Netdev List
 help / color / mirror / Atom feed
From: Florian Fainelli <florian.fainelli@broadcom.com>
To: netdev@vger.kernel.org
Cc: Florian Fainelli <florian.fainelli@broadcom.com>,
	andrew@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
	horms@kernel.org, jonas.gorski@gmail.com, kuba@kernel.org,
	olteanv@gmail.com, pabeni@redhat.com, willemb@google.com
Subject: [PATCH net-next v2 2/6] net: dsa: add Broadcom FA metadata and IPv4 exception paths
Date: Tue,  1 Dec 2026 10:22:23 -0800	[thread overview]
Message-ID: <20261201182227.3990791-3-florian.fainelli@broadcom.com> (raw)
In-Reply-To: <20261201182227.3990791-1-florian.fainelli@broadcom.com>

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.

Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
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(-)

diff --git a/drivers/net/dsa/b53/Kconfig b/drivers/net/dsa/b53/Kconfig
index 915008e8eff53..8e2a8c20bc4ac 100644
--- a/drivers/net/dsa/b53/Kconfig
+++ b/drivers/net/dsa/b53/Kconfig
@@ -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
diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index b7aff5e238e85..234c6a2905e26 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -17,19 +17,25 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#include <linux/bitfield.h>
 #include <linux/delay.h>
+#include <linux/dsa/brcm.h>
 #include <linux/export.h>
 #include <linux/gpio/consumer.h>
+#include <linux/in.h>
+#include <linux/iopoll.h>
 #include <linux/kernel.h>
 #include <linux/math.h>
 #include <linux/minmax.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/platform_data/b53.h>
 #include <linux/phy.h>
 #include <linux/phylink.h>
 #include <linux/etherdevice.h>
 #include <linux/if_bridge.h>
 #include <linux/if_vlan.h>
+#include <linux/unaligned.h>
 #include <net/dsa.h>
 
 #include "b53_regs.h"
@@ -667,9 +673,10 @@ static void b53_eee_enable_set(struct dsa_switch *ds, int port, bool enable)
 int b53_setup_port(struct dsa_switch *ds, int port)
 {
 	struct b53_device *dev = ds->priv;
+	bool auxiliary = dev->fa_cfp_enabled && port == 5;
 
-	b53_port_set_ucast_flood(dev, port, true);
-	b53_port_set_mcast_flood(dev, port, true);
+	b53_port_set_ucast_flood(dev, port, !auxiliary);
+	b53_port_set_mcast_flood(dev, port, !auxiliary);
 	b53_port_set_learning(dev, port, false);
 	b53_port_set_isolated(dev, port, false);
 
@@ -678,7 +685,8 @@ int b53_setup_port(struct dsa_switch *ds, int port)
 	 * dropping frames because it isn't allowed to forward there.
 	 */
 	if (dsa_is_user_port(ds, port))
-		b53_set_eap_mode(dev, port, EAP_MODE_SIMPLIFIED);
+		b53_set_eap_mode(dev, port, dev->fa_cfp_enabled ? EAP_MODE_BASIC :
+			 EAP_MODE_SIMPLIFIED);
 
 	if (is5325(dev) &&
 	    in_range(port, 1, 4)) {
@@ -728,6 +736,8 @@ int b53_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy)
 	pvlan &= ~0x1ff;
 	pvlan |= BIT(port);
 	pvlan |= dev->ports[port].vlan_ctl_mask;
+	if (dev->fa_cfp_enabled && (dev->fa_cfp_ports & BIT(port)))
+		pvlan |= BIT(5);
 	b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan);
 
 	b53_imp_vlan_setup(ds, cpu_port);
@@ -1326,6 +1336,391 @@ int b53_setup_devlink_resources(struct dsa_switch *ds)
 }
 EXPORT_SYMBOL(b53_setup_devlink_resources);
 
+static int b53_fa_cfp_wait(struct b53_device *dev, u32 mask)
+{
+	u32 val;
+	int ret, err;
+
+	ret = read_poll_timeout(b53_read32, err, err || !(val & mask),
+				10, 10000, false, dev, B53_CFP_TCAM_PAGE,
+				B53_CFP_ACC, &val);
+	return ret ?: err;
+}
+
+static int b53_fa_cfp_write(struct b53_device *dev, unsigned int index, u32 ram)
+{
+	int err;
+
+	err = b53_write32(dev, B53_CFP_TCAM_PAGE, B53_CFP_ACC,
+			  CFP_ACC_INDEX(index) | ram | CFP_ACC_WRITE | CFP_ACC_START);
+	return err ?: b53_fa_cfp_wait(dev, CFP_ACC_START);
+}
+
+#define B53_FA_GUARD_BASE 16
+#define B53_FA_CLIENT_BASE 64
+
+static void b53_fa_udf(u32 data[8], u32 mask[8], unsigned int udf,
+		       u16 value, u16 bits)
+{
+	unsigned int bit = CFP_TCAM_UDF_OFFSET + 16 * udf;
+	unsigned int word = bit / 32;
+	unsigned int shift = bit % 32;
+
+	data[word] |= (u32)value << shift;
+	mask[word] |= (u32)bits << shift;
+	if (shift > 16) {
+		data[word + 1] |= value >> (32 - shift);
+		mask[word + 1] |= bits >> (32 - shift);
+	}
+	bit = 5 * 32 + 24 + udf;
+	data[bit / 32] |= BIT(bit % 32);
+	mask[bit / 32] |= BIT(bit % 32);
+}
+
+static int b53_fa_rule(struct b53_device *dev, unsigned int index,
+		       const u32 data[8], const u32 mask[8], bool trap)
+{
+	unsigned int i;
+	int err;
+
+	for (i = 0; i < 8; i++) {
+		err = b53_write32(dev, B53_CFP_TCAM_PAGE, B53_CFP_DATA(i), data[i]);
+		if (!err)
+			err = b53_write32(dev, B53_CFP_TCAM_PAGE, B53_CFP_MASK(i), mask[i]);
+		if (err)
+			return err;
+	}
+	err = b53_write32(dev, B53_CFP_TCAM_PAGE, B53_CFP_ACTION(0),
+			  trap ? CFP_ACT0_FWD_MAP_REPLACE | CFP_ACT0_DST_PORT5 |
+				CFP_ACT0_REASON_TERMINATION : 0);
+	if (!err)
+		err = b53_write32(dev, B53_CFP_TCAM_PAGE, B53_CFP_ACTION(1),
+				  trap ? CFP_ACT1_CLASS_ID(1) | CFP_ACT1_FWD_MAP_REPLACE |
+				  CFP_ACT1_DST_PORT5 : 0);
+	if (!err)
+		err = b53_fa_cfp_write(dev, index, CFP_ACC_ACTION);
+	if (!err)
+		err = b53_write32(dev, B53_CFP_TCAM_PAGE, B53_CFP_METER, 0);
+	if (!err)
+		err = b53_write32(dev, B53_CFP_TCAM_PAGE, B53_CFP_METER + 4, 0);
+	if (!err)
+		err = b53_fa_cfp_write(dev, index, CFP_ACC_METER);
+	return err ?: b53_fa_cfp_write(dev, index, CFP_ACC_TCAM);
+}
+
+static const u16 b53_fa_lengths[][2] = {
+	{ 1501, 0xffff }, { 1502, 0xfffe }, { 1504, 0xffe0 },
+	{ 1536, 0xfe00 }, { 2048, 0xf800 }, { 4096, 0xf000 },
+	{ 8192, 0xe000 }, { 16384, 0xc000 }, { 32768, 0x8000 },
+};
+
+static int b53_fa_guards(struct b53_device *dev)
+{
+	u32 data[8] = {}, mask[8] = {};
+	unsigned int i;
+	int err;
+
+	/* UDF A1: IPv4 TTL/protocol; A2: IPv4 total length. */
+	err = b53_write8(dev, B53_CFP_PAGE, B53_CFP_UDF1_A0 + 1,
+			 CFP_UDF_BASE_END_L2 | CFP_UDF_OFFSET(4));
+	if (!err)
+		err = b53_write8(dev, B53_CFP_PAGE, B53_CFP_UDF1_A0 + 2,
+				 CFP_UDF_BASE_END_L2 | CFP_UDF_OFFSET(1));
+	for (i = 0; !err && i < 3; i++)
+		err = b53_write8(dev, B53_CFP_PAGE, B53_CFP_UDF1_A0 + 3 + i, i);
+	if (err)
+		return err;
+	data[0] = CFP_TCAM0_VALID | CFP_TCAM0_SLICE1;
+	mask[0] = CFP_TCAM0_VALID | CFP_TCAM0_SLICE_MASK;
+	mask[6] = CFP_TCAM6_L3_FRAMING; /* IPv4, including options and fragments. */
+	b53_fa_udf(data, mask, 1, 0, 0xfe00); /* TTL 0 or 1. */
+	err = b53_fa_rule(dev, 3, data, mask, true);
+	for (i = 0; !err && i < ARRAY_SIZE(b53_fa_lengths); i++) {
+		memset(data, 0, sizeof(data));
+		memset(mask, 0, sizeof(mask));
+		data[0] = CFP_TCAM0_VALID | CFP_TCAM0_SLICE1;
+		mask[0] = CFP_TCAM0_VALID | CFP_TCAM0_SLICE_MASK;
+		mask[6] = CFP_TCAM6_L3_FRAMING;
+		b53_fa_udf(data, mask, 2, b53_fa_lengths[i][0], b53_fa_lengths[i][1]);
+		err = b53_fa_rule(dev, 4 + i, data, mask, true);
+	}
+	if (err)
+		return err;
+	/* UDF A6..A8: source MAC for active bridge-client move guards. */
+	for (i = 0; !err && i < 3; i++)
+		err = b53_write8(dev, B53_CFP_PAGE, B53_CFP_UDF1_A0 + 6 + i, 3 + i);
+	return err;
+}
+
+/* Original FA ignores switch exceptions on its inline port. Redirect IPv4
+ * exceptions through GMAC0/IMP1, outside FA, while GMAC2/IMP0 carries data.
+ * Reserve classifier rules only when the board describes both CPU paths.
+ */
+static int b53_fa_setup(struct b53_device *dev)
+{
+	struct dsa_port *dp;
+	unsigned int rule;
+	u32 data[8], mask[8];
+	int err;
+
+	if (!is5301x(dev) || dev->tag_protocol != DSA_TAG_PROTO_BRCM_FA ||
+	    !dsa_is_cpu_port(dev->ds, 5) || !dsa_is_cpu_port(dev->ds, 8))
+		return 0;
+
+	err = b53_write16(dev, B53_CFP_PAGE, B53_CFP_CTRL, 0);
+	if (err)
+		return err;
+	err = b53_write32(dev, B53_CFP_TCAM_PAGE, B53_CFP_ACC, CFP_ACC_RESET);
+	if (!err)
+		err = b53_fa_cfp_wait(dev, CFP_ACC_RESET);
+	if (err)
+		return err;
+	/* Slice 1 UDF A0 extracts TCP bytes 12..13, relative to the parsed end of L3.
+	 * This also works with IP options. Match the individual
+	 * FIN/SYN/RST bits, never payload bytes in UDP packets. Slice 0
+	 * with a nonzero class ID would request a chained search instead.
+	 */
+	err = b53_write8(dev, B53_CFP_PAGE, B53_CFP_UDF1_A0,
+			 CFP_UDF_BASE_END_L3 | CFP_UDF_OFFSET(6));
+	if (err)
+		return err;
+	for (rule = 0; rule < 3; rule++) {
+		memset(data, 0, sizeof(data));
+		memset(mask, 0, sizeof(mask));
+		data[0] = CFP_TCAM0_VALID | CFP_TCAM0_SLICE1 | CFP_TCAM0_UDF0_FLAG(rule);
+		/* Slice 1; FIN, SYN or RST. */
+		mask[0] = CFP_TCAM0_VALID | CFP_TCAM0_SLICE_MASK | CFP_TCAM0_UDF0_FLAG(rule);
+		data[5] = CFP_TCAM5_UDF_VALID(0); /* UDF A0 valid. */
+		mask[5] = CFP_TCAM5_UDF_VALID(0);
+		data[6] = FIELD_PREP(CFP_TCAM6_IP_PROTOCOL, IPPROTO_TCP);
+		mask[6] = CFP_TCAM6_L3_FRAMING | CFP_TCAM6_IP_PROTOCOL | CFP_TCAM6_IP_FRAGMENT;
+		/* Both meter outcomes redirect to IMP1, with class 1 and a
+		 * termination reason. Preserve VLAN, EAP and STP filtering.
+		 */
+		err = b53_fa_rule(dev, rule, data, mask, true);
+		if (err)
+			return err;
+	}
+	err = b53_fa_guards(dev);
+	if (err)
+		return err;
+	/* Unicast and multicast flooding must reach only the data CPU. The
+	 * RX_xCST_EN bits only exist in the port 8 IMP control register.
+	 */
+	b53_port_set_ucast_flood(dev, 5, false);
+	b53_port_set_mcast_flood(dev, 5, false);
+	dev->fa_cfp_ports = 0;
+	dsa_switch_for_each_user_port(dp, dev->ds)
+		dev->fa_cfp_ports |= BIT(dp->index);
+	dev->fa_user_ports = dev->fa_cfp_ports;
+	/* The conduit state callback enables these rules after GMAC0 is up. */
+	err = b53_write16(dev, B53_CFP_PAGE, B53_CFP_CTRL, 0);
+	if (!err)
+		dev->fa_cfp_enabled = true;
+	return err;
+}
+
+static bool b53_fa_ready(struct b53_device *dev, bool operational)
+{
+	/* Every user port must have its exception rules: the FA key has no input
+	 * port, so a port without them could inject into a live tuple.
+	 */
+	return operational && READ_ONCE(dev->fa_guards_ready) &&
+	       !READ_ONCE(dev->fa_guards_failed) &&
+	       dev->fa_cfp_ports == dev->fa_user_ports;
+}
+
+static void b53_fa_retire(struct b53_device *dev)
+{
+	struct dsa_port *data = dsa_to_port(dev->ds, B53_CPU_PORT);
+
+	/* Retire offloads before removing any of the exception paths. */
+	if (data && data->conduit)
+		brcm_fa_control_set_ready(data->conduit, false);
+}
+
+/* Apply the readiness of the exception paths: retire first, then enable the
+ * rules and only then allow new entries. Failing to update the hardware keeps
+ * FA retired.
+ */
+static int b53_fa_update(struct b53_device *dev, bool operational)
+{
+	bool ready = b53_fa_ready(dev, operational);
+	struct dsa_port *data;
+	int err;
+
+	b53_fa_retire(dev);
+	err = b53_write16(dev, B53_CFP_PAGE, B53_CFP_CTRL,
+			  ready ? dev->fa_cfp_ports : 0);
+	if (err) {
+		WRITE_ONCE(dev->fa_guards_failed, true);
+		dev_err(dev->dev, "failed to update FA exception path: %d\n", err);
+		return err;
+	}
+	data = dsa_to_port(dev->ds, B53_CPU_PORT);
+	if (ready && data && data->conduit)
+		brcm_fa_control_set_ready(data->conduit, true);
+	return 0;
+}
+
+static int b53_fa_port(struct b53_device *dev)
+{
+	int err;
+
+	if (!dev->fa_cfp_enabled)
+		return 0;
+	WRITE_ONCE(dev->fa_guards_ready, false);
+	err = b53_fa_update(dev, false);
+	/* Membership changes finish after the switch callback, under RTNL. */
+	if (READ_ONCE(dev->fa_notifier_registered) && !READ_ONCE(dev->fa_stopping))
+		schedule_work(&dev->fa_resync_work);
+	return err;
+}
+
+static void b53_fa_conduit_state_change(struct dsa_switch *ds,
+					const struct net_device *conduit, bool operational)
+{
+	struct b53_device *dev = ds->priv;
+	struct dsa_port *control;
+
+	if (!dev->fa_cfp_enabled)
+		return;
+	control = dsa_to_port(ds, 5);
+	if (conduit != control->conduit)
+		return;
+	b53_fa_update(dev, operational);
+}
+
+/* Called under RTNL, after the bridge membership/MAC transaction. */
+static const u8 *b53_fa_router_mac(struct dsa_port *dp)
+{
+	struct net_device *upper = netdev_master_upper_dev_get(dp->user);
+
+	return upper && netif_is_bridge_master(upper) ? upper->dev_addr : dp->user->dev_addr;
+}
+
+static int b53_fa_update_guard(struct b53_device *dev, struct dsa_port *dp)
+{
+	const u8 *addr = b53_fa_router_mac(dp);
+	u32 data[8] = {}, mask[8] = {};
+	struct dsa_port *other;
+	unsigned int i;
+
+	data[0] = CFP_TCAM0_VALID | CFP_TCAM0_SLICE1;
+	mask[0] = CFP_TCAM0_VALID | CFP_TCAM0_SLICE_MASK;
+	mask[6] = CFP_TCAM6_L3_FRAMING;
+	/* Source ports are one-hot. Match this router MAC outside its own
+	 * L3 domain, allowing all ports of the same LAN bridge to share it.
+	 * Other destination MACs cannot hit FA's router-MAC pool and retain
+	 * ordinary bridge switching, including copies to software ports.
+	 */
+	dsa_switch_for_each_user_port(other, dev->ds)
+		if (other->user && ether_addr_equal(addr, b53_fa_router_mac(other)))
+			mask[7] |= BIT(other->index);
+	for (i = 0; i < 3; i++)
+		b53_fa_udf(data, mask, 3 + i, get_unaligned_be16(addr + 2 * i), 0xffff);
+	return b53_fa_rule(dev, B53_FA_GUARD_BASE + dp->index, data, mask, true);
+}
+
+static int b53_fa_client_guard(void *priv, unsigned int slot, const u8 *addr,
+			       unsigned int port)
+{
+	struct b53_device *dev = priv;
+	u32 data[8] = {}, mask[8] = {};
+	unsigned int i;
+	int err;
+
+	if (addr) {
+		if (port >= 8 || !dsa_is_user_port(dev->ds, port))
+			return -EINVAL;
+		data[0] = CFP_TCAM0_VALID | CFP_TCAM0_SLICE1;
+		mask[0] = CFP_TCAM0_VALID | CFP_TCAM0_SLICE_MASK;
+		mask[6] = CFP_TCAM6_L3_FRAMING;
+		/* A client appearing on any other input must reach bridge
+		 * learning before it can hit an entry with the old egress port.
+		 */
+		mask[7] = BIT(port);
+		for (i = 0; i < 3; i++)
+			b53_fa_udf(data, mask, 6 + i, get_unaligned_be16(addr + 2 * i), 0xffff);
+	}
+	err = b53_fa_rule(dev, B53_FA_CLIENT_BASE + slot, data, mask, true);
+	if (err)
+		WRITE_ONCE(dev->fa_guards_failed, true);
+	return err;
+}
+
+/* Rewrite all router-domain guards from the current MAC addresses. This also restores
+ * the rules after a MAC address change which did not complete.
+ */
+static void b53_fa_resync_work(struct work_struct *work)
+{
+	struct b53_device *dev = container_of(work, struct b53_device, fa_resync_work);
+	struct dsa_port *control, *dp;
+
+	rtnl_lock();
+	if (!READ_ONCE(dev->fa_stopping)) {
+		b53_fa_retire(dev);
+		control = dsa_to_port(dev->ds, 5);
+		dsa_switch_for_each_user_port(dp, dev->ds) {
+			if (dp->index >= 8 || !dp->user)
+				continue;
+			if (b53_fa_update_guard(dev, dp)) {
+				WRITE_ONCE(dev->fa_guards_failed, true);
+				dev_err(dev->dev, "failed to update FA ingress guard\n");
+			}
+		}
+		WRITE_ONCE(dev->fa_guards_ready, true);
+		b53_fa_update(dev, dsa_port_conduit_is_operational(control));
+	}
+	rtnl_unlock();
+}
+
+static int b53_fa_netdev_event(struct notifier_block *nb, unsigned long event, void *ptr)
+{
+	struct b53_device *dev = container_of(nb, struct b53_device, fa_netdev_nb);
+	struct net_device *netdev = netdev_notifier_info_to_dev(ptr);
+	struct dsa_port *dp;
+
+	if (READ_ONCE(dev->fa_stopping) ||
+	    (event != NETDEV_REGISTER && event != NETDEV_UP &&
+	     event != NETDEV_PRE_CHANGEADDR && event != NETDEV_CHANGEADDR &&
+	     event != NETDEV_PRECHANGEUPPER && event != NETDEV_CHANGEUPPER))
+		return NOTIFY_DONE;
+	if (!netif_is_bridge_master(netdev)) {
+		if (!dsa_user_dev_check(netdev))
+			return NOTIFY_DONE;
+		dp = dsa_port_from_netdev(netdev);
+		if (dp->ds != dev->ds || dp->index >= 8)
+			return NOTIFY_DONE;
+	}
+	/* A vetoed MAC change may have no completion event. Resynchronize
+	 * after RTNL is released, using whichever addresses actually remain.
+	 */
+	b53_fa_port(dev);
+	return NOTIFY_DONE;
+}
+
+/* Stop tracking user devices and disable the exception paths. Must not be
+ * called with RTNL held.
+ */
+void b53_fa_stop(struct b53_device *dev)
+{
+	if (!dev->fa_notifier_registered && !dev->fa_switch_registered)
+		return;
+	WRITE_ONCE(dev->fa_stopping, true);
+	if (dev->fa_notifier_registered)
+		unregister_netdevice_notifier(&dev->fa_netdev_nb);
+	cancel_work_sync(&dev->fa_resync_work);
+	dev->fa_notifier_registered = false;
+	b53_fa_retire(dev);
+	if (dev->fa_switch_registered) {
+		brcm_fa_switch_unregister(&dev->fa_switch);
+		dev->fa_switch_registered = false;
+	}
+	b53_write16(dev, B53_CFP_PAGE, B53_CFP_CTRL, 0);
+}
+EXPORT_SYMBOL(b53_fa_stop);
+
 static int b53_setup(struct dsa_switch *ds)
 {
 	struct b53_device *dev = ds->priv;
@@ -1391,11 +1786,20 @@ static int b53_setup(struct dsa_switch *ds)
 	if (ret)
 		return ret;
 
+	ret = b53_fa_setup(dev);
+	if (ret)
+		return ret;
+
 	return b53_setup_devlink_resources(ds);
 }
 
 static void b53_teardown(struct dsa_switch *ds)
 {
+	struct b53_device *dev = ds->priv;
+
+	WRITE_ONCE(dev->fa_stopping, true);
+	if (dev->fa_cfp_enabled)
+		b53_write16(dev, B53_CFP_PAGE, B53_CFP_CTRL, 0);
 	dsa_devlink_resources_unregister(ds);
 }
 
@@ -1745,8 +2149,12 @@ int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering,
 		       struct netlink_ext_ack *extack)
 {
 	struct b53_device *dev = ds->priv;
+	int err;
 
 	if (dev->vlan_filtering != vlan_filtering) {
+		err = b53_fa_port(dev);
+		if (err)
+			return err;
 		dev->vlan_filtering = vlan_filtering;
 		b53_apply_config(dev);
 	}
@@ -1813,6 +2221,13 @@ int b53_vlan_add(struct dsa_switch *ds, int port,
 		vl->untag |= BIT(port);
 	else
 		vl->untag &= ~BIT(port);
+	/* CFP redirects to the auxiliary CPU port, which VLAN filtering still
+	 * applies to: keep it a tagged member wherever the data CPU port is.
+	 */
+	if (dev->fa_cfp_enabled && port == B53_CPU_PORT) {
+		vl->members |= BIT(5);
+		vl->untag &= ~BIT(5);
+	}
 
 	if (!dev->vlan_filtering)
 		return 0;
@@ -1846,6 +2261,8 @@ int b53_vlan_del(struct dsa_switch *ds, int port,
 	vl = &dev->vlans[vlan->vid];
 
 	vl->members &= ~BIT(port);
+	if (dev->fa_cfp_enabled && port == B53_CPU_PORT)
+		vl->members &= ~BIT(5);
 
 	if (pvid == vlan->vid)
 		pvid = b53_default_pvid(dev);
@@ -2332,6 +2749,7 @@ int b53_br_join(struct dsa_switch *ds, int port, struct dsa_bridge bridge,
 	s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index;
 	u16 pvlan, reg, pvid;
 	unsigned int i;
+	int err;
 
 	/* On 7278, port 7 which connects to the ASP should only receive
 	 * traffic from matching CFP rules.
@@ -2339,6 +2757,10 @@ int b53_br_join(struct dsa_switch *ds, int port, struct dsa_bridge bridge,
 	if (dev->chip_id == BCM7278_DEVICE_ID && port == 7)
 		return -EINVAL;
 
+	err = b53_fa_port(dev);
+	if (err)
+		return err;
+
 	pvid = b53_default_pvid(dev);
 	vl = &dev->vlans[pvid];
 
@@ -2416,9 +2838,14 @@ void b53_br_leave(struct dsa_switch *ds, int port, struct dsa_bridge bridge)
 			pvlan &= ~BIT(i);
 	}
 
-	/* Enable redirection of unknown SA to the CPU port */
-	b53_set_eap_mode(dev, port, EAP_MODE_SIMPLIFIED);
+	/* Enable redirection of unknown SA to the CPU port, except with FA
+	 * where CFP classifies standalone traffic instead.
+	 */
+	b53_set_eap_mode(dev, port, dev->fa_cfp_enabled ? EAP_MODE_BASIC :
+			 EAP_MODE_SIMPLIFIED);
 
+	if (dev->fa_cfp_enabled)
+		pvlan |= BIT(5);
 	b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), pvlan);
 	dev->ports[port].vlan_ctl_mask = pvlan;
 
@@ -2439,6 +2866,11 @@ void b53_br_leave(struct dsa_switch *ds, int port, struct dsa_bridge bridge)
 		vl->members |= BIT(port);
 		b53_set_vlan_entry(dev, pvid, vl);
 	}
+	if (b53_fa_port(dev)) {
+		/* fa_cfp_ports records the port, and FA stays disabled. */
+		dev_err(ds->dev, "failed to restore FA classification on port %d\n", port);
+		b53_disable_port(ds, port);
+	}
 }
 EXPORT_SYMBOL(b53_br_leave);
 
@@ -2552,6 +2984,7 @@ static bool b53_can_enable_brcm_tags(struct dsa_switch *ds, int port,
 	switch (tag_protocol) {
 	case DSA_TAG_PROTO_BRCM:
 	case DSA_TAG_PROTO_BRCM_PREPEND:
+	case DSA_TAG_PROTO_BRCM_FA:
 		dev_warn(ds->dev,
 			 "Port %d is stacked to Broadcom tag switch\n", port);
 		ret = false;
@@ -2564,6 +2997,47 @@ static bool b53_can_enable_brcm_tags(struct dsa_switch *ds, int port,
 	return ret;
 }
 
+static bool b53_uses_fa_tag(struct dsa_switch *ds, int port)
+{
+	struct device_node *ports, *node, *ethernet = NULL, *fa = NULL;
+	struct b53_device *dev = ds->priv;
+	bool enabled = false;
+	u32 index;
+
+	if (port != B53_CPU_PORT)
+		return false;
+	/* CPU5 may be parsed before CPU8 has a dsa_port firmware node. */
+	ports = of_get_child_by_name(ds->dev->of_node, "ports");
+	if (!ports)
+		ports = of_get_child_by_name(ds->dev->of_node, "ethernet-ports");
+	for_each_available_child_of_node(ports, node) {
+		if (of_property_read_u32(node, "reg", &index) || index != B53_CPU_PORT)
+			continue;
+		ethernet = of_parse_phandle(node, "ethernet", 0);
+		fa = of_parse_phandle(ethernet, "brcm,flow-accelerator", 0);
+		enabled = IS_ENABLED(CONFIG_BCM_NS_FA) && is5301x(dev) &&
+			  of_device_is_available(fa) &&
+			  (of_device_is_compatible(fa, "brcm,bcm4708-fa") ||
+			   of_device_is_compatible(fa, "brcm,bcm53011-fa") ||
+			   of_device_is_compatible(fa, "brcm,bcm53012-fa"));
+		of_node_put(node);
+		break;
+	}
+	of_node_put(ports);
+	of_node_put(fa);
+	of_node_put(ethernet);
+	return enabled;
+}
+
+static struct dsa_port *b53_preferred_cpu_port(struct dsa_switch *ds)
+{
+	struct b53_device *dev = ds->priv;
+
+	if (is5301x(dev) && dsa_is_cpu_port(ds, B53_CPU_PORT) && b53_uses_fa_tag(ds, B53_CPU_PORT))
+		return dsa_to_port(ds, B53_CPU_PORT);
+	return NULL;
+}
+
 enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds, int port,
 					   enum dsa_tag_protocol mprot)
 {
@@ -2583,6 +3057,11 @@ enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds, int port,
 		goto out;
 	}
 
+	if (b53_uses_fa_tag(ds, B53_CPU_PORT)) {
+		dev->tag_protocol = DSA_TAG_PROTO_BRCM_FA;
+		goto out;
+	}
+
 	/* Broadcom BCM58xx chips have a flow accelerator on Port 8
 	 * which requires us to use the prepended Broadcom tag type
 	 */
@@ -2763,6 +3242,8 @@ static const struct phylink_mac_ops b53_phylink_mac_ops = {
 
 static const struct dsa_switch_ops b53_switch_ops = {
 	.get_tag_protocol	= b53_get_tag_protocol,
+	.preferred_default_local_cpu_port = b53_preferred_cpu_port,
+	.conduit_state_change = b53_fa_conduit_state_change,
 	.setup			= b53_setup,
 	.teardown		= b53_teardown,
 	.get_strings		= b53_get_strings,
@@ -3385,7 +3866,30 @@ int b53_switch_register(struct b53_device *dev)
 	dev_info(dev->dev, "found switch: %s, rev %i\n",
 		 dev->name, dev->core_rev);
 
-	return dsa_register_switch(dev->ds);
+	ret = dsa_register_switch(dev->ds);
+	if (ret || !dev->fa_cfp_enabled)
+		return ret;
+	/* Registration replays existing user devices, after their MACs and
+	 * DSA private data are initialized. Keep lookup gated until it finishes.
+	 */
+	dev->fa_netdev_nb.notifier_call = b53_fa_netdev_event;
+	INIT_WORK(&dev->fa_resync_work, b53_fa_resync_work);
+	dev->fa_switch.conduit = dsa_to_port(dev->ds, 8)->conduit;
+	dev->fa_switch.set_guard = b53_fa_client_guard;
+	dev->fa_switch.priv = dev;
+	brcm_fa_switch_register(&dev->fa_switch);
+	dev->fa_switch_registered = true;
+	ret = register_netdevice_notifier(&dev->fa_netdev_nb);
+	if (ret)
+		goto unregister_switch;
+	dev->fa_notifier_registered = true;
+	/* The worker takes RTNL, so all replayed devices are fully visible. */
+	schedule_work(&dev->fa_resync_work);
+	return 0;
+unregister_switch:
+	b53_fa_stop(dev);
+	dsa_unregister_switch(dev->ds);
+	return ret;
 }
 EXPORT_SYMBOL(b53_switch_register);
 
diff --git a/drivers/net/dsa/b53/b53_priv.h b/drivers/net/dsa/b53/b53_priv.h
index c4d2a41c714f6..2a2769b15d1b0 100644
--- a/drivers/net/dsa/b53/b53_priv.h
+++ b/drivers/net/dsa/b53/b53_priv.h
@@ -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);
 }
 
diff --git a/drivers/net/dsa/b53/b53_regs.h b/drivers/net/dsa/b53/b53_regs.h
index cfdb5ed383260..4ca7ea64efc6c 100644
--- a/drivers/net/dsa/b53/b53_regs.h
+++ b/drivers/net/dsa/b53/b53_regs.h
@@ -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 */
diff --git a/include/linux/dsa/brcm.h b/include/linux/dsa/brcm.h
index 47545a9487840..3a99d0a80920f 100644
--- a/include/linux/dsa/brcm.h
+++ b/include/linux/dsa/brcm.h
@@ -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)
diff --git a/include/net/dsa.h b/include/net/dsa.h
index 5d12191b6f6f5..5f926b7fde5bb 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -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,
diff --git a/net/dsa/Kconfig b/net/dsa/Kconfig
index 4f44bf3ede238..d62de6f716cd9 100644
--- a/net/dsa/Kconfig
+++ b/net/dsa/Kconfig
@@ -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
diff --git a/net/dsa/tag_brcm.c b/net/dsa/tag_brcm.c
index b58669c921474..df1e43f8b11a9 100644
--- a/net/dsa/tag_brcm.c
+++ b/net/dsa/tag_brcm.c
@@ -9,6 +9,7 @@
 #include <linux/etherdevice.h>
 #include <linux/if_vlan.h>
 #include <linux/list.h>
+#include <linux/mutex.h>
 #include <linux/slab.h>
 
 #include "tag.h"
@@ -17,6 +18,8 @@
 #define BRCM_LEGACY_NAME	"brcm-legacy"
 #define BRCM_LEGACY_FCS_NAME	"brcm-legacy-fcs"
 #define BRCM_PREPEND_NAME	"brcm-prepend"
+#define BRCM_FA_NAME		"brcm-fa"
+#define BRCM_FA_OPCODE_MISS	2
 
 /* Legacy Broadcom tag (6 bytes) */
 #define BRCM_LEG_TAG_LEN	6
@@ -84,7 +87,8 @@
 #define BRCM_EG_PID_MASK	0x1f
 
 #if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM) || \
-	IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM_PREPEND)
+	IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM_PREPEND) || \
+	IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM_FA)
 
 static struct sk_buff *brcm_tag_xmit_ll(struct sk_buff *skb,
 					struct net_device *dev,
@@ -146,10 +150,11 @@ static struct sk_buff *brcm_tag_xmit_ll(struct sk_buff *skb,
  */
 static struct sk_buff *brcm_tag_rcv_ll(struct sk_buff *skb,
 				       struct net_device *dev,
-				       unsigned int offset)
+				       unsigned int offset, bool fa)
 {
 	int source_port;
 	const u8 *dest;
+	u8 opcode;
 	u8 *brcm_tag;
 
 	if (unlikely(!pskb_may_pull(skb, BRCM_TAG_LEN))) {
@@ -159,8 +164,12 @@ static struct sk_buff *brcm_tag_rcv_ll(struct sk_buff *skb,
 
 	brcm_tag = skb->data - offset;
 
-	/* The opcode should never be different than 0b000 */
-	if (unlikely((brcm_tag[0] >> BRCM_OPCODE_SHIFT) & BRCM_OPCODE_MASK)) {
+	/* Opcode 2 is a four-byte FA miss descriptor. Its middle bytes
+	 * contain the flow hash and parser status, not classification/reason.
+	 * Timestamp descriptors (opcode 1, eight bytes) are not supported.
+	 */
+	opcode = (brcm_tag[0] >> BRCM_OPCODE_SHIFT) & BRCM_OPCODE_MASK;
+	if (unlikely(opcode && !(fa && opcode == BRCM_FA_OPCODE_MISS))) {
 		kfree_skb(skb);
 		return NULL;
 	}
@@ -168,7 +177,7 @@ static struct sk_buff *brcm_tag_rcv_ll(struct sk_buff *skb,
 	/* We should never see a reserved reason code without knowing how to
 	 * handle it
 	 */
-	if (unlikely(brcm_tag[2] & BRCM_EG_RC_RSVD)) {
+	if (unlikely(!opcode && (brcm_tag[2] & BRCM_EG_RC_RSVD))) {
 		kfree_skb(skb);
 		return NULL;
 	}
@@ -210,7 +219,7 @@ static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev)
 	struct sk_buff *nskb;
 
 	/* skb->data points to the EtherType, the tag is right before it */
-	nskb = brcm_tag_rcv_ll(skb, dev, 2);
+	nskb = brcm_tag_rcv_ll(skb, dev, 2, false);
 	if (!nskb)
 		return nskb;
 
@@ -397,7 +406,7 @@ static struct sk_buff *brcm_tag_rcv_prepend(struct sk_buff *skb,
 					    struct net_device *dev)
 {
 	/* tag is prepended to the packet */
-	return brcm_tag_rcv_ll(skb, dev, ETH_HLEN);
+	return brcm_tag_rcv_ll(skb, dev, ETH_HLEN, false);
 }
 
 static const struct dsa_device_ops brcm_prepend_netdev_ops = {
@@ -412,7 +421,146 @@ DSA_TAG_DRIVER(brcm_prepend_netdev_ops);
 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_BRCM_PREPEND, BRCM_PREPEND_NAME);
 #endif
 
+#if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM_FA)
+static LIST_HEAD(brcm_fa_controls);
+static DEFINE_MUTEX(brcm_fa_control_lock);
+
+static LIST_HEAD(brcm_fa_switches);
+static DEFINE_MUTEX(brcm_fa_switch_lock);
+
+void brcm_fa_switch_register(struct brcm_fa_switch *sw)
+{
+	mutex_lock(&brcm_fa_switch_lock);
+	list_add(&sw->list, &brcm_fa_switches);
+	mutex_unlock(&brcm_fa_switch_lock);
+}
+EXPORT_SYMBOL_GPL(brcm_fa_switch_register);
+
+void brcm_fa_switch_unregister(struct brcm_fa_switch *sw)
+{
+	mutex_lock(&brcm_fa_switch_lock);
+	list_del(&sw->list);
+	mutex_unlock(&brcm_fa_switch_lock);
+}
+EXPORT_SYMBOL_GPL(brcm_fa_switch_unregister);
+
+int brcm_fa_bridge_guard(struct net_device *conduit, unsigned int slot,
+			 const u8 *addr, unsigned int port)
+{
+	struct brcm_fa_switch *sw;
+	int err = -ENODEV;
+
+	if (slot >= BRCM_FA_BRIDGE_GUARDS)
+		return -EINVAL;
+	/* Separate from the control lock: retiring the data path can release
+	 * guards while a control-state callback holds that lock.
+	 */
+	mutex_lock(&brcm_fa_switch_lock);
+	list_for_each_entry(sw, &brcm_fa_switches, list) {
+		if (sw->conduit != conduit)
+			continue;
+		err = sw->set_guard(sw->priv, slot, addr, port);
+		break;
+	}
+	mutex_unlock(&brcm_fa_switch_lock);
+	return err;
+}
+EXPORT_SYMBOL_GPL(brcm_fa_bridge_guard);
+
+void brcm_fa_control_register(struct brcm_fa_control *control)
+{
+	mutex_lock(&brcm_fa_control_lock);
+	list_add_rcu(&control->list, &brcm_fa_controls);
+	mutex_unlock(&brcm_fa_control_lock);
+}
+EXPORT_SYMBOL_GPL(brcm_fa_control_register);
+
+void brcm_fa_control_unregister(struct brcm_fa_control *control)
+{
+	mutex_lock(&brcm_fa_control_lock);
+	list_del_rcu(&control->list);
+	mutex_unlock(&brcm_fa_control_lock);
+	synchronize_net();
+}
+EXPORT_SYMBOL_GPL(brcm_fa_control_unregister);
+
+void brcm_fa_control_set_ready(struct net_device *conduit, bool ready)
+{
+	struct brcm_fa_control *control;
+
+	/* State callbacks can sleep while retiring hardware entries. */
+	mutex_lock(&brcm_fa_control_lock);
+	list_for_each_entry(control, &brcm_fa_controls, list)
+		if (control->conduit == conduit && control->state_change)
+			control->state_change(control->priv, ready);
+	mutex_unlock(&brcm_fa_control_lock);
+}
+EXPORT_SYMBOL_GPL(brcm_fa_control_set_ready);
+
+static struct sk_buff *brcm_fa_tag_xmit(struct sk_buff *skb,
+					struct net_device *dev)
+{
+	struct dsa_port *dp = dsa_user_to_port(dev);
+
+	return brcm_tag_xmit_ll(skb, dev, dp->cpu_dp->index == 5 ? 2 * ETH_ALEN : 0);
+}
+
+static struct sk_buff *brcm_fa_tag_rcv(struct sk_buff *skb, struct net_device *dev)
+{
+	struct dsa_port *cpu = dev->dsa_ptr;
+	struct brcm_fa_control *control;
+	struct dsa_port *data_cpu;
+	unsigned int port;
+	u8 reason;
+
+	if (cpu->index != 5)
+		return brcm_tag_rcv_ll(skb, dev, ETH_HLEN, true);
+	if (!pskb_may_pull(skb, BRCM_TAG_LEN))
+		goto drop;
+	reason = skb->data[0]; /* Embedded tag byte 2 after eth_type_trans(). */
+	port = skb->data[1] & BRCM_EG_PID_MASK;
+	skb = brcm_tag_rcv_ll(skb, dev, 2, false);
+	if (!skb)
+		return NULL;
+	dsa_strip_etype_header(skb, BRCM_TAG_LEN);
+	skb_set_mac_header(skb, -ETH_HLEN);
+	if (!(reason & BRCM_EG_RC_PROT_TERM))
+		return skb;
+	/* CFP replaced the complete forwarding map with the auxiliary CPU.
+	 * Linux must forward a bridged exception to wired ports as well.
+	 */
+	skb->offload_fwd_mark = 0;
+	data_cpu = dsa_to_port(cpu->ds, 8);
+	if (!data_cpu || !dsa_port_is_cpu(data_cpu))
+		return skb;
+	rcu_read_lock();
+	list_for_each_entry_rcu(control, &brcm_fa_controls, list)
+		if (control->conduit == data_cpu->conduit)
+			control->receive(control->priv, skb, port);
+	rcu_read_unlock();
+	return skb;
+drop:
+	kfree_skb(skb);
+	return NULL;
+}
+
+static const struct dsa_device_ops brcm_fa_netdev_ops = {
+	.name = BRCM_FA_NAME,
+	.proto = DSA_TAG_PROTO_BRCM_FA,
+	.xmit = brcm_fa_tag_xmit,
+	.rcv = brcm_fa_tag_rcv,
+	.needed_headroom = BRCM_TAG_LEN,
+	.promisc_on_conduit = true,
+};
+
+DSA_TAG_DRIVER(brcm_fa_netdev_ops);
+MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_BRCM_FA, BRCM_FA_NAME);
+#endif
+
 static struct dsa_tag_driver *dsa_tag_driver_array[] =	{
+#if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM_FA)
+	&DSA_TAG_DRIVER_NAME(brcm_fa_netdev_ops),
+#endif
 #if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM)
 	&DSA_TAG_DRIVER_NAME(brcm_netdev_ops),
 #endif

  parent reply	other threads:[~2026-12-01 18:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 18:22 [PATCH net-next v2 0/6] Add Northstar FA TCP/UDP NAT offload with a bridged LAN Florian Fainelli
2026-12-01 18:22 ` [PATCH net-next v2 1/6] dt-bindings: net: describe the Northstar flow accelerator Florian Fainelli
2026-12-01 18:22 ` Florian Fainelli [this message]
2026-12-01 18:22 ` [PATCH net-next v2 3/6] net: flow_offload: allow drivers to validate and invalidate cached paths Florian Fainelli
2026-12-01 18:22 ` [PATCH net-next v2 4/6] net: bgmac: add Northstar IPv4 TCP/UDP NAT flowtable offload Florian Fainelli
2026-12-01 18:22 ` [PATCH net-next v2 5/6] net: add KUnit coverage for FA and flowtable path validation Florian Fainelli
2026-12-01 18:22 ` [PATCH net-next v2 6/6] docs: net: document Northstar FA setup and NAT qualification Florian Fainelli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201182227.3990791-3-florian.fainelli@broadcom.com \
    --to=florian.fainelli@broadcom.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=jonas.gorski@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox