Skip to contentSkip to conversation

ax88179_178a: Add support for AX88179A-based chips

PATCH Applied Birger Koblitz 4 participants 40 messages Nov 14 – Nov 19

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

v21 cover ax88179_178a: Add support for AX88179A-based chips

This adds support for the current generation of ASIX network adapter chips, which are based on the AX88179A. This includes the AX88179A/B (1GBit-PHY), AX88772D/E (100MBit) and AX88279 (2.5GBit).

The AX179A-based chips all provide both a CDC-NCM compatible USB interface, and a proprietary vendor interface with more features. By default, the proprietary vendor interface is not active and Linux will load the CDC-NCM driver to support the devices. If the ax88179_178a module is configured by the OS to have precedence over CDC-NCM, then this driver will switch the device to use the vendor interface, and the device will be controlled by the ax88179_178a driver when the device is probed again after an automatic reset of the device bringing up the vendor interface.

The following hardware was tested:
Delock 66046 2.5GBit adapter (AX88279, FW: 1.2.0.0) TP-Link UE306 1GBit adapter (AX88179B, FW: 1.3.0.0) Renkforce RF-4708614 1GBit adapter (AX88179A, FW: 1.0.4.0) UGREEN CR110 100MBit adapter (AX88722E, FW: 1.3.0.0)

The driver supports the following features
- EEE
- TCP segmentation offload
- VLAN filtering/tagging offload (NETIF_F_HW_VLAN_CTAG_FILTER, NETIF_F_HW_VLAN_CTAG_RX/TX)
- RX/TX checksum offload
- FC/Pause configuration
- EEPROM read access

The code is based on the ASIX 4.1.0 out-of-tree driver published under the GPL,, the aqc111 driver which provides support for the AX88279A, and some tracing of USB-transfers of the Windows-driver.

---
Changes in v21:
- Drop "default y" in Kconfig for driver
- Rebased and switched to kmalloc_objs
- Link to v20: https://lore.kernel.org/r/[email protected]

Changes in v20:
- fixed goto-label being called in patch before label defined in later patch
- Link to v19: https://lore.kernel.org/r/[email protected]

Changes in v19:
- Use WRITE_ONCE to set net->mtu and move before changing JUMBO-register flag
- Set TX-Offload HW flags depending on dev->net->features at reset
- In ax88179_set_features() init stack variables to prevent leaking stack memory to device
- Fix back writing of VLAN table using Write-Execute bit, add futher comments and make sure VFE and VSO bits are preserved
- Make manipulating data->rxctl in ax88179_set_multicast() atomic
- Include include phylink_resume() in error-exit path of suspend(()
- Exclude setting MAC-address in resume path in ax88179a_reset()
- Ensure to restart auto-negotiation if a user only changes the
2.5G advertisement bit
- Link to v18: https://lore.kernel.org/r/[email protected]

Changes in v18:
- Add also check for PHY_BROKEN_FORCED in phy_mii_ioctl() to prevent
users to circumvent check via ioctl.
- Do not unconditionally dereference phydev->drv when it might be NULL
in phy_ethtool_ksettings_set()
- Fix RTNL deadlock accessing mtu-settings by using dedicated lock for mtu access
- Use get_unaligned_le64() instead of le64_to_cpup() to
support older architectures
- Add check for skb_cloned() before buffer resize
- Add explicit handling of disabling of NETIF_F_HW_VLAN_CTAG_FILTER
- Fix clobbering of AX_VLAN_CONTROL_VFE bit when setting AX_VLAN_CONTROL_WE
- Do no longer use XOR to change AX_VLAN_CONTROL_VFE by conditional clear/set
of bit in if/else block to prevent theoretical de-synching of bit and OS state
- Make sure interface is enabled when resuming phylink in suspend error-path
- Fix leaking in_pm / unbalanced suspend_count in suspend error-path
- Add pm_runtime_put_noidle() to unbind()
- Reorder setting MII_ADVERTISE and genphy_config_aneg()
- Remove possible 1000M-bits reported by AX88772D when reading MII_ESTATUS
- Link to v17: https://lore.kernel.org/r/[email protected]

Changes in v17:
- Fix clang warnings from kernel-robot
- Link to v16: https://lore.kernel.org/r/[email protected]

Changes in v16:
- Fix error-checking in VLAN-offload code
as Suggested-by: Jianhui Xu <[email protected]>
- Link to v15: https://lore.kernel.org/r/[email protected]

Changes in v15:
- Removed already committed patch fixing pause watermark register
endianess
- Rebased
- Link to v14: https://lore.kernel.org/r/[email protected]

Changes in v14:
- Fix return value handling in VLAN offload functions
- Add explanatory comment for phylink_mac_interrupt()
- Link to v13: https://lore.kernel.org/r/[email protected]

Changes in v13:
- Add MODULE_ALIAS to ax88179_178a
- Squashed commit adding netdev2data() into the first one needing it
- Add wrappers ax88179_write_u8/ax88179_write_u16
- Use FIELD_GET() FIELD_PREP() in fixups.
- Add guard for phydev->drv NULL in phy_ethtool_ksettings_set()
- Various endianess fixes in fixups
- Add error checking for too small packets in ax88179a_rx_fixup
- Typo fixed: ax88179_read_cmd -> ax88179_write_cmd setting PHY power
- Changed call to usbnet_nway_reset by phy_ethtool_nway_reset
- ax88179a_bulkin_config() handles FS USB now for all chip versions
- Use phylink versions of calls for get/set_link_ksettings
- Add handling of return values of ax88179_read_cmd() in various places
- Removed usbnet_link_change(dev, 0, 0); at the end of ax88179a_reset().
- Add RTLN-lock to protect AX_MEDIUM_STATUS_MODE register,
WRITE_ONCE/READONCE for rxctl.
- Changed to clearing AX_XGMII_EN for all speeds != SPEED_2500 independent
of chip-id.
- Fix access to AX88179A_MAC_RX_DATA_CDC_CNT by using 2 1-byte writes.
- In ax88179a_mac_link_up initialize link_status.
- Added setting of AX_GPHY_EEE_CTRL to disabled in ax88179a_reset(),
consistent with phylink default.
- Various commit messages fixed
- Conditionally set AX_VLAN_CONTROL_VFE after loop over the VLAN-entries
- Moved code in wrong commits to the right ones (2x).
- Fix races around rx_checksum flag setting.
- Suspend/resume fixes: correct sequence of WoL settings and usbnet/phylink suspend calls.
- Read revision number into the 4th field of software version
- Kconfig descriptiona and module description mention 2.5GBit
- Fix orphaned defconfigs
- Fix EEPROM access settings derived from chip versions
- Fix EEPROM read error checking
- Return value checking in asix_ax88279_read_status()
- Added clearing of ETHTOOL_LINK_MODE_2500baseT_Full_BIT in lp_advertising before modifying the bit.
- In asix_ax88279_read_status() add if (!phydev->link) guard
- Linkmode cleaning code shortened.
- Link to v12: https://lore.kernel.org/r/[email protected]

Changes in v12:
- Fix BCD ranges for USB device detection
- Free SKB in ax88179a_tx_fixup() when skb_linearize() fails
- Use phylink_mii_ioctl instead of usbnet_mii_ioctl
- Link to v11: https://lore.kernel.org/r/[email protected]

Changes in v11:
- Fix sparse warnings
- Link to v10: https://lore.kernel.org/r/[email protected]

Changes in v10:
- Fix missing variable declaration in ax88179a_status()
- Add reviewed-bys
- Link to v9: https://lore.kernel.org/r/[email protected]

Changes in v9:
- Fix ax88179a_status() to not call carrier-related netif or usbnet methods
- Use genphy_read_mmd_c45() and genphy_write_mmd_c45()
- Link to v8: https://lore.kernel.org/r/[email protected]

Changes in v8:
- Fix resume sequence as Suggested-by: Jianhui Xu <[email protected]>
- Add handling of PHYs with broken forced mode in phylib to handle AX88279 PHY
- Multple formatting fixes
- Fix transiently unused functions ax88179a_mac_disable_tx_lpi() and ax88179a_mac_enable_tx_lpi()
- Removed unnecessary checks for dev initialized
- Link to v7: https://lore.kernel.org/r/[email protected]

Changes in v7:
- Add phylink_mac_interrupt() function to phylink and stop
polling the PHY to prevent a race condition between the controller
and phylink when configuring a new link.
- Fix typo in ax88179_read_cmd Reported-by: Jianhui Xu <[email protected]>
- Return -EOPNOTSUPP in asix_ax88279_config_aneg when autoneg is being disabled
- Link to v6: https://lore.kernel.org/r/[email protected]

Changes in v6:
- Use genphy_read_status() in asix_ax88279_read_status()
- Use SGMII and 2500BaseX interfaces for PHY
- Fix speed determination of MAC/PHY link
- Fix bulk transfer configuration to use enums for bulk configuration types
- Link to v5: https://lore.kernel.org/r/[email protected]

Changes in v5:
- Fixed read_status() and config_aneg() in PHY driver
- Introduced netdev2data() as convenience function
- netdev_info instances and debugging relicts removed
- Several instances of badly written/formatted code that was copy and pasted from the original driver corrected
- select PHYLINK added to Kconfig when phylib dependency added
- PHYLINK selects PHYLIB, so not needed to specify separately
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- Split driver into library part and part2 for AX88179 and AX88179A-based controllers
- Driver renamed ax88179
- Improved phylink use: use phylink standard functions for speed and EEE-settings, correct MAC capabilities, removed ax88179_status() irq-urb callback
- Fixes in PHY driver for AX88179A integrated PHYs
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Add PHY drivers for the PHYs of the AX88179A-based controllers
- Use phylink for the AX88179A-based chips
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Correctly use net-next prefix
- Fix compilation issue in HW support patch
- Split MMD support patch into patches for EEE/new chip support
- Do not use ADVERTISE_RESV but private flag definition
- Fix pause configuration to keep track of settings when autoneg disabled
- Fix issue with unitialized variable reported by kernel test robot <[email protected]>
- Avoid white-space changes

- Link to v1: https://lore.kernel.org/r/[email protected]

---
Birger Koblitz (13):

      phylink: Add phylink_mac_interrupt
      phylib: Add support for PHYs with broken forced mode
      ax88179_178a: Split driver into library and device specific code
      ax88179_178a: Add HW support for AX179A-based chips
      ax88179_178a: Add EEE configuration support for AX88179A MACs
      ax88179_178a: Add EEE configuration support for AX88179A PHYs
      ax88179_178a: Add VLAN offload support for AX88179A
      ax88179_178a: Add AX179A/AX279 multicast configuration
      ax88179_178a: Add Suspend/resume support for AX88179A/772D/279
      ax88179_178a: Add ethtool get_drvinfo
      ax88179_178a: Update driver name and information
      ax88179_178a: Add support for AX88179A/772D/279 EEPROM access
      ax88796b: Add support for AX88772D, AX88179A and AX88279
 MAINTAINERS                                 |    6 +
 arch/loongarch/configs/loongson32_defconfig |    2 +-
 arch/loongarch/configs/loongson64_defconfig |    2 +-
 drivers/net/phy/ax88796b.c                  |  165 ++++
 drivers/net/phy/phy.c                       |    7 +
 drivers/net/phy/phylink.c                   |   20 +
 drivers/net/usb/Kconfig                     |   11 +-
 drivers/net/usb/Makefile                    |    3 +-
 drivers/net/usb/ax88179_178a.c              |  659 +-------------
 drivers/net/usb/ax88179_lib.c               |  545 +++++++++++
 drivers/net/usb/ax88179_lib.h               |  360 ++++++++
 drivers/net/usb/ax88179a_devices.c          | 1311 +++++++++++++++++++++++++++
 include/linux/phy.h                         |    1 +
 include/linux/phylink.h                     |    1 +
 14 files changed, 2471 insertions(+), 622 deletions(-)

---
base-commit: 6964ff21c5d8b75649211a52dbfd92753e605649
change-id: 20260630-ax88179a-a1d89fe21730

Best regards,

Signature · 1 line
Birger Koblitz <[email protected]>
#1 lore raw

PATCH v21 1/13 phylink: Add phylink_mac_interrupt

Add the phylink_mac_interrupt() function to phylink, which passes a link-change interrupt received by the MAC to phylib. This function can be used by drivers which want to avoid polling the PHY and instead rely on an interrupt received by the MAC when a link-change happens.

---
 drivers/net/phy/phylink.c | 20 ++++++++++++++++++++
 include/linux/phylink.h   |  1 +
 2 files changed, 21 insertions(+)
drivers/net/phy/phylink.c +20 -0
index e885da1c28311a12a869e29ceb3c96886f31adc6..a87eaa2f3db5bef8fe56e12b90375bdb7f9c52e7 100644
@@ -1616,6 +1616,26 @@ static bool phylink_link_is_up(struct phylink *pl)
 	return pl->netdev ? netif_carrier_ok(pl->netdev) : pl->old_link_state;
 }
 
+/**
+ * phylink_mac_interrupt() - wrapper for phy_mac_interrupt()
+ * @pl: a pointer to a &struct phylink returned from phylink_create()
+ *
+ * Passes a link-change interrupt received by the MAC to phylib.
+ * This function may be called in interrupt context, and therefore cannot take
+ * a mutex. However, it is safe to assume that the reference to phy does not
+ * disappear during the call, as only an SFP module may be unplugged to make a
+ * PHY disappear. SFP modules however do not support interrupts.
+ */
+void phylink_mac_interrupt(struct phylink *pl)
+{
+	struct phy_device *phy;
+
+	phy = pl->phydev;
+	if (phy)
+		phy_mac_interrupt(phy);
+}
+EXPORT_SYMBOL_GPL(phylink_mac_interrupt);
+
 static void phylink_resolve(struct work_struct *w)
 {
 	struct phylink *pl = container_of(w, struct phylink, resolve);
include/linux/phylink.h +1 -0
index 3a88a69882a610afb868b55df6f6e77aea918649..a7b6294cc4a075bd2aaa43ed6484de17a6cb88b1 100644
@@ -768,6 +768,7 @@ int phylink_ethtool_set_eee(struct phylink *link, struct ethtool_keee *eee);
 int phylink_mii_ioctl(struct phylink *, struct ifreq *, int);
 int phylink_speed_down(struct phylink *pl, bool sync);
 int phylink_speed_up(struct phylink *pl);
+void phylink_mac_interrupt(struct phylink *pl);
 
 #define phylink_zero(bm) \
 	bitmap_zero(bm, __ETHTOOL_LINK_MODE_MASK_NBITS)
Signature · 1 line
2.47.3
#2 lore raw

Re: [PATCH net-next v21 01/13] phylink: Add phylink_mac_interrupt

Sashiko has reviewed this patch and found no issues.
Quoted 7 lines

Add the phylink_mac_interrupt() function to phylink, which passes a link-change interrupt received by the MAC to phylib. This function can be used by drivers which want to avoid polling the PHY and instead rely on an interrupt received by the MAC when a link-change happens.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

Re: [PATCH net-next v21 01/13] phylink: Add phylink_mac_interrupt

In reply to Birger Koblitz
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

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

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

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] phylink_mac_interrupt() (drivers/net/phy/phylink.c:1629-1637) is meant to be called from interrupt context.

--

phylink: Add phylink_mac_interrupt

This adds an exported helper, phylink_mac_interrupt(), that MAC drivers can call from interrupt context. It forwards a link-change interrupt seen by the MAC to phylib by calling phy_mac_interrupt() on the attached PHY. Drivers can then skip polling the PHY.

Quoted 15 lines
drivers/net/phy/phylink.c +7 -0
index e885da1c28311..a87eaa2f3db5b 100644
@@ -1616,6 +1616,26 @@ static bool phylink_link_is_up(struct phylink *pl)
 	return pl->netdev ? netif_carrier_ok(pl->netdev) : pl->old_link_state;
 }
 
+/**
+ * phylink_mac_interrupt() - wrapper for phy_mac_interrupt()
+ * @pl: a pointer to a &struct phylink returned from phylink_create()
+ *
+ * Passes a link-change interrupt received by the MAC to phylib.
+ * This function may be called in interrupt context, and therefore cannot take
+ * a mutex. However, it is safe to assume that the reference to phy does not

drivers/net/phy/phylink.c static bool phylink_link_is_up(struct phylink *pl) · line 1635

Quoted 10 lines
drivers/net/phy/phylink.c +10 -0
+ * disappear during the call, as only an SFP module may be unplugged to make a
+ * PHY disappear. SFP modules however do not support interrupts.
+ */
+void phylink_mac_interrupt(struct phylink *pl)
+{
+	struct phy_device *phy;
+
+	phy = pl->phydev;
+	if (phy)
+		phy_mac_interrupt(phy);

[Severity: Medium]

Does the lifetime argument in the kernel-doc above hold?

pl->phydev is read here with a plain load. No lock, RCU or reference is taken. Every writer, phylink_bringup_phy() and phylink_disconnect_phy(), changes it while holding phydev_mutex, phy->lock and state_mutex. KCSAN would likely report this as a data race.

The pointer is then used by phy_mac_interrupt()->phy_trigger_machine(), which calls mod_delayed_work() on phy->state_queue.

phylink_disconnect_phy() is not specific to SFP. It does not wait for a phylink_mac_interrupt() call that is already running:

drivers/net/phy/phylink.c:phylink_disconnect_phy() {
    ...
		pl->phydev = NULL;
    ...
	if (phy) {
		flush_work(&pl->resolve);
		phy_disconnect(phy);
	}
}

phy_disconnect() goes through phy_stop_machine(), which calls cancel_delayed_work_sync(&phydev->state_queue). Then phy_detach() drops the attach reference.

Suppose an IRQ loaded the old pointer before pl->phydev was cleared. Can it then queue state_queue again after the cancel, on a PHY that has already been stopped and detached?

The SFP part of the argument may not hold either. SFP module PHYs are also stored in pl->phydev, via phylink_sfp_connect_phy()->phylink_bringup_phy(), and phylink_mac_interrupt() does not check phy->is_on_sfp_module.

The interrupt comes from the MAC, not from the SFP PHY. Removing a module is just the kind of event that makes a MAC or PCS report a link change.

When the module is removed, sfp_sm_phy_detach() does:

	sfp_remove_phy(sfp->sfp_bus);
	phy_device_remove(sfp->mod_phy);
	phy_device_free(sfp->mod_phy);

Here sfp_remove_phy() ends up in phylink_sfp_disconnect_phy()->phylink_disconnect_phy().

If a MAC hardirq has already loaded the old pl->phydev, could mod_delayed_work() run on a phy_device that has already been freed?

The only caller in this series, ax88179a_status(), looks safe. usbnet_stop() kills the status URB before ->unbind() calls phylink_disconnect_phy(). The concern is the contract of the exported API. The kernel-doc says the call is safe and does not tell callers to mask and synchronize the MAC interrupt before phylink_disconnect_phy() or PHY teardown.

Should the kernel-doc state that requirement, or should phylink_mac_interrupt() protect the pl->phydev pointer itself?

Quoted 2 lines
drivers/net/phy/phylink.c +2 -0
+}
+EXPORT_SYMBOL_GPL(phylink_mac_interrupt);

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261114-ax88179a-v21-0-c2d34410bcbe%40birger-koblitz.de
#4 lore raw

PATCH v21 2/13 phylib: Add support for PHYs with broken forced mode

In reply to Birger Koblitz

Add support for PHYs which only supported auto-negotiated speed modes. This prevents a kernel warning and stack-trace within the phy_state_machine when PHYs return -EOPNOTSUPP from config_aneg() because they do not support forced modes.

---
 drivers/net/phy/phy.c | 7 +++++++
 include/linux/phy.h   | 1 +
 2 files changed, 8 insertions(+)
drivers/net/phy/phy.c +7 -0
index fce9bc7be3304b408c9f3ec9b5b95c76d3680a88..079c53516f424ca5f8d50292f1912af04b45b07a 100644
@@ -354,6 +354,9 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd)
 			switch (devad) {
 			case MII_BMCR:
 				if ((val & (BMCR_RESET | BMCR_ANENABLE)) == 0) {
+					if (phydev->drv &&
+					    (phydev->drv->flags & PHY_BROKEN_FORCED))
+						return -EOPNOTSUPP;
 					if (phydev->autoneg == AUTONEG_ENABLE)
 						change_autoneg = true;
 					phydev->autoneg = AUTONEG_DISABLE;
@@ -1190,6 +1193,10 @@ int phy_ethtool_ksettings_set(struct phy_device *phydev,
 	      duplex != DUPLEX_FULL)))
 		return -EINVAL;
 
+	if (autoneg == AUTONEG_DISABLE && phydev->drv &&
+	    (phydev->drv->flags & PHY_BROKEN_FORCED))
+		return -EOPNOTSUPP;
+
 	mutex_lock(&phydev->lock);
 	phydev->autoneg = autoneg;
 
include/linux/phy.h +1 -0
index 21afc2082b1741ff276a9588246c2f98351464f5..f1b1ad1dd82f5c51ddd2f0759666e17802894c96 100644
@@ -64,6 +64,7 @@ extern const int phy_basic_ports_array[3];
 #define PHY_RST_AFTER_CLK_EN	0x00000002
 #define PHY_POLL_CABLE_TEST	0x00000004
 #define PHY_ALWAYS_CALL_SUSPEND	0x00000008
+#define PHY_BROKEN_FORCED	0x00000010
 #define MDIO_DEVICE_IS_PHY	0x80000000
 
 /**
Signature · 1 line
2.47.3
#5 lore raw

Re: [PATCH net-next v21 02/13] phylib: Add support for PHYs with broken forced mode

Sashiko has reviewed this patch and found no issues.
Quoted 6 lines

Add support for PHYs which only supported auto-negotiated speed modes. This prevents a kernel warning and stack-trace within the phy_state_machine when PHYs return -EOPNOTSUPP from config_aneg() because they do not support forced modes.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#6 lore raw

Re: [PATCH net-next v21 02/13] phylib: Add support for PHYs with broken forced mode

In reply to Birger Koblitz
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The concern: PHY_BROKEN_FORCED (include/linux/phy.h:67) has no user at this commit, so the checks in phy_ethtool_ksettings_set()…

--

phylib: Add support for PHYs with broken forced mode

This adds a PHY_BROKEN_FORCED driver flag. With it set, phy_ethtool_ksettings_set() and phy_mii_ioctl() return -EOPNOTSUPP when someone asks for a forced speed/duplex mode. The aim is to avoid the warning in the PHY state machine when config_aneg() rejects forced mode.

Quoted 4 lines
drivers/net/phy/phy.c +0 -0
index fce9bc7be3304..079c53516f424 100644

[ ... ]

drivers/net/phy/phy.c int phy_ethtool_ksettings_set(struct phy_device *phydev, · line 1199

Quoted 8 lines
drivers/net/phy/phy.c +4 -0
@@ -1190,6 +1193,10 @@ int phy_ethtool_ksettings_set(struct phy_device *phydev,
 	      duplex != DUPLEX_FULL)))
 		return -EINVAL;
 
+	if (autoneg == AUTONEG_DISABLE && phydev->drv &&
+	    (phydev->drv->flags & PHY_BROKEN_FORCED))
+		return -EOPNOTSUPP;
+

[Severity: Low]
No driver sets PHY_BROKEN_FORCED at this commit. Doesn't that mean this check, and the matching one in phy_mii_ioctl(), can't trigger yet?

The commit message says:

This prevents a kernel warning and stack-trace within the phy_state_machine when PHYs return -EOPNOTSUPP from config_aneg()

Later in the series, "ax88796b: Add support for AX88772D, AX88179A and AX88279" sets the flag on the AX88279 entry. That driver's asix_ax88279_config_aneg() returns -EOPNOTSUPP when autoneg is disabled, so the description is accurate once that patch is applied.

Would it help to say in the commit message that the first user comes later in the series?

Separately, two existing drivers already reject forced mode in config_aneg(), but they return -EINVAL:

drivers/net/phy/bcm84881.c:bcm84881_config_aneg() {
    ...
	/* disabled autoneg doesn't seem to work with this PHY */
	if (phydev->autoneg == AUTONEG_DISABLE)
		return -EINVAL;
    ...
}
drivers/net/phy/air_en8811h.c:en8811h_config_aneg() {
    ...
	if (phydev->autoneg == AUTONEG_DISABLE) {
		phydev_warn(phydev, "Disabling autoneg is not supported\n");
		return -EINVAL;
	}
    ...
}

These two still reach the warning through _phy_state_machine()->_phy_start_aneg()->phy_error_precise(). This patch didn't cause that, and converting them could be a separate follow-up.

Would these two drivers be good candidates for the new flag?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261114-ax88179a-v21-0-c2d34410bcbe%40birger-koblitz.de
#7 lore raw

PATCH v21 3/13 ax88179_178a: Split driver into library and device specific code

In reply to Birger Koblitz

Split the ax88179_178a module code into code common to the AX88179/178a/179a and 279 family of controllers and device specific code for the currently supported devices based on the AX88179 and AX88178a.

Rename the module to ax88179 to reflect the broader scope of controllers supported by the module and add an alias to the old module name:
MODULE_ALIAS("ax88179_178a");

---
 drivers/net/usb/Makefile       |   3 +-
 drivers/net/usb/ax88179_178a.c | 611 +----------------------------------------
 drivers/net/usb/ax88179_lib.c  | 459 +++++++++++++++++++++++++++++++
 drivers/net/usb/ax88179_lib.h  | 195 +++++++++++++
 4 files changed, 659 insertions(+), 609 deletions(-)
drivers/net/usb/Makefile +2 -1
index 4964f7b326fbcedffc1e5a1bf004aea95560db8c..ddd76fa71e2ee670888df1c9715632e5c04a8149 100644
@@ -12,7 +12,8 @@ obj-$(CONFIG_USB_HSO)		+= hso.o
 obj-$(CONFIG_USB_LAN78XX)	+= lan78xx.o
 obj-$(CONFIG_USB_NET_AX8817X)	+= asix.o
 asix-y := asix_devices.o asix_common.o ax88172a.o
-obj-$(CONFIG_USB_NET_AX88179_178A)      += ax88179_178a.o
+obj-$(CONFIG_USB_NET_AX88179_178A)      += ax88179.o
+ax88179-y := ax88179_178a.o ax88179_lib.o
 obj-$(CONFIG_USB_NET_CDCETHER)	+= cdc_ether.o
 obj-$(CONFIG_USB_NET_CDC_EEM)	+= cdc_eem.o
 obj-$(CONFIG_USB_NET_DM9601)	+= dm9601.o
drivers/net/usb/ax88179_178a.c +3 -608

660 lines not on this page · raw message

drivers/net/usb/ax88179_lib.c new file +459 -0

459 lines not on this page · raw message

drivers/net/usb/ax88179_lib.h new file +195 -0

195 lines not on this page · raw message

Signature · 1 line
2.47.3
#8 lore raw

Re: [PATCH net-next v21 03/13] ax88179_178a: Split driver into library and device specific code

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] net: usb: ax88179: premature MTU state update in ax88179_change_mtu() - [Medium] net: usb…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] net: usb: ax88179: premature MTU state update in ax88179_change_mtu()
- [Medium] net: usb: ax88179: incomplete medium_status_mutex locking --

commit 9cf9d4a99ae16c171272ec2bbd3db39766daf1ee
Author: Birger Koblitz <[email protected]>

ax88179_178a: Split driver into library and device specific code

This commit splits the ax88179_178a driver into a shared library and device-specific code, and renames the module to ax88179 with an alias for ax88179_178a.

Quoted 5 lines
drivers/net/usb/ax88179_lib.c new file +0 -0
new file mode 100644
index 0000000000000..fbaf12b713b03

[ ... ]

Quoted 33 lines
drivers/net/usb/ax88179_lib.c new file +33 -0
+int ax88179_change_mtu(struct net_device *net, int new_mtu)
+{
+	struct usbnet *dev = netdev_priv(net);
+	struct ax88179_data *data;
+	u16 tmp16;
+	int err;
+
+	data = dev->driver_priv;
+	mutex_lock(&data->medium_status_mutex);
+	WRITE_ONCE(net->mtu, new_mtu);
+	dev->hard_mtu = net->mtu + net->hard_header_len;
+	if (net->mtu > 1500) {
+		err = ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
+				       2, 2, &tmp16);
+		if (err < 0)
+			goto err_out;
+		tmp16 |= AX_MEDIUM_JUMBO_EN;
+		err = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
+					2, 2, &tmp16);
+		if (err < 0)
+			goto err_out;
+	} else {
+		err = ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
+				       2, 2, &tmp16);
+		if (err < 0)
+			goto err_out;
+		tmp16 &= ~AX_MEDIUM_JUMBO_EN;
+		err = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
+					2, 2, &tmp16);
+		if (err < 0)
+			goto err_out;
+	}
+	mutex_unlock(&data->medium_status_mutex);

drivers/net/usb/ax88179_lib.c line 436

Quoted 10 lines
drivers/net/usb/ax88179_lib.c new file +10 -0
+
+	/* max qlen depend on hard_mtu and rx_urb_size */
+	usbnet_update_max_qlen(dev);
+
+	return 0;
+
+err_out:
+	mutex_unlock(&data->medium_status_mutex);
+	return err;
+}

[Severity: Medium]
Does jumping to err_out leave net->mtu and dev->hard_mtu updated to new_mtu when a register read or write fails?

When __netif_set_mtu() returns an error, netif_set_mtu_ext() assumes the driver did not modify net->mtu, so it does not roll the value back or run NETDEV_CHANGEMTU notifiers, and err_out also skips usbnet_update_max_qlen(). This leaves net->mtu and dev->hard_mtu out of sync with AX_MEDIUM_JUMBO_EN and dev->tx_qlen, and a retry with the same new_mtu returns early in netif_set_mtu_ext() because net->mtu already equals new_mtu. Updating net->mtu and dev->hard_mtu only after ax88179_write_cmd() succeeds would avoid this regression.

[ ... ]

Quoted 5 lines
drivers/net/usb/ax88179_lib.h new file +0 -0
new file mode 100644
index 0000000000000..9111a1395eb2f

[ ... ]

drivers/net/usb/ax88179_lib.h line 161

Quoted 2 lines
drivers/net/usb/ax88179_lib.h new file +2 -0
+struct ax88179_data {
+	struct mutex medium_status_mutex;  /* protect AX_MEDIUM_STATUS_MODE */

[Severity: Medium]
Can ax88179_change_mtu() still race with ax88179_link_reset() when updating AX_MEDIUM_STATUS_MODE?

This patch adds medium_status_mutex and takes it in ax88179_change_mtu(), but ax88179_link_reset() runs on dev->kevent without holding medium_status_mutex or rtnl_lock:

CPU0 kworker
ax88179_change_mtu() ax88179_link_reset()

                                    if (dev->net->mtu > 1500)
                                      mode |= AX_MEDIUM_JUMBO_EN;
                                    ax88179_write_cmd(...,
                                      AX_RX_BULKIN_QCTRL, ...);
  mutex_lock(&medium_status_mutex)
  WRITE_ONCE(net->mtu, 4000)
  ax88179_read_cmd(...,
    AX_MEDIUM_STATUS_MODE, &tmp16)
  tmp16 |= AX_MEDIUM_JUMBO_EN
  ax88179_write_cmd(...,
    AX_MEDIUM_STATUS_MODE, &tmp16)
  mutex_unlock(&medium_status_mutex)
                                    ax88179_write_cmd(...,
                                      AX_MEDIUM_STATUS_MODE, &mode);
                                      <-- overwrites AX_MEDIUM_JUMBO_EN

In the reverse order, ax88179_change_mtu() can read AX_MEDIUM_STATUS_MODE before ax88179_link_reset() writes the new link mode and then write back stale speed and duplex bits.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#9 lore raw

Re: [PATCH net-next v21 03/13] ax88179_178a: Split driver into library and device specific code

In reply to Birger Koblitz
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.

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

Critical: 0 · High: 0 · Medium: 3 · 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] The commit message describes a pure refactor: split ax88179_178a into common library code plus device-specific code, then…
- [Medium] The patch renames the kernel module from ax88179_178a.ko to ax88179.ko (Makefile: `obj-$(CONFIG_USB_NET_AX88179_178A) +=…
- [Medium] The reworked ax88179_change_mtu() (ax88179_lib.c:394-436) does WRITE_ONCE(net->mtu, new_mtu) and `dev->hard_mtu = net->mtu +…
- [Low] The new medium_status_mutex is commented /* protect AX_MEDIUM_STATUS_MODE */ (ax88179_lib.h:161), but in this patch only…

--

ax88179_178a: Split driver into library and device specific code

This splits the ax88179_178a driver into common library code (ax88179_lib.c/ax88179_lib.h) and device specific code for the AX88179 and AX88178a. It also renames the module to ax88179 and adds a MODULE_ALIAS for the old ax88179_178a name.

drivers/net/usb/Makefile obj-$(CONFIG_USB_HSO) += hso.o · line 16

Quoted 11 lines
drivers/net/usb/Makefile +2 -1
index 4964f7b326fbc..ddd76fa71e2ee 100644
@@ -12,7 +12,8 @@ obj-$(CONFIG_USB_HSO)		+= hso.o
 obj-$(CONFIG_USB_LAN78XX)	+= lan78xx.o
 obj-$(CONFIG_USB_NET_AX8817X)	+= asix.o
 asix-y := asix_devices.o asix_common.o ax88172a.o
-obj-$(CONFIG_USB_NET_AX88179_178A)      += ax88179_178a.o
+obj-$(CONFIG_USB_NET_AX88179_178A)      += ax88179.o
+ax88179-y := ax88179_178a.o ax88179_lib.o

[Severity: Medium]
This renames the module from ax88179_178a.ko to ax88179.ko. The new MODULE_ALIAS("ax88179_178a") keeps "modprobe ax88179_178a" working. Is that enough for existing userspace configuration?

As I understand kmod, modprobe.d blacklist entries are matched against the real module name. Hotplug loads the driver through the USB modalias, which now resolves to ax88179. An existing "blacklist ax88179_178a" would then stop applying, and the driver would bind again. People commonly blacklist this driver so that cdc_ncm binds to AX88179A adapters.

"options ax88179_178a ...", "rmmod ax88179_178a" and scripts that check /sys/module/ax88179_178a would also stop matching.

Could the commit message mention this user visible change?

Quoted 4 lines
drivers/net/usb/ax88179_178a.c +0 -0
index 2279dbbcdb4dd..55268d0890d12 100644

[ ... ]

drivers/net/usb/ax88179_178a.c static int ax88179_bind(struct usbnet *dev, struct usb_interface *intf) · line 689

Quoted 8 lines
drivers/net/usb/ax88179_178a.c +1 -0
@@ -1290,6 +683,7 @@ static int ax88179_bind(struct usbnet *dev, struct usb_interface *intf)
 		return -ENOMEM;
 
 	dev->driver_priv = ax179_data;
+	mutex_init(&ax179_data->medium_status_mutex);
 
 	dev->net->netdev_ops = &ax88179_netdev_ops;
 	dev->net->ethtool_ops = &ax88179_ethtool_ops;

[Severity: Medium]
The commit message only describes a split into library and device specific code plus a module rename. This hunk, though, adds a new medium_status_mutex. ax88179_change_mtu() in ax88179_lib.c is also reworked to take that mutex and to return errors from the AX_MEDIUM_STATUS_MODE read and write.

The old ax88179_change_mtu() ignored those errors, always called usbnet_update_max_qlen() and always returned 0. The new version can return a negative errno from ndo_change_mtu.

Could these functional changes be described in the commit message, or moved into a separate patch? Later patches in the series use this mutex, so it looks like groundwork for them. Anyone bisecting or backporting what looks like a pure split would otherwise pick up new locking and new ndo_change_mtu error semantics without knowing it.

[ ... ]

Quoted 5 lines
drivers/net/usb/ax88179_lib.c new file +0 -0
new file mode 100644
index 0000000000000..fbaf12b713b03

[ ... ]

Quoted 22 lines
drivers/net/usb/ax88179_lib.c new file +22 -0
+int ax88179_change_mtu(struct net_device *net, int new_mtu)
+{
+	struct usbnet *dev = netdev_priv(net);
+	struct ax88179_data *data;
+	u16 tmp16;
+	int err;
+
+	data = dev->driver_priv;
+	mutex_lock(&data->medium_status_mutex);
+	WRITE_ONCE(net->mtu, new_mtu);
+	dev->hard_mtu = net->mtu + net->hard_header_len;
+	if (net->mtu > 1500) {
+		err = ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
+				       2, 2, &tmp16);
+		if (err < 0)
+			goto err_out;
+		tmp16 |= AX_MEDIUM_JUMBO_EN;
+		err = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
+					2, 2, &tmp16);
+		if (err < 0)
+			goto err_out;
+	} else {

[ ... ]

drivers/net/usb/ax88179_lib.c line 436

Quoted 12 lines
drivers/net/usb/ax88179_lib.c new file +12 -0
+	}
+	mutex_unlock(&data->medium_status_mutex);
+
+	/* max qlen depend on hard_mtu and rx_urb_size */
+	usbnet_update_max_qlen(dev);
+
+	return 0;
+
+err_out:
+	mutex_unlock(&data->medium_status_mutex);
+	return err;
+}

