Skip to contentSkip to conversation

mii_bus->read return checking in phy_device.c

DISCUSSION Florian Fainelli 2 participants 5 messages Mar 4, 2011 – Mar 7, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hello Andy,

While debugging a PHY probing issue with the au1000_eth, I stumbled upon this in drivers/net/phy/phy_device.c:

        phy_reg = bus->read(bus, addr, MII_PHYSID1);                                                  
                                   
        if (phy_reg < 0)                        
                return -EIO;

most drivers implement phylib's mdio_read callback by simply returning the contents of their MDIO register after a readl, ioread ... which is unsigned. Would not it rather make sense to check for phy_reg <= 0 instead?

This can lead for instance to believing that a PHY is present at a wrong address because the MDIO read function returns 0 for that particular register, which is logical because no PHY is present at that address.

I am asking in case I just miss something.

Thank you.
--
Florian

#1 lore raw
Quoted 5 lines · Florian Fainelli

Hello Andy,

While debugging a PHY probing issue with the au1000_eth, I stumbled upon this in drivers/net/phy/phy_device.c:

Quoted 8 lines
       phy_reg = bus->read(bus, addr, MII_PHYSID1);                                                  

       if (phy_reg < 0)                        
               return -EIO;

most drivers implement phylib's mdio_read callback by simply returning the contents of their MDIO register after a readl, ioread ... which is unsigned. Would not it rather make sense to check for phy_reg <= 0 instead?

That isn't a check for a non-existent PHY. PHY registers are unsigned 16-bit quantities. The negative 32-bit return value would be the result of something going wrong in the bus transaction.

Notice that later the code actually checks to see if the read value was mostly 1s...

Quoted 11 lines

This can lead for instance to believing that a PHY is present at a wrong address because the MDIO read function returns 0 for that particular register, which is logical because no PHY is present at that address.

I am asking in case I just miss something.

Thank you.
--
Florian

#2 lore raw
Quoted 13 lines · On Friday 04 March 2011 19:06:20 Fleming Andy-AFLEMING wrote:
Quoted 12 lines · Florian Fainelli

Hello Andy,

While debugging a PHY probing issue with the au1000_eth, I stumbled upon this

in drivers/net/phy/phy_device.c:

       phy_reg = bus->read(bus, addr, MII_PHYSID1);
       
       if (phy_reg < 0)
       
               return -EIO;
Quoted 8 lines
Quoted 4 lines

most drivers implement phylib's mdio_read callback by simply returning the contents of their MDIO register after a readl, ioread ... which is unsigned. Would not it rather make sense to check for phy_reg <= 0 instead?

That isn't a check for a non-existent PHY. PHY registers are unsigned 16-bit quantities. The negative 32-bit return value would be the result of something going wrong in the bus transaction.

Ok, but 0 is not an acceptable value either for both ID1 and ID2.

Quoted 3 lines

Notice that later the code actually checks to see if the read value was mostly 1s...

What if the MDIO bus returns 0 instead of 1? Should that be fixed to return 0xffff instead in the driver?

Quoted 15 lines
Quoted 10 lines

This can lead for instance to believing that a PHY is present at a wrong address because the MDIO read function returns 0 for that particular register, which is logical because no PHY is present at that address.

I am asking in case I just miss something.

Thank you.
--
Florian

--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
Quoted 19 lines · Florian Fainelli
Quoted 18 lines · On Friday 04 March 2011 19:06:20 Fleming Andy-AFLEMING wrote:
Quoted 16 lines · Florian Fainelli

Hello Andy,

While debugging a PHY probing issue with the au1000_eth, I stumbled upon this

in drivers/net/phy/phy_device.c:

      phy_reg = bus->read(bus, addr, MII_PHYSID1);

      if (phy_reg < 0)

              return -EIO;

most drivers implement phylib's mdio_read callback by simply returning the contents of their MDIO register after a readl, ioread ... which is unsigned. Would not it rather make sense to check for phy_reg <= 0 instead?

Quoted 5 lines
Quoted 3 lines

That isn't a check for a non-existent PHY. PHY registers are unsigned 16-bit quantities. The negative 32-bit return value would be the result of something going wrong in the bus transaction.

Ok, but 0 is not an acceptable value either for both ID1 and ID2.

I don't remember the exact details, but i recall we had a discussion about this several years ago, and decided that 0 should not be interpreted as a non-existent PHY. I know I have a part that has an internal PHY which doesnt have anything in the ID registers. If your driver is aware that it did not get a response from the PHY, it should return 0xffff. Otherwise, you can return 0, and just be aware that the PHY subsystem will believe there's a PHY there.

Quoted 24 lines
Quoted 4 lines

Notice that later the code actually checks to see if the read value was mostly 1s...

What if the MDIO bus returns 0 instead of 1? Should that be fixed to return 0xffff instead in the driver?

Quoted 15 lines
Quoted 10 lines

This can lead for instance to believing that a PHY is present at a wrong address because the MDIO read function returns 0 for that particular register, which is logical because no PHY is present at that address.

I am asking in case I just miss something.

Thank you.
--
Florian

--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
Quoted 26 lines · On Friday 04 March 2011 19:19:10 Fleming Andy-AFLEMING wrote:
Quoted 19 lines · Florian Fainelli
Quoted 18 lines · On Friday 04 March 2011 19:06:20 Fleming Andy-AFLEMING wrote:
Quoted 16 lines · Florian Fainelli

Hello Andy,

While debugging a PHY probing issue with the au1000_eth, I stumbled upon this

in drivers/net/phy/phy_device.c:

      phy_reg = bus->read(bus, addr, MII_PHYSID1);
      
      if (phy_reg < 0)
      
              return -EIO;

most drivers implement phylib's mdio_read callback by simply returning the contents of their MDIO register after a readl, ioread ... which is unsigned. Would not it rather make sense to check for phy_reg <= 0 instead?

Quoted 5 lines
Quoted 3 lines

That isn't a check for a non-existent PHY. PHY registers are unsigned 16-bit quantities. The negative 32-bit return value would be the result of something going wrong in the bus transaction.

Ok, but 0 is not an acceptable value either for both ID1 and ID2.

Quoted 7 lines

I don't remember the exact details, but i recall we had a discussion about this several years ago, and decided that 0 should not be interpreted as a non-existent PHY. I know I have a part that has an internal PHY which doesnt have anything in the ID registers. If your driver is aware that it did not get a response from the PHY, it should return 0xffff. Otherwise, you can return 0, and just be aware that the PHY subsystem will believe there's a PHY there.

Allright, thanks for the clarification, I have sorted this in platform code registering the particular ethernet driver.
--
Florian