From nobody Sat Sep 21 06:51:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57902C63797 for ; Mon, 16 Jan 2023 12:57:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231352AbjAPM5W (ORCPT ); Mon, 16 Jan 2023 07:57:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230469AbjAPM4s (ORCPT ); Mon, 16 Jan 2023 07:56:48 -0500 Received: from mail.3ffe.de (0001.3ffe.de [159.69.201.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2B441F91D; Mon, 16 Jan 2023 04:55:38 -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 52F641693; Mon, 16 Jan 2023 13:55:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1673873736; 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=Yr2NORBSCEQzLcadIYW0ER8YcDgLHVyF8s5GGXOqM/0=; b=iujqjS5GzttHoM3AZRBPHyJXUxzurtJo3pvMcQNLMKHyaqqVudo8CJtxrfMlo7YAbvQn7F qBF/LeJMxMtF8AcaWBmw9e7lK/Hux36og2l7+IEjgEDy+5jTHJTOY5Qu5hqLY9+DYBezTP R+kppHvrasBdBzdJvBWJXAenIZjV95SRdsR/xU53+4Fa4NuGwfC6bzdoqFZA7sR92HoczS tI4zs9LJ3RlAjg6Jhxy55BPh4PK6ScVftbtL7qxSVPARCavGvWe95ie2WtwISd7WmQRBWV agi5r6ImYKAbRJClKjEAM8jbprZGFn6yHU9U6CJZj1qSM+8MRW7B6vZOJTmhEw== From: Michael Walle Date: Mon, 16 Jan 2023 13:55:14 +0100 Subject: [PATCH net-next 2/6] net: mdio: Rework scanning of bus ready for quirks MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230116-net-next-remove-probe-capabilities-v1-2-5aa29738a023@walle.cc> References: <20230116-net-next-remove-probe-capabilities-v1-0-5aa29738a023@walle.cc> In-Reply-To: <20230116-net-next-remove-probe-capabilities-v1-0-5aa29738a023@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 X-Mailer: b4 0.11.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/net/ethernet/marvell/pxa168_eth.c | 2 +- drivers/net/phy/mdio_bus.c | 123 +++++++++++++++++++++-----= ---- include/linux/phy.h | 2 +- 3 files changed, 87 insertions(+), 40 deletions(-) diff --git a/drivers/net/ethernet/marvell/pxa168_eth.c b/drivers/net/ethern= et/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; =20 - phy =3D mdiobus_scan(pep->smi_bus, pep->phy_addr); + phy =3D mdiobus_scan_c22(pep->smi_bus, pep->phy_addr); if (IS_ERR(phy)) return PTR_ERR(phy); =20 diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index 61c33c6098a1..25a964b98bc6 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; } =20 -/** - * 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 =3D ERR_PTR(-ENODEV); int err; =20 - switch (bus->probe_capabilities) { - case MDIOBUS_NO_CAP: - case MDIOBUS_C22: - phydev =3D get_phy_device(bus, addr, false); - break; - case MDIOBUS_C45: - phydev =3D get_phy_device(bus, addr, true); - break; - case MDIOBUS_C22_C45: - phydev =3D get_phy_device(bus, addr, false); - if (IS_ERR(phydev)) - phydev =3D get_phy_device(bus, addr, true); - break; - } - + phydev =3D get_phy_device(bus, addr, c45); if (IS_ERR(phydev)) return phydev; =20 @@ -554,7 +528,77 @@ struct phy_device *mdiobus_scan(struct mii_bus *bus, i= nt addr) =20 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 =3D 0; i < PHY_MAX_ADDR; i++) { + if ((bus->phy_mask & BIT(i)) =3D=3D 0) { + struct phy_device *phydev; + + phydev =3D mdiobus_scan_c22(bus, i); + if (IS_ERR(phydev) && (PTR_ERR(phydev) !=3D -ENODEV)) + return PTR_ERR(phydev); + } + } + return 0; +} + +static int mdiobus_scan_bus_c45(struct mii_bus *bus) +{ + int i; + + for (i =3D 0; i < PHY_MAX_ADDR; i++) { + if ((bus->phy_mask & BIT(i)) =3D=3D 0) { + struct phy_device *phydev; + + /* Don't scan C45 if we already have a C22 device */ + if (bus->mdio_map[i]) + continue; + + phydev =3D mdiobus_scan_c45(bus, i); + if (IS_ERR(phydev) && (PTR_ERR(phydev) !=3D -ENODEV)) + return PTR_ERR(phydev); + } + } + return 0; +} =20 /** * __mdiobus_register - bring up all the PHYs on a given bus and attach th= em to bus @@ -639,16 +683,19 @@ int __mdiobus_register(struct mii_bus *bus, struct mo= dule *owner) goto error_reset_gpiod; } =20 - for (i =3D 0; i < PHY_MAX_ADDR; i++) { - if ((bus->phy_mask & BIT(i)) =3D=3D 0) { - struct phy_device *phydev; + if (bus->probe_capabilities =3D=3D MDIOBUS_NO_CAP || + bus->probe_capabilities =3D=3D MDIOBUS_C22 || + bus->probe_capabilities =3D=3D MDIOBUS_C22_C45) { + err =3D mdiobus_scan_bus_c22(bus); + if (err) + goto error; + } =20 - phydev =3D mdiobus_scan(bus, i); - if (IS_ERR(phydev) && (PTR_ERR(phydev) !=3D -ENODEV)) { - err =3D PTR_ERR(phydev); - goto error; - } - } + if (bus->probe_capabilities =3D=3D MDIOBUS_C45 || + bus->probe_capabilities =3D=3D MDIOBUS_C22_C45) { + err =3D mdiobus_scan_bus_c45(bus); + if (err) + goto error; } =20 mdiobus_setup_mdiodev_from_board_info(bus, mdiobus_create_device); 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) } =20 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); =20 #define PHY_INTERRUPT_DISABLED false #define PHY_INTERRUPT_ENABLED true --=20 2.30.2