[Severity: Medium]
Can this leave the MTU half applied when a USB control transfer fails?

net->mtu and dev->hard_mtu are updated before the AX_MEDIUM_STATUS_MODE read and write. The err_out path only drops the mutex and returns the error. It does not restore the old MTU, and it skips usbnet_update_max_qlen().

netif_set_mtu_ext() only sends NETDEV_CHANGEMTU when the driver succeeds. It only restores orig_mtu when a notifier fails:

net/core/dev.c:netif_set_mtu_ext() {
    ...
	orig_mtu = dev->mtu;
	err = __netif_set_mtu(dev, new_mtu);

	if (!err) {
		err = call_netdevice_notifiers_mtu(NETDEV_CHANGEMTU, dev,
						   orig_mtu);
    ...
}

Say the adapter returns -ETIMEDOUT or -EPIPE, or -ENODEV during unplug. Userspace gets the error, but dev->mtu already holds the new value. Upper layers never got NETDEV_CHANGEMTU, the JUMBO_EN bit in hardware may not match the MTU, and the rx/tx qlen were not recomputed.

Retrying with the same value does not help, because netif_set_mtu_ext() returns early:

	if (new_mtu == dev->mtu)
		return 0;

The previous code ignored these errors and always returned 0, so it never ended up in this state. This code is the same at the end of the series.

Should the MTU be set only after the register update succeeds, or be restored on the error path?

Quoted 5 lines
drivers/net/usb/ax88179_lib.h new file +0 -0
new file mode 100644
index 0000000000000..9111a1395eb2f

[ ... ]

drivers/net/usb/ax88179_lib.h line 161

Quoted 2 lines
drivers/net/usb/ax88179_lib.h new file +2 -0
+struct ax88179_data {
+	struct mutex medium_status_mutex;  /* protect AX_MEDIUM_STATUS_MODE */

[Severity: Low]
Is this comment accurate? It says the mutex protects AX_MEDIUM_STATUS_MODE.

In this patch only ax88179_change_mtu() takes the mutex, and that function already runs under RTNL. None of the other accesses to this register in ax88179_178a.c take it: ax88179_suspend(), ax88179_link_reset(), ax88179_reset(), ax88179_net_reset() and ax88179_stop().

For example, ax88179_link_reset() runs from the usbnet kevent work without RTNL. It writes the whole register, with JUMBO_EN based on dev->net->mtu:

	} else if (GMII_PHY_PHYSR_GIGA == (tmp16 & GMII_PHY_PHYSR_SMASK)) {
		mode |= AX_MEDIUM_GIGAMODE | AX_MEDIUM_EN_125MHZ;
		if (dev->net->mtu > 1500)
			mode |= AX_MEDIUM_JUMBO_EN;
    ...
	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE,
			  2, 2, &mode);

Here is one possible sequence. link_reset reads an MTU of 1500. Then change_mtu sets the MTU to 4000 and turns JUMBO_EN on. The later link_reset write clears JUMBO_EN again.

The other way round, the read-modify-write in change_mtu can write back stale GIGAMODE and 125MHz bits over a 100M mode that link_reset just wrote.

This race was there before the patch. However, the comment now claims protection that the code does not give. This is still the case at the end of the series. The ax88179a_devices.c link up path takes the mutex, but none of the ax88179_178a.c accessors do.

Should the comment be narrowed, or should the other accessors take the lock too?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261114-ax88179a-v21-0-c2d34410bcbe%40birger-koblitz.de
#10 lore raw

PATCH v21 4/13 ax88179_178a: Add HW support for AX179A-based chips

In reply to Birger Koblitz

This adds bindings and HW support for AX179A-based USB-Ethernet controllers. The AX179A-family of chips consists of the AX88279 (2.5GBit PHY)
AX88179A/B (1GBit PHY, B variant has wider temperature range) AX772D/E (100Mbit PHY)

The controllers all have the same vendor and device ID (0x0b95, 0x1790) and are distinguished by their BCD device versions, which are
2.00 AX88179A/B
3.00 AX88772D/E
4.00 AX88279

For all chips, the driver calls the same ax88179a_bind() function and the chips are then distinguished by the chip version and BCD device ID. The AX179A-based chips all provide both a CDC-NCM compatible USB interface, and a proprietary vendor interface. By default, the proprietary vendor interface is not active and Linux will load the CDC-NCM driver to support the devices. If the ax88179_178a module is configured by the OS to have precedence over CDC-NCM, then this driver will switch the device to use the vendor interface, and the device will be controlled by the ax88179_178a driver when the device is probed again after an automatic reset by the device.

Also add a convenience function for the ethtool ops that use phylink and need to retrieve the ax88179_data structure from
net_device: netdev2data().

---
 MAINTAINERS                        |   6 +
 drivers/net/usb/Kconfig            |   2 +-
 drivers/net/usb/Makefile           |   2 +-
 drivers/net/usb/ax88179_178a.c     |  31 ++
 drivers/net/usb/ax88179_lib.c      |  30 ++
 drivers/net/usb/ax88179_lib.h      | 161 ++++++
 drivers/net/usb/ax88179a_devices.c | 983 +++++++++++++++++++++++++++++++++++++
 7 files changed, 1213 insertions(+), 2 deletions(-)
MAINTAINERS +6 -0
index 0cf311e6c4be4db2654fea4f0af77a3bd1d77125..1fc792582e1a151068cbc7f63ab8fcfc43eb2444 100644
@@ -4123,6 +4123,12 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/net/asix,ax88796c.yaml
 F:	drivers/net/ethernet/asix/ax88796c_*
 
+ASIX AX88179 USB ETHERNET DRIVER
+M:	Birger Koblitz <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/net/usb/ax88179*
+
 ASIX PHY DRIVER [RUST]
 M:	FUJITA Tomonori <[email protected]>
 R:	Trevor Gross <[email protected]>
drivers/net/usb/Kconfig +1 -1
index 52a5c0922c79fc52906d4d4040ec2b3411ff0984..115990b0d9537aea2776544c9768b034f32aa7a4 100644
@@ -199,7 +199,7 @@ config USB_NET_AX88179_178A
 	tristate "ASIX AX88179/178A USB 3.0/2.0 to Gigabit Ethernet"
 	depends on USB_USBNET
 	select CRC32
-	select PHYLIB
+	select PHYLINK
 	default y
 	help
 	  This option adds support for ASIX AX88179 based USB 3.0/2.0
drivers/net/usb/Makefile +1 -1
index ddd76fa71e2ee670888df1c9715632e5c04a8149..2ecead0181eaf8d66fb6f5dbd6f2905b22b6eb57 100644
@@ -13,7 +13,7 @@ obj-$(CONFIG_USB_LAN78XX)	+= lan78xx.o
 obj-$(CONFIG_USB_NET_AX8817X)	+= asix.o
 asix-y := asix_devices.o asix_common.o ax88172a.o
 obj-$(CONFIG_USB_NET_AX88179_178A)      += ax88179.o
-ax88179-y := ax88179_178a.o ax88179_lib.o
+ax88179-y := ax88179_178a.o ax88179a_devices.o ax88179_lib.o
 obj-$(CONFIG_USB_NET_CDCETHER)	+= cdc_ether.o
 obj-$(CONFIG_USB_NET_CDC_EEM)	+= cdc_eem.o
 obj-$(CONFIG_USB_NET_DM9601)	+= dm9601.o
drivers/net/usb/ax88179_178a.c +31 -0
index 55268d0890d1200be07b87f2dc9e62d2d7b69fc1..f78ad344c1c4f1f057164728e4f21f875e6cdc1a 100644
@@ -685,6 +685,19 @@ static int ax88179_bind(struct usbnet *dev, struct usb_interface *intf)
 	dev->driver_priv = ax179_data;
 	mutex_init(&ax179_data->medium_status_mutex);
 
+	ret = ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_CHIP_STATUS,
+			       1, 1, &ax179_data->chip_version);
+	if (ret < 0)
+		goto err_nodev;
+
+	ax179_data->chip_version = (ax179_data->chip_version & 0xf0) >> 4;
+	ax179_data->is_ax88772d = 0;
+	ax179_data->ip_align = 1;
+	ax179_data->eeprom_read_cmd = AX_ACCESS_EEPROM;
+	ax179_data->eeprom_write_cmd = AX_ACCESS_EEPROM;
+	ax179_data->eeprom_block = 2;
+	ax179_data->eeprom_wen = 0;
+
 	dev->net->netdev_ops = &ax88179_netdev_ops;
 	dev->net->ethtool_ops = &ax88179_ethtool_ops;
 	dev->net->needed_headroom = 8;
@@ -709,6 +722,12 @@ static int ax88179_bind(struct usbnet *dev, struct usb_interface *intf)
 	ax88179_reset(dev);
 
 	return 0;
+
+err_nodev:
+	kfree(ax179_data);
+	ax179_data = NULL;
+
+	return ret;
 }
 
 static void ax88179_unbind(struct usbnet *dev, struct usb_interface *intf)
@@ -1271,6 +1290,18 @@ static const struct driver_info at_umc2000sp_info = {
 
 static const struct usb_device_id products[] = {
 {
+	/* ASIX AX88179A USB 3.2 1000Mbit Ethernet */
+	USB_DEVICE_VER(0x0b95, 0x1790, 0x0200, 0x0200),
+	.driver_info = (unsigned long)&ax88179a_info,
+}, {
+	/* ASIX AX88772D USB 2.0 100Mbit Ethernet */
+	USB_DEVICE_VER(0x0b95, 0x1790, 0x0300, 0x0300),
+	.driver_info = (unsigned long)&ax88772d_info,
+}, {
+	/* ASIX AX88279 USB 3.2 2500Mbit Ethernet */
+	USB_DEVICE_VER(0x0b95, 0x1790, 0x0400, 0x0400),
+	.driver_info = (unsigned long)&ax88279_info,
+}, {
 	/* ASIX AX88179 10/100/1000 */
 	USB_DEVICE_AND_INTERFACE_INFO(0x0b95, 0x1790, 0xff, 0xff, 0),
 	.driver_info = (unsigned long)&ax88179_info,
drivers/net/usb/ax88179_lib.c +30 -0
index fbaf12b713b03208995ae5969ec85065c4c0a48b..fa6423f51849e2ea5b640dcb82af6282d41b189e 100644
@@ -129,6 +129,28 @@ int ax88179_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
 	return ret;
 }
 
+int ax88179_write_u16(struct usbnet *dev, u8 cmd, u16 value, u16 index, u16 data)
+{
+	u16 buf = data;
+
+	cpu_to_le16s(&buf);
+	return __ax88179_write_cmd(dev, cmd, value, index, 2, &buf);
+}
+
+int ax88179_write_u8(struct usbnet *dev, u8 cmd, u16 value, u16 index, u8 data)
+{
+	u8 buf = data;
+
+	return __ax88179_write_cmd(dev, cmd, value, index, 1, &buf);
+}
+
+struct ax88179_data *netdev2data(struct net_device *net)
+{
+	struct usbnet *dev = netdev_priv(net);
+
+	return dev->driver_priv;
+}
+
 void ax88179_status(struct usbnet *dev, struct urb *urb)
 {
 	struct ax88179_int_data *event;
@@ -338,6 +360,7 @@ int ax88179_set_features(struct net_device *net, netdev_features_t features)
 {
 	u8 tmp;
 	struct usbnet *dev = netdev_priv(net);
+	struct ax88179_data *data = dev->driver_priv;
 	netdev_features_t changed = net->features ^ features;
 
 	if (changed & NETIF_F_IP_CSUM) {
@@ -353,10 +376,17 @@ int ax88179_set_features(struct net_device *net, netdev_features_t features)
 	}
 
 	if (changed & NETIF_F_RXCSUM) {
+		/* When we disable rx-checksumming, we need to clear the rx_checksum
+		 * flag before disabling the engine
+		 */
+		if (!(features & NETIF_F_RXCSUM))
+			data->rx_checksum = 0;
+
 		ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_RXCOE_CTL, 1, 1, &tmp);
 		tmp ^= AX_RXCOE_IP | AX_RXCOE_TCP | AX_RXCOE_UDP |
 		       AX_RXCOE_TCPV6 | AX_RXCOE_UDPV6;
 		ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RXCOE_CTL, 1, 1, &tmp);
+		data->rx_checksum = !!(features & NETIF_F_RXCSUM);
 	}
 
 	return 0;
drivers/net/usb/ax88179_lib.h +161 -0

234 lines not on this page · raw message

drivers/net/usb/ax88179a_devices.c new file +983 -0

983 lines not on this page · raw message

Signature · 1 line
2.47.3
#11 lore raw

Re: [PATCH net-next v21 04/13] ax88179_178a: Add HW support for AX179A-based chips

Thank you for your contribution! Sashiko AI review found 9 potential issues to consider: - [High] net: usb: ax88179_178a: missing usbnet_link_change() in phylink callbacks - [High] net: usb…

Thank you for your contribution! Sashiko AI review found 9 potential issues to consider:
- [High] net: usb: ax88179_178a: missing usbnet_link_change() in phylink callbacks
- [High] net: usb: ax88179: UAF on unbind when down due to FLAG_AVOID_UNLINK_URBS
- [Medium] net: usb: ax88179_178a: byte-swapped pause waterlevels in ax88179a_mac_link_up()
- [Medium] net: usb: ax88179_178a: positive return from ax88179_mdiobus_write() and c45
- [Medium] net: usb: ax88179a: ax88179a_reset() clobbers custom MAC and perm_addr on open
- [Medium] net: usb: ax88179_178a: missing wol_supported init in ax88179a_bind()
- [Medium] net: usb: ax88179_178a: phylink_start() not unwound if usbnet_open() fails
- [Medium] net: usb: ax88179: ax88179a_stop() powers off PHY while attached to phylink
- [Low] net: usb: ax88179a: unaligned u16 pointer cast of u8 buf[5] in ax88179a_reset()
--

commit 2a91332d4bb64576008617e61fef57f6ed964420
Author: Birger Koblitz <[email protected]>

ax88179_178a: Add HW support for AX179A-based chips

This commit adds hardware support and USB device IDs for the AX88179A, AX88772D/E, and AX88279 USB Ethernet controllers using phylink.

Quoted 5 lines
drivers/net/usb/ax88179a_devices.c new file +0 -0
new file mode 100644
index 0000000000000..1aa8479422517

[ ... ]

Quoted 33 lines
drivers/net/usb/ax88179a_devices.c new file +33 -0
+static int ax88179_mdiobus_write(struct mii_bus *bus, int phy_id, int regnum, u16 val)
+{
+	struct usbnet *dev = bus->priv;
+
+	return ax88179_write_u16(dev, AX_ACCESS_PHY, phy_id, (__u16)regnum, val);
+}
+
+static int ax179a_read_mmd(struct usbnet *dev, u16 dev_addr, u16 reg)
+{
+	u16 res;
+	int ret;
+
+	ret = ax88179_read_cmd(dev, AX88179A_PHY_CLAUSE45, dev_addr, reg, 2, &res);
+	if (ret < 0)
+		return ret;
+	return res;
+}
+
+static int ax179a_write_mmd(struct usbnet *dev, u16 dev_addr, u16 reg, u16 data)
+{
+	return ax88179_write_cmd(dev, AX88179A_PHY_CLAUSE45, dev_addr, reg, 2, &data);
+}
+
+static int ax88179_mdiobus_read_c45(struct mii_bus *bus, int addr, int devnum, int regnum)
+{
+	struct usbnet *dev = bus->priv;
+
+	if (addr != AX88179_PHY_ID)
+		return -EINVAL;
+
+	return ax179a_read_mmd(dev, devnum, regnum);
+}
+

drivers/net/usb/ax88179a_devices.c line 117

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c new file +10 -0
+static int ax88179_mdiobus_write_c45(struct mii_bus *bus, int addr, int devnum,
+				     int regnum, u16 val)
+{
+	struct usbnet *dev = bus->priv;
+
+	if (addr != AX88179_PHY_ID)
+		return -EINVAL;
+
+	return ax179a_write_mmd(dev, devnum, regnum, val);
+}

[Severity: Medium]
Do ax88179_mdiobus_write() and ax88179_mdiobus_write_c45() return 2 instead of 0 on a successful write?

ax88179_write_u16() and ax88179_write_cmd() return the positive byte count from usb_control_msg(), whereas mii_bus .write and .write_c45 callbacks are expected to return 0 on success and a negative errno on failure. Callers that check for a non-zero return value, such as phylink_mii_ioctl() for SIOCSMIIREG or phy_suspend() when a PHY driver returns phy_write() directly, will treat the positive return value as an unusual return or failure.

[ ... ]

Quoted 15 lines
drivers/net/usb/ax88179a_devices.c new file +15 -0
+static void ax88179a_mac_link_down(struct phylink_config *config,
+				   unsigned int mode, phy_interface_t interface)
+{
+	/* Nothing to do */
+}
+
+static void ax88179a_mac_link_up(struct phylink_config *config,
+				 struct phy_device *phy,
+				 unsigned int phy_mode, phy_interface_t interface,
+				 int speed, int duplex,
+				 bool tx_pause, bool rx_pause)
+{
+	struct usbnet *dev = netdev_priv(to_net_dev(config->dev));
+	struct ax88179_data *ax179_data = dev->driver_priv;
+	u8 link_sts = 0, reg8[3];

drivers/net/usb/ax88179a_devices.c line 307

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c new file +10 -0
+	u8 bulk_config_speed = 0;
+	u16 mode;
+
+	/* Stop RX/TX for link configuration */
+	ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, AX_RX_CTL_STOP);
+	ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_PATH, 1, 0);
+
+	ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_CDC_DELAY_TX, 1, 0xa5);
+
+	ax88179_write_u16(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_LOW, 2, 0x0410);

[Severity: Medium]
Does this 16-bit write program AX_PAUSE_WATERLVL_LOW and AX_PAUSE_WATERLVL_HIGH with their values swapped?

ax88179a_reset() writes 0x04 to AX_PAUSE_WATERLVL_LOW (0x54) and 0x10 to AX_PAUSE_WATERLVL_HIGH (0x55), but ax88179_write_u16() converts 0x0410 to little-endian via cpu_to_le16s(), sending 0x10 to register 0x54 and 0x04 to register 0x55 so the low pause threshold exceeds the high threshold.

[ ... ]

drivers/net/usb/ax88179a_devices.c line 396

Quoted 3 lines
drivers/net/usb/ax88179a_devices.c new file +3 -0
+	ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_PATH, 1,
+			 AX_MAC_RX_PATH_READY | AX_MAC_TX_PATH_READY);
+}

[Severity: High]
Should ax88179a_mac_link_up() and ax88179a_mac_link_down() call usbnet_link_change(dev, true/false, false) like ax88772_mac_link_up() and ax88772_mac_link_down() in drivers/net/usb/asix_devices.c?

During usbnet_open(), ax88179a_reset() calls phylink_start(), which leaves netif_carrier_ok(dev->net) false while PHY autonegotiation runs in the phylink resolve workqueue. When usbnet_open() then schedules dev->bh_work, usbnet_bh() skips rx_alloc_submit() because carrier is off, leaving dev->rxq empty:

drivers/net/usb/usbnet.c:usbnet_bh() {
    ...
	} else if (netif_running (dev->net) &&
		   netif_device_present (dev->net) &&
		   netif_carrier_ok(dev->net) &&
		   !timer_pending(&dev->delay) &&
		   !test_bit(EVENT_RX_KILL, &dev->flags) &&
		   !test_bit(EVENT_RX_HALT, &dev->flags)) {
		int	temp = dev->rxq.qlen;

		if (temp < RX_QLEN(dev)) {
			if (rx_alloc_submit(dev, GFP_ATOMIC) == -ENOLINK)
				return;
    ...
}

When phylink later brings the link up and calls netif_carrier_on(), usbnet is never notified via usbnet_link_change(), so __handle_link_change() never runs to schedule dev->bh_work and submit RX URBs or update max queue lengths, and pending RX URBs are never unlinked when the link drops.

[ ... ]

Quoted 2 lines
drivers/net/usb/ax88179a_devices.c new file +2 -0
+static int ax88179a_bind(struct usbnet *dev, struct usb_interface *intf)
+{

[ ... ]

drivers/net/usb/ax88179a_devices.c line 611

Quoted 5 lines
drivers/net/usb/ax88179a_devices.c new file +5 -0
+	ret = ax88179a_init_phy(dev);
+	if (ret)
+		goto initphy_err;
+
+	return 0;

[Severity: Medium]
Should ax88179a_bind() initialize ax179_data->wol_supported before the net_device is registered?

Unlike ax88179_bind(), which calls ax88179_reset() during bind, ax88179a_bind() leaves ax179_data->wol_supported at 0 until usbnet_open() calls ax88179a_reset(). Any ethtool get_wol or set_wol request issued while the interface is still down before the first open (such as udev or systemd-networkd applying WakeOnLan link settings at probe time) sees wol_supported == 0 and fails with -EINVAL.

[ ... ]

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c new file +10 -0
+static int ax88179a_reset(struct usbnet *dev)
+{
+	struct ax88179_data *ax179_data = dev->driver_priv;
+	u16 *tmp16;
+	u8 buf[5];
+	u16 rxctl;
+	u8 *tmp;
+
+	tmp16 = (u16 *)buf;
+	tmp = (u8 *)buf;

[ ... ]

drivers/net/usb/ax88179a_devices.c line 866

Quoted 3 lines
drivers/net/usb/ax88179a_devices.c new file +3 -0
+	/* Read MAC address from DTB or asix chip */
+	ax88179_get_mac_addr(dev);
+	memcpy(dev->net->perm_addr, dev->net->dev_addr, ETH_ALEN);

[Severity: Medium]
Does calling ax88179_get_mac_addr() and overwriting dev->net->perm_addr in ax88179a_reset() clobber a user-configured MAC address or the permanent MAC address on open?

ax88179_set_mac_addr() requires the interface to be down and writes the new address to dev->net->dev_addr and AX_NODE_ID. When usbnet_open() then calls ax88179a_reset(), ax88179_get_mac_addr() either overwrites the custom MAC address with the Device Tree MAC address if one is present, or reads the custom MAC back from AX_NODE_ID, resets addr_assign_type to NET_ADDR_PERM, and copies it into dev->net->perm_addr.

[ ... ]

drivers/net/usb/ax88179a_devices.c line 915

Quoted 6 lines
drivers/net/usb/ax88179a_devices.c new file +6 -0
+	/* Configure default medium type => giga */
+	*tmp16 = AX_MEDIUM_RECEIVE_EN | AX_MEDIUM_TXFLOW_CTRLEN |
+		 AX_MEDIUM_RXFLOW_CTRLEN | AX_MEDIUM_FULL_DUPLEX;
+	if (!ax179_data->is_ax88772d)
+		*tmp16 |= AX_MEDIUM_GIGAMODE;
+	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 2, 2, tmp16);

[Severity: Low]
As reported by Jakub Kicinski on v12 [1], casting u8 buf[5] to u16 *tmp16 and dereferencing it performs 16-bit accesses on a 1-byte-aligned stack array. Can this use ax88179_write_u16() with a u16 local variable like the other 16-bit writes in this function?

Quoted 4 lines
drivers/net/usb/ax88179a_devices.c new file +4 -0
+
+	/* Check if WoL is supported */
+	ax179_data->wol_supported = 0;
+	if (ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD,

drivers/net/usb/ax88179a_devices.c line 929

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c new file +10 -0
+			     1, 1, tmp) > 0)
+		ax179_data->wol_supported = WAKE_MAGIC | WAKE_PHY;
+
+	/* Ensure EEE state is off, consistent with phylink setup */
+	ax88179_write_cmd(dev, AX_GPHY_CTL, AX_GPHY_EEE_CTRL, false, 0, NULL);
+
+	phylink_start(ax179_data->phylink);
+
+	return 0;
+}

[Severity: Medium]
If usbnet_status_start() fails in usbnet_open() after info->reset() has succeeded, does phylink remain started while the interface stays down?

usbnet_open() calls info->reset() before usbnet_status_start(), and its error path does not call info->stop(). Leaving phylink running when open fails leaves phydev in PHY_UP/PHY_NOLINK/PHY_RUNNING, which triggers a WARN_ON in phy_start() on the next open attempt.

Quoted 8 lines
drivers/net/usb/ax88179a_devices.c new file +8 -0
+
+static int ax88179a_stop(struct usbnet *dev)
+{
+	struct ax88179_data *ax179_data = dev->driver_priv;
+	u16 reg16 = 0;
+
+	phylink_stop(ax179_data->phylink);
+

drivers/net/usb/ax88179a_devices.c line 947

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c new file +10 -0
+	ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 2, 2, &reg16);
+	reg16 &= ~AX_MEDIUM_RECEIVE_EN;
+	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 2, 2, &reg16);
+
+	ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 0);
+
+	ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_PHY_POWER, 0, 0, 0);
+
+	return 0;
+}

[Severity: Medium]
Does powering off AX88179A_PHY_POWER in ax88179a_stop() break MDIO accesses while the interface is down and lose PHY state across down/up transitions?

phylink_stop() already suspends the PHY via BMCR_PDOWN while keeping it powered for MDIO requests. Cutting power to the PHY while it remains attached to phylink causes ethtool and MII ioctl operations performed while the interface is down to access an unpowered PHY, and when ax88179a_reset() later restores power, phylink_start() -> phy_start() only calls __phy_resume() without re-running phy_init_hw().

Quoted 26 lines
drivers/net/usb/ax88179a_devices.c new file +26 -0
+
+const struct driver_info ax88179a_info = {
+	.description = "ASIX AX88179A USB 3.2 Gigabit Ethernet",
+	.bind = ax88179a_bind,
+	.unbind = ax88179a_unbind,
+	.status = ax88179a_status,
+	.reset = ax88179a_reset,
+	.stop = ax88179a_stop,
+	.flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_MULTI_PACKET | FLAG_AVOID_UNLINK_URBS,
+	.rx_fixup = ax88179a_rx_fixup,
+	.tx_fixup = ax88179a_tx_fixup,
+};
+
+const struct driver_info ax88772d_info = {
+	.description = "ASIX AX88772D/E USB 2.0 Fast Ethernet",
+	.bind = ax88179a_bind,
+	.unbind = ax88179a_unbind,
+	.status = ax88179a_status,
+	.reset = ax88179a_reset,
+	.stop = ax88179a_stop,
+	.flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_MULTI_PACKET | FLAG_AVOID_UNLINK_URBS,
+	.rx_fixup = ax88179a_rx_fixup,
+	.tx_fixup = ax88179a_tx_fixup,
+};
+
+const struct driver_info ax88279_info = {

drivers/net/usb/ax88179a_devices.c line 983

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c new file +10 -0
+	.description = "ASIX AX88279 USB 3.2 2.5Gigabit Ethernet",
+	.bind = ax88179a_bind,
+	.unbind = ax88179a_unbind,
+	.status = ax88179a_status,
+	.reset = ax88179a_reset,
+	.stop = ax88179a_stop,
+	.flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_MULTI_PACKET | FLAG_AVOID_UNLINK_URBS,
+	.rx_fixup = ax88179a_rx_fixup,
+	.tx_fixup = ax88179a_tx_fixup,
+};

[Severity: High]
Can setting FLAG_AVOID_UNLINK_URBS on these driver_info structs cause a use-after-free in usbnet_bh_work() if the device is unplugged or unbound after the interface has been brought down?

When FLAG_AVOID_UNLINK_URBS is set, usbnet_stop() skips usbnet_terminate_urbs(), leaving submitted RX URBs queued in dev->rxq after ndo_stop completes. If the USB device is then disconnected while the interface is already down, unregister_netdev() skips usbnet_stop() and usbnet_disconnect() frees the net_device without cancelling dev->bh_work:

CPU0 CPU1 (system_bh_wq)
usb_unbind_interface()
usb_disable_interface()

    ...
      rx_complete()
        defer_bh()
          queue_work(..., &dev->bh_work)
  usbnet_disconnect()
    unregister_netdev(net)
    free_netdev(net)
                                      usbnet_bh_work()
                                        usbnet_bh()  <-- use-after-free

[1] https://lore.kernel.org/r/[email protected]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#12 lore raw

Re: [PATCH net-next v21 04/13] ax88179_178a: Add HW support for AX179A-based chips

In reply to Birger Koblitz
Thank you for your contribution! Sashiko AI review found 14 potential issue(s) to consider.

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

Critical: 0 · High: 1 · Medium: 9 · 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).

- [High] net: usb: ax88179: UAF on unbind when down due to FLAG_AVOID_UNLINK_URBS
- [Medium] The commit message says that by default Linux binds CDC-NCM, and that the vendor interface is used only 'if the ax88179_178a module…
- [Medium] ax88179a_rx_fixup() drops any frame with pkt_len > (dev->hard_mtu + AX179A_RX_HW_PAD).
- [Medium] ax88179a_mac_link_up() and ax88179a_mac_link_down() never call usbnet_link_change().
- [Medium] ax88179a_tx_fixup() programs the hardware TSO MSS from skb_shinfo(skb)->gso_size (NETIF_F_TSO is advertised), but reports…
- [Medium] ax88179a_tx_fixup() linearizes only when !dev->can_dma_sg && (dev->net->features & NETIF_F_SG), i.e. based on the live feature bit…
- [Medium] In ax88179a_mac_link_up(), the SPEED_2500 branch programs three registers that the 1000/100/10 branches never write back.
- [Medium] net: usb: ax88179_178a: missing wol_supported init in ax88179a_bind()
- [Medium] net: usb: ax88179_178a: positive return from ax88179_mdiobus_write() and c45
- [Medium] net: usb: ax88179a: ax88179a_reset() clobbers custom MAC and perm_addr on open
- [Low] ax88179a_reset() is usbnet's info->reset hook.
- [Low] In ax88179a_mac_link_up(), the return value of `ax88179_read_cmd(dev, AX_ACCESS_MAC, PHYSICAL_LINK_STATUS, 1, 1,…
- [Low] The pause water-level registers get contradictory values.
- [Low] ax88179a_bind() switches the firmware mode (AX_FW_MODE_179A) and powers the Ethernet PHY with `ax88179_write_u8(dev,…

--

ax88179_178a: Add HW support for AX179A-based chips

This adds support for the AX88179A/B, AX88772D/E and AX88279 USB Ethernet controllers. All of them share the 0b95:1790 ID and are told apart by bcdDevice. A new ax88179a_devices.c provides bind/reset/stop, RX/TX framing and a phylink/MDIO based PHY setup, and switches the device from its CDC-NCM configuration to the vendor configuration.

Quoted 4 lines
drivers/net/usb/ax88179_178a.c +0 -0
index 55268d0890d12..f78ad344c1c4f 100644

[ ... ]

Quoted 9 lines
drivers/net/usb/ax88179_178a.c +5 -0
@@ -1271,6 +1290,18 @@ static const struct driver_info at_umc2000sp_info = {
 
 static const struct usb_device_id products[] = {
 {
+	/* ASIX AX88179A USB 3.2 1000Mbit Ethernet */
+	USB_DEVICE_VER(0x0b95, 0x1790, 0x0200, 0x0200),
+	.driver_info = (unsigned long)&ax88179a_info,
+}, {
+	/* ASIX AX88772D USB 2.0 100Mbit Ethernet */

drivers/net/usb/ax88179_178a.c static const struct driver_info at_umc2000sp_info = { · line 1307

Quoted 10 lines
drivers/net/usb/ax88179_178a.c +7 -0
+	USB_DEVICE_VER(0x0b95, 0x1790, 0x0300, 0x0300),
+	.driver_info = (unsigned long)&ax88772d_info,
+}, {
+	/* ASIX AX88279 USB 3.2 2500Mbit Ethernet */
+	USB_DEVICE_VER(0x0b95, 0x1790, 0x0400, 0x0400),
+	.driver_info = (unsigned long)&ax88279_info,
+}, {
 	/* ASIX AX88179 10/100/1000 */
 	USB_DEVICE_AND_INTERFACE_INFO(0x0b95, 0x1790, 0xff, 0xff, 0),
 	.driver_info = (unsigned long)&ax88179_info,

[Severity: Medium]
The commit message says:

By default, the proprietary vendor interface is not active and Linux will load the CDC-NCM driver to support the devices. If the ax88179_178a module is configured by the OS to have precedence over CDC-NCM, then this driver will switch the device to use the vendor interface

Do these new entries behave that way? USB_DEVICE_VER() only sets USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION. That means the entries match every interface of the device, including the CDC-NCM control and data interfaces of the default configuration. The existing 0b95:1790 entry uses USB_DEVICE_AND_INTERFACE_INFO(..., 0xff, 0xff, 0), and that entry can't match CDC class interfaces.

Once one of these entries matches, ax88179a_bind() always switches the configuration:

	if (udev->actconfig->desc.bConfigurationValue != 1) {
		netdev_info(dev->net, "Switching to vendor mode\n");
		usb_driver_set_configuration(udev, 1);
		return -ENODEV;
	}

In drivers/net/usb/Makefile, ax88179.o is linked before cdc_ncm.o. When both drivers are built in, this driver registers first and is offered the CDC interfaces first. With modules, the result depends on load order.

Won't adapters that work through cdc_ncm today then always be switched to the vendor configuration, with no way to opt out? If that is intended, could the commit message say so?

Quoted 6 lines
drivers/net/usb/ax88179a_devices.c new file +0 -0
new file mode 100644
index 0000000000000..1aa8479422517
@@ -0,0 +1,983 @@

[ ... ]

drivers/net/usb/ax88179a_devices.c line 287

Quoted 5 lines
drivers/net/usb/ax88179a_devices.c new file +5 -0
+static void ax88179a_mac_link_down(struct phylink_config *config,
+				   unsigned int mode, phy_interface_t interface)
+{
+	/* Nothing to do */
+}

[Severity: Medium]
Should ax88179a_mac_link_down() and ax88179a_mac_link_up() call usbnet_link_change(), as ax88772_mac_link_down() and ax88772_mac_link_up() in asix_devices.c do?

Without that call, nothing queues dev->bh_work when phylink turns the carrier on. usbnet_bh() doesn't submit RX URBs while the carrier is off:

usbnet_open()
ax88179a_reset()
phylink_start() <- carrier set off
queue_work(system_bh_wq, &dev->bh_work)
usbnet_bh() <- !netif_carrier_ok(), no RX URBs

phylink_resolve()
ax88179a_mac_link_up()
netif_carrier_on() <- bh_work is not queued

After that, RX URBs are only posted when something else runs usbnet_bh(), typically a TX completion.

Could a host that doesn't transmit after link-up (static addressing, no IPv6 or DHCP traffic) then never receive packets? The same sequence looks possible after resume, because phylink_resume() restarts phylink with the carrier off.

Quoted 6 lines
drivers/net/usb/ax88179a_devices.c new file +6 -0
+static void ax88179a_mac_link_up(struct phylink_config *config,
+				 struct phy_device *phy,
+				 unsigned int phy_mode, phy_interface_t interface,
+				 int speed, int duplex,
+				 bool tx_pause, bool rx_pause)
+{

[ ... ]

drivers/net/usb/ax88179a_devices.c line 307

Quoted 1 line
drivers/net/usb/ax88179a_devices.c new file +1 -0
+	ax88179_write_u16(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_LOW, 2, 0x0410);

[Severity: Low]
ax88179_write_u16() stores the value little endian. So this writes 0x10 to AX_PAUSE_WATERLVL_LOW (0x54) and 0x04 to AX_PAUSE_WATERLVL_HIGH (0x55). ax88179a_reset() programs the opposite values:

	ax88179_write_u8(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_LOW, 1, 0x04);
	ax88179_write_u8(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_HIGH, 1, 0x10);

Which ordering is intended? In practice the link-up values win, because mac_link_up() runs before any traffic. They also follow the LOW > HIGH ordering of the legacy chip (0x52/0x34), so the reset values look inverted.

[ ... ]

Quoted 11 lines
drivers/net/usb/ax88179a_devices.c new file +11 -0
+	switch (speed) {
+	case SPEED_2500:
+		reg8[0] = 0x00;
+		reg8[1] = 0xF8;
+		reg8[2] = 0x07;
+		ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_MAC_TX_PAUSE, 3, 3, reg8);
+
+		reg8[0] = 0x78;
+		reg8[1] = (AX_LSOFC_WCNT_7_ACCESS << 5);
+		reg8[2] = 0;
+		ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_MAC_RX_STATUS_CDC, 3, 3, reg8);

drivers/net/usb/ax88179a_devices.c line 342

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c new file +10 -0
+
+		ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_RX_DATA_CDC_CNT, 1, 0x40);
+		ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_RX_DATA_CDC_CNT + 1, 1,
+				 AX_MAC_MIQFFCTRL_FORMAT | AX_MAC_MIQFFCTRL_DROP_CRC |
+				 AX_MAC_LSO_ERR_EN);
+
+		ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_BFM_DATA, 1, AX_XGMII_EN);
+
+		ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_LSO_ENHANCE_CTRL, 1,
+				 0x1C | AX_LSO_ENHANCE_EN);

[Severity: Medium]
The SPEED_2500 case writes three registers: AX88179A_MAC_TX_PAUSE, AX88179A_MAC_RX_DATA_CDC_CNT + 1 and AX88179A_MAC_LSO_ENHANCE_CTRL. The 1000, 100 and 10 cases never write them, and ax88179a_reset() doesn't initialize them either. Only AX88179A_BFM_DATA is cleared for the other speeds:

	if (speed != SPEED_2500)
		ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_BFM_DATA, 1, 0);

Suppose an AX88279 renegotiates from 2.5G down to 1G or 100M without a device reset. Does the MAC keep the 2.5G RX FIFO format, CRC drop and LSO enhance settings, now combined with AX_GMII_CRC_APPEND in AX88179A_MAC_RX_STATUS_CDC?

A fresh lower-speed link-up never programs that combination. The hardware effect can't be confirmed without the ASIX documentation.

[ ... ]

drivers/net/usb/ax88179a_devices.c line 378

Quoted 2 lines
drivers/net/usb/ax88179a_devices.c new file +2 -0
+	ax88179_read_cmd(dev, AX_ACCESS_MAC, PHYSICAL_LINK_STATUS, 1, 1, &link_sts);
+	ax88179a_bulkin_config(dev, link_sts, bulk_config_speed, !!duplex);

[Severity: Low]
The return value of this read is ignored. On failure the 1-byte buffer is left untouched, so link_sts stays 0 and ax88179a_bulkin_config() sees none of the SS/HS/FS bits. index then stays 0 for ETHER_LINK_1000. For ETHER_LINK_100 it is 0, or 1 for half duplex.

Those slots are not initialized in the sparse tables. AX88179A_BULKIN_SIZE[BULK_IN_SPEED_2G5] and AX88772D_BULKIN_SIZE[0..4] are all zeros.

Would this write zero for ctrl, timer, size and ifg to AX_RX_BULKIN_QCTRL, with no error reported, and leave it that way until the next link-up?

[ ... ]

Quoted 18 lines
drivers/net/usb/ax88179a_devices.c new file +18 -0
+	/* Power PHY for probing */
+	ax88179_write_u8(dev, AX88179A_PHY_POWER, 0, 0, AX_PHY_POWER);
+	msleep(250);
+
+	ret = ax88179a_init_mdio(dev);
+	if (ret)
+		goto err_nodev;
+
+	ret = ax88179a_phylink_setup(dev);
+	if (ret)
+		goto phylink_err;
+
+	ret = ax88179a_init_phy(dev);
+	if (ret)
+		goto initphy_err;
+
+	return 0;
+

drivers/net/usb/ax88179a_devices.c line 622

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c new file +10 -0
+initphy_err:
+	phylink_destroy(ax179_data->phylink);
+phylink_err:
+	ax88179a_mdio_unregister(ax179_data);
+err_nodev:
+	kfree(ax179_data);
+	ax179_data = NULL;
+
+	return ret;
+}

[Severity: Low]
Suppose ax88179a_init_mdio(), ax88179a_phylink_setup() or ax88179a_init_phy() fails (for example with "Could not find PHY"). The error labels unwind phylink, the MDIO bus and ax179_data, but AX88179A_PHY_POWER is never written back to 0.

Does this leave the PHY powered, possibly with the copper link up, on a device the driver has abandoned? ax88179a_unbind() and ax88179a_stop() both power the PHY down explicitly.

[ ... ]

Quoted 2 lines
drivers/net/usb/ax88179a_devices.c new file +2 -0
+static int ax88179a_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
+{

[ ... ]

drivers/net/usb/ax88179a_devices.c line 734

Quoted 2 lines
drivers/net/usb/ax88179a_devices.c new file +2 -0
+		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) {

[Severity: Medium]
ax88179a_bind() sets dev->hard_mtu to 9 * 1024. However, ndo_change_mtu is ax88179_change_mtu(), which overwrites it:

drivers/net/usb/ax88179_lib.c:ax88179_change_mtu() {
    ...
	dev->hard_mtu = net->mtu + net->hard_header_len;
    ...
}

After any MTU change, this check drops frames longer than mtu + 16.

With an MTU of 1500, wouldn't a full-size 802.1Q tagged frame (1518 bytes) be dropped? VLAN RX tag stripping isn't enabled, so the tag stays in the frame.

Before the first MTU change, frames up to about 9218 bytes are accepted. So whether a frame is accepted depends on whether the MTU was ever changed.

[ ... ]

Quoted 2 lines
drivers/net/usb/ax88179a_devices.c new file +2 -0
+static struct sk_buff *ax88179a_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
+{

[ ... ]

Quoted 7 lines
drivers/net/usb/ax88179a_devices.c new file +7 -0
+	if (!dev->can_dma_sg && (dev->net->features & NETIF_F_SG) && skb_linearize(skb)) {
+		dev_kfree_skb_any(skb);
+		return NULL;
+	}
+
+	headroom = skb_headroom(skb);
+	tailroom = skb_tailroom(skb);

drivers/net/usb/ax88179a_devices.c line 814

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c new file +10 -0
+
+	if (skb_cloned(skb) || !(headroom >= sizeof(tx_desc) && tailroom >= padding_size)) {
+		ax_skb = skb_copy_expand(skb, sizeof(tx_desc), padding_size, flags);
+		dev_kfree_skb_any(skb);
+		skb = ax_skb;
+		if (!skb)
+			return NULL;
+	}
+	if (padding_size != 0)
+		skb_put_zero(skb, padding_size);

[Severity: Medium]
Linearization here depends on the current NETIF_F_SG bit, not on whether the skb is actually non-linear. Feature updates are not serialized against the transmit path.

If SG is cleared with ethtool -K in the window after validate_xmit_skb() has accepted a non-linear skb and before usbnet_start_xmit() calls this tx_fixup, skb_linearize() is skipped.

For a non-cloned skb with enough tailroom, skb_put_zero() would then hit SKB_LINEAR_ASSERT(). If padding_size is 0, usbnet_start_xmit() without can_dma_sg submits the skb as one linear buffer:

	usb_fill_bulk_urb(urb, dev->udev, dev->out,
			  skb->data, skb->len, tx_complete, skb);

Can this read past the linear head, up to the 16K GSO size, and send that memory out on the wire? Would checking skb_is_nonlinear(), or linearizing whenever !dev->can_dma_sg, avoid this?

drivers/net/usb/ax88179a_devices.c line 819

Quoted 5 lines
drivers/net/usb/ax88179a_devices.c new file +5 -0
+	/* Copy TX header */
+	tx_desc_ptr = skb_push(skb, sizeof(tx_desc));
+	put_unaligned_le64(tx_desc, tx_desc_ptr);
+
+	usbnet_set_skb_tx_stats(skb, 1, 0);

[Severity: Medium]
NETIF_F_TSO is advertised and the MSS comes from gso_size, so the hardware splits a GSO skb into several frames. Here it is counted as a single packet.

Doesn't this undercount tx_packets under TSO? The existing ax88179_tx_fixup() in the same module uses:

	usbnet_set_skb_tx_stats(skb, (skb_shinfo(skb)->gso_segs ?: 1), 0);
Quoted 2 lines
drivers/net/usb/ax88179a_devices.c new file +2 -0
+static int ax88179a_reset(struct usbnet *dev)
+{

[ ... ]

drivers/net/usb/ax88179a_devices.c line 929

Quoted 7 lines
drivers/net/usb/ax88179a_devices.c new file +7 -0
+	/* Ensure EEE state is off, consistent with phylink setup */
+	ax88179_write_cmd(dev, AX_GPHY_CTL, AX_GPHY_EEE_CTRL, false, 0, NULL);
+
+	phylink_start(ax179_data->phylink);
+
+	return 0;
+}

[Severity: Low]
ax88179a_reset() is the info->reset hook that usbnet_open() calls first. If usbnet_open() fails later, for example because usbnet_status_start() can't submit the interrupt URB, it jumps to done without calling info->stop:

	if (dev->interrupt) {
		retval = usbnet_status_start(dev, GFP_KERNEL);
		if (retval < 0) {
			...
			goto done;
		}
	}

Because dev_open() failed, ndo_stop isn't called either, so phylink_stop() in ax88179a_stop() never runs.

Do phylink and the PHY state machine then keep running, with the PHY powered, while the interface is down? On the next open, phylink_start() would be called on an already started phylink. phy_start() would then WARN, because the PHY is no longer in READY or HALTED.

[ ... ]

Quoted 70 lines
drivers/net/usb/ax88179a_devices.c new file +69 -0
@@ -0,0 +1,983 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <linux/module.h>
+#include <linux/phylink.h>
+#include <linux/if_vlan.h>
+#include "ax88179_lib.h"
+
+#define AX88279_EEPROM_LEN			0x4000
+#define AX88179A_EEPROM_LEN			(32 * 20)
+
+enum ax_bulk_in_speeds {
+	BULK_IN_SPEED_2G5 = 0,
+	BULK_IN_SPEED_1G_SS = 1,
+	BULK_IN_SPEED_1G_HS   = 2,
+	BULK_IN_SPEED_100_FULL_SS = 3,
+	BULK_IN_SPEED_100_HALF_SS = 4,
+	BULK_IN_SPEED_100_FULL_HS = 5,
+	BULK_IN_SPEED_100_HALF_HS = 6,
+	BULK_IN_SPEED_FS = 7,
+};
+
+static const struct ax_bulkin_settings AX88179A_BULKIN_SIZE[] = {
+	[BULK_IN_SPEED_1G_SS]		= {5, 0x7B, 0x00, 0x17, 0x0F},
+	[BULK_IN_SPEED_1G_HS]		= {5, 0xC0, 0x02, 0x06, 0x0F},
+	[BULK_IN_SPEED_100_FULL_SS]	= {7, 0xF0, 0x00, 0x0C, 0x0F},
+	[BULK_IN_SPEED_100_HALF_SS]	= {6, 0x00, 0x00, 0x06, 0x0F},
+	[BULK_IN_SPEED_100_FULL_HS]	= {5, 0xC0, 0x04, 0x06, 0x0F},
+	[BULK_IN_SPEED_100_HALF_HS]	= {7, 0xC0, 0x04, 0x06, 0x0F},
+	[BULK_IN_SPEED_FS]		= {7, 0x00, 0x00, 0x03, 0x3F},
+};
+
+static const struct ax_bulkin_settings AX88772D_BULKIN_SIZE[] = {
+	[BULK_IN_SPEED_100_FULL_HS]	= {5, 0xC0, 0x04, 0x06, 0x0F},
+	[BULK_IN_SPEED_100_HALF_HS]	= {7, 0xC0, 0x04, 0x06, 0x0F},
+	[BULK_IN_SPEED_FS]		= {7, 0x00, 0x00, 0x03, 0x3F},
+};
+
+static const struct ax_bulkin_settings AX88279_BULKIN_SIZE[] = {
+	[BULK_IN_SPEED_2G5]		= {5, 0x10, 0x01, 0x11, 0x0F},
+	[BULK_IN_SPEED_1G_SS]		= {7, 0xB3, 0x01, 0x11, 0x0F},
+	[BULK_IN_SPEED_1G_HS]		= {7, 0xC0, 0x02, 0x06, 0x0F},
+	[BULK_IN_SPEED_100_FULL_SS]	= {7, 0x80, 0x01, 0x03, 0x0F},
+	[BULK_IN_SPEED_100_HALF_SS]	= {7, 0x80, 0x01, 0x03, 0x0F},
+	[BULK_IN_SPEED_100_FULL_HS]	= {7, 0x80, 0x01, 0x03, 0x0F},
+	[BULK_IN_SPEED_100_HALF_HS]	= {7, 0x80, 0x01, 0x03, 0x0F},
+	[BULK_IN_SPEED_FS]		= {7, 0x00, 0x00, 0x03, 0x3F},
+};
+
+static int ax88179_mdiobus_read(struct mii_bus *bus, int phy_id, int regnum)
+{
+	struct usbnet *dev = bus->priv;
+	struct ax88179_data *priv;
+	u16 res;
+	int ret;
+
+	priv = dev->driver_priv;
+	/* When reading PHYSID, return unused PHY-IDs from the ASIX vendor range */
+	if (phy_id == AX88179_PHY_ID && regnum == MII_PHYSID1)
+		return 0x003b;
+	if (phy_id == AX88179_PHY_ID && regnum == MII_PHYSID2) {
+		if (priv->chip_version == AX_VERSION_AX88179A && priv->is_ax88772d)
+			return 0x772d;
+		else if (priv->chip_version == AX_VERSION_AX88179A)
+			return 0x179a;
+		else if (priv->chip_version == AX_VERSION_AX88279)
+			return 0x2790;
+	}
+
+	ret = ax88179_read_cmd(dev, AX_ACCESS_PHY, phy_id, (__u16)regnum, 2, &res);

drivers/net/usb/ax88179a_devices.c line 79

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c new file +10 -0
+	if (ret < 0)
+		return ret;
+	return res;
+}
+
+static int ax88179_mdiobus_write(struct mii_bus *bus, int phy_id, int regnum, u16 val)
+{
+	struct usbnet *dev = bus->priv;
+
+	return ax88179_write_u16(dev, AX_ACCESS_PHY, phy_id, (__u16)regnum, val);

[Severity: Medium]
ax88179_write_u16() returns whatever __ax88179_write_cmd() returns. That is the usb_control_msg() result from usbnet_write_cmd(), which is the number of bytes transferred, so 2 on success. ax179a_write_mmd() behaves the same way through ax88179_write_cmd().

The mii_bus write and write_c45 callbacks are expected to return 0 on success and a negative errno on failure. __mdiobus_write() and __mdiobus_c45_write() pass the value straight up. phy_write() and phy_write_mmd() will therefore return 2 for a successful write on this bus.

phylib and PHY drivers commonly check the result with if (ret), or return the phy_write() result directly from a callback. For example, phy_suspend() only sets phydev->suspended when the driver's suspend callback returns 0.

Won't those paths treat every successful write on this bus as an error, or pass 2 up to their callers? Should both ax88179_mdiobus_write() and ax88179_mdiobus_write_c45() map a non-negative result to 0?

Quoted 775 lines
drivers/net/usb/ax88179a_devices.c new file +775 -0
+}
+
+static int ax179a_read_mmd(struct usbnet *dev, u16 dev_addr, u16 reg)
+{
+	u16 res;
+	int ret;
+
+	ret = ax88179_read_cmd(dev, AX88179A_PHY_CLAUSE45, dev_addr, reg, 2, &res);
+	if (ret < 0)
+		return ret;
+	return res;
+}
+
+static int ax179a_write_mmd(struct usbnet *dev, u16 dev_addr, u16 reg, u16 data)
+{
+	return ax88179_write_cmd(dev, AX88179A_PHY_CLAUSE45, dev_addr, reg, 2, &data);
+}
+
+static int ax88179_mdiobus_read_c45(struct mii_bus *bus, int addr, int devnum, int regnum)
+{
+	struct usbnet *dev = bus->priv;
+
+	if (addr != AX88179_PHY_ID)
+		return -EINVAL;
+
+	return ax179a_read_mmd(dev, devnum, regnum);
+}
+
+static int ax88179_mdiobus_write_c45(struct mii_bus *bus, int addr, int devnum,
+				     int regnum, u16 val)
+{
+	struct usbnet *dev = bus->priv;
+
+	if (addr != AX88179_PHY_ID)
+		return -EINVAL;
+
+	return ax179a_write_mmd(dev, devnum, regnum, val);
+}
+
+static void ax88179a_status(struct usbnet *dev, struct urb *urb)
+{
+	struct ax88179_data *data = dev->driver_priv;
+
+	if (urb->actual_length < 8)
+		return;
+
+	phylink_mac_interrupt(data->phylink);
+}
+
+static int ax88179a_auto_detach(struct usbnet *dev)
+{
+	u16 tmp16;
+
+	tmp16 = AX88179A_AUTODETACH_DELAY;
+	ax88179_write_cmd(dev, AX88179A_AUTODETACH, tmp16, 0, 0, NULL);
+	return 0;
+}
+
+static void ax88179a_bulkin_config(struct usbnet *dev, u8 link_sts, u8 speed, bool full_duplex)
+{
+	struct ax88179_data *ax179_data = dev->driver_priv;
+	const struct ax_bulkin_settings *bulkin_data;
+	int index = 0;
+
+	switch (speed) {
+	case ETHER_LINK_2500:	/* AX88279 only */
+		index = BULK_IN_SPEED_2G5;
+		break;
+
+	case ETHER_LINK_1000:	/* AX88279 & AX88178A */
+		if (link_sts & AX_USB_SS)
+			index = BULK_IN_SPEED_1G_SS;
+		else if (link_sts & AX_USB_HS)
+			index = BULK_IN_SPEED_1G_HS;
+		break;
+
+	case ETHER_LINK_100:
+		if (link_sts & AX_USB_SS)
+			index = BULK_IN_SPEED_100_FULL_SS;
+		else if (link_sts & AX_USB_HS)
+			index = BULK_IN_SPEED_100_FULL_HS;
+		if (!full_duplex)
+			index++;
+		break;
+
+	case ETHER_LINK_10:
+		index = BULK_IN_SPEED_FS;
+		break;
+
+	default:	/* No link */
+		index = BULK_IN_SPEED_FS;
+	}
+
+	if (link_sts & AX_USB_FS)
+		index = BULK_IN_SPEED_FS;
+
+	if (ax179_data->chip_version == AX_VERSION_AX88279) {
+		bulkin_data = AX88279_BULKIN_SIZE;
+	} else {
+		if (ax179_data->is_ax88772d)
+			bulkin_data = AX88772D_BULKIN_SIZE;
+		else
+			bulkin_data = AX88179A_BULKIN_SIZE;
+	}
+
+	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_BULKIN_QCTRL, 5, 5, &bulkin_data[index]);
+}
+
+static void ax88179a_get_pauseparam(struct net_device *net, struct ethtool_pauseparam *pause)
+{
+	struct ax88179_data *data = netdev2data(net);
+
+	phylink_ethtool_get_pauseparam(data->phylink, pause);
+}
+
+static int ax88179a_set_pauseparam(struct net_device *net, struct ethtool_pauseparam *pause)
+{
+	struct ax88179_data *data = netdev2data(net);
+
+	return phylink_ethtool_set_pauseparam(data->phylink, pause);
+}
+
+static int ax88179a_get_link_ksettings(struct net_device *net,
+				       struct ethtool_link_ksettings *cmd)
+{
+	struct ax88179_data *data = netdev2data(net);
+
+	return phylink_ethtool_ksettings_get(data->phylink, cmd);
+}
+
+static int ax88179a_set_link_ksettings(struct net_device *net,
+				       const struct ethtool_link_ksettings *cmd)
+{
+	struct ax88179_data *data = netdev2data(net);
+
+	return phylink_ethtool_ksettings_set(data->phylink, cmd);
+}
+
+static int ax88179a_get_eeprom_len(struct net_device *net)
+{
+	struct ax88179_data *ax179_data = netdev2data(net);
+
+	if (ax179_data->chip_version >= AX_VERSION_AX88279)
+		return AX88279_EEPROM_LEN;
+	else
+		return AX88179A_EEPROM_LEN;
+}
+
+static const struct ethtool_ops ax88179a_ethtool_ops = {
+	.get_link		= ethtool_op_get_link,
+	.get_msglevel		= usbnet_get_msglevel,
+	.set_msglevel		= usbnet_set_msglevel,
+	.get_wol		= ax88179_get_wol,
+	.set_wol		= ax88179_set_wol,
+	.get_eeprom_len		= ax88179a_get_eeprom_len,
+	.get_eeprom		= ax88179_get_eeprom,
+	.set_eeprom		= ax88179_set_eeprom,
+	.nway_reset		= phy_ethtool_nway_reset,
+	.get_link_ksettings	= ax88179a_get_link_ksettings,
+	.set_link_ksettings	= ax88179a_set_link_ksettings,
+	.get_pauseparam		= ax88179a_get_pauseparam,
+	.set_pauseparam		= ax88179a_set_pauseparam,
+	.get_ts_info		= ethtool_op_get_ts_info,
+};
+
+static void ax88179a_mdio_unregister(struct ax88179_data *data)
+{
+	mdiobus_unregister(data->mdio);
+	mdiobus_free(data->mdio);
+}
+
+static int ax88179a_init_phy(struct usbnet *dev)
+{
+	struct ax88179_data *data = dev->driver_priv;
+	int ret;
+
+	data->phydev = mdiobus_get_phy(data->mdio, AX88179_PHY_ID);
+	if (!data->phydev) {
+		netdev_err(dev->net, "Could not find PHY\n");
+		return -ENODEV;
+	}
+
+	data->phydev->irq = PHY_MAC_INTERRUPT;
+	ret = phylink_connect_phy(data->phylink, data->phydev);
+	if (ret) {
+		netdev_err(dev->net, "Could not connect PHY\n");
+		return ret;
+	}
+
+	phy_suspend(data->phydev);
+	data->phydev->mac_managed_pm = true;
+
+	phy_attached_info(data->phydev);
+
+	return 0;
+}
+
+static void ax88179a_mac_config(struct phylink_config *config, unsigned int mode,
+				const struct phylink_link_state *state)
+{
+	/* Nothing to do */
+}
+
+static void ax88179a_mac_link_down(struct phylink_config *config,
+				   unsigned int mode, phy_interface_t interface)
+{
+	/* Nothing to do */
+}
+
+static void ax88179a_mac_link_up(struct phylink_config *config,
+				 struct phy_device *phy,
+				 unsigned int phy_mode, phy_interface_t interface,
+				 int speed, int duplex,
+				 bool tx_pause, bool rx_pause)
+{
+	struct usbnet *dev = netdev_priv(to_net_dev(config->dev));
+	struct ax88179_data *ax179_data = dev->driver_priv;
+	u8 link_sts = 0, reg8[3];
+	u8 bulk_config_speed = 0;
+	u16 mode;
+
+	/* Stop RX/TX for link configuration */
+	ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, AX_RX_CTL_STOP);
+	ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_PATH, 1, 0);
+
+	ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_CDC_DELAY_TX, 1, 0xa5);
+
+	ax88179_write_u16(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_LOW, 2, 0x0410);
+
+	ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_ETH_TX_GAP, 1, 0);
+
+	ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_EP5_EHR, 1, 0x07);
+
+	ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_NEW_PAUSE_CTRL, 1,
+			 0x28 | AX_NEW_PAUSE_EN);
+
+	mode = AX_MEDIUM_RECEIVE_EN;
+	if (tx_pause)
+		mode |= AX_MEDIUM_TXFLOW_CTRLEN;
+	if (rx_pause)
+		mode |= AX_MEDIUM_RXFLOW_CTRLEN;
+
+	switch (speed) {
+	case SPEED_2500:
+		reg8[0] = 0x00;
+		reg8[1] = 0xF8;
+		reg8[2] = 0x07;
+		ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_MAC_TX_PAUSE, 3, 3, reg8);
+
+		reg8[0] = 0x78;
+		reg8[1] = (AX_LSOFC_WCNT_7_ACCESS << 5);
+		reg8[2] = 0;
+		ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_MAC_RX_STATUS_CDC, 3, 3, reg8);
+
+		ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_RX_DATA_CDC_CNT, 1, 0x40);
+		ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_RX_DATA_CDC_CNT + 1, 1,
+				 AX_MAC_MIQFFCTRL_FORMAT | AX_MAC_MIQFFCTRL_DROP_CRC |
+				 AX_MAC_LSO_ERR_EN);
+
+		ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_BFM_DATA, 1, AX_XGMII_EN);
+
+		ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_LSO_ENHANCE_CTRL, 1,
+				 0x1C | AX_LSO_ENHANCE_EN);
+
+		mode |= AX_MEDIUM_GIGAMODE | AX_MEDIUM_FULL_DUPLEX;
+		bulk_config_speed = ETHER_LINK_2500;
+
+		break;
+
+	case SPEED_1000:
+		mode |= AX_MEDIUM_GIGAMODE;
+		bulk_config_speed = ETHER_LINK_1000;
+		fallthrough;
+
+	case SPEED_100:
+		reg8[0] = 0x78;
+		reg8[1] = (AX_LSOFC_WCNT_7_ACCESS << 5) | AX_GMII_CRC_APPEND;
+		reg8[2] = 0;
+		ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_MAC_RX_STATUS_CDC, 3, 3, reg8);
+
+		ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_RX_DATA_CDC_CNT, 1, 0x40);
+		if (!bulk_config_speed)
+			bulk_config_speed = ETHER_LINK_100;
+		break;
+
+	case SPEED_10:
+		reg8[0] = 0xFA;
+		reg8[1] = (AX_LSOFC_WCNT_7_ACCESS << 5) | AX_GMII_CRC_APPEND;
+		reg8[2] = 0xFF;
+		ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_MAC_RX_STATUS_CDC, 3, 3, reg8);
+
+		ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_RX_DATA_CDC_CNT, 1, 0xFA);
+
+		bulk_config_speed = ETHER_LINK_10;
+		break;
+	}
+
+	ax88179_read_cmd(dev, AX_ACCESS_MAC, PHYSICAL_LINK_STATUS, 1, 1, &link_sts);
+	ax88179a_bulkin_config(dev, link_sts, bulk_config_speed, !!duplex);
+
+	if (speed != SPEED_2500)
+		ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_BFM_DATA, 1, 0);
+
+	if (duplex)
+		mode |= AX_MEDIUM_FULL_DUPLEX;
+
+	mutex_lock(&ax179_data->medium_status_mutex);
+	if (dev->net->mtu > 1500)
+		mode |= AX_MEDIUM_JUMBO_EN;
+	ax88179_write_u16(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 2, mode);
+
+	ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, READ_ONCE(ax179_data->rxctl));
+	mutex_unlock(&ax179_data->medium_status_mutex);
+
+	ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_PATH, 1,
+			 AX_MAC_RX_PATH_READY | AX_MAC_TX_PATH_READY);
+}
+
+static const struct phylink_mac_ops ax88179a_phylink_mac_ops = {
+	.mac_config = ax88179a_mac_config,
+	.mac_link_down = ax88179a_mac_link_down,
+	.mac_link_up = ax88179a_mac_link_up,
+};
+
+static int ax88179a_phylink_setup(struct usbnet *dev)
+{
+	struct ax88179_data *data = dev->driver_priv;
+	phy_interface_t phy_if_mode;
+	struct phylink *phylink;
+
+	data->phylink_config.dev = &dev->net->dev;
+	data->phylink_config.type = PHYLINK_NETDEV;
+	data->phylink_config.mac_capabilities = MAC_SYM_PAUSE | MAC_ASYM_PAUSE | MAC_100;
+	if (data->is_ax88772d)
+		data->phylink_config.mac_capabilities |= MAC_10;
+	else if (data->chip_version < AX_VERSION_AX88279)
+		data->phylink_config.mac_capabilities |= MAC_10 | MAC_1000;
+	else
+		data->phylink_config.mac_capabilities |= MAC_1000 | MAC_2500FD;
+
+	if (!data->is_ax88772d) {
+		data->phylink_config.lpi_capabilities = MAC_100FD | MAC_1000FD;
+		data->phylink_config.eee_enabled_default = false;
+	}
+
+	if (data->chip_version == AX_VERSION_AX88279) {
+		__set_bit(PHY_INTERFACE_MODE_2500BASEX,
+			  data->phylink_config.supported_interfaces);
+		__set_bit(PHY_INTERFACE_MODE_SGMII,
+			  data->phylink_config.supported_interfaces);
+		phy_if_mode = PHY_INTERFACE_MODE_2500BASEX;
+	} else {
+		__set_bit(PHY_INTERFACE_MODE_SGMII,
+			  data->phylink_config.supported_interfaces);
+		phy_if_mode = PHY_INTERFACE_MODE_SGMII;
+	}
+
+	phylink = phylink_create(&data->phylink_config, dev->net->dev.fwnode,
+				 phy_if_mode, &ax88179a_phylink_mac_ops);
+	if (IS_ERR(phylink))
+		return PTR_ERR(phylink);
+
+	data->phylink = phylink;
+	return 0;
+}
+
+static int ax88179a_init_mdio(struct usbnet *dev)
+{
+	struct ax88179_data *data = dev->driver_priv;
+	int ret;
+
+	data->mdio = mdiobus_alloc();
+	if (!data->mdio)
+		return -ENOMEM;
+
+	data->mdio->priv = dev;
+	data->mdio->read = ax88179_mdiobus_read;
+	data->mdio->write = ax88179_mdiobus_write;
+	data->mdio->read_c45 = ax88179_mdiobus_read_c45;
+	data->mdio->write_c45 = ax88179_mdiobus_write_c45;
+	data->mdio->name = "AX88179A MDIO Bus";
+	data->mdio->phy_mask = ~(1 << AX88179_PHY_ID);
+	/* mii bus name is usb-<usb bus number>-<usb device number> */
+	snprintf(data->mdio->id, MII_BUS_ID_SIZE, "usb-%03d:%03d",
+		 dev->udev->bus->busnum, dev->udev->devnum);
+
+	ret = mdiobus_register(data->mdio);
+	if (ret) {
+		netdev_err(dev->net, "Could not register MDIO bus (err %d)\n", ret);
+		mdiobus_free(data->mdio);
+		data->mdio = NULL;
+	}
+
+	return ret;
+}
+
+static int ax88179a_mii_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
+{
+	struct ax88179_data *data = netdev2data(net);
+
+	return phylink_mii_ioctl(data->phylink, rq, cmd);
+}
+
+static const struct net_device_ops ax88179a_netdev_ops = {
+	.ndo_open		= usbnet_open,
+	.ndo_stop		= usbnet_stop,
+	.ndo_start_xmit		= usbnet_start_xmit,
+	.ndo_tx_timeout		= usbnet_tx_timeout,
+	.ndo_get_stats64	= dev_get_tstats64,
+	.ndo_change_mtu		= ax88179_change_mtu,
+	.ndo_set_mac_address	= ax88179_set_mac_addr,
+	.ndo_validate_addr	= eth_validate_addr,
+	.ndo_eth_ioctl		= ax88179a_mii_ioctl,
+};
+
+static int ax88179a_bind(struct usbnet *dev, struct usb_interface *intf)
+{
+	struct usb_device *udev = interface_to_usbdev(intf);
+	struct ax88179_data *ax179_data;
+	int ret;
+
+	/* Check if vendor configuration */
+	if (udev->actconfig->desc.bConfigurationValue != 1) {
+		netdev_info(dev->net, "Switching to vendor mode\n");
+		usb_driver_set_configuration(udev, 1);
+		return -ENODEV;
+	}
+
+	ret = usbnet_get_endpoints(dev, intf);
+	if (ret < 0)
+		return ret;
+
+	ax179_data = kzalloc_obj(*ax179_data);
+	if (!ax179_data)
+		return -ENOMEM;
+
+	dev->driver_priv = ax179_data;
+	mutex_init(&ax179_data->medium_status_mutex);
+
+	ret = ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_CHIP_STATUS,
+			       1, 1, &ax179_data->chip_version);
+	if (ret < 0)
+		goto err_nodev;
+
+	ax179_data->chip_version = (ax179_data->chip_version & 0xf0) >> 4;
+	ax179_data->is_ax88772d = 0;
+	if (ax179_data->chip_version == AX_VERSION_AX88179A) {
+		if (le16_to_cpu(udev->descriptor.bcdDevice) == 0x300)
+			ax179_data->is_ax88772d = 1;
+	}
+
+	for (int i = 0; i < 3; i++) {
+		ret = ax88179_read_cmd(dev, AX88179A_ACCESS_BL, AX88179A_SW_VERSION + i,
+				       1, 1, &ax179_data->fw_version[i]);
+		if (ret < 0)
+			ax179_data->fw_version[i] = 0xff;
+	}
+	ret = ax88179_read_cmd(dev, AX88179A_ACCESS_BL, AX88179A_SW_REVISION,
+			       1, 1, &ax179_data->fw_version[3]);
+	if (ret < 0)
+		ax179_data->fw_version[3] = 0xff;
+
+	netdev_info(dev->net, "AX88179A/279/772D Chip Version: %x, FW: %d.%d.%d.%d\n",
+		    ax179_data->chip_version,
+		    ax179_data->fw_version[0], ax179_data->fw_version[1],
+		    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.
+	 * Also configure eeprom access parameters.
+	 */
+	if (ax179_data->chip_version == AX_VERSION_AX88279) {
+		ax179_data->ip_align = 1;
+		ax179_data->eeprom_read_cmd = AX88179A_FLASH_READ;
+		ax179_data->eeprom_write_cmd = AX88179A_FLASH_WRITE;
+		ax179_data->eeprom_block = 256;
+		ax179_data->eeprom_wen = 1;
+	} else {
+		ax179_data->ip_align = 0;
+		ax179_data->eeprom_read_cmd = AX_ACCESS_EFUS;
+		ax179_data->eeprom_write_cmd = AX_ACCESS_EFUS;
+		ax179_data->eeprom_block = 20;
+		ax179_data->eeprom_wen = 0;
+	}
+
+	dev->net->netdev_ops = &ax88179a_netdev_ops;
+	dev->net->ethtool_ops = &ax88179a_ethtool_ops;
+	dev->net->needed_headroom = 8;
+	dev->net->needed_tailroom = 8;
+	dev->net->min_mtu = ETH_MIN_MTU;
+	dev->hard_mtu = 9 * 1024;
+	dev->net->max_mtu = dev->hard_mtu - dev->net->hard_header_len;
+
+	if (!ax179_data->is_ax88772d)
+		dev->mii.supports_gmii = 1;
+
+	dev->net->features |= NETIF_F_SG | NETIF_F_IP_CSUM |
+			      NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM | NETIF_F_TSO;
+
+	dev->net->hw_features |= dev->net->features;
+
+	dev->net->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM |
+				  NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM | NETIF_F_TSO;
+
+	netif_set_tso_max_size(dev->net, 16384);
+
+	/* Enable Transmission of Link Speed byte in interrupt URB */
+	ax88179_write_cmd(dev, AX_FW_MODE, AX_FW_MODE_179A, 0, 0, NULL);
+	ax88179_write_cmd(dev, AX_RELOAD_EEPROM_EFUSE, 0, 0, 0, NULL);
+
+	/* Read MAC address from DTB or ASIX chip */
+	ax88179_get_mac_addr(dev);
+	memcpy(dev->net->perm_addr, dev->net->dev_addr, ETH_ALEN);
+
+	/* Power PHY for probing */
+	ax88179_write_u8(dev, AX88179A_PHY_POWER, 0, 0, AX_PHY_POWER);
+	msleep(250);
+
+	ret = ax88179a_init_mdio(dev);
+	if (ret)
+		goto err_nodev;
+
+	ret = ax88179a_phylink_setup(dev);
+	if (ret)
+		goto phylink_err;
+
+	ret = ax88179a_init_phy(dev);
+	if (ret)
+		goto initphy_err;
+
+	return 0;
+
+initphy_err:
+	phylink_destroy(ax179_data->phylink);
+phylink_err:
+	ax88179a_mdio_unregister(ax179_data);
+err_nodev:
+	kfree(ax179_data);
+	ax179_data = NULL;
+
+	return ret;
+}
+
+static void ax88179a_unbind(struct usbnet *dev, struct usb_interface *intf)
+{
+	struct ax88179_data *ax179_data = dev->driver_priv;
+
+	/* Configure RX control register => stop operation */
+	ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, AX_RX_CTL_STOP);
+
+	rtnl_lock();
+	phylink_disconnect_phy(ax179_data->phylink);
+	rtnl_unlock();
+	phylink_destroy(ax179_data->phylink);
+	ax88179a_mdio_unregister(ax179_data);
+
+	ax88179_write_u8(dev, AX88179A_PHY_POWER, 0, 0, 0);
+
+	kfree(ax179_data);
+}
+
+static void ax88179a_rx_checksum(struct sk_buff *skb, u64 pkt_desc)
+{
+	u32 pkt_type;
+
+	skb->ip_summed = CHECKSUM_NONE;
+	/* checksum error bit is set */
+	if (pkt_desc & AX179A_RX_PD_L4_ERR || pkt_desc & AX179A_RX_PD_L3_ERR)
+		return;
+
+	pkt_type = pkt_desc & AX179A_RX_PD_L4_TYPE_MASK;
+	/* It must be a TCP or UDP packet with a valid checksum */
+	if (pkt_type == AX179A_RX_PD_L4_TCP || pkt_type == AX179A_RX_PD_L4_UDP)
+		skb->ip_summed = CHECKSUM_UNNECESSARY;
+}
+
+static int ax88179a_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
+{
+	struct ax88179_data *ax179_data = dev->driver_priv;
+	struct sk_buff *ax_skb;
+	u32 hdr_off, pkt_end;
+	__le64 *pkt_desc_ptr;
+	u16 vlan_tag;
+	u16 pkt_cnt;
+	u64 rx_hdr;
+
+	/* SKB contents for AX179A-based chips:
+	 *   <packet 1>
+	 *   ...
+	 *   <packet N>
+	 *   <per-packet metadata entry 1>
+	 *   ...
+	 *   <per-packet metadata entry N>
+	 *   <rx_hdr>
+	 *
+	 * where:
+	 *   <packet N> contains pkt_len data bytes and padding:
+	 *		2 bytes of IP alignment (optional, depends on AX_RX_CTL_IPE flag)
+	 *		packet data received
+	 *		optional padding to 8-bytes boundary
+	 *   <per-packet metadata entry N> contains 8 bytes:
+	 *		pkt_len and fields AX_RXHDR_*
+	 *   <rx-hdr>	contains 8 bytes:
+	 *		pkt_cnt and hdr_off (offset of <per-packet metadata entry 1>)
+	 *
+	 * pkt_cnt is number of entries in the per-packet metadata array.
+	 */
+
+	if (!skb || skb->len < sizeof(rx_hdr))
+		goto err;
+
+	/* RX Descriptor Header */
+	skb_trim(skb, skb->len - sizeof(rx_hdr));
+	rx_hdr = get_unaligned_le64((__le64 *)skb_tail_pointer(skb));
+
+	/* Check these packets */
+	hdr_off = FIELD_GET(AX179A_RX_DH_DESC_OFFSET, rx_hdr);
+	pkt_cnt = rx_hdr & AX179A_RX_DH_PKT_CNT_MASK;
+
+	/* Consistency check header position */
+	if (hdr_off != skb->len - (pkt_cnt * sizeof(rx_hdr)))
+		goto err;
+
+	/* Make sure that the bounds of the metadata array are inside the SKB
+	 * (and in front of the counter at the end).
+	 */
+	if (pkt_cnt * 8 + hdr_off > skb->len)
+		goto err;
+
+	/* Packets must not overlap the metadata array */
+	skb_trim(skb, hdr_off);
+
+	if (!pkt_cnt)
+		goto err;
+
+	/* Get the first RX packet descriptor */
+	pkt_desc_ptr = (__le64 *)(skb->data + hdr_off);
+
+	pkt_end = 0;
+	while (pkt_cnt--) {
+		u64 pkt_desc = get_unaligned_le64(pkt_desc_ptr);
+		u32 pkt_len_plus_padd;
+		u32 pkt_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);
+
+		pkt_end += pkt_len_plus_padd;
+		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) {
+			skb_pull(skb, pkt_len_plus_padd);
+
+			/* Next RX Packet Descriptor */
+			pkt_desc_ptr++;
+			continue;
+		}
+
+		ax_skb = netdev_alloc_skb_ip_align(dev->net, pkt_len);
+		if (!ax_skb)
+			goto err;
+
+		skb_put(ax_skb, pkt_len);
+		memcpy(ax_skb->data, skb->data + (ax179_data->ip_align ? AX179A_RX_HW_PAD : 0),
+		       pkt_len);
+
+		if (ax179_data->rx_checksum)
+			ax88179a_rx_checksum(ax_skb, pkt_desc);
+
+		if (pkt_desc & AX179A_RX_PD_VLAN) {
+			vlan_tag = pkt_desc >> AX179A_RX_PD_VLAN_SHIFT;
+			__vlan_hwaccel_put_tag(ax_skb, htons(ETH_P_8021Q), vlan_tag);
+		}
+
+		usbnet_skb_return(dev, ax_skb);
+		skb_pull(skb, pkt_len_plus_padd);
+
+		/* Next RX Packet Header */
+		pkt_desc_ptr++;
+	}
+
+	return 1;
+
+err:
+	return 0;
+}
+
+static struct sk_buff *ax88179a_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
+{
+	u64 tx_desc = skb->len & AX179A_TX_DESC_LEN_MASK;
+	int frame_size = dev->maxpacket;
+	struct sk_buff *ax_skb;
+	u64 *tx_desc_ptr;
+	int padding_size;
+	int headroom;
+	int tailroom;
+	u16 tci = 0;
+
+	/* TSO MSS */
+	tx_desc |= FIELD_PREP(AX179A_TX_DESC_MSS, (u64)skb_shinfo(skb)->gso_size);
+
+	headroom = (skb->len + sizeof(tx_desc)) % 8;
+	padding_size = headroom ? 8 - headroom : 0;
+
+	if (((skb->len + sizeof(tx_desc) + padding_size) % frame_size) == 0) {
+		padding_size += 8;
+		tx_desc |= AX179A_TX_DESC_DROP_PADD;
+	}
+
+	if ((dev->net->features & NETIF_F_HW_VLAN_CTAG_TX) && (vlan_get_tag(skb, &tci) >= 0)) {
+		tx_desc |= AX179A_TX_DESC_VLAN;
+		tx_desc |= FIELD_PREP(AX179A_TX_DESC_VLAN_ID, (u64)tci);
+	}
+
+	if (!dev->can_dma_sg && (dev->net->features & NETIF_F_SG) && skb_linearize(skb)) {
+		dev_kfree_skb_any(skb);
+		return NULL;
+	}
+
+	headroom = skb_headroom(skb);
+	tailroom = skb_tailroom(skb);
+
+	if (skb_cloned(skb) || !(headroom >= sizeof(tx_desc) && tailroom >= padding_size)) {
+		ax_skb = skb_copy_expand(skb, sizeof(tx_desc), padding_size, flags);
+		dev_kfree_skb_any(skb);
+		skb = ax_skb;
+		if (!skb)
+			return NULL;
+	}
+	if (padding_size != 0)
+		skb_put_zero(skb, padding_size);
+	/* Copy TX header */
+	tx_desc_ptr = skb_push(skb, sizeof(tx_desc));
+	put_unaligned_le64(tx_desc, tx_desc_ptr);
+
+	usbnet_set_skb_tx_stats(skb, 1, 0);
+
+	return skb;
+}
+
+static int ax88179a_reset(struct usbnet *dev)
+{
+	struct ax88179_data *ax179_data = dev->driver_priv;
+	u16 *tmp16;
+	u8 buf[5];
+	u16 rxctl;
+	u8 *tmp;
+
+	tmp16 = (u16 *)buf;
+	tmp = (u8 *)buf;
+
+	/* Power up ethernet PHY */
+	ax88179_write_u8(dev, AX88179A_PHY_POWER, 0, 0, AX_PHY_POWER);
+	msleep(250);
+
+	/* Ethernet PHY Auto Detach*/
+	ax88179a_auto_detach(dev);
+
+	ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_BULK_OUT_CTRL, 1, AX_MAC_EFF_EN);
+
+	ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 0);
+
+	ax88179_write_u8(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_LOW, 1, 0x04);
+	ax88179_write_u8(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_HIGH, 1, 0x10);
+
+	*tmp = 0;
+	if (dev->net->features & NETIF_F_HW_VLAN_CTAG_FILTER)
+		*tmp |= AX_VLAN_CONTROL_VFE;
+	if (dev->net->features & NETIF_F_HW_VLAN_CTAG_RX)
+		*tmp |= AX_VLAN_CONTROL_VSO;
+	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_CONTROL, 1, 1, tmp);

