Skip to contentSkip to conversation

net: phy: aquantia: Switch to generic firmware loader

PATCH Superseded Beiyan Yun 3 participants 10 messages Oct 14, 2025 – Oct 30, 2025

Subsystems (3)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Beiyan Yun

author
#0 lore raw

v3 cover net: phy: aquantia: Switch to generic firmware loader

Hi,

This patch series refactors the Aquantia PHY firmware loader to use the generic fsloader framework.

The existing loader is limited to loading firmware from an MMC device, which restricts its use on many devices (e.g., routers) that may use other storage like USB or have a UBIFS root filesystem. Migrating to the generic firmware loader allows firmware to be sourced from any backend supported by the fwloader and fsloader framework.

The series is structured as follows:
- The first patch is a minor cleanup, switching to the phy_get_ofnode() helper.
- The second patch aligns binding document with upstream and prepares for the migration.
- The third patch aligns binding for MDI with upstream.
- The final and main patch replaces the custom loader with generic one.

Kept smb-addr intact as NXP is the only consumer.

This change has been tested on a Buffalo WXR18000BE10P router, loading firmware from a UBIFS volume for Marvell CUX3410.

Changes in v3:
- Select FW_LOADER with PHY_AQUANTIA_UPLOAD_FW

Changes in v2:
- doc: bindings: use upstream bindings for aquantia phy
- net: phy: aquantia: replace the "mdi-reversal" node with "marvell,mdi-cfg-order"
- Add support for script based loader

Beiyan Yun (4):
net: phy: aquantia: switch to use phy_get_ofnode()
doc: bindings: use upstream bindings for aquantia phy
net: phy: aquantia: replace the "mdi-reversal" node with
"marvell,mdi-cfg-order"
net: phy: aquantia: use generic firmware loader

 arch/arm/dts/fsl-sch-30841.dtsi               |   8 +-
 arch/arm/dts/fsl-sch-30842.dtsi               |   2 +-
 doc/device-tree-bindings/net/aquantia-phy.txt |  15 +-
 drivers/net/phy/Kconfig                       |  24 +--
 drivers/net/phy/aquantia.c                    | 139 ++++++++++--------
 5 files changed, 99 insertions(+), 89 deletions(-)
Signature · 4 lines
2.47.3

base-commit: 48f21e66e360552c75d70a50421d0e0ed1f59e90
branch: aquantia-fsloader-v3
author
#1 lore raw

PATCH v3 1/4 net: phy: aquantia: switch to use phy_get_ofnode()

Use PHY API phy_get_ofnode() helper to get PHY DT node.

---

(no changes since v1)

 drivers/net/phy/aquantia.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/phy/aquantia.c +1 -1
