[ifmgmt] Move link-up status messages from autoboot() to iflinkwait()

With the addition of link status codes, we can now display a detailed
error indication if iflinkwait() fails.

Putting the error output in iflinkwait avoids code duplication, and
gains symmetry with the other interface management routines; ifopen()
already prints an error directly if it cannot open its interface.

Modified-by: Michael Brown <mcb30@etherboot.org>
Signed-off-by: Michael Brown <mcb30@etherboot.org>
pull/1/head
Joshua Oreman 2009-06-19 02:08:21 -07:00 committed by Michael Brown
parent a310d00d37
commit 4125216a2f
2 changed files with 28 additions and 12 deletions

View File

@ -154,12 +154,8 @@ static int netboot ( struct net_device *netdev ) {
ifstat ( netdev ); ifstat ( netdev );
/* Wait for link-up */ /* Wait for link-up */
printf ( "Waiting for link-up on %s...", netdev->name ); if ( ( rc = iflinkwait ( netdev, LINK_WAIT_MS ) ) != 0 )
if ( ( rc = iflinkwait ( netdev, LINK_WAIT_MS ) ) != 0 ) {
printf ( " no link detected\n" );
return rc; return rc;
}
printf ( " ok\n" );
/* Configure device via DHCP */ /* Configure device via DHCP */
if ( ( rc = dhcp ( netdev ) ) != 0 ) if ( ( rc = dhcp ( netdev ) ) != 0 )

View File

@ -103,25 +103,45 @@ void ifstat ( struct net_device *netdev ) {
} }
/** /**
* Wait for link-up * Wait for link-up, with status indication
* *
* @v netdev Network device * @v netdev Network device
* @v max_wait_ms Maximum time to wait, in ms * @v max_wait_ms Maximum time to wait, in ms
*/ */
int iflinkwait ( struct net_device *netdev, unsigned int max_wait_ms ) { int iflinkwait ( struct net_device *netdev, unsigned int max_wait_ms ) {
int key; int key;
int rc;
while ( 1 ) {
if ( netdev_link_ok ( netdev ) ) if ( netdev_link_ok ( netdev ) )
return 0; return 0;
if ( max_wait_ms-- == 0 )
return -ETIMEDOUT; printf ( "Waiting for link-up on %s...", netdev->name );
while ( 1 ) {
if ( netdev_link_ok ( netdev ) ) {
rc = 0;
break;
}
if ( max_wait_ms-- == 0 ) {
rc = netdev->link_rc;
break;
}
step(); step();
if ( iskey() ) { if ( iskey() ) {
key = getchar(); key = getchar();
if ( key == CTRL_C ) if ( key == CTRL_C ) {
return -ECANCELED; rc = -ECANCELED;
break;
}
} }
mdelay ( 1 ); mdelay ( 1 );
} }
if ( rc == 0 ) {
printf ( " ok\n" );
} else {
printf ( " failed: %s\n", strerror ( rc ) );
}
return rc;
} }