drivers/net/usb/ax88179a_devices.c line 864

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c new file +10 -0
+
+	ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_BM_INT_MASK, 1, 0xff);
+
+	ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_BM_RX_DMA_CTL, 1, 0);
+	ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_BM_TX_DMA_CTL, 1, 0);
+	ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_ARC_CTRL, 1, 0);
+	ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_SWP_CTRL, 1, 0);
+	ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_TX_HDR_CKSUM, 1, 0);
+
+	/* Read MAC address from DTB or asix chip */

[Severity: Medium]
ax88179a_reset() is the info->reset hook, so it runs on every usbnet_open(). It calls ax88179_get_mac_addr() again and then copies dev_addr into perm_addr, although ax88179a_bind() already did both.

Suppose the administrator sets a MAC address while the interface is down. ax88179_set_mac_addr() stores it with eth_hw_addr_set(), which sets addr_assign_type to NET_ADDR_SET, and writes it to AX_NODE_ID. On the next ifup there are two cases.

If eth_platform_get_mac_address() returns an address, ax88179_get_mac_addr() replaces the configured dev_addr with the platform one. It also writes that back to AX_NODE_ID, so the user setting is silently lost.

Otherwise it reads the configured address back from AX_NODE_ID and marks it NET_ADDR_PERM if it is not locally administered. The memcpy() then overwrites perm_addr with it. From then on ethtool -P reports the configured address, and the real permanent address is gone until the device is probed again.

Do these chips need the MAC address re-read on open? If the reset sequence loses AX_NODE_ID, would it be enough to write dev->net->dev_addr back to AX_NODE_ID here and leave perm_addr alone?

Quoted 110 lines
drivers/net/usb/ax88179a_devices.c new file +109 -0
+	ax88179_get_mac_addr(dev);
+	memcpy(dev->net->perm_addr, dev->net->dev_addr, ETH_ALEN);
+
+	/* The Bulk-Register configuration for the AX88179A is done in
+	 * ax88179a_mac_link_up(), once the link is up for a given link and USB-speed.
+	 */
+	if (ax179_data->is_ax88772d)
+		dev->rx_urb_size = 1024 * 24;
+	else
+		dev->rx_urb_size = 1024 * 48;
+
+	/* Enable checksum offload */
+	if (dev->net->features & NETIF_F_RXCSUM) {
+		ax88179_write_u8(dev, AX_ACCESS_MAC, AX_RXCOE_CTL, 1,
+				 AX_RXCOE_IP | AX_RXCOE_TCP | AX_RXCOE_UDP |
+				 AX_RXCOE_TCPV6 | AX_RXCOE_UDPV6);
+		ax179_data->rx_checksum = 1;
+	} else {
+		ax179_data->rx_checksum = 0;
+		ax88179_write_u8(dev, AX_ACCESS_MAC, AX_RXCOE_CTL, 1, 0);
+	}
+
+	*tmp = 0;
+	if (dev->net->features & NETIF_F_IP_CSUM)
+		*tmp = AX_TXCOE_IP | AX_TXCOE_TCP | AX_TXCOE_UDP;
+	if (dev->net->features & NETIF_F_IPV6_CSUM)
+		*tmp |= AX_TXCOE_IP | AX_TXCOE_TCPV6 | AX_TXCOE_UDPV6;
+	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;
+	if (ax179_data->ip_align)
+		rxctl |= AX_RX_CTL_IPE;
+	if (dev->net->flags & IFF_PROMISC)
+		rxctl |= AX_RX_CTL_PRO;
+	WRITE_ONCE(ax179_data->rxctl, rxctl);
+	ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, rxctl);
+
+	if (ax179_data->chip_version < AX_VERSION_AX88179A)
+		*tmp = AX_MONITOR_MODE_PMETYPE | AX_MONITOR_MODE_PMEPOL | AX_MONITOR_MODE_RWMP;
+	else
+		*tmp = AX_MONITOR_MODE_RWMP;
+	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD, 1, 1, tmp);
+
+	/* Configure default medium type => giga */
+	*tmp16 = AX_MEDIUM_RECEIVE_EN | AX_MEDIUM_TXFLOW_CTRLEN |
+		 AX_MEDIUM_RXFLOW_CTRLEN | AX_MEDIUM_FULL_DUPLEX;
+	if (!ax179_data->is_ax88772d)
+		*tmp16 |= AX_MEDIUM_GIGAMODE;
+	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 2, 2, tmp16);
+
+	/* Check if WoL is supported */
+	ax179_data->wol_supported = 0;
+	if (ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD,
+			     1, 1, tmp) > 0)
+		ax179_data->wol_supported = WAKE_MAGIC | WAKE_PHY;
+
+	/* Ensure EEE state is off, consistent with phylink setup */
+	ax88179_write_cmd(dev, AX_GPHY_CTL, AX_GPHY_EEE_CTRL, false, 0, NULL);
+
+	phylink_start(ax179_data->phylink);
+
+	return 0;
+}
+
+static int ax88179a_stop(struct usbnet *dev)
+{
+	struct ax88179_data *ax179_data = dev->driver_priv;
+	u16 reg16 = 0;
+
+	phylink_stop(ax179_data->phylink);
+
+	ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 2, 2, &reg16);
+	reg16 &= ~AX_MEDIUM_RECEIVE_EN;
+	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 2, 2, &reg16);
+
+	ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 0);
+
+	ax88179_write_u8(dev, AX88179A_PHY_POWER, 0, 0, 0);
+
+	return 0;
+}
+
+const struct driver_info ax88179a_info = {
+	.description = "ASIX AX88179A USB 3.2 Gigabit Ethernet",
+	.bind = ax88179a_bind,
+	.unbind = ax88179a_unbind,
+	.status = ax88179a_status,
+	.reset = ax88179a_reset,
+	.stop = ax88179a_stop,
+	.flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_MULTI_PACKET | FLAG_AVOID_UNLINK_URBS,
+	.rx_fixup = ax88179a_rx_fixup,
+	.tx_fixup = ax88179a_tx_fixup,
+};
+
+const struct driver_info ax88772d_info = {
+	.description = "ASIX AX88772D/E USB 2.0 Fast Ethernet",
+	.bind = ax88179a_bind,
+	.unbind = ax88179a_unbind,
+	.status = ax88179a_status,
+	.reset = ax88179a_reset,
+	.stop = ax88179a_stop,
+	.flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_MULTI_PACKET | FLAG_AVOID_UNLINK_URBS,
+	.rx_fixup = ax88179a_rx_fixup,
+	.tx_fixup = ax88179a_tx_fixup,
+};
+
+const struct driver_info ax88279_info = {

drivers/net/usb/ax88179a_devices.c line 983

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c new file +10 -0
+	.description = "ASIX AX88279 USB 3.2 2.5Gigabit Ethernet",
+	.bind = ax88179a_bind,
+	.unbind = ax88179a_unbind,
+	.status = ax88179a_status,
+	.reset = ax88179a_reset,
+	.stop = ax88179a_stop,
+	.flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_MULTI_PACKET | FLAG_AVOID_UNLINK_URBS,
+	.rx_fixup = ax88179a_rx_fixup,
+	.tx_fixup = ax88179a_tx_fixup,
+};

[Severity: High]
All three new driver_info entries set FLAG_AVOID_UNLINK_URBS. None of the existing entries in ax88179_178a.c do.

With that flag, usbnet_stop() skips usbnet_terminate_urbs(). After ifdown the RX URBs stay submitted and remain on dev->rxq. ax88179a_stop() only clears AX_MEDIUM_RECEIVE_EN and AX_RX_CTL and powers the PHY down, so those URBs never complete on their own. usbnet_stop() then cancels bh_work and deletes dev->delay, but nothing prevents them from being re-armed later.

Now suppose the adapter is unplugged or unbound while the interface is down:

usb_unbind_interface()
usb_disable_interface() <- leftover RX URBs killed, -ESHUTDOWN

    rx_complete()
      defer_bh()           <- queues dev->bh_work

usbnet_disconnect()
unregister_netdev() <- already down, usbnet_stop() not called
free_netdev() <- bh_work and dev->delay not cancelled

On a physical unplug the leftover URBs can also fail first with -EPROTO and similar errors, and rx_complete() then arms dev->delay. Either way, usbnet_bh() would later run on the freed struct usbnet and net_device.

Is FLAG_AVOID_UNLINK_URBS actually needed for these chips? If the hardware copes with URB unlinking, dropping the flag avoids this. If it doesn't, wouldn't usbnet_disconnect() need to cancel bh_work and dev->delay before freeing the netdev?

[Severity: Medium]
ax88179a_bind() allocates ax179_data with kzalloc_obj() and never sets wol_supported. The only place it gets filled in is ax88179a_reset(). usbnet calls that from usbnet_open(), so it first runs on the first ifup.

usbnet_probe() registers the netdev right after bind returns. Until the interface has been brought up once, ax88179_get_wol() reports supported = 0. ax88179_set_wol() rejects any non-zero wolopts with -EINVAL, and so does the ethtool netlink path.

WoL can be queried and configured while the interface is down. udev and systemd-networkd apply WakeOnLan= link settings when the interface appears, which is usually before it is up. Won't that setting always fail on these chips?

The legacy ax88179_bind() avoids this because it calls ax88179_reset() from bind. Could the WoL capability check also be done in ax88179a_bind(), or moved there entirely?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261114-ax88179a-v21-0-c2d34410bcbe%40birger-koblitz.de
#13 lore raw

PATCH v21 5/13 ax88179_178a: Add EEE configuration support for AX88179A MACs

In reply to Birger Koblitz

The AX88179A uses a simple HW configuration for EEE
via a single EEE configuration register without LPI timer support Add support for setting this EEE enable/disable register in implementations of mac_enable_tx_lpi/mac_disable_tx_lpi.

---
 drivers/net/usb/ax88179a_devices.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/net/usb/ax88179a_devices.c +17 -0
index 1aa8479422517bff6758c884c5e47258c5d3ed3a..62619fd68c408f453e48c94020bce2254da9a1f9 100644
@@ -395,10 +395,27 @@ static void ax88179a_mac_link_up(struct phylink_config *config,
 			 AX_MAC_RX_PATH_READY | AX_MAC_TX_PATH_READY);
 }
 
+static void ax88179a_mac_disable_tx_lpi(struct phylink_config *config)
+{
+	struct usbnet *dev = netdev_priv(to_net_dev(config->dev));
+
+	ax88179_write_cmd(dev, AX_GPHY_CTL, AX_GPHY_EEE_CTRL, false, 0, NULL);
+}
+
+static int ax88179a_mac_enable_tx_lpi(struct phylink_config *config, u32 timer, bool tx_clk_stop)
+{
+	struct usbnet *dev = netdev_priv(to_net_dev(config->dev));
+
+	/* AX88179A does not provide LPI timer registers */
+	return ax88179_write_cmd(dev, AX_GPHY_CTL, AX_GPHY_EEE_CTRL, true, 0, NULL);
+}
+
 static const struct phylink_mac_ops ax88179a_phylink_mac_ops = {
 	.mac_config = ax88179a_mac_config,
 	.mac_link_down = ax88179a_mac_link_down,
 	.mac_link_up = ax88179a_mac_link_up,
+	.mac_disable_tx_lpi = ax88179a_mac_disable_tx_lpi,
+	.mac_enable_tx_lpi = ax88179a_mac_enable_tx_lpi,
 };
 
 static int ax88179a_phylink_setup(struct usbnet *dev)
Signature · 1 line
2.47.3
#14 lore raw

Re: [PATCH net-next v21 05/13] ax88179_178a: Add EEE configuration support for AX88179A MACs

Sashiko has reviewed this patch and found no issues.
Quoted 6 lines

The AX88179A uses a simple HW configuration for EEE
via a single EEE configuration register without LPI timer support Add support for setting this EEE enable/disable register in implementations of mac_enable_tx_lpi/mac_disable_tx_lpi.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
#15 lore raw

PATCH v21 6/13 ax88179_178a: Add EEE configuration support for AX88179A PHYs

In reply to Birger Koblitz

Configure phylink to work with the PHYs in the AX88179A controllers and provide ethtool get/set eee operations calling into phylink.

---
 drivers/net/usb/ax88179a_devices.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/net/usb/ax88179a_devices.c +20 -0
index 62619fd68c408f453e48c94020bce2254da9a1f9..272e92365683247b42a5fd25013c728a9c1af711 100644
@@ -225,6 +225,20 @@ static int ax88179a_get_eeprom_len(struct net_device *net)
 		return AX88179A_EEPROM_LEN;
 }
 
+static int ax88179a_get_eee(struct net_device *net, struct ethtool_keee *edata)
+{
+	struct ax88179_data *ax179_data = netdev2data(net);
+
+	return phylink_ethtool_get_eee(ax179_data->phylink, edata);
+}
+
+static int ax88179a_set_eee(struct net_device *net, struct ethtool_keee *edata)
+{
+	struct ax88179_data *ax179_data = netdev2data(net);
+
+	return phylink_ethtool_set_eee(ax179_data->phylink, edata);
+}
+
 static const struct ethtool_ops ax88179a_ethtool_ops = {
 	.get_link		= ethtool_op_get_link,
 	.get_msglevel		= usbnet_get_msglevel,
@@ -234,6 +248,8 @@ static const struct ethtool_ops ax88179a_ethtool_ops = {
 	.get_eeprom_len		= ax88179a_get_eeprom_len,
 	.get_eeprom		= ax88179_get_eeprom,
 	.set_eeprom		= ax88179_set_eeprom,
+	.get_eee		= ax88179a_get_eee,
+	.set_eee		= ax88179a_set_eee,
 	.nway_reset		= phy_ethtool_nway_reset,
 	.get_link_ksettings	= ax88179a_get_link_ksettings,
 	.set_link_ksettings	= ax88179a_set_link_ksettings,
@@ -451,6 +467,10 @@ static int ax88179a_phylink_setup(struct usbnet *dev)
 		phy_if_mode = PHY_INTERFACE_MODE_SGMII;
 	}
 
+	memcpy(data->phylink_config.lpi_interfaces,
+	       data->phylink_config.supported_interfaces,
+	       sizeof(data->phylink_config.lpi_interfaces));
+
 	phylink = phylink_create(&data->phylink_config, dev->net->dev.fwnode,
 				 phy_if_mode, &ax88179a_phylink_mac_ops);
 	if (IS_ERR(phylink))
Signature · 1 line
2.47.3
#16 lore raw

Re: [PATCH net-next v21 06/13] ax88179_178a: Add EEE configuration support for AX88179A PHYs

Sashiko has reviewed this patch and found no issues.
Quoted 4 lines

Configure phylink to work with the PHYs in the AX88179A controllers and provide ethtool get/set eee operations calling into phylink.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
#17 lore raw

Re: [PATCH net-next v21 06/13] ax88179_178a: Add EEE configuration support for AX88179A PHYs

In reply to Birger Koblitz
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

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

Critical: 0 · High: 0 · Medium: 1 · 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] This patch fills phylink_config.lpi_interfaces in ax88179a_phylink_setup() (drivers/net/usb/ax88179a_devices.c:470-472).
- [Low] Once this patch fills lpi_interfaces, pl->mac_supports_eee becomes true, and the new .get_eee/.set_eee ops…

--

ax88179_178a: Add EEE configuration support for AX88179A PHYs

This commit fills phylink_config.lpi_interfaces in ax88179a_phylink_setup(), so phylink now treats the MAC as EEE capable. It also adds ethtool get_eee/set_eee operations that call into phylink.

Quoted 11 lines
drivers/net/usb/ax88179a_devices.c +3 -0
index 62619fd68c408..272e923656832 100644
@@ -225,6 +225,20 @@ static int ax88179a_get_eeprom_len(struct net_device *net)
 		return AX88179A_EEPROM_LEN;
 }
 
+static int ax88179a_get_eee(struct net_device *net, struct ethtool_keee *edata)
+{
+	struct ax88179_data *ax179_data = netdev2data(net);

drivers/net/usb/ax88179a_devices.c static int ax88179a_get_eeprom_len(struct net_device *net) · line 240

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c +10 -0
+
+	return phylink_ethtool_get_eee(ax179_data->phylink, edata);
+}
+
+static int ax88179a_set_eee(struct net_device *net, struct ethtool_keee *edata)
+{
+	struct ax88179_data *ax179_data = netdev2data(net);
+
+	return phylink_ethtool_set_eee(ax179_data->phylink, edata);
+}

[Severity: Low]
Will ethtool now accept and report a tx_lpi_timer that the hardware never uses?

ax88179a_mac_enable_tx_lpi() ignores its timer argument:

static int ax88179a_mac_enable_tx_lpi(struct phylink_config *config, u32 timer, bool tx_clk_stop)

{
	...
	/* AX88179A does not provide LPI timer registers */
	return ax88179_write_cmd(dev, AX_GPHY_CTL, AX_GPHY_EEE_CTRL, true, 0, NULL);
}

phylink_ethtool_set_eee() does not check eee->tx_lpi_timer. On success it stores the value in pl->eee_cfg, and later get_eee calls report it back. So "ethtool --set-eee <dev> tx-timer N" succeeds and reads back N, but the hardware does not change.

ax88179a_phylink_setup() also never sets phylink_config.lpi_timer_default, so phylink_create() starts with:

	pl->eee_cfg.tx_lpi_timer = pl->config->lpi_timer_default;

As a result, ethtool shows a 0 us LPI timer by default. That probably does not match the fixed delay the hardware actually uses.

Before this patch, get/set_eee returned -EOPNOTSUPP, so none of this was reachable. Some other phylink drivers (r8169, ksz, rtl8365mb) also ignore the timer.

Could lpi_timer_default be set to the hardware's real fixed delay, or could values other than the default be rejected?

[ ... ]

drivers/net/usb/ax88179a_devices.c static int ax88179a_phylink_setup(struct usbnet *dev) · line 473

Quoted 8 lines
drivers/net/usb/ax88179a_devices.c +4 -0
@@ -451,6 +467,10 @@ static int ax88179a_phylink_setup(struct usbnet *dev)
 		phy_if_mode = PHY_INTERFACE_MODE_SGMII;
 	}
 
+	memcpy(data->phylink_config.lpi_interfaces,
+	       data->phylink_config.supported_interfaces,
+	       sizeof(data->phylink_config.lpi_interfaces));
+

[Severity: Medium]
Does this change the default EEE advertisement on chips other than the AX88772D?

With lpi_interfaces filled in, phylink_create() now sets pl->mac_supports_eee to true. ax88179a_phylink_setup() still sets eee_enabled_default = false, so pl->eee_cfg.eee_enabled is false. In phylink_bringup_phy() this means:

	if (pl->mac_supports_eee) {
		if (pl->eee_cfg.eee_enabled)
			phy_support_eee(phy);
		...
		linkmode_and(phy->advertising_eee, phy->advertising_eee,
			     pl->supported_lpi);
	} else if (pl->mac_supports_eee_ops) {
		/* MAC supports phylink EEE, but wants EEE always disabled. */
		phy_disable_eee(phy);
	}

Before this patch, the else-if branch ran and phy_disable_eee() cleared advertising_eee. Now only the linkmode_and() runs. Whatever phy_probe() read from the PHY's power-on EEE advertisement stays in place, and phy_probe() has already set:

	phydev->eee_cfg.eee_enabled = !linkmode_empty(phydev->advertising_eee);

If the internal PHY advertises EEE at reset, the link would negotiate EEE with the partner by default, and ethtool --show-eee would report EEE as enabled. Meanwhile, phylink's eee_cfg says disabled and MAC TX LPI stays off.

This seems to go against the comment in ax88179a_reset():

	/* Ensure EEE state is off, consistent with phylink setup */
	ax88179_write_cmd(dev, AX_GPHY_CTL, AX_GPHY_EEE_CTRL, false, 0, NULL);

After this patch, that comment holds for the MAC LPI control but not for the PHY advertisement. The older ax88179_178a driver for the same devices cleared the advertisement explicitly in ax88179_reset(), using ax88179_disable_eee() and linkmode_zero(eee_data.advertised).

If EEE is meant to be off by default, should the PHY's EEE advertisement be cleared explicitly? That way the default would not depend on the PHY's reset or strap values.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261114-ax88179a-v21-0-c2d34410bcbe%40birger-koblitz.de
#18 lore raw

PATCH v21 7/13 ax88179_178a: Add VLAN offload support for AX88179A

In reply to Birger Koblitz

The AX88179A-based chips support VLAN offload. Add configuration support in netdev_ops. Features supported are:
NETIF_F_HW_VLAN_CTAG_TX, NETIF_F_HW_VLAN_CTAG_RX
and NETIF_F_HW_VLAN_CTAG_FILTER.

Error-checking fixes Suggested-by: Jianhui Xu <[email protected]>

---
 drivers/net/usb/ax88179a_devices.c | 158 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 157 insertions(+), 1 deletion(-)
drivers/net/usb/ax88179a_devices.c +157 -1
index 272e92365683247b42a5fd25013c728a9c1af711..4207d2cc2b865e5780b3c7f5ba2645a6242df477 100644
@@ -258,6 +258,88 @@ static const struct ethtool_ops ax88179a_ethtool_ops = {
 	.get_ts_info		= ethtool_op_get_ts_info,
 };
 
