Skip to contentSkip to conversation

Add Cortina Systems CS7542 network engine support

PATCH Superseded Fil Dunsky 2 participants 6 messages Dec 4 – Dec 5

Subsystems (4)

v8 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Fil Dunsky

author
#0 lore raw

v8 cover Add Cortina Systems CS7542 network engine support

Add the CS7542 CPU network datapath with phylink for three GMACs. Almond+ connects two GMACs to QCA8337 CPU ports handled by DSA.

This series depends on the combined CS7542 global controls v6 series.
The six prerequisite patches apply on the current net-next base. The consumer acquires the NI, FE, TM, SCH, QM, DMA and NI-XRAM reset controls exclusively. Board DTS
support is separate. The verified 64 MiB no-map queue-manager reservation
is required. NAND uses PIO; a separate SSP DMA consumer cannot run
concurrently with the shared DMA reset domain.

Use normal NAPI weight 64 and external-DDR QM/TM setup, with no module parameters. Support scatter-gather TX and multi-buffer RX, bounded initialization, tracked DMA ownership, shared NI register serialization and protective reset before freeing active mappings. No checksum/NAT offload or performance capability is added.

The port byte counters previously wrapped at 4 GiB on 32-bit ARM. Use the network core's 64-bit per-CPU totals and preserve the existing error and drop counters. Allow independent MAC addresses on each netdev. With PAUSE temporarily enabled for testing, QCA8337 PAUSE frames stopped transmission on both GMACs with different addresses. Cortina did not generate PAUSE frames under offered line-rate traffic or when NAPI stopped draining the RX ring, so this series leaves hardware flow control disabled.

The driver exposes no MAC-level Wake-on-LAN support. The NI magic-packet comparator uses the
shared MAC prefix and cannot follow arbitrary independent netdev MAC addresses. PHY-based wake support can be considered separately once the PHY capability and board wake path are verified.

The driver compiles for ARM with warnings as errors. On Almond+ an OpenWrt RAM build exercised LAN1 over each of the two QCA8337 CPU ports with the standard two-byte QCA tag. Five two-packet ICMP exchanges succeeded while assigning and changing different MAC addresses for the two GMACs. RX/TX counters increased on the selected GMAC in each case. All MTD partitions were read-only and the watchdog returned to OpenWrt.

Earlier combined-kernel Almond+ checks covered reset/probe/removal, LAN1 protected-data transfers and automatic watchdog return to normal OpenWrt. Separate earlier fixtures checked 600 UDP echoes, 20 ICMPv6 replies and 448 scatter-gather/jumbo frames. Protected-region hashes and flash layout matched; unrelated concurrent settings activity was excluded from any unchanged-settings claim. These observations predate the new retry/context fixes and are integration/functional checks, not throughput or offload results.

Changes in v8:
- Rebase onto current net-next (Willem de Bruijn).
- Anchor MAINTAINERS independently of the global-controls entry.
- Pick up Rob Herring's Reviewed-by on the unchanged binding.
- Link to v7: https://patch.msgid.link/[email protected]

Changes in v7:
- Address Andrew Lunn's review. Simplify the FE return path and order
local declarations. Separate RX packet handling from the NAPI loop.
- Allow independent MAC addresses, retain NVMEM probe deferral and
leave hardware pause disabled.
- Link to v6: https://patch.msgid.link/[email protected]

Changes in v6:
- Keep zero-budget NAPI polling limited to TX completions.
- Link to v5: https://lore.kernel.org/r/[email protected]

Changes in v5:
- Use the network core's 64-bit per-CPU packet and byte totals.
- Pack the MAC register value with get_unaligned_le32().
- Update the global-controls dependency to v6.
- Link to v4: https://lore.kernel.org/all/[email protected]/

Changes in v4:
- Bound DMA-owned RX head polling and defer retries with the IRQ masked.
- Schedule NAPI with bottom halves disabled from process context.
- Link to v3: https://lore.kernel.org/all/[email protected]/

Changes in v3:
- Include FCS in RX buffer recycling and retry transient descriptor ownership.
- Validate the shared MAC prefix and reject sibling-clobbering changes.
- Drop the RESET_CONTROLLER select from the Ethernet consumer.
- Rely on reset provider error propagation instead of redundant status reads.
- Use bulk deassert on bring-up; preserve all protective assertions on teardown.
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- Use the common parent provider and all seven exclusive reset lines;
remove the virtual reset child, duplicate provider and consumer hook.
- Assert and verify every line without protective-assert rollback;
retain active DMA allocations on any error and deassert in reverse order.
- Use rgmii-id in the binding example for switch-inserted RX/TX delays.
- Remove module parameters and unused internal-buffer mode; retain the
previous default external-DDR initialization policy.
- Use NAPI weight64, plain static MMIO helpers and goto-based open cleanup;
retain the lock-protected publication and stopping gates.
- Serialize shared NI RMW and stop on the first scheduler command error.
- Keep MAC preflight before hardware cleanup registration and preserve
a late NVMEM probe defer instead of replacing it with a random MAC.
- Recycle bounded RX fragments also when the frame is dropped.
- Poll already queued RX after open and retain safe closed-port TX reaping.
- Review Sashiko 231860: existing NI/SCH/NAPI fixes address the older v1; temporary BM initialization bypass clearing follows the vendor sequence.
- Link to v1: https://lore.kernel.org/all/[email protected]/

