iPXE
netdevice.h File Reference

Network device management. More...

#include <stdint.h>
#include <ipxe/list.h>
#include <ipxe/tables.h>
#include <ipxe/refcnt.h>
#include <ipxe/settings.h>
#include <ipxe/interface.h>
#include <ipxe/retry.h>

Go to the source code of this file.

Data Structures

struct  net_protocol
 A network-layer protocol. More...
struct  ll_protocol
 A link-layer protocol. More...
struct  net_device_operations
 Network device operations. More...
struct  net_device_error
 Network device error. More...
struct  net_device_stats
 Network device statistics. More...
struct  net_device_configuration
 A network device configuration. More...
struct  net_device_configurator
 A network device configurator. More...
struct  net_device
 A network device. More...
struct  net_driver
 A network upper-layer driver. More...

Macros

#define MAX_HW_ADDR_LEN   8
 Maximum length of a hardware address.
#define MAX_LL_ADDR_LEN   20
 Maximum length of a link-layer address.
#define MAX_LL_HEADER_LEN   64
 Maximum length of a link-layer header.
#define MAX_NET_ADDR_LEN   16
 Maximum length of a network-layer address.
#define MAX_NET_HEADER_LEN   40
 Maximum length of a network-layer header.
#define MAX_LL_NET_HEADER_LEN   ( MAX_LL_HEADER_LEN + MAX_NET_HEADER_LEN )
 Maximum combined length of a link-layer and network-layer header.
#define LL_MULTICAST   0x0001
 Packet is a multicast (including broadcast) packet.
#define LL_BROADCAST   0x0002
 Packet is a broadcast packet.
#define LL_NAME_ONLY   0x0001
 Local link-layer address functions only as a name.
#define NETDEV_MAX_UNIQUE_ERRORS   4
 Maximum number of unique errors that we will keep track of.
#define NET_DEVICE_CONFIGURATORS    __table ( struct net_device_configurator, "net_device_configurators" )
 Network device configurator table.
#define __net_device_configurator    __table_entry ( NET_DEVICE_CONFIGURATORS, 01 )
 Declare a network device configurator.
#define NETDEV_NAME_LEN   12
 Maximum length of a network device name.
#define NETDEV_OPEN   0x0001
 Network device is open.
#define NETDEV_IRQ_ENABLED   0x0002
 Network device interrupts are enabled.
#define NETDEV_RX_FROZEN   0x0004
 Network device receive queue processing is frozen.
#define NETDEV_IRQ_UNSUPPORTED   0x0008
 Network device interrupts are unsupported.
#define NETDEV_TX_IN_PROGRESS   0x0010
 Network device transmission is in progress.
#define NETDEV_POLL_IN_PROGRESS   0x0020
 Network device poll is in progress.
#define NETDEV_INSOMNIAC   0x0040
 Network device must be polled even when closed.
#define LL_PROTOCOLS   __table ( struct ll_protocol, "ll_protocols" )
 Link-layer protocol table.
#define __ll_protocol   __table_entry ( LL_PROTOCOLS, 01 )
 Declare a link-layer protocol.
#define NET_PROTOCOLS   __table ( struct net_protocol, "net_protocols" )
 Network-layer protocol table.
#define __net_protocol   __table_entry ( NET_PROTOCOLS, 01 )
 Declare a network-layer protocol.
#define NET_DRIVERS   __table ( struct net_driver, "net_drivers" )
 Network driver table.
#define __net_driver   __table_entry ( NET_DRIVERS, 01 )
 Declare a network driver.
#define for_each_netdev(netdev)
 Iterate over all network devices.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
static void netdev_init (struct net_device *netdev, struct net_device_operations *op)
 Initialise a network device.
static void netdev_nullify (struct net_device *netdev)
 Stop using a network device.
static const char * netdev_addr (struct net_device *netdev)
 Get printable network device link-layer address.
static int have_netdevs (void)
 There exist some network devices.
static struct net_devicenetdev_get (struct net_device *netdev)
 Get reference to network device.
static void netdev_put (struct net_device *netdev)
 Drop reference to network device.
static struct settingsnetdev_settings (struct net_device *netdev)
 Get per-netdevice configuration settings block.
static void netdev_settings_init (struct net_device *netdev)
 Initialise a per-netdevice configuration settings block.
static struct net_device_configurationnetdev_configuration (struct net_device *netdev, struct net_device_configurator *configurator)
 Get network device configuration.
static int netdev_configurator_applies (struct net_device *netdev, struct net_device_configurator *configurator)
 Check if configurator applies to network device.
static int netdev_link_ok (struct net_device *netdev)
 Check link state of network device.
static int netdev_link_blocked (struct net_device *netdev)
 Check link block state of network device.
static int netdev_is_open (struct net_device *netdev)
 Check whether or not network device is open.
static int netdev_irq_supported (struct net_device *netdev)
 Check whether or not network device supports interrupts.
static int netdev_irq_enabled (struct net_device *netdev)
 Check whether or not network device interrupts are currently enabled.
static int netdev_rx_frozen (struct net_device *netdev)
 Check whether or not network device receive queue processing is frozen.
static int netdev_insomniac (struct net_device *netdev)
 Check whether or not network device must be polled even while closed.
void * netdev_priv (struct net_device *netdev, struct net_driver *driver)
 Get network device driver private data.
void netdev_rx_freeze (struct net_device *netdev)
 Freeze network device receive queue processing.
void netdev_rx_unfreeze (struct net_device *netdev)
 Unfreeze network device receive queue processing.
void netdev_link_err (struct net_device *netdev, int rc)
 Mark network device as having a specific link state.
void netdev_link_down (struct net_device *netdev)
 Mark network device as having link down.
void netdev_link_block (struct net_device *netdev, unsigned long timeout)
 Mark network device link as being blocked.
void netdev_link_unblock (struct net_device *netdev)
 Mark network device link as being unblocked.
int netdev_tx (struct net_device *netdev, struct io_buffer *iobuf)
 Transmit raw packet via network device.
void netdev_tx_defer (struct net_device *netdev, struct io_buffer *iobuf)
 Defer transmitted packet.
void netdev_tx_err (struct net_device *netdev, struct io_buffer *iobuf, int rc)
 Discard transmitted packet.
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.
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_buffernetdev_rx_dequeue (struct net_device *netdev)
 Remove packet from device's receive queue.
struct net_devicealloc_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_devicefind_netdev (const char *name)
 Get network device by name.
struct net_devicefind_netdev_by_scope_id (unsigned int scope_id)
 Get network device by scope ID.
struct net_devicefind_netdev_by_location (unsigned int bus_type, unsigned int location)
 Get network device by PCI bus:dev.fn address.
struct net_devicelast_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, const void *ll_source)
 Transmit network-layer packet.
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.
void net_poll (void)
 Poll the network stack.
struct net_device_configuratorfind_netdev_configurator (const char *name)
 Find network device configurator.
int netdev_configure (struct net_device *netdev, struct net_device_configurator *configurator)
 Start network device configuration.
int netdev_configure_all (struct net_device *netdev)
 Start network device configuration via all supported configurators.
int netdev_configuration_in_progress (struct net_device *netdev)
 Check if network device configuration is in progress.
int netdev_configuration_ok (struct net_device *netdev)
 Check if network device has at least one successful configuration.
static void netdev_tx_complete (struct net_device *netdev, struct io_buffer *iobuf)
 Complete network transmission.
static void netdev_tx_complete_next (struct net_device *netdev)
 Complete network transmission.
static void netdev_link_up (struct net_device *netdev)
 Mark network device as having link up.

Variables

struct list_head net_devices
 List of network devices.
struct net_device_operations null_netdev_operations
struct settings_operations netdev_settings_operations
 Network device configuration settings operations.

Detailed Description

Network device management.

Definition in file netdevice.h.

Macro Definition Documentation

◆ MAX_HW_ADDR_LEN

#define MAX_HW_ADDR_LEN   8

Maximum length of a hardware address.

The longest currently-supported link-layer address is for IPoIB.

Definition at line 31 of file netdevice.h.

◆ MAX_LL_ADDR_LEN

#define MAX_LL_ADDR_LEN   20

Maximum length of a link-layer address.

The longest currently-supported link-layer address is for IPoIB.

Definition at line 37 of file netdevice.h.

Referenced by arp_tx_request(), ipv4_tx(), ipv6_tx(), and pxenv_undi_transmit().

◆ MAX_LL_HEADER_LEN

#define MAX_LL_HEADER_LEN   64

Maximum length of a link-layer header.

The longest currently-supported link-layer header is for RNDIS: an 8-byte RNDIS header, a 32-byte RNDIS packet message header, a 14-byte Ethernet header and a possible 4-byte VLAN header. Round up to 64 bytes.

Definition at line 46 of file netdevice.h.

Referenced by aoecmd_tx(), arp_tx_request(), eapol_tx(), efi_snp_transmit(), fcoe_alloc_iob(), fcoe_fip_tx_keepalive(), fcoe_fip_tx_solicitation(), fcoe_fip_tx_vlan(), loopback_test(), pxenv_undi_transmit(), and wpa_alloc_frame().

◆ MAX_NET_ADDR_LEN

#define MAX_NET_ADDR_LEN   16

Maximum length of a network-layer address.

Definition at line 49 of file netdevice.h.

Referenced by arp_tx_request().

◆ MAX_NET_HEADER_LEN

#define MAX_NET_HEADER_LEN   40

Maximum length of a network-layer header.

The longest currently-supported network-layer header is for IPv6 at 40 bytes.

Definition at line 56 of file netdevice.h.

◆ MAX_LL_NET_HEADER_LEN

#define MAX_LL_NET_HEADER_LEN   ( MAX_LL_HEADER_LEN + MAX_NET_HEADER_LEN )

Maximum combined length of a link-layer and network-layer header.

Definition at line 59 of file netdevice.h.

Referenced by ndp_tx_ll_addr(), ping_alloc_iob(), udp_tx(), and udp_xfer_alloc_iob().

◆ LL_MULTICAST

#define LL_MULTICAST   0x0001

Packet is a multicast (including broadcast) packet.

Definition at line 106 of file netdevice.h.

Referenced by eth_pull(), ipv4_rx(), ipv6_rx(), net80211_ll_pull(), and pxenv_undi_isr().

◆ LL_BROADCAST

#define LL_BROADCAST   0x0002

Packet is a broadcast packet.

Definition at line 109 of file netdevice.h.

Referenced by eth_pull(), ipv4_rx(), ipv6_rx(), net80211_ll_pull(), pxenv_undi_isr(), and undinet_transmit().

◆ LL_NAME_ONLY

#define LL_NAME_ONLY   0x0001

Local link-layer address functions only as a name.

This flag indicates that the local link-layer address cannot directly be used as a destination address by a remote node.

Definition at line 211 of file netdevice.h.

Referenced by dhcp_create_packet().

◆ NETDEV_MAX_UNIQUE_ERRORS

#define NETDEV_MAX_UNIQUE_ERRORS   4

Maximum number of unique errors that we will keep track of.

Definition at line 289 of file netdevice.h.

◆ NET_DEVICE_CONFIGURATORS

#define NET_DEVICE_CONFIGURATORS    __table ( struct net_device_configurator, "net_device_configurators" )

Network device configurator table.

Definition at line 333 of file netdevice.h.

333#define NET_DEVICE_CONFIGURATORS \
334 __table ( struct net_device_configurator, "net_device_configurators" )

Referenced by alloc_netdev(), find_netdev_configurator(), netdev_close(), netdev_configuration(), netdev_configure_all(), netdev_has_configuration_rc(), and netdev_priv_offset().

◆ __net_device_configurator

#define __net_device_configurator    __table_entry ( NET_DEVICE_CONFIGURATORS, 01 )

Declare a network device configurator.

Definition at line 337 of file netdevice.h.

337#define __net_device_configurator \
338 __table_entry ( NET_DEVICE_CONFIGURATORS, 01 )

◆ NETDEV_NAME_LEN

#define NETDEV_NAME_LEN   12

Maximum length of a network device name.

Definition at line 341 of file netdevice.h.

Referenced by ipv6_sock_ntoa().

◆ NETDEV_OPEN

#define NETDEV_OPEN   0x0001

Network device is open.

Definition at line 439 of file netdevice.h.

Referenced by efx_hunt_irq(), netdev_close(), netdev_is_open(), netdev_open(), and netdev_poll().

◆ NETDEV_IRQ_ENABLED

#define NETDEV_IRQ_ENABLED   0x0002

Network device interrupts are enabled.

Definition at line 442 of file netdevice.h.

Referenced by netdev_irq(), and netdev_irq_enabled().

◆ NETDEV_RX_FROZEN

#define NETDEV_RX_FROZEN   0x0004

Network device receive queue processing is frozen.

Definition at line 445 of file netdevice.h.

Referenced by netdev_rx_freeze(), netdev_rx_frozen(), and netdev_rx_unfreeze().

◆ NETDEV_IRQ_UNSUPPORTED

#define NETDEV_IRQ_UNSUPPORTED   0x0008

Network device interrupts are unsupported.

This flag can be used by a network device to indicate that interrupts are not supported despite the presence of an irq() method.

Definition at line 453 of file netdevice.h.

Referenced by hunt_probe(), net80211_register(), netdev_irq_supported(), and vlan_create().

◆ NETDEV_TX_IN_PROGRESS

#define NETDEV_TX_IN_PROGRESS   0x0010

Network device transmission is in progress.

Definition at line 456 of file netdevice.h.

Referenced by netdev_tx().

◆ NETDEV_POLL_IN_PROGRESS

#define NETDEV_POLL_IN_PROGRESS   0x0020

Network device poll is in progress.

Definition at line 459 of file netdevice.h.

Referenced by netdev_poll().

◆ NETDEV_INSOMNIAC

#define NETDEV_INSOMNIAC   0x0040

Network device must be polled even when closed.

Definition at line 462 of file netdevice.h.

Referenced by netdev_insomniac(), netdev_poll(), and snpnet_start().

◆ LL_PROTOCOLS

#define LL_PROTOCOLS   __table ( struct ll_protocol, "ll_protocols" )

Link-layer protocol table.

Definition at line 465 of file netdevice.h.

◆ __ll_protocol

#define __ll_protocol   __table_entry ( LL_PROTOCOLS, 01 )

Declare a link-layer protocol.

Definition at line 468 of file netdevice.h.

◆ NET_PROTOCOLS

#define NET_PROTOCOLS   __table ( struct net_protocol, "net_protocols" )

Network-layer protocol table.

Definition at line 471 of file netdevice.h.

Referenced by net_rx().

◆ __net_protocol

struct net_protocol vlan_protocol __net_protocol   __table_entry ( NET_PROTOCOLS, 01 )

Declare a network-layer protocol.

VLAN protocol.

FIP protocol.

FCoE protocol.

Slow protocol.

ARP network protocol.

AoE protocol.

Definition at line 474 of file netdevice.h.

Referenced by FILE_LICENCE().

◆ NET_DRIVERS

#define NET_DRIVERS   __table ( struct net_driver, "net_drivers" )

Network driver table.

Definition at line 504 of file netdevice.h.

Referenced by netdev_notify(), netdev_priv_offset(), register_netdev(), and unregister_netdev().

◆ __net_driver

struct net_driver lldp_driver __net_driver   __table_entry ( NET_DRIVERS, 01 )

Declare a network driver.

LLDP driver.

FCoE driver.

EAPoL driver.

Definition at line 507 of file netdevice.h.

◆ for_each_netdev

#define for_each_netdev ( netdev)
Value:
static struct net_device * netdev
Definition gdbudp.c:53
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition list.h:432
struct list_head net_devices
List of network devices.
Definition netdevice.c:54

Iterate over all network devices.

Definition at line 547 of file netdevice.h.

547#define for_each_netdev( netdev ) \
548 list_for_each_entry ( (netdev), &net_devices, list )

Referenced by apply_netdev_settings(), autoboot(), close_other_netdevs(), eoib_discard(), ibft_fill_target_nic_association(), ibft_install(), ifcommon_exec(), ipoib_discard_remac(), ipv4_settings(), ipv6_create_all_routes(), net_discard(), peerdisc_socket_tx(), route(), vlan_find(), vlan_notify(), and vlan_remove_first().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ netdev_init()

void netdev_init ( struct net_device * netdev,
struct net_device_operations * op )
inlinestatic

◆ netdev_nullify()

void netdev_nullify ( struct net_device * netdev)
inlinestatic

Stop using a network device.

Parameters
netdevNetwork device

Drivers should call this method immediately before the final call to netdev_put().

Definition at line 532 of file netdevice.h.

532 {
534}
struct net_device_operations null_netdev_operations
Definition nullnet.c:60

References netdev, and null_netdev_operations.

Referenced by a3c90x_remove(), af_packet_nic_probe(), af_packet_nic_remove(), atl1e_probe(), atl1e_remove(), atl_probe(), atl_remove(), axge_probe(), axge_remove(), b44_remove(), bnxt_init_one(), bnxt_remove_one(), cgem_probe(), cgem_remove(), dm96xx_probe(), dm96xx_remove(), dwmac_probe(), dwmac_remove(), ecm_probe(), ecm_remove(), efab_remove(), ena_probe(), ena_remove(), eoib_create(), eoib_destroy(), exanic_probe_port(), exanic_remove_port(), flexboot_nodnic_unregister_netdev(), forcedeth_probe(), forcedeth_remove(), free_rndis(), golan_remove_normal(), gve_probe(), gve_remove(), hermon_probe(), hermon_remove(), hunt_remove(), ice_probe(), ice_remove(), icplus_probe(), icplus_remove(), ifec_pci_probe(), ifec_pci_remove(), igbvf_remove(), intel_probe(), intel_remove(), intelx_probe(), intelx_remove(), intelxl_probe(), intelxl_remove(), intelxlvf_probe(), intelxlvf_remove(), intelxvf_probe(), intelxvf_remove(), iphone_probe(), iphone_remove(), ipoib_probe(), ipoib_remove(), jme_probe(), jme_remove(), lan78xx_probe(), lan78xx_remove(), legacy_probe(), legacy_remove(), mnpnet_start(), mnpnet_stop(), myri10ge_pci_probe(), myri10ge_pci_remove(), myson_probe(), myson_remove(), natsemi_probe(), natsemi_remove(), ncm_probe(), ncm_remove(), net80211_free(), netfront_probe(), netfront_remove(), nii_start(), nii_stop(), pcnet32_remove(), phantom_probe(), phantom_remove(), pnic_probe(), pnic_remove(), rdc_probe(), rdc_remove(), realtek_probe(), realtek_remove(), rhine_probe(), rhine_remove(), sis190_remove(), skeleton_probe(), skeleton_remove(), skge_probe(), skge_remove(), sky2_probe(), sky2_remove(), slirp_probe(), slirp_remove(), smsc75xx_probe(), smsc75xx_remove(), smsc95xx_probe(), smsc95xx_remove(), snpnet_start(), snpnet_stop(), tap_probe(), tap_remove(), testnet_remove_okx(), tg3_remove_one(), txnic_alloc(), txnic_free(), undinet_probe(), undinet_remove(), velocity_probe(), velocity_remove(), virtnet_probe_legacy(), virtnet_probe_modern(), virtnet_remove(), vlan_create(), vlan_destroy(), vmxnet3_probe(), vmxnet3_remove(), and vxge_device_unregister().

◆ netdev_addr()

const char * netdev_addr ( struct net_device * netdev)
inlinestatic

Get printable network device link-layer address.

Parameters
netdevNetwork device
Return values
nameLink-layer address

Definition at line 542 of file netdevice.h.

542 {
543 return netdev->ll_protocol->ntoa ( netdev->ll_addr );
544}

References netdev.

Referenced by efi_snp_hii_package_list(), efi_snp_probe(), ifstat(), register_netdev(), rtl818x_probe(), skge_show_addr(), and sky2_show_addr().

◆ have_netdevs()

int have_netdevs ( void )
inlinestatic

There exist some network devices.

Return values
existenceExistence of network devices

Definition at line 554 of file netdevice.h.

554 {
555 return ( ! list_empty ( &net_devices ) );
556}
#define list_empty(list)
Test whether a list is empty.
Definition list.h:137

References list_empty, and net_devices.

◆ netdev_get()

struct net_device * netdev_get ( struct net_device * netdev)
inlinestatic

Get reference to network device.

Parameters
netdevNetwork device
Return values
netdevNetwork device

Definition at line 565 of file netdevice.h.

565 {
566 ref_get ( &netdev->refcnt );
567 return netdev;
568}
#define ref_get(refcnt)
Get additional reference to object.
Definition refcnt.h:93

References netdev, and ref_get.

Referenced by aoedev_open(), efi_pxe_install(), efi_snp_probe(), gdbudp_configure(), ipv4_add_miniroute(), ipv6_add_miniroute(), neighbour_create(), pxe_exec(), pxe_set_netdev(), register_netdev(), start_dhcp(), start_dhcpv6(), start_ipv6conf(), start_pxebs(), and vlan_create().

◆ netdev_put()

void netdev_put ( struct net_device * netdev)
inlinestatic

Drop reference to network device.

Parameters
netdevNetwork device

Definition at line 576 of file netdevice.h.

576 {
577 ref_put ( &netdev->refcnt );
578}
#define ref_put(refcnt)
Drop reference to object.
Definition refcnt.h:107

References netdev, and ref_put.

Referenced by a3c90x_probe(), a3c90x_remove(), af_packet_nic_probe(), af_packet_nic_remove(), aoedev_free(), atl1e_probe(), atl1e_remove(), atl_probe(), atl_remove(), axge_probe(), axge_remove(), b44_probe(), b44_remove(), bnxt_init_one(), bnxt_remove_one(), cgem_probe(), cgem_remove(), dhcp_free(), dhcpv6_free(), dm96xx_probe(), dm96xx_remove(), dwmac_probe(), dwmac_remove(), ecm_probe(), ecm_remove(), efab_probe(), efab_remove(), efi_pxe_free(), efi_snp_probe(), efi_snp_remove(), ena_probe(), ena_remove(), eoib_create(), eoib_destroy(), exanic_probe_port(), exanic_remove_port(), flexboot_nodnic_register_netdev(), flexboot_nodnic_unregister_netdev(), forcedeth_probe(), forcedeth_remove(), free_rndis(), gdbudp_configure(), gve_probe(), gve_remove(), hermon_probe(), hermon_remove(), hunt_probe(), hunt_remove(), ice_probe(), ice_remove(), icplus_probe(), icplus_remove(), ifec_pci_probe(), ifec_pci_remove(), igbvf_probe(), igbvf_remove(), intel_probe(), intel_remove(), intelx_probe(), intelx_remove(), intelxl_probe(), intelxl_remove(), intelxlvf_probe(), intelxlvf_remove(), intelxvf_probe(), intelxvf_remove(), iphone_probe(), iphone_remove(), ipoib_probe(), ipoib_remove(), ipv4_del_miniroute(), ipv6_del_miniroute(), ipv6conf_free(), jme_probe(), jme_remove(), lan78xx_probe(), lan78xx_remove(), legacy_probe(), legacy_remove(), mnpnet_start(), mnpnet_stop(), myri10ge_pci_probe(), myri10ge_pci_remove(), myson_probe(), myson_remove(), natsemi_probe(), natsemi_remove(), ncm_probe(), ncm_remove(), neighbour_free(), net80211_free(), netfront_probe(), netfront_remove(), nii_start(), nii_stop(), pcnet32_probe(), pcnet32_remove(), phantom_probe(), phantom_remove(), pnic_probe(), pnic_remove(), pxe_exec(), pxe_set_netdev(), rdc_probe(), rdc_remove(), realtek_probe(), realtek_remove(), register_netdev(), rhine_probe(), rhine_remove(), sis190_remove(), skeleton_probe(), skeleton_remove(), skge_probe(), skge_remove(), sky2_probe(), sky2_remove(), slirp_probe(), slirp_remove(), smsc75xx_probe(), smsc75xx_remove(), smsc95xx_probe(), smsc95xx_remove(), snpnet_start(), snpnet_stop(), tap_probe(), tap_remove(), testnet_remove_okx(), tg3_init_one(), tg3_remove_one(), txnic_alloc(), txnic_free(), undinet_probe(), undinet_remove(), unregister_netdev(), velocity_probe(), velocity_remove(), virtnet_probe_legacy(), virtnet_probe_modern(), virtnet_remove(), vlan_create(), vlan_destroy(), vmxnet3_probe(), vmxnet3_remove(), vxge_device_register(), and vxge_device_unregister().