+static int ax88179a_vlan_rx_kill_vid(struct net_device *net, __be16 proto, u16 vid)
+{
+	struct usbnet *dev = netdev_priv(net);
+	u16 reg16 = 0;
+	u8 vlan_ctrl;
+	int ret = 0;
+	u8 reg8 = 0;
+
+	ret = ax88179_read_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_CONTROL, 1, 1, &reg8);
+	if (ret < 0)
+		return ret;
+	vlan_ctrl = reg8;
+
+	/* Address */
+	reg8 = (vid / 16);
+	ret = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_ADDRESS, 1, 1, &reg8);
+	if (ret < 0)
+		return ret;
+
+	/* Data */
+	reg8 = vlan_ctrl | AX_VLAN_CONTROL_RD;
+	ret = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_CONTROL, 1, 1, &reg8);
+	if (ret < 0)
+		return ret;
+
+	ret = ax88179_read_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_DATA0, 2, 2, &reg16);
+	if (ret < 0)
+		return ret;
+	reg16 &= ~(1 << (vid % 16));
+	ret = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_DATA0, 2, 2, &reg16);
+	if (ret < 0)
+		return ret;
+
+	reg8 = vlan_ctrl | AX_VLAN_CONTROL_WE;
+	ret = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_CONTROL, 1, 1, &reg8);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+static int ax88179a_vlan_rx_add_vid(struct net_device *net, __be16 proto, u16 vid)
+{
+	struct usbnet *dev = netdev_priv(net);
+	u8 vlan_ctrl;
+	int ret = 0;
+	u16 reg16;
+	u8 reg8;
+
+	ret = ax88179_read_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_CONTROL, 1, 1, &reg8);
+	if (ret < 0)
+		return ret;
+	vlan_ctrl = reg8;
+
+	/* Address */
+	reg8 = (vid / 16);
+	ret = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_ADDRESS, 1, 1, &reg8);
+	if (ret < 0)
+		return ret;
+
+	/* Data */
+	reg8 = vlan_ctrl | AX_VLAN_CONTROL_RD;
+	ret = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_CONTROL, 1, 1, &reg8);
+	if (ret < 0)
+		return ret;
+
+	ret = ax88179_read_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_DATA0, 2, 2, &reg16);
+	if (ret < 0)
+		return ret;
+	reg16 |= (1 << (vid % 16));
+	ret = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_DATA0, 2, 2, &reg16);
+	if (ret < 0)
+		return ret;
+
+	reg8 = vlan_ctrl | AX_VLAN_CONTROL_WE;
+	ret = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_CONTROL, 1, 1, &reg8);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
 static void ax88179a_mdio_unregister(struct ax88179_data *data)
 {
 	mdiobus_unregister(data->mdio);
@@ -517,6 +599,75 @@ static int ax88179a_mii_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
 	return phylink_mii_ioctl(data->phylink, rq, cmd);
 }
 
+static int ax88179a_set_features(struct net_device *net, netdev_features_t features)
+{
+	struct usbnet *dev = netdev_priv(net);
+	netdev_features_t changed;
+	int ret;
+	u8 tmp;
+
+	changed = net->features ^ features;
+
+	ret = ax88179_set_features(net, features);
+	if (ret)
+		return ret;
+
+	if (changed & NETIF_F_HW_VLAN_CTAG_FILTER) {
+		if (features & NETIF_F_HW_VLAN_CTAG_FILTER) {
+			u8 vlan_state = 0;
+
+			ret = ax88179_read_cmd(dev, AX_ACCESS_MAC,
+					       AX88179A_VLAN_ID_CONTROL, 1, 1, &vlan_state);
+			if (ret < 0)
+				return ret;
+
+			for (int i = 0; i < 256; i++) {
+				/* Address */
+				tmp = i;
+				ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_ADDRESS,
+						  1, 1, &tmp);
+				/* Data */
+				ax88179_write_u16(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_DATA0,
+						  2, 0);
+				/* Write-Execute */
+				ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_CONTROL,
+						 1, vlan_state | AX_VLAN_CONTROL_WE);
+			}
+			vlan_state |= AX_VLAN_CONTROL_VFE;
+			ret = ax88179_write_cmd(dev, AX_ACCESS_MAC,
+						AX88179A_VLAN_ID_CONTROL, 1, 1, &vlan_state);
+			if (ret < 0)
+				return ret;
+		} else {
+			ret = ax88179_read_cmd(dev, AX_ACCESS_MAC,
+					       AX88179A_VLAN_ID_CONTROL, 1, 1, &tmp);
+			if (ret < 0)
+				return ret;
+			tmp &= ~AX_VLAN_CONTROL_VFE;
+			ret = ax88179_write_cmd(dev, AX_ACCESS_MAC,
+						AX88179A_VLAN_ID_CONTROL, 1, 1, &tmp);
+			if (ret < 0)
+				return ret;
+		}
+	}
+
+	if (changed & NETIF_F_HW_VLAN_CTAG_RX) {
+		ret = ax88179_read_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_CONTROL,
+				       1, 1, &tmp);
+		if (ret < 0)
+			return ret;
+		if (features & NETIF_F_HW_VLAN_CTAG_RX)
+			tmp |= AX_VLAN_CONTROL_VSO;
+		else
+			tmp &= ~AX_VLAN_CONTROL_VSO;
+		ret = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_CONTROL,
+					1, 1, &tmp);
+		if (ret < 0)
+			return ret;
+	}
+	return 0;
+}
+
 static const struct net_device_ops ax88179a_netdev_ops = {
 	.ndo_open		= usbnet_open,
 	.ndo_stop		= usbnet_stop,
@@ -527,6 +678,9 @@ static const struct net_device_ops ax88179a_netdev_ops = {
 	.ndo_set_mac_address	= ax88179_set_mac_addr,
 	.ndo_validate_addr	= eth_validate_addr,
 	.ndo_eth_ioctl		= ax88179a_mii_ioctl,
+	.ndo_set_features	= ax88179a_set_features,
+	.ndo_vlan_rx_add_vid	= ax88179a_vlan_rx_add_vid,
+	.ndo_vlan_rx_kill_vid	= ax88179a_vlan_rx_kill_vid,
 };
 
 static int ax88179a_bind(struct usbnet *dev, struct usb_interface *intf)
@@ -612,9 +766,11 @@ static int ax88179a_bind(struct usbnet *dev, struct usb_interface *intf)
 		dev->mii.supports_gmii = 1;
 
 	dev->net->features |= NETIF_F_SG | NETIF_F_IP_CSUM |
-			      NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM | NETIF_F_TSO;
+			      NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM | NETIF_F_TSO |
+			      NETIF_F_HW_VLAN_CTAG_TX;
 
 	dev->net->hw_features |= dev->net->features;
+	dev->net->hw_features |= NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_FILTER;
 
 	dev->net->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM |
 				  NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM | NETIF_F_TSO;
Signature · 1 line
2.47.3
#19 lore raw

Re: [PATCH net-next v21 07/13] ax88179_178a: Add VLAN offload support for AX88179A

Thank you for your contribution! Sashiko AI review found 5 potential issues to consider: - [Medium] net: usb: ax88179: uninitialized stack read and short USB read in VLAN ops - [Medium] net: usb…

Thank you for your contribution! Sashiko AI review found 5 potential issues to consider:
- [Medium] net: usb: ax88179: uninitialized stack read and short USB read in VLAN ops
- [Medium] net: usb: ax88179: unchecked USB writes in ax88179a_set_features() loop
- [Medium] net: usb: ax88179_178a: TX VLAN tag drop race in ax88179a_tx_fixup()
- [Low] net: usb: ax88179_178a: partial feature state in ax88179a_set_features()
- [Low] net: usb: ax88179_178a: duplicated VLAN filter update logic in add/kill vid
--

commit a2245f1909a4b4c924abeed75400e9c875dcb39c
Author: Birger Koblitz <[email protected]>

ax88179_178a: Add VLAN offload support for AX88179A

This commit adds hardware VLAN offload and filtering callbacks (NETIF_F_HW_VLAN_CTAG_TX, NETIF_F_HW_VLAN_CTAG_RX, and NETIF_F_HW_VLAN_CTAG_FILTER) for AX88179A-based USB network devices.

Quoted 79 lines
drivers/net/usb/ax88179a_devices.c +71 -0
index 272e923656832..4207d2cc2b865 100644
@@ -258,6 +258,88 @@ static const struct ethtool_ops ax88179a_ethtool_ops = {
 	.get_ts_info		= ethtool_op_get_ts_info,
 };
 
+static int ax88179a_vlan_rx_kill_vid(struct net_device *net, __be16 proto, u16 vid)
+{
+	struct usbnet *dev = netdev_priv(net);
+	u16 reg16 = 0;
+	u8 vlan_ctrl;
+	int ret = 0;
+	u8 reg8 = 0;
+
+	ret = ax88179_read_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_CONTROL, 1, 1, &reg8);
+	if (ret < 0)
+		return ret;
+	vlan_ctrl = reg8;
+
+	/* Address */
+	reg8 = (vid / 16);
+	ret = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_ADDRESS, 1, 1, &reg8);
+	if (ret < 0)
+		return ret;
+
+	/* Data */
+	reg8 = vlan_ctrl | AX_VLAN_CONTROL_RD;
+	ret = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_CONTROL, 1, 1, &reg8);
+	if (ret < 0)
+		return ret;
+
+	ret = ax88179_read_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_DATA0, 2, 2, &reg16);
+	if (ret < 0)
+		return ret;
+	reg16 &= ~(1 << (vid % 16));
+	ret = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_DATA0, 2, 2, &reg16);
+	if (ret < 0)
+		return ret;
+
+	reg8 = vlan_ctrl | AX_VLAN_CONTROL_WE;
+	ret = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_CONTROL, 1, 1, &reg8);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+static int ax88179a_vlan_rx_add_vid(struct net_device *net, __be16 proto, u16 vid)
+{
+	struct usbnet *dev = netdev_priv(net);
+	u8 vlan_ctrl;
+	int ret = 0;
+	u16 reg16;
+	u8 reg8;
+
+	ret = ax88179_read_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_CONTROL, 1, 1, &reg8);
+	if (ret < 0)
+		return ret;
+	vlan_ctrl = reg8;
+
+	/* Address */
+	reg8 = (vid / 16);
+	ret = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_ADDRESS, 1, 1, &reg8);
+	if (ret < 0)
+		return ret;
+
+	/* Data */
+	reg8 = vlan_ctrl | AX_VLAN_CONTROL_RD;
+	ret = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_CONTROL, 1, 1, &reg8);
+	if (ret < 0)
+		return ret;
+
+	ret = ax88179_read_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_DATA0, 2, 2, &reg16);
+	if (ret < 0)
+		return ret;
+	reg16 |= (1 << (vid % 16));
+	ret = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_DATA0, 2, 2, &reg16);

drivers/net/usb/ax88179a_devices.c static const struct ethtool_ops ax88179a_ethtool_ops = { · line 341

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c +10 -0
+	if (ret < 0)
+		return ret;
+
+	reg8 = vlan_ctrl | AX_VLAN_CONTROL_WE;
+	ret = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_CONTROL, 1, 1, &reg8);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}

[Severity: Medium]
Can a 0-byte USB read in ax88179a_vlan_rx_add_vid() or ax88179a_set_features() write uninitialized stack memory into AX88179A_VLAN_ID_CONTROL?

For 1-byte reads, ax88179_read_cmd() passes the caller's pointer directly to __usbnet_read_cmd(), which only copies into the buffer when usb_control_msg() returns > 0. If a control read returns 0, reg8 in ax88179a_vlan_rx_add_vid() and tmp in ax88179a_set_features() remain uninitialized because the callers only check ret < 0, and that stack byte is then modified and written back to AX88179A_VLAN_ID_CONTROL.

Similarly, the 2-byte reads of AX88179A_VLAN_ID_DATA0 only check ret < 0 instead of ret < 2, so a short read leaves reg16 zeroed or partially populated and causes the subsequent write to clear the other 15 VIDs in the same (vid / 16) filter entry.

[Severity: Low]
This isn't a bug, but ax88179a_vlan_rx_kill_vid() and ax88179a_vlan_rx_add_vid() duplicate the same five-step register sequence and only differ in whether they clear or set BIT(vid % 16) in reg16. Could they share a common helper taking a boolean flag?

[ ... ]

Quoted 28 lines
drivers/net/usb/ax88179a_devices.c +24 -0
@@ -517,6 +599,75 @@ static int ax88179a_mii_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
 	return phylink_mii_ioctl(data->phylink, rq, cmd);
 }
 
+static int ax88179a_set_features(struct net_device *net, netdev_features_t features)
+{
+	struct usbnet *dev = netdev_priv(net);
+	netdev_features_t changed;
+	int ret;
+	u8 tmp;
+
+	changed = net->features ^ features;
+
+	ret = ax88179_set_features(net, features);
+	if (ret)
+		return ret;
+
+	if (changed & NETIF_F_HW_VLAN_CTAG_FILTER) {
+		if (features & NETIF_F_HW_VLAN_CTAG_FILTER) {
+			u8 vlan_state = 0;
+
+			ret = ax88179_read_cmd(dev, AX_ACCESS_MAC,
+					       AX88179A_VLAN_ID_CONTROL, 1, 1, &vlan_state);
+			if (ret < 0)
+				return ret;
+
+			for (int i = 0; i < 256; i++) {
+				/* Address */

drivers/net/usb/ax88179a_devices.c static int ax88179a_mii_ioctl(struct net_device *net, struct ifreq *rq, int cmd) · line 635

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c +10 -0
+				tmp = i;
+				ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_ADDRESS,
+						  1, 1, &tmp);
+				/* Data */
+				ax88179_write_u16(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_DATA0,
+						  2, 0);
+				/* Write-Execute */
+				ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_CONTROL,
+						 1, vlan_state | AX_VLAN_CONTROL_WE);
+			}

[Severity: Medium]
Should the USB writes inside this loop check for errors?

If any write fails transiently while the final write enabling AX_VLAN_CONTROL_VFE succeeds, hardware VLAN filtering is enabled over an incompletely cleared filter table with stale VID entries. On a persistent USB error, the loop also runs all 768 synchronous control transfers under rtnl_lock instead of bailing out on the first failure.

Quoted 24 lines
drivers/net/usb/ax88179a_devices.c +24 -0
+			vlan_state |= AX_VLAN_CONTROL_VFE;
+			ret = ax88179_write_cmd(dev, AX_ACCESS_MAC,
+						AX88179A_VLAN_ID_CONTROL, 1, 1, &vlan_state);
+			if (ret < 0)
+				return ret;
+		} else {
+			ret = ax88179_read_cmd(dev, AX_ACCESS_MAC,
+					       AX88179A_VLAN_ID_CONTROL, 1, 1, &tmp);
+			if (ret < 0)
+				return ret;
+			tmp &= ~AX_VLAN_CONTROL_VFE;
+			ret = ax88179_write_cmd(dev, AX_ACCESS_MAC,
+						AX88179A_VLAN_ID_CONTROL, 1, 1, &tmp);
+			if (ret < 0)
+				return ret;
+		}
+	}
+
+	if (changed & NETIF_F_HW_VLAN_CTAG_RX) {
+		ret = ax88179_read_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_CONTROL,
+				       1, 1, &tmp);
+		if (ret < 0)
+			return ret;
+		if (features & NETIF_F_HW_VLAN_CTAG_RX)

drivers/net/usb/ax88179a_devices.c static int ax88179a_mii_ioctl(struct net_device *net, struct ifreq *rq, int cmd) · line 669

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c +10 -0
+			tmp |= AX_VLAN_CONTROL_VSO;
+		else
+			tmp &= ~AX_VLAN_CONTROL_VSO;
+		ret = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_CONTROL,
+					1, 1, &tmp);
+		if (ret < 0)
+			return ret;
+	}
+	return 0;
+}

[Severity: Low]
Can a late failure in ax88179a_set_features() leave hardware offload state out of sync with net->features?

When multiple features are changed at once and a later register access fails, __netdev_update_features() aborts without updating net->features or repopulating the VLAN filter table, while earlier changes stay active in hardware. For example, if enabling NETIF_F_HW_VLAN_CTAG_FILTER succeeds and the NETIF_F_HW_VLAN_CTAG_RX step fails, AX_VLAN_CONTROL_VFE remains enabled with an all-zero filter table, and any checksum bits already toggled via XOR in ax88179_set_features() remain inverted relative to net->features.

[ ... ]

drivers/net/usb/ax88179a_devices.c static int ax88179a_bind(struct usbnet *dev, struct usb_interface *intf) · line 773

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c +3 -1
@@ -612,9 +766,11 @@ static int ax88179a_bind(struct usbnet *dev, struct usb_interface *intf)
 		dev->mii.supports_gmii = 1;
 
 	dev->net->features |= NETIF_F_SG | NETIF_F_IP_CSUM |
-			      NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM | NETIF_F_TSO;
+			      NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM | NETIF_F_TSO |
+			      NETIF_F_HW_VLAN_CTAG_TX;
 
 	dev->net->hw_features |= dev->net->features;
+	dev->net->hw_features |= NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_FILTER;

[Severity: Medium]
Can toggling NETIF_F_HW_VLAN_CTAG_TX at runtime cause ax88179a_tx_fixup() to transmit VLAN-tagged packets without their VLAN tag?

drivers/net/usb/ax88179a_devices.c:ax88179a_tx_fixup() {
    ...
	if ((dev->net->features & NETIF_F_HW_VLAN_CTAG_TX) && (vlan_get_tag(skb, &tci) >= 0)) {
		tx_desc |= AX179A_TX_DESC_VLAN;
		tx_desc |= FIELD_PREP(AX179A_TX_DESC_VLAN_ID, (u64)tci);
	}
    ...
}

CPU0 CPU1
dev_hard_start_xmit()
validate_xmit_skb()

    validate_xmit_vlan()
      /* tag left in skb->vlan_tci */
                                  __netdev_update_features()
                                    /* clears NETIF_F_HW_VLAN_CTAG_TX */
  ndo_start_xmit()
    ax88179a_tx_fixup()
      /* skips AX179A_TX_DESC_VLAN */  <-- sent untagged

Now that NETIF_F_HW_VLAN_CTAG_TX is exposed in features and hw_features, disabling it while packets validated under NETIF_F_HW_VLAN_CTAG_TX are in flight causes both the feature check in ax88179a_tx_fixup() and vlan_get_tag() to ignore skb->vlan_tci. Checking skb_vlan_tag_present(skb) and reading the tag with skb_vlan_tag_get(skb) avoids dropping the tag.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
#20 lore raw

Re: [PATCH net-next v21 07/13] ax88179_178a: Add VLAN offload support for AX88179A

In reply to Birger Koblitz
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider.

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

Critical: 0 · High: 0 · Medium: 6 · 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] ax88179a_set_features() can fail halfway and leave hardware checksum state out of sync with dev->features.
- [Medium] When NETIF_F_HW_VLAN_CTAG_FILTER is turned on, ax88179a_set_features() clears the VLAN table with a 256-iteration…
- [Medium] The driver keeps no software copy of the VLAN filter table.
- [Medium] This patch makes NETIF_F_HW_VLAN_CTAG_RX a toggleable feature that is off by default (only in hw_features).
- [Medium] Uninitialized stack bytes are used and written back to the USB device.
- [Medium] Partial failure within the VLAN steps of ax88179a_set_features() leaves the filter state in hardware different…
- [Low] The commit message doesn't mention that the patch changes checksum offload behaviour.

--

ax88179_178a: Add VLAN offload support for AX88179A

This commit adds VLAN offload support for AX88179A-based chips. It adds an ndo_set_features handler for CTAG filtering and stripping, and ndo_vlan_rx_add_vid/kill_vid callbacks that program the hardware VID table. It also enables CTAG TX by default and adds CTAG RX and FILTER to hw_features.

Quoted 5 lines
drivers/net/usb/ax88179a_devices.c +0 -0
index 272e923656832..4207d2cc2b865 100644
@@ -258,6 +258,88 @@ static const struct ethtool_ops ax88179a_ethtool_ops = {

[ ... ]

drivers/net/usb/ax88179a_devices.c static const struct ethtool_ops ax88179a_ethtool_ops = { · line 313

Quoted 12 lines
drivers/net/usb/ax88179a_devices.c +12 -0
+static int ax88179a_vlan_rx_add_vid(struct net_device *net, __be16 proto, u16 vid)
+{
+	struct usbnet *dev = netdev_priv(net);
+	u8 vlan_ctrl;
+	int ret = 0;
+	u16 reg16;
+	u8 reg8;
+
+	ret = ax88179_read_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_CONTROL, 1, 1, &reg8);
+	if (ret < 0)
+		return ret;
+	vlan_ctrl = reg8;

[Severity: Medium]
Can reg8 be used uninitialized here? For size 1, ax88179_read_cmd() hands &reg8 straight to __usbnet_read_cmd(). That function only copies into the buffer when the reply has a positive length:

drivers/net/usb/usbnet.c:__usbnet_read_cmd() {
    ...
	if (err > 0 && err <= size) {
		if (data)
			memcpy(data, buf, err);
    ...
}

If the device sends a 0-byte reply, ret is 0, so the ret < 0 check passes and vlan_ctrl holds stack garbage. That value is then OR'ed with AX_VLAN_CONTROL_RD and AX_VLAN_CONTROL_WE and written back to AX88179A_VLAN_ID_CONTROL. Uninitialized stack bytes go to the device, and KMSAN would report an uninit-value.

ax88179a_vlan_rx_kill_vid() initializes its reg8 to 0, but this function does not.

ax88179a_set_features() has the same pattern with u8 tmp. In both the VFE-disable branch and the NETIF_F_HW_VLAN_CTAG_RX branch, tmp is read with ax88179_read_cmd() and written back.

Earlier syzbot fixes in this driver family dealt with the same short-read pattern.

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c +10 -0
+
+	/* Address */
+	reg8 = (vid / 16);
+	ret = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_ADDRESS, 1, 1, &reg8);
+	if (ret < 0)
+		return ret;
+
+	/* Data */
+	reg8 = vlan_ctrl | AX_VLAN_CONTROL_RD;
+	ret = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_CONTROL, 1, 1, &reg8);

drivers/net/usb/ax88179a_devices.c static const struct ethtool_ops ax88179a_ethtool_ops = { · line 333

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c +10 -0
+	if (ret < 0)
+		return ret;
+
+	ret = ax88179_read_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_DATA0, 2, 2, &reg16);
+	if (ret < 0)
+		return ret;
+	reg16 |= (1 << (vid % 16));
+	ret = ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_DATA0, 2, 2, &reg16);
+	if (ret < 0)
+		return ret;

[Severity: Medium]
The VID table only exists in device memory. What restores it after the device loses power?

ax88179a_reset() sets the filter again from dev->features, but it does not rewrite the table:

drivers/net/usb/ax88179a_devices.c:ax88179a_reset() {
    ...
	*tmp = 0;
	if (dev->net->features & NETIF_F_HW_VLAN_CTAG_FILTER)
		*tmp |= AX_VLAN_CONTROL_VFE;
	if (dev->net->features & NETIF_F_HW_VLAN_CTAG_RX)
		*tmp |= AX_VLAN_CONTROL_VSO;
	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_CONTROL, 1, 1, tmp);
    ...
}

The later commit "ax88179_178a: Add Suspend/resume support for AX88179A/772D/279" routes .reset_resume through ax88179_resume_wrapper()->ax88179a_resume()->ax88179a_reset(). After hibernate, or after the host controller loses power, VFE would be set on a table that holds power-on defaults.

The VLAN core does not replay VIDs on resume. On NETDEV_UP it only adds VID 0 again. VIDs held by existing VLAN sub-interfaces keep their refcounts, so ndo_vlan_rx_add_vid is not called again for them.

Would the hardware then drop tagged traffic for those VLANs until rx-vlan-filter is toggled? Other USB MACs, such as lan78xx, keep a shadow copy of the table and rewrite it on reset.

[ ... ]

Quoted 6 lines
drivers/net/usb/ax88179a_devices.c +2 -0
@@ -517,6 +599,75 @@ static int ax88179a_mii_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
 	return phylink_mii_ioctl(data->phylink, rq, cmd);
 }
 
+static int ax88179a_set_features(struct net_device *net, netdev_features_t features)
+{

drivers/net/usb/ax88179a_devices.c static int ax88179a_mii_ioctl(struct net_device *net, struct ifreq *rq, int cmd) · line 613

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c +10 -0
+	struct usbnet *dev = netdev_priv(net);
+	netdev_features_t changed;
+	int ret;
+	u8 tmp;
+
+	changed = net->features ^ features;
+
+	ret = ax88179_set_features(net, features);
+	if (ret)
+		return ret;

[Severity: Medium]
What happens to the checksum state if one of the later VLAN register accesses fails?

By the time the VLAN steps run, ax88179_set_features() has already XOR-toggled AX_TXCOE_CTL and AX_RXCOE_CTL based on net->features ^ features, and it has set data->rx_checksum. If a VLAN_ID_CONTROL read or write below fails, this function returns an error and does not undo any of that. __netdev_update_features() then leaves dev->features as it was:

net/core/dev.c:__netdev_update_features() {
    ...
	if (unlikely(err < 0)) {
		netdev_err(dev,
			"set_features() failed (%d); wanted %pNF, left %pNF\n",
			err, &features, &dev->features);
		...
		return -1;
	}
    ...
}

Take ethtool -K ethX tx-checksum-ipv4 off rx-vlan-filter on, with a USB error during the VLAN step. TX checksum offload ends up off in hardware while dev->features still has NETIF_F_IP_CSUM. The stack keeps sending CHECKSUM_PARTIAL skbs, and they go out with bad TCP/UDP checksums.

ax88179_set_features() toggles relative to dev->features, which was never updated. Each later successful update would flip the bits again using a wrong changed mask. Would hardware and software stay inverted until the next open, when ax88179a_reset() runs?

The RX side can end up inverted the same way: data->rx_checksum is set while the RX checksum engine is off. ax88179a_rx_checksum() would then trust descriptor error bits the engine never computed.

Could the checksum update run after the VLAN steps, or be rolled back on failure?

Quoted 12 lines
drivers/net/usb/ax88179a_devices.c +12 -0
+
+	if (changed & NETIF_F_HW_VLAN_CTAG_FILTER) {
+		if (features & NETIF_F_HW_VLAN_CTAG_FILTER) {
+			u8 vlan_state = 0;
+
+			ret = ax88179_read_cmd(dev, AX_ACCESS_MAC,
+					       AX88179A_VLAN_ID_CONTROL, 1, 1, &vlan_state);
+			if (ret < 0)
+				return ret;
+
+			for (int i = 0; i < 256; i++) {
+				/* Address */

drivers/net/usb/ax88179a_devices.c static int ax88179a_mii_ioctl(struct net_device *net, struct ifreq *rq, int cmd) · line 635

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c +10 -0
+				tmp = i;
+				ax88179_write_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_ADDRESS,
+						  1, 1, &tmp);
+				/* Data */
+				ax88179_write_u16(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_DATA0,
+						  2, 0);
+				/* Write-Execute */
+				ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_CONTROL,
+						 1, vlan_state | AX_VLAN_CONTROL_WE);
+			}

[Severity: Medium]
This loop ignores the return values of all 768 control writes, and AX_VLAN_CONTROL_VFE is then set unconditionally. Is that intentional, given that every other register access in this patch is checked?

ndo_set_features runs under the rtnl lock. Each write goes through usb_control_msg() with USB_CTRL_SET_TIMEOUT (5 seconds), and the loop never stops early. A device that stays attached but stops responding could hold rtnl for up to 768 * 5 seconds, which is roughly an hour.

If only some of the writes fail, those table words keep stale bits, or WE commits zero to the wrong latched address. The filter is still enabled and the call still reports success.

Related to this, the commit message has this trailer:

Error-checking fixes Suggested-by: Jianhui Xu <[email protected]>

There is free text before the tag, so tools won't parse it as a
Suggested-by: trailer. It also credits error-checking work that this loop does not have.

Quoted 5 lines
drivers/net/usb/ax88179a_devices.c +5 -0
+			vlan_state |= AX_VLAN_CONTROL_VFE;
+			ret = ax88179_write_cmd(dev, AX_ACCESS_MAC,
+						AX88179A_VLAN_ID_CONTROL, 1, 1, &vlan_state);
+			if (ret < 0)
+				return ret;

[ ... ]

drivers/net/usb/ax88179a_devices.c static int ax88179a_mii_ioctl(struct net_device *net, struct ifreq *rq, int cmd) · line 658

Quoted 5 lines
drivers/net/usb/ax88179a_devices.c +5 -0
+	if (changed & NETIF_F_HW_VLAN_CTAG_RX) {
+		ret = ax88179_read_cmd(dev, AX_ACCESS_MAC, AX88179A_VLAN_ID_CONTROL,
+				       1, 1, &tmp);
+		if (ret < 0)
+			return ret;

[Severity: Medium]
Suppose a single update enables NETIF_F_HW_VLAN_CTAG_FILTER and also changes NETIF_F_HW_VLAN_CTAG_RX. By the time this read runs, the table has been cleared and VFE has been written. If this read, or the write after it, fails, could the hardware be left filtering on an empty table?

On error, __netdev_update_features() does not update dev->features. It also skips vlan_get_rx_ctag_filter_info(), so no VIDs are pushed. Because CTAG_FILTER is then missing from dev->features, vlan_hw_filter_capable() returns false, and later VLAN additions don't call ndo_vlan_rx_add_vid either.

The MAC would then drop tagged traffic for every configured VLAN sub-interface, while the stack believes filtering is off.

The reverse case also exists. If disabling the filter succeeds and the CTAG_RX step fails, VFE is off in hardware but the feature still shows as enabled.

[ ... ]

drivers/net/usb/ax88179a_devices.c static const struct net_device_ops ax88179a_netdev_ops = { · line 681

Quoted 5 lines
drivers/net/usb/ax88179a_devices.c +1 -0
@@ -527,6 +678,9 @@ static const struct net_device_ops ax88179a_netdev_ops = {
 	.ndo_set_mac_address	= ax88179_set_mac_addr,
 	.ndo_validate_addr	= eth_validate_addr,
 	.ndo_eth_ioctl		= ax88179a_mii_ioctl,
+	.ndo_set_features	= ax88179a_set_features,

[Severity: Low]
This isn't a bug, but adding .ndo_set_features here also changes checksum offload behaviour, and the commit message doesn't mention it.

Before this patch, ax88179a_netdev_ops had no .ndo_set_features, even though NETIF_F_IP_CSUM, NETIF_F_IPV6_CSUM and NETIF_F_RXCSUM were already in hw_features. ethtool -K could change them in net->features, but AX_TXCOE_CTL and AX_RXCOE_CTL were never reprogrammed. data->rx_checksum also kept the value ax88179a_reset() set at open. So ethtool -K ethX rx off did not stop ax88179a_rx_fixup() from marking packets CHECKSUM_UNNECESSARY.

ax88179a_set_features() calls ax88179_set_features() first, so this patch also fixes runtime checksum toggling for all AX179A-family chips. Could that fix go into the earlier commit "ax88179_178a: Add HW support for AX179A-based chips", or at least be described in this commit message, so it can be found during bisection and backports?

Quoted 3 lines
drivers/net/usb/ax88179a_devices.c +2 -0
+	.ndo_vlan_rx_add_vid	= ax88179a_vlan_rx_add_vid,
+	.ndo_vlan_rx_kill_vid	= ax88179a_vlan_rx_kill_vid,
 };

[ ... ]

drivers/net/usb/ax88179a_devices.c static int ax88179a_bind(struct usbnet *dev, struct usb_interface *intf) · line 773

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c +3 -1
@@ -612,9 +766,11 @@ static int ax88179a_bind(struct usbnet *dev, struct usb_interface *intf)
 		dev->mii.supports_gmii = 1;
 
 	dev->net->features |= NETIF_F_SG | NETIF_F_IP_CSUM |
-			      NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM | NETIF_F_TSO;
+			      NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM | NETIF_F_TSO |
+			      NETIF_F_HW_VLAN_CTAG_TX;
 
 	dev->net->hw_features |= dev->net->features;
+	dev->net->hw_features |= NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_FILTER;

[Severity: Medium]
NETIF_F_HW_VLAN_CTAG_RX is now user-toggleable and off by default, and toggling it only changes AX_VLAN_CONTROL_VSO. Should the RX path follow this setting too?

ax88179a_rx_fixup() still pushes a hwaccel tag based only on the descriptor bit:

drivers/net/usb/ax88179a_devices.c:ax88179a_rx_fixup() {
    ...
		if (pkt_desc & AX179A_RX_PD_VLAN) {
			vlan_tag = pkt_desc >> AX179A_RX_PD_VLAN_SHIFT;
			__vlan_hwaccel_put_tag(ax_skb, htons(ETH_P_8021Q), vlan_tag);
		}
    ...
}

Suppose the hardware still sets AX179A_RX_PD_VLAN for tagged frames when VSO is clear. Then with rxvlan off, which is the default, the stack would receive frames that still carry the 802.1Q header in the payload and also have a hwaccel tag.

I couldn't tell from the code whether PD_VLAN is suppressed when stripping is off. The aqc111 driver always sets VSO, so it doesn't answer the question either.

In the same function, checksum reporting is gated on data->rx_checksum, and drivers such as lan78xx gate the tag push on the feature bit. The tag push came in earlier in this series ("ax88179_178a: Add HW support for AX179A-based chips"), but this patch is the one that makes CTAG_RX toggleable. Would a check of dev->net->features & NETIF_F_HW_VLAN_CTAG_RX be needed here?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261114-ax88179a-v21-0-c2d34410bcbe%40birger-koblitz.de
#21 lore raw

PATCH v21 8/13 ax88179_178a: Add AX179A/AX279 multicast configuration

In reply to Birger Koblitz

Add support for conditionally setting the ip_alignement flag AX_RX_CTL_IPE in AX_RX_CTL and make sure that AX_RX_CTL_DROPCRCERR is also set to be consistent with the initial configuration in ax88179_reset()

---
 drivers/net/usb/ax88179_lib.c      | 16 +++++++++++-----
 drivers/net/usb/ax88179a_devices.c |  1 +
 2 files changed, 12 insertions(+), 5 deletions(-)
drivers/net/usb/ax88179_lib.c +11 -5
index fa6423f51849e2ea5b640dcb82af6282d41b189e..f27b073e1bccb72a49437cb082a80c8e73a5de46 100644
@@ -319,16 +319,21 @@ int ax88179_set_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom, u8
 void ax88179_set_multicast(struct net_device *net)
 {
 	struct usbnet *dev = netdev_priv(net);
-	struct ax88179_data *data = dev->driver_priv;
 	u8 *m_filter = ((u8 *)dev->data);
+	struct ax88179_data *data;
+	u16 rxctl = 0;
+
+	data = dev->driver_priv;
 
-	data->rxctl = (AX_RX_CTL_START | AX_RX_CTL_AB | AX_RX_CTL_IPE);
+	rxctl = (AX_RX_CTL_START | AX_RX_CTL_AB | AX_RX_CTL_DROPCRCERR);
+	if (data->ip_align)
+		rxctl |= AX_RX_CTL_IPE;
 
 	if (net->flags & IFF_PROMISC) {
-		data->rxctl |= AX_RX_CTL_PRO;
+		rxctl |= AX_RX_CTL_PRO;
 	} else if (net->flags & IFF_ALLMULTI ||
 		   netdev_mc_count(net) > AX_MAX_MCAST) {
-		data->rxctl |= AX_RX_CTL_AMALL;
+		rxctl |= AX_RX_CTL_AMALL;
 	} else if (netdev_mc_empty(net)) {
 		/* just broadcast and directed */
 	} else {
@@ -349,9 +354,10 @@ void ax88179_set_multicast(struct net_device *net)
 					AX_MCAST_FLTSIZE, AX_MCAST_FLTSIZE,
 					m_filter);
 
-		data->rxctl |= AX_RX_CTL_AM;
+		rxctl |= AX_RX_CTL_AM;
 	}
 
+	WRITE_ONCE(data->rxctl, rxctl);
 	ax88179_write_cmd_async(dev, AX_ACCESS_MAC, AX_RX_CTL,
 				2, 2, &data->rxctl);
 }
drivers/net/usb/ax88179a_devices.c +1 -0
index 4207d2cc2b865e5780b3c7f5ba2645a6242df477..a6b0a3f47118c46db38d483792c083510aa2641a 100644
@@ -678,6 +678,7 @@ static const struct net_device_ops ax88179a_netdev_ops = {
 	.ndo_set_mac_address	= ax88179_set_mac_addr,
 	.ndo_validate_addr	= eth_validate_addr,
 	.ndo_eth_ioctl		= ax88179a_mii_ioctl,
+	.ndo_set_rx_mode	= ax88179_set_multicast,
 	.ndo_set_features	= ax88179a_set_features,
 	.ndo_vlan_rx_add_vid	= ax88179a_vlan_rx_add_vid,
 	.ndo_vlan_rx_kill_vid	= ax88179a_vlan_rx_kill_vid,
Signature · 1 line
2.47.3
#22 lore raw

Re: [PATCH net-next v21 08/13] ax88179_178a: Add AX179A/AX279 multicast configuration

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] net: usb: ax88179: unsynchronized AX_RX_CTL updates in ax88179_set_multicast() --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] net: usb: ax88179: unsynchronized AX_RX_CTL updates in ax88179_set_multicast()
--

commit f349443476b08db9f2083703ec74ef889b46544c
Author: Birger Koblitz <[email protected]>

ax88179_178a: Add AX179A/AX279 multicast configuration

This commit updates ax88179_set_multicast() to set AX_RX_CTL_DROPCRCERR and conditionally set AX_RX_CTL_IPE based on data->ip_align, and wires it up as .ndo_set_rx_mode in ax88179a_netdev_ops.

Quoted 47 lines
drivers/net/usb/ax88179_lib.c +11 -5
index fa6423f51849e..f27b073e1bccb 100644
@@ -319,16 +319,21 @@ int ax88179_set_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom, u8
 void ax88179_set_multicast(struct net_device *net)
 {
 	struct usbnet *dev = netdev_priv(net);
-	struct ax88179_data *data = dev->driver_priv;
 	u8 *m_filter = ((u8 *)dev->data);
+	struct ax88179_data *data;
+	u16 rxctl = 0;
+
+	data = dev->driver_priv;
 
-	data->rxctl = (AX_RX_CTL_START | AX_RX_CTL_AB | AX_RX_CTL_IPE);
+	rxctl = (AX_RX_CTL_START | AX_RX_CTL_AB | AX_RX_CTL_DROPCRCERR);
+	if (data->ip_align)
+		rxctl |= AX_RX_CTL_IPE;
 
 	if (net->flags & IFF_PROMISC) {
-		data->rxctl |= AX_RX_CTL_PRO;
+		rxctl |= AX_RX_CTL_PRO;
 	} else if (net->flags & IFF_ALLMULTI ||
 		   netdev_mc_count(net) > AX_MAX_MCAST) {
-		data->rxctl |= AX_RX_CTL_AMALL;
+		rxctl |= AX_RX_CTL_AMALL;
 	} else if (netdev_mc_empty(net)) {
 		/* just broadcast and directed */
 	} else {
@@ -349,9 +354,10 @@ void ax88179_set_multicast(struct net_device *net)
 					AX_MCAST_FLTSIZE, AX_MCAST_FLTSIZE,
 					m_filter);
 
-		data->rxctl |= AX_RX_CTL_AM;
+		rxctl |= AX_RX_CTL_AM;
 	}
 
+	WRITE_ONCE(data->rxctl, rxctl);
 	ax88179_write_cmd_async(dev, AX_ACCESS_MAC, AX_RX_CTL,
 				2, 2, &data->rxctl);
 }