---
Fil Dunsky (3):
dt-bindings: net: Add Cortina CS7542 network engine
net: cortina: Add CS7542 CPU network datapath
MAINTAINERS: Add CS7542 network engine support

 .../bindings/net/cortina,cs7542-ethernet.yaml      |  162 ++
 MAINTAINERS                                        |    7 +
 drivers/net/ethernet/cortina/Kconfig               |   13 +
 drivers/net/ethernet/cortina/Makefile              |    3 +
 drivers/net/ethernet/cortina/cs752x_fe.c           |  475 +++++
 drivers/net/ethernet/cortina/cs752x_ne.c           | 1893 ++++++++++++++++++++
 drivers/net/ethernet/cortina/cs752x_ne.h           |   13 +
 drivers/net/ethernet/cortina/cs752x_sch_tm.c       |  688 +++++++
 8 files changed, 3254 insertions(+)

---
base-commit: aea6deaf6b3c8a204242a4ca1fdb26e8e74de5fc
change-id: 20261123-b4-cs7542-ethernet-59c15dbc7e7e
prerequisite-message-id: <[email protected]>
prerequisite-patch-id: 27fe25055bcadb3c3fbc8b6788f31c2fb791df38
prerequisite-patch-id: ae69b5cca6f4604972300a89411bdca0ea19ab57
prerequisite-patch-id: 55dc4f1e91fc85340c4422438225f50fdf636799
prerequisite-patch-id: 66fccae72a8f951ac0ee182490e98543af29bd89
prerequisite-patch-id: 7fbe9405265ef3d1ec62811415a46c0061afd7c8
prerequisite-patch-id: 01ece2c91e080d5cae6af81944159373776484ca

Best regards,

Signature · 1 line
Fil Dunsky <[email protected]>
author
#1 lore raw

PATCH v8 1/3 dt-bindings: net: Add Cortina CS7542 network engine

Describe the CS7542 network engine register windows, interrupts, GMACs and reserved queue-manager memory. Require exclusive ownership of the seven NI/FE/TM/SCH/QM/DMA/NI-XRAM reset controls from the global provider. The shared DMA line includes both LSO and SSP. Use rgmii-id for the example switch peer which inserts RX and TX clock delays.

---
 .../bindings/net/cortina,cs7542-ethernet.yaml      | 162 +++++++++++++++++++++
 1 file changed, 162 insertions(+)
Documentation/devicetree/bindings/net/cortina,cs7542-ethernet.yaml new file +162 -0
new file mode 100644
index 000000000..c5ba9b30e
@@ -0,0 +1,162 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/cortina,cs7542-ethernet.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Cortina Systems CS7542 network engine
+
+maintainers:
+  - Fil Dunsky <[email protected]>
+
+description: |
+  The CS7542 network engine contains three GMACs, the network interface (NI),
+  forwarding engine (FE), queue manager (QM), traffic manager (TM), scheduler,
+  CPU XRAM interface and packet DMA. The CPU datapath uses the DMA-LSO TX
+  queue and QM-managed RX buffers. The complete DMA-LSO/SSP register block
+  and the combined reset domain must be exclusively owned by this device;
+  a separate SSP DMA consumer cannot operate concurrently. A NAND controller
+  using PIO does not consume that DMA block.
+  The three GMAC station addresses share their first five bytes in NI
+  registers; only the last byte is independent for each port.
+
+properties:
+  compatible:
+    const: cortina,cs7542-ethernet
+
+  reg:
+    items:
+      - description: NI registers
+      - description: Complete DMA-LSO and DMA-SSP registers
+      - description: FE registers and indirect table interfaces
+      - description: QM registers
+      - description: TM registers
+      - description: Scheduler registers
+      - description: CPU XRAM
+
+  reg-names:
+    items:
+      - const: ni
+      - const: dma
+      - const: fe
+      - const: qm
+      - const: tm
+      - const: sch
+      - const: xram
+
+  interrupts:
+    items:
+      - description: GMAC0 CPU receive queue interrupt
+      - description: GMAC1 CPU receive queue interrupt
+      - description: GMAC2 CPU receive queue interrupt
+
+  interrupt-names:
+    items:
+      - const: eth0
+      - const: eth1
+      - const: eth2
+
+  cortina,global-syscon:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description: Global control syscon for network drive strength and status.
+
+  resets:
+    items:
+      - description: Network interface reset.
+      - description: Forwarding engine reset.
+      - description: Traffic manager reset.
+      - description: Scheduler reset.
+      - description: Queue manager reset.
+      - description: Shared DMA-LSO/SSP reset, exclusively owned by this consumer.
+      - description: Network interface XRAM reset.
+
+  reset-names:
+    items:
+      - const: ni
+      - const: fe
+      - const: tm
+      - const: sch
+      - const: qm
+      - const: dma
+      - const: xram
+
+  memory-region:
+    maxItems: 1
+    description: |
+      Reserved no-map DDR region used by the packet queue manager. Initial
+      support uses the upper 64 MiB of the 512 MiB DDR layout at 0x1c000000.
+
+  "#address-cells":
+    const: 1
+
+  "#size-cells":
+    const: 0
+
+patternProperties:
+  "^ethernet-port@[0-2]$":
+    type: object
+    $ref: ethernet-controller.yaml#
+    unevaluatedProperties: false
+    properties:
+      reg:
+        maxItems: 1
+      phy-mode:
+        enum: [rgmii, rgmii-id, rgmii-rxid, rgmii-txid]
+    required:
+      - reg
+      - phy-mode
+
+required:
+  - compatible
+  - reg
+  - reg-names
+  - interrupts
+  - interrupt-names
+  - cortina,global-syscon
+  - resets
+  - reset-names
+  - memory-region
+  - "#address-cells"
+  - "#size-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/reset/cortina,cs7542-reset.h>
+
+    ethernet@f0010000 {
+        compatible = "cortina,cs7542-ethernet";
+        reg = <0xf0010000 0x500>, <0xf0090000 0x800>,
+              <0xf0020000 0x4000>, <0xf0030000 0x400>,
+              <0xf0040000 0x800>, <0xf0060000 0x100>,
+              <0xf0400000 0x100000>;
+        reg-names = "ni", "dma", "fe", "qm", "tm", "sch", "xram";
+        interrupts = <GIC_SPI 37 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 38 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 39 IRQ_TYPE_LEVEL_HIGH>;
+        interrupt-names = "eth0", "eth1", "eth2";
+        cortina,global-syscon = <&global>;
+        resets = <&global CS7542_RESET_NI>,
+                 <&global CS7542_RESET_FE>,
+                 <&global CS7542_RESET_TM>,
+                 <&global CS7542_RESET_SCH>,
+                 <&global CS7542_RESET_QM>,
+                 <&global CS7542_RESET_DMA>,
+                 <&global CS7542_RESET_NI_XRAM>;
+        reset-names = "ni", "fe", "tm", "sch", "qm", "dma", "xram";
+        memory-region = <&qm_reserved>;
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        ethernet-port@1 {
+            reg = <1>;
+            /* Fixed MAC-to-switch link; peer inserts RX/TX clock delays. */
+            phy-mode = "rgmii-id";
+            fixed-link {
+                speed = <1000>;
+                full-duplex;
+            };
+        };
+    };
Signature · 1 line
2.53.0
author
#2 lore raw

