Skip to contentSkip to conversation

net: dsa: rtl8366rb: support bridge offloading

RFC In review DENG Qingfang 5 participants 10 messages Feb 24, 2021 – Mar 3, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC 1/1 net: dsa: rtl8366rb: support bridge offloading

Use port isolation registers to configure bridge offloading. Remove the VLAN init, as we have proper CPU tag and bridge offloading support now.

---
This is not tested, as I don't have a RTL8366RB board. And I think there is potential race condition in port_bridge_{join,leave}.

 drivers/net/dsa/rtl8366rb.c | 73 ++++++++++++++++++++++++++++++++++---
 1 file changed, 67 insertions(+), 6 deletions(-)
drivers/net/dsa/rtl8366rb.c +67 -6
index a89093bc6c6a..9f6e2b361216 100644
@@ -300,6 +300,12 @@
 #define RTL8366RB_INTERRUPT_STATUS_REG	0x0442
 #define RTL8366RB_NUM_INTERRUPT		14 /* 0..13 */
 
+/* Port isolation registers */
+#define RTL8366RB_PORT_ISO_BASE		0x0F08
+#define RTL8366RB_PORT_ISO(pnum)	(RTL8366RB_PORT_ISO_BASE + (pnum))
+#define RTL8366RB_PORT_ISO_EN		BIT(0)
+#define RTL8366RB_PORT_ISO_PORTS_MASK	GENMASK(7, 1)
+
 /* bits 0..5 enable force when cleared */
 #define RTL8366RB_MAC_FORCE_CTRL_REG	0x0F11
 
@@ -835,6 +841,15 @@ static int rtl8366rb_setup(struct dsa_switch *ds)
 	if (ret)
 		return ret;
 
+	/* Isolate user ports */
+	for (i = 0; i < RTL8366RB_PORT_NUM_CPU; i++) {
+		ret = regmap_write(smi->map, RTL8366RB_PORT_ISO(i),
+				   RTL8366RB_PORT_ISO_EN |
+				   BIT(RTL8366RB_PORT_NUM_CPU + 1));
+		if (ret)
+			return ret;
+	}
+
 	/* Set up the "green ethernet" feature */
 	ret = rtl8366rb_jam_table(rtl8366rb_green_jam,
 				  ARRAY_SIZE(rtl8366rb_green_jam), smi, false);
@@ -963,10 +978,6 @@ static int rtl8366rb_setup(struct dsa_switch *ds)
 			return ret;
 	}
 
-	ret = rtl8366_init_vlan(smi);
-	if (ret)
-		return ret;
-
 	ret = rtl8366rb_setup_cascaded_irq(smi);
 	if (ret)
 		dev_info(smi->dev, "no interrupt support\n");
@@ -977,8 +988,6 @@ static int rtl8366rb_setup(struct dsa_switch *ds)
 		return -ENODEV;
 	}
 
-	ds->configure_vlan_while_not_filtering = false;
-
 	return 0;
 }
 
@@ -1127,6 +1136,56 @@ rtl8366rb_port_disable(struct dsa_switch *ds, int port)
 	rb8366rb_set_port_led(smi, port, false);
 }
 
