2 * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <gpxe/netdevice.h>
25 #include <gpxe/device.h>
26 #include <gpxe/process.h>
27 #include <gpxe/keys.h>
28 #include <usr/ifmgmt.h>
32 * Network interface management
39 * @v netdev Network device
40 * @ret rc Return status code
42 int ifopen ( struct net_device *netdev ) {
45 if ( ( rc = netdev_open ( netdev ) ) != 0 ) {
46 printf ( "Could not open %s: %s\n",
47 netdev->name, strerror ( rc ) );
55 * Close network device
57 * @v netdev Network device
59 void ifclose ( struct net_device *netdev ) {
60 netdev_close ( netdev );
64 * Print network device error breakdown
66 * @v stats Network device statistics
67 * @v prefix Message prefix
69 static void ifstat_errors ( struct net_device_stats *stats,
70 const char *prefix ) {
73 for ( i = 0 ; i < ( sizeof ( stats->errors ) /
74 sizeof ( stats->errors[0] ) ) ; i++ ) {
75 if ( stats->errors[i].count )
76 printf ( " [%s: %d x \"%s\"]\n", prefix,
77 stats->errors[i].count,
78 strerror ( stats->errors[i].rc ) );
83 * Print status of network device
85 * @v netdev Network device
87 void ifstat ( struct net_device *netdev ) {
88 printf ( "%s: %s on %s (%s)\n"
89 " [Link:%s, TX:%d TXE:%d RX:%d RXE:%d]\n",
90 netdev->name, netdev_hwaddr ( netdev ), netdev->dev->name,
91 ( ( netdev->state & NETDEV_OPEN ) ? "open" : "closed" ),
92 ( netdev_link_ok ( netdev ) ? "up" : "down" ),
93 netdev->tx_stats.good, netdev->tx_stats.bad,
94 netdev->rx_stats.good, netdev->rx_stats.bad );
95 ifstat_errors ( &netdev->tx_stats, "TXE" );
96 ifstat_errors ( &netdev->rx_stats, "RXE" );
102 * @v netdev Network device
103 * @v max_wait_ms Maximum time to wait, in ms
105 int iflinkwait ( struct net_device *netdev, unsigned int max_wait_ms ) {
109 if ( netdev_link_ok ( netdev ) )
111 if ( max_wait_ms-- == 0 )