public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Beiyan Yun <root@infi.wang>
To: u-boot@lists.denx.de
Cc: Yao Zi <ziyao@disroot.org>,
	Marek Vasut <marek.vasut+renesas@mailbox.org>,
	Tom Rini <trini@konsulko.com>, Beiyan Yun <root@infi.wang>,
	Jerome Forissier <jerome.forissier@linaro.org>,
	Joe Hershberger <joe.hershberger@ni.com>,
	Ramon Fried <rfried.dev@gmail.com>,
	Siddharth Vadapalli <s-vadapalli@ti.com>
Subject: [PATCH v4 4/5] net: phy: aquantia: refactor firmware upload helpers
Date: Fri, 31 Oct 2025 23:21:06 +0800	[thread overview]
Message-ID: <20251031152348.60571-5-root@infi.wang> (raw)
In-Reply-To: <20251031152348.60571-1-root@infi.wang>

Split `aquantia_upload_firmware` into `aquantia_upload_firmware`
and `aquantia_do_upload_firmware` to prepare for fsloader change.

Signed-off-by: Beiyan Yun <root@infi.wang>

Patch-cc:marek
---

Changes in v4:
- New

 drivers/net/phy/aquantia.c | 34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/drivers/net/phy/aquantia.c b/drivers/net/phy/aquantia.c
index 11e450cdb0b..461d4b07a40 100644
--- a/drivers/net/phy/aquantia.c
+++ b/drivers/net/phy/aquantia.c
@@ -218,27 +218,21 @@ 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)
+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;
-
 	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. */
@@ -269,14 +263,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);
@@ -290,8 +284,24 @@ 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:
+
+	return 0;
+}
+
+static int aquantia_upload_firmware(struct phy_device *phydev)
+{
+	int ret;
+	u8 *addr = NULL;
+	size_t fw_length = 0;
+
+	ret = aquantia_read_fw(&addr, &fw_length);
+	if (ret != 0)
+		return ret;
+
+	ret = aquantia_do_upload_firmware(phydev, addr, fw_length);
+
 	free(addr);
+
 	return ret;
 }
 #else
-- 
2.47.3


  parent reply	other threads:[~2025-10-31 15:24 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-31 15:21 [PATCH v4 0/5] net: phy: aquantia: Switch to generic firmware loader Beiyan Yun
2025-10-31 15:21 ` [PATCH v4 1/5] net: phy: aquantia: refresh format Beiyan Yun
2025-10-31 15:51   ` Marek Vasut
2025-10-31 17:21     ` Beiyan Yun
2025-10-31 18:33       ` Marek Vasut
2025-10-31 19:00         ` Tom Rini
2025-10-31 15:21 ` [PATCH v4 2/5] doc: bindings: use upstream bindings for aquantia phy Beiyan Yun
2025-10-31 15:53   ` Marek Vasut
2025-10-31 17:02     ` Beiyan Yun
2025-10-31 17:12       ` Marek Vasut
2025-10-31 15:21 ` [PATCH v4 3/5] net: phy: aquantia: replace the "mdi-reversal" node with "marvell, mdi-cfg-order" Beiyan Yun
2025-10-31 15:21 ` Beiyan Yun [this message]
2025-10-31 15:21 ` [PATCH v4 5/5] net: phy: aquantia: use generic firmware loader Beiyan Yun
2025-10-31 15:41   ` Daniel Golle
2025-10-31 16:09     ` Beiyan Yun
2025-10-31 15:57   ` Marek Vasut
2025-10-31 16:34     ` Beiyan Yun
2025-10-31 16:51       ` Marek Vasut
2025-11-01  7:45         ` Beiyan Yun
2025-11-01 11:54           ` Marek Vasut
2025-11-02  4:57             ` Beiyan Yun
2025-11-02 14:25               ` Marek Vasut

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251031152348.60571-5-root@infi.wang \
    --to=root@infi.wang \
    --cc=jerome.forissier@linaro.org \
    --cc=joe.hershberger@ni.com \
    --cc=marek.vasut+renesas@mailbox.org \
    --cc=rfried.dev@gmail.com \
    --cc=s-vadapalli@ti.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=ziyao@disroot.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox