From patchwork Wed Dec 13 10:57:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 177868 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp7688768dys; Wed, 13 Dec 2023 02:58:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IHBzqjwPiS+FYkJZxgNRYE6pR9y1O6qfCG24skJowWQwzSA1v/I4TXaq/xVV9fyMNfi5nbL X-Received: by 2002:a05:6a00:8802:b0:6ce:5637:787b with SMTP id ho2-20020a056a00880200b006ce5637787bmr6510988pfb.51.1702465131818; Wed, 13 Dec 2023 02:58:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702465131; cv=none; d=google.com; s=arc-20160816; b=jU/KEryvnKESX5RNK/N1XFluSbsH8D68hhl/ncZa5u6FBKvOKYxlxXeUCkwt2PAuKG ENAYR7t4WPd7xz/isH8C0ahksue7Ee5RSzj9n4pUGgIb0OaYB+mX0qRKWQ3mlcWwa2tV 3iCxY337HxH6HiR2XR93geAhpDIYLYKIW4w+wz0AYbQExUXIehgVGV9tpgIIPP7PgFoH usQz6Y4OgO1Rc17AU51cFDeO9tjABXbOO91T9SVKqGCEtHKgmuC9u8j0WvGi54fjiH2o ex4Zv3CJovEJmv1IaDChqoBvzJ8xkM65do/s5SMujBa63v47Nm8nNrHdmhoXPTPaIjEu nWWg== 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 :message-id:date:subject:to:from:dkim-signature; bh=aqVEiehGB93HQ19d7TI9TDkVLe/UWdQF1ND0VBnLrHk=; fh=e4NTAZpYxJjO9KGOmyKA8buDcaE3F5PQ5hdNGG6SGOA=; b=UxXPOQrUW20w4jEOcU0duxN/Ht4LiFQpKtcRyS/ADri6t8NSi1YRr09IZ7i6GY55Vu w9HZU9fjb1IDsI+FCE2W9rjOs9GjwvgPh6rouOaZ7ahyWeA1XDBrEzVqnWmNF9M08ejZ ZEMVNRUPStCKFfRD6+SxVtR3BFcnmjvkPlX+hj3XWkdz1RrJdA9wMBIm+KBUD4Glbm4/ 7gwqPJNQypmO3wgCM1BA+7LW7vS8OD00FP542lOk6zCOM64D9ioNRROfBFxWphPrN83q eGcakQnKAgcWWGGLkvqyA+0OGuuAQMMlugyBUxNuN1fUUmpjVgzZazbJ/mgBabUVn/R+ zgag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=beD5gGpa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id f15-20020a65628f000000b005b9519d9e3esi9398828pgv.242.2023.12.13.02.58.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 02:58:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=beD5gGpa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 9225A8045C51; Wed, 13 Dec 2023 02:58:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235450AbjLMK6O (ORCPT + 99 others); Wed, 13 Dec 2023 05:58:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235385AbjLMK6K (ORCPT ); Wed, 13 Dec 2023 05:58:10 -0500 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21ACB106; Wed, 13 Dec 2023 02:58:06 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-40c256ffdbcso69221345e9.2; Wed, 13 Dec 2023 02:58:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702465084; x=1703069884; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=aqVEiehGB93HQ19d7TI9TDkVLe/UWdQF1ND0VBnLrHk=; b=beD5gGpaPmtsIARqOvLbsO3SurppSLkH/Z0quQ7bW4BH2nJaI7S6RBSgY+qR0MVoR/ z/5pTvgcBNW8F8O0hH8xS7eVZ+j3H226EBA4CHcIlvvs0cCq2cbsHhHm3oL5W55S+dsk oK/gIUy01zofVvS6NlCkR+J6g/iM4iYx+aXivV5yS2CpUXC8/nDoUp51CZtBOzYedSaI lCNGKIeGD1lCHHK2qlMIjYtCPG/Ooo+1ysbNog0GKbcvWHAR9ZAY3t9MCEx1xwq7Z+8G m7pX1McYdL/0b4PrDySbyZofSVz5cWqjZBxoj30okPDyhS2rcSZBT2GB5qYyd7kRkg6l gLzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702465084; x=1703069884; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=aqVEiehGB93HQ19d7TI9TDkVLe/UWdQF1ND0VBnLrHk=; b=LRTrGNE+1LzyKVM8F7sKI6/WZXxiI7Ou9xcJU7imbdRxaIZC2PGVe98t66euhz4Ntk ToOCEUL8qO8a80QTQ+2uDjsyxJor33FofsxDzI17Ci7kQslb4oBCtQkvTkdwgq1QCtU7 s7mqQ2qYsepFG/mBT5fGZ7P9AO29ovMujmcuyNVaVEDtiGTY4j6ChQIQQ2Bi+YbgQhN8 7ehrdE1vU7eCipbYuv5oj3qNYfXd8PpOxrmrB73wp8urY4FdUHt5HDt6u73F7eaBwtjz cvr/se0FG7A/QOkYzgLA81RuD0IlRv1t3FoGktyxJF8tZtdtaTFMRxm73CI9bqc30A5R zUDA== X-Gm-Message-State: AOJu0YyjQHCmsvCoLQPQPA2j0SEWToFJLn7O27A7cQ14962Odsoo7hZE ZhHpF31BGo9rPBiu/dPE7/s= X-Received: by 2002:a05:600c:29a:b0:40c:2910:50bb with SMTP id 26-20020a05600c029a00b0040c291050bbmr3672650wmk.143.1702465084189; Wed, 13 Dec 2023 02:58:04 -0800 (PST) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id a11-20020a05600c348b00b0040b400711f5sm22432385wmq.7.2023.12.13.02.58.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 02:58:03 -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 , Harini Katakam , Christian Marangi , Simon Horman , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [net-next PATCH v6 1/3] net: phy: extend PHY package API to support multiple global address Date: Wed, 13 Dec 2023 11:57:28 +0100 Message-Id: <20231213105730.1731-1-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Wed, 13 Dec 2023 02:58:48 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785164078123657141 X-GMAIL-MSGID: 1785164078123657141 Current API for PHY package are limited to single address to configure global settings for the PHY package. It was found that some PHY package (for example the qca807x, a PHY package that is shipped with a bundle of 5 PHY) requires multiple PHY address to configure global settings. An example scenario is a PHY that have a dedicated PHY for PSGMII/serdes calibrarion and have a specific PHY in the package where the global PHY mode is set and affects every other PHY in the package. Change the API in the following way: - Change phy_package_join() to take the base addr of the PHY package instead of the global PHY addr. - Make __/phy_package_write/read() require an additional arg that select what global PHY address to use by passing the offset from the base addr passed on phy_package_join(). Each user of this API is updated to follow this new implementation following a pattern where an enum is defined to declare the offset of the addr. We also drop the check if shared is defined as any user of the phy_package_read/write is expected to use phy_package_join first. Misuse of this will correctly trigger a kernel panic for NULL pointer exception. Signed-off-by: Christian Marangi --- Changes v2: - Make kernel panic if shared is not init (bugged scenario) - Fix some confusing comments drivers/net/phy/bcm54140.c | 16 +++++++++---- drivers/net/phy/mscc/mscc.h | 5 ++++ drivers/net/phy/mscc/mscc_main.c | 4 ++-- drivers/net/phy/phy_device.c | 35 ++++++++++++++------------- include/linux/phy.h | 41 +++++++++++++++++++------------- 5 files changed, 63 insertions(+), 38 deletions(-) diff --git a/drivers/net/phy/bcm54140.c b/drivers/net/phy/bcm54140.c index d43076592f81..2eea3d09b1e6 100644 --- a/drivers/net/phy/bcm54140.c +++ b/drivers/net/phy/bcm54140.c @@ -128,6 +128,10 @@ #define BCM54140_DEFAULT_DOWNSHIFT 5 #define BCM54140_MAX_DOWNSHIFT 9 +enum bcm54140_global_phy { + BCM54140_BASE_ADDR = 0, +}; + struct bcm54140_priv { int port; int base_addr; @@ -429,11 +433,13 @@ static int bcm54140_base_read_rdb(struct phy_device *phydev, u16 rdb) int ret; phy_lock_mdio_bus(phydev); - ret = __phy_package_write(phydev, MII_BCM54XX_RDB_ADDR, rdb); + ret = __phy_package_write(phydev, BCM54140_BASE_ADDR, + MII_BCM54XX_RDB_ADDR, rdb); if (ret < 0) goto out; - ret = __phy_package_read(phydev, MII_BCM54XX_RDB_DATA); + ret = __phy_package_read(phydev, BCM54140_BASE_ADDR, + MII_BCM54XX_RDB_DATA); out: phy_unlock_mdio_bus(phydev); @@ -446,11 +452,13 @@ static int bcm54140_base_write_rdb(struct phy_device *phydev, int ret; phy_lock_mdio_bus(phydev); - ret = __phy_package_write(phydev, MII_BCM54XX_RDB_ADDR, rdb); + ret = __phy_package_write(phydev, BCM54140_BASE_ADDR, + MII_BCM54XX_RDB_ADDR, rdb); if (ret < 0) goto out; - ret = __phy_package_write(phydev, MII_BCM54XX_RDB_DATA, val); + ret = __phy_package_write(phydev, BCM54140_BASE_ADDR, + MII_BCM54XX_RDB_DATA, val); out: phy_unlock_mdio_bus(phydev); diff --git a/drivers/net/phy/mscc/mscc.h b/drivers/net/phy/mscc/mscc.h index 7a962050a4d4..6a3d8a754eb8 100644 --- a/drivers/net/phy/mscc/mscc.h +++ b/drivers/net/phy/mscc/mscc.h @@ -416,6 +416,11 @@ struct vsc8531_private { * gpio_lock: used for PHC operations. Common for all PHYs as the load/save GPIO * is shared. */ + +enum vsc85xx_global_phy { + VSC88XX_BASE_ADDR = 0, +}; + struct vsc85xx_shared_private { struct mutex gpio_lock; }; diff --git a/drivers/net/phy/mscc/mscc_main.c b/drivers/net/phy/mscc/mscc_main.c index 4171f01d34e5..6f74ce0ab1aa 100644 --- a/drivers/net/phy/mscc/mscc_main.c +++ b/drivers/net/phy/mscc/mscc_main.c @@ -711,7 +711,7 @@ int phy_base_write(struct phy_device *phydev, u32 regnum, u16 val) dump_stack(); } - return __phy_package_write(phydev, regnum, val); + return __phy_package_write(phydev, VSC88XX_BASE_ADDR, regnum, val); } /* phydev->bus->mdio_lock should be locked when using this function */ @@ -722,7 +722,7 @@ int phy_base_read(struct phy_device *phydev, u32 regnum) dump_stack(); } - return __phy_package_read(phydev, regnum); + return __phy_package_read(phydev, VSC88XX_BASE_ADDR, regnum); } u32 vsc85xx_csr_read(struct phy_device *phydev, diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 478126f6b5bc..424cbb13de13 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1648,20 +1648,22 @@ EXPORT_SYMBOL_GPL(phy_driver_is_genphy_10g); /** * phy_package_join - join a common PHY group * @phydev: target phy_device struct - * @addr: cookie and PHY address for global register access + * @base_addr: cookie and base PHY address of PHY package for offset + * calculation of global register access * @priv_size: if non-zero allocate this amount of bytes for private data * * This joins a PHY group and provides a shared storage for all phydevs in * this group. This is intended to be used for packages which contain * more than one PHY, for example a quad PHY transceiver. * - * The addr parameter serves as a cookie which has to have the same value - * for all members of one group and as a PHY address to access generic - * registers of a PHY package. Usually, one of the PHY addresses of the - * different PHYs in the package provides access to these global registers. + * The base_addr parameter serves as cookie which has to have the same values + * for all members of one group and as the base PHY address of the PHY package + * for offset calculation to access generic registers of a PHY package. + * Usually, one of the PHY addresses of the different PHYs in the package + * provides access to these global registers. * The address which is given here, will be used in the phy_package_read() - * and phy_package_write() convenience functions. If your PHY doesn't have - * global registers you can just pick any of the PHY addresses. + * and phy_package_write() convenience functions as base and added to the + * passed offset in those functions. * * This will set the shared pointer of the phydev to the shared storage. * If this is the first call for a this cookie the shared storage will be @@ -1671,17 +1673,17 @@ EXPORT_SYMBOL_GPL(phy_driver_is_genphy_10g); * Returns < 1 on error, 0 on success. Esp. calling phy_package_join() * with the same cookie but a different priv_size is an error. */ -int phy_package_join(struct phy_device *phydev, int addr, size_t priv_size) +int phy_package_join(struct phy_device *phydev, int base_addr, size_t priv_size) { struct mii_bus *bus = phydev->mdio.bus; struct phy_package_shared *shared; int ret; - if (addr < 0 || addr >= PHY_MAX_ADDR) + if (base_addr < 0 || base_addr >= PHY_MAX_ADDR) return -EINVAL; mutex_lock(&bus->shared_lock); - shared = bus->shared[addr]; + shared = bus->shared[base_addr]; if (!shared) { ret = -ENOMEM; shared = kzalloc(sizeof(*shared), GFP_KERNEL); @@ -1693,9 +1695,9 @@ int phy_package_join(struct phy_device *phydev, int addr, size_t priv_size) goto err_free; shared->priv_size = priv_size; } - shared->addr = addr; + shared->base_addr = base_addr; refcount_set(&shared->refcnt, 1); - bus->shared[addr] = shared; + bus->shared[base_addr] = shared; } else { ret = -EINVAL; if (priv_size && priv_size != shared->priv_size) @@ -1733,7 +1735,7 @@ void phy_package_leave(struct phy_device *phydev) return; if (refcount_dec_and_mutex_lock(&shared->refcnt, &bus->shared_lock)) { - bus->shared[shared->addr] = NULL; + bus->shared[shared->base_addr] = NULL; mutex_unlock(&bus->shared_lock); kfree(shared->priv); kfree(shared); @@ -1752,7 +1754,8 @@ static void devm_phy_package_leave(struct device *dev, void *res) * devm_phy_package_join - resource managed phy_package_join() * @dev: device that is registering this PHY package * @phydev: target phy_device struct - * @addr: cookie and PHY address for global register access + * @base_addr: cookie and base PHY address of PHY package for offset + * calculation of global register access * @priv_size: if non-zero allocate this amount of bytes for private data * * Managed phy_package_join(). Shared storage fetched by this function, @@ -1760,7 +1763,7 @@ static void devm_phy_package_leave(struct device *dev, void *res) * phy_package_join() for more information. */ int devm_phy_package_join(struct device *dev, struct phy_device *phydev, - int addr, size_t priv_size) + int base_addr, size_t priv_size) { struct phy_device **ptr; int ret; @@ -1770,7 +1773,7 @@ int devm_phy_package_join(struct device *dev, struct phy_device *phydev, if (!ptr) return -ENOMEM; - ret = phy_package_join(phydev, addr, priv_size); + ret = phy_package_join(phydev, base_addr, priv_size); if (!ret) { *ptr = phydev; diff --git a/include/linux/phy.h b/include/linux/phy.h index e5f1f41e399c..51702e349d83 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -327,7 +327,8 @@ struct mdio_bus_stats { /** * struct phy_package_shared - Shared information in PHY packages - * @addr: Common PHY address used to combine PHYs in one package + * @base_addr: Base PHY address of PHY package used to combine PHYs + * in one package and for offset calculation of phy_package_read/write * @refcnt: Number of PHYs connected to this shared data * @flags: Initialization of PHY package * @priv_size: Size of the shared private data @priv @@ -338,7 +339,7 @@ struct mdio_bus_stats { * phy_package_leave(). */ struct phy_package_shared { - int addr; + int base_addr; refcount_t refcnt; unsigned long flags; size_t priv_size; @@ -1972,10 +1973,10 @@ int phy_ethtool_get_link_ksettings(struct net_device *ndev, int phy_ethtool_set_link_ksettings(struct net_device *ndev, const struct ethtool_link_ksettings *cmd); int phy_ethtool_nway_reset(struct net_device *ndev); -int phy_package_join(struct phy_device *phydev, int addr, size_t priv_size); +int phy_package_join(struct phy_device *phydev, int base_addr, size_t priv_size); void phy_package_leave(struct phy_device *phydev); int devm_phy_package_join(struct device *dev, struct phy_device *phydev, - int addr, size_t priv_size); + int base_addr, size_t priv_size); int __init mdio_bus_init(void); void mdio_bus_exit(void); @@ -1998,46 +1999,54 @@ int __phy_hwtstamp_set(struct phy_device *phydev, struct kernel_hwtstamp_config *config, struct netlink_ext_ack *extack); -static inline int phy_package_read(struct phy_device *phydev, u32 regnum) +static inline int phy_package_read(struct phy_device *phydev, + unsigned int addr_offset, u32 regnum) { struct phy_package_shared *shared = phydev->shared; + int addr = shared->base_addr + addr_offset; - if (!shared) + if (addr >= PHY_MAX_ADDR) return -EIO; - return mdiobus_read(phydev->mdio.bus, shared->addr, regnum); + return mdiobus_read(phydev->mdio.bus, addr, regnum); } -static inline int __phy_package_read(struct phy_device *phydev, u32 regnum) +static inline int __phy_package_read(struct phy_device *phydev, + unsigned int addr_offset, u32 regnum) { struct phy_package_shared *shared = phydev->shared; + int addr = shared->base_addr + addr_offset; - if (!shared) + if (addr >= PHY_MAX_ADDR) return -EIO; - return __mdiobus_read(phydev->mdio.bus, shared->addr, regnum); + return __mdiobus_read(phydev->mdio.bus, addr, regnum); } static inline int phy_package_write(struct phy_device *phydev, - u32 regnum, u16 val) + unsigned int addr_offset, u32 regnum, + u16 val) { struct phy_package_shared *shared = phydev->shared; + int addr = shared->base_addr + addr_offset; - if (!shared) + if (addr >= PHY_MAX_ADDR) return -EIO; - return mdiobus_write(phydev->mdio.bus, shared->addr, regnum, val); + return mdiobus_write(phydev->mdio.bus, addr, regnum, val); } static inline int __phy_package_write(struct phy_device *phydev, - u32 regnum, u16 val) + unsigned int addr_offset, u32 regnum, + u16 val) { struct phy_package_shared *shared = phydev->shared; + int addr = shared->base_addr + addr_offset; - if (!shared) + if (addr >= PHY_MAX_ADDR) return -EIO; - return __mdiobus_write(phydev->mdio.bus, shared->addr, regnum, val); + return __mdiobus_write(phydev->mdio.bus, addr, regnum, val); } static inline bool __phy_package_set_once(struct phy_device *phydev, From patchwork Wed Dec 13 10:57:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 177866 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp7688682dys; Wed, 13 Dec 2023 02:58:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IFpLd3HJzxNoQJbSKRx0J1TRduwJFUDxmVdH1Bhjal2N7t8+/3YO/dI4KRqOtsfWlbV+pR3 X-Received: by 2002:a05:6e02:1baf:b0:35d:59a2:6901 with SMTP id n15-20020a056e021baf00b0035d59a26901mr10294458ili.46.1702465119240; Wed, 13 Dec 2023 02:58:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702465119; cv=none; d=google.com; s=arc-20160816; b=L5631D0G9MSTnN4EtII+M0jMTQ0WEK4ledJwg0hY4worRFqvFTjOdwSnCZbG0QkeIC wiusoEzSJu0+tHXdEfy/c2ulfx7UkNvWyIWydx0KdevWjN8unAMt5+pvRLXcg+lulzA9 gfqPpF4e/9qaXiq/n6Okok8PGmCuQrm4sfMIB3UlZ1DjAMGgAW7R8sIYduLGg8ThIEee 4MmgOjZAVnWkDrd5qEWd8mLe8sJvtFv1YEK7uaP9OKk7aEwml/KrZCXRJtPOAbavjQkQ NQiPCqiXKfMlYImUsyqHKIcEeCbcWQayqh12ocDZBnNcrCzrl+yNN6PWADipp4hqOWdt Iv0A== 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=3PtocJM18WUz/9bnwDNM1XbvsGaiWt5uOf7PvLbW1SQ=; fh=e4NTAZpYxJjO9KGOmyKA8buDcaE3F5PQ5hdNGG6SGOA=; b=yduIEQWi/+KPqb+XcFH8tLmkvD1Nc9D5rF7CZN+aMLQiO6g39z+TF3+XzTg20uSdDn VDa1M+tkLSxu/gHWTIRJvv157dtUnmpcym53R9nnr7EvEXkBiMKbOZRG0HgcIwQh0abe pPEMyMYkl+YQa+O2tN1MQFcf7iS6MBonNkLHr+9Mw6feR3Celwy9gyjQu7xrC3xbtpH/ VD9sRKJF5zIw2uGmbsB4PeiC01sTH/s0eUtpA9/kYE92kvFDRnc63IMtMiI243dYvmOe z0Xpwm2o5M9BGqTrf+JBQ+Lu3kGsqlXaiCjZlcQkGWM0AOQ5Jwj8qt0VcssqDZ4s3+bB mfQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=c6qAI960; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id bv129-20020a632e87000000b0056a36ac322fsi9010203pgb.514.2023.12.13.02.58.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 02:58:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=c6qAI960; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 3C9B38220131; Wed, 13 Dec 2023 02:58:29 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378325AbjLMK6S (ORCPT + 99 others); Wed, 13 Dec 2023 05:58:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235389AbjLMK6K (ORCPT ); Wed, 13 Dec 2023 05:58:10 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B427F110; Wed, 13 Dec 2023 02:58:07 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-40c1e3ea2f2so66996335e9.2; Wed, 13 Dec 2023 02:58:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702465086; x=1703069886; 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=3PtocJM18WUz/9bnwDNM1XbvsGaiWt5uOf7PvLbW1SQ=; b=c6qAI960XOriwdyW/CqBexgivKhbvfULx6wpp5jy9r7jBW755QkxkBGBO2X8SzSarA YGwkbCR6Tlg5TX7+fypTATv0LZChUW+KHp6q3T/xSbBBiEdaSBXlZ2CmrxENWXCxArdf R4X6kFss1CiCOWmost9TW/zU33JUG5+J4DbVtvGHb7dzfOcY0dRiHI5HmfnPaayJ3Agv S1kP6iGkIe3lOexZ8tLp1l8I+VV38oBfijkYHpt5EPfFyzgJuWrt9qf7BQ8SPoFJGOjd 8eRAIMDWLH3LLo1A32IBnZKrsOgFsihSn28NEJtAGZmDl3uakq/WlG6RdqL5kUlG1yvZ 44/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702465086; x=1703069886; 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=3PtocJM18WUz/9bnwDNM1XbvsGaiWt5uOf7PvLbW1SQ=; b=QteZzSWBujUVxDsMOjPehX1BOVmdsNkzgIU7l2an6JobOE9k5HM6H/jx210GWMDHFt Ly5LoJX/OqZ9unyjZUa2TxPMKcBSgzwyeDMqjzEYQzYHpB5uOu8fSiSLRNOUSyueTnYX QlM/LSdc4sU66tnUeLMd/D/43M6rSDj7yb9pE7S5i80m3GGiduISGdrkGCrxeHuF+tJ8 PXKqQq00DfCebAy5mjymq8BW5xGbHe8hRQt9foOJ+RnJmGYIHMzPrqYabE5ZNs1JZlwR bum7GWXqVv30r8Cg3UruvvWVS+5+fhvy4HJoltB7OCBldp6ou7Xekib+kMVr8N9188Qp jtUg== X-Gm-Message-State: AOJu0YwVj6GUCWh/MD5//3N1w7eOSud+dXg6O8xha6LgpxTB2LrDY8NL BsQ/YKzbksnG6QBJdt8ZDuI= X-Received: by 2002:a7b:c419:0:b0:40b:5e1b:54a9 with SMTP id k25-20020a7bc419000000b0040b5e1b54a9mr4834446wmi.53.1702465085289; Wed, 13 Dec 2023 02:58:05 -0800 (PST) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id a11-20020a05600c348b00b0040b400711f5sm22432385wmq.7.2023.12.13.02.58.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 02:58:04 -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 , Harini Katakam , Christian Marangi , Simon Horman , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [net-next PATCH v6 2/3] net: phy: restructure __phy_write/read_mmd to helper and phydev user Date: Wed, 13 Dec 2023 11:57:29 +0100 Message-Id: <20231213105730.1731-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231213105730.1731-1-ansuelsmth@gmail.com> References: <20231213105730.1731-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email 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 (howler.vger.email [0.0.0.0]); Wed, 13 Dec 2023 02:58:29 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785164064503724117 X-GMAIL-MSGID: 1785164064503724117 Restructure phy_write_mmd and phy_read_mmd to implement generic helper for direct mdiobus access for mmd and use these helper for phydev user. This is needed in preparation of PHY package API that requires generic access to the mdiobus and are deatched from phydev struct but instead access them based on PHY package base_addr and offsets. Signed-off-by: Christian Marangi Reviewed-by: Russell King (Oracle) --- Changes v3: - Move to phy-core.c instead of inline in phy.h Changes v2: - Introduce this patch drivers/net/phy/phy-core.c | 64 ++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c index 966c93cbe616..b729ac8b2640 100644 --- a/drivers/net/phy/phy-core.c +++ b/drivers/net/phy/phy-core.c @@ -540,6 +540,28 @@ static void mmd_phy_indirect(struct mii_bus *bus, int phy_addr, int devad, devad | MII_MMD_CTRL_NOINCR); } +static int mmd_phy_read(struct mii_bus *bus, int phy_addr, bool is_c45, + int devad, u32 regnum) +{ + if (is_c45) + return __mdiobus_c45_read(bus, phy_addr, devad, regnum); + + mmd_phy_indirect(bus, phy_addr, devad, regnum); + /* Read the content of the MMD's selected register */ + return __mdiobus_read(bus, phy_addr, MII_MMD_DATA); +} + +static int mmd_phy_write(struct mii_bus *bus, int phy_addr, bool is_c45, + int devad, u32 regnum, u16 val) +{ + if (is_c45) + return __mdiobus_c45_write(bus, phy_addr, devad, regnum, val); + + mmd_phy_indirect(bus, phy_addr, devad, regnum); + /* Write the data into MMD's selected register */ + return __mdiobus_write(bus, phy_addr, MII_MMD_DATA, val); +} + /** * __phy_read_mmd - Convenience function for reading a register * from an MMD on a given PHY. @@ -551,26 +573,14 @@ static void mmd_phy_indirect(struct mii_bus *bus, int phy_addr, int devad, */ int __phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum) { - int val; - 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 (phydev->is_c45) { - 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; + if (phydev->drv && phydev->drv->read_mmd) + return phydev->drv->read_mmd(phydev, devad, regnum); - mmd_phy_indirect(bus, phy_addr, devad, regnum); - - /* Read the content of the MMD's selected register */ - val = __mdiobus_read(bus, phy_addr, MII_MMD_DATA); - } - return val; + return mmd_phy_read(phydev->mdio.bus, phydev->mdio.addr, + phydev->is_c45, devad, regnum); } EXPORT_SYMBOL(__phy_read_mmd); @@ -607,28 +617,14 @@ EXPORT_SYMBOL(phy_read_mmd); */ int __phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val) { - 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 (phydev->is_c45) { - 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; + if (phydev->drv && phydev->drv->write_mmd) + return phydev->drv->write_mmd(phydev, devad, regnum, val); - mmd_phy_indirect(bus, phy_addr, devad, regnum); - - /* Write the data into MMD's selected register */ - __mdiobus_write(bus, phy_addr, MII_MMD_DATA, val); - - ret = 0; - } - return ret; + return mmd_phy_write(phydev->mdio.bus, phydev->mdio.addr, + phydev->is_c45, devad, regnum, val); } EXPORT_SYMBOL(__phy_write_mmd); From patchwork Wed Dec 13 10:57:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 177867 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp7688752dys; Wed, 13 Dec 2023 02:58:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IG/AXo3yUjswC2G6Ys/RE7lgKx1eZkiB3JO7uPe68m3AaUybZOJsp0Y2chdDMRzA2o6OEuH X-Received: by 2002:a05:6808:1708:b0:3b8:bb04:dab5 with SMTP id bc8-20020a056808170800b003b8bb04dab5mr8058914oib.52.1702465129604; Wed, 13 Dec 2023 02:58:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702465129; cv=none; d=google.com; s=arc-20160816; b=drgQhb/vY0N/2zG+Y0sYJlAYvwM91zYtCk9WnSPHs4gs99i/ev/uOgNHku+k7Hl8vE +nXhbmx31YxvgTtTvr1efHOKQrDwNEvIwzPxp1MfALwO/9V+OB2kIyHVID7ZGWxV7PXV FHgtUIaB68F7ePB6+UHITrbBXE/tHUze07+E9dG4kXG+FFigGANbOCkfjsIqnJaqCwQO N4sgjQXMzTeixT98B9MTgYD4NiDCPGhJuccn+auSQHhPp1u5Rh7psW9/hupJYCg7/VyT eLpf0QB1EqDOplnczkYhNd68345rldjFPj3aPu15EMXlNGpL9NQcRZDOLXM67t8o7kkt gR6w== 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=VjlDFU5MqEyExkF6mm44V/gH6aZZAPAMOeMwXvyUDrw=; fh=e4NTAZpYxJjO9KGOmyKA8buDcaE3F5PQ5hdNGG6SGOA=; b=G4jYmhUb1d+KEkboq49Dsh7Dl3hFukxTs+KsEgF3nx7+Igj0l7DuXFlNlInzTEy0el q9hBCMcDhGPTsNykITgWDaof7RG0Y7ily57Oxxak4C/QJTCS9TpX36/sagouQrusv9o2 mQaopu7lNtdQ7EIk299O8/ltVc1yHbIfqrRP1P5jjcmCtbSbRyh8wkXFttafLpUC2UHS xrfRquEVYtVJqRMNrNNYgSYSFOnoNlsxcyL5bfNuxr4HHAVTdxAabE65wHu6YpRHaxZ6 XxZNcLXwaF/1fBDsAFxmzMId87+8azg9lOowx23TwzZLELgZTRmSxz2ypPhoQou20Hr7 y8dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=REiI0Mf1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id fd3-20020a056a002e8300b006ce7e4a9afasi9582038pfb.200.2023.12.13.02.58.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 02:58:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=REiI0Mf1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id CAFA5803E8FA; Wed, 13 Dec 2023 02:58:46 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235415AbjLMK6X (ORCPT + 99 others); Wed, 13 Dec 2023 05:58:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235393AbjLMK6K (ORCPT ); Wed, 13 Dec 2023 05:58:10 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D429F7; Wed, 13 Dec 2023 02:58:08 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-40c256ffdbcso69222025e9.2; Wed, 13 Dec 2023 02:58:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702465087; x=1703069887; 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=VjlDFU5MqEyExkF6mm44V/gH6aZZAPAMOeMwXvyUDrw=; b=REiI0Mf1hNfvYNbYSPmMP8QNM5wBMHmN+aIpx4YoFcrSCtmrDgpIePa64CYV/h2PlP BKlfdvTNOmjYPDjpfYCcNWKaQb3uVRqH5xQ6HJkIHHIMCjxXYmLCy2ffjXnCHqJPWuhw CiDevJkPM84E9H2BMsVfiCff08RUxyh6y4jEa4B8gfkIWI1aW3qzotG4gmQt/7TabMC8 tbFlHJrxRit1k1Gz+Ks46YXpyU056PHb5agkKyP3zwPFnubKSHuxBDM3RZKOnsKve0I0 xgXh7pGufbGDr75ob/0QjbfjyjHqvUYLAa7SqxMbkTmM2Jbr80S+t9c2JEkfjdzX02Jp JPAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702465087; x=1703069887; 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=VjlDFU5MqEyExkF6mm44V/gH6aZZAPAMOeMwXvyUDrw=; b=h1ubtXFM5nojLZ+c0SztHyOyqTjWlIapKsyL3uN9DNnXKxqjtuUlwtmy0gwUq7+nGy DtXV1x2VB/Va4KfCeH+0mNovCDQN+0D7zFGMBl492gZdDABpvsPCv3f45LMadW+mnxYG ZGZy1u9Zic//l6NzYLlOPn3HpASSzpjIGwQRKdtWRDVuKFYp/aR1DHGEGyljBeIl3Z+f L1DzJpajlCTC5gQFYF/OTM46zFcEqJoF7ZHuiRRBBY7yu5+bBb80XmN2ewEMq5DfUJ/v Eglin06lMT090qWqIBWK74LOR0olhgN2Jfom5bU+h14XpgovK5TLdmZbi4IbdailH/jT 1Xrg== X-Gm-Message-State: AOJu0YzyKXUrzf69XzGvuPbKMtsf1MCpa02MSLGzSKSBzlYCnanDI09l vf99JkD+4sQ7N4RpMmRcRnI= X-Received: by 2002:a05:600c:4507:b0:40c:2b2b:6429 with SMTP id t7-20020a05600c450700b0040c2b2b6429mr3900738wmo.67.1702465086682; Wed, 13 Dec 2023 02:58:06 -0800 (PST) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id a11-20020a05600c348b00b0040b400711f5sm22432385wmq.7.2023.12.13.02.58.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 02:58:06 -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 , Harini Katakam , Christian Marangi , Simon Horman , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [net-next PATCH v6 3/3] net: phy: add support for PHY package MMD read/write Date: Wed, 13 Dec 2023 11:57:30 +0100 Message-Id: <20231213105730.1731-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231213105730.1731-1-ansuelsmth@gmail.com> References: <20231213105730.1731-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email 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 (lipwig.vger.email [0.0.0.0]); Wed, 13 Dec 2023 02:58:46 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785164075835390511 X-GMAIL-MSGID: 1785164075835390511 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 v6: - Fix copy paste error for kdoc 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..4c5927197557 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) {