summaryrefslogtreecommitdiffstats
path: root/src/net/netdevice.c
diff options
context:
space:
mode:
authorMichael Brown2009-06-24 13:52:38 +0200
committerMichael Brown2009-06-24 14:04:36 +0200
commita310d00d37f8362b48913972927bfb78e7d7586d (patch)
tree8cd343a5de2c6ab1c3f4b825daba09f5a631d101 /src/net/netdevice.c
parent[comboot] Implement INT 22h AX=000Bh (Get Serial Console Configuration) (diff)
downloadipxe-a310d00d37f8362b48913972927bfb78e7d7586d.tar.gz
ipxe-a310d00d37f8362b48913972927bfb78e7d7586d.tar.xz
ipxe-a310d00d37f8362b48913972927bfb78e7d7586d.zip
[netdevice] Add mechanism for reporting detailed link status codes
Expand the NETDEV_LINK_UP bit into a link_rc status code field, allowing specific reasons for link failure to be reported via "ifstat". Originally-authored-by: Joshua Oreman <oremanj@rwcr.net>
Diffstat (limited to 'src/net/netdevice.c')
-rw-r--r--src/net/netdevice.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/net/netdevice.c b/src/net/netdevice.c
index c3551ea4..e16ebaa0 100644
--- a/src/net/netdevice.c
+++ b/src/net/netdevice.c
@@ -30,6 +30,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <gpxe/process.h>
#include <gpxe/init.h>
#include <gpxe/device.h>
+#include <gpxe/errortab.h>
#include <gpxe/netdevice.h>
/** @file
@@ -44,6 +45,34 @@ struct list_head net_devices = LIST_HEAD_INIT ( net_devices );
/** List of open network devices, in reverse order of opening */
struct list_head open_net_devices = LIST_HEAD_INIT ( open_net_devices );
+/** Default link status code */
+#define EUNKNOWN_LINK_STATUS EINPROGRESS
+
+/** Human-readable message for the default link status */
+struct errortab netdev_errors[] __errortab = {
+ { EUNKNOWN_LINK_STATUS, "Unknown" },
+};
+
+/**
+ * Mark network device as having link down
+ *
+ * @v netdev Network device
+ */
+void netdev_link_down ( struct net_device *netdev ) {
+
+ switch ( netdev->link_rc ) {
+ case 0:
+ case -EUNKNOWN_LINK_STATUS:
+ netdev->link_rc = -ENOTCONN;
+ break;
+ default:
+ /* Avoid clobbering a more detailed link status code,
+ * if one is already set.
+ */
+ break;
+ }
+}
+
/**
* Record network device statistic
*
@@ -302,6 +331,7 @@ struct net_device * alloc_netdev ( size_t priv_size ) {
netdev = zalloc ( total_len );
if ( netdev ) {
netdev->refcnt.free = free_netdev;
+ netdev->link_rc = -EUNKNOWN_LINK_STATUS;
INIT_LIST_HEAD ( &netdev->tx_queue );
INIT_LIST_HEAD ( &netdev->rx_queue );
netdev_settings_init ( netdev );