drivers/net/usb/ax88179a_devices.c +0 -0
index 4207d2cc2b865..a6b0a3f47118c 100644

drivers/net/usb/ax88179a_devices.c static const struct net_device_ops ax88179a_netdev_ops = { · line 684

Quoted 7 lines
drivers/net/usb/ax88179a_devices.c +1 -0
@@ -678,6 +678,7 @@ static const struct net_device_ops ax88179a_netdev_ops = {
 	.ndo_set_mac_address	= ax88179_set_mac_addr,
 	.ndo_validate_addr	= eth_validate_addr,
 	.ndo_eth_ioctl		= ax88179a_mii_ioctl,
+	.ndo_set_rx_mode	= ax88179_set_multicast,
 	.ndo_set_features	= ax88179a_set_features,
 	.ndo_vlan_rx_add_vid	= ax88179a_vlan_rx_add_vid,
 	.ndo_vlan_rx_kill_vid	= ax88179a_vlan_rx_kill_vid,

[Severity: Medium]
Can ax88179_set_multicast() race with ax88179a_mac_link_up() when writing AX_RX_CTL?

ax88179_set_multicast() runs in BH context under netif_addr_lock_bh(), while phylink runs ax88179a_mac_link_up() in process context without any shared lock:

drivers/net/usb/ax88179a_devices.c: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);
	...
	mutex_lock(&ax179_data->medium_status_mutex);
	if (dev->net->mtu > 1500)
		mode |= AX_MEDIUM_JUMBO_EN;
	ax88179_write_u16(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 2, mode);

	ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, READ_ONCE(ax179_data->rxctl));
	mutex_unlock(&ax179_data->medium_status_mutex);
}

WRITE_ONCE() and READ_ONCE() only protect the in-memory ax179_data->rxctl load and store, not the USB control transfers to AX_RX_CTL:

CPU0 (kworker) CPU1 (<softirq>)
ax88179a_mac_link_up()
val = READ_ONCE(ax179_data->rxctl)

                                      ax88179_set_multicast()
                                        WRITE_ONCE(data->rxctl, rxctl)
                                        ax88179_write_cmd_async(..., AX_RX_CTL, ...)
                                          usb_submit_urb()

ax88179_write_u16(..., AX_RX_CTL, val)
usb_control_msg() <-- overwrites AX_RX_CTL with stale val

This leaves the hardware AX_RX_CTL filter out of sync with data->rxctl when RX mode updates (such as IPv6 MLD joins during interface bring-up) overlap with link resolution. In addition, if ax88179_set_multicast() runs while ax88179a_mac_link_up() is between writing AX_RX_CTL_STOP and restoring AX_RX_CTL at the end of link setup, its asynchronous write sets AX_RX_CTL_START and re-enables RX in the middle of MAC and bulk-in queue reconfiguration.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
#23 lore raw

Re: [PATCH net-next v21 08/13] ax88179_178a: Add AX179A/AX279 multicast configuration

In reply to Birger Koblitz
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

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

Critical: 0 · High: 0 · Medium: 1 · 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] This patch hooks ax88179_set_multicast() up as .ndo_set_rx_mode for the AX88179A/AX88772D/AX88279 family…
- [Low] The patch is titled "Add AX179A/AX279 multicast configuration", but it changes ax88179_set_multicast() in…

--

ax88179_178a: Add AX179A/AX279 multicast configuration

This commit changes ax88179_set_multicast() to build the RX_CTL value in a local variable. The value now always includes AX_RX_CTL_DROPCRCERR, and AX_RX_CTL_IPE is added only when data->ip_align is set. The commit also hooks ax88179_set_multicast() up as .ndo_set_rx_mode for the AX88179A family netdev ops.

Quoted 7 lines
drivers/net/usb/ax88179_lib.c +0 -0
index fa6423f51849e..f27b073e1bccb 100644
@@ -319,16 +319,21 @@ int ax88179_set_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom, u8
 void ax88179_set_multicast(struct net_device *net)
 {

[ ... ]

drivers/net/usb/ax88179_lib.c int ax88179_set_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom, u8 · line 330

Quoted 4 lines
drivers/net/usb/ax88179_lib.c +3 -1
-	data->rxctl = (AX_RX_CTL_START | AX_RX_CTL_AB | AX_RX_CTL_IPE);
+	rxctl = (AX_RX_CTL_START | AX_RX_CTL_AB | AX_RX_CTL_DROPCRCERR);
+	if (data->ip_align)
+		rxctl |= AX_RX_CTL_IPE;

[Severity: Low]
ax88179_set_multicast() is shared code. The legacy AX88179/AX88178A driver in ax88179_178a.c also uses it as .ndo_set_rx_mode. ip_align is always 1 for those chips, so IPE does not change for them. The only change on legacy hardware is that DROPCRCERR now stays set after every open and every RX mode change.

Before this patch, the START|AB|IPE value cleared the DROPCRCERR bit that ax88179_reset() programs. With the bit kept set, the chip drops bad-CRC frames before they reach ax88179_rx_fixup(). They are then no longer counted here:

drivers/net/usb/ax88179_178a.c:ax88179_rx_fixup() {
    ...
		if ((*pkt_hdr & (AX_RXHDR_CRC_ERR | AX_RXHDR_DROP_ERR)) ||
		    pkt_len < 2 + ETH_HLEN) {
			dev->net->stats.rx_errors++;
    ...
}

The subject only names AX179A/AX279. Could the commit message say that the legacy chips are affected too, and that their rx_errors accounting changes?

The commit message also says:

"make sure that AX_RX_CTL_DROPCRCERR is also set to be consistent with the initial configuration in ax88179_reset()"

That is only partly true. ax88179_reset() and ax88179a_reset() both set AX_RX_CTL_AP, and this function still clears it.

The comment in ax88179a_bind() points to a different reason, a requirement of the AX88279:

/* 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.

Would it be clearer to split the legacy behaviour change into its own patch, or to describe it in the commit message? This also appears to be unchanged at the end of the series.

[ ... ]

drivers/net/usb/ax88179a_devices.c static const struct net_device_ops ax88179a_netdev_ops = { · line 681

Quoted 9 lines
drivers/net/usb/ax88179a_devices.c +1 -0
index 4207d2cc2b865..a6b0a3f47118c 100644
@@ -678,6 +678,7 @@ static const struct net_device_ops ax88179a_netdev_ops = {
 	.ndo_set_mac_address	= ax88179_set_mac_addr,
 	.ndo_validate_addr	= eth_validate_addr,
 	.ndo_eth_ioctl		= ax88179a_mii_ioctl,
+	.ndo_set_rx_mode	= ax88179_set_multicast,

[Severity: Medium]
This hook makes ax88179_set_multicast() a second writer of AX_RX_CTL on the AX88179A/AX88772D/AX88279 family. What serializes it with ax88179a_mac_link_up()?

ax88179_set_multicast() is called from __dev_set_rx_mode() with only netif_addr_lock_bh() held. It stores data->rxctl with WRITE_ONCE(), always with AX_RX_CTL_START set, and then submits an async control URB through ax88179_write_cmd_async().

ax88179a_mac_link_up() runs from the phylink_resolve() worker with phy->lock and pl->state_mutex held. It takes medium_status_mutex around its final write. It holds neither RTNL nor addr_list_lock, and ax88179_set_multicast() never takes medium_status_mutex:

drivers/net/usb/ax88179a_devices.c: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);
	ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_PATH, 1, 0);
    ...
	mutex_lock(&ax179_data->medium_status_mutex);
    ...
	ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, READ_ONCE(ax179_data->rxctl));
	mutex_unlock(&ax179_data->medium_status_mutex);
    ...
}

Could an update be lost in this sequence?

phylink_resolve() worker
ax88179a_mac_link_up()

    READ_ONCE(ax179_data->rxctl) returns the old value

                          dev_set_promiscuity()
                          ax88179_set_multicast()
                              WRITE_ONCE(data->rxctl, rxctl with PRO)
                              async AX_RX_CTL URB completes

    ax88179_write_u16(..., AX_RX_CTL, 2, <old value>)

The hardware would then be missing PRO/AM/AMALL even though data->rxctl says they are set. This would last until the next RX mode change or link flap. Enabling promisc, adding the device to a bridge or starting tcpdump while a link-up is being processed could all trigger it.

The ordering also looks open. Suppose an async START|AB|DROPCRCERR write is submitted after the AX_RX_CTL_STOP write but before the final restore. RX would be turned back on while the RX CDC and bulk-in settings for the new speed are only partly programmed. What the hardware does with START set while MAC_PATH is 0 isn't documented, so this part is less certain.

The WRITE_ONCE()/READ_ONCE() pair prevents torn reads. It does not make "read rxctl, then program the register" atomic with respect to the other writer.

Before this patch these devices had no ndo_set_rx_mode. AX_RX_CTL was only written from the reset, link_up, unbind and suspend paths. This also appears to be unchanged at the end of the series.

Quoted 3 lines
drivers/net/usb/ax88179a_devices.c +0 -0
 	.ndo_set_features	= ax88179a_set_features,
 	.ndo_vlan_rx_add_vid	= ax88179a_vlan_rx_add_vid,
 	.ndo_vlan_rx_kill_vid	= ax88179a_vlan_rx_kill_vid,
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261114-ax88179a-v21-0-c2d34410bcbe%40birger-koblitz.de
#24 lore raw

PATCH v21 9/13 ax88179_178a: Add Suspend/resume support for AX88179A/772D/279

In reply to Birger Koblitz

The suspend and resume functions are called via the usb_driver structure, for which the driver has only a single instance. Add wrapper functions for the different implementations for the AX88179 and AX179A architecutres in ax88179_lib which calls the 2 implementations in ax88179_178a and ax88179a_devices, respectively.

---
 drivers/net/usb/ax88179_178a.c     |   9 ++-
 drivers/net/usb/ax88179_lib.c      |  19 ++++++
 drivers/net/usb/ax88179_lib.h      |   4 ++
 drivers/net/usb/ax88179a_devices.c | 129 +++++++++++++++++++++++++++++++++++--
 4 files changed, 153 insertions(+), 8 deletions(-)
drivers/net/usb/ax88179_178a.c +6 -3
index f78ad344c1c4f1f057164728e4f21f875e6cdc1a..b077b7153f0c07676aafd5dfd13a2c0d9a826719 100644
@@ -685,6 +685,9 @@ static int ax88179_bind(struct usbnet *dev, struct usb_interface *intf)
 	dev->driver_priv = ax179_data;
 	mutex_init(&ax179_data->medium_status_mutex);
 
+	ax179_data->resume = ax88179_resume;
+	ax179_data->suspend = ax88179_suspend;
+
 	ret = ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_CHIP_STATUS,
 			       1, 1, &ax179_data->chip_version);
 	if (ret < 0)
@@ -1362,9 +1365,9 @@ static struct usb_driver ax88179_178a_driver = {
 	.name =		"ax88179_178a",
 	.id_table =	products,
 	.probe =	usbnet_probe,
-	.suspend =	ax88179_suspend,
-	.resume =	ax88179_resume,
-	.reset_resume =	ax88179_resume,
+	.suspend =	ax88179_suspend_wrapper,
+	.resume =	ax88179_resume_wrapper,
+	.reset_resume =	ax88179_resume_wrapper,
 	.disconnect =	ax88179_disconnect,
 	.supports_autosuspend = 1,
 	.disable_hub_initiated_lpm = 1,
drivers/net/usb/ax88179_lib.c +19 -0
index f27b073e1bccb72a49437cb082a80c8e73a5de46..1523a920f3c38bf5c88a43c8a33645987b569bcd 100644
@@ -493,3 +493,22 @@ int ax88179_set_mac_addr(struct net_device *net, void *p)
 	return 0;
 }
 
+int ax88179_suspend_wrapper(struct usb_interface *intf, pm_message_t message)
+{
+	struct usbnet *dev = usb_get_intfdata(intf);
+	struct ax88179_data *priv;
+
+	priv = dev->driver_priv;
+
+	return priv->suspend(intf, message);
+}
+
+int ax88179_resume_wrapper(struct usb_interface *intf)
+{
+	struct usbnet *dev = usb_get_intfdata(intf);
+	struct ax88179_data *priv;
+
+	priv = dev->driver_priv;
+	return priv->resume(intf);
+}
+
drivers/net/usb/ax88179_lib.h +4 -0
index adc2b4598bb52d80c18a6e2cc467144d3bd57a88..401c0bed3d28b4b94f0a0cad7509cd7087ef0639 100644
@@ -315,6 +315,8 @@ struct ax88179_data {
 	struct phy_device *phydev;
 	struct phylink *phylink;
 	struct phylink_config phylink_config;
+	int (*resume)(struct usb_interface *intf);
+	int (*suspend)(struct usb_interface *intf, pm_message_t message);
 };
 
 struct ax88179_int_data {
@@ -348,6 +350,8 @@ int ax88179_set_features(struct net_device *net, netdev_features_t features);
 void ax88179_get_mac_addr(struct usbnet *dev);
 int ax88179_change_mtu(struct net_device *net, int new_mtu);
 int ax88179_set_mac_addr(struct net_device *net, void *p);
+int ax88179_suspend_wrapper(struct usb_interface *intf, pm_message_t message);
+int ax88179_resume_wrapper(struct usb_interface *intf);
 
 extern const struct driver_info ax88179a_info;
 extern const struct driver_info ax88772d_info;
drivers/net/usb/ax88179a_devices.c +124 -5

177 lines not on this page · raw message

Signature · 1 line
2.47.3
#25 lore raw

Re: [PATCH net-next v21 09/13] ax88179_178a: Add Suspend/resume support for AX88179A/772D/279

Thank you for your contribution! Sashiko AI review found 5 potential issues to consider: - [High] net: usb: ax88179_178a: PHY power-cycle in ax88179a_resume() breaks WoL resume - [High] net: usb…

Thank you for your contribution! Sashiko AI review found 5 potential issues to consider:
- [High] net: usb: ax88179_178a: PHY power-cycle in ax88179a_resume() breaks WoL resume
- [High] net: usb: ax88179_178a: missing MAC address restore in ax88179a_reset()
- [Medium] net: usb: ax88179_178a: ax88179a_resume() enables PHY and MAC when netdev down
- [Medium] net: usb: ax88179_178a: dropped error code in ax88179a_resume()
- [Medium] net: usb: ax88179_178a: unaligned u16 access in ax88179a_reset()
--

commit 5db223d1e5c5523038980ec1d7429f2d0d6d6dd9
Author: Birger Koblitz <[email protected]>

ax88179_178a: Add Suspend/resume support for AX88179A/772D/279

This commit adds suspend and resume callbacks for AX88179A, AX88772D, and AX88279 devices and dispatches USB driver suspend and resume calls through per-device function pointers.

Quoted 4 lines
drivers/net/usb/ax88179a_devices.c +0 -0
index a6b0a3f47118c..01d6a35f68b2c 100644

[ ... ]

Quoted 20 lines
drivers/net/usb/ax88179a_devices.c +16 -0
@@ -126,6 +128,63 @@ static void ax88179a_status(struct usbnet *dev, struct urb *urb)
 	phylink_mac_interrupt(data->phylink);
 }
 
+static int ax88179a_suspend(struct usb_interface *intf, pm_message_t message)
+{
+	struct usbnet *dev = usb_get_intfdata(intf);
+	struct ax88179_data *priv;
+	u8 tmp8 = 0;
+	u16 tmp16;
+	int ret;
+
+	priv = dev->driver_priv;
+	ax88179_set_pm_mode(dev, true);
+
+	if (netif_running(dev->net)) {
+		rtnl_lock();
+		phylink_suspend(priv->phylink, !!priv->wolopts);
+		rtnl_unlock();
+	}

[ ... ]

Quoted 18 lines
drivers/net/usb/ax88179a_devices.c +18 -0
+static int ax88179a_resume(struct usb_interface *intf)
+{
+	struct usbnet *dev = usb_get_intfdata(intf);
+	struct ax88179_data *ax179_data;
+	u8 reg8 = 0;
+	int ret;
+
+	ax179_data = dev->driver_priv;
+	ax88179_set_pm_mode(dev, true);
+
+	ret = ax88179_read_cmd(dev, AX88179A_PHY_POWER, 0, 0, 1, &reg8);
+	if (ret < 0)
+		goto err_out;
+
+	if (!(reg8 & AX_PHY_POWER)) {
+		reg8 = AX_PHY_POWER;
+		ax88179_write_cmd(dev, AX88179A_PHY_POWER, 0, 0, 1, &reg8);
+		msleep(250);

drivers/net/usb/ax88179a_devices.c static int ax88179a_auto_detach(struct usbnet *dev) · line 224

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c +10 -0
+	}
+	ax88179_write_cmd(dev, AX_FW_MODE, AX_FW_MODE_179A, 0, 0, NULL);
+
+	/* Now, that AX_FW_MODE_179A is enabled, the PHY needs a power-cycle.
+	 * PHY-power is re-enabled in ax88179a_reset()
+	 */
+	ax88179_write_u8(dev, AX88179A_PHY_POWER, 0, 0, 0);
+	msleep(250);
+
+	ax88179a_reset(dev);

[Severity: High]
Does power-cycling the PHY in ax88179a_resume() break resume when Wake-on-LAN is enabled?

When priv->wolopts is non-zero, phylink_suspend(priv->phylink, true) sets PHYLINK_DISABLE_MAC_WOL and leaves the PHY running instead of calling phylink_stop(). ax88179a_resume() then writes 0 to AX88179A_PHY_POWER and calls ax88179a_reset(), which wipes all volatile PHY registers, drops the physical link, and skips phylink_start() because ax179_data->in_pm is set. When phylink_resume() runs next, it sees PHYLINK_DISABLE_MAC_WOL and takes the MAC WoL branch instead of calling phylink_start() -> phy_start():

drivers/net/phy/phylink.c:phylink_resume() {
    ...
	if (test_bit(PHYLINK_DISABLE_MAC_WOL, &pl->phylink_disable_state)) {
		...
		phylink_mac_initial_config(pl, true);

		/* Re-enable and re-resolve the link parameters */
		phylink_enable_and_run_resolve(pl, PHYLINK_DISABLE_MAC_WOL);
	} else {
		phylink_start(pl);
	}
}

Because phy_start() is never called after the PHY power-cycle, phylib never re-runs phy_config_aneg() to restore user-configured link modes, EEE, or AX88279 2.5G advertisement, and phylink_resolve() immediately reports carrier on from the stale pre-suspend pl->phy_state.link while the reset PHY is still down.

[Severity: Medium]
Does calling ax88179a_reset() unconditionally in ax88179a_resume() power on the PHY and enable MAC receive even when the interface is down?

When !netif_running(dev->net), the PHY was suspended or powered off by ax88179a_init_phy() or ax88179a_stop(). Running ax88179a_reset() during resume writes AX_PHY_POWER to AX88179A_PHY_POWER (clearing BMCR_PDOWN in the freshly power-cycled PHY while phydev->suspended remains true in software) and enables AX_RX_CTL_START and AX_MEDIUM_RECEIVE_EN, leaving the link and receiver active while the interface is administratively down.

drivers/net/usb/ax88179a_devices.c static int ax88179a_auto_detach(struct usbnet *dev) · line 236

Quoted 12 lines
drivers/net/usb/ax88179a_devices.c +12 -0
+
+err_out:
+	if (netif_running(dev->net)) {
+		rtnl_lock();
+		phylink_resume(ax179_data->phylink);
+		rtnl_unlock();
+	}
+
+	ax88179_set_pm_mode(dev, false);
+
+	return usbnet_resume(intf);
+}

[Severity: Medium]
When ax88179_read_cmd() fails in ax88179a_resume() and jumps to err_out, does returning usbnet_resume(intf) discard the negative error code in ret and resume phylink on uninitialized hardware?

[ ... ]

Quoted 4 lines
drivers/net/usb/ax88179a_devices.c +0 -0
@@ -1055,9 +1166,13 @@ static int ax88179a_reset(struct usbnet *dev)
 	ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_SWP_CTRL, 1, 0);
 	ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_TX_HDR_CKSUM, 1, 0);
 

drivers/net/usb/ax88179a_devices.c static int ax88179a_reset(struct usbnet *dev) · line 1175

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c +7 -3
-	/* Read MAC address from DTB or asix chip */
-	ax88179_get_mac_addr(dev);
-	memcpy(dev->net->perm_addr, dev->net->dev_addr, ETH_ALEN);
+	/* Read MAC address from DTB or asix chip, except when called
+	 * from resume context.
+	 */
+	if (!ax179_data->in_pm) {
+		ax88179_get_mac_addr(dev);
+		memcpy(dev->net->perm_addr, dev->net->dev_addr, ETH_ALEN);
+	}

[Severity: High]
When ax88179a_reset() is called from ax88179a_resume() with ax179_data->in_pm set, does skipping ax88179_get_mac_addr() leave the AX_NODE_ID register unprogrammed if the chip was reset or lost power?

ax88179_get_mac_addr() is the only place in the reset path that writes dev->net->dev_addr to AX_NODE_ID. Without an else branch writing dev->net->dev_addr to AX_NODE_ID during resume, a custom, Device Tree, or random fallback MAC address is lost in hardware after reset_resume or a power-loss suspend, causing the unicast filter (AX_RX_CTL_AP) to drop frames for dev->net->dev_addr.

[Severity: Medium]
In ax88179a_reset(), which is now also called from ax88179a_resume(), can dereferencing tmp16 fault on architectures that trap unaligned accesses?

ax88179a_reset() aliases tmp16 to a 1-byte-aligned stack array (u8 buf[5]) and dereferences it as a u16 when writing AX_MEDIUM_STATUS_MODE:

drivers/net/usb/ax88179a_devices.c:ax88179a_reset() {
	struct ax88179_data *ax179_data = dev->driver_priv;
	u16 *tmp16;
	u8 buf[5];
	u16 rxctl;
	u8 *tmp;

	tmp16 = (u16 *)buf;
    ...
	*tmp16 = AX_MEDIUM_RECEIVE_EN | AX_MEDIUM_TXFLOW_CTRLEN |
		 AX_MEDIUM_RXFLOW_CTRLEN | AX_MEDIUM_FULL_DUPLEX;
	if (!ax179_data->is_ax88772d)
		*tmp16 |= AX_MEDIUM_GIGAMODE;
	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 2, 2, tmp16);
    ...
}

Using a u16 local variable or ax88179_write_u16() would avoid the unaligned access.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
#26 lore raw

Re: [PATCH net-next v21 09/13] ax88179_178a: Add Suspend/resume support for AX88179A/772D/279

In reply to Birger Koblitz
Thank you for your contribution! Sashiko AI review found 11 potential issue(s) to consider.

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

Critical: 0 · High: 0 · Medium: 5 · Low: 6

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 patch turns off runtime PM (USB autosuspend) for every AX88179A/AX88772D/AX88279 interface, and the commit message never says…
- [Medium] When ax88179a_reset() is called from ax88179a_resume() (in_pm == true), the patch skips ax88179_get_mac_addr() entirely.
- [Medium] ax88179a_resume() always cuts PHY power (ax88179_write_u8(dev, AX88179A_PHY_POWER, 0, 0, 0); msleep(250)).
- [Medium] In ax88179a_resume(), if the first control read ax88179_read_cmd(dev, AX88179A_PHY_POWER, ...) fails, the code jumps…
- [Medium] In the resume path, ax88179a_reset() writes AX88179A_VLAN_ID_CONTROL with AX_VLAN_CONTROL_VFE whenever…
- [Low] The commit message presents this change as adding suspend/resume for the AX179A family.
- [Low] struct ax88179_data documents struct mutex medium_status_mutex; /* protect AX_MEDIUM_STATUS_MODE */.
- [Low] The patch makes the control flow of ax88179a_reset() depend on the shared, unlocked flag ax179_data->in_pm.
- [Low] ax88179a_suspend() and ax88179a_resume() call netif_running(dev->net) before rtnl_lock(), then call…
- [Low] The WoL branch of ax88179a_suspend() arms AX88179A_WAKEUP_SETTING.
- [Low] In the WoL branch of ax88179a_suspend(), the return value of ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 2, 2,…

--

ax88179_178a: Add Suspend/resume support for AX88179A/772D/279

This commit stores per-chip suspend and resume callbacks in struct ax88179_data. Wrappers in ax88179_lib dispatch to them from the single usb_driver. It adds ax88179a_suspend()/ax88179a_resume() for the AX179A family using phylink_suspend()/phylink_resume(), and takes a runtime PM usage reference in ax88179a_bind().

Quoted 4 lines
drivers/net/usb/ax88179_178a.c +0 -0
index f78ad344c1c4f..b077b7153f0c0 100644

[ ... ]

drivers/net/usb/ax88179_178a.c static struct usb_driver ax88179_178a_driver = { · line 1370

Quoted 10 lines
drivers/net/usb/ax88179_178a.c +3 -3
@@ -1362,9 +1365,9 @@ static struct usb_driver ax88179_178a_driver = {
 	.name =		"ax88179_178a",
 	.id_table =	products,
 	.probe =	usbnet_probe,
-	.suspend =	ax88179_suspend,
-	.resume =	ax88179_resume,
-	.reset_resume =	ax88179_resume,
+	.suspend =	ax88179_suspend_wrapper,
+	.resume =	ax88179_resume_wrapper,
+	.reset_resume =	ax88179_resume_wrapper,

[Severity: Low]
The subject says "Add Suspend/resume support for AX88179A/772D/279". Is that accurate?

Since "ax88179_178a: Add HW support for AX179A-based chips", the ax88179a_info, ax88772d_info and ax88279_info entries in the shared products table have already been using .suspend = ax88179_suspend and .resume/.reset_resume = ax88179_resume.

Those legacy handlers program AX_PHYPWR_RSTCTL (in ax88179_suspend() and through ax88179_reset()). They never stop or start phylink.

That means every commit between that one and this one runs the legacy AX88179 PM code on AX179A hardware. Could the commit message say that this replaces the legacy handlers that were being used for the AX179A family? Or could the series be reordered so that no bisectable commit wires up the wrong callbacks?

Quoted 2 lines
drivers/net/usb/ax88179_178a.c +0 -0
 	.disconnect =	ax88179_disconnect,
 	.supports_autosuspend = 1,

[ ... ]

Quoted 4 lines
drivers/net/usb/ax88179a_devices.c +0 -0
index a6b0a3f47118c..01d6a35f68b2c 100644

[ ... ]

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c +6 -0
@@ -126,6 +128,63 @@ static void ax88179a_status(struct usbnet *dev, struct urb *urb)
 	phylink_mac_interrupt(data->phylink);
 }
 
+static int ax88179a_suspend(struct usb_interface *intf, pm_message_t message)
+{
+	struct usbnet *dev = usb_get_intfdata(intf);
+	struct ax88179_data *priv;
+	u8 tmp8 = 0;
+	u16 tmp16;

drivers/net/usb/ax88179a_devices.c static void ax88179a_status(struct usbnet *dev, struct urb *urb) · line 146

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c +10 -0
+	int ret;
+
+	priv = dev->driver_priv;
+	ax88179_set_pm_mode(dev, true);
+
+	if (netif_running(dev->net)) {
+		rtnl_lock();
+		phylink_suspend(priv->phylink, !!priv->wolopts);
+		rtnl_unlock();
+	}

[Severity: Low]
netif_running() is checked here before rtnl_lock() is taken. ndo_open and ndo_stop change the running state and call phylink_start()/phylink_stop() under RTNL. Could the result be stale by the time RTNL is held?

If dev_close() runs between the check and rtnl_lock(), phylink_suspend() without WoL would call phylink_stop() a second time on a PHY that is already stopped.

The error path below has the same pattern, and so does ax88179a_resume(). There, a stale result would run phylink_resume() -> phylink_start() on an interface that is down.

The window is narrow, because userspace is frozen during system sleep and this patch blocks runtime PM. Would moving the netif_running() check inside the rtnl_lock() section close it?

Quoted 14 lines
drivers/net/usb/ax88179a_devices.c +14 -0
+
+	ret = usbnet_suspend(intf, message);
+	if (ret && netif_running(dev->net)) {
+		rtnl_lock();
+		phylink_resume(priv->phylink);
+		rtnl_unlock();
+		ax88179_set_pm_mode(dev, false);
+		return ret;
+	}
+
+	/* Enable WoL */
+	if (priv->wolopts) {
+		ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD, 1, 1, &tmp8);
+		tmp8 &= ~(AX_MONITOR_MODE_RWLC | AX_MONITOR_MODE_RWMP);

drivers/net/usb/ax88179a_devices.c static void ax88179a_status(struct usbnet *dev, struct urb *urb) · line 170

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c +10 -0
+		if (priv->wolopts & WAKE_PHY)
+			tmp8 |= AX_MONITOR_MODE_RWLC;
+		if (priv->wolopts & WAKE_MAGIC)
+			tmp8 |= AX_MONITOR_MODE_RWMP;
+
+		ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD, 1, 1, &tmp8);
+
+		ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 2, 2, &tmp16);
+		tmp16 |= AX_MEDIUM_RECEIVE_EN;
+		ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 2, 2, &tmp16);

[Severity: Low]
What happens here if the AX_MEDIUM_STATUS_MODE read fails? For size == 2, ax88179_read_cmd() copies its zero-initialised buffer to the caller even on error:

drivers/net/usb/ax88179_lib.c:ax88179_read_cmd() {
	...
		u16 buf = 0;

		ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf);
		le16_to_cpus(&buf);
		*((u16 *)data) = buf;
	...
}

If the read fails and the write succeeds, only AX_MEDIUM_RECEIVE_EN is left set. That clears the GIGAMODE, FULL_DUPLEX, flow control and JUMBO bits that ax88179a_mac_link_up() programmed, while phylink_suspend(pl, true) has kept the link up for WoL.

The AX_MONITOR_MOD read above has the same problem with tmp8.

[Severity: Low]
This isn't a bug, but struct ax88179_data documents:

struct mutex medium_status_mutex; /* protect AX_MEDIUM_STATUS_MODE */

