diff options
author | Daniel Verkamp | 2008-12-10 09:35:02 +0100 |
---|---|---|
committer | Michael Brown | 2009-05-26 12:37:46 +0200 |
commit | 1f80b2dcd5b889875ac40a11bf15b88b0dffc330 (patch) | |
tree | b0eef85aced64e5170864482bd885cfd2bd90492 /src/include/mii.h | |
parent | [ethernet] Update mii.h and use it in drivers that had a private copy (diff) | |
download | ipxe-1f80b2dcd5b889875ac40a11bf15b88b0dffc330.tar.gz ipxe-1f80b2dcd5b889875ac40a11bf15b88b0dffc330.tar.xz ipxe-1f80b2dcd5b889875ac40a11bf15b88b0dffc330.zip |
[ethernet] Add MII link status functions from Linux
Signed-off-by: Michael Brown <mcb30@etherboot.org>
Diffstat (limited to 'src/include/mii.h')
-rwxr-xr-x | src/include/mii.h | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/include/mii.h b/src/include/mii.h index 05c54f09..3b735d99 100755 --- a/src/include/mii.h +++ b/src/include/mii.h @@ -157,4 +157,63 @@ struct mii_if_info { void (*mdio_write) (struct net_device *dev, int phy_id, int location, int val); }; + +extern int mii_link_ok (struct mii_if_info *mii); +extern void mii_check_link (struct mii_if_info *mii); +extern unsigned int mii_check_media (struct mii_if_info *mii, + unsigned int ok_to_print, + unsigned int init_media); + + +/** + * mii_nway_result + * @negotiated: value of MII ANAR and'd with ANLPAR + * + * Given a set of MII abilities, check each bit and returns the + * currently supported media, in the priority order defined by + * IEEE 802.3u. We use LPA_xxx constants but note this is not the + * value of LPA solely, as described above. + * + * The one exception to IEEE 802.3u is that 100baseT4 is placed + * between 100T-full and 100T-half. If your phy does not support + * 100T4 this is fine. If your phy places 100T4 elsewhere in the + * priority order, you will need to roll your own function. + */ +static inline unsigned int mii_nway_result (unsigned int negotiated) +{ + unsigned int ret; + + if (negotiated & LPA_100FULL) + ret = LPA_100FULL; + else if (negotiated & LPA_100BASE4) + ret = LPA_100BASE4; + else if (negotiated & LPA_100HALF) + ret = LPA_100HALF; + else if (negotiated & LPA_10FULL) + ret = LPA_10FULL; + else + ret = LPA_10HALF; + + return ret; +} + +/** + * mii_duplex + * @duplex_lock: Non-zero if duplex is locked at full + * @negotiated: value of MII ANAR and'd with ANLPAR + * + * A small helper function for a common case. Returns one + * if the media is operating or locked at full duplex, and + * returns zero otherwise. + */ +static inline unsigned int mii_duplex (unsigned int duplex_lock, + unsigned int negotiated) +{ + if (duplex_lock) + return 1; + if (mii_nway_result(negotiated) & LPA_DUPLEX) + return 1; + return 0; +} + #endif |