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 status of network device
64 * @v netdev Network device
66 void ifstat ( struct net_device *netdev ) {
67 printf ( "%s: %s on %s (%s)\n"
68 " [Link:%s, TX:%d TXE:%d RX:%d RXE:%d]\n",
69 netdev->name, netdev_hwaddr ( netdev ), netdev->dev->name,
70 ( ( netdev->state & NETDEV_OPEN ) ? "open" : "closed" ),
71 ( netdev_link_ok ( netdev ) ? "up" : "down" ),
72 netdev->stats.tx_ok, netdev->stats.tx_err,
73 netdev->stats.rx_ok, netdev->stats.rx_err );
79 * @v netdev Network device
80 * @v max_wait_ms Maximum time to wait, in ms
82 int iflinkwait ( struct net_device *netdev, unsigned int max_wait_ms ) {
84 if ( netdev_link_ok ( netdev ) )
86 if ( max_wait_ms-- == 0 )