Commit 506d0a3e authored by David S. Miller's avatar David S. Miller

Merge branch 'dsa_ptr-port'

Vivien Didelot says:

====================
net: dsa: change dsa_ptr for a dsa_port

With DSA, a master net_device is physically wired to a dedicated CPU
switch port. For interaction with the DSA layer, the struct net_device
contains a dsa_ptr, which currently points to a dsa_switch_tree object.

This is only valid for a switch fabric with a single CPU port. In order
to support switch fabrics with multiple CPU ports, we first need to
change the type of dsa_ptr to what it really is: a dsa_port object.

This is what this patchset does. The first patches adds a
dsa_master_get_slave helper and cleans up portions of DSA core to make
the next patches more readable. These next patches prepare the xmit and
receive hot paths and finally change dsa_ptr.

Changes in v2:
  - introduce dsa_master_get_slave helper to simplify patch 6
  - keep hot path data at beginning of dsa_port for cacheline 1
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 075cfdd6 aa193d9b
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
struct netpoll_info; struct netpoll_info;
struct device; struct device;
struct phy_device; struct phy_device;
struct dsa_switch_tree; struct dsa_port;
/* 802.11 specific */ /* 802.11 specific */
struct wireless_dev; struct wireless_dev;
...@@ -1752,7 +1752,7 @@ struct net_device { ...@@ -1752,7 +1752,7 @@ struct net_device {
struct vlan_info __rcu *vlan_info; struct vlan_info __rcu *vlan_info;
#endif #endif
#if IS_ENABLED(CONFIG_NET_DSA) #if IS_ENABLED(CONFIG_NET_DSA)
struct dsa_switch_tree *dsa_ptr; struct dsa_port *dsa_ptr;
#endif #endif
#if IS_ENABLED(CONFIG_TIPC) #if IS_ENABLED(CONFIG_TIPC)
struct tipc_bearer __rcu *tipc_ptr; struct tipc_bearer __rcu *tipc_ptr;
......
...@@ -130,11 +130,6 @@ struct dsa_switch_tree { ...@@ -130,11 +130,6 @@ struct dsa_switch_tree {
*/ */
struct dsa_platform_data *pd; struct dsa_platform_data *pd;
/* Copy of tag_ops->rcv for faster access in hot path */
struct sk_buff * (*rcv)(struct sk_buff *skb,
struct net_device *dev,
struct packet_type *pt);
/* /*
* The switch port to which the CPU is attached. * The switch port to which the CPU is attached.
*/ */
...@@ -144,12 +139,6 @@ struct dsa_switch_tree { ...@@ -144,12 +139,6 @@ struct dsa_switch_tree {
* Data for the individual switch chips. * Data for the individual switch chips.
*/ */
struct dsa_switch *ds[DSA_MAX_SWITCHES]; struct dsa_switch *ds[DSA_MAX_SWITCHES];
/*
* Tagging protocol operations for adding and removing an
* encapsulation tag.
*/
const struct dsa_device_ops *tag_ops;
}; };
/* TC matchall action types, only mirroring for now */ /* TC matchall action types, only mirroring for now */
...@@ -175,6 +164,14 @@ struct dsa_mall_tc_entry { ...@@ -175,6 +164,14 @@ struct dsa_mall_tc_entry {
struct dsa_port { struct dsa_port {
/* CPU port tagging operations used by master or slave devices */
const struct dsa_device_ops *tag_ops;
/* Copies for faster access in master receive hot path */
struct dsa_switch_tree *dst;
struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev,
struct packet_type *pt);
struct dsa_switch *ds; struct dsa_switch *ds;
unsigned int index; unsigned int index;
const char *name; const char *name;
......
...@@ -160,12 +160,12 @@ EXPORT_SYMBOL_GPL(dsa_dev_to_net_device); ...@@ -160,12 +160,12 @@ EXPORT_SYMBOL_GPL(dsa_dev_to_net_device);
static int dsa_switch_rcv(struct sk_buff *skb, struct net_device *dev, static int dsa_switch_rcv(struct sk_buff *skb, struct net_device *dev,
struct packet_type *pt, struct net_device *unused) struct packet_type *pt, struct net_device *unused)
{ {
struct dsa_switch_tree *dst = dev->dsa_ptr; struct dsa_port *cpu_dp = dev->dsa_ptr;
struct sk_buff *nskb = NULL; struct sk_buff *nskb = NULL;
struct pcpu_sw_netstats *s; struct pcpu_sw_netstats *s;
struct dsa_slave_priv *p; struct dsa_slave_priv *p;
if (unlikely(dst == NULL)) { if (unlikely(!cpu_dp)) {
kfree_skb(skb); kfree_skb(skb);
return 0; return 0;
} }
...@@ -174,7 +174,7 @@ static int dsa_switch_rcv(struct sk_buff *skb, struct net_device *dev, ...@@ -174,7 +174,7 @@ static int dsa_switch_rcv(struct sk_buff *skb, struct net_device *dev,
if (!skb) if (!skb)
return 0; return 0;
nskb = dst->rcv(skb, dev, pt); nskb = cpu_dp->rcv(skb, dev, pt);
if (!nskb) { if (!nskb) {
kfree_skb(skb); kfree_skb(skb);
return 0; return 0;
......
...@@ -438,7 +438,7 @@ static int dsa_dst_apply(struct dsa_switch_tree *dst) ...@@ -438,7 +438,7 @@ static int dsa_dst_apply(struct dsa_switch_tree *dst)
* sent to the tag format's receive function. * sent to the tag format's receive function.
*/ */
wmb(); wmb();
dst->cpu_dp->netdev->dsa_ptr = dst; dst->cpu_dp->netdev->dsa_ptr = dst->cpu_dp;
err = dsa_master_ethtool_setup(dst->cpu_dp->netdev); err = dsa_master_ethtool_setup(dst->cpu_dp->netdev);
if (err) if (err)
...@@ -485,6 +485,7 @@ static int dsa_cpu_parse(struct dsa_port *port, u32 index, ...@@ -485,6 +485,7 @@ static int dsa_cpu_parse(struct dsa_port *port, u32 index,
struct dsa_switch_tree *dst, struct dsa_switch_tree *dst,
struct dsa_switch *ds) struct dsa_switch *ds)
{ {
const struct dsa_device_ops *tag_ops;
enum dsa_tag_protocol tag_protocol; enum dsa_tag_protocol tag_protocol;
struct net_device *ethernet_dev; struct net_device *ethernet_dev;
struct device_node *ethernet; struct device_node *ethernet;
...@@ -514,14 +515,18 @@ static int dsa_cpu_parse(struct dsa_port *port, u32 index, ...@@ -514,14 +515,18 @@ static int dsa_cpu_parse(struct dsa_port *port, u32 index,
ds->cpu_port_mask |= BIT(index); ds->cpu_port_mask |= BIT(index);
tag_protocol = ds->ops->get_tag_protocol(ds); tag_protocol = ds->ops->get_tag_protocol(ds);
dst->tag_ops = dsa_resolve_tag_protocol(tag_protocol); tag_ops = dsa_resolve_tag_protocol(tag_protocol);
if (IS_ERR(dst->tag_ops)) { if (IS_ERR(tag_ops)) {
dev_warn(ds->dev, "No tagger for this switch\n"); dev_warn(ds->dev, "No tagger for this switch\n");
ds->cpu_port_mask &= ~BIT(index); ds->cpu_port_mask &= ~BIT(index);
return PTR_ERR(dst->tag_ops); return PTR_ERR(tag_ops);
} }
dst->rcv = dst->tag_ops->rcv; dst->cpu_dp->tag_ops = tag_ops;
/* Make a few copies for faster access in master receive hot path */
dst->cpu_dp->rcv = dst->cpu_dp->tag_ops->rcv;
dst->cpu_dp->dst = dst;
return 0; return 0;
} }
......
...@@ -66,7 +66,7 @@ struct dsa_notifier_vlan_info { ...@@ -66,7 +66,7 @@ struct dsa_notifier_vlan_info {
}; };
struct dsa_slave_priv { struct dsa_slave_priv {
/* Copy of dp->ds->dst->tag_ops->xmit for faster access in hot path */ /* Copy of CPU port xmit for faster access in slave transmit hot path */
struct sk_buff * (*xmit)(struct sk_buff *skb, struct sk_buff * (*xmit)(struct sk_buff *skb,
struct net_device *dev); struct net_device *dev);
...@@ -113,6 +113,26 @@ int dsa_legacy_fdb_del(struct ndmsg *ndm, struct nlattr *tb[], ...@@ -113,6 +113,26 @@ int dsa_legacy_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
int dsa_master_ethtool_setup(struct net_device *dev); int dsa_master_ethtool_setup(struct net_device *dev);
void dsa_master_ethtool_restore(struct net_device *dev); void dsa_master_ethtool_restore(struct net_device *dev);
static inline struct net_device *dsa_master_get_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_switch *ds;
if (device < 0 || device >= DSA_MAX_SWITCHES)
return NULL;
ds = dst->ds[device];
if (!ds)
return NULL;
if (port < 0 || port >= ds->num_ports)
return NULL;
return ds->ports[port].netdev;
}
/* port.c */ /* port.c */
int dsa_port_set_state(struct dsa_port *dp, u8 state, int dsa_port_set_state(struct dsa_port *dp, u8 state,
struct switchdev_trans *trans); struct switchdev_trans *trans);
...@@ -182,9 +202,4 @@ static inline struct net_device *dsa_master_netdev(struct dsa_slave_priv *p) ...@@ -182,9 +202,4 @@ static inline struct net_device *dsa_master_netdev(struct dsa_slave_priv *p)
return p->dp->cpu_dp->netdev; return p->dp->cpu_dp->netdev;
} }
static inline struct dsa_port *dsa_get_cpu_port(struct dsa_switch_tree *dst)
{
return dst->cpu_dp;
}
#endif #endif
...@@ -144,14 +144,19 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, ...@@ -144,14 +144,19 @@ static int dsa_switch_setup_one(struct dsa_switch *ds,
* switch. * switch.
*/ */
if (dst->cpu_dp->ds == ds) { if (dst->cpu_dp->ds == ds) {
const struct dsa_device_ops *tag_ops;
enum dsa_tag_protocol tag_protocol; enum dsa_tag_protocol tag_protocol;
tag_protocol = ops->get_tag_protocol(ds); tag_protocol = ops->get_tag_protocol(ds);
dst->tag_ops = dsa_resolve_tag_protocol(tag_protocol); tag_ops = dsa_resolve_tag_protocol(tag_protocol);
if (IS_ERR(dst->tag_ops)) if (IS_ERR(tag_ops))
return PTR_ERR(dst->tag_ops); return PTR_ERR(tag_ops);
dst->rcv = dst->tag_ops->rcv; dst->cpu_dp->tag_ops = tag_ops;
/* Few copies for faster access in master receive hot path */
dst->cpu_dp->rcv = dst->cpu_dp->tag_ops->rcv;
dst->cpu_dp->dst = dst;
} }
memcpy(ds->rtable, cd->rtable, sizeof(ds->rtable)); memcpy(ds->rtable, cd->rtable, sizeof(ds->rtable));
...@@ -600,7 +605,7 @@ static int dsa_setup_dst(struct dsa_switch_tree *dst, struct net_device *dev, ...@@ -600,7 +605,7 @@ static int dsa_setup_dst(struct dsa_switch_tree *dst, struct net_device *dev,
* sent to the tag format's receive function. * sent to the tag format's receive function.
*/ */
wmb(); wmb();
dev->dsa_ptr = dst; dev->dsa_ptr = dst->cpu_dp;
return dsa_master_ethtool_setup(dst->cpu_dp->netdev); return dsa_master_ethtool_setup(dst->cpu_dp->netdev);
} }
......
...@@ -16,10 +16,10 @@ static void dsa_master_get_ethtool_stats(struct net_device *dev, ...@@ -16,10 +16,10 @@ static void dsa_master_get_ethtool_stats(struct net_device *dev,
struct ethtool_stats *stats, struct ethtool_stats *stats,
uint64_t *data) uint64_t *data)
{ {
struct dsa_switch_tree *dst = dev->dsa_ptr; struct dsa_port *cpu_dp = dev->dsa_ptr;
struct dsa_port *port = dst->cpu_dp; const struct ethtool_ops *ops = cpu_dp->orig_ethtool_ops;
struct dsa_switch *ds = port->ds; struct dsa_switch *ds = cpu_dp->ds;
const struct ethtool_ops *ops = port->orig_ethtool_ops; int port = cpu_dp->index;
int count = 0; int count = 0;
if (ops && ops->get_sset_count && ops->get_ethtool_stats) { if (ops && ops->get_sset_count && ops->get_ethtool_stats) {
...@@ -28,15 +28,14 @@ static void dsa_master_get_ethtool_stats(struct net_device *dev, ...@@ -28,15 +28,14 @@ static void dsa_master_get_ethtool_stats(struct net_device *dev,
} }
if (ds->ops->get_ethtool_stats) if (ds->ops->get_ethtool_stats)
ds->ops->get_ethtool_stats(ds, port->index, data + count); ds->ops->get_ethtool_stats(ds, port, data + count);
} }
static int dsa_master_get_sset_count(struct net_device *dev, int sset) static int dsa_master_get_sset_count(struct net_device *dev, int sset)
{ {
struct dsa_switch_tree *dst = dev->dsa_ptr; struct dsa_port *cpu_dp = dev->dsa_ptr;
struct dsa_port *port = dst->cpu_dp; const struct ethtool_ops *ops = cpu_dp->orig_ethtool_ops;
struct dsa_switch *ds = port->ds; struct dsa_switch *ds = cpu_dp->ds;
const struct ethtool_ops *ops = port->orig_ethtool_ops;
int count = 0; int count = 0;
if (ops && ops->get_sset_count) if (ops && ops->get_sset_count)
...@@ -51,17 +50,17 @@ static int dsa_master_get_sset_count(struct net_device *dev, int sset) ...@@ -51,17 +50,17 @@ static int dsa_master_get_sset_count(struct net_device *dev, int sset)
static void dsa_master_get_strings(struct net_device *dev, uint32_t stringset, static void dsa_master_get_strings(struct net_device *dev, uint32_t stringset,
uint8_t *data) uint8_t *data)
{ {
struct dsa_switch_tree *dst = dev->dsa_ptr; struct dsa_port *cpu_dp = dev->dsa_ptr;
struct dsa_port *port = dst->cpu_dp; const struct ethtool_ops *ops = cpu_dp->orig_ethtool_ops;
struct dsa_switch *ds = port->ds; struct dsa_switch *ds = cpu_dp->ds;
const struct ethtool_ops *ops = port->orig_ethtool_ops; int port = cpu_dp->index;
int len = ETH_GSTRING_LEN; int len = ETH_GSTRING_LEN;
int mcount = 0, count; int mcount = 0, count;
unsigned int i; unsigned int i;
uint8_t pfx[4]; uint8_t pfx[4];
uint8_t *ndata; uint8_t *ndata;
snprintf(pfx, sizeof(pfx), "p%.2d", port->index); snprintf(pfx, sizeof(pfx), "p%.2d", port);
/* We do not want to be NULL-terminated, since this is a prefix */ /* We do not want to be NULL-terminated, since this is a prefix */
pfx[sizeof(pfx) - 1] = '_'; pfx[sizeof(pfx) - 1] = '_';
...@@ -76,7 +75,7 @@ static void dsa_master_get_strings(struct net_device *dev, uint32_t stringset, ...@@ -76,7 +75,7 @@ static void dsa_master_get_strings(struct net_device *dev, uint32_t stringset,
* the output after to prepend our CPU port prefix we * the output after to prepend our CPU port prefix we
* constructed earlier * constructed earlier
*/ */
ds->ops->get_strings(ds, port->index, ndata); ds->ops->get_strings(ds, port, ndata);
count = ds->ops->get_sset_count(ds); count = ds->ops->get_sset_count(ds);
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
memmove(ndata + (i * len + sizeof(pfx)), memmove(ndata + (i * len + sizeof(pfx)),
...@@ -88,18 +87,17 @@ static void dsa_master_get_strings(struct net_device *dev, uint32_t stringset, ...@@ -88,18 +87,17 @@ static void dsa_master_get_strings(struct net_device *dev, uint32_t stringset,
int dsa_master_ethtool_setup(struct net_device *dev) int dsa_master_ethtool_setup(struct net_device *dev)
{ {
struct dsa_switch_tree *dst = dev->dsa_ptr; struct dsa_port *cpu_dp = dev->dsa_ptr;
struct dsa_port *port = dst->cpu_dp; struct dsa_switch *ds = cpu_dp->ds;
struct dsa_switch *ds = port->ds;
struct ethtool_ops *ops; struct ethtool_ops *ops;
ops = devm_kzalloc(ds->dev, sizeof(*ops), GFP_KERNEL); ops = devm_kzalloc(ds->dev, sizeof(*ops), GFP_KERNEL);
if (!ops) if (!ops)
return -ENOMEM; return -ENOMEM;
port->orig_ethtool_ops = dev->ethtool_ops; cpu_dp->orig_ethtool_ops = dev->ethtool_ops;
if (port->orig_ethtool_ops) if (cpu_dp->orig_ethtool_ops)
memcpy(ops, port->orig_ethtool_ops, sizeof(*ops)); memcpy(ops, cpu_dp->orig_ethtool_ops, sizeof(*ops));
ops->get_sset_count = dsa_master_get_sset_count; ops->get_sset_count = dsa_master_get_sset_count;
ops->get_ethtool_stats = dsa_master_get_ethtool_stats; ops->get_ethtool_stats = dsa_master_get_ethtool_stats;
...@@ -112,9 +110,8 @@ int dsa_master_ethtool_setup(struct net_device *dev) ...@@ -112,9 +110,8 @@ int dsa_master_ethtool_setup(struct net_device *dev)
void dsa_master_ethtool_restore(struct net_device *dev) void dsa_master_ethtool_restore(struct net_device *dev)
{ {
struct dsa_switch_tree *dst = dev->dsa_ptr; struct dsa_port *cpu_dp = dev->dsa_ptr;
struct dsa_port *port = dst->cpu_dp;
dev->ethtool_ops = port->orig_ethtool_ops; dev->ethtool_ops = cpu_dp->orig_ethtool_ops;
port->orig_ethtool_ops = NULL; cpu_dp->orig_ethtool_ops = NULL;
} }
...@@ -1117,7 +1117,6 @@ int dsa_slave_resume(struct net_device *slave_dev) ...@@ -1117,7 +1117,6 @@ int dsa_slave_resume(struct net_device *slave_dev)
int dsa_slave_create(struct dsa_port *port, const char *name) int dsa_slave_create(struct dsa_port *port, const char *name)
{ {
struct dsa_switch *ds = port->ds; struct dsa_switch *ds = port->ds;
struct dsa_switch_tree *dst = ds->dst;
struct net_device *master; struct net_device *master;
struct net_device *slave_dev; struct net_device *slave_dev;
struct dsa_slave_priv *p; struct dsa_slave_priv *p;
...@@ -1162,7 +1161,7 @@ int dsa_slave_create(struct dsa_port *port, const char *name) ...@@ -1162,7 +1161,7 @@ int dsa_slave_create(struct dsa_port *port, const char *name)
} }
p->dp = port; p->dp = port;
INIT_LIST_HEAD(&p->mall_tc_list); INIT_LIST_HEAD(&p->mall_tc_list);
p->xmit = dst->tag_ops->xmit; p->xmit = cpu_dp->tag_ops->xmit;
p->old_pause = -1; p->old_pause = -1;
p->old_link = -1; p->old_link = -1;
......
...@@ -92,9 +92,6 @@ static struct sk_buff *brcm_tag_xmit(struct sk_buff *skb, struct net_device *dev ...@@ -92,9 +92,6 @@ static struct sk_buff *brcm_tag_xmit(struct sk_buff *skb, struct net_device *dev
static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev, static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev,
struct packet_type *pt) struct packet_type *pt)
{ {
struct dsa_switch_tree *dst = dev->dsa_ptr;
struct dsa_port *cpu_dp = dsa_get_cpu_port(dst);
struct dsa_switch *ds = cpu_dp->ds;
int source_port; int source_port;
u8 *brcm_tag; u8 *brcm_tag;
...@@ -117,8 +114,8 @@ static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev, ...@@ -117,8 +114,8 @@ static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev,
/* Locate which port this is coming from */ /* Locate which port this is coming from */
source_port = brcm_tag[3] & BRCM_EG_PID_MASK; source_port = brcm_tag[3] & BRCM_EG_PID_MASK;
/* Validate port against switch setup, either the port is totally */ skb->dev = dsa_master_get_slave(dev, 0, source_port);
if (source_port >= ds->num_ports || !ds->ports[source_port].netdev) if (!skb->dev)
return NULL; return NULL;
/* Remove Broadcom tag and update checksum */ /* Remove Broadcom tag and update checksum */
...@@ -129,8 +126,6 @@ static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev, ...@@ -129,8 +126,6 @@ static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev,
skb->data - ETH_HLEN - BRCM_TAG_LEN, skb->data - ETH_HLEN - BRCM_TAG_LEN,
2 * ETH_ALEN); 2 * ETH_ALEN);
skb->dev = ds->ports[source_port].netdev;
return skb; return skb;
} }
......
...@@ -67,8 +67,6 @@ static struct sk_buff *dsa_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -67,8 +67,6 @@ static struct sk_buff *dsa_xmit(struct sk_buff *skb, struct net_device *dev)
static struct sk_buff *dsa_rcv(struct sk_buff *skb, struct net_device *dev, static struct sk_buff *dsa_rcv(struct sk_buff *skb, struct net_device *dev,
struct packet_type *pt) struct packet_type *pt)
{ {
struct dsa_switch_tree *dst = dev->dsa_ptr;
struct dsa_switch *ds;
u8 *dsa_header; u8 *dsa_header;
int source_device; int source_device;
int source_port; int source_port;
...@@ -93,18 +91,8 @@ static struct sk_buff *dsa_rcv(struct sk_buff *skb, struct net_device *dev, ...@@ -93,18 +91,8 @@ static struct sk_buff *dsa_rcv(struct sk_buff *skb, struct net_device *dev,
source_device = dsa_header[0] & 0x1f; source_device = dsa_header[0] & 0x1f;
source_port = (dsa_header[1] >> 3) & 0x1f; source_port = (dsa_header[1] >> 3) & 0x1f;
/* skb->dev = dsa_master_get_slave(dev, source_device, source_port);
* Check that the source device exists and that the source if (!skb->dev)
* port is a registered DSA port.
*/
if (source_device >= DSA_MAX_SWITCHES)
return NULL;
ds = dst->ds[source_device];
if (!ds)
return NULL;
if (source_port >= ds->num_ports || !ds->ports[source_port].netdev)
return NULL; return NULL;
/* /*
...@@ -153,8 +141,6 @@ static struct sk_buff *dsa_rcv(struct sk_buff *skb, struct net_device *dev, ...@@ -153,8 +141,6 @@ static struct sk_buff *dsa_rcv(struct sk_buff *skb, struct net_device *dev,
2 * ETH_ALEN); 2 * ETH_ALEN);
} }
skb->dev = ds->ports[source_port].netdev;
return skb; return skb;
} }
......
...@@ -80,8 +80,6 @@ static struct sk_buff *edsa_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -80,8 +80,6 @@ static struct sk_buff *edsa_xmit(struct sk_buff *skb, struct net_device *dev)
static struct sk_buff *edsa_rcv(struct sk_buff *skb, struct net_device *dev, static struct sk_buff *edsa_rcv(struct sk_buff *skb, struct net_device *dev,
struct packet_type *pt) struct packet_type *pt)
{ {
struct dsa_switch_tree *dst = dev->dsa_ptr;
struct dsa_switch *ds;
u8 *edsa_header; u8 *edsa_header;
int source_device; int source_device;
int source_port; int source_port;
...@@ -106,18 +104,8 @@ static struct sk_buff *edsa_rcv(struct sk_buff *skb, struct net_device *dev, ...@@ -106,18 +104,8 @@ static struct sk_buff *edsa_rcv(struct sk_buff *skb, struct net_device *dev,
source_device = edsa_header[0] & 0x1f; source_device = edsa_header[0] & 0x1f;
source_port = (edsa_header[1] >> 3) & 0x1f; source_port = (edsa_header[1] >> 3) & 0x1f;
/* skb->dev = dsa_master_get_slave(dev, source_device, source_port);
* Check that the source device exists and that the source if (!skb->dev)
* port is a registered DSA port.
*/
if (source_device >= DSA_MAX_SWITCHES)
return NULL;
ds = dst->ds[source_device];
if (!ds)
return NULL;
if (source_port >= ds->num_ports || !ds->ports[source_port].netdev)
return NULL; return NULL;
/* /*
...@@ -172,8 +160,6 @@ static struct sk_buff *edsa_rcv(struct sk_buff *skb, struct net_device *dev, ...@@ -172,8 +160,6 @@ static struct sk_buff *edsa_rcv(struct sk_buff *skb, struct net_device *dev,
2 * ETH_ALEN); 2 * ETH_ALEN);
} }
skb->dev = ds->ports[source_port].netdev;
return skb; return skb;
} }
......
...@@ -80,22 +80,19 @@ static struct sk_buff *ksz_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -80,22 +80,19 @@ static struct sk_buff *ksz_xmit(struct sk_buff *skb, struct net_device *dev)
static struct sk_buff *ksz_rcv(struct sk_buff *skb, struct net_device *dev, static struct sk_buff *ksz_rcv(struct sk_buff *skb, struct net_device *dev,
struct packet_type *pt) struct packet_type *pt)
{ {
struct dsa_switch_tree *dst = dev->dsa_ptr;
struct dsa_port *cpu_dp = dsa_get_cpu_port(dst);
struct dsa_switch *ds = cpu_dp->ds;
u8 *tag; u8 *tag;
int source_port; int source_port;
tag = skb_tail_pointer(skb) - KSZ_EGRESS_TAG_LEN; tag = skb_tail_pointer(skb) - KSZ_EGRESS_TAG_LEN;
source_port = tag[0] & 7; source_port = tag[0] & 7;
if (source_port >= ds->num_ports || !ds->ports[source_port].netdev)
skb->dev = dsa_master_get_slave(dev, 0, source_port);
if (!skb->dev)
return NULL; return NULL;
pskb_trim_rcsum(skb, skb->len - KSZ_EGRESS_TAG_LEN); pskb_trim_rcsum(skb, skb->len - KSZ_EGRESS_TAG_LEN);
skb->dev = ds->ports[source_port].netdev;
return skb; return skb;
} }
......
...@@ -71,17 +71,8 @@ static struct sk_buff *lan9303_rcv(struct sk_buff *skb, struct net_device *dev, ...@@ -71,17 +71,8 @@ static struct sk_buff *lan9303_rcv(struct sk_buff *skb, struct net_device *dev,
struct packet_type *pt) struct packet_type *pt)
{ {
u16 *lan9303_tag; u16 *lan9303_tag;
struct dsa_switch_tree *dst = dev->dsa_ptr;
struct dsa_switch *ds;
unsigned int source_port; unsigned int source_port;
ds = dst->ds[0];
if (unlikely(!ds)) {
dev_warn_ratelimited(&dev->dev, "Dropping packet, due to missing DSA switch device\n");
return NULL;
}
if (unlikely(!pskb_may_pull(skb, LAN9303_TAG_LEN))) { if (unlikely(!pskb_may_pull(skb, LAN9303_TAG_LEN))) {
dev_warn_ratelimited(&dev->dev, dev_warn_ratelimited(&dev->dev,
"Dropping packet, cannot pull\n"); "Dropping packet, cannot pull\n");
...@@ -103,16 +94,12 @@ static struct sk_buff *lan9303_rcv(struct sk_buff *skb, struct net_device *dev, ...@@ -103,16 +94,12 @@ static struct sk_buff *lan9303_rcv(struct sk_buff *skb, struct net_device *dev,
source_port = ntohs(lan9303_tag[1]) & 0x3; source_port = ntohs(lan9303_tag[1]) & 0x3;
if (source_port >= ds->num_ports) { skb->dev = dsa_master_get_slave(dev, 0, source_port);
if (!skb->dev) {
dev_warn_ratelimited(&dev->dev, "Dropping packet due to invalid source port\n"); dev_warn_ratelimited(&dev->dev, "Dropping packet due to invalid source port\n");
return NULL; return NULL;
} }
if (!ds->ports[source_port].netdev) {
dev_warn_ratelimited(&dev->dev, "Dropping packet due to invalid netdev or device\n");
return NULL;
}
/* remove the special VLAN tag between the MAC addresses /* remove the special VLAN tag between the MAC addresses
* and the current ethertype field. * and the current ethertype field.
*/ */
...@@ -120,9 +107,6 @@ static struct sk_buff *lan9303_rcv(struct sk_buff *skb, struct net_device *dev, ...@@ -120,9 +107,6 @@ static struct sk_buff *lan9303_rcv(struct sk_buff *skb, struct net_device *dev,
memmove(skb->data - ETH_HLEN, skb->data - (ETH_HLEN + LAN9303_TAG_LEN), memmove(skb->data - ETH_HLEN, skb->data - (ETH_HLEN + LAN9303_TAG_LEN),
2 * ETH_ALEN); 2 * ETH_ALEN);
/* forward the packet to the dedicated interface */
skb->dev = ds->ports[source_port].netdev;
return skb; return skb;
} }
......
...@@ -46,8 +46,6 @@ static struct sk_buff *mtk_tag_xmit(struct sk_buff *skb, ...@@ -46,8 +46,6 @@ static struct sk_buff *mtk_tag_xmit(struct sk_buff *skb,
static struct sk_buff *mtk_tag_rcv(struct sk_buff *skb, struct net_device *dev, static struct sk_buff *mtk_tag_rcv(struct sk_buff *skb, struct net_device *dev,
struct packet_type *pt) struct packet_type *pt)
{ {
struct dsa_switch_tree *dst = dev->dsa_ptr;
struct dsa_switch *ds;
int port; int port;
__be16 *phdr, hdr; __be16 *phdr, hdr;
...@@ -68,20 +66,12 @@ static struct sk_buff *mtk_tag_rcv(struct sk_buff *skb, struct net_device *dev, ...@@ -68,20 +66,12 @@ static struct sk_buff *mtk_tag_rcv(struct sk_buff *skb, struct net_device *dev,
skb->data - ETH_HLEN - MTK_HDR_LEN, skb->data - ETH_HLEN - MTK_HDR_LEN,
2 * ETH_ALEN); 2 * ETH_ALEN);
/* This protocol doesn't support cascading multiple
* switches so it's safe to assume the switch is first
* in the tree.
*/
ds = dst->ds[0];
if (!ds)
return NULL;
/* Get source port information */ /* Get source port information */
port = (hdr & MTK_HDR_RECV_SOURCE_PORT_MASK); port = (hdr & MTK_HDR_RECV_SOURCE_PORT_MASK);
if (!ds->ports[port].netdev)
return NULL;
skb->dev = ds->ports[port].netdev; skb->dev = dsa_master_get_slave(dev, 0, port);
if (!skb->dev)
return NULL;
return skb; return skb;
} }
......
...@@ -65,9 +65,6 @@ static struct sk_buff *qca_tag_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -65,9 +65,6 @@ static struct sk_buff *qca_tag_xmit(struct sk_buff *skb, struct net_device *dev)
static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev, static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev,
struct packet_type *pt) struct packet_type *pt)
{ {
struct dsa_switch_tree *dst = dev->dsa_ptr;
struct dsa_port *cpu_dp = dsa_get_cpu_port(dst);
struct dsa_switch *ds;
u8 ver; u8 ver;
int port; int port;
__be16 *phdr, hdr; __be16 *phdr, hdr;
...@@ -92,20 +89,12 @@ static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev, ...@@ -92,20 +89,12 @@ static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev,
memmove(skb->data - ETH_HLEN, skb->data - ETH_HLEN - QCA_HDR_LEN, memmove(skb->data - ETH_HLEN, skb->data - ETH_HLEN - QCA_HDR_LEN,
ETH_HLEN - QCA_HDR_LEN); ETH_HLEN - QCA_HDR_LEN);
/* This protocol doesn't support cascading multiple switches so it's
* safe to assume the switch is first in the tree
*/
ds = cpu_dp->ds;
if (!ds)
return NULL;
/* Get source port information */ /* Get source port information */
port = (hdr & QCA_HDR_RECV_SOURCE_PORT_MASK); port = (hdr & QCA_HDR_RECV_SOURCE_PORT_MASK);
if (!ds->ports[port].netdev)
return NULL;
/* Update skb & forward the frame accordingly */ skb->dev = dsa_master_get_slave(dev, 0, port);
skb->dev = ds->ports[port].netdev; if (!skb->dev)
return NULL;
return skb; return skb;
} }
......
...@@ -58,9 +58,6 @@ static struct sk_buff *trailer_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -58,9 +58,6 @@ static struct sk_buff *trailer_xmit(struct sk_buff *skb, struct net_device *dev)
static struct sk_buff *trailer_rcv(struct sk_buff *skb, struct net_device *dev, static struct sk_buff *trailer_rcv(struct sk_buff *skb, struct net_device *dev,
struct packet_type *pt) struct packet_type *pt)
{ {
struct dsa_switch_tree *dst = dev->dsa_ptr;
struct dsa_port *cpu_dp = dsa_get_cpu_port(dst);
struct dsa_switch *ds = cpu_dp->ds;
u8 *trailer; u8 *trailer;
int source_port; int source_port;
...@@ -73,13 +70,13 @@ static struct sk_buff *trailer_rcv(struct sk_buff *skb, struct net_device *dev, ...@@ -73,13 +70,13 @@ static struct sk_buff *trailer_rcv(struct sk_buff *skb, struct net_device *dev,
return NULL; return NULL;
source_port = trailer[1] & 7; source_port = trailer[1] & 7;
if (source_port >= ds->num_ports || !ds->ports[source_port].netdev)
skb->dev = dsa_master_get_slave(dev, 0, source_port);
if (!skb->dev)
return NULL; return NULL;
pskb_trim_rcsum(skb, skb->len - 4); pskb_trim_rcsum(skb, skb->len - 4);
skb->dev = ds->ports[source_port].netdev;
return skb; return skb;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment