aboutsummaryrefslogtreecommitdiffstats
path: root/gpxe/src/include/gpxe/netdevice.h
diff options
context:
space:
mode:
Diffstat (limited to 'gpxe/src/include/gpxe/netdevice.h')
-rw-r--r--gpxe/src/include/gpxe/netdevice.h135
1 files changed, 103 insertions, 32 deletions
diff --git a/gpxe/src/include/gpxe/netdevice.h b/gpxe/src/include/gpxe/netdevice.h
index f1585de0..858d8e97 100644
--- a/gpxe/src/include/gpxe/netdevice.h
+++ b/gpxe/src/include/gpxe/netdevice.h
@@ -7,6 +7,8 @@
*
*/
+FILE_LICENCE ( GPL2_OR_LATER );
+
#include <stdint.h>
#include <gpxe/list.h>
#include <gpxe/tables.h>
@@ -19,11 +21,26 @@ struct net_protocol;
struct ll_protocol;
struct device;
-/** Maximum length of a link-layer address */
+/** Maximum length of a hardware address
+ *
+ * The longest currently-supported link-layer address is for IPoIB.
+ */
+#define MAX_HW_ADDR_LEN 8
+
+/** Maximum length of a link-layer address
+ *
+ * The longest currently-supported link-layer address is for IPoIB.
+ */
#define MAX_LL_ADDR_LEN 20
-/** Maximum length of a link-layer header */
-#define MAX_LL_HEADER_LEN 6
+/** Maximum length of a link-layer header
+ *
+ * The longest currently-supported link-layer header is for 802.11: a
+ * 24-byte frame header plus an 8-byte 802.3 LLC/SNAP header. (The
+ * IPoIB link-layer pseudo-header doesn't actually include link-layer
+ * addresses; see ipoib.c for details).
+ */
+#define MAX_LL_HEADER_LEN 32
/** Maximum length of a network-layer address */
#define MAX_NET_ADDR_LEN 4
@@ -78,30 +95,41 @@ struct ll_protocol {
/**
* Add link-layer header
*
+ * @v netdev Network device
* @v iobuf I/O buffer
* @v ll_dest Link-layer destination address
* @v ll_source Source link-layer address
* @v net_proto Network-layer protocol, in network-byte order
* @ret rc Return status code
*/
- int ( * push ) ( struct io_buffer *iobuf, const void *ll_dest,
- const void *ll_source, uint16_t net_proto );
+ int ( * push ) ( struct net_device *netdev, struct io_buffer *iobuf,
+ const void *ll_dest, const void *ll_source,
+ uint16_t net_proto );
/**
* Remove link-layer header
*
+ * @v netdev Network device
* @v iobuf I/O buffer
* @ret ll_dest Link-layer destination address
* @ret ll_source Source link-layer address
* @ret net_proto Network-layer protocol, in network-byte order
* @ret rc Return status code
*/
- int ( * pull ) ( struct io_buffer *iobuf, const void **ll_dest,
- const void **ll_source, uint16_t *net_proto );
+ int ( * pull ) ( struct net_device *netdev, struct io_buffer *iobuf,
+ const void **ll_dest, const void **ll_source,
+ uint16_t *net_proto );
+ /**
+ * Initialise link-layer address
+ *
+ * @v hw_addr Hardware address
+ * @v ll_addr Link-layer address to fill in
+ */
+ void ( * init_addr ) ( const void *hw_addr, void *ll_addr );
/**
* Transcribe link-layer address
*
- * @v ll_addr Link-layer address
- * @ret string Human-readable transcription of address
+ * @v ll_addr Link-layer address
+ * @ret string Human-readable transcription of address
*
* This method should convert the link-layer address into a
* human-readable format.
@@ -109,28 +137,35 @@ struct ll_protocol {
* The buffer used to hold the transcription is statically
* allocated.
*/
- const char * ( * ntoa ) ( const void * ll_addr );
+ const char * ( * ntoa ) ( const void *ll_addr );
/**
* Hash multicast address
*
- * @v af Address family
- * @v net_addr Network-layer address
- * @v ll_addr Link-layer address to fill in
- * @ret rc Return status code
+ * @v af Address family
+ * @v net_addr Network-layer address
+ * @v ll_addr Link-layer address to fill in
+ * @ret rc Return status code
*/
int ( * mc_hash ) ( unsigned int af, const void *net_addr,
void *ll_addr );
+ /**
+ * Generate Ethernet-compatible compressed link-layer address
+ *
+ * @v ll_addr Link-layer address
+ * @v eth_addr Ethernet-compatible address to fill in
+ */
+ int ( * eth_addr ) ( const void *ll_addr, void *eth_addr );
/** Link-layer protocol
*
* This is an ARPHRD_XXX constant, in network byte order.
*/
uint16_t ll_proto;
+ /** Hardware address length */
+ uint8_t hw_addr_len;
/** Link-layer address length */
uint8_t ll_addr_len;
/** Link-layer header length */
uint8_t ll_header_len;
- /** Link-layer broadcast address */
- const uint8_t *ll_broadcast;
};
/** Network device operations */
@@ -241,17 +276,35 @@ struct net_device {
/** Link-layer protocol */
struct ll_protocol *ll_protocol;
+ /** Hardware address
+ *
+ * This is an address which is an intrinsic property of the
+ * hardware, e.g. an address held in EEPROM.
+ *
+ * Note that the hardware address may not be the same length
+ * as the link-layer address.
+ */
+ uint8_t hw_addr[MAX_HW_ADDR_LEN];
/** Link-layer address
*
- * For Ethernet, this is the MAC address.
+ * This is the current link-layer address assigned to the
+ * device. It can be changed at runtime.
*/
uint8_t ll_addr[MAX_LL_ADDR_LEN];
+ /** Link-layer broadcast address */
+ const uint8_t *ll_broadcast;
/** Current device state
*
* This is the bitwise-OR of zero or more NETDEV_XXX constants.
*/
unsigned int state;
+ /** Link status code
+ *
+ * Zero indicates that the link is up; any other value
+ * indicates the error preventing link-up.
+ */
+ int link_rc;
/** Maximum packet length
*
* This length includes any link-layer headers.
@@ -267,7 +320,7 @@ struct net_device {
struct net_device_stats rx_stats;
/** Configuration settings applicable to this device */
- struct simple_settings settings;
+ struct generic_settings settings;
/** Driver private data */
void *priv;
@@ -276,17 +329,21 @@ struct net_device {
/** Network device is open */
#define NETDEV_OPEN 0x0001
-/** Network device has link */
-#define NETDEV_LINK_UP 0x0002
+/** Link-layer protocol table */
+#define LL_PROTOCOLS __table ( struct ll_protocol, "ll_protocols" )
/** Declare a link-layer protocol */
-#define __ll_protocol __table ( struct ll_protocol, ll_protocols, 01 )
+#define __ll_protocol __table_entry ( LL_PROTOCOLS, 01 )
+
+/** Network-layer protocol table */
+#define NET_PROTOCOLS __table ( struct net_protocol, "net_protocols" )
/** Declare a network-layer protocol */
-#define __net_protocol __table ( struct net_protocol, net_protocols, 01 )
+#define __net_protocol __table_entry ( NET_PROTOCOLS, 01 )
extern struct list_head net_devices;
extern struct net_device_operations null_netdev_operations;
+extern struct settings_operations netdev_settings_operations;
/**
* Initialise a network device
@@ -312,12 +369,12 @@ static inline void netdev_nullify ( struct net_device *netdev ) {
}
/**
- * Get printable network device hardware address
+ * Get printable network device link-layer address
*
* @v netdev Network device
- * @ret name Hardware address
+ * @ret name Link-layer address
*/
-static inline const char * netdev_hwaddr ( struct net_device *netdev ) {
+static inline const char * netdev_addr ( struct net_device *netdev ) {
return netdev->ll_protocol->ntoa ( netdev->ll_addr );
}
@@ -378,23 +435,38 @@ netdev_settings ( struct net_device *netdev ) {
}
/**
+ * Initialise a per-netdevice configuration settings block
+ *
+ * @v generics Generic settings block
+ * @v refcnt Containing object reference counter, or NULL
+ * @v name Settings block name
+ */
+static inline __attribute__ (( always_inline )) void
+netdev_settings_init ( struct net_device *netdev ) {
+ generic_settings_init ( &netdev->settings,
+ &netdev->refcnt, netdev->name );
+ netdev->settings.settings.op = &netdev_settings_operations;
+}
+
+/**
* 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;
+ netdev->link_rc = 0;
}
/**
- * Mark network device as having link down
+ * Mark network device as having link down due to a specific error
*
* @v netdev Network device
+ * @v rc Link status code
*/
static inline __attribute__ (( always_inline )) void
-netdev_link_down ( struct net_device *netdev ) {
- netdev->state &= ~NETDEV_LINK_UP;
+netdev_link_err ( struct net_device *netdev, int rc ) {
+ netdev->link_rc = rc;
}
/**
@@ -405,9 +477,10 @@ netdev_link_down ( struct net_device *netdev ) {
*/
static inline __attribute__ (( always_inline )) int
netdev_link_ok ( struct net_device *netdev ) {
- return ( netdev->state & NETDEV_LINK_UP );
+ return ( netdev->link_rc == 0 );
}
+extern void netdev_link_down ( struct net_device *netdev );
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 );
@@ -432,8 +505,6 @@ extern int net_tx ( struct io_buffer *iobuf, struct net_device *netdev,
extern int net_rx ( struct io_buffer *iobuf, struct net_device *netdev,
uint16_t net_proto, const void *ll_source );
-extern struct settings_operations netdev_settings_operations;
-
/**
* Complete network transmission
*