Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp38500127rwd; Wed, 12 Jul 2023 08:28:02 -0700 (PDT) X-Google-Smtp-Source: APBJJlHrEQKps4T1Yi72JWpy5Y0O9XeM4xC0SsR8lnodvOrBOfIThbWtWBR1Ws2xbZpUzywj5Jfx X-Received: by 2002:a17:906:64d6:b0:991:f913:a479 with SMTP id p22-20020a17090664d600b00991f913a479mr16927479ejn.2.1689175682036; Wed, 12 Jul 2023 08:28:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689175682; cv=none; d=google.com; s=arc-20160816; b=X2RADIpMQ58C9R5vhz+6aBxpVlIGL5Atw3mQKNcTx4A0nxbAdnXFvMVQFS4rFbprSS mJPCN8HIulDbKftNwNC9xibbW6M8tk1IBfEW5Lpn7lbGCR4ymtunjoDiEtSUlzP1xIBr /5FENPYUIw1Aauli9fn2bSj9s8dB5Dja1sNokQTP1XtKTDCSJ03m88YN+0Ei1fELiewm 3n57h/kBQNeXy24cBb2SC6ybNVlLAP87I5j5ezE1eiTWcgRtfudumQ935FYTHDvUVjJB 5brbIEFQs9+y9IIAfwE28iMqwr1h9nP5Q7yqxWF30acxEmdwxo2u7Yw8Xd6gxT/CP7Gy xl0w== 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=MYVO99sTZVawrn6pDvpyWVEAmabkE6xw+mHnSxcGcq8=; fh=iCOcDVYygcUt3nx67Q2pFMpkgstG/nFvtDYAC1AAD60=; b=CiXwesjDafPBJhJ/ielMU+EG2XhjtBOvYJYACp9ezS2oxc/6FbrKRx47N3klYxDNoV tHSV0URugeV+aczqGUJ2mxxRMq1BVcLkguKWUiSAvMSvcWjOq8FAlQuqLpAOjWIP3aCS ubHzaliDuDwYXXNKCvPNOBRFq6E0QgZ1SgEslz6xCd4cuCz221YOTYn1SFbv5QBxWNS/ E8dawicxYMEOjFwzNU3qYfAnrIUEgkX6O5pXrhtvH+iNysTwwsXsG9PYRUp5JtuV4eV6 pGg/jFX9jTYgaL/Do6Mt4v+JAdI5GM3nsyUynn6dPXa1gyWPtC+pTSoimu7tNyBU6rUd ebEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=R74Y+0qv; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v13-20020a1709064e8d00b009885217c85bsi5085350eju.275.2023.07.12.08.27.37; Wed, 12 Jul 2023 08:28:02 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b=R74Y+0qv; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233397AbjGLPIq (ORCPT + 99 others); Wed, 12 Jul 2023 11:08:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233605AbjGLPIR (ORCPT ); Wed, 12 Jul 2023 11:08:17 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F27BAE74 for ; Wed, 12 Jul 2023 08:08:03 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D433A61852 for ; Wed, 12 Jul 2023 15:08:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19723C433CB; Wed, 12 Jul 2023 15:07:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689174483; bh=GAjpRvAIlM6CKm/Pe/JoMXcbUjsEHttM8EMsZkCnfVc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=R74Y+0qvg5O9WE1C4wD1tQkMEZUiTm0sGGgQYdRbYvA7fGhhW3kG9fvAo1sU9nt6L 2KkrrBCeeTLjDRyKpbO5Itc1MvBGkb5jZrM1a6CzfQEWXw+X8hn0S+GwQuls8FcUL7 sXDoVN5vUQDIs5nsw+nQarQcfTYOUoUCSrxzYdhfIuwoG/c/FahpZaVW/k7ScLPIfA i9BXvblXzhYQDqTx0nxrEfcyf3+bC+h9r9y9kz/G4A5qIIvfkSISPpv9OVR3za2hjw aj6O2mBOZzzjtOwc56XfXut1TU8aShiLxFi2nrBs5x6ikqmp35lCKeH51ScARoNkUi eiIc3qyBWp2cg== From: Michael Walle Date: Wed, 12 Jul 2023 17:07:09 +0200 Subject: [PATCH net-next v3 09/11] net: phy: introduce phy_promote_to_c45() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230620-feature-c45-over-c22-v3-9-9eb37edf7be0@kernel.org> References: <20230620-feature-c45-over-c22-v3-0-9eb37edf7be0@kernel.org> In-Reply-To: <20230620-feature-c45-over-c22-v3-0-9eb37edf7be0@kernel.org> To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Yisen Zhuang , Salil Mehta , Florian Fainelli , Broadcom internal kernel review list , =?utf-8?q?Marek_Beh=C3=BAn?= , Xu Liang Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Simon Horman , Michael Walle X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 If not explitly asked to be probed as a C45 PHY, on a bus which is capable of doing both C22 and C45 transfers, C45 PHYs are first tried to be probed as C22 PHYs. To be able to promote the PHY to be a C45 one, the driver can call phy_promote_to_c45() in its probe function. This was already done in the mxl-gpy driver by the following snippet: if (!phy_is_c45(phydev)) { ret = phy_get_c45_ids(phydev); if (ret < 0) return ret; } Move that code into the core as it could be used by other drivers, too. If a PHY is promoted C45-over-C22 access is automatically used as a fallback if the bus doesn't support C45 transactions. Signed-off-by: Michael Walle --- drivers/net/phy/mxl-gpy.c | 9 ++++----- drivers/net/phy/phy_device.c | 36 ++++++++++++++++++++++++++++++------ include/linux/phy.h | 7 ++++++- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/drivers/net/phy/mxl-gpy.c b/drivers/net/phy/mxl-gpy.c index b4ddb9a003d9..b7fca1aae1c3 100644 --- a/drivers/net/phy/mxl-gpy.c +++ b/drivers/net/phy/mxl-gpy.c @@ -281,11 +281,10 @@ static int gpy_probe(struct phy_device *phydev) int fw_version; int ret; - if (!phy_has_c45_registers(phydev)) { - ret = phy_get_c45_ids(phydev); - if (ret < 0) - return ret; - } + /* This might have been probed as a C22 PHY, but this is a C45 PHY */ + ret = phy_promote_to_c45(phydev); + if (ret) + return ret; priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); if (!priv) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 01c41ecb63a7..97fb3cb8b54c 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1057,18 +1057,42 @@ void phy_device_remove(struct phy_device *phydev) EXPORT_SYMBOL(phy_device_remove); /** - * phy_get_c45_ids - Read 802.3-c45 IDs for phy device. - * @phydev: phy_device structure to read 802.3-c45 IDs + * phy_promote_to_c45 - Promote to a C45 PHY + * @phydev: phy_device structure + * + * If a PHY supports both C22 and C45 register access and it isn't specifically + * asked to probe as a C45 PHY it might be probed as a C22 PHY. The driver can + * call this function to promote the PHY from C22 to C45. + * + * Can also be called if a PHY is already a C45 one. In that case it does + * nothing. + * + * If the bus isn't capable of doing C45 transfers, C45-over-C22 access will be + * used as a fallback. * * Returns zero on success, %-EIO on bus access error, or %-ENODEV if * the "devices in package" is invalid. */ -int phy_get_c45_ids(struct phy_device *phydev) +int phy_promote_to_c45(struct phy_device *phydev) { - return get_phy_c45_ids(phydev->mdio.bus, phydev->mdio.addr, - PHY_ACCESS_C45, &phydev->c45_ids); + struct mii_bus *bus = phydev->mdio.bus; + + if (phydev->access_mode != PHY_ACCESS_C22) + return 0; + + if (dev_of_node(&phydev->mdio.dev)) + phydev_info(phydev, + "Promoting PHY to a C45 one. Please consider using compatible=\"ethernet-phy-ieee802.3-c45\"."); + + if (mdiobus_supports_c45(bus)) + phydev->access_mode = PHY_ACCESS_C45; + else + phydev->access_mode = PHY_ACCESS_C45_OVER_C22; + + return get_phy_c45_ids(bus, phydev->mdio.addr, phydev->access_mode, + &phydev->c45_ids); } -EXPORT_SYMBOL(phy_get_c45_ids); +EXPORT_SYMBOL(phy_promote_to_c45); /** * phy_find_first - finds the first PHY device on the bus diff --git a/include/linux/phy.h b/include/linux/phy.h index e4014972b799..180fa5ac0b29 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -467,6 +467,11 @@ struct phy_device *mdiobus_scan_c22(struct mii_bus *bus, int addr); void mdiobus_scan_for_broken_c45_access(struct mii_bus *bus); +static inline bool mdiobus_supports_c45(struct mii_bus *bus) +{ + return bus->read_c45 && !bus->prevent_c45_access; +} + #define PHY_INTERRUPT_DISABLED false #define PHY_INTERRUPT_ENABLED true @@ -1701,7 +1706,7 @@ static inline int phy_device_register(struct phy_device *phy) static inline void phy_device_free(struct phy_device *phydev) { } #endif /* CONFIG_PHYLIB */ void phy_device_remove(struct phy_device *phydev); -int phy_get_c45_ids(struct phy_device *phydev); +int phy_promote_to_c45(struct phy_device *phydev); int phy_init_hw(struct phy_device *phydev); int phy_suspend(struct phy_device *phydev); int phy_resume(struct phy_device *phydev); -- 2.39.2