From: Yao Zi <me@ziyao.cc>
To: Zixian Zeng <sycamoremoon376@gmail.com>,
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>, Yao Zi <me@ziyao.cc>
Subject: Re: [PATCH v3 1/2] net: spacemit: k1: add Ethernet MAC driver
Date: Sat, 21 Nov 2026 18:31:20 +0000 [thread overview]
Message-ID: <awHjeCEz4XVJmLr_@pie> (raw)
In-Reply-To: <awB7rFETr-jVP5_b@pie>
On Fri, Nov 20, 2026 at 04:56:12PM +0000, 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 int k1_emac_send(struct udevice *dev, void *packet, int length)
> > +{
> > + struct k1_emac_priv *priv = dev_get_priv(dev);
> > + unsigned int index = priv->tx_index;
> > + struct k1_emac_desc *desc = k1_desc_at(priv->tx_desc, index);
> > + u8 *buffer = k1_tx_buf_at(priv, index);
> > + ulong start;
> > +
> > + if (length <= 0 || length > K1_DMA_BUF_SIZE)
> > + return -EMSGSIZE;
> > +
> > + k1_desc_invalidate(desc);
> > + if (desc->status & K1_TX_DESC_OWN)
> > + return -EBUSY;
> > +
> > + memcpy(buffer, packet, length);
> > + flush_dcache_range((ulong)buffer,
> > + ALIGN((ulong)buffer + length, ARCH_DMA_MINALIGN));
> > +
> > + /* Clear stale state before handing the descriptor to DMA. */
> > + writel(K1_DMA_STATUS_TX_DESC_UNAVAILABLE, priv->base + K1_DMA_STATUS);
> > + /* Complete the W1C write before asking the DMA engine to resume. */
> > + readl(priv->base + K1_DMA_STATUS);
> > +
> > + desc->buffer_addr1 = priv->tx_buf_dma[index];
> > + desc->buffer_addr2 = 0;
> > + desc->control = FIELD_PREP(K1_TX_DESC_BUFFER_SIZE, length) |
> > + K1_TX_DESC_FIRST | K1_TX_DESC_LAST;
> > + if (index == K1_TX_DESC_COUNT - 1)
> > + desc->control |= K1_TX_DESC_END_RING;
> > + desc->status = K1_TX_DESC_OWN;
> > + /* Complete descriptor stores before cleaning its cache line. */
> > + mb();
>
> Probably redundant barrier since RISC-V guarantees order between
> overlapping stores...
I think I shouldn't review this in such a hurry. Quoting the
specification,
> For cache-block management instructions, the resulting invalidate,
> clean, and flush operations behave as stores in the PPO rules subject
> to one additional overlapping address rule.
Stores to the descriptor before the mb() overlap with the flush after
it, thus should be naturally ordered.
[...]
> > +static int k1_emac_recv(struct udevice *dev, int flags, uchar **packetp)
> > +{
> > + struct k1_emac_priv *priv = dev_get_priv(dev);
> > + struct k1_emac_desc *desc;
> > + u32 status, length;
> > + u8 *buffer;
> > + unsigned int checked = 0;
> > +
> > + if (priv->rx_pending)
> > + return -EBUSY;
> > +
> > + while (checked++ < K1_RX_DESC_COUNT) {
> > + desc = k1_desc_at(priv->rx_desc, priv->rx_index);
> > + k1_desc_invalidate(desc);
> > + status = desc->status;
> > + if (status & K1_RX_DESC_OWN)
> > + return -EAGAIN;
> > +
> > + length = FIELD_GET(K1_RX_DESC_FRAME_LEN, status);
> > + if ((status & (K1_RX_DESC_FIRST | K1_RX_DESC_LAST)) ==
> > + (K1_RX_DESC_FIRST | K1_RX_DESC_LAST) &&
> > + !(status & K1_RX_DESC_ERRORS) && length > ETH_FCS_LEN &&
> > + length <= K1_DMA_BUF_SIZE) {
> > + buffer = k1_rx_buf_at(priv, priv->rx_index);
> > + k1_buffer_invalidate(buffer);
> > + /* Complete invalidation before exposing the received frame. */
> > + mb();
>
> RISC-V guarantees that cache management operations couldn't be reordered
> with later stores,
Here's a typo, s/stores/loads/. Cache management operations indeed
couldn't be re-ordered with later overlapping stores, but here only
order between cache management operations and later loads matters, since
it's a RX buffer.
> > Specifically, if a precedes b in program order, then a will precede b
> > in the global memory order if:
> > a is an invalidate, clean, or flush, b is a load, and a and b
> > access overlapping memory addresses
>
> Thus this mb() is redundant. Any access to buffer must be ordered after
> this invalidation.
This explanation is correct though.
[...]
--
Thanks,
Yao Zi
Meow-mrrp-mrow, I'm a cat.
next prev parent reply other threads:[~2026-11-21 18:32 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 [this message]
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
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=awHjeCEz4XVJmLr_@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.