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 FILE_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 
21 struct io_buffer;
22 struct net_device;
23 struct net_protocol;
24 struct ll_protocol;
25 struct 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  */
65 struct net_protocol {
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  */
115 struct ll_protocol {
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 */
310  struct interface job;
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  */
353 struct net_device {
354  /** Reference counter */
355  struct refcnt refcnt;
356  /** List of network devices */
357  struct list_head list;
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 */
367  struct dma_device *dma;
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  */
402  int link_rc;
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  */
410  size_t max_pkt_len;
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 /** Link-layer protocol table */
465 #define LL_PROTOCOLS __table ( struct ll_protocol, "ll_protocols" )
466 
467 /** Declare a link-layer protocol */
468 #define __ll_protocol __table_entry ( LL_PROTOCOLS, 01 )
469 
470 /** Network-layer protocol table */
471 #define NET_PROTOCOLS __table ( struct net_protocol, "net_protocols" )
472 
473 /** Declare a network-layer protocol */
474 #define __net_protocol __table_entry ( NET_PROTOCOLS, 01 )
475 
476 /** A network upper-layer driver */
477 struct net_driver {
478  /** Name */
479  const char *name;
480  /** Size of private data */
481  size_t priv_len;
482  /** Probe device
483  *
484  * @v netdev Network device
485  * @v priv Private data
486  * @ret rc Return status code
487  */
488  int ( * probe ) ( struct net_device *netdev, void *priv );
489  /** Notify of device or link state change
490  *
491  * @v netdev Network device
492  * @v priv Private data
493  */
494  void ( * notify ) ( struct net_device *netdev, void *priv );
495  /** Remove device
496  *
497  * @v netdev Network device
498  * @v priv Private data
499  */
500  void ( * remove ) ( struct net_device *netdev, void *priv );
501 };
502 
503 /** Network driver table */
504 #define NET_DRIVERS __table ( struct net_driver, "net_drivers" )
505 
506 /** Declare a network driver */
507 #define __net_driver __table_entry ( NET_DRIVERS, 01 )
508 
509 extern struct list_head net_devices;
512 
513 /**
514  * Initialise a network device
515  *
516  * @v netdev Network device
517  * @v op Network device operations
518  */
519 static inline void netdev_init ( struct net_device *netdev,
520  struct net_device_operations *op ) {
521  netdev->op = op;
522 }
523 
524 /**
525  * Stop using a network device
526  *
527  * @v netdev Network device
528  *
529  * Drivers should call this method immediately before the final call
530  * to netdev_put().
531  */
532 static inline void netdev_nullify ( struct net_device *netdev ) {
534 }
535 
536 /**
537  * Get printable network device link-layer address
538  *
539  * @v netdev Network device
540  * @ret name Link-layer address
541  */
542 static inline const char * netdev_addr ( struct net_device *netdev ) {
543  return netdev->ll_protocol->ntoa ( netdev->ll_addr );
544 }
545 
546 /** Iterate over all network devices */
547 #define for_each_netdev( netdev ) \
548  list_for_each_entry ( (netdev), &net_devices, list )
549 
550 /** There exist some network devices
551  *
552  * @ret existence Existence of network devices
553  */
554 static inline int have_netdevs ( void ) {
555  return ( ! list_empty ( &net_devices ) );
556 }
557 
558 /**
559  * Get reference to network device
560  *
561  * @v netdev Network device
562  * @ret netdev Network device
563  */
564 static inline __attribute__ (( always_inline )) struct net_device *
566  ref_get ( &netdev->refcnt );
567  return netdev;
568 }
569 
570 /**
571  * Drop reference to network device
572  *
573  * @v netdev Network device
574  */
575 static inline __attribute__ (( always_inline )) void
577  ref_put ( &netdev->refcnt );
578 }
579 
580 /**
581  * Get per-netdevice configuration settings block
582  *
583  * @v netdev Network device
584  * @ret settings Settings block
585  */
586 static inline __attribute__ (( always_inline )) struct settings *
588  return &netdev->settings.settings;
589 }
590 
591 /**
592  * Initialise a per-netdevice configuration settings block
593  *
594  * @v generics Generic settings block
595  * @v refcnt Containing object reference counter, or NULL
596  * @v name Settings block name
597  */
598 static inline __attribute__ (( always_inline )) void
602 }
603 
604 /**
605  * Get network device configuration
606  *
607  * @v netdev Network device
608  * @v configurator Network device configurator
609  * @ret config Network device configuration
610  */
611 static inline struct net_device_configuration *
614 
616  configurator ) ];
617 }
618 
619 /**
620  * Check if configurator applies to network device
621  *
622  * @v netdev Network device
623  * @v configurator Network device configurator
624  * @ret applies Configurator applies to network device
625  */
626 static inline int
629  return ( ( configurator->applies == NULL ) ||
630  configurator->applies ( netdev ) );
631 }
632 
633 /**
634  * Check link state of network device
635  *
636  * @v netdev Network device
637  * @ret link_up Link is up
638  */
639 static inline __attribute__ (( always_inline )) int
641  return ( netdev->link_rc == 0 );
642 }
643 
644 /**
645  * Check link block state of network device
646  *
647  * @v netdev Network device
648  * @ret link_blocked Link is blocked
649  */
650 static inline __attribute__ (( always_inline )) int
652  return ( timer_running ( &netdev->link_block ) );
653 }
654 
655 /**
656  * Check whether or not network device is open
657  *
658  * @v netdev Network device
659  * @ret is_open Network device is open
660  */
661 static inline __attribute__ (( always_inline )) int
663  return ( netdev->state & NETDEV_OPEN );
664 }
665 
666 /**
667  * Check whether or not network device supports interrupts
668  *
669  * @v netdev Network device
670  * @ret irq_supported Network device supports interrupts
671  */
672 static inline __attribute__ (( always_inline )) int
674  return ( ( netdev->op->irq != NULL ) &&
676 }
677 
678 /**
679  * Check whether or not network device interrupts are currently enabled
680  *
681  * @v netdev Network device
682  * @ret irq_enabled Network device interrupts are enabled
683  */
684 static inline __attribute__ (( always_inline )) int
686  return ( netdev->state & NETDEV_IRQ_ENABLED );
687 }
688 
689 /**
690  * Check whether or not network device receive queue processing is frozen
691  *
692  * @v netdev Network device
693  * @ret rx_frozen Network device receive queue processing is frozen
694  */
695 static inline __attribute__ (( always_inline )) int
697  return ( netdev->state & NETDEV_RX_FROZEN );
698 }
699 
700 /**
701  * Check whether or not network device must be polled even while closed
702  *
703  * @v netdev Network device
704  * @ret insomniac Network device must be polled even while closed
705  */
706 static inline __attribute__ (( always_inline )) int
708  return ( netdev->state & NETDEV_INSOMNIAC );
709 }
710 
711 extern void * netdev_priv ( struct net_device *netdev,
712  struct net_driver *driver );
713 extern void netdev_rx_freeze ( struct net_device *netdev );
714 extern void netdev_rx_unfreeze ( struct net_device *netdev );
715 extern void netdev_link_err ( struct net_device *netdev, int rc );
716 extern void netdev_link_down ( struct net_device *netdev );
717 extern void netdev_link_block ( struct net_device *netdev,
718  unsigned long timeout );
719 extern void netdev_link_unblock ( struct net_device *netdev );
720 extern int netdev_tx ( struct net_device *netdev, struct io_buffer *iobuf );
721 extern void netdev_tx_defer ( struct net_device *netdev,
722  struct io_buffer *iobuf );
723 extern void netdev_tx_err ( struct net_device *netdev,
724  struct io_buffer *iobuf, int rc );
725 extern void netdev_tx_complete_err ( struct net_device *netdev,
726  struct io_buffer *iobuf, int rc );
727 extern void netdev_tx_complete_next_err ( struct net_device *netdev, int rc );
728 extern void netdev_rx ( struct net_device *netdev, struct io_buffer *iobuf );
729 extern void netdev_rx_err ( struct net_device *netdev,
730  struct io_buffer *iobuf, int rc );
731 extern void netdev_poll ( struct net_device *netdev );
732 extern struct io_buffer * netdev_rx_dequeue ( struct net_device *netdev );
733 extern struct net_device * alloc_netdev ( size_t priv_size );
734 extern int register_netdev ( struct net_device *netdev );
735 extern int netdev_open ( struct net_device *netdev );
736 extern void netdev_close ( struct net_device *netdev );
737 extern void unregister_netdev ( struct net_device *netdev );
738 extern void netdev_irq ( struct net_device *netdev, int enable );
739 extern struct net_device * find_netdev ( const char *name );
740 extern struct net_device * find_netdev_by_scope_id ( unsigned int scope_id );
741 extern struct net_device * find_netdev_by_location ( unsigned int bus_type,
742  unsigned int location );
743 extern struct net_device * last_opened_netdev ( void );
744 extern int net_tx ( struct io_buffer *iobuf, struct net_device *netdev,
745  struct net_protocol *net_protocol, const void *ll_dest,
746  const void *ll_source );
747 extern int net_rx ( struct io_buffer *iobuf, struct net_device *netdev,
748  uint16_t net_proto, const void *ll_dest,
749  const void *ll_source, unsigned int flags );
750 extern void net_poll ( void );
751 extern struct net_device_configurator *
752 find_netdev_configurator ( const char *name );
753 extern int netdev_configure ( struct net_device *netdev,
754  struct net_device_configurator *configurator );
755 extern int netdev_configure_all ( struct net_device *netdev );
756 extern int netdev_configuration_in_progress ( struct net_device *netdev );
757 extern int netdev_configuration_ok ( struct net_device *netdev );
758 
759 /**
760  * Complete network transmission
761  *
762  * @v netdev Network device
763  * @v iobuf I/O buffer
764  *
765  * The packet must currently be in the network device's TX queue.
766  */
767 static inline void netdev_tx_complete ( struct net_device *netdev,
768  struct io_buffer *iobuf ) {
769  netdev_tx_complete_err ( netdev, iobuf, 0 );
770 }
771 
772 /**
773  * Complete network transmission
774  *
775  * @v netdev Network device
776  *
777  * Completes the oldest outstanding packet in the TX queue.
778  */
779 static inline void netdev_tx_complete_next ( struct net_device *netdev ) {
781 }
782 
783 /**
784  * Mark network device as having link up
785  *
786  * @v netdev Network device
787  */
788 static inline __attribute__ (( always_inline )) void
790  netdev_link_err ( netdev, 0 );
791 }
792 
793 #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:722
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1986
unsigned short uint16_t
Definition: stdint.h:11
const char * name
Name.
Definition: netdevice.h:316
const char * name
Protocol name.
Definition: netdevice.h:67
static void netdev_tx_complete(struct net_device *netdev, struct io_buffer *iobuf)
Complete network transmission.
Definition: netdevice.h:767
static void netdev_settings_init(struct net_device *netdev)
Initialise a per-netdevice configuration settings block.
Definition: netdevice.h:599
uint8_t ll_header_len
Link-layer header length.
Definition: netdevice.h:201
uint8_t ll_addr_len
Link-layer address length.
Definition: netdevice.h:199
int(* start)(struct interface *job, struct net_device *netdev)
Start configuring network device.
Definition: netdevice.h:329
struct list_head net_devices
List of network devices.
Definition: netdevice.c:54
#define NETDEV_RX_FROZEN
Network device receive queue processing is frozen.
Definition: netdevice.h:445
void netdev_close(struct net_device *netdev)
Close network device.
Definition: netdevice.c:896
void netdev_rx_freeze(struct net_device *netdev)
Freeze network device receive queue processing.
Definition: netdevice.c:179
int(* open)(struct net_device *netdev)
Open network device.
Definition: netdevice.h:223
#define NETDEV_OPEN
Network device is open.
Definition: netdevice.h:439
void netdev_poll(struct net_device *netdev)
Poll for completed and received packets on network device.
Definition: netdevice.c:613
struct interface job
Job control interface.
Definition: netdevice.h:310
static void generic_settings_init(struct generic_settings *generics, struct refcnt *refcnt)
Initialise a settings block.
Definition: settings.h:520
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:1030
static void netdev_tx_complete_next(struct net_device *netdev)
Complete network transmission.
Definition: netdevice.h:779
int netdev_configuration_ok(struct net_device *netdev)
Check if network device has at least one successful configuration.
Definition: netdevice.c:1392
struct retry_timer link_block
Link block timer.
Definition: netdevice.h:404
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:760
struct net_device_operations null_netdev_operations
Definition: nullnet.c:60
size_t mtu
Maximum transmission unit length.
Definition: netdevice.h:416
Retry timers.
struct list_head list
List of network devices.
Definition: netdevice.h:357
static int netdev_insomniac(struct net_device *netdev)
Check whether or not network device must be polled even while closed.
Definition: netdevice.h:707
void netdev_link_block(struct net_device *netdev, unsigned long timeout)
Mark network device link as being blocked.
Definition: netdevice.c:248
A retry timer.
Definition: retry.h:22
const uint8_t * ll_broadcast
Link-layer broadcast address.
Definition: netdevice.h:390
void netdev_link_unblock(struct net_device *netdev)
Mark network device link as being unblocked.
Definition: netdevice.c:263
unsigned int state
Current device state.
Definition: netdevice.h:396
struct dma_device * dma
DMA device.
Definition: netdevice.h:367
struct net_device * last_opened_netdev(void)
Get most recently opened network device.
Definition: netdevice.c:1048
struct net_device * find_netdev_by_scope_id(unsigned int scope_id)
Get network device by scope ID.
Definition: netdevice.c:1011
static int have_netdevs(void)
There exist some network devices.
Definition: netdevice.h:554
Network device error.
Definition: netdevice.h:281
static int netdev_link_blocked(struct net_device *netdev)
Check link block state of network device.
Definition: netdevice.h:651
struct net_device_operations * op
Network device operations.
Definition: netdevice.h:370
#define NETDEV_NAME_LEN
Maximum length of a network device name.
Definition: netdevice.h:341
static const char * netdev_addr(struct net_device *netdev)
Get printable network device link-layer address.
Definition: netdevice.h:542
struct settings_operations * op
Settings block operations.
Definition: settings.h:145
struct net_device_stats tx_stats
TX statistics.
Definition: netdevice.h:424
unsigned int scope_id
Scope ID.
Definition: netdevice.h:361
void(* init_addr)(const void *hw_addr, void *ll_addr)
Initialise link-layer address.
Definition: netdevice.h:151
A network upper-layer driver.
Definition: netdevice.h:477
int(* probe)(struct net_device *netdev, void *priv)
Probe device.
Definition: netdevice.h:488
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition: netdevice.h:587
size_t priv_len
Size of private data.
Definition: netdevice.h:481
A link-layer protocol.
Definition: netdevice.h:115
struct list_head rx_queue
RX packet queue.
Definition: netdevice.h:422
unsigned int count
Error count.
Definition: netdevice.h:285
A doubly-linked list entry (or list head)
Definition: list.h:19
FILE_SECBOOT(PERMITTED)
void(* poll)(struct net_device *netdev)
Poll for completed and received packets.
Definition: netdevice.h:268
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
A reference counter.
Definition: refcnt.h:27
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:1074
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:137
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:519
const char * name
Protocol name.
Definition: netdevice.h:117
void(* irq)(struct net_device *netdev, int enable)
Enable or disable interrupts.
Definition: netdevice.h:277
int netdev_open(struct net_device *netdev)
Open network device.
Definition: netdevice.c:862
void netdev_irq(struct net_device *netdev, int enable)
Enable or disable interrupts.
Definition: netdevice.c:971
struct settings_operations netdev_settings_operations
Network device configuration settings operations.
A hardware device.
Definition: device.h:77
#define NETDEV_MAX_UNIQUE_ERRORS
Maximum number of unique errors that we will keep track of.
Definition: netdevice.h:289
const char * name
Name.
Definition: netdevice.h:479
static int netdev_is_open(struct net_device *netdev)
Check whether or not network device is open.
Definition: netdevice.h:662
#define MAX_LL_ADDR_LEN
Maximum length of a link-layer address.
Definition: netdevice.h:37
int link_rc
Link status code.
Definition: netdevice.h:402
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:576
An object interface.
Definition: interface.h:125
uint8_t hw_addr_len
Hardware address length.
Definition: netdevice.h:197
void * priv
Driver private data.
Definition: netdevice.h:432
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:789
struct list_head tx_queue
TX packet queue.
Definition: netdevice.h:418
static int netdev_link_ok(struct net_device *netdev)
Check link state of network device.
Definition: netdevice.h:640
#define MAX_HW_ADDR_LEN
Maximum length of a hardware address.
Definition: netdevice.h:31
struct net_device_configuration configs[0]
Network device configurations (variable length)
Definition: netdevice.h:435
static struct net_device * netdev
Definition: gdbudp.c:53
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:587
struct list_head tx_deferred
Deferred TX packet queue.
Definition: netdevice.h:420
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:685
uint8_t flags
Flags.
Definition: ena.h:18
struct refcnt refcnt
Reference counter.
Definition: netdevice.h:355
#define ref_get(refcnt)
Get additional reference to object.
Definition: refcnt.h:93
struct net_device_stats rx_stats
RX statistics.
Definition: netdevice.h:426
int(* eui64)(const void *ll_addr, void *eui64)
Generate EUI-64 address.
Definition: netdevice.h:190
unsigned int bad
Count of error completions.
Definition: netdevice.h:296
A network device.
Definition: netdevice.h:353
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:532
Settings block operations.
Definition: settings.h:86
A settings block.
Definition: settings.h:133
struct net_device_error errors[NETDEV_MAX_UNIQUE_ERRORS]
Error breakdowns.
Definition: netdevice.h:298
unsigned char uint8_t
Definition: stdint.h:10
Network device statistics.
Definition: netdevice.h:292
unsigned int flags
Flags.
Definition: netdevice.h:203
static struct net_device * netdev_get(struct net_device *netdev)
Get reference to network device.
Definition: netdevice.h:565
void(* notify)(struct net_device *netdev, void *priv)
Notify of device or link state change.
Definition: netdevice.h:494
void(* close)(struct net_device *netdev)
Close network device.
Definition: netdevice.h:231
uint16_t net_proto
Network-layer protocol.
Definition: netdevice.h:100
void netdev_tx_complete_next_err(struct net_device *netdev, int rc)
Complete network transmission.
Definition: netdevice.c:510
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
Definition: netdevice.c:231
uint16_t ll_proto
Link-layer protocol.
Definition: netdevice.h:195
int(* mc_hash)(unsigned int af, const void *net_addr, void *ll_addr)
Hash multicast address.
Definition: netdevice.h:173
void * netdev_priv(struct net_device *netdev, struct net_driver *driver)
Get network device driver private data.
Definition: netdevice.c:153
int(* transmit)(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: netdevice.h:255
int(* applies)(struct net_device *netdev)
Check applicability of configurator.
Definition: netdevice.h:322
Network device operations.
Definition: netdevice.h:214
struct device * dev
Underlying hardware device.
Definition: netdevice.h:365
A network-layer protocol.
Definition: netdevice.h:65
void net_poll(void)
Poll the network stack.
Definition: netdevice.c:1127
static int netdev_configurator_applies(struct net_device *netdev, struct net_device_configurator *configurator)
Check if configurator applies to network device.
Definition: netdevice.h:627
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
A generic settings block.
Definition: settings.h:299
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:942
unsigned int good
Count of successful completions.
Definition: netdevice.h:294
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
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:363
struct settings settings
Settings block.
Definition: settings.h:301
int netdev_configure_all(struct net_device *netdev)
Start network device configuration via all supported configurators.
Definition: netdevice.c:1336
static struct tlan_private * priv
Definition: tlan.c:225
uint8_t net_addr_len
Network-layer address length.
Definition: netdevice.h:102
struct net_device * netdev
Network device.
Definition: netdevice.h:304
void(* remove)(struct net_device *netdev, void *priv)
Remove device.
Definition: netdevice.h:500
struct io_buffer * netdev_rx_dequeue(struct net_device *netdev)
Remove packet from device's receive queue.
Definition: netdevice.c:638
int rc
Configuration status.
Definition: netdevice.h:308
struct list_head open_list
List of open network devices.
Definition: netdevice.h:359
A network device configurator.
Definition: netdevice.h:314
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:1103
Linker tables.
int netdev_configuration_in_progress(struct net_device *netdev)
Check if network device configuration is in progress.
Definition: netdevice.c:1380
const char *(* ntoa)(const void *ll_addr)
Transcribe link-layer address.
Definition: netdevice.h:164
int netdev_tx(struct net_device *netdev, struct io_buffer *iobuf)
Transmit raw packet via network device.
Definition: netdevice.c:335
void netdev_tx_defer(struct net_device *netdev, struct io_buffer *iobuf)
Defer transmitted packet.
Definition: netdevice.c:413
struct net_device_configurator * configurator
Network device configurator.
Definition: netdevice.h:306
#define NET_DEVICE_CONFIGURATORS
Network device configurator table.
Definition: netdevice.h:333
void timeout(int)
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:388
size_t max_pkt_len
Maximum packet length.
Definition: netdevice.h:410
int rc
Error status code.
Definition: netdevice.h:283
void netdev_tx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard transmitted packet.
Definition: netdevice.c:441
A network device configuration.
Definition: netdevice.h:302
static int netdev_rx_frozen(struct net_device *netdev)
Check whether or not network device receive queue processing is frozen.
Definition: netdevice.h:696
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition: netdevice.c:549
#define NETDEV_IRQ_UNSUPPORTED
Network device interrupts are unsupported.
Definition: netdevice.h:453
#define NETDEV_INSOMNIAC
Network device must be polled even when closed.
Definition: netdevice.h:462
struct generic_settings settings
Configuration settings applicable to this device.
Definition: netdevice.h:429
void netdev_rx_unfreeze(struct net_device *netdev)
Unfreeze network device receive queue processing.
Definition: netdevice.c:193
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:382
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
static int netdev_irq_supported(struct net_device *netdev)
Check whether or not network device supports interrupts.
Definition: netdevice.h:673
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
Definition: netdevice.c:471
#define NETDEV_IRQ_ENABLED
Network device interrupts are enabled.
Definition: netdevice.h:442
static struct net_device_configuration * netdev_configuration(struct net_device *netdev, struct net_device_configurator *configurator)
Get network device configuration.
Definition: netdevice.h:612
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:373
int netdev_configure(struct net_device *netdev, struct net_device_configurator *configurator)
Start network device configuration.
Definition: netdevice.c:1296
#define table_index(table, entry)
Get index of entry within linker table.
Definition: tables.h:362
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:107
A DMA-capable device.
Definition: dma.h:48
struct net_device_configurator * find_netdev_configurator(const char *name)
Find network device configurator.
Definition: netdevice.c:1279
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
int(* eth_addr)(const void *ll_addr, void *eth_addr)
Generate Ethernet-compatible compressed link-layer address.
Definition: netdevice.h:182
struct net_device * find_netdev(const char *name)
Get network device by name.
Definition: netdevice.c:989
A persistent I/O buffer.
Definition: iobuf.h:38
void netdev_link_err(struct net_device *netdev, int rc)
Mark network device as having a specific link state.
Definition: netdevice.c:208