◆ netdev_settings()

◆ netdev_settings_init()

void netdev_settings_init ( struct net_device * netdev)
inlinestatic

Initialise a per-netdevice configuration settings block.

Parameters
genericsGeneric settings block
refcntContaining object reference counter, or NULL
nameSettings block name

Definition at line 599 of file netdevice.h.

599 {
600 generic_settings_init ( &netdev->settings, &netdev->refcnt );
601 netdev->settings.settings.op = &netdev_settings_operations;
602}
static void generic_settings_init(struct generic_settings *generics, struct refcnt *refcnt)
Initialise a settings block.
Definition settings.h:520
struct settings_operations netdev_settings_operations
Network device configuration settings operations.

References generic_settings_init(), netdev, and netdev_settings_operations.

Referenced by alloc_netdev().

◆ netdev_configuration()

struct net_device_configuration * netdev_configuration ( struct net_device * netdev,
struct net_device_configurator * configurator )
inlinestatic

Get network device configuration.

Parameters
netdevNetwork device
configuratorNetwork device configurator
Return values
configNetwork device configuration

Definition at line 612 of file netdevice.h.

613 {
614
615 return &netdev->configs[ table_index ( NET_DEVICE_CONFIGURATORS,
616 configurator ) ];
617}
#define NET_DEVICE_CONFIGURATORS
Network device configurator table.
Definition netdevice.h:333
#define table_index(table, entry)
Get index of entry within linker table.
Definition tables.h:362

References net_device_configuration::configurator, NET_DEVICE_CONFIGURATORS, netdev, and table_index.

Referenced by ifconf_progress(), and netdev_configure().

◆ netdev_configurator_applies()

int netdev_configurator_applies ( struct net_device * netdev,
struct net_device_configurator * configurator )
inlinestatic

Check if configurator applies to network device.

Parameters
netdevNetwork device
configuratorNetwork device configurator
Return values
appliesConfigurator applies to network device

Definition at line 627 of file netdevice.h.

628 {
629 return ( ( configurator->applies == NULL ) ||
630 configurator->applies ( netdev ) );
631}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
int(* applies)(struct net_device *netdev)
Check applicability of configurator.
Definition netdevice.h:322

References net_device_configurator::applies, net_device_configuration::configurator, netdev, and NULL.

Referenced by netdev_configure(), and netdev_configure_all().

◆ netdev_link_ok()

◆ netdev_link_blocked()

int netdev_link_blocked ( struct net_device * netdev)
inlinestatic

Check link block state of network device.

Parameters
netdevNetwork device
Return values
link_blockedLink is blocked

Definition at line 651 of file netdevice.h.

651 {
652 return ( timer_running ( &netdev->link_block ) );
653}

References netdev.

Referenced by dhcp_discovery_expired(), eth_slow_lacp_rx(), ifstat(), ipv6conf_expired(), netdev_link_block(), netdev_link_unblock(), and stp_rx().

◆ netdev_is_open()

◆ netdev_irq_supported()

int netdev_irq_supported ( struct net_device * netdev)
inlinestatic

Check whether or not network device supports interrupts.

Parameters
netdevNetwork device
Return values
irq_supportedNetwork device supports interrupts

Definition at line 673 of file netdevice.h.

673 {
674 return ( ( netdev->op->irq != NULL ) &&
675 ! ( netdev->state & NETDEV_IRQ_UNSUPPORTED ) );
676}
#define NETDEV_IRQ_UNSUPPORTED
Network device interrupts are unsupported.
Definition netdevice.h:453

References netdev, NETDEV_IRQ_UNSUPPORTED, and NULL.

Referenced by netdev_irq(), pxe_exec(), pxenv_undi_get_iface_info(), pxenv_undi_get_information(), and vlan_create().

◆ netdev_irq_enabled()

int netdev_irq_enabled ( struct net_device * netdev)
inlinestatic

Check whether or not network device interrupts are currently enabled.

Parameters
netdevNetwork device
Return values
irq_enabledNetwork device interrupts are enabled

Definition at line 685 of file netdevice.h.

685 {
686 return ( netdev->state & NETDEV_IRQ_ENABLED );
687}
#define NETDEV_IRQ_ENABLED
Network device interrupts are enabled.
Definition netdevice.h:442

References netdev, and NETDEV_IRQ_ENABLED.

Referenced by pxenv_undi_isr().

◆ netdev_rx_frozen()

int netdev_rx_frozen ( struct net_device * netdev)
inlinestatic

Check whether or not network device receive queue processing is frozen.

Parameters
netdevNetwork device
Return values
rx_frozenNetwork device receive queue processing is frozen

Definition at line 696 of file netdevice.h.

696 {
697 return ( netdev->state & NETDEV_RX_FROZEN );
698}
#define NETDEV_RX_FROZEN
Network device receive queue processing is frozen.
Definition netdevice.h:445

References netdev, and NETDEV_RX_FROZEN.

Referenced by net_poll(), and pxenv_undi_transmit().

◆ netdev_insomniac()

int netdev_insomniac ( struct net_device * netdev)
inlinestatic

Check whether or not network device must be polled even while closed.

Parameters
netdevNetwork device
Return values
insomniacNetwork device must be polled even while closed

Definition at line 707 of file netdevice.h.

707 {
708 return ( netdev->state & NETDEV_INSOMNIAC );
709}
#define NETDEV_INSOMNIAC
Network device must be polled even when closed.
Definition netdevice.h:462

References netdev, and NETDEV_INSOMNIAC.

Referenced by snpnet_close(), snpnet_open(), and snpnet_start().

◆ netdev_priv()

void * netdev_priv ( struct net_device * netdev,
struct net_driver * driver )
extern

Get network device driver private data.

Parameters
netdevNetwork device
driverUpper-layer driver, or NULL for device driver
Return values
privDriver private data

Definition at line 153 of file netdevice.c.

153 {
154
155 return ( ( ( void * ) netdev ) + netdev_priv_offset ( driver ) );
156}
static size_t netdev_priv_offset(struct net_driver *driver)
Get offset of network device driver private data.
Definition netdevice.c:119

References netdev, and netdev_priv_offset().

Referenced by alloc_netdev(), eapol_rx(), fcoe_fip_rx(), fcoe_rx(), lldp_rx(), netdev_notify(), register_netdev(), and unregister_netdev().

◆ netdev_rx_freeze()

void netdev_rx_freeze ( struct net_device * netdev)
extern

Freeze network device receive queue processing.

Parameters
netdevNetwork device

Definition at line 179 of file netdevice.c.

179 {
180
181 /* Mark receive queue processing as frozen */
182 netdev->state |= NETDEV_RX_FROZEN;
183
184 /* Notify drivers of change */
186}
static void netdev_notify(struct net_device *netdev)
Notify drivers of network device or link state change.
Definition netdevice.c:163

References netdev, netdev_notify(), and NETDEV_RX_FROZEN.

Referenced by pxe_netdev_open(), and pxenv_undi_transmit().

◆ netdev_rx_unfreeze()

void netdev_rx_unfreeze ( struct net_device * netdev)
extern

Unfreeze network device receive queue processing.

Parameters
netdevNetwork device

Definition at line 193 of file netdevice.c.

193 {
194
195 /* Mark receive queue processing as not frozen */
196 netdev->state &= ~NETDEV_RX_FROZEN;
197
198 /* Notify drivers of change */
200}

References netdev, netdev_notify(), and NETDEV_RX_FROZEN.

Referenced by pxe_netdev_close(), and pxe_set_netdev().

◆ netdev_link_err()

void netdev_link_err ( struct net_device * netdev,
int rc )
extern

Mark network device as having a specific link state.

Parameters
netdevNetwork device
rcLink status code

Definition at line 208 of file netdevice.c.

208 {
209
210 /* Stop link block timer */
211 stop_timer ( &netdev->link_block );
212
213 /* Record link state */
214 netdev->link_rc = rc;
215 if ( netdev->link_rc == 0 ) {
216 DBGC ( netdev, "NETDEV %s link is up\n", netdev->name );
217 } else {
218 DBGC ( netdev, "NETDEV %s link is down: %s\n",
219 netdev->name, strerror ( netdev->link_rc ) );
220 }
221
222 /* Notify drivers of link state change */
224}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
#define DBGC(...)
Definition compiler.h:505
void stop_timer(struct retry_timer *timer)
Stop timer.
Definition retry.c:118
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79

References DBGC, netdev, netdev_notify(), rc, stop_timer(), and strerror().

Referenced by eoib_join_complete(), eoib_link_state_changed(), gve_startup(), iphone_check_link(), ipoib_join_complete(), ipoib_link_state_changed(), net80211_deauthenticate(), net80211_set_state(), net80211_step_associate(), netdev_link_down(), netdev_link_up(), netfront_close(), rhine_check_link(), skeleton_check_link(), and vlan_sync().

◆ netdev_link_down()

void netdev_link_down ( struct net_device * netdev)
extern

Mark network device as having link down.

Parameters
netdevNetwork device

Definition at line 231 of file netdevice.c.

231 {
232
233 /* Avoid clobbering a more detailed link status code, if one
234 * is already set.
235 */
236 if ( ( netdev->link_rc == 0 ) ||
237 ( netdev->link_rc == -EUNKNOWN_LINK_STATUS ) ) {
239 }
240}
#define EUNKNOWN_LINK_STATUS
Default link status code.
Definition fc.c:186
void netdev_link_err(struct net_device *netdev, int rc)
Mark network device as having a specific link state.
Definition netdevice.c:208
#define ENOTCONN_LINK_DOWN
Default link-down status code.
Definition netdevice.c:84

References ENOTCONN_LINK_DOWN, EUNKNOWN_LINK_STATUS, netdev, and netdev_link_err().

Referenced by __vxge_hw_vpath_alarm_process(), atl1e_check_link(), atl1e_down(), atl_check_link(), atl_probe(), axge_check_link(), bnxt_set_link(), dm96xx_link_nsr(), dwmac_check_link(), ecm_intr_complete(), exanic_check_link(), flexboot_nodnic_state_change_netdev(), forcedeth_link_status(), gve_restart(), hermon_state_change_netdev(), hunt_check_link(), hunt_open(), ice_admin_link(), icplus_check_link(), intel_check_link(), intelx_check_link(), intelxl_admin_link(), intelxlvf_admin_link(), intelxvf_check_link(), jme_check_link(), jme_close(), jme_link_change(), mii_check_link(), myri10ge_interrupt_handler(), natsemi_check_link(), ncm_intr_complete(), net80211_netdev_close(), net80211_set_state(), netfront_close(), netfront_probe(), nii_poll_link(), phantom_poll_link_state(), realtek_check_link(), rhine_check_link(), rndis_rx_query_oid(), rndis_rx_status(), sis190_phy_task(), skge_down(), skge_link_down(), sky2_link_down(), sky2_up(), snpnet_check_link(), tg3_phy_reset(), tg3_setup_copper_phy(), tg3_setup_fiber_mii_phy(), tg3_test_and_report_link_chg(), txnic_lmac_update_link(), velocity_check_link(), vmxnet3_check_link(), vxge_close(), and vxge_open().

◆ netdev_link_block()

void netdev_link_block ( struct net_device * netdev,
unsigned long timeout )
extern

Mark network device link as being blocked.

Parameters
netdevNetwork device
timeoutTimeout (in ticks)

Definition at line 248 of file netdevice.c.

248 {
249
250 /* Start link block timer */
251 if ( ! netdev_link_blocked ( netdev ) ) {
252 DBGC ( netdev, "NETDEV %s link blocked for %ld ticks\n",
253 netdev->name, timeout );
254 }
255 start_timer_fixed ( &netdev->link_block, timeout );
256}
void timeout(int)
static int netdev_link_blocked(struct net_device *netdev)
Check link block state of network device.
Definition netdevice.h:651
void start_timer_fixed(struct retry_timer *timer, unsigned long timeout)
Start timer with a specified timeout.
Definition retry.c:65

References DBGC, netdev, netdev_link_blocked(), start_timer_fixed(), and timeout().

Referenced by eap_rx_identity(), eth_slow_lacp_rx(), and stp_rx().

◆ netdev_link_unblock()

void netdev_link_unblock ( struct net_device * netdev)
extern

Mark network device link as being unblocked.

Parameters
netdevNetwork device

Definition at line 263 of file netdevice.c.

263 {
264
265 /* Stop link block timer */
266 if ( netdev_link_blocked ( netdev ) )
267 DBGC ( netdev, "NETDEV %s link unblocked\n", netdev->name );
268 stop_timer ( &netdev->link_block );
269}

References DBGC, netdev, netdev_link_blocked(), and stop_timer().

Referenced by eap_rx_success(), eth_slow_lacp_rx(), and stp_rx().

◆ netdev_tx()

int netdev_tx ( struct net_device * netdev,
struct io_buffer * iobuf )
extern

Transmit raw packet via network device.

Parameters
netdevNetwork device
iobufI/O buffer
Return values
rcReturn status code

Transmits the packet via the specified network device. This function takes ownership of the I/O buffer.

Definition at line 335 of file netdevice.c.

335 {
336 int rc;
337
338 DBGC2 ( netdev, "NETDEV %s transmitting %p (%p+%zx)\n",
339 netdev->name, iobuf, iobuf->data, iob_len ( iobuf ) );
340 profile_start ( &net_tx_profiler );
341
342 /* Enqueue packet */
343 list_add_tail ( &iobuf->list, &netdev->tx_queue );
344
345 /* Guard against re-entry */
346 if ( netdev->state & NETDEV_TX_IN_PROGRESS ) {
347 rc = -EBUSY;
348 goto err_busy;
349 }
351
352 /* Avoid calling transmit() on unopened network devices */
353 if ( ! netdev_is_open ( netdev ) ) {
354 rc = -ENETUNREACH;
355 goto err_closed;
356 }
357
358 /* Discard packet (for test purposes) if applicable */
359 if ( ( rc = inject_fault ( NETDEV_DISCARD_RATE ) ) != 0 )
360 goto err_fault;
361
362 /* Map for DMA, if required */
363 if ( netdev->dma && ( ! dma_mapped ( &iobuf->map ) ) ) {
364 if ( ( rc = iob_map_tx ( iobuf, netdev->dma ) ) != 0 )
365 goto err_map;
366 }
367
368 /* Transmit packet */
369 if ( ( rc = netdev->op->transmit ( netdev, iobuf ) ) != 0 )
370 goto err_transmit;
371
372 /* Clear in-progress flag */
374
375 profile_stop ( &net_tx_profiler );
376 return 0;
377
378 err_transmit:
379 err_map:
380 err_fault:
381 err_closed:
383 err_busy:
384 netdev_tx_complete_err ( netdev, iobuf, rc );
385 return rc;
386}
#define NETDEV_DISCARD_RATE
Definition fault.h:16
#define DBGC2(...)
Definition compiler.h:522
#define ENETUNREACH
Network unreachable.
Definition errno.h:489
#define EBUSY
Device or resource busy.
Definition errno.h:339
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition profile.h:174
static void profile_start(struct profiler *profiler)
Start profiling.
Definition profile.h:161
static __always_inline int iob_map_tx(struct io_buffer *iobuf, struct dma_device *dma)
Map I/O buffer for transmit DMA.
Definition iobuf.h:244
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition iobuf.h:160
static __always_inline int dma_mapped(struct dma_mapping *map)
Check if DMA unmapping is required.
Definition dma.h:442
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition list.h:94
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
Definition netdevice.c:471
#define NETDEV_TX_IN_PROGRESS
Network device transmission is in progress.
Definition netdevice.h:456
static int netdev_is_open(struct net_device *netdev)
Check whether or not network device is open.
Definition netdevice.h:662
void * data
Start of data.
Definition iobuf.h:53
struct list_head list
List of which this buffer is a member.
Definition iobuf.h:45
struct dma_mapping map
DMA mapping.
Definition iobuf.h:48

References io_buffer::data, DBGC2, dma_mapped(), EBUSY, ENETUNREACH, iob_len(), iob_map_tx(), io_buffer::list, list_add_tail, io_buffer::map, netdev, NETDEV_DISCARD_RATE, netdev_is_open(), netdev_tx_complete_err(), NETDEV_TX_IN_PROGRESS, profile_start(), profile_stop(), and rc.

Referenced by efi_snp_transmit(), gdbudp_recv(), gdbudp_send(), net80211_handle_auth(), net80211_netdev_transmit(), net80211_tx_mgmt(), net_tx(), netdev_tx_complete_err(), and pxenv_undi_transmit().

◆ netdev_tx_defer()

void netdev_tx_defer ( struct net_device * netdev,
struct io_buffer * iobuf )
extern

Defer transmitted packet.

Parameters
netdevNetwork device
iobufI/O buffer

Drivers may call netdev_tx_defer() if there is insufficient space in the transmit descriptor ring. Any packets deferred in this way will be automatically retransmitted as soon as space becomes available (i.e. as soon as the driver calls netdev_tx_complete()).

The packet must currently be in the network device's TX queue.

Drivers utilising netdev_tx_defer() must ensure that space in the transmit descriptor ring is freed up before calling netdev_tx_complete(). For example, if the ring is modelled using a producer counter and a consumer counter, then the consumer counter must be incremented before the call to netdev_tx_complete(). Failure to do this will cause the retransmitted packet to be immediately redeferred (which will result in out-of-order transmissions and other nastiness).

I/O buffers that have been mapped for DMA will remain mapped while present in the deferred transmit queue.

Definition at line 413 of file netdevice.c.

413 {
414
415 /* Catch data corruption as early as possible */
416 list_check_contains_entry ( iobuf, &netdev->tx_queue, list );
417
418 /* Remove from transmit queue */
419 list_del ( &iobuf->list );
420
421 /* Add to deferred transmit queue */
422 list_add_tail ( &iobuf->list, &netdev->tx_deferred );
423
424 /* Record "out of space" statistic */
426}
#define ENOBUFS
No buffer space available.
Definition errno.h:499
#define list_del(list)
Delete an entry from a list.
Definition list.h:120
#define list_check_contains_entry(entry, head, member)
Check list contains a specified entry.
Definition list.h:550
void netdev_tx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard transmitted packet.
Definition netdevice.c:441

References ENOBUFS, io_buffer::list, list_add_tail, list_check_contains_entry, list_del, netdev, netdev_tx_err(), and NULL.

Referenced by gve_transmit(), mnpnet_transmit(), nii_transmit(), realtek_transmit(), rndis_tx_defer(), and snpnet_transmit().

◆ netdev_tx_err()

void netdev_tx_err ( struct net_device * netdev,
struct io_buffer * iobuf,
int rc )
extern

Discard transmitted packet.

Parameters
netdevNetwork device
iobufI/O buffer, or NULL
rcPacket status code

The packet is discarded and a TX error is recorded. This function takes ownership of the I/O buffer.

The I/O buffer will be automatically unmapped for DMA, if applicable.

Definition at line 441 of file netdevice.c.

442 {
443
444 /* Update statistics counter */
445 netdev_record_stat ( &netdev->tx_stats, rc );
446 if ( rc == 0 ) {
447 DBGC2 ( netdev, "NETDEV %s transmission %p complete\n",
448 netdev->name, iobuf );
449 } else {
450 DBGC ( netdev, "NETDEV %s transmission %p failed: %s\n",
451 netdev->name, iobuf, strerror ( rc ) );
452 }
453
454 /* Unmap I/O buffer, if required */
455 if ( iobuf && dma_mapped ( &iobuf->map ) )
456 iob_unmap ( iobuf );
457
458 /* Discard packet */
459 free_iob ( iobuf );
460}
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition iobuf.c:153
static __always_inline void iob_unmap(struct io_buffer *iobuf)
Unmap I/O buffer for DMA.
Definition iobuf.h:279
static void netdev_record_stat(struct net_device_stats *stats, int rc)
Record network device statistic.
Definition netdevice.c:292

References DBGC, DBGC2, dma_mapped(), free_iob(), iob_unmap(), io_buffer::map, netdev, netdev_record_stat(), rc, and strerror().

Referenced by eoib_duplicate(), intel_poll(), neighbour_destroy(), net_tx(), netdev_tx_complete_err(), netdev_tx_defer(), rdc_poll(), rhine_poll(), rndis_tx_complete_err(), snpnet_poll_tx(), vmxnet3_poll_events(), and vmxnet3_poll_tx().

◆ netdev_tx_complete_err()

void netdev_tx_complete_err ( struct net_device * netdev,
struct io_buffer * iobuf,
int rc )
extern

Complete network transmission.

Parameters
netdevNetwork device
iobufI/O buffer
rcPacket status code

The packet must currently be in the network device's TX queue.

Definition at line 471 of file netdevice.c.

472 {
473
474 /* Catch data corruption as early as possible */
475 list_check_contains_entry ( iobuf, &netdev->tx_queue, list );
476
477 /* Dequeue and free I/O buffer */
478 list_del ( &iobuf->list );
479 netdev_tx_err ( netdev, iobuf, rc );
480
481 /* Handle pending transmit queue */
482 while ( ( iobuf = list_first_entry ( &netdev->tx_deferred,
483 struct io_buffer, list ) ) ) {
484
485 /* Remove from pending transmit queue */
486 list_del ( &iobuf->list );
487
488 /* When any transmit completion fails, cancel all
489 * pending transmissions.
490 */
491 if ( rc != 0 ) {
492 netdev_tx_err ( netdev, iobuf, -ECANCELED );
493 continue;
494 }
495
496 /* Otherwise, attempt to transmit the first pending packet */
497 netdev_tx ( netdev, iobuf );
498 break;
499 }
500}
#define ECANCELED
Operation canceled.
Definition errno.h:344
#define list_first_entry(list, type, member)
Get the container of the first entry in a list.
Definition list.h:334
int netdev_tx(struct net_device *netdev, struct io_buffer *iobuf)
Transmit raw packet via network device.
Definition netdevice.c:335
A persistent I/O buffer.
Definition iobuf.h:38

References ECANCELED, io_buffer::list, list_check_contains_entry, list_del, list_first_entry, netdev, netdev_tx(), netdev_tx_err(), and rc.

Referenced by axge_out_complete(), dm96xx_out_complete(), ecm_out_complete(), ena_cancel_tx(), eoib_complete_send(), flexboot_nodnic_eth_complete_send(), gve_cancel_tx(), hermon_eth_complete_send(), ifec_tx_process(), iphone_out_complete(), ipoib_complete_send(), jme_free_tx_buffers(), jme_tx_clean(), mnpnet_close(), mnpnet_poll_tx(), ncm_out_complete(), net80211_tx_complete(), netdev_tx(), netdev_tx_complete(), netdev_tx_complete_next_err(), netfront_poll_tx(), nii_close(), phantom_close(), rndis_tx_complete_err(), sis190_process_tx(), smscusb_out_complete(), snpnet_close(), vmxnet3_flush_tx(), and vxge_xmit_compl().

◆ netdev_tx_complete_next_err()

