diff options
author | Michael Brown <mcb30@ipxe.org> | 2015-03-10 21:23:51 +0000 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2015-03-10 21:31:07 +0000 |
commit | 6ad02e78bb85f5afebe3d897bc629b26f89abc17 (patch) | |
tree | d7bd31a2d9bad2b2a7a0fa3f95491f68e75e69c4 /src | |
parent | 03e71d5d1a24c1cb5babf7f56f118cbe9908cfc7 (diff) | |
download | ipxe-6ad02e78bb85f5afebe3d897bc629b26f89abc17.tar.gz |
[mii] Add generic mii_check_link() function
Most devices expose at least the link up/down status via a bit in a
MAC register, since the MAC generally already needs to know whether or
not the link is up. Some devices (e.g. the SMSC75xx USB NIC) expose
this information to software only via the MII registers.
Provide a generic mii_check_link() implementation to check the BMSR
and report the link status via netdev_link_{up,down}().
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/drivers/net/mii.c | 32 | ||||
-rw-r--r-- | src/include/ipxe/mii.h | 2 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/drivers/net/mii.c b/src/drivers/net/mii.c index 4e45874aa..9b297029a 100644 --- a/src/drivers/net/mii.c +++ b/src/drivers/net/mii.c @@ -115,3 +115,35 @@ int mii_reset ( struct mii_interface *mii ) { DBGC ( mii, "MII %p timed out waiting for reset\n", mii ); return -ETIMEDOUT; } + +/** + * Update link status via MII + * + * @v mii MII interface + * @v netdev Network device + * @ret rc Return status code + */ +int mii_check_link ( struct mii_interface *mii, struct net_device *netdev ) { + int bmsr; + int link; + int rc; + + /* Read BMSR */ + bmsr = mii_read ( mii, MII_BMSR ); + if ( bmsr < 0 ) { + rc = bmsr; + return rc; + } + + /* Report link status */ + link = ( bmsr & BMSR_LSTATUS ); + DBGC ( mii, "MII %p link %s (BMSR %#04x)\n", + mii, ( link ? "up" : "down" ), bmsr ); + if ( link ) { + netdev_link_up ( netdev ); + } else { + netdev_link_down ( netdev ); + } + + return 0; +} diff --git a/src/include/ipxe/mii.h b/src/include/ipxe/mii.h index daf29dac5..c2245b49e 100644 --- a/src/include/ipxe/mii.h +++ b/src/include/ipxe/mii.h @@ -114,5 +114,7 @@ mii_dump ( struct mii_interface *mii ) { extern int mii_restart ( struct mii_interface *mii ); extern int mii_reset ( struct mii_interface *mii ); +extern int mii_check_link ( struct mii_interface *mii, + struct net_device *netdev ); #endif /* _IPXE_MII_H */ |