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