From patchwork Sun Nov 26 00:37:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13468699 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="J9v+88RD" Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53E5A111; Sat, 25 Nov 2023 16:37:57 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-332d2b6a84cso2118166f8f.0; Sat, 25 Nov 2023 16:37:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700959076; x=1701563876; 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=5L2G5Sq1174Yt3GpbAcT1mBIypZjcw/HGW1slLMQ/vE=; b=J9v+88RD/dPCE1A+++ZkCFbSixs1PTIjBuI6UXXwMwgIMWC+rhmzHNktMNNO5hU7DA 60rs08QHiuYZx/PDyYF7FFkl1Oleqg+1kxQkGtZ6G4sz4ptFAFk/thFcpS/Wpnkq0UMg F5MfwZNP6lv1R49X+jbCWshPgiwjPFB/HsBiJ9KJtwe0QYFLDdda3dH5hd+c0MK2y9Sa QFXI5ZAYnWCqIB31Qt8zKHAc4y7Dm9k8YiTcpvhVkFzB1zX5IeV1fgEKmYozupJF+VJD xtyxfdKcWJAubSSAs1v5kmK9bjJWuGfnDO7+QG73EBw4MrPBeeZUTqjgCv9KNEorzi8Y HfUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700959076; x=1701563876; 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=5L2G5Sq1174Yt3GpbAcT1mBIypZjcw/HGW1slLMQ/vE=; b=s26+NT7/LGeY/ikrDRKwyrj+Ya1bRYyLxpa7EEFtPjhNj52d3Rz013h5BSe4F10nKi BoPF50jKJ4Uy9CuDiiGDAFFeS4r/jhXZgMuheFYhvJvuBsMYUC9ek0dk/NeLTkKL8kTY ty8KKMydPg0Q450e4oFLHRpioZvu9pKaWiv3wA3S0ZMNlTUVc3lQBHler9uRxAvvD9qy ibDJFmVFckabqJV/WeoBeRHBlFoGBqv2XMm+c5PbTp8BI1uQ9zXv+1SHpkjlMbQNC1+Z 7uxoSsAPXLHUDG//nCSbLmLNzCqRfolbsmXT94VVYscdnLp/EGTojUticPZvsSWMm18k bztw== X-Gm-Message-State: AOJu0Yzh753x2V46I5nx7YhbnmbcKFfuxyn/bJG2bf3l+iwSdgX0dkTB g9Sv4jRmo9a9lIKNZ4SbpHo= X-Google-Smtp-Source: AGHT+IHN5+gxXbAqwunIKXGI3e8OrbCrA3zMZbQTpWAyKHxsrWrNUHfPGZOGKjqkYNqb0OEMjQrplg== X-Received: by 2002:a05:6000:1b0f:b0:332:eaa7:56b4 with SMTP id f15-20020a0560001b0f00b00332eaa756b4mr4560776wrz.22.1700959075416; Sat, 25 Nov 2023 16: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 v19-20020adfd053000000b0032f9688ea48sm7735249wrh.10.2023.11.25.16.37.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Nov 2023 16: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 , Harini Katakam , "Russell King (Oracle)" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [net-next PATCH 1/3] net: phy: extend PHY package API to support multiple global address Date: Sun, 26 Nov 2023 01:37:46 +0100 Message-Id: <20231126003748.9600-1-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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. Signed-off-by: Christian Marangi --- 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 | 40 ++++++++++++++++------------ include/linux/phy.h | 45 ++++++++++++++++++++------------ 5 files changed, 72 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..823b25bb3e3e 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1648,20 +1648,27 @@ 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 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. If your PHY doesn't have global registers + * you can just pick any of the PHY addresses. + * In some special PHY package, multiple PHY are used for global init of + * the entire PHY package. In this the scenario, phy_package_read() and + * phy_package_write() offset is used to communicate which PHY to use for + * global init on read/write. * * 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 +1678,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 +1700,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 +1740,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 +1759,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 +1768,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 +1778,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..8253c7871d68 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,58 @@ 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; - if (!shared) + if (!shared || shared->base_addr + addr_offset > PHY_MAX_ADDR) return -EIO; - return mdiobus_read(phydev->mdio.bus, shared->addr, regnum); + addr = shared->base_addr + addr_offset; + 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; - if (!shared) + if (!shared || shared->base_addr + addr_offset > PHY_MAX_ADDR) return -EIO; - return __mdiobus_read(phydev->mdio.bus, shared->addr, regnum); + addr = shared->base_addr + addr_offset; + 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; - if (!shared) + if (!shared || shared->base_addr + addr_offset > PHY_MAX_ADDR) return -EIO; - return mdiobus_write(phydev->mdio.bus, shared->addr, regnum, val); + addr = shared->base_addr + addr_offset; + 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; - if (!shared) + if (!shared || shared->base_addr + addr_offset > PHY_MAX_ADDR) return -EIO; - return __mdiobus_write(phydev->mdio.bus, shared->addr, regnum, val); + addr = shared->base_addr + addr_offset; + return __mdiobus_write(phydev->mdio.bus, addr, regnum, val); } static inline bool __phy_package_set_once(struct phy_device *phydev, From patchwork Sun Nov 26 00:37:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13468700 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lG99uR1O" Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CAB013E; Sat, 25 Nov 2023 16:37:58 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-332c0c32d19so2111564f8f.3; Sat, 25 Nov 2023 16:37:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700959076; x=1701563876; 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=nawp6U3vqPYo/CUc2ds9jui4s+5qr227Har9OTpQpYc=; b=lG99uR1O5q5MdIn5x/FUuSNHRbkbT4zuCVS2sNNuM/0u1/59fR8KpjUek+dcEKuFSv ahXlv0Yky0myjpzDujCjxbsUzdVAL62IJJYuqt8brYXD7SFikRF2k1v9RalwCGpD/PMf kaVoKqppu+mS6aFZ6bWRSCcLjGIu+7Nkb1Jhg7rlv+a+G/+koY1cFlEsB8VQEwYubopM 6kj3+90sU+ply1oygzMPTQuvGPh3d0Opjaf1lyY3hmKXSte7Yhh4PsK/Aqnd7Zrguwk1 D9x7WFNWRNlcbqIn9MEKNQyMT9ZwMEW74bKx/dYV/lHZHeeCyjs1MMMsSrct8CE1ozQ8 du2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700959076; x=1701563876; 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=nawp6U3vqPYo/CUc2ds9jui4s+5qr227Har9OTpQpYc=; b=iMQWcZBsfFIPZxp+/PCajrzSOpYlCbBSB2ntq4ZU1y3D4VDP8CE56jcz8utHZCACyr QEBNv3zcgJtl4Wh0kA6f7wVgJ34+RfhhSG3tUvC/lq4nGo1KDwbsgcqGl7HKVTuOkgsi RQlSNiqhHnRmjhXrhsIgDhZAiQE4ZFMZHPuweQsq5GDv/039kKFid490VFqpQB1HFnbX /3rcbxGqoZ+IYbP0FkU1gw8g5i8zaXvOWeo/lxbK9Gsp0IQ3GiBAwLI4ivHKi5FjZnlJ BMhxslDtVIC8ZiVe0Y8vLHwU1UJz2htDCJqdy3DoOQASEyxbrEs8q9Bwxd+l4bzZzTPB bBBQ== X-Gm-Message-State: AOJu0Yx/dcCcbPjYennV8fhI8oqYUY/EgFYqU0AGcUhY/JvHP//qsWLF tmTVx6CU7IdUKkjR/+W8+QM= X-Google-Smtp-Source: AGHT+IGTyfDzfPril3A5JZlueNrlqBBg6D+eglrTT/8Gw0O9pB7NEl+qeTDytozz9QqxKQl48lqJ8A== X-Received: by 2002:a5d:68cc:0:b0:332:ef1e:bb96 with SMTP id p12-20020a5d68cc000000b00332ef1ebb96mr2163557wrw.36.1700959076464; Sat, 25 Nov 2023 16:37:56 -0800 (PST) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id v19-20020adfd053000000b0032f9688ea48sm7735249wrh.10.2023.11.25.16.37.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Nov 2023 16:37:56 -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 , Harini Katakam , "Russell King (Oracle)" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [net-next PATCH 2/3] net: phy: move mmd_phy_indirect to generic header Date: Sun, 26 Nov 2023 01:37:47 +0100 Message-Id: <20231126003748.9600-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231126003748.9600-1-ansuelsmth@gmail.com> References: <20231126003748.9600-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Move mmd_phy_indirect function from phy-core to generic phy.h to permit future usage for PHY package read/write_mmd. Signed-off-by: Christian Marangi --- drivers/net/phy/phy-core.c | 14 -------------- include/linux/phy.h | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c index 966c93cbe616..b4f80847eefd 100644 --- a/drivers/net/phy/phy-core.c +++ b/drivers/net/phy/phy-core.c @@ -526,20 +526,6 @@ 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) -{ - /* Write the desired MMD Devad */ - __mdiobus_write(bus, phy_addr, MII_MMD_CTRL, devad); - - /* Write the desired MMD register address */ - __mdiobus_write(bus, phy_addr, MII_MMD_DATA, regnum); - - /* Select the Function : DATA with no post increment */ - __mdiobus_write(bus, phy_addr, MII_MMD_CTRL, - devad | MII_MMD_CTRL_NOINCR); -} - /** * __phy_read_mmd - Convenience function for reading a register * from an MMD on a given PHY. diff --git a/include/linux/phy.h b/include/linux/phy.h index 8253c7871d68..984bca9a82f4 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1316,6 +1316,20 @@ static inline int __phy_modify_changed(struct phy_device *phydev, u32 regnum, regnum, mask, set); } +static inline void mmd_phy_indirect(struct mii_bus *bus, int phy_addr, int devad, + u16 regnum) +{ + /* Write the desired MMD Devad */ + __mdiobus_write(bus, phy_addr, MII_MMD_CTRL, devad); + + /* Write the desired MMD register address */ + __mdiobus_write(bus, phy_addr, MII_MMD_DATA, regnum); + + /* Select the Function : DATA with no post increment */ + __mdiobus_write(bus, phy_addr, MII_MMD_CTRL, + devad | MII_MMD_CTRL_NOINCR); +} + /* * phy_read_mmd - Convenience function for reading a register * from an MMD on a given PHY. From patchwork Sun Nov 26 00:37:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13468701 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dqCtQy9x" Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18E6C182; Sat, 25 Nov 2023 16:37:59 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-332d2b6a84cso2118174f8f.0; Sat, 25 Nov 2023 16:37:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700959077; x=1701563877; 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=1uPUXkFTFTY3wjyppF4kZdPmBYcUNyv8eWABZcZLvEU=; b=dqCtQy9xgG5eo3lWyOVCPujrfXvDkvzHwAlLoMtWgFom2c5zBciE+6ta28FmYAnjJj 7ynfMKXA5WCJBakigtwReQJoECIGerjMcZsngMUdoC+iDWpsh5Fy1y6Iu8yqiW1A6yA+ SCQjcp7F/Hxm9v+YwG8Jlkm3BNAntfTrlDFzqR+rvjiPXHkAiGeuxIXGhhuYTmzPC4wY qUY84+Cc4N23AvCdwRhh7Hbmmu0Hn/expUrGqZsDLbbGSNiiebgLxXTZtM1r0Bpgxgj2 Ha6+ObIxcvBeElM0cvgodvjm4qwj3YPOrKPlFMSHWmRH89SlL8I7eDBoulU5xDhqhlpG 4/8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700959077; x=1701563877; 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=1uPUXkFTFTY3wjyppF4kZdPmBYcUNyv8eWABZcZLvEU=; b=a41u3qlvnBbMgnr1tRXZFw2JMupn7d9Pm3z7AON4cVrjfosrojSiZIfzNsgQZY0I4g LFS1O42slvIBLdq3bPUyAVf271N3i+0nNOK7DdFgrVqf81jYGBHB3ioACt+n1PcuZ8U6 TGP/bA1wnmxXoEkFF8M9V5y4bS8TMm0ijQSbrfqT8xZg+JRVd77cR1b94ZUtK7zB8bLS 4CPrsLumBvNUFUOWb3ZE1k94RjBLbCCFUPI5Bc2C4kqMsPw3aA/k5QVdlU1dHSYVCT23 qk4Se03QM5EfarHwHIv82PYBT4DXkTlW9qi/SUt0NbySwWxjAtiNf9sfMzt2LYfdjd1l g3nA== X-Gm-Message-State: AOJu0YzcvZtXNizTBFgZU9WKE3ulrA8IUoXeiNu8JInDYncpNn6lyxKv 4Bgo9taZBhkb6tLt8gim6l0= X-Google-Smtp-Source: AGHT+IFbjCVaPkKuump1gsxBNZe2guiftP25Uvws8RLzuh7OnwNLqC2X/9V7y2UNRbD1wave5mjM+w== X-Received: by 2002:adf:fd48:0:b0:332:e9f7:9a99 with SMTP id h8-20020adffd48000000b00332e9f79a99mr4703218wrs.43.1700959077474; Sat, 25 Nov 2023 16:37:57 -0800 (PST) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id v19-20020adfd053000000b0032f9688ea48sm7735249wrh.10.2023.11.25.16.37.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Nov 2023 16:37:57 -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 , Harini Katakam , "Russell King (Oracle)" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [net-next PATCH 3/3] net: phy: add support for PHY package MMD read/write Date: Sun, 26 Nov 2023 01:37:48 +0100 Message-Id: <20231126003748.9600-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231126003748.9600-1-ansuelsmth@gmail.com> References: <20231126003748.9600-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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. Signed-off-by: Christian Marangi --- include/linux/phy.h | 74 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/include/linux/phy.h b/include/linux/phy.h index 984bca9a82f4..1799133c8387 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -2067,6 +2067,80 @@ static inline int __phy_package_write(struct phy_device *phydev, return __mdiobus_write(phydev->mdio.bus, addr, regnum, val); } +static inline int phy_package_read_mmd(struct phy_device *phydev, + unsigned int addr_offset, int devad, + u32 regnum) +{ + struct phy_package_shared *shared = phydev->shared; + struct mii_bus *bus = phydev->mdio.bus; + int addr, val; + + if (!shared || shared->base_addr + addr_offset > PHY_MAX_ADDR) + return -EIO; + + addr = shared->base_addr + addr_offset; + + phy_lock_mdio_bus(phydev); + mmd_phy_indirect(bus, addr, devad, regnum); + val = __mdiobus_read(bus, addr, MII_MMD_DATA); + phy_unlock_mdio_bus(phydev); + + return val; +} + +static inline int __phy_package_read_mmd(struct phy_device *phydev, + unsigned int addr_offset, int devad, + u32 regnum) +{ + struct phy_package_shared *shared = phydev->shared; + struct mii_bus *bus = phydev->mdio.bus; + int addr; + + if (!shared || shared->base_addr + addr_offset > PHY_MAX_ADDR) + return -EIO; + + addr = shared->base_addr + addr_offset; + mmd_phy_indirect(bus, addr, devad, regnum); + return __mdiobus_read(bus, addr, MII_MMD_DATA); +} + +static inline 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; + struct mii_bus *bus = phydev->mdio.bus; + int addr, ret; + + if (!shared || shared->base_addr + addr_offset > PHY_MAX_ADDR) + return -EIO; + + addr = shared->base_addr + addr_offset; + + phy_lock_mdio_bus(phydev); + mmd_phy_indirect(bus, addr, devad, regnum); + ret = __mdiobus_write(bus, addr, MII_MMD_DATA, val); + phy_unlock_mdio_bus(phydev); + + return ret; +} + +static inline 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; + struct mii_bus *bus = phydev->mdio.bus; + int addr; + + if (!shared || shared->base_addr + addr_offset > PHY_MAX_ADDR) + return -EIO; + + addr = shared->base_addr + addr_offset; + mmd_phy_indirect(bus, addr, devad, regnum); + return __mdiobus_write(bus, addr, MII_MMD_DATA, val); +} + static inline bool __phy_package_set_once(struct phy_device *phydev, unsigned int b) {