* [PATCH net-next v4 0/2] net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A
@ 2026-12-04 21:21 Birger Koblitz
2026-12-04 21:21 ` [PATCH net-next v4 1/2] net: usb: ax88179: Make receiving FCS on AX88179A configurable Birger Koblitz
2026-12-04 21:21 ` [PATCH net-next v4 2/2] net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A Birger Koblitz
0 siblings, 2 replies; 4+ messages in thread
From: Birger Koblitz @ 2026-12-04 21:21 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 v4:
- Add locking for changes in rxctl
- Include read-modify-write changes to rxctl in commit message
- Add comment to explain AX_RX_CTL_DROPCRCERR behaviour
- Link to v3: https://lore.kernel.org/r/20261201-fcs-v3-0-6c355917b17e@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 | 18 +++++++++---
drivers/net/usb/ax88179_lib.h | 1 +
drivers/net/usb/ax88179a_devices.c | 56 ++++++++++++++++++++++++++++++++++----
3 files changed, 65 insertions(+), 10 deletions(-)
---
base-commit: eb6d6c80d35449c27471b1874f13066c09a8964d
change-id: 20261126-fcs-afccb4a76dd1
Best regards,
--
Birger Koblitz <mail@birger-koblitz.de>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH net-next v4 1/2] net: usb: ax88179: Make receiving FCS on AX88179A configurable
2026-12-04 21:21 [PATCH net-next v4 0/2] net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A Birger Koblitz
@ 2026-12-04 21:21 ` Birger Koblitz
2026-12-04 21:21 ` [PATCH net-next v4 2/2] net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A Birger Koblitz
1 sibling, 0 replies; 4+ messages in thread
From: Birger Koblitz @ 2026-12-04 21:21 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.
Use read-modify-write for the changes to rxctrl on AX88179A/AX88279.
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 +++++++++++---
drivers/net/usb/ax88179a_devices.c | 3 +--
2 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/drivers/net/usb/ax88179_lib.c b/drivers/net/usb/ax88179_lib.c
index 821ee9cd8ded1b8f1e425bcef493fb175ed30376..273c5946e16a159f5f392b822942e0d393d5075f 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; /* Do not remove FCS from frame */
if (net->flags & IFF_PROMISC) {
rxctl |= AX_RX_CTL_PRO;
} else if (net->flags & IFF_ALLMULTI ||
diff --git a/drivers/net/usb/ax88179a_devices.c b/drivers/net/usb/ax88179a_devices.c
index 69095110e70435806a99274c50d79e86016ec9a0..78a804203202f7741eb62efd10c19253043a3708 100644
--- a/drivers/net/usb/ax88179a_devices.c
+++ b/drivers/net/usb/ax88179a_devices.c
@@ -1216,8 +1216,7 @@ 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)
--
2.47.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH net-next v4 2/2] net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A
2026-12-04 21:21 [PATCH net-next v4 0/2] net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A Birger Koblitz
2026-12-04 21:21 ` [PATCH net-next v4 1/2] net: usb: ax88179: Make receiving FCS on AX88179A configurable Birger Koblitz
@ 2026-12-04 21:21 ` Birger Koblitz
2026-12-05 22:22 ` netdev-bot+sashiko
1 sibling, 1 reply; 4+ messages in thread
From: Birger Koblitz @ 2026-12-04 21:21 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/ax88179_lib.c | 4 ++-
drivers/net/usb/ax88179_lib.h | 1 +
drivers/net/usb/ax88179a_devices.c | 53 +++++++++++++++++++++++++++++++++++---
3 files changed, 53 insertions(+), 5 deletions(-)
diff --git a/drivers/net/usb/ax88179_lib.c b/drivers/net/usb/ax88179_lib.c
index 273c5946e16a159f5f392b822942e0d393d5075f..dc32660a2335935bc99776b68a5fd7604fa98728 100644
--- a/drivers/net/usb/ax88179_lib.c
+++ b/drivers/net/usb/ax88179_lib.c
@@ -356,6 +356,7 @@ void ax88179_set_multicast(struct net_device *net)
data = dev->driver_priv;
+ mutex_lock(&data->rx_ctl_mutex);
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 |
@@ -397,8 +398,9 @@ void ax88179_set_multicast(struct net_device *net)
}
WRITE_ONCE(data->rxctl, rxctl);
+ mutex_unlock(&data->rx_ctl_mutex);
ax88179_write_cmd_async(dev, AX_ACCESS_MAC, AX_RX_CTL,
- 2, 2, &data->rxctl);
+ 2, 2, &rxctl);
}
int ax88179_set_features(struct net_device *net, netdev_features_t features)
diff --git a/drivers/net/usb/ax88179_lib.h b/drivers/net/usb/ax88179_lib.h
index 401c0bed3d28b4b94f0a0cad7509cd7087ef0639..a9e688424c1299f17d777b573db53c1ea81fdbfe 100644
--- a/drivers/net/usb/ax88179_lib.h
+++ b/drivers/net/usb/ax88179_lib.h
@@ -292,6 +292,7 @@ enum ax_chip_version {
struct ax88179_data {
struct mutex medium_status_mutex; /* protect AX_MEDIUM_STATUS_MODE */
+ struct mutex rx_ctl_mutex; /* protect AX_RX_CTL */
u8 eee_enabled;
u8 eee_active;
u16 rxctl;
diff --git a/drivers/net/usb/ax88179a_devices.c b/drivers/net/usb/ax88179a_devices.c
index 78a804203202f7741eb62efd10c19253043a3708..9137f790ddaa61f6f741ba3f59ab24628bbd92af 100644
--- a/drivers/net/usb/ax88179a_devices.c
+++ b/drivers/net/usb/ax88179a_devices.c
@@ -601,7 +601,9 @@ static void ax88179a_mac_link_up(struct phylink_config *config,
mode |= AX_MEDIUM_JUMBO_EN;
ax88179_write_u16(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 2, mode);
+ mutex_lock(&ax179_data->rx_ctl_mutex);
ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, READ_ONCE(ax179_data->rxctl));
+ mutex_unlock(&ax179_data->rx_ctl_mutex);
mutex_unlock(&ax179_data->medium_status_mutex);
ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_PATH, 1,
@@ -717,10 +719,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 +784,24 @@ 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;
+
+ mutex_lock(&ax179_data->rx_ctl_mutex);
+ 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);
+ mutex_unlock(&ax179_data->rx_ctl_mutex);
+
+ if (ret < 0)
+ return ret;
+ }
+
return 0;
}
@@ -852,8 +874,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 +916,9 @@ 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;
+
netif_set_tso_max_size(dev->net, 16384);
/* Enable Transmission of Link Speed byte in interrupt URB */
@@ -1039,9 +1064,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 +1080,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 +1102,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);
@@ -1221,6 +1263,9 @@ static int ax88179a_reset(struct usbnet *dev)
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] 4+ messages in thread
* Re: [PATCH net-next v4 2/2] net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A
2026-12-04 21:21 ` [PATCH net-next v4 2/2] net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A Birger Koblitz
@ 2026-12-05 22:22 ` netdev-bot+sashiko
0 siblings, 0 replies; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 22:22 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 13 potential
issue(s) to consider.
Critical: 0 · High: 2 · Medium: 6 · Low: 5
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).
- [High] The patch adds `struct mutex rx_ctl_mutex` to `struct
ax88179_data` (drivers/net/usb/ax88179_lib.h:295) and locks it in…
- [High] The patch adds mutex_lock(&data->rx_ctl_mutex) to
ax88179_set_multicast() (drivers/net/usb/ax88179_lib.c:359-401).
- [Medium] The commit message only covers the RXFCS/RXALL features, FCS-
aware length checks and new counters.
- [Medium] The preceding commit 'net: usb: ax88179: Make receiving FCS on
AX88179A configurable', which carries a Fixes: tag, removed…
- [Medium] In ax88179a_rx_fixup(), the RXALL handling and the new error
accounting are incomplete.
- [Medium] In ax88179_set_multicast() (drivers/net/usb/ax88179_lib.c),
mutex_unlock(&data->rx_ctl_mutex) at line 401 comes before…
- [Medium] ax88179_set_multicast() clears AX_RX_CTL_DROPCRCERR and re-
derives it from `net->features & (NETIF_F_RXFCS | NETIF_F_RXALL)`.
- [Medium] net: usb: ax88179: unlocked AX_RX_CTL updates in reset() and
mac_link_up()
- [Low] The patch mainly adds new user-visible functionality:
NETIF_F_RXFCS and NETIF_F_RXALL in hw_features for AX88179A…
- [Low] In ax88179a_set_features(), WRITE_ONCE(ax179_data->rxctl, rxctl)
at ax88179a_devices.c:797 stores the new DROPCRCERR state before…
- [Low] Whether a frame carries an FCS is fixed by the
AX_RX_CTL_DROPCRCERR setting at the moment the hardware receives it,…
- [Low] ax88179a_mac_link_up() writes AX_RX_CTL_STOP at
ax88179a_devices.c:515 ('Stop RX/TX for link configuration') without…
- [Low] The new increments of dev->net->stats.rx_dropped, rx_crc_errors
and rx_errors in ax88179a_rx_fixup() (ax88179a_devices.c:1089-1094)…
--
net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A
This patch advertises NETIF_F_RXFCS and NETIF_F_RXALL on the AX88179A. It
toggles AX_RX_CTL_DROPCRCERR so the MAC keeps the FCS, and it accounts for
the trailing FCS in the ax88179a_rx_fixup() length checks. It also counts
dropped and bad-FCS frames and adds a new rx_ctl_mutex around AX_RX_CTL
updates.
> 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.
[Severity: Medium]
Should the commit message also describe the locking changes? The patch also
does the following:
- adds rx_ctl_mutex ("protect AX_RX_CTL") to struct ax88179_data
- takes it in ax88179_set_multicast(), which ax88179_178a.c also uses
for the older AX88179/AX88178A devices
- makes the async AX_RX_CTL write use a stack copy (&rxctl) instead of
&data->rxctl
The message doesn't say which race the mutex is meant to close. It also
doesn't say that the older driver is affected. The two locking problems
raised further down both come from this change.
> Fixes: 7d573278f9a5 ("ax88179_178a: Add HW support for AX179A-based chips")
[Severity: Low]
This isn't a bug, but is this Fixes: tag accurate? Most of the patch is new
functionality: NETIF_F_RXFCS/NETIF_F_RXALL in hw_features and new error
counters. With default features the AX88179A strips the FCS, so the old
length check in ax88179a_rx_fixup() was already correct.
The only real fix here is restoring AX_RX_CTL_DROPCRCERR for AX88279 in
ax88179a_reset(). That fixes the preceding commit in this series, not
7d573278f9a5.
Could this tag lead stable to backport the new feature toggles?
> diff --git a/drivers/net/usb/ax88179_lib.c b/drivers/net/usb/ax88179_lib.c
> index 273c5946e16a1..dc32660a23359 100644
> --- a/drivers/net/usb/ax88179_lib.c
> +++ b/drivers/net/usb/ax88179_lib.c
> @@ -356,6 +356,7 @@ void ax88179_set_multicast(struct net_device *net)
>
> data = dev->driver_priv;
>
> + mutex_lock(&data->rx_ctl_mutex);
[Severity: High]
Can ax88179_set_multicast() sleep here? It is the .ndo_set_rx_mode callback
for both ax88179a_netdev_ops and the legacy ax88179_netdev_ops in
ax88179_178a.c. Neither sets ndo_set_rx_mode_async, so the core calls it in
atomic context:
include/linux/netdevice.h:
* void (*ndo_set_rx_mode)(struct net_device *dev);
...
* Cannot sleep, called with netif_addr_lock_bh held.
net/core/dev_addr_lists.c:dev_set_rx_mode() {
netif_addr_lock_bh(dev);
__dev_set_rx_mode(dev);
netif_addr_unlock_bh(dev);
}
mutex_lock() calls might_sleep(), so CONFIG_DEBUG_ATOMIC_SLEEP would warn
on every call.
Both ax88179a_mac_link_up() (phylink resolve worker) and
ax88179a_set_features() (ethtool -K) hold rx_ctl_mutex across synchronous
USB control transfers. If one of them holds it when the rx-mode callback
runs, mutex_lock() sleeps with a BH-disabling spinlock held. Would that end
in "scheduling while atomic"?
An unprivileged multicast join through dev_mc_add() is enough to reach this
path. That includes the older AX88179/AX88178A devices.
Would a spinlock, or a move to ndo_set_rx_mode_async, work better here?
> 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 |
> @@ -397,8 +398,9 @@ void ax88179_set_multicast(struct net_device *net)
> }
>
> WRITE_ONCE(data->rxctl, rxctl);
> + mutex_unlock(&data->rx_ctl_mutex);
> ax88179_write_cmd_async(dev, AX_ACCESS_MAC, AX_RX_CTL,
> - 2, 2, &data->rxctl);
> + 2, 2, &rxctl);
[Severity: Medium]
The async write is submitted after mutex_unlock(). Does the mutex then
control the order in which values reach the hardware? Consider:
CPU0 (ax88179_set_multicast)
computes X
WRITE_ONCE(data->rxctl, X)
mutex_unlock()
CPU1 (ax88179a_set_features)
mutex_lock()
Y = X | AX_RX_CTL_DROPCRCERR
WRITE_ONCE(ax179_data->rxctl, Y)
ax88179_write_u16(..., AX_RX_CTL, 2, Y) /* synchronous */
mutex_unlock()
CPU0
ax88179_write_cmd_async(..., AX_RX_CTL, ..., &rxctl) /* X */
The hardware then holds X while data->rxctl and dev->features say Y. If
DROPCRCERR differs, ax88179a_rx_fixup() gets the FCS handling wrong for
every frame until the next rx-mode change.
This callback has to stay atomic, so the write can't simply move inside the
mutex.
[ ... ]
> diff --git a/drivers/net/usb/ax88179_lib.h b/drivers/net/usb/ax88179_lib.h
> index 401c0bed3d28b..a9e688424c129 100644
> --- a/drivers/net/usb/ax88179_lib.h
> +++ b/drivers/net/usb/ax88179_lib.h
> @@ -292,6 +292,7 @@ enum ax_chip_version {
>
> struct ax88179_data {
> struct mutex medium_status_mutex; /* protect AX_MEDIUM_STATUS_MODE */
> + struct mutex rx_ctl_mutex; /* protect AX_RX_CTL */
[Severity: High]
Where is rx_ctl_mutex initialized? Both bind routines allocate this struct
with kzalloc but only initialize medium_status_mutex:
drivers/net/usb/ax88179a_devices.c:ax88179a_bind() {
...
dev->driver_priv = ax179_data;
mutex_init(&ax179_data->medium_status_mutex);
...
}
ax88179_bind() in drivers/net/usb/ax88179_178a.c has the same single
mutex_init() call. Its ndo_set_rx_mode is ax88179_set_multicast(), so it
now locks this mutex too.
With CONFIG_DEBUG_MUTEXES, the lock->magic check fires on lock and unlock.
With lockdep, the uninitialized dep_map triggers a non-static key report and
lockdep turns itself off.
Should mutex_init(&ax179_data->rx_ctl_mutex) be added next to the
medium_status_mutex init in both ax88179a_bind() and ax88179_bind()?
> u8 eee_enabled;
> u8 eee_active;
> u16 rxctl;
> diff --git a/drivers/net/usb/ax88179a_devices.c b/drivers/net/usb/ax88179a_devices.c
> index 78a804203202f..9137f790ddaa6 100644
> --- a/drivers/net/usb/ax88179a_devices.c
> +++ b/drivers/net/usb/ax88179a_devices.c
> @@ -601,7 +601,9 @@ static void ax88179a_mac_link_up(struct phylink_config *config,
> mode |= AX_MEDIUM_JUMBO_EN;
> ax88179_write_u16(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 2, mode);
>
> + mutex_lock(&ax179_data->rx_ctl_mutex);
> ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, READ_ONCE(ax179_data->rxctl));
> + mutex_unlock(&ax179_data->rx_ctl_mutex);
[Severity: Low]
Is it enough to cover only the restore write here? Earlier in the function,
RX is stopped without the mutex:
ax88179a_mac_link_up() {
/* Stop RX/TX for link configuration */
ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, AX_RX_CTL_STOP);
...
ax88179a_bulkin_config(dev, link_sts, bulk_config_speed, !!duplex);
...
}
ax88179a_mac_link_up() runs from the phylink resolve worker without RTNL.
It can therefore run at the same time as ax88179a_set_features().
The new synchronous AX_RX_CTL write in ax88179a_set_features() writes the
cached rxctl, which has AX_RX_CTL_START set. If that write lands inside this
window, could it restart RX while the bulk-in/CDC parameters are only partly
programmed?
The async write in ax88179_set_multicast() could already land in this window
before this patch. This patch adds another writer.
> mutex_unlock(&ax179_data->medium_status_mutex);
>
> ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_PATH, 1,
[ ... ]
> @@ -780,6 +784,24 @@ 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;
> +
> + mutex_lock(&ax179_data->rx_ctl_mutex);
> + 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);
[Severity: Low]
What happens to the cached rxctl if this USB write fails? WRITE_ONCE() has
already stored the new DROPCRCERR state. On the error return the core leaves
dev->features unchanged, but nothing rolls data->rxctl back.
On the next link flap, ax88179a_mac_link_up() writes
READ_ONCE(ax179_data->rxctl) to AX_RX_CTL unchanged. The MAC then keeps or
strips the FCS opposite to what dev->features says. This lasts until an
rx-mode change recomputes the bit.
[Severity: Medium]
Can an rx-mode update undo this change? ax88179_set_multicast() clears
AX_RX_CTL_DROPCRCERR and re-derives it from net->features:
if (net->features & (NETIF_F_RXFCS | NETIF_F_RXALL) ||
data->chip_version != AX_VERSION_AX88179A)
rxctl |= AX_RX_CTL_DROPCRCERR; /* Do not remove FCS from frame */
__netdev_update_features() only assigns dev->features after ndo_set_features
returns, and rx_ctl_mutex doesn't cover net->features.
An rx-mode update can run in that window, for example an IPv6 MLD join
calling dev_mc_add() under idev->mc_lock without RTNL. It reads the old
features and reverts DROPCRCERR. The core then commits the new features.
>From then on the hardware and ax88179a_rx_fixup() disagree on FCS presence
for every frame.
> + mutex_unlock(&ax179_data->rx_ctl_mutex);
> +
> + if (ret < 0)
> + return ret;
> + }
> +
> return 0;
> }
[ ... ]
> @@ -1039,9 +1064,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;
[Severity: Low]
Is the live dev->net->features a reliable indication of whether this frame
has an FCS? Whether the FCS is present depends on AX_RX_CTL_DROPCRCERR at
the time the hardware received the frame. The descriptor has no bit for it.
ax88179a_set_features() reprograms AX_RX_CTL before the core updates
dev->features, and it doesn't stop or flush RX. Several 48 KiB bulk-in URBs
can still hold frames in the old format.
During an rx-fcs/rx-all toggle, frames without an FCS could lose 4 bytes of
payload to the later pkt_len -= fcs_trailer. Frames with an FCS could have
it delivered as payload.
Would it make sense to reset or quiesce RX on these feature changes, as igb
does?
> 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 +1080,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]
Are the error counters complete? They are only updated inside this drop
branch, which leaves two gaps:
- With NETIF_F_RXALL enabled, a bad-FCS frame (RX_OK clear) with a valid
length skips this branch. It goes to the stack without incrementing
rx_crc_errors or rx_errors.
- A frame dropped only by the pkt_len checks, with PD_DROP clear and
RX_OK set, increments nothing.
Both seem to contradict "Count dropped packets and those with incorrect
FCS" in the commit message.
The only hardware change RXALL makes is setting AX_RX_CTL_DROPCRCERR, the
same bit RXFCS sets. The preceding commit says this bit doesn't affect
whether the adapter drops corrupt frames. Does RXALL then only skip the
software check of the descriptor error flags?
Frames let through under RXALL with PD_DROP set or RX_OK clear still go
through ax88179a_rx_checksum() and __vlan_hwaccel_put_tag() using
descriptor fields. Can those fields be trusted for errored frames?
[Severity: Low]
These dev->net->stats increments are plain non-atomic read-modify-writes,
and ax88179a_rx_fixup() runs from the usbnet BH work. usbnet's
rx_complete() also updates dev->net->stats.rx_errors from URB completion
context, which may run on another CPU. Can increments be lost here?
This follows existing usbnet practice. Would
dev_core_stats_rx_dropped_inc() or per-CPU stats be a better fit for the
new counters?
> /* Next RX Packet Descriptor */
> pkt_desc_ptr++;
> continue;
[ ... ]
> @@ -1221,6 +1263,9 @@ static int ax88179a_reset(struct usbnet *dev)
> 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]
Does ax88179a_reset() also need to take rx_ctl_mutex? It rebuilds
rxctl from dev->net->flags and dev->net->features, stores it with
WRITE_ONCE(ax179_data->rxctl, rxctl) and writes AX_RX_CTL, all without
the new lock.
ax88179a_resume() calls ax88179a_reset() before it takes rtnl_lock(),
and the netdev is already present again at that point. So
ax88179a_set_features() and ax88179_set_multicast() can run at the
same time as the reset:
CPU0 (ax88179a_set_features, ethtool -K rx-fcs on)
mutex_lock(&ax179_data->rx_ctl_mutex)
rxctl |= AX_RX_CTL_DROPCRCERR
WRITE_ONCE(ax179_data->rxctl, rxctl)
ax88179_write_u16(..., AX_RX_CTL, 2, rxctl)
mutex_unlock(&ax179_data->rx_ctl_mutex)
CPU1 (ax88179a_resume -> ax88179a_reset)
reads dev->net->features, still without NETIF_F_RXFCS
rxctl = AX_RX_CTL_START | ... /* no DROPCRCERR */
WRITE_ONCE(ax179_data->rxctl, rxctl)
ax88179_write_u16(..., AX_RX_CTL, 2, rxctl)
The core then commits NETIF_F_RXFCS to dev->features. Both the cached
rxctl and the hardware still strip the FCS. From then on
ax88179a_rx_fixup() assumes every frame carries an FCS that the MAC has
already removed. If the two writes land in the other order, an rx-mode
update is lost the same way.
The AX_RX_CTL_STOP write at the top of ax88179a_mac_link_up() has the
same gap. The lock is only taken for the final restore of the cached
value. A set_features or set_multicast write that lands between the
STOP and the restore can set AX_RX_CTL_START while the bulk-in, CDC
and medium registers are only partly programmed.
Should ax88179a_reset() hold rx_ctl_mutex while it builds and writes
rxctl? And should ax88179a_mac_link_up() hold it from the STOP write
through the restore? The second option makes the mutex cover a long run
of synchronous USB transfers, and the atomic rx-mode path can't wait on
that anyway. A different scheme may be needed there.
[Severity: Medium]
Should the AX88279 part of this go into the preceding commit, "net: usb:
ax88179: Make receiving FCS on AX88179A configurable"? That commit removed
AX_RX_CTL_DROPCRCERR from the base rxctl here for every AX179A-family chip,
including the AX88279. Its own message says "For AX88279-based adapters,
the flag must be set in order to receive complete frames".
With only that patch applied, a resume runs ax88179a_reset() and then
ax88179a_mac_link_up(). The latter writes the cached rxctl without
DROPCRCERR. Until an rx-mode change, the AX88279 can then receive incomplete
frames.
This patch quietly restores the bit. It also rewrites the ax88179a_bind()
comment that the previous patch made false. Its commit message mentions
neither change.
Since the previous patch carries a Fixes: tag, could stable pick it up
without this follow-up?
> 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/20261204-fcs-v4-0-32773b612c81%40birger-koblitz.de
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-05 22:22 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 21:21 [PATCH net-next v4 0/2] net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A Birger Koblitz
2026-12-04 21:21 ` [PATCH net-next v4 1/2] net: usb: ax88179: Make receiving FCS on AX88179A configurable Birger Koblitz
2026-12-04 21:21 ` [PATCH net-next v4 2/2] net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A Birger Koblitz
2026-12-05 22:22 ` 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