aboutsummaryrefslogtreecommitdiffstats
path: root/net/dsa
diff options
context:
space:
mode:
authorAndrew Lunn <andrew@lunn.ch>2016-06-04 15:17:03 -0400
committerDavid S. Miller <davem@davemloft.net>2016-06-04 17:29:54 -0400
commit39a7f2a4eb496c0c68cc93fcb403190b48605168 (patch)
tree4c9edb3b66b95a2a6215e2844c131ac618424b8b /net/dsa
parent5377b802fc9fde9442dcaba571edefcb73765056 (diff)
net: dsa: Refactor selection of tag ops into a function
Replace the two switch statements with an array lookup, and store the result in the dsa tree structure. The drivers no longer need to know the selected tag protocol, so remove it from the dsa switch structure. Signed-off-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Reviewed-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/dsa')
-rw-r--r--net/dsa/dsa.c71
-rw-r--r--net/dsa/dsa_priv.h1
-rw-r--r--net/dsa/slave.c35
3 files changed, 47 insertions, 60 deletions
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 7140de475c07..221ebde4318d 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -29,6 +29,33 @@
29 29
30char dsa_driver_version[] = "0.1"; 30char dsa_driver_version[] = "0.1";
31 31
32static struct sk_buff *dsa_slave_notag_xmit(struct sk_buff *skb,
33 struct net_device *dev)
34{
35 /* Just return the original SKB */
36 return skb;
37}
38
39static const struct dsa_device_ops none_ops = {
40 .xmit = dsa_slave_notag_xmit,
41 .rcv = NULL,
42};
43
44const struct dsa_device_ops *dsa_device_ops[DSA_TAG_LAST] = {
45#ifdef CONFIG_NET_DSA_TAG_DSA
46 [DSA_TAG_PROTO_DSA] = &dsa_netdev_ops,
47#endif
48#ifdef CONFIG_NET_DSA_TAG_EDSA
49 [DSA_TAG_PROTO_EDSA] = &edsa_netdev_ops,
50#endif
51#ifdef CONFIG_NET_DSA_TAG_TRAILER
52 [DSA_TAG_PROTO_TRAILER] = &trailer_netdev_ops,
53#endif
54#ifdef CONFIG_NET_DSA_TAG_BRCM
55 [DSA_TAG_PROTO_BRCM] = &brcm_netdev_ops,
56#endif
57 [DSA_TAG_PROTO_NONE] = &none_ops,
58};
32 59
33/* switch driver registration ***********************************************/ 60/* switch driver registration ***********************************************/
34static DEFINE_MUTEX(dsa_switch_drivers_mutex); 61static DEFINE_MUTEX(dsa_switch_drivers_mutex);
@@ -225,6 +252,20 @@ static int dsa_cpu_dsa_setups(struct dsa_switch *ds, struct device *dev)
225 return 0; 252 return 0;
226} 253}
227 254
255const struct dsa_device_ops *dsa_resolve_tag_protocol(int tag_protocol)
256{
257 const struct dsa_device_ops *ops;
258
259 if (tag_protocol >= DSA_TAG_LAST)
260 return ERR_PTR(-EINVAL);
261 ops = dsa_device_ops[tag_protocol];
262
263 if (!ops)
264 return ERR_PTR(-ENOPROTOOPT);
265
266 return ops;
267}
268
228static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent) 269static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
229{ 270{
230 struct dsa_switch_driver *drv = ds->drv; 271 struct dsa_switch_driver *drv = ds->drv;
@@ -277,35 +318,13 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
277 * switch. 318 * switch.
278 */ 319 */
279 if (dst->cpu_switch == index) { 320 if (dst->cpu_switch == index) {
280 switch (drv->tag_protocol) { 321 dst->tag_ops = dsa_resolve_tag_protocol(drv->tag_protocol);
281#ifdef CONFIG_NET_DSA_TAG_DSA 322 if (IS_ERR(dst->tag_ops)) {
282 case DSA_TAG_PROTO_DSA: 323 ret = PTR_ERR(dst->tag_ops);
283 dst->rcv = dsa_netdev_ops.rcv;
284 break;
285#endif
286#ifdef CONFIG_NET_DSA_TAG_EDSA
287 case DSA_TAG_PROTO_EDSA:
288 dst->rcv = edsa_netdev_ops.rcv;
289 break;
290#endif
291#ifdef CONFIG_NET_DSA_TAG_TRAILER
292 case DSA_TAG_PROTO_TRAILER:
293 dst->rcv = trailer_netdev_ops.rcv;
294 break;
295#endif
296#ifdef CONFIG_NET_DSA_TAG_BRCM
297 case DSA_TAG_PROTO_BRCM:
298 dst->rcv = brcm_netdev_ops.rcv;
299 break;
300#endif
301 case DSA_TAG_PROTO_NONE:
302 break;
303 default:
304 ret = -ENOPROTOOPT;
305 goto out; 324 goto out;
306 } 325 }
307 326
308 dst->tag_protocol = drv->tag_protocol; 327 dst->rcv = dst->tag_ops->rcv;
309 } 328 }
310 329
311 memcpy(ds->rtable, cd->rtable, sizeof(ds->rtable)); 330 memcpy(ds->rtable, cd->rtable, sizeof(ds->rtable));
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index dbea5d9e7f75..72f7b8989cfb 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -53,6 +53,7 @@ extern char dsa_driver_version[];
53int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev, 53int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev,
54 struct device_node *port_dn, int port); 54 struct device_node *port_dn, int port);
55void dsa_cpu_dsa_destroy(struct device_node *port_dn); 55void dsa_cpu_dsa_destroy(struct device_node *port_dn);
56const struct dsa_device_ops *dsa_resolve_tag_protocol(int tag_protocol);
56 57
57/* slave.c */ 58/* slave.c */
58extern const struct dsa_device_ops notag_netdev_ops; 59extern const struct dsa_device_ops notag_netdev_ops;
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 52f1183c42a0..35e5f0f6688b 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -521,14 +521,6 @@ static netdev_tx_t dsa_slave_xmit(struct sk_buff *skb, struct net_device *dev)
521 return NETDEV_TX_OK; 521 return NETDEV_TX_OK;
522} 522}
523 523
524static struct sk_buff *dsa_slave_notag_xmit(struct sk_buff *skb,
525 struct net_device *dev)
526{
527 /* Just return the original SKB */
528 return skb;
529}
530
531
532/* ethtool operations *******************************************************/ 524/* ethtool operations *******************************************************/
533static int 525static int
534dsa_slave_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) 526dsa_slave_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
@@ -1151,32 +1143,7 @@ int dsa_slave_create(struct dsa_switch *ds, struct device *parent,
1151 p = netdev_priv(slave_dev); 1143 p = netdev_priv(slave_dev);
1152 p->parent = ds; 1144 p->parent = ds;
1153 p->port = port; 1145 p->port = port;
1154 1146 p->xmit = dst->tag_ops->xmit;
1155 switch (ds->dst->tag_protocol) {
1156#ifdef CONFIG_NET_DSA_TAG_DSA
1157 case DSA_TAG_PROTO_DSA:
1158 p->xmit = dsa_netdev_ops.xmit;
1159 break;
1160#endif
1161#ifdef CONFIG_NET_DSA_TAG_EDSA
1162 case DSA_TAG_PROTO_EDSA:
1163 p->xmit = edsa_netdev_ops.xmit;
1164 break;
1165#endif
1166#ifdef CONFIG_NET_DSA_TAG_TRAILER
1167 case DSA_TAG_PROTO_TRAILER:
1168 p->xmit = trailer_netdev_ops.xmit;
1169 break;
1170#endif
1171#ifdef CONFIG_NET_DSA_TAG_BRCM
1172 case DSA_TAG_PROTO_BRCM:
1173 p->xmit = brcm_netdev_ops.xmit;
1174 break;
1175#endif
1176 default:
1177 p->xmit = dsa_slave_notag_xmit;
1178 break;
1179 }
1180 1147
1181 p->old_pause = -1; 1148 p->old_pause = -1;
1182 p->old_link = -1; 1149 p->old_link = -1;