MMM
MMM

Reputation: 35

How to get from phy_device to net_device?

I'm trying to implement phy statistics reading by ethtool from a custom switch driver. Ethtool doesn't see the phy_driver structure I declared in my driver, because it simply has an empty dev->phydev pointer in function __ethtool_get_sset_count. I have a phydev pointer returned from MDIO bus scan, retrieved by:

mv_switch->phydev = (struct phy_device *)mv_switch->mii_bus->mdio_map[mv_switch->mdio_addr]

but can't understand how to get to the parent net_device pointer.

Upvotes: 1

Views: 460

Answers (1)

Justin Iurman
Justin Iurman

Reputation: 19016

struct phy_device has a field called attached_dev for that purpose, I guess... Proof here.

So one could assume that the following would work for your use case

struct net_device *dev = mv_switch->phydev->attached_dev;

Upvotes: 1

Related Questions