Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next v3 0/2] net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A
@ 2026-12-01 17:17 Birger Koblitz
  2026-12-01 17:17 ` [PATCH net-next v3 1/2] net: usb: ax88179: Make receiving FCS on AX88179A configurable Birger Koblitz
  2026-12-01 17:17 ` [PATCH net-next v3 2/2] net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A Birger Koblitz
  0 siblings, 2 replies; 5+ messages in thread
From: Birger Koblitz @ 2026-12-01 17:17 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni
  Cc: netdev, linux-usb, Benjamin Larsson, Birger Koblitz

The AX88179A-Chip family supports reception of the FCS
at the host. This is configured by enabling the AX_RX_CTL_DROPCRCERR
flag in the USB-adapters RX-controls. For AX88279-based adapters,
the flag has already been always set in order to receive
complete frames, however, the FCS is not necessarily usable, as it
is only part of the transferred up-to 8-byte padding area, and for
some frame-lengths only 2 of the 4 bytes of the FCS are transferred
to the host.
    
Note, that the AX_RX_CTL_DROPCRCERR flag has no influence on dropping
of corrupt frames already by the USB adapter, even corrupt frames
are always transferred to the host.

Add Add NETIF_F_RXFCS and NETIF_F_RXALL features for
the AX88179A and take a trailing FCS into account for MTU
verification when checking packet length in rx_fixup().

Also add code rx_fixup() in order to Count dropped packets and those
with incorrect checksum.
    

Suggested-by: Benjamin Larsson <benjamin.larsson@genexis.eu>
Signed-off-by: Birger Koblitz <mail@birger-koblitz.de>
---
Changes in v3:
- In ax88179_set_multicast() make sure the behaviour for the older
  AX88179 devices is not changed
- Improve error checking in set_features()
- Improve lower packet length check to take FCS into account
- Link to v2: https://lore.kernel.org/r/20261129-fcs-v2-0-f60d6b105a15@birger-koblitz.de

Changes in v2:
- Do not clobber rxctl in ax88179_set_multicast(): read and update it
- Use netdev_features_t for features in rx_fixup()
- Do not include FCS trailer when NETIF_F_RXFCS not set
- Count rx_errors together with crc_errors as per definition
- Link to v1: https://lore.kernel.org/r/20261127-fcs-v1-0-0c4ede015bf5@birger-koblitz.de

---
Birger Koblitz (2):
      net: usb: ax88179: Make receiving FCS on AX88179A configurable
      net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A

 drivers/net/usb/ax88179_lib.c      | 14 +++++++---
 drivers/net/usb/ax88179a_devices.c | 52 +++++++++++++++++++++++++++++++++-----
 2 files changed, 57 insertions(+), 9 deletions(-)
---
base-commit: eb6d6c80d35449c27471b1874f13066c09a8964d
change-id: 20261126-fcs-afccb4a76dd1

Best regards,
-- 
Birger Koblitz <mail@birger-koblitz.de>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH net-next v3 1/2] net: usb: ax88179: Make receiving FCS on AX88179A configurable
  2026-12-01 17:17 [PATCH net-next v3 0/2] net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A Birger Koblitz
