netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 net-next 0/9] DSA changes for multiple CPU ports (part 3)
@ 2022-08-18 13:52 Vladimir Oltean
  2022-08-18 13:52 ` [PATCH v2 net-next 1/9] net: dsa: walk through all changeupper notifier functions Vladimir Oltean
                   ` (8 more replies)
  0 siblings, 9 replies; 18+ messages in thread
From: Vladimir Oltean @ 2022-08-18 13:52 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Florian Fainelli, Vivien Didelot, Andrew Lunn, Vladimir Oltean,
	Claudiu Manoil, Alexandre Belloni, UNGLinuxDriver, Colin Foster,
	Roopa Prabhu, Nikolay Aleksandrov

Those who have been following part 1:
https://patchwork.kernel.org/project/netdevbpf/cover/20220511095020.562461-1-vladimir.oltean@nxp.com/
and part 2:
https://patchwork.kernel.org/project/netdevbpf/cover/20220521213743.2735445-1-vladimir.oltean@nxp.com/
will know that I am trying to enable the second internal port pair from
the NXP LS1028A Felix switch for DSA-tagged traffic via "ocelot-8021q".
This series represents part 3 of that effort.

Covered here are some preparations in DSA for handling multiple DSA
masters:
- when changing the tagging protocol via sysfs
- when the masters go down
as well as preparation for monitoring the upper devices of a DSA master
(to support DSA masters under a LAG).

There are also 2 small preparations for the ocelot driver, for the case
where multiple tag_8021q CPU ports are used in a LAG. Both those changes
have to do with PGID forwarding domains.

Compared to v1, the patches were trimmed down to just another
preparation stage, and the UAPI changes were pushed further out to part 4.
https://patchwork.kernel.org/project/netdevbpf/cover/20220523104256.3556016-1-olteanv@gmail.com/

Vladimir Oltean (9):
  net: dsa: walk through all changeupper notifier functions
  net: dsa: don't stop at NOTIFY_OK when calling
    ds->ops->port_prechangeupper
  net: bridge: move DSA master bridging restriction to DSA
  net: dsa: existing DSA masters cannot join upper interfaces
  net: dsa: only bring down user ports assigned to a given DSA master
  net: dsa: all DSA masters must be down when changing the tagging
    protocol
  net: dsa: use dsa_tree_for_each_cpu_port in
    dsa_tree_{setup,teardown}_master
  net: mscc: ocelot: set up tag_8021q CPU ports independent of user port
    affinity
  net: mscc: ocelot: adjust forwarding domain for CPU ports in a LAG

 drivers/net/dsa/ocelot/felix.c     |   6 ++
 drivers/net/ethernet/mscc/ocelot.c |  82 ++++++++++++--------
 include/net/dsa.h                  |   4 +
 include/soc/mscc/ocelot.h          |   2 +
 net/bridge/br_if.c                 |  20 -----
 net/dsa/dsa2.c                     |  56 ++++++--------
 net/dsa/dsa_priv.h                 |   1 -
 net/dsa/master.c                   |   2 +-
 net/dsa/slave.c                    | 119 ++++++++++++++++++++++++++---
 9 files changed, 196 insertions(+), 96 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v2 net-next 1/9] net: dsa: walk through all changeupper notifier functions
  2022-08-18 13:52 [PATCH v2 net-next 0/9] DSA changes for multiple CPU ports (part 3) Vladimir Oltean
@ 2022-08-18 13:52 ` Vladimir Oltean
  2022-08-18 13:52 ` [PATCH v2 net-next 2/9] net: dsa: don't stop at NOTIFY_OK when calling ds->ops->port_prechangeupper Vladimir Oltean
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 18+ messages in thread
From: Vladimir Oltean @ 2022-08-18 13:52 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Florian Fainelli, Vivien Didelot, Andrew Lunn, Vladimir Oltean,
	Claudiu Manoil, Alexandre Belloni, UNGLinuxDriver, Colin Foster,
	Roopa Prabhu, Nikolay Aleksandrov

Traditionally, DSA has had a single netdev notifier handling function
for each device type.

For the sake of code cleanliness, we would like to introduce more
handling functions which do one thing, but the conditions for entering
these functions start to overlap. Example: a handling function which
tracks whether any bridges contain both DSA and non-DSA interfaces.
Either this is placed before dsa_slave_changeupper(), case in which it
will prevent that function from executing, or we place it after
dsa_slave_changeupper(), case in which we will prevent it from
executing. The other alternative is to ignore errors from the new
handling function (not ideal).

To support this usage, we need to change the pattern. In the new model,
we enter all notifier handling sub-functions, and exit with NOTIFY_DONE
if there is nothing to do. This allows the sub-functions to be
relatively free-form and independent from each other.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
---
v1->v2: none

 net/dsa/slave.c | 37 ++++++++++++++++++++++++++++---------
 1 file changed, 28 insertions(+), 9 deletions(-)

diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index ad6a6663feeb..2f0400a696fc 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -2476,6 +2476,9 @@ static int dsa_slave_changeupper(struct net_device *dev,
 	struct netlink_ext_ack *extack;
 	int err = NOTIFY_DONE;
 
+	if (!dsa_slave_dev_check(dev))
+		return err;
+
 	extack = netdev_notifier_info_to_extack(&info->info);
 
 	if (netif_is_bridge_master(info->upper_dev)) {
@@ -2531,6 +2534,9 @@ static int dsa_slave_prechangeupper(struct net_device *dev,
 {
 	struct dsa_port *dp = dsa_slave_to_port(dev);
 
+	if (!dsa_slave_dev_check(dev))
+		return NOTIFY_DONE;
+
 	if (netif_is_bridge_master(info->upper_dev) && !info->linking)
 		dsa_port_pre_bridge_leave(dp, info->upper_dev);
 	else if (netif_is_lag_master(info->upper_dev) && !info->linking)
@@ -2551,6 +2557,9 @@ dsa_slave_lag_changeupper(struct net_device *dev,
 	int err = NOTIFY_DONE;
 	struct dsa_port *dp;
 
+	if (!netif_is_lag_master(dev))
+		return err;
+
 	netdev_for_each_lower_dev(dev, lower, iter) {
 		if (!dsa_slave_dev_check(lower))
 			continue;
@@ -2580,6 +2589,9 @@ dsa_slave_lag_prechangeupper(struct net_device *dev,
 	int err = NOTIFY_DONE;
 	struct dsa_port *dp;
 
+	if (!netif_is_lag_master(dev))
+		return err;
+
 	netdev_for_each_lower_dev(dev, lower, iter) {
 		if (!dsa_slave_dev_check(lower))
 			continue;
@@ -2701,22 +2713,29 @@ static int dsa_slave_netdevice_event(struct notifier_block *nb,
 		if (err != NOTIFY_DONE)
 			return err;
 
-		if (dsa_slave_dev_check(dev))
-			return dsa_slave_prechangeupper(dev, ptr);
+		err = dsa_slave_prechangeupper(dev, ptr);
+		if (notifier_to_errno(err))
+			return err;
 
-		if (netif_is_lag_master(dev))
-			return dsa_slave_lag_prechangeupper(dev, ptr);
+		err = dsa_slave_lag_prechangeupper(dev, ptr);
+		if (notifier_to_errno(err))
+			return err;
 
 		break;
 	}
-	case NETDEV_CHANGEUPPER:
-		if (dsa_slave_dev_check(dev))
-			return dsa_slave_changeupper(dev, ptr);
+	case NETDEV_CHANGEUPPER: {
+		int err;
+
+		err = dsa_slave_changeupper(dev, ptr);
+		if (notifier_to_errno(err))
+			return err;
 
-		if (netif_is_lag_master(dev))
-			return dsa_slave_lag_changeupper(dev, ptr);
+		err = dsa_slave_lag_changeupper(dev, ptr);
+		if (notifier_to_errno(err))
+			return err;
 
 		break;
+	}
 	case NETDEV_CHANGELOWERSTATE: {
 		struct netdev_notifier_changelowerstate_info *info = ptr;
 		struct dsa_port *dp;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 net-next 2/9] net: dsa: don't stop at NOTIFY_OK when calling ds->ops->port_prechangeupper
  2022-08-18 13:52 [PATCH v2 net-next 0/9] DSA changes for multiple CPU ports (part 3) Vladimir Oltean
  2022-08-18 13:52 ` [PATCH v2 net-next 1/9] net: dsa: walk through all changeupper notifier functions Vladimir Oltean
@ 2022-08-18 13:52 ` Vladimir Oltean
  2022-08-18 13:52 ` [PATCH v2 net-next 3/9] net: bridge: move DSA master bridging restriction to DSA Vladimir Oltean
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 18+ messages in thread
From: Vladimir Oltean @ 2022-08-18 13:52 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Florian Fainelli, Vivien Didelot, Andrew Lunn, Vladimir Oltean,
	Claudiu Manoil, Alexandre Belloni, UNGLinuxDriver, Colin Foster,
	Roopa Prabhu, Nikolay Aleksandrov

dsa_slave_prechangeupper_sanity_check() is supposed to enforce some
adjacency restrictions, and calls ds->ops->port_prechangeupper if the
driver implements it.

We convert the error code from the port_prechangeupper() call to a
notifier code, and 0 is converted to NOTIFY_OK, but the caller of
dsa_slave_prechangeupper_sanity_check() stops at any notifier code
different from NOTIFY_DONE.

Avoid this by converting back the notifier code to an error code, so
that both NOTIFY_OK and NOTIFY_DONE will be seen as 0. This allows more
parallel sanity check functions to be added.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
---
v1->v2: none

 net/dsa/slave.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 2f0400a696fc..008bbe1c0285 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -2710,7 +2710,7 @@ static int dsa_slave_netdevice_event(struct notifier_block *nb,
 		int err;
 
 		err = dsa_slave_prechangeupper_sanity_check(dev, info);
-		if (err != NOTIFY_DONE)
+		if (notifier_to_errno(err))
 			return err;
 
 		err = dsa_slave_prechangeupper(dev, ptr);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 net-next 3/9] net: bridge: move DSA master bridging restriction to DSA
  2022-08-18 13:52 [PATCH v2 net-next 0/9] DSA changes for multiple CPU ports (part 3) Vladimir Oltean
  2022-08-18 13:52 ` [PATCH v2 net-next 1/9] net: dsa: walk through all changeupper notifier functions Vladimir Oltean
  2022-08-18 13:52 ` [PATCH v2 net-next 2/9] net: dsa: don't stop at NOTIFY_OK when calling ds->ops->port_prechangeupper Vladimir Oltean
@ 2022-08-18 13:52 ` Vladimir Oltean
  2022-08-18 13:52 ` [PATCH v2 net-next 4/9] net: dsa: existing DSA masters cannot join upper interfaces Vladimir Oltean
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 18+ messages in thread
From: Vladimir Oltean @ 2022-08-18 13:52 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Florian Fainelli, Vivien Didelot, Andrew Lunn, Vladimir Oltean,
	Claudiu Manoil, Alexandre Belloni, UNGLinuxDriver, Colin Foster,
	Roopa Prabhu, Nikolay Aleksandrov

When DSA gains support for multiple CPU ports in a LAG, it will become
mandatory to monitor the changeupper events for the DSA master.

In fact, there are already some restrictions to be imposed in that area,
namely that a DSA master cannot be a bridge port except in some special
circumstances.

Centralize the restrictions at the level of the DSA layer as a
preliminary step.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Acked-by: Nikolay Aleksandrov <razor@blackwall.org>
---
v1->v2: none

 net/bridge/br_if.c | 20 --------------------
 net/dsa/slave.c    | 44 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 20 deletions(-)

diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c
index a84a7cfb9d6d..efbd93e92ce2 100644
--- a/net/bridge/br_if.c
+++ b/net/bridge/br_if.c
@@ -568,26 +568,6 @@ int br_add_if(struct net_bridge *br, struct net_device *dev,
 	    !is_valid_ether_addr(dev->dev_addr))
 		return -EINVAL;
 
-	/* Also don't allow bridging of net devices that are DSA masters, since
-	 * the bridge layer rx_handler prevents the DSA fake ethertype handler
-	 * to be invoked, so we don't get the chance to strip off and parse the
-	 * DSA switch tag protocol header (the bridge layer just returns
-	 * RX_HANDLER_CONSUMED, stopping RX processing for these frames).
-	 * The only case where that would not be an issue is when bridging can
-	 * already be offloaded, such as when the DSA master is itself a DSA
-	 * or plain switchdev port, and is bridged only with other ports from
-	 * the same hardware device.
-	 */
-	if (netdev_uses_dsa(dev)) {
-		list_for_each_entry(p, &br->port_list, list) {
-			if (!netdev_port_same_parent_id(dev, p->dev)) {
-				NL_SET_ERR_MSG(extack,
-					       "Cannot do software bridging with a DSA master");
-				return -EINVAL;
-			}
-		}
-	}
-
 	/* No bridging of bridges */
 	if (dev->netdev_ops->ndo_start_xmit == br_dev_xmit) {
 		NL_SET_ERR_MSG(extack,
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 008bbe1c0285..09767f4b3b37 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -2699,6 +2699,46 @@ dsa_slave_prechangeupper_sanity_check(struct net_device *dev,
 	return NOTIFY_DONE;
 }
 
+/* Don't allow bridging of DSA masters, since the bridge layer rx_handler
+ * prevents the DSA fake ethertype handler to be invoked, so we don't get the
+ * chance to strip off and parse the DSA switch tag protocol header (the bridge
+ * layer just returns RX_HANDLER_CONSUMED, stopping RX processing for these
+ * frames).
+ * The only case where that would not be an issue is when bridging can already
+ * be offloaded, such as when the DSA master is itself a DSA or plain switchdev
+ * port, and is bridged only with other ports from the same hardware device.
+ */
+static int
+dsa_bridge_prechangelower_sanity_check(struct net_device *new_lower,
+				       struct netdev_notifier_changeupper_info *info)
+{
+	struct net_device *br = info->upper_dev;
+	struct netlink_ext_ack *extack;
+	struct net_device *lower;
+	struct list_head *iter;
+
+	if (!netif_is_bridge_master(br))
+		return NOTIFY_DONE;
+
+	if (!info->linking)
+		return NOTIFY_DONE;
+
+	extack = netdev_notifier_info_to_extack(&info->info);
+
+	netdev_for_each_lower_dev(br, lower, iter) {
+		if (!netdev_uses_dsa(new_lower) && !netdev_uses_dsa(lower))
+			continue;
+
+		if (!netdev_port_same_parent_id(lower, new_lower)) {
+			NL_SET_ERR_MSG(extack,
+				       "Cannot do software bridging with a DSA master");
+			return notifier_from_errno(-EINVAL);
+		}
+	}
+
+	return NOTIFY_DONE;
+}
+
 static int dsa_slave_netdevice_event(struct notifier_block *nb,
 				     unsigned long event, void *ptr)
 {
@@ -2713,6 +2753,10 @@ static int dsa_slave_netdevice_event(struct notifier_block *nb,
 		if (notifier_to_errno(err))
 			return err;
 
+		err = dsa_bridge_prechangelower_sanity_check(dev, info);
+		if (notifier_to_errno(err))
+			return err;
+
 		err = dsa_slave_prechangeupper(dev, ptr);
 		if (notifier_to_errno(err))
 			return err;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 net-next 4/9] net: dsa: existing DSA masters cannot join upper interfaces
  2022-08-18 13:52 [PATCH v2 net-next 0/9] DSA changes for multiple CPU ports (part 3) Vladimir Oltean
                   ` (2 preceding siblings ...)
  2022-08-18 13:52 ` [PATCH v2 net-next 3/9] net: bridge: move DSA master bridging restriction to DSA Vladimir Oltean
@ 2022-08-18 13:52 ` Vladimir Oltean
  2022-08-18 13:52 ` [PATCH v2 net-next 5/9] net: dsa: only bring down user ports assigned to a given DSA master Vladimir Oltean
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 18+ messages in thread
From: Vladimir Oltean @ 2022-08-18 13:52 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Florian Fainelli, Vivien Didelot, Andrew Lunn, Vladimir Oltean,
	Claudiu Manoil, Alexandre Belloni, UNGLinuxDriver, Colin Foster,
	Roopa Prabhu, Nikolay Aleksandrov

All the traffic to/from a DSA master is supposed to be distributed among
its DSA switch upper interfaces, so we should not allow other upper
device kinds.

An exception to this is DSA_TAG_PROTO_NONE (switches with no DSA tags),
and in that case it is actually expected to create e.g. VLAN interfaces
on the master. But for those, netdev_uses_dsa(master) returns false, so
the restriction doesn't apply.

The motivation for this change is to allow LAG interfaces of DSA masters
to be DSA masters themselves. We want to restrict the user's degrees of
freedom by 1: the LAG should already have all DSA masters as lowers, and
while lower ports of the LAG can be removed, none can be added after the
fact.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
---
v1->v2: none

 net/dsa/slave.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 09767f4b3b37..5b2e8f90ee2c 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -2699,6 +2699,35 @@ dsa_slave_prechangeupper_sanity_check(struct net_device *dev,
 	return NOTIFY_DONE;
 }
 
+static int
+dsa_master_prechangeupper_sanity_check(struct net_device *master,
+				       struct netdev_notifier_changeupper_info *info)
+{
+	struct netlink_ext_ack *extack;
+
+	if (!netdev_uses_dsa(master))
+		return NOTIFY_DONE;
+
+	if (!info->linking)
+		return NOTIFY_DONE;
+
+	/* Allow DSA switch uppers */
+	if (dsa_slave_dev_check(info->upper_dev))
+		return NOTIFY_DONE;
+
+	/* Allow bridge uppers of DSA masters, subject to further
+	 * restrictions in dsa_bridge_prechangelower_sanity_check()
+	 */
+	if (netif_is_bridge_master(info->upper_dev))
+		return NOTIFY_DONE;
+
+	extack = netdev_notifier_info_to_extack(&info->info);
+
+	NL_SET_ERR_MSG_MOD(extack,
+			   "DSA master cannot join unknown upper interfaces");
+	return notifier_from_errno(-EBUSY);
+}
+
 /* Don't allow bridging of DSA masters, since the bridge layer rx_handler
  * prevents the DSA fake ethertype handler to be invoked, so we don't get the
  * chance to strip off and parse the DSA switch tag protocol header (the bridge
@@ -2753,6 +2782,10 @@ static int dsa_slave_netdevice_event(struct notifier_block *nb,
 		if (notifier_to_errno(err))
 			return err;
 
+		err = dsa_master_prechangeupper_sanity_check(dev, info);
+		if (notifier_to_errno(err))
+			return err;
+
 		err = dsa_bridge_prechangelower_sanity_check(dev, info);
 		if (notifier_to_errno(err))
 			return err;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 net-next 5/9] net: dsa: only bring down user ports assigned to a given DSA master
  2022-08-18 13:52 [PATCH v2 net-next 0/9] DSA changes for multiple CPU ports (part 3) Vladimir Oltean
                   ` (3 preceding siblings ...)
  2022-08-18 13:52 ` [PATCH v2 net-next 4/9] net: dsa: existing DSA masters cannot join upper interfaces Vladimir Oltean
@ 2022-08-18 13:52 ` Vladimir Oltean
  2022-08-18 13:52 ` [PATCH v2 net-next 6/9] net: dsa: all DSA masters must be down when changing the tagging protocol Vladimir Oltean
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 18+ messages in thread
From: Vladimir Oltean @ 2022-08-18 13:52 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Florian Fainelli, Vivien Didelot, Andrew Lunn, Vladimir Oltean,
	Claudiu Manoil, Alexandre Belloni, UNGLinuxDriver, Colin Foster,
	Roopa Prabhu, Nikolay Aleksandrov

This is an adaptation of commit c0a8a9c27493 ("net: dsa: automatically
bring user ports down when master goes down") for multiple DSA masters.
When a DSA master goes down, only the user ports under its control
should go down too, the others can still send/receive traffic.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
---
v1->v2: none

 net/dsa/slave.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 5b2e8f90ee2c..c548b969b083 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -2873,6 +2873,9 @@ static int dsa_slave_netdevice_event(struct notifier_block *nb,
 			if (!dsa_port_is_user(dp))
 				continue;
 
+			if (dp->cpu_dp != cpu_dp)
+				continue;
+
 			list_add(&dp->slave->close_list, &close_list);
 		}
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 net-next 6/9] net: dsa: all DSA masters must be down when changing the tagging protocol
  2022-08-18 13:52 [PATCH v2 net-next 0/9] DSA changes for multiple CPU ports (part 3) Vladimir Oltean
                   ` (4 preceding siblings ...)
  2022-08-18 13:52 ` [PATCH v2 net-next 5/9] net: dsa: only bring down user ports assigned to a given DSA master Vladimir Oltean
@ 2022-08-18 13:52 ` Vladimir Oltean
  2022-08-18 13:52 ` [PATCH v2 net-next 7/9] net: dsa: use dsa_tree_for_each_cpu_port in dsa_tree_{setup,teardown}_master Vladimir Oltean
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 18+ messages in thread
From: Vladimir Oltean @ 2022-08-18 13:52 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Florian Fainelli, Vivien Didelot, Andrew Lunn, Vladimir Oltean,
	Claudiu Manoil, Alexandre Belloni, UNGLinuxDriver, Colin Foster,
	Roopa Prabhu, Nikolay Aleksandrov

The fact that the tagging protocol is set and queried from the
/sys/class/net/<dsa-master>/dsa/tagging file is a bit of a quirk from
the single CPU port days which isn't aging very well now that DSA can
have more than a single CPU port. This is because the tagging protocol
is a switch property, yet in the presence of multiple CPU ports it can
be queried and set from multiple sysfs files, all of which are handled
by the same implementation.

The current logic ensures that the net device whose sysfs file we're
changing the tagging protocol through must be down. That net device is
the DSA master, and this is fine for single DSA master / CPU port setups.

But exactly because the tagging protocol is per switch [ tree, in fact ]
and not per DSA master, this isn't fine any longer with multiple CPU
ports, and we must iterate through the tree and find all DSA masters,
and make sure that all of them are down.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
---
v1->v2: none

 net/dsa/dsa2.c     | 10 +++-------
 net/dsa/dsa_priv.h |  1 -
 net/dsa/master.c   |  2 +-
 3 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index cac48a741f27..b2fe62bfe8dd 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -1238,7 +1238,6 @@ static int dsa_tree_bind_tag_proto(struct dsa_switch_tree *dst,
  * they would have formed disjoint trees (different "dsa,member" values).
  */
 int dsa_tree_change_tag_proto(struct dsa_switch_tree *dst,
-			      struct net_device *master,
 			      const struct dsa_device_ops *tag_ops,
 			      const struct dsa_device_ops *old_tag_ops)
 {
@@ -1254,14 +1253,11 @@ int dsa_tree_change_tag_proto(struct dsa_switch_tree *dst,
 	 * attempts to change the tagging protocol. If we ever lift the IFF_UP
 	 * restriction, there needs to be another mutex which serializes this.
 	 */
-	if (master->flags & IFF_UP)
-		goto out_unlock;
-
 	list_for_each_entry(dp, &dst->ports, list) {
-		if (!dsa_port_is_user(dp))
-			continue;
+		if (dsa_port_is_cpu(dp) && (dp->master->flags & IFF_UP))
+			goto out_unlock;
 
-		if (dp->slave->flags & IFF_UP)
+		if (dsa_port_is_user(dp) && (dp->slave->flags & IFF_UP))
 			goto out_unlock;
 	}
 
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index d9722e49864b..cc1cc866dc42 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -545,7 +545,6 @@ struct dsa_lag *dsa_tree_lag_find(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,
-			      struct net_device *master,
 			      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,
diff --git a/net/dsa/master.c b/net/dsa/master.c
index 2851e44c4cf0..32c0a00a8b92 100644
--- a/net/dsa/master.c
+++ b/net/dsa/master.c
@@ -307,7 +307,7 @@ static ssize_t tagging_store(struct device *d, struct device_attribute *attr,
 		 */
 		goto out;
 
-	err = dsa_tree_change_tag_proto(cpu_dp->ds->dst, dev, new_tag_ops,
+	err = dsa_tree_change_tag_proto(cpu_dp->ds->dst, new_tag_ops,
 					old_tag_ops);
 	if (err) {
 		/* On failure the old tagger is restored, so we don't need the
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 net-next 7/9] net: dsa: use dsa_tree_for_each_cpu_port in dsa_tree_{setup,teardown}_master
  2022-08-18 13:52 [PATCH v2 net-next 0/9] DSA changes for multiple CPU ports (part 3) Vladimir Oltean
                   ` (5 preceding siblings ...)
  2022-08-18 13:52 ` [PATCH v2 net-next 6/9] net: dsa: all DSA masters must be down when changing the tagging protocol Vladimir Oltean
@ 2022-08-18 13:52 ` Vladimir Oltean
  2022-08-18 13:52 ` [PATCH v2 net-next 8/9] net: mscc: ocelot: set up tag_8021q CPU ports independent of user port affinity Vladimir Oltean
  2022-08-18 13:52 ` [PATCH v2 net-next 9/9] net: mscc: ocelot: adjust forwarding domain for CPU ports in a LAG Vladimir Oltean
  8 siblings, 0 replies; 18+ messages in thread
From: Vladimir Oltean @ 2022-08-18 13:52 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Florian Fainelli, Vivien Didelot, Andrew Lunn, Vladimir Oltean,
	Claudiu Manoil, Alexandre Belloni, UNGLinuxDriver, Colin Foster,
	Roopa Prabhu, Nikolay Aleksandrov

More logic will be added to dsa_tree_setup_master() and
dsa_tree_teardown_master() in upcoming changes.

Reduce the indentation by one level in these functions by introducing
and using a dedicated iterator for CPU ports of a tree.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
---
v1->v2: none

 include/net/dsa.h |  4 ++++
 net/dsa/dsa2.c    | 46 +++++++++++++++++++++-------------------------
 2 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/include/net/dsa.h b/include/net/dsa.h
index b902b31bebce..f2ce12860546 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -559,6 +559,10 @@ static inline bool dsa_is_user_port(struct dsa_switch *ds, int p)
 	list_for_each_entry((_dp), &(_dst)->ports, list) \
 		if (dsa_port_is_user((_dp)))
 
+#define dsa_tree_for_each_cpu_port(_dp, _dst) \
+	list_for_each_entry((_dp), &(_dst)->ports, list) \
+		if (dsa_port_is_cpu((_dp)))
+
 #define dsa_switch_for_each_port(_dp, _ds) \
 	list_for_each_entry((_dp), &(_ds)->dst->ports, list) \
 		if ((_dp)->ds == (_ds))
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index b2fe62bfe8dd..6c46c3b414e2 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -1046,26 +1046,24 @@ static int dsa_tree_setup_switches(struct dsa_switch_tree *dst)
 
 static int dsa_tree_setup_master(struct dsa_switch_tree *dst)
 {
-	struct dsa_port *dp;
+	struct dsa_port *cpu_dp;
 	int err = 0;
 
 	rtnl_lock();
 
-	list_for_each_entry(dp, &dst->ports, list) {
-		if (dsa_port_is_cpu(dp)) {
-			struct net_device *master = dp->master;
-			bool admin_up = (master->flags & IFF_UP) &&
-					!qdisc_tx_is_noop(master);
+	dsa_tree_for_each_cpu_port(cpu_dp, dst) {
+		struct net_device *master = cpu_dp->master;
+		bool admin_up = (master->flags & IFF_UP) &&
+				!qdisc_tx_is_noop(master);
 
-			err = dsa_master_setup(master, dp);
-			if (err)
-				break;
+		err = dsa_master_setup(master, cpu_dp);
+		if (err)
+			break;
 
-			/* Replay master state event */
-			dsa_tree_master_admin_state_change(dst, master, admin_up);
-			dsa_tree_master_oper_state_change(dst, master,
-							  netif_oper_up(master));
-		}
+		/* Replay master state event */
+		dsa_tree_master_admin_state_change(dst, master, admin_up);
+		dsa_tree_master_oper_state_change(dst, master,
+						  netif_oper_up(master));
 	}
 
 	rtnl_unlock();
@@ -1075,22 +1073,20 @@ static int dsa_tree_setup_master(struct dsa_switch_tree *dst)
 
 static void dsa_tree_teardown_master(struct dsa_switch_tree *dst)
 {
-	struct dsa_port *dp;
+	struct dsa_port *cpu_dp;
 
 	rtnl_lock();
 
-	list_for_each_entry(dp, &dst->ports, list) {
-		if (dsa_port_is_cpu(dp)) {
-			struct net_device *master = dp->master;
+	dsa_tree_for_each_cpu_port(cpu_dp, dst) {
+		struct net_device *master = cpu_dp->master;
 
-			/* Synthesizing an "admin down" state is sufficient for
-			 * the switches to get a notification if the master is
-			 * currently up and running.
-			 */
-			dsa_tree_master_admin_state_change(dst, master, false);
+		/* Synthesizing an "admin down" state is sufficient for
+		 * the switches to get a notification if the master is
+		 * currently up and running.
+		 */
+		dsa_tree_master_admin_state_change(dst, master, false);
 
-			dsa_master_teardown(master);
-		}
+		dsa_master_teardown(master);
 	}
 
 	rtnl_unlock();
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 net-next 8/9] net: mscc: ocelot: set up tag_8021q CPU ports independent of user port affinity
  2022-08-18 13:52 [PATCH v2 net-next 0/9] DSA changes for multiple CPU ports (part 3) Vladimir Oltean
                   ` (6 preceding siblings ...)
  2022-08-18 13:52 ` [PATCH v2 net-next 7/9] net: dsa: use dsa_tree_for_each_cpu_port in dsa_tree_{setup,teardown}_master Vladimir Oltean
@ 2022-08-18 13:52 ` Vladimir Oltean
  2022-08-19  3:58   ` Jakub Kicinski
  2022-08-18 13:52 ` [PATCH v2 net-next 9/9] net: mscc: ocelot: adjust forwarding domain for CPU ports in a LAG Vladimir Oltean
  8 siblings, 1 reply; 18+ messages in thread
From: Vladimir Oltean @ 2022-08-18 13:52 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Florian Fainelli, Vivien Didelot, Andrew Lunn, Vladimir Oltean,
	Claudiu Manoil, Alexandre Belloni, UNGLinuxDriver, Colin Foster,
	Roopa Prabhu, Nikolay Aleksandrov

This is a partial revert of commit c295f9831f1d ("net: mscc: ocelot:
switch from {,un}set to {,un}assign for tag_8021q CPU ports"), because
as it turns out, this isn't how tag_8021q CPU ports under a LAG are
supposed to work.

Under that scenario, all user ports are "assigned" to the single
tag_8021q CPU port represented by the logical port corresponding to the
bonding interface. So one CPU port in a LAG would have is_dsa_8021q_cpu
set to true (the one whose physical port ID is equal to the logical port
ID), and the other one to false.

In turn, this makes 2 undesirable things happen:

(1) PGID_CPU contains only the first physical CPU port, rather than both
(2) only the first CPU port will be added to the private VLANs used by
    ocelot for VLAN-unaware bridging

To make the driver behave in the same way for both bonded CPU ports, we
need to bring back the old concept of setting up a port as a tag_8021q
CPU port, and this is what deals with VLAN membership and PGID_CPU
updating. But we also need the CPU port "assignment" (the user to CPU
port affinity), and this is what updates the PGID_SRC forwarding rules.

All DSA CPU ports are statically configured for tag_8021q mode when the
tagging protocol is changed to ocelot-8021q. User ports are "assigned"
to one CPU port or the other dynamically (this will be handled by a
future change).

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
v1->v2: patch is new

 drivers/net/dsa/ocelot/felix.c     |  6 +++
 drivers/net/ethernet/mscc/ocelot.c | 63 +++++++++++++++---------------
 include/soc/mscc/ocelot.h          |  2 +
 3 files changed, 39 insertions(+), 32 deletions(-)

diff --git a/drivers/net/dsa/ocelot/felix.c b/drivers/net/dsa/ocelot/felix.c
index aadb0bd7c24f..ee19ed96f284 100644
--- a/drivers/net/dsa/ocelot/felix.c
+++ b/drivers/net/dsa/ocelot/felix.c
@@ -445,6 +445,9 @@ static int felix_tag_8021q_setup(struct dsa_switch *ds)
 	if (err)
 		return err;
 
+	dsa_switch_for_each_cpu_port(dp, ds)
+		ocelot_port_setup_dsa_8021q_cpu(ocelot, dp->index);
+
 	dsa_switch_for_each_user_port(dp, ds)
 		ocelot_port_assign_dsa_8021q_cpu(ocelot, dp->index,
 						 dp->cpu_dp->index);
@@ -493,6 +496,9 @@ static void felix_tag_8021q_teardown(struct dsa_switch *ds)
 	dsa_switch_for_each_user_port(dp, ds)
 		ocelot_port_unassign_dsa_8021q_cpu(ocelot, dp->index);
 
+	dsa_switch_for_each_cpu_port(dp, ds)
+		ocelot_port_teardown_dsa_8021q_cpu(ocelot, dp->index);
+
 	dsa_tag_8021q_unregister(ds);
 }
 
diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c
index d4649e4ee0e7..7d350c944521 100644
--- a/drivers/net/ethernet/mscc/ocelot.c
+++ b/drivers/net/ethernet/mscc/ocelot.c
@@ -2196,61 +2196,60 @@ static void ocelot_update_pgid_cpu(struct ocelot *ocelot)
 	ocelot_write_rix(ocelot, pgid_cpu, ANA_PGID_PGID, PGID_CPU);
 }
 
-void ocelot_port_assign_dsa_8021q_cpu(struct ocelot *ocelot, int port,
-				      int cpu)
+void ocelot_port_setup_dsa_8021q_cpu(struct ocelot *ocelot, int cpu)
 {
 	struct ocelot_port *cpu_port = ocelot->ports[cpu];
 	u16 vid;
 
 	mutex_lock(&ocelot->fwd_domain_lock);
 
-	ocelot->ports[port]->dsa_8021q_cpu = cpu_port;
+	cpu_port->is_dsa_8021q_cpu = true;
 
-	if (!cpu_port->is_dsa_8021q_cpu) {
-		cpu_port->is_dsa_8021q_cpu = true;
+	for (vid = OCELOT_RSV_VLAN_RANGE_START; vid < VLAN_N_VID; vid++)
+		ocelot_vlan_member_add(ocelot, cpu, vid, true);
 
-		for (vid = OCELOT_RSV_VLAN_RANGE_START; vid < VLAN_N_VID; vid++)
-			ocelot_vlan_member_add(ocelot, cpu, vid, true);
-
-		ocelot_update_pgid_cpu(ocelot);
-	}
-
-	ocelot_apply_bridge_fwd_mask(ocelot, true);
+	ocelot_update_pgid_cpu(ocelot);
 
 	mutex_unlock(&ocelot->fwd_domain_lock);
 }
-EXPORT_SYMBOL_GPL(ocelot_port_assign_dsa_8021q_cpu);
+EXPORT_SYMBOL_GPL(ocelot_port_setup_dsa_8021q_cpu);
 
-void ocelot_port_unassign_dsa_8021q_cpu(struct ocelot *ocelot, int port)
+void ocelot_port_teardown_dsa_8021q_cpu(struct ocelot *ocelot, int cpu)
 {
-	struct ocelot_port *cpu_port = ocelot->ports[port]->dsa_8021q_cpu;
-	bool keep = false;
+	struct ocelot_port *cpu_port = ocelot->ports[cpu];
 	u16 vid;
-	int p;
 
 	mutex_lock(&ocelot->fwd_domain_lock);
 
-	ocelot->ports[port]->dsa_8021q_cpu = NULL;
+	cpu_port->is_dsa_8021q_cpu = false;
 
-	for (p = 0; p < ocelot->num_phys_ports; p++) {
-		if (!ocelot->ports[p])
-			continue;
+	for (vid = OCELOT_RSV_VLAN_RANGE_START; vid < VLAN_N_VID; vid++)
+		ocelot_vlan_member_del(ocelot, cpu_port->index, vid);
 
-		if (ocelot->ports[p]->dsa_8021q_cpu == cpu_port) {
-			keep = true;
-			break;
-		}
-	}
+	ocelot_update_pgid_cpu(ocelot);
 
-	if (!keep) {
-		cpu_port->is_dsa_8021q_cpu = false;
+	mutex_unlock(&ocelot->fwd_domain_lock);
+}
 
-		for (vid = OCELOT_RSV_VLAN_RANGE_START; vid < VLAN_N_VID; vid++)
-			ocelot_vlan_member_del(ocelot, cpu_port->index, vid);
+void ocelot_port_assign_dsa_8021q_cpu(struct ocelot *ocelot, int port,
+				      int cpu)
+{
+	struct ocelot_port *cpu_port = ocelot->ports[cpu];
 
-		ocelot_update_pgid_cpu(ocelot);
-	}
+	mutex_lock(&ocelot->fwd_domain_lock);
 
+	ocelot->ports[port]->dsa_8021q_cpu = cpu_port;
+	ocelot_apply_bridge_fwd_mask(ocelot, true);
+
+	mutex_unlock(&ocelot->fwd_domain_lock);
+}
+EXPORT_SYMBOL_GPL(ocelot_port_assign_dsa_8021q_cpu);
+
+void ocelot_port_unassign_dsa_8021q_cpu(struct ocelot *ocelot, int port)
+{
+	mutex_lock(&ocelot->fwd_domain_lock);
+
+	ocelot->ports[port]->dsa_8021q_cpu = NULL;
 	ocelot_apply_bridge_fwd_mask(ocelot, true);
 
 	mutex_unlock(&ocelot->fwd_domain_lock);
diff --git a/include/soc/mscc/ocelot.h b/include/soc/mscc/ocelot.h
index ac151ecc7f19..4c8818576437 100644
--- a/include/soc/mscc/ocelot.h
+++ b/include/soc/mscc/ocelot.h
@@ -875,6 +875,8 @@ void ocelot_deinit(struct ocelot *ocelot);
 void ocelot_init_port(struct ocelot *ocelot, int port);
 void ocelot_deinit_port(struct ocelot *ocelot, int port);
 
+void ocelot_port_setup_dsa_8021q_cpu(struct ocelot *ocelot, int cpu);
+void ocelot_port_teardown_dsa_8021q_cpu(struct ocelot *ocelot, int cpu);
 void ocelot_port_assign_dsa_8021q_cpu(struct ocelot *ocelot, int port, int cpu);
 void ocelot_port_unassign_dsa_8021q_cpu(struct ocelot *ocelot, int port);
 u32 ocelot_port_assigned_dsa_8021q_cpu_mask(struct ocelot *ocelot, int port);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v2 net-next 9/9] net: mscc: ocelot: adjust forwarding domain for CPU ports in a LAG
  2022-08-18 13:52 [PATCH v2 net-next 0/9] DSA changes for multiple CPU ports (part 3) Vladimir Oltean
                   ` (7 preceding siblings ...)
  2022-08-18 13:52 ` [PATCH v2 net-next 8/9] net: mscc: ocelot: set up tag_8021q CPU ports independent of user port affinity Vladimir Oltean
@ 2022-08-18 13:52 ` Vladimir Oltean
  8 siblings, 0 replies; 18+ messages in thread
From: Vladimir Oltean @ 2022-08-18 13:52 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Florian Fainelli, Vivien Didelot, Andrew Lunn, Vladimir Oltean,
	Claudiu Manoil, Alexandre Belloni, UNGLinuxDriver, Colin Foster,
	Roopa Prabhu, Nikolay Aleksandrov

Currently when we have 2 CPU ports configured for DSA tag_8021q mode and
we put them in a LAG, a PGID dump looks like this:

PGID_SRC[0] = ports 4,
PGID_SRC[1] = ports 4,
PGID_SRC[2] = ports 4,
PGID_SRC[3] = ports 4,
PGID_SRC[4] = ports 0, 1, 2, 3, 4, 5,
PGID_SRC[5] = no ports

(ports 0-3 are user ports, ports 4 and 5 are CPU ports)

There are 2 problems with the configuration above:

- user ports should enable forwarding towards both CPU ports, not just 4,
  and the aggregation PGIDs should prune one CPU port or the other from
  the destination port mask, based on a hash computed from packet headers.

- CPU ports should not be allowed to forward towards themselves and also
  not towards other ports in the same LAG as themselves

The first problem requires fixing up the PGID_SRC of user ports, when
ocelot_port_assigned_dsa_8021q_cpu_mask() is called. We need to say that
when a user port is assigned to a tag_8021q CPU port and that port is in
a LAG, it should forward towards all ports in that LAG.

The second problem requires fixing up the PGID_SRC of port 4, to remove
ports 4 and 5 (in a LAG) from the allowed destinations.

After this change, the PGID source masks look as follows:

PGID_SRC[0] = ports 4, 5,
PGID_SRC[1] = ports 4, 5,
PGID_SRC[2] = ports 4, 5,
PGID_SRC[3] = ports 4, 5,
PGID_SRC[4] = ports 0, 1, 2, 3,
PGID_SRC[5] = no ports

Note that PGID_SRC[5] still looks weird (it should say "0, 1, 2, 3" just
like PGID_SRC[4] does), but I've tested forwarding through this CPU port
and it doesn't seem like anything is affected (it appears that PGID_SRC[4]
is being looked up on forwarding from the CPU, since both ports 4 and 5
have logical port ID 4). The reason why it looks weird is because
we've never called ocelot_port_assign_dsa_8021q_cpu() for any user port
towards port 5 (all user ports are assigned to port 4 which is in a LAG
with 5).

Since things aren't broken, I'm willing to leave it like that for now
and just document the oddity.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
v1->v2: patch is new

 drivers/net/ethernet/mscc/ocelot.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c
index 7d350c944521..af46ea385c31 100644
--- a/drivers/net/ethernet/mscc/ocelot.c
+++ b/drivers/net/ethernet/mscc/ocelot.c
@@ -2046,6 +2046,16 @@ static int ocelot_bond_get_id(struct ocelot *ocelot, struct net_device *bond)
 	return __ffs(bond_mask);
 }
 
+/* Returns the mask of user ports assigned to this DSA tag_8021q CPU port.
+ * Note that when CPU ports are in a LAG, the user ports are assigned to the
+ * 'primary' CPU port, the one whose physical port number gives the logical
+ * port number of the LAG.
+ *
+ * We leave PGID_SRC poorly configured for the 'secondary' CPU port in the LAG
+ * (to which no user port is assigned), but it appears that forwarding from
+ * this secondary CPU port looks at the PGID_SRC associated with the logical
+ * port ID that it's assigned to, which *is* configured properly.
+ */
 static u32 ocelot_dsa_8021q_cpu_assigned_ports(struct ocelot *ocelot,
 					       struct ocelot_port *cpu)
 {
@@ -2062,9 +2072,15 @@ static u32 ocelot_dsa_8021q_cpu_assigned_ports(struct ocelot *ocelot,
 			mask |= BIT(port);
 	}
 
+	if (cpu->bond)
+		mask &= ~ocelot_get_bond_mask(ocelot, cpu->bond);
+
 	return mask;
 }
 
+/* Returns the DSA tag_8021q CPU port that the given port is assigned to,
+ * or the bit mask of CPU ports if said CPU port is in a LAG.
+ */
 u32 ocelot_port_assigned_dsa_8021q_cpu_mask(struct ocelot *ocelot, int port)
 {
 	struct ocelot_port *ocelot_port = ocelot->ports[port];
@@ -2073,6 +2089,9 @@ u32 ocelot_port_assigned_dsa_8021q_cpu_mask(struct ocelot *ocelot, int port)
 	if (!cpu_port)
 		return 0;
 
+	if (cpu_port->bond)
+		return ocelot_get_bond_mask(ocelot, cpu_port->bond);
+
 	return BIT(cpu_port->index);
 }
 EXPORT_SYMBOL_GPL(ocelot_port_assigned_dsa_8021q_cpu_mask);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 net-next 8/9] net: mscc: ocelot: set up tag_8021q CPU ports independent of user port affinity
  2022-08-18 13:52 ` [PATCH v2 net-next 8/9] net: mscc: ocelot: set up tag_8021q CPU ports independent of user port affinity Vladimir Oltean
@ 2022-08-19  3:58   ` Jakub Kicinski
  2022-08-19 11:06     ` Vladimir Oltean
  0 siblings, 1 reply; 18+ messages in thread
From: Jakub Kicinski @ 2022-08-19  3:58 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: netdev, David S. Miller, Eric Dumazet, Paolo Abeni,
	Florian Fainelli, Vivien Didelot, Andrew Lunn, Vladimir Oltean,
	Claudiu Manoil, Alexandre Belloni, UNGLinuxDriver, Colin Foster,
	Roopa Prabhu, Nikolay Aleksandrov

On Thu, 18 Aug 2022 16:52:55 +0300 Vladimir Oltean wrote:
> This is a partial revert of commit c295f9831f1d ("net: mscc: ocelot:
> switch from {,un}set to {,un}assign for tag_8021q CPU ports"), because
> as it turns out, this isn't how tag_8021q CPU ports under a LAG are
> supposed to work.
> 
> Under that scenario, all user ports are "assigned" to the single
> tag_8021q CPU port represented by the logical port corresponding to the
> bonding interface. So one CPU port in a LAG would have is_dsa_8021q_cpu
> set to true (the one whose physical port ID is equal to the logical port
> ID), and the other one to false.
> 
> In turn, this makes 2 undesirable things happen:
> 
> (1) PGID_CPU contains only the first physical CPU port, rather than both
> (2) only the first CPU port will be added to the private VLANs used by
>     ocelot for VLAN-unaware bridging
> 
> To make the driver behave in the same way for both bonded CPU ports, we
> need to bring back the old concept of setting up a port as a tag_8021q
> CPU port, and this is what deals with VLAN membership and PGID_CPU
> updating. But we also need the CPU port "assignment" (the user to CPU
> port affinity), and this is what updates the PGID_SRC forwarding rules.
> 
> All DSA CPU ports are statically configured for tag_8021q mode when the
> tagging protocol is changed to ocelot-8021q. User ports are "assigned"
> to one CPU port or the other dynamically (this will be handled by a
> future change).

ERROR: modpost: "ocelot_port_teardown_dsa_8021q_cpu" [drivers/net/dsa/ocelot/mscc_felix.ko] undefined!
ERROR: modpost: "ocelot_port_teardown_dsa_8021q_cpu" [drivers/net/dsa/ocelot/mscc_seville.ko] undefined!

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 net-next 8/9] net: mscc: ocelot: set up tag_8021q CPU ports independent of user port affinity
  2022-08-19  3:58   ` Jakub Kicinski
@ 2022-08-19 11:06     ` Vladimir Oltean
  2022-08-19 13:37       ` Colin Foster
  0 siblings, 1 reply; 18+ messages in thread
From: Vladimir Oltean @ 2022-08-19 11:06 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: netdev@vger.kernel.org, David S. Miller, Eric Dumazet,
	Paolo Abeni, Florian Fainelli, Vivien Didelot, Andrew Lunn,
	Vladimir Oltean, Claudiu Manoil, Alexandre Belloni,
	UNGLinuxDriver@microchip.com, Colin Foster, Roopa Prabhu,
	Nikolay Aleksandrov

On Thu, Aug 18, 2022 at 08:58:56PM -0700, Jakub Kicinski wrote:
> ERROR: modpost: "ocelot_port_teardown_dsa_8021q_cpu" [drivers/net/dsa/ocelot/mscc_felix.ko] undefined!
> ERROR: modpost: "ocelot_port_teardown_dsa_8021q_cpu" [drivers/net/dsa/ocelot/mscc_seville.ko] undefined!

Damn, I forgot EXPORT_SYMBOL_GPL()....
Since I see you've marked the patches as changes requested already, I'll
go ahead and resubmit.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 net-next 8/9] net: mscc: ocelot: set up tag_8021q CPU ports independent of user port affinity
  2022-08-19 11:06     ` Vladimir Oltean
@ 2022-08-19 13:37       ` Colin Foster
  2022-08-19 13:39         ` Vladimir Oltean
  0 siblings, 1 reply; 18+ messages in thread
From: Colin Foster @ 2022-08-19 13:37 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: Jakub Kicinski, netdev@vger.kernel.org, David S. Miller,
	Eric Dumazet, Paolo Abeni, Florian Fainelli, Vivien Didelot,
	Andrew Lunn, Vladimir Oltean, Claudiu Manoil, Alexandre Belloni,
	UNGLinuxDriver@microchip.com, Roopa Prabhu, Nikolay Aleksandrov

On Fri, Aug 19, 2022 at 11:06:23AM +0000, Vladimir Oltean wrote:
> On Thu, Aug 18, 2022 at 08:58:56PM -0700, Jakub Kicinski wrote:
> > ERROR: modpost: "ocelot_port_teardown_dsa_8021q_cpu" [drivers/net/dsa/ocelot/mscc_felix.ko] undefined!
> > ERROR: modpost: "ocelot_port_teardown_dsa_8021q_cpu" [drivers/net/dsa/ocelot/mscc_seville.ko] undefined!
> 
> Damn, I forgot EXPORT_SYMBOL_GPL()....
> Since I see you've marked the patches as changes requested already, I'll
> go ahead and resubmit.

Any reason not to use the _NS() variants?

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 net-next 8/9] net: mscc: ocelot: set up tag_8021q CPU ports independent of user port affinity
  2022-08-19 13:37       ` Colin Foster
@ 2022-08-19 13:39         ` Vladimir Oltean
  2022-08-19 13:45           ` Colin Foster
  0 siblings, 1 reply; 18+ messages in thread
From: Vladimir Oltean @ 2022-08-19 13:39 UTC (permalink / raw)
  To: Colin Foster
  Cc: Jakub Kicinski, netdev@vger.kernel.org, David S. Miller,
	Eric Dumazet, Paolo Abeni, Florian Fainelli, Vivien Didelot,
	Andrew Lunn, Vladimir Oltean, Claudiu Manoil, Alexandre Belloni,
	UNGLinuxDriver@microchip.com, Roopa Prabhu, Nikolay Aleksandrov

On Fri, Aug 19, 2022 at 06:37:56AM -0700, Colin Foster wrote:
> On Fri, Aug 19, 2022 at 11:06:23AM +0000, Vladimir Oltean wrote:
> > On Thu, Aug 18, 2022 at 08:58:56PM -0700, Jakub Kicinski wrote:
> > > ERROR: modpost: "ocelot_port_teardown_dsa_8021q_cpu" [drivers/net/dsa/ocelot/mscc_felix.ko] undefined!
> > > ERROR: modpost: "ocelot_port_teardown_dsa_8021q_cpu" [drivers/net/dsa/ocelot/mscc_seville.ko] undefined!
> > 
> > Damn, I forgot EXPORT_SYMBOL_GPL()....
> > Since I see you've marked the patches as changes requested already, I'll
> > go ahead and resubmit.
> 
> Any reason not to use the _NS() variants?

What's _NS() and why would I use it?

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 net-next 8/9] net: mscc: ocelot: set up tag_8021q CPU ports independent of user port affinity
  2022-08-19 13:39         ` Vladimir Oltean
@ 2022-08-19 13:45           ` Colin Foster
  2022-08-19 13:48             ` Vladimir Oltean
  0 siblings, 1 reply; 18+ messages in thread
From: Colin Foster @ 2022-08-19 13:45 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: Jakub Kicinski, netdev@vger.kernel.org, David S. Miller,
	Eric Dumazet, Paolo Abeni, Florian Fainelli, Vivien Didelot,
	Andrew Lunn, Vladimir Oltean, Claudiu Manoil, Alexandre Belloni,
	UNGLinuxDriver@microchip.com, Roopa Prabhu, Nikolay Aleksandrov

On Fri, Aug 19, 2022 at 01:39:00PM +0000, Vladimir Oltean wrote:
> On Fri, Aug 19, 2022 at 06:37:56AM -0700, Colin Foster wrote:
> > On Fri, Aug 19, 2022 at 11:06:23AM +0000, Vladimir Oltean wrote:
> > > On Thu, Aug 18, 2022 at 08:58:56PM -0700, Jakub Kicinski wrote:
> > > > ERROR: modpost: "ocelot_port_teardown_dsa_8021q_cpu" [drivers/net/dsa/ocelot/mscc_felix.ko] undefined!
> > > > ERROR: modpost: "ocelot_port_teardown_dsa_8021q_cpu" [drivers/net/dsa/ocelot/mscc_seville.ko] undefined!
> > > 
> > > Damn, I forgot EXPORT_SYMBOL_GPL()....
> > > Since I see you've marked the patches as changes requested already, I'll
> > > go ahead and resubmit.
> > 
> > Any reason not to use the _NS() variants?
> 
> What's _NS() and why would I use it?

include/linux/export.h.

I don't know when to use one over the other. I just know it was
requested in my MFD set for drivers/mfd/ocelot*. Partitioning of the
symtab, from what I best understand.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 net-next 8/9] net: mscc: ocelot: set up tag_8021q CPU ports independent of user port affinity
  2022-08-19 13:45           ` Colin Foster
@ 2022-08-19 13:48             ` Vladimir Oltean
  2022-08-19 13:57               ` Colin Foster
  0 siblings, 1 reply; 18+ messages in thread
From: Vladimir Oltean @ 2022-08-19 13:48 UTC (permalink / raw)
  To: Colin Foster
  Cc: Jakub Kicinski, netdev@vger.kernel.org, David S. Miller,
	Eric Dumazet, Paolo Abeni, Florian Fainelli, Vivien Didelot,
	Andrew Lunn, Vladimir Oltean, Claudiu Manoil, Alexandre Belloni,
	UNGLinuxDriver@microchip.com, Roopa Prabhu, Nikolay Aleksandrov

On Fri, Aug 19, 2022 at 06:45:48AM -0700, Colin Foster wrote:
> On Fri, Aug 19, 2022 at 01:39:00PM +0000, Vladimir Oltean wrote:
> > On Fri, Aug 19, 2022 at 06:37:56AM -0700, Colin Foster wrote:
> > > On Fri, Aug 19, 2022 at 11:06:23AM +0000, Vladimir Oltean wrote:
> > > > On Thu, Aug 18, 2022 at 08:58:56PM -0700, Jakub Kicinski wrote:
> > > > > ERROR: modpost: "ocelot_port_teardown_dsa_8021q_cpu" [drivers/net/dsa/ocelot/mscc_felix.ko] undefined!
> > > > > ERROR: modpost: "ocelot_port_teardown_dsa_8021q_cpu" [drivers/net/dsa/ocelot/mscc_seville.ko] undefined!
> > > > 
> > > > Damn, I forgot EXPORT_SYMBOL_GPL()....
> > > > Since I see you've marked the patches as changes requested already, I'll
> > > > go ahead and resubmit.
> > > 
> > > Any reason not to use the _NS() variants?
> > 
> > What's _NS() and why would I use it?
> 
> include/linux/export.h.
> 
> I don't know when to use one over the other. I just know it was
> requested in my MFD set for drivers/mfd/ocelot*. Partitioning of the
> symtab, from what I best understand.

Odd. No reason given? I would understand symbol namespacing when there
is a risk of name collision, but I fail to see such a thing when talking
about ocelot_port_teardown_dsa_8021q_cpu().

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 net-next 8/9] net: mscc: ocelot: set up tag_8021q CPU ports independent of user port affinity
  2022-08-19 13:48             ` Vladimir Oltean
@ 2022-08-19 13:57               ` Colin Foster
  2022-08-19 16:44                 ` Vladimir Oltean
  0 siblings, 1 reply; 18+ messages in thread
From: Colin Foster @ 2022-08-19 13:57 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: Jakub Kicinski, netdev@vger.kernel.org, David S. Miller,
	Eric Dumazet, Paolo Abeni, Florian Fainelli, Vivien Didelot,
	Andrew Lunn, Vladimir Oltean, Claudiu Manoil, Alexandre Belloni,
	UNGLinuxDriver@microchip.com, Roopa Prabhu, Nikolay Aleksandrov

On Fri, Aug 19, 2022 at 01:48:00PM +0000, Vladimir Oltean wrote:
> On Fri, Aug 19, 2022 at 06:45:48AM -0700, Colin Foster wrote:
> > On Fri, Aug 19, 2022 at 01:39:00PM +0000, Vladimir Oltean wrote:
> > > On Fri, Aug 19, 2022 at 06:37:56AM -0700, Colin Foster wrote:
> > > > On Fri, Aug 19, 2022 at 11:06:23AM +0000, Vladimir Oltean wrote:
> > > > > On Thu, Aug 18, 2022 at 08:58:56PM -0700, Jakub Kicinski wrote:
> > > > > > ERROR: modpost: "ocelot_port_teardown_dsa_8021q_cpu" [drivers/net/dsa/ocelot/mscc_felix.ko] undefined!
> > > > > > ERROR: modpost: "ocelot_port_teardown_dsa_8021q_cpu" [drivers/net/dsa/ocelot/mscc_seville.ko] undefined!
> > > > > 
> > > > > Damn, I forgot EXPORT_SYMBOL_GPL()....
> > > > > Since I see you've marked the patches as changes requested already, I'll
> > > > > go ahead and resubmit.
> > > > 
> > > > Any reason not to use the _NS() variants?
> > > 
> > > What's _NS() and why would I use it?
> > 
> > include/linux/export.h.
> > 
> > I don't know when to use one over the other. I just know it was
> > requested in my MFD set for drivers/mfd/ocelot*. Partitioning of the
> > symtab, from what I best understand.
> 
> Odd. No reason given? I would understand symbol namespacing when there
> is a risk of name collision, but I fail to see such a thing when talking
> about ocelot_port_teardown_dsa_8021q_cpu().

https://patchwork.kernel.org/project/netdevbpf/patch/20220508185313.2222956-9-colin.foster@in-advantage.com/#24849610

From there:

> +EXPORT_SYMBOL(ocelot_chip_reset);

Please, switch to the namespace (_NS) variant of the exported-imported
symbols for these drivers.


I'm not sure the full motivation. But I agree, I can't imagine anyone
else randomly naming and exporting another function of that name.

Just thought I'd ask.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v2 net-next 8/9] net: mscc: ocelot: set up tag_8021q CPU ports independent of user port affinity
  2022-08-19 13:57               ` Colin Foster
@ 2022-08-19 16:44                 ` Vladimir Oltean
  0 siblings, 0 replies; 18+ messages in thread
From: Vladimir Oltean @ 2022-08-19 16:44 UTC (permalink / raw)
  To: Colin Foster
  Cc: Jakub Kicinski, netdev@vger.kernel.org, David S. Miller,
	Eric Dumazet, Paolo Abeni, Florian Fainelli, Vivien Didelot,
	Andrew Lunn, Vladimir Oltean, Claudiu Manoil, Alexandre Belloni,
	UNGLinuxDriver@microchip.com, Roopa Prabhu, Nikolay Aleksandrov

On Fri, Aug 19, 2022 at 06:57:48AM -0700, Colin Foster wrote:
> https://patchwork.kernel.org/project/netdevbpf/patch/20220508185313.2222956-9-colin.foster@in-advantage.com/#24849610
> 
> From there:
> 
> > +EXPORT_SYMBOL(ocelot_chip_reset);
> 
> Please, switch to the namespace (_NS) variant of the exported-imported
> symbols for these drivers.
> 
> 
> I'm not sure the full motivation. But I agree, I can't imagine anyone
> else randomly naming and exporting another function of that name.
> 
> Just thought I'd ask.

Ok, I'm not going to namespace a new symbol when 62 others from ocelot.c
alone aren't. I'll ask Andy what was the intention if I manage to find
that email in my inbox, and maybe I'll consider namespacing them
separately.

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2022-08-19 17:27 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-18 13:52 [PATCH v2 net-next 0/9] DSA changes for multiple CPU ports (part 3) Vladimir Oltean
2022-08-18 13:52 ` [PATCH v2 net-next 1/9] net: dsa: walk through all changeupper notifier functions Vladimir Oltean
2022-08-18 13:52 ` [PATCH v2 net-next 2/9] net: dsa: don't stop at NOTIFY_OK when calling ds->ops->port_prechangeupper Vladimir Oltean
2022-08-18 13:52 ` [PATCH v2 net-next 3/9] net: bridge: move DSA master bridging restriction to DSA Vladimir Oltean
2022-08-18 13:52 ` [PATCH v2 net-next 4/9] net: dsa: existing DSA masters cannot join upper interfaces Vladimir Oltean
2022-08-18 13:52 ` [PATCH v2 net-next 5/9] net: dsa: only bring down user ports assigned to a given DSA master Vladimir Oltean
2022-08-18 13:52 ` [PATCH v2 net-next 6/9] net: dsa: all DSA masters must be down when changing the tagging protocol Vladimir Oltean
2022-08-18 13:52 ` [PATCH v2 net-next 7/9] net: dsa: use dsa_tree_for_each_cpu_port in dsa_tree_{setup,teardown}_master Vladimir Oltean
2022-08-18 13:52 ` [PATCH v2 net-next 8/9] net: mscc: ocelot: set up tag_8021q CPU ports independent of user port affinity Vladimir Oltean
2022-08-19  3:58   ` Jakub Kicinski
2022-08-19 11:06     ` Vladimir Oltean
2022-08-19 13:37       ` Colin Foster
2022-08-19 13:39         ` Vladimir Oltean
2022-08-19 13:45           ` Colin Foster
2022-08-19 13:48             ` Vladimir Oltean
2022-08-19 13:57               ` Colin Foster
2022-08-19 16:44                 ` Vladimir Oltean
2022-08-18 13:52 ` [PATCH v2 net-next 9/9] net: mscc: ocelot: adjust forwarding domain for CPU ports in a LAG Vladimir Oltean

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).