mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH master] mdio_bus: return 0xFFFF when read fails with error code
@ 2024-05-02 15:17 Ahmad Fatoum
  2024-05-03  6:51 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2024-05-02 15:17 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

phy_read may return an error code if the underlying transport
misbehaves, e.g. a busy and non-recoverable I2C bus.

Instead of packing the error code value into the buffer, let's just
report 0xFFFF, which is the natural value used for unresponsive PHYs,
due to the pull-ups.

We could instead also return an error code, but this brings us quite a
bit of complexity, because we would need to decide:

  - Either use an intermediary buffer and report an error code
    immediately

  - Return an incomplete count and assume that the error condition persists
    to the follow-up read, so it can return the error code

Take the easy way out and just report 0xFFFF, which is generally
understood to mean unresponsive PHY.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/net/phy/mdio_bus.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index eed7c779e753..30d5aeacff0d 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -472,12 +472,13 @@ int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val)
 
 static ssize_t phydev_read(struct cdev *cdev, void *_buf, size_t count, loff_t offset, ulong flags)
 {
-	int i = count;
+	int ret, i = count;
 	uint16_t *buf = _buf;
 	struct phy_device *phydev = cdev->priv;
 
 	while (i > 0) {
-		*buf = phy_read(phydev, offset / 2);
+		ret = phy_read(phydev, offset / 2);
+		*buf = ret >= 0 ? ret : 0xffff;
 		buf++;
 		i -= 2;
 		offset += 2;
-- 
2.39.2




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-05-03  6:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-02 15:17 [PATCH master] mdio_bus: return 0xFFFF when read fails with error code Ahmad Fatoum
2024-05-03  6:51 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox