選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

netdevice.h 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  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 length includes any link-layer headers.
  373. */
  374. size_t max_pkt_len;
  375. /** TX packet queue */
  376. struct list_head tx_queue;
  377. /** Deferred TX packet queue */
  378. struct list_head tx_deferred;
  379. /** RX packet queue */
  380. struct list_head rx_queue;
  381. /** TX statistics */
  382. struct net_device_stats tx_stats;
  383. /** RX statistics */
  384. struct net_device_stats rx_stats;
  385. /** Configuration settings applicable to this device */
  386. struct generic_settings settings;
  387. /** Driver private data */
  388. void *priv;
  389. /** Network device configurations (variable length) */
  390. struct net_device_configuration configs[0];
  391. };
  392. /** Network device is open */
  393. #define NETDEV_OPEN 0x0001
  394. /** Network device interrupts are enabled */
  395. #define NETDEV_IRQ_ENABLED 0x0002
  396. /** Network device receive queue processing is frozen */
  397. #define NETDEV_RX_FROZEN 0x0004
  398. /** Network device interrupts are unsupported
  399. *
  400. * This flag can be used by a network device to indicate that
  401. * interrupts are not supported despite the presence of an irq()
  402. * method.
  403. */
  404. #define NETDEV_IRQ_UNSUPPORTED 0x0008
  405. /** Link-layer protocol table */
  406. #define LL_PROTOCOLS __table ( struct ll_protocol, "ll_protocols" )
  407. /** Declare a link-layer protocol */
  408. #define __ll_protocol __table_entry ( LL_PROTOCOLS, 01 )
  409. /** Network-layer protocol table */
  410. #define NET_PROTOCOLS __table ( struct net_protocol, "net_protocols" )
  411. /** Declare a network-layer protocol */
  412. #define __net_protocol __table_entry ( NET_PROTOCOLS, 01 )
  413. /** A network upper-layer driver */
  414. struct net_driver {
  415. /** Name */
  416. const char *name;
  417. /** Probe device
  418. *
  419. * @v netdev Network device
  420. * @ret rc Return status code
  421. */
  422. int ( * probe ) ( struct net_device *netdev );
  423. /** Notify of device or link state change
  424. *
  425. * @v netdev Network device
  426. */
  427. void ( * notify ) ( struct net_device *netdev );
  428. /** Remove device
  429. *
  430. * @v netdev Network device
  431. */
  432. void ( * remove ) ( struct net_device *netdev );
  433. };
  434. /** Network driver table */
  435. #define NET_DRIVERS __table ( struct net_driver, "net_drivers" )
  436. /** Declare a network driver */
  437. #define __net_driver __table_entry ( NET_DRIVERS, 01 )
  438. extern struct list_head net_devices;
  439. extern struct net_device_operations null_netdev_operations;
  440. extern struct settings_operations netdev_settings_operations;
  441. /**
  442. * Initialise a network device
  443. *
  444. * @v netdev Network device
  445. * @v op Network device operations
  446. */
  447. static inline void netdev_init ( struct net_device *netdev,
  448. struct net_device_operations *op ) {
  449. netdev->op = op;
  450. }
  451. /**
  452. * Stop using a network device
  453. *
  454. * @v netdev Network device
  455. *
  456. * Drivers should call this method immediately before the final call
  457. * to netdev_put().
  458. */
  459. static inline void netdev_nullify ( struct net_device *netdev ) {
  460. netdev->op = &null_netdev_operations;
  461. }
  462. /**
  463. * Get printable network device link-layer address
  464. *
  465. * @v netdev Network device
  466. * @ret name Link-layer address
  467. */
  468. static inline const char * netdev_addr ( struct net_device *netdev ) {
  469. return netdev->ll_protocol->ntoa ( netdev->ll_addr );
  470. }
  471. /** Iterate over all network devices */
  472. #define for_each_netdev( netdev ) \
  473. list_for_each_entry ( (netdev), &net_devices, list )
  474. /** There exist some network devices
  475. *
  476. * @ret existence Existence of network devices
  477. */
  478. static inline int have_netdevs ( void ) {
  479. return ( ! list_empty ( &net_devices ) );
  480. }
  481. /**
  482. * Get reference to network device
  483. *
  484. * @v netdev Network device
  485. * @ret netdev Network device
  486. */
  487. static inline __attribute__ (( always_inline )) struct net_device *
  488. netdev_get ( struct net_device *netdev ) {
  489. ref_get ( &netdev->refcnt );
  490. return netdev;
  491. }
  492. /**
  493. * Drop reference to network device
  494. *
  495. * @v netdev Network device
  496. */
  497. static inline __attribute__ (( always_inline )) void
  498. netdev_put ( struct net_device *netdev ) {
  499. ref_put ( &netdev->refcnt );
  500. }
  501. /**
  502. * Get driver private area for this network device
  503. *
  504. * @v netdev Network device
  505. * @ret priv Driver private area for this network device
  506. */
  507. static inline __attribute__ (( always_inline )) void *
  508. netdev_priv ( struct net_device *netdev ) {
  509. return netdev->priv;
  510. }
  511. /**
  512. * Get per-netdevice configuration settings block
  513. *
  514. * @v netdev Network device
  515. * @ret settings Settings block
  516. */
  517. static inline __attribute__ (( always_inline )) struct settings *
  518. netdev_settings ( struct net_device *netdev ) {
  519. return &netdev->settings.settings;
  520. }
  521. /**
  522. * Initialise a per-netdevice configuration settings block
  523. *
  524. * @v generics Generic settings block
  525. * @v refcnt Containing object reference counter, or NULL
  526. * @v name Settings block name
  527. */
  528. static inline __attribute__ (( always_inline )) void
  529. netdev_settings_init ( struct net_device *netdev ) {
  530. generic_settings_init ( &netdev->settings, &netdev->refcnt );
  531. netdev->settings.settings.op = &netdev_settings_operations;
  532. }
  533. /**
  534. * Get network device configuration
  535. *
  536. * @v netdev Network device
  537. * @v configurator Network device configurator
  538. * @ret config Network device configuration
  539. */
  540. static inline struct net_device_configuration *
  541. netdev_configuration ( struct net_device *netdev,
  542. struct net_device_configurator *configurator ) {
  543. return &netdev->configs[ table_index ( NET_DEVICE_CONFIGURATORS,
  544. configurator ) ];
  545. }
  546. /**
  547. * Check if configurator applies to network device
  548. *
  549. * @v netdev Network device
  550. * @v configurator Network device configurator
  551. * @ret applies Configurator applies to network device
  552. */
  553. static inline int
  554. netdev_configurator_applies ( struct net_device *netdev,
  555. struct net_device_configurator *configurator ) {
  556. return ( ( configurator->applies == NULL ) ||
  557. configurator->applies ( netdev ) );
  558. }
  559. /**
  560. * Check link state of network device
  561. *
  562. * @v netdev Network device
  563. * @ret link_up Link is up
  564. */
  565. static inline __attribute__ (( always_inline )) int
  566. netdev_link_ok ( struct net_device *netdev ) {
  567. return ( netdev->link_rc == 0 );
  568. }
  569. /**
  570. * Check link block state of network device
  571. *
  572. * @v netdev Network device
  573. * @ret link_blocked Link is blocked
  574. */
  575. static inline __attribute__ (( always_inline )) int
  576. netdev_link_blocked ( struct net_device *netdev ) {
  577. return ( timer_running ( &netdev->link_block ) );
  578. }
  579. /**
  580. * Check whether or not network device is open
  581. *
  582. * @v netdev Network device
  583. * @ret is_open Network device is open
  584. */
  585. static inline __attribute__ (( always_inline )) int
  586. netdev_is_open ( struct net_device *netdev ) {
  587. return ( netdev->state & NETDEV_OPEN );
  588. }
  589. /**
  590. * Check whether or not network device supports interrupts
  591. *
  592. * @v netdev Network device
  593. * @ret irq_supported Network device supports interrupts
  594. */
  595. static inline __attribute__ (( always_inline )) int
  596. netdev_irq_supported ( struct net_device *netdev ) {
  597. return ( ( netdev->op->irq != NULL ) &&
  598. ! ( netdev->state & NETDEV_IRQ_UNSUPPORTED ) );
  599. }
  600. /**
  601. * Check whether or not network device interrupts are currently enabled
  602. *
  603. * @v netdev Network device
  604. * @ret irq_enabled Network device interrupts are enabled
  605. */
  606. static inline __attribute__ (( always_inline )) int
  607. netdev_irq_enabled ( struct net_device *netdev ) {
  608. return ( netdev->state & NETDEV_IRQ_ENABLED );
  609. }
  610. /**
  611. * Check whether or not network device receive queue processing is frozen
  612. *
  613. * @v netdev Network device
  614. * @ret rx_frozen Network device receive queue processing is frozen
  615. */
  616. static inline __attribute__ (( always_inline )) int
  617. netdev_rx_frozen ( struct net_device *netdev ) {
  618. return ( netdev->state & NETDEV_RX_FROZEN );
  619. }
  620. extern void netdev_rx_freeze ( struct net_device *netdev );
  621. extern void netdev_rx_unfreeze ( struct net_device *netdev );
  622. extern void netdev_link_err ( struct net_device *netdev, int rc );
  623. extern void netdev_link_down ( struct net_device *netdev );
  624. extern void netdev_link_block ( struct net_device *netdev,
  625. unsigned long timeout );
  626. extern void netdev_link_unblock ( struct net_device *netdev );
  627. extern int netdev_tx ( struct net_device *netdev, struct io_buffer *iobuf );
  628. extern void netdev_tx_defer ( struct net_device *netdev,
  629. struct io_buffer *iobuf );
  630. extern void netdev_tx_err ( struct net_device *netdev,
  631. struct io_buffer *iobuf, int rc );
  632. extern void netdev_tx_complete_err ( struct net_device *netdev,
  633. struct io_buffer *iobuf, int rc );
  634. extern void netdev_tx_complete_next_err ( struct net_device *netdev, int rc );
  635. extern void netdev_rx ( struct net_device *netdev, struct io_buffer *iobuf );
  636. extern void netdev_rx_err ( struct net_device *netdev,
  637. struct io_buffer *iobuf, int rc );
  638. extern void netdev_poll ( struct net_device *netdev );
  639. extern struct io_buffer * netdev_rx_dequeue ( struct net_device *netdev );
  640. extern struct net_device * alloc_netdev ( size_t priv_size );
  641. extern int register_netdev ( struct net_device *netdev );
  642. extern int netdev_open ( struct net_device *netdev );
  643. extern void netdev_close ( struct net_device *netdev );
  644. extern void unregister_netdev ( struct net_device *netdev );
  645. extern void netdev_irq ( struct net_device *netdev, int enable );
  646. extern struct net_device * find_netdev ( const char *name );
  647. extern struct net_device * find_netdev_by_index ( unsigned int index );
  648. extern struct net_device * find_netdev_by_location ( unsigned int bus_type,
  649. unsigned int location );
  650. extern struct net_device *
  651. find_netdev_by_ll_addr ( struct ll_protocol *ll_protocol, const void *ll_addr );
  652. extern struct net_device * last_opened_netdev ( void );
  653. extern int net_tx ( struct io_buffer *iobuf, struct net_device *netdev,
  654. struct net_protocol *net_protocol, const void *ll_dest,
  655. const void *ll_source );
  656. extern int net_rx ( struct io_buffer *iobuf, struct net_device *netdev,
  657. uint16_t net_proto, const void *ll_dest,
  658. const void *ll_source, unsigned int flags );
  659. extern void net_poll ( void );
  660. extern struct net_device_configurator *
  661. find_netdev_configurator ( const char *name );
  662. extern int netdev_configure ( struct net_device *netdev,
  663. struct net_device_configurator *configurator );
  664. extern int netdev_configure_all ( struct net_device *netdev );
  665. extern int netdev_configuration_in_progress ( struct net_device *netdev );
  666. extern int netdev_configuration_ok ( struct net_device *netdev );
  667. /**
  668. * Complete network transmission
  669. *
  670. * @v netdev Network device
  671. * @v iobuf I/O buffer
  672. *
  673. * The packet must currently be in the network device's TX queue.
  674. */
  675. static inline void netdev_tx_complete ( struct net_device *netdev,
  676. struct io_buffer *iobuf ) {
  677. netdev_tx_complete_err ( netdev, iobuf, 0 );
  678. }
  679. /**
  680. * Complete network transmission
  681. *
  682. * @v netdev Network device
  683. *
  684. * Completes the oldest outstanding packet in the TX queue.
  685. */
  686. static inline void netdev_tx_complete_next ( struct net_device *netdev ) {
  687. netdev_tx_complete_next_err ( netdev, 0 );
  688. }
  689. /**
  690. * Mark network device as having link up
  691. *
  692. * @v netdev Network device
  693. */
  694. static inline __attribute__ (( always_inline )) void
  695. netdev_link_up ( struct net_device *netdev ) {
  696. netdev_link_err ( netdev, 0 );
  697. }
  698. #endif /* _IPXE_NETDEVICE_H */