* [RFC PATCH net-next v3 1/6] dt-bindings: net: add Airoha EN8811H PHY MCU
2026-09-12 13:04 [RFC PATCH net-next v3 0/6] net: mdio: an MDIO device driver for the Airoha EN8811H Aleksei Sviridkin
@ 2026-09-12 13:04 ` Aleksei Sviridkin
2026-09-12 13:04 ` [RFC PATCH net-next v3 2/6] net: phy: air: type the buckpbus core on the mdio device Aleksei Sviridkin
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Aleksei Sviridkin @ 2026-09-12 13:04 UTC (permalink / raw)
To: andrew, andrew+netdev, hkallweit1, linux, davem, edumazet, kuba,
pabeni, horms, robh, krzk+dt, conor+dt
Cc: ericwouds, netdev, devicetree, linux-kernel, Aleksei Sviridkin
The EN8811H answers its PHY ID from power-on, but a link is only
possible once its MD32 MCU runs firmware that the host loads over
MDIO into volatile RAM. On systems that keep the firmware files in
a filesystem, the files arrive long after the MDIO bus was scanned,
and the PHY node alone cannot express that gap.
Describe the MCU as an MDIO device of its own, with the PHY node on
a child bus underneath it. The device downloads the firmware when
the files appear, or adopts firmware the bootloader left running,
and registers the child bus only then, so the PHY never becomes
visible before the chip can serve it.
The reset line belongs to this node, not to the PHY node: firmware
lives in volatile RAM, so reset may be asserted only while the MCU
is not executing it. On a PHY node the line would be pulsed by
every phy_detach() and wipe the running firmware.
Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
---
.../bindings/net/airoha,en8811h-mcu.yaml | 127 ++++++++++++++++++
MAINTAINERS | 6 +
2 files changed, 133 insertions(+)
create mode 100644 Documentation/devicetree/bindings/net/airoha,en8811h-mcu.yaml
diff --git a/Documentation/devicetree/bindings/net/airoha,en8811h-mcu.yaml b/Documentation/devicetree/bindings/net/airoha,en8811h-mcu.yaml
new file mode 100644
index 000000000000..7c204b5f29c9
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/airoha,en8811h-mcu.yaml
@@ -0,0 +1,127 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/airoha,en8811h-mcu.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Airoha EN8811H PHY MCU
+
+maintainers:
+ - Aleksei Sviridkin <f@lex.la>
+
+description: |
+ The Airoha EN8811H 2.5G PHY is built around an MD32 core that executes
+ firmware from volatile RAM. The chip answers an MDIO address from
+ power-on, but the PHY function does not exist until firmware has been
+ loaded over MDIO, and it disappears again if that RAM is cleared.
+
+ This node describes the MD32 core. The PHY function answers on a child
+ MDIO bus below it, at the same address the core occupies on the parent
+ bus, and only while firmware is running.
+
+ The reset line is wired to the core, and asserting it clears the
+ firmware RAM. It therefore belongs to this node: a reset described on
+ the PHY node would be pulsed by that node's own lifecycle, whatever
+ the core is doing.
+
+ A board that has firmware in hand while its MDIO bus is enumerated can
+ describe the PHY on its own, as airoha,en8811h.yaml does, and that form
+ stays valid. This binding is for the boards where firmware arrives
+ later, so that there is no PHY to describe until the core has it.
+
+properties:
+ $nodename:
+ pattern: "^mcu@[0-9a-f]+$"
+
+ compatible:
+ const: airoha,en8811h-mcu
+
+ reg:
+ maxItems: 1
+
+ reset-gpios:
+ maxItems: 1
+ description:
+ The GPIO phandle and specifier for the reset signal wired to the
+ MD32 core.
+
+ reset-assert-us:
+ description:
+ Delay after the reset was asserted in microseconds. If this
+ property is missing the delay will be skipped.
+
+ reset-deassert-us:
+ description:
+ Delay after the reset was deasserted in microseconds. If this
+ property is missing the delay will be skipped.
+
+ mdio:
+ $ref: mdio.yaml#
+ description:
+ The bus the PHY function answers on while firmware is running, at
+ the same address this node occupies on the parent bus. Only that
+ one address is passed through. The bus-level reset properties
+ mdio.yaml allows are refused here, because the MDIO core asserts
+ such a line when the bus registers, and that erases the firmware
+ this PHY is made of.
+
+ properties:
+ reset-gpios: false
+ reset-delay-us: false
+ reset-post-delay-us: false
+
+ patternProperties:
+ '^ethernet-phy@[0-9a-f]+$':
+ type: object
+ $ref: airoha,en8811h.yaml#
+ unevaluatedProperties: false
+
+ properties:
+ reset-gpios: false
+ reset-assert-us: false
+ reset-deassert-us: false
+ resets: false
+ reset-names: false
+
+ description:
+ The reset line belongs to the MCU node above. A reset described
+ here would be pulsed by this node's own lifecycle, and that erases
+ the firmware that created this PHY.
+
+ unevaluatedProperties: false
+
+required:
+ - compatible
+ - reg
+ - mdio
+
+additionalProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/gpio/gpio.h>
+ #include <dt-bindings/interrupt-controller/irq.h>
+
+ mdio {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ mcu@d {
+ compatible = "airoha,en8811h-mcu";
+ reg = <0xd>;
+ reset-gpios = <&pio 14 GPIO_ACTIVE_LOW>;
+ reset-assert-us = <10000>;
+ reset-deassert-us = <20000>;
+
+ mdio {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ ethernet-phy@d {
+ compatible = "ethernet-phy-id03a2.a411";
+ reg = <0xd>;
+ interrupts-extended = <&pio 15 IRQ_TYPE_LEVEL_LOW>;
+ };
+ };
+ };
+ };
diff --git a/MAINTAINERS b/MAINTAINERS
index b23fb6f2f4ef..4ca19275f4d0 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -750,6 +750,12 @@ S: Supported
F: fs/aio.c
F: include/linux/*aio*.h
+AIROHA EN8811H MCU MDIO DRIVER
+M: Aleksei Sviridkin <f@lex.la>
+L: netdev@vger.kernel.org
+S: Maintained
+F: Documentation/devicetree/bindings/net/airoha,en8811h-mcu.yaml
+
AIROHA ETHERNET DRIVER
M: Lorenzo Bianconi <lorenzo@kernel.org>
L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
--
2.53.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [RFC PATCH net-next v3 2/6] net: phy: air: type the buckpbus core on the mdio device
2026-09-12 13:04 [RFC PATCH net-next v3 0/6] net: mdio: an MDIO device driver for the Airoha EN8811H Aleksei Sviridkin
2026-09-12 13:04 ` [RFC PATCH net-next v3 1/6] dt-bindings: net: add Airoha EN8811H PHY MCU Aleksei Sviridkin
@ 2026-09-12 13:04 ` Aleksei Sviridkin
2026-09-12 13:04 ` [RFC PATCH net-next v3 3/6] net: phy: air: move the EN8811H firmware download into the library Aleksei Sviridkin
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Aleksei Sviridkin @ 2026-09-12 13:04 UTC (permalink / raw)
To: andrew, andrew+netdev, hkallweit1, linux, davem, edumazet, kuba,
pabeni, horms, robh, krzk+dt, conor+dt
Cc: ericwouds, netdev, devicetree, linux-kernel, Aleksei Sviridkin
The buckpbus accessors only need an MDIO device, but they take a
phy_device, which ties them to a probed PHY. An upcoming MDIO device
driver needs the same register access before any phy_device exists,
since it runs precisely to make the PHY presentable.
Retype the internal helpers onto an mdio_device and keep the exported
phy_device API as page-selecting wrappers that pass &phydev->mdio. The
EN8811H driver already reaches the AN8811HB pbus through an
mdio_device, so this follows an existing direction rather than opening
a new one.
No functional change.
Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
---
drivers/net/phy/air_phy_lib.c | 80 ++++++++++++++++++-----------------
1 file changed, 42 insertions(+), 38 deletions(-)
diff --git a/drivers/net/phy/air_phy_lib.c b/drivers/net/phy/air_phy_lib.c
index 5141db19fa5e..e314717843ae 100644
--- a/drivers/net/phy/air_phy_lib.c
+++ b/drivers/net/phy/air_phy_lib.c
@@ -14,31 +14,32 @@
#include "air_phy_lib.h"
-static int __air_buckpbus_reg_read(struct phy_device *phydev,
+static int __air_buckpbus_reg_read(struct mdio_device *mdiodev,
u32 pbus_address, u32 *pbus_data)
{
int pbus_data_low, pbus_data_high;
int ret;
- ret = __phy_write(phydev, AIR_BPBUS_MODE, AIR_BPBUS_MODE_ADDR_FIXED);
+ ret = __mdiodev_write(mdiodev, AIR_BPBUS_MODE,
+ AIR_BPBUS_MODE_ADDR_FIXED);
if (ret < 0)
return ret;
- ret = __phy_write(phydev, AIR_BPBUS_RD_ADDR_HIGH,
- upper_16_bits(pbus_address));
+ ret = __mdiodev_write(mdiodev, AIR_BPBUS_RD_ADDR_HIGH,
+ upper_16_bits(pbus_address));
if (ret < 0)
return ret;
- ret = __phy_write(phydev, AIR_BPBUS_RD_ADDR_LOW,
- lower_16_bits(pbus_address));
+ ret = __mdiodev_write(mdiodev, AIR_BPBUS_RD_ADDR_LOW,
+ lower_16_bits(pbus_address));
if (ret < 0)
return ret;
- pbus_data_high = __phy_read(phydev, AIR_BPBUS_RD_DATA_HIGH);
+ pbus_data_high = __mdiodev_read(mdiodev, AIR_BPBUS_RD_DATA_HIGH);
if (pbus_data_high < 0)
return pbus_data_high;
- pbus_data_low = __phy_read(phydev, AIR_BPBUS_RD_DATA_LOW);
+ pbus_data_low = __mdiodev_read(mdiodev, AIR_BPBUS_RD_DATA_LOW);
if (pbus_data_low < 0)
return pbus_data_low;
@@ -46,64 +47,66 @@ static int __air_buckpbus_reg_read(struct phy_device *phydev,
return 0;
}
-static int __air_buckpbus_reg_write(struct phy_device *phydev,
+static int __air_buckpbus_reg_write(struct mdio_device *mdiodev,
u32 pbus_address, u32 pbus_data)
{
int ret;
- ret = __phy_write(phydev, AIR_BPBUS_MODE, AIR_BPBUS_MODE_ADDR_FIXED);
+ ret = __mdiodev_write(mdiodev, AIR_BPBUS_MODE,
+ AIR_BPBUS_MODE_ADDR_FIXED);
if (ret < 0)
return ret;
- ret = __phy_write(phydev, AIR_BPBUS_WR_ADDR_HIGH,
- upper_16_bits(pbus_address));
+ ret = __mdiodev_write(mdiodev, AIR_BPBUS_WR_ADDR_HIGH,
+ upper_16_bits(pbus_address));
if (ret < 0)
return ret;
- ret = __phy_write(phydev, AIR_BPBUS_WR_ADDR_LOW,
- lower_16_bits(pbus_address));
+ ret = __mdiodev_write(mdiodev, AIR_BPBUS_WR_ADDR_LOW,
+ lower_16_bits(pbus_address));
if (ret < 0)
return ret;
- ret = __phy_write(phydev, AIR_BPBUS_WR_DATA_HIGH,
- upper_16_bits(pbus_data));
+ ret = __mdiodev_write(mdiodev, AIR_BPBUS_WR_DATA_HIGH,
+ upper_16_bits(pbus_data));
if (ret < 0)
return ret;
- ret = __phy_write(phydev, AIR_BPBUS_WR_DATA_LOW,
- lower_16_bits(pbus_data));
+ ret = __mdiodev_write(mdiodev, AIR_BPBUS_WR_DATA_LOW,
+ lower_16_bits(pbus_data));
if (ret < 0)
return ret;
return 0;
}
-static int __air_buckpbus_reg_modify(struct phy_device *phydev,
+static int __air_buckpbus_reg_modify(struct mdio_device *mdiodev,
u32 pbus_address, u32 mask, u32 set)
{
int pbus_data_low, pbus_data_high;
u32 pbus_data_old, pbus_data_new;
int ret;
- ret = __phy_write(phydev, AIR_BPBUS_MODE, AIR_BPBUS_MODE_ADDR_FIXED);
+ ret = __mdiodev_write(mdiodev, AIR_BPBUS_MODE,
+ AIR_BPBUS_MODE_ADDR_FIXED);
if (ret < 0)
return ret;
- ret = __phy_write(phydev, AIR_BPBUS_RD_ADDR_HIGH,
- upper_16_bits(pbus_address));
+ ret = __mdiodev_write(mdiodev, AIR_BPBUS_RD_ADDR_HIGH,
+ upper_16_bits(pbus_address));
if (ret < 0)
return ret;
- ret = __phy_write(phydev, AIR_BPBUS_RD_ADDR_LOW,
- lower_16_bits(pbus_address));
+ ret = __mdiodev_write(mdiodev, AIR_BPBUS_RD_ADDR_LOW,
+ lower_16_bits(pbus_address));
if (ret < 0)
return ret;
- pbus_data_high = __phy_read(phydev, AIR_BPBUS_RD_DATA_HIGH);
+ pbus_data_high = __mdiodev_read(mdiodev, AIR_BPBUS_RD_DATA_HIGH);
if (pbus_data_high < 0)
return pbus_data_high;
- pbus_data_low = __phy_read(phydev, AIR_BPBUS_RD_DATA_LOW);
+ pbus_data_low = __mdiodev_read(mdiodev, AIR_BPBUS_RD_DATA_LOW);
if (pbus_data_low < 0)
return pbus_data_low;
@@ -112,23 +115,23 @@ static int __air_buckpbus_reg_modify(struct phy_device *phydev,
if (pbus_data_new == pbus_data_old)
return 0;
- ret = __phy_write(phydev, AIR_BPBUS_WR_ADDR_HIGH,
- upper_16_bits(pbus_address));
+ ret = __mdiodev_write(mdiodev, AIR_BPBUS_WR_ADDR_HIGH,
+ upper_16_bits(pbus_address));
if (ret < 0)
return ret;
- ret = __phy_write(phydev, AIR_BPBUS_WR_ADDR_LOW,
- lower_16_bits(pbus_address));
+ ret = __mdiodev_write(mdiodev, AIR_BPBUS_WR_ADDR_LOW,
+ lower_16_bits(pbus_address));
if (ret < 0)
return ret;
- ret = __phy_write(phydev, AIR_BPBUS_WR_DATA_HIGH,
- upper_16_bits(pbus_data_new));
+ ret = __mdiodev_write(mdiodev, AIR_BPBUS_WR_DATA_HIGH,
+ upper_16_bits(pbus_data_new));
if (ret < 0)
return ret;
- ret = __phy_write(phydev, AIR_BPBUS_WR_DATA_LOW,
- lower_16_bits(pbus_data_new));
+ ret = __mdiodev_write(mdiodev, AIR_BPBUS_WR_DATA_LOW,
+ lower_16_bits(pbus_data_new));
if (ret < 0)
return ret;
@@ -144,7 +147,8 @@ int air_phy_buckpbus_reg_read(struct phy_device *phydev, u32 pbus_address,
saved_page = phy_select_page(phydev, AIR_PHY_PAGE_EXTENDED_4);
if (saved_page >= 0) {
- ret = __air_buckpbus_reg_read(phydev, pbus_address, pbus_data);
+ ret = __air_buckpbus_reg_read(&phydev->mdio, pbus_address,
+ pbus_data);
if (ret < 0)
phydev_err(phydev, "%s 0x%08x failed: %d\n", __func__,
pbus_address, ret);
@@ -163,7 +167,7 @@ int air_phy_buckpbus_reg_write(struct phy_device *phydev, u32 pbus_address,
saved_page = phy_select_page(phydev, AIR_PHY_PAGE_EXTENDED_4);
if (saved_page >= 0) {
- ret = __air_buckpbus_reg_write(phydev, pbus_address,
+ ret = __air_buckpbus_reg_write(&phydev->mdio, pbus_address,
pbus_data);
if (ret < 0)
phydev_err(phydev, "%s 0x%08x failed: %d\n", __func__,
@@ -183,8 +187,8 @@ int air_phy_buckpbus_reg_modify(struct phy_device *phydev, u32 pbus_address,
saved_page = phy_select_page(phydev, AIR_PHY_PAGE_EXTENDED_4);
if (saved_page >= 0) {
- ret = __air_buckpbus_reg_modify(phydev, pbus_address, mask,
- set);
+ ret = __air_buckpbus_reg_modify(&phydev->mdio, pbus_address,
+ mask, set);
if (ret < 0)
phydev_err(phydev, "%s 0x%08x failed: %d\n", __func__,
pbus_address, ret);
--
2.53.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [RFC PATCH net-next v3 3/6] net: phy: air: move the EN8811H firmware download into the library
2026-09-12 13:04 [RFC PATCH net-next v3 0/6] net: mdio: an MDIO device driver for the Airoha EN8811H Aleksei Sviridkin
2026-09-12 13:04 ` [RFC PATCH net-next v3 1/6] dt-bindings: net: add Airoha EN8811H PHY MCU Aleksei Sviridkin
2026-09-12 13:04 ` [RFC PATCH net-next v3 2/6] net: phy: air: type the buckpbus core on the mdio device Aleksei Sviridkin
@ 2026-09-12 13:04 ` Aleksei Sviridkin
2026-09-12 13:04 ` [RFC PATCH net-next v3 4/6] net: phy: air: skip the download when the MD32 is already running Aleksei Sviridkin
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Aleksei Sviridkin @ 2026-09-12 13:04 UTC (permalink / raw)
To: andrew, andrew+netdev, hkallweit1, linux, davem, edumazet, kuba,
pabeni, horms, robh, krzk+dt, conor+dt
Cc: ericwouds, netdev, devicetree, linux-kernel, Aleksei Sviridkin
The EN8811H firmware loader is welded to the PHY driver, but the next
patch adds an MDIO device driver that must perform the same download
before any phy_device exists.
Move the download engine into the shared library, typed on the MDIO
device like the buckpbus core. The moved helpers take the bus lock and
save and restore the page register themselves, since phy_select_page()
needs a phy_device.
The write loop is broken into chunks that each take the bus lock on
their own, because the larger of the two blobs held it for 65536
register writes at a stretch and stalled every other PHY on the bus.
It did not matter while this only ran from phy_probe() on a quiet bus
at boot; the next patches run it on a live system.
The status poll asks for the MMD register through the Clause 22
indirection unconditionally, which is what the Clause 22 probe path was
already doing.
Behaviour changes where the library now reports instead of printing: the
version read at the end of the download is checked, the readiness poll
hands back the errno from a failed status read rather than -ENODEV, and
the lines the old helpers printed on failure move to their callers or to
debug level. The AN8811HB probe shares the readiness wait and the block
writer, so it sees those too.
Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
---
Notes:
The status read does its three Clause 22 selection writes itself rather
than through mmd_phy_read(), which discards their errors and would let a
failed selection read a different register back as a success. Asking for
Clause 22 unconditionally records what was already happening rather than
choosing it: phy_read_mmd() resolved the question from phydev->is_c45,
which the Clause 22 probe path leaves false.
The readiness poll's timeout message moves out to the PHY driver's
wrapper, which is where the errno was already being reported to a human.
The poll is about to gain a caller that retries forever, and an
unconditional message there would repeat with every retry; the status
value it used to name stays behind at debug level.
The behaviour changes, one by one. The version read at the end of the
download is now checked, so a bus error there fails the load instead of
leaving the version at zero; en8811h_print_fw_version() still discards it
on the AN8811HB path, which does not go through this download. The
readiness poll hands back the errno from a failed status read rather than
-ENODEV. Its failure is now reported once, by the wrapper and naming that
errno, where phy_read_mmd_poll_timeout() used to print a line of its own
before the wrapper printed the status register. A failed block write no
longer names its address, since both callers report the failure anyway.
The version print moves to the wrapper for the same reason as the timeout
message: the library hands the number back through fw_version, and the
caller decides whether a human sees it.
drivers/net/phy/air_en8811h.c | 150 ++---------------
drivers/net/phy/air_phy_lib.c | 297 ++++++++++++++++++++++++++++++++++
drivers/net/phy/air_phy_lib.h | 29 ++++
3 files changed, 337 insertions(+), 139 deletions(-)
diff --git a/drivers/net/phy/air_en8811h.c b/drivers/net/phy/air_en8811h.c
index 16a9171cb838..43d2eff808f1 100644
--- a/drivers/net/phy/air_en8811h.c
+++ b/drivers/net/phy/air_en8811h.c
@@ -20,21 +20,15 @@
#include <linux/bitfield.h>
#include <linux/property.h>
#include <linux/wordpart.h>
-#include <linux/unaligned.h>
#include "air_phy_lib.h"
#define EN8811H_PHY_ID 0x03a2a411
#define AN8811HB_PHY_ID 0xc0ff04a0
-#define EN8811H_MD32_DM "airoha/EthMD32.dm.bin"
-#define EN8811H_MD32_DSP "airoha/EthMD32.DSP.bin"
#define AN8811HB_MD32_DM "airoha/an8811hb/EthMD32_CRC.DM.bin"
#define AN8811HB_MD32_DSP "airoha/an8811hb/EthMD32_CRC.DSP.bin"
-#define AIR_FW_ADDR_DM 0x00000000
-#define AIR_FW_ADDR_DSP 0x00100000
-
/* MII Registers */
#define AIR_AUX_CTRL_STATUS 0x1d
#define AIR_AUX_CTRL_STATUS_SPEED_MASK GENMASK(4, 2)
@@ -44,8 +38,6 @@
#define AIR_AUX_CTRL_STATUS_SPEED_2500 0xc
/* Registers on MDIO_MMD_VEND1 */
-#define EN8811H_PHY_FW_STATUS 0x8009
-#define EN8811H_PHY_READY 0x02
#define AIR_PHY_MCU_CMD_0 0x800b
#define AIR_PHY_MCU_CMD_1 0x800c
@@ -108,8 +100,6 @@
#define EN8811H_2P5G_LPA 0x3b30
#define EN8811H_2P5G_LPA_2P5G BIT(0)
-#define EN8811H_FW_VERSION 0x3b3c
-
#define EN8811H_POLARITY 0xca0f8
#define EN8811H_POLARITY_TX_NORMAL BIT(0)
#define EN8811H_POLARITY_RX_REVERSE BIT(1)
@@ -122,12 +112,6 @@
#define EN8811H_CLK_CGM 0xcf958
#define EN8811H_CLK_CGM_CKO BIT(26)
-#define EN8811H_FW_CTRL_1 0x0f0018
-#define EN8811H_FW_CTRL_1_START 0x0
-#define EN8811H_FW_CTRL_1_FINISH 0x1
-#define EN8811H_FW_CTRL_2 0x800000
-#define EN8811H_FW_CTRL_2_LOADING BIT(11)
-
#define AN8811HB_CRC_PM_SET1 0xf020c
#define AN8811HB_CRC_PM_MON2 0xf0218
#define AN8811HB_CRC_PM_MON3 0xf021c
@@ -270,86 +254,15 @@ static int __air_pbus_reg_write(struct mdio_device *mdiodev,
upper_16_bits(pbus_data));
}
-static int __air_write_buf(struct phy_device *phydev, u32 address,
- const struct firmware *fw)
-{
- unsigned int offset;
- int ret;
- u16 val;
-
- ret = __phy_write(phydev, AIR_BPBUS_MODE, AIR_BPBUS_MODE_ADDR_INCR);
- if (ret < 0)
- return ret;
-
- ret = __phy_write(phydev, AIR_BPBUS_WR_ADDR_HIGH,
- upper_16_bits(address));
- if (ret < 0)
- return ret;
-
- ret = __phy_write(phydev, AIR_BPBUS_WR_ADDR_LOW,
- lower_16_bits(address));
- if (ret < 0)
- return ret;
-
- for (offset = 0; offset < fw->size; offset += 4) {
- val = get_unaligned_le16(&fw->data[offset + 2]);
- ret = __phy_write(phydev, AIR_BPBUS_WR_DATA_HIGH, val);
- if (ret < 0)
- return ret;
-
- val = get_unaligned_le16(&fw->data[offset]);
- ret = __phy_write(phydev, AIR_BPBUS_WR_DATA_LOW, val);
- if (ret < 0)
- return ret;
- }
-
- return 0;
-}
-
-static int air_write_buf(struct phy_device *phydev, u32 address,
- const struct firmware *fw)
-{
- int saved_page;
- int ret = 0;
-
- if (fw->size % 4) {
- phydev_err(phydev, "firmware size %zu is not a multiple of 4\n",
- fw->size);
- return -EINVAL;
- }
-
- saved_page = phy_select_page(phydev, AIR_PHY_PAGE_EXTENDED_4);
-
- if (saved_page >= 0) {
- ret = __air_write_buf(phydev, address, fw);
- if (ret < 0)
- phydev_err(phydev, "%s 0x%08x failed: %d\n", __func__,
- address, ret);
- }
-
- return phy_restore_page(phydev, saved_page, ret);
-}
-
static int en8811h_wait_mcu_ready(struct phy_device *phydev)
{
- int ret, reg_value;
+ int ret;
- ret = air_phy_buckpbus_reg_write(phydev, EN8811H_FW_CTRL_1,
- EN8811H_FW_CTRL_1_FINISH);
- if (ret)
- return ret;
+ ret = air_en8811h_wait_mcu_ready(&phydev->mdio);
+ if (ret < 0)
+ phydev_err(phydev, "MCU not ready: %pe\n", ERR_PTR(ret));
- /* Because of mdio-lock, may have to wait for multiple loads */
- ret = phy_read_mmd_poll_timeout(phydev, MDIO_MMD_VEND1,
- EN8811H_PHY_FW_STATUS, reg_value,
- reg_value == EN8811H_PHY_READY,
- 20000, 7500000, true);
- if (ret) {
- phydev_err(phydev, "MCU not ready: 0x%x\n", reg_value);
- return -ENODEV;
- }
-
- return 0;
+ return ret;
}
static int an8811hb_check_crc(struct phy_device *phydev, u32 set1,
@@ -411,7 +324,7 @@ static int an8811hb_load_file(struct phy_device *phydev, const char *name,
if (ret < 0)
return ret;
- ret = air_write_buf(phydev, address, fw);
+ ret = air_fw_write_buf(&phydev->mdio, address, fw);
release_firmware(fw);
return ret;
}
@@ -507,56 +420,15 @@ static int an8811hb_load_firmware(struct phy_device *phydev)
static int en8811h_load_firmware(struct phy_device *phydev)
{
- struct device *dev = &phydev->mdio.dev;
- const struct firmware *fw1, *fw2;
+ struct en8811h_priv *priv = phydev->priv;
int ret;
- ret = request_firmware_direct(&fw1, EN8811H_MD32_DM, dev);
- if (ret < 0)
- return ret;
-
- ret = request_firmware_direct(&fw2, EN8811H_MD32_DSP, dev);
- if (ret < 0)
- goto en8811h_load_firmware_rel1;
-
- ret = air_phy_buckpbus_reg_write(phydev, EN8811H_FW_CTRL_1,
- EN8811H_FW_CTRL_1_START);
- if (ret < 0)
- goto en8811h_load_firmware_out;
-
- ret = air_phy_buckpbus_reg_modify(phydev, EN8811H_FW_CTRL_2,
- EN8811H_FW_CTRL_2_LOADING,
- EN8811H_FW_CTRL_2_LOADING);
- if (ret < 0)
- goto en8811h_load_firmware_out;
-
- ret = air_write_buf(phydev, AIR_FW_ADDR_DM, fw1);
- if (ret < 0)
- goto en8811h_load_firmware_out;
-
- ret = air_write_buf(phydev, AIR_FW_ADDR_DSP, fw2);
- if (ret < 0)
- goto en8811h_load_firmware_out;
-
- ret = air_phy_buckpbus_reg_modify(phydev, EN8811H_FW_CTRL_2,
- EN8811H_FW_CTRL_2_LOADING, 0);
- if (ret < 0)
- goto en8811h_load_firmware_out;
-
- ret = en8811h_wait_mcu_ready(phydev);
- if (ret < 0)
- goto en8811h_load_firmware_out;
-
- en8811h_print_fw_version(phydev);
-
-en8811h_load_firmware_out:
- release_firmware(fw2);
-
-en8811h_load_firmware_rel1:
- release_firmware(fw1);
-
+ ret = air_en8811h_fw_download(&phydev->mdio, &priv->firmware_version);
if (ret < 0)
phydev_err(phydev, "Load firmware failed: %d\n", ret);
+ else
+ phydev_info(phydev, "MD32 firmware version: %08x\n",
+ priv->firmware_version);
return ret;
}
diff --git a/drivers/net/phy/air_phy_lib.c b/drivers/net/phy/air_phy_lib.c
index e314717843ae..672a82539dbe 100644
--- a/drivers/net/phy/air_phy_lib.c
+++ b/drivers/net/phy/air_phy_lib.c
@@ -8,8 +8,12 @@
*/
#include <linux/export.h>
+#include <linux/firmware.h>
+#include <linux/iopoll.h>
+#include <linux/mdio.h>
#include <linux/module.h>
#include <linux/phy.h>
+#include <linux/unaligned.h>
#include <linux/wordpart.h>
#include "air_phy_lib.h"
@@ -198,6 +202,299 @@ int air_phy_buckpbus_reg_modify(struct phy_device *phydev, u32 pbus_address,
}
EXPORT_SYMBOL_GPL(air_phy_buckpbus_reg_modify);
+static int __air_write_buf(struct mdio_device *mdiodev, u32 address,
+ const u8 *data, size_t len)
+{
+ unsigned int offset;
+ int ret;
+ u16 val;
+
+ ret = __mdiodev_write(mdiodev, AIR_BPBUS_MODE,
+ AIR_BPBUS_MODE_ADDR_INCR);
+ if (ret < 0)
+ return ret;
+
+ ret = __mdiodev_write(mdiodev, AIR_BPBUS_WR_ADDR_HIGH,
+ upper_16_bits(address));
+ if (ret < 0)
+ return ret;
+
+ ret = __mdiodev_write(mdiodev, AIR_BPBUS_WR_ADDR_LOW,
+ lower_16_bits(address));
+ if (ret < 0)
+ return ret;
+
+ for (offset = 0; offset < len; offset += 4) {
+ val = get_unaligned_le16(&data[offset + 2]);
+ ret = __mdiodev_write(mdiodev, AIR_BPBUS_WR_DATA_HIGH, val);
+ if (ret < 0)
+ return ret;
+
+ val = get_unaligned_le16(&data[offset]);
+ ret = __mdiodev_write(mdiodev, AIR_BPBUS_WR_DATA_LOW, val);
+ if (ret < 0)
+ return ret;
+ }
+
+ return 0;
+}
+
+/* phy_select_page() needs a phy_device, which does not exist yet. */
+static int __air_mdio_select_page(struct mdio_device *mdiodev, int page)
+{
+ int saved_page, ret;
+
+ saved_page = __mdiodev_read(mdiodev, AIR_EXT_PAGE_ACCESS);
+ if (saved_page < 0)
+ return saved_page;
+
+ if (saved_page != page) {
+ ret = __mdiodev_write(mdiodev, AIR_EXT_PAGE_ACCESS, page);
+ if (ret < 0)
+ return ret;
+ }
+
+ return saved_page;
+}
+
+static int __air_mdio_restore_page(struct mdio_device *mdiodev,
+ int saved_page, int page, int ret)
+{
+ int restore;
+
+ if (saved_page != page) {
+ restore = __mdiodev_write(mdiodev, AIR_EXT_PAGE_ACCESS,
+ saved_page);
+ if (ret >= 0 && restore < 0)
+ ret = restore;
+ }
+
+ return ret;
+}
+
+int air_fw_write_buf(struct mdio_device *mdiodev, u32 address,
+ const struct firmware *fw)
+{
+ size_t chunk, done = 0;
+ int saved_page, ret;
+
+ if (fw->size % 4) {
+ dev_err(&mdiodev->dev, "firmware size %zu is not a multiple of 4\n",
+ fw->size);
+ return -EINVAL;
+ }
+
+ while (done < fw->size) {
+ chunk = min_t(size_t, fw->size - done, AIR_FW_CHUNK_BYTES);
+
+ mutex_lock(&mdiodev->bus->mdio_lock);
+
+ saved_page = __air_mdio_select_page(mdiodev,
+ AIR_PHY_PAGE_EXTENDED_4);
+ if (saved_page < 0) {
+ ret = saved_page;
+ } else {
+ ret = __air_write_buf(mdiodev, address + done,
+ fw->data + done, chunk);
+ ret = __air_mdio_restore_page(mdiodev, saved_page,
+ AIR_PHY_PAGE_EXTENDED_4,
+ ret);
+ }
+
+ mutex_unlock(&mdiodev->bus->mdio_lock);
+ if (ret < 0)
+ return ret;
+
+ done += chunk;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(air_fw_write_buf);
+
+static int air_mdio_buckpbus_reg_read(struct mdio_device *mdiodev,
+ u32 pbus_address, u32 *pbus_data)
+{
+ int saved_page, ret;
+
+ mutex_lock(&mdiodev->bus->mdio_lock);
+
+ saved_page = __air_mdio_select_page(mdiodev, AIR_PHY_PAGE_EXTENDED_4);
+ if (saved_page < 0) {
+ ret = saved_page;
+ } else {
+ ret = __air_buckpbus_reg_read(mdiodev, pbus_address, pbus_data);
+ ret = __air_mdio_restore_page(mdiodev, saved_page,
+ AIR_PHY_PAGE_EXTENDED_4, ret);
+ }
+
+ mutex_unlock(&mdiodev->bus->mdio_lock);
+ return ret;
+}
+
+static int air_mdio_buckpbus_reg_write(struct mdio_device *mdiodev,
+ u32 pbus_address, u32 pbus_data)
+{
+ int saved_page, ret;
+
+ mutex_lock(&mdiodev->bus->mdio_lock);
+
+ saved_page = __air_mdio_select_page(mdiodev, AIR_PHY_PAGE_EXTENDED_4);
+ if (saved_page < 0) {
+ ret = saved_page;
+ } else {
+ ret = __air_buckpbus_reg_write(mdiodev, pbus_address,
+ pbus_data);
+ ret = __air_mdio_restore_page(mdiodev, saved_page,
+ AIR_PHY_PAGE_EXTENDED_4, ret);
+ }
+
+ mutex_unlock(&mdiodev->bus->mdio_lock);
+ return ret;
+}
+
+static int air_mdio_buckpbus_reg_modify(struct mdio_device *mdiodev,
+ u32 pbus_address, u32 mask, u32 set)
+{
+ int saved_page, ret;
+
+ mutex_lock(&mdiodev->bus->mdio_lock);
+
+ saved_page = __air_mdio_select_page(mdiodev, AIR_PHY_PAGE_EXTENDED_4);
+ if (saved_page < 0) {
+ ret = saved_page;
+ } else {
+ ret = __air_buckpbus_reg_modify(mdiodev, pbus_address,
+ mask, set);
+ ret = __air_mdio_restore_page(mdiodev, saved_page,
+ AIR_PHY_PAGE_EXTENDED_4, ret);
+ }
+
+ mutex_unlock(&mdiodev->bus->mdio_lock);
+ return ret;
+}
+
+/* mmd_phy_read() drops the errors from the three writes that select the
+ * register, so a failed selection reads a different one back as success.
+ */
+static int __air_mmd_read(struct mdio_device *mdiodev, u16 devad, u16 regnum)
+{
+ struct mii_bus *bus = mdiodev->bus;
+ int addr = mdiodev->addr;
+ int ret;
+
+ ret = __mdiobus_write(bus, addr, MII_MMD_CTRL, devad);
+ if (ret < 0)
+ return ret;
+
+ ret = __mdiobus_write(bus, addr, MII_MMD_DATA, regnum);
+ if (ret < 0)
+ return ret;
+
+ ret = __mdiobus_write(bus, addr, MII_MMD_CTRL,
+ devad | MII_MMD_CTRL_NOINCR);
+ if (ret < 0)
+ return ret;
+
+ return __mdiobus_read(bus, addr, MII_MMD_DATA);
+}
+
+static int air_mmd_status_read(struct mdio_device *mdiodev)
+{
+ int ret;
+
+ mutex_lock(&mdiodev->bus->mdio_lock);
+ ret = __air_mmd_read(mdiodev, MDIO_MMD_VEND1, EN8811H_PHY_FW_STATUS);
+ mutex_unlock(&mdiodev->bus->mdio_lock);
+
+ return ret;
+}
+
+int air_en8811h_wait_mcu_ready(struct mdio_device *mdiodev)
+{
+ int ret, reg_value;
+
+ ret = air_mdio_buckpbus_reg_write(mdiodev, EN8811H_FW_CTRL_1,
+ EN8811H_FW_CTRL_1_FINISH);
+ if (ret)
+ return ret;
+
+ /* Because of mdio-lock, may have to wait for multiple loads. A read
+ * error ends the poll at once, like phy_read_mmd_poll_timeout().
+ */
+ ret = read_poll_timeout(air_mmd_status_read, reg_value,
+ reg_value < 0 ||
+ reg_value == EN8811H_PHY_READY,
+ 20000, 7500000, true, mdiodev);
+ if (reg_value < 0)
+ return reg_value;
+ if (ret) {
+ dev_dbg(&mdiodev->dev, "MCU not ready: 0x%x\n", reg_value);
+ return -ENODEV;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(air_en8811h_wait_mcu_ready);
+
+int air_en8811h_fw_download(struct mdio_device *mdiodev, u32 *fw_version)
+{
+ struct device *dev = &mdiodev->dev;
+ const struct firmware *fw1, *fw2;
+ int ret;
+
+ ret = request_firmware_direct(&fw1, EN8811H_MD32_DM, dev);
+ if (ret < 0)
+ return ret;
+
+ ret = request_firmware_direct(&fw2, EN8811H_MD32_DSP, dev);
+ if (ret < 0)
+ goto air_fw_download_rel1;
+
+ ret = air_mdio_buckpbus_reg_write(mdiodev, EN8811H_FW_CTRL_1,
+ EN8811H_FW_CTRL_1_START);
+ if (ret < 0)
+ goto air_fw_download_out;
+
+ ret = air_mdio_buckpbus_reg_modify(mdiodev, EN8811H_FW_CTRL_2,
+ EN8811H_FW_CTRL_2_LOADING,
+ EN8811H_FW_CTRL_2_LOADING);
+ if (ret < 0)
+ goto air_fw_download_out;
+
+ ret = air_fw_write_buf(mdiodev, AIR_FW_ADDR_DM, fw1);
+ if (ret < 0)
+ goto air_fw_download_out;
+
+ ret = air_fw_write_buf(mdiodev, AIR_FW_ADDR_DSP, fw2);
+ if (ret < 0)
+ goto air_fw_download_out;
+
+ ret = air_mdio_buckpbus_reg_modify(mdiodev, EN8811H_FW_CTRL_2,
+ EN8811H_FW_CTRL_2_LOADING, 0);
+ if (ret < 0)
+ goto air_fw_download_out;
+
+ ret = air_en8811h_wait_mcu_ready(mdiodev);
+ if (ret < 0)
+ goto air_fw_download_out;
+
+ ret = air_mdio_buckpbus_reg_read(mdiodev, EN8811H_FW_VERSION,
+ fw_version);
+
+air_fw_download_out:
+ release_firmware(fw2);
+
+air_fw_download_rel1:
+ release_firmware(fw1);
+
+ /* No error print: callers log on their own terms, and a poller
+ * would repeat it on every retry.
+ */
+ return ret;
+}
+EXPORT_SYMBOL_GPL(air_en8811h_fw_download);
+
int air_phy_read_page(struct phy_device *phydev)
{
return __phy_read(phydev, AIR_EXT_PAGE_ACCESS);
diff --git a/drivers/net/phy/air_phy_lib.h b/drivers/net/phy/air_phy_lib.h
index 01bb32e7c7c9..c288b34f2ffc 100644
--- a/drivers/net/phy/air_phy_lib.h
+++ b/drivers/net/phy/air_phy_lib.h
@@ -10,12 +10,19 @@
#include <linux/phy.h>
+struct firmware;
+
#define AIR_EXT_PAGE_ACCESS 0x1f
#define AIR_PHY_PAGE_STANDARD 0x0000
#define AIR_PHY_PAGE_EXTENDED_1 0x0001
#define AIR_PHY_PAGE_EXTENDED_4 0x0004
+/* Bytes written between bus releases, so the other PHYs on it get a turn.
+ * At a 2.5 MHz MDC this size holds the bus for about 30 ms.
+ */
+#define AIR_FW_CHUNK_BYTES 2304
+
/* MII Registers Page 4*/
#define AIR_BPBUS_MODE 0x10
#define AIR_BPBUS_MODE_ADDR_FIXED 0x0000
@@ -29,6 +36,23 @@
#define AIR_BPBUS_RD_DATA_HIGH 0x17
#define AIR_BPBUS_RD_DATA_LOW 0x18
+#define EN8811H_MD32_DM "airoha/EthMD32.dm.bin"
+#define EN8811H_MD32_DSP "airoha/EthMD32.DSP.bin"
+
+#define AIR_FW_ADDR_DM 0x00000000
+#define AIR_FW_ADDR_DSP 0x00100000
+
+#define EN8811H_FW_CTRL_1 0x0f0018
+#define EN8811H_FW_CTRL_1_START 0x0
+#define EN8811H_FW_CTRL_1_FINISH 0x1
+#define EN8811H_FW_CTRL_2 0x800000
+#define EN8811H_FW_CTRL_2_LOADING BIT(11)
+
+#define EN8811H_PHY_FW_STATUS 0x8009
+#define EN8811H_PHY_READY 0x02
+
+#define EN8811H_FW_VERSION 0x3b3c
+
int air_phy_buckpbus_reg_modify(struct phy_device *phydev, u32 pbus_address,
u32 mask, u32 set);
int air_phy_buckpbus_reg_read(struct phy_device *phydev, u32 pbus_address,
@@ -38,4 +62,9 @@ int air_phy_buckpbus_reg_write(struct phy_device *phydev, u32 pbus_address,
int air_phy_read_page(struct phy_device *phydev);
int air_phy_write_page(struct phy_device *phydev, int page);
+int air_fw_write_buf(struct mdio_device *mdiodev, u32 address,
+ const struct firmware *fw);
+int air_en8811h_wait_mcu_ready(struct mdio_device *mdiodev);
+int air_en8811h_fw_download(struct mdio_device *mdiodev, u32 *fw_version);
+
#endif /* __AIR_PHY_LIB_H */
--
2.53.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [RFC PATCH net-next v3 4/6] net: phy: air: skip the download when the MD32 is already running
2026-09-12 13:04 [RFC PATCH net-next v3 0/6] net: mdio: an MDIO device driver for the Airoha EN8811H Aleksei Sviridkin
` (2 preceding siblings ...)
2026-09-12 13:04 ` [RFC PATCH net-next v3 3/6] net: phy: air: move the EN8811H firmware download into the library Aleksei Sviridkin
@ 2026-09-12 13:04 ` Aleksei Sviridkin
2026-09-12 13:04 ` [RFC PATCH net-next v3 5/6] net: mdio: add Airoha EN8811H MDIO device driver Aleksei Sviridkin
2026-09-12 13:04 ` [RFC PATCH net-next v3 6/6] net: mdio: en8811h: add the nested bus Aleksei Sviridkin
5 siblings, 0 replies; 7+ messages in thread
From: Aleksei Sviridkin @ 2026-09-12 13:04 UTC (permalink / raw)
To: andrew, andrew+netdev, hkallweit1, linux, davem, edumazet, kuba,
pabeni, horms, robh, krzk+dt, conor+dt
Cc: ericwouds, netdev, devicetree, linux-kernel, Aleksei Sviridkin
The download is unconditional, so a chip whose firmware was loaded by
something else - a bootloader, an earlier bind of the PHY driver, or
an MDIO device serving the chip - is reprogrammed at 144KB per probe.
Read the status register the loader already polls for readiness and
skip the download when it reports ready, only picking up the running
firmware's version. Adopting is reported back distinctly from loading,
because nothing on that path touches FW_CTRL_1: the PHY driver must
leave the MCU restart to .config_init() rather than assume probe
already did it.
The image in RAM now wins over the files on disk. Where the PHY node
carries no reset-gpios nothing clears that RAM on unbind, so writing
new firmware files and rebinding keeps the old image running and
reports its version as the current one. A power cycle, or a reset line
on the PHY node for phy_detach() to assert, brings the reload back.
Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
---
drivers/net/phy/air_en8811h.c | 4 ++--
drivers/net/phy/air_phy_lib.c | 23 +++++++++++++++++++++++
drivers/net/phy/air_phy_lib.h | 3 +++
3 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/drivers/net/phy/air_en8811h.c b/drivers/net/phy/air_en8811h.c
index 43d2eff808f1..c9b46cfc854f 100644
--- a/drivers/net/phy/air_en8811h.c
+++ b/drivers/net/phy/air_en8811h.c
@@ -1028,8 +1028,8 @@ static int en8811h_probe(struct phy_device *phydev)
if (ret < 0)
return ret;
- /* mcu has just restarted after firmware load */
- priv->mcu_needs_restart = false;
+ /* Firmware that was already running was never restarted here. */
+ priv->mcu_needs_restart = (ret == 1);
/* MDIO_DEVS1/2 empty, so set mmds_present bits here */
phydev->c45_ids.mmds_present |= MDIO_DEVS_PMAPMD | MDIO_DEVS_AN;
diff --git a/drivers/net/phy/air_phy_lib.c b/drivers/net/phy/air_phy_lib.c
index 672a82539dbe..2b1a73beca8d 100644
--- a/drivers/net/phy/air_phy_lib.c
+++ b/drivers/net/phy/air_phy_lib.c
@@ -410,6 +410,16 @@ static int air_mmd_status_read(struct mdio_device *mdiodev)
return ret;
}
+int air_en8811h_mcu_running(struct mdio_device *mdiodev)
+{
+ int ret = air_mmd_status_read(mdiodev);
+
+ if (ret < 0)
+ return ret;
+
+ return ret == EN8811H_PHY_READY;
+}
+
int air_en8811h_wait_mcu_ready(struct mdio_device *mdiodev)
{
int ret, reg_value;
@@ -443,6 +453,19 @@ int air_en8811h_fw_download(struct mdio_device *mdiodev, u32 *fw_version)
const struct firmware *fw1, *fw2;
int ret;
+ ret = air_en8811h_mcu_running(mdiodev);
+ if (ret < 0)
+ return ret;
+
+ if (ret) {
+ ret = air_mdio_buckpbus_reg_read(mdiodev, EN8811H_FW_VERSION,
+ fw_version);
+ if (ret < 0)
+ return ret;
+
+ return 1;
+ }
+
ret = request_firmware_direct(&fw1, EN8811H_MD32_DM, dev);
if (ret < 0)
return ret;
diff --git a/drivers/net/phy/air_phy_lib.h b/drivers/net/phy/air_phy_lib.h
index c288b34f2ffc..47b4bd0b7c1e 100644
--- a/drivers/net/phy/air_phy_lib.h
+++ b/drivers/net/phy/air_phy_lib.h
@@ -64,7 +64,10 @@ int air_phy_write_page(struct phy_device *phydev, int page);
int air_fw_write_buf(struct mdio_device *mdiodev, u32 address,
const struct firmware *fw);
+/* Returns 1 running, 0 dormant, negative on a failed status read. */
+int air_en8811h_mcu_running(struct mdio_device *mdiodev);
int air_en8811h_wait_mcu_ready(struct mdio_device *mdiodev);
+/* Returns 1 when it adopted firmware that was already running. */
int air_en8811h_fw_download(struct mdio_device *mdiodev, u32 *fw_version);
#endif /* __AIR_PHY_LIB_H */
--
2.53.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [RFC PATCH net-next v3 5/6] net: mdio: add Airoha EN8811H MDIO device driver
2026-09-12 13:04 [RFC PATCH net-next v3 0/6] net: mdio: an MDIO device driver for the Airoha EN8811H Aleksei Sviridkin
` (3 preceding siblings ...)
2026-09-12 13:04 ` [RFC PATCH net-next v3 4/6] net: phy: air: skip the download when the MD32 is already running Aleksei Sviridkin
@ 2026-09-12 13:04 ` Aleksei Sviridkin
2026-09-12 13:04 ` [RFC PATCH net-next v3 6/6] net: mdio: en8811h: add the nested bus Aleksei Sviridkin
5 siblings, 0 replies; 7+ messages in thread
From: Aleksei Sviridkin @ 2026-09-12 13:04 UTC (permalink / raw)
To: andrew, andrew+netdev, hkallweit1, linux, davem, edumazet, kuba,
pabeni, horms, robh, krzk+dt, conor+dt
Cc: ericwouds, netdev, devicetree, linux-kernel, Aleksei Sviridkin
Until its firmware has been downloaded the EN8811H is not an Ethernet
PHY, it is an MD32 microcontroller waiting in its bootloader. On
systems that keep the firmware files in a filesystem, the files become
readable long after the MDIO bus was scanned, and the PHY driver's
probe-time download then cannot work at boot.
Describe the chip as an MDIO device that polls for the files and
downloads through the shared library helper once they can be read; a
chip left running by the bootloader is adopted as-is. Polling rather
than deferred probing because request_firmware_direct() has no
usermode-helper fallback: an unmounted rootfs fails at once, and a
deferral only leaves the device on the deferred-probe list until
something else retries it, which need not happen when the files
appear. There is no give-up path, since installing the firmware
package on a running system is a normal thing to do.
The reset line is claimed here rather than on the PHY node, and it is
cycled only while the MD32 does not report a running firmware: that
firmware lives in volatile RAM, so an assert on a running chip - such
as the one phy_detach() performs on a PHY-node reset - would wipe it.
Resume repeats the reset decision and the download in line, since a
suspend that cut power leaves the MD32 back in its bootloader.
Nothing yet publishes a PHY: this driver takes the chip over, and the
bus that exposes it to the device tree is the next patch.
Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
---
Notes:
Splitting the series there keeps the download and its retry policy
separate from what registering a bus costs, which is its own failure
mode with its own backoff.
A status read that fails says nothing about the firmware, so the reset
line is left alone unless it is already asserted; clearing an asserted
one is worth a try, since nothing answers through it.
The download registers both blobs with the firmware cache, so the reload
on resume reaches a filesystem only if that registration failed. On the
download path that registration is already done: request_firmware_direct()
passes no FW_OPT_NOCACHE, so assign_fw() has called fw_add_devm_name()
for both names. It is the adoption path, which never calls
request_firmware at all, that needs it.
The reload on resume is not cheap: 144 KB over MDIO is about two seconds,
and the readiness poll after it allows another seven and a half. The rest
of the resume chain waits for it, which is the price of having the
firmware back before the PHY below runs its own resume.
MAINTAINERS | 2 +
drivers/net/mdio/Kconfig | 13 ++
drivers/net/mdio/Makefile | 1 +
drivers/net/mdio/mdio-airoha-en8811h.c | 197 +++++++++++++++++++++++
drivers/net/phy/air_phy_lib.c | 1 +
drivers/net/phy/air_phy_lib.h | 8 +-
include/linux/mdio/mdio-airoha-en8811h.h | 24 +++
7 files changed, 239 insertions(+), 7 deletions(-)
create mode 100644 drivers/net/mdio/mdio-airoha-en8811h.c
create mode 100644 include/linux/mdio/mdio-airoha-en8811h.h
diff --git a/MAINTAINERS b/MAINTAINERS
index 4ca19275f4d0..3bd86df2be57 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -755,6 +755,8 @@ M: Aleksei Sviridkin <f@lex.la>
L: netdev@vger.kernel.org
S: Maintained
F: Documentation/devicetree/bindings/net/airoha,en8811h-mcu.yaml
+F: drivers/net/mdio/mdio-airoha-en8811h.c
+F: include/linux/mdio/mdio-airoha-en8811h.h
AIROHA ETHERNET DRIVER
M: Lorenzo Bianconi <lorenzo@kernel.org>
diff --git a/drivers/net/mdio/Kconfig b/drivers/net/mdio/Kconfig
index d44278f26fab..57c83bfd4090 100644
--- a/drivers/net/mdio/Kconfig
+++ b/drivers/net/mdio/Kconfig
@@ -29,6 +29,19 @@ config MDIO_AIROHA
This module provides a driver for the MDIO busses found in the
Airoha AN7583 SoC's.
+config MDIO_AIROHA_EN8811H
+ tristate "Airoha EN8811H MDIO device support"
+ depends on OF_MDIO
+ depends on FW_LOADER
+ select AIR_NET_PHYLIB
+ imply AIR_EN8811H_PHY
+ help
+ This module provides a driver for the Airoha EN8811H, which is an
+ MD32 microcontroller until firmware is downloaded into it and only
+ becomes an Ethernet PHY afterwards. The driver downloads that
+ firmware once it becomes readable, or leaves in place firmware a
+ bootloader already started.
+
config MDIO_SUN4I
tristate "Allwinner sun4i MDIO interface support"
depends on ARCH_SUNXI || COMPILE_TEST
diff --git a/drivers/net/mdio/Makefile b/drivers/net/mdio/Makefile
index 048586746026..06d096675dac 100644
--- a/drivers/net/mdio/Makefile
+++ b/drivers/net/mdio/Makefile
@@ -6,6 +6,7 @@ obj-$(CONFIG_FWNODE_MDIO) += fwnode_mdio.o
obj-$(CONFIG_OF_MDIO) += of_mdio.o
obj-$(CONFIG_MDIO_AIROHA) += mdio-airoha.o
+obj-$(CONFIG_MDIO_AIROHA_EN8811H) += mdio-airoha-en8811h.o
obj-$(CONFIG_MDIO_ASPEED) += mdio-aspeed.o
obj-$(CONFIG_MDIO_BCM_IPROC) += mdio-bcm-iproc.o
obj-$(CONFIG_MDIO_BCM_UNIMAC) += mdio-bcm-unimac.o
diff --git a/drivers/net/mdio/mdio-airoha-en8811h.c b/drivers/net/mdio/mdio-airoha-en8811h.c
new file mode 100644
index 000000000000..b88e3c014d15
--- /dev/null
+++ b/drivers/net/mdio/mdio-airoha-en8811h.c
@@ -0,0 +1,197 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Airoha EN8811H MDIO device driver
+ *
+ * The EN8811H is an MD32 microcontroller until firmware is downloaded into
+ * it, and only then an Ethernet PHY.
+ *
+ * Copyright (C) 2026 Aleksei Sviridkin <f@lex.la>
+ */
+
+#include <linux/delay.h>
+#include <linux/firmware.h>
+#include <linux/gpio/consumer.h>
+#include <linux/mdio.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/pm.h>
+#include <linux/property.h>
+#include <linux/workqueue.h>
+
+#include <linux/mdio/mdio-airoha-en8811h.h>
+
+#define EN8811H_FW_POLL_MIN_MS 1000
+#define EN8811H_FW_POLL_MAX_MS 30000
+#define EN8811H_FW_WARN_MS 60000
+
+struct en8811h_mcu {
+ struct mdio_device *mdiodev;
+ struct gpio_desc *reset_gpio;
+ struct delayed_work fw_poll;
+ unsigned int poll_ms;
+ unsigned int waited_ms;
+ u32 fw_version;
+ bool warned;
+};
+
+static void en8811h_mcu_fw_poll(struct work_struct *work)
+{
+ struct en8811h_mcu *mcu = container_of(to_delayed_work(work),
+ struct en8811h_mcu, fw_poll);
+ struct device *dev = &mcu->mdiodev->dev;
+ int cached, ret;
+
+ ret = air_en8811h_fw_download(mcu->mdiodev, &mcu->fw_version);
+ if (ret >= 0) {
+ dev_dbg(dev, "firmware %08x running after %ums\n",
+ mcu->fw_version, mcu->waited_ms);
+ cached = firmware_request_cache(dev, EN8811H_MD32_DM);
+ ret = firmware_request_cache(dev, EN8811H_MD32_DSP) ?: cached;
+ if (ret)
+ dev_warn(dev, "not cached, resume will read the files off a filesystem: %pe\n",
+ ERR_PTR(ret));
+ return;
+ }
+
+ if (!mcu->warned && mcu->waited_ms >= EN8811H_FW_WARN_MS) {
+ if (ret == -ENOENT)
+ dev_warn(dev, "still waiting for %s and %s\n",
+ EN8811H_MD32_DM, EN8811H_MD32_DSP);
+ else
+ dev_warn(dev, "firmware download keeps failing: %pe\n",
+ ERR_PTR(ret));
+ mcu->warned = true;
+ }
+
+ /* Count the sleep ahead: the first run was immediate. */
+ mcu->waited_ms += mcu->poll_ms;
+ queue_delayed_work(system_freezable_wq, &mcu->fw_poll,
+ msecs_to_jiffies(mcu->poll_ms));
+ mcu->poll_ms = min(mcu->poll_ms * 2, EN8811H_FW_POLL_MAX_MS);
+}
+
+/* The firmware lives in volatile RAM: no reset while the MD32 reports ready. */
+static void en8811h_mcu_reset_unless_running(struct en8811h_mcu *mcu)
+{
+ struct mdio_device *mdiodev = mcu->mdiodev;
+ struct device *dev = &mdiodev->dev;
+ u32 assert_us = 0, deassert_us = 0;
+ int ret;
+
+ ret = air_en8811h_mcu_running(mdiodev);
+ if (ret > 0) {
+ dev_dbg(dev, "MD32 already running, leaving reset alone\n");
+ return;
+ }
+
+ if (!mcu->reset_gpio)
+ return;
+
+ /* A failed read does not mean the firmware is gone: leave a
+ * deasserted line alone, and clear an asserted one before giving up.
+ */
+ if (ret < 0 && gpiod_get_value_cansleep(mcu->reset_gpio) <= 0) {
+ dev_dbg(dev, "MD32 state unknown (%d), leaving reset alone\n",
+ ret);
+ return;
+ }
+
+ device_property_read_u32(dev, "reset-assert-us", &assert_us);
+ device_property_read_u32(dev, "reset-deassert-us", &deassert_us);
+
+ ret = gpiod_direction_output(mcu->reset_gpio, 1);
+ if (ret) {
+ dev_warn(dev, "reset not asserted: %pe\n", ERR_PTR(ret));
+ return;
+ }
+
+ if (assert_us)
+ fsleep(assert_us);
+
+ gpiod_set_value_cansleep(mcu->reset_gpio, 0);
+ if (deassert_us)
+ fsleep(deassert_us);
+}
+
+static int en8811h_mcu_probe(struct mdio_device *mdiodev)
+{
+ struct device *dev = &mdiodev->dev;
+ struct en8811h_mcu *mcu;
+
+ mcu = devm_kzalloc(dev, sizeof(*mcu), GFP_KERNEL);
+ if (!mcu)
+ return -ENOMEM;
+
+ mcu->mdiodev = mdiodev;
+ mdiodev_set_drvdata(mdiodev, mcu);
+
+ /* The core claims reset-gpios only for devices flagged as PHYs. */
+ mcu->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_ASIS);
+ if (IS_ERR(mcu->reset_gpio))
+ return dev_err_probe(dev, PTR_ERR(mcu->reset_gpio),
+ "failed to get reset GPIO\n");
+
+ if (mcu->reset_gpio)
+ gpiod_set_consumer_name(mcu->reset_gpio, "EN8811H reset");
+
+ en8811h_mcu_reset_unless_running(mcu);
+
+ mcu->poll_ms = EN8811H_FW_POLL_MIN_MS;
+ INIT_DELAYED_WORK(&mcu->fw_poll, en8811h_mcu_fw_poll);
+ /* Freezable: neither the file lookup nor the download may land on
+ * a suspending bus.
+ */
+ queue_delayed_work(system_freezable_wq, &mcu->fw_poll, 0);
+
+ return 0;
+}
+
+static void en8811h_mcu_remove(struct mdio_device *mdiodev)
+{
+ struct en8811h_mcu *mcu = mdiodev_get_drvdata(mdiodev);
+
+ cancel_delayed_work_sync(&mcu->fw_poll);
+}
+
+static int en8811h_mcu_resume(struct device *dev)
+{
+ struct en8811h_mcu *mcu = dev_get_drvdata(dev);
+ int ret;
+
+ /* Synchronous: the poll's workqueue is freezable and thaws only
+ * after the resume callbacks have run.
+ */
+ en8811h_mcu_reset_unless_running(mcu);
+ ret = air_en8811h_fw_download(mcu->mdiodev, &mcu->fw_version);
+ if (ret < 0)
+ dev_err(dev, "firmware not restored: %pe\n", ERR_PTR(ret));
+
+ return 0;
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(en8811h_mcu_pm_ops, NULL, en8811h_mcu_resume);
+
+static const struct of_device_id en8811h_mcu_of_match[] = {
+ { .compatible = "airoha,en8811h-mcu" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, en8811h_mcu_of_match);
+
+static struct mdio_driver en8811h_mcu_driver = {
+ .probe = en8811h_mcu_probe,
+ .remove = en8811h_mcu_remove,
+ .mdiodrv.driver = {
+ .name = "airoha-en8811h-mcu",
+ .of_match_table = en8811h_mcu_of_match,
+ .pm = pm_sleep_ptr(&en8811h_mcu_pm_ops),
+ },
+};
+
+mdio_module_driver(en8811h_mcu_driver);
+
+MODULE_FIRMWARE(EN8811H_MD32_DM);
+MODULE_FIRMWARE(EN8811H_MD32_DSP);
+
+MODULE_DESCRIPTION("Airoha EN8811H MDIO device driver");
+MODULE_AUTHOR("Aleksei Sviridkin <f@lex.la>");
+MODULE_LICENSE("GPL");
diff --git a/drivers/net/phy/air_phy_lib.c b/drivers/net/phy/air_phy_lib.c
index 2b1a73beca8d..c71322f16c21 100644
--- a/drivers/net/phy/air_phy_lib.c
+++ b/drivers/net/phy/air_phy_lib.c
@@ -419,6 +419,7 @@ int air_en8811h_mcu_running(struct mdio_device *mdiodev)
return ret == EN8811H_PHY_READY;
}
+EXPORT_SYMBOL_GPL(air_en8811h_mcu_running);
int air_en8811h_wait_mcu_ready(struct mdio_device *mdiodev)
{
diff --git a/drivers/net/phy/air_phy_lib.h b/drivers/net/phy/air_phy_lib.h
index 47b4bd0b7c1e..764f832a02a7 100644
--- a/drivers/net/phy/air_phy_lib.h
+++ b/drivers/net/phy/air_phy_lib.h
@@ -8,6 +8,7 @@
#ifndef __AIR_PHY_LIB_H
#define __AIR_PHY_LIB_H
+#include <linux/mdio/mdio-airoha-en8811h.h>
#include <linux/phy.h>
struct firmware;
@@ -36,9 +37,6 @@ struct firmware;
#define AIR_BPBUS_RD_DATA_HIGH 0x17
#define AIR_BPBUS_RD_DATA_LOW 0x18
-#define EN8811H_MD32_DM "airoha/EthMD32.dm.bin"
-#define EN8811H_MD32_DSP "airoha/EthMD32.DSP.bin"
-
#define AIR_FW_ADDR_DM 0x00000000
#define AIR_FW_ADDR_DSP 0x00100000
@@ -64,10 +62,6 @@ int air_phy_write_page(struct phy_device *phydev, int page);
int air_fw_write_buf(struct mdio_device *mdiodev, u32 address,
const struct firmware *fw);
-/* Returns 1 running, 0 dormant, negative on a failed status read. */
-int air_en8811h_mcu_running(struct mdio_device *mdiodev);
int air_en8811h_wait_mcu_ready(struct mdio_device *mdiodev);
-/* Returns 1 when it adopted firmware that was already running. */
-int air_en8811h_fw_download(struct mdio_device *mdiodev, u32 *fw_version);
#endif /* __AIR_PHY_LIB_H */
diff --git a/include/linux/mdio/mdio-airoha-en8811h.h b/include/linux/mdio/mdio-airoha-en8811h.h
new file mode 100644
index 000000000000..8a073a1b7ee6
--- /dev/null
+++ b/include/linux/mdio/mdio-airoha-en8811h.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2023, 2026 Airoha Technology Corp.
+ * Copyright (C) 2026 Aleksei Sviridkin <f@lex.la>
+ */
+
+#ifndef __LINUX_MDIO_AIROHA_EN8811H_H
+#define __LINUX_MDIO_AIROHA_EN8811H_H
+
+#include <linux/types.h>
+
+struct mdio_device;
+
+#define EN8811H_MD32_DM "airoha/EthMD32.dm.bin"
+#define EN8811H_MD32_DSP "airoha/EthMD32.DSP.bin"
+
+/* Returns 1 when the firmware runs, 0 when the MD32 is still in its
+ * bootloader, and negative on a failed status read.
+ */
+int air_en8811h_mcu_running(struct mdio_device *mdiodev);
+/* Returns 1 when firmware was already running and was left in place. */
+int air_en8811h_fw_download(struct mdio_device *mdiodev, u32 *fw_version);
+
+#endif /* __LINUX_MDIO_AIROHA_EN8811H_H */
--
2.53.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [RFC PATCH net-next v3 6/6] net: mdio: en8811h: add the nested bus
2026-09-12 13:04 [RFC PATCH net-next v3 0/6] net: mdio: an MDIO device driver for the Airoha EN8811H Aleksei Sviridkin
` (4 preceding siblings ...)
2026-09-12 13:04 ` [RFC PATCH net-next v3 5/6] net: mdio: add Airoha EN8811H MDIO device driver Aleksei Sviridkin
@ 2026-09-12 13:04 ` Aleksei Sviridkin
5 siblings, 0 replies; 7+ messages in thread
From: Aleksei Sviridkin @ 2026-09-12 13:04 UTC (permalink / raw)
To: andrew, andrew+netdev, hkallweit1, linux, davem, edumazet, kuba,
pabeni, horms, robh, krzk+dt, conor+dt
Cc: ericwouds, netdev, devicetree, linux-kernel, Aleksei Sviridkin
Registering the bus is what publishes the PHY, so it can only happen
once the MD32 runs its firmware. Giving the PHY a bus of its own rather
than the parent lets the device tree describe it normally, interrupt
included, and leaves the reset line owned by the MCU, where the PHY
cannot assert it. Only the address the MD32 answers on is passed
through.
That split puts the PHY driver and this one on two mutexes: the PHY
holds the child bus lock across a whole paged sequence while each frame
under it takes only the parent, so a chip access holding the parent
alone would land between two of those frames and step on the state the
PHY left mid-sequence - the buckpbus mode and address registers it had
already written. The library therefore holds the child lock across the
whole of its own chip access, and the caller hands it the bus to take or
nothing when there is none. Only the firmware read stays outside: those
files may have to come from a filesystem reached over that very PHY.
Registering the bus can fail on its own, so it becomes a second retry
phase. Where the wait for firmware files never gives up, this one does
once its minute is spent - except on a deferred probe, which nothing but
a retry resolves. A failed reload on resume goes back to that poller,
which restores the chip and not the port.
The sysfs bind attributes are suppressed, because unregistering this bus
while its PHY is attached leaves the consumer holding a phy_device whose
driver is gone, and this driver cannot tell a consumer it does not know
to let go. Module unload needs no such guard, since attaching a PHY
takes a reference on the child bus owner, which is this module. Removing
the parent MDIO bus still reaches this driver's remove and is not
covered; that wants a way for a bus to tell its PHYs' consumers to let
go.
Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
---
Notes:
Why the registration phase gives up where the wait for firmware does
not: every failed registration repeats a bus creation, a message from
the MDIO core and a pair of uevents. Firmware files are the opposite
case, since the package carrying them can be installed at any time.
Why the deferral is exempt, since the default configuration hides the
reason. fwnode_mdiobus_phy_device_register() runs fwnode_irq_get()'s
deferral through driver_deferred_probe_check_state(), which answers
-ETIMEDOUT once deferred_probe_timeout has expired, or -ENODEV when the
kernel is built without modules; neither escapes, and the PHY is
registered with the bus default that mdiobus_alloc() filled with
PHY_POLL. So a PHY that asks for an interrupt gets one only while its
controller can still defer the registration. With the timeout at its
default of ten seconds this driver, which registers only once firmware
files can be read, is always past that point and never sees a deferral
at all. But the timeout is a kernel parameter: a negative value is
documented as infinite, the timer is then never armed, and every
successful driver registration restarts it while it is pending. Under
either setting the deferral persists until the dependency shows up, and
a driver that stopped retrying after a minute would leave the PHY absent
until reboot, with fw_running still true so neither the poller nor
resume tries again.
Why a failed reload on resume restores the chip and not the port: the
PHY below resumes next, its phy_init_hw() runs against a chip still in
its bootloader and fails, and when the poller later gets the firmware
back nothing runs that resume again.
Both lock helpers in the library take mdio_lock directly rather than
through phylib's phy_lock_mdio_bus(), which keys off a phy_device: this
code runs before one exists for the chip, and the child bus never has
one at all.
drivers/net/mdio/mdio-airoha-en8811h.c | 203 +++++++++++++++++++++--
drivers/net/phy/air_en8811h.c | 7 +-
drivers/net/phy/air_phy_lib.c | 89 +++++++---
drivers/net/phy/air_phy_lib.h | 5 +-
include/linux/mdio/mdio-airoha-en8811h.h | 11 +-
5 files changed, 271 insertions(+), 44 deletions(-)
diff --git a/drivers/net/mdio/mdio-airoha-en8811h.c b/drivers/net/mdio/mdio-airoha-en8811h.c
index b88e3c014d15..7785525c57a6 100644
--- a/drivers/net/mdio/mdio-airoha-en8811h.c
+++ b/drivers/net/mdio/mdio-airoha-en8811h.c
@@ -14,6 +14,8 @@
#include <linux/mdio.h>
#include <linux/module.h>
#include <linux/of.h>
+#include <linux/of_mdio.h>
+#include <linux/phy.h>
#include <linux/pm.h>
#include <linux/property.h>
#include <linux/workqueue.h>
@@ -28,12 +30,109 @@ struct en8811h_mcu {
struct mdio_device *mdiodev;
struct gpio_desc *reset_gpio;
struct delayed_work fw_poll;
+ struct mii_bus *bus;
unsigned int poll_ms;
unsigned int waited_ms;
u32 fw_version;
bool warned;
+ bool fw_running;
};
+static int en8811h_mcu_read(struct mii_bus *bus, int addr, int regnum)
+{
+ struct en8811h_mcu *mcu = bus->priv;
+
+ if (addr != mcu->mdiodev->addr)
+ return -ENODEV;
+
+ return mdiobus_read_nested(mcu->mdiodev->bus, addr, regnum);
+}
+
+static int en8811h_mcu_write(struct mii_bus *bus, int addr, int regnum, u16 val)
+{
+ struct en8811h_mcu *mcu = bus->priv;
+
+ if (addr != mcu->mdiodev->addr)
+ return -ENODEV;
+
+ return mdiobus_write_nested(mcu->mdiodev->bus, addr, regnum, val);
+}
+
+static int en8811h_mcu_read_c45(struct mii_bus *bus, int addr, int devad,
+ int regnum)
+{
+ struct en8811h_mcu *mcu = bus->priv;
+
+ if (addr != mcu->mdiodev->addr)
+ return -ENODEV;
+
+ return mdiobus_c45_read_nested(mcu->mdiodev->bus, addr, devad, regnum);
+}
+
+static int en8811h_mcu_write_c45(struct mii_bus *bus, int addr, int devad,
+ int regnum, u16 val)
+{
+ struct en8811h_mcu *mcu = bus->priv;
+
+ if (addr != mcu->mdiodev->addr)
+ return -ENODEV;
+
+ return mdiobus_c45_write_nested(mcu->mdiodev->bus, addr, devad, regnum,
+ val);
+}
+
+static int en8811h_mcu_bus_register(struct en8811h_mcu *mcu)
+{
+ struct mii_bus *parent = mcu->mdiodev->bus;
+ struct device *dev = &mcu->mdiodev->dev;
+ struct device_node *np;
+ struct mii_bus *bus;
+ int ret;
+
+ np = of_get_child_by_name(dev->of_node, "mdio");
+ if (!np)
+ return -ENODEV;
+
+ /* Not devm: this is retried, and a devm bus would only be freed at
+ * detach.
+ */
+ bus = mdiobus_alloc();
+ if (!bus) {
+ of_node_put(np);
+ return -ENOMEM;
+ }
+
+ bus->name = "airoha-en8811h";
+ snprintf(bus->id, MII_BUS_ID_SIZE, "%s", dev_name(dev));
+ bus->priv = mcu;
+ bus->parent = dev;
+ if (parent->read && parent->write) {
+ bus->read = en8811h_mcu_read;
+ bus->write = en8811h_mcu_write;
+ }
+ if (parent->read_c45 && parent->write_c45) {
+ bus->read_c45 = en8811h_mcu_read_c45;
+ bus->write_c45 = en8811h_mcu_write_c45;
+ }
+
+ ret = of_mdiobus_register(bus, np);
+ of_node_put(np);
+ if (!ret && !mdiobus_get_phy(bus, mcu->mdiodev->addr)) {
+ /* An ID read that failed leaves the bus registered and the
+ * PHY absent; of_mdiobus_register() returns 0 either way.
+ */
+ mdiobus_unregister(bus);
+ ret = -ENODEV;
+ }
+ if (ret) {
+ mdiobus_free(bus);
+ return ret;
+ }
+
+ mcu->bus = bus;
+ return 0;
+}
+
static void en8811h_mcu_fw_poll(struct work_struct *work)
{
struct en8811h_mcu *mcu = container_of(to_delayed_work(work),
@@ -41,8 +140,12 @@ static void en8811h_mcu_fw_poll(struct work_struct *work)
struct device *dev = &mcu->mdiodev->dev;
int cached, ret;
- ret = air_en8811h_fw_download(mcu->mdiodev, &mcu->fw_version);
- if (ret >= 0) {
+ if (!mcu->fw_running) {
+ ret = air_en8811h_fw_download(mcu->mdiodev, &mcu->fw_version,
+ mcu->bus);
+ if (ret < 0)
+ goto retry;
+
dev_dbg(dev, "firmware %08x running after %ums\n",
mcu->fw_version, mcu->waited_ms);
cached = firmware_request_cache(dev, EN8811H_MD32_DM);
@@ -50,19 +153,38 @@ static void en8811h_mcu_fw_poll(struct work_struct *work)
if (ret)
dev_warn(dev, "not cached, resume will read the files off a filesystem: %pe\n",
ERR_PTR(ret));
- return;
+ mcu->fw_running = true;
+ mcu->poll_ms = EN8811H_FW_POLL_MIN_MS;
+ mcu->waited_ms = 0;
+ mcu->warned = false;
}
+ /* Resume re-runs the download, so the bus can already be here. */
+ ret = mcu->bus ? 0 : en8811h_mcu_bus_register(mcu);
+ if (!ret)
+ return;
+
+retry:
if (!mcu->warned && mcu->waited_ms >= EN8811H_FW_WARN_MS) {
- if (ret == -ENOENT)
- dev_warn(dev, "still waiting for %s and %s\n",
- EN8811H_MD32_DM, EN8811H_MD32_DSP);
+ if (!mcu->fw_running)
+ dev_warn(dev, "no firmware after %ums of waiting for %s and %s: %pe\n",
+ mcu->waited_ms, EN8811H_MD32_DM,
+ EN8811H_MD32_DSP, ERR_PTR(ret));
else
- dev_warn(dev, "firmware download keeps failing: %pe\n",
+ dev_warn(dev, "still no PHY at address %d, %ums after the firmware started: %pe\n",
+ mcu->mdiodev->addr, mcu->waited_ms,
ERR_PTR(ret));
mcu->warned = true;
}
+ /* Registering again repeats the MDIO core's message and its uevents,
+ * so this phase gives up - except on a deferral, which only a retry
+ * resolves and which deferred_probe_timeout can make permanent.
+ */
+ if (mcu->fw_running && ret != -EPROBE_DEFER &&
+ mcu->waited_ms >= EN8811H_FW_WARN_MS)
+ return;
+
/* Count the sleep ahead: the first run was immediate. */
mcu->waited_ms += mcu->poll_ms;
queue_delayed_work(system_freezable_wq, &mcu->fw_poll,
@@ -78,7 +200,7 @@ static void en8811h_mcu_reset_unless_running(struct en8811h_mcu *mcu)
u32 assert_us = 0, deassert_us = 0;
int ret;
- ret = air_en8811h_mcu_running(mdiodev);
+ ret = air_en8811h_mcu_running(mdiodev, mcu->bus);
if (ret > 0) {
dev_dbg(dev, "MD32 already running, leaving reset alone\n");
return;
@@ -117,6 +239,8 @@ static int en8811h_mcu_probe(struct mdio_device *mdiodev)
{
struct device *dev = &mdiodev->dev;
struct en8811h_mcu *mcu;
+ struct device_node *np;
+ unsigned int phys = 0;
mcu = devm_kzalloc(dev, sizeof(*mcu), GFP_KERNEL);
if (!mcu)
@@ -125,6 +249,43 @@ static int en8811h_mcu_probe(struct mdio_device *mdiodev)
mcu->mdiodev = mdiodev;
mdiodev_set_drvdata(mdiodev, mcu);
+ /* Registration needs this only once the firmware runs, but a DT
+ * hole should fail the bind now, not as a work-item error later.
+ */
+ np = of_get_child_by_name(dev->of_node, "mdio");
+ if (!np || !of_device_is_available(np)) {
+ of_node_put(np);
+ return dev_err_probe(dev, -ENODEV,
+ "no usable mdio node describing the PHY\n");
+ }
+
+ /* Only the address this core occupies on the parent bus is passed
+ * through, so a node at any other one will never respond.
+ */
+ for_each_available_child_of_node_scoped(np, child) {
+ u32 addr;
+
+ if (of_property_read_u32(child, "reg", &addr))
+ continue;
+ if (addr != mdiodev->addr) {
+ dev_err(dev, "%pOF: address %u is not answered here, only %u\n",
+ child, addr, mdiodev->addr);
+ of_node_put(np);
+ return -EINVAL;
+ }
+ phys++;
+ }
+ of_node_put(np);
+
+ if (!phys)
+ return dev_err_probe(dev, -ENODEV,
+ "mdio node describes no PHY\n");
+
+ /* A truncated bus name loses the address that makes it unique. */
+ if (strlen(dev_name(dev)) >= MII_BUS_ID_SIZE)
+ return dev_err_probe(dev, -ENAMETOOLONG,
+ "name does not fit an MDIO bus id\n");
+
/* The core claims reset-gpios only for devices flagged as PHYs. */
mcu->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_ASIS);
if (IS_ERR(mcu->reset_gpio))
@@ -151,6 +312,10 @@ static void en8811h_mcu_remove(struct mdio_device *mdiodev)
struct en8811h_mcu *mcu = mdiodev_get_drvdata(mdiodev);
cancel_delayed_work_sync(&mcu->fw_poll);
+ if (mcu->bus) {
+ mdiobus_unregister(mcu->bus);
+ mdiobus_free(mcu->bus);
+ }
}
static int en8811h_mcu_resume(struct device *dev)
@@ -158,13 +323,27 @@ static int en8811h_mcu_resume(struct device *dev)
struct en8811h_mcu *mcu = dev_get_drvdata(dev);
int ret;
+ /* Nothing to redo: the poll is armed and thaws with everything else. */
+ if (!mcu->fw_running)
+ return 0;
+
/* Synchronous: the poll's workqueue is freezable and thaws only
* after the resume callbacks have run.
*/
en8811h_mcu_reset_unless_running(mcu);
- ret = air_en8811h_fw_download(mcu->mdiodev, &mcu->fw_version);
- if (ret < 0)
- dev_err(dev, "firmware not restored: %pe\n", ERR_PTR(ret));
+ ret = air_en8811h_fw_download(mcu->mdiodev, &mcu->fw_version, mcu->bus);
+ if (ret < 0) {
+ dev_err(dev, "firmware not restored, reloading: %pe\n",
+ ERR_PTR(ret));
+ mcu->fw_running = false;
+ mcu->poll_ms = EN8811H_FW_POLL_MIN_MS;
+ mcu->waited_ms = 0;
+ mcu->warned = false;
+ /* The poll may already be pending on a long backoff, and
+ * queue_delayed_work() would leave that timer alone.
+ */
+ mod_delayed_work(system_freezable_wq, &mcu->fw_poll, 0);
+ }
return 0;
}
@@ -184,6 +363,8 @@ static struct mdio_driver en8811h_mcu_driver = {
.name = "airoha-en8811h-mcu",
.of_match_table = en8811h_mcu_of_match,
.pm = pm_sleep_ptr(&en8811h_mcu_pm_ops),
+ /* No safe teardown under an attached PHY. */
+ .suppress_bind_attrs = true,
},
};
diff --git a/drivers/net/phy/air_en8811h.c b/drivers/net/phy/air_en8811h.c
index c9b46cfc854f..940379e2737b 100644
--- a/drivers/net/phy/air_en8811h.c
+++ b/drivers/net/phy/air_en8811h.c
@@ -258,7 +258,7 @@ static int en8811h_wait_mcu_ready(struct phy_device *phydev)
{
int ret;
- ret = air_en8811h_wait_mcu_ready(&phydev->mdio);
+ ret = air_en8811h_wait_mcu_ready(&phydev->mdio, false);
if (ret < 0)
phydev_err(phydev, "MCU not ready: %pe\n", ERR_PTR(ret));
@@ -324,7 +324,7 @@ static int an8811hb_load_file(struct phy_device *phydev, const char *name,
if (ret < 0)
return ret;
- ret = air_fw_write_buf(&phydev->mdio, address, fw);
+ ret = air_fw_write_buf(&phydev->mdio, address, fw, false);
release_firmware(fw);
return ret;
}
@@ -423,7 +423,8 @@ static int en8811h_load_firmware(struct phy_device *phydev)
struct en8811h_priv *priv = phydev->priv;
int ret;
- ret = air_en8811h_fw_download(&phydev->mdio, &priv->firmware_version);
+ ret = air_en8811h_fw_download(&phydev->mdio, &priv->firmware_version,
+ NULL);
if (ret < 0)
phydev_err(phydev, "Load firmware failed: %d\n", ret);
else
diff --git a/drivers/net/phy/air_phy_lib.c b/drivers/net/phy/air_phy_lib.c
index c71322f16c21..5902a6ba3643 100644
--- a/drivers/net/phy/air_phy_lib.c
+++ b/drivers/net/phy/air_phy_lib.c
@@ -272,8 +272,31 @@ static int __air_mdio_restore_page(struct mdio_device *mdiodev,
return ret;
}
+static void air_mdiodev_lock(struct mdio_device *mdiodev, bool nested)
+{
+ if (nested)
+ mutex_lock_nested(&mdiodev->bus->mdio_lock, MDIO_MUTEX_NESTED);
+ else
+ mutex_lock(&mdiodev->bus->mdio_lock);
+}
+
+/* The PHY below reaches these registers under this lock through
+ * phy_select_page(); the firmware read must stay outside it.
+ */
+static void air_child_bus_lock(struct mii_bus *child_bus)
+{
+ if (child_bus)
+ mutex_lock(&child_bus->mdio_lock);
+}
+
+static void air_child_bus_unlock(struct mii_bus *child_bus)
+{
+ if (child_bus)
+ mutex_unlock(&child_bus->mdio_lock);
+}
+
int air_fw_write_buf(struct mdio_device *mdiodev, u32 address,
- const struct firmware *fw)
+ const struct firmware *fw, bool nested)
{
size_t chunk, done = 0;
int saved_page, ret;
@@ -287,7 +310,7 @@ int air_fw_write_buf(struct mdio_device *mdiodev, u32 address,
while (done < fw->size) {
chunk = min_t(size_t, fw->size - done, AIR_FW_CHUNK_BYTES);
- mutex_lock(&mdiodev->bus->mdio_lock);
+ air_mdiodev_lock(mdiodev, nested);
saved_page = __air_mdio_select_page(mdiodev,
AIR_PHY_PAGE_EXTENDED_4);
@@ -313,11 +336,12 @@ int air_fw_write_buf(struct mdio_device *mdiodev, u32 address,
EXPORT_SYMBOL_GPL(air_fw_write_buf);
static int air_mdio_buckpbus_reg_read(struct mdio_device *mdiodev,
- u32 pbus_address, u32 *pbus_data)
+ u32 pbus_address, u32 *pbus_data,
+ bool nested)
{
int saved_page, ret;
- mutex_lock(&mdiodev->bus->mdio_lock);
+ air_mdiodev_lock(mdiodev, nested);
saved_page = __air_mdio_select_page(mdiodev, AIR_PHY_PAGE_EXTENDED_4);
if (saved_page < 0) {
@@ -333,11 +357,12 @@ static int air_mdio_buckpbus_reg_read(struct mdio_device *mdiodev,
}
static int air_mdio_buckpbus_reg_write(struct mdio_device *mdiodev,
- u32 pbus_address, u32 pbus_data)
+ u32 pbus_address, u32 pbus_data,
+ bool nested)
{
int saved_page, ret;
- mutex_lock(&mdiodev->bus->mdio_lock);
+ air_mdiodev_lock(mdiodev, nested);
saved_page = __air_mdio_select_page(mdiodev, AIR_PHY_PAGE_EXTENDED_4);
if (saved_page < 0) {
@@ -354,11 +379,12 @@ static int air_mdio_buckpbus_reg_write(struct mdio_device *mdiodev,
}
static int air_mdio_buckpbus_reg_modify(struct mdio_device *mdiodev,
- u32 pbus_address, u32 mask, u32 set)
+ u32 pbus_address, u32 mask, u32 set,
+ bool nested)
{
int saved_page, ret;
- mutex_lock(&mdiodev->bus->mdio_lock);
+ air_mdiodev_lock(mdiodev, nested);
saved_page = __air_mdio_select_page(mdiodev, AIR_PHY_PAGE_EXTENDED_4);
if (saved_page < 0) {
@@ -399,20 +425,25 @@ static int __air_mmd_read(struct mdio_device *mdiodev, u16 devad, u16 regnum)
return __mdiobus_read(bus, addr, MII_MMD_DATA);
}
-static int air_mmd_status_read(struct mdio_device *mdiodev)
+static int air_mmd_status_read(struct mdio_device *mdiodev, bool nested)
{
int ret;
- mutex_lock(&mdiodev->bus->mdio_lock);
+ air_mdiodev_lock(mdiodev, nested);
ret = __air_mmd_read(mdiodev, MDIO_MMD_VEND1, EN8811H_PHY_FW_STATUS);
mutex_unlock(&mdiodev->bus->mdio_lock);
return ret;
}
-int air_en8811h_mcu_running(struct mdio_device *mdiodev)
+int air_en8811h_mcu_running(struct mdio_device *mdiodev,
+ struct mii_bus *child_bus)
{
- int ret = air_mmd_status_read(mdiodev);
+ int ret;
+
+ air_child_bus_lock(child_bus);
+ ret = air_mmd_status_read(mdiodev, !!child_bus);
+ air_child_bus_unlock(child_bus);
if (ret < 0)
return ret;
@@ -421,12 +452,12 @@ int air_en8811h_mcu_running(struct mdio_device *mdiodev)
}
EXPORT_SYMBOL_GPL(air_en8811h_mcu_running);
-int air_en8811h_wait_mcu_ready(struct mdio_device *mdiodev)
+int air_en8811h_wait_mcu_ready(struct mdio_device *mdiodev, bool nested)
{
int ret, reg_value;
ret = air_mdio_buckpbus_reg_write(mdiodev, EN8811H_FW_CTRL_1,
- EN8811H_FW_CTRL_1_FINISH);
+ EN8811H_FW_CTRL_1_FINISH, nested);
if (ret)
return ret;
@@ -436,7 +467,7 @@ int air_en8811h_wait_mcu_ready(struct mdio_device *mdiodev)
ret = read_poll_timeout(air_mmd_status_read, reg_value,
reg_value < 0 ||
reg_value == EN8811H_PHY_READY,
- 20000, 7500000, true, mdiodev);
+ 20000, 7500000, true, mdiodev, nested);
if (reg_value < 0)
return reg_value;
if (ret) {
@@ -448,19 +479,23 @@ int air_en8811h_wait_mcu_ready(struct mdio_device *mdiodev)
}
EXPORT_SYMBOL_GPL(air_en8811h_wait_mcu_ready);
-int air_en8811h_fw_download(struct mdio_device *mdiodev, u32 *fw_version)
+int air_en8811h_fw_download(struct mdio_device *mdiodev, u32 *fw_version,
+ struct mii_bus *child_bus)
{
struct device *dev = &mdiodev->dev;
const struct firmware *fw1, *fw2;
+ bool nested = !!child_bus;
int ret;
- ret = air_en8811h_mcu_running(mdiodev);
+ ret = air_en8811h_mcu_running(mdiodev, child_bus);
if (ret < 0)
return ret;
if (ret) {
+ air_child_bus_lock(child_bus);
ret = air_mdio_buckpbus_reg_read(mdiodev, EN8811H_FW_VERSION,
- fw_version);
+ fw_version, nested);
+ air_child_bus_unlock(child_bus);
if (ret < 0)
return ret;
@@ -475,38 +510,42 @@ int air_en8811h_fw_download(struct mdio_device *mdiodev, u32 *fw_version)
if (ret < 0)
goto air_fw_download_rel1;
+ air_child_bus_lock(child_bus);
+
ret = air_mdio_buckpbus_reg_write(mdiodev, EN8811H_FW_CTRL_1,
- EN8811H_FW_CTRL_1_START);
+ EN8811H_FW_CTRL_1_START, nested);
if (ret < 0)
goto air_fw_download_out;
ret = air_mdio_buckpbus_reg_modify(mdiodev, EN8811H_FW_CTRL_2,
EN8811H_FW_CTRL_2_LOADING,
- EN8811H_FW_CTRL_2_LOADING);
+ EN8811H_FW_CTRL_2_LOADING, nested);
if (ret < 0)
goto air_fw_download_out;
- ret = air_fw_write_buf(mdiodev, AIR_FW_ADDR_DM, fw1);
+ ret = air_fw_write_buf(mdiodev, AIR_FW_ADDR_DM, fw1, nested);
if (ret < 0)
goto air_fw_download_out;
- ret = air_fw_write_buf(mdiodev, AIR_FW_ADDR_DSP, fw2);
+ ret = air_fw_write_buf(mdiodev, AIR_FW_ADDR_DSP, fw2, nested);
if (ret < 0)
goto air_fw_download_out;
ret = air_mdio_buckpbus_reg_modify(mdiodev, EN8811H_FW_CTRL_2,
- EN8811H_FW_CTRL_2_LOADING, 0);
+ EN8811H_FW_CTRL_2_LOADING, 0,
+ nested);
if (ret < 0)
goto air_fw_download_out;
- ret = air_en8811h_wait_mcu_ready(mdiodev);
+ ret = air_en8811h_wait_mcu_ready(mdiodev, nested);
if (ret < 0)
goto air_fw_download_out;
ret = air_mdio_buckpbus_reg_read(mdiodev, EN8811H_FW_VERSION,
- fw_version);
+ fw_version, nested);
air_fw_download_out:
+ air_child_bus_unlock(child_bus);
release_firmware(fw2);
air_fw_download_rel1:
diff --git a/drivers/net/phy/air_phy_lib.h b/drivers/net/phy/air_phy_lib.h
index 764f832a02a7..5f6f09446008 100644
--- a/drivers/net/phy/air_phy_lib.h
+++ b/drivers/net/phy/air_phy_lib.h
@@ -60,8 +60,9 @@ int air_phy_buckpbus_reg_write(struct phy_device *phydev, u32 pbus_address,
int air_phy_read_page(struct phy_device *phydev);
int air_phy_write_page(struct phy_device *phydev, int page);
+/* nested: the caller already holds the child bus this chip publishes. */
int air_fw_write_buf(struct mdio_device *mdiodev, u32 address,
- const struct firmware *fw);
-int air_en8811h_wait_mcu_ready(struct mdio_device *mdiodev);
+ const struct firmware *fw, bool nested);
+int air_en8811h_wait_mcu_ready(struct mdio_device *mdiodev, bool nested);
#endif /* __AIR_PHY_LIB_H */
diff --git a/include/linux/mdio/mdio-airoha-en8811h.h b/include/linux/mdio/mdio-airoha-en8811h.h
index 8a073a1b7ee6..383ff4a7f6a1 100644
--- a/include/linux/mdio/mdio-airoha-en8811h.h
+++ b/include/linux/mdio/mdio-airoha-en8811h.h
@@ -10,15 +10,20 @@
#include <linux/types.h>
struct mdio_device;
+struct mii_bus;
#define EN8811H_MD32_DM "airoha/EthMD32.dm.bin"
#define EN8811H_MD32_DSP "airoha/EthMD32.DSP.bin"
-/* Returns 1 when the firmware runs, 0 when the MD32 is still in its
+/* child_bus is the bus this chip publishes below mdiodev, or NULL.
+ *
+ * Returns 1 when the firmware runs, 0 when the MD32 is still in its
* bootloader, and negative on a failed status read.
*/
-int air_en8811h_mcu_running(struct mdio_device *mdiodev);
+int air_en8811h_mcu_running(struct mdio_device *mdiodev,
+ struct mii_bus *child_bus);
/* Returns 1 when firmware was already running and was left in place. */
-int air_en8811h_fw_download(struct mdio_device *mdiodev, u32 *fw_version);
+int air_en8811h_fw_download(struct mdio_device *mdiodev, u32 *fw_version,
+ struct mii_bus *child_bus);
#endif /* __LINUX_MDIO_AIROHA_EN8811H_H */
--
2.53.0
^ permalink raw reply related [flat|nested] 7+ messages in thread