net: dsa: modularize DSA_TAG_PROTO_NONE
authorVladimir Oltean <vladimir.oltean@nxp.com>
Mon, 21 Nov 2022 13:55:40 +0000 (15:55 +0200)
committerJakub Kicinski <kuba@kernel.org>
Wed, 23 Nov 2022 04:41:45 +0000 (20:41 -0800)
There is no reason that I can see why the no-op tagging protocol should
be registered manually, so make it a module and make all drivers which
have any sort of reference to DSA_TAG_PROTO_NONE select it.

Note that I don't know if ksz_get_tag_protocol() really needs this,
or if it's just the logic which is poorly written. All switches seem to
have their own tagging protocol, and DSA_TAG_PROTO_NONE is just a
fallback that never gets used.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/dsa/Kconfig
drivers/net/dsa/b53/Kconfig
drivers/net/dsa/microchip/Kconfig
net/dsa/Kconfig
net/dsa/Makefile
net/dsa/dsa.c
net/dsa/dsa_priv.h
net/dsa/tag_none.c [new file with mode: 0644]

index 07507b4820d73075bd63c7e6c2fc929ecb984dc2..c26755f662c1ff9bbed72742a2e83eeb747b0821 100644 (file)
@@ -18,6 +18,7 @@ config NET_DSA_BCM_SF2
 
 config NET_DSA_LOOP
        tristate "DSA mock-up Ethernet switch chip support"
+       select NET_DSA_TAG_NONE
        select FIXED_PHY
        help
          This enables support for a fake mock-up switch chip which
@@ -99,6 +100,7 @@ config NET_DSA_SMSC_LAN9303_MDIO
 
 config NET_DSA_VITESSE_VSC73XX
        tristate
+       select NET_DSA_TAG_NONE
        select FIXED_PHY
        select VITESSE_PHY
        select GPIOLIB
index 90b525160b7112db55af6d88f2d13a734d7a8200..ebaa4a80d5444f4283023756bc9978c3c65df146 100644 (file)
@@ -2,6 +2,7 @@
 menuconfig B53
        tristate "Broadcom BCM53xx managed switch support"
        depends on NET_DSA
+       select NET_DSA_TAG_NONE
        select NET_DSA_TAG_BRCM
        select NET_DSA_TAG_BRCM_LEGACY
        select NET_DSA_TAG_BRCM_PREPEND
index 06b1efdb5e7d67b1077bd576c50e45f60567d605..913f83ef013c0c03f34e906aaec0c519b60832d1 100644 (file)
@@ -3,6 +3,7 @@ menuconfig NET_DSA_MICROCHIP_KSZ_COMMON
        tristate "Microchip KSZ8795/KSZ9477/LAN937x series switch support"
        depends on NET_DSA
        select NET_DSA_TAG_KSZ
+       select NET_DSA_TAG_NONE
        help
          This driver adds support for Microchip KSZ9477 series switch and
          KSZ8795/KSZ88x3 switch chips.
index 3eef72ce99a4bdf1c52b25d2ceaa75b3421918fb..8e698bea99a30601b70b997008257e7d3d3ca89b 100644 (file)
@@ -18,6 +18,12 @@ if NET_DSA
 
 # Drivers must select the appropriate tagging format(s)
 
+config NET_DSA_TAG_NONE
+       tristate "No-op tag driver"
+       help
+         Say Y or M if you want to enable support for switches which don't tag
+         frames over the CPU port.
+
 config NET_DSA_TAG_AR9331
        tristate "Tag driver for Atheros AR9331 SoC with built-in switch"
        help
index bf57ef3bce2a47b3af5e4d938b543a369507b01d..14e05ab641350a2af1b1fb8d6678ea94cc97101a 100644 (file)
@@ -20,6 +20,7 @@ obj-$(CONFIG_NET_DSA_TAG_HELLCREEK) += tag_hellcreek.o
 obj-$(CONFIG_NET_DSA_TAG_KSZ) += tag_ksz.o
 obj-$(CONFIG_NET_DSA_TAG_LAN9303) += tag_lan9303.o
 obj-$(CONFIG_NET_DSA_TAG_MTK) += tag_mtk.o
