* [PATCH net 01/14] net: phy: as21xxx: handle stale link status during autoneg
2026-11-30 0:55 [PATCH net 00/14] net: phy: as21xxx: Fix a batch of driver issues Cristian Ciocaltea
@ 2026-11-30 0:55 ` Cristian Ciocaltea
2026-11-30 0:55 ` [PATCH net 02/14] net: phy: as21xxx: handle odd firmware on loading Cristian Ciocaltea
` (12 subsequent siblings)
13 siblings, 0 replies; 38+ messages in thread
From: Cristian Ciocaltea @ 2026-11-30 0:55 UTC (permalink / raw)
To: Christian Marangi, Andrew Lunn, Heiner Kallweit, Russell King,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: kernel, netdev, Maxime Chevallier
From: Christian Marangi <ansuelsmth@gmail.com>
When autonegotiation is restarted, MDIO_STAT1_ANEGCOMPLETE may be
cleared before MDIO_STAT1_LSTATUS. In this case, the link status bit
may still indicate link up even though autonegotiation has not
completed.
Force the link down when autonegotiation is enabled but has not
completed, preventing as21xxx_read_status() from reporting a link up
with an unknown or stale speed.
Fixes: 830877d89edc ("net: phy: Add support for Aeonsemi AS21xxx PHYs")
Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
---
drivers/net/phy/as21xxx.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/net/phy/as21xxx.c b/drivers/net/phy/as21xxx.c
index dbe6be963389..3db455314b67 100644
--- a/drivers/net/phy/as21xxx.c
+++ b/drivers/net/phy/as21xxx.c
@@ -657,6 +657,13 @@ static int as21xxx_read_link(struct phy_device *phydev, int *bmcr)
return status;
phydev->link = !!(status & MDIO_STAT1_LSTATUS);
+ phydev->autoneg_complete = !!(status & MDIO_AN_STAT1_COMPLETE);
+
+ /* Consider the case that autoneg was started and "aneg complete"
+ * bit has been reset, but "link up" bit not yet.
+ */
+ if (phydev->autoneg == AUTONEG_ENABLE && !phydev->autoneg_complete)
+ phydev->link = 0;
return 0;
}
--
2.56.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* [PATCH net 02/14] net: phy: as21xxx: handle odd firmware on loading
2026-11-30 0:55 [PATCH net 00/14] net: phy: as21xxx: Fix a batch of driver issues Cristian Ciocaltea
2026-11-30 0:55 ` [PATCH net 01/14] net: phy: as21xxx: handle stale link status during autoneg Cristian Ciocaltea
@ 2026-11-30 0:55 ` Cristian Ciocaltea
2026-11-30 0:55 ` [PATCH net 03/14] net: phy: as21xxx: Fix LED index bounds check Cristian Ciocaltea
` (11 subsequent siblings)
13 siblings, 0 replies; 38+ messages in thread
From: Cristian Ciocaltea @ 2026-11-30 0:55 UTC (permalink / raw)
To: Christian Marangi, Andrew Lunn, Heiner Kallweit, Russell King,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: kernel, netdev
From: Christian Marangi <ansuelsmth@gmail.com>
Even if firmware for AS21xxx should be always u16 aligned, we can't assume
this will be the same forever. Better address this by simply validate the
index before reading out of bound from the data buffer.
A zero padded buffer will be passed to the AS21xxx mailbox in such case.
Fixes: 830877d89edc ("net: phy: Add support for Aeonsemi AS21xxx PHYs")
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
---
drivers/net/phy/as21xxx.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/net/phy/as21xxx.c b/drivers/net/phy/as21xxx.c
index 3db455314b67..5fb06cd765cf 100644
--- a/drivers/net/phy/as21xxx.c
+++ b/drivers/net/phy/as21xxx.c
@@ -323,9 +323,11 @@ static int aeon_firmware_boot(struct phy_device *phydev, const u8 *data,
return -EINVAL;
}
- /* Firmware is always aligned to u16 */
+ /* Firmware should be u16 aligned, zero-pad a trailing odd byte */
for (i = 0; i < size; i += 2) {
- val = data[i + 1] << 8 | data[i];
+ val = data[i];
+ if (i + 1 < size)
+ val |= data[i + 1] << 8;
ret = phy_write_mmd(phydev, MDIO_MMD_VEND1,
VEND1_GLB_REG_MDIO_INDIRECT_LOAD, val);
--
2.56.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* [PATCH net 03/14] net: phy: as21xxx: Fix LED index bounds check
2026-11-30 0:55 [PATCH net 00/14] net: phy: as21xxx: Fix a batch of driver issues Cristian Ciocaltea
2026-11-30 0:55 ` [PATCH net 01/14] net: phy: as21xxx: handle stale link status during autoneg Cristian Ciocaltea
2026-11-30 0:55 ` [PATCH net 02/14] net: phy: as21xxx: handle odd firmware on loading Cristian Ciocaltea
@ 2026-11-30 0:55 ` Cristian Ciocaltea
2026-11-30 2:37 ` Andrew Lunn
2026-11-30 0:55 ` [PATCH net 04/14] net: phy: as21xxx: Use the correct mask for the speed status Cristian Ciocaltea
` (10 subsequent siblings)
13 siblings, 1 reply; 38+ messages in thread
From: Cristian Ciocaltea @ 2026-11-30 0:55 UTC (permalink / raw)
To: Christian Marangi, Andrew Lunn, Heiner Kallweit, Russell King,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: kernel, netdev
The LED indexes are zero-based, so valid indexes are strictly less than
the number of LEDs, AEON_MAX_LEDS. However, the LED ops only reject
indexes greater than AEON_MAX_LEDS, which wrongly accepts an index equal
to AEON_MAX_LEDS, one past the last valid LED.
Such an index makes VEND1_LED_REG() compute an address outside the LED
register block. A bogus LED node in the device tree can then cause
reads and writes of an unrelated vendor register.
Reject indexes greater than or equal to AEON_MAX_LEDS so that only valid
LED indexes are accepted.
Fixes: 830877d89edc ("net: phy: Add support for Aeonsemi AS21xxx PHYs")
Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
---
drivers/net/phy/as21xxx.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/net/phy/as21xxx.c b/drivers/net/phy/as21xxx.c
index 5fb06cd765cf..5b38c641329a 100644
--- a/drivers/net/phy/as21xxx.c
+++ b/drivers/net/phy/as21xxx.c
@@ -781,7 +781,7 @@ static int as21xxx_led_brightness_set(struct phy_device *phydev,
{
u16 val = VEND1_LED_REG_A_EVENT_OFF;
- if (index > AEON_MAX_LEDS)
+ if (index >= AEON_MAX_LEDS)
return -EINVAL;
if (value)
@@ -798,7 +798,7 @@ static int as21xxx_led_hw_is_supported(struct phy_device *phydev, u8 index,
{
int i;
- if (index > AEON_MAX_LEDS)
+ if (index >= AEON_MAX_LEDS)
return -EINVAL;
for (i = 0; i < ARRAY_SIZE(as21xxx_led_supported_pattern); i++)
@@ -813,7 +813,7 @@ static int as21xxx_led_hw_control_get(struct phy_device *phydev, u8 index,
{
int i, val;
- if (index > AEON_MAX_LEDS)
+ if (index >= AEON_MAX_LEDS)
return -EINVAL;
val = phy_read_mmd(phydev, MDIO_MMD_VEND1, VEND1_LED_REG(index));
@@ -837,7 +837,7 @@ static int as21xxx_led_hw_control_set(struct phy_device *phydev, u8 index,
u16 val = 0;
int i;
- if (index > AEON_MAX_LEDS)
+ if (index >= AEON_MAX_LEDS)
return -EINVAL;
for (i = 0; i < ARRAY_SIZE(as21xxx_led_supported_pattern); i++)
@@ -859,7 +859,7 @@ static int as21xxx_led_polarity_set(struct phy_device *phydev, int index,
u16 mask, val = 0;
u32 mode;
- if (index > AEON_MAX_LEDS)
+ if (index >= AEON_MAX_LEDS)
return -EINVAL;
for_each_set_bit(mode, &modes, __PHY_LED_MODES_NUM) {
--
2.56.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* Re: [PATCH net 03/14] net: phy: as21xxx: Fix LED index bounds check
2026-11-30 0:55 ` [PATCH net 03/14] net: phy: as21xxx: Fix LED index bounds check Cristian Ciocaltea
@ 2026-11-30 2:37 ` Andrew Lunn
2026-11-30 10:35 ` Cristian Ciocaltea
0 siblings, 1 reply; 38+ messages in thread
From: Andrew Lunn @ 2026-11-30 2:37 UTC (permalink / raw)
To: Cristian Ciocaltea
Cc: Christian Marangi, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, kernel, netdev
On Mon, Nov 30, 2026 at 02:55:10AM +0200, Cristian Ciocaltea wrote:
> The LED indexes are zero-based, so valid indexes are strictly less than
> the number of LEDs, AEON_MAX_LEDS. However, the LED ops only reject
> indexes greater than AEON_MAX_LEDS, which wrongly accepts an index equal
> to AEON_MAX_LEDS, one past the last valid LED.
>
> Such an index makes VEND1_LED_REG() compute an address outside the LED
> register block. A bogus LED node in the device tree can then cause
> reads and writes of an unrelated vendor register.
>
> Reject indexes greater than or equal to AEON_MAX_LEDS so that only valid
> LED indexes are accepted.
>
> Fixes: 830877d89edc ("net: phy: Add support for Aeonsemi AS21xxx PHYs")
> Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
I'm not sure a Fixes tag is justified. Does this actually bother
anybody? It requires a broken DT blob. Does mainline have one?
I suggest this goes via net-next.
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
^ permalink raw reply [flat|nested] 38+ messages in thread* Re: [PATCH net 03/14] net: phy: as21xxx: Fix LED index bounds check
2026-11-30 2:37 ` Andrew Lunn
@ 2026-11-30 10:35 ` Cristian Ciocaltea
0 siblings, 0 replies; 38+ messages in thread
From: Cristian Ciocaltea @ 2026-11-30 10:35 UTC (permalink / raw)
To: Andrew Lunn
Cc: Christian Marangi, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, kernel, netdev
Hi Andrew,
On 11/30/26 4:37 AM, Andrew Lunn wrote:
> On Mon, Nov 30, 2026 at 02:55:10AM +0200, Cristian Ciocaltea wrote:
>> The LED indexes are zero-based, so valid indexes are strictly less than
>> the number of LEDs, AEON_MAX_LEDS. However, the LED ops only reject
>> indexes greater than AEON_MAX_LEDS, which wrongly accepts an index equal
>> to AEON_MAX_LEDS, one past the last valid LED.
>>
>> Such an index makes VEND1_LED_REG() compute an address outside the LED
>> register block. A bogus LED node in the device tree can then cause
>> reads and writes of an unrelated vendor register.
>>
>> Reject indexes greater than or equal to AEON_MAX_LEDS so that only valid
>> LED indexes are accepted.
>>
>> Fixes: 830877d89edc ("net: phy: Add support for Aeonsemi AS21xxx PHYs")
>> Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
>
> I'm not sure a Fixes tag is justified. Does this actually bother
> anybody? It requires a broken DT blob. Does mainline have one?
>
> I suggest this goes via net-next.
Ack, I'll make this part of the follow-up series adding Gen2 support.
> Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Thanks for your quick review.
Regards,
Cristian
^ permalink raw reply [flat|nested] 38+ messages in thread
* [PATCH net 04/14] net: phy: as21xxx: Use the correct mask for the speed status
2026-11-30 0:55 [PATCH net 00/14] net: phy: as21xxx: Fix a batch of driver issues Cristian Ciocaltea
` (2 preceding siblings ...)
2026-11-30 0:55 ` [PATCH net 03/14] net: phy: as21xxx: Fix LED index bounds check Cristian Ciocaltea
@ 2026-11-30 0:55 ` Cristian Ciocaltea
2026-11-30 2:39 ` Andrew Lunn
2026-11-30 0:55 ` [PATCH net 05/14] net: phy: as21xxx: Correct the 10M speed status value Cristian Ciocaltea
` (9 subsequent siblings)
13 siblings, 1 reply; 38+ messages in thread
From: Cristian Ciocaltea @ 2026-11-30 0:55 UTC (permalink / raw)
To: Christian Marangi, Andrew Lunn, Heiner Kallweit, Russell King,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: kernel, netdev
as21xxx_read_status() masks the speed status with VEND1_SPEED_STATUS,
the address of the register it just read, instead of VEND1_SPEED_MASK,
which is the field mask the speed values are built with.
This affects the path taken when auto-negotiation is disabled. For
example, after setting "speed 100 duplex full autoneg off", ethtool
would incorrectly report "Speed: 10Mb/s" instead of "Speed: 100Mb/s".
Switch to the correct field mask so the speed is decoded properly.
Fixes: 830877d89edc ("net: phy: Add support for Aeonsemi AS21xxx PHYs")
Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
---
drivers/net/phy/as21xxx.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/phy/as21xxx.c b/drivers/net/phy/as21xxx.c
index 5b38c641329a..ff6c2005c442 100644
--- a/drivers/net/phy/as21xxx.c
+++ b/drivers/net/phy/as21xxx.c
@@ -740,7 +740,7 @@ static int as21xxx_read_status(struct phy_device *phydev)
if (speed < 0)
return speed;
- switch (speed & VEND1_SPEED_STATUS) {
+ switch (speed & VEND1_SPEED_MASK) {
case VEND1_SPEED_10000:
phydev->speed = SPEED_10000;
phydev->duplex = DUPLEX_FULL;
--
2.56.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* Re: [PATCH net 04/14] net: phy: as21xxx: Use the correct mask for the speed status
2026-11-30 0:55 ` [PATCH net 04/14] net: phy: as21xxx: Use the correct mask for the speed status Cristian Ciocaltea
@ 2026-11-30 2:39 ` Andrew Lunn
0 siblings, 0 replies; 38+ messages in thread
From: Andrew Lunn @ 2026-11-30 2:39 UTC (permalink / raw)
To: Cristian Ciocaltea
Cc: Christian Marangi, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, kernel, netdev
On Mon, Nov 30, 2026 at 02:55:11AM +0200, Cristian Ciocaltea wrote:
> as21xxx_read_status() masks the speed status with VEND1_SPEED_STATUS,
> the address of the register it just read, instead of VEND1_SPEED_MASK,
> which is the field mask the speed values are built with.
>
> This affects the path taken when auto-negotiation is disabled. For
> example, after setting "speed 100 duplex full autoneg off", ethtool
> would incorrectly report "Speed: 10Mb/s" instead of "Speed: 100Mb/s".
>
> Switch to the correct field mask so the speed is decoded properly.
>
> Fixes: 830877d89edc ("net: phy: Add support for Aeonsemi AS21xxx PHYs")
> Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
^ permalink raw reply [flat|nested] 38+ messages in thread
* [PATCH net 05/14] net: phy: as21xxx: Correct the 10M speed status value
2026-11-30 0:55 [PATCH net 00/14] net: phy: as21xxx: Fix a batch of driver issues Cristian Ciocaltea
` (3 preceding siblings ...)
2026-11-30 0:55 ` [PATCH net 04/14] net: phy: as21xxx: Use the correct mask for the speed status Cristian Ciocaltea
@ 2026-11-30 0:55 ` Cristian Ciocaltea
2026-11-30 2:40 ` Andrew Lunn
2026-11-30 0:55 ` [PATCH net 06/14] net: phy: as21xxx: Do not write the IPC reply to a NULL buffer Cristian Ciocaltea
` (8 subsequent siblings)
13 siblings, 1 reply; 38+ messages in thread
From: Cristian Ciocaltea @ 2026-11-30 0:55 UTC (permalink / raw)
To: Christian Marangi, Andrew Lunn, Heiner Kallweit, Russell King,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: kernel, netdev
The speed status register reports 0x40 for a 10M link, not 0x0 as
VEND1_SPEED_10 describes.
Attempting to force a 10M link would therefore match no case of the
switch in aeon_read_status() and make it fail with -EINVAL, generating
the following splat:
[ 740.903011] _phy_start_aneg+0x0/0x98: returned: -22
[ 740.907932] WARNING: CPU: 0 PID: 6774 at _phy_state_machine+0x60/0x2dc
[...]
[ 741.192990] Call trace:
[ 741.195429] _phy_state_machine+0x60/0x2dc
[ 741.199526] phy_state_machine+0x28/0x80
[ 741.203449] process_one_work+0x174/0x300
[...]
The bug was hidden because the status was masked with VEND1_SPEED_STATUS
(the register address) instead of VEND1_SPEED_MASK. 0x40 & 0x4002
evaluates to 0, which happened to match the wrong VEND1_SPEED_10 value,
so 10M links were still reported correctly. Fixing the mask exposes the
bad definition.
Describe the value the PHY actually reports.
Fixes: 830877d89edc ("net: phy: Add support for Aeonsemi AS21xxx PHYs")
Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
---
drivers/net/phy/as21xxx.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/phy/as21xxx.c b/drivers/net/phy/as21xxx.c
index ff6c2005c442..8d46fdfc279a 100644
--- a/drivers/net/phy/as21xxx.c
+++ b/drivers/net/phy/as21xxx.c
@@ -47,7 +47,7 @@
#define VEND1_SPEED_2500 FIELD_PREP_CONST(VEND1_SPEED_MASK, 0x9)
#define VEND1_SPEED_1000 FIELD_PREP_CONST(VEND1_SPEED_MASK, 0x10)
#define VEND1_SPEED_100 FIELD_PREP_CONST(VEND1_SPEED_MASK, 0x20)
-#define VEND1_SPEED_10 FIELD_PREP_CONST(VEND1_SPEED_MASK, 0x0)
+#define VEND1_SPEED_10 FIELD_PREP_CONST(VEND1_SPEED_MASK, 0x40)
#define VEND1_IPC_CMD 0x5801
#define AEON_IPC_CMD_PARITY BIT(15)
--
2.56.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* Re: [PATCH net 05/14] net: phy: as21xxx: Correct the 10M speed status value
2026-11-30 0:55 ` [PATCH net 05/14] net: phy: as21xxx: Correct the 10M speed status value Cristian Ciocaltea
@ 2026-11-30 2:40 ` Andrew Lunn
0 siblings, 0 replies; 38+ messages in thread
From: Andrew Lunn @ 2026-11-30 2:40 UTC (permalink / raw)
To: Cristian Ciocaltea
Cc: Christian Marangi, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, kernel, netdev
On Mon, Nov 30, 2026 at 02:55:12AM +0200, Cristian Ciocaltea wrote:
> The speed status register reports 0x40 for a 10M link, not 0x0 as
> VEND1_SPEED_10 describes.
>
> Attempting to force a 10M link would therefore match no case of the
> switch in aeon_read_status() and make it fail with -EINVAL, generating
> the following splat:
>
> [ 740.903011] _phy_start_aneg+0x0/0x98: returned: -22
> [ 740.907932] WARNING: CPU: 0 PID: 6774 at _phy_state_machine+0x60/0x2dc
> [...]
> [ 741.192990] Call trace:
> [ 741.195429] _phy_state_machine+0x60/0x2dc
> [ 741.199526] phy_state_machine+0x28/0x80
> [ 741.203449] process_one_work+0x174/0x300
> [...]
>
> The bug was hidden because the status was masked with VEND1_SPEED_STATUS
> (the register address) instead of VEND1_SPEED_MASK. 0x40 & 0x4002
> evaluates to 0, which happened to match the wrong VEND1_SPEED_10 value,
> so 10M links were still reported correctly. Fixing the mask exposes the
> bad definition.
>
> Describe the value the PHY actually reports.
>
> Fixes: 830877d89edc ("net: phy: Add support for Aeonsemi AS21xxx PHYs")
> Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
^ permalink raw reply [flat|nested] 38+ messages in thread
* [PATCH net 06/14] net: phy: as21xxx: Do not write the IPC reply to a NULL buffer
2026-11-30 0:55 [PATCH net 00/14] net: phy: as21xxx: Fix a batch of driver issues Cristian Ciocaltea
` (4 preceding siblings ...)
2026-11-30 0:55 ` [PATCH net 05/14] net: phy: as21xxx: Correct the 10M speed status value Cristian Ciocaltea
@ 2026-11-30 0:55 ` Cristian Ciocaltea
2026-11-30 2:49 ` Andrew Lunn
2026-11-30 0:55 ` [PATCH net 07/14] net: phy: as21xxx: Write IPC payload under ipc_lock Cristian Ciocaltea
` (7 subsequent siblings)
13 siblings, 1 reply; 38+ messages in thread
From: Cristian Ciocaltea @ 2026-11-30 0:55 UTC (permalink / raw)
To: Christian Marangi, Andrew Lunn, Heiner Kallweit, Russell King,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: kernel, netdev
aeon_ipc_send_msg() intends to skip reading the IPC reply when the
caller passes no buffer for it, but the check tests the input buffer
(data) rather than the output buffer (ret_data). A caller supplying
a payload but a NULL ret_data would have the reply written through a
NULL pointer.
Check ret_data before copying the reply. While at it, validate the
input buffer at function entry, rejecting a NULL data pointer with a
non-zero data_len.
Fixes: 830877d89edc ("net: phy: Add support for Aeonsemi AS21xxx PHYs")
Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
---
drivers/net/phy/as21xxx.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/net/phy/as21xxx.c b/drivers/net/phy/as21xxx.c
index 8d46fdfc279a..592b4b7a7869 100644
--- a/drivers/net/phy/as21xxx.c
+++ b/drivers/net/phy/as21xxx.c
@@ -464,6 +464,9 @@ static int aeon_ipc_send_msg(struct phy_device *phydev,
int ret;
int i;
+ if (data_len && !data)
+ return -EINVAL;
+
/* IPC have a max of 8 register to transfer data,
* make sure we never exceed this.
*/
@@ -486,14 +489,14 @@ static int aeon_ipc_send_msg(struct phy_device *phydev,
goto out;
}
- if (!data)
- goto out;
-
if ((ret_sts & AEON_IPC_STS_STATUS) == AEON_IPC_STS_STATUS_ERROR) {
ret = -EINVAL;
goto out;
}
+ if (!ret_data)
+ goto out;
+
/* Prevent IPC from stack smashing the kernel.
* We can't trust IPC to return a good value and we always
* preallocate space for 16 Bytes.
--
2.56.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* Re: [PATCH net 06/14] net: phy: as21xxx: Do not write the IPC reply to a NULL buffer
2026-11-30 0:55 ` [PATCH net 06/14] net: phy: as21xxx: Do not write the IPC reply to a NULL buffer Cristian Ciocaltea
@ 2026-11-30 2:49 ` Andrew Lunn
2026-11-30 10:53 ` Cristian Ciocaltea
0 siblings, 1 reply; 38+ messages in thread
From: Andrew Lunn @ 2026-11-30 2:49 UTC (permalink / raw)
To: Cristian Ciocaltea
Cc: Christian Marangi, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, kernel, netdev
On Mon, Nov 30, 2026 at 02:55:13AM +0200, Cristian Ciocaltea wrote:
> aeon_ipc_send_msg() intends to skip reading the IPC reply when the
> caller passes no buffer for it, but the check tests the input buffer
> (data) rather than the output buffer (ret_data).
The comment at the beginning of the function is also wrong:
/* If data is NULL, return 0 or negative error.
* If data not NULL, return number of Bytes received from IPC or
* a negative error.
*/
static int aeon_ipc_send_msg(struct phy_device *phydev,
u16 opcode, u16 *data, unsigned int data_len,
u16 *ret_data)
{
Maybe a later patch fixes that?
> A caller supplying
> a payload but a NULL ret_data would have the reply written through a
> NULL pointer.
>
> Check ret_data before copying the reply. While at it, validate the
> input buffer at function entry, rejecting a NULL data pointer with a
> non-zero data_len.
I would actually let this explode. The oops makes it clear where the
bug is, returning EINVAL will be harder to correct, there is already
three of them in this function.
> Fixes: 830877d89edc ("net: phy: Add support for Aeonsemi AS21xxx PHYs")
> Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
This is purely about validation of the passed parameters, that the
validation is not strictly correct. As far as i see, nothing in the
happy days case is actually broken? So this should go via net-next.
Andrew
^ permalink raw reply [flat|nested] 38+ messages in thread* Re: [PATCH net 06/14] net: phy: as21xxx: Do not write the IPC reply to a NULL buffer
2026-11-30 2:49 ` Andrew Lunn
@ 2026-11-30 10:53 ` Cristian Ciocaltea
0 siblings, 0 replies; 38+ messages in thread
From: Cristian Ciocaltea @ 2026-11-30 10:53 UTC (permalink / raw)
To: Andrew Lunn
Cc: Christian Marangi, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, kernel, netdev
On 11/30/26 4:49 AM, Andrew Lunn wrote:
> On Mon, Nov 30, 2026 at 02:55:13AM +0200, Cristian Ciocaltea wrote:
>> aeon_ipc_send_msg() intends to skip reading the IPC reply when the
>> caller passes no buffer for it, but the check tests the input buffer
>> (data) rather than the output buffer (ret_data).
>
> The comment at the beginning of the function is also wrong:
>
> /* If data is NULL, return 0 or negative error.
> * If data not NULL, return number of Bytes received from IPC or
> * a negative error.
> */
> static int aeon_ipc_send_msg(struct phy_device *phydev,
> u16 opcode, u16 *data, unsigned int data_len,
> u16 *ret_data)
> {
>
>
> Maybe a later patch fixes that?
Sure, I somehow missed to correct it.
>> A caller supplying
>> a payload but a NULL ret_data would have the reply written through a
>> NULL pointer.
>>
>> Check ret_data before copying the reply. While at it, validate the
>> input buffer at function entry, rejecting a NULL data pointer with a
>> non-zero data_len.
>
> I would actually let this explode. The oops makes it clear where the
> bug is, returning EINVAL will be harder to correct, there is already
> three of them in this function.
Ok, I'll drop the 'data_len && !data' check and just keep the '!ret_data' one.
>> Fixes: 830877d89edc ("net: phy: Add support for Aeonsemi AS21xxx PHYs")
>> Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
>
> This is purely about validation of the passed parameters, that the
> validation is not strictly correct. As far as i see, nothing in the
> happy days case is actually broken? So this should go via net-next.
Indeed, let's move this to the next series.
Thanks,
Cristian
^ permalink raw reply [flat|nested] 38+ messages in thread
* [PATCH net 07/14] net: phy: as21xxx: Write IPC payload under ipc_lock
2026-11-30 0:55 [PATCH net 00/14] net: phy: as21xxx: Fix a batch of driver issues Cristian Ciocaltea
` (5 preceding siblings ...)
2026-11-30 0:55 ` [PATCH net 06/14] net: phy: as21xxx: Do not write the IPC reply to a NULL buffer Cristian Ciocaltea
@ 2026-11-30 0:55 ` Cristian Ciocaltea
2026-11-30 2:53 ` Andrew Lunn
2026-11-30 0:55 ` [PATCH net 08/14] net: phy: as21xxx: Handle IPC payload write errors Cristian Ciocaltea
` (6 subsequent siblings)
13 siblings, 1 reply; 38+ messages in thread
From: Cristian Ciocaltea @ 2026-11-30 0:55 UTC (permalink / raw)
To: Christian Marangi, Andrew Lunn, Heiner Kallweit, Russell King,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: kernel, netdev
aeon_ipc_send_msg() writes the message payload to the shared
VEND1_IPC_DATA registers before taking ipc_lock. Two concurrent
senders may interleave, so that one overwrites the payload of the
other before the corresponding command is issued. The firmware would
then execute a command with the wrong arguments.
Take ipc_lock before writing the payload, so that filling the data
registers and issuing the command happen atomically with respect to
other IPC users. The argument checks remain outside the lock.
Fixes: 830877d89edc ("net: phy: Add support for Aeonsemi AS21xxx PHYs")
Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
---
drivers/net/phy/as21xxx.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/phy/as21xxx.c b/drivers/net/phy/as21xxx.c
index 592b4b7a7869..4e10b0920a3c 100644
--- a/drivers/net/phy/as21xxx.c
+++ b/drivers/net/phy/as21xxx.c
@@ -473,6 +473,8 @@ static int aeon_ipc_send_msg(struct phy_device *phydev,
if (data_len > AEON_IPC_DATA_MAX)
return -EINVAL;
+ mutex_lock(&priv->ipc_lock);
+
for (i = 0; i < data_len / sizeof(u16); i++)
phy_write_mmd(phydev, MDIO_MMD_VEND1, VEND1_IPC_DATA(i),
data[i]);
@@ -480,8 +482,6 @@ static int aeon_ipc_send_msg(struct phy_device *phydev,
cmd = FIELD_PREP(AEON_IPC_CMD_SIZE, data_len) |
FIELD_PREP(AEON_IPC_CMD_OPCODE, opcode);
- mutex_lock(&priv->ipc_lock);
-
ret = aeon_ipc_send_cmd(phydev, priv, cmd, &ret_sts);
if (ret) {
phydev_err(phydev, "failed to send ipc msg for %x: %d\n",
--
2.56.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* Re: [PATCH net 07/14] net: phy: as21xxx: Write IPC payload under ipc_lock
2026-11-30 0:55 ` [PATCH net 07/14] net: phy: as21xxx: Write IPC payload under ipc_lock Cristian Ciocaltea
@ 2026-11-30 2:53 ` Andrew Lunn
2026-11-30 11:09 ` Cristian Ciocaltea
0 siblings, 1 reply; 38+ messages in thread
From: Andrew Lunn @ 2026-11-30 2:53 UTC (permalink / raw)
To: Cristian Ciocaltea
Cc: Christian Marangi, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, kernel, netdev
On Mon, Nov 30, 2026 at 02:55:14AM +0200, Cristian Ciocaltea wrote:
> aeon_ipc_send_msg() writes the message payload to the shared
> VEND1_IPC_DATA registers before taking ipc_lock. Two concurrent
> senders may interleave, so that one overwrites the payload of the
> other before the corresponding command is issued. The firmware would
> then execute a command with the wrong arguments.
>
> Take ipc_lock before writing the payload, so that filling the data
> registers and issuing the command happen atomically with respect to
> other IPC users. The argument checks remain outside the lock.
How theoretical is this? phylib operations are protected by the phylib
mutex. That should include LEDs.
What is outside of phylib is things like hwmon devices. Does this
driver have any paths which don't take the phydev mutex?
The patch seems theoretically valid, but does it actually bother
anybody? If not, net-next.
Andrew
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: [PATCH net 07/14] net: phy: as21xxx: Write IPC payload under ipc_lock
2026-11-30 2:53 ` Andrew Lunn
@ 2026-11-30 11:09 ` Cristian Ciocaltea
0 siblings, 0 replies; 38+ messages in thread
From: Cristian Ciocaltea @ 2026-11-30 11:09 UTC (permalink / raw)
To: Andrew Lunn
Cc: Christian Marangi, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, kernel, netdev
On 11/30/26 4:53 AM, Andrew Lunn wrote:
> On Mon, Nov 30, 2026 at 02:55:14AM +0200, Cristian Ciocaltea wrote:
>> aeon_ipc_send_msg() writes the message payload to the shared
>> VEND1_IPC_DATA registers before taking ipc_lock. Two concurrent
>> senders may interleave, so that one overwrites the payload of the
>> other before the corresponding command is issued. The firmware would
>> then execute a command with the wrong arguments.
>>
>> Take ipc_lock before writing the payload, so that filling the data
>> registers and issuing the command happen atomically with respect to
>> other IPC users. The argument checks remain outside the lock.
>
> How theoretical is this? phylib operations are protected by the phylib
> mutex. That should include LEDs.
>
> What is outside of phylib is things like hwmon devices. Does this
> driver have any paths which don't take the phydev mutex?
>
> The patch seems theoretically valid, but does it actually bother
> anybody? If not, net-next.
The driver defines IPC_CMD_TEMP_MON_GET but doesn't use it to support any hwmon
temperature features yet, so I'll move it to net-next.
Thanks,
Cristian
^ permalink raw reply [flat|nested] 38+ messages in thread
* [PATCH net 08/14] net: phy: as21xxx: Handle IPC payload write errors
2026-11-30 0:55 [PATCH net 00/14] net: phy: as21xxx: Fix a batch of driver issues Cristian Ciocaltea
` (6 preceding siblings ...)
2026-11-30 0:55 ` [PATCH net 07/14] net: phy: as21xxx: Write IPC payload under ipc_lock Cristian Ciocaltea
@ 2026-11-30 0:55 ` Cristian Ciocaltea
2026-11-30 2:54 ` Andrew Lunn
2026-11-30 0:55 ` [PATCH net 09/14] net: phy: as21xxx: Reject odd IPC payload lengths Cristian Ciocaltea
` (5 subsequent siblings)
13 siblings, 1 reply; 38+ messages in thread
From: Cristian Ciocaltea @ 2026-11-30 0:55 UTC (permalink / raw)
To: Christian Marangi, Andrew Lunn, Heiner Kallweit, Russell King,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: kernel, netdev
aeon_ipc_send_msg() ignores the return value of phy_write_mmd() when
filling the IPC data registers. On an MDIO failure the command is still
issued, and the firmware acts on stale or partial data left in the
registers.
Check the result of each write and abort the transfer on error,
propagating the error code to the caller.
Fixes: 830877d89edc ("net: phy: Add support for Aeonsemi AS21xxx PHYs")
Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
---
drivers/net/phy/as21xxx.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/net/phy/as21xxx.c b/drivers/net/phy/as21xxx.c
index 4e10b0920a3c..14c22cb80db7 100644
--- a/drivers/net/phy/as21xxx.c
+++ b/drivers/net/phy/as21xxx.c
@@ -475,9 +475,12 @@ static int aeon_ipc_send_msg(struct phy_device *phydev,
mutex_lock(&priv->ipc_lock);
- for (i = 0; i < data_len / sizeof(u16); i++)
- phy_write_mmd(phydev, MDIO_MMD_VEND1, VEND1_IPC_DATA(i),
- data[i]);
+ for (i = 0; i < data_len / sizeof(u16); i++) {
+ ret = phy_write_mmd(phydev, MDIO_MMD_VEND1, VEND1_IPC_DATA(i),
+ data[i]);
+ if (ret < 0)
+ goto out;
+ }
cmd = FIELD_PREP(AEON_IPC_CMD_SIZE, data_len) |
FIELD_PREP(AEON_IPC_CMD_OPCODE, opcode);
--
2.56.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* Re: [PATCH net 08/14] net: phy: as21xxx: Handle IPC payload write errors
2026-11-30 0:55 ` [PATCH net 08/14] net: phy: as21xxx: Handle IPC payload write errors Cristian Ciocaltea
@ 2026-11-30 2:54 ` Andrew Lunn
0 siblings, 0 replies; 38+ messages in thread
From: Andrew Lunn @ 2026-11-30 2:54 UTC (permalink / raw)
To: Cristian Ciocaltea
Cc: Christian Marangi, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, kernel, netdev
On Mon, Nov 30, 2026 at 02:55:15AM +0200, Cristian Ciocaltea wrote:
> aeon_ipc_send_msg() ignores the return value of phy_write_mmd() when
> filling the IPC data registers. On an MDIO failure the command is still
> issued, and the firmware acts on stale or partial data left in the
> registers.
>
> Check the result of each write and abort the transfer on error,
> propagating the error code to the caller.
>
> Fixes: 830877d89edc ("net: phy: Add support for Aeonsemi AS21xxx PHYs")
> Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
MDIO transactions pretty much never fail, so this is
theoretical. net-next please.
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
^ permalink raw reply [flat|nested] 38+ messages in thread
* [PATCH net 09/14] net: phy: as21xxx: Reject odd IPC payload lengths
2026-11-30 0:55 [PATCH net 00/14] net: phy: as21xxx: Fix a batch of driver issues Cristian Ciocaltea
` (7 preceding siblings ...)
2026-11-30 0:55 ` [PATCH net 08/14] net: phy: as21xxx: Handle IPC payload write errors Cristian Ciocaltea
@ 2026-11-30 0:55 ` Cristian Ciocaltea
2026-11-30 2:55 ` Andrew Lunn
2026-11-30 0:55 ` [PATCH net 10/14] net: phy: as21xxx: Fix LED hw control set for unsupported rules Cristian Ciocaltea
` (4 subsequent siblings)
13 siblings, 1 reply; 38+ messages in thread
From: Cristian Ciocaltea @ 2026-11-30 0:55 UTC (permalink / raw)
To: Christian Marangi, Andrew Lunn, Heiner Kallweit, Russell King,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: kernel, netdev
The IPC payload is transferred through 16-bit data registers, but
aeon_ipc_send_msg() advertises data_len bytes to the firmware while
writing only data_len / 2 registers. For an odd length the last byte is
silently dropped, and the firmware reads whatever was left in the next
register.
Reject payload lengths that are not a multiple of the register width.
Fixes: 830877d89edc ("net: phy: Add support for Aeonsemi AS21xxx PHYs")
Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
---
drivers/net/phy/as21xxx.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/net/phy/as21xxx.c b/drivers/net/phy/as21xxx.c
index 14c22cb80db7..90b6f528f76d 100644
--- a/drivers/net/phy/as21xxx.c
+++ b/drivers/net/phy/as21xxx.c
@@ -473,6 +473,10 @@ static int aeon_ipc_send_msg(struct phy_device *phydev,
if (data_len > AEON_IPC_DATA_MAX)
return -EINVAL;
+ /* Data is transferred in 16-bit words, so the length must be even. */
+ if (data_len % sizeof(u16))
+ return -EINVAL;
+
mutex_lock(&priv->ipc_lock);
for (i = 0; i < data_len / sizeof(u16); i++) {
--
2.56.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* Re: [PATCH net 09/14] net: phy: as21xxx: Reject odd IPC payload lengths
2026-11-30 0:55 ` [PATCH net 09/14] net: phy: as21xxx: Reject odd IPC payload lengths Cristian Ciocaltea
@ 2026-11-30 2:55 ` Andrew Lunn
0 siblings, 0 replies; 38+ messages in thread
From: Andrew Lunn @ 2026-11-30 2:55 UTC (permalink / raw)
To: Cristian Ciocaltea
Cc: Christian Marangi, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, kernel, netdev
On Mon, Nov 30, 2026 at 02:55:16AM +0200, Cristian Ciocaltea wrote:
> The IPC payload is transferred through 16-bit data registers, but
> aeon_ipc_send_msg() advertises data_len bytes to the firmware while
> writing only data_len / 2 registers. For an odd length the last byte is
> silently dropped, and the firmware reads whatever was left in the next
> register.
>
> Reject payload lengths that are not a multiple of the register width.
Are there currently can callers which get this wrong?
Seems like net-next.
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
^ permalink raw reply [flat|nested] 38+ messages in thread
* [PATCH net 10/14] net: phy: as21xxx: Fix LED hw control set for unsupported rules
2026-11-30 0:55 [PATCH net 00/14] net: phy: as21xxx: Fix a batch of driver issues Cristian Ciocaltea
` (8 preceding siblings ...)
2026-11-30 0:55 ` [PATCH net 09/14] net: phy: as21xxx: Reject odd IPC payload lengths Cristian Ciocaltea
@ 2026-11-30 0:55 ` Cristian Ciocaltea
2026-11-30 3:01 ` Andrew Lunn
2026-11-30 0:55 ` [PATCH net 11/14] net: phy: as21xxx: Read 10/100/1000 link modes from C22 advertisement Cristian Ciocaltea
` (3 subsequent siblings)
13 siblings, 1 reply; 38+ messages in thread
From: Cristian Ciocaltea @ 2026-11-30 0:55 UTC (permalink / raw)
To: Christian Marangi, Andrew Lunn, Heiner Kallweit, Russell King,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: kernel, netdev
as21xxx_led_hw_control_set() looks up the requested rules in
as21xxx_led_supported_pattern, but does not check whether a match was
found. If the rules are not in the table, val keeps its initial value
of 0, so phy_modify_mmd() still gets called, overwriting the current LED
configuration with event 0, and the function returns success.
Return -EOPNOTSUPP when no matching pattern exists, before touching the
hardware, consistent with as21xxx_led_hw_is_supported(). As val is now
only used after a successful lookup, drop its redundant zero
initialization.
Fixes: 830877d89edc ("net: phy: Add support for Aeonsemi AS21xxx PHYs")
Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
---
drivers/net/phy/as21xxx.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/net/phy/as21xxx.c b/drivers/net/phy/as21xxx.c
index 90b6f528f76d..1c4a808bf01e 100644
--- a/drivers/net/phy/as21xxx.c
+++ b/drivers/net/phy/as21xxx.c
@@ -844,7 +844,7 @@ static int as21xxx_led_hw_control_get(struct phy_device *phydev, u8 index,
static int as21xxx_led_hw_control_set(struct phy_device *phydev, u8 index,
unsigned long rules)
{
- u16 val = 0;
+ u16 val;
int i;
if (index >= AEON_MAX_LEDS)
@@ -856,6 +856,9 @@ static int as21xxx_led_hw_control_set(struct phy_device *phydev, u8 index,
break;
}
+ if (i == ARRAY_SIZE(as21xxx_led_supported_pattern))
+ return -EOPNOTSUPP;
+
return phy_modify_mmd(phydev, MDIO_MMD_VEND1,
VEND1_LED_REG(index),
VEND1_LED_REG_A_EVENT,
--
2.56.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* Re: [PATCH net 10/14] net: phy: as21xxx: Fix LED hw control set for unsupported rules
2026-11-30 0:55 ` [PATCH net 10/14] net: phy: as21xxx: Fix LED hw control set for unsupported rules Cristian Ciocaltea
@ 2026-11-30 3:01 ` Andrew Lunn
2026-11-30 11:29 ` Cristian Ciocaltea
0 siblings, 1 reply; 38+ messages in thread
From: Andrew Lunn @ 2026-11-30 3:01 UTC (permalink / raw)
To: Cristian Ciocaltea
Cc: Christian Marangi, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, kernel, netdev
> + if (i == ARRAY_SIZE(as21xxx_led_supported_pattern))
> + return -EOPNOTSUPP;
> +
> return phy_modify_mmd(phydev, MDIO_MMD_VEND1,
> VEND1_LED_REG(index),
> VEND1_LED_REG_A_EVENT,
This works, but maybe:
for (i = 0; i < ARRAY_SIZE(as21xxx_led_supported_pattern); i++)
if (rules == as21xxx_led_supported_pattern[i].pattern) {
val = as21xxx_led_supported_pattern[i].val;
return phy_modify_mmd(phydev, MDIO_MMD_VEND1,
VEND1_LED_REG(index),
VEND1_LED_REG_A_EVENT,
FIELD_PREP(VEND1_LED_REG_A_EVENT,
val));
}
return -EOPNOTSUPP
}
Andrew
^ permalink raw reply [flat|nested] 38+ messages in thread* Re: [PATCH net 10/14] net: phy: as21xxx: Fix LED hw control set for unsupported rules
2026-11-30 3:01 ` Andrew Lunn
@ 2026-11-30 11:29 ` Cristian Ciocaltea
2026-11-30 13:37 ` Andrew Lunn
0 siblings, 1 reply; 38+ messages in thread
From: Cristian Ciocaltea @ 2026-11-30 11:29 UTC (permalink / raw)
To: Andrew Lunn
Cc: Christian Marangi, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, kernel, netdev
On 11/30/26 5:01 AM, Andrew Lunn wrote:
>> + if (i == ARRAY_SIZE(as21xxx_led_supported_pattern))
>> + return -EOPNOTSUPP;
>> +
>> return phy_modify_mmd(phydev, MDIO_MMD_VEND1,
>> VEND1_LED_REG(index),
>> VEND1_LED_REG_A_EVENT,
>
> This works, but maybe:
>
> for (i = 0; i < ARRAY_SIZE(as21xxx_led_supported_pattern); i++)
> if (rules == as21xxx_led_supported_pattern[i].pattern) {
> val = as21xxx_led_supported_pattern[i].val;
> return phy_modify_mmd(phydev, MDIO_MMD_VEND1,
> VEND1_LED_REG(index),
> VEND1_LED_REG_A_EVENT,
> FIELD_PREP(VEND1_LED_REG_A_EVENT,
> val));
>
> }
>
> return -EOPNOTSUPP
> }
On upcoming Gen2 PHY the LEDs are meant to be driven by the firmware via IPC
rather than by writing the vendor LED registers directly. The refactored block
will look like this:
info = aeon_led_find_pattern(phydev, rules);
if (!info)
return -EOPNOTSUPP;
return data->led_ops->set_event(phydev, index, info->val);
I'm happy to incorporate your suggestion if you prefer, though it will add some
churn to the diffs.
Cristian
^ permalink raw reply [flat|nested] 38+ messages in thread* Re: [PATCH net 10/14] net: phy: as21xxx: Fix LED hw control set for unsupported rules
2026-11-30 11:29 ` Cristian Ciocaltea
@ 2026-11-30 13:37 ` Andrew Lunn
0 siblings, 0 replies; 38+ messages in thread
From: Andrew Lunn @ 2026-11-30 13:37 UTC (permalink / raw)
To: Cristian Ciocaltea
Cc: Christian Marangi, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, kernel, netdev
On Mon, Nov 30, 2026 at 01:29:45PM +0200, Cristian Ciocaltea wrote:
> On 11/30/26 5:01 AM, Andrew Lunn wrote:
> >> + if (i == ARRAY_SIZE(as21xxx_led_supported_pattern))
> >> + return -EOPNOTSUPP;
> >> +
> >> return phy_modify_mmd(phydev, MDIO_MMD_VEND1,
> >> VEND1_LED_REG(index),
> >> VEND1_LED_REG_A_EVENT,
> >
> > This works, but maybe:
> >
> > for (i = 0; i < ARRAY_SIZE(as21xxx_led_supported_pattern); i++)
> > if (rules == as21xxx_led_supported_pattern[i].pattern) {
> > val = as21xxx_led_supported_pattern[i].val;
> > return phy_modify_mmd(phydev, MDIO_MMD_VEND1,
> > VEND1_LED_REG(index),
> > VEND1_LED_REG_A_EVENT,
> > FIELD_PREP(VEND1_LED_REG_A_EVENT,
> > val));
> >
> > }
> >
> > return -EOPNOTSUPP
> > }
>
> On upcoming Gen2 PHY the LEDs are meant to be driven by the firmware via IPC
> rather than by writing the vendor LED registers directly.
Why would a vendor implement an IPC, when MDIO is already an IPC?
It seems to me the quality of design of PHYs has gone down in recent
years.
Anyway...
> info = aeon_led_find_pattern(phydev, rules);
> if (!info)
> return -EOPNOTSUPP;
>
> return data->led_ops->set_event(phydev, index, info->val);
This is fine. I just did not like the:
if (i == ARRAY_SIZE(as21xxx_led_supported_pattern))
but that seems to be going away.
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
^ permalink raw reply [flat|nested] 38+ messages in thread
* [PATCH net 11/14] net: phy: as21xxx: Read 10/100/1000 link modes from C22 advertisement
2026-11-30 0:55 [PATCH net 00/14] net: phy: as21xxx: Fix a batch of driver issues Cristian Ciocaltea
` (9 preceding siblings ...)
2026-11-30 0:55 ` [PATCH net 10/14] net: phy: as21xxx: Fix LED hw control set for unsupported rules Cristian Ciocaltea
@ 2026-11-30 0:55 ` Cristian Ciocaltea
2026-11-30 3:34 ` Andrew Lunn
2026-11-30 0:55 ` [PATCH net 12/14] net: phy: as21xxx: Configure autoneg advertisement via IPC Cristian Ciocaltea
` (2 subsequent siblings)
13 siblings, 1 reply; 38+ messages in thread
From: Cristian Ciocaltea @ 2026-11-30 0:55 UTC (permalink / raw)
To: Christian Marangi, Andrew Lunn, Heiner Kallweit, Russell King,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: kernel, netdev
The Clause 45 ability registers hold a single bit for 10BASE-T and one
for 100BASE-TX, so genphy_c45_pma_read_abilities() derives both the full
and half duplex link modes from each of them, even on PHYs that support
neither 10BASE-T nor half duplex.
Read the 2.5G, 5G and 10G abilities from the Clause 45 registers as
before, then take the 10M, 100M and 1G link modes from the Clause 22
ADVERTISE and CTRL1000 registers mapped in the AN MMD. The firmware
does not update the C22 BMSR/ESTATUS ability bits, but its default
advertisement reflects the modes the PHY actually supports. If the
advertisement reads back empty, keep the Clause 45 derived modes.
Note that those registers mirror the current advertisement rather than a
fixed capability set, so they reflect the supported modes only while the
firmware defaults are in place. The PHY is reset when the driver is
unbound, so it reports the generic pre-firmware ID again and the
firmware is reloaded from .match_phy_device() before the next probe.
Hence .get_features() always samples the firmware defaults.
Fixes: 830877d89edc ("net: phy: Add support for Aeonsemi AS21xxx PHYs")
Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
---
drivers/net/phy/as21xxx.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 65 insertions(+)
diff --git a/drivers/net/phy/as21xxx.c b/drivers/net/phy/as21xxx.c
index 1c4a808bf01e..3423448a0cb1 100644
--- a/drivers/net/phy/as21xxx.c
+++ b/drivers/net/phy/as21xxx.c
@@ -644,6 +644,61 @@ static int as21xxx_probe(struct phy_device *phydev)
return aeon_dpc_ra_enable(phydev);
}
+static int as21xxx_get_features(struct phy_device *phydev)
+{
+ int ret, adv, ctrl1000;
+
+ /* Only the Clause 45 ability registers describe the 2.5G, 5G and 10G
+ * speeds.
+ */
+ ret = genphy_c45_pma_read_abilities(phydev);
+ if (ret)
+ return ret;
+
+ /* The C45 registers hold a single bit each for 10BASE-T and 100BASE-TX,
+ * so phylib sets both duplex modes. The firmware doesn't update the
+ * ability bits of the C22 BMSR/ESTATUS mapped in the AN MMD, but its
+ * default advertisement in the mapped ADVERTISE and CTRL1000 reflects
+ * the modes it actually supports, so take the 10M, 100M and 1G link
+ * modes from there.
+ */
+ adv = phy_read_mmd(phydev, MDIO_MMD_AN,
+ AS21XXX_MDIO_AN_C22 + MII_ADVERTISE);
+ if (adv < 0)
+ return adv;
+
+ ctrl1000 = phy_read_mmd(phydev, MDIO_MMD_AN,
+ AS21XXX_MDIO_AN_C22 + MII_CTRL1000);
+ if (ctrl1000 < 0)
+ return ctrl1000;
+
+ /* If the firmware defaults are not available, keep the C45-derived
+ * modes rather than dropping all 10/100/1000 link modes.
+ */
+ if (!(adv & ADVERTISE_ALL) ||
+ !(ctrl1000 & (ADVERTISE_1000HALF | ADVERTISE_1000FULL))) {
+ phydev_warn(phydev,
+ "Empty C22 advertisement, using C45 abilities\n");
+ return 0;
+ }
+
+ linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT_Half_BIT,
+ phydev->supported, adv & ADVERTISE_10HALF);
+ linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT_Full_BIT,
+ phydev->supported, adv & ADVERTISE_10FULL);
+ linkmode_mod_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT,
+ phydev->supported, adv & ADVERTISE_100HALF);
+ linkmode_mod_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT,
+ phydev->supported, adv & ADVERTISE_100FULL);
+
+ linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT,
+ phydev->supported, ctrl1000 & ADVERTISE_1000HALF);
+ linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
+ phydev->supported, ctrl1000 & ADVERTISE_1000FULL);
+
+ return 0;
+}
+
static int as21xxx_read_link(struct phy_device *phydev, int *bmcr)
{
int status;
@@ -981,6 +1036,7 @@ static struct phy_driver as21xxx_drivers[] = {
.probe = as21xxx_probe,
.match_phy_device = as21xxx_match_phy_device,
.read_status = as21xxx_read_status,
+ .get_features = as21xxx_get_features,
.led_brightness_set = as21xxx_led_brightness_set,
.led_hw_is_supported = as21xxx_led_hw_is_supported,
.led_hw_control_set = as21xxx_led_hw_control_set,
@@ -993,6 +1049,7 @@ static struct phy_driver as21xxx_drivers[] = {
.probe = as21xxx_probe,
.match_phy_device = as21xxx_match_phy_device,
.read_status = as21xxx_read_status,
+ .get_features = as21xxx_get_features,
.led_brightness_set = as21xxx_led_brightness_set,
.led_hw_is_supported = as21xxx_led_hw_is_supported,
.led_hw_control_set = as21xxx_led_hw_control_set,
@@ -1005,6 +1062,7 @@ static struct phy_driver as21xxx_drivers[] = {
.probe = as21xxx_probe,
.match_phy_device = as21xxx_match_phy_device,
.read_status = as21xxx_read_status,
+ .get_features = as21xxx_get_features,
.led_brightness_set = as21xxx_led_brightness_set,
.led_hw_is_supported = as21xxx_led_hw_is_supported,
.led_hw_control_set = as21xxx_led_hw_control_set,
@@ -1017,6 +1075,7 @@ static struct phy_driver as21xxx_drivers[] = {
.probe = as21xxx_probe,
.match_phy_device = as21xxx_match_phy_device,
.read_status = as21xxx_read_status,
+ .get_features = as21xxx_get_features,
.led_brightness_set = as21xxx_led_brightness_set,
.led_hw_is_supported = as21xxx_led_hw_is_supported,
.led_hw_control_set = as21xxx_led_hw_control_set,
@@ -1029,6 +1088,7 @@ static struct phy_driver as21xxx_drivers[] = {
.probe = as21xxx_probe,
.match_phy_device = as21xxx_match_phy_device,
.read_status = as21xxx_read_status,
+ .get_features = as21xxx_get_features,
.led_brightness_set = as21xxx_led_brightness_set,
.led_hw_is_supported = as21xxx_led_hw_is_supported,
.led_hw_control_set = as21xxx_led_hw_control_set,
@@ -1041,6 +1101,7 @@ static struct phy_driver as21xxx_drivers[] = {
.probe = as21xxx_probe,
.match_phy_device = as21xxx_match_phy_device,
.read_status = as21xxx_read_status,
+ .get_features = as21xxx_get_features,
.led_brightness_set = as21xxx_led_brightness_set,
.led_hw_is_supported = as21xxx_led_hw_is_supported,
.led_hw_control_set = as21xxx_led_hw_control_set,
@@ -1053,6 +1114,7 @@ static struct phy_driver as21xxx_drivers[] = {
.probe = as21xxx_probe,
.match_phy_device = as21xxx_match_phy_device,
.read_status = as21xxx_read_status,
+ .get_features = as21xxx_get_features,
.led_brightness_set = as21xxx_led_brightness_set,
.led_hw_is_supported = as21xxx_led_hw_is_supported,
.led_hw_control_set = as21xxx_led_hw_control_set,
@@ -1065,6 +1127,7 @@ static struct phy_driver as21xxx_drivers[] = {
.probe = as21xxx_probe,
.match_phy_device = as21xxx_match_phy_device,
.read_status = as21xxx_read_status,
+ .get_features = as21xxx_get_features,
.led_brightness_set = as21xxx_led_brightness_set,
.led_hw_is_supported = as21xxx_led_hw_is_supported,
.led_hw_control_set = as21xxx_led_hw_control_set,
@@ -1077,6 +1140,7 @@ static struct phy_driver as21xxx_drivers[] = {
.probe = as21xxx_probe,
.match_phy_device = as21xxx_match_phy_device,
.read_status = as21xxx_read_status,
+ .get_features = as21xxx_get_features,
.led_brightness_set = as21xxx_led_brightness_set,
.led_hw_is_supported = as21xxx_led_hw_is_supported,
.led_hw_control_set = as21xxx_led_hw_control_set,
@@ -1089,6 +1153,7 @@ static struct phy_driver as21xxx_drivers[] = {
.probe = as21xxx_probe,
.match_phy_device = as21xxx_match_phy_device,
.read_status = as21xxx_read_status,
+ .get_features = as21xxx_get_features,
.led_brightness_set = as21xxx_led_brightness_set,
.led_hw_is_supported = as21xxx_led_hw_is_supported,
.led_hw_control_set = as21xxx_led_hw_control_set,
--
2.56.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* Re: [PATCH net 11/14] net: phy: as21xxx: Read 10/100/1000 link modes from C22 advertisement
2026-11-30 0:55 ` [PATCH net 11/14] net: phy: as21xxx: Read 10/100/1000 link modes from C22 advertisement Cristian Ciocaltea
@ 2026-11-30 3:34 ` Andrew Lunn
2026-11-30 11:53 ` Cristian Ciocaltea
0 siblings, 1 reply; 38+ messages in thread
From: Andrew Lunn @ 2026-11-30 3:34 UTC (permalink / raw)
To: Cristian Ciocaltea
Cc: Christian Marangi, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, kernel, netdev
On Mon, Nov 30, 2026 at 02:55:18AM +0200, Cristian Ciocaltea wrote:
> The Clause 45 ability registers hold a single bit for 10BASE-T and one
> for 100BASE-TX, so genphy_c45_pma_read_abilities() derives both the full
> and half duplex link modes from each of them, even on PHYs that support
> neither 10BASE-T nor half duplex.
>
> Read the 2.5G, 5G and 10G abilities from the Clause 45 registers as
> before, then take the 10M, 100M and 1G link modes from the Clause 22
> ADVERTISE and CTRL1000 registers mapped in the AN MMD. The firmware
> does not update the C22 BMSR/ESTATUS ability bits, but its default
> advertisement reflects the modes the PHY actually supports. If the
> advertisement reads back empty, keep the Clause 45 derived modes.
This is funky, i'm not sure this is a safe assumption to make.
Is it known what this PHY actually supports?
I think it would be better to just accept the firmware is broken and
hard code the 10/100/1G link modes after calling
genphy_c45_pma_read_abilities().
Andrew
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: [PATCH net 11/14] net: phy: as21xxx: Read 10/100/1000 link modes from C22 advertisement
2026-11-30 3:34 ` Andrew Lunn
@ 2026-11-30 11:53 ` Cristian Ciocaltea
2026-11-30 13:39 ` Andrew Lunn
0 siblings, 1 reply; 38+ messages in thread
From: Cristian Ciocaltea @ 2026-11-30 11:53 UTC (permalink / raw)
To: Andrew Lunn
Cc: Christian Marangi, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, kernel, netdev
On 11/30/26 5:34 AM, Andrew Lunn wrote:
> On Mon, Nov 30, 2026 at 02:55:18AM +0200, Cristian Ciocaltea wrote:
>> The Clause 45 ability registers hold a single bit for 10BASE-T and one
>> for 100BASE-TX, so genphy_c45_pma_read_abilities() derives both the full
>> and half duplex link modes from each of them, even on PHYs that support
>> neither 10BASE-T nor half duplex.
>>
>> Read the 2.5G, 5G and 10G abilities from the Clause 45 registers as
>> before, then take the 10M, 100M and 1G link modes from the Clause 22
>> ADVERTISE and CTRL1000 registers mapped in the AN MMD. The firmware
>> does not update the C22 BMSR/ESTATUS ability bits, but its default
>> advertisement reflects the modes the PHY actually supports. If the
>> advertisement reads back empty, keep the Clause 45 derived modes.
>
> This is funky, i'm not sure this is a safe assumption to make.
>
> Is it known what this PHY actually supports?
>
> I think it would be better to just accept the firmware is broken and
> hard code the 10/100/1G link modes after calling
> genphy_c45_pma_read_abilities().
Yeah, the firmware is definitely broken. This is what ethtool currently shows
for both PHY generations:
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Half 1000baseT/Full
10000baseT/Full
2500baseT/Full
5000baseT/Full
However, my understanding is that Gen1 doesn't actually support 10baseT, only
Gen2 does, while 100baseT/Half is never advertised by the firmware. I can go
with the hard-coded approach, as there doesn't seem to be a better or more
reliable way to get this information from the hardware.
Thanks,
Cristian
^ permalink raw reply [flat|nested] 38+ messages in thread* Re: [PATCH net 11/14] net: phy: as21xxx: Read 10/100/1000 link modes from C22 advertisement
2026-11-30 11:53 ` Cristian Ciocaltea
@ 2026-11-30 13:39 ` Andrew Lunn
0 siblings, 0 replies; 38+ messages in thread
From: Andrew Lunn @ 2026-11-30 13:39 UTC (permalink / raw)
To: Cristian Ciocaltea
Cc: Christian Marangi, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, kernel, netdev
> Yeah, the firmware is definitely broken. This is what ethtool currently shows
> for both PHY generations:
>
> Supported link modes: 10baseT/Half 10baseT/Full
> 100baseT/Half 100baseT/Full
> 1000baseT/Half 1000baseT/Full
> 10000baseT/Full
> 2500baseT/Full
> 5000baseT/Full
>
> However, my understanding is that Gen1 doesn't actually support 10baseT, only
> Gen2 does, while 100baseT/Half is never advertised by the firmware. I can go
> with the hard-coded approach, as there doesn't seem to be a better or more
> reliable way to get this information from the hardware.
Yes, hardwired is normal. See the mess aquantia made with their PHY as
an example.
Andrew
^ permalink raw reply [flat|nested] 38+ messages in thread
* [PATCH net 12/14] net: phy: as21xxx: Configure autoneg advertisement via IPC
2026-11-30 0:55 [PATCH net 00/14] net: phy: as21xxx: Fix a batch of driver issues Cristian Ciocaltea
` (10 preceding siblings ...)
2026-11-30 0:55 ` [PATCH net 11/14] net: phy: as21xxx: Read 10/100/1000 link modes from C22 advertisement Cristian Ciocaltea
@ 2026-11-30 0:55 ` Cristian Ciocaltea
2026-11-30 3:43 ` Andrew Lunn
2026-11-30 0:55 ` [PATCH net 13/14] net: phy: as21xxx: Fix speed and duplex reporting Cristian Ciocaltea
2026-11-30 0:55 ` [PATCH net 14/14] net: phy: as21xxx: Release reset before reading ID in match Cristian Ciocaltea
13 siblings, 1 reply; 38+ messages in thread
From: Cristian Ciocaltea @ 2026-11-30 0:55 UTC (permalink / raw)
To: Christian Marangi, Andrew Lunn, Heiner Kallweit, Russell King,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: kernel, netdev
The PHY does not properly support the Clause 45 auto-negotiation
registers that phylib writes from genphy_c45_config_aneg(). As a
consequence, restricting the advertisement from userspace does not have
the expected outcome on the wire. For example, setting it to
2500baseT/Full will confuse the peer, as 5000baseT/Full still shows up
in the link partner advertised link modes. Even worse, setting it to
100baseT/Full + 1000baseT/Full will end up with a broken link, because
the peer would only see the unrelated 2500baseT/Full + 5000baseT/Full
modes.
Since the firmware owns the advertisement and is reachable over IPC,
implement the .config_aneg callback and pass the highest advertised
speed. Cache it and only restart autoneg when it changes, as
genphy_c45_config_aneg() does, so that phy_start_aneg() does not take
the link down unnecessarily. Forced mode invalidates the cache so that
autoneg is restarted once it is re-enabled. So does .config_init, since
the firmware might have lost the setting, e.g. across a suspend/resume
cycle.
Note that the related IPC command only takes a top speed, and every
slower speed the PHY supports is advertised along with it. An arbitrary
subset cannot be described yet, so a link can still be negotiated below
the slowest speed that was asked for. Add those slower speeds to
phydev->advertising so that it reflects what is actually advertised on
the wire. If no BASE-T speed is advertised, which ethtool still allows,
fall back to the slowest supported one rather than leaving the PHY in
the error state.
Fixes: 830877d89edc ("net: phy: Add support for Aeonsemi AS21xxx PHYs")
Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
---
drivers/net/phy/as21xxx.c | 169 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 169 insertions(+)
diff --git a/drivers/net/phy/as21xxx.c b/drivers/net/phy/as21xxx.c
index 3423448a0cb1..967ff3020814 100644
--- a/drivers/net/phy/as21xxx.c
+++ b/drivers/net/phy/as21xxx.c
@@ -112,6 +112,18 @@
#define IPC_CFG_PARAM_DIRECT_TEMP_MON 0x11
#define IPC_CFG_PARAM_DIRECT_WOL 0x12
+/* Sub command of IPC_CFG_PARAM_DIRECT_CU_AN */
+#define IPC_CU_AN_RESTART 0xa
+#define IPC_CU_AN_TOP_SPD 0xc
+
+/* Argument of IPC_CU_AN_TOP_SPD */
+#define IPC_CU_AN_TOP_SPD_10 BIT(1)
+#define IPC_CU_AN_TOP_SPD_100 BIT(2)
+#define IPC_CU_AN_TOP_SPD_1000 BIT(3)
+#define IPC_CU_AN_TOP_SPD_2500 BIT(4)
+#define IPC_CU_AN_TOP_SPD_5000 BIT(5)
+#define IPC_CU_AN_TOP_SPD_10000 BIT(6)
+
/* Sub command of CMD_TEMP_MON */
#define IPC_CMD_TEMP_MON_GET 0x4
@@ -186,6 +198,11 @@ struct as21xxx_priv {
bool parity_status;
/* Protect concurrent IPC access */
struct mutex ipc_lock;
+ /* Top speed last handed to the firmware, 0 when it has to be sent
+ * again. Updated under phydev->lock, or while the state machine is
+ * stopped.
+ */
+ u16 top_spd;
};
static struct as21xxx_led_pattern_info as21xxx_led_supported_pattern[] = {
@@ -841,6 +858,138 @@ static int as21xxx_read_status(struct phy_device *phydev)
return 0;
}
+static int aeon_restart_aneg(struct phy_device *phydev)
+{
+ u16 data[3];
+
+ data[0] = IPC_CFG_PARAM_DIRECT;
+ data[1] = IPC_CFG_PARAM_DIRECT_CU_AN;
+ data[2] = IPC_CU_AN_RESTART;
+
+ return aeon_ipc_send_msg(phydev, IPC_CMD_CFG_PARAM, data,
+ sizeof(data), NULL);
+}
+
+static int aeon_set_top_speed(struct phy_device *phydev, u16 top_spd)
+{
+ u16 data[4];
+
+ data[0] = IPC_CFG_PARAM_DIRECT;
+ data[1] = IPC_CFG_PARAM_DIRECT_CU_AN;
+ data[2] = IPC_CU_AN_TOP_SPD;
+ data[3] = top_spd;
+
+ return aeon_ipc_send_msg(phydev, IPC_CMD_CFG_PARAM, data,
+ sizeof(data), NULL);
+}
+
+/* Highest speed first, the firmware is given the fastest advertised one */
+static const struct {
+ u16 top_spd;
+ int linkmode;
+} aeon_top_speeds[] = {
+ { IPC_CU_AN_TOP_SPD_10000, ETHTOOL_LINK_MODE_10000baseT_Full_BIT },
+ { IPC_CU_AN_TOP_SPD_5000, ETHTOOL_LINK_MODE_5000baseT_Full_BIT },
+ { IPC_CU_AN_TOP_SPD_2500, ETHTOOL_LINK_MODE_2500baseT_Full_BIT },
+ { IPC_CU_AN_TOP_SPD_1000, ETHTOOL_LINK_MODE_1000baseT_Full_BIT },
+ { IPC_CU_AN_TOP_SPD_1000, ETHTOOL_LINK_MODE_1000baseT_Half_BIT },
+ { IPC_CU_AN_TOP_SPD_100, ETHTOOL_LINK_MODE_100baseT_Full_BIT },
+ { IPC_CU_AN_TOP_SPD_100, ETHTOOL_LINK_MODE_100baseT_Half_BIT },
+ { IPC_CU_AN_TOP_SPD_10, ETHTOOL_LINK_MODE_10baseT_Full_BIT },
+ { IPC_CU_AN_TOP_SPD_10, ETHTOOL_LINK_MODE_10baseT_Half_BIT },
+};
+
+static int as21xxx_config_init(struct phy_device *phydev)
+{
+ struct as21xxx_priv *priv = phydev->priv;
+
+ /* The firmware might have lost the top speed, e.g. across a
+ * suspend/resume cycle, make sure the next .config_aneg sends it.
+ */
+ priv->top_spd = 0;
+
+ return 0;
+}
+
+static int as21xxx_config_aneg(struct phy_device *phydev)
+{
+ struct as21xxx_priv *priv = phydev->priv;
+ u16 top_spd;
+ int ret, i;
+
+ if (phydev->autoneg == AUTONEG_DISABLE) {
+ /* Make sure autoneg is restarted once enabled again */
+ priv->top_spd = 0;
+
+ return genphy_c45_pma_setup_forced(phydev);
+ }
+
+ /* The firmware doesn't properly support the C45 autoneg registers, so
+ * it has to be told over the IPC instead. Only the highest speed can
+ * be described at the moment, the slower ones the PHY supports are
+ * implicitly advertised along with it.
+ */
+ for (i = 0; i < ARRAY_SIZE(aeon_top_speeds); i++)
+ if (linkmode_test_bit(aeon_top_speeds[i].linkmode,
+ phydev->advertising))
+ break;
+
+ /* None of the BASE-T speeds is advertised, e.g. after
+ * "ethtool -s ... autoneg on speed 10" on a PHY lacking 10M. The IPC
+ * cannot advertise nothing, and an error would only put the PHY in
+ * the error state, so fall back to the slowest supported speed.
+ */
+ if (i == ARRAY_SIZE(aeon_top_speeds)) {
+ while (--i >= 0 &&
+ !linkmode_test_bit(aeon_top_speeds[i].linkmode,
+ phydev->supported))
+ ;
+
+ if (i < 0)
+ return -EINVAL;
+ }
+
+ top_spd = aeon_top_speeds[i].top_spd;
+
+ /* Let the advertisement reflect the slower speeds which go on the
+ * wire along with the highest one.
+ */
+ for (i = 0; i < ARRAY_SIZE(aeon_top_speeds); i++)
+ if (aeon_top_speeds[i].top_spd <= top_spd &&
+ linkmode_test_bit(aeon_top_speeds[i].linkmode,
+ phydev->supported))
+ linkmode_set_bit(aeon_top_speeds[i].linkmode,
+ phydev->advertising);
+
+ /* Restarting autoneg takes the link down, so only do it when the
+ * advertisement changed, or has to be sent again.
+ */
+ if (top_spd == priv->top_spd)
+ return 0;
+
+ ret = aeon_set_top_speed(phydev, top_spd);
+ if (ret)
+ return ret;
+
+ if (!priv->top_spd) {
+ /* genphy_c45_pma_setup_forced() clears MDIO_AN_CTRL1_ENABLE,
+ * which restarting autoneg over the IPC doesn't set back.
+ */
+ ret = phy_set_bits_mmd(phydev, MDIO_MMD_AN, MDIO_CTRL1,
+ MDIO_AN_CTRL1_ENABLE);
+ if (ret)
+ return ret;
+ }
+
+ ret = aeon_restart_aneg(phydev);
+ if (ret)
+ return ret;
+
+ priv->top_spd = top_spd;
+
+ return 0;
+}
+
static int as21xxx_led_brightness_set(struct phy_device *phydev,
u8 index, enum led_brightness value)
{
@@ -1037,6 +1186,8 @@ static struct phy_driver as21xxx_drivers[] = {
.match_phy_device = as21xxx_match_phy_device,
.read_status = as21xxx_read_status,
.get_features = as21xxx_get_features,
+ .config_init = as21xxx_config_init,
+ .config_aneg = as21xxx_config_aneg,
.led_brightness_set = as21xxx_led_brightness_set,
.led_hw_is_supported = as21xxx_led_hw_is_supported,
.led_hw_control_set = as21xxx_led_hw_control_set,
@@ -1050,6 +1201,8 @@ static struct phy_driver as21xxx_drivers[] = {
.match_phy_device = as21xxx_match_phy_device,
.read_status = as21xxx_read_status,
.get_features = as21xxx_get_features,
+ .config_init = as21xxx_config_init,
+ .config_aneg = as21xxx_config_aneg,
.led_brightness_set = as21xxx_led_brightness_set,
.led_hw_is_supported = as21xxx_led_hw_is_supported,
.led_hw_control_set = as21xxx_led_hw_control_set,
@@ -1063,6 +1216,8 @@ static struct phy_driver as21xxx_drivers[] = {
.match_phy_device = as21xxx_match_phy_device,
.read_status = as21xxx_read_status,
.get_features = as21xxx_get_features,
+ .config_init = as21xxx_config_init,
+ .config_aneg = as21xxx_config_aneg,
.led_brightness_set = as21xxx_led_brightness_set,
.led_hw_is_supported = as21xxx_led_hw_is_supported,
.led_hw_control_set = as21xxx_led_hw_control_set,
@@ -1076,6 +1231,8 @@ static struct phy_driver as21xxx_drivers[] = {
.match_phy_device = as21xxx_match_phy_device,
.read_status = as21xxx_read_status,
.get_features = as21xxx_get_features,
+ .config_init = as21xxx_config_init,
+ .config_aneg = as21xxx_config_aneg,
.led_brightness_set = as21xxx_led_brightness_set,
.led_hw_is_supported = as21xxx_led_hw_is_supported,
.led_hw_control_set = as21xxx_led_hw_control_set,
@@ -1089,6 +1246,8 @@ static struct phy_driver as21xxx_drivers[] = {
.match_phy_device = as21xxx_match_phy_device,
.read_status = as21xxx_read_status,
.get_features = as21xxx_get_features,
+ .config_init = as21xxx_config_init,
+ .config_aneg = as21xxx_config_aneg,
.led_brightness_set = as21xxx_led_brightness_set,
.led_hw_is_supported = as21xxx_led_hw_is_supported,
.led_hw_control_set = as21xxx_led_hw_control_set,
@@ -1102,6 +1261,8 @@ static struct phy_driver as21xxx_drivers[] = {
.match_phy_device = as21xxx_match_phy_device,
.read_status = as21xxx_read_status,
.get_features = as21xxx_get_features,
+ .config_init = as21xxx_config_init,
+ .config_aneg = as21xxx_config_aneg,
.led_brightness_set = as21xxx_led_brightness_set,
.led_hw_is_supported = as21xxx_led_hw_is_supported,
.led_hw_control_set = as21xxx_led_hw_control_set,
@@ -1115,6 +1276,8 @@ static struct phy_driver as21xxx_drivers[] = {
.match_phy_device = as21xxx_match_phy_device,
.read_status = as21xxx_read_status,
.get_features = as21xxx_get_features,
+ .config_init = as21xxx_config_init,
+ .config_aneg = as21xxx_config_aneg,
.led_brightness_set = as21xxx_led_brightness_set,
.led_hw_is_supported = as21xxx_led_hw_is_supported,
.led_hw_control_set = as21xxx_led_hw_control_set,
@@ -1128,6 +1291,8 @@ static struct phy_driver as21xxx_drivers[] = {
.match_phy_device = as21xxx_match_phy_device,
.read_status = as21xxx_read_status,
.get_features = as21xxx_get_features,
+ .config_init = as21xxx_config_init,
+ .config_aneg = as21xxx_config_aneg,
.led_brightness_set = as21xxx_led_brightness_set,
.led_hw_is_supported = as21xxx_led_hw_is_supported,
.led_hw_control_set = as21xxx_led_hw_control_set,
@@ -1141,6 +1306,8 @@ static struct phy_driver as21xxx_drivers[] = {
.match_phy_device = as21xxx_match_phy_device,
.read_status = as21xxx_read_status,
.get_features = as21xxx_get_features,
+ .config_init = as21xxx_config_init,
+ .config_aneg = as21xxx_config_aneg,
.led_brightness_set = as21xxx_led_brightness_set,
.led_hw_is_supported = as21xxx_led_hw_is_supported,
.led_hw_control_set = as21xxx_led_hw_control_set,
@@ -1154,6 +1321,8 @@ static struct phy_driver as21xxx_drivers[] = {
.match_phy_device = as21xxx_match_phy_device,
.read_status = as21xxx_read_status,
.get_features = as21xxx_get_features,
+ .config_init = as21xxx_config_init,
+ .config_aneg = as21xxx_config_aneg,
.led_brightness_set = as21xxx_led_brightness_set,
.led_hw_is_supported = as21xxx_led_hw_is_supported,
.led_hw_control_set = as21xxx_led_hw_control_set,
--
2.56.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* Re: [PATCH net 12/14] net: phy: as21xxx: Configure autoneg advertisement via IPC
2026-11-30 0:55 ` [PATCH net 12/14] net: phy: as21xxx: Configure autoneg advertisement via IPC Cristian Ciocaltea
@ 2026-11-30 3:43 ` Andrew Lunn
2026-11-30 12:05 ` Cristian Ciocaltea
0 siblings, 1 reply; 38+ messages in thread
From: Andrew Lunn @ 2026-11-30 3:43 UTC (permalink / raw)
To: Cristian Ciocaltea
Cc: Christian Marangi, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, kernel, netdev
On Mon, Nov 30, 2026 at 02:55:19AM +0200, Cristian Ciocaltea wrote:
> The PHY does not properly support the Clause 45 auto-negotiation
> registers that phylib writes from genphy_c45_config_aneg(). As a
> consequence, restricting the advertisement from userspace does not have
> the expected outcome on the wire. For example, setting it to
> 2500baseT/Full will confuse the peer, as 5000baseT/Full still shows up
> in the link partner advertised link modes. Even worse, setting it to
> 100baseT/Full + 1000baseT/Full will end up with a broken link, because
> the peer would only see the unrelated 2500baseT/Full + 5000baseT/Full
> modes.
>
> Since the firmware owns the advertisement and is reachable over IPC,
> implement the .config_aneg callback and pass the highest advertised
> speed.
That is not technically correct.
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
There is free choice of any combination of the supported modes.
It should be possible to ask it to advertise
Advertised link modes: 10baseT/Half 1000baseT/Full
I find it surprising it is totally broken. 10/100/1G are often in
vendor registers, so you might need to implement those link modes
separately to the standard C45 2500, 5000 and 10G.
Andrew
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: [PATCH net 12/14] net: phy: as21xxx: Configure autoneg advertisement via IPC
2026-11-30 3:43 ` Andrew Lunn
@ 2026-11-30 12:05 ` Cristian Ciocaltea
0 siblings, 0 replies; 38+ messages in thread
From: Cristian Ciocaltea @ 2026-11-30 12:05 UTC (permalink / raw)
To: Andrew Lunn
Cc: Christian Marangi, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, kernel, netdev
On 11/30/26 5:43 AM, Andrew Lunn wrote:
> On Mon, Nov 30, 2026 at 02:55:19AM +0200, Cristian Ciocaltea wrote:
>> The PHY does not properly support the Clause 45 auto-negotiation
>> registers that phylib writes from genphy_c45_config_aneg(). As a
>> consequence, restricting the advertisement from userspace does not have
>> the expected outcome on the wire. For example, setting it to
>> 2500baseT/Full will confuse the peer, as 5000baseT/Full still shows up
>> in the link partner advertised link modes. Even worse, setting it to
>> 100baseT/Full + 1000baseT/Full will end up with a broken link, because
>> the peer would only see the unrelated 2500baseT/Full + 5000baseT/Full
>> modes.
>>
>> Since the firmware owns the advertisement and is reachable over IPC,
>> implement the .config_aneg callback and pass the highest advertised
>> speed.
>
> That is not technically correct.
>
> Supported link modes: 10baseT/Half 10baseT/Full
> 100baseT/Half 100baseT/Full
> 1000baseT/Full
>
> There is free choice of any combination of the supported modes.
> It should be possible to ask it to advertise
>
> Advertised link modes: 10baseT/Half 1000baseT/Full
>
> I find it surprising it is totally broken. 10/100/1G are often in
> vendor registers, so you might need to implement those link modes
> separately to the standard C45 2500, 5000 and 10G.
Yeah, this was unexpected for me as well, but I later confirmed it with the
vendor: the firmware doesn't support arbitrary combinations of modes. It can
only take a top speed, and everything below is implicitly advertised :-(
Cristian
^ permalink raw reply [flat|nested] 38+ messages in thread
* [PATCH net 13/14] net: phy: as21xxx: Fix speed and duplex reporting
2026-11-30 0:55 [PATCH net 00/14] net: phy: as21xxx: Fix a batch of driver issues Cristian Ciocaltea
` (11 preceding siblings ...)
2026-11-30 0:55 ` [PATCH net 12/14] net: phy: as21xxx: Configure autoneg advertisement via IPC Cristian Ciocaltea
@ 2026-11-30 0:55 ` Cristian Ciocaltea
2026-11-30 3:50 ` Andrew Lunn
2026-11-30 0:55 ` [PATCH net 14/14] net: phy: as21xxx: Release reset before reading ID in match Cristian Ciocaltea
13 siblings, 1 reply; 38+ messages in thread
From: Cristian Ciocaltea @ 2026-11-30 0:55 UTC (permalink / raw)
To: Christian Marangi, Andrew Lunn, Heiner Kallweit, Russell King,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: kernel, netdev
With autoneg enabled, as21xxx_read_status() derives the result purely in
software via phy_resolve_aneg_linkmode(). That does not work reliably
here: the advertisement is driven by the firmware over IPC, which
ignores the Clause 45 AN registers phylib writes except for the maximum
speed, and arbitrary subsets of speeds are not supported. The speed the
firmware actually settles on can therefore differ from what resolving
the advertised and link partner abilities yields.
Use VEND1_SPEED_STATUS, the authoritative source, on the autoneg path
too. Since aeon_config_aneg() makes phydev->advertising reflect what
the firmware puts on the wire, it is still reliable for picking the
duplex mode at that speed: resolve duplex from the link partner
advertisement (2.5GBASE-T and above are full duplex only), then resolve
pause. Parallel detection at 10/100M implies half duplex, unless the
PHY lacks it.
The link partner abilities are read from the Clause 22 registers mapped
in the AN MMD (base page and 1000BASE-T status), plus the 10GBASE-T
status register for 2.5G/5G/10G. Rename as21xxx_read_c22_lpa() to
as21xxx_read_lpa() accordingly, as it no longer covers Clause 22 only.
Speed and link partner abilities are only read once the link is up and
are reported unknown until then. An unrecognised speed status holds the
link down instead of failing read_status, which would move the PHY to
PHY_ERROR. I/O errors are still propagated.
With autoneg disabled, report the settings programmed by
genphy_c45_pma_setup_forced() via genphy_c45_read_pma(), regardless of
link state. Otherwise phy_sanitize_settings() sees unknown values on
the next autoneg restart with the link down and falls back to the
slowest mode. As a result, the BMCR_FULLDPLX check goes away, as it was
never set in Clause 45 forced mode, which is full duplex only. With the
link up, the speed is still taken from VEND1_SPEED_STATUS.
Fixes: 830877d89edc ("net: phy: Add support for Aeonsemi AS21xxx PHYs")
Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
---
drivers/net/phy/as21xxx.c | 200 ++++++++++++++++++++++++++++++++--------------
1 file changed, 141 insertions(+), 59 deletions(-)
diff --git a/drivers/net/phy/as21xxx.c b/drivers/net/phy/as21xxx.c
index 967ff3020814..5eea6baa75bf 100644
--- a/drivers/net/phy/as21xxx.c
+++ b/drivers/net/phy/as21xxx.c
@@ -716,22 +716,22 @@ static int as21xxx_get_features(struct phy_device *phydev)
return 0;
}
-static int as21xxx_read_link(struct phy_device *phydev, int *bmcr)
+static int as21xxx_read_link(struct phy_device *phydev)
{
- int status;
+ int bmcr, status;
/* Normal C22 BMCR report inconsistent data, use
* the mapped C22 in C45 to have more consistent link info.
*/
- *bmcr = phy_read_mmd(phydev, MDIO_MMD_AN,
- AS21XXX_MDIO_AN_C22 + MII_BMCR);
- if (*bmcr < 0)
- return *bmcr;
+ bmcr = phy_read_mmd(phydev, MDIO_MMD_AN,
+ AS21XXX_MDIO_AN_C22 + MII_BMCR);
+ if (bmcr < 0)
+ return bmcr;
/* Autoneg is being started, therefore disregard current
* link status and report link as down.
*/
- if (*bmcr & BMCR_ANRESTART) {
+ if (bmcr & BMCR_ANRESTART) {
phydev->link = 0;
return 0;
}
@@ -752,9 +752,9 @@ static int as21xxx_read_link(struct phy_device *phydev, int *bmcr)
return 0;
}
-static int as21xxx_read_c22_lpa(struct phy_device *phydev)
+static int as21xxx_read_lpa(struct phy_device *phydev)
{
- int lpagb;
+ int lpagb, lpa;
/* MII_STAT1000 are only filled in the mapped C22
* in C45, use that to fill lpagb values and check.
@@ -781,15 +781,107 @@ static int as21xxx_read_c22_lpa(struct phy_device *phydev)
mii_stat1000_mod_linkmode_lpa_t(phydev->lp_advertising,
lpagb);
+ /* Same goes for the base page of the link partner */
+ lpa = phy_read_mmd(phydev, MDIO_MMD_AN,
+ AS21XXX_MDIO_AN_C22 + MII_LPA);
+ if (lpa < 0)
+ return lpa;
+
+ mii_lpa_mod_linkmode_lpa_t(phydev->lp_advertising, lpa);
+
+ lpagb = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_10GBT_STAT);
+ if (lpagb < 0)
+ return lpagb;
+
+ mii_10gbt_stat_mod_linkmode_lpa_t(phydev->lp_advertising, lpagb);
+
return 0;
}
+static int as21xxx_read_speed(struct phy_device *phydev)
+{
+ int val;
+
+ val = phy_read_mmd(phydev, MDIO_MMD_VEND1, VEND1_SPEED_STATUS);
+ if (val < 0)
+ return val;
+
+ switch (val & VEND1_SPEED_MASK) {
+ case VEND1_SPEED_10000:
+ phydev->speed = SPEED_10000;
+ break;
+ case VEND1_SPEED_5000:
+ phydev->speed = SPEED_5000;
+ break;
+ case VEND1_SPEED_2500:
+ phydev->speed = SPEED_2500;
+ break;
+ case VEND1_SPEED_1000:
+ phydev->speed = SPEED_1000;
+ break;
+ case VEND1_SPEED_100:
+ phydev->speed = SPEED_100;
+ break;
+ case VEND1_SPEED_10:
+ phydev->speed = SPEED_10;
+ break;
+ default:
+ dev_warn_once(&phydev->mdio.dev,
+ "Unknown speed status 0x%04x\n", val);
+ phydev->speed = SPEED_UNKNOWN;
+ break;
+ }
+
+ return 0;
+}
+
+/* Pick the duplex mode negotiated for the speed the link came up at */
+static void as21xxx_resolve_duplex(struct phy_device *phydev)
+{
+ __ETHTOOL_DECLARE_LINK_MODE_MASK(common);
+ int full, half;
+
+ switch (phydev->speed) {
+ case SPEED_1000:
+ full = ETHTOOL_LINK_MODE_1000baseT_Full_BIT;
+ half = ETHTOOL_LINK_MODE_1000baseT_Half_BIT;
+ break;
+ case SPEED_100:
+ full = ETHTOOL_LINK_MODE_100baseT_Full_BIT;
+ half = ETHTOOL_LINK_MODE_100baseT_Half_BIT;
+ break;
+ case SPEED_10:
+ full = ETHTOOL_LINK_MODE_10baseT_Full_BIT;
+ half = ETHTOOL_LINK_MODE_10baseT_Half_BIT;
+ break;
+ default:
+ /* 2.5GBASE-T and above are full duplex only */
+ phydev->duplex = DUPLEX_FULL;
+ return;
+ }
+
+ linkmode_and(common, phydev->lp_advertising, phydev->advertising);
+
+ if (linkmode_test_bit(full, common)) {
+ phydev->duplex = DUPLEX_FULL;
+ } else if (linkmode_test_bit(half, common)) {
+ phydev->duplex = DUPLEX_HALF;
+ } else {
+ /* No partner abilities, i.e. parallel detection at 10/100M,
+ * which implies half duplex, unless the PHY lacks it.
+ */
+ phydev->duplex = phydev->speed != SPEED_1000 &&
+ linkmode_test_bit(half, phydev->supported) ?
+ DUPLEX_HALF : DUPLEX_FULL;
+ }
+}
+
static int as21xxx_read_status(struct phy_device *phydev)
{
- int bmcr, old_link = phydev->link;
+ int old_link = phydev->link;
int ret;
- ret = as21xxx_read_link(phydev, &bmcr);
+ ret = as21xxx_read_link(phydev);
if (ret)
return ret;
@@ -797,64 +889,54 @@ static int as21xxx_read_status(struct phy_device *phydev)
if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link)
return 0;
- phydev->speed = SPEED_UNKNOWN;
- phydev->duplex = DUPLEX_UNKNOWN;
phydev->pause = 0;
phydev->asym_pause = 0;
- if (phydev->autoneg == AUTONEG_ENABLE) {
- ret = genphy_c45_read_lpa(phydev);
+ if (phydev->autoneg == AUTONEG_DISABLE) {
+ ret = genphy_c45_read_pma(phydev);
if (ret)
return ret;
- ret = as21xxx_read_c22_lpa(phydev);
- if (ret)
- return ret;
+ if (phydev->link) {
+ ret = as21xxx_read_speed(phydev);
- phy_resolve_aneg_linkmode(phydev);
- } else {
- int speed;
-
- linkmode_zero(phydev->lp_advertising);
-
- speed = phy_read_mmd(phydev, MDIO_MMD_VEND1,
- VEND1_SPEED_STATUS);
- if (speed < 0)
- return speed;
-
- switch (speed & VEND1_SPEED_MASK) {
- case VEND1_SPEED_10000:
- phydev->speed = SPEED_10000;
- phydev->duplex = DUPLEX_FULL;
- break;
- case VEND1_SPEED_5000:
- phydev->speed = SPEED_5000;
- phydev->duplex = DUPLEX_FULL;
- break;
- case VEND1_SPEED_2500:
- phydev->speed = SPEED_2500;
- phydev->duplex = DUPLEX_FULL;
- break;
- case VEND1_SPEED_1000:
- phydev->speed = SPEED_1000;
- if (bmcr & BMCR_FULLDPLX)
- phydev->duplex = DUPLEX_FULL;
- else
- phydev->duplex = DUPLEX_HALF;
- break;
- case VEND1_SPEED_100:
- phydev->speed = SPEED_100;
- phydev->duplex = DUPLEX_FULL;
- break;
- case VEND1_SPEED_10:
- phydev->speed = SPEED_10;
- phydev->duplex = DUPLEX_FULL;
- break;
- default:
- return -EINVAL;
+ /* Hold the link down until the speed status settles */
+ if (!ret && phydev->speed == SPEED_UNKNOWN)
+ phydev->link = 0;
}
+
+ return ret;
}
+ phydev->speed = SPEED_UNKNOWN;
+ phydev->duplex = DUPLEX_UNKNOWN;
+ linkmode_zero(phydev->lp_advertising);
+
+ /* as21xxx_read_link() reports link up only once autoneg completed */
+ if (!phydev->link)
+ return 0;
+
+ /* The firmware advertises every speed up to the highest one in
+ * phydev->advertising, hence resolving the advertisements may not
+ * match the link. Take the speed from VEND1_SPEED_STATUS instead.
+ */
+ ret = as21xxx_read_speed(phydev);
+ if (ret)
+ return ret;
+
+ /* Hold the link down until the speed status settles */
+ if (phydev->speed == SPEED_UNKNOWN) {
+ phydev->link = 0;
+ return 0;
+ }
+
+ ret = as21xxx_read_lpa(phydev);
+ if (ret)
+ return ret;
+
+ as21xxx_resolve_duplex(phydev);
+ phy_resolve_aneg_pause(phydev);
+
return 0;
}
--
2.56.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* Re: [PATCH net 13/14] net: phy: as21xxx: Fix speed and duplex reporting
2026-11-30 0:55 ` [PATCH net 13/14] net: phy: as21xxx: Fix speed and duplex reporting Cristian Ciocaltea
@ 2026-11-30 3:50 ` Andrew Lunn
2026-11-30 12:21 ` Cristian Ciocaltea
0 siblings, 1 reply; 38+ messages in thread
From: Andrew Lunn @ 2026-11-30 3:50 UTC (permalink / raw)
To: Cristian Ciocaltea
Cc: Christian Marangi, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, kernel, netdev
On Mon, Nov 30, 2026 at 02:55:20AM +0200, Cristian Ciocaltea wrote:
> With autoneg enabled, as21xxx_read_status() derives the result purely in
> software via phy_resolve_aneg_linkmode(). That does not work reliably
> here: the advertisement is driven by the firmware over IPC, which
> ignores the Clause 45 AN registers phylib writes except for the maximum
> speed, and arbitrary subsets of speeds are not supported.
So the firmware is totally FUBAR?
So autoneg does not work, other than for a single link mode? This
suggests you are setting phydev->supported wrongly. It should have a
single link mode in it, the top speed the PHY supports.
phylib should then do the correct thing, it will only let the user
select that one link mode for advertisement.
Andrew
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: [PATCH net 13/14] net: phy: as21xxx: Fix speed and duplex reporting
2026-11-30 3:50 ` Andrew Lunn
@ 2026-11-30 12:21 ` Cristian Ciocaltea
2026-11-30 14:01 ` Andrew Lunn
0 siblings, 1 reply; 38+ messages in thread
From: Cristian Ciocaltea @ 2026-11-30 12:21 UTC (permalink / raw)
To: Andrew Lunn
Cc: Christian Marangi, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, kernel, netdev
On 11/30/26 5:50 AM, Andrew Lunn wrote:
> On Mon, Nov 30, 2026 at 02:55:20AM +0200, Cristian Ciocaltea wrote:
>> With autoneg enabled, as21xxx_read_status() derives the result purely in
>> software via phy_resolve_aneg_linkmode(). That does not work reliably
>> here: the advertisement is driven by the firmware over IPC, which
>> ignores the Clause 45 AN registers phylib writes except for the maximum
>> speed, and arbitrary subsets of speeds are not supported.
>
> So the firmware is totally FUBAR?
>
> So autoneg does not work, other than for a single link mode? This
> suggests you are setting phydev->supported wrongly. It should have a
> single link mode in it, the top speed the PHY supports.
>
> phylib should then do the correct thing, it will only let the user
> select that one link mode for advertisement.
As previously discussed, the root cause of all this unexpected behavior is the
firmware limitation: it cannot handle arbitrary subsets of speeds and always
advertises the full range, from the minimum supported speed up to the top one
(the only limit that can be enforced).
aeon$ ethtool -s eth1 autoneg on advertise 0x800000000000 # 2.5G
peer$ ethtool enp0s13f0u1
Link partner advertised link modes: 100baseT/Full
1000baseT/Full
2500baseT/Full
Thanks,
Cristian
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: [PATCH net 13/14] net: phy: as21xxx: Fix speed and duplex reporting
2026-11-30 12:21 ` Cristian Ciocaltea
@ 2026-11-30 14:01 ` Andrew Lunn
0 siblings, 0 replies; 38+ messages in thread
From: Andrew Lunn @ 2026-11-30 14:01 UTC (permalink / raw)
To: Cristian Ciocaltea
Cc: Christian Marangi, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, kernel, netdev
On Mon, Nov 30, 2026 at 02:21:12PM +0200, Cristian Ciocaltea wrote:
> On 11/30/26 5:50 AM, Andrew Lunn wrote:
> > On Mon, Nov 30, 2026 at 02:55:20AM +0200, Cristian Ciocaltea wrote:
> >> With autoneg enabled, as21xxx_read_status() derives the result purely in
> >> software via phy_resolve_aneg_linkmode(). That does not work reliably
> >> here: the advertisement is driven by the firmware over IPC, which
> >> ignores the Clause 45 AN registers phylib writes except for the maximum
> >> speed, and arbitrary subsets of speeds are not supported.
> >
> > So the firmware is totally FUBAR?
> >
> > So autoneg does not work, other than for a single link mode? This
> > suggests you are setting phydev->supported wrongly. It should have a
> > single link mode in it, the top speed the PHY supports.
> >
> > phylib should then do the correct thing, it will only let the user
> > select that one link mode for advertisement.
>
> As previously discussed, the root cause of all this unexpected behavior is the
> firmware limitation: it cannot handle arbitrary subsets of speeds and always
> advertises the full range, from the minimum supported speed up to the top one
> (the only limit that can be enforced).
>
> aeon$ ethtool -s eth1 autoneg on advertise 0x800000000000 # 2.5G
>
> peer$ ethtool enp0s13f0u1
> Link partner advertised link modes: 100baseT/Full
> 1000baseT/Full
> 2500baseT/Full
What happens if you return -EOPNOTSUPP here? Does it make it back to
userspace?
I don't think it is guaranteed to. This is probably the first PHY
which is broken like this, all other vendors are capable of reading
802.3. So we don't have support in phylib for this sort of brokenness.
Maybe add a new op to struct phy_device:
/**
* @validate_aneg: Validate that the PHY can actually advertise this valid
* combination of link modes.
* Return 0 if it can, -EOPNOTSUPP if the PHY is broken and cannot.
*/
int (validate_aneg)(struct phy_device *phydev, unsigned long *advertisement);
Call it in phy_ethtool_ksettings_set() when not NULL.
Andrew
^ permalink raw reply [flat|nested] 38+ messages in thread
* [PATCH net 14/14] net: phy: as21xxx: Release reset before reading ID in match
2026-11-30 0:55 [PATCH net 00/14] net: phy: as21xxx: Fix a batch of driver issues Cristian Ciocaltea
` (12 preceding siblings ...)
2026-11-30 0:55 ` [PATCH net 13/14] net: phy: as21xxx: Fix speed and duplex reporting Cristian Ciocaltea
@ 2026-11-30 0:55 ` Cristian Ciocaltea
2026-11-30 3:53 ` Andrew Lunn
13 siblings, 1 reply; 38+ messages in thread
From: Cristian Ciocaltea @ 2026-11-30 0:55 UTC (permalink / raw)
To: Christian Marangi, Andrew Lunn, Heiner Kallweit, Russell King,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: kernel, netdev
The Aeonsemi PHYs report a generic PHY ID until their firmware is
loaded, so the driver reads the ID from the hardware while matching
instead of relying on the ID cached at bus scan time.
The PHY only reports a valid ID while out of reset, which is not
guaranteed. phy_remove() asserts the reset and phy_probe() deasserts
it, but probing only happens once a driver has matched. Rebinding the
driver, for instance by reloading the module, therefore reads the ID of
a PHY held in reset. This fails to match, leaving the PHY in reset with
no driver bound, which cannot be recovered without a power cycle.
Deassert the reset before reading the ID. mdio_device_reset() keeps
track of the reset state, so this does nothing when the PHY has no reset
described or is already out of reset. Since the PHY comes out of reset
with its firmware unloaded, it reports the generic PHY ID again and the
existing firmware loading path handles it. If no driver matches, the
PHY is left out of reset, just as after phy_device_register().
Fixes: 830877d89edc ("net: phy: Add support for Aeonsemi AS21xxx PHYs")
Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
---
drivers/net/phy/as21xxx.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/net/phy/as21xxx.c b/drivers/net/phy/as21xxx.c
index 5eea6baa75bf..761458c606a2 100644
--- a/drivers/net/phy/as21xxx.c
+++ b/drivers/net/phy/as21xxx.c
@@ -1196,6 +1196,12 @@ static int as21xxx_match_phy_device(struct phy_device *phydev,
PHY_VENDOR_AEONSEMI))
return genphy_match_phy_device(phydev, phydrv);
+ /* phy_remove() leaves the PHY in reset and only phy_probe() releases
+ * it, so release it here to be able to read the ID on rebind. No-op
+ * if there is no reset or it is already released.
+ */
+ phy_device_reset(phydev, 0);
+
/* Read PHY ID to handle firmware loaded or HW reset */
ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MII_PHYSID1);
if (ret < 0)
--
2.56.0
^ permalink raw reply related [flat|nested] 38+ messages in thread* Re: [PATCH net 14/14] net: phy: as21xxx: Release reset before reading ID in match
2026-11-30 0:55 ` [PATCH net 14/14] net: phy: as21xxx: Release reset before reading ID in match Cristian Ciocaltea
@ 2026-11-30 3:53 ` Andrew Lunn
2026-11-30 12:22 ` Cristian Ciocaltea
0 siblings, 1 reply; 38+ messages in thread
From: Andrew Lunn @ 2026-11-30 3:53 UTC (permalink / raw)
To: Cristian Ciocaltea
Cc: Christian Marangi, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, kernel, netdev
On Mon, Nov 30, 2026 at 02:55:21AM +0200, Cristian Ciocaltea wrote:
> The Aeonsemi PHYs report a generic PHY ID until their firmware is
> loaded, so the driver reads the ID from the hardware while matching
> instead of relying on the ID cached at bus scan time.
>
> The PHY only reports a valid ID while out of reset, which is not
> guaranteed. phy_remove() asserts the reset and phy_probe() deasserts
> it, but probing only happens once a driver has matched. Rebinding the
> driver, for instance by reloading the module, therefore reads the ID of
> a PHY held in reset. This fails to match, leaving the PHY in reset with
> no driver bound, which cannot be recovered without a power cycle.
We don't do fun and games like this. We just require the compatible in
DT contains the ID, if the ID cannot be reliably read from the device.
Andrew
^ permalink raw reply [flat|nested] 38+ messages in thread
* Re: [PATCH net 14/14] net: phy: as21xxx: Release reset before reading ID in match
2026-11-30 3:53 ` Andrew Lunn
@ 2026-11-30 12:22 ` Cristian Ciocaltea
0 siblings, 0 replies; 38+ messages in thread
From: Cristian Ciocaltea @ 2026-11-30 12:22 UTC (permalink / raw)
To: Andrew Lunn
Cc: Christian Marangi, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, kernel, netdev
On 11/30/26 5:53 AM, Andrew Lunn wrote:
> On Mon, Nov 30, 2026 at 02:55:21AM +0200, Cristian Ciocaltea wrote:
>> The Aeonsemi PHYs report a generic PHY ID until their firmware is
>> loaded, so the driver reads the ID from the hardware while matching
>> instead of relying on the ID cached at bus scan time.
>>
>> The PHY only reports a valid ID while out of reset, which is not
>> guaranteed. phy_remove() asserts the reset and phy_probe() deasserts
>> it, but probing only happens once a driver has matched. Rebinding the
>> driver, for instance by reloading the module, therefore reads the ID of
>> a PHY held in reset. This fails to match, leaving the PHY in reset with
>> no driver bound, which cannot be recovered without a power cycle.
>
> We don't do fun and games like this. We just require the compatible in
> DT contains the ID, if the ID cannot be reliably read from the device.
Ack, will drop this patch.
Thanks,
Cristian
^ permalink raw reply [flat|nested] 38+ messages in thread