[PATCH] bcm53xx: switch to the upstream DSA-based b53 driver

Rafał Miłecki zajec5 at gmail.com
Mon Oct 18 06:04:17 PDT 2021


From: Rafał Miłecki <rafal at milecki.pl>

1. Drop swconfig
2. Simplify network setup
3. Verify network config
4. Disable Buffalo WZR-900DHP for now - it misses ports definition

Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
---
 target/linux/bcm53xx/Makefile                 |  2 +-
 .../bcm53xx/base-files/etc/board.d/02_network | 80 +++----------------
 .../etc/uci-defaults/03_dsa_migrate           | 23 ++++++
 target/linux/bcm53xx/config-5.10              | 19 ++++-
 target/linux/bcm53xx/image/Makefile           |  1 +
 5 files changed, 49 insertions(+), 76 deletions(-)
 create mode 100644 target/linux/bcm53xx/base-files/etc/uci-defaults/03_dsa_migrate

diff --git a/target/linux/bcm53xx/Makefile b/target/linux/bcm53xx/Makefile
index 083f905096..921058d140 100644
--- a/target/linux/bcm53xx/Makefile
+++ b/target/linux/bcm53xx/Makefile
@@ -22,7 +22,7 @@ include $(INCLUDE_DIR)/target.mk
 
 KERNELNAME:=zImage dtbs
 
-DEFAULT_PACKAGES += swconfig nvram \
+DEFAULT_PACKAGES += nvram \
 	osafeloader oseama otrx \
 	kmod-gpio-button-hotplug \
 	kmod-leds-gpio
diff --git a/target/linux/bcm53xx/base-files/etc/board.d/02_network b/target/linux/bcm53xx/base-files/etc/board.d/02_network
index e02286027f..9308801b85 100644
--- a/target/linux/bcm53xx/base-files/etc/board.d/02_network
+++ b/target/linux/bcm53xx/base-files/etc/board.d/02_network
@@ -9,74 +9,24 @@ bcm53xx_setup_interfaces()
 {
 	local board="$1"
 
-	# On BCM4708 / BCM4709(4) there are 3 Ethernet interfaces connected to 3 switch
-	# ports. It's up to vendor which to use.
 	case "$board" in
-	tenda,ac9)
-		ucidef_add_switch "switch0" \
-			"1:lan" "2:lan" "3:lan" "4:lan" "8 at eth0" "0:wan" "5 at eth1"
-		;;
-	buffalo,wxr-1900dhp| \
-	buffalo,wzr-1750dhp)
-		ucidef_add_switch "switch0" \
-			"0:lan:1" "1:lan:2" "2:lan:3" "3:lan:4" "4:wan:5" "5 at eth0"
-		;;
-	dlink,dir-885l | \
-	netgear,r7900 | \
-	netgear,r8000 | \
-	netgear,r8500)
-		# NVRAM specifies port 8 (eth2) - unsupported by OpenWrt b53
-		# Use port 5 (eth0) as workaround
-		ucidef_add_switch "switch0" \
-			"0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5t at eth0"
+	asus,rt-ac87u)
+		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3" "wan"
 		;;
 	linksys,panamera)
-		ucidef_add_switch "switch1" \
-			"0:lan" "1:lan:7" "2:lan:4" "3:lan:8" "4:wan" "5t at eth0"
-		;;
-	luxul,abr-4500-v1|\
-	luxul,xbr-4500-v1)
-		ucidef_add_switch "switch0" \
-			"0:wan" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5 at eth0"
+		ucidef_set_interfaces_lan_wan "lan4 lan7 lan8 extsw" "wan"
 		;;
 	luxul,xap-1610-v1)
-		ucidef_add_switch "switch0" \
-			"0:lan" "1:lan" "5 at eth0"
-		ucidef_set_interface_lan "eth0.1" "dhcp"
+		ucidef_set_interface_lan "poe lan" "dhcp"
 		;;
-	luxul,xwr-3150-v1)
-		ucidef_add_switch "switch0" \
-			"0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "4:wan" "5 at eth0"
+	meraki,mr32)
+		ucidef_set_interface_lan "poe" "dhcp"
 		;;
 	phicomm,k3)