void netdev_tx_complete_next_err ( struct net_device * netdev,
int rc )
extern

Complete network transmission.

Parameters
netdevNetwork device
rcPacket status code

Completes the oldest outstanding packet in the TX queue.

Definition at line 510 of file netdevice.c.

510 {
511 struct io_buffer *iobuf;
512
513 if ( ( iobuf = list_first_entry ( &netdev->tx_queue, struct io_buffer,
514 list ) ) != NULL ) {
515 netdev_tx_complete_err ( netdev, iobuf, rc );
516 }
517}

References io_buffer::list, list_first_entry, netdev, netdev_tx_complete_err(), NULL, and rc.

Referenced by dwmac_poll_tx(), myson_poll_tx(), natsemi_poll_tx(), netdev_tx_complete_next(), netdev_tx_flush(), rhine_poll_tx(), txnic_complete_sqe(), and velocity_poll_tx().

◆ netdev_rx()

void netdev_rx ( struct net_device * netdev,
struct io_buffer * iobuf )
extern

Add packet to receive queue.

Parameters
netdevNetwork device
iobufI/O buffer

The packet is added to the network device's RX queue. This function takes ownership of the I/O buffer.

The I/O buffer will be automatically unmapped for DMA, if applicable.

Definition at line 549 of file netdevice.c.

549 {
550 int rc;
551
552 DBGC2 ( netdev, "NETDEV %s received %p (%p+%zx)\n",
553 netdev->name, iobuf, iobuf->data, iob_len ( iobuf ) );
554
555 /* Discard packet (for test purposes) if applicable */
556 if ( ( rc = inject_fault ( NETDEV_DISCARD_RATE ) ) != 0 ) {
557 netdev_rx_err ( netdev, iobuf, rc );
558 return;
559 }
560
561 /* Unmap I/O buffer, if required */
562 if ( dma_mapped ( &iobuf->map ) )
563 iob_unmap ( iobuf );
564
565 /* Enqueue packet */
566 list_add_tail ( &iobuf->list, &netdev->rx_queue );
567
568 /* Update statistics counter */
569 netdev_record_stat ( &netdev->rx_stats, 0 );
570}
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition netdevice.c:587

References io_buffer::data, DBGC2, dma_mapped(), iob_len(), iob_unmap(), io_buffer::list, list_add_tail, io_buffer::map, netdev, NETDEV_DISCARD_RATE, netdev_record_stat(), netdev_rx_err(), and rc.

Referenced by a3c90x_process_rx_packets(), af_packet_nic_poll(), atl1e_clean_rx_irq(), atl_poll_rx(), axge_in_complete(), b44_process_rx_packets(), bnxt_rx_process(), cgem_poll_rx(), dm96xx_in_complete(), dwmac_poll_rx(), ecm_in_complete(), efab_receive(), efx_hunt_receive(), ena_poll_rx(), eoib_complete_recv(), exanic_poll_rx(), flexboot_nodnic_eth_complete_recv(), gve_poll_rx(), icplus_poll_rx(), ifec_rx_process(), igbvf_process_rx_packets(), intel_poll_rx(), iphone_in_complete(), ipoib_complete_recv(), jme_alloc_and_feed_iob(), legacy_poll(), mnpnet_poll_rx(), myri10ge_net_poll(), myson_poll_rx(), natsemi_poll_rx(), ncm_in_complete(), net80211_rx(), netfront_poll_rx(), nii_poll_rx(), nv_process_rx_packets(), pcnet32_process_rx_packets(), phantom_poll(), pnic_poll(), rdc_poll_rx(), realtek_legacy_poll_rx(), realtek_poll_rx(), rhine_poll_rx(), rndis_rx_data(), sis190_process_rx(), skge_rx_done(), sky2_status_intr(), slirp_send_packet(), smsc75xx_in_complete(), smsc95xx_in_complete(), snpnet_poll_rx(), tap_poll(), tg3_rx_complete(), txnic_complete_rqe(), undinet_poll(), velocity_poll_rx(), virtnet_process_rx_packets(), vlan_netdev_rx(), vlan_rx(), vmxnet3_poll_rx(), and vxge_hw_vpath_poll_rx().

◆ netdev_rx_err()

void netdev_rx_err ( struct net_device * netdev,
struct io_buffer * iobuf,
int rc )
extern

Discard received packet.

Parameters
netdevNetwork device
iobufI/O buffer, or NULL
rcPacket status code

The packet is discarded and an RX error is recorded. This function takes ownership of the I/O buffer. 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.

The I/O buffer will be automatically unmapped for DMA, if applicable.

Definition at line 587 of file netdevice.c.

588 {
589
590 DBGC ( netdev, "NETDEV %s failed to receive %p: %s\n",
591 netdev->name, iobuf, strerror ( rc ) );
592
593 /* Unmap I/O buffer, if required */
594 if ( iobuf && dma_mapped ( &iobuf->map ) )
595 iob_unmap ( iobuf );
596
597 /* Discard packet */
598 free_iob ( iobuf );
599
600 /* Update statistics counter */
601 netdev_record_stat ( &netdev->rx_stats, rc );
602}

References DBGC, dma_mapped(), free_iob(), iob_unmap(), io_buffer::map, netdev, netdev_record_stat(), rc, and strerror().

Referenced by a3c90x_process_rx_packets(), atl1e_clean_rx_irq(), axge_in_complete(), axge_intr_complete(), axge_poll(), b44_process_rx_packets(), bnxt_rx_process(), dm96xx_in_complete(), dm96xx_intr_complete(), dm96xx_poll(), dwmac_poll_rx(), ecm_in_complete(), ecm_intr_complete(), ecm_poll(), efx_hunt_receive(), eoib_complete_recv(), exanic_close(), exanic_poll_rx(), flexboot_nodnic_eth_complete_recv(), gve_poll_rx(), icplus_poll_rx(), ifec_rx_process(), igbvf_process_rx_packets(), intel_poll(), intel_poll_rx(), intelx_poll(), intelxvf_poll(), iphone_in_complete(), iphone_poll(), ipoib_complete_recv(), jme_process_receive(), mnpnet_poll_rx(), myson_poll_rx(), myson_refill_rx(), natsemi_poll_rx(), natsemi_refill_rx(), ncm_in_complete(), ncm_intr_complete(), ncm_poll(), net80211_rx(), net80211_rx_err(), net_poll(), netdev_rx(), netdev_rx_flush(), netfront_poll_rx(), netfront_refill_rx(), nii_poll_rx(), nv_process_rx_packets(), pcnet32_process_rx_packets(), phantom_refill_rx_ring(), pnic_poll(), rdc_poll_rx(), realtek_legacy_poll_rx(), realtek_poll_rx(), rhine_poll(), rhine_poll_rx(), rndis_rx(), rndis_rx_data(), rndis_rx_err(), rndis_rx_message(), rndis_rx_status(), skge_rx_done(), sky2_receive(), sky2_status_intr(), slirp_poll(), smsc75xx_in_complete(), smsc75xx_poll(), smsc95xx_in_complete(), smsc95xx_poll(), smscusb_intr_complete(), snpnet_poll_rx(), snpnet_poll_tx(), tg3_rx_complete(), txnic_complete_rqe(), undinet_poll(), velocity_poll_rx(), vlan_netdev_rx(), vlan_netdev_rx_err(), vlan_netdev_rx_err(), vmxnet3_flush_rx(), vmxnet3_poll_events(), vmxnet3_poll_rx(), and vxge_hw_vpath_poll_rx().

◆ netdev_poll()

void netdev_poll ( struct net_device * netdev)
extern

Poll for completed and received packets on network device.

Parameters
netdevNetwork device

Polls the network device for completed transmissions and received packets. Any received packets will be added to the RX packet queue via netdev_rx().

Definition at line 613 of file netdevice.c.

613 {
614
615 /* Call poll() only on open (or insomniac) network devices */
616 if ( ! ( netdev->state & ( NETDEV_OPEN | NETDEV_INSOMNIAC ) ) )
617 return;
618
619 /* Guard against re-entry */
620 if ( netdev->state & NETDEV_POLL_IN_PROGRESS )
621 return;
622
623 /* Poll device */
625 netdev->op->poll ( netdev );
627}
#define NETDEV_POLL_IN_PROGRESS
Network device poll is in progress.
Definition netdevice.h:459

References netdev, NETDEV_INSOMNIAC, NETDEV_OPEN, and NETDEV_POLL_IN_PROGRESS.

Referenced by efi_snp_poll(), gdbudp_recv(), iflinkwait(), net_poll(), and vlan_poll().

◆ netdev_rx_dequeue()

struct io_buffer * netdev_rx_dequeue ( struct net_device * netdev)
extern

Remove packet from device's receive queue.

Parameters
netdevNetwork device
Return values
iobufI/O buffer, or NULL

Removes the first packet from the device's RX queue and returns it. Ownership of the packet is transferred to the caller.

Definition at line 638 of file netdevice.c.

638 {
639 struct io_buffer *iobuf;
640
641 iobuf = list_first_entry ( &netdev->rx_queue, struct io_buffer, list );
642 if ( ! iobuf )
643 return NULL;
644
645 list_del ( &iobuf->list );
646 return iobuf;
647}

References io_buffer::list, list_del, list_first_entry, netdev, and NULL.

Referenced by efi_snp_poll(), gdbudp_recv(), net_poll(), netdev_rx_flush(), and pxenv_undi_isr().

◆ alloc_netdev()

struct net_device * alloc_netdev ( size_t priv_len)
extern

Allocate network device.

Parameters
priv_lenLength of private data area (net_device::priv)
Return values
netdevNetwork device, or NULL

Allocates space for a network device and its private data area.

Definition at line 722 of file netdevice.c.

722 {
723 struct net_device *netdev;
724 struct net_device_configurator *configurator;
725 struct net_device_configuration *config;
726
727 netdev = zalloc ( netdev_priv_offset ( NULL ) + priv_len );
728 if ( netdev ) {
729 ref_init ( &netdev->refcnt, free_netdev );
730 netdev->link_rc = -EUNKNOWN_LINK_STATUS;
731 timer_init ( &netdev->link_block, netdev_link_block_expired,
732 &netdev->refcnt );
733 INIT_LIST_HEAD ( &netdev->tx_queue );
734 INIT_LIST_HEAD ( &netdev->tx_deferred );
735 INIT_LIST_HEAD ( &netdev->rx_queue );
737 config = netdev->configs;
739 config->netdev = netdev;
740 config->configurator = configurator;
741 config->rc = -EUNUSED_CONFIG;
742 intf_init ( &config->job, &netdev_config_desc,
743 &netdev->refcnt );
744 config++;
745 }
746 netdev->priv = netdev_priv ( netdev, NULL );
747 }
748 return netdev;
749}
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition interface.h:204
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition list.h:46
void * zalloc(size_t size)
Allocate cleared memory.
Definition malloc.c:662
static void netdev_link_block_expired(struct retry_timer *timer, int fail __unused)
Handle network device link block timer expiry.
Definition netdevice.c:277
void * netdev_priv(struct net_device *netdev, struct net_driver *driver)
Get network device driver private data.
Definition netdevice.c:153
static void free_netdev(struct refcnt *refcnt)
Free network device.
Definition netdevice.c:703
static struct interface_descriptor netdev_config_desc
Network device configuration interface descriptor.
Definition netdevice.c:695
#define EUNUSED_CONFIG
Default not-yet-attempted-configuration status code.
Definition netdevice.c:74
static void netdev_settings_init(struct net_device *netdev)
Initialise a per-netdevice configuration settings block.
Definition netdevice.h:599
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition refcnt.h:65
A network device configuration.
Definition netdevice.h:302
int rc
Configuration status.
Definition netdevice.h:308
struct net_device_configurator * configurator
Network device configurator.
Definition netdevice.h:306
struct net_device * netdev
Network device.
Definition netdevice.h:304
struct interface job
Job control interface.
Definition netdevice.h:310
A network device configurator.
Definition netdevice.h:314
A network device.
Definition netdevice.h:353
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition tables.h:386

