[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.
This commit is contained in:
Michael Brown
2008-04-22 17:40:50 +01:00
parent d72bf13b78
commit 1ba959c6b3
13 changed files with 110 additions and 2 deletions

View File

@@ -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;

View File

@@ -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 );
}
}