Skip to contentSkip to conversation

net: sparx5: add router legs for L3 routing offload

PATCH Applied Jens Emil Schulz Østergaard 2 participants 5 messages Nov 25 – Dec 3

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

v4 cover net: sparx5: add router legs for L3 routing offload

This is the first series adding L3 unicast routing offload for IPv4 and IPv6 to Sparx5 and LAN969x. It adds the routing registers and the router legs, the hardware interfaces where routing happens. No route is offloaded yet. Routing is enabled in the chip, but with no LPM rule a routed frame misses the lookup and is redirected to the CPU, so the kernel keeps routing every frame in software.

The chips only route in VLAN aware mode. A router leg is created for a direct VLAN upper of the offloaded bridge when it gets its first address, provided the upper qualifies for hardware routing: a non-zero vid, the bridge VLAN protocol, the bridge MAC and no master. Any other configuration is routed in software as usual.

Patch 1 adds the register macros for the L3 routing blocks.

Patch 2 adds the router legs, their lifecycle on address events, the global leg base MAC and the hardware enable sequence.

Patch 3 keeps the legs in sync with the bridge. A transition that would leave the hardware and kernel routing differently drops the leg instead of being refused, and the leg is recreated once the upper qualifies. It also follows bridge MAC and vid changes and the upper going down, and recreates the legs when a switch port joins the bridge again.

The plan for future series building on this one:

2: track FIB entries and trap them to the CPU, with the LPM VCAP 3: main and local table arbitration, FIB rule refusal and neighbour
host routes
4: forwarding through a single nexthop, ECMP and blackhole routes 5: routes through nexthop objects

The Super VCAP shared-register race reported on v1 is fixed separately by commit d7a8d500d7e4 ("net: microchip: vcap: fix races on the shared Super VCAP block"), which is now in net-next.

---
Changes in v4:
- Queue the leg reconcile when the first switch port joins the bridge,
so it runs after the bridge MAC is recalculated.
- Queue the leg reconcile when a vlan upper of the bridge comes up, so a
leg lost while the upper was down is created again.
- Tear the router down before the switchdev and netdevice notifiers on
remove.
- Publish the router only after its workqueue is set up.
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Split the series. The router code is now rebuilt as smaller series.
This series keeps the registers and the router legs. The VCAP
preparation moves to the second series.
- Tighten which device may carry a router leg: a direct VLAN upper of
the bridge whose ports are offloaded, without a master of its own,
with a non-zero vid, the bridge VLAN protocol and the bridge MAC.
- Follow the transitions that would leave the chip and kernel out of
sync: enslaving a leg to any master, changing its MAC, and disabling vlan_filtering or changing the VLAN protocol on its bridge drop the
leg, which is created again when the upper qualifies.
- Destroy a leg created from the address validator when the address add
fails afterwards, and handle IPv6 address removal from a work embedded
in the router rather than one allocated per event.
- Keep addresses when a leg cannot be created, and route that upper
in software.
- Disable a leg as an ingress router leg while its upper is down or the
bridge does not carry its vid.
- Flush the legs of a bridge when its last switch port leaves and
recreate them on rejoin.
- Program the leg base MAC from the bridge MAC when a leg is created,
not only when the bridge MAC changes.
- Enable unicast routing only on the switch ports, and restore the
routing registers when the router is torn down.
- Carry on without offload when the router cannot initialise, rather
than failing the probe, and skip the router without CONFIG_VLAN_8021Q.
- Remove the blackhole leg and the IPv6 link-local trap.
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Reworked neighbour lifetime: anchor neighbours to the router leg
instead of the most-specific covering FIB entry (matching
mlxsw/prestera). Fixes a neighbour-entry leak (memory + VMID + host
VCAP rule + netdev reference) and lets the software LPM be removed
entirely.
- Fixed a heap overflow in the fib6 nexthop prune path.
- Fixed a leak on the router_init() error path.
- Hardening: netns filtering and offload-ownership checks on the global
notifiers, and a NETDEV_UNREGISTER leg-teardown backstop.
- Fixed do_div() misuse on a 32-bit value. Added the missing RCU
annotation on in_dev->ifa_list.
- Zero-initialise the actionfield data in vcap_rule_mod_action_bit().
- Updated the sparx5_router.c header comment to describe the
leg-anchored model.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Jens Emil Schulz Østergaard (3):
net: sparx5: add l3 routing registers
net: sparx5: add L3 router legs
net: sparx5: keep router legs in sync with the bridge

 drivers/net/ethernet/microchip/sparx5/Makefile     |   2 +-
 .../ethernet/microchip/sparx5/lan969x/lan969x.c    |   1 +
 .../microchip/sparx5/lan969x/lan969x_regs.c        |  11 +
 .../net/ethernet/microchip/sparx5/sparx5_main.c    |  13 +-
 .../net/ethernet/microchip/sparx5/sparx5_main.h    |  36 +
 .../ethernet/microchip/sparx5/sparx5_main_regs.h   | 528 ++++++++++++
 .../net/ethernet/microchip/sparx5/sparx5_regs.c    |  11 +
 .../net/ethernet/microchip/sparx5/sparx5_regs.h    |  11 +
 .../net/ethernet/microchip/sparx5/sparx5_router.c  | 920 +++++++++++++++++++++
 .../ethernet/microchip/sparx5/sparx5_switchdev.c   |  30 +-
 .../net/ethernet/microchip/sparx5/sparx5_vlan.c    |   2 +
 11 files changed, 1560 insertions(+), 5 deletions(-)

