Skip to content

Commit eb7fd7a

Browse files
QSchulzPaolo Abeni
authored andcommitted
net: stmmac: platform: guarantee uniqueness of bus_id
bus_id is currently derived from the ethernetX alias. If one is missing for the device, 0 is used. If ethernet0 points to another stmmac device or if there are 2+ stmmac devices without an ethernet alias, then bus_id will be 0 for all of those. This is an issue because the bus_id is used to generate the mdio bus id (new_bus->id in drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c stmmac_mdio_register) and this needs to be unique. This allows to avoid needing to define ethernet aliases for devices with multiple stmmac controllers (such as the Rockchip RK3588) for multiple stmmac devices to probe properly. Obviously, the bus_id isn't guaranteed to be stable across reboots if no alias is set for the device but that is easily fixed by simply adding an alias if this is desired. Fixes: 25c83b5 ("dt:net:stmmac: Add support to dwmac version 3.610 and 3.710") Signed-off-by: Quentin Schulz <quentin.schulz@cherry.de> Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com> Link: https://patch.msgid.link/20250527-stmmac-mdio-bus_id-v2-1-a5ca78454e3c@cherry.de Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 271683b commit eb7fd7a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
430430
struct device_node *np = pdev->dev.of_node;
431431
struct plat_stmmacenet_data *plat;
432432
struct stmmac_dma_cfg *dma_cfg;
433+
static int bus_id = -ENODEV;
433434
int phy_mode;
434435
void *ret;
435436
int rc;
@@ -465,8 +466,14 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
465466
of_property_read_u32(np, "max-speed", &plat->max_speed);
466467

467468
plat->bus_id = of_alias_get_id(np, "ethernet");
468-
if (plat->bus_id < 0)
469-
plat->bus_id = 0;
469+
if (plat->bus_id < 0) {
470+
if (bus_id < 0)
471+
bus_id = of_alias_get_highest_id("ethernet");
472+
/* No ethernet alias found, init at -1 so first bus_id is 0 */
473+
if (bus_id < 0)
474+
bus_id = -1;
475+
plat->bus_id = ++bus_id;
476+
}
470477

471478
/* Default to phy auto-detection */
472479
plat->phy_addr = -1;

0 commit comments

Comments
 (0)