From: Christian Marangi <ansuelsmth@gmail.com>
To: Florian Fainelli <florian.fainelli@broadcom.com>,
Broadcom internal kernel review list
<bcm-kernel-feedback-list@broadcom.com>,
Andrew Lunn <andrew@lunn.ch>,
Heiner Kallweit <hkallweit1@gmail.com>,
Russell King <linux@armlinux.org.uk>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Vladimir Oltean <olteanv@gmail.com>,
David Epping <david.epping@missinglinkelectronics.com>,
"Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>,
Harini Katakam <harini.katakam@amd.com>,
Christian Marangi <ansuelsmth@gmail.com>,
Simon Horman <horms@kernel.org>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [net-next PATCH v2 4/4] net: phy: add support for PHY package MMD read/write
Date: Mon, 27 Nov 2023 00:51:41 +0100 [thread overview]
Message-ID: <20231126235141.17996-4-ansuelsmth@gmail.com> (raw)
In-Reply-To: <20231126235141.17996-1-ansuelsmth@gmail.com>
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 possible to set is_c45 bool for phy_package_read/write to true to
access mmd regs for accessing C45 PHY in PHY package for global
configuration.
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
Changes v2:
- Rework to use newly introduced helper
- Add common check for regnum and devad
include/linux/phy.h | 78 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 78 insertions(+)
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 96f6f34be051..3e507bd2c3b4 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -2085,6 +2085,84 @@ 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, bool is_c45,
+ 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, is_c45, devad,
+ regnum);
+ phy_unlock_mdio_bus(phydev);
+
+ return val;
+}
+
+static inline int __phy_package_read_mmd(struct phy_device *phydev,
+ unsigned int addr_offset, bool is_c45,
+ 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, is_c45, devad,
+ regnum);
+}
+
+static inline int phy_package_write_mmd(struct phy_device *phydev,
+ unsigned int addr_offset, bool is_c45,
+ 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, is_c45, devad,
+ regnum, val);
+ phy_unlock_mdio_bus(phydev);
+
+ return ret;
+}
+
+static inline int __phy_package_write_mmd(struct phy_device *phydev,
+ unsigned int addr_offset, bool is_c45,
+ 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, is_c45, devad,
+ regnum, val);
+}
+
static inline bool __phy_package_set_once(struct phy_device *phydev,
unsigned int b)
{
--
2.40.1
next prev parent reply other threads:[~2023-11-26 23:51 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-26 23:51 [net-next PATCH v2 1/4] net: phy: extend PHY package API to support multiple global address Christian Marangi
2023-11-26 23:51 ` [net-next PATCH v2 2/4] net: phy: move mmd_phy_indirect to generic header Christian Marangi
2023-11-26 23:51 ` [net-next PATCH v2 3/4] net: phy: restructure __phy_write/read_mmd to helper and phydev user Christian Marangi
2023-11-28 0:46 ` Andrew Lunn
2023-11-28 12:11 ` Christian Marangi
2023-11-28 12:22 ` Russell King (Oracle)
2023-11-26 23:51 ` Christian Marangi [this message]
2023-11-28 0:51 ` [net-next PATCH v2 4/4] net: phy: add support for PHY package MMD read/write Andrew Lunn
2023-11-28 12:12 ` Christian Marangi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231126235141.17996-4-ansuelsmth@gmail.com \
--to=ansuelsmth@gmail.com \
--cc=andrew@lunn.ch \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=davem@davemloft.net \
--cc=david.epping@missinglinkelectronics.com \
--cc=edumazet@google.com \
--cc=florian.fainelli@broadcom.com \
--cc=harini.katakam@amd.com \
--cc=hkallweit1@gmail.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=rmk+kernel@armlinux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).