#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <byteswap.h>
#include <string.h>
#include <errno.h>
#include <gpxe/if_ether.h>
#include <gpxe/iobuf.h>
#include <gpxe/tables.h>
#include <gpxe/process.h>
#include <gpxe/init.h>
#include <gpxe/device.h>
#include <gpxe/errortab.h>
#include <gpxe/netdevice.h>
Go to the source code of this file.
Defines | |
| #define | EUNKNOWN_LINK_STATUS EINPROGRESS |
| Default link status code. | |
Functions | |
| FILE_LICENCE (GPL2_OR_LATER) | |
| void | netdev_link_down (struct net_device *netdev) |
| Mark network device as having link down. | |
| static void | netdev_record_stat (struct net_device_stats *stats, int rc) |
| Record network device statistic. | |
| int | netdev_tx (struct net_device *netdev, struct io_buffer *iobuf) |
| Transmit raw packet via network device. | |
| void | netdev_tx_complete_err (struct net_device *netdev, struct io_buffer *iobuf, int rc) |
| Complete network transmission. | |
| void | netdev_tx_complete_next_err (struct net_device *netdev, int rc) |
| Complete network transmission. | |
| static void | netdev_tx_flush (struct net_device *netdev) |
| Flush device's transmit queue. | |
| void | netdev_rx (struct net_device *netdev, struct io_buffer *iobuf) |
| Add packet to receive queue. | |
| void | netdev_rx_err (struct net_device *netdev, struct io_buffer *iobuf, int rc) |
| Discard received packet. | |
| void | netdev_poll (struct net_device *netdev) |
| Poll for completed and received packets on network device. | |
| struct io_buffer * | netdev_rx_dequeue (struct net_device *netdev) |
| Remove packet from device's receive queue. | |
| static void | netdev_rx_flush (struct net_device *netdev) |
| Flush device's receive queue. | |
| static void | free_netdev (struct refcnt *refcnt) |
| Free network device. | |
| struct net_device * | alloc_netdev (size_t priv_size) |
| Allocate network device. | |
| int | register_netdev (struct net_device *netdev) |
| Register network device. | |
| int | netdev_open (struct net_device *netdev) |
| Open network device. | |
| void | netdev_close (struct net_device *netdev) |
| Close network device. | |
| void | unregister_netdev (struct net_device *netdev) |
| Unregister network device. | |
| void | netdev_irq (struct net_device *netdev, int enable) |
| Enable or disable interrupts. | |
| struct net_device * | find_netdev (const char *name) |
| Get network device by name. | |
| struct net_device * | find_netdev_by_location (unsigned int bus_type, unsigned int location) |
| Get network device by PCI bus:dev.fn address. | |
| struct net_device * | last_opened_netdev (void) |
| Get most recently opened network device. | |
| int | net_tx (struct io_buffer *iobuf, struct net_device *netdev, struct net_protocol *net_protocol, const void *ll_dest) |
| Transmit network-layer packet. | |
| int | net_rx (struct io_buffer *iobuf, struct net_device *netdev, uint16_t net_proto, const void *ll_source) |
| Process received network-layer packet. | |
| static void | net_step (struct process *process __unused) |
| Single-step the network stack. | |
Variables | |
| struct list_head | net_devices = LIST_HEAD_INIT ( net_devices ) |
| List of network devices. | |
| static struct list_head | open_net_devices = LIST_HEAD_INIT ( open_net_devices ) |
| List of open network devices, in reverse order of opening. | |
| struct errortab netdev_errors[] | __errortab |
| Human-readable message for the default link status. | |
| struct process net_process | __permanent_process |
| Networking stack process. | |
Definition in file netdevice.c.
| #define EUNKNOWN_LINK_STATUS EINPROGRESS |
Default link status code.
Definition at line 49 of file netdevice.c.
Referenced by alloc_netdev(), and netdev_link_down().
| FILE_LICENCE | ( | GPL2_OR_LATER | ) |
| void netdev_link_down | ( | struct net_device * | netdev | ) |
Mark network device as having link down.
| netdev | Network device |
Definition at line 61 of file netdevice.c.
References ENOTCONN, EUNKNOWN_LINK_STATUS, and net_device::link_rc.
Referenced by __vxge_hw_vpath_alarm_process(), atl1e_check_link(), atl1e_down(), atl1e_probe(), atl1e_sw_init(), ifec_link_update(), mii_check_link(), mii_check_media(), mtnic_open(), myri10ge_interrupt_handler(), net80211_netdev_close(), net80211_set_state(), phantom_poll_link_state(), sis190_phy_task(), sis190_probe(), skge_devinit(), skge_down(), skge_link_down(), sky2_link_down(), sky2_up(), vxge_close(), vxge_device_register(), and vxge_open().
00061 { 00062 00063 switch ( netdev->link_rc ) { 00064 case 0: 00065 case -EUNKNOWN_LINK_STATUS: 00066 netdev->link_rc = -ENOTCONN; 00067 break; 00068 default: 00069 /* Avoid clobbering a more detailed link status code, 00070 * if one is already set. 00071 */ 00072 break; 00073 } 00074 }
| static void netdev_record_stat | ( | struct net_device_stats * | stats, | |
| int | rc | |||
| ) | [static] |
Record network device statistic.
| stats | Network device statistics | |
| rc | Status code |
Definition at line 82 of file netdevice.c.
References net_device_stats::bad, net_device_error::count, net_device_stats::errors, net_device_stats::good, and net_device_error::rc.
Referenced by netdev_rx(), netdev_rx_err(), and netdev_tx_complete_err().
00082 { 00083 struct net_device_error *error; 00084 struct net_device_error *least_common_error; 00085 unsigned int i; 00086 00087 /* If this is not an error, just update the good counter */ 00088 if ( rc == 0 ) { 00089 stats->good++; 00090 return; 00091 } 00092 00093 /* Update the bad counter */ 00094 stats->bad++; 00095 00096 /* Locate the appropriate error record */ 00097 least_common_error = &stats->errors[0]; 00098 for ( i = 0 ; i < ( sizeof ( stats->errors ) / 00099 sizeof ( stats->errors[0] ) ) ; i++ ) { 00100 error = &stats->errors[i]; 00101 /* Update matching record, if found */ 00102 if ( error->rc == rc ) { 00103 error->count++; 00104 return; 00105 } 00106 if ( error->count < least_common_error->count ) 00107 least_common_error = error; 00108 } 00109 00110 /* Overwrite the least common error record */ 00111 least_common_error->rc = rc; 00112 least_common_error->count = 1; 00113 }
| int netdev_tx | ( | struct net_device * | netdev, | |
| struct io_buffer * | iobuf | |||
| ) |
Transmit raw packet via network device.
| netdev | Network device | |
| iobuf | I/O buffer |
| rc | Return status code |
Definition at line 125 of file netdevice.c.
References io_buffer::data, DBGC, ENETUNREACH, iob_len(), io_buffer::list, list_add_tail, netdev_is_open(), netdev_tx_complete_err(), net_device::op, net_device_error::rc, net_device_operations::transmit, and net_device::tx_queue.
Referenced by efi_snp_transmit(), gdbudp_recv(), gdbudp_send(), net80211_handle_auth(), net80211_netdev_transmit(), net80211_tx_mgmt(), net_tx(), and pxenv_undi_transmit().
00125 { 00126 int rc; 00127 00128 DBGC ( netdev, "NETDEV %p transmitting %p (%p+%zx)\n", 00129 netdev, iobuf, iobuf->data, iob_len ( iobuf ) ); 00130 00131 list_add_tail ( &iobuf->list, &netdev->tx_queue ); 00132 00133 if ( ! netdev_is_open ( netdev ) ) { 00134 rc = -ENETUNREACH; 00135 goto err; 00136 } 00137 00138 if ( ( rc = netdev->op->transmit ( netdev, iobuf ) ) != 0 ) 00139 goto err; 00140 00141 return 0; 00142 00143 err: 00144 netdev_tx_complete_err ( netdev, iobuf, rc ); 00145 return rc; 00146 }
| void netdev_tx_complete_err | ( | struct net_device * | netdev, | |
| struct io_buffer * | iobuf, | |||
| int | rc | |||
| ) |
Complete network transmission.
| netdev | Network device | |
| iobuf | I/O buffer | |
| rc | Packet status code |
Definition at line 157 of file netdevice.c.
References assert, DBGC, free_iob(), io_buffer::list, list_del, netdev_record_stat(), list_head::next, NULL, list_head::prev, strerror(), and net_device::tx_stats.
Referenced by e1000_process_tx_packets(), e1000e_process_tx_packets(), ifec_tx_process(), igb_process_tx_packets(), ipoib_complete_send(), natsemi_poll(), net80211_tx_complete(), netdev_tx(), netdev_tx_complete(), netdev_tx_complete_next_err(), phantom_close(), sis190_process_tx(), and vxge_xmit_compl().
00158 { 00159 00160 /* Update statistics counter */ 00161 netdev_record_stat ( &netdev->tx_stats, rc ); 00162 if ( rc == 0 ) { 00163 DBGC ( netdev, "NETDEV %p transmission %p complete\n", 00164 netdev, iobuf ); 00165 } else { 00166 DBGC ( netdev, "NETDEV %p transmission %p failed: %s\n", 00167 netdev, iobuf, strerror ( rc ) ); 00168 } 00169 00170 /* Catch data corruption as early as possible */ 00171 assert ( iobuf->list.next != NULL ); 00172 assert ( iobuf->list.prev != NULL ); 00173 00174 /* Dequeue and free I/O buffer */ 00175 list_del ( &iobuf->list ); 00176 free_iob ( iobuf ); 00177 }
| void netdev_tx_complete_next_err | ( | struct net_device * | netdev, | |
| int | rc | |||
| ) |
Complete network transmission.
| netdev | Network device | |
| rc | Packet status code |
Definition at line 187 of file netdevice.c.
References io_buffer::list, list_for_each_entry, netdev_tx_complete_err(), and net_device::tx_queue.
Referenced by netdev_tx_complete_next(), and netdev_tx_flush().
00187 { 00188 struct io_buffer *iobuf; 00189 00190 list_for_each_entry ( iobuf, &netdev->tx_queue, list ) { 00191 netdev_tx_complete_err ( netdev, iobuf, rc ); 00192 return; 00193 } 00194 }
| static void netdev_tx_flush | ( | struct net_device * | netdev | ) | [static] |
Flush device's transmit queue.
| netdev | Network device |
Definition at line 201 of file netdevice.c.
References ECANCELED, list_empty(), netdev_tx_complete_next_err(), and net_device::tx_queue.
Referenced by free_netdev(), and netdev_close().
00201 { 00202 00203 /* Discard any packets in the TX queue */ 00204 while ( ! list_empty ( &netdev->tx_queue ) ) { 00205 netdev_tx_complete_next_err ( netdev, -ECANCELED ); 00206 } 00207 }
| void netdev_rx | ( | struct net_device * | netdev, | |
| struct io_buffer * | iobuf | |||
| ) |
Add packet to receive queue.
| netdev | Network device | |
| iobuf | I/O buffer, or NULL |
Definition at line 218 of file netdevice.c.
References io_buffer::data, DBGC, iob_len(), io_buffer::list, list_add_tail, netdev_record_stat(), net_device::rx_queue, and net_device::rx_stats.
Referenced by a3c90x_process_rx_packets(), atl1e_clean_rx_irq(), b44_process_rx_packets(), e1000_process_rx_packets(), e1000e_process_rx_packets(), efab_receive(), ifec_rx_process(), igb_process_rx_packets(), ipoib_complete_recv(), legacy_poll(), mtnic_process_rx_cq(), myri10ge_net_poll(), natsemi_poll(), net80211_rx(), phantom_poll(), pnic_poll(), rtl8169_process_rx_packets(), rtl_poll(), sis190_process_rx(), skge_rx_done(), sky2_status_intr(), undinet_poll(), and vxge_hw_vpath_poll_rx().
00218 { 00219 00220 DBGC ( netdev, "NETDEV %p received %p (%p+%zx)\n", 00221 netdev, iobuf, iobuf->data, iob_len ( iobuf ) ); 00222 00223 /* Enqueue packet */ 00224 list_add_tail ( &iobuf->list, &netdev->rx_queue ); 00225 00226 /* Update statistics counter */ 00227 netdev_record_stat ( &netdev->rx_stats, 0 ); 00228 }
| void netdev_rx_err | ( | struct net_device * | netdev, | |
| struct io_buffer * | iobuf, | |||
| int | rc | |||
| ) |
Discard received packet.
| netdev | Network device | |
| iobuf | I/O buffer, or NULL | |
| rc | Packet status code |
iobuf may be NULL if, for example, the net device wishes to report an error due to being unable to allocate an I/O buffer.
Definition at line 242 of file netdevice.c.
References DBGC, free_iob(), netdev_record_stat(), net_device::rx_stats, and strerror().
Referenced by a3c90x_process_rx_packets(), atl1e_clean_rx_irq(), b44_process_rx_packets(), e1000_process_rx_packets(), e1000e_process_rx_packets(), ifec_rx_process(), igb_process_rx_packets(), ipoib_complete_recv(), natsemi_poll(), net80211_rx(), net80211_rx_err(), netdev_rx_flush(), phantom_refill_rx_ring(), pnic_poll(), rtl8169_process_rx_packets(), rtl_poll(), skge_rx_done(), sky2_receive(), sky2_status_intr(), undinet_poll(), and vxge_hw_vpath_poll_rx().
00243 { 00244 00245 DBGC ( netdev, "NETDEV %p failed to receive %p: %s\n", 00246 netdev, iobuf, strerror ( rc ) ); 00247 00248 /* Discard packet */ 00249 free_iob ( iobuf ); 00250 00251 /* Update statistics counter */ 00252 netdev_record_stat ( &netdev->rx_stats, rc ); 00253 }
| void netdev_poll | ( | struct net_device * | netdev | ) |
Poll for completed and received packets on network device.
| netdev | Network device |
Definition at line 264 of file netdevice.c.
References netdev_is_open(), net_device::op, and net_device_operations::poll.
Referenced by efi_snp_poll(), gdbudp_recv(), net_step(), net_tx(), and pxenv_undi_isr().
00264 { 00265 00266 if ( netdev_is_open ( netdev ) ) 00267 netdev->op->poll ( netdev ); 00268 }
| struct io_buffer* netdev_rx_dequeue | ( | struct net_device * | netdev | ) | [read] |
Remove packet from device's receive queue.
| netdev | Network device |
| iobuf | I/O buffer, or NULL |
Definition at line 279 of file netdevice.c.
References io_buffer::list, list_del, list_for_each_entry, NULL, and net_device::rx_queue.
Referenced by efi_snp_receive(), gdbudp_recv(), net_step(), netdev_rx_flush(), and pxenv_undi_isr().
00279 { 00280 struct io_buffer *iobuf; 00281 00282 list_for_each_entry ( iobuf, &netdev->rx_queue, list ) { 00283 list_del ( &iobuf->list ); 00284 return iobuf; 00285 } 00286 return NULL; 00287 }
| static void netdev_rx_flush | ( | struct net_device * | netdev | ) | [static] |
Flush device's receive queue.
| netdev | Network device |
Definition at line 294 of file netdevice.c.
References ECANCELED, netdev_rx_dequeue(), and netdev_rx_err().
Referenced by free_netdev(), and netdev_close().
00294 { 00295 struct io_buffer *iobuf; 00296 00297 /* Discard any packets in the RX queue */ 00298 while ( ( iobuf = netdev_rx_dequeue ( netdev ) ) ) { 00299 netdev_rx_err ( netdev, iobuf, -ECANCELED ); 00300 } 00301 }
| static void free_netdev | ( | struct refcnt * | refcnt | ) | [static] |
Free network device.
Definition at line 308 of file netdevice.c.
References clear_settings(), container_of, free(), netdev, netdev_rx_flush(), netdev_settings(), and netdev_tx_flush().
Referenced by alloc_netdev().
00308 { 00309 struct net_device *netdev = 00310 container_of ( refcnt, struct net_device, refcnt ); 00311 00312 netdev_tx_flush ( netdev ); 00313 netdev_rx_flush ( netdev ); 00314 clear_settings ( netdev_settings ( netdev ) ); 00315 free ( netdev ); 00316 }
| struct net_device* alloc_netdev | ( | size_t | priv_size | ) | [read] |
Allocate network device.
| priv_size | Size of private data area (net_device::priv) |
| netdev | Network device, or NULL |
Definition at line 326 of file netdevice.c.
References EUNKNOWN_LINK_STATUS, refcnt::free, free_netdev(), INIT_LIST_HEAD, net_device::link_rc, netdev, netdev_settings_init(), net_device::priv, net_device::refcnt, net_device::rx_queue, net_device::tx_queue, and zalloc().
Referenced by alloc_etherdev(), alloc_ipoibdev(), and net80211_alloc().
00326 { 00327 struct net_device *netdev; 00328 size_t total_len; 00329 00330 total_len = ( sizeof ( *netdev ) + priv_size ); 00331 netdev = zalloc ( total_len ); 00332 if ( netdev ) { 00333 netdev->refcnt.free = free_netdev; 00334 netdev->link_rc = -EUNKNOWN_LINK_STATUS; 00335 INIT_LIST_HEAD ( &netdev->tx_queue ); 00336 INIT_LIST_HEAD ( &netdev->rx_queue ); 00337 netdev_settings_init ( netdev ); 00338 netdev->priv = ( ( ( void * ) netdev ) + sizeof ( *netdev ) ); 00339 } 00340 return netdev; 00341 }
| int register_netdev | ( | struct net_device * | netdev | ) |
Register network device.
| netdev | Network device |
| rc | Return status code |
Definition at line 352 of file netdevice.c.
References DBGC, net_device::dev, net_device::hw_addr, ll_protocol::init_addr, net_device::list, list_add_tail, net_device::ll_addr, net_device::ll_protocol, device::name, net_device::name, netdev_addr(), netdev_get(), netdev_settings(), NULL, register_settings(), snprintf(), and strerror().
Referenced by a3c90x_probe(), atl1e_probe(), b44_probe(), e1000_probe(), e1000e_probe(), efab_probe(), ifec_pci_probe(), igb_probe(), ipoib_probe(), legacy_probe(), mtnic_probe(), myri10ge_pci_probe(), natsemi_probe(), net80211_register(), phantom_probe(), pnic_probe(), rtl8169_probe(), rtl_probe(), sis190_probe(), skge_probe(), sky2_probe(), undinet_probe(), and vxge_device_register().
00352 { 00353 static unsigned int ifindex = 0; 00354 int rc; 00355 00356 /* Create device name */ 00357 snprintf ( netdev->name, sizeof ( netdev->name ), "net%d", 00358 ifindex++ ); 00359 00360 /* Set initial link-layer address */ 00361 netdev->ll_protocol->init_addr ( netdev->hw_addr, netdev->ll_addr ); 00362 00363 /* Register per-netdev configuration settings */ 00364 if ( ( rc = register_settings ( netdev_settings ( netdev ), 00365 NULL ) ) != 0 ) { 00366 DBGC ( netdev, "NETDEV %p could not register settings: %s\n", 00367 netdev, strerror ( rc ) ); 00368 return rc; 00369 } 00370 00371 /* Add to device list */ 00372 netdev_get ( netdev ); 00373 list_add_tail ( &netdev->list, &net_devices ); 00374 DBGC ( netdev, "NETDEV %p registered as %s (phys %s hwaddr %s)\n", 00375 netdev, netdev->name, netdev->dev->name, 00376 netdev_addr ( netdev ) ); 00377 00378 return 0; 00379 }
| int netdev_open | ( | struct net_device * | netdev | ) |
Open network device.
| netdev | Network device |
| rc | Return status code |
Definition at line 387 of file netdevice.c.
References DBGC, list_add, NETDEV_OPEN, net_device::op, net_device_operations::open, net_device::open_list, and net_device::state.
Referenced by efi_snp_initialize(), efi_snp_reset(), gdbudp_ensure_netdev_open(), ifopen(), iwlist(), and pxe_netdev_open().
00387 { 00388 int rc; 00389 00390 /* Do nothing if device is already open */ 00391 if ( netdev->state & NETDEV_OPEN ) 00392 return 0; 00393 00394 DBGC ( netdev, "NETDEV %p opening\n", netdev ); 00395 00396 /* Open the device */ 00397 if ( ( rc = netdev->op->open ( netdev ) ) != 0 ) 00398 return rc; 00399 00400 /* Mark as opened */ 00401 netdev->state |= NETDEV_OPEN; 00402 00403 /* Add to head of open devices list */ 00404 list_add ( &netdev->open_list, &open_net_devices ); 00405 00406 return 0; 00407 }
| void netdev_close | ( | struct net_device * | netdev | ) |
Close network device.
| netdev | Network device |
Definition at line 414 of file netdevice.c.
References net_device_operations::close, DBGC, list_del, NETDEV_OPEN, netdev_rx_flush(), netdev_tx_flush(), net_device::op, net_device::open_list, and net_device::state.
Referenced by efi_snp_reset(), efi_snp_shutdown(), ifclose(), iwlist(), pxe_netdev_close(), and unregister_netdev().
00414 { 00415 00416 /* Do nothing if device is already closed */ 00417 if ( ! ( netdev->state & NETDEV_OPEN ) ) 00418 return; 00419 00420 DBGC ( netdev, "NETDEV %p closing\n", netdev ); 00421 00422 /* Close the device */ 00423 netdev->op->close ( netdev ); 00424 00425 /* Flush TX and RX queues */ 00426 netdev_tx_flush ( netdev ); 00427 netdev_rx_flush ( netdev ); 00428 00429 /* Mark as closed */ 00430 netdev->state &= ~NETDEV_OPEN; 00431 00432 /* Remove from open devices list */ 00433 list_del ( &netdev->open_list ); 00434 }
| void unregister_netdev | ( | struct net_device * | netdev | ) |
Unregister network device.
| netdev | Network device |
Definition at line 443 of file netdevice.c.
References DBGC, net_device::list, list_del, netdev_close(), netdev_put(), netdev_settings(), and unregister_settings().
Referenced by a3c90x_remove(), atl1e_remove(), b44_remove(), e1000_remove(), e1000e_remove(), efab_probe(), efab_remove(), ifec_pci_remove(), igb_remove(), ipoib_remove(), legacy_remove(), mtnic_disable(), myri10ge_pci_remove(), natsemi_remove(), net80211_unregister(), phantom_probe(), phantom_remove(), pnic_remove(), rtl8169_remove(), rtl_probe(), rtl_remove(), sis190_remove(), skge_remove(), sky2_remove(), undinet_remove(), and vxge_device_unregister().
00443 { 00444 00445 /* Ensure device is closed */ 00446 netdev_close ( netdev ); 00447 00448 /* Unregister per-netdev configuration settings */ 00449 unregister_settings ( netdev_settings ( netdev ) ); 00450 00451 /* Remove from device list */ 00452 list_del ( &netdev->list ); 00453 netdev_put ( netdev ); 00454 DBGC ( netdev, "NETDEV %p unregistered\n", netdev ); 00455 }
| void netdev_irq | ( | struct net_device * | netdev, | |
| int | enable | |||
| ) |
Enable or disable interrupts.
| netdev | Network device | |
| enable | Interrupts should be enabled |
Definition at line 462 of file netdevice.c.
References net_device_operations::irq, NETDEV_IRQ_ENABLED, net_device::op, and net_device::state.
Referenced by pxe_netdev_close(), pxe_netdev_open(), pxenv_undi_isr(), and pxenv_undi_transmit().
00462 { 00463 00464 /* Enable or disable device interrupts */ 00465 netdev->op->irq ( netdev, enable ); 00466 00467 /* Record interrupt enabled state */ 00468 netdev->state &= ~NETDEV_IRQ_ENABLED; 00469 if ( enable ) 00470 netdev->state |= NETDEV_IRQ_ENABLED; 00471 }
| struct net_device* find_netdev | ( | const char * | name | ) | [read] |
Get network device by name.
| name | Network device name |
| netdev | Network device, or NULL |
Definition at line 479 of file netdevice.c.
References net_device::list, list_for_each_entry, net_device::name, netdev, NULL, and strcmp().
Referenced by dhcp_exec(), gdbudp_configure(), ifcommon_do_list(), and pxebs_exec().
00479 { 00480 struct net_device *netdev; 00481 00482 list_for_each_entry ( netdev, &net_devices, list ) { 00483 if ( strcmp ( netdev->name, name ) == 0 ) 00484 return netdev; 00485 } 00486 00487 return NULL; 00488 }
| struct net_device* find_netdev_by_location | ( | unsigned int | bus_type, | |
| unsigned int | location | |||
| ) | [read] |
Get network device by PCI bus:dev.fn address.
| bus_type | Bus type | |
| location | Bus location |
| netdev | Network device, or NULL |
Definition at line 497 of file netdevice.c.
References device_description::bus_type, device::desc, net_device::dev, net_device::list, list_for_each_entry, device_description::location, netdev, and NULL.
Referenced by efi_snp_netdev(), and pxenv_start_undi().
00498 { 00499 struct net_device *netdev; 00500 00501 list_for_each_entry ( netdev, &net_devices, list ) { 00502 if ( ( netdev->dev->desc.bus_type == bus_type ) && 00503 ( netdev->dev->desc.location == location ) ) 00504 return netdev; 00505 } 00506 00507 return NULL; 00508 }
| struct net_device* last_opened_netdev | ( | void | ) | [read] |
Get most recently opened network device.
| netdev | Most recently opened network device, or NULL |
Definition at line 515 of file netdevice.c.
References assert, list_for_each_entry, netdev, netdev_is_open(), NULL, and net_device::open_list.
Referenced by aoeboot(), iscsiboot(), nbi_prepare_dhcp(), parse_settings_name(), pxe_exec(), and store_cached_dhcpack().
00515 { 00516 struct net_device *netdev; 00517 00518 list_for_each_entry ( netdev, &open_net_devices, open_list ) { 00519 assert ( netdev_is_open ( netdev ) ); 00520 return netdev; 00521 } 00522 00523 return NULL; 00524 }
| int net_tx | ( | struct io_buffer * | iobuf, | |
| struct net_device * | netdev, | |||
| struct net_protocol * | net_protocol, | |||
| const void * | ll_dest | |||
| ) |
Transmit network-layer packet.
| iobuf | I/O buffer | |
| netdev | Network device | |
| net_protocol | Network-layer protocol | |
| ll_dest | Destination link-layer address |
| rc | Return status code |
Definition at line 539 of file netdevice.c.
References free_iob(), net_device::ll_addr, net_device::ll_protocol, net_protocol::net_proto, netdev_poll(), netdev_tx(), and ll_protocol::push.
Referenced by aoe_send_command(), arp_resolve(), arp_rx(), ipv4_tx(), ipv6_tx(), and wpa_send_eapol().
00540 { 00541 struct ll_protocol *ll_protocol = netdev->ll_protocol; 00542 int rc; 00543 00544 /* Force a poll on the netdevice to (potentially) clear any 00545 * backed-up TX completions. This is needed on some network 00546 * devices to avoid excessive losses due to small TX ring 00547 * sizes. 00548 */ 00549 netdev_poll ( netdev ); 00550 00551 /* Add link-layer header */ 00552 if ( ( rc = ll_protocol->push ( netdev, iobuf, ll_dest, netdev->ll_addr, 00553 net_protocol->net_proto ) ) != 0 ) { 00554 free_iob ( iobuf ); 00555 return rc; 00556 } 00557 00558 /* Transmit packet */ 00559 return netdev_tx ( netdev, iobuf ); 00560 }
| int net_rx | ( | struct io_buffer * | iobuf, | |
| struct net_device * | netdev, | |||
| uint16_t | net_proto, | |||
| const void * | ll_source | |||
| ) |
Process received network-layer packet.
| iobuf | I/O buffer | |
| netdev | Network device | |
| net_proto | Network-layer protocol, in network-byte order | |
| ll_source | Source link-layer address |
| rc | Return status code |
Definition at line 571 of file netdevice.c.
References DBGC, for_each_table_entry, free_iob(), net_protocol::net_proto, NET_PROTOCOLS, ntohs, and net_protocol::rx.
Referenced by net_step().
00572 { 00573 struct net_protocol *net_protocol; 00574 00575 /* Hand off to network-layer protocol, if any */ 00576 for_each_table_entry ( net_protocol, NET_PROTOCOLS ) { 00577 if ( net_protocol->net_proto == net_proto ) 00578 return net_protocol->rx ( iobuf, netdev, ll_source ); 00579 } 00580 00581 DBGC ( netdev, "NETDEV %p unknown network protocol %04x\n", 00582 netdev, ntohs ( net_proto ) ); 00583 free_iob ( iobuf ); 00584 return 0; 00585 }
Single-step the network stack.
This polls all interfaces for received packets, and processes packets from the RX queue.
Definition at line 595 of file netdevice.c.
References io_buffer::data, DBGC, free_iob(), iob_len(), list_for_each_entry, net_device::ll_protocol, net_rx(), netdev, netdev_poll(), netdev_rx_dequeue(), and ll_protocol::pull.
00595 { 00596 struct net_device *netdev; 00597 struct io_buffer *iobuf; 00598 struct ll_protocol *ll_protocol; 00599 const void *ll_dest; 00600 const void *ll_source; 00601 uint16_t net_proto; 00602 int rc; 00603 00604 /* Poll and process each network device */ 00605 list_for_each_entry ( netdev, &net_devices, list ) { 00606 00607 /* Poll for new packets */ 00608 netdev_poll ( netdev ); 00609 00610 /* Process at most one received packet. Give priority 00611 * to getting packets out of the NIC over processing 00612 * the received packets, because we advertise a window 00613 * that assumes that we can receive packets from the 00614 * NIC faster than they arrive. 00615 */ 00616 if ( ( iobuf = netdev_rx_dequeue ( netdev ) ) ) { 00617 00618 DBGC ( netdev, "NETDEV %p processing %p (%p+%zx)\n", 00619 netdev, iobuf, iobuf->data, 00620 iob_len ( iobuf ) ); 00621 00622 /* Remove link-layer header */ 00623 ll_protocol = netdev->ll_protocol; 00624 if ( ( rc = ll_protocol->pull ( netdev, iobuf, 00625 &ll_dest, &ll_source, 00626 &net_proto ) ) != 0 ) { 00627 free_iob ( iobuf ); 00628 continue; 00629 } 00630 00631 net_rx ( iobuf, netdev, net_proto, ll_source ); 00632 } 00633 } 00634 }
| struct list_head net_devices = LIST_HEAD_INIT ( net_devices ) |
struct list_head open_net_devices = LIST_HEAD_INIT ( open_net_devices ) [static] |
List of open network devices, in reverse order of opening.
Definition at line 46 of file netdevice.c.
| struct errortab netdev_errors [] __errortab |
Initial value:
{
{ EUNKNOWN_LINK_STATUS, "Unknown" },
}
Definition at line 52 of file netdevice.c.
| struct process net_process __permanent_process |
Initial value:
{
.list = LIST_HEAD_INIT ( net_process.list ),
.step = net_step,
}
Definition at line 637 of file netdevice.c.
1.5.7.1