-		ucidef_add_switch "switch0" \
-			"0:lan" "1:lan" "2:lan" "3:wan" "5 at eth0"
+		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3" "wan"
 		;;
 	*)
-		# NVRAM entries may contain unsorted ports, e.g. Netgear R6250 uses
-		# vlan1ports=3 2 1 0 5*
-		# vlan2ports=4 5u
-		# and early Netgear R8000 was using
-		# vlan1ports=3 2 1 0 5 7 8*
-		# (the enclosing echo is needed to convert newline back to space)
-		vlan1ports="$(echo $(nvram get vlan1ports | tr " " "\n" | sort))"
-		vlan2ports="$(echo $(nvram get vlan2ports | tr " " "\n" | sort))"
-		if echo "$vlan1ports" | egrep -q "^1 2 3 4 5" && \
-		   echo "$vlan2ports" | egrep -q "^0 5"; then
-			ucidef_add_switch "switch0" \
-				"1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5t at eth0"
-		elif echo "$vlan1ports" | egrep -q "^1 2 3 5 7" && \
-		     echo "$vlan2ports" | egrep -q "^0 7"; then
-			ucidef_add_switch "switch0" \
-				"1:lan" "2:lan" "3:lan" "5:lan" "0:wan" "7t at eth1"
-		elif echo "$vlan1ports" | egrep -q "^0 1 2 3 5 7 8" && \
-		     echo "$vlan2ports" | egrep -q "^4 8"; then
-			ucidef_add_switch "switch0" \
-				"0:lan" "1:lan" "2:lan" "3:lan" "5:lan" "7:lan" "4:wan" "8t at eth2"
-		else
-			ucidef_add_switch "switch0" \
-				"0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5t at eth0"
-		fi
+		ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "wan"
 		;;
 	esac
 }
@@ -85,20 +35,8 @@ bcm53xx_setup_macs()
 {
 	local board="$1"
 
-	case "$board" in
-	dlink,dir-885l | \
-	linksys,panamera | \
-	netgear,r7900 | \
-	netgear,r8000 | \
-	netgear,r8500)
-		# As vendor doesn't use eth0 its MAC may be missing. Use one from eth2.
-		et2macaddr="$(nvram get et2macaddr)"
-		;;
-	esac
-
-	[ -n "$et2macaddr" ] && ucidef_set_interface_macaddr "lan" "$et2macaddr"
-
 	wan_macaddr="$(nvram get wan_hwaddr)"
+
 	case "$board" in
 	asus,rt-ac87u)
 		etXmacaddr=$(nvram get et1macaddr)
diff --git a/target/linux/bcm53xx/base-files/etc/uci-defaults/03_dsa_migrate b/target/linux/bcm53xx/base-files/etc/uci-defaults/03_dsa_migrate
new file mode 100644
index 0000000000..7350f57e5d
--- /dev/null
+++ b/target/linux/bcm53xx/base-files/etc/uci-defaults/03_dsa_migrate
@@ -0,0 +1,23 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+# Exit if network doesn't contain any swconfig section
+uci -q get network. at switch[0] > /dev/null || exit 0
+
+lan_proto="$(uci -q get network.lan.proto)"
+lan_ipaddr="$(uci -q get network.lan.ipaddr)"
+lan_netmask="$(uci -q get network.lan.netmask)"
+wan_proto="$(uci -q get network.wan.proto)"
+wan_ipaddr="$(uci -q get network.wan.ipaddr)"
+wan_netmask="$(uci -q get network.wan.netmask)"
+
+rm /etc/config/network
+config_generate
+
+uci -q batch <<-EOF
+	set network.lan.proto="$lan_proto"
+	set network.lan.ipaddr="$lan_ipaddr"
+	set network.lan.netmask="$lan_netmask"
+	set network.wan.proto="$wan_proto"
+	set network.wan.ipaddr="$wan_ipaddr"
+	set network.wan.netmask="$wan_netmask"
+EOF
diff --git a/target/linux/bcm53xx/config-5.10 b/target/linux/bcm53xx/config-5.10
index 9d98e812bd..73cccf1d3a 100644
--- a/target/linux/bcm53xx/config-5.10
+++ b/target/linux/bcm53xx/config-5.10
@@ -39,6 +39,12 @@ CONFIG_ARM_UNWIND=y
 CONFIG_ARM_VIRT_EXT=y
 CONFIG_ATAGS=y
 CONFIG_AUTO_ZRELADDR=y
