]> git.baikalelectronics.ru Git - kernel.git/commitdiff
dsa: Move tagger name into its ops structure
authorAndrew Lunn <andrew@lunn.ch>
Sun, 28 Apr 2019 17:37:11 +0000 (19:37 +0200)
committerDavid S. Miller <davem@davemloft.net>
Sun, 28 Apr 2019 23:41:00 +0000 (19:41 -0400)
Rather than keep a list to map a tagger ops to a name, place the name
into the ops structure. This removes the hard coded list, a step
towards making the taggers more dynamic.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
v2:
Move name to end of structure, keeping the hot entries at the beginning.

Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/dsa.h
net/dsa/dsa.c
net/dsa/tag_brcm.c
net/dsa/tag_dsa.c
net/dsa/tag_edsa.c
net/dsa/tag_gswip.c
net/dsa/tag_ksz.c
net/dsa/tag_lan9303.c
net/dsa/tag_mtk.c
net/dsa/tag_qca.c
net/dsa/tag_trailer.c

index 0cfc2f828b87d911b8263a3f92f1e38754fc2d45..801346e31e9bb1cda1b10c39e1812dfbd002778d 100644 (file)
@@ -56,6 +56,7 @@ struct dsa_device_ops {
        int (*flow_dissect)(const struct sk_buff *skb, __be16 *proto,
                            int *offset);
        unsigned int overhead;
+       const char *name;
 };
 
 struct dsa_switch_tree {
index 36de4f2a3366b4a56d50d3c3ac26a61c0c89548b..92b3cd129eb79b6e66af577192651db5754da442 100644 (file)
@@ -35,6 +35,7 @@ static struct sk_buff *dsa_slave_notag_xmit(struct sk_buff *skb,
 }
 
 static const struct dsa_device_ops none_ops = {
+       .name   = "none",
        .xmit   = dsa_slave_notag_xmit,
        .rcv    = NULL,
 };
@@ -76,49 +77,7 @@ const struct dsa_device_ops *dsa_device_ops[DSA_TAG_LAST] = {
 
 const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops)
 {
-       const char *protocol_name[DSA_TAG_LAST] = {
-#ifdef CONFIG_NET_DSA_TAG_BRCM
-               [DSA_TAG_PROTO_BRCM] = "brcm",
-#endif
-#ifdef CONFIG_NET_DSA_TAG_BRCM_PREPEND
-               [DSA_TAG_PROTO_BRCM_PREPEND] = "brcm-prepend",
-#endif
-#ifdef CONFIG_NET_DSA_TAG_DSA
-               [DSA_TAG_PROTO_DSA] = "dsa",
-#endif
-#ifdef CONFIG_NET_DSA_TAG_EDSA
-               [DSA_TAG_PROTO_EDSA] = "edsa",
-#endif
-#ifdef CONFIG_NET_DSA_TAG_GSWIP
-               [DSA_TAG_PROTO_GSWIP] = "gswip",
-#endif
-#ifdef CONFIG_NET_DSA_TAG_KSZ9477
-               [DSA_TAG_PROTO_KSZ9477] = "ksz9477",
-               [DSA_TAG_PROTO_KSZ9893] = "ksz9893",
-#endif
-#ifdef CONFIG_NET_DSA_TAG_LAN9303
-               [DSA_TAG_PROTO_LAN9303] = "lan9303",
-#endif
-#ifdef CONFIG_NET_DSA_TAG_MTK
-               [DSA_TAG_PROTO_MTK] = "mtk",
-#endif
-#ifdef CONFIG_NET_DSA_TAG_QCA
-               [DSA_TAG_PROTO_QCA] = "qca",
-#endif
-#ifdef CONFIG_NET_DSA_TAG_TRAILER
-               [DSA_TAG_PROTO_TRAILER] = "trailer",
-#endif
-               [DSA_TAG_PROTO_NONE] = "none",
-       };
-       unsigned int i;
-
-       BUILD_BUG_ON(ARRAY_SIZE(protocol_name) != DSA_TAG_LAST);
-
-       for (i = 0; i < ARRAY_SIZE(dsa_device_ops); i++)
-               if (ops == dsa_device_ops[i])
-                       return protocol_name[i];
-
-       return protocol_name[DSA_TAG_PROTO_NONE];
+       return ops->name;
 };
 
 const struct dsa_device_ops *dsa_resolve_tag_protocol(int tag_protocol)
index b3063e7adb735fd853f62a18ecca83588e546059..1b7dfbe6b3aec34df920af42fea4453ae0202aed 100644 (file)
@@ -168,6 +168,7 @@ static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev,
 }
 
 const struct dsa_device_ops brcm_netdev_ops = {
+       .name   = "brcm",
        .xmit   = brcm_tag_xmit,
        .rcv    = brcm_tag_rcv,
        .overhead = BRCM_TAG_LEN,
@@ -191,6 +192,7 @@ static struct sk_buff *brcm_tag_rcv_prepend(struct sk_buff *skb,
 }
 
 const struct dsa_device_ops brcm_prepend_netdev_ops = {
+       .name   = "brcm-prepend",
        .xmit   = brcm_tag_xmit_prepend,
        .rcv    = brcm_tag_rcv_prepend,
        .overhead = BRCM_TAG_LEN,
index fdaf850831e2bff8aa711259fc66f5d6534cc4e9..e1c90709de6cc501c97bcae17a279cd43a979677 100644 (file)
@@ -151,6 +151,7 @@ static int dsa_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
 }
 
 const struct dsa_device_ops dsa_netdev_ops = {
+       .name   = "dsa",
        .xmit   = dsa_xmit,
        .rcv    = dsa_rcv,
        .flow_dissect   = dsa_tag_flow_dissect,
index df879445f658a95be7d58d27eb501fd3f59a2fd8..b936b4660b717f1cf9d15d3c9d480f4ca97f9a85 100644 (file)
@@ -170,6 +170,7 @@ static int edsa_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
 }
 
 const struct dsa_device_ops edsa_netdev_ops = {
+       .name   = "edsa",
        .xmit   = edsa_xmit,
        .rcv    = edsa_rcv,
        .flow_dissect   = edsa_tag_flow_dissect,
index cb6f82ffe5eb5d54c5697d27a59e849bfc2b753a..d1c1e7db87b69c62b878128a1ea28b1250cafd61 100644 (file)
@@ -104,6 +104,7 @@ static struct sk_buff *gswip_tag_rcv(struct sk_buff *skb,
 }
 
 const struct dsa_device_ops gswip_netdev_ops = {
+       .name = "gwsip",
        .xmit = gswip_tag_xmit,
        .rcv = gswip_tag_rcv,
        .overhead = GSWIP_RX_HEADER_LEN,
index 12b2f58786ee1847b6f59065c2345dacaa84916e..631094599514c37dce0df4e01ebdc91949ffac29 100644 (file)
@@ -134,6 +134,7 @@ static struct sk_buff *ksz9477_rcv(struct sk_buff *skb, struct net_device *dev,
 }
 
 const struct dsa_device_ops ksz9477_netdev_ops = {
+       .name   = "ksz9477",
        .xmit   = ksz9477_xmit,
        .rcv    = ksz9477_rcv,
        .overhead = KSZ9477_INGRESS_TAG_LEN,
@@ -167,6 +168,7 @@ static struct sk_buff *ksz9893_xmit(struct sk_buff *skb,
 }
 
 const struct dsa_device_ops ksz9893_netdev_ops = {
+       .name   = "ksz9893",
        .xmit   = ksz9893_xmit,
        .rcv    = ksz9477_rcv,
        .overhead = KSZ_INGRESS_TAG_LEN,
index 7bfd3165e46e9cd8b48ad0f115867451f890e5a6..67d70339536d8fdb610c7e47c47a8f9efcef9b45 100644 (file)
@@ -129,6 +129,7 @@ static struct sk_buff *lan9303_rcv(struct sk_buff *skb, struct net_device *dev,
 }
 
 const struct dsa_device_ops lan9303_netdev_ops = {
+       .name = "lan9303",
        .xmit = lan9303_xmit,
        .rcv = lan9303_rcv,
        .overhead = LAN9303_TAG_LEN,
index 6e06fa621bbca9a61d3e8de3bacd1ba25d956e61..dc537d9a18c01c54b09fede9d8745dd799001885 100644 (file)
@@ -99,6 +99,7 @@ static int mtk_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
 }
 
 const struct dsa_device_ops mtk_netdev_ops = {
+       .name           = "mtk",
        .xmit           = mtk_tag_xmit,
        .rcv            = mtk_tag_rcv,
        .flow_dissect   = mtk_tag_flow_dissect,
index de3eb1022e21478d7bcb0e2246b6b9d7570be039..f62296ffc5b7584c1421b171b121f4ff8c16c1d3 100644 (file)
@@ -100,6 +100,7 @@ static int qca_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
 }
 
 const struct dsa_device_ops qca_netdev_ops = {
+       .name   = "qca",
        .xmit   = qca_tag_xmit,
        .rcv    = qca_tag_rcv,
        .flow_dissect = qca_tag_flow_dissect,
index 492a3004628161678f8c7687a1752e92529e0ffc..20ee7f84fe4df183779780baa987881b6a88824b 100644 (file)
@@ -78,6 +78,7 @@ static struct sk_buff *trailer_rcv(struct sk_buff *skb, struct net_device *dev,
 }
 
 const struct dsa_device_ops trailer_netdev_ops = {
+       .name   = "trailer",
        .xmit   = trailer_xmit,
        .rcv    = trailer_rcv,
        .overhead = 4,