+obj-$(CONFIG_NET_DSA_TAG_NONE) += tag_none.o
 obj-$(CONFIG_NET_DSA_TAG_OCELOT) += tag_ocelot.o
 obj-$(CONFIG_NET_DSA_TAG_OCELOT_8021Q) += tag_ocelot_8021q.o
 obj-$(CONFIG_NET_DSA_TAG_QCA) += tag_qca.o
index 07158c7560b5fc8893ac9a4760d9eda7f056f8a2..e609d64a22160267e1a6fa07351d3a88c2305b8d 100644 (file)
 static LIST_HEAD(dsa_tag_drivers_list);
 static DEFINE_MUTEX(dsa_tag_drivers_lock);
 
-static struct sk_buff *dsa_slave_notag_xmit(struct sk_buff *skb,
-                                           struct net_device *dev)
-{
-       /* Just return the original SKB */
-       return skb;
-}
-
-static const struct dsa_device_ops none_ops = {
-       .name   = "none",
-       .proto  = DSA_TAG_PROTO_NONE,
-       .xmit   = dsa_slave_notag_xmit,
-       .rcv    = NULL,
-};
-
-DSA_TAG_DRIVER(none_ops);
-
 static void dsa_tag_driver_register(struct dsa_tag_driver *dsa_tag_driver,
                                    struct module *owner)
 {
@@ -551,9 +535,6 @@ static int __init dsa_init_module(void)
 
        dev_add_pack(&dsa_pack_type);
 
-       dsa_tag_driver_register(&DSA_TAG_DRIVER_NAME(none_ops),
-                               THIS_MODULE);
-
        rc = rtnl_link_register(&dsa_link_ops);
        if (rc)
                goto netlink_register_fail;
@@ -561,7 +542,6 @@ static int __init dsa_init_module(void)
        return 0;
 
 netlink_register_fail:
-       dsa_tag_driver_unregister(&DSA_TAG_DRIVER_NAME(none_ops));
        dsa_slave_unregister_notifier();
        dev_remove_pack(&dsa_pack_type);
 register_notifier_fail:
@@ -574,7 +554,6 @@ module_init(dsa_init_module);
 static void __exit dsa_cleanup_module(void)
 {
        rtnl_link_unregister(&dsa_link_ops);
-       dsa_tag_driver_unregister(&DSA_TAG_DRIVER_NAME(none_ops));
 
        dsa_slave_unregister_notifier();
        dev_remove_pack(&dsa_pack_type);
index b60987e8d9314acdca39598e4bdd5ad43a714528..c4ea5fda8f1498909f32c736e432450c68b2ef0a 100644 (file)
@@ -384,7 +384,6 @@ int dsa_port_change_master(struct dsa_port *dp, struct net_device *master,
                           struct netlink_ext_ack *extack);
 
 /* slave.c */
-extern const struct dsa_device_ops notag_netdev_ops;
 extern struct notifier_block dsa_slave_switchdev_notifier;
 extern struct notifier_block dsa_slave_switchdev_blocking_notifier;
 
diff --git a/net/dsa/tag_none.c b/net/dsa/tag_none.c
new file mode 100644 (file)
index 0000000..34a13c5
--- /dev/null
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * net/dsa/tag_none.c - Traffic handling for switches with no tag
+ * Copyright (c) 2008-2009 Marvell Semiconductor
+ * Copyright (c) 2013 Florian Fainelli <florian@openwrt.org>
+ *
+ * WARNING: do not use this for new switches. In case of no hardware
+ * tagging support, look at tag_8021q.c instead.
+ */
+
+#include "dsa_priv.h"
+
+#define NONE_NAME      "none"
+
+static struct sk_buff *dsa_slave_notag_xmit(struct sk_buff *skb,
+                                           struct net_device *dev)
+{
+       /* Just return the original SKB */
+       return skb;
+}
+
+static const struct dsa_device_ops none_ops = {
+       .name   = NONE_NAME,
+       .proto  = DSA_TAG_PROTO_NONE,
+       .xmit   = dsa_slave_notag_xmit,
+};
+
+module_dsa_tag_driver(none_ops);
+MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_NONE, NONE_NAME);
+MODULE_LICENSE("GPL");