diff options
author | Michael Brown <mcb30@etherboot.org> | 2008-04-22 17:40:50 +0100 |
---|---|---|
committer | Michael Brown <mcb30@etherboot.org> | 2008-04-22 17:40:50 +0100 |
commit | 1ba959c6b342b314dfb01ca0a926ed6832c090b3 (patch) | |
tree | d977e301ebfe46d76f9def376e9edb173b96eb26 /src/usr | |
parent | d72bf13b788104aa4c853800c5627c1074d30ca7 (diff) | |
download | ipxe-1ba959c6b342b314dfb01ca0a926ed6832c090b3.zip ipxe-1ba959c6b342b314dfb01ca0a926ed6832c090b3.tar.gz ipxe-1ba959c6b342b314dfb01ca0a926ed6832c090b3.tar.bz2 |
[NETDEV] Add notion of link state
Add ability for network devices to flag link up/down state to the
networking core.
Autobooting code will now wait for link-up before attempting DHCP.
IPoIB reflects the Infiniband link state as the network device link state
(which is not strictly correct; we also need a succesful IPoIB IPv4
broadcast group join), but is probably more informative.
Diffstat (limited to 'src/usr')
-rw-r--r-- | src/usr/autoboot.c | 11 | ||||
-rw-r--r-- | src/usr/ifmgmt.c | 24 |
2 files changed, 34 insertions, 1 deletions
diff --git a/src/usr/autoboot.c b/src/usr/autoboot.c index c1a61ec..cff6e95 100644 --- a/src/usr/autoboot.c +++ b/src/usr/autoboot.c @@ -38,6 +38,9 @@ * */ +/** Time to wait for link-up */ +#define LINK_WAIT_MS 15000 + /** * Identify the boot network device * @@ -136,6 +139,14 @@ static int netboot ( struct net_device *netdev ) { return rc; ifstat ( netdev ); + /* Wait for link-up */ + printf ( "Waiting for link-up on %s...", netdev->name ); + if ( ( rc = iflinkwait ( netdev, LINK_WAIT_MS ) ) != 0 ) { + printf ( " no link detected\n" ); + return rc; + } + printf ( " ok\n" ); + /* Configure device via DHCP */ if ( ( rc = dhcp ( netdev ) ) != 0 ) return rc; diff --git a/src/usr/ifmgmt.c b/src/usr/ifmgmt.c index 5f4323d..9c88ab5 100644 --- a/src/usr/ifmgmt.c +++ b/src/usr/ifmgmt.c @@ -18,8 +18,11 @@ #include <string.h> #include <stdio.h> +#include <unistd.h> +#include <errno.h> #include <gpxe/netdevice.h> #include <gpxe/device.h> +#include <gpxe/process.h> #include <usr/ifmgmt.h> /** @file @@ -61,9 +64,28 @@ void ifclose ( struct net_device *netdev ) { * @v netdev Network device */ void ifstat ( struct net_device *netdev ) { - printf ( "%s: %s on %s (%s) TX:%d TXE:%d RX:%d RXE:%d\n", + printf ( "%s: %s on %s (%s)\n" + " [Link:%s, TX:%d TXE:%d RX:%d RXE:%d]\n", netdev->name, netdev_hwaddr ( netdev ), netdev->dev->name, ( ( netdev->state & NETDEV_OPEN ) ? "open" : "closed" ), + ( netdev_link_ok ( netdev ) ? "up" : "down" ), netdev->stats.tx_ok, netdev->stats.tx_err, netdev->stats.rx_ok, netdev->stats.rx_err ); } + +/** + * Wait for link-up + * + * @v netdev Network device + * @v max_wait_ms Maximum time to wait, in ms + */ +int iflinkwait ( struct net_device *netdev, unsigned int max_wait_ms ) { + while ( 1 ) { + if ( netdev_link_ok ( netdev ) ) + return 0; + if ( max_wait_ms-- == 0 ) + return -ETIMEDOUT; + step(); + mdelay ( 1 ); + } +} |