ifmgmt.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 FILE_LICENCE ( GPL2_OR_LATER );
00020
00021 #include <string.h>
00022 #include <stdio.h>
00023 #include <unistd.h>
00024 #include <errno.h>
00025 #include <console.h>
00026 #include <gpxe/netdevice.h>
00027 #include <gpxe/device.h>
00028 #include <gpxe/process.h>
00029 #include <gpxe/keys.h>
00030 #include <usr/ifmgmt.h>
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 int ifopen ( struct net_device *netdev ) {
00045 int rc;
00046
00047 if ( ( rc = netdev_open ( netdev ) ) != 0 ) {
00048 printf ( "Could not open %s: %s\n",
00049 netdev->name, strerror ( rc ) );
00050 return rc;
00051 }
00052
00053 return 0;
00054 }
00055
00056
00057
00058
00059
00060
00061 void ifclose ( struct net_device *netdev ) {
00062 netdev_close ( netdev );
00063 }
00064
00065
00066
00067
00068
00069
00070
00071 static void ifstat_errors ( struct net_device_stats *stats,
00072 const char *prefix ) {
00073 unsigned int i;
00074
00075 for ( i = 0 ; i < ( sizeof ( stats->errors ) /
00076 sizeof ( stats->errors[0] ) ) ; i++ ) {
00077 if ( stats->errors[i].count )
00078 printf ( " [%s: %d x \"%s\"]\n", prefix,
00079 stats->errors[i].count,
00080 strerror ( stats->errors[i].rc ) );
00081 }
00082 }
00083
00084
00085
00086
00087
00088
00089 void ifstat ( struct net_device *netdev ) {
00090 printf ( "%s: %s on %s (%s)\n"
00091 " [Link:%s, TX:%d TXE:%d RX:%d RXE:%d]\n",
00092 netdev->name, netdev_addr ( netdev ), netdev->dev->name,
00093 ( netdev_is_open ( netdev ) ? "open" : "closed" ),
00094 ( netdev_link_ok ( netdev ) ? "up" : "down" ),
00095 netdev->tx_stats.good, netdev->tx_stats.bad,
00096 netdev->rx_stats.good, netdev->rx_stats.bad );
00097 if ( ! netdev_link_ok ( netdev ) ) {
00098 printf ( " [Link status: %s]\n",
00099 strerror ( netdev->link_rc ) );
00100 }
00101 ifstat_errors ( &netdev->tx_stats, "TXE" );
00102 ifstat_errors ( &netdev->rx_stats, "RXE" );
00103 }
00104
00105
00106
00107
00108
00109
00110
00111 int iflinkwait ( struct net_device *netdev, unsigned int max_wait_ms ) {
00112 int key;
00113 int rc;
00114
00115 if ( netdev_link_ok ( netdev ) )
00116 return 0;
00117
00118 printf ( "Waiting for link-up on %s...", netdev->name );
00119
00120 while ( 1 ) {
00121 if ( netdev_link_ok ( netdev ) ) {
00122 rc = 0;
00123 break;
00124 }
00125 if ( max_wait_ms-- == 0 ) {
00126 rc = netdev->link_rc;
00127 break;
00128 }
00129 step();
00130 if ( iskey() ) {
00131 key = getchar();
00132 if ( key == CTRL_C ) {
00133 rc = -ECANCELED;
00134 break;
00135 }
00136 }
00137 mdelay ( 1 );
00138 }
00139
00140 if ( rc == 0 ) {
00141 printf ( " ok\n" );
00142 } else {
00143 printf ( " failed: %s\n", strerror ( rc ) );
00144 }
00145
00146 return rc;
00147 }