Netdev List
 help / color / mirror / Atom feed
From: Florian Fainelli <florian.fainelli@broadcom.com>
To: netdev@vger.kernel.org
Cc: Florian Fainelli <florian.fainelli@broadcom.com>,
	Doug Berger <opendmb@gmail.com>,
	Nicolai Buchwitz <nb@tipi-net.de>,
	Broadcom internal kernel review list
	<bcm-kernel-feedback-list@broadcom.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Subject: [PATCH net-next 2/2] net: bcmgenet: add support for NETIF_F_RXFCS
Date: Fri,  4 Dec 2026 15:00:48 -0800	[thread overview]
Message-ID: <20261204230048.3554713-3-florian.fainelli@broadcom.com> (raw)
In-Reply-To: <20261204230048.3554713-1-florian.fainelli@broadcom.com>

Allow the Ethernet FCS to be delivered to the network stack, which is
useful for packet capture and for debugging link-level corruption.
The feature is off by default and is toggled with "ethtool -K <dev>
rx-fcs on|off".

bcmgenet_set_features() now programs CMD_CRC_FWD in UMAC_CMD according
to NETIF_F_RXFCS, and keeps RBUF_SKIP_FCS in RBUF_CHK_CTRL in sync so
the RX checksum block ignores the forwarded FCS. This replaces the
previous read-back of CMD_CRC_FWD into priv->crc_fwd_en, which is
still updated and still used by the Wake-on-LAN code.

In bcmgenet_desc_rx() the FCS is only trimmed when it was forwarded and
NETIF_F_RXFCS is off. The hardware checksum does not cover the FCS, so
it cannot be reported as CHECKSUM_COMPLETE for frames that still carry
it; such frames are left to the stack to verify.

Frames already queued in the RX rings were written with the previous
setting and cannot be told apart from new ones, so a change on a running
interface is refused with -EBUSY. The request is kept in the device's
wanted features, and bcmgenet_close() calls netdev_update_features() so
that it takes effect once the interface is down. Changing the feature
while the interface is down only needs the register update. The open
and resume paths re-apply the current features and are not affected.

Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
 .../net/ethernet/broadcom/genet/bcmgenet.c    | 46 ++++++++++++++++---
 1 file changed, 40 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
index 93a773d0ccf3..35a0fe425acd 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
+++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
@@ -814,14 +814,40 @@ static int bcmgenet_set_features(struct net_device *dev,
 	u32 reg;
 	int ret;
 
+	/* Frames already queued in the RX rings were written with the old FCS
+	 * setting and cannot be told apart from new ones, so refuse a live
+	 * change. The request stays in wanted_features and is applied by
+	 * bcmgenet_close(). Re-applying the current features from open and
+	 * resume does not change the flag and is not affected.
+	 */
+	if (netif_running(dev) && ((features ^ dev->features) & NETIF_F_RXFCS))
+		return -EBUSY;
+
 	ret = clk_prepare_enable(priv->clk);
 	if (ret)
 		return ret;
 
-	/* Make sure we reflect the value of CRC_CMD_FWD */
+	/* Forward the FCS to the host when NETIF_F_RXFCS is requested.
+	 * RBUF_SKIP_FCS tells the RX checksum block to ignore the forwarded
+	 * FCS, so keep it in sync with CMD_CRC_FWD.
+	 */
+	spin_lock_bh(&priv->reg_lock);
 	reg = bcmgenet_umac_readl(priv, UMAC_CMD);
+	if (features & NETIF_F_RXFCS)
+		reg |= CMD_CRC_FWD;
+	else
+		reg &= ~CMD_CRC_FWD;
+	bcmgenet_umac_writel(priv, reg, UMAC_CMD);
 	priv->crc_fwd_en = !!(reg & CMD_CRC_FWD);
 
+	reg = bcmgenet_rbuf_readl(priv, RBUF_CHK_CTRL);
+	if (priv->crc_fwd_en)
+		reg |= RBUF_SKIP_FCS;
+	else
+		reg &= ~RBUF_SKIP_FCS;
+	bcmgenet_rbuf_writel(priv, reg, RBUF_CHK_CTRL);
+	spin_unlock_bh(&priv->reg_lock);
+
 	clk_disable_unprepare(priv->clk);
 
 	return ret;
@@ -2461,12 +2487,15 @@ static unsigned int bcmgenet_desc_rx(struct bcmgenet_rx_ring *ring,
 		skb_reserve(skb, GENET_RSB_PAD);
 		__skb_put(skb, len - GENET_RSB_PAD);
 
-		if (priv->crc_fwd_en) {
+		/* Strip the FCS unless the user asked to receive it */
+		if (priv->crc_fwd_en && !(dev->features & NETIF_F_RXFCS))
 			skb_trim(skb, skb->len - ETH_FCS_LEN);
-		}
 
-		/* Set up checksum offload */
-		if (dev->features & NETIF_F_RXCSUM) {
+		/* Set up checksum offload. The hardware checksum excludes the
+		 * FCS, so it cannot be used when the FCS is passed up.
+		 */
+		if ((dev->features & NETIF_F_RXCSUM) &&
+		    !(dev->features & NETIF_F_RXFCS)) {
 			rx_csum = (__force __be16)(status->rx_csum & 0xffff);
 			if (rx_csum) {
 				skb->csum = (__force __wsum)ntohs(rx_csum);
@@ -3552,6 +3581,11 @@ static int bcmgenet_close(struct net_device *dev)
 
 	clk_disable_unprepare(priv->clk);
 
+	/* Apply a feature change, e.g. NETIF_F_RXFCS, that was refused while
+	 * the interface was running. The device is not running anymore.
+	 */
+	netdev_update_features(dev);
+
 	return ret;
 }
 
@@ -4098,7 +4132,7 @@ static int bcmgenet_probe(struct platform_device *pdev)
 	/* Set default features */
 	dev->features |= NETIF_F_SG | NETIF_F_HIGHDMA | NETIF_F_HW_CSUM |
 			 NETIF_F_RXCSUM;
-	dev->hw_features |= dev->features;
+	dev->hw_features |= dev->features | NETIF_F_RXFCS;
 	dev->vlan_features |= dev->features;
 
 	netdev_sw_irq_coalesce_default_on(dev);
-- 
2.56.1


      parent reply	other threads:[~2026-12-04 23:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 23:00 [PATCH net-next 0/2] net: bcmgenet: Support for NETIF_F_RXFCS Florian Fainelli
2026-12-04 23:00 ` [PATCH net-next 1/2] net: bcmgenet: keep FCS forwarding when exiting Wake-on-LAN Florian Fainelli
2026-12-04 23:00 ` Florian Fainelli [this message]

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=20261204230048.3554713-3-florian.fainelli@broadcom.com \
    --to=florian.fainelli@broadcom.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@kernel.org \
    --cc=nb@tipi-net.de \
    --cc=netdev@vger.kernel.org \
    --cc=opendmb@gmail.com \
    --cc=pabeni@redhat.com \
    /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