Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4606350rdb; Tue, 12 Dec 2023 04:38:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IGMITaIg/kvPdjIXxvnScOcVZTs3lhOM8nnaaAKm7jJIRbP3LxHCC8HhiIzF1WmJxF0A3Q2 X-Received: by 2002:a05:6358:a082:b0:170:efdb:bba8 with SMTP id u2-20020a056358a08200b00170efdbbba8mr615738rwn.30.1702384689023; Tue, 12 Dec 2023 04:38:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702384688; cv=none; d=google.com; s=arc-20160816; b=qwom1kMCiwxyW6+W7ul2U/FZkRrPYSIjn6+/h9eJx4PdWW9N9oHOBg5uBxVDKNylDh s8lgFqijo5XeFbXJoDUHX3tz6BuTMnrXbPhRapIdRnC8XPOatVCQ1ghIALzJGYmQQprW Ueb7YY+BCRTIRTAHndv/Yc31pxzjxMFuoVSk1TFIJg0SWtzIf5ewk2VBKXvzg/xlm8Xc +E5I7Icpgq7gan6pIBW4WZnH/X8sblPmWayUOHyhDVPIf/BCJUiyKAQToIUIEJktR5un RHfL9Lkwba5fphlC4vAHofadl19Eo9jTpRtWJvZXiDfVHBbejqgyW7Q0GWHsK7nN/XZF WDyA== 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:to:from :dkim-signature; bh=M+NoPfid+7puCdo9sPDvLb7zjUyvTkje5iwQvI0aUXs=; fh=nc30ahckg68b/PDFQmmNDlUC9NcuXkQtpDFpHwacUN8=; b=D2o60xKvn+6rKJAGvYD2BS7RujvIXNcTRWtMfj30fqTwhZTOvfHLErF6STW6EkHca8 kvlJTJ1ekmrlVDeRDIBlpU/8/dtUZzm8b74DK6sNQKPZc/kPHnSJF5vF8KhQSEHzi/R6 lGVZbJCzMeNlOaKpIV19scwJdjpePj6y5D6A+uAbHcILkrO0UQt6asvSsftWtgCEkvgq elEnEVbWJLY3LZEATGjo6wcl7Bs755qURkN4WxE6IKSdCm95Q6swg9+qxToYUtKDobA3 jGj3L8I1nePNX0E9Y38PdImQc5Q/zEXI1ebY0qwKBtKJVb2zCN/iFn35s9g0L0qsMFen 3H2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=WfEvKaOC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id z16-20020a056a00241000b006cef5bed80fsi5483715pfh.143.2023.12.12.04.38.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 04:38:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=WfEvKaOC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 62E2A807591F; Tue, 12 Dec 2023 04:38:07 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346600AbjLLMhx (ORCPT + 99 others); Tue, 12 Dec 2023 07:37:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346535AbjLLMhv (ORCPT ); Tue, 12 Dec 2023 07:37:51 -0500 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 997B0CA; Tue, 12 Dec 2023 04:37:57 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-3332f1512e8so5216691f8f.2; Tue, 12 Dec 2023 04:37:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702384676; x=1702989476; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=M+NoPfid+7puCdo9sPDvLb7zjUyvTkje5iwQvI0aUXs=; b=WfEvKaOC7IunAbmL2INIRuNOivmbuJS9r886wPoLsBadp1m0gSBTWEVPqlF7vmw6Hv Int2y/nhZtrJlH6fmSB2d1bz9KEBJVp/AmB0aeHDaiKeVwDsjbXB97Fv/RqqyPNaAOHf DESQad97cc9HmPbylzzcyh5yLsjgOdml+Uts6MsMQMw9FSl+6x4i4Kl8ZgCdIGVh0zaP iZaKprjQuDyRj0GkUsdjtUM7mEQaPLzJFIPnLJDMRlM49oqW0u951zrv7vd/8iumI5GG Q0LMS+H5s+QdH9FakGJIyrrRSvbaTN7j52fv+V+nQFO3+nX4sY2H/e8jbCsy2XPoYio2 vRFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702384676; x=1702989476; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=M+NoPfid+7puCdo9sPDvLb7zjUyvTkje5iwQvI0aUXs=; b=jx2Wgqg5D0I3y1+SPWQ8YIQkT9b5uWWaDzuObjWBe3OAvOb/OO2PzkTVIAw8jpYDqn iSlQHLSgnHF8mT7XO4Emx8dHCD1ZKOlZEQnMICHutuweYDe/GtBVUL1rLXKCFzcTvCFy iJrPg4gLpM4zmTTeKOMLxgYjtMlS4ZLX2p6IfS46y0y32mCX9LvPwXvHWdB3skpp/aO2 iArdI5B3DyzrhNx61q/qk6ImNNxv9ceUkt+Gr/Z/baFSrqFX9ly7YUWLQ3/e/FjQxoUn V2OpER2jqLzMlhZ8Cir6TOEn1Uge1kIN5wSTUw516JchmOvuRyXF3P6OdmsXUlCNqfvk 30lQ== X-Gm-Message-State: AOJu0YxZGov1QJSA5ORPnIcS+l1RcgfHMDxxlUIQ/bppCkOym2FslrTY 9W7k4BGtwUw4mdxZe1dMRHk= X-Received: by 2002:a05:600c:304a:b0:40c:233f:e02a with SMTP id n10-20020a05600c304a00b0040c233fe02amr3520971wmh.7.1702384675674; Tue, 12 Dec 2023 04:37:55 -0800 (PST) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id o12-20020a05600c4fcc00b0040c552a1338sm214890wmq.1.2023.12.12.04.37.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 04:37:55 -0800 (PST) From: Christian Marangi To: Florian Fainelli , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Vladimir Oltean , David Epping , Christian Marangi , "Russell King (Oracle)" , Harini Katakam , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [net-next PATCH v5 3/3] net: phy: add support for PHY package MMD read/write Date: Tue, 12 Dec 2023 13:37:43 +0100 Message-Id: <20231212123743.29829-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231212123743.29829-1-ansuelsmth@gmail.com> References: <20231212123743.29829-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 12 Dec 2023 04:38:07 -0800 (PST) Some PHY in PHY package may require to read/write MMD regs to correctly configure the PHY package. Add support for these additional required function in both lock and no lock variant. It's assumed that the entire PHY package is either C22 or C45. We use C22 or C45 way of writing/reading to mmd regs based on the passed phydev whether it's C22 or C45. Signed-off-by: Christian Marangi --- Changes v5: - Improve function description Changes v4: - Drop function comments in header file Changes v3: - Move in phy-core.c from phy.h - Base c45 from phydev Changes v2: - Rework to use newly introduced helper - Add common check for regnum and devad drivers/net/phy/phy-core.c | 144 +++++++++++++++++++++++++++++++++++++ include/linux/phy.h | 16 +++++ 2 files changed, 160 insertions(+) diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c index b729ac8b2640..8132ed83cff8 100644 --- a/drivers/net/phy/phy-core.c +++ b/drivers/net/phy/phy-core.c @@ -650,6 +650,150 @@ int phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val) } EXPORT_SYMBOL(phy_write_mmd); +/** + * __phy_package_read_mmd - read MMD reg relative to PHY package base addr + * @phydev: The phy_device struct + * @addr_offset: The offset to be added to PHY package base_addr + * @devad: The MMD to read from + * @regnum: The register on the MMD to read + * + * Convenience helper for reading a register of an MMD on a given PHY + * using the PHY package base address. The base address is added to + * the addr_offset value. + * + * Same calling rules as for __phy_read(); + * + * NOTE: It's assumed that the entire PHY package is either C22 or C45. + */ +int __phy_package_read_mmd(struct phy_device *phydev, + unsigned int addr_offset, int devad, + u32 regnum) +{ + struct phy_package_shared *shared = phydev->shared; + int addr = shared->base_addr + addr_offset; + + if (addr >= PHY_MAX_ADDR) + return -EIO; + + if (regnum > (u16)~0 || devad > 32) + return -EINVAL; + + return mmd_phy_read(phydev->mdio.bus, addr, phydev->is_c45, devad, + regnum); +} +EXPORT_SYMBOL(__phy_package_read_mmd); + +/** + * phy_package_read_mmd - read MMD reg relative to PHY package base addr + * @phydev: The phy_device struct + * @addr_offset: The offset to be added to PHY package base_addr + * @devad: The MMD to read from + * @regnum: The register on the MMD to read + * + * Convenience helper for reading a register of an MMD on a given PHY + * using the PHY package base address. The base address is added to + * the addr_offset value. + * + * Same calling rules as for phy_read(); + * + * NOTE: It's assumed that the entire PHY package is either C22 or C45. + */ +int phy_package_read_mmd(struct phy_device *phydev, + unsigned int addr_offset, int devad, + u32 regnum) +{ + struct phy_package_shared *shared = phydev->shared; + int addr = shared->base_addr + addr_offset; + int val; + + if (addr >= PHY_MAX_ADDR) + return -EIO; + + if (regnum > (u16)~0 || devad > 32) + return -EINVAL; + + phy_lock_mdio_bus(phydev); + val = mmd_phy_read(phydev->mdio.bus, addr, phydev->is_c45, devad, + regnum); + phy_unlock_mdio_bus(phydev); + + return val; +} +EXPORT_SYMBOL(phy_package_read_mmd); + +/** + * __phy_package_write_mmd - write MMD reg relative to PHY package base addr + * @phydev: The phy_device struct + * @addr_offset: The offset to be added to PHY package base_addr + * @devad: The MMD to write to + * @regnum: The register on the MMD to write + * @val: value to write to @regnum + * + * Convenience helper for writing a register of an MMD on a given PHY + * using the PHY package base address. The base address is added to + * the addr_offset value. + * + * Same calling rules as for __phy_write(); + * + * NOTE: It's assumed that the entire PHY package is either C22 or C45. + */ +int __phy_package_write_mmd(struct phy_device *phydev, + unsigned int addr_offset, int devad, + u32 regnum, u16 val) +{ + struct phy_package_shared *shared = phydev->shared; + int addr = shared->base_addr + addr_offset; + + if (addr >= PHY_MAX_ADDR) + return -EIO; + + if (regnum > (u16)~0 || devad > 32) + return -EINVAL; + + return mmd_phy_write(phydev->mdio.bus, addr, phydev->is_c45, devad, + regnum, val); +} +EXPORT_SYMBOL(__phy_package_write_mmd); + +/** + * __phy_package_write_mmd - write MMD reg relative to PHY package base addr + * @phydev: The phy_device struct + * @addr_offset: The offset to be added to PHY package base_addr + * @devad: The MMD to write to + * @regnum: The register on the MMD to write + * @val: value to write to @regnum + * + * Convenience helper for writing a register of an MMD on a given PHY + * using the PHY package base address. The base address is added to + * the addr_offset value. + * + * Same calling rules as for phy_write(); + * + * NOTE: It's assumed that the entire PHY package is either C22 or C45. + */ +int phy_package_write_mmd(struct phy_device *phydev, + unsigned int addr_offset, int devad, + u32 regnum, u16 val) +{ + struct phy_package_shared *shared = phydev->shared; + int addr = shared->base_addr + addr_offset; + int ret; + + if (addr >= PHY_MAX_ADDR) + return -EIO; + + if (regnum > (u16)~0 || devad > 32) + return -EINVAL; + + phy_lock_mdio_bus(phydev); + ret = mmd_phy_write(phydev->mdio.bus, addr, phydev->is_c45, devad, + regnum, val); + phy_unlock_mdio_bus(phydev); + + return ret; +} +EXPORT_SYMBOL(phy_package_write_mmd); + /** * phy_modify_changed - Function for modifying a PHY register * @phydev: the phy_device struct diff --git a/include/linux/phy.h b/include/linux/phy.h index 51702e349d83..f58a9ff52e0d 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -2049,6 +2049,22 @@ static inline int __phy_package_write(struct phy_device *phydev, return __mdiobus_write(phydev->mdio.bus, addr, regnum, val); } +int __phy_package_read_mmd(struct phy_device *phydev, + unsigned int addr_offset, int devad, + u32 regnum); + +int phy_package_read_mmd(struct phy_device *phydev, + unsigned int addr_offset, int devad, + u32 regnum); + +int __phy_package_write_mmd(struct phy_device *phydev, + unsigned int addr_offset, int devad, + u32 regnum, u16 val); + +int phy_package_write_mmd(struct phy_device *phydev, + unsigned int addr_offset, int devad, + u32 regnum, u16 val); + static inline bool __phy_package_set_once(struct phy_device *phydev, unsigned int b) { -- 2.40.1