I'm trying to write a user-space app to access devices on an MII management bus (MDIO/MDC) associated with an Ethernet controller.
I'm using code copied from mii-tool, but the method used by mii-tool to override the PHY id doesn't seem to work.
After calling an ioctl() to fill in the mii/phy details in the interface request structure, mii-tool then overrides the phy_id field like this:
static struct ifreq ifr;
ioctl(skfd, SIOCGMIIPHY, &ifr); // load ifr with mii/phy details
struct mii_ioctl_data *mii = (struct mii_ioctl_data*)&ifr.ifr_data; mii->phy_id = phyid; // override phy mii bus address But that doesn't actually seem to work. No matter what value is written to mii->phy_id, the id that ends up passed to the ethernet driver's mdio_read/write() functions is always 0.
How do I control what MII bus address is read/written by the SIOCGMIIREG and SIOCSMIIREG?