From nobody Sat Sep 21 06:33:28 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 04051C46467 for ; Wed, 18 Jan 2023 10:56:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229910AbjARK4D (ORCPT ); Wed, 18 Jan 2023 05:56:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229995AbjARKxB (ORCPT ); Wed, 18 Jan 2023 05:53:01 -0500 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1923388742; Wed, 18 Jan 2023 02:01:48 -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 CF3581671; 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=1674036106; 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=7i9qbwSDlGkaEMAao/7IOBLlkWEf4kE9vsL/6dW7DOw=; b=sfpSS9Kjd9842sP40iyX+WvxgWIzof0diOjdpmoYAZE3RTcYKt2G38MkWRx4WLhkoRrVjX v/4fI/4AbkKptvvqLKhYqdYf9fC29BSzA89BeZWQLwEF3iYIXtFaSsn0aRvEeHUz/Vr67C CgefUeD6AcNz8oorpMrkwONDcoKdufbdmEbDonIsUeubP4W5+teBXU3A8Q1SzDKs9cIpvm TLplpA7l4ioD8wtn3Lz+RI3+7xCXSa3ednymkbTwHDjs37GP2fYgRKzpTkA1UbSrwLVzEo azg3IK2lO195nKysbe5d3R1dGqi+Rrnrkkt2qDss8UJKO9VFnpEB5I62KoZIqg== From: Michael Walle Date: Wed, 18 Jan 2023 11:01:37 +0100 Subject: [PATCH net-next v2 3/6] net: mdio: Add workaround for Micrel PHYs which are not C45 compatible MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230116-net-next-remove-probe-capabilities-v2-3-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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrew Lunn After scanning the bus for C22 devices, check if any Micrel PHYs have been found. They are known to do bad things if there are C45 transactions on the bus. Prevent the scanning of the bus using C45 if such a PHY has been detected. Signed-off-by: Andrew Lunn Signed-off-by: Michael Walle --- v2: [mw] move variable declaration into the loop. Thanks, Jesse. --- drivers/net/phy/mdio_bus.c | 37 ++++++++++++++++++++++++++++++++++--- include/linux/micrel_phy.h | 2 ++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index 667247f661c5..a664eeb1868d 100644 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -600,6 +601,32 @@ static int mdiobus_scan_bus_c45(struct mii_bus *bus) return 0; } =20 +/* There are some C22 PHYs which do bad things when where is a C45 + * transaction on the bus, like accepting a read themselves, and + * stomping over the true devices reply, to performing a write to + * themselves which was intended for another device. Now that C22 + * devices have been found, see if any of them are bad for C45, and if we + * should skip the C45 scan. + */ +static bool mdiobus_prevent_c45_scan(struct mii_bus *bus) +{ + int i; + + for (i =3D 0; i < PHY_MAX_ADDR; i++) { + struct phy_device *phydev; + u32 oui; + + phydev =3D mdiobus_get_phy(bus, i); + if (!phydev) + continue; + oui =3D phydev->phy_id >> 10; + + if (oui =3D=3D MICREL_OUI) + return true; + } + return false; +} + /** * __mdiobus_register - bring up all the PHYs on a given bus and attach th= em to bus * @bus: target mii_bus @@ -617,8 +644,9 @@ static int mdiobus_scan_bus_c45(struct mii_bus *bus) int __mdiobus_register(struct mii_bus *bus, struct module *owner) { struct mdio_device *mdiodev; - int i, err; struct gpio_desc *gpiod; + bool prevent_c45_scan; + int i, err; =20 if (!bus || !bus->name) return -EINVAL; @@ -691,8 +719,11 @@ int __mdiobus_register(struct mii_bus *bus, struct mod= ule *owner) goto error; } =20 - if (bus->probe_capabilities =3D=3D MDIOBUS_C45 || - bus->probe_capabilities =3D=3D MDIOBUS_C22_C45) { + prevent_c45_scan =3D mdiobus_prevent_c45_scan(bus); + + if (!prevent_c45_scan && + (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; diff --git a/include/linux/micrel_phy.h b/include/linux/micrel_phy.h index 1f7c33b2f5a3..771e050883db 100644 --- a/include/linux/micrel_phy.h +++ b/include/linux/micrel_phy.h @@ -8,6 +8,8 @@ #ifndef _MICREL_PHY_H #define _MICREL_PHY_H =20 +#define MICREL_OUI 0x0885 + #define MICREL_PHY_ID_MASK 0x00fffff0 =20 #define PHY_ID_KSZ8873MLL 0x000e7237 --=20 2.30.2