mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH RFC net-next 0/7] net: cortina: CS7542 wired IPv4 hardware flowtable offload
@ 2026-11-25 20:50 Fil Dunsky via B4 Relay
  2026-11-25 20:50 ` [PATCH RFC net-next 1/7] dt-bindings: net: dsa: allow the QCA four-byte tag protocol Fil Dunsky via B4 Relay
                   ` (7 more replies)
  0 siblings, 8 replies; 13+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-11-25 20:50 UTC (permalink / raw)
  To: Andrew Lunn, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Florian Fainelli, Simon Horman, Pablo Neira Ayuso,
	Florian Westphal, Phil Sutter, Hans Ulli Kroll, Linus Walleij,
	Andrew Lunn, Russell King, Christian Marangi, Jonathan Corbet,
	Shuah Khan, Randy Dunlap
  Cc: netdev, devicetree, linux-kernel, netfilter-devel, coreteam,
	linux-arm-kernel, linux-doc, Fil Dunsky

This RFC connects the CS7542 forwarding engine to nftables hardware
flowtables on Securifi Almond+. It is separate from the CPU Ethernet
bring-up series. The main questions are the flowtable context interface,
QCA four-byte CPU framing, and conservative hardware resource lifetime.

The Ethernet driver retains DMA, MMIO, table and reset ownership. A
loadable frontend translates ordinary flowtable requests; a replaceable
algorithm operates through bounded typed table hooks. The switch format
is selected with the existing dsa-tag-protocol property before ports are
opened. Laboratory marker/observer commands and timed tag switching have
been removed from this composition.

Hardware qualification of the OpenWrt 6.18.64 precursor:
- Separate physical LAN 1 and WAN with normal firewall4 NAT and the LuCI
  hardware-flow-offloading option. Server observed the router WAN address.
- UDP IP 512/1400/1500, DF set/clear, exact bidirectional data and TTL 63.
  Without offload CPU captured 72/72 marked packets; with offload 4/212.
- The four CPU packets are refresh pairs near 30 and 60 seconds. Sticky HIT
  bits do not prove a new lastused timestamp, so the driver conservatively
  lets Linux age and relearn a flow rather than inventing activity.
- TCP exchanged 2,293,760 verified bytes over 70 seconds. TCP/UDP conntrack
  showed HW_OFFLOAD at 3, 35 and 69 seconds. TCP stacks accepted the data;
  this is not an independent checksum capture of every TCP segment.
- Eight connections used 16 selectors sharing one immutable result. Removing
  one did not alter the seven remaining selectors or their forwarding.
These are correctness measurements at a controlled rate, not throughput
benchmarks. They were made on the precursor, not these exact Linux bytes.

Validation of this Linux composition:
- Full ARM zImage and modules build, COMPILE_TEST=n, no platform series.
- Seven real sk_buff KUnit tests passed under UML: tag/flow dissection,
  VLAN and checksum metadata, clones, port dispatch and nonlinear headers.
- Current table/algorithm and guard code passed 590,845 checks under each
  of GCC and Clang, with ASan/UBSan. Tests cover concurrent selectors,
  sharing, both removal orders, capacity, transient failures and permanent
  failure retention. This is software fault injection, not hardware proof.

Limits and review questions:
- Wired IPv4 TCP/UDP only; Wi-Fi, IPv6 and unsupported policies use CPU.
- There are 16 selectors and eight immutable results. Identical actions can
  share/rebind results; incompatible results exhaust this pool until a
  verified engine reset. General result reclamation is not implemented.
- HIT accounting can cause a brief CPU refresh on each Linux timeout.
  No hardware packet/byte counters are fabricated.
- Ethernet/QCA/MDIO remain built in; suspend and forced module removal are
  excluded. The development modules require checked detachment. Should
  this replaceable interface be consolidated into the Ethernet driver?
- Is directional route MTU plus established TCP context appropriate in
  flow_cls_offload, or should flowtable expose these differently?
- Is dsa-tag-protocol the right selection interface for this parser need?
- What hardware drain evidence is needed before safely replacing different
  result records or clearing the sticky HIT bitmap?

Prerequisites, applied in this order on Linux 7.4-rc4:
- Global controls v4:
https://lore.kernel.org/all/20261125-cs7542-syscon-v4-0-3337bb0d3b48@gmail.com/
- Ethernet v2:
https://lore.kernel.org/all/20261125-b4-cs7542-ethernet-v2-0-d0ea3c6eb375@gmail.com/
- MDIO v2:
https://lore.kernel.org/all/20261123-b4-cs7542-mdio-v2-0-30465e831853@gmail.com/

The platform/DTS series is not needed for compilation. A bootable Almond+
configuration additionally needs that board support and qca4 on both CPU
ports. This RFC does not reroll or replace any prerequisite series.

Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com>
---
Fil Dunsky (7):
      dt-bindings: net: dsa: allow the QCA four-byte tag protocol
      net: dsa: add a QCA four-byte CPU tagger
      netfilter: flowtable: expose route MTU and established TCP context
      net: cortina: add a serialized CS7542 forwarding engine owner
      net: dsa: qca8k: select the four-byte format before port activation
      net: cortina: connect wired IPv4 NAT to nftables hardware flowtables
      docs: networking: describe the CS7542 flowtable RFC limits

 .../devicetree/bindings/net/dsa/dsa-port.yaml      |   1 +
 .../ethernet/cortina/cs7542-flowtable.rst          | 112 +++
 MAINTAINERS                                        |   5 +
 drivers/net/dsa/qca/persistent_qca4.h              | 178 ++++
 drivers/net/dsa/qca/persistent_qca4_mtu.h          | 165 ++++
 drivers/net/dsa/qca/qca8k-8xxx.c                   | 123 ++-
 drivers/net/dsa/qca/qca8k-common.c                 |  42 +-
 drivers/net/dsa/qca/qca8k-persistent-boot.inc      | 632 +++++++++++++
 drivers/net/dsa/qca/qca8k-persistent-lifecycle.inc | 394 +++++++++
 drivers/net/dsa/qca/qca8k.h                        |  40 +
 drivers/net/ethernet/cortina/Kconfig               |  64 ++
 drivers/net/ethernet/cortina/Makefile              |  14 +-
 drivers/net/ethernet/cortina/cs752x_ne.c           | 120 +++
 drivers/net/ethernet/cortina/cs7542_fe_live.c      | 735 ++++++++++++++++
 drivers/net/ethernet/cortina/cs7542_ft_live.c      | 415 +++++++++
 drivers/net/ethernet/cortina/cs_fe_acl_encode.c    | 124 +++
 drivers/net/ethernet/cortina/cs_fe_acl_guard.c     | 324 +++++++
 drivers/net/ethernet/cortina/cs_fe_acl_guard.h     |  47 +
 drivers/net/ethernet/cortina/cs_fe_backend.h       | 228 +++++
 .../net/ethernet/cortina/cs_fe_backend_algorithm.c | 976 +++++++++++++++++++++
 .../net/ethernet/cortina/cs_fe_backend_dispatch.c  | 433 +++++++++
 .../net/ethernet/cortina/cs_fe_backend_module.c    | 164 ++++
 drivers/net/ethernet/cortina/cs_fe_encode.c        | 562 ++++++++++++
 drivers/net/ethernet/cortina/cs_fe_encode.h        |   5 +
 drivers/net/ethernet/cortina/cs_fe_fields.h        | 339 +++++++
 drivers/net/ethernet/cortina/cs_fe_format.h        |  23 +
 drivers/net/ethernet/cortina/cs_fe_hot.c           |  84 ++
 drivers/net/ethernet/cortina/cs_fe_hot.h           |  15 +
 drivers/net/ethernet/cortina/cs_fe_hot_access.c    | 276 ++++++
 drivers/net/ethernet/cortina/cs_fe_hot_access.h    |  55 ++
 drivers/net/ethernet/cortina/cs_fe_hot_codec.c     |   2 +
 drivers/net/ethernet/cortina/cs_fe_hot_compare.h   |  47 +
 drivers/net/ethernet/cortina/cs_fe_hot_internal.h  |  44 +
 drivers/net/ethernet/cortina/cs_fe_hot_lineage.c   | 138 +++
 drivers/net/ethernet/cortina/cs_fe_hot_lineage.h   |  70 ++
 drivers/net/ethernet/cortina/cs_fe_hot_tables.c    | 920 +++++++++++++++++++
 drivers/net/ethernet/cortina/cs_fe_native.inc      | 668 ++++++++++++++
 .../net/ethernet/cortina/cs_fe_native_activity.inc | 237 +++++
 drivers/net/ethernet/cortina/cs_fe_native_mtu.h    |  43 +
 drivers/net/ethernet/cortina/cs_fe_native_mtu.inc  | 128 +++
 drivers/net/ethernet/cortina/cs_fe_native_state.h  |  24 +
 drivers/net/ethernet/cortina/flowtable/Makefile    |   2 +
 .../cortina/flowtable/codec/cs_ft_rewrite.c        | 234 +++++
 .../cortina/flowtable/codec/cs_ft_rewrite.h        |  42 +
 .../net/ethernet/cortina/flowtable/cs7542_fw4.c    | 437 +++++++++
 .../ethernet/cortina/flowtable/cs7542_rx_path.c    | 225 +++++
 .../ethernet/cortina/flowtable/cs7542_rx_path.h    |  35 +
 drivers/net/ethernet/cortina/flowtable/nf_native.c |  90 ++
 drivers/net/ethernet/cortina/flowtable/nf_native.h |  31 +
 include/linux/cs7542_fe_backend.h                  |  65 ++
 include/linux/cs7542_fe_codec.h                    | 145 +++
 include/linux/cs7542_fe_live.h                     |  58 ++
 include/linux/cs7542_fe_native.h                   |  34 +
 include/linux/cs7542_ft_live.h                     |  70 ++
 include/linux/dsa/qca8k_persistent.h               |  45 +
 include/net/dsa.h                                  |  21 +-
 include/net/flow_offload.h                         |   5 +
 net/dsa/Kconfig                                    |  30 +
 net/dsa/Makefile                                   |   2 +
 net/dsa/tag_qca4.c                                 | 165 ++++
 net/dsa/tag_qca4_kunit.h                           | 469 ++++++++++
 net/netfilter/nf_flow_table_offload.c              |  25 +-
 62 files changed, 11218 insertions(+), 28 deletions(-)
---
base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
change-id: 20261125-almondplus-offload-rfc-149cfb29ade9
prerequisite-message-id: <20261125-cs7542-syscon-v4-0-3337bb0d3b48@gmail.com>
prerequisite-patch-id: a9208276c628f8741a807d0e5c5945d4bf211c8a
prerequisite-patch-id: 65d46bb3caaa8518ee561f65d3f603ade396fff9
prerequisite-patch-id: a0ed5fbcfa308b16eaf265371a6697ad0aea6802
prerequisite-patch-id: bb8ffd99cb30e5a0b47881f6ba19a36329d5f4f2
prerequisite-patch-id: 7fbe9405265ef3d1ec62811415a46c0061afd7c8
prerequisite-patch-id: 01ece2c91e080d5cae6af81944159373776484ca
prerequisite-message-id: <20261125-b4-cs7542-ethernet-v2-0-d0ea3c6eb375@gmail.com>
prerequisite-patch-id: aecabdb905864eca2f0634c4d08c78194d3ceffc
prerequisite-patch-id: 14f8d8de3d9bff0276c1f0a54e3f42727d40d41a
prerequisite-patch-id: f42fb7a3c96e1ea44a7cf4495929acb9fdc47349
prerequisite-message-id: <20261123-b4-cs7542-mdio-v2-0-30465e831853@gmail.com>
prerequisite-patch-id: 3656dbe3324c7bb9ec757a4c13c990cd28ec3d2a
prerequisite-patch-id: 268165424b18f66611028ebbea04dbb43cd4a7c5
prerequisite-patch-id: 33fc64ae4aa932467903052b4f27bce0f8b5e7c7

Best regards,
--  
Fil Dunsky <filipp.dunsky@gmail.com>



^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH RFC net-next 1/7] dt-bindings: net: dsa: allow the QCA four-byte tag protocol
  2026-11-25 20:50 [PATCH RFC net-next 0/7] net: cortina: CS7542 wired IPv4 hardware flowtable offload Fil Dunsky via B4 Relay
@ 2026-11-25 20:50 ` Fil Dunsky via B4 Relay
  2026-11-25 20:50 ` [PATCH RFC net-next 2/7] net: dsa: add a QCA four-byte CPU tagger Fil Dunsky via B4 Relay
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-11-25 20:50 UTC (permalink / raw)
  To: Andrew Lunn, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Florian Fainelli, Simon Horman, Pablo Neira Ayuso,
	Florian Westphal, Phil Sutter, Hans Ulli Kroll, Linus Walleij,
	Andrew Lunn, Russell King, Christian Marangi, Jonathan Corbet,
	Shuah Khan, Randy Dunlap
  Cc: netdev, devicetree, linux-kernel, netfilter-devel, coreteam,
	linux-arm-kernel, linux-doc, Fil Dunsky

From: Fil Dunsky <filipp.dunsky@gmail.com>

The CS7542 parser needs an EtherType identifier ahead of the QCA
metadata. Allow CPU ports to select that format through the existing DSA
property.

Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com>
---
 Documentation/devicetree/bindings/net/dsa/dsa-port.yaml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/net/dsa/dsa-port.yaml b/Documentation/devicetree/bindings/net/dsa/dsa-port.yaml
index 480120469..30c6f70c9 100644
--- a/Documentation/devicetree/bindings/net/dsa/dsa-port.yaml
+++ b/Documentation/devicetree/bindings/net/dsa/dsa-port.yaml
@@ -53,6 +53,7 @@ properties:
     enum:
       - dsa
       - edsa
+      - qca4
       - ocelot
       - ocelot-8021q
       - rtl8_4

-- 
2.53.0



^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH RFC net-next 2/7] net: dsa: add a QCA four-byte CPU tagger
  2026-11-25 20:50 [PATCH RFC net-next 0/7] net: cortina: CS7542 wired IPv4 hardware flowtable offload Fil Dunsky via B4 Relay
  2026-11-25 20:50 ` [PATCH RFC net-next 1/7] dt-bindings: net: dsa: allow the QCA four-byte tag protocol Fil Dunsky via B4 Relay
@ 2026-11-25 20:50 ` Fil Dunsky via B4 Relay
  2026-11-25 21:15   ` Andrew Lunn
  2026-11-25 20:50 ` [PATCH RFC net-next 3/7] netfilter: flowtable: expose route MTU and established TCP context Fil Dunsky via B4 Relay
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 13+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-11-25 20:50 UTC (permalink / raw)
  To: Andrew Lunn, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Florian Fainelli, Simon Horman, Pablo Neira Ayuso,
	Florian Westphal, Phil Sutter, Hans Ulli Kroll, Linus Walleij,
	Andrew Lunn, Russell King, Christian Marangi, Jonathan Corbet,
	Shuah Khan, Randy Dunlap
  Cc: netdev, devicetree, linux-kernel, netfilter-devel, coreteam,
	linux-arm-kernel, linux-doc, Fil Dunsky

From: Fil Dunsky <filipp.dunsky@gmail.com>

Insert the 0x8100 identifier and the ordinary QCA metadata ahead of the
inner EtherType. Preserve checksum/header offsets, materialize VLAN
metadata inside the CPU tag and validate nonlinear receive headers
before dispatch.

Keep the two-byte format as the default. Add KUnit coverage for tagging,
VLAN and checksum metadata, source-port dispatch, clones and
truncated/nonlinear packets. Seven tests passed under UML.

Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com>
---
 include/net/dsa.h        |  21 +--
 net/dsa/Kconfig          |  30 +++
 net/dsa/Makefile         |   2 +
 net/dsa/tag_qca4.c       | 165 +++++++++++++++++
 net/dsa/tag_qca4_kunit.h | 469 +++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 671 insertions(+), 16 deletions(-)

diff --git a/include/net/dsa.h b/include/net/dsa.h
index 5d12191b6..7d3c836c2 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -36,6 +36,7 @@ struct tc_action;
 #define DSA_TAG_PROTO_LAN9303_VALUE		8
 #define DSA_TAG_PROTO_MTK_VALUE			9
 #define DSA_TAG_PROTO_QCA_VALUE			10
+#define DSA_TAG_PROTO_QCA4_VALUE 37
 #define DSA_TAG_PROTO_TRAILER_VALUE		11
 #define DSA_TAG_PROTO_8021Q_VALUE		12
 #define DSA_TAG_PROTO_SJA1105_VALUE		13
@@ -77,6 +78,7 @@ enum dsa_tag_protocol {
 	DSA_TAG_PROTO_LAN9303		= DSA_TAG_PROTO_LAN9303_VALUE,
 	DSA_TAG_PROTO_MTK		= DSA_TAG_PROTO_MTK_VALUE,
 	DSA_TAG_PROTO_QCA		= DSA_TAG_PROTO_QCA_VALUE,
+	DSA_TAG_PROTO_QCA4		= DSA_TAG_PROTO_QCA4_VALUE,
 	DSA_TAG_PROTO_TRAILER		= DSA_TAG_PROTO_TRAILER_VALUE,
 	DSA_TAG_PROTO_8021Q		= DSA_TAG_PROTO_8021Q_VALUE,
 	DSA_TAG_PROTO_SJA1105		= DSA_TAG_PROTO_SJA1105_VALUE,
@@ -183,15 +185,12 @@ struct dsa_switch_tree {
 #define dsa_lags_foreach_id(_id, _dst)				\
 	for ((_id) = 1; (_id) <= (_dst)->lags_len; (_id)++)	\
 		if ((_dst)->lags[(_id) - 1])
-
 #define dsa_lag_foreach_port(_dp, _dst, _lag)			\
 	list_for_each_entry((_dp), &(_dst)->ports, list)	\
 		if (dsa_port_offloads_lag((_dp), (_lag)))
-
 #define dsa_hsr_foreach_port(_dp, _ds, _hsr)			\
 	list_for_each_entry((_dp), &(_ds)->dst->ports, list)	\
 		if ((_dp)->ds == (_ds) && (_dp)->hsr_dev == (_hsr))
-
 static inline struct dsa_lag *dsa_lag_by_id(struct dsa_switch_tree *dst,
 					    unsigned int id)
 {
@@ -579,47 +578,36 @@ static inline bool dsa_is_user_port(struct dsa_switch *ds, int p)
 #define dsa_tree_for_each_user_port(_dp, _dst) \
 	list_for_each_entry((_dp), &(_dst)->ports, list) \
 		if (dsa_port_is_user((_dp)))
-
 #define dsa_tree_for_each_user_port_continue_reverse(_dp, _dst) \
 	list_for_each_entry_continue_reverse((_dp), &(_dst)->ports, list) \
 		if (dsa_port_is_user((_dp)))
-
 #define dsa_tree_for_each_cpu_port(_dp, _dst) \
 	list_for_each_entry((_dp), &(_dst)->ports, list) \
 		if (dsa_port_is_cpu((_dp)))
-
 #define dsa_switch_for_each_port(_dp, _ds) \
 	list_for_each_entry((_dp), &(_ds)->dst->ports, list) \
 		if ((_dp)->ds == (_ds))
-
 #define dsa_switch_for_each_port_safe(_dp, _next, _ds) \
 	list_for_each_entry_safe((_dp), (_next), &(_ds)->dst->ports, list) \
 		if ((_dp)->ds == (_ds))
-
 #define dsa_switch_for_each_port_continue_reverse(_dp, _ds) \
 	list_for_each_entry_continue_reverse((_dp), &(_ds)->dst->ports, list) \
 		if ((_dp)->ds == (_ds))
-
 #define dsa_switch_for_each_available_port(_dp, _ds) \
 	dsa_switch_for_each_port((_dp), (_ds)) \
 		if (!dsa_port_is_unused((_dp)))
-
 #define dsa_switch_for_each_user_port(_dp, _ds) \
 	dsa_switch_for_each_port((_dp), (_ds)) \
 		if (dsa_port_is_user((_dp)))
-
 #define dsa_switch_for_each_user_port_continue_reverse(_dp, _ds) \
 	dsa_switch_for_each_port_continue_reverse((_dp), (_ds)) \
 		if (dsa_port_is_user((_dp)))
-
 #define dsa_switch_for_each_cpu_port(_dp, _ds) \
 	dsa_switch_for_each_port((_dp), (_ds)) \
 		if (dsa_port_is_cpu((_dp)))
-
 #define dsa_switch_for_each_cpu_port_continue_reverse(_dp, _ds) \
 	dsa_switch_for_each_port_continue_reverse((_dp), (_ds)) \
 		if (dsa_port_is_cpu((_dp)))
-
 static inline u32 dsa_user_ports(struct dsa_switch *ds)
 {
 	struct dsa_port *dp;
@@ -842,7 +830,6 @@ dsa_tree_offloads_bridge_dev(struct dsa_switch_tree *dst,
 #define dsa_switch_for_each_bridge_member(_dp, _ds, _bdev) \
 	dsa_switch_for_each_user_port(_dp, _ds) \
 		if (dsa_port_offloads_bridge_dev(_dp, _bdev))
-
 static inline u32
 dsa_bridge_ports(struct dsa_switch *ds, const struct net_device *bdev)
 {
@@ -996,7 +983,6 @@ struct dsa_switch_ops {
 			       struct phy_device *phy);
 	void	(*port_disable)(struct dsa_switch *ds, int port);
 
-
 	/*
 	 * Notification for MAC address changes on user ports. Drivers can
 	 * currently only veto operations. They should not use the method to
@@ -1401,10 +1387,12 @@ static inline int dsa_switch_suspend(struct dsa_switch *ds)
 {
 	return 0;
 }
+
 static inline int dsa_switch_resume(struct dsa_switch *ds)
 {
 	return 0;
 }
+
 #endif /* CONFIG_PM_SLEEP */
 
 #if IS_ENABLED(CONFIG_NET_DSA)
@@ -1414,6 +1402,7 @@ static inline bool dsa_user_dev_check(const struct net_device *dev)
 {
 	return false;
 }
+
 #endif
 
 netdev_tx_t dsa_enqueue_skb(struct sk_buff *skb, struct net_device *dev);
diff --git a/net/dsa/Kconfig b/net/dsa/Kconfig
index 4f44bf3ed..99933b270 100644
--- a/net/dsa/Kconfig
+++ b/net/dsa/Kconfig
@@ -174,6 +174,36 @@ config NET_DSA_TAG_QCA
 	  Say Y or M if you want to enable support for tagging frames for
 	  the Qualcomm Atheros QCA8K switches.
 
+config NET_DSA_TAG_QCA4
+	tristate "Tag driver for QCA four-byte tags"
+	default n
+	help
+	  QCA switch CPU framing with identifier 0x8100 and two-byte metadata.
+	  Does not enable hardware checksum, GSO, VLAN or NAT offload features.
+	  The ordinary QCA two-byte tagger remains the default.
+	  Select qca4 on the CPU ports only when the switch driver supports it.
+
+config NET_DSA_TAG_QCA4_KUNIT_TEST
+	bool "KUnit tests for QCA four-byte sk_buff operations"
+	depends on KUNIT=y && NET_DSA_TAG_QCA4=y
+	default n
+	help
+	  Exercise real sk_buff allocation, copy-on-write, nonlinear headers,
+	  checksum metadata and source-port dispatch for the four-byte tagger.
+	  These are software tests and do not require a physical QCA switch.
+	  They can run with the standard KUnit test framework.
+
+config NET_DSA_QCA8K_4B_MODE
+	bool "QCA8K four-byte boot format for CS7542 offload"
+	depends on NET_DSA_QCA8K=y && NET_DSA_TAG_QCA4=y
+	depends on !PM && CS7542_FT_LIVE_BRIDGE && MDIO_CS75XX=y
+	default n
+	help
+	  Support the four-byte CPU tag requested through dsa-tag-protocol.
+	  The current implementation supports the CS7542 dual-conduit topology.
+	  Ethernet register access uses MDIO while the four-byte format is active.
+	  Both CPU ports must request the same format before the switch starts.
+
 config NET_DSA_TAG_RTL4_A
 	tristate "Tag driver for Realtek 4 byte protocol A tags"
 	help
diff --git a/net/dsa/Makefile b/net/dsa/Makefile
index 1f9cc30e9..3d5949e50 100644
--- a/net/dsa/Makefile
+++ b/net/dsa/Makefile
@@ -48,3 +48,5 @@ obj-$(CONFIG_NET_DSA_TAG_YT921X) += tag_yt921x.o
 
 # for tracing framework to find trace.h
 CFLAGS_trace.o := -I$(src)
+
+obj-$(CONFIG_NET_DSA_TAG_QCA4) += tag_qca4.o
diff --git a/net/dsa/tag_qca4.c b/net/dsa/tag_qca4.c
new file mode 100644
index 000000000..413756679
--- /dev/null
+++ b/net/dsa/tag_qca4.c
@@ -0,0 +1,165 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Private source-review prototype. No offload feature advertisement. */
+#include <linux/bitfield.h>
+#include <linux/etherdevice.h>
+#include <linux/if_vlan.h>
+#include <linux/unaligned.h>
+#include <linux/dsa/tag_qca.h>
+#include <net/dsa.h>
+#include "tag.h"
+
+#define QCA4_PRIVATE_LEN 4
+#define QCA4_PRIVATE_IDENTIFIER 0x8100
+#define QCA4_PRIVATE_NAME "qca4"
+
+/*
+ * Offsets are absolute from skb head. Pushing the outer tag leaves the real
+ * L3/L4 and CHECKSUM_PARTIAL start at their original bytes; their offsets from
+ * skb->data grow by four. Standard core/conduit features own segmentation and
+ * software checksum fallback. GSO/checksum metadata is not rejected or changed.
+ */
+static int qca4_private_insert(struct sk_buff *skb, unsigned long ports)
+{
+	u16 hdr;
+	u8 *tag;
+
+	if (!ports || ports & ~FIELD_MAX(QCA_HDR_XMIT_DP_BIT))
+		return -EINVAL;
+	if (!pskb_may_pull(skb, ETH_HLEN))
+		return -EINVAL;
+	if (skb_cow_head(skb, QCA4_PRIVATE_LEN))
+		return -ENOMEM;
+	skb_push(skb, QCA4_PRIVATE_LEN);
+	dsa_alloc_etype_header(skb, QCA4_PRIVATE_LEN);
+	tag = dsa_etype_header_pos_tx(skb);
+	hdr = FIELD_PREP(QCA_HDR_XMIT_VERSION, QCA_HDR_VERSION) |
+	      QCA_HDR_XMIT_FROM_CPU | FIELD_PREP(QCA_HDR_XMIT_DP_BIT, ports);
+	/* Same metadata policy as legacy QCA: no new skb-priority mapping. */
+	put_unaligned_be16(QCA4_PRIVATE_IDENTIFIER, tag);
+	put_unaligned_be16(hdr, tag + 2);
+	skb_reset_mac_header(skb);
+	return 0;
+}
+
+static struct sk_buff *qca4_private_xmit(struct sk_buff *skb,
+					 struct net_device *dev)
+{
+	/*
+	 * A pending hardware VLAN tag must be inside QCA metadata, never inserted
+	 * outside it later by the conduit. This standard helper also handles COW and
+	 * header/checksum offsets. No HW VLAN feature is advertised by this tagger.
+	 */
+
+	if (skb_vlan_tag_present(skb)) {
+		skb = __vlan_hwaccel_push_inside(skb);
+		if (!skb)
+			return NULL; /* VLAN helper already freed the original. */
+	}
+	if (qca4_private_insert(skb, dsa_xmit_port_mask(skb, dev))) {
+		kfree_skb(skb);
+		return NULL;
+	}
+
+	return skb;
+}
+
+/*
+ * Conduit eth_type_trans pulled fourteen bytes: identifier is data[-2],
+ * metadata is data[0..1], and inner EtherType is data[2..3]. Do not read a
+ * possibly nonlinear metadata/inner EtherType before the full pull check.
+ */
+static int qca4_private_parse(struct sk_buff *skb, u16 *metadata)
+{
+	unsigned int reason;
+	u8 *tag;
+	u16 hdr;
+
+	if (skb_headroom(skb) < ETH_HLEN ||
+	    !pskb_may_pull(skb, QCA4_PRIVATE_LEN)) {
+		return -EINVAL;
+	}
+	if (skb_cow_head(skb, 0))
+		return -ENOMEM;
+	tag = dsa_etype_header_pos_rx(skb);
+	if (get_unaligned_be16(tag) != QCA4_PRIVATE_IDENTIFIER)
+		return -EPROTO;
+	hdr = get_unaligned_be16(tag + 2);
+	if (FIELD_GET(QCA_HDR_RECV_VERSION, hdr) != QCA_HDR_VERSION)
+		return -EPROTO;
+	reason = FIELD_GET(QCA_HDR_RECV_TYPE, hdr);
+	/*
+	 * These fixed14-byte pseudo-Ethernet formats are disabled in private4 mode.
+	 * Never dispatch them into legacy MDIO/MIB callbacks with the wrong layout.
+	 * Other normal/trap reasons remain valid, including observed flooding0x19.
+	 */
+	if (reason == QCA_HDR_RECV_TYPE_MIB ||
+	    reason == QCA_HDR_RECV_TYPE_RW_REG_ACK) {
+		return -EOPNOTSUPP;
+	}
+	*metadata = hdr;
+	return 0;
+}
+
+static struct sk_buff *qca4_private_rcv(struct sk_buff *skb,
+					struct net_device *conduit)
+{
+	struct net_device *user;
+	u16 metadata;
+	int port;
+
+	if (qca4_private_parse(skb, &metadata))
+		goto drop;
+	port = FIELD_GET(QCA_HDR_RECV_SOURCE_PORT, metadata);
+	user = dsa_conduit_find_user(conduit, 0, port);
+	if (!user)
+		goto drop;
+
+	skb->dev = user;
+	skb_pull_rcsum(skb, QCA4_PRIVATE_LEN);
+	dsa_strip_etype_header(skb, QCA4_PRIVATE_LEN);
+
+	/*
+	 * DSA core pushes ETH_HLEN and invokes user eth_type_trans, exposing only
+	 * the real inner EtherType/VLAN after the complete four-byte tag is gone.
+	 */
+	return skb;
+drop:
+	kfree_skb(skb);
+	return NULL;
+}
+
+/*
+ * Called before rcv(): do not assume the metadata or inner EtherType is
+ * linear or even present. Keep the const skb and its layout unchanged.
+ */
+static void qca4_private_flow_dissect(const struct sk_buff *skb, __be16 *proto,
+				      int *offset)
+{
+	__be16 temporary;
+	const void *inner;
+
+	*offset = QCA4_PRIVATE_LEN;
+	*proto = 0;
+	inner = skb_header_pointer(skb, 2, sizeof(temporary), &temporary);
+	if (inner)
+		*proto = get_unaligned((const __be16 *)inner);
+}
+
+static const struct dsa_device_ops qca4_private_ops = {
+	.name = QCA4_PRIVATE_NAME,
+	.proto = DSA_TAG_PROTO_QCA4,
+	.xmit = qca4_private_xmit,
+	.rcv = qca4_private_rcv,
+	.flow_dissect = qca4_private_flow_dissect,
+	.needed_headroom = QCA4_PRIVATE_LEN,
+	.promisc_on_conduit = true,
+};
+
+MODULE_DESCRIPTION("Private source-review QCA four-byte tag prototype");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_QCA4, QCA4_PRIVATE_NAME);
+module_dsa_tag_driver(qca4_private_ops);
+
+#if IS_ENABLED(CONFIG_NET_DSA_TAG_QCA4_KUNIT_TEST)
+#include "tag_qca4_kunit.h"
+#endif
diff --git a/net/dsa/tag_qca4_kunit.h b/net/dsa/tag_qca4_kunit.h
new file mode 100644
index 000000000..cc520b7fb
--- /dev/null
+++ b/net/dsa/tag_qca4_kunit.h
@@ -0,0 +1,469 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Real kernel sk_buff tests; offline QEMU execution only. */
+#include <kunit/test.h>
+#include <linux/highmem.h>
+#include <linux/mm.h>
+#include <net/checksum.h>
+
+struct qca4_test_context {
+	struct dsa_switch ds;
+	struct dsa_switch_tree dst;
+	struct dsa_port cpu, user;
+	struct net_device *conduit, *netdev;
+};
+
+static int qca4_test_init(struct kunit *test)
+{
+	struct qca4_test_context *c =
+		kunit_kzalloc(test, sizeof(*c), GFP_KERNEL);
+	struct dsa_user_priv *p;
+
+	if (!c)
+		return -ENOMEM;
+	c->conduit = alloc_etherdev(0);
+	c->netdev = alloc_etherdev(sizeof(*p));
+	if (!c->conduit || !c->netdev) {
+		if (c->conduit)
+			free_netdev(c->conduit);
+		if (c->netdev)
+			free_netdev(c->netdev);
+		return -ENOMEM;
+	}
+	INIT_LIST_HEAD(&c->dst.ports);
+	c->ds.index = 0;
+	c->ds.dst = &c->dst;
+	c->cpu.ds = &c->ds;
+	c->cpu.dst = &c->dst;
+	c->cpu.type = DSA_PORT_TYPE_CPU;
+	c->cpu.index = 0;
+	c->cpu.conduit = c->conduit;
+	c->cpu.rcv = qca4_private_rcv;
+	c->cpu.tag_ops = &qca4_private_ops;
+	c->conduit->dsa_ptr = &c->cpu;
+	c->user.ds = &c->ds;
+	c->user.dst = &c->dst;
+	c->user.type = DSA_PORT_TYPE_USER;
+	c->user.index = 5;
+	c->user.user = c->netdev;
+	c->user.cpu_dp = &c->cpu;
+	list_add_tail(&c->cpu.list, &c->dst.ports);
+	list_add_tail(&c->user.list, &c->dst.ports);
+	p = netdev_priv(c->netdev);
+	p->dp = &c->user;
+	test->priv = c;
+	return 0;
+}
+
+static void qca4_test_exit(struct kunit *test)
+{
+	struct qca4_test_context *c = test->priv;
+
+	free_netdev(c->netdev);
+	free_netdev(c->conduit);
+}
+
+static struct sk_buff *qca4_test_frame(unsigned int headroom,
+				       unsigned int vlans)
+{
+	struct sk_buff *skb = alloc_skb(headroom + 128, GFP_KERNEL);
+	unsigned int len = 96 + 4 * vlans, network = ETH_HLEN + 4 * vlans;
+	u8 *data;
+
+	if (!skb)
+		return NULL;
+	skb_reserve(skb, headroom);
+	data = skb_put_zero(skb, len);
+	eth_broadcast_addr(data);
+	data[6] = 2;
+	data[11] = 1;
+	put_unaligned_be16(vlans == 2 ? ETH_P_8021AD :
+			   vlans == 1 ? ETH_P_8021Q :
+					ETH_P_IP,
+			   data + 12);
+	if (vlans) {
+		put_unaligned_be16(0xa123, data + 14);
+		put_unaligned_be16(vlans == 2 ? ETH_P_8021Q : ETH_P_IP,
+				   data + 16);
+	}
+	if (vlans == 2) {
+		put_unaligned_be16(0x6000, data + 18); /* Priority tag, VID0. */
+		put_unaligned_be16(ETH_P_IP, data + 20);
+	}
+	data[network] = 0x45;
+	data[network + 9] = IPPROTO_TCP;
+	skb_reset_mac_header(skb);
+	skb_set_network_header(skb, network);
+	skb_set_transport_header(skb, network + 20);
+	skb->protocol = htons(vlans == 2 ? ETH_P_8021AD :
+			      vlans == 1 ? ETH_P_8021Q :
+					   ETH_P_IP);
+	return skb;
+}
+
+static void qca4_test_tx_metadata(struct kunit *test)
+{
+	struct qca4_test_context *c = test->priv;
+	unsigned int vlans, n;
+	static const unsigned int reserves[] = { 0, 2, 16, 32 };
+
+	for (vlans = 0; vlans <= 2; vlans++) {
+		for (n = 0; n < ARRAY_SIZE(reserves); n++) {
+			struct sk_buff *skb = qca4_test_frame(reserves[n],
+							      vlans),
+				       *original;
+			unsigned int net, trans, start, len;
+			u8 bytes[128];
+
+			KUNIT_ASSERT_NOT_NULL(test, skb);
+			skb->ip_summed = CHECKSUM_PARTIAL;
+			skb->csum_start = skb_transport_header(skb) - skb->head;
+			skb->csum_offset = 16;
+			skb->priority = 7;
+			skb_shinfo(skb)->gso_size = 1460;
+			skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
+			net = skb_network_offset(skb);
+			trans = skb_transport_offset(skb);
+			start = skb_checksum_start_offset(skb);
+			len = skb->len;
+			memcpy(bytes, skb->data, len);
+			original = skb_clone(skb, GFP_KERNEL);
+			KUNIT_ASSERT_NOT_NULL(test, original);
+			skb = qca4_private_xmit(skb, c->netdev);
+			KUNIT_ASSERT_NOT_NULL(test, skb);
+			KUNIT_EXPECT_EQ(test, skb->len, len + 4);
+			KUNIT_EXPECT_EQ(test, skb_network_offset(skb), net + 4);
+			KUNIT_EXPECT_EQ(test, skb_transport_offset(skb),
+					trans + 4);
+			KUNIT_EXPECT_EQ(test, skb_checksum_start_offset(skb),
+					start + 4);
+			KUNIT_EXPECT_EQ(test, skb->csum_offset, (u16)16);
+			KUNIT_EXPECT_EQ(test, (unsigned int)skb->ip_summed,
+					(unsigned int)CHECKSUM_PARTIAL);
+			KUNIT_EXPECT_EQ(test, skb->priority, 7U);
+			KUNIT_EXPECT_EQ(test, skb_shinfo(skb)->gso_size,
+					(u16)1460);
+			KUNIT_EXPECT_EQ(test, skb_shinfo(skb)->gso_type,
+					SKB_GSO_TCPV4);
+			KUNIT_EXPECT_PTR_EQ(test, skb_mac_header(skb),
+					    skb->data);
+			KUNIT_EXPECT_MEMEQ(test, skb->data, bytes, 12);
+			KUNIT_EXPECT_MEMEQ(test, skb->data + 16, bytes + 12,
+					   len - 12);
+			KUNIT_EXPECT_MEMEQ(test, original->data, bytes, len);
+			KUNIT_EXPECT_EQ(test,
+					get_unaligned_be16(skb->data + 12),
+					0x8100);
+			KUNIT_EXPECT_EQ(test,
+					get_unaligned_be16(skb->data + 14),
+					0x80a0);
+			kfree_skb(original);
+			kfree_skb(skb);
+		}
+	}
+}
+
+static void qca4_test_vlan_metadata(struct kunit *test)
+{
+	struct qca4_test_context *c = test->priv;
+	struct sk_buff *skb = qca4_test_frame(0, 0);
+	unsigned int net, trans, start;
+
+	KUNIT_ASSERT_NOT_NULL(test, skb);
+	skb->ip_summed = CHECKSUM_PARTIAL;
+	skb->csum_start = skb_transport_header(skb) - skb->head;
+	skb->csum_offset = 16;
+	skb_shinfo(skb)->gso_size = 1460;
+	skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
+	net = skb_network_offset(skb);
+	trans = skb_transport_offset(skb);
+	start = skb_checksum_start_offset(skb);
+	__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
+			       0xe000); /* PCP7, VID0 */
+	skb = qca4_private_xmit(skb, c->netdev);
+	KUNIT_ASSERT_NOT_NULL(test, skb);
+	KUNIT_EXPECT_FALSE(test, skb_vlan_tag_present(skb));
+	KUNIT_EXPECT_EQ(test, skb_network_offset(skb), net + 8);
+	KUNIT_EXPECT_EQ(test, skb_transport_offset(skb), trans + 8);
+	KUNIT_EXPECT_EQ(test, skb_checksum_start_offset(skb), start + 8);
+	KUNIT_EXPECT_EQ(test, (unsigned int)skb->ip_summed,
+			(unsigned int)CHECKSUM_PARTIAL);
+	KUNIT_EXPECT_EQ(test, skb->csum_offset, (u16)16);
+	KUNIT_EXPECT_EQ(test, skb_shinfo(skb)->gso_size, (u16)1460);
+	KUNIT_EXPECT_EQ(test, skb_shinfo(skb)->gso_type, SKB_GSO_TCPV4);
+	KUNIT_EXPECT_EQ(test, get_unaligned_be16(skb->data + 12), 0x8100);
+	KUNIT_EXPECT_EQ(test, get_unaligned_be16(skb->data + 14), 0x80a0);
+	KUNIT_EXPECT_EQ(test, get_unaligned_be16(skb->data + 16), ETH_P_8021Q);
+	KUNIT_EXPECT_EQ(test, get_unaligned_be16(skb->data + 18), 0xe000);
+	KUNIT_EXPECT_EQ(test, get_unaligned_be16(skb->data + 20), ETH_P_IP);
+	kfree_skb(skb);
+}
+
+static struct sk_buff *qca4_test_fragment(struct sk_buff *old,
+					  unsigned int linear)
+{
+	struct sk_buff *skb = alloc_skb(32 + linear, GFP_KERNEL);
+	struct page *page;
+	void *mapped;
+	unsigned int bytes = old->len - linear;
+
+	if (!skb)
+		return NULL;
+	page = alloc_page(GFP_KERNEL);
+	if (!page) {
+		kfree_skb(skb);
+		return NULL;
+	}
+	skb_reserve(skb, 16);
+	skb_put_data(skb, old->data, linear);
+	mapped = kmap_local_page(page);
+	memcpy(mapped, old->data + linear, bytes);
+	kunmap_local(mapped);
+	skb_add_rx_frag(skb, 0, page, 0, bytes, PAGE_SIZE);
+	skb_reset_mac_header(skb);
+	return skb;
+}
+
+static void qca4_test_rx_dispatch(struct kunit *test)
+{
+	struct qca4_test_context *c = test->priv;
+	unsigned int vlans, reason, priority, port;
+
+	for (vlans = 0; vlans <= 2; vlans++) {
+		for (reason = 0; reason < 32; reason++) {
+			for (priority = 0; priority < 8; priority++) {
+				for (port = 0; port < 8; port++) {
+					struct sk_buff *skb = qca4_test_frame(16, vlans),
+						       *result;
+					u16 hdr =
+						FIELD_PREP(QCA_HDR_RECV_VERSION,
+							   QCA_HDR_VERSION) |
+						FIELD_PREP(QCA_HDR_RECV_PRIORITY,
+							priority) |
+						FIELD_PREP(QCA_HDR_RECV_TYPE,
+							   reason) |
+						port;
+					bool accept =
+						port == 5 &&
+						reason !=
+							QCA_HDR_RECV_TYPE_MIB &&
+						reason !=
+							QCA_HDR_RECV_TYPE_RW_REG_ACK;
+
+					KUNIT_ASSERT_NOT_NULL(test, skb);
+					KUNIT_ASSERT_EQ(test,
+							qca4_private_insert(skb, BIT(5)),
+							0);
+					put_unaligned_be16(hdr, skb->data + 14);
+					skb->protocol =
+						eth_type_trans(skb, c->conduit);
+					KUNIT_EXPECT_EQ(test, skb->protocol,
+							htons(ETH_P_XDSA));
+					skb->priority = 42;
+					skb->ip_summed = CHECKSUM_COMPLETE;
+					skb->csum = skb_checksum(skb, 0,
+								 skb->len, 0);
+					result = qca4_private_rcv(skb,
+								  c->conduit);
+					if (!accept) {
+						KUNIT_EXPECT_PTR_EQ(test, result, NULL);
+						continue;
+					}
+					KUNIT_ASSERT_NOT_NULL(test, result);
+					KUNIT_EXPECT_PTR_EQ(test, result->dev,
+							    c->netdev);
+					KUNIT_EXPECT_EQ(test, result->priority,
+							42U);
+					KUNIT_EXPECT_EQ(test, csum_fold(result->csum),
+						csum_fold(skb_checksum(result, 0, result->len,
+							0)));
+					KUNIT_EXPECT_EQ(test,
+						(unsigned int)result->ip_summed,
+						(unsigned int)CHECKSUM_COMPLETE);
+					skb_push(result, ETH_HLEN);
+					result->protocol = eth_type_trans(result, c->netdev);
+					KUNIT_EXPECT_EQ(test, result->protocol,
+						htons(vlans == 2 ?
+							      ETH_P_8021AD :
+						      vlans == 1 ? ETH_P_8021Q :
+								   ETH_P_IP));
+					kfree_skb(result);
+				}
+			}
+		}
+	}
+}
+
+static void qca4_test_nonlinear_and_truncated(struct kunit *test)
+{
+	struct qca4_test_context *c = test->priv;
+	struct sk_buff *full, *skb, *result;
+	unsigned int n;
+
+	full = qca4_test_frame(16, 2);
+	KUNIT_ASSERT_NOT_NULL(test, full);
+	skb = qca4_test_fragment(full,
+				 10); /* TX Ethernet header crosses fragment. */
+	KUNIT_ASSERT_NOT_NULL(test, skb);
+	KUNIT_EXPECT_TRUE(test, skb_is_nonlinear(skb));
+	skb = qca4_private_xmit(skb, c->netdev);
+	KUNIT_ASSERT_NOT_NULL(test, skb);
+	KUNIT_EXPECT_EQ(test, get_unaligned_be16(skb->data + 12), 0x8100);
+	kfree_skb(skb);
+	KUNIT_ASSERT_EQ(test, qca4_private_insert(full, BIT(5)), 0);
+	put_unaligned_be16(0xbe45, full->data + 14); /* Actual observed flood metadata. */
+	skb = qca4_test_fragment(full, ETH_HLEN); /* RX metadata+inner EType nonlinear. */
+	KUNIT_ASSERT_NOT_NULL(test, skb);
+	skb->protocol = eth_type_trans(skb, c->conduit);
+	result = qca4_private_rcv(skb, c->conduit);
+	KUNIT_ASSERT_NOT_NULL(test, result);
+	KUNIT_EXPECT_PTR_EQ(test, result->dev, c->netdev);
+	kfree_skb(result);
+	/* Wrong identifier. */
+	put_unaligned_be16(0x0081, full->data + 12);
+	full->protocol = eth_type_trans(full, c->conduit);
+	KUNIT_EXPECT_PTR_EQ(test, qca4_private_rcv(full, c->conduit), NULL);
+	for (n = 0; n < 4; n++) {
+		skb = alloc_skb(ETH_HLEN + n, GFP_KERNEL);
+		KUNIT_ASSERT_NOT_NULL(test, skb);
+		skb_put_zero(skb, ETH_HLEN + n);
+		put_unaligned_be16(0x8100, skb->data + 12);
+		skb_reset_mac_header(skb);
+		skb_pull(skb, ETH_HLEN);
+		KUNIT_EXPECT_PTR_EQ(test, qca4_private_rcv(skb, c->conduit),
+				    NULL);
+	}
+	for (n = 0; n < ETH_HLEN; n++) {
+		skb = alloc_skb(n, GFP_KERNEL);
+		KUNIT_ASSERT_NOT_NULL(test, skb);
+		skb_put_zero(skb, n);
+		KUNIT_EXPECT_PTR_EQ(test, qca4_private_xmit(skb, c->netdev),
+				    NULL);
+	}
+}
+
+static void qca4_test_rx_clone_complete(struct kunit *test)
+{
+	struct qca4_test_context *c = test->priv;
+	struct sk_buff *skb = qca4_test_frame(16, 0), *copy, *result;
+	unsigned int wire_len;
+	u8 before[128];
+
+	KUNIT_ASSERT_NOT_NULL(test, skb);
+	KUNIT_ASSERT_EQ(test, qca4_private_insert(skb, BIT(5)), 0);
+	put_unaligned_be16(0xbe45, skb->data + 14);
+	wire_len = skb->len;
+	memcpy(before, skb->data, wire_len);
+	skb->protocol = eth_type_trans(skb, c->conduit);
+	skb->ip_summed = CHECKSUM_COMPLETE;
+	skb->csum = skb_checksum(skb, 0, skb->len, 0);
+	copy = skb_clone(skb, GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, copy);
+	result = qca4_private_rcv(copy, c->conduit);
+	KUNIT_ASSERT_NOT_NULL(test, result);
+	KUNIT_EXPECT_MEMEQ(test, skb_mac_header(skb), before, wire_len);
+	KUNIT_EXPECT_EQ(test, csum_fold(result->csum),
+			csum_fold(skb_checksum(result, 0, result->len, 0)));
+	KUNIT_EXPECT_EQ(test, (unsigned int)result->ip_summed,
+			(unsigned int)CHECKSUM_COMPLETE);
+	kfree_skb(result);
+	kfree_skb(skb);
+}
+
+static void qca4_test_masks_and_bad_versions(struct kunit *test)
+{
+	struct qca4_test_context *c = test->priv;
+	struct sk_buff *skb;
+	unsigned int mask, version;
+	int ret;
+
+	for (mask = 0; mask <= 255; mask++) {
+		skb = qca4_test_frame(0, 0);
+		KUNIT_ASSERT_NOT_NULL(test, skb);
+		ret = qca4_private_insert(skb, mask);
+		if (!mask || mask > 127) {
+			KUNIT_EXPECT_EQ(test, ret, -EINVAL);
+		} else {
+			KUNIT_EXPECT_EQ(test, ret, 0);
+			KUNIT_EXPECT_EQ(test,
+					get_unaligned_be16(skb->data + 14),
+					0x8080 | mask);
+		}
+		kfree_skb(skb);
+	}
+	for (version = 0; version < 4; version++) {
+		if (version == QCA_HDR_VERSION)
+			continue;
+		skb = qca4_test_frame(16, 0);
+		KUNIT_ASSERT_NOT_NULL(test, skb);
+		KUNIT_ASSERT_EQ(test, qca4_private_insert(skb, BIT(5)), 0);
+		put_unaligned_be16((version << 14) | 5, skb->data + 14);
+		skb->protocol = eth_type_trans(skb, c->conduit);
+		KUNIT_EXPECT_PTR_EQ(test, qca4_private_rcv(skb, c->conduit),
+				    NULL);
+	}
+}
+
+static void qca4_test_flow_dissect(struct kunit *test)
+{
+	static const u8 bytes[] = { 0xbe, 0x45, 0x08, 0x00 };
+	unsigned int length, linear;
+
+	/*
+	 * Every truncated length and every possible split across a page fragment.
+	 * A one-byte reserve also exercises unaligned linear EtherType access.
+	 */
+	for (length = 0; length <= sizeof(bytes); length++) {
+		for (linear = 0; linear <= length; linear++) {
+			struct sk_buff *skb, *full, *clone;
+			unsigned char *data;
+			unsigned int headlen;
+			__be16 proto = htons(0xffff);
+			int offset = -1;
+
+			full = alloc_skb(16, GFP_KERNEL);
+			KUNIT_ASSERT_NOT_NULL(test, full);
+			skb_reserve(full, 1);
+			skb_put_data(full, bytes, length);
+			skb = full;
+			if (linear < length) {
+				skb = qca4_test_fragment(full, linear);
+				kfree_skb(full);
+				KUNIT_ASSERT_NOT_NULL(test, skb);
+			}
+			clone = skb_clone(skb, GFP_KERNEL);
+			KUNIT_ASSERT_NOT_NULL(test, clone);
+			data = clone->data;
+			headlen = skb_headlen(clone);
+			qca4_private_ops.flow_dissect(clone, &proto, &offset);
+			KUNIT_EXPECT_EQ(test, offset, QCA4_PRIVATE_LEN);
+			KUNIT_EXPECT_EQ(test, proto,
+				length == sizeof(bytes) ? htons(ETH_P_IP) : 0);
+			KUNIT_EXPECT_PTR_EQ(test, clone->data, data);
+			KUNIT_EXPECT_EQ(test, clone->len, length);
+			KUNIT_EXPECT_EQ(test, skb_headlen(clone), headlen);
+			KUNIT_EXPECT_MEMEQ(test, skb->data, bytes, headlen);
+			kfree_skb(clone);
+			kfree_skb(skb);
+		}
+	}
+}
+
+static struct kunit_case qca4_private_cases[] = {
+	KUNIT_CASE(qca4_test_flow_dissect),
+	KUNIT_CASE(qca4_test_tx_metadata),
+	KUNIT_CASE(qca4_test_vlan_metadata),
+	KUNIT_CASE(qca4_test_rx_clone_complete),
+	KUNIT_CASE(qca4_test_masks_and_bad_versions),
+	KUNIT_CASE(qca4_test_rx_dispatch),
+	KUNIT_CASE(qca4_test_nonlinear_and_truncated),
+	{}
+};
+
+static struct kunit_suite qca4_private_suite = {
+	.name = "qca4-skb",
+	.init = qca4_test_init,
+	.exit = qca4_test_exit,
+	.test_cases = qca4_private_cases,
+};
+
+kunit_test_suite(qca4_private_suite);

-- 
2.53.0



^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH RFC net-next 3/7] netfilter: flowtable: expose route MTU and established TCP context
  2026-11-25 20:50 [PATCH RFC net-next 0/7] net: cortina: CS7542 wired IPv4 hardware flowtable offload Fil Dunsky via B4 Relay
  2026-11-25 20:50 ` [PATCH RFC net-next 1/7] dt-bindings: net: dsa: allow the QCA four-byte tag protocol Fil Dunsky via B4 Relay
  2026-11-25 20:50 ` [PATCH RFC net-next 2/7] net: dsa: add a QCA four-byte CPU tagger Fil Dunsky via B4 Relay
@ 2026-11-25 20:50 ` Fil Dunsky via B4 Relay
  2026-11-25 20:50 ` [PATCH RFC net-next 4/7] net: cortina: add a serialized CS7542 forwarding engine owner Fil Dunsky via B4 Relay
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-11-25 20:50 UTC (permalink / raw)
  To: Andrew Lunn, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Florian Fainelli, Simon Horman, Pablo Neira Ayuso,
	Florian Westphal, Phil Sutter, Hans Ulli Kroll, Linus Walleij,
	Andrew Lunn, Russell King, Christian Marangi, Jonathan Corbet,
	Shuah Khan, Randy Dunlap
  Cc: netdev, devicetree, linux-kernel, netfilter-devel, coreteam,
	linux-arm-kernel, linux-doc, Fil Dunsky

From: Fil Dunsky <filipp.dunsky@gmail.com>

Carry the direction route MTU in the classifier request. Snapshot
established TCP state under the conntrack lock, rejecting dying and
closing flows. The CS7542 backend needs these facts to install its
length and TCP exception guards; flower rewrites alone do not supply
them.

This is an RFC interface proposal. Other flower users leave the added
fields zero.

Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com>
---
 include/net/flow_offload.h            |  5 +++++
 net/netfilter/nf_flow_table_offload.c | 25 ++++++++++++++++++++++++-
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/include/net/flow_offload.h b/include/net/flow_offload.h
index 70a02ee14..0f9783b5c 100644
--- a/include/net/flow_offload.h
+++ b/include/net/flow_offload.h
@@ -699,8 +699,13 @@ struct flow_cls_offload {
 	struct flow_rule *rule;
 	struct flow_stats stats;
 	u32 classid;
+	u16 nf_route_mtu;
+	bool nf_tcp_established;
 };
 
+#define NF_FLOW_CLS_HAS_ROUTE_MTU 1
+u16 nf_flow_offload_route_mtu(const struct flow_cls_offload *cls);
+
 enum offload_act_command  {
 	FLOW_ACT_REPLACE,
 	FLOW_ACT_DESTROY,
diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
index 436585922..686781363 100644
--- a/net/netfilter/nf_flow_table_offload.c
+++ b/net/netfilter/nf_flow_table_offload.c
@@ -13,6 +13,7 @@
 #include <net/netfilter/nf_conntrack.h>
 #include <net/netfilter/nf_conntrack_acct.h>
 #include <net/netfilter/nf_conntrack_core.h>
+#include <net/netfilter/nf_conntrack_l4proto.h>
 #include <net/netfilter/nf_conntrack_tuple.h>
 
 #define NF_FLOW_RULE_ACTION_MAX	24
@@ -885,6 +886,16 @@ static int nf_flow_offload_alloc(const struct flow_offload_work *offload,
 	return 0;
 }
 
+/* The flowtable records the route MTU independently for each direction. */
+u16 nf_flow_offload_route_mtu(const struct flow_cls_offload *cls)
+{
+	if (!cls || cls->command != FLOW_CLS_REPLACE || !cls->rule)
+		return 0;
+
+	return cls->nf_route_mtu;
+}
+EXPORT_SYMBOL_GPL(nf_flow_offload_route_mtu);
+
 static void nf_flow_offload_init(struct flow_cls_offload *cls_flow,
 				 __be16 proto, int priority,
 				 enum flow_cls_command cmd,
@@ -896,6 +907,7 @@ static void nf_flow_offload_init(struct flow_cls_offload *cls_flow,
 	cls_flow->common.extack = extack;
 	cls_flow->command = cmd;
 	cls_flow->cookie = (unsigned long)tuple;
+	cls_flow->nf_route_mtu = tuple->mtu;
 }
 
 static int nf_flow_offload_tuple(struct nf_flowtable *flowtable,
@@ -914,8 +926,19 @@ static int nf_flow_offload_tuple(struct nf_flowtable *flowtable,
 
 	nf_flow_offload_init(&cls_flow, proto, priority, cmd,
 			     &flow->tuplehash[dir].tuple, &extack);
-	if (cmd == FLOW_CLS_REPLACE)
+	if (cmd == FLOW_CLS_REPLACE) {
 		cls_flow.rule = flow_rule->rule;
+		if (flow->tuplehash[dir].tuple.l4proto == IPPROTO_TCP &&
+		    flow->ct) {
+			spin_lock_bh(&flow->ct->lock);
+			cls_flow.nf_tcp_established =
+				nf_conntrack_tcp_established(flow->ct) &&
+				!nf_ct_is_dying(flow->ct) &&
+				!test_bit(NF_FLOW_TEARDOWN, &flow->flags) &&
+				!test_bit(NF_FLOW_CLOSING, &flow->flags);
+			spin_unlock_bh(&flow->ct->lock);
+		}
+	}
 
 	down_read(&flowtable->flow_block_lock);
 	list_for_each_entry(block_cb, block_cb_list, list) {

-- 
2.53.0



^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH RFC net-next 4/7] net: cortina: add a serialized CS7542 forwarding engine owner
  2026-11-25 20:50 [PATCH RFC net-next 0/7] net: cortina: CS7542 wired IPv4 hardware flowtable offload Fil Dunsky via B4 Relay
                   ` (2 preceding siblings ...)
  2026-11-25 20:50 ` [PATCH RFC net-next 3/7] netfilter: flowtable: expose route MTU and established TCP context Fil Dunsky via B4 Relay
@ 2026-11-25 20:50 ` Fil Dunsky via B4 Relay
  2026-11-25 20:50 ` [PATCH RFC net-next 5/7] net: dsa: qca8k: select the four-byte format before port activation Fil Dunsky via B4 Relay
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-11-25 20:50 UTC (permalink / raw)
  To: Andrew Lunn, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Florian Fainelli, Simon Horman, Pablo Neira Ayuso,
	Florian Westphal, Phil Sutter, Hans Ulli Kroll, Linus Walleij,
	Andrew Lunn, Russell King, Christian Marangi, Jonathan Corbet,
	Shuah Khan, Randy Dunlap
  Cc: netdev, devicetree, linux-kernel, netfilter-devel, coreteam,
	linux-arm-kernel, linux-doc, Fil Dunsky

From: Fil Dunsky <filipp.dunsky@gmail.com>

Attach hardware flowtable requests through the indirect conduit block
API. Retain DMA and register ownership in the Ethernet driver, with
bounded typed operations for a replaceable placement algorithm.

Verify the complete table image and exception guards before exposing a
lookup. Retain immutable results across lookup withdrawal: identical
actions can be shared and rebound, while incompatible actions fall back
when the eight-result pool is exhausted. Never treat invalidation as
proof of pipeline drain.

Only zero-to-one sticky HIT observations advance lastused. Active flows
can therefore refresh through the CPU on the normal Linux timeout. The
RFC keeps the development module attachment and checked-detach
interface; consolidation into the Ethernet driver remains open.

Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com>
---
 drivers/net/ethernet/cortina/Kconfig               |  53 ++
 drivers/net/ethernet/cortina/Makefile              |  13 +-
 drivers/net/ethernet/cortina/cs752x_ne.c           | 120 +++
 drivers/net/ethernet/cortina/cs7542_fe_live.c      | 735 ++++++++++++++++
 drivers/net/ethernet/cortina/cs7542_ft_live.c      | 415 +++++++++
 drivers/net/ethernet/cortina/cs_fe_acl_encode.c    | 124 +++
 drivers/net/ethernet/cortina/cs_fe_acl_guard.c     | 324 +++++++
 drivers/net/ethernet/cortina/cs_fe_acl_guard.h     |  47 +
 drivers/net/ethernet/cortina/cs_fe_backend.h       | 228 +++++
 .../net/ethernet/cortina/cs_fe_backend_algorithm.c | 976 +++++++++++++++++++++
 .../net/ethernet/cortina/cs_fe_backend_dispatch.c  | 433 +++++++++
 .../net/ethernet/cortina/cs_fe_backend_module.c    | 164 ++++
 drivers/net/ethernet/cortina/cs_fe_encode.c        | 562 ++++++++++++
 drivers/net/ethernet/cortina/cs_fe_encode.h        |   5 +
 drivers/net/ethernet/cortina/cs_fe_fields.h        | 339 +++++++
 drivers/net/ethernet/cortina/cs_fe_format.h        |  23 +
 drivers/net/ethernet/cortina/cs_fe_hot.c           |  84 ++
 drivers/net/ethernet/cortina/cs_fe_hot.h           |  15 +
 drivers/net/ethernet/cortina/cs_fe_hot_access.c    | 276 ++++++
 drivers/net/ethernet/cortina/cs_fe_hot_access.h    |  55 ++
 drivers/net/ethernet/cortina/cs_fe_hot_codec.c     |   2 +
 drivers/net/ethernet/cortina/cs_fe_hot_compare.h   |  47 +
 drivers/net/ethernet/cortina/cs_fe_hot_internal.h  |  44 +
 drivers/net/ethernet/cortina/cs_fe_hot_lineage.c   | 138 +++
 drivers/net/ethernet/cortina/cs_fe_hot_lineage.h   |  70 ++
 drivers/net/ethernet/cortina/cs_fe_hot_tables.c    | 920 +++++++++++++++++++
 drivers/net/ethernet/cortina/cs_fe_native.inc      | 668 ++++++++++++++
 .../net/ethernet/cortina/cs_fe_native_activity.inc | 237 +++++
 drivers/net/ethernet/cortina/cs_fe_native_mtu.h    |  43 +
 drivers/net/ethernet/cortina/cs_fe_native_mtu.inc  | 128 +++
 drivers/net/ethernet/cortina/cs_fe_native_state.h  |  24 +
 include/linux/cs7542_fe_backend.h                  |  65 ++
 include/linux/cs7542_fe_codec.h                    | 145 +++
 include/linux/cs7542_fe_live.h                     |  58 ++
 include/linux/cs7542_fe_native.h                   |  34 +
 include/linux/cs7542_ft_live.h                     |  70 ++
 include/linux/dsa/qca8k_persistent.h               |  45 +
 37 files changed, 7728 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/cortina/Kconfig b/drivers/net/ethernet/cortina/Kconfig
index 52c0683be..13df28071 100644
--- a/drivers/net/ethernet/cortina/Kconfig
+++ b/drivers/net/ethernet/cortina/Kconfig
@@ -35,3 +35,56 @@ config CS7542_ETHERNET
 	  cs7542-eth.
 
 endif # NET_VENDOR_CORTINA
+
+config CS7542_FT_LIVE_BRIDGE
+	bool "CS7542 hardware flowtable attachment"
+	depends on CS7542_ETHERNET=y && NET_DSA && MODULES && MODULE_UNLOAD
+	depends on !MODULE_FORCE_UNLOAD
+	default n
+	help
+	  Attach a flowtable frontend through the standard indirect block API.
+	  Packet DMA remains owned by the network engine driver.
+	  Only TC_SETUP_FT bindings are accepted. Ordinary traffic-control
+	  flower blocks cannot use this attachment to program the engine.
+
+config CS7542_FE_LIVE_OWNER
+	bool "CS7542 forwarding engine owner"
+	depends on CS7542_FT_LIVE_BRIDGE && !PM
+	depends on BRIDGE=y && INET && NETFILTER=y && NET_SWITCHDEV
+	default n
+	help
+	  Serialize forwarding-engine transactions with network-engine reset.
+	  Uncertain hardware state is retained until a verified reset.
+	  Rules use numeric leases under the same mutex as table access.
+	  Immutable action records remain allocated after lookup withdrawal.
+
+config CS7542_FE_HOT_BACKEND
+	bool "CS7542 replaceable forwarding backend"
+	depends on CS7542_FE_LIVE_OWNER && CS7542_ETHERNET=y
+	depends on MODULES && !MODULE_FORCE_UNLOAD
+	default n
+	help
+	  Keep table ownership in the built-in driver while a module supplies
+	  the placement algorithm. This RFC retains the replaceable backend
+	  used for hardware development; the module interface is not stable.
+	  MMIO and guard ownership never move into the replaceable module.
+
+config CS7542_FE_BACKEND
+	tristate "CS7542 forwarding placement backend"
+	depends on CS7542_FE_HOT_BACKEND && m
+	default n
+	help
+	  Install supported forwarding rules and retire their lookup selectors.
+	  Hardware uncertainty retains the module until checked detachment.
+	  The backend receives typed, bounded table operations from the owner.
+	  Retained actions can be shared or rebound only with identical contents.
+
+config CS7542_FE_WIRED
+	bool "CS7542 wired IPv4 TCP and UDP NAT"
+	depends on CS7542_FE_HOT_BACKEND
+	default n
+	help
+	  Accept hardware flowtable requests on the CS7542 wired DSA path.
+	  IPv6, Wi-Fi and unsupported policies continue through the CPU.
+	  TCP requires an established connection; SYN and FIN stay in software.
+	  Route, neighbor, MTU and tag state are checked before admission.
diff --git a/drivers/net/ethernet/cortina/Makefile b/drivers/net/ethernet/cortina/Makefile
index e998ffcc8..2bd0572d0 100644
--- a/drivers/net/ethernet/cortina/Makefile
+++ b/drivers/net/ethernet/cortina/Makefile
@@ -2,6 +2,17 @@
 # Makefile for the Cortina Gemini network device drivers.
 
 obj-$(CONFIG_GEMINI_ETHERNET) += gemini.o
-
 obj-$(CONFIG_CS7542_ETHERNET) += cs7542-eth.o
 cs7542-eth-y := cs752x_ne.o cs752x_fe.o cs752x_sch_tm.o
+
+obj-$(CONFIG_CS7542_FT_LIVE_BRIDGE) += cs7542_ft_live.o
+cs7542-eth-$(CONFIG_CS7542_FE_LIVE_OWNER) += cs7542_fe_live.o cs_fe_encode.o cs_fe_acl_guard.o cs_fe_acl_encode.o cs_fe_hot.o
+
+ifeq ($(CONFIG_CS7542_FE_HOT_BACKEND),y)
+cs7542-eth-y += cs_fe_backend_dispatch.o cs_fe_hot_tables.o cs_fe_hot_access.o cs_fe_hot_lineage.o
+else
+cs7542-eth-$(CONFIG_CS7542_FE_LIVE_OWNER) += cs_fe_backend.o
+endif
+obj-$(CONFIG_CS7542_FE_BACKEND) += cs7542_fe_backend.o
+cs7542_fe_backend-y := cs_fe_backend_module.o cs_fe_backend_algorithm.o cs_fe_hot_codec.o
+
diff --git a/drivers/net/ethernet/cortina/cs752x_ne.c b/drivers/net/ethernet/cortina/cs752x_ne.c
index 081b42079..d6933fc1b 100644
--- a/drivers/net/ethernet/cortina/cs752x_ne.c
+++ b/drivers/net/ethernet/cortina/cs752x_ne.c
@@ -27,6 +27,13 @@
 #include <linux/xarray.h>
 
 #include "cs752x_ne.h"
+#ifdef CONFIG_CS7542_FT_LIVE_BRIDGE
+#include <linux/cs7542_ft_live.h>
+#endif
+
+#ifdef CONFIG_CS7542_FE_LIVE_OWNER
+#include <linux/cs7542_fe_live.h>
+#endif
 
 #define CS_NE_PORTS			3
 #define CS_NE_RX_INSTANCES		9
@@ -249,6 +256,10 @@ struct cs_ne_txq {
 };
 
 struct cs_ne_port {
+#ifdef CONFIG_CS7542_FT_LIVE_BRIDGE
+	struct cs7542_ft_live *live;
+#endif
+
 	struct cs_ne *ne;
 	struct net_device *ndev;
 	struct device_node *np;
@@ -273,6 +284,9 @@ static const char * const cs_ne_reset_names[CS_NE_NUM_RESETS] = {
 };
 
 struct cs_ne {
+#ifdef CONFIG_CS7542_FE_LIVE_OWNER
+	struct cs7542_fe_live *fe_live;
+#endif
 	struct device *dev;
 	/* Shared NI registers contain fields belonging to several MACs. */
 	spinlock_t ni_lock;
@@ -1458,7 +1472,33 @@ static const struct ethtool_ops cs_ne_ethtool_ops = {
 	.set_link_ksettings = cs_ne_set_link_ksettings,
 };
 
+#ifdef CONFIG_CS7542_FT_LIVE_BRIDGE
+static int cs_ne_live_setup_tc(struct net_device *dev, enum tc_setup_type type,
+			       void *data)
+{
+	struct cs_ne_port *port = netdev_priv(dev);
+
+	return cs7542_ft_live_setup(port->live, type, data);
+}
+
+static ssize_t private_ft_live_show(struct device *dev,
+				    struct device_attribute *attr, char *buffer)
+{
+	struct cs_ne_port *port = netdev_priv(to_net_dev(dev));
+
+	return cs7542_ft_live_format(port->live, buffer);
+}
+
+static DEVICE_ATTR_RO(private_ft_live);
+static struct attribute *cs_live_attrs[] = { &dev_attr_private_ft_live.attr,
+					     NULL };
+static const struct attribute_group cs_live_group = { .attrs = cs_live_attrs };
+#endif
+
 static const struct net_device_ops cs_ne_netdev_ops = {
+#ifdef CONFIG_CS7542_FT_LIVE_BRIDGE
+	.ndo_setup_tc = cs_ne_live_setup_tc,
+#endif
 	.ndo_open = cs_ne_open,
 	.ndo_stop = cs_ne_stop,
 	.ndo_start_xmit = cs_ne_start_xmit,
@@ -1471,8 +1511,24 @@ static void cs_ne_port_cleanup(void *data)
 {
 	struct cs_ne_port *port = data;
 
+#ifdef CONFIG_CS7542_FE_LIVE_OWNER
+	cs7542_fe_live_unbind(port->ne->fe_live, port->ndev, port->id);
+#endif
+#ifdef CONFIG_CS7542_FT_LIVE_BRIDGE
+	/*
+	 * Drain callbacks before unregister stops the port and owner.
+	 * The FE API rejects later MMIO after terminal/reset.
+	 */
+	if (cs7542_ft_live_quiesce(port->live))
+		dev_err(port->ne->dev,
+			"live provider withdrawal uncertain; retained module pin\n");
+#endif
 	if (port->registered)
 		unregister_netdev(port->ndev);
+#ifdef CONFIG_CS7542_FT_LIVE_BRIDGE
+	cs7542_ft_live_put(port->live);
+	port->live = NULL;
+#endif
 	phylink_destroy(port->phylink);
 	netif_napi_del(&port->napi);
 	/* The shared completion poll can outlive a closed port. */
@@ -1547,6 +1603,17 @@ static int cs_ne_probe_port(struct cs_ne *ne, struct device_node *np)
 	ret = devm_add_action_or_reset(dev, cs_ne_port_cleanup, port);
 	if (ret)
 		return ret;
+#ifdef CONFIG_CS7542_FT_LIVE_BRIDGE
+	if (id == 1) {
+		port->live = cs7542_ft_live_create(ndev, id);
+		if (IS_ERR(port->live)) {
+			ret = PTR_ERR(port->live);
+			port->live = NULL;
+			return ret;
+		}
+		ndev->sysfs_groups[0] = &cs_live_group;
+	}
+#endif
 
 	cs_ne_port_hw_init(port);
 	cs_ne_set_hw_addr(port);
@@ -1612,6 +1679,18 @@ static void cs_ne_context_release(void *data)
 	kfree(ne);
 }
 
+#ifdef CONFIG_CS7542_FE_LIVE_OWNER
+static void cs_ne_live_release(void *data)
+{
+	struct cs_ne *ne = data;
+
+	cs7542_fe_live_stop(ne->fe_live);
+	cs7542_fe_live_put(ne->fe_live);
+	ne->fe_live = NULL;
+}
+
+#endif
+
 /* All ports/IRQs/NAPI have been removed before this action runs. */
 static void cs_ne_hw_cleanup(void *data)
 {
@@ -1623,6 +1702,10 @@ static void cs_ne_hw_cleanup(void *data)
 	if (ne->hw_cleanup_done)
 		return;
 	ne->hw_cleanup_done = true;
+#ifdef CONFIG_CS7542_FE_LIVE_OWNER
+	/* Port cleanup drained the bridge before the owner becomes terminal. */
+	cs7542_fe_live_stop(ne->fe_live);
+#endif
 	cs_ne_rx_cancel_retry(ne);
 	cs_ne_tx_cancel_timer(txq);
 	if (ne->hw_accessible) {
@@ -1635,6 +1718,10 @@ static void cs_ne_hw_cleanup(void *data)
 
 	/* The entire owned NE + LSO/SSP domain stays reset through release. */
 	ret = cs_ne_assert_resets(ne);
+#ifdef CONFIG_CS7542_FE_LIVE_OWNER
+	if (!ret)
+		cs7542_fe_live_reset_done(ne->fe_live);
+#endif
 	if (ret && ne->hw_active) {
 		ne->dma_pinned = true;
 		return;
@@ -1770,6 +1857,18 @@ static int cs_ne_probe(struct platform_device *pdev)
 		}
 	}
 
+#ifdef CONFIG_CS7542_FE_LIVE_OWNER
+	ne->fe_live = cs7542_fe_live_create(dev, ne->fe,
+		min_t(resource_size_t,
+		      resource_size(platform_get_resource_byname(pdev, IORESOURCE_MEM, "fe")),
+		      UINT_MAX));
+	if (IS_ERR(ne->fe_live))
+		return PTR_ERR(ne->fe_live);
+	ret = devm_add_action_or_reset(dev, cs_ne_live_release, ne);
+	if (ret)
+		return ret;
+#endif
+
 	/* No hardware state needs unwinding until the first reset attempt. */
 	ret = devm_add_action(dev, cs_ne_hw_cleanup, ne);
 	if (ret)
@@ -1800,7 +1899,11 @@ static int cs_ne_probe(struct platform_device *pdev)
 	ret = cs752x_tm_init(dev, ne->tm);
 	if (ret)
 		return dev_err_probe(dev, ret, "TM init failed\n");
+#ifdef CONFIG_CS7542_FE_LIVE_OWNER
+	ret = cs7542_fe_live_init(ne->fe_live, cs752x_fe_init);
+#else
 	ret = cs752x_fe_init(dev, ne->fe);
+#endif
 	if (ret)
 		return dev_err_probe(dev, ret, "FE init failed\n");
 	writel(readl(ne->fe + FETOP_FE_PRSR_CFG_0) & ~FE_L4_CHKSUM_CHK_DISABLE,
@@ -1821,6 +1924,15 @@ static int cs_ne_probe(struct platform_device *pdev)
 	if (!nports)
 		return -ENODEV;
 
+#ifdef CONFIG_CS7542_FE_LIVE_OWNER
+	for (i = 0; i < CS_NE_PORTS; i++) {
+		if (!ne->ports[i])
+			continue;
+		ret = cs7542_fe_live_bind(ne->fe_live, ne->ports[i]->ndev, i);
+		if (ret)
+			return ret;
+	}
+#endif
 	/* No netdev may open while the shared pools are only partly prepared. */
 	rtnl_lock();
 	for (i = 0; i < CS_NE_PORTS; i++) {
@@ -1834,6 +1946,9 @@ static int cs_ne_probe(struct platform_device *pdev)
 
 	/* Cleanup must revoke hardware references before releasing any mappings. */
 	ne->hw_active = true;
+#ifdef CONFIG_CS7542_FE_LIVE_OWNER
+	cs7542_fe_live_activate(ne->fe_live);
+#endif
 	/* There are no fallible probe operations after publishing DMA addresses. */
 	spin_lock_irq(&ne->rx_lock);
 	ne->rx_stopping = false;
@@ -1852,6 +1967,7 @@ static const struct of_device_id cs_ne_of_match[] = {
 	{ .compatible = "cortina,cs7542-ethernet" },
 	{ }
 };
+
 MODULE_DEVICE_TABLE(of, cs_ne_of_match);
 
 static struct platform_driver cs_ne_driver = {
@@ -1860,9 +1976,13 @@ static struct platform_driver cs_ne_driver = {
 	.shutdown = cs_ne_shutdown,
 	.driver = {
 		.name = "cs7542-ethernet",
+#ifdef CONFIG_CS7542_FT_LIVE_BRIDGE
+		.suppress_bind_attrs = true,
+#endif
 		.of_match_table = cs_ne_of_match,
 	},
 };
+
 module_platform_driver(cs_ne_driver);
 
 MODULE_DESCRIPTION("Cortina CS7542 network engine driver");
diff --git a/drivers/net/ethernet/cortina/cs7542_fe_live.c b/drivers/net/ethernet/cortina/cs7542_fe_live.c
new file mode 100644
index 000000000..a2de22061
--- /dev/null
+++ b/drivers/net/ethernet/cortina/cs7542_fe_live.c
@@ -0,0 +1,735 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Built-in sole FE owner. Only typed numeric requests cross the module ABI. */
+#include <linux/device.h>
+#include <linux/etherdevice.h>
+#include <linux/err.h>
+#include <linux/export.h>
+#include <linux/io.h>
+#include <linux/kref.h>
+#include <linux/ktime.h>
+#include <linux/list.h>
+#include <linux/math64.h>
+#include <linux/mutex.h>
+#include <linux/netdevice.h>
+#include <linux/slab.h>
+#include <linux/rtnetlink.h>
+#include <linux/skbuff.h>
+#include <linux/spinlock.h>
+#include <linux/workqueue.h>
+#include <linux/cs7542_fe_live.h>
+#include <linux/dsa/qca8k_persistent.h>
+#include <linux/of.h>
+#include <net/dsa.h>
+#include <net/route.h>
+#include <net/arp.h>
+#include <linux/capability.h>
+#include "cs_fe_hot.h"
+#include "cs_fe_backend.h"
+#define CS_FE_NATIVE_AVAILABLE                                            \
+	(IS_ENABLED(CONFIG_CS7542_FE_HOT_BACKEND) &&                      \
+	 IS_BUILTIN(CONFIG_BRIDGE) && IS_ENABLED(CONFIG_NET_SWITCHDEV) && \
+	 IS_BUILTIN(CONFIG_INET) && IS_BUILTIN(CONFIG_NETFILTER))
+#if IS_ENABLED(CONFIG_CS7542_FE_HOT_BACKEND)
+#include "cs_fe_hot_internal.h"
+#endif
+#if CS_FE_NATIVE_AVAILABLE
+#include "cs_fe_native_state.h"
+#endif
+#include "cs_fe_acl_guard.h"
+
+#define CS_FE_LIVE_PORTS 3
+struct cs7542_fe_live {
+	struct list_head node;
+	struct kref refs;
+	struct mutex lock;
+	struct device *dev;
+	struct net_device *ports[CS_FE_LIVE_PORTS];
+	void __iomem *base;
+	unsigned int extent;
+	bool initialized, online, closing, reset_verified, quarantine_ref;
+	u64 epoch;
+	struct cs7542_fe_hot_sample hot_before[CS_FE_BACKEND_LEASES];
+	struct cs7542_fe_hot_sample hot_after[CS_FE_BACKEND_LEASES];
+	struct cs_fe_backend backend;
+#if IS_ENABLED(CONFIG_CS7542_FE_HOT_BACKEND)
+	struct cs_fe_hot_state hot_state;
+#endif
+#if CS_FE_NATIVE_AVAILABLE
+	struct cs_fe_native_state native;
+#endif
+	struct cs_fe_acl_guard guard[CS_FE_BACKEND_LEASES];
+};
+
+static int cs_fe_live_guard_prepare(void *context,
+				    const struct cs_fe_backend_io *io,
+				    unsigned int lease,
+				    const struct cs_fe_rows *rows,
+				    const struct cs_fe_plan *plan,
+				    unsigned long long end_us);
+static int cs_fe_live_guard_rearm(void *context,
+				  const struct cs_fe_backend_io *io,
+				  unsigned int lease,
+				  const struct cs_fe_rows *rows,
+				  const struct cs_fe_plan *plan,
+				  unsigned long long end_us);
+static int cs_fe_live_guard_withdraw(void *context,
+				     const struct cs_fe_backend_io *io,
+				     unsigned int lease,
+				     const struct cs_fe_rows *rows,
+				     const struct cs_fe_plan *plan,
+				     unsigned long long end_us);
+static void cs_fe_live_before_withdraw(void *context,
+				       const struct cs_fe_backend_io *io,
+				       unsigned int lease,
+				       const struct cs_fe_plan *plan,
+				       unsigned long long end_us);
+#if IS_ENABLED(CONFIG_CS7542_FE_HOT_BACKEND)
+static bool cs_fe_live_hot_guards_ready(void *context, unsigned int slot);
+#endif
+#if CS_FE_NATIVE_AVAILABLE
+static int cs_fe_native_range(void *context, bool prepare, u8 range_bit,
+			      unsigned long long end);
+static void cs_fe_native_prune(struct cs7542_fe_live *owner);
+#else
+static inline void cs_fe_native_prune(struct cs7542_fe_live *owner)
+{
+}
+
+#endif
+#if IS_ENABLED(CONFIG_CS7542_FE_HOT_BACKEND)
+static int cs_fe_live_hot_guards_rebind(void *context, unsigned int slot,
+					const u32 *old_invalid,
+					const u32 *new_invalid,
+					unsigned long long end, bool commit);
+#endif
+static LIST_HEAD(cs_fe_live_owners);
+static DEFINE_MUTEX(cs_fe_live_owners_lock);
+
+static void cs_fe_live_release(struct kref *ref)
+{
+	struct cs7542_fe_live *owner =
+		container_of(ref, struct cs7542_fe_live, refs);
+
+#if IS_ENABLED(CONFIG_CS7542_FE_HOT_BACKEND)
+	mutex_lock(&cs_fe_live_owners_lock);
+	list_del_init(&owner->node);
+	mutex_unlock(&cs_fe_live_owners_lock);
+#else
+	WARN_ON(!list_empty(&owner->node));
+#endif
+	WARN_ON(owner->quarantine_ref);
+	put_device(owner->dev);
+	kvfree(owner);
+}
+
+void cs7542_fe_live_put(struct cs7542_fe_live *owner)
+{
+	if (owner)
+		kref_put(&owner->refs, cs_fe_live_release);
+}
+EXPORT_SYMBOL_GPL(cs7542_fe_live_put);
+
+struct cs7542_fe_live *cs7542_fe_live_create(struct device *dev,
+					     void __iomem *base,
+					     unsigned int extent)
+{
+	struct cs7542_fe_live *owner;
+
+	if (!dev || !base || extent < 0x2080)
+		return ERR_PTR(-EINVAL);
+	owner = kvzalloc_obj(*owner);
+	if (!owner)
+		return ERR_PTR(-ENOMEM);
+	INIT_LIST_HEAD(&owner->node);
+	kref_init(&owner->refs);
+	mutex_init(&owner->lock);
+	owner->dev = get_device(dev);
+	owner->base = base;
+	owner->extent = extent;
+	owner->epoch = 1;
+	/* Routing hardware admission is closed, including in this live lab. */
+	cs_fe_backend_init(&owner->backend, 0);
+#if IS_ENABLED(CONFIG_CS7542_FE_HOT_BACKEND)
+	owner->backend.hot_state = &owner->hot_state;
+	owner->hot_state.guards_ready = cs_fe_live_hot_guards_ready;
+#if CS_FE_NATIVE_AVAILABLE
+	owner->hot_state.native_range = cs_fe_native_range;
+#endif
+	owner->hot_state.guards_rebind = cs_fe_live_hot_guards_rebind;
+	owner->hot_state.guard_context = owner;
+#endif
+	owner->backend.guard_prepare = cs_fe_live_guard_prepare;
+	owner->backend.guard_withdraw = cs_fe_live_guard_withdraw;
+	owner->backend.guard_rearm = cs_fe_live_guard_rearm;
+	owner->backend.guard_context = owner;
+	owner->backend.before_withdraw = cs_fe_live_before_withdraw;
+	mutex_lock(&cs_fe_live_owners_lock);
+	list_add_tail(&owner->node, &cs_fe_live_owners);
+	mutex_unlock(&cs_fe_live_owners_lock);
+	return owner;
+}
+
+int cs7542_fe_live_init(struct cs7542_fe_live *owner,
+			int (*initialize)(struct device *, void __iomem *))
+{
+	int error;
+
+	if (!owner || !initialize)
+		return -EINVAL;
+	mutex_lock(&owner->lock);
+	if (owner->closing || owner->initialized || !owner->base)
+		error = -EBUSY;
+	else {
+		error = initialize(owner->dev, owner->base);
+		if (!error)
+			owner->initialized = true;
+		else
+			owner->backend.poisoned = true;
+	}
+	mutex_unlock(&owner->lock);
+	return error;
+}
+
+void cs7542_fe_live_activate(struct cs7542_fe_live *owner)
+{
+	mutex_lock(&owner->lock);
+	if (owner->initialized && !owner->closing && !owner->backend.poisoned)
+		owner->online = true;
+	mutex_unlock(&owner->lock);
+}
+
+int cs7542_fe_live_bind(struct cs7542_fe_live *owner,
+			struct net_device *conduit, unsigned int gmac)
+{
+	int error = 0;
+
+	if (!owner || !conduit || gmac >= CS_FE_LIVE_PORTS)
+		return -EINVAL;
+	mutex_lock(&cs_fe_live_owners_lock);
+	mutex_lock(&owner->lock);
+	if (owner->closing || owner->ports[gmac])
+		error = -EBUSY;
+	else {
+		dev_hold(conduit);
+		owner->ports[gmac] = conduit;
+	}
+	mutex_unlock(&owner->lock);
+	mutex_unlock(&cs_fe_live_owners_lock);
+	return error;
+}
+
+/*
+ * Drop the engine's conduit ref BEFORE unregister_netdev waits for refs.
+ *
+ * Existing holders may still withdraw under the owner lock; new arms cannot
+ * acquire this port or commit after it has been detached from the registry.
+ */
+void cs7542_fe_live_unbind(struct cs7542_fe_live *owner,
+			   struct net_device *conduit, unsigned int gmac)
+{
+	struct net_device *held = NULL;
+
+	if (!owner || gmac >= CS_FE_LIVE_PORTS)
+		return;
+	mutex_lock(&cs_fe_live_owners_lock);
+	mutex_lock(&owner->lock);
+	if (owner->ports[gmac] == conduit) {
+		held = owner->ports[gmac];
+		owner->ports[gmac] = NULL;
+	}
+	mutex_unlock(&owner->lock);
+	mutex_unlock(&cs_fe_live_owners_lock);
+	if (held)
+		dev_put(held);
+}
+
+struct cs7542_fe_live *cs7542_fe_live_get(struct net_device *conduit)
+{
+	struct cs7542_fe_live *owner, *found = ERR_PTR(-ENODEV);
+
+	if (!conduit)
+		return ERR_PTR(-EINVAL);
+	mutex_lock(&cs_fe_live_owners_lock);
+	list_for_each_entry(owner, &cs_fe_live_owners, node) {
+		/* Only the physically studied GMAC1 is a current candidate. */
+		if (owner->ports[1] != conduit)
+			continue;
+		if (!READ_ONCE(owner->online) || READ_ONCE(owner->closing))
+			found = ERR_PTR(-ESHUTDOWN);
+		else {
+			kref_get(&owner->refs);
+			found = owner;
+		}
+		break;
+	}
+	mutex_unlock(&cs_fe_live_owners_lock);
+	return found;
+}
+EXPORT_SYMBOL_GPL(cs7542_fe_live_get);
+
+static unsigned long long cs_fe_live_now(void *context)
+{
+	return div_u64(ktime_get_ns(), 1000);
+}
+
+static int cs_fe_live_read(void *context, unsigned int offset, u32 *value)
+{
+	struct cs7542_fe_live *owner = context;
+
+	if (!owner->base || owner->closing)
+		return -ESHUTDOWN;
+	if ((offset & 3) || offset > owner->extent - 4)
+		return -ERANGE;
+	*value = readl(owner->base + offset);
+	return 0;
+}
+
+static int cs_fe_live_write(void *context, unsigned int offset, u32 value)
+{
+	struct cs7542_fe_live *owner = context;
+
+	if (!owner->base || owner->closing)
+		return -ESHUTDOWN;
+	if ((offset & 3) || offset > owner->extent - 4)
+		return -ERANGE;
+	writel(value, owner->base + offset);
+	return 0;
+}
+
+static struct cs_fe_backend_io cs_fe_live_io(struct cs7542_fe_live *owner)
+{
+	struct cs_fe_backend_io io = {
+		.context = owner,
+		.extent = owner->extent,
+		.now_us = cs_fe_live_now,
+		.read32 = cs_fe_live_read,
+		.write32 = cs_fe_live_write,
+	};
+	return io;
+}
+
+/*
+ * These callbacks run inside the SAME backend owner transaction/mutex.
+ *
+ * No RTNL acquisition, second scratch owner, new budget or user selector.
+ */
+static int cs_fe_live_guard_prepare(void *context,
+				    const struct cs_fe_backend_io *io,
+				    unsigned int lease,
+				    const struct cs_fe_rows *rows,
+				    const struct cs_fe_plan *plan,
+				    unsigned long long end_us)
+{
+	struct cs7542_fe_live *owner = context;
+	struct cs_fe_backend_io bounded = cs_fe_live_io(owner);
+
+	if (lease >= CS_FE_BACKEND_LEASES || rows->class_row != 5 + lease ||
+	    rows->sdb_row != rows->class_row ||
+	    (plan->sdb.expected[6] & (1U << 13)) ||
+	    (plan->hit.expected[2] & (1U << 29)) ||
+	    ((plan->sdb.expected[0] >> 7) & 15) >= 7)
+		return -EOPNOTSUPP;
+	bounded.limit_us =
+		io->limit_us && io->limit_us < end_us ? io->limit_us : end_us;
+	{
+		int error = cs_fe_acl_prepare(&owner->guard[lease], &bounded,
+					      lease, rows->class_row,
+					      plan->class_invalid.expected);
+
+		if (!error)
+			(void)cs_fe_hot_read(&bounded, plan->key.bucket,
+					     &owner->hot_before[lease]);
+		return error;
+	}
+}
+
+static int cs_fe_live_guard_withdraw(void *context,
+				     const struct cs_fe_backend_io *io,
+				     unsigned int lease,
+				     const struct cs_fe_rows *rows,
+				     const struct cs_fe_plan *plan,
+				     unsigned long long end_us)
+{
+	struct cs7542_fe_live *owner = context;
+	struct cs_fe_backend_io bounded = cs_fe_live_io(owner);
+
+	if (lease >= CS_FE_BACKEND_LEASES ||
+	    owner->guard[lease].class_id != rows->class_row ||
+	    memcmp(owner->guard[lease].class_invalid,
+		   plan->class_invalid.expected,
+		   sizeof(owner->guard[lease].class_invalid)))
+		return -EUCLEAN;
+	bounded.limit_us =
+		io->limit_us && io->limit_us < end_us ? io->limit_us : end_us;
+	{
+		int error;
+
+		if (owner->backend.lease[lease].scoped) {
+			/*
+			 * Keep traps valid even after CLASS invalidation: in-flight old packets
+			 * must not lose exceptions, and identical rearm never changes them.
+			 */
+			error = cs_fe_acl_verify_retained(&owner->guard[lease], &bounded, lease,
+				rows->class_row, plan->class_invalid.expected);
+		} else {
+			error = cs_fe_acl_disarm(&owner->guard[lease],
+						 &bounded);
+		}
+
+		return error;
+	}
+}
+
+static int
+
+cs_fe_live_guard_rearm(void *context, const struct cs_fe_backend_io *io,
+		       unsigned int lease, const struct cs_fe_rows *rows,
+		       const struct cs_fe_plan *plan, unsigned long long end_us)
+{
+	struct cs7542_fe_live *owner = context;
+	struct cs_fe_backend_io bounded = cs_fe_live_io(owner);
+	int error;
+
+	if (lease >= CS_FE_BACKEND_LEASES ||
+	    !owner->backend.lease[lease].scoped ||
+	    owner->backend.lease[lease].marker)
+		return -EOPNOTSUPP;
+	bounded.limit_us =
+		io->limit_us && io->limit_us < end_us ? io->limit_us : end_us;
+	error = cs_fe_acl_verify_retained(&owner->guard[lease], &bounded, lease,
+					  rows->class_row,
+					  plan->class_invalid.expected);
+	if (!error) {
+		memset(&owner->hot_after[lease], 0,
+		       sizeof(owner->hot_after[lease]));
+		(void)cs_fe_hot_read(&bounded, plan->key.bucket,
+				     &owner->hot_before[lease]);
+	}
+	return error;
+}
+
+/*
+ * Main-table allocator ONLY publishes way0/slot0; no overflow lease exists.
+ * Snapshot activity BEFORE any HASH/CLASS invalidation, no bitmap clear.
+ */
+static void cs_fe_live_before_withdraw(void *context,
+				       const struct cs_fe_backend_io *io,
+				       unsigned int lease,
+				       const struct cs_fe_plan *plan,
+				       unsigned long long end_us)
+{
+	struct cs7542_fe_live *owner = context;
+	struct cs_fe_backend_io bounded = cs_fe_live_io(owner);
+
+	bounded.limit_us =
+		io->limit_us && io->limit_us < end_us ? io->limit_us : end_us;
+	if (lease < CS_FE_BACKEND_LEASES)
+		(void)cs_fe_hot_read(&bounded, plan->key.bucket,
+				     &owner->hot_after[lease]);
+}
+
+static int cs_fe_live_ready(struct cs7542_fe_live *owner)
+{
+	if (!owner->online || owner->closing || !owner->base)
+		return -ENODEV;
+	return owner->backend.poisoned ? -EIO : 0;
+}
+
+static void cs_fe_live_pin(struct cs7542_fe_live *owner)
+{
+	/*
+	 * Caller and engine refs cover the complete transaction before this point.
+	 * Pin persistent numeric leases before releasing the sole owner mutex.
+	 */
+	bool guard_written = false;
+	unsigned int i;
+
+	for (i = 0; i < CS_FE_BACKEND_LEASES; i++)
+		guard_written |= owner->guard[i].written;
+#if CS_FE_NATIVE_AVAILABLE
+	for (i = 0; i < ARRAY_SIZE(owner->native.range); i++)
+		guard_written |= owner->native.range[i].touched;
+#endif
+	if ((owner->backend.next_lease || guard_written) &&
+	    !owner->quarantine_ref) {
+		kref_get(&owner->refs);
+		owner->quarantine_ref = true;
+	}
+}
+
+int cs7542_fe_live_open(struct cs7542_fe_live *owner, u64 *block)
+{
+	unsigned long long handle = 0;
+	int error;
+
+	if (!owner || !block)
+		return -EINVAL;
+	mutex_lock(&owner->lock);
+	error = cs_fe_live_ready(owner);
+	if (!error)
+		error = owner->ports[1] ?
+				cs_fe_backend_block_open(&owner->backend,
+							 &handle) :
+				-ESHUTDOWN;
+	if (!error)
+		*block = handle;
+	mutex_unlock(&owner->lock);
+	return error;
+}
+EXPORT_SYMBOL_GPL(cs7542_fe_live_open);
+
+static int cs_fe_live_end(struct cs7542_fe_live *owner, u64 block,
+			  unsigned long cookie, u64 version, int reason,
+			  bool rejection)
+{
+	struct cs_fe_backend_io io;
+	int error;
+
+	if (!owner)
+		return -EINVAL;
+	mutex_lock(&owner->lock);
+	error = cs_fe_live_ready(owner);
+	if (!error) {
+		io = cs_fe_live_io(owner);
+		if (rejection)
+			error = cs_fe_backend_reject(&owner->backend, &io,
+						     block, cookie, version,
+						     reason);
+		else
+			error = cs_fe_backend_destroy(&owner->backend, &io,
+						      block, cookie, version);
+		cs_fe_live_pin(owner);
+	}
+	cs_fe_native_prune(owner);
+	mutex_unlock(&owner->lock);
+	return error;
+}
+
+int cs7542_fe_live_reject(struct cs7542_fe_live *owner, u64 block,
+			  unsigned long cookie, u64 version, int reason)
+{
+	return cs_fe_live_end(owner, block, cookie, version, reason, true);
+}
+EXPORT_SYMBOL_GPL(cs7542_fe_live_reject);
+
+int cs7542_fe_live_destroy(struct cs7542_fe_live *owner, u64 block,
+			   unsigned long cookie, u64 version)
+{
+	return cs_fe_live_end(owner, block, cookie, version, 0, false);
+}
+EXPORT_SYMBOL_GPL(cs7542_fe_live_destroy);
+
+int cs7542_fe_live_close(struct cs7542_fe_live *owner, u64 block)
+{
+	struct cs_fe_backend_io io;
+	int error;
+
+	if (!owner)
+		return -EINVAL;
+	mutex_lock(&owner->lock);
+	if (owner->reset_verified)
+		error = 0; /* Complete reset proof, never an I/O attempt on dead mappings. */
+	else {
+		error = cs_fe_live_ready(owner);
+		if (!error) {
+			io = cs_fe_live_io(owner);
+			error = cs_fe_backend_unbind(&owner->backend, &io,
+						     block);
+			if (!error)
+				error = cs_fe_backend_forget(&owner->backend,
+							     block);
+		}
+	}
+	cs_fe_native_prune(owner);
+	mutex_unlock(&owner->lock);
+	return error;
+}
+EXPORT_SYMBOL_GPL(cs7542_fe_live_close);
+
+int cs7542_fe_live_status(struct cs7542_fe_live *owner,
+			  struct cs7542_fe_live_status *status)
+{
+	unsigned int index;
+
+	if (!owner || !status)
+		return -EINVAL;
+	mutex_lock(&owner->lock);
+	memset(status, 0, sizeof(*status));
+	status->epoch = owner->epoch;
+	status->online = owner->online;
+	status->closing = owner->closing;
+	status->reset_verified = owner->reset_verified;
+	status->poisoned = owner->backend.poisoned;
+	status->pending = owner->backend.pending;
+	status->first_error = owner->backend.first_error;
+	status->leases = owner->backend.next_lease;
+	status->capacity = CS_FE_BACKEND_LEASES;
+	status->admitted_requirements = owner->backend.admitted_requirements;
+	for (index = 0; index < CS_FE_BACKEND_BLOCKS; index++)
+		status->blocks += !!owner->backend.block[index].identity;
+	mutex_unlock(&owner->lock);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(cs7542_fe_live_status);
+
+void cs7542_fe_live_stop(struct cs7542_fe_live *owner)
+{
+	struct net_device *ports[CS_FE_LIVE_PORTS];
+	unsigned int index;
+
+	if (!owner)
+		return;
+	mutex_lock(&owner->lock);
+	owner->closing = true;
+	owner->online = false;
+	mutex_unlock(&owner->lock);
+	mutex_lock(&cs_fe_live_owners_lock);
+	mutex_lock(&owner->lock);
+#if !IS_ENABLED(CONFIG_CS7542_FE_HOT_BACKEND)
+	list_del_init(&owner->node);
+#endif
+	owner->online = false;
+	owner->closing = true;
+	owner->base = NULL;
+#if IS_ENABLED(CONFIG_CS7542_FE_HOT_BACKEND)
+	owner->hot_state.ledger.blocked = true;
+#endif
+	memcpy(ports, owner->ports, sizeof(ports));
+	memset(owner->ports, 0, sizeof(owner->ports));
+	mutex_unlock(&owner->lock);
+	mutex_unlock(&cs_fe_live_owners_lock);
+	for (index = 0; index < CS_FE_LIVE_PORTS; index++)
+		if (ports[index])
+			dev_put(ports[index]);
+}
+
+void cs7542_fe_live_reset_done(struct cs7542_fe_live *owner)
+{
+	bool drop = false;
+
+	if (!owner)
+		return;
+	mutex_lock(&owner->lock);
+	if (WARN_ON(!owner->closing))
+		goto unlock;
+	owner->reset_verified = true;
+	cs_fe_native_prune(owner);
+	owner->epoch++;
+	if (owner->quarantine_ref) {
+		owner->quarantine_ref = false;
+		drop = true;
+	}
+unlock:
+	mutex_unlock(&owner->lock);
+	if (drop)
+		cs7542_fe_live_put(owner);
+}
+
+#if CS_FE_NATIVE_AVAILABLE
+#include "cs_fe_native.inc"
+#endif
+
+#if IS_ENABLED(CONFIG_CS7542_FE_HOT_BACKEND)
+static bool cs_fe_live_hot_guards_ready(void *context, unsigned int slot)
+{
+	struct cs7542_fe_live *owner = context;
+	struct cs_fe_acl_guard *guard;
+
+	lockdep_assert_held(&owner->lock);
+	if (slot >= CS_FE_BACKEND_LEASES || owner->closing || !owner->base)
+		return false;
+	guard = &owner->guard[slot];
+	return guard->ready && guard->exposed && !guard->pending &&
+	       !guard->poisoned;
+}
+
+/* Same owner lock and original absolute deadline; no ACL writes/reallocation. */
+static int cs_fe_live_hot_guards_rebind(void *context, unsigned int slot,
+					const u32 *old_invalid,
+					const u32 *new_invalid,
+					unsigned long long end, bool commit)
+{
+	struct cs7542_fe_live *owner = context;
+	struct cs_fe_acl_guard *guard;
+	struct cs_fe_backend_io bounded;
+
+	lockdep_assert_held(&owner->lock);
+	if (!cs_fe_live_hot_guards_ready(context, slot))
+		return -EUCLEAN;
+	guard = &owner->guard[slot];
+	if (memcmp(guard->class_invalid, old_invalid,
+		   sizeof(guard->class_invalid)))
+		return -ESTALE;
+	bounded = cs_fe_live_io(owner);
+	bounded.limit_us = end;
+	if (!commit)
+		return cs_fe_acl_verify_retained(guard, &bounded, slot,
+						 5 + slot, old_invalid);
+	/*
+	 * Tables executor has just verified the complete new CLASS-invalid image.
+	 * Preserve every trap record and all error/history fields.
+	 */
+	if (guard->retained_records != 1 + 2 * CS_ACL_KINDS ||
+	    guard->retained[0].table != CS_ACL_CLASS ||
+	    guard->retained[0].row != 5 + slot ||
+	    guard->retained[0].complete != 20 || guard->retained[0].error ||
+	    memcmp(guard->retained[0].raw, old_invalid,
+		   sizeof(guard->class_invalid)))
+		return -EUCLEAN;
+	memcpy(guard->class_invalid, new_invalid, sizeof(guard->class_invalid));
+	memcpy(guard->retained[0].raw, new_invalid,
+	       sizeof(guard->class_invalid));
+	return 0;
+}
+
+int cs_fe_live_hot_idle(unsigned int *contexts, unsigned int *leases,
+			bool verify)
+{
+	struct cs7542_fe_live *owner;
+	int first = 0;
+
+	*contexts = *leases = 0;
+	mutex_lock(&cs_fe_live_owners_lock);
+	list_for_each_entry(owner, &cs_fe_live_owners, node) {
+		struct cs_fe_backend_io io;
+		unsigned int index;
+		int error = 0;
+
+		mutex_lock(&owner->lock);
+		(*contexts)++;
+		*leases += owner->backend.next_lease;
+		if (owner->reset_verified)
+			goto next; /* Actual full NE reset, not a module-reset fiction. */
+		if (owner->backend.pending || owner->backend.poisoned ||
+		    owner->hot_state.ledger.pending)
+			error = -EBUSY;
+		for (index = 0; !error && index < CS_FE_BACKEND_BLOCKS; index++)
+			if (owner->backend.block[index].identity)
+				error = -EBUSY;
+		for (index = 0; !error && index < CS_FE_BACKEND_ENTRIES;
+		     index++)
+			if (owner->backend.entry[index].active)
+				error = -EBUSY;
+		for (index = 0; !error && index < CS_FE_HOT_SLOTS; index++) {
+			if (owner->backend.lease[index].active ||
+			    owner->hot_state.binding[index].visible ||
+			    owner->hot_state.binding[index].hash_present)
+				error = -EBUSY;
+			if (owner->hot_state.ledger.slots[index].claimed &&
+			    (owner->closing || !owner->base || !owner->online))
+				error = -ESHUTDOWN;
+		}
+		if (!error && verify && owner->base && owner->online) {
+			io = cs_fe_live_io(owner);
+			error = cs_fe_hot_verify_idle(&owner->backend, &io);
+		}
+next:
+		mutex_unlock(&owner->lock);
+		if (error && !first)
+			first = error;
+	}
+	mutex_unlock(&cs_fe_live_owners_lock);
+	return first;
+}
+
+#endif
diff --git a/drivers/net/ethernet/cortina/cs7542_ft_live.c b/drivers/net/ethernet/cortina/cs7542_ft_live.c
new file mode 100644
index 000000000..d93b9198f
--- /dev/null
+++ b/drivers/net/ethernet/cortina/cs7542_ft_live.c
@@ -0,0 +1,415 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Private built-in attachment: standard DSA/conduit FT, no MMIO. */
+#include <linux/cs7542_ft_live.h>
+#include <linux/capability.h>
+#include <linux/err.h>
+#include <linux/kref.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/netdevice.h>
+#include <linux/slab.h>
+#include <net/flow_offload.h>
+#include <net/net_namespace.h>
+#include <net/pkt_cls.h>
+#define CS_LIVE_MAX_BINDINGS 32
+struct cs7542_ft_live {
+	struct kref refs;
+	struct net_device *conduit;
+	u32 gmac;
+	bool closing;
+	u64 replace, destroy, stats;
+};
+
+struct cs_live_binding {
+	struct list_head list;
+	struct cs7542_ft_live *live;
+
+	u64 identity;
+	u32 users;
+	bool opened, retired;
+};
+
+/*
+ * flow-block/RTNL -> live_lock -> provider FE owner. Module callbacks must
+ *
+ * resolve topology with rtnl_trylock only, never block on RTNL.
+ */
+static DEFINE_MUTEX(live_lock);
+static LIST_HEAD(live_callbacks);
+static LIST_HEAD(live_bindings);
+static const struct cs7542_ft_live_ops *provider_ops;
+static void *provider_context;
+static bool provider_closed;
+static bool format_blocked;
+static bool detach_available;
+static u64 next_identity;
+static u32 binding_count;
+static void live_free(struct kref *ref)
+{
+	struct cs7542_ft_live *live =
+		container_of(ref, struct cs7542_ft_live, refs);
+	WARN_ON(live->conduit);
+	kfree(live);
+}
+
+void cs7542_ft_live_put(struct cs7542_ft_live *live)
+{
+	if (live)
+		kref_put(&live->refs, live_free);
+}
+
+static void binding_free(struct cs_live_binding *binding)
+{
+	list_del(&binding->list);
+	binding_count--;
+	cs7542_ft_live_put(binding->live);
+	kfree(binding);
+}
+
+static int binding_close(struct cs_live_binding *binding)
+{
+	int error;
+
+	if (!binding->opened)
+		return 0;
+	if (WARN_ON(!provider_ops))
+		return -EUCLEAN;
+	error = provider_ops->close(provider_context, binding->identity);
+	if (!error)
+		binding->opened = false;
+	return error;
+}
+
+static void binding_release(void *private)
+{
+	struct cs_live_binding *binding = private;
+
+	mutex_lock(&live_lock);
+
+	binding->retired = true;
+	if (!binding_close(binding))
+		binding_free(binding);
+	else
+		provider_closed = true;
+	mutex_unlock(&live_lock);
+}
+
+static int live_rule(enum tc_setup_type type, void *data, void *private)
+{
+	struct cs_live_binding *binding = private;
+
+	struct flow_cls_offload *cls = data;
+	int error = -EOPNOTSUPP;
+
+	if (type != TC_SETUP_CLSFLOWER || !cls)
+		return -EOPNOTSUPP;
+	mutex_lock(&live_lock);
+	if (binding->retired || binding->live->closing || !provider_ops ||
+	    provider_closed || format_blocked)
+		goto out;
+	switch (cls->command) {
+	case FLOW_CLS_REPLACE:
+		binding->live->replace++;
+		break;
+	case FLOW_CLS_DESTROY:
+		binding->live->destroy++;
+		break;
+	case FLOW_CLS_STATS:
+		binding->live->stats++;
+		break;
+	default:
+		goto out;
+	}
+	if (!binding->opened) {
+		if (cls->command != FLOW_CLS_REPLACE) {
+			error = cls->command == FLOW_CLS_DESTROY ? -ENOENT :
+								   -EOPNOTSUPP;
+			goto out;
+		}
+		error = provider_ops->open(provider_context, binding->identity,
+					   binding->live->conduit);
+		if (error)
+			goto out;
+		binding->opened = true;
+	}
+	error = provider_ops->rule(provider_context, binding->identity, cls);
+out:
+	mutex_unlock(&live_lock);
+	return error;
+}
+
+int cs7542_ft_live_register(const struct cs7542_ft_live_ops *ops, void *context)
+{
+	int error = 0;
+
+	if (!ops || !ops->owner || !ops->name || !ops->open || !ops->rule ||
+	    !ops->close || !ops->detach ||
+	    ops->api_version != CS7542_FT_LIVE_API_VERSION ||
+	    ops->size != sizeof(*ops) || strnlen(ops->name, 32) == 32)
+		return -EINVAL;
+	mutex_lock(&live_lock);
+	if (!detach_available)
+		error = -ENODEV;
+	else if (provider_ops || format_blocked)
+		error = -EBUSY;
+	else if (!try_module_get(ops->owner))
+		error = -ENODEV;
+	else {
+		provider_context = context;
+		provider_ops = ops;
+		provider_closed = false;
+	}
+	mutex_unlock(&live_lock);
+	return error;
+}
+EXPORT_SYMBOL_GPL(cs7542_ft_live_register);
+
+static int detach_locked(void)
+{
+	struct cs_live_binding *binding, *next;
+	const struct cs7542_ft_live_ops *ops = provider_ops;
+	int first = 0, error;
+
+	if (!ops)
+		return 0;
+	provider_closed = true;
+	list_for_each_entry_safe(binding, next, &live_bindings, list) {
+		error = binding_close(binding);
+		if (error && !first)
+			first = error;
+		if (!error && binding->retired)
+			binding_free(binding);
+	}
+	error = ops->detach(provider_context);
+	if (error && !first)
+		first = error;
+	if (first)
+		return first; /* Uncertain remains closed and pinned. */
+	provider_ops = NULL;
+	provider_context = NULL;
+	module_put(ops->owner);
+	return 0;
+}
+
+int cs7542_ft_live_format_hold(void)
+{
+	int error;
+
+	mutex_lock(&live_lock);
+
+	format_blocked = true;
+	error = detach_locked();
+	mutex_unlock(&live_lock);
+	return error;
+}
+
+int cs7542_ft_live_format_release(void)
+{
+	int error = 0;
+
+	mutex_lock(&live_lock);
+
+	if (provider_ops)
+		error = -EBUSY;
+	else
+		format_blocked = false;
+	mutex_unlock(&live_lock);
+	return error;
+}
+
+bool cs7542_ft_live_format_held(void)
+{
+	bool held;
+
+	mutex_lock(&live_lock);
+
+	held = format_blocked && !provider_ops;
+	mutex_unlock(&live_lock);
+	return held;
+}
+
+int cs7542_ft_live_unregister(const struct cs7542_ft_live_ops *ops,
+			      void *context)
+{
+	int error;
+
+	if (!ops || !ops->owner)
+		return -EINVAL;
+	mutex_lock(&live_lock);
+	if (provider_ops != ops || provider_context != context)
+		error = -ENOENT;
+	else if (READ_ONCE(ops->owner->state) != MODULE_STATE_COMING)
+		error = -EPERM;
+	else
+		error = detach_locked();
+	mutex_unlock(&live_lock);
+	return error;
+}
+EXPORT_SYMBOL_GPL(cs7542_ft_live_unregister);
+
+struct cs7542_ft_live *cs7542_ft_live_create(struct net_device *conduit,
+					     u32 gmac)
+{
+	struct cs7542_ft_live *live;
+
+	if (!conduit || gmac != 1)
+		return ERR_PTR(-EOPNOTSUPP);
+	live = kzalloc_obj(*live);
+	if (!live)
+		return ERR_PTR(-ENOMEM);
+	kref_init(&live->refs);
+	dev_hold(conduit);
+	live->conduit = conduit;
+	live->gmac = gmac;
+	return live;
+}
+
+int cs7542_ft_live_setup(struct cs7542_ft_live *live, int type, void *data)
+{
+	struct flow_block_offload *block = data;
+	struct flow_block_cb *callback;
+	struct cs_live_binding *binding;
+	int error = 0;
+
+	if (!live || type != TC_SETUP_FT || !block ||
+	    block->binder_type != FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
+		return -EOPNOTSUPP;
+	mutex_lock(&live_lock);
+	block->driver_block_list = &live_callbacks;
+	switch (block->command) {
+	case FLOW_BLOCK_BIND:
+		if (live->closing || !block->net ||
+		    !net_eq(block->net, dev_net(live->conduit))) {
+			error = -ENODEV;
+			break;
+		}
+		callback = flow_block_cb_lookup(block->block, live_rule, live);
+		if (callback) {
+			binding = callback->cb_priv;
+			if (binding->users == U32_MAX) {
+				error = -EOVERFLOW;
+				break;
+			}
+			binding->users++;
+			break;
+		}
+		if (binding_count == CS_LIVE_MAX_BINDINGS ||
+		    next_identity == U64_MAX) {
+			error = -ENOSPC;
+			break;
+		}
+		binding = kzalloc(sizeof(*binding), GFP_KERNEL);
+		if (!binding) {
+			error = -ENOMEM;
+			break;
+		}
+		callback = flow_block_cb_alloc(live_rule, live, binding,
+					       binding_release);
+		if (IS_ERR(callback)) {
+			error = PTR_ERR(callback);
+			kfree(binding);
+			break;
+		}
+		binding->live = live;
+		binding->identity = ++next_identity;
+		binding->users = 1;
+		kref_get(&live->refs);
+		list_add_tail(&binding->list, &live_bindings);
+		binding_count++;
+		flow_block_cb_add(callback, block);
+		list_add_tail(&callback->driver_list, &live_callbacks);
+		break;
+	case FLOW_BLOCK_UNBIND:
+		callback = flow_block_cb_lookup(block->block, live_rule, live);
+		if (!callback) {
+			error = -ENOENT;
+			break;
+		}
+		binding = callback->cb_priv;
+		if (--binding->users)
+			break;
+		flow_block_cb_remove(callback, block);
+		list_del(&callback->driver_list);
+		break;
+	default:
+		error = -EOPNOTSUPP;
+	}
+	mutex_unlock(&live_lock);
+	return error;
+}
+
+int cs7542_ft_live_quiesce(struct cs7542_ft_live *live)
+{
+	struct cs_live_binding *binding;
+	struct net_device *conduit;
+	int first = 0, error;
+
+	if (!live)
+		return 0;
+	mutex_lock(&live_lock);
+	live->closing = true;
+	list_for_each_entry(binding, &live_bindings, list) {
+		if (binding->live != live)
+			continue;
+		error = binding_close(binding);
+		if (error && !first)
+			first = error;
+	}
+	if (first)
+		provider_closed = true;
+	conduit = live->conduit;
+	live->conduit = NULL;
+	mutex_unlock(&live_lock);
+	if (conduit)
+		dev_put(conduit);
+	return first;
+}
+
+ssize_t cs7542_ft_live_format(struct cs7542_ft_live *live, char *buffer)
+{
+	ssize_t length;
+
+	mutex_lock(&live_lock);
+
+	length =
+		live ? sysfs_emit(buffer,
+			       "CS_FT_LIVE_V1 gmac=%u closing=%u provider=%s closed=%u format_blocked=%u bindings=%u replace=%llu destroy=%llu stats=%llu\n",
+			       live->gmac, live->closing,
+			       provider_ops ? provider_ops->name : "none",
+			       provider_closed, format_blocked, binding_count,
+			       live->replace, live->destroy, live->stats) :
+		       -ENODEV;
+	mutex_unlock(&live_lock);
+	return length;
+}
+
+/* Built-in text survives dropping the provider's final reference. */
+
+static ssize_t detach_store(struct kobject *kobj, struct kobj_attribute *attr,
+			    const char *buffer, size_t count)
+{
+	int error;
+
+	if (!capable(CAP_NET_ADMIN))
+		return -EPERM;
+	if (!sysfs_streq(buffer, "detach"))
+		return -EINVAL;
+	mutex_lock(&live_lock);
+	error = detach_locked();
+	mutex_unlock(&live_lock);
+	return error ? error : count;
+}
+
+static struct kobj_attribute detach_attribute =
+
+	__ATTR(cs7542_ft_provider_detach, 0200, NULL, detach_store);
+static int __init live_init(void)
+{
+	int error = sysfs_create_file(kernel_kobj, &detach_attribute.attr);
+
+	if (!error)
+		detach_available = true;
+	return error;
+}
+
+subsys_initcall(live_init);
diff --git a/drivers/net/ethernet/cortina/cs_fe_acl_encode.c b/drivers/net/ethernet/cortina/cs_fe_acl_encode.c
new file mode 100644
index 000000000..09746fa5d
--- /dev/null
+++ b/drivers/net/ethernet/cortina/cs_fe_acl_encode.c
@@ -0,0 +1,124 @@
+// SPDX-License-Identifier: GPL-2.0
+#ifdef __KERNEL__
+#include <linux/errno.h>
+#include <linux/string.h>
+#else
+#include <errno.h>
+#include <string.h>
+#endif
+#include "cs_fe_acl_guard.h"
+/* Primary SDK descriptor offsets, DATA0 first; not ascending MMIO words. */
+static void field(u32 *out, unsigned int bit, unsigned int width, u32 value)
+{
+	unsigned int i;
+
+	for (i = 0; i < width; i++) {
+		unsigned int n = bit + i;
+		u32 mask = 1U << (n % 32);
+
+		out[n / 32] = (out[n / 32] & ~mask) |
+
+			      (((value >> i) & 1U) ? mask : 0);
+	}
+}
+
+static void parity(u32 *out, unsigned int words, unsigned int bit)
+{
+	unsigned int i, j, value = 0;
+
+	field(out, bit, 1, 0);
+
+	for (i = 0; i < words; i++)
+		for (j = 0; j < 32; j++)
+			value ^= (out[i] >> j) & 1U;
+	field(out, bit, 1, value);
+}
+
+int cs_fe_acl_encode(enum cs_fe_acl_kind kind, bool valid,
+		     unsigned int class_id, u32 rule[CS_ACL_RULE_WORDS],
+		     u32 action[CS_ACL_ACTION_WORDS])
+{
+	unsigned int i;
+
+	if ((unsigned int)kind >= CS_ACL_KINDS || class_id < 5 ||
+	    class_id >= 5 + CS_FE_BACKEND_LEASES || !rule || !action)
+		return -EINVAL;
+	/*
+	 * Preserve the actual SDK ff-initialized wildcard constructor, including
+	 * its named reserved_879_878 field. The serializer only fills bits0..881.
+	 * No general reserved/parity readback mask is accepted.
+	 */
+	for (i = 0; i < CS_ACL_RULE_WORDS; i++)
+		rule[i] = ~0U;
+	rule[27] = 0x0003ffffU;
+	field(rule, 23 * 32 + 27, 16, 0); /* NE_VEC */
+	field(rule, 19 * 32 + 31, 9, 0); /* IP_DA_MASK wildcard */
+	field(rule, 20 * 32 + 8, 9, 0); /* IP_SA_MASK wildcard */
+	if (kind == CS_ACL_TTL1 || kind == CS_ACL_TTL0) {
+		field(rule, 13 * 32 + 31, 8,
+		      kind == CS_ACL_TTL1 ? 1 : 0); /* TTL_HOPLMT */
+		field(rule, 20 * 32 + 29, 1, 0); /* TTL_HOPLMT_MASK */
+	} else {
+		field(rule, 13 * 32 + 10, 1, 1); /* IP_OPTIONS */
+		field(rule, 20 * 32 + 27, 1, 0); /* IP_OPTIONS_MASK */
+	}
+	/*
+	 * Experimental narrowing beyond the broad vendor exception: current
+	 * IPv4/class5/physical ingress1 only. Existing CLASS5 checks UDP tuple,
+	 * tag, DSCP0 and fragmentation; a CLASS result is NOT payload matching.
+	 * SDK DA_MAC_NO_MATCH callers establish class-hit/index selectors.
+	 */
+	field(rule, 4 * 32 + 23, 1, 1); /* IP_VLD */
+	field(rule, 19 * 32 + 29, 1, 0); /* IP_VLD_MASK */
+	field(rule, 4 * 32 + 24, 1, 0); /* IP_VER: IPv4 */
+	field(rule, 19 * 32 + 30, 1, 0); /* IP_VER_MASK */
+	field(rule, 16 * 32 + 8, 4, 1); /* LSPID */
+	field(rule, 21 * 32 + 3, 1, 0); /* LSPID_MASK */
+	field(rule, 17 * 32 + 4, 1, 1); /* CLASS_HIT */
+	field(rule, 21 * 32 + 25, 1, 0); /* CLASS_HIT_MASK */
+	field(rule, 17 * 32 + 5, 6, class_id); /* CLASS_SVIDX */
+	field(rule, 21 * 32 + 26, 1, 0); /* CLASS_SVIDX_MASK */
+	field(rule, 27 * 32 + 16, 1, valid); /* RULE_VLD, valid LAST */
+	parity(rule, CS_ACL_RULE_WORDS, 881);
+	memset(action, 0, CS_ACL_ACTION_WORDS * sizeof(*action));
+	/*
+	 * CPU56 is the current serviced destination, not vendor VOQ104.
+	 * Priority7 zero-valued overrides request cancellation, NOT a copy after
+	 * edits. Whether silicon applies them before modification is the test.
+	 */
+	field(action, 0, 1, 1); /* VOQ_VLD */
+	field(action, 1, 4, 7); /* VOQ_PRI */
+	field(action, 5, 8, 56); /* VOQ */
+	field(action, 13, 4, 3); /* LDPID */
+	field(action, 69, 1, 1); /* DROP_PERMIT_VLD */
+	field(action, 71, 1, 1); /* PERMIT */
+	field(action, 72, 4, 7); /* DROP_PERMIT_PRI */
+	field(action, 76, 1, 1); /* 8021P_1_VLD */
+	field(action, 80, 4, 7); /* 8021P_1_PRI */
+	field(action, 84, 1, 1); /* DEI_1_VLD */
+	field(action, 86, 4, 7); /* DEI_1_PRI */
+	field(action, 90, 1, 1); /* 8021P_2_VLD */
+	field(action, 95, 4, 7); /* 8021P_2_PRI */
+	field(action, 99, 1, 1); /* DEI_2_VLD */
+	field(action, 101, 4, 7); /* DEI_2_PRI */
+	field(action, 105, 1, 1); /* DSCP_VLD */
+	field(action, 112, 4, 7); /* DSCP_PRI */
+	field(action, 139, 1, 1); /* FIRST_VLAN_CMD_VLD */
+	field(action, 159, 4, 7); /* FIRST_VLAN_CMD_PRI */
+	field(action, 163, 1, 1); /* SECOND_VLAN_CMD_VLD */
+	field(action, 183, 4, 7); /* SECOND_VLAN_CMD_PRI */
+	field(action, 192, 1, 1); /* IP_SA_REPLACE_EN_VLD */
+	field(action, 194, 4, 7); /* IP_SA_REPLACE_EN_PRI */
+	field(action, 198, 1, 1); /* IP_DA_REPLACE_EN_VLD */
+	field(action, 200, 4, 7); /* IP_DA_REPLACE_EN_PRI */
+	field(action, 204, 1, 1); /* L4_SP_REPLACE_EN_VLD */
+	field(action, 222, 4, 7); /* L4_SP_REPLACE_EN_PRI */
+	field(action, 226, 1, 1); /* L4_DP_REPLACE_EN_VLD */
+	field(action, 244, 4, 7); /* L4_DP_REPLACE_EN_PRI */
+	field(action, 272, 1, 1); /* MAC_DA_SA_REPLACE_EN_VLD */
+	field(action, 275, 4, 7); /* MAC_DA_SA_REPLACE_EN_PRI */
+	field(action, 289, 1, 1); /* DECR_TTL_HOPLIMIT_VLD */
+	field(action, 291, 4, 7); /* DECR_TTL_HOPLIMIT_PRI */
+	parity(action, CS_ACL_ACTION_WORDS, 305);
+	return 0;
+}
diff --git a/drivers/net/ethernet/cortina/cs_fe_acl_guard.c b/drivers/net/ethernet/cortina/cs_fe_acl_guard.c
new file mode 100644
index 000000000..72be89368
--- /dev/null
+++ b/drivers/net/ethernet/cortina/cs_fe_acl_guard.c
@@ -0,0 +1,324 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "cs_fe_acl_guard.h"
+#ifdef __KERNEL__
+#include <linux/errno.h>
+#include <linux/string.h>
+#else
+#include <errno.h>
+#include <string.h>
+#endif
+#define ACL_START (1U << 31)
+#define ACL_WRITE (1U << 30)
+#define ACL_BUSY_US 1000U
+struct acl_table {
+	unsigned int access, words, parity;
+};
+
+static const struct acl_table tables[] = {
+	[CS_ACL_RULE] = { 0x138, 28, 881 },
+	[CS_ACL_ACTION] = { 0x1ac, 10, 305 },
+	[CS_ACL_CLASS] = { 0x54, 20, 629 },
+};
+
+static int before(const struct cs_fe_backend_io *io)
+{
+	return io->now_us(io->context) >= io->limit_us ? -ETIMEDOUT : 0;
+}
+
+static int idle(const struct cs_fe_backend_io *io, unsigned int access)
+{
+	unsigned long long start = io->now_us(io->context);
+	u32 value;
+	int error;
+
+	for (;;) {
+		error = before(io);
+		if (error)
+			return error;
+		error = io->read32(io->context, access, &value);
+		if (error)
+			return error;
+		if (!(value & ACL_START))
+			return before(io);
+		if (io->now_us(io->context) - start >= ACL_BUSY_US)
+			return -ETIMEDOUT;
+	}
+}
+
+static int read_record(const struct cs_fe_backend_io *io, unsigned int table,
+		       unsigned int row, struct cs_fe_acl_record *record)
+{
+	const struct acl_table *t;
+	unsigned int i;
+	int error;
+
+	if (table > CS_ACL_CLASS || row >= 64)
+		return -ERANGE;
+	t = &tables[table];
+	if (t->access + (t->words + 1) * 4 > io->extent)
+		return -ERANGE;
+	memset(record, 0, sizeof(*record));
+	record->table = table;
+	record->row = row;
+	record->words = t->words;
+	record->error = -EINPROGRESS;
+	error = idle(io, t->access);
+	if (error)
+		goto done;
+	error = before(io);
+	if (error)
+		goto done;
+	/* READ has bit30 clear; row bit6 is ALWAYS clear. */
+	error = io->write32(io->context, t->access, ACL_START | row);
+	if (error)
+		goto done;
+	error = idle(io, t->access);
+	if (error)
+		goto done;
+	for (i = 0; i < t->words; i++) {
+		error = before(io);
+		if (error)
+			goto done;
+		error = io->read32(io->context, t->access + (t->words - i) * 4,
+				   &record->raw[i]);
+		if (error)
+			goto done;
+		record->complete++;
+	}
+	error = before(io);
+done:
+	record->error = error;
+	return error;
+}
+
+static int read_entry(struct cs_fe_acl_guard *guard,
+		      const struct cs_fe_backend_io *io, unsigned int table,
+		      unsigned int row, struct cs_fe_acl_record **out)
+{
+	if (table > CS_ACL_CLASS || row >= 64 ||
+	    guard->records >= CS_ACL_RECORDS)
+		return -ERANGE;
+	*out = &guard->record[guard->records++];
+	return read_record(io, table, row, *out);
+}
+
+static int write_entry(struct cs_fe_acl_guard *guard,
+		       const struct cs_fe_backend_io *io, unsigned int table,
+		       unsigned int row, const u32 *expected, bool valid)
+{
+	const struct acl_table *t;
+	struct cs_fe_acl_record *record;
+	unsigned int i;
+	int error;
+
+	if (table > CS_ACL_ACTION || row >= 64)
+		return -EINVAL;
+	t = &tables[table];
+	guard->written = guard->pending =
+		true; /* BEFORE uncertain scratch data. */
+	error = idle(io, t->access);
+	if (error)
+		return error;
+	for (i = 0; i < t->words; i++) {
+		u32 word = expected[i];
+
+		error = before(io);
+		if (error)
+			return error;
+		/* Primary named parity only; strict full expected readback retained. */
+		if (i == t->parity / 32)
+			word &= ~(1U << (t->parity % 32));
+		error = io->write32(io->context, t->access + (t->words - i) * 4,
+				    word);
+		if (error)
+			return error;
+	}
+	error = before(io);
+	if (error)
+		return error;
+	if (valid)
+		guard->exposed = true; /* BEFORE uncertain valid command. */
+	error = io->write32(io->context, t->access,
+			    ACL_START | ACL_WRITE | row);
+	if (error)
+		return error;
+	error = idle(io, t->access);
+	if (error)
+		return error;
+	error = read_entry(guard, io, table, row, &record);
+	if (error)
+		return error;
+	if (memcmp(record->raw, expected, t->words * sizeof(u32))) {
+		record->error = -EBADMSG;
+		return -EBADMSG;
+	}
+	return 0;
+}
+
+static int fail(struct cs_fe_acl_guard *guard, int error)
+{
+	if (!guard->first_error)
+		guard->first_error = error;
+	guard->poisoned = true;
+	return error;
+}
+
+int cs_fe_acl_prepare(struct cs_fe_acl_guard *guard,
+		      const struct cs_fe_backend_io *io, unsigned int lease,
+		      unsigned int class_id, const u32 class_invalid[20])
+{
+	struct cs_fe_acl_record *record;
+	u32 rule[CS_ACL_RULE_WORDS], action[CS_ACL_ACTION_WORDS];
+	unsigned int table, kind, i;
+	int error;
+
+	if (!guard || !io || !io->now_us || !io->read32 || !io->write32 ||
+	    !io->limit_us || !class_invalid || lease >= CS_FE_BACKEND_LEASES ||
+	    class_id != 5 + lease || io->extent < 0x1d8)
+		return -EINVAL;
+	if (guard->attempted || guard->pending)
+		return -EBUSY;
+	guard->attempted = true;
+	guard->lease = lease;
+	guard->class_id = class_id;
+	memcpy(guard->class_invalid, class_invalid,
+	       sizeof(guard->class_invalid));
+	guard->first_row =
+		5 + lease * 3; /* 5..52, below the disputed address bit 6. */
+	/*
+	 * The scoped CLASS must be fresh/inactive before ANY ACL entry DATA write.
+	 * Sole owner mutex prevents it being published by another transaction.
+	 */
+	error = read_entry(guard, io, CS_ACL_CLASS, class_id, &record);
+	if (error)
+		return fail(guard, error);
+	if (memcmp(record->raw, class_invalid, sizeof(guard->class_invalid)) ||
+	    (record->raw[19] & (1U << 20)))
+		return fail(guard, -EEXIST);
+	for (table = CS_ACL_RULE; table <= CS_ACL_ACTION; table++)
+		for (kind = 0; kind < CS_ACL_KINDS; kind++) {
+			error = read_entry(guard, io, table,
+					   guard->first_row + kind, &record);
+			if (error)
+				return fail(guard, error);
+			for (i = 0; i < record->complete; i++)
+				if (record->raw[i])
+					return fail(guard, -EEXIST);
+		}
+	/*
+	 * Both actions first, then invalid rules, then valid rules. CLASS is still
+	 * inactive; its owner can publish it only after this full transaction.
+	 */
+	for (table = 0; table < 3; table++)
+		for (kind = 0; kind < CS_ACL_KINDS; kind++) {
+			error = cs_fe_acl_encode(kind, table == 2, class_id,
+						 rule, action);
+			if (error)
+				return fail(guard, error);
+			error = write_entry(guard, io,
+				table == 0 ? CS_ACL_ACTION : CS_ACL_RULE,
+				guard->first_row + kind,
+				table == 0 ? action : rule, table == 2);
+			if (error)
+				return fail(guard, error);
+		}
+	error = before(io);
+	if (error)
+		return fail(guard, error);
+	guard->pending = false;
+	guard->ready = true;
+	return 0;
+}
+
+int cs_fe_acl_verify_retained(struct cs_fe_acl_guard *guard,
+			      const struct cs_fe_backend_io *io,
+			      unsigned int lease, unsigned int class_id,
+			      const u32 class_invalid[20])
+{
+	struct cs_fe_acl_record *record;
+	u32 rule[CS_ACL_RULE_WORDS], action[CS_ACL_ACTION_WORDS];
+	unsigned int kind, table;
+	int error;
+
+	if (!guard || !io || !io->now_us || !io->read32 || !io->write32 ||
+	    !io->limit_us || !class_invalid || lease >= CS_FE_BACKEND_LEASES ||
+	    class_id != 5 + lease)
+		return -EINVAL;
+	if (!guard->attempted || !guard->written || !guard->ready ||
+	    guard->pending || guard->disarmed || guard->poisoned ||
+	    guard->lease != lease || guard->class_id != class_id ||
+	    guard->first_row != 5 + 3 * lease ||
+	    memcmp(guard->class_invalid, class_invalid,
+		   sizeof(guard->class_invalid)))
+		return fail(guard, -EUCLEAN);
+	guard->retained_records = 0;
+	record = &guard->retained[guard->retained_records++];
+	error = read_record(io, CS_ACL_CLASS, class_id, record);
+	if (!error && ((record->raw[19] & (1U << 20)) ||
+		       memcmp(record->raw, class_invalid,
+			      sizeof(guard->class_invalid)))) {
+		record->error = error = -EUCLEAN;
+	}
+	if (error)
+		return fail(guard, error);
+	for (kind = 0; kind < CS_ACL_KINDS; kind++) {
+		error = cs_fe_acl_encode(kind, true, class_id, rule, action);
+		if (error)
+			return fail(guard, error);
+		for (table = CS_ACL_RULE; table <= CS_ACL_ACTION; table++) {
+			record = &guard->retained[guard->retained_records++];
+			error = read_record(io, table, guard->first_row + kind,
+					    record);
+			if (!error &&
+			    memcmp(record->raw,
+				   table == CS_ACL_RULE ? rule : action,
+				   tables[table].words * sizeof(u32)))
+				record->error = error = -EUCLEAN;
+			if (error)
+				return fail(guard, error);
+		}
+	}
+	if (guard->retained_checks != ~0U)
+		guard->retained_checks++;
+	return 0;
+}
+
+int cs_fe_acl_disarm(struct cs_fe_acl_guard *guard,
+		     const struct cs_fe_backend_io *io)
+{
+	struct cs_fe_acl_record *record;
+	u32 rule[CS_ACL_RULE_WORDS], action[CS_ACL_ACTION_WORDS];
+	unsigned int kind;
+	int first = 0, error;
+
+	if (!guard || !io || !io->limit_us || !guard->attempted)
+		return -EINVAL;
+	if (!guard->written || guard->disarmed)
+		return 0;
+	error = read_entry(guard, io, CS_ACL_CLASS, guard->class_id, &record);
+	if (error)
+		return fail(guard, error);
+	if (memcmp(record->raw, guard->class_invalid,
+		   sizeof(guard->class_invalid)) ||
+	    (record->raw[19] & (1U << 20)))
+		return fail(guard,
+			-EBUSY); /* Guard never removed under active CLASS. */
+	guard->pending = true;
+	for (kind = 0; kind < CS_ACL_KINDS; kind++) {
+		error = cs_fe_acl_encode(kind, false, guard->class_id, rule,
+					 action);
+		if (!error)
+			error = write_entry(guard, io, CS_ACL_RULE,
+					    guard->first_row + kind, rule,
+					    false);
+		if (error && !first)
+			first = error; /* Attempt BOTH rules; never delete/reuse ACTION. */
+	}
+	if (first)
+		return fail(guard, first);
+	guard->pending = guard->ready = false;
+	guard->disarmed = true;
+	return 0;
+}
+
+#include "cs_fe_native_mtu.inc"
diff --git a/drivers/net/ethernet/cortina/cs_fe_acl_guard.h b/drivers/net/ethernet/cortina/cs_fe_acl_guard.h
new file mode 100644
index 000000000..09fab9e3b
--- /dev/null
+++ b/drivers/net/ethernet/cortina/cs_fe_acl_guard.h
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef CS_FE_ACL_GUARD_H
+#define CS_FE_ACL_GUARD_H
+#include "cs_fe_backend.h"
+#define CS_ACL_RULE_WORDS 28U
+#define CS_ACL_ACTION_WORDS 10U
+#define CS_ACL_RECORDS 32U
+/* Address0..63 is common to BOTH primary layouts; no table-depth claim. */
+enum cs_fe_acl_kind { CS_ACL_TTL1, CS_ACL_OPTIONS, CS_ACL_TTL0, CS_ACL_KINDS };
+enum cs_fe_acl_table { CS_ACL_RULE, CS_ACL_ACTION, CS_ACL_CLASS };
+struct cs_fe_acl_record {
+	u32 table, row, words, complete;
+	int error;
+	u32 raw[CS_ACL_RULE_WORDS];
+};
+
+struct cs_fe_acl_guard {
+	bool attempted, written, exposed, pending, ready, disarmed, poisoned;
+	int first_error;
+	u32 lease, class_id, first_row, records;
+	u32 class_invalid[20];
+	struct cs_fe_acl_record record[CS_ACL_RECORDS];
+	u32 retained_records, retained_checks;
+	struct cs_fe_acl_record retained[1 + 2 * CS_ACL_KINDS];
+};
+
+int cs_fe_acl_encode(enum cs_fe_acl_kind kind, bool valid,
+		     unsigned int class_id, u32 rule[CS_ACL_RULE_WORDS],
+		     u32 action[CS_ACL_ACTION_WORDS]);
+/*
+ * Internal only. Caller owns the SAME FE mutex throughout. lease0..7 maps
+ * only to own CLASS5..12 and ACL5..28. No arbitrary selector crosses ABI.
+ */
+int cs_fe_acl_prepare(struct cs_fe_acl_guard *guard,
+		      const struct cs_fe_backend_io *io, unsigned int lease,
+		      unsigned int class_id, const u32 class_invalid[20]);
+/*
+ * READ ONLY: scoped traps stay installed permanently under inactive CLASS.
+ * Finite latest verification journal does not exhaust the prepare journal.
+ */
+int cs_fe_acl_verify_retained(struct cs_fe_acl_guard *guard,
+			      const struct cs_fe_backend_io *io,
+			      unsigned int lease, unsigned int class_id,
+			      const u32 class_invalid[20]);
+int cs_fe_acl_disarm(struct cs_fe_acl_guard *guard,
+		     const struct cs_fe_backend_io *io);
+#endif
diff --git a/drivers/net/ethernet/cortina/cs_fe_backend.h b/drivers/net/ethernet/cortina/cs_fe_backend.h
new file mode 100644
index 000000000..5fd3cf101
--- /dev/null
+++ b/drivers/net/ethernet/cortina/cs_fe_backend.h
@@ -0,0 +1,228 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef CS_FE_BACKEND_H
+#define CS_FE_BACKEND_H
+#include "cs_fe_encode.h"
+
+#define CS_FE_BACKEND_BLOCKS 4
+#define CS_FE_BACKEND_ACTIONS 8
+#define CS_FE_BACKEND_LEASES 16
+#define CS_FE_BACKEND_ENTRIES CS_FE_BACKEND_LEASES
+#define CS_FE_BACKEND_WORDS 20
+#define CS_FE_BACKEND_US 1000000ULL
+
+enum cs_fe_backend_table_id {
+	CS_BE_CLASS,
+	CS_BE_SDB,
+	CS_BE_FWD,
+	CS_BE_VOQ,
+	CS_BE_MASK,
+	CS_BE_HASH,
+	CS_BE_OVERFLOW,
+	CS_BE_L2,
+	CS_BE_L3,
+	CS_BE_FVLAN,
+	CS_BE_TABLES,
+};
+
+struct cs_fe_backend_table {
+	unsigned int access, rows, words;
+	int parity;
+};
+
+extern const struct cs_fe_backend_table cs_fe_backend_tables[CS_BE_TABLES];
+
+/*
+ * The actual sole FE owner mutex covers EACH entire operation. The host model
+ * supplies the same caller serialization. No caller may access FE scratch in
+ * parallel, or free/reinitialize this context while block callbacks exist.
+ */
+#ifndef CS_FE_HOT_SELECTOR_DEFINED
+#define CS_FE_HOT_SELECTOR_DEFINED
+struct cs_fe_hot_selector {
+	u8 source[6], destination[6];
+	bool valid;
+};
+
+#endif
+struct cs_fe_hot_state;
+struct cs_fe_rule;
+struct cs_fe_key_policy;
+struct cs_fe_rows;
+struct cs_fe_plan;
+#define CS_FE_BACKEND_IO_ABI 3U
+struct cs_fe_backend_io {
+	unsigned int abi, size;
+	struct cs_fe_hot_selector selector;
+	void *context;
+	unsigned int extent;
+	unsigned long long (*now_us)(void *context);
+	int (*read32)(void *context, unsigned int offset, u32 *value);
+	int (*write32)(void *context, unsigned int offset, u32 value);
+	unsigned long long limit_us; /* Absolute programming limit;0 permits cleanup. */
+	/* Hot backend receives only these typed hooks; raw read32/write32 are NULL. */
+	int (*table_read)(void *context, unsigned int table, unsigned int row,
+			  unsigned long long end);
+	int (*table_write)(void *context, unsigned int table, unsigned int row, const u32 *input,
+			   const u32 *expected, unsigned long long end);
+	int (*claim)(void *context, unsigned int lease, const struct cs_fe_rule *rule,
+		     const struct cs_fe_key_policy *policy, const struct cs_fe_rows *rows,
+		     const struct cs_fe_plan *plan);
+	int (*engine_status)(void *context, u32 *status, u32 *mask, unsigned long long end);
+	int (*rebind)(void *context, unsigned int lease, const struct cs_fe_rule *rule,
+		      const struct cs_fe_key_policy *policy,
+		      const struct cs_fe_plan *plan, unsigned long long end);
+	int (*receipt)(void *context, unsigned int lease, struct cs_fe_plan *plan);
+	/* Owner selects both physical row sets from its own validated request. */
+	int (*placement)(void *context, unsigned int selector, struct cs_fe_rows *rows,
+			 bool *shared);
+	/* Cuts only a failed member of a shared result. Success is verified in FE. */
+	int (*isolate)(void *context, unsigned int selector);
+};
+
+struct cs_fe_backend_diag {
+	unsigned int table, row, words, complete;
+	int error;
+	u32 raw[CS_FE_BACKEND_WORDS];
+};
+
+struct cs_fe_backend_entry {
+	unsigned long long block, version;
+	unsigned long cookie;
+	unsigned int lease;
+	bool occupied, active;
+};
+
+struct cs_fe_backend_encoding {
+	struct cs_fe_key key;
+	u32 mask[5], action[4];
+	bool guarded; /* Internal validated manual request, not module bytes. */
+	bool exact_class, negative_class;
+	unsigned int class_match;
+};
+
+struct cs_fe_backend_lease {
+	bool reserved, submitted, active, marker, guarded, scoped, scope_exact;
+	bool rearmable, shared_result;
+	unsigned int scope_grant;
+	struct cs_fe_rule rule;
+	struct cs_fe_key_policy policy;
+	struct cs_fe_rows rows;
+	struct cs_fe_plan plan;
+};
+
+struct cs_fe_backend_block {
+	unsigned long long identity, rejected_through;
+	bool closed;
+};
+
+struct cs_fe_backend {
+	struct cs_fe_hot_state *hot_state;
+	int (*guard_prepare)(void *context, const struct cs_fe_backend_io *io,
+			     unsigned int lease, const struct cs_fe_rows *rows,
+			     const struct cs_fe_plan *plan,
+			     unsigned long long end_us);
+	int (*guard_withdraw)(void *context, const struct cs_fe_backend_io *io,
+			      unsigned int lease, const struct cs_fe_rows *rows,
+			      const struct cs_fe_plan *plan,
+			      unsigned long long end_us);
+	int (*guard_rearm)(void *context, const struct cs_fe_backend_io *io,
+			   unsigned int lease, const struct cs_fe_rows *rows,
+			   const struct cs_fe_plan *plan,
+			   unsigned long long end_us);
+	void (*before_withdraw)(void *context,
+				const struct cs_fe_backend_io *io,
+				unsigned int lease,
+				const struct cs_fe_plan *plan,
+				unsigned long long end_us);
+	void *guard_context;
+	void (*observe)(void *context, const struct cs_fe_backend_diag *record);
+	void *observe_context;
+	bool initialized, poisoned, pending;
+	int first_error;
+	u32 status, init;
+	unsigned int admitted_requirements, next_lease, immutable_rearms;
+	unsigned long long next_block;
+	struct cs_fe_backend_block block[CS_FE_BACKEND_BLOCKS];
+	struct cs_fe_backend_entry entry[CS_FE_BACKEND_ENTRIES];
+	struct cs_fe_backend_lease lease[CS_FE_BACKEND_LEASES];
+	struct cs_fe_backend_diag last;
+};
+
+/*
+ * No live reset/reinit/free API: leases, including withdrawn/failed ones, stay
+ *
+ * owned until actual full NE reset and callback drain. These APIs do not prove
+ * a pipeline retirement fence. Serial is a PRIVATE desired-version guard,
+ * never a generation supplied by upstream FLOW_CLS_DESTROY. The provider
+ * allocates versions from ONE monotonic counter before validating any cookie.
+ * Unknown rejections advance a conservative block-wide fence for pending
+ * older versions without allocating cookie tombstones or hardware leases.
+ */
+int cs_fe_backend_init(struct cs_fe_backend *backend,
+		       unsigned int requirements);
+int cs_fe_backend_replace_native(struct cs_fe_backend *backend,
+				 const struct cs_fe_backend_io *io,
+				 unsigned long long block, unsigned long cookie,
+				 unsigned long long version,
+				 const struct cs_fe_rule *rule,
+				 const struct cs_fe_key_policy *policy);
+int cs_fe_backend_block_open(struct cs_fe_backend *backend,
+			     unsigned long long *handle);
+int cs_fe_backend_marker_encoded(struct cs_fe_backend *backend,
+				 const struct cs_fe_backend_io *io,
+				 unsigned long long block, unsigned long cookie,
+				 unsigned long long version,
+				 const struct cs_fe_rule *rule,
+				 const struct cs_fe_key_policy *policy,
+				 const struct cs_fe_backend_encoding *encoding);
+int cs_fe_backend_marker(struct cs_fe_backend *backend,
+			 const struct cs_fe_backend_io *io,
+			 unsigned long long block, unsigned long cookie,
+			 unsigned long long version,
+			 const struct cs_fe_rule *rule,
+			 const struct cs_fe_key_policy *policy);
+/*
+ * Internal sole-owner entrypoint; caller must validate scoped policy.
+ * Still checks backend requirements; this is not a policy bypass.
+ */
+/* Internal verified-scope call only; not exported to loadable providers. */
+int cs_fe_backend_replace_scoped(struct cs_fe_backend *backend,
+				 const struct cs_fe_backend_io *io,
+				 unsigned long long block, unsigned long cookie,
+				 unsigned long long version,
+				 const struct cs_fe_rule *rule,
+				 const struct cs_fe_key_policy *policy,
+				 bool exact_ingress);
+int cs_fe_backend_replace_guarded(struct cs_fe_backend *backend,
+				  const struct cs_fe_backend_io *io,
+				  unsigned long long block,
+				  unsigned long cookie,
+				  unsigned long long version,
+				  const struct cs_fe_rule *rule,
+				  const struct cs_fe_key_policy *policy);
+int cs_fe_backend_replace(struct cs_fe_backend *backend,
+			  const struct cs_fe_backend_io *io,
+			  unsigned long long block, unsigned long cookie,
+			  unsigned long long version,
+			  const struct cs_fe_rule *rule,
+			  const struct cs_fe_key_policy *policy);
+int cs_fe_backend_reject(struct cs_fe_backend *backend,
+			 const struct cs_fe_backend_io *io,
+			 unsigned long long block, unsigned long cookie,
+			 unsigned long long version, int reason);
+/*
+ * DESTROY accepts the registry-snapshotted current version or newer, not an
+ * invented upstream generation. Repeat of a retired current version is0.
+ */
+int cs_fe_backend_destroy(struct cs_fe_backend *backend,
+			  const struct cs_fe_backend_io *io,
+			  unsigned long long block, unsigned long cookie,
+			  unsigned long long version);
+int cs_fe_backend_next_rows(const struct cs_fe_backend *backend,
+			    struct cs_fe_rows *rows);
+int cs_fe_backend_forget(struct cs_fe_backend *backend,
+			 unsigned long long block);
+int cs_fe_backend_unbind(struct cs_fe_backend *backend,
+			 const struct cs_fe_backend_io *io,
+			 unsigned long long block);
+#endif
diff --git a/drivers/net/ethernet/cortina/cs_fe_backend_algorithm.c b/drivers/net/ethernet/cortina/cs_fe_backend_algorithm.c
new file mode 100644
index 000000000..5df711540
--- /dev/null
+++ b/drivers/net/ethernet/cortina/cs_fe_backend_algorithm.c
@@ -0,0 +1,976 @@
+// SPDX-License-Identifier: GPL-2.0
+#ifndef CS_FE_HOT_REARM
+#define CS_FE_HOT_REARM 1
+#endif
+/* Private direction backend. No callback registration/capability/statistics. */
+#ifdef __KERNEL__
+#include <linux/errno.h>
+#include <linux/string.h>
+#else
+#include <errno.h>
+#include <string.h>
+#endif
+#define cs_fe_backend_init hot_cs_fe_backend_init
+#define cs_fe_backend_block_open hot_cs_fe_backend_block_open
+#define cs_fe_backend_next_rows hot_cs_fe_backend_next_rows
+#define cs_fe_backend_replace hot_cs_fe_backend_replace
+#define cs_fe_backend_replace_scoped hot_cs_fe_backend_replace_scoped
+#define cs_fe_backend_replace_guarded hot_cs_fe_backend_replace_guarded
+#define cs_fe_backend_marker hot_cs_fe_backend_marker
+#define cs_fe_backend_marker_encoded hot_cs_fe_backend_marker_encoded
+#define cs_fe_backend_destroy hot_cs_fe_backend_destroy
+#define cs_fe_backend_reject hot_cs_fe_backend_reject
+#define cs_fe_backend_unbind hot_cs_fe_backend_unbind
+#define cs_fe_backend_forget hot_cs_fe_backend_forget
+#define cs_fe_backend_tables hot_algorithm_tables
+#include "cs_fe_backend.h"
+#include "cs_fe_hot_compare.h"
+
+/* Exact proven indirect layout; DATA0 is the highest DATA address. */
+const struct cs_fe_backend_table cs_fe_backend_tables[CS_BE_TABLES] = {
+	[CS_BE_CLASS] = { 0x0054, 64, 20, 629 },
+	[CS_BE_SDB] = { 0x00a8, 64, 7, 206 },
+	[CS_BE_FWD] = { 0x00d4, 8192, 4, 113 },
+	[CS_BE_VOQ] = { 0x00f4, 512, 2, 40 },
+	[CS_BE_MASK] = { 0x2068, 64, 5, 149 },
+	[CS_BE_HASH] = { 0x201c, 12288, 4, -1 },
+	[CS_BE_OVERFLOW] = { 0x203c, 64, 2, -1 },
+	[CS_BE_L2] = { 0x0124, 512, 4, 96 },
+	[CS_BE_L3] = { 0x010c, 1024, 5, 128 },
+	[CS_BE_FVLAN] = { 0x0100, 512, 2, 38 },
+};
+
+#define CS_BE_START (1U << 31)
+#define CS_BE_WRITE (1U << 30)
+
+static unsigned int cs_be_parity(u32 value)
+{
+	unsigned int parity = 0;
+
+	while (value) {
+		parity ^= value & 1;
+		value >>= 1;
+	}
+	return parity;
+}
+
+static int cs_be_read(struct cs_fe_backend *backend,
+		      const struct cs_fe_backend_io *io, unsigned int table,
+		      unsigned int row, unsigned long long end)
+{
+	(void)backend;
+	return io->table_read(io->context, table, row, end);
+}
+
+static int cs_be_compare(struct cs_fe_backend *backend,
+			 const struct cs_fe_backend_io *io, unsigned int id,
+			 unsigned int row, const u32 *expected,
+			 unsigned long long end)
+{
+	int error = cs_be_read(backend, io, id, row, end);
+
+	if (!error && memcmp(backend->last.raw, expected,
+			     cs_fe_backend_tables[id].words * sizeof(u32))) {
+		backend->last.error = -EUCLEAN;
+		error = -EUCLEAN;
+	}
+	return error;
+}
+
+static int cs_be_write(struct cs_fe_backend *backend,
+		       const struct cs_fe_backend_io *io, unsigned int table,
+		       unsigned int row, const u32 *input, const u32 *expected,
+		       unsigned long long end)
+{
+	(void)backend;
+	return io->table_write(io->context, table, row, input, expected, end);
+}
+
+static int cs_be_fail(struct cs_fe_backend *backend, int error)
+{
+	if (!backend->first_error)
+		backend->first_error = error;
+	backend->poisoned = true;
+	return error;
+}
+
+static int cs_be_io(const struct cs_fe_backend_io *io)
+{
+	return !io || io->abi != CS_FE_BACKEND_IO_ABI ||
+			       io->size != sizeof(*io) || !io->now_us ||
+			       !io->table_read || !io->table_write ||
+			       !io->claim || !io->engine_status ||
+			       io->extent < 0x2080 ?
+		       -EINVAL :
+		       0;
+}
+
+static int cs_be_block(struct cs_fe_backend *backend, unsigned long long handle)
+{
+	unsigned int index;
+
+	if (!backend->initialized || !handle)
+		return -ENODEV;
+	for (index = 0; index < CS_FE_BACKEND_BLOCKS; index++)
+		if (backend->block[index].identity == handle)
+			return backend->block[index].closed ? -ESHUTDOWN :
+							      (int)index;
+	return -ENOENT;
+}
+
+static struct cs_fe_backend_entry *cs_be_entry(struct cs_fe_backend *backend,
+					       unsigned long long block,
+					       unsigned long cookie,
+					       bool allocate)
+{
+	struct cs_fe_backend_entry *free = NULL;
+	unsigned int index;
+
+	for (index = 0; index < CS_FE_BACKEND_ENTRIES; index++) {
+		struct cs_fe_backend_entry *entry = &backend->entry[index];
+
+		if (entry->occupied && entry->block == block &&
+		    entry->cookie == cookie)
+			return entry;
+		if (!entry->occupied && !free)
+			free = entry;
+	}
+	if (!allocate || !free)
+		return NULL;
+	*free = (struct cs_fe_backend_entry){ .occupied = true,
+					      .block = block,
+					      .cookie = cookie };
+	return free;
+}
+
+static bool cs_be_tuple_equal(const struct cs_fe_tuple *a,
+			      const struct cs_fe_tuple *b)
+{
+	return a->src == b->src && a->dst == b->dst && a->sport == b->sport &&
+	       a->dport == b->dport;
+}
+
+static bool cs_be_link_equal(const struct cs_fe_link *a,
+			     const struct cs_fe_link *b)
+{
+	return a->gmac == b->gmac && a->tag_mode == b->tag_mode &&
+	       a->switch_port == b->switch_port && a->cpu_port == b->cpu_port &&
+	       a->base_voq == b->base_voq && a->rx_qca_meta == b->rx_qca_meta &&
+	       !memcmp(a->base_mac, b->base_mac, 6);
+}
+
+static bool cs_be_equal(const struct cs_fe_backend_lease *lease,
+			const struct cs_fe_rule *rule,
+			const struct cs_fe_key_policy *policy)
+{
+	return cs_fe_l4proto(&lease->rule, &lease->policy) ==
+		       cs_fe_l4proto(rule, policy) &&
+	       cs_be_tuple_equal(&lease->rule.original, &rule->original) &&
+	       cs_be_tuple_equal(&lease->rule.translated, &rule->translated) &&
+	       cs_be_link_equal(&lease->rule.ingress, &rule->ingress) &&
+	       cs_be_link_equal(&lease->rule.egress, &rule->egress) &&
+	       lease->rule.decrement_ttl == rule->decrement_ttl &&
+	       !memcmp(lease->rule.smac, rule->smac, 6) &&
+	       !memcmp(lease->rule.dmac, rule->dmac, 6) &&
+	       lease->policy.exact_dscp == policy->exact_dscp &&
+	       lease->policy.dscp == policy->dscp &&
+	       lease->policy.require_mtu_range == policy->require_mtu_range;
+}
+
+static bool cs_be_overlap(const struct cs_fe_rule *a,
+			  const struct cs_fe_rule *b)
+{
+	/* Codec CLASS is coarse: distinct IPs do NOT make these selectors disjoint. */
+	return a->ingress.gmac == b->ingress.gmac &&
+	       a->ingress.tag_mode == b->ingress.tag_mode &&
+	       (a->ingress.rx_qca_meta & 0xefff) ==
+		       (b->ingress.rx_qca_meta & 0xefff) &&
+	       a->original.sport == b->original.sport &&
+	       a->original.dport == b->original.dport;
+}
+
+static int cs_be_withdraw(struct cs_fe_backend *backend,
+			  const struct cs_fe_backend_io *io,
+			  struct cs_fe_backend_entry *entry,
+			  unsigned long long end)
+{
+	struct cs_fe_backend_lease *lease;
+	u32 zero[20] = { 0 };
+	int error;
+
+	if (!entry->active)
+		return 0;
+	lease = &backend->lease[entry->lease];
+	if (backend->before_withdraw)
+		backend->before_withdraw(backend->guard_context, io,
+					 entry->lease, &lease->plan, end);
+	error = cs_be_compare(backend, io, CS_BE_HASH, lease->plan.key.bucket,
+			      lease->plan.hash, end);
+	if (!error)
+		error = cs_be_compare(backend, io, CS_BE_CLASS,
+				      lease->rows.class_row,
+				      lease->plan.class_valid.expected, end);
+	if (!error)
+		error = cs_be_write(backend, io, CS_BE_HASH,
+				    lease->plan.key.bucket, zero, zero, end);
+	if (!error)
+		error = cs_be_write(backend, io, CS_BE_CLASS,
+				    lease->rows.class_row,
+				    lease->plan.class_invalid.input,
+				    lease->plan.class_invalid.expected, end);
+	if (!error && lease->guarded) {
+		if (!backend->guard_withdraw)
+			error = -EOPNOTSUPP;
+		else
+			error = backend->guard_withdraw(backend->guard_context,
+							io, entry->lease,
+							&lease->rows,
+							&lease->plan, end);
+	}
+	if (error) {
+		if (!io->isolate || io->isolate(io->context, entry->lease))
+			return cs_be_fail(backend, error);
+		entry->active = false;
+		lease->active = false;
+		lease->rearmable = false;
+		return 0;
+	}
+	entry->active = false;
+	lease->active = false;
+	lease->rearmable = lease->scoped && lease->guarded && !lease->marker &&
+			   backend->guard_rearm;
+	/* No dependency, bucket or reservation is freed/reused, even after success. */
+	return 0;
+}
+
+static int cs_be_program(struct cs_fe_backend *backend,
+			 const struct cs_fe_backend_io *io,
+			 struct cs_fe_backend_lease *lease,
+			 unsigned long long end)
+{
+	const struct cs_fe_rows *rows = &lease->rows;
+	const struct cs_fe_plan *plan = &lease->plan;
+	u32 zero[20] = { 0 }, cpu_voq[2] = { 56, 1U << 8 };
+	unsigned int index;
+	int error;
+
+	/* Exact closed-profile prestate; never repair or enable another owner. */
+	error = io->engine_status(io->context, &backend->status, &backend->init,
+				  end);
+	if (!error && (backend->status != 2 || backend->init))
+		error = -EUCLEAN;
+	/* Freshly verify the physically proven CPU fallback reference. */
+	if (!error)
+		error = cs_be_compare(backend, io, CS_BE_VOQ, 2, cpu_voq, end);
+#define CS_BE_FRESH(table, row)                                              \
+	do {                                                                 \
+		if (!error)                                                  \
+			error = cs_be_compare(backend, io, table, row, zero, \
+					      end);                          \
+	} while (0)
+	CS_BE_FRESH(CS_BE_CLASS, rows->class_row);
+	CS_BE_FRESH(CS_BE_SDB, rows->sdb_row);
+	CS_BE_FRESH(CS_BE_MASK, rows->mask_row);
+	CS_BE_FRESH(CS_BE_FWD, rows->miss_fwd);
+	if (!lease->shared_result) {
+		CS_BE_FRESH(CS_BE_FWD, rows->hit_fwd);
+		CS_BE_FRESH(CS_BE_VOQ, rows->voq);
+		CS_BE_FRESH(CS_BE_L2, rows->l2);
+		CS_BE_FRESH(CS_BE_L3, rows->l3);
+		CS_BE_FRESH(CS_BE_FVLAN, rows->fvlan);
+	}
+	for (index = 0; index < 3; index++)
+		CS_BE_FRESH(CS_BE_HASH, plan->key.bucket + index * 4096);
+	for (index = 0; index < 64; index++)
+		CS_BE_FRESH(CS_BE_OVERFLOW, index);
+#undef CS_BE_FRESH
+	if (error)
+		return error;
+	lease->submitted = true;
+#define CS_BE_PROGRAM_IMAGE(table, row, image)                          \
+	do {                                                            \
+		if (!error)                                             \
+			error = cs_be_write(backend, io, table, row,    \
+					    plan->image.input,          \
+					    plan->image.expected, end); \
+	} while (0)
+	if (!lease->shared_result) {
+		CS_BE_PROGRAM_IMAGE(CS_BE_VOQ, rows->voq, voq);
+		CS_BE_PROGRAM_IMAGE(CS_BE_L2, rows->l2, l2);
+		if (plan->write_l3)
+			CS_BE_PROGRAM_IMAGE(CS_BE_L3, rows->l3, l3);
+		if (plan->write_fvlan)
+			CS_BE_PROGRAM_IMAGE(CS_BE_FVLAN, rows->fvlan, fvlan);
+		CS_BE_PROGRAM_IMAGE(CS_BE_FWD, rows->hit_fwd, hit);
+	}
+	CS_BE_PROGRAM_IMAGE(CS_BE_FWD, rows->miss_fwd, miss);
+	CS_BE_PROGRAM_IMAGE(CS_BE_MASK, rows->mask_row, mask);
+	CS_BE_PROGRAM_IMAGE(CS_BE_SDB, rows->sdb_row, sdb);
+	CS_BE_PROGRAM_IMAGE(CS_BE_CLASS, rows->class_row, class_invalid);
+	if (!error && lease->guarded) {
+		if (!backend->guard_prepare)
+			error = -EOPNOTSUPP;
+		else
+			error = backend->guard_prepare(backend->guard_context,
+						       io,
+						       lease - backend->lease,
+						       rows, plan, end);
+	}
+	if (!error)
+		error = cs_be_write(backend, io, CS_BE_HASH, plan->key.bucket,
+				    plan->hash, plan->hash, end);
+	CS_BE_PROGRAM_IMAGE(CS_BE_CLASS, rows->class_row, class_valid);
+#undef CS_BE_PROGRAM_IMAGE
+	return error;
+}
+
+/*
+ * Unknown rejected cookies use one conservative block-wide version fence,
+ * not a metadata/physical lease. Older pending finishes may lose admission,
+ * but must not preserve an obsolete active version of that same cookie.
+ */
+static int cs_be_rejected(struct cs_fe_backend *backend, unsigned int block,
+			  unsigned long long version, int error)
+{
+	if (backend->block[block].rejected_through < version)
+		backend->block[block].rejected_through = version;
+	return error;
+}
+
+/*
+ * Retired cookie metadata is not a physical resource. Keep a block-wide
+ * monotonic floor so evicting it cannot let an older pending finish reappear.
+ * Known independent active DESTROY is still checked against its own version.
+ */
+static void cs_be_retire_cookie(struct cs_fe_backend *backend,
+				struct cs_fe_backend_entry *entry,
+				unsigned int block_index)
+{
+	if (backend->block[block_index].rejected_through < entry->version)
+		backend->block[block_index].rejected_through = entry->version;
+	memset(entry, 0, sizeof(*entry));
+}
+
+static bool cs_be_rows_equal(const struct cs_fe_rows *a,
+			     const struct cs_fe_rows *b)
+{
+	return a->class_row == b->class_row && a->sdb_row == b->sdb_row &&
+	       a->mask_row == b->mask_row && a->miss_fwd == b->miss_fwd &&
+	       a->hit_fwd == b->hit_fwd && a->voq == b->voq && a->l2 == b->l2 &&
+	       a->l3 == b->l3 && a->fvlan == b->fvlan &&
+	       a->priority == b->priority && a->miss_marker == b->miss_marker;
+}
+
+static bool cs_be_plan_equal(const struct cs_fe_plan *a,
+			     const struct cs_fe_plan *b)
+{
+	if (memcmp(a->key.bytes, b->key.bytes, sizeof(a->key.bytes)) ||
+	    a->key.crc32 != b->key.crc32 || a->key.crc16 != b->key.crc16 ||
+	    a->key.bucket != b->key.bucket ||
+	    memcmp(a->hash, b->hash, sizeof(a->hash)) ||
+	    !cs_fe_hot_action_equal(a, b))
+		return false;
+#define CS_BE_SAME_IMAGE(name) \
+	(a->name.words == b->name.words && \
+	 !memcmp(a->name.input, b->name.input, sizeof(a->name.input)) && \
+	 !memcmp(a->name.expected, b->name.expected, sizeof(a->name.expected)))
+	return CS_BE_SAME_IMAGE(class_invalid) && CS_BE_SAME_IMAGE(class_valid);
+#undef CS_BE_SAME_IMAGE
+}
+
+/*
+ * No dependency or ACL write here. Old in-flight references see EXACTLY the
+ * same immutable data. This is reactivation, never reclamation or ABA reuse.
+ */
+static int cs_be_rearm_graph(struct cs_fe_backend *backend,
+			     const struct cs_fe_backend_io *io,
+			     unsigned int index, unsigned long long end)
+{
+	struct cs_fe_backend_lease *lease = &backend->lease[index];
+	const struct cs_fe_rows *rows = &lease->rows;
+	const struct cs_fe_plan *plan = &lease->plan;
+	u32 zero[20] = { 0 }, cpu_voq[2] = { 56, 1U << 8 };
+	unsigned int way;
+	int error;
+
+	error = io->engine_status(io->context, &backend->status, &backend->init,
+				  end);
+	if (!error && (backend->status != 2 || backend->init))
+		error = -EUCLEAN;
+#define CS_BE_RETAINED(table, row, expected)                           \
+	do {                                                           \
+		if (!error)                                            \
+			error = cs_be_compare(backend, io, table, row, \
+					      expected, end);          \
+	} while (0)
+	CS_BE_RETAINED(CS_BE_CLASS, rows->class_row,
+		       plan->class_invalid.expected);
+	CS_BE_RETAINED(CS_BE_VOQ, 2, cpu_voq);
+	CS_BE_RETAINED(CS_BE_SDB, rows->sdb_row, plan->sdb.expected);
+	CS_BE_RETAINED(CS_BE_MASK, rows->mask_row, plan->mask.expected);
+	CS_BE_RETAINED(CS_BE_FWD, rows->miss_fwd, plan->miss.expected);
+	CS_BE_RETAINED(CS_BE_FWD, rows->hit_fwd, plan->hit.expected);
+	CS_BE_RETAINED(CS_BE_VOQ, rows->voq, plan->voq.expected);
+	CS_BE_RETAINED(CS_BE_L2, rows->l2, plan->l2.expected);
+	CS_BE_RETAINED(CS_BE_L3, rows->l3,
+		       plan->write_l3 ? plan->l3.expected : zero);
+	CS_BE_RETAINED(CS_BE_FVLAN, rows->fvlan,
+		       plan->write_fvlan ? plan->fvlan.expected : zero);
+	for (way = 0; way < 3; way++)
+		CS_BE_RETAINED(CS_BE_HASH, plan->key.bucket + way * 4096, zero);
+	for (way = 0; way < 64; way++)
+		CS_BE_RETAINED(CS_BE_OVERFLOW, way, zero);
+#undef CS_BE_RETAINED
+	if (!error)
+		error = backend->guard_rearm(backend->guard_context, io, index,
+					     rows, plan, end);
+	if (error)
+		return error;
+	lease->rearmable = false; /* BEFORE uncertain publication. */
+	error = cs_be_write(backend, io, CS_BE_HASH, plan->key.bucket,
+			    plan->hash, plan->hash, end);
+	if (!error)
+		error = cs_be_write(backend, io, CS_BE_CLASS, rows->class_row,
+				    plan->class_valid.input,
+				    plan->class_valid.expected, end);
+	return error;
+}
+
+/* 1=reactivated, 0=no identical retained scoped graph, negative=closed error. */
+static int cs_be_try_rearm(struct cs_fe_backend *backend,
+			   const struct cs_fe_backend_io *io,
+			   unsigned long long block, unsigned long cookie,
+			   unsigned long long version,
+			   const struct cs_fe_rule *rule,
+			   const struct cs_fe_key_policy *policy,
+			   unsigned int scope_grant, bool scope_exact,
+			   unsigned long long end, struct cs_fe_plan *expected)
+{
+	struct cs_fe_backend_entry *entry;
+	struct cs_fe_backend_lease *lease;
+	struct cs_fe_rows rows;
+	unsigned int index, other;
+	int error;
+
+	if (!scope_grant || !backend->guard_rearm)
+		return 0;
+	for (index = 0; index < backend->next_lease; index++) {
+		lease = &backend->lease[index];
+		if (!lease->reserved || !lease->submitted ||
+		    !lease->rearmable || lease->active || lease->marker ||
+		    !lease->scoped || !lease->guarded ||
+		    lease->scope_exact != scope_exact ||
+		    lease->scope_grant != scope_grant ||
+		    !cs_be_equal(lease, rule, policy))
+			continue;
+		if (!io->placement)
+			return -EPROTO;
+		{
+			bool shared;
+
+			error = io->placement(io->context, index, &rows,
+					      &shared);
+			if (error || shared != lease->shared_result)
+				return cs_be_fail(backend,
+						  error ? error : -EUCLEAN);
+		}
+		if (!cs_be_rows_equal(&rows, &lease->rows))
+			return cs_be_fail(backend, -EUCLEAN);
+		error = cs_fe_encode(rule, &rows, policy, expected);
+		if (!error && scope_exact)
+			cs_fe_exact_class_ipv4(expected, &rule->original,
+					       io->selector.source,
+					       io->selector.destination);
+		if (error)
+			return cs_be_fail(backend, error);
+		if (!cs_be_plan_equal(expected, &lease->plan)) {
+			/* A different Ethernet header requires a checked CLASS rebind. */
+			if (scope_exact &&
+			    cs_fe_hot_action_equal(expected, &lease->plan))
+				continue;
+			return cs_be_fail(backend, -EUCLEAN);
+		}
+		if (expected->requirements &
+		    ~(backend->admitted_requirements | scope_grant))
+			return -EOPNOTSUPP;
+		for (other = 0; other < CS_FE_BACKEND_ENTRIES; other++)
+			if (backend->entry[other].occupied &&
+			    backend->entry[other].active &&
+			    backend->entry[other].lease == index)
+				return cs_be_fail(backend, -EUCLEAN);
+		for (other = 0; other < backend->next_lease; other++)
+			if (backend->lease[other].active &&
+			    cs_be_overlap(&backend->lease[other].rule, rule))
+				return -EOPNOTSUPP;
+		entry = cs_be_entry(backend, block, cookie, true);
+		if (!entry)
+			return -ENOSPC;
+		entry->version = version;
+		entry->lease = index;
+		error = cs_be_rearm_graph(backend, io, index, end);
+		if (error)
+			return cs_be_fail(backend, error);
+		lease->active = entry->active = true;
+		backend->immutable_rearms++;
+		return 1;
+	}
+	return 0;
+}
+
+/*
+ * Mutable placement policy: choose an inactive immutable action, never reuse
+ * a different action's bucket or child rows. Owner independently verifies the
+ * canonical request and all real retained state before authorizing a rebind.
+ */
+static int cs_be_try_rekey(struct cs_fe_backend *backend,
+			   const struct cs_fe_backend_io *io,
+			   unsigned long long block, unsigned long cookie,
+			   unsigned long long version,
+			   const struct cs_fe_rule *rule,
+			   const struct cs_fe_key_policy *policy,
+			   unsigned int scope_grant, bool scope_exact,
+			   unsigned long long end, struct cs_fe_plan *candidate)
+{
+	struct cs_fe_backend_entry *entry;
+	struct cs_fe_backend_lease *lease;
+	unsigned int index, other;
+	int error;
+
+	if (!scope_grant || !scope_exact || !backend->guard_rearm ||
+	    !io->rebind || !io->receipt)
+		return 0;
+	for (index = 0; index < backend->next_lease; index++) {
+		lease = &backend->lease[index];
+		if (!lease->reserved || !lease->submitted ||
+		    !lease->rearmable || lease->active || lease->marker ||
+		    !lease->scoped || !lease->guarded ||
+		    lease->scope_exact != scope_exact ||
+		    lease->scope_grant != scope_grant ||
+		    lease->policy.exact_dscp != policy->exact_dscp ||
+		    lease->policy.dscp != policy->dscp ||
+		    lease->policy.require_mtu_range !=
+			    policy->require_mtu_range ||
+		    cs_fe_l4proto(&lease->rule, &lease->policy) !=
+			    cs_fe_l4proto(rule, policy))
+			continue;
+		error = io->receipt(io->context, index, candidate);
+		if (error || !cs_be_plan_equal(candidate, &lease->plan))
+			return cs_be_fail(backend, error ? error : -EUCLEAN);
+		error = cs_fe_encode(rule, &lease->rows, policy, candidate);
+		if (error)
+			return error;
+		cs_fe_exact_class_ipv4(candidate, &rule->original,
+				       io->selector.source,
+				       io->selector.destination);
+		if (!cs_fe_hot_action_equal(&lease->plan, candidate))
+			continue;
+		if (candidate->requirements &
+		    ~(backend->admitted_requirements | scope_grant))
+			return -EOPNOTSUPP;
+		for (other = 0; other < backend->next_lease; other++)
+			if (backend->lease[other].active &&
+			    cs_be_overlap(&backend->lease[other].rule, rule))
+				return -EOPNOTSUPP;
+		entry = cs_be_entry(backend, block, cookie, true);
+		if (!entry)
+			return -ENOSPC;
+		entry->version = version;
+		entry->lease = index;
+		error = io->rebind(io->context, index, rule, policy, candidate,
+				   end);
+		if (error == -EADDRINUSE) {
+			/*
+			 * Each slot has a different mask index in the lookup key.
+			 * The owner declined this bucket without reserving a transition.
+			 */
+			memset(entry, 0, sizeof(*entry));
+			continue;
+		}
+		if (error)
+			return cs_be_fail(backend, error);
+		lease->rearmable = false;
+		lease->rule = *rule;
+		lease->policy = *policy;
+		lease->plan = *candidate;
+		error = cs_be_write(backend, io, CS_BE_CLASS,
+				    lease->rows.class_row,
+				    candidate->class_invalid.input,
+				    candidate->class_invalid.expected, end);
+		if (!error)
+			error = backend->guard_rearm(backend->guard_context, io,
+						     index, &lease->rows,
+						     candidate, end);
+		if (!error)
+			error = cs_be_write(backend, io, CS_BE_HASH,
+					    candidate->key.bucket,
+					    candidate->hash, candidate->hash,
+					    end);
+		if (!error)
+			error = cs_be_write(backend, io, CS_BE_CLASS,
+					    lease->rows.class_row,
+					    candidate->class_valid.input,
+					    candidate->class_valid.expected,
+					    end);
+		if (error)
+			return cs_be_fail(backend, error);
+		lease->active = entry->active = true;
+		backend->immutable_rearms++;
+		return 1;
+	}
+	return 0;
+}
+
+static int
+cs_be_replace(struct cs_fe_backend *backend, const struct cs_fe_backend_io *io,
+	      unsigned long long block, unsigned long cookie,
+	      unsigned long long version, const struct cs_fe_rule *rule,
+	      const struct cs_fe_key_policy *policy, bool marker,
+	      const struct cs_fe_backend_encoding *encoding, bool guarded,
+	      unsigned int scope_grant, bool scope_exact)
+{
+	struct cs_fe_backend_entry *entry;
+	struct cs_fe_backend_lease *lease;
+	struct cs_fe_rows rows;
+	struct cs_fe_plan plan;
+	bool shared_result = false;
+	unsigned long long end;
+	unsigned int index, block_index;
+	int error;
+
+	if (!backend || cs_be_io(io) || !version)
+		return -EINVAL;
+	error = cs_be_block(backend, block);
+	if (error < 0)
+		return error;
+	block_index = error;
+	if (backend->poisoned)
+		return -EIO;
+	entry = cs_be_entry(backend, block, cookie, false);
+	if (entry && version <= entry->version)
+		return -ESTALE;
+	end = io->now_us(io->context) + CS_FE_BACKEND_US;
+	if (version <= backend->block[block_index].rejected_through) {
+		if (entry) {
+			entry->version = version;
+			error = cs_be_withdraw(backend, io, entry, end);
+			if (error)
+				return error;
+			cs_be_retire_cookie(backend, entry, block_index);
+		}
+		return -ESTALE;
+	}
+	if (entry) {
+		entry->version = version;
+		if (entry->active && rule && policy && !encoding &&
+		    backend->lease[entry->lease].marker == marker &&
+		    backend->lease[entry->lease].guarded == guarded &&
+		    backend->lease[entry->lease].scoped == !!scope_grant &&
+		    backend->lease[entry->lease].scope_exact == scope_exact &&
+		    backend->lease[entry->lease].scope_grant == scope_grant &&
+		    cs_be_equal(&backend->lease[entry->lease], rule, policy))
+			return 0;
+		error = cs_be_withdraw(backend, io, entry, end);
+		if (error)
+			return error;
+		cs_be_retire_cookie(backend, entry, block_index);
+		entry = NULL;
+	}
+	if (CS_FE_HOT_REARM && rule && policy && !marker && !encoding &&
+	    guarded && scope_grant) {
+		error = cs_be_try_rearm(backend, io, block, cookie, version,
+					rule, policy, scope_grant, scope_exact,
+					end, &plan);
+		if (error)
+			return error > 0 ? 0 :
+					   cs_be_rejected(backend, block_index,
+							  version, error);
+		error = cs_be_try_rekey(backend, io, block, cookie, version,
+					rule, policy, scope_grant, scope_exact,
+					end, &plan);
+		if (error)
+			return error > 0 ? 0 :
+					   cs_be_rejected(backend, block_index,
+							  version, error);
+	}
+	if (!rule || !policy)
+		error = -EINVAL;
+	else if (guarded &&
+		 (!backend->guard_prepare || !backend->guard_withdraw))
+		error = -EOPNOTSUPP;
+	else if (backend->next_lease == CS_FE_BACKEND_LEASES)
+		error = -ENOSPC;
+	else {
+		error = io->placement ?
+				io->placement(io->context, backend->next_lease,
+					      &rows, &shared_result) :
+				-EPROTO;
+		if (!error)
+			error = cs_fe_encode(rule, &rows, policy, &plan);
+		if (!error && marker) {
+			/*
+			 * Fixed CPU-preserving proof action, physically measured5a125.
+			 * Both IP replacements and every MAC/port/TTL edit are disabled.
+			 * This is never a successful NF hardware flow installation.
+			 */
+			memset(&plan.hit, 0, sizeof(plan.hit));
+			plan.hit.words = 4;
+			plan.hit.input[0] = 0x6824a011;
+			plan.hit.input[1] = 1;
+			memcpy(plan.hit.expected, plan.hit.input,
+			       sizeof(plan.hit.input));
+			plan.write_l3 = false;
+			plan.write_fvlan = false;
+			plan.requirements = 0;
+		}
+		if (!error && scope_grant && scope_exact)
+			cs_fe_exact_class_ipv4(&plan, &rule->original,
+					       io->selector.source,
+					       io->selector.destination);
+		if (!error && marker && encoding && encoding->exact_class) {
+			struct cs_fe_tuple classifier = rule->original;
+
+			/* The fixed probes vary only CLASS; keep the HASH unchanged. */
+			if (encoding->negative_class)
+				classifier.dst ^= 1;
+			if (encoding->class_match)
+				cs_fe_class_addresses(&plan, &classifier,
+						      rule->dmac,
+						      rule->ingress.base_mac,
+						      encoding->class_match);
+			else
+				cs_fe_exact_class_ipv4(&plan, &classifier,
+						       rule->dmac,
+						       rule->ingress.base_mac);
+		}
+		if (!error && encoding) {
+			unsigned int word, parity = 0;
+
+			/*
+			 * Actual module bytes are submitted, after the built-in semantic
+			 * verifier. No hidden regeneration of the old built-in key.
+			 */
+			plan.key = encoding->key;
+			memcpy(plan.mask.input, encoding->mask,
+			       sizeof(plan.mask.input));
+			memcpy(plan.mask.expected, encoding->mask,
+			       sizeof(plan.mask.expected));
+			for (word = 0; word < 5; word++)
+				parity ^= cs_be_parity(plan.mask.input[word]);
+			plan.mask.expected[4] |= parity << 21;
+			memcpy(plan.hit.input, encoding->action,
+			       sizeof(plan.hit.input));
+			memcpy(plan.hit.expected, encoding->action,
+			       sizeof(plan.hit.expected));
+			parity = 0;
+			for (word = 0; word < 4; word++)
+				parity ^= cs_be_parity(plan.hit.input[word]);
+			plan.hit.expected[3] |= parity << 17;
+			memset(plan.hash, 0, sizeof(plan.hash));
+			plan.hash[0] = plan.key.crc32;
+			plan.hash[1] = rows.hit_fwd |
+				       ((u32)rows.mask_row << 13);
+		}
+		if (!error && (plan.requirements &
+			       ~(backend->admitted_requirements | scope_grant)))
+			error = -EOPNOTSUPP;
+	}
+	if (error)
+		return entry ? error :
+			       cs_be_rejected(backend, block_index, version,
+					      error);
+	for (index = 0; index < backend->next_lease; index++) {
+		if (backend->lease[index].plan.key.bucket == plan.key.bucket) {
+			error = -ENOSPC;
+			break;
+		}
+		if (backend->lease[index].active &&
+		    cs_be_overlap(&backend->lease[index].rule, rule)) {
+			error = -EOPNOTSUPP;
+			break;
+		}
+	}
+	if (error)
+		return entry ? error :
+			       cs_be_rejected(backend, block_index, version,
+					      error);
+	if (!entry)
+		entry = cs_be_entry(backend, block, cookie, true);
+	if (!entry)
+		return cs_be_rejected(backend, block_index, version, -ENOSPC);
+	entry->version = version;
+	/* Claim is all-or-nothing. Rejections have no hardware or ledger effect. */
+	error = io->claim(io->context, backend->next_lease, rule, policy, &rows,
+			  &plan);
+	if (error) {
+		cs_be_retire_cookie(backend, entry, block_index);
+		return error;
+	}
+	entry->lease = backend->next_lease++;
+	lease = &backend->lease[entry->lease];
+	lease->reserved = true;
+	lease->shared_result = shared_result;
+	lease->marker = marker;
+	lease->guarded = guarded;
+	lease->scoped = !!scope_grant;
+	lease->scope_exact = scope_exact;
+	lease->scope_grant = scope_grant;
+	lease->rule = *rule;
+	lease->policy = *policy;
+	lease->rows = rows;
+	lease->plan = plan;
+	error = cs_be_program(backend, io, lease, end);
+	if (error && lease->shared_result && io->isolate &&
+	    !io->isolate(io->context, entry->lease)) {
+		cs_be_retire_cookie(backend, entry, block_index);
+		return error;
+	}
+	if (error)
+		return cs_be_fail(backend, error);
+	lease->active = true;
+	entry->active = true;
+	return 0;
+}
+
+int cs_fe_backend_replace(struct cs_fe_backend *backend,
+			  const struct cs_fe_backend_io *io,
+			  unsigned long long block, unsigned long cookie,
+			  unsigned long long version,
+			  const struct cs_fe_rule *rule,
+			  const struct cs_fe_key_policy *policy)
+{
+	return cs_be_replace(backend, io, block, cookie, version, rule, policy,
+			     false, NULL, false, 0, false);
+}
+
+int cs_fe_backend_replace_scoped(struct cs_fe_backend *backend,
+				 const struct cs_fe_backend_io *io,
+				 unsigned long long block, unsigned long cookie,
+				 unsigned long long version,
+				 const struct cs_fe_rule *rule,
+				 const struct cs_fe_key_policy *policy,
+				 bool exact_ingress)
+{
+	return cs_be_replace(backend, io, block, cookie, version, rule, policy,
+			     false, NULL, true,
+			     CS_FE_REQ_PACKET_EXCEPTIONS |
+				     CS_FE_REQ_COLLISION_CHECK |
+				     CS_FE_REQ_OWNER_LIFETIME,
+			     exact_ingress);
+}
+
+int cs_fe_backend_replace_guarded(struct cs_fe_backend *backend,
+				  const struct cs_fe_backend_io *io,
+				  unsigned long long block,
+				  unsigned long cookie,
+				  unsigned long long version,
+				  const struct cs_fe_rule *rule,
+				  const struct cs_fe_key_policy *policy)
+{
+	return cs_be_replace(backend, io, block, cookie, version, rule, policy,
+			     false, NULL, true, 0, false);
+}
+
+int cs_fe_backend_marker(struct cs_fe_backend *backend,
+			 const struct cs_fe_backend_io *io,
+			 unsigned long long block, unsigned long cookie,
+			 unsigned long long version,
+			 const struct cs_fe_rule *rule,
+			 const struct cs_fe_key_policy *policy)
+{
+	return cs_be_replace(backend, io, block, cookie, version, rule, policy,
+			     true, NULL, false, 0, false);
+}
+
+int cs_fe_backend_marker_encoded(struct cs_fe_backend *backend,
+				 const struct cs_fe_backend_io *io,
+				 unsigned long long block, unsigned long cookie,
+				 unsigned long long version,
+				 const struct cs_fe_rule *rule,
+				 const struct cs_fe_key_policy *policy,
+				 const struct cs_fe_backend_encoding *encoding)
+{
+	if (!encoding)
+		return -EINVAL;
+	return cs_be_replace(backend, io, block, cookie, version, rule, policy,
+			     true, encoding, encoding->guarded, 0, false);
+}
+
+static int cs_be_end(struct cs_fe_backend *backend,
+		     const struct cs_fe_backend_io *io,
+		     unsigned long long block, unsigned long cookie,
+		     unsigned long long version, bool require_new)
+{
+	struct cs_fe_backend_entry *entry;
+	int error, block_index;
+
+	if (!backend || cs_be_io(io) || !version)
+		return -EINVAL;
+	error = cs_be_block(backend, block);
+	if (error < 0)
+		return error;
+	block_index = error;
+	if (backend->poisoned)
+		return -EIO;
+	entry = cs_be_entry(backend, block, cookie, false);
+	if (!entry)
+		return cs_be_rejected(backend, block_index, version, 0);
+	if (version < entry->version ||
+	    (require_new && version == entry->version))
+		return -ESTALE;
+	entry->version = version;
+	error = cs_be_withdraw(backend, io, entry,
+			       io->now_us(io->context) + CS_FE_BACKEND_US);
+	if (!error)
+		cs_be_retire_cookie(backend, entry, block_index);
+	return error;
+}
+
+int cs_fe_backend_destroy(struct cs_fe_backend *backend,
+			  const struct cs_fe_backend_io *io,
+			  unsigned long long block, unsigned long cookie,
+			  unsigned long long version)
+{
+	return cs_be_end(backend, io, block, cookie, version, false);
+}
+
+int cs_fe_backend_reject(struct cs_fe_backend *backend,
+			 const struct cs_fe_backend_io *io,
+			 unsigned long long block, unsigned long cookie,
+			 unsigned long long version, int reason)
+{
+	int error = cs_be_end(backend, io, block, cookie, version, true);
+
+	return error ? error : reason < 0 ? reason : -EOPNOTSUPP;
+}
+
+int cs_fe_backend_unbind(struct cs_fe_backend *backend,
+			 const struct cs_fe_backend_io *io,
+			 unsigned long long block)
+{
+	unsigned long long end;
+	unsigned int index;
+	int error, slot;
+
+	if (!backend || cs_be_io(io))
+		return -EINVAL;
+	slot = cs_be_block(backend, block);
+	if (slot == -ESHUTDOWN)
+		return backend->poisoned ? -EIO : 0;
+	if (slot < 0)
+		return slot;
+	/* Close BEFORE any I/O; a failed withdrawal never reopens this block. */
+	backend->block[slot].closed = true;
+	if (backend->poisoned)
+		return -EIO;
+	end = io->now_us(io->context) + CS_FE_BACKEND_US;
+	for (index = 0; index < CS_FE_BACKEND_ENTRIES; index++) {
+		if (!backend->entry[index].occupied ||
+		    backend->entry[index].block != block)
+			continue;
+		error = cs_be_withdraw(backend, io, &backend->entry[index],
+				       end);
+		if (error)
+			return error;
+	}
+	return 0;
+}
diff --git a/drivers/net/ethernet/cortina/cs_fe_backend_dispatch.c b/drivers/net/ethernet/cortina/cs_fe_backend_dispatch.c
new file mode 100644
index 000000000..4ffd929a9
--- /dev/null
+++ b/drivers/net/ethernet/cortina/cs_fe_backend_dispatch.c
@@ -0,0 +1,433 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Stable private owner attachment. NAPI never calls these module methods. */
+#include <linux/atomic.h>
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/kobject.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/rwsem.h>
+#include <linux/string.h>
+#include <linux/sysfs.h>
+#include "cs_fe_hot_internal.h"
+
+static DEFINE_MUTEX(provider_control);
+static DECLARE_RWSEM(provider_calls);
+static const struct cs7542_fe_backend_ops *provider;
+static bool provider_blocked;
+static u64 provider_epoch;
+static atomic_t provider_active = ATOMIC_INIT(0);
+static struct kobject *provider_kobject;
+
+int cs7542_fe_backend_register(const struct cs7542_fe_backend_ops *ops)
+{
+	int error = 0;
+
+	if (!ops || ops->abi != CS7542_FE_BACKEND_ABI ||
+	    ops->size != sizeof(*ops) ||
+	    ops->state_size != sizeof(struct cs_fe_backend) || !ops->owner ||
+	    !ops->run || !ops->name || !ops->revision)
+		return -EINVAL;
+	if (IS_ENABLED(CONFIG_MODULE_FORCE_UNLOAD))
+		return -EOPNOTSUPP;
+	mutex_lock(&provider_control);
+	down_write(&provider_calls);
+	if (!provider_kobject)
+		error = -ENODEV;
+	else if (provider)
+		error = provider == ops && !provider_blocked ? 0 : -EBUSY;
+	else if (provider_epoch == U64_MAX)
+		error = -EOVERFLOW;
+	else if (!try_module_get(ops->owner))
+		error = -ESHUTDOWN;
+	else {
+		provider = ops;
+		provider_blocked = false;
+		provider_epoch++;
+	}
+	up_write(&provider_calls);
+	mutex_unlock(&provider_control);
+	return error;
+}
+EXPORT_SYMBOL_GPL(cs7542_fe_backend_register);
+
+bool cs7542_fe_backend_registered(const struct cs7542_fe_backend_ops *ops)
+{
+	bool registered;
+
+	down_read(&provider_calls);
+	registered = provider == ops;
+	up_read(&provider_calls);
+	return registered;
+}
+EXPORT_SYMBOL_GPL(cs7542_fe_backend_registered);
+
+static int cs_hot_dispatch(enum cs_fe_hot_command command,
+			   struct cs_fe_backend *backend,
+			   const struct cs_fe_backend_io *native,
+			   struct cs_fe_hot_request request)
+{
+	struct cs_fe_hot_session session;
+	struct cs_fe_backend_io typed;
+	const struct cs7542_fe_backend_ops *ops;
+	u64 blocks;
+	unsigned int leases;
+	int error;
+
+	if (!backend || !native || !backend->hot_state || !native->now_us ||
+	    !native->read32 || !native->write32)
+		return -EINVAL;
+	down_read(&provider_calls);
+	ops = provider;
+	if (!ops || provider_blocked) {
+		error = -EOPNOTSUPP;
+		goto unlock;
+	}
+	if (!try_module_get(ops->owner)) {
+		error = -ESHUTDOWN;
+		goto unlock;
+	}
+	request.selector = native->selector;
+	session = (struct cs_fe_hot_session){
+		.backend = backend,
+		.native = *native,
+		.request = request,
+		.command = command,
+	};
+	cs_fe_hot_typed_io(&session, &typed);
+	blocks = backend->next_block;
+	leases = backend->next_lease;
+	atomic_inc(&provider_active);
+	error = ops->run(command, backend, &typed, &session.request);
+	atomic_dec(&provider_active);
+	/* Physical claims and opaque handles may never rewind across versions. */
+	if (backend->next_block != blocks || backend->next_lease < leases ||
+	    backend->next_lease > CS_FE_BACKEND_LEASES) {
+		backend->poisoned = true;
+		backend->hot_state->ledger.pending = true;
+		error = -EUCLEAN;
+	}
+	module_put(
+		ops->owner); /* Builtin code: never drop final pin in module text. */
+unlock:
+	up_read(&provider_calls);
+	return error;
+}
+
+/*
+ * Builtin status never holds provider_calls while acquiring an owner mutex:
+ * ordinary callbacks already hold owner->lock before entering dispatch.
+ */
+static ssize_t status_show(struct kobject *kobj, struct kobj_attribute *attr,
+			   char *buffer)
+{
+	unsigned int contexts = 0, leases = 0, revision = 0, refs = 0;
+	char name[64] = "none";
+	u64 before, after;
+	bool registered, blocked;
+	int error;
+
+	down_read(&provider_calls);
+	before = provider_epoch;
+	registered = !!provider;
+	blocked = provider_blocked;
+	if (provider) {
+		strscpy(name, provider->name, sizeof(name));
+		revision = provider->revision;
+		refs = module_refcount(provider->owner);
+	}
+	up_read(&provider_calls);
+	error = cs_fe_live_hot_idle(&contexts, &leases, false);
+	down_read(&provider_calls);
+	after = provider_epoch;
+	up_read(&provider_calls);
+	return sysfs_emit(buffer,
+		"api=1 epoch=%llu registered=%u blocked=%u active_calls=%d contexts=%u leases=%u idle_error=%d ready_to_release=%u revision=%u module_refs=%u name=%s\n",
+		after, registered, blocked, atomic_read(&provider_active),
+		contexts, leases, error,
+		registered && !blocked && !error && before == after &&
+			refs == 1,
+		revision, refs, name);
+}
+
+static ssize_t release_store(struct kobject *kobj, struct kobj_attribute *attr,
+			     const char *buffer, size_t count)
+{
+	const struct cs7542_fe_backend_ops *ops;
+	unsigned int contexts = 0, leases = 0;
+	int error;
+
+	if (!sysfs_streq(buffer, "release"))
+		return -EINVAL;
+	mutex_lock(&provider_control);
+	down_write(
+		&provider_calls); /* Drain every synchronous algorithm call. */
+	ops = provider;
+	if (!ops) {
+		up_write(&provider_calls);
+		mutex_unlock(&provider_control);
+		return count;
+	}
+	if (ops->owner->state != MODULE_STATE_LIVE ||
+	    module_refcount(ops->owner) != 1) {
+		up_write(&provider_calls);
+		mutex_unlock(&provider_control);
+		return -EBUSY;
+	}
+	provider_blocked = true;
+	up_write(&provider_calls);
+	/* No provider rwsem held while taking owner locks or reading table cuts. */
+	error = cs_fe_live_hot_idle(&contexts, &leases, true);
+	down_write(&provider_calls);
+	if (!error && module_refcount(ops->owner) != 1)
+		error = -EBUSY;
+	if (!error) {
+		provider = NULL;
+		if (provider_epoch != U64_MAX)
+			provider_epoch++;
+		module_put(
+			ops->owner); /* Safe builtin caller; data/text no longer reachable. */
+	}
+	provider_blocked =
+		false; /* On failure keep the provider usable for cleanup. */
+	up_write(&provider_calls);
+	mutex_unlock(&provider_control);
+	return error ? error : count;
+}
+
+static struct kobj_attribute status_attribute = __ATTR_RO(status);
+static struct kobj_attribute release_attribute = __ATTR_WO(release);
+static struct attribute *provider_attributes[] = {
+	&status_attribute.attr,
+	&release_attribute.attr,
+	NULL,
+};
+
+static const struct attribute_group provider_group = {
+	.attrs = provider_attributes
+};
+
+static int __init cs_hot_manager_init(void)
+{
+	int error;
+
+	provider_kobject =
+		kobject_create_and_add("cs7542_fe_backend", kernel_kobj);
+	if (!provider_kobject)
+		return -ENOMEM;
+	error = sysfs_create_group(provider_kobject, &provider_group);
+	if (error) {
+		kobject_put(provider_kobject);
+		provider_kobject = NULL;
+	}
+	return error;
+}
+
+subsys_initcall(cs_hot_manager_init);
+
+int cs_fe_backend_init(struct cs_fe_backend *backend, unsigned int requirements)
+{
+	if (!backend || backend->initialized)
+		return -EBUSY;
+	memset(backend, 0, sizeof(*backend));
+	backend->admitted_requirements = requirements;
+	backend->initialized = true;
+	return 0;
+}
+
+int cs_fe_backend_block_open(struct cs_fe_backend *backend,
+			     unsigned long long *handle)
+{
+	unsigned int index;
+
+	if (!backend || !handle || !backend->initialized || backend->poisoned)
+		return -ENODEV;
+	if (backend->next_block == ~0ULL)
+		return -EOVERFLOW;
+	for (index = 0; index < CS_FE_BACKEND_BLOCKS; index++) {
+		if (backend->block[index].identity)
+			continue;
+		*handle = ++backend->next_block;
+		backend->block[index].identity = *handle;
+		return 0;
+	}
+	return -ENOSPC;
+}
+
+int cs_fe_backend_next_rows(const struct cs_fe_backend *backend,
+			    struct cs_fe_rows *rows)
+{
+	if (!backend || !rows || backend->poisoned || backend->pending)
+		return -EIO;
+	if (backend->next_lease >= CS_FE_BACKEND_ACTIONS)
+		return -ENOSPC;
+	*rows = cs_fe_hot_rows(backend->next_lease);
+	return 0;
+}
+
+int cs_fe_backend_forget(struct cs_fe_backend *backend,
+			 unsigned long long block)
+{
+	unsigned int index, slot = CS_FE_BACKEND_BLOCKS;
+
+	if (!backend || !block || !backend->initialized)
+		return -EINVAL;
+	if (backend->poisoned || backend->pending)
+		return -EIO;
+	for (index = 0; index < CS_FE_BACKEND_BLOCKS; index++)
+		if (backend->block[index].identity == block)
+			slot = index;
+	if (slot == CS_FE_BACKEND_BLOCKS)
+		return 0; /* Already forgotten; a late finish still gets ENOENT. */
+	if (!backend->block[slot].closed)
+		return -EBUSY;
+	for (index = 0; index < CS_FE_BACKEND_ENTRIES; index++)
+		if (backend->entry[index].occupied &&
+		    backend->entry[index].block == block &&
+		    backend->entry[index].active)
+			return -EBUSY;
+	for (index = 0; index < CS_FE_BACKEND_ENTRIES; index++)
+		if (backend->entry[index].block == block)
+			memset(&backend->entry[index], 0,
+			       sizeof(backend->entry[index]));
+	memset(&backend->block[slot], 0, sizeof(backend->block[slot]));
+	return 0;
+}
+
+int cs_fe_backend_replace(struct cs_fe_backend *backend,
+			  const struct cs_fe_backend_io *io,
+			  unsigned long long block, unsigned long cookie,
+			  unsigned long long version,
+			  const struct cs_fe_rule *rule,
+			  const struct cs_fe_key_policy *policy)
+{
+	struct cs_fe_hot_request request = {
+		.block = block,
+		.cookie = cookie,
+		.version = version,
+		.rule = rule,
+		.policy = policy,
+	};
+	return cs_hot_dispatch(CS_HOT_REPLACE, backend, io, request);
+}
+
+int cs_fe_backend_replace_native(struct cs_fe_backend *backend,
+				 const struct cs_fe_backend_io *io,
+				 unsigned long long block, unsigned long cookie,
+				 unsigned long long version,
+				 const struct cs_fe_rule *rule,
+				 const struct cs_fe_key_policy *policy)
+{
+	struct cs_fe_hot_request request = {
+		.block = block,
+		.cookie = cookie,
+		.version = version,
+		.rule = rule,
+		.policy = policy,
+		.exact = true,
+	};
+	return cs_hot_dispatch(CS_HOT_NATIVE, backend, io, request);
+}
+
+int cs_fe_backend_replace_scoped(struct cs_fe_backend *backend,
+				 const struct cs_fe_backend_io *io,
+				 unsigned long long block, unsigned long cookie,
+				 unsigned long long version,
+				 const struct cs_fe_rule *rule,
+				 const struct cs_fe_key_policy *policy,
+				 bool exact_ingress)
+{
+	struct cs_fe_hot_request request = {
+		.block = block,
+		.cookie = cookie,
+		.version = version,
+		.rule = rule,
+		.policy = policy,
+		.exact = exact_ingress,
+	};
+	return cs_hot_dispatch(CS_HOT_SCOPED, backend, io, request);
+}
+
+int cs_fe_backend_replace_guarded(struct cs_fe_backend *backend,
+				  const struct cs_fe_backend_io *io,
+				  unsigned long long block,
+				  unsigned long cookie,
+				  unsigned long long version,
+				  const struct cs_fe_rule *rule,
+				  const struct cs_fe_key_policy *policy)
+{
+	struct cs_fe_hot_request request = {
+		.block = block,
+		.cookie = cookie,
+		.version = version,
+		.rule = rule,
+		.policy = policy,
+	};
+	return cs_hot_dispatch(CS_HOT_GUARDED, backend, io, request);
+}
+
+int cs_fe_backend_marker(struct cs_fe_backend *backend,
+			 const struct cs_fe_backend_io *io,
+			 unsigned long long block, unsigned long cookie,
+			 unsigned long long version,
+			 const struct cs_fe_rule *rule,
+			 const struct cs_fe_key_policy *policy)
+{
+	struct cs_fe_hot_request request = {
+		.block = block,
+		.cookie = cookie,
+		.version = version,
+		.rule = rule,
+		.policy = policy,
+	};
+	return cs_hot_dispatch(CS_HOT_MARKER, backend, io, request);
+}
+
+int cs_fe_backend_marker_encoded(struct cs_fe_backend *backend,
+				 const struct cs_fe_backend_io *io,
+				 unsigned long long block, unsigned long cookie,
+				 unsigned long long version,
+				 const struct cs_fe_rule *rule,
+				 const struct cs_fe_key_policy *policy,
+				 const struct cs_fe_backend_encoding *encoding)
+{
+	struct cs_fe_hot_request request = { .block = block,
+					     .cookie = cookie,
+					     .version = version,
+					     .rule = rule,
+					     .policy = policy,
+					     .encoding = encoding };
+	return cs_hot_dispatch(CS_HOT_ENCODED, backend, io, request);
+}
+
+int cs_fe_backend_reject(struct cs_fe_backend *backend,
+			 const struct cs_fe_backend_io *io,
+			 unsigned long long block, unsigned long cookie,
+			 unsigned long long version, int reason)
+{
+	struct cs_fe_hot_request request = { .block = block,
+					     .cookie = cookie,
+					     .version = version,
+					     .reason = reason };
+	return cs_hot_dispatch(CS_HOT_REJECT, backend, io, request);
+}
+
+int cs_fe_backend_destroy(struct cs_fe_backend *backend,
+			  const struct cs_fe_backend_io *io,
+			  unsigned long long block, unsigned long cookie,
+			  unsigned long long version)
+{
+	struct cs_fe_hot_request request = { .block = block,
+					     .cookie = cookie,
+					     .version = version };
+	return cs_hot_dispatch(CS_HOT_DESTROY, backend, io, request);
+}
+
+int cs_fe_backend_unbind(struct cs_fe_backend *backend,
+			 const struct cs_fe_backend_io *io,
+			 unsigned long long block)
+{
+	struct cs_fe_hot_request request = { .block = block };
+
+	return cs_hot_dispatch(CS_HOT_UNBIND, backend, io, request);
+}
diff --git a/drivers/net/ethernet/cortina/cs_fe_backend_module.c b/drivers/net/ethernet/cortina/cs_fe_backend_module.c
new file mode 100644
index 000000000..9082e055c
--- /dev/null
+++ b/drivers/net/ethernet/cortina/cs_fe_backend_module.c
@@ -0,0 +1,164 @@
+// SPDX-License-Identifier: GPL-2.0
+#ifndef CS_FE_HOT_REARM
+#define CS_FE_HOT_REARM 1
+#endif
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/errno.h>
+#include <linux/sysfs.h>
+#include <linux/cs7542_fe_backend.h>
+#define cs_fe_backend_init hot_cs_fe_backend_init
+#define cs_fe_backend_block_open hot_cs_fe_backend_block_open
+#define cs_fe_backend_next_rows hot_cs_fe_backend_next_rows
+#define cs_fe_backend_replace hot_cs_fe_backend_replace
+#define cs_fe_backend_replace_scoped hot_cs_fe_backend_replace_scoped
+#define cs_fe_backend_replace_guarded hot_cs_fe_backend_replace_guarded
+#define cs_fe_backend_marker hot_cs_fe_backend_marker
+#define cs_fe_backend_marker_encoded hot_cs_fe_backend_marker_encoded
+#define cs_fe_backend_destroy hot_cs_fe_backend_destroy
+#define cs_fe_backend_reject hot_cs_fe_backend_reject
+#define cs_fe_backend_unbind hot_cs_fe_backend_unbind
+#define cs_fe_backend_forget hot_cs_fe_backend_forget
+#include "cs_fe_backend.h"
+#undef cs_fe_backend_init
+#undef cs_fe_backend_block_open
+#undef cs_fe_backend_next_rows
+#undef cs_fe_backend_replace
+#undef cs_fe_backend_replace_scoped
+#undef cs_fe_backend_replace_guarded
+#undef cs_fe_backend_marker
+#undef cs_fe_backend_marker_encoded
+#undef cs_fe_backend_destroy
+#undef cs_fe_backend_reject
+#undef cs_fe_backend_unbind
+#undef cs_fe_backend_forget
+
+/* Native TCP requests carry an established nftables flow and a checked tuple. */
+#ifndef CS_FE_WIRED_TCP
+#define CS_FE_WIRED_TCP 1
+#endif
+#if IS_ENABLED(CONFIG_CS7542_FE_WIRED) && CS_FE_WIRED_TCP
+#define CS_FE_REVISION 8
+#define CS_FE_VERSION "8"
+#define CS_FE_NAME "native-wired-tcp-udp"
+#elif IS_ENABLED(CONFIG_CS7542_FE_WIRED)
+#define CS_FE_REVISION 7
+#define CS_FE_VERSION "7"
+#define CS_FE_NAME "native-wired-udp"
+#elif CS_FE_HOT_REARM
+#define CS_FE_REVISION 3
+#define CS_FE_VERSION "3"
+#define CS_FE_NAME "sdk-identical-rebind"
+#else
+#define CS_FE_REVISION 1
+#define CS_FE_VERSION "1"
+#define CS_FE_NAME "fresh-only"
+#endif
+static int algorithm_run(enum cs_fe_hot_command command,
+			 struct cs_fe_backend *backend,
+			 const struct cs_fe_backend_io *io,
+			 const struct cs_fe_hot_request *request)
+{
+	switch (command) {
+	case CS_HOT_NATIVE:
+		/*
+		 * Run supported wired flows through the replaceable backend.
+		 * The owner supplies observed wire addresses, a route MTU and its strict
+		 * per-packet policy. Older revisions reject this operation.
+		 */
+#if IS_ENABLED(CONFIG_CS7542_FE_WIRED)
+		if (!request->rule || !request->policy || !request->exact ||
+		    !request->selector.valid ||
+		    (cs_fe_l4proto(request->rule, request->policy) !=
+			     CS_FE_L4_UDP &&
+		     (!CS_FE_WIRED_TCP ||
+		      cs_fe_l4proto(request->rule, request->policy) !=
+			      CS_FE_L4_TCP)) ||
+		    !request->policy->require_mtu_range ||
+		    request->policy->exact_dscp)
+			return -EOPNOTSUPP;
+		return hot_cs_fe_backend_replace_scoped(backend, io, request->block,
+			request->cookie,
+			request->version, request->rule, request->policy, true);
+#else
+		return -EOPNOTSUPP;
+#endif
+	case CS_HOT_REPLACE:
+		return hot_cs_fe_backend_replace(backend, io, request->block,
+			request->cookie,
+			request->version, request->rule, request->policy);
+	case CS_HOT_SCOPED:
+		return hot_cs_fe_backend_replace_scoped(backend, io, request->block,
+			request->cookie,
+			request->version, request->rule, request->policy,
+			request->exact);
+	case CS_HOT_GUARDED:
+		return hot_cs_fe_backend_replace_guarded(backend, io, request->block,
+			request->cookie,
+			request->version, request->rule, request->policy);
+	case CS_HOT_MARKER:
+		return hot_cs_fe_backend_marker(backend, io, request->block,
+						request->cookie,
+						request->version, request->rule,
+						request->policy);
+	case CS_HOT_ENCODED:
+		return hot_cs_fe_backend_marker_encoded(backend, io, request->block,
+			request->cookie,
+			request->version, request->rule, request->policy,
+			request->encoding);
+	case CS_HOT_REJECT:
+		return hot_cs_fe_backend_reject(backend, io, request->block,
+						request->cookie,
+						request->version,
+						request->reason);
+	case CS_HOT_DESTROY:
+		return hot_cs_fe_backend_destroy(backend, io, request->block,
+						 request->cookie,
+						 request->version);
+	case CS_HOT_UNBIND:
+		return hot_cs_fe_backend_unbind(backend, io, request->block);
+	}
+	return -EOPNOTSUPP;
+}
+
+static const struct cs7542_fe_backend_ops algorithm_ops = {
+	.abi = CS7542_FE_BACKEND_ABI,
+	.size = sizeof(algorithm_ops),
+	.state_size = sizeof(struct cs_fe_backend),
+	.revision = CS_FE_REVISION,
+	.owner = THIS_MODULE,
+	.name = CS_FE_NAME,
+	.run = algorithm_run,
+};
+
+static unsigned int revision = CS_FE_REVISION;
+
+module_param(revision, uint, 0444);
+static int attach_set(const char *value, const struct kernel_param *parameter)
+{
+	(void)parameter;
+	if (!sysfs_streq(value, "attach"))
+		return -EINVAL;
+	return cs7542_fe_backend_register(&algorithm_ops);
+}
+
+static const struct kernel_param_ops attach_ops = { .set = attach_set };
+
+module_param_cb(attach, &attach_ops, NULL, 0200);
+static int __init algorithm_init(void)
+{
+	/* Registration is last: no later failure can free accepted module text. */
+	return cs7542_fe_backend_register(&algorithm_ops);
+}
+
+static void __exit algorithm_exit(void)
+{
+	WARN_ON(cs7542_fe_backend_registered(&algorithm_ops));
+	/* Builtin release already drained calls and verified the visibility cut. */
+}
+
+module_init(algorithm_init);
+module_exit(algorithm_exit);
+MODULE_LICENSE("GPL");
+MODULE_INFO(version, CS_FE_VERSION);
+MODULE_INFO(description, "Private replaceable CS7542 FE placement backend");
diff --git a/drivers/net/ethernet/cortina/cs_fe_encode.c b/drivers/net/ethernet/cortina/cs_fe_encode.c
new file mode 100644
index 000000000..e968a5c6c
--- /dev/null
+++ b/drivers/net/ethernet/cortina/cs_fe_encode.c
@@ -0,0 +1,562 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "cs_fe_encode.h"
+#ifdef __KERNEL__
+#include <linux/array_size.h>
+#include <linux/errno.h>
+#include <linux/string.h>
+#else
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
+#include <errno.h>
+#include <string.h>
+#endif
+/* cs75xx_fe_core_table.h: declared HASH key bit offsets. */
+enum lookup_key_offset {
+	KEY_ETHERTYPE = 96,
+	KEY_OUTER_TPID = 116,
+	KEY_OUTER_PCP = 119,
+	KEY_OUTER_DEI = 122,
+	KEY_OUTER_VID = 123,
+	KEY_IPV4_DESTINATION = 155,
+	KEY_IPV4_SOURCE = 283,
+	KEY_PROTOCOL = 411,
+	KEY_DSCP = 419,
+	KEY_PKTLEN_RANGE_VECTOR = 427,
+	KEY_IP_VALID = 452,
+	KEY_DESTINATION_PORT = 453,
+	KEY_SOURCE_PORT = 469,
+	KEY_L4_VALID = 494,
+	KEY_LSPID = 501,
+	KEY_MASK_POINTER = 526,
+};
+
+/* Named fields from the pinned primary descriptors. */
+#include "cs_fe_fields.h"
+#define LOOKUP_FIELD(words, name, value) \
+	lookup_store_bits(words, name##_START, name##_WIDTH, value)
+
+static void lookup_store_bits(u32 *words, unsigned int start,
+			      unsigned int width, u32 value)
+{
+	unsigned int index, bit;
+
+	for (index = 0; index < width; index++) {
+		bit = start + index;
+		words[bit / 32] &= ~(1U << (bit % 32));
+		words[bit / 32] |= ((value >> index) & 1U) << (bit % 32);
+	}
+}
+
+static void lookup_key_bits(u8 key[84], unsigned int start, unsigned int width,
+			    u32 value)
+{
+	unsigned int index;
+
+	for (index = 0; index < width; index++)
+		key[(start + index) / 8] |= ((value >> index) & 1U)
+					    << ((start + index) % 8);
+}
+
+static u32 lookup_reverse(u32 value, unsigned int width)
+{
+	u32 reversed = 0;
+	unsigned int index;
+
+	for (index = 0; index < width; index++) {
+		reversed = (reversed << 1) | (value & 1U);
+		value >>= 1;
+	}
+	return reversed;
+}
+
+static void build_key(const struct cs_fe_rule *rule,
+		      const struct cs_fe_rows *rows,
+		      const struct cs_fe_key_policy *policy,
+		      struct cs_fe_key *key)
+{
+	const unsigned int mac_len = sizeof(rule->ingress.base_mac);
+	u32 crc32 = 0xffffffffU;
+	u32 crc16 = 0xffffU;
+	unsigned int index, bit, input;
+
+	/* FE_HASH_DA occupies the first 48 bits, least significant byte first. */
+	for (index = 0; index < mac_len; index++)
+		key->bytes[index] = rule->ingress.base_mac[mac_len - 1 - index];
+
+	if (rule->ingress.tag_mode == 4) {
+		lookup_key_bits(key->bytes, KEY_OUTER_TPID, 3, 4);
+		lookup_key_bits(key->bytes, KEY_OUTER_PCP, 3,
+				rule->ingress.rx_qca_meta >> 13);
+		lookup_key_bits(key->bytes, KEY_OUTER_DEI, 1,
+				(rule->ingress.rx_qca_meta >> 12) & 1);
+		lookup_key_bits(key->bytes, KEY_OUTER_VID, 12,
+				rule->ingress.rx_qca_meta & 4095);
+	} else {
+		lookup_key_bits(key->bytes, KEY_ETHERTYPE, 16, 0x0800);
+	}
+
+	lookup_key_bits(key->bytes, KEY_IPV4_DESTINATION, 32,
+			rule->original.dst);
+	lookup_key_bits(key->bytes, KEY_IPV4_SOURCE, 32, rule->original.src);
+	lookup_key_bits(key->bytes, KEY_PROTOCOL, 8,
+			cs_fe_l4proto(rule, policy));
+	lookup_key_bits(key->bytes, KEY_DSCP, 6,
+			policy->exact_dscp ? policy->dscp : 0);
+	if (policy->require_mtu_range)
+		lookup_key_bits(key->bytes, KEY_PKTLEN_RANGE_VECTOR, 4,
+				policy->require_mtu_range);
+	lookup_key_bits(key->bytes, KEY_IP_VALID, 1, 1);
+	lookup_key_bits(key->bytes, KEY_DESTINATION_PORT, 16,
+			rule->original.dport);
+	lookup_key_bits(key->bytes, KEY_SOURCE_PORT, 16, rule->original.sport);
+	lookup_key_bits(key->bytes, KEY_L4_VALID, 1, 1);
+	lookup_key_bits(key->bytes, KEY_LSPID, 4, rule->ingress.gmac);
+	lookup_key_bits(key->bytes, KEY_MASK_POINTER, 6, rows->mask_row);
+
+	for (index = 0; index < sizeof(key->bytes); index++) {
+		for (bit = 0; bit < 8; bit++) {
+			input = (key->bytes[index] >> bit) & 1U;
+			crc32 = (crc32 >> 1) ^
+				(((crc32 ^ input) & 1U) ? 0xedb88320U : 0);
+			crc16 = (crc16 >> 1) ^
+				(((crc16 ^ input) & 1U) ? 0x8408U : 0);
+		}
+	}
+
+	key->crc32 = lookup_reverse(crc32, 32);
+	key->crc16 = lookup_reverse(crc16, 16);
+	key->bucket = key->crc16 >> 4;
+}
+
+static void build_mask(const struct cs_fe_rule *rule,
+		       const struct cs_fe_key_policy *policy, u32 out[5])
+{
+	u32 payload[5] = { 0 };
+
+	unsigned int index;
+
+	for (index = 0;
+	     index < ARRAY_SIZE(cs_fe_mask_fields);
+	     index++) {
+		const struct cs_fe_mask_field *field =
+			&cs_fe_mask_fields[index];
+
+		lookup_store_bits(payload, field->start, field->width,
+				  (1U << field->width) - 1);
+	}
+#define INCLUDE_MASK(name, value) \
+	lookup_store_bits(payload, name##_START, name##_WIDTH, value)
+	/* Vendor scalar include0, full IP128 and CCITT polynomial0. */
+	INCLUDE_MASK(FE_HM_MAC_DA_MASK, 0);
+	INCLUDE_MASK(FE_HM_TPID_ENC_1_MSB_MASK, 0);
+	INCLUDE_MASK(FE_HM_TPID_ENC_1_LSB_MASK, 0);
+	INCLUDE_MASK(FE_HM_8021P_1_MASK, 0);
+	INCLUDE_MASK(FE_HM_DEI_1_MASK, 0);
+	INCLUDE_MASK(FE_HM_VID_1_MASK, 0);
+	INCLUDE_MASK(FE_HM_TPID_ENC_2_MSB_MASK, 0);
+	INCLUDE_MASK(FE_HM_PPPOE_SESSION_ID_VLD_MASK, 0);
+	INCLUDE_MASK(FE_HM_IP_DA_MASK, 128);
+	INCLUDE_MASK(FE_HM_IP_SA_MASK, 128);
+	INCLUDE_MASK(FE_HM_IP_PROT_MASK, 0);
+	/*
+	 * SDK TCP_CTRL_MASK ignores URG, ACK and PSH. The zero-initialized
+	 * TCP control key (bits 485..490) requires RST, SYN and FIN clear.
+	 * Otherwise this SDB returns the original frame to the CPU.
+	 */
+	if (cs_fe_l4proto(rule, policy) == CS_FE_L4_TCP)
+		INCLUDE_MASK(FE_HM_TCP_CTRL_MASK, 0x38);
+	INCLUDE_MASK(FE_HM_DSCP_MASK, policy->exact_dscp ? 0 : 1);
+	if (!rule->ingress.tag_mode)
+		INCLUDE_MASK(FE_HM_ETHERTYPE_MASK, 0);
+	INCLUDE_MASK(FE_HM_IP_FRAGMENT_MASK, 0);
+	if (policy->require_mtu_range) {
+		/*
+		 * Compare the positive range bit and require clear parser errors.
+		 * No new ACL action can override other firewall decisions.
+		 */
+		INCLUDE_MASK(FE_HM_PKTLEN_RNG_MATCH_VECTOR_MASK,
+			     0xfU ^ policy->require_mtu_range);
+		INCLUDE_MASK(FE_HM_L3_CHKSUM_ERR_MASK, 0);
+		INCLUDE_MASK(FE_HM_L4_CHKSUM_ERR_MASK, 0);
+		INCLUDE_MASK(FE_HM_NOT_HDR_A_FLAGS_STSVLD_MASK, 0);
+	}
+	INCLUDE_MASK(FE_HM_KEYGEN_POLY_SEL, 0);
+	INCLUDE_MASK(FE_HM_IP_VER_MASK, 0);
+	INCLUDE_MASK(FE_HM_IP_VLD_MASK, 0);
+	INCLUDE_MASK(FE_HM_L4_PORTS_RNGD, 0);
+	INCLUDE_MASK(FE_HM_L4_DP_MASK, 0);
+	INCLUDE_MASK(FE_HM_L4_SP_MASK, 0);
+	INCLUDE_MASK(FE_HM_L4_VLD_MASK, 0);
+	INCLUDE_MASK(FE_HM_LSPID_MASK, 0);
+	/* Preserve the observed reserved bit instead of copying legacy memsetff. */
+	INCLUDE_MASK(FE_HM_RSVD_109, 0);
+	INCLUDE_MASK(FE_HM_PARITY, 0);
+#undef INCLUDE_MASK
+	memcpy(out, payload, sizeof(payload));
+}
+
+static void build_sdb(const struct cs_fe_rows *rows, u32 out[7])
+{
+	u32 payload[7] = { 0 };
+
+	/* SDB tuple0 enable[0], mask[6:1], priority[10:7]. */
+	LOOKUP_FIELD(payload, FE_SDB_HTUPL_EN_0, 1);
+	LOOKUP_FIELD(payload, FE_SDB_HTUPL_MASK_PTR_0, rows->mask_row);
+	LOOKUP_FIELD(payload, FE_SDB_HTUPL_PRI_0, 0);
+	LOOKUP_FIELD(payload, FE_SDB_TTL_HOPLIMIT_ZERO_DISCARD_EN,
+		     1); /* inherited TTL-zero policy */
+	LOOKUP_FIELD(payload, FE_SDB_UU_FLOWIDX,
+		     rows->miss_fwd); /* unknown unicast */
+	LOOKUP_FIELD(payload, FE_SDB_BC_FLOWIDX,
+		     rows->miss_fwd); /* broadcast */
+	LOOKUP_FIELD(payload, FE_SDB_UM_FLOWIDX,
+		     rows->miss_fwd); /* unknown multicast */
+	/* KEYRULE0, LPM/other tuples/drop/rewrites/ACL override remain zero. */
+	memcpy(out, payload, sizeof(payload));
+}
+
+static void build_class(const struct cs_fe_rule *rule,
+			const struct cs_fe_rows *rows, u8 l4proto, bool valid,
+			u32 out[20])
+{
+	u32 payload[20];
+	unsigned int index;
+
+	for (index = 0; index < 20; index++)
+		payload[index] = 0xffffffffU;
+	/* A coarse typed protocol/port/domain selector; full tuple goes in HASH. */
+	LOOKUP_FIELD(payload, FE_CLASS_SVIDX, rows->sdb_row);
+	LOOKUP_FIELD(payload, FE_CLASS_LSPID, rule->ingress.gmac);
+	LOOKUP_FIELD(payload, FE_CLASS_LSPID_MASK, 0);
+	LOOKUP_FIELD(payload, FE_CLASS_TPID_ENC_1,
+		     rule->ingress.tag_mode ? 4 : 0);
+	LOOKUP_FIELD(payload, FE_CLASS_8021P_1,
+		     rule->ingress.rx_qca_meta >> 13);
+	LOOKUP_FIELD(payload, FE_CLASS_VID_1, rule->ingress.rx_qca_meta & 4095);
+	LOOKUP_FIELD(payload, FE_CLASS_TPID_ENC_2, 0);
+	LOOKUP_FIELD(payload, FE_CLASS_TPID_ENC_1_MSB_MASK, 0);
+	LOOKUP_FIELD(payload, FE_CLASS_TPID_ENC_1_LSB_MASK, 0);
+	LOOKUP_FIELD(payload, FE_CLASS_8021P_1_MASK, 0);
+	LOOKUP_FIELD(payload, FE_CLASS_VID_1_MASK, 0);
+	LOOKUP_FIELD(payload, FE_CLASS_TPID_ENC_2_MSB_MASK, 0);
+	LOOKUP_FIELD(payload, FE_CLASS_IP_DA_MASK, 0);
+	LOOKUP_FIELD(payload, FE_CLASS_IP_SA_MASK, 0);
+	LOOKUP_FIELD(payload, FE_CLASS_MCGID, 0);
+	LOOKUP_FIELD(payload, FE_CLASS_MCGID_MASK, 0);
+	LOOKUP_FIELD(payload, FE_CLASS_RSVD_621_606, 0);
+	LOOKUP_FIELD(payload, FE_CLASS_RULE_PRI, rows->priority);
+	LOOKUP_FIELD(payload, FE_CLASS_ENTRY_VLD, valid);
+	LOOKUP_FIELD(payload, FE_CLASS_MEM_PARITY, 0);
+	LOOKUP_FIELD(payload, FE_CLASS_DATA19_RSRVD, 0);
+	LOOKUP_FIELD(payload, FE_CLASS_IP_PROT, l4proto);
+	LOOKUP_FIELD(payload, FE_CLASS_L4_SP, rule->original.sport);
+	LOOKUP_FIELD(payload, FE_CLASS_L4_DP, rule->original.dport);
+	LOOKUP_FIELD(payload, FE_CLASS_IP_VLD, 1);
+	LOOKUP_FIELD(payload, FE_CLASS_IP_VER, 0);
+	LOOKUP_FIELD(payload, FE_CLASS_IP_FRAGMENT, 0);
+	LOOKUP_FIELD(payload, FE_CLASS_L4_VLD, 1);
+	LOOKUP_FIELD(payload, FE_CLASS_IP_PROT_MASK, 0);
+	LOOKUP_FIELD(payload, FE_CLASS_L4_PORT_MASK, 0);
+	LOOKUP_FIELD(payload, FE_CLASS_IP_VLD_MASK, 0);
+	LOOKUP_FIELD(payload, FE_CLASS_IP_VER_MASK, 0);
+	LOOKUP_FIELD(payload, FE_CLASS_IP_FRAGMENT_MASK, 0);
+	LOOKUP_FIELD(payload, FE_CLASS_L4_VLD_MASK, 0);
+	memcpy(out, payload, sizeof(payload));
+}
+
+static void cs_fe_finish_image(u32 *input, u32 *expected, unsigned int words,
+			       int parity_bit)
+{
+	unsigned int index, bit, ones = 0;
+
+	if (parity_bit >= 0)
+		lookup_store_bits(input, parity_bit, 1, 0);
+	memcpy(expected, input, words * sizeof(*input));
+	if (parity_bit < 0)
+		return;
+
+	for (index = 0; index < words; index++) {
+		for (bit = 0; bit < 32; bit++)
+			ones += (input[index] >> bit) & 1;
+	}
+	lookup_store_bits(expected, parity_bit, 1, ones & 1);
+}
+
+#define CS_FE_FINISH_IMAGE(member, count, parity)                            \
+	do {                                                                 \
+		(member).words = count;                                      \
+		cs_fe_finish_image((member).input, (member).expected, count, \
+				   parity);                                  \
+	} while (0)
+/*
+ * CLASS address fields from cs_fe_class_fields in the vendor register map.
+ * IPv4 occupies the first of four words. The CLASS IP masks encode a prefix
+ * length, as in the vendor IPv4 multicast class (prefix 4).
+ */
+static void cs_fe_class_ip(u32 *words, unsigned int start, u32 address)
+{
+	unsigned int index;
+
+	lookup_store_bits(words, start, 32, address);
+	for (index = 1; index < 4; index++)
+		lookup_store_bits(words, start + 32 * index, 32, 0);
+}
+
+static void cs_fe_class_mac(u32 *words, unsigned int start, const u8 address[6],
+			    bool reverse)
+{
+	unsigned int index;
+
+	for (index = 0; index < 6; index++)
+		lookup_store_bits(words, start + 8 * index, 8,
+				  address[reverse ? 5 - index : index]);
+}
+
+static void cs_fe_class_address_inputs(u32 *words,
+				       const struct cs_fe_tuple *tuple,
+				       const u8 source[6],
+				       const u8 destination[6],
+				       unsigned int match)
+{
+	bool reverse = match & CS_FE_CLASS_MATCH_REVERSED_MAC;
+
+	if (match & CS_FE_CLASS_MATCH_DA) {
+		cs_fe_class_mac(words, FE_CLASS_DA_START, destination, reverse);
+		LOOKUP_FIELD(words, FE_CLASS_DA_MASK, 0);
+	}
+	if (match & CS_FE_CLASS_MATCH_SA) {
+		cs_fe_class_mac(words, FE_CLASS_SA_START, source, reverse);
+		LOOKUP_FIELD(words, FE_CLASS_SA_MASK, 0);
+	}
+	if (match & CS_FE_CLASS_MATCH_IP_DA) {
+		cs_fe_class_ip(words, FE_CLASS_IP_DA_START, tuple->dst);
+		LOOKUP_FIELD(words, FE_CLASS_IP_DA_MASK, 32);
+	}
+	if (match & CS_FE_CLASS_MATCH_IP_SA) {
+		cs_fe_class_ip(words, FE_CLASS_IP_SA_START, tuple->src);
+		LOOKUP_FIELD(words, FE_CLASS_IP_SA_MASK, 32);
+	}
+}
+
+void cs_fe_class_addresses(struct cs_fe_plan *plan,
+			   const struct cs_fe_tuple *tuple, const u8 source[6],
+			   const u8 destination[6], unsigned int match)
+{
+	cs_fe_class_address_inputs(plan->class_invalid.input, tuple, source,
+				   destination, match);
+	cs_fe_class_address_inputs(plan->class_valid.input, tuple, source,
+				   destination, match);
+	CS_FE_FINISH_IMAGE(plan->class_invalid, 20, 629);
+	CS_FE_FINISH_IMAGE(plan->class_valid, 20, 629);
+}
+
+/*
+ * The wire-order MAC pairs use the following ordering. The selected CS7542 CLASS
+ * MAC comparison consumes the octets starting with the least
+ * significant byte, independently of the IPv4 word order.
+ */
+void cs_fe_exact_class_ipv4(struct cs_fe_plan *plan,
+			    const struct cs_fe_tuple *tuple, const u8 source[6],
+			    const u8 destination[6])
+{
+	cs_fe_class_addresses(plan, tuple, source, destination,
+			      CS_FE_CLASS_MATCH_DA | CS_FE_CLASS_MATCH_SA |
+				      CS_FE_CLASS_MATCH_REVERSED_MAC |
+				      CS_FE_CLASS_MATCH_IP_DA |
+				      CS_FE_CLASS_MATCH_IP_SA);
+}
+
+static bool cs_fe_mac_valid(const u8 *mac)
+{
+	unsigned int index, nonzero = 0;
+
+	for (index = 0; index < 6; index++)
+		nonzero |= mac[index];
+	return nonzero && !(mac[0] & 1);
+}
+
+static bool cs_fe_ip_valid(u32 address)
+{
+	return address && (address >> 24) != 0 && (address >> 24) != 127 &&
+	       (address >> 24) < 224;
+}
+
+static int cs_fe_link_valid(const struct cs_fe_link *link)
+{
+	unsigned int reason = (link->rx_qca_meta >> 6) & 31;
+
+	if (link->gmac != 1 || link->base_voq != 8 || link->cpu_port)
+		return -EOPNOTSUPP;
+
+	if (link->tag_mode == 4) {
+		if (link->switch_port < 1 || link->switch_port > 5)
+			return -EOPNOTSUPP;
+		/* Egress metadata may be0: it is not used for the ingress key. */
+		if (link->rx_qca_meta &&
+		    ((link->rx_qca_meta >> 14) != 2 ||
+		     (link->rx_qca_meta & 7) != link->switch_port ||
+		     reason == 1 || reason == 2))
+			return -EOPNOTSUPP;
+	} else if (link->tag_mode || link->switch_port || link->rx_qca_meta) {
+		return -EOPNOTSUPP;
+	}
+
+	return 0;
+}
+
+static bool cs_fe_row_valid(u16 row, unsigned int limit)
+{
+	return row >= 5 && row < limit;
+}
+
+int cs_fe_encode(const struct cs_fe_rule *rule, const struct cs_fe_rows *rows,
+		 const struct cs_fe_key_policy *policy, struct cs_fe_plan *out)
+{
+	struct cs_fe_plan plan = { 0 };
+	unsigned long long source_mac = 0, destination_mac = 0;
+	bool source_ip_changed, destination_ip_changed;
+	bool source_port_changed, destination_port_changed;
+	u32 *fwd = plan.hit.input;
+	unsigned int index;
+
+	if (!rule || !rows || !policy || !out)
+		return -EINVAL;
+
+	if (cs_fe_link_valid(&rule->ingress) ||
+	    cs_fe_link_valid(&rule->egress) ||
+	    rule->ingress.tag_mode != rule->egress.tag_mode ||
+	    (rule->ingress.tag_mode == 4 && !rule->ingress.rx_qca_meta) ||
+	    !cs_fe_mac_valid(rule->smac) || !cs_fe_mac_valid(rule->dmac) ||
+	    !cs_fe_mac_valid(rule->ingress.base_mac) ||
+	    !cs_fe_mac_valid(rule->egress.base_mac) ||
+	    memcmp(rule->smac, rule->egress.base_mac, sizeof(rule->smac)) ||
+	    !rule->decrement_ttl)
+		return -EOPNOTSUPP;
+
+	if (cs_fe_l4proto(rule, policy) != CS_FE_L4_UDP &&
+	    (cs_fe_l4proto(rule, policy) != CS_FE_L4_TCP || policy->exact_dscp))
+		return -EOPNOTSUPP;
+
+	if (!cs_fe_ip_valid(rule->original.src) ||
+	    !cs_fe_ip_valid(rule->original.dst) ||
+	    !cs_fe_ip_valid(rule->translated.src) ||
+	    !cs_fe_ip_valid(rule->translated.dst) || !rule->original.sport ||
+	    !rule->original.dport || !rule->translated.sport ||
+	    !rule->translated.dport || policy->dscp > 63 ||
+	    (!policy->exact_dscp && policy->dscp) ||
+	    (policy->require_mtu_range != 0 &&
+	     policy->require_mtu_range != CS_FE_MTU_RANGE_SMALL &&
+	     policy->require_mtu_range != CS_FE_MTU_RANGE_1500))
+		return -EOPNOTSUPP;
+
+	if (!cs_fe_row_valid(rows->class_row, 64) ||
+	    !cs_fe_row_valid(rows->sdb_row, 64) ||
+	    !cs_fe_row_valid(rows->mask_row, 64) ||
+	    !cs_fe_row_valid(rows->miss_fwd, 8192) ||
+	    !cs_fe_row_valid(rows->hit_fwd, 8192) ||
+	    rows->miss_fwd == rows->hit_fwd ||
+	    !cs_fe_row_valid(rows->voq, 512) ||
+	    !cs_fe_row_valid(rows->l2, 512) || rows->priority > 63 ||
+	    rows->miss_marker > 0xfffffU)
+		return -ERANGE;
+
+	source_ip_changed = rule->original.src != rule->translated.src;
+	destination_ip_changed = rule->original.dst != rule->translated.dst;
+	source_port_changed = rule->original.sport != rule->translated.sport;
+	destination_port_changed = rule->original.dport !=
+				   rule->translated.dport;
+	plan.source_nat = source_ip_changed || source_port_changed;
+	plan.destination_nat = destination_ip_changed ||
+			       destination_port_changed;
+	plan.write_l3 = source_ip_changed || destination_ip_changed;
+	plan.write_fvlan = rule->egress.tag_mode == 4;
+
+	if ((plan.write_l3 && !cs_fe_row_valid(rows->l3, 1024)) ||
+	    (plan.write_fvlan && !cs_fe_row_valid(rows->fvlan, 512)))
+		return -ERANGE;
+
+	plan.requirements = CS_FE_REQ_PACKET_EXCEPTIONS |
+			    CS_FE_REQ_COLLISION_CHECK |
+			    CS_FE_REQ_OWNER_LIFETIME;
+	build_key(rule, rows, policy, &plan.key);
+	build_mask(rule, policy, plan.mask.input);
+	CS_FE_FINISH_IMAGE(plan.mask, 5, 149);
+	build_class(rule, rows, cs_fe_l4proto(rule, policy), false,
+		    plan.class_invalid.input);
+	CS_FE_FINISH_IMAGE(plan.class_invalid, 20, 629);
+	build_class(rule, rows, cs_fe_l4proto(rule, policy), true,
+		    plan.class_valid.input);
+	CS_FE_FINISH_IMAGE(plan.class_valid, 20, 629);
+	build_sdb(rows, plan.sdb.input);
+	CS_FE_FINISH_IMAGE(plan.sdb, 7, 206);
+
+	/*
+	 * Fallback uses only the physically read/verified reserved VOQ2.
+	 * Diagnostic IP-index markers are never replacement-enabled rows.
+	 */
+	LOOKUP_FIELD(plan.miss.input, FWD_VOQ_POLICY, 1);
+	LOOKUP_FIELD(plan.miss.input, FWD_VOQ_POL_TBL_IDX, 2);
+	LOOKUP_FIELD(plan.miss.input, FWD_IP_SA_IDX, rows->miss_marker & 4095);
+	LOOKUP_FIELD(plan.miss.input, FWD_IP_DA_IDX, rows->miss_marker >> 12);
+	CS_FE_FINISH_IMAGE(plan.miss, 4, 113);
+	plan.voq.input[0] = rule->egress.base_voq;
+	CS_FE_FINISH_IMAGE(plan.voq, 2, 40);
+
+	for (index = 0; index < 6; index++) {
+		source_mac = (source_mac << 8) | rule->smac[index];
+		destination_mac = (destination_mac << 8) | rule->dmac[index];
+	}
+	plan.l2.input[0] = (u32)source_mac;
+	plan.l2.input[1] = (u32)(source_mac >> 32) |
+			   ((u32)destination_mac << 16);
+	plan.l2.input[2] = (u32)(destination_mac >> 16);
+	CS_FE_FINISH_IMAGE(plan.l2, 4, 96);
+	if (plan.write_l3) {
+		/* Only the replacement indices enabled in FWDRSLT are referenced. */
+		if (source_ip_changed)
+			plan.l3.input[0] = rule->translated.src;
+		if (destination_ip_changed)
+			plan.l3.input[1] = rule->translated.dst;
+		CS_FE_FINISH_IMAGE(plan.l3, 5, 128);
+	}
+
+	LOOKUP_FIELD(fwd, FWD_VOQ_POLICY, 1);
+	LOOKUP_FIELD(fwd, FWD_VOQ_POL_TBL_IDX, rows->voq);
+	if (source_ip_changed) {
+		LOOKUP_FIELD(fwd, FWD_IP_SA_REPLACE_EN, 1);
+		LOOKUP_FIELD(fwd, FWD_IP_SA_IDX, rows->l3 * 4U);
+	}
+	if (destination_ip_changed) {
+		LOOKUP_FIELD(fwd, FWD_IP_DA_REPLACE_EN, 1);
+		LOOKUP_FIELD(fwd, FWD_IP_DA_IDX, rows->l3 * 4U + 1);
+	}
+	if (source_port_changed) {
+		LOOKUP_FIELD(fwd, FWD_L4_SP_REPLACE_EN, 1);
+		LOOKUP_FIELD(fwd, FWD_L4_SP, rule->translated.sport);
+	}
+	if (destination_port_changed) {
+		LOOKUP_FIELD(fwd, FWD_L4_DP_REPLACE_EN, 1);
+		LOOKUP_FIELD(fwd, FWD_L4_DP, rule->translated.dport);
+	}
+	LOOKUP_FIELD(fwd, FWD_MAC_SA_REPLACE_EN, 1);
+	LOOKUP_FIELD(fwd, FWD_MAC_DA_REPLACE_EN, 1);
+	LOOKUP_FIELD(fwd, FWD_L2_IDX, rows->l2);
+	LOOKUP_FIELD(fwd, FWD_DECR_TTL_HOPLIMIT, 1);
+	if (plan.write_fvlan) {
+		u16 vid = 0x80U | (1U << rule->egress.switch_port);
+
+		/* FIRST_CMD SWAP_B=2, TPID0=8100, no second operation. */
+		plan.fvlan.input[0] = 2U | ((u32)vid << 5);
+		CS_FE_FINISH_IMAGE(plan.fvlan, 2, 38);
+		LOOKUP_FIELD(fwd, FWD_FLOW_VLAN_OP_EN, 1);
+		LOOKUP_FIELD(fwd, FWD_FLOW_VLANTBL_IDX, rows->fvlan);
+		plan.predicted_tx_qca = (rule->ingress.rx_qca_meta & 0xf000U) |
+					vid;
+	}
+	CS_FE_FINISH_IMAGE(plan.hit, 4, 113);
+	lookup_store_bits(plan.hash, 0, 32, plan.key.crc32);
+	lookup_store_bits(plan.hash, 32, 13, rows->hit_fwd);
+	lookup_store_bits(plan.hash, 45, 6, rows->mask_row);
+
+	*out = plan;
+	return 0;
+}
diff --git a/drivers/net/ethernet/cortina/cs_fe_encode.h b/drivers/net/ethernet/cortina/cs_fe_encode.h
new file mode 100644
index 000000000..56eca7a35
--- /dev/null
+++ b/drivers/net/ethernet/cortina/cs_fe_encode.h
@@ -0,0 +1,5 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef CS_FE_ENCODE_PRIVATE_SHIM_H
+#define CS_FE_ENCODE_PRIVATE_SHIM_H
+#include <linux/cs7542_fe_codec.h>
+#endif
diff --git a/drivers/net/ethernet/cortina/cs_fe_fields.h b/drivers/net/ethernet/cortina/cs_fe_fields.h
new file mode 100644
index 000000000..ce452b6d6
--- /dev/null
+++ b/drivers/net/ethernet/cortina/cs_fe_fields.h
@@ -0,0 +1,339 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Generated from pinned descriptor extracts; generate_fields.py checks it. */
+#ifndef CS_FE_FIELDS_H
+#define CS_FE_FIELDS_H
+
+enum cs_fe_field_offset {
+	FE_HM_MAC_DA_MASK_START = 0,
+	FE_HM_MAC_DA_MASK_WIDTH = 6,
+	FE_HM_MAC_SA_MASK_START = 6,
+	FE_HM_MAC_SA_MASK_WIDTH = 6,
+	FE_HM_ETHERTYPE_MASK_START = 12,
+	FE_HM_ETHERTYPE_MASK_WIDTH = 1,
+	FE_HM_LLC_TYPE_ENC_MSB_MASK_START = 13,
+	FE_HM_LLC_TYPE_ENC_MSB_MASK_WIDTH = 1,
+	FE_HM_LLC_TYPE_ENC_LSB_MASK_START = 14,
+	FE_HM_LLC_TYPE_ENC_LSB_MASK_WIDTH = 1,
+	FE_HM_TPID_ENC_1_MSB_MASK_START = 15,
+	FE_HM_TPID_ENC_1_MSB_MASK_WIDTH = 1,
+	FE_HM_TPID_ENC_1_LSB_MASK_START = 16,
+	FE_HM_TPID_ENC_1_LSB_MASK_WIDTH = 1,
+	FE_HM_8021P_1_MASK_START = 17,
+	FE_HM_8021P_1_MASK_WIDTH = 1,
+	FE_HM_DEI_1_MASK_START = 18,
+	FE_HM_DEI_1_MASK_WIDTH = 1,
+	FE_HM_VID_1_MASK_START = 19,
+	FE_HM_VID_1_MASK_WIDTH = 1,
+	FE_HM_TPID_ENC_2_MSB_MASK_START = 20,
+	FE_HM_TPID_ENC_2_MSB_MASK_WIDTH = 1,
+	FE_HM_TPID_ENC_2_LSB_MASK_START = 21,
+	FE_HM_TPID_ENC_2_LSB_MASK_WIDTH = 1,
+	FE_HM_8021P_2_MASK_START = 22,
+	FE_HM_8021P_2_MASK_WIDTH = 1,
+	FE_HM_DEI_2_MASK_START = 23,
+	FE_HM_DEI_2_MASK_WIDTH = 1,
+	FE_HM_VID_2_MASK_START = 24,
+	FE_HM_VID_2_MASK_WIDTH = 1,
+	FE_HM_IP_DA_MASK_START = 25,
+	FE_HM_IP_DA_MASK_WIDTH = 9,
+	FE_HM_IP_SA_MASK_START = 34,
+	FE_HM_IP_SA_MASK_WIDTH = 9,
+	FE_HM_IP_PROT_MASK_START = 43,
+	FE_HM_IP_PROT_MASK_WIDTH = 1,
+	FE_HM_DSCP_MASK_START = 44,
+	FE_HM_DSCP_MASK_WIDTH = 6,
+	FE_HM_ECN_MASK_START = 50,
+	FE_HM_ECN_MASK_WIDTH = 2,
+	FE_HM_IP_FRAGMENT_MASK_START = 52,
+	FE_HM_IP_FRAGMENT_MASK_WIDTH = 1,
+	FE_HM_KEYGEN_POLY_SEL_START = 53,
+	FE_HM_KEYGEN_POLY_SEL_WIDTH = 2,
+	FE_HM_IPV6_FLOW_LBL_MASK_START = 55,
+	FE_HM_IPV6_FLOW_LBL_MASK_WIDTH = 1,
+	FE_HM_IP_VER_MASK_START = 56,
+	FE_HM_IP_VER_MASK_WIDTH = 1,
+	FE_HM_IP_VLD_MASK_START = 57,
+	FE_HM_IP_VLD_MASK_WIDTH = 1,
+	FE_HM_L4_PORTS_RNGD_START = 58,
+	FE_HM_L4_PORTS_RNGD_WIDTH = 2,
+	FE_HM_L4_DP_MASK_START = 60,
+	FE_HM_L4_DP_MASK_WIDTH = 16,
+	FE_HM_L4_SP_MASK_START = 76,
+	FE_HM_L4_SP_MASK_WIDTH = 16,
+	FE_HM_TCP_CTRL_MASK_START = 92,
+	FE_HM_TCP_CTRL_MASK_WIDTH = 6,
+	FE_HM_TCP_ECN_MASK_START = 98,
+	FE_HM_TCP_ECN_MASK_WIDTH = 3,
+	FE_HM_L4_VLD_MASK_START = 101,
+	FE_HM_L4_VLD_MASK_WIDTH = 1,
+	FE_HM_LSPID_MASK_START = 102,
+	FE_HM_LSPID_MASK_WIDTH = 1,
+	FE_HM_FWDTYPE_MASK_START = 103,
+	FE_HM_FWDTYPE_MASK_WIDTH = 4,
+	FE_HM_PPPOE_SESSION_ID_VLD_MASK_START = 107,
+	FE_HM_PPPOE_SESSION_ID_VLD_MASK_WIDTH = 1,
+	FE_HM_PPPOE_SESSION_ID_MASK_START = 108,
+	FE_HM_PPPOE_SESSION_ID_MASK_WIDTH = 1,
+	FE_HM_RSVD_109_START = 109,
+	FE_HM_RSVD_109_WIDTH = 1,
+	FE_HM_RECIRC_IDX_MASK_START = 110,
+	FE_HM_RECIRC_IDX_MASK_WIDTH = 1,
+	FE_HM_MCIDX_MASK_START = 111,
+	FE_HM_MCIDX_MASK_WIDTH = 1,
+	FE_HM_MC_DA_MASK_START = 112,
+	FE_HM_MC_DA_MASK_WIDTH = 1,
+	FE_HM_BC_DA_MASK_START = 113,
+	FE_HM_BC_DA_MASK_WIDTH = 1,
+	FE_HM_DA_AN_MAC_SEL_MASK_START = 114,
+	FE_HM_DA_AN_MAC_SEL_MASK_WIDTH = 1,
+	FE_HM_DA_AN_MAC_HIT_MASK_START = 115,
+	FE_HM_DA_AN_MAC_HIT_MASK_WIDTH = 1,
+	FE_HM_ORIG_LSPID_MASK_START = 116,
+	FE_HM_ORIG_LSPID_MASK_WIDTH = 1,
+	FE_HM_L7_FIELD_MASK_START = 117,
+	FE_HM_L7_FIELD_MASK_WIDTH = 1,
+	FE_HM_L7_FIELD_VLD_MASK_START = 118,
+	FE_HM_L7_FIELD_VLD_MASK_WIDTH = 1,
+	FE_HM_HDR_A_FLAGS_CRCERR_MASK_START = 119,
+	FE_HM_HDR_A_FLAGS_CRCERR_MASK_WIDTH = 1,
+	FE_HM_L3_CHKSUM_ERR_MASK_START = 120,
+	FE_HM_L3_CHKSUM_ERR_MASK_WIDTH = 1,
+	FE_HM_L4_CHKSUM_ERR_MASK_START = 121,
+	FE_HM_L4_CHKSUM_ERR_MASK_WIDTH = 1,
+	FE_HM_NOT_HDR_A_FLAGS_STSVLD_MASK_START = 122,
+	FE_HM_NOT_HDR_A_FLAGS_STSVLD_MASK_WIDTH = 1,
+	FE_HM_HASH_FID_MASK_START = 123,
+	FE_HM_HASH_FID_MASK_WIDTH = 1,
+	FE_HM_L7_FIELD_SEL_START = 124,
+	FE_HM_L7_FIELD_SEL_WIDTH = 2,
+	FE_HM_SA_BNG_MAC_SEL_MASK_START = 126,
+	FE_HM_SA_BNG_MAC_SEL_MASK_WIDTH = 1,
+	FE_HM_SA_BNG_MAC_HIT_MASK_START = 127,
+	FE_HM_SA_BNG_MAC_HIT_MASK_WIDTH = 1,
+	FE_HM_SPI_VLD_MASK_START = 128,
+	FE_HM_SPI_VLD_MASK_WIDTH = 1,
+	FE_HM_SPI_MASK_START = 129,
+	FE_HM_SPI_MASK_WIDTH = 1,
+	FE_HM_IPV6_NDP_MASK_START = 130,
+	FE_HM_IPV6_NDP_MASK_WIDTH = 1,
+	FE_HM_IPV6_HBH_MASK_START = 131,
+	FE_HM_IPV6_HBH_MASK_WIDTH = 1,
+	FE_HM_IPV6_RH_MASK_START = 132,
+	FE_HM_IPV6_RH_MASK_WIDTH = 1,
+	FE_HM_IPV6_DOH_MASK_START = 133,
+	FE_HM_IPV6_DOH_MASK_WIDTH = 1,
+	FE_HM_PPP_PROTOCOL_VLD_MASK_START = 134,
+	FE_HM_PPP_PROTOCOL_VLD_MASK_WIDTH = 1,
+	FE_HM_PPP_PROTOCOL_MASK_START = 135,
+	FE_HM_PPP_PROTOCOL_MASK_WIDTH = 1,
+	FE_HM_PKTLEN_RNG_MATCH_VECTOR_MASK_START = 136,
+	FE_HM_PKTLEN_RNG_MATCH_VECTOR_MASK_WIDTH = 4,
+	FE_HM_MCGID_MASK_START = 140,
+	FE_HM_MCGID_MASK_WIDTH = 9,
+	FE_HM_PARITY_START = 149,
+	FE_HM_PARITY_WIDTH = 1,
+	FE_CLASS_SVIDX_START = 0,
+	FE_CLASS_SVIDX_WIDTH = 6,
+	FE_CLASS_LSPID_START = 6,
+	FE_CLASS_LSPID_WIDTH = 4,
+	FE_CLASS_TPID_ENC_1_START = 18,
+	FE_CLASS_TPID_ENC_1_WIDTH = 3,
+	FE_CLASS_VID_1_START = 21,
+	FE_CLASS_VID_1_WIDTH = 12,
+	FE_CLASS_8021P_1_START = 33,
+	FE_CLASS_8021P_1_WIDTH = 3,
+	FE_CLASS_TPID_ENC_2_START = 36,
+	FE_CLASS_TPID_ENC_2_WIDTH = 3,
+	FE_CLASS_DA_START = 118,
+	FE_CLASS_SA_START = 166,
+	FE_CLASS_IP_DA_START = 214,
+	FE_CLASS_IP_SA_START = 342,
+	FE_CLASS_DA_MASK_START = 512,
+	FE_CLASS_DA_MASK_WIDTH = 6,
+	FE_CLASS_SA_MASK_START = 518,
+	FE_CLASS_SA_MASK_WIDTH = 6,
+	FE_CLASS_LSPID_MASK_START = 481,
+	FE_CLASS_LSPID_MASK_WIDTH = 1,
+	FE_CLASS_TPID_ENC_1_MSB_MASK_START = 487,
+	FE_CLASS_TPID_ENC_1_MSB_MASK_WIDTH = 1,
+	FE_CLASS_TPID_ENC_1_LSB_MASK_START = 488,
+	FE_CLASS_TPID_ENC_1_LSB_MASK_WIDTH = 1,
+	FE_CLASS_VID_1_MASK_START = 489,
+	FE_CLASS_VID_1_MASK_WIDTH = 2,
+	FE_CLASS_8021P_1_MASK_START = 491,
+	FE_CLASS_8021P_1_MASK_WIDTH = 1,
+	FE_CLASS_TPID_ENC_2_MSB_MASK_START = 492,
+	FE_CLASS_TPID_ENC_2_MSB_MASK_WIDTH = 1,
+	FE_CLASS_IP_DA_MASK_START = 524,
+	FE_CLASS_IP_DA_MASK_WIDTH = 9,
+	FE_CLASS_IP_SA_MASK_START = 533,
+	FE_CLASS_IP_SA_MASK_WIDTH = 9,
+	FE_CLASS_MCGID_START = 588,
+	FE_CLASS_MCGID_WIDTH = 9,
+	FE_CLASS_MCGID_MASK_START = 597,
+	FE_CLASS_MCGID_MASK_WIDTH = 9,
+	FE_CLASS_RSVD_621_606_START = 606,
+	FE_CLASS_RSVD_621_606_WIDTH = 16,
+	FE_CLASS_RULE_PRI_START = 622,
+	FE_CLASS_RULE_PRI_WIDTH = 6,
+	FE_CLASS_ENTRY_VLD_START = 628,
+	FE_CLASS_ENTRY_VLD_WIDTH = 1,
+	FE_CLASS_MEM_PARITY_START = 629,
+	FE_CLASS_MEM_PARITY_WIDTH = 1,
+	FE_CLASS_DATA19_RSRVD_START = 630,
+	FE_CLASS_DATA19_RSRVD_WIDTH = 10,
+	FE_CLASS_IP_PROT_START = 78,
+	FE_CLASS_IP_PROT_WIDTH = 8,
+	FE_CLASS_L4_SP_START = 86,
+	FE_CLASS_L4_SP_WIDTH = 16,
+	FE_CLASS_L4_DP_START = 102,
+	FE_CLASS_L4_DP_WIDTH = 16,
+	FE_CLASS_IP_VLD_START = 470,
+	FE_CLASS_IP_VLD_WIDTH = 1,
+	FE_CLASS_IP_VER_START = 471,
+	FE_CLASS_IP_VER_WIDTH = 1,
+	FE_CLASS_IP_FRAGMENT_START = 472,
+	FE_CLASS_IP_FRAGMENT_WIDTH = 1,
+	FE_CLASS_L4_VLD_START = 473,
+	FE_CLASS_L4_VLD_WIDTH = 1,
+	FE_CLASS_IP_PROT_MASK_START = 509,
+	FE_CLASS_IP_PROT_MASK_WIDTH = 1,
+	FE_CLASS_L4_PORT_MASK_START = 510,
+	FE_CLASS_L4_PORT_MASK_WIDTH = 2,
+	FE_CLASS_IP_VLD_MASK_START = 542,
+	FE_CLASS_IP_VLD_MASK_WIDTH = 1,
+	FE_CLASS_IP_VER_MASK_START = 543,
+	FE_CLASS_IP_VER_MASK_WIDTH = 1,
+	FE_CLASS_IP_FRAGMENT_MASK_START = 544,
+	FE_CLASS_IP_FRAGMENT_MASK_WIDTH = 1,
+	FE_CLASS_L4_VLD_MASK_START = 545,
+	FE_CLASS_L4_VLD_MASK_WIDTH = 1,
+	FE_SDB_HTUPL_EN_0_START = 0,
+	FE_SDB_HTUPL_EN_0_WIDTH = 1,
+	FE_SDB_HTUPL_MASK_PTR_0_START = 1,
+	FE_SDB_HTUPL_MASK_PTR_0_WIDTH = 6,
+	FE_SDB_HTUPL_PRI_0_START = 7,
+	FE_SDB_HTUPL_PRI_0_WIDTH = 4,
+	FE_SDB_TTL_HOPLIMIT_ZERO_DISCARD_EN_START = 154,
+	FE_SDB_TTL_HOPLIMIT_ZERO_DISCARD_EN_WIDTH = 1,
+	FE_SDB_UU_FLOWIDX_START = 161,
+	FE_SDB_UU_FLOWIDX_WIDTH = 13,
+	FE_SDB_BC_FLOWIDX_START = 176,
+	FE_SDB_BC_FLOWIDX_WIDTH = 13,
+	FE_SDB_UM_FLOWIDX_START = 189,
+	FE_SDB_UM_FLOWIDX_WIDTH = 13,
+	FWD_VOQ_POLICY_START = 0,
+	FWD_VOQ_POLICY_WIDTH = 1,
+	FWD_VOQ_POL_TBL_IDX_START = 3,
+	FWD_VOQ_POL_TBL_IDX_WIDTH = 9,
+	FWD_IP_SA_IDX_START = 13,
+	FWD_IP_SA_IDX_WIDTH = 12,
+	FWD_IP_DA_IDX_START = 26,
+	FWD_IP_DA_IDX_WIDTH = 12,
+	FWD_IP_SA_REPLACE_EN_START = 12,
+	FWD_IP_SA_REPLACE_EN_WIDTH = 1,
+	FWD_IP_DA_REPLACE_EN_START = 25,
+	FWD_IP_DA_REPLACE_EN_WIDTH = 1,
+	FWD_L4_SP_REPLACE_EN_START = 38,
+	FWD_L4_SP_REPLACE_EN_WIDTH = 1,
+	FWD_L4_SP_START = 39,
+	FWD_L4_SP_WIDTH = 16,
+	FWD_L4_DP_REPLACE_EN_START = 55,
+	FWD_L4_DP_REPLACE_EN_WIDTH = 1,
+	FWD_L4_DP_START = 56,
+	FWD_L4_DP_WIDTH = 16,
+	FWD_MAC_SA_REPLACE_EN_START = 72,
+	FWD_MAC_SA_REPLACE_EN_WIDTH = 1,
+	FWD_MAC_DA_REPLACE_EN_START = 73,
+	FWD_MAC_DA_REPLACE_EN_WIDTH = 1,
+	FWD_L2_IDX_START = 74,
+	FWD_L2_IDX_WIDTH = 9,
+	FWD_DECR_TTL_HOPLIMIT_START = 99,
+	FWD_DECR_TTL_HOPLIMIT_WIDTH = 1,
+	FWD_FLOW_VLAN_OP_EN_START = 100,
+	FWD_FLOW_VLAN_OP_EN_WIDTH = 1,
+	FWD_FLOW_VLANTBL_IDX_START = 101,
+	FWD_FLOW_VLANTBL_IDX_WIDTH = 9,
+};
+
+struct cs_fe_mask_field {
+	unsigned int start;
+	unsigned int width;
+};
+
+static const struct cs_fe_mask_field cs_fe_mask_fields[] = {
+	{ FE_HM_MAC_DA_MASK_START, FE_HM_MAC_DA_MASK_WIDTH },
+	{ FE_HM_MAC_SA_MASK_START, FE_HM_MAC_SA_MASK_WIDTH },
+	{ FE_HM_ETHERTYPE_MASK_START, FE_HM_ETHERTYPE_MASK_WIDTH },
+	{ FE_HM_LLC_TYPE_ENC_MSB_MASK_START,
+	  FE_HM_LLC_TYPE_ENC_MSB_MASK_WIDTH },
+	{ FE_HM_LLC_TYPE_ENC_LSB_MASK_START,
+	  FE_HM_LLC_TYPE_ENC_LSB_MASK_WIDTH },
+	{ FE_HM_TPID_ENC_1_MSB_MASK_START, FE_HM_TPID_ENC_1_MSB_MASK_WIDTH },
+	{ FE_HM_TPID_ENC_1_LSB_MASK_START, FE_HM_TPID_ENC_1_LSB_MASK_WIDTH },
+	{ FE_HM_8021P_1_MASK_START, FE_HM_8021P_1_MASK_WIDTH },
+	{ FE_HM_DEI_1_MASK_START, FE_HM_DEI_1_MASK_WIDTH },
+	{ FE_HM_VID_1_MASK_START, FE_HM_VID_1_MASK_WIDTH },
+	{ FE_HM_TPID_ENC_2_MSB_MASK_START, FE_HM_TPID_ENC_2_MSB_MASK_WIDTH },
+	{ FE_HM_TPID_ENC_2_LSB_MASK_START, FE_HM_TPID_ENC_2_LSB_MASK_WIDTH },
+	{ FE_HM_8021P_2_MASK_START, FE_HM_8021P_2_MASK_WIDTH },
+	{ FE_HM_DEI_2_MASK_START, FE_HM_DEI_2_MASK_WIDTH },
+	{ FE_HM_VID_2_MASK_START, FE_HM_VID_2_MASK_WIDTH },
+	{ FE_HM_IP_DA_MASK_START, FE_HM_IP_DA_MASK_WIDTH },
+	{ FE_HM_IP_SA_MASK_START, FE_HM_IP_SA_MASK_WIDTH },
+	{ FE_HM_IP_PROT_MASK_START, FE_HM_IP_PROT_MASK_WIDTH },
+	{ FE_HM_DSCP_MASK_START, FE_HM_DSCP_MASK_WIDTH },
+	{ FE_HM_ECN_MASK_START, FE_HM_ECN_MASK_WIDTH },
+	{ FE_HM_IP_FRAGMENT_MASK_START, FE_HM_IP_FRAGMENT_MASK_WIDTH },
+	{ FE_HM_KEYGEN_POLY_SEL_START, FE_HM_KEYGEN_POLY_SEL_WIDTH },
+	{ FE_HM_IPV6_FLOW_LBL_MASK_START, FE_HM_IPV6_FLOW_LBL_MASK_WIDTH },
+	{ FE_HM_IP_VER_MASK_START, FE_HM_IP_VER_MASK_WIDTH },
+	{ FE_HM_IP_VLD_MASK_START, FE_HM_IP_VLD_MASK_WIDTH },
+	{ FE_HM_L4_PORTS_RNGD_START, FE_HM_L4_PORTS_RNGD_WIDTH },
+	{ FE_HM_L4_DP_MASK_START, FE_HM_L4_DP_MASK_WIDTH },
+	{ FE_HM_L4_SP_MASK_START, FE_HM_L4_SP_MASK_WIDTH },
+	{ FE_HM_TCP_CTRL_MASK_START, FE_HM_TCP_CTRL_MASK_WIDTH },
+	{ FE_HM_TCP_ECN_MASK_START, FE_HM_TCP_ECN_MASK_WIDTH },
+	{ FE_HM_L4_VLD_MASK_START, FE_HM_L4_VLD_MASK_WIDTH },
+	{ FE_HM_LSPID_MASK_START, FE_HM_LSPID_MASK_WIDTH },
+	{ FE_HM_FWDTYPE_MASK_START, FE_HM_FWDTYPE_MASK_WIDTH },
+	{ FE_HM_PPPOE_SESSION_ID_VLD_MASK_START,
+	  FE_HM_PPPOE_SESSION_ID_VLD_MASK_WIDTH },
+	{ FE_HM_PPPOE_SESSION_ID_MASK_START,
+	  FE_HM_PPPOE_SESSION_ID_MASK_WIDTH },
+	{ FE_HM_RSVD_109_START, FE_HM_RSVD_109_WIDTH },
+	{ FE_HM_RECIRC_IDX_MASK_START, FE_HM_RECIRC_IDX_MASK_WIDTH },
+	{ FE_HM_MCIDX_MASK_START, FE_HM_MCIDX_MASK_WIDTH },
+	{ FE_HM_MC_DA_MASK_START, FE_HM_MC_DA_MASK_WIDTH },
+	{ FE_HM_BC_DA_MASK_START, FE_HM_BC_DA_MASK_WIDTH },
+	{ FE_HM_DA_AN_MAC_SEL_MASK_START, FE_HM_DA_AN_MAC_SEL_MASK_WIDTH },
+	{ FE_HM_DA_AN_MAC_HIT_MASK_START, FE_HM_DA_AN_MAC_HIT_MASK_WIDTH },
+	{ FE_HM_ORIG_LSPID_MASK_START, FE_HM_ORIG_LSPID_MASK_WIDTH },
+	{ FE_HM_L7_FIELD_MASK_START, FE_HM_L7_FIELD_MASK_WIDTH },
+	{ FE_HM_L7_FIELD_VLD_MASK_START, FE_HM_L7_FIELD_VLD_MASK_WIDTH },
+	{ FE_HM_HDR_A_FLAGS_CRCERR_MASK_START,
+	  FE_HM_HDR_A_FLAGS_CRCERR_MASK_WIDTH },
+	{ FE_HM_L3_CHKSUM_ERR_MASK_START, FE_HM_L3_CHKSUM_ERR_MASK_WIDTH },
+	{ FE_HM_L4_CHKSUM_ERR_MASK_START, FE_HM_L4_CHKSUM_ERR_MASK_WIDTH },
+	{ FE_HM_NOT_HDR_A_FLAGS_STSVLD_MASK_START,
+	  FE_HM_NOT_HDR_A_FLAGS_STSVLD_MASK_WIDTH },
+	{ FE_HM_HASH_FID_MASK_START, FE_HM_HASH_FID_MASK_WIDTH },
+	{ FE_HM_L7_FIELD_SEL_START, FE_HM_L7_FIELD_SEL_WIDTH },
+	{ FE_HM_SA_BNG_MAC_SEL_MASK_START, FE_HM_SA_BNG_MAC_SEL_MASK_WIDTH },
+	{ FE_HM_SA_BNG_MAC_HIT_MASK_START, FE_HM_SA_BNG_MAC_HIT_MASK_WIDTH },
+	{ FE_HM_SPI_VLD_MASK_START, FE_HM_SPI_VLD_MASK_WIDTH },
+	{ FE_HM_SPI_MASK_START, FE_HM_SPI_MASK_WIDTH },
+	{ FE_HM_IPV6_NDP_MASK_START, FE_HM_IPV6_NDP_MASK_WIDTH },
+	{ FE_HM_IPV6_HBH_MASK_START, FE_HM_IPV6_HBH_MASK_WIDTH },
+	{ FE_HM_IPV6_RH_MASK_START, FE_HM_IPV6_RH_MASK_WIDTH },
+	{ FE_HM_IPV6_DOH_MASK_START, FE_HM_IPV6_DOH_MASK_WIDTH },
+	{ FE_HM_PPP_PROTOCOL_VLD_MASK_START,
+	  FE_HM_PPP_PROTOCOL_VLD_MASK_WIDTH },
+	{ FE_HM_PPP_PROTOCOL_MASK_START, FE_HM_PPP_PROTOCOL_MASK_WIDTH },
+	{ FE_HM_PKTLEN_RNG_MATCH_VECTOR_MASK_START,
+	  FE_HM_PKTLEN_RNG_MATCH_VECTOR_MASK_WIDTH },
+	{ FE_HM_MCGID_MASK_START, FE_HM_MCGID_MASK_WIDTH },
+	{ FE_HM_PARITY_START, FE_HM_PARITY_WIDTH },
+};
+
+#endif
diff --git a/drivers/net/ethernet/cortina/cs_fe_format.h b/drivers/net/ethernet/cortina/cs_fe_format.h
new file mode 100644
index 000000000..ff65f08e3
--- /dev/null
+++ b/drivers/net/ethernet/cortina/cs_fe_format.h
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef CS_FE_FORMAT_H
+#define CS_FE_FORMAT_H
+
+/* Epochs from different format owners are separate domains. */
+enum cs_fe_format_kind {
+	CS_FE_FORMAT_NONE,
+	CS_FE_FORMAT_TIMED,
+	CS_FE_FORMAT_PERSISTENT,
+};
+
+struct cs_fe_format_cookie {
+	enum cs_fe_format_kind kind;
+	u64 epoch;
+};
+
+static inline bool cs_fe_format_equal(const struct cs_fe_format_cookie *left,
+				      const struct cs_fe_format_cookie *right)
+{
+	return left->kind == right->kind && left->epoch == right->epoch;
+}
+
+#endif
diff --git a/drivers/net/ethernet/cortina/cs_fe_hot.c b/drivers/net/ethernet/cortina/cs_fe_hot.c
new file mode 100644
index 000000000..3c227707f
--- /dev/null
+++ b/drivers/net/ethernet/cortina/cs_fe_hot.c
@@ -0,0 +1,84 @@
+// SPDX-License-Identifier: GPL-2.0
+#ifdef __KERNEL__
+#include <linux/errno.h>
+#include <linux/string.h>
+#else
+#include <errno.h>
+#include <string.h>
+#endif
+#include "cs_fe_hot.h"
+#define HOT_ACCESS 0x2048U
+#define HOT_DATA0 0x2050U
+#define HOT_DATA1 0x204cU
+#define HOT_START (1U << 31)
+static int hot_wait(const struct cs_fe_backend_io *io,
+		    unsigned long long deadline)
+{
+	unsigned long long local = io->now_us(io->context) + 1000U;
+	u32 v;
+	int error;
+
+	for (;;) {
+		if (io->now_us(io->context) >= deadline)
+			return -ETIMEDOUT;
+		error = io->read32(io->context, HOT_ACCESS, &v);
+		if (error)
+			return error;
+		if (io->now_us(io->context) >= deadline)
+			return -ETIMEDOUT;
+		if (!(v & HOT_START))
+			return 0;
+		if (io->now_us(io->context) >= local)
+			return -ETIMEDOUT;
+	}
+}
+
+int cs_fe_hot_read(const struct cs_fe_backend_io *io, unsigned int bucket,
+		   struct cs7542_fe_hot_sample *out)
+{
+	unsigned int i;
+	unsigned long long deadline = io ? io->limit_us : 0;
+	int error;
+
+	if (!out || bucket >= 4096)
+		return -EINVAL;
+	memset(out, 0, sizeof(*out));
+	out->attempted = true;
+	out->error = -EINPROGRESS;
+	if (!io || !io->context || !io->now_us || !io->read32 || !io->write32 ||
+	    io->extent < HOT_DATA0 + 4) {
+		out->error = -EINVAL;
+		return -EINVAL;
+	}
+	error = hot_wait(io, deadline);
+	if (!error && io->now_us(io->context) >= deadline)
+		error = -ETIMEDOUT;
+	/* READ opcode only: never RBW30, DATA or bitmap clear writes. */
+	if (!error)
+		error = io->write32(io->context, HOT_ACCESS,
+				    HOT_START | ((bucket * 6U) >> 6));
+	if (!error)
+		error = hot_wait(io, deadline);
+	for (i = 0; !error && i < 2; i++) {
+		if (io->now_us(io->context) >= deadline) {
+			error = -ETIMEDOUT;
+			break;
+		}
+		error = io->read32(io->context, i ? HOT_DATA1 : HOT_DATA0,
+				   &out->data[i]);
+		if (!error)
+			out->valid_words++;
+	}
+	if (!error && io->now_us(io->context) >= deadline)
+		error = -ETIMEDOUT;
+	out->word = (bucket * 6U) >> 6;
+	out->bit = (bucket * 6U) & 63U;
+	out->timestamp_us = io->now_us(io->context);
+	out->error = error;
+	if (!error) {
+		out->selected =
+			!!(out->data[out->bit / 32] & (1U << (out->bit % 32)));
+		out->complete = true;
+	}
+	return error;
+}
diff --git a/drivers/net/ethernet/cortina/cs_fe_hot.h b/drivers/net/ethernet/cortina/cs_fe_hot.h
new file mode 100644
index 000000000..4f30e0257
--- /dev/null
+++ b/drivers/net/ethernet/cortina/cs_fe_hot.h
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef CS_FE_HOT_H
+#define CS_FE_HOT_H
+#include "cs_fe_backend.h"
+struct cs7542_fe_hot_sample {
+	u64 timestamp_us;
+	u32 attempted, complete, valid_words, data[2], selected, word, bit;
+	int error;
+};
+
+/* Internal numeric bucket from an ACTUAL own lease; no public row selector. */
+
+int cs_fe_hot_read(const struct cs_fe_backend_io *io, unsigned int bucket,
+		   struct cs7542_fe_hot_sample *out);
+#endif
diff --git a/drivers/net/ethernet/cortina/cs_fe_hot_access.c b/drivers/net/ethernet/cortina/cs_fe_hot_access.c
new file mode 100644
index 000000000..6c37bd7ad
--- /dev/null
+++ b/drivers/net/ethernet/cortina/cs_fe_hot_access.c
@@ -0,0 +1,276 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "cs_fe_hot_access.h"
+#include "cs_fe_hot_compare.h"
+#ifdef __KERNEL__
+#include <linux/errno.h>
+#include <linux/string.h>
+#else
+#include <errno.h>
+#include <string.h>
+#endif
+static const unsigned int hot_words[CS_BE_TABLES] = {
+	[CS_BE_CLASS] = 20,   [CS_BE_SDB] = 7,	[CS_BE_FWD] = 4,
+	[CS_BE_VOQ] = 2,      [CS_BE_MASK] = 5, [CS_BE_HASH] = 4,
+	[CS_BE_OVERFLOW] = 2, [CS_BE_L2] = 4,	[CS_BE_L3] = 5,
+	[CS_BE_FVLAN] = 2,
+};
+
+static bool geometry(unsigned int slot, const struct cs_fe_rows *r)
+{
+	unsigned int g = r->voq - 5U;
+
+	return r->class_row == 5 + slot && r->sdb_row == 5 + slot &&
+	       r->mask_row == 5 + slot && r->miss_fwd == 5 + 2 * slot &&
+	       g < CS_FE_BACKEND_ACTIONS && r->hit_fwd == 6 + 2 * g &&
+	       r->l2 == r->voq && r->l3 == r->voq && r->fvlan == r->voq &&
+	       r->priority == 51 && r->miss_marker == 0x5a123;
+}
+
+_Static_assert(CS_FE_HOT_SLOTS <= 32, "selector member bits fit in u32");
+
+_Static_assert(5 + 3 * CS_FE_HOT_SLOTS <= 64,
+	       "private ACL guards fit the low bank");
+
+int cs_fe_hot_graph(const struct cs_fe_hot_ledger *ledger,
+		    unsigned int selector, const struct cs_fe_hot_slot **anchor)
+{
+	const struct cs_fe_hot_slot *member, *root;
+	const struct cs_fe_hot_action *graph;
+	unsigned int base;
+
+	if (!ledger || !anchor || selector >= CS_FE_HOT_SLOTS)
+		return -EINVAL;
+	member = &ledger->slots[selector];
+	if (!member->claimed || !geometry(selector, &member->rows))
+		return -EUCLEAN;
+	graph = &ledger->actions[member->rows.voq - 5U];
+	base = graph->anchor_plus_one - 1U;
+	if (base >= CS_FE_HOT_SLOTS || !(graph->members & (1U << selector)) ||
+	    !(graph->members & (1U << base)) ||
+	    (graph->visible & ~graph->members))
+		return -EUCLEAN;
+	root = &ledger->slots[base];
+	if (!root->claimed || !geometry(base, &root->rows) ||
+	    root->rows.voq != member->rows.voq ||
+	    (base != selector &&
+	     !cs_fe_hot_egress_equal(&root->plan, &member->plan)))
+		return -EUCLEAN;
+	*anchor = root;
+	return 0;
+}
+
+#define RESULT_BITS                                                 \
+	(CS_FE_HOT_DEP_HIT | CS_FE_HOT_DEP_VOQ | CS_FE_HOT_DEP_L2 | \
+	 CS_FE_HOT_DEP_L3 | CS_FE_HOT_DEP_FVLAN)
+static u32 required(const struct cs_fe_plan *p)
+{
+	return CS_FE_HOT_DEP_MASK | CS_FE_HOT_DEP_SDB | CS_FE_HOT_DEP_MISS |
+	       CS_FE_HOT_DEP_HIT | CS_FE_HOT_DEP_VOQ | CS_FE_HOT_DEP_L2 |
+	       (p->write_l3 ? CS_FE_HOT_DEP_L3 : 0) |
+	       (p->write_fvlan ? CS_FE_HOT_DEP_FVLAN : 0);
+}
+
+static bool same(const u32 *a, const u32 *b, unsigned int words)
+{
+	return !memcmp(a, b, words * sizeof(u32));
+}
+
+static bool zero(const u32 *a, unsigned int words)
+{
+	unsigned int i;
+
+	for (i = 0; i < words; i++)
+		if (a[i])
+			return false;
+	return true;
+}
+
+int cs_fe_hot_access(const struct cs_fe_hot_ledger *ledger, unsigned int table,
+		     unsigned int row, bool write, const u32 *input,
+		     const u32 *expected, unsigned int words,
+		     struct cs_fe_hot_access_result *out)
+{
+	const struct cs_fe_hot_slot *slot = NULL, *anchor;
+	const struct cs_fe_plan *plan;
+	const u32 *canonical_input = NULL, *canonical_expected = NULL;
+	unsigned int i, other, count = 0, canonical_words = words;
+	u32 role = 0;
+	bool publish = false;
+
+	if (!out)
+		return -EINVAL;
+	out->slot = ~0U;
+	out->dependency_bit = 0;
+	if (!ledger || table >= CS_BE_TABLES || words != hot_words[table] ||
+	    (write && (!input || !expected)))
+		return -EINVAL;
+	if (write && ledger->blocked)
+		return -ESHUTDOWN;
+	if (write && ledger->pending)
+		return -EBUSY;
+	for (i = 0; i < CS_FE_HOT_SLOTS; i++) {
+		const struct cs_fe_hot_slot *s = &ledger->slots[i];
+
+		if (!s->claimed)
+			continue;
+		if (cs_fe_hot_graph(ledger, i, &anchor) ||
+		    s->plan.key.bucket >= 4096 ||
+		    s->plan.key.bucket != (s->plan.key.crc16 >> 4))
+			return -EUCLEAN;
+		for (other = 0; other < i; other++)
+			if (ledger->slots[other].claimed &&
+			    ledger->slots[other].plan.key.bucket ==
+				    s->plan.key.bucket)
+				/* Permanent bucket-to-action ownership is exclusive. */
+				return -EUCLEAN;
+	}
+	if (table == CS_BE_OVERFLOW)
+		return !write && row < 64 ? 0 : -EACCES;
+	if (table == CS_BE_VOQ && row == 2)
+		return write ? -EACCES : 0;
+	for (i = 0; i < CS_FE_HOT_SLOTS; i++) {
+		const struct cs_fe_hot_slot *s = &ledger->slots[i];
+		const struct cs_fe_rows *r = &s->rows;
+		bool hit = false;
+
+		if (!s->claimed)
+			continue;
+		switch (table) {
+		case CS_BE_CLASS:
+			hit = row == r->class_row;
+			break;
+		case CS_BE_SDB:
+			hit = row == r->sdb_row;
+			role = CS_FE_HOT_DEP_SDB;
+			break;
+		case CS_BE_MASK:
+			hit = row == r->mask_row;
+			role = CS_FE_HOT_DEP_MASK;
+			break;
+		case CS_BE_FWD:
+			hit = row == r->miss_fwd || row == r->hit_fwd;
+			role = row == r->miss_fwd ? CS_FE_HOT_DEP_MISS :
+						    CS_FE_HOT_DEP_HIT;
+			break;
+		case CS_BE_VOQ:
+			hit = row == r->voq;
+			role = CS_FE_HOT_DEP_VOQ;
+			break;
+		case CS_BE_L2:
+			hit = row == r->l2;
+			role = CS_FE_HOT_DEP_L2;
+			break;
+		case CS_BE_L3:
+			hit = row == r->l3;
+			role = CS_FE_HOT_DEP_L3;
+			break;
+		case CS_BE_FVLAN:
+			hit = row == r->fvlan;
+			role = CS_FE_HOT_DEP_FVLAN;
+			break;
+		case CS_BE_HASH:
+			hit = row == s->plan.key.bucket ||
+			      (!write && (row == s->plan.key.bucket + 4096U ||
+					  row == s->plan.key.bucket + 8192U));
+			break;
+		default:
+			break;
+		}
+		/*
+		 * Resolve output writes to their single immutable anchor. CLASS/HASH,
+		 * SDB, MASK and the odd CPU miss FWD always belong to the selector.
+		 */
+		if (hit && (role & RESULT_BITS) &&
+		    ledger->actions[r->voq - 5U].anchor_plus_one != i + 1U)
+			continue;
+		if (hit) {
+			slot = s;
+			out->slot = i;
+			out->dependency_bit = role;
+			count++;
+			break;
+		}
+	}
+	if (!count)
+		return -EACCES;
+	if (!write)
+		return 0;
+	plan = &slot->plan;
+#define HOT_IMAGE(name) \
+	do { \
+		canonical_words = plan->name.words; \
+		canonical_input = plan->name.input; \
+		canonical_expected = plan->name.expected; \
+	} while (0)
+	switch (table) {
+	case CS_BE_CLASS:
+		if (plan->class_invalid.words != words ||
+		    plan->class_valid.words != words)
+			return -EUCLEAN;
+		if (same(input, plan->class_invalid.input, words) &&
+		    same(expected, plan->class_invalid.expected, words))
+			return 0; /* Cut is allowed even when dependency setup is incomplete. */
+		canonical_input = plan->class_valid.input;
+		canonical_expected = plan->class_valid.expected;
+		publish = true;
+		break;
+	case CS_BE_HASH:
+		if (zero(input, words) && zero(expected, words))
+			return 0;
+		canonical_input = canonical_expected = plan->hash;
+		publish = true;
+		break;
+	case CS_BE_SDB:
+		HOT_IMAGE(sdb);
+		break;
+	case CS_BE_MASK:
+		HOT_IMAGE(mask);
+		break;
+	case CS_BE_FWD:
+		if (out->dependency_bit == CS_FE_HOT_DEP_MISS)
+			HOT_IMAGE(miss);
+		else
+			HOT_IMAGE(hit);
+		break;
+	case CS_BE_VOQ:
+		HOT_IMAGE(voq);
+		break;
+	case CS_BE_L2:
+		HOT_IMAGE(l2);
+		break;
+	case CS_BE_L3:
+		if (!plan->write_l3)
+			return -EOPNOTSUPP;
+		HOT_IMAGE(l3);
+		break;
+	case CS_BE_FVLAN:
+		if (!plan->write_fvlan)
+			return -EOPNOTSUPP;
+		HOT_IMAGE(fvlan);
+		break;
+	default:
+		return -EACCES;
+	}
+#undef HOT_IMAGE
+	if (canonical_words != words)
+		return -EUCLEAN;
+	if (!same(input, canonical_input, words) ||
+	    !same(expected, canonical_expected, words))
+		return -EINVAL;
+	if (publish) {
+		u32 present;
+
+		if (slot->fenced)
+			return -ESHUTDOWN;
+		if (cs_fe_hot_graph(ledger, out->slot, &anchor))
+			return -EUCLEAN;
+		present = (slot->dependency_written & ~RESULT_BITS) |
+			  (anchor->dependency_written & RESULT_BITS);
+		if ((present & required(plan)) != required(plan))
+			return -EAGAIN;
+	}
+	if (out->dependency_bit &&
+	    (slot->dependency_written & out->dependency_bit))
+		return -EALREADY;
+	return 0;
+}
diff --git a/drivers/net/ethernet/cortina/cs_fe_hot_access.h b/drivers/net/ethernet/cortina/cs_fe_hot_access.h
new file mode 100644
index 000000000..fa0abdca5
--- /dev/null
+++ b/drivers/net/ethernet/cortina/cs_fe_hot_access.h
@@ -0,0 +1,55 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef CS_FE_HOT_ACCESS_H
+#define CS_FE_HOT_ACCESS_H
+#include "cs_fe_backend.h"
+#define CS_FE_HOT_SLOTS CS_FE_BACKEND_LEASES
+#define CS_FE_HOT_DEP_MASK (1U << 0)
+#define CS_FE_HOT_DEP_SDB (1U << 1)
+#define CS_FE_HOT_DEP_MISS (1U << 2)
+#define CS_FE_HOT_DEP_HIT (1U << 3)
+#define CS_FE_HOT_DEP_VOQ (1U << 4)
+#define CS_FE_HOT_DEP_L2 (1U << 5)
+#define CS_FE_HOT_DEP_L3 (1U << 6)
+#define CS_FE_HOT_DEP_FVLAN (1U << 7)
+struct cs_fe_hot_slot {
+	bool claimed, fenced;
+	struct cs_fe_rows rows;
+	struct cs_fe_plan plan;
+	u32 dependency_written;
+};
+
+struct cs_fe_hot_ledger {
+	struct cs_fe_hot_slot slots[CS_FE_HOT_SLOTS];
+	/*
+	 * The first successful claim pins an output image for this owner's epoch.
+	 * A selector keeps its member bit after withdrawal (in-flight packets).
+	 * Visible tracks only CLASS writes that completed hardware readback.
+	 */
+	struct cs_fe_hot_action {
+		unsigned int anchor_plus_one, members, visible;
+		bool native;
+	} actions[CS_FE_BACKEND_ACTIONS];
+	unsigned int pending_selector_plus_one;
+	bool blocked, pending;
+};
+
+int cs_fe_hot_graph(const struct cs_fe_hot_ledger *ledger,
+		    unsigned int selector,
+		    const struct cs_fe_hot_slot **anchor);
+struct cs_fe_hot_access_result {
+	unsigned int slot;
+	u32 dependency_bit;
+};
+
+/*
+ * Pure validation only. Owner resolves epoch/incarnation before this call.
+ *
+ * -EALREADY means identical retained dependency: skip hardware entirely.
+ * Owner journals pending+role BEFORE DATA and clears pending only after full
+ * readback. This helper never changes ledger or proves CLASS/trap phase.
+ */
+int cs_fe_hot_access(const struct cs_fe_hot_ledger *ledger, unsigned int table,
+		     unsigned int row, bool write, const u32 *input,
+		     const u32 *expected, unsigned int words,
+		     struct cs_fe_hot_access_result *out);
+#endif
diff --git a/drivers/net/ethernet/cortina/cs_fe_hot_codec.c b/drivers/net/ethernet/cortina/cs_fe_hot_codec.c
new file mode 100644
index 000000000..73c579326
--- /dev/null
+++ b/drivers/net/ethernet/cortina/cs_fe_hot_codec.c
@@ -0,0 +1,2 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "cs_fe_encode.c"
diff --git a/drivers/net/ethernet/cortina/cs_fe_hot_compare.h b/drivers/net/ethernet/cortina/cs_fe_hot_compare.h
new file mode 100644
index 000000000..74093e6ba
--- /dev/null
+++ b/drivers/net/ethernet/cortina/cs_fe_hot_compare.h
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef CS_FE_HOT_COMPARE_H
+#define CS_FE_HOT_COMPARE_H
+#include "cs_fe_encode.h"
+#ifdef __KERNEL__
+#include <linux/string.h>
+#else
+#include <string.h>
+#endif
+
+/*
+ * At the same physical result indices, compare every word the FE can read
+ * from the shared forwarding result, including the write/readback form.
+ */
+static inline bool cs_fe_hot_egress_equal(const struct cs_fe_plan *a,
+					  const struct cs_fe_plan *b)
+{
+	if (!a || !b || a->requirements != b->requirements ||
+	    a->write_l3 != b->write_l3 || a->write_fvlan != b->write_fvlan ||
+	    a->source_nat != b->source_nat ||
+	    a->destination_nat != b->destination_nat ||
+	    a->predicted_tx_qca != b->predicted_tx_qca)
+		return false;
+#define SAME_IMAGE(name) \
+	(a->name.words == b->name.words && \
+	 !memcmp(a->name.input, b->name.input, sizeof(a->name.input)) && \
+	 !memcmp(a->name.expected, b->name.expected, sizeof(a->name.expected)))
+	return SAME_IMAGE(hit) && SAME_IMAGE(l2) && SAME_IMAGE(l3) &&
+	       SAME_IMAGE(voq) && SAME_IMAGE(fvlan);
+#undef SAME_IMAGE
+}
+
+static inline bool cs_fe_hot_action_equal(const struct cs_fe_plan *a,
+					  const struct cs_fe_plan *b)
+{
+	if (!cs_fe_hot_egress_equal(a, b))
+		return false;
+#define SAME_PRIVATE(name)                                               \
+	(a->name.words == b->name.words &&                               \
+	 !memcmp(a->name.input, b->name.input, sizeof(a->name.input)) && \
+	 !memcmp(a->name.expected, b->name.expected,                     \
+		 sizeof(a->name.expected)))
+	return SAME_PRIVATE(sdb) && SAME_PRIVATE(mask) && SAME_PRIVATE(miss);
+#undef SAME_PRIVATE
+}
+
+#endif
diff --git a/drivers/net/ethernet/cortina/cs_fe_hot_internal.h b/drivers/net/ethernet/cortina/cs_fe_hot_internal.h
new file mode 100644
index 000000000..3728c3f0b
--- /dev/null
+++ b/drivers/net/ethernet/cortina/cs_fe_hot_internal.h
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef CS_FE_HOT_INTERNAL_H
+#define CS_FE_HOT_INTERNAL_H
+#include <linux/cs7542_fe_backend.h>
+#include "cs_fe_hot_access.h"
+#include "cs_fe_hot_lineage.h"
+struct cs_fe_hot_binding {
+	u64 block, version;
+	unsigned long cookie;
+	bool visible, hash_present;
+};
+
+/* Builtin memory: never cleared by module attach/release. */
+
+struct cs_fe_hot_state {
+	struct cs_fe_hot_ledger ledger;
+	struct cs_fe_hot_lineage lineage;
+	struct cs_fe_hot_binding binding[CS_FE_HOT_SLOTS];
+	u64 block_highwater;
+	bool (*guards_ready)(void *context, unsigned int slot);
+	int (*guards_rebind)(void *context, unsigned int slot, const u32 *old_invalid,
+			     const u32 *new_invalid,
+			     unsigned long long end, bool commit);
+	int (*native_range)(void *context, bool prepare, u8 range_bit,
+			    unsigned long long end);
+	void *guard_context;
+};
+
+struct cs_fe_hot_session {
+	struct cs_fe_backend *backend;
+	struct cs_fe_backend_io native;
+	struct cs_fe_hot_request request;
+	enum cs_fe_hot_command command;
+};
+
+struct cs_fe_rows cs_fe_hot_rows(unsigned int slot);
+
+void cs_fe_hot_typed_io(struct cs_fe_hot_session *session,
+			struct cs_fe_backend_io *typed);
+int cs_fe_hot_verify_idle(struct cs_fe_backend *backend,
+			  const struct cs_fe_backend_io *native);
+int cs_fe_live_hot_idle(unsigned int *contexts, unsigned int *leases,
+			bool verify);
+#endif
diff --git a/drivers/net/ethernet/cortina/cs_fe_hot_lineage.c b/drivers/net/ethernet/cortina/cs_fe_hot_lineage.c
new file mode 100644
index 000000000..63f677599
--- /dev/null
+++ b/drivers/net/ethernet/cortina/cs_fe_hot_lineage.c
@@ -0,0 +1,138 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "cs_fe_hot_lineage.h"
+#ifdef __KERNEL__
+#include <linux/errno.h>
+#include <linux/string.h>
+#else
+#include <errno.h>
+#include <string.h>
+#endif
+
+int cs_fe_hot_affinity_claim(struct cs_fe_hot_lineage *lineage,
+			     unsigned int slot, unsigned int bucket)
+{
+	if (!lineage || slot >= CS_FE_HOT_SLOTS || bucket >= CS_FE_HOT_BUCKETS)
+		return -EINVAL;
+	if (lineage->bucket_owner[bucket] &&
+	    lineage->bucket_owner[bucket] != slot + 1)
+		return -EADDRINUSE;
+	lineage->bucket_owner[bucket] = slot + 1;
+	return 0;
+}
+
+static void selector_copy(struct cs_fe_hot_selector_image *out,
+			  const struct cs_fe_plan *plan)
+{
+	out->key = plan->key;
+	memcpy(out->hash, plan->hash, sizeof(out->hash));
+	memcpy(out->invalid_input, plan->class_invalid.input,
+	       sizeof(out->invalid_input));
+	memcpy(out->invalid_expected, plan->class_invalid.expected,
+	       sizeof(out->invalid_expected));
+	memcpy(out->valid_input, plan->class_valid.input,
+	       sizeof(out->valid_input));
+	memcpy(out->valid_expected, plan->class_valid.expected,
+	       sizeof(out->valid_expected));
+}
+
+int cs_fe_hot_lineage_begin(struct cs_fe_hot_lineage *lineage,
+			    unsigned int slot, const struct cs_fe_plan *old,
+			    const struct cs_fe_plan *candidate,
+			    unsigned long long *generation)
+{
+	struct cs_fe_hot_transition *transition;
+	int error;
+
+	if (!lineage || !old || !candidate || !generation ||
+	    slot >= CS_FE_HOT_SLOTS || old->key.bucket >= CS_FE_HOT_BUCKETS ||
+	    candidate->key.bucket >= CS_FE_HOT_BUCKETS ||
+	    old->key.bucket != old->key.crc16 >> 4 ||
+	    candidate->key.bucket != candidate->key.crc16 >> 4 ||
+	    old->class_invalid.words != 20 || old->class_valid.words != 20 ||
+	    candidate->class_invalid.words != 20 ||
+	    candidate->class_valid.words != 20)
+		return -EINVAL;
+	transition = &lineage->transition[slot];
+	if (transition->pending || transition->phase != CS_FE_HOT_IDLE)
+		return -EBUSY;
+	if (transition->generation == ~0ULL)
+		return -EOVERFLOW;
+	if (lineage->bucket_owner[old->key.bucket] != slot + 1)
+		return -EUCLEAN;
+	if (!cs_fe_hot_action_equal(old, candidate))
+		return -EOPNOTSUPP;
+	error = cs_fe_hot_affinity_claim(lineage, slot, candidate->key.bucket);
+	if (error)
+		return error;
+	selector_copy(&transition->old_selector, old);
+	selector_copy(&transition->new_selector, candidate);
+	transition->generation++;
+	transition->phase = CS_FE_HOT_NEW_INVALID;
+	*generation = transition->generation;
+	return 0;
+}
+
+static int transition_get(struct cs_fe_hot_lineage *lineage, unsigned int slot,
+			  unsigned long long generation,
+			  struct cs_fe_hot_transition **out)
+{
+	if (!lineage || slot >= CS_FE_HOT_SLOTS || !generation)
+		return -EINVAL;
+	*out = &lineage->transition[slot];
+	if ((*out)->generation != generation)
+		return -ESTALE;
+	return 0;
+}
+
+int cs_fe_hot_lineage_write_begin(struct cs_fe_hot_lineage *lineage,
+				  unsigned int slot,
+				  unsigned long long generation,
+				  enum cs_fe_hot_phase phase)
+{
+	struct cs_fe_hot_transition *transition;
+	int error = transition_get(lineage, slot, generation, &transition);
+
+	if (error)
+		return error;
+	if (phase < CS_FE_HOT_NEW_INVALID || phase > CS_FE_HOT_NEW_VALID ||
+	    transition->phase != phase || transition->pending)
+		return -EPERM;
+	transition->pending = true;
+	return 0;
+}
+
+int cs_fe_hot_lineage_write_complete(struct cs_fe_hot_lineage *lineage,
+				     unsigned int slot,
+				     unsigned long long generation,
+				     enum cs_fe_hot_phase phase, bool verified)
+{
+	struct cs_fe_hot_transition *transition;
+	int error = transition_get(lineage, slot, generation, &transition);
+
+	if (error)
+		return error;
+	if (phase < CS_FE_HOT_NEW_INVALID || phase > CS_FE_HOT_NEW_VALID ||
+	    transition->phase != phase || !transition->pending)
+		return -EPERM;
+	if (!verified) {
+		transition->phase = CS_FE_HOT_FAULT;
+		return -EIO;
+	}
+	transition->pending = false;
+	transition->phase++;
+	return 0;
+}
+
+int cs_fe_hot_lineage_cut(struct cs_fe_hot_lineage *lineage, unsigned int slot,
+			  unsigned long long generation)
+{
+	struct cs_fe_hot_transition *transition;
+	int error = transition_get(lineage, slot, generation, &transition);
+
+	if (error)
+		return error;
+	if (transition->pending || transition->phase != CS_FE_HOT_ACTIVE)
+		return -EPERM;
+	transition->phase = CS_FE_HOT_IDLE;
+	return 0;
+}
diff --git a/drivers/net/ethernet/cortina/cs_fe_hot_lineage.h b/drivers/net/ethernet/cortina/cs_fe_hot_lineage.h
new file mode 100644
index 000000000..cfcfb14df
--- /dev/null
+++ b/drivers/net/ethernet/cortina/cs_fe_hot_lineage.h
@@ -0,0 +1,70 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef CS_FE_HOT_LINEAGE_H
+#define CS_FE_HOT_LINEAGE_H
+#include "cs_fe_hot_access.h"
+#include "cs_fe_hot_compare.h"
+
+#define CS_FE_HOT_BUCKETS 4096U
+
+enum cs_fe_hot_phase {
+	CS_FE_HOT_IDLE,
+	CS_FE_HOT_NEW_INVALID,
+	CS_FE_HOT_NEW_HASH,
+	CS_FE_HOT_NEW_VALID,
+	CS_FE_HOT_ACTIVE,
+	CS_FE_HOT_FAULT,
+};
+
+/* No dependent action image or module pointer is duplicated here. */
+struct cs_fe_hot_selector_image {
+	struct cs_fe_key key;
+	u32 hash[4];
+	u32 invalid_input[20], invalid_expected[20];
+	u32 valid_input[20], valid_expected[20];
+};
+
+struct cs_fe_hot_transition {
+	unsigned long long generation;
+	enum cs_fe_hot_phase phase;
+	bool pending;
+	struct cs_fe_hot_selector_image old_selector, new_selector;
+};
+
+struct cs_fe_hot_lineage {
+	/* Permanent action-slot affinity, including withdrawn/failed attempts. */
+	u8 bucket_owner[CS_FE_HOT_BUCKETS];
+	struct cs_fe_hot_transition transition[CS_FE_HOT_SLOTS];
+};
+
+int cs_fe_hot_affinity_claim(struct cs_fe_hot_lineage *lineage,
+			     unsigned int slot, unsigned int bucket);
+/*
+ * Owner lock held. Caller has independently canonicalized candidate and read
+ * actual old CLASS-invalid/HASH-zero, every retained dependency and every trap.
+ * These checks are mandatory executor preconditions, not facts this pure helper
+ * can establish. New bucket's actual all-way emptiness is checked by executor.
+ * Journal before scratch; then replace ONLY slot.plan's selector images.
+ */
+int cs_fe_hot_lineage_begin(struct cs_fe_hot_lineage *lineage,
+			    unsigned int slot, const struct cs_fe_plan *old,
+			    const struct cs_fe_plan *candidate,
+			    unsigned long long *generation);
+/*
+ * Call immediately BEFORE first scratch write. Complete only after literal
+ * full readback. false means uncertain failure: permanently fault, retain all.
+ */
+int cs_fe_hot_lineage_write_begin(struct cs_fe_hot_lineage *lineage,
+				  unsigned int slot,
+				  unsigned long long generation,
+				  enum cs_fe_hot_phase phase);
+int cs_fe_hot_lineage_write_complete(struct cs_fe_hot_lineage *lineage,
+				     unsigned int slot,
+				     unsigned long long generation,
+				     enum cs_fe_hot_phase phase, bool verified);
+/*
+ * After separately verified ordinary withdrawal, permit another begin. This
+ * does not release affinity/dependencies or establish a pipeline drain.
+ */
+int cs_fe_hot_lineage_cut(struct cs_fe_hot_lineage *lineage, unsigned int slot,
+			  unsigned long long generation);
+#endif
diff --git a/drivers/net/ethernet/cortina/cs_fe_hot_tables.c b/drivers/net/ethernet/cortina/cs_fe_hot_tables.c
new file mode 100644
index 000000000..ab60e09b5
--- /dev/null
+++ b/drivers/net/ethernet/cortina/cs_fe_hot_tables.c
@@ -0,0 +1,920 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Private direction backend. No callback registration/capability/statistics. */
+#ifdef __KERNEL__
+#include <linux/errno.h>
+#include <linux/string.h>
+#else
+#include <errno.h>
+#include <string.h>
+#endif
+#include "cs_fe_hot_internal.h"
+
+/* Exact proven indirect layout; DATA0 is the highest DATA address. */
+const struct cs_fe_backend_table cs_fe_backend_tables[CS_BE_TABLES] = {
+	[CS_BE_CLASS] = { 0x0054, 64, 20, 629 },
+	[CS_BE_SDB] = { 0x00a8, 64, 7, 206 },
+	[CS_BE_FWD] = { 0x00d4, 8192, 4, 113 },
+	[CS_BE_VOQ] = { 0x00f4, 512, 2, 40 },
+	[CS_BE_MASK] = { 0x2068, 64, 5, 149 },
+	[CS_BE_HASH] = { 0x201c, 12288, 4, -1 },
+	[CS_BE_OVERFLOW] = { 0x203c, 64, 2, -1 },
+	[CS_BE_L2] = { 0x0124, 512, 4, 96 },
+	[CS_BE_L3] = { 0x010c, 1024, 5, 128 },
+	[CS_BE_FVLAN] = { 0x0100, 512, 2, 38 },
+};
+
+#define CS_BE_START (1U << 31)
+#define CS_BE_WRITE (1U << 30)
+
+static int cs_be_time(const struct cs_fe_backend_io *io, unsigned long long end)
+{
+	if (io->limit_us && io->limit_us < end)
+		end = io->limit_us;
+	return io->now_us(io->context) >= end ? -ETIMEDOUT : 0;
+}
+
+static int cs_be_wait(const struct cs_fe_backend_io *io, unsigned int access,
+		      unsigned long long end)
+{
+	unsigned long long local = io->now_us(io->context) + 10000;
+	u32 value;
+	int error;
+
+	for (;;) {
+		error = cs_be_time(io, end);
+		if (error)
+			return error;
+		error = io->read32(io->context, access, &value);
+		if (error)
+			return error;
+		if (!(value & CS_BE_START))
+			return cs_be_time(io, end);
+		if (io->now_us(io->context) >= local)
+			return -ETIMEDOUT;
+	}
+}
+
+static int cs_be_read(struct cs_fe_backend *backend,
+		      const struct cs_fe_backend_io *io, unsigned int id,
+		      unsigned int row, unsigned long long end)
+{
+	const struct cs_fe_backend_table *table = &cs_fe_backend_tables[id];
+	struct cs_fe_backend_diag *last = &backend->last;
+	unsigned int word;
+	int error;
+
+	memset(last, 0, sizeof(*last));
+	last->table = id;
+	last->row = row;
+	last->words = table->words;
+	last->error = -EINPROGRESS;
+	error = cs_be_wait(io, table->access, end);
+	if (!error)
+		error = cs_be_time(io, end);
+	if (!error)
+		error = io->write32(io->context, table->access,
+				    CS_BE_START | row);
+	if (!error)
+		error = cs_be_wait(io, table->access, end);
+	for (word = 0; !error && word < table->words; word++) {
+		error = cs_be_time(io, end);
+		if (!error)
+			error = io->read32(io->context,
+					   table->access +
+						   (table->words - word) * 4,
+					   &last->raw[word]);
+		if (!error)
+			last->complete++;
+	}
+	if (!error)
+		error = cs_be_time(io, end);
+	last->error = error;
+	if (backend->observe)
+		backend->observe(backend->observe_context, last);
+	return error;
+}
+
+static int cs_be_compare(struct cs_fe_backend *backend,
+			 const struct cs_fe_backend_io *io, unsigned int id,
+			 unsigned int row, const u32 *expected,
+			 unsigned long long end)
+{
+	int error = cs_be_read(backend, io, id, row, end);
+
+	if (!error && memcmp(backend->last.raw, expected,
+			     cs_fe_backend_tables[id].words * sizeof(u32))) {
+		backend->last.error = -EUCLEAN;
+		error = -EUCLEAN;
+	}
+	return error;
+}
+
+static int cs_be_write(struct cs_fe_backend *backend,
+		       const struct cs_fe_backend_io *io, unsigned int id,
+		       unsigned int row, const u32 *input, const u32 *expected,
+		       unsigned long long end)
+{
+	const struct cs_fe_backend_table *table = &cs_fe_backend_tables[id];
+	unsigned int word;
+	int error = cs_be_wait(io, table->access, end);
+
+	if (error)
+		return error;
+	/* Uncertain scratch/ACCESS publication pins all resources, before low word. */
+	backend->pending = true;
+	for (word = 0; word < table->words; word++) {
+		u32 value = input[word];
+
+		if (table->parity >= 0 &&
+		    word == (unsigned int)table->parity / 32)
+			value &= ~(1U << (table->parity % 32));
+		error = cs_be_time(io, end);
+		if (!error)
+			error = io->write32(io->context,
+					    table->access +
+						    (table->words - word) * 4,
+					    value);
+		if (error)
+			return error;
+	}
+	error = cs_be_time(io, end);
+	if (!error)
+		error = io->write32(io->context, table->access,
+				    CS_BE_START | CS_BE_WRITE | row);
+	if (!error)
+		error = cs_be_wait(io, table->access, end);
+	if (!error)
+		error = cs_be_compare(backend, io, id, row, expected, end);
+	if (!error)
+		backend->pending = false;
+	return error;
+}
+
+static bool cs_be_rows_equal(const struct cs_fe_rows *a,
+			     const struct cs_fe_rows *b)
+{
+	return a->class_row == b->class_row && a->sdb_row == b->sdb_row &&
+	       a->mask_row == b->mask_row && a->miss_fwd == b->miss_fwd &&
+	       a->hit_fwd == b->hit_fwd && a->voq == b->voq && a->l2 == b->l2 &&
+	       a->l3 == b->l3 && a->fvlan == b->fvlan &&
+	       a->priority == b->priority && a->miss_marker == b->miss_marker;
+}
+
+static bool cs_be_plan_equal(const struct cs_fe_plan *a,
+			     const struct cs_fe_plan *b)
+{
+	if (memcmp(a->key.bytes, b->key.bytes, sizeof(a->key.bytes)) ||
+	    a->key.crc32 != b->key.crc32 || a->key.crc16 != b->key.crc16 ||
+	    a->key.bucket != b->key.bucket ||
+	    memcmp(a->hash, b->hash, sizeof(a->hash)) ||
+	    !cs_fe_hot_action_equal(a, b))
+		return false;
+#define CS_BE_SAME_IMAGE(name) \
+	(a->name.words == b->name.words && \
+	 !memcmp(a->name.input, b->name.input, sizeof(a->name.input)) && \
+	 !memcmp(a->name.expected, b->name.expected, sizeof(a->name.expected)))
+	return CS_BE_SAME_IMAGE(class_invalid) && CS_BE_SAME_IMAGE(class_valid);
+#undef CS_BE_SAME_IMAGE
+}
+
+struct cs_fe_rows cs_fe_hot_rows(unsigned int index)
+{
+	return (struct cs_fe_rows){
+		.class_row = 5 + index,
+		.sdb_row = 5 + index,
+		.mask_row = 5 + index,
+		.miss_fwd = 5 + index * 2,
+		.hit_fwd = 6 + index * 2,
+		.voq = 5 + index,
+		.l2 = 5 + index,
+		.l3 = 5 + index,
+		.fvlan = 5 + index,
+		/* Match exact UDP flows ahead of the default CPU class (50). */
+		.priority = 51,
+		.miss_marker = 0x5a123,
+	};
+}
+
+static unsigned long long hot_now(void *context)
+{
+	struct cs_fe_hot_session *session = context;
+
+	return session->native.now_us(session->native.context);
+}
+
+static int hot_status(void *context, u32 *status, u32 *init,
+		      unsigned long long end)
+{
+	struct cs_fe_hot_session *session = context;
+
+	const struct cs_fe_backend_io *io = &session->native;
+	int error = cs_be_time(io, end);
+
+	if (!error)
+		error = io->read32(io->context, 0x2000, status);
+	if (!error)
+		error = cs_be_time(io, end);
+	if (!error)
+		error = io->read32(io->context, 0x2004, init);
+	return error ? error : cs_be_time(io, end);
+}
+
+/*
+ * The native command arrives exclusively from the topology-checked owner.
+ * Its immutable encoder must include the range and error-status comparators.
+ * Unsupported commands and older module revisions cannot publish a rule.
+ */
+static bool hot_routed(const struct cs_fe_hot_session *session)
+{
+	if (!session->request.exact || !session->request.rule ||
+	    !session->request.policy || !session->request.selector.valid)
+		return false;
+	if (session->command == CS_HOT_NATIVE)
+		return (session->request.policy->require_mtu_range ==
+				CS_FE_MTU_RANGE_SMALL ||
+			session->request.policy->require_mtu_range ==
+				CS_FE_MTU_RANGE_1500) &&
+		       !session->request.policy->exact_dscp &&
+		       (cs_fe_l4proto(session->request.rule,
+				      session->request.policy) ==
+				CS_FE_L4_UDP ||
+			cs_fe_l4proto(session->request.rule,
+				      session->request.policy) == CS_FE_L4_TCP);
+	return session->command == CS_HOT_SCOPED &&
+	       !session->request.policy->require_mtu_range;
+}
+
+static int hot_native_range(struct cs_fe_hot_session *session, bool prepare,
+			    unsigned long long end)
+{
+	struct cs_fe_hot_state *state = session->backend->hot_state;
+
+	if (session->command != CS_HOT_NATIVE)
+		return 0;
+	if (!state->native_range || !end)
+		return -EOPNOTSUPP;
+	return state->native_range(state->guard_context, prepare,
+				   session->request.policy->require_mtu_range,
+				   end);
+}
+
+static struct cs_fe_rows hot_result_rows(unsigned int selector,
+					 unsigned int result)
+{
+	struct cs_fe_rows rows = cs_fe_hot_rows(selector);
+
+	rows.hit_fwd = 6 + 2 * result;
+	rows.voq = rows.l2 = rows.l3 = rows.fvlan = 5 + result;
+	return rows;
+}
+
+static int hot_placement(void *context, unsigned int index,
+			 struct cs_fe_rows *out, bool *shared)
+{
+	struct cs_fe_hot_session *session = context;
+
+	struct cs_fe_backend *backend = session->backend;
+	struct cs_fe_hot_state *state = backend->hot_state;
+	struct cs_fe_plan candidate;
+	unsigned int g, free_result = CS_FE_BACKEND_ACTIONS;
+	int error;
+
+	if (!state || !out || !shared || index >= CS_FE_HOT_SLOTS ||
+	    !hot_routed(session))
+		return -EOPNOTSUPP;
+	if (state->ledger.blocked || state->ledger.pending ||
+	    backend->pending || backend->poisoned)
+		return -EUCLEAN;
+	if (state->ledger.slots[index].claimed) {
+		const struct cs_fe_hot_slot *anchor;
+
+		error = cs_fe_hot_graph(&state->ledger, index, &anchor);
+		if (error)
+			return error;
+		*out = state->ledger.slots[index].rows;
+		*shared = anchor != &state->ledger.slots[index];
+		return 0;
+	}
+	*shared = false;
+	if (session->command != CS_HOT_NATIVE) {
+		if (index >= CS_FE_BACKEND_ACTIONS ||
+		    state->ledger.actions[index].anchor_plus_one)
+			return -ENOSPC;
+		*out = cs_fe_hot_rows(index);
+		return 0;
+	}
+	for (g = 0; g < CS_FE_BACKEND_ACTIONS; g++) {
+		const struct cs_fe_hot_action *graph =
+			&state->ledger.actions[g];
+		const struct cs_fe_hot_slot *anchor;
+		const struct cs_fe_backend_lease *lease;
+		unsigned int first;
+
+		if (!graph->anchor_plus_one) {
+			if (free_result == CS_FE_BACKEND_ACTIONS)
+				free_result = g;
+			continue;
+		}
+		first = graph->anchor_plus_one - 1;
+		error = cs_fe_hot_graph(&state->ledger, first, &anchor);
+		if (error)
+			return error;
+		lease = &backend->lease[first];
+		/*
+		 * Protocol comparisons and route-length selection are private to each
+		 * selector's CLASS, MASK and SDB; they do not alter identical output words.
+		 */
+		if (!graph->native || !lease->reserved || !lease->submitted ||
+		    !lease->guarded || !lease->scoped || !lease->scope_exact ||
+		    !lease->policy.require_mtu_range || lease->marker)
+			continue;
+		*out = hot_result_rows(index, g);
+		error = cs_fe_encode(session->request.rule, out,
+				     session->request.policy, &candidate);
+		if (error)
+			return error;
+		if (cs_fe_hot_egress_equal(&anchor->plan, &candidate)) {
+			*shared = true;
+			return 0;
+		}
+	}
+	if (free_result == CS_FE_BACKEND_ACTIONS)
+		return -ENOSPC;
+	*out = hot_result_rows(index, free_result);
+	return 0;
+}
+
+/*
+ * Full physical readback of the proposed parent's immutable results before
+ * attaching another exact classifier. The parent may be active or retired.
+ */
+static int hot_verify_output(struct cs_fe_hot_session *session,
+			     const struct cs_fe_rows *r,
+			     const struct cs_fe_plan *p, unsigned long long end)
+{
+	const u32 zero[CS_FE_BACKEND_WORDS] = {};
+	int error = 0;
+
+#define CHECK_OUTPUT(table, row, words)                                     \
+	do {                                                                \
+		if (!error)                                                 \
+			error = cs_be_compare(session->backend,             \
+					      &session->native, table, row, \
+					      words, end);                  \
+	} while (0)
+	CHECK_OUTPUT(CS_BE_FWD, r->hit_fwd, p->hit.expected);
+	CHECK_OUTPUT(CS_BE_VOQ, r->voq, p->voq.expected);
+	CHECK_OUTPUT(CS_BE_L2, r->l2, p->l2.expected);
+	CHECK_OUTPUT(CS_BE_L3, r->l3, p->write_l3 ? p->l3.expected : zero);
+	CHECK_OUTPUT(CS_BE_FVLAN, r->fvlan,
+		     p->write_fvlan ? p->fvlan.expected : zero);
+#undef CHECK_OUTPUT
+	return error;
+}
+
+static int hot_empty_selector(struct cs_fe_hot_session *session,
+			      const struct cs_fe_rows *r,
+			      const struct cs_fe_plan *p,
+			      unsigned long long end)
+{
+	const u32 zero[CS_FE_BACKEND_WORDS] = {};
+	unsigned int way;
+	int error = 0;
+
+#define EMPTY(table, row)                                                   \
+	do {                                                                \
+		if (!error)                                                 \
+			error = cs_be_compare(session->backend,             \
+					      &session->native, table, row, \
+					      zero, end);                   \
+	} while (0)
+	EMPTY(CS_BE_CLASS, r->class_row);
+	EMPTY(CS_BE_SDB, r->sdb_row);
+	EMPTY(CS_BE_MASK, r->mask_row);
+	EMPTY(CS_BE_FWD, r->miss_fwd);
+	for (way = 0; way < 3; way++)
+		EMPTY(CS_BE_HASH, p->key.bucket + way * 4096U);
+#undef EMPTY
+	return error == -EUCLEAN ? -EADDRINUSE : error;
+}
+
+static int hot_claim(void *context, unsigned int index,
+		     const struct cs_fe_rule *rule,
+		     const struct cs_fe_key_policy *policy,
+		     const struct cs_fe_rows *rows,
+		     const struct cs_fe_plan *plan)
+{
+	struct cs_fe_hot_session *session = context;
+
+	struct cs_fe_backend *backend = session->backend;
+	struct cs_fe_hot_state *state = backend->hot_state;
+	struct cs_fe_hot_slot *slot;
+	struct cs_fe_hot_action *graph;
+	struct cs_fe_rows issued;
+	struct cs_fe_plan canonical;
+	unsigned int other;
+	bool shared;
+	int error;
+
+	(void)rule;
+	(void)policy;
+	if (!state || index >= CS_FE_HOT_SLOTS || !hot_routed(session))
+		return -EOPNOTSUPP;
+	if (state->ledger.blocked || state->ledger.pending ||
+	    backend->pending || backend->poisoned)
+		return -EUCLEAN;
+	error = hot_placement(context, index, &issued, &shared);
+	if (error)
+		return error;
+	if (!cs_be_rows_equal(&issued, rows))
+		return -EUCLEAN;
+	error = cs_fe_encode(session->request.rule, &issued,
+			     session->request.policy, &canonical);
+	if (error)
+		return error;
+	cs_fe_exact_class_ipv4(&canonical, &session->request.rule->original,
+			       session->request.selector.source,
+			       session->request.selector.destination);
+	if (!cs_be_plan_equal(&canonical, plan))
+		return -EUCLEAN;
+	/* Collision refusal precedes any change to the permanent journal. */
+	for (other = 0; other < CS_FE_HOT_SLOTS; other++)
+		if (other != index && state->ledger.slots[other].claimed &&
+		    state->ledger.slots[other].plan.key.bucket ==
+			    canonical.key.bucket)
+			return -EOPNOTSUPP;
+	error = hot_native_range(session, true, session->native.limit_us);
+	if (error)
+		return error;
+	slot = &state->ledger.slots[index];
+	if (slot->claimed)
+		return cs_be_rows_equal(&slot->rows, &issued) &&
+				       cs_be_plan_equal(&slot->plan,
+							&canonical) ?
+			       0 :
+			       -ESTALE;
+	graph = &state->ledger.actions[issued.voq - 5U];
+	if (shared) {
+		unsigned long long end =
+			session->native.now_us(session->native.context) +
+			CS_FE_BACKEND_US;
+
+		if (session->native.limit_us && session->native.limit_us < end)
+			end = session->native.limit_us;
+		error = hot_empty_selector(session, &issued, &canonical, end);
+		if (!error)
+			error = hot_verify_output(session, &issued, &canonical,
+						  end);
+		if (error)
+			return error;
+	} else if (graph->anchor_plus_one || graph->members || graph->visible) {
+		return -EUCLEAN;
+	}
+	error = cs_fe_hot_affinity_claim(&state->lineage, index,
+					 canonical.key.bucket);
+	if (error)
+		return error;
+	slot->rows = issued;
+	slot->plan = canonical;
+	slot->dependency_written = 0;
+	slot->claimed = true; /* Before any physical scratch write. */
+	if (!shared) {
+		graph->anchor_plus_one = index + 1U;
+		graph->native = session->command == CS_HOT_NATIVE;
+	}
+	graph->members |= 1U << index;
+	if (shared) {
+		state->binding[index].block = session->request.block;
+		state->binding[index].cookie = session->request.cookie;
+		state->binding[index].version = session->request.version;
+	}
+	return 0;
+}
+
+/* Actual owner-mediated rebind. No raw offsets cross the module boundary. */
+static int hot_rebind(void *context, unsigned int index,
+		      const struct cs_fe_rule *rule,
+		      const struct cs_fe_key_policy *policy,
+		      const struct cs_fe_plan *proposal, unsigned long long end)
+{
+	struct cs_fe_hot_session *session = context;
+
+	struct cs_fe_backend *backend = session->backend;
+	struct cs_fe_hot_state *state = backend->hot_state;
+	struct cs_fe_hot_slot *slot;
+	struct cs_fe_hot_binding *binding;
+	struct cs_fe_plan canonical;
+	unsigned long long generation;
+	u32 zero[20] = {}, cpu_voq[2] = { 56, 1U << 8 };
+	unsigned int way;
+	int error;
+
+	/* Selection is mutable policy. Actual input and fixed row ownership are not. */
+	(void)rule;
+	(void)policy;
+	if (!state || index >= CS_FE_HOT_SLOTS || !proposal ||
+	    !hot_routed(session))
+		return -EOPNOTSUPP;
+	if (state->ledger.blocked || state->ledger.pending ||
+	    backend->pending || backend->poisoned)
+		return -EUCLEAN;
+	slot = &state->ledger.slots[index];
+	binding = &state->binding[index];
+	if (!slot->claimed || binding->visible || binding->hash_present ||
+	    backend->lease[index].active || !backend->lease[index].rearmable ||
+	    !backend->lease[index].scoped || !backend->lease[index].guarded ||
+	    backend->lease[index].marker)
+		return -EBUSY;
+	if (binding->block == session->request.block &&
+	    session->request.version <= binding->version)
+		return -ESTALE;
+	error = cs_fe_encode(session->request.rule, &slot->rows,
+			     session->request.policy, &canonical);
+	if (error)
+		return error;
+	cs_fe_exact_class_ipv4(&canonical, &session->request.rule->original,
+			       session->request.selector.source,
+			       session->request.selector.destination);
+	if (!cs_be_plan_equal(&canonical, proposal) ||
+	    !cs_fe_hot_action_equal(&slot->plan, &canonical))
+		return -EOPNOTSUPP;
+	if (state->lineage.bucket_owner[canonical.key.bucket] &&
+	    state->lineage.bucket_owner[canonical.key.bucket] != index + 1)
+		return -EADDRINUSE;
+	if (session->native.limit_us && session->native.limit_us < end)
+		end = session->native.limit_us;
+	error = hot_native_range(session, false, end);
+	if (error)
+		return error;
+	error = hot_status(context, &backend->status, &backend->init, end);
+	if (!error && (backend->status != 2 || backend->init))
+		error = -EUCLEAN;
+#define RETAIN(table, row, expected)                                      \
+	do {                                                              \
+		if (!error)                                               \
+			error = cs_be_compare(backend, &session->native,  \
+					      table, row, expected, end); \
+	} while (0)
+	RETAIN(CS_BE_CLASS, slot->rows.class_row,
+	       slot->plan.class_invalid.expected);
+	RETAIN(CS_BE_VOQ, 2, cpu_voq);
+	RETAIN(CS_BE_SDB, slot->rows.sdb_row, slot->plan.sdb.expected);
+	RETAIN(CS_BE_MASK, slot->rows.mask_row, slot->plan.mask.expected);
+	RETAIN(CS_BE_FWD, slot->rows.miss_fwd, slot->plan.miss.expected);
+	RETAIN(CS_BE_FWD, slot->rows.hit_fwd, slot->plan.hit.expected);
+	RETAIN(CS_BE_VOQ, slot->rows.voq, slot->plan.voq.expected);
+	RETAIN(CS_BE_L2, slot->rows.l2, slot->plan.l2.expected);
+	RETAIN(CS_BE_L3, slot->rows.l3,
+	       slot->plan.write_l3 ? slot->plan.l3.expected : zero);
+	RETAIN(CS_BE_FVLAN, slot->rows.fvlan,
+	       slot->plan.write_fvlan ? slot->plan.fvlan.expected : zero);
+	for (way = 0; way < 3; way++)
+		RETAIN(CS_BE_HASH, slot->plan.key.bucket + way * 4096, zero);
+	for (way = 0;
+	     !error && canonical.key.bucket != slot->plan.key.bucket && way < 3;
+	     way++) {
+		error = cs_be_read(backend, &session->native, CS_BE_HASH,
+				   canonical.key.bucket + way * 4096, end);
+		if (!error && memcmp(backend->last.raw, zero, 4 * sizeof(u32)))
+			return -EADDRINUSE;
+	}
+	for (way = 0; way < 64; way++)
+		RETAIN(CS_BE_OVERFLOW, way, zero);
+#undef RETAIN
+	if (!error)
+		error = state->guards_rebind(state->guard_context, index,
+					     slot->plan.class_invalid.expected,
+					     canonical.class_invalid.expected,
+					     end, false);
+	if (!error)
+		error = cs_be_time(&session->native, end);
+	if (error)
+		return error;
+	/* A prior verified rekey withdrawal must cut its current generation. */
+	if (state->lineage.transition[index].phase == CS_FE_HOT_ACTIVE) {
+		error = cs_fe_hot_lineage_cut(&state->lineage, index,
+			state->lineage.transition[index].generation);
+		if (error)
+			return error;
+	}
+	error = cs_fe_hot_lineage_begin(&state->lineage, index, &slot->plan,
+					&canonical, &generation);
+	if (error)
+		return error;
+	/* All child images were compared bit-for-bit; only selector images differ. */
+	slot->plan.key = canonical.key;
+	memcpy(slot->plan.hash, canonical.hash, sizeof(slot->plan.hash));
+	slot->plan.class_invalid = canonical.class_invalid;
+	slot->plan.class_valid = canonical.class_valid;
+	return 0;
+}
+
+static int hot_receipt(void *context, unsigned int index,
+		       struct cs_fe_plan *out)
+{
+	struct cs_fe_hot_session *session = context;
+
+	struct cs_fe_hot_state *state = session->backend->hot_state;
+
+	if (!state || !out || index >= CS_FE_HOT_SLOTS ||
+	    !state->ledger.slots[index].claimed)
+		return -ENOENT;
+	*out = state->ledger.slots[index].plan;
+	return 0;
+}
+
+static int hot_read(void *context, unsigned int table, unsigned int row,
+		    unsigned long long end)
+{
+	struct cs_fe_hot_session *session = context;
+
+	struct cs_fe_hot_access_result access;
+	struct cs_fe_hot_state *state = session->backend->hot_state;
+
+	int error;
+
+	if (!state || table >= CS_BE_TABLES)
+		return -EINVAL;
+	error = cs_fe_hot_access(&state->ledger, table, row, false, NULL, NULL,
+				 cs_fe_backend_tables[table].words, &access);
+	if (error)
+		return error;
+	return cs_be_read(session->backend, &session->native, table, row, end);
+}
+
+static bool same_binding(const struct cs_fe_hot_binding *binding,
+			 const struct cs_fe_hot_session *session)
+{
+	if (binding->block != session->request.block)
+		return false;
+	if (session->command == CS_HOT_UNBIND)
+		return true;
+	return binding->cookie == session->request.cookie &&
+	       session->request.version >= binding->version;
+}
+
+static int hot_write(void *context, unsigned int table, unsigned int row,
+		     const u32 *input, const u32 *expected,
+		     unsigned long long end)
+{
+	struct cs_fe_hot_session *session = context;
+
+	struct cs_fe_backend *backend = session->backend;
+	struct cs_fe_hot_state *state = backend->hot_state;
+	struct cs_fe_hot_access_result access;
+	struct cs_fe_hot_slot *slot;
+	struct cs_fe_hot_binding *binding;
+	bool hash_zero, class_valid, transition_write = false;
+	enum cs_fe_hot_phase phase = CS_FE_HOT_IDLE;
+	struct cs_fe_hot_transition *transition;
+	u32 zero[4] = {};
+	int error;
+
+	if (!state || table >= CS_BE_TABLES)
+		return -EINVAL;
+	error = cs_fe_hot_access(&state->ledger, table, row, true, input,
+				 expected, cs_fe_backend_tables[table].words,
+				 &access);
+	if (session->native.limit_us && session->native.limit_us < end)
+		end = session->native.limit_us;
+	if (error == -EALREADY)
+		return 0; /* Identical sealed dependency is never rewritten. */
+	if (error)
+		return error;
+	if (access.slot >= CS_FE_HOT_SLOTS)
+		return -EUCLEAN;
+	slot = &state->ledger.slots[access.slot];
+	binding = &state->binding[access.slot];
+	hash_zero = table == CS_BE_HASH && !memcmp(input, zero, sizeof(zero));
+	class_valid = table == CS_BE_CLASS &&
+		      !memcmp(input, slot->plan.class_valid.input,
+			      sizeof(slot->plan.class_valid.input));
+	if (table == CS_BE_HASH || table == CS_BE_CLASS) {
+		/* A stale cookie/block can never cut a newly installed association. */
+		if ((binding->visible || binding->hash_present) &&
+		    !same_binding(binding, session))
+			return -ESTALE;
+		if ((table == CS_BE_HASH && !hash_zero) || class_valid) {
+			struct cs_fe_plan canonical;
+
+			if (!hot_routed(session))
+				return -EOPNOTSUPP;
+			error = hot_native_range(session, false, end);
+			if (error)
+				return error;
+			error = cs_fe_encode(session->request.rule, &slot->rows,
+					     session->request.policy,
+					     &canonical);
+			if (error)
+				return error;
+			cs_fe_exact_class_ipv4(&canonical, &session->request.rule->original,
+				session->request.selector.source,
+				session->request.selector.destination);
+			if (!cs_be_plan_equal(&canonical, &slot->plan))
+				return -ESTALE;
+			if (table == CS_BE_HASH) {
+				error = cs_be_compare(backend, &session->native, CS_BE_CLASS,
+					slot->rows.class_row,
+					slot->plan.class_invalid.expected, end);
+				if (error)
+					return error;
+			}
+			if (!state->guards_ready ||
+			    !state->guards_ready(state->guard_context,
+						 access.slot))
+				return -EUCLEAN;
+			if (class_valid && (!binding->hash_present ||
+					    !same_binding(binding, session)))
+				return -EUCLEAN;
+		}
+	}
+	transition = &state->lineage.transition[access.slot];
+	if (transition->phase >= CS_FE_HOT_NEW_INVALID &&
+	    transition->phase <= CS_FE_HOT_NEW_VALID) {
+		if (table == CS_BE_CLASS && !class_valid)
+			phase = CS_FE_HOT_NEW_INVALID;
+		else if (table == CS_BE_HASH && !hash_zero)
+			phase = CS_FE_HOT_NEW_HASH;
+		else if (table == CS_BE_CLASS && class_valid)
+			phase = CS_FE_HOT_NEW_VALID;
+		else
+			return -EPERM;
+		error = cs_fe_hot_lineage_write_begin(&state->lineage,
+						      access.slot,
+						      transition->generation,
+						      phase);
+		if (error)
+			return error;
+		transition_write = true;
+	} else if (transition->phase == CS_FE_HOT_FAULT) {
+		return -EUCLEAN;
+	}
+	state->ledger.pending = true; /* BEFORE first scratch word. */
+	state->ledger.pending_selector_plus_one = access.slot + 1;
+	slot->dependency_written |= access.dependency_bit;
+	error = cs_be_write(backend, &session->native, table, row, input,
+			    expected, end);
+	if (!error && transition_write && phase == CS_FE_HOT_NEW_INVALID)
+		error = state->guards_rebind(state->guard_context, access.slot,
+			transition->old_selector.invalid_expected,
+			transition->new_selector.invalid_expected, end, true);
+	if (transition_write) {
+		int complete = cs_fe_hot_lineage_write_complete(&state->lineage, access.slot,
+					transition->generation,
+			phase, !error);
+		if (!error)
+			error = complete;
+	}
+	if (error)
+		return error; /* Both pending journals and module pin remain. */
+	state->ledger.pending = false;
+	state->ledger.pending_selector_plus_one = 0;
+	if (table == CS_BE_HASH) {
+		binding->hash_present = !hash_zero;
+		if (!hash_zero) {
+			binding->block = session->request.block;
+			binding->cookie = session->request.cookie;
+			binding->version = session->request.version;
+		}
+	}
+	if (table == CS_BE_CLASS) {
+		struct cs_fe_hot_action *graph =
+			&state->ledger.actions[slot->rows.voq - 5U];
+		unsigned int bit = 1U << access.slot;
+
+		binding->visible = class_valid;
+		if (class_valid)
+			graph->visible |= bit;
+		else
+			graph->visible &= ~bit;
+	}
+	return 0;
+}
+
+/*
+ * A failed joined selector retains its permanent reservation and ACL rows.
+ * Use its recorded class and HASH only. Moving a result or clearing another
+ * selector to recover would expose traffic after a firewall change.
+ */
+static int hot_isolate(void *context, unsigned int index)
+{
+	struct cs_fe_hot_session *session = context;
+
+	struct cs_fe_backend *backend = session->backend;
+	struct cs_fe_hot_state *state = backend->hot_state;
+	const struct cs_fe_hot_slot *anchor;
+	struct cs_fe_hot_slot *slot;
+	struct cs_fe_hot_action *graph;
+	struct cs_fe_hot_binding *binding;
+	unsigned long long end;
+	struct cs_fe_backend_io cleanup;
+	const u32 zero[4] = {};
+	int error;
+
+	if (!state || state->ledger.blocked || backend->poisoned ||
+	    cs_fe_hot_graph(&state->ledger, index, &anchor) ||
+	    (state->ledger.pending &&
+	     state->ledger.pending_selector_plus_one != index + 1U))
+		return -EUCLEAN;
+	slot = &state->ledger.slots[index];
+	binding = &state->binding[index];
+	graph = &state->ledger.actions[slot->rows.voq - 5U];
+	if (!(graph->members & ~(1U << index)) ||
+	    !same_binding(binding, session) ||
+	    state->lineage.bucket_owner[slot->plan.key.bucket] != index + 1U ||
+	    state->lineage.transition[index].pending)
+		return -EPERM;
+	/* Independent bounded withdrawal budget. No publication on this path. */
+	cleanup = session->native;
+	end = cleanup.now_us(cleanup.context) + CS_FE_BACKEND_US;
+	cleanup.limit_us = end;
+	state->ledger.pending = true;
+	state->ledger.pending_selector_plus_one = index + 1U;
+	error = cs_be_write(backend, &cleanup, CS_BE_CLASS,
+			    slot->rows.class_row,
+			    slot->plan.class_invalid.input,
+			    slot->plan.class_invalid.expected, end);
+	if (!error)
+		error = cs_be_write(backend, &cleanup, CS_BE_HASH,
+				    slot->plan.key.bucket, zero, zero, end);
+	if (error)
+		return error;
+	slot->fenced = true;
+	graph->visible &= ~(1U << index);
+	binding->visible = false;
+	binding->hash_present = false;
+	state->ledger.pending = false;
+	state->ledger.pending_selector_plus_one = 0;
+	return 0;
+}
+
+void cs_fe_hot_typed_io(struct cs_fe_hot_session *session,
+			struct cs_fe_backend_io *typed)
+{
+	*typed = (struct cs_fe_backend_io){
+		.abi = CS_FE_BACKEND_IO_ABI,
+		.size = sizeof(*typed),
+		.context = session,
+		.extent = session->native.extent,
+		.now_us = hot_now,
+		.limit_us = session->native.limit_us,
+		.selector = session->request.selector,
+		.table_read = hot_read,
+		.table_write = hot_write,
+		.claim = hot_claim,
+		.engine_status = hot_status,
+		.rebind = hot_rebind,
+		.receipt = hot_receipt,
+		.placement = hot_placement,
+		.isolate = hot_isolate,
+	};
+	/* raw read32/write32 remain NULL: no offset interface crosses into .ko. */
+}
+
+int cs_fe_hot_verify_idle(struct cs_fe_backend *backend,
+			  const struct cs_fe_backend_io *native)
+{
+	struct cs_fe_hot_state *state = backend->hot_state;
+	unsigned long long end =
+		native->now_us(native->context) + CS_FE_BACKEND_US;
+	u32 zero[4] = {};
+	unsigned int index;
+	int error;
+
+	if (!state || backend->poisoned || backend->pending ||
+	    state->ledger.pending)
+		return -EUCLEAN;
+	for (index = 0; index < CS_FE_BACKEND_BLOCKS; index++)
+		if (backend->block[index].identity)
+			return -EBUSY;
+	for (index = 0; index < CS_FE_BACKEND_ENTRIES; index++)
+		if (backend->entry[index].active)
+			return -EBUSY;
+	for (index = 0; index < CS_FE_HOT_SLOTS; index++) {
+		struct cs_fe_hot_slot *slot = &state->ledger.slots[index];
+
+		struct cs_fe_hot_transition *transition =
+			&state->lineage.transition[index];
+
+		if (transition->pending ||
+		    (transition->phase != CS_FE_HOT_IDLE &&
+		     transition->phase != CS_FE_HOT_ACTIVE))
+			return -EUCLEAN;
+		if (backend->lease[index].active ||
+		    state->binding[index].visible ||
+		    state->binding[index].hash_present)
+			return -EBUSY;
+		if (!slot->claimed)
+			continue;
+		error = cs_be_compare(backend, native, CS_BE_HASH,
+				      slot->plan.key.bucket, zero, end);
+		if (!error)
+			error = cs_be_compare(backend, native, CS_BE_CLASS,
+					      slot->rows.class_row,
+					      slot->plan.class_invalid.expected,
+					      end);
+		if (error)
+			return error;
+	}
+	return 0;
+}
diff --git a/drivers/net/ethernet/cortina/cs_fe_native.inc b/drivers/net/ethernet/cortina/cs_fe_native.inc
new file mode 100644
index 000000000..77d37280b
--- /dev/null
+++ b/drivers/net/ethernet/cortina/cs_fe_native.inc
@@ -0,0 +1,668 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Included by the FE owner. No network-device references are kept in slots. */
+#include <linux/icmp.h>
+#include <linux/if_bridge.h>
+#include <linux/jhash.h>
+#include <linux/moduleparam.h>
+#include <linux/netfilter_ipv4.h>
+#include <net/fib_notifier.h>
+#include <net/flow_offload.h>
+#include <net/ip.h>
+#include <net/netevent.h>
+#include <net/switchdev.h>
+
+static atomic_t cs_native_live = ATOMIC_INIT(0);
+static atomic_t cs_native_programming = ATOMIC_INIT(0);
+static atomic64_t cs_native_generation = ATOMIC64_INIT(0);
+static atomic64_t cs_native_scanned = ATOMIC64_INIT(0);
+static unsigned long cs_native_events;
+static bool cs_native_watching;
+
+enum cs_native_event { CS_NATIVE_RECHECK_FDB, CS_NATIVE_REVOKE };
+
+/* RANGE0 and RANGE1 have fixed framing limits, serialized across owners. */
+static DEFINE_MUTEX(cs_native_mtu_lock);
+static const unsigned int cs_native_mtu1500_high = CS_FE_NATIVE_1500_MAX_HIGH;
+
+static int cs_fe_native_range(void *context, bool prepare, u8 range_bit,
+			      unsigned long long end)
+{
+	struct cs7542_fe_live *owner = context;
+	struct cs_fe_backend_io io = cs_fe_live_io(owner);
+	unsigned int row, high;
+	struct cs_fe_native_mtu *range;
+	int err;
+
+	lockdep_assert_held(&owner->lock);
+	if (range_bit != CS_FE_MTU_RANGE_SMALL &&
+	    range_bit != CS_FE_MTU_RANGE_1500)
+		return -EINVAL;
+	row = range_bit == CS_FE_MTU_RANGE_1500;
+	range = &owner->native.range[row];
+	io.limit_us = end;
+	mutex_lock(&cs_native_mtu_lock);
+	high = row ? cs_native_mtu1500_high : CS_FE_NATIVE_SMALL_HIGH;
+	if (!high)
+		err = -EOPNOTSUPP;
+	else if (prepare)
+		err = cs_fe_native_mtu_prepare(range, &io, row, high);
+	else
+		err = cs_fe_native_mtu_verify(range, &io, row, high);
+	mutex_unlock(&cs_native_mtu_lock);
+	return err;
+}
+
+static void cs_native_forget(struct cs_fe_native_flow *flow)
+{
+	if (flow->block) {
+		memset(flow, 0, sizeof(*flow));
+		atomic_dec(&cs_native_live);
+	}
+}
+
+static struct cs_fe_backend_entry *
+cs_native_hw_entry(struct cs7542_fe_live *owner, u64 block,
+		   unsigned long cookie)
+{
+	unsigned int n;
+
+	for (n = 0; n < CS_FE_BACKEND_ENTRIES; n++) {
+		struct cs_fe_backend_entry *entry = &owner->backend.entry[n];
+
+		if (entry->occupied && entry->active && entry->block == block &&
+		    entry->cookie == cookie)
+			return entry;
+	}
+	return NULL;
+}
+
+static bool cs_native_visible(const struct cs7542_fe_live *owner, u64 block,
+			      unsigned long cookie)
+{
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(owner->hot_state.binding); i++) {
+		const struct cs_fe_hot_binding *b =
+			&owner->hot_state.binding[i];
+
+		if (b->block == block && b->cookie == cookie &&
+		    (b->visible || b->hash_present))
+			return true;
+	}
+	return false;
+}
+
+static void cs_fe_native_prune(struct cs7542_fe_live *owner)
+{
+	struct cs_fe_native_flow *flow;
+	unsigned int i;
+
+	lockdep_assert_held(&owner->lock);
+	for (i = 0; i < ARRAY_SIZE(owner->native.flows); i++) {
+		flow = &owner->native.flows[i];
+		if (!flow->block)
+			continue;
+		if (owner->reset_verified ||
+		    (!owner->backend.poisoned && !owner->backend.pending &&
+		     !cs_native_hw_entry(owner, flow->block, flow->cookie) &&
+		     !cs_native_visible(owner, flow->block, flow->cookie)))
+			cs_native_forget(flow);
+	}
+}
+
+static struct cs_fe_native_flow *cs_native_slot(struct cs7542_fe_live *owner,
+						u64 block, unsigned long cookie)
+{
+	struct cs_fe_native_flow *free = NULL;
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(owner->native.flows); i++) {
+		struct cs_fe_native_flow *flow = &owner->native.flows[i];
+
+		if (flow->block == block && flow->cookie == cookie)
+			return flow;
+		if (!flow->block && !free)
+			free = flow;
+	}
+	return free;
+}
+
+static struct dsa_port *cs_native_port(int ifindex,
+				       const struct cs_fe_link *link,
+				       const u8 *peer, unsigned int route_mtu)
+{
+	struct net_device *dev = __dev_get_by_index(&init_net, ifindex);
+	struct dsa_port *dp = dsa_port_from_netdev(dev);
+	struct net_device *l3dev;
+
+	ASSERT_RTNL();
+	if (IS_ERR(dp) || !dp->ds || !dp->ds->dev || !dp->cpu_dp ||
+	    !of_device_is_compatible(dp->ds->dev->of_node, "qca,qca8337") ||
+	    !dp->cpu_dp->conduit || dp->cpu_dp->index || dp->lag ||
+	    dp->hsr_dev || dp->index < 1 || dp->index > 5 ||
+	    dp->index != link->switch_port || link->tag_mode != 4 ||
+	    link->cpu_port || link->gmac != 1 || link->base_voq != 8 ||
+	    !netif_running(dev) || !netif_carrier_ok(dev) ||
+	    dsa_port_is_vlan_filtering(dp))
+		return ERR_PTR(-EOPNOTSUPP);
+	l3dev = netdev_master_upper_dev_get(dev);
+	if (l3dev) {
+		if (!netif_is_bridge_master(l3dev) || !netif_running(l3dev) ||
+		    br_vlan_enabled(l3dev) ||
+		    br_port_get_stp_state(dev) != BR_STATE_FORWARDING ||
+		    br_port_flag_is_set(dev, BR_ISOLATED | BR_PORT_LOCKED |
+						     BR_PORT_MAB |
+						     BR_VLAN_TUNNEL) ||
+		    br_fdb_find_port(l3dev, peer, 0) != dev)
+			return ERR_PTR(-EOPNOTSUPP);
+	} else {
+		l3dev = dev;
+	}
+	if (!ether_addr_equal(link->base_mac, l3dev->dev_addr) ||
+	    route_mtu > min(READ_ONCE(dev->mtu), READ_ONCE(l3dev->mtu)))
+		return ERR_PTR(-ESTALE);
+	return dp;
+}
+
+static struct net_device *
+cs_native_path(const struct cs7542_fe_native_request *r)
+{
+	const struct cs_fe_rule *rule = &r->rule;
+	struct dsa_port *in, *out;
+
+	if (!is_valid_ether_addr(r->ingress_smac) ||
+	    !is_valid_ether_addr(rule->dmac) ||
+	    !ether_addr_equal(rule->egress.base_mac, rule->smac) ||
+	    r->route_mtu < CS_FE_NATIVE_SMALL_HIGH || !rule->decrement_ttl ||
+	    rule->egress.rx_qca_meta)
+		return ERR_PTR(-EOPNOTSUPP);
+	in = cs_native_port(r->ingress_ifindex, &rule->ingress, r->ingress_smac,
+			    0);
+	out = cs_native_port(r->egress_ifindex, &rule->egress, rule->dmac,
+			     r->route_mtu);
+	if (IS_ERR(in) || IS_ERR(out) || in->ds != out->ds ||
+	    in->cpu_dp != out->cpu_dp || !netif_running(in->cpu_dp->conduit) ||
+	    !netif_carrier_ok(in->cpu_dp->conduit))
+		return ERR_PTR(-EOPNOTSUPP);
+	return in->cpu_dp->conduit;
+}
+
+static int cs_native_format(struct net_device *conduit, u64 epoch)
+{
+	struct qca8k_persistent_status f = {
+		.version = QCA8K_PERSISTENT_STATUS_VERSION,
+		.size = sizeof(f),
+	};
+	int err;
+
+	err = qca8k_persistent_status(conduit, &f);
+	if (err)
+		return err;
+	if (!epoch || f.epoch != epoch || f.size != sizeof(f) ||
+	    f.version != QCA8K_PERSISTENT_STATUS_VERSION || f.reserved ||
+	    f.closing || f.uncertain || f.first_error || f.held_fault ||
+	    f.requested != 1 || f.ready != 1 || f.known != 1 ||
+	    f.coherent != 1 || f.restore_debt != 1 ||
+	    f.selected != DSA_TAG_PROTO_QCA4 ||
+	    f.tree_protocol != DSA_TAG_PROTO_QCA4)
+		return -ESTALE;
+	return 0;
+}
+
+static int cs_native_cut(struct cs7542_fe_live *owner,
+			 struct cs_fe_native_flow *flow)
+{
+	struct cs_fe_backend_io io = cs_fe_live_io(owner);
+	struct cs_fe_backend_entry *entry;
+	int err;
+
+	if (owner->reset_verified)
+		goto cut;
+	err = cs_fe_live_ready(owner);
+	if (err)
+		return err;
+	entry = cs_native_hw_entry(owner, flow->block, flow->cookie);
+	if (entry) {
+		err = cs_fe_backend_destroy(&owner->backend, &io, flow->block,
+					    flow->cookie, entry->version);
+		if (err)
+			return err;
+	}
+	if (owner->backend.pending ||
+	    cs_native_visible(owner, flow->block, flow->cookie))
+		return -EIO;
+cut:
+	cs_native_forget(flow);
+	return 0;
+}
+
+/*
+ * Admission is tied to netfilter's conntrack snapshot and its exact rule.
+ * Never interpret its opaque cookie as a kernel pointer.
+ */
+static bool cs_native_tcp_match(const struct flow_cls_offload *cls,
+				unsigned long cookie,
+				const struct cs7542_fe_native_request *r)
+{
+	const struct cs_fe_tuple *tuple = &r->rule.original;
+	const u64 allowed = BIT_ULL(FLOW_DISSECTOR_KEY_BASIC) |
+			    BIT_ULL(FLOW_DISSECTOR_KEY_TCP) |
+			    BIT_ULL(FLOW_DISSECTOR_KEY_IPV4_ADDRS) |
+			    BIT_ULL(FLOW_DISSECTOR_KEY_PORTS) |
+			    BIT_ULL(FLOW_DISSECTOR_KEY_CONTROL) |
+			    BIT_ULL(FLOW_DISSECTOR_KEY_META);
+	struct flow_match_ipv4_addrs ip;
+	struct flow_match_control control;
+	struct flow_match_basic basic;
+	struct flow_match_ports ports;
+	struct flow_match_meta meta;
+	struct flow_match_tcp tcp;
+
+	if (!cls || cls->command != FLOW_CLS_REPLACE ||
+	    !cls->nf_tcp_established || !cls->rule ||
+	    !cls->rule->match.dissector || cls->cookie != cookie ||
+	    cls->nf_route_mtu != r->route_mtu ||
+	    cls->rule->match.dissector->used_keys != allowed)
+		return false;
+	flow_rule_match_basic(cls->rule, &basic);
+	flow_rule_match_control(cls->rule, &control);
+	flow_rule_match_ipv4_addrs(cls->rule, &ip);
+	flow_rule_match_ports(cls->rule, &ports);
+	flow_rule_match_meta(cls->rule, &meta);
+	flow_rule_match_tcp(cls->rule, &tcp);
+	return basic.key->n_proto == htons(ETH_P_IP) &&
+	       basic.mask->n_proto == htons(0xffff) &&
+	       basic.key->ip_proto == IPPROTO_TCP &&
+	       basic.mask->ip_proto == 0xff &&
+	       control.key->addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS &&
+	       control.mask->addr_type == 0xffff &&
+	       ip.mask->src == htonl(U32_MAX) &&
+	       ip.mask->dst == htonl(U32_MAX) &&
+	       ip.key->src == htonl(tuple->src) &&
+	       ip.key->dst == htonl(tuple->dst) &&
+	       ports.mask->src == htons(0xffff) &&
+	       ports.mask->dst == htons(0xffff) &&
+	       ports.key->src == htons(tuple->sport) &&
+	       ports.key->dst == htons(tuple->dport) &&
+	       meta.mask->ingress_ifindex == -1 &&
+	       meta.key->ingress_ifindex == r->ingress_ifindex &&
+	       !tcp.key->flags &&
+	       tcp.mask->flags == htons(0x05); /* Linux FIN | RST */
+}
+
+static int cs_native_replace(struct cs7542_fe_live *owner, u64 block,
+			     unsigned long cookie, u64 version,
+			     const struct cs7542_fe_native_request *input,
+			     u8 proto, const struct flow_cls_offload *cls)
+{
+	struct cs7542_fe_native_request path;
+	const struct cs7542_fe_native_request *r = &path;
+	struct cs_fe_key_policy policy = {};
+	struct cs_fe_native_flow *slot = NULL;
+	struct cs_fe_backend_entry *entry;
+	struct net_device *conduit;
+	struct cs_fe_backend_io io;
+	u64 gen;
+	int err;
+
+	ASSERT_RTNL();
+	if (!owner || !input || !block || !version ||
+	    input->size != sizeof(*r) ||
+	    (input->abi != CS7542_FE_NATIVE_ABI &&
+	     !(proto == IPPROTO_UDP && input->abi == 1)))
+		return -EINVAL;
+	path = *input;
+	/* An ABI1 UDP caller could have arbitrary tail padding in cs_fe_rule. */
+	path.rule.native_l4proto = proto;
+	atomic_inc(&cs_native_programming);
+	gen = atomic64_read(&cs_native_generation);
+	conduit = cs_native_path(r);
+	err = IS_ERR(conduit) ? PTR_ERR(conduit) :
+				cs_native_format(conduit, r->format_epoch);
+	if (!err && ((proto == IPPROTO_TCP &&
+		      (input->rule.native_l4proto != IPPROTO_TCP ||
+		       !cs_native_tcp_match(cls, cookie, r))) ||
+		     (proto == IPPROTO_UDP && input->abi != 1 &&
+		      input->rule.native_l4proto &&
+		      input->rule.native_l4proto != IPPROTO_UDP)))
+		err = -EOPNOTSUPP;
+	mutex_lock(&owner->lock);
+	if (cs_fe_live_ready(owner)) {
+		err = -ESHUTDOWN;
+		goto out;
+	}
+	cs_fe_native_prune(owner);
+	io = cs_fe_live_io(owner);
+	if (!err &&
+	    (owner->ports[1] != conduit || !READ_ONCE(cs_native_watching) ||
+	     gen != atomic64_read(&cs_native_scanned)))
+		err = -EAGAIN;
+	if (!err) {
+		slot = cs_native_slot(owner, block, cookie);
+		if (!slot)
+			err = -ENOSPC;
+		else if (slot->block && slot->version >= version) {
+			err = -ESTALE;
+			goto out;
+		}
+	}
+	if (err) {
+		err = cs_fe_backend_reject(&owner->backend, &io, block, cookie,
+					   version, err);
+		goto out;
+	}
+	policy.require_mtu_range = cs_fe_native_mtu_select(r->route_mtu, READ_ONCE(cs_native_mtu1500_high));
+	io.limit_us = io.now_us(io.context) + CS_FE_BACKEND_US;
+	io.selector.valid = true;
+	ether_addr_copy(io.selector.source, r->ingress_smac);
+	ether_addr_copy(io.selector.destination, r->rule.ingress.base_mac);
+	/*
+	 * Record the obligation before publication, including an uncertain
+	 * hardware write. A verified inactive tuple is pruned below.
+	 */
+	if (!slot->block)
+		atomic_inc(&cs_native_live);
+	slot->block = block;
+	slot->cookie = cookie;
+	slot->version = version;
+	slot->path = *r;
+	err = cs_fe_backend_replace_native(&owner->backend, &io, block, cookie,
+					   version, &r->rule, &policy);
+	cs_fe_live_pin(owner);
+	entry = cs_native_hw_entry(owner, block, cookie);
+	if (err) {
+		/*
+		 * An older algorithm can decline the new opcode before seeing
+		 * this desired version. A prior association still needs cutting.
+		 */
+		if (entry && entry->version < version)
+			err = cs_fe_backend_reject(&owner->backend, &io, block,
+						   cookie, version, err);
+		goto out;
+	}
+	if (!entry || entry->lease >= ARRAY_SIZE(owner->hot_state.binding) ||
+	    entry->version != version ||
+	    owner->hot_state.binding[entry->lease].block != block ||
+	    owner->hot_state.binding[entry->lease].cookie != cookie ||
+	    !owner->hot_state.binding[entry->lease].visible ||
+	    !owner->hot_state.binding[entry->lease].hash_present)
+		err = cs_native_cut(owner, slot) ?: -EUCLEAN;
+	else if (atomic64_read(&cs_native_generation) != gen)
+		err = cs_native_cut(owner, slot) ?: -ESTALE;
+out:
+	cs_fe_native_prune(owner);
+	mutex_unlock(&owner->lock);
+	atomic_dec(&cs_native_programming);
+	return err;
+}
+
+int cs7542_fe_live_replace_native(struct cs7542_fe_live *owner, u64 block,
+				  unsigned long cookie, u64 version,
+				  const struct cs7542_fe_native_request *r)
+{
+	return cs_native_replace(owner, block, cookie, version, r, IPPROTO_UDP,
+				 NULL);
+}
+EXPORT_SYMBOL_GPL(cs7542_fe_live_replace_native);
+
+int cs7542_fe_live_replace_native_tcp(struct cs7542_fe_live *owner, u64 block,
+				      unsigned long cookie, u64 version,
+				      const struct cs7542_fe_native_request *r,
+				      const struct flow_cls_offload *cls)
+{
+	return cs_native_replace(owner, block, cookie, version, r, IPPROTO_TCP,
+				 cls);
+}
+EXPORT_SYMBOL_GPL(cs7542_fe_live_replace_native_tcp);
+
+static int cs_native_scan(bool revoke_all)
+{
+	struct cs7542_fe_live *owner;
+	unsigned int i;
+	int first = 0;
+
+	ASSERT_RTNL();
+	mutex_lock(&cs_fe_live_owners_lock);
+	list_for_each_entry(owner, &cs_fe_live_owners, node) {
+		mutex_lock(&owner->lock);
+		cs_fe_native_prune(owner);
+		for (i = 0; i < ARRAY_SIZE(owner->native.flows); i++) {
+			struct cs_fe_native_flow *flow =
+				&owner->native.flows[i];
+			int err;
+
+			if (!flow->block ||
+			    (!revoke_all &&
+			     !IS_ERR(cs_native_path(&flow->path))))
+				continue;
+			err = cs_native_cut(owner, flow);
+			if (err && !first)
+				first = err;
+		}
+		mutex_unlock(&owner->lock);
+	}
+	mutex_unlock(&cs_fe_live_owners_lock);
+	return first;
+}
+
+static int cs_native_drain(void)
+{
+	unsigned long events;
+	u64 gen;
+	int err;
+
+	ASSERT_RTNL();
+	do {
+		gen = atomic64_read(&cs_native_generation);
+		events = xchg(&cs_native_events, 0UL);
+		err = cs_native_scan(events & BIT(CS_NATIVE_REVOKE));
+		if (err) {
+			set_bit(CS_NATIVE_REVOKE, &cs_native_events);
+			return err;
+		}
+		atomic64_set(&cs_native_scanned, gen);
+	} while (READ_ONCE(cs_native_events));
+	return 0;
+}
+
+static void cs_native_worker(struct work_struct *work)
+{
+	rtnl_lock();
+	cs_native_drain();
+	rtnl_unlock();
+}
+
+static DECLARE_WORK(cs_native_work, cs_native_worker);
+
+static int cs_native_changed(enum cs_native_event kind, bool sync)
+{
+	if (!atomic_read(&cs_native_live) &&
+	    !atomic_read(&cs_native_programming))
+		return NOTIFY_DONE;
+	set_bit(kind, &cs_native_events);
+	atomic64_inc(&cs_native_generation);
+	if (sync)
+		return notifier_from_errno(cs_native_drain());
+	schedule_work(&cs_native_work);
+	return NOTIFY_DONE;
+}
+
+static int cs_native_device(struct notifier_block *nb, unsigned long event,
+			    void *info)
+{
+	struct net_device *dev = netdev_notifier_info_to_dev(info);
+
+	if (!net_eq(dev_net(dev), &init_net))
+		return NOTIFY_DONE;
+	switch (event) {
+	case NETDEV_PRECHANGEUPPER:
+	case NETDEV_PRE_CHANGEADDR:
+	case NETDEV_PRECHANGEMTU:
+	case NETDEV_GOING_DOWN:
+	case NETDEV_UNREGISTER:
+		return cs_native_changed(CS_NATIVE_REVOKE, true);
+	case NETDEV_CHANGE:
+	case NETDEV_CHANGELOWERSTATE:
+	case NETDEV_CHANGEUPPER:
+	case NETDEV_CHANGEMTU:
+	case NETDEV_CHANGEADDR:
+		return cs_native_changed(CS_NATIVE_REVOKE, false);
+	default:
+		return NOTIFY_DONE;
+	}
+}
+
+static int cs_native_fdb(struct notifier_block *nb, unsigned long event,
+			 void *info)
+{
+	struct net_device *dev = switchdev_notifier_info_to_dev(info);
+
+	if (!dev || !net_eq(dev_net(dev), &init_net))
+		return NOTIFY_DONE;
+	switch (event) {
+	case SWITCHDEV_FDB_DEL_TO_DEVICE:
+	case SWITCHDEV_FDB_ADD_TO_DEVICE:
+	case SWITCHDEV_FDB_DEL_TO_BRIDGE:
+	case SWITCHDEV_FDB_ADD_TO_BRIDGE:
+	case SWITCHDEV_FDB_FLUSH_TO_BRIDGE:
+		return cs_native_changed(CS_NATIVE_RECHECK_FDB, false);
+	default:
+		return NOTIFY_DONE;
+	}
+}
+
+/*
+ * Ordinary NUD refreshes keep the same usable next-hop MAC. Notice a change
+ * in address or reachability without expiring flows for every ARP confirmation.
+ * Collisions only make an extra conservative recheck necessary.
+ */
+struct cs_native_arp_state {
+	__be32 address;
+	int ifindex;
+	u8 mac[ETH_ALEN];
+	bool valid;
+};
+
+static struct cs_native_arp_state cs_native_arp[128];
+static DEFINE_SPINLOCK(cs_native_arp_lock);
+
+static bool cs_native_arp_changed(const struct neighbour *neigh)
+{
+	struct cs_native_arp_state next = { .ifindex = neigh->dev->ifindex };
+	struct cs_native_arp_state *last;
+	unsigned int index;
+	bool changed;
+
+	memcpy(&next.address, neigh->primary_key, sizeof(next.address));
+	next.valid = !!(READ_ONCE(neigh->nud_state) & NUD_VALID);
+	neigh_ha_snapshot(next.mac, neigh, neigh->dev);
+	index = jhash_2words((__force u32)next.address, next.ifindex, 0);
+	last = &cs_native_arp[index % ARRAY_SIZE(cs_native_arp)];
+	spin_lock_bh(&cs_native_arp_lock);
+	changed = last->address != next.address ||
+		  last->ifindex != next.ifindex || last->valid != next.valid ||
+		  !ether_addr_equal(last->mac, next.mac);
+	*last = next;
+	spin_unlock_bh(&cs_native_arp_lock);
+	return changed;
+}
+
+static int cs_native_neigh(struct notifier_block *nb, unsigned long event,
+			   void *info)
+{
+	if (event == NETEVENT_NEIGH_UPDATE) {
+		const struct neighbour *neigh = info;
+
+		if (neigh->tbl != arp_table(dev_net(neigh->dev)) ||
+		    neigh->dev->addr_len != ETH_ALEN ||
+		    !net_eq(dev_net(neigh->dev), &init_net) ||
+		    !cs_native_arp_changed(neigh))
+			return NOTIFY_DONE;
+	} else if (event != NETEVENT_REDIRECT &&
+		   event != NETEVENT_IPV4_MPATH_HASH_UPDATE)
+		return NOTIFY_DONE;
+	return cs_native_changed(CS_NATIVE_REVOKE, false);
+}
+
+static int cs_native_fib(struct notifier_block *nb, unsigned long event,
+			 void *info)
+{
+	const struct fib_notifier_info *fib = info;
+
+	if (fib->family != AF_INET)
+		return NOTIFY_DONE;
+	return cs_native_changed(CS_NATIVE_REVOKE, false);
+}
+
+static unsigned int cs_native_icmp(void *priv, struct sk_buff *skb,
+				   const struct nf_hook_state *state)
+{
+	struct icmphdr copy;
+	const struct icmphdr *icmp;
+	const struct iphdr *ip;
+
+	if (!atomic_read(&cs_native_live) &&
+	    !atomic_read(&cs_native_programming))
+		return NF_ACCEPT;
+	ip = ip_hdr(skb);
+	if (ip->protocol == IPPROTO_ICMP && !ip_is_fragment(ip)) {
+		icmp = skb_header_pointer(skb,
+					  skb_network_offset(skb) + ip->ihl * 4,
+					  sizeof(copy), &copy);
+		if (icmp && icmp->type == ICMP_DEST_UNREACH &&
+		    icmp->code == ICMP_FRAG_NEEDED)
+			cs_native_changed(CS_NATIVE_REVOKE, false);
+	}
+	return NF_ACCEPT;
+}
+
+static struct notifier_block cs_native_dev_nb = { .notifier_call =
+							  cs_native_device };
+static struct notifier_block cs_native_fdb_nb = { .notifier_call =
+							  cs_native_fdb };
+static struct notifier_block cs_native_neigh_nb = { .notifier_call =
+							    cs_native_neigh };
+static struct notifier_block cs_native_fib_nb = { .notifier_call =
+							  cs_native_fib };
+static const struct nf_hook_ops cs_native_pmtu_hook = {
+	.hook = cs_native_icmp,
+	.pf = NFPROTO_IPV4,
+	.hooknum = NF_INET_PRE_ROUTING,
+	.priority = NF_IP_PRI_FIRST,
+};
+
+static int __init cs_native_notifiers(void)
+{
+	int err;
+
+	err = register_netdevice_notifier(&cs_native_dev_nb);
+	if (err)
+		return err;
+	err = register_switchdev_notifier(&cs_native_fdb_nb);
+	if (err)
+		goto dev;
+	err = register_netevent_notifier(&cs_native_neigh_nb);
+	if (err)
+		goto fdb;
+	err = register_fib_notifier(&init_net, &cs_native_fib_nb, NULL, NULL);
+	if (err)
+		goto neigh;
+	err = nf_register_net_hook(&init_net, &cs_native_pmtu_hook);
+	if (err)
+		goto fib;
+	WRITE_ONCE(cs_native_watching, true);
+	return 0;
+fib:
+	unregister_fib_notifier(&init_net, &cs_native_fib_nb);
+neigh:
+	unregister_netevent_notifier(&cs_native_neigh_nb);
+fdb:
+	unregister_switchdev_notifier(&cs_native_fdb_nb);
+dev:
+	unregister_netdevice_notifier(&cs_native_dev_nb);
+	return err;
+}
+
+late_initcall(cs_native_notifiers);
+
+#include "cs_fe_native_activity.inc"
diff --git a/drivers/net/ethernet/cortina/cs_fe_native_activity.inc b/drivers/net/ethernet/cortina/cs_fe_native_activity.inc
new file mode 100644
index 000000000..0e8b6c36c
--- /dev/null
+++ b/drivers/net/ethernet/cortina/cs_fe_native_activity.inc
@@ -0,0 +1,237 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* An access selects an owned way0 bucket for a read. No bitmap is cleared. */
+#include <linux/moduleparam.h>
+#include <linux/sysfs.h>
+
+/*
+ * The bitmap uses the same selector number that native_activity calls lease.
+ * Retained membership is lifetime ownership. Visible requires CLASS readback.
+ */
+static int cs_native_actions_get(char *buf, const struct kernel_param *kp)
+{
+	struct cs7542_fe_live *owner;
+	unsigned int i, s;
+	int len = 0;
+
+	mutex_lock(&cs_fe_live_owners_lock);
+	list_for_each_entry(owner, &cs_fe_live_owners, node) {
+		mutex_lock(&owner->lock);
+		for (i = 0; i < CS_FE_BACKEND_ACTIONS && len < PAGE_SIZE - 192;
+		     i++) {
+			const struct cs_fe_hot_action *graph =
+				&owner->hot_state.ledger.actions[i];
+			const struct cs_fe_hot_slot *root;
+			u32 fenced = 0;
+
+			if (!graph->anchor_plus_one)
+				continue;
+			if (cs_fe_hot_graph(&owner->hot_state.ledger,
+					    graph->anchor_plus_one - 1,
+					    &root)) {
+				len += sysfs_emit_at(buf, len,
+					"epoch=%llu result=%u inconsistent=1\n",
+					owner->epoch, i);
+				continue;
+			}
+			for (s = 0; s < CS_FE_HOT_SLOTS; s++)
+				if ((graph->members & BIT(s)) &&
+				    owner->hot_state.ledger.slots[s].fenced)
+					fenced |= BIT(s);
+			len += sysfs_emit_at(buf, len,
+				"epoch=%llu result=%u hit_fwd=%u voq=%u l2=%u l3=%u fvlan=%u members=0x%x visible=0x%x fenced=0x%x uncertain=%u\n",
+				owner->epoch, i, root->rows.hit_fwd,
+				root->rows.voq, root->rows.l2, root->rows.l3,
+				root->rows.fvlan, graph->members,
+				graph->visible, fenced,
+				owner->backend.pending ||
+					owner->backend.poisoned ||
+					owner->hot_state.ledger.pending);
+		}
+		mutex_unlock(&owner->lock);
+	}
+	mutex_unlock(&cs_fe_live_owners_lock);
+	return len;
+}
+
+static const struct kernel_param_ops cs_native_actions_ops = {
+	.get = cs_native_actions_get
+};
+
+module_param_cb(native_actions, &cs_native_actions_ops, NULL, 0400);
+
+static bool cs_native_sample_for(const struct cs7542_fe_hot_sample *s,
+				 unsigned int bucket)
+{
+	return s->complete && !s->error && s->valid_words == 2 &&
+	       s->word == (bucket * 6U) / 64 && s->bit == (bucket * 6U) % 64;
+}
+
+/*
+ * A set sticky bit can only establish activity after the most recent zero.
+ * Neither a repeated set bit nor a bit inherited at installation is fresh.
+ */
+static u64 cs_native_hot_stamp(struct cs_fe_native_clock *clock,
+			       const struct cs7542_fe_hot_sample *before,
+			       const struct cs7542_fe_hot_sample *sample)
+{
+	if (clock->baseline_us != before->timestamp_us) {
+		clock->baseline_us = before->timestamp_us;
+		clock->lastuse_us = 0;
+		clock->last_zero_us = before->selected ? 0 :
+							 before->timestamp_us;
+	}
+	if (sample->timestamp_us < before->timestamp_us)
+		return 0;
+	if (!sample->selected) {
+		clock->last_zero_us = sample->timestamp_us;
+	} else if (clock->last_zero_us) {
+		clock->lastuse_us = clock->last_zero_us;
+		clock->last_zero_us = 0;
+	}
+	return clock->lastuse_us;
+}
+
+static bool cs_native_lease_active(const struct cs7542_fe_live *owner,
+				   unsigned int index)
+{
+	const struct cs_fe_hot_binding *binding =
+		&owner->hot_state.binding[index];
+
+	return owner->backend.lease[index].active && binding->visible &&
+	       binding->hash_present;
+}
+
+int cs7542_fe_live_native_lastused(struct cs7542_fe_live *owner, u64 block,
+				   unsigned long cookie,
+				   unsigned long *lastused)
+{
+	const struct cs7542_fe_hot_sample *before;
+	struct cs_fe_backend_entry *entry;
+	struct cs7542_fe_hot_sample sample;
+	struct cs_fe_backend_io io;
+	unsigned int lease, bucket;
+	u64 last, elapsed;
+	int err;
+
+	if (!owner || !lastused)
+		return -EINVAL;
+	mutex_lock(&owner->lock);
+	err = cs_fe_live_ready(owner);
+	if (err)
+		goto out;
+	entry = cs_native_hw_entry(owner, block, cookie);
+	if (!entry || owner->backend.pending ||
+	    entry->lease >= CS_FE_BACKEND_LEASES ||
+	    !cs_native_lease_active(owner, entry->lease) ||
+	    !owner->backend.lease[entry->lease].policy.require_mtu_range) {
+		err = -ENOENT;
+		goto out;
+	}
+	lease = entry->lease;
+	bucket = owner->backend.lease[lease].plan.key.bucket;
+	io = cs_fe_live_io(owner);
+	io.limit_us = io.now_us(io.context) + 3000;
+	err = cs_fe_hot_read(&io, bucket, &sample);
+	if (err)
+		goto out;
+	before = &owner->hot_before[lease];
+	if (!cs_native_sample_for(before, bucket) ||
+	    !cs_native_sample_for(&sample, bucket)) {
+		err = -ENODATA;
+		goto out;
+	}
+	last = cs_native_hot_stamp(&owner->native.clocks[lease], before,
+				   &sample);
+	if (!last) {
+		err = -ENODATA;
+		goto out;
+	}
+	elapsed = io.now_us(io.context) - last;
+	*lastused = jiffies - nsecs_to_jiffies64(elapsed * NSEC_PER_USEC);
+out:
+	mutex_unlock(&owner->lock);
+	return err;
+}
+EXPORT_SYMBOL_GPL(cs7542_fe_live_native_lastused);
+
+static int cs_native_activity_get(char *buf, const struct kernel_param *kp)
+{
+	struct cs7542_fe_live *owner;
+	int len = 0;
+
+	mutex_lock(&cs_fe_live_owners_lock);
+	list_for_each_entry(owner, &cs_fe_live_owners, node) {
+		struct cs_fe_backend_io io;
+		unsigned int i;
+		u32 range = 0;
+		int err, ready;
+
+		mutex_lock(&owner->lock);
+		ready = cs_fe_live_ready(owner);
+		if (!ready && owner->backend.pending)
+			ready = -EBUSY;
+		io = cs_fe_live_io(owner);
+		io.limit_us = io.now_us(io.context) + 12000;
+		err = ready ?:
+			      cs_fe_native_mtu_readback(&owner->native.range[0],
+							&io, 0, &range);
+		len += sysfs_emit_at(buf, len, "epoch=%llu range_error=%d range0=0x%08x\n",
+			owner->epoch, err, range);
+		range = 0;
+		err = ready ?:
+			      cs_fe_native_mtu_readback(&owner->native.range[1],
+							&io, 1, &range);
+		len += sysfs_emit_at(buf, len,
+			"range1_error=%d range1=0x%08x configured_high=%u\n",
+			err, range, READ_ONCE(cs_native_mtu1500_high));
+		for (i = 0;
+		     i < owner->backend.next_lease && len < PAGE_SIZE - 256;
+		     i++) {
+			const struct cs_fe_backend_lease *lease =
+				&owner->backend.lease[i];
+			const struct cs7542_fe_hot_sample *before =
+				&owner->hot_before[i];
+			const struct cs_fe_tuple *tuple = &lease->rule.original;
+			struct cs7542_fe_hot_sample sample = {};
+			unsigned int bucket = lease->plan.key.bucket;
+			bool initial, complete, active;
+			__be32 src, dst;
+
+			if (!lease->policy.require_mtu_range ||
+			    !lease->submitted)
+				continue;
+			active = cs_native_lease_active(owner, i);
+			if (active && !ready)
+				cs_fe_hot_read(&io, bucket, &sample);
+			else if (!active)
+				sample = owner->hot_after[i];
+			initial = cs_native_sample_for(before, bucket);
+			complete = cs_native_sample_for(&sample, bucket) &&
+				   initial &&
+				   sample.timestamp_us >= before->timestamp_us;
+			src = htonl(tuple->src);
+			dst = htonl(tuple->dst);
+			len += sysfs_emit_at(buf, len,
+				"lease=%u bucket=%u active=%u uncertain=%u src=%pI4 dst=%pI4 sport=%u dport=%u before_complete=%u before=%u sample_complete=%u sample=%u transition=%u range_row=%u l4proto=%u\n",
+				i, bucket, active, !!ready, &src, &dst,
+				tuple->sport, tuple->dport, initial,
+				before->selected, complete, sample.selected,
+				complete && !before->selected &&
+					sample.selected,
+				lease->policy.require_mtu_range ==
+					CS_FE_MTU_RANGE_1500,
+				cs_fe_l4proto(&lease->rule, &lease->policy));
+		}
+		mutex_unlock(&owner->lock);
+		if (len >= PAGE_SIZE - 256)
+			break;
+	}
+	mutex_unlock(&cs_fe_live_owners_lock);
+	return len;
+}
+
+static const struct kernel_param_ops cs_native_activity_ops = {
+	.get = cs_native_activity_get
+};
+
+module_param_cb(native_activity, &cs_native_activity_ops, NULL, 0400);
diff --git a/drivers/net/ethernet/cortina/cs_fe_native_mtu.h b/drivers/net/ethernet/cortina/cs_fe_native_mtu.h
new file mode 100644
index 000000000..7a55b1d49
--- /dev/null
+++ b/drivers/net/ethernet/cortina/cs_fe_native_mtu.h
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef CS_FE_NATIVE_MTU_H
+#define CS_FE_NATIVE_MTU_H
+
+#include "cs_fe_backend.h"
+
+/* The two positive HASH predicates index immutable, independently owned rows. */
+#define CS_FE_NATIVE_RANGE_ROWS 2U
+#define CS_FE_NATIVE_SMALL_HIGH 1046U
+#define CS_FE_NATIVE_IP_MTU 1500U
+/*
+ * A [64,1046] hardware range ended at IP length 1020 in both directions.
+ * The verified 1526 limit includes a 1500-byte IP packet on QCA4 framing.
+ */
+#define CS_FE_NATIVE_1500_MAX_HIGH 1526U
+
+struct cs_fe_native_mtu {
+	bool owned;
+	bool touched;
+	int error;
+};
+
+static inline u8 cs_fe_native_mtu_select(unsigned int route_mtu,
+					 unsigned int high)
+{
+	if (route_mtu < CS_FE_NATIVE_SMALL_HIGH)
+		return 0;
+	if (high && route_mtu >= CS_FE_NATIVE_IP_MTU)
+		return CS_FE_MTU_RANGE_1500;
+	return CS_FE_MTU_RANGE_SMALL;
+}
+
+int cs_fe_native_mtu_readback(const struct cs_fe_native_mtu *range,
+			      const struct cs_fe_backend_io *io,
+			      unsigned int row, u32 *actual);
+int cs_fe_native_mtu_prepare(struct cs_fe_native_mtu *range,
+			     const struct cs_fe_backend_io *io,
+			     unsigned int row, unsigned int high);
+int cs_fe_native_mtu_verify(struct cs_fe_native_mtu *range,
+			    const struct cs_fe_backend_io *io, unsigned int row,
+			    unsigned int high);
+
+#endif
diff --git a/drivers/net/ethernet/cortina/cs_fe_native_mtu.inc b/drivers/net/ethernet/cortina/cs_fe_native_mtu.inc
new file mode 100644
index 000000000..f0db52c1d
--- /dev/null
+++ b/drivers/net/ethernet/cortina/cs_fe_native_mtu.inc
@@ -0,0 +1,128 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Included by the driver's sole indirect table owner. */
+#include "cs_fe_native_mtu.h"
+#define MTU_ACCESS 0x288U
+#define MTU_DATA 0x28cU
+
+static u32 cs_fe_native_range_word(unsigned int row, unsigned int high)
+{
+	if (!((row == 0 && high == CS_FE_NATIVE_SMALL_HIGH) ||
+	      (row == 1 && high >= CS_FE_NATIVE_IP_MTU &&
+	       high <= CS_FE_NATIVE_1500_MAX_HIGH)))
+		return 0;
+	return (1U << 28) | (high << 14) | 64U;
+}
+
+static int cs_fe_native_range_read(const struct cs_fe_backend_io *io,
+				   unsigned int row, u32 *word)
+{
+	int ret;
+
+	ret = idle(io, MTU_ACCESS);
+	if (!ret)
+		ret = before(io);
+	if (!ret)
+		ret = io->write32(io->context, MTU_ACCESS, ACL_START | row);
+	if (!ret)
+		ret = idle(io, MTU_ACCESS);
+	if (!ret)
+		ret = before(io);
+	if (!ret)
+		ret = io->read32(io->context, MTU_DATA, word);
+	return ret ?: before(io);
+}
+
+static int cs_fe_native_range_args(const struct cs_fe_native_mtu *range,
+				   const struct cs_fe_backend_io *io)
+{
+	if (!range || !io || !io->read32 || !io->write32 || !io->now_us ||
+	    !io->limit_us || io->extent < MTU_DATA + sizeof(u32))
+		return -EINVAL;
+
+	return range->error;
+}
+
+int cs_fe_native_mtu_readback(const struct cs_fe_native_mtu *range,
+			      const struct cs_fe_backend_io *io,
+			      unsigned int row, u32 *actual)
+{
+	int ret = cs_fe_native_range_args(range, io);
+
+	if (ret || !actual || row >= CS_FE_NATIVE_RANGE_ROWS)
+		return ret ?: -EINVAL;
+	if (!range->owned)
+		return -ENOENT;
+	return cs_fe_native_range_read(io, row, actual);
+}
+
+int cs_fe_native_mtu_verify(struct cs_fe_native_mtu *range,
+			    const struct cs_fe_backend_io *io, unsigned int row,
+			    unsigned int high)
+{
+	u32 expected = cs_fe_native_range_word(row, high);
+	u32 actual;
+	int ret;
+
+	ret = cs_fe_native_range_args(range, io);
+	if (ret || !expected)
+		return ret ?: -EINVAL;
+	if (!range->owned)
+		return -ENOENT;
+
+	ret = cs_fe_native_range_read(io, row, &actual);
+	if (!ret && actual != expected)
+		ret = -EUCLEAN;
+	if (ret)
+		range->error = ret;
+	return ret;
+}
+
+int cs_fe_native_mtu_prepare(struct cs_fe_native_mtu *range,
+			     const struct cs_fe_backend_io *io,
+			     unsigned int row, unsigned int high)
+{
+	u32 expected = cs_fe_native_range_word(row, high);
+	u32 actual;
+	int ret;
+
+	ret = cs_fe_native_range_args(range, io);
+	if (ret || !expected)
+		return ret ?: -EINVAL;
+	if (range->owned)
+		return cs_fe_native_mtu_verify(range, io, row, high);
+
+	ret = cs_fe_native_range_read(io, row, &actual);
+	if (ret)
+		return ret;
+	/*
+	 * The calibration bank and any foreign nonzero row have their own
+	 * lifetime. Even byte-identical contents do not convey ownership.
+	 */
+	if (actual)
+		return -EBUSY;
+
+	ret = before(io);
+	if (ret)
+		return ret;
+	/* A failed write may already have reached the indirect interface. */
+	range->touched = true;
+	ret = io->write32(io->context, MTU_DATA, expected);
+	if (!ret)
+		ret = before(io);
+	if (!ret)
+		ret = io->write32(io->context, MTU_ACCESS,
+				  ACL_START | ACL_WRITE | row);
+	if (!ret)
+		ret = idle(io, MTU_ACCESS);
+	if (!ret)
+		ret = cs_fe_native_range_read(io, row, &actual);
+	if (!ret && actual != expected)
+		ret = -EUCLEAN;
+	if (ret) {
+		range->error = ret;
+		return ret;
+	}
+
+	range->owned = true;
+	return 0;
+}
diff --git a/drivers/net/ethernet/cortina/cs_fe_native_state.h b/drivers/net/ethernet/cortina/cs_fe_native_state.h
new file mode 100644
index 000000000..c86e3a3e3
--- /dev/null
+++ b/drivers/net/ethernet/cortina/cs_fe_native_state.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef CS_FE_NATIVE_STATE_H
+#define CS_FE_NATIVE_STATE_H
+
+#include <linux/cs7542_fe_native.h>
+#include "cs_fe_native_mtu.h"
+
+struct cs_fe_native_flow {
+	u64 block, version;
+	unsigned long cookie;
+	struct cs7542_fe_native_request path;
+};
+
+struct cs_fe_native_clock {
+	u64 baseline_us, last_zero_us, lastuse_us;
+};
+
+struct cs_fe_native_state {
+	struct cs_fe_native_clock clocks[CS_FE_BACKEND_LEASES];
+	struct cs_fe_native_mtu range[CS_FE_NATIVE_RANGE_ROWS];
+	struct cs_fe_native_flow flows[CS_FE_BACKEND_ENTRIES];
+};
+
+#endif
diff --git a/include/linux/cs7542_fe_backend.h b/include/linux/cs7542_fe_backend.h
new file mode 100644
index 000000000..2c412e17f
--- /dev/null
+++ b/include/linux/cs7542_fe_backend.h
@@ -0,0 +1,65 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef CS7542_FE_BACKEND_H
+#define CS7542_FE_BACKEND_H
+#include <linux/types.h>
+struct module;
+struct cs_fe_backend;
+struct cs_fe_backend_io;
+struct cs_fe_rule;
+struct cs_fe_key_policy;
+struct cs_fe_backend_encoding;
+struct cs_fe_plan;
+#define CS7542_FE_BACKEND_ABI 6
+
+enum cs_fe_hot_command {
+	CS_HOT_REPLACE,
+	CS_HOT_SCOPED,
+	CS_HOT_GUARDED,
+	CS_HOT_MARKER,
+	CS_HOT_ENCODED,
+	CS_HOT_REJECT,
+	CS_HOT_DESTROY,
+	CS_HOT_UNBIND,
+	CS_HOT_NATIVE,
+};
+
+/* Every pointer is borrowed synchronously under the NIC owner mutex. */
+
+#ifndef CS_FE_HOT_SELECTOR_DEFINED
+#define CS_FE_HOT_SELECTOR_DEFINED
+struct cs_fe_hot_selector {
+	u8 source[6], destination[6];
+	bool valid;
+};
+
+#endif
+struct cs_fe_hot_request {
+	struct cs_fe_hot_selector selector;
+	const struct cs_fe_plan
+		*validated_plan; /* optional borrowed owner receipt */
+	u64 block, version;
+	unsigned long cookie;
+	const struct cs_fe_rule *rule;
+	const struct cs_fe_key_policy *policy;
+	const struct cs_fe_backend_encoding *encoding;
+	int reason;
+	bool exact;
+};
+
+struct cs7542_fe_backend_ops {
+	u32 abi, size, state_size, revision;
+	struct module *owner;
+	const char *name;
+	int (*run)(enum cs_fe_hot_command command, struct cs_fe_backend *state,
+		   const struct cs_fe_backend_io *typed_io,
+		   const struct cs_fe_hot_request *request);
+};
+
+/*
+ * Registration pins module text. Runtime release is builtin sysfs only.
+ *
+ * module_exit performs no hardware cleanup and must never drop the last pin.
+ */
+int cs7542_fe_backend_register(const struct cs7542_fe_backend_ops *ops);
+bool cs7542_fe_backend_registered(const struct cs7542_fe_backend_ops *ops);
+#endif
diff --git a/include/linux/cs7542_fe_codec.h b/include/linux/cs7542_fe_codec.h
new file mode 100644
index 000000000..b2a3d7d60
--- /dev/null
+++ b/include/linux/cs7542_fe_codec.h
@@ -0,0 +1,145 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef CS_FE_ENCODE_H
+#define CS_FE_ENCODE_H
+
+#ifdef __KERNEL__
+#include <linux/types.h>
+#else
+#include <stdbool.h>
+#include <stdint.h>
+typedef uint8_t u8;
+typedef uint16_t u16;
+typedef uint32_t u32;
+#endif
+
+/* Numeric host order. Only the Linux adapter converts network-order tuples. */
+struct cs_fe_tuple {
+	u32 src;
+	u32 dst;
+	u16 sport;
+	u16 dport;
+};
+
+struct cs_fe_link {
+	u8 gmac;
+	u8 tag_mode;
+	u8 switch_port;
+	u8 cpu_port;
+	u16 base_voq;
+	u16 rx_qca_meta;
+	u8 base_mac[6];
+};
+
+struct cs_fe_rule {
+	struct cs_fe_tuple original;
+	struct cs_fe_tuple translated;
+	struct cs_fe_link ingress;
+	struct cs_fe_link egress;
+	u8 smac[6];
+	u8 dmac[6];
+	bool decrement_ttl;
+	/* Consumed only with a native per-packet range. Zero selects legacy UDP. */
+	u8 native_l4proto;
+};
+
+/* Leased by a separate owner, never allocated or deleted by this codec. */
+struct cs_fe_rows {
+	u16 class_row;
+	u16 sdb_row;
+	u16 mask_row;
+	u16 miss_fwd;
+	u16 hit_fwd;
+	u16 voq;
+	u16 l2;
+	u16 l3;
+	u16 fvlan;
+	u8 priority;
+	/* Diagnostic only, with both fallback IP replacements disabled. */
+	u32 miss_marker;
+};
+
+/* NF rules wildcard DSCP. Exact DSCP is an explicit lab profile only. */
+struct cs_fe_key_policy {
+	bool exact_dscp;
+	u8 dscp;
+	/* One positive PKTLEN_RANGE bit, or zero for a profile without a range. */
+	u8 require_mtu_range;
+};
+
+#define CS_FE_L4_TCP 6U
+#define CS_FE_L4_UDP 17U
+
+static inline u8 cs_fe_l4proto(const struct cs_fe_rule *rule,
+			       const struct cs_fe_key_policy *policy)
+{
+	if (policy->require_mtu_range && rule->native_l4proto)
+		return rule->native_l4proto;
+	return CS_FE_L4_UDP;
+}
+
+#define CS_FE_MTU_RANGE_SMALL 1U
+#define CS_FE_MTU_RANGE_1500 2U
+
+struct cs_fe_key {
+	u8 bytes[84];
+	u32 crc32;
+	u16 crc16;
+	u16 bucket;
+};
+
+#define CS_FE_IMAGE(n)           \
+	struct {                 \
+		u32 input[n];    \
+		u32 expected[n]; \
+		u8 words;        \
+	}
+
+/* IHL5, no fragments, valid nonzero UDP checksum, TTL > 1 and MTU guards. */
+#define CS_FE_REQ_PACKET_EXCEPTIONS (1U << 0)
+#define CS_FE_REQ_COLLISION_CHECK (1U << 1)
+#define CS_FE_REQ_OWNER_LIFETIME (1U << 2)
+
+struct cs_fe_plan {
+	struct cs_fe_key key;
+
+	CS_FE_IMAGE(20) class_invalid, class_valid;
+	CS_FE_IMAGE(7) sdb;
+	CS_FE_IMAGE(5) mask, l3;
+	CS_FE_IMAGE(4) miss, hit, l2;
+	CS_FE_IMAGE(2) voq, fvlan;
+	/* Fresh main way0/slot0. No hardware valid bit is invented. */
+	u32 hash[4];
+	unsigned int requirements;
+	bool write_l3;
+	bool write_fvlan;
+	bool source_nat;
+	bool destination_nat;
+	/* Prediction, not an internal-link observation. */
+	u16 predicted_tx_qca;
+};
+
+#undef CS_FE_IMAGE
+
+/*
+ * Pure serialization: return0 is not hardware acceptance. No MMIO, allocation,
+ * retention or exception proof is provided. Failure leaves output untouched.
+ */
+int cs_fe_encode(const struct cs_fe_rule *rule, const struct cs_fe_rows *rows,
+		 const struct cs_fe_key_policy *policy, struct cs_fe_plan *out);
+void cs_fe_exact_class_ipv4(struct cs_fe_plan *plan,
+			    const struct cs_fe_tuple *tuple, const u8 source[6],
+			    const u8 destination[6]);
+
+enum cs_fe_class_match {
+	CS_FE_CLASS_MATCH_DA = 1,
+	CS_FE_CLASS_MATCH_SA = 2,
+	CS_FE_CLASS_MATCH_IP_DA = 4,
+	CS_FE_CLASS_MATCH_IP_SA = 8,
+	CS_FE_CLASS_MATCH_REVERSED_MAC = 16,
+};
+
+void cs_fe_class_addresses(struct cs_fe_plan *plan,
+			   const struct cs_fe_tuple *tuple, const u8 source[6],
+			   const u8 destination[6], unsigned int match);
+
+#endif
diff --git a/include/linux/cs7542_fe_live.h b/include/linux/cs7542_fe_live.h
new file mode 100644
index 000000000..fe863c058
--- /dev/null
+++ b/include/linux/cs7542_fe_live.h
@@ -0,0 +1,58 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_CS7542_FE_LIVE_H
+#define _LINUX_CS7542_FE_LIVE_H
+#include <linux/types.h>
+#include <linux/cs7542_fe_codec.h>
+#define CS7542_FE_LIVE_API_VERSION 1
+#ifndef __KERNEL__
+typedef uint64_t u64;
+#define __iomem
+#endif
+struct device;
+struct net_device;
+struct cs_fe_rule;
+struct cs_fe_key_policy;
+struct cs7542_fe_live;
+/* Built-in owner only; no arbitrary row, address, register or table selector. */
+struct cs7542_fe_live_status {
+	u64 epoch;
+	u32 admitted_requirements, leases, capacity, blocks;
+	int first_error;
+	bool online, closing, poisoned, pending, reset_verified;
+};
+
+/*
+ * Borrowed conduit is resolved to its actual NE context. Returned references
+ *
+ * pin this BUILT-IN owner metadata, never authorize I/O after owner_stop.
+ */
+struct cs7542_fe_live *cs7542_fe_live_get(struct net_device *conduit);
+void cs7542_fe_live_put(struct cs7542_fe_live *owner);
+int cs7542_fe_live_open(struct cs7542_fe_live *owner, u64 *owner_block);
+int cs7542_fe_live_reject(struct cs7542_fe_live *owner, u64 owner_block,
+			  unsigned long cookie, u64 version, int reason);
+int cs7542_fe_live_destroy(struct cs7542_fe_live *owner, u64 owner_block,
+			   unsigned long cookie, u64 current_version);
+int cs7542_fe_live_close(struct cs7542_fe_live *owner, u64 owner_block);
+int cs7542_fe_live_status(struct cs7542_fe_live *owner,
+			  struct cs7542_fe_live_status *status);
+/*
+ * Engine hooks, never called by the loadable provider. init serializes the
+ * existing real FE initialization under the SAME mutex as runtime scratch.
+ * Stop excludes I/O BEFORE devres unmap; reset_done only follows verified
+ * complete NE reset, not merely port-down or a failed reset attempt.
+ */
+struct cs7542_fe_live *cs7542_fe_live_create(struct device *dev,
+					     void __iomem *base,
+					     unsigned int extent);
+int cs7542_fe_live_init(struct cs7542_fe_live *owner,
+			int (*initialize)(struct device *dev,
+					  void __iomem *base));
+void cs7542_fe_live_activate(struct cs7542_fe_live *owner);
+int cs7542_fe_live_bind(struct cs7542_fe_live *owner,
+			struct net_device *conduit, unsigned int gmac);
+void cs7542_fe_live_unbind(struct cs7542_fe_live *owner,
+			   struct net_device *conduit, unsigned int gmac);
+void cs7542_fe_live_stop(struct cs7542_fe_live *owner);
+void cs7542_fe_live_reset_done(struct cs7542_fe_live *owner);
+#endif
diff --git a/include/linux/cs7542_fe_native.h b/include/linux/cs7542_fe_native.h
new file mode 100644
index 000000000..97ab51e28
--- /dev/null
+++ b/include/linux/cs7542_fe_native.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef CS7542_FE_NATIVE_H
+#define CS7542_FE_NATIVE_H
+
+#include <linux/cs7542_fe_live.h>
+
+#define CS7542_FE_NATIVE_ABI 2
+
+/*
+ * Only ordinary Ethernet and Linux route properties cross the module boundary.
+ * The owner exclusively manages hardware resources and decides admission.
+ */
+struct cs7542_fe_native_request {
+	u32 abi, size;
+	u64 format_epoch;
+	u32 ingress_ifindex, egress_ifindex;
+	u16 route_mtu;
+	u8 ingress_smac[6];
+	struct cs_fe_rule rule;
+};
+
+int cs7542_fe_live_replace_native(struct cs7542_fe_live *owner, u64 block, unsigned long cookie,
+	u64 version, const struct cs7542_fe_native_request *request);
+
+struct flow_cls_offload;
+int cs7542_fe_live_replace_native_tcp(struct cs7542_fe_live *owner, u64 block, unsigned long cookie,
+	u64 version, const struct cs7542_fe_native_request *request,
+	const struct flow_cls_offload *cls);
+
+int cs7542_fe_live_native_lastused(struct cs7542_fe_live *owner, u64 block,
+				   unsigned long cookie,
+				   unsigned long *lastused);
+
+#endif
diff --git a/include/linux/cs7542_ft_live.h b/include/linux/cs7542_ft_live.h
new file mode 100644
index 000000000..c7e318eb5
--- /dev/null
+++ b/include/linux/cs7542_ft_live.h
@@ -0,0 +1,70 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_CS7542_FT_LIVE_H
+#define _LINUX_CS7542_FT_LIVE_H
+#include <linux/types.h>
+struct module;
+struct net_device;
+struct flow_cls_offload;
+struct cs7542_ft_live;
+/*
+ * No private NF cookie interpretation. All calls synchronous and borrowed.
+ * rule() may resolve topology with rtnl_trylock ONLY: core BIND holds RTNL.
+ * No raw MMIO is exposed by this entrypoint. A separate built-in FE owner
+ * issues numeric leases and retains quarantine across provider replacement.
+ */
+#define CS7542_FT_LIVE_API_VERSION 1
+struct cs7542_ft_live_ops {
+	u32 api_version;
+	u32 size;
+	struct module *owner;
+	const char *name;
+	int (*open)(void *provider, u64 block, struct net_device *conduit);
+	/*
+	 * REPLACE must retire any prior version before rejecting a new rule.
+	 * Return0 only for a verified installation; pure encoding is NOT acceptance.
+	 * STATS must not fabricate counters/lastused. No borrowed pointer survives.
+	 */
+	int (*rule)(void *provider, u64 block, struct flow_cls_offload *cls);
+	/*
+	 * close success means every lookup owned by this block is inactive; it
+	 * NEVER promises drain/resource reuse. Error keeps provider pinned.
+	 */
+	int (*close)(void *provider, u64 block);
+	/*
+	 * Close all provider-owned non-NF proof handles too. Serialize against its
+	 * controls, cancel further arms, and retain module pin on any uncertainty.
+	 */
+	int (*detach)(void *provider);
+};
+
+int cs7542_ft_live_register(const struct cs7542_ft_live_ops *ops,
+			    void *provider);
+/*
+ * Explicitly call before rmmod. On error registration remains closed+pinned;
+ * retry is permitted. module_exit cannot report failed withdrawal.
+ */
+/*
+ * Runtime unregister must be initiated from built-in detach sysfs, not a
+ * module-text control that could drop its last pin while still executing.
+ * This exported form is for COMING/module_init rollback only.
+ */
+int cs7542_ft_live_unregister(const struct cs7542_ft_live_ops *ops,
+			      void *provider);
+struct cs7542_ft_live *cs7542_ft_live_create(struct net_device *conduit,
+					     u32 gmac);
+int cs7542_ft_live_setup(struct cs7542_ft_live *live, int type, void *data);
+/*
+ * Stop all CPU callback access before freeing the conduit. No owner MMIO
+ * lifetime promise: backend FE owner stop/reset is a separate ordered step.
+ */
+/*
+ * Built-in QCA owner only (not exported to modules): serialize table withdrawal
+ * against a format transition, with admission held through exact readback.
+ */
+int cs7542_ft_live_format_hold(void);
+int cs7542_ft_live_format_release(void);
+bool cs7542_ft_live_format_held(void);
+int cs7542_ft_live_quiesce(struct cs7542_ft_live *live);
+void cs7542_ft_live_put(struct cs7542_ft_live *live);
+ssize_t cs7542_ft_live_format(struct cs7542_ft_live *live, char *buffer);
+#endif
diff --git a/include/linux/dsa/qca8k_persistent.h b/include/linux/dsa/qca8k_persistent.h
new file mode 100644
index 000000000..5363f7ad0
--- /dev/null
+++ b/include/linux/dsa/qca8k_persistent.h
@@ -0,0 +1,45 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef QCA8K_PERSISTENT_STATUS_H
+#define QCA8K_PERSISTENT_STATUS_H
+#include <linux/types.h>
+#include <linux/errno.h>
+
+struct net_device;
+#define QCA8K_PERSISTENT_STATUS_VERSION 1
+struct qca8k_persistent_status {
+	__u32 size;
+	__u32 version;
+	__u64 epoch;
+	__u32 selected;
+	__u32 tree_protocol;
+	__u32 requested;
+	__u32 known;
+	__u32 coherent;
+	__u32 ready;
+	__u32 closing;
+	__u32 restore_debt;
+	__u32 uncertain;
+	__s32 first_error;
+	__s32 held_fault;
+	__u32 conduit_mtu[2];
+	__u32 reserved;
+};
+
+/*
+ * Process context with RTNL held. Read-only, no table programming, deadline or
+ * fabricated bounded ownership. The caller must require known/coherent/ready
+ * and still enforce every independent packet/topology/hardware admission gate.
+ */
+#if IS_ENABLED(CONFIG_NET_DSA_QCA8K_4B_MODE)
+int qca8k_persistent_status(struct net_device *conduit,
+			    struct qca8k_persistent_status *status);
+#else
+static inline int
+qca8k_persistent_status(struct net_device *conduit,
+			struct qca8k_persistent_status *status)
+{
+	return -EOPNOTSUPP;
+}
+
+#endif
+#endif

-- 
2.53.0



^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH RFC net-next 5/7] net: dsa: qca8k: select the four-byte format before port activation
  2026-11-25 20:50 [PATCH RFC net-next 0/7] net: cortina: CS7542 wired IPv4 hardware flowtable offload Fil Dunsky via B4 Relay
                   ` (3 preceding siblings ...)
  2026-11-25 20:50 ` [PATCH RFC net-next 4/7] net: cortina: add a serialized CS7542 forwarding engine owner Fil Dunsky via B4 Relay
@ 2026-11-25 20:50 ` Fil Dunsky via B4 Relay
  2026-11-25 21:13   ` Andrew Lunn
  2026-11-25 20:50 ` [PATCH RFC net-next 6/7] net: cortina: connect wired IPv4 NAT to nftables hardware flowtables Fil Dunsky via B4 Relay
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 13+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-11-25 20:50 UTC (permalink / raw)
  To: Andrew Lunn, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Florian Fainelli, Simon Horman, Pablo Neira Ayuso,
	Florian Westphal, Phil Sutter, Hans Ulli Kroll, Linus Walleij,
	Andrew Lunn, Russell King, Christian Marangi, Jonathan Corbet,
	Shuah Khan, Randy Dunlap
  Cc: netdev, devicetree, linux-kernel, netfilter-devel, coreteam,
	linux-arm-kernel, linux-doc, Fil Dunsky

From: Fil Dunsky <filipp.dunsky@gmail.com>

Select the requested format from the CPU ports before DSA chooses its
tagger. Stop packet actors and verify the switch header state before
opening user ports. Use MDIO for management and preserve both conduit
MTUs.

On teardown, retire flowtable lookups before changing the format.
Restore and verify the two-byte baseline before releasing the format
hold. The initial supported topology is the CS7542 dual-conduit QCA8337
arrangement; unsupported topologies remain rejected.

Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com>
---
 drivers/net/dsa/qca/persistent_qca4.h              | 178 ++++++
 drivers/net/dsa/qca/persistent_qca4_mtu.h          | 165 ++++++
 drivers/net/dsa/qca/qca8k-8xxx.c                   | 123 +++-
 drivers/net/dsa/qca/qca8k-common.c                 |  42 +-
 drivers/net/dsa/qca/qca8k-persistent-boot.inc      | 632 +++++++++++++++++++++
 drivers/net/dsa/qca/qca8k-persistent-lifecycle.inc | 394 +++++++++++++
 drivers/net/dsa/qca/qca8k.h                        |  40 ++
 7 files changed, 1564 insertions(+), 10 deletions(-)

diff --git a/drivers/net/dsa/qca/persistent_qca4.h b/drivers/net/dsa/qca/persistent_qca4.h
new file mode 100644
index 000000000..6e4dc2162
--- /dev/null
+++ b/drivers/net/dsa/qca/persistent_qca4.h
@@ -0,0 +1,178 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Source-only transaction core. No driver hookup or register-address API. */
+#ifndef QCA4_PERSISTENT_TRANSACTION_H
+#define QCA4_PERSISTENT_TRANSACTION_H
+#ifdef __KERNEL__
+#include <linux/types.h>
+#include <linux/errno.h>
+typedef u32 qca4_word;
+#else
+#include <stdint.h>
+#include <stdbool.h>
+#include <errno.h>
+typedef uint32_t qca4_word;
+#endif
+
+#define QCA4_PERSISTENT_MASK 0x1ffffU
+#define QCA4_PERSISTENT_VALUE 0x18100U
+#define QCA4_PERSISTENT_CPU_HEADER 0xaU
+
+/*
+ * Stop/restore callbacks must attempt every relevant field and preserve the
+ * first errno separately from verified readback. Only the actual bus owner
+ * may implement them; this header supplies no hardware executor.
+ */
+struct qca4_persistent_ops {
+	void *context;
+	int (*quiesce)(void *context);
+	int (*stop_all_macs)(void *context);
+	int (*read_global)(void *context, qca4_word *value);
+	int (*read_cpu_header)(void *context, unsigned int cpu_port,
+			       qca4_word *value);
+	int (*set_global)(void *context, qca4_word value, bool restore,
+			  bool *verified);
+	int (*software_ready)(void *context);
+	int (*replay_cpu_enables)(void *context);
+};
+
+struct qca4_persistent_state {
+	bool requested;
+	bool hardware4;
+	bool ready;
+	bool saved_valid;
+	bool restore_pending;
+	bool unknown;
+	qca4_word saved_header;
+	int first_error;
+};
+
+static inline int qca4_persistent_error(struct qca4_persistent_state *state,
+					int error)
+{
+	if (error < 0 && !state->first_error)
+		state->first_error = error;
+	return error;
+}
+
+/*
+ * May run only after all packet actors are closed/drained, before software
+ * detachment, or during unpublished setup unwind. No running tagger is flipped.
+ */
+static inline int qca4_persistent_restore(struct qca4_persistent_state *state,
+					  struct qca4_persistent_ops *ops)
+{
+	bool verified = false;
+	int error;
+
+	state->ready = false;
+	error = ops->quiesce(ops->context);
+	if (error)
+		return qca4_persistent_error(state, error);
+	error = ops->stop_all_macs(ops->context);
+	if (error)
+		return qca4_persistent_error(state, error);
+	if (!state->restore_pending)
+		return 0;
+	if (!state->saved_valid)
+		return qca4_persistent_error(state, -EUCLEAN);
+	error = ops->set_global(ops->context, state->saved_header, true,
+				&verified);
+	qca4_persistent_error(state, error);
+	if (!verified) {
+		state->unknown = true;
+		return error ? error : qca4_persistent_error(state, -EIO);
+	}
+	state->hardware4 = false;
+	state->restore_pending = false;
+	state->unknown = false;
+	return error;
+}
+
+static inline int qca4_persistent_begin(struct qca4_persistent_state *state,
+					struct qca4_persistent_ops *ops,
+					bool opt_in)
+{
+	qca4_word header;
+	bool verified = false;
+	int error;
+
+	if (!opt_in)
+		return 0; /* Default QCA2: zero callbacks and zero new I/O. */
+	if (state->requested || state->restore_pending || state->first_error)
+		return -EBUSY;
+	state->requested = true;
+	error = ops->quiesce(ops->context);
+	if (error)
+		return qca4_persistent_error(state, error);
+	error = ops->stop_all_macs(ops->context);
+	if (error)
+		return qca4_persistent_error(state, error);
+	error = ops->read_global(ops->context, &header);
+	if (error)
+		return qca4_persistent_error(state, error);
+	if (header & 0x10000U)
+		return qca4_persistent_error(state, -EUCLEAN);
+	state->saved_header = header & QCA4_PERSISTENT_MASK;
+	state->saved_valid = true;
+	error = ops->read_cpu_header(ops->context, 0, &header);
+	if (!error && header != QCA4_PERSISTENT_CPU_HEADER)
+		error = -EUCLEAN;
+	if (!error)
+		error = ops->read_cpu_header(ops->context, 6, &header);
+	if (!error && header != QCA4_PERSISTENT_CPU_HEADER)
+		error = -EUCLEAN;
+	if (error)
+		return qca4_persistent_error(state, error);
+	state->restore_pending = true; /* Before a possibly applied write. */
+	error = ops->set_global(ops->context, QCA4_PERSISTENT_VALUE, false,
+				&verified);
+	if (error || !verified) {
+		qca4_persistent_error(state, error ? error : -EIO);
+		(void)qca4_persistent_restore(state, ops);
+		return state->first_error;
+	}
+	state->hardware4 = true;
+	return 0;
+}
+
+/*
+ * First-user-open gate, after actual DSA conduit setup. software_ready must
+ * check both actual dsa_ptr/tag_ops/rcv identities AND effective MTUs. The
+ * conduit MTU setter returning success earlier is insufficient evidence.
+ */
+static inline int qca4_persistent_ready(struct qca4_persistent_state *state,
+					struct qca4_persistent_ops *ops)
+{
+	qca4_word header;
+	int error;
+
+	if (!state->hardware4 || state->unknown || state->first_error)
+		return -EIO;
+	error = ops->software_ready(ops->context);
+	if (error)
+		return error;
+	error = ops->read_global(ops->context, &header);
+	if (!error && (header & QCA4_PERSISTENT_MASK) != QCA4_PERSISTENT_VALUE)
+		error = -EUCLEAN;
+	if (!error)
+		error = ops->read_cpu_header(ops->context, 0, &header);
+	if (!error && header != QCA4_PERSISTENT_CPU_HEADER)
+		error = -EUCLEAN;
+	if (!error)
+		error = ops->read_cpu_header(ops->context, 6, &header);
+	if (!error && header != QCA4_PERSISTENT_CPU_HEADER)
+		error = -EUCLEAN;
+	if (!error)
+		error = ops->replay_cpu_enables(ops->context);
+	if (error) {
+		int stopped = ops->stop_all_macs(ops->context);
+
+		if (stopped)
+			state->unknown = true;
+		return qca4_persistent_error(state, error);
+	}
+	state->ready = true;
+	return 0;
+}
+
+#endif
diff --git a/drivers/net/dsa/qca/persistent_qca4_mtu.h b/drivers/net/dsa/qca/persistent_qca4_mtu.h
new file mode 100644
index 000000000..efbc482bb
--- /dev/null
+++ b/drivers/net/dsa/qca/persistent_qca4_mtu.h
@@ -0,0 +1,165 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef QCA4_PERSISTENT_MTU_H
+#define QCA4_PERSISTENT_MTU_H
+#include "persistent_qca4.h"
+
+enum qca4_persistent_mtu_field {
+	QCA4_PMTU_CONDUIT0,
+	QCA4_PMTU_CONDUIT6,
+	QCA4_PMTU_FRAME,
+	QCA4_PMTU_MAC0,
+	QCA4_PMTU_MAC6,
+	QCA4_PMTU_FIELDS,
+};
+
+struct qca4_persistent_mtu_state {
+	qca4_word saved[QCA4_PMTU_FIELDS];
+	qca4_word committed_mtu[2];
+	qca4_word committed_frame;
+	bool committed_valid;
+	bool pending;
+	bool unknown;
+	int first_error;
+};
+
+struct qca4_persistent_mtu_ops {
+	void *context;
+	int (*read)(void *context, enum qca4_persistent_mtu_field field, qca4_word *value);
+	int (*write)(void *context, enum qca4_persistent_mtu_field field, qca4_word value,
+		     bool restore, bool *verified);
+};
+
+static inline void qca4_pmtu_error(struct qca4_persistent_mtu_state *state,
+				   int error)
+{
+	if (error && !state->first_error)
+		state->first_error = error;
+}
+
+static inline int qca4_pmtu_write(struct qca4_persistent_mtu_ops *ops,
+				  enum qca4_persistent_mtu_field field,
+				  qca4_word value, bool restore, bool *verified)
+{
+	int ret;
+
+	*verified = false;
+	ret = ops->write(ops->context, field, value, restore, verified);
+	return ret ? ret : *verified ? 0 : -EIO;
+}
+
+/*
+ * Caller holds RTNL and the SAME mutex used by async MAC callbacks. No nested
+ * phylink stop/close here. Both CPU MACs must be independently verified stopped
+ * before any conduit/global frame update, including rollback.
+ */
+static inline int qca4_pmtu_restore(struct qca4_persistent_mtu_state *state,
+				    struct qca4_persistent_mtu_ops *ops)
+{
+	bool verified, stopped = true, restored = true;
+	int field, ret, first = 0;
+
+	if (!state->pending)
+		return 0;
+	for (field = QCA4_PMTU_MAC0; field <= QCA4_PMTU_MAC6; field++) {
+		ret = qca4_pmtu_write(ops, field, 0, true, &verified);
+		if (ret && !first)
+			first = ret;
+		if (!verified)
+			stopped = false;
+	}
+	if (!stopped)
+		goto unknown;
+	for (field = QCA4_PMTU_CONDUIT0; field <= QCA4_PMTU_FRAME; field++) {
+		ret = qca4_pmtu_write(ops, field, state->saved[field], true,
+				      &verified);
+		if (ret && !first)
+			first = ret;
+		if (!verified)
+			restored = false;
+	}
+	if (!restored)
+		goto unknown;
+	for (field = QCA4_PMTU_MAC0; field <= QCA4_PMTU_MAC6; field++) {
+		ret = qca4_pmtu_write(ops, field, state->saved[field], true,
+				      &verified);
+		if (ret && !first)
+			first = ret;
+		if (!verified)
+			restored = false;
+	}
+	if (!restored) {
+		/* A possibly applied restore cannot leave one CPU active. */
+		for (field = QCA4_PMTU_MAC0; field <= QCA4_PMTU_MAC6; field++) {
+			ret = qca4_pmtu_write(ops, field, 0, true, &verified);
+			if (ret && !first)
+				first = ret;
+		}
+		goto unknown;
+	}
+	state->pending = false;
+	state->unknown = false;
+	qca4_pmtu_error(state, first);
+	return first;
+unknown:
+	state->unknown = true;
+	qca4_pmtu_error(state, first ? first : -EIO);
+	return first ? first : -EIO;
+}
+
+static inline int qca4_pmtu_change(struct qca4_persistent_mtu_state *state,
+				   struct qca4_persistent_mtu_ops *ops,
+				   qca4_word conduit_mtu, qca4_word frame)
+{
+	bool verified;
+	int field, ret, original;
+
+	if (state->pending || state->unknown || state->first_error)
+		return -EUCLEAN;
+	for (field = 0; field < QCA4_PMTU_FIELDS; field++) {
+		ret = ops->read(ops->context, field, &state->saved[field]);
+		if (ret)
+			return ret;
+	}
+	/*
+	 * DSA may already have changed the assigned conduit before invoking
+	 * port_change_mtu. Restore our last committed pair, not that half-new
+	 * snapshot. On initial readiness, both actual values are the baseline.
+	 */
+	if (state->committed_valid) {
+		state->saved[QCA4_PMTU_CONDUIT0] = state->committed_mtu[0];
+		state->saved[QCA4_PMTU_CONDUIT6] = state->committed_mtu[1];
+	}
+	state->pending = true;
+	for (field = QCA4_PMTU_MAC0; field <= QCA4_PMTU_MAC6; field++) {
+		ret = qca4_pmtu_write(ops, field, 0, false, &verified);
+		if (ret)
+			goto rollback;
+	}
+	for (field = QCA4_PMTU_CONDUIT0; field <= QCA4_PMTU_FRAME; field++) {
+		ret = qca4_pmtu_write(ops, field,
+				      field == QCA4_PMTU_FRAME ? frame :
+								 conduit_mtu,
+				      false, &verified);
+		if (ret)
+			goto rollback;
+	}
+	for (field = QCA4_PMTU_MAC0; field <= QCA4_PMTU_MAC6; field++) {
+		ret = qca4_pmtu_write(ops, field, state->saved[field], true,
+				      &verified);
+		if (ret)
+			goto rollback;
+	}
+	state->pending = false;
+	state->committed_valid = true;
+	state->committed_mtu[0] = conduit_mtu;
+	state->committed_mtu[1] = conduit_mtu;
+	state->committed_frame = frame;
+	return 0;
+rollback:
+	original = ret;
+	qca4_pmtu_error(state, original);
+	(void)qca4_pmtu_restore(state, ops);
+	return original;
+}
+
+#endif
diff --git a/drivers/net/dsa/qca/qca8k-8xxx.c b/drivers/net/dsa/qca/qca8k-8xxx.c
index 382753bcc..3e120ddaa 100644
--- a/drivers/net/dsa/qca/qca8k-8xxx.c
+++ b/drivers/net/dsa/qca/qca8k-8xxx.c
@@ -174,6 +174,9 @@ static void qca8k_rw_reg_ack_handler(struct dsa_switch *ds, struct sk_buff *skb)
 	u8 len, cmd;
 	int i;
 
+	if (qca8k_private_mgmt_blocked(priv))
+		return;
+
 	mgmt_ethhdr = (struct qca_mgmt_ethhdr *)skb_mac_header(skb);
 	mgmt_eth_data = &priv->mgmt_eth_data;
 
@@ -321,6 +324,9 @@ static int qca8k_read_eth(struct qca8k_priv *priv, u32 reg, u32 *val, int len)
 	bool ack;
 	int ret;
 
+	if (qca8k_private_mgmt_blocked(priv))
+		return -EOPNOTSUPP;
+
 	skb = qca8k_alloc_mdio_header(MDIO_READ, reg, NULL,
 				      QCA8K_ETHERNET_MDIO_PRIORITY, len);
 	if (!skb)
@@ -329,7 +335,7 @@ static int qca8k_read_eth(struct qca8k_priv *priv, u32 reg, u32 *val, int len)
 	mutex_lock(&mgmt_eth_data->mutex);
 
 	/* Check if the mgmt_conduit if is operational */
-	if (!priv->mgmt_conduit) {
+	if (qca8k_private_mgmt_blocked(priv) || !priv->mgmt_conduit) {
 		kfree_skb(skb);
 		mutex_unlock(&mgmt_eth_data->mutex);
 		return -EINVAL;
@@ -373,6 +379,9 @@ static int qca8k_write_eth(struct qca8k_priv *priv, u32 reg, u32 *val, int len)
 	bool ack;
 	int ret;
 
+	if (qca8k_private_mgmt_blocked(priv))
+		return -EOPNOTSUPP;
+
 	skb = qca8k_alloc_mdio_header(MDIO_WRITE, reg, val,
 				      QCA8K_ETHERNET_MDIO_PRIORITY, len);
 	if (!skb)
@@ -381,7 +390,7 @@ static int qca8k_write_eth(struct qca8k_priv *priv, u32 reg, u32 *val, int len)
 	mutex_lock(&mgmt_eth_data->mutex);
 
 	/* Check if the mgmt_conduit if is operational */
-	if (!priv->mgmt_conduit) {
+	if (qca8k_private_mgmt_blocked(priv) || !priv->mgmt_conduit) {
 		kfree_skb(skb);
 		mutex_unlock(&mgmt_eth_data->mutex);
 		return -EINVAL;
@@ -513,7 +522,7 @@ qca8k_bulk_read(void *ctx, const void *reg_buf, size_t reg_len,
 	struct qca8k_priv *priv = ctx;
 	u32 reg = *(u16 *)reg_buf;
 
-	if (priv->mgmt_conduit &&
+	if (!qca8k_private_mgmt_blocked(priv) && priv->mgmt_conduit &&
 	    !qca8k_read_eth(priv, reg, val_buf, val_len))
 		return 0;
 
@@ -536,7 +545,7 @@ qca8k_bulk_gather_write(void *ctx, const void *reg_buf, size_t reg_len,
 	u32 reg = *(u16 *)reg_buf;
 	u32 *val = (u32 *)val_buf;
 
-	if (priv->mgmt_conduit &&
+	if (!qca8k_private_mgmt_blocked(priv) && priv->mgmt_conduit &&
 	    !qca8k_write_eth(priv, reg, val, val_len))
 		return 0;
 
@@ -564,7 +573,8 @@ qca8k_regmap_update_bits(void *ctx, uint32_t reg, uint32_t mask, uint32_t write_
 {
 	struct qca8k_priv *priv = ctx;
 
-	if (!qca8k_regmap_update_bits_eth(priv, reg, mask, write_val))
+	if (!qca8k_private_mgmt_blocked(priv) &&
+	    !qca8k_regmap_update_bits_eth(priv, reg, mask, write_val))
 		return 0;
 
 	return qca8k_regmap_update_bits_mii(priv, reg, mask, write_val);
@@ -635,6 +645,9 @@ qca8k_phy_eth_command(struct qca8k_priv *priv, bool read, int phy,
 	int ret, ret1;
 	bool ack;
 
+	if (qca8k_private_mgmt_blocked(priv))
+		return -EOPNOTSUPP;
+
 	if (regnum >= QCA8K_MDIO_MASTER_MAX_REG)
 		return -EINVAL;
 
@@ -690,7 +703,7 @@ qca8k_phy_eth_command(struct qca8k_priv *priv, bool read, int phy,
 
 	/* Check if mgmt_conduit is operational */
 	mgmt_conduit = priv->mgmt_conduit;
-	if (!mgmt_conduit) {
+	if (qca8k_private_mgmt_blocked(priv) || !mgmt_conduit) {
 		mutex_unlock(&mgmt_eth_data->mutex);
 		mutex_unlock(&priv->bus->mdio_lock);
 		ret = -EINVAL;
@@ -1465,6 +1478,12 @@ qca8k_phylink_mac_link_up(struct phylink_config *config,
 	int port = dp->index;
 	u32 reg;
 
+#if IS_ENABLED(CONFIG_NET_DSA_QCA8K_4B_MODE)
+	if (!READ_ONCE(priv->persistent_boot.requested) &&
+	    READ_ONCE(priv->private_open_blocked))
+		return;
+#endif
+
 	if (phylink_autoneg_inband(mode)) {
 		reg = QCA8K_PORT_STATUS_LINK_AUTO;
 	} else {
@@ -1494,6 +1513,12 @@ qca8k_phylink_mac_link_up(struct phylink_config *config,
 	}
 
 	reg |= QCA8K_PORT_STATUS_TXMAC | QCA8K_PORT_STATUS_RXMAC;
+#if IS_ENABLED(CONFIG_NET_DSA_QCA8K_4B_MODE)
+	if (qca8k_persistent_link_up(priv, port, reg))
+		return;
+	if (READ_ONCE(priv->private_open_blocked))
+		return;
+#endif
 
 	qca8k_write(priv, QCA8K_REG_PORT_STATUS(port), reg);
 }
@@ -1673,6 +1698,9 @@ static void qca8k_mib_autocast_handler(struct dsa_switch *ds, struct sk_buff *sk
 	u8 port;
 	int i;
 
+	if (qca8k_private_mgmt_blocked(priv))
+		return;
+
 	mib_ethhdr = (struct mib_ethhdr *)skb_mac_header(skb);
 	mib_eth_data = &priv->mib_eth_data;
 
@@ -1720,6 +1748,10 @@ qca8k_get_ethtool_stats_eth(struct dsa_switch *ds, int port, u64 *data)
 	mib_eth_data = &priv->mib_eth_data;
 
 	mutex_lock(&mib_eth_data->mutex);
+	if (qca8k_private_mgmt_blocked(priv)) {
+		mutex_unlock(&mib_eth_data->mutex);
+		return -EOPNOTSUPP;
+	}
 
 	reinit_completion(&mib_eth_data->rw_done);
 
@@ -1768,6 +1800,9 @@ static enum dsa_tag_protocol
 qca8k_get_tag_protocol(struct dsa_switch *ds, int port,
 		       enum dsa_tag_protocol mp)
 {
+	if (IS_ENABLED(CONFIG_NET_DSA_QCA8K_4B_MODE))
+		return READ_ONCE(
+			((struct qca8k_priv *)ds->priv)->private_tag_protocol);
 	return DSA_TAG_PROTO_QCA;
 }
 
@@ -1782,6 +1817,18 @@ qca8k_conduit_change(struct dsa_switch *ds, const struct net_device *conduit,
 	if (dp->index != 0)
 		return;
 
+	if (IS_ENABLED(CONFIG_NET_DSA_QCA8K_4B_MODE)) {
+		mutex_lock(&priv->mib_eth_data.mutex);
+		mutex_lock(&priv->mgmt_eth_data.mutex);
+		priv->mgmt_conduit =
+			operational && !qca8k_private_mgmt_blocked(priv) ?
+				(struct net_device *)conduit :
+				NULL;
+		mutex_unlock(&priv->mgmt_eth_data.mutex);
+		mutex_unlock(&priv->mib_eth_data.mutex);
+		return;
+	}
+
 	mutex_lock(&priv->mgmt_eth_data.mutex);
 	mutex_lock(&priv->mib_eth_data.mutex);
 
@@ -1804,6 +1851,14 @@ static int qca8k_connect_tag_protocol(struct dsa_switch *ds,
 		tagger_data->mib_autocast_handler = qca8k_mib_autocast_handler;
 
 		break;
+	case DSA_TAG_PROTO_QCA4:
+		if (!IS_ENABLED(CONFIG_NET_DSA_QCA8K_4B_MODE) ||
+		    ((struct qca8k_priv *)ds->priv)->private_tag_protocol !=
+			    DSA_TAG_PROTO_QCA4)
+			return -EOPNOTSUPP;
+		/* No tagger_data allocation/legacy14-byte callbacks for private4. */
+		break;
+
 	default:
 		return -EOPNOTSUPP;
 	}
@@ -1851,8 +1906,11 @@ static void qca8k_setup_hol_fixup(struct qca8k_priv *priv, int port)
 			   mask);
 }
 
-static int
-qca8k_setup(struct dsa_switch *ds)
+#if !IS_ENABLED(CONFIG_NET_DSA_QCA8K_4B_MODE)
+#define qca8k_setup_native qca8k_setup
+#endif
+
+static int qca8k_setup_native(struct dsa_switch *ds)
 {
 	struct qca8k_priv *priv = ds->priv;
 	struct dsa_port *dp;
@@ -2023,6 +2081,10 @@ qca8k_setup(struct dsa_switch *ds)
 	return 0;
 }
 
+#if IS_ENABLED(CONFIG_NET_DSA_QCA8K_4B_MODE)
+#include "qca8k-persistent-boot.inc"
+#endif
+
 static const struct phylink_mac_ops qca8k_phylink_mac_ops = {
 	.mac_select_pcs	= qca8k_phylink_mac_select_pcs,
 	.mac_config	= qca8k_phylink_mac_config,
@@ -2032,6 +2094,9 @@ static const struct phylink_mac_ops qca8k_phylink_mac_ops = {
 
 static const struct dsa_switch_ops qca8k_switch_ops = {
 	.get_tag_protocol	= qca8k_get_tag_protocol,
+#if IS_ENABLED(CONFIG_NET_DSA_QCA8K_4B_MODE)
+	.teardown		= qca8k_persistent_dsa_teardown,
+#endif
 	.setup			= qca8k_setup,
 	.get_strings		= qca8k_get_strings,
 	.get_ethtool_stats	= qca8k_get_ethtool_stats,
@@ -2080,6 +2145,7 @@ qca8k_sw_probe(struct mdio_device *mdiodev)
 	if (!priv)
 		return -ENOMEM;
 
+	priv->private_tag_protocol = DSA_TAG_PROTO_QCA;
 	priv->bus = mdiodev->bus;
 	priv->dev = &mdiodev->dev;
 	priv->info = of_device_get_match_data(priv->dev);
@@ -2130,7 +2196,17 @@ qca8k_sw_probe(struct mdio_device *mdiodev)
 	mutex_init(&priv->reg_mutex);
 	dev_set_drvdata(&mdiodev->dev, priv);
 
-	return dsa_register_switch(priv->ds);
+#if IS_ENABLED(CONFIG_NET_DSA_QCA8K_4B_MODE)
+	mutex_init(&priv->persistent_lock);
+	ret = qca8k_persistent_boot_admit(priv);
+	if (ret)
+		return ret;
+#endif
+	ret = dsa_register_switch(priv->ds);
+#if IS_ENABLED(CONFIG_NET_DSA_QCA8K_4B_MODE)
+	qca8k_persistent_register_complete(priv, ret);
+#endif
+	return ret;
 }
 
 static void
@@ -2142,6 +2218,13 @@ qca8k_sw_remove(struct mdio_device *mdiodev)
 	if (!priv)
 		return;
 
+#if IS_ENABLED(CONFIG_NET_DSA_QCA8K_4B_MODE)
+	if (priv->persistent_boot.requested) {
+		qca8k_persistent_remove(priv);
+		return;
+	}
+#endif
+
 	for (i = 0; i < QCA8K_NUM_PORTS; i++)
 		qca8k_port_set_status(priv, i, 0);
 
@@ -2155,6 +2238,14 @@ static void qca8k_sw_shutdown(struct mdio_device *mdiodev)
 	if (!priv)
 		return;
 
+#if IS_ENABLED(CONFIG_NET_DSA_QCA8K_4B_MODE)
+	if (priv->persistent_boot.requested) {
+		qca8k_persistent_shutdown(priv);
+		dev_set_drvdata(&mdiodev->dev, NULL);
+		return;
+	}
+#endif
+
 	dsa_switch_shutdown(priv->ds);
 
 	dev_set_drvdata(&mdiodev->dev, NULL);
@@ -2181,6 +2272,11 @@ static int qca8k_suspend(struct device *dev)
 {
 	struct qca8k_priv *priv = dev_get_drvdata(dev);
 
+	if (IS_ENABLED(CONFIG_NET_DSA_QCA8K_4B_MODE) &&
+	    (READ_ONCE(priv->private_open_blocked) ||
+	     priv->private_tag_protocol == DSA_TAG_PROTO_QCA4))
+		return -EBUSY;
+
 	qca8k_set_pm(priv, 0);
 
 	return dsa_switch_suspend(priv->ds);
@@ -2190,10 +2286,16 @@ static int qca8k_resume(struct device *dev)
 {
 	struct qca8k_priv *priv = dev_get_drvdata(dev);
 
+	if (IS_ENABLED(CONFIG_NET_DSA_QCA8K_4B_MODE) &&
+	    (READ_ONCE(priv->private_open_blocked) ||
+	     priv->private_tag_protocol == DSA_TAG_PROTO_QCA4))
+		return -EBUSY;
+
 	qca8k_set_pm(priv, 1);
 
 	return dsa_switch_resume(priv->ds);
 }
+
 #endif /* CONFIG_PM_SLEEP */
 
 static SIMPLE_DEV_PM_OPS(qca8k_pm_ops,
@@ -2236,6 +2338,9 @@ static struct mdio_driver qca8kmdio_driver = {
 	.shutdown = qca8k_sw_shutdown,
 	.mdiodrv.driver = {
 		.name = "qca8k",
+#if IS_ENABLED(CONFIG_NET_DSA_QCA8K_4B_MODE)
+		.suppress_bind_attrs = true,
+#endif
 		.of_match_table = qca8k_of_match,
 		.pm = &qca8k_pm_ops,
 	},
diff --git a/drivers/net/dsa/qca/qca8k-common.c b/drivers/net/dsa/qca/qca8k-common.c
index ab978cc83..2f690593e 100644
--- a/drivers/net/dsa/qca/qca8k-common.c
+++ b/drivers/net/dsa/qca/qca8k-common.c
@@ -467,6 +467,15 @@ void qca8k_port_set_status(struct qca8k_priv *priv, int port, int enable)
 {
 	u32 mask = QCA8K_PORT_STATUS_TXMAC | QCA8K_PORT_STATUS_RXMAC;
 
+#if IS_ENABLED(CONFIG_NET_DSA_QCA8K_4B_MODE)
+	if (qca8k_persistent_port_status(priv, port, enable))
+		return;
+#endif
+
+	if (enable && IS_ENABLED(CONFIG_NET_DSA_QCA8K_4B_MODE) &&
+	    READ_ONCE(priv->private_open_blocked))
+		return;
+
 	/* Port 0 and 6 have no internal PHY */
 	if (port > 0 && port < 6)
 		mask |= QCA8K_PORT_STATUS_LINK_AUTO;
@@ -496,7 +505,8 @@ void qca8k_get_ethtool_stats(struct dsa_switch *ds, int port,
 	u32 hi = 0;
 	int ret;
 
-	if (priv->mgmt_conduit && priv->info->ops->autocast_mib &&
+	if (!qca8k_private_mgmt_blocked(priv) && priv->mgmt_conduit &&
+	    priv->info->ops->autocast_mib &&
 	    priv->info->ops->autocast_mib(ds, port, data) > 0)
 		return;
 
@@ -741,6 +751,31 @@ int qca8k_port_enable(struct dsa_switch *ds, int port,
 		      struct phy_device *phy)
 {
 	struct qca8k_priv *priv = ds->priv;
+#if IS_ENABLED(CONFIG_NET_DSA_QCA8K_4B_MODE)
+	int ret;
+
+	if (READ_ONCE(priv->persistent_boot.requested) &&
+	    dsa_is_cpu_port(ds, port)) {
+		mutex_lock(&priv->persistent_lock);
+		if (!priv->persistent_boot.ready) {
+			priv->persistent_cpu_requested |= BIT(port);
+			priv->port_enabled_map |= BIT(port);
+			mutex_unlock(&priv->persistent_lock);
+			return 0;
+		}
+		mutex_unlock(&priv->persistent_lock);
+	}
+	if (dsa_is_user_port(ds, port)) {
+		ret = qca8k_persistent_first_user(priv);
+		if (ret)
+			return ret;
+	}
+
+#endif
+
+	if (IS_ENABLED(CONFIG_NET_DSA_QCA8K_4B_MODE) &&
+	    READ_ONCE(priv->private_open_blocked))
+		return -EIO;
 
 	qca8k_port_set_status(priv, port, 1);
 	priv->port_enabled_map |= BIT(port);
@@ -764,6 +799,11 @@ int qca8k_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
 	struct qca8k_priv *priv = ds->priv;
 	int ret;
 
+#if IS_ENABLED(CONFIG_NET_DSA_QCA8K_4B_MODE)
+	if (READ_ONCE(priv->persistent_boot.requested))
+		return qca8k_persistent_change_mtu(priv, port, new_mtu);
+#endif
+
 	/* We have only have a general MTU setting.
 	 * DSA always set the CPU port's MTU to the largest MTU of the user
 	 * ports.
diff --git a/drivers/net/dsa/qca/qca8k-persistent-boot.inc b/drivers/net/dsa/qca/qca8k-persistent-boot.inc
new file mode 100644
index 000000000..88638bb53
--- /dev/null
+++ b/drivers/net/dsa/qca/qca8k-persistent-boot.inc
@@ -0,0 +1,632 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#include <linux/cs7542_ft_live.h>
+#include <net/net_namespace.h>
+#define QCA4_PRIVATE_MAC_MASK \
+	(QCA8K_PORT_STATUS_TXMAC | QCA8K_PORT_STATUS_RXMAC)
+static void qca8k_private4_block_management(void *context)
+{
+	struct qca8k_priv *priv = context;
+
+	if (priv->private_management_drained)
+		return;
+	WRITE_ONCE(priv->private_mgmt_blocked, true);
+	mutex_lock(&priv->mib_eth_data.mutex);
+	mutex_lock_nested(&priv->bus->mdio_lock, MDIO_MUTEX_NESTED);
+	mutex_lock(&priv->mgmt_eth_data.mutex);
+	priv->mgmt_conduit = NULL;
+	mutex_unlock(&priv->mgmt_eth_data.mutex);
+	mutex_unlock(&priv->bus->mdio_lock);
+	mutex_unlock(&priv->mib_eth_data.mutex);
+	synchronize_net();
+	priv->private_management_drained = true;
+}
+
+static void qca8k_private4_close_links(struct qca8k_priv *priv)
+{
+	struct dsa_port *dp;
+
+	ASSERT_RTNL();
+	dsa_switch_for_each_user_port(dp, priv->ds)
+		if (dp->user && dp->user->flags & IFF_UP)
+			dev_close(dp->user);
+	dsa_switch_for_each_cpu_port(dp, priv->ds)
+		if (dp->conduit && dp->conduit->flags & IFF_UP)
+			dev_close(dp->conduit);
+	synchronize_net();
+}
+
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Private opt-in boot adapter; default profile remains native QCA2. */
+#include <linux/dsa/qca8k_persistent.h>
+static int qca8k_persistent_software_ready(struct qca8k_priv *priv,
+					   bool bootstrap)
+{
+	struct dsa_switch *ds = priv->ds;
+	struct dsa_port *cpu, *user;
+	unsigned int needed_mtu = ETH_DATA_LEN;
+	unsigned int cpu_mask = 0;
+
+	ASSERT_RTNL();
+	if (!ds->dst->setup || !ds->dst->tag_ops ||
+	    ds->dst->tag_ops->proto != DSA_TAG_PROTO_QCA4)
+		return -EAGAIN;
+	dsa_switch_for_each_user_port(user, ds) {
+		if (!user->user)
+			return -ENODEV;
+		if (!bootstrap)
+			needed_mtu = max_t(unsigned int, needed_mtu,
+					   user->user->mtu);
+	}
+	dsa_switch_for_each_cpu_port(cpu, ds) {
+		if (cpu->index != 0 && cpu->index != 6)
+			return -EOPNOTSUPP;
+		cpu_mask |= BIT(cpu->index);
+		if (!cpu->conduit || cpu->conduit->dsa_ptr != cpu ||
+		    !cpu->tag_ops ||
+		    cpu->tag_ops->proto != DSA_TAG_PROTO_QCA4 ||
+		    cpu->rcv != cpu->tag_ops->rcv)
+			return -EUCLEAN;
+		/*
+		 * dsa_conduit_setup() can swallow dev_set_mtu() failure. Check
+		 * the actual effective MTU on BOTH configured conduits instead.
+		 */
+		if (cpu->conduit->mtu < needed_mtu +
+						cpu->tag_ops->needed_headroom +
+						cpu->tag_ops->needed_tailroom)
+			return -EMSGSIZE;
+	}
+	return cpu_mask == (BIT(0) | BIT(6)) ? 0 : -ENODEV;
+}
+
+/*
+ * Replay only CPU enables recorded during setup, never arbitrary user MACs.
+ * A failed replay closes the format again; its first errno remains sticky.
+ */
+static int qca8k_persistent_replay_cpus(struct qca8k_priv *priv)
+{
+	unsigned int port;
+	u32 actual;
+	u32 mask = QCA8K_PORT_STATUS_SPEED | QCA4_PRIVATE_MAC_MASK |
+		   QCA8K_PORT_STATUS_TXFLOW | QCA8K_PORT_STATUS_RXFLOW |
+		   QCA8K_PORT_STATUS_DUPLEX | QCA8K_PORT_STATUS_LINK_AUTO;
+	int ret;
+
+	if (priv->persistent_status_valid != (BIT(0) | BIT(6)))
+		return -EAGAIN;
+
+	for (port = 0; port <= 6; port += 6) {
+		u32 wanted = priv->persistent_status[port == 6];
+
+		if (!(priv->persistent_cpu_requested & BIT(port)))
+			wanted &= ~QCA4_PRIVATE_MAC_MASK;
+
+		ret = qca8k_rmw(priv, QCA8K_REG_PORT_STATUS(port), mask,
+				wanted);
+		if (ret)
+			return ret;
+		ret = qca8k_read_mii(priv, QCA8K_REG_PORT_STATUS(port),
+				     &actual);
+		if (ret)
+			return ret;
+		if ((actual & mask) != (wanted & mask))
+			return -EIO;
+	}
+	return 0;
+}
+
+static int qca8k_persistent_stop_cpus(struct qca8k_priv *priv)
+{
+	unsigned int port;
+	u32 actual;
+	int first = 0, ret;
+
+	for (port = 0; port <= 6; port += 6) {
+		ret = qca8k_rmw(priv, QCA8K_REG_PORT_STATUS(port),
+				QCA4_PRIVATE_MAC_MASK, 0);
+		if (ret && !first)
+			first = ret;
+		ret = qca8k_read_mii(priv, QCA8K_REG_PORT_STATUS(port),
+				     &actual);
+		if (!ret && (actual & QCA4_PRIVATE_MAC_MASK))
+			ret = -EIO;
+		if (ret && !first)
+			first = ret;
+	}
+	return first;
+}
+
+static int qca8k_persistent_mtu_read(void *context,
+				     enum qca4_persistent_mtu_field field,
+				     qca4_word *value)
+{
+	struct qca8k_priv *priv = context;
+	unsigned int port =
+		field == QCA4_PMTU_CONDUIT6 || field == QCA4_PMTU_MAC6 ? 6 : 0;
+	struct dsa_port *cpu = dsa_to_port(priv->ds, port);
+	u32 reg;
+	int ret;
+
+	if (field <= QCA4_PMTU_CONDUIT6) {
+		if (!cpu || !cpu->conduit)
+			return -ENODEV;
+		*value = cpu->conduit->mtu;
+		return 0;
+	}
+	reg = field == QCA4_PMTU_FRAME ? QCA8K_MAX_FRAME_SIZE :
+					 QCA8K_REG_PORT_STATUS(port);
+	ret = qca8k_read_mii(priv, reg, value);
+	if (!ret && field >= QCA4_PMTU_MAC0)
+		*value &= QCA4_PRIVATE_MAC_MASK;
+	return ret;
+}
+
+static int qca8k_persistent_mtu_write(void *context,
+				      enum qca4_persistent_mtu_field field,
+				      qca4_word value, bool restore,
+				      bool *verified)
+{
+	struct qca8k_priv *priv = context;
+	unsigned int port =
+		field == QCA4_PMTU_CONDUIT6 || field == QCA4_PMTU_MAC6 ? 6 : 0;
+	struct dsa_port *cpu = dsa_to_port(priv->ds, port);
+	u32 actual = 0, mask, reg;
+	int ret, checked;
+
+	ASSERT_RTNL();
+	lockdep_assert_held(&priv->persistent_lock);
+	(void)restore; /* Persistent operations use native bounded MDIO in both directions. */
+	*verified = false;
+	if (!priv->private_mgmt_blocked)
+		return -EPERM;
+	if (field <= QCA4_PMTU_CONDUIT6) {
+		if (!cpu || !cpu->conduit)
+			return -ENODEV;
+		/*
+		 * Correct netdevice API, including actual notifier/MTU limits. No
+		 * phylink stop occurs here. Callbacks share persistent_lock.
+		 */
+		ret = dev_set_mtu(cpu->conduit, value);
+		*verified = cpu->conduit->mtu == value;
+		return ret ? ret : *verified ? 0 : -EIO;
+	}
+	reg = field == QCA4_PMTU_FRAME ? QCA8K_MAX_FRAME_SIZE :
+					 QCA8K_REG_PORT_STATUS(port);
+	mask = field == QCA4_PMTU_FRAME ? ~0U : QCA4_PRIVATE_MAC_MASK;
+	/*
+	 * Persistent operation has no fabricated bounded-owner deadline. The
+	 * native MDIO driver bounds each actual low/high bus transaction.
+	 * Rollback uses the same checked owner, preserving the original errno.
+	 */
+	ret = qca8k_rmw(priv, reg, mask, value);
+	checked = qca8k_read_mii(priv, reg, &actual);
+	*verified = !checked && !((actual ^ value) & mask);
+	return ret ? ret : checked ? checked : *verified ? 0 : -EIO;
+}
+
+static struct qca4_persistent_mtu_ops
+qca8k_persistent_mtu_ops(struct qca8k_priv *priv)
+{
+	return (struct qca4_persistent_mtu_ops){
+		.context = priv,
+		.read = qca8k_persistent_mtu_read,
+		.write = qca8k_persistent_mtu_write,
+	};
+}
+
+/*
+ * Core has already changed one conduit before its CPU callback. Apply the
+ * passed aggregate there, then independently validate the user callback using
+ * its proposed MTU. A repeated already-verified pair is idempotent. Setup can
+ * ignore CPU callback errors: first-open readiness remains the traffic gate.
+ */
+static int qca8k_persistent_change_mtu_locked(struct qca8k_priv *priv, int port,
+					      int mtu)
+{
+	struct qca4_persistent_mtu_ops ops = qca8k_persistent_mtu_ops(priv);
+	struct dsa_port *user;
+	unsigned int largest = ETH_DATA_LEN;
+	bool blocked;
+	int ret = 0;
+
+	ASSERT_RTNL();
+	if (!dsa_is_user_port(priv->ds, port) &&
+	    !dsa_is_cpu_port(priv->ds, port))
+		return -EOPNOTSUPP;
+	if (mtu <= 0 || mtu > QCA8K_MAX_MTU)
+		return -EINVAL;
+	lockdep_assert_held(&priv->persistent_lock);
+	if (priv->persistent_closing || priv->persistent_boot.first_error ||
+	    priv->persistent_mtu.pending || priv->persistent_mtu.unknown) {
+		ret = -EUCLEAN;
+		goto unlock;
+	}
+	/*
+	 * Early DSA allocation has not yet published both conduits. First-open
+	 * readiness performs the initial checked transaction before MAC replay.
+	 */
+	if (!priv->persistent_boot.ready)
+		goto unlock;
+	if (dsa_is_cpu_port(priv->ds, port)) {
+		largest = max_t(unsigned int, largest, mtu);
+	} else {
+		dsa_switch_for_each_user_port(user, priv->ds) {
+			if (user->user)
+				largest = max_t(unsigned int, largest,
+					user->index == (unsigned int)port ?
+						(unsigned int)mtu :
+						user->user->mtu);
+		}
+	}
+	if (priv->persistent_mtu.committed_valid &&
+	    priv->persistent_mtu.committed_mtu[0] == largest + 4 &&
+	    priv->persistent_mtu.committed_mtu[1] == largest + 4 &&
+	    priv->persistent_mtu.committed_frame ==
+		    largest + ETH_HLEN + ETH_FCS_LEN &&
+	    dsa_to_port(priv->ds, 0)->conduit->mtu == largest + 4 &&
+	    dsa_to_port(priv->ds, 6)->conduit->mtu == largest + 4)
+		goto unlock;
+	blocked = priv->private_open_blocked;
+	priv->private_open_blocked = true;
+	ret = qca4_pmtu_change(&priv->persistent_mtu, &ops, largest + 4,
+			       largest + ETH_HLEN + ETH_FCS_LEN);
+	if (ret) {
+		qca4_persistent_error(&priv->persistent_boot, ret);
+		priv->persistent_boot.ready = false;
+		if (qca8k_persistent_stop_cpus(priv))
+			priv->persistent_boot.unknown = true;
+	} else {
+		priv->private_open_blocked = blocked;
+	}
+unlock:
+	return ret;
+}
+
+int qca8k_persistent_change_mtu(struct qca8k_priv *priv, int port, int mtu)
+{
+	int ret;
+
+	ASSERT_RTNL();
+	mutex_lock(&priv->persistent_lock);
+	ret = qca8k_persistent_change_mtu_locked(priv, port, mtu);
+	mutex_unlock(&priv->persistent_lock);
+	return ret;
+}
+
+static int qca8k_persistent_first_user_locked(struct qca8k_priv *priv)
+{
+	unsigned int port;
+	u32 value;
+	int ret;
+
+	if (!priv->persistent_boot.requested)
+		return 0;
+	ASSERT_RTNL();
+	if (priv->persistent_closing || !priv->persistent_boot.hardware4 ||
+	    priv->persistent_boot.unknown || priv->persistent_boot.first_error)
+		return -EIO;
+	ret = qca8k_persistent_software_ready(priv, !priv->persistent_mtu.committed_valid);
+	/*
+	 * A netdev can be published before the complete DSA tree. This is a
+	 * pre-I/O readiness refusal, not an I/O fault or a permanent latch.
+	 */
+	if (ret == -EAGAIN)
+		return ret;
+	if (ret)
+		goto failed;
+	if (priv->persistent_status_valid != (BIT(0) | BIT(6)))
+		return -EAGAIN;
+	ret = qca8k_read_mii(priv, QCA8K_REG_GLOBAL_HDR_CTRL, &value);
+	if (!ret && (value & QCA4_PERSISTENT_MASK) != QCA4_PERSISTENT_VALUE)
+		ret = -EUCLEAN;
+	for (port = 0; !ret && port <= 6; port += 6) {
+		ret = qca8k_read_mii(priv, QCA8K_REG_PORT_HDR_CTRL(port),
+				     &value);
+		if (!ret && value != QCA4_PERSISTENT_CPU_HEADER)
+			ret = -EUCLEAN;
+	}
+	if (!ret && !priv->persistent_mtu.committed_valid) {
+		struct qca4_persistent_mtu_ops ops =
+			qca8k_persistent_mtu_ops(priv);
+		struct dsa_port *user;
+		unsigned int largest = ETH_DATA_LEN;
+
+		dsa_switch_for_each_user_port(user, priv->ds)
+			if (user->user)
+				largest = max_t(unsigned int, largest,
+						user->user->mtu);
+		ret = qca4_pmtu_change(&priv->persistent_mtu, &ops, largest + 4,
+				       largest + ETH_HLEN + ETH_FCS_LEN);
+	}
+	if (!ret)
+		ret = qca8k_persistent_software_ready(priv, false);
+	if (!ret)
+		ret = qca8k_persistent_replay_cpus(priv);
+	if (ret)
+		goto failed;
+	if (priv->persistent_fe_held) {
+		ret = cs7542_ft_live_format_release();
+		if (ret)
+			goto failed;
+		priv->persistent_fe_held = false;
+	}
+	priv->persistent_boot.ready = true;
+	WRITE_ONCE(priv->private_open_blocked, false);
+	return 0;
+failed:
+	WRITE_ONCE(priv->private_open_blocked, true);
+	priv->persistent_boot.ready = false;
+	qca4_persistent_error(&priv->persistent_boot, ret);
+	if (qca8k_persistent_stop_cpus(priv))
+		priv->persistent_boot.unknown = true;
+	/* No detach or mode clear here. Incomplete boot admission is closed. */
+	return ret;
+}
+
+/*
+ * Lock order: RTNL (when present), phylink's own state locks (when present),
+ * persistent_lock, native MDIO. Never call phylink_stop/dev_close while holding
+ * persistent_lock: those paths wait for resolve work that takes this mutex.
+ */
+int qca8k_persistent_first_user(struct qca8k_priv *priv)
+{
+	int ret;
+
+	if (!READ_ONCE(priv->persistent_boot.requested))
+		return 0;
+	mutex_lock(&priv->persistent_lock);
+	ret = qca8k_persistent_first_user_locked(priv);
+	mutex_unlock(&priv->persistent_lock);
+	return ret;
+}
+
+bool qca8k_persistent_link_up(struct qca8k_priv *priv, int port, u32 status)
+{
+	int ret;
+	u32 actual;
+	u32 mask = QCA8K_PORT_STATUS_SPEED | QCA4_PRIVATE_MAC_MASK |
+		   QCA8K_PORT_STATUS_TXFLOW | QCA8K_PORT_STATUS_RXFLOW |
+		   QCA8K_PORT_STATUS_DUPLEX | QCA8K_PORT_STATUS_LINK_AUTO;
+
+	if (!READ_ONCE(priv->persistent_boot.requested))
+		return false;
+	mutex_lock(&priv->persistent_lock);
+	if (port == 0 || port == 6) {
+		priv->persistent_status[port == 6] = status;
+		priv->persistent_status_valid |= BIT(port);
+		priv->persistent_cpu_requested |= BIT(port);
+	}
+	if (!priv->private_open_blocked) {
+		ret = qca8k_write(priv, QCA8K_REG_PORT_STATUS(port), status);
+		if (!ret)
+			ret = qca8k_read_mii(priv, QCA8K_REG_PORT_STATUS(port),
+					     &actual);
+		if (!ret && ((actual ^ status) & mask))
+			ret = -EIO;
+		if (ret) {
+			priv->private_open_blocked = true;
+			priv->persistent_boot.ready = false;
+			qca4_persistent_error(&priv->persistent_boot, ret);
+			if (qca8k_persistent_stop_cpus(priv))
+				priv->persistent_boot.unknown = true;
+		}
+	}
+	mutex_unlock(&priv->persistent_lock);
+	return true;
+}
+
+bool qca8k_persistent_port_status(struct qca8k_priv *priv, int port,
+				  bool enable)
+{
+	u32 mask = QCA4_PRIVATE_MAC_MASK, verify_mask, actual;
+	int ret;
+
+	if (!READ_ONCE(priv->persistent_boot.requested))
+		return false;
+	mutex_lock(&priv->persistent_lock);
+	if (port == 0 || port == 6) {
+		if (enable)
+			priv->persistent_cpu_requested |= BIT(port);
+		else
+			priv->persistent_cpu_requested &= ~BIT(port);
+	} else {
+		mask |= QCA8K_PORT_STATUS_LINK_AUTO;
+	}
+	if (enable && priv->private_open_blocked)
+		goto unlock;
+	/*
+	 * With user-port auto negotiation, hardware can keep the MAC bits
+	 * clear until link-up. Check the requested auto mode here; the actual
+	 * phylink link-up callback still verifies the complete MAC status.
+	 * Disables and both CPU ports retain the exact MAC-bit check.
+	 */
+	verify_mask = enable && port > 0 && port < 6 ?
+			      QCA8K_PORT_STATUS_LINK_AUTO :
+			      mask;
+	ret = qca8k_rmw(priv, QCA8K_REG_PORT_STATUS(port), mask,
+			enable ? mask : 0);
+	if (!ret)
+		ret = qca8k_read_mii(priv, QCA8K_REG_PORT_STATUS(port),
+				     &actual);
+	if (!ret && (actual & verify_mask) != (enable ? verify_mask : 0))
+		ret = -EIO;
+	if (ret) {
+		priv->private_open_blocked = true;
+		priv->persistent_boot.ready = false;
+		qca4_persistent_error(&priv->persistent_boot, ret);
+		if (qca8k_persistent_stop_cpus(priv))
+			priv->persistent_boot.unknown = true;
+	}
+unlock:
+	mutex_unlock(&priv->persistent_lock);
+	return true;
+}
+
+/*
+ * int-returning preparation only. It is NOT a void MDIO remove veto. The
+ * boot property remains inadmissible until unknown cleanup can prevent driver
+ * core devres release in every reachable detach/unwind path.
+ */
+static int qca8k_persistent_stop_all(struct qca8k_priv *priv,
+				     bool *verified_all)
+{
+	unsigned int port;
+	u32 actual, mask;
+	int ret, checked, first = 0;
+
+	*verified_all = true;
+	for (port = 0; port < QCA8K_NUM_PORTS; port++) {
+		mask = QCA4_PRIVATE_MAC_MASK;
+		if (port > 0 && port < 6)
+			mask |= QCA8K_PORT_STATUS_LINK_AUTO;
+		ret = qca8k_rmw(priv, QCA8K_REG_PORT_STATUS(port), mask, 0);
+		checked = qca8k_read_mii(priv, QCA8K_REG_PORT_STATUS(port),
+					 &actual);
+		if (checked || (actual & mask))
+			*verified_all = false;
+		if (!ret)
+			ret = checked ? checked : (actual & mask) ? -EIO : 0;
+		if (ret && !first)
+			first = ret;
+	}
+	return first;
+}
+
+static int qca8k_persistent_restore_global(struct qca8k_priv *priv)
+{
+	u32 before, actual, expected;
+	int ret, checked;
+
+	if (!priv->persistent_boot.saved_valid)
+		return -EUCLEAN;
+	ret = qca8k_read_mii(priv, QCA8K_REG_GLOBAL_HDR_CTRL, &before);
+	if (ret)
+		return ret;
+	expected = (before & ~QCA4_PERSISTENT_MASK) |
+		   (priv->persistent_boot.saved_header & QCA4_PERSISTENT_MASK);
+	ret = qca8k_rmw(priv, QCA8K_REG_GLOBAL_HDR_CTRL, QCA4_PERSISTENT_MASK,
+			expected);
+	checked = qca8k_read_mii(priv, QCA8K_REG_GLOBAL_HDR_CTRL, &actual);
+	priv->persistent_native2_verified = !checked && actual == expected &&
+					    !(actual & BIT(16));
+	if (priv->persistent_native2_verified) {
+		priv->persistent_boot.restore_pending = false;
+		priv->persistent_boot.hardware4 = false;
+	}
+	return ret				 ? ret :
+	       checked				 ? checked :
+	       priv->persistent_native2_verified ? 0 :
+						   -EIO;
+}
+
+static bool qca8k_persistent_can_release(struct qca8k_priv *priv)
+{
+	lockdep_assert_held(&priv->persistent_lock);
+	return priv->persistent_closing && priv->persistent_fe_held &&
+	       priv->private_open_blocked &&
+	       priv->persistent_stopped_verified &&
+	       priv->persistent_native2_verified &&
+	       !priv->persistent_boot.hardware4 &&
+	       !priv->persistent_boot.restore_pending &&
+	       !priv->persistent_boot.unknown &&
+	       !priv->persistent_mtu.pending && !priv->persistent_mtu.unknown;
+}
+
+static int __maybe_unused
+qca8k_persistent_prepare_detach(struct qca8k_priv *priv)
+{
+	struct qca4_persistent_mtu_ops ops = qca8k_persistent_mtu_ops(priv);
+	int ret, first = 0;
+
+	ASSERT_RTNL();
+	if (!priv->persistent_boot.requested)
+		return 0;
+	if (priv->persistent_cleanup_attempted)
+		return priv->persistent_cleanup_result;
+	priv->persistent_cleanup_attempted = true;
+	mutex_lock(&priv->persistent_lock);
+	priv->persistent_closing = true;
+	priv->private_open_blocked = true;
+	priv->persistent_boot.ready = false;
+	mutex_unlock(&priv->persistent_lock);
+	priv->persistent_fe_held = false;
+	ret = priv->persistent_hold_error ? priv->persistent_hold_error :
+					    cs7542_ft_live_format_hold();
+	if (ret)
+		first = ret;
+	else
+		priv->persistent_fe_held = true;
+	/*
+	 * No persistent_lock: dev_close/phylink_stop can join callbacks that
+	 * take it. Future callbacks remain unable to enable any MAC.
+	 */
+	qca8k_private4_close_links(priv);
+	qca8k_private4_block_management(priv);
+	mutex_lock(&priv->persistent_lock);
+	ret = qca8k_persistent_stop_all(priv,
+					&priv->persistent_stopped_verified);
+	if (ret && !first)
+		first = ret;
+	if (!priv->persistent_stopped_verified || !priv->persistent_fe_held)
+		goto unknown;
+	ret = qca4_pmtu_restore(&priv->persistent_mtu, &ops);
+	if (ret && !first)
+		first = ret;
+	if (priv->persistent_mtu.pending || priv->persistent_mtu.unknown)
+		goto unknown;
+	/*
+	 * MTU rollback may restore prior CPU enables; close/verify them again
+	 * before changing the global format or authorizing detach.
+	 */
+	ret = qca8k_persistent_stop_all(priv,
+					&priv->persistent_stopped_verified);
+	if (ret && !first)
+		first = ret;
+	if (!priv->persistent_stopped_verified)
+		goto unknown;
+	ret = qca8k_persistent_restore_global(priv);
+	if (ret && !first)
+		first = ret;
+	if (!priv->persistent_native2_verified)
+		goto unknown;
+	priv->persistent_boot.unknown = false;
+	if (qca8k_persistent_can_release(priv))
+		priv->private_tag_protocol = DSA_TAG_PROTO_QCA;
+	qca4_persistent_error(&priv->persistent_boot, first);
+	priv->persistent_cleanup_result = first;
+	mutex_unlock(&priv->persistent_lock);
+	return first; /* first I/O error and proved-release eligibility differ */
+unknown:
+	priv->persistent_boot.unknown = true;
+	qca4_persistent_error(&priv->persistent_boot, first ? first : -EIO);
+	priv->persistent_cleanup_result = first ? first : -EIO;
+	mutex_unlock(&priv->persistent_lock);
+	return priv->persistent_cleanup_result;
+}
+
+/*
+ * Only AFTER actual DSA teardown has drained/detached its callbacks. An I/O
+ * error in the history is still reported, but is not itself fabricated current
+ * uncertainty after independent complete readback proved restoration.
+ */
+static int __maybe_unused
+qca8k_persistent_detach_complete(struct qca8k_priv *priv)
+{
+	int ret;
+
+	ASSERT_RTNL();
+	mutex_lock(&priv->persistent_lock);
+	if (!qca8k_persistent_can_release(priv) || priv->ds->setup) {
+		mutex_unlock(&priv->persistent_lock);
+		return -EBUSY;
+	}
+	priv->private_tag_protocol = DSA_TAG_PROTO_QCA;
+	mutex_unlock(&priv->persistent_lock);
+	ret = cs7542_ft_live_format_release();
+	mutex_lock(&priv->persistent_lock);
+	if (!ret)
+		priv->persistent_fe_held = false;
+	mutex_unlock(&priv->persistent_lock);
+	return ret;
+}
+
+#include "qca8k-persistent-lifecycle.inc"
diff --git a/drivers/net/dsa/qca/qca8k-persistent-lifecycle.inc b/drivers/net/dsa/qca/qca8k-persistent-lifecycle.inc
new file mode 100644
index 000000000..bd7892b80
--- /dev/null
+++ b/drivers/net/dsa/qca/qca8k-persistent-lifecycle.inc
@@ -0,0 +1,394 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Private boot profile. All lifecycle entry points below execute under RTNL;
+ * the fault is only a scalar. No retired QCA/DSA pointer survives in FE hold.
+ */
+static int qca8k_persistent_last_fault;
+static u64 qca8k_persistent_generation;
+
+static int qca8k_persistent_profile(struct qca8k_priv *priv)
+{
+	struct dsa_port *cpu, *user;
+	struct net_device *conduits[2] = {};
+	unsigned int cpu_mask = 0, user_mask = 0;
+	phy_interface_t mode;
+	u32 reg;
+
+	ASSERT_RTNL();
+	if (priv->switch_id != QCA8K_ID_QCA8337 || !priv->ds->dst ||
+	    !priv->ds->dst->tag_ops ||
+	    priv->ds->dst->tag_ops->proto != DSA_TAG_PROTO_QCA4)
+		return -EOPNOTSUPP;
+	dsa_switch_for_each_cpu_port(cpu, priv->ds) {
+		struct device *parent;
+		unsigned int index = cpu->index == 6;
+
+		if ((cpu->index != 0 && cpu->index != 6) || !cpu->conduit ||
+		    !cpu->dn || !of_phy_is_fixed_link(cpu->dn) ||
+		    of_get_phy_mode(cpu->dn, &mode) ||
+		    !phy_interface_mode_is_rgmii(mode))
+			return -EOPNOTSUPP;
+		if (dev_net(cpu->conduit) != &init_net ||
+		    cpu->conduit->flags & IFF_UP)
+			return -EBUSY;
+		/*
+		 * The netdev's direct OF node is ethernet-port@N. Its device
+		 * parent is the shared NE and cannot identify GMAC0 versus GMAC1.
+		 */
+		if (of_property_read_u32(dev_of_node(&cpu->conduit->dev), "reg",
+					 &reg) ||
+		    reg != (cpu->index == 0 ? 1 : 0))
+			return -ENODEV;
+		parent = cpu->conduit->dev.parent;
+		if (!parent || !parent->driver || parent->driver->owner ||
+		    !of_device_is_compatible(dev_of_node(parent),
+					     "cortina,cs7542-ethernet"))
+			return -EOPNOTSUPP;
+		conduits[index] = cpu->conduit;
+		cpu_mask |= BIT(cpu->index);
+	}
+	dsa_switch_for_each_user_port(user, priv->ds) {
+		if (user->index < 1 || user->index > 5)
+			return -EOPNOTSUPP;
+		user_mask |= BIT(user->index);
+	}
+	if (cpu_mask != 0x41 || user_mask != 0x3e ||
+	    conduits[0] == conduits[1] ||
+	    conduits[0]->dev.parent != conduits[1]->dev.parent)
+		return -EOPNOTSUPP;
+	return 0;
+}
+
+static void qca8k_persistent_note_fault(struct qca8k_priv *priv, int error)
+{
+	ASSERT_RTNL();
+	if (!qca8k_persistent_last_fault)
+		qca8k_persistent_last_fault = error ? error : -EIO;
+	dev_err(priv->dev,
+		"persistent4 held fault=%d native2=%u stopped=%u; no reopen or cleanup success\n",
+		qca8k_persistent_last_fault, priv->persistent_native2_verified,
+		priv->persistent_stopped_verified);
+}
+
+static int qca8k_persistent_boot_start(struct qca8k_priv *priv)
+{
+	u32 global;
+	int ret;
+
+	ASSERT_RTNL();
+	ret = qca8k_persistent_profile(priv);
+	if (ret)
+		return ret; /* No actor closure or hardware I/O on failed admission. */
+	priv->persistent_setup_started = true;
+	ret = cs7542_ft_live_format_hold();
+	if (ret) {
+		priv->persistent_hold_error = ret;
+		return ret;
+	} /* format_blocked remains set, even on detach failure. */
+	priv->persistent_fe_held = true;
+	qca8k_private4_block_management(priv);
+	mutex_lock(&priv->persistent_lock);
+	ret = qca8k_persistent_stop_all(priv,
+					&priv->persistent_stopped_verified);
+	if (ret || !priv->persistent_stopped_verified)
+		goto unlock;
+	ret = qca8k_read_mii(priv, QCA8K_REG_GLOBAL_HDR_CTRL, &global);
+	if (ret)
+		goto unlock;
+	/* Recovery baseline is native2, not firmware's possibly retained4. */
+	priv->persistent_boot.saved_header = (global & QCA4_PERSISTENT_MASK) &
+					     ~BIT(16);
+	priv->persistent_boot.saved_valid = true;
+	priv->persistent_boot.restore_pending = true;
+	ret = qca8k_persistent_restore_global(priv);
+	if (!ret && priv->persistent_native2_verified)
+		qca8k_persistent_last_fault =
+			0; /* Actual proved native2 recovery. */
+unlock:
+	mutex_unlock(&priv->persistent_lock);
+	return ret ? ret : priv->persistent_stopped_verified ? 0 : -EIO;
+}
+
+static int qca8k_persistent_boot_hardware4(struct qca8k_priv *priv)
+{
+	u32 before, actual, expected, header;
+	unsigned int port;
+	int ret, checked;
+
+	ASSERT_RTNL();
+	ret = qca8k_persistent_profile(priv);
+	if (ret)
+		return ret;
+	mutex_lock(&priv->persistent_lock);
+	ret = qca8k_persistent_stop_all(priv,
+					&priv->persistent_stopped_verified);
+	if (ret || !priv->persistent_stopped_verified)
+		goto unlock;
+	for (port = 0; port <= 6; port += 6) {
+		ret = qca8k_read_mii(priv, QCA8K_REG_PORT_HDR_CTRL(port),
+				     &header);
+		if (!ret && header != QCA4_PERSISTENT_CPU_HEADER)
+			ret = -EUCLEAN;
+		if (ret)
+			goto unlock;
+	}
+	ret = qca8k_read_mii(priv, QCA8K_REG_GLOBAL_HDR_CTRL, &before);
+	if (ret)
+		goto unlock;
+	if (before & BIT(16)) {
+		ret = -EUCLEAN;
+		goto unlock;
+	}
+	if (qca8k_persistent_generation == ~0ULL) {
+		ret = -EOVERFLOW;
+		goto unlock;
+	}
+	priv->persistent_epoch = ++qca8k_persistent_generation;
+	expected = (before & ~QCA4_PERSISTENT_MASK) | QCA4_PERSISTENT_VALUE;
+	priv->persistent_boot.restore_pending =
+		true; /* Before either data word. */
+	priv->persistent_native2_verified = false;
+	ret = qca8k_rmw(priv, QCA8K_REG_GLOBAL_HDR_CTRL, QCA4_PERSISTENT_MASK,
+			expected);
+	checked = qca8k_read_mii(priv, QCA8K_REG_GLOBAL_HDR_CTRL, &actual);
+	priv->persistent_boot.hardware4 = !checked && actual == expected;
+	if (!ret)
+		ret = checked			      ? checked :
+		      priv->persistent_boot.hardware4 ? 0 :
+							-EIO;
+	priv->persistent_boot.unknown = !priv->persistent_boot.hardware4;
+unlock:
+	mutex_unlock(&priv->persistent_lock);
+	return ret ? ret : priv->persistent_stopped_verified ? 0 : -EIO;
+}
+
+/*
+ * Called while parsed ports still exist: in setup wrapper, internal DSA
+ * teardown, or before normal unregister. Standard software teardown always
+ * follows, even after uncertain hardware cleanup; QCA owns no host DMA memory.
+ */
+static void qca8k_persistent_unwind(struct qca8k_priv *priv, int cause)
+{
+	int error;
+	bool release;
+
+	ASSERT_RTNL();
+	mutex_lock(&priv->persistent_lock);
+	if (cause)
+		qca4_persistent_error(&priv->persistent_boot, cause);
+	mutex_unlock(&priv->persistent_lock);
+	if (!priv->persistent_setup_started)
+		return;
+	error = qca8k_persistent_prepare_detach(priv);
+	mutex_lock(&priv->persistent_lock);
+	release = qca8k_persistent_can_release(priv);
+	mutex_unlock(&priv->persistent_lock);
+	if (!release)
+		qca8k_persistent_note_fault(priv, error ? error : cause);
+}
+
+static int qca8k_setup(struct dsa_switch *ds)
+{
+	struct qca8k_priv *priv = ds->priv;
+	int ret;
+
+	if (!priv->persistent_boot.requested)
+		return qca8k_setup_native(ds);
+	rtnl_lock();
+	ret = qca8k_persistent_boot_start(priv);
+	rtnl_unlock();
+	if (!ret)
+		ret = qca8k_setup_native(ds);
+	if (!ret) {
+		rtnl_lock();
+		ret = qca8k_persistent_boot_hardware4(priv);
+		rtnl_unlock();
+	}
+	if (ret) {
+		rtnl_lock();
+		qca8k_persistent_unwind(priv, ret);
+		rtnl_unlock();
+	}
+	return ret;
+}
+
+static void qca8k_persistent_dsa_teardown(struct dsa_switch *ds)
+{
+	struct qca8k_priv *priv = ds->priv;
+
+	if (!priv->persistent_boot.requested) {
+		return;
+	}
+	/*
+	 * DSA invokes this outside RTNL, including its internal setup failure.
+	 * Never route persistent4 through the timed watchdog-wait invariant.
+	 */
+	rtnl_lock();
+	qca8k_persistent_unwind(priv, 0);
+	rtnl_unlock();
+}
+
+static void qca8k_persistent_register_complete(struct qca8k_priv *priv,
+					       int error)
+{
+	int completed;
+
+	if (!priv->persistent_boot.requested || !error ||
+	    !priv->persistent_setup_started)
+		return;
+	/*
+	 * Ports/dst may have been released by core now. No port dereference:
+	 * hardware cleanup ran while parsed ports were alive in setup/teardown.
+	 */
+	rtnl_lock();
+	completed = qca8k_persistent_detach_complete(priv);
+	if (completed)
+		qca8k_persistent_note_fault(priv, completed);
+	rtnl_unlock();
+}
+
+static void qca8k_persistent_remove(struct qca8k_priv *priv)
+{
+	int completed;
+
+	rtnl_lock();
+	qca8k_persistent_unwind(priv, 0);
+	rtnl_unlock();
+	dsa_unregister_switch(priv->ds);
+	rtnl_lock();
+	completed = qca8k_persistent_detach_complete(priv);
+	if (completed)
+		qca8k_persistent_note_fault(priv, completed);
+	rtnl_unlock();
+}
+
+static void qca8k_persistent_shutdown(struct qca8k_priv *priv)
+{
+	/*
+	 * Driver core drains dev_groups before remove, but not shutdown. Do it
+	 * before drvdata is cleared by the outer shutdown callback.
+	 */
+	rtnl_lock();
+	qca8k_persistent_unwind(priv, 0);
+	rtnl_unlock();
+	dsa_switch_shutdown(priv->ds);
+	/*
+	 * shutdown is NOT unregister: keep FE held through restart, no claim
+	 * that taggers/work/contexts have been destroyed or resources released.
+	 */
+}
+
+/*
+ * DSA parses this same CPU-port property when choosing its tagger. Select
+ * the hardware format before get_tag_protocol(), rather than changing the
+ * running tree through a private sysfs API. All CPU ports must agree.
+ */
+static int qca8k_persistent_boot_admit(struct qca8k_priv *priv)
+{
+	struct device_node *ports;
+	unsigned int cpus = 0, selected = 0;
+	const char *protocol;
+
+	ports = of_get_child_by_name(priv->dev->of_node, "ports");
+	if (!ports)
+		ports = of_get_child_by_name(priv->dev->of_node,
+					     "ethernet-ports");
+	if (!ports)
+		return 0;
+	for_each_available_child_of_node_scoped(ports, port) {
+		if (!of_property_present(port, "ethernet"))
+			continue;
+		cpus++;
+		if (!of_property_read_string(port, "dsa-tag-protocol",
+					     &protocol) &&
+		    !strcmp(protocol, "qca4"))
+			selected++;
+	}
+	of_node_put(ports);
+	if (!selected)
+		return 0;
+	if (selected != cpus)
+		return -EINVAL;
+	priv->persistent_boot.requested = true;
+	priv->private_tag_protocol = DSA_TAG_PROTO_QCA4;
+	priv->private_open_blocked = true;
+	priv->private_mgmt_blocked = true;
+	return 0;
+}
+
+int qca8k_persistent_status(struct net_device *conduit,
+			    struct qca8k_persistent_status *status)
+{
+	struct qca8k_persistent_status snapshot = {
+		.size = sizeof(snapshot),
+		.version = QCA8K_PERSISTENT_STATUS_VERSION,
+	};
+	struct dsa_port *cpu;
+	struct qca8k_priv *priv;
+	unsigned int port;
+	u32 value;
+	int ret = 0;
+
+	ASSERT_RTNL();
+	if (!status || status->size != sizeof(*status) ||
+	    status->version != QCA8K_PERSISTENT_STATUS_VERSION ||
+	    status->reserved || !conduit)
+		return -EINVAL;
+	*status = snapshot;
+	cpu = conduit->dsa_ptr;
+	if (!cpu || !dsa_port_is_cpu(cpu) ||
+	    cpu->ds->ops->get_tag_protocol != qca8k_get_tag_protocol)
+		return -EOPNOTSUPP;
+	priv = cpu->ds->priv;
+	mutex_lock(&priv->persistent_lock);
+	if (!priv->persistent_boot.requested) {
+		ret = -EOPNOTSUPP;
+		goto unlock;
+	}
+	snapshot.conduit_mtu[0] = dsa_to_port(priv->ds, 0)->conduit->mtu;
+	snapshot.conduit_mtu[1] = dsa_to_port(priv->ds, 6)->conduit->mtu;
+	snapshot.epoch = priv->persistent_epoch;
+	snapshot.selected = priv->private_tag_protocol;
+	snapshot.tree_protocol =
+		priv->ds->dst->tag_ops ? priv->ds->dst->tag_ops->proto : 0;
+	snapshot.requested = true;
+	snapshot.ready = priv->persistent_boot.ready;
+	snapshot.closing = priv->persistent_closing;
+	snapshot.restore_debt = priv->persistent_boot.restore_pending;
+	snapshot.uncertain = priv->persistent_boot.unknown ||
+			     priv->persistent_mtu.unknown ||
+			     priv->persistent_mtu.pending;
+	snapshot.first_error = priv->persistent_boot.first_error;
+	snapshot.held_fault = qca8k_persistent_last_fault;
+	if (!snapshot.ready || snapshot.closing || snapshot.uncertain ||
+	    snapshot.first_error || snapshot.held_fault)
+		goto publish;
+	ret = qca8k_persistent_software_ready(priv, false);
+	if (ret)
+		goto publish;
+	ret = qca8k_read_mii(priv, QCA8K_REG_GLOBAL_HDR_CTRL, &value);
+	if (!ret && (value & QCA4_PERSISTENT_MASK) != QCA4_PERSISTENT_VALUE)
+		ret = -EUCLEAN;
+	for (port = 0; !ret && port <= 6; port += 6) {
+		ret = qca8k_read_mii(priv, QCA8K_REG_PORT_HDR_CTRL(port),
+				     &value);
+		if (!ret && value != QCA4_PERSISTENT_CPU_HEADER)
+			ret = -EUCLEAN;
+	}
+	if (!ret) {
+		snapshot.known = true;
+		snapshot.coherent = true;
+		snapshot.conduit_mtu[0] =
+			dsa_to_port(priv->ds, 0)->conduit->mtu;
+		snapshot.conduit_mtu[1] =
+			dsa_to_port(priv->ds, 6)->conduit->mtu;
+	}
+publish:
+	if (ret)
+		snapshot.uncertain = true;
+	*status = snapshot; /* Even an I/O error cannot leave a stale known4. */
+unlock:
+	mutex_unlock(&priv->persistent_lock);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(qca8k_persistent_status);
diff --git a/drivers/net/dsa/qca/qca8k.h b/drivers/net/dsa/qca/qca8k.h
index 956338893..9427e5d7d 100644
--- a/drivers/net/dsa/qca/qca8k.h
+++ b/drivers/net/dsa/qca/qca8k.h
@@ -13,6 +13,14 @@
 #include <linux/gpio/consumer.h>
 #include <linux/leds.h>
 #include <linux/dsa/tag_qca.h>
+#include <net/dsa.h>
+#include <linux/workqueue.h>
+#include "persistent_qca4.h"
+#include "persistent_qca4_mtu.h"
+#include <linux/dsa/qca8k_persistent.h>
+
+#define QCA8K_REG_GLOBAL_HDR_CTRL 0x098
+#define QCA8K_GLOBAL_HDR_CTRL_LEN_4B BIT(16)
 
 #define QCA8K_ETHERNET_MDIO_PRIORITY			7
 #define QCA8K_ETHERNET_PHY_PRIORITY			6
@@ -443,6 +451,9 @@ struct qca8k_led {
 };
 
 struct qca8k_priv {
+	enum dsa_tag_protocol private_tag_protocol;
+	bool private_mgmt_blocked, private_management_drained;
+	bool private_open_blocked;
 	u8 switch_id;
 	u8 switch_revision;
 	u8 mirror_rx;
@@ -469,8 +480,31 @@ struct qca8k_priv {
 	struct qca8k_pcs pcs_port_6;
 	const struct qca8k_match_data *info;
 	struct qca8k_led ports_led[QCA8K_LED_COUNT];
+#if IS_ENABLED(CONFIG_NET_DSA_QCA8K_4B_MODE)
+	struct mutex persistent_lock;
+	struct qca4_persistent_state persistent_boot;
+	struct qca4_persistent_mtu_state persistent_mtu;
+	bool persistent_closing;
+	bool persistent_setup_started;
+	bool persistent_cleanup_attempted;
+	int persistent_cleanup_result;
+	int persistent_hold_error;
+	u64 persistent_epoch;
+	bool persistent_fe_held;
+	bool persistent_stopped_verified;
+	bool persistent_native2_verified;
+	u8 persistent_cpu_requested;
+	u8 persistent_status_valid;
+	u32 persistent_status[2];
+#endif
 };
 
+static inline bool qca8k_private_mgmt_blocked(struct qca8k_priv *priv)
+{
+	return IS_ENABLED(CONFIG_NET_DSA_QCA8K_4B_MODE) &&
+	       READ_ONCE(priv->private_mgmt_blocked);
+}
+
 struct qca8k_mib_desc {
 	unsigned int size;
 	unsigned int offset;
@@ -593,4 +627,10 @@ int qca8k_port_lag_join(struct dsa_switch *ds, int port, struct dsa_lag lag,
 int qca8k_port_lag_leave(struct dsa_switch *ds, int port,
 			 struct dsa_lag lag);
 
+int qca8k_persistent_first_user(struct qca8k_priv *priv);
+int qca8k_persistent_change_mtu(struct qca8k_priv *priv, int port, int mtu);
+bool qca8k_persistent_link_up(struct qca8k_priv *priv, int port, u32 status);
+bool qca8k_persistent_port_status(struct qca8k_priv *priv, int port,
+				  bool enable);
+
 #endif /* __QCA8K_H */

-- 
2.53.0



^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH RFC net-next 6/7] net: cortina: connect wired IPv4 NAT to nftables hardware flowtables
  2026-11-25 20:50 [PATCH RFC net-next 0/7] net: cortina: CS7542 wired IPv4 hardware flowtable offload Fil Dunsky via B4 Relay
                   ` (4 preceding siblings ...)
  2026-11-25 20:50 ` [PATCH RFC net-next 5/7] net: dsa: qca8k: select the four-byte format before port activation Fil Dunsky via B4 Relay
@ 2026-11-25 20:50 ` Fil Dunsky via B4 Relay
  2026-11-25 20:50 ` [PATCH RFC net-next 7/7] docs: networking: describe the CS7542 flowtable RFC limits Fil Dunsky via B4 Relay
  2026-11-25 21:10 ` [PATCH RFC net-next 0/7] net: cortina: CS7542 wired IPv4 hardware flowtable offload Andrew Lunn
  7 siblings, 0 replies; 13+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-11-25 20:50 UTC (permalink / raw)
  To: Andrew Lunn, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Florian Fainelli, Simon Horman, Pablo Neira Ayuso,
	Florian Westphal, Phil Sutter, Hans Ulli Kroll, Linus Walleij,
	Andrew Lunn, Russell King, Christian Marangi, Jonathan Corbet,
	Shuah Khan, Randy Dunlap
  Cc: netdev, devicetree, linux-kernel, netfilter-devel, coreteam,
	linux-arm-kernel, linux-doc, Fil Dunsky

From: Fil Dunsky <filipp.dunsky@gmail.com>

Translate established IPv4 TCP and UDP flowtable requests into checked
CS7542 leases. Derive original Ethernet addresses and QCA metadata from
actual CPU-routed packets, then validate route neighbors, bridge FDB and
the persistent switch-format generation.

Requests outside the supported physical DSA path, namespace, rewrite
policy or MTU are rejected to software. SYN, FIN, IP options, fragments
and low-TTL exceptions remain in the CPU path. Module configuration is
explicit; enabling this driver does not enable a firewall
hardware-offload flag.

Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com>
---
 drivers/net/ethernet/cortina/Kconfig               |  11 +
 drivers/net/ethernet/cortina/Makefile              |   1 +
 drivers/net/ethernet/cortina/flowtable/Makefile    |   2 +
 .../cortina/flowtable/codec/cs_ft_rewrite.c        | 234 +++++++++++
 .../cortina/flowtable/codec/cs_ft_rewrite.h        |  42 ++
 .../net/ethernet/cortina/flowtable/cs7542_fw4.c    | 437 +++++++++++++++++++++
 .../ethernet/cortina/flowtable/cs7542_rx_path.c    | 225 +++++++++++
 .../ethernet/cortina/flowtable/cs7542_rx_path.h    |  35 ++
 drivers/net/ethernet/cortina/flowtable/nf_native.c |  90 +++++
 drivers/net/ethernet/cortina/flowtable/nf_native.h |  31 ++
 10 files changed, 1108 insertions(+)

diff --git a/drivers/net/ethernet/cortina/Kconfig b/drivers/net/ethernet/cortina/Kconfig
index 13df28071..50e627ce3 100644
--- a/drivers/net/ethernet/cortina/Kconfig
+++ b/drivers/net/ethernet/cortina/Kconfig
@@ -88,3 +88,14 @@ config CS7542_FE_WIRED
 	  IPv6, Wi-Fi and unsupported policies continue through the CPU.
 	  TCP requires an established connection; SYN and FIN stay in software.
 	  Route, neighbor, MTU and tag state are checked before admission.
+
+config CS7542_FLOWTABLE
+	tristate "Cortina CS7542 nftables hardware flowtable"
+	depends on CS7542_FE_WIRED && NF_FLOW_TABLE && m
+	depends on NET_DSA_QCA8K_4B_MODE
+	default n
+	help
+	  Wired IPv4 TCP/UDP NAT offload through the CS7542 forwarding engine.
+	  This RFC frontend is loadable; the Ethernet owner remains built in.
+	  Users must explicitly request hardware flowtable offload in nftables.
+	  Selecting the driver alone does not change the firewall configuration.
diff --git a/drivers/net/ethernet/cortina/Makefile b/drivers/net/ethernet/cortina/Makefile
index 2bd0572d0..3d6614765 100644
--- a/drivers/net/ethernet/cortina/Makefile
+++ b/drivers/net/ethernet/cortina/Makefile
@@ -16,3 +16,4 @@ endif
 obj-$(CONFIG_CS7542_FE_BACKEND) += cs7542_fe_backend.o
 cs7542_fe_backend-y := cs_fe_backend_module.o cs_fe_backend_algorithm.o cs_fe_hot_codec.o
 
+obj-$(CONFIG_CS7542_FLOWTABLE) += flowtable/
diff --git a/drivers/net/ethernet/cortina/flowtable/Makefile b/drivers/net/ethernet/cortina/flowtable/Makefile
new file mode 100644
index 000000000..00bbbc108
--- /dev/null
+++ b/drivers/net/ethernet/cortina/flowtable/Makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_CS7542_FLOWTABLE) += cs7542_flowtable.o
+cs7542_flowtable-y := cs7542_fw4.o cs7542_rx_path.o nf_native.o codec/cs_ft_rewrite.o
diff --git a/drivers/net/ethernet/cortina/flowtable/codec/cs_ft_rewrite.c b/drivers/net/ethernet/cortina/flowtable/codec/cs_ft_rewrite.c
new file mode 100644
index 000000000..cd5e4e924
--- /dev/null
+++ b/drivers/net/ethernet/cortina/flowtable/codec/cs_ft_rewrite.c
@@ -0,0 +1,234 @@
+// SPDX-License-Identifier: GPL-2.0
+#ifdef CS_FT_HOST_TEST
+#include "host_shim.h"
+#else
+#include <linux/etherdevice.h>
+#include <linux/ip.h>
+#include <linux/pkt_cls.h>
+#include <linux/tc_act/tc_csum.h>
+#include <net/flow_offload.h>
+#endif
+#include "cs_ft_rewrite.h"
+
+/*
+ * Native u32 mask/value storage is intentional: nf_flow_table_offload copies
+ * network-byte arrays into these scalars. Do not ntohl() them a second time.
+ */
+static int cs_ft_patch(u8 *bytes, u8 *written, unsigned int size,
+		       unsigned int offset, u32 mask, u32 value)
+{
+	u8 m[4], v[4];
+	unsigned int i;
+
+	if (offset > size || size - offset < 4)
+		return -EOPNOTSUPP;
+	memcpy(m, &mask, 4);
+	memcpy(v, &value, 4);
+	for (i = 0; i < 4; i++) {
+		if (m[i] != 0 && m[i] != 255)
+			return -EOPNOTSUPP;
+		if (!m[i] && written[offset + i])
+			return -EOPNOTSUPP;
+		if (m[i] && v[i])
+			return -EOPNOTSUPP;
+	}
+	for (i = 0; i < 4; i++)
+		if (!m[i]) {
+			bytes[offset + i] = v[i];
+			written[offset + i] = 1;
+		}
+	return 0;
+}
+
+static int cs_ft_extract_actions(const struct flow_rule *rule, u8 proto,
+				 const struct cs_ft_tuple *before,
+				 struct cs_ft_rewrite *out)
+{
+	struct cs_ft_rewrite r = { 0 };
+	const struct flow_action_entry *a;
+	u8 eth[12] = { 0 }, eth_written[12] = { 0 };
+	u8 addresses[8], address_written[8] = { 0 }, ports[4],
+			 ports_written[4] = { 0 };
+	const u32 csum_flags = TCA_CSUM_UPDATE_FLAG_IPV4HDR |
+			       (proto == IPPROTO_TCP ?
+					TCA_CSUM_UPDATE_FLAG_TCP :
+					TCA_CSUM_UPDATE_FLAG_UDP);
+	const enum flow_action_mangle_base port_header =
+		proto == IPPROTO_TCP ? FLOW_ACT_MANGLE_HDR_TYPE_TCP :
+				       FLOW_ACT_MANGLE_HDR_TYPE_UDP;
+	unsigned int i, csum = 0, nat = 0;
+	struct net_device *egress = NULL;
+
+	if (!rule || !before || !out || !rule->action.num_entries ||
+	    rule->action.num_entries > 16)
+		return -EOPNOTSUPP;
+	memcpy(addresses, &before->src, 4);
+	memcpy(addresses + 4, &before->dst, 4);
+	memcpy(ports, &before->sport, 2);
+	memcpy(ports + 2, &before->dport, 2);
+	flow_action_for_each(i, a, &rule->action) {
+		if (egress)
+			return -EOPNOTSUPP; /* redirect must be last */
+		switch (a->id) {
+		case FLOW_ACTION_MANGLE:
+			if (csum)
+				return -EOPNOTSUPP;
+			switch (a->mangle.htype) {
+			case FLOW_ACT_MANGLE_HDR_TYPE_ETH:
+				if ((a->mangle.offset != 0 &&
+				     a->mangle.offset != 4 &&
+				     a->mangle.offset != 8) ||
+				    cs_ft_patch(eth, eth_written, 12,
+						a->mangle.offset,
+						a->mangle.mask, a->mangle.val))
+					return -EOPNOTSUPP;
+				break;
+			case FLOW_ACT_MANGLE_HDR_TYPE_IP4:
+				if ((a->mangle.offset != 12 &&
+				     a->mangle.offset != 16) ||
+				    a->mangle.mask ||
+				    cs_ft_patch(addresses, address_written, 8,
+						a->mangle.offset - 12,
+						a->mangle.mask, a->mangle.val))
+					return -EOPNOTSUPP;
+				nat = 1;
+				break;
+			case FLOW_ACT_MANGLE_HDR_TYPE_UDP:
+			case FLOW_ACT_MANGLE_HDR_TYPE_TCP:
+				if (a->mangle.htype != port_header ||
+				    a->mangle.offset ||
+				    cs_ft_patch(ports, ports_written, 4, 0,
+						a->mangle.mask, a->mangle.val))
+					return -EOPNOTSUPP;
+				nat = 1;
+				break;
+			default:
+				return -EOPNOTSUPP;
+			}
+			break;
+		case FLOW_ACTION_CSUM:
+			if (csum++ || !nat || a->csum_flags != csum_flags)
+				return -EOPNOTSUPP;
+			break;
+		case FLOW_ACTION_REDIRECT:
+			if (!a->dev)
+				return -EOPNOTSUPP;
+			egress = a->dev;
+			break;
+		default:
+			return -EOPNOTSUPP;
+		}
+	}
+	if (!egress || (nat && !csum))
+		return -EOPNOTSUPP;
+	for (i = 0; i < 12; i++)
+		if (!eth_written[i])
+			return -EOPNOTSUPP;
+	if (!is_valid_ether_addr(eth) || !is_valid_ether_addr(eth + 6))
+		return -EOPNOTSUPP;
+	r.before = *before;
+	memcpy(r.dmac, eth, 6);
+	memcpy(r.smac, eth + 6, 6);
+	memcpy(&r.after.src, addresses, 4);
+	memcpy(&r.after.dst, addresses + 4, 4);
+	memcpy(&r.after.sport, ports, 2);
+	memcpy(&r.after.dport, ports + 2, 2);
+	r.redirect = egress;
+	r.action_count = rule->action.num_entries;
+	r.nat_action = !!nat;
+	r.csum_action = !!csum;
+	r.csum_flags = csum ? csum_flags : 0;
+	*out = r;
+	return 0;
+}
+
+static int cs_ft_extract_match(const struct flow_rule *rule,
+			       struct cs_ft_tuple *tuple, int *ingress,
+			       u8 *proto)
+{
+	const u64 required = BIT_ULL(FLOW_DISSECTOR_KEY_META) |
+			     BIT_ULL(FLOW_DISSECTOR_KEY_CONTROL) |
+			     BIT_ULL(FLOW_DISSECTOR_KEY_BASIC) |
+			     BIT_ULL(FLOW_DISSECTOR_KEY_IPV4_ADDRS) |
+			     BIT_ULL(FLOW_DISSECTOR_KEY_PORTS);
+	struct flow_match_meta meta;
+	struct flow_match_control control;
+	struct flow_match_basic basic;
+	struct flow_match_ipv4_addrs ip;
+	struct flow_match_ports ports;
+
+	if (!rule || !tuple || !ingress || !rule->match.dissector ||
+	    (rule->match.dissector->used_keys & required) != required)
+		return -EOPNOTSUPP;
+	flow_rule_match_meta(rule, &meta);
+	flow_rule_match_control(rule, &control);
+	flow_rule_match_basic(rule, &basic);
+	flow_rule_match_ipv4_addrs(rule, &ip);
+	flow_rule_match_ports(rule, &ports);
+	if (meta.mask->ingress_ifindex != -1 || meta.mask->ingress_iftype ||
+	    meta.mask->l2_miss ||
+	    control.key->addr_type != FLOW_DISSECTOR_KEY_IPV4_ADDRS ||
+	    control.mask->addr_type != 0xffff || control.mask->flags ||
+	    control.mask->thoff || basic.key->n_proto != htons(ETH_P_IP) ||
+	    basic.mask->n_proto != htons(0xffff) ||
+	    basic.mask->ip_proto != 255 || ip.mask->src != htonl(~0U) ||
+	    ip.mask->dst != htonl(~0U) || ports.mask->src != htons(0xffff) ||
+	    ports.mask->dst != htons(0xffff))
+		return -EOPNOTSUPP;
+	if (basic.key->ip_proto == IPPROTO_TCP) {
+		struct flow_match_tcp tcp;
+
+		if (!(rule->match.dissector->used_keys &
+		      BIT_ULL(FLOW_DISSECTOR_KEY_TCP)))
+			return -EOPNOTSUPP;
+		flow_rule_match_tcp(rule, &tcp);
+		if (tcp.key->flags || tcp.mask->flags != htons(0x05))
+			return -EOPNOTSUPP;
+	} else if (basic.key->ip_proto != IPPROTO_UDP) {
+		return -EOPNOTSUPP;
+	}
+	*proto = basic.key->ip_proto;
+	*tuple = (struct cs_ft_tuple){ ip.key->src, ip.key->dst, ports.key->src,
+				       ports.key->dst };
+	*ingress = meta.key->ingress_ifindex;
+	return 0;
+}
+
+int cs_ft_nf_extract(const struct flow_cls_offload *cls, bool routed_nf_context,
+		     struct cs_ft_nf_facts *out)
+{
+	struct cs_ft_nf_facts f = { 0 };
+	struct cs_ft_tuple tuple;
+	const struct flow_rule *rule;
+	const u64 required = BIT_ULL(FLOW_DISSECTOR_KEY_META) |
+			     BIT_ULL(FLOW_DISSECTOR_KEY_CONTROL) |
+			     BIT_ULL(FLOW_DISSECTOR_KEY_BASIC) |
+			     BIT_ULL(FLOW_DISSECTOR_KEY_IPV4_ADDRS) |
+			     BIT_ULL(FLOW_DISSECTOR_KEY_PORTS);
+	if (!cls || !out || cls->command != FLOW_CLS_REPLACE ||
+	    cls->common.chain_index)
+		return -EOPNOTSUPP;
+	rule = flow_cls_offload_flow_rule(cls);
+	if (cs_ft_extract_match(rule, &tuple, &f.ingress_ifindex,
+				&f.ip_proto) ||
+	    cs_ft_extract_actions(rule, f.ip_proto, &tuple, &f.rewrite))
+		return -EOPNOTSUPP;
+	f.egress_ifindex = f.rewrite.redirect->ifindex;
+	f.rewrite.redirect =
+		NULL; /* No borrowed netdev pointer escapes diagnostic API. */
+	f.match_used_keys = rule->match.dissector->used_keys;
+	f.extra_match_keys =
+		f.match_used_keys !=
+		(required |
+		 (f.ip_proto == IPPROTO_TCP ? BIT_ULL(FLOW_DISSECTOR_KEY_TCP) :
+					      0));
+	f.vlan_offset =
+		!!rule->match.dissector->offset[FLOW_DISSECTOR_KEY_VLAN];
+	f.cvlan_offset =
+		!!rule->match.dissector->offset[FLOW_DISSECTOR_KEY_CVLAN];
+	f.routed_nf_context = routed_nf_context;
+	f.ttl_decrement_from_context = routed_nf_context;
+	/* Unknown ingress encapsulation stays unknown even without VLAN actions. */
+	*out = f;
+	return 0;
+}
diff --git a/drivers/net/ethernet/cortina/flowtable/codec/cs_ft_rewrite.h b/drivers/net/ethernet/cortina/flowtable/codec/cs_ft_rewrite.h
new file mode 100644
index 000000000..9f96b1ea6
--- /dev/null
+++ b/drivers/net/ethernet/cortina/flowtable/codec/cs_ft_rewrite.h
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef CS_FT_REWRITE_H
+#define CS_FT_REWRITE_H
+#ifndef CS_FT_HOST_TEST
+#include <linux/types.h>
+#include <net/flow_offload.h>
+#endif
+struct cs_ft_tuple {
+	__be32 src, dst;
+	__be16 sport, dport;
+};
+
+struct cs_ft_rewrite {
+	struct cs_ft_tuple before, after;
+	u8 smac[6],
+		dmac[6]; /* Requested OUTPUT MACs; original MACs not in these NF matches. */
+	struct net_device
+		*redirect; /* Borrowed only during the synchronous call. */
+	unsigned int action_count, csum_flags;
+	bool nat_action, csum_action;
+};
+
+/*
+ * Decode facts only: no topology, domain, QCA or hardware admission. Native
+ *
+ * mask/value bytes follow the actual NF generator; no second ntohl().
+ */
+struct cs_ft_nf_facts {
+	struct cs_ft_rewrite rewrite;
+	u8 ip_proto;
+	int ingress_ifindex, egress_ifindex;
+	u64 match_used_keys;
+	bool extra_match_keys, vlan_offset, cvlan_offset;
+	bool routed_nf_context, ttl_decrement_from_context;
+	bool ttl_action_observed; /* false: this supported NF action set has none. */
+	bool customer_encap_proven_plain; /* always false; absence isn't provenance. */
+	bool hardware_admitted; /* always false: diagnostic result only. */
+};
+
+int cs_ft_nf_extract(const struct flow_cls_offload *cls, bool routed_nf_context,
+		     struct cs_ft_nf_facts *facts);
+#endif
diff --git a/drivers/net/ethernet/cortina/flowtable/cs7542_fw4.c b/drivers/net/ethernet/cortina/flowtable/cs7542_fw4.c
new file mode 100644
index 000000000..d5a132e87
--- /dev/null
+++ b/drivers/net/ethernet/cortina/flowtable/cs7542_fw4.c
@@ -0,0 +1,437 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Standard nftables flowtable frontend for the CS7542/QCA8337 wired path. */
+#include <linux/bitfield.h>
+#include <linux/cs7542_ft_live.h>
+#include <linux/dsa/qca8k_persistent.h>
+#include <linux/etherdevice.h>
+#include <linux/if_bridge.h>
+#include <linux/list.h>
+#include <linux/module.h>
+#include <linux/netdevice.h>
+#include <linux/of.h>
+#include <linux/rtnetlink.h>
+#include <linux/slab.h>
+#include <net/dsa.h>
+#include <net/flow_offload.h>
+#include <net/net_namespace.h>
+#include <net/arp.h>
+#include <net/ip.h>
+#include <net/route.h>
+#include "nf_native.h"
+
+struct native_binding {
+	struct list_head list;
+	struct cs7542_fe_live *owner;
+	struct net_device *conduit;
+	u64 id, handle, version;
+};
+
+/*
+ * cs7542_ft_live serializes every binding callback and retires them all
+ * before dropping the registration pin. The counters are read from sysfs.
+ */
+static LIST_HEAD(bindings);
+static atomic64_t counts[NATIVE_REASONS];
+static typeof(cs7542_fe_live_replace_native) *replace_native;
+static typeof(cs7542_fe_live_replace_native_tcp) *replace_native_tcp;
+static typeof(qca8k_persistent_status) *persistent_status;
+static typeof(cs7542_fe_live_native_lastused) *native_lastused;
+/*
+ * The private nf_flow_table module supplies the PMTU of this direction.
+ * This frontend can load before the flowtable module.
+ */
+
+static struct native_binding *find_binding(u64 id)
+{
+	struct native_binding *b;
+
+	list_for_each_entry(b, &bindings, list)
+		if (b->id == id)
+			return b;
+	return NULL;
+}
+
+static int native_open(void *ctx, u64 id, struct net_device *conduit)
+{
+	struct native_binding *b;
+	int err;
+
+	b = find_binding(id);
+	if (b)
+		return b->conduit ? -EEXIST : -ESHUTDOWN;
+	b = kzalloc_obj(*b);
+	if (!b)
+		return -ENOMEM;
+	b->owner = cs7542_fe_live_get(conduit);
+	if (IS_ERR(b->owner)) {
+		err = PTR_ERR(b->owner);
+		goto free;
+	}
+	err = cs7542_fe_live_open(b->owner, &b->handle);
+	if (err) {
+		cs7542_fe_live_put(b->owner);
+		goto free;
+	}
+	b->id = id;
+	dev_hold(conduit);
+	b->conduit = conduit;
+	list_add_tail(&b->list, &bindings);
+	return 0;
+free:
+	kfree(b);
+	return err;
+}
+
+static struct dsa_port *get_endpoint(struct net_device *conduit, int ifindex,
+				     struct native_endpoint *endpoint)
+{
+	struct net_device *dev = __dev_get_by_index(dev_net(conduit), ifindex);
+	struct net_device *bridge;
+	struct dsa_port *port;
+
+	ASSERT_RTNL();
+	port = dsa_port_from_netdev(dev);
+	if (IS_ERR(port) || !port->ds || !port->ds->dev || !port->cpu_dp ||
+	    port->cpu_dp->conduit != conduit || port->cpu_dp->index != 0 ||
+	    !of_device_is_compatible(port->ds->dev->of_node, "qca,qca8337") ||
+	    port->index < 1 || port->index > 5 || port->lag || port->hsr_dev ||
+	    !netif_running(dev) || !netif_carrier_ok(dev) ||
+	    dsa_port_is_vlan_filtering(port))
+		return ERR_PTR(-EOPNOTSUPP);
+	bridge = netdev_master_upper_dev_get(dev);
+	if (bridge &&
+	    (!netif_is_bridge_master(bridge) || !netif_running(bridge) ||
+	     br_vlan_enabled(bridge) ||
+	     br_port_get_stp_state(dev) != BR_STATE_FORWARDING ||
+	     br_port_flag_is_set(dev, BR_PORT_LOCKED | BR_PORT_MAB |
+					      BR_ISOLATED | BR_VLAN_TUNNEL)))
+		return ERR_PTR(-EOPNOTSUPP);
+	endpoint->ifindex = ifindex;
+	endpoint->port = port->index;
+	ether_addr_copy(endpoint->mac,
+			bridge ? bridge->dev_addr : dev->dev_addr);
+	return port;
+}
+
+static bool fdb_matches(const struct dsa_port *port, const u8 addr[ETH_ALEN])
+{
+	struct net_device *bridge = netdev_master_upper_dev_get(port->user);
+
+	return !bridge || br_fdb_find_port(bridge, addr, 0) == port->user;
+}
+
+/*
+ * Re-resolve the unicast next hop on the same Linux L3 device. The nft
+ * action remains authoritative. The lookup may only corroborate it or
+ * reject it, including routes that require unsupported neighbour types.
+ */
+static int native_check_neighbour(const struct cs7542_fe_native_request *r)
+{
+	struct net_device *dev =
+		__dev_get_by_index(&init_net, r->egress_ifindex);
+	struct flowi4 fl = {
+		.daddr = htonl(r->rule.translated.dst),
+		.saddr = htonl(r->rule.original.src),
+		.fl4_sport = htons(r->rule.original.sport),
+		.fl4_dport = htons(r->rule.translated.dport),
+		.flowi4_proto = r->rule.native_l4proto,
+		.flowi4_flags = FLOWI_FLAG_ANYSRC,
+	};
+	struct net_device *l3;
+	struct neighbour *neigh;
+	struct rtable *rt;
+	__be32 next;
+	int err = -ESTALE;
+
+	ASSERT_RTNL();
+	if (!dev)
+		return -ENODEV;
+	l3 = netdev_master_upper_dev_get(dev);
+	if (!l3)
+		l3 = dev;
+	fl.flowi4_oif = l3->ifindex;
+	rt = ip_route_output_key(&init_net, &fl);
+	if (IS_ERR(rt))
+		return PTR_ERR(rt);
+	if (rt->rt_type != RTN_UNICAST || dst_dev(&rt->dst) != l3 ||
+	    dst_xfrm(&rt->dst) || rt->dst.lwtstate ||
+	    (rt->rt_gw_family && rt->rt_gw_family != AF_INET) ||
+	    ip_dst_mtu_maybe_forward(&rt->dst, true) < r->route_mtu)
+		goto put;
+	next = rt_nexthop(rt, fl.daddr);
+	/*
+	 * Read an existing entry only. Hardware admission never creates one or
+	 * triggers an ARP solicitation to manufacture its own evidence.
+	 */
+	neigh = neigh_lookup(arp_table(dev_net(l3)), &next, l3);
+	if (neigh) {
+		read_lock_bh(&neigh->lock);
+		if ((neigh->nud_state & NUD_VALID) &&
+		    ether_addr_equal(neigh->ha, r->rule.dmac))
+			err = 0;
+		read_unlock_bh(&neigh->lock);
+		neigh_release(neigh);
+	}
+put:
+	ip_rt_put(rt);
+	return err;
+}
+
+static enum native_reason
+prepare_request(struct native_binding *b, struct flow_cls_offload *cls,
+		struct cs7542_fe_native_request *request)
+{
+	struct qca8k_persistent_status format = {
+		.size = sizeof(format),
+		.version = QCA8K_PERSISTENT_STATUS_VERSION,
+	};
+	struct cs_ft_nf_facts facts;
+	struct native_endpoint in, out;
+	struct cs7542_l4_tuple tuple;
+	struct dsa_port *ip, *op;
+	struct cs7542_rx_path wire;
+	enum native_reason reason;
+	typeof(nf_flow_offload_route_mtu) *route_mtu;
+
+	ASSERT_RTNL();
+	if (cs_ft_nf_extract(cls, true, &facts) || facts.extra_match_keys ||
+	    facts.vlan_offset || facts.cvlan_offset ||
+	    !facts.rewrite.nat_action)
+		return NATIVE_MATCH;
+	if (facts.ip_proto == IPPROTO_TCP &&
+	    (!replace_native_tcp || !cls->nf_tcp_established))
+		return NATIVE_MATCH;
+	if (!net_eq(dev_net(b->conduit), &init_net) ||
+	    !netif_running(b->conduit) || !netif_carrier_ok(b->conduit))
+		return NATIVE_PATH;
+	ip = get_endpoint(b->conduit, facts.ingress_ifindex, &in);
+	op = get_endpoint(b->conduit, facts.egress_ifindex, &out);
+	if (IS_ERR(ip) || IS_ERR(op) || ip->ds != op->ds)
+		return NATIVE_PATH;
+	tuple = (struct cs7542_l4_tuple){
+		.src = facts.rewrite.before.src,
+		.dst = facts.rewrite.before.dst,
+		.sport = facts.rewrite.before.sport,
+		.dport = facts.rewrite.before.dport,
+		.ip_proto = htonl(facts.ip_proto),
+	};
+	if (cs7542_rx_path_lookup(b->conduit, in.port, &tuple, &wire))
+		return NATIVE_WIRE;
+	if (!fdb_matches(ip, wire.source) ||
+	    !fdb_matches(op, facts.rewrite.dmac))
+		return NATIVE_PATH;
+	reason = native_rule_build(&facts, &in, &out, &wire, request);
+	if (reason != NATIVE_OWNER)
+		return reason;
+	if (!persistent_status || persistent_status(b->conduit, &format) ||
+	    format.size != sizeof(format) ||
+	    format.version != QCA8K_PERSISTENT_STATUS_VERSION ||
+	    !format.epoch || format.requested != 1 || format.known != 1 ||
+	    format.coherent != 1 || format.ready != 1 ||
+	    format.restore_debt != 1 || format.closing || format.uncertain ||
+	    format.first_error || format.held_fault || format.reserved ||
+	    format.selected != DSA_TAG_PROTO_QCA4 ||
+	    format.tree_protocol != DSA_TAG_PROTO_QCA4)
+		return NATIVE_TAG;
+	request->format_epoch = format.epoch;
+	route_mtu = symbol_get(nf_flow_offload_route_mtu);
+	if (route_mtu) {
+		request->route_mtu = route_mtu(cls);
+		symbol_put(nf_flow_offload_route_mtu);
+	}
+	return NATIVE_OWNER;
+}
+
+static int
+native_replace_checked(struct native_binding *b, struct flow_cls_offload *cls,
+		       const struct cs7542_fe_native_request *request,
+		       enum native_reason *reason)
+{
+	int err;
+
+	err = native_check_neighbour(request);
+	if (err) {
+		*reason = NATIVE_PATH;
+		return cs7542_fe_live_reject(b->owner, b->handle, cls->cookie,
+					     b->version, err);
+	}
+	if (request->rule.native_l4proto == IPPROTO_TCP)
+		err = replace_native_tcp(b->owner, b->handle, cls->cookie,
+					 b->version, request, cls);
+	else
+		err = replace_native(b->owner, b->handle, cls->cookie,
+				     b->version, request);
+	if (err)
+		return err;
+	/*
+	 * Updates during publication are covered by the built-in watcher.
+	 * Recheck the gap between the initial validation and publication.
+	 */
+	err = native_check_neighbour(request);
+	if (err) {
+		*reason = NATIVE_PATH;
+		return cs7542_fe_live_destroy(b->owner, b->handle, cls->cookie, b->version) ?:
+			       err;
+	}
+	*reason = NATIVE_INSTALLED;
+	return 0;
+}
+
+static int native_rule(void *ctx, u64 id, struct flow_cls_offload *cls)
+{
+	struct native_binding *b = find_binding(id);
+	struct cs7542_fe_native_request request;
+	enum native_reason reason;
+	int result;
+
+	if (!b)
+		return -ENOENT;
+	if (!b->conduit)
+		return -ESHUTDOWN;
+	if (cls->command == FLOW_CLS_STATS) {
+		unsigned long lastused;
+
+		if (!native_lastused)
+			return -EOPNOTSUPP;
+		result = native_lastused(b->owner, b->handle, cls->cookie,
+					 &lastused);
+		if (!result)
+			flow_stats_update(&cls->stats, 0, 0, 0, lastused,
+					  FLOW_ACTION_HW_STATS_DELAYED);
+		return result;
+	}
+	if (b->version == U64_MAX)
+		return -EOVERFLOW;
+	b->version++;
+	if (cls->command == FLOW_CLS_DESTROY)
+		return cs7542_fe_live_destroy(b->owner, b->handle, cls->cookie,
+					      b->version);
+	if (cls->command != FLOW_CLS_REPLACE)
+		return -EOPNOTSUPP;
+	/*
+	 * flow-block callbacks can race RTNL-held teardown. Never wait on RTNL
+	 * while holding the live bridge mutex. Every rejection withdraws an
+	 * earlier version of this cookie before returning it to software.
+	 */
+	if (!rtnl_trylock()) {
+		reason = NATIVE_PATH;
+		result = cs7542_fe_live_reject(b->owner, b->handle, cls->cookie,
+					       b->version, -EBUSY);
+	} else {
+		reason = prepare_request(b, cls, &request);
+		if (reason == NATIVE_OWNER && request.route_mtu &&
+		    replace_native) {
+			result = native_replace_checked(b, cls, &request,
+							&reason);
+		} else {
+			result = cs7542_fe_live_reject(b->owner, b->handle,
+						       cls->cookie, b->version,
+						       -EOPNOTSUPP);
+		}
+		rtnl_unlock();
+	}
+	atomic64_inc(&counts[reason]);
+	return result;
+}
+
+static int native_close(void *ctx, u64 id)
+{
+	struct native_binding *b = find_binding(id);
+	int err;
+
+	if (!b)
+		return 0;
+	/*
+	 * A failed hardware cut keeps the block handle and owner reference for
+	 * retry. It must never hold unregister_netdevice() hostage.
+	 */
+	if (b->conduit) {
+		dev_put(b->conduit);
+		b->conduit = NULL;
+	}
+	err = cs7542_fe_live_close(b->owner, b->handle);
+	if (err)
+		return err;
+	list_del(&b->list);
+	cs7542_fe_live_put(b->owner);
+	kfree(b);
+	return 0;
+}
+
+static int native_detach(void *ctx)
+{
+	/* The bridge calls close() for every open binding before detach(). */
+	return list_empty(&bindings) ? 0 : -EBUSY;
+}
+
+static const struct cs7542_ft_live_ops native_ops = {
+	.api_version = CS7542_FT_LIVE_API_VERSION,
+	.size = sizeof(native_ops),
+	.owner = THIS_MODULE,
+	.name = "cs7542-fw4",
+	.open = native_open,
+	.rule = native_rule,
+	.close = native_close,
+	.detach = native_detach,
+};
+
+static int status_get(char *buf, const struct kernel_param *kp)
+{
+	return sysfs_emit(buf,
+		"owner_api=%u rule=%lld topology=%lld wire=%lld mac=%lld format=%lld owner=%lld installed=%lld tcp_native=%u\n",
+		!!replace_native, atomic64_read(&counts[NATIVE_MATCH]),
+		atomic64_read(&counts[NATIVE_PATH]),
+		atomic64_read(&counts[NATIVE_WIRE]),
+		atomic64_read(&counts[NATIVE_MAC]),
+		atomic64_read(&counts[NATIVE_TAG]),
+		atomic64_read(&counts[NATIVE_OWNER]),
+		atomic64_read(&counts[NATIVE_INSTALLED]), !!replace_native_tcp);
+}
+
+static const struct kernel_param_ops status_ops = { .get = status_get };
+module_param_cb(status, &status_ops, NULL, 0444);
+
+static int __init native_init(void)
+{
+	int err = cs7542_rx_path_init();
+
+	if (err)
+		return err;
+	replace_native = symbol_get(cs7542_fe_live_replace_native);
+	replace_native_tcp = symbol_get(cs7542_fe_live_replace_native_tcp);
+	persistent_status = symbol_get(qca8k_persistent_status);
+	native_lastused = symbol_get(cs7542_fe_live_native_lastused);
+	err = cs7542_ft_live_register(&native_ops, NULL);
+	if (err) {
+		if (native_lastused)
+			symbol_put(cs7542_fe_live_native_lastused);
+		if (persistent_status)
+			symbol_put(qca8k_persistent_status);
+		if (replace_native_tcp)
+			symbol_put(cs7542_fe_live_replace_native_tcp);
+		if (replace_native)
+			symbol_put(cs7542_fe_live_replace_native);
+		cs7542_rx_path_exit();
+	}
+	return err;
+}
+
+static void __exit native_exit(void)
+{
+	/* The bridge's reference pins this module until its callbacks quiesce. */
+	cs7542_rx_path_exit();
+	if (native_lastused)
+		symbol_put(cs7542_fe_live_native_lastused);
+	if (persistent_status)
+		symbol_put(qca8k_persistent_status);
+	if (replace_native_tcp)
+		symbol_put(cs7542_fe_live_replace_native_tcp);
+	if (replace_native)
+		symbol_put(cs7542_fe_live_replace_native);
+}
+
+module_init(native_init);
+module_exit(native_exit);
+MODULE_LICENSE("GPL");
+MODULE_INFO(description,
+	"Cortina CS7542 IPv4 TCP and UDP nftables hardware flowtable frontend");
diff --git a/drivers/net/ethernet/cortina/flowtable/cs7542_rx_path.c b/drivers/net/ethernet/cortina/flowtable/cs7542_rx_path.c
new file mode 100644
index 000000000..20a132852
--- /dev/null
+++ b/drivers/net/ethernet/cortina/flowtable/cs7542_rx_path.c
@@ -0,0 +1,225 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Recover the original Ethernet addresses and switch tag of a CPU-routed flow. */
+#include <linux/bitfield.h>
+#include <linux/dsa/tag_qca.h>
+#include <linux/etherdevice.h>
+#include <linux/if_vlan.h>
+#include <linux/ip.h>
+#include <linux/jhash.h>
+#include <linux/jiffies.h>
+#include <linux/module.h>
+#include <linux/netdevice.h>
+#include <linux/of.h>
+#include <linux/udp.h>
+#include <linux/tcp.h>
+#include <linux/unaligned.h>
+#include <net/ip.h>
+#include <net/net_namespace.h>
+#include "cs7542_rx_path.h"
+
+#define PATH_SLOTS 128
+#define PATH_AGE (2 * HZ)
+
+/*
+ * skb->dev is the DSA conduit. Its WAN user port can have a different
+ * unicast MAC. Resolve the addressed L3 device when nftables supplies the
+ * real source port of the route. Observing a frame never installs a rule.
+ */
+struct path_entry {
+	struct cs7542_l4_tuple tuple;
+	struct cs7542_rx_path path;
+	int ifindex;
+	unsigned long expires;
+	bool ambiguous;
+};
+
+static DEFINE_SPINLOCK(paths_lock);
+static struct path_entry paths[PATH_SLOTS];
+static unsigned int index_of(const struct cs7542_l4_tuple *tuple, int ifindex)
+{
+	static_assert(sizeof(*tuple) == 16);
+	return jhash(tuple, sizeof(*tuple), ifindex) % PATH_SLOTS;
+}
+
+static bool fresh(const struct path_entry *entry)
+{
+	return entry->ifindex && time_before(jiffies, entry->expires);
+}
+
+static void remember(int ifindex, const struct cs7542_l4_tuple *tuple,
+		     const struct cs7542_rx_path *path)
+{
+	struct path_entry *entry = &paths[index_of(tuple, ifindex)];
+
+	spin_lock_bh(&paths_lock);
+	if (!fresh(entry)) {
+		entry->ifindex = ifindex;
+		entry->tuple = *tuple;
+		entry->path = *path;
+		entry->ambiguous = false;
+	} else if (entry->ifindex != ifindex ||
+		   memcmp(&entry->tuple, tuple, sizeof(*tuple))) {
+		/* Keep a live owner's observation across hash collisions. */
+		goto out;
+	} else if (entry->path.tag != path->tag ||
+		   entry->path.tag_len != path->tag_len ||
+		   !ether_addr_equal(entry->path.source, path->source) ||
+		   !ether_addr_equal(entry->path.destination,
+				     path->destination)) {
+		entry->ambiguous = true;
+	}
+	entry->expires = jiffies + PATH_AGE;
+out:
+	spin_unlock_bh(&paths_lock);
+}
+
+int cs7542_rx_path_lookup(struct net_device *conduit, unsigned int port,
+			  const struct cs7542_l4_tuple *tuple,
+			  struct cs7542_rx_path *out)
+{
+	struct path_entry *entry;
+	int error = -ENOENT;
+
+	if (!conduit || !tuple || !out || !net_eq(dev_net(conduit), &init_net))
+		return -EINVAL;
+	entry = &paths[index_of(tuple, conduit->ifindex)];
+	spin_lock_bh(&paths_lock);
+	if (fresh(entry) && entry->ifindex == conduit->ifindex &&
+	    !memcmp(&entry->tuple, tuple, sizeof(*tuple)) &&
+	    !entry->ambiguous &&
+	    FIELD_GET(QCA_HDR_RECV_SOURCE_PORT, entry->path.tag) == port) {
+		*out = entry->path;
+		error = 0;
+	}
+	spin_unlock_bh(&paths_lock);
+	return error;
+}
+
+static void observe(struct sk_buff *skb, struct net_device *dev)
+{
+	u8 ether[ETH_HLEN + 4] __aligned(4);
+	struct iphdr ip;
+	union {
+		struct udphdr udp;
+		struct tcphdr tcp;
+	} transport;
+	unsigned int l4_length;
+	struct cs7542_l4_tuple tuple;
+	struct cs7542_rx_path path;
+	unsigned int reason;
+	int offset;
+
+	if ((skb->pkt_type != PACKET_HOST &&
+	     skb->pkt_type != PACKET_OTHERHOST) ||
+	    !net_eq(dev_net(dev), &init_net) || !skb_mac_header_was_set(skb) ||
+	    skb_vlan_tag_present(skb) || skb_is_gso(skb))
+		return;
+	offset = skb_mac_header(skb) - skb->data;
+	if (offset != -ETH_HLEN ||
+	    skb_copy_bits(skb, offset, ether, sizeof(ether)))
+		return;
+	path.tag_len = get_unaligned_be16(ether + 12) == ETH_P_8021Q ? 4 : 2;
+	path.tag = get_unaligned_be16(ether + 10 + path.tag_len);
+	reason = FIELD_GET(QCA_HDR_RECV_TYPE, path.tag);
+	/*
+	 * Ordinary frames sent to the CPU also carry forwarding reason codes.
+	 * Both QCA taggers consume register replies and MIB packets themselves.
+	 */
+	if (FIELD_GET(QCA_HDR_RECV_VERSION, path.tag) != QCA_HDR_VERSION ||
+	    reason == QCA_HDR_RECV_TYPE_MIB ||
+	    reason == QCA_HDR_RECV_TYPE_RW_REG_ACK ||
+	    (path.tag & QCA_HDR_RECV_FRAME_IS_TAGGED) ||
+	    !FIELD_GET(QCA_HDR_RECV_SOURCE_PORT, path.tag) ||
+	    get_unaligned_be16(ether + 12 + path.tag_len) != ETH_P_IP ||
+	    !is_valid_ether_addr(ether) ||
+	    !is_valid_ether_addr(ether + ETH_ALEN))
+		return;
+	if (skb_copy_bits(skb, path.tag_len, &ip, sizeof(ip)) ||
+	    ip.version != 4 || ip.ihl != 5 || ip_is_fragment(&ip) ||
+	    ip_fast_csum(&ip, 5) || ntohs(ip.tot_len) < sizeof(ip) ||
+	    skb->len < path.tag_len + ntohs(ip.tot_len))
+		return;
+	l4_length = ntohs(ip.tot_len) - sizeof(ip);
+	if (ip.protocol == IPPROTO_UDP) {
+		if (l4_length < sizeof(transport.udp) ||
+		    skb_copy_bits(skb, path.tag_len + sizeof(ip),
+				  &transport.udp, sizeof(transport.udp)) ||
+		    ntohs(transport.udp.len) != l4_length)
+			return;
+		tuple.sport = transport.udp.source;
+		tuple.dport = transport.udp.dest;
+	} else if (ip.protocol == IPPROTO_TCP) {
+		/*
+		 * Even a handshake can identify a switch peer. Only netfilter can
+		 * authorize established data offload via its typed request.
+		 */
+		if (l4_length < sizeof(transport.tcp) ||
+		    skb_copy_bits(skb, path.tag_len + sizeof(ip),
+				  &transport.tcp, sizeof(transport.tcp)) ||
+		    transport.tcp.doff < 5 ||
+		    transport.tcp.doff * 4 > l4_length)
+			return;
+		tuple.sport = transport.tcp.source;
+		tuple.dport = transport.tcp.dest;
+	} else {
+		return;
+	}
+	tuple.src = ip.saddr;
+	tuple.dst = ip.daddr;
+	tuple.ip_proto = htonl(ip.protocol);
+	ether_addr_copy(path.source, ether + ETH_ALEN);
+	ether_addr_copy(path.destination, ether);
+	remember(dev->ifindex, &tuple, &path);
+}
+
+static int receive(struct sk_buff *skb, struct net_device *dev,
+		   struct packet_type *ptype, struct net_device *original)
+{
+	observe(skb, dev);
+	consume_skb(skb);
+	return NET_RX_SUCCESS;
+}
+
+static struct packet_type observer = {
+	.type = cpu_to_be16(ETH_P_XDSA),
+	.func = receive,
+};
+
+static int link_event(struct notifier_block *nb, unsigned long event,
+		      void *data)
+{
+	struct net_device *dev = netdev_notifier_info_to_dev(data);
+	unsigned int i;
+
+	if (!net_eq(dev_net(dev), &init_net) ||
+	    (event != NETDEV_DOWN && event != NETDEV_CHANGEADDR &&
+	     event != NETDEV_UNREGISTER))
+		return NOTIFY_DONE;
+	spin_lock_bh(&paths_lock);
+	for (i = 0; i < ARRAY_SIZE(paths); i++)
+		if (paths[i].ifindex == dev->ifindex)
+			paths[i].ifindex = 0;
+	spin_unlock_bh(&paths_lock);
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block netdev_events = { .notifier_call = link_event };
+
+int cs7542_rx_path_init(void)
+{
+	int error;
+
+	if (!of_machine_is_compatible("securifi,almondplus"))
+		return -ENODEV;
+	error = register_netdevice_notifier(&netdev_events);
+	if (error)
+		return error;
+	dev_add_pack(&observer);
+	return 0;
+}
+
+void cs7542_rx_path_exit(void)
+{
+	dev_remove_pack(&observer);
+	unregister_netdevice_notifier(&netdev_events);
+}
diff --git a/drivers/net/ethernet/cortina/flowtable/cs7542_rx_path.h b/drivers/net/ethernet/cortina/flowtable/cs7542_rx_path.h
new file mode 100644
index 000000000..20f6b4c7c
--- /dev/null
+++ b/drivers/net/ethernet/cortina/flowtable/cs7542_rx_path.h
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef CS7542_RX_PATH_H
+#define CS7542_RX_PATH_H
+
+#include <linux/if_ether.h>
+#include <linux/types.h>
+
+struct net_device;
+
+struct cs7542_l4_tuple {
+	__be32 src, dst;
+	__be16 sport, dport;
+	/* Network order keeps all 16 hash/key bytes defined on every architecture. */
+	__be32 ip_proto;
+};
+
+struct cs7542_rx_path {
+	u8 source[ETH_ALEN];
+	u8 destination[ETH_ALEN];
+	u16 tag;
+	u8 tag_len;
+};
+
+/*
+ * The caller supplies the flow's live ingress conduit and DSA port.
+ * An observation is input to the classifier, not permission to install a rule.
+ */
+int cs7542_rx_path_lookup(struct net_device *conduit, unsigned int port,
+			  const struct cs7542_l4_tuple *tuple,
+			  struct cs7542_rx_path *out);
+
+int cs7542_rx_path_init(void);
+void cs7542_rx_path_exit(void);
+
+#endif
diff --git a/drivers/net/ethernet/cortina/flowtable/nf_native.c b/drivers/net/ethernet/cortina/flowtable/nf_native.c
new file mode 100644
index 000000000..7363e8f4c
--- /dev/null
+++ b/drivers/net/ethernet/cortina/flowtable/nf_native.c
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: GPL-2.0
+#ifdef CS_FT_HOST_TEST
+#include "host_shim.h"
+#define be32_to_cpu(v) ntohl(v)
+#define be16_to_cpu(v) ntohs(v)
+#define ether_addr_equal(a, b) (!memcmp(a, b, 6))
+#define ether_addr_copy(d, s) memcpy(d, s, 6)
+#else
+#include <linux/etherdevice.h>
+#endif
+#include "nf_native.h"
+
+static struct cs_fe_tuple to_tuple(const struct cs_ft_tuple *bytes)
+{
+	return (struct cs_fe_tuple){
+		.src = be32_to_cpu(bytes->src),
+		.dst = be32_to_cpu(bytes->dst),
+		.sport = be16_to_cpu(bytes->sport),
+		.dport = be16_to_cpu(bytes->dport),
+	};
+}
+
+static struct cs_fe_link to_link(const struct native_endpoint *endpoint)
+{
+	struct cs_fe_link link = {
+		.gmac = 1,
+		.cpu_port = 0,
+		.switch_port = endpoint->port,
+		.base_voq = 8,
+		.tag_mode = 4,
+	};
+
+	ether_addr_copy(link.base_mac, endpoint->mac);
+	return link;
+}
+
+enum native_reason native_rule_build(const struct cs_ft_nf_facts *facts,
+				     const struct native_endpoint *ingress,
+				     const struct native_endpoint *egress,
+				     const struct cs7542_rx_path *wire,
+				     struct cs7542_fe_native_request *request)
+{
+	const struct cs_ft_rewrite *rw = &facts->rewrite;
+	struct cs7542_fe_native_request next = {
+		.abi = facts->ip_proto == CS_FE_L4_TCP ? CS7542_FE_NATIVE_ABI :
+							 1,
+		.size = sizeof(next),
+	};
+	unsigned int reason;
+
+	if ((facts->ip_proto != CS_FE_L4_UDP &&
+	     facts->ip_proto != CS_FE_L4_TCP) ||
+	    !facts->routed_nf_context || !facts->ttl_decrement_from_context ||
+	    facts->extra_match_keys || facts->vlan_offset ||
+	    facts->cvlan_offset || !rw->nat_action || !rw->csum_action)
+		return NATIVE_MATCH;
+	if (facts->ingress_ifindex <= 0 || facts->egress_ifindex <= 0 ||
+	    ingress->ifindex != (unsigned int)facts->ingress_ifindex ||
+	    egress->ifindex != (unsigned int)facts->egress_ifindex ||
+	    ingress->port < 1 || ingress->port > 5 || egress->port < 1 ||
+	    egress->port > 5)
+		return NATIVE_PATH;
+	if (!wire || !is_valid_ether_addr(wire->source) ||
+	    !is_valid_ether_addr(wire->destination))
+		return NATIVE_WIRE;
+	if (!ether_addr_equal(wire->destination, ingress->mac) ||
+	    !ether_addr_equal(rw->smac, egress->mac))
+		return NATIVE_MAC;
+	reason = (wire->tag >> 6) & 31;
+	if (wire->tag_len != 4 || (wire->tag >> 14) != 2 ||
+	    (wire->tag & 7) != ingress->port || (wire->tag & 8) ||
+	    reason == 1 || reason == 2)
+		return NATIVE_TAG;
+
+	next.ingress_ifindex = ingress->ifindex;
+	next.egress_ifindex = egress->ifindex;
+	ether_addr_copy(next.ingress_smac, wire->source);
+	next.rule.native_l4proto = facts->ip_proto;
+	next.rule.original = to_tuple(&rw->before);
+	next.rule.translated = to_tuple(&rw->after);
+	next.rule.ingress = to_link(ingress);
+	next.rule.ingress.rx_qca_meta = wire->tag;
+	next.rule.egress = to_link(egress);
+	ether_addr_copy(next.rule.smac, rw->smac);
+	ether_addr_copy(next.rule.dmac, rw->dmac);
+	next.rule.decrement_ttl = true;
+	*request = next;
+	/* Owner confirmation is the next step. There is no installed entry yet. */
+	return NATIVE_OWNER;
+}
diff --git a/drivers/net/ethernet/cortina/flowtable/nf_native.h b/drivers/net/ethernet/cortina/flowtable/nf_native.h
new file mode 100644
index 000000000..cedd89727
--- /dev/null
+++ b/drivers/net/ethernet/cortina/flowtable/nf_native.h
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef CS7542_NF_NATIVE_H
+#define CS7542_NF_NATIVE_H
+
+#include <linux/cs7542_fe_native.h>
+#include "cs7542_rx_path.h"
+#include "codec/cs_ft_rewrite.h"
+
+enum native_reason {
+	NATIVE_MATCH,
+	NATIVE_PATH,
+	NATIVE_WIRE,
+	NATIVE_MAC,
+	NATIVE_TAG,
+	NATIVE_OWNER,
+	NATIVE_INSTALLED,
+	NATIVE_REASONS
+};
+
+struct native_endpoint {
+	unsigned int ifindex, port;
+	u8 mac[6];
+};
+
+enum native_reason native_rule_build(const struct cs_ft_nf_facts *facts,
+				     const struct native_endpoint *ingress,
+				     const struct native_endpoint *egress,
+				     const struct cs7542_rx_path *wire,
+				     struct cs7542_fe_native_request *request);
+
+#endif

-- 
2.53.0



^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH RFC net-next 7/7] docs: networking: describe the CS7542 flowtable RFC limits
  2026-11-25 20:50 [PATCH RFC net-next 0/7] net: cortina: CS7542 wired IPv4 hardware flowtable offload Fil Dunsky via B4 Relay
                   ` (5 preceding siblings ...)
  2026-11-25 20:50 ` [PATCH RFC net-next 6/7] net: cortina: connect wired IPv4 NAT to nftables hardware flowtables Fil Dunsky via B4 Relay
@ 2026-11-25 20:50 ` Fil Dunsky via B4 Relay
  2026-11-25 21:10 ` [PATCH RFC net-next 0/7] net: cortina: CS7542 wired IPv4 hardware flowtable offload Andrew Lunn
  7 siblings, 0 replies; 13+ messages in thread
From: Fil Dunsky via B4 Relay @ 2026-11-25 20:50 UTC (permalink / raw)
  To: Andrew Lunn, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Florian Fainelli, Simon Horman, Pablo Neira Ayuso,
	Florian Westphal, Phil Sutter, Hans Ulli Kroll, Linus Walleij,
	Andrew Lunn, Russell King, Christian Marangi, Jonathan Corbet,
	Shuah Khan, Randy Dunlap
  Cc: netdev, devicetree, linux-kernel, netfilter-devel, coreteam,
	linux-arm-kernel, linux-doc, Fil Dunsky

From: Fil Dunsky <filipp.dunsky@gmail.com>

Record the real LAN/WAN NAT qualification and its precise limits:
immutable result capacity, conservative sticky-HIT aging, module
lifetime restrictions and software fallback. Distinguish precursor
hardware results from execution of the new Linux composition. Extend the
existing network-engine file patterns.

Signed-off-by: Fil Dunsky <filipp.dunsky@gmail.com>
---
 .../ethernet/cortina/cs7542-flowtable.rst          | 112 +++++++++++++++++++++
 MAINTAINERS                                        |   5 +
 2 files changed, 117 insertions(+)

diff --git a/Documentation/networking/device_drivers/ethernet/cortina/cs7542-flowtable.rst b/Documentation/networking/device_drivers/ethernet/cortina/cs7542-flowtable.rst
new file mode 100644
index 000000000..bedb825b6
--- /dev/null
+++ b/Documentation/networking/device_drivers/ethernet/cortina/cs7542-flowtable.rst
@@ -0,0 +1,112 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+CS7542 hardware flowtable RFC
+============================
+
+This RFC connects the CS7542 forwarding engine to nftables hardware
+flowtables. The Ethernet driver remains the sole owner of packet DMA,
+indirect tables and network-engine reset. The forwarding algorithm and
+flowtable frontend are replaceable modules in this development version.
+They do not map hardware registers themselves.
+
+Supported path
+--------------
+
+The current path is wired IPv4 TCP/UDP NAT through a QCA8337 switch on the
+CS7542. It accepts physical user ports 1 through 5 on CPU port 0/GMAC1.
+Both ingress and egress must resolve to that conduit and to the initial
+network namespace. It checks the route, neighbor, bridge FDB, observed
+original Ethernet header, tag format and directional route MTU before
+publishing a lookup. Unsupported requests return to software processing.
+Wi-Fi and IPv6 are not accelerated.
+
+TCP admission additionally requires an established conntrack state. The
+flowtable supplies that state together with the route MTU. SYN, FIN,
+fragments, IP options, low TTL and packets outside the admitted length
+range remain on the CPU path. The driver does not infer a route MTU or an
+established connection from flower rewrite actions.
+
+The QCA four-byte CPU header puts an identifier ahead of the ordinary
+two-byte QCA metadata. This lets the CS7542 parser recognize the inner
+IPv4 header. CPU-port ``dsa-tag-protocol = "qca4"`` selects the format.
+Both configured CPU ports must agree. The default remains the ordinary
+two-byte QCA format. Ethernet management frames are not usable with this
+four-byte tagger, so switch register access stays on MDIO.
+
+Resource lifetime
+-----------------
+
+There are 16 admitted direction selectors and eight immutable result
+records in this implementation. A result includes every hardware-visible
+forwarding dependency. Identical results may be shared by independent
+selectors. A retired selector may be rebound only after invalidation and
+complete readback, with the original immutable result still present.
+Removing one selector does not retire another selector sharing its result.
+
+This is not general result reclamation. An incompatible result consumes
+another record. Eight different retained results exhaust this small
+allocation pool until a verified complete network-engine reset. Further
+flows fall back to software. A successful lookup withdrawal is not treated
+as proof that all in-flight hardware references have drained.
+
+Failed or ambiguous hardware transactions close admission and retain the
+state needed for isolation and recovery. The current replaceable modules
+remain pinned until the built-in manager completes checked detachment.
+Ordinary arbitrary module removal and suspend are not supported by this
+RFC. The Ethernet owner, switch and MDIO must be built in; forced module
+removal and power management are excluded by Kconfig. Consolidating this
+development interface into the Ethernet driver is an open design item.
+
+Activity accounting
+-------------------
+
+The hardware HIT bit is sticky. The driver only treats an observed
+zero-to-one transition as evidence of recent activity. It neither clears
+the bitmap without a proven drain protocol nor fabricates packet counters
+or fresh timestamps from repeated reads of the same set bit.
+
+Consequently an active connection can expire from the hardware flowtable
+at the normal Linux timeout and be learned again in software. On the
+tested OpenWrt configuration this produced one CPU packet in each direction
+at about 30-second intervals. This conservative refresh is a known limit,
+not evidence of uninterrupted hardware residency or accurate packet counts.
+
+Validation and provenance
+-------------------------
+
+The precursor on Almond+ OpenWrt 6.18.64 was tested with the standard LuCI
+hardware flow-offloading option and ordinary firewall4 NAT. LAN and WAN
+were separate physical switch ports. The client was 192.168.1.2; the WAN
+server was 10.42.0.1 and observed the translated router address 10.42.0.139.
+
+Byte-exact UDP exchanges covered IP lengths 512, 1400 and 1500 with DF
+set and clear. Both directions arrived with TTL 63. With flow offload
+disabled, the CPU capture contained all 72 marked packets. With hardware
+offload enabled it contained four of 212 packets: the two refresh pairs
+at 30 and 60 seconds. Capture reported no kernel drops. TCP exchanged
+2,293,760 verified bytes over 70 seconds; TCP and UDP conntrack entries
+retained HW_OFFLOAD at the 3, 35 and 69 second observations. TCP endpoints
+accepted the data; this is not an independent capture-based checksum
+audit of every accelerated TCP segment.
+
+A separate eight-connection test exercised 16 selectors sharing one result.
+Seven connections kept their original selectors and continued forwarding
+after the first connection was removed. These were correctness tests at a
+controlled rate, not throughput or maximum-capacity benchmarks.
+
+The Linux RFC changes the DSA selection interface, removes laboratory
+controls and adapts to current kernel APIs. Measurements of the precursor
+must not be represented as an execution of these exact Linux source bytes.
+Build and software-test results are recorded separately in the cover letter.
+
+Review questions
+----------------
+
+* Should directional route MTU and established TCP state be carried in the
+  flowtable's classifier request, or through a different common interface?
+* Is the standard DSA tag-selection property appropriate for this CPU
+  parser constraint and the two-conduit switch setup?
+* What hardware evidence would be sufficient to permit reclamation of
+  different result records and clearing the sticky HIT state safely?
+* Should the built-in owner and replaceable algorithm be consolidated
+  before a non-RFC submission?
diff --git a/MAINTAINERS b/MAINTAINERS
index d17acadaa..a70086354 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2966,7 +2966,12 @@ M:	Fil Dunsky <filipp.dunsky@gmail.com>
 L:	netdev@vger.kernel.org
 S:	Maintained
 F:	Documentation/devicetree/bindings/net/cortina,cs7542-ethernet.yaml
+F:	Documentation/networking/device_drivers/ethernet/cortina/cs7542-flowtable.rst
 F:	drivers/net/ethernet/cortina/cs752x_*
+F:	drivers/net/ethernet/cortina/cs7542*
+F:	drivers/net/ethernet/cortina/cs_fe_*
+F:	drivers/net/ethernet/cortina/flowtable/
+F:	include/linux/cs7542_*
 
 ARM/CORTINA SYSTEMS GEMINI ARM ARCHITECTURE
 M:	Hans Ulli Kroll <ulli.kroll@googlemail.com>

-- 
2.53.0



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH RFC net-next 0/7] net: cortina: CS7542 wired IPv4 hardware flowtable offload
  2026-11-25 20:50 [PATCH RFC net-next 0/7] net: cortina: CS7542 wired IPv4 hardware flowtable offload Fil Dunsky via B4 Relay
                   ` (6 preceding siblings ...)
  2026-11-25 20:50 ` [PATCH RFC net-next 7/7] docs: networking: describe the CS7542 flowtable RFC limits Fil Dunsky via B4 Relay
@ 2026-11-25 21:10 ` Andrew Lunn
  2026-11-25 21:55   ` Fil Dunsky
  7 siblings, 1 reply; 13+ messages in thread
From: Andrew Lunn @ 2026-11-25 21:10 UTC (permalink / raw)
  To: filipp.dunsky
  Cc: Vladimir Oltean, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Florian Fainelli, Simon Horman, Pablo Neira Ayuso,
	Florian Westphal, Phil Sutter, Hans Ulli Kroll, Linus Walleij,
	Andrew Lunn, Russell King, Christian Marangi, Jonathan Corbet,
	Shuah Khan, Randy Dunlap, netdev, devicetree, linux-kernel,
	netfilter-devel, coreteam, linux-arm-kernel, linux-doc

On Wed, Nov 25, 2026 at 11:50:28PM +0300, Fil Dunsky via B4 Relay wrote:
> This RFC connects the CS7542 forwarding engine to nftables hardware
> flowtables on Securifi Almond+. It is separate from the CPU Ethernet
> bring-up series. The main questions are the flowtable context interface,
> QCA four-byte CPU framing, and conservative hardware resource lifetime.

This is v2? Please include a version number in the subject line.

Please also list what changed relative to v1.

> - Is dsa-tag-protocol the right selection interface for this parser need?
> - What hardware drain evidence is needed before safely replacing different
>   result records or clearing the sticky HIT bitmap?

Is this a DSA switch?

DSA implies that there is a conduit interface which is used to pass
frames to a port of the switch. My first look at this driver did not
suggest that. It looked like there where a bunch of DMA channels, not
a full network interface?

I will look at the code again, but you should decide this quickly, the
different between a pure switchdev driver and a DSA driver is quite
big.

	Andrew

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH RFC net-next 5/7] net: dsa: qca8k: select the four-byte format before port activation
  2026-11-25 20:50 ` [PATCH RFC net-next 5/7] net: dsa: qca8k: select the four-byte format before port activation Fil Dunsky via B4 Relay
@ 2026-11-25 21:13   ` Andrew Lunn
  0 siblings, 0 replies; 13+ messages in thread
From: Andrew Lunn @ 2026-11-25 21:13 UTC (permalink / raw)
  To: filipp.dunsky
  Cc: Vladimir Oltean, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Florian Fainelli, Simon Horman, Pablo Neira Ayuso,
	Florian Westphal, Phil Sutter, Hans Ulli Kroll, Linus Walleij,
	Andrew Lunn, Russell King, Christian Marangi, Jonathan Corbet,
	Shuah Khan, Randy Dunlap, netdev, devicetree, linux-kernel,
	netfilter-devel, coreteam, linux-arm-kernel, linux-doc

On Wed, Nov 25, 2026 at 11:50:33PM +0300, Fil Dunsky via B4 Relay wrote:
> From: Fil Dunsky <filipp.dunsky@gmail.com>
> 
> Select the requested format from the CPU ports before DSA chooses its
> tagger. Stop packet actors and verify the switch header state before
> opening user ports. Use MDIO for management and preserve both conduit
> MTUs.

Confused. What has the QCA driver got to do with this?

I think it is time for a big picture architecture email.

  Andrew

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH RFC net-next 2/7] net: dsa: add a QCA four-byte CPU tagger
  2026-11-25 20:50 ` [PATCH RFC net-next 2/7] net: dsa: add a QCA four-byte CPU tagger Fil Dunsky via B4 Relay
@ 2026-11-25 21:15   ` Andrew Lunn
  0 siblings, 0 replies; 13+ messages in thread
From: Andrew Lunn @ 2026-11-25 21:15 UTC (permalink / raw)
  To: filipp.dunsky
  Cc: Vladimir Oltean, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Florian Fainelli, Simon Horman, Pablo Neira Ayuso,
	Florian Westphal, Phil Sutter, Hans Ulli Kroll, Linus Walleij,
	Andrew Lunn, Russell King, Christian Marangi, Jonathan Corbet,
	Shuah Khan, Randy Dunlap, netdev, devicetree, linux-kernel,
	netfilter-devel, coreteam, linux-arm-kernel, linux-doc

>  #define dsa_lags_foreach_id(_id, _dst)				\
>  	for ((_id) = 1; (_id) <= (_dst)->lags_len; (_id)++)	\
>  		if ((_dst)->lags[(_id) - 1])
> -
>  #define dsa_lag_foreach_port(_dp, _dst, _lag)			\
>  	list_for_each_entry((_dp), &(_dst)->ports, list)	\
>  		if (dsa_port_offloads_lag((_dp), (_lag)))
> -
>  #define dsa_hsr_foreach_port(_dp, _ds, _hsr)			\
>  	list_for_each_entry((_dp), &(_ds)->dst->ports, list)	\
>  		if ((_dp)->ds == (_ds) && (_dp)->hsr_dev == (_hsr))
> -
>  static inline struct dsa_lag *dsa_lag_by_id(struct dsa_switch_tree *dst,
>  					    unsigned int id)

Did you review your own patches?

	Andrew

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH RFC net-next 0/7] net: cortina: CS7542 wired IPv4 hardware flowtable offload
  2026-11-25 21:10 ` [PATCH RFC net-next 0/7] net: cortina: CS7542 wired IPv4 hardware flowtable offload Andrew Lunn
@ 2026-11-25 21:55   ` Fil Dunsky
  2026-11-25 22:10     ` Andrew Lunn
  0 siblings, 1 reply; 13+ messages in thread
From: Fil Dunsky @ 2026-11-25 21:55 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Vladimir Oltean, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Florian Fainelli, Simon Horman, Pablo Neira Ayuso,
	Florian Westphal, Phil Sutter, Hans Ulli Kroll, Linus Walleij,
	Russell King, Christian Marangi, Jonathan Corbet, Shuah Khan,
	Randy Dunlap, netdev, devicetree, linux-kernel, netfilter-devel,
	coreteam, linux-arm-kernel, linux-doc

Hi Andrew,

This is the first standalone offload RFC, v1. The prerequisite CPU-only
Ethernet series is v2; this RFC does not replace that series. I should
have made the relationship and architecture much clearer. The next
revision will carry an explicit v2 and a changelog.

There are two separate chips on Almond+:

  LAN1..4, WAN
       |
  QCA8337 external switch (existing qca8k DSA driver)
       | CPU port 0                 | CPU port 6
       | RGMII                     | RGMII
       v                           v
  CS7542 GMAC1 (eth1)          CS7542 GMAC0 (eth0)
       \                           /
        CS7542 network/forwarding engine and shared DMA
                         |
                        CPU

The proposed CS7542 Ethernet driver exposes two full Ethernet netdevs,
eth1 and eth0, despite sharing the DMA engine. Those are the conduits
for the external QCA8337. I am not modelling the CS7542 forwarding
engine itself as another DSA switch.

The CPU receive path is QCA8337 -> RGMII -> CS7542 DMA -> eth1/eth0 ->
DSA tagger -> lanN/wan. Transmit follows the reverse path. Ordinary L2
switching remains the existing QCA8337 driver's responsibility.

The accelerated routed IPv4 path in this RFC is QCA8337 -> GMAC1 ->
CS7542 FE lookup/NAT rewrite -> GMAC1 -> QCA8337 destination port. It
bypasses the CPU DMA path. The frontend accepts standard nftables
hardware flowtable requests through TC_SETUP_FT; it is not a new L2
switchdev implementation.

This explains the QCA changes in patch 5: its optional four-byte CPU
header adds an identifier before the normal QCA metadata. With the
identifier set to 0x8100, the CS7542 FE parser can locate the inner IPv4
header. It cannot do that with the ordinary two-byte QCA header. The
new tagger therefore describes the external switch's wire format, not
a DSA interface inside CS7542. Header length is global to QCA8337, so
both CPU ports must agree, although the present accelerated path uses
only CPU port 0/GMAC1. Management uses MDIO in this mode.

Your patch-2 comment is also correct: the unrelated blank-line changes
in include/net/dsa.h were my mistake. I have removed them locally;
only the two protocol-ID additions remain. No replacement series is
being sent while this discussion is ongoing.

Thanks,
Fil


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH RFC net-next 0/7] net: cortina: CS7542 wired IPv4 hardware flowtable offload
  2026-11-25 21:55   ` Fil Dunsky
@ 2026-11-25 22:10     ` Andrew Lunn
  0 siblings, 0 replies; 13+ messages in thread
From: Andrew Lunn @ 2026-11-25 22:10 UTC (permalink / raw)
  To: Fil Dunsky
  Cc: Vladimir Oltean, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Florian Fainelli, Simon Horman, Pablo Neira Ayuso,
	Florian Westphal, Phil Sutter, Hans Ulli Kroll, Linus Walleij,
	Russell King, Christian Marangi, Jonathan Corbet, Shuah Khan,
	Randy Dunlap, netdev, devicetree, linux-kernel, netfilter-devel,
	coreteam, linux-arm-kernel, linux-doc

On Thu, Nov 26, 2026 at 12:55:27AM +0300, Fil Dunsky wrote:
> Hi Andrew,
> 
> This is the first standalone offload RFC, v1. The prerequisite CPU-only
> Ethernet series is v2; this RFC does not replace that series.

Ah.

One patchset at a time please. Get the basic Ethernet support working
first. Then start on the next topic.

       Andrew

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2026-11-25 22:11 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 20:50 [PATCH RFC net-next 0/7] net: cortina: CS7542 wired IPv4 hardware flowtable offload Fil Dunsky via B4 Relay
2026-11-25 20:50 ` [PATCH RFC net-next 1/7] dt-bindings: net: dsa: allow the QCA four-byte tag protocol Fil Dunsky via B4 Relay
2026-11-25 20:50 ` [PATCH RFC net-next 2/7] net: dsa: add a QCA four-byte CPU tagger Fil Dunsky via B4 Relay
2026-11-25 21:15   ` Andrew Lunn
2026-11-25 20:50 ` [PATCH RFC net-next 3/7] netfilter: flowtable: expose route MTU and established TCP context Fil Dunsky via B4 Relay
2026-11-25 20:50 ` [PATCH RFC net-next 4/7] net: cortina: add a serialized CS7542 forwarding engine owner Fil Dunsky via B4 Relay
2026-11-25 20:50 ` [PATCH RFC net-next 5/7] net: dsa: qca8k: select the four-byte format before port activation Fil Dunsky via B4 Relay
2026-11-25 21:13   ` Andrew Lunn
2026-11-25 20:50 ` [PATCH RFC net-next 6/7] net: cortina: connect wired IPv4 NAT to nftables hardware flowtables Fil Dunsky via B4 Relay
2026-11-25 20:50 ` [PATCH RFC net-next 7/7] docs: networking: describe the CS7542 flowtable RFC limits Fil Dunsky via B4 Relay
2026-11-25 21:10 ` [PATCH RFC net-next 0/7] net: cortina: CS7542 wired IPv4 hardware flowtable offload Andrew Lunn
2026-11-25 21:55   ` Fil Dunsky
2026-11-25 22:10     ` Andrew Lunn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®