aboutsummaryrefslogtreecommitdiffstats
path: root/net/dsa/dsa.c
diff options
context:
space:
mode:
authorFlorian Fainelli <f.fainelli@gmail.com>2014-08-27 20:04:46 -0400
committerDavid S. Miller <davem@davemloft.net>2014-08-28 01:59:39 -0400
commit3e8a72d1dae374cf6fc1dba97cec663585845ff9 (patch)
tree83a2ebc590d0dc90d27515dc15bf6323cb2a6c1b /net/dsa/dsa.c
parent8663dc2002b02abfe5dfb0fb7e544b81982ad95b (diff)
net: dsa: reduce number of protocol hooks
DSA is currently registering one packet_type function per EtherType it needs to intercept in the receive path of a DSA-enabled Ethernet device. Right now we have three of them: trailer, DSA and eDSA, and there might be more in the future, this will not scale to the addition of new protocols. This patch proceeds with adding a new layer of abstraction and two new functions: dsa_switch_rcv() which will dispatch into the tag-protocol specific receive function implemented by net/dsa/tag_*.c dsa_slave_xmit() which will dispatch into the tag-protocol specific transmit function implemented by net/dsa/tag_*.c When we do create the per-port slave network devices, we iterate over the switch protocol to assign the DSA-specific receive and transmit operations. A new fake ethertype value is used: ETH_P_XDSA to illustrate the fact that this is no longer going to look like ETH_P_DSA or ETH_P_TRAILER like it used to be. This allows us to greatly simplify the check in eth_type_trans() and always override the skb->protocol with ETH_P_XDSA for Ethernet switches tagged protocol, while also reducing the number repetitive slave netdevice_ops assignments. Signed-off-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/dsa/dsa.c')
-rw-r--r--net/dsa/dsa.c39
1 files changed, 21 insertions, 18 deletions
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 0a49632fac47..92e71d2a2ccd 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -608,6 +608,24 @@ static void dsa_shutdown(struct platform_device *pdev)
608{ 608{
609} 609}
610 610
611static int dsa_switch_rcv(struct sk_buff *skb, struct net_device *dev,
612 struct packet_type *pt, struct net_device *orig_dev)
613{
614 struct dsa_switch_tree *dst = dev->dsa_ptr;
615
616 if (unlikely(dst == NULL)) {
617 kfree_skb(skb);
618 return 0;
619 }
620
621 return dst->ops->rcv(skb, dev, pt, orig_dev);
622}
623
624struct packet_type dsa_pack_type __read_mostly = {
625 .type = cpu_to_be16(ETH_P_XDSA),
626 .func = dsa_switch_rcv,
627};
628
611static const struct of_device_id dsa_of_match_table[] = { 629static const struct of_device_id dsa_of_match_table[] = {
612 { .compatible = "marvell,dsa", }, 630 { .compatible = "marvell,dsa", },
613 {} 631 {}
@@ -633,30 +651,15 @@ static int __init dsa_init_module(void)
633 if (rc) 651 if (rc)
634 return rc; 652 return rc;
635 653
636#ifdef CONFIG_NET_DSA_TAG_DSA 654 dev_add_pack(&dsa_pack_type);
637 dev_add_pack(&dsa_packet_type); 655
638#endif
639#ifdef CONFIG_NET_DSA_TAG_EDSA
640 dev_add_pack(&edsa_packet_type);
641#endif
642#ifdef CONFIG_NET_DSA_TAG_TRAILER
643 dev_add_pack(&trailer_packet_type);
644#endif
645 return 0; 656 return 0;
646} 657}
647module_init(dsa_init_module); 658module_init(dsa_init_module);
648 659
649static void __exit dsa_cleanup_module(void) 660static void __exit dsa_cleanup_module(void)
650{ 661{
651#ifdef CONFIG_NET_DSA_TAG_TRAILER 662 dev_remove_pack(&dsa_pack_type);
652 dev_remove_pack(&trailer_packet_type);
653#endif
654#ifdef CONFIG_NET_DSA_TAG_EDSA
655 dev_remove_pack(&edsa_packet_type);
656#endif
657#ifdef CONFIG_NET_DSA_TAG_DSA
658 dev_remove_pack(&dsa_packet_type);
659#endif
660 platform_driver_unregister(&dsa_driver); 663 platform_driver_unregister(&dsa_driver);
661} 664}
662module_exit(dsa_cleanup_module); 665module_exit(dsa_cleanup_module);