@ 2026-12-01 17:17 ` Birger Koblitz
  2026-12-04  8:19   ` netdev-bot+sashiko
  2026-12-01 17:17 ` [PATCH net-next v3 2/2] net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A Birger Koblitz
  1 sibling, 1 reply; 5+ messages in thread
From: Birger Koblitz @ 2026-12-01 17:17 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni
  Cc: netdev, linux-usb, Benjamin Larsson, Birger Koblitz

Make reception of FCS on AX88179A configuration-dependent.

In contrast to what the name suggests, AX_RX_CTL_DROPCRCERR
actually instructs the MAC to leave the FCS attached to the end of the
Ethernet frame when sent by the USB-adapter to the host. This was
tested for AX88179A as well as on the AX88772D, which behaves the same
as the AX88179A in respect of this flag, as this refers to MAC
functionality and the AX88772D is merely a AX88179A with a different
integrated 100Mbit PHY.
For the older AX88179, the behaviour does not change.

For AX88279-based adapters, the flag must be set in order to receive
complete frames, however, the FCS is not necessarily usable, as it
is only part of the transferred up-to 8-byte padding area, and for
some frame-lengths only 2 of the 4 bytes of the FCS are transferred
to the host.

The AX_RX_CTL_DROPCRCERR flag has no influence on dropping of corrupt
frames already by the USB adapter.

Fixes: 7d573278f9a5 ("ax88179_178a: Add HW support for AX179A-based chips")
Signed-off-by: Birger Koblitz <mail@birger-koblitz.de>
---
 drivers/net/usb/ax88179_lib.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/net/usb/ax88179_lib.c b/drivers/net/usb/ax88179_lib.c
index 821ee9cd8ded1b8f1e425bcef493fb175ed30376..353b3a74793084085c42c1068caf5922e0681ad3 100644
--- a/drivers/net/usb/ax88179_lib.c
+++ b/drivers/net/usb/ax88179_lib.c
@@ -352,14 +352,22 @@ void ax88179_set_multicast(struct net_device *net)
 	struct usbnet *dev = netdev_priv(net);
 	u8 *m_filter = ((u8 *)dev->data);
 	struct ax88179_data *data;
-	u16 rxctl = 0;
+	u16 rxctl;
 
 	data = dev->driver_priv;
 
-	rxctl = (AX_RX_CTL_START | AX_RX_CTL_AB | AX_RX_CTL_DROPCRCERR);
+	if (data->chip_version >= AX_VERSION_AX88179A) {
+		rxctl = READ_ONCE(data->rxctl);
+		rxctl &= ~(AX_RX_CTL_IPE | AX_RX_CTL_DROPCRCERR | AX_RX_CTL_PRO |
+			AX_RX_CTL_AMALL | AX_RX_CTL_AM);
+	} else {
+		rxctl = (AX_RX_CTL_START | AX_RX_CTL_AB | AX_RX_CTL_DROPCRCERR);
+	}
 	if (data->ip_align)
 		rxctl |= AX_RX_CTL_IPE;
-
+	if (net->features & (NETIF_F_RXFCS | NETIF_F_RXALL) ||
+	    data->chip_version != AX_VERSION_AX88179A)
+		rxctl |= AX_RX_CTL_DROPCRCERR;
 	if (net->flags & IFF_PROMISC) {
 		rxctl |= AX_RX_CTL_PRO;
 	} else if (net->flags & IFF_ALLMULTI ||

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net-next v3 2/2] net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A
  2026-12-01 17:17 [PATCH net-next v3 0/2] net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A Birger Koblitz
  2026-12-01 17:17 ` [PATCH net-next v3 1/2] net: usb: ax88179: Make receiving FCS on AX88179A configurable Birger Koblitz
@ 2026-12-01 17:17 ` Birger Koblitz
  2026-12-04  8:19   ` netdev-bot+sashiko
  1 sibling, 1 reply; 5+ messages in thread
From: Birger Koblitz @ 2026-12-01 17:17 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni
  Cc: netdev, linux-usb, Benjamin Larsson, Birger Koblitz

Add NETIF_F_RXFCS and NETIF_F_RXALL features for
the AX88179A and take a trailing FCS into account for MTU
verification when checking packet length in rx_fixup().

Count dropped packets and those with incorrect FCS.

Fixes: 7d573278f9a5 ("ax88179_178a: Add HW support for AX179A-based chips")
Suggested-by: Benjamin Larsson <benjamin.larsson@genexis.eu>
Signed-off-by: Birger Koblitz <mail@birger-koblitz.de>
---
 drivers/net/usb/ax88179a_devices.c | 52 +++++++++++++++++++++++++++++++++-----
 1 file changed, 46 insertions(+), 6 deletions(-)

diff --git a/drivers/net/usb/ax88179a_devices.c b/drivers/net/usb/ax88179a_devices.c
index 69095110e70435806a99274c50d79e86016ec9a0..04d8f37bc7ebef3f2e530cb41f403dca9d0dd7d7 100644
--- a/drivers/net/usb/ax88179a_devices.c
+++ b/drivers/net/usb/ax88179a_devices.c
@@ -717,10 +717,12 @@ static int ax88179a_mii_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
 static int ax88179a_set_features(struct net_device *net, netdev_features_t features)
 {
 	struct usbnet *dev = netdev_priv(net);
+	struct ax88179_data *ax179_data;
 	netdev_features_t changed;
 	int ret;
 	u8 tmp;
 
+	ax179_data = dev->driver_priv;
 	changed = net->features ^ features;
 
 	ret = ax88179_set_features(net, features);
@@ -780,6 +782,20 @@ static int ax88179a_set_features(struct net_device *net, netdev_features_t featu
 		if (ret < 0)
 			return ret;
 	}
+
+	if (changed & (NETIF_F_RXFCS | NETIF_F_RXALL)) {
+		u16 rxctl = READ_ONCE(ax179_data->rxctl);
+
+		if (features & (NETIF_F_RXFCS | NETIF_F_RXALL))
+			rxctl |= AX_RX_CTL_DROPCRCERR;
+		else
+			rxctl &= ~AX_RX_CTL_DROPCRCERR;
+		WRITE_ONCE(ax179_data->rxctl, rxctl);
+		ret = ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, rxctl);
+		if (ret < 0)
+			return ret;
+	}
+
 	return 0;
 }
 
