Skip to contentSkip to conversation

net: dsa: realtek: rtl8365mb: bridge offloading and VLAN support

PATCH Superseded Luiz Angelo Daros de Luca 4 participants 33 messages May 7 – May 13

Subsystems (4)

v3 of 13 Superseded Latest is v13 →

lore
Share & tools
lore

Luiz Angelo Daros de Luca

author maintainer
#0 lore raw

v3 cover net: dsa: realtek: rtl8365mb: bridge offloading and VLAN support

This series introduces bridge offloading, FDB management, and VLAN support for the Realtek rtl8365mb DSA switch driver. The primary goal is to enable hardware frame forwarding between bridge ports, reducing CPU overhead and providing advanced features like VLAN and FDB isolation.

Some of these patches are based on original work by Alvin Šipraga, subsequently adapted and updated for the current net-next state.

---
I attempted to reach Alvin for review of the final version but was unable to establish contact. Any regressions in this version are my responsibility.

Changes in v3:
- Fixed kernel-doc warnings
- Removed unnecessary defensive checks
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- added patch to use ERR_PTR()
- dropped bitfield patch. Use FIELD_PREP instead. Suggested by Yury Norov
- tag_rtl8_4 patches were submitted on its own series (already accepted)
- dropped rtl8365mb_vlan_mc_port_{add,del}(). rtl8365mb_vlan_mc_port_set is now called directly from PVID methods.
- reordered methods in rtl8365mb_vlan.c
- use dsa_switch_for_each_user_port() instead of simple for in bridge port join/leave
- PVID check now uses dsa_switch_for_each_available_port instead of dsa_switch_for_each_port
- set EFID of user ports to 0 at setup(), although it is the expected state after reset
- STP patch was dropped and replaced by a more extensive one that disables all ports (including unused ones) before setting CPU and user ports. It also extended the CPU port isolation to include all user ports.
- refactored bridge, FDB, and MDB port operations into the common rtl83xx module, introducing new realtek_ops callbacks to abstract the hardware access
- Collected Reviewed-by and Suggested-by tags
- Link to v1:
https://patch.msgid.link/[email protected]

To: Linus Walleij <[email protected]>
To: Alvin Šipraga <[email protected]>
To: Andrew Lunn <[email protected]>
To: Vladimir Oltean <[email protected]>
To: "David S. Miller" <[email protected]>
To: Eric Dumazet <[email protected]>
To: Jakub Kicinski <[email protected]>
To: Paolo Abeni <[email protected]>
To: Russell King <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
Alvin Šipraga (6):
net: dsa: realtek: rtl8365mb: prepare for multiple source files
net: dsa: realtek: rtl8365mb: add table lookup interface
net: dsa: realtek: rtl8365mb: add VLAN support
net: dsa: realtek: rtl8365mb: add port_bridge_{join,leave}
net: dsa: realtek: rtl8365mb: add FDB support
net: dsa: realtek: rtl8365mb: add bridge port flags

Luiz Angelo Daros de Luca (2):
net: dsa: realtek: rtl8365mb: use ERR_PTR
net: dsa: realtek: rtl8365mb: use dsa helpers for port iteration

 drivers/net/dsa/realtek/Makefile                   |   4 +
 drivers/net/dsa/realtek/realtek.h                  |  42 ++
 drivers/net/dsa/realtek/rtl8365mb_l2.c             | 493 +++++++++++++
 drivers/net/dsa/realtek/rtl8365mb_l2.h             |  32 +
 .../dsa/realtek/{rtl8365mb.c => rtl8365mb_main.c}  | 548 ++++++++++++--
 drivers/net/dsa/realtek/rtl8365mb_table.c          | 214 ++++++
 drivers/net/dsa/realtek/rtl8365mb_table.h          | 131 ++++
 drivers/net/dsa/realtek/rtl8365mb_vlan.c           | 797 +++++++++++++++++++++
 drivers/net/dsa/realtek/rtl8365mb_vlan.h           |  25 +
 drivers/net/dsa/realtek/rtl83xx.c                  | 482 +++++++++++++
 drivers/net/dsa/realtek/rtl83xx.h                  |  27 +
 11 files changed, 2727 insertions(+), 68 deletions(-)

---
base-commit: edf4bee4215a173c0534d1851d7523d827149f9e
change-id: 20260323-realtek_forward-1bac3a77c664

Best regards,

Signature · 1 line
Luiz Angelo Daros de Luca <[email protected]>
author maintainer
#1 lore raw

PATCH v3 1/8 net: dsa: realtek: rtl8365mb: use ERR_PTR

Convert numeric error codes into human-readable strings by using %pe together with ERR_PTR() in dev_err() messages.

---
 drivers/net/dsa/realtek/rtl8365mb.c | 40 ++++++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 18 deletions(-)
drivers/net/dsa/realtek/rtl8365mb.c +22 -18
index c35cef01ec26..edbc16345d0d 100644
@@ -789,8 +789,8 @@ static int rtl8365mb_phy_read(struct realtek_priv *priv, int phy, int regnum)
 	ret = rtl8365mb_phy_ocp_read(priv, phy, ocp_addr, &val);
 	if (ret) {
 		dev_err(priv->dev,
-			"failed to read PHY%d reg %02x @ %04x, ret %d\n", phy,
-			regnum, ocp_addr, ret);
+			"failed to read PHY%d reg %02x @ %04x, ret %pe\n", phy,
+			regnum, ocp_addr, ERR_PTR(ret));
 		return ret;
 	}
 
@@ -817,8 +817,8 @@ static int rtl8365mb_phy_write(struct realtek_priv *priv, int phy, int regnum,
 	ret = rtl8365mb_phy_ocp_write(priv, phy, ocp_addr, val);
 	if (ret) {
 		dev_err(priv->dev,
-			"failed to write PHY%d reg %02x @ %04x, ret %d\n", phy,
-			regnum, ocp_addr, ret);
+			"failed to write PHY%d reg %02x @ %04x, ret %pe\n", phy,
+			regnum, ocp_addr, ERR_PTR(ret));
 		return ret;
 	}
 
@@ -1068,8 +1068,8 @@ static void rtl8365mb_phylink_mac_config(struct phylink_config *config,
 		ret = rtl8365mb_ext_config_rgmii(priv, port, state->interface);
 		if (ret)
 			dev_err(priv->dev,
-				"failed to configure RGMII mode on port %d: %d\n",
-				port, ret);
+				"failed to configure RGMII mode on port %d: %pe\n",
+				port, ERR_PTR(ret));
 		return;
 	}
 
@@ -1098,8 +1098,8 @@ static void rtl8365mb_phylink_mac_link_down(struct phylink_config *config,
 						     false, false);
 		if (ret)
 			dev_err(priv->dev,
-				"failed to reset forced mode on port %d: %d\n",
-				port, ret);
+				"failed to reset forced mode on port %d: %pe\n",
+				port, ERR_PTR(ret));
 
 		return;
 	}
@@ -1129,8 +1129,8 @@ static void rtl8365mb_phylink_mac_link_up(struct phylink_config *config,
 						     rx_pause);
 		if (ret)
 			dev_err(priv->dev,
-				"failed to force mode on port %d: %d\n", port,
-				ret);
+				"failed to force mode on port %d: %pe\n", port,
+				ERR_PTR(ret));
 
 		return;
 	}
@@ -1285,8 +1285,8 @@ static void rtl8365mb_get_ethtool_stats(struct dsa_switch *ds, int port, u64 *da
 						 mib->length, &data[i]);
 		if (ret) {
 			dev_err(priv->dev,
-				"failed to read port %d counters: %d\n", port,
-				ret);
+				"failed to read port %d counters: %pe\n", port,
+				ERR_PTR(ret));
 			break;
 		}
 	}
@@ -1638,7 +1638,8 @@ static irqreturn_t rtl8365mb_irq(int irq, void *data)
 	return IRQ_HANDLED;
 
 out_error:
-	dev_err(priv->dev, "failed to read interrupt status: %d\n", ret);
+	dev_err(priv->dev, "failed to read interrupt status: %pe\n",
+		ERR_PTR(ret));
 
 out_none:
 	return IRQ_NONE;
@@ -1776,7 +1777,8 @@ static int rtl8365mb_irq_setup(struct realtek_priv *priv)
 	ret = request_threaded_irq(irq, NULL, rtl8365mb_irq, IRQF_ONESHOT,
 				   "rtl8365mb", priv);
 	if (ret) {
-		dev_err(priv->dev, "failed to request irq: %d\n", ret);
+		dev_err(priv->dev, "failed to request irq: %pe\n",
+			ERR_PTR(ret));
 		goto out_remove_irqdomain;
 	}
 
@@ -1952,14 +1954,16 @@ static int rtl8365mb_setup(struct dsa_switch *ds)
 
 	ret = rtl8365mb_reset_chip(priv);
 	if (ret) {
-		dev_err(priv->dev, "failed to reset chip: %d\n", ret);
+		dev_err(priv->dev, "failed to reset chip: %pe\n",
+			ERR_PTR(ret));
 		goto out_error;
 	}
 
 	/* Configure switch to vendor-defined initial state */
 	ret = rtl8365mb_switch_init(priv);
 	if (ret) {
-		dev_err(priv->dev, "failed to initialize switch: %d\n", ret);
+		dev_err(priv->dev, "failed to initialize switch: %pe\n",
+			ERR_PTR(ret));
 		goto out_error;
 	}
 
@@ -2077,8 +2081,8 @@ static int rtl8365mb_detect(struct realtek_priv *priv)
 
 	ret = rtl8365mb_get_chip_id_and_ver(priv->map, &chip_id, &chip_ver);
 	if (ret) {
-		dev_err(priv->dev, "failed to read chip id and version: %d\n",
-			ret);
+		dev_err(priv->dev, "failed to read chip id and version: %pe\n",
+			ERR_PTR(ret));
 		return ret;
 	}
 
Signature · 1 line
2.54.0
author maintainer
#3 lore raw

PATCH v3 2/8 net: dsa: realtek: rtl8365mb: use dsa helpers for port iteration

In reply to Luiz Angelo Daros de Luca

Use dsa_switch_for_each_*() whenever possible.

For port setup(), a new blocking setup phase was added for all ports, including unused ones, before the user and CPU port setup.

CPU isolation now includes all user ports as traffic was being blocked in some scenarios (suggested by Abdulkader Alrezej).

---
 drivers/net/dsa/realtek/rtl8365mb.c | 115 +++++++++++++++++++++---------------
 1 file changed, 66 insertions(+), 49 deletions(-)
drivers/net/dsa/realtek/rtl8365mb.c +66 -49
index edbc16345d0d..7ddb82fcd026 100644
@@ -1540,18 +1540,15 @@ static void rtl8365mb_stats_setup(struct realtek_priv *priv)
 {
 	struct rtl8365mb *mb = priv->chip_data;
 	struct dsa_switch *ds = &priv->ds;
-	int i;
+	struct dsa_port *dp;
 
 	/* Per-chip global mutex to protect MIB counter access, since doing
 	 * so requires accessing a series of registers in a particular order.
 	 */
 	mutex_init(&mb->mib_lock);
 
-	for (i = 0; i < priv->num_ports; i++) {
-		struct rtl8365mb_port *p = &mb->ports[i];
-
-		if (dsa_is_unused_port(ds, i))
-			continue;
+	dsa_switch_for_each_available_port(dp, ds) {
+		struct rtl8365mb_port *p = &mb->ports[dp->index];
 
 		/* Per-port spinlock to protect the stats64 data */
 		spin_lock_init(&p->stats_lock);
@@ -1567,13 +1564,10 @@ static void rtl8365mb_stats_teardown(struct realtek_priv *priv)
 {
 	struct rtl8365mb *mb = priv->chip_data;
 	struct dsa_switch *ds = &priv->ds;
-	int i;
-
-	for (i = 0; i < priv->num_ports; i++) {
-		struct rtl8365mb_port *p = &mb->ports[i];
+	struct dsa_port *dp;
 
-		if (dsa_is_unused_port(ds, i))
-			continue;
+	dsa_switch_for_each_available_port(dp, ds) {
+		struct rtl8365mb_port *p = &mb->ports[dp->index];
 
 		cancel_delayed_work_sync(&p->mib_work);
 	}
@@ -1632,6 +1626,9 @@ static irqreturn_t rtl8365mb_irq(int irq, void *data)
 	for_each_set_bit(line, &line_changes, priv->num_ports) {
 		int child_irq = irq_find_mapping(priv->irqdomain, line);
 
+		if (!child_irq)
+			continue;
+
 		handle_nested_irq(child_irq);
 	}
 
@@ -1695,13 +1692,14 @@ static int rtl8365mb_irq_disable(struct realtek_priv *priv)
 static int rtl8365mb_irq_setup(struct realtek_priv *priv)
 {
 	struct rtl8365mb *mb = priv->chip_data;
+	struct dsa_switch *ds = &priv->ds;
 	struct device_node *intc;
+	struct dsa_port *dp;
 	u32 irq_trig;
 	int virq;
 	int irq;
 	u32 val;
 	int ret;
-	int i;
 
 	intc = of_get_child_by_name(priv->dev->of_node, "interrupt-controller");
 	if (!intc) {
@@ -1727,8 +1725,8 @@ static int rtl8365mb_irq_setup(struct realtek_priv *priv)
 		goto out_put_node;
 	}
 
-	for (i = 0; i < priv->num_ports; i++) {
-		virq = irq_create_mapping(priv->irqdomain, i);
+	dsa_switch_for_each_available_port(dp, ds) {
+		virq = irq_create_mapping(priv->irqdomain, dp->index);
 		if (!virq) {
 			dev_err(priv->dev,
 				"failed to create irq domain mapping\n");
@@ -1798,9 +1796,11 @@ static int rtl8365mb_irq_setup(struct realtek_priv *priv)
 	mb->irq = 0;
 
 out_remove_irqdomain:
-	for (i = 0; i < priv->num_ports; i++) {
-		virq = irq_find_mapping(priv->irqdomain, i);
-		irq_dispose_mapping(virq);
+	dsa_switch_for_each_available_port(dp, ds) {
+		virq = irq_find_mapping(priv->irqdomain, dp->index);
+
+		if (virq)
+			irq_dispose_mapping(virq);
 	}
 
 	irq_domain_remove(priv->irqdomain);
@@ -1815,8 +1815,9 @@ static int rtl8365mb_irq_setup(struct realtek_priv *priv)
 static void rtl8365mb_irq_teardown(struct realtek_priv *priv)
 {
 	struct rtl8365mb *mb = priv->chip_data;
+	struct dsa_switch *ds = &priv->ds;
+	struct dsa_port *dp;
 	int virq;
-	int i;
 
 	if (mb->irq) {
 		free_irq(mb->irq, priv);
@@ -1824,9 +1825,11 @@ static void rtl8365mb_irq_teardown(struct realtek_priv *priv)
 	}
 
 	if (priv->irqdomain) {
-		for (i = 0; i < priv->num_ports; i++) {
-			virq = irq_find_mapping(priv->irqdomain, i);
-			irq_dispose_mapping(virq);
+		dsa_switch_for_each_available_port(dp, ds) {
+			virq = irq_find_mapping(priv->irqdomain, dp->index);
+
+			if (virq)
+				irq_dispose_mapping(virq);
 		}
 
 		irq_domain_remove(priv->irqdomain);
@@ -1943,11 +1946,11 @@ static int rtl8365mb_reset_chip(struct realtek_priv *priv)
 static int rtl8365mb_setup(struct dsa_switch *ds)
 {
 	struct realtek_priv *priv = ds->priv;
+	struct dsa_port *cpu_dp, *dp;
 	struct rtl8365mb_cpu *cpu;
-	struct dsa_port *cpu_dp;
 	struct rtl8365mb *mb;
+	u32 userports_mask;
 	int ret;
-	int i;
 
 	mb = priv->chip_data;
 	cpu = &mb->cpu;
@@ -1974,44 +1977,58 @@ static int rtl8365mb_setup(struct dsa_switch *ds)
 	else if (ret)
 		dev_info(priv->dev, "no interrupt support\n");
 
+	/* Start with all ports blocked, including unused ports */
+	dsa_switch_for_each_port(dp, ds) {
+		struct rtl8365mb_port *p = &mb->ports[dp->index];
+
+		/* Set the initial STP state of all ports to DISABLED, otherwise
+		 * ports will still forward frames to the CPU despite being
+		 * administratively down by default.
+		 */
+		rtl8365mb_port_stp_state_set(ds, dp->index, BR_STATE_DISABLED);
+
+		/* Start with all port completely isolated */
+		ret = rtl8365mb_port_set_isolation(priv, dp->index, 0);
+		if (ret)
+			goto out_teardown_irq;
+
+		/* Disable learning */
+		ret = rtl8365mb_port_set_learning(priv, dp->index, false);
+		if (ret)
+			goto out_teardown_irq;
+
+		/* Set up per-port private data */
+		p->priv = priv;
+		p->index = dp->index;
+	}
+
+	userports_mask = dsa_user_ports(ds);
+
 	/* Configure CPU tagging */
 	dsa_switch_for_each_cpu_port(cpu_dp, ds) {
-		cpu->mask |= BIT(cpu_dp->index);
-
+		/* Use the first CPU port as trap_port */
 		if (cpu->trap_port == RTL8365MB_MAX_NUM_PORTS)
 			cpu->trap_port = cpu_dp->index;
+
+		/* Forward to all user ports */
+		ret = rtl8365mb_port_set_isolation(priv, cpu_dp->index,
+						   userports_mask);
+		if (ret)
+			goto out_teardown_irq;
 	}
+
+	cpu->mask = dsa_cpu_ports(ds);
 	cpu->enable = cpu->mask > 0;
 	ret = rtl8365mb_cpu_config(priv);
 	if (ret)
 		goto out_teardown_irq;
 
-	/* Configure ports */
-	for (i = 0; i < priv->num_ports; i++) {
-		struct rtl8365mb_port *p = &mb->ports[i];
-
-		if (dsa_is_unused_port(ds, i))
-			continue;
-
+	/* Configure user ports */
+	dsa_switch_for_each_user_port(dp, ds) {
 		/* Forward only to the CPU */
-		ret = rtl8365mb_port_set_isolation(priv, i, cpu->mask);
+		ret = rtl8365mb_port_set_isolation(priv, dp->index, cpu->mask);
 		if (ret)
 			goto out_teardown_irq;
-
-		/* Disable learning */
-		ret = rtl8365mb_port_set_learning(priv, i, false);
-		if (ret)
-			goto out_teardown_irq;
-
-		/* Set the initial STP state of all ports to DISABLED, otherwise
-		 * ports will still forward frames to the CPU despite being
-		 * administratively down by default.
-		 */
-		rtl8365mb_port_stp_state_set(ds, i, BR_STATE_DISABLED);
-
-		/* Set up per-port private data */
-		p->priv = priv;
-		p->index = i;
 	}
 
 	ret = rtl8365mb_port_change_mtu(ds, cpu->trap_port, ETH_DATA_LEN);
Signature · 1 line
2.54.0
Reviewed-by on v3 2/8
#4 lore raw

Re: [net-next PATCH v3 2/8] net: dsa: realtek: rtl8365mb: use dsa helpers for port iteration

Quoted 11 lines · Luiz Angelo Daros de Luca

Use dsa_switch_for_each_*() whenever possible.

For port setup(), a new blocking setup phase was added for all ports, including unused ones, before the user and CPU port setup.

CPU isolation now includes all user ports as traffic was being blocked in some scenarios (suggested by Abdulkader Alrezej).

maintainer
#5 lore raw

Re: [net-next PATCH v3 2/8] net: dsa: realtek: rtl8365mb: use dsa helpers for port iteration

In reply to Luiz Angelo Daros de Luca

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: dsa: realtek: rtl8365mb: use dsa helpers for port iteration

This commit refactors rtl8365mb port iteration to use the dsa_switch_for_each_*() helpers, adds a blocking setup phase for all ports up front, and extends CPU-port isolation to include all user ports.

Quoted 4 lines
drivers/net/dsa/realtek/rtl8365mb.c +0 -0
index edbc16345d0d..7ddb82fcd026 100644

[ ... ]

Quoted 14 lines
drivers/net/dsa/realtek/rtl8365mb.c +2 -2
@@ -1943,11 +1946,11 @@ static int rtl8365mb_reset_chip(struct realtek_priv *priv)
 static int rtl8365mb_setup(struct dsa_switch *ds)
 {
 	struct realtek_priv *priv = ds->priv;
+	struct dsa_port *cpu_dp, *dp;
 	struct rtl8365mb_cpu *cpu;
-	struct dsa_port *cpu_dp;
 	struct rtl8365mb *mb;
+	u32 userports_mask;
 	int ret;
-	int i;
 
 	mb = priv->chip_data;
 	cpu = &mb->cpu;

[ ... ]

Quoted 52 lines
drivers/net/dsa/realtek/rtl8365mb.c +36 -6
+	/* Start with all ports blocked, including unused ports */
+	dsa_switch_for_each_port(dp, ds) {
+		struct rtl8365mb_port *p = &mb->ports[dp->index];
+
+		/* Set the initial STP state of all ports to DISABLED, otherwise
+		 * ports will still forward frames to the CPU despite being
+		 * administratively down by default.
+		 */
+		rtl8365mb_port_stp_state_set(ds, dp->index, BR_STATE_DISABLED);
+
+		/* Start with all port completely isolated */
+		ret = rtl8365mb_port_set_isolation(priv, dp->index, 0);
+		if (ret)
+			goto out_teardown_irq;
+
+		/* Disable learning */
+		ret = rtl8365mb_port_set_learning(priv, dp->index, false);
+		if (ret)
+			goto out_teardown_irq;
+
+		/* Set up per-port private data */
+		p->priv = priv;
+		p->index = dp->index;
+	}
+
+	userports_mask = dsa_user_ports(ds);
+
 	/* Configure CPU tagging */
 	dsa_switch_for_each_cpu_port(cpu_dp, ds) {
-		cpu->mask |= BIT(cpu_dp->index);
-
+		/* Use the first CPU port as trap_port */
 		if (cpu->trap_port == RTL8365MB_MAX_NUM_PORTS)
 			cpu->trap_port = cpu_dp->index;
+
+		/* Forward to all user ports */
+		ret = rtl8365mb_port_set_isolation(priv, cpu_dp->index,
+						   userports_mask);
+		if (ret)
+			goto out_teardown_irq;
 	}
+
+	cpu->mask = dsa_cpu_ports(ds);
 	cpu->enable = cpu->mask > 0;
 	ret = rtl8365mb_cpu_config(priv);
 	if (ret)
 		goto out_teardown_irq;
 
-	/* Configure ports */
-	for (i = 0; i < priv->num_ports; i++) {
-		struct rtl8365mb_port *p = &mb->ports[i];
-

drivers/net/dsa/realtek/rtl8365mb.c static int rtl8365mb_setup(struct dsa_switch *ds) · line 2031

Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb.c +3 -4
-		if (dsa_is_unused_port(ds, i))
-			continue;
-
+	/* Configure user ports */
+	dsa_switch_for_each_user_port(dp, ds) {
 		/* Forward only to the CPU */
-		ret = rtl8365mb_port_set_isolation(priv, i, cpu->mask);
+		ret = rtl8365mb_port_set_isolation(priv, dp->index, cpu->mask);
 		if (ret)
 			goto out_teardown_irq;

[Medium]
Does this refactor change behaviour for DSA-type ports (DSA_PORT_TYPE_DSA)?

Before the patch, the configuration loop iterated every non-unused port and applied cpu->mask as the isolation mask, which included DSA-type ports:

	for (i = 0; i < priv->num_ports; i++) {
		...
		if (dsa_is_unused_port(ds, i))
			continue;
		/* Forward only to the CPU */
		ret = rtl8365mb_port_set_isolation(priv, i, cpu->mask);
		...
	}

After the patch, the first pass sets isolation to 0 for every port, and the subsequent passes only match CPU ports and user ports:

	#define dsa_switch_for_each_cpu_port(_dp, _ds) \
		dsa_switch_for_each_port((_dp), (_ds)) \
			if (dsa_port_is_cpu((_dp)))

	#define dsa_switch_for_each_user_port(_dp, _ds) \
		dsa_switch_for_each_port((_dp), (_ds)) \
			if (dsa_port_is_user((_dp)))

So a DSA-type port keeps isolation=0 from the initial pass and is never reconfigured.

In addition, the masks derived from dsa_user_ports() and dsa_cpu_ports() exclude DSA-type ports, so CPU and user ports will not include DSA link ports in their isolation masks either, which looks like it would block forwarding across cascaded switches in both directions.

The commit message describes the behaviour change only as "CPU isolation now includes all user ports"; is the loss of DSA-port configuration intentional, and if so should it be called out in the commit message?

Signature · 1 line
pw-bot: cr
maintainer
#6 lore raw

Re: [net-next PATCH v3 2/8] net: dsa: realtek: rtl8365mb: use dsa helpers for port iteration

In reply to Luiz Angelo Daros de Luca

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: dsa: realtek: rtl8365mb: use dsa helpers for port iteration

This commit modifies the port initialization to use DSA iterator helpers instead of manually iterating over ports. It introduces an initial blocking phase for all ports and updates the isolation rules for CPU and user ports.

Quoted 3 lines
drivers/net/dsa/realtek/rtl8365mb.c +0 -0

[ ... ]

Quoted 1 line
drivers/net/dsa/realtek/rtl8365mb.c +0 -0
@@ -1974,44 +1977,58 @@ static int rtl8365mb_setup(struct dsa_switch *ds)

[ ... ]

Quoted 2 lines
drivers/net/dsa/realtek/rtl8365mb.c +2 -0
+	/* Start with all ports blocked, including unused ports */
+	dsa_switch_for_each_port(dp, ds) {

[ ... ]

Quoted 2 lines
drivers/net/dsa/realtek/rtl8365mb.c +2 -0
+		/* Start with all port completely isolated */
+		ret = rtl8365mb_port_set_isolation(priv, dp->index, 0);

[ ... ]

Quoted 4 lines
drivers/net/dsa/realtek/rtl8365mb.c +2 -0
+	userports_mask = dsa_user_ports(ds);
+
 	/* Configure CPU tagging */
 	dsa_switch_for_each_cpu_port(cpu_dp, ds) {

[ ... ]

drivers/net/dsa/realtek/rtl8365mb.c static int rtl8365mb_setup(struct dsa_switch *ds) · line 2015

Quoted 3 lines
drivers/net/dsa/realtek/rtl8365mb.c +3 -0
+		/* Forward to all user ports */
+		ret = rtl8365mb_port_set_isolation(priv, cpu_dp->index,
+						   userports_mask);

Will CPU ports be prevented from forwarding traffic to downstream switches in a multi-switch configuration?

Since dsa_user_ports(ds) only includes user ports, the userports_mask will exclude DSA cascade ports.

Quoted 15 lines
drivers/net/dsa/realtek/rtl8365mb.c +3 -5
+		if (ret)
+			goto out_teardown_irq;
 	}
+
 	cpu->mask = dsa_cpu_ports(ds);
 	cpu->enable = cpu->mask > 0;
 	ret = rtl8365mb_cpu_config(priv);
 	if (ret)
 		goto out_teardown_irq;
 
-	/* Configure ports */
-	for (i = 0; i < priv->num_ports; i++) {
-		struct rtl8365mb_port *p = &mb->ports[i];
-
-		if (dsa_is_unused_port(ds, i))

drivers/net/dsa/realtek/rtl8365mb.c static int rtl8365mb_setup(struct dsa_switch *ds) · line 2032

Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb.c +3 -3
-			continue;
-
+	/* Configure user ports */
+	dsa_switch_for_each_user_port(dp, ds) {
 		/* Forward only to the CPU */
-		ret = rtl8365mb_port_set_isolation(priv, i, cpu->mask);
+		ret = rtl8365mb_port_set_isolation(priv, dp->index, cpu->mask);
 		if (ret)
 			goto out_teardown_irq;
 	}

Does this leave DSA cascade ports permanently isolated?

In the previous code, the loop skipped unused ports and applied the CPU mask to all active ports, which implicitly included DSA cascade ports.

Because the new setup explicitly targets only user ports and CPU ports, it appears DSA cascade ports (DSA_PORT_TYPE_DSA) are never unblocked after being isolated in the initial blocking phase.

author maintainer
#7 lore raw

PATCH v3 3/8 net: dsa: realtek: rtl8365mb: prepare for multiple source files

In reply to Luiz Angelo Daros de Luca

From: Alvin Šipraga <[email protected]>

Rename rtl8365mb.c to rtl8365mb_main.c in preparation for subsequent commits which add additional source files to the driver.

The trailing backslash in the Makefile is deliberate. It allows for new files to be added without clobbering git history.

---
 drivers/net/dsa/realtek/Makefile                          | 1 +
 drivers/net/dsa/realtek/{rtl8365mb.c => rtl8365mb_main.c} | 0
 2 files changed, 1 insertion(+)
drivers/net/dsa/realtek/Makefile +1 -0
index 17367bcba496..3f986e04912f 100644
@@ -16,3 +16,4 @@ ifdef CONFIG_NET_DSA_REALTEK_RTL8366RB_LEDS
 rtl8366-objs 				+= rtl8366rb-leds.o
 endif
 obj-$(CONFIG_NET_DSA_REALTEK_RTL8365MB) += rtl8365mb.o
+rtl8365mb-objs := rtl8365mb_main.o \
drivers/net/dsa/realtek/rtl8365mb_main.c renamed from drivers/net/dsa/realtek/rtl8365mb.c +0 -0
similarity index 100%
rename from drivers/net/dsa/realtek/rtl8365mb.c
rename to drivers/net/dsa/realtek/rtl8365mb_main.c
Signature · 1 line
2.54.0
Reviewed-by on v3 3/8
#8 lore raw

Re: [net-next PATCH v3 3/8] net: dsa: realtek: rtl8365mb: prepare for multiple source files

Quoted 5 lines · Luiz Angelo Daros de Luca

From: Alvin Šipraga <[email protected]>

Rename rtl8365mb.c to rtl8365mb_main.c in preparation for subsequent commits which add additional source files to the driver.

Quoted 7 lines

The trailing backslash in the Makefile is deliberate. It allows for new files to be added without clobbering git history.

author maintainer
#9 lore raw

PATCH v3 4/8 net: dsa: realtek: rtl8365mb: add table lookup interface

In reply to Luiz Angelo Daros de Luca

From: Alvin Šipraga <[email protected]>

Add a generic table lookup interface to centralize access to the RTL8365MB internal tables.

This interface abstracts the low-level table access logic and will be used by subsequent commits to implement FDB and VLAN operations.

---
 drivers/net/dsa/realtek/Makefile          |   1 +
 drivers/net/dsa/realtek/rtl8365mb_table.c | 214 ++++++++++++++++++++++++++++++
 drivers/net/dsa/realtek/rtl8365mb_table.h | 131 ++++++++++++++++++
 3 files changed, 346 insertions(+)
drivers/net/dsa/realtek/Makefile +1 -0
index 3f986e04912f..99654c4c5a3d 100644
@@ -17,3 +17,4 @@ rtl8366-objs 				+= rtl8366rb-leds.o
 endif
 obj-$(CONFIG_NET_DSA_REALTEK_RTL8365MB) += rtl8365mb.o
 rtl8365mb-objs := rtl8365mb_main.o \
+		  rtl8365mb_table.o \
drivers/net/dsa/realtek/rtl8365mb_table.c new file +214 -0

214 lines not on this page · raw message

drivers/net/dsa/realtek/rtl8365mb_table.h new file +131 -0

131 lines not on this page · raw message

Signature · 1 line
2.54.0
Reviewed-by on v3 4/8
#10 lore raw

Re: [net-next PATCH v3 4/8] net: dsa: realtek: rtl8365mb: add table lookup interface

Quoted 5 lines · Luiz Angelo Daros de Luca

From: Alvin Šipraga <[email protected]>

Add a generic table lookup interface to centralize access to the RTL8365MB internal tables.

Quoted 8 lines

This interface abstracts the low-level table access logic and will be used by subsequent commits to implement FDB and VLAN operations.

maintainer
#11 lore raw

Re: [net-next PATCH v3 4/8] net: dsa: realtek: rtl8365mb: add table lookup interface

In reply to Luiz Angelo Daros de Luca

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: dsa: realtek: rtl8365mb: add table lookup interface

This commit adds a generic table lookup interface for the RTL8365MB switch family via rtl8365mb_table_query(), centralizing access to the internal ACL, CVLAN, L2 and IGMP tables behind a single helper.

Quoted 5 lines
drivers/net/dsa/realtek/rtl8365mb_table.c new file +0 -0
new file mode 100644
index 000000000000..df312769b0be

[ ... ]

Quoted 4 lines
drivers/net/dsa/realtek/rtl8365mb_table.c new file +4 -0
+int rtl8365mb_table_query(struct realtek_priv *priv,
+			  enum rtl8365mb_table table,
+			  enum rtl8365mb_table_op op, u16 *addr,
+			  enum rtl8365mb_table_l2_method method,

drivers/net/dsa/realtek/rtl8365mb_table.c line 74

Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_table.c new file +10 -0
+			  u16 port, u16 *data, size_t size)
+{
+	bool addr_as_input = true;
+	bool write_data = false;
+	int ret = 0;
+	u32 cmd;
+	u32 val;
+	u32 hit;
+
+	/* Prepare target table and operation (read or write) */

[Medium]
Is the size argument validated anywhere in this function? The kerneldoc for rtl8365mb_table_query() in rtl8365mb_table.h states:

* @size must match the size of the target table entry, expressed in 16-bit
* words. This function only validates that it is non-zero and fits in the
* available register space.

but no check of the form

    if (!size || size > RTL8365MB_TABLE_ENTRY_MAX_SIZE)
            return -EINVAL;

appears to exist. All in-tree callers introduced by subsequent patches pass compile-time-constant sizes well within bounds, so nothing breaks today, but should the kerneldoc be adjusted to make the caller responsible, or should the validation it promises be added at the top of the function?

[ ... ]

drivers/net/dsa/realtek/rtl8365mb_table.c line 129

Quoted 9 lines
drivers/net/dsa/realtek/rtl8365mb_table.c new file +9 -0
+	/* Write entry data if writing to the table (or L2_METHOD_MAC) */
+	if (write_data) {
+		/* bulk write data up to 9th byte */
+		ret = regmap_bulk_write(priv->map_nolock,
+					RTL8365MB_TABLE_WRITE_BASE,
+					data,
+					min_t(size_t, size,
+					      RTL8365MB_TABLE_ENTRY_MAX_SIZE -
+						      1));

[Low]
Does the comment "bulk write data up to 9th byte" match the code? The data parameter is declared as u16 *, the kerneldoc defines @size as "size of @data in 16-bit words", and regmap_bulk_write() counts in register-sized units (2 bytes here). The min_t() clamp of RTL8365MB_TABLE_ENTRY_MAX_SIZE - 1 is 9 words (18 bytes), not 9 bytes.

drivers/net/dsa/realtek/rtl8365mb_table.c line 133

Quoted 4 lines
drivers/net/dsa/realtek/rtl8365mb_table.c new file +4 -0
+		if (ret)
+			goto out;
+
+		/* 10th register uses only 4 less significant bits */

[Low]
Should "4 less significant bits" read "4 least significant bits" here? RTL8365MB_TABLE_10TH_DATA_MASK is GENMASK(3, 0), i.e. the four least significant bits.

Quoted 12 lines
drivers/net/dsa/realtek/rtl8365mb_table.c new file +12 -0
+		if (size == RTL8365MB_TABLE_ENTRY_MAX_SIZE) {
+			val = FIELD_PREP(RTL8365MB_TABLE_10TH_DATA_MASK,
+					 data[size - 1]);
+			ret = regmap_update_bits(priv->map_nolock,
+						 RTL8365MB_TABLE_WRITE_10TH_REG,
+						 RTL8365MB_TABLE_10TH_DATA_MASK,
+						 val);
+		}
+
+		if (ret)
+			goto out;
+	}

[ ... ]

Quoted 8 lines
drivers/net/dsa/realtek/rtl8365mb_table.c new file +8 -0
+	/* Finally, get the table entry if we were reading */
+	if (op == RTL8365MB_TABLE_OP_READ) {
+		ret = regmap_bulk_read(priv->map_nolock,
+				       RTL8365MB_TABLE_READ_BASE,
+				       data, size);
+
+		/* For the biggest table entries, the uppermost table
+		 * entry register has space for only one nibble. Mask

drivers/net/dsa/realtek/rtl8365mb_table.c line 208

Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_table.c new file +10 -0
+		 * out the remainder bits. Empirically I saw nothing
+		 * wrong with omitting this mask, but it may prevent
+		 * unwanted behaviour. FYI.
+		 */
+		if (size == RTL8365MB_TABLE_ENTRY_MAX_SIZE) {
+			val = FIELD_GET(RTL8365MB_TABLE_10TH_DATA_MASK,
+					data[size - 1]);
+			data[size - 1] = val;
+		}
+	}

[Low, Medium]
Should the return value of regmap_bulk_read() be checked before falling through to the data[size - 1] masking block? Every other regmap call in this function bails out with "if (ret) goto out;". The ret is still propagated to the caller via the out: label and the kerneldoc notes that @data is undefined on error, so there is no functional bug with the current callers, but the asymmetry stands out.

Relatedly, since size is not validated up front, regmap_bulk_read() is called with the raw size here while the write path used min_t(size_t, size, RTL8365MB_TABLE_ENTRY_MAX_SIZE - 1). If a future caller passed size > RTL8365MB_TABLE_ENTRY_MAX_SIZE, reads would spill past the RTL8365MB_TABLE_READ_BASE register window and into whatever follows, and could write past the caller's buffer too. Would an explicit bounds check make the contract enforceable?

Quoted 6 lines
drivers/net/dsa/realtek/rtl8365mb_table.c new file +6 -0
+
+out:
+	mutex_unlock(&priv->map_lock);
+
+	return ret;
+}
author maintainer
#12 lore raw

PATCH v3 5/8 net: dsa: realtek: rtl8365mb: add VLAN support

In reply to Luiz Angelo Daros de Luca

From: Alvin Šipraga <[email protected]>

Realtek RTL8365MB switches (a.k.a. RTL8367C family) use two different structures for VLANs:

- VLAN4K: A full table with 4096 entries defining port membership and tagging.
- VLANMC: A smaller table with 32 entries used primarily for PVID assignment.

In this hardware, a port's PVID must point to an index in the VLANMC table rather than a VID directly. Since the VLANMC table is limited to 32 entries, the driver implements a dynamic allocation scheme to maximize resource usage:

- VLAN4K is treated by the driver as the source of truth for membership.
- A VLANMC entry is only allocated when a port is configured to use a specific VID as its PVID.
- VLANMC entries are deleted when no longer needed as a PVID by any port.

Although VLANMC has a members field, the switch only checks membership in the VLAN4K table. However, when a corresponding VLAN entry also exists in VLANMC, this driver keeps both membership configurations in sync.

VLANMC index 0, although a valid entry, is reserved in this driver as a neutral PVID value for ports not using a specific PVID.

In the subsequent RTL8367D switch family, VLANMC table was removed and PVID assignment was delegated to a dedicated set of registers.

All ports start isolated, forwarding exclusively to CPU ports, and with VLAN transparent, ignoring VLAN membership. Once a member in a bridge, the port isolation is expanded to include the bridge members. When that bridge enables VLAN filtering, the VLAN transparent feature is disabled, letting the switch filter based on VLAN setup.

The use of FIELD_PREP for reconstructing LO/HI values was suggested by Yury Norov.

Fix for vlan_setup and vlan_filtering was suggested by Abdulkader Alrezej.

---
 drivers/net/dsa/realtek/Makefile         |   1 +
 drivers/net/dsa/realtek/rtl8365mb_main.c | 248 ++++++++++
 drivers/net/dsa/realtek/rtl8365mb_vlan.c | 797 +++++++++++++++++++++++++++++++
 drivers/net/dsa/realtek/rtl8365mb_vlan.h |  25 +
 4 files changed, 1071 insertions(+)
drivers/net/dsa/realtek/Makefile +1 -0
index 99654c4c5a3d..b7fc4e852fd8 100644
@@ -18,3 +18,4 @@ endif
 obj-$(CONFIG_NET_DSA_REALTEK_RTL8365MB) += rtl8365mb.o
 rtl8365mb-objs := rtl8365mb_main.o \
 		  rtl8365mb_table.o \
+		  rtl8365mb_vlan.o \
drivers/net/dsa/realtek/rtl8365mb_main.c +248 -0

278 lines not on this page · raw message

drivers/net/dsa/realtek/rtl8365mb_vlan.c new file +797 -0

797 lines not on this page · raw message

drivers/net/dsa/realtek/rtl8365mb_vlan.h new file +25 -0
new file mode 100644
index 000000000000..ed63a0ec0d10
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* VLAN configuration interface for the rtl8365mb switch family
+ *
+ * Copyright (C) 2022 Alvin Šipraga <[email protected]>
+ *
+ */
+
+#ifndef _REALTEK_RTL8365MB_VLAN_H
+#define _REALTEK_RTL8365MB_VLAN_H
+
+#include <linux/types.h>
+
+#include "realtek.h"
+
+int rtl8365mb_vlan_4k_port_add(struct dsa_switch *ds, int port,
+			       const struct switchdev_obj_port_vlan *vlan,
+			       struct netlink_ext_ack *extack);
+int rtl8365mb_vlan_4k_port_del(struct dsa_switch *ds, int port,
+			       const struct switchdev_obj_port_vlan *vlan);
+int rtl8365mb_vlan_pvid_port_add(struct dsa_switch *ds, int port,
+				 const struct switchdev_obj_port_vlan *vlan,
+				 struct netlink_ext_ack *extack);
+int rtl8365mb_vlan_pvid_port_del(struct dsa_switch *ds, int port,
+				 const struct switchdev_obj_port_vlan *vlan);
+#endif /* _REALTEK_RTL8365MB_VLAN_H */
Signature · 1 line
2.54.0
Reviewed-by on v3 5/8
#13 lore raw

Re: [net-next PATCH v3 5/8] net: dsa: realtek: rtl8365mb: add VLAN support

Quoted 43 lines · Luiz Angelo Daros de Luca

From: Alvin Šipraga <[email protected]>

Realtek RTL8365MB switches (a.k.a. RTL8367C family) use two different structures for VLANs:

- VLAN4K: A full table with 4096 entries defining port membership and tagging.
- VLANMC: A smaller table with 32 entries used primarily for PVID assignment.

In this hardware, a port's PVID must point to an index in the VLANMC table rather than a VID directly. Since the VLANMC table is limited to 32 entries, the driver implements a dynamic allocation scheme to maximize resource usage:

- VLAN4K is treated by the driver as the source of truth for membership.
- A VLANMC entry is only allocated when a port is configured to use a specific VID as its PVID.
- VLANMC entries are deleted when no longer needed as a PVID by any port.

Although VLANMC has a members field, the switch only checks membership in the VLAN4K table. However, when a corresponding VLAN entry also exists in VLANMC, this driver keeps both membership configurations in sync.

VLANMC index 0, although a valid entry, is reserved in this driver as a neutral PVID value for ports not using a specific PVID.

In the subsequent RTL8367D switch family, VLANMC table was removed and PVID assignment was delegated to a dedicated set of registers.

All ports start isolated, forwarding exclusively to CPU ports, and with VLAN transparent, ignoring VLAN membership. Once a member in a bridge, the port isolation is expanded to include the bridge members. When that bridge enables VLAN filtering, the VLAN transparent feature is disabled, letting the switch filter based on VLAN setup.

The use of FIELD_PREP for reconstructing LO/HI values was suggested by Yury Norov.

Fix for vlan_setup and vlan_filtering was suggested by Abdulkader Alrezej.

Quoted 6 lines
maintainer
#14 lore raw

Re: [net-next PATCH v3 5/8] net: dsa: realtek: rtl8365mb: add VLAN support

In reply to Luiz Angelo Daros de Luca

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
Subject: net: dsa: realtek: rtl8365mb: add VLAN support

This patch adds VLAN support for the rtl8365mb switch family, using the 4096-entry VLAN4K table as the source of truth for membership and dynamically allocating entries from the 32-entry VLAN MC table to back per-port PVID assignments. Standalone ports use VLAN-transparent mode combined with port isolation, and filtering is toggled per-port via ingress filtering, transparent mode and the egress tag-mode register.

[Low]
Regarding this portion of the commit message:

Once a member in a bridge, the port isolation is expanded to include the bridge members. When that bridge enables VLAN filtering, the VLAN transparent feature is disabled, letting the switch filter based on VLAN setup.

This patch does not add port_bridge_join or port_bridge_leave callbacks and does not adjust the isolation masks when bridge membership changes; that functionality appears to be introduced by the following patch in the series (net: dsa: realtek: rtl8365mb: add port_bridge_{join,leave}).

Would it be clearer to describe the end state as applying to the full series, or to move this paragraph to the patch that actually implements the bridge-driven isolation adjustment?

Quoted 4 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +0 -0
index 7ddb82fcd026..b37aa847a9aa 100644

[ ... ]

Quoted 34 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +34 -0
+static int rtl8365mb_port_vlan_filtering(struct dsa_switch *ds, int port,
+					 bool vlan_filtering,
+					 struct netlink_ext_ack *extack)
+{
+	enum rtl8365mb_vlan_egress_mode mode;
+	struct realtek_priv *priv = ds->priv;
+	struct dsa_port *dp;
+	int ret;
+
+	dev_dbg(priv->dev, "port %d: %s VLAN filtering\n", port,
+		vlan_filtering ? "enable" : "disable");
+
+	/* When vlan filter is enable/disabled in a bridge, this function is
+	 * called for all member ports. We need to enable/disable ingress
+	 * VLAN membership check.
+	 */
+	ret = rtl8365mb_port_set_ingress_filtering(priv, port, vlan_filtering);
+	if (ret)
+		return ret;
+
+	/* However, we also enable/disable egress filtering because the switch
+	 * still consider the egress interface VLAN membership to forward the
+	 * traffic. We enable/disable that check disabling/enabling transparent
+	 * VLAN between the ingress port and all other available ports.
+	 */
+	dsa_switch_for_each_available_port(dp, ds) {
+		/* port isolation will still keep traffic inside the bridge */
+		ret = rtl8365mb_port_set_transparent(priv, port, dp->index,
+						     !vlan_filtering);
+		if (ret)
+			return ret;
+	}
+
+	/* When VLAN filtering is disabled, preserve frames exactly as received.

drivers/net/dsa/realtek/rtl8365mb_main.c static void rtl8365mb_port_stp_state_set(struct dsa_switch *ds, int port, · line 1349

Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +10 -0
+	 * Otherwise, the VLAN egress pipeline may still alter tag state
+	 * according to VLAN membership and untag configuration.
+	 */
+	if (vlan_filtering)
+		mode = RTL8365MB_VLAN_EGRESS_MODE_ORIGINAL;
+	else
+		mode = RTL8365MB_VLAN_EGRESS_MODE_REAL_KEEP;
+
+	return rtl8365mb_port_set_vlan_egress_mode(priv, port, mode);
+}

[Low]
If any of the regmap writes here fails, is the hardware left in a partially-updated state?

rtl8365mb_port_set_ingress_filtering() is already committed before the loop runs, and inside the loop each rtl8365mb_port_set_transparent() call flips a transparent bit on a different egress register. A mid-loop failure returns the error but leaves earlier ports with transparent mode toggled and also skips the trailing rtl8365mb_port_set_vlan_egress_mode() write.

Would it be worth reverting already-applied changes on error, so that a returned failure corresponds to an unchanged port configuration rather than a port split between the old and new vlan_filtering state?

[ ... ]

Quoted 8 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +4 -0
@@ -2035,6 +2266,20 @@ static int rtl8365mb_setup(struct dsa_switch *ds)
 	if (ret)
 		goto out_teardown_irq;
 
+	ds->configure_vlan_while_not_filtering = true;
+
+	/* Set up VLAN */
+	ret = rtl8365mb_vlan_setup(ds);

drivers/net/dsa/realtek/rtl8365mb_main.c static int rtl8365mb_setup(struct dsa_switch *ds) · line 2282

Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +10 -0
+	if (ret)
+		goto out_teardown_irq;
+
+	/* Set maximum packet length to 1536 bytes */
+	ret = regmap_update_bits(priv->map, RTL8365MB_CFG0_MAX_LEN_REG,
+				 RTL8365MB_CFG0_MAX_LEN_MASK,
+				 FIELD_PREP(RTL8365MB_CFG0_MAX_LEN_MASK, 1536));
+	if (ret)
+		goto out_teardown_irq;
+

[Medium]
Is this RTL8365MB_CFG0_MAX_LEN_REG write intended to be part of this VLAN patch?

rtl8365mb_setup() already calls rtl8365mb_port_change_mtu(ds, cpu->trap_port, ETH_DATA_LEN) earlier, which programs the same global RTL8365MB_CFG0_MAX_LEN_REG with frame_size derived from ETH_DATA_LEN + VLAN_ETH_HLEN + ETH_FCS_LEN (1522). This new hunk then unconditionally overwrites that with 1536.

Neither the subject nor the commit message mention any MTU or frame-length change. Would it make sense to split this MAX_LEN_REG adjustment into its own patch with a rationale for the 1536 value, rather than carrying it as an unrelated side-effect of VLAN support?

[ ... ]

Quoted 5 lines
drivers/net/dsa/realtek/rtl8365mb_vlan.c new file +0 -0
new file mode 100644
index 000000000000..a68e0d18a611

[ ... ]

Quoted 32 lines
drivers/net/dsa/realtek/rtl8365mb_vlan.c new file +32 -0
+static int rtl8365mb_vlan_mc_read(struct realtek_priv *priv, u32 index,
+				  struct rtl8365mb_vlanmc *vlanmc)
+{
+	u16 data[RTL8365MB_VLAN_MC_ENTRY_SIZE];
+	int ret;
+
+	ret = regmap_bulk_read(priv->map, RTL8365MB_VLAN_MC_REG(index), &data,
+			       RTL8365MB_VLAN_MC_ENTRY_SIZE);
+	if (ret)
+		return ret;
+
+	vlanmc->member = FIELD_GET(RTL8365MB_VLAN_MC_D0_MBR_MASK, data[0]);
+	vlanmc->fid = FIELD_GET(RTL8365MB_VLAN_MC_D1_FID_MASK, data[1]);
+	vlanmc->priority = FIELD_GET(RTL8365MB_VLAN_MC_D2_VBPRI_MASK, data[2]);
+	vlanmc->evid = FIELD_GET(RTL8365MB_VLAN_MC_D3_EVID_MASK, data[3]);
+
+	return 0;
+}
+
+static int rtl8365mb_vlan_mc_write(struct realtek_priv *priv, u32 index,
+				   const struct rtl8365mb_vlanmc *vlanmc)
+{
+	u16 data[4] = { 0 };
+	int ret;
+
+	data[0] |= FIELD_PREP(RTL8365MB_VLAN_MC_D0_MBR_MASK, vlanmc->member);
+	data[1] |= FIELD_PREP(RTL8365MB_VLAN_MC_D1_FID_MASK, vlanmc->fid);
+	data[2] |= FIELD_PREP(RTL8365MB_VLAN_MC_D2_METERIDX_MASK,
+			      vlanmc->meteridx);
+	data[2] |= FIELD_PREP(RTL8365MB_VLAN_MC_D2_ENVLANPOL_MASK,
+			      vlanmc->policing_en);
+	data[2] |=

drivers/net/dsa/realtek/rtl8365mb_vlan.c line 393

Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_vlan.c new file +10 -0
+		FIELD_PREP(RTL8365MB_VLAN_MC_D2_VBPRI_MASK, vlanmc->priority);
+	data[2] |= FIELD_PREP(RTL8365MB_VLAN_MC_D2_VBPEN_MASK,
+			      vlanmc->priority_en);
+	data[3] |= FIELD_PREP(RTL8365MB_VLAN_MC_D3_EVID_MASK, vlanmc->evid);
+
+	ret = regmap_bulk_write(priv->map, RTL8365MB_VLAN_MC_REG(index), &data,
+				RTL8365MB_VLAN_MC_ENTRY_SIZE);
+
+	return ret;
+}

[Medium]
Are rtl8365mb_vlan_mc_read() and rtl8365mb_vlan_mc_write() intended to be symmetric?

rtl8365mb_vlan_mc_read() only extracts member, fid, priority and evid from the hardware entry, while rtl8365mb_vlan_mc_write() writes member, fid, meteridx, policing_en (ENVLANPOL), priority, priority_en (VBPEN) and evid.

In rtl8365mb_vlan_mc_port_set() the pattern is to declare struct rtl8365mb_vlanmc vlanmc = {0}, call rtl8365mb_vlan_mc_read() when an entry exists, toggle only vlanmc.member, and write it back. Because priority_en, policing_en and meteridx are never populated by the read, the subsequent write unconditionally FIELD_PREPs them as zero.

Would it be safer to unpack VBPEN, ENVLANPOL and METERIDX in rtl8365mb_vlan_mc_read() as well, so that read/modify/write preserves those bits? The rtl8365mb_vlan_4k_read()/rtl8365mb_vlan_4k_write() pair already handles all fields symmetrically.

[ ... ]

Quoted 25 lines
drivers/net/dsa/realtek/rtl8365mb_vlan.c new file +25 -0
+static int rtl8365mb_vlan_mc_find(struct realtek_priv *priv, u16 vid,
+				  u8 *index, u8 *first_free)
+{
+	u32 vlan_entry_d3;
+	u8 vlanmc_idx;
+	u16 evid;
+	int ret;
+
+	*index = 0;
+	*first_free = 0;
+
+	/* look for existing entry or an empty one */
+	/* vlanmc index 0 is reserved as a neutral PVID value for standalone
+	 * ports. Traffic reaches the CPU via VLAN transparent mode.
+	 **/
+	for (vlanmc_idx = 1; vlanmc_idx <= RTL8365MB_VLAN_MCMAX; vlanmc_idx++) {
+		/* just read the 4th word, where the evid is */
+		ret = regmap_read(priv->map,
+				  RTL8365MB_VLAN_MC_REG(vlanmc_idx) + 3,
+				  &vlan_entry_d3);
+		if (ret)
+			return ret;
+
+		evid = FIELD_GET(RTL8365MB_VLAN_MC_D3_EVID_MASK, vlan_entry_d3);
+

drivers/net/dsa/realtek/rtl8365mb_vlan.c line 461

Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_vlan.c new file +10 -0
+		if (evid == vid) {
+			*index = vlanmc_idx;
+			return 0;
+		}
+
+		if (evid == 0x0 && *first_free < 1)
+			*first_free = vlanmc_idx;
+	}
+	return 0;
+}

[Low]
Does this function correctly disambiguate "VLAN 0 already programmed" from "this slot is empty"?

Both conditions use evid == 0 as their signal:

    if (evid == vid) {
        *index = vlanmc_idx;
        return 0;
    }

    if (evid == 0x0 && *first_free < 1)
        *first_free = vlanmc_idx;

When called with vid == 0, the first empty slot encountered satisfies evid == vid and is returned via *index as if it were a pre-existing match. rtl8365mb_vlan_mc_port_set() then treats it as an allocated entry and performs a read-modify-write that silently claims the slot.

The driver's entry points only reject vid > RTL8365MB_MAX_MC_VID; vid == 0 is not explicitly guarded. Would adding a "used" bit per MC slot (or an explicit vid == 0 check at the add/del entry points) remove this ambiguity?

[ ... ]

Quoted 23 lines
drivers/net/dsa/realtek/rtl8365mb_vlan.c new file +23 -0
+int rtl8365mb_vlan_pvid_port_add(struct dsa_switch *ds, int port,
+				 const struct switchdev_obj_port_vlan *vlan,
+				 struct netlink_ext_ack *extack)
+{
+	bool pvid = !!(vlan->flags & BRIDGE_VLAN_INFO_PVID);
+	enum rtl8365mb_frame_ingress accepted_frame;
+	struct realtek_priv *priv = ds->priv;
+	u8 _unused_first_free_idx;
+	u8 vlanmc_idx;
+	int ret;
+
+	if (!pvid)
+		return 0;
+
+	/* Find or allocate a new vlan MC and add port to members,
+	 * although members are not checked by the HW in vlan MC.
+	 */
+	ret = rtl8365mb_vlan_mc_port_set(ds, port, vlan, extack, true);
+	if (ret)
+		return ret;
+
+	/* look for existing entry */
+	ret = rtl8365mb_vlan_mc_find(priv, vlan->vid, &vlanmc_idx,

drivers/net/dsa/realtek/rtl8365mb_vlan.c line 727

Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_vlan.c new file +10 -0
+				     &_unused_first_free_idx);
+	if (ret) {
+		RTL_VLAN_ERR("Failed to find a VLAN MC table index");
+		goto undo_vlan_mc_port_set;
+	}
+
+	if (!vlanmc_idx) {
+		RTL_VLAN_ERR("VLAN should already exist in VLAN MC");
+		goto undo_vlan_mc_port_set;
+	}

[Medium]
Does this error path return success where it intended to return an error?

At the !vlanmc_idx branch, ret is 0 (rtl8365mb_vlan_mc_find() just succeeded), and the undo label ends with:

    undo_vlan_mc_port_set:
        (void)rtl8365mb_vlan_mc_port_set(ds, port, vlan, NULL, false);
        return ret;

So rtl8365mb_vlan_pvid_port_add() would return 0 after logging "VLAN should already exist in VLAN MC" and rolling back the MC allocation. rtl8365mb_port_vlan_add() then treats the operation as successful and leaves the VLAN4K membership in place, hiding the inconsistency from the DSA core.

Should this branch set ret to something like -EIO (or -ENOENT) before the goto, so the rollback is paired with a returned error?

Quoted 6 lines
drivers/net/dsa/realtek/rtl8365mb_vlan.c new file +6 -0
+
+	ret = rtl8365mb_vlan_port_set_pvid(priv, port, vlanmc_idx);
+	if (ret) {
+		RTL_VLAN_ERR("Failed to set port PVID");
+		goto undo_vlan_mc_port_set;
+	}

[ ... ]

maintainer
#15 lore raw

Re: [net-next PATCH v3 5/8] net: dsa: realtek: rtl8365mb: add VLAN support

In reply to Luiz Angelo Daros de Luca

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
Note: The format of this review has been altered to use a free-form summary of the findings rather than inline code quotes due to recitation restrictions.

commit 2401182ef461b16c2b0ffe98288b5a310381d0f7
Author: Alvin Šipraga <[email protected]>
Subject: net: dsa: realtek: rtl8365mb: add VLAN support

This commit adds VLAN support for the RTL8365MB switch family. It implements a dynamic allocation scheme to manage both the full 4096-entry VLAN4K table and the smaller 32-entry VLANMC table, keeping them synchronized and allocating VLANMC entries primarily for PVID assignment.

When configuring a port's PVID, rtl8365mb_vlan_pvid_port_add() allocates a new VLANMC entry. However, if a user changes a port's PVID, does the driver leak the old PVID's hardware slot? In rtl8365mb_vlan_pvid_port_del(), the driver reads the port's current PVID and returns early if it no longer matches the deleted VLAN. Since the hardware is strictly limited to 31 VLANMC entries, it seems repeatedly changing PVIDs could permanently exhaust the table and result in -E2BIG errors.

In rtl8365mb_vlan_mc_read(), the driver extracts the member, fid, priority, and evid fields, but appears to leave meteridx, policing_en, and priority_en uninitialized. When modifying an existing entry, rtl8365mb_vlan_mc_port_set() passes a partially zero-initialized stack structure to rtl8365mb_vlan_mc_write(). Does this unintentionally clear those fields in the hardware register during write-back?

The commit message states that the driver keeps membership configurations in sync when a corresponding entry exists in VLANMC. However, rtl8365mb_port_vlan_add() only calls the PVID add function if the pvid flag is true. If a port is added as a non-PVID member to a VLAN that already has an active MC entry, it seems the port is only added to the VLAN4K table. Does this leave the VLANMC member mask permanently desynchronized from the actual VLAN membership?

In rtl8365mb_port_vlan_filtering(), the driver iterates through available ports to set the transparent mode. If rtl8365mb_port_set_transparent() fails midway, the function returns immediately. A similar pattern exists in rtl8365mb_vlan_pvid_port_del(), where it modifies the port frame filter and PVID before calling rtl8365mb_vlan_mc_port_set(). Could these early returns leave the switch in an inconsistent state? It looks like they might benefit from proper error unwinding to revert the successful register modifications.

When searching for an empty VLANMC slot, rtl8365mb_vlan_mc_find() checks if the evid is 0x0. If a port is explicitly configured to use VLAN 0, perhaps for 802.1p priority tagging, could this active configuration be mistakenly identified as an empty slot? It seems this might cause a newly configured PVID to silently overwrite the active VLAN 0 configuration. Would checking the member mask alongside the evid help prevent this?

This isn't a bug, but in rtl8365mb_vlan_port_set_framefilter(), the accepted_frame argument is typed as an enum rtl8365mb_frame_ingress, but it is bit-shifted and reassigned to itself. Could this trigger static analyzer warnings about assigning a shifted integer back into an enum variable? Using a separate u32 variable for the shifted mask might be safer.

author maintainer
#16 lore raw

PATCH v3 6/8 net: dsa: realtek: rtl8365mb: add port_bridge_{join,leave}

In reply to Luiz Angelo Daros de Luca

From: Alvin Šipraga <[email protected]>

Implement hardware offloading of bridge functionality. This is achieved by using the per-port isolation registers, which contain a forwarding port mask. The switch will refuse to forward packets ingressed on a given port to a port which is not in its forwarding mask.

For each bridge that is offloaded, use the DSA-provided bridge number for the Extended Filtering ID (EFID). When using Independent VLAN Learning (IVL), the forwarding database is keyed with the tuple {VID, MAC, EFID}. There are 8 EFIDs available (0~7), but we reserve the default EFID 0 for standalone ports where learning is disabled. This fits nicely because DSA indexes the bridge number starting from 1.

Because of the limited number of EFIDs, we have to set the max_num_bridges property of our switch to 7: we can't offload more than that or we will fail to offer IVL as at least two bridges would end up having to share an EFID.

---
 drivers/net/dsa/realtek/realtek.h        |   5 ++
 drivers/net/dsa/realtek/rtl8365mb_main.c |  57 +++++++++++++++-
 drivers/net/dsa/realtek/rtl83xx.c        | 114 +++++++++++++++++++++++++++++++
 drivers/net/dsa/realtek/rtl83xx.h        |   7 ++
 4 files changed, 182 insertions(+), 1 deletion(-)
drivers/net/dsa/realtek/realtek.h +5 -0
index c03485a80d93..0942f534834d 100644
@@ -107,6 +107,11 @@ struct realtek_ops {
 	int	(*enable_vlan)(struct realtek_priv *priv, bool enable);
 	int	(*enable_vlan4k)(struct realtek_priv *priv, bool enable);
 	int	(*enable_port)(struct realtek_priv *priv, int port, bool enable);
+	int	(*port_add_isolation)(struct realtek_priv *priv, int port,
+				      u32 mask);
+	int	(*port_remove_isolation)(struct realtek_priv *priv, int port,
+					 u32 mask);
+	int	(*port_set_efid)(struct realtek_priv *priv, int port, u32 efid);
 	int	(*phy_read)(struct realtek_priv *priv, int phy, int regnum);
 	int	(*phy_write)(struct realtek_priv *priv, int phy, int regnum,
 			     u16 val);
drivers/net/dsa/realtek/rtl8365mb_main.c +56 -1

96 lines not on this page · raw message

drivers/net/dsa/realtek/rtl83xx.c +114 -0

120 lines not on this page · raw message

drivers/net/dsa/realtek/rtl83xx.h +7 -0
index c8a0ff8fd75e..2481a1aaa226 100644
@@ -21,4 +21,11 @@ void rtl83xx_remove(struct realtek_priv *priv);
 void rtl83xx_reset_assert(struct realtek_priv *priv);
 void rtl83xx_reset_deassert(struct realtek_priv *priv);
 
+int rtl83xx_port_bridge_join(struct dsa_switch *ds, int port,
+			     struct dsa_bridge bridge,
+			     bool *tx_forward_offload,
+			     struct netlink_ext_ack *extack);
+void rtl83xx_port_bridge_leave(struct dsa_switch *ds, int port,
+			       struct dsa_bridge bridge);
+
 #endif /* _RTL83XX_H */
Signature · 1 line
2.54.0
Reviewed-by on v3 6/8
#17 lore raw

Re: [net-next PATCH v3 6/8] net: dsa: realtek: rtl8365mb: add port_bridge_{join,leave}

Quoted 19 lines · Luiz Angelo Daros de Luca

From: Alvin Šipraga <[email protected]>

Implement hardware offloading of bridge functionality. This is achieved by using the per-port isolation registers, which contain a forwarding port mask. The switch will refuse to forward packets ingressed on a given port to a port which is not in its forwarding mask.

For each bridge that is offloaded, use the DSA-provided bridge number for the Extended Filtering ID (EFID). When using Independent VLAN Learning (IVL), the forwarding database is keyed with the tuple {VID, MAC, EFID}. There are 8 EFIDs available (0~7), but we reserve the default EFID 0 for standalone ports where learning is disabled. This fits nicely because DSA indexes the bridge number starting from 1.

Because of the limited number of EFIDs, we have to set the max_num_bridges property of our switch to 7: we can't offload more than that or we will fail to offer IVL as at least two bridges would end up having to share an EFID.

Quoted 4 lines
maintainer
#18 lore raw

Re: [net-next PATCH v3 6/8] net: dsa: realtek: rtl8365mb: add port_bridge_{join,leave}

In reply to Luiz Angelo Daros de Luca

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: dsa: realtek: rtl8365mb: add port_bridge_{join,leave}

This change implements hardware bridge offload for rtl8365mb by programming per-port isolation masks and an EFID derived from the DSA bridge number. The common helpers rtl83xx_port_bridge_join() and rtl83xx_port_bridge_leave() are added for reuse across realtek drivers.

Quoted 42 lines
drivers/net/dsa/realtek/rtl83xx.c +34 -0
index 2b9bd4462714..3ab91cd82743 100644
@@ -325,6 +325,120 @@ void rtl83xx_reset_deassert(struct realtek_priv *priv)
 	gpiod_set_value(priv->reset, false);
 }
 
+/**
+ * rtl83xx_port_bridge_join() - join a port to a bridge
+ * @ds: DSA switch instance
+ * @port: port index
+ * @bridge: bridge being joined
+ * @tx_forward_offload: if the switch can offload TX forwarding
+ * @extack: netlink extended ack for reporting errors
+ *
+ * This function handles joining a port to a bridge. It updates the port
+ * isolation masks and EFID.
+ *
+ * Context: Can sleep.
+ * Return: 0 on success, negative value for failure.
+ */
+int rtl83xx_port_bridge_join(struct dsa_switch *ds, int port,
+			     struct dsa_bridge bridge,
+			     bool *tx_forward_offload,
+			     struct netlink_ext_ack *extack)
+{
+	struct realtek_priv *priv = ds->priv;
+	struct dsa_port *dp;
+	u32 mask = 0;
+	int ret;
+
+	if (!priv->ops->port_add_isolation)
+		return -EOPNOTSUPP;
+
+	dev_dbg(priv->dev, "bridge %d join port %d\n", bridge.num, port);
+
+	/* Add this port to the isolation group of every other port
+	 * offloading this bridge.
+	 */
+	dsa_switch_for_each_user_port(dp, ds) {
+		/* Handle this port after */

drivers/net/dsa/realtek/rtl83xx.c void rtl83xx_reset_deassert(struct realtek_priv *priv) · line 371

Quoted 10 lines
drivers/net/dsa/realtek/rtl83xx.c +10 -0
+		if (dp->index == port)
+			continue;
+
+		/* Skip ports that are not in this bridge */
+		if (!dsa_port_offloads_bridge(dp, &bridge))
+			continue;
+
+		ret = priv->ops->port_add_isolation(priv, dp->index, BIT(port));
+		if (ret)
+			return ret;

[Medium]
If port_add_isolation() succeeds for one or more peer ports and then fails for a subsequent peer, this returns without undoing the earlier updates.

Looking at dsa_port_bridge_join() in net/dsa/port.c, the failure path goes to out_rollback which calls dsa_port_bridge_destroy() but does not dispatch DSA_NOTIFIER_BRIDGE_LEAVE, so rtl83xx_port_bridge_leave() is not invoked to revert the partial state.

Can peer ports end up retaining BIT(port) in their forwarding mask even though port never successfully joined the bridge, leaving frames from bridge members forwardable to a non-member?

drivers/net/dsa/realtek/rtl83xx.c void rtl83xx_reset_deassert(struct realtek_priv *priv) · line 379

Quoted 8 lines
drivers/net/dsa/realtek/rtl83xx.c +8 -0
+
+		mask |= BIT(dp->index);
+	}
+
+	/* Add those ports to the isolation group of this port */
+	ret = priv->ops->port_add_isolation(priv, port, mask);
+	if (ret)
+		return ret;

[Medium]
Similarly, if this call fails after peers have already been updated, the peers keep BIT(port) set without any rollback. Should this path walk the peers again and clear BIT(port) from the ones already modified before returning the error?

drivers/net/dsa/realtek/rtl83xx.c void rtl83xx_reset_deassert(struct realtek_priv *priv) · line 385

Quoted 6 lines
drivers/net/dsa/realtek/rtl83xx.c +6 -0
+
+	/* Use the bridge number as the EFID for this port */
+	if (priv->ops->port_set_efid) {
+		ret = priv->ops->port_set_efid(priv, port, bridge.num);
+		if (ret)
+			return ret;

[Medium]
If port_set_efid() fails here, both the peer ports' isolation masks and this port's isolation mask have already been updated to include the bridge membership, but the function returns an error as if the join did not happen. Should the isolation mask updates be reverted (and a plain EFID 0 restored where needed) before returning?

Quoted 6 lines
drivers/net/dsa/realtek/rtl83xx.c +6 -0
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_NS_GPL(rtl83xx_port_bridge_join, "REALTEK_DSA");
+

[ ... ]

maintainer
#19 lore raw

Re: [net-next PATCH v3 6/8] net: dsa: realtek: rtl8365mb: add port_bridge_{join,leave}

In reply to Luiz Angelo Daros de Luca

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: dsa: realtek: rtl8365mb: add port_bridge_{join,leave}

This commit implements hardware offloading of bridge functionality for the rtl8365mb switch by configuring per-port isolation registers and Extended Filtering IDs (EFIDs) for Independent VLAN Learning (IVL).

Quoted 4 lines
drivers/net/dsa/realtek/rtl83xx.c +0 -0
index 2b9bd4462714b..3ab91cd82743a 100644

[ ... ]

Quoted 6 lines
drivers/net/dsa/realtek/rtl83xx.c +2 -0
@@ -325,6 +325,120 @@ void rtl83xx_reset_deassert(struct realtek_priv *priv)
 	gpiod_set_value(priv->reset, false);
 }
 
+/**
+ * rtl83xx_port_bridge_join() - join a port to a bridge

[ ... ]

Quoted 20 lines
drivers/net/dsa/realtek/rtl83xx.c +20 -0
+int rtl83xx_port_bridge_join(struct dsa_switch *ds, int port,
+			     struct dsa_bridge bridge,
+			     bool *tx_forward_offload,
+			     struct netlink_ext_ack *extack)
+{
+	struct realtek_priv *priv = ds->priv;
+	struct dsa_port *dp;
+	u32 mask = 0;
+	int ret;
+
+	if (!priv->ops->port_add_isolation)
+		return -EOPNOTSUPP;
+
+	dev_dbg(priv->dev, "bridge %d join port %d\n", bridge.num, port);
+
+	/* Add this port to the isolation group of every other port
+	 * offloading this bridge.
+	 */
+	dsa_switch_for_each_user_port(dp, ds) {
+		/* Handle this port after */

drivers/net/dsa/realtek/rtl83xx.c void rtl83xx_reset_deassert(struct realtek_priv *priv) · line 371

Quoted 10 lines
drivers/net/dsa/realtek/rtl83xx.c +10 -0
+		if (dp->index == port)
+			continue;
+
+		/* Skip ports that are not in this bridge */
+		if (!dsa_port_offloads_bridge(dp, &bridge))
+			continue;
+
+		ret = priv->ops->port_add_isolation(priv, dp->index, BIT(port));
+		if (ret)
+			return ret;

What happens if this port_add_isolation() fails midway through the loop, or if any subsequent operations fail?

It looks like the function returns immediately without rolling back the isolation masks of the ports that were already successfully modified.

This would leave the hardware partially configured, allowing the modified bridge ports to forward traffic to the standalone port in hardware, while the DSA core aborted the join in software, leading to a network isolation regression.

Should there be an error unwinding path here that reverts the isolation masks for the previously configured ports using port_remove_isolation()?

Quoted 18 lines
drivers/net/dsa/realtek/rtl83xx.c +18 -0
+
+		mask |= BIT(dp->index);
+	}
+
+	/* Add those ports to the isolation group of this port */
+	ret = priv->ops->port_add_isolation(priv, port, mask);
+	if (ret)
+		return ret;
+
+	/* Use the bridge number as the EFID for this port */
+	if (priv->ops->port_set_efid) {
+		ret = priv->ops->port_set_efid(priv, port, bridge.num);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
author maintainer
#20 lore raw

PATCH v3 7/8 net: dsa: realtek: rtl8365mb: add FDB support

In reply to Luiz Angelo Daros de Luca

From: Alvin Šipraga <[email protected]>

Implement support for FDB and MDB management for the RTL8365MB series switches.

The hardware supports IVL by keying the forwarding database with the {VID, MAC, EFID} tuple. The Extended Filtering ID (EFID) is 3 bits wide, providing 8 unique filtering domains. This driver reserves EFID 0 for standalone ports, effectively limiting the hardware offload to a maximum of 7 bridges.

Introduce a mutex lock (l2_lock) to protect concurrent L2 table updates.

Add support for forwarding database operations, including unicast and multicast entry handling as well as fast aging support.

---
 drivers/net/dsa/realtek/Makefile         |   1 +
 drivers/net/dsa/realtek/realtek.h        |  29 ++
 drivers/net/dsa/realtek/rtl8365mb_l2.c   | 493 +++++++++++++++++++++++++++++++
 drivers/net/dsa/realtek/rtl8365mb_l2.h   |  32 ++
 drivers/net/dsa/realtek/rtl8365mb_main.c |  21 +-
 drivers/net/dsa/realtek/rtl83xx.c        | 268 +++++++++++++++++
 drivers/net/dsa/realtek/rtl83xx.h        |  16 +
 7 files changed, 859 insertions(+), 1 deletion(-)
drivers/net/dsa/realtek/Makefile +1 -0
index b7fc4e852fd8..6c329e046d0b 100644
@@ -19,3 +19,4 @@ obj-$(CONFIG_NET_DSA_REALTEK_RTL8365MB) += rtl8365mb.o
 rtl8365mb-objs := rtl8365mb_main.o \
 		  rtl8365mb_table.o \
 		  rtl8365mb_vlan.o \
+		  rtl8365mb_l2.o \
drivers/net/dsa/realtek/realtek.h +29 -0
index 0942f534834d..ef2d3ddfef60 100644
@@ -45,6 +45,12 @@ struct rtl8366_vlan_4k {
 	u8	fid;
 };
 
+struct realtek_fdb_entry {
+	u8 mac_addr[ETH_ALEN];
+	u16 vid;
+	bool is_static;
+};
+
 struct realtek_priv {
 	struct device		*dev;
 	struct reset_control    *reset_ctl;
@@ -54,6 +60,15 @@ struct realtek_priv {
 	struct regmap		*map;
 	struct regmap		*map_nolock;
 	struct mutex		map_lock;
+	/* l2_lock is used to prevent concurrent modifications of L2 table
+	 * entries while another function is reading it. l2_(add,del)_mc
+	 * is an example that first read current table entry and then
+	 * create/update it. l2_(add|del)_uc uses a single table op and,
+	 * internally, it might not need this lock. However, altering FDB
+	 * may still collide, as well as l2_flush, with fdb_dump iterating
+	 * over FDB.
+	 */
+	struct mutex		l2_lock;
 	struct mii_bus		*user_mii_bus;
 	struct mii_bus		*bus;
 	int			mdio_addr;
@@ -112,6 +127,19 @@ struct realtek_ops {
 	int	(*port_remove_isolation)(struct realtek_priv *priv, int port,
 					 u32 mask);
 	int	(*port_set_efid)(struct realtek_priv *priv, int port, u32 efid);
+	int	(*l2_add_uc)(struct realtek_priv *priv, int port,
+			     const unsigned char addr[ETH_ALEN],
+			     u16 efid, u16 vid);
+	int	(*l2_del_uc)(struct realtek_priv *priv, int port,
+			     const unsigned char addr[ETH_ALEN],
+			     u16 efid, u16 vid);
+	int	(*l2_get_next_uc)(struct realtek_priv *priv, u16 *addr, int port,
+				  struct realtek_fdb_entry *entry);
+	int	(*l2_add_mc)(struct realtek_priv *priv, int port,
+			     const unsigned char addr[ETH_ALEN], u16 vid);
+	int	(*l2_del_mc)(struct realtek_priv *priv, int port,
+			     const unsigned char addr[ETH_ALEN], u16 vid);
+	int	(*l2_flush)(struct realtek_priv *priv, int port, u16 vid);
 	int	(*phy_read)(struct realtek_priv *priv, int phy, int regnum);
 	int	(*phy_write)(struct realtek_priv *priv, int phy, int regnum,
 			     u16 val);
@@ -124,6 +152,7 @@ struct realtek_variant {
 	unsigned int clk_delay;
 	u8 cmd_read;
 	u8 cmd_write;
+	u16 l2_table_size;
 	size_t chip_data_sz;
 };
 
drivers/net/dsa/realtek/rtl8365mb_l2.c new file +493 -0

493 lines not on this page · raw message

drivers/net/dsa/realtek/rtl8365mb_l2.h new file +32 -0
new file mode 100644
index 000000000000..9470cf059ce5
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Forwarding and multicast database interface for the rtl8365mb switch family
+ *
+ * Copyright (C) 2022 Alvin Šipraga <[email protected]>
+ */
+
+#ifndef _REALTEK_RTL8365MB_L2_H
+#define _REALTEK_RTL8365MB_L2_H
+
+#include <linux/if_ether.h>
+#include <linux/types.h>
+
+#include "realtek.h"
+
+int rtl8365mb_l2_get_next_uc(struct realtek_priv *priv, u16 *addr, int port,
+			     struct realtek_fdb_entry *entry);
+int rtl8365mb_l2_add_uc(struct realtek_priv *priv, int port,
+			const unsigned char addr[static ETH_ALEN],
+			u16 efid, u16 vid);
+int rtl8365mb_l2_del_uc(struct realtek_priv *priv, int port,
+			const unsigned char addr[static ETH_ALEN],
+			u16 efid, u16 vid);
+int rtl8365mb_l2_flush(struct realtek_priv *priv, int port, u16 vid);
+
+int rtl8365mb_l2_add_mc(struct realtek_priv *priv, int port,
+			const unsigned char mac_addr[static ETH_ALEN],
+			u16 vid);
+int rtl8365mb_l2_del_mc(struct realtek_priv *priv, int port,
+			const unsigned char mac_addr[static ETH_ALEN],
+			u16 vid);
+
+#endif /* _REALTEK_RTL8365MB_L2_H */
drivers/net/dsa/realtek/rtl8365mb_main.c +20 -1
index 576bec52d863..1b8034311b17 100644
@@ -104,6 +104,7 @@
 #include "realtek-smi.h"
 #include "realtek-mdio.h"
 #include "rtl83xx.h"
+#include "rtl8365mb_l2.h"
 #include "rtl8365mb_vlan.h"
 
 /* Family-specific data and limits */
@@ -111,8 +112,9 @@
 #define RTL8365MB_NUM_PHYREGS		32
 #define RTL8365MB_PHYREGMAX		(RTL8365MB_NUM_PHYREGS - 1)
 #define RTL8365MB_MAX_NUM_PORTS		11
-#define RTL8365MB_MAX_NUM_EXTINTS	3
+/* Valid for the whole family except RTL8370B, which has 4160 entries. */
 #define RTL8365MB_LEARN_LIMIT_MAX	2112
+#define RTL8365MB_MAX_NUM_EXTINTS	3
 
 /* Chip identification registers */
 #define RTL8365MB_CHIP_ID_REG		0x1300
@@ -2229,6 +2231,8 @@ static int rtl8365mb_setup(struct dsa_switch *ds)
 	mb = priv->chip_data;
 	cpu = &mb->cpu;
 
+	mutex_init(&priv->l2_lock);
+
 	ret = rtl8365mb_reset_chip(priv);
 	if (ret) {
 		dev_err(priv->dev, "failed to reset chip: %pe\n",
@@ -2314,6 +2318,8 @@ static int rtl8365mb_setup(struct dsa_switch *ds)
 	if (ret)
 		goto out_teardown_irq;
 
+	ds->assisted_learning_on_cpu_port = true;
+	ds->fdb_isolation = true;
 	/* The EFID is 3 bits, but EFID 0 is reserved for standalone ports */
 	ds->max_num_bridges = FIELD_MAX(RTL8365MB_EFID_MASK);
 	ds->configure_vlan_while_not_filtering = true;
@@ -2442,6 +2448,12 @@ static const struct dsa_switch_ops rtl8365mb_switch_ops = {
 	.port_bridge_join = rtl83xx_port_bridge_join,
 	.port_bridge_leave = rtl83xx_port_bridge_leave,
 	.port_stp_state_set = rtl8365mb_port_stp_state_set,
+	.port_fast_age = rtl83xx_port_fast_age,
+	.port_fdb_add = rtl83xx_port_fdb_add,
+	.port_fdb_del = rtl83xx_port_fdb_del,
+	.port_fdb_dump = rtl83xx_port_fdb_dump,
+	.port_mdb_add = rtl83xx_port_mdb_add,
+	.port_mdb_del = rtl83xx_port_mdb_del,
 	.port_vlan_add = rtl8365mb_port_vlan_add,
 	.port_vlan_del = rtl8365mb_port_vlan_del,
 	.port_vlan_filtering = rtl8365mb_port_vlan_filtering,
@@ -2463,6 +2475,12 @@ static const struct realtek_ops rtl8365mb_ops = {
 	.port_add_isolation = rtl8365mb_port_add_isolation,
 	.port_remove_isolation = rtl8365mb_port_remove_isolation,
 	.port_set_efid = rtl8365mb_port_set_efid,
+	.l2_add_uc = rtl8365mb_l2_add_uc,
+	.l2_del_uc = rtl8365mb_l2_del_uc,
+	.l2_get_next_uc = rtl8365mb_l2_get_next_uc,
+	.l2_add_mc = rtl8365mb_l2_add_mc,
+	.l2_del_mc = rtl8365mb_l2_del_mc,
+	.l2_flush = rtl8365mb_l2_flush,
 	.phy_read = rtl8365mb_phy_read,
 	.phy_write = rtl8365mb_phy_write,
 };
@@ -2474,6 +2492,7 @@ const struct realtek_variant rtl8365mb_variant = {
 	.clk_delay = 10,
 	.cmd_read = 0xb9,
 	.cmd_write = 0xb8,
+	.l2_table_size = RTL8365MB_LEARN_LIMIT_MAX,
 	.chip_data_sz = sizeof(struct rtl8365mb),
 };
 
drivers/net/dsa/realtek/rtl83xx.c +268 -0

274 lines not on this page · raw message

drivers/net/dsa/realtek/rtl83xx.h +16 -0
index 2481a1aaa226..dcb819fe567f 100644
@@ -28,4 +28,20 @@ int rtl83xx_port_bridge_join(struct dsa_switch *ds, int port,
 void rtl83xx_port_bridge_leave(struct dsa_switch *ds, int port,
 			       struct dsa_bridge bridge);
 
+void rtl83xx_port_fast_age(struct dsa_switch *ds, int port);
+int rtl83xx_port_fdb_add(struct dsa_switch *ds, int port,
+			 const unsigned char *addr, u16 vid,
+			 struct dsa_db db);
+int rtl83xx_port_fdb_del(struct dsa_switch *ds, int port,
+			 const unsigned char *addr, u16 vid,
+			 struct dsa_db db);
+int rtl83xx_port_fdb_dump(struct dsa_switch *ds, int port,
+			  dsa_fdb_dump_cb_t *cb, void *data);
+int rtl83xx_port_mdb_add(struct dsa_switch *ds, int port,
+			 const struct switchdev_obj_port_mdb *mdb,
+			 struct dsa_db db);
+int rtl83xx_port_mdb_del(struct dsa_switch *ds, int port,
+			 const struct switchdev_obj_port_mdb *mdb,
+			 struct dsa_db db);
+
 #endif /* _RTL83XX_H */
Signature · 1 line
2.54.0
Reviewed-by on v3 7/8
#21 lore raw

Re: [net-next PATCH v3 7/8] net: dsa: realtek: rtl8365mb: add FDB support

Quoted 13 lines · Luiz Angelo Daros de Luca

From: Alvin Šipraga <[email protected]>

Implement support for FDB and MDB management for the RTL8365MB series switches.

The hardware supports IVL by keying the forwarding database with the {VID, MAC, EFID} tuple. The Extended Filtering ID (EFID) is 3 bits wide, providing 8 unique filtering domains. This driver reserves EFID 0 for standalone ports, effectively limiting the hardware offload to a maximum of 7 bridges.

Introduce a mutex lock (l2_lock) to protect concurrent L2 table updates.

Quoted 7 lines

Add support for forwarding database operations, including unicast and multicast entry handling as well as fast aging support.

maintainer
#22 lore raw

Re: [net-next PATCH v3 7/8] net: dsa: realtek: rtl8365mb: add FDB support

In reply to Luiz Angelo Daros de Luca

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
Subject: net: dsa: realtek: rtl8365mb: add FDB support

This patch adds unicast/multicast FDB offload to the rtl8365mb DSA driver, introduces a new l2_lock mutex and realtek_ops entry points for L2 table access, and wires up the DSA fdb/mdb/fast_age callbacks via shared rtl83xx_port_* helpers.

A few questions below, inline with the diff.

Quoted 5 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c new file +0 -0
new file mode 100644
index 000000000000..400e21dd4d03

[ ... ]

drivers/net/dsa/realtek/rtl8365mb_l2.c line 78

Quoted 8 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c new file +8 -0
+#define RTL8365MB_L2_FLUSH_CTRL2_REG		0x0A38
+#define   RTL8365MB_L2_FLUSH_CTRL2_MODE_MASK	GENMASK(1, 0)
+#define   RTL8365MB_L2_FLUSH_CTRL2_MODE_PORT	0
+#define   RTL8365MB_L2_FLUSH_CTRL2_MODE_PORT_VID 1
+#define   RTL8365MB_L2_FLUSH_CTRL2_MODE_PORT_FID 2
+#define   RTL8365MB_L2_FLUSH_CTRL2_TYPE_MASK	GENMASK(2, 2)
+#define   RTL8365MB_L2_FLUSH_CTRL2_TYPE_DYNAMIC	0
+#define   RTL8365MB_L2_FLUSH_CTRL2_TYPE_BOTH	0

[Low]
Is RTL8365MB_L2_FLUSH_CTRL2_TYPE_BOTH correct here? The TYPE field is GENMASK(2, 2), a single bit, so it admits exactly two values: 0 and 1. TYPE_DYNAMIC is 0 and TYPE_BOTH is also 0. Should TYPE_BOTH be 1? The symbol is not used today (l2_flush hardcodes TYPE_DYNAMIC), but a future user would silently program dynamic-only flushing.

[ ... ]

Quoted 2 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c new file +2 -0
+static void rtl8365mb_l2_data_to_mc(const u16 *data, struct rtl8365mb_l2_mc *mc)
+{

[ ... ]

Quoted 3 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c new file +3 -0
+	mc->member = FIELD_GET(RTL8365MB_L2_MC_MBR_MASK, data[4]) |
+		     (FIELD_GET(RTL8365MB_L2_MC_MBR_EXT1_MASK, data[3]) << 8) |
+		     (FIELD_GET(RTL8365MB_L2_MC_MBR_EXT2_MASK, data[5]) << 8);

[ ... ]

Quoted 4 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c new file +4 -0
+}
+
+static void rtl8365mb_l2_mc_to_data(const struct rtl8365mb_l2_mc *mc, u16 *data)
+{

[ ... ]

Quoted 2 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c new file +2 -0
+	data[3] |= FIELD_PREP(RTL8365MB_L2_MC_MBR_EXT1_MASK, mc->member >> 8);
+	data[4] |= FIELD_PREP(RTL8365MB_L2_MC_MBR_MASK, mc->member);

[ ... ]

drivers/net/dsa/realtek/rtl8365mb_l2.c

Quoted 2 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c new file +2 -0
+	data[5] |= FIELD_PREP(RTL8365MB_L2_MC_MBR_EXT2_MASK, mc->member >> 10);
+}

[High]
Do the encode and decode paths for MBR_EXT2 agree?

In rtl8365mb_l2_mc_to_data() EXT2 is written from bit 10 of mc->member:

    data[5] |= FIELD_PREP(RTL8365MB_L2_MC_MBR_EXT2_MASK, mc->member >> 10);

In rtl8365mb_l2_data_to_mc() the same EXT2 field is read back into bit 8:

    mc->member = FIELD_GET(RTL8365MB_L2_MC_MBR_MASK, data[4]) |
                 (FIELD_GET(RTL8365MB_L2_MC_MBR_EXT1_MASK, data[3]) << 8) |
                 (FIELD_GET(RTL8365MB_L2_MC_MBR_EXT2_MASK, data[5]) << 8);

RTL8365MB_MAX_NUM_PORTS is 11 and l2_flush() has an explicit port >= 8 path, so port 10 is a real value. If an MDB entry has port 10 in its member mask, won't the following read-modify-write in rtl8365mb_l2_add_mc()/rtl8365mb_l2_del_mc() lose membership of port 10 and spuriously add port 8? Should both sides use a consistent shift (either >> 10 / << 10, or >> 8 / << 8 for the matching bit)?

[ ... ]

Quoted 4 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c new file +4 -0
+int rtl8365mb_l2_del_mc(struct realtek_priv *priv, int port,
+			const unsigned char mac_addr[static ETH_ALEN],
+			u16 vid)
+{

[ ... ]

Quoted 9 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c new file +9 -0
+	rtl8365mb_l2_data_to_mc(data, &mc);
+	/* the port must be removed as a member */
+	mc.member &= ~BIT(port);
+	if (!mc.member) {
+		/* With no members, zero all non-key fields to delete the
+		 * entry. However is_static is everything else we wrote.
+		 * (and probably all that is needed by the HW)
+		 */
+		mc.is_static = 0;

drivers/net/dsa/realtek/rtl8365mb_l2.c line 493

Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c new file +10 -0
+	}
+	rtl8365mb_l2_mc_to_data(&mc, data);
+
+	/* update the existing entry. */
+	ret = rtl8365mb_table_query(priv, RTL8365MB_TABLE_L2,
+				    RTL8365MB_TABLE_OP_WRITE, &addr,
+				    0, 0,
+				    data, RTL8365MB_L2_ENTRY_SIZE);
+	return ret;
+}

[Medium]
Does this actually remove the entry from the hardware when the last port leaves the group? The unicast path uses age=0 as the documented delete signal; here the code writes the entry back with member=0 and is_static=0 based on the comment "probably all that is needed by the HW".

If the HW keeps the slot occupied with the same {MAC, VID, IVL} key, will the next add_mc() for the same group hit the OP_READ path and update in place on a stale entry? And can zero-member entries accumulate until the table returns -ENOSPC under MDB churn?

Quoted 1 line
drivers/net/dsa/realtek/rtl8365mb_main.c +0 -0

[ ... ]

drivers/net/dsa/realtek/rtl8365mb_main.c static int rtl8365mb_setup(struct dsa_switch *ds) · line 2325

Quoted 9 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +2 -0
@@ -2314,6 +2318,8 @@ static int rtl8365mb_setup(struct dsa_switch *ds)
 	if (ret)
 		goto out_teardown_irq;
 
+	ds->assisted_learning_on_cpu_port = true;
+	ds->fdb_isolation = true;
 	/* The EFID is 3 bits, but EFID 0 is reserved for standalone ports */
 	ds->max_num_bridges = FIELD_MAX(RTL8365MB_EFID_MASK);
 	ds->configure_vlan_while_not_filtering = true;

[Low, Medium]
Could the commit message mention that this patch also unconditionally turns on ds->assisted_learning_on_cpu_port? The log describes FDB/MDB offload and l2_lock, but the CPU-port auto-programming behavior change is not called out.

Regarding ds->fdb_isolation = true: include/net/dsa.h documents that this affects both .port_fdb_{add,del} and .port_mdb_{add,del}. The unicast path encodes db.bridge.num as EFID, but the MDB path (rtl83xx_port_mdb_add/del -> rtl8365mb_l2_add_mc/del_mc) does not pass db down, and rtl8365mb_l2_mc_to_data() has no EFID field — the MC key is only {MAC, VID, IVL}. If two bridges try to install the same (MAC, VID) group, won't they collide on one HW slot with OR'd member masks, breaking bridge-scoped MDB reference counting and conflict detection?

Quoted 1 line
drivers/net/dsa/realtek/rtl83xx.c +0 -0

[ ... ]

Quoted 9 lines
drivers/net/dsa/realtek/rtl83xx.c +9 -0
+int rtl83xx_port_fdb_add(struct dsa_switch *ds, int port,
+			 const unsigned char *addr, u16 vid,
+			 struct dsa_db db)
+{
+	struct realtek_priv *priv = ds->priv;
+	int efid;
+	int ret;
+
+	if (!priv->ops->l2_add_uc)

drivers/net/dsa/realtek/rtl83xx.c void rtl83xx_port_bridge_leave(struct dsa_switch *ds, int port, · line 506

Quoted 10 lines
drivers/net/dsa/realtek/rtl83xx.c +10 -0
+		return -EOPNOTSUPP;
+
+	if (db.type != DSA_DB_PORT && db.type != DSA_DB_BRIDGE)
+		return -EOPNOTSUPP;
+
+	/*
+	 * DSA_DB_BRIDGE ports use bridge number [1..N] as EFID, while
+	 * DSA_DB_PORT use the default EFID (0), not used by any bridge.
+	 */
+	efid = db.type == DSA_DB_BRIDGE ? db.bridge.num : 0;

[Low]
When db.type is DSA_DB_PORT, every standalone port ends up sharing EFID 0, so the HW key collapses to {VID, MAC} across all standalone ports. If DSA requests the same (MAC, VID) on two different standalone ports, won't rtl8365mb_l2_add_uc() silently rebind the existing entry to the last-added port (uc.port = port), without any collision detection?

[ ... ]

Quoted 17 lines
drivers/net/dsa/realtek/rtl83xx.c +17 -0
+int rtl83xx_port_fdb_dump(struct dsa_switch *ds, int port,
+			  dsa_fdb_dump_cb_t *cb, void *data)
+{
+	struct realtek_priv *priv = ds->priv;
+	struct realtek_fdb_entry entry;
+	u16 l2_table_size = priv->variant->l2_table_size;
+	u16 start_addr, addr = 0;
+	int ret = 0;
+
+	if (!priv->ops->l2_get_next_uc)
+		return -EOPNOTSUPP;
+	if (!l2_table_size) {
+		dev_warn_once(priv->dev, "l2_table_size not defined\n");
+		return -EOPNOTSUPP;
+	}
+
+	mutex_lock(&priv->l2_lock);

drivers/net/dsa/realtek/rtl83xx.c void rtl83xx_port_bridge_leave(struct dsa_switch *ds, int port, · line 608

Quoted 10 lines
drivers/net/dsa/realtek/rtl83xx.c +10 -0
+	while (true) {
+		start_addr = addr;
+
+		dev_dbg(priv->dev, "l2_get_next_uc, addr:%d, port:%d\n",
+			addr, port);
+		ret = priv->ops->l2_get_next_uc(priv, &addr, port, &entry);
+		dev_dbg(priv->dev,
+			"l2_get_next_uc addr:%d mac:%pM vid:%d static:%d ret:%pe\n",
+			addr, entry.mac_addr, entry.vid, entry.is_static,
+			ERR_PTR(ret));

[Low]
Should this dev_dbg() happen before ret is checked? entry is declared on the stack without initialization, and rtl8365mb_l2_get_next_uc() only writes to *entry on the success path. On the very first iteration when the walk returns -ENOENT (no FDB entries on this port), won't this print uninitialized stack contents via %pM / entry.vid / entry.is_static when dynamic debug is enabled?

drivers/net/dsa/realtek/rtl83xx.c void rtl83xx_port_bridge_leave(struct dsa_switch *ds, int port, · line 618

Quoted 10 lines
drivers/net/dsa/realtek/rtl83xx.c +10 -0
+
+		if (ret == -ENOENT)
+			break;
+		if (ret)
+			break;
+
+		if (addr < start_addr)
+			break;
+
+		cb(entry.mac_addr, entry.vid, entry.is_static, data);

[Medium]
Should cb's return value be checked and propagated here? dsa_user_port_fdb_do_dump() returns -EMSGSIZE when the netlink skb is full, and rtnl_fdb_dump() in net/core/rtnetlink.c relies on the driver bubbling that up:

    err = ...->port_fdb_dump(...);
    if (err == -EMSGSIZE)
        break;

Other DSA drivers (mv88e6xxx, qca8k, mt7530, ksz9477, sja1105, ...) stop immediately when cb returns non-zero. As written, the loop keeps calling cb() for every remaining HW entry, silently discarding -EMSGSIZE, and terminates with 0 or -ENOENT.

drivers/net/dsa/realtek/rtl83xx.c void rtl83xx_port_bridge_leave(struct dsa_switch *ds, int port, · line 624

Quoted 6 lines
drivers/net/dsa/realtek/rtl83xx.c +6 -0
+
+		addr++;
+
+		/* Avoid querying beyond the valid L2 table range. */
+		if (addr > l2_table_size)
+			break;

[Low]
Should this be addr >= l2_table_size? With l2_table_size = 2112, valid indices are 0..2111, so the current test allows one extra l2_get_next_uc() call at addr = 2112.

drivers/net/dsa/realtek/rtl83xx.c void rtl83xx_port_bridge_leave(struct dsa_switch *ds, int port, · line 518

Quoted 5 lines
drivers/net/dsa/realtek/rtl83xx.c +5 -0
+	}
+	mutex_unlock(&priv->l2_lock);
+
+	return ret;
+}

[Low]
On a normal end-of-walk, l2_get_next_uc() returns -ENOENT (the HIT bit cleared in rtl8365mb_table_query()) and the loop breaks with ret still set to -ENOENT. Shouldn't the successful-completion case return 0, matching the convention used by other DSA drivers? The kerneldoc above also states -ENOENT is returned at end-of-walk, which seems to describe the current (non-idiomatic) behavior rather than the intended one.

maintainer
#23 lore raw

Re: [net-next PATCH v3 7/8] net: dsa: realtek: rtl8365mb: add FDB support

In reply to Luiz Angelo Daros de Luca

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: dsa: realtek: rtl8365mb: add FDB support

Implement support for FDB and MDB management for the RTL8365MB series switches. Introduce a mutex lock (l2_lock) to protect concurrent L2 table updates. Add support for forwarding database operations, including unicast and multicast entry handling as well as fast aging support.

Quoted 3 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c new file +0 -0

[ ... ]

Quoted 2 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c new file +2 -0
+static void rtl8365mb_l2_data_to_uc(const u16 *data, struct rtl8365mb_l2_uc *uc)
+{

[ ... ]

drivers/net/dsa/realtek/rtl8365mb_l2.c line 141

Quoted 4 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c new file +4 -0
+	uc->key.efid = FIELD_GET(RTL8365MB_L2_UC_D4_EFID_MASK, data[4]);
+	uc->key.vid = FIELD_GET(RTL8365MB_L2_UC_D3_VID_MASK, data[3]);
+	uc->key.ivl = FIELD_GET(RTL8365MB_L2_UC_D3_IVL_MASK, data[3]);
+	uc->key.fid = FIELD_GET(RTL8365MB_L2_UC_D4_FID_MASK, data[4]);

Because vid and fid share the same union memory in struct rtl8365mb_l2_uc_key, does setting fid immediately after vid overwrite the 12-bit vid value with the 4-bit fid value?

When rtl83xx_port_fdb_dump() later passes entry.vid to the DSA core, it appears this sends the corrupted fid value instead, breaking VLAN visibility in userspace tools like bridge fdb show.

[ ... ]

Quoted 2 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c new file +2 -0
+static void rtl8365mb_l2_data_to_mc(const u16 *data, struct rtl8365mb_l2_mc *mc)
+{

[ ... ]

drivers/net/dsa/realtek/rtl8365mb_l2.c line 200

Quoted 4 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c new file +4 -0
+	mc->is_static = FIELD_GET(RTL8365MB_L2_MC_STATIC_MASK, data[5]);
+	mc->member = FIELD_GET(RTL8365MB_L2_MC_MBR_MASK, data[4]) |
+		     (FIELD_GET(RTL8365MB_L2_MC_MBR_EXT1_MASK, data[3]) << 8) |
+		     (FIELD_GET(RTL8365MB_L2_MC_MBR_EXT2_MASK, data[5]) << 8);

Could this shift for MBR_EXT2_MASK be incorrect?

It seems this shifts MBR_EXT2_MASK by 8 instead of 10. This causes the extended bit for port 10 to collide with the EXT1 bits (which are correctly shifted by 8) and leaves bit 10 perpetually unset.

In rtl8365mb_l2_mc_to_data(), the shift used is 10:

data[5] |= FIELD_PREP(RTL8365MB_L2_MC_MBR_EXT2_MASK, mc->member >> 10);

When the driver performs a read-modify-write operation on an existing multicast entry, this shift mismatch might cause port 10 to be silently dropped and port 8 to be erroneously altered.

[ ... ]

Quoted 4 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c new file +4 -0
+int rtl8365mb_l2_add_mc(struct realtek_priv *priv, int port,
+			const unsigned char mac_addr[static ETH_ALEN],
+			u16 vid)
+{

[ ... ]

Quoted 5 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c new file +5 -0
+	mc.member |= BIT(port);
+	mc.is_static = 1;
+	rtl8365mb_l2_mc_to_data(&mc, data);
+
+	/* First look for an existing entry (to get existing port members) */

drivers/net/dsa/realtek/rtl8365mb_l2.c line 425

Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c new file +10 -0
+	ret = rtl8365mb_table_query(priv, RTL8365MB_TABLE_L2,
+				    RTL8365MB_TABLE_OP_READ, &addr,
+				    RTL8365MB_TABLE_L2_METHOD_MAC, 0,
+				    data, RTL8365MB_L2_ENTRY_SIZE);
+	if (!ret) {
+		/* There is already an entry... */
+		rtl8365mb_l2_data_to_mc(data, &mc);
+		/* the port must be added as a member */
+		mc.member |= BIT(port);
+		rtl8365mb_l2_mc_to_data(&mc, data);

If an entry already exists in hardware, rtl8365mb_l2_data_to_mc() overwrites the mc struct with the hardware state. If the existing hardware entry was dynamically learned (e.g., via IGMP snooping), is_static is overwritten to 0.

Would this cause the software-requested static MDB entry to be subject to hardware aging?

Quoted 3 lines
drivers/net/dsa/realtek/rtl83xx.c +0 -0

[ ... ]

Quoted 3 lines
drivers/net/dsa/realtek/rtl83xx.c +3 -0
+int rtl83xx_port_fdb_dump(struct dsa_switch *ds, int port,
+			  dsa_fdb_dump_cb_t *cb, void *data)
+{

[ ... ]

Quoted 11 lines
drivers/net/dsa/realtek/rtl83xx.c +11 -0
+	mutex_lock(&priv->l2_lock);
+	while (true) {
+		start_addr = addr;
+
+		dev_dbg(priv->dev, "l2_get_next_uc, addr:%d, port:%d\n",
+			addr, port);
+		ret = priv->ops->l2_get_next_uc(priv, &addr, port, &entry);
+		dev_dbg(priv->dev,
+			"l2_get_next_uc addr:%d mac:%pM vid:%d static:%d ret:%pe\n",
+			addr, entry.mac_addr, entry.vid, entry.is_static,
+			ERR_PTR(ret));

drivers/net/dsa/realtek/rtl83xx.c void rtl83xx_port_bridge_leave(struct dsa_switch *ds, int port, · line 618

Quoted 10 lines
drivers/net/dsa/realtek/rtl83xx.c +10 -0
+
+		if (ret == -ENOENT)
+			break;
+		if (ret)
+			break;
+
+		if (addr < start_addr)
+			break;
+
+		cb(entry.mac_addr, entry.vid, entry.is_static, data);

If the netlink socket buffer fills up, the callback returns -EMSGSIZE. Since the return value of cb() is ignored here, does the loop fail to abort and continue iterating the hardware table?

This would result in the netlink subsystem receiving an incorrect success (or -ENOENT) instead of -EMSGSIZE, preventing it from resuming the dump later and silently truncating FDB lists.

drivers/net/dsa/realtek/rtl83xx.c void rtl83xx_port_bridge_leave(struct dsa_switch *ds, int port, · line 628

Quoted 10 lines
drivers/net/dsa/realtek/rtl83xx.c +10 -0
+
+		addr++;
+
+		/* Avoid querying beyond the valid L2 table range. */
+		if (addr > l2_table_size)
+			break;
+	}
+	mutex_unlock(&priv->l2_lock);
+
+	return ret;

When l2_get_next_uc() reaches the end of the hardware table, it returns -ENOENT.

Because ret is not reset to 0, this returns -ENOENT to the DSA core upon successful completion. Should this return 0 on success to adhere to the expected API contract?

#24 lore raw

Re: [net-next PATCH v3 7/8] net: dsa: realtek: rtl8365mb: add FDB support

Quoted 21 lines · Jakub Kicinski

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: dsa: realtek: rtl8365mb: add FDB support

Implement support for FDB and MDB management for the RTL8365MB series switches. Introduce a mutex lock (l2_lock) to protect concurrent L2 table updates. Add support for forwarding database operations, including unicast and multicast entry handling as well as fast aging support.

Quoted 3 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c new file +0 -0

[ ... ]

Quoted 2 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c new file +2 -0
+static void rtl8365mb_l2_data_to_uc(const u16 *data, struct rtl8365mb_l2_uc *uc)
+{

[ ... ]

Quoted 8 lines

drivers/net/dsa/realtek/rtl8365mb_l2.c line 141

Quoted 4 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c new file +4 -0
+	uc->key.efid = FIELD_GET(RTL8365MB_L2_UC_D4_EFID_MASK, data[4]);
+	uc->key.vid = FIELD_GET(RTL8365MB_L2_UC_D3_VID_MASK, data[3]);
+	uc->key.ivl = FIELD_GET(RTL8365MB_L2_UC_D3_IVL_MASK, data[3]);
+	uc->key.fid = FIELD_GET(RTL8365MB_L2_UC_D4_FID_MASK, data[4]);

Because vid and fid share the same union memory in struct rtl8365mb_l2_uc_key, does setting fid immediately after vid overwrite the 12-bit vid value with the 4-bit fid value?

Change code to:

uc->key.efid = FIELD_GET(RTL8365MB_L2_UC_D4_EFID_MASK, data[4]); uc->key.ivl = FIELD_GET(RTL8365MB_L2_UC_D3_IVL_MASK, data[3]);

if (uc->key.ivl)

	uc->key.vid = FIELD_GET(RTL8365MB_L2_UC_D3_VID_MASK, data[3]);
else
	uc->key.fid = FIELD_GET(RTL8365MB_L2_UC_D4_FID_MASK, data[4]);
author maintainer
#25 lore raw

Re: [net-next PATCH v3 7/8] net: dsa: realtek: rtl8365mb: add FDB support

Quoted 33 lines · Jakub Kicinski
Quoted 21 lines

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: dsa: realtek: rtl8365mb: add FDB support

Implement support for FDB and MDB management for the RTL8365MB series switches. Introduce a mutex lock (l2_lock) to protect concurrent L2 table updates. Add support for forwarding database operations, including unicast and multicast entry handling as well as fast aging support.

Quoted 3 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c new file +0 -0

[ ... ]

Quoted 2 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c new file +2 -0
+static void rtl8365mb_l2_data_to_uc(const u16 *data, struct rtl8365mb_l2_uc *uc)
+{

[ ... ]

Quoted 8 lines

drivers/net/dsa/realtek/rtl8365mb_l2.c line 141

Quoted 4 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c new file +4 -0
+    uc->key.efid = FIELD_GET(RTL8365MB_L2_UC_D4_EFID_MASK, data[4]);
+    uc->key.vid = FIELD_GET(RTL8365MB_L2_UC_D3_VID_MASK, data[3]);
+    uc->key.ivl = FIELD_GET(RTL8365MB_L2_UC_D3_IVL_MASK, data[3]);
+    uc->key.fid = FIELD_GET(RTL8365MB_L2_UC_D4_FID_MASK, data[4]);

Because vid and fid share the same union memory in struct rtl8365mb_l2_uc_key, does setting fid immediately after vid overwrite the 12-bit vid value with the 4-bit fid value?

Change code to:

Quoted 8 lines

uc->key.efid = FIELD_GET(RTL8365MB_L2_UC_D4_EFID_MASK, data[4]); uc->key.ivl = FIELD_GET(RTL8365MB_L2_UC_D3_IVL_MASK, data[3]);

if (uc->key.ivl)

        uc->key.vid = FIELD_GET(RTL8365MB_L2_UC_D3_VID_MASK, data[3]);
else
        uc->key.fid = FIELD_GET(RTL8365MB_L2_UC_D4_FID_MASK, data[4]);

Thanks Mieczyslaw,

It is a little more complicated than that. There are three FIDs in a Unicast L2 table:

RTL8367C:

        15  14  13  12  11  10   9   8   7   6   5   4   3   2   1   0
        +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
Index 0 |     MAC Octet [4] (High)      |      MAC Octet [5] (Low)      |
        +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
Index 1 |     MAC Octet [2] (High)      |      MAC Octet [3] (Low)      |
        +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
Index 2 |     MAC Octet [0] (High)      |      MAC Octet [1] (Low)      |
        +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
        | S |   | I | L |               |                               |
Index 3 | P | 0 | V | 3 |               CVID / FID                      |
        | A |   | L | L |               (12 bits)                       |
        +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
        | S |   |       |               | S |           |               |
Index 4 | A | A |  AGE  |      SPA      | A |    FID    |     EFID      |
        | B | U |       |    (bits 2-0) | E |           |               |
        +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
        |                               | N | F |       |       | D |
Index 5 |           (Reserved)          | O | W | (Res) |  PRI  | A |
        |                               | S | D |       |       | B |
        +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+

One shared between CVID/FID (word 3), and two FID/EFID in work 4.

For Unicast entries, the vendor code just store CVID/FID in a cvid unconditionally:

       pL2_entry->ivl       = l2Table.ivl_svl;
       pL2_entry->cvid      = l2Table.cvid_fid;
       pL2_entry->fid       = l2Table.fid;

Only for Multicast that it uses that condition:

       if(l2Table.ivl_svl == 1) /* IVL */
       {
           pL2_entry->cvid      = l2Table.cvid_fid;
           pL2_entry->fid       = 0;
       }
       else /* SVL*/
       {
           pL2_entry->cvid      = 0;
           pL2_entry->fid       = l2Table.cvid_fid;
       }

So, for unicast entries, we need dedicated fid/efid struct fields and that cvid_fid is always cvid.

According to the delete method, the Unicast key is (MAC, IVL/SVL, FID, EFID):

    /* fill key (MAC,FID) to get L2 entry */
   memcpy(l2Table.mac.octet, pMac->octet, ETHER_ADDR_LEN);
   l2Table.ivl_svl     = pL2_data->ivl;
   l2Table.cvid_fid    = pL2_data->cvid;
   l2Table.fid         = pL2_data->fid;
   l2Table.efid        = pL2_data->efid;

The union just makes sense for multicast. The multicast key is (MAC, IVL/SVL, VID/FID), without extra FID/EFID. The same delete code but for multicast is:

   /* fill key (MAC,FID) to get L2 entry */
   memcpy(l2Table.mac.octet, pMcastAddr->mac.octet, ETHER_ADDR_LEN);
   l2Table.ivl_svl     = pMcastAddr->ivl;
   if(pMcastAddr->ivl)
       l2Table.cvid_fid    = pMcastAddr->vid;
   else
       l2Table.cvid_fid    = pMcastAddr->fid;

And without FID/EFID, we can have collisions between different bridges.

I'm also preparing the code for other families (RTL8367,RTL8367B,RTL8367D) but they have their own problems. RTL8367 does not have a CVID field and RTL8367D does not have FID/EFID. It will take some time to figure out everything here. And more time to test it properly.

Regards,

Luiz

author maintainer
#26 lore raw

Re: [net-next PATCH v3 7/8] net: dsa: realtek: rtl8365mb: add FDB support

In reply to Luiz Angelo Daros de Luca

Hello,

I'm getting double calls to delete the same MDB entry:

[11725.824460] rtl8365mb-mdio mdio-bus:1d: rtl83xx_port_mdb_del:
port:2 addr:33:33:00:00:00:02 efid:1 vid:1 dbtype:2
[11725.836787] rtl8365mb-mdio mdio-bus:1d: l2_del_mc: found existing
addr=1376 member=0x4 igmpidx=0x0 static=1
[11725.848130] rtl8365mb-mdio mdio-bus:1d: rtl83xx_port_mdb_del:
port:2 addr:33:33:00:00:00:02 efid:1 vid:1 dbtype:2
[11725.859746] rtl8365mb-mdio mdio-bus:1d: mdb_del ERROR -ENOENT
[11725.865656] rtl8365mb-mdio mdio-bus:1d lan2: Failed to del Port
Multicast Database entry (object id=2) with error: -ENOENT (-2).
[11725.865656] Failure in updating the port's Multicast Database could lead to
[11725.865656] multicast forwarding issues.
[11725.865656]
[11725.890297] rtl8365mb-mdio mdio-bus:1d: rtl83xx_port_mdb_del:

port:2 addr:33:33:ff:cc:27:50 efid:1 vid:1 dbtype:2

(port 2(lan2) in this case is forming a bridge with port 3(lan1))

Is that normal?

I checked if 161ca59d39e9 from Vladimir Oltean was supposed to avoid that but it explicilty ignores user ports (and focus on CPU/link ports).

Quoted 12 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c new file +12 -0
+int rtl8365mb_l2_del_mc(struct realtek_priv *priv, int port,
+                       const unsigned char mac_addr[static ETH_ALEN],
+                       u16 vid)
+{
+       u16 data[RTL8365MB_L2_ENTRY_SIZE] = { 0 };
+       struct rtl8365mb_l2_mc mc = { 0 };
+       u16 addr;
+       int ret;
+
+       memcpy(mc.key.mac_addr, mac_addr, ETH_ALEN);
+       mc.key.vid = vid;
+       mc.key.ivl = true;

drivers/net/dsa/realtek/rtl8365mb_l2.c line 473

Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c new file +10 -0
+       rtl8365mb_l2_mc_to_data(&mc, data);
+
+       /* First look for an existing entry (to get existing port members) */
+       ret = rtl8365mb_table_query(priv, RTL8365MB_TABLE_L2,
+                                   RTL8365MB_TABLE_OP_READ, &addr,
+                                   RTL8365MB_TABLE_L2_METHOD_MAC, 0,
+                                   data, RTL8365MB_L2_ENTRY_SIZE);
+       if (ret)
+               /* Any error, including -ENOENT is unexpected */
+               return ret;

The easier solution would be to ignore -ENOENT here and just return 0 with a dbg message.
Some drivers I checked just do like that.

Quoted 22 lines
drivers/net/dsa/realtek/rtl8365mb_l2.c new file +20 -0
+
+       rtl8365mb_l2_data_to_mc(data, &mc);
+       /* the port must be removed as a member */
+       mc.member &= ~BIT(port);
+       if (!mc.member) {
+               /* With no members, zero all non-key fields to delete the
+                * entry. However is_static is everything else we wrote.
+                * (and probably all that is needed by the HW)
+                */
+               mc.is_static = 0;
+       }
+       rtl8365mb_l2_mc_to_data(&mc, data);
+
+       /* update the existing entry. */
+       ret = rtl8365mb_table_query(priv, RTL8365MB_TABLE_L2,
+                                   RTL8365MB_TABLE_OP_WRITE, &addr,
+                                   0, 0,
+                                   data, RTL8365MB_L2_ENTRY_SIZE);
+       return ret;
+}
@@ -2442,6 +2448,12 @@ static const struct dsa_switch_ops rtl8365mb_switch_ops = {

...

Quoted 1 line

+ .port_mdb_del = rtl83xx_port_mdb_del,

...

Quoted 27 lines
drivers/net/dsa/realtek/rtl83xx.c +27 -0
+/**
+ * rtl83xx_port_mdb_del() - delete a multicast database entry from a port database
+ * @ds: DSA switch instance
+ * @port: port index
+ * @mdb: multicast database entry to delete
+ * @db: database where the entry should be removed
+ *
+ * This function deletes a multicast database entry from the standalone port
+ * database or from a bridge database.
+ *
+ * Context: Can sleep.
+ * Return: 0 on success, negative value for failure.
+ */
+int rtl83xx_port_mdb_del(struct dsa_switch *ds, int port,
+                        const struct switchdev_obj_port_mdb *mdb,
+                        struct dsa_db db)
+{
+       struct realtek_priv *priv = ds->priv;
+       int ret;
+
+       if (!priv->ops->l2_del_mc)
+               return -EOPNOTSUPP;
+
+       if (db.type != DSA_DB_PORT && db.type != DSA_DB_BRIDGE)
+               return -EOPNOTSUPP;
+
+       dev_dbg(priv->dev, "mdb_del port %d addr %pM vid %d\n",

drivers/net/dsa/realtek/rtl83xx.c void rtl83xx_port_bridge_leave(struct dsa_switch *ds, int port, · line 707

Quoted 10 lines
drivers/net/dsa/realtek/rtl83xx.c +10 -0
+               port, mdb->addr, mdb->vid);
+
+       mutex_lock(&priv->l2_lock);
+       ret = priv->ops->l2_del_mc(priv, port, mdb->addr, mdb->vid);
+       mutex_unlock(&priv->l2_lock);
+
+       if (ret)
+               dev_err(priv->dev, "mdb_del ERROR %pe\n", ERR_PTR(ret));
+       return ret;
+}

Regards,

Luiz

author maintainer
#27 lore raw

PATCH v3 8/8 net: dsa: realtek: rtl8365mb: add bridge port flags

In reply to Luiz Angelo Daros de Luca

From: Alvin Šipraga <[email protected]>

Implement support for bridge port flags to control learning and flooding behavior. This patch maps hardware functionalities to the following bridge flags:

- BR_LEARNING
- BR_FLOOD
- BR_MCAST_FLOOD
- BR_BCAST_FLOOD

By default, all flooding types are enabled during port setup to ensure standard bridge behavior.

---
 drivers/net/dsa/realtek/realtek.h        |   8 +++
 drivers/net/dsa/realtek/rtl8365mb_main.c |  69 +++++++++++++++++++++
 drivers/net/dsa/realtek/rtl83xx.c        | 100 +++++++++++++++++++++++++++++++
 drivers/net/dsa/realtek/rtl83xx.h        |   4 ++
 4 files changed, 181 insertions(+)
drivers/net/dsa/realtek/realtek.h +8 -0
index ef2d3ddfef60..e78113f050dc 100644
@@ -140,6 +140,14 @@ struct realtek_ops {
 	int	(*l2_del_mc)(struct realtek_priv *priv, int port,
 			     const unsigned char addr[ETH_ALEN], u16 vid);
 	int	(*l2_flush)(struct realtek_priv *priv, int port, u16 vid);
+	int	(*port_set_learning)(struct realtek_priv *priv, int port,
+				     bool enable);
+	int	(*port_set_ucast_flood)(struct realtek_priv *priv, int port,
+					bool enable);
+	int	(*port_set_mcast_flood)(struct realtek_priv *priv, int port,
+					bool enable);
+	int	(*port_set_bcast_flood)(struct realtek_priv *priv, int port,
+					bool enable);
 	int	(*phy_read)(struct realtek_priv *priv, int phy, int regnum);
 	int	(*phy_write)(struct realtek_priv *priv, int phy, int regnum,
 			     u16 val);
drivers/net/dsa/realtek/rtl8365mb_main.c +69 -0

99 lines not on this page · raw message

drivers/net/dsa/realtek/rtl83xx.c +100 -0

112 lines not on this page · raw message

drivers/net/dsa/realtek/rtl83xx.h +4 -0
index dcb819fe567f..d86447121276 100644
@@ -27,6 +27,10 @@ int rtl83xx_port_bridge_join(struct dsa_switch *ds, int port,
 			     struct netlink_ext_ack *extack);
 void rtl83xx_port_bridge_leave(struct dsa_switch *ds, int port,
 			       struct dsa_bridge bridge);
+int rtl83xx_port_bridge_flags(struct dsa_switch *ds, int port,
+			      struct switchdev_brport_flags flags,
+			      struct netlink_ext_ack *extack);
+int rtl83xx_setup_port_flood_control(struct realtek_priv *priv, int port);
 
 void rtl83xx_port_fast_age(struct dsa_switch *ds, int port);
 int rtl83xx_port_fdb_add(struct dsa_switch *ds, int port,
Signature · 1 line
2.54.0
Reviewed-by on v3 8/8
#28 lore raw

Re: [net-next PATCH v3 8/8] net: dsa: realtek: rtl8365mb: add bridge port flags

Quoted 11 lines · Luiz Angelo Daros de Luca

From: Alvin Šipraga <[email protected]>

Implement support for bridge port flags to control learning and flooding behavior. This patch maps hardware functionalities to the following bridge flags:

- BR_LEARNING
- BR_FLOOD
- BR_MCAST_FLOOD
- BR_BCAST_FLOOD

Quoted 7 lines

By default, all flooding types are enabled during port setup to ensure standard bridge behavior.

maintainer
#29 lore raw

Re: [net-next PATCH v3 8/8] net: dsa: realtek: rtl8365mb: add bridge port flags

In reply to Luiz Angelo Daros de Luca

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: dsa: realtek: rtl8365mb: add bridge port flags

This patch adds support for bridge port flags (BR_LEARNING, BR_FLOOD, BR_MCAST_FLOOD, BR_BCAST_FLOOD) for rtl8365mb, adds new ops to the shared realtek_ops structure, and introduces rtl83xx_port_bridge_flags and rtl83xx_setup_port_flood_control helpers in the shared rtl83xx module. All flooding types are enabled by default at port setup time.

Quoted 9 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +1 -0
index 1b8034311b17..7c296f6a0a05 100644
@@ -304,6 +304,21 @@
 #define   RTL8365MB_MSTI_CTRL_PORT_STATE_MASK(_physport) \
 		(0x3 << RTL8365MB_MSTI_CTRL_PORT_STATE_OFFSET((_physport)))
 
+/* Unknown unicast DA flooding port mask */

drivers/net/dsa/realtek/rtl8365mb_main.c line 317

Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +10 -0
+#define RTL8365MB_UNKNOWN_UNICAST_FLOODING_PMASK_REG		0x0890
+#define   RTL8365MB_UNKNOWN_UNICAST_FLOODING_PMASK_MASK		0x07FF
+
+/* Unknown multicast DA flooding port mask */
+#define RTL8365MB_UNKNOWN_MULTICAST_FLOODING_PMASK_REG		0x0891
+#define   RTL8365MB_UNKNOWN_MULTICAST_FLOODING_PMASK_MASK	0x07FF
+
+/* Broadcast flooding port mask */
+#define RTL8365MB_UNKNOWN_BROADCAST_FLOODING_PMASK_REG		0x0892
+#define   RTL8365MB_UNKNOWN_BROADCAST_FLOODING_PMASK_MASK	0x07FF

[Low]
The three _PMASK_MASK defines (all 0x07FF) describing the 11-bit valid port-mask field are introduced here, but the helpers below pass BIT(port) directly as the regmap_update_bits mask and never reference these macros. There is also no BUILD_BUG_ON or bounds guard relating BIT(port) to the hardware field width.

Should these _MASK macros be dropped, or used in something like a BUILD_BUG_ON asserting BIT(RTL8365MB_MAX_NUM_PORTS - 1) fits within the valid field?

Quoted 22 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +15 -0
+
+#define RTL8365MB_SUPPORTED_BRIDGE_FLAGS \
+	    (BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD | BR_BCAST_FLOOD)
+
 /* Miscellaneous port configuration register, incl. VLAN egress mode */
 #define RTL8365MB_PORT_MISC_CFG_REG_BASE			0x000E
 #define RTL8365MB_PORT_MISC_CFG_REG(_p) \
@@ -1450,6 +1465,49 @@ static int rtl8365mb_port_set_learning(struct realtek_priv *priv, int port,
 			    enable ? RTL8365MB_LEARN_LIMIT_MAX : 0);
 }
 
+static int rtl8365mb_port_set_ucast_flood(struct realtek_priv *priv, int port,
+					  bool enable)
+{
+	/* Frames with unknown unicast DA will be flooded to a programmable
+	 * port mask that by default includes all ports. Add or remove
+	 * the specified port from this port mask accordingly.
+	 */
+	return regmap_update_bits(priv->map,
+				  RTL8365MB_UNKNOWN_UNICAST_FLOODING_PMASK_REG,
+				  BIT(port), enable ? BIT(port) : 0);
+}

[ ... ]

Quoted 4 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +4 -0
+static int rtl8365mb_port_pre_bridge_flags(struct dsa_switch *ds, int port,
+					   struct switchdev_brport_flags flags,
+					   struct netlink_ext_ack *extack)
+{

drivers/net/dsa/realtek/rtl8365mb_main.c static int rtl8365mb_port_set_learning(struct realtek_priv *priv, int port, · line 1509

Quoted 10 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +10 -0
+	struct realtek_priv *priv = ds->priv;
+
+	dev_dbg(priv->dev, "pre_bridge_flags port:%d flags:%lx supported:%lx",
+		port, flags.mask, RTL8365MB_SUPPORTED_BRIDGE_FLAGS);
+
+	if (flags.mask & ~RTL8365MB_SUPPORTED_BRIDGE_FLAGS)
+		return -EINVAL;
+
+	return 0;
+}

[Low]
Is there a reason the supported-mask lives in the per-chip driver while the apply path in the shared module independently decides support by NULL-checking each ops pointer at runtime?

The pre_bridge_flags contract in DSA/switchdev is that pre_bridge_flags must reject any flag that bridge_flags cannot later apply. Today rtl8365mb populates all four port_set_* ops and the hardcoded mask agrees, so there is no user-visible bug.

However, a future sibling driver reusing the exported rtl83xx_port_bridge_flags with a mismatched per-chip pre_bridge_flags could violate that contract, since rtl83xx_port_bridge_flags still returns -EOPNOTSUPP for a missing ops pointer:

drivers/net/dsa/realtek/rtl83xx.c:rtl83xx_port_bridge_flags() {
    ...
    if (flags.mask & BR_LEARNING) {
        if (!priv->ops->port_set_learning)
            return -EOPNOTSUPP;
        ...
    }
    ...
}

Would it be cleaner to have the shared module own a common pre_bridge_flags (or a helper that computes the supported mask from the ops vector) so the two paths cannot drift?

Quoted 4 lines
drivers/net/dsa/realtek/rtl8365mb_main.c +1 -0
+
 static int rtl8365mb_port_set_efid(struct realtek_priv *priv, int port,
 				   u32 efid)
 {

[ ... ]

maintainer
#30 lore raw
In reply to Luiz Angelo Daros de Luca
Quoted 7 lines · On Wed, 06 May 2026 23:58:17 -0300 Luiz Angelo Daros de Luca wrote:

This series introduces bridge offloading, FDB management, and VLAN support for the Realtek rtl8365mb DSA switch driver. The primary goal is to enable hardware frame forwarding between bridge ports, reducing CPU overhead and providing advanced features like VLAN and FDB isolation.

Some of these patches are based on original work by Alvin Šipraga, subsequently adapted and updated for the current net-next state.

Could you please look thru the feedback provided by AI bots? Most of it looks kinda subjective to me but hard for me to evaluate the HW details on patch 7, especially.

author maintainer
#31 lore raw
Quoted 1 line

Could you please look thru the feedback provided by AI bots?

Sure, Jakub.

I was expecting that, if it was an AI bot reviewing, I would receive an answer or something here. However, Simon Horman sent me the links. I'm already working on the fixes.

Quoted 2 lines

Most of it looks kinda subjective to me but hard for me to evaluate the HW details on patch 7, especially.

Yes, I'll have to rethink how to deal with the HW limitations. It'll take me some days.

Regards,

Luiz

maintainer
#32 lore raw
Quoted 2 lines · Luiz Angelo Daros de Luca

Yes, I'll have to rethink how to deal with the HW limitations. It'll take me some days.

Thanks a lot for your efforts Luiz!

I'm excited about the patches and look forward to making some RTL8366RB modifications on top once they get merged.

Yours,
Linus Walleij