ax88179a_mac_link_up() and ax88179_change_mtu() take that mutex around their AX_MEDIUM_STATUS_MODE accesses. Should this read-modify-write hold medium_status_mutex too, for consistency?

drivers/net/usb/ax88179a_devices.c static void ax88179a_status(struct usbnet *dev, struct urb *urb) · line 182

Quoted 12 lines
drivers/net/usb/ax88179a_devices.c +12 -0
+
+		if (priv->chip_version == AX_VERSION_AX88279)
+			ax88179_write_cmd(dev, AX88179A_WAKEUP_SETTING, 8,
+					  EPHY_LOW_POWER_EN | S5_WOL_EN
+					  | S5_WOL_LOW_POWER | 0x8000, 0, NULL);
+		else
+			ax88179_write_cmd(dev, AX88179A_WAKEUP_SETTING, 0,
+					  EPHY_LOW_POWER_EN, 0, NULL);
+
+	} else if (priv->chip_version == AX_VERSION_AX88279) {
+		ax88179_write_cmd(dev, AX88179A_WAKEUP_SETTING, 8, 0x8000, 0, NULL);
+	}

[Severity: Low]
Is AX88179A_WAKEUP_SETTING ever cleared after a WoL suspend?

Neither ax88179a_resume() nor ax88179a_reset() writes this register. ax88179_set_wol() only updates priv->wolopts.

On AX88179A/772D nothing clears it at all, because the else branch above only handles AX88279. On AX88279 the S5 wake bits are cleared only at a later suspend with WoL off.

Suppose a WoL suspend/resume cycle is followed by WoL being disabled and the system shutting down. Could S5_WOL_EN stay armed while ethtool reports WoL as off? Whether the chip clears this itself on resume depends on the hardware.

Quoted 4 lines
drivers/net/usb/ax88179a_devices.c +4 -0
+
+	ax88179_set_pm_mode(dev, false);
+	return 0;
+}

[ ... ]

Quoted 7 lines
drivers/net/usb/ax88179a_devices.c +3 -0
@@ -135,6 +194,47 @@ static int ax88179a_auto_detach(struct usbnet *dev)
 	return 0;
 }
 
+static int ax88179a_resume(struct usb_interface *intf)
+{
+	struct usbnet *dev = usb_get_intfdata(intf);

drivers/net/usb/ax88179a_devices.c static int ax88179a_auto_detach(struct usbnet *dev) · line 209

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c +10 -0
+	struct ax88179_data *ax179_data;
+	u8 reg8 = 0;
+	int ret;
+
+	ax179_data = dev->driver_priv;
+	ax88179_set_pm_mode(dev, true);
+
+	ret = ax88179_read_cmd(dev, AX88179A_PHY_POWER, 0, 0, 1, &reg8);
+	if (ret < 0)
+		goto err_out;

[Severity: Medium]
If this first control read fails, the jump to err_out skips the PHY power-on, the AX_FW_MODE_179A write and all of ax88179a_reset(). The err_out path still does this:

err_out:

	if (netif_running(dev->net)) {
		rtnl_lock();
		phylink_resume(ax179_data->phylink);
		rtnl_unlock();
	}
	ax88179_set_pm_mode(dev, false);
	return usbnet_resume(intf);

usbnet_resume() returns 0, so ret is lost. Does this report a successful resume to the USB core while RX is stopped and the PHY may have no power, with phylink running and usbnet resubmitting URBs?

Should the error be returned so the USB core can reset or rebind the device?

drivers/net/usb/ax88179a_devices.c static int ax88179a_auto_detach(struct usbnet *dev) · line 222

Quoted 13 lines
drivers/net/usb/ax88179a_devices.c +13 -0
+
+	if (!(reg8 & AX_PHY_POWER)) {
+		reg8 = AX_PHY_POWER;
+		ax88179_write_cmd(dev, AX88179A_PHY_POWER, 0, 0, 1, &reg8);
+		msleep(250);
+	}
+	ax88179_write_cmd(dev, AX_FW_MODE, AX_FW_MODE_179A, 0, 0, NULL);
+
+	/* Now, that AX_FW_MODE_179A is enabled, the PHY needs a power-cycle.
+	 * PHY-power is re-enabled in ax88179a_reset()
+	 */
+	ax88179_write_u8(dev, AX88179A_PHY_POWER, 0, 0, 0);
+	msleep(250);

[Severity: Medium]
Does this power cycle reset the PHY registers to their power-on defaults, with nothing re-initialising them afterwards?

ax88179a_init_phy() sets:

	data->phydev->mac_managed_pm = true;

so mdio_bus_phy_resume() returns early and never calls phy_init_hw(). This driver doesn't call it either.

With WoL enabled, phylink_suspend(pl, true) did not stop the PHY. So phylink_resume() takes the PHYLINK_DISABLE_MAC_WOL branch, which only runs phylink_link_down(), phylink_mac_initial_config() and a resolve. It never calls phy_start(), so config_aneg does not run.

Would the PHY then autonegotiate with its reset-default advertisement, BMCR and EEE settings? Meanwhile phylib and ethtool would still report the earlier user settings, such as a forced speed, a restricted advertisement or EEE off.

In the non-WoL path, phy_start() restores the advertisement, but soft_reset and config_init are still skipped.

drivers/net/usb/ax88179a_devices.c static int ax88179a_auto_detach(struct usbnet *dev) · line 224

Quoted 2 lines
drivers/net/usb/ax88179a_devices.c +2 -0
+
+	ax88179a_reset(dev);

[Severity: Medium]
Is the hardware VLAN filter table restored on this path? When NETIF_F_HW_VLAN_CTAG_FILTER is enabled, ax88179a_reset() turns the filter back on:

	if (dev->net->features & NETIF_F_HW_VLAN_CTAG_FILTER)
		*tmp |= AX_VLAN_CONTROL_VFE;

Nothing clears or refills the 256-entry VLAN ID table, though. Entries are written one at a time by ax88179a_vlan_rx_add_vid(), and the driver keeps no shadow copy. ax88179a_set_features() zeroes all 256 entries before setting VFE, so it treats the table as undefined.

.reset_resume also goes through this path. After a USB reset or power loss, could tagged traffic on configured VLANs be dropped (or wrongly passed, if the table holds garbage) until the feature is toggled? Whether the table survives a reset depends on the hardware.

Quoted 12 lines
drivers/net/usb/ax88179a_devices.c +12 -0
+
+err_out:
+	if (netif_running(dev->net)) {
+		rtnl_lock();
+		phylink_resume(ax179_data->phylink);
+		rtnl_unlock();
+	}
+
+	ax88179_set_pm_mode(dev, false);
+
+	return usbnet_resume(intf);
+}

[ ... ]

drivers/net/usb/ax88179a_devices.c static int ax88179a_bind(struct usbnet *dev, struct usb_interface *intf) · line 913

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c +6 -0
@@ -802,6 +905,13 @@ static int ax88179a_bind(struct usbnet *dev, struct usb_interface *intf)
 	if (ret)
 		goto initphy_err;
 
+	/* Keep this interface runtime-PM active by taking a usage ref.
+	 * Prevents runtime suspend while bound and avoids resume paths
+	 * that could deadlock (autoresume under RTNL while USB PM lock
+	 * is held, phylink/MDIO wants RTNL).
+	 */
+	pm_runtime_get_noresume(&intf->dev);

[Severity: Medium]
This turns off USB autosuspend for every bound AX88179A, AX88772D and AX88279 interface, even when the netdev is down. The only matching put is pm_runtime_put_noidle() in ax88179a_unbind(). The shared usb_driver still sets .supports_autosuspend = 1.

The commit message only talks about adding system suspend/resume wrappers. Could it say that runtime PM is deliberately disabled for the AX179A family, and why? The reason is that ax88179a_resume() takes rtnl_lock(), which would deadlock when an ethtool or MDIO access under RTNL triggers an autoresume.

Quoted 2 lines
drivers/net/usb/ax88179a_devices.c +1 -0
+
 	return 0;

[ ... ]

Quoted 4 lines
drivers/net/usb/ax88179a_devices.c +0 -0
@@ -1055,9 +1166,13 @@ static int ax88179a_reset(struct usbnet *dev)
 	ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_SWP_CTRL, 1, 0);
 	ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_TX_HDR_CKSUM, 1, 0);
 

drivers/net/usb/ax88179a_devices.c static int ax88179a_reset(struct usbnet *dev) · line 1175

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c +7 -3
-	/* Read MAC address from DTB or asix chip */
-	ax88179_get_mac_addr(dev);
-	memcpy(dev->net->perm_addr, dev->net->dev_addr, ETH_ALEN);
+	/* Read MAC address from DTB or asix chip, except when called
+	 * from resume context.
+	 */
+	if (!ax179_data->in_pm) {
+		ax88179_get_mac_addr(dev);
+		memcpy(dev->net->perm_addr, dev->net->dev_addr, ETH_ALEN);
+	}

[Severity: Medium]
Skipping ax88179_get_mac_addr() here skips more than the read. It also skips writing the station address back to the hardware:

drivers/net/usb/ax88179_lib.c:ax88179_get_mac_addr() {
	...
	ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_NODE_ID, ETH_ALEN, ETH_ALEN,
			  dev->net->dev_addr);
}

On this path, the only other code that writes AX_NODE_ID is ax88179_set_mac_addr(), and it returns -EBUSY while the interface is running.

After a reset_resume or hibernation restore, the chip would reload NODE_ID from efuse/EEPROM. dev_addr may hold a different address: one set by the user, a random one for a blank efuse, or one from DT.

ax88179a_reset() programs AX_RX_CTL with AX_RX_CTL_AP and without AX_RX_CTL_PRO. In that case, would the hardware filter out unicast frames sent to the netdev's own address?

Before this patch, the legacy resume path went through ax88179_reset() -> ax88179_get_mac_addr(), which rewrote NODE_ID. Could the resume path skip only the read and still write dev->net->dev_addr to AX_NODE_ID?

[ ... ]

drivers/net/usb/ax88179a_devices.c static int ax88179a_reset(struct usbnet *dev) · line 1239

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c +5 -1
@@ -1117,7 +1232,11 @@ static int ax88179a_reset(struct usbnet *dev)
 	/* Ensure EEE state is off, consistent with phylink setup */
 	ax88179_write_cmd(dev, AX_GPHY_CTL, AX_GPHY_EEE_CTRL, false, 0, NULL);
 
-	phylink_start(ax179_data->phylink);
+	/* ax88179a_reset() may also be called from resume context,
+	 * phylink_resume() will start phylink, then.
+	 */
+	if (!ax179_data->in_pm)
+		phylink_start(ax179_data->phylink);

[Severity: Low]
ax88179a_reset() is also the usbnet .reset callback, which usbnet_open() calls under RTNL. in_pm is set and cleared by plain stores in ax88179a_suspend()/ax88179a_resume(), and there is no lock shared with the open path:

drivers/net/usb/ax88179_lib.c:ax88179_set_pm_mode() {
	...
	ax179_data->in_pm = pm_mode;
}

If ndo_open ran while in_pm was true, phylink_start() and the MAC address programming would be skipped without any warning. The interface would be up with phylink stopped.

The window is very narrow, given the freezer and the runtime PM usage reference. Still, could the resume context be passed in explicitly, for example as a bool argument to an internal reset helper, so this doesn't depend on a shared mutable flag?

Quoted 3 lines
drivers/net/usb/ax88179a_devices.c +0 -0
 	return 0;
 }
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261114-ax88179a-v21-0-c2d34410bcbe%40birger-koblitz.de
#27 lore raw

PATCH v21 10/13 ax88179_178a: Add ethtool get_drvinfo

In reply to Birger Koblitz

Add ax88179a_get_drvinfo() as implementation of get_drvinfo, in order to provide information about the device firmware.

---
 drivers/net/usb/ax88179a_devices.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/net/usb/ax88179a_devices.c +15 -0
index 01d6a35f68b2c56f79acbe2875ce8e99ccdfb197..69095110e70435806a99274c50d79e86016ec9a0 100644
@@ -235,6 +235,20 @@ static int ax88179a_resume(struct usb_interface *intf)
 	return usbnet_resume(intf);
 }
 
+static void ax88179a_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *info)
+{
+	struct ax88179_data *priv = netdev2data(net);
+
+	/* Inherit standard device info */
+	usbnet_get_drvinfo(net, info);
+	if (priv->chip_version < AX_VERSION_AX88179A)
+		return;
+
+	snprintf(info->fw_version, sizeof(info->fw_version), "%d.%d.%d.%d",
+		 priv->fw_version[0], priv->fw_version[1],
+		 priv->fw_version[2], priv->fw_version[3]);
+}
+
 static void ax88179a_bulkin_config(struct usbnet *dev, u8 link_sts, u8 speed, bool full_duplex)
 {
 	struct ax88179_data *ax179_data = dev->driver_priv;
@@ -340,6 +354,7 @@ static int ax88179a_set_eee(struct net_device *net, struct ethtool_keee *edata)
 }
 
 static const struct ethtool_ops ax88179a_ethtool_ops = {
+	.get_drvinfo            = ax88179a_get_drvinfo,
 	.get_link		= ethtool_op_get_link,
 	.get_msglevel		= usbnet_get_msglevel,
 	.set_msglevel		= usbnet_set_msglevel,
Signature · 1 line
2.47.3
#28 lore raw

Re: [PATCH net-next v21 10/13] ax88179_178a: Add ethtool get_drvinfo

Sashiko has reviewed this patch and found no issues.
Quoted 4 lines

Add ax88179a_get_drvinfo() as implementation of get_drvinfo, in order to provide information about the device firmware.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
#29 lore raw

Re: [PATCH net-next v21 10/13] ax88179_178a: Add ethtool get_drvinfo

In reply to Birger Koblitz
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The new ax88179a_get_drvinfo() (drivers/net/usb/ax88179a_devices.c:247-249) prints…

--

ax88179_178a: Add ethtool get_drvinfo

This commit adds ax88179a_get_drvinfo() as the get_drvinfo ethtool callback for AX88179A-based devices. It reports the firmware version that was read from the device at bind time.

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c +2 -0
index 01d6a35f68b2c..69095110e7043 100644
@@ -235,6 +235,20 @@ static int ax88179a_resume(struct usb_interface *intf)
 	return usbnet_resume(intf);
 }
 
+static void ax88179a_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *info)
+{

drivers/net/usb/ax88179a_devices.c static int ax88179a_resume(struct usb_interface *intf) · line 249

Quoted 10 lines
drivers/net/usb/ax88179a_devices.c +10 -0
+	struct ax88179_data *priv = netdev2data(net);
+
+	/* Inherit standard device info */
+	usbnet_get_drvinfo(net, info);
+	if (priv->chip_version < AX_VERSION_AX88179A)
+		return;
+
+	snprintf(info->fw_version, sizeof(info->fw_version), "%d.%d.%d.%d",
+		 priv->fw_version[0], priv->fw_version[1],
+		 priv->fw_version[2], priv->fw_version[3]);

[Severity: Low]
What does ethtool -i report here if one of the firmware version reads failed at bind time?

ax88179a_bind() stores 0xff in any byte whose AX88179A_ACCESS_BL read returns an error:

drivers/net/usb/ax88179a_devices.c:ax88179a_bind() {
    ...
	for (int i = 0; i < 3; i++) {
		ret = ax88179_read_cmd(dev, AX88179A_ACCESS_BL, AX88179A_SW_VERSION + i,
				       1, 1, &ax179_data->fw_version[i]);
		if (ret < 0)
			ax179_data->fw_version[i] = 0xff;
	}
	ret = ax88179_read_cmd(dev, AX88179A_ACCESS_BL, AX88179A_SW_REVISION,
			       1, 1, &ax179_data->fw_version[3]);
	if (ret < 0)
		ax179_data->fw_version[3] = 0xff;
    ...
}

The only check in ax88179a_get_drvinfo() is the chip_version one, and chip_version was read successfully just before these reads. So if the BL access stalls or hits a transient USB error, the ethtool fw_version field would show something like "255.255.255.255" or "1.2.255.3". Userspace has no way to tell that apart from a real firmware version.

This also overwrites the dev->driver_info->description string that usbnet_get_drvinfo() has just written into info->fw_version.

The 0xff marker itself comes from the earlier commit "ax88179_178a: Add HW support for AX179A-based chips". This patch is what exposes it through the ethtool uAPI.

Could the driver record whether the reads succeeded, or skip the snprintf() when any byte holds the 0xff marker, so that the usbnet default is kept?

Quoted 2 lines
drivers/net/usb/ax88179a_devices.c +2 -0
+}
+

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261114-ax88179a-v21-0-c2d34410bcbe%40birger-koblitz.de
#30 lore raw

PATCH v21 11/13 ax88179_178a: Update driver name and information

In reply to Birger Koblitz

Add additionally supported devices to Kconfig description, add further requirements such as PHYLINK.

Update driver name in usb_driver and update MODULE_DESCRIPTION to include the additionally supported chips.

Change Kconfig symbol name from USB_NET_AX88179_178A to USB_NET_AX88179 and update loongson32_defconfig/loongson64_defconfig to use that symbol.

---
 arch/loongarch/configs/loongson32_defconfig |  2 +-
 arch/loongarch/configs/loongson64_defconfig |  2 +-
 drivers/net/usb/Kconfig                     | 11 +++++++----
 drivers/net/usb/Makefile                    |  2 +-
 drivers/net/usb/ax88179_178a.c              |  8 ++++----
 5 files changed, 14 insertions(+), 11 deletions(-)
arch/loongarch/configs/loongson32_defconfig +1 -1
index dbef879935f322e6167b4ed878ad4cb20048c6db..a039b8e8d242073c16ea281cf8734068a1a9b29f 100644
@@ -641,7 +641,7 @@ CONFIG_USB_RTL8150=m
 CONFIG_USB_RTL8152=m
 CONFIG_USB_USBNET=m
 # CONFIG_USB_NET_AX8817X is not set
-# CONFIG_USB_NET_AX88179_178A is not set
+# CONFIG_USB_NET_AX88179 is not set
 CONFIG_USB_NET_CDC_EEM=m
 CONFIG_USB_NET_HUAWEI_CDC_NCM=m
 CONFIG_USB_NET_CDC_MBIM=m
arch/loongarch/configs/loongson64_defconfig +1 -1
index 4f8bb77b8a1e6e30bcbd6e96d7e38b5054630ea0..b30415c03fa185cae77e81ded929c743ef22ee40 100644
@@ -657,7 +657,7 @@ CONFIG_USB_RTL8150=m
 CONFIG_USB_RTL8152=m
 CONFIG_USB_USBNET=m
 # CONFIG_USB_NET_AX8817X is not set
-# CONFIG_USB_NET_AX88179_178A is not set
+# CONFIG_USB_NET_AX88179 is not set
 CONFIG_USB_NET_CDC_EEM=m
 CONFIG_USB_NET_HUAWEI_CDC_NCM=m
 CONFIG_USB_NET_CDC_MBIM=m
drivers/net/usb/Kconfig +7 -4
index 115990b0d9537aea2776544c9768b034f32aa7a4..cc8f2e150339915908fe1c28dea82e1103bbf17d 100644
@@ -195,18 +195,21 @@ config USB_NET_AX8817X
 	  This driver creates an interface named "ethX", where X depends on
 	  what other networking devices you have in use.
 
-config USB_NET_AX88179_178A
-	tristate "ASIX AX88179/178A USB 3.0/2.0 to Gigabit Ethernet"
+config USB_NET_AX88179
+	tristate "ASIX AX88179/179A/178A USB 2.0/3.0 to 100M/1G/2.5GbE Adapters"
 	depends on USB_USBNET
-	select CRC32
 	select PHYLINK
-	default y
+	select AX88796B_PHY
+	select CRC32
 	help
 	  This option adds support for ASIX AX88179 based USB 3.0/2.0
 	  to Gigabit Ethernet adapters.
 
 	  This driver should work with at least the following devices:
 	    * ASIX AX88179
+	    * ASIX AX88179A/B
+	    * ASIX AX88279
+	    * ASIX AX88772D/E
 	    * ASIX AX88178A
 	    * Sitcomm LN-032
 
drivers/net/usb/Makefile +1 -1
index 2ecead0181eaf8d66fb6f5dbd6f2905b22b6eb57..4026f19ecb826a6465de38f1d9bb0e4c0af80421 100644
@@ -12,7 +12,7 @@ obj-$(CONFIG_USB_HSO)		+= hso.o
 obj-$(CONFIG_USB_LAN78XX)	+= lan78xx.o
 obj-$(CONFIG_USB_NET_AX8817X)	+= asix.o
 asix-y := asix_devices.o asix_common.o ax88172a.o
-obj-$(CONFIG_USB_NET_AX88179_178A)      += ax88179.o
+obj-$(CONFIG_USB_NET_AX88179)      += ax88179.o
 ax88179-y := ax88179_178a.o ax88179a_devices.o ax88179_lib.o
 obj-$(CONFIG_USB_NET_CDCETHER)	+= cdc_ether.o
 obj-$(CONFIG_USB_NET_CDC_EEM)	+= cdc_eem.o
drivers/net/usb/ax88179_178a.c +4 -4
index b077b7153f0c07676aafd5dfd13a2c0d9a826719..88dce368eacfeee5df4062ff277041427f6ff475 100644
@@ -1361,8 +1361,8 @@ static const struct usb_device_id products[] = {
 };
 MODULE_DEVICE_TABLE(usb, products);
 
-static struct usb_driver ax88179_178a_driver = {
-	.name =		"ax88179_178a",
+static struct usb_driver ax88179_driver = {
+	.name =		"ax88179",
 	.id_table =	products,
 	.probe =	usbnet_probe,
 	.suspend =	ax88179_suspend_wrapper,
@@ -1373,8 +1373,8 @@ static struct usb_driver ax88179_178a_driver = {
 	.disable_hub_initiated_lpm = 1,
 };
 
-module_usb_driver(ax88179_178a_driver);
+module_usb_driver(ax88179_driver);
 
-MODULE_DESCRIPTION("ASIX AX88179/178A based USB 3.0/2.0 Gigabit Ethernet Devices");
+MODULE_DESCRIPTION("ASIX AX88179/179A/178A/279 based USB 3.0/2.0 100M/1G/2.5GbE Controllers");
 MODULE_LICENSE("GPL");
 MODULE_ALIAS("ax88179_178a");
Signature · 1 line
2.47.3
#31 lore raw

Re: [PATCH net-next v21 11/13] ax88179_178a: Update driver name and information

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] net: usb: ax88179: Kconfig rename drops default y and disables driver --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] net: usb: ax88179: Kconfig rename drops default y and disables driver
--

commit a2dd9912da623ded3490ea8a07a91779c220769c
Author: Birger Koblitz <[email protected]>

ax88179_178a: Update driver name and information

This commit renames Kconfig symbol USB_NET_AX88179_178A to USB_NET_AX88179, updates the USB driver name to "ax88179", and expands the Kconfig and module descriptions for newly supported ASIX chips.

Quoted 8 lines
drivers/net/usb/Kconfig +0 -0
index 115990b0d9537..cc8f2e1503399 100644
@@ -195,18 +195,21 @@ config USB_NET_AX8817X
 	  This driver creates an interface named "ethX", where X depends on
 	  what other networking devices you have in use.
 

drivers/net/usb/Kconfig config USB_NET_AX8817X · line 203

Quoted 10 lines
drivers/net/usb/Kconfig +4 -4
-config USB_NET_AX88179_178A
-	tristate "ASIX AX88179/178A USB 3.0/2.0 to Gigabit Ethernet"
+config USB_NET_AX88179
+	tristate "ASIX AX88179/179A/178A USB 2.0/3.0 to 100M/1G/2.5GbE Adapters"
 	depends on USB_USBNET
-	select CRC32
 	select PHYLINK
-	default y
+	select AX88796B_PHY
+	select CRC32

[Severity: Medium]
Does dropping "default y" when renaming USB_NET_AX88179_178A to USB_NET_AX88179 disable this driver across existing configurations?

Because savedefconfig omits symbols that match their default, the 25 in-tree defconfigs that enable CONFIG_USB_USBNET relied on "default y" to build this driver and did not list CONFIG_USB_NET_AX88179_178A explicitly. Removing "default y" alongside the symbol rename causes a regression where CONFIG_USB_NET_AX88179 defaults to n, disabling the driver in those defconfigs and when updating existing .config files via olddefconfig, while also making the "# CONFIG_USB_NET_AX88179 is not set" overrides in loongson32_defconfig and loongson64_defconfig redundant.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
#32 lore raw

Re: [PATCH net-next v21 11/13] ax88179_178a: Update driver name and information

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

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] In drivers/net/usb/Kconfig the patch quietly deletes default y from the AX88179 driver entry and, in the same hunk, renames the…
- [Medium] The patch changes usb_driver.name in drivers/net/usb/ax88179_178a.c (struct ax88179_driver) from…
- [Low] The commit message says the patch adds "further requirements such as PHYLINK".

--

ax88179_178a: Update driver name and information

This commit renames the Kconfig symbol USB_NET_AX88179_178A to USB_NET_AX88179 and updates the loongarch defconfigs to match. It extends the Kconfig help text and MODULE_DESCRIPTION to list the newly supported chips, and renames the usb_driver from "ax88179_178a" to "ax88179".

Quoted 6 lines
drivers/net/usb/Kconfig +0 -0
index 115990b0d9537..cc8f2e1503399 100644
@@ -195,18 +195,21 @@ config USB_NET_AX8817X
 	  This driver creates an interface named "ethX", where X depends on

drivers/net/usb/Kconfig config USB_NET_AX8817X · line 203

Quoted 10 lines
drivers/net/usb/Kconfig +2 -4
 	  what other networking devices you have in use.
 
-config USB_NET_AX88179_178A
-	tristate "ASIX AX88179/178A USB 3.0/2.0 to Gigabit Ethernet"
+config USB_NET_AX88179
+	tristate "ASIX AX88179/179A/178A USB 2.0/3.0 to 100M/1G/2.5GbE Adapters"
 	depends on USB_USBNET
-	select CRC32
 	select PHYLINK
-	default y

[Severity: Medium]
The commit message covers the symbol rename but does not mention that default y is removed here. Was that intended?

savedefconfig leaves out symbols that are at their default, so the two loongarch defconfigs are the only in-tree defconfigs that name this symbol. Other defconfigs enable USB_USBNET without naming it. For example, arch/arm64/configs/defconfig has:

CONFIG_USB_USBNET=m

The same goes for multi_v7, imx_v6_v7, exynos, tegra, qcom, omap2plus, bcm2835 and the drm CI configs. These got ax88179.ko only through the default. With the symbol renamed and the default gone, won't they silently stop building the driver?

Existing .config files hit the same problem. make olddefconfig drops the stale CONFIG_USB_NET_AX88179_178A line, and the new symbol takes its default, which is now n.

The sibling USB_NET_AX8817X entry still has default y. Without the default, the updated "# CONFIG_USB_NET_AX88179 is not set" lines in the loongarch defconfigs are also redundant.

Should default y be kept here?

drivers/net/usb/Kconfig config USB_NET_AX8817X · line 202

Quoted 1 line
drivers/net/usb/Kconfig +1 -0
+	select AX88796B_PHY

[Severity: Low]
The commit message says:

Add additionally supported devices to Kconfig description, add further requirements such as PHYLINK.

select PHYLINK was already there before this patch and appears as unchanged context above. The only new dependency is select AX88796B_PHY, and the commit message does not name it. Could the message mention it instead?

At this commit the select also does nothing. drivers/net/phy/ax88796b.c matches only 0x003b1861, 0x003b1881 and 0x003b184x. ax88179_mdiobus_read() reports 0x003b179a, 0x003b772d and 0x003b2790, so genphy binds instead.

The last patch in the series ("ax88796b: Add support for AX88772D, AX88179A and AX88279") adds those IDs to the C driver.

The Rust variant still lacks them at the end of the series. With CONFIG_AX88796B_RUST_PHY=y, drivers/net/phy/Makefile builds ax88796b_rust.o in place of ax88796b.o:

ifdef CONFIG_AX88796B_RUST_PHY
obj-$(CONFIG_AX88796B_PHY) += ax88796b_rust.o
else
obj-$(CONFIG_AX88796B_PHY) += ax88796b.o

ax88796b_rust.rs matches only 0x003b1861, 0x003b1881 and 0x003b1841. In that configuration, wouldn't the AX88772D, AX88179A and AX88279 PHYs still fall back to genphy? That gap belongs to the later ax88796b patch rather than this one.

Quoted 2 lines
drivers/net/usb/Kconfig +1 -0
+	select CRC32
 	help

[ ... ]

