summaryrefslogtreecommitdiffstats
path: root/src/usr/ifmgmt.c
diff options
context:
space:
mode:
authorMichael Brown2008-04-22 18:40:50 +0200
committerMichael Brown2008-04-22 18:40:50 +0200
commit1ba959c6b342b314dfb01ca0a926ed6832c090b3 (patch)
treed977e301ebfe46d76f9def376e9edb173b96eb26 /src/usr/ifmgmt.c
parent[Infiniband] Fix event queue doorbell ringing on Arbel (diff)
downloadipxe-1ba959c6b342b314dfb01ca0a926ed6832c090b3.tar.gz
ipxe-1ba959c6b342b314dfb01ca0a926ed6832c090b3.tar.xz
ipxe-1ba959c6b342b314dfb01ca0a926ed6832c090b3.zip
[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/ifmgmt.c')
-rw-r--r--src/usr/ifmgmt.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/usr/ifmgmt.c b/src/usr/ifmgmt.c
index 5f4323de..9c88ab53 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 );
+ }
+}