Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp3197902rwb; Mon, 16 Jan 2023 05:09:25 -0800 (PST) X-Google-Smtp-Source: AMrXdXua8KdqznuFwlJusRQ+nQmjaV6ClRgMCowzl1EsJTYXvCJ3StF0MHpKvPKWFjIOrJh0ZgNc X-Received: by 2002:a05:6402:2932:b0:47e:bdb8:9133 with SMTP id ee50-20020a056402293200b0047ebdb89133mr87520030edb.38.1673874565470; Mon, 16 Jan 2023 05:09:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673874565; cv=none; d=google.com; s=arc-20160816; b=lU2Y3eBXswgNoRoeSoEgWSJDqEyeUnuK6XiVls6AnTubSIWz3z40iUxjW5A0zYToSB DHV3n1gIgwx/F1mGjh8v17WVWxWtBMiqAdyOoEE+DbDcT6NFRPYeyGvalrUoNIlM2uXJ cbG8tnwoxdqD1iY7BNO7Mt6QrkDJ13AvXo6hE8Cqra7dFiE6sjUMNKeJ1MtstBDoaPHm vryRK/NH5E8I1t4Wh3dnbymLxx0Bhyp2kS0nh4Hn4GovdEOiNXBbJ1/wyQ/U+a1T8hlp M6TCDfOQdTq/+uEOUKUeZcDfDIFFkySB73GBT0gdw52uJdaD2yHeD02Tf0F7QDTpuotw p0Sw== 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=mOdDk7qwM6KUEnwMOgYHBFHa54fOPcgwCfCBJX4vAW4=; b=gcBobA/vzVbyAicGdk5duS0XzH9l8WXUZnHAfzISxxBkSILj2AFtLD4aqHmxlaLYiU iacu3aSv7S1qB453L3pzKSpIyBPcoKxZOoMfsZhHcIw4OX1B58INymWgUu8Myd8WJ4Q/ Jes1PvERKyPjnLVlpQvQ/Xkicj6awWd0B+HK4Pix+1Wx9VDI1ddL7kznjX41ILOcMDzK brXS+N7ehsWyOB6XGyWz+7M95k8bpZr9g7HSRjXShk90Z7gAvO/fdD7dGzH9JqOaE6Ho ghhLakaK/mbhYnXllG7Ztaa9SXBoKuxaUh6bv5Uv5FqdTN1bIoBLhGxW4YUFs9D4+crg eXhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=rth6PUzu; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h6-20020a50ed86000000b0049b67ac6ecdsi11116887edr.556.2023.01.16.05.09.12; Mon, 16 Jan 2023 05:09:25 -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=rth6PUzu; 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 S231390AbjAPM5P (ORCPT + 51 others); Mon, 16 Jan 2023 07:57:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231267AbjAPM4r (ORCPT ); Mon, 16 Jan 2023 07:56:47 -0500 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19A161F923; Mon, 16 Jan 2023 04:55:39 -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 047F016AE; Mon, 16 Jan 2023 13:55:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1673873737; 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=mOdDk7qwM6KUEnwMOgYHBFHa54fOPcgwCfCBJX4vAW4=; b=rth6PUzujx7tCIfgztgrsh2zQJqux1ncT1wDPw36a1KamHLyr8BHG6ACVmZUhn6afvUi35 L5b9RYITB+ctJL9lojjnvvEAJgiA9QtzZdxwy2R3ZlnEPh0kZPtUIVhSzF3wHVB/JP7UL4 xbGumpX0EArRziQAVyjxeuRgEU24zZpy0xc0l4AAjc0cu5VeMXljYv7qhwkcDbbSYEOdq9 FrD6pXadv+kz6oEaJCLtVB1z2UuwVvf8UJ/U1jJWUF/5J2VmXCK/RAp7xnQ+EIzwM0uvyq 8yvj17bZn37bpi5CX7/xT5mbl5Tq8dNvaTcpcObt36w/m+fkrAc/1m1Geu1s1w== From: Michael Walle Date: Mon, 16 Jan 2023 13:55:15 +0100 Subject: [PATCH net-next 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: 7bit Message-Id: <20230116-net-next-remove-probe-capabilities-v1-3-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 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 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 --- drivers/net/phy/mdio_bus.c | 36 +++++++++++++++++++++++++++++++++--- include/linux/micrel_phy.h | 2 ++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index 25a964b98bc6..f173c91842e0 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,31 @@ static int mdiobus_scan_bus_c45(struct mii_bus *bus) return 0; } +/* 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) +{ + struct phy_device *phydev; + u32 oui; + int i; + + for (i = 0; i < PHY_MAX_ADDR; i++) { + phydev = mdiobus_get_phy(bus, i); + if (!phydev) + continue; + oui = phydev->phy_id >> 10; + + if (oui == MICREL_OUI) + return true; + } + return false; +} + /** * __mdiobus_register - bring up all the PHYs on a given bus and attach them to bus * @bus: target mii_bus @@ -617,8 +643,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; if (!bus || !bus->name) return -EINVAL; @@ -691,8 +718,11 @@ int __mdiobus_register(struct mii_bus *bus, struct module *owner) goto error; } - if (bus->probe_capabilities == MDIOBUS_C45 || - bus->probe_capabilities == MDIOBUS_C22_C45) { + prevent_c45_scan = mdiobus_prevent_c45_scan(bus); + + if (!prevent_c45_scan && + (bus->probe_capabilities == MDIOBUS_C45 || + bus->probe_capabilities == MDIOBUS_C22_C45)) { err = 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 +#define MICREL_OUI 0x0885 + #define MICREL_PHY_ID_MASK 0x00fffff0 #define PHY_ID_KSZ8873MLL 0x000e7237 -- 2.30.2