[PATCH net-next v13 13/14] ax88179_178a: Add support for AX88179A/772D/279 EEPROM access
From: Birger Koblitz <hidden>
Date: 2026-09-27 09:44:04
Also in:
linux-usb, lkml, loongarch
Subsystem:
networking drivers, the rest, usb networking drivers · Maintainers:
Andrew Lunn, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds
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. Signed-off-by: Birger Koblitz <redacted> Reviewed-by: Andrew Lunn <andrew@lunn.ch> --- drivers/net/usb/ax88179_178a.c | 6 +++++ drivers/net/usb/ax88179_lib.c | 56 ++++++++++++++++++++++++++++++++---------- 2 files changed, 49 insertions(+), 13 deletions(-)
diff --git a/drivers/net/usb/ax88179_178a.c b/drivers/net/usb/ax88179_178a.c
index 8b52994e2a604101b61ec9cc0d698a0ecb520a14..7ec71438054844c7263c82ca911e42ea5854a682 100644
--- a/drivers/net/usb/ax88179_178a.c
+++ b/drivers/net/usb/ax88179_178a.c@@ -724,6 +724,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)
diff --git a/drivers/net/usb/ax88179_lib.c b/drivers/net/usb/ax88179_lib.c
index 6f32d4da601ca11d19cf428ecb79206ab4460f3e..de849650f7871022290fc1ba3e3d463434e42fbe 100644
--- a/drivers/net/usb/ax88179_lib.c
+++ b/drivers/net/usb/ax88179_lib.c@@ -210,36 +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_array(last_word - first_word + 1, sizeof(u16), - GFP_KERNEL); + 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; }
@@ -247,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);
--
2.47.3