* [net-next PATCH v2 1/3] net: mdio: Add helper functions for accessing MDIO devices
@ 2021-10-22 15:59 Sean Anderson
2021-10-22 15:59 ` [net-next PATCH v2 2/3] net: phylink: Convert some users of mdiobus_* to mdiodev_* Sean Anderson
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Sean Anderson @ 2021-10-22 15:59 UTC (permalink / raw)
To: netdev, Andrew Lunn, Heiner Kallweit
Cc: Russell King, linux-kernel, Jakub Kicinski, David S . Miller,
Sean Anderson
This adds some helpers for accessing non-phy MDIO devices. They are
analogous to phy_(read|write|modify), except that they take an mdio_device
and not a phy_device.
Signed-off-by: Sean Anderson <sean.anderson@seco.com>
---
This patch was originally submitted as [1].
[1] https://lore.kernel.org/netdev/20211004191527.1610759-15-sean.anderson@seco.com/
(no changes since v1)
include/linux/mdio.h | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/include/linux/mdio.h b/include/linux/mdio.h
index f622888a4ba8..9f3587a61e14 100644
--- a/include/linux/mdio.h
+++ b/include/linux/mdio.h
@@ -352,6 +352,30 @@ int mdiobus_modify(struct mii_bus *bus, int addr, u32 regnum, u16 mask,
int mdiobus_modify_changed(struct mii_bus *bus, int addr, u32 regnum,
u16 mask, u16 set);
+static inline int mdiodev_read(struct mdio_device *mdiodev, u32 regnum)
+{
+ return mdiobus_read(mdiodev->bus, mdiodev->addr, regnum);
+}
+
+static inline int mdiodev_write(struct mdio_device *mdiodev, u32 regnum,
+ u16 val)
+{
+ return mdiobus_write(mdiodev->bus, mdiodev->addr, regnum, val);
+}
+
+static inline int mdiodev_modify(struct mdio_device *mdiodev, u32 regnum,
+ u16 mask, u16 set)
+{
+ return mdiobus_modify(mdiodev->bus, mdiodev->addr, regnum, mask, set);
+}
+
+static inline int mdiodev_modify_changed(struct mdio_device *mdiodev,
+ u32 regnum, u16 mask, u16 set)
+{
+ return mdiobus_modify_changed(mdiodev->bus, mdiodev->addr, regnum,
+ mask, set);
+}
+
static inline u32 mdiobus_c45_addr(int devad, u16 regnum)
{
return MII_ADDR_C45 | devad << MII_DEVADDR_C45_SHIFT | regnum;
--
2.25.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [net-next PATCH v2 2/3] net: phylink: Convert some users of mdiobus_* to mdiodev_*
2021-10-22 15:59 [net-next PATCH v2 1/3] net: mdio: Add helper functions for accessing MDIO devices Sean Anderson
@ 2021-10-22 15:59 ` Sean Anderson
2021-10-22 16:14 ` Russell King (Oracle)
2021-10-22 15:59 ` [net-next PATCH v2 3/3] net: Convert more " Sean Anderson
` (2 subsequent siblings)
3 siblings, 1 reply; 6+ messages in thread
From: Sean Anderson @ 2021-10-22 15:59 UTC (permalink / raw)
To: netdev, Andrew Lunn, Heiner Kallweit
Cc: Russell King, linux-kernel, Jakub Kicinski, David S . Miller,
Sean Anderson
This refactors the phylink pcs helper functions to use mdiobus_* instead
of mdiodev_*.
Signed-off-by: Sean Anderson <sean.anderson@seco.com>
---
Changes in v2:
- Rebased onto net-next/master
drivers/net/phy/phylink.c | 23 +++++++----------------
1 file changed, 7 insertions(+), 16 deletions(-)
diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index 7e93d81fa5ad..14c7d73790b4 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -2542,12 +2542,10 @@ EXPORT_SYMBOL_GPL(phylink_decode_usxgmii_word);
void phylink_mii_c22_pcs_get_state(struct mdio_device *pcs,
struct phylink_link_state *state)
{
- struct mii_bus *bus = pcs->bus;
- int addr = pcs->addr;
int bmsr, lpa;
- bmsr = mdiobus_read(bus, addr, MII_BMSR);
- lpa = mdiobus_read(bus, addr, MII_LPA);
+ bmsr = mdiodev_read(pcs, MII_BMSR);
+ lpa = mdiodev_read(pcs, MII_LPA);
if (bmsr < 0 || lpa < 0) {
state->link = false;
return;
@@ -2603,8 +2601,6 @@ int phylink_mii_c22_pcs_set_advertisement(struct mdio_device *pcs,
phy_interface_t interface,
const unsigned long *advertising)
{
- struct mii_bus *bus = pcs->bus;
- int addr = pcs->addr;
u16 adv;
switch (interface) {
@@ -2618,12 +2614,10 @@ int phylink_mii_c22_pcs_set_advertisement(struct mdio_device *pcs,
advertising))
adv |= ADVERTISE_1000XPSE_ASYM;
- return mdiobus_modify_changed(bus, addr, MII_ADVERTISE,
- 0xffff, adv);
+ return mdiodev_modify_changed(pcs, MII_ADVERTISE, 0xffff, adv);
case PHY_INTERFACE_MODE_SGMII:
- return mdiobus_modify_changed(bus, addr, MII_ADVERTISE,
- 0xffff, 0x0001);
+ return mdiodev_modify_changed(pcs, MII_ADVERTISE, 0xffff, 0x0001);
default:
/* Nothing to do for other modes */
@@ -2666,8 +2660,7 @@ int phylink_mii_c22_pcs_config(struct mdio_device *pcs, unsigned int mode,
else
bmcr = 0;
- ret = mdiobus_modify(pcs->bus, pcs->addr, MII_BMCR,
- BMCR_ANENABLE | BMCR_ISOLATE, bmcr);
+ ret = mdiodev_modify(pcs, MII_BMCR, BMCR_ANENABLE | BMCR_ISOLATE, bmcr);
if (ret < 0)
return ret;
@@ -2688,14 +2681,12 @@ EXPORT_SYMBOL_GPL(phylink_mii_c22_pcs_config);
*/
void phylink_mii_c22_pcs_an_restart(struct mdio_device *pcs)
{
- struct mii_bus *bus = pcs->bus;
- int val, addr = pcs->addr;
+ int val = mdiodev_read(pcs, MII_BMCR);
- val = mdiobus_read(bus, addr, MII_BMCR);
if (val >= 0) {
val |= BMCR_ANRESTART;
- mdiobus_write(bus, addr, MII_BMCR, val);
+ mdiodev_write(pcs, MII_BMCR, val);
}
}
EXPORT_SYMBOL_GPL(phylink_mii_c22_pcs_an_restart);
--
2.25.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [net-next PATCH v2 3/3] net: Convert more users of mdiobus_* to mdiodev_*
2021-10-22 15:59 [net-next PATCH v2 1/3] net: mdio: Add helper functions for accessing MDIO devices Sean Anderson
2021-10-22 15:59 ` [net-next PATCH v2 2/3] net: phylink: Convert some users of mdiobus_* to mdiodev_* Sean Anderson
@ 2021-10-22 15:59 ` Sean Anderson
2021-10-22 16:14 ` [net-next PATCH v2 1/3] net: mdio: Add helper functions for accessing MDIO devices Russell King (Oracle)
2021-10-24 12:50 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 6+ messages in thread
From: Sean Anderson @ 2021-10-22 15:59 UTC (permalink / raw)
To: netdev, Andrew Lunn, Heiner Kallweit
Cc: Russell King, linux-kernel, Jakub Kicinski, David S . Miller,
Sean Anderson, Florian Fainelli, George McCollister,
Kishon Vijay Abraham I, Mark Brown, Vivien Didelot,
Vladimir Oltean
This converts users of mdiobus to mdiodev using the following semantic
patch:
@@
identifier mdiodev;
expression regnum;
@@
- mdiobus_read(mdiodev->bus, mdiodev->addr, regnum)
+ mdiodev_read(mdiodev, regnum)
@@
identifier mdiodev;
expression regnum, val;
@@
- mdiobus_write(mdiodev->bus, mdiodev->addr, regnum, val)
+ mdiodev_write(mdiodev, regnum, val)
Signed-off-by: Sean Anderson <sean.anderson@seco.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
---
I am not too experienced with coccinelle, so pointers would be
appreciated. In particular, is it possible to convert things like
bus = mdiodev->bus;
addr = mdiodev->addr;
mdiobus_foo(bus, addr, ...);
in a generic way?
(no changes since v1)
drivers/base/regmap/regmap-mdio.c | 6 +++---
drivers/net/dsa/xrs700x/xrs700x_mdio.c | 12 ++++++------
drivers/phy/broadcom/phy-bcm-ns-usb3.c | 2 +-
drivers/phy/broadcom/phy-bcm-ns2-pcie.c | 6 ++----
4 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/drivers/base/regmap/regmap-mdio.c b/drivers/base/regmap/regmap-mdio.c
index 6a20201299f5..f7293040a2b1 100644
--- a/drivers/base/regmap/regmap-mdio.c
+++ b/drivers/base/regmap/regmap-mdio.c
@@ -14,7 +14,7 @@ static int regmap_mdio_read(struct mdio_device *mdio_dev, u32 reg, unsigned int
{
int ret;
- ret = mdiobus_read(mdio_dev->bus, mdio_dev->addr, reg);
+ ret = mdiodev_read(mdio_dev, reg);
if (ret < 0)
return ret;
@@ -24,7 +24,7 @@ static int regmap_mdio_read(struct mdio_device *mdio_dev, u32 reg, unsigned int
static int regmap_mdio_write(struct mdio_device *mdio_dev, u32 reg, unsigned int val)
{
- return mdiobus_write(mdio_dev->bus, mdio_dev->addr, reg, val);
+ return mdiodev_write(mdio_dev, reg, val);
}
static int regmap_mdio_c22_read(void *context, unsigned int reg, unsigned int *val)
@@ -44,7 +44,7 @@ static int regmap_mdio_c22_write(void *context, unsigned int reg, unsigned int v
if (unlikely(reg & ~REGNUM_C22_MASK))
return -ENXIO;
- return mdiobus_write(mdio_dev->bus, mdio_dev->addr, reg, val);
+ return mdiodev_write(mdio_dev, reg, val);
}
static const struct regmap_bus regmap_mdio_c22_bus = {
diff --git a/drivers/net/dsa/xrs700x/xrs700x_mdio.c b/drivers/net/dsa/xrs700x/xrs700x_mdio.c
index d01cf1073d49..127a677d1f39 100644
--- a/drivers/net/dsa/xrs700x/xrs700x_mdio.c
+++ b/drivers/net/dsa/xrs700x/xrs700x_mdio.c
@@ -31,7 +31,7 @@ static int xrs700x_mdio_reg_read(void *context, unsigned int reg,
uval = (u16)FIELD_GET(GENMASK(31, 16), reg);
- ret = mdiobus_write(mdiodev->bus, mdiodev->addr, XRS_MDIO_IBA1, uval);
+ ret = mdiodev_write(mdiodev, XRS_MDIO_IBA1, uval);
if (ret < 0) {
dev_err(dev, "xrs mdiobus_write returned %d\n", ret);
return ret;
@@ -39,13 +39,13 @@ static int xrs700x_mdio_reg_read(void *context, unsigned int reg,
uval = (u16)((reg & GENMASK(15, 1)) | XRS_IB_READ);
- ret = mdiobus_write(mdiodev->bus, mdiodev->addr, XRS_MDIO_IBA0, uval);
+ ret = mdiodev_write(mdiodev, XRS_MDIO_IBA0, uval);
if (ret < 0) {
dev_err(dev, "xrs mdiobus_write returned %d\n", ret);
return ret;
}
- ret = mdiobus_read(mdiodev->bus, mdiodev->addr, XRS_MDIO_IBD);
+ ret = mdiodev_read(mdiodev, XRS_MDIO_IBD);
if (ret < 0) {
dev_err(dev, "xrs mdiobus_read returned %d\n", ret);
return ret;
@@ -64,7 +64,7 @@ static int xrs700x_mdio_reg_write(void *context, unsigned int reg,
u16 uval;
int ret;
- ret = mdiobus_write(mdiodev->bus, mdiodev->addr, XRS_MDIO_IBD, (u16)val);
+ ret = mdiodev_write(mdiodev, XRS_MDIO_IBD, (u16)val);
if (ret < 0) {
dev_err(dev, "xrs mdiobus_write returned %d\n", ret);
return ret;
@@ -72,7 +72,7 @@ static int xrs700x_mdio_reg_write(void *context, unsigned int reg,
uval = (u16)FIELD_GET(GENMASK(31, 16), reg);
- ret = mdiobus_write(mdiodev->bus, mdiodev->addr, XRS_MDIO_IBA1, uval);
+ ret = mdiodev_write(mdiodev, XRS_MDIO_IBA1, uval);
if (ret < 0) {
dev_err(dev, "xrs mdiobus_write returned %d\n", ret);
return ret;
@@ -80,7 +80,7 @@ static int xrs700x_mdio_reg_write(void *context, unsigned int reg,
uval = (u16)((reg & GENMASK(15, 1)) | XRS_IB_WRITE);
- ret = mdiobus_write(mdiodev->bus, mdiodev->addr, XRS_MDIO_IBA0, uval);
+ ret = mdiodev_write(mdiodev, XRS_MDIO_IBA0, uval);
if (ret < 0) {
dev_err(dev, "xrs mdiobus_write returned %d\n", ret);
return ret;
diff --git a/drivers/phy/broadcom/phy-bcm-ns-usb3.c b/drivers/phy/broadcom/phy-bcm-ns-usb3.c
index b1adaecc26f8..bbfad209c890 100644
--- a/drivers/phy/broadcom/phy-bcm-ns-usb3.c
+++ b/drivers/phy/broadcom/phy-bcm-ns-usb3.c
@@ -183,7 +183,7 @@ static int bcm_ns_usb3_mdio_phy_write(struct bcm_ns_usb3 *usb3, u16 reg,
{
struct mdio_device *mdiodev = usb3->mdiodev;
- return mdiobus_write(mdiodev->bus, mdiodev->addr, reg, value);
+ return mdiodev_write(mdiodev, reg, value);
}
static int bcm_ns_usb3_mdio_probe(struct mdio_device *mdiodev)
diff --git a/drivers/phy/broadcom/phy-bcm-ns2-pcie.c b/drivers/phy/broadcom/phy-bcm-ns2-pcie.c
index 4c7d11d2b378..9e7434a0d3e0 100644
--- a/drivers/phy/broadcom/phy-bcm-ns2-pcie.c
+++ b/drivers/phy/broadcom/phy-bcm-ns2-pcie.c
@@ -29,14 +29,12 @@ static int ns2_pci_phy_init(struct phy *p)
int rc;
/* select the AFE 100MHz block page */
- rc = mdiobus_write(mdiodev->bus, mdiodev->addr,
- BLK_ADDR_REG_OFFSET, PLL_AFE1_100MHZ_BLK);
+ rc = mdiodev_write(mdiodev, BLK_ADDR_REG_OFFSET, PLL_AFE1_100MHZ_BLK);
if (rc)
goto err;
/* set the 100 MHz reference clock amplitude to 2.05 v */
- rc = mdiobus_write(mdiodev->bus, mdiodev->addr,
- PLL_CLK_AMP_OFFSET, PLL_CLK_AMP_2P05V);
+ rc = mdiodev_write(mdiodev, PLL_CLK_AMP_OFFSET, PLL_CLK_AMP_2P05V);
if (rc)
goto err;
--
2.25.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [net-next PATCH v2 1/3] net: mdio: Add helper functions for accessing MDIO devices
2021-10-22 15:59 [net-next PATCH v2 1/3] net: mdio: Add helper functions for accessing MDIO devices Sean Anderson
2021-10-22 15:59 ` [net-next PATCH v2 2/3] net: phylink: Convert some users of mdiobus_* to mdiodev_* Sean Anderson
2021-10-22 15:59 ` [net-next PATCH v2 3/3] net: Convert more " Sean Anderson
@ 2021-10-22 16:14 ` Russell King (Oracle)
2021-10-24 12:50 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 6+ messages in thread
From: Russell King (Oracle) @ 2021-10-22 16:14 UTC (permalink / raw)
To: Sean Anderson
Cc: netdev, Andrew Lunn, Heiner Kallweit, linux-kernel,
Jakub Kicinski, David S . Miller
On Fri, Oct 22, 2021 at 11:59:12AM -0400, Sean Anderson wrote:
> This adds some helpers for accessing non-phy MDIO devices. They are
> analogous to phy_(read|write|modify), except that they take an mdio_device
> and not a phy_device.
>
> Signed-off-by: Sean Anderson <sean.anderson@seco.com>
Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Thanks.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [net-next PATCH v2 2/3] net: phylink: Convert some users of mdiobus_* to mdiodev_*
2021-10-22 15:59 ` [net-next PATCH v2 2/3] net: phylink: Convert some users of mdiobus_* to mdiodev_* Sean Anderson
@ 2021-10-22 16:14 ` Russell King (Oracle)
0 siblings, 0 replies; 6+ messages in thread
From: Russell King (Oracle) @ 2021-10-22 16:14 UTC (permalink / raw)
To: Sean Anderson
Cc: netdev, Andrew Lunn, Heiner Kallweit, linux-kernel,
Jakub Kicinski, David S . Miller
On Fri, Oct 22, 2021 at 11:59:13AM -0400, Sean Anderson wrote:
> This refactors the phylink pcs helper functions to use mdiobus_* instead
> of mdiodev_*.
>
> Signed-off-by: Sean Anderson <sean.anderson@seco.com>
Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [net-next PATCH v2 1/3] net: mdio: Add helper functions for accessing MDIO devices
2021-10-22 15:59 [net-next PATCH v2 1/3] net: mdio: Add helper functions for accessing MDIO devices Sean Anderson
` (2 preceding siblings ...)
2021-10-22 16:14 ` [net-next PATCH v2 1/3] net: mdio: Add helper functions for accessing MDIO devices Russell King (Oracle)
@ 2021-10-24 12:50 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-10-24 12:50 UTC (permalink / raw)
To: Sean Anderson
Cc: netdev, andrew, hkallweit1, linux, linux-kernel, kuba, davem
Hello:
This series was applied to netdev/net-next.git (master)
by David S. Miller <davem@davemloft.net>:
On Fri, 22 Oct 2021 11:59:12 -0400 you wrote:
> This adds some helpers for accessing non-phy MDIO devices. They are
> analogous to phy_(read|write|modify), except that they take an mdio_device
> and not a phy_device.
>
> Signed-off-by: Sean Anderson <sean.anderson@seco.com>
> ---
> This patch was originally submitted as [1].
>
> [...]
Here is the summary with links:
- [net-next,v2,1/3] net: mdio: Add helper functions for accessing MDIO devices
https://git.kernel.org/netdev/net-next/c/0ebecb2644c8
- [net-next,v2,2/3] net: phylink: Convert some users of mdiobus_* to mdiodev_*
https://git.kernel.org/netdev/net-next/c/c8fb89a7a7d1
- [net-next,v2,3/3] net: Convert more users of mdiobus_* to mdiodev_*
https://git.kernel.org/netdev/net-next/c/65aa371ea52a
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-10-24 12:50 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-22 15:59 [net-next PATCH v2 1/3] net: mdio: Add helper functions for accessing MDIO devices Sean Anderson
2021-10-22 15:59 ` [net-next PATCH v2 2/3] net: phylink: Convert some users of mdiobus_* to mdiodev_* Sean Anderson
2021-10-22 16:14 ` Russell King (Oracle)
2021-10-22 15:59 ` [net-next PATCH v2 3/3] net: Convert more " Sean Anderson
2021-10-22 16:14 ` [net-next PATCH v2 1/3] net: mdio: Add helper functions for accessing MDIO devices Russell King (Oracle)
2021-10-24 12:50 ` patchwork-bot+netdevbpf
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).