From: Russell King <rmk+kernel@armlinux.org.uk>
To: "David S. Miller" <davem@davemloft.net>
Cc: Vladimir Oltean <olteanv@gmail.com>, Andrew Lunn <andrew@lunn.ch>,
Florian Fainelli <f.fainelli@gmail.com>,
Heiner Kallweit <hkallweit1@gmail.com>,
netdev@vger.kernel.org
Subject: [PATCH net-next 2/4] net: phy: allow Clause 45 access via mii ioctl
Date: Mon, 20 May 2019 16:22:05 +0100 [thread overview]
Message-ID: <E1hSk73-0000vz-UE@rmk-PC.armlinux.org.uk> (raw)
In-Reply-To: <20190520152134.qyka5t7c2i7drk4a@shell.armlinux.org.uk>
Allow userspace to generate Clause 45 MII access cycles via phylib.
This is useful for tools such as mii-diag to be able to inspect Clause
45 PHYs.
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
---
drivers/net/phy/phy.c | 33 ++++++++++++++++++++++++---------
1 file changed, 24 insertions(+), 9 deletions(-)
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index e8885429293a..cd8990e34905 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -407,6 +407,7 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd)
struct mii_ioctl_data *mii_data = if_mii(ifr);
u16 val = mii_data->val_in;
bool change_autoneg = false;
+ int prtad, devad;
switch (cmd) {
case SIOCGMIIPHY:
@@ -414,14 +415,29 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd)
/* fall through */
case SIOCGMIIREG:
- mii_data->val_out = mdiobus_read(phydev->mdio.bus,
- mii_data->phy_id,
- mii_data->reg_num);
+ if (mdio_phy_id_is_c45(mii_data->phy_id)) {
+ prtad = mdio_phy_id_prtad(mii_data->phy_id);
+ devad = mdio_phy_id_devad(mii_data->phy_id);
+ devad = MII_ADDR_C45 | devad << 16 | mii_data->reg_num;
+ } else {
+ prtad = mii_data->phy_id;
+ devad = mii_data->reg_num;
+ }
+ mii_data->val_out = mdiobus_read(phydev->mdio.bus, prtad,
+ devad);
return 0;
case SIOCSMIIREG:
- if (mii_data->phy_id == phydev->mdio.addr) {
- switch (mii_data->reg_num) {
+ if (mdio_phy_id_is_c45(mii_data->phy_id)) {
+ prtad = mdio_phy_id_prtad(mii_data->phy_id);
+ devad = mdio_phy_id_devad(mii_data->phy_id);
+ devad = MII_ADDR_C45 | devad << 16 | mii_data->reg_num;
+ } else {
+ prtad = mii_data->phy_id;
+ devad = mii_data->reg_num;
+ }
+ if (prtad == phydev->mdio.addr) {
+ switch (devad) {
case MII_BMCR:
if ((val & (BMCR_RESET | BMCR_ANENABLE)) == 0) {
if (phydev->autoneg == AUTONEG_ENABLE)
@@ -454,11 +470,10 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd)
}
}
- mdiobus_write(phydev->mdio.bus, mii_data->phy_id,
- mii_data->reg_num, val);
+ mdiobus_write(phydev->mdio.bus, prtad, devad, val);
- if (mii_data->phy_id == phydev->mdio.addr &&
- mii_data->reg_num == MII_BMCR &&
+ if (prtad == phydev->mdio.addr &&
+ devad == MII_BMCR &&
val & BMCR_RESET)
return phy_init_hw(phydev);
--
2.7.4
next prev parent reply other threads:[~2019-05-20 15:22 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-20 15:21 [PATCH net-next 0/4] phylink/sfp updates Russell King - ARM Linux admin
2019-05-20 15:22 ` [PATCH net-next 1/4] net: phylink: support for link gpio interrupt Russell King
2019-05-20 18:22 ` Florian Fainelli
2019-05-20 18:31 ` Russell King - ARM Linux admin
2019-05-20 15:22 ` Russell King [this message]
2019-05-20 18:23 ` [PATCH net-next 2/4] net: phy: allow Clause 45 access via mii ioctl Florian Fainelli
2019-05-20 15:22 ` [PATCH net-next 3/4] net: sfp: add mandatory attach/detach methods for sfp buses Russell King
2019-05-20 18:24 ` Florian Fainelli
2019-05-20 15:22 ` [PATCH net-next 4/4] net: sfp: remove sfp-bus use of netdevs Russell King
2019-05-20 18:25 ` Florian Fainelli
2019-05-20 15:40 ` [PATCH net-next 0/4] phylink/sfp updates Vladimir Oltean
2019-05-22 17:34 ` David Miller
2019-05-28 9:56 ` [PATCH net-next 0/5] " Russell King - ARM Linux admin
2019-05-28 9:57 ` [PATCH net-next 1/5] net: phylink: remove netdev from phylink mii ioctl emulation Russell King
2019-05-28 15:19 ` Andrew Lunn
2019-05-28 9:57 ` [PATCH net-next 2/5] net: phylink: support for link gpio interrupt Russell King
2019-05-28 10:02 ` Russell King - ARM Linux admin
2019-05-29 21:21 ` David Miller
2019-05-28 9:57 ` [PATCH net-next 3/5] net: phy: allow Clause 45 access via mii ioctl Russell King
2019-05-28 12:54 ` Vladimir Oltean
2019-05-28 13:27 ` Russell King - ARM Linux admin
2019-05-28 15:31 ` Andrew Lunn
2019-05-28 9:57 ` [PATCH net-next 4/5] net: sfp: add mandatory attach/detach methods for sfp buses Russell King
2019-05-28 15:21 ` Andrew Lunn
2019-05-28 9:57 ` [PATCH net-next 5/5] net: sfp: remove sfp-bus use of netdevs Russell King
2019-05-28 15:21 ` Andrew Lunn
2019-05-31 19:39 ` [PATCH net-next 0/5] phylink/sfp updates David Miller
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=E1hSk73-0000vz-UE@rmk-PC.armlinux.org.uk \
--to=rmk+kernel@armlinux.org.uk \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=f.fainelli@gmail.com \
--cc=hkallweit1@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.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;
as well as URLs for NNTP newsgroup(s).