From: Michael Walle <michael@walle.cc>
To: "Yisen Zhuang" <yisen.zhuang@huawei.com>,
"Salil Mehta" <salil.mehta@huawei.com>,
"David S . Miller" <davem@davemloft.net>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Florian Fainelli" <f.fainelli@gmail.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>,
"Marek Behún" <kabel@kernel.org>, "Xu Liang" <lxu@maxlinear.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Michael Walle <michael@walle.cc>
Subject: [PATCH net-next 1/5] net: phy: add error checks in mmd_phy_indirect() and export it
Date: Fri, 20 Jan 2023 23:40:07 +0100 [thread overview]
Message-ID: <20230120224011.796097-2-michael@walle.cc> (raw)
In-Reply-To: <20230120224011.796097-1-michael@walle.cc>
Add missing error checks in mmd_phy_indirect(). The error checks need to
be disabled to retain the current behavior in phy_read_mmd() and
phy_write_mmd(). Therefore, add a new parameter to enable the error
checks. Add a thin wrapper __phy_mmd_indirect() which is then exported.
Signed-off-by: Michael Walle <michael@walle.cc>
---
drivers/net/phy/phy-core.c | 44 +++++++++++++++++++++++++++++++-------
include/linux/phy.h | 2 ++
2 files changed, 38 insertions(+), 8 deletions(-)
diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c
index a64186dc53f8..c9c92b95ace2 100644
--- a/drivers/net/phy/phy-core.c
+++ b/drivers/net/phy/phy-core.c
@@ -524,19 +524,47 @@ 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)
+static int mmd_phy_indirect(struct mii_bus *bus, int phy_addr, int devad,
+ u16 regnum, bool check_rc)
{
+ int ret;
+
/* Write the desired MMD Devad */
- __mdiobus_write(bus, phy_addr, MII_MMD_CTRL, devad);
+ ret = __mdiobus_write(bus, phy_addr, MII_MMD_CTRL, devad);
+ if (check_rc && ret)
+ return ret;
/* Write the desired MMD register address */
- __mdiobus_write(bus, phy_addr, MII_MMD_DATA, regnum);
+ ret = __mdiobus_write(bus, phy_addr, MII_MMD_DATA, regnum);
+ if (check_rc && ret)
+ return ret;
/* Select the Function : DATA with no post increment */
- __mdiobus_write(bus, phy_addr, MII_MMD_CTRL,
- devad | MII_MMD_CTRL_NOINCR);
+ ret = __mdiobus_write(bus, phy_addr, MII_MMD_CTRL,
+ devad | MII_MMD_CTRL_NOINCR);
+ if (check_rc && ret)
+ return ret;
+
+ return 0;
+}
+
+/**
+ * __phy_mmd_indirect - prepare an indirect C45 register access
+ *
+ * @bus: the target MII bus
+ * @phy_addr: PHY address on the MII bus
+ * @devad: The target MMD (0..31)
+ * @regnum: The target register on the MMD (0..65535)
+ *
+ * Prepare an indirect C45 read or write transfer using the MII_MMD_CTRL and
+ * MII_MMD_DATA registers in C22 space.
+ */
+int __phy_mmd_indirect(struct mii_bus *bus, int phy_addr, int devad,
+ u16 regnum)
+{
+ return mmd_phy_indirect(bus, phy_addr, devad, regnum, true);
}
+EXPORT_SYMBOL(__phy_mmd_indirect);
/**
* __phy_read_mmd - Convenience function for reading a register
@@ -563,7 +591,7 @@ int __phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum)
struct mii_bus *bus = phydev->mdio.bus;
int phy_addr = phydev->mdio.addr;
- mmd_phy_indirect(bus, phy_addr, devad, regnum);
+ mmd_phy_indirect(bus, phy_addr, devad, regnum, false);
/* Read the content of the MMD's selected register */
val = __mdiobus_read(bus, phy_addr, MII_MMD_DATA);
@@ -619,7 +647,7 @@ int __phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val)
struct mii_bus *bus = phydev->mdio.bus;
int phy_addr = phydev->mdio.addr;
- mmd_phy_indirect(bus, phy_addr, devad, regnum);
+ mmd_phy_indirect(bus, phy_addr, devad, regnum, false);
/* Write the data into MMD's selected register */
__mdiobus_write(bus, phy_addr, MII_MMD_DATA, val);
diff --git a/include/linux/phy.h b/include/linux/phy.h
index fbeba4fee8d4..f7a5e110f95c 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -1228,6 +1228,8 @@ int phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum);
__ret; \
})
+int __phy_mmd_indirect(struct mii_bus *bus, int phy_addr, int devad,
+ u16 regnum);
/*
* __phy_read_mmd - Convenience function for reading a register
* from an MMD on a given PHY.
--
2.30.2
next prev parent reply other threads:[~2023-01-20 22:40 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-20 22:40 [PATCH net-next 0/5] net: phy: C45-over-C22 access Michael Walle
2023-01-20 22:40 ` Michael Walle [this message]
2023-01-23 15:34 ` [PATCH net-next 1/5] net: phy: add error checks in mmd_phy_indirect() and export it Andrew Lunn
2023-01-20 22:40 ` [PATCH net-next 2/5] net: phy: support indirect c45 access in get_phy_c45_ids() Michael Walle
2023-01-20 22:40 ` [PATCH net-next 3/5] net: phy: add support for C45-over-C22 transfers Michael Walle
2023-01-20 22:40 ` [PATCH net-next 4/5] phy: net: introduce phy_promote_to_c45() Michael Walle
2023-01-20 23:20 ` Russell King (Oracle)
2023-01-20 23:27 ` Michael Walle
2023-01-20 22:40 ` [PATCH net-next 5/5] net: phy: mxl-gpy: remove unneeded ops Michael Walle
2023-01-23 18:03 ` [PATCH net-next 0/5] net: phy: C45-over-C22 access Andrew Lunn
2023-01-23 18:47 ` Russell King (Oracle)
2023-01-23 20:05 ` Andrew Lunn
2023-01-24 0:35 ` Michael Walle
2023-01-24 1:44 ` Andrew Lunn
2023-01-24 14:41 ` Michael Walle
2023-01-24 21:03 ` Andrew Lunn
2023-01-24 21:20 ` Michael Walle
2023-01-25 13:52 ` Andrew Lunn
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=20230120224011.796097-2-michael@walle.cc \
--to=michael@walle.cc \
--cc=andrew@lunn.ch \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=davem@davemloft.net \
--cc=f.fainelli@gmail.com \
--cc=hkallweit1@gmail.com \
--cc=kabel@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=lxu@maxlinear.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=salil.mehta@huawei.com \
--cc=yisen.zhuang@huawei.com \
/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
all inboxes | Powered by JetHome®