index f63a13824ca..903fcd667f6 100644
@@ -338,7 +338,7 @@ static int aquantia_set_proto(struct phy_device *phydev,
 
 static int aquantia_dts_config(struct phy_device *phydev)
 {
-	ofnode node = phydev->node;
+	ofnode node = phy_get_ofnode(phydev);
 	u32 prop;
 	u16 reg;
 
Signature · 1 line
2.47.3
author
#2 lore raw

PATCH v3 2/4 doc: bindings: use upstream bindings for aquantia phy

In reply to Beiyan Yun

Prepare for the switch to upstream bindings and generic firmware loader, remove reference to upstreamed bindings, also add a firmware-name example.

---

(no changes since v2)

Changes in v2:
- New

 doc/device-tree-bindings/net/aquantia-phy.txt | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)
doc/device-tree-bindings/net/aquantia-phy.txt +3 -12
index 89ce61e05bb..80de0e8b158 100644
@@ -1,25 +1,16 @@
 PHY nodes for Aquantia devices.
 
 This text describes properties that are applicable to Aquantia PHY nodes in
-addition to the bindings in phy.txt.
-
-Aquantia PHYs allow some flexibility in the way they are wired in a system,
-they allow MDI pins to be reversed, LEDs linked up in different weays, have an
-I2C slave interface that can be used for debug.  Normally the configuration
-corresponding to these is driven by the PHY firmware with the downside that
-a custom firmware is needed for each integration of a PHY.
-Several optional bindings are defined that allow these configuration points to
-be driven by the PHY driver and reduce dependency on specific FW versions.
+addition to the bindings in upstream and phy.txt.
 
 Optional properties:
-mdi-reversal: 0 or 1 indicating that reversal must be disabled/enabled.
-              Firmware default is used if the property is missing.
 smb-addr:     I2C/SMBus address to use, firmware default is used if the property
               is missing.
 
 Example node:
 phy@00 {
 	reg = <0x00>;
-	mdi-reversal = <1>;
+	marvell,mdi-cfg-order = <1>;
 	smb-addr = <0x25>;
+	firmware-name = "aqr-firmware.cld";
 };
Signature · 1 line
2.47.3
author
#3 lore raw

PATCH v3 3/4 net: phy: aquantia: replace the "mdi-reversal" node with "marvell, mdi-cfg-order"

In reply to Beiyan Yun

As part of the effort of making U-Boot work with the same device tree as Linux, align with upstream node name.

---

(no changes since v2)

Changes in v2:
- New

 arch/arm/dts/fsl-sch-30841.dtsi | 8 ++++----
 arch/arm/dts/fsl-sch-30842.dtsi | 2 +-
 drivers/net/phy/aquantia.c      | 4 ++--
 3 files changed, 7 insertions(+), 7 deletions(-)
arch/arm/dts/fsl-sch-30841.dtsi +4 -4
index 28b1bec18a5..a92d9811fd3 100644
@@ -15,24 +15,24 @@
  */
 phy@00 {
 	reg = <0x00>;
-	mdi-reversal = <1>;
+	marvell,mdi-cfg-order = <1>;
 	smb-addr = <0x25>;
 };
 
 phy@01 {
 	reg = <0x01>;
-	mdi-reversal = <1>;
+	marvell,mdi-cfg-order = <1>;
 	smb-addr = <0x26>;
 };
 
 phy@02 {
 	reg = <0x02>;
-	mdi-reversal = <1>;
+	marvell,mdi-cfg-order = <1>;
 	smb-addr = <0x27>;
 };
 
 phy@03 {
 	reg = <0x03>;
-	mdi-reversal = <1>;
+	marvell,mdi-cfg-order = <1>;
 	smb-addr = <0x28>;
 };
arch/arm/dts/fsl-sch-30842.dtsi +1 -1
index bff9e76570b..fca38d14975 100644
@@ -13,6 +13,6 @@
  */
 phy@02 {
 	reg = <0x02>;
-	mdi-reversal = <1>;
+	marvell,mdi-cfg-order = <1>;
 	smb-addr = <0x25>;
 };
drivers/net/phy/aquantia.c +2 -2
index 903fcd667f6..d9df0e23a45 100644
@@ -350,8 +350,8 @@ static int aquantia_dts_config(struct phy_device *phydev)
 	if (!ofnode_valid(node))
 		return 0;
 
-	if (!ofnode_read_u32(node, "mdi-reversal", &prop)) {
-		debug("mdi-reversal = %d\n", (int)prop);
+	if (!ofnode_read_u32(node, "marvell,mdi-cfg-order", &prop)) {
+		debug("marvell,mdi-cfg-order = %d\n", (int)prop);
 		reg =  phy_read(phydev, MDIO_MMD_PMAPMD,
 				AQUANTIA_PMA_RX_VENDOR_P1);
 		reg &= ~AQUANTIA_PMA_RX_VENDOR_P1_MDI_MSK;
Signature · 1 line
2.47.3
author
#4 lore raw

PATCH v3 4/4 net: phy: aquantia: use generic firmware loader

In reply to Beiyan Yun

Aquantia PHYs are being used w/o SPI flash in some routers recently. Current firmware loader only attempts to load from FS on top of MMC, limiting the use on many devices.

Removed the old firmware loader, migrate to generic firmware loader to allow a wider range and runtime override of firmware source. (e.g., USB).

Tested on Buffalo WXR18000BE10P with UBIFS.

---

Changes in v3:
- Select FW_LOADER with PHY_AQUANTIA_UPLOAD_FW

Changes in v2:
- Add support for script based loader

 drivers/net/phy/Kconfig    |  24 ++++---
 drivers/net/phy/aquantia.c | 133 ++++++++++++++++++++-----------------
 2 files changed, 88 insertions(+), 69 deletions(-)
drivers/net/phy/Kconfig +15 -9
index 185c6a3156e..68765290671 100644
@@ -1,4 +1,3 @@
-
 config BITBANGMII
 	bool "Bit-banged ethernet MII management channel support"
 
@@ -90,23 +89,30 @@ menuconfig PHY_AQUANTIA
 config PHY_AQUANTIA_UPLOAD_FW
 	bool "Aquantia firmware loading support"
 	depends on PHY_AQUANTIA
+	select FS_LOADER
+	select FW_LOADER
 	help
 		Aquantia PHYs use firmware which can be either loaded automatically
 		from storage directly attached to the phy or loaded by the boot loader
-		via MDIO commands.  The firmware is loaded from a file, specified by
-		the PHY_AQUANTIA_FW_PART and PHY_AQUANTIA_FW_NAME options.
+		via MDIO commands.
+
+		This option enables loading the firmware using the generic
+		file system firmware loader framework.
 
-config PHY_AQUANTIA_FW_PART
-	string "Aquantia firmware partition"
+config PHY_AQUANTIA_FW_MAX_SIZE
+	hex "Max firmware size"
 	depends on PHY_AQUANTIA_UPLOAD_FW
+	default 0x80000
 	help
-		Partition containing the firmware file.
+	  The maximum size of the Aquantia PHY firmware. This is used to
+	  allocate a buffer to load the firmware into.
 
-config PHY_AQUANTIA_FW_NAME
-	string "Aquantia firmware filename"
+config PHY_AQUANTIA_FW_LOADER_SCRIPT
+	string "Aquantia firmware loader script"
 	depends on PHY_AQUANTIA_UPLOAD_FW
+	default "aqr_phy_load_firmware"
 	help
-		Firmware filename.
+		The firmware loading script variable name.
 
 config PHY_ATHEROS
 	bool "Atheros Ethernet PHYs support"
drivers/net/phy/aquantia.c +73 -60

181 lines not on this page · raw message

Signature · 1 line
2.47.3
#5 lore raw

Re: [PATCH v3 4/4] net: phy: aquantia: use generic firmware loader

Hi Beiyan,

Quoted 102 lines · Beiyan Yun

External email : Please do not click links or open attachments until you have verified the sender or the content.

Aquantia PHYs are being used w/o SPI flash in some routers recently. Current firmware loader only attempts to load from FS on top of MMC, limiting the use on many devices.

Removed the old firmware loader, migrate to generic firmware loader to
allow a wider range and runtime override of firmware source. (e.g., USB).

Tested on Buffalo WXR18000BE10P with UBIFS.

---

Changes in v3:
- Select FW_LOADER with PHY_AQUANTIA_UPLOAD_FW

Changes in v2:
- Add support for script based loader

 drivers/net/phy/Kconfig    |  24 ++++---
 drivers/net/phy/aquantia.c | 133 ++++++++++++++++++++---------------
--
 2 files changed, 88 insertions(+), 69 deletions(-)
drivers/net/phy/Kconfig +2 -1
index 185c6a3156e..68765290671 100644
@@ -1,4 +1,3 @@
-
 config BITBANGMII
        bool "Bit-banged ethernet MII management channel support"
 
@@ -90,23 +89,30 @@ menuconfig PHY_AQUANTIA
 config PHY_AQUANTIA_UPLOAD_FW
        bool "Aquantia firmware loading support"
        depends on PHY_AQUANTIA
+       select FS_LOADER
+       select FW_LOADER
        help
                Aquantia PHYs use firmware which can be either loaded

automatically
from storage directly attached to the phy or loaded
by the boot loader
- via MDIO commands. The firmware is loaded from a
file, specified by
- the PHY_AQUANTIA_FW_PART and PHY_AQUANTIA_FW_NAME
options.

drivers/net/phy/Kconfig +3 -0
+               via MDIO commands.
+
+               This option enables loading the firmware using the

generic

drivers/net/phy/Kconfig +5 -3
+               file system firmware loader framework.
 
-config PHY_AQUANTIA_FW_PART
-       string "Aquantia firmware partition"
+config PHY_AQUANTIA_FW_MAX_SIZE
+       hex "Max firmware size"
        depends on PHY_AQUANTIA_UPLOAD_FW
+       default 0x80000
        help
-               Partition containing the firmware file.
+         The maximum size of the Aquantia PHY firmware. This is used

to

drivers/net/phy/Kconfig +5 -3
+         allocate a buffer to load the firmware into.
 
-config PHY_AQUANTIA_FW_NAME
-       string "Aquantia firmware filename"
+config PHY_AQUANTIA_FW_LOADER_SCRIPT
+       string "Aquantia firmware loader script"
        depends on PHY_AQUANTIA_UPLOAD_FW
+       default "aqr_phy_load_firmware"
        help
-               Firmware filename.
+               The firmware loading script variable name.
 
 config PHY_ATHEROS
        bool "Atheros Ethernet PHYs support"
drivers/net/phy/aquantia.c +4 -0
index d9df0e23a45..98ee7ae10e7 100644
@@ -17,6 +17,10 @@
 #include <malloc.h>
 #include <asm/byteorder.h>
 #include <fs.h>
+#if (IS_ENABLED(CONFIG_PHY_AQUANTIA_UPLOAD_FW))
+#include <fs_loader.h>
+#include <fw_loader.h>
+#endif
 
 #define AQUNTIA_10G_CTL                0x20
 #define AQUNTIA_VENDOR_P1      0xc400

drivers/net/phy/aquantia.c struct fw_header { · line 131

Quoted 5 lines
drivers/net/phy/aquantia.c +0 -2
@@ -127,53 +131,7 @@ struct fw_header {
 
 #pragma pack()
 
-#if defined(CONFIG_PHY_AQUANTIA_UPLOAD_FW)
-static int aquantia_read_fw(u8 **fw_addr, size_t *fw_length)

I think it's better to add a weak function, e.g.:
int __weak aquantia_read_fw(u8 **fw_addr, size_t *fw_length);

And put the default fw loading logic into this function. Overriding this function by board allows using firmware data embedded into u-boot by binman.

It's useful in case that firmware data was damaged in filesystem.

Quoted 195 lines
drivers/net/phy/aquantia.c +0 -39
-{
-       loff_t length, read;
-       int ret;
-       void *addr = NULL;
-
-       *fw_addr = NULL;
-       *fw_length = 0;
-       debug("Loading Aquantia microcode from %s %s\n",
-             CONFIG_PHY_AQUANTIA_FW_PART,
 CONFIG_PHY_AQUANTIA_FW_NAME);
-       ret = fs_set_blk_dev("mmc", CONFIG_PHY_AQUANTIA_FW_PART,
 FS_TYPE_ANY);
-       if (ret < 0)
-               goto cleanup;
-
-       ret = fs_size(CONFIG_PHY_AQUANTIA_FW_NAME, &length);
-       if (ret < 0)
-               goto cleanup;
-
-       addr = malloc(length);
-       if (!addr) {
-               ret = -ENOMEM;
-               goto cleanup;
-       }
-
-       ret = fs_set_blk_dev("mmc", CONFIG_PHY_AQUANTIA_FW_PART,
 FS_TYPE_ANY);
-       if (ret < 0)
-               goto cleanup;
-
-       ret = fs_read(CONFIG_PHY_AQUANTIA_FW_NAME, (ulong)addr, 0,
 length,
-                     &read);
-       if (ret < 0)
-               goto cleanup;
-
-       *fw_addr = addr;
-       *fw_length = length;
-       debug("Found Aquantia microcode.\n");
-
-cleanup:
-       if (ret < 0) {
-               printf("loading firmware file %s %s failed with error

%d\n",

drivers/net/phy/aquantia.c +10 -15
-                      CONFIG_PHY_AQUANTIA_FW_PART,
-                      CONFIG_PHY_AQUANTIA_FW_NAME, ret);
-               free(addr);
-       }
-       return ret;
-}
+#if (IS_ENABLED(CONFIG_PHY_AQUANTIA_UPLOAD_FW))
 
 /* load data into the phy's memory */
 static int aquantia_load_memory(struct phy_device *phydev, u32 addr,
@@ -218,27 +176,27 @@ static u32 unpack_u24(const u8 *data)
        return (data[2] << 16) + (data[1] << 8) + data[0];
 }
 
-static int aquantia_upload_firmware(struct phy_device *phydev)
+/* Common firmware upload implementation */
+static int aquantia_do_upload_firmware(struct phy_device *phydev,
+                                      const u8 *addr, size_t
 fw_length)
 {
        int ret;
-       u8 *addr = NULL;
-       size_t fw_length = 0;
        u16 calculated_crc, read_crc;
        char version[VERSION_STRING_SIZE];
        u32 primary_offset, iram_offset, iram_size, dram_offset,
 dram_size;
        const struct fw_header *header;
 
-       ret = aquantia_read_fw(&addr, &fw_length);
-       if (ret != 0)
-               return ret;
+       if (!addr || !fw_length) {
+               printf("%s: Invalid firmware data\n", phydev->dev-
 >name);
+               return -EINVAL;
+       }
 
-       read_crc = (addr[fw_length - 2] << 8)  | addr[fw_length - 1];
+       read_crc = (addr[fw_length - 2] << 8) | addr[fw_length - 1];
        calculated_crc = crc16_ccitt(0, addr, fw_length - 2);
        if (read_crc != calculated_crc) {
                printf("%s bad firmware crc: file 0x%04x calculated
 0x%04x\n",
                       phydev->dev->name, read_crc, calculated_crc);
-               ret = -EINVAL;
-               goto done;
+               return -EINVAL;
        }
 
        /* Find the DRAM and IRAM sections within the firmware file.

*/

drivers/net/phy/aquantia.c +2 -2
@@ -268,14 +226,14 @@ static int aquantia_upload_firmware(struct
 phy_device *phydev)
        ret = aquantia_load_memory(phydev, DRAM_BASE_ADDR,
 &addr[dram_offset],
                                   dram_size);
        if (ret != 0)
-               goto done;
+               return ret;
 
        debug("loading iram 0x%08x from offset=%d size=%d\n",
              IRAM_BASE_ADDR, iram_offset, iram_size);
        ret = aquantia_load_memory(phydev, IRAM_BASE_ADDR,
 &addr[iram_offset],
                                   iram_size);
        if (ret != 0)
-               goto done;
+               return ret;

/* make sure soft reset and low power mode are clear */ phy_write(phydev, MDIO_MMD_VEND1, GLOBAL_STANDARD_CONTROL,
0);

drivers/net/phy/aquantia.c +22 -2
@@ -289,8 +247,63 @@ static int aquantia_upload_firmware(struct
 phy_device *phydev)
        phy_write(phydev, MDIO_MMD_VEND1, UP_CONTROL,
 UP_RUN_STALL_OVERRIDE);
 
        printf("%s firmware loading done.\n", phydev->dev->name);
-done:
-       free(addr);
+       return 0;
+}
+
+static int aquantia_upload_firmware(struct phy_device *phydev)
+{
+       int ret;
+       ofnode node;
+       struct udevice *loader_dev;
+       const char *fw_name;
+       u8 *fw_addr = NULL;
+       size_t fw_length;
+
+       fw_addr = malloc(CONFIG_PHY_AQUANTIA_FW_MAX_SIZE);
+       if (!fw_addr) {
+               printf("Failed to allocate memory for firmware\n");
+               return -ENOMEM;
+       }
+
+       /* First, try to load firmware via script */
+       ret = request_firmware_into_buf_via_script(fw_addr,
+                                                  CONFIG_PHY_AQUANTI
 A_FW_MAX_SIZE,
+                                                  CONFIG_PHY_AQUANTI

A_FW_LOADER_SCRIPT,

drivers/net/phy/aquantia.c +20 -0
+                                                  &fw_length);
+       if (ret) {
+               /* Fallback to DT specified firmware */
+               node = phy_get_ofnode(phydev);
+               if (!ofnode_valid(node)) {
+                       printf("Failed to get PHY node\n");
+                       ret = -EINVAL;
+                       goto out;
+               }
+
+               fw_name = ofnode_read_string(node, "firmware-name");
+               if (!fw_name) {
+                       printf("Failed to get firmware name\n");
+                       ret = -ENOENT;
+                       goto out;
+               }
+
+               ret = get_fs_loader(&loader_dev);
+               if (ret) {
+                       printf("Failed to get fs_loader instance:

%d\n", ret);

drivers/net/phy/aquantia.c +4 -0
+                       goto out;
+               }
+
+               ret = request_firmware_into_buf(loader_dev, fw_name,

fw_addr,
+ CONFIG_PHY_AQUANTIA_F
W_MAX_SIZE, 0);

drivers/net/phy/aquantia.c +2 -0
+               if (ret < 0) {
+                       printf("Failed to load firmware %s: %d\n",

fw_name, ret);

drivers/net/phy/aquantia.c +6 -0
+                       goto out;
+               }
+               fw_length = ret;
+       }
+
+       ret = aquantia_do_upload_firmware(phydev, fw_addr,

fw_length);

drivers/net/phy/aquantia.c +2 -1
+out:
+       free(fw_addr);
        return ret;
 }
 #else
--

2.47.3

author
#6 lore raw

Re: [PATCH v3 4/4] net: phy: aquantia: use generic firmware loader

Hi Weijie,

Sorry for the late reply.

Quoted 116 lines · Weijie Gao

Hi Beiyan,

Quoted 102 lines · Beiyan Yun

External email : Please do not click links or open attachments until you have verified the sender or the content.

Aquantia PHYs are being used w/o SPI flash in some routers recently. Current firmware loader only attempts to load from FS on top of MMC, limiting the use on many devices.

Removed the old firmware loader, migrate to generic firmware loader to
allow a wider range and runtime override of firmware source. (e.g., USB).

Tested on Buffalo WXR18000BE10P with UBIFS.

---

Changes in v3:
- Select FW_LOADER with PHY_AQUANTIA_UPLOAD_FW

Changes in v2:
- Add support for script based loader

drivers/net/phy/Kconfig | 24 ++++---
drivers/net/phy/aquantia.c | 133 ++++++++++++++++++++--------------- --

2 files changed, 88 insertions(+), 69 deletions(-)
drivers/net/phy/Kconfig +0 -1
index 185c6a3156e..68765290671 100644
@@ -1,4 +1,3 @@
-

config BITBANGMII
bool "Bit-banged ethernet MII management channel support"

drivers/net/phy/Kconfig +0 -0
@@ -90,23 +89,30 @@ menuconfig PHY_AQUANTIA

config PHY_AQUANTIA_UPLOAD_FW
bool "Aquantia firmware loading support"
depends on PHY_AQUANTIA

drivers/net/phy/Kconfig +2 -0
+       select FS_LOADER
+       select FW_LOADER
       help
               Aquantia PHYs use firmware which can be either loaded

automatically
from storage directly attached to the phy or loaded
by the boot loader
- via MDIO commands. The firmware is loaded from a
file, specified by
- the PHY_AQUANTIA_FW_PART and PHY_AQUANTIA_FW_NAME
options.

drivers/net/phy/Kconfig +3 -0
+               via MDIO commands.
+
+               This option enables loading the firmware using the

generic

drivers/net/phy/Kconfig +5 -3
+               file system firmware loader framework.
 
-config PHY_AQUANTIA_FW_PART
-       string "Aquantia firmware partition"
+config PHY_AQUANTIA_FW_MAX_SIZE
+       hex "Max firmware size"
       depends on PHY_AQUANTIA_UPLOAD_FW
+       default 0x80000
       help
-               Partition containing the firmware file.
+         The maximum size of the Aquantia PHY firmware. This is used

to

drivers/net/phy/Kconfig +5 -3
+         allocate a buffer to load the firmware into.
 
-config PHY_AQUANTIA_FW_NAME
-       string "Aquantia firmware filename"
+config PHY_AQUANTIA_FW_LOADER_SCRIPT
+       string "Aquantia firmware loader script"
       depends on PHY_AQUANTIA_UPLOAD_FW
+       default "aqr_phy_load_firmware"
       help
-               Firmware filename.
+               The firmware loading script variable name.

config PHY_ATHEROS
bool "Atheros Ethernet PHYs support"

drivers/net/phy/aquantia.c +4 -0
index d9df0e23a45..98ee7ae10e7 100644
@@ -17,6 +17,10 @@
 #include <malloc.h>
 #include <asm/byteorder.h>
 #include <fs.h>
+#if (IS_ENABLED(CONFIG_PHY_AQUANTIA_UPLOAD_FW))
+#include <fs_loader.h>
+#include <fw_loader.h>
+#endif
 
 #define AQUNTIA_10G_CTL                0x20
 #define AQUNTIA_VENDOR_P1      0xc400

drivers/net/phy/aquantia.c struct fw_header { · line 131

Quoted 5 lines
drivers/net/phy/aquantia.c +0 -2
@@ -127,53 +131,7 @@ struct fw_header {
 
 #pragma pack()
 
-#if defined(CONFIG_PHY_AQUANTIA_UPLOAD_FW)
-static int aquantia_read_fw(u8 **fw_addr, size_t *fw_length)

I think it's better to add a weak function, e.g.:
int __weak aquantia_read_fw(u8 **fw_addr, size_t *fw_length);

Quoted 6 lines

And put the default fw loading logic into this function. Overriding this function by board allows using firmware data embedded into u-boot by binman.

It's useful in case that firmware data was damaged in filesystem.

Good point, I can see that’s how MTK U-Boot manages the firmware currently.

There’s a catch though: I’ve prototyped the change locally, realize it breaks current assumption of lifetime. Let's say we override aquantia_upload_firmware with a wrapper function to bin data array, in that case we can not free fw_addr in aquantia_upload_firmware, or a dumb memory copy is needed.

Maybe we can add a structure wrapper with additional info like Qcom's struct rpmh_request? That’s a bit too much for me, I’d like further opinion.

Cheers,
Yun

Quoted 194 lines
Quoted 194 lines
drivers/net/phy/aquantia.c +0 -39
-{
-       loff_t length, read;
-       int ret;
-       void *addr = NULL;
-
-       *fw_addr = NULL;
-       *fw_length = 0;
-       debug("Loading Aquantia microcode from %s %s\n",
-             CONFIG_PHY_AQUANTIA_FW_PART,
 CONFIG_PHY_AQUANTIA_FW_NAME);
-       ret = fs_set_blk_dev("mmc", CONFIG_PHY_AQUANTIA_FW_PART,
 FS_TYPE_ANY);
-       if (ret < 0)
-               goto cleanup;
-
-       ret = fs_size(CONFIG_PHY_AQUANTIA_FW_NAME, &length);
-       if (ret < 0)
-               goto cleanup;
-
-       addr = malloc(length);
-       if (!addr) {
-               ret = -ENOMEM;
-               goto cleanup;
-       }
-
-       ret = fs_set_blk_dev("mmc", CONFIG_PHY_AQUANTIA_FW_PART,
 FS_TYPE_ANY);
-       if (ret < 0)
-               goto cleanup;
-
-       ret = fs_read(CONFIG_PHY_AQUANTIA_FW_NAME, (ulong)addr, 0,
 length,
-                     &read);
-       if (ret < 0)
-               goto cleanup;
-
-       *fw_addr = addr;
-       *fw_length = length;
-       debug("Found Aquantia microcode.\n");
-
-cleanup:
-       if (ret < 0) {
-               printf("loading firmware file %s %s failed with error

%d\n",

drivers/net/phy/aquantia.c +1 -6
-                      CONFIG_PHY_AQUANTIA_FW_PART,
-                      CONFIG_PHY_AQUANTIA_FW_NAME, ret);
-               free(addr);
-       }
-       return ret;
-}
+#if (IS_ENABLED(CONFIG_PHY_AQUANTIA_UPLOAD_FW))

/* load data into the phy's memory */
static int aquantia_load_memory(struct phy_device *phydev, u32 addr,

drivers/net/phy/aquantia.c +9 -9
@@ -218,27 +176,27 @@ static u32 unpack_u24(const u8 *data)
       return (data[2] << 16) + (data[1] << 8) + data[0];
 }
 
-static int aquantia_upload_firmware(struct phy_device *phydev)
+/* Common firmware upload implementation */
+static int aquantia_do_upload_firmware(struct phy_device *phydev,
+                                      const u8 *addr, size_t
 fw_length)
 {
       int ret;
-       u8 *addr = NULL;
-       size_t fw_length = 0;
       u16 calculated_crc, read_crc;
       char version[VERSION_STRING_SIZE];
       u32 primary_offset, iram_offset, iram_size, dram_offset,
 dram_size;
       const struct fw_header *header;
 
-       ret = aquantia_read_fw(&addr, &fw_length);
-       if (ret != 0)
-               return ret;
+       if (!addr || !fw_length) {
+               printf("%s: Invalid firmware data\n", phydev->dev-
 > name);
+               return -EINVAL;
+       }
 
-       read_crc = (addr[fw_length - 2] << 8)  | addr[fw_length - 1];
+       read_crc = (addr[fw_length - 2] << 8) | addr[fw_length - 1];
       calculated_crc = crc16_ccitt(0, addr, fw_length - 2);
       if (read_crc != calculated_crc) {
               printf("%s bad firmware crc: file 0x%04x calculated
 0x%04x\n",
                      phydev->dev->name, read_crc, calculated_crc);
-               ret = -EINVAL;
-               goto done;
+               return -EINVAL;
       }
 
       /* Find the DRAM and IRAM sections within the firmware file.

*/

drivers/net/phy/aquantia.c +2 -2
@@ -268,14 +226,14 @@ static int aquantia_upload_firmware(struct
 phy_device *phydev)
       ret = aquantia_load_memory(phydev, DRAM_BASE_ADDR,
 &addr[dram_offset],
                                  dram_size);
       if (ret != 0)
-               goto done;
+               return ret;
 
       debug("loading iram 0x%08x from offset=%d size=%d\n",
             IRAM_BASE_ADDR, iram_offset, iram_size);
       ret = aquantia_load_memory(phydev, IRAM_BASE_ADDR,
 &addr[iram_offset],
                                  iram_size);
       if (ret != 0)
-               goto done;
+               return ret;

/* make sure soft reset and low power mode are clear */ phy_write(phydev, MDIO_MMD_VEND1, GLOBAL_STANDARD_CONTROL,
0);

drivers/net/phy/aquantia.c +22 -2
@@ -289,8 +247,63 @@ static int aquantia_upload_firmware(struct
 phy_device *phydev)
       phy_write(phydev, MDIO_MMD_VEND1, UP_CONTROL,
 UP_RUN_STALL_OVERRIDE);
 
       printf("%s firmware loading done.\n", phydev->dev->name);
-done:
-       free(addr);
+       return 0;
+}
+
+static int aquantia_upload_firmware(struct phy_device *phydev)
+{
+       int ret;
+       ofnode node;
+       struct udevice *loader_dev;
+       const char *fw_name;
+       u8 *fw_addr = NULL;
+       size_t fw_length;
+
+       fw_addr = malloc(CONFIG_PHY_AQUANTIA_FW_MAX_SIZE);
+       if (!fw_addr) {
+               printf("Failed to allocate memory for firmware\n");
+               return -ENOMEM;
+       }
+
+       /* First, try to load firmware via script */
+       ret = request_firmware_into_buf_via_script(fw_addr,
+                                                  CONFIG_PHY_AQUANTI
 A_FW_MAX_SIZE,
+                                                  CONFIG_PHY_AQUANTI

A_FW_LOADER_SCRIPT,

drivers/net/phy/aquantia.c +20 -0
+                                                  &fw_length);
+       if (ret) {
+               /* Fallback to DT specified firmware */
+               node = phy_get_ofnode(phydev);
+               if (!ofnode_valid(node)) {
+                       printf("Failed to get PHY node\n");
+                       ret = -EINVAL;
+                       goto out;
+               }
+
+               fw_name = ofnode_read_string(node, "firmware-name");
+               if (!fw_name) {
+                       printf("Failed to get firmware name\n");
+                       ret = -ENOENT;
+                       goto out;
+               }
+
+               ret = get_fs_loader(&loader_dev);
+               if (ret) {
+                       printf("Failed to get fs_loader instance:

%d\n", ret);

drivers/net/phy/aquantia.c +4 -0
+                       goto out;
+               }
+
+               ret = request_firmware_into_buf(loader_dev, fw_name,

fw_addr,
+ CONFIG_PHY_AQUANTIA_F
W_MAX_SIZE, 0);

drivers/net/phy/aquantia.c +2 -0
+               if (ret < 0) {
+                       printf("Failed to load firmware %s: %d\n",

fw_name, ret);

drivers/net/phy/aquantia.c +6 -0
+                       goto out;
+               }
+               fw_length = ret;
+       }
+
+       ret = aquantia_do_upload_firmware(phydev, fw_addr,

fw_length);

drivers/net/phy/aquantia.c +2 -0
+out:
+       free(fw_addr);
       return ret;

}
#else
--
2.47.3

#7 lore raw

Re: [PATCH v3 4/4] net: phy: aquantia: use generic firmware loader

Quoted 152 lines · Beiyan Yun

External email : Please do not click links or open attachments until you have verified the sender or the content.
Hi Weijie,

Sorry for the late reply.

Quoted 128 lines

On 15 Oct 2025, at 8:43 AM, Weijie Gao <[email protected]> wrote:

Hi Beiyan,

Quoted 113 lines · Beiyan Yun

External email : Please do not click links or open attachments until
you have verified the sender or the content.

Aquantia PHYs are being used w/o SPI flash in some routers recently.
Current firmware loader only attempts to load from FS on top of MMC,
limiting the use on many devices.

Removed the old firmware loader, migrate to generic firmware loader
to
allow a wider range and runtime override of firmware source. (e.g.,
USB).

Tested on Buffalo WXR18000BE10P with UBIFS.

---

Changes in v3:
- Select FW_LOADER with PHY_AQUANTIA_UPLOAD_FW

Changes in v2:
- Add support for script based loader

drivers/net/phy/Kconfig | 24 ++++---
drivers/net/phy/aquantia.c | 133 ++++++++++++++++++++----------
-----
--

2 files changed, 88 insertions(+), 69 deletions(-)
drivers/net/phy/Kconfig +0 -1
index 185c6a3156e..68765290671 100644
@@ -1,4 +1,3 @@
-

config BITBANGMII
bool "Bit-banged ethernet MII management channel support"

drivers/net/phy/Kconfig +0 -0
@@ -90,23 +89,30 @@ menuconfig PHY_AQUANTIA

config PHY_AQUANTIA_UPLOAD_FW
bool "Aquantia firmware loading support"
depends on PHY_AQUANTIA

drivers/net/phy/Kconfig +2 -0
+       select FS_LOADER
+       select FW_LOADER
       help
               Aquantia PHYs use firmware which can be either

loaded
automatically
from storage directly attached to the phy or
loaded
by the boot loader
- via MDIO commands. The firmware is loaded from a
file, specified by
- the PHY_AQUANTIA_FW_PART and PHY_AQUANTIA_FW_NAME
options.

drivers/net/phy/Kconfig +3 -0
+               via MDIO commands.
+
+               This option enables loading the firmware using

the
generic

drivers/net/phy/Kconfig +5 -3
+               file system firmware loader framework.
 
-config PHY_AQUANTIA_FW_PART
-       string "Aquantia firmware partition"
+config PHY_AQUANTIA_FW_MAX_SIZE
+       hex "Max firmware size"
       depends on PHY_AQUANTIA_UPLOAD_FW
+       default 0x80000
       help
-               Partition containing the firmware file.
+         The maximum size of the Aquantia PHY firmware. This is

used
to

drivers/net/phy/Kconfig +5 -3
+         allocate a buffer to load the firmware into.
 
-config PHY_AQUANTIA_FW_NAME
-       string "Aquantia firmware filename"
+config PHY_AQUANTIA_FW_LOADER_SCRIPT
+       string "Aquantia firmware loader script"
       depends on PHY_AQUANTIA_UPLOAD_FW
+       default "aqr_phy_load_firmware"
       help
-               Firmware filename.
+               The firmware loading script variable name.

config PHY_ATHEROS
bool "Atheros Ethernet PHYs support"

drivers/net/phy/aquantia.c +4 -0
index d9df0e23a45..98ee7ae10e7 100644
@@ -17,6 +17,10 @@
 #include <malloc.h>
 #include <asm/byteorder.h>
 #include <fs.h>
+#if (IS_ENABLED(CONFIG_PHY_AQUANTIA_UPLOAD_FW))
+#include <fs_loader.h>
+#include <fw_loader.h>
+#endif
 
 #define AQUNTIA_10G_CTL                0x20
 #define AQUNTIA_VENDOR_P1      0xc400

drivers/net/phy/aquantia.c struct fw_header { · line 131

Quoted 5 lines
drivers/net/phy/aquantia.c +0 -2
@@ -127,53 +131,7 @@ struct fw_header {
 
 #pragma pack()
 
-#if defined(CONFIG_PHY_AQUANTIA_UPLOAD_FW)
-static int aquantia_read_fw(u8 **fw_addr, size_t *fw_length)

I think it's better to add a weak function, e.g.:
int __weak aquantia_read_fw(u8 **fw_addr, size_t *fw_length);

Quoted 7 lines

And put the default fw loading logic into this function. Overriding this function by board allows using firmware data embedded
into u-boot by binman.

It's useful in case that firmware data was damaged in filesystem.

Good point, I can see that’s how MTK U-Boot manages the firmware currently.

There’s a catch though: I’ve prototyped the change locally, realize it breaks current assumption of lifetime. Let's say we override aquantia_upload_firmware with a wrapper function to bin data array, in that case we can not free fw_addr in aquantia_upload_firmware, or a dumb memory copy is needed.

Quoted 4 lines

Maybe we can add a structure wrapper with additional info like Qcom's `struct
rpmh_request`? That’s a bit too much for me, I’d like further
opinion.

I use the return value to tell the caller whether the fw memory needs to be freed.

In the mtk 2p5ge driver:

static int mt7988_i2p5ge_phy_load_fw(struct phy_device *phydev)

{
	int fwrc;
	void *fw;

	fwrc = mt7988_i2p5ge_get_fw(&fw, &fw_size);
	if (fwrc < 0)
		return -EINVAL;

	......

cleanup:

	if (fwrc > 0)
		free(fw);

	return ret;
}

The return value of mt7988_i2p5ge_get_fw function:
0: no need to free the memory

Quoted 1 line

0: need to free

<0: error

Quoted 220 lines

Cheers,
Yun

Quoted 214 lines
Quoted 214 lines
drivers/net/phy/aquantia.c +0 -28
-{
-       loff_t length, read;
-       int ret;
-       void *addr = NULL;
-
-       *fw_addr = NULL;
-       *fw_length = 0;
-       debug("Loading Aquantia microcode from %s %s\n",
-             CONFIG_PHY_AQUANTIA_FW_PART,
 CONFIG_PHY_AQUANTIA_FW_NAME);
-       ret = fs_set_blk_dev("mmc", CONFIG_PHY_AQUANTIA_FW_PART,
 FS_TYPE_ANY);
-       if (ret < 0)
-               goto cleanup;
-
-       ret = fs_size(CONFIG_PHY_AQUANTIA_FW_NAME, &length);
-       if (ret < 0)
-               goto cleanup;
-
-       addr = malloc(length);
-       if (!addr) {
-               ret = -ENOMEM;
-               goto cleanup;
-       }
-
-       ret = fs_set_blk_dev("mmc", CONFIG_PHY_AQUANTIA_FW_PART,
 FS_TYPE_ANY);
-       if (ret < 0)
-               goto cleanup;
-
-       ret = fs_read(CONFIG_PHY_AQUANTIA_FW_NAME, (ulong)addr,
 0,

length,

drivers/net/phy/aquantia.c +0 -11
-                     &read);
-       if (ret < 0)
-               goto cleanup;
-
-       *fw_addr = addr;
-       *fw_length = length;
-       debug("Found Aquantia microcode.\n");
-
-cleanup:
-       if (ret < 0) {
-               printf("loading firmware file %s %s failed with

error
%d\n",

drivers/net/phy/aquantia.c +1 -6
-                      CONFIG_PHY_AQUANTIA_FW_PART,
-                      CONFIG_PHY_AQUANTIA_FW_NAME, ret);
-               free(addr);
-       }
-       return ret;
-}
+#if (IS_ENABLED(CONFIG_PHY_AQUANTIA_UPLOAD_FW))

/* load data into the phy's memory */
static int aquantia_load_memory(struct phy_device *phydev, u32 addr,

drivers/net/phy/aquantia.c +5 -6
@@ -218,27 +176,27 @@ static u32 unpack_u24(const u8 *data)
       return (data[2] << 16) + (data[1] << 8) + data[0];
 }
 
-static int aquantia_upload_firmware(struct phy_device *phydev)
+/* Common firmware upload implementation */
+static int aquantia_do_upload_firmware(struct phy_device
 *phydev,
+                                      const u8 *addr, size_t
 fw_length)
 {
       int ret;
-       u8 *addr = NULL;
-       size_t fw_length = 0;
       u16 calculated_crc, read_crc;
       char version[VERSION_STRING_SIZE];
       u32 primary_offset, iram_offset, iram_size, dram_offset,
 dram_size;
       const struct fw_header *header;
 
-       ret = aquantia_read_fw(&addr, &fw_length);
-       if (ret != 0)
-               return ret;
+       if (!addr || !fw_length) {
+               printf("%s: Invalid firmware data\n", phydev-
Quoted 2 lines

dev-
name);

+ return -EINVAL;

drivers/net/phy/aquantia.c +1 -1
+       }
 
-       read_crc = (addr[fw_length - 2] << 8)  | addr[fw_length -

1];
+ read_crc = (addr[fw_length - 2] << 8) | addr[fw_length -

1];
       calculated_crc = crc16_ccitt(0, addr, fw_length - 2);
       if (read_crc != calculated_crc) {
               printf("%s bad firmware crc: file 0x%04x
calculated
0x%04x\n",
                      phydev->dev->name, read_crc,

calculated_crc);

drivers/net/phy/aquantia.c +1 -2
-               ret = -EINVAL;
-               goto done;
+               return -EINVAL;
       }
 
       /* Find the DRAM and IRAM sections within the firmware

file.
*/

drivers/net/phy/aquantia.c +2 -2
@@ -268,14 +226,14 @@ static int aquantia_upload_firmware(struct
 phy_device *phydev)
       ret = aquantia_load_memory(phydev, DRAM_BASE_ADDR,
 &addr[dram_offset],
                                  dram_size);
       if (ret != 0)
-               goto done;
+               return ret;
 
       debug("loading iram 0x%08x from offset=%d size=%d\n",
             IRAM_BASE_ADDR, iram_offset, iram_size);
       ret = aquantia_load_memory(phydev, IRAM_BASE_ADDR,
 &addr[iram_offset],
                                  iram_size);
       if (ret != 0)
-               goto done;
+               return ret;

/* make sure soft reset and low power mode are clear */ phy_write(phydev, MDIO_MMD_VEND1, GLOBAL_STANDARD_CONTROL,
0);

drivers/net/phy/aquantia.c +21 -2
@@ -289,8 +247,63 @@ static int aquantia_upload_firmware(struct
 phy_device *phydev)
       phy_write(phydev, MDIO_MMD_VEND1, UP_CONTROL,
 UP_RUN_STALL_OVERRIDE);
 
       printf("%s firmware loading done.\n", phydev->dev->name);
-done:
-       free(addr);
+       return 0;
+}
+
+static int aquantia_upload_firmware(struct phy_device *phydev)
+{
+       int ret;
+       ofnode node;
+       struct udevice *loader_dev;
+       const char *fw_name;
+       u8 *fw_addr = NULL;
+       size_t fw_length;
+
+       fw_addr = malloc(CONFIG_PHY_AQUANTIA_FW_MAX_SIZE);
+       if (!fw_addr) {
+               printf("Failed to allocate memory for
 firmware\n");
+               return -ENOMEM;
+       }
+
+       /* First, try to load firmware via script */
+       ret = request_firmware_into_buf_via_script(fw_addr,
+
                                                 CONFIG_PHY_AQUAN

TI
A_FW_MAX_SIZE,
+
CONFIG_PHY_AQUAN
TI
A_FW_LOADER_SCRIPT,

drivers/net/phy/aquantia.c +11 -0
+                                                  &fw_length);
+       if (ret) {
+               /* Fallback to DT specified firmware */
+               node = phy_get_ofnode(phydev);
+               if (!ofnode_valid(node)) {
+                       printf("Failed to get PHY node\n");
+                       ret = -EINVAL;
+                       goto out;
+               }
+
+               fw_name = ofnode_read_string(node, "firmware-

name");

drivers/net/phy/aquantia.c +9 -0
+               if (!fw_name) {
+                       printf("Failed to get firmware name\n");
+                       ret = -ENOENT;
+                       goto out;
+               }
+
+               ret = get_fs_loader(&loader_dev);
+               if (ret) {
+                       printf("Failed to get fs_loader instance:

%d\n", ret);

drivers/net/phy/aquantia.c +4 -0
+                       goto out;
+               }
+
+               ret = request_firmware_into_buf(loader_dev,

fw_name,
fw_addr,
+
CONFIG_PHY_AQUANTIA
_F
W_MAX_SIZE, 0);

drivers/net/phy/aquantia.c +2 -0
+               if (ret < 0) {
+                       printf("Failed to load firmware %s:

%d\n",
fw_name, ret);

drivers/net/phy/aquantia.c +6 -0
+                       goto out;
+               }
+               fw_length = ret;
+       }
+
+       ret = aquantia_do_upload_firmware(phydev, fw_addr,

fw_length);

drivers/net/phy/aquantia.c +2 -0
+out:
+       free(fw_addr);
       return ret;

}
#else
--
2.47.3

#8 lore raw

Re: [PATCH v3 4/4] net: phy: aquantia: use generic firmware loader

In reply to Weijie Gao

On 10/15/25 2:43 AM, Weijie Gao wrote:

Hello everyone,

Quoted 11 lines

drivers/net/phy/aquantia.c struct fw_header { · line 131

Quoted 2 lines
drivers/net/phy/aquantia.c +0 -2
-#if defined(CONFIG_PHY_AQUANTIA_UPLOAD_FW)
-static int aquantia_read_fw(u8 **fw_addr, size_t *fw_length)

I think it's better to add a weak function, e.g.:
int __weak aquantia_read_fw(u8 **fw_addr, size_t *fw_length);

And put the default fw loading logic into this function. Overriding this function by board allows using firmware data embedded into u-boot by binman.

It's useful in case that firmware data was damaged in filesystem.

Is the firmware GPL that is embedded into U-Boot GPL too ?

Be mindful of the licensing implications here.

#9 lore raw

Re: [PATCH v3 4/4] net: phy: aquantia: use generic firmware loader

In reply to Beiyan Yun
Quoted 10 lines · Beiyan Yun

Aquantia PHYs are being used w/o SPI flash in some routers recently. Current firmware loader only attempts to load from FS on top of MMC, limiting the use on many devices.

Removed the old firmware loader, migrate to generic firmware loader to allow a wider range and runtime override of firmware source. (e.g., USB).

Tested on Buffalo WXR18000BE10P with UBIFS.

Please don't add own Tested-by tags.

Quoted 3 lines

Newlines not needed before ---

Quoted 11 lines

---

Changes in v3:
- Select FW_LOADER with PHY_AQUANTIA_UPLOAD_FW

Changes in v2:
- Add support for script based loader

  drivers/net/phy/Kconfig    |  24 ++++---
  drivers/net/phy/aquantia.c | 133 ++++++++++++++++++++-----------------
  2 files changed, 88 insertions(+), 69 deletions(-)

Would it be possible to split this patch up a bit, so it is easier to review ? Clean ups and code moves first, functional changes second ?

Thank you