mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master] mdio_bus: return 0xFFFF when read fails with error code
Date: Thu,  2 May 2024 17:17:23 +0200	[thread overview]
Message-ID: <20240502151723.3964267-1-a.fatoum@pengutronix.de> (raw)

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




             reply	other threads:[~2024-05-02 15:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-02 15:17 Ahmad Fatoum [this message]
2024-05-03  6:51 ` Sascha Hauer

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=20240502151723.3964267-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.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