From patchwork Fri Jun 23 10:29:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 112051 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5671450vqr; Fri, 23 Jun 2023 03:35:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7QOuN05nG9GS8uhUw20C8gCgLAQRsR2zMr1wVYFtPA5fxeNWn4Y+YkHZaakRgKTMinjavC X-Received: by 2002:a17:902:ce87:b0:1b5:6312:4c5b with SMTP id f7-20020a170902ce8700b001b563124c5bmr12970992plg.63.1687516546695; Fri, 23 Jun 2023 03:35:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687516546; cv=none; d=google.com; s=arc-20160816; b=louPwYC62euEEl7nIerZ9hh1kdEhSM9v33Yw+Kp6aXqABdkBCcHeI0mLEn8DLg0kIc IRQwScGyuKdddTLkfvuc231O/nISo53GmH7oal7FbSLQkzygG8wQr0DCbWeRVG6ZKtLl kk62LTFB1HEVWELGzbuGsI/PxAD75v4fLsKAMTijiRvl4w7br0q9DQ4mmt203wbrQAxd r4FQaocUruUtVXxdIOkrbcxqmld5rUjj13haJRu8cT/xIiLfLiNyNWSE/HVvahjc18Hl wXW7nAeMzryBs9fAkJOsRlB7dBJOEdTLQ9JPxuNITmz8pGonzP+GsvmGUpJ4id/bs9fh WG0A== 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=qAUXo6upYsTu4bAng7vH9abfr1KXA/Hi/oyOetdL3Dc=; b=ZD7YOp8Ugsi3rDn/5A+LYzOw6vi8HHhySfwHILxbi3sQ6evgx6K1QmTY2Ru5yNeckS 5f1mKbowRmvqBiK+WrHIW1lvsJEuBldHyXvWFyrBJZ5Wu403IMy2ccjqkM1PcAabCk+f lUbbVVPDKofyvvlL/tKake4CSoHECXDtIeT2eFvmAbLPdomwXU8SWJYPAL/8iuSzh9pN roOUgftNL7RCaiph7OyOM5rIpUo/jw+ZK+NlSsmXHshXI4kmmBXrUdL+23YdFjz6OvgM hUGt38y6l7eRKpC9lwfryhRSIFWTTkGyMuKOYj4mueQv7+EZVI5uhPOc66O2AwSLLOLj 6iHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fl2VzWeG; 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 p18-20020a170902ebd200b001aaf5dcd774si3490841plg.173.2023.06.23.03.35.05; Fri, 23 Jun 2023 03:35:46 -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=fl2VzWeG; 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 S232009AbjFWK33 (ORCPT + 99 others); Fri, 23 Jun 2023 06:29:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229611AbjFWK3Z (ORCPT ); Fri, 23 Jun 2023 06:29:25 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E5A4E9 for ; Fri, 23 Jun 2023 03:29:24 -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 2A4586196E for ; Fri, 23 Jun 2023 10:29:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F899C433C0; Fri, 23 Jun 2023 10:29:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687516163; bh=vEp6e9pd3I6Zdh/O1E/anlFi8UY82+4KI4u5fMcKVkw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=fl2VzWeGxHzb+H7YHngnlyV15as9Bo0BUqKBKHwIksx/JXSbfP39UPJDN8kM7VS7Z /2zNRz6PFZ8hCxpvWr/6ACVaLwRcbQQth00pjag1gTwzBCGHGSGUXUyCr93jf5HlID dskHpg/6Aa7ejr2L/JExuOKs1tjtLha8wXGva3K+b8YeWvI+8YoFT9QT1IECPE3Hy8 a40vA93nnHbq5c7oVevU7/JiBsWN3mPHXIaJCcQ8A2Ybht6VKD9j6PIZuDCnqhoxpe oZolzu8I4VVaqfuG0GH/KbYRcK1o37iTDZIWnUrOc4YmV2Sq4zlBuVozGmxnU0oUXD FwLAIAxRma7hA== From: Michael Walle Date: Fri, 23 Jun 2023 12:29:10 +0200 Subject: [PATCH net-next v2 01/10] net: phy: add error checks in mmd_phy_indirect() and export it MIME-Version: 1.0 Message-Id: <20230620-feature-c45-over-c22-v2-1-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=-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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769489350505266128?= X-GMAIL-MSGID: =?utf-8?q?1769489350505266128?= Add missing error checks in mmd_phy_indirect(). The error checks need to be disabled to retain the current behavior in phy_read_mmd() and phy_write_mmd(). Therefore, add a new parameter to enable the error checks. Add a thin wrapper __phy_mmd_indirect() which is then exported. Regarding the legacy handling, Russell states: | The reason for that goes back to commit a59a4d192166 ("phy: add the | EEE support and the way to access to the MMD registers.") | | and to maintain compatibility with that; if we start checking for | errors now, we might trigger a kernel regression sadly. Signed-off-by: Michael Walle --- drivers/net/phy/phy-core.c | 42 ++++++++++++++++++++++++++++++++++-------- include/linux/phy.h | 2 ++ 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c index a64186dc53f8..65ff58b36fc0 100644 --- a/drivers/net/phy/phy-core.c +++ b/drivers/net/phy/phy-core.c @@ -524,19 +524,45 @@ int phy_speed_down_core(struct phy_device *phydev) return 0; } -static void mmd_phy_indirect(struct mii_bus *bus, int phy_addr, int devad, - u16 regnum) +static int mmd_phy_indirect(struct mii_bus *bus, int phy_addr, int devad, + u16 regnum, bool check_rc) { + int ret; + /* Write the desired MMD Devad */ - __mdiobus_write(bus, phy_addr, MII_MMD_CTRL, devad); + ret = __mdiobus_write(bus, phy_addr, MII_MMD_CTRL, devad); + if (check_rc && ret) + return ret; /* Write the desired MMD register address */ - __mdiobus_write(bus, phy_addr, MII_MMD_DATA, regnum); + ret = __mdiobus_write(bus, phy_addr, MII_MMD_DATA, regnum); + if (check_rc && ret) + return ret; /* Select the Function : DATA with no post increment */ - __mdiobus_write(bus, phy_addr, MII_MMD_CTRL, - devad | MII_MMD_CTRL_NOINCR); + ret = __mdiobus_write(bus, phy_addr, MII_MMD_CTRL, + devad | MII_MMD_CTRL_NOINCR); + + return check_rc ? ret : 0; +} + +/** + * __phy_mmd_indirect - prepare an indirect C45 register access + * + * @bus: the target MII bus + * @phy_addr: PHY address on the MII bus + * @devad: The target MMD (0..31) + * @regnum: The target register on the MMD (0..65535) + * + * Prepare an indirect C45 read or write transfer using the MII_MMD_CTRL and + * MII_MMD_DATA registers in C22 space. + */ +int __phy_mmd_indirect(struct mii_bus *bus, int phy_addr, int devad, + u16 regnum) +{ + return mmd_phy_indirect(bus, phy_addr, devad, regnum, true); } +EXPORT_SYMBOL(__phy_mmd_indirect); /** * __phy_read_mmd - Convenience function for reading a register @@ -563,7 +589,7 @@ int __phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum) struct mii_bus *bus = phydev->mdio.bus; int phy_addr = phydev->mdio.addr; - mmd_phy_indirect(bus, phy_addr, devad, regnum); + mmd_phy_indirect(bus, phy_addr, devad, regnum, false); /* Read the content of the MMD's selected register */ val = __mdiobus_read(bus, phy_addr, MII_MMD_DATA); @@ -619,7 +645,7 @@ int __phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val) struct mii_bus *bus = phydev->mdio.bus; int phy_addr = phydev->mdio.addr; - mmd_phy_indirect(bus, phy_addr, devad, regnum); + mmd_phy_indirect(bus, phy_addr, devad, regnum, false); /* Write the data into MMD's selected register */ __mdiobus_write(bus, phy_addr, MII_MMD_DATA, val); diff --git a/include/linux/phy.h b/include/linux/phy.h index 11c1e91563d4..9521b815d3f0 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1316,6 +1316,8 @@ int phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum); __ret; \ }) +int __phy_mmd_indirect(struct mii_bus *bus, int phy_addr, int devad, + u16 regnum); /* * __phy_read_mmd - Convenience function for reading a register * from an MMD on a given PHY. From patchwork Fri Jun 23 10:29:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 112049 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5670965vqr; Fri, 23 Jun 2023 03:34:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6E7RFhCjgTsNpLIeOHqzyGbuBJ6Q0p/lKeMEXZvc/OTMTxkgXSoJJ2HAXPvD63xdGEsbYH X-Received: by 2002:a05:6a00:1a89:b0:668:7744:10f5 with SMTP id e9-20020a056a001a8900b00668774410f5mr13896912pfv.10.1687516486244; Fri, 23 Jun 2023 03:34:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687516486; cv=none; d=google.com; s=arc-20160816; b=Rt6jN+pIoue6QquRaPJ/gsa4ZAen4vE6L9n/v4oeJWF6YpZmsdM8Ac0Ft6R9NIwbL7 JXGDUd3WH/TmHe+hZABm8n4UvfxKt7dwrMr2uOWLu/yn5GGhd0fXiFC6zt1hh39FrbmF hTLquZiLxBIWaq4SqECiB2WCUV0K2Xabh9feg+myzHDsmWbfPZPVVOPJSZGvNCjC5JZS uQdp+lO0ffM2ZosYF00kjayVU+/OdsjjJX2HK2X9D5NGtNav/F3S44fm/LOj1cq+l7NR 3kF8WpzS8IGGzykL+dEAiHQ0oiImd+pflOWmTgpDAfMzo0ClGw6ZxnHPdxz7Fqofx24E Th1A== 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=OU7+4qsJlAMGD194fx1AaI3yHYu8KdEChrNhRSexvu0=; b=R7OR3Zh6SIeRm5S8uiEzbGHl8Af8vGLDbMdAI8RP/GnqPtOifJhLSu5/NPeSjwLNF7 D1OqmgyOfN4KrJKGBCaKBkEQYooJ6MiuytG0oHXjchFqHsEjdhHLIfwtFkFEpXLJNF8I OSYOy8/XOH14Brmt//jWV77AgwGbniGvKjoXfGhagAzAJpUtaxfHCC5gbda/1Tt+Wepq Bp71eC6BHoY3eGVhbWaXcplrVFvK+ICqutA7AHTVcbvUbTHzgH4swXBHMy2+dRlPsPpW klN9I9jGi4I+Co6WFE7ZZDM74MS1aeUdSsOJzx6xG6xTjNFNuerEHpdFwBDEiIl36fqa p64Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HB4DiJYF; 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 k11-20020aa7972b000000b00661cd40bd67si8206577pfg.314.2023.06.23.03.34.27; Fri, 23 Jun 2023 03:34:46 -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=HB4DiJYF; 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 S232099AbjFWK3j (ORCPT + 99 others); Fri, 23 Jun 2023 06:29:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232011AbjFWK33 (ORCPT ); Fri, 23 Jun 2023 06:29:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4687D170B for ; Fri, 23 Jun 2023 03:29:28 -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 C9DD061A0A for ; Fri, 23 Jun 2023 10:29:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09EC6C433CD; Fri, 23 Jun 2023 10:29:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687516167; bh=6hu2QLAnatQP5UFKHqQxLipPsz8mKS6yWJMOvqrfh4E=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=HB4DiJYFdsC6nwsmuBDgpqzoftv3wGE9kx2A/mRbaPiEWS39Oqg+CY8ll48GHQJBW VXtDxP4I7g2jundKpNXZnzc22jw/AyQhuBaAZag0Do7EFWom6vRJhQN8FuVDOaXjST gDd6u8/UwkNkhWnxOyZrHo0f/5I+y1eLyNtJmxFgF65bbTTEF3m1b3rD83F4s3Dyns Ka1d3Wdk6nIWJQt4/vH4gtRHBXYuwRpxCpEJPEYIcSq9GYwHqKl1SpNN6xdv5sa+V6 sW6WMUGj+O+RKNnKHb2TPN1BnATO1gAqNWdgq5eKjAgRlkwJgh2nGTD/fGp1CcL8Co gSy3OVqo7WZrA== From: Michael Walle Date: Fri, 23 Jun 2023 12:29:11 +0200 Subject: [PATCH net-next v2 02/10] net: phy: get rid of redundant is_c45 information MIME-Version: 1.0 Message-Id: <20230620-feature-c45-over-c22-v2-2-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=-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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769489287183801525?= X-GMAIL-MSGID: =?utf-8?q?1769489287183801525?= phy_device_create() will be called with is_c45 and c45_ids. If c45_ids are set, is_c45 is (usually) true. Change the only caller which do things differently, then drop the is_c45 check in phy_device_create(). This is a preparation patch to replace the is_c45 boolean with an enum which will indicate how the PHY is accessed (by c22, c45 or c45-over-c22). Signed-off-by: Michael Walle --- drivers/net/phy/phy_device.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 0c2014accba7..226d5507c865 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -689,7 +689,7 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id, * driver will get bored and give up as soon as it finds that * there's no driver _already_ loaded. */ - if (is_c45 && c45_ids) { + if (c45_ids) { const int num_ids = ARRAY_SIZE(c45_ids->device_ids); int i; @@ -970,7 +970,8 @@ struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45) true, &c45_ids); } - return phy_device_create(bus, addr, phy_id, is_c45, &c45_ids); + return phy_device_create(bus, addr, phy_id, is_c45, + !is_c45 ? NULL : &c45_ids); } EXPORT_SYMBOL(get_phy_device); From patchwork Fri Jun 23 10:29:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 112050 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5671037vqr; Fri, 23 Jun 2023 03:34:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7aPg7BMcaSXRE67xoUBvF7vjeHAJ2K0beGPu1T1oKgGeXdOjc9HKy3pNCo+GvlRvMVR4tj X-Received: by 2002:a05:6358:ce24:b0:131:22f2:8185 with SMTP id gt36-20020a056358ce2400b0013122f28185mr5896754rwb.12.1687516497129; Fri, 23 Jun 2023 03:34:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687516497; cv=none; d=google.com; s=arc-20160816; b=j+FsWvU1sAKfRmSd1GTE1qNlYlnuvm8DobYCsNw7Xez8gVBF7ghA8RabEqE5MWGCcN Ns+LIq04+gZ/Xsh9nXN2MM2IywzLNXVkTGat83SdtHdm7Oxta3+1INaJdOGx4AhtrTdM 73+ssSuPToePUvCe1jXx5haMDmAEjal1X8jEdlmKY128lLbfSk1zLi94jMqhkBiT1NmV gv9CW+3czi2aKGGzy5/hrTrp5UeqxIWRiI+udcIp5QqeZ2j5PkO+cOmQwZe4Z9Nq6CSs TbwLHSNUgtotHqD8zoxrGY9WzxGIvLIe0O4RS395tKT9x7Rvb/HMYxJHdRnLknu1pWFE rl/w== 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=mZuBS9hls3mPERjAUlXP6tPaoMP3uRHTjj7mysEGE4g=; b=mwtVEHZBifNS5rSduJv4EiuLyGmPEwXWsqlPFULB/lN6oB1dRQzSuSebec0McKC3TY cHsGtWPmS379+okvekT3+mNMH5inB675PStWgDxB68M2e3cLtv1Iwv/KvNCJ1ww5Pzyy WSrWq6mMRgmmnXwI6BZkhpKcJ6M1BPVEeVaQSuRe6h1bxlmTkNc2ach6OZFH/9QsOvEF RrhM0TOS7p1oBV2ZRDp+rJoAzednruaxT74Knm8Pb7dF+X+1AsP7WMRQORJLyDCMLfiy IrAuX5BpkBaGkJhbncabe/yGXkbTakQYjzYP6NNyY/UUwQKLcOdVpEc7BlXIpfEYTvDC Nd5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aegJOsCP; 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 z14-20020aa7958e000000b0064d35b65bddsi8294667pfj.362.2023.06.23.03.34.36; Fri, 23 Jun 2023 03:34:57 -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=aegJOsCP; 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 S232181AbjFWK3o (ORCPT + 99 others); Fri, 23 Jun 2023 06:29:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232186AbjFWK3f (ORCPT ); Fri, 23 Jun 2023 06:29:35 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AFD91BD2 for ; Fri, 23 Jun 2023 03:29:32 -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 7389E61A17 for ; Fri, 23 Jun 2023 10:29:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AABE2C43397; Fri, 23 Jun 2023 10:29:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687516170; bh=Y6cTng4sB3ljn5S+j92xxJk0426djdJ4J90vclqWu28=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=aegJOsCPs/KVKg3ATjRfSC6ANHZO+2teCEwsHxw/uaJ3KEsFHmv36DlosLbUjiTlK AWF4zyTpCQp8LmOvSTESu+Obv9hST8WlA13JHEBcOVMuFBwmrnEiRgIDAF+7KbtMSn u/GAT9oqOwTzxaWoifQ/1r9pVL9Ysy+WPv0CzqgvToPYfM0MSQz+g6Hu1PeC+lo6PL lvexR2A1tEVLE6xz9M9UCJG7qDwCWLDUQVipfGWR/HBd9jxLFRcQ+rSrnSjNHcJ8kN eXHJmJy1YXb6A5gHNinoqRFGiS9hyXXF6Q+jjUlME1AXKCNQ5TJoJTA81jmdXSQebU 708vq8Av0/42g== From: Michael Walle Date: Fri, 23 Jun 2023 12:29:12 +0200 Subject: [PATCH net-next v2 03/10] net: phy: introduce phy_is_c45() MIME-Version: 1.0 Message-Id: <20230620-feature-c45-over-c22-v2-3-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=-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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769489298303391437?= X-GMAIL-MSGID: =?utf-8?q?1769489298303391437?= Provide a helper to determine if the PHY is a C45 one. This is a preparation patch to remove the is_c45 field. No functional change. Signed-off-by: Michael Walle --- drivers/net/ethernet/hisilicon/hns/hns_ethtool.c | 4 ++-- drivers/net/phy/bcm84881.c | 2 +- drivers/net/phy/marvell10g.c | 2 +- drivers/net/phy/mxl-gpy.c | 2 +- drivers/net/phy/phy-core.c | 4 ++-- drivers/net/phy/phy.c | 8 +++++--- drivers/net/phy/phy_device.c | 6 +++--- drivers/net/phy/phylink.c | 10 +++++----- include/linux/phy.h | 5 +++++ 9 files changed, 25 insertions(+), 18 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c index b54f3706fb97..7b1511edc2c5 100644 --- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c +++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c @@ -916,7 +916,7 @@ static void hns_get_strings(struct net_device *netdev, u32 stringset, u8 *data) hns_nic_test_strs[MAC_INTERNALLOOP_MAC]); ethtool_sprintf(&buff, hns_nic_test_strs[MAC_INTERNALLOOP_SERDES]); - if ((netdev->phydev) && (!netdev->phydev->is_c45)) + if (netdev->phydev && !phy_is_c45(netdev->phydev)) ethtool_sprintf(&buff, hns_nic_test_strs[MAC_INTERNALLOOP_PHY]); @@ -976,7 +976,7 @@ static int hns_get_sset_count(struct net_device *netdev, int stringset) if (priv->ae_handle->phy_if == PHY_INTERFACE_MODE_XGMII) cnt--; - if ((!netdev->phydev) || (netdev->phydev->is_c45)) + if (!netdev->phydev || phy_is_c45(netdev->phydev)) cnt--; return cnt; diff --git a/drivers/net/phy/bcm84881.c b/drivers/net/phy/bcm84881.c index 9717a1626f3f..5fd67ede6802 100644 --- a/drivers/net/phy/bcm84881.c +++ b/drivers/net/phy/bcm84881.c @@ -47,7 +47,7 @@ static int bcm84881_probe(struct phy_device *phydev) /* This driver requires PMAPMD and AN blocks */ const u32 mmd_mask = MDIO_DEVS_PMAPMD | MDIO_DEVS_AN; - if (!phydev->is_c45 || + if (!phy_is_c45(phydev) || (phydev->c45_ids.devices_in_package & mmd_mask) != mmd_mask) return -ENODEV; diff --git a/drivers/net/phy/marvell10g.c b/drivers/net/phy/marvell10g.c index 55d9d7acc32e..6c2cde4b87fc 100644 --- a/drivers/net/phy/marvell10g.c +++ b/drivers/net/phy/marvell10g.c @@ -499,7 +499,7 @@ static int mv3310_probe(struct phy_device *phydev) u32 mmd_mask = MDIO_DEVS_PMAPMD | MDIO_DEVS_AN; int ret; - if (!phydev->is_c45 || + if (!phy_is_c45(phydev) || (phydev->c45_ids.devices_in_package & mmd_mask) != mmd_mask) return -ENODEV; diff --git a/drivers/net/phy/mxl-gpy.c b/drivers/net/phy/mxl-gpy.c index ea1073adc5a1..66411e46937b 100644 --- a/drivers/net/phy/mxl-gpy.c +++ b/drivers/net/phy/mxl-gpy.c @@ -281,7 +281,7 @@ static int gpy_probe(struct phy_device *phydev) int fw_version; int ret; - if (!phydev->is_c45) { + if (!phy_is_c45(phydev)) { ret = phy_get_c45_ids(phydev); if (ret < 0) return ret; diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c index 65ff58b36fc0..5f73d27fe330 100644 --- a/drivers/net/phy/phy-core.c +++ b/drivers/net/phy/phy-core.c @@ -582,7 +582,7 @@ int __phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum) if (phydev->drv && phydev->drv->read_mmd) { val = phydev->drv->read_mmd(phydev, devad, regnum); - } else if (phydev->is_c45) { + } else if (phy_is_c45(phydev)) { val = __mdiobus_c45_read(phydev->mdio.bus, phydev->mdio.addr, devad, regnum); } else { @@ -638,7 +638,7 @@ int __phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val) if (phydev->drv && phydev->drv->write_mmd) { ret = phydev->drv->write_mmd(phydev, devad, regnum, val); - } else if (phydev->is_c45) { + } else if (phy_is_c45(phydev)) { ret = __mdiobus_c45_write(phydev->mdio.bus, phydev->mdio.addr, devad, regnum, val); } else { diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index bdf00b2b2c1d..debd618670e6 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -182,7 +182,8 @@ int phy_restart_aneg(struct phy_device *phydev) { int ret; - if (phydev->is_c45 && !(phydev->c45_ids.devices_in_package & BIT(0))) + if (phy_is_c45(phydev) && + !(phydev->c45_ids.devices_in_package & BIT(0))) ret = genphy_c45_restart_aneg(phydev); else ret = genphy_restart_aneg(phydev); @@ -203,7 +204,7 @@ int phy_aneg_done(struct phy_device *phydev) { if (phydev->drv && phydev->drv->aneg_done) return phydev->drv->aneg_done(phydev); - else if (phydev->is_c45) + else if (phy_is_c45(phydev)) return genphy_c45_aneg_done(phydev); else return genphy_aneg_done(phydev); @@ -896,7 +897,8 @@ int phy_config_aneg(struct phy_device *phydev) /* Clause 45 PHYs that don't implement Clause 22 registers are not * allowed to call genphy_config_aneg() */ - if (phydev->is_c45 && !(phydev->c45_ids.devices_in_package & BIT(0))) + if (phy_is_c45(phydev) && + !(phydev->c45_ids.devices_in_package & BIT(0))) return genphy_c45_config_aneg(phydev); return genphy_config_aneg(phydev); diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 226d5507c865..660dca65f76f 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -533,7 +533,7 @@ static int phy_bus_match(struct device *dev, struct device_driver *drv) if (phydrv->match_phy_device) return phydrv->match_phy_device(phydev); - if (phydev->is_c45) { + if (phy_is_c45(phydev)) { for (i = 1; i < num_ids; i++) { if (phydev->c45_ids.device_ids[i] == 0xffffffff) continue; @@ -1452,7 +1452,7 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, * exist, and we should use the genphy driver. */ if (!d->driver) { - if (phydev->is_c45) + if (phy_is_c45(phydev)) d->driver = &genphy_c45_driver.mdiodrv.driver; else d->driver = &genphy_driver.mdiodrv.driver; @@ -3227,7 +3227,7 @@ static int phy_probe(struct device *dev) } else if (phydrv->get_features) err = phydrv->get_features(phydev); - else if (phydev->is_c45) + else if (phy_is_c45(phydev)) err = genphy_c45_pma_read_abilities(phydev); else err = genphy_read_abilities(phydev); diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 97c15e1f81de..eeac36176960 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -1703,7 +1703,7 @@ static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy, * against all interface modes, which may lead to more ethtool link * modes being advertised than are actually supported. */ - if (phy->is_c45 && config.rate_matching == RATE_MATCH_NONE && + if (phy_is_c45(phy) && config.rate_matching == RATE_MATCH_NONE && interface != PHY_INTERFACE_MODE_RXAUI && interface != PHY_INTERFACE_MODE_XAUI && interface != PHY_INTERFACE_MODE_USXGMII) @@ -2650,7 +2650,7 @@ static int phylink_phy_read(struct phylink *pl, unsigned int phy_id, reg); } - if (phydev->is_c45) { + if (phy_is_c45(phydev)) { switch (reg) { case MII_BMCR: case MII_BMSR: @@ -2692,7 +2692,7 @@ static int phylink_phy_write(struct phylink *pl, unsigned int phy_id, reg, val); } - if (phydev->is_c45) { + if (phy_is_c45(phydev)) { switch (reg) { case MII_BMCR: case MII_BMSR: @@ -3165,8 +3165,8 @@ static void phylink_sfp_link_up(void *upstream) */ static bool phylink_phy_no_inband(struct phy_device *phy) { - return phy->is_c45 && phy_id_compare(phy->c45_ids.device_ids[1], - 0xae025150, 0xfffffff0); + return phy_is_c45(phy) && phy_id_compare(phy->c45_ids.device_ids[1], + 0xae025150, 0xfffffff0); } static int phylink_sfp_connect_phy(void *upstream, struct phy_device *phy) diff --git a/include/linux/phy.h b/include/linux/phy.h index 9521b815d3f0..787bfe8e5c45 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -766,6 +766,11 @@ static inline struct phy_device *to_phy_device(const struct device *dev) return container_of(to_mdio_device(dev), struct phy_device, mdio); } +static inline bool phy_is_c45(struct phy_device *phydev) +{ + return phydev->is_c45; +} + /** * struct phy_tdr_config - Configuration of a TDR raw test * From patchwork Fri Jun 23 10:29:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 112061 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5683694vqr; Fri, 23 Jun 2023 04:02:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Idpq+TTbHJ1GonQfccebp73T5slhoKaliUzSarp8ymMkfReJkD0IMNz87kfXxd1szqAy6 X-Received: by 2002:a17:90a:e385:b0:25e:e70f:423f with SMTP id b5-20020a17090ae38500b0025ee70f423fmr23420216pjz.19.1687518161526; Fri, 23 Jun 2023 04:02:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687518161; cv=none; d=google.com; s=arc-20160816; b=TnnadYYbjNQT9UIzZePe71P2GsGUpqHbBKuvhvUohYQRYflPXhIdfP6XU6YgIKXCDX wiT+ER2uS8/ry3rjZgDkNi4LTPlw4fBW87APN0aBnhNlhgjPhpTIa74B7Fo8xDoqQ0Qv lwvdepqVWcWqmV+hSSYwBalSz/QIu6u/BTfkupDd/ZSmEecH9aUEADZ/fmeDr/mij3nb z03g5rOsZEUH0JAOCpLIzzCXmpug368AK5LeZ08ujVRRGJBDrhz/PieNrFtg+5M6vBMn aSMzrW8NwnI7ZKTl/yyF5RHg1M8qcGbbvAxdqHHzH1DNdBLMdJheGgmVxmoh39qBqVSe sIUw== 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=N/RO18laRP3Jg0XIfTWt+vFS9KeLPGTx829iSVKVro4=; b=PUiITtPGVAX4Z2QZDBfcOVab0MYDl3hQNtbi0xFsG26OpVY0UWswcU78rbfkIKJR3H mChQORHXBu96cmfcBBsbI0T4vulMuG7u6wFmRKRALz9LnN5z51wNyxNvmDZjFpZDckdP 5j/nn2RtzJKnjYtg8bkiH2JFwbGJg506qbGXN6TCfsqJ32HC6pDJyq1XzDXNcMsbm3Cc +ByKRBPBOSvCTSIvLTzbfsdLH+29IuPKJe3IJfF6nrxwNhElftIVmntHhY5692tcBkiD yeiDo3/hVoSLLDzBAYe8KyZkfXxtXpNrW9c+MR3Qn3mXx4bVNxLAfTvJJ0ok61a24jMT xApw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HNfoafwU; 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 17-20020a630011000000b0053eef60f940si8360409pga.765.2023.06.23.04.02.26; Fri, 23 Jun 2023 04:02:41 -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=HNfoafwU; 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 S232011AbjFWKaM (ORCPT + 99 others); Fri, 23 Jun 2023 06:30:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232210AbjFWK3m (ORCPT ); Fri, 23 Jun 2023 06:29:42 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CC07211D for ; Fri, 23 Jun 2023 03:29:36 -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 BFD5A61A17 for ; Fri, 23 Jun 2023 10:29:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55C08C433C8; Fri, 23 Jun 2023 10:29:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687516175; bh=ehSuoLZghcZW1yKiUB0M1IR3WQ5jy4tA9bTfMTbRBDI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=HNfoafwUCHzTITdApnHi/iZO3PsmhY198i7gYphSIX23mdcCtn7+xzYt3DSk2CygX Kw2YVlw+CttucssWUlhgSwSyF8kIgDBxkhcJFz/KoaDSZfrnvpT0muhU7iiWhjx2ch 1Qe81SEGRgXsubV3ohPR7jqc4lde6/pNKroV03WXHWEkeGSm97VeZdYbeqeEimwZzq YhlsmHLYvj5yPU6F7Yy8rdvJeEmkCuroGLB8AShYS+1KKp2wkETfkRvqkkh7Y77IU0 6yfT2YQmk6xGy4N769VrI+3R3I9FwAj+hjp5EPhuRVs0F/WbIRGtXyQBxYAr3zzmrQ +VERbxJuRaDSQ== From: Michael Walle Date: Fri, 23 Jun 2023 12:29:13 +0200 Subject: [PATCH net-next v2 04/10] net: phy: replace is_c45 with phy_accces_mode MIME-Version: 1.0 Message-Id: <20230620-feature-c45-over-c22-v2-4-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=-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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769491043837990522?= X-GMAIL-MSGID: =?utf-8?q?1769491043837990522?= Instead of tracing whether the PHY is a C45 one, use the method how the PHY is accessed. For now, that is either by C22 or by C45 transactions. There is no functional change, just a semantical difference. This is a preparation patch to add a third access method C45-over-C22. Signed-off-by: Michael Walle --- drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c | 8 +++--- drivers/net/mdio/fwnode_mdio.c | 6 ++-- drivers/net/phy/mdio_bus.c | 9 +++--- drivers/net/phy/nxp-tja11xx.c | 3 +- drivers/net/phy/phy_device.c | 34 +++++++++++++++-------- drivers/net/phy/sfp.c | 12 ++++---- include/linux/phy.h | 28 ++++++++++++++----- 7 files changed, 66 insertions(+), 34 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c index 928d934cb21a..74cd6197735b 100644 --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c @@ -687,9 +687,9 @@ static int hns_mac_register_phydev(struct mii_bus *mdio, struct hns_mac_cb *mac_cb, u32 addr) { + enum phy_access_mode mode; struct phy_device *phy; const char *phy_type; - bool is_c45; int rc; rc = fwnode_property_read_string(mac_cb->fw_port, @@ -698,13 +698,13 @@ hns_mac_register_phydev(struct mii_bus *mdio, struct hns_mac_cb *mac_cb, return rc; if (!strcmp(phy_type, phy_modes(PHY_INTERFACE_MODE_XGMII))) - is_c45 = true; + mode = PHY_ACCESS_C45; else if (!strcmp(phy_type, phy_modes(PHY_INTERFACE_MODE_SGMII))) - is_c45 = false; + mode = PHY_ACCESS_C22; else return -ENODATA; - phy = get_phy_device(mdio, addr, is_c45); + phy = get_phy_device(mdio, addr, mode); if (!phy || IS_ERR(phy)) return -EIO; diff --git a/drivers/net/mdio/fwnode_mdio.c b/drivers/net/mdio/fwnode_mdio.c index 1183ef5e203e..972c8932c2fe 100644 --- a/drivers/net/mdio/fwnode_mdio.c +++ b/drivers/net/mdio/fwnode_mdio.c @@ -131,9 +131,11 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, is_c45 = fwnode_device_is_compatible(child, "ethernet-phy-ieee802.3-c45"); if (is_c45 || fwnode_get_phy_id(child, &phy_id)) - phy = get_phy_device(bus, addr, is_c45); + phy = get_phy_device(bus, addr, + is_c45 ? PHY_ACCESS_C45 : PHY_ACCESS_C22); else - phy = phy_device_create(bus, addr, phy_id, 0, NULL); + phy = phy_device_create(bus, addr, phy_id, PHY_ACCESS_C22, + NULL); if (IS_ERR(phy)) { rc = PTR_ERR(phy); goto clean_mii_ts; diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index 8b3618d3da4a..a31eb1204f63 100644 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c @@ -513,12 +513,13 @@ static int mdiobus_create_device(struct mii_bus *bus, return ret; } -static struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr, bool c45) +static struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr, + enum phy_access_mode mode) { struct phy_device *phydev = ERR_PTR(-ENODEV); int err; - phydev = get_phy_device(bus, addr, c45); + phydev = get_phy_device(bus, addr, mode); if (IS_ERR(phydev)) return phydev; @@ -550,7 +551,7 @@ static struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr, bool c45) */ struct phy_device *mdiobus_scan_c22(struct mii_bus *bus, int addr) { - return mdiobus_scan(bus, addr, false); + return mdiobus_scan(bus, addr, PHY_ACCESS_C22); } EXPORT_SYMBOL(mdiobus_scan_c22); @@ -568,7 +569,7 @@ EXPORT_SYMBOL(mdiobus_scan_c22); */ static struct phy_device *mdiobus_scan_c45(struct mii_bus *bus, int addr) { - return mdiobus_scan(bus, addr, true); + return mdiobus_scan(bus, addr, PHY_ACCESS_C45); } static int mdiobus_scan_bus_c22(struct mii_bus *bus) diff --git a/drivers/net/phy/nxp-tja11xx.c b/drivers/net/phy/nxp-tja11xx.c index b13e15310feb..1c6c1523540e 100644 --- a/drivers/net/phy/nxp-tja11xx.c +++ b/drivers/net/phy/nxp-tja11xx.c @@ -580,7 +580,8 @@ static void tja1102_p1_register(struct work_struct *work) } /* Real PHY ID of Port 1 is 0 */ - phy = phy_device_create(bus, addr, PHY_ID_TJA1102, false, NULL); + phy = phy_device_create(bus, addr, PHY_ID_TJA1102, + PHY_ACCESS_C22, NULL); if (IS_ERR(phy)) { dev_err(dev, "Can't create PHY device for Port 1: %i\n", addr); diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 660dca65f76f..4fd095282ef7 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -630,7 +630,7 @@ static int phy_request_driver_module(struct phy_device *dev, u32 phy_id) } struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id, - bool is_c45, + enum phy_access_mode mode, struct phy_c45_device_ids *c45_ids) { struct phy_device *dev; @@ -664,7 +664,7 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id, dev->autoneg = AUTONEG_ENABLE; dev->pma_extable = -ENODATA; - dev->is_c45 = is_c45; + dev->access_mode = mode; dev->phy_id = phy_id; if (c45_ids) dev->c45_ids = *c45_ids; @@ -926,7 +926,7 @@ EXPORT_SYMBOL(fwnode_get_phy_id); * struct * @bus: the target MII bus * @addr: PHY address on the MII bus - * @is_c45: If true the PHY uses the 802.3 clause 45 protocol + * @mode: Access mode of the PHY * * Probe for a PHY at @addr on @bus. * @@ -937,10 +937,16 @@ EXPORT_SYMBOL(fwnode_get_phy_id); * If the "devices in package" appears valid, read the ID registers for each * MMD, allocate and return a &struct phy_device. * + * When using %PHY_ACCESS_C45_OVER_C22 as @mode care have to be taken to not + * access a non-PHY device as C45-over-C22 is a property of a PHY and not a + * generic MDIO device. As the access involves register writes, it may be + * destructive on non-PHY devices. IOW, it cannot be used for bus scanning. + * * Returns an allocated &struct phy_device on success, %-ENODEV if there is * no PHY present, or %-EIO on bus access error. */ -struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45) +struct phy_device *get_phy_device(struct mii_bus *bus, int addr, + enum phy_access_mode mode) { struct phy_c45_device_ids c45_ids; u32 phy_id = 0; @@ -950,10 +956,16 @@ struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45) c45_ids.mmds_present = 0; memset(c45_ids.device_ids, 0xff, sizeof(c45_ids.device_ids)); - if (is_c45) - r = get_phy_c45_ids(bus, addr, &c45_ids); - else + switch (mode) { + case PHY_ACCESS_C22: r = get_phy_c22_id(bus, addr, &phy_id); + break; + case PHY_ACCESS_C45: + r = get_phy_c45_ids(bus, addr, &c45_ids); + break; + default: + return ERR_PTR(-EIO); + } if (r) return ERR_PTR(r); @@ -963,15 +975,15 @@ struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45) * probe with C45 to see if we're able to get a valid PHY ID in the C45 * space, if successful, create the C45 PHY device. */ - if (!is_c45 && phy_id == 0 && bus->read_c45) { + if (mode == PHY_ACCESS_C22 && phy_id == 0 && bus->read_c45) { r = get_phy_c45_ids(bus, addr, &c45_ids); if (!r) return phy_device_create(bus, addr, phy_id, - true, &c45_ids); + PHY_ACCESS_C45, &c45_ids); } - return phy_device_create(bus, addr, phy_id, is_c45, - !is_c45 ? NULL : &c45_ids); + return phy_device_create(bus, addr, phy_id, mode, + mode == PHY_ACCESS_C22 ? NULL : &c45_ids); } EXPORT_SYMBOL(get_phy_device); diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c index d855a18308d7..e7f8decaf3ff 100644 --- a/drivers/net/phy/sfp.c +++ b/drivers/net/phy/sfp.c @@ -1750,12 +1750,13 @@ static void sfp_sm_phy_detach(struct sfp *sfp) sfp->mod_phy = NULL; } -static int sfp_sm_probe_phy(struct sfp *sfp, int addr, bool is_c45) +static int sfp_sm_probe_phy(struct sfp *sfp, int addr, + enum phy_access_mode mode) { struct phy_device *phy; int err; - phy = get_phy_device(sfp->i2c_mii, addr, is_c45); + phy = get_phy_device(sfp->i2c_mii, addr, mode); if (phy == ERR_PTR(-ENODEV)) return PTR_ERR(phy); if (IS_ERR(phy)) { @@ -1879,15 +1880,16 @@ static int sfp_sm_probe_for_phy(struct sfp *sfp) break; case MDIO_I2C_MARVELL_C22: - err = sfp_sm_probe_phy(sfp, SFP_PHY_ADDR, false); + err = sfp_sm_probe_phy(sfp, SFP_PHY_ADDR, PHY_ACCESS_C22); break; case MDIO_I2C_C45: - err = sfp_sm_probe_phy(sfp, SFP_PHY_ADDR, true); + err = sfp_sm_probe_phy(sfp, SFP_PHY_ADDR, PHY_ACCESS_C45); break; case MDIO_I2C_ROLLBALL: - err = sfp_sm_probe_phy(sfp, SFP_PHY_ADDR_ROLLBALL, true); + err = sfp_sm_probe_phy(sfp, SFP_PHY_ADDR_ROLLBALL, + PHY_ACCESS_C45); break; } diff --git a/include/linux/phy.h b/include/linux/phy.h index 787bfe8e5c45..12679bbd4b91 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -531,6 +531,17 @@ struct phy_c45_device_ids { struct macsec_context; struct macsec_ops; +/** + * enum phy_access_mode - PHY register access mode definitions + * + * @PHY_ACCESS_C22: use 802.3 c22 MDIO transactions + * @PHY_ACCESS_C45: use 802.3 c45 MDIO transactions + */ +enum phy_access_mode { + PHY_ACCESS_C22, + PHY_ACCESS_C45, +}; + /** * struct phy_device - An instance of a PHY * @@ -539,8 +550,8 @@ struct macsec_ops; * @devlink: Create a link between phy dev and mac dev, if the external phy * used by current mac interface is managed by another mac interface. * @phy_id: UID for this device found during discovery - * @c45_ids: 802.3-c45 Device Identifiers if is_c45. - * @is_c45: Set to true if this PHY uses clause 45 addressing. + * @access_mode: MDIO access mode of the PHY. + * @c45_ids: 802.3-c45 Device Identifiers if it's an C45 PHY. * @is_internal: Set to true if this PHY is internal to a MAC. * @is_pseudo_fixed_link: Set to true if this PHY is an Ethernet switch, etc. * @is_gigabit_capable: Set to true if PHY supports 1000Mbps @@ -637,8 +648,9 @@ struct phy_device { u32 phy_id; + enum phy_access_mode access_mode; + struct phy_c45_device_ids c45_ids; - unsigned is_c45:1; unsigned is_internal:1; unsigned is_pseudo_fixed_link:1; unsigned is_gigabit_capable:1; @@ -768,7 +780,7 @@ static inline struct phy_device *to_phy_device(const struct device *dev) static inline bool phy_is_c45(struct phy_device *phydev) { - return phydev->is_c45; + return phydev->access_mode != PHY_ACCESS_C22; } /** @@ -1626,7 +1638,7 @@ int phy_modify_paged(struct phy_device *phydev, int page, u32 regnum, u16 mask, u16 set); struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id, - bool is_c45, + enum phy_access_mode mode, struct phy_c45_device_ids *c45_ids); #if IS_ENABLED(CONFIG_PHYLIB) int fwnode_get_phy_id(struct fwnode_handle *fwnode, u32 *phy_id); @@ -1634,7 +1646,8 @@ struct mdio_device *fwnode_mdio_find_device(struct fwnode_handle *fwnode); struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode); struct phy_device *device_phy_find_device(struct device *dev); struct fwnode_handle *fwnode_get_phy_node(const struct fwnode_handle *fwnode); -struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45); +struct phy_device *get_phy_device(struct mii_bus *bus, int addr, + enum phy_access_mode mode); int phy_device_register(struct phy_device *phy); void phy_device_free(struct phy_device *phydev); #else @@ -1666,7 +1679,8 @@ struct fwnode_handle *fwnode_get_phy_node(struct fwnode_handle *fwnode) } static inline -struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45) +struct phy_device *get_phy_device(struct mii_bus *bus, int addr, + enum phy_access_mode mode) { return NULL; } From patchwork Fri Jun 23 10:29:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 112067 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5690444vqr; Fri, 23 Jun 2023 04:13:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6JfXdSsvlPAiR5bW/I3PxHZ00ARq7MEXSSXloWDjOnOBE/eC0CcEZYYv0Qo5R4U/JrzMGn X-Received: by 2002:a05:6a20:8e1b:b0:122:231c:32d6 with SMTP id y27-20020a056a208e1b00b00122231c32d6mr11935528pzj.61.1687518799716; Fri, 23 Jun 2023 04:13:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687518799; cv=none; d=google.com; s=arc-20160816; b=oSC8t9/rr+K8YImkaN0CGO8+c9cc/+jBFk/xdMt7ZgvIbcKZpNml10xNnhmCpw/gNV F2IujU/nAx9w6v3j5yMTFcDAsFZhz5aWZfk2sfHLrsk/6+bWphIaauon5u5rJu7RWbyF IKYALoRDY1ewRz9ZFU5ilAoHjn9YrgbBWjzPnu2xnGRMzVwqvGR5GVJUtZaj4w5P32PD uZ7E8isGNHaKfqcI/d763DW1WyDkGRUKxyG2Pdj1QoCmQ54/xkojCcj8jNUoYenkP4pA SPBT2yB93kcid8Ij9NSz/gw3IpDVPsNVzdhWGYkUtWGr4lkDPmfuNQJc+hWMNKY9GsWM Fftg== 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=uMfFqlSsIdXxH6teq+gKlgFk8RwGx24Z/+Pl6A49pEc=; b=mEKPiFOupO1FnvnqyjmP0FQRNfjBlwu89Ic1q6Sy94S7cGyXbsk8lUzMYfTJaXTJSe 5m1Hds5Ui1QAnLDbUjj/vPVCq/BrcuqzJZLBObFZeg98vLE4AcEQ2hz1xJ/7Vds7IuGD R2k0S5bAzMf0DR7hRjc8czd6PMneogRtlah9bP4AXJeGyJPrrQ9nx4GRyXpu38/jLCyu tMzBxfwNj1UnXNwGNLqUHiFb2zK/oPl5XfeE/8jJhMDaKQ4JuHQWDQw+/CRU3ABifjyP qZU0r82HgjeD8f3qzigUREMYtEFsu8e2uKLm89iKatpd0tfIloZJrby6pfn1/TsaQqP4 ihOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vM0BLBkK; 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 x28-20020aa7941c000000b00666b95e38efsi580045pfo.34.2023.06.23.04.13.07; Fri, 23 Jun 2023 04:13:19 -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=vM0BLBkK; 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 S232244AbjFWKaT (ORCPT + 99 others); Fri, 23 Jun 2023 06:30:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232228AbjFWK3s (ORCPT ); Fri, 23 Jun 2023 06:29:48 -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 EBE541724 for ; Fri, 23 Jun 2023 03:29:39 -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 6BF1761A09 for ; Fri, 23 Jun 2023 10:29:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99EE3C43391; Fri, 23 Jun 2023 10:29:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687516178; bh=UYZUmCUG6Xzc7GFPwcyPMr7KaNM/T/mzCRnwUpgMqIo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=vM0BLBkK1qYdn9gOMmCqu8TmveJYxYF8Qz5PL9sng1jk+gB3zqFZMhLffjYkprNrd nn0Nxikr78IjN0CsNZGEi9URT/at1SPUj0Ya5P9AAXzPBw6YLtrAQYmMHbQ/YQNhR/ VL7Ih4nfg+OaqCVGNl49FR6cUfC/HkLnLqckeR5oNSSoVxeVSmYzAdt37Tb/CFFTNA Si2ys2zP54jJdcXPu04yVIC4oclxO/bJp2MzlFXzGeWhzibe81S4ZjMBrbcgmbL1/J KVGNxDyvCQBD8vDfSb8ylHgntcr8dipyAvwmVAFmQ98+Zx0Xwpt24x62FTBbUDZqVs ICFsWoQ+P6cdw== From: Michael Walle Date: Fri, 23 Jun 2023 12:29:14 +0200 Subject: [PATCH net-next v2 05/10] net: phy: make the "prevent_c45_scan" a property of the MII bus MIME-Version: 1.0 Message-Id: <20230620-feature-c45-over-c22-v2-5-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?1769491712962652714?= X-GMAIL-MSGID: =?utf-8?q?1769491712962652714?= The blacklist will also be used elsewhere in the kernel, e.g. in the DT scanning code. Make it a property of mii_bus and export the function. Signed-off-by: Michael Walle --- drivers/net/phy/mdio_bus.c | 17 ++++++++--------- include/linux/phy.h | 5 +++++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index a31eb1204f63..00b25f6803bc 100644 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c @@ -613,9 +613,9 @@ static int mdiobus_scan_bus_c45(struct mii_bus *bus) * 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. + * should prohibit any C45 transactions. */ -static bool mdiobus_prevent_c45_scan(struct mii_bus *bus) +void mdiobus_scan_for_broken_c45_access(struct mii_bus *bus) { int i; @@ -628,10 +628,11 @@ static bool mdiobus_prevent_c45_scan(struct mii_bus *bus) continue; oui = phydev->phy_id >> 10; - if (oui == MICREL_OUI) - return true; + if (oui == MICREL_OUI) { + bus->prevent_c45_access = true; + break; + } } - return false; } /** @@ -652,7 +653,6 @@ int __mdiobus_register(struct mii_bus *bus, struct module *owner) { struct mdio_device *mdiodev; struct gpio_desc *gpiod; - bool prevent_c45_scan; int i, err; if (!bus || !bus->name) @@ -724,9 +724,8 @@ int __mdiobus_register(struct mii_bus *bus, struct module *owner) goto error; } - prevent_c45_scan = mdiobus_prevent_c45_scan(bus); - - if (!prevent_c45_scan && bus->read_c45) { + mdiobus_scan_for_broken_c45_access(bus); + if (!bus->prevent_c45_access && bus->read_c45) { err = mdiobus_scan_bus_c45(bus); if (err) goto error; diff --git a/include/linux/phy.h b/include/linux/phy.h index 12679bbd4b91..a7aff91f4eb0 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -410,6 +410,9 @@ struct mii_bus { /** @phy_ignore_ta_mask: PHY addresses to ignore the TA/read failure */ u32 phy_ignore_ta_mask; + /** @prevent_c45_access: Don't do any C45 transactions on the bus */ + unsigned prevent_c45_access:1; + /** * @irq: An array of interrupts, each PHY's interrupt at the index * matching its address @@ -462,6 +465,8 @@ static inline struct mii_bus *devm_mdiobus_alloc(struct device *dev) struct mii_bus *mdio_find_bus(const char *mdio_name); struct phy_device *mdiobus_scan_c22(struct mii_bus *bus, int addr); +void mdiobus_scan_for_broken_c45_access(struct mii_bus *bus); + #define PHY_INTERRUPT_DISABLED false #define PHY_INTERRUPT_ENABLED true From patchwork Fri Jun 23 10:29:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 112064 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5689736vqr; Fri, 23 Jun 2023 04:12:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7REi89xdjbDtX570jcLrhKGkfdZU1so8ByY91XTNOwEVcV+A64wR7HSNFqiWLCNJL1R29T X-Received: by 2002:a05:6a20:8f0b:b0:107:1805:feea with SMTP id b11-20020a056a208f0b00b001071805feeamr28004356pzk.37.1687518726697; Fri, 23 Jun 2023 04:12:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687518726; cv=none; d=google.com; s=arc-20160816; b=0MpeyamzbVWncpVboBs/oCpFr0ydKE8r/NHLLpyv64LBSq02XTO9D0NgwYDrDUUrv7 a2Gv81zbS0dlfqvjq9LcgVyFBi0dUlvtnaGsYfSlpIMzhxkdl6jJ5Wdn+PP2blsUOKR+ NZ25jMeWY40IL80iMT1i5JlKdIzL3xbVnXsasIwt9c/4wq705x/a/K9uNrp4lsjmvCcx uY0rUj0WUqkkq4nbpDdbfNQ0fLmpU6hLZrSByA5aMStJs8y1wjf7UTpZ8+Jfhek4TWkJ YbEayFwpJogKMEcpiFiQPnOCRNR2hNhm3ttWTtHsGNtB+g+iWP+ZeUv7MlbFz1MW3OWc qtjA== 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=aKdR3QPmyq7+6EljlQ451QSp3/scHw5pWGCh06IzL+Q=; b=I8sGbjrP2+Snxt/IgZHhPQx0u2xsca0HdT55Q4dLV66VEJ6tRiwVPp3sNKZKxjCz8o Fp1Fi2poWuSM8kzxMbCdNSDGsjKNwmDvQRXoqX8JkluEWftD6tP3I6HjySW8kxpQWHJo RPrgwoUHu4nA8lKG6GoWo+p9DodgUzsi4bl1Bpf0hlb0Dx0TAIGn5KSUP+F/k7LYF74J q/IZvH3nsDx9BUIeVGxGLx52Ue1TTR8KZM6pZrIzOq6rG7vWqK86hvvA5bSepe71R3kS poJOhloL4camq+Xgh9wL1ZJhlVvoWHGrJ7rvzWjJbJ88pCdpWr5ULYvjfH8/exOFNAJe 1gaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Fg6wduN5; 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 17-20020a630011000000b0053eef60f940si8360409pga.765.2023.06.23.04.11.45; Fri, 23 Jun 2023 04:12:06 -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=Fg6wduN5; 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 S232266AbjFWKaX (ORCPT + 99 others); Fri, 23 Jun 2023 06:30:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232276AbjFWK34 (ORCPT ); Fri, 23 Jun 2023 06:29:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E7BF1BCA for ; Fri, 23 Jun 2023 03:29:43 -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 1351F61A18 for ; Fri, 23 Jun 2023 10:29:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46DF5C433CC; Fri, 23 Jun 2023 10:29:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687516182; bh=1muRLOb59+kQ7ZeXLBMZWXmkOisk9F6Bf+D/rqGDwuY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Fg6wduN550kCKQZAgcUK+qaSxIyBJvy3NpfG7LFBjHOeAxveVY2qfyTrz2SYTMYok V9yn8w0v64hHHiyJx+/fThXbsPsHutp/n8hsSi5SMYEIjOGK7w/qZFfzbMtzBX1iTE 29nL8rlcN2obNqdLHbi5OzZRLRIie1wjFJqC7qN6U6kVIaOy/hCRiEk6wu2b0fePP7 D/kwRdTlPoDZ+t4LzMymI/5K5LWgCcR0jpt/8U5pI7RJI2Y89s57LurgxGWmq0bYYx G/weE/QDJSfjzcCEDCxb815JI2ABvpdqcRO+qIXgrxyLIBUbxw8rXN2aqyO4nBjcnF WHOJX1er4qZUg== From: Michael Walle Date: Fri, 23 Jun 2023 12:29:15 +0200 Subject: [PATCH net-next v2 06/10] net: phy: print an info if a broken C45 bus is found MIME-Version: 1.0 Message-Id: <20230620-feature-c45-over-c22-v2-6-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=-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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769491636843657104?= X-GMAIL-MSGID: =?utf-8?q?1769491636843657104?= If there is an PHY which gets confused by C45 transactions on the MDIO bus, print an info together with the PHY identifier of the offending one. Signed-off-by: Michael Walle --- I wasn't sure if this should be phydev_dbg() or phydev_info(). I mainly see this as an info to a user why some PHYs might not be probed (or c45-over-c22 is used later). --- drivers/net/phy/mdio_bus.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index 00b25f6803bc..38529add6420 100644 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c @@ -617,10 +617,10 @@ static int mdiobus_scan_bus_c45(struct mii_bus *bus) */ void mdiobus_scan_for_broken_c45_access(struct mii_bus *bus) { + struct phy_device *phydev; int i; for (i = 0; i < PHY_MAX_ADDR; i++) { - struct phy_device *phydev; u32 oui; phydev = mdiobus_get_phy(bus, i); @@ -633,6 +633,11 @@ void mdiobus_scan_for_broken_c45_access(struct mii_bus *bus) break; } } + + if (bus->prevent_c45_access) + dev_info(&bus->dev, + "Detected broken PHY (ID %08lx). Disabling C45 bus transactions.\n", + (unsigned long)phydev->phy_id); } /** From patchwork Fri Jun 23 10:29:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 112066 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5689927vqr; Fri, 23 Jun 2023 04:12:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4tfessJ/O1uDs7D58BYaxN1bDl1q6Q7b5pfjgDxU38wuaHN3tqlRTlfjbXXJOewp1dWbsf X-Received: by 2002:a05:6a00:1995:b0:668:9f05:29db with SMTP id d21-20020a056a00199500b006689f0529dbmr8763885pfl.3.1687518746667; Fri, 23 Jun 2023 04:12:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687518746; cv=none; d=google.com; s=arc-20160816; b=r9eVhGnSqqkfBqBlIDsg/ArMHaPUCTII0DVxpLlC9kDakd761af5OGf608mw4AoRJq CPzId1f94YOwdfFK0mCOA03oKJS8NTaiq6KyxeV6aYXR/XiLXkpnx49BDnIsFz9mz3Ot mvq0GxvI/1zNGDwbb0OOQXny1NZeMrQLJkLq7qTtzFdh3jTN0aTV/8s+JU6xVvtYX+0C XHQtyHevK8BjjcJJc//Bg9evEIym1RhPom1IscZFqASZN8ZGrkvKKaLQ01HFOkb4ZIKu nWcUgCLVqJlYAOS1HIkPd/XWz0nnwc1SSAphZHNcmjDdD0+7yH9Eo6huHuyH0KlNzJa4 GuLg== 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=scKxl37pgyuRxLjld2f0PEbiH1bStl+VFq6NZqHi9Ts=; b=rQ9PtN1iPzYemQ+ESZzdaRvLIuDKm/Z1hTVWowDCGhWKmpwd+fOZxB5BsGFnIdoLb7 lnb4VZrD5j9kaW4rN6YvH0A9BYU4gzHE72QMi4b5E6DoMv1qwWRqkLBCTlJzWZGlP6Nh em5nAqVgXpWN4prtHS+j1tOI3+mAct87hmutxOoJ4D5l+oYl7ouhjB1+vzDEPq0zu8aw tAqKFdisz8ks3TKYdXbKp5X7XG33j7Gr0VrmcAzJeBRLTKeZI22sFmsAvu9E9Gr7IG/T xqZtcFicmnbhjMYqfZsqP0Qjy4BrpX3LpsD6UhqrIInGauY7uYAKaelDaMgKPIKFSSHY Fzhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CjeB60KX; 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 a4-20020aa795a4000000b00654355ac8a5si8285157pfk.56.2023.06.23.04.12.13; Fri, 23 Jun 2023 04:12:26 -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=CjeB60KX; 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 S232203AbjFWKa2 (ORCPT + 99 others); Fri, 23 Jun 2023 06:30:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232367AbjFWKaG (ORCPT ); Fri, 23 Jun 2023 06:30:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41FFC2703 for ; Fri, 23 Jun 2023 03:29:47 -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 ADBC161A11 for ; Fri, 23 Jun 2023 10:29:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9985C433C0; Fri, 23 Jun 2023 10:29:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687516186; bh=nhfXPWVT6hYc2KxtGUneaAM4Ns1ERr4nJhfqHxksMjA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=CjeB60KXr6Ja0lTREdGBW7QOmoKBYVj5y8NJlY+i10h+8lEVZmKfAqCfrG9TsJYgY 6v+jiiIiCKqnK9X0UmwhNzewutJpXk44NdP5B373WchEzsq6nBtzsS53EUhFIR7+y9 O7m/wKHJsPTBhsH64k23kayeOXa8w+esriNF0ENpz9zv8Tz32RUWxNzA2twICKCCBc t3hm6U7IUCxVkWSsuWeKqqLxCXsqHqcjmWpGrwARrz1Y1zHPu5QeFZS1F+No9L9VSz bDCPb37qG8nzUy0bhvJJd1dVXTmsWg0h4ulYNUcBcVjPpLNg6pFk6wRDaKygS3OufZ IYcKb54WH3rrQ== From: Michael Walle Date: Fri, 23 Jun 2023 12:29:16 +0200 Subject: [PATCH net-next v2 07/10] net: phy: add support for C45-over-C22 transfers MIME-Version: 1.0 Message-Id: <20230620-feature-c45-over-c22-v2-7-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=-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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769491657454434060?= X-GMAIL-MSGID: =?utf-8?q?1769491657454434060?= If an MDIO bus is only capable of doing C22 transfers we can use indirect accesses to C45 registers over C22 registers. This was already the intention of the GPY215 driver. The author described their use case as follows: Our product supports both C22 and C45. In the real system, we found C22 was used by customers (with indirect access to C45 registers when necessary). In its probe function phy_get_c45_ids() is called but this will always do C45 accesses and thus will fail on a C22-only bus. Add a new transfer mode C45-over-C22. Care has to be taken for get_phy_device() which is called by either the bus scanning code or the network device drivers. In the former case, we must not do any C45-over-C22 accesses because it invokes register writes and we cannot be sure if the accessed device is a PHY. C45-over-C22 is just defined for network PHYs, not generic MDIO devices. Therefore, the it is the callers responsibility to choose the access mode for get_phy_device(). Due to the reasons above, the current scanning code the PHY core cannot make use of the new transfer mode because we cannot be sure what device is a PHY. The code will be used for the device tree scanning where we know which device is a PHY and therefore, C45-over-C22 is safe to use. A word on the error checking in the MMD access methods: due to legacy reasons, we cannot check for errors if we do "normal" MMD access to a C22 PHY without introducing possible regressions. Although, C45-over-C22 is doing essentially the same access, we can do better now and check for any errors while doing the indirect access. Signed-off-by: Michael Walle --- drivers/net/phy/phy-core.c | 67 +++++++++++++++++++++++++++----------------- drivers/net/phy/phy_device.c | 66 +++++++++++++++++++++++++++++++++---------- include/linux/phy.h | 3 ++ 3 files changed, 95 insertions(+), 41 deletions(-) diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c index 5f73d27fe330..57062574ca04 100644 --- a/drivers/net/phy/phy-core.c +++ b/drivers/net/phy/phy-core.c @@ -575,26 +575,34 @@ EXPORT_SYMBOL(__phy_mmd_indirect); */ int __phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum) { - int val; + struct mii_bus *bus = phydev->mdio.bus; + int phy_addr = phydev->mdio.addr; + bool check_rc = true; + int ret; if (regnum > (u16)~0 || devad > 32) return -EINVAL; - if (phydev->drv && phydev->drv->read_mmd) { - val = phydev->drv->read_mmd(phydev, devad, regnum); - } else if (phy_is_c45(phydev)) { - val = __mdiobus_c45_read(phydev->mdio.bus, phydev->mdio.addr, - devad, regnum); - } else { - struct mii_bus *bus = phydev->mdio.bus; - int phy_addr = phydev->mdio.addr; - - mmd_phy_indirect(bus, phy_addr, devad, regnum, false); + if (phydev->drv && phydev->drv->read_mmd) + return phydev->drv->read_mmd(phydev, devad, regnum); + + switch (phydev->access_mode) { + case PHY_ACCESS_C45: + return __mdiobus_c45_read(bus, phy_addr, devad, regnum); + case PHY_ACCESS_C22: + /* ignore return value for legacy reasons */ + check_rc = false; + fallthrough; + case PHY_ACCESS_C45_OVER_C22: + ret = mmd_phy_indirect(bus, phy_addr, devad, regnum, check_rc); + if (check_rc && ret) + return ret; /* Read the content of the MMD's selected register */ - val = __mdiobus_read(bus, phy_addr, MII_MMD_DATA); + return __mdiobus_read(bus, phy_addr, MII_MMD_DATA); } - return val; + + return -EOPNOTSUPP; } EXPORT_SYMBOL(__phy_read_mmd); @@ -631,28 +639,35 @@ EXPORT_SYMBOL(phy_read_mmd); */ int __phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val) { + struct mii_bus *bus = phydev->mdio.bus; + int phy_addr = phydev->mdio.addr; + bool check_rc = true; int ret; if (regnum > (u16)~0 || devad > 32) return -EINVAL; - if (phydev->drv && phydev->drv->write_mmd) { - ret = phydev->drv->write_mmd(phydev, devad, regnum, val); - } else if (phy_is_c45(phydev)) { - ret = __mdiobus_c45_write(phydev->mdio.bus, phydev->mdio.addr, - devad, regnum, val); - } else { - struct mii_bus *bus = phydev->mdio.bus; - int phy_addr = phydev->mdio.addr; - - mmd_phy_indirect(bus, phy_addr, devad, regnum, false); + if (phydev->drv && phydev->drv->write_mmd) + return phydev->drv->write_mmd(phydev, devad, regnum, val); + + switch (phydev->access_mode) { + case PHY_ACCESS_C45: + return __mdiobus_c45_write(bus, phy_addr, devad, regnum, val); + case PHY_ACCESS_C22: + check_rc = false; + fallthrough; + case PHY_ACCESS_C45_OVER_C22: + ret = mmd_phy_indirect(bus, phy_addr, devad, regnum, check_rc); + if (check_rc && ret) + return ret; /* Write the data into MMD's selected register */ - __mdiobus_write(bus, phy_addr, MII_MMD_DATA, val); + ret = __mdiobus_write(bus, phy_addr, MII_MMD_DATA, val); - ret = 0; + return check_rc ? ret : 0; } - return ret; + + return -EOPNOTSUPP; } EXPORT_SYMBOL(__phy_write_mmd); diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 4fd095282ef7..13d5ec7a7c21 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -715,6 +715,28 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id, } EXPORT_SYMBOL(phy_device_create); +static int phy_probe_mmd_read(struct mii_bus *bus, int prtad, int devad, + u16 regnum, bool c45_over_c22) +{ + int ret; + + if (!c45_over_c22) + return mdiobus_c45_read(bus, prtad, devad, regnum); + + mutex_lock(&bus->mdio_lock); + + ret = __phy_mmd_indirect(bus, prtad, devad, regnum); + if (ret) + goto out; + + ret = __mdiobus_read(bus, prtad, MII_MMD_DATA); + +out: + mutex_unlock(&bus->mdio_lock); + + return ret; +} + /* phy_c45_probe_present - checks to see if a MMD is present in the package * @bus: the target MII bus * @prtad: PHY package address on the MII bus @@ -726,11 +748,13 @@ EXPORT_SYMBOL(phy_device_create); * Returns: negative error number on bus access error, zero if no device * is responding, or positive if a device is present. */ -static int phy_c45_probe_present(struct mii_bus *bus, int prtad, int devad) +static int phy_c45_probe_present(struct mii_bus *bus, int prtad, int devad, + bool c45_over_c22) { int stat2; - stat2 = mdiobus_c45_read(bus, prtad, devad, MDIO_STAT2); + stat2 = phy_probe_mmd_read(bus, prtad, devad, MDIO_STAT2, + c45_over_c22); if (stat2 < 0) return stat2; @@ -749,16 +773,18 @@ static int phy_c45_probe_present(struct mii_bus *bus, int prtad, int devad) * Returns: 0 on success, -EIO on failure. */ static int get_phy_c45_devs_in_pkg(struct mii_bus *bus, int addr, int dev_addr, - u32 *devices_in_package) + u32 *devices_in_package, bool c45_over_c22) { int phy_reg; - phy_reg = mdiobus_c45_read(bus, addr, dev_addr, MDIO_DEVS2); + phy_reg = phy_probe_mmd_read(bus, addr, dev_addr, MDIO_DEVS2, + c45_over_c22); if (phy_reg < 0) return -EIO; *devices_in_package = phy_reg << 16; - phy_reg = mdiobus_c45_read(bus, addr, dev_addr, MDIO_DEVS1); + phy_reg = phy_probe_mmd_read(bus, addr, dev_addr, MDIO_DEVS1, + c45_over_c22); if (phy_reg < 0) return -EIO; *devices_in_package |= phy_reg; @@ -780,7 +806,8 @@ static int get_phy_c45_devs_in_pkg(struct mii_bus *bus, int addr, int dev_addr, * the "devices in package" is invalid. */ static int get_phy_c45_ids(struct mii_bus *bus, int addr, - struct phy_c45_device_ids *c45_ids) + struct phy_c45_device_ids *c45_ids, + bool c45_over_c22) { const int num_ids = ARRAY_SIZE(c45_ids->device_ids); u32 devs_in_pkg = 0; @@ -798,14 +825,16 @@ static int get_phy_c45_ids(struct mii_bus *bus, int addr, * Some PHYs (88x3310) vendor space is not IEEE802.3 * compliant. */ - ret = phy_c45_probe_present(bus, addr, i); + ret = phy_c45_probe_present(bus, addr, i, + c45_over_c22); if (ret < 0) return -EIO; if (!ret) continue; } - phy_reg = get_phy_c45_devs_in_pkg(bus, addr, i, &devs_in_pkg); + phy_reg = get_phy_c45_devs_in_pkg(bus, addr, i, &devs_in_pkg, + c45_over_c22); if (phy_reg < 0) return -EIO; } @@ -815,7 +844,8 @@ static int get_phy_c45_ids(struct mii_bus *bus, int addr, * MMD 0, as some 10G PHYs have zero Devices In package, * e.g. Cortina CS4315/CS4340 PHY. */ - phy_reg = get_phy_c45_devs_in_pkg(bus, addr, 0, &devs_in_pkg); + phy_reg = get_phy_c45_devs_in_pkg(bus, addr, 0, &devs_in_pkg, + c45_over_c22); if (phy_reg < 0) return -EIO; @@ -834,7 +864,8 @@ static int get_phy_c45_ids(struct mii_bus *bus, int addr, * to ignore these if they do not contain IEEE 802.3 * registers. */ - ret = phy_c45_probe_present(bus, addr, i); + ret = phy_c45_probe_present(bus, addr, i, + c45_over_c22); if (ret < 0) return ret; @@ -842,12 +873,14 @@ static int get_phy_c45_ids(struct mii_bus *bus, int addr, continue; } - phy_reg = mdiobus_c45_read(bus, addr, i, MII_PHYSID1); + phy_reg = phy_probe_mmd_read(bus, addr, i, MII_PHYSID1, + c45_over_c22); if (phy_reg < 0) return -EIO; c45_ids->device_ids[i] = phy_reg << 16; - phy_reg = mdiobus_c45_read(bus, addr, i, MII_PHYSID2); + phy_reg = phy_probe_mmd_read(bus, addr, i, MII_PHYSID2, + c45_over_c22); if (phy_reg < 0) return -EIO; c45_ids->device_ids[i] |= phy_reg; @@ -961,7 +994,10 @@ struct phy_device *get_phy_device(struct mii_bus *bus, int addr, r = get_phy_c22_id(bus, addr, &phy_id); break; case PHY_ACCESS_C45: - r = get_phy_c45_ids(bus, addr, &c45_ids); + r = get_phy_c45_ids(bus, addr, &c45_ids, false); + break; + case PHY_ACCESS_C45_OVER_C22: + r = get_phy_c45_ids(bus, addr, &c45_ids, true); break; default: return ERR_PTR(-EIO); @@ -976,7 +1012,7 @@ struct phy_device *get_phy_device(struct mii_bus *bus, int addr, * space, if successful, create the C45 PHY device. */ if (mode == PHY_ACCESS_C22 && phy_id == 0 && bus->read_c45) { - r = get_phy_c45_ids(bus, addr, &c45_ids); + r = get_phy_c45_ids(bus, addr, &c45_ids, false); if (!r) return phy_device_create(bus, addr, phy_id, PHY_ACCESS_C45, &c45_ids); @@ -1058,7 +1094,7 @@ EXPORT_SYMBOL(phy_device_remove); int phy_get_c45_ids(struct phy_device *phydev) { return get_phy_c45_ids(phydev->mdio.bus, phydev->mdio.addr, - &phydev->c45_ids); + &phydev->c45_ids, false); } EXPORT_SYMBOL(phy_get_c45_ids); diff --git a/include/linux/phy.h b/include/linux/phy.h index a7aff91f4eb0..4852651f6326 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -541,10 +541,13 @@ struct macsec_ops; * * @PHY_ACCESS_C22: use 802.3 c22 MDIO transactions * @PHY_ACCESS_C45: use 802.3 c45 MDIO transactions + * @PHY_ACCESS_C45_OVER_C22: indirectly access C45 registers by using by 802.3 + * c22 MDIO transactions and registers 13 and 14. */ enum phy_access_mode { PHY_ACCESS_C22, PHY_ACCESS_C45, + PHY_ACCESS_C45_OVER_C22, }; /** 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); From patchwork Fri Jun 23 10:29:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 112053 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5671803vqr; Fri, 23 Jun 2023 03:36:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7SGUKGp452VWftT2ZaEpiZ6CGqVp9zxARDp5fNZi3GFtLLT+ynRSJpt366e17IhgYYLUIa X-Received: by 2002:a05:6358:cc2f:b0:132:5a2:7c55 with SMTP id gx47-20020a056358cc2f00b0013205a27c55mr6540642rwb.10.1687516597223; Fri, 23 Jun 2023 03:36:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687516597; cv=none; d=google.com; s=arc-20160816; b=TiNkKBO6AeeqNTe0CAXeoLKLluOJQqoqQnwSjekxTWXisXRip4noxl2+51TtjT//h8 ygXTgRygT3K1ShSGLmwISjvyV9bZuH6ySL8oX8LIRi1J91TqNp/lJXkTqEpMifzIjDMA pUrCxn65ZMki00UijgpSn2oQtd+WzhDqlmhFXYjhuhkB8j7uapTpUJfXEFCGkEH1i0Gv 0gPqIOoFUM5tgyXLqDF9sWdC3Lkf980MWCHSqTygtSOlBH1Evf7wGKO+LpiHTG0bRbFe bEfyGWJuZ/HEiM9P3w5HzNca7/DMH2utYfSpYkovciag18Of8p3pOVWaXJToe/mQixf/ q9QQ== 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=HxZmATM9BCQCA94L+QmEj7JLd8/HMN2dZUx1eArB4MU=; b=Um7Ly1nKksGM6A5uZcsd/cm3kzBfO9e9jqZXjAfIKYtKzx0001aIxaCU4cpw9wQuZ0 UQZ/+YhIVcvHTK98tHotp+CmpAqRuDBrH6rsjne8kJVF4XoeETDpOx+O40CkTLrLZJPq uVUwD/lk4MneRO3l6P0p1QzX9Sq1gMiJiFssWx2KuWeetcf6YiTV4f1EqlQt8LMs25Dw 7cYQ3lyvFte4ueVViFCHOuJpW84y1SGpNNTG6fTZHJcyMmbCKfc4wB73RNj5w5okJwsZ OLYRfVpzTGOMUelXnEcno+1yfgPby9eAkxqKglBYcoBXpj3NaI9uHdbfouq2g8J98haS +pzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XB95Dcmc; 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 c14-20020aa7952e000000b0063b7c4435c0si1671664pfp.54.2023.06.23.03.36.24; Fri, 23 Jun 2023 03:36:37 -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=XB95Dcmc; 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 S232291AbjFWKaf (ORCPT + 99 others); Fri, 23 Jun 2023 06:30:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232213AbjFWKaP (ORCPT ); Fri, 23 Jun 2023 06:30:15 -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 E11D7268E for ; Fri, 23 Jun 2023 03:29:54 -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 6F33A61A1E for ; Fri, 23 Jun 2023 10:29:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39768C4339A; Fri, 23 Jun 2023 10:29:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687516193; bh=ix+vKAfBpwxnlJKw+L5AoviCMLKx2fPBzB19tGgvqkA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=XB95Dcmc8wW4JD6DEXS1rgGOZ3p9hQXaQDnOEyCD1wlXpCZXNv6UbfGnRzpENIj+z VNhwpnqp7isIRSIOiB4mwA5c9iciXrMUI2QS6ttZ15BfUARuOLziQfUgm6TV1c7SvW o7wIIiRA2OpWWVs46jl12LGHMsjskm9c+dcKxwaFw5lKYFJEYs/9++Xs5XPWtq4G6d zm//Jbll4UGQbAWhKle057rjMgHzgc9uHkOib3D5aYnUFgJrHE921KvI/WR+pGLtOa BYS6UMXaRTRalUQtnr2ba8y2V4LmboZo08ULDWWy8DlP9Hd0rMiccCfsXMcSK07SVX JQwia/4TOByfA== From: Michael Walle Date: Fri, 23 Jun 2023 12:29:18 +0200 Subject: [PATCH net-next v2 09/10] net: mdio: add C45-over-C22 fallback to fwnode_mdiobus_register_phy() MIME-Version: 1.0 Message-Id: <20230620-feature-c45-over-c22-v2-9-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?1769489403025476121?= X-GMAIL-MSGID: =?utf-8?q?1769489403025476121?= If trying to register a C45 PHY on an MDIO bus which isn't capable of C45 (either because the MDIO controller doesn't support it or because C45 accesses are prohibited due to faulty C22 PHYs) we can fall back to the new C45-over-C22 access method. Signed-off-by: Michael Walle --- Please note, that both with the old and the new code compatible = "ethernet-phy-idNNNN.NNNN" only works for the C22 case. I'm wondering if compatible = "ethernet-phy-idNNNN.NNNN", "ethernet-phy-ieee802.3-c45 even makes sense because there might be multiple C45 ids. At least it is an allowed pattern according to the device tree bindings. But with the current code, the ethernet-phy-idNNNN.NNNN is ignored in the c45 case. --- drivers/net/mdio/fwnode_mdio.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/net/mdio/fwnode_mdio.c b/drivers/net/mdio/fwnode_mdio.c index 972c8932c2fe..fed056d82b4e 100644 --- a/drivers/net/mdio/fwnode_mdio.c +++ b/drivers/net/mdio/fwnode_mdio.c @@ -115,7 +115,6 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, struct mii_timestamper *mii_ts = NULL; struct pse_control *psec = NULL; struct phy_device *phy; - bool is_c45; u32 phy_id; int rc; @@ -129,13 +128,19 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, goto clean_pse; } - is_c45 = fwnode_device_is_compatible(child, "ethernet-phy-ieee802.3-c45"); - if (is_c45 || fwnode_get_phy_id(child, &phy_id)) - phy = get_phy_device(bus, addr, - is_c45 ? PHY_ACCESS_C45 : PHY_ACCESS_C22); - else + if (fwnode_device_is_compatible(child, "ethernet-phy-ieee802.3-c45")) { + if (mdiobus_supports_c45(bus)) + phy = get_phy_device(bus, addr, PHY_ACCESS_C45); + else + phy = get_phy_device(bus, addr, + PHY_ACCESS_C45_OVER_C22); + } else if (fwnode_get_phy_id(child, &phy_id) == 0) { phy = phy_device_create(bus, addr, phy_id, PHY_ACCESS_C22, NULL); + } else { + phy = get_phy_device(bus, addr, PHY_ACCESS_C22); + } + if (IS_ERR(phy)) { rc = PTR_ERR(phy); goto clean_mii_ts; From patchwork Fri Jun 23 10:29:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 112059 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5676008vqr; Fri, 23 Jun 2023 03:46:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7KuTa2cnJe2NSsyxu3UDQbbTa4h9Q2LGj0z8AFZj3cNPVhetJbEVbx4T/eUrQvGV1kFO9C X-Received: by 2002:a17:902:f545:b0:1b6:6751:95f5 with SMTP id h5-20020a170902f54500b001b6675195f5mr20506448plf.25.1687517204563; Fri, 23 Jun 2023 03:46:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687517204; cv=none; d=google.com; s=arc-20160816; b=uBhUt4xQdHSg8dKqY4t0OyuguBwdHqMs1/GwpS8rk5SL9hhxgSn6uKa0QX6rie1Pf+ F3kNxsLaMpA7cNflrcwhgispr6WAsgCPYZkxWC4Y9oMHSx9+/Eg1WK63/Ptmrelg2t3c sEcj84/zC90udeoXjHQIXkV/fXrqpQbJL9Im8sWo5D9VPYBIS/eFhHIvIPvshZ+8ZHJK Q+Y6b50tAV9gkb3GzD7954tCcphDc/nDD+exuLzXYiY3EPpzTV0SLSePC6wu+Qb7XEpF otQ/uaY1nM2Pd+BYEBPIWGopuVb259eVl/Ji2Ea7c/M0+WBEQ69ZDDKWb8ozRzrTDF9u nQIw== 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=QrYNqZUvhgT7uYiFoNOw4w75pT272hSBonYWzh06JTY=; b=y8ZWJpiIxr4hW7VlnJiQC17ekriW9471J08/hqyECvawFsgXupYG31QKup1tip26nq SVh5rEAg8aCE3GAWJnxL8W+Pnk7ge8x+cUhB60elx2Vr63w7x9idi9NM78WOKkcT1ryG CjfO6ktjPTfSNqFaLpNpVGxpMXWC0pR2XkmRJlC5IYd3zyXBINyAy/1ms/G1xrpEF5zc 3vblS8RShxVC3AzYOBUQ4DBLHkuhTdq6hb6GX+fiVuGRWXBa/adX8JmtQ5W+9DHEPlCh 5M47s7smSWIriWBEkWHLfGY0NfPq3VC5BwZhPAPQ5EZ6/wF92pmvvAOwDWBtW2NFBDA/ ji0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lfBY0m7e; 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 m18-20020a170902d19200b001a52db202c7si4702098plb.382.2023.06.23.03.46.30; Fri, 23 Jun 2023 03:46:44 -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=lfBY0m7e; 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 S232273AbjFWKat (ORCPT + 99 others); Fri, 23 Jun 2023 06:30:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232253AbjFWKaT (ORCPT ); Fri, 23 Jun 2023 06:30:19 -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 A718B1BCA for ; Fri, 23 Jun 2023 03:29:58 -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 218D061A18 for ; Fri, 23 Jun 2023 10:29:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5574AC433C0; Fri, 23 Jun 2023 10:29:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687516197; bh=baWU82tteE6wohLuYV2acd4eWNdncxCiiHvc8i4RT7E=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=lfBY0m7e5+WEmW8SojOvSZKUaHdINeF5dAbAzVwmShBp4Ch39m8pmZzcmnn5ueahr bEocoJVB1oQXM6z6WtbQbcubQ95dqTeK24a3RqI//l9KdNZpXBL0GD13+/OcXlQPO5 2NLK0PnWN9VvvsOmDnpTr9nZYMT5whgjexHy1l2fV7EPJS4pEeF8SJI1VC+6VNfgds cjuqqNp/ieqTyXIVoQuzuJQFrwakExMUnJvHs2v75QBcDJ7WrklgyXoHnGvV+IxkE0 iSSje+PGesKnwYkQNJQlVagp3SDn+g1Vye6GYUY1EZjINU1kFtDEMgsn4h2EDMvPn3 q/jV6zxJNP41A== From: Michael Walle Date: Fri, 23 Jun 2023 12:29:19 +0200 Subject: [PATCH net-next v2 10/10] net: mdio: support C45-over-C22 when probed via OF MIME-Version: 1.0 Message-Id: <20230620-feature-c45-over-c22-v2-10-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?1769490040505127824?= X-GMAIL-MSGID: =?utf-8?q?1769490040505127824?= Fall back to C45-over-C22 when the MDIO bus isn't capable of doing C45 transfers. This might be the case if there are broken PHYs on the bus or if the MDIO controller cannot do C45 transactions at all. For this to work, split the PHY registration into three steps, as done in the generic PHY probing code: (1) add C22 PHYs (2) scan for broken C22 PHYs (3) add C45 PHYs If step (2) detects a broken PHY, any PHYs will be added with C45-over-C22 access in step (3). Step (3) also ensures, that C45-over-C22 is used if C45 access is not supported at all on the bus. Signed-off-by: Michael Walle --- drivers/net/mdio/of_mdio.c | 63 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 15 deletions(-) diff --git a/drivers/net/mdio/of_mdio.c b/drivers/net/mdio/of_mdio.c index 7eb32ebb846d..e9d3cf6b68ee 100644 --- a/drivers/net/mdio/of_mdio.c +++ b/drivers/net/mdio/of_mdio.c @@ -100,6 +100,11 @@ static const struct of_device_id whitelist_phys[] = { {} }; +static bool of_mdiobus_child_is_c45_phy(struct device_node *child) +{ + return of_device_is_compatible(child, "ethernet-phy-ieee802.3-c45"); +} + /* * Return true if the child node is for a phy. It must either: * o Compatible string of "ethernet-phy-idX.X" @@ -118,7 +123,7 @@ bool of_mdiobus_child_is_phy(struct device_node *child) if (of_get_phy_id(child, &phy_id) != -EINVAL) return true; - if (of_device_is_compatible(child, "ethernet-phy-ieee802.3-c45")) + if (of_mdiobus_child_is_c45_phy(child)) return true; if (of_device_is_compatible(child, "ethernet-phy-ieee802.3-c22")) @@ -138,6 +143,32 @@ bool of_mdiobus_child_is_phy(struct device_node *child) } EXPORT_SYMBOL(of_mdiobus_child_is_phy); +static int of_mdiobus_register_child(struct mii_bus *mdio, + struct device_node *child, bool *scanphys) +{ + int addr, rc; + + addr = of_mdio_parse_addr(&mdio->dev, child); + if (addr < 0) { + *scanphys = true; + return 0; + } + + if (mdiobus_is_registered_device(mdio, addr)) + return 0; + + if (of_mdiobus_child_is_phy(child)) + rc = of_mdiobus_register_phy(mdio, child, addr); + else + rc = of_mdiobus_register_device(mdio, child, addr); + + if (rc == -ENODEV) + dev_err(&mdio->dev, "MDIO device at address %d is missing.\n", + addr); + + return rc; +} + /** * __of_mdiobus_register - Register mii_bus and create PHYs from the device tree * @mdio: pointer to mii_bus structure @@ -178,24 +209,26 @@ int __of_mdiobus_register(struct mii_bus *mdio, struct device_node *np, if (rc) return rc; - /* Loop over the child nodes and register a phy_device for each phy */ + /* Loop over the child nodes, skipping C45 PHYs so we can scan for + * broken C22 PHYs. The C45 PHYs will be registered afterwards. + */ for_each_available_child_of_node(np, child) { - addr = of_mdio_parse_addr(&mdio->dev, child); - if (addr < 0) { - scanphys = true; + if (of_mdiobus_child_is_c45_phy(child)) continue; - } + rc = of_mdiobus_register_child(mdio, child, &scanphys); + if (rc) + goto unregister; + } - if (of_mdiobus_child_is_phy(child)) - rc = of_mdiobus_register_phy(mdio, child, addr); - else - rc = of_mdiobus_register_device(mdio, child, addr); + /* Some C22 PHYs are broken with C45 transactions. */ + mdiobus_scan_for_broken_c45_access(mdio); - if (rc == -ENODEV) - dev_err(&mdio->dev, - "MDIO device at address %d is missing.\n", - addr); - else if (rc) + /* Now add any missing C45 PHYs. If C45 access is not allowed, they + * will be registered with C45-over-C22 access. + */ + for_each_available_child_of_node(np, child) { + rc = of_mdiobus_register_child(mdio, child, &scanphys); + if (rc) goto unregister; }