+CONFIG_B53=y
+CONFIG_B53_MDIO_DRIVER=y
+# CONFIG_B53_MMAP_DRIVER is not set
+# CONFIG_B53_SERDES is not set
+# CONFIG_B53_SPI_DRIVER is not set
+CONFIG_B53_SRAB_DRIVER=y
 CONFIG_BCM47XX_NVRAM=y
 CONFIG_BCM47XX_SPROM=y
 CONFIG_BCM47XX_WDT=y
@@ -149,6 +155,7 @@ CONFIG_GPIOLIB_IRQCHIP=y
 CONFIG_GPIO_74X164=y
 CONFIG_GPIO_BCM_XGS_IPROC=y
 CONFIG_GPIO_GENERIC=y
+CONFIG_GRO_CELLS=y
 CONFIG_HANDLE_DOMAIN_IRQ=y
 CONFIG_HARDEN_BRANCH_PREDICTOR=y
 CONFIG_HARDIRQS_SW_RESEND=y
@@ -204,7 +211,14 @@ CONFIG_MTD_UBI_BLOCK=y
 CONFIG_MTD_UBI_WL_THRESHOLD=4096
 CONFIG_MUTEX_SPIN_ON_OWNER=y
 CONFIG_NEED_DMA_MAP_STATE=y
+CONFIG_NET_DEVLINK=y
+CONFIG_NET_DSA=y
+CONFIG_NET_DSA_TAG_BRCM=y
+CONFIG_NET_DSA_TAG_BRCM_COMMON=y
+CONFIG_NET_DSA_TAG_BRCM_LEGACY=y
+CONFIG_NET_DSA_TAG_BRCM_PREPEND=y
 CONFIG_NET_FLOW_LIMIT=y
+CONFIG_NET_SWITCHDEV=y
 CONFIG_NR_CPUS=2
 CONFIG_NVMEM=y
 CONFIG_NVMEM_BRCM_NVRAM=y
@@ -233,6 +247,7 @@ CONFIG_PCI_DOMAINS_GENERIC=y
 CONFIG_PERF_USE_VMALLOC=y
 CONFIG_PGTABLE_LEVELS=2
 CONFIG_PHYLIB=y
+CONFIG_PHYLINK=y
 # CONFIG_PHY_BCM_NS_USB2 is not set
 # CONFIG_PHY_BCM_NS_USB3 is not set
 # CONFIG_PHY_BCM_SR_PCIE is not set
@@ -267,10 +282,6 @@ CONFIG_SPI_MASTER=y
 CONFIG_SPI_MEM=y
 CONFIG_SRCU=y
 CONFIG_SWCONFIG=y
-CONFIG_SWCONFIG_B53=y
-CONFIG_SWCONFIG_B53_PHY_DRIVER=y
-CONFIG_SWCONFIG_B53_PHY_FIXUP=y
-CONFIG_SWCONFIG_B53_SRAB_DRIVER=y
 CONFIG_SWPHY=y
 CONFIG_SWP_EMULATE=y
 CONFIG_SYS_SUPPORTS_APM_EMULATION=y
diff --git a/target/linux/bcm53xx/image/Makefile b/target/linux/bcm53xx/image/Makefile
index 45355e1ec9..86f204f2cd 100644
--- a/target/linux/bcm53xx/image/Makefile
+++ b/target/linux/bcm53xx/image/Makefile
@@ -218,6 +218,7 @@ define Device/buffalo_wzr-900dhp
 	buffalo-enc WZR-900DHP2 $$(BUFFALO_TAG_VERSION) | \
 	buffalo-tag-dhp WZR-900DHP2 JP jp | buffalo-enc-tag | \
 	buffalo-dhp-image
+  BROKEN := y
 endef
 TARGET_DEVICES += buffalo_wzr-900dhp
 
-- 
2.31.1




More information about the openwrt-devel mailing list