All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yao Zi <me@ziyao.cc>
To: Zixian Zeng <sycamoremoon376@gmail.com>, Yao Zi <me@ziyao.cc>,
	u-boot@lists.u-boot-project.org, u-boot-spacemit@groups.io
Cc: Tom Rini <trini@konsulko.com>,
	Jerome Forissier <jerome.forissier@arm.com>,
	Huan Zhou <pericycle.cc@gmail.com>,
	Guodong Xu <guodong.xu@riscstar.com>,
	Quentin Schulz <quentin.schulz@cherry.de>,
	Julien Stephan <jstephan@baylibre.com>,
	Johan Jonker <jbx6244@gmail.com>,
	David Lechner <dlechner@baylibre.com>,
	Raymond Mao <raymond.mao@riscstar.com>,
	Eric Chung <eric.chung@riscstar.com>, Yixun Lan <dlan@kernel.org>,
	James Hilliard <james.hilliard1@gmail.com>,
	Guodong Xu <guodong@riscstar.com>, E Shattow <e@freeshell.de>,
	Dave Klotz <DaveWK225@protonmail.com>
Subject: Re: [PATCH v3 1/2] net: spacemit: k1: add Ethernet MAC driver
Date: Sun, 22 Nov 2026 17:10:44 +0000	[thread overview]
Message-ID: <awMiFGmDtjhuZ9zx@pie> (raw)
In-Reply-To: <3e0188b3-6191-4ebc-924e-e76807a11241@gmail.com>

On Sun, Nov 22, 2026 at 08:37:30PM +0800, Zixian Zeng wrote:
> Hi Yao Zi,
> 
> On 2026/11/22 16:10, Yao Zi wrote:
> > On Sun, Nov 22, 2026 at 02:23:56PM +0800, Zixian Zeng wrote:
> > > Hi, Yao Zi,
> > > 
> > > Thank you for the detailed review and the follow-up clarifications. I
> > > went through both replies against the RISC-V CMO and RVWMO specifications,
> > > the U-Boot cache/MMIO implementations, and the Linux K1 driver used as the
> > > reference for this port.
> > > 
> > > On 2026/11/21 00:56, Yao Zi wrote:
> > > > On Fri, Nov 20, 2026 at 02:35:56PM +0800, Zixian Zeng wrote:
> > > > > Add Ethernet MAC driver support for the SpacemiT K1 SoC. The driver
> > > > > supports RGMII and RMII interfaces, synchronous transmission, and exposes
> > > > > the integrated MDIO controller through the MDIO uclass.
> > > > > 
> > > > > The register definitions, descriptor layout, MDIO protocol, RGMII delay
> > > > > line handling and hardware initialisation sequences are derived from the
> > > > > mainline Linux commit bfec6d7f2001 (net: spacemit: Add K1 Ethernet MAC).
> > > > > 
> > > > > Link: https://lore.kernel.org/all/20250914-net-k1-emac-v12-0-65b31b398f44@iscas.ac.cn/
> > > > > Tested-by: Dave Klotz <DaveWK225@protonmail.com>
> > > > > Tested-by: Yixun Lan <dlan@kernel.org> # MusePi Pro
> > > > > Signed-off-by: Zixian Zeng <sycamoremoon376@gmail.com>
> > > > > ---
> > > > >    drivers/net/Kconfig            |   1 +
> > > > >    drivers/net/Makefile           |   1 +
> > > > >    drivers/net/spacemit/Kconfig   |  14 +
> > > > >    drivers/net/spacemit/Makefile  |   3 +
> > > > >    drivers/net/spacemit/k1_emac.c | 957 +++++++++++++++++++++++++++++++++++++++++
> > > > >    5 files changed, 976 insertions(+)
> > 
> > [...]
> > 
> > > > > +static void k1_emac_prepare_rx(struct k1_emac_priv *priv, unsigned int index)
> > > > > +{
> > > > > +	struct k1_emac_desc *desc = k1_desc_at(priv->rx_desc, index);
> > > > > +	u8 *buffer = k1_rx_buf_at(priv, index);
> > > > > +
> > > > > +	k1_buffer_flush(buffer);
> > > > 
> > > > Does flushing the RX buffer really make a difference on the hardware's
> > > > behavior?
> > > 
> > > The purpose is to prevent dirty CPU cache lines from a previous use from
> > > being written back over a later DMA receive.
> > > 
> > > The buffer is passed directly to the U-Boot network stack before
> > > free_pkt(). In particular, ping_receive() modifies the received Ethernet,
> > > IP and ICMP headers in place when answering an ICMP echo request, before
> > > copying the reply to a TX buffer. Consequently, an RX buffer can contain
> > > dirty cache lines when it is recycled.
> > > 
> > > If cache maintenance is omitted before returning the buffer,
> > > the following sequence of events may occur:
> > > 
> > > 1. The CPU modifies an old packet A, leaving the updated content A′ in a "dirty" cache line.
> > > 2. The driver hands the buffer over to the DMA, which then writes a new packet B into memory.
> > > 3. The CPU’s dirty cache line is subsequently evicted, causing A′ to be written back to the same memory location.
> > > 4. Part of the new packet B is overwritten.
> > 
> > Oh, this makes sense. Please replace flush with a clean though.
> 
> OK, do you mean using a clean-only cache operation here, or just renaming
> the helper from k1_buffer_flush() to k1_buffer_flush() to reflect its purpose?
> The current RISC-V implementation does not expose a public range clean API.

Oops, I didn't realize this when writing this comment. Then it's okay to
keep the code as-is, with a comment added to explain its purpose.

> > > The Linux RISC-V DMA implementation at the reference commit also performs
> > > a clean for DMA_FROM_DEVICE before device ownership, followed by an
> > > invalidate when ownership returns to the CPU. The Linux K1 driver's
> > > dma_map_single(..., DMA_FROM_DEVICE) provides that preparation implicitly.
> > > 
> > > I therefore plan to retain the pre-DMA buffer maintenance and add a short
> > > comment explaining the dirty-line case. The current flush supplies the
> > > required clean as well as invalidation.
> > > 
> > > > > +	desc->control = FIELD_PREP(K1_RX_DESC_BUFFER_SIZE, K1_DMA_BUF_SIZE);
> > > > > +	if (index == K1_RX_DESC_COUNT - 1)
> > > > > +		desc->control |= K1_RX_DESC_END_RING;
> > > > > +	desc->buffer_addr1 = priv->rx_buf_dma[index];
> > > > > +	desc->buffer_addr2 = 0;
> > > > > +	desc->status = K1_RX_DESC_OWN;
> > > > > +}

