wkz / mdio-tools

Low-level debug tools for MDIO devices.
GNU General Public License v2.0
66 stars 31 forks source link

Mess Up of page Register ends in wrong PHY-ID #9

Closed akaeba closed 3 years ago

akaeba commented 3 years ago

Hello WKZ,

thanks again for the great tool!

It seems that I found an interesting behaviour. If I run the tool the first time with following command:

$ sudo mdio stmmac-1
 DEV          PHY-ID  LINK
0x01  0x01410dd1  down
0x15  0x00000000  down

works the tool perfectly.

Now I mess up the page register, f.e.

$ sudo mdio stmmac-1 0x01 raw 22 6

and rerun again:

$ sudo mdio stmmac-1
 DEV          PHY-ID  LINK
0x01  0x00000000  down
0x15  0x00000000  down

Then the wrong PHY-ID is readen.

One Solution could be to check the value of the page register before read the PHY-ID. Thanks for your Help.

Best Regards, Andreas

wkz commented 3 years ago

Here's the thing: there are an enormous amount of different devices connected to MDIO buses - one class of devices, namely Alaska PHYs from Marvell, happen to use register 22 as a page register. So it would be wrong for a generic tool like mdio to try to accommodate all such quirks.

Furthermore, changing the page register of a PHY that is controlled by a kernel driver will likely lead to weird bugs during debug sessions. Been there, done that - got the t-shirt: phytool

That is why mdio has the mva (Marvell Alaska) addressing mode. So instead of this:

~$ page=$(mdio stmmac-1 phy 0x01 raw 22)
~$ # Pray that the driver does not try to access the PHY before we're done
~$ mdio stmmac-1 phy 0x01 raw 22 6
~$ mdio stmmac-1 phy 0x01 raw 16 0x000e
~$ mdio stmmac-1 phy 0x01 raw 22 $page

You can use mva like this:

~$ mdio stmmac-1 mva 0x01 raw 6:16 0x000e

In addition to being easier to use, the operation is atomic with respect to any other users of the PHY, e.g. a kernel driver.

So in summary: don't mess up the page register :smile:, use mva. If you do mess up the page register, there is no reliable way for mdio to figure that out.