Re: [PATCH master] mdio_bus: return 0xFFFF when read fails with error code

2024-05-03 Thread Sascha Hauer


On Thu, 02 May 2024 17:17:23 +0200, Ahmad Fatoum wrote:
> 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 0x, which is the natural value used for unresponsive PHYs,
> due to the pull-ups.
> 
> [...]

Applied, thanks!

[1/1] mdio_bus: return 0x when read fails with error code
  https://git.pengutronix.de/cgit/barebox/commit/?id=ff36e78033e8 (link may 
not be stable)

Best regards,
-- 
Sascha Hauer 




[PATCH master] mdio_bus: return 0xFFFF when read fails with error code

2024-05-02 Thread 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 0x, 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 0x, which is generally
understood to mean unresponsive PHY.

Signed-off-by: Ahmad Fatoum 
---
 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 : 0x;
buf++;
i -= 2;
offset += 2;
-- 
2.39.2