You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

netdevice.h 21KB

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