From: Jose Abreu <jose.abreu@synopsys.com>
To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Jose Abreu <jose.abreu@synopsys.com>,
Andrew Lunn <andrew@lunn.ch>,
Florian Fainelli <f.fainelli@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Joao Pinto <joao.pinto@synopsys.com>
Subject: [PATCH net] net: phy: Don't assume loopback is supported
Date: Thu, 14 Mar 2019 11:37:21 +0100 [thread overview]
Message-ID: <eeea080649153eefafef8ff93274733fe8f25b01.1552559796.git.joabreu@synopsys.com> (raw)
Some PHYs may not support loopback mode so we need to check if register
is read-only.
Fixes: f0f9b4ed2338 ("net: phy: Add phy loopback support in net phy framework")
Signed-off-by: Jose Abreu <joabreu@synopsys.com>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Joao Pinto <joao.pinto@synopsys.com>
---
drivers/net/phy/phy_device.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 49fdd1ee798e..a749639d98c3 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1918,8 +1918,24 @@ EXPORT_SYMBOL(genphy_resume);
int genphy_loopback(struct phy_device *phydev, bool enable)
{
- return phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK,
- enable ? BMCR_LOOPBACK : 0);
+ int ret;
+
+ ret = phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK,
+ enable ? BMCR_LOOPBACK : 0);
+ if (ret < 0)
+ return ret;
+
+ ret = phy_read(phydev, MII_BMCR);
+ if (ret < 0)
+ return ret;
+
+ if (enable) {
+ if (ret & BMCR_LOOPBACK)
+ return 0;
+ return -EOPNOTSUPP;
+ }
+
+ return 0;
}
EXPORT_SYMBOL(genphy_loopback);
--
2.7.4
next reply other threads:[~2019-03-14 10:38 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-14 10:37 Jose Abreu [this message]
2019-03-15 22:43 ` [PATCH net] net: phy: Don't assume loopback is supported David Miller
2019-03-15 22:48 ` Florian Fainelli
2019-03-17 18:38 ` Andrew Lunn
2019-03-18 12:46 ` Jose Abreu
2019-03-18 14:19 ` Andrew Lunn
2019-03-15 23:14 ` Heiner Kallweit
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=eeea080649153eefafef8ff93274733fe8f25b01.1552559796.git.joabreu@synopsys.com \
--to=jose.abreu@synopsys.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=f.fainelli@gmail.com \
--cc=joao.pinto@synopsys.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/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).