From mboxrd@z Thu Jan 1 00:00:00 1970 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: 8bit 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 = "ethernet-phy-id1234.5678"; }; phy1: ethernet-phy { compatible = "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ěk --- 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"); +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); static int __of_mdiobus_parse_phys(struct mii_bus *mdio, struct device_node *np, - bool *scanphys) + bool *scanphys, enum scan_phase phase) { struct device_node *child; int addr, rc = 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; - rc = __of_mdiobus_parse_phys(mdio, child, NULL); + rc = __of_mdiobus_parse_phys(mdio, child, NULL, phase); if (rc && rc != -ENODEV) goto exit; @@ -164,6 +169,12 @@ static int __of_mdiobus_parse_phys(struct mii_bus *mdio, struct device_node *np, continue; } + if (phase == SCAN_PHASE_NOT_PHYAD_0 && addr == 0) + continue; + + if (phase == SCAN_PHASE_PHYAD_0 && addr != 0) + continue; + if (of_mdiobus_child_is_phy(child)) rc = 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; - /* Loop over the child nodes and register a phy_device for each phy */ - rc = __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 = __of_mdiobus_parse_phys(mdio, np, &scanphys, + SCAN_PHASE_NOT_PHYAD_0); + if (rc) + goto unregister; + + rc = __of_mdiobus_parse_phys(mdio, np, &scanphys, + SCAN_PHASE_PHYAD_0); if (rc) goto unregister; @@ -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; + /* 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 = 0; addr < PHY_MAX_ADDR; addr++) { /* skip already registered PHYs */ if (mdiobus_is_registered_device(mdio, addr)) -- 2.43.0