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.