PATCH v8 2/3 net: cortina: Add CS7542 CPU network datapath

In reply to Fil Dunsky

Add the three-GMAC CS7542 CPU network datapath with phylink, per-port NAPI RX and a shared coherent TX ring. Support scatter-gather TX and multi-buffer RX while validating DMA addresses and ring ownership. Use the normal NAPI weight and the supported external-DDR QM/TM setup.

Bound indirect initialization and require confirmed complete-domain reset before freeing active DMA mappings. Pin mappings and context when reset fails. Keep resource publication and shared-ring timer cancellation under the TX lock so completions cannot wake a closing or failed port. Use shared ndo_open cleanup labels and let the compiler inline MMIO helpers when appropriate.

Acquire NI, FE, TM, SCH, QM, DMA and NI-XRAM controls exclusively from the global provider. Assert and verify all seven without rolling back protective assertions; preserve the first error and retain all active DMA allocations on any failure. Deassert in reverse order. The shared DMA control covers both LSO and SSP. Require the verified 64 MiB no-map queue-manager reservation on the supported DDR layout.

Serialize read-modify-write accesses to NI registers shared by the MACs. Abort initialization on the first scheduler command error before the network engine can publish DMA buffers.

Resolve NVMEM MAC deferral before installing hardware cleanup, when no reset or DMA state needs unwinding. Register the plain managed cleanup action immediately before the first reset attempt, preserving protective cleanup for that attempt and all later failures.

Count RX fragments independently of whether the frame is deliverable. Start with a masked NAPI poll to service previously queued RX descriptors. Keep TX completion reaping available while closed ports still own queued mappings. The coherent TX read pointer identifies completed descriptors; this hardware retains TX OWN after completion.

Count all DMA bytes including FCS when recycling RX fragments. Bound immediate NAPI retries of a hardware-owned head to four polls, then keep the IRQ masked and retry from delayed work without touching DMA-owned buffers. Cancel the retry when stopping the port. Disable bottom halves around NAPI scheduling from ndo_open and the retry worker, restoring locks and IRQ state before allowing the softirq to run.
Read each port's MAC address independently and use the standard Ethernet netdev address change helper. The NI control-frame MAC address has a shared five-octet prefix. Keep MAC flow control disabled until PAUSE transmission is validated.

Keep packet and byte totals in the network core per-CPU statistics. Separate RX packet handling from NAPI polling. Keep zero-budget NAPI polling limited to TX completions.

---
 drivers/net/ethernet/cortina/Kconfig         |   13 +
 drivers/net/ethernet/cortina/Makefile        |    3 +
 drivers/net/ethernet/cortina/cs752x_fe.c     |  475 +++++++
 drivers/net/ethernet/cortina/cs752x_ne.c     | 1893 ++++++++++++++++++++++++++
 drivers/net/ethernet/cortina/cs752x_ne.h     |   13 +
 drivers/net/ethernet/cortina/cs752x_sch_tm.c |  688 ++++++++++
 6 files changed, 3085 insertions(+)
drivers/net/ethernet/cortina/Kconfig +13 -0
index aaf9e294b..6a93e28bd 100644
@@ -20,4 +20,17 @@ config GEMINI_ETHERNET
 	help
 	  This driver supports StorLink SL351x (Gemini) dual Gigabit Ethernet.
 
+config CS7542_ETHERNET
+	tristate "Cortina CS7542 network engine"
+	depends on OF && OF_RESERVED_MEM && HAS_IOMEM
+	select PHYLINK
+	select MFD_SYSCON
+	help
+	  Support the CS7542 network engine GMACs with a CPU DMA datapath.
+	  A dedicated queue-manager DDR reservation and exclusive ownership
+	  of all seven NI, FE, TM, SCH, QM, DMA and NI-XRAM reset lines are
+	  required. The shared DMA line covers both LSO and SSP.
+	  To compile this driver as a module, choose M; the module is named
+	  cs7542-eth.
+
 endif # NET_VENDOR_CORTINA