[...]

> > > > > +	k1_desc_flush(desc);
> > > > > +	writel(1, priv->base + K1_DMA_TX_POLL_DEMAND);
> > > > > +
> > > > > +	start = get_timer(0);
> > > > > +	do {
> > > > 
> > > > The could would be simpler if you use a loop simply bounded by retry
> > > > counts.
> > > 
> > > A retry-bounded loop would work if the intended limit is a number of
> > > attempts. However, I prefer to retain an elapsed-time timeout here, thanks.
> > 
> > Why? The code would look simpler with the change, like
> > 
> > 	for (; retry < K1_TX_TIMEOUT_MS / 10; retry++) {
> > 		/* ... */
> > 		udelay(10);
> > 	}
> 
> Just a preference :-) I will switch to a retry-bounded loop in next revision.
> With udelay(10), I will calculate the retry limit as K1_TX_TIMEOUT_MS * 1000 / 10,
> which converting ms to us.

Just FYI, we have USEC_PER_MSEC, which makes the code's purpose more
explicit.

> > > > > +		k1_desc_invalidate(desc);
> > > > > +		/*
> > > > > +		 * OWN is cleared before transmission finishes. Descriptor
> > > > > +		 * unavailable is raised after DMA completes the packet and moves
> > > > > +		 * to the next CPU-owned descriptor.
> > > > > +		 */
> > > > > +		if (!(desc->status & K1_TX_DESC_OWN) &&
> > > > > +		    (readl(priv->base + K1_DMA_STATUS) &
> > > > > +		     K1_DMA_STATUS_TX_DESC_UNAVAILABLE)) {
> > > > > +			priv->tx_index = (index + 1) % K1_TX_DESC_COUNT;
> > > > > +			return 0;
> > > > > +		}
> > > > > +		udelay(10);
> > > > > +	} while (get_timer(start) <= K1_TX_TIMEOUT_MS);
> > 
> > [...]
> > 
> 
> Best regards,
> Zixian
> 

-- 
Thanks,
Yao Zi

Meow-mrrp-mrow, I'm a cat.

  reply	other threads:[~2026-11-22 17:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  6:35 [PATCH v3 0/2] net: add SpacemiT K1 EMAC support Zixian Zeng
2026-11-20  6:35 ` [PATCH v3 1/2] net: spacemit: k1: add Ethernet MAC driver Zixian Zeng
2026-11-20 16:56   ` Yao Zi
2026-11-21 18:31     ` Yao Zi
2026-11-22  6:23     ` Zixian Zeng
2026-11-22  8:10       ` Yao Zi
2026-11-22 12:37         ` Zixian Zeng
2026-11-22 17:10           ` Yao Zi [this message]
2026-11-20  6:35 ` [PATCH v3 2/2] configs: spacemit: k1: enable Ethernet support Zixian Zeng

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=awMiFGmDtjhuZ9zx@pie \
    --to=me@ziyao.cc \
    --cc=DaveWK225@protonmail.com \
    --cc=dlan@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=e@freeshell.de \
    --cc=eric.chung@riscstar.com \
    --cc=guodong.xu@riscstar.com \
    --cc=guodong@riscstar.com \
    --cc=james.hilliard1@gmail.com \
    --cc=jbx6244@gmail.com \
    --cc=jerome.forissier@arm.com \
    --cc=jstephan@baylibre.com \
    --cc=pericycle.cc@gmail.com \
    --cc=quentin.schulz@cherry.de \
    --cc=raymond.mao@riscstar.com \
    --cc=sycamoremoon376@gmail.com \
    --cc=trini@konsulko.com \
    --cc=u-boot-spacemit@groups.io \
    --cc=u-boot@lists.u-boot-project.org \
    /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.