From patchwork Wed Jan 18 10:01:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 45168 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2267645wrn; Wed, 18 Jan 2023 02:57:26 -0800 (PST) X-Google-Smtp-Source: AMrXdXvAmO+Hzp+OLDnUtcnnl1NNdHmLjJM4AlnUq6g1QcR7nLE7SXk2QwfPXWUsh+h96PJHPaNC X-Received: by 2002:a17:907:7f12:b0:7c1:9eb:845b with SMTP id qf18-20020a1709077f1200b007c109eb845bmr25070700ejc.16.1674039446320; Wed, 18 Jan 2023 02:57:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674039446; cv=none; d=google.com; s=arc-20160816; b=wZnz84Zb9Yl4k7MTQM6Rcw/0Nzw+w9dUFS0VdfxH4S9KhRpmRS6wEiMIKdeXsyBGBr JvI0uQy22SAl+gWimT76vRZR52RF/K4k3ysaDGr5jaVE6tTKGMGXUlxD8vEJPBh8uKz8 2NKpKAeRWzzDrEPDv9dl8lnUTy4L49M40G/O9vnu74hZOxdpLspvfjLRaFGx+Y8Iykg1 J1LEssk3+JfJ4gjJb3A+9lSymDFGKC9Muu1I/to01uaIHhus6+ytR8BT3cVaqTKsmda7 kMQ2jORUwPlLdR6zVODI7LQlmZhBFaaFX2uFN2ZO/Pv0B+UZP2t+MZVIZRXYVlphT2wa wgjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=5sGIMeo0xOf+3HRghClVH+PZ/YqsQ1nE+ZFy+ze4Ous=; b=Hv1ug4GlbwzyqZ8WwGHat7Y5hN5J08YPsodSFzx++X/c6oWbCj5K7WdSJ0+FtST4DP kK4fnz5cMANAxPLKL5qIN3EgtxsuA7UdHcHSG5UpzzQLg9ykPYWcRaRDhZAN6kXcBs9N xfyzghQVfPJWe7sRR64tMyRDPCIOB6Pxx/9fYK1zlFtgKuvTDwjb/W2BcOQXAq6WrSRI Vqm1gYT0XyzNhSuvoVJTGrmBkX4/8nHp4r4H4kTZgS1JCVVUMsN2O9eeQl5peJveh+Xb r0vOuEPzutENvqTDUXeolJ4Zk42kGIHX6o/c45IQqPhjCx096Cl9QOMan/QHLtDQ/631 joSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=NHUX7muh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=walle.cc Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id wt10-20020a170906ee8a00b007c4fb4ee06bsi39696645ejb.534.2023.01.18.02.57.02; Wed, 18 Jan 2023 02:57:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=NHUX7muh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=walle.cc Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230096AbjARK4Z (ORCPT + 99 others); Wed, 18 Jan 2023 05:56:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229998AbjARKxB (ORCPT ); Wed, 18 Jan 2023 05:53:01 -0500 Received: from mail.3ffe.de (0001.3ffe.de [159.69.201.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABADA86EF4; Wed, 18 Jan 2023 02:01:47 -0800 (PST) Received: from mwalle01.sab.local (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.3ffe.de (Postfix) with ESMTPSA id 2C9B91670; Wed, 18 Jan 2023 11:01:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1674036105; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5sGIMeo0xOf+3HRghClVH+PZ/YqsQ1nE+ZFy+ze4Ous=; b=NHUX7muhruWGH3lnBOr/S/uqJpQ+U4zAk0U/A2nUwtxZLpL0RBfibHeDxRw5e4aOxxUbaD ya4muCRnd7Qu8R6EFopsvjujS/YdUdBgnZ0tnHqOwJCw9JcOMy4z3FtmH2468mjwN0agCf rEbaTvNKyxHEULtle3rEqhPxjH3Ool1Y11EUiJU4wlfX66sx9tKtKRm7a0zunpNLv9/B/H ueF1cQy679mgce3HqSBI6T5peevtcxc5KhX7JlcC0zgQ5wyJYTikR9hNKhPH8mFPLOdjth LJGAUxVuGg8AX6A8skIK3qhwxOgrAS8x/biP8JqsHA7NN36fOSzrnJcwOx7dXQ== From: Michael Walle Date: Wed, 18 Jan 2023 11:01:36 +0100 Subject: [PATCH net-next v2 2/6] net: mdio: Rework scanning of bus ready for quirks MIME-Version: 1.0 Message-Id: <20230116-net-next-remove-probe-capabilities-v2-2-15513b05e1f4@walle.cc> References: <20230116-net-next-remove-probe-capabilities-v2-0-15513b05e1f4@walle.cc> In-Reply-To: <20230116-net-next-remove-probe-capabilities-v2-0-15513b05e1f4@walle.cc> To: Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Felix Fietkau , John Crispin , Sean Wang , Mark Lee , Lorenzo Bianconi , Matthias Brugger , Bryan Whitehead , UNGLinuxDriver@microchip.com, Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , Maxime Coquelin , Joel Stanley , Andrew Jeffery Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-aspeed@lists.ozlabs.org, Andrew Lunn , Michael Walle , Jesse Brandeburg X-Mailer: b4 0.11.1 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755357586569784920?= X-GMAIL-MSGID: =?utf-8?q?1755357586569784920?= From: Andrew Lunn Some C22 PHYs do bad things when there are C45 transactions on the bus. In order to handle this, the bus needs to be scanned first for C22 at all addresses, and then C45 scanned for all addresses. The Marvell pxa168 driver scans a specific address on the bus to find its PHY. This is a C22 only device, so update it to use the c22 helper. Signed-off-by: Andrew Lunn Signed-off-by: Michael Walle Reviewed-by: Jesse Brandeburg --- v2: [mw] Avoid the use of unitialized variabe. Thanks Jakub. Just iterate over all possible addresses in the error path. --- drivers/net/ethernet/marvell/pxa168_eth.c | 2 +- drivers/net/phy/mdio_bus.c | 125 ++++++++++++++++++++---------- include/linux/phy.h | 2 +- 3 files changed, 88 insertions(+), 41 deletions(-) diff --git a/drivers/net/ethernet/marvell/pxa168_eth.c b/drivers/net/ethernet/marvell/pxa168_eth.c index cf456d62677f..87fff539d39d 100644 --- a/drivers/net/ethernet/marvell/pxa168_eth.c +++ b/drivers/net/ethernet/marvell/pxa168_eth.c @@ -965,7 +965,7 @@ static int pxa168_init_phy(struct net_device *dev) if (dev->phydev) return 0; - phy = mdiobus_scan(pep->smi_bus, pep->phy_addr); + phy = mdiobus_scan_c22(pep->smi_bus, pep->phy_addr); if (IS_ERR(phy)) return PTR_ERR(phy); diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index 61c33c6098a1..667247f661c5 100644 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c @@ -506,38 +506,12 @@ static int mdiobus_create_device(struct mii_bus *bus, return ret; } -/** - * mdiobus_scan - scan a bus for MDIO devices. - * @bus: mii_bus to scan - * @addr: address on bus to scan - * - * This function scans the MDIO bus, looking for devices which can be - * identified using a vendor/product ID in registers 2 and 3. Not all - * MDIO devices have such registers, but PHY devices typically - * do. Hence this function assumes anything found is a PHY, or can be - * treated as a PHY. Other MDIO devices, such as switches, will - * probably not be found during the scan. - */ -struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr) +static struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr, bool c45) { struct phy_device *phydev = ERR_PTR(-ENODEV); int err; - switch (bus->probe_capabilities) { - case MDIOBUS_NO_CAP: - case MDIOBUS_C22: - phydev = get_phy_device(bus, addr, false); - break; - case MDIOBUS_C45: - phydev = get_phy_device(bus, addr, true); - break; - case MDIOBUS_C22_C45: - phydev = get_phy_device(bus, addr, false); - if (IS_ERR(phydev)) - phydev = get_phy_device(bus, addr, true); - break; - } - + phydev = get_phy_device(bus, addr, c45); if (IS_ERR(phydev)) return phydev; @@ -554,7 +528,77 @@ struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr) return phydev; } -EXPORT_SYMBOL(mdiobus_scan); + +/** + * mdiobus_scan_c22 - scan one address on a bus for C22 MDIO devices. + * @bus: mii_bus to scan + * @addr: address on bus to scan + * + * This function scans one address on the MDIO bus, looking for + * devices which can be identified using a vendor/product ID in + * registers 2 and 3. Not all MDIO devices have such registers, but + * PHY devices typically do. Hence this function assumes anything + * found is a PHY, or can be treated as a PHY. Other MDIO devices, + * such as switches, will probably not be found during the scan. + */ +struct phy_device *mdiobus_scan_c22(struct mii_bus *bus, int addr) +{ + return mdiobus_scan(bus, addr, false); +} +EXPORT_SYMBOL(mdiobus_scan_c22); + +/** + * mdiobus_scan_c45 - scan one address on a bus for C45 MDIO devices. + * @bus: mii_bus to scan + * @addr: address on bus to scan + * + * This function scans one address on the MDIO bus, looking for + * devices which can be identified using a vendor/product ID in + * registers 2 and 3. Not all MDIO devices have such registers, but + * PHY devices typically do. Hence this function assumes anything + * found is a PHY, or can be treated as a PHY. Other MDIO devices, + * such as switches, will probably not be found during the scan. + */ +static struct phy_device *mdiobus_scan_c45(struct mii_bus *bus, int addr) +{ + return mdiobus_scan(bus, addr, true); +} + +static int mdiobus_scan_bus_c22(struct mii_bus *bus) +{ + int i; + + for (i = 0; i < PHY_MAX_ADDR; i++) { + if ((bus->phy_mask & BIT(i)) == 0) { + struct phy_device *phydev; + + phydev = mdiobus_scan_c22(bus, i); + if (IS_ERR(phydev) && (PTR_ERR(phydev) != -ENODEV)) + return PTR_ERR(phydev); + } + } + return 0; +} + +static int mdiobus_scan_bus_c45(struct mii_bus *bus) +{ + int i; + + for (i = 0; i < PHY_MAX_ADDR; i++) { + if ((bus->phy_mask & BIT(i)) == 0) { + struct phy_device *phydev; + + /* Don't scan C45 if we already have a C22 device */ + if (bus->mdio_map[i]) + continue; + + phydev = mdiobus_scan_c45(bus, i); + if (IS_ERR(phydev) && (PTR_ERR(phydev) != -ENODEV)) + return PTR_ERR(phydev); + } + } + return 0; +} /** * __mdiobus_register - bring up all the PHYs on a given bus and attach them to bus @@ -639,16 +683,19 @@ int __mdiobus_register(struct mii_bus *bus, struct module *owner) goto error_reset_gpiod; } - for (i = 0; i < PHY_MAX_ADDR; i++) { - if ((bus->phy_mask & BIT(i)) == 0) { - struct phy_device *phydev; + if (bus->probe_capabilities == MDIOBUS_NO_CAP || + bus->probe_capabilities == MDIOBUS_C22 || + bus->probe_capabilities == MDIOBUS_C22_C45) { + err = mdiobus_scan_bus_c22(bus); + if (err) + goto error; + } - phydev = mdiobus_scan(bus, i); - if (IS_ERR(phydev) && (PTR_ERR(phydev) != -ENODEV)) { - err = PTR_ERR(phydev); - goto error; - } - } + if (bus->probe_capabilities == MDIOBUS_C45 || + bus->probe_capabilities == MDIOBUS_C22_C45) { + err = mdiobus_scan_bus_c45(bus); + if (err) + goto error; } mdiobus_setup_mdiodev_from_board_info(bus, mdiobus_create_device); @@ -658,7 +705,7 @@ int __mdiobus_register(struct mii_bus *bus, struct module *owner) return 0; error: - while (--i >= 0) { + for (i = 0; i < PHY_MAX_ADDR; i++) { mdiodev = bus->mdio_map[i]; if (!mdiodev) continue; diff --git a/include/linux/phy.h b/include/linux/phy.h index b3cf1e08e880..fceaac0fb319 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -464,7 +464,7 @@ static inline struct mii_bus *devm_mdiobus_alloc(struct device *dev) } struct mii_bus *mdio_find_bus(const char *mdio_name); -struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr); +struct phy_device *mdiobus_scan_c22(struct mii_bus *bus, int addr); #define PHY_INTERRUPT_DISABLED false #define PHY_INTERRUPT_ENABLED true