+static int
+rtl8366rb_port_bridge_join(struct dsa_switch *ds, int port,
+			   struct net_device *bridge)
+{
+	struct realtek_smi *smi = ds->priv;
+	unsigned int port_bitmap = 0;
+	int ret, i;
+
+	for (i = 0; i < RTL8366RB_PORT_NUM_CPU; i++) {
+		if (i == port)
+			continue;
+		if (dsa_to_port(ds, i)->bridge_dev != bridge)
+			continue;
+		ret = regmap_update_bits(smi->map, RTL8366RB_PORT_ISO(i),
+					 0, BIT(port + 1));
+		if (ret)
+			return ret;
+
+		port_bitmap |= BIT(i);
+	}
+
+	return regmap_update_bits(smi->map, RTL8366RB_PORT_ISO(port),
+				  0, port_bitmap << 1);
+}
+
+static int
+rtl8366rb_port_bridge_leave(struct dsa_switch *ds, int port,
+			    struct net_device *bridge)
+{
+	struct realtek_smi *smi = ds->priv;
+	unsigned int port_bitmap = 0;
+	int ret, i;
+
+	for (i = 0; i < RTL8366RB_PORT_NUM_CPU; i++) {
+		if (i == port)
+			continue;
+		if (dsa_to_port(ds, i)->bridge_dev != bridge)
+			continue;
+		ret = regmap_update_bits(smi->map, RTL8366RB_PORT_ISO(i),
+					 BIT(port + 1), 0);
+		if (ret)
+			return ret;
+
+		port_bitmap |= BIT(i);
+	}
+
+	return regmap_update_bits(smi->map, RTL8366RB_PORT_ISO(port),
+				  port_bitmap << 1, 0);
+}
+
 static int rtl8366rb_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
 {
 	struct realtek_smi *smi = ds->priv;
@@ -1510,6 +1569,8 @@ static const struct dsa_switch_ops rtl8366rb_switch_ops = {
 	.get_strings = rtl8366_get_strings,
 	.get_ethtool_stats = rtl8366_get_ethtool_stats,
 	.get_sset_count = rtl8366_get_sset_count,
+	.port_bridge_join = rtl8366rb_port_bridge_join,
+	.port_bridge_leave = rtl8366rb_port_bridge_leave,
 	.port_vlan_filtering = rtl8366_vlan_filtering,
 	.port_vlan_add = rtl8366_vlan_add,
 	.port_vlan_del = rtl8366_vlan_del,
Signature · 1 line
2.25.1
#1 lore raw
reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # install powerpc64 cross compiling tool…

Hi DENG,

[FYI, it's a private test report for your RFC patch.] [auto build test ERROR on net-next/master]

url:    https://github.com/0day-ci/linux/commits/DENG-Qingfang/net-dsa-rtl8366rb-support-bridge-offloading/20210224-141416
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git d310ec03a34e92a77302edb804f7d68ee4f01ba0
config: powerpc64-randconfig-r033-20210223 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project f14a14dd2564703db02f80c00db8ae492b594f77)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install powerpc64 cross compiling tool for clang build
# apt-get install binutils-powerpc64-linux-gnu
# https://github.com/0day-ci/linux/commit/ef93701fa107a39c6ab6d43795c3a08d7f779bef
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review DENG-Qingfang/net-dsa-rtl8366rb-support-bridge-offloading/20210224-141416 git checkout ef93701fa107a39c6ab6d43795c3a08d7f779bef
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=powerpc64

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

>> drivers/net/dsa/rtl8366rb.c:1573:23: error: incompatible function pointer types initializing 'void (*)(struct dsa_switch *, int, struct net_device *)' with an expression of type 'int (struct dsa_switch *, int, struct net_device *)' [-Werror,-Wincompatible-function-pointer-types]

.port_bridge_leave = rtl8366rb_port_bridge_leave,
^~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

vim +1573 drivers/net/dsa/rtl8366rb.c

1563
1564 static const struct dsa_switch_ops rtl8366rb_switch_ops = {
1565 .get_tag_protocol = rtl8366_get_tag_protocol,
1566 .setup = rtl8366rb_setup,
1567 .phylink_mac_link_up = rtl8366rb_mac_link_up,
1568 .phylink_mac_link_down = rtl8366rb_mac_link_down,
1569 .get_strings = rtl8366_get_strings,
1570 .get_ethtool_stats = rtl8366_get_ethtool_stats,
1571 .get_sset_count = rtl8366_get_sset_count,
1572 .port_bridge_join = rtl8366rb_port_bridge_join,

> 1573		.port_bridge_leave = rtl8366rb_port_bridge_leave,

1574 .port_vlan_filtering = rtl8366_vlan_filtering,
1575 .port_vlan_add = rtl8366_vlan_add,
1576 .port_vlan_del = rtl8366_vlan_del,
1577 .port_enable = rtl8366rb_port_enable,
1578 .port_disable = rtl8366rb_port_disable,
1579 .port_change_mtu = rtl8366rb_change_mtu,
1580 .port_max_mtu = rtl8366rb_max_mtu,
1581 };
1582

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

Tested-by on v1 1/1
#2 lore raw
In reply to DENG Qingfang
Quoted 8 lines · DENG Qingfang

Use port isolation registers to configure bridge offloading. Remove the VLAN init, as we have proper CPU tag and bridge offloading support now.

---
This is not tested, as I don't have a RTL8366RB board. And I think there is potential race condition in port_bridge_{join,leave}.

Compilation failed for me like this:

../drivers/net/dsa/rtl8366rb.c:1573:23: error: initialization of 'void (*)(struct dsa_switch *, int, struct net_device *)' from incompatible pointer type 'int (*)(struct dsa_switch *, int, struct net_device *)' [-Werror=incompatible-pointer-types]
1573 | .port_bridge_leave = rtl8366rb_port_bridge_leave,

      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~

../drivers/net/dsa/rtl8366rb.c:1573:23: note: (near initialization for 'rtl8366rb_switch_ops.port_bridge_leave')

I fixed it like this:

drivers/net/dsa/rtl8366rb.c +0 -0
index e7abf846350d..0719fadadc3d 100644
@@ -1161,7 +1161,7 @@ rtl8366rb_port_bridge_join(struct dsa_switch

*ds, int port,

                                  0, port_bitmap << 1);

}

-static int
+static void
rtl8366rb_port_bridge_leave(struct dsa_switch *ds, int port,
struct net_device *bridge)
{
@@ -1176,14 +1176,17 @@ rtl8366rb_port_bridge_leave(struct dsa_switch *ds, int port,

                        continue;
                ret = regmap_update_bits(smi->map, RTL8366RB_PORT_ISO(i),
                                         BIT(port + 1), 0);

- if (ret)
- return ret;
+ if (ret) {
+ dev_err(smi->dev, "failed to leave port %d
from bridge\n",
+ port);
+ return;
+ }

                port_bitmap |= BIT(i);
        }

- return regmap_update_bits(smi->map, RTL8366RB_PORT_ISO(port),
- port_bitmap << 1, 0);
+ regmap_update_bits(smi->map, RTL8366RB_PORT_ISO(port),
+ port_bitmap << 1, 0);
}

After this it works like a charm.

Review

Quoted 3 lines
(quoted diff) +0 -3
-       ret = rtl8366_init_vlan(smi);
-       if (ret)
-               return ret;

I suppose we can delete that confused VLAN set-up after this.

Quoted 1 line

- ds->configure_vlan_while_not_filtering = false;

This is default true not IIUC so we should be good!

With my minor changes:

Yours,
Linus Walleij

#7 lore raw
In reply to DENG Qingfang

drivers/net/dsa/rtl8366rb.c line 307

Quoted 5 lines · DENG Qingfang
drivers/net/dsa/rtl8366rb.c +5 -0
+/* Port isolation registers */
+#define RTL8366RB_PORT_ISO_BASE                0x0F08
+#define RTL8366RB_PORT_ISO(pnum)       (RTL8366RB_PORT_ISO_BASE + (pnum))
+#define RTL8366RB_PORT_ISO_EN          BIT(0)
+#define RTL8366RB_PORT_ISO_PORTS_MASK  GENMASK(7, 1)

BTW where did you find this register? It's not in any of my vendor driver code dumps.

Curious!

Yours,
Linus Walleij

#4 lore raw
Quoted 7 lines · DENG Qingfang
Quoted 2 lines · Linus Walleij

With my minor changes:

How about using a mutex lock in port_bridge_{join,leave} ? In my opinion all functions that access multiple registers should be synchronized.

That's one way, in some cases the framework (DSA) serialize the accesses so I don't know if that already happens on a higher level? Since it is accessed over a slow bus we should go for mutex in that case indeed.

Yours,
Linus Walleij

#6 lore raw
In reply to Vladimir Oltean
Quoted 20 lines · Vladimir Oltean
Quoted 5 lines · Linus Walleij
Quoted 4 lines · DENG Qingfang
Quoted 2 lines · Linus Walleij

With my minor changes:

Quoted 8 lines
Quoted 3 lines

How about using a mutex lock in port_bridge_{join,leave} ? In my opinion all functions that access multiple registers should be synchronized.

That's one way, in some cases the framework (DSA) serialize the accesses so I don't know if that already happens on a higher level? Since it is accessed over a slow bus we should go for mutex in that case indeed.

DSA does not serialize this. The .port_bridge_join and .port_bridge_leave calls are initiated from the NETDEV_CHANGEUPPER net device event, which is called under rtnl_mutex (see call_netdevice_notifiers). This is pretty fundamental and I don't think it will ever change.

Quoted 4 lines

However, if you still want to add an extra layer of locking (with code paths that for some reason are not under the rtnl_mutex), then go ahead, I suppose. It will be challenging to make sure they do something that isn't snake oil, though.

Nah, just didn't know if was already in place.

I suggest Qingfang go with a driver-local mutex (it may already be needed in more places).

Yours,
Linus Walleij

maintainer
#5 lore raw
In reply to Linus Walleij
Quoted 5 lines · Linus Walleij
Quoted 4 lines · DENG Qingfang
Quoted 2 lines · Linus Walleij

With my minor changes:

Quoted 8 lines
Quoted 3 lines

How about using a mutex lock in port_bridge_{join,leave} ? In my opinion all functions that access multiple registers should be synchronized.

That's one way, in some cases the framework (DSA) serialize the accesses so I don't know if that already happens on a higher level? Since it is accessed over a slow bus we should go for mutex in that case indeed.

DSA does not serialize this. The .port_bridge_join and .port_bridge_leave calls are initiated from the NETDEV_CHANGEUPPER net device event, which is called under rtnl_mutex (see call_netdevice_notifiers). This is pretty fundamental and I don't think it will ever change.

However, if you still want to add an extra layer of locking (with code paths that for some reason are not under the rtnl_mutex), then go ahead, I suppose. It will be challenging to make sure they do something that isn't snake oil, though.

#9 lore raw
In reply to DENG Qingfang
Quoted 57 lines · DENG Qingfang

Use port isolation registers to configure bridge offloading. Remove the VLAN init, as we have proper CPU tag and bridge offloading support now.

---
This is not tested, as I don't have a RTL8366RB board. And I think there is potential race condition in port_bridge_{join,leave}.

 drivers/net/dsa/rtl8366rb.c | 73 ++++++++++++++++++++++++++++++++++---
 1 file changed, 67 insertions(+), 6 deletions(-)
drivers/net/dsa/rtl8366rb.c +15 -4
index a89093bc6c6a..9f6e2b361216 100644
@@ -300,6 +300,12 @@
 #define RTL8366RB_INTERRUPT_STATUS_REG	0x0442
 #define RTL8366RB_NUM_INTERRUPT		14 /* 0..13 */
 
+/* Port isolation registers */
+#define RTL8366RB_PORT_ISO_BASE		0x0F08
+#define RTL8366RB_PORT_ISO(pnum)	(RTL8366RB_PORT_ISO_BASE + (pnum))
+#define RTL8366RB_PORT_ISO_EN		BIT(0)
+#define RTL8366RB_PORT_ISO_PORTS_MASK	GENMASK(7, 1)
+
 /* bits 0..5 enable force when cleared */
 #define RTL8366RB_MAC_FORCE_CTRL_REG	0x0F11
 
@@ -835,6 +841,15 @@ static int rtl8366rb_setup(struct dsa_switch *ds)
 	if (ret)
 		return ret;
 
+	/* Isolate user ports */
+	for (i = 0; i < RTL8366RB_PORT_NUM_CPU; i++) {
+		ret = regmap_write(smi->map, RTL8366RB_PORT_ISO(i),
+				   RTL8366RB_PORT_ISO_EN |
+				   BIT(RTL8366RB_PORT_NUM_CPU + 1));
+		if (ret)
+			return ret;
+	}
+
 	/* Set up the "green ethernet" feature */
 	ret = rtl8366rb_jam_table(rtl8366rb_green_jam,
 				  ARRAY_SIZE(rtl8366rb_green_jam), smi, false);
@@ -963,10 +978,6 @@ static int rtl8366rb_setup(struct dsa_switch *ds)
 			return ret;
 	}
 
-	ret = rtl8366_init_vlan(smi);
-	if (ret)
-		return ret;
-
 	ret = rtl8366rb_setup_cascaded_irq(smi);
 	if (ret)
 		dev_info(smi->dev, "no interrupt support\n");

drivers/net/dsa/rtl8366rb.c static int rtl8366rb_setup(struct dsa_switch *ds) · line 980

Quoted 4 lines
drivers/net/dsa/rtl8366rb.c +0 -1
@@ -977,8 +988,6 @@ static int rtl8366rb_setup(struct dsa_switch *ds)
 		return -ENODEV;
 	}
 
-	ds->configure_vlan_while_not_filtering = false;

If you have a configuration with ports that are part of a bridge with VLAN filtering enabled, what happens to the standalone ports, are they a member of a default VLAN entry still?

Signature · 1 line
Florian