All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Fil Dunsky" <filipp.dunsky@gmail.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH net-next v2 2/3] net: cortina: Add CS7542 CPU network datapath
Date: Thu, 26 Nov 2026 10:36:49 +0000	[thread overview]
Message-ID: <sashiko-outbox-235301@kernel.org> (raw)
In-Reply-To: <20261125-b4-cs7542-ethernet-v2-2-d0ea3c6eb375@gmail.com>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] net: cortina: RX buffer leak in cs_ne_rx_poll() when FCS spans
  buffers
- [Medium] net: cortina: missing TX_DESC_OWN check in
  cs_ne_tx_complete()
- [Medium] net: cortina: RX stall in cs_ne_rx_poll() after XR_OWNERSHIP
  break
- [Medium] net: cortina: BM bypass bits cleared after init in
  cs752x_tm_bm_init()
- [Medium] net: cortina: shared MAC prefix registers clobbered in
  cs_ne_set_hw_addr()
--

commit 6a57a4063dd740b5d790fca88be11e9fe060a608
Author: Fil Dunsky <filipp.dunsky@gmail.com>

net: cortina: Add CS7542 CPU network datapath

This commit adds the Cortina CS7542 three-GMAC network engine driver with
phylink support, per-port NAPI RX, a shared TX ring, and FE, QM, TM, and
SCH initialization.

> diff --git a/drivers/net/ethernet/cortina/cs752x_ne.c b/drivers/net/ethernet/cortina/cs752x_ne.c
> new file mode 100644
> index 0000000000000..081b4207928e4
> --- /dev/null
> +++ b/drivers/net/ethernet/cortina/cs752x_ne.c
[ ... ]
> +static int cs_ne_rx_poll(struct napi_struct *napi, int budget)
> +{
[ ... ]
> +	wr = ni_rd(ne, NI_CPUXRAM_CPU_STA_RX(port->id)) & NI_XRAM_PTR_MASK;
> +	rd = port->rd;
> +	while (rd != wr && done < budget) {
> +		desc = ne->xram + rd * 8;
> +		w1 = readl(desc + 4);
> +		if (w1 & XR_OWNERSHIP) {
> +			ndev->stats.rx_fifo_errors++;
> +			break;
> +		}
> +		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) {
> +			/*
> +			 * 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);
> +		}
> +		hdre_hi = readl(desc + 8);
> +		hdre_lo = readl(desc + 12);
> +		rd = next;
> +		pkt_size = FIELD_GET(HDRE_PKT_SIZE, hdre_lo);
> +		off = CS_NE_BUF_HDR_OFF + 8 + 16 + 2;
> +		total = pkt_size > 20 ? pkt_size - 20 : 0;
> +		valid = total >= ETH_HLEN && total <= CS_NE_MAX_PKT_LEN;
> +		/* Drop policy must not hide trailing buffers in this descriptor. */
> +		nbufs = 1;
> +		if (total > CS_NE_BUF_DATA_MAX - (off & 0xff))
> +			nbufs += DIV_ROUND_UP(total - (CS_NE_BUF_DATA_MAX - (off & 0xff)),
> +					      CS_NE_BUF_DATA_MAX);

[Severity: High]
Does computing nbufs from total (which subtracts the 4-byte FCS) rather
than total + ETH_FCS_LEN leak the trailing RX buffer when the FCS crosses
a buffer boundary?

The first buffer holds CS_NE_BUF_DATA_MAX - (off & 0xff) = 3558 bytes of
frame data, so when total is 3555..3558 bytes (or 7139..7142 bytes at the
next boundary), QM writes the trailing FCS bytes into an extra buffer that
cs_ne_rx_poll() never claims or recycles, leaving it stuck in CS_NE_RX_HW
until the port's RX pool is exhausted.

[ ... ]
> +	cs_ne_rx_kick(ne);
> +	ni_wr(ne, NI_CPUXRAM_CPU_CFG_RX(port->id), rd);
> +	port->rd = rd;
> +	if (done < budget && napi_complete_done(napi, done)) {
> +		spin_lock_irqsave(&ne->rx_lock, flags);
> +		if (READ_ONCE(port->opened) && !ne->rx_stopping)
> +			ni_wr(ne, NI_CPUXRAM_RXPKT_INTENABLE(port->id), 1);
> +		spin_unlock_irqrestore(&ne->rx_lock, flags);
> +	}
> +	return done;
> +}

[Severity: Medium]
Can breaking out of the loop when XR_OWNERSHIP is set and then calling
napi_complete_done() stall RX on this port?

cs_ne_rx_irq() already cleared NI_CPUXRAM_RXPKT_INTERRUPT(port->id) before
scheduling NAPI, and an already-queued XRAM descriptor does not generate a
new interrupt edge, so completing NAPI while rd != wr leaves that
descriptor unread until another packet arrives.

[ ... ]
> +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;
> +	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;
> +	}
> +	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
> +				dma_unmap_single(ne->dev, buf->dma, buf->len,
> +						 DMA_TO_DEVICE);
> +			buf->len = 0;
> +		}

[Severity: Medium]
Should cs_ne_tx_complete() verify that TX_DESC_OWN is clear in
txq->desc[txq->tail * 8] before unmapping buf->dma and consuming buf->skb?

The commit message notes that the driver never releases descriptors whose
hardware ownership remains set, and if DMA_LSO_TXQ_RPTR(0) advances when
the descriptor is fetched before completion writeback clears TX_DESC_OWN,
this loop will unmap an in-flight buffer.

[ ... ]
> +static void cs_ne_set_hw_addr(struct cs_ne_port *port)
> +{
> +	struct cs_ne *ne = port->ne;
> +	const u8 *a = port->ndev->dev_addr;
> +
> +	ni_wr(ne, NI_MAC_ADDR0, a[0] | (a[1] << 8) | (a[2] << 16) | (a[3] << 24));
> +	ni_rmw(ne, NI_MAC_ADDR1, 0xff, a[4]);
> +	ni_rmw(ne, NI_ETH_MAC_CONFIG2(port->id), 0xff, a[5]);
> +}

[Severity: Medium]
Does cs_ne_set_hw_addr() clobber the upper five MAC address bytes of the
other ports?

NI_MAC_ADDR0 and NI_MAC_ADDR1 are shared across all three GMACs while only
NI_ETH_MAC_CONFIG2(port->id) is per-port, so probing multiple ports with
different 5-byte prefixes (such as the eth_hw_addr_random() fallback in
cs_ne_probe_port()) or changing one port's address via
cs_ne_set_mac_address() silently overwrites the hardware MAC prefix of the
sibling ports.

> diff --git a/drivers/net/ethernet/cortina/cs752x_sch_tm.c b/drivers/net/ethernet/cortina/cs752x_sch_tm.c
> new file mode 100644
> index 0000000000000..da156349678d4
> --- /dev/null
> +++ b/drivers/net/ethernet/cortina/cs752x_sch_tm.c
[ ... ]
> +static int cs752x_tm_bm_init(struct device *dev, void __iomem *tm)
> +{
[ ... ]
> +	cfg = readl(tm + TM_BM_CONFIG_0);
> +	cfg &= ~(TM_BM_CONFIG_0_DISABLE |
> +		 TM_BM_CONFIG_0_RECALCULATE_GLOBAL_BUFFERS_USED |
> +		 TM_BM_CONFIG_0_BM2_BYPASS_CA_PROCESS |
> +		 TM_BM_CONFIG_0_BM2_BYPASS_DEST_PORT_PROCESS |
> +		 TM_BM_CONFIG_0_BM2_BYPASS_VOQ_PROCESS |
> +		 TM_BM_CONFIG_0_BM1_BYPASS_CA_PROCESS |
> +		 TM_BM_CONFIG_0_BM1_BYPASS_DEST_PORT_PROCESS |
> +		 TM_BM_CONFIG_0_BM1_BYPASS_VOQ_PROCESS |
> +		 TM_BM_CONFIG_0_ENQUE_HDR_ADJUST |
> +		 TM_BM_CONFIG_0_INIT);
> +
> +	writel(cfg | TM_BM_CONFIG_0_BM1_BYPASS_CA_PROCESS |
> +	       TM_BM_CONFIG_0_BM2_BYPASS_DEST_PORT_PROCESS |
> +	       TM_BM_CONFIG_0_BM2_BYPASS_VOQ_PROCESS |
> +	       TM_BM_CONFIG_0_INIT, tm + TM_BM_CONFIG_0);
> +	ret = cs752x_tm_wait_init_done(dev, tm, TM_BM_STATUS_0,
> +				       TM_BM_STATUS_0_INIT_DONE, "bm");
> +	if (ret)
> +		return ret;
> +
> +	writel(cfg, tm + TM_BM_CONFIG_0);

[Severity: Medium]
Does writing cfg back to TM_BM_CONFIG_0 here clear
TM_BM_CONFIG_0_BM1_BYPASS_CA_PROCESS,
TM_BM_CONFIG_0_BM2_BYPASS_DEST_PORT_PROCESS, and
TM_BM_CONFIG_0_BM2_BYPASS_VOQ_PROCESS right after initialization finishes?
Those three bits are masked out of cfg and only ORed into the
TM_BM_CONFIG_0_INIT write, so deasserting INIT disables the bypasses.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-b4-cs7542-ethernet-v2-0-d0ea3c6eb375@gmail.com?part=2

  parent reply	other threads:[~2026-11-26 10:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 10:36 [PATCH net-next v2 0/3] net: cortina: Add CS7542 network engine support Fil Dunsky via B4 Relay
2026-11-25 10:36 ` Fil Dunsky
2026-11-25 10:36 ` [PATCH net-next v2 1/3] dt-bindings: net: Add Cortina CS7542 network engine Fil Dunsky via B4 Relay
2026-11-25 10:36   ` Fil Dunsky
2026-11-25 10:36 ` [PATCH net-next v2 2/3] net: cortina: Add CS7542 CPU network datapath Fil Dunsky via B4 Relay
2026-11-25 10:36   ` Fil Dunsky
2026-11-25 11:12   ` Philipp Zabel
2026-11-25 11:24     ` Fil Dunsky
2026-11-26 10:36   ` sashiko-bot [this message]
2026-11-25 10:36 ` [PATCH net-next v2 3/3] MAINTAINERS: Add CS7542 network engine support Fil Dunsky via B4 Relay
2026-11-25 10:36   ` Fil Dunsky

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=sashiko-outbox-235301@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=filipp.dunsky@gmail.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

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

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