Merge branch 'remove-dsa_priv-h'
Vladimir Oltean says: ==================== Remove dsa_priv.h After working on the "Autoload DSA tagging driver when dynamically changing protocol" series: https://patchwork.kernel.org/project/netdevbpf/cover/20221115011847.2843127-1-vladimir.oltean@nxp.com/ it became clear to me that the situation with DSA headers is a bit messy, and I put the tagging protocol driver macros in a pretty random temporary spot in dsa_priv.h. Now is the time to make the net/dsa/ folder a bit more organized, and to make tagging protocol driver modules include just headers they're going to use. Another thing is the merging and cleanup of dsa.c and dsa2.c. Before, dsa.c had 589 lines and dsa2.c had 1817 lines. Now, the combined dsa.c has 1749 lines, the rest went to some other places. Sorry for the set size, I know the rules, but since this is basically code movement for the most part, I thought more patches are better. ==================== Link: https://lore.kernel.org/r/20221121135555.1227271-1-vladimir.oltean@nxp.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
commit
8263ee81f6
@ -18,6 +18,7 @@ config NET_DSA_BCM_SF2
|
||||
|
||||
config NET_DSA_LOOP
|
||||
tristate "DSA mock-up Ethernet switch chip support"
|
||||
select NET_DSA_TAG_NONE
|
||||
select FIXED_PHY
|
||||
help
|
||||
This enables support for a fake mock-up switch chip which
|
||||
@ -99,6 +100,7 @@ config NET_DSA_SMSC_LAN9303_MDIO
|
||||
|
||||
config NET_DSA_VITESSE_VSC73XX
|
||||
tristate
|
||||
select NET_DSA_TAG_NONE
|
||||
select FIXED_PHY
|
||||
select VITESSE_PHY
|
||||
select GPIOLIB
|
||||
|
@ -2,6 +2,7 @@
|
||||
menuconfig B53
|
||||
tristate "Broadcom BCM53xx managed switch support"
|
||||
depends on NET_DSA
|
||||
select NET_DSA_TAG_NONE
|
||||
select NET_DSA_TAG_BRCM
|
||||
select NET_DSA_TAG_BRCM_LEGACY
|
||||
select NET_DSA_TAG_BRCM_PREPEND
|
||||
|
@ -3,6 +3,7 @@ menuconfig NET_DSA_MICROCHIP_KSZ_COMMON
|
||||
tristate "Microchip KSZ8795/KSZ9477/LAN937x series switch support"
|
||||
depends on NET_DSA
|
||||
select NET_DSA_TAG_KSZ
|
||||
select NET_DSA_TAG_NONE
|
||||
help
|
||||
This driver adds support for Microchip KSZ9477 series switch and
|
||||
KSZ8795/KSZ88x3 switch chips.
|
||||
|
@ -5,28 +5,8 @@
|
||||
#ifndef _NET_DSA_8021Q_H
|
||||
#define _NET_DSA_8021Q_H
|
||||
|
||||
#include <linux/refcount.h>
|
||||
#include <linux/types.h>
|
||||
#include <net/dsa.h>
|
||||
|
||||
struct dsa_switch;
|
||||
struct dsa_port;
|
||||
struct sk_buff;
|
||||
struct net_device;
|
||||
|
||||
struct dsa_tag_8021q_vlan {
|
||||
struct list_head list;
|
||||
int port;
|
||||
u16 vid;
|
||||
refcount_t refcount;
|
||||
};
|
||||
|
||||
struct dsa_8021q_context {
|
||||
struct dsa_switch *ds;
|
||||
struct list_head vlans;
|
||||
/* EtherType of RX VID, used for filtering on master interface */
|
||||
__be16 proto;
|
||||
};
|
||||
#include <linux/types.h>
|
||||
|
||||
int dsa_tag_8021q_register(struct dsa_switch *ds, __be16 proto);
|
||||
|
||||
@ -38,15 +18,6 @@ int dsa_tag_8021q_bridge_join(struct dsa_switch *ds, int port,
|
||||
void dsa_tag_8021q_bridge_leave(struct dsa_switch *ds, int port,
|
||||
struct dsa_bridge bridge);
|
||||
|
||||
struct sk_buff *dsa_8021q_xmit(struct sk_buff *skb, struct net_device *netdev,
|
||||
u16 tpid, u16 tci);
|
||||
|
||||
void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id,
|
||||
int *vbid);
|
||||
|
||||
struct net_device *dsa_tag_8021q_find_port_by_vbid(struct net_device *master,
|
||||
int vbid);
|
||||
|
||||
u16 dsa_tag_8021q_bridge_vid(unsigned int bridge_num);
|
||||
|
||||
u16 dsa_tag_8021q_standalone_vid(const struct dsa_port *dp);
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <net/devlink.h>
|
||||
#include <net/switchdev.h>
|
||||
|
||||
struct dsa_8021q_context;
|
||||
struct tc_action;
|
||||
struct phy_device;
|
||||
struct fixed_phy_status;
|
||||
@ -1285,8 +1286,6 @@ struct dsa_switch_driver {
|
||||
const struct dsa_switch_ops *ops;
|
||||
};
|
||||
|
||||
struct net_device *dsa_dev_to_net_device(struct device *dev);
|
||||
|
||||
bool dsa_fdb_present_in_other_db(struct dsa_switch *ds, int port,
|
||||
const unsigned char *addr, u16 vid,
|
||||
struct dsa_db db);
|
||||
|
@ -18,6 +18,12 @@ if NET_DSA
|
||||
|
||||
# Drivers must select the appropriate tagging format(s)
|
||||
|
||||
config NET_DSA_TAG_NONE
|
||||
tristate "No-op tag driver"
|
||||
help
|
||||
Say Y or M if you want to enable support for switches which don't tag
|
||||
frames over the CPU port.
|
||||
|
||||
config NET_DSA_TAG_AR9331
|
||||
tristate "Tag driver for Atheros AR9331 SoC with built-in switch"
|
||||
help
|
||||
|
@ -2,13 +2,14 @@
|
||||
# the core
|
||||
obj-$(CONFIG_NET_DSA) += dsa_core.o
|
||||
dsa_core-y += \
|
||||
devlink.o \
|
||||
dsa.o \
|
||||
dsa2.o \
|
||||
master.o \
|
||||
netlink.o \
|
||||
port.o \
|
||||
slave.o \
|
||||
switch.o \
|
||||
tag.o \
|
||||
tag_8021q.o
|
||||
|
||||
# tagging formats
|
||||
@ -20,6 +21,7 @@ obj-$(CONFIG_NET_DSA_TAG_HELLCREEK) += tag_hellcreek.o
|
||||
obj-$(CONFIG_NET_DSA_TAG_KSZ) += tag_ksz.o
|
||||
obj-$(CONFIG_NET_DSA_TAG_LAN9303) += tag_lan9303.o
|
||||
obj-$(CONFIG_NET_DSA_TAG_MTK) += tag_mtk.o
|
||||
obj-$(CONFIG_NET_DSA_TAG_NONE) += tag_none.o
|
||||
obj-$(CONFIG_NET_DSA_TAG_OCELOT) += tag_ocelot.o
|
||||
obj-$(CONFIG_NET_DSA_TAG_OCELOT_8021Q) += tag_ocelot_8021q.o
|
||||
obj-$(CONFIG_NET_DSA_TAG_QCA) += tag_qca.o
|
||||
|
391
net/dsa/devlink.c
Normal file
391
net/dsa/devlink.c
Normal file
@ -0,0 +1,391 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
/*
|
||||
* DSA devlink handling
|
||||
*/
|
||||
|
||||
#include <net/dsa.h>
|
||||
#include <net/devlink.h>
|
||||
|
||||
#include "devlink.h"
|
||||
|
||||
static int dsa_devlink_info_get(struct devlink *dl,
|
||||
struct devlink_info_req *req,
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
struct dsa_switch *ds = dsa_devlink_to_ds(dl);
|
||||
|
||||
if (ds->ops->devlink_info_get)
|
||||
return ds->ops->devlink_info_get(ds, req, extack);
|
||||
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
static int dsa_devlink_sb_pool_get(struct devlink *dl,
|
||||
unsigned int sb_index, u16 pool_index,
|
||||
struct devlink_sb_pool_info *pool_info)
|
||||
{
|
||||
struct dsa_switch *ds = dsa_devlink_to_ds(dl);
|
||||
|
||||
if (!ds->ops->devlink_sb_pool_get)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
return ds->ops->devlink_sb_pool_get(ds, sb_index, pool_index,
|
||||
pool_info);
|
||||
}
|
||||
|
||||
static int dsa_devlink_sb_pool_set(struct devlink *dl, unsigned int sb_index,
|
||||
u16 pool_index, u32 size,
|
||||
enum devlink_sb_threshold_type threshold_type,
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
struct dsa_switch *ds = dsa_devlink_to_ds(dl);
|
||||
|
||||
if (!ds->ops->devlink_sb_pool_set)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
return ds->ops->devlink_sb_pool_set(ds, sb_index, pool_index, size,
|
||||
threshold_type, extack);
|
||||
}
|
||||
|
||||
static int dsa_devlink_sb_port_pool_get(struct devlink_port *dlp,
|
||||
unsigned int sb_index, u16 pool_index,
|
||||
u32 *p_threshold)
|
||||
{
|
||||
struct dsa_switch *ds = dsa_devlink_port_to_ds(dlp);
|
||||
int port = dsa_devlink_port_to_port(dlp);
|
||||
|
||||
if (!ds->ops->devlink_sb_port_pool_get)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
return ds->ops->devlink_sb_port_pool_get(ds, port, sb_index,
|
||||
pool_index, p_threshold);
|
||||
}
|
||||
|
||||
static int dsa_devlink_sb_port_pool_set(struct devlink_port *dlp,
|
||||
unsigned int sb_index, u16 pool_index,
|
||||
u32 threshold,
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
struct dsa_switch *ds = dsa_devlink_port_to_ds(dlp);
|
||||
int port = dsa_devlink_port_to_port(dlp);
|
||||
|
||||
if (!ds->ops->devlink_sb_port_pool_set)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
return ds->ops->devlink_sb_port_pool_set(ds, port, sb_index,
|
||||
pool_index, threshold, extack);
|
||||
}
|
||||
|
||||
static int
|
||||
dsa_devlink_sb_tc_pool_bind_get(struct devlink_port *dlp,
|
||||
unsigned int sb_index, u16 tc_index,
|
||||
enum devlink_sb_pool_type pool_type,
|
||||
u16 *p_pool_index, u32 *p_threshold)
|
||||
{
|
||||
struct dsa_switch *ds = dsa_devlink_port_to_ds(dlp);
|
||||
int port = dsa_devlink_port_to_port(dlp);
|
||||
|
||||
if (!ds->ops->devlink_sb_tc_pool_bind_get)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
return ds->ops->devlink_sb_tc_pool_bind_get(ds, port, sb_index,
|
||||
tc_index, pool_type,
|
||||
p_pool_index, p_threshold);
|
||||
}
|
||||
|
||||
static int
|
||||
dsa_devlink_sb_tc_pool_bind_set(struct devlink_port *dlp,
|
||||
unsigned int sb_index, u16 tc_index,
|
||||
enum devlink_sb_pool_type pool_type,
|
||||
u16 pool_index, u32 threshold,
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
struct dsa_switch *ds = dsa_devlink_port_to_ds(dlp);
|
||||
int port = dsa_devlink_port_to_port(dlp);
|
||||
|
||||
if (!ds->ops->devlink_sb_tc_pool_bind_set)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
return ds->ops->devlink_sb_tc_pool_bind_set(ds, port, sb_index,
|
||||
tc_index, pool_type,
|
||||
pool_index, threshold,
|
||||
extack);
|
||||
}
|
||||
|
||||
static int dsa_devlink_sb_occ_snapshot(struct devlink *dl,
|
||||
unsigned int sb_index)
|
||||
{
|
||||
struct dsa_switch *ds = dsa_devlink_to_ds(dl);
|
||||
|
||||
if (!ds->ops->devlink_sb_occ_snapshot)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
return ds->ops->devlink_sb_occ_snapshot(ds, sb_index);
|
||||
}
|
||||
|
||||
static int dsa_devlink_sb_occ_max_clear(struct devlink *dl,
|
||||
unsigned int sb_index)
|
||||
{
|
||||
struct dsa_switch *ds = dsa_devlink_to_ds(dl);
|
||||
|
||||
if (!ds->ops->devlink_sb_occ_max_clear)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
return ds->ops->devlink_sb_occ_max_clear(ds, sb_index);
|
||||
}
|
||||
|
||||
static int dsa_devlink_sb_occ_port_pool_get(struct devlink_port *dlp,
|
||||
unsigned int sb_index,
|
||||
u16 pool_index, u32 *p_cur,
|
||||
u32 *p_max)
|
||||
{
|
||||
struct dsa_switch *ds = dsa_devlink_port_to_ds(dlp);
|
||||
int port = dsa_devlink_port_to_port(dlp);
|
||||
|
||||
if (!ds->ops->devlink_sb_occ_port_pool_get)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
return ds->ops->devlink_sb_occ_port_pool_get(ds, port, sb_index,
|
||||
pool_index, p_cur, p_max);
|
||||
}
|
||||
|
||||
static int
|
||||
dsa_devlink_sb_occ_tc_port_bind_get(struct devlink_port *dlp,
|
||||
unsigned int sb_index, u16 tc_index,
|
||||
enum devlink_sb_pool_type pool_type,
|
||||
u32 *p_cur, u32 *p_max)
|
||||
{
|
||||
struct dsa_switch *ds = dsa_devlink_port_to_ds(dlp);
|
||||
int port = dsa_devlink_port_to_port(dlp);
|
||||
|
||||
if (!ds->ops->devlink_sb_occ_tc_port_bind_get)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
return ds->ops->devlink_sb_occ_tc_port_bind_get(ds, port,
|
||||
sb_index, tc_index,
|
||||
pool_type, p_cur,
|
||||
p_max);
|
||||
}
|
||||
|
||||
static const struct devlink_ops dsa_devlink_ops = {
|
||||
.info_get = dsa_devlink_info_get,
|
||||
.sb_pool_get = dsa_devlink_sb_pool_get,
|
||||
.sb_pool_set = dsa_devlink_sb_pool_set,
|
||||
.sb_port_pool_get = dsa_devlink_sb_port_pool_get,
|
||||
.sb_port_pool_set = dsa_devlink_sb_port_pool_set,
|
||||
.sb_tc_pool_bind_get = dsa_devlink_sb_tc_pool_bind_get,
|
||||
.sb_tc_pool_bind_set = dsa_devlink_sb_tc_pool_bind_set,
|
||||
.sb_occ_snapshot = dsa_devlink_sb_occ_snapshot,
|
||||
.sb_occ_max_clear = dsa_devlink_sb_occ_max_clear,
|
||||
.sb_occ_port_pool_get = dsa_devlink_sb_occ_port_pool_get,
|
||||
.sb_occ_tc_port_bind_get = dsa_devlink_sb_occ_tc_port_bind_get,
|
||||
};
|
||||
|
||||
int dsa_devlink_param_get(struct devlink *dl, u32 id,
|
||||
struct devlink_param_gset_ctx *ctx)
|
||||
{
|
||||
struct dsa_switch *ds = dsa_devlink_to_ds(dl);
|
||||
|
||||
if (!ds->ops->devlink_param_get)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
return ds->ops->devlink_param_get(ds, id, ctx);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(dsa_devlink_param_get);
|
||||
|
||||
int dsa_devlink_param_set(struct devlink *dl, u32 id,
|
||||
struct devlink_param_gset_ctx *ctx)
|
||||
{
|
||||
struct dsa_switch *ds = dsa_devlink_to_ds(dl);
|
||||
|
||||
if (!ds->ops->devlink_param_set)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
return ds->ops->devlink_param_set(ds, id, ctx);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(dsa_devlink_param_set);
|
||||
|
||||
int dsa_devlink_params_register(struct dsa_switch *ds,
|
||||
const struct devlink_param *params,
|
||||
size_t params_count)
|
||||
{
|
||||
return devlink_params_register(ds->devlink, params, params_count);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(dsa_devlink_params_register);
|
||||
|
||||
void dsa_devlink_params_unregister(struct dsa_switch *ds,
|
||||
const struct devlink_param *params,
|
||||
size_t params_count)
|
||||
{
|
||||
devlink_params_unregister(ds->devlink, params, params_count);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(dsa_devlink_params_unregister);
|
||||
|
||||
int dsa_devlink_resource_register(struct dsa_switch *ds,
|
||||
const char *resource_name,
|
||||
u64 resource_size,
|
||||
u64 resource_id,
|
||||
u64 parent_resource_id,
|
||||
const struct devlink_resource_size_params *size_params)
|
||||
{
|
||||
return devlink_resource_register(ds->devlink, resource_name,
|
||||
resource_size, resource_id,
|
||||
parent_resource_id,
|
||||
size_params);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(dsa_devlink_resource_register);
|
||||
|
||||
void dsa_devlink_resources_unregister(struct dsa_switch *ds)
|
||||
{
|
||||
devlink_resources_unregister(ds->devlink);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(dsa_devlink_resources_unregister);
|
||||
|
||||
void dsa_devlink_resource_occ_get_register(struct dsa_switch *ds,
|
||||
u64 resource_id,
|
||||
devlink_resource_occ_get_t *occ_get,
|
||||
void *occ_get_priv)
|
||||
{
|
||||
return devlink_resource_occ_get_register(ds->devlink, resource_id,
|
||||
occ_get, occ_get_priv);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(dsa_devlink_resource_occ_get_register);
|
||||
|
||||
void dsa_devlink_resource_occ_get_unregister(struct dsa_switch *ds,
|
||||
u64 resource_id)
|
||||
{
|
||||
devlink_resource_occ_get_unregister(ds->devlink, resource_id);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(dsa_devlink_resource_occ_get_unregister);
|
||||
|
||||
struct devlink_region *
|
||||
dsa_devlink_region_create(struct dsa_switch *ds,
|
||||
const struct devlink_region_ops *ops,
|
||||
u32 region_max_snapshots, u64 region_size)
|
||||
{
|
||||
return devlink_region_create(ds->devlink, ops, region_max_snapshots,
|
||||
region_size);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(dsa_devlink_region_create);
|
||||
|
||||
struct devlink_region *
|
||||
dsa_devlink_port_region_create(struct dsa_switch *ds,
|
||||
int port,
|
||||
const struct devlink_port_region_ops *ops,
|
||||
u32 region_max_snapshots, u64 region_size)
|
||||
{
|
||||
struct dsa_port *dp = dsa_to_port(ds, port);
|
||||
|
||||
return devlink_port_region_create(&dp->devlink_port, ops,
|
||||
region_max_snapshots,
|
||||
region_size);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(dsa_devlink_port_region_create);
|
||||
|
||||
void dsa_devlink_region_destroy(struct devlink_region *region)
|
||||
{
|
||||
devlink_region_destroy(region);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(dsa_devlink_region_destroy);
|
||||
|
||||
int dsa_port_devlink_setup(struct dsa_port *dp)
|
||||
{
|
||||
struct devlink_port *dlp = &dp->devlink_port;
|
||||
struct dsa_switch_tree *dst = dp->ds->dst;
|
||||
struct devlink_port_attrs attrs = {};
|
||||
struct devlink *dl = dp->ds->devlink;
|
||||
struct dsa_switch *ds = dp->ds;
|
||||
const unsigned char *id;
|
||||
unsigned char len;
|
||||
int err;
|
||||
|
||||
memset(dlp, 0, sizeof(*dlp));
|
||||
devlink_port_init(dl, dlp);
|
||||
|
||||
if (ds->ops->port_setup) {
|
||||
err = ds->ops->port_setup(ds, dp->index);
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
|
||||
id = (const unsigned char *)&dst->index;
|
||||
len = sizeof(dst->index);
|
||||
|
||||
attrs.phys.port_number = dp->index;
|
||||
memcpy(attrs.switch_id.id, id, len);
|
||||
attrs.switch_id.id_len = len;
|
||||
|
||||
switch (dp->type) {
|
||||
case DSA_PORT_TYPE_UNUSED:
|
||||
attrs.flavour = DEVLINK_PORT_FLAVOUR_UNUSED;
|
||||
break;
|
||||
case DSA_PORT_TYPE_CPU:
|
||||
attrs.flavour = DEVLINK_PORT_FLAVOUR_CPU;
|
||||
break;
|
||||
case DSA_PORT_TYPE_DSA:
|
||||
attrs.flavour = DEVLINK_PORT_FLAVOUR_DSA;
|
||||
break;
|
||||
case DSA_PORT_TYPE_USER:
|
||||
attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL;
|
||||
break;
|
||||
}
|
||||
|
||||
devlink_port_attrs_set(dlp, &attrs);
|
||||
err = devlink_port_register(dl, dlp, dp->index);
|
||||
if (err) {
|
||||
if (ds->ops->port_teardown)
|
||||
ds->ops->port_teardown(ds, dp->index);
|
||||
return err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dsa_port_devlink_teardown(struct dsa_port *dp)
|
||||
{
|
||||
struct devlink_port *dlp = &dp->devlink_port;
|
||||
struct dsa_switch *ds = dp->ds;
|
||||
|
||||
devlink_port_unregister(dlp);
|
||||
|
||||
if (ds->ops->port_teardown)
|
||||
ds->ops->port_teardown(ds, dp->index);
|
||||
|
||||
devlink_port_fini(dlp);
|
||||
}
|
||||
|
||||
void dsa_switch_devlink_register(struct dsa_switch *ds)
|
||||
{
|
||||
devlink_register(ds->devlink);
|
||||
}
|
||||
|
||||
void dsa_switch_devlink_unregister(struct dsa_switch *ds)
|
||||
{
|
||||
devlink_unregister(ds->devlink);
|
||||
}
|
||||
|
||||
int dsa_switch_devlink_alloc(struct dsa_switch *ds)
|
||||
{
|
||||
struct dsa_devlink_priv *dl_priv;
|
||||
struct devlink *dl;
|
||||
|
||||
/* Add the switch to devlink before calling setup, so that setup can
|
||||
* add dpipe tables
|
||||
*/
|
||||
dl = devlink_alloc(&dsa_devlink_ops, sizeof(*dl_priv), ds->dev);
|
||||
if (!dl)
|
||||
return -ENOMEM;
|
||||
|
||||
ds->devlink = dl;
|
||||
|
||||
dl_priv = devlink_priv(ds->devlink);
|
||||
dl_priv->ds = ds;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dsa_switch_devlink_free(struct dsa_switch *ds)
|
||||
{
|
||||
devlink_free(ds->devlink);
|
||||
ds->devlink = NULL;
|
||||
}
|
16
net/dsa/devlink.h
Normal file
16
net/dsa/devlink.h
Normal file
@ -0,0 +1,16 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#ifndef __DSA_DEVLINK_H
|
||||
#define __DSA_DEVLINK_H
|
||||
|
||||
struct dsa_port;
|
||||
struct dsa_switch;
|
||||
|
||||
int dsa_port_devlink_setup(struct dsa_port *dp);
|
||||
void dsa_port_devlink_teardown(struct dsa_port *dp);
|
||||
void dsa_switch_devlink_register(struct dsa_switch *ds);
|
||||
void dsa_switch_devlink_unregister(struct dsa_switch *ds);
|
||||
int dsa_switch_devlink_alloc(struct dsa_switch *ds);
|
||||
void dsa_switch_devlink_free(struct dsa_switch *ds);
|
||||
|
||||
#endif
|
1806
net/dsa/dsa.c
1806
net/dsa/dsa.c
File diff suppressed because it is too large
Load Diff
40
net/dsa/dsa.h
Normal file
40
net/dsa/dsa.h
Normal file
@ -0,0 +1,40 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#ifndef __DSA_H
|
||||
#define __DSA_H
|
||||
|
||||
#include <linux/list.h>
|
||||
#include <linux/types.h>
|
||||
|
||||
struct dsa_db;
|
||||
struct dsa_device_ops;
|
||||
struct dsa_lag;
|
||||
struct dsa_switch_tree;
|
||||
struct net_device;
|
||||
struct work_struct;
|
||||
|
||||
extern struct list_head dsa_tree_list;
|
||||
|
||||
bool dsa_db_equal(const struct dsa_db *a, const struct dsa_db *b);
|
||||
bool dsa_schedule_work(struct work_struct *work);
|
||||
void dsa_lag_map(struct dsa_switch_tree *dst, struct dsa_lag *lag);
|
||||
void dsa_lag_unmap(struct dsa_switch_tree *dst, struct dsa_lag *lag);
|
||||
struct dsa_lag *dsa_tree_lag_find(struct dsa_switch_tree *dst,
|
||||
const struct net_device *lag_dev);
|
||||
struct net_device *dsa_tree_find_first_master(struct dsa_switch_tree *dst);
|
||||
int dsa_tree_change_tag_proto(struct dsa_switch_tree *dst,
|
||||
const struct dsa_device_ops *tag_ops,
|
||||
const struct dsa_device_ops *old_tag_ops);
|
||||
void dsa_tree_master_admin_state_change(struct dsa_switch_tree *dst,
|
||||
struct net_device *master,
|
||||
bool up);
|
||||
void dsa_tree_master_oper_state_change(struct dsa_switch_tree *dst,
|
||||
struct net_device *master,
|
||||
bool up);
|
||||
unsigned int dsa_bridge_num_get(const struct net_device *bridge_dev, int max);
|
||||
void dsa_bridge_num_put(const struct net_device *bridge_dev,
|
||||
unsigned int bridge_num);
|
||||
struct dsa_bridge *dsa_tree_bridge_find(struct dsa_switch_tree *dst,
|
||||
const struct net_device *br);
|
||||
|
||||
#endif
|
1817
net/dsa/dsa2.c
1817
net/dsa/dsa2.c
File diff suppressed because it is too large
Load Diff
@ -1,663 +0,0 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
/*
|
||||
* net/dsa/dsa_priv.h - Hardware switch handling
|
||||
* Copyright (c) 2008-2009 Marvell Semiconductor
|
||||
*/
|
||||
|
||||
#ifndef __DSA_PRIV_H
|
||||
#define __DSA_PRIV_H
|
||||
|
||||
#include <linux/if_bridge.h>
|
||||
#include <linux/if_vlan.h>
|
||||
#include <linux/phy.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/netpoll.h>
|
||||
#include <net/dsa.h>
|
||||
#include <net/gro_cells.h>
|
||||
|
||||
#define DSA_MAX_NUM_OFFLOADING_BRIDGES BITS_PER_LONG
|
||||
|
||||
/* Create 2 modaliases per tagging protocol, one to auto-load the module
|
||||
* given the ID reported by get_tag_protocol(), and the other by name.
|
||||
*/
|
||||
#define DSA_TAG_DRIVER_ALIAS "dsa_tag:"
|
||||
#define MODULE_ALIAS_DSA_TAG_DRIVER(__proto, __name) \
|
||||
MODULE_ALIAS(DSA_TAG_DRIVER_ALIAS __name); \
|
||||
MODULE_ALIAS(DSA_TAG_DRIVER_ALIAS "id-" \
|
||||
__stringify(__proto##_VALUE))
|
||||
|
||||
struct dsa_tag_driver {
|
||||
const struct dsa_device_ops *ops;
|
||||
struct list_head list;
|
||||
struct module *owner;
|
||||
};
|
||||
|
||||
void dsa_tag_drivers_register(struct dsa_tag_driver *dsa_tag_driver_array[],
|
||||
unsigned int count,
|
||||
struct module *owner);
|
||||
void dsa_tag_drivers_unregister(struct dsa_tag_driver *dsa_tag_driver_array[],
|
||||
unsigned int count);
|
||||
|
||||
#define dsa_tag_driver_module_drivers(__dsa_tag_drivers_array, __count) \
|
||||
static int __init dsa_tag_driver_module_init(void) \
|
||||
{ \
|
||||
dsa_tag_drivers_register(__dsa_tag_drivers_array, __count, \
|
||||
THIS_MODULE); \
|
||||
return 0; \
|
||||
} \
|
||||
module_init(dsa_tag_driver_module_init); \
|
||||
\
|
||||
static void __exit dsa_tag_driver_module_exit(void) \
|
||||
{ \
|
||||
dsa_tag_drivers_unregister(__dsa_tag_drivers_array, __count); \
|
||||
} \
|
||||
module_exit(dsa_tag_driver_module_exit)
|
||||
|
||||
/**
|
||||
* module_dsa_tag_drivers() - Helper macro for registering DSA tag
|
||||
* drivers
|
||||
* @__ops_array: Array of tag driver structures
|
||||
*
|
||||
* Helper macro for DSA tag drivers which do not do anything special
|
||||
* in module init/exit. Each module may only use this macro once, and
|
||||
* calling it replaces module_init() and module_exit().
|
||||
*/
|
||||
#define module_dsa_tag_drivers(__ops_array) \
|
||||
dsa_tag_driver_module_drivers(__ops_array, ARRAY_SIZE(__ops_array))
|
||||
|
||||
#define DSA_TAG_DRIVER_NAME(__ops) dsa_tag_driver ## _ ## __ops
|
||||
|
||||
/* Create a static structure we can build a linked list of dsa_tag
|
||||
* drivers
|
||||
*/
|
||||
#define DSA_TAG_DRIVER(__ops) \
|
||||
static struct dsa_tag_driver DSA_TAG_DRIVER_NAME(__ops) = { \
|
||||
.ops = &__ops, \
|
||||
}
|
||||
|
||||
/**
|
||||
* module_dsa_tag_driver() - Helper macro for registering a single DSA tag
|
||||
* driver
|
||||
* @__ops: Single tag driver structures
|
||||
*
|
||||
* Helper macro for DSA tag drivers which do not do anything special
|
||||
* in module init/exit. Each module may only use this macro once, and
|
||||
* calling it replaces module_init() and module_exit().
|
||||
*/
|
||||
#define module_dsa_tag_driver(__ops) \
|
||||
DSA_TAG_DRIVER(__ops); \
|
||||
\
|
||||
static struct dsa_tag_driver *dsa_tag_driver_array[] = { \
|
||||
&DSA_TAG_DRIVER_NAME(__ops) \
|
||||
}; \
|
||||
module_dsa_tag_drivers(dsa_tag_driver_array)
|
||||
|
||||
enum {
|
||||
DSA_NOTIFIER_AGEING_TIME,
|
||||
DSA_NOTIFIER_BRIDGE_JOIN,
|
||||
DSA_NOTIFIER_BRIDGE_LEAVE,
|
||||
DSA_NOTIFIER_FDB_ADD,
|
||||
DSA_NOTIFIER_FDB_DEL,
|
||||
DSA_NOTIFIER_HOST_FDB_ADD,
|
||||
DSA_NOTIFIER_HOST_FDB_DEL,
|
||||
DSA_NOTIFIER_LAG_FDB_ADD,
|
||||
DSA_NOTIFIER_LAG_FDB_DEL,
|
||||
DSA_NOTIFIER_LAG_CHANGE,
|
||||
DSA_NOTIFIER_LAG_JOIN,
|
||||
DSA_NOTIFIER_LAG_LEAVE,
|
||||
DSA_NOTIFIER_MDB_ADD,
|
||||
DSA_NOTIFIER_MDB_DEL,
|
||||
DSA_NOTIFIER_HOST_MDB_ADD,
|
||||
DSA_NOTIFIER_HOST_MDB_DEL,
|
||||
DSA_NOTIFIER_VLAN_ADD,
|
||||
DSA_NOTIFIER_VLAN_DEL,
|
||||
DSA_NOTIFIER_HOST_VLAN_ADD,
|
||||
DSA_NOTIFIER_HOST_VLAN_DEL,
|
||||
DSA_NOTIFIER_MTU,
|
||||
DSA_NOTIFIER_TAG_PROTO,
|
||||
DSA_NOTIFIER_TAG_PROTO_CONNECT,
|
||||
DSA_NOTIFIER_TAG_PROTO_DISCONNECT,
|
||||
DSA_NOTIFIER_TAG_8021Q_VLAN_ADD,
|
||||
DSA_NOTIFIER_TAG_8021Q_VLAN_DEL,
|
||||
DSA_NOTIFIER_MASTER_STATE_CHANGE,
|
||||
};
|
||||
|
||||
/* DSA_NOTIFIER_AGEING_TIME */
|
||||
struct dsa_notifier_ageing_time_info {
|
||||
unsigned int ageing_time;
|
||||
};
|
||||
|
||||
/* DSA_NOTIFIER_BRIDGE_* */
|
||||
struct dsa_notifier_bridge_info {
|
||||
const struct dsa_port *dp;
|
||||
struct dsa_bridge bridge;
|
||||
bool tx_fwd_offload;
|
||||
struct netlink_ext_ack *extack;
|
||||
};
|
||||
|
||||
/* DSA_NOTIFIER_FDB_* */
|
||||
struct dsa_notifier_fdb_info {
|
||||
const struct dsa_port *dp;
|
||||
const unsigned char *addr;
|
||||
u16 vid;
|
||||
struct dsa_db db;
|
||||
};
|
||||
|
||||
/* DSA_NOTIFIER_LAG_FDB_* */
|
||||
struct dsa_notifier_lag_fdb_info {
|
||||
struct dsa_lag *lag;
|
||||
const unsigned char *addr;
|
||||
u16 vid;
|
||||
struct dsa_db db;
|
||||
};
|
||||
|
||||
/* DSA_NOTIFIER_MDB_* */
|
||||
struct dsa_notifier_mdb_info {
|
||||
const struct dsa_port *dp;
|
||||
const struct switchdev_obj_port_mdb *mdb;
|
||||
struct dsa_db db;
|
||||
};
|
||||
|
||||
/* DSA_NOTIFIER_LAG_* */
|
||||
struct dsa_notifier_lag_info {
|
||||
const struct dsa_port *dp;
|
||||
struct dsa_lag lag;
|
||||
struct netdev_lag_upper_info *info;
|
||||
struct netlink_ext_ack *extack;
|
||||
};
|
||||
|
||||
/* DSA_NOTIFIER_VLAN_* */
|
||||
struct dsa_notifier_vlan_info {
|
||||
const struct dsa_port *dp;
|
||||
const struct switchdev_obj_port_vlan *vlan;
|
||||
struct netlink_ext_ack *extack;
|
||||
};
|
||||
|
||||
/* DSA_NOTIFIER_MTU */
|
||||
struct dsa_notifier_mtu_info {
|
||||
const struct dsa_port *dp;
|
||||
int mtu;
|
||||
};
|
||||
|
||||
/* DSA_NOTIFIER_TAG_PROTO_* */
|
||||
struct dsa_notifier_tag_proto_info {
|
||||
const struct dsa_device_ops *tag_ops;
|
||||
};
|
||||
|
||||
/* DSA_NOTIFIER_TAG_8021Q_VLAN_* */
|
||||
struct dsa_notifier_tag_8021q_vlan_info {
|
||||
const struct dsa_port *dp;
|
||||
u16 vid;
|
||||
};
|
||||
|
||||
/* DSA_NOTIFIER_MASTER_STATE_CHANGE */
|
||||
struct dsa_notifier_master_state_info {
|
||||
const struct net_device *master;
|
||||
bool operational;
|
||||
};
|
||||
|
||||
struct dsa_switchdev_event_work {
|
||||
struct net_device *dev;
|
||||
struct net_device *orig_dev;
|
||||
struct work_struct work;
|
||||
unsigned long event;
|
||||
/* Specific for SWITCHDEV_FDB_ADD_TO_DEVICE and
|
||||
* SWITCHDEV_FDB_DEL_TO_DEVICE
|
||||
*/
|
||||
unsigned char addr[ETH_ALEN];
|
||||
u16 vid;
|
||||
bool host_addr;
|
||||
};
|
||||
|
||||
enum dsa_standalone_event {
|
||||
DSA_UC_ADD,
|
||||
DSA_UC_DEL,
|
||||
DSA_MC_ADD,
|
||||
DSA_MC_DEL,
|
||||
};
|
||||
|
||||
struct dsa_standalone_event_work {
|
||||
struct work_struct work;
|
||||
struct net_device *dev;
|
||||
enum dsa_standalone_event event;
|
||||
unsigned char addr[ETH_ALEN];
|
||||
u16 vid;
|
||||
};
|
||||
|
||||
struct dsa_slave_priv {
|
||||
/* Copy of CPU port xmit for faster access in slave transmit hot path */
|
||||
struct sk_buff * (*xmit)(struct sk_buff *skb,
|
||||
struct net_device *dev);
|
||||
|
||||
struct gro_cells gcells;
|
||||
|
||||
/* DSA port data, such as switch, port index, etc. */
|
||||
struct dsa_port *dp;
|
||||
|
||||
#ifdef CONFIG_NET_POLL_CONTROLLER
|
||||
struct netpoll *netpoll;
|
||||
#endif
|
||||
|
||||
/* TC context */
|
||||
struct list_head mall_tc_list;
|
||||
};
|
||||
|
||||
/* dsa.c */
|
||||
const struct dsa_device_ops *dsa_tag_driver_get_by_id(int tag_protocol);
|
||||
const struct dsa_device_ops *dsa_tag_driver_get_by_name(const char *name);
|
||||
void dsa_tag_driver_put(const struct dsa_device_ops *ops);
|
||||
|
||||
bool dsa_db_equal(const struct dsa_db *a, const struct dsa_db *b);
|
||||
|
||||
bool dsa_schedule_work(struct work_struct *work);
|
||||
const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops);
|
||||
|
||||
static inline int dsa_tag_protocol_overhead(const struct dsa_device_ops *ops)
|
||||
{
|
||||
return ops->needed_headroom + ops->needed_tailroom;
|
||||
}
|
||||
|
||||
/* master.c */
|
||||
int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp);
|
||||
void dsa_master_teardown(struct net_device *dev);
|
||||
int dsa_master_lag_setup(struct net_device *lag_dev, struct dsa_port *cpu_dp,
|
||||
struct netdev_lag_upper_info *uinfo,
|
||||
struct netlink_ext_ack *extack);
|
||||
void dsa_master_lag_teardown(struct net_device *lag_dev,
|
||||
struct dsa_port *cpu_dp);
|
||||
|
||||
static inline struct net_device *dsa_master_find_slave(struct net_device *dev,
|
||||
int device, int port)
|
||||
{
|
||||
struct dsa_port *cpu_dp = dev->dsa_ptr;
|
||||
struct dsa_switch_tree *dst = cpu_dp->dst;
|
||||
struct dsa_port *dp;
|
||||
|
||||
list_for_each_entry(dp, &dst->ports, list)
|
||||
if (dp->ds->index == device && dp->index == port &&
|
||||
dp->type == DSA_PORT_TYPE_USER)
|
||||
return dp->slave;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* netlink.c */
|
||||
extern struct rtnl_link_ops dsa_link_ops __read_mostly;
|
||||
|
||||
/* port.c */
|
||||
bool dsa_port_supports_hwtstamp(struct dsa_port *dp, struct ifreq *ifr);
|
||||
void dsa_port_set_tag_protocol(struct dsa_port *cpu_dp,
|
||||
const struct dsa_device_ops *tag_ops);
|
||||
int dsa_port_set_state(struct dsa_port *dp, u8 state, bool do_fast_age);
|
||||
int dsa_port_set_mst_state(struct dsa_port *dp,
|
||||
const struct switchdev_mst_state *state,
|
||||
struct netlink_ext_ack *extack);
|
||||
int dsa_port_enable_rt(struct dsa_port *dp, struct phy_device *phy);
|
||||
int dsa_port_enable(struct dsa_port *dp, struct phy_device *phy);
|
||||
void dsa_port_disable_rt(struct dsa_port *dp);
|
||||
void dsa_port_disable(struct dsa_port *dp);
|
||||
int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br,
|
||||
struct netlink_ext_ack *extack);
|
||||
void dsa_port_pre_bridge_leave(struct dsa_port *dp, struct net_device *br);
|
||||
void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br);
|
||||
int dsa_port_lag_change(struct dsa_port *dp,
|
||||
struct netdev_lag_lower_state_info *linfo);
|
||||
int dsa_port_lag_join(struct dsa_port *dp, struct net_device *lag_dev,
|
||||
struct netdev_lag_upper_info *uinfo,
|
||||
struct netlink_ext_ack *extack);
|
||||
void dsa_port_pre_lag_leave(struct dsa_port *dp, struct net_device *lag_dev);
|
||||
void dsa_port_lag_leave(struct dsa_port *dp, struct net_device *lag_dev);
|
||||
int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering,
|
||||
struct netlink_ext_ack *extack);
|
||||
bool dsa_port_skip_vlan_configuration(struct dsa_port *dp);
|
||||
int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock);
|
||||
int dsa_port_mst_enable(struct dsa_port *dp, bool on,
|
||||
struct netlink_ext_ack *extack);
|
||||
int dsa_port_vlan_msti(struct dsa_port *dp,
|
||||
const struct switchdev_vlan_msti *msti);
|
||||
int dsa_port_mtu_change(struct dsa_port *dp, int new_mtu);
|
||||
int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr,
|
||||
u16 vid);
|
||||
int dsa_port_fdb_del(struct dsa_port *dp, const unsigned char *addr,
|
||||
u16 vid);
|
||||
int dsa_port_standalone_host_fdb_add(struct dsa_port *dp,
|
||||
const unsigned char *addr, u16 vid);
|
||||
int dsa_port_standalone_host_fdb_del(struct dsa_port *dp,
|
||||
const unsigned char *addr, u16 vid);
|
||||
int dsa_port_bridge_host_fdb_add(struct dsa_port *dp, const unsigned char *addr,
|
||||
u16 vid);
|
||||
int dsa_port_bridge_host_fdb_del(struct dsa_port *dp, const unsigned char *addr,
|
||||
u16 vid);
|
||||
int dsa_port_lag_fdb_add(struct dsa_port *dp, const unsigned char *addr,
|
||||
u16 vid);
|
||||
int dsa_port_lag_fdb_del(struct dsa_port *dp, const unsigned char *addr,
|
||||
u16 vid);
|
||||
int dsa_port_fdb_dump(struct dsa_port *dp, dsa_fdb_dump_cb_t *cb, void *data);
|
||||
int dsa_port_mdb_add(const struct dsa_port *dp,
|
||||
const struct switchdev_obj_port_mdb *mdb);
|
||||
int dsa_port_mdb_del(const struct dsa_port *dp,
|
||||
const struct switchdev_obj_port_mdb *mdb);
|
||||
int dsa_port_standalone_host_mdb_add(const struct dsa_port *dp,
|
||||
const struct switchdev_obj_port_mdb *mdb);
|
||||
int dsa_port_standalone_host_mdb_del(const struct dsa_port *dp,
|
||||
const struct switchdev_obj_port_mdb *mdb);
|
||||
int dsa_port_bridge_host_mdb_add(const struct dsa_port *dp,
|
||||
const struct switchdev_obj_port_mdb *mdb);
|
||||
int dsa_port_bridge_host_mdb_del(const struct dsa_port *dp,
|
||||
const struct switchdev_obj_port_mdb *mdb);
|
||||
int dsa_port_pre_bridge_flags(const struct dsa_port *dp,
|
||||
struct switchdev_brport_flags flags,
|
||||
struct netlink_ext_ack *extack);
|
||||
int dsa_port_bridge_flags(struct dsa_port *dp,
|
||||
struct switchdev_brport_flags flags,
|
||||
struct netlink_ext_ack *extack);
|
||||
int dsa_port_vlan_add(struct dsa_port *dp,
|
||||
const struct switchdev_obj_port_vlan *vlan,
|
||||
struct netlink_ext_ack *extack);
|
||||
int dsa_port_vlan_del(struct dsa_port *dp,
|
||||
const struct switchdev_obj_port_vlan *vlan);
|
||||
int dsa_port_host_vlan_add(struct dsa_port *dp,
|
||||
const struct switchdev_obj_port_vlan *vlan,
|
||||
struct netlink_ext_ack *extack);
|
||||
int dsa_port_host_vlan_del(struct dsa_port *dp,
|
||||
const struct switchdev_obj_port_vlan *vlan);
|
||||
int dsa_port_mrp_add(const struct dsa_port *dp,
|
||||
const struct switchdev_obj_mrp *mrp);
|
||||
int dsa_port_mrp_del(const struct dsa_port *dp,
|
||||
const struct switchdev_obj_mrp *mrp);
|
||||
int dsa_port_mrp_add_ring_role(const struct dsa_port *dp,
|
||||
const struct switchdev_obj_ring_role_mrp *mrp);
|
||||
int dsa_port_mrp_del_ring_role(const struct dsa_port *dp,
|
||||
const struct switchdev_obj_ring_role_mrp *mrp);
|
||||
int dsa_port_phylink_create(struct dsa_port *dp);
|
||||
void dsa_port_phylink_destroy(struct dsa_port *dp);
|
||||
int dsa_shared_port_link_register_of(struct dsa_port *dp);
|
||||
void dsa_shared_port_link_unregister_of(struct dsa_port *dp);
|
||||
int dsa_port_hsr_join(struct dsa_port *dp, struct net_device *hsr);
|
||||
void dsa_port_hsr_leave(struct dsa_port *dp, struct net_device *hsr);
|
||||
int dsa_port_tag_8021q_vlan_add(struct dsa_port *dp, u16 vid, bool broadcast);
|
||||
void dsa_port_tag_8021q_vlan_del(struct dsa_port *dp, u16 vid, bool broadcast);
|
||||
void dsa_port_set_host_flood(struct dsa_port *dp, bool uc, bool mc);
|
||||
int dsa_port_change_master(struct dsa_port *dp, struct net_device *master,
|
||||
struct netlink_ext_ack *extack);
|
||||
|
||||
/* slave.c */
|
||||
extern const struct dsa_device_ops notag_netdev_ops;
|
||||
extern struct notifier_block dsa_slave_switchdev_notifier;
|
||||
extern struct notifier_block dsa_slave_switchdev_blocking_notifier;
|
||||
|
||||
void dsa_slave_mii_bus_init(struct dsa_switch *ds);
|
||||
int dsa_slave_create(struct dsa_port *dp);
|
||||
void dsa_slave_destroy(struct net_device *slave_dev);
|
||||
int dsa_slave_suspend(struct net_device *slave_dev);
|
||||
int dsa_slave_resume(struct net_device *slave_dev);
|
||||
int dsa_slave_register_notifier(void);
|
||||
void dsa_slave_unregister_notifier(void);
|
||||
void dsa_slave_sync_ha(struct net_device *dev);
|
||||
void dsa_slave_unsync_ha(struct net_device *dev);
|
||||
void dsa_slave_setup_tagger(struct net_device *slave);
|
||||
int dsa_slave_change_mtu(struct net_device *dev, int new_mtu);
|
||||
int dsa_slave_change_master(struct net_device *dev, struct net_device *master,
|
||||
struct netlink_ext_ack *extack);
|
||||
int dsa_slave_manage_vlan_filtering(struct net_device *dev,
|
||||
bool vlan_filtering);
|
||||
|
||||
static inline struct dsa_port *dsa_slave_to_port(const struct net_device *dev)
|
||||
{
|
||||
struct dsa_slave_priv *p = netdev_priv(dev);
|
||||
|
||||
return p->dp;
|
||||
}
|
||||
|
||||
static inline struct net_device *
|
||||
dsa_slave_to_master(const struct net_device *dev)
|
||||
{
|
||||
struct dsa_port *dp = dsa_slave_to_port(dev);
|
||||
|
||||
return dsa_port_to_master(dp);
|
||||
}
|
||||
|
||||
/* If under a bridge with vlan_filtering=0, make sure to send pvid-tagged
|
||||
* frames as untagged, since the bridge will not untag them.
|
||||
*/
|
||||
static inline struct sk_buff *dsa_untag_bridge_pvid(struct sk_buff *skb)
|
||||
{
|
||||
struct dsa_port *dp = dsa_slave_to_port(skb->dev);
|
||||
struct net_device *br = dsa_port_bridge_dev_get(dp);
|
||||
struct net_device *dev = skb->dev;
|
||||
struct net_device *upper_dev;
|
||||
u16 vid, pvid, proto;
|
||||
int err;
|
||||
|
||||
if (!br || br_vlan_enabled(br))
|
||||
return skb;
|
||||
|
||||
err = br_vlan_get_proto(br, &proto);
|
||||
if (err)
|
||||
return skb;
|
||||
|
||||
/* Move VLAN tag from data to hwaccel */
|
||||
if (!skb_vlan_tag_present(skb) && skb->protocol == htons(proto)) {
|
||||
skb = skb_vlan_untag(skb);
|
||||
if (!skb)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!skb_vlan_tag_present(skb))
|
||||
return skb;
|
||||
|
||||
vid = skb_vlan_tag_get_id(skb);
|
||||
|
||||
/* We already run under an RCU read-side critical section since
|
||||
* we are called from netif_receive_skb_list_internal().
|
||||
*/
|
||||
err = br_vlan_get_pvid_rcu(dev, &pvid);
|
||||
if (err)
|
||||
return skb;
|
||||
|
||||
if (vid != pvid)
|
||||
return skb;
|
||||
|
||||
/* The sad part about attempting to untag from DSA is that we
|
||||
* don't know, unless we check, if the skb will end up in
|
||||
* the bridge's data path - br_allowed_ingress() - or not.
|
||||
* For example, there might be an 8021q upper for the
|
||||
* default_pvid of the bridge, which will steal VLAN-tagged traffic
|
||||
* from the bridge's data path. This is a configuration that DSA
|
||||
* supports because vlan_filtering is 0. In that case, we should
|
||||
* definitely keep the tag, to make sure it keeps working.
|
||||
*/
|
||||
upper_dev = __vlan_find_dev_deep_rcu(br, htons(proto), vid);
|
||||
if (upper_dev)
|
||||
return skb;
|
||||
|
||||
__vlan_hwaccel_clear_tag(skb);
|
||||
|
||||
return skb;
|
||||
}
|
||||
|
||||
/* For switches without hardware support for DSA tagging to be able
|
||||
* to support termination through the bridge.
|
||||
*/
|
||||
static inline struct net_device *
|
||||
dsa_find_designated_bridge_port_by_vid(struct net_device *master, u16 vid)
|
||||
{
|
||||
struct dsa_port *cpu_dp = master->dsa_ptr;
|
||||
struct dsa_switch_tree *dst = cpu_dp->dst;
|
||||
struct bridge_vlan_info vinfo;
|
||||
struct net_device *slave;
|
||||
struct dsa_port *dp;
|
||||
int err;
|
||||
|
||||
list_for_each_entry(dp, &dst->ports, list) {
|
||||
if (dp->type != DSA_PORT_TYPE_USER)
|
||||
continue;
|
||||
|
||||
if (!dp->bridge)
|
||||
continue;
|
||||
|
||||
if (dp->stp_state != BR_STATE_LEARNING &&
|
||||
dp->stp_state != BR_STATE_FORWARDING)
|
||||
continue;
|
||||
|
||||
/* Since the bridge might learn this packet, keep the CPU port
|
||||
* affinity with the port that will be used for the reply on
|
||||
* xmit.
|
||||
*/
|
||||
if (dp->cpu_dp != cpu_dp)
|
||||
continue;
|
||||
|
||||
slave = dp->slave;
|
||||
|
||||
err = br_vlan_get_info_rcu(slave, vid, &vinfo);
|
||||
if (err)
|
||||
continue;
|
||||
|
||||
return slave;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* If the ingress port offloads the bridge, we mark the frame as autonomously
|
||||
* forwarded by hardware, so the software bridge doesn't forward in twice, back
|
||||
* to us, because we already did. However, if we're in fallback mode and we do
|
||||
* software bridging, we are not offloading it, therefore the dp->bridge
|
||||
* pointer is not populated, and flooding needs to be done by software (we are
|
||||
* effectively operating in standalone ports mode).
|
||||
*/
|
||||
static inline void dsa_default_offload_fwd_mark(struct sk_buff *skb)
|
||||
{
|
||||
struct dsa_port *dp = dsa_slave_to_port(skb->dev);
|
||||
|
||||
skb->offload_fwd_mark = !!(dp->bridge);
|
||||
}
|
||||
|
||||
/* Helper for removing DSA header tags from packets in the RX path.
|
||||
* Must not be called before skb_pull(len).
|
||||
* skb->data
|
||||
* |
|
||||
* v
|
||||
* | | | | | | | | | | | | | | | | | | |
|
||||
* +-----------------------+-----------------------+---------------+-------+
|
||||
* | Destination MAC | Source MAC | DSA header | EType |
|
||||
* +-----------------------+-----------------------+---------------+-------+
|
||||
* | |
|
||||
* <----- len -----> <----- len ----->
|
||||
* |
|
||||
* >>>>>>> v
|
||||
* >>>>>>> | | | | | | | | | | | | | | |
|
||||
* >>>>>>> +-----------------------+-----------------------+-------+
|
||||
* >>>>>>> | Destination MAC | Source MAC | EType |
|
||||
* +-----------------------+-----------------------+-------+
|
||||
* ^
|
||||
* |
|
||||
* skb->data
|
||||
*/
|
||||
static inline void dsa_strip_etype_header(struct sk_buff *skb, int len)
|
||||
{
|
||||
memmove(skb->data - ETH_HLEN, skb->data - ETH_HLEN - len, 2 * ETH_ALEN);
|
||||
}
|
||||
|
||||
/* Helper for creating space for DSA header tags in TX path packets.
|
||||
* Must not be called before skb_push(len).
|
||||
*
|
||||
* Before:
|
||||
*
|
||||
* <<<<<<< | | | | | | | | | | | | | | |
|
||||
* ^ <<<<<<< +-----------------------+-----------------------+-------+
|
||||
* | <<<<<<< | Destination MAC | Source MAC | EType |
|
||||
* | +-----------------------+-----------------------+-------+
|
||||
* <----- len ----->
|
||||
* |
|
||||
* |
|
||||
* skb->data
|
||||
*
|
||||
* After:
|
||||
*
|
||||
* | | | | | | | | | | | | | | | | | | |
|
||||
* +-----------------------+-----------------------+---------------+-------+
|
||||
* | Destination MAC | Source MAC | DSA header | EType |
|
||||
* +-----------------------+-----------------------+---------------+-------+
|
||||
* ^ | |
|
||||
* | <----- len ----->
|
||||
* skb->data
|
||||
*/
|
||||
static inline void dsa_alloc_etype_header(struct sk_buff *skb, int len)
|
||||
{
|
||||
memmove(skb->data, skb->data + len, 2 * ETH_ALEN);
|
||||
}
|
||||
|
||||
/* On RX, eth_type_trans() on the DSA master pulls ETH_HLEN bytes starting from
|
||||
* skb_mac_header(skb), which leaves skb->data pointing at the first byte after
|
||||
* what the DSA master perceives as the EtherType (the beginning of the L3
|
||||
* protocol). Since DSA EtherType header taggers treat the EtherType as part of
|
||||
* the DSA tag itself, and the EtherType is 2 bytes in length, the DSA header
|
||||
* is located 2 bytes behind skb->data. Note that EtherType in this context
|
||||
* means the first 2 bytes of the DSA header, not the encapsulated EtherType
|
||||
* that will become visible after the DSA header is stripped.
|
||||
*/
|
||||
static inline void *dsa_etype_header_pos_rx(struct sk_buff *skb)
|
||||
{
|
||||
return skb->data - 2;
|
||||
}
|
||||
|
||||
/* On TX, skb->data points to skb_mac_header(skb), which means that EtherType
|
||||
* header taggers start exactly where the EtherType is (the EtherType is
|
||||
* treated as part of the DSA header).
|
||||
*/
|
||||
static inline void *dsa_etype_header_pos_tx(struct sk_buff *skb)
|
||||
{
|
||||
return skb->data + 2 * ETH_ALEN;
|
||||
}
|
||||
|
||||
/* switch.c */
|
||||
int dsa_switch_register_notifier(struct dsa_switch *ds);
|
||||
void dsa_switch_unregister_notifier(struct dsa_switch *ds);
|
||||
|
||||
static inline bool dsa_switch_supports_uc_filtering(struct dsa_switch *ds)
|
||||
{
|
||||
return ds->ops->port_fdb_add && ds->ops->port_fdb_del &&
|
||||
ds->fdb_isolation && !ds->vlan_filtering_is_global &&
|
||||
!ds->needs_standalone_vlan_filtering;
|
||||
}
|
||||
|
||||
static inline bool dsa_switch_supports_mc_filtering(struct dsa_switch *ds)
|
||||
{
|
||||
return ds->ops->port_mdb_add && ds->ops->port_mdb_del &&
|
||||
ds->fdb_isolation && !ds->vlan_filtering_is_global &&
|
||||
!ds->needs_standalone_vlan_filtering;
|
||||
}
|
||||
|
||||
/* dsa2.c */
|
||||
void dsa_lag_map(struct dsa_switch_tree *dst, struct dsa_lag *lag);
|
||||
void dsa_lag_unmap(struct dsa_switch_tree *dst, struct dsa_lag *lag);
|
||||
struct dsa_lag *dsa_tree_lag_find(struct dsa_switch_tree *dst,
|
||||
const struct net_device *lag_dev);
|
||||
struct net_device *dsa_tree_find_first_master(struct dsa_switch_tree *dst);
|
||||
int dsa_tree_notify(struct dsa_switch_tree *dst, unsigned long e, void *v);
|
||||
int dsa_broadcast(unsigned long e, void *v);
|
||||
int dsa_tree_change_tag_proto(struct dsa_switch_tree *dst,
|
||||
const struct dsa_device_ops *tag_ops,
|
||||
const struct dsa_device_ops *old_tag_ops);
|
||||
void dsa_tree_master_admin_state_change(struct dsa_switch_tree *dst,
|
||||
struct net_device *master,
|
||||
bool up);
|
||||
void dsa_tree_master_oper_state_change(struct dsa_switch_tree *dst,
|
||||
struct net_device *master,
|
||||
bool up);
|
||||
unsigned int dsa_bridge_num_get(const struct net_device *bridge_dev, int max);
|
||||
void dsa_bridge_num_put(const struct net_device *bridge_dev,
|
||||
unsigned int bridge_num);
|
||||
struct dsa_bridge *dsa_tree_bridge_find(struct dsa_switch_tree *dst,
|
||||
const struct net_device *br);
|
||||
|
||||
/* tag_8021q.c */
|
||||
int dsa_switch_tag_8021q_vlan_add(struct dsa_switch *ds,
|
||||
struct dsa_notifier_tag_8021q_vlan_info *info);
|
||||
int dsa_switch_tag_8021q_vlan_del(struct dsa_switch *ds,
|
||||
struct dsa_notifier_tag_8021q_vlan_info *info);
|
||||
|
||||
extern struct list_head dsa_tree_list;
|
||||
|
||||
#endif
|
@ -6,7 +6,15 @@
|
||||
* Vivien Didelot <vivien.didelot@savoirfairelinux.com>
|
||||
*/
|
||||
|
||||
#include "dsa_priv.h"
|
||||
#include <linux/ethtool.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/netlink.h>
|
||||
#include <net/dsa.h>
|
||||
|
||||
#include "dsa.h"
|
||||
#include "master.h"
|
||||
#include "port.h"
|
||||
#include "tag.h"
|
||||
|
||||
static int dsa_master_get_regs_len(struct net_device *dev)
|
||||
{
|
||||
|
19
net/dsa/master.h
Normal file
19
net/dsa/master.h
Normal file
@ -0,0 +1,19 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#ifndef __DSA_MASTER_H
|
||||
#define __DSA_MASTER_H
|
||||
|
||||
struct dsa_port;
|
||||
struct net_device;
|
||||
struct netdev_lag_upper_info;
|
||||
struct netlink_ext_ack;
|
||||
|
||||
int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp);
|
||||
void dsa_master_teardown(struct net_device *dev);
|
||||
int dsa_master_lag_setup(struct net_device *lag_dev, struct dsa_port *cpu_dp,
|
||||
struct netdev_lag_upper_info *uinfo,
|
||||
struct netlink_ext_ack *extack);
|
||||
void dsa_master_lag_teardown(struct net_device *lag_dev,
|
||||
struct dsa_port *cpu_dp);
|
||||
|
||||
#endif
|
@ -4,7 +4,8 @@
|
||||
#include <linux/netdevice.h>
|
||||
#include <net/rtnetlink.h>
|
||||
|
||||
#include "dsa_priv.h"
|
||||
#include "netlink.h"
|
||||
#include "slave.h"
|
||||
|
||||
static const struct nla_policy dsa_policy[IFLA_DSA_MAX + 1] = {
|
||||
[IFLA_DSA_MASTER] = { .type = NLA_U32 },
|
||||
|
8
net/dsa/netlink.h
Normal file
8
net/dsa/netlink.h
Normal file
@ -0,0 +1,8 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#ifndef __DSA_NETLINK_H
|
||||
#define __DSA_NETLINK_H
|
||||
|
||||
extern struct rtnl_link_ops dsa_link_ops __read_mostly;
|
||||
|
||||
#endif
|
@ -12,7 +12,11 @@
|
||||
#include <linux/of_mdio.h>
|
||||
#include <linux/of_net.h>
|
||||
|
||||
#include "dsa_priv.h"
|
||||
#include "dsa.h"
|
||||
#include "port.h"
|
||||
#include "slave.h"
|
||||
#include "switch.h"
|
||||
#include "tag_8021q.h"
|
||||
|
||||
/**
|
||||
* dsa_port_notify - Notify the switching fabric of changes to a port
|
||||
|
114
net/dsa/port.h
Normal file
114
net/dsa/port.h
Normal file
@ -0,0 +1,114 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#ifndef __DSA_PORT_H
|
||||
#define __DSA_PORT_H
|
||||
|
||||
#include <linux/types.h>
|
||||
#include <net/dsa.h>
|
||||
|
||||
struct ifreq;
|
||||
struct netdev_lag_lower_state_info;
|
||||
struct netdev_lag_upper_info;
|
||||
struct netlink_ext_ack;
|
||||
struct switchdev_mst_state;
|
||||
struct switchdev_obj_port_mdb;
|
||||
struct switchdev_vlan_msti;
|
||||
struct phy_device;
|
||||
|
||||
bool dsa_port_supports_hwtstamp(struct dsa_port *dp, struct ifreq *ifr);
|
||||
void dsa_port_set_tag_protocol(struct dsa_port *cpu_dp,
|
||||
const struct dsa_device_ops *tag_ops);
|
||||
int dsa_port_set_state(struct dsa_port *dp, u8 state, bool do_fast_age);
|
||||
int dsa_port_set_mst_state(struct dsa_port *dp,
|
||||
const struct switchdev_mst_state *state,
|
||||
struct netlink_ext_ack *extack);
|
||||
int dsa_port_enable_rt(struct dsa_port *dp, struct phy_device *phy);
|
||||
int dsa_port_enable(struct dsa_port *dp, struct phy_device *phy);
|
||||
void dsa_port_disable_rt(struct dsa_port *dp);
|
||||
void dsa_port_disable(struct dsa_port *dp);
|
||||
int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br,
|
||||
struct netlink_ext_ack *extack);
|
||||
void dsa_port_pre_bridge_leave(struct dsa_port *dp, struct net_device *br);
|
||||
void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br);
|
||||
int dsa_port_lag_change(struct dsa_port *dp,
|
||||
struct netdev_lag_lower_state_info *linfo);
|
||||
int dsa_port_lag_join(struct dsa_port *dp, struct net_device *lag_dev,
|
||||
struct netdev_lag_upper_info *uinfo,
|
||||
struct netlink_ext_ack *extack);
|
||||
void dsa_port_pre_lag_leave(struct dsa_port *dp, struct net_device *lag_dev);
|
||||
void dsa_port_lag_leave(struct dsa_port *dp, struct net_device *lag_dev);
|
||||
int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering,
|
||||
struct netlink_ext_ack *extack);
|
||||
bool dsa_port_skip_vlan_configuration(struct dsa_port *dp);
|
||||
int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock);
|
||||
int dsa_port_mst_enable(struct dsa_port *dp, bool on,
|
||||
struct netlink_ext_ack *extack);
|
||||
int dsa_port_vlan_msti(struct dsa_port *dp,
|
||||
const struct switchdev_vlan_msti *msti);
|
||||
int dsa_port_mtu_change(struct dsa_port *dp, int new_mtu);
|
||||
int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr,
|
||||
u16 vid);
|
||||
int dsa_port_fdb_del(struct dsa_port *dp, const unsigned char *addr,
|
||||
u16 vid);
|
||||
int dsa_port_standalone_host_fdb_add(struct dsa_port *dp,
|
||||
const unsigned char *addr, u16 vid);
|
||||
int dsa_port_standalone_host_fdb_del(struct dsa_port *dp,
|
||||
const unsigned char *addr, u16 vid);
|
||||
int dsa_port_bridge_host_fdb_add(struct dsa_port *dp, const unsigned char *addr,
|
||||
u16 vid);
|
||||
int dsa_port_bridge_host_fdb_del(struct dsa_port *dp, const unsigned char *addr,
|
||||
u16 vid);
|
||||
int dsa_port_lag_fdb_add(struct dsa_port *dp, const unsigned char *addr,
|
||||
u16 vid);
|
||||
int dsa_port_lag_fdb_del(struct dsa_port *dp, const unsigned char *addr,
|
||||
u16 vid);
|
||||
int dsa_port_fdb_dump(struct dsa_port *dp, dsa_fdb_dump_cb_t *cb, void *data);
|
||||
int dsa_port_mdb_add(const struct dsa_port *dp,
|
||||
const struct switchdev_obj_port_mdb *mdb);
|
||||
int dsa_port_mdb_del(const struct dsa_port *dp,
|
||||
const struct switchdev_obj_port_mdb *mdb);
|
||||
int dsa_port_standalone_host_mdb_add(const struct dsa_port *dp,
|
||||
const struct switchdev_obj_port_mdb *mdb);
|
||||
int dsa_port_standalone_host_mdb_del(const struct dsa_port *dp,
|
||||
const struct switchdev_obj_port_mdb *mdb);
|
||||
int dsa_port_bridge_host_mdb_add(const struct dsa_port *dp,
|
||||
const struct switchdev_obj_port_mdb *mdb);
|
||||
int dsa_port_bridge_host_mdb_del(const struct dsa_port *dp,
|
||||
const struct switchdev_obj_port_mdb *mdb);
|
||||
int dsa_port_pre_bridge_flags(const struct dsa_port *dp,
|
||||
struct switchdev_brport_flags flags,
|
||||
struct netlink_ext_ack *extack);
|
||||
int dsa_port_bridge_flags(struct dsa_port *dp,
|
||||
struct switchdev_brport_flags flags,
|
||||
struct netlink_ext_ack *extack);
|
||||
int dsa_port_vlan_add(struct dsa_port *dp,
|
||||
const struct switchdev_obj_port_vlan *vlan,
|
||||
struct netlink_ext_ack *extack);
|
||||
int dsa_port_vlan_del(struct dsa_port *dp,
|
||||
const struct switchdev_obj_port_vlan *vlan);
|
||||
int dsa_port_host_vlan_add(struct dsa_port *dp,
|
||||
const struct switchdev_obj_port_vlan *vlan,
|
||||
struct netlink_ext_ack *extack);
|
||||
int dsa_port_host_vlan_del(struct dsa_port *dp,
|
||||
const struct switchdev_obj_port_vlan *vlan);
|
||||
int dsa_port_mrp_add(const struct dsa_port *dp,
|
||||
const struct switchdev_obj_mrp *mrp);
|
||||
int dsa_port_mrp_del(const struct dsa_port *dp,
|
||||
const struct switchdev_obj_mrp *mrp);
|
||||
int dsa_port_mrp_add_ring_role(const struct dsa_port *dp,
|
||||
const struct switchdev_obj_ring_role_mrp *mrp);
|
||||
int dsa_port_mrp_del_ring_role(const struct dsa_port *dp,
|
||||
const struct switchdev_obj_ring_role_mrp *mrp);
|
||||
int dsa_port_phylink_create(struct dsa_port *dp);
|
||||
void dsa_port_phylink_destroy(struct dsa_port *dp);
|
||||
int dsa_shared_port_link_register_of(struct dsa_port *dp);
|
||||
void dsa_shared_port_link_unregister_of(struct dsa_port *dp);
|
||||
int dsa_port_hsr_join(struct dsa_port *dp, struct net_device *hsr);
|
||||
void dsa_port_hsr_leave(struct dsa_port *dp, struct net_device *hsr);
|
||||
int dsa_port_tag_8021q_vlan_add(struct dsa_port *dp, u16 vid, bool broadcast);
|
||||
void dsa_port_tag_8021q_vlan_del(struct dsa_port *dp, u16 vid, bool broadcast);
|
||||
void dsa_port_set_host_flood(struct dsa_port *dp, bool uc, bool mc);
|
||||
int dsa_port_change_master(struct dsa_port *dp, struct net_device *master,
|
||||
struct netlink_ext_ack *extack);
|
||||
|
||||
#endif
|
@ -22,7 +22,54 @@
|
||||
#include <net/dcbnl.h>
|
||||
#include <linux/netpoll.h>
|
||||
|
||||
#include "dsa_priv.h"
|
||||
#include "dsa.h"
|
||||
#include "port.h"
|
||||
#include "master.h"
|
||||
#include "netlink.h"
|
||||
#include "slave.h"
|
||||
#include "tag.h"
|
||||
|
||||
struct dsa_switchdev_event_work {
|
||||
struct net_device *dev;
|
||||
struct net_device *orig_dev;
|
||||
struct work_struct work;
|
||||
unsigned long event;
|
||||
/* Specific for SWITCHDEV_FDB_ADD_TO_DEVICE and
|
||||
* SWITCHDEV_FDB_DEL_TO_DEVICE
|
||||
*/
|
||||
unsigned char addr[ETH_ALEN];
|
||||
u16 vid;
|
||||
bool host_addr;
|
||||
};
|
||||
|
||||
enum dsa_standalone_event {
|
||||
DSA_UC_ADD,
|
||||
DSA_UC_DEL,
|
||||
DSA_MC_ADD,
|
||||
DSA_MC_DEL,
|
||||
};
|
||||
|
||||
struct dsa_standalone_event_work {
|
||||
struct work_struct work;
|
||||
struct net_device *dev;
|
||||
enum dsa_standalone_event event;
|
||||
unsigned char addr[ETH_ALEN];
|
||||
u16 vid;
|
||||
};
|
||||
|
||||
static bool dsa_switch_supports_uc_filtering(struct dsa_switch *ds)
|
||||
{
|
||||
return ds->ops->port_fdb_add && ds->ops->port_fdb_del &&
|
||||
ds->fdb_isolation && !ds->vlan_filtering_is_global &&
|
||||
!ds->needs_standalone_vlan_filtering;
|
||||
}
|
||||
|
||||
static bool dsa_switch_supports_mc_filtering(struct dsa_switch *ds)
|
||||
{
|
||||
return ds->ops->port_mdb_add && ds->ops->port_mdb_del &&
|
||||
ds->fdb_isolation && !ds->vlan_filtering_is_global &&
|
||||
!ds->needs_standalone_vlan_filtering;
|
||||
}
|
||||
|
||||
static void dsa_slave_standalone_event_work(struct work_struct *work)
|
||||
{
|
||||
|
69
net/dsa/slave.h
Normal file
69
net/dsa/slave.h
Normal file
@ -0,0 +1,69 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#ifndef __DSA_SLAVE_H
|
||||
#define __DSA_SLAVE_H
|
||||
|
||||
#include <linux/if_bridge.h>
|
||||
#include <linux/if_vlan.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/netpoll.h>
|
||||
#include <linux/types.h>
|
||||
#include <net/dsa.h>
|
||||
#include <net/gro_cells.h>
|
||||
|
||||
struct net_device;
|
||||
struct netlink_ext_ack;
|
||||
|
||||
extern struct notifier_block dsa_slave_switchdev_notifier;
|
||||
extern struct notifier_block dsa_slave_switchdev_blocking_notifier;
|
||||
|
||||
struct dsa_slave_priv {
|
||||
/* Copy of CPU port xmit for faster access in slave transmit hot path */
|
||||
struct sk_buff * (*xmit)(struct sk_buff *skb,
|
||||
struct net_device *dev);
|
||||
|
||||
struct gro_cells gcells;
|
||||
|
||||
/* DSA port data, such as switch, port index, etc. */
|
||||
struct dsa_port *dp;
|
||||
|
||||
#ifdef CONFIG_NET_POLL_CONTROLLER
|
||||
struct netpoll *netpoll;
|
||||
#endif
|
||||
|
||||
/* TC context */
|
||||
struct list_head mall_tc_list;
|
||||
};
|
||||
|
||||
void dsa_slave_mii_bus_init(struct dsa_switch *ds);
|
||||
int dsa_slave_create(struct dsa_port *dp);
|
||||
void dsa_slave_destroy(struct net_device *slave_dev);
|
||||
int dsa_slave_suspend(struct net_device *slave_dev);
|
||||
int dsa_slave_resume(struct net_device *slave_dev);
|
||||
int dsa_slave_register_notifier(void);
|
||||
void dsa_slave_unregister_notifier(void);
|
||||
void dsa_slave_sync_ha(struct net_device *dev);
|
||||
void dsa_slave_unsync_ha(struct net_device *dev);
|
||||
void dsa_slave_setup_tagger(struct net_device *slave);
|
||||
int dsa_slave_change_mtu(struct net_device *dev, int new_mtu);
|
||||
int dsa_slave_change_master(struct net_device *dev, struct net_device *master,
|
||||
struct netlink_ext_ack *extack);
|
||||
int dsa_slave_manage_vlan_filtering(struct net_device *dev,
|
||||
bool vlan_filtering);
|
||||
|
||||
static inline struct dsa_port *dsa_slave_to_port(const struct net_device *dev)
|
||||
{
|
||||
struct dsa_slave_priv *p = netdev_priv(dev);
|
||||
|
||||
return p->dp;
|
||||
}
|
||||
|
||||
static inline struct net_device *
|
||||
dsa_slave_to_master(const struct net_device *dev)
|
||||
{
|
||||
struct dsa_port *dp = dsa_slave_to_port(dev);
|
||||
|
||||
return dsa_port_to_master(dp);
|
||||
}
|
||||
|
||||
#endif
|
@ -12,7 +12,12 @@
|
||||
#include <linux/if_vlan.h>
|
||||
#include <net/switchdev.h>
|
||||
|
||||
#include "dsa_priv.h"
|
||||
#include "dsa.h"
|
||||
#include "netlink.h"
|
||||
#include "port.h"
|
||||
#include "slave.h"
|
||||
#include "switch.h"
|
||||
#include "tag_8021q.h"
|
||||
|
||||
static unsigned int dsa_switch_fastest_ageing_time(struct dsa_switch *ds,
|
||||
unsigned int ageing_time)
|
||||
@ -1013,6 +1018,52 @@ static int dsa_switch_event(struct notifier_block *nb,
|
||||
return notifier_from_errno(err);
|
||||
}
|
||||
|
||||
/**
|
||||
* dsa_tree_notify - Execute code for all switches in a DSA switch tree.
|
||||
* @dst: collection of struct dsa_switch devices to notify.
|
||||
* @e: event, must be of type DSA_NOTIFIER_*
|
||||
* @v: event-specific value.
|
||||
*
|
||||
* Given a struct dsa_switch_tree, this can be used to run a function once for
|
||||
* each member DSA switch. The other alternative of traversing the tree is only
|
||||
* through its ports list, which does not uniquely list the switches.
|
||||
*/
|
||||
int dsa_tree_notify(struct dsa_switch_tree *dst, unsigned long e, void *v)
|
||||
{
|
||||
struct raw_notifier_head *nh = &dst->nh;
|
||||
int err;
|
||||
|
||||
err = raw_notifier_call_chain(nh, e, v);
|
||||
|
||||
return notifier_to_errno(err);
|
||||
}
|
||||
|
||||
/**
|
||||
* dsa_broadcast - Notify all DSA trees in the system.
|
||||
* @e: event, must be of type DSA_NOTIFIER_*
|
||||
* @v: event-specific value.
|
||||
*
|
||||
* Can be used to notify the switching fabric of events such as cross-chip
|
||||
* bridging between disjoint trees (such as islands of tagger-compatible
|
||||
* switches bridged by an incompatible middle switch).
|
||||
*
|
||||
* WARNING: this function is not reliable during probe time, because probing
|
||||
* between trees is asynchronous and not all DSA trees might have probed.
|
||||
*/
|
||||
int dsa_broadcast(unsigned long e, void *v)
|
||||
{
|
||||
struct dsa_switch_tree *dst;
|
||||
int err = 0;
|
||||
|
||||
list_for_each_entry(dst, &dsa_tree_list, list) {
|
||||
err = dsa_tree_notify(dst, e, v);
|
||||
if (err)
|
||||
break;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int dsa_switch_register_notifier(struct dsa_switch *ds)
|
||||
{
|
||||
ds->nb.notifier_call = dsa_switch_event;
|
||||
|
120
net/dsa/switch.h
Normal file
120
net/dsa/switch.h
Normal file
@ -0,0 +1,120 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#ifndef __DSA_SWITCH_H
|
||||
#define __DSA_SWITCH_H
|
||||
|
||||
#include <net/dsa.h>
|
||||
|
||||
struct netlink_ext_ack;
|
||||
|
||||
enum {
|
||||
DSA_NOTIFIER_AGEING_TIME,
|
||||
DSA_NOTIFIER_BRIDGE_JOIN,
|
||||
DSA_NOTIFIER_BRIDGE_LEAVE,
|
||||
DSA_NOTIFIER_FDB_ADD,
|
||||
DSA_NOTIFIER_FDB_DEL,
|
||||
DSA_NOTIFIER_HOST_FDB_ADD,
|
||||
DSA_NOTIFIER_HOST_FDB_DEL,
|
||||
DSA_NOTIFIER_LAG_FDB_ADD,
|
||||
DSA_NOTIFIER_LAG_FDB_DEL,
|
||||
DSA_NOTIFIER_LAG_CHANGE,
|
||||
DSA_NOTIFIER_LAG_JOIN,
|
||||
DSA_NOTIFIER_LAG_LEAVE,
|
||||
DSA_NOTIFIER_MDB_ADD,
|
||||
DSA_NOTIFIER_MDB_DEL,
|
||||
DSA_NOTIFIER_HOST_MDB_ADD,
|
||||
DSA_NOTIFIER_HOST_MDB_DEL,
|
||||
DSA_NOTIFIER_VLAN_ADD,
|
||||
DSA_NOTIFIER_VLAN_DEL,
|
||||
DSA_NOTIFIER_HOST_VLAN_ADD,
|
||||
DSA_NOTIFIER_HOST_VLAN_DEL,
|
||||
DSA_NOTIFIER_MTU,
|
||||
DSA_NOTIFIER_TAG_PROTO,
|
||||
DSA_NOTIFIER_TAG_PROTO_CONNECT,
|
||||
DSA_NOTIFIER_TAG_PROTO_DISCONNECT,
|
||||
DSA_NOTIFIER_TAG_8021Q_VLAN_ADD,
|
||||
DSA_NOTIFIER_TAG_8021Q_VLAN_DEL,
|
||||
DSA_NOTIFIER_MASTER_STATE_CHANGE,
|
||||
};
|
||||
|
||||
/* DSA_NOTIFIER_AGEING_TIME */
|
||||
struct dsa_notifier_ageing_time_info {
|
||||
unsigned int ageing_time;
|
||||
};
|
||||
|
||||
/* DSA_NOTIFIER_BRIDGE_* */
|
||||
struct dsa_notifier_bridge_info {
|
||||
const struct dsa_port *dp;
|
||||
struct dsa_bridge bridge;
|
||||
bool tx_fwd_offload;
|
||||
struct netlink_ext_ack *extack;
|
||||
};
|
||||
|
||||
/* DSA_NOTIFIER_FDB_* */
|
||||
struct dsa_notifier_fdb_info {
|
||||
const struct dsa_port *dp;
|
||||
const unsigned char *addr;
|
||||
u16 vid;
|
||||
struct dsa_db db;
|
||||
};
|
||||
|
||||
/* DSA_NOTIFIER_LAG_FDB_* */
|
||||
struct dsa_notifier_lag_fdb_info {
|
||||
struct dsa_lag *lag;
|
||||
const unsigned char *addr;
|
||||
u16 vid;
|
||||
struct dsa_db db;
|
||||
};
|
||||
|
||||
/* DSA_NOTIFIER_MDB_* */
|
||||
struct dsa_notifier_mdb_info {
|
||||
const struct dsa_port *dp;
|
||||
const struct switchdev_obj_port_mdb *mdb;
|
||||
struct dsa_db db;
|
||||
};
|
||||
|
||||
/* DSA_NOTIFIER_LAG_* */
|
||||
struct dsa_notifier_lag_info {
|
||||
const struct dsa_port *dp;
|
||||
struct dsa_lag lag;
|
||||
struct netdev_lag_upper_info *info;
|
||||
struct netlink_ext_ack *extack;
|
||||
};
|
||||
|
||||
/* DSA_NOTIFIER_VLAN_* */
|
||||
struct dsa_notifier_vlan_info {
|
||||
const struct dsa_port *dp;
|
||||
const struct switchdev_obj_port_vlan *vlan;
|
||||
struct netlink_ext_ack *extack;
|
||||
};
|
||||
|
||||
/* DSA_NOTIFIER_MTU */
|
||||
struct dsa_notifier_mtu_info {
|
||||
const struct dsa_port *dp;
|
||||
int mtu;
|
||||
};
|
||||
|
||||
/* DSA_NOTIFIER_TAG_PROTO_* */
|
||||
struct dsa_notifier_tag_proto_info {
|
||||
const struct dsa_device_ops *tag_ops;
|
||||
};
|
||||
|
||||
/* DSA_NOTIFIER_TAG_8021Q_VLAN_* */
|
||||
struct dsa_notifier_tag_8021q_vlan_info {
|
||||
const struct dsa_port *dp;
|
||||
u16 vid;
|
||||
};
|
||||
|
||||
/* DSA_NOTIFIER_MASTER_STATE_CHANGE */
|
||||
struct dsa_notifier_master_state_info {
|
||||
const struct net_device *master;
|
||||
bool operational;
|
||||
};
|
||||
|
||||
int dsa_tree_notify(struct dsa_switch_tree *dst, unsigned long e, void *v);
|
||||
int dsa_broadcast(unsigned long e, void *v);
|
||||
|
||||
int dsa_switch_register_notifier(struct dsa_switch *ds);
|
||||
void dsa_switch_unregister_notifier(struct dsa_switch *ds);
|
||||
|
||||
#endif
|
243
net/dsa/tag.c
Normal file
243
net/dsa/tag.c
Normal file
@ -0,0 +1,243 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
/*
|
||||
* DSA tagging protocol handling
|
||||
*
|
||||
* Copyright (c) 2008-2009 Marvell Semiconductor
|
||||
* Copyright (c) 2013 Florian Fainelli <florian@openwrt.org>
|
||||
* Copyright (c) 2016 Andrew Lunn <andrew@lunn.ch>
|
||||
*/
|
||||
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/ptp_classify.h>
|
||||
#include <linux/skbuff.h>
|
||||
#include <net/dsa.h>
|
||||
#include <net/dst_metadata.h>
|
||||
|
||||
#include "slave.h"
|
||||
#include "tag.h"
|
||||
|
||||
static LIST_HEAD(dsa_tag_drivers_list);
|
||||
static DEFINE_MUTEX(dsa_tag_drivers_lock);
|
||||
|
||||
/* Determine if we should defer delivery of skb until we have a rx timestamp.
|
||||
*
|
||||
* Called from dsa_switch_rcv. For now, this will only work if tagging is
|
||||
* enabled on the switch. Normally the MAC driver would retrieve the hardware
|
||||
* timestamp when it reads the packet out of the hardware. However in a DSA
|
||||
* switch, the DSA driver owning the interface to which the packet is
|
||||
* delivered is never notified unless we do so here.
|
||||
*/
|
||||
static bool dsa_skb_defer_rx_timestamp(struct dsa_slave_priv *p,
|
||||
struct sk_buff *skb)
|
||||
{
|
||||
struct dsa_switch *ds = p->dp->ds;
|
||||
unsigned int type;
|
||||
|
||||
if (skb_headroom(skb) < ETH_HLEN)
|
||||
return false;
|
||||
|
||||
__skb_push(skb, ETH_HLEN);
|
||||
|
||||
type = ptp_classify_raw(skb);
|
||||
|
||||
__skb_pull(skb, ETH_HLEN);
|
||||
|
||||
if (type == PTP_CLASS_NONE)
|
||||
return false;
|
||||
|
||||
if (likely(ds->ops->port_rxtstamp))
|
||||
return ds->ops->port_rxtstamp(ds, p->dp->index, skb, type);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static int dsa_switch_rcv(struct sk_buff *skb, struct net_device *dev,
|
||||
struct packet_type *pt, struct net_device *unused)
|
||||
{
|
||||
struct metadata_dst *md_dst = skb_metadata_dst(skb);
|
||||
struct dsa_port *cpu_dp = dev->dsa_ptr;
|
||||
struct sk_buff *nskb = NULL;
|
||||
struct dsa_slave_priv *p;
|
||||
|
||||
if (unlikely(!cpu_dp)) {
|
||||
kfree_skb(skb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
skb = skb_unshare(skb, GFP_ATOMIC);
|
||||
if (!skb)
|
||||
return 0;
|
||||
|
||||
if (md_dst && md_dst->type == METADATA_HW_PORT_MUX) {
|
||||
unsigned int port = md_dst->u.port_info.port_id;
|
||||
|
||||
skb_dst_drop(skb);
|
||||
if (!skb_has_extensions(skb))
|
||||
skb->slow_gro = 0;
|
||||
|
||||
skb->dev = dsa_master_find_slave(dev, 0, port);
|
||||
if (likely(skb->dev)) {
|
||||
dsa_default_offload_fwd_mark(skb);
|
||||
nskb = skb;
|
||||
}
|
||||
} else {
|
||||
nskb = cpu_dp->rcv(skb, dev);
|
||||
}
|
||||
|
||||
if (!nskb) {
|
||||
kfree_skb(skb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
skb = nskb;
|
||||
skb_push(skb, ETH_HLEN);
|
||||
skb->pkt_type = PACKET_HOST;
|
||||
skb->protocol = eth_type_trans(skb, skb->dev);
|
||||
|
||||
if (unlikely(!dsa_slave_dev_check(skb->dev))) {
|
||||
/* Packet is to be injected directly on an upper
|
||||
* device, e.g. a team/bond, so skip all DSA-port
|
||||
* specific actions.
|
||||
*/
|
||||
netif_rx(skb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
p = netdev_priv(skb->dev);
|
||||
|
||||
if (unlikely(cpu_dp->ds->untag_bridge_pvid)) {
|
||||
nskb = dsa_untag_bridge_pvid(skb);
|
||||
if (!nskb) {
|
||||
kfree_skb(skb);
|
||||
return 0;
|
||||
}
|
||||
skb = nskb;
|
||||
}
|
||||
|
||||
dev_sw_netstats_rx_add(skb->dev, skb->len);
|
||||
|
||||
if (dsa_skb_defer_rx_timestamp(p, skb))
|
||||
return 0;
|
||||
|
||||
gro_cells_receive(&p->gcells, skb);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct packet_type dsa_pack_type __read_mostly = {
|
||||
.type = cpu_to_be16(ETH_P_XDSA),
|
||||
.func = dsa_switch_rcv,
|
||||
};
|
||||
|
||||
static void dsa_tag_driver_register(struct dsa_tag_driver *dsa_tag_driver,
|
||||
struct module *owner)
|
||||
{
|
||||
dsa_tag_driver->owner = owner;
|
||||
|
||||
mutex_lock(&dsa_tag_drivers_lock);
|
||||
list_add_tail(&dsa_tag_driver->list, &dsa_tag_drivers_list);
|
||||
mutex_unlock(&dsa_tag_drivers_lock);
|
||||
}
|
||||
|
||||
void dsa_tag_drivers_register(struct dsa_tag_driver *dsa_tag_driver_array[],
|
||||
unsigned int count, struct module *owner)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
dsa_tag_driver_register(dsa_tag_driver_array[i], owner);
|
||||
}
|
||||
|
||||
static void dsa_tag_driver_unregister(struct dsa_tag_driver *dsa_tag_driver)
|
||||
{
|
||||
mutex_lock(&dsa_tag_drivers_lock);
|
||||
list_del(&dsa_tag_driver->list);
|
||||
mutex_unlock(&dsa_tag_drivers_lock);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(dsa_tag_drivers_register);
|
||||
|
||||
void dsa_tag_drivers_unregister(struct dsa_tag_driver *dsa_tag_driver_array[],
|
||||
unsigned int count)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
dsa_tag_driver_unregister(dsa_tag_driver_array[i]);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(dsa_tag_drivers_unregister);
|
||||
|
||||
const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops)
|
||||
{
|
||||
return ops->name;
|
||||
};
|
||||
|
||||
/* Function takes a reference on the module owning the tagger,
|
||||
* so dsa_tag_driver_put must be called afterwards.
|
||||
*/
|
||||
const struct dsa_device_ops *dsa_tag_driver_get_by_name(const char *name)
|
||||
{
|
||||
const struct dsa_device_ops *ops = ERR_PTR(-ENOPROTOOPT);
|
||||
struct dsa_tag_driver *dsa_tag_driver;
|
||||
|
||||
request_module("%s%s", DSA_TAG_DRIVER_ALIAS, name);
|
||||
|
||||
mutex_lock(&dsa_tag_drivers_lock);
|
||||
list_for_each_entry(dsa_tag_driver, &dsa_tag_drivers_list, list) {
|
||||
const struct dsa_device_ops *tmp = dsa_tag_driver->ops;
|
||||
|
||||
if (strcmp(name, tmp->name))
|
||||
continue;
|
||||
|
||||
if (!try_module_get(dsa_tag_driver->owner))
|
||||
break;
|
||||
|
||||
ops = tmp;
|
||||
break;
|
||||
}
|
||||
mutex_unlock(&dsa_tag_drivers_lock);
|
||||
|
||||
return ops;
|
||||
}
|
||||
|
||||
const struct dsa_device_ops *dsa_tag_driver_get_by_id(int tag_protocol)
|
||||
{
|
||||
struct dsa_tag_driver *dsa_tag_driver;
|
||||
const struct dsa_device_ops *ops;
|
||||
bool found = false;
|
||||
|
||||
request_module("%sid-%d", DSA_TAG_DRIVER_ALIAS, tag_protocol);
|
||||
|
||||
mutex_lock(&dsa_tag_drivers_lock);
|
||||
list_for_each_entry(dsa_tag_driver, &dsa_tag_drivers_list, list) {
|
||||
ops = dsa_tag_driver->ops;
|
||||
if (ops->proto == tag_protocol) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
if (!try_module_get(dsa_tag_driver->owner))
|
||||
ops = ERR_PTR(-ENOPROTOOPT);
|
||||
} else {
|
||||
ops = ERR_PTR(-ENOPROTOOPT);
|
||||
}
|
||||
|
||||
mutex_unlock(&dsa_tag_drivers_lock);
|
||||
|
||||
return ops;
|
||||
}
|
||||
|
||||
void dsa_tag_driver_put(const struct dsa_device_ops *ops)
|
||||
{
|
||||
struct dsa_tag_driver *dsa_tag_driver;
|
||||
|
||||
mutex_lock(&dsa_tag_drivers_lock);
|
||||
list_for_each_entry(dsa_tag_driver, &dsa_tag_drivers_list, list) {
|
||||
if (dsa_tag_driver->ops == ops) {
|
||||
module_put(dsa_tag_driver->owner);
|
||||
break;
|
||||
}
|
||||
}
|
||||
mutex_unlock(&dsa_tag_drivers_lock);
|
||||
}
|
310
net/dsa/tag.h
Normal file
310
net/dsa/tag.h
Normal file
@ -0,0 +1,310 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#ifndef __DSA_TAG_H
|
||||
#define __DSA_TAG_H
|
||||
|
||||
#include <linux/if_vlan.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/types.h>
|
||||
#include <net/dsa.h>
|
||||
|
||||
#include "port.h"
|
||||
#include "slave.h"
|
||||
|
||||
struct dsa_tag_driver {
|
||||
const struct dsa_device_ops *ops;
|
||||
struct list_head list;
|
||||
struct module *owner;
|
||||
};
|
||||
|
||||
extern struct packet_type dsa_pack_type;
|
||||
|
||||
const struct dsa_device_ops *dsa_tag_driver_get_by_id(int tag_protocol);
|
||||
const struct dsa_device_ops *dsa_tag_driver_get_by_name(const char *name);
|
||||
void dsa_tag_driver_put(const struct dsa_device_ops *ops);
|
||||
const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops);
|
||||
|
||||
static inline int dsa_tag_protocol_overhead(const struct dsa_device_ops *ops)
|
||||
{
|
||||
return ops->needed_headroom + ops->needed_tailroom;
|
||||
}
|
||||
|
||||
static inline struct net_device *dsa_master_find_slave(struct net_device *dev,
|
||||
int device, int port)
|
||||
{
|
||||
struct dsa_port *cpu_dp = dev->dsa_ptr;
|
||||
struct dsa_switch_tree *dst = cpu_dp->dst;
|
||||
struct dsa_port *dp;
|
||||
|
||||
list_for_each_entry(dp, &dst->ports, list)
|
||||
if (dp->ds->index == device && dp->index == port &&
|
||||
dp->type == DSA_PORT_TYPE_USER)
|
||||
return dp->slave;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* If under a bridge with vlan_filtering=0, make sure to send pvid-tagged
|
||||
* frames as untagged, since the bridge will not untag them.
|
||||
*/
|
||||
static inline struct sk_buff *dsa_untag_bridge_pvid(struct sk_buff *skb)
|
||||
{
|
||||
struct dsa_port *dp = dsa_slave_to_port(skb->dev);
|
||||
struct net_device *br = dsa_port_bridge_dev_get(dp);
|
||||
struct net_device *dev = skb->dev;
|
||||
struct net_device *upper_dev;
|
||||
u16 vid, pvid, proto;
|
||||
int err;
|
||||
|
||||
if (!br || br_vlan_enabled(br))
|
||||
return skb;
|
||||
|
||||
err = br_vlan_get_proto(br, &proto);
|
||||
if (err)
|
||||
return skb;
|
||||
|
||||
/* Move VLAN tag from data to hwaccel */
|
||||
if (!skb_vlan_tag_present(skb) && skb->protocol == htons(proto)) {
|
||||
skb = skb_vlan_untag(skb);
|
||||
if (!skb)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!skb_vlan_tag_present(skb))
|
||||
return skb;
|
||||
|
||||
vid = skb_vlan_tag_get_id(skb);
|
||||
|
||||
/* We already run under an RCU read-side critical section since
|
||||
* we are called from netif_receive_skb_list_internal().
|
||||
*/
|
||||
err = br_vlan_get_pvid_rcu(dev, &pvid);
|
||||
if (err)
|
||||
return skb;
|
||||
|
||||
if (vid != pvid)
|
||||
return skb;
|
||||
|
||||
/* The sad part about attempting to untag from DSA is that we
|
||||
* don't know, unless we check, if the skb will end up in
|
||||
* the bridge's data path - br_allowed_ingress() - or not.
|
||||
* For example, there might be an 8021q upper for the
|
||||
* default_pvid of the bridge, which will steal VLAN-tagged traffic
|
||||
* from the bridge's data path. This is a configuration that DSA
|
||||
* supports because vlan_filtering is 0. In that case, we should
|
||||
* definitely keep the tag, to make sure it keeps working.
|
||||
*/
|
||||
upper_dev = __vlan_find_dev_deep_rcu(br, htons(proto), vid);
|
||||
if (upper_dev)
|
||||
return skb;
|
||||
|
||||
__vlan_hwaccel_clear_tag(skb);
|
||||
|
||||
return skb;
|
||||
}
|
||||
|
||||
/* For switches without hardware support for DSA tagging to be able
|
||||
* to support termination through the bridge.
|
||||
*/
|
||||
static inline struct net_device *
|
||||
dsa_find_designated_bridge_port_by_vid(struct net_device *master, u16 vid)
|
||||
{
|
||||
struct dsa_port *cpu_dp = master->dsa_ptr;
|
||||
struct dsa_switch_tree *dst = cpu_dp->dst;
|
||||
struct bridge_vlan_info vinfo;
|
||||
struct net_device *slave;
|
||||
struct dsa_port *dp;
|
||||
int err;
|
||||
|
||||
list_for_each_entry(dp, &dst->ports, list) {
|
||||
if (dp->type != DSA_PORT_TYPE_USER)
|
||||
continue;
|
||||
|
||||
if (!dp->bridge)
|
||||
continue;
|
||||
|
||||
if (dp->stp_state != BR_STATE_LEARNING &&
|
||||
dp->stp_state != BR_STATE_FORWARDING)
|
||||
continue;
|
||||
|
||||
/* Since the bridge might learn this packet, keep the CPU port
|
||||
* affinity with the port that will be used for the reply on
|
||||
* xmit.
|
||||
*/
|
||||
if (dp->cpu_dp != cpu_dp)
|
||||
continue;
|
||||
|
||||
slave = dp->slave;
|
||||
|
||||
err = br_vlan_get_info_rcu(slave, vid, &vinfo);
|
||||
if (err)
|
||||
continue;
|
||||
|
||||
return slave;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* If the ingress port offloads the bridge, we mark the frame as autonomously
|
||||
* forwarded by hardware, so the software bridge doesn't forward in twice, back
|
||||
* to us, because we already did. However, if we're in fallback mode and we do
|
||||
* software bridging, we are not offloading it, therefore the dp->bridge
|
||||
* pointer is not populated, and flooding needs to be done by software (we are
|
||||
* effectively operating in standalone ports mode).
|
||||
*/
|
||||
static inline void dsa_default_offload_fwd_mark(struct sk_buff *skb)
|
||||
{
|
||||
struct dsa_port *dp = dsa_slave_to_port(skb->dev);
|
||||
|
||||
skb->offload_fwd_mark = !!(dp->bridge);
|
||||
}
|
||||
|
||||
/* Helper for removing DSA header tags from packets in the RX path.
|
||||
* Must not be called before skb_pull(len).
|
||||
* skb->data
|
||||
* |
|
||||
* v
|
||||
* | | | | | | | | | | | | | | | | | | |
|
||||
* +-----------------------+-----------------------+---------------+-------+
|
||||
* | Destination MAC | Source MAC | DSA header | EType |
|
||||
* +-----------------------+-----------------------+---------------+-------+
|
||||
* | |
|
||||
* <----- len -----> <----- len ----->
|
||||
* |
|
||||
* >>>>>>> v
|
||||
* >>>>>>> | | | | | | | | | | | | | | |
|
||||
* >>>>>>> +-----------------------+-----------------------+-------+
|
||||
* >>>>>>> | Destination MAC | Source MAC | EType |
|
||||
* +-----------------------+-----------------------+-------+
|
||||
* ^
|
||||
* |
|
||||
* skb->data
|
||||
*/
|
||||
static inline void dsa_strip_etype_header(struct sk_buff *skb, int len)
|
||||
{
|
||||
memmove(skb->data - ETH_HLEN, skb->data - ETH_HLEN - len, 2 * ETH_ALEN);
|
||||
}
|
||||
|
||||
/* Helper for creating space for DSA header tags in TX path packets.
|
||||
* Must not be called before skb_push(len).
|
||||
*
|
||||
* Before:
|
||||
*
|
||||
* <<<<<<< | | | | | | | | | | | | | | |
|
||||
* ^ <<<<<<< +-----------------------+-----------------------+-------+
|
||||
* | <<<<<<< | Destination MAC | Source MAC | EType |
|
||||
* | +-----------------------+-----------------------+-------+
|
||||
* <----- len ----->
|
||||
* |
|
||||
* |
|
||||
* skb->data
|
||||
*
|
||||
* After:
|
||||
*
|
||||
* | | | | | | | | | | | | | | | | | | |
|
||||
* +-----------------------+-----------------------+---------------+-------+
|
||||
* | Destination MAC | Source MAC | DSA header | EType |
|
||||
* +-----------------------+-----------------------+---------------+-------+
|
||||
* ^ | |
|
||||
* | <----- len ----->
|
||||
* skb->data
|
||||
*/
|
||||
static inline void dsa_alloc_etype_header(struct sk_buff *skb, int len)
|
||||
{
|
||||
memmove(skb->data, skb->data + len, 2 * ETH_ALEN);
|
||||
}
|
||||
|
||||
/* On RX, eth_type_trans() on the DSA master pulls ETH_HLEN bytes starting from
|
||||
* skb_mac_header(skb), which leaves skb->data pointing at the first byte after
|
||||
* what the DSA master perceives as the EtherType (the beginning of the L3
|
||||
* protocol). Since DSA EtherType header taggers treat the EtherType as part of
|
||||
* the DSA tag itself, and the EtherType is 2 bytes in length, the DSA header
|
||||
* is located 2 bytes behind skb->data. Note that EtherType in this context
|
||||
* means the first 2 bytes of the DSA header, not the encapsulated EtherType
|
||||
* that will become visible after the DSA header is stripped.
|
||||
*/
|
||||
static inline void *dsa_etype_header_pos_rx(struct sk_buff *skb)
|
||||
{
|
||||
return skb->data - 2;
|
||||
}
|
||||
|
||||
/* On TX, skb->data points to skb_mac_header(skb), which means that EtherType
|
||||
* header taggers start exactly where the EtherType is (the EtherType is
|
||||
* treated as part of the DSA header).
|
||||
*/
|
||||
static inline void *dsa_etype_header_pos_tx(struct sk_buff *skb)
|
||||
{
|
||||
return skb->data + 2 * ETH_ALEN;
|
||||
}
|
||||
|
||||
/* Create 2 modaliases per tagging protocol, one to auto-load the module
|
||||
* given the ID reported by get_tag_protocol(), and the other by name.
|
||||
*/
|
||||
#define DSA_TAG_DRIVER_ALIAS "dsa_tag:"
|
||||
#define MODULE_ALIAS_DSA_TAG_DRIVER(__proto, __name) \
|
||||
MODULE_ALIAS(DSA_TAG_DRIVER_ALIAS __name); \
|
||||
MODULE_ALIAS(DSA_TAG_DRIVER_ALIAS "id-" \
|
||||
__stringify(__proto##_VALUE))
|
||||
|
||||
void dsa_tag_drivers_register(struct dsa_tag_driver *dsa_tag_driver_array[],
|
||||
unsigned int count,
|
||||
struct module *owner);
|
||||
void dsa_tag_drivers_unregister(struct dsa_tag_driver *dsa_tag_driver_array[],
|
||||
unsigned int count);
|
||||
|
||||
#define dsa_tag_driver_module_drivers(__dsa_tag_drivers_array, __count) \
|
||||
static int __init dsa_tag_driver_module_init(void) \
|
||||
{ \
|
||||
dsa_tag_drivers_register(__dsa_tag_drivers_array, __count, \
|
||||
THIS_MODULE); \
|
||||
return 0; \
|
||||
} \
|
||||
module_init(dsa_tag_driver_module_init); \
|
||||
\
|
||||
static void __exit dsa_tag_driver_module_exit(void) \
|
||||
{ \
|
||||
dsa_tag_drivers_unregister(__dsa_tag_drivers_array, __count); \
|
||||
} \
|
||||
module_exit(dsa_tag_driver_module_exit)
|
||||
|
||||
/**
|
||||
* module_dsa_tag_drivers() - Helper macro for registering DSA tag
|
||||
* drivers
|
||||
* @__ops_array: Array of tag driver structures
|
||||
*
|
||||
* Helper macro for DSA tag drivers which do not do anything special
|
||||
* in module init/exit. Each module may only use this macro once, and
|
||||
* calling it replaces module_init() and module_exit().
|
||||
*/
|
||||
#define module_dsa_tag_drivers(__ops_array) \
|
||||
dsa_tag_driver_module_drivers(__ops_array, ARRAY_SIZE(__ops_array))
|
||||
|
||||
#define DSA_TAG_DRIVER_NAME(__ops) dsa_tag_driver ## _ ## __ops
|
||||
|
||||
/* Create a static structure we can build a linked list of dsa_tag
|
||||
* drivers
|
||||
*/
|
||||
#define DSA_TAG_DRIVER(__ops) \
|
||||
static struct dsa_tag_driver DSA_TAG_DRIVER_NAME(__ops) = { \
|
||||
.ops = &__ops, \
|
||||
}
|
||||
|
||||
/**
|
||||
* module_dsa_tag_driver() - Helper macro for registering a single DSA tag
|
||||
* driver
|
||||
* @__ops: Single tag driver structures
|
||||
*
|
||||
* Helper macro for DSA tag drivers which do not do anything special
|
||||
* in module init/exit. Each module may only use this macro once, and
|
||||
* calling it replaces module_init() and module_exit().
|
||||
*/
|
||||
#define module_dsa_tag_driver(__ops) \
|
||||
DSA_TAG_DRIVER(__ops); \
|
||||
\
|
||||
static struct dsa_tag_driver *dsa_tag_driver_array[] = { \
|
||||
&DSA_TAG_DRIVER_NAME(__ops) \
|
||||
}; \
|
||||
module_dsa_tag_drivers(dsa_tag_driver_array)
|
||||
|
||||
#endif
|
@ -7,7 +7,10 @@
|
||||
#include <linux/if_vlan.h>
|
||||
#include <linux/dsa/8021q.h>
|
||||
|
||||
#include "dsa_priv.h"
|
||||
#include "port.h"
|
||||
#include "switch.h"
|
||||
#include "tag.h"
|
||||
#include "tag_8021q.h"
|
||||
|
||||
/* Binary structure of the fake 12-bit VID field (when the TPID is
|
||||
* ETH_P_DSA_8021Q):
|
||||
@ -60,6 +63,20 @@
|
||||
#define DSA_8021Q_PORT(x) (((x) << DSA_8021Q_PORT_SHIFT) & \
|
||||
DSA_8021Q_PORT_MASK)
|
||||
|
||||
struct dsa_tag_8021q_vlan {
|
||||
struct list_head list;
|
||||
int port;
|
||||
u16 vid;
|
||||
refcount_t refcount;
|
||||
};
|
||||
|
||||
struct dsa_8021q_context {
|
||||
struct dsa_switch *ds;
|
||||
struct list_head vlans;
|
||||
/* EtherType of RX VID, used for filtering on master interface */
|
||||
__be16 proto;
|
||||
};
|
||||
|
||||
u16 dsa_tag_8021q_bridge_vid(unsigned int bridge_num)
|
||||
{
|
||||
/* The VBID value of 0 is reserved for precise TX, but it is also
|
||||
|
27
net/dsa/tag_8021q.h
Normal file
27
net/dsa/tag_8021q.h
Normal file
@ -0,0 +1,27 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#ifndef __DSA_TAG_8021Q_H
|
||||
#define __DSA_TAG_8021Q_H
|
||||
|
||||
#include <net/dsa.h>
|
||||
|
||||
#include "switch.h"
|
||||
|
||||
struct sk_buff;
|
||||
struct net_device;
|
||||
|
||||
struct sk_buff *dsa_8021q_xmit(struct sk_buff *skb, struct net_device *netdev,
|
||||
u16 tpid, u16 tci);
|
||||
|
||||
void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id,
|
||||
int *vbid);
|
||||
|
||||
struct net_device *dsa_tag_8021q_find_port_by_vbid(struct net_device *master,
|
||||
int vbid);
|
||||
|
||||
int dsa_switch_tag_8021q_vlan_add(struct dsa_switch *ds,
|
||||
struct dsa_notifier_tag_8021q_vlan_info *info);
|
||||
int dsa_switch_tag_8021q_vlan_del(struct dsa_switch *ds,
|
||||
struct dsa_notifier_tag_8021q_vlan_info *info);
|
||||
|
||||
#endif
|
@ -7,7 +7,7 @@
|
||||
#include <linux/bitfield.h>
|
||||
#include <linux/etherdevice.h>
|
||||
|
||||
#include "dsa_priv.h"
|
||||
#include "tag.h"
|
||||
|
||||
#define AR9331_NAME "ar9331"
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include <linux/list.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
#include "dsa_priv.h"
|
||||
#include "tag.h"
|
||||
|
||||
#define BRCM_NAME "brcm"
|
||||
#define BRCM_LEGACY_NAME "brcm-legacy"
|
||||
|
@ -50,7 +50,7 @@
|
||||
#include <linux/list.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
#include "dsa_priv.h"
|
||||
#include "tag.h"
|
||||
|
||||
#define DSA_NAME "dsa"
|
||||
#define EDSA_NAME "edsa"
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include <linux/skbuff.h>
|
||||
#include <net/dsa.h>
|
||||
|
||||
#include "dsa_priv.h"
|
||||
#include "tag.h"
|
||||
|
||||
#define GSWIP_NAME "gswip"
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include <linux/skbuff.h>
|
||||
#include <net/dsa.h>
|
||||
|
||||
#include "dsa_priv.h"
|
||||
#include "tag.h"
|
||||
|
||||
#define HELLCREEK_NAME "hellcreek"
|
||||
|
||||
|
@ -7,7 +7,8 @@
|
||||
#include <linux/etherdevice.h>
|
||||
#include <linux/list.h>
|
||||
#include <net/dsa.h>
|
||||
#include "dsa_priv.h"
|
||||
|
||||
#include "tag.h"
|
||||
|
||||
#define KSZ8795_NAME "ksz8795"
|
||||
#define KSZ9477_NAME "ksz9477"
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <linux/list.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
#include "dsa_priv.h"
|
||||
#include "tag.h"
|
||||
|
||||
/* To define the outgoing port and to discover the incoming port a regular
|
||||
* VLAN tag is used by the LAN9303. But its VID meaning is 'special':
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <linux/etherdevice.h>
|
||||
#include <linux/if_vlan.h>
|
||||
|
||||
#include "dsa_priv.h"
|
||||
#include "tag.h"
|
||||
|
||||
#define MTK_NAME "mtk"
|
||||
|
||||
|
30
net/dsa/tag_none.c
Normal file
30
net/dsa/tag_none.c
Normal file
@ -0,0 +1,30 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
/*
|
||||
* net/dsa/tag_none.c - Traffic handling for switches with no tag
|
||||
* Copyright (c) 2008-2009 Marvell Semiconductor
|
||||
* Copyright (c) 2013 Florian Fainelli <florian@openwrt.org>
|
||||
*
|
||||
* WARNING: do not use this for new switches. In case of no hardware
|
||||
* tagging support, look at tag_8021q.c instead.
|
||||
*/
|
||||
|
||||
#include "tag.h"
|
||||
|
||||
#define NONE_NAME "none"
|
||||
|
||||
static struct sk_buff *dsa_slave_notag_xmit(struct sk_buff *skb,
|
||||
struct net_device *dev)
|
||||
{
|
||||
/* Just return the original SKB */
|
||||
return skb;
|
||||
}
|
||||
|
||||
static const struct dsa_device_ops none_ops = {
|
||||
.name = NONE_NAME,
|
||||
.proto = DSA_TAG_PROTO_NONE,
|
||||
.xmit = dsa_slave_notag_xmit,
|
||||
};
|
||||
|
||||
module_dsa_tag_driver(none_ops);
|
||||
MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_NONE, NONE_NAME);
|
||||
MODULE_LICENSE("GPL");
|
@ -2,7 +2,8 @@
|
||||
/* Copyright 2019 NXP
|
||||
*/
|
||||
#include <linux/dsa/ocelot.h>
|
||||
#include "dsa_priv.h"
|
||||
|
||||
#include "tag.h"
|
||||
|
||||
#define OCELOT_NAME "ocelot"
|
||||
#define SEVILLE_NAME "seville"
|
||||
|
@ -10,7 +10,9 @@
|
||||
*/
|
||||
#include <linux/dsa/8021q.h>
|
||||
#include <linux/dsa/ocelot.h>
|
||||
#include "dsa_priv.h"
|
||||
|
||||
#include "tag.h"
|
||||
#include "tag_8021q.h"
|
||||
|
||||
#define OCELOT_8021Q_NAME "ocelot-8021q"
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <net/dsa.h>
|
||||
#include <linux/dsa/tag_qca.h>
|
||||
|
||||
#include "dsa_priv.h"
|
||||
#include "tag.h"
|
||||
|
||||
#define QCA_NAME "qca"
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
#include <linux/etherdevice.h>
|
||||
#include <linux/bits.h>
|
||||
|
||||
#include "dsa_priv.h"
|
||||
#include "tag.h"
|
||||
|
||||
#define RTL4_A_NAME "rtl4a"
|
||||
|
||||
|
@ -77,7 +77,7 @@
|
||||
#include <linux/bits.h>
|
||||
#include <linux/etherdevice.h>
|
||||
|
||||
#include "dsa_priv.h"
|
||||
#include "tag.h"
|
||||
|
||||
/* Protocols supported:
|
||||
*
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include <linux/if_ether.h>
|
||||
#include <net/dsa.h>
|
||||
|
||||
#include "dsa_priv.h"
|
||||
#include "tag.h"
|
||||
|
||||
/* To define the outgoing port and to discover the incoming port a TAG is
|
||||
* inserted after Src MAC :
|
||||
|
@ -5,7 +5,9 @@
|
||||
#include <linux/dsa/sja1105.h>
|
||||
#include <linux/dsa/8021q.h>
|
||||
#include <linux/packing.h>
|
||||
#include "dsa_priv.h"
|
||||
|
||||
#include "tag.h"
|
||||
#include "tag_8021q.h"
|
||||
|
||||
#define SJA1105_NAME "sja1105"
|
||||
#define SJA1110_NAME "sja1110"
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <linux/list.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
#include "dsa_priv.h"
|
||||
#include "tag.h"
|
||||
|
||||
#define TRAILER_NAME "trailer"
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include <linux/bitops.h>
|
||||
|
||||
#include "dsa_priv.h"
|
||||
#include "tag.h"
|
||||
|
||||
#define XRS700X_NAME "xrs700x"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user