References net_device_configuration::configurator, EUNKNOWN_LINK_STATUS, EUNUSED_CONFIG, for_each_table_entry, free_netdev(), INIT_LIST_HEAD, intf_init(), net_device_configuration::job, NET_DEVICE_CONFIGURATORS, net_device_configuration::netdev, netdev, netdev_config_desc, netdev_link_block_expired(), netdev_priv(), netdev_priv_offset(), netdev_settings_init(), NULL, net_device_configuration::rc, ref_init, and zalloc().

Referenced by alloc_etherdev(), alloc_ipoibdev(), net80211_alloc(), and nii_start().

◆ register_netdev()

int register_netdev ( struct net_device * netdev)
extern

Register network device.

Parameters
netdevNetwork device
Return values
rcReturn status code

Gives the network device a name and adds it to the list of network devices.

Definition at line 760 of file netdevice.c.

760 {
761 struct ll_protocol *ll_protocol = netdev->ll_protocol;
762 struct net_driver *driver;
763 struct net_device *duplicate;
764 unsigned int i;
765 uint32_t seed;
766 void *priv;
767 int rc;
768
769 /* Set initial link-layer address, if not already set */
770 if ( ! netdev_has_ll_addr ( netdev ) ) {
771 ll_protocol->init_addr ( netdev->hw_addr, netdev->ll_addr );
772 }
773
774 /* Set MTU, if not already set */
775 if ( ! netdev->mtu ) {
776 netdev->mtu = ( netdev->max_pkt_len -
778 }
779
780 /* Reject named network devices that already exist */
781 if ( netdev->name[0] && ( duplicate = find_netdev ( netdev->name ) ) ) {
782 DBGC ( netdev, "NETDEV rejecting duplicate name %s\n",
783 duplicate->name );
784 rc = -EEXIST;
785 goto err_duplicate;
786 }
787
788 /* Assign a unique device name, if not already set */
789 if ( netdev->name[0] == '\0' ) {
790 for ( i = 0 ; ; i++ ) {
791 snprintf ( netdev->name, sizeof ( netdev->name ),
792 "net%d", i );
793 if ( find_netdev ( netdev->name ) == NULL )
794 break;
795 }
796 }
797
798 /* Assign a unique non-zero scope ID */
799 for ( netdev->scope_id = 1 ; ; netdev->scope_id++ ) {
800 if ( find_netdev_by_scope_id ( netdev->scope_id ) == NULL )
801 break;
802 }
803
804 /* Use least significant bits of the link-layer address to
805 * improve the randomness of the (non-cryptographic) random
806 * number generator.
807 */
808 memcpy ( &seed, ( netdev->ll_addr + ll_protocol->ll_addr_len
809 - sizeof ( seed ) ), sizeof ( seed ) );
810 srand ( rand() ^ seed );
811
812 /* Add to device list */
813 netdev_get ( netdev );
814 list_add_tail ( &netdev->list, &net_devices );
815 DBGC ( netdev, "NETDEV %s registered (phys %s hwaddr %s)\n",
816 netdev->name, netdev->dev->name,
817 netdev_addr ( netdev ) );
818
819 /* Register per-netdev configuration settings */
821 NULL, netdev->name ) ) != 0 ) {
822 DBGC ( netdev, "NETDEV %s could not register settings: %s\n",
823 netdev->name, strerror ( rc ) );
824 goto err_register_settings;
825 }
826
827 /* Probe device */
829 priv = netdev_priv ( netdev, driver );
830 if ( driver->probe &&
831 ( rc = driver->probe ( netdev, priv ) ) != 0 ) {
832 DBGC ( netdev, "NETDEV %s could not add %s device: "
833 "%s\n", netdev->name, driver->name,
834 strerror ( rc ) );
835 goto err_probe;
836 }
837 }
838
839 return 0;
840
841 err_probe:
843 priv = netdev_priv ( netdev, driver );
844 if ( driver->remove )
845 driver->remove ( netdev, priv );
846 }
849 err_register_settings:
850 list_del ( &netdev->list );
851 netdev_put ( netdev );
852 err_duplicate:
853 return rc;
854}
unsigned int uint32_t
Definition stdint.h:12
#define EEXIST
File exists.
Definition errno.h:389
void * memcpy(void *dest, const void *src, size_t len) __nonnull
struct net_device * find_netdev_by_scope_id(unsigned int scope_id)
Get network device by scope ID.
Definition netdevice.c:1011
static int netdev_has_ll_addr(struct net_device *netdev)
Check whether or not network device has a link-layer address.
Definition netdevice.c:102
struct net_device * find_netdev(const char *name)
Get network device by name.
Definition netdevice.c:989
static struct net_device * netdev_get(struct net_device *netdev)
Get reference to network device.
Definition netdevice.h:565
#define NET_DRIVERS
Network driver table.
Definition netdevice.h:504
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition netdevice.h:576
static const char * netdev_addr(struct net_device *netdev)
Get printable network device link-layer address.
Definition netdevice.h:542
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition netdevice.h:587
int register_settings(struct settings *settings, struct settings *parent, const char *name)
Register settings block.
Definition settings.c:476
void clear_settings(struct settings *settings)
Clear settings block.
Definition settings.c:1103
void unregister_settings(struct settings *settings)
Unregister settings block.
Definition settings.c:515
static void srand(unsigned int seed)
Definition stdlib.h:64
static int rand(void)
Definition stdlib.h:60
A link-layer protocol.
Definition netdevice.h:115
void(* init_addr)(const void *hw_addr, void *ll_addr)
Initialise link-layer address.
Definition netdevice.h:151
uint8_t ll_addr_len
Link-layer address length.
Definition netdevice.h:199
uint8_t ll_header_len
Link-layer header length.
Definition netdevice.h:201
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition netdevice.h:363
A network upper-layer driver.
Definition netdevice.h:477
int(* probe)(struct net_device *netdev, void *priv)
Probe device.
Definition netdevice.h:488
void(* remove)(struct net_device *netdev, void *priv)
Remove device.
Definition netdevice.h:500
const char * name
Name.
Definition netdevice.h:479
#define for_each_table_entry_continue_reverse(pointer, table)
Iterate through all remaining entries within a linker table in reverse order.
Definition tables.h:470
static struct tlan_private * priv
Definition tlan.c:225
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition vsprintf.c:383

References clear_settings(), DBGC, EEXIST, find_netdev(), find_netdev_by_scope_id(), for_each_table_entry, for_each_table_entry_continue_reverse, ll_protocol::init_addr, list_add_tail, list_del, ll_protocol::ll_addr_len, ll_protocol::ll_header_len, memcpy(), net_device::name, net_driver::name, net_devices, NET_DRIVERS, netdev, netdev_addr(), netdev_get(), netdev_has_ll_addr(), netdev_priv(), netdev_put(), netdev_settings(), NULL, priv, net_driver::probe, rand(), rc, register_settings(), net_driver::remove, snprintf(), srand(), strerror(), and unregister_settings().

Referenced by a3c90x_probe(), af_packet_nic_probe(), atl1e_probe(), atl_probe(), axge_probe(), b44_probe(), bnxt_init_one(), cgem_probe(), dm96xx_probe(), dwmac_probe(), ecm_probe(), efab_probe(), ena_probe(), eoib_create(), exanic_probe_port(), flexboot_nodnic_register_netdev(), forcedeth_probe(), gve_probe(), hermon_register_netdev(), hunt_probe(), ice_probe(), icplus_probe(), ifec_pci_probe(), igbvf_probe(), intel_probe(), intelx_probe(), intelxl_probe(), intelxlvf_probe(), intelxvf_probe(), iphone_probe(), ipoib_probe(), jme_probe(), lan78xx_probe(), legacy_probe(), mnpnet_start(), myri10ge_pci_probe(), myson_probe(), natsemi_probe(), ncm_probe(), net80211_register(), netfront_probe(), nii_start(), pcnet32_probe(), phantom_probe(), pnic_probe(), rdc_probe(), realtek_probe(), register_rndis(), rhine_probe(), sis190_probe(), skeleton_probe(), skge_probe(), sky2_probe(), slirp_probe(), smsc75xx_probe(), smsc95xx_probe(), snpnet_start(), tap_probe(), testnet_okx(), tg3_init_one(), txnic_lmac_probe(), undinet_probe(), velocity_probe(), virtnet_probe_legacy(), virtnet_probe_modern(), vlan_create(), vmxnet3_probe(), and vxge_device_register().

◆ netdev_open()

int netdev_open ( struct net_device * netdev)
extern

Open network device.

Parameters
netdevNetwork device
Return values
rcReturn status code

Definition at line 862 of file netdevice.c.

862 {
863 int rc;
864
865 /* Do nothing if device is already open */
866 if ( netdev->state & NETDEV_OPEN )
867 return 0;
868
869 DBGC ( netdev, "NETDEV %s opening\n", netdev->name );
870
871 /* Mark as opened */
872 netdev->state |= NETDEV_OPEN;
873
874 /* Open the device */
875 if ( ( rc = netdev->op->open ( netdev ) ) != 0 )
876 goto err;
877
878 /* Add to head of open devices list */
879 list_add ( &netdev->open_list, &open_net_devices );
880
881 /* Notify drivers of device state change */
883
884 return 0;
885
886 err:
887 netdev->state &= ~NETDEV_OPEN;
888 return rc;
889}
#define list_add(new, head)
Add a new entry to the head of a list.
Definition list.h:70
static struct list_head open_net_devices
List of open network devices, in reverse order of opening.
Definition netdevice.c:57

References DBGC, list_add, netdev, netdev_notify(), NETDEV_OPEN, open_net_devices, and rc.

Referenced by apply_netdev_settings(), efi_autoexec_network(), efi_snp_initialize(), efi_snp_reset(), gdbudp_ensure_netdev_open(), ifopen(), iwlist(), netvsc_reset(), pxe_exec(), pxe_netdev_open(), pxenv_udp_open(), testnet_open_okx(), vlan_open(), vlan_sync(), and xve_open().

◆ netdev_close()

void netdev_close ( struct net_device * netdev)
extern

Close network device.

Parameters
netdevNetwork device

Definition at line 896 of file netdevice.c.

896 {
897 unsigned int num_configs;
898 unsigned int i;
899
900 /* Do nothing if device is already closed */
901 if ( ! ( netdev->state & NETDEV_OPEN ) )
902 return;
903
904 DBGC ( netdev, "NETDEV %s closing\n", netdev->name );
905
906 /* Terminate any ongoing configurations. Use intf_close()
907 * rather than intf_restart() to allow the cancellation to be
908 * reported back to us if a configuration is actually in
909 * progress.
910 */
912 for ( i = 0 ; i < num_configs ; i++ )
913 intf_close ( &netdev->configs[i].job, -ECANCELED );
914
915 /* Remove from open devices list */
916 list_del ( &netdev->open_list );
917
918 /* Mark as closed */
919 netdev->state &= ~NETDEV_OPEN;
920
921 /* Notify drivers of device state change */
923
924 /* Close the device */
925 netdev->op->close ( netdev );
926
927 /* Stop link block timer */
928 stop_timer ( &netdev->link_block );
929
930 /* Flush TX and RX queues */
933}
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition interface.c:250
static void netdev_tx_flush(struct net_device *netdev)
Flush device's transmit queue.
Definition netdevice.c:524
static void netdev_rx_flush(struct net_device *netdev)
Flush device's receive queue.
Definition netdevice.c:654
#define table_num_entries(table)
Get number of entries in linker table.
Definition tables.h:336

References DBGC, ECANCELED, intf_close(), list_del, NET_DEVICE_CONFIGURATORS, netdev, netdev_notify(), NETDEV_OPEN, netdev_rx_flush(), netdev_tx_flush(), stop_timer(), and table_num_entries.

Referenced by apply_netdev_settings(), efi_snp_reset(), efi_snp_shutdown(), ifclose(), ifconf_payload(), iflinkwait_payload(), iwlist(), netvsc_reset(), pxe_netdev_close(), testnet_close_okx(), unregister_netdev(), vlan_close(), vlan_sync(), and xve_close().

◆ unregister_netdev()

void unregister_netdev ( struct net_device * netdev)
extern

Unregister network device.

Parameters
netdevNetwork device

Removes the network device from the list of network devices.

Definition at line 942 of file netdevice.c.

942 {
943 struct net_driver *driver;
944 void *priv;
945
946 /* Ensure device is closed */
948
949 /* Remove device */
951 priv = netdev_priv ( netdev, driver );
952 if ( driver->remove )
953 driver->remove ( netdev, priv );
954 }
955
956 /* Unregister per-netdev configuration settings */
959
960 /* Remove from device list */
961 DBGC ( netdev, "NETDEV %s unregistered\n", netdev->name );
962 list_del ( &netdev->list );
963 netdev_put ( netdev );
964}
void netdev_close(struct net_device *netdev)
Close network device.
Definition netdevice.c:896
#define for_each_table_entry_reverse(pointer, table)
Iterate through all entries within a linker table in reverse order.
Definition tables.h:441

References clear_settings(), DBGC, for_each_table_entry_reverse, list_del, NET_DRIVERS, netdev, netdev_close(), netdev_priv(), netdev_put(), netdev_settings(), priv, net_driver::remove, and unregister_settings().

Referenced by a3c90x_remove(), af_packet_nic_probe(), af_packet_nic_remove(), atl1e_remove(), atl_remove(), axge_probe(), axge_remove(), b44_remove(), bnxt_init_one(), bnxt_remove_one(), cgem_probe(), cgem_remove(), dm96xx_probe(), dm96xx_remove(), dwmac_probe(), dwmac_remove(), ecm_probe(), ecm_remove(), efab_probe(), efab_remove(), ena_probe(), ena_remove(), eoib_create(), eoib_destroy(), exanic_probe_port(), exanic_remove_port(), flexboot_nodnic_unregister_netdev(), forcedeth_remove(), gve_probe(), gve_remove(), hermon_register_netdev(), hermon_unregister_netdev(), hunt_remove(), ice_probe(), ice_remove(), icplus_probe(), icplus_remove(), ifec_pci_remove(), igbvf_remove(), intel_probe(), intel_remove(), intelx_probe(), intelx_remove(), intelxl_probe(), intelxl_remove(), intelxlvf_probe(), intelxlvf_remove(), intelxvf_probe(), intelxvf_remove(), iphone_probe(), iphone_remove(), ipoib_probe(), ipoib_remove(), jme_remove(), lan78xx_probe(), lan78xx_remove(), legacy_remove(), mnpnet_start(), mnpnet_stop(), myri10ge_pci_probe(), myri10ge_pci_remove(), myson_probe(), myson_remove(), natsemi_probe(), natsemi_remove(), ncm_probe(), ncm_remove(), net80211_unregister(), netfront_probe(), netfront_remove(), nii_start(), nii_stop(), pcnet32_remove(), phantom_probe(), phantom_remove(), pnic_remove(), rdc_probe(), rdc_remove(), realtek_probe(), realtek_remove(), register_rndis(), rhine_remove(), sis190_remove(), skeleton_probe(), skeleton_remove(), skge_remove(), sky2_remove(), slirp_probe(), slirp_remove(), smsc75xx_probe(), smsc75xx_remove(), smsc95xx_probe(), smsc95xx_remove(), snpnet_start(), snpnet_stop(), tap_probe(), tap_remove(), testnet_remove_okx(), tg3_remove_one(), txnic_lmac_probe(), txnic_lmac_remove(), undinet_remove(), unregister_rndis(), velocity_remove(), virtnet_probe_legacy(), virtnet_probe_modern(), virtnet_remove(), vlan_create(), vlan_destroy(), vmxnet3_probe(), vmxnet3_remove(), and vxge_device_unregister().

◆ netdev_irq()

void netdev_irq ( struct net_device * netdev,
int enable )
extern

Enable or disable interrupts.

Parameters
netdevNetwork device
enableInterrupts should be enabled

Definition at line 971 of file netdevice.c.

971 {
972
973 /* Enable or disable device interrupts, if applicable */
975 netdev->op->irq ( netdev, enable );
976
977 /* Record interrupt enabled state */
978 netdev->state &= ~NETDEV_IRQ_ENABLED;
979 if ( enable )
980 netdev->state |= NETDEV_IRQ_ENABLED;
981}
static int netdev_irq_supported(struct net_device *netdev)
Check whether or not network device supports interrupts.
Definition netdevice.h:673

References netdev, NETDEV_IRQ_ENABLED, and netdev_irq_supported().

Referenced by pxe_netdev_close(), pxe_netdev_open(), pxenv_undi_isr(), pxenv_undi_transmit(), virtnet_open_legacy(), virtnet_open_modern(), and vlan_irq().

◆ find_netdev()

struct net_device * find_netdev ( const char * name)
extern

Get network device by name.

Parameters
nameNetwork device name
Return values
netdevNetwork device, or NULL

Definition at line 989 of file netdevice.c.

989 {
990 struct net_device *netdev;
991
992 /* Allow "netX" shortcut */
993 if ( strcmp ( name, "netX" ) == 0 )
994 return last_opened_netdev();
995
996 /* Identify network device by name */
998 if ( strcmp ( netdev->name, name ) == 0 )
999 return netdev;
1000 }
1001
1002 return NULL;
1003}
const char * name
Definition ath9k_hw.c:1986
struct net_device * last_opened_netdev(void)
Get most recently opened network device.
Definition netdevice.c:1048
int strcmp(const char *first, const char *second)
Compare strings.
Definition string.c:174
struct list_head list
List of network devices.
Definition netdevice.h:357

References last_opened_netdev(), net_device::list, list_for_each_entry, name, net_devices, netdev, NULL, and strcmp().

Referenced by gdbudp_configure(), ipv6_sock_aton(), netdev_redirect(), parse_netdev(), and register_netdev().

◆ find_netdev_by_scope_id()

struct net_device * find_netdev_by_scope_id ( unsigned int scope_id)
extern

Get network device by scope ID.

Parameters
indexNetwork device index
Return values
netdevNetwork device, or NULL

Definition at line 1011 of file netdevice.c.

1011 {
1012 struct net_device *netdev;
1013
1014 /* Identify network device by index */
1016 if ( netdev->scope_id == scope_id )
1017 return netdev;
1018 }
1019
1020 return NULL;
1021}
unsigned int scope_id
Scope ID.
Definition netdevice.h:361

References net_device::list, list_for_each_entry, net_devices, netdev, NULL, and net_device::scope_id.

Referenced by ipv6_sock_ntoa(), and register_netdev().

◆ find_netdev_by_location()

struct net_device * find_netdev_by_location ( unsigned int bus_type,
unsigned int location )
extern

Get network device by PCI bus:dev.fn address.

Parameters
bus_typeBus type
locationBus location
Return values
netdevNetwork device, or NULL

Definition at line 1030 of file netdevice.c.

1031 {
1032 struct net_device *netdev;
1033
1035 if ( ( netdev->dev->desc.bus_type == bus_type ) &&
1036 ( netdev->dev->desc.location == location ) )
1037 return netdev;
1038 }
1039
1040 return NULL;
1041}

References net_device::list, list_for_each_entry, net_devices, netdev, and NULL.

Referenced by pxenv_start_undi().

◆ last_opened_netdev()

struct net_device * last_opened_netdev ( void )
extern

Get most recently opened network device.

Return values
netdevMost recently opened network device, or NULL

Definition at line 1048 of file netdevice.c.

1048 {
1049 struct net_device *netdev;
1050
1052 open_list );
1053 if ( ! netdev )
1054 return NULL;
1055
1057 return netdev;
1058}
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
struct list_head open_list
List of open network devices.
Definition netdevice.h:359

References assert, list_first_entry, netdev, netdev_is_open(), NULL, net_device::open_list, and open_net_devices.

Referenced by aoe_open(), find_netdev(), ipv6_sock_aton(), last_opened_snpdev(), nbi_prepare_dhcp(), and pxe_exec().

◆ net_tx()

int net_tx ( struct io_buffer * iobuf,
struct net_device * netdev,
struct net_protocol * net_protocol,
const void * ll_dest,
const void * ll_source )
extern

Transmit network-layer packet.

Parameters
iobufI/O buffer
netdevNetwork device
net_protocolNetwork-layer protocol
ll_destDestination link-layer address
ll_sourceSource link-layer address
Return values
rcReturn status code

Prepends link-layer headers to the I/O buffer and transmits the packet via the specified network device. This function takes ownership of the I/O buffer.

Definition at line 1074 of file netdevice.c.

1076 {
1077 struct ll_protocol *ll_protocol = netdev->ll_protocol;
1078 int rc;
1079
1080 /* Add link-layer header */
1081 if ( ( rc = ll_protocol->push ( netdev, iobuf, ll_dest, ll_source,
1082 net_protocol->net_proto ) ) != 0 ) {
1083 /* Record error for diagnosis */
1084 netdev_tx_err ( netdev, iobuf, rc );
1085 return rc;
1086 }
1087
1088 /* Transmit packet */
1089 return netdev_tx ( netdev, iobuf );
1090}
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 network-layer protocol.
Definition netdevice.h:65
uint16_t net_proto
Network-layer protocol.
Definition netdevice.h:100

References net_protocol::net_proto, netdev, netdev_tx(), netdev_tx_err(), ll_protocol::push, and rc.

Referenced by aoecmd_tx(), arp_rx(), arp_tx_request(), eapol_tx(), eth_slow_lacp_rx(), eth_slow_marker_rx(), fcoe_deliver(), fcoe_fip_tx_keepalive(), fcoe_fip_tx_solicitation(), fcoe_fip_tx_vlan(), ipv4_tx(), ipv6_tx(), loopback_test(), neighbour_tx(), neighbour_tx_queue(), vlan_transmit(), and wpa_send_eapol().

◆ net_rx()

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 )
extern

Process received network-layer packet.

Parameters
iobufI/O buffer
netdevNetwork device
net_protoNetwork-layer protocol, in network-byte order
ll_destDestination link-layer address
ll_sourceSource link-layer address
flagsPacket flags
Return values
rcReturn status code

Definition at line 1103 of file netdevice.c.

1105 {
1106 struct net_protocol *net_protocol;
1107
1108 /* Hand off to network-layer protocol, if any */
1111 return net_protocol->rx ( iobuf, netdev, ll_dest,
1112 ll_source, flags );
1113 }
1114
1115 DBGC ( netdev, "NETDEV %s unknown network protocol %04x\n",
1116 netdev->name, ntohs ( net_proto ) );
1117 free_iob ( iobuf );
1118 return -ENOTSUP;
1119}
uint8_t flags
Flags.
Definition ena.h:7
#define ENOTSUP
Operation not supported.
Definition errno.h:590
#define ntohs(value)
Definition byteswap.h:137
#define NET_PROTOCOLS
Network-layer protocol table.
Definition netdevice.h:471
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

References DBGC, ENOTSUP, flags, for_each_table_entry, free_iob(), net_protocol::net_proto, NET_PROTOCOLS, netdev, ntohs, and net_protocol::rx.

Referenced by net_poll().

◆ net_poll()

void net_poll ( void )
extern

Poll the network stack.

This polls all interfaces for received packets, and processes packets from the RX queue.

Definition at line 1127 of file netdevice.c.

1127 {
1128 struct net_device *netdev;
1129 struct io_buffer *iobuf;
1130 struct ll_protocol *ll_protocol;
1131 const void *ll_dest;
1132 const void *ll_source;
1133 uint16_t net_proto;
1134 unsigned int flags;
1135 int rc;
1136
1137 /* Poll and process each network device */
1139
1140 /* Poll for new packets */
1141 profile_start ( &net_poll_profiler );
1142 netdev_poll ( netdev );
1143 profile_stop ( &net_poll_profiler );
1144
1145 /* Leave received packets on the queue if receive
1146 * queue processing is currently frozen. This will
1147 * happen when the raw packets are to be manually
1148 * dequeued using netdev_rx_dequeue(), rather than
1149 * processed via the usual networking stack.
1150 */
1151 if ( netdev_rx_frozen ( netdev ) )
1152 continue;
1153
1154 /* Process all received packets */
1155 while ( ( iobuf = netdev_rx_dequeue ( netdev ) ) ) {
1156
1157 DBGC2 ( netdev, "NETDEV %s processing %p (%p+%zx)\n",
1158 netdev->name, iobuf, iobuf->data,
1159 iob_len ( iobuf ) );
1160 profile_start ( &net_rx_profiler );
1161
1162 /* Remove link-layer header */
1163 ll_protocol = netdev->ll_protocol;
1164 if ( ( rc = ll_protocol->pull ( netdev, iobuf,
1165 &ll_dest, &ll_source,
1166 &net_proto,
1167 &flags ) ) != 0 ) {
1168 free_iob ( iobuf );
1169 continue;
1170 }
1171
1172 /* Hand packet to network layer */
1173 if ( ( rc = net_rx ( iob_disown ( iobuf ), netdev,
1174 net_proto, ll_dest,
1175 ll_source, flags ) ) != 0 ) {
1176 /* Record error for diagnosis */
1178 }
1179 profile_stop ( &net_rx_profiler );
1180 }
1181 }
1182}
unsigned short uint16_t
Definition stdint.h:11
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition iobuf.h:217
struct io_buffer * netdev_rx_dequeue(struct net_device *netdev)
Remove packet from device's receive queue.
Definition netdevice.c:638
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
void netdev_poll(struct net_device *netdev)
Poll for completed and received packets on network device.
Definition netdevice.c:613
static int netdev_rx_frozen(struct net_device *netdev)
Check whether or not network device receive queue processing is frozen.
Definition netdevice.h:696
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

References io_buffer::data, DBGC2, flags, free_iob(), iob_disown, iob_len(), list_for_each_entry, net_devices, net_rx(), netdev, netdev_poll(), netdev_rx_dequeue(), netdev_rx_err(), netdev_rx_frozen(), NULL, profile_start(), profile_stop(), ll_protocol::pull, and rc.

Referenced by loopback_wait(), net_step(), and pxenv_undi_isr().

◆ find_netdev_configurator()

struct net_device_configurator * find_netdev_configurator ( const char * name)
extern

Find network device configurator.

Parameters
nameName
Return values
configuratorNetwork device configurator, or NULL

Definition at line 1279 of file netdevice.c.

1279 {
1280 struct net_device_configurator *configurator;
1281
1283 if ( strcmp ( configurator->name, name ) == 0 )
1284 return configurator;
1285 }
1286 return NULL;
1287}
const char * name
Name.
Definition netdevice.h:316

References for_each_table_entry, name, net_device_configurator::name, NET_DEVICE_CONFIGURATORS, NULL, and strcmp().

Referenced by parse_netdev_configurator().

◆ netdev_configure()

int netdev_configure ( struct net_device * netdev,
struct net_device_configurator * configurator )
extern

Start network device configuration.

Parameters
netdevNetwork device
configuratorNetwork device configurator
Return values
rcReturn status code

Definition at line 1296 of file netdevice.c.

1297 {
1298 struct net_device_configuration *config =
1300 int rc;
1301
1302 /* Check applicability of configurator */
1304 DBGC ( netdev, "NETDEV %s does not support configuration via "
1305 "%s\n", netdev->name, configurator->name );
1306 return -ENOTSUP;
1307 }
1308
1309 /* Terminate any ongoing configuration */
1310 intf_restart ( &config->job, -ECANCELED );
1311
1312 /* Mark configuration as being in progress */
1313 config->rc = -EINPROGRESS_CONFIG;
1314
1315 DBGC ( netdev, "NETDEV %s starting configuration via %s\n",
1316 netdev->name, configurator->name );
1317
1318 /* Start configuration */
1319 if ( ( rc = configurator->start ( &config->job, netdev ) ) != 0 ) {
1320 DBGC ( netdev, "NETDEV %s could not start configuration via "
1321 "%s: %s\n", netdev->name, configurator->name,
1322 strerror ( rc ) );
1323 config->rc = rc;
1324 return rc;
1325 }
1326
1327 return 0;
1328}
void intf_restart(struct interface *intf, int rc)
Shut down and restart an object interface.
Definition interface.c:344
#define EINPROGRESS_CONFIG
Default configuration-in-progress status code.
Definition netdevice.c:79
static struct net_device_configuration * netdev_configuration(struct net_device *netdev, struct net_device_configurator *configurator)
Get network device configuration.
Definition netdevice.h:612
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
int(* start)(struct interface *job, struct net_device *netdev)
Start configuring network device.
Definition netdevice.h:329

References net_device_configuration::configurator, DBGC, ECANCELED, EINPROGRESS_CONFIG, ENOTSUP, intf_restart(), net_device_configuration::job, net_device_configurator::name, netdev, netdev_configuration(), netdev_configurator_applies(), net_device_configuration::rc, rc, net_device_configurator::start, and strerror().

Referenced by ifconf(), and netdev_configure_all().

◆ netdev_configure_all()

int netdev_configure_all ( struct net_device * netdev)
extern

Start network device configuration via all supported configurators.

Parameters
netdevNetwork device
Return values
rcReturn status code

Definition at line 1336 of file netdevice.c.

1336 {
1337 struct net_device_configurator *configurator;
1338 int rc;
1339
1340 /* Start configuration for each configurator */
1342
1343 /* Skip any inapplicable configurators */
1344 if ( ! netdev_configurator_applies ( netdev, configurator ) )
1345 continue;
1346
1347 /* Start configuration */
1348 if ( ( rc = netdev_configure ( netdev, configurator ) ) != 0 )
1349 return rc;
1350 }
1351
1352 return 0;
1353}
int netdev_configure(struct net_device *netdev, struct net_device_configurator *configurator)
Start network device configuration.
Definition netdevice.c:1296

References for_each_table_entry, NET_DEVICE_CONFIGURATORS, netdev, netdev_configurator_applies(), netdev_configure(), and rc.

Referenced by efi_pxe_dhcp(), and ifconf().

◆ netdev_configuration_in_progress()

int netdev_configuration_in_progress ( struct net_device * netdev)
extern

Check if network device configuration is in progress.

Parameters
netdevNetwork device
Return values
is_in_progressNetwork device configuration is in progress

Definition at line 1380 of file netdevice.c.

1380 {
1381
1383}
static int netdev_has_configuration_rc(struct net_device *netdev, int rc)
Check if network device has a configuration with a specified status code.
Definition netdevice.c:1362

References EINPROGRESS_CONFIG, netdev, and netdev_has_configuration_rc().

Referenced by efi_pxe_dhcp(), and ifconf_progress().

◆ netdev_configuration_ok()

int netdev_configuration_ok ( struct net_device * netdev)
extern

Check if network device has at least one successful configuration.

Parameters
netdevNetwork device
configuratorConfigurator
Return values
rcReturn status code

Definition at line 1392 of file netdevice.c.

1392 {
1393
1394 return netdev_has_configuration_rc ( netdev, 0 );
1395}

References netdev, and netdev_has_configuration_rc().

Referenced by efi_pxe_dhcp(), and ifconf_progress().

◆ netdev_tx_complete()

◆ netdev_tx_complete_next()

void netdev_tx_complete_next ( struct net_device * netdev)
inlinestatic

Complete network transmission.

Parameters
netdevNetwork device

Completes the oldest outstanding packet in the TX queue.

Definition at line 779 of file netdevice.h.

779 {
781}
void netdev_tx_complete_next_err(struct net_device *netdev, int rc)
Complete network transmission.
Definition netdevice.c:510

References netdev, and netdev_tx_complete_next_err().

Referenced by atl_poll_tx(), cgem_poll_tx(), dwmac_poll_tx(), exanic_poll_tx(), icplus_poll_tx(), intel_poll_tx(), intelxl_poll_tx(), myson_poll_tx(), natsemi_poll_tx(), rdc_poll_tx(), realtek_poll_tx(), rhine_poll_tx(), txnic_complete_sqe(), and velocity_poll_tx().

◆ netdev_link_up()

void netdev_link_up ( struct net_device * netdev)
inlinestatic

Mark network device as having link up.

Parameters
netdevNetwork device

Definition at line 789 of file netdevice.h.

789 {
790 netdev_link_err ( netdev, 0 );
791}
void netdev_link_err(struct net_device *netdev, int rc)
Mark network device as having a specific link state.
Definition netdevice.c:208

References netdev, and netdev_link_err().

Referenced by __vxge_hw_vpath_alarm_process(), a3c90x_probe(), af_packet_nic_probe(), atl1e_check_link(), atl_check_link(), axge_check_link(), b44_probe(), bnxt_set_link(), dm96xx_link_nsr(), dwmac_check_link(), ecm_intr_complete(), efab_init_mac(), efab_probe(), ena_probe(), exanic_check_link(), flexboot_nodnic_state_change_netdev(), forcedeth_link_status(), gve_startup(), hermon_state_change_netdev(), hunt_check_link(), ice_admin_link(), icplus_check_link(), ifec_pci_probe(), igbvf_probe(), intel_check_link(), intelx_check_link(), intelxl_admin_link(), intelxlvf_admin_link(), intelxvf_check_link(), jme_check_link(), legacy_probe(), mii_check_link(), mnpnet_start(), myri10ge_interrupt_handler(), myson_probe(), natsemi_check_link(), ncm_intr_complete(), net80211_step_associate(), netfront_open(), nii_poll_link(), nii_start(), pcnet32_probe(), phantom_poll_link_state(), pnic_probe(), realtek_check_link(), rhine_check_link(), rndis_rx_query_oid(), rndis_rx_status(), sis190_phy_task(), skge_link_up(), sky2_link_up(), slirp_probe(), snpnet_check_link(), snpnet_start(), tap_probe(), tg3_setup_copper_phy(), tg3_test_and_report_link_chg(), txnic_lmac_update_link(), undinet_probe(), velocity_check_link(), virtnet_probe_legacy(), virtnet_probe_modern(), vmxnet3_check_link(), and vxge_open().

Variable Documentation

◆ net_devices

struct list_head net_devices
extern

List of network devices.

Definition at line 54 of file netdevice.c.

Referenced by find_netdev(), find_netdev_by_location(), find_netdev_by_scope_id(), have_netdevs(), net_poll(), and register_netdev().

◆ null_netdev_operations

struct net_device_operations null_netdev_operations
extern

Definition at line 60 of file nullnet.c.

60 {
61 .open = null_open,
62 .close = null_close,
63 .transmit = null_transmit,
64 .poll = null_poll,
65 .irq = null_irq,
66};
static int null_open(struct net_device *netdev __unused)
Definition nullnet.c:38
static int null_transmit(struct net_device *netdev __unused, struct io_buffer *iobuf __unused)
Definition nullnet.c:46
static void null_poll(struct net_device *netdev __unused)
Definition nullnet.c:51
static void null_close(struct net_device *netdev __unused)
Definition nullnet.c:42
static void null_irq(struct net_device *netdev __unused, int enable __unused)
Definition nullnet.c:55

Referenced by netdev_nullify().

◆ netdev_settings_operations

struct settings_operations netdev_settings_operations
extern

Network device configuration settings operations.

Definition at line 382 of file netdev_settings.c.

382 {
383 .store = netdev_store,
384 .fetch = netdev_fetch,
385 .clear = netdev_clear,
386};
static int netdev_store(struct settings *settings, const struct setting *setting, const void *data, size_t len)
Store value of network device setting.
static int netdev_fetch(struct settings *settings, struct setting *setting, void *data, size_t len)
Fetch value of network device setting.
static void netdev_clear(struct settings *settings)
Clear network device settings.

Referenced by netdev_settings_init().