---
base-commit: 612848d37e68b858e15815175f1c5e609e09d719
change-id: 20260210-sparx5_l3_routing-962458e4d3da

Best regards,

Signature · 1 line
Jens Emil Schulz Østergaard <[email protected]>
#1 lore raw

PATCH v4 1/3 net: sparx5: add l3 routing registers

Add the registers used to configure L3 routing, on both sparx5 and
lan969x: the common routing and router leg configuration of ANA_L3, its per VLAN and per VMID router leg configuration and its ARP table, the router leg MAC and per VMID router leg control of REW, the router leg MAC of EACL, and the VCAP_S2_MISC_CTRL register of ANA_ACL.

---
 .../microchip/sparx5/lan969x/lan969x_regs.c        |  11 +
 .../ethernet/microchip/sparx5/sparx5_main_regs.h   | 528 +++++++++++++++++++++
 .../net/ethernet/microchip/sparx5/sparx5_regs.c    |  11 +
 .../net/ethernet/microchip/sparx5/sparx5_regs.h    |  11 +
 4 files changed, 561 insertions(+)
drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_regs.c +11 -0
index 5650550d4294..6858772c964f 100644
@@ -82,12 +82,15 @@ const unsigned int lan969x_gaddr[GADDR_LAST] = {
 	[GA_ANA_CL_COMMON] = 87040,
 	[GA_ANA_L2_COMMON] = 561928,
 	[GA_ANA_L3_COMMON] = 370752,
+	[GA_ANA_L3_VMID] = 360448,
+	[GA_ANA_L3_ARP] = 294912,
 	[GA_ANA_L3_VLAN_ARP_L3MC_STICKY] = 368580,
 	[GA_ASM_CFG] = 18304,
 	[GA_ASM_PFC_TIMER_CFG] = 15568,
 	[GA_ASM_LBK_WM_CFG] = 15596,
 	[GA_ASM_LBK_MISC_CFG] = 15608,
 	[GA_ASM_RAM_CTRL] = 15684,
+	[GA_EACL_COMMON] = 37408,
 	[GA_EACL_ES2_KEY_SELECT_PROFILE] = 36864,
 	[GA_EACL_CNT_TBL] = 30720,
 	[GA_EACL_POL_CFG] = 38400,
@@ -111,6 +114,7 @@ const unsigned int lan969x_gaddr[GADDR_LAST] = {
 	[GA_QSYS_RAM_CTRL] = 2204,
 	[GA_REW_COMMON] = 98304,
 	[GA_REW_PORT] = 49152,
+	[GA_REW_VMID] = 96768,
 	[GA_REW_VOE_PORT_LM_CNT] = 90112,
 	[GA_REW_RAM_CTRL] = 93992,
 	[GA_VOP_RAM_CTRL] = 16368,
@@ -133,6 +137,8 @@ const unsigned int lan969x_gcnt[GCNT_LAST] = {
 	[GC_ANA_L2_ISDX_LIMIT] = 256,
 	[GC_ANA_L2_ISDX] = 1024,
 	[GC_ANA_L3_VLAN] = 4608,
+	[GC_ANA_L3_VMID] = 127,
+	[GC_ANA_L3_ARP] = 1024,
 	[GC_ASM_DEV_STATISTICS] = 30,
 	[GC_EACL_ES2_KEY_SELECT_PROFILE] = 68,
 	[GC_EACL_CNT_TBL] = 512,
@@ -143,6 +149,7 @@ const unsigned int lan969x_gcnt[GCNT_LAST] = {
 	[GC_PTP_PTP_PINS] = 8,
 	[GC_PTP_PHASE_DETECTOR_CTRL] = 8,
 	[GC_REW_PORT] = 35,
+	[GC_REW_VMID] = 127,
 	[GC_REW_VOE_PORT_LM_CNT] = 240,
 };
 
@@ -202,7 +209,10 @@ const unsigned int lan969x_fsize[FSIZE_LAST] = {
 	[FW_ANA_L2_AUTO_LRN_CFG_AUTO_LRN_ENA] = 30,
 	[FW_ANA_L2_DLB_CFG_DLB_IDX] = 9,
 	[FW_ANA_L2_TSN_CFG_TSN_SFID] = 8,
+	[FW_ANA_L3_L3_UC_ENA_L3_UC_ENA] = 30,
+	[FW_ANA_L3_VMID_CFG_VMID] = 7,
 	[FW_ANA_L3_VLAN_MASK_CFG_VLAN_PORT_MASK] = 30,
+	[FW_ANA_L3_ARP_CFG_0_ARP_VMID] = 7,
 	[FW_FDMA_CH_CFG_CH_DCB_DB_CNT] = 2,
 	[FW_GCB_HW_SGPIO_TO_SD_MAP_CFG_SGPIO_TO_SD_SEL] = 7,
 	[FW_HSCH_SE_CFG_SE_DWRR_CNT] = 5,
@@ -234,6 +244,7 @@ const unsigned int lan969x_fsize[FSIZE_LAST] = {
 	[FW_QSYS_ATOP_ATOP] = 11,
 	[FW_QSYS_ATOP_TOT_CFG_ATOP_TOT] = 11,
 	[FW_REW_RTAG_ETAG_CTRL_IPE_TBL] = 6,
+	[FW_REW_RLEG_CTRL_DECAP_IRLEG] = 7,
 	[FW_XQS_STAT_CFG_STAT_VIEW] = 10,
 	[FW_XQS_QLIMIT_SHR_TOP_CFG_QLIMIT_SHR_TOP] = 14,
 	[FW_XQS_QLIMIT_SHR_ATOP_CFG_QLIMIT_SHR_ATOP] = 14,
drivers/net/ethernet/microchip/sparx5/sparx5_main_regs.h +528 -0

564 lines not on this page · raw message

drivers/net/ethernet/microchip/sparx5/sparx5_regs.c +11 -0
index ce5f0bbf0e65..3a382603cb01 100644
@@ -82,12 +82,15 @@ const unsigned int sparx5_gaddr[GADDR_LAST] = {
 	[GA_ANA_CL_COMMON] = 166912,
 	[GA_ANA_L2_COMMON] = 566024,
 	[GA_ANA_L3_COMMON] = 493632,
+	[GA_ANA_L3_VMID] = 458752,
+	[GA_ANA_L3_ARP] = 327680,
 	[GA_ANA_L3_VLAN_ARP_L3MC_STICKY] = 491460,
 	[GA_ASM_CFG] = 33280,
 	[GA_ASM_PFC_TIMER_CFG] = 34716,
 	[GA_ASM_LBK_WM_CFG] = 34744,
 	[GA_ASM_LBK_MISC_CFG] = 34756,
 	[GA_ASM_RAM_CTRL] = 34832,
+	[GA_EACL_COMMON] = 118480,
 	[GA_EACL_ES2_KEY_SELECT_PROFILE] = 149504,
 	[GA_EACL_CNT_TBL] = 122880,
 	[GA_EACL_POL_CFG] = 150608,
@@ -111,6 +114,7 @@ const unsigned int sparx5_gaddr[GADDR_LAST] = {
 	[GA_QSYS_RAM_CTRL] = 2344,
 	[GA_REW_COMMON] = 387264,
 	[GA_REW_PORT] = 360448,
+	[GA_REW_VMID] = 389120,
 	[GA_REW_VOE_PORT_LM_CNT] = 393216,
 	[GA_REW_RAM_CTRL] = 378696,
 	[GA_VOP_RAM_CTRL] = 279176,
@@ -133,6 +137,8 @@ const unsigned int sparx5_gcnt[GCNT_LAST] = {
 	[GC_ANA_L2_ISDX_LIMIT] = 1536,
 	[GC_ANA_L2_ISDX] = 4096,
 	[GC_ANA_L3_VLAN] = 5120,
+	[GC_ANA_L3_VMID] = 511,
+	[GC_ANA_L3_ARP] = 2048,
 	[GC_ASM_DEV_STATISTICS] = 65,
 	[GC_EACL_ES2_KEY_SELECT_PROFILE] = 138,
 	[GC_EACL_CNT_TBL] = 2048,
@@ -143,6 +149,7 @@ const unsigned int sparx5_gcnt[GCNT_LAST] = {
 	[GC_PTP_PTP_PINS] = 5,
 	[GC_PTP_PHASE_DETECTOR_CTRL] = 5,
 	[GC_REW_PORT] = 70,
+	[GC_REW_VMID] = 511,
 	[GC_REW_VOE_PORT_LM_CNT] = 520,
 };
 
@@ -202,7 +209,10 @@ const unsigned int sparx5_fsize[FSIZE_LAST] = {
 	[FW_ANA_L2_AUTO_LRN_CFG_AUTO_LRN_ENA] = 32,
 	[FW_ANA_L2_DLB_CFG_DLB_IDX] = 13,
 	[FW_ANA_L2_TSN_CFG_TSN_SFID] = 10,
+	[FW_ANA_L3_L3_UC_ENA_L3_UC_ENA] = 32,
+	[FW_ANA_L3_VMID_CFG_VMID] = 9,
 	[FW_ANA_L3_VLAN_MASK_CFG_VLAN_PORT_MASK] = 32,
+	[FW_ANA_L3_ARP_CFG_0_ARP_VMID] = 9,
 	[FW_FDMA_CH_CFG_CH_DCB_DB_CNT] = 4,
 	[FW_GCB_HW_SGPIO_TO_SD_MAP_CFG_SGPIO_TO_SD_SEL] = 9,
 	[FW_HSCH_SE_CFG_SE_DWRR_CNT] = 7,
@@ -234,6 +244,7 @@ const unsigned int sparx5_fsize[FSIZE_LAST] = {
 	[FW_QSYS_ATOP_ATOP] = 12,
 	[FW_QSYS_ATOP_TOT_CFG_ATOP_TOT] = 12,
 	[FW_REW_RTAG_ETAG_CTRL_IPE_TBL] = 7,
+	[FW_REW_RLEG_CTRL_DECAP_IRLEG] = 9,
 	[FW_XQS_STAT_CFG_STAT_VIEW] = 13,
 	[FW_XQS_QLIMIT_SHR_TOP_CFG_QLIMIT_SHR_TOP] = 15,
 	[FW_XQS_QLIMIT_SHR_ATOP_CFG_QLIMIT_SHR_ATOP] = 15,
drivers/net/ethernet/microchip/sparx5/sparx5_regs.h +11 -0
index 17abaa5798cb..a9741a3e35de 100644
@@ -91,12 +91,15 @@ enum sparx5_gaddr_enum {
 	GA_ANA_CL_COMMON,
 	GA_ANA_L2_COMMON,
 	GA_ANA_L3_COMMON,
+	GA_ANA_L3_VMID,
+	GA_ANA_L3_ARP,
 	GA_ANA_L3_VLAN_ARP_L3MC_STICKY,
 	GA_ASM_CFG,
 	GA_ASM_PFC_TIMER_CFG,
 	GA_ASM_LBK_WM_CFG,
 	GA_ASM_LBK_MISC_CFG,
 	GA_ASM_RAM_CTRL,
+	GA_EACL_COMMON,
 	GA_EACL_ES2_KEY_SELECT_PROFILE,
 	GA_EACL_CNT_TBL,
 	GA_EACL_POL_CFG,
@@ -120,6 +123,7 @@ enum sparx5_gaddr_enum {
 	GA_QSYS_RAM_CTRL,
 	GA_REW_COMMON,
 	GA_REW_PORT,
+	GA_REW_VMID,
 	GA_REW_VOE_PORT_LM_CNT,
 	GA_REW_RAM_CTRL,
 	GA_VOP_RAM_CTRL,
@@ -143,6 +147,8 @@ enum sparx5_gcnt_enum {
 	GC_ANA_L2_ISDX_LIMIT,
 	GC_ANA_L2_ISDX,
 	GC_ANA_L3_VLAN,
+	GC_ANA_L3_VMID,
+	GC_ANA_L3_ARP,
 	GC_ASM_DEV_STATISTICS,
 	GC_EACL_ES2_KEY_SELECT_PROFILE,
 	GC_EACL_CNT_TBL,
@@ -153,6 +159,7 @@ enum sparx5_gcnt_enum {
 	GC_PTP_PTP_PINS,
 	GC_PTP_PHASE_DETECTOR_CTRL,
 	GC_REW_PORT,
+	GC_REW_VMID,
 	GC_REW_VOE_PORT_LM_CNT,
 	GCNT_LAST,
 };
@@ -215,7 +222,10 @@ enum sparx5_fsize_enum {
 	FW_ANA_L2_AUTO_LRN_CFG_AUTO_LRN_ENA,
 	FW_ANA_L2_DLB_CFG_DLB_IDX,
 	FW_ANA_L2_TSN_CFG_TSN_SFID,
+	FW_ANA_L3_L3_UC_ENA_L3_UC_ENA,
+	FW_ANA_L3_VMID_CFG_VMID,
 	FW_ANA_L3_VLAN_MASK_CFG_VLAN_PORT_MASK,
+	FW_ANA_L3_ARP_CFG_0_ARP_VMID,
 	FW_FDMA_CH_CFG_CH_DCB_DB_CNT,
 	FW_GCB_HW_SGPIO_TO_SD_MAP_CFG_SGPIO_TO_SD_SEL,
 	FW_HSCH_SE_CFG_SE_DWRR_CNT,
@@ -247,6 +257,7 @@ enum sparx5_fsize_enum {
 	FW_QSYS_ATOP_ATOP,
 	FW_QSYS_ATOP_TOT_CFG_ATOP_TOT,
 	FW_REW_RTAG_ETAG_CTRL_IPE_TBL,
+	FW_REW_RLEG_CTRL_DECAP_IRLEG,
 	FW_XQS_STAT_CFG_STAT_VIEW,
 	FW_XQS_QLIMIT_SHR_TOP_CFG_QLIMIT_SHR_TOP,
 	FW_XQS_QLIMIT_SHR_ATOP_CFG_QLIMIT_SHR_ATOP,
Signature · 1 line
2.52.0
#2 lore raw

PATCH v4 2/3 net: sparx5: add L3 router legs

In reply to Jens Emil Schulz Østergaard

The chips can only route in VLAN aware mode, and routing happens between router legs (RLEG). To each direct VLAN upper of a VLAN aware bridge, we associate a router leg. The indices to the router leg table are called VMIDs in the datasheet. Leg hardware state is indexed by VLAN id, so leg vids must be unique.

A leg is created when the first address is added to such an upper, and destroyed when the last one is removed or the upper is unregistered. A bridge's legs are also torn down when its last switch port leaves, since the switch then has no datapath on it.

There is a global router leg base MAC used for MAC rewrites by the chip. Here we use the bridge MAC, programmed when a leg is created.

A router leg is offloaded only for a device that is:

1) A direct VLAN upper of the single bridge that has switch ports lowers.

2) On an 802.1Q bridge, using the bridge's VLAN protocol.

3) On a non-zero vid. Every non-bridged port classifies into vid 0, so such a leg would offer routing to frames from ports outside the bridge.

4) Carrying and inheriting the bridge MAC. ANA_L3 matches one global base MAC as the router leg MAC for every VMID.

5) Without a master. A bridge, LAG, OVS or HSR master owns the devices rx path, and an l3mdev master owns its routing table.

The conditions are evaluated when an address is added to a VLAN upper. Configurations that are not offloaded are handled in software as usual. A qualifying upper whose leg cannot be created, because the VMIDs are used up, an allocation fails or another upper already has a leg for the vid, keeps its address and is routed in software. The failure is reported as an extack warning, or in the kernel log.

Routing is enabled in the chip, but no LPM rule is programmed. A routed frame misses the LPM lookup and is redirected to the CPU on CPU_UC_FAIL_QU, so the kernel routes every frame in software.

L3 offload is optional. If the router cannot initialise, probe carries on without offload rather than failing the whole switch.

Without CONFIG_VLAN_8021Q there is no VLAN upper to attach a leg to, so sparx5_rr_router_init() returns early: no notifiers are registered and routing is not enabled in the chip.

---
 drivers/net/ethernet/microchip/sparx5/Makefile     |   2 +-
 .../ethernet/microchip/sparx5/lan969x/lan969x.c    |   1 +
 .../net/ethernet/microchip/sparx5/sparx5_main.c    |  13 +-
 .../net/ethernet/microchip/sparx5/sparx5_main.h    |  33 +
 .../net/ethernet/microchip/sparx5/sparx5_router.c  | 790 +++++++++++++++++++++
 .../ethernet/microchip/sparx5/sparx5_switchdev.c   |   5 +-
 .../net/ethernet/microchip/sparx5/sparx5_vlan.c    |   2 +
 7 files changed, 842 insertions(+), 4 deletions(-)
drivers/net/ethernet/microchip/sparx5/Makefile +1 -1
index 06cf583effdb..d7a1e6ad087e 100644
@@ -11,7 +11,7 @@ sparx5-switch-y  := sparx5_main.o sparx5_packet.o \
  sparx5_ptp.o sparx5_pgid.o sparx5_tc.o sparx5_qos.o \
  sparx5_vcap_impl.o sparx5_vcap_ag_api.o sparx5_tc_flower.o \
  sparx5_tc_matchall.o sparx5_pool.o sparx5_sdlb.o sparx5_police.o \
- sparx5_psfp.o sparx5_mirror.o sparx5_regs.o sparx5_tas.o
+ sparx5_psfp.o sparx5_mirror.o sparx5_regs.o sparx5_tas.o sparx5_router.o
 
 sparx5-switch-$(CONFIG_SPARX5_DCB) += sparx5_dcb.o
 sparx5-switch-$(CONFIG_DEBUG_FS) += sparx5_vcap_debugfs.o
drivers/net/ethernet/microchip/sparx5/lan969x/lan969x.c +1 -0
index df211e608056..e0d497d809ea 100644
@@ -325,6 +325,7 @@ static const struct sparx5_consts lan969x_consts = {
 	.qres_max_prio_idx   = 315,
 	.qres_max_colour_idx = 323,
 	.tod_pin             = 4,
+	.vmid_cnt            = 127,
 	.vcaps               = lan969x_vcaps,
 	.vcap_stats          = &lan969x_vcap_stats,
 	.vcaps_cfg           = lan969x_vcap_inst_cfg,
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +11 -2
index a968d36ae7ef..c8176ab35278 100644
@@ -1119,15 +1119,22 @@ static int mchp_sparx5_probe(struct platform_device *pdev)
 		goto cleanup_ptp;
 	}
 
+	/* L3 offload is optional, probe carries on without it. */
+	err = sparx5_rr_router_init(sparx5);
+	if (err)
+		dev_warn(sparx5->dev, "L3 routing offload unavailable: %pe\n",
+			 ERR_PTR(err));
+
 	err = sparx5_register_notifier_blocks(sparx5);
 	if (err) {
 		dev_err(sparx5->dev, "Failed to register notifier blocks\n");
-		goto cleanup_netdevs;
+		goto cleanup_router;
 	}
 
 	goto cleanup_config;
 
-cleanup_netdevs:
+cleanup_router:
+	sparx5_rr_router_deinit(sparx5);
 	sparx5_unregister_netdevs(sparx5);
 cleanup_ptp:
 	sparx5_ptp_deinit(sparx5);
@@ -1153,6 +1160,7 @@ static void mchp_sparx5_remove(struct platform_device *pdev)
 	struct sparx5 *sparx5 = platform_get_drvdata(pdev);
 
 	debugfs_remove_recursive(sparx5->debugfs_root);
+	sparx5_rr_router_deinit(sparx5);
 	sparx5_unregister_notifier_blocks(sparx5);
 	sparx5_unregister_netdevs(sparx5);
 	sparx5_ptp_deinit(sparx5);
@@ -1194,6 +1202,7 @@ static const struct sparx5_consts sparx5_consts = {
 	.qres_max_prio_idx   = 630,
 	.qres_max_colour_idx = 638,
 	.tod_pin             = 4,
+	.vmid_cnt            = 511,
 	.vcaps               = sparx5_vcaps,
 	.vcaps_cfg           = sparx5_vcap_inst_cfg,
 	.vcap_stats          = &sparx5_vcap_stats,
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +33 -0
index f6316086e6ec..b940f8199942 100644
@@ -138,6 +138,11 @@ enum sparx5_feature {
 
 #define SPARX5_MAX_PTP_ID	512
 
+/* Must be the maximum across all L3 enabled platforms, which
+ * sparx5_rr_router_init() checks against the per-platform consts.
+ */
+#define SPARX5_ROUTER_LEG_N_VMID 511
+
 struct sparx5;
 
 struct sparx5_calendar_data {
@@ -362,6 +367,7 @@ struct sparx5_consts {
 	u32 qres_max_prio_idx;   /* Maximum QRES prio index */
 	u32 qres_max_colour_idx; /* Maximum QRES colour index */
 	u32 tod_pin;             /* PTP TOD pin */
+	u32 vmid_cnt;            /* Number of router leg VMID's */
 	const struct sparx5_vcap_inst *vcaps_cfg;
 	const struct vcap_info *vcaps;
 	const struct vcap_statistics *vcap_stats;
@@ -480,6 +486,8 @@ struct sparx5 {
 	/* Common root for debugfs */
 	struct dentry *debugfs_root;
 	const struct sparx5_match_data *data;
+	/* L3 Forwarding */
+	struct sparx5_router *router;
 };
 
 /* sparx5_main.c */
@@ -549,6 +557,31 @@ int sparx5_vlan_vid_add(struct sparx5_port *port, u16 vid, bool pvid,
 int sparx5_vlan_vid_del(struct sparx5_port *port, u16 vid);
 void sparx5_vlan_port_apply(struct sparx5 *sparx5, struct sparx5_port *port);
 
+/* sparx5_router.c */
+void sparx5_rr_port_fwd_update(struct sparx5 *sparx5);
+int sparx5_rr_router_init(struct sparx5 *sparx5);
+void sparx5_rr_router_deinit(struct sparx5 *sparx5);
+void sparx5_rr_bridge_legs_flush(struct sparx5 *sparx5,
+				 const struct net_device *bridge);
+
+struct sparx5_router {
+	struct sparx5 *sparx5;
+	struct notifier_block inetaddr_nb;
+	struct notifier_block inetaddr_valid_nb;
+	struct notifier_block netdevice_nb;
+	struct notifier_block inet6addr_nb;
+	struct notifier_block inet6addr_valid_nb;
+
+	struct mutex lock; /* Global router lock for all shared data. */
+
+	struct workqueue_struct *sparx5_router_owq;
+	struct work_struct legs_work;
+
+	struct list_head leg_list;
+	/* Track allocated router leg indices in hw */
+	DECLARE_BITMAP(vmid_mask, SPARX5_ROUTER_LEG_N_VMID);
+};
+
 /* sparx5_calendar.c */
 int sparx5_calendar_init(struct sparx5 *sparx5);
 int sparx5_dsm_calendar_calc(struct sparx5 *sparx5, u32 taxi,
drivers/net/ethernet/microchip/sparx5/sparx5_router.c new file +790 -0

790 lines not on this page · raw message

drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c +4 -1
index dac4dd833127..46b3351f717f 100644
@@ -227,8 +227,11 @@ static void sparx5_port_bridge_leave(struct sparx5_port *port,
 	switchdev_bridge_port_unoffload(port->ndev, NULL, NULL, NULL);
 
 	clear_bit(port->portno, sparx5->bridge_mask);
-	if (bitmap_empty(sparx5->bridge_mask, SPX5_PORTS))
+	if (bitmap_empty(sparx5->bridge_mask, SPX5_PORTS)) {
+		/* L3 offload has no datapath left on this bridge. */
+		sparx5_rr_bridge_legs_flush(sparx5, bridge);
 		sparx5->hw_bridge_dev = NULL;
+	}
 
 	/* Clear bridge vlan settings before updating the port settings */
 	port->vlan_aware = 0;
drivers/net/ethernet/microchip/sparx5/sparx5_vlan.c +2 -0
index 494782871903..96edb05af5b7 100644
@@ -199,6 +199,8 @@ void sparx5_update_fwd(struct sparx5 *sparx5)
 		spx5_wr(mask[1], sparx5, ANA_L2_AUTO_LRN_CFG1);
 		spx5_wr(mask[2], sparx5, ANA_L2_AUTO_LRN_CFG2);
 	}
+
+	sparx5_rr_port_fwd_update(sparx5);
 }
 
 void sparx5_vlan_port_apply(struct sparx5 *sparx5,
Signature · 1 line
2.52.0
#3 lore raw

PATCH v4 3/3 net: sparx5: keep router legs in sync with the bridge

In reply to Jens Emil Schulz Østergaard

The conditions for offloading a leg are evaluated when an address is added, but the bridge and the upper can change afterwards.

A change that would leave the chip routing differently from the kernel destroys the leg before it takes effect: disabling VLAN filtering, changing the bridge to a VLAN protocol other than 802.1Q, linking the upper to a master, and changing the upper's MAC.

The global leg base MAC follows later bridge MAC changes. When the first switch port joins a bridge again, the reconcile is queued and creates the legs for its uppers that kept their addresses while the bridge was not offloaded.

While the upper is administratively down the leg is disabled as an ingress router leg. The same holds while the bridge itself does not carry the leg's vid, or carries it untagged, since the kernel then does not deliver that vid to the upper. A bridge vlan delete, or an add that makes the vid untagged, disables the leg at once.

A leg with an IPv4 address is kept while the upper is down, so it is available again when the interface comes back up. Unless keep_addr_on_down is set, link down removes IPv6 addresses, so an IPv6 only leg goes with its last address.

A down upper does not follow bridge MAC changes, so it can lose its leg while down. Bringing a vlan upper of the bridge up queues the reconcile, which creates the leg again.

IPv6 addresses that the kernel adds without calling the validator, such as SLAAC and temporary addresses, get their leg from the reconcile, which the address notifier queues for them.

---
 .../net/ethernet/microchip/sparx5/sparx5_main.h    |   3 +
 .../net/ethernet/microchip/sparx5/sparx5_router.c  | 140 ++++++++++++++++++++-
 .../ethernet/microchip/sparx5/sparx5_switchdev.c   |  25 +++-
 3 files changed, 162 insertions(+), 6 deletions(-)
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +3 -0
index b940f8199942..36df730e9bdb 100644
@@ -563,6 +563,9 @@ int sparx5_rr_router_init(struct sparx5 *sparx5);
 void sparx5_rr_router_deinit(struct sparx5 *sparx5);
 void sparx5_rr_bridge_legs_flush(struct sparx5 *sparx5,
 				 const struct net_device *bridge);
+void sparx5_rr_legs_reconcile_schedule(struct sparx5 *sparx5);
+void sparx5_rr_bridge_vlan_clear(struct sparx5 *sparx5,
+				 const struct net_device *bridge, u16 vid);
 
 struct sparx5_router {
 	struct sparx5 *sparx5;
drivers/net/ethernet/microchip/sparx5/sparx5_router.c +135 -5

218 lines not on this page · raw message

drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c +24 -1
index 46b3351f717f..322806fbfe2b 100644
@@ -152,6 +152,11 @@ static int sparx5_port_attr_set(struct net_device *dev, const void *ctx,
 		sparx5_port_attr_ageing_set(port, attr->u.ageing_time);
 		break;
 	case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING:
+		/* L3 offload requires a VLAN aware bridge. */
+		if (!attr->u.vlan_filtering)
+			sparx5_rr_bridge_legs_flush(port->sparx5,
+						    attr->orig_dev);
+		sparx5_rr_legs_reconcile_schedule(port->sparx5);
 		/* Used PVID 1 when default_pvid is 0, to avoid
 		 * collision with non-bridged ports.
 		 */
@@ -160,6 +165,13 @@ static int sparx5_port_attr_set(struct net_device *dev, const void *ctx,
 		port->vlan_aware = attr->u.vlan_filtering;
 		sparx5_vlan_port_apply(port->sparx5, port);
 		break;
+	case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_PROTOCOL:
+		/* A leg is classified by vid alone, whatever the protocol. */
+		if (attr->u.vlan_protocol != ETH_P_8021Q)
+			sparx5_rr_bridge_legs_flush(port->sparx5,
+						    attr->orig_dev);
+		sparx5_rr_legs_reconcile_schedule(port->sparx5);
+		return -EOPNOTSUPP;
 	case SWITCHDEV_ATTR_ID_PORT_MROUTER:
 		sparx5_port_attr_mrouter_set(port,
 					     attr->orig_dev,
@@ -179,9 +191,11 @@ static int sparx5_port_bridge_join(struct sparx5_port *port,
 	struct switchdev_brport_flags flags = {0};
 	struct sparx5 *sparx5 = port->sparx5;
 	struct net_device *ndev = port->ndev;
+	bool first;
 	int err;
 
-	if (bitmap_empty(sparx5->bridge_mask, SPX5_PORTS))
+	first = bitmap_empty(sparx5->bridge_mask, SPX5_PORTS);
+	if (first)
 		/* First bridged port */
 		sparx5->hw_bridge_dev = bridge;
 	else
@@ -211,6 +225,10 @@ static int sparx5_port_bridge_join(struct sparx5_port *port,
 	flags.val = flags.mask;
 	sparx5_port_attr_bridge_flags(port, flags);
 
+	/* The bridge's legs were flushed when its last port left. */
+	if (first)
+		sparx5_rr_legs_reconcile_schedule(sparx5);
+
 	return 0;
 
 err_switchdev_offload:
@@ -448,6 +466,10 @@ static int sparx5_handle_port_vlan_add(struct net_device *dev,
 		/* Flood broadcast to CPU */
 		sparx5_mact_learn(sparx5, sparx5_get_pgid(sparx5, PGID_BCAST),
 				  dev->broadcast, v->vid);
+		if (v->flags & BRIDGE_VLAN_INFO_UNTAGGED)
+			sparx5_rr_bridge_vlan_clear(sparx5, dev, v->vid);
+		else
+			sparx5_rr_legs_reconcile_schedule(sparx5);
 		return 0;
 	}
 
@@ -683,6 +705,7 @@ static int sparx5_handle_port_vlan_del(struct net_device *dev,
 				     switchdev_blocking_nb);
 
 		sparx5_mact_forget(sparx5, dev->broadcast, vid);
+		sparx5_rr_bridge_vlan_clear(sparx5, dev, vid);
 		return 0;
 	}
 
Signature · 1 line
2.52.0
#4 lore raw
In reply to Jens Emil Schulz Østergaard
This series was applied to netdev/net-next.git (main) by Willem de Bruijn <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Willem de Bruijn <[email protected]>:

Quoted 8 lines · On Wed, 25 Nov 2026 14:35:05 +0100 you wrote:

This is the first series adding L3 unicast routing offload for IPv4 and IPv6 to Sparx5 and LAN969x. It adds the routing registers and the router legs, the hardware interfaces where routing happens. No route is offloaded yet. Routing is enabled in the chip, but with no LPM rule a routed frame misses the lookup and is redirected to the CPU, so the kernel keeps routing every frame in software.

[...]

Here is the summary with links:
- [net-next,v4,1/3] net: sparx5: add l3 routing registers

    https://git.kernel.org/netdev/net-next/c/0b54fec6d3c6
  - [net-next,v4,2/3] net: sparx5: add L3 router legs
    https://git.kernel.org/netdev/net-next/c/00465eaa4f49
  - [net-next,v4,3/3] net: sparx5: keep router legs in sync with the bridge
    https://git.kernel.org/netdev/net-next/c/e955e3e7dca4

You are awesome, thank you!

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