From nobody Thu Apr 16 08:52:53 2026 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2933B2DEA62 for ; Sat, 28 Feb 2026 23:23:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772320986; cv=none; b=V9+LdjFj+WeemGPvE/2JAR6AlJHrNDGK7g9RVPQUT0rVE3NfpfD9VvlHnxBo98kz23yhM9LteIz1cqI7FMAPTFaI2XgWAEJcUj3ARi2TZSsxEyKF4m+rAT06Gvh9lNk6tLFN7s5S/A134HKJxZNoxztvcps6wzjojer+uJv1vn0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772320986; c=relaxed/simple; bh=LO39Axnq6iF8iPb7VGpGZoLs2F2b7LqrK7p8ZPbk8gs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OOKHhrwWLNThRH5GYzP+y55LD1ksGFtRr8CQ+jJ6mWcU6tc/+oGGTcTRhrCY3Xb+kz6t1qrZySkw0N60VhSPXyTwKOJ6sAQsfEPl/0R8AFbWoL8TOTIX52c6yuQO0Mz99IUSKEacgvsXaVommVa6ZkCC3EMFYqfOVUEqVFSEehA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gb86NN1z; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gb86NN1z" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-483bd7354efso44766035e9.2 for ; Sat, 28 Feb 2026 15:23:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772320983; x=1772925783; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AvI9rfVkeg68adZAPqkcXmdhi9It9JA2cusW9CSADLE=; b=gb86NN1znZB3caC61tvZawVeL+gPO9PC+xx5AL7XZWT4dvt8/iUeKOoZzmi9Gf/Z1R oFLo9HNOx1atI80oHdRWej53qWkwQHS6kT6MJuwy8PC45dFPCMcCmvTekAXWqHBe8CSz Lv4BkRWpyjvmMAlDoxNTGkYjrEnszB3H54VL4Fy39nomyBIjK5CK+qY7RYaK5Cuxei0q lEBUbx2jaxSVV/HCS/3eTbIW8+WsT0/wQat5sz1wW4QCywR/kqcOlmLCcAd2bedOQG7B /1CP5jAwaZEp4OqGQPE89SueR5FYnNqAQtDf1yfiqyGPd9NmDlfK/IgiOQTvy49+WojV zEEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772320983; x=1772925783; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=AvI9rfVkeg68adZAPqkcXmdhi9It9JA2cusW9CSADLE=; b=nilkF5Kvb9Rz35eru1U8DjHqoGnRiDgmLoQn3N/K2YrIyQgW4xRDAtkLpoWkDV71Q1 6MbJU2dO4SCM3+DukXgnGF4OgtNmDnhyNXEVeZk/K53sGjJvyV23SbWshMCNODcHB/WY HhQqjTlAmpZZte/PENp2HopnM6safp8Uyr+LIEBjt3bU0dRJU4C0JuixIA2wZVCu38Bz gtl9Qm+YideRX70ZLA0HCYBTymCYpnMnmHSL/3zdsLkTmRX9ws8aPT+4f0Ubq4/VEy+e 38Qsn5wXJusI3l1KNbvFzsjB1JM5i/dfuKsuTkhrT0hiErxZcl0KGnmqzLp6JiYxoW8L aSsg== X-Gm-Message-State: AOJu0Yz2FLVi22hbTbS2NmhWZCQVgwel51a4yXWWbqpKSCxoLGQTNjzk KFYadJihLQ8iYIHXMYmtY9IxiS0r85xdFS5hy1zmsF+y/+PYqRims7IQmJQRBwwUqck= X-Gm-Gg: ATEYQzytLkOg8CVSHCc+nF12PaeBz/7oTjbJh5pj3Zq6FpD4fHUcChr3hrbCL932Atu RyjLVXOOseOnjqnxK8YAyPi4byCVGdtvnfpJKoMnsvgzvuSZpjIVjCjFvCCiuMYpDy3uxBLDcNw +SpyzVwKOTYPOHkRh/Hr6pVKbwT4q6JG8FVCL8AhrdBSgJVkzPHADDbtGPWgbWYThlz3CX5a7R9 +EDecm7c8qhThm1mdRPZ2SqQnQ5dMxgIO4ehI2hzHEVmT4E/uRlcUZ7yuAa3txFau/ZldD0o2Ud NbUGklFbj/rn1f04HdVJ9QDffq4LWONSw93YTHYovTO0htYceXujyKl562G1NDz+fY2TVl5NH67 FT50YFs9XHDrTmKNdDRQf7znNQUw6/wceQ9DrgtkRXmLJmDHrO/taO+J96b316BusOWAEYOD+9I ltV7OJR2tKYW6w0ABdrF2C/YV0D7tr9oDrcw7KmhBGlVMhq4KBS3lzZccnQxq69sqWkdbyIZ7LJ OXcKA1vE3QCesFtig== X-Received: by 2002:a05:600c:46d5:b0:483:5310:dc67 with SMTP id 5b1f17b1804b1-483c9bbbe77mr110176085e9.20.1772320983185; Sat, 28 Feb 2026 15:23:03 -0800 (PST) Received: from pc-kuba-l13.. (snat-2.cgn.sat-an.net. [176.222.226.2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4399c70ed47sm18515680f8f.11.2026.02.28.15.23.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Feb 2026 15:23:02 -0800 (PST) From: =?UTF-8?q?Jakub=20Van=C4=9Bk?= To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Frank , Sai Krishna , Daniel Golle , =?UTF-8?q?Jakub=20Van=C4=9Bk?= Subject: [PATCH net-next v2 1/5] net: mdiobus: Scan buses in reverse order (31 -> 0) Date: Sun, 1 Mar 2026 00:22:37 +0100 Message-ID: <20260228232241.1274236-2-linuxtardis@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260228232241.1274236-1-linuxtardis@gmail.com> References: <20260228232241.1274236-1-linuxtardis@gmail.com> 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 Some PHY devices incorrectly treat address 0 as a broadcast address. As a result, accesses to address 0 may cause multiple PHYs to respond, making one or both PHYs work unreliably. In other cases, the PHY may be detected twice by Linux: once at address 0 and once at its actual address). On several PHYs (e.g. Motorcomm YT8821 and Realtek RTL8221B), this behavior can be disabled via a vendor-specific internal register. However, for that to be useful, that register would have to be programmed before address 0 is accessed for the first time. On non-Device Tree systems, MDIO buses are typically scanned in mdiobus_register(). Change the address scan order from 0->31 to 31->0 so that PHY fixups are applied to addresses 1-31 before address 0 is probed. This way the address collision can be avoided. The change is implemented separately for Clause 22 and Clause 45 PHYs. This approach might still leave some collisions at address 0 unhandled, but it is much easier to implement. Device Tree-based systems also require a different approach. In that case, of_mdiobus_register() probes only the addresses explicitly described in the Device Tree. Handling for DT-based systems is implemented in a separate commit. Suggested-by: Daniel Golle Signed-off-by: Jakub Van=C4=9Bk --- drivers/net/phy/mdio_bus_provider.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/net/phy/mdio_bus_provider.c b/drivers/net/phy/mdio_bus= _provider.c index 4b0637405740..d3454d229795 100644 --- a/drivers/net/phy/mdio_bus_provider.c +++ b/drivers/net/phy/mdio_bus_provider.c @@ -208,7 +208,12 @@ static int mdiobus_scan_bus_c22(struct mii_bus *bus) { int i; =20 - for (i =3D 0; i < PHY_MAX_ADDR; i++) { + /* Scan address 0 last. Some vendors consider it a broadcast address + * and so their PHYs respond at it in addition to the actual PHY address. + * Scanning addresses 1-31 first allows PHY fixups to reconfigure these + * PHYs to not respond at address 0 before we try to scan it. + */ + for (i =3D PHY_MAX_ADDR - 1; i >=3D 0; i--) { if ((bus->phy_mask & BIT(i)) =3D=3D 0) { struct phy_device *phydev; =20 @@ -224,7 +229,12 @@ static int mdiobus_scan_bus_c45(struct mii_bus *bus) { int i; =20 - for (i =3D 0; i < PHY_MAX_ADDR; i++) { + /* Scan address 0 last. Some vendors consider it a broadcast address + * and so their PHYs respond at it in addition to the actual PHY address. + * Scanning addresses 1-31 first allows PHY fixups to reconfigure these + * PHYs to not respond at address 0 before we try to scan it. + */ + for (i =3D PHY_MAX_ADDR - 1; i >=3D 0; i--) { if ((bus->phy_mask & BIT(i)) =3D=3D 0) { struct phy_device *phydev; =20 --=20 2.43.0 From nobody Thu Apr 16 08:52:53 2026 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F33D36C5AF for ; Sat, 28 Feb 2026 23:23:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772320988; cv=none; b=SdRnYRCqqIJ+05po1NqmYUPHZ53sjVCUMaxbByudF8IpRff2RdQWOQYIeoqzrLuwxvMkSijE1P80zvRZwzUWZTDOjW3NEyG5rIMH0Rmi9AXhyKf/2adZ39hF4GUlSEGdl8E9OjaYNG+cJPXuzNNOculTMgNVd6e2nKKNRclKHtQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772320988; c=relaxed/simple; bh=Z7bSopnXsEHjGorY9KUB86YcxCDj7BOcmMab+g55N+A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SkviB/G5c9AfA8Z9ZoI8BX2i2ETDA+/g5ynRxBkkIytQQN/21RNTMRUyLMihpOTEQ05y6ARDi92HBRmNs1bPTOTI17/c1KIRhSdhMfna1B3/nsUDa5ZzZehLPBopoVcUk92J+t/6aVHH+dNY17WhT8g6vTQpduTZJMV+Imk8CQk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=X9gPO857; arc=none smtp.client-ip=209.85.221.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="X9gPO857" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-439afc58ac7so270529f8f.0 for ; Sat, 28 Feb 2026 15:23:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772320985; x=1772925785; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4QSUk/O1YaQrNE2KB+afVPAquqS3lddYamh9fKT5kIM=; b=X9gPO857/hi5d+5tezTW5vF70BBEdE22awFROw26FKPEhcVO4yJ1tnjyLWzK0zOtGw krcxbXc38/Sb0QBkkaBrn4mJl7A7s3M+Wn5AJrvm8UBXvhNfwkiWAfQAPGjeiLwwxpPg ymbfqfIPJAVGbNb22COoDhUFJGpQBKOY0ud3cZdhRD3iYYoJdVhA2SrgUq6TbM4Kn+Gj oL85xaZlQfINRu0xXZ4XGaO7bCxjb887isfc/HY0exeF/GaJtvDYXA01+ieutv7QRAir nrEANNzruNgpBXx6oZO7VlfLZ8LuzBBynD7g4NNNqsdnun2zExSBeJxP2Jj0cMH6qObR ZhIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772320985; x=1772925785; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=4QSUk/O1YaQrNE2KB+afVPAquqS3lddYamh9fKT5kIM=; b=JLl/0NTB6dPcwMFSrMi0m3fwRzWNTjLt6O0bPpYJRq8WWGL9ju+eIHDAuIw94FFyn2 7aRdXoL34/pxhxAKfX0eusPLMfsgv7zlXEzeFd3/v5DaLmjXh2jSB6KaLC5W1iB7E0yQ xUvsoCdgTvytfyhUrHTFXaFP+wFG0ECz3Dhpn0+PnvNS37VKsWlwd16ItDqh6h5JmkG3 L4gF895VSIxfp+FMSCvPPO/IGSlWq8QxXHthhO7r1cP7xc7B9bYKsX9rgvOjEfXEEjYM sh+DAZQ72+yrKlLJMBJ0Xzt0fuLIrvaVhoUtKwBWijXiUIyL9unfwzr6rE1ljVJQlPTy hURw== X-Gm-Message-State: AOJu0YxXxl5qfsCUxMeDRdEl0HZX7YbP1Mc0s4rpi4kG2GyO9TNjbPhy PGZ7ICpHGtZnulzqpmakz4kWyDqKe9lNkeQfPL9QlcW1tsRF39kT/+0+3cWvJdTpHvY= X-Gm-Gg: ATEYQzzJgQN2DaXzUoQdeq64bMOvZbU9JDlOlel5CPee19ozJ+yD1mmd9f52Vwr9wNO cpqCFmG7PoGG0c8eGJN9QRHaPXkqCuNkLUuh0i/IZfLJkmS3LPmWThhzHz+OlmZ74JeiEZ+/wok 38j3RwxocBc/Y7Z67LBgBRSYlbMiWNpFhjBS5vLB2wLpIOq8yP2ZJR78v3lzXjVg/9za3AoJ+So 1ltgfOI5preGYhJ2dulKNggI+CRJkhupN+RDJ+gMxCKOn57ooRMYY4tLSjs5UDbEFEM4jsZlSMQ aEkcvuL+emAo7ofGbkr1qGM5/1jxlMJFicw5/FXj3LipKlXAs9WvBxpT6CLUs9viCoOFYb0oCzz r6eu8f0IgyCDW4M3ZjTxPtMs/tWWlBVB5x7PaUUB35jOfujl5gME4jrqAnt3uKoX9q+Sr1WLNn4 28UJvvtw9X3F/pG5GpAmThZ+jtitqCO4HNKultyotIutZVFsFtGAy+ySpI5HbGu2lcXVQ7PEEWi Xwi8as= X-Received: by 2002:a5d:5d81:0:b0:439:872f:b495 with SMTP id ffacd0b85a97d-4399de4a779mr11175104f8f.42.1772320984427; Sat, 28 Feb 2026 15:23:04 -0800 (PST) Received: from pc-kuba-l13.. (snat-2.cgn.sat-an.net. [176.222.226.2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4399c70ed47sm18515680f8f.11.2026.02.28.15.23.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Feb 2026 15:23:04 -0800 (PST) From: =?UTF-8?q?Jakub=20Van=C4=9Bk?= To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Frank , Sai Krishna , Daniel Golle , =?UTF-8?q?Jakub=20Van=C4=9Bk?= Subject: [PATCH net-next v2 2/5] of: mdio: Scan PHY address 0 last Date: Sun, 1 Mar 2026 00:22:38 +0100 Message-ID: <20260228232241.1274236-3-linuxtardis@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260228232241.1274236-1-linuxtardis@gmail.com> References: <20260228232241.1274236-1-linuxtardis@gmail.com> 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 Some PHY devices incorrectly treat address 0 as a broadcast address. As a result, accesses to address 0 may cause multiple PHYs to respond, making one or both PHYs work unreliably. On several PHYs (e.g. Motorcomm YT8821 and Realtek RTL8221B), this behavior can be disabled via a vendor-specific internal register. However, for that to be useful, that register would have to be programmed before address 0 is accessed for the first time. Device Tree-based systems scan MDIO buses via of_mdiobus_register(). Modify the scanning order so that address 0 is scanned last. This ensures PHY fixups for addresses 1-31 are applied before address 0 is accessed, allowing the collision to be prevented. However, preserve the original probing order for one edge case: when the Device Tree does not explicitly specify PHY addresses. In that scenario, PHY DT nodes appear to be matched to devices based on a sequential bus scan. Changing the scanning sequence could change the association between DT nodes and PHY devices and potentially break existing setups. For example, with: mdio-bus { phy0: ethernet-phy { compatible =3D "ethernet-phy-id1234.5678"; }; phy1: ethernet-phy { compatible =3D "ethernet-phy-id90AB.CDEF"; }; }; scanning address 0 last could cause the PHY on address 0 to be associated with the phy1 node. Suggested-by: Daniel Golle Signed-off-by: Jakub Van=C4=9Bk --- drivers/net/mdio/of_mdio.c | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/drivers/net/mdio/of_mdio.c b/drivers/net/mdio/of_mdio.c index b8d298c04d3f..a705991f6b04 100644 --- a/drivers/net/mdio/of_mdio.c +++ b/drivers/net/mdio/of_mdio.c @@ -27,6 +27,11 @@ MODULE_AUTHOR("Grant Likely "= ); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("OpenFirmware MDIO bus (Ethernet PHY) accessors"); =20 +enum scan_phase { + SCAN_PHASE_NOT_PHYAD_0, + SCAN_PHASE_PHYAD_0, +}; + /* Extract the clause 22 phy ID from the compatible string of the form * ethernet-phy-idAAAA.BBBB */ static int of_get_phy_id(struct device_node *device, u32 *phy_id) @@ -137,7 +142,7 @@ bool of_mdiobus_child_is_phy(struct device_node *child) EXPORT_SYMBOL(of_mdiobus_child_is_phy); =20 static int __of_mdiobus_parse_phys(struct mii_bus *mdio, struct device_nod= e *np, - bool *scanphys) + bool *scanphys, enum scan_phase phase) { struct device_node *child; int addr, rc =3D 0; @@ -149,7 +154,7 @@ static int __of_mdiobus_parse_phys(struct mii_bus *mdio= , struct device_node *np, if (!of_property_present(child, "reg")) continue; =20 - rc =3D __of_mdiobus_parse_phys(mdio, child, NULL); + rc =3D __of_mdiobus_parse_phys(mdio, child, NULL, phase); if (rc && rc !=3D -ENODEV) goto exit; =20 @@ -164,6 +169,12 @@ static int __of_mdiobus_parse_phys(struct mii_bus *mdi= o, struct device_node *np, continue; } =20 + if (phase =3D=3D SCAN_PHASE_NOT_PHYAD_0 && addr =3D=3D 0) + continue; + + if (phase =3D=3D SCAN_PHASE_PHYAD_0 && addr !=3D 0) + continue; + if (of_mdiobus_child_is_phy(child)) rc =3D of_mdiobus_register_phy(mdio, child, addr); else @@ -223,8 +234,19 @@ int __of_mdiobus_register(struct mii_bus *mdio, struct= device_node *np, if (rc) return rc; =20 - /* Loop over the child nodes and register a phy_device for each phy */ - rc =3D __of_mdiobus_parse_phys(mdio, np, &scanphys); + /* Loop over the child nodes and register a phy_device for each phy. + * However, scan address 0 last. Some vendors consider it a broadcast + * address and so their PHYs respond at it in addition to the actual PHY + * address. Scanning addresses 1-31 first allows PHY fixups to stop + * the potential collision at address 0 from occurring. + */ + rc =3D __of_mdiobus_parse_phys(mdio, np, &scanphys, + SCAN_PHASE_NOT_PHYAD_0); + if (rc) + goto unregister; + + rc =3D __of_mdiobus_parse_phys(mdio, np, &scanphys, + SCAN_PHASE_PHYAD_0); if (rc) goto unregister; =20 @@ -238,6 +260,11 @@ int __of_mdiobus_register(struct mii_bus *mdio, struct= device_node *np, of_node_name_eq(child, "ethernet-phy-package")) continue; =20 + /* Skip the SCAN_PHASE_NOT_PHYAD_0/SCAN_PHASE_PHYAD_0 + * stuff here. Some device tree setups may assume linear + * assignment from address 0 onwards and the two-pass probing + * is not worth breaking these setups. + */ for (addr =3D 0; addr < PHY_MAX_ADDR; addr++) { /* skip already registered PHYs */ if (mdiobus_is_registered_device(mdio, addr)) --=20 2.43.0 From nobody Thu Apr 16 08:52:53 2026 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C97983BFE47 for ; Sat, 28 Feb 2026 23:23:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772320989; cv=none; b=aYt+qRssheKONzZJdTVSvTDD91eoFiKvQyqSYRA0wfxoF9JFNIe4zAt9elonAHxaDvN+JVDzEn6qrCHYypsY6q5AlbWxqreLHCrJvpZjHkL3kU3Mmz++jl4JWJ7VTaBTLjALwz/rv90rnI0QrH+lGk8+caziFqF5VNu/A6Y+OP4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772320989; c=relaxed/simple; bh=6MGxm/fgJ5bkzDB43ONDayAw+9QBpNWDaDqUHZZveWM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IE3zjHkJxVGMoK6xwWxfALnxSF9Z9/7lkprSOtGv2rVPf2WKsvgGzqTcSeMzdODtiYbdOQ0oDKjT4D7lnw7XF2e2ouCbLsy3Bvq5A+VsHfLFHZX7oYTTulw/aqDiq89Da7gF8w3kJfhbZpUaXQe7cO5d1/rC53aILN16GFqUIvU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=P6drrikf; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="P6drrikf" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-48371bb515eso47827785e9.1 for ; Sat, 28 Feb 2026 15:23:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772320986; x=1772925786; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=x8gi44qcEURz8IdVWGsHR4vcJOzvUGKuaF1I7xr8jDI=; b=P6drrikfmhkAwMxlW9MakD6X8AX2vpYEmOABfFjcSNZtTArdBDi4mPSS1fqrzacsqp 0aTe6bFrhIoP0Y4/tdYqG+mEOO/YTGpxF5z2XlACw9F4eLlvYglvYU7CwGYvmzYHe3+Y p78T6WU4J2lWwn2wcQJAkWnmSv52jcsrQ1nDaqzTwoq29iRebQjQOs0lPpZhYM42Vznf ga+7kLuy1ooE+hp6yd2kh405PXRlhmeH/8tJrEupU9wTX6DYjo8adgU5Nx6+ldDyCjGg AOyxgJuSt//OWYD0gLmShuOhcpNtzW+LFyCSB2e++Pnc4g4hMStXkmLKsuLpG5wVGlLT WQ6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772320986; x=1772925786; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=x8gi44qcEURz8IdVWGsHR4vcJOzvUGKuaF1I7xr8jDI=; b=dfwCx6ZY8l6j+CjUSPPdyfnKCCekpPp+xRwd28GdyOMACC/ZtJtt/cuTwB8Ej9ALgr Y0WuLy0LCMzTt+8O+t1tHJTn352M3L9GL6SHQFofoJGlhPotmoeTclRUpvT+A6Xutfbj KH4RlEc/phqT/cPG1y4/371AE1FigrJK1m+zbu9FUbCDY+iLiuECVzYCyX2U+nZySSE2 p5clrBw40i1HxTKs+FondyCOZ5xsz5uX12E4VSdjhmAQL1OmfORWzzSD0smhwqturudE V3RyY4Dh7Y6wsYJ6eVceFvqwX0gBNiZuXlcAiOGmj8kKalF2/CW//eWvVd76h+Wcjioz cRGQ== X-Gm-Message-State: AOJu0YwgLkUBe6X3vM7bbOL4kCrqZb0LzsoQfBpbYE4lV0MEaDOuJMBb pe8G667RFpOZkesiOawfhUHOQ5pZixqJ2j8ohrurTWXO4TrsrGiTNtC6VzjGz4ef6rE= X-Gm-Gg: ATEYQzxQAvuxR2RnSmaqIkFZLExsw6yvAEJiY+lXJGK0wkyYYmOs0zKSI+berE2J1o/ Km8bsyiBBOUClqbG2EIoTZuua0JlRq+deh/TsqFYkz5oxySrVhM89ShgvDpAcEc/q3wvAVNh4K9 5ARJjyAB1Omldn8CaYYBn/KWfEM5DdsaBG3A/35SuV/bTIMJKE2AoW0on/0wAaxCApmw6dq6S1r QVQcQnxpPUTEJw0AYCmp8N/O/G+176wm3cfzJ5OQfhkO1kl4ynecDRhQg0ofTsfArw37mdNhler EHUp4Vms4Fm/L1htbG/j65nH0pAjEbM5k2dJuvDBCrWHYZl5WTNCUGNR8hXISo7jmYAMFUTNjzC UJvPv8oCTOLYCCyvqle8osLDLPSWlP40tibq/STPgS7Js7OyUKqLvAul9MXUJe4Uu3K+LC6paoW LwxIoHP0zQS18UvLXDlI6OB02vCyJn4Yn8/MunY2ejRioGeuYnd5dkiqXa7EHnWFvnKgjMLkYj1 IMJNCQ= X-Received: by 2002:a05:600c:8106:b0:483:afbb:a064 with SMTP id 5b1f17b1804b1-483c9bb7b7emr126969785e9.1.1772320985811; Sat, 28 Feb 2026 15:23:05 -0800 (PST) Received: from pc-kuba-l13.. (snat-2.cgn.sat-an.net. [176.222.226.2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4399c70ed47sm18515680f8f.11.2026.02.28.15.23.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Feb 2026 15:23:05 -0800 (PST) From: =?UTF-8?q?Jakub=20Van=C4=9Bk?= To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Frank , Sai Krishna , Daniel Golle , =?UTF-8?q?Jakub=20Van=C4=9Bk?= Subject: [PATCH net-next v2 3/5] net: phy: Support PHY fixups on Clause 45 PHYs Date: Sun, 1 Mar 2026 00:22:39 +0100 Message-ID: <20260228232241.1274236-4-linuxtardis@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260228232241.1274236-1-linuxtardis@gmail.com> References: <20260228232241.1274236-1-linuxtardis@gmail.com> 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 For Clause 45 PHYs, phydev->phy_id is zero and therefore cannot be used to match PHY fixups. Clause 45 PHYs instead have per-MMD identifiers stored in phydev->c45_ids. Extend phy_needs_fixup() to match against these IDs by reusing the relevant matching logic from genphy_match_phy_device(). Signed-off-by: Jakub Van=C4=9Bk --- drivers/net/phy/phy_device.c | 56 ++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 02fc0133428d..db187d370eaa 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -472,13 +472,48 @@ int phy_register_fixup_for_id(const char *bus_id, } EXPORT_SYMBOL(phy_register_fixup_for_id); =20 +/** + * genphy_check_device_id - match a PHY device against a given ID + * @phydev: target phy_device struct + * @phy_id: expected PHY ID + * @phy_id_mask: the PHY ID mask, set bits are significant in matching + * + * Description: Checks whether the given PHY device matches the specified + * ID. For Clause 45 PHYs, iterates over the available device identifiers + * and compares them against the expected PHY ID, applying the provided ma= sk. + * For Clause 22 PHYs, a direct ID comparison is performed. + * + * Return: true if the PHY device matches the masked ID, false otherwise. + */ +static bool genphy_check_device_id(struct phy_device *phydev, + u32 phy_id, u32 phy_id_mask) +{ + if (phydev->is_c45) { + const int num_ids =3D ARRAY_SIZE(phydev->c45_ids.device_ids); + int i; + + for (i =3D 1; i < num_ids; i++) { + if (phydev->c45_ids.device_ids[i] =3D=3D 0xffffffff) + continue; + + if (phy_id_compare(phydev->c45_ids.device_ids[i], + phy_id, phy_id_mask)) + return true; + } + + return false; + } + + return phy_id_compare(phydev->phy_id, phy_id, phy_id_mask); +} + static bool phy_needs_fixup(struct phy_device *phydev, struct phy_fixup *f= ixup) { if (!strcmp(fixup->bus_id, phydev_name(phydev))) return true; =20 if (fixup->phy_uid_mask && - phy_id_compare(phydev->phy_id, fixup->phy_uid, fixup->phy_uid_mask)) + genphy_check_device_id(phydev, fixup->phy_uid, fixup->phy_uid_mask)) return true; =20 return false; @@ -522,24 +557,7 @@ static int phy_scan_fixups(struct phy_device *phydev) int genphy_match_phy_device(struct phy_device *phydev, const struct phy_driver *phydrv) { - if (phydev->is_c45) { - const int num_ids =3D ARRAY_SIZE(phydev->c45_ids.device_ids); - int i; - - for (i =3D 1; i < num_ids; i++) { - if (phydev->c45_ids.device_ids[i] =3D=3D 0xffffffff) - continue; - - if (phy_id_compare(phydev->c45_ids.device_ids[i], - phydrv->phy_id, phydrv->phy_id_mask)) - return 1; - } - - return 0; - } - - return phy_id_compare(phydev->phy_id, phydrv->phy_id, - phydrv->phy_id_mask); + return genphy_check_device_id(phydev, phydrv->phy_id, phydrv->phy_id_mask= ); } EXPORT_SYMBOL_GPL(genphy_match_phy_device); =20 --=20 2.43.0 From nobody Thu Apr 16 08:52:53 2026 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C6BC3E0C5E for ; Sat, 28 Feb 2026 23:23:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772320990; cv=none; b=Sy+2aVTEut2QzntU1rEk0qhiyWZ3142aDY+fVPRF8hnFYxwx624hxQzrwxDiLyAAflqEdJljDY5wPvOE7u59I/UfMk5N0+lWBPAk1Hlq9nqAK4nJGuMslEQ3QTjhIYE3/qP5vlUOW3bb1IZfKqxnkI6HU3YRQLMYE9vnf9hyBHE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772320990; c=relaxed/simple; bh=VLHiua2iLbiZ7Hk6ZHDZpitnvizx9Nykr+jwd3W0HG4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tcjSDwImoO4eyL1a2XI5lC8pBNCv3sjFugry+oozTld1pl6GAPv9iNkbyaBn0sDahbLzdHX0TNxxx5NeeufpjpHqLNjCS+7VnGzQonqZAqT1OpNkI9X+ZvENRmRFhbRo7wb/nEOaVdc4ZjKj0svAoKqjux+rNc2B3Kr4s8p2iEs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=SCbiGF9U; arc=none smtp.client-ip=209.85.221.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SCbiGF9U" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-439ac15f35fso490991f8f.0 for ; Sat, 28 Feb 2026 15:23:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772320987; x=1772925787; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TtSinzVGJkzPvF9jByekTq6nORuTGb+Z3JsuJnZZQ7c=; b=SCbiGF9UIEOLCF+7xUb01le0+fKVUf/0ywWyTDAGn2Zi0JErN6Qfw0AnblUTXOT5hC p68qGrZcttEWOf1dQvpUzxchOfIpIczkBts0gJQ4KE0DMHgRbEYoI63D2mwHdLp3dUsN 4gZ2pooOhnIvPfy6S9Z/rnojfx9aH3pdogLZ/XydaotNGo8jw6bS2KpCXSH8He8Rfgcj Y3+qOiYtLAgqUUUC3fxgx3ZgZJk8AGYkM+c5pAJI0Gr3wT5LQYQIgW3itAVte6GiYIJd mchAPuwsDAbrsbfzgSkYwrHrxFljjUozdu7Jh723epdYEocQ6AONZxspMNKiSq4w33eW iJ3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772320987; x=1772925787; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=TtSinzVGJkzPvF9jByekTq6nORuTGb+Z3JsuJnZZQ7c=; b=E6AxVDMlctmB6eZa/5kwZPdFtHVm7DGsIUITGHJXbwVWGgOqwW+UWaCMmF2bv/4EEd QTOZzvmb6bw4kmw+vTpVKg5a1yaacXR0fWO1WHluDhlqnHMJL9SEdoszEvI0I1MBLmn5 cRHnUMl4W1poH5Lg+gN89pao37/4a8HrSUpC3eOiiLdlAkdyCOdMt05pbTj9VDBRWAXY 2OXJGtuxEqtuRTyvF2tR5HWSUV/yhCIGq0XqtLU21sJLFPYxs+2vwf48pHDfaAdX9S9C 0S6eUBxfTCNAGulSkNyfaeAQgVD1i7fKQnaHnl4tRurUi5mKDio9cKijUySNbhzxHy/j n83Q== X-Gm-Message-State: AOJu0YxOgORo1eqLtnX9qnU4IV+9cRnbxVXJ+7TRLi1GWiRTi5bNugDC qE+kf/itm/hLfD1F/vFsAr26+WObs+u80qQ5Elli0RIMkS6njETm1CJ/H7lvNlQobdA= X-Gm-Gg: ATEYQzwLJMzQarR40tskVMhNNFimfk+iRZC7rdeyQFEZK12zlSpvq2/7QbtiOm/yol9 UcZLDsDVSQOQEotpCJ/75vZSHX0wf0pLjBQX4t6pfO/HvDifbKee7/CTWfr7yz7NdmMv8Vee4i3 TL9mPMyfwICxIMY88xT4Adk98jHIkgtL4MlAoLCSwHembs8sDEbkh1s9e+PTXH1uM96j4S4p02b umQ7u1ms7p4VMVwtFGfl61lQfJuYux90qco6VnfSvgD8kuvBQpnnxcKWpblFwd881HRevA+oFZY HvXa9rT7dg+hBmnt8ds6LLOOLQBpvinj30U6ndbJG4wbeoMAFknwSqkMj/Fh/d7gAsmOo0t+BRF SJecS7RQ0MQdSqhhZeL3Dw4secoKozRVNKqiuQDEv6peEKR+rY1nwxfKvm+AEWq1/sWOhAGV1h3 6zZ360lX6etB8AUQ9Q1j/PaWO+88qvIhNxb724RL+pvEMoUNPjvWaFxzFC9ZY/Z2Cd5FprPks/R ypj/C4= X-Received: by 2002:a05:6000:2007:b0:437:6625:d0d7 with SMTP id ffacd0b85a97d-4399de3694fmr12066071f8f.42.1772320987140; Sat, 28 Feb 2026 15:23:07 -0800 (PST) Received: from pc-kuba-l13.. (snat-2.cgn.sat-an.net. [176.222.226.2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4399c70ed47sm18515680f8f.11.2026.02.28.15.23.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Feb 2026 15:23:06 -0800 (PST) From: =?UTF-8?q?Jakub=20Van=C4=9Bk?= To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Frank , Sai Krishna , Daniel Golle , =?UTF-8?q?Jakub=20Van=C4=9Bk?= Subject: [PATCH net-next v2 4/5] net: phy: Add infrastructure for PHY address 0 fixups Date: Sun, 1 Mar 2026 00:22:40 +0100 Message-ID: <20260228232241.1274236-5-linuxtardis@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260228232241.1274236-1-linuxtardis@gmail.com> References: <20260228232241.1274236-1-linuxtardis@gmail.com> 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 Certain PHYs incorrectly treat MDIO address 0 as a broadcast address and therefore respond both at address 0 and at their assigned address. As outlined in the code, this is problematic. Provide a way to disable this behaviour via a PHY fixup. It would be ideal to have these collisions prevented early by the bootloader, but there may be hardware (e.g. WiFi routers) out there where the bootloader doesn't do this and cannot be easily replaced. Signed-off-by: Jakub Van=C4=9Bk --- drivers/net/phy/Makefile | 3 ++- drivers/net/phy/phy_common_fixups.c | 26 ++++++++++++++++++++++++++ drivers/net/phy/phy_device.c | 4 ++++ drivers/net/phy/phylib-internal.h | 2 ++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 drivers/net/phy/phy_common_fixups.c diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile index 3a34917adea7..3bf9ba208b90 100644 --- a/drivers/net/phy/Makefile +++ b/drivers/net/phy/Makefile @@ -3,7 +3,8 @@ =20 libphy-y :=3D phy.o phy-c45.o phy-core.o phy_device.o \ linkmode.o phy_link_topology.o \ - phy_caps.o mdio_bus_provider.o phy_port.o + phy_caps.o mdio_bus_provider.o phy_port.o \ + phy_common_fixups.o mdio-bus-y +=3D mdio_bus.o mdio_device.o =20 ifdef CONFIG_PHYLIB diff --git a/drivers/net/phy/phy_common_fixups.c b/drivers/net/phy/phy_comm= on_fixups.c new file mode 100644 index 000000000000..fa51c6d7b25f --- /dev/null +++ b/drivers/net/phy/phy_common_fixups.c @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include + +#include "phylib-internal.h" + +/** + * phy_register_address_0_fixups - Register fixups for disabling MDIO + * broadcast address 0 + * + * Some vendors interpret MDIO address 0 as a broadcast address and so the= ir + * PHYs initially respond both at address 0 as well as at their normal + * address. This is problematic: + * - Linux may create two struct phy_device for a single device. + * - MDIO address collision may occur if there is another PHY + * legitimately listening on address 0. + * + * The broadcast address can often be disabled through some internal + * PHY register. These fixups are designed to do just that -- + * they shall stop these PHYs from responding at address 0 before + * the MDIO address 0 is scanned for devices. + */ +int phy_register_address_0_fixups(void) +{ + return 0; +} diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index db187d370eaa..2d4f119b45b4 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -3969,6 +3969,10 @@ static int __init phy_init(void) if (rc) goto err_ethtool_phy_ops; =20 + rc =3D phy_register_address_0_fixups(); + if (rc) + goto err_ethtool_phy_ops; + features_init(); =20 rc =3D phy_driver_register(&genphy_c45_driver, THIS_MODULE); diff --git a/drivers/net/phy/phylib-internal.h b/drivers/net/phy/phylib-int= ernal.h index dc9592c6bb8e..1e6ff8f2d721 100644 --- a/drivers/net/phy/phylib-internal.h +++ b/drivers/net/phy/phylib-internal.h @@ -22,4 +22,6 @@ void phy_check_downshift(struct phy_device *phydev); =20 int genphy_c45_read_eee_adv(struct phy_device *phydev, unsigned long *adv); =20 +int phy_register_address_0_fixups(void); + #endif /* __PHYLIB_INTERNAL_H */ --=20 2.43.0 From nobody Thu Apr 16 08:52:53 2026 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73AFD2C21C1 for ; Sat, 28 Feb 2026 23:23:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772320991; cv=none; b=gUBNTtjrQQgFunU2J48KuEKM3H8BI/M1DxcjZ70BA2HTSYCLFwFi3DUQql5RZPiLmmAKTf81BU/SZ8CxX6khhewMwcMMx2uSjA8m1Pugtergom2uk4mA47R573uWggxS7qdFUzVFFZh26GrNLR1E8c/rQtFKZ0h+1GBDusgJllU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772320991; c=relaxed/simple; bh=/E00kd06ARqV1EiG6J7bbJMQs/AdElwvl+AD4goyHi8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZYlGxVvgILkJzlIptiU2WKW7mryUGbj7oAaJSJvt55/5J+xiD6Gz26Myg8IGGG89fTK99eR4ryIQPpDb3NZk08HQ9fIyT2sdpbw2fQhmQ93FLcHpLT5ShMeyLKqSnC11GY7+DoUxUwY9viwZ1ktULD/bKyjbhyrMGTtMGXVmL3w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HMhisKHN; arc=none smtp.client-ip=209.85.221.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HMhisKHN" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-4398f8403edso2579416f8f.1 for ; Sat, 28 Feb 2026 15:23:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772320989; x=1772925789; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=R7E353CUJwnGyuCmm4n5uTZxUZWsHiLJYSS1cugMXcw=; b=HMhisKHNsCap3F38Px4IfUG4LXbhDM37+U5jdmOJ5TCuMNZ6KyEG5VdNuZl9Szztah 4i8N+iaPOimo263DldltdsyDv7iAfEEIGnbDHrd/Z5NqcZEGZGlB8NlYbIV+uBwdBTx+ 8CMd2MtMxwGnkl9jFzUPbIrCjeQ23Pozf8CKUDxLM+9jzolPZ82QEquWa/ts63NpXuyX d/VfDrFRe3+ARFLC3dN3K7cjO2+9BNRjxbf13+YX2/sM1fZjV6G3+RaO9hRDhSvaf0cS q0j3yebzt5VEkQW2CCzZddRW9TA66qurEaCkjx4XesCULjRmUUnhgOLCYNiX1ZFIVu/+ mFDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772320989; x=1772925789; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=R7E353CUJwnGyuCmm4n5uTZxUZWsHiLJYSS1cugMXcw=; b=rGWLE71VfKb0Sen8agwG70IDa8vPwXxoqYG4qRmlbUTbMbyQWhrCuXqLEjt2bMS7+/ m6u8BJs9dU9d57qCTUq+kgIQAEHRSFtvR+MaFpYaEPN7g3rsBDp04e6bVJpal4iwyztB kORSAye69GVbxjvajmNLnj0buj1qxrgcmGgIYh/9ZIdRc1uLbTDRIkvGwLSibUoVaZi9 ljb/jKEiLFCG5P2U1RHmnH4HH0LBgcb1a2nXBUPxmaWkueX8cDBljHygBWqYkfVnoWRT ZAMqq3mounWrfeIQcv5uxWlAaWYiwrFCq2fddcOlFALkcrhCuVpLjyDdAL2tQeERuoG0 IpRg== X-Gm-Message-State: AOJu0Yzc0YEj3B6VYoibRY1iSsPW6LKMdD+1jk8dGQKzjKcsuDCYYduW LLP8qfdQ4uTqLgY/5fZb4b/J2ZafV81M0pY1tcP1Qy2Zn+qIKNBR1SmGzq5QBmgFnSM= X-Gm-Gg: ATEYQzy19NQrlPGjIet5KvQO6GYd/vEfYDr4AxVhf8sL6EM15RFtRcNiczwGxEtF2dk CLMMLxzWRTkyQ+4qWXlgQb0hahR1Op0V5Q8tr+RWUM8ko+idHgoHUqenC/SCwR2kGmpHDSPe0iA FiYatKHNRYtGmbDMrxwZMvhLVP0wixNBzZdgxqJD7UrNu8C8IlseEt5i8n2Esrj7RScLbHi6KJA Y0zpyChaHttXa/DSRf1RlqGuVivxO+gxixoDTtUzbfIzdPB3f74s5TmqR4sESh5iyDLqdD6IbNw DMNRu2THeuJWItypSIj/tUjjnuv/Gt8PvsLV1jeQtqX3xwSgl5R+PaiR8tXR/tvPGutocgISz4/ fLk+2EYbxFKdEeN4lwxJs4h9VVIi8j1kXGLX+9UZ0UgRcCue973vSm9FnSIkwv5k0MJxGH1300K zJcrCpit2mhvz6BB8E8/xGPulvwRRGprF09MtbaF32emRw3+qFQwGr3tO1Khd1mW0j4FSWRMlD2 LDA5lM= X-Received: by 2002:a05:6000:2903:b0:439:9312:4b72 with SMTP id ffacd0b85a97d-4399de20ad6mr12654417f8f.30.1772320988508; Sat, 28 Feb 2026 15:23:08 -0800 (PST) Received: from pc-kuba-l13.. (snat-2.cgn.sat-an.net. [176.222.226.2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4399c70ed47sm18515680f8f.11.2026.02.28.15.23.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Feb 2026 15:23:08 -0800 (PST) From: =?UTF-8?q?Jakub=20Van=C4=9Bk?= To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Frank , Sai Krishna , Daniel Golle , =?UTF-8?q?Jakub=20Van=C4=9Bk?= Subject: [PATCH net-next v2 5/5] net: phy: motorcomm: yt8821: Disable MDIO broadcast Date: Sun, 1 Mar 2026 00:22:41 +0100 Message-ID: <20260228232241.1274236-6-linuxtardis@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260228232241.1274236-1-linuxtardis@gmail.com> References: <20260228232241.1274236-1-linuxtardis@gmail.com> 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 By default, the YT8821 responds at two MDIO addresses: the address selected by its strapping pins and the broadcast address 0. This causes problems if another PHY is legitimately configured at address 0. Disable the broadcast address using two mechanisms. The PHY fixup prevents collisions during initial MDIO bus scanning. yt8821_config_init() then re-disables the broadcast address if the PHY goes through a hardware reset (this happens if the PHY has a reset GPIO on its device tree node, and the interface is brought down and up). Link: https://github.com/openwrt/openwrt/pull/21584 Fixes: b671105b88c3 ("net: phy: Add driver for Motorcomm yt8821 2.5G ethern= et phy") Signed-off-by: Jakub Van=C4=9Bk --- drivers/net/phy/motorcomm.c | 29 +++++++++++++++++++++++++ drivers/net/phy/phy_common_fixups.c | 33 +++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c index 4d62f7b36212..e1503fab568a 100644 --- a/drivers/net/phy/motorcomm.c +++ b/drivers/net/phy/motorcomm.c @@ -227,6 +227,9 @@ #define YT8521_LED_100_ON_EN BIT(5) #define YT8521_LED_10_ON_EN BIT(4) =20 +#define YTPHY_MDIO_ADDRESS_CONTROL_REG 0xA005 +#define YTPHY_MACR_EN_PHY_ADDR_0 BIT(6) + #define YTPHY_MISC_CONFIG_REG 0xA006 #define YTPHY_MCR_FIBER_SPEED_MASK BIT(0) #define YTPHY_MCR_FIBER_1000BX (0x1 << 0) @@ -2764,6 +2767,28 @@ static int yt8821_soft_reset(struct phy_device *phyd= ev) YT8521_CCR_SW_RST, 0); } =20 +/** + * yt8821_disable_mdio_address_zero() - disable MDIO broadcast address 0 + * @phydev: a pointer to a &struct phy_device + * + * The YT8821 responds on two MDIO addresses by default: + * - the address selected by its strapping pins + * - the broadcast address 0 + * + * Some other PHYs (e.g. the MT7981B internal Gigabit PHY) are hardwired to + * respond only at MDIO address 0. If the YT8821 also listens on address 0, + * it may incorrectly react to transactions intended for those PHYs. + * + * Returns: 0 or negative errno code + */ +static int yt8821_disable_mdio_address_zero(struct phy_device *phydev) +{ + return ytphy_modify_ext_with_lock(phydev, + YTPHY_MDIO_ADDRESS_CONTROL_REG, + YTPHY_MACR_EN_PHY_ADDR_0, + 0); +} + /** * yt8821_config_init() - phy initializatioin * @phydev: a pointer to a &struct phy_device @@ -2799,6 +2824,10 @@ static int yt8821_config_init(struct phy_device *phy= dev) phydev->rate_matching =3D RATE_MATCH_PAUSE; } =20 + ret =3D yt8821_disable_mdio_address_zero(phydev); + if (ret < 0) + return ret; + ret =3D yt8821_serdes_init(phydev); if (ret < 0) return ret; diff --git a/drivers/net/phy/phy_common_fixups.c b/drivers/net/phy/phy_comm= on_fixups.c index fa51c6d7b25f..5a60721b56d6 100644 --- a/drivers/net/phy/phy_common_fixups.c +++ b/drivers/net/phy/phy_common_fixups.c @@ -4,6 +4,32 @@ =20 #include "phylib-internal.h" =20 +#define PHY_ID_YT8821 0x4f51ea19 +#define YTPHY_PAGE_SELECT 0x1E +#define YTPHY_PAGE_DATA 0x1F +#define YTPHY_MDIO_ADDRESS_CONTROL_REG 0xA005 +#define YTPHY_MACR_EN_PHY_ADDR_0 BIT(6) + +/** + * yt8821_disable_broadcast - Disable MDIO broadcast on address 0 + */ +static int yt8821_disable_broadcast(struct phy_device *phydev) +{ + int rc =3D 0; + + phy_lock_mdio_bus(phydev); + + rc =3D __phy_write(phydev, YTPHY_PAGE_SELECT, YTPHY_MDIO_ADDRESS_CONTROL_= REG); + if (rc < 0) + goto unlock; + + rc =3D __phy_modify(phydev, YTPHY_PAGE_DATA, YTPHY_MACR_EN_PHY_ADDR_0, 0); + +unlock: + phy_unlock_mdio_bus(phydev); + return rc; +} + /** * phy_register_address_0_fixups - Register fixups for disabling MDIO * broadcast address 0 @@ -22,5 +48,12 @@ */ int phy_register_address_0_fixups(void) { + int rc; + + rc =3D phy_register_fixup_for_uid(PHY_ID_YT8821, 0xFFFFFFFF, + yt8821_disable_broadcast); + if (rc < 0) + return rc; + return 0; } --=20 2.43.0