From patchwork Fri Jun 23 10:29:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 112069 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5690561vqr; Fri, 23 Jun 2023 04:13:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ45BSFA8UGNQ1yWkhHI1ykxbKg/NovATbX9icRvmJcRyMD5kRF0Zl8XJOu92aAjbdcyptf7 X-Received: by 2002:a05:6830:22f2:b0:6b7:1ab5:9bcb with SMTP id t18-20020a05683022f200b006b71ab59bcbmr3157124otc.36.1687518812999; Fri, 23 Jun 2023 04:13:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687518812; cv=none; d=google.com; s=arc-20160816; b=Mlt9V3O7NcjAREHiih4kk8Jt4ZUvnhkFohSWAYs3xYZtUcSKBv9QvdCzg1InL/CjKg qHtDib+JCExAdYab2T0J7J+w3W1vCb76UPS6amYNXK1m8MdMtrp5GPgUB//RfJs9CM4Q Qw7Dsn9z5JCyM8oPZvO2EucZ4HLtvxn2+8ysOwK1Fib3Z8Llwk4Eqrqudl0ikuhDhhnw JuQLvr7lqt62SWDVaDIuA3NkNQvmz9dGe0ltHWgJ23BF8P+yljM1VGaGmcDFPLwGBaxP 1/YQkHLUdvQlANKN+YxSZNJy+CFuBD2epTnKqgMyt1jasMU0RV0CgWki/IhER6rOcEkX +MAw== 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=M/0eqHUOmIYD/MOGOp91LNvLdvfANGQzvOpOkBMnslE=; b=kZnE1mhQ3gyRFco+tbs61B06voVmZLBtRrC0cq/RIVkrfzraz6zohf/TjTeXNFr7Su YtuzhVjvKXDTBq8XAgcKK4725kqOd3iMQ5e0fVR6ihx8fRJxSwVVxVDcCKlIt7Ccgl3Q /GjwYaMiKWo7oF7V7Ll1yVWgCDOCpD66aCNuNRz4KU6eTAiZrB4FuUltuu9vT/30y+YR geX5O/egdFh25qvguK+y57KDkOejHD0nlWfhJ8Bt+bRQxI+ne648kqKytjoM6FtiI7ZR CNabw1pcdiSNnJ23x6SEpJUGRMHd63DtuC5GVHu4Ipk9F7+d6q1ToFEuzLalry/35cOJ 4fQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vB3MzkX4; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s68-20020a632c47000000b00557848bf4d7si39882pgs.798.2023.06.23.04.13.20; Fri, 23 Jun 2023 04:13:32 -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=vB3MzkX4; 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 S232274AbjFWKab (ORCPT + 99 others); Fri, 23 Jun 2023 06:30:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232400AbjFWKaK (ORCPT ); Fri, 23 Jun 2023 06:30:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDBF810FD for ; Fri, 23 Jun 2023 03:29:50 -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 730FF61A1B for ; Fri, 23 Jun 2023 10:29:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8FF1EC433C8; Fri, 23 Jun 2023 10:29:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687516189; bh=h/wyoas79DZ6KTfkJ9+jTQgKoQB1VoPw7r90QcpSJeU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=vB3MzkX4oj4tmkT1SKsRSUZg0wrSuMKJMAQ0dJvlFeECCRx1vb8rN/BR16D3p1zqd 4+7SJSZXmKwGdsGzSeSNTVaYks7MX7R2b1hgJ2Bo1Tn3YPeg20N5dQC4rUrppZ88EJ 6zI/yWqX9QYYZ9iwbF4/MSYoWWpX55M4bE/NHttvb27DvwozTzLbxTExtftkpvhfQ6 bGodJrJtQl8K31vwIcrrnXkkcr+kmfZw3LE/D9CwzatT6jilvpkeXGNMBwTVZgW/0z Y2gWrs2aPiXSrWKTEBzUhOjest9B3iDfMFYui+JwKnM7SDNSxc6+E5z8RZ7WCKa13I RoOLpdzCHxODw== From: Michael Walle Date: Fri, 23 Jun 2023 12:29:17 +0200 Subject: [PATCH net-next v2 08/10] net: phy: introduce phy_promote_to_c45() MIME-Version: 1.0 Message-Id: <20230620-feature-c45-over-c22-v2-8-def0ab9ccee2@kernel.org> References: <20230620-feature-c45-over-c22-v2-0-def0ab9ccee2@kernel.org> In-Reply-To: <20230620-feature-c45-over-c22-v2-0-def0ab9ccee2@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, Michael Walle X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769491726907419461?= X-GMAIL-MSGID: =?utf-8?q?1769491726907419461?= 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 66411e46937b..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_is_c45(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 13d5ec7a7c21..3f9041a3ad72 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1085,18 +1085,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 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 a 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, - &phydev->c45_ids, false); + struct mii_bus *bus = phydev->mdio.bus; + + if (phy_is_c45(phydev)) + 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->c45_ids, + phydev->access_mode == PHY_ACCESS_C45_OVER_C22); } -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 4852651f6326..f9c91766bc47 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);