drivers/net/usb/ax88179_178a.c static const struct usb_device_id products[] = { · line 1365

Quoted 12 lines
drivers/net/usb/ax88179_178a.c +2 -2
index b077b7153f0c0..88dce368eacfe 100644
@@ -1361,8 +1361,8 @@ static const struct usb_device_id products[] = {
 };
 MODULE_DEVICE_TABLE(usb, products);
 
-static struct usb_driver ax88179_178a_driver = {
-	.name =		"ax88179_178a",
+static struct usb_driver ax88179_driver = {
+	.name =		"ax88179",

[Severity: Medium]
Userspace can see this name. usbnet_probe() copies it into dev->driver_name, and usbnet_get_drvinfo() reports it:

drivers/net/usb/usbnet.c:usbnet_get_drvinfo() {
    ...
	strscpy(info->driver, dev->driver_name, sizeof(info->driver));
    ...
}

So ethtool -i now shows "ax88179" for every device this driver handles, including existing AX88179/178A adapters.

The USB core also registers the driver directory under this name. That means /sys/bus/usb/drivers/ax88179_178a/, along with its bind, unbind and new_id files, goes away.

MODULE_ALIAS("ax88179_178a") keeps modprobe ax88179_178a working. Does it help udev rules matching DRIVERS=="ax88179_178a", systemd .link files using Driver=ax88179_178a, or scripts that write to the old sysfs path?

The earlier patch "ax88179_178a: Add HW support for AX179A-based chips" says AX179A-family devices bind to cdc_ncm by default. They only use this driver "if the ax88179_178a module is configured by the OS to have precedence over CDC-NCM". That kind of configuration would usually be a udev or sysfs rule that names the driver.

Is this userspace-visible rename intended, and could the commit message describe its impact?

Quoted 3 lines
drivers/net/usb/ax88179_178a.c +0 -0
 	.id_table =	products,
 	.probe =	usbnet_probe,
 	.suspend =	ax88179_suspend_wrapper,

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261114-ax88179a-v21-0-c2d34410bcbe%40birger-koblitz.de
#33 lore raw

PATCH v21 12/13 ax88179_178a: Add support for AX88179A/772D/279 EEPROM access

In reply to Birger Koblitz

The AX88179A/772D devices have 32 efuses with 20 bytes each, which can be randomly programmed. The AX88279 has 16K FLASH.

Provide ethtool read capability for these devices. However, no write access is provided.

---
 drivers/net/usb/ax88179_lib.c | 55 +++++++++++++++++++++++++++++++++----------
 1 file changed, 43 insertions(+), 12 deletions(-)
drivers/net/usb/ax88179_lib.c +43 -12
index 1523a920f3c38bf5c88a43c8a33645987b569bcd..821ee9cd8ded1b8f1e425bcef493fb175ed30376 100644
@@ -210,35 +210,61 @@ int ax88179_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
 	return 0;
 }
 
+static void
+ax88179_eeprom_access_params(struct ax88179_data *ax179_data, int i, u16 *value, u16 *idx)
+{
+	/* AX88179 has a word-addressable EEPROM
+	 * AX88179A uses EFUSES with 20 bytes length
+	 * AX88279 has an EEPROM addressable in 256 byte blocks
+	 */
+	if (ax179_data->chip_version < AX_VERSION_AX88179A) {
+		*value = i;
+		*idx = 1;
+	} else if (ax179_data->chip_version == AX_VERSION_AX88279) {
+		*value = (i * ax179_data->eeprom_block) >> 16;
+		*idx = (i * ax179_data->eeprom_block) & 0xffff;
+	} else {
+		*value = i << 4;
+		*idx = 0;
+	}
+}
+
 int ax88179_get_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom, u8 *data)
 {
 	struct usbnet *dev = netdev_priv(net);
-	u16 *eeprom_buff;
-	int first_word, last_word;
-	int i, ret;
+	struct ax88179_data *ax179_data;
+	int first, last, i, ret;
+	u8 *eeprom_buff;
+
+	ax179_data = dev->driver_priv;
 
 	if (eeprom->len == 0)
 		return -EINVAL;
 
 	eeprom->magic = AX88179_EEPROM_MAGIC;
 
-	first_word = eeprom->offset >> 1;
-	last_word = (eeprom->offset + eeprom->len - 1) >> 1;
-	eeprom_buff = kmalloc_objs(u16, last_word - first_word + 1);
+	first = eeprom->offset / ax179_data->eeprom_block;
+	last = (eeprom->offset + eeprom->len - 1) / ax179_data->eeprom_block;
+
+	eeprom_buff = kzalloc((last - first + 1) * ax179_data->eeprom_block, GFP_KERNEL);
 	if (!eeprom_buff)
 		return -ENOMEM;
 
-	/* ax88179/178A returns 2 bytes from eeprom on read */
-	for (i = first_word; i <= last_word; i++) {
-		ret = __ax88179_read_cmd(dev, AX_ACCESS_EEPROM, i, 1, 2,
-					 &eeprom_buff[i - first_word]);
-		if (ret < 0) {
+	for (i = first; i <= last; i++) {
+		u16 value, idx;
+
+		ax88179_eeprom_access_params(ax179_data, i, &value, &idx);
+		ret = __ax88179_read_cmd(dev, ax179_data->eeprom_read_cmd,
+					 value, idx, ax179_data->eeprom_block,
+					 eeprom_buff + (i - first) * ax179_data->eeprom_block);
+
+		if (ret != ax179_data->eeprom_block) {
 			kfree(eeprom_buff);
 			return -EIO;
 		}
 	}
 
-	memcpy(data, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
+	memcpy(data, eeprom_buff + eeprom->offset % ax179_data->eeprom_block, eeprom->len);
 	kfree(eeprom_buff);
 	return 0;
 }
@@ -246,12 +272,17 @@ int ax88179_get_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom, u8
 int ax88179_set_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom, u8 *data)
 {
 	struct usbnet *dev = netdev_priv(net);
+	struct ax88179_data *ax179_data;
 	u16 *eeprom_buff;
 	int first_word;
 	int last_word;
 	int ret;
 	int i;
 
+	ax179_data = dev->driver_priv;
+	if (ax179_data->chip_version >= AX_VERSION_AX88179A)
+		return -EOPNOTSUPP;
+
 	netdev_dbg(net, "write EEPROM len %d, offset %d, magic 0x%x\n",
 		   eeprom->len, eeprom->offset, eeprom->magic);
 
Signature · 1 line
2.47.3
#34 lore raw

Re: [PATCH net-next v21 12/13] ax88179_178a: Add support for AX88179A/772D/279 EEPROM access

Sashiko has reviewed this patch and found no issues.
Quoted 7 lines

The AX88179A/772D devices have 32 efuses with 20 bytes each, which can be randomly programmed. The AX88279 has 16K FLASH.

Provide ethtool read capability for these devices. However, no write access is provided.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
#35 lore raw

Re: [PATCH net-next v21 12/13] ax88179_178a: Add support for AX88179A/772D/279 EEPROM access

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

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

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

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 new EEPROM read path builds each vendor request from two sources that are not tied together.
- [Low] This patch quietly closes an EEPROM write path that an earlier commit in this series already opened on AX88179A/772D/279 chips, and…
- [Low] The new comment in ax88179_eeprom_access_params() (drivers/net/usb/ax88179_lib.c) says "AX88279 has an EEPROM…

--

ax88179_178a: Add support for AX88179A/772D/279 EEPROM access

This commit makes ax88179_get_eeprom() chip-aware. It uses a per-device read command and block size, so ethtool can read the AX88179A/772D efuses and the AX88279 flash. It also makes ax88179_set_eeprom() return -EOPNOTSUPP on AX88179A and newer chips.

Quoted 5 lines
drivers/net/usb/ax88179_lib.c +0 -0
index 1523a920f3c38..821ee9cd8ded1 100644

drivers/net/usb/ax88179_lib.c int ax88179_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) · line 219

Quoted 10 lines
drivers/net/usb/ax88179_lib.c +7 -0
@@ -210,35 +210,61 @@ int ax88179_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
 	return 0;
 }
 
+static void
+ax88179_eeprom_access_params(struct ax88179_data *ax179_data, int i, u16 *value, u16 *idx)
+{
+	/* AX88179 has a word-addressable EEPROM
+	 * AX88179A uses EFUSES with 20 bytes length
+	 * AX88279 has an EEPROM addressable in 256 byte blocks
+	 */

[Severity: Low]
This isn't a bug, but is this comment accurate for the AX88279?

The commit message says "The AX88279 has 16K FLASH", and ax88179a_bind() sets up AX88179A_FLASH_READ/AX88179A_FLASH_WRITE for it. The code below also passes a byte offset, not a block number:

	*value = (i * ax179_data->eeprom_block) >> 16;
	*idx = (i * ax179_data->eeprom_block) & 0xffff;

Would it be clearer to describe this as flash read in 256 byte chunks, with a 32-bit byte offset split across wValue/wIndex?

drivers/net/usb/ax88179_lib.c int ax88179_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) · line 230

Quoted 11 lines
drivers/net/usb/ax88179_lib.c +11 -0
+	if (ax179_data->chip_version < AX_VERSION_AX88179A) {
+		*value = i;
+		*idx = 1;
+	} else if (ax179_data->chip_version == AX_VERSION_AX88279) {
+		*value = (i * ax179_data->eeprom_block) >> 16;
+		*idx = (i * ax179_data->eeprom_block) & 0xffff;
+	} else {
+		*value = i << 4;
+		*idx = 0;
+	}
+}

[Severity: Medium]
Can the wValue/wIndex chosen here disagree with the opcode and length used in the same request?

ax88179_get_eeprom() takes eeprom_read_cmd and eeprom_block from whatever the bind function set. This helper, and the new write gate in ax88179_set_eeprom(), branch only on chip_version. That value comes from the hardware as (AX_CHIP_STATUS & 0xf0) >> 4, so it can be 0..15, and nothing validates it.

ax88179_bind() in ax88179_178a.c stores chip_version without checking it and always uses the legacy parameters:

	ax179_data->eeprom_read_cmd = AX_ACCESS_EEPROM;
	ax179_data->eeprom_write_cmd = AX_ACCESS_EEPROM;
	ax179_data->eeprom_block = 2;

That bind handles the generic 0b95:1790 entry, which matches any bcdDevice other than 0x200/0x300/0x400. It also handles all of the OEM IDs.

Suppose an AX88179A-class chip binds this way:

version 6: ethtool -e sends AX_ACCESS_EEPROM with value=i<<4, idx=0,

             len=2

version 7: ethtool -e sends value=(2*i)>>16, idx=2*i

Before this patch, the same device got consistent word reads (value=i, idx=1). On that device, ethtool -E now returns -EOPNOTSUPP, even though bind set up the legacy word-write protocol.

The ax88179a path has the opposite mismatch. ax88179a_get_eeprom_len() uses a >= test:

	if (ax179_data->chip_version >= AX_VERSION_AX88279)
		return AX88279_EEPROM_LEN;

ax88179a_bind() and this helper both test == AX_VERSION_AX88279 instead. A chip code of 8..15 would be reported as 16K of flash. It would then be read with 20-byte efuse requests (value=i<<4) for up to 819 rows, while only 32 rows exist.

A chip code below 6 on the ax88179a path would get value=i, idx=1 with the efuse opcode and a 20-byte length. ax88179_set_eeprom() would also still allow the legacy word writes for it.

Could all of these decisions come from one per-bind setting, for example an access mode stored next to eeprom_block? Alternatively, could bind reject or normalize unexpected chip_version values?

[ ... ]

Quoted 6 lines
drivers/net/usb/ax88179_lib.c +1 -0
@@ -246,12 +272,17 @@ int ax88179_get_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom, u8
 int ax88179_set_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom, u8 *data)
 {
 	struct usbnet *dev = netdev_priv(net);
+	struct ax88179_data *ax179_data;
 	u16 *eeprom_buff;

[ ... ]

drivers/net/usb/ax88179_lib.c int ax88179_get_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom, u8 · line 285

Quoted 4 lines
drivers/net/usb/ax88179_lib.c +4 -0
+	ax179_data = dev->driver_priv;
+	if (ax179_data->chip_version >= AX_VERSION_AX88179A)
+		return -EOPNOTSUPP;
+

[Severity: Low]
This guard changes existing behavior, but the commit message only describes new read support ("no write access is provided"). Should the commit message say that this also closes a write path that already exists?

An earlier patch in this series, "ax88179_178a: Add HW support for AX179A-based chips", already added these to ax88179a_ethtool_ops in ax88179a_devices.c:

	.get_eeprom_len		= ax88179a_get_eeprom_len,
	.get_eeprom		= ax88179_get_eeprom,
	.set_eeprom		= ax88179_set_eeprom,

At that point ax88179a_get_eeprom_len() already reported 640 bytes or 16K. So at every commit between that one and this patch, ethtool -E on an AX88179A/772D/279 runs the legacy word read-modify-write:

ax88179_set_eeprom()
ax88179_write_cmd(dev, AX_ACCESS_EEPROM, i, 1, 2, ...) /* per word */ ax88179_write_cmd(dev, AX_RELOAD_EEPROM_EFUSE, ...)

These parts have efuses or SPI flash, not a word EEPROM. At those commits, ethtool -e also sends legacy AX_ACCESS_EEPROM word reads across the whole advertised range.

Could the series be reordered? One option is to leave .get_eeprom/.set_eeprom out of ax88179a_ethtool_ops until this patch. Another is to move the -EOPNOTSUPP guard into the commit that adds the ops. Either way, a bisect or partial backport would not land on a kernel that can send EEPROM writes and a reload to these parts.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261114-ax88179a-v21-0-c2d34410bcbe%40birger-koblitz.de
#36 lore raw

PATCH v21 13/13 ax88796b: Add support for AX88772D, AX88179A and AX88279

In reply to Birger Koblitz

The AX88772D, AX88179A and AX88279 are 100MBit, 1GBit and respectively 2.5 GBit PHYs that are found in ASIX USB-Ethernet controllers of the same name.

---
 drivers/net/phy/ax88796b.c | 165 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 165 insertions(+)
drivers/net/phy/ax88796b.c +165 -0
index f20ddf64914993f7097070d1f56c1103ec1e40e8..0df44e0e236abb02e16cb7885d0c743f0a2c501d 100644
@@ -13,6 +13,19 @@
 #define PHY_ID_ASIX_AX88772A		0x003b1861
 #define PHY_ID_ASIX_AX88772C		0x003b1881
 #define PHY_ID_ASIX_AX88796B		0x003b1841
+#define PHY_ID_ASIX_AX88772D		0x003b772d
+#define PHY_ID_ASIX_AX88179A		0x003b179a
+#define PHY_ID_ASIX_AX88279		0x003b2790
+
+#define AX_ADVERTISE_2500		0x1000
+
+/* MII Vendor registers */
+#define AX_CTRL_STATUS			0x1d
+#define AX_CTRL_STATUS_SPEED_MASK	0x0c
+#define   AX_CTRL_STATUS_SPEED_10	0x0
+#define   AX_CTRL_STATUS_SPEED_100	0x4
+#define   AX_CTRL_STATUS_SPEED_1000	0x8
+#define   AX_CTRL_STATUS_SPEED_2500	0xc
 
 MODULE_DESCRIPTION("Asix PHY driver");
 MODULE_AUTHOR("Michael Schmitz <[email protected]>");
@@ -83,6 +96,107 @@ static int asix_ax88772a_read_status(struct phy_device *phydev)
 	return 0;
 }
 
+static int asix_ax88279_read_status(struct phy_device *phydev)
+{
+	int ret, val;
+
+	ret = genphy_read_status(phydev);
+	if (ret)
+		return ret;
+
+	if (!phydev->link)
+		return 0;
+
+	/* Read actual speed from vendor register */
+	val = phy_read(phydev, AX_CTRL_STATUS);
+	if (val < 0)
+		return val;
+
+	switch (val & AX_CTRL_STATUS_SPEED_MASK) {
+	case AX_CTRL_STATUS_SPEED_2500:
+		phydev->speed = SPEED_2500;
+		break;
+	case AX_CTRL_STATUS_SPEED_1000:
+		phydev->speed = SPEED_1000;
+		break;
+	case AX_CTRL_STATUS_SPEED_100:
+		phydev->speed = SPEED_100;
+		break;
+	case AX_CTRL_STATUS_SPEED_10:
+		phydev->speed = SPEED_10;
+	}
+
+	/* MDIO_AN_10GBT_STAT_LP2_5G is broken, but we can deduce that
+	 * the link-partner advertised 2500M if remotely AN succceded
+	 * for link speed > 1000M and we locally have a link speed of
+	 * 2500M
+	 */
+	linkmode_clear_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, phydev->lp_advertising);
+	val = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_10GBT_STAT);
+	if (val >= 0 && val & MDIO_AN_10GBT_STAT_REMOK) {
+		linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
+				 phydev->lp_advertising,
+				 phydev->speed == SPEED_2500);
+	}
+	/* Only supports full duplex */
+	phydev->duplex = DUPLEX_FULL;
+
+	/* PHY switches interface between 2.5GBit and slower modes */
+	if (phydev->speed == SPEED_2500)
+		phydev->interface = PHY_INTERFACE_MODE_2500BASEX;
+	else
+		phydev->interface = PHY_INTERFACE_MODE_SGMII;
+
+	return 0;
+}
+
+static int asix_ax88279_config_aneg(struct phy_device *phydev)
+{
+	bool adv_2500;
+	int ret;
+
+	if (phydev->autoneg == AUTONEG_DISABLE) {
+		phydev_warn(phydev, "Disabling autoneg is not supported\n");
+		return -EOPNOTSUPP;
+	}
+
+	adv_2500 = linkmode_test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, phydev->advertising);
+	ret = phy_modify_changed(phydev, MII_ADVERTISE, AX_ADVERTISE_2500,
+				 adv_2500 ? AX_ADVERTISE_2500 : 0);
+	if (ret < 0)
+		return ret;
+
+	return __genphy_config_aneg(phydev, (ret == 1));
+}
+
+static int asix_ax88279_get_features(struct phy_device *phydev)
+{
+	int ret;
+
+	/* MDIO_DEVS1/2 empty, so set mmds_present bits to allow reading abilities */
+	phydev->c45_ids.mmds_present |= MDIO_DEVS_PMAPMD | MDIO_DEVS_AN;
+
+	linkmode_set_bit_array(phy_basic_ports_array, ARRAY_SIZE(phy_basic_ports_array),
+			       phydev->supported);
+
+	ret = genphy_c45_pma_read_abilities(phydev);
+	if (ret < 0)
+		return ret;
+
+	/* AX88279 does not support reported 100baseT-half duplex mode */
+	linkmode_clear_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT, phydev->supported);
+
+	return 0;
+}
+
+static int asix_ax88279_config_init(struct phy_device *phydev)
+{
+	__set_bit(PHY_INTERFACE_MODE_2500BASEX, phydev->possible_interfaces);
+	__set_bit(PHY_INTERFACE_MODE_SGMII, phydev->possible_interfaces);
+
+	return 0;
+}
+
 static void asix_ax88772a_link_change_notify(struct phy_device *phydev)
 {
 	/* Reset PHY, otherwise MII_LPA will provide outdated information.
@@ -94,6 +208,25 @@ static void asix_ax88772a_link_change_notify(struct phy_device *phydev)
 	}
 }
 
+static int asix_ax88772D_get_features(struct phy_device *phydev)
+{
+	int ret;
+
+	/* MDIO_DEVS1/2 empty, so set mmds_present bits to allow reading abilities */
+	phydev->c45_ids.mmds_present |= MDIO_DEVS_PMAPMD | MDIO_DEVS_AN;
+
+	ret = genphy_read_abilities(phydev);
+	if (ret < 0)
+		return ret;
+
+	/* AX88772D does not support (possibly) reported 1000baseT modes */
+	linkmode_clear_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, phydev->supported);
+	linkmode_clear_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT, phydev->supported);
+	linkmode_clear_bit(ETHTOOL_LINK_MODE_1000baseX_Full_BIT, phydev->supported);
+
+	return 0;
+}
+
 static struct phy_driver asix_driver[] = {
 {
 	PHY_ID_MATCH_EXACT(PHY_ID_ASIX_AX88772A),
@@ -111,6 +244,35 @@ static struct phy_driver asix_driver[] = {
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
 	.soft_reset	= asix_soft_reset,
+}, {
+	PHY_ID_MATCH_EXACT(PHY_ID_ASIX_AX88772D),
+	.name		= "Asix Electronics AX88772D",
+	.flags		= PHY_IS_INTERNAL,
+	.get_features	= asix_ax88772D_get_features,
+	.read_mmd	= genphy_read_mmd_c45,
+	.write_mmd	= genphy_write_mmd_c45,
+	.suspend	= genphy_suspend,
+	.resume		= genphy_resume,
+}, {
+	PHY_ID_MATCH_EXACT(PHY_ID_ASIX_AX88179A),
+	.name		= "Asix Electronics AX88179A",
+	.flags		= PHY_IS_INTERNAL,
+	.suspend	= genphy_suspend,
+	.resume		= genphy_resume,
+	.read_mmd	= genphy_read_mmd_c45,
+	.write_mmd	= genphy_write_mmd_c45,
+}, {
+	PHY_ID_MATCH_EXACT(PHY_ID_ASIX_AX88279),
+	.name		= "Asix Electronics AX88279",
+	.flags		= PHY_IS_INTERNAL | PHY_BROKEN_FORCED,
+	.get_features	= asix_ax88279_get_features,
+	.read_status	= asix_ax88279_read_status,
+	.config_aneg	= asix_ax88279_config_aneg,
+	.config_init	= asix_ax88279_config_init,
+	.read_mmd	= genphy_read_mmd_c45,
+	.write_mmd	= genphy_write_mmd_c45,
+	.suspend	= genphy_suspend,
+	.resume		= genphy_resume,
 }, {
 	PHY_ID_MATCH_MODEL(PHY_ID_ASIX_AX88796B),
 	.name		= "Asix Electronics AX88796B",
@@ -124,6 +286,9 @@ static const struct mdio_device_id __maybe_unused asix_tbl[] = {
 	{ PHY_ID_MATCH_EXACT(PHY_ID_ASIX_AX88772A) },
 	{ PHY_ID_MATCH_EXACT(PHY_ID_ASIX_AX88772C) },
 	{ PHY_ID_MATCH_MODEL(PHY_ID_ASIX_AX88796B) },
+	{ PHY_ID_MATCH_EXACT(PHY_ID_ASIX_AX88772D) },
+	{ PHY_ID_MATCH_EXACT(PHY_ID_ASIX_AX88179A) },
+	{ PHY_ID_MATCH_EXACT(PHY_ID_ASIX_AX88279) },
 	{ }
 };
 
Signature · 1 line
2.47.3
#37 lore raw

Re: [PATCH net-next v21 13/13] ax88796b: Add support for AX88772D, AX88179A and AX88279

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] net: phy: ax88796b: broken 2.5G LPA and pause in asix_ax88279_read_status() --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] net: phy: ax88796b: broken 2.5G LPA and pause in asix_ax88279_read_status()
--

commit bae79c8bab2ee5c87d5267f24efcefa71548bd4c
Author: Birger Koblitz <[email protected]>

ax88796b: Add support for AX88772D, AX88179A and AX88279

This commit adds PHY driver support for the ASIX AX88772D (100Mbps), AX88179A (1Gbps), and AX88279 (2.5Gbps) internal Ethernet PHYs.

Quoted 4 lines
drivers/net/phy/ax88796b.c +0 -0
index f20ddf6491499..0df44e0e236ab 100644

[ ... ]

Quoted 47 lines
drivers/net/phy/ax88796b.c +43 -0
@@ -83,6 +96,107 @@ static int asix_ax88772a_read_status(struct phy_device *phydev)
 	return 0;
 }
 
+static int asix_ax88279_read_status(struct phy_device *phydev)
+{
+	int ret, val;
+
+	ret = genphy_read_status(phydev);
+	if (ret)
+		return ret;
+
+	if (!phydev->link)
+		return 0;
+
+	/* Read actual speed from vendor register */
+	val = phy_read(phydev, AX_CTRL_STATUS);
+	if (val < 0)
+		return val;
+
+	switch (val & AX_CTRL_STATUS_SPEED_MASK) {
+	case AX_CTRL_STATUS_SPEED_2500:
+		phydev->speed = SPEED_2500;
+		break;
+	case AX_CTRL_STATUS_SPEED_1000:
+		phydev->speed = SPEED_1000;
+		break;
+	case AX_CTRL_STATUS_SPEED_100:
+		phydev->speed = SPEED_100;
+		break;
+	case AX_CTRL_STATUS_SPEED_10:
+		phydev->speed = SPEED_10;
+	}
+
+	/* MDIO_AN_10GBT_STAT_LP2_5G is broken, but we can deduce that
+	 * the link-partner advertised 2500M if remotely AN succceded
+	 * for link speed > 1000M and we locally have a link speed of
+	 * 2500M
+	 */
+	linkmode_clear_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, phydev->lp_advertising);
+	val = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_10GBT_STAT);
+	if (val >= 0 && val & MDIO_AN_10GBT_STAT_REMOK) {
+		linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
+				 phydev->lp_advertising,
+				 phydev->speed == SPEED_2500);
+	}
+	/* Only supports full duplex */

drivers/net/phy/ax88796b.c static int asix_ax88772a_read_status(struct phy_device *phydev) · line 151

Quoted 10 lines
drivers/net/phy/ax88796b.c +10 -0
+	phydev->duplex = DUPLEX_FULL;
+
+	/* PHY switches interface between 2.5GBit and slower modes */
+	if (phydev->speed == SPEED_2500)
+		phydev->interface = PHY_INTERFACE_MODE_2500BASEX;
+	else
+		phydev->interface = PHY_INTERFACE_MODE_SGMII;
+
+	return 0;
+}

[Severity: Medium]
Does updating phydev->lp_advertising and phydev->duplex after genphy_read_status() leave pause resolution and 2.5G link-partner advertising broken?

genphy_read_status() resets phydev->duplex to DUPLEX_UNKNOWN and phydev->pause / phydev->asym_pause to false, then calls phy_resolve_aneg_linkmode(). When 2500baseT_Full is the only common advertised speed mode (for example, when local advertisement is restricted to 2500baseT/Full via ethtool), ETHTOOL_LINK_MODE_2500baseT_Full_BIT is not yet set in phydev->lp_advertising during genphy_read_status(), so phy_caps_lookup_by_linkmode() fails and phydev->duplex remains DUPLEX_UNKNOWN when phy_resolve_aneg_pause() runs:

drivers/net/phy/phy-core.c:phy_resolve_aneg_pause() {
	if (phydev->duplex == DUPLEX_FULL) {
		phydev->pause = linkmode_test_bit(ETHTOOL_LINK_MODE_Pause_BIT,
						  phydev->lp_advertising);
		phydev->asym_pause = linkmode_test_bit(
			ETHTOOL_LINK_MODE_Asym_Pause_BIT,
			phydev->lp_advertising);
	}
}

Setting phydev->duplex = DUPLEX_FULL later without calling phy_resolve_aneg_pause(phydev) leaves negotiated pause flow control disabled.

Also, returning early on !phydev->link before clearing ETHTOOL_LINK_MODE_2500baseT_Full_BIT leaves that bit stale in phydev->lp_advertising when a 2.5G link drops, because genphy_read_lpa() only clears Clause 22 MII_LPA and MII_STAT1000 bits. Finally, if phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_10GBT_STAT) returns a negative error, the error is ignored rather than returned to phy_check_link_status().

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13
#38 lore raw

Re: [PATCH net-next v21 13/13] ax88796b: Add support for AX88772D, AX88179A and AX88279

In reply to Birger Koblitz
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.

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

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

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 three new PHY IDs (AX88772D 0x003b772d, AX88179A 0x003b179a, AX88279 0x003b2790) are added only to the C driver…
- [Medium] In asix_ax88279_read_status(), the 2500baseT_Full bit in phydev->lp_advertising is cleared and recomputed only after the `if…
- [Low] In asix_ax88772D_get_features() (drivers/net/phy/ax88796b.c, line 215-216), `phydev->c45_ids.mmds_present |= MDIO_DEVS_PMAPMD |…
- [Low] asix_ax88279_read_status() always sets phydev->duplex = DUPLEX_FULL (line 142) with the comment "Only supports full duplex".
- [Low] asix_ax88772D_get_features() removes 1000baseT_Full/1000baseT_Half/1000baseX_Full from phydev->supported…

--

ax88796b: Add support for AX88772D, AX88179A and AX88279

This adds PHY IDs and driver entries for the internal PHYs of the ASIX AX88772D, AX88179A and AX88279 USB Ethernet controllers. The AX88279 gets its own get_features, config_aneg, read_status and config_init callbacks. They handle 2.5G advertisement, read the speed from a vendor register, and switch the interface between SGMII and 2500BASE-X.

Quoted 4 lines
drivers/net/phy/ax88796b.c +0 -0
index f20ddf6491499..0df44e0e236ab 100644

[ ... ]

Quoted 14 lines
drivers/net/phy/ax88796b.c +10 -0
@@ -83,6 +96,107 @@ static int asix_ax88772a_read_status(struct phy_device *phydev)
 	return 0;
 }
 
+static int asix_ax88279_read_status(struct phy_device *phydev)
+{
+	int ret, val;
+
+	ret = genphy_read_status(phydev);
+	if (ret)
+		return ret;
+
+	if (!phydev->link)
+		return 0;

[ ... ]

drivers/net/phy/ax88796b.c static int asix_ax88772a_read_status(struct phy_device *phydev) · line 140

Quoted 7 lines
drivers/net/phy/ax88796b.c +7 -0
+	linkmode_clear_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, phydev->lp_advertising);
+	val = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_10GBT_STAT);
+	if (val >= 0 && val & MDIO_AN_10GBT_STAT_REMOK) {
+		linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
+				 phydev->lp_advertising,
+				 phydev->speed == SPEED_2500);
+	}

[Severity: Medium]
Can the 2500baseT_Full bit that is set here stay in lp_advertising after the link goes down?

This is the only place in asix_ax88279_read_status() that clears it, and it comes after the early return on !phydev->link.

When a 2.5G link drops, genphy_read_status()->genphy_read_lpa() runs with autoneg_complete false. That path only clears the C22 and 1000BASE-T partner bits:

drivers/net/phy/phy_device.c:genphy_read_lpa() {
    ...
		if (!phydev->autoneg_complete) {
			mii_stat1000_mod_linkmode_lpa_t(phydev->lp_advertising,
							0);
			mii_lpa_mod_linkmode_lpa_t(phydev->lp_advertising, 0);
			return 0;
		}
    ...
}

The driver then returns before it gets to this linkmode_clear_bit(). As a result, ethtool would show the link partner advertising 2500baseT/Full while the link is down.

On the next link-up, phy_resolve_aneg_linkmode() also runs with the stale bit still set. The AX_CTRL_STATUS read afterwards does correct the final speed.

Should the bit be cleared before the !phydev->link check?

Quoted 2 lines
drivers/net/phy/ax88796b.c +2 -0
+	/* Only supports full duplex */
+	phydev->duplex = DUPLEX_FULL;

[ ... ]

Quoted 6 lines
drivers/net/phy/ax88796b.c +6 -0
+static int asix_ax88279_get_features(struct phy_device *phydev)
+{
+	int ret;
+
+	/* MDIO_DEVS1/2 empty, so set mmds_present bits to allow reading abilities */
+	phydev->c45_ids.mmds_present |= MDIO_DEVS_PMAPMD | MDIO_DEVS_AN;

drivers/net/phy/ax88796b.c static int asix_ax88772a_read_status(struct phy_device *phydev) · line 187

Quoted 10 lines
drivers/net/phy/ax88796b.c +10 -0
+
+	linkmode_set_bit_array(phy_basic_ports_array, ARRAY_SIZE(phy_basic_ports_array),
+			       phydev->supported);
+
+	ret = genphy_c45_pma_read_abilities(phydev);
+	if (ret < 0)
+		return ret;
+
+	/* AX88279 does not support reported 100baseT-half duplex mode */
+	linkmode_clear_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT, phydev->supported);

[Severity: Low]
Should 10baseT_Half be cleared here too?

genphy_c45_pma_read_ext_abilities() sets both 10baseT_Full and 10baseT_Half from the single MDIO_PMA_EXTABLE_10BT bit. 10M also looks supported, since asix_ax88279_read_status() decodes AX_CTRL_STATUS_SPEED_10.

However, asix_ax88279_read_status() always reports full duplex:

	/* Only supports full duplex */
	phydev->duplex = DUPLEX_FULL;

If 10baseT_Half ends up in advertising, genphy_config_advert() writes ADVERTISE_10HALF. A partner that only does 10M half duplex would then resolve to 10/half while the driver reports full duplex.

The in-tree consumer, ax88179a_phylink_setup() in drivers/net/usb/ax88179a_devices.c, does not give the AX88279 MAC_10. phylink_bringup_phy() also replaces the PHY advertising with the validated mask. So this cannot be hit through that driver today, but the supported mask still disagrees with what read_status reports.

Quoted 3 lines
drivers/net/phy/ax88796b.c +3 -0
+
+	return 0;
+}

[ ... ]

drivers/net/phy/ax88796b.c static void asix_ax88772a_link_change_notify(struct phy_device *phydev) · line 218

Quoted 12 lines
drivers/net/phy/ax88796b.c +8 -0
@@ -94,6 +208,25 @@ static void asix_ax88772a_link_change_notify(struct phy_device *phydev)
 	}
 }
 
+static int asix_ax88772D_get_features(struct phy_device *phydev)
+{
+	int ret;
+
+	/* MDIO_DEVS1/2 empty, so set mmds_present bits to allow reading abilities */
+	phydev->c45_ids.mmds_present |= MDIO_DEVS_PMAPMD | MDIO_DEVS_AN;
+
+	ret = genphy_read_abilities(phydev);

[Severity: Low]
This isn't a bug, but is the mmds_present assignment needed here?

genphy_read_abilities() is the C22 helper and never reads mmds_present. In the tree, mmds_present is only read by genphy_c45_pma_read_abilities(), genphy_c45_read_link() and phylink's C45 ioctl emulation. None of those are on the AX88772D path.

It looks copied from asix_ax88279_get_features(), which does call genphy_c45_pma_read_abilities(). Here the comment does not match what the code does.

drivers/net/phy/ax88796b.c static void asix_ax88772a_link_change_notify(struct phy_device *phydev) · line 225

Quoted 7 lines
drivers/net/phy/ax88796b.c +7 -0
+	if (ret < 0)
+		return ret;
+
+	/* AX88772D does not support (possibly) reported 1000baseT modes */
+	linkmode_clear_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, phydev->supported);
+	linkmode_clear_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT, phydev->supported);
+	linkmode_clear_bit(ETHTOOL_LINK_MODE_1000baseX_Full_BIT, phydev->supported);

[Severity: Low]
Can supported_eee keep 1000baseT_Full after these bits are cleared?

genphy_read_abilities() has already called genphy_c45_read_eee_abilities(). That masks supported_eee against supported as supported was at that point:

drivers/net/phy/phy-c45.c:genphy_c45_read_eee_cap1() {
    ...
	linkmode_and(phydev->supported_eee, phydev->supported_eee,
		     phydev->supported);
    ...
}

If ESTATUS reported 1000BT, that mask still includes 1000baseT_Full. Nothing trims supported_eee again afterwards, and phy_probe() only ANDs advertising_eee with supported_eee.

With ax88179a_phylink_setup() no lpi_capabilities are set for AX88772D, so phylink calls phy_disable_eee() and this does not show up today. Would it make sense to also clear the 1000BASE-T EEE modes from supported_eee here?

Quoted 3 lines
drivers/net/phy/ax88796b.c +3 -0
+
+	return 0;
+}

[ ... ]

drivers/net/phy/ax88796b.c static const struct mdio_device_id __maybe_unused asix_tbl[] = { · line 293

Quoted 9 lines
drivers/net/phy/ax88796b.c +3 -0
@@ -124,6 +286,9 @@ static const struct mdio_device_id __maybe_unused asix_tbl[] = {
 	{ PHY_ID_MATCH_EXACT(PHY_ID_ASIX_AX88772A) },
 	{ PHY_ID_MATCH_EXACT(PHY_ID_ASIX_AX88772C) },
 	{ PHY_ID_MATCH_MODEL(PHY_ID_ASIX_AX88796B) },
+	{ PHY_ID_MATCH_EXACT(PHY_ID_ASIX_AX88772D) },
+	{ PHY_ID_MATCH_EXACT(PHY_ID_ASIX_AX88179A) },
+	{ PHY_ID_MATCH_EXACT(PHY_ID_ASIX_AX88279) },
 	{ }
 };

[Severity: Medium]
What happens to these PHYs when CONFIG_AX88796B_RUST_PHY=y?

drivers/net/phy/Makefile builds only one of the two drivers:

ifdef CONFIG_AX88796B_RUST_PHY
obj-$(CONFIG_AX88796B_PHY) += ax88796b_rust.o
else
obj-$(CONFIG_AX88796B_PHY) += ax88796b.o
endif

drivers/net/phy/ax88796b_rust.rs still registers only:

    drivers: [PhyAX88772A, PhyAX88772C, PhyAX88796B],

In that configuration, the IDs reported by ax88179_mdiobus_read() in drivers/net/usb/ax88179a_devices.c would bind to the Generic PHY driver. The AX88279 would then lose:

- the C45 2.5G ability read
- the AX_ADVERTISE_2500 write
- the AX_CTRL_STATUS speed decoding
- the SGMII/2500BASE-X interface switching

The AX88796B_RUST_PHY help text in drivers/net/phy/Kconfig also still says:

The features are equivalent. It supports the Asix Electronics PHY found in the X-Surf 100 AX88796B package.

The AX88796B_PHY help text still describes only the X-Surf 100 AX88796B PHY.

Should the Rust driver get matching entries, or should Kconfig be updated to reflect the difference?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261114-ax88179a-v21-0-c2d34410bcbe%40birger-koblitz.de
#39 lore raw
In reply to Birger Koblitz
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 13 lines · On Sat, 14 Nov 2026 11:50:56 +0100 you wrote:

This adds support for the current generation of ASIX network adapter chips, which are based on the AX88179A. This includes the AX88179A/B (1GBit-PHY), AX88772D/E (100MBit) and AX88279 (2.5GBit).

The AX179A-based chips all provide both a CDC-NCM compatible USB interface, and a proprietary vendor interface with more features. By default, the proprietary vendor interface is not active and Linux will load the CDC-NCM driver to support the devices. If the ax88179_178a module is configured by the OS to have precedence over CDC-NCM, then this driver will switch the device to use the vendor interface, and the device will be controlled by the ax88179_178a driver when the device is probed again after an automatic reset of the device bringing up the vendor interface.

Quoted 1 line

[...]

Here is the summary with links:
- [net-next,v21,01/13] phylink: Add phylink_mac_interrupt

    https://git.kernel.org/netdev/net-next/c/525e055f026b
  - [net-next,v21,02/13] phylib: Add support for PHYs with broken forced mode
    https://git.kernel.org/netdev/net-next/c/73f8fcee8453
  - [net-next,v21,03/13] ax88179_178a: Split driver into library and device specific code
    https://git.kernel.org/netdev/net-next/c/aadb4048a412
  - [net-next,v21,04/13] ax88179_178a: Add HW support for AX179A-based chips
    https://git.kernel.org/netdev/net-next/c/7d573278f9a5
  - [net-next,v21,05/13] ax88179_178a: Add EEE configuration support for AX88179A MACs
    https://git.kernel.org/netdev/net-next/c/ac12cbe7b385
  - [net-next,v21,06/13] ax88179_178a: Add EEE configuration support for AX88179A PHYs
    https://git.kernel.org/netdev/net-next/c/4ae4234e779c
  - [net-next,v21,07/13] ax88179_178a: Add VLAN offload support for AX88179A
    https://git.kernel.org/netdev/net-next/c/faea93a5239c
  - [net-next,v21,08/13] ax88179_178a: Add AX179A/AX279 multicast configuration
    https://git.kernel.org/netdev/net-next/c/192c7b09608a
  - [net-next,v21,09/13] ax88179_178a: Add Suspend/resume support for AX88179A/772D/279
    https://git.kernel.org/netdev/net-next/c/24543aeed42f
  - [net-next,v21,10/13] ax88179_178a: Add ethtool get_drvinfo
    https://git.kernel.org/netdev/net-next/c/8d405df176e1
  - [net-next,v21,11/13] ax88179_178a: Update driver name and information
    https://git.kernel.org/netdev/net-next/c/d7e3ce733ae3
  - [net-next,v21,12/13] ax88179_178a: Add support for AX88179A/772D/279 EEPROM access
    https://git.kernel.org/netdev/net-next/c/bfa4a3adf638
  - [net-next,v21,13/13] ax88796b: Add support for AX88772D, AX88179A and AX88279
    https://git.kernel.org/netdev/net-next/c/8cacc4fd1518

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html