wkz / phytool

Linux MDIO register access
GNU General Public License v2.0
154 stars 78 forks source link

phytool always reads eth0 even though eth1 specified #12

Closed k3wals closed 1 year ago

k3wals commented 1 year ago

I'm working on a TI AM335x based embedded system that has two PHYs and uses cpsw. I noticed that regardless of if I specify eth0 or eth1, I always get data for eth0 when using phytool.

For purpose of demonstration, I have only one of my interfaces connected (eth0). As you can see, phytool eth1/0/1 reports back the same register value as eth0. ethtool reports correctly.

root@hostname:~# cat /sys/class/net/eth0/carrier
1
root@hostname:~# phytool eth0/0/1
root@hostname:~# ethtool eth0 | grep detected
        Link detected: yes
ieee-phy: reg:BMSR(0x01) val:0x796d
   capabilities:   -100-b4 +100-f +100-h +10-f +10-h -100-t2-f -100-t2-h
   flags:          +ext-status +aneg-complete -remote-fault +aneg-capable +link -jabber +ext-register
                                                                           ^^^^
root@hostname:~# cat /sys/class/net/eth1/carrier
0
root@hostname:~# ethtool eth1 | grep detected
        Link detected: no
root@hostname:~# phytool eth1/0/1
ieee-phy: reg:BMSR(0x01) val:0x796d
   capabilities:   -100-b4 +100-f +100-h +10-f +10-h -100-t2-f -100-t2-h
   flags:          +ext-status +aneg-complete -remote-fault +aneg-capable +link -jabber +ext-register
                                                                           ^^^^
wkz commented 1 year ago

My quess is that you have to specify the correct PHY address.

phytool read IFACE/ADDR/REG

Means read REG from PHY using address ADDR on the MDIO bus to which IFACE's PHY is attached. I.e., if eth0 and eth1 are using PHYs that are attached to the same underlying MDIO bus, then your two commands will be equivalent.

This should give you what you want:

phytool eth0/$(ethtool eth0 | awk '/PHYAD:/ { print($2); }')/1 phytool eth1/$(ethtool eth1 | awk '/PHYAD:/ { print($2); }')/1

I realize that this is not very user-friendly at all. In time, I hope to provide a much better interface using mdio-tools. Once I solve wkz/mdio-tools#22, this should all work much better.

k3wals commented 1 year ago

This is a good work-around. Thanks.