From: Vivian Wang <wangruikang@iscas.ac.cn>
To: Simon Horman <horms@kernel.org>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
Jakub Kicinski <kuba@kernel.org>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>, Yixun Lan <dlan@gentoo.org>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>,
Philipp Zabel <p.zabel@pengutronix.de>,
Paul Walmsley <paul.walmsley@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>,
Vadim Fedorenko <vadim.fedorenko@linux.dev>,
Junhui Liu <junhui.liu@pigmoral.tech>,
Maxime Chevallier <maxime.chevallier@bootlin.com>,
netdev@vger.kernel.org, devicetree@vger.kernel.org,
linux-riscv@lists.infradead.org, spacemit@lists.linux.dev,
linux-kernel@vger.kernel.org,
Troy Mitchell <troy.mitchell@linux.spacemit.com>,
Vivian Wang <uwu@dram.page>
Subject: Re: [PATCH net-next v9 2/5] net: spacemit: Add K1 Ethernet MAC
Date: Fri, 5 Sep 2025 23:45:29 +0800 [thread overview]
Message-ID: <0605f176-5cdb-4f5b-9a6b-afa139c96732@iscas.ac.cn> (raw)
In-Reply-To: <20250905153500.GH553991@horms.kernel.org>
Hi Simon,
Thanks for the review.
(I have a question about the use of ndev->stats - see below.)
On 9/5/25 23:35, Simon Horman wrote:
> On Fri, Sep 05, 2025 at 07:09:31PM +0800, Vivian Wang wrote:
>> The Ethernet MACs found on SpacemiT K1 appears to be a custom design
>> that only superficially resembles some other embedded MACs. SpacemiT
>> refers to them as "EMAC", so let's just call the driver "k1_emac".
>>
>> Supports RGMII and RMII interfaces. Includes support for MAC hardware
>> statistics counters. PTP support is not implemented.
>>
>> Signed-off-by: Vivian Wang <wangruikang@iscas.ac.cn>
>> Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
>> Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
>> Reviewed-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
>> Tested-by: Junhui Liu <junhui.liu@pigmoral.tech>
>> Tested-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
> ...
>
>> diff --git a/drivers/net/ethernet/spacemit/k1_emac.c b/drivers/net/ethernet/spacemit/k1_emac.c
> ...
>
>> +static void emac_init_hw(struct emac_priv *priv)
>> +{
>> + /* Destination address for 802.3x Ethernet flow control */
>> + u8 fc_dest_addr[ETH_ALEN] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x01 };
>> +
>> + u32 rxirq = 0, dma = 0;
>> +
>> + regmap_set_bits(priv->regmap_apmu,
>> + priv->regmap_apmu_offset + APMU_EMAC_CTRL_REG,
>> + AXI_SINGLE_ID);
>> +
>> + /* Disable transmit and receive units */
>> + emac_wr(priv, MAC_RECEIVE_CONTROL, 0x0);
>> + emac_wr(priv, MAC_TRANSMIT_CONTROL, 0x0);
>> +
>> + /* Enable MAC address 1 filtering */
>> + emac_wr(priv, MAC_ADDRESS_CONTROL, MREGBIT_MAC_ADDRESS1_ENABLE);
>> +
>> + /* Zero initialize the multicast hash table */
>> + emac_wr(priv, MAC_MULTICAST_HASH_TABLE1, 0x0);
>> + emac_wr(priv, MAC_MULTICAST_HASH_TABLE2, 0x0);
>> + emac_wr(priv, MAC_MULTICAST_HASH_TABLE3, 0x0);
>> + emac_wr(priv, MAC_MULTICAST_HASH_TABLE4, 0x0);
>> +
>> + /* Configure thresholds */
>> + emac_wr(priv, MAC_TRANSMIT_FIFO_ALMOST_FULL, DEFAULT_TX_ALMOST_FULL);
>> + emac_wr(priv, MAC_TRANSMIT_PACKET_START_THRESHOLD,
>> + DEFAULT_TX_THRESHOLD);
>> + emac_wr(priv, MAC_RECEIVE_PACKET_START_THRESHOLD, DEFAULT_RX_THRESHOLD);
>> +
>> + /* Configure flow control (enabled in emac_adjust_link() later) */
>> + emac_set_mac_addr_reg(priv, fc_dest_addr, MAC_FC_SOURCE_ADDRESS_HIGH);
>> + emac_wr(priv, MAC_FC_PAUSE_HIGH_THRESHOLD, DEFAULT_FC_FIFO_HIGH);
>> + emac_wr(priv, MAC_FC_HIGH_PAUSE_TIME, DEFAULT_FC_PAUSE_TIME);
>> + emac_wr(priv, MAC_FC_PAUSE_LOW_THRESHOLD, 0);
>> +
>> + /* RX IRQ mitigation */
>> + rxirq = EMAC_RX_FRAMES & MREGBIT_RECEIVE_IRQ_FRAME_COUNTER_MASK;
>> + rxirq |= (EMAC_RX_COAL_TIMEOUT
>> + << MREGBIT_RECEIVE_IRQ_TIMEOUT_COUNTER_SHIFT) &
>> + MREGBIT_RECEIVE_IRQ_TIMEOUT_COUNTER_MASK;
> Probably this driver can benefit from using FIELD_PREP and FIELD_GET
> in a number of places. In this case I think it would mean that
> MREGBIT_RECEIVE_IRQ_TIMEOUT_COUNTER_SHIFT can be removed entirely.
That looks useful. There's a few more uses of *_SHIFT in this driver,
and I think I can get them all to use FIELD_PREP. I'll change those in
the next version.
>> +
>> + rxirq |= MREGBIT_RECEIVE_IRQ_MITIGATION_ENABLE;
>> + emac_wr(priv, DMA_RECEIVE_IRQ_MITIGATION_CTRL, rxirq);
> ...
>
>> +/* Returns number of packets received */
>> +static int emac_rx_clean_desc(struct emac_priv *priv, int budget)
>> +{
>> + struct net_device *ndev = priv->ndev;
>> + struct emac_rx_desc_buffer *rx_buf;
>> + struct emac_desc_ring *rx_ring;
>> + struct sk_buff *skb = NULL;
>> + struct emac_desc *rx_desc;
>> + u32 got = 0, skb_len, i;
>> + int status;
>> +
>> + rx_ring = &priv->rx_ring;
>> +
>> + i = rx_ring->tail;
>> +
>> + while (budget--) {
>> + rx_desc = &((struct emac_desc *)rx_ring->desc_addr)[i];
>> +
>> + /* Stop checking if rx_desc still owned by DMA */
>> + if (READ_ONCE(rx_desc->desc0) & RX_DESC_0_OWN)
>> + break;
>> +
>> + dma_rmb();
>> +
>> + rx_buf = &rx_ring->rx_desc_buf[i];
>> +
>> + if (!rx_buf->skb)
>> + break;
>> +
>> + got++;
>> +
>> + dma_unmap_single(&priv->pdev->dev, rx_buf->dma_addr,
>> + rx_buf->dma_len, DMA_FROM_DEVICE);
>> +
>> + status = emac_rx_frame_status(priv, rx_desc);
>> + if (unlikely(status == RX_FRAME_DISCARD)) {
>> + ndev->stats.rx_dropped++;
> As per the comment in struct net-device,
> ndev->stats should not be used in modern drivers.
>
> Probably you want to implement NETDEV_PCPU_STAT_TSTATS.
>
> Sorry for not mentioning this in an earlier review of
> stats in this driver.
>
On a closer look, these counters in ndev->stats seems to be redundant
with the hardware-tracked statistics, so maybe I should just not bother
with updating ndev->stats. Does that make sense?
Thanks,
Vivian "dramforever" Wang
next prev parent reply other threads:[~2025-09-05 15:46 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-05 11:09 [PATCH net-next v9 0/5] Add Ethernet MAC support for SpacemiT K1 Vivian Wang
2025-09-05 11:09 ` [PATCH net-next v9 1/5] dt-bindings: net: Add " Vivian Wang
2025-09-05 11:09 ` [PATCH net-next v9 2/5] net: spacemit: Add K1 Ethernet MAC Vivian Wang
2025-09-05 15:35 ` Simon Horman
2025-09-05 15:45 ` Vivian Wang [this message]
2025-09-05 16:01 ` Simon Horman
2025-09-05 16:35 ` Vivian Wang
2025-09-05 23:59 ` Jakub Kicinski
2025-09-06 1:46 ` Vivian Wang
2025-09-07 8:22 ` Vivian Wang
2025-09-09 0:34 ` Jakub Kicinski
2025-09-09 16:15 ` Simon Horman
2025-09-09 16:18 ` Simon Horman
2025-09-05 11:09 ` [PATCH net-next v9 3/5] riscv: dts: spacemit: Add Ethernet support for K1 Vivian Wang
2025-09-05 11:09 ` [PATCH net-next v9 4/5] riscv: dts: spacemit: Add Ethernet support for BPI-F3 Vivian Wang
2025-09-05 11:09 ` [PATCH net-next v9 5/5] riscv: dts: spacemit: Add Ethernet support for Jupiter Vivian Wang
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=0605f176-5cdb-4f5b-9a6b-afa139c96732@iscas.ac.cn \
--to=wangruikang@iscas.ac.cn \
--cc=alex@ghiti.fr \
--cc=andrew+netdev@lunn.ch \
--cc=aou@eecs.berkeley.edu \
--cc=conor+dt@kernel.org \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=dlan@gentoo.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=junhui.liu@pigmoral.tech \
--cc=krzk+dt@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=maxime.chevallier@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=pabeni@redhat.com \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=robh@kernel.org \
--cc=spacemit@lists.linux.dev \
--cc=troy.mitchell@linux.spacemit.com \
--cc=uwu@dram.page \
--cc=vadim.fedorenko@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).