Skip to content

Commit 5075314

Browse files
Alexander Duyckdavem330
authored andcommitted
dsa: Split ops up, and avoid assigning tag_protocol and receive separately
This change addresses several issues. First, it was possible to set tag_protocol without setting the ops pointer. To correct that I have reordered things so that rcv is now populated before we set tag_protocol. Second, it didn't make much sense to keep setting the device ops each time a new slave was registered. So by moving the receive portion out into root switch initialization that issue should be addressed. Third, I wanted to avoid sending tags if the rcv pointer was not registered so I changed the tag check to verify if the rcv function pointer is set on the root tree. If it is then we start sending DSA tagged frames. Finally I split the device ops pointer in the structures into two spots. I placed the rcv function pointer in the root switch since this makes it easiest to access from there, and I placed the xmit function pointer in the slave for the same reason. Signed-off-by: Alexander Duyck <alexander.h.duyck@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 6cca9ad commit 5075314

9 files changed

Lines changed: 59 additions & 42 deletions

File tree

‎include/linux/netdevice.h‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,13 +1928,6 @@ struct udp_offload {
19281928
struct offload_callbacks callbacks;
19291929
};
19301930

1931-
struct dsa_device_ops {
1932-
netdev_tx_t (*xmit)(struct sk_buff *skb, struct net_device *dev);
1933-
int (*rcv)(struct sk_buff *skb, struct net_device *dev,
1934-
struct packet_type *pt, struct net_device *orig_dev);
1935-
};
1936-
1937-
19381931
/* often modified stats are per cpu, other are shared (netdev->stats) */
19391932
struct pcpu_sw_netstats {
19401933
u64 rx_packets;

‎include/net/dsa.h‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ struct dsa_platform_data {
7777
struct dsa_chip_data *chip;
7878
};
7979

80-
struct dsa_device_ops;
80+
struct packet_type;
8181

8282
struct dsa_switch_tree {
8383
/*
@@ -91,7 +91,10 @@ struct dsa_switch_tree {
9191
* protocol to use.
9292
*/
9393
struct net_device *master_netdev;
94-
const struct dsa_device_ops *ops;
94+
int (*rcv)(struct sk_buff *skb,
95+
struct net_device *dev,
96+
struct packet_type *pt,
97+
struct net_device *orig_dev);
9598
enum dsa_tag_protocol tag_protocol;
9699

97100
/*
@@ -218,7 +221,6 @@ static inline void *ds_to_priv(struct dsa_switch *ds)
218221

219222
static inline bool dsa_uses_tagged_protocol(struct dsa_switch_tree *dst)
220223
{
221-
return dst->tag_protocol != DSA_TAG_PROTO_NONE;
224+
return dst->rcv != NULL;
222225
}
223-
224226
#endif

‎net/dsa/dsa.c‎

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
*/
1111

1212
#include <linux/list.h>
13-
#include <linux/netdevice.h>
1413
#include <linux/platform_device.h>
1514
#include <linux/slab.h>
1615
#include <linux/module.h>
@@ -154,9 +153,34 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,
154153
* tagging protocol to the preferred tagging format of this
155154
* switch.
156155
*/
157-
if (ds->dst->cpu_switch == index)
158-
ds->dst->tag_protocol = drv->tag_protocol;
156+
if (dst->cpu_switch == index) {
157+
switch (drv->tag_protocol) {
158+
#ifdef CONFIG_NET_DSA_TAG_DSA
159+
case DSA_TAG_PROTO_DSA:
160+
dst->rcv = dsa_netdev_ops.rcv;
161+
break;
162+
#endif
163+
#ifdef CONFIG_NET_DSA_TAG_EDSA
164+
case DSA_TAG_PROTO_EDSA:
165+
dst->rcv = edsa_netdev_ops.rcv;
166+
break;
167+
#endif
168+
#ifdef CONFIG_NET_DSA_TAG_TRAILER
169+
case DSA_TAG_PROTO_TRAILER:
170+
dst->rcv = trailer_netdev_ops.rcv;
171+
break;
172+
#endif
173+
#ifdef CONFIG_NET_DSA_TAG_BRCM
174+
case DSA_TAG_PROTO_BRCM:
175+
dst->rcv = brcm_netdev_ops.rcv;
176+
break;
177+
#endif
178+
default:
179+
break;
180+
}
159181

182+
dst->tag_protocol = drv->tag_protocol;
183+
}
160184

161185
/*
162186
* Do basic register setup.
@@ -626,7 +650,7 @@ static int dsa_switch_rcv(struct sk_buff *skb, struct net_device *dev,
626650
return 0;
627651
}
628652

629-
return dst->ops->rcv(skb, dev, pt, orig_dev);
653+
return dst->rcv(skb, dev, pt, orig_dev);
630654
}
631655

632656
static struct packet_type dsa_pack_type __read_mostly = {

‎net/dsa/dsa_priv.h‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,22 @@
1212
#define __DSA_PRIV_H
1313

1414
#include <linux/phy.h>
15-
#include <net/dsa.h>
15+
#include <linux/netdevice.h>
16+
17+
struct dsa_device_ops {
18+
netdev_tx_t (*xmit)(struct sk_buff *skb, struct net_device *dev);
19+
int (*rcv)(struct sk_buff *skb, struct net_device *dev,
20+
struct packet_type *pt, struct net_device *orig_dev);
21+
};
1622

1723
struct dsa_slave_priv {
1824
/*
1925
* The linux network interface corresponding to this
2026
* switch port.
2127
*/
2228
struct net_device *dev;
29+
netdev_tx_t (*xmit)(struct sk_buff *skb,
30+
struct net_device *dev);
2331

2432
/*
2533
* Which switch this port is a part of, and the port index
@@ -43,6 +51,7 @@ struct dsa_slave_priv {
4351
extern char dsa_driver_version[];
4452

4553
/* slave.c */
54+
extern const struct dsa_device_ops notag_netdev_ops;
4655
void dsa_slave_mii_bus_init(struct dsa_switch *ds);
4756
struct net_device *dsa_slave_create(struct dsa_switch *ds,
4857
struct device *parent,

‎net/dsa/slave.c‎

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
*/
1010

1111
#include <linux/list.h>
12-
#include <linux/netdevice.h>
1312
#include <linux/etherdevice.h>
1413
#include <linux/phy.h>
1514
#include <linux/of_net.h>
@@ -176,9 +175,8 @@ static int dsa_slave_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
176175
static netdev_tx_t dsa_slave_xmit(struct sk_buff *skb, struct net_device *dev)
177176
{
178177
struct dsa_slave_priv *p = netdev_priv(dev);
179-
struct dsa_switch_tree *dst = p->parent->dst;
180178

181-
return dst->ops->xmit(skb, dev);
179+
return p->xmit(skb, dev);
182180
}
183181

184182
static netdev_tx_t dsa_slave_notag_xmit(struct sk_buff *skb,
@@ -325,11 +323,6 @@ static const struct net_device_ops dsa_slave_netdev_ops = {
325323
.ndo_do_ioctl = dsa_slave_ioctl,
326324
};
327325

328-
static const struct dsa_device_ops notag_netdev_ops = {
329-
.xmit = dsa_slave_notag_xmit,
330-
.rcv = NULL,
331-
};
332-
333326
static void dsa_slave_adjust_link(struct net_device *dev)
334327
{
335328
struct dsa_slave_priv *p = netdev_priv(dev);
@@ -435,41 +428,41 @@ dsa_slave_create(struct dsa_switch *ds, struct device *parent,
435428
slave_dev->tx_queue_len = 0;
436429
slave_dev->netdev_ops = &dsa_slave_netdev_ops;
437430

431+
SET_NETDEV_DEV(slave_dev, parent);
432+
slave_dev->dev.of_node = ds->pd->port_dn[port];
433+
slave_dev->vlan_features = master->vlan_features;
434+
435+
p = netdev_priv(slave_dev);
436+
p->dev = slave_dev;
437+
p->parent = ds;
438+
p->port = port;
439+
438440
switch (ds->dst->tag_protocol) {
439441
#ifdef CONFIG_NET_DSA_TAG_DSA
440442
case DSA_TAG_PROTO_DSA:
441-
ds->dst->ops = &dsa_netdev_ops;
443+
p->xmit = dsa_netdev_ops.xmit;
442444
break;
443445
#endif
444446
#ifdef CONFIG_NET_DSA_TAG_EDSA
445447
case DSA_TAG_PROTO_EDSA:
446-
ds->dst->ops = &edsa_netdev_ops;
448+
p->xmit = edsa_netdev_ops.xmit;
447449
break;
448450
#endif
449451
#ifdef CONFIG_NET_DSA_TAG_TRAILER
450452
case DSA_TAG_PROTO_TRAILER:
451-
ds->dst->ops = &trailer_netdev_ops;
453+
p->xmit = trailer_netdev_ops.xmit;
452454
break;
453455
#endif
454456
#ifdef CONFIG_NET_DSA_TAG_BRCM
455457
case DSA_TAG_PROTO_BRCM:
456-
ds->dst->ops = &brcm_netdev_ops;
458+
p->xmit = brcm_netdev_ops.xmit;
457459
break;
458460
#endif
459461
default:
460-
ds->dst->ops = &notag_netdev_ops;
462+
p->xmit = dsa_slave_notag_xmit;
461463
break;
462464
}
463465

464-
SET_NETDEV_DEV(slave_dev, parent);
465-
slave_dev->dev.of_node = ds->pd->port_dn[port];
466-
slave_dev->vlan_features = master->vlan_features;
467-
468-
p = netdev_priv(slave_dev);
469-
p->dev = slave_dev;
470-
p->parent = ds;
471-
p->port = port;
472-
473466
p->old_pause = -1;
474467
p->old_link = -1;
475468
p->old_duplex = -1;

‎net/dsa/tag_brcm.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include <linux/etherdevice.h>
1313
#include <linux/list.h>
14-
#include <linux/netdevice.h>
1514
#include <linux/slab.h>
1615
#include "dsa_priv.h"
1716

‎net/dsa/tag_dsa.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#include <linux/etherdevice.h>
1212
#include <linux/list.h>
13-
#include <linux/netdevice.h>
1413
#include <linux/slab.h>
1514
#include "dsa_priv.h"
1615

‎net/dsa/tag_edsa.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#include <linux/etherdevice.h>
1212
#include <linux/list.h>
13-
#include <linux/netdevice.h>
1413
#include <linux/slab.h>
1514
#include "dsa_priv.h"
1615

‎net/dsa/tag_trailer.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#include <linux/etherdevice.h>
1212
#include <linux/list.h>
13-
#include <linux/netdevice.h>
1413
#include <linux/slab.h>
1514
#include "dsa_priv.h"
1615

0 commit comments

Comments
 (0)