iPXE
netdevice.h
Go to the documentation of this file.
1#ifndef _IPXE_NETDEVICE_H
2#define _IPXE_NETDEVICE_H
3
4/** @file
5 *
6 * Network device management
7 *
8 */
9
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11FILE_SECBOOT ( PERMITTED );
12
13#include <stdint.h>
14#include <ipxe/list.h>
15#include <ipxe/tables.h>
16#include <ipxe/refcnt.h>
17#include <ipxe/settings.h>
18#include <ipxe/interface.h>
19#include <ipxe/retry.h>
20
21struct io_buffer;
22struct net_device;
23struct net_protocol;
24struct ll_protocol;
25struct device;
26
27/** Maximum length of a hardware address
28 *
29 * The longest currently-supported link-layer address is for IPoIB.
30 */
31#define MAX_HW_ADDR_LEN 8
32
33/** Maximum length of a link-layer address
34 *
35 * The longest currently-supported link-layer address is for IPoIB.
36 */
37#define MAX_LL_ADDR_LEN 20
38
39/** Maximum length of a link-layer header
40 *
41 * The longest currently-supported link-layer header is for RNDIS: an
42 * 8-byte RNDIS header, a 32-byte RNDIS packet message header, a
43 * 14-byte Ethernet header and a possible 4-byte VLAN header. Round
44 * up to 64 bytes.
45 */
46#define MAX_LL_HEADER_LEN 64
47
48/** Maximum length of a network-layer address */
49#define MAX_NET_ADDR_LEN 16
50
51/** Maximum length of a network-layer header
52 *
53 * The longest currently-supported network-layer header is for IPv6 at
54 * 40 bytes.
55 */
56#define MAX_NET_HEADER_LEN 40
57
58/** Maximum combined length of a link-layer and network-layer header */
59#define MAX_LL_NET_HEADER_LEN ( MAX_LL_HEADER_LEN + MAX_NET_HEADER_LEN )
60
61/**
62 * A network-layer protocol
63 *
64 */
66 /** Protocol name */
67 const char *name;
68 /**
69 * Process received packet
70 *
71 * @v iobuf I/O buffer
72 * @v netdev Network device
73 * @v ll_dest Link-layer destination address
74 * @v ll_source Link-layer source address
75 * @v flags Packet flags
76 * @ret rc Return status code
77 *
78 * This method takes ownership of the I/O buffer.
79 */
80 int ( * rx ) ( struct io_buffer *iobuf, struct net_device *netdev,
81 const void *ll_dest, const void *ll_source,
82 unsigned int flags );
83 /**
84 * Transcribe network-layer address
85 *
86 * @v net_addr Network-layer address
87 * @ret string Human-readable transcription of address
88 *
89 * This method should convert the network-layer address into a
90 * human-readable format (e.g. dotted quad notation for IPv4).
91 *
92 * The buffer used to hold the transcription is statically
93 * allocated.
94 */
95 const char * ( *ntoa ) ( const void * net_addr );
96 /** Network-layer protocol
97 *
98 * This is an ETH_P_XXX constant, in network-byte order
99 */
101 /** Network-layer address length */
103};
104
105/** Packet is a multicast (including broadcast) packet */
106#define LL_MULTICAST 0x0001
107
108/** Packet is a broadcast packet */
109#define LL_BROADCAST 0x0002
110
111/**
112 * A link-layer protocol
113 *
114 */
116 /** Protocol name */
117 const char *name;
118 /**
119 * Add link-layer header
120 *
121 * @v netdev Network device
122 * @v iobuf I/O buffer
123 * @v ll_dest Link-layer destination address
124 * @v ll_source Source link-layer address
125 * @v net_proto Network-layer protocol, in network-byte order
126 * @ret rc Return status code
127 */
128 int ( * push ) ( struct net_device *netdev, struct io_buffer *iobuf,
129 const void *ll_dest, const void *ll_source,
130 uint16_t net_proto );
131 /**
132 * Remove link-layer header
133 *
134 * @v netdev Network device
135 * @v iobuf I/O buffer
136 * @ret ll_dest Link-layer destination address
137 * @ret ll_source Source link-layer address
138 * @ret net_proto Network-layer protocol, in network-byte order
139 * @ret flags Packet flags
140 * @ret rc Return status code
141 */
142 int ( * pull ) ( struct net_device *netdev, struct io_buffer *iobuf,
143 const void **ll_dest, const void **ll_source,
144 uint16_t *net_proto, unsigned int *flags );
145 /**
146 * Initialise link-layer address
147 *
148 * @v hw_addr Hardware address
149 * @v ll_addr Link-layer address to fill in
150 */
151 void ( * init_addr ) ( const void *hw_addr, void *ll_addr );
152 /**
153 * Transcribe link-layer address
154 *
155 * @v ll_addr Link-layer address
156 * @ret string Human-readable transcription of address
157 *
158 * This method should convert the link-layer address into a
159 * human-readable format.
160 *
161 * The buffer used to hold the transcription is statically
162 * allocated.
163 */
164 const char * ( * ntoa ) ( const void *ll_addr );
165 /**
166 * Hash multicast address
167 *
168 * @v af Address family
169 * @v net_addr Network-layer address
170 * @v ll_addr Link-layer address to fill in
171 * @ret rc Return status code
172 */
173 int ( * mc_hash ) ( unsigned int af, const void *net_addr,
174 void *ll_addr );
175 /**
176 * Generate Ethernet-compatible compressed link-layer address
177 *
178 * @v ll_addr Link-layer address
179 * @v eth_addr Ethernet-compatible address to fill in
180 * @ret rc Return status code
181 */
182 int ( * eth_addr ) ( const void *ll_addr, void *eth_addr );
183 /**
184 * Generate EUI-64 address
185 *
186 * @v ll_addr Link-layer address
187 * @v eui64 EUI-64 address to fill in
188 * @ret rc Return status code
189 */
190 int ( * eui64 ) ( const void *ll_addr, void *eui64 );
191 /** Link-layer protocol
192 *
193 * This is an ARPHRD_XXX constant, in network byte order.
194 */
196 /** Hardware address length */
198 /** Link-layer address length */
200 /** Link-layer header length */
202 /** Flags */
203 unsigned int flags;
204};
205
206/** Local link-layer address functions only as a name
207 *
208 * This flag indicates that the local link-layer address cannot
209 * directly be used as a destination address by a remote node.
210 */
211#define LL_NAME_ONLY 0x0001
212
213/** Network device operations */
215 /** Open network device
216 *
217 * @v netdev Network device
218 * @ret rc Return status code
219 *
220 * This method should allocate RX I/O buffers and enable
221 * the hardware to start transmitting and receiving packets.
222 */
223 int ( * open ) ( struct net_device *netdev );
224 /** Close network device
225 *
226 * @v netdev Network device
227 *
228 * This method should stop the flow of packets, and free up
229 * any packets that are currently in the device's TX queue.
230 */
231 void ( * close ) ( struct net_device *netdev );
232 /** Transmit packet
233 *
234 * @v netdev Network device
235 * @v iobuf I/O buffer
236 * @ret rc Return status code
237 *
238 * This method should cause the hardware to initiate
239 * transmission of the I/O buffer.
240 *
241 * If this method returns success, the I/O buffer remains
242 * owned by the net device's TX queue, and the net device must
243 * eventually call netdev_tx_complete() to free the buffer.
244 * If this method returns failure, the I/O buffer is
245 * immediately released; the failure is interpreted as
246 * "failure to enqueue buffer".
247 *
248 * This method is guaranteed to be called only when the device
249 * is open.
250 *
251 * If the network device has an associated DMA device, then
252 * the I/O buffer will be automatically mapped for transmit
253 * DMA.
254 */
255 int ( * transmit ) ( struct net_device *netdev,
256 struct io_buffer *iobuf );
257 /** Poll for completed and received packets
258 *
259 * @v netdev Network device
260 *
261 * This method should cause the hardware to check for
262 * completed transmissions and received packets. Any received
263 * packets should be delivered via netdev_rx().
264 *
265 * This method is guaranteed to be called only when the device
266 * is open.
267 */
268 void ( * poll ) ( struct net_device *netdev );
269 /** Enable or disable interrupts
270 *
271 * @v netdev Network device
272 * @v enable Interrupts should be enabled
273 *
274 * This method may be NULL to indicate that interrupts are not
275 * supported.
276 */
277 void ( * irq ) ( struct net_device *netdev, int enable );
278};
279
280/** Network device error */
282 /** Error status code */
283 int rc;
284 /** Error count */
285 unsigned int count;
286};
287
288/** Maximum number of unique errors that we will keep track of */
289#define NETDEV_MAX_UNIQUE_ERRORS 4
290
291/** Network device statistics */
293 /** Count of successful completions */
294 unsigned int good;
295 /** Count of error completions */
296 unsigned int bad;
297 /** Error breakdowns */
299};
300
301/** A network device configuration */
303 /** Network device */
305 /** Network device configurator */
307 /** Configuration status */
308 int rc;
309 /** Job control interface */
311};
312
313/** A network device configurator */
315 /** Name */
316 const char *name;
317 /** Check applicability of configurator
318 *
319 * @v netdev Network device
320 * @ret applies Configurator applies to this network device
321 */
322 int ( * applies ) ( struct net_device *netdev );
323 /** Start configuring network device
324 *
325 * @v job Job control interface
326 * @v netdev Network device
327 * @ret rc Return status code
328 */
329 int ( * start ) ( struct interface *job, struct net_device *netdev );
330};
331
332/** Network device configurator table */
333#define NET_DEVICE_CONFIGURATORS \
334 __table ( struct net_device_configurator, "net_device_configurators" )
335
336/** Declare a network device configurator */
337#define __net_device_configurator \
338 __table_entry ( NET_DEVICE_CONFIGURATORS, 01 )
339
340/** Maximum length of a network device name */
341#define NETDEV_NAME_LEN 12
342
343/**
344 * A network device
345 *
346 * This structure represents a piece of networking hardware. It has
347 * properties such as a link-layer address and methods for
348 * transmitting and receiving raw packets.
349 *
350 * Note that this structure must represent a generic network device,
351 * not just an Ethernet device.
352 */
354 /** Reference counter */
356 /** List of network devices */
358 /** List of open network devices */
360 /** Scope ID */
361 unsigned int scope_id;
362 /** Name of this network device */
364 /** Underlying hardware device */
365 struct device *dev;
366 /** DMA device */
368
369 /** Network device operations */
371
372 /** Link-layer protocol */
374 /** Hardware address
375 *
376 * This is an address which is an intrinsic property of the
377 * hardware, e.g. an address held in EEPROM.
378 *
379 * Note that the hardware address may not be the same length
380 * as the link-layer address.
381 */
383 /** Link-layer address
384 *
385 * This is the current link-layer address assigned to the
386 * device. It can be changed at runtime.
387 */
389 /** Link-layer broadcast address */
391
392 /** Current device state
393 *
394 * This is the bitwise-OR of zero or more NETDEV_XXX constants.
395 */
396 unsigned int state;
397 /** Link status code
398 *
399 * Zero indicates that the link is up; any other value
400 * indicates the error preventing link-up.
401 */
403 /** Link block timer */
405 /** Maximum packet length
406 *
407 * This is the maximum packet length (including any link-layer
408 * headers) supported by the hardware.
409 */
411 /** Maximum transmission unit length
412 *
413 * This is the maximum transmission unit length (excluding any
414 * link-layer headers) configured for the link.
415 */
416 size_t mtu;
417 /** TX packet queue */
419 /** Deferred TX packet queue */
421 /** RX packet queue */
423 /** TX statistics */
425 /** RX statistics */
427
428 /** Configuration settings applicable to this device */
430
431 /** Driver private data */
432 void *priv;
433
434 /** Network device configurations (variable length) */
436};
437
438/** Network device is open */
439#define NETDEV_OPEN 0x0001
440
441/** Network device interrupts are enabled */
442#define NETDEV_IRQ_ENABLED 0x0002
443
444/** Network device receive queue processing is frozen */
445#define NETDEV_RX_FROZEN 0x0004
446
447/** Network device interrupts are unsupported
448 *
449 * This flag can be used by a network device to indicate that
450 * interrupts are not supported despite the presence of an irq()
451 * method.
452 */
453#define NETDEV_IRQ_UNSUPPORTED 0x0008
454
455/** Network device transmission is in progress */
456#define NETDEV_TX_IN_PROGRESS 0x0010
457
458/** Network device poll is in progress */
459#define NETDEV_POLL_IN_PROGRESS 0x0020
460
461/** Network device must be polled even when closed */
462#define NETDEV_INSOMNIAC 0x0040
463
464/** Network device should be opened automatically */
465#define NETDEV_AUTO_OPEN 0x0080
466
467/** Link-layer protocol table */
468#define LL_PROTOCOLS __table ( struct ll_protocol, "ll_protocols" )
469
470/** Declare a link-layer protocol */
471#define __ll_protocol __table_entry ( LL_PROTOCOLS, 01 )
472
473/** Network-layer protocol table */
474#define NET_PROTOCOLS __table ( struct net_protocol, "net_protocols" )
475
476/** Declare a network-layer protocol */
477#define __net_protocol __table_entry ( NET_PROTOCOLS, 01 )
478
479/** A network upper-layer driver */
481 /** Name */
482 const char *name;
483 /** Size of private data */
484 size_t priv_len;
485 /** Probe device
486 *
487 * @v netdev Network device
488 * @v priv Private data
489 * @ret rc Return status code
490 */
491 int ( * probe ) ( struct net_device *netdev, void *priv );
492 /** Notify of device or link state change
493 *
494 * @v netdev Network device
495 * @v priv Private data
496 */
497 void ( * notify ) ( struct net_device *netdev, void *priv );
498 /** Remove device
499 *
500 * @v netdev Network device
501 * @v priv Private data
502 */
503 void ( * remove ) ( struct net_device *netdev, void *priv );
504};
505
506/** Network driver table */
507#define NET_DRIVERS __table ( struct net_driver, "net_drivers" )
508
509/** Declare a network driver */
510#define __net_driver __table_entry ( NET_DRIVERS, 01 )
511
512extern struct list_head net_devices;
515
516/**
517 * Initialise a network device
518 *
519 * @v netdev Network device
520 * @v op Network device operations
521 */
522static inline void netdev_init ( struct net_device *netdev,
523 struct net_device_operations *op ) {
524 netdev->op = op;
525}
526
527/**
528 * Stop using a network device
529 *
530 * @v netdev Network device
531 *
532 * Drivers should call this method immediately before the final call
533 * to netdev_put().
534 */
535static inline void netdev_nullify ( struct net_device *netdev ) {
537}
538
539/**
540 * Get printable network device link-layer address
541 *
542 * @v netdev Network device
543 * @ret name Link-layer address
544 */
545static inline const char * netdev_addr ( struct net_device *netdev ) {
546 return netdev->ll_protocol->ntoa ( netdev->ll_addr );
547}
548
549/** Iterate over all network devices */
550#define for_each_netdev( netdev ) \
551 list_for_each_entry ( (netdev), &net_devices, list )
552
553/** There exist some network devices
554 *
555 * @ret existence Existence of network devices
556 */
557static inline int have_netdevs ( void ) {
558 return ( ! list_empty ( &net_devices ) );
559}
560
561/**
562 * Get reference to network device
563 *
564 * @v netdev Network device
565 * @ret netdev Network device
566 */
567static inline __attribute__ (( always_inline )) struct net_device *
569 ref_get ( &netdev->refcnt );
570 return netdev;
571}
572
573/**
574 * Drop reference to network device
575 *
576 * @v netdev Network device
577 */
578static inline __attribute__ (( always_inline )) void
580 ref_put ( &netdev->refcnt );
581}
582
583/**
584 * Get per-netdevice configuration settings block
585 *
586 * @v netdev Network device
587 * @ret settings Settings block
588 */
589static inline __attribute__ (( always_inline )) struct settings *
591 return &netdev->settings.settings;
592}
593
594/**
595 * Initialise a per-netdevice configuration settings block
596 *
597 * @v generics Generic settings block
598 * @v refcnt Containing object reference counter, or NULL
599 * @v name Settings block name
600 */
601static inline __attribute__ (( always_inline )) void
603 generic_settings_init ( &netdev->settings, &netdev->refcnt );
604 netdev->settings.settings.op = &netdev_settings_operations;
605}
606
607/**
608 * Get network device configuration
609 *
610 * @v netdev Network device
611 * @v configurator Network device configurator
612 * @ret config Network device configuration
613 */
614static inline struct net_device_configuration *
621
622/**
623 * Check if configurator applies to network device
624 *
625 * @v netdev Network device
626 * @v configurator Network device configurator
627 * @ret applies Configurator applies to network device
628 */
629static inline int
635
636/**
637 * Check link state of network device
638 *
639 * @v netdev Network device
640 * @ret link_up Link is up
641 */
642static inline __attribute__ (( always_inline )) int
644 return ( netdev->link_rc == 0 );
645}
646
647/**
648 * Check link block state of network device
649 *
650 * @v netdev Network device
651 * @ret link_blocked Link is blocked
652 */
653static inline __attribute__ (( always_inline )) int
655 return ( timer_running ( &netdev->link_block ) );
656}
657
658/**
659 * Check whether or not network device is open
660 *
661 * @v netdev Network device
662 * @ret is_open Network device is open
663 */
664static inline __attribute__ (( always_inline )) int
666 return ( netdev->state & NETDEV_OPEN );
667}
668
669/**
670 * Check whether or not network device supports interrupts
671 *
672 * @v netdev Network device
673 * @ret irq_supported Network device supports interrupts
674 */
675static inline __attribute__ (( always_inline )) int
677 return ( ( netdev->op->irq != NULL ) &&
678 ! ( netdev->state & NETDEV_IRQ_UNSUPPORTED ) );
679}
680
681/**
682 * Check whether or not network device interrupts are currently enabled
683 *
684 * @v netdev Network device
685 * @ret irq_enabled Network device interrupts are enabled
686 */
687static inline __attribute__ (( always_inline )) int
689 return ( netdev->state & NETDEV_IRQ_ENABLED );
690}
691
692/**
693 * Check whether or not network device receive queue processing is frozen
694 *
695 * @v netdev Network device
696 * @ret rx_frozen Network device receive queue processing is frozen
697 */
698static inline __attribute__ (( always_inline )) int
700 return ( netdev->state & NETDEV_RX_FROZEN );
701}
702
703/**
704 * Check whether or not network device must be polled even while closed
705 *
706 * @v netdev Network device
707 * @ret insomniac Network device must be polled even while closed
708 */
709static inline __attribute__ (( always_inline )) int
711 return ( netdev->state & NETDEV_INSOMNIAC );
712}
713
714extern void * netdev_priv ( struct net_device *netdev,
715 struct net_driver *driver );
716extern void netdev_rx_freeze ( struct net_device *netdev );
717extern void netdev_rx_unfreeze ( struct net_device *netdev );
718extern void netdev_link_err ( struct net_device *netdev, int rc );
719extern void netdev_link_down ( struct net_device *netdev );
720extern void netdev_link_block ( struct net_device *netdev,
721 unsigned long timeout );
722extern void netdev_link_unblock ( struct net_device *netdev );
723extern int netdev_tx ( struct net_device *netdev, struct io_buffer *iobuf );
724extern void netdev_tx_defer ( struct net_device *netdev,
725 struct io_buffer *iobuf );
726extern void netdev_tx_err ( struct net_device *netdev,
727 struct io_buffer *iobuf, int rc );
728extern void netdev_tx_complete_err ( struct net_device *netdev,
729 struct io_buffer *iobuf, int rc );
730extern void netdev_tx_complete_next_err ( struct net_device *netdev, int rc );
731extern void netdev_rx ( struct net_device *netdev, struct io_buffer *iobuf );
732extern void netdev_rx_err ( struct net_device *netdev,
733 struct io_buffer *iobuf, int rc );
734extern void netdev_poll ( struct net_device *netdev );
735extern struct io_buffer * netdev_rx_dequeue ( struct net_device *netdev );
736extern struct net_device * alloc_netdev ( size_t priv_size );
737extern int register_netdev ( struct net_device *netdev );
738extern int netdev_open ( struct net_device *netdev );
739extern void netdev_close ( struct net_device *netdev );
740extern void unregister_netdev ( struct net_device *netdev );
741extern void netdev_irq ( struct net_device *netdev, int enable );
742extern struct net_device * find_netdev ( const char *name );
743extern struct net_device * find_netdev_by_scope_id ( unsigned int scope_id );
744extern struct net_device * find_netdev_by_location ( unsigned int bus_type,
745 unsigned int location );
746extern struct net_device * last_opened_netdev ( void );
747extern int net_tx ( struct io_buffer *iobuf, struct net_device *netdev,
748 struct net_protocol *net_protocol, const void *ll_dest,
749 const void *ll_source );
750extern int net_rx ( struct io_buffer *iobuf, struct net_device *netdev,
751 uint16_t net_proto, const void *ll_dest,
752 const void *ll_source, unsigned int flags );
753extern void net_poll ( void );
754extern struct net_device_configurator *
755find_netdev_configurator ( const char *name );
756extern int netdev_configure ( struct net_device *netdev,
757 struct net_device_configurator *configurator );
758extern int netdev_configure_all ( struct net_device *netdev );
760extern int netdev_configuration_ok ( struct net_device *netdev );
761
762/**
763 * Complete network transmission
764 *
765 * @v netdev Network device
766 * @v iobuf I/O buffer
767 *
768 * The packet must currently be in the network device's TX queue.
769 */
770static inline void netdev_tx_complete ( struct net_device *netdev,
771 struct io_buffer *iobuf ) {
772 netdev_tx_complete_err ( netdev, iobuf, 0 );
773}
774
775/**
776 * Complete network transmission
777 *
778 * @v netdev Network device
779 *
780 * Completes the oldest outstanding packet in the TX queue.
781 */
782static inline void netdev_tx_complete_next ( struct net_device *netdev ) {
784}
785
786/**
787 * Mark network device as having link up
788 *
789 * @v netdev Network device
790 */
791static inline __attribute__ (( always_inline )) void
795
796#endif /* _IPXE_NETDEVICE_H */
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
unsigned short uint16_t
Definition stdint.h:11
unsigned char uint8_t
Definition stdint.h:10
const char * name
Definition ath9k_hw.c:1986
void timeout(int)
uint8_t flags
Flags.
Definition ena.h:7
static struct net_device * netdev
Definition gdbudp.c:53
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
#define __attribute__(x)
Definition compiler.h:10
Configuration settings.
static void generic_settings_init(struct generic_settings *generics, struct refcnt *refcnt)
Initialise a settings block.
Definition settings.h:520
Object interfaces.
Linked lists.
#define list_empty(list)
Test whether a list is empty.
Definition list.h:137
struct settings_operations netdev_settings_operations
Network device configuration settings operations.
struct list_head net_devices
List of network devices.
Definition netdevice.c:54
struct net_device * alloc_netdev(size_t priv_size)
Allocate network device.
Definition netdevice.c:722
void netdev_rx_unfreeze(struct net_device *netdev)
Unfreeze network device receive queue processing.
Definition netdevice.c:193
int net_tx(struct io_buffer *iobuf, struct net_device *netdev, struct net_protocol *net_protocol, const void *ll_dest, const void *ll_source)
Transmit network-layer packet.
Definition netdevice.c:1078
void netdev_link_err(struct net_device *netdev, int rc)
Mark network device as having a specific link state.
Definition netdevice.c:208
int netdev_configure_all(struct net_device *netdev)
Start network device configuration via all supported configurators.
Definition netdevice.c:1340
static int netdev_link_blocked(struct net_device *netdev)
Check link block state of network device.
Definition netdevice.h:654
static struct net_device * netdev_get(struct net_device *netdev)
Get reference to network device.
Definition netdevice.h:568
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
Definition netdevice.c:231
static void netdev_settings_init(struct net_device *netdev)
Initialise a per-netdevice configuration settings block.
Definition netdevice.h:602
struct net_device * find_netdev_by_scope_id(unsigned int scope_id)
Get network device by scope ID.
Definition netdevice.c:1015
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition netdevice.c:549
struct net_device * last_opened_netdev(void)
Get most recently opened network device.
Definition netdevice.c:1052
#define NETDEV_RX_FROZEN
Network device receive queue processing is frozen.
Definition netdevice.h:445
void netdev_tx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard transmitted packet.
Definition netdevice.c:441
static int netdev_irq_enabled(struct net_device *netdev)
Check whether or not network device interrupts are currently enabled.
Definition netdevice.h:688
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition netdevice.c:946
struct io_buffer * netdev_rx_dequeue(struct net_device *netdev)
Remove packet from device's receive queue.
Definition netdevice.c:638
static int netdev_is_open(struct net_device *netdev)
Check whether or not network device is open.
Definition netdevice.h:665
static int netdev_link_ok(struct net_device *netdev)
Check link state of network device.
Definition netdevice.h:643
static int netdev_irq_supported(struct net_device *netdev)
Check whether or not network device supports interrupts.
Definition netdevice.h:676
int netdev_configuration_ok(struct net_device *netdev)
Check if network device has at least one successful configuration.
Definition netdevice.c:1396
void netdev_tx_defer(struct net_device *netdev, struct io_buffer *iobuf)
Defer transmitted packet.
Definition netdevice.c:413
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
Definition netdevice.c:471
void * netdev_priv(struct net_device *netdev, struct net_driver *driver)
Get network device driver private data.
Definition netdevice.c:153
void netdev_rx_freeze(struct net_device *netdev)
Freeze network device receive queue processing.
Definition netdevice.c:179
#define NETDEV_INSOMNIAC
Network device must be polled even when closed.
Definition netdevice.h:462
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition netdevice.h:792
int netdev_open(struct net_device *netdev)
Open network device.
Definition netdevice.c:866
#define NETDEV_NAME_LEN
Maximum length of a network device name.
Definition netdevice.h:341
void netdev_link_block(struct net_device *netdev, unsigned long timeout)
Mark network device link as being blocked.
Definition netdevice.c:248
#define MAX_HW_ADDR_LEN
Maximum length of a hardware address.
Definition netdevice.h:31
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition netdevice.h:522
static int netdev_insomniac(struct net_device *netdev)
Check whether or not network device must be polled even while closed.
Definition netdevice.h:710
void netdev_tx_complete_next_err(struct net_device *netdev, int rc)
Complete network transmission.
Definition netdevice.c:510
void netdev_close(struct net_device *netdev)
Close network device.
Definition netdevice.c:900
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition netdevice.h:535
#define NETDEV_IRQ_UNSUPPORTED
Network device interrupts are unsupported.
Definition netdevice.h:453
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition netdevice.h:579
void net_poll(void)
Poll the network stack.
Definition netdevice.c:1131
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition netdevice.c:587
int register_netdev(struct net_device *netdev)
Register network device.
Definition netdevice.c:760
static int netdev_rx_frozen(struct net_device *netdev)
Check whether or not network device receive queue processing is frozen.
Definition netdevice.h:699
void netdev_link_unblock(struct net_device *netdev)
Mark network device link as being unblocked.
Definition netdevice.c:263
void netdev_irq(struct net_device *netdev, int enable)
Enable or disable interrupts.
Definition netdevice.c:975
static const char * netdev_addr(struct net_device *netdev)
Get printable network device link-layer address.
Definition netdevice.h:545
struct net_device_configurator * find_netdev_configurator(const char *name)
Find network device configurator.
Definition netdevice.c:1283
int net_rx(struct io_buffer *iobuf, struct net_device *netdev, uint16_t net_proto, const void *ll_dest, const void *ll_source, unsigned int flags)
Process received network-layer packet.
Definition netdevice.c:1107
struct net_device * find_netdev(const char *name)
Get network device by name.
Definition netdevice.c:993
#define NETDEV_IRQ_ENABLED
Network device interrupts are enabled.
Definition netdevice.h:442
int netdev_configure(struct net_device *netdev, struct net_device_configurator *configurator)
Start network device configuration.
Definition netdevice.c:1300
#define NET_DEVICE_CONFIGURATORS
Network device configurator table.
Definition netdevice.h:333
static struct net_device_configuration * netdev_configuration(struct net_device *netdev, struct net_device_configurator *configurator)
Get network device configuration.
Definition netdevice.h:615
void netdev_poll(struct net_device *netdev)
Poll for completed and received packets on network device.
Definition netdevice.c:613
static int netdev_configurator_applies(struct net_device *netdev, struct net_device_configurator *configurator)
Check if configurator applies to network device.
Definition netdevice.h:630
static void netdev_tx_complete(struct net_device *netdev, struct io_buffer *iobuf)
Complete network transmission.
Definition netdevice.h:770
struct net_device * find_netdev_by_location(unsigned int bus_type, unsigned int location)
Get network device by PCI bus:dev.fn address.
Definition netdevice.c:1034
#define NETDEV_OPEN
Network device is open.
Definition netdevice.h:439
#define MAX_LL_ADDR_LEN
Maximum length of a link-layer address.
Definition netdevice.h:37
static void netdev_tx_complete_next(struct net_device *netdev)
Complete network transmission.
Definition netdevice.h:782
#define NETDEV_MAX_UNIQUE_ERRORS
Maximum number of unique errors that we will keep track of.
Definition netdevice.h:289
int netdev_configuration_in_progress(struct net_device *netdev)
Check if network device configuration is in progress.
Definition netdevice.c:1384
int netdev_tx(struct net_device *netdev, struct io_buffer *iobuf)
Transmit raw packet via network device.
Definition netdevice.c:335
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition netdevice.h:590
static int have_netdevs(void)
There exist some network devices.
Definition netdevice.h:557
static uint16_t struct vmbus_xfer_pages_operations * op
Definition netvsc.h:327
struct net_device_operations null_netdev_operations
Definition nullnet.c:60
Reference counting.
#define ref_get(refcnt)
Get additional reference to object.
Definition refcnt.h:93
#define ref_put(refcnt)
Drop reference to object.
Definition refcnt.h:107
Retry timers.
A hardware device.
Definition device.h:77
A DMA-capable device.
Definition dma.h:48
A generic settings block.
Definition settings.h:299
An object interface.
Definition interface.h:125
A persistent I/O buffer.
Definition iobuf.h:38
A doubly-linked list entry (or list head)
Definition list.h:19
A link-layer protocol.
Definition netdevice.h:115
unsigned int flags
Flags.
Definition netdevice.h:203
int(* eui64)(const void *ll_addr, void *eui64)
Generate EUI-64 address.
Definition netdevice.h:190
int(* push)(struct net_device *netdev, struct io_buffer *iobuf, const void *ll_dest, const void *ll_source, uint16_t net_proto)
Add link-layer header.
Definition netdevice.h:128
const char * name
Protocol name.
Definition netdevice.h:117
void(* init_addr)(const void *hw_addr, void *ll_addr)
Initialise link-layer address.
Definition netdevice.h:151
int(* eth_addr)(const void *ll_addr, void *eth_addr)
Generate Ethernet-compatible compressed link-layer address.
Definition netdevice.h:182
int(* mc_hash)(unsigned int af, const void *net_addr, void *ll_addr)
Hash multicast address.
Definition netdevice.h:173
int(* pull)(struct net_device *netdev, struct io_buffer *iobuf, const void **ll_dest, const void **ll_source, uint16_t *net_proto, unsigned int *flags)
Remove link-layer header.
Definition netdevice.h:142
uint8_t ll_addr_len
Link-layer address length.
Definition netdevice.h:199
uint8_t ll_header_len
Link-layer header length.
Definition netdevice.h:201
uint8_t hw_addr_len
Hardware address length.
Definition netdevice.h:197
uint16_t ll_proto
Link-layer protocol.
Definition netdevice.h:195
A network device configuration.
Definition netdevice.h:302
int rc
Configuration status.
Definition netdevice.h:308
struct net_device_configurator * configurator
Network device configurator.
Definition netdevice.h:306
struct net_device * netdev
Network device.
Definition netdevice.h:304
struct interface job
Job control interface.
Definition netdevice.h:310
A network device configurator.
Definition netdevice.h:314
const char * name
Name.
Definition netdevice.h:316
int(* applies)(struct net_device *netdev)
Check applicability of configurator.
Definition netdevice.h:322
int(* start)(struct interface *job, struct net_device *netdev)
Start configuring network device.
Definition netdevice.h:329
Network device error.
Definition netdevice.h:281
int rc
Error status code.
Definition netdevice.h:283
unsigned int count
Error count.
Definition netdevice.h:285
Network device operations.
Definition netdevice.h:214
void(* close)(struct net_device *netdev)
Close network device.
Definition netdevice.h:231
void(* irq)(struct net_device *netdev, int enable)
Enable or disable interrupts.
Definition netdevice.h:277
void(* poll)(struct net_device *netdev)
Poll for completed and received packets.
Definition netdevice.h:268
int(* open)(struct net_device *netdev)
Open network device.
Definition netdevice.h:223
int(* transmit)(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition netdevice.h:255
Network device statistics.
Definition netdevice.h:292
unsigned int good
Count of successful completions.
Definition netdevice.h:294
struct net_device_error errors[NETDEV_MAX_UNIQUE_ERRORS]
Error breakdowns.
Definition netdevice.h:298
unsigned int bad
Count of error completions.
Definition netdevice.h:296
A network device.
Definition netdevice.h:353
size_t max_pkt_len
Maximum packet length.
Definition netdevice.h:410
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition netdevice.h:382
void * priv
Driver private data.
Definition netdevice.h:432
struct list_head tx_queue
TX packet queue.
Definition netdevice.h:418
struct net_device_configuration configs[0]
Network device configurations (variable length)
Definition netdevice.h:435
struct refcnt refcnt
Reference counter.
Definition netdevice.h:355
struct net_device_stats rx_stats
RX statistics.
Definition netdevice.h:426
struct list_head rx_queue
RX packet queue.
Definition netdevice.h:422
struct dma_device * dma
DMA device.
Definition netdevice.h:367
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition netdevice.h:373
struct net_device_operations * op
Network device operations.
Definition netdevice.h:370
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition netdevice.h:363
struct list_head open_list
List of open network devices.
Definition netdevice.h:359
struct retry_timer link_block
Link block timer.
Definition netdevice.h:404
int link_rc
Link status code.
Definition netdevice.h:402
struct device * dev
Underlying hardware device.
Definition netdevice.h:365
struct list_head list
List of network devices.
Definition netdevice.h:357
struct generic_settings settings
Configuration settings applicable to this device.
Definition netdevice.h:429
unsigned int scope_id
Scope ID.
Definition netdevice.h:361
struct net_device_stats tx_stats
TX statistics.
Definition netdevice.h:424
const uint8_t * ll_broadcast
Link-layer broadcast address.
Definition netdevice.h:390
struct list_head tx_deferred
Deferred TX packet queue.
Definition netdevice.h:420
size_t mtu
Maximum transmission unit length.
Definition netdevice.h:416
unsigned int state
Current device state.
Definition netdevice.h:396
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition netdevice.h:388
A network upper-layer driver.
Definition netdevice.h:480
int(* probe)(struct net_device *netdev, void *priv)
Probe device.
Definition netdevice.h:491
size_t priv_len
Size of private data.
Definition netdevice.h:484
void(* remove)(struct net_device *netdev, void *priv)
Remove device.
Definition netdevice.h:503
void(* notify)(struct net_device *netdev, void *priv)
Notify of device or link state change.
Definition netdevice.h:497
const char * name
Name.
Definition netdevice.h:482
A network-layer protocol.
Definition netdevice.h:65
const char * name
Protocol name.
Definition netdevice.h:67
uint16_t net_proto
Network-layer protocol.
Definition netdevice.h:100
uint8_t net_addr_len
Network-layer address length.
Definition netdevice.h:102
int(* rx)(struct io_buffer *iobuf, struct net_device *netdev, const void *ll_dest, const void *ll_source, unsigned int flags)
Process received packet.
Definition netdevice.h:80
A retry timer.
Definition retry.h:22
Settings block operations.
Definition settings.h:86
A settings block.
Definition settings.h:133
Linker tables.
#define table_index(table, entry)
Get index of entry within linker table.
Definition tables.h:362
static struct tlan_private * priv
Definition tlan.c:225