drivers/net/ethernet/cortina/Makefile +3 -0
index 4e86d398a..e998ffcc8 100644
@@ -2,3 +2,6 @@
 # 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
drivers/net/ethernet/cortina/cs752x_fe.c new file +475 -0

475 lines not on this page · raw message

drivers/net/ethernet/cortina/cs752x_ne.c new file +1893 -0

1,893 lines not on this page · raw message

drivers/net/ethernet/cortina/cs752x_ne.h new file +13 -0
new file mode 100644
index 000000000..1f7c08166
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __CS752X_NE_H__
+#define __CS752X_NE_H__
+
+#include <linux/types.h>
+
+struct device;
+
+int cs752x_fe_init(struct device *dev, void __iomem *fe);
+int cs752x_sch_init(struct device *dev, void __iomem *sch);
+int cs752x_tm_init(struct device *dev, void __iomem *tm);
+
+#endif
drivers/net/ethernet/cortina/cs752x_sch_tm.c new file +688 -0

596 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.53.0

Part of the diff is not shown here. View the raw message.

#3 lore raw

Re: [PATCH net-next v8 2/3] net: cortina: Add CS7542 CPU network datapath

Thank you for your contribution! Sashiko AI review found 13 potential issues to consider: - [High] net: cortina: netpoll/netconsole deadlocks on ne->txq.lock - [Medium] net: cortina: missing…

Thank you for your contribution! Sashiko AI review found 13 potential issues to consider:
- [High] net: cortina: netpoll/netconsole deadlocks on ne->txq.lock
- [Medium] net: cortina: missing of_node_get()/of_node_put() for port OF nodes
- [Medium] net: cortina: atomic dev_alloc_page() used for bulk RX probe refill
- [Medium] net: cortina: host-endian writes to coherent TX DMA descriptors
- [Medium] net: cortina: excessive hard-IRQ-disabling ne->rx_lock use in RX path
- [Medium] net: cortina: TX ring data race and lock contention under ne->txq.lock
- [Medium] net: cortina: order-2 atomic RX skb allocations for jumbo frames
- [Medium] net: cortina: loop-invariant shaper bypass in cs752x_sch_init()
- [Medium] net: cortina: cs_ne_rx_poll() discards refreshed RX write pointer
- [Medium] net: cortina: missing IRQ status clear and recheck in cs_ne_rx_poll()
- [Low] net: cortina: unpaired plain writes to txq->head, tail, and fault
- [Low] net: cortina: duplicated TX descriptor, free-space, and txq init code
- [Low] net: cortina: unmarked ndev->stats increments race with dev_get_tstats64()
--

commit fd19fefeb519d024c28ee4b48974974a246e10bf
Author: Fil Dunsky <[email protected]>

net: cortina: Add CS7542 CPU network datapath

This commit adds the Cortina CS7542 Ethernet driver supporting three GMAC ports with phylink, per-port NAPI RX, a shared coherent TX ring, and forwarding engine, scheduler, and traffic manager initialization.

Quoted 5 lines
drivers/net/ethernet/cortina/cs752x_ne.c new file +0 -0
new file mode 100644
index 0000000000000..ad673449802c6

[ ... ]

drivers/net/ethernet/cortina/cs752x_ne.c line 712