@@ -852,8 +868,8 @@ static int ax88179a_bind(struct usbnet *dev, struct usb_interface *intf)
 		    ax179_data->fw_version[2], ax179_data->fw_version[3]);
 
 	/* The AX88279 requires both the AX_RX_CTL_IPE and AX_RX_CTL_DROPCRCERR
-	 * bits set in AX_RX_CTL for creating correct RX-URBs. AX_RX_CTL_DROPCRCERR
-	 * is anyway set for all chips, make sure AX_RX_CTL_IPE is set via ip_align.
+	 * bits set in AX_RX_CTL for creating correct RX-URBs. Make sure
+	 * AX_RX_CTL_IPE is set via ip_align.
 	 * Also configure eeprom access parameters.
 	 */
 	if (ax179_data->chip_version == AX_VERSION_AX88279) {
@@ -894,6 +910,11 @@ static int ax88179a_bind(struct usbnet *dev, struct usb_interface *intf)
 	dev->net->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM |
 				  NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM | NETIF_F_TSO;
 
+	if (ax179_data->chip_version == AX_VERSION_AX88179A) {
+		dev->net->hw_features |= NETIF_F_RXFCS | NETIF_F_RXALL;
+		dev->net->vlan_features |= NETIF_F_RXFCS | NETIF_F_RXALL;
+	}
+
 	netif_set_tso_max_size(dev->net, 16384);
 
 	/* Enable Transmission of Link Speed byte in interrupt URB */
@@ -1039,9 +1060,14 @@ static int ax88179a_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
 	pkt_end = 0;
 	while (pkt_cnt--) {
 		u64 pkt_desc = get_unaligned_le64(pkt_desc_ptr);
+		netdev_features_t features = dev->net->features;
 		u32 pkt_len_plus_padd;
+		u32 fcs_trailer = 0;
 		u32 pkt_len;
 
+		if (features & (NETIF_F_RXFCS | NETIF_F_RXALL))
+			fcs_trailer = ETH_FCS_LEN;
+
 		pkt_len = FIELD_GET(AX179A_RX_PD_LEN, pkt_desc);
 		pkt_len -= (ax179_data->ip_align ? 2 : 0);
 		pkt_len_plus_padd = ((pkt_len + 7 + (ax179_data->ip_align ? 2 : 0)) & 0x7FFF8);
@@ -1050,10 +1076,19 @@ static int ax88179a_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
 		if (pkt_end > hdr_off || (pkt_cnt == 0 && pkt_end != hdr_off))
 			goto err;
 
-		if (pkt_desc & AX179A_RX_PD_DROP || !(pkt_desc & AX179A_RX_PD_RX_OK) ||
-		    pkt_len > (dev->hard_mtu + AX179A_RX_HW_PAD) || pkt_len < 2 + ETH_HLEN) {
+		if (((pkt_desc & AX179A_RX_PD_DROP || !(pkt_desc & AX179A_RX_PD_RX_OK)) &&
+		     !(features & NETIF_F_RXALL)) ||
+		    pkt_len > dev->hard_mtu + AX179A_RX_HW_PAD + fcs_trailer ||
+		    pkt_len < 2 + ETH_HLEN + fcs_trailer) {
 			skb_pull(skb, pkt_len_plus_padd);
 
+			if (pkt_desc & AX179A_RX_PD_DROP)
+				dev->net->stats.rx_dropped++;
+
+			if (!(pkt_desc & AX179A_RX_PD_RX_OK)) {
+				dev->net->stats.rx_crc_errors++;
+				dev->net->stats.rx_errors++;
+			}
 			/* Next RX Packet Descriptor */
 			pkt_desc_ptr++;
 			continue;
@@ -1063,6 +1098,9 @@ static int ax88179a_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
 		if (!ax_skb)
 			goto err;
 
+		if (!(features & NETIF_F_RXFCS))
+			pkt_len -= fcs_trailer;
+
 		skb_put(ax_skb, pkt_len);
 		memcpy(ax_skb->data, skb->data + (ax179_data->ip_align ? AX179A_RX_HW_PAD : 0),
 		       pkt_len);
@@ -1216,12 +1254,14 @@ static int ax88179a_reset(struct usbnet *dev)
 	ax88179_write_u8(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, *tmp);
 
 	/* Configure RX control register => start operation */
-	rxctl = AX_RX_CTL_DROPCRCERR | AX_RX_CTL_START | AX_RX_CTL_AP |
-		AX_RX_CTL_AMALL | AX_RX_CTL_AB;
+	rxctl = AX_RX_CTL_START | AX_RX_CTL_AP | AX_RX_CTL_AMALL | AX_RX_CTL_AB;
 	if (ax179_data->ip_align)
 		rxctl |= AX_RX_CTL_IPE;
 	if (dev->net->flags & IFF_PROMISC)
 		rxctl |= AX_RX_CTL_PRO;
+	if (dev->net->features & (NETIF_F_RXFCS | NETIF_F_RXALL) ||
+	    ax179_data->chip_version == AX_VERSION_AX88279)
+		rxctl |= AX_RX_CTL_DROPCRCERR;
 	WRITE_ONCE(ax179_data->rxctl, rxctl);
 	ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, rxctl);
 

-- 
2.47.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next v3 1/2] net: usb: ax88179: Make receiving FCS on AX88179A configurable
  2026-12-01 17:17 ` [PATCH net-next v3 1/2] net: usb: ax88179: Make receiving FCS on AX88179A configurable Birger Koblitz
@ 2026-12-04  8:19   ` netdev-bot+sashiko
  0 siblings, 0 replies; 5+ messages in thread
From: netdev-bot+sashiko @ 2026-12-04  8:19 UTC (permalink / raw)
  To: mail
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, netdev, linux-usb,
	benjamin.larsson

Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] ax88179_set_multicast()
  (drivers/net/usb/ax88179_lib.c:359-365) now picks its starting rxctl…
- [Medium] ax88179_set_multicast() now does an unlocked read-modify-write
  of data->rxctl: READ_ONCE, clear IPE/DROPCRCERR/PRO/AMALL/AM, then…
- [Low] For chip_version >= AX_VERSION_AX88179A (AX88179A, AX88772D,
  AX88279), ax88179_set_multicast()…

--

net: usb: ax88179: Make receiving FCS on AX88179A configurable

This patch changes ax88179_set_multicast() so that AX_RX_CTL_DROPCRCERR is
set on the AX88179A only when NETIF_F_RXFCS or NETIF_F_RXALL is enabled.
For chips with chip_version >= AX_VERSION_AX88179A, the rxctl value is now
built from the cached data->rxctl, not from a fixed baseline. The
behaviour of the older AX88179 is meant to stay the same.

> diff --git a/drivers/net/usb/ax88179_lib.c b/drivers/net/usb/ax88179_lib.c
> index 821ee9cd8ded1..353b3a7479308 100644
> --- a/drivers/net/usb/ax88179_lib.c
> +++ b/drivers/net/usb/ax88179_lib.c
> @@ -352,14 +352,22 @@ void ax88179_set_multicast(struct net_device *net)
>  	struct usbnet *dev = netdev_priv(net);
>  	u8 *m_filter = ((u8 *)dev->data);
>  	struct ax88179_data *data;
> -	u16 rxctl = 0;
> +	u16 rxctl;
>  
>  	data = dev->driver_priv;
>  
> -	rxctl = (AX_RX_CTL_START | AX_RX_CTL_AB | AX_RX_CTL_DROPCRCERR);
> +	if (data->chip_version >= AX_VERSION_AX88179A) {
> +		rxctl = READ_ONCE(data->rxctl);
> +		rxctl &= ~(AX_RX_CTL_IPE | AX_RX_CTL_DROPCRCERR | AX_RX_CTL_PRO |
> +			AX_RX_CTL_AMALL | AX_RX_CTL_AM);

[Severity: Medium]

When chip_version >= AX_VERSION_AX88179A, this branch now starts from the
cached data->rxctl instead of AX_RX_CTL_START | AX_RX_CTL_AB. It never adds
START or AB back. The cache is only initialized by ax88179a_reset(). What
happens if this runs on the legacy ax88179_178a.c path?

ax88179_bind() zero-allocates the private data:

drivers/net/usb/ax88179_178a.c:ax88179_bind() {
    ...
	ax179_data = kzalloc_obj(*ax179_data);
    ...
}

It then reads chip_version from AX_CHIP_STATUS and does not reject values
>= AX_VERSION_AX88179A. The legacy driver_info is picked only by USB
VID/PID. That covers the 0b95:1790 vendor-interface catch-all entry and
the OEM entries (D-Link, Sitecom, Samsung, Lenovo, Belkin, Toshiba, MCT,
Allied Telesis).

ax88179_reset() starts RX from a stack buffer and never stores the value
in ax179_data->rxctl:

	*tmp16 = AX_RX_CTL_DROPCRCERR | AX_RX_CTL_IPE | AX_RX_CTL_START |
		 AX_RX_CTL_AP | AX_RX_CTL_AMALL | AX_RX_CTL_AB;
	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, tmp16);

If AX179A-class silicon (chip_version 6 or 7) is bound through this path,
would open go like this?

__dev_open()
  dev_set_rx_mode()
    ax88179_set_multicast()
      rxctl = 0 & ~(...);              /* no START, no AB */
      WRITE_ONCE(data->rxctl, rxctl);
      ax88179_write_cmd_async(dev, AX_ACCESS_MAC, AX_RX_CTL, ...);

ax88179_link_reset() would then write the same START-less value back on
every link reset:

		ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2,
				  &ax179_data->rxctl);

