From nobody Sun Dec 14 19:30:16 2025 Received: from smtp-bc08.mail.infomaniak.ch (smtp-bc08.mail.infomaniak.ch [45.157.188.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B6299252900 for ; Tue, 27 May 2025 11:56:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.157.188.8 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748347011; cv=none; b=IEw0BCd+aZ5q6KH9nAfNj+gkylBrR++ZdvpVrEJia2Nwq1H3g3BHktipcH8k7mAYlUIQ+xElcShv3KW3QaX1Oj3LVchhUGr35F6ydDhNaf6t3Fq8aJiFX8wKPkVlipoRpUHTRVoEpMGzwLgvxinOKZu6bi1jlh3Ijm8qN0Mo2rE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748347011; c=relaxed/simple; bh=xIO6hrqs+VZXl85J+lCqT5C+UwY6Zhg2KGVoBNq4/2I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=JWKHWUnSw0Un74ooUIIjPZZu+M3q32r/R2avqY+CoLCQtdbVAlwCUGBV5GytI1hFSRBExeRYC6rpa+FC7Oz89WnHWKsAAtS69LlpTe0B73SjkZP+yrRFwvbc30Rt4Kdx+edCmVFK50QD8RsoejAx6sH9MCtDAagv/pyvBrJIwHA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=0leil.net; spf=pass smtp.mailfrom=0leil.net; arc=none smtp.client-ip=45.157.188.8 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=0leil.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=0leil.net Received: from smtp-3-0000.mail.infomaniak.ch (smtp-3-0000.mail.infomaniak.ch [10.4.36.107]) by smtp-3-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4b6B1p536tzjYD; Tue, 27 May 2025 13:56:46 +0200 (CEST) Received: from unknown by smtp-3-0000.mail.infomaniak.ch (Postfix) with ESMTPA id 4b6B1m5HnLzfFg; Tue, 27 May 2025 13:56:44 +0200 (CEST) From: Quentin Schulz Date: Tue, 27 May 2025 13:56:23 +0200 Subject: [PATCH net v2] net: stmmac: platform: guarantee uniqueness of bus_id Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250527-stmmac-mdio-bus_id-v2-1-a5ca78454e3c@cherry.de> X-B4-Tracking: v=1; b=H4sIAGaoNWgC/32NQQ6CMBBFr0Jm7RimlSCuvIchprSDnUXBtJVIC He34QAu3//572+QOAonuFUbRF4kyTwVUKcKrDfTi1FcYVC1aupGEaYcgrEYnMw4fNJTHGrSQ3u xbdtpDWX4jjzK95A+YOIMfQm9pDzH9Tha6Kj+ORdCwo6uRluiYVT2bj3HuJ4dQ7/v+w+TF1Rru QAAAA== X-Change-ID: 20250521-stmmac-mdio-bus_id-313b74c77933 To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , Alexandre Torgue Cc: Jakob Unterwurzacher , Heiko Stuebner , netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Quentin Schulz X-Mailer: b4 0.14.2 X-Infomaniak-Routing: alpha From: Quentin Schulz 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: 25c83b5c2e82 ("dt:net:stmmac: Add support to dwmac version 3.610 and= 3.710") Signed-off-by: Quentin Schulz Reviewed-by: Maxime Chevallier --- Unsure if I should cc stable since people who encountered that issue for sure had to add an ethernet alias to make things work with their DT so shouldn't be too much of an actual issue? Based on Paolo's feedback, have a Fixes tag regardless of the answer to the above question. --- Changes in v2: - added Fixes tag, - Link to v1: https://lore.kernel.org/r/20250521-stmmac-mdio-bus_id-v1-1-91= 8a3c11bf2c@cherry.de --- drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/driver= s/net/ethernet/stmicro/stmmac/stmmac_platform.c index c73eff6a56b87a3783c91b2ffbf5807a27df303f..15205a47cafc276442c3759a36d= 115d8da1fe51d 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c @@ -430,6 +430,7 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8= *mac) struct device_node *np =3D pdev->dev.of_node; struct plat_stmmacenet_data *plat; struct stmmac_dma_cfg *dma_cfg; + static int bus_id =3D -ENODEV; int phy_mode; void *ret; int rc; @@ -465,8 +466,14 @@ stmmac_probe_config_dt(struct platform_device *pdev, u= 8 *mac) of_property_read_u32(np, "max-speed", &plat->max_speed); =20 plat->bus_id =3D of_alias_get_id(np, "ethernet"); - if (plat->bus_id < 0) - plat->bus_id =3D 0; + if (plat->bus_id < 0) { + if (bus_id < 0) + bus_id =3D of_alias_get_highest_id("ethernet"); + /* No ethernet alias found, init at -1 so first bus_id is 0 */ + if (bus_id < 0) + bus_id =3D -1; + plat->bus_id =3D ++bus_id; + } =20 /* Default to phy auto-detection */ plat->phy_addr =3D -1; --- base-commit: 4a95bc121ccdaee04c4d72f84dbfa6b880a514b6 change-id: 20250521-stmmac-mdio-bus_id-313b74c77933 Best regards, --=20 Quentin Schulz