From 1ba959c6b342b314dfb01ca0a926ed6832c090b3 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 22 Apr 2008 17:40:50 +0100 Subject: [NETDEV] Add notion of link state Add ability for network devices to flag link up/down state to the networking core. Autobooting code will now wait for link-up before attempting DHCP. IPoIB reflects the Infiniband link state as the network device link state (which is not strictly correct; we also need a succesful IPoIB IPv4 broadcast group join), but is probably more informative. --- src/include/gpxe/errfile.h | 1 + src/include/gpxe/netdevice.h | 34 ++++++++++++++++++++++++++++++++++ src/include/usr/ifmgmt.h | 1 + 3 files changed, 36 insertions(+) (limited to 'src/include') diff --git a/src/include/gpxe/errfile.h b/src/include/gpxe/errfile.h index ae8b14809..011ff1f13 100644 --- a/src/include/gpxe/errfile.h +++ b/src/include/gpxe/errfile.h @@ -151,6 +151,7 @@ #define ERRFILE_uri_test ( ERRFILE_OTHER | 0x000b0000 ) #define ERRFILE_ibft ( ERRFILE_OTHER | 0x000c0000 ) #define ERRFILE_tls ( ERRFILE_OTHER | 0x000d0000 ) +#define ERRFILE_ifmgmt ( ERRFILE_OTHER | 0x000e0000 ) /** @} */ diff --git a/src/include/gpxe/netdevice.h b/src/include/gpxe/netdevice.h index d8cb84d08..1ef648e11 100644 --- a/src/include/gpxe/netdevice.h +++ b/src/include/gpxe/netdevice.h @@ -254,6 +254,9 @@ struct net_device { /** Network device is open */ #define NETDEV_OPEN 0x0001 +/** Network device has link */ +#define NETDEV_LINK_UP 0x0002 + /** Declare a link-layer protocol */ #define __ll_protocol __table ( struct ll_protocol, ll_protocols, 01 ) @@ -352,6 +355,37 @@ netdev_settings ( struct net_device *netdev ) { return &netdev->settings.settings; } +/** + * Mark network device as having link up + * + * @v netdev Network device + */ +static inline __attribute__ (( always_inline )) void +netdev_link_up ( struct net_device *netdev ) { + netdev->state |= NETDEV_LINK_UP; +} + +/** + * Mark network device as having link down + * + * @v netdev Network device + */ +static inline __attribute__ (( always_inline )) void +netdev_link_down ( struct net_device *netdev ) { + netdev->state &= ~NETDEV_LINK_UP; +} + +/** + * Check link state of network device + * + * @v netdev Network device + * @ret link_up Link is up + */ +static inline __attribute__ (( always_inline )) int +netdev_link_ok ( struct net_device *netdev ) { + return ( netdev->state & NETDEV_LINK_UP ); +} + extern int netdev_tx ( struct net_device *netdev, struct io_buffer *iobuf ); extern void netdev_tx_complete_err ( struct net_device *netdev, struct io_buffer *iobuf, int rc ); diff --git a/src/include/usr/ifmgmt.h b/src/include/usr/ifmgmt.h index c7d35da88..7b49d3492 100644 --- a/src/include/usr/ifmgmt.h +++ b/src/include/usr/ifmgmt.h @@ -12,5 +12,6 @@ struct net_device; extern int ifopen ( struct net_device *netdev ); extern void ifclose ( struct net_device *netdev ); extern void ifstat ( struct net_device *netdev ); +extern int iflinkwait ( struct net_device *netdev, unsigned int max_wait_ms ); #endif /* _USR_IFMGMT_H */ -- cgit v1.2.3-55-g7522