Wouldn't that leave the RX engine stopped and broadcast reception off?

Before this patch the legacy path always rebuilt the value with
START | AB, whatever chip_version said. The second patch in the series
does not seem to change this.

I could not confirm that any shipping device puts AX179A-class silicon
behind one of the legacy table entries. Still, nothing in the code
prevents it.

[Severity: Low]

AX_RX_CTL_AP is not in this mask, so is it intended that AP now stays set
on AX179A-family chips? ax88179a_reset() puts it into the cache:

	rxctl = AX_RX_CTL_DROPCRCERR | AX_RX_CTL_START | AX_RX_CTL_AP |
		AX_RX_CTL_AMALL | AX_RX_CTL_AB;

Before this patch, the first ndo_set_rx_mode call rebuilt rxctl from
START | AB | DROPCRCERR, which cleared AP. Now AP survives every rx-mode
update on the AX88179A, AX88772D and AX88279.

The commit message only covers the DROPCRCERR/FCS change. Could it also
mention the switch to a read-modify-write of the cached value, and this
change to the filter mode? That switch is also what makes this function
depend on data->rxctl being initialized, as noted above.

> +	} else {
> +		rxctl = (AX_RX_CTL_START | AX_RX_CTL_AB | AX_RX_CTL_DROPCRCERR);
> +	}
>  	if (data->ip_align)
>  		rxctl |= AX_RX_CTL_IPE;
> -
> +	if (net->features & (NETIF_F_RXFCS | NETIF_F_RXALL) ||
> +	    data->chip_version != AX_VERSION_AX88179A)
> +		rxctl |= AX_RX_CTL_DROPCRCERR;

