[PATCH] net: dsa: qca8k: fix led devicename when using external mdio bus

George Moussalem via B4 Relay posted 1 patch 9 months, 2 weeks ago
There is a newer version of this series
drivers/net/dsa/qca/qca8k-leds.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH] net: dsa: qca8k: fix led devicename when using external mdio bus
Posted by George Moussalem via B4 Relay 9 months, 2 weeks ago
From: George Moussalem <george.moussalem@outlook.com>

The qca8k dsa switch can use either an external or internal mdio bus.
This depends on whether the mdio node is defined under the switch node
itself and, as such, the internal_mdio_mask is populated with its
internal phys. Upon registering the internal mdio bus, the slave_mii_bus
of the dsa switch is assigned to this bus. When an external mdio bus is
used, it is left unassigned, though its id is used to create the device
names of the leds.
This leads to the leds being named '(efault):00:green:lan' and so on as
the slave_mii_bus is null. So let's fix this by adding a null check and
use the devicename of the external bus instead when an external bus is
configured.

Signed-off-by: George Moussalem <george.moussalem@outlook.com>
---
Fix the led device names when an external mdio is configured.
The current codepath for registering led device names 'assumes' that the
internal mdio bus is used. Therefore, add a check and fallback to the
device name of the external mdio bus while creating the led device
names.

Wrong device names:
root@OpenWrt:~# ls -l /sys/class/leds                                           
lrwxrwxrwx    1 root     root             0 Jan  1  1970 (efault):00:green:lan -> ../../devices/platform/soc@0/90000.mdio/mdio_bus/90000.mdio-1/90000.n
lrwxrwxrwx    1 root     root             0 Jan  1  1970 (efault):01:green:lan -> ../../devices/platform/soc@0/90000.mdio/mdio_bus/90000.mdio-1/90000.n
lrwxrwxrwx    1 root     root             0 Jan  1  1970 (efault):02:green:lan -> ../../devices/platform/soc@0/90000.mdio/mdio_bus/90000.mdio-1/90000.n

Correct device names:
root@OpenWrt:~# ls -l /sys/class/leds                                                                                                                      
lrwxrwxrwx    1 root     root             0 Jan  1  1970 90000.mdio-1:00:green:lan -> ../../devices/platform/soc@0/90000.mdio/mdio_bus/90000.mdio-1/90000.n
lrwxrwxrwx    1 root     root             0 Jan  1  1970 90000.mdio-1:01:green:lan -> ../../devices/platform/soc@0/90000.mdio/mdio_bus/90000.mdio-1/90000.n
lrwxrwxrwx    1 root     root             0 Jan  1  1970 90000.mdio-1:02:green:lan -> ../../devices/platform/soc@0/90000.mdio/mdio_bus/90000.mdio-1/90000.n
---
 drivers/net/dsa/qca/qca8k-leds.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/dsa/qca/qca8k-leds.c b/drivers/net/dsa/qca/qca8k-leds.c
index 43ac68052baf9f9926aaf4a9d8d09640f9022fcd..abe5beae330ef316113a8f1931671b0191b54218 100644
--- a/drivers/net/dsa/qca/qca8k-leds.c
+++ b/drivers/net/dsa/qca/qca8k-leds.c
@@ -429,7 +429,8 @@ qca8k_parse_port_leds(struct qca8k_priv *priv, struct fwnode_handle *port, int p
 		init_data.fwnode = led;
 		init_data.devname_mandatory = true;
 		init_data.devicename = kasprintf(GFP_KERNEL, "%s:0%d",
-						 priv->internal_mdio_bus->id,
+						 ds->slave_mii_bus ?
+						 ds->slave_mii_bus->id : dev_name(&priv->bus->dev),
 						 port_num);
 		if (!init_data.devicename) {
 			fwnode_handle_put(led);

---
base-commit: 02ddfb981de88a2c15621115dd7be2431252c568
change-id: 20250425-qca8k-leds-35e31b9a319f

Best regards,
-- 
George Moussalem <george.moussalem@outlook.com>
Re: [PATCH] net: dsa: qca8k: fix led devicename when using external mdio bus
Posted by Jakub Kicinski 9 months, 2 weeks ago
On Fri, 25 Apr 2025 10:49:55 +0400 George Moussalem via B4 Relay wrote:
> From: George Moussalem <george.moussalem@outlook.com>
> 
> The qca8k dsa switch can use either an external or internal mdio bus.
> This depends on whether the mdio node is defined under the switch node
> itself and, as such, the internal_mdio_mask is populated with its
> internal phys. Upon registering the internal mdio bus, the slave_mii_bus
> of the dsa switch is assigned to this bus. When an external mdio bus is
> used, it is left unassigned, though its id is used to create the device
> names of the leds.
> This leads to the leds being named '(efault):00:green:lan' and so on as
> the slave_mii_bus is null. So let's fix this by adding a null check and
> use the devicename of the external bus instead when an external bus is
> configured.

Hi Andrew, would you mind taking a quick look?
Re: [PATCH] net: dsa: qca8k: fix led devicename when using external mdio bus
Posted by Andrew Lunn 9 months, 2 weeks ago
On Tue, Apr 29, 2025 at 11:41:28AM -0700, Jakub Kicinski wrote:
> On Fri, 25 Apr 2025 10:49:55 +0400 George Moussalem via B4 Relay wrote:
> > From: George Moussalem <george.moussalem@outlook.com>
> > 
> > The qca8k dsa switch can use either an external or internal mdio bus.
> > This depends on whether the mdio node is defined under the switch node
> > itself and, as such, the internal_mdio_mask is populated with its
> > internal phys. Upon registering the internal mdio bus, the slave_mii_bus
> > of the dsa switch is assigned to this bus. When an external mdio bus is
> > used, it is left unassigned, though its id is used to create the device
> > names of the leds.
> > This leads to the leds being named '(efault):00:green:lan' and so on as
> > the slave_mii_bus is null. So let's fix this by adding a null check and
> > use the devicename of the external bus instead when an external bus is
> > configured.
> 
> Hi Andrew, would you mind taking a quick look?

There is a somewhat ongoing discussion which could affect this:

https://patchwork.kernel.org/project/netdevbpf/patch/20250425151309.30493-1-kabel@kernel.org/

It could well be there is no internal and external MDIO bus, its just
one bus with two bus masters. LED names are somewhere ABI, so i think
we need to resolve the other thread first.

	Andrew