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.
23 #include <gpxe/netdevice.h>
24 #include <gpxe/device.h>
25 #include <gpxe/process.h>
26 #include <usr/ifmgmt.h>
30 * Network interface management
37 * @v netdev Network device
38 * @ret rc Return status code
40 int ifopen ( struct net_device *netdev ) {
43 if ( ( rc = netdev_open ( netdev ) ) != 0 ) {
44 printf ( "Could not open %s: %s\n",
45 netdev->name, strerror ( rc ) );
53 * Close network device
55 * @v netdev Network device
57 void ifclose ( struct net_device *netdev ) {
58 netdev_close ( netdev );
62 * Print network device error breakdown
64 * @v stats Network device statistics
65 * @v prefix Message prefix
67 static void ifstat_errors ( struct net_device_stats *stats,
68 const char *prefix ) {
71 for ( i = 0 ; i < ( sizeof ( stats->errors ) /
72 sizeof ( stats->errors[0] ) ) ; i++ ) {
73 if ( stats->errors[i].count )
74 printf ( " [%s: %d x \"%s\"]\n", prefix,
75 stats->errors[i].count,
76 strerror ( stats->errors[i].rc ) );
81 * Print status of network device
83 * @v netdev Network device
85 void ifstat ( struct net_device *netdev ) {
86 printf ( "%s: %s on %s (%s)\n"
87 " [Link:%s, TX:%d TXE:%d RX:%d RXE:%d]\n",
88 netdev->name, netdev_hwaddr ( netdev ), netdev->dev->name,
89 ( ( netdev->state & NETDEV_OPEN ) ? "open" : "closed" ),
90 ( netdev_link_ok ( netdev ) ? "up" : "down" ),
91 netdev->tx_stats.good, netdev->tx_stats.bad,
92 netdev->rx_stats.good, netdev->rx_stats.bad );
93 ifstat_errors ( &netdev->tx_stats, "TXE" );
94 ifstat_errors ( &netdev->rx_stats, "RXE" );
100 * @v netdev Network device
101 * @v max_wait_ms Maximum time to wait, in ms
103 int iflinkwait ( struct net_device *netdev, unsigned int max_wait_ms ) {
105 if ( netdev_link_ok ( netdev ) )
107 if ( max_wait_ms-- == 0 )