[Severity: Medium]

This is an unlocked read-modify-write of data->rxctl, and DROPCRCERR is
derived from net->features. Can it race with ndo_set_features?

Later in this series, the "Support NETIF_F_RXFCS and NETIF_F_RXALL" patch
makes ax88179a_set_features() do its own read-modify-write. It calls
READ_ONCE() on ax179_data->rxctl, toggles DROPCRCERR, stores the result
with WRITE_ONCE() and then does a synchronous AX_RX_CTL write. All of this
runs under RTNL only.

ndo_set_rx_mode runs under netif_addr_lock and can be reached without
RTNL, for example by an unprivileged IPV6_ADD_MEMBERSHIP:

ipv6_sock_mc_join()
  dev_mc_add()
    __dev_set_rx_mode()
      ax88179_set_multicast()

Also, __netdev_update_features() only updates dev->features after
ndo_set_features() returns:

	err = dev->netdev_ops->ndo_set_features(dev, features);
	...
		dev->features = features;

With "ethtool -K ethX rx-all on", the interleaving could be:

CPU1 (set_features)               CPU2 (ax88179_set_multicast)
sets DROPCRCERR in cache and hw
                                  sees RXALL still clear
                                  clears DROPCRCERR
                                  async AX_RX_CTL write lands last
dev->features gains RXALL

After that, ax88179a_rx_fixup() sets fcs_trailer = ETH_FCS_LEN and
subtracts it from pkt_len because RXFCS is off, but the hardware no
longer appends the FCS. Wouldn't every received frame then lose 4 bytes
of payload until the next rx-mode change? Turning rx-fcs or rx-all off
would hit the reverse case and leave a 4-byte trailer on every frame.

The two read-modify-write paths can also lose each other's PRO/AM/AMALL
updates. ax88179a_mac_link_up() then writes the stale cache back to the
hardware. It holds medium_status_mutex, which neither writer takes:

	ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, READ_ONCE(ax179_data->rxctl));

The second patch in the series fixes the resume case by deriving
DROPCRCERR from the features in ax88179a_reset(). It doesn't seem to fix
this race, and it adds the second writer. Should these writers share a
lock?

>  	if (net->flags & IFF_PROMISC) {
>  		rxctl |= AX_RX_CTL_PRO;
>  	} else if (net->flags & IFF_ALLMULTI ||

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201-fcs-v3-0-6c355917b17e%40birger-koblitz.de

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next v3 2/2] net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A
  2026-12-01 17:17 ` [PATCH net-next v3 2/2] net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A Birger Koblitz
@ 2026-12-04  8:19   ` netdev-bot+sashiko
  0 siblings, 0 replies; 5+ messages in thread