Quoted 12 lines
drivers/net/ethernet/cortina/cs752x_ne.c new file +12 -0
+static int cs_ne_rx_refill(struct cs_ne_port *port, int count)
+{
+	struct cs_ne *ne = port->ne;
+	struct cs_ne_rx_buf *buf;
+	unsigned long flags;
+	int ret, i;
+
+	for (i = 0; i < count; i++) {
+		buf = kzalloc_obj(*buf);
+		if (!buf)
+			break;
+		buf->page = dev_alloc_page();

[Severity: Medium]
Should cs_ne_rx_refill() use alloc_page(GFP_KERNEL) instead of dev_alloc_page()?

cs_ne_rx_refill() is only called during sleepable probe from cs_ne_probe_port() and already uses GFP_KERNEL for kzalloc_obj() and xa_insert(). dev_alloc_page() allocates with GFP_ATOMIC, which can unnecessarily fail probe with -ENOMEM when filling up to 2304 RX pages (9 MiB) on a 512 MiB platform with 64 MiB reserved for QM.

[ ... ]

Quoted 26 lines
drivers/net/ethernet/cortina/cs752x_ne.c new file +26 -0
+static bool cs_ne_rx_claim(struct cs_ne *ne, const dma_addr_t *dma,
+			   struct cs_ne_rx_buf **bufs, unsigned int count)
+{
+	struct cs_ne_rx_buf *buf;
+	unsigned long flags;
+	unsigned int i;
+	bool valid = true;
+
+	if (!count || count > CS_NE_RX_MAX_BUFS)
+		return false;
+	spin_lock_irqsave(&ne->rx_lock, flags);
+	for (i = 0; i < count; i++) {
+		bufs[i] = NULL;
+		buf = xa_load(&ne->rx_buffers, dma[i] >> CS_NE_RX_DMA_SHIFT);
+		if (!buf || buf->dma != dma[i] || buf->state != CS_NE_RX_HW) {
+			valid = false;
+			continue;
+		}
+		buf->state = CS_NE_RX_CPU;
+		buf->sync_off = 0;
+		buf->sync_len = 0;
+		bufs[i] = buf;
+	}
+	spin_unlock_irqrestore(&ne->rx_lock, flags);
+	return valid;
+}

[ ... ]

Quoted 8 lines
drivers/net/ethernet/cortina/cs752x_ne.c new file +8 -0
+static void cs_ne_rx_recycle(struct cs_ne *ne, struct cs_ne_rx_buf *buf)
+{
+	unsigned long flags;
+
+	if (!buf)
+		return;
+	/* A claimed mapping cannot be handed to another CPU while it is copied. */
+	if (WARN_ON_ONCE(buf->state != CS_NE_RX_CPU))

drivers/net/ethernet/cortina/cs752x_ne.c line 814

Quoted 10 lines
drivers/net/ethernet/cortina/cs752x_ne.c new file +10 -0
+		return;
+	if (buf->sync_len)
+		dma_sync_single_range_for_device(ne->dev, buf->dma, buf->sync_off,
+						 buf->sync_len, DMA_FROM_DEVICE);
+	spin_lock_irqsave(&ne->rx_lock, flags);
+	buf->sync_len = 0;
+	buf->state = CS_NE_RX_PENDING;
+	list_add_tail(&buf->pending, &ne->rx_pending);
+	spin_unlock_irqrestore(&ne->rx_lock, flags);
+}

[Severity: Medium]
Does ne->rx_lock need to disable hard IRQs and be taken per packet and per fragment on the RX path?

cs_ne_rx_irq() never acquires ne->rx_lock and zero-budget netpoll in cs_ne_rx_poll() returns before touching it, so every caller runs in softirq or process context. Acquiring spin_lock_irqsave(&ne->rx_lock) in cs_ne_rx_claim() across xa_load() lookups, again per fragment in cs_ne_rx_recycle(), and across the MMIO push loop in cs_ne_rx_kick() masks hard interrupts and serializes concurrent NAPI polls across all three ports. Using spin_lock_bh()/spin_lock(), doing the immutable xa_load() lookups outside the lock, and batching recycled buffers onto a local list spliced once per poll in cs_ne_rx_kick() would avoid this.

[ ... ]

Quoted 9 lines
drivers/net/ethernet/cortina/cs752x_ne.c new file +9 -0
+static void cs_ne_tx_complete(struct cs_ne *ne)
+{
+	struct cs_ne_txq *txq = &ne->txq;
+	struct cs_ne_tx_buf *buf;
+	u32 rptr;
+	int i;
+
+	if (txq->fault)
+		return;

drivers/net/ethernet/cortina/cs752x_ne.c line 873

Quoted 10 lines
drivers/net/ethernet/cortina/cs752x_ne.c new file +10 -0
+	rptr = readl(ne->dma + DMA_LSO_TXQ_RPTR(0)) & DMA_PTR_MASK;
+	/* Never consume unsubmitted descriptors or loop past the ring boundary. */
+	if (rptr >= CS_NE_TX_DESC_NUM ||
+	    ((rptr - txq->tail) & (CS_NE_TX_DESC_NUM - 1)) >
+	    ((txq->head - txq->tail) & (CS_NE_TX_DESC_NUM - 1))) {
+		txq->fault = true;
+		cs_ne_tx_stop_all(ne);
+		dev_err_ratelimited(ne->dev, "invalid TX completion pointer %#x\n", rptr);
+		return;
+	}

[Severity: High]
Can netpoll or netconsole self-deadlock on ne->txq.lock here and across the TX paths?

The driver does not set IFF_DISABLE_NETPOLL and supports zero-budget polling in cs_ne_rx_poll(). netconsole invokes netpoll_send_skb() from hardirq context with local IRQs disabled, reaching cs_ne_start_xmit() and cs_ne_rx_poll(..., 0) -> cs_ne_tx_reap(), while normal callers (cs_ne_tx_timer(), cs_ne_tx_reap(), cs_ne_start_xmit(), cs_ne_open(), cs_ne_stop()) acquire the shared ne->txq.lock with hardirqs enabled:

cs_ne_tx_timer()
spin_lock(&txq->lock)
<hardirq>

    netconsole -> netpoll_send_skb(port0)
      cs_ne_start_xmit()
        spin_lock(&txq->lock)  <-- spins forever

In addition, calling dev_err_ratelimited() in cs_ne_tx_complete() while holding ne->txq.lock after cs_ne_tx_stop_all() synchronously re-enters netconsole -> netpoll_poll_dev() -> cs_ne_rx_poll(..., 0) -> cs_ne_tx_reap(), which self-deadlocks on ne->txq.lock even with spin_lock_irqsave().

Consider either setting IFF_DISABLE_NETPOLL, or converting all ne->txq.lock acquisitions to spin_lock_irqsave()/spin_unlock_irqrestore() and moving dev_err_ratelimited() outside ne->txq.lock.

Quoted 8 lines
drivers/net/ethernet/cortina/cs752x_ne.c new file +8 -0
+	/* This engine retires through RPTR; completed descriptors keep OWN set. */
+	while (txq->tail != rptr) {
+		buf = &txq->bufs[txq->tail];
+		if (buf->len) {
+			if (buf->page)
+				dma_unmap_page(ne->dev, buf->dma, buf->len,
+					       DMA_TO_DEVICE);
+			else

drivers/net/ethernet/cortina/cs752x_ne.c line 891

Quoted 10 lines
drivers/net/ethernet/cortina/cs752x_ne.c new file +10 -0
+				dma_unmap_single(ne->dev, buf->dma, buf->len,
+						 DMA_TO_DEVICE);
+			buf->len = 0;
+		}
+		if (buf->skb) {
+			dev_consume_skb_any(buf->skb);
+			buf->skb = NULL;
+		}
+		txq->tail = (txq->tail + 1) & (CS_NE_TX_DESC_NUM - 1);
+	}

[Severity: Medium]
Can holding the shared ne->txq.lock across DMA mapping, unmapping, and SKB freeing cause excessive multi-port contention and data races?

cs_ne_tx_complete() holds ne->txq.lock while unmapping up to 1023 descriptors and calling dev_consume_skb_any(), while cs_ne_start_xmit() and cs_ne_xmit_sg() hold the same device-wide lock across dma_map_single() and skb_frag_dma_map(). In addition, cs_ne_xmit_sg() advances txq->head per fragment inside the mapping loop before writing DMA_LSO_TXQ_WPTR(0), exposing intermediate values to lockless READ_ONCE(txq->head) checks in cs_ne_tx_reap() and triggering spurious lock contention across all three ports.

[ ... ]

drivers/net/ethernet/cortina/cs752x_ne.c line 960

Quoted 10 lines
drivers/net/ethernet/cortina/cs752x_ne.c new file +10 -0
+static void cs_ne_tx_reap(struct cs_ne *ne)
+{
+	struct cs_ne_txq *txq = &ne->txq;
+
+	if (READ_ONCE(txq->tail) == READ_ONCE(txq->head))
+		return;
+	spin_lock(&txq->lock);
+	cs_ne_tx_complete(ne);
+	spin_unlock(&txq->lock);
+}

[Severity: Low]
Are the plain writes to txq->tail, txq->head, and txq->fault a data race with the lockless READ_ONCE() checks here and in cs_ne_open()?

cs_ne_tx_complete(), cs_ne_xmit_sg(), and cs_ne_start_xmit() update txq->tail, txq->head, and txq->fault with plain assignments, which will trigger KCSAN data-race warnings against READ_ONCE(txq->tail), READ_ONCE(txq->head), and READ_ONCE(ne->txq.fault). Pairing those writes with WRITE_ONCE() (and publishing txq->head once an SG frame is fully mapped) would resolve this.

[ ... ]

drivers/net/ethernet/cortina/cs752x_ne.c line 999

Quoted 4 lines
drivers/net/ethernet/cortina/cs752x_ne.c new file +4 -0
+	if (!valid) {
+		ndev->stats.rx_errors++;
+		goto recycle;
+	}

[Severity: Low]
Should these ndev->stats increments use DEV_STATS_INC()?

cs_ne_probe_port() sets NETDEV_PCPU_STAT_TSTATS without ndo_get_stats64 or ndo_get_stats, so dev_get_stats() reads dev->stats locklessly via netdev_stats_to_stats64() using atomic_long_read(). Plain ++ updates to rx_errors, rx_dropped, rx_fifo_errors, and tx_dropped across cs_ne_rx_packet(), cs_ne_rx_poll(), cs_ne_xmit_sg(), and cs_ne_start_xmit() race with those readers under CONFIG_KCSAN_STRICT.

Quoted 5 lines
drivers/net/ethernet/cortina/cs752x_ne.c new file +5 -0
+	skb = napi_alloc_skb(&port->napi, total);
+	if (!skb) {
+		ndev->stats.rx_dropped++;
+		goto recycle;
+	}

drivers/net/ethernet/cortina/cs752x_ne.c line 1014

Quoted 10 lines
drivers/net/ethernet/cortina/cs752x_ne.c new file +10 -0
+	remaining = total;
+	for (i = 0; i < nbufs && remaining; i++) {
+		seg = min_t(u32, remaining, CS_NE_BUF_DATA_MAX - (off & 0xff));
+		data = cs_ne_rx_buf_cpu(ne, bufs[i], off, seg);
+		if (!data)
+			break;
+		skb_put_data(skb, data, seg);
+		remaining -= seg;
+		off = CS_NE_BUF_HDR_OFF;
+	}

[Severity: Medium]
Will napi_alloc_skb(&port->napi, total) force order-2 atomic allocations for jumbo frames?

cs_ne_probe_port() sets ndev->max_mtu up to 8988 bytes, allowing total up to CS_NE_MAX_PKT_LEN (9022 bytes). Lengths above SKB_WITH_OVERHEAD(PAGE_SIZE) bypass the NAPI page-frag cache and fall back to GFP_ATOMIC order-2 kmalloc-16k allocations, which can cause rx_dropped bursts under fragmentation on a 512 MiB system instead of attaching order-0 page fragments.

[ ... ]

Quoted 4 lines
drivers/net/ethernet/cortina/cs752x_ne.c new file +4 -0
+		next = FIELD_GET(XR_NEXT_LINK, w1);
+		if (next == wr &&
+		    (ni_rd(ne, NI_CPUXRAM_CPU_STA_RX(port->id)) & NI_XRAM_PTR_MASK) == wr) {
+			/*

drivers/net/ethernet/cortina/cs752x_ne.c line 1074

Quoted 10 lines
drivers/net/ethernet/cortina/cs752x_ne.c new file +10 -0
+			 * The next link reaches the unchanged hardware write pointer:
+			 * this is the current tail packet. Retain the vendor's 16us
+			 * DDR-arrival guard before reading its header and payload.
+			 * NAPI softirq context cannot use a sleeping delay here.
+			 */
+			udelay(CS_NE_RX_TAIL_SETTLE_US);
+		}
+		rd = next;
+		cs_ne_rx_packet(port, desc, w1);
+		done++;

[Severity: Medium]
Should cs_ne_rx_poll() update wr from the refreshed NI_CPUXRAM_CPU_STA_RX(port->id) read when next == wr?

When hardware has already queued newer packets past wr, discarding the re-read value causes rd = next to equal the stale wr and exit the loop with done < budget. This flushes GRO early via napi_complete_done() and triggers an immediate hard interrupt and NAPI reschedule for packets already visible in XRAM.

[ ... ]

Quoted 5 lines
drivers/net/ethernet/cortina/cs752x_ne.c new file +5 -0
+	if (done < budget && napi_complete_done(napi, done)) {
+		spin_lock_irqsave(&ne->rx_lock, flags);
+		if (READ_ONCE(port->opened) && !ne->rx_stopping) {
+			/*
+			 * Keep DMA-owned buffers untouched and the IRQ masked.

drivers/net/ethernet/cortina/cs752x_ne.c line 1095

Quoted 10 lines
drivers/net/ethernet/cortina/cs752x_ne.c new file +10 -0
+			 * A delayed poll also handles completion without a new edge.
+			 */
+			if (defer)
+				mod_delayed_work(system_wq, &port->rx_owned_retry,
+						 msecs_to_jiffies(1));
+			else
+				ni_wr(ne, NI_CPUXRAM_RXPKT_INTENABLE(port->id), 1);
+		}
+		spin_unlock_irqrestore(&ne->rx_lock, flags);
+	}

[Severity: Medium]
Can re-enabling NI_CPUXRAM_RXPKT_INTENABLE(port->id) without clearing NI_CPUXRAM_RXPKT_INTERRUPT fire a spurious level-triggered interrupt after every multi-packet burst?

cs_ne_rx_irq() clears the W1C NI_CPUXRAM_RXPKT_INTERRUPT bit before NAPI runs, so any packet arriving before cs_ne_rx_poll() reads NI_CPUXRAM_CPU_STA_RX re-latches it while INTENABLE is masked. After draining those packets and calling napi_complete_done(), enabling INTENABLE with the stale latch still set immediately asserts the IRQ_TYPE_LEVEL_HIGH GIC SPI and schedules an empty 0-packet poll.

Clearing NI_CPUXRAM_RXPKT_INTERRUPT after updating NI_CPUXRAM_CPU_CFG_RX and re-checking NI_CPUXRAM_CPU_STA_RX != rd before re-enabling INTENABLE would avoid both spurious and missed interrupts.

[ ... ]

Quoted 15 lines
drivers/net/ethernet/cortina/cs752x_ne.c new file +15 -0
+static void cs_ne_tx_desc(struct cs_ne_txq *txq, int port_id, dma_addr_t dma,
+			  u32 len, u32 total, bool sof, bool eof)
+{
+	u32 *desc = txq->desc + txq->head * 8;
+	u32 word0, word3;
+
+	word3 = TX_LSO_SEGMENT_EN | CS_NE_MAX_PKT_LEN;
+	if (eof && total < CS_NE_MIN_PKT_LEN)
+		word3 |= TX_LSO_IP_LENFIX_EN;
+	word0 = TX_DESC_OWN | FIELD_PREP(TX_DESC_LEN, len);
+	if (sof)
+		word0 |= TX_DESC_SOF;
+	if (eof)
+		word0 |= TX_DESC_EOF;
+

drivers/net/ethernet/cortina/cs752x_ne.c line 1123

Quoted 10 lines
drivers/net/ethernet/cortina/cs752x_ne.c new file +10 -0
+	desc[1] = dma;
+	desc[2] = sof ? total << 16 : 0;
+	desc[3] = word3;
+	desc[4] = CS_NE_HDRA_CPU_PKT | FIELD_PREP(TX_HDRA_DVOQ, port_id * 8);
+	desc[5] = 0;
+	desc[6] = 0;
+	desc[7] = 0;
+	dma_wmb();
+	desc[0] = word0;
+}

[Severity: Medium]
Will writing host-endian u32 words directly to txq->desc break TX on big-endian kernels?

CS7542_ETHERNET can be built on big-endian configurations such as ARM BE8, and cs_ne_dma_init() does not enable a big-endian descriptor mode. Both cs_ne_tx_desc() and cs_ne_start_xmit() write raw host-endian values into coherent DMA memory instead of typing txq->desc as __le32 * and converting descriptor words with cpu_to_le32().

[ ... ]

Quoted 5 lines
drivers/net/ethernet/cortina/cs752x_ne.c new file +5 -0
+	word3 = TX_LSO_SEGMENT_EN | CS_NE_MAX_PKT_LEN;
+	if (len < CS_NE_MIN_PKT_LEN)
+		word3 |= TX_LSO_IP_LENFIX_EN;
+
+	desc = txq->desc + txq->head * 8;

drivers/net/ethernet/cortina/cs752x_ne.c line 1277

Quoted 10 lines
drivers/net/ethernet/cortina/cs752x_ne.c new file +10 -0
+	desc[1] = dma;
+	desc[2] = len << 16;
+	desc[3] = word3;
+	desc[4] = CS_NE_HDRA_CPU_PKT | FIELD_PREP(TX_HDRA_DVOQ, port->id * 8);
+	desc[5] = 0;
+	desc[6] = 0;
+	desc[7] = 0;
+	dma_wmb();
+	desc[0] = TX_DESC_OWN | TX_DESC_SOF | TX_DESC_EOF |
+		  FIELD_PREP(TX_DESC_LEN, len);

[Severity: Low]
Can this open-coded descriptor setup reuse cs_ne_tx_desc(txq, port->id, dma, len, len, true, true)?

Similarly, cs_ne_tx_complete(), cs_ne_xmit_sg(), and cs_ne_start_xmit() open-code the ring free-space expression instead of calling cs_ne_tx_free(txq), and cs_ne_dma_init() redundantly re-initializes txq->ne, txq->stopping, and txq->lock after cs_ne_probe() already did.

[ ... ]

Quoted 5 lines
drivers/net/ethernet/cortina/cs752x_ne.c new file +5 -0
+	port = netdev_priv(ndev);
+	port->ne = ne;
+	port->ndev = ndev;
+	port->np = np;
+	port->id = id;

[ ... ]

drivers/net/ethernet/cortina/cs752x_ne.c line 1578

Quoted 1 line
drivers/net/ethernet/cortina/cs752x_ne.c new file +1 -0
+	ndev->dev.of_node = np;

[Severity: Medium]
Does storing np in port->np and ndev->dev.of_node need of_node_get(np) with a matching of_node_put(port->np) in cs_ne_port_cleanup()?

cs_ne_probe() iterates child nodes with for_each_available_child_of_node(), which drops its reference to np when the loop advances or exits. port->np is later passed to phylink_of_phy_connect() in cs_ne_open(), so without taking a reference it risks a use-after-free under CONFIG_OF_DYNAMIC overlay removal.

[ ... ]

Quoted 5 lines
drivers/net/ethernet/cortina/cs752x_sch_tm.c new file +0 -0
new file mode 100644
index 0000000000000..5886c1bc57a86

[ ... ]

Quoted 19 lines
drivers/net/ethernet/cortina/cs752x_sch_tm.c new file +19 -0
+	for (port = 0; port < SCH_PORT_NO; port++) {
+		cpu_port = port >= SCH_CPU_PORT0 ? port - SCH_CPU_PORT0 : 0;
+
+		ret = cs752x_sch_enable_port(dev, sch, port);
+		if (ret)
+			return ret;
+		ret = cs752x_sch_set_port_burst(dev, sch, port, 0);
+		if (ret)
+			return ret;
+		ret = cs752x_sch_bypass_shaper(dev, sch, port + SCH_LT_BASE_ID, 0);
+		if (ret)
+			return ret;
+		ret = cs752x_sch_bypass_shaper(dev, sch, port + SCH_ST_BASE_ID, 0);
+		if (ret)
+			return ret;
+
+		for (q = 0; q < SCH_MAX_PORT_QUEUE; q++) {
+			ret = cs752x_sch_enable_voq_drr(dev, sch,
+							port * SCH_MAX_PORT_QUEUE + q,

drivers/net/ethernet/cortina/cs752x_sch_tm.c line 403

Quoted 10 lines
drivers/net/ethernet/cortina/cs752x_sch_tm.c new file +10 -0
+							SCH_DEFAULT_QUANTA, cpu_port);
+			if (ret)
+				return ret;
+			ret = cs752x_sch_bypass_shaper(dev, sch,
+						       port + SCH_DRR_BASE_ID,
+						       cpu_port);
+			if (ret)
+				return ret;
+		}
+	}

[Severity: Medium]
Is cs752x_sch_bypass_shaper() inside the queue loop supposed to bypass the per-VOQ shaper (port * SCH_MAX_PORT_QUEUE + q) rather than repeating port + SCH_DRR_BASE_ID eight times per port?

Because port + SCH_DRR_BASE_ID does not depend on q, this sends 98 redundant atomic scheduler commands for the per-port DRR shapers while leaving all 112 per-VOQ shapers (IDs 0..111) unprogrammed. Also, the per-port LT and ST shaper bypass calls pass literal 0 instead of the computed cpu_port.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
author
#4 lore raw

Re: [PATCH net-next v8 2/3] net: cortina: Add CS7542 CPU network datapath

Thanks for the review. v9 disables netpoll for the shared TX ring, takes a reference on each port's DT node until after phylink teardown, uses GFP_KERNEL for the probe-time RX pool, and uses DEV_STATS_INC() for the error and drop counters.

The linear and scatter-gather TX paths share the descriptor helper and write the DMA words in little-endian order. The head is published once, after the complete frame has been mapped. Updates to head, tail and fault use WRITE_ONCE() to pair with the lockless reads. The shared lock still protects mapping and completion against per-port TX and teardown.

RX now uses the refreshed XRAM write pointer. The IRQ handler still acknowledges the latch, so a stale latch can cause an extra empty poll. The current RX lock and jumbo skb allocation are retained. The receive path copies from a persistent DMA pool, and transferring those pages to the stack would also require changing how the pool is replenished.

The DRR bypass command addresses the port shaper, so v9 issues it once per port, outside the queue loop. The per-queue DRR enable commands and the existing LT/ST programming are retained.

I'll post the full v9 series separately.

Thanks,
Fil

author
#5 lore raw

PATCH v8 3/3 MAINTAINERS: Add CS7542 network engine support

In reply to Fil Dunsky

Cover the Ethernet binding and network engine datapath. The shared global reset provider is maintained separately under global control.

---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
index 27bfe399c..7268b0796 100644
@@ -7213,6 +7213,13 @@ M:	Jaya Kumar <[email protected]>
 S:	Maintained
 F:	sound/pci/cs5535audio/
 
+CS7542 CORTINA NETWORK ENGINE
+M:	Fil Dunsky <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/net/cortina,cs7542-ethernet.yaml
+F:	drivers/net/ethernet/cortina/cs752x_*
+
 CTU CAN FD DRIVER
 M:	Pavel Pisa <[email protected]>
 M:	Ondrej Ille <[email protected]>
Signature · 1 line
2.53.0