Skip to contentSkip to conversation

Remove dsa_priv.h

PATCH Applied Vladimir Oltean 3 participants 38 messages Nov 21, 2022 – Nov 23, 2022

Subsystems (13)
lore
Share & tools
lore

Vladimir Oltean

author maintainer
#0 lore raw

cover Remove dsa_priv.h

After working on the "Autoload DSA tagging driver when dynamically changing protocol" series:
https://patchwork.kernel.org/project/netdevbpf/cover/[email protected]/

it became clear to me that the situation with DSA headers is a bit messy, and I put the tagging protocol driver macros in a pretty random temporary spot in dsa_priv.h.

Now is the time to make the net/dsa/ folder a bit more organized, and to make tagging protocol driver modules include just headers they're going to use.

Another thing is the merging and cleanup of dsa.c and dsa2.c. Before, dsa.c had 589 lines and dsa2.c had 1817 lines. Now, the combined dsa.c has 1749 lines, the rest went to some other places.

Sorry for the set size, I know the rules, but since this is basically code movement for the most part, I thought more patches are better.

Vladimir Oltean (17):
net: dsa: unexport dsa_dev_to_net_device()
net: dsa: modularize DSA_TAG_PROTO_NONE
net: dsa: move bulk of devlink code to devlink.{c,h}
net: dsa: if ds->setup is true, ds->devlink is always non-NULL
net: dsa: move rest of devlink setup/teardown to devlink.c
net: dsa: move headers exported by port.c to port.h
net: dsa: move headers exported by master.c to master.h
net: dsa: move headers exported by slave.c to slave.h
net: dsa: move tagging protocol code to tag.{c,h}
net: dsa: move headers exported by switch.c to switch.h
net: dsa: move dsa_tree_notify() and dsa_broadcast() to switch.c
net: dsa: move notifier definitions to switch.h
net: dsa: merge dsa.c into dsa2.c
net: dsa: rename dsa2.c back into dsa.c and create its header
net: dsa: move definitions from dsa_priv.h to slave.c
net: dsa: move tag_8021q headers to their proper place
net: dsa: kill off dsa_priv.h

 drivers/net/dsa/Kconfig           |    2 +
 drivers/net/dsa/b53/Kconfig       |    1 +
 drivers/net/dsa/microchip/Kconfig |    1 +
 include/linux/dsa/8021q.h         |   31 +-
 include/net/dsa.h                 |    3 +-
 net/dsa/Kconfig                   |    6 +
 net/dsa/Makefile                  |    4 +-
 net/dsa/devlink.c                 |  391 +++++++
 net/dsa/devlink.h                 |   16 +
 net/dsa/dsa.c                     | 1754 +++++++++++++++++++++++-----
 net/dsa/dsa.h                     |   40 +
 net/dsa/dsa2.c                    | 1817 -----------------------------
 net/dsa/dsa_priv.h                |  663 -----------
 net/dsa/master.c                  |   10 +-
 net/dsa/master.h                  |   19 +
 net/dsa/netlink.c                 |    3 +-
 net/dsa/netlink.h                 |    8 +
 net/dsa/port.c                    |    6 +-
 net/dsa/port.h                    |  114 ++
 net/dsa/slave.c                   |   49 +-
 net/dsa/slave.h                   |   69 ++
 net/dsa/switch.c                  |   53 +-
 net/dsa/switch.h                  |  120 ++
 net/dsa/tag.c                     |  243 ++++
 net/dsa/tag.h                     |  310 +++++
 net/dsa/tag_8021q.c               |   19 +-
 net/dsa/tag_8021q.h               |   27 +
 net/dsa/tag_ar9331.c              |    2 +-
 net/dsa/tag_brcm.c                |    2 +-
 net/dsa/tag_dsa.c                 |    2 +-
 net/dsa/tag_gswip.c               |    2 +-
 net/dsa/tag_hellcreek.c           |    2 +-
 net/dsa/tag_ksz.c                 |    3 +-
 net/dsa/tag_lan9303.c             |    2 +-
 net/dsa/tag_mtk.c                 |    2 +-
 net/dsa/tag_none.c                |   30 +
 net/dsa/tag_ocelot.c              |    3 +-
 net/dsa/tag_ocelot_8021q.c        |    4 +-
 net/dsa/tag_qca.c                 |    2 +-
 net/dsa/tag_rtl4_a.c              |    2 +-
 net/dsa/tag_rtl8_4.c              |    2 +-
 net/dsa/tag_rzn1_a5psw.c          |    2 +-
 net/dsa/tag_sja1105.c             |    4 +-
 net/dsa/tag_trailer.c             |    2 +-
 net/dsa/tag_xrs700x.c             |    2 +-
 45 files changed, 3016 insertions(+), 2833 deletions(-)
 create mode 100644 net/dsa/devlink.c
 create mode 100644 net/dsa/devlink.h
 create mode 100644 net/dsa/dsa.h
 delete mode 100644 net/dsa/dsa2.c
 delete mode 100644 net/dsa/dsa_priv.h
 create mode 100644 net/dsa/master.h
 create mode 100644 net/dsa/netlink.h
 create mode 100644 net/dsa/port.h
 create mode 100644 net/dsa/slave.h
 create mode 100644 net/dsa/switch.h
 create mode 100644 net/dsa/tag.c
 create mode 100644 net/dsa/tag.h
 create mode 100644 net/dsa/tag_8021q.h
 create mode 100644 net/dsa/tag_none.c
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH 1/17 net: dsa: unexport dsa_dev_to_net_device()

dsa.o and dsa2.o are linked into the same dsa_core.o, there is no reason to export this symbol when its only caller is local.

---
 include/net/dsa.h  | 2 --
 net/dsa/dsa.c      | 1 -
 net/dsa/dsa_priv.h | 2 ++
 3 files changed, 2 insertions(+), 3 deletions(-)
include/net/dsa.h +0 -2
index 82da44561f4c..d5bfcb63d4c2 100644
@@ -1285,8 +1285,6 @@ struct dsa_switch_driver {
 	const struct dsa_switch_ops *ops;
 };
 
-struct net_device *dsa_dev_to_net_device(struct device *dev);
-
 bool dsa_fdb_present_in_other_db(struct dsa_switch *ds, int port,
 				 const unsigned char *addr, u16 vid,
 				 struct dsa_db db);
net/dsa/dsa.c +0 -1
index 4afd3edbd64d..07158c7560b5 100644
@@ -182,7 +182,6 @@ struct net_device *dsa_dev_to_net_device(struct device *dev)
 
 	return NULL;
 }
-EXPORT_SYMBOL_GPL(dsa_dev_to_net_device);
 
 /* Determine if we should defer delivery of skb until we have a rx timestamp.
  *
net/dsa/dsa_priv.h +2 -0
index 24e0ea218a35..b60987e8d931 100644
@@ -247,6 +247,8 @@ const struct dsa_device_ops *dsa_tag_driver_get_by_id(int tag_protocol);
 const struct dsa_device_ops *dsa_tag_driver_get_by_name(const char *name);
 void dsa_tag_driver_put(const struct dsa_device_ops *ops);
 
+struct net_device *dsa_dev_to_net_device(struct device *dev);
+
 bool dsa_db_equal(const struct dsa_db *a, const struct dsa_db *b);
 
 bool dsa_schedule_work(struct work_struct *work);
Signature · 1 line
2.34.1
author maintainer
#3 lore raw

PATCH 2/17 net: dsa: modularize DSA_TAG_PROTO_NONE

In reply to Vladimir Oltean

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.

---
 drivers/net/dsa/Kconfig           |  2 ++
 drivers/net/dsa/b53/Kconfig       |  1 +
 drivers/net/dsa/microchip/Kconfig |  1 +
 net/dsa/Kconfig                   |  6 ++++++
 net/dsa/Makefile                  |  1 +
 net/dsa/dsa.c                     | 21 ---------------------
 net/dsa/dsa_priv.h                |  1 -
 net/dsa/tag_none.c                | 30 ++++++++++++++++++++++++++++++
 8 files changed, 41 insertions(+), 22 deletions(-)
 create mode 100644 net/dsa/tag_none.c
drivers/net/dsa/Kconfig +2 -0
index 07507b4820d7..c26755f662c1 100644
@@ -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
drivers/net/dsa/b53/Kconfig +1 -0
index 90b525160b71..ebaa4a80d544 100644
@@ -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
drivers/net/dsa/microchip/Kconfig +1 -0
index 06b1efdb5e7d..913f83ef013c 100644
@@ -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.
net/dsa/Kconfig +6 -0
index 3eef72ce99a4..8e698bea99a3 100644
@@ -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
net/dsa/Makefile +1 -0
index bf57ef3bce2a..14e05ab64135 100644
@@ -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
net/dsa/dsa.c +0 -21
index 07158c7560b5..e609d64a2216 100644
@@ -18,22 +18,6 @@
 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);
net/dsa/dsa_priv.h +0 -1
index b60987e8d931..c4ea5fda8f14 100644
@@ -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;
 
net/dsa/tag_none.c new file +30 -0
new file mode 100644
index 000000000000..34a13c50d245
@@ -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 <[email protected]>
+ *
+ * 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");
Signature · 1 line
2.34.1
Reviewed-by on v1 2/17
#4 lore raw

Re: [PATCH net-next 02/17] net: dsa: modularize DSA_TAG_PROTO_NONE

Quoted 10 lines · Vladimir Oltean

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.

Signature · 1 line
Florian
author maintainer
#5 lore raw

PATCH 3/17 net: dsa: move bulk of devlink code to devlink.{c,h}

In reply to Vladimir Oltean

dsa.c and dsa2.c are bloated with too much off-topic code. Identify all code related to devlink and move it to a new devlink.c file.

Steer clear of the dsa_priv.h dumping ground antipattern and create a dedicated devlink.h for it, which will be included only by the C files which need it. Usage of dsa_priv.h will be minimized in later patches.

---
 net/dsa/Makefile  |   1 +
 net/dsa/devlink.c | 355 ++++++++++++++++++++++++++++++++++++++++++++++
 net/dsa/devlink.h |  13 ++
 net/dsa/dsa.c     | 107 --------------
 net/dsa/dsa2.c    | 240 +------------------------------
 5 files changed, 370 insertions(+), 346 deletions(-)
 create mode 100644 net/dsa/devlink.c
 create mode 100644 net/dsa/devlink.h
net/dsa/Makefile +1 -0
index 14e05ab64135..bc872c0d7011 100644
@@ -2,6 +2,7 @@
 # the core
 obj-$(CONFIG_NET_DSA) += dsa_core.o
 dsa_core-y += \
+	devlink.o \
 	dsa.o \
 	dsa2.o \
 	master.o \
net/dsa/devlink.c new file +355 -0

355 lines not on this page · raw message

net/dsa/devlink.h new file +13 -0
new file mode 100644
index 000000000000..d077c7f336da
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef __DSA_DEVLINK_H
+#define __DSA_DEVLINK_H
+
+struct dsa_port;
+
+extern const struct devlink_ops dsa_devlink_ops;
+
+int dsa_port_devlink_setup(struct dsa_port *dp);
+void dsa_port_devlink_teardown(struct dsa_port *dp);
+
+#endif
net/dsa/dsa.c +0 -107

113 lines not on this page · raw message

net/dsa/dsa2.c +1 -239

258 lines not on this page · raw message

Signature · 1 line
2.34.1
Reviewed-by on v1 3/17
#6 lore raw

Re: [PATCH net-next 03/17] net: dsa: move bulk of devlink code to devlink.{c,h}

Quoted 8 lines · Vladimir Oltean

dsa.c and dsa2.c are bloated with too much off-topic code. Identify all code related to devlink and move it to a new devlink.c file.

Steer clear of the dsa_priv.h dumping ground antipattern and create a dedicated devlink.h for it, which will be included only by the C files which need it. Usage of dsa_priv.h will be minimized in later patches.

Signature · 1 line
Florian
author maintainer
#7 lore raw

PATCH 4/17 net: dsa: if ds->setup is true, ds->devlink is always non-NULL

In reply to Vladimir Oltean

Simplify dsa_switch_teardown() to remove the NULL checking for ds->devlink.

---
 net/dsa/dsa2.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
net/dsa/dsa2.c +5 -7
index 05e682c25590..f890dfcbf412 100644
@@ -682,8 +682,9 @@ static int dsa_switch_setup(struct dsa_switch *ds)
 			goto free_slave_mii_bus;
 	}
 
-	ds->setup = true;
 	devlink_register(ds->devlink);
+
+	ds->setup = true;
 	return 0;
 
 free_slave_mii_bus:
@@ -705,8 +706,7 @@ static void dsa_switch_teardown(struct dsa_switch *ds)
 	if (!ds->setup)
 		return;
 
-	if (ds->devlink)
-		devlink_unregister(ds->devlink);
+	devlink_unregister(ds->devlink);
 
 	if (ds->slave_mii_bus && ds->ops->phy_read) {
 		mdiobus_unregister(ds->slave_mii_bus);
@@ -721,10 +721,8 @@ static void dsa_switch_teardown(struct dsa_switch *ds)
 
 	dsa_switch_unregister_notifier(ds);
 
-	if (ds->devlink) {
-		devlink_free(ds->devlink);
-		ds->devlink = NULL;
-	}
+	devlink_free(ds->devlink);
+	ds->devlink = NULL;
 
 	ds->setup = false;
 }
Signature · 1 line
2.34.1
author maintainer
#9 lore raw

PATCH 5/17 net: dsa: move rest of devlink setup/teardown to devlink.c

In reply to Vladimir Oltean

The code that needed further refactoring into dedicated functions in dsa2.c was left aside. Move it now to devlink.c, and make dsa2.c stop including net/devlink.h.

---
 net/dsa/devlink.c | 38 +++++++++++++++++++++++++++++++++++++-
 net/dsa/devlink.h |  7 +++++--
 net/dsa/dsa2.c    | 24 +++++++-----------------
 3 files changed, 49 insertions(+), 20 deletions(-)
net/dsa/devlink.c +37 -1
index eff440b2b3c5..431bf52290a1 100644
@@ -167,7 +167,7 @@ dsa_devlink_sb_occ_tc_port_bind_get(struct devlink_port *dlp,
 							p_max);
 }
 
-const struct devlink_ops dsa_devlink_ops = {
+static const struct devlink_ops dsa_devlink_ops = {
 	.info_get			= dsa_devlink_info_get,
 	.sb_pool_get			= dsa_devlink_sb_pool_get,
 	.sb_pool_set			= dsa_devlink_sb_pool_set,
@@ -353,3 +353,39 @@ void dsa_port_devlink_teardown(struct dsa_port *dp)
 
 	devlink_port_fini(dlp);
 }
+
+void dsa_switch_devlink_register(struct dsa_switch *ds)
+{
+	devlink_register(ds->devlink);
+}
+
+void dsa_switch_devlink_unregister(struct dsa_switch *ds)
+{
+	devlink_unregister(ds->devlink);
+}
+
+int dsa_switch_devlink_alloc(struct dsa_switch *ds)
+{
+	struct dsa_devlink_priv *dl_priv;
+	struct devlink *dl;
+
+	/* Add the switch to devlink before calling setup, so that setup can
+	 * add dpipe tables
+	 */
+	dl = devlink_alloc(&dsa_devlink_ops, sizeof(*dl_priv), ds->dev);
+	if (!dl)
+		return -ENOMEM;
+
+	ds->devlink = dl;
+
+	dl_priv = devlink_priv(ds->devlink);
+	dl_priv->ds = ds;
+
+	return 0;
+}
+
+void dsa_switch_devlink_free(struct dsa_switch *ds)
+{
+	devlink_free(ds->devlink);
+	ds->devlink = NULL;
+}
net/dsa/devlink.h +5 -2
index d077c7f336da..4d9f4f23705b 100644
@@ -4,10 +4,13 @@
 #define __DSA_DEVLINK_H
 
 struct dsa_port;
-
-extern const struct devlink_ops dsa_devlink_ops;
+struct dsa_switch;
 
 int dsa_port_devlink_setup(struct dsa_port *dp);
 void dsa_port_devlink_teardown(struct dsa_port *dp);
+void dsa_switch_devlink_register(struct dsa_switch *ds);
+void dsa_switch_devlink_unregister(struct dsa_switch *ds);
+int dsa_switch_devlink_alloc(struct dsa_switch *ds);
+void dsa_switch_devlink_free(struct dsa_switch *ds);
 
 #endif
net/dsa/dsa2.c +7 -17
index f890dfcbf412..c0ef49d86381 100644
@@ -15,7 +15,6 @@
 #include <linux/of.h>
 #include <linux/of_mdio.h>
 #include <linux/of_net.h>
-#include <net/devlink.h>
 #include <net/sch_generic.h>
 
 #include "devlink.h"
@@ -627,7 +626,6 @@ static void dsa_switch_teardown_tag_protocol(struct dsa_switch *ds)
 
 static int dsa_switch_setup(struct dsa_switch *ds)
 {
-	struct dsa_devlink_priv *dl_priv;
 	struct device_node *dn;
 	int err;
 
@@ -641,15 +639,9 @@ static int dsa_switch_setup(struct dsa_switch *ds)
 	 */
 	ds->phys_mii_mask |= dsa_user_ports(ds);
 
-	/* Add the switch to devlink before calling setup, so that setup can
-	 * add dpipe tables
-	 */
-	ds->devlink =
-		devlink_alloc(&dsa_devlink_ops, sizeof(*dl_priv), ds->dev);
-	if (!ds->devlink)
-		return -ENOMEM;
-	dl_priv = devlink_priv(ds->devlink);
-	dl_priv->ds = ds;
+	err = dsa_switch_devlink_alloc(ds);
+	if (err)
+		return err;
 
 	err = dsa_switch_register_notifier(ds);
 	if (err)
@@ -682,7 +674,7 @@ static int dsa_switch_setup(struct dsa_switch *ds)
 			goto free_slave_mii_bus;
 	}
 
-	devlink_register(ds->devlink);
+	dsa_switch_devlink_register(ds);
 
 	ds->setup = true;
 	return 0;
@@ -696,8 +688,7 @@ static int dsa_switch_setup(struct dsa_switch *ds)
 unregister_notifier:
 	dsa_switch_unregister_notifier(ds);
 devlink_free:
-	devlink_free(ds->devlink);
-	ds->devlink = NULL;
+	dsa_switch_devlink_free(ds);
 	return err;
 }
 
@@ -706,7 +697,7 @@ static void dsa_switch_teardown(struct dsa_switch *ds)
 	if (!ds->setup)
 		return;
 
-	devlink_unregister(ds->devlink);
+	dsa_switch_devlink_unregister(ds);
 
 	if (ds->slave_mii_bus && ds->ops->phy_read) {
 		mdiobus_unregister(ds->slave_mii_bus);
@@ -721,8 +712,7 @@ static void dsa_switch_teardown(struct dsa_switch *ds)
 
 	dsa_switch_unregister_notifier(ds);
 
-	devlink_free(ds->devlink);
-	ds->devlink = NULL;
+	dsa_switch_devlink_free(ds);
 
 	ds->setup = false;
 }
Signature · 1 line
2.34.1
author maintainer
#11 lore raw

PATCH 6/17 net: dsa: move headers exported by port.c to port.h

In reply to Vladimir Oltean

Minimize the use of the bloated dsa_priv.h by moving the prototypes exported by port.c to their own header file.

---
 net/dsa/dsa2.c      |   1 +
 net/dsa/dsa_priv.h  |  97 -------------------------------------
 net/dsa/master.c    |   1 +
 net/dsa/port.c      |   1 +
 net/dsa/port.h      | 114 ++++++++++++++++++++++++++++++++++++++++++++
 net/dsa/slave.c     |   1 +
 net/dsa/switch.c    |   1 +
 net/dsa/tag_8021q.c |   1 +
 8 files changed, 120 insertions(+), 97 deletions(-)
 create mode 100644 net/dsa/port.h
net/dsa/dsa2.c +1 -0
index c0ef49d86381..5a9cf74a0166 100644
@@ -19,6 +19,7 @@
 
 #include "devlink.h"
 #include "dsa_priv.h"
+#include "port.h"
 
 static DEFINE_MUTEX(dsa2_mutex);
 LIST_HEAD(dsa_tree_list);
net/dsa/dsa_priv.h +0 -97

103 lines not on this page · raw message

net/dsa/master.c +1 -0
index e24f02743c21..0d3ef591b3b4 100644
@@ -7,6 +7,7 @@
  */
 
 #include "dsa_priv.h"
+#include "port.h"
 
 static int dsa_master_get_regs_len(struct net_device *dev)
 {
net/dsa/port.c +1 -0
index 707bd854cea2..0708fe8d4736 100644
@@ -13,6 +13,7 @@
 #include <linux/of_net.h>
 
 #include "dsa_priv.h"
+#include "port.h"
 
 /**
  * dsa_port_notify - Notify the switching fabric of changes to a port
net/dsa/port.h new file +114 -0

114 lines not on this page · raw message

net/dsa/slave.c +1 -0
index 24d8ad36fc8b..b782a1788f5a 100644
@@ -23,6 +23,7 @@
 #include <linux/netpoll.h>
 
 #include "dsa_priv.h"
+#include "port.h"
 
 static void dsa_slave_standalone_event_work(struct work_struct *work)
 {
net/dsa/switch.c +1 -0
index ce56acdba203..5ece5c5c2acf 100644
@@ -13,6 +13,7 @@
 #include <net/switchdev.h>
 
 #include "dsa_priv.h"
+#include "port.h"
 
 static unsigned int dsa_switch_fastest_ageing_time(struct dsa_switch *ds,
 						   unsigned int ageing_time)
net/dsa/tag_8021q.c +1 -0
index 34e5ec5d3e23..a6617d7b692a 100644
@@ -8,6 +8,7 @@
 #include <linux/dsa/8021q.h>
 
 #include "dsa_priv.h"
+#include "port.h"
 
 /* Binary structure of the fake 12-bit VID field (when the TPID is
  * ETH_P_DSA_8021Q):
Signature · 1 line
2.34.1
author maintainer
#13 lore raw

PATCH 7/17 net: dsa: move headers exported by master.c to master.h

In reply to Vladimir Oltean

Minimize the use of the bloated dsa_priv.h by moving the prototypes exported by master.c to their own header file.

---
 net/dsa/dsa2.c     |  1 +
 net/dsa/dsa_priv.h |  9 ---------
 net/dsa/master.c   |  6 ++++++
 net/dsa/master.h   | 19 +++++++++++++++++++
 net/dsa/slave.c    |  1 +
 5 files changed, 27 insertions(+), 9 deletions(-)
 create mode 100644 net/dsa/master.h
net/dsa/dsa2.c +1 -0
index 5a9cf74a0166..10cd4ea9afe1 100644
@@ -19,6 +19,7 @@
 
 #include "devlink.h"
 #include "dsa_priv.h"
+#include "master.h"
 #include "port.h"
 
 static DEFINE_MUTEX(dsa2_mutex);
net/dsa/dsa_priv.h +0 -9
index 81ddc52feb94..94e385ec6da5 100644
@@ -259,15 +259,6 @@ static inline int dsa_tag_protocol_overhead(const struct dsa_device_ops *ops)
 	return ops->needed_headroom + ops->needed_tailroom;
 }
 
-/* master.c */
-int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp);
-void dsa_master_teardown(struct net_device *dev);
-int dsa_master_lag_setup(struct net_device *lag_dev, struct dsa_port *cpu_dp,
-			 struct netdev_lag_upper_info *uinfo,
-			 struct netlink_ext_ack *extack);
-void dsa_master_lag_teardown(struct net_device *lag_dev,
-			     struct dsa_port *cpu_dp);
-
 static inline struct net_device *dsa_master_find_slave(struct net_device *dev,
 						       int device, int port)
 {
net/dsa/master.c +6 -0
index 0d3ef591b3b4..6105821834a2 100644
@@ -6,7 +6,13 @@
  *	Vivien Didelot <[email protected]>
  */
 
+#include <linux/ethtool.h>
+#include <linux/netdevice.h>
+#include <linux/netlink.h>
+#include <net/dsa.h>
+
 #include "dsa_priv.h"
+#include "master.h"
 #include "port.h"
 
 static int dsa_master_get_regs_len(struct net_device *dev)
net/dsa/master.h new file +19 -0
new file mode 100644
index 000000000000..3fc0e610b5b5
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef __DSA_MASTER_H
+#define __DSA_MASTER_H
+
+struct dsa_port;
+struct net_device;
+struct netdev_lag_upper_info;
+struct netlink_ext_ack;
+
+int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp);
+void dsa_master_teardown(struct net_device *dev);
+int dsa_master_lag_setup(struct net_device *lag_dev, struct dsa_port *cpu_dp,
+			 struct netdev_lag_upper_info *uinfo,
+			 struct netlink_ext_ack *extack);
+void dsa_master_lag_teardown(struct net_device *lag_dev,
+			     struct dsa_port *cpu_dp);
+
+#endif
net/dsa/slave.c +1 -0
index b782a1788f5a..523f9ebeb45b 100644
@@ -24,6 +24,7 @@
 
 #include "dsa_priv.h"
 #include "port.h"
+#include "master.h"
 
 static void dsa_slave_standalone_event_work(struct work_struct *work)
 {
Signature · 1 line
2.34.1
author maintainer
#15 lore raw

PATCH 8/17 net: dsa: move headers exported by slave.c to slave.h

In reply to Vladimir Oltean

Minimize the use of the bloated dsa_priv.h by moving the prototypes exported by slave.c to their own header file.

This is just approximate to get the code structure right. There are some interdependencies with static inline code left in dsa_priv.h, so leave slave.h included from there for now.

---
 net/dsa/dsa.c      |  1 +
 net/dsa/dsa2.c     |  1 +
 net/dsa/dsa_priv.h | 59 ++-------------------------------------
 net/dsa/netlink.c  |  1 +
 net/dsa/port.c     |  1 +
 net/dsa/slave.c    |  1 +
 net/dsa/slave.h    | 69 ++++++++++++++++++++++++++++++++++++++++++++++
 net/dsa/switch.c   |  1 +
 8 files changed, 77 insertions(+), 57 deletions(-)
 create mode 100644 net/dsa/slave.h
net/dsa/dsa.c +1 -0
index 842a1f2488b2..422f8853d1c4 100644
@@ -14,6 +14,7 @@
 #include <net/dst_metadata.h>
 
 #include "dsa_priv.h"
+#include "slave.h"
 
 static LIST_HEAD(dsa_tag_drivers_list);
 static DEFINE_MUTEX(dsa_tag_drivers_lock);
net/dsa/dsa2.c +1 -0
index 10cd4ea9afe1..f917e695d38c 100644
@@ -21,6 +21,7 @@
 #include "dsa_priv.h"
 #include "master.h"
 #include "port.h"
+#include "slave.h"
 
 static DEFINE_MUTEX(dsa2_mutex);
 LIST_HEAD(dsa_tree_list);
net/dsa/dsa_priv.h +2 -57

80 lines not on this page · raw message

net/dsa/netlink.c +1 -0
index ecf9ed1de185..824b09d904cc 100644
@@ -5,6 +5,7 @@
 #include <net/rtnetlink.h>
 
 #include "dsa_priv.h"
+#include "slave.h"
 
 static const struct nla_policy dsa_policy[IFLA_DSA_MAX + 1] = {
 	[IFLA_DSA_MASTER]	= { .type = NLA_U32 },
net/dsa/port.c +1 -0
index 0708fe8d4736..56728242f079 100644
@@ -14,6 +14,7 @@
 
 #include "dsa_priv.h"
 #include "port.h"
+#include "slave.h"
 
 /**
  * dsa_port_notify - Notify the switching fabric of changes to a port
net/dsa/slave.c +1 -0
index 523f9ebeb45b..2cf83892072f 100644
@@ -25,6 +25,7 @@
 #include "dsa_priv.h"
 #include "port.h"
 #include "master.h"
+#include "slave.h"
 
 static void dsa_slave_standalone_event_work(struct work_struct *work)
 {
net/dsa/slave.h new file +69 -0

69 lines not on this page · raw message

net/dsa/switch.c +1 -0
index 5ece5c5c2acf..d0d5a1c7e6f6 100644
@@ -14,6 +14,7 @@
 
 #include "dsa_priv.h"
 #include "port.h"
+#include "slave.h"
 
 static unsigned int dsa_switch_fastest_ageing_time(struct dsa_switch *ds,
 						   unsigned int ageing_time)
Signature · 1 line
2.34.1
Reviewed-by on v1 8/17
#16 lore raw

Re: [PATCH net-next 08/17] net: dsa: move headers exported by slave.c to slave.h

Quoted 8 lines · Vladimir Oltean

Minimize the use of the bloated dsa_priv.h by moving the prototypes exported by slave.c to their own header file.

This is just approximate to get the code structure right. There are some interdependencies with static inline code left in dsa_priv.h, so leave slave.h included from there for now.

Signature · 1 line
Florian
author maintainer
#17 lore raw

PATCH 9/17 net: dsa: move tagging protocol code to tag.{c,h}

In reply to Vladimir Oltean

It would be nice if tagging protocol drivers could include just the header they need, since they are (mostly) data path and isolated from most of the other DSA core code does.

Create a tag.c and a tag.h file which are meant to support tagging protocol drivers.

---
 net/dsa/Makefile           |   1 +
 net/dsa/dsa.c              | 229 +--------------------------
 net/dsa/dsa2.c             |   1 +
 net/dsa/dsa_priv.h         | 296 -----------------------------------
 net/dsa/master.c           |   1 +
 net/dsa/slave.c            |   1 +
 net/dsa/tag.c              | 243 +++++++++++++++++++++++++++++
 net/dsa/tag.h              | 310 +++++++++++++++++++++++++++++++++++++
 net/dsa/tag_8021q.c        |   1 +
 net/dsa/tag_ar9331.c       |   2 +-
 net/dsa/tag_brcm.c         |   2 +-
 net/dsa/tag_dsa.c          |   2 +-
 net/dsa/tag_gswip.c        |   2 +-
 net/dsa/tag_hellcreek.c    |   1 +
 net/dsa/tag_ksz.c          |   3 +-
 net/dsa/tag_lan9303.c      |   2 +-
 net/dsa/tag_mtk.c          |   2 +-
 net/dsa/tag_none.c         |   2 +-
 net/dsa/tag_ocelot.c       |   3 +-
 net/dsa/tag_ocelot_8021q.c |   3 +-
 net/dsa/tag_qca.c          |   2 +-
 net/dsa/tag_rtl4_a.c       |   2 +-
 net/dsa/tag_rtl8_4.c       |   2 +-
 net/dsa/tag_rzn1_a5psw.c   |   2 +-
 net/dsa/tag_sja1105.c      |   3 +-
 net/dsa/tag_trailer.c      |   2 +-
 net/dsa/tag_xrs700x.c      |   2 +-
 27 files changed, 581 insertions(+), 541 deletions(-)
 create mode 100644 net/dsa/tag.c
 create mode 100644 net/dsa/tag.h
net/dsa/Makefile +1 -0
index bc872c0d7011..93f5d5f1e495 100644
@@ -10,6 +10,7 @@ dsa_core-y += \
 	port.o \
 	slave.o \
 	switch.o \
+	tag.o \
 	tag_8021q.o
 
 # tagging formats
net/dsa/dsa.c +1 -228

250 lines not on this page · raw message

net/dsa/dsa2.c +1 -0
index f917e695d38c..5373edf45a62 100644
@@ -22,6 +22,7 @@
 #include "master.h"
 #include "port.h"
 #include "slave.h"
+#include "tag.h"
 
 static DEFINE_MUTEX(dsa2_mutex);
 LIST_HEAD(dsa_tree_list);
net/dsa/dsa_priv.h +0 -296

319 lines not on this page · raw message

net/dsa/master.c +1 -0
index 6105821834a2..e38b349ca7f8 100644
@@ -14,6 +14,7 @@
 #include "dsa_priv.h"
 #include "master.h"
 #include "port.h"
+#include "tag.h"
 
 static int dsa_master_get_regs_len(struct net_device *dev)
 {
net/dsa/slave.c +1 -0
index 2cf83892072f..a928aaf68804 100644
@@ -26,6 +26,7 @@
 #include "port.h"
 #include "master.h"
 #include "slave.h"
+#include "tag.h"
 
 static void dsa_slave_standalone_event_work(struct work_struct *work)
 {
net/dsa/tag.c new file +243 -0

243 lines not on this page · raw message

net/dsa/tag.h new file +310 -0

310 lines not on this page · raw message

net/dsa/tag_8021q.c +1 -0
index a6617d7b692a..ee5dd1a54b51 100644
@@ -9,6 +9,7 @@
 
 #include "dsa_priv.h"
 #include "port.h"
+#include "tag.h"
 
 /* Binary structure of the fake 12-bit VID field (when the TPID is
  * ETH_P_DSA_8021Q):
net/dsa/tag_ar9331.c +1 -1
index bfa161a4f502..7f3b7d730b85 100644
@@ -7,7 +7,7 @@
 #include <linux/bitfield.h>
 #include <linux/etherdevice.h>
 
-#include "dsa_priv.h"
+#include "tag.h"
 
 #define AR9331_NAME			"ar9331"
 
net/dsa/tag_brcm.c +1 -1
index 9e7477ed70f1..10239daa5745 100644
@@ -10,7 +10,7 @@
 #include <linux/list.h>
 #include <linux/slab.h>
 
-#include "dsa_priv.h"
+#include "tag.h"
 
 #define BRCM_NAME		"brcm"
 #define BRCM_LEGACY_NAME	"brcm-legacy"
net/dsa/tag_dsa.c +1 -1
index 9fe77f5cc759..1fd7fa26db64 100644
@@ -50,7 +50,7 @@
 #include <linux/list.h>
 #include <linux/slab.h>
 
-#include "dsa_priv.h"
+#include "tag.h"
 
 #define DSA_NAME	"dsa"
 #define EDSA_NAME	"edsa"
net/dsa/tag_gswip.c +1 -1
index 020050dff3e4..e279cd9057b0 100644
@@ -10,7 +10,7 @@
 #include <linux/skbuff.h>
 #include <net/dsa.h>
 
-#include "dsa_priv.h"
+#include "tag.h"
 
 #define GSWIP_NAME			"gswip"
 
net/dsa/tag_hellcreek.c +1 -0
index 03fd5f2877c8..a047041e7686 100644
@@ -12,6 +12,7 @@
 #include <net/dsa.h>
 
 #include "dsa_priv.h"
+#include "tag.h"
 
 #define HELLCREEK_NAME		"hellcreek"
 
net/dsa/tag_ksz.c +2 -1
index 37db5156f9a3..0f6ae143afc9 100644
@@ -7,7 +7,8 @@
 #include <linux/etherdevice.h>
 #include <linux/list.h>
 #include <net/dsa.h>
-#include "dsa_priv.h"
+
+#include "tag.h"
 
 #define KSZ8795_NAME "ksz8795"
 #define KSZ9477_NAME "ksz9477"
net/dsa/tag_lan9303.c +1 -1
index 4118292ed218..c25f5536706b 100644
@@ -7,7 +7,7 @@
 #include <linux/list.h>
 #include <linux/slab.h>
 
-#include "dsa_priv.h"
+#include "tag.h"
 
 /* To define the outgoing port and to discover the incoming port a regular
  * VLAN tag is used by the LAN9303. But its VID meaning is 'special':
net/dsa/tag_mtk.c +1 -1
index 8948c4f99f8e..40af80452747 100644
@@ -8,7 +8,7 @@
 #include <linux/etherdevice.h>
 #include <linux/if_vlan.h>
 
-#include "dsa_priv.h"
+#include "tag.h"
 
 #define MTK_NAME		"mtk"
 
net/dsa/tag_none.c +1 -1
index 34a13c50d245..d2fd179c4227 100644
@@ -8,7 +8,7 @@
  * tagging support, look at tag_8021q.c instead.
  */
 
-#include "dsa_priv.h"
+#include "tag.h"
 
 #define NONE_NAME	"none"
 
net/dsa/tag_ocelot.c +2 -1
index 8cc31ab47e28..28ebecafdd24 100644
@@ -2,7 +2,8 @@
 /* Copyright 2019 NXP
  */
 #include <linux/dsa/ocelot.h>
-#include "dsa_priv.h"
+
+#include "tag.h"
 
 #define OCELOT_NAME	"ocelot"
 #define SEVILLE_NAME	"seville"
net/dsa/tag_ocelot_8021q.c +2 -1
index d1ec68001487..7f0c2d71e89b 100644
@@ -10,7 +10,8 @@
  */
 #include <linux/dsa/8021q.h>
 #include <linux/dsa/ocelot.h>
-#include "dsa_priv.h"
+
+#include "tag.h"
 
 #define OCELOT_8021Q_NAME "ocelot-8021q"
 
net/dsa/tag_qca.c +1 -1
index 73d6e111228d..e757c8de06f1 100644
@@ -8,7 +8,7 @@
 #include <net/dsa.h>
 #include <linux/dsa/tag_qca.h>
 
-#include "dsa_priv.h"
+#include "tag.h"
 
 #define QCA_NAME "qca"
 
net/dsa/tag_rtl4_a.c +1 -1
index 18b52d77d200..c327314b95e3 100644
@@ -18,7 +18,7 @@
 #include <linux/etherdevice.h>
 #include <linux/bits.h>
 
-#include "dsa_priv.h"
+#include "tag.h"
 
 #define RTL4_A_NAME		"rtl4a"
 
net/dsa/tag_rtl8_4.c +1 -1
index 030a8cf0ad48..4f67834fd121 100644
@@ -77,7 +77,7 @@
 #include <linux/bits.h>
 #include <linux/etherdevice.h>
 
-#include "dsa_priv.h"
+#include "tag.h"
 
 /* Protocols supported:
  *
net/dsa/tag_rzn1_a5psw.c +1 -1
index b9135069f9fc..437a6820ac42 100644
@@ -10,7 +10,7 @@
 #include <linux/if_ether.h>
 #include <net/dsa.h>
 
-#include "dsa_priv.h"
+#include "tag.h"
 
 /* To define the outgoing port and to discover the incoming port a TAG is
  * inserted after Src MAC :
net/dsa/tag_sja1105.c +2 -1
index 3b6e642a90e9..8f581617e15c 100644
@@ -5,7 +5,8 @@
 #include <linux/dsa/sja1105.h>
 #include <linux/dsa/8021q.h>
 #include <linux/packing.h>
-#include "dsa_priv.h"
+
+#include "tag.h"
 
 #define SJA1105_NAME				"sja1105"
 #define SJA1110_NAME				"sja1110"
net/dsa/tag_trailer.c +1 -1
index 8754dfe680f6..7361b9106382 100644
@@ -8,7 +8,7 @@
 #include <linux/list.h>
 #include <linux/slab.h>
 
-#include "dsa_priv.h"
+#include "tag.h"
 
 #define TRAILER_NAME "trailer"
 
net/dsa/tag_xrs700x.c +1 -1
index dc935dd90f98..af19969f9bc4 100644
@@ -7,7 +7,7 @@
 
 #include <linux/bitops.h>
 
-#include "dsa_priv.h"
+#include "tag.h"
 
 #define XRS700X_NAME "xrs700x"
 
Signature · 1 line
2.34.1
Reviewed-by on v1 9/17
#18 lore raw

Re: [PATCH net-next 09/17] net: dsa: move tagging protocol code to tag.{c,h}

Quoted 8 lines · Vladimir Oltean

It would be nice if tagging protocol drivers could include just the header they need, since they are (mostly) data path and isolated from most of the other DSA core code does.

Create a tag.c and a tag.h file which are meant to support tagging protocol drivers.

Signature · 1 line
Florian
author maintainer
#19 lore raw

PATCH 10/17 net: dsa: move headers exported by switch.c to switch.h

In reply to Vladimir Oltean

Reduce code bloat in dsa_priv.h by moving the prototypes exported by switch.h into their own header file.

---
 net/dsa/dsa2.c      |  1 +
 net/dsa/dsa_priv.h  |  4 ----
 net/dsa/port.c      |  1 +
 net/dsa/switch.c    |  1 +
 net/dsa/switch.h    | 11 +++++++++++
 net/dsa/tag_8021q.c |  1 +
 6 files changed, 15 insertions(+), 4 deletions(-)
 create mode 100644 net/dsa/switch.h
net/dsa/dsa2.c +1 -0
index 5373edf45a62..7c6b689267d0 100644
@@ -22,6 +22,7 @@
 #include "master.h"
 #include "port.h"
 #include "slave.h"
+#include "switch.h"
 #include "tag.h"
 
 static DEFINE_MUTEX(dsa2_mutex);
net/dsa/dsa_priv.h +0 -4
index eee2c9729e32..4f21228c6f52 100644
@@ -155,10 +155,6 @@ bool dsa_schedule_work(struct work_struct *work);
 /* netlink.c */
 extern struct rtnl_link_ops dsa_link_ops __read_mostly;
 
-/* switch.c */
-int dsa_switch_register_notifier(struct dsa_switch *ds);
-void dsa_switch_unregister_notifier(struct dsa_switch *ds);
-
 static inline bool dsa_switch_supports_uc_filtering(struct dsa_switch *ds)
 {
 	return ds->ops->port_fdb_add && ds->ops->port_fdb_del &&
net/dsa/port.c +1 -0
index 56728242f079..bf2c98215021 100644
@@ -15,6 +15,7 @@
 #include "dsa_priv.h"
 #include "port.h"
 #include "slave.h"
+#include "switch.h"
 
 /**
  * dsa_port_notify - Notify the switching fabric of changes to a port
net/dsa/switch.c +1 -0
index d0d5a1c7e6f6..6a1c84c5ec8b 100644
@@ -15,6 +15,7 @@
 #include "dsa_priv.h"
 #include "port.h"
 #include "slave.h"
+#include "switch.h"
 
 static unsigned int dsa_switch_fastest_ageing_time(struct dsa_switch *ds,
 						   unsigned int ageing_time)
net/dsa/switch.h new file +11 -0
new file mode 100644
index 000000000000..b831b6fb45e9
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef __DSA_SWITCH_H
+#define __DSA_SWITCH_H
+
+struct dsa_switch;
+
+int dsa_switch_register_notifier(struct dsa_switch *ds);
+void dsa_switch_unregister_notifier(struct dsa_switch *ds);
+
+#endif
net/dsa/tag_8021q.c +1 -0
index ee5dd1a54b51..abd994dc76d5 100644
@@ -9,6 +9,7 @@
 
 #include "dsa_priv.h"
 #include "port.h"
+#include "switch.h"
 #include "tag.h"
 
 /* Binary structure of the fake 12-bit VID field (when the TPID is
Signature · 1 line
2.34.1
author maintainer
#21 lore raw

PATCH 11/17 net: dsa: move dsa_tree_notify() and dsa_broadcast() to switch.c

In reply to Vladimir Oltean

There isn't an intuitive place for these 2 cross-chip notifier functions according to the function-to-file classification based on names (dsa_switch_*() goes to switch.c), but I consider these to be part of the cross-chip notifier handling, therefore part of switch.c. Move them there to reduce bloat in dsa2.c (the place where all code with no better place to go goes).

---
 net/dsa/dsa2.c     | 46 ----------------------------------------------
 net/dsa/dsa_priv.h |  2 --
 net/dsa/switch.c   | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 net/dsa/switch.h   |  4 ++++
 4 files changed, 50 insertions(+), 48 deletions(-)
net/dsa/dsa2.c +0 -46
index 7c6b689267d0..7a314c8b3aaa 100644
@@ -31,52 +31,6 @@ LIST_HEAD(dsa_tree_list);
 /* Track the bridges with forwarding offload enabled */
 static unsigned long dsa_fwd_offloading_bridges;
 
-/**
- * dsa_tree_notify - Execute code for all switches in a DSA switch tree.
- * @dst: collection of struct dsa_switch devices to notify.
- * @e: event, must be of type DSA_NOTIFIER_*
- * @v: event-specific value.
- *
- * Given a struct dsa_switch_tree, this can be used to run a function once for
- * each member DSA switch. The other alternative of traversing the tree is only
- * through its ports list, which does not uniquely list the switches.
- */
-int dsa_tree_notify(struct dsa_switch_tree *dst, unsigned long e, void *v)
-{
-	struct raw_notifier_head *nh = &dst->nh;
-	int err;
-
-	err = raw_notifier_call_chain(nh, e, v);
-
-	return notifier_to_errno(err);
-}
-
-/**
- * dsa_broadcast - Notify all DSA trees in the system.
- * @e: event, must be of type DSA_NOTIFIER_*
- * @v: event-specific value.
- *
- * Can be used to notify the switching fabric of events such as cross-chip
- * bridging between disjoint trees (such as islands of tagger-compatible
- * switches bridged by an incompatible middle switch).
- *
- * WARNING: this function is not reliable during probe time, because probing
- * between trees is asynchronous and not all DSA trees might have probed.
- */
-int dsa_broadcast(unsigned long e, void *v)
-{
-	struct dsa_switch_tree *dst;
-	int err = 0;
-
-	list_for_each_entry(dst, &dsa_tree_list, list) {
-		err = dsa_tree_notify(dst, e, v);
-		if (err)
-			break;
-	}
-
-	return err;
-}
-
 /**
  * dsa_lag_map() - Map LAG structure to a linear LAG array
  * @dst: Tree in which to record the mapping.
net/dsa/dsa_priv.h +0 -2
index 4f21228c6f52..8cf8608344f5 100644
@@ -175,8 +175,6 @@ void dsa_lag_unmap(struct dsa_switch_tree *dst, struct dsa_lag *lag);
 struct dsa_lag *dsa_tree_lag_find(struct dsa_switch_tree *dst,
 				  const struct net_device *lag_dev);
 struct net_device *dsa_tree_find_first_master(struct dsa_switch_tree *dst);
-int dsa_tree_notify(struct dsa_switch_tree *dst, unsigned long e, void *v);
-int dsa_broadcast(unsigned long e, void *v);
 int dsa_tree_change_tag_proto(struct dsa_switch_tree *dst,
 			      const struct dsa_device_ops *tag_ops,
 			      const struct dsa_device_ops *old_tag_ops);
net/dsa/switch.c +46 -0

52 lines not on this page · raw message

net/dsa/switch.h +4 -0
index b831b6fb45e9..b2fd496bc56f 100644
@@ -3,8 +3,12 @@
 #ifndef __DSA_SWITCH_H
 #define __DSA_SWITCH_H
 
+struct dsa_switch_tree;
 struct dsa_switch;
 
+int dsa_tree_notify(struct dsa_switch_tree *dst, unsigned long e, void *v);
+int dsa_broadcast(unsigned long e, void *v);
+
 int dsa_switch_register_notifier(struct dsa_switch *ds);
 void dsa_switch_unregister_notifier(struct dsa_switch *ds);
 
Signature · 1 line
2.34.1
Reviewed-by on v1 11/17
#22 lore raw

Re: [PATCH net-next 11/17] net: dsa: move dsa_tree_notify() and dsa_broadcast() to switch.c

Quoted 8 lines · Vladimir Oltean

There isn't an intuitive place for these 2 cross-chip notifier functions according to the function-to-file classification based on names (dsa_switch_*() goes to switch.c), but I consider these to be part of the cross-chip notifier handling, therefore part of switch.c. Move them there to reduce bloat in dsa2.c (the place where all code with no better place to go goes).

Signature · 1 line
Florian
author maintainer
#23 lore raw

PATCH 12/17 net: dsa: move notifier definitions to switch.h

In reply to Vladimir Oltean

Reduce bloat in dsa_priv.h by moving the cross-chip notifier data structures to switch.h.

---
 net/dsa/dsa_priv.h | 104 +-----------------------------------------
 net/dsa/switch.h   | 109 ++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 108 insertions(+), 105 deletions(-)
net/dsa/dsa_priv.h +1 -103
index 8cf8608344f5..e5d421cdaa8f 100644
@@ -13,109 +13,7 @@
 
 #define DSA_MAX_NUM_OFFLOADING_BRIDGES		BITS_PER_LONG
 
-enum {
-	DSA_NOTIFIER_AGEING_TIME,
-	DSA_NOTIFIER_BRIDGE_JOIN,
-	DSA_NOTIFIER_BRIDGE_LEAVE,
-	DSA_NOTIFIER_FDB_ADD,
-	DSA_NOTIFIER_FDB_DEL,
-	DSA_NOTIFIER_HOST_FDB_ADD,
-	DSA_NOTIFIER_HOST_FDB_DEL,
-	DSA_NOTIFIER_LAG_FDB_ADD,
-	DSA_NOTIFIER_LAG_FDB_DEL,
-	DSA_NOTIFIER_LAG_CHANGE,
-	DSA_NOTIFIER_LAG_JOIN,
-	DSA_NOTIFIER_LAG_LEAVE,
-	DSA_NOTIFIER_MDB_ADD,
-	DSA_NOTIFIER_MDB_DEL,
-	DSA_NOTIFIER_HOST_MDB_ADD,
-	DSA_NOTIFIER_HOST_MDB_DEL,
-	DSA_NOTIFIER_VLAN_ADD,
-	DSA_NOTIFIER_VLAN_DEL,
-	DSA_NOTIFIER_HOST_VLAN_ADD,
-	DSA_NOTIFIER_HOST_VLAN_DEL,
-	DSA_NOTIFIER_MTU,
-	DSA_NOTIFIER_TAG_PROTO,
-	DSA_NOTIFIER_TAG_PROTO_CONNECT,
-	DSA_NOTIFIER_TAG_PROTO_DISCONNECT,
-	DSA_NOTIFIER_TAG_8021Q_VLAN_ADD,
-	DSA_NOTIFIER_TAG_8021Q_VLAN_DEL,
-	DSA_NOTIFIER_MASTER_STATE_CHANGE,
-};
-
-/* DSA_NOTIFIER_AGEING_TIME */
-struct dsa_notifier_ageing_time_info {
-	unsigned int ageing_time;
-};
-
-/* DSA_NOTIFIER_BRIDGE_* */
-struct dsa_notifier_bridge_info {
-	const struct dsa_port *dp;
-	struct dsa_bridge bridge;
-	bool tx_fwd_offload;
-	struct netlink_ext_ack *extack;
-};
-
-/* DSA_NOTIFIER_FDB_* */
-struct dsa_notifier_fdb_info {
-	const struct dsa_port *dp;
-	const unsigned char *addr;
-	u16 vid;
-	struct dsa_db db;
-};
-
-/* DSA_NOTIFIER_LAG_FDB_* */
-struct dsa_notifier_lag_fdb_info {
-	struct dsa_lag *lag;
-	const unsigned char *addr;
-	u16 vid;
-	struct dsa_db db;
-};
-
-/* DSA_NOTIFIER_MDB_* */
-struct dsa_notifier_mdb_info {
-	const struct dsa_port *dp;
-	const struct switchdev_obj_port_mdb *mdb;
-	struct dsa_db db;
-};
-
-/* DSA_NOTIFIER_LAG_* */
-struct dsa_notifier_lag_info {
-	const struct dsa_port *dp;
-	struct dsa_lag lag;
-	struct netdev_lag_upper_info *info;
-	struct netlink_ext_ack *extack;
-};
-
-/* DSA_NOTIFIER_VLAN_* */
-struct dsa_notifier_vlan_info {
-	const struct dsa_port *dp;
-	const struct switchdev_obj_port_vlan *vlan;
-	struct netlink_ext_ack *extack;
-};
-
-/* DSA_NOTIFIER_MTU */
-struct dsa_notifier_mtu_info {
-	const struct dsa_port *dp;
-	int mtu;
-};
-
-/* DSA_NOTIFIER_TAG_PROTO_* */
-struct dsa_notifier_tag_proto_info {
-	const struct dsa_device_ops *tag_ops;
-};
-
-/* DSA_NOTIFIER_TAG_8021Q_VLAN_* */
-struct dsa_notifier_tag_8021q_vlan_info {
-	const struct dsa_port *dp;
-	u16 vid;
-};
-
-/* DSA_NOTIFIER_MASTER_STATE_CHANGE */
-struct dsa_notifier_master_state_info {
-	const struct net_device *master;
-	bool operational;
-};
+struct dsa_notifier_tag_8021q_vlan_info;
 
 struct dsa_switchdev_event_work {
 	struct net_device *dev;
net/dsa/switch.h +107 -2

115 lines not on this page · raw message

Signature · 1 line
2.34.1
author maintainer
#25 lore raw

PATCH 13/17 net: dsa: merge dsa.c into dsa2.c

In reply to Vladimir Oltean

There is no longer a meaningful distinction between what goes into dsa2.c and what goes into dsa.c. Merge the 2 into a single file.

---
 net/dsa/Makefile   |   1 -
 net/dsa/dsa.c      | 234 ---------------------------------------------
 net/dsa/dsa2.c     | 222 +++++++++++++++++++++++++++++++++++++++++-
 net/dsa/dsa_priv.h |   2 -
 4 files changed, 221 insertions(+), 238 deletions(-)
 delete mode 100644 net/dsa/dsa.c
net/dsa/Makefile +0 -1
index 93f5d5f1e495..f38d0f4bf76c 100644
@@ -3,7 +3,6 @@
 obj-$(CONFIG_NET_DSA) += dsa_core.o
 dsa_core-y += \
 	devlink.o \
-	dsa.o \
 	dsa2.o \
 	master.o \
 	netlink.o \
net/dsa/dsa.c deleted +0 -234

234 lines not on this page · raw message

net/dsa/dsa2.c +221 -1

251 lines not on this page · raw message

net/dsa/dsa_priv.h +0 -2
index e5d421cdaa8f..3f6f84150592 100644
@@ -44,8 +44,6 @@ struct dsa_standalone_event_work {
 };
 
 /* dsa.c */
-struct net_device *dsa_dev_to_net_device(struct device *dev);
-
 bool dsa_db_equal(const struct dsa_db *a, const struct dsa_db *b);
 
 bool dsa_schedule_work(struct work_struct *work);
Signature · 1 line
2.34.1
author maintainer
#27 lore raw

PATCH 14/17 net: dsa: rename dsa2.c back into dsa.c and create its header

In reply to Vladimir Oltean

The previous change moved the code into the larger file (dsa2.c) to minimize the delta. Rename that now to dsa.c, and create dsa.h, where all related definitions from dsa_priv.h go.

---
 net/dsa/Makefile          |  2 +-
 net/dsa/{dsa2.c => dsa.c} |  1 +
 net/dsa/dsa.h             | 40 +++++++++++++++++++++++++++++++++++++++
 net/dsa/dsa_priv.h        | 28 ---------------------------
 net/dsa/master.c          |  2 +-
 net/dsa/port.c            |  2 +-
 net/dsa/slave.c           |  1 +
 net/dsa/switch.c          |  1 +
 8 files changed, 46 insertions(+), 31 deletions(-)
 rename net/dsa/{dsa2.c => dsa.c} (99%)
 create mode 100644 net/dsa/dsa.h
net/dsa/Makefile +1 -1
index f38d0f4bf76c..cc7e93a562fe 100644
@@ -3,7 +3,7 @@
 obj-$(CONFIG_NET_DSA) += dsa_core.o
 dsa_core-y += \
 	devlink.o \
-	dsa2.o \
+	dsa.o \
 	master.o \
 	netlink.o \
 	port.o \
net/dsa/dsa.c renamed from net/dsa/dsa2.c +1 -0
similarity index 99%
rename from net/dsa/dsa2.c
rename to net/dsa/dsa.c
index 7a75b0767dd1..fee4d28b7304 100644
@@ -20,6 +20,7 @@
 #include <net/sch_generic.h>
 
 #include "devlink.h"
+#include "dsa.h"
 #include "dsa_priv.h"
 #include "master.h"
 #include "port.h"
net/dsa/dsa.h new file +40 -0
new file mode 100644
index 000000000000..b7e17ae1094d
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef __DSA_H
+#define __DSA_H
+
+#include <linux/list.h>
+#include <linux/types.h>
+
+struct dsa_db;
+struct dsa_device_ops;
+struct dsa_lag;
+struct dsa_switch_tree;
+struct net_device;
+struct work_struct;
+
+extern struct list_head dsa_tree_list;
+
+bool dsa_db_equal(const struct dsa_db *a, const struct dsa_db *b);
+bool dsa_schedule_work(struct work_struct *work);
+void dsa_lag_map(struct dsa_switch_tree *dst, struct dsa_lag *lag);
+void dsa_lag_unmap(struct dsa_switch_tree *dst, struct dsa_lag *lag);
+struct dsa_lag *dsa_tree_lag_find(struct dsa_switch_tree *dst,
+				  const struct net_device *lag_dev);
+struct net_device *dsa_tree_find_first_master(struct dsa_switch_tree *dst);
+int dsa_tree_change_tag_proto(struct dsa_switch_tree *dst,
+			      const struct dsa_device_ops *tag_ops,
+			      const struct dsa_device_ops *old_tag_ops);
+void dsa_tree_master_admin_state_change(struct dsa_switch_tree *dst,
+					struct net_device *master,
+					bool up);
+void dsa_tree_master_oper_state_change(struct dsa_switch_tree *dst,
+				       struct net_device *master,
+				       bool up);
+unsigned int dsa_bridge_num_get(const struct net_device *bridge_dev, int max);
+void dsa_bridge_num_put(const struct net_device *bridge_dev,
+			unsigned int bridge_num);
+struct dsa_bridge *dsa_tree_bridge_find(struct dsa_switch_tree *dst,
+					const struct net_device *br);
+
+#endif
net/dsa/dsa_priv.h +0 -28
index 3f6f84150592..b7ec6efe8b74 100644
@@ -43,11 +43,6 @@ struct dsa_standalone_event_work {
 	u16 vid;
 };
 
-/* dsa.c */
-bool dsa_db_equal(const struct dsa_db *a, const struct dsa_db *b);
-
-bool dsa_schedule_work(struct work_struct *work);
-
 /* netlink.c */
 extern struct rtnl_link_ops dsa_link_ops __read_mostly;
 
@@ -65,33 +60,10 @@ static inline bool dsa_switch_supports_mc_filtering(struct dsa_switch *ds)
 	       !ds->needs_standalone_vlan_filtering;
 }
 
-/* dsa2.c */
-void dsa_lag_map(struct dsa_switch_tree *dst, struct dsa_lag *lag);
-void dsa_lag_unmap(struct dsa_switch_tree *dst, struct dsa_lag *lag);
-struct dsa_lag *dsa_tree_lag_find(struct dsa_switch_tree *dst,
-				  const struct net_device *lag_dev);
-struct net_device *dsa_tree_find_first_master(struct dsa_switch_tree *dst);
-int dsa_tree_change_tag_proto(struct dsa_switch_tree *dst,
-			      const struct dsa_device_ops *tag_ops,
-			      const struct dsa_device_ops *old_tag_ops);
-void dsa_tree_master_admin_state_change(struct dsa_switch_tree *dst,
-					struct net_device *master,
-					bool up);
-void dsa_tree_master_oper_state_change(struct dsa_switch_tree *dst,
-				       struct net_device *master,
-				       bool up);
-unsigned int dsa_bridge_num_get(const struct net_device *bridge_dev, int max);
-void dsa_bridge_num_put(const struct net_device *bridge_dev,
-			unsigned int bridge_num);
-struct dsa_bridge *dsa_tree_bridge_find(struct dsa_switch_tree *dst,
-					const struct net_device *br);
-
 /* tag_8021q.c */
 int dsa_switch_tag_8021q_vlan_add(struct dsa_switch *ds,
 				  struct dsa_notifier_tag_8021q_vlan_info *info);
 int dsa_switch_tag_8021q_vlan_del(struct dsa_switch *ds,
 				  struct dsa_notifier_tag_8021q_vlan_info *info);
 
-extern struct list_head dsa_tree_list;
-
 #endif
net/dsa/master.c +1 -1
index e38b349ca7f8..26d90140d271 100644
@@ -11,7 +11,7 @@
 #include <linux/netlink.h>
 #include <net/dsa.h>
 
-#include "dsa_priv.h"
+#include "dsa.h"
 #include "master.h"
 #include "port.h"
 #include "tag.h"
net/dsa/port.c +1 -1
index bf2c98215021..e6d5c05b41b4 100644
@@ -12,7 +12,7 @@
 #include <linux/of_mdio.h>
 #include <linux/of_net.h>
 
-#include "dsa_priv.h"
+#include "dsa.h"
 #include "port.h"
 #include "slave.h"
 #include "switch.h"
net/dsa/slave.c +1 -0
index a928aaf68804..d4c436930a04 100644
@@ -22,6 +22,7 @@
 #include <net/dcbnl.h>
 #include <linux/netpoll.h>
 
+#include "dsa.h"
 #include "dsa_priv.h"
 #include "port.h"
 #include "master.h"
net/dsa/switch.c +1 -0
index b534116dc519..4420af0081af 100644
@@ -12,6 +12,7 @@
 #include <linux/if_vlan.h>
 #include <net/switchdev.h>
 
+#include "dsa.h"
 #include "dsa_priv.h"
 #include "port.h"
 #include "slave.h"
Signature · 1 line
2.34.1
Reviewed-by on v1 14/17
#28 lore raw

Re: [PATCH net-next 14/17] net: dsa: rename dsa2.c back into dsa.c and create its header

Quoted 5 lines · Vladimir Oltean

The previous change moved the code into the larger file (dsa2.c) to minimize the delta. Rename that now to dsa.c, and create dsa.h, where all related definitions from dsa_priv.h go.

Signature · 1 line
Florian
author maintainer
#29 lore raw

PATCH 15/17 net: dsa: move definitions from dsa_priv.h to slave.c

In reply to Vladimir Oltean

There are some definitions in dsa_priv.h which are only used from slave.c. So move them to slave.c.

---
 net/dsa/dsa_priv.h | 42 ------------------------------------------
 net/dsa/slave.c    | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 42 deletions(-)
net/dsa/dsa_priv.h +0 -42
index b7ec6efe8b74..aa685d2309e0 100644
@@ -15,51 +15,9 @@
 
 struct dsa_notifier_tag_8021q_vlan_info;
 
-struct dsa_switchdev_event_work {
-	struct net_device *dev;
-	struct net_device *orig_dev;
-	struct work_struct work;
-	unsigned long event;
-	/* Specific for SWITCHDEV_FDB_ADD_TO_DEVICE and
-	 * SWITCHDEV_FDB_DEL_TO_DEVICE
-	 */
-	unsigned char addr[ETH_ALEN];
-	u16 vid;
-	bool host_addr;
-};
-
-enum dsa_standalone_event {
-	DSA_UC_ADD,
-	DSA_UC_DEL,
-	DSA_MC_ADD,
-	DSA_MC_DEL,
-};
-
-struct dsa_standalone_event_work {
-	struct work_struct work;
-	struct net_device *dev;
-	enum dsa_standalone_event event;
-	unsigned char addr[ETH_ALEN];
-	u16 vid;
-};
-
 /* netlink.c */
 extern struct rtnl_link_ops dsa_link_ops __read_mostly;
 
-static inline bool dsa_switch_supports_uc_filtering(struct dsa_switch *ds)
-{
-	return ds->ops->port_fdb_add && ds->ops->port_fdb_del &&
-	       ds->fdb_isolation && !ds->vlan_filtering_is_global &&
-	       !ds->needs_standalone_vlan_filtering;
-}
-
-static inline bool dsa_switch_supports_mc_filtering(struct dsa_switch *ds)
-{
-	return ds->ops->port_mdb_add && ds->ops->port_mdb_del &&
-	       ds->fdb_isolation && !ds->vlan_filtering_is_global &&
-	       !ds->needs_standalone_vlan_filtering;
-}
-
 /* tag_8021q.c */
 int dsa_switch_tag_8021q_vlan_add(struct dsa_switch *ds,
 				  struct dsa_notifier_tag_8021q_vlan_info *info);
net/dsa/slave.c +42 -0

48 lines not on this page · raw message

Signature · 1 line
2.34.1
author maintainer
#31 lore raw

PATCH 16/17 net: dsa: move tag_8021q headers to their proper place

In reply to Vladimir Oltean

tag_8021q definitions are all over the place. Some are exported to linux/dsa/8021q.h (visible by DSA core, taggers, switch drivers and everyone else), and some are in dsa_priv.h.

Move the structures that don't need external visibility into tag_8021q.c, and the ones which don't need the world or switch drivers to see them into tag_8021q.h.

We also have the tag_8021q.h inclusion from switch.c, which is basically the entire reason why tag_8021q.c was built into DSA in commit 8b6e638b4be2 ("net: dsa: build tag_8021q.c as part of DSA core"). I still don't know how to better deal with that, so leave it alone.

---
 include/linux/dsa/8021q.h  | 31 +------------------------------
 include/net/dsa.h          |  1 +
 net/dsa/dsa_priv.h         |  8 --------
 net/dsa/port.c             |  1 +
 net/dsa/switch.c           |  1 +
 net/dsa/tag_8021q.c        | 15 +++++++++++++++
 net/dsa/tag_8021q.h        | 27 +++++++++++++++++++++++++++
 net/dsa/tag_ocelot_8021q.c |  1 +
 net/dsa/tag_sja1105.c      |  1 +
 9 files changed, 48 insertions(+), 38 deletions(-)
 create mode 100644 net/dsa/tag_8021q.h
include/linux/dsa/8021q.h +1 -30
index 3ed117e299ec..f3664ee12170 100644
@@ -5,28 +5,8 @@
 #ifndef _NET_DSA_8021Q_H
 #define _NET_DSA_8021Q_H
 
-#include <linux/refcount.h>
-#include <linux/types.h>
 #include <net/dsa.h>
-
-struct dsa_switch;
-struct dsa_port;
-struct sk_buff;
-struct net_device;
-
-struct dsa_tag_8021q_vlan {
-	struct list_head list;
-	int port;
-	u16 vid;
-	refcount_t refcount;
-};
-
-struct dsa_8021q_context {
-	struct dsa_switch *ds;
-	struct list_head vlans;
-	/* EtherType of RX VID, used for filtering on master interface */
-	__be16 proto;
-};
+#include <linux/types.h>
 
 int dsa_tag_8021q_register(struct dsa_switch *ds, __be16 proto);
 
@@ -38,15 +18,6 @@ int dsa_tag_8021q_bridge_join(struct dsa_switch *ds, int port,
 void dsa_tag_8021q_bridge_leave(struct dsa_switch *ds, int port,
 				struct dsa_bridge bridge);
 
-struct sk_buff *dsa_8021q_xmit(struct sk_buff *skb, struct net_device *netdev,
-			       u16 tpid, u16 tci);
-
-void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id,
-		   int *vbid);
-
-struct net_device *dsa_tag_8021q_find_port_by_vbid(struct net_device *master,
-						   int vbid);
-
 u16 dsa_tag_8021q_bridge_vid(unsigned int bridge_num);
 
 u16 dsa_tag_8021q_standalone_vid(const struct dsa_port *dp);
include/net/dsa.h +1 -0
index d5bfcb63d4c2..96086289aa9b 100644
@@ -22,6 +22,7 @@
 #include <net/devlink.h>
 #include <net/switchdev.h>
 
+struct dsa_8021q_context;
 struct tc_action;
 struct phy_device;
 struct fixed_phy_status;
net/dsa/dsa_priv.h +0 -8
index aa685d2309e0..265659954ffd 100644
@@ -13,15 +13,7 @@
 
 #define DSA_MAX_NUM_OFFLOADING_BRIDGES		BITS_PER_LONG
 
-struct dsa_notifier_tag_8021q_vlan_info;
-
 /* netlink.c */
 extern struct rtnl_link_ops dsa_link_ops __read_mostly;
 
-/* tag_8021q.c */
-int dsa_switch_tag_8021q_vlan_add(struct dsa_switch *ds,
-				  struct dsa_notifier_tag_8021q_vlan_info *info);
-int dsa_switch_tag_8021q_vlan_del(struct dsa_switch *ds,
-				  struct dsa_notifier_tag_8021q_vlan_info *info);
-
 #endif
net/dsa/port.c +1 -0
index e6d5c05b41b4..67ad1adec2a2 100644
@@ -16,6 +16,7 @@
 #include "port.h"
 #include "slave.h"
 #include "switch.h"
+#include "tag_8021q.h"
 
 /**
  * dsa_port_notify - Notify the switching fabric of changes to a port
net/dsa/switch.c +1 -0
index 4420af0081af..e53cc0c3c933 100644
@@ -17,6 +17,7 @@
 #include "port.h"
 #include "slave.h"
 #include "switch.h"
+#include "tag_8021q.h"
 
 static unsigned int dsa_switch_fastest_ageing_time(struct dsa_switch *ds,
 						   unsigned int ageing_time)
net/dsa/tag_8021q.c +15 -0
index abd994dc76d5..ac2eb933106e 100644
@@ -11,6 +11,7 @@
 #include "port.h"
 #include "switch.h"
 #include "tag.h"
+#include "tag_8021q.h"
 
 /* Binary structure of the fake 12-bit VID field (when the TPID is
  * ETH_P_DSA_8021Q):
@@ -63,6 +64,20 @@
 #define DSA_8021Q_PORT(x)		(((x) << DSA_8021Q_PORT_SHIFT) & \
 						 DSA_8021Q_PORT_MASK)
 
+struct dsa_tag_8021q_vlan {
+	struct list_head list;
+	int port;
+	u16 vid;
+	refcount_t refcount;
+};
+
+struct dsa_8021q_context {
+	struct dsa_switch *ds;
+	struct list_head vlans;
+	/* EtherType of RX VID, used for filtering on master interface */
+	__be16 proto;
+};
+
 u16 dsa_tag_8021q_bridge_vid(unsigned int bridge_num)
 {
 	/* The VBID value of 0 is reserved for precise TX, but it is also
net/dsa/tag_8021q.h new file +27 -0
new file mode 100644
index 000000000000..b75cbaa028ef
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef __DSA_TAG_8021Q_H
+#define __DSA_TAG_8021Q_H
+
+#include <net/dsa.h>
+
+#include "switch.h"
+
+struct sk_buff;
+struct net_device;
+
+struct sk_buff *dsa_8021q_xmit(struct sk_buff *skb, struct net_device *netdev,
+			       u16 tpid, u16 tci);
+
+void dsa_8021q_rcv(struct sk_buff *skb, int *source_port, int *switch_id,
+		   int *vbid);
+
+struct net_device *dsa_tag_8021q_find_port_by_vbid(struct net_device *master,
+						   int vbid);
+
+int dsa_switch_tag_8021q_vlan_add(struct dsa_switch *ds,
+				  struct dsa_notifier_tag_8021q_vlan_info *info);
+int dsa_switch_tag_8021q_vlan_del(struct dsa_switch *ds,
+				  struct dsa_notifier_tag_8021q_vlan_info *info);
+
+#endif
net/dsa/tag_ocelot_8021q.c +1 -0
index 7f0c2d71e89b..1f0b8c20eba5 100644
@@ -12,6 +12,7 @@
 #include <linux/dsa/ocelot.h>
 
 #include "tag.h"
+#include "tag_8021q.h"
 
 #define OCELOT_8021Q_NAME "ocelot-8021q"
 
net/dsa/tag_sja1105.c +1 -0
index 8f581617e15c..f14f51b41491 100644
@@ -7,6 +7,7 @@
 #include <linux/packing.h>
 
 #include "tag.h"
+#include "tag_8021q.h"
 
 #define SJA1105_NAME				"sja1105"
 #define SJA1110_NAME				"sja1110"
Signature · 1 line
2.34.1
Reviewed-by on v1 16/17
#32 lore raw

Re: [PATCH net-next 16/17] net: dsa: move tag_8021q headers to their proper place

Quoted 8 lines · Vladimir Oltean

tag_8021q definitions are all over the place. Some are exported to linux/dsa/8021q.h (visible by DSA core, taggers, switch drivers and everyone else), and some are in dsa_priv.h.

Move the structures that don't need external visibility into tag_8021q.c, and the ones which don't need the world or switch drivers to see them into tag_8021q.h.

Quoted 6 lines

We also have the tag_8021q.h inclusion from switch.c, which is basically the entire reason why tag_8021q.c was built into DSA in commit 8b6e638b4be2 ("net: dsa: build tag_8021q.c as part of DSA core"). I still don't know how to better deal with that, so leave it alone.

Signature · 1 line
Florian
author maintainer
#33 lore raw

PATCH 17/17 net: dsa: kill off dsa_priv.h

In reply to Vladimir Oltean

The last remnants in dsa_priv.h are a netlink-related definition for which we create a new header, and DSA_MAX_NUM_OFFLOADING_BRIDGES which is only used from dsa.c, so move it there.

Some inclusions need to be adjusted now that we no longer have headers included transitively from dsa_priv.h.

---
 net/dsa/dsa.c           |  4 +++-
 net/dsa/dsa_priv.h      | 19 -------------------
 net/dsa/netlink.c       |  2 +-
 net/dsa/netlink.h       |  8 ++++++++
 net/dsa/slave.c         |  2 +-
 net/dsa/switch.c        |  2 +-
 net/dsa/tag_8021q.c     |  1 -
 net/dsa/tag_hellcreek.c |  1 -
 8 files changed, 14 insertions(+), 25 deletions(-)
 delete mode 100644 net/dsa/dsa_priv.h
 create mode 100644 net/dsa/netlink.h
net/dsa/dsa.c +3 -1
index fee4d28b7304..e5f156940c67 100644
@@ -21,13 +21,15 @@
 
 #include "devlink.h"
 #include "dsa.h"
-#include "dsa_priv.h"
 #include "master.h"
+#include "netlink.h"
 #include "port.h"
 #include "slave.h"
 #include "switch.h"
 #include "tag.h"
 
+#define DSA_MAX_NUM_OFFLOADING_BRIDGES		BITS_PER_LONG
+
 static DEFINE_MUTEX(dsa2_mutex);
 LIST_HEAD(dsa_tree_list);
 
net/dsa/dsa_priv.h deleted +0 -19
deleted file mode 100644
index 265659954ffd..000000000000
@@ -1,19 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-/*
- * net/dsa/dsa_priv.h - Hardware switch handling
- * Copyright (c) 2008-2009 Marvell Semiconductor
- */
-
-#ifndef __DSA_PRIV_H
-#define __DSA_PRIV_H
-
-#include <linux/phy.h>
-#include <linux/netdevice.h>
-#include <net/dsa.h>
-
-#define DSA_MAX_NUM_OFFLOADING_BRIDGES		BITS_PER_LONG
-
-/* netlink.c */
-extern struct rtnl_link_ops dsa_link_ops __read_mostly;
-
-#endif
net/dsa/netlink.c +1 -1
index 824b09d904cc..bd4bbaf851de 100644
@@ -4,7 +4,7 @@
 #include <linux/netdevice.h>
 #include <net/rtnetlink.h>
 
-#include "dsa_priv.h"
+#include "netlink.h"
 #include "slave.h"
 
 static const struct nla_policy dsa_policy[IFLA_DSA_MAX + 1] = {
net/dsa/netlink.h new file +8 -0
new file mode 100644
index 000000000000..7eda2fa15722
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef __DSA_NETLINK_H
+#define __DSA_NETLINK_H
+
+extern struct rtnl_link_ops dsa_link_ops __read_mostly;
+
+#endif
net/dsa/slave.c +1 -1
index 337cbd80633a..aab79c355224 100644
@@ -23,9 +23,9 @@
 #include <linux/netpoll.h>
 
 #include "dsa.h"
-#include "dsa_priv.h"
 #include "port.h"
 #include "master.h"
+#include "netlink.h"
 #include "slave.h"
 #include "tag.h"
 
net/dsa/switch.c +1 -1
index e53cc0c3c933..d5bc4bb7310d 100644
@@ -13,7 +13,7 @@
 #include <net/switchdev.h>
 
 #include "dsa.h"
-#include "dsa_priv.h"
+#include "netlink.h"
 #include "port.h"
 #include "slave.h"
 #include "switch.h"
net/dsa/tag_8021q.c +0 -1
index ac2eb933106e..b1263917fcb2 100644
@@ -7,7 +7,6 @@
 #include <linux/if_vlan.h>
 #include <linux/dsa/8021q.h>
 
-#include "dsa_priv.h"
 #include "port.h"
 #include "switch.h"
 #include "tag.h"
net/dsa/tag_hellcreek.c +0 -1
index a047041e7686..71884296fc70 100644
@@ -11,7 +11,6 @@
 #include <linux/skbuff.h>
 #include <net/dsa.h>
 
-#include "dsa_priv.h"
 #include "tag.h"
 
 #define HELLCREEK_NAME		"hellcreek"
Signature · 1 line
2.34.1
Reviewed-by on v1 17/17
#34 lore raw

Re: [PATCH net-next 17/17] net: dsa: kill off dsa_priv.h

Quoted 8 lines · Vladimir Oltean

The last remnants in dsa_priv.h are a netlink-related definition for which we create a new header, and DSA_MAX_NUM_OFFLOADING_BRIDGES which is only used from dsa.c, so move it there.

Some inclusions need to be adjusted now that we no longer have headers included transitively from dsa_priv.h.

Signature · 1 line
Florian
#35 lore raw
In reply to Vladimir Oltean
Quoted 12 lines · Vladimir Oltean

After working on the "Autoload DSA tagging driver when dynamically changing protocol" series:
https://patchwork.kernel.org/project/netdevbpf/cover/[email protected]/

it became clear to me that the situation with DSA headers is a bit messy, and I put the tagging protocol driver macros in a pretty random temporary spot in dsa_priv.h.

Now is the time to make the net/dsa/ folder a bit more organized, and to make tagging protocol driver modules include just headers they're going to use.

Quoted 6 lines

Another thing is the merging and cleanup of dsa.c and dsa2.c. Before, dsa.c had 589 lines and dsa2.c had 1817 lines. Now, the combined dsa.c has 1749 lines, the rest went to some other places.

Sorry for the set size, I know the rules, but since this is basically code movement for the most part, I thought more patches are better.

This all looks fine on paper, only concern is that it will make our lives so much more miserable for back porting fixes into older kernels, if you are fine with that as a co-maintainer, then so am I.

That argument could always be used to make zero re-structuring and it would be sad for DSA to ossify, so obviously should not be the major reason for not making changes.

Thanks for doing this work!

Signature · 1 line
Florian
author maintainer
#36 lore raw
Quoted 7 lines · Florian Fainelli

This all looks fine on paper, only concern is that it will make our lives so much more miserable for back porting fixes into older kernels, if you are fine with that as a co-maintainer, then so am I.

That argument could always be used to make zero re-structuring and it would be sad for DSA to ossify, so obviously should not be the major reason for not making changes.

I think the opposite of restructuring is not ossification as you say, but rather disorganized growth which will become even harder to disentangle later on.

The next step (at some point) is going to be reorganization of what gets exported to include/net/dsa.h and how, since to me, there's already a worrying amount of uncontrolled information being scavenged by certain DSA master drivers, even if the intended recipient for that header is switch drivers. I didn't start with include/net/dsa.h because, well, I think first you need to make your own bed before you rule the world, but in general, what is here can be seen only a small piece of what's to come.

I'm not sure what to say about backports.. it doesn't scare me too much. Maybe that's also the lack of experience speaking.

#37 lore raw
In reply to Vladimir Oltean
This series was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Mon, 21 Nov 2022 15:55:38 +0200 you wrote:

After working on the "Autoload DSA tagging driver when dynamically changing protocol" series:
https://patchwork.kernel.org/project/netdevbpf/cover/[email protected]/

it became clear to me that the situation with DSA headers is a bit messy, and I put the tagging protocol driver macros in a pretty random temporary spot in dsa_priv.h.

[...]

Here is the summary with links:
- [net-next,01/17] net: dsa: unexport dsa_dev_to_net_device()

    https://git.kernel.org/netdev/net-next/c/c5fb8ead3283
  - [net-next,02/17] net: dsa: modularize DSA_TAG_PROTO_NONE
    https://git.kernel.org/netdev/net-next/c/d2be320495b9
  - [net-next,03/17] net: dsa: move bulk of devlink code to devlink.{c,h}
    https://git.kernel.org/netdev/net-next/c/5cf2c75b5b91
  - [net-next,04/17] net: dsa: if ds->setup is true, ds->devlink is always non-NULL
    https://git.kernel.org/netdev/net-next/c/d95fa75061fb
  - [net-next,05/17] net: dsa: move rest of devlink setup/teardown to devlink.c
    https://git.kernel.org/netdev/net-next/c/7aea535d40ea
  - [net-next,06/17] net: dsa: move headers exported by port.c to port.h
    https://git.kernel.org/netdev/net-next/c/022bba63c3ca
  - [net-next,07/17] net: dsa: move headers exported by master.c to master.h
    https://git.kernel.org/netdev/net-next/c/94ef6fad3bf3
  - [net-next,08/17] net: dsa: move headers exported by slave.c to slave.h
    https://git.kernel.org/netdev/net-next/c/09f92341681a
  - [net-next,09/17] net: dsa: move tagging protocol code to tag.{c,h}
    https://git.kernel.org/netdev/net-next/c/bd954b826032
  - [net-next,10/17] net: dsa: move headers exported by switch.c to switch.h
    https://git.kernel.org/netdev/net-next/c/0c603136e1e0
  - [net-next,11/17] net: dsa: move dsa_tree_notify() and dsa_broadcast() to switch.c
    https://git.kernel.org/netdev/net-next/c/6dbdfce77357
  - [net-next,12/17] net: dsa: move notifier definitions to switch.h
    https://git.kernel.org/netdev/net-next/c/495550a4844b
  - [net-next,13/17] net: dsa: merge dsa.c into dsa2.c
    https://git.kernel.org/netdev/net-next/c/165c2fb93bed
  - [net-next,14/17] net: dsa: rename dsa2.c back into dsa.c and create its header
    https://git.kernel.org/netdev/net-next/c/47d2ce03dcfb
  - [net-next,15/17] net: dsa: move definitions from dsa_priv.h to slave.c
    https://git.kernel.org/netdev/net-next/c/8e396fec2146
  - [net-next,16/17] net: dsa: move tag_8021q headers to their proper place
    https://git.kernel.org/netdev/net-next/c/19d05ea712ec
  - [net-next,17/17] net: dsa: kill off dsa_priv.h
    https://git.kernel.org/netdev/net-next/c/5917bfe68867

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html