From: netdev-bot+sashiko @ 2026-12-04  8:19 UTC (permalink / raw)
  To: mail
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, netdev, linux-usb,
	benjamin.larsson

Thank you for your contribution! Sashiko AI review found 8 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 4 · Low: 4

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The commit message describes only feature work: new
  NETIF_F_RXFCS/NETIF_F_RXALL features, an FCS-aware length check and…
- [Medium] The statistics in ax88179a_rx_fixup() are incomplete, and they
  change with an unrelated feature toggle.
- [Medium] ax88179a_set_features() adds a new writer of ax179_data->rxctl
  and the AX_RX_CTL register: READ_ONCE, modify DROPCRCERR, WRITE_ONCE,…
- [Medium] In ax88179a_set_features(), the cached value is committed with
  WRITE_ONCE(ax179_data->rxctl, rxctl) before…
- [Low] The new code sets a bit named AX_RX_CTL_DROPCRCERR ('drop CRC-
  error frames') when the user asks for NETIF_F_RXALL ('also receive…
- [Low] ax88179a_bind() ORs NETIF_F_RXFCS | NETIF_F_RXALL into
  dev->net->vlan_features.
- [Low] Each packet in ax88179a_rx_fixup() reads dev->net->features
  without a lock to decide whether a 4-byte FCS trailer is present and…
- [Low] The new branch in ax88179a_set_features() writes the whole cached
  ax179_data->rxctl to AX_RX_CTL, including AX_RX_CTL_START | AP | AMALL…

--

net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A

This patch adds NETIF_F_RXFCS and NETIF_F_RXALL support for the AX88179A.
It sets AX_RX_CTL_DROPCRCERR only when those features are on, and accounts
for a trailing FCS in the ax88179a_rx_fixup() length checks. It also counts
dropped and CRC-errored frames.

> diff --git a/drivers/net/usb/ax88179a_devices.c b/drivers/net/usb/ax88179a_devices.c
> index 69095110e7043..04d8f37bc7ebe 100644
> --- a/drivers/net/usb/ax88179a_devices.c
> +++ b/drivers/net/usb/ax88179a_devices.c

[ ... ]

> @@ -780,6 +782,20 @@ static int ax88179a_set_features(struct net_device *net, netdev_features_t featu
>  		if (ret < 0)
>  			return ret;
>  	}
> +
> +	if (changed & (NETIF_F_RXFCS | NETIF_F_RXALL)) {
> +		u16 rxctl = READ_ONCE(ax179_data->rxctl);
> +
> +		if (features & (NETIF_F_RXFCS | NETIF_F_RXALL))
> +			rxctl |= AX_RX_CTL_DROPCRCERR;
> +		else
> +			rxctl &= ~AX_RX_CTL_DROPCRCERR;

[Severity: Low]
This isn't a bug, but this sets a bit named AX_RX_CTL_DROPCRCERR when
rx-all (keep errored frames) or rx-fcs is requested, and clears it
otherwise. Read literally, the logic looks inverted.

ax88179a_rx_fixup() treats the set bit as "a 4 byte FCS trailer is
present". The only place that explains this (on AX88179A the bit leaves
the FCS attached rather than controlling dropping) is the commit message
of the earlier patch "net: usb: ax88179: Make receiving FCS on AX88179A
configurable".

ax88179_178a.c and the older-chip branch of ax88179_set_multicast() also
use this define. There it is set by default and there is no FCS handling.

Could a comment here, or next to the define in ax88179_lib.h, describe
the AX88179A semantics? That would stop a later cleanup from inverting
this logic.

> +		WRITE_ONCE(ax179_data->rxctl, rxctl);
> +		ret = ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, rxctl);
> +		if (ret < 0)
> +			return ret;

[Severity: Medium]
What happens if ax88179_write_u16() fails here? The cached
ax179_data->rxctl already holds the new DROPCRCERR state. Because of the
error return, __netdev_update_features() keeps the old dev->features.

ax88179a_mac_link_up() later writes the cached value to the hardware
unchanged:

	ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, READ_ONCE(ax179_data->rxctl));

After the next link-up, the hardware FCS mode no longer matches what
dev->features tells ax88179a_rx_fixup().

For example, a failed attempt to turn rx-all off with rx-fcs off leaves
NETIF_F_RXALL set while DROPCRCERR is cleared. fcs_trailer is then 4, and
every frame would lose 4 bytes of real payload.

Should the cache only be updated after the register write succeeds?

[Severity: Medium]
What serializes this read-modify-write of ax179_data->rxctl and
AX_RX_CTL against the other writers?

ax88179a_set_features() runs under RTNL only. The other two writers use
different locks:

- ax88179a_mac_link_up() runs from the phylink resolve worker without
  RTNL. It writes the cached value under medium_status_mutex, which is
  not taken here.
- ax88179_set_multicast() runs as ndo_set_rx_mode and rebuilds
  DROPCRCERR from net->features. The core only updates net->features
  after ndo_set_features() returns.

One possible interleaving:

phylink worker                     ethtool -K ethX rx-all on
ax88179a_mac_link_up()
  READ_ONCE(ax179_data->rxctl)
    (old DROPCRCERR)
                                   ax88179a_set_features()
                                     WRITE_ONCE(ax179_data->rxctl, new)
                                     ax88179_write_u16(.., AX_RX_CTL, new)
  ax88179_write_u16(.., AX_RX_CTL, old)

The hardware FCS mode then disagrees with dev->features, which
ax88179a_rx_fixup() uses to decide whether to strip 4 bytes. Could this
leave every received frame either truncated by 4 bytes or carrying the
FCS as payload until something else rewrites rxctl?

[Severity: Low]
This writes the whole cached rxctl, including AX_RX_CTL_START, AP, AMALL
and AB from the last ax88179a_reset(). ax88179a_stop() clears the
register but not the cache:

	ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 0);

Does toggling rx-fcs or rx-all while the interface is down re-arm the
receive control register that stop() cleared on purpose? Before this
patch nothing wrote AX_RX_CTL while the interface was down, because
ndo_set_rx_mode only runs with IFF_UP.

A related case is a link-up in progress. ax88179a_mac_link_up() writes
AX_RX_CTL_STOP and MAC_PATH = 0, reprograms the bulk-in and medium
settings, and only then restores rxctl under medium_status_mutex.

Can this write set START in the middle of that sequence and restart RX
while the link is still being reconfigured?

> +	}
> +
>  	return 0;
>  }

[ ... ]

> @@ -894,6 +910,11 @@ static int ax88179a_bind(struct usbnet *dev, struct usb_interface *intf)
>  	dev->net->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM |
>  				  NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM | NETIF_F_TSO;
>  
> +	if (ax179_data->chip_version == AX_VERSION_AX88179A) {
> +		dev->net->hw_features |= NETIF_F_RXFCS | NETIF_F_RXALL;
> +		dev->net->vlan_features |= NETIF_F_RXFCS | NETIF_F_RXALL;

[Severity: Low]
Do these bits have any effect in vlan_features?

vlan_dev_init() builds the VLAN device's hw_features from a fixed set
that does not include NETIF_F_RXFCS or NETIF_F_RXALL.
vlan_dev_fix_features() only intersects with the lower device's
vlan_features, so a VLAN upper device can never enable them.

These are port level RX controls, and no other driver under drivers/net/
adds them to vlan_features. Can this line be dropped?

> +	}
> +
>  	netif_set_tso_max_size(dev->net, 16384);

[ ... ]

