Skip to contentSkip to conversation

Add Northstar FA TCP/UDP NAT offload with a bridged LAN

PATCH In review Florian Fainelli 2 participants 9 messages Dec 1 – Dec 3

Subsystems (9)
lore
Share & tools
lore

Florian Fainelli

author maintainer
#0 lore raw

v2 cover Add Northstar FA TCP/UDP NAT offload with a bridged LAN

Add nftables flowtable offload for the original flow accelerator in BCM4708/BCM5301X. The six patches provide bindings, B53/DSA metadata and exception paths, cached-path validation and invalidation, the bgmac backend, KUnit tests and a hardware qualification guide.

Support the usual router layout: a standalone WAN and an untagged LAN bridge containing four wired LAN ports and software members such as a PCIe WLAN interface. Wired IPv4 TCP/UDP SNAT or DNAT can use FA. Software members retain software forwarding. Two standalone DSA router ports also remain supported. Use distinct LAN/WAN router MACs, MTU 1500 and one hardware flowtable in the initial network namespace. Include only the physical wired DSA ports in the hardware flowtable.

Data travels through GMAC2 and switch port 8 (IMP0). B53 CFP redirects TCP control, low-TTL, oversized and ingress-policy exceptions through GMAC0 and switch port 5 (IMP1), outside inline FA. Both protocols require this auxiliary connection. Router-domain and source-MAC guards preserve ordinary LAN switching and force continued tuples from another physical ingress through Linux learning. Table or classifier exhaustion retains software forwarding. Existing board device trees must explicitly opt in.

Validate both actual cached routes, neighbours and bridge FDB paths. FDB notifications invalidate bridge flowtable generations, including software-only and hardware-capacity fallback owners after client moves. Retirement is conservative across bridge paths in the same namespace and across notified IPv4 route, rule and nexthop changes. Non-bridge caches retain their existing automatic route-validation policy. Unnotified DSCP-specific route aliases must not be used for accelerated traffic.

Changes in v2:
- Describe the GMAC3-hosted register window, restrict the GMAC2 consumer schema and correct the auxiliary CPU port name to IMP1.
- Support the bridged-LAN router layout. Add shared source-MAC guards, preserve ordinary LAN switching and clear the forwarding mark on auxiliary redirects which may require software bridging.
- Validate cached routes and neighbours without allocating entries; return the owner's reverse peer MAC for ingress guards. Resolve untagged bridge paths and permit STP state reads under RCU.
- Notify caches around FDB changes and retire stale bridge generations during construction, packet lookup, GC and hardware admission, including software-only flows and hardware-capacity fallback.
- Recheck every installed next hop, serialize block bookkeeping, reject non-initial namespaces and retire before ports can receive.
- Match TCP control in both directions using exact tuples, including IP options, and close concurrent peer-installation races. Leave unparseable and non-initial fragments on the software path.
- Handle guard failures, MAC-change vetoes, auxiliary VLAN membership and notifier teardown. Retire on bridge state and security changes.
- Extend the combined KUnit suite to 37 cases and document bridge configuration, software-member tests and FDB movement qualification.
- Fold intermediate fixes into their feature commits, wrap commit messages and remove redundant nftables transport matches. Every feature patch passes checkpatch.pl --strict without suppressions.
- Repeat qualification and complete a fresh bridged-LAN mixed soak lasting 23 hours 58 minutes, including TCP/UDP capacity fallback.

v1: https://lore.kernel.org/all/[email protected]/

Dependencies:
The base-commit trailer identifies the tested net-next snapshot. The five prerequisite-patch-id trailers identify independent fixes supplied in a separate prerequisite bundle, in this order:

net: ethernet: bgmac: validate RX length against the DMA packet capacity
netfilter: flowtable: do not forward frames not addressed to the host
netfilter: flowtable: retain offload ownership until deletion completes
net: dsa: tag_brcm: fix link-local detection with a prepended tag
net: ethernet: bgmac: update netdev MTU after changing the MAC

Validation on BCM953012ER / BCM53012:
- ARM W=1 built-in, module and disabled builds, including module link and modpost; targeted DT schemas, examples and board DTBs.
- 37 combined QEMU KUnit cases, including bridge movement, cache generation, source guards and the RCU STP accessor regression.
- Classic, software-flowtable and hardware TCP/UDP SNAT/DNAT controls with payload, checksum, TTL and raw hardware-key checks.
- Prior boundary, ingress-policy, invalidation and read/insert/delete completion-timeout qualification, with fallback and recovery.
- Software-to-wired continued-tuple movement, simultaneous wired HW NAT and software-member NAT/L2 traffic, wrong-ingress trapping, FDB updates and bridge/auxiliary-link control transitions.
- The new bridge soak completed 21 mixed-traffic phases and 20 cycles each of UDP overflow, aging, recovery, TCP overflow, FIN drain and TCP recovery. Its 132,404,736 wired echo exchanges and 1,538,648 exchanges on each software bridge stream had no loss or payload errors. All 144 periodic independent audits were healthy. There were no campaign restarts, host OOMs or unexpected kernel/FA errors.

The software bridge member was a veth; no actual WLAN radio was tested. Traffic through every physical LAN port, BCM4708/BCM53011 hardware, FA2/FA+, PPPoE and maximum throughput remain outside this qualification. Earlier multicast-database diagnostics are tracked separately; the NAT soak does not establish a fix for them. Register accessibility still depends on the bootloader's GMAC3 state, as the binding and guide explain.

OpenAI Codex assistance covered implementation, tests, documentation, changelogs, lab orchestration and submission preparation, using the requested design, Broadcom documentation, the ISC downstream driver, kernel sources and review feedback.

Florian Fainelli (6):
dt-bindings: net: describe the Northstar flow accelerator
net: dsa: add Broadcom FA metadata and IPv4 exception paths
net: flow_offload: allow drivers to validate and invalidate cached
paths
net: bgmac: add Northstar IPv4 TCP/UDP NAT flowtable offload
net: add KUnit coverage for FA and flowtable path validation
docs: net: document Northstar FA setup and NAT qualification

 .../bindings/net/brcm,bcm4708-fa.yaml         |   52 +
 .../bindings/net/brcm,bcm5301x-gmac.yaml      |   33 +
 .../ethernet/broadcom/bcm-ns-fa.rst           |  638 +++++
 .../device_drivers/ethernet/index.rst         |    1 +
 MAINTAINERS                                   |    7 +
 drivers/net/dsa/b53/Kconfig                   |   12 +
 drivers/net/dsa/b53/b53_common.c              |  520 +++-
 drivers/net/dsa/b53/b53_fa_test.c             |  124 +
 drivers/net/dsa/b53/b53_priv.h                |   16 +
 drivers/net/dsa/b53/b53_regs.h                |   39 +
 drivers/net/ethernet/broadcom/.kunitconfig    |   24 +
 drivers/net/ethernet/broadcom/Kconfig         |   39 +
 drivers/net/ethernet/broadcom/Makefile        |    1 +
 .../net/ethernet/broadcom/bcm-ns-fa-test.c    |  795 ++++++
 drivers/net/ethernet/broadcom/bcm-ns-fa.c     | 2218 +++++++++++++++++
 drivers/net/ethernet/broadcom/bcm-ns-fa.h     |   30 +
 drivers/net/ethernet/broadcom/bgmac-bcma.c    |    5 +
 drivers/net/ethernet/broadcom/bgmac.c         |   30 +
 drivers/net/ethernet/broadcom/bgmac.h         |    2 +
 include/linux/dsa/brcm.h                      |   34 +
 include/net/dsa.h                             |    2 +
 include/net/flow_offload.h                    |   14 +
 include/net/netevent.h                        |    1 +
 include/net/netfilter/nf_flow_table.h         |   13 +-
 include/net/netns/flow_table.h                |    3 +
 net/bridge/br_fdb.c                           |   26 +-
 net/bridge/br_stp.c                           |    7 +-
 net/dsa/Kconfig                               |   23 +
 net/dsa/tag_brcm.c                            |  166 +-
 net/dsa/tag_brcm_test.c                       |  200 ++
 net/netfilter/Kconfig                         |   15 +-
 net/netfilter/nf_flow_table_core.c            |   57 +-
 net/netfilter/nf_flow_table_core_test.c       |  203 ++
 net/netfilter/nf_flow_table_offload.c         |  143 ++
 net/netfilter/nf_flow_table_offload_test.c    |  242 ++
 net/netfilter/nf_flow_table_path.c            |    8 +
 net/netfilter/nft_flow_offload.c              |    6 +-
 37 files changed, 5712 insertions(+), 37 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/brcm,bcm4708-fa.yaml
 create mode 100644 Documentation/devicetree/bindings/net/brcm,bcm5301x-gmac.yaml
 create mode 100644 Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst
 create mode 100644 drivers/net/dsa/b53/b53_fa_test.c
 create mode 100644 drivers/net/ethernet/broadcom/.kunitconfig
 create mode 100644 drivers/net/ethernet/broadcom/bcm-ns-fa-test.c
 create mode 100644 drivers/net/ethernet/broadcom/bcm-ns-fa.c
 create mode 100644 drivers/net/ethernet/broadcom/bcm-ns-fa.h
 create mode 100644 net/dsa/tag_brcm_test.c
 create mode 100644 net/netfilter/nf_flow_table_offload_test.c

base-commit: d1f4b7c6b997c29de67ad7178ababac2328cb1b4
prerequisite-patch-id: cc5740b3c0df34f00a185bc49b48af0de0b4f246
prerequisite-patch-id: 4a2aa7a8f7a1670091364bf8856b1286bdd4e371
prerequisite-patch-id: 4dac987af9eb210ace8e99bf06ce4273995692bb
prerequisite-patch-id: d322079467996d4b88d7f928251d11869862b32a
prerequisite-patch-id: bfc2b85226ebd6baac17d44e5909873c908e821c

author maintainer
#1 lore raw

PATCH v2 1/6 dt-bindings: net: describe the Northstar flow accelerator

Describe the BCM4708/BCM53011/BCM53012 accelerator register resource and the GMAC2 consumer phandle. The accelerator is inline on switch CPU port 8 (IMP0); GMAC0 and GMAC1 bypass it. Document the additional port 5 (IMP1)/GMAC0 CPU connection for exceptions that cannot safely traverse the inline lookup. Keep existing boards unchanged unless their topology explicitly opts in.

The accelerator registers belong to the AXI MAC + flow accelerator block and sit in the 4 KiB BCMA window of the GMAC3 core, outside of the range described for the GMAC3 node. BCMA GMAC nodes have no compatible string, so the consumer schema is selected by the property and restricted to the GMAC2 node name.

---
Changes in v2:
- Describe the AXI MAC/FA block and the register placement within the GMAC3 4 KiB BCMA window; clarify that FA has no separate DT clock or reset input and correct port 5 to IMP1.
- Explain property-based schema selection for BCMA GMAC nodes and restrict the consumer to GMAC2 (ethernet@26000).

 .../bindings/net/brcm,bcm4708-fa.yaml         | 52 +++++++++++++++++++
 .../bindings/net/brcm,bcm5301x-gmac.yaml      | 33 ++++++++++++
 MAINTAINERS                                   |  2 +
 3 files changed, 87 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/brcm,bcm4708-fa.yaml
 create mode 100644 Documentation/devicetree/bindings/net/brcm,bcm5301x-gmac.yaml
Documentation/devicetree/bindings/net/brcm,bcm4708-fa.yaml new file +52 -0
new file mode 100644
index 0000000000000..69dcfd060589b
@@ -0,0 +1,52 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/brcm,bcm4708-fa.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Broadcom Northstar BCM4708 and BCM5301X flow accelerator
+
+maintainers:
+  - Florian Fainelli <[email protected]>
+
+description: |
+  The flow accelerator is part of the AXI MAC + flow accelerator block, which
+  also contains the four GMAC cores enumerated by BCMA. It is inline between
+  GMAC2 and switch port 8 (IMP0); GMAC0 and GMAC1 bypass it. The GMAC2 BCMA
+  Ethernet node references this register block through a
+  brcm,flow-accelerator phandle. Miss packets carry a prepended accelerator
+  descriptor in place of the embedded switch tag.
+
+  The registers are in the same 4 KiB BCMA window as the GMAC3 core (the
+  loopback port of the block), above the 0x800 bytes that the GMAC3 node
+  describes. The accelerator is part of that block and has no clock or reset
+  input of its own in the device tree.
+
+  Switch port 5 (IMP1), connected to GMAC0, provides a second CPU path for
+  exceptions that must bypass the accelerator, including TCP control,
+  low-TTL and oversized packets. Describe that CPU port with an ethernet
+  phandle to GMAC0 and an internal, 1 Gbps full-duplex fixed link in the
+  switch's ports node. Port 8 remains the data connection to GMAC2.
+
+properties:
+  compatible:
+    enum:
+      - brcm,bcm4708-fa
+      - brcm,bcm53011-fa
+      - brcm,bcm53012-fa
+
+  reg:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    flow-accelerator@18027c00 {
+        compatible = "brcm,bcm53011-fa";
+        reg = <0x18027c00 0xc0>;
+    };
Documentation/devicetree/bindings/net/brcm,bcm5301x-gmac.yaml new file +33 -0
new file mode 100644
index 0000000000000..c560731987bed
@@ -0,0 +1,33 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/brcm,bcm5301x-gmac.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Broadcom Northstar BCMA GMAC flow accelerator connection
+
+maintainers:
+  - Florian Fainelli <[email protected]>
+
+description: |
+  BCMA enumerates the Northstar GMACs, and their nodes have no compatible
+  string. This schema is therefore selected by the brcm,flow-accelerator
+  property and describes the optional inline flow accelerator connection on
+  GMAC2, connected to switch IMP0.
+
+select:
+  required:
+    - brcm,flow-accelerator
+
+properties:
+  $nodename:
+    pattern: "^ethernet@26000$"
+
+  brcm,flow-accelerator:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description: |
+      Phandle to the BCM4708, BCM53011 or BCM53012 inline flow accelerator.
+      Only GMAC2 (BCMA Ethernet core unit 2, ethernet@26000) has this
+      connection.
+
+additionalProperties: true
MAINTAINERS +2 -0
index 56212dbc9a0d0..dce9a88f4aef4 100644
@@ -5669,6 +5669,8 @@ R:	Broadcom internal kernel review list <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/net/brcm,amac.yaml
+F:	Documentation/devicetree/bindings/net/brcm,bcm4708-fa.yaml
+F:	Documentation/devicetree/bindings/net/brcm,bcm5301x-gmac.yaml
 F:	drivers/net/ethernet/broadcom/bgmac*
 F:	drivers/net/ethernet/broadcom/unimac.h
 
author maintainer
#2 lore raw

PATCH v2 2/6 net: dsa: add Broadcom FA metadata and IPv4 exception paths

In reply to Florian Fainelli

The original Northstar FA prepends miss metadata which is incompatible with the ordinary Broadcom switch tag. Add a distinct tag protocol and receive callback registry for hash learning and exception handling.

Use B53 CFP to redirect TCP control, low-TTL, oversized and wrong- router- MAC traffic through the auxiliary GMAC0 connection, outside inline FA. Require complete guards on all user ports and mirror data-CPU VLAN membership to the auxiliary CPU port. Preserve its flooding policy.

Support a LAN bridge with shared router-MAC and refcounted source-MAC guards. Trap a continued tuple arriving on another port before FA can forward it, while preserving ordinary LAN switching. Clear the forwarded mark on auxiliary redirects so Linux can bridge packets back to wired members. Publish client guards before NAT entries and release them only after the last owner has retired; reject uncertain classifier state.

Resynchronize guards after successful and vetoed MAC changes, retire entries before changing guards, and stop notifiers and deferred work before switch teardown. Other Broadcom tag protocols retain their opcode validation and forwarding semantics.

---
Changes in v2:
- Support an untagged LAN bridge with software members opposite a standalone WAN. Use router-domain guards on all user ports and shared source-MAC guards for wired clients, preserving ordinary LAN switching and trapping continued tuples after client movement.
- Clear the forwarded mark on auxiliary classifier redirects. Mirror CPU VLAN membership, retain the auxiliary flooding policy, and handle MAC- change failure and notifier teardown.
- Keep the prepended-tag link-local correction in the independent prerequisites.

 drivers/net/dsa/b53/Kconfig      |   1 +
 drivers/net/dsa/b53/b53_common.c | 516 ++++++++++++++++++++++++++++++-
 drivers/net/dsa/b53/b53_priv.h   |  16 +
 drivers/net/dsa/b53/b53_regs.h   |  39 +++
 include/linux/dsa/brcm.h         |  34 ++
 include/net/dsa.h                |   2 +
 net/dsa/Kconfig                  |  12 +
 net/dsa/tag_brcm.c               | 162 +++++++++-
 8 files changed, 769 insertions(+), 13 deletions(-)
drivers/net/dsa/b53/Kconfig +1 -0
index 915008e8eff53..8e2a8c20bc4ac 100644
@@ -7,6 +7,7 @@ menuconfig B53
 	select NET_DSA_TAG_BRCM_LEGACY
 	select NET_DSA_TAG_BRCM_LEGACY_FCS
 	select NET_DSA_TAG_BRCM_PREPEND
+	select NET_DSA_TAG_BRCM_FA
 	help
 	  This driver adds support for Broadcom managed switch chips. It supports
 	  BCM5325E, BCM5365, BCM539x, BCM53115 and BCM53125 as well as BCM63XX
drivers/net/dsa/b53/b53_common.c +510 -6

646 lines not on this page · raw message

drivers/net/dsa/b53/b53_priv.h +16 -0
index c4d2a41c714f6..2a2769b15d1b0 100644
@@ -19,6 +19,7 @@
 #ifndef __B53_PRIV_H
 #define __B53_PRIV_H
 
+#include <linux/dsa/brcm.h>
 #include <linux/kernel.h>
 #include <linux/mutex.h>
 #include <linux/phylink.h>
@@ -153,6 +154,17 @@ struct b53_device {
 	u8 num_arl_bins;
 	u16 num_arl_buckets;
 	enum dsa_tag_protocol tag_protocol;
+	u16 fa_cfp_ports;
+	u16 fa_user_ports;
+	bool fa_cfp_enabled;
+	bool fa_guards_ready;
+	bool fa_guards_failed;
+	bool fa_stopping;
+	bool fa_notifier_registered;
+	bool fa_switch_registered;
+	struct work_struct fa_resync_work;
+	struct notifier_block fa_netdev_nb;
+	struct brcm_fa_switch fa_switch;
 
 	/* used ports mask */
 	u16 enabled_ports;
@@ -285,13 +297,17 @@ int b53_switch_detect(struct b53_device *dev);
 
 int b53_switch_register(struct b53_device *dev);
 
+void b53_fa_stop(struct b53_device *dev);
+
 static inline void b53_switch_remove(struct b53_device *dev)
 {
+	b53_fa_stop(dev);
 	dsa_unregister_switch(dev->ds);
 }
 
 static inline void b53_switch_shutdown(struct b53_device *dev)
 {
+	b53_fa_stop(dev);
 	dsa_switch_shutdown(dev->ds);
 }
 
drivers/net/dsa/b53/b53_regs.h +39 -0
index cfdb5ed383260..4ca7ea64efc6c 100644
@@ -614,4 +614,43 @@
 /* CFP Control Register with ports map (8 bit) */
 #define B53_CFP_CTRL			0x00
 
+/* Northstar CFP indirect table port. */
+#define B53_CFP_TCAM_PAGE		0xa0
+#define B53_CFP_ACC			0x00
+#define  CFP_ACC_START			BIT(0)
+#define  CFP_ACC_WRITE			(2 << 1)
+#define  CFP_ACC_TCAM			BIT(10)
+#define  CFP_ACC_ACTION			(2 << 10)
+#define  CFP_ACC_METER			(4 << 10)
+#define  CFP_ACC_RESET			BIT(15)
+#define  CFP_ACC_INDEX(n)		((n) << 16)
+#define B53_CFP_DATA(n)			(0x10 + (n) * 4)
+#define B53_CFP_MASK(n)			(0x30 + (n) * 4)
+#define B53_CFP_ACTION(n)		(0x50 + (n) * 4)
+#define B53_CFP_METER			0x60
+#define B53_CFP_UDF1_A0			0x20
+#define  CFP_UDF_BASE_END_L2		(2 << 5)
+#define  CFP_UDF_BASE_END_L3		(3 << 5)
+#define  CFP_UDF_OFFSET(n)		(n)
+
+/* Slice 1 IPv4 key fields, indexed by DATA/MASK word. */
+#define CFP_TCAM0_VALID			GENMASK(1, 0)
+#define CFP_TCAM0_SLICE1			BIT(2)
+#define CFP_TCAM0_SLICE_MASK		GENMASK(3, 2)
+#define CFP_TCAM0_UDF0_FLAG(n)		BIT(8 + (n))
+#define CFP_TCAM_UDF_OFFSET		8
+#define CFP_TCAM5_UDF_VALID(n)		BIT(24 + (n))
+#define CFP_TCAM6_L3_FRAMING		GENMASK(25, 24)
+#define CFP_TCAM6_IP_PROTOCOL		GENMASK(15, 8)
+#define CFP_TCAM6_IP_FRAGMENT		BIT(7)
+#define CFP_TCAM7_SOURCE_PORTS		GENMASK(7, 0)
+
+/* Both meter outcomes replace the destination map with CPU port 5. */
+#define CFP_ACT0_FWD_MAP_REPLACE		(2 << 24)
+#define CFP_ACT0_DST_PORT5		BIT(19)
+#define CFP_ACT0_REASON_TERMINATION	BIT(6)
+#define CFP_ACT1_CLASS_ID(n)		((n) << 20)
+#define CFP_ACT1_FWD_MAP_REPLACE		(2 << 11)
+#define CFP_ACT1_DST_PORT5		BIT(6)
+
 #endif /* !__B53_REGS_H */
include/linux/dsa/brcm.h +34 -0
index 47545a9487840..3a99d0a80920f 100644
@@ -8,6 +8,40 @@
 #ifndef _NET_DSA_BRCM_H
 #define _NET_DSA_BRCM_H
 
+#include <linux/list.h>
+#include <linux/types.h>
+
+struct net_device;
+struct sk_buff;
+
+#define BRCM_FA_BRIDGE_GUARDS 128
+
+/* Guard callbacks run in process context. Unregister waits for callers. */
+struct brcm_fa_switch {
+	struct list_head list;
+	struct net_device *conduit;
+	int (*set_guard)(void *priv, unsigned int slot, const u8 *addr, unsigned int port);
+	void *priv;
+};
+
+void brcm_fa_switch_register(struct brcm_fa_switch *sw);
+void brcm_fa_switch_unregister(struct brcm_fa_switch *sw);
+int brcm_fa_bridge_guard(struct net_device *conduit, unsigned int slot,
+			 const u8 *addr, unsigned int port);
+
+/* Original FA control packets arrive through the auxiliary CPU port. */
+struct brcm_fa_control {
+	struct list_head list;
+	struct net_device *conduit;
+	void (*receive)(void *priv, struct sk_buff *skb, unsigned int port);
+	void (*state_change)(void *priv, bool ready);
+	void *priv;
+};
+
+void brcm_fa_control_register(struct brcm_fa_control *control);
+void brcm_fa_control_unregister(struct brcm_fa_control *control);
+void brcm_fa_control_set_ready(struct net_device *conduit, bool ready);
+
 /* Broadcom tag specific helpers to insert and extract queue/port number */
 #define BRCM_TAG_SET_PORT_QUEUE(p, q)	((p) << 8 | q)
 #define BRCM_TAG_GET_PORT(v)		((v) >> 8)
include/net/dsa.h +2 -0
index 5d12191b6f6f5..5f926b7fde5bb 100644
@@ -62,6 +62,7 @@ struct tc_action;
 #define DSA_TAG_PROTO_KSZ8463_VALUE		34
 #define DSA_TAG_PROTO_MT7628_VALUE		35
 #define DSA_TAG_PROTO_KS8995_VALUE		36
+#define DSA_TAG_PROTO_BRCM_FA_VALUE		37
 
 enum dsa_tag_protocol {
 	DSA_TAG_PROTO_NONE		= DSA_TAG_PROTO_NONE_VALUE,
@@ -69,6 +70,7 @@ enum dsa_tag_protocol {
 	DSA_TAG_PROTO_BRCM_LEGACY	= DSA_TAG_PROTO_BRCM_LEGACY_VALUE,
 	DSA_TAG_PROTO_BRCM_LEGACY_FCS	= DSA_TAG_PROTO_BRCM_LEGACY_FCS_VALUE,
 	DSA_TAG_PROTO_BRCM_PREPEND	= DSA_TAG_PROTO_BRCM_PREPEND_VALUE,
+	DSA_TAG_PROTO_BRCM_FA		= DSA_TAG_PROTO_BRCM_FA_VALUE,
 	DSA_TAG_PROTO_DSA		= DSA_TAG_PROTO_DSA_VALUE,
 	DSA_TAG_PROTO_EDSA		= DSA_TAG_PROTO_EDSA_VALUE,
 	DSA_TAG_PROTO_GSWIP		= DSA_TAG_PROTO_GSWIP_VALUE,
net/dsa/Kconfig +12 -0
index 4f44bf3ede238..d62de6f716cd9 100644
@@ -69,6 +69,18 @@ config NET_DSA_TAG_BRCM_PREPEND
 	  Broadcom switches which places the tag before the Ethernet header
 	  (prepended).
 
+config NET_DSA_TAG_BRCM_FA
+	tristate "Tag driver for the Broadcom Northstar flow accelerator"
+	select NET_DSA_TAG_BRCM_COMMON
+	help
+	  Support the prepended four-byte FA metadata tag on Northstar GMAC2,
+	  which carries the data of switch port 8. The receive format includes
+	  a hash, bucket, parser status, and input switch port. The auxiliary
+	  GMAC0 connection to switch port 5 uses the ordinary Broadcom tag,
+	  embedded after the source address, in both directions.
+	  The B53 driver selects this tagger and uses it only for a switch
+	  explicitly connected to an accelerator.
+
 config NET_DSA_TAG_HELLCREEK
 	tristate "Tag driver for Hirschmann Hellcreek TSN switches"
 	help
net/dsa/tag_brcm.c +155 -7

220 lines not on this page · raw message

author maintainer
#3 lore raw

PATCH v2 3/6 net: flow_offload: allow drivers to validate and invalidate cached paths

In reply to Florian Fainelli

A classifier can lack the mark, DSCP and output-interface context used to select its forwarding path. Provide optional owner validation and invalidation callbacks so an accelerator can validate the actual cached routes and Ethernet peers instead of treating a partial FIB lookup as proof that a software path is stale.

Retain direct-path dst references for validating hardware consumers. Mark references held only for that purpose so packet lookup and GC keep their existing route-validation policy. Validate without creating a neighbour, and report missing or unsupported context as unavailable. For untagged bridge paths, resolve the bridge neighbour through the FDB and compare the physical transmit port. Return the reverse cached peer MAC when requested, so ingress guards use the owner's authoritative peer. Allow the bridge STP accessor under either RTNL or RCU for flow workers.

Notify forwarding caches before FDB movement or deletion and after publication, including administrative dynamic entries hidden from switchdev. Track a generation per network namespace for flows traversing a bridge, sampled before path construction. Reject stale construction, packet lookup, GC and hardware admission. This also retires software- only and hardware-capacity fallback owners after a client moves, without walking flowtables while bridge learning holds its locks. Non-bridge flows keep their existing semantics.

Invalidation marks the owning connection for teardown. Owners retain the cookie through an RCU grace period after DESTROY; drivers stop calling back when their rules are destroyed. Conntrack ownership remains held until asynchronous deletion has completed.

---
Changes in v2:
- Validate the owner's cached route and neighbour without allocating entries; missing context is unavailable validation rather than proof of a stale software path.
- Resolve untagged bridge neighbours through the FDB and return the authoritative reverse peer MAC for ingress guards. Permit the bridge STP accessor under RCU as well as RTNL.
- Notify forwarding caches around FDB mutation and publication. Track a per-network-namespace generation for bridge paths so software-only and capacity-fallback owners also retire on moves, deletion and aging. Preserve non-bridge cache semantics.

 include/net/flow_offload.h            |  14 +++
 include/net/netevent.h                |   1 +
 include/net/netfilter/nf_flow_table.h |  13 ++-
 include/net/netns/flow_table.h        |   3 +
 net/bridge/br_fdb.c                   |  26 ++++-
 net/bridge/br_stp.c                   |   7 +-
 net/netfilter/nf_flow_table_core.c    |  57 ++++++++++-
 net/netfilter/nf_flow_table_offload.c | 139 ++++++++++++++++++++++++++
 net/netfilter/nf_flow_table_path.c    |   8 ++
 net/netfilter/nft_flow_offload.c      |   6 +-
 10 files changed, 257 insertions(+), 17 deletions(-)
include/net/flow_offload.h +14 -0
index 70a02ee143080..ab5c0677debb4 100644
@@ -697,6 +697,20 @@ struct flow_cls_offload {
 	bool use_act_stats;
 	unsigned long cookie;
 	struct flow_rule *rule;
+	/* Optional owner notification when a rule no longer represents the path.
+	 * Call under RCU; the owner retains the cookie and callback until a
+	 * grace period after DESTROY. Drivers must stop new calls at DESTROY.
+	 * The callback must not sleep or call back into the offload driver.
+	 */
+	void (*invalidate)(unsigned long cookie);
+	/* Optional cached-path validation, called under RCU during REPLACE.
+	 * Return 0 for a valid path, -ESTALE for a demonstrably stale path,
+	 * or -EOPNOTSUPP when validation is unavailable. Do not sleep or
+	 * call back into the driver. The callback does not invalidate its owner.
+	 * If ingress_mac is non-NULL, also return the peer MAC from the cached
+	 * reverse Ethernet path, or -EOPNOTSUPP if it is unavailable.
+	 */
+	int (*validate)(unsigned long cookie, u8 *ingress_mac);
 	struct flow_stats stats;
 	u32 classid;
 };
include/net/netevent.h +1 -0
index 1be3757a8b7f0..68258accc9eab 100644
@@ -30,6 +30,7 @@ enum netevent_notif_type {
 	NETEVENT_IPV4_MPATH_HASH_UPDATE, /* arg is struct net ptr */
 	NETEVENT_IPV6_MPATH_HASH_UPDATE, /* arg is struct net ptr */
 	NETEVENT_IPV4_FWD_UPDATE_PRIORITY_UPDATE, /* arg is struct net ptr */
+	NETEVENT_BRIDGE_FDB_UPDATE, /* arg is the bridge net_device ptr */
 };
 
 int register_netevent_notifier(struct notifier_block *nb);
include/net/netfilter/nf_flow_table.h +10 -3
index 5b22d31cb1407..c9dcd9bc8d3d3 100644
@@ -154,7 +154,8 @@ struct flow_offload_tuple {
 					encap_num:2,
 					needs_gso_segment:1,
 					tun_num:2,
-					in_vlan_ingress:2;
+					in_vlan_ingress:2,
+					dst_validation_only:1;
 	u16				mtu;
 	u32				dst_cookie;
 	struct dst_entry		*dst_cache;
@@ -190,6 +191,7 @@ enum nf_flow_flags {
 	NF_FLOW_HW_DEAD,
 	NF_FLOW_HW_BIDIRECTIONAL,
 	NF_FLOW_HW_ESTABLISHED,
+	NF_FLOW_BRIDGE,
 };
 
 enum flow_offload_type {
@@ -203,6 +205,7 @@ struct flow_offload {
 	unsigned long				flags;
 	u16					type;
 	u32					timeout;
+	u32					bridge_genid;
 	struct rcu_head				rcu_head;
 };
 
@@ -210,6 +213,7 @@ struct flow_offload {
 #define nf_flowtable_time_stamp	(u32)jiffies
 
 unsigned long flow_offload_get_timeout(struct flow_offload *flow);
+bool nf_flow_bridge_stale(const struct flow_offload *flow);
 
 static inline __s32 nf_flow_timeout_delta(unsigned int timeout)
 {
@@ -217,6 +221,8 @@ static inline __s32 nf_flow_timeout_delta(unsigned int timeout)
 }
 
 struct nf_flow_route {
+	u32 bridge_genid;
+	bool uses_bridge;
 	struct {
 		struct dst_entry		*dst;
 		struct {
@@ -305,7 +311,7 @@ nf_flow_table_offload_del_cb(struct nf_flowtable *flow_table,
 }
 
 void flow_offload_route_init(struct flow_offload *flow,
-			     struct nf_flow_route *route);
+			     struct nf_flow_route *route, bool keep_dst);
 
 int flow_offload_add(struct nf_flowtable *flow_table, struct flow_offload *flow);
 void flow_offload_refresh(struct nf_flowtable *flow_table,
@@ -313,7 +319,8 @@ void flow_offload_refresh(struct nf_flowtable *flow_table,
 
 static inline bool nf_flow_dst_check(struct flow_offload_tuple *tuple)
 {
-	if (!tuple->dst_cache)
+	/* A driver-only reference must not change direct-path/GC semantics. */
+	if (!tuple->dst_cache || tuple->dst_validation_only)
 		return true;
 
 	return dst_check(tuple->dst_cache, tuple->dst_cookie);
include/net/netns/flow_table.h +3 -0
index 1c5fc657e2675..b286b23116ac1 100644
@@ -2,6 +2,8 @@
 #ifndef __NETNS_FLOW_TABLE_H
 #define __NETNS_FLOW_TABLE_H
 
+#include <linux/atomic.h>
+
 struct nf_flow_table_stat {
 	unsigned int count_wq_add;
 	unsigned int count_wq_del;
@@ -10,5 +12,6 @@ struct nf_flow_table_stat {
 
 struct netns_ft {
 	struct nf_flow_table_stat __percpu *stat;
+	atomic_t bridge_genid;
 };
 #endif
net/bridge/br_fdb.c +22 -4
index b601245ad9239..922c34fdfecd4 100644
@@ -20,6 +20,7 @@
 #include <linux/atomic.h>
 #include <linux/unaligned.h>
 #include <linux/if_vlan.h>
+#include <net/netevent.h>
 #include <net/switchdev.h>
 #include <trace/events/bridge.h>
 #include "br_private.h"
@@ -174,6 +175,15 @@ static inline size_t fdb_nlmsg_size(void)
 		+ nla_total_size(sizeof(u8)); /* NFEA_ACTIVITY_NOTIFY */
 }
 
+/* Forwarding caches must also observe FDB changes which are intentionally
+ * hidden from switchdev, such as software-only administrative entries.
+ * Notify before changing an existing destination and after publication.
+ */
+static void fdb_notify_cache(struct net_bridge *br)
+{
+	call_netevent_notifiers(NETEVENT_BRIDGE_FDB_UPDATE, br->dev);
+}
+
 static void fdb_notify(struct net_bridge *br,
 		       const struct net_bridge_fdb_entry *fdb, int type,
 		       bool swdev_notify)
@@ -182,6 +192,7 @@ static void fdb_notify(struct net_bridge *br,
 	struct sk_buff *skb;
 	int err = -ENOBUFS;
 
+	fdb_notify_cache(br);
 	if (swdev_notify)
 		br_switchdev_fdb_notify(br, fdb, type);
 
@@ -315,6 +326,7 @@ static void fdb_del_hw_addr(struct net_bridge *br, const unsigned char *addr)
 static void fdb_delete(struct net_bridge *br, struct net_bridge_fdb_entry *f,
 		       bool swdev_notify)
 {
+	fdb_notify_cache(br);
 	trace_fdb_delete(br, f, br_fdb_dst_port(f));
 
 	if (test_bit(BR_FDB_STATIC, &f->flags))
@@ -350,8 +362,10 @@ static void fdb_delete_local(struct net_bridge *br,
 		vg = nbp_vlan_group(op);
 		if (op != p && ether_addr_equal(op->dev->dev_addr, addr) &&
 		    (!vid || br_vlan_find(vg, vid))) {
+			fdb_notify_cache(br);
 			br_fdb_dst_write(f, br_port_to_dst(op));
 			clear_bit(BR_FDB_ADDED_BY_USER, &f->flags);
+			fdb_notify_cache(br);
 			return;
 		}
 	}
@@ -361,8 +375,10 @@ static void fdb_delete_local(struct net_bridge *br,
 	/* Maybe bridge device has same hw addr? */
 	if (p && ether_addr_equal(br->dev->dev_addr, addr) &&
 	    (!vid || (v && br_vlan_should_use(v)))) {
+		fdb_notify_cache(br);
 		br_fdb_dst_write(f, br_port_to_dst(NULL));
 		clear_bit(BR_FDB_ADDED_BY_USER, &f->flags);
+		fdb_notify_cache(br);
 		return;
 	}
 
@@ -409,6 +425,7 @@ static struct net_bridge_fdb_entry *fdb_create(struct net_bridge *br,
 		return NULL;
 
 	memcpy(fdb->key.addr.addr, addr, ETH_ALEN);
+	fdb_notify_cache(br);
 	br_fdb_dst_write(fdb, dst);
 	fdb->key.vlan_id = vid;
 	fdb->flags = flags;
@@ -1030,6 +1047,7 @@ static void __fdb_update(struct net_bridge *br,
 		      !test_bit(BR_FDB_STICKY, &fdb->flags)))) {
 		if (source != old_port) {
 			br_switchdev_fdb_notify(br, fdb, RTM_DELNEIGH);
+			fdb_notify_cache(br);
 			br_fdb_dst_write(fdb, dst);
 			fdb_modified = true;
 			/* take over HW learned entry */
@@ -1194,7 +1212,7 @@ static bool fdb_handle_notify(struct net_bridge_fdb_entry *fdb, u8 notify)
 	return modified;
 }
 
-static bool fdb_update_dst(struct net_bridge_fdb_entry *fdb,
+static bool fdb_update_dst(struct net_bridge *br, struct net_bridge_fdb_entry *fdb,
 			   struct net_bridge_dst old_dst,
 			   struct net_bridge_dst dst)
 {
@@ -1205,7 +1223,7 @@ static bool fdb_update_dst(struct net_bridge_fdb_entry *fdb,
 		br_fdb_dst_replace(fdb, old_dst, dst);
 		return false;
 	}
-
+	fdb_notify_cache(br);
 	br_fdb_dst_write(fdb, dst);
 	return true;
 }
@@ -1263,7 +1281,7 @@ static int fdb_add_entry(struct net_bridge *br, struct net_bridge_dst dst,
 			return -EEXIST;
 
 		old_dst = br_fdb_dst_read(fdb);
-		modified = fdb_update_dst(fdb, old_dst, dst);
+		modified = fdb_update_dst(br, fdb, old_dst, dst);
 
 		set_bit(BR_FDB_ADDED_BY_USER, &fdb->flags);
 		if (test_and_clear_bit(BR_FDB_DYNAMIC_LEARNED, &fdb->flags))
@@ -1644,7 +1662,7 @@ int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p,
 
 		WRITE_ONCE(fdb->updated, jiffies);
 
-		modified = fdb_update_dst(fdb, old_dst, dst);
+		modified = fdb_update_dst(br, fdb, old_dst, dst);
 
 		if (test_and_set_bit(BR_FDB_ADDED_BY_EXT_LEARN, &fdb->flags)) {
 			/* Refresh entry */
net/bridge/br_stp.c +3 -4
index c7e7e924f1557..5717bf33c2667 100644
@@ -70,17 +70,16 @@ void br_set_state(struct net_bridge_port *p, unsigned int state)
 	}
 }
 
+/* Caller holds RTNL or RCU. */
 u8 br_port_get_stp_state(const struct net_device *dev)
 {
 	struct net_bridge_port *p;
 
-	ASSERT_RTNL();
-
-	p = br_port_get_rtnl(dev);
+	p = br_port_get_rtnl_rcu(dev);
 	if (!p)
 		return BR_STATE_DISABLED;
 
-	return p->state;
+	return READ_ONCE(p->state);
 }
 EXPORT_SYMBOL_GPL(br_port_get_stp_state);
 
net/netfilter/nf_flow_table_core.c +52 -5

128 lines not on this page · raw message

net/netfilter/nf_flow_table_offload.c +139 -0

158 lines not on this page · raw message

net/netfilter/nf_flow_table_path.c +8 -0
index 841f099434d98..de862e3e7770d 100644
@@ -96,6 +96,7 @@ struct nft_forward_info {
 	u8 h_source[ETH_ALEN];
 	u8 h_dest[ETH_ALEN];
 	bool needs_gso_segment;
+	bool uses_bridge;
 	enum flow_offload_xmit_type xmit_type;
 };
 
@@ -157,6 +158,7 @@ static int nft_dev_path_info(struct net_device_path_stack *stack,
 			}
 			break;
 		case DEV_PATH_BRIDGE:
+			info->uses_bridge = true;
 			if (is_zero_ether_addr(info->h_source))
 				memcpy(info->h_source, path->dev->dev_addr, ETH_ALEN);
 
@@ -265,6 +267,7 @@ static int nft_dev_forward_path(const struct nft_pktinfo *pkt,
 		route->tuple[dir].xmit_type = info.xmit_type;
 	}
 	route->tuple[dir].out.needs_gso_segment = info.needs_gso_segment;
+	route->uses_bridge |= info.uses_bridge;
 
 	return 0;
 }
@@ -277,6 +280,11 @@ int nft_flow_route(const struct nft_pktinfo *pkt, const struct nf_conn *ct,
 	struct dst_entry *other_dst = NULL;
 	struct flowi fl;
 
+	/* Snapshot before either FDB lookup. An update during path resolution
+	 * must invalidate the resulting cache, including software-only owners.
+	 */
+	route->bridge_genid = atomic_read_acquire(&nft_net(pkt)->ft.bridge_genid);
+
 	memset(&fl, 0, sizeof(fl));
 	switch (nft_pf(pkt)) {
 	case NFPROTO_IPV4:
net/netfilter/nft_flow_offload.c +5 -1
index d3c5651dd6997..05207ca808ee7 100644
@@ -113,7 +113,11 @@ static void nft_flow_offload_eval(const struct nft_expr *expr,
 	if (!flow)
 		goto err_flow_alloc;
 
-	flow_offload_route_init(flow, &route);
+	/* Hardware admission may validate the route used to build a direct path.
+	 * Keep its reference and cookie instead of reconstructing a lookup with
+	 * incomplete policy-routing inputs in the driver.
+	 */
+	flow_offload_route_init(flow, &route, nf_flowtable_hw_offload(flowtable));
 	if (tcph)
 		flow_offload_ct_tcp(ct);
 
#4 lore raw

Re: [PATCH net-next v2 3/6] net: flow_offload: allow drivers to validate and invalidate cached paths

Quoted 43 lines · Florian Fainelli

A classifier can lack the mark, DSCP and output-interface context used to select its forwarding path. Provide optional owner validation and invalidation callbacks so an accelerator can validate the actual cached routes and Ethernet peers instead of treating a partial FIB lookup as proof that a software path is stale.

Retain direct-path dst references for validating hardware consumers. Mark references held only for that purpose so packet lookup and GC keep their existing route-validation policy. Validate without creating a neighbour, and report missing or unsupported context as unavailable. For untagged bridge paths, resolve the bridge neighbour through the FDB and compare the physical transmit port. Return the reverse cached peer MAC when requested, so ingress guards use the owner's authoritative peer. Allow the bridge STP accessor under either RTNL or RCU for flow workers.

Notify forwarding caches before FDB movement or deletion and after publication, including administrative dynamic entries hidden from switchdev. Track a generation per network namespace for flows traversing a bridge, sampled before path construction. Reject stale construction, packet lookup, GC and hardware admission. This also retires software- only and hardware-capacity fallback owners after a client moves, without walking flowtables while bridge learning holds its locks. Non-bridge flows keep their existing semantics.

Invalidation marks the owning connection for teardown. Owners retain the cookie through an RCU grace period after DESTROY; drivers stop calling back when their rules are destroyed. Conntrack ownership remains held until asynchronous deletion has completed.

---
Changes in v2:
- Validate the owner's cached route and neighbour without allocating entries; missing context is unavailable validation rather than proof of a stale software path.
- Resolve untagged bridge neighbours through the FDB and return the authoritative reverse peer MAC for ingress guards. Permit the bridge STP accessor under RCU as well as RTNL.
- Notify forwarding caches around FDB mutation and publication. Track a per-network-namespace generation for bridge paths so software-only and capacity-fallback owners also retire on moves, deletion and aging. Preserve non-bridge cache semantics.

Quoted 12 lines
  include/net/flow_offload.h            |  14 +++
  include/net/netevent.h                |   1 +
  include/net/netfilter/nf_flow_table.h |  13 ++-
  include/net/netns/flow_table.h        |   3 +
  net/bridge/br_fdb.c                   |  26 ++++-
  net/bridge/br_stp.c                   |   7 +-
  net/netfilter/nf_flow_table_core.c    |  57 ++++++++++-
  net/netfilter/nf_flow_table_offload.c | 139 ++++++++++++++++++++++++++
  net/netfilter/nf_flow_table_path.c    |   8 ++
  net/netfilter/nft_flow_offload.c      |   6 +-
  10 files changed, 257 insertions(+), 17 deletions(-)

In general I'm not a fan of sprinkling a new notification around the bridge, I've left a few comments and a potential alternative that is more contained, but at the very least if a new notification mechanism is at all needed (which I'm yet not convinced of) I think the scope should be per-bridge instead of netns-global. As it stands any FDB change in the netns (learning, aging) invalidates all bridged flows, including software only flowtables.

More below.

Quoted 30 lines
include/net/flow_offload.h +14 -0
index 70a02ee143080..ab5c0677debb4 100644
@@ -697,6 +697,20 @@ struct flow_cls_offload {
  	bool use_act_stats;
  	unsigned long cookie;
  	struct flow_rule *rule;
+	/* Optional owner notification when a rule no longer represents the path.
+	 * Call under RCU; the owner retains the cookie and callback until a
+	 * grace period after DESTROY. Drivers must stop new calls at DESTROY.
+	 * The callback must not sleep or call back into the offload driver.
+	 */
+	void (*invalidate)(unsigned long cookie);
+	/* Optional cached-path validation, called under RCU during REPLACE.
+	 * Return 0 for a valid path, -ESTALE for a demonstrably stale path,
+	 * or -EOPNOTSUPP when validation is unavailable. Do not sleep or
+	 * call back into the driver. The callback does not invalidate its owner.
+	 * If ingress_mac is non-NULL, also return the peer MAC from the cached
+	 * reverse Ethernet path, or -EOPNOTSUPP if it is unavailable.
+	 */
+	int (*validate)(unsigned long cookie, u8 *ingress_mac);
  	struct flow_stats stats;
  	u32 classid;
  };
include/net/netevent.h +0 -0
index 1be3757a8b7f0..68258accc9eab 100644

include/net/netevent.h enum netevent_notif_type { · line 34

Quoted 5 lines
include/net/netevent.h +1 -0
@@ -30,6 +30,7 @@ enum netevent_notif_type {
  	NETEVENT_IPV4_MPATH_HASH_UPDATE, /* arg is struct net ptr */
  	NETEVENT_IPV6_MPATH_HASH_UPDATE, /* arg is struct net ptr */
  	NETEVENT_IPV4_FWD_UPDATE_PRIORITY_UPDATE, /* arg is struct net ptr */
+	NETEVENT_BRIDGE_FDB_UPDATE, /* arg is the bridge net_device ptr */
  };

The netevent chain is global and shared by all event types so each fdb change now walks every registered netevent listener (mlx5 representors, mlxsw, cxgb4, rdma cm and so on) from the learning path in softirq and under br->hash_lock. The event carries no information about the entry, so it is only usable as a gen bump for this one consumer.

Could the bridge keep the generation itself or could the flowtable revalidate the bridge hop per flow instead of adding a global event?

nf_flow_offload_bridge_path added later in this patch already resolves the current FDB port through dev_fill_forward_path under RCU and compares it with tuple->out.ifidx. Could that same per flow check be run from nf_flow_offload_gc_step for NF_FLOW_BRIDGE flows? That would only retire the flows whose entry actually moved or disappeared, needs no bridge changes and the staleness window would be the GC interval which hardware flows already have with this patch.

In case the event stays could it at least be gated by a static key that the flowtable enables only while a flowtable exists so systems without flowtables do not pay for it?

Quoted 125 lines
include/net/netevent.h +0 -0
  int register_netevent_notifier(struct notifier_block *nb);
include/net/netfilter/nf_flow_table.h +10 -3
index 5b22d31cb1407..c9dcd9bc8d3d3 100644
@@ -154,7 +154,8 @@ struct flow_offload_tuple {
  					encap_num:2,
  					needs_gso_segment:1,
  					tun_num:2,
-					in_vlan_ingress:2;
+					in_vlan_ingress:2,
+					dst_validation_only:1;
  	u16				mtu;
  	u32				dst_cookie;
  	struct dst_entry		*dst_cache;
@@ -190,6 +191,7 @@ enum nf_flow_flags {
  	NF_FLOW_HW_DEAD,
  	NF_FLOW_HW_BIDIRECTIONAL,
  	NF_FLOW_HW_ESTABLISHED,
+	NF_FLOW_BRIDGE,
  };
 
  enum flow_offload_type {
@@ -203,6 +205,7 @@ struct flow_offload {
  	unsigned long				flags;
  	u16					type;
  	u32					timeout;
+	u32					bridge_genid;
  	struct rcu_head				rcu_head;
  };
 
@@ -210,6 +213,7 @@ struct flow_offload {
  #define nf_flowtable_time_stamp	(u32)jiffies
 
  unsigned long flow_offload_get_timeout(struct flow_offload *flow);
+bool nf_flow_bridge_stale(const struct flow_offload *flow);
 
  static inline __s32 nf_flow_timeout_delta(unsigned int timeout)
  {
@@ -217,6 +221,8 @@ static inline __s32 nf_flow_timeout_delta(unsigned int timeout)
  }
 
  struct nf_flow_route {
+	u32 bridge_genid;
+	bool uses_bridge;
  	struct {
  		struct dst_entry		*dst;
  		struct {
@@ -305,7 +311,7 @@ nf_flow_table_offload_del_cb(struct nf_flowtable *flow_table,
  }
 
  void flow_offload_route_init(struct flow_offload *flow,
-			     struct nf_flow_route *route);
+			     struct nf_flow_route *route, bool keep_dst);
 
  int flow_offload_add(struct nf_flowtable *flow_table, struct flow_offload *flow);
  void flow_offload_refresh(struct nf_flowtable *flow_table,
@@ -313,7 +319,8 @@ void flow_offload_refresh(struct nf_flowtable *flow_table,
 
  static inline bool nf_flow_dst_check(struct flow_offload_tuple *tuple)
  {
-	if (!tuple->dst_cache)
+	/* A driver-only reference must not change direct-path/GC semantics. */
+	if (!tuple->dst_cache || tuple->dst_validation_only)
  		return true;
 
  	return dst_check(tuple->dst_cache, tuple->dst_cookie);
include/net/netns/flow_table.h +3 -0
index 1c5fc657e2675..b286b23116ac1 100644
@@ -2,6 +2,8 @@
  #ifndef __NETNS_FLOW_TABLE_H
  #define __NETNS_FLOW_TABLE_H
 
+#include <linux/atomic.h>
+
  struct nf_flow_table_stat {
  	unsigned int count_wq_add;
  	unsigned int count_wq_del;
@@ -10,5 +12,6 @@ struct nf_flow_table_stat {
 
  struct netns_ft {
  	struct nf_flow_table_stat __percpu *stat;
+	atomic_t bridge_genid;
  };
  #endif
net/bridge/br_fdb.c +11 -0
index b601245ad9239..922c34fdfecd4 100644
@@ -20,6 +20,7 @@
  #include <linux/atomic.h>
  #include <linux/unaligned.h>
  #include <linux/if_vlan.h>
+#include <net/netevent.h>
  #include <net/switchdev.h>
  #include <trace/events/bridge.h>
  #include "br_private.h"
@@ -174,6 +175,15 @@ static inline size_t fdb_nlmsg_size(void)
  		+ nla_total_size(sizeof(u8)); /* NFEA_ACTIVITY_NOTIFY */
  }
 
+/* Forwarding caches must also observe FDB changes which are intentionally
+ * hidden from switchdev, such as software-only administrative entries.
+ * Notify before changing an existing destination and after publication.
+ */
+static void fdb_notify_cache(struct net_bridge *br)
+{
+	call_netevent_notifiers(NETEVENT_BRIDGE_FDB_UPDATE, br->dev);
+}
+
  static void fdb_notify(struct net_bridge *br,
  		       const struct net_bridge_fdb_entry *fdb, int type,
  		       bool swdev_notify)
@@ -182,6 +192,7 @@ static void fdb_notify(struct net_bridge *br,
  	struct sk_buff *skb;
  	int err = -ENOBUFS;
 
+	fdb_notify_cache(br);
  	if (swdev_notify)
  		br_switchdev_fdb_notify(br, fdb, type);
 

net/bridge/br_fdb.c static void fdb_del_hw_addr(struct net_bridge *br, const unsigned char *addr) · line 330

Quoted 5 lines
net/bridge/br_fdb.c +1 -0
@@ -315,6 +326,7 @@ static void fdb_del_hw_addr(struct net_bridge *br, const unsigned char *addr)
  static void fdb_delete(struct net_bridge *br, struct net_bridge_fdb_entry *f,
  		       bool swdev_notify)
  {
+	fdb_notify_cache(br);
  	trace_fdb_delete(br, f, br_fdb_dst_port(f));

fdb_delete already ends with fdb_notify(br, f, RTM_DELNEIGH), which now also calls fdb_notify_cache so each deletion bumps the generation twice.

Quoted 25 lines
net/bridge/br_fdb.c +4 -0
  	if (test_bit(BR_FDB_STATIC, &f->flags))
@@ -350,8 +362,10 @@ static void fdb_delete_local(struct net_bridge *br,
  		vg = nbp_vlan_group(op);
  		if (op != p && ether_addr_equal(op->dev->dev_addr, addr) &&
  		    (!vid || br_vlan_find(vg, vid))) {
+			fdb_notify_cache(br);
  			br_fdb_dst_write(f, br_port_to_dst(op));
  			clear_bit(BR_FDB_ADDED_BY_USER, &f->flags);
+			fdb_notify_cache(br);
  			return;
  		}
  	}
@@ -361,8 +375,10 @@ static void fdb_delete_local(struct net_bridge *br,
  	/* Maybe bridge device has same hw addr? */
  	if (p && ether_addr_equal(br->dev->dev_addr, addr) &&
  	    (!vid || (v && br_vlan_should_use(v)))) {
+		fdb_notify_cache(br);
  		br_fdb_dst_write(f, br_port_to_dst(NULL));
  		clear_bit(BR_FDB_ADDED_BY_USER, &f->flags);
+		fdb_notify_cache(br);
  		return;
  	}
 

net/bridge/br_fdb.c static struct net_bridge_fdb_entry *fdb_create(struct net_bridge *br, · line 429

Quoted 5 lines
net/bridge/br_fdb.c +1 -0
@@ -409,6 +425,7 @@ static struct net_bridge_fdb_entry *fdb_create(struct net_bridge *br,
  		return NULL;
 
  	memcpy(fdb->key.addr.addr, addr, ETH_ALEN);
+	fdb_notify_cache(br);
  	br_fdb_dst_write(fdb, dst);

The entry isn't published yet at this point so nothing can have resolved a path through it. Is this notification needed at all? All callers of fdb_create follow it with fdb_notify which bumps the generation again.

Quoted 59 lines
net/bridge/br_fdb.c +5 -4
  	fdb->key.vlan_id = vid;
  	fdb->flags = flags;
@@ -1030,6 +1047,7 @@ static void __fdb_update(struct net_bridge *br,
  		      !test_bit(BR_FDB_STICKY, &fdb->flags)))) {
  		if (source != old_port) {
  			br_switchdev_fdb_notify(br, fdb, RTM_DELNEIGH);
+			fdb_notify_cache(br);
  			br_fdb_dst_write(fdb, dst);
  			fdb_modified = true;
  			/* take over HW learned entry */
@@ -1194,7 +1212,7 @@ static bool fdb_handle_notify(struct net_bridge_fdb_entry *fdb, u8 notify)
  	return modified;
  }
 
-static bool fdb_update_dst(struct net_bridge_fdb_entry *fdb,
+static bool fdb_update_dst(struct net_bridge *br, struct net_bridge_fdb_entry *fdb,
  			   struct net_bridge_dst old_dst,
  			   struct net_bridge_dst dst)
  {
@@ -1205,7 +1223,7 @@ static bool fdb_update_dst(struct net_bridge_fdb_entry *fdb,
  		br_fdb_dst_replace(fdb, old_dst, dst);
  		return false;
  	}
-
+	fdb_notify_cache(br);
  	br_fdb_dst_write(fdb, dst);
  	return true;
  }
@@ -1263,7 +1281,7 @@ static int fdb_add_entry(struct net_bridge *br, struct net_bridge_dst dst,
  			return -EEXIST;
 
  		old_dst = br_fdb_dst_read(fdb);
-		modified = fdb_update_dst(fdb, old_dst, dst);
+		modified = fdb_update_dst(br, fdb, old_dst, dst);
 
  		set_bit(BR_FDB_ADDED_BY_USER, &fdb->flags);
  		if (test_and_clear_bit(BR_FDB_DYNAMIC_LEARNED, &fdb->flags))
@@ -1644,7 +1662,7 @@ int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p,
 
  		WRITE_ONCE(fdb->updated, jiffies);
 
-		modified = fdb_update_dst(fdb, old_dst, dst);
+		modified = fdb_update_dst(br, fdb, old_dst, dst);
 
  		if (test_and_set_bit(BR_FDB_ADDED_BY_EXT_LEARN, &fdb->flags)) {
  			/* Refresh entry */
net/bridge/br_stp.c +1 -0
index c7e7e924f1557..5717bf33c2667 100644
@@ -70,17 +70,16 @@ void br_set_state(struct net_bridge_port *p, unsigned int state)
  	}
  }
 
+/* Caller holds RTNL or RCU. */
  u8 br_port_get_stp_state(const struct net_device *dev)
  {
  	struct net_bridge_port *p;
 

net/bridge/br_stp.c void br_set_state(struct net_bridge_port *p, unsigned int state) · line 83

Quoted 10 lines
net/bridge/br_stp.c +2 -4
-	ASSERT_RTNL();
-
-	p = br_port_get_rtnl(dev);
+	p = br_port_get_rtnl_rcu(dev);
  	if (!p)
  		return BR_STATE_DISABLED;
 
-	return p->state;
+	return READ_ONCE(p->state);
  }

Nothing in this patch calls br_port_get_stp_state under rcu. Could this go into the patch that adds the RCU user, or a separate bridge patch?

Also br_set_state still writes the state with a plain store instead of WRITE_ONCE.

The patch changes the bridge, netevent, the flow_offload API and the netfilter flowtable at once. Could it be split so the bridge and netevent parts can be reviewed on their own?

Cheers,
Nik

author maintainer
#5 lore raw

Re: [PATCH net-next v2 3/6] net: flow_offload: allow drivers to validate and invalidate cached paths

Quoted 58 lines · Nikolay Aleksandrov
Quoted 53 lines · Florian Fainelli

A classifier can lack the mark, DSCP and output-interface context used to select its forwarding path. Provide optional owner validation and invalidation callbacks so an accelerator can validate the actual cached routes and Ethernet peers instead of treating a partial FIB lookup as proof that a software path is stale.

Retain direct-path dst references for validating hardware consumers. Mark references held only for that purpose so packet lookup and GC keep their existing route-validation policy. Validate without creating a neighbour, and report missing or unsupported context as unavailable. For untagged bridge paths, resolve the bridge neighbour through the FDB and compare the physical transmit port. Return the reverse cached peer MAC when requested, so ingress guards use the owner's authoritative peer. Allow the bridge STP accessor under either RTNL or RCU for flow workers.

Notify forwarding caches before FDB movement or deletion and after publication, including administrative dynamic entries hidden from switchdev. Track a generation per network namespace for flows traversing a bridge, sampled before path construction. Reject stale construction, packet lookup, GC and hardware admission. This also retires software- only and hardware-capacity fallback owners after a client moves, without walking flowtables while bridge learning holds its locks. Non-bridge flows keep their existing semantics.

Invalidation marks the owning connection for teardown. Owners retain the cookie through an RCU grace period after DESTROY; drivers stop calling back when their rules are destroyed. Conntrack ownership remains held until asynchronous deletion has completed.

---
Changes in v2:
   - Validate the owner's cached route and neighbour without allocating entries; missing context is unavailable validation rather than proof of a stale software path.
   - Resolve untagged bridge neighbours through the FDB and return the authoritative reverse peer MAC for ingress guards. Permit the bridge STP accessor under RCU as well as RTNL.
   - Notify forwarding caches around FDB mutation and publication. Track a per-network-namespace generation for bridge paths so software- only and capacity-fallback owners also retire on moves, deletion and aging. Preserve non-bridge cache semantics.

  include/net/flow_offload.h            |  14 +++ include/net/netevent.h                |   1 + include/net/netfilter/nf_flow_table.h |  13 ++- include/net/netns/flow_table.h        |   3 + net/bridge/br_fdb.c                   |  26 ++++- net/bridge/br_stp.c                   |   7 +- net/netfilter/nf_flow_table_core.c    |  57 ++++++++++- net/netfilter/nf_flow_table_offload.c | 139 ++++++++++++++++++++++++++ net/netfilter/nf_flow_table_path.c    |   8 ++ net/netfilter/nft_flow_offload.c      |   6 +-

Quoted 2 lines
  10 files changed, 257 insertions(+), 17 deletions(-)
Quoted 4 lines

In general I'm not a fan of sprinkling a new notification around the bridge, I've left a few comments and a potential alternative that is more contained, but at the very least if a new notification mechanism is at all needed (which I'm yet not convinced of) I think the scope should be per-bridge instead of netns-global.

Agreed. I've taken the per-flow GC approach you suggested and removed the new notification mechanism entirely in the next iteration.

Quoted 2 lines

As it stands any FDB change in the netns (learning, aging) invalidates all bridged flows, including software only flowtables.

Yes, that was unnecessarily broad. The revised implementation checks each flow's cached bridge destination and retires it when that path becomes stale. Changes involving another MAC or another bridge leave the flow cached.

Quoted 40 lines

More below.

Quoted 37 lines
include/net/flow_offload.h +1 -0
index 70a02ee143080..ab5c0677debb4 100644
@@ -697,6 +697,20 @@ struct flow_cls_offload {
       bool use_act_stats;
       unsigned long cookie;
       struct flow_rule *rule;
+    /* Optional owner notification when a rule no longer represents 

the path.
+     * Call under RCU; the owner retains the cookie and callback until a +     * grace period after DESTROY. Drivers must stop new calls at DESTROY.
+     * The callback must not sleep or call back into the offload driver. +     */
+    void (*invalidate)(unsigned long cookie);
+    /* Optional cached-path validation, called under RCU during REPLACE. +     * Return 0 for a valid path, -ESTALE for a demonstrably stale path, +     * or -EOPNOTSUPP when validation is unavailable. Do not sleep or +     * call back into the driver. The callback does not invalidate its owner.
+     * If ingress_mac is non-NULL, also return the peer MAC from the cached
+     * reverse Ethernet path, or -EOPNOTSUPP if it is unavailable. +     */
+    int (*validate)(unsigned long cookie, u8 *ingress_mac); struct flow_stats stats;
      u32 classid;
  };

include/net/netevent.h +0 -0
index 1be3757a8b7f0..68258accc9eab 100644
@@ -30,6 +30,7 @@ enum netevent_notif_type {

      NETEVENT_IPV4_MPATH_HASH_UPDATE, /* arg is struct net ptr */ NETEVENT_IPV6_MPATH_HASH_UPDATE, /* arg is struct net ptr */ NETEVENT_IPV4_FWD_UPDATE_PRIORITY_UPDATE, /* arg is struct net ptr */

Quoted 8 lines
Quoted 2 lines

+    NETEVENT_BRIDGE_FDB_UPDATE, /* arg is the bridge net_device ptr */ };

The netevent chain is global and shared by all event types so each fdb change now walks every registered netevent listener (mlx5 representors, mlxsw, cxgb4, rdma cm and so on) from the learning path in softirq and under br->hash_lock. The event carries no information about the entry, so it is only usable as a gen bump for this one consumer.

I've removed NETEVENT_BRIDGE_FDB_UPDATE and all its call sites. There is no longer a notifier-chain traversal from bridge learning, publication or deletion. br_fdb.c and the netevent header are unchanged from the base.

Quoted 3 lines

Could the bridge keep the generation itself or could the flowtable revalidate the bridge hop per flow instead of adding a global event?

Yes, the flowtable now revalidates the bridge hop per flow. Software bridge caches retain validation-only route references, allowing the check to use their cached bridge destination MAC and physical egress. This also covers software-only and hardware-capacity fallback owners without introducing bridge generation state.

Quoted 8 lines

nf_flow_offload_bridge_path added later in this patch already resolves the current FDB port through dev_fill_forward_path under RCU and compares it with tuple->out.ifidx. Could that same per flow check be run from nf_flow_offload_gc_step for NF_FLOW_BRIDGE flows? That would only retire the flows whose entry actually moved or disappeared, needs no bridge changes and the staleness window would be the GC interval which hardware flows already have with this patch.

That's the approach I've implemented. GC reuses the bridge-path resolver under RCU and compares the current path against the cached egress and router MAC. Construction and pending hardware admission also recheck the path; packet lookup does not acquire a new FDB check.

The recovery follows GC and queued hardware deletion, and full owner release can require a further GC pass. I've documented that asynchronous window. On BCM53012 the measured full owner release took approximately 903 ms for a software-cache move and 1440 ms for a hardware-to-software move.

Quoted 5 lines

In case the event stays could it at least be gated by a static key that the flowtable enables only while a flowtable exists so systems without flowtables do not pay for it?

The event is gone, so no static key is needed and systems without flowtables incur no new bridge-learning overhead.

Quoted 223 lines
Quoted 116 lines

  int register_netevent_notifier(struct notifier_block *nb);

include/net/netfilter/nf_flow_table.h +9 -3
index 5b22d31cb1407..c9dcd9bc8d3d3 100644
@@ -154,7 +154,8 @@ struct flow_offload_tuple {
                       encap_num:2,
                       needs_gso_segment:1,
                       tun_num:2,
-                    in_vlan_ingress:2;
+                    in_vlan_ingress:2,
+                    dst_validation_only:1;
       u16                mtu;
       u32                dst_cookie;
       struct dst_entry        *dst_cache;
@@ -190,6 +191,7 @@ enum nf_flow_flags {
       NF_FLOW_HW_DEAD,
       NF_FLOW_HW_BIDIRECTIONAL,
       NF_FLOW_HW_ESTABLISHED,
+    NF_FLOW_BRIDGE,
   };
   enum flow_offload_type {
@@ -203,6 +205,7 @@ struct flow_offload {
       unsigned long                flags;
       u16                    type;
       u32                    timeout;
+    u32                    bridge_genid;
       struct rcu_head                rcu_head;
   };
@@ -210,6 +213,7 @@ struct flow_offload {
   #define nf_flowtable_time_stamp    (u32)jiffies
   unsigned long flow_offload_get_timeout(struct flow_offload *flow);
+bool nf_flow_bridge_stale(const struct flow_offload *flow);
   static inline __s32 nf_flow_timeout_delta(unsigned int timeout)
   {
@@ -217,6 +221,8 @@ static inline __s32 nf_flow_timeout_delta(unsigned 
 int timeout)
   }
   struct nf_flow_route {
+    u32 bridge_genid;
+    bool uses_bridge;
       struct {
           struct dst_entry        *dst;
           struct {
@@ -305,7 +311,7 @@ nf_flow_table_offload_del_cb(struct nf_flowtable 
 *flow_table,
   }
   void flow_offload_route_init(struct flow_offload *flow,
-                 struct nf_flow_route *route);
+                 struct nf_flow_route *route, bool keep_dst);
   int flow_offload_add(struct nf_flowtable *flow_table, struct flow_offload *flow);
   void flow_offload_refresh(struct nf_flowtable *flow_table,
@@ -313,7 +319,8 @@ void flow_offload_refresh(struct nf_flowtable 
 *flow_table,
   static inline bool nf_flow_dst_check(struct flow_offload_tuple *tuple)
   {
-    if (!tuple->dst_cache)
+    /* A driver-only reference must not change direct-path/GC 

semantics. */
+    if (!tuple->dst_cache || tuple->dst_validation_only) return true;
      return dst_check(tuple->dst_cache, tuple->dst_cookie);

include/net/netns/flow_table.h +3 -0
index 1c5fc657e2675..b286b23116ac1 100644
@@ -2,6 +2,8 @@
   #ifndef __NETNS_FLOW_TABLE_H
   #define __NETNS_FLOW_TABLE_H
+#include <linux/atomic.h>
+
   struct nf_flow_table_stat {
       unsigned int count_wq_add;
       unsigned int count_wq_del;
@@ -10,5 +12,6 @@ struct nf_flow_table_stat {
   struct netns_ft {
       struct nf_flow_table_stat __percpu *stat;
+    atomic_t bridge_genid;
   };
   #endif
net/bridge/br_fdb.c +1 -0
index b601245ad9239..922c34fdfecd4 100644
@@ -20,6 +20,7 @@
   #include <linux/atomic.h>
   #include <linux/unaligned.h>
   #include <linux/if_vlan.h>
+#include <net/netevent.h>
   #include <net/switchdev.h>
   #include <trace/events/bridge.h>
   #include "br_private.h"
@@ -174,6 +175,15 @@ static inline size_t fdb_nlmsg_size(void)

          + nla_total_size(sizeof(u8)); /* NFEA_ACTIVITY_NOTIFY */ }
+/* Forwarding caches must also observe FDB changes which are intentionally
+ * hidden from switchdev, such as software-only administrative entries.
+ * Notify before changing an existing destination and after publication.
+ */

net/bridge/br_fdb.c +5 -0
+static void fdb_notify_cache(struct net_bridge *br)
+{
+    call_netevent_notifiers(NETEVENT_BRIDGE_FDB_UPDATE, br->dev);
+}
+

  static void fdb_notify(struct net_bridge *br,
                 const struct net_bridge_fdb_entry *fdb, int type, bool swdev_notify)

net/bridge/br_fdb.c +1 -0
@@ -182,6 +192,7 @@ static void fdb_notify(struct net_bridge *br,
       struct sk_buff *skb;
       int err = -ENOBUFS;
+    fdb_notify_cache(br);
       if (swdev_notify)
           br_switchdev_fdb_notify(br, fdb, type);

net/bridge/br_fdb.c static void fdb_del_hw_addr(struct net_bridge *br, · line 331

Quoted 6 lines
net/bridge/br_fdb.c +1 -0
@@ -315,6 +326,7 @@ static void fdb_del_hw_addr(struct net_bridge *br, 
 const unsigned char *addr)
   static void fdb_delete(struct net_bridge *br, struct net_bridge_fdb_entry *f,
                  bool swdev_notify)
   {
+    fdb_notify_cache(br);
       trace_fdb_delete(br, f, br_fdb_dst_port(f));

fdb_delete already ends with fdb_notify(br, f, RTM_DELNEIGH), which now also calls fdb_notify_cache so each deletion bumps the generation twice.

Quoted 23 lines
net/bridge/br_fdb.c +0 -0
       if (test_bit(BR_FDB_STATIC, &f->flags))
@@ -350,8 +362,10 @@ static void fdb_delete_local(struct net_bridge *br,
           vg = nbp_vlan_group(op);

          if (op != p && ether_addr_equal(op->dev->dev_addr, addr) && (!vid || br_vlan_find(vg, vid))) {
+            fdb_notify_cache(br);
              br_fdb_dst_write(f, br_port_to_dst(op)); clear_bit(BR_FDB_ADDED_BY_USER, &f->flags); +            fdb_notify_cache(br);
              return;
          }
      }

net/bridge/br_fdb.c +0 -0
@@ -361,8 +375,10 @@ static void fdb_delete_local(struct net_bridge *br,
       /* Maybe bridge device has same hw addr? */

      if (p && ether_addr_equal(br->dev->dev_addr, addr) && (!vid || (v && br_vlan_should_use(v)))) { +        fdb_notify_cache(br);
          br_fdb_dst_write(f, br_port_to_dst(NULL)); clear_bit(BR_FDB_ADDED_BY_USER, &f->flags); +        fdb_notify_cache(br);
          return;
      }

net/bridge/br_fdb.c static struct net_bridge_fdb_entry · line 429

Quoted 5 lines
net/bridge/br_fdb.c +1 -0
@@ -409,6 +425,7 @@ static struct net_bridge_fdb_entry 
 *fdb_create(struct net_bridge *br,
           return NULL;
       memcpy(fdb->key.addr.addr, addr, ETH_ALEN);
+    fdb_notify_cache(br);
       br_fdb_dst_write(fdb, dst);

The entry isn't published yet at this point so nothing can have resolved a path through it. Is this notification needed at all? All callers of fdb_create follow it with fdb_notify which bumps the generation again.

Quoted 62 lines
net/bridge/br_fdb.c +2 -1
       fdb->key.vlan_id = vid;
       fdb->flags = flags;
@@ -1030,6 +1047,7 @@ static void __fdb_update(struct net_bridge *br,
                 !test_bit(BR_FDB_STICKY, &fdb->flags)))) {
           if (source != old_port) {
               br_switchdev_fdb_notify(br, fdb, RTM_DELNEIGH);
+            fdb_notify_cache(br);
               br_fdb_dst_write(fdb, dst);
               fdb_modified = true;
               /* take over HW learned entry */
@@ -1194,7 +1212,7 @@ static bool fdb_handle_notify(struct 
 net_bridge_fdb_entry *fdb, u8 notify)
       return modified;
   }
-static bool fdb_update_dst(struct net_bridge_fdb_entry *fdb,
+static bool fdb_update_dst(struct net_bridge *br, struct 
 net_bridge_fdb_entry *fdb,
                  struct net_bridge_dst old_dst,
                  struct net_bridge_dst dst)

  {

net/bridge/br_fdb.c +1 -1
@@ -1205,7 +1223,7 @@ static bool fdb_update_dst(struct 
 net_bridge_fdb_entry *fdb,
           br_fdb_dst_replace(fdb, old_dst, dst);
           return false;
       }
-
+    fdb_notify_cache(br);
       br_fdb_dst_write(fdb, dst);
       return true;

  }

net/bridge/br_fdb.c +2 -2
@@ -1263,7 +1281,7 @@ static int fdb_add_entry(struct net_bridge *br, 
 struct net_bridge_dst dst,
               return -EEXIST;
           old_dst = br_fdb_dst_read(fdb);
-        modified = fdb_update_dst(fdb, old_dst, dst);
+        modified = fdb_update_dst(br, fdb, old_dst, dst);
           set_bit(BR_FDB_ADDED_BY_USER, &fdb->flags);
           if (test_and_clear_bit(BR_FDB_DYNAMIC_LEARNED, &fdb->flags))
@@ -1644,7 +1662,7 @@ int br_fdb_external_learn_add(struct net_bridge 
 *br, struct net_bridge_port *p,
           WRITE_ONCE(fdb->updated, jiffies);
-        modified = fdb_update_dst(fdb, old_dst, dst);
+        modified = fdb_update_dst(br, fdb, old_dst, dst);
           if (test_and_set_bit(BR_FDB_ADDED_BY_EXT_LEARN, &fdb->flags)) {
               /* Refresh entry */
net/bridge/br_stp.c +2 -3
index c7e7e924f1557..5717bf33c2667 100644
@@ -70,17 +70,16 @@ void br_set_state(struct net_bridge_port *p, 
 unsigned int state)
       }
   }
+/* Caller holds RTNL or RCU. */
   u8 br_port_get_stp_state(const struct net_device *dev)
   {
       struct net_bridge_port *p;
-    ASSERT_RTNL();
-
-    p = br_port_get_rtnl(dev);
+    p = br_port_get_rtnl_rcu(dev);
       if (!p)
Quoted 8 lines

net/bridge/br_stp.c void br_set_state(struct net_bridge_port *p, unsigned int state) · line 83

Quoted 4 lines
net/bridge/br_stp.c +1 -1
           return BR_STATE_DISABLED;
-    return p->state;
+    return READ_ONCE(p->state);
   }

Nothing in this patch calls br_port_get_stp_state under rcu. Could this go into the patch that adds the RCU user, or a separate bridge patch?

I've moved the accessor change into a separate bridge preparation patch immediately before the FA driver patch that introduces its RCU caller.

Quoted 3 lines

Also br_set_state still writes the state with a plain store instead of WRITE_ONCE.

Fixed. br_set_state() now uses WRITE_ONCE(), paired with the accessor's READ_ONCE().

Quoted 5 lines

The patch changes the bridge, netevent, the flow_offload API and the netfilter flowtable at once. Could it be split so the bridge and netevent parts can be reviewed on their own?

I've split the original patch into three: the generic cached-owner validation/invalidation API, per-flow bridge cache revalidation with focused tests, and the standalone bridge STP accessor preparation. There is no netevent change remaining.

Thank you!

pw-bot: cr

Signature · 1 line
Florian
author maintainer
#6 lore raw

PATCH v2 4/6 net: bgmac: add Northstar IPv4 TCP/UDP NAT flowtable offload

In reply to Florian Fainelli

Expose the inline BCM4708/BCM5301X accelerator through TC_SETUP_FT on GMAC2. Learn placement hashes from miss metadata and install exact IPv4 TCP/UDP SNAT or DNAT rules with shared router-MAC and next-hop resources. Accept two standalone untagged DSA ports, or a standalone WAN opposite an untagged LAN bridge. Require distinct router MACs, MTU 1500 and one flowtable in the initial namespace. Require an operational GMAC0 exception path for both protocols and the flowtable FIN/RST exclusion mask for TCP. Reject unsupported or exhausted rules.

Gate lookup synchronously and retire all hardware owners on every IPv4 route, rule or nexthop notification, including unrelated prefixes and local-table changes. This is deliberately conservative: the driver lacks enough policy-routing context to prove an event irrelevant. Coalesce control work, accepting reduced offload residency during unrelated churn. Track explicit low-MTU prefixes incrementally from notifier replay and updates; avoid repeated FIB dumps. Bound tracking memory and latch software fallback if tracking is exhausted.

Use the owner's actual cached-route and neighbour validation as the only authority for stale-owner teardown. The driver's partial FIB lookup is an eligibility probe; it lacks mark, DSCP and output-interface context. A mismatch or unsupported shape declines hardware offload without tearing down a valid policy-routed software flow. Reject publication across invalidation generations. Use RCU lookups and tracked netdevice references. Drive neighbour probes from hardware counter activity, including the initial pre-wrap jiffies epoch. Retire owners on neighbour, topology or exception-path changes that withdraw their hardware paths. Any update of an unknown neighbour or loss of validity on an FA port retires them, as the driver cannot tell which next hops are in use, and low-MTU prefixes tracked anywhere disable offload until reprobe. Probe the next hop of every installed entry, and check its neighbour again once the entry is published. Flush on NETDEV_PRE_UP, as a port can receive before NETDEV_UP.

Resolve bridged routes against their bridge neighbour and current FDB path, using the bridge router MAC. Validate both cached directions and acquire a source-MAC ingress guard from the authoritative reverse peer before publishing a NAT row. Keep WLAN and other software-member flows in software. Retire on FDB, STP, security, VLAN, MAC or membership changes and preserve fallback on classifier or table exhaustion.

Quiesce lookups using GMAC2 CPU flow control around indirect table accesses, drain an in-flight frame, check busy and address completion, and release read mode before resuming traffic. Preserve Broadcom-tag relocation when disabling lookup. On an uncertain transaction, gate the parser before releasing pause, retain uncertain resources and reject new entries until reprobe. Add optional per-device completion fault injection.

TCP control packets retire both NAT directions before tuple reuse. A control packet matches either direction of an entry, with exact ports, and an entry paired with a retiring direction is retired too, even if it was installed concurrently. Fragments other than the first, and headers which cannot be parsed, are left to the slow path as in the software flowtable. Accumulate packet deltas and preserve the final delta for retired owners; do not fabricate hardware byte counters. Provide debugfs status and raw table readback. FA2/FA+, PPPoE and board enablement remain separate work.

The accelerator is inline in the data path of GMAC2 and the DSA tag format depends on how it was configured, so failing to initialize it fails the probe of GMAC2. Only the initial namespace can bind a flowtable. Suspend and resume are not supported, as BCMA has no PM callbacks.

---
Changes in v2:
- Drive neighbour probes from every installed entry's next hop instead of a bounded notification cache. Recheck the neighbour after publishing an entry and before committing its hardware row.
- Match TCP control packets by exact ports in either direction, including headers with IP options. Leave unparseable/non-initial fragments to the slow path. Retire a concurrently installed peer when the other direction is already closing.
- Serialize flow-block bookkeeping, reject non-initial namespaces at bind time, and invalidate before a newly opened port can receive.
- Use READ_ONCE/WRITE_ONCE for shared MTU-tracking flags, hash debugfs cookie pointers, and remove the unsupported BCMA suspend hook.
- Accept the bridged LAN router layout, use the bridge router MAC and owner-derived peer address, publish source guards before NAT rows, and retire entries on FDB, STP, security, VLAN, MAC and membership changes. Keep software-member traffic in software.

 MAINTAINERS                                |    1 +
 drivers/net/ethernet/broadcom/Kconfig      |   26 +
 drivers/net/ethernet/broadcom/Makefile     |    1 +
 drivers/net/ethernet/broadcom/bcm-ns-fa.c  | 2214 ++++++++++++++++++++
 drivers/net/ethernet/broadcom/bcm-ns-fa.h  |   30 +
 drivers/net/ethernet/broadcom/bgmac-bcma.c |    5 +
 drivers/net/ethernet/broadcom/bgmac.c      |   30 +
 drivers/net/ethernet/broadcom/bgmac.h      |    2 +
 8 files changed, 2309 insertions(+)
 create mode 100644 drivers/net/ethernet/broadcom/bcm-ns-fa.c
 create mode 100644 drivers/net/ethernet/broadcom/bcm-ns-fa.h
MAINTAINERS +1 -0
index dce9a88f4aef4..80969b91af402 100644
@@ -5671,6 +5671,7 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/net/brcm,amac.yaml
 F:	Documentation/devicetree/bindings/net/brcm,bcm4708-fa.yaml
 F:	Documentation/devicetree/bindings/net/brcm,bcm5301x-gmac.yaml
+F:	drivers/net/ethernet/broadcom/bcm-ns-fa*
 F:	drivers/net/ethernet/broadcom/bgmac*
 F:	drivers/net/ethernet/broadcom/unimac.h
 
drivers/net/ethernet/broadcom/Kconfig +26 -0
index f0bac0dd14390..bb86e73757ee1 100644
@@ -163,13 +163,38 @@ config BNX2X_SRIOV
 
 config BGMAC
 	tristate
+	depends on BCM_NS_FA || !BCM_NS_FA
 	help
 	  This enables the integrated ethernet controller support for many
 	  Broadcom (mostly iProc) SoCs. An appropriate bus interface driver
 	  needs to be enabled to select this.
 
+config BCM_NS_FA
+	tristate "Broadcom Northstar IPv4 TCP/UDP NAT flow accelerator"
+	depends on ARCH_BCM_5301X || COMPILE_TEST
+	depends on OF && NET_DSA && NF_FLOW_TABLE
+	select NET_DSA_TAG_BRCM_FA
+	help
+	  Offload IPv4 TCP/UDP NAT flows from nftables flowtables to the inline
+	  accelerator on BCM4708, BCM53011 and BCM53012. Requires GMAC2, a B53 switch
+	  using brcm-fa tags, a second CPU link through GMAC0 for IPv4 exceptions,
+	  and explicit device tree configuration.
+	  Supports standalone ports or a standalone WAN opposite an untagged
+	  LAN bridge. WLAN members retain software forwarding. VLANs,
+	  VLAN-filtering bridges, PPPoE and double NAT use the software path.
+
+config BCM_NS_FA_FAULT_INJECTION
+	bool "Fault injection for Northstar FA table transactions"
+	depends on BCM_NS_FA && FAULT_INJECTION_DEBUG_FS
+	help
+	  Add per-device fail_table controls in debugfs to simulate an uncertain
+	  indirect table completion. The failure disables hardware lookup until
+	  reprobe and leaves forwarding to software. Intended for driver testing.
+	  Injection is disabled by default and can be armed through debugfs.
+
 config BGMAC_BCMA
 	tristate "Broadcom iProc GBit BCMA support"
+	depends on BCM_NS_FA || !BCM_NS_FA
 	depends on BCMA && BCMA_HOST_SOC
 	depends on BCM47XX || ARCH_BCM_5301X || COMPILE_TEST
 	select BGMAC
@@ -183,6 +208,7 @@ config BGMAC_BCMA
 
 config BGMAC_PLATFORM
 	tristate "Broadcom iProc GBit platform support"
+	depends on BCM_NS_FA || !BCM_NS_FA
 	depends on ARCH_BCM_IPROC || COMPILE_TEST
 	select BGMAC
 	select PHYLIB
drivers/net/ethernet/broadcom/Makefile +1 -0
index 10cc1c92ecfc6..1c445d9849efe 100644
@@ -19,3 +19,4 @@ obj-$(CONFIG_SYSTEMPORT) += bcmsysport.o
 obj-$(CONFIG_BNXT) += bnxt/
 obj-$(CONFIG_BCMASP) += asp2/
 obj-$(CONFIG_BNGE) += bnge/
+obj-$(CONFIG_BCM_NS_FA) += bcm-ns-fa.o
drivers/net/ethernet/broadcom/bcm-ns-fa.c new file +2214 -0

2,214 lines not on this page · raw message

drivers/net/ethernet/broadcom/bcm-ns-fa.h new file +30 -0
new file mode 100644
index 0000000000000..825b019fb89fe
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef _BCM_NS_FA_H
+#define _BCM_NS_FA_H
+
+#include <linux/netdevice.h>
+
+struct bcm_ns_fa;
+
+#if IS_REACHABLE(CONFIG_BCM_NS_FA)
+struct bcm_ns_fa *bcm_ns_fa_init(struct net_device *dev);
+void bcm_ns_fa_rx(struct bcm_ns_fa *fa, struct sk_buff *skb);
+int bcm_ns_fa_setup_tc(struct bcm_ns_fa *fa, enum tc_setup_type type, void *data);
+void bcm_ns_fa_flush(struct bcm_ns_fa *fa);
+void bcm_ns_fa_set_offload(struct bcm_ns_fa *fa, bool enable);
+#else
+static inline struct bcm_ns_fa *bcm_ns_fa_init(struct net_device *dev)
+{
+	return NULL;
+}
+
+static inline void bcm_ns_fa_rx(struct bcm_ns_fa *fa, struct sk_buff *skb) {}
+static inline void bcm_ns_fa_flush(struct bcm_ns_fa *fa) {}
+static inline void bcm_ns_fa_set_offload(struct bcm_ns_fa *fa, bool enable) {}
+static inline int bcm_ns_fa_setup_tc(struct bcm_ns_fa *fa,
+				     enum tc_setup_type type, void *data)
+{
+	return -EOPNOTSUPP;
+}
+#endif
+#endif
drivers/net/ethernet/broadcom/bgmac-bcma.c +5 -0
index 36f9bad28e6a9..87338e01a825b 100644
@@ -11,6 +11,7 @@
 #include <linux/bcma/bcma.h>
 #include <linux/brcmphy.h>
 #include <linux/etherdevice.h>
+#include <linux/of.h>
 #include <linux/of_mdio.h>
 #include <linux/of_net.h>
 #include "bgmac.h"
@@ -130,6 +131,10 @@ static int bgmac_probe(struct bcma_device *core)
 	const u8 *mac;
 	int err;
 
+	if (of_property_present(core->dev.of_node, "brcm,flow-accelerator") &&
+	    core->core_unit != 2)
+		return -EINVAL;
+
 	bgmac = bgmac_alloc(&core->dev);
 	if (!bgmac)
 		return -ENOMEM;
drivers/net/ethernet/broadcom/bgmac.c +30 -0
index b6d1572417a44..a6d0ed24f7d34 100644
@@ -495,6 +495,7 @@ static int bgmac_dma_rx_read(struct bgmac *bgmac, struct bgmac_dma_ring *ring,
 			skb_pull(skb, BGMAC_RX_FRAME_OFFSET +
 				 BGMAC_RX_BUF_OFFSET);
 
+			bcm_ns_fa_rx(bgmac->fa, skb);
 			skb_checksum_none_assert(skb);
 			skb->protocol = eth_type_trans(skb, bgmac->net_dev);
 			bgmac->net_dev->stats.rx_bytes += len;
@@ -1284,7 +1285,25 @@ static int bgmac_change_mtu(struct net_device *net_dev, int mtu)
 	return 0;
 }
 
+static int bgmac_set_features(struct net_device *dev, netdev_features_t features)
+{
+	struct bgmac *bgmac = netdev_priv(dev);
+
+	bcm_ns_fa_set_offload(bgmac->fa, features & NETIF_F_HW_TC);
+	return 0;
+}
+
+static int bgmac_setup_tc(struct net_device *dev, enum tc_setup_type type,
+			  void *data)
+{
+	struct bgmac *bgmac = netdev_priv(dev);
+
+	return bcm_ns_fa_setup_tc(bgmac->fa, type, data);
+}
+
 static const struct net_device_ops bgmac_netdev_ops = {
+	.ndo_set_features	= bgmac_set_features,
+	.ndo_setup_tc		= bgmac_setup_tc,
 	.ndo_open		= bgmac_open,
 	.ndo_stop		= bgmac_stop,
 	.ndo_start_xmit		= bgmac_start_xmit,
@@ -1572,6 +1591,17 @@ int bgmac_enet_probe(struct bgmac *bgmac)
 	net_dev->hw_features = net_dev->features;
 	net_dev->vlan_features = net_dev->features;
 
+	bgmac->fa = bcm_ns_fa_init(net_dev);
+	if (IS_ERR(bgmac->fa)) {
+		err = PTR_ERR(bgmac->fa);
+		bgmac->fa = NULL;
+		goto err_phy_disconnect;
+	}
+	if (bgmac->fa) {
+		net_dev->features |= NETIF_F_HW_TC;
+		net_dev->hw_features |= NETIF_F_HW_TC;
+	}
+
 	/* Omit L2 header, VLAN tag and FCS from max MTU size */
 	net_dev->max_mtu = BGMAC_RX_MAX_FRAME_SIZE - ETH_HLEN - VLAN_HLEN -
 			   ETH_FCS_LEN;
drivers/net/ethernet/broadcom/bgmac.h +2 -0
index 6fee9a41839c0..788d5ba9c9b5b 100644
@@ -5,6 +5,7 @@
 #include <linux/netdevice.h>
 
 #include "unimac.h"
+#include "bcm-ns-fa.h"
 
 #define BGMAC_DEV_CTL				0x000
 #define  BGMAC_DC_TSM				0x00000002
@@ -437,6 +438,7 @@ struct bgmac_rx_header {
 };
 
 struct bgmac {
+	struct bcm_ns_fa *fa;
 	union {
 		struct {
 			void __iomem *base;
author maintainer
#7 lore raw

PATCH v2 5/6 net: add KUnit coverage for FA and flowtable path validation

In reply to Florian Fainelli

Exercise Northstar NAT fields, byte order, protocol-aware hash learning, TCP control identity, lookup gating, MTU tracking and owner invalidation. Check B53 UDF layout and every IPv4 packet length, failed- guard readiness, and FA/ordinary switch tags.

Test cached-route owner validation with route-cookie expiry, changed or invalid neighbours, absent route context and unsupported stacked paths. Require explicit owner validation to detect an expired validation-only dst even though the generic packet/GC helper ignores that reference.

Add seven scenarios using real route initialization and the private GC
step: ordinary direct software forwarding, validation-only references, direct tunnels with and without hardware requested, neighbour routes with and without hardware requested, and XFRM. Check legacy validation policy, GC teardown and balanced dst references. The validation-only scenario fails both packet and GC expectations before the policy fix.

The independent netfilter prerequisite already carries its lifetime tests and standalone configuration. Extend that test configuration's help for these path cases, embed private tests in their parent units, and keep the combined FA configuration beside the backend.

Cover bridge path movement, missing FDB entries, owner-derived ingress peers, software cache invalidation during lookup, GC and construction, pending hardware admission, source-guard sharing and exhaustion, RCU- only STP access, auxiliary forwarding marks and the ninth CFP UDF valid bit.

---
Changes in v2:
- Cover missing-neighbour and unsupported-family validation, exact TCP control identity in both directions, and all-port bridge guards.
- Give each negative NAT-action case an independent valid starting rule, refresh checksums when changing test protocols, and provide a working dummy netdevice transmit callback.
- Skip direct-register cases with indirect MMIO accessors, such as UML. Update the combined suite help for standalone lifetime tests.
- Add bridge movement and generation tests for construction, packet lookup, GC and pending hardware admission; cover source-guard sharing/exhaustion, RCU STP access, auxiliary forwarding marks and the ninth CFP UDF validity bit. The combined QEMU suite has 37 cases.

 MAINTAINERS                                   |   3 +
 drivers/net/dsa/b53/Kconfig                   |  11 +
 drivers/net/dsa/b53/b53_common.c              |   4 +
 drivers/net/dsa/b53/b53_fa_test.c             | 124 +++
 drivers/net/ethernet/broadcom/.kunitconfig    |  24 +
 drivers/net/ethernet/broadcom/Kconfig         |  13 +
 .../net/ethernet/broadcom/bcm-ns-fa-test.c    | 795 ++++++++++++++++++
 drivers/net/ethernet/broadcom/bcm-ns-fa.c     |   4 +
 net/dsa/Kconfig                               |  11 +
 net/dsa/tag_brcm.c                            |   4 +
 net/dsa/tag_brcm_test.c                       | 200 +++++
 net/netfilter/Kconfig                         |  15 +-
 net/netfilter/nf_flow_table_core_test.c       | 203 +++++
 net/netfilter/nf_flow_table_offload.c         |   4 +
 net/netfilter/nf_flow_table_offload_test.c    | 242 ++++++
 15 files changed, 1650 insertions(+), 7 deletions(-)
 create mode 100644 drivers/net/dsa/b53/b53_fa_test.c
 create mode 100644 drivers/net/ethernet/broadcom/.kunitconfig
 create mode 100644 drivers/net/ethernet/broadcom/bcm-ns-fa-test.c
 create mode 100644 net/dsa/tag_brcm_test.c
 create mode 100644 net/netfilter/nf_flow_table_offload_test.c
MAINTAINERS +3 -0
index 80969b91af402..c05ac2258889e 100644
@@ -5305,6 +5305,7 @@ F:	drivers/net/dsa/bcm_sf2*
 F:	include/linux/dsa/brcm.h
 F:	include/linux/platform_data/b53.h
 F:	net/dsa/tag_brcm.c
+F:	net/dsa/tag_brcm_test.c
 
 BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE
 M:	Florian Fainelli <[email protected]>
@@ -5671,6 +5672,8 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/net/brcm,amac.yaml
 F:	Documentation/devicetree/bindings/net/brcm,bcm4708-fa.yaml
 F:	Documentation/devicetree/bindings/net/brcm,bcm5301x-gmac.yaml
+F:	drivers/net/dsa/b53/b53_fa_test.c
+F:	drivers/net/ethernet/broadcom/.kunitconfig
 F:	drivers/net/ethernet/broadcom/bcm-ns-fa*
 F:	drivers/net/ethernet/broadcom/bgmac*
 F:	drivers/net/ethernet/broadcom/unimac.h
drivers/net/dsa/b53/Kconfig +11 -0
index 8e2a8c20bc4ac..5a03bacef2e55 100644
@@ -13,6 +13,17 @@ menuconfig B53
 	  BCM5325E, BCM5365, BCM539x, BCM53115 and BCM53125 as well as BCM63XX
 	  integrated switches.
 
+config B53_FA_KUNIT_TEST
+	bool "KUnit tests for B53 FA exception guards" if !KUNIT_ALL_TESTS
+	depends on KUNIT=y && B53
+	default KUNIT_ALL_TESTS
+	help
+	  Tests are compiled into the parent driver and require built-in KUnit.
+	  Verify the original FA classifier field layout and complete packet
+	  length range used to divert unsafe packets around the accelerator.
+	  Check cross-word destination MAC encoding and every 16-bit IPv4
+	  packet length against the standard MTU without accessing hardware.
+
 config B53_SPI_DRIVER
 	tristate "B53 SPI connected switch driver"
 	depends on B53 && SPI
drivers/net/dsa/b53/b53_common.c +4 -0
index 234c6a2905e26..1a6fcb9b9a710 100644
@@ -3893,6 +3893,10 @@ int b53_switch_register(struct b53_device *dev)
 }
 EXPORT_SYMBOL(b53_switch_register);
 
+#if IS_ENABLED(CONFIG_B53_FA_KUNIT_TEST)
+#include "b53_fa_test.c"
+#endif
+
 MODULE_AUTHOR("Jonas Gorski <[email protected]>");
 MODULE_DESCRIPTION("B53 switch library");
 MODULE_LICENSE("Dual BSD/GPL");
drivers/net/dsa/b53/b53_fa_test.c new file +124 -0

124 lines not on this page · raw message

drivers/net/ethernet/broadcom/.kunitconfig new file +24 -0
new file mode 100644
index 0000000000000..6ef784dfce24b
@@ -0,0 +1,24 @@
+CONFIG_KUNIT=y
+CONFIG_DEBUG_KERNEL=y
+CONFIG_NET_DEV_REFCNT_TRACKER=y
+CONFIG_COMPILE_TEST=y
+CONFIG_NET=y
+CONFIG_INET=y
+CONFIG_NETDEVICES=y
+CONFIG_NET_VENDOR_BROADCOM=y
+CONFIG_NETFILTER=y
+CONFIG_NF_CONNTRACK=y
+CONFIG_NF_TABLES=y
+CONFIG_NF_FLOW_TABLE=y
+CONFIG_NF_FLOW_TABLE_KUNIT_TEST=y
+CONFIG_NET_DSA=y
+CONFIG_OF=y
+CONFIG_BCM_NS_FA=y
+CONFIG_BCM_NS_FA_KUNIT_TEST=y
+CONFIG_NET_DSA_TAG_BRCM_FA=y
+CONFIG_NET_DSA_TAG_BRCM_FA_KUNIT_TEST=y
+CONFIG_B53=y
+CONFIG_B53_FA_KUNIT_TEST=y
+CONFIG_VLAN_8021Q=y
+CONFIG_BRIDGE=y
+CONFIG_BRIDGE_VLAN_FILTERING=y
drivers/net/ethernet/broadcom/Kconfig +13 -0
index bb86e73757ee1..6f132061253fb 100644
@@ -192,6 +192,19 @@ config BCM_NS_FA_FAULT_INJECTION
 	  reprobe and leaves forwarding to software. Intended for driver testing.
 	  Injection is disabled by default and can be armed through debugfs.
 
+config BCM_NS_FA_KUNIT_TEST
+	bool "KUnit tests for the Northstar flow accelerator" if !KUNIT_ALL_TESTS
+	depends on KUNIT=y && BCM_NS_FA
+	default KUNIT_ALL_TESTS
+	help
+	  Test NAT action validation, table field encoding, and RX hash learning.
+	  Exercise upper-device inspection under RCU with real netdevices.
+	  Tests are compiled into the parent driver and require built-in KUnit.
+	  These tests run without an accelerator and do not simulate table I/O.
+	  The few cases which access registers use plain memory instead, and
+	  are skipped where MMIO is emulated, such as on UML.
+	  Use the hardware validation plan to check actual forwarding.
+
 config BGMAC_BCMA
 	tristate "Broadcom iProc GBit BCMA support"
 	depends on BCM_NS_FA || !BCM_NS_FA
drivers/net/ethernet/broadcom/bcm-ns-fa-test.c new file +795 -0

795 lines not on this page · raw message

drivers/net/ethernet/broadcom/bcm-ns-fa.c +4 -0
index 800381a828ef5..c39de5d4a0106 100644
@@ -2210,5 +2210,9 @@ struct bcm_ns_fa *bcm_ns_fa_init(struct net_device *dev)
 }
 EXPORT_SYMBOL_GPL(bcm_ns_fa_init);
 
+#if IS_ENABLED(CONFIG_BCM_NS_FA_KUNIT_TEST)
+#include "bcm-ns-fa-test.c"
+#endif
+
 MODULE_DESCRIPTION("Broadcom Northstar IPv4 TCP/UDP NAT flow accelerator");
 MODULE_LICENSE("GPL");
net/dsa/Kconfig +11 -0
index d62de6f716cd9..16adbe4d54f7a 100644
@@ -81,6 +81,17 @@ config NET_DSA_TAG_BRCM_FA
 	  The B53 driver selects this tagger and uses it only for a switch
 	  explicitly connected to an accelerator.
 
+config NET_DSA_TAG_BRCM_FA_KUNIT_TEST
+	bool "KUnit tests for Broadcom FA tags" if !KUNIT_ALL_TESTS
+	depends on KUNIT=y && NET_DSA_TAG_BRCM_FA
+	default KUNIT_ALL_TESTS
+	help
+	  Tests are compiled into the parent driver and require built-in KUnit.
+	  Verify FA miss demultiplexing, parser-status handling, and rejection
+	  of unsupported opcodes without changing ordinary Broadcom tagging.
+	  Exercise source-port demultiplexing and consumption of the metadata
+	  tag through the receive path, without requiring a physical switch.
+
 config NET_DSA_TAG_HELLCREEK
 	tristate "Tag driver for Hirschmann Hellcreek TSN switches"
 	help
net/dsa/tag_brcm.c +4 -0
index df1e43f8b11a9..e41b409400be7 100644
@@ -577,5 +577,9 @@ static struct dsa_tag_driver *dsa_tag_driver_array[] =	{
 
 module_dsa_tag_drivers(dsa_tag_driver_array);
 
+#if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM_FA_KUNIT_TEST)
+#include "tag_brcm_test.c"
+#endif
+
 MODULE_DESCRIPTION("DSA tag driver for Broadcom switches using in-frame headers");
 MODULE_LICENSE("GPL");
net/dsa/tag_brcm_test.c new file +200 -0

200 lines not on this page · raw message

net/netfilter/Kconfig +8 -7
index 952724e462043..b80c568cc5da9 100644
@@ -719,16 +719,17 @@ config NF_FLOW_TABLE
 	  To compile it as a module, choose M here.
 
 config NF_FLOW_TABLE_KUNIT_TEST
-	bool "KUnit tests for flowtable ownership" if !KUNIT_ALL_TESTS
+	bool "KUnit tests for flowtable ownership and cached paths" if !KUNIT_ALL_TESTS
 	depends on KUNIT=y && NF_FLOW_TABLE
 	default KUNIT_ALL_TESTS
 	help
-	  Test conntrack offload ownership during flowtable teardown.
-	  Check that GC keeps ownership until the flow is removed from the
-	  hash tables, after a pending hardware deletion has run, and that
-	  late teardown notifications cannot release a replacement owner.
-	  Check that GC does not extend a conntrack timeout repaired by teardown.
-	  These private tests are embedded in the flowtable core.
+	  Test that flowtable GC keeps conntrack ownership until the flow is
+	  removed from the hash tables, after a pending hardware deletion has
+	  run, that repeated teardown notifications cannot release a
+	  replacement owner, and that GC does not extend a timeout repaired by
+	  teardown. Also validate cached forwarding paths.
+	  Tests cover route expiry, neighbour changes and unsupported contexts.
+	  The tests are embedded in their parent translation units.
 
 config NF_FLOW_TABLE_PROCFS
 	bool "Supply flow table statistics in procfs"
net/netfilter/nf_flow_table_core_test.c +203 -0

213 lines not on this page · raw message

net/netfilter/nf_flow_table_offload.c +4 -0
index daf42db2b31cf..acb4ea90688e8 100644
@@ -1463,3 +1463,7 @@ void nf_flow_table_offload_exit(void)
 	destroy_workqueue(nf_flow_offload_del_wq);
 	destroy_workqueue(nf_flow_offload_stats_wq);
 }
+
+#if IS_ENABLED(CONFIG_NF_FLOW_TABLE_KUNIT_TEST)
+#include "nf_flow_table_offload_test.c"
+#endif
net/netfilter/nf_flow_table_offload_test.c new file +242 -0

242 lines not on this page · raw message

author maintainer
#8 lore raw

PATCH v2 6/6 docs: net: document Northstar FA setup and NAT qualification

In reply to Florian Fainelli

Describe the supported topology, GMAC2 data and GMAC0 exception wiring, configuration, counters and software fallback. Provide classic/software/ hardware NAT controls and same-live-tuple TTL, MTU and ingress-policy checks. Cover live route/neighbour changes, reachability probes and read/insertion/deletion completion injection with reprobe recovery.

Explain that every notified IPv4 route, rule or nexthop event retires all hardware owners, including unrelated and local-table updates. Document the resulting offload-residency cost and distinguish actual cached-path validation from the driver's incomplete FIB eligibility probe. State the limits of FIB notifications and of the GMAC3-hosted registers.

Describe a standalone WAN opposite a four-port LAN bridge with software members, physical-only hardware flowtable devices, source-MAC guards, FDB invalidation, software-to-wired movement and mixed NAT/L2 tests.

---
Changes in v2:
- Document complete ingress guards, auxiliary VLAN membership, failed- MAC-change recovery and exact TCP control retirement.
- Clarify GMAC3 register accessibility and bootloader dependencies, the supported compatibles, and unnotified DSCP-specific route aliases which must not be used with FA traffic.
- Include both TCP and UDP in the nftables example and run all combined KUnit suites without the earlier name filter.
- Document bridge setup, wired-only hardware flowtable devices, software- member NAT/L2 forwarding, FDB movement and mixed soak qualification. Remove redundant transport protocol matches from the nftables example so strict checkpatch is clean.

 .../ethernet/broadcom/bcm-ns-fa.rst           | 638 ++++++++++++++++++
 .../device_drivers/ethernet/index.rst         |   1 +
 MAINTAINERS                                   |   1 +
 3 files changed, 640 insertions(+)
 create mode 100644 Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst
Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst new file +638 -0
new file mode 100644
index 0000000000000..a0bbddada2ed5
@@ -0,0 +1,638 @@
+.. SPDX-License-Identifier: GPL-2.0-only
+
+Broadcom Northstar flow accelerator
+===================================
+
+Status and scope
+----------------
+
+The driver supports BCM4708, BCM53011 and BCM53012. IPv4 TCP and UDP
+SNAT/DNAT have been validated on BCM953012ER (BCM53012), including normal
+and software-flowtable controls, external wire checks, hardware table
+pressure, software fallback, natural aging, teardown and recovery.
+
+BCM4708 and BCM53011 remain unvalidated. BCM53012 validation covers the
+limited topology below; maximum throughput has not been established.
+
+The driver accepts nftables flowtable offload through ``TC_SETUP_FT`` on
+bgmac. DSA forwards flowtable binds from its user ports to the GMAC2 conduit.
+The FA is inline on the UniMAC2 / switch IMP0 (port 8) path. GMAC0 and GMAC1
+are pass-through paths and cannot accelerate these flows.
+
+The initial supported configuration is deliberately limited:
+
+* IPv4 TCP/UDP with source NAT or destination NAT, including port translation.
+* Two untagged router interfaces in the initial network namespace: either
+  two standalone DSA ports, or a standalone WAN port and one LAN bridge.
+  The bridge may contain all four LAN switch ports and software ports such
+  as a PCIe WLAN interface. Accelerated ingress and egress must both be
+  DSA ports of the same switch, using GMAC2 as their conduit.
+* Distinct unicast MAC addresses on the LAN and WAN router interfaces.
+* MTU 1500 on both router interfaces and their physical ports, one hardware
+  flowtable, and no upper devices other than the untagged LAN bridge.
+
+IPv6, VLAN devices or VLAN-filtering bridges, PPPoE, tunnels, bonds, hairpin forwarding,
+plain routing, multipath/nexthop-object routes, and simultaneous source and
+destination NAT in one direction
+are rejected for hardware offload. They can still use software forwarding.
+Hardware admission requires a second, operational CPU connection from switch
+port 5 to GMAC0. B53 CFP redirects IPv4 exceptions through this connection,
+physically bypassing FA. This includes TCP SYN/FIN/RST, TTL 0/1, IP lengths
+above 1500, and packets that do not match the input port's router MAC. TCP
+also requires the flowtable FIN/RST exclusion mask. Boards without the
+auxiliary connection retain software forwarding for both protocols.
+
+The hardware has 1024 directional IPv4 entries, arranged in 256 four-way
+buckets, four router MAC entries, and 128 next-hop entries. Capacity exhaustion
+returns an error to the flowtable infrastructure, leaving traffic in software.
+One connection normally needs two directional entries. Next-hop entries are
+shared by destination MAC; router MACs are shared with an internal/external
+side attribute. The driver learns the tuple hash from opcode-2 miss tags,
+so it does not implement an assumed software equivalent of the hardware CRC.
+A finite RX hash cache can also cause an offload attempt to fall back to
+software under miss floods.
+
+The new ``brcm-fa`` DSA tag protocol carries the prepended FA miss descriptor.
+Its hash, bucket, and parser status fields differ from the ordinary switch
+tag. The bgmac receive hook observes the metadata for hash learning; the DSA
+tagger consumes it and selects the input port. Timestamp descriptors are not
+supported. The ordinary ``brcm`` and ``brcm-prepend`` taggers retain their
+opcode validation.
+
+Implementation notes
+--------------------
+
+Table operations use the documented indirect access sequence. DATA0 triggers
+the transfer; reads discard the initial DATA0 value and wait for the fetch
+before consuming DATA7 through DATA0. Every wait is bounded. The driver keeps
+clear-on-read disabled because clearing on a read gives unreliable hit counts.
+Instead it reads cumulative packet counts and computes wrapping deltas in
+software.
+
+The indirect read port is released after each access, including an access
+that times out. Leaving read mode armed prevents per-entry hit counters from
+updating and breaks the flowtable's activity accounting.
+
+Live packet lookups must not overlap software table transactions. On the
+tested BCM53012, that overlap can advance the indirect address more than
+once and persistently copy one flow's key into another slot. Before each
+transaction, the driver requests GMAC2 CPU flow control, waits for pause to
+assert and allows an in-flight frame to drain. It preserves automatic flow
+control and restores the previous MAC control on every exit path. The switch
+CPU port must honor pause, with matching internal link speeds at both ends.
+The FA stays in normal mode so packet and Broadcom-header processing retain
+their usual paths. Completion checks cover both the busy bit and the
+auto-incremented table address. Frequent statistics and debugfs reads also
+consume time on the internal link; include that work in performance tests.
+
+Router destination MAC validation is enabled before publishing a forwarding
+entry. With no installed entries, it is disabled to obtain hashes for the
+first unknown tuples. VLAN TPIDs are disabled in the FA parser so tagged
+packets cannot match an installed untagged tuple merely by sharing its inner
+five-tuple, including the TCP/UDP protocol bit. When both CPU connections
+are explicitly described, B53 CFP reserves rules for TCP SYN/FIN/RST, TTL
+0/1 and IPv4 total lengths above 1500. These redirect to port 5 with a
+classification and termination reason. Nine masked prefixes cover every
+length from 1501 through 65535. Router-MAC guards redirect packets using
+another router interface's destination MAC to port 5. All ports of the LAN
+bridge share its router MAC and routing domain. Other destination MACs
+cannot match the FA router-MAC pool; normal LAN switching and copies to
+software bridge members continue. MAC and bridge membership changes disable
+admission while updating these rules, and a MAC change which fails restores
+them. Both
+meter outcomes use the same action. Ordinary data uses port 8 only; unicast
+and multicast flooding to the auxiliary CPU is disabled. Redirected frames
+stay subject to VLAN filtering, so the auxiliary CPU port follows the VLAN
+membership of port 8. Standalone ports use basic EAP mode, with
+private VLAN membership restricting forwarding to the CPU connections.
+VLAN, EAP and STP filtering remain enabled. CFP classification is disabled
+on CPU ports. Router-domain guards cover every user port, including bridge
+members. FA cannot separate an additional active routing domain, so such a
+configuration is declined for hardware offload.
+
+Each accelerated LAN client also owns a classifier source-MAC guard. It
+redirects IPv4 packets from that MAC on any switch port other than the one
+recorded by the bridge FDB. This makes wired roaming observable even when
+the client continues an already accelerated tuple without ARP or TCP control
+traffic. The first packet reaches Linux bridge learning, which invalidates
+the old forwarding cache before a new hardware egress can be admitted.
+There are 128 shared client guards; exhaustion retains software forwarding.
+Classifier failures disable FA until reprobe. Redirected bridge frames are
+not marked as already forwarded by hardware, so Linux can forward them to
+other wired ports as well as WLAN.
+
+FA must ignore switch exception metadata to accelerate standalone data,
+which normally carries the switch flooding reason. Consequently, an inline
+SYN/FIN/RST trap through port 8 is insufficient: FA would accelerate those
+packets as well. The auxiliary GMAC0 path avoids that lookup entirely. It
+uses embedded Broadcom tags; the port 8 data path uses prepended FA metadata.
+The tagger dispatches control packets to FA before delivering them to Linux.
+The auxiliary conduit uses promiscuous mode to receive the router port MACs.
+Before disabling its CFP redirects, B53 disables hardware lookup, retires
+all entries and blocks admission. Re-enabling the path permits fresh
+connections to offload.
+
+On a valid TCP control packet, NAPI marks the matching direction as closing
+and immediately disables IPv4 lookup in the parser. Broadcom-tag relocation
+remains active so the control packet can traverse the software forwarding
+path. A worker removes both NAT directions before resuming lookups. Global
+bypass is unsuitable here because it also disables tag relocation. Control
+packets match either direction of an entry by their exact ports, including
+packets with IP options. Fragments other than the first, which carry no TCP
+header, are left to the slow path, as in the software flowtable. A direction
+installed while its peer is being retired is retired as well. RCU protects entry
+identity, and a generation check prevents an insertion learned before the
+control packet from racing past it. Closing rows retain their final packet
+delta for software accounting until the flowtable deletes their ownership.
+
+Hardware packet counters refresh flowtable last-used time and packet
+accounting. The hardware has no per-entry byte counter; reported byte totals
+therefore do not include accelerated traffic. Three-bit timestamps are not
+used for aging. Debugfs reads do not consume the driver's accounting deltas.
+
+Netdevice shutdown, address/MTU changes, new active switch ports, and upper
+interface changes flush entries. Bridge FDB updates, including software-only
+administrative moves, deletions and aging, retire all hardware owners. Bridge
+port state, security flags and VLAN changes also invalidate the cache. The
+retained bridge route is validated against its actual neighbour and current
+FDB-selected physical egress. A moved client retires the old software owner
+as well. Neighbor probes use the bridge L3 interface, rather than a member
+port. Accelerated packets do not refresh the software FDB; its normal aging
+may therefore cause retirement and relearning during a long connection.
+Every IPv4 FIB route, rule and nexthop event
+which the kernel notifies flushes all FA-owned flows, including unrelated
+prefixes and local-table entries. This is intentional: the rule does not carry
+enough routing-policy context to prove that an event cannot affect an
+installed path. The kernel only notifies the first alias of a prefix in a
+table, so a change to a route which is not first, such as a route with a
+non-zero DSCP (``tos``) next to the default one for the same prefix, is not
+seen, and neither are the route MTUs of such aliases. Do not use DSCP-specific
+routes for traffic which uses FA. Work is
+coalesced, but even unrelated routing churn can reduce offload residency.
+Redirects and next-hop MAC or validity changes also disable lookup and schedule
+entry retirement. The driver also notifies the flowtable owner to retire
+its cached software path; merely removing hardware rows would leave stale
+direct-transmit routes and destination MACs in use. Generation checks reject observations and publications
+that raced with invalidation. Before admitting a rule, the flowtable owner
+validates its actual cached routes and direct-path neighbours. Hardware
+flowtables retain validation-only route references, so this check preserves the mark,
+DSCP and output-interface context used when those paths were selected.
+These references do not enable automatic route checks for plain direct
+flows in other drivers or hardware-enabled flowtables. Existing direct
+tunnel, neighbour and XFRM route checks keep their previous behaviour.
+A proven stale cached route or neighbour retires the software owner too.
+The driver's separate FIB lookup is only a hardware eligibility probe:
+it lacks the complete policy context, so any mismatch declines hardware
+offload without tearing down a valid software owner. Unsupported route types,
+such as multipath, nexthop objects and lightweight tunnels, decline hardware
+admission without tearing down valid software flowtable forwarding.
+Valid neighbour aging transitions do not unnecessarily flush entries.
+Hardware counter activity drives Linux
+neighbour reachability probes, so an accelerated connection cannot leave a
+stale neighbour untested indefinitely.
+
+The flowtable classifier provides no per-route MTU. The driver therefore
+keeps all flows in software while any IPv4 route in the initial network
+namespace has an explicit MTU below 1500. The initial FIB notifier replay
+seeds a hash of low-MTU table/prefix pairs; route replacements and deletions
+update it incrementally without further FIB dumps. Ordinary routes use no
+tracking memory. If allocation fails or more than 1024 low-MTU prefixes
+need tracking, hardware admission remains disabled until reprobe; route
+updates and software forwarding continue. This conservative restriction also
+applies to unrelated routes. The CFP length trap handles packets exceeding
+the admitted interface MTU, including packets of an already installed tuple.
+
+A table timeout disables parser lookup
+and prevents further hardware insertion until reprobe. Tag relocation remains
+active for software fallback. Reconfiguration can
+leave an existing conntrack entry temporarily labelled HW_OFFLOAD after its
+hardware entries have been flushed. Use fresh connections after topology or
+ruleset changes; the label alone is never proof of forwarding by hardware.
+
+Device tree and kernel configuration
+------------------------------------
+
+Enable at least::
+
+  CONFIG_BGMAC_BCMA=y
+  CONFIG_BCM_NS_FA=y
+  CONFIG_NET_DSA=y
+  CONFIG_B53=y
+  CONFIG_B53_SRAB_DRIVER=y
+  CONFIG_NET_DSA_TAG_BRCM_FA=y
+  CONFIG_NF_CONNTRACK=y
+  CONFIG_NF_TABLES=y
+  CONFIG_NF_FLOW_TABLE=y
+  CONFIG_NF_FLOW_TABLE_INET=y
+  CONFIG_NFT_FLOW_OFFLOAD=y
+  CONFIG_NFT_NAT=y
+  CONFIG_NF_NAT=y
+  CONFIG_DEBUG_FS=y
+
+Modules are supported too. Use the board's existing ARM configuration and
+retain its PHY, switch, filesystem, and boot-device options.
+
+For a BCM53012 board, add the following node under the root address space
+(adjust the compatible to ``brcm,bcm53011-fa`` for BCM53011)::
+
+  / {
+      fa: flow-accelerator@18027c00 {
+          compatible = "brcm,bcm53012-fa";
+          reg = <0x18027c00 0xc0>;
+      };
+  };
+
+  &gmac2 {
+      brcm,flow-accelerator = <&fa>;
+      status = "okay";
+  };
+
+Both tested user ports must use switch port 8 and GMAC2. In the existing B53
+switch node, port 8 must have ``ethernet = <&gmac2>``. Also enable
+switch port 5 with ``ethernet = <&gmac0>``, ``phy-mode = "internal"`` and a
+1 Gbps full-duplex fixed link. Enable GMAC0 and bring its network interface
+up before testing either protocol; retain port 8 as the preferred conduit for
+user ports.
+Remove any other conflicting CPU assignments for this test. B53 selects ``brcm-fa``
+for a BCM5301x switch when the ethernet node of its port 8 has the phandle to
+an enabled accelerator node compatible with ``brcm,bcm4708-fa``,
+``brcm,bcm53011-fa`` or ``brcm,bcm53012-fa``. These are the compatibles which
+the backend accepts, so both agree on whether FA metadata is used. Another
+compatible on an enabled node fails the probe of GMAC2. The binding lists
+the supported SoCs: BCM4708, BCM53011 and BCM53012. Do not set
+``dsa-tag-protocol``: B53 does not implement the runtime protocol-change
+operation. No existing board is enabled automatically by this series.
+
+The FA registers are in the 4 KiB BCMA window of the GMAC3 core, outside the
+0x800 bytes of its own registers. They are managed by the GMAC2 consumer; they
+do not need a separate platform driver or character device. The driver neither
+enables nor resets the GMAC3 core. bgmac only probes GMAC3 when it has a MAC
+address, which would reset the core and the accelerator state: do not
+give GMAC3 one. Whether the registers can be accessed depends on the state in
+which the bootloader leaves that core, which has not been established for all
+boards. Leave the accelerator disabled or omit the GMAC2 phandle to retain the
+existing board configuration.
+
+Standalone WAN and bridged LAN
+------------------------------
+
+A common router configuration keeps the WAN separate and assigns the LAN
+IPv4 address to a bridge. For example, with ``lan1`` through ``lan4`` as
+switch ports, ``wan`` as the standalone WAN, and ``wlan0`` as the WLAN::
+
+  ip link add br-lan type bridge vlan_filtering 0
+  ip link set br-lan address 02:00:00:00:01:01
+  for dev in lan1 lan2 lan3 lan4 wlan0; do
+      ip link set "$dev" master br-lan
+      ip link set "$dev" up
+  done
+  ip address add 192.0.2.1/24 dev br-lan
+  ip link set br-lan up
+  ip link set wan address 02:00:00:00:03:01
+  ip address add 198.51.100.1/24 dev wan
+  ip link set wan up
+
+Remove the LAN IPv4 address from individual member ports before assigning
+it to the bridge. The LAN and WAN router MACs must be distinct. Keep the
+GMAC0 exception connection operational as for the standalone-port setup.
+Use bridge ports in the flowtable and the bridge name in routed firewall
+and NAT rules::
+
+  flowtable ft {
+      hook ingress priority 0;
+      devices = { lan1, lan2, lan3, lan4, wan };
+      flags offload;
+      counter;
+  }
+
+The hardware table can bind only devices which support flowtable offload.
+Keep WLAN devices out of this table: their connections use normal software
+forwarding, including the bridge FDB lookup. For the software-flowtable
+control test, omit ``flags offload`` and add ``wlan0`` to the device list.
+
+For the later test rules, replace LAN ``iifname`` and ``oifname`` matches
+with ``br-lan`` and retain ``wan`` for the WAN. Wired LAN-to-WAN connections
+can use FA in both directions. Connections using a WLAN or another software
+bridge port retain software forwarding; adding that member does not disable
+wired offload. VLAN filtering, stacked bridges, locked or isolated accelerated
+ports, and a second active LAN routing domain are not supported by this
+initial bridge implementation.
+
+Bridge FDB changes invalidate cached bridge paths in software as well as
+the FA entries. In particular, a software-only owner must not keep sending
+replies to a WLAN member after its client moves to a wired port. The next
+packet takes the normal forwarding path until the retired owner has been
+removed, then a fresh cache can resolve the new physical bridge port.
+
+Qualify both protocols and NAT initiation directions using classic,
+software-flowtable and hardware modes. While counters advance, exercise:
+
+* All four wired LAN members, including ordinary LAN-to-LAN switching,
+  unknown-unicast flooding and broadcast delivery to a software member.
+* The bridge MAC differing from every member MAC, and a failed MAC change.
+* Wired client movement while reusing a live tuple without ARP or TCP
+  SYN/FIN/RST, and movement between a wired port and WLAN.
+* FDB replacement, deletion and aging, including ``master dynamic`` entries
+  intentionally omitted from switchdev notifications.
+* Member removal/addition, STP blocking, auxiliary-link loss, and a VLAN
+  filtering toggle. Unsupported configurations must keep working in software.
+* Concurrent WLAN software forwarding and wired FA traffic, checking
+  duplicate delivery, wire NAT/checksum/TTL correctness and raw FA keys.
+* Client-guard and NAT-table exhaustion, teardown, recovery, and a mixed
+  TCP/UDP soak with bridge FDB aging left enabled.
+
+A veth bridge member can test software-member forwarding and movement in
+an automated lab. It does not qualify a real WLAN driver or association
+and roaming behavior; repeat those cases with the intended PCIe radio.
+
+Three-host hardware test
+------------------------
+
+Before any traffic test, read the accelerator control registers at 0x18027c00,
+for example with ``devmem``, after a cold boot, both with GMAC3 enabled and
+disabled in the device tree. A bus error or a timeout during probe means that
+the registers are not accessible in the state in which the bootloader leaves
+that core, and the board cannot use the accelerator.
+
+Use a dedicated test router with serial access and two external Linux hosts.
+Traffic generated on the router itself does not exercise the inline receive
+path. Keep all other switch user ports administratively down. Replace the
+interface names below with those on the board::
+
+  LAN host                 BCM5301X router               WAN host
+  192.0.2.2/24 -- lan1 192.0.2.1   198.51.100.1 wan -- 198.51.100.2/24
+                           \       /
+                         GMAC2 / FA
+
+Assign distinct router MACs before bringing up the interfaces::
+
+  ip link set lan1 down
+  ip link set wan down
+  ip link set lan1 address 02:00:00:00:01:01
+  ip link set wan address 02:00:00:00:02:01
+  ip addr add 192.0.2.1/24 dev lan1
+  ip addr add 198.51.100.1/24 dev wan
+  ip link set lan1 up
+  ip link set wan up
+  sysctl -w net.ipv4.ip_forward=1
+
+On the LAN host, assign 192.0.2.2/24 and a default route via 192.0.2.1.
+On the WAN host, assign 198.51.100.2/24 and a default route via 198.51.100.1.
+Do not put the router ports in a bridge or create VLAN uppers. Ensure that
+other firewall rules on this lab router permit the test packets.
+
+Mount debugfs if necessary and locate the FA status file::
+
+  mount -t debugfs none /sys/kernel/debug
+  find /sys/kernel/debug -name fa -type f
+  cat /sys/kernel/debug/<GMAC2-device-name>/fa
+
+The file contains ``failed``, global ``hits`` and ``misses``, error bits,
+and a row for every programmed directional entry. Each row identifies its
+slot, cookie, input/output interfaces, and raw hardware packet count. Save
+snapshots with timestamps before, during, and after every test.
+
+The adjacent ``fa_table`` file shows each software-owned tuple and the eight
+hardware words in DATA7 through DATA0 order. It uses the same lock and
+bounded indirect accesses as statistics collection. Save it when an entry
+stops counting to compare the hardware key against software ownership.
+
+Install a uniquely named test table; do not flush unrelated tables::
+
+  table inet fa_test {
+      flowtable ft {
+          hook ingress priority 0;
+          devices = { lan1, wan };
+          flags offload;
+          counter;
+      }
+      chain forward {
+          type filter hook forward priority 0; policy drop;
+          meta l4proto { tcp, udp } ct state established flow add @ft
+          ct state established,related counter accept
+          iifname "lan1" oifname "wan" meta l4proto { tcp, udp } th dport 5001 counter accept
+          iifname "wan" oifname "lan1" meta l4proto { tcp, udp } th dport 5001 ct status dnat counter accept
+      }
+      chain prerouting {
+          type nat hook prerouting priority dstnat; policy accept;
+          iifname "wan" udp dport 15001 dnat ip to 192.0.2.2:5001
+          iifname "wan" tcp dport 15001 dnat ip to 192.0.2.2:5001
+      }
+      chain postrouting {
+          type nat hook postrouting priority srcnat; policy accept;
+          iifname "lan1" oifname "wan" meta l4proto udp ip saddr 192.0.2.2 snat ip to 198.51.100.1:45000
+          iifname "lan1" oifname "wan" meta l4proto tcp ip saddr 192.0.2.2 snat ip to 198.51.100.1:45000
+      }
+  }
+
+Save this as a ruleset and load it with ``nft -f <file>``. For the two control
+runs described below, edit only this test table. Delete it between phases
+with ``nft delete table inet fa_test``. Delete matching conntrack entries
+between phases, for example::
+
+  conntrack -D -p udp --orig-src 192.0.2.2 --orig-dst 198.51.100.2 --dport 5001
+
+For SNAT, run a UDP or TCP echo server on the WAN host at
+198.51.100.2:5001. Run a client on the LAN host, bind its source to
+192.0.2.2:40000, and connect to that server. Verify the server observes
+the translated peer 198.51.100.1:45000. Include a sequence number in each
+payload and check every returned payload for loss or corruption.
+
+Run three phases with a fresh connection each time:
+
+1. **Normal forwarding:** omit the ``flow add @ft`` rule. Forward-chain
+   counters should grow throughout the test. FA entry counts and hit counts
+   should not grow for this traffic.
+2. **Software flowtable:** restore ``flow add @ft`` and omit ``flags offload``.
+   Expect OFFLOAD and no hardware entries/hit growth for this flow. Reduced
+   forward-chain counters in this phase demonstrate why those counters alone
+   cannot prove hardware offload.
+3. **Hardware flowtable:** restore ``flags offload``. Wait a few seconds for
+   asynchronous rule installation, then compare multiple debugfs snapshots.
+
+The hardware phase passes only when all of the following hold:
+
+* The WAN server sees the peer as 198.51.100.1:45000, proving address and
+  source-port translation. The client receives the original payloads.
+* ``conntrack -L -p udp -o extended`` identifies the expected original and
+  reply tuples and reports HW_OFFLOAD. OFFLOAD alone is insufficient.
+* There are two hardware entry rows for the connection and **both** packet
+  counters advance while the echo stream runs. The netfilter core can mark
+  HW_OFFLOAD when only one direction is accepted, so check each direction.
+* The global FA hit count advances with the transfer, ``failed`` remains 0,
+  and hardware error bits do not increase.
+* Captures on the external hosts show the expected rewritten IPv4/TCP or
+  IPv4/UDP tuples, valid checksums, unchanged payloads, and exactly one TTL
+  decrement.
+* Router CPU load and GMAC DMA packet growth are substantially below the
+  software phase at the same offered packet rate. A router-side capture
+  should see initial misses but few steady-state packets from this stream.
+  Compare external captures; packet-capture placement and GRO can affect
+  counts on the router.
+
+Use ``tcpdump -ni <host-interface> -vv -w <capture.pcap> udp`` on both external
+hosts. If host checksum offload obscures validation, temporarily disable the
+relevant offloads on the test hosts and restore them afterward. Capture from
+the receiving host or a wire tap when checking checksums.
+
+For DNAT, stop the WAN server and run the echo server on the LAN host at
+192.0.2.2:5001. Run the client on the WAN host, bind it to 198.51.100.2:40001,
+and connect it to 198.51.100.1:15001. Verify destination IP/port translation
+on the LAN capture and the source IP/port restoration on the WAN reply.
+Repeat all three phases and require hit growth in both directions.
+
+Stress, teardown, and negative tests
+------------------------------------
+
+* Change SNAT to a port range for parallel sessions. Exercise multiple
+  clients and next hops, hot buckets, more than 128 next-hop MACs, and over
+  512 bidirectional sessions. Failures to allocate must fall back to software
+  without modifying a different connection's entry. Four-way collisions can
+  exhaust a bucket before the whole table is full.
+* Keep a densely occupied table active while repeatedly reading statistics.
+  Compare the software tuples with the raw entries in ``fa_table`` before
+  and after the test. Every valid hardware key must match its owning slot,
+  cookies must stay stable and every active direction's counter must grow.
+  Intact echoes and HW_OFFLOAD labels alone can conceal damaged entries
+  whose traffic has fallen back to software.
+* Stop the generator and wait longer than the configured UDP conntrack
+  timeout. Hardware rows must disappear. Run sustained traffic longer than
+  that timeout and verify that counter-based last-used refresh keeps the
+  connection alive. Check packet counter wrap handling during a long soak.
+* Delete the test flowtable during traffic. Entries must disappear and
+  forwarding must continue through the remaining firewall/NAT path. Delete
+  only the flow-add rule first if retaining the table is useful for this test.
+* Disable ``hw-tc-offload`` on the conduit with ethtool. Entries must be
+  flushed and new hardware insertions rejected. Re-enable it and use fresh
+  connections.
+* Test port down/up, a third port up, router MAC changes, MTU changes, a bridge
+  or VLAN upper being added, conduit down/up, module unload/reload, and
+  suspend/resume if supported. Require removal of stale entries and clean
+  resource reuse. Start fresh connections after each topology change.
+* Try IPv6, ICMP, GRE, PPPoE, VLAN and QinQ devices, double NAT, and
+  hairpin NAT. They must not create FA entries. Exercise tagged packets whose
+  inner tuple equals a live untagged offload; they must not hit that entry.
+* Send IPv4 fragments, IP options, bad IP checksums, runt/truncated headers,
+  and switch exception traffic. Require software handling or the normal
+  stack/switch drop behavior, never a stale or unrelated hardware hit.
+* Verify UDP zero-checksum packets, nonzero checksums, packets whose updated
+  checksum folds to zero, minimum-size frames, and maximum MTU packets.
+* Repeat SNAT, DNAT, table pressure, software fallback, aging and recovery
+  with TCP. Require the TCP bit in every owned raw table key and advancing
+  counters in both directions. Compare classic, software and hardware modes.
+* While hardware data counters advance, capture SYN/FIN/RST on the GMAC0
+  auxiliary conduit. Require embedded Broadcom tags and delivery to Linux.
+  Close with FIN and RST, reuse the same tuple, and change its NAT
+  mapping; require immediate removal of the old hardware directions, correct
+  new peers and intact framed payloads. Repeat with options and fragmented
+  control packets. An HW_OFFLOAD label alone does not qualify this test.
+  Bring GMAC0 down while TCP data flows. Require removal of its hardware
+  rows, intact software forwarding, and rejection of new TCP hardware
+  entries. Bring GMAC0 up and require fresh connections to offload again.
+* Run TCP and UDP with identical IP addresses and transport ports. Require
+  independent hashes, hardware protocol bits and correct payload delivery;
+  closing TCP must leave the UDP directions installed and advancing.
+* With a development fault-injection mechanism, force an indirect-port busy
+  timeout. Require bounded completion, ``failed 1``, no further insertions,
+  no reuse of uncertain table resources, and working software forwarding.
+  Reprobe before repeating. The driver provides no writable debugfs register
+  interface; do not poke live registers from userspace.
+
+Boundary and invalidation qualification
+---------------------------------------
+
+Run these tests with UDP and TCP, SNAT and DNAT, and classic, software
+flowtable and hardware forwarding. Install both hardware directions and
+verify their raw keys before injecting packets of that same live tuple:
+
+* TTL 0 and 1 must produce the software baseline's ICMP time-exceeded
+  response without forwarding a wrapped TTL. Ordinary traffic must decrement
+  TTL exactly once.
+* An IP length of 1500 must pass. At 1501, DF must produce ICMP fragmentation
+  needed with MTU 1500; without DF, Linux must fragment into packets no
+  larger than 1500. Check transport checksums after reassembly.
+* Inject the tuple on the opposite physical port, addressed both to the
+  original input MAC and the receiving port's MAC. Require the same ingress
+  firewall policy as the software baseline. Also test unrelated unicast,
+  broadcast and multicast destination MACs. These must not enter IPv4
+  forwarding merely because a five-tuple matches.
+
+While a hardware connection is live, replace its neighbour MAC and require
+all subsequently forwarded frames to use the new MAC. Set the neighbour to
+``NUD_FAILED`` while preventing ARP replies and require forwarding to stop.
+Restore reachability and require recovery. Force a valid neighbour to STALE
+while hardware counters advance and require a Linux ARP reachability probe.
+
+Install a blackhole host route and then a source-policy blackhole rule;
+require forwarding to stop after each netlink acknowledgment. Remove each
+change and check payload delivery and fresh hardware admission. Add an MTU
+1200 host route both during an existing connection and before a fresh one.
+Require zero hardware entries, intact small software-forwarded packets and
+ICMP fragmentation-needed with MTU 1200 for a 1280-byte DF probe. Remove
+that route and verify recovery. Keep the flowtable installed throughout;
+recreating it would conceal missing invalidation.
+
+Fault injection qualification
+-----------------------------
+
+A development kernel can enable ``CONFIG_FAULT_INJECTION``,
+``CONFIG_FAULT_INJECTION_DEBUG_FS`` and
+``CONFIG_BCM_NS_FA_FAULT_INJECTION``. The per-device ``fail_table`` directory
+uses the standard fault-injection attributes. The default probability is
+zero. Injection returns a timeout after an indirect transfer has completed,
+which deliberately makes completion uncertain to its caller. This tests
+software handling of uncertain reads and writes, including a write that may
+already have published an entry; it does not emulate a physical bus hang.
+The ordinary hardware busy/address waits remain bounded independently.
+
+For one injected failure, with the device name adjusted as needed::
+
+  D=/sys/kernel/debug/bcma0:5
+  echo 1 > $D/fail_table/times
+  echo 1 > $D/fail_table/interval
+  echo 0 > $D/fail_table/space
+  echo 100 > $D/fail_table/probability
+
+The next table access fails. To restrict injection to a table write, set
+``fail_table_write_only`` to ``Y`` before arming it, then insert a fresh
+connection or delete an installed one. Run read, insertion and deletion
+cases on separate clean probes. Verify ``failed 1`` and exactly one
+``fault_injections`` increment. Lookup must be disabled before the paused
+switch traffic resumes. Broadcom-tag relocation must remain active, and
+uncertain entries and MAC resources must not be reused until reprobe.
+
+Keep UDP and TCP SNAT/DNAT traffic active across each failure. Validate all
+eight wire directions for correct tuples, payloads, checksums and exactly
+one TTL decrement. Require a fresh connection to work in software and an
+ethtool feature toggle to leave the failed state latched. Stop the test,
+reprobe and require clean hardware admission again. Do not poke live
+registers from userspace; no writable register interface is provided.
+
+Automated validation
+--------------------
+
+Run the supplied KUnit configuration from a clean source tree::
+
+  ./tools/testing/kunit/kunit.py run --arch=x86_64 \
+      --kunitconfig=drivers/net/ethernet/broadcom/.kunitconfig \
+      --build_dir=/tmp/bcm-ns-fa-kunit
+
+The backend, switch and tagger provide KUnit suites named ``bcm-ns-fa``,
+``b53-fa-guards`` and ``brcm-fa-tag``. Enable ``CONFIG_BCM_NS_FA_KUNIT_TEST``,
+``CONFIG_NET_DSA_TAG_BRCM_FA_KUNIT_TEST`` and ``CONFIG_B53_FA_KUNIT_TEST``
+with KUnit and their parent drivers. ``CONFIG_NF_FLOW_TABLE_KUNIT_TEST``
+adds the ``nf-flow-lifetime`` and ``nf-flow-path`` suites for flowtable
+ownership and cached route validation, which the configuration also enables,
+so do not filter the suites by name. A few cases which access registers are
+skipped on UML, where MMIO is emulated.
+They cover cross-word field layout and endianness, NAT action rejection,
+miss-hash learning exclusions, opcode validation, source-port demultiplexing,
+consumption of the four-byte metadata tag, route-MTU admission and CFP UDF
+layout. The length-prefix test checks all 65536 possible IPv4 lengths.
+These tests do not simulate the FA.
+
+Build the bgmac, B53, and DSA objects with ``W=1`` for ARM, plus an x86
+COMPILE_TEST configuration; also check the FA-disabled configuration and
+built-in/module combinations. Run ``dt_binding_check`` for both new schemas,
+``checkpatch.pl``, and ``git diff --check``. The hardware matrix above remains
+mandatory even when all automated checks pass.
Documentation/networking/device_drivers/ethernet/index.rst +1 -0
index 403ae9c2b06a9..007e5c5c892ac 100644
@@ -18,6 +18,7 @@ Contents:
    amd/pds_vdpa
    amd/pds_vfio_pci
    aquantia/atlantic
+   broadcom/bcm-ns-fa
    chelsio/cxgb
    dlink/dl2k
    davicom/dm9000
MAINTAINERS +1 -0
index c05ac2258889e..7fbc78f9dd413 100644
@@ -5672,6 +5672,7 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/net/brcm,amac.yaml
 F:	Documentation/devicetree/bindings/net/brcm,bcm4708-fa.yaml
 F:	Documentation/devicetree/bindings/net/brcm,bcm5301x-gmac.yaml
+F:	Documentation/networking/device_drivers/ethernet/broadcom/bcm-ns-fa.rst
 F:	drivers/net/dsa/b53/b53_fa_test.c
 F:	drivers/net/ethernet/broadcom/.kunitconfig
 F:	drivers/net/ethernet/broadcom/bcm-ns-fa*