Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2301477pxb; Fri, 25 Mar 2022 15:01:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztuC0ZLDG4t0ayfr8MtCTNTa/pwa1D7U4OqvB3tE8d8ViN8hZ2d46CkTamSnB9DESpavaW X-Received: by 2002:a17:90a:5797:b0:1bc:56a9:f6c8 with SMTP id g23-20020a17090a579700b001bc56a9f6c8mr27692318pji.12.1648245688342; Fri, 25 Mar 2022 15:01:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648245688; cv=none; d=google.com; s=arc-20160816; b=tY0HLOXe4K0BPb9NJwbPME3d61+g9sH2jOrpImOR3n33Waed0eRCe1q6wq8lHB2sNy god91CPMpO3NxKBuCLIbre80DuLsvnVBA0OvSvNsWy0PdyzKOWdm2BcjNELj0YpHF50j XycaWU++xiLZLeLFCah/G1WCANXM3Md2i5jwrL1DFZnGQb1CQtLL9zZLvXg19mnG6jPN q6IKTQmN2+bbcYZz8/J1GeShFYV4UV0mUlYZLmMLsgMo5/57MFiBRE0gNVm7QHH9hwJg XCZEh3SolL31hmezOuRG8VsyvHUg1oWFgLc/hLRSt5u5ZPOAyGcxQ8AH5+NFoRSumR0Z 8lFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HO3BNNMiGWEE7yu4esdw667t4cALNEKNqcbKGS1w0kw=; b=dDlIifLpnEdGAi94spyqFH99XPDD3dAEMEts4G7eD4bhJniLpJ0TAGLVAjtYO+EZoK 1jev8aCvPqhfbmkMecqFkKgy2dcXSLr9wnVaRenmQI2yR8ZchdA1HMvoz4MLhSIJ3dY/ NcQOqwGKlJVrpBsh2RGgagnxqnZcR8dI9zRih6MRNYqAj9kJFU42gIo7TxKLp2g+OsBu zhCbcUpaIZGFQdcZMk/hszlOy1YL4EO9Xq8xyhhNCRfmw/WBNmTYIuDkcnCzhkgmmABz cIR7m3lhL0RTTl+1KX8ss8aYh1bf14UZKZu6Q+UcQpxCNE8GdYCVOKP9AW5Pjc9GsEXw yQ/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=SBUdBNid; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id l22-20020a056a0016d600b004fa3a8dffbdsi4635853pfc.116.2022.03.25.15.01.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 15:01:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=SBUdBNid; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 52CDD517CB; Fri, 25 Mar 2022 14:35:49 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233505AbiCYVhQ (ORCPT + 99 others); Fri, 25 Mar 2022 17:37:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233443AbiCYVhE (ORCPT ); Fri, 25 Mar 2022 17:37:04 -0400 Received: from ssl.serverraum.org (ssl.serverraum.org [176.9.125.105]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B7EE4AE3A; Fri, 25 Mar 2022 14:35:28 -0700 (PDT) Received: from mwalle01.kontron.local. (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id 8DD54223F0; Fri, 25 Mar 2022 22:35:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1648244126; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HO3BNNMiGWEE7yu4esdw667t4cALNEKNqcbKGS1w0kw=; b=SBUdBNid1b83ipDQWD3bS9UHVF4AToC2TN4ACVgrOfhu9qdnI5Ch+vGjGua3qvYvluuyKW YtvPWMDx088UgmjFpkyHE6xwpJM8CeAWvbpmzp5Jq5+jCCtaQ45ujrNn4shxjY8dvS4j9v m6yrOzLR4OI3PE2piUGrVvNXZqNHZpM= From: Michael Walle To: Andrew Lunn , Heiner Kallweit , Russell King , Jakub Kicinski , Paolo Abeni Cc: "David S . Miller" , Xu Liang , Alexandre Belloni , Florian Fainelli , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Michael Walle Subject: [PATCH RFC net-next v2 3/8] net: phy: add error checks in __phy_mmd_indirect() and export it Date: Fri, 25 Mar 2022 22:35:13 +0100 Message-Id: <20220325213518.2668832-4-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220325213518.2668832-1-michael@walle.cc> References: <20220325213518.2668832-1-michael@walle.cc> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Add missing error checks and export it so it can be reused. Rename the function to have the common "phy_" prefix. Signed-off-by: Michael Walle --- drivers/net/phy/phy-core.c | 34 ++++++++++++++++++++++++++-------- include/linux/phy.h | 2 ++ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c index 2001f3329133..dd9b6b64757d 100644 --- a/drivers/net/phy/phy-core.c +++ b/drivers/net/phy/phy-core.c @@ -437,19 +437,37 @@ 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) +/** + * __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) { + 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 (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 (ret) + return ret; /* Select the Function : DATA with no post increment */ - __mdiobus_write(bus, phy_addr, MII_MMD_CTRL, - devad | MII_MMD_CTRL_NOINCR); + return __mdiobus_write(bus, phy_addr, MII_MMD_CTRL, + devad | MII_MMD_CTRL_NOINCR); } +EXPORT_SYMBOL(__phy_mmd_indirect); /** * __phy_read_mmd - Convenience function for reading a register @@ -476,7 +494,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); + __phy_mmd_indirect(bus, phy_addr, devad, regnum); /* Read the content of the MMD's selected register */ val = __mdiobus_read(bus, phy_addr, MII_MMD_DATA); @@ -532,7 +550,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); + __phy_mmd_indirect(bus, phy_addr, devad, regnum); /* 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 36ca2b5c2253..c81c209d4abd 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1110,6 +1110,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. -- 2.30.2