> @@ -1039,9 +1060,14 @@ static int ax88179a_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
>  	pkt_end = 0;
>  	while (pkt_cnt--) {
>  		u64 pkt_desc = get_unaligned_le64(pkt_desc_ptr);
> +		netdev_features_t features = dev->net->features;

[Severity: Low]
FCS handling for each frame is decided from a lockless read of
dev->net->features. That is not necessarily the setting the hardware
used when it framed this data.

ax88179a_set_features() changes DROPCRCERR in AX_RX_CTL while RX is
live, and dev->features is only updated after ndo_set_features()
returns. Some data may have been framed under the old setting: data
still buffered in the device, URBs in flight, or skbs queued on
dev->done.

When rx-fcs or rx-all is enabled, frames carrying the FCS would be
parsed with fcs_trailer = 0, so the FCS is delivered as payload.

When rx-all is disabled with rx-fcs off, frames without an FCS would go
through this with fcs_trailer = 4 and lose 4 bytes of real payload:

	if (!(features & NETIF_F_RXFCS))
		pkt_len -= fcs_trailer;

Is a short burst of mis-sized frames after each toggle acceptable here?
Drivers such as igb and e1000e reset the device when these features
change.

>  		u32 pkt_len_plus_padd;
> +		u32 fcs_trailer = 0;
>  		u32 pkt_len;
>  
> +		if (features & (NETIF_F_RXFCS | NETIF_F_RXALL))
> +			fcs_trailer = ETH_FCS_LEN;
> +

[ ... ]

> @@ -1050,10 +1076,19 @@ static int ax88179a_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
>  		if (pkt_end > hdr_off || (pkt_cnt == 0 && pkt_end != hdr_off))
>  			goto err;
>  
> -		if (pkt_desc & AX179A_RX_PD_DROP || !(pkt_desc & AX179A_RX_PD_RX_OK) ||
> -		    pkt_len > (dev->hard_mtu + AX179A_RX_HW_PAD) || pkt_len < 2 + ETH_HLEN) {
> +		if (((pkt_desc & AX179A_RX_PD_DROP || !(pkt_desc & AX179A_RX_PD_RX_OK)) &&
> +		     !(features & NETIF_F_RXALL)) ||
> +		    pkt_len > dev->hard_mtu + AX179A_RX_HW_PAD + fcs_trailer ||
> +		    pkt_len < 2 + ETH_HLEN + fcs_trailer) {
>  			skb_pull(skb, pkt_len_plus_padd);
>  
> +			if (pkt_desc & AX179A_RX_PD_DROP)
> +				dev->net->stats.rx_dropped++;
> +
> +			if (!(pkt_desc & AX179A_RX_PD_RX_OK)) {
> +				dev->net->stats.rx_crc_errors++;
> +				dev->net->stats.rx_errors++;
> +			}

[Severity: Medium]
The commit message says "Count dropped packets and those with incorrect
FCS", but some cases don't seem to be counted.

Frames dropped only by the length checks, with AX179A_RX_PD_RX_OK set and
AX179A_RX_PD_DROP clear, are discarded without bumping any counter.
Should those increment rx_length_errors and rx_errors?

With NETIF_F_RXALL enabled, frames with AX179A_RX_PD_RX_OK clear skip
this branch entirely. rx_crc_errors and rx_errors therefore stop counting
exactly when rx-all is turned on.

If such a frame also fails a length check, it is counted after all. Could
the error accounting be done whether or not the frame is dropped?

AX179A_RX_PD_RX_OK also looks like a generic receive status bit:

	#define AX179A_RX_PD_RX_OK		BIT(11)

Is every frame without it really a CRC error? Or should only rx_errors be
incremented when the descriptor doesn't give the cause?

>  			/* Next RX Packet Descriptor */
>  			pkt_desc_ptr++;
>  			continue;

[ ... ]

> @@ -1216,12 +1254,14 @@ static int ax88179a_reset(struct usbnet *dev)
>  	ax88179_write_u8(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, *tmp);
>  
>  	/* Configure RX control register => start operation */
> -	rxctl = AX_RX_CTL_DROPCRCERR | AX_RX_CTL_START | AX_RX_CTL_AP |
> -		AX_RX_CTL_AMALL | AX_RX_CTL_AB;
> +	rxctl = AX_RX_CTL_START | AX_RX_CTL_AP | AX_RX_CTL_AMALL | AX_RX_CTL_AB;
>  	if (ax179_data->ip_align)
>  		rxctl |= AX_RX_CTL_IPE;
>  	if (dev->net->flags & IFF_PROMISC)
>  		rxctl |= AX_RX_CTL_PRO;
> +	if (dev->net->features & (NETIF_F_RXFCS | NETIF_F_RXALL) ||
> +	    ax179_data->chip_version == AX_VERSION_AX88279)
> +		rxctl |= AX_RX_CTL_DROPCRCERR;

[Severity: Medium]
This changes the default AX_RX_CTL value programmed for every AX88179A
and AX88772D user. AX_RX_CTL_DROPCRCERR used to be set unconditionally.
It is now set only when rx-fcs or rx-all is on, or when the chip is
AX88279. The commit message doesn't mention this.

This hunk also seems to complete the previous patch in the series, "net:
usb: ax88179: Make receiving FCS on AX88179A configurable", which only
changed ax88179_set_multicast(). With that patch alone, the resume path
goes:

ax88179a_resume()
  ax88179a_reset()
    sets DROPCRCERR and caches it in rxctl
ax88179a_mac_link_up()
  writes the cached rxctl back to AX_RX_CTL

So the FCS is attached again after every resume, and nothing in
ax88179a_rx_fixup() strips it.

This patch carries a Fixes: tag but also adds new rx-fcs and rx-all
toggles that show up in ethtool -k. A stable backport can't take the fix
without the feature.

Would it make sense to move this reset() change into the earlier fix and
describe it there, so this patch only adds the feature?

>  	WRITE_ONCE(ax179_data->rxctl, rxctl);
>  	ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, rxctl);

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201-fcs-v3-0-6c355917b17e%40birger-koblitz.de

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-12-04  8:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 17:17 [PATCH net-next v3 0/2] net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A Birger Koblitz
2026-12-01 17:17 ` [PATCH net-next v3 1/2] net: usb: ax88179: Make receiving FCS on AX88179A configurable Birger Koblitz
2026-12-04  8:19   ` netdev-bot+sashiko
2026-12-01 17:17 ` [PATCH net-next v3 2/2] net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A Birger Koblitz
2026-12-04  8:19   ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox