iPXE
Data Structures | Macros | Functions | Variables
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. More...
 
#define MAX_LL_ADDR_LEN   20
 Maximum length of a link-layer address. More...
 
#define MAX_LL_HEADER_LEN   64
 Maximum length of a link-layer header. More...
 
#define MAX_NET_ADDR_LEN   16
 Maximum length of a network-layer address. More...
 
#define MAX_NET_HEADER_LEN   40
 Maximum length of a network-layer header. More...
 
#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. More...
 
#define LL_MULTICAST   0x0001
 Packet is a multicast (including broadcast) packet. More...
 
#define LL_BROADCAST   0x0002
 Packet is a broadcast packet. More...
 
#define LL_NAME_ONLY   0x0001
 Local link-layer address functions only as a name. More...
 
#define NETDEV_MAX_UNIQUE_ERRORS   4
 Maximum number of unique errors that we will keep track of. More...
 
#define NET_DEVICE_CONFIGURATORS   __table ( struct net_device_configurator, "net_device_configurators" )
 Network device configurator table. More...
 
#define __net_device_configurator   __table_entry ( NET_DEVICE_CONFIGURATORS, 01 )
 Declare a network device configurator. More...
 
#define NETDEV_NAME_LEN   12
 Maximum length of a network device name. More...
 
#define NETDEV_OPEN   0x0001
 Network device is open. More...
 
#define NETDEV_IRQ_ENABLED   0x0002
 Network device interrupts are enabled. More...
 
#define NETDEV_RX_FROZEN   0x0004
 Network device receive queue processing is frozen. More...
 
#define NETDEV_IRQ_UNSUPPORTED   0x0008
 Network device interrupts are unsupported. More...
 
#define NETDEV_TX_IN_PROGRESS   0x0010
 Network device transmission is in progress. More...
 
#define NETDEV_POLL_IN_PROGRESS   0x0020
 Network device poll is in progress. More...
 
#define LL_PROTOCOLS   __table ( struct ll_protocol, "ll_protocols" )
 Link-layer protocol table. More...
 
#define __ll_protocol   __table_entry ( LL_PROTOCOLS, 01 )
 Declare a link-layer protocol. More...
 
#define NET_PROTOCOLS   __table ( struct net_protocol, "net_protocols" )
 Network-layer protocol table. More...
 
#define __net_protocol   __table_entry ( NET_PROTOCOLS, 01 )
 Declare a network-layer protocol. More...
 
#define NET_DRIVERS   __table ( struct net_driver, "net_drivers" )
 Network driver table. More...
 
#define __net_driver   __table_entry ( NET_DRIVERS, 01 )
 Declare a network driver. More...
 
#define for_each_netdev(netdev)   list_for_each_entry ( (netdev), &net_devices, list )
 Iterate over all network devices. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static void netdev_init (struct net_device *netdev, struct net_device_operations *op)
 Initialise a network device. More...
 
static void netdev_nullify (struct net_device *netdev)
 Stop using a network device. More...
 
static const char * netdev_addr (struct net_device *netdev)
 Get printable network device link-layer address. More...
 
static int have_netdevs (void)
 There exist some network devices. More...
 
static struct net_devicenetdev_get (struct net_device *netdev)
 Get reference to network device. More...
 
static void netdev_put (struct net_device *netdev)
 Drop reference to network device. More...
 
static void * netdev_priv (struct net_device *netdev)
 Get driver private area for this network device. More...
 
static struct settingsnetdev_settings (struct net_device *netdev)
 Get per-netdevice configuration settings block. More...
 
static void netdev_settings_init (struct net_device *netdev)
 Initialise a per-netdevice configuration settings block. More...
 
static struct net_device_configurationnetdev_configuration (struct net_device *netdev, struct net_device_configurator *configurator)
 Get network device configuration. More...
 
static int netdev_configurator_applies (struct net_device *netdev, struct net_device_configurator *configurator)
 Check if configurator applies to network device. More...
 
static int netdev_link_ok (struct net_device *netdev)
 Check link state of network device. More...
 
static int netdev_link_blocked (struct net_device *netdev)
 Check link block state of network device. More...
 
static int netdev_is_open (struct net_device *netdev)
 Check whether or not network device is open. More...
 
static int netdev_irq_supported (struct net_device *netdev)
 Check whether or not network device supports interrupts. More...
 
static int netdev_irq_enabled (struct net_device *netdev)
 Check whether or not network device interrupts are currently enabled. More...
 
static int netdev_rx_frozen (struct net_device *netdev)
 Check whether or not network device receive queue processing is frozen. More...
 
void netdev_rx_freeze (struct net_device *netdev)
 Freeze network device receive queue processing. More...
 
void netdev_rx_unfreeze (struct net_device *netdev)
 Unfreeze network device receive queue processing. More...
 
void netdev_link_err (struct net_device *netdev, int rc)
 Mark network device as having a specific link state. More...
 
void netdev_link_down (struct net_device *netdev)
 Mark network device as having link down. More...
 
void netdev_link_block (struct net_device *netdev, unsigned long timeout)
 Mark network device link as being blocked. More...
 
void netdev_link_unblock (struct net_device *netdev)
 Mark network device link as being unblocked. More...
 
int netdev_tx (struct net_device *netdev, struct io_buffer *iobuf)
 Transmit raw packet via network device. More...
 
void netdev_tx_defer (struct net_device *netdev, struct io_buffer *iobuf)
 Defer transmitted packet. More...
 
void netdev_tx_err (struct net_device *netdev, struct io_buffer *iobuf, int rc)
 Discard transmitted packet. More...
 
void netdev_tx_complete_err (struct net_device *netdev, struct io_buffer *iobuf, int rc)
 Complete network transmission. More...
 
void netdev_tx_complete_next_err (struct net_device *netdev, int rc)
 Complete network transmission. More...
 
void netdev_rx (struct net_device *netdev, struct io_buffer *iobuf)
 Add packet to receive queue. More...
 
void netdev_rx_err (struct net_device *netdev, struct io_buffer *iobuf, int rc)
 Discard received packet. More...
 
void netdev_poll (struct net_device *netdev)
 Poll for completed and received packets on network device. More...
 
struct io_buffernetdev_rx_dequeue (struct net_device *netdev)
 Remove packet from device's receive queue. More...
 
struct net_devicealloc_netdev (size_t priv_size)
 Allocate network device. More...
 
int register_netdev (struct net_device *netdev)
 Register network device. More...
 
int netdev_open (struct net_device *netdev)
 Open network device. More...
 
void netdev_close (struct net_device *netdev)
 Close network device. More...
 
void unregister_netdev (struct net_device *netdev)
 Unregister network device. More...
 
void netdev_irq (struct net_device *netdev, int enable)
 Enable or disable interrupts. More...
 
struct net_devicefind_netdev (const char *name)
 Get network device by name. More...
 
struct net_devicefind_netdev_by_index (unsigned int index)
 Get network device by index. More...
 
struct net_devicefind_netdev_by_location (unsigned int bus_type, unsigned int location)
 Get network device by PCI bus:dev.fn address. More...
 
struct net_devicefind_netdev_by_ll_addr (struct ll_protocol *ll_protocol, const void *ll_addr)
 Get network device by link-layer address. More...
 
struct net_devicelast_opened_netdev (void)
 Get most recently opened network device. More...
 
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. More...
 
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. More...
 
void net_poll (void)
 Poll the network stack. More...
 
struct net_device_configuratorfind_netdev_configurator (const char *name)
 Find network device configurator. More...
 
int netdev_configure (struct net_device *netdev, struct net_device_configurator *configurator)
 Start network device configuration. More...
 
int netdev_configure_all (struct net_device *netdev)
 Start network device configuration via all supported configurators. More...
 
int netdev_configuration_in_progress (struct net_device *netdev)
 Check if network device configuration is in progress. More...
 
int netdev_configuration_ok (struct net_device *netdev)
 Check if network device has at least one successful configuration. More...
 
static void netdev_tx_complete (struct net_device *netdev, struct io_buffer *iobuf)
 Complete network transmission. More...
 
static void netdev_tx_complete_next (struct net_device *netdev)
 Complete network transmission. More...
 
static void netdev_link_up (struct net_device *netdev)
 Mark network device as having link up. More...
 

Variables

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

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 30 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 36 of file netdevice.h.

◆ 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 45 of file netdevice.h.

◆ MAX_NET_ADDR_LEN

#define MAX_NET_ADDR_LEN   16

Maximum length of a network-layer address.

Definition at line 48 of file netdevice.h.

◆ 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 55 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 58 of file netdevice.h.

◆ LL_MULTICAST

#define LL_MULTICAST   0x0001

Packet is a multicast (including broadcast) packet.

Definition at line 105 of file netdevice.h.

◆ LL_BROADCAST

#define LL_BROADCAST   0x0002

Packet is a broadcast packet.

Definition at line 108 of file netdevice.h.

◆ 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 210 of file netdevice.h.

◆ NETDEV_MAX_UNIQUE_ERRORS

#define NETDEV_MAX_UNIQUE_ERRORS   4

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

Definition at line 288 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 332 of file netdevice.h.

◆ __net_device_configurator

#define __net_device_configurator   __table_entry ( NET_DEVICE_CONFIGURATORS, 01 )

Declare a network device configurator.

Definition at line 336 of file netdevice.h.

◆ NETDEV_NAME_LEN

#define NETDEV_NAME_LEN   12

Maximum length of a network device name.

Definition at line 340 of file netdevice.h.

◆ NETDEV_OPEN

#define NETDEV_OPEN   0x0001

Network device is open.

Definition at line 438 of file netdevice.h.

◆ NETDEV_IRQ_ENABLED

#define NETDEV_IRQ_ENABLED   0x0002

Network device interrupts are enabled.

Definition at line 441 of file netdevice.h.

◆ NETDEV_RX_FROZEN

#define NETDEV_RX_FROZEN   0x0004

Network device receive queue processing is frozen.

Definition at line 444 of file netdevice.h.

◆ 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 452 of file netdevice.h.

◆ NETDEV_TX_IN_PROGRESS

#define NETDEV_TX_IN_PROGRESS   0x0010

Network device transmission is in progress.

Definition at line 455 of file netdevice.h.

◆ NETDEV_POLL_IN_PROGRESS

#define NETDEV_POLL_IN_PROGRESS   0x0020

Network device poll is in progress.

Definition at line 458 of file netdevice.h.

◆ LL_PROTOCOLS

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

Link-layer protocol table.

Definition at line 461 of file netdevice.h.

◆ __ll_protocol

#define __ll_protocol   __table_entry ( LL_PROTOCOLS, 01 )

Declare a link-layer protocol.

Definition at line 464 of file netdevice.h.

◆ NET_PROTOCOLS

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

Network-layer protocol table.

Definition at line 467 of file netdevice.h.

◆ __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 470 of file netdevice.h.

◆ NET_DRIVERS

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

Network driver table.

Definition at line 495 of file netdevice.h.

◆ __net_driver

#define __net_driver   __table_entry ( NET_DRIVERS, 01 )

Declare a network driver.

Definition at line 498 of file netdevice.h.

◆ for_each_netdev

#define for_each_netdev (   netdev)    list_for_each_entry ( (netdev), &net_devices, list )

Iterate over all network devices.

Definition at line 538 of file netdevice.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ netdev_init()

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

◆ netdev_nullify()

static 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 523 of file netdevice.h.

523  {
525 }
struct net_device_operations null_netdev_operations
Definition: nullnet.c:59
struct net_device_operations * op
Network device operations.
Definition: netdevice.h:369
static struct net_device * netdev
Definition: gdbudp.c:52

References netdev, null_netdev_operations, and net_device::op.

Referenced by a3c90x_remove(), atl1e_probe(), atl1e_remove(), axge_probe(), axge_remove(), b44_remove(), bnxt_init_one(), bnxt_remove_one(), dm96xx_probe(), dm96xx_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(), hermon_probe(), hermon_remove(), hunt_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(), 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(), smsc75xx_probe(), smsc75xx_remove(), smsc95xx_probe(), smsc95xx_remove(), snpnet_start(), snpnet_stop(), 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()

static 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 533 of file netdevice.h.

533  {
534  return netdev->ll_protocol->ntoa ( netdev->ll_addr );
535 }
static struct net_device * netdev
Definition: gdbudp.c:52
const char *(* ntoa)(const void *ll_addr)
Transcribe link-layer address.
Definition: netdevice.h:163
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:387
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:372

References net_device::ll_addr, net_device::ll_protocol, netdev, and ll_protocol::ntoa.

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

◆ have_netdevs()

static int have_netdevs ( void  )
inlinestatic

There exist some network devices.

Return values
existenceExistence of network devices

Definition at line 545 of file netdevice.h.

545  {
546  return ( ! list_empty ( &net_devices ) );
547 }
struct list_head net_devices
List of network devices.
Definition: netdevice.c:53
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136

References list_empty, and net_devices.

◆ netdev_get()

static 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 556 of file netdevice.h.

556  {
557  ref_get ( &netdev->refcnt );
558  return netdev;
559 }
static struct net_device * netdev
Definition: gdbudp.c:52
struct refcnt refcnt
Reference counter.
Definition: netdevice.h:354
#define ref_get(refcnt)
Get additional reference to object.
Definition: refcnt.h:92

References netdev, ref_get, and net_device::refcnt.

Referenced by add_ipv4_miniroute(), aoedev_open(), efi_pxe_install(), efi_snp_probe(), fcoe_probe(), gdbudp_configure(), 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()

static void netdev_put ( struct net_device netdev)
inlinestatic

Drop reference to network device.

Parameters
netdevNetwork device

Definition at line 567 of file netdevice.h.

567  {
568  ref_put ( &netdev->refcnt );
569 }
static struct net_device * netdev
Definition: gdbudp.c:52
struct refcnt refcnt
Reference counter.
Definition: netdevice.h:354
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106

References netdev, ref_put, and net_device::refcnt.

Referenced by a3c90x_probe(), a3c90x_remove(), aoedev_free(), atl1e_probe(), atl1e_remove(), axge_probe(), axge_remove(), b44_probe(), b44_remove(), bnxt_init_one(), bnxt_remove_one(), del_ipv4_miniroute(), dhcp_free(), dhcpv6_free(), dm96xx_probe(), dm96xx_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(), fcoe_close(), fcoe_probe(), flexboot_nodnic_register_netdev(), flexboot_nodnic_unregister_netdev(), forcedeth_probe(), forcedeth_remove(), free_rndis(), gdbudp_configure(), hermon_probe(), hermon_remove(), hunt_probe(), hunt_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(), ipv6_del_miniroute(), ipv6conf_free(), jme_probe(), jme_remove(), lan78xx_probe(), lan78xx_remove(), legacy_probe(), legacy_remove(), 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(), smsc75xx_probe(), smsc75xx_remove(), smsc95xx_probe(), smsc95xx_remove(), snpnet_start(), snpnet_stop(), 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_priv()

static void* netdev_priv ( struct net_device netdev)
inlinestatic

Get driver private area for this network device.

Parameters
netdevNetwork device
Return values
privDriver private area for this network device

Definition at line 578 of file netdevice.h.

578  {
579  return netdev->priv;
580 }
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52

References netdev, and net_device::priv.

Referenced by __mdio_read(), __mdio_write(), __tg3_set_rx_mode(), a3c90x_close(), a3c90x_hw_start(), a3c90x_irq(), a3c90x_open(), a3c90x_poll(), a3c90x_probe(), a3c90x_process_rx_packets(), a3c90x_process_tx_packets(), a3c90x_remove(), a3c90x_transmit(), atl1e_close(), atl1e_irq(), atl1e_mdio_read(), atl1e_mdio_write(), atl1e_open(), atl1e_poll(), atl1e_probe(), atl1e_remove(), atl1e_xmit_frame(), b44_close(), b44_irq(), b44_open(), b44_poll(), b44_probe(), b44_remove(), b44_set_rx_mode(), b44_transmit(), bcom_check_link(), bnxt_close(), bnxt_init_one(), bnxt_open(), bnxt_remove_one(), bnxt_rx_complete(), bnxt_service_cq(), bnxt_service_nq(), bnxt_tx(), bnxt_tx_complete(), efab_close(), efab_irq(), efab_open(), efab_poll(), efab_probe(), efab_remove(), efab_transmit(), efx_hunt_close(), efx_hunt_ev_init(), efx_hunt_irq(), efx_hunt_open(), efx_hunt_poll(), efx_hunt_rx_init(), efx_hunt_transmit(), efx_hunt_tx_init(), efx_probe(), efx_remove(), forcedeth_close(), forcedeth_irq(), forcedeth_link_status(), forcedeth_open(), forcedeth_poll(), forcedeth_probe(), forcedeth_transmit(), genesis_mac_init(), hunt_close(), hunt_open(), hunt_poll(), hunt_probe(), hunt_remove(), ifec_free(), igbvf_close(), igbvf_irq(), igbvf_open(), igbvf_poll(), igbvf_probe(), igbvf_process_rx_packets(), igbvf_process_tx_packets(), igbvf_remove(), igbvf_transmit(), jme_load_macaddr(), nv_process_rx_packets(), nv_process_tx_packets(), pcnet32_close(), pcnet32_irq(), pcnet32_open(), pcnet32_poll(), pcnet32_probe(), pcnet32_process_rx_packets(), pcnet32_process_tx_packets(), pcnet32_transmit(), phantom_close(), phantom_irq(), phantom_open(), phantom_poll(), phantom_poll_link_state(), phantom_probe(), phantom_refill_rx_ring(), phantom_remove(), phantom_transmit(), sis190_down(), sis190_free(), sis190_get_mac_addr_from_apc(), sis190_get_mac_addr_from_eeprom(), sis190_hw_start(), sis190_init_board(), sis190_init_ring(), sis190_init_rxfilter(), sis190_irq(), sis190_mii_probe(), sis190_mii_remove(), sis190_open(), sis190_poll(), sis190_probe(), sis190_set_rx_mode(), sis190_set_speed_auto(), sis190_transmit(), skge_devinit(), skge_down(), skge_free(), skge_net_irq(), skge_phyirq(), skge_poll(), skge_rx_done(), skge_rx_refill(), skge_tx_clean(), skge_tx_done(), skge_up(), skge_xmit_frame(), sky2_down(), sky2_init_netdev(), sky2_le_error(), sky2_net_irq(), sky2_phy_init(), sky2_phy_intr(), sky2_poll(), sky2_receive(), sky2_set_multicast(), sky2_status_intr(), sky2_tx_clean(), sky2_tx_done(), sky2_up(), sky2_xmit_frame(), snpnet_check_link(), snpnet_dump_mode(), snpnet_transmit(), tg3_close(), tg3_init_one(), tg3_irq(), tg3_open(), tg3_poll(), tg3_rx_complete(), tg3_transmit(), tg3_tx_complete(), vmxnet3_check_link(), vmxnet3_close(), vmxnet3_flush_rx(), vmxnet3_flush_tx(), vmxnet3_irq(), vmxnet3_open(), vmxnet3_poll_events(), vmxnet3_poll_rx(), vmxnet3_poll_tx(), vmxnet3_probe(), vmxnet3_refill_rx(), vmxnet3_remove(), vmxnet3_transmit(), vxge_close(), vxge_device_register(), vxge_irq(), vxge_open(), vxge_poll(), vxge_remove(), vxge_xmit(), xm_check_link(), xm_link_down(), yukon_init(), and yukon_mac_init().

◆ netdev_settings()

static struct settings* netdev_settings ( struct net_device netdev)
inlinestatic

◆ netdev_settings_init()

static 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 601 of file netdevice.h.

601  {
604 }
static void generic_settings_init(struct generic_settings *generics, struct refcnt *refcnt)
Initialise a settings block.
Definition: settings.h:513
struct settings_operations * op
Settings block operations.
Definition: settings.h:144
struct settings_operations netdev_settings_operations
Network device configuration settings operations.
static struct net_device * netdev
Definition: gdbudp.c:52
struct refcnt refcnt
Reference counter.
Definition: netdevice.h:354
struct settings settings
Settings block.
Definition: settings.h:300
struct generic_settings settings
Configuration settings applicable to this device.
Definition: netdevice.h:428

References generic_settings_init(), netdev, netdev_settings_operations, settings::op, net_device::refcnt, generic_settings::settings, and net_device::settings.

Referenced by alloc_netdev().

◆ netdev_configuration()

static 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 614 of file netdevice.h.

615  {
616 
618  configurator ) ];
619 }
struct net_device_configuration configs[0]
Network device configurations (variable length)
Definition: netdevice.h:434
static struct net_device * netdev
Definition: gdbudp.c:52
#define NET_DEVICE_CONFIGURATORS
Network device configurator table.
Definition: netdevice.h:332
#define table_index(table, entry)
Get index of entry within linker table.
Definition: tables.h:334

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

Referenced by ifconf_progress(), and netdev_configure().

◆ netdev_configurator_applies()

static 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 629 of file netdevice.h.

630  {
631  return ( ( configurator->applies == NULL ) ||
632  configurator->applies ( netdev ) );
633 }
static struct net_device * netdev
Definition: gdbudp.c:52
int(* applies)(struct net_device *netdev)
Check applicability of configurator.
Definition: netdevice.h:321
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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

Referenced by netdev_configure(), and netdev_configure_all().

◆ netdev_link_ok()

static int netdev_link_ok ( struct net_device netdev)
inlinestatic

◆ netdev_link_blocked()

static 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 653 of file netdevice.h.

653  {
654  return ( timer_running ( &netdev->link_block ) );
655 }
struct retry_timer link_block
Link block timer.
Definition: netdevice.h:403
static struct net_device * netdev
Definition: gdbudp.c:52

References net_device::link_block, and 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()

static int netdev_is_open ( struct net_device netdev)
inlinestatic

◆ netdev_irq_supported()

static 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 675 of file netdevice.h.

675  {
676  return ( ( netdev->op->irq != NULL ) &&
678 }
unsigned int state
Current device state.
Definition: netdevice.h:395
struct net_device_operations * op
Network device operations.
Definition: netdevice.h:369
void(* irq)(struct net_device *netdev, int enable)
Enable or disable interrupts.
Definition: netdevice.h:276
static struct net_device * netdev
Definition: gdbudp.c:52
#define NETDEV_IRQ_UNSUPPORTED
Network device interrupts are unsupported.
Definition: netdevice.h:452
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References net_device_operations::irq, netdev, NETDEV_IRQ_UNSUPPORTED, NULL, net_device::op, and net_device::state.

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

◆ netdev_irq_enabled()

static 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 687 of file netdevice.h.

687  {
688  return ( netdev->state & NETDEV_IRQ_ENABLED );
689 }
unsigned int state
Current device state.
Definition: netdevice.h:395
static struct net_device * netdev
Definition: gdbudp.c:52
#define NETDEV_IRQ_ENABLED
Network device interrupts are enabled.
Definition: netdevice.h:441

References netdev, NETDEV_IRQ_ENABLED, and net_device::state.

Referenced by pxenv_undi_isr().

◆ netdev_rx_frozen()

static 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 698 of file netdevice.h.

698  {
699  return ( netdev->state & NETDEV_RX_FROZEN );
700 }
#define NETDEV_RX_FROZEN
Network device receive queue processing is frozen.
Definition: netdevice.h:444
unsigned int state
Current device state.
Definition: netdevice.h:395
static struct net_device * netdev
Definition: gdbudp.c:52

References netdev, NETDEV_RX_FROZEN, and net_device::state.

Referenced by net_poll(), and pxenv_undi_transmit().

◆ netdev_rx_freeze()

void netdev_rx_freeze ( struct net_device netdev)

Freeze network device receive queue processing.

Parameters
netdevNetwork device

Definition at line 134 of file netdevice.c.

134  {
135 
136  /* Mark receive queue processing as frozen */
138 
139  /* Notify drivers of change */
140  netdev_notify ( netdev );
141 }
#define NETDEV_RX_FROZEN
Network device receive queue processing is frozen.
Definition: netdevice.h:444
unsigned int state
Current device state.
Definition: netdevice.h:395
static struct net_device * netdev
Definition: gdbudp.c:52
static void netdev_notify(struct net_device *netdev)
Notify drivers of network device or link state change.
Definition: netdevice.c:120

References netdev, netdev_notify(), NETDEV_RX_FROZEN, and net_device::state.

Referenced by pxe_netdev_open(), and pxenv_undi_transmit().

◆ netdev_rx_unfreeze()

void netdev_rx_unfreeze ( struct net_device netdev)

Unfreeze network device receive queue processing.

Parameters
netdevNetwork device

Definition at line 148 of file netdevice.c.

148  {
149 
150  /* Mark receive queue processing as not frozen */
152 
153  /* Notify drivers of change */
154  netdev_notify ( netdev );
155 }
#define NETDEV_RX_FROZEN
Network device receive queue processing is frozen.
Definition: netdevice.h:444
unsigned int state
Current device state.
Definition: netdevice.h:395
static struct net_device * netdev
Definition: gdbudp.c:52
static void netdev_notify(struct net_device *netdev)
Notify drivers of network device or link state change.
Definition: netdevice.c:120

References netdev, netdev_notify(), NETDEV_RX_FROZEN, and net_device::state.

Referenced by pxe_netdev_close(), and pxe_set_netdev().

◆ netdev_link_err()

void netdev_link_err ( struct net_device netdev,
int  rc 
)

Mark network device as having a specific link state.

Parameters
netdevNetwork device
rcLink status code

Definition at line 163 of file netdevice.c.

163  {
164 
165  /* Stop link block timer */
167 
168  /* Record link state */
169  netdev->link_rc = rc;
170  if ( netdev->link_rc == 0 ) {
171  DBGC ( netdev, "NETDEV %s link is up\n", netdev->name );
172  } else {
173  DBGC ( netdev, "NETDEV %s link is down: %s\n",
174  netdev->name, strerror ( netdev->link_rc ) );
175  }
176 
177  /* Notify drivers of link state change */
178  netdev_notify ( netdev );
179 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct retry_timer link_block
Link block timer.
Definition: netdevice.h:403
#define DBGC(...)
Definition: compiler.h:505
int link_rc
Link status code.
Definition: netdevice.h:401
static struct net_device * netdev
Definition: gdbudp.c:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
void stop_timer(struct retry_timer *timer)
Stop timer.
Definition: retry.c:117
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
static void netdev_notify(struct net_device *netdev)
Notify drivers of network device or link state change.
Definition: netdevice.c:120

References DBGC, net_device::link_block, net_device::link_rc, net_device::name, netdev, netdev_notify(), rc, stop_timer(), and strerror().

Referenced by eoib_join_complete(), eoib_link_state_changed(), 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)

Mark network device as having link down.

Parameters
netdevNetwork device

Definition at line 186 of file netdevice.c.

186  {
187 
188  /* Avoid clobbering a more detailed link status code, if one
189  * is already set.
190  */
191  if ( ( netdev->link_rc == 0 ) ||
192  ( netdev->link_rc == -EUNKNOWN_LINK_STATUS ) ) {
194  }
195 }
#define EUNKNOWN_LINK_STATUS
Default unknown link status code.
Definition: netdevice.c:71
int link_rc
Link status code.
Definition: netdevice.h:401
static struct net_device * netdev
Definition: gdbudp.c:52
void netdev_link_err(struct net_device *netdev, int rc)
Mark network device as having a specific link state.
Definition: netdevice.c:163
#define ENOTCONN_LINK_DOWN
Default link-down status code.
Definition: netdevice.c:86

References ENOTCONN_LINK_DOWN, EUNKNOWN_LINK_STATUS, net_device::link_rc, netdev, and netdev_link_err().

Referenced by __vxge_hw_vpath_alarm_process(), atl1e_check_link(), atl1e_down(), axge_check_link(), bnxt_set_link(), dm96xx_link_nsr(), ecm_intr_complete(), exanic_check_link(), flexboot_nodnic_state_change_netdev(), forcedeth_link_status(), hermon_state_change_netdev(), hunt_check_link(), hunt_open(), 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 
)

Mark network device link as being blocked.

Parameters
netdevNetwork device
timeoutTimeout (in ticks)

Definition at line 203 of file netdevice.c.

203  {
204 
205  /* Start link block timer */
206  if ( ! netdev_link_blocked ( netdev ) ) {
207  DBGC ( netdev, "NETDEV %s link blocked for %ld ticks\n",
208  netdev->name, timeout );
209  }
211 }
struct retry_timer link_block
Link block timer.
Definition: netdevice.h:403
#define DBGC(...)
Definition: compiler.h:505
static int netdev_link_blocked(struct net_device *netdev)
Check link block state of network device.
Definition: netdevice.h:653
static struct net_device * netdev
Definition: gdbudp.c:52
void start_timer_fixed(struct retry_timer *timer, unsigned long timeout)
Start timer with a specified timeout.
Definition: retry.c:64
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
void timeout(int)

References DBGC, net_device::link_block, net_device::name, netdev, netdev_link_blocked(), start_timer_fixed(), and timeout().

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

◆ netdev_link_unblock()

void netdev_link_unblock ( struct net_device netdev)

Mark network device link as being unblocked.

Parameters
netdevNetwork device

Definition at line 218 of file netdevice.c.

218  {
219 
220  /* Stop link block timer */
221  if ( netdev_link_blocked ( netdev ) )
222  DBGC ( netdev, "NETDEV %s link unblocked\n", netdev->name );
224 }
struct retry_timer link_block
Link block timer.
Definition: netdevice.h:403
#define DBGC(...)
Definition: compiler.h:505
static int netdev_link_blocked(struct net_device *netdev)
Check link block state of network device.
Definition: netdevice.h:653
static struct net_device * netdev
Definition: gdbudp.c:52
void stop_timer(struct retry_timer *timer)
Stop timer.
Definition: retry.c:117
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362

References DBGC, net_device::link_block, net_device::name, 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 
)

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 290 of file netdevice.c.

290  {
291  int rc;
292 
293  DBGC2 ( netdev, "NETDEV %s transmitting %p (%p+%zx)\n",
294  netdev->name, iobuf, iobuf->data, iob_len ( iobuf ) );
295  profile_start ( &net_tx_profiler );
296 
297  /* Enqueue packet */
298  list_add_tail ( &iobuf->list, &netdev->tx_queue );
299 
300  /* Guard against re-entry */
302  rc = -EBUSY;
303  goto err_busy;
304  }
306 
307  /* Avoid calling transmit() on unopened network devices */
308  if ( ! netdev_is_open ( netdev ) ) {
309  rc = -ENETUNREACH;
310  goto err_closed;
311  }
312 
313  /* Discard packet (for test purposes) if applicable */
314  if ( ( rc = inject_fault ( NETDEV_DISCARD_RATE ) ) != 0 )
315  goto err_fault;
316 
317  /* Map for DMA, if required */
318  if ( netdev->dma && ( ! dma_mapped ( &iobuf->map ) ) ) {
319  if ( ( rc = iob_map_tx ( iobuf, netdev->dma ) ) != 0 )
320  goto err_map;
321  }
322 
323  /* Transmit packet */
324  if ( ( rc = netdev->op->transmit ( netdev, iobuf ) ) != 0 )
325  goto err_transmit;
326 
327  /* Clear in-progress flag */
329 
330  profile_stop ( &net_tx_profiler );
331  return 0;
332 
333  err_transmit:
334  err_map:
335  err_fault:
336  err_closed:
338  err_busy:
339  netdev_tx_complete_err ( netdev, iobuf, rc );
340  return rc;
341 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EBUSY
Device or resource busy.
Definition: errno.h:338
struct dma_mapping map
DMA mapping.
Definition: iobuf.h:43
#define NETDEV_DISCARD_RATE
Definition: fault.h:15
unsigned int state
Current device state.
Definition: netdevice.h:395
struct dma_device * dma
DMA device.
Definition: netdevice.h:366
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:171
struct net_device_operations * op
Network device operations.
Definition: netdevice.h:369
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:240
static int netdev_is_open(struct net_device *netdev)
Check whether or not network device is open.
Definition: netdevice.h:664
static __always_inline int dma_mapped(struct dma_mapping *map)
Check if DMA unmapping is required.
Definition: dma.h:449
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
struct list_head tx_queue
TX packet queue.
Definition: netdevice.h:417
static struct net_device * netdev
Definition: gdbudp.c:52
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:158
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
int(* transmit)(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: netdevice.h:254
#define NETDEV_TX_IN_PROGRESS
Network device transmission is in progress.
Definition: netdevice.h:455
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
Definition: netdevice.c:426
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
struct list_head list
List of which this buffer is a member.
Definition: iobuf.h:40
#define DBGC2(...)
Definition: compiler.h:522
void * data
Start of data.
Definition: iobuf.h:48
#define ENETUNREACH
Network unreachable.
Definition: errno.h:488

References io_buffer::data, DBGC2, net_device::dma, dma_mapped(), EBUSY, ENETUNREACH, iob_len(), iob_map_tx(), io_buffer::list, list_add_tail, io_buffer::map, net_device::name, netdev, NETDEV_DISCARD_RATE, netdev_is_open(), netdev_tx_complete_err(), NETDEV_TX_IN_PROGRESS, net_device::op, profile_start(), profile_stop(), rc, net_device::state, 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(), netdev_tx_complete_err(), and pxenv_undi_transmit().

◆ netdev_tx_defer()

void netdev_tx_defer ( struct net_device netdev,
struct io_buffer iobuf 
)

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 368 of file netdevice.c.

368  {
369 
370  /* Catch data corruption as early as possible */
372 
373  /* Remove from transmit queue */
374  list_del ( &iobuf->list );
375 
376  /* Add to deferred transmit queue */
377  list_add_tail ( &iobuf->list, &netdev->tx_deferred );
378 
379  /* Record "out of space" statistic */
381 }
void netdev_tx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard transmitted packet.
Definition: netdevice.c:396
struct list_head list
List of neighbour cache entries.
Definition: neighbour.h:41
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
struct list_head tx_queue
TX packet queue.
Definition: netdevice.h:417
static struct net_device * netdev
Definition: gdbudp.c:52
struct list_head tx_deferred
Deferred TX packet queue.
Definition: netdevice.h:419
struct list_head list
List of which this buffer is a member.
Definition: iobuf.h:40
#define ENOBUFS
No buffer space available.
Definition: errno.h:498
#define list_check_contains_entry(entry, head, member)
Check list contains a specified entry.
Definition: list.h:522
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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

Referenced by 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 
)

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 396 of file netdevice.c.

397  {
398 
399  /* Update statistics counter */
401  if ( rc == 0 ) {
402  DBGC2 ( netdev, "NETDEV %s transmission %p complete\n",
403  netdev->name, iobuf );
404  } else {
405  DBGC ( netdev, "NETDEV %s transmission %p failed: %s\n",
406  netdev->name, iobuf, strerror ( rc ) );
407  }
408 
409  /* Unmap I/O buffer, if required */
410  if ( iobuf && dma_mapped ( &iobuf->map ) )
411  iob_unmap ( iobuf );
412 
413  /* Discard packet */
414  free_iob ( iobuf );
415 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct dma_mapping map
DMA mapping.
Definition: iobuf.h:43
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
#define DBGC(...)
Definition: compiler.h:505
static void netdev_record_stat(struct net_device_stats *stats, int rc)
Record network device statistic.
Definition: netdevice.c:247
struct net_device_stats tx_stats
TX statistics.
Definition: netdevice.h:423
static __always_inline int dma_mapped(struct dma_mapping *map)
Check if DMA unmapping is required.
Definition: dma.h:449
static __always_inline void iob_unmap(struct io_buffer *iobuf)
Unmap I/O buffer for DMA.
Definition: iobuf.h:275
static struct net_device * netdev
Definition: gdbudp.c:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
#define DBGC2(...)
Definition: compiler.h:522

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

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 
)

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 426 of file netdevice.c.

427  {
428 
429  /* Catch data corruption as early as possible */
431 
432  /* Dequeue and free I/O buffer */
433  list_del ( &iobuf->list );
434  netdev_tx_err ( netdev, iobuf, rc );
435 
436  /* Handle pending transmit queue */
437  while ( ( iobuf = list_first_entry ( &netdev->tx_deferred,
438  struct io_buffer, list ) ) ) {
439 
440  /* Remove from pending transmit queue */
441  list_del ( &iobuf->list );
442 
443  /* When any transmit completion fails, cancel all
444  * pending transmissions.
445  */
446  if ( rc != 0 ) {
447  netdev_tx_err ( netdev, iobuf, -ECANCELED );
448  continue;
449  }
450 
451  /* Otherwise, attempt to transmit the first pending packet */
452  netdev_tx ( netdev, iobuf );
453  break;
454  }
455 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void netdev_tx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard transmitted packet.
Definition: netdevice.c:396
#define ECANCELED
Operation canceled.
Definition: errno.h:343
struct list_head list
List of neighbour cache entries.
Definition: neighbour.h:41
#define list_first_entry(list, type, member)
Get the container of the first entry in a list.
Definition: list.h:333
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
struct list_head tx_queue
TX packet queue.
Definition: netdevice.h:417
static struct net_device * netdev
Definition: gdbudp.c:52
struct list_head tx_deferred
Deferred TX packet queue.
Definition: netdevice.h:419
int netdev_tx(struct net_device *netdev, struct io_buffer *iobuf)
Transmit raw packet via network device.
Definition: netdevice.c:290
struct list_head list
List of which this buffer is a member.
Definition: iobuf.h:40
#define list_check_contains_entry(entry, head, member)
Check list contains a specified entry.
Definition: list.h:522
A persistent I/O buffer.
Definition: iobuf.h:33

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

Referenced by axge_out_complete(), dm96xx_out_complete(), ecm_out_complete(), eoib_complete_send(), flexboot_nodnic_eth_complete_send(), hermon_eth_complete_send(), ifec_tx_process(), iphone_out_complete(), ipoib_complete_send(), jme_free_tx_buffers(), jme_tx_clean(), 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 
)

Complete network transmission.

Parameters
netdevNetwork device
rcPacket status code

Completes the oldest outstanding packet in the TX queue.

Definition at line 465 of file netdevice.c.

465  {
466  struct io_buffer *iobuf;
467 
468  if ( ( iobuf = list_first_entry ( &netdev->tx_queue, struct io_buffer,
469  list ) ) != NULL ) {
470  netdev_tx_complete_err ( netdev, iobuf, rc );
471  }
472 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define list_first_entry(list, type, member)
Get the container of the first entry in a list.
Definition: list.h:333
struct list_head tx_queue
TX packet queue.
Definition: netdevice.h:417
static struct net_device * netdev
Definition: gdbudp.c:52
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
Definition: netdevice.c:426
struct list_head list
List of which this buffer is a member.
Definition: iobuf.h:40
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
A persistent I/O buffer.
Definition: iobuf.h:33

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

Referenced by 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 
)

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 504 of file netdevice.c.

504  {
505  int rc;
506 
507  DBGC2 ( netdev, "NETDEV %s received %p (%p+%zx)\n",
508  netdev->name, iobuf, iobuf->data, iob_len ( iobuf ) );
509 
510  /* Discard packet (for test purposes) if applicable */
511  if ( ( rc = inject_fault ( NETDEV_DISCARD_RATE ) ) != 0 ) {
512  netdev_rx_err ( netdev, iobuf, rc );
513  return;
514  }
515 
516  /* Unmap I/O buffer, if required */
517  if ( dma_mapped ( &iobuf->map ) )
518  iob_unmap ( iobuf );
519 
520  /* Enqueue packet */
521  list_add_tail ( &iobuf->list, &netdev->rx_queue );
522 
523  /* Update statistics counter */
525 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:542
struct dma_mapping map
DMA mapping.
Definition: iobuf.h:43
#define NETDEV_DISCARD_RATE
Definition: fault.h:15
static void netdev_record_stat(struct net_device_stats *stats, int rc)
Record network device statistic.
Definition: netdevice.c:247
struct list_head rx_queue
RX packet queue.
Definition: netdevice.h:421
static __always_inline int dma_mapped(struct dma_mapping *map)
Check if DMA unmapping is required.
Definition: dma.h:449
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
static __always_inline void iob_unmap(struct io_buffer *iobuf)
Unmap I/O buffer for DMA.
Definition: iobuf.h:275
static struct net_device * netdev
Definition: gdbudp.c:52
struct net_device_stats rx_stats
RX statistics.
Definition: netdevice.h:425
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
struct list_head list
List of which this buffer is a member.
Definition: iobuf.h:40
#define DBGC2(...)
Definition: compiler.h:522
void * data
Start of data.
Definition: iobuf.h:48

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

Referenced by a3c90x_process_rx_packets(), atl1e_clean_rx_irq(), axge_in_complete(), b44_process_rx_packets(), bnxt_rx_process(), dm96xx_in_complete(), ecm_in_complete(), efab_receive(), efx_hunt_receive(), ena_poll_rx(), eoib_complete_recv(), exanic_poll_rx(), flexboot_nodnic_eth_complete_recv(), 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(), 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(), smsc75xx_in_complete(), smsc95xx_in_complete(), snpnet_poll_rx(), 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 
)

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 542 of file netdevice.c.

543  {
544 
545  DBGC ( netdev, "NETDEV %s failed to receive %p: %s\n",
546  netdev->name, iobuf, strerror ( rc ) );
547 
548  /* Unmap I/O buffer, if required */
549  if ( iobuf && dma_mapped ( &iobuf->map ) )
550  iob_unmap ( iobuf );
551 
552  /* Discard packet */
553  free_iob ( iobuf );
554 
555  /* Update statistics counter */
557 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct dma_mapping map
DMA mapping.
Definition: iobuf.h:43
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
#define DBGC(...)
Definition: compiler.h:505
static void netdev_record_stat(struct net_device_stats *stats, int rc)
Record network device statistic.
Definition: netdevice.c:247
static __always_inline int dma_mapped(struct dma_mapping *map)
Check if DMA unmapping is required.
Definition: dma.h:449
static __always_inline void iob_unmap(struct io_buffer *iobuf)
Unmap I/O buffer for DMA.
Definition: iobuf.h:275
static struct net_device * netdev
Definition: gdbudp.c:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
struct net_device_stats rx_stats
RX statistics.
Definition: netdevice.h:425
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362

References DBGC, dma_mapped(), free_iob(), iob_unmap(), io_buffer::map, net_device::name, netdev, netdev_record_stat(), rc, net_device::rx_stats, 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(), ecm_in_complete(), ecm_intr_complete(), ecm_poll(), efx_hunt_receive(), eoib_complete_recv(), exanic_close(), exanic_poll_rx(), flexboot_nodnic_eth_complete_recv(), 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(), 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(), 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(), vmxnet3_flush_rx(), vmxnet3_poll_events(), vmxnet3_poll_rx(), and vxge_hw_vpath_poll_rx().

◆ netdev_poll()

void netdev_poll ( struct net_device netdev)

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 568 of file netdevice.c.

568  {
569 
570  /* Avoid calling poll() on unopened network devices */
571  if ( ! netdev_is_open ( netdev ) )
572  return;
573 
574  /* Guard against re-entry */
576  return;
577 
578  /* Poll device */
580  netdev->op->poll ( netdev );
582 }
unsigned int state
Current device state.
Definition: netdevice.h:395
struct net_device_operations * op
Network device operations.
Definition: netdevice.h:369
void(* poll)(struct net_device *netdev)
Poll for completed and received packets.
Definition: netdevice.h:267
static int netdev_is_open(struct net_device *netdev)
Check whether or not network device is open.
Definition: netdevice.h:664
static struct net_device * netdev
Definition: gdbudp.c:52
#define NETDEV_POLL_IN_PROGRESS
Network device poll is in progress.
Definition: netdevice.h:458

References netdev, netdev_is_open(), NETDEV_POLL_IN_PROGRESS, net_device::op, net_device_operations::poll, and net_device::state.

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)

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 593 of file netdevice.c.

593  {
594  struct io_buffer *iobuf;
595 
596  iobuf = list_first_entry ( &netdev->rx_queue, struct io_buffer, list );
597  if ( ! iobuf )
598  return NULL;
599 
600  list_del ( &iobuf->list );
601  return iobuf;
602 }
struct list_head rx_queue
RX packet queue.
Definition: netdevice.h:421
#define list_first_entry(list, type, member)
Get the container of the first entry in a list.
Definition: list.h:333
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
static struct net_device * netdev
Definition: gdbudp.c:52
struct list_head list
List of which this buffer is a member.
Definition: iobuf.h:40
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
A persistent I/O buffer.
Definition: iobuf.h:33

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

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)

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 677 of file netdevice.c.

677  {
678  struct net_device *netdev;
679  struct net_device_configurator *configurator;
680  struct net_device_configuration *config;
681  unsigned int num_configs;
682  size_t confs_len;
683  size_t total_len;
684 
686  confs_len = ( num_configs * sizeof ( netdev->configs[0] ) );
687  total_len = ( sizeof ( *netdev ) + confs_len + priv_len );
688  netdev = zalloc ( total_len );
689  if ( netdev ) {
693  &netdev->refcnt );
698  config = netdev->configs;
700  config->netdev = netdev;
701  config->configurator = configurator;
702  config->rc = -EUNUSED_CONFIG;
703  intf_init ( &config->job, &netdev_config_desc,
704  &netdev->refcnt );
705  config++;
706  }
707  netdev->priv = ( ( ( void * ) netdev ) + sizeof ( *netdev ) +
708  confs_len );
709  }
710  return netdev;
711 }
static void netdev_settings_init(struct net_device *netdev)
Initialise a per-netdevice configuration settings block.
Definition: netdevice.h:601
#define EUNKNOWN_LINK_STATUS
Default unknown link status code.
Definition: netdevice.c:71
struct interface job
Job control interface.
Definition: netdevice.h:309
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
struct retry_timer link_block
Link block timer.
Definition: netdevice.h:403
struct list_head rx_queue
RX packet queue.
Definition: netdevice.h:421
#define EUNUSED_CONFIG
Default not-yet-attempted-configuration status code.
Definition: netdevice.c:76
int link_rc
Link status code.
Definition: netdevice.h:401
void * priv
Driver private data.
Definition: netdevice.h:431
struct list_head tx_queue
TX packet queue.
Definition: netdevice.h:417
struct net_device_configuration configs[0]
Network device configurations (variable length)
Definition: netdevice.h:434
static struct net_device * netdev
Definition: gdbudp.c:52
struct list_head tx_deferred
Deferred TX packet queue.
Definition: netdevice.h:419
static struct interface_descriptor netdev_config_desc
Network device configuration interface descriptor.
Definition: netdevice.c:650
struct refcnt refcnt
Reference counter.
Definition: netdevice.h:354
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:358
A network device.
Definition: netdevice.h:352
static void netdev_link_block_expired(struct retry_timer *timer, int fail __unused)
Handle network device link block timer expiry.
Definition: netdevice.c:232
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
struct net_device * netdev
Network device.
Definition: netdevice.h:303
int rc
Configuration status.
Definition: netdevice.h:307
A network device configurator.
Definition: netdevice.h:313
struct net_device_configurator * configurator
Network device configurator.
Definition: netdevice.h:305
static void free_netdev(struct refcnt *refcnt)
Free network device.
Definition: netdevice.c:658
#define NET_DEVICE_CONFIGURATORS
Network device configurator table.
Definition: netdevice.h:332
A network device configuration.
Definition: netdevice.h:301
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:190
#define table_num_entries(table)
Get number of entries in linker table.
Definition: tables.h:308

References net_device::configs, 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::link_block, net_device::link_rc, NET_DEVICE_CONFIGURATORS, netdev, net_device_configuration::netdev, netdev_config_desc, netdev_link_block_expired(), netdev_settings_init(), net_device::priv, net_device_configuration::rc, ref_init, net_device::refcnt, net_device::rx_queue, table_num_entries, net_device::tx_deferred, net_device::tx_queue, and zalloc().

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

◆ register_netdev()

int register_netdev ( struct net_device netdev)

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 722 of file netdevice.c.

722  {
724  struct net_driver *driver;
725  struct net_device *duplicate;
726  uint32_t seed;
727  int rc;
728 
729  /* Set initial link-layer address, if not already set */
730  if ( ! netdev_has_ll_addr ( netdev ) ) {
732  }
733 
734  /* Set MTU, if not already set */
735  if ( ! netdev->mtu ) {
736  netdev->mtu = ( netdev->max_pkt_len -
738  }
739 
740  /* Reject network devices that are already available via a
741  * different hardware device.
742  */
744  if ( duplicate && ( duplicate->dev != netdev->dev ) ) {
745  DBGC ( netdev, "NETDEV rejecting duplicate (phys %s) of %s "
746  "(phys %s)\n", netdev->dev->name, duplicate->name,
747  duplicate->dev->name );
748  rc = -EEXIST;
749  goto err_duplicate;
750  }
751 
752  /* Reject named network devices that already exist */
753  if ( netdev->name[0] && ( duplicate = find_netdev ( netdev->name ) ) ) {
754  DBGC ( netdev, "NETDEV rejecting duplicate name %s\n",
755  duplicate->name );
756  rc = -EEXIST;
757  goto err_duplicate;
758  }
759 
760  /* Record device index and create device name */
761  if ( netdev->name[0] == '\0' ) {
762  snprintf ( netdev->name, sizeof ( netdev->name ), "net%d",
763  netdev_index );
764  }
766 
767  /* Use least significant bits of the link-layer address to
768  * improve the randomness of the (non-cryptographic) random
769  * number generator.
770  */
772  - sizeof ( seed ) ), sizeof ( seed ) );
773  srand ( rand() ^ seed );
774 
775  /* Add to device list */
776  netdev_get ( netdev );
778  DBGC ( netdev, "NETDEV %s registered (phys %s hwaddr %s)\n",
779  netdev->name, netdev->dev->name,
780  netdev_addr ( netdev ) );
781 
782  /* Register per-netdev configuration settings */
784  NULL, netdev->name ) ) != 0 ) {
785  DBGC ( netdev, "NETDEV %s could not register settings: %s\n",
786  netdev->name, strerror ( rc ) );
787  goto err_register_settings;
788  }
789 
790  /* Probe device */
791  for_each_table_entry ( driver, NET_DRIVERS ) {
792  if ( driver->probe && ( rc = driver->probe ( netdev ) ) != 0 ) {
793  DBGC ( netdev, "NETDEV %s could not add %s device: "
794  "%s\n", netdev->name, driver->name,
795  strerror ( rc ) );
796  goto err_probe;
797  }
798  }
799 
800  return 0;
801 
802  err_probe:
804  if ( driver->remove )
805  driver->remove ( netdev );
806  }
809  err_register_settings:
810  list_del ( &netdev->list );
811  netdev_put ( netdev );
812  err_duplicate:
813  return rc;
814 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint8_t ll_header_len
Link-layer header length.
Definition: netdevice.h:200
uint8_t ll_addr_len
Link-layer address length.
Definition: netdevice.h:198
void unregister_settings(struct settings *settings)
Unregister settings block.
Definition: settings.c:517
#define EEXIST
File exists.
Definition: errno.h:388
size_t mtu
Maximum transmission unit length.
Definition: netdevice.h:415
struct list_head list
List of network devices.
Definition: netdevice.h:356
#define DBGC(...)
Definition: compiler.h:505
char name[40]
Name.
Definition: device.h:75
static const char * netdev_addr(struct net_device *netdev)
Get printable network device link-layer address.
Definition: netdevice.h:533
void(* init_addr)(const void *hw_addr, void *ll_addr)
Initialise link-layer address.
Definition: netdevice.h:150
A network upper-layer driver.
Definition: netdevice.h:473
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition: netdevice.h:589
A link-layer protocol.
Definition: netdevice.h:114
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
void * memcpy(void *dest, const void *src, size_t len) __nonnull
const char * name
Name.
Definition: netdevice.h:475
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:567
static int rand(void)
Definition: stdlib.h:59
static void srand(unsigned int seed)
Definition: stdlib.h:63
void(* remove)(struct net_device *netdev)
Remove device.
Definition: netdevice.h:491
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
static struct net_device * netdev
Definition: gdbudp.c:52
#define NET_DRIVERS
Network driver table.
Definition: netdevice.h:495
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:358
A network device.
Definition: netdevice.h:352
static struct net_device * netdev_get(struct net_device *netdev)
Get reference to network device.
Definition: netdevice.h:556
unsigned int uint32_t
Definition: stdint.h:12
static int netdev_has_ll_addr(struct net_device *netdev)
Check whether or not network device has a link-layer address.
Definition: netdevice.c:104
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
unsigned int index
Index of this network device.
Definition: netdevice.h:360
struct net_device * find_netdev(const char *name)
Get network device by name.
Definition: netdevice.c:948
static unsigned int netdev_index
Network device index.
Definition: netdevice.c:59
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
int register_settings(struct settings *settings, struct settings *parent, const char *name)
Register settings block.
Definition: settings.c:478
void clear_settings(struct settings *settings)
Clear settings block.
Definition: settings.c:1106
struct list_head net_devices
List of network devices.
Definition: netdevice.c:53
int(* probe)(struct net_device *netdev)
Probe device.
Definition: netdevice.h:481
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:387
size_t max_pkt_len
Maximum packet length.
Definition: netdevice.h:409
#define for_each_table_entry_continue_reverse(pointer, table)
Iterate through all remaining entries within a linker table in reverse order.
Definition: tables.h:442
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:381
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:372
struct net_device * find_netdev_by_ll_addr(struct ll_protocol *ll_protocol, const void *ll_addr)
Get network device by link-layer address.
Definition: netdevice.c:1009

References clear_settings(), DBGC, net_device::dev, EEXIST, find_netdev(), find_netdev_by_ll_addr(), for_each_table_entry, for_each_table_entry_continue_reverse, net_device::hw_addr, net_device::index, ll_protocol::init_addr, net_device::list, list_add_tail, list_del, net_device::ll_addr, ll_protocol::ll_addr_len, ll_protocol::ll_header_len, net_device::ll_protocol, net_device::max_pkt_len, memcpy(), net_device::mtu, device::name, net_device::name, net_driver::name, net_devices, NET_DRIVERS, netdev, netdev_addr(), netdev_get(), netdev_has_ll_addr(), netdev_index, netdev_put(), netdev_settings(), NULL, net_driver::probe, rand(), rc, register_settings(), net_driver::remove, snprintf(), srand(), strerror(), and unregister_settings().

Referenced by a3c90x_probe(), atl1e_probe(), axge_probe(), b44_probe(), bnxt_init_one(), dm96xx_probe(), ecm_probe(), efab_probe(), ena_probe(), eoib_create(), exanic_probe_port(), flexboot_nodnic_register_netdev(), forcedeth_probe(), hermon_register_netdev(), hunt_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(), 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(), smsc75xx_probe(), smsc95xx_probe(), snpnet_start(), 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)

Open network device.

Parameters
netdevNetwork device
Return values
rcReturn status code

Definition at line 822 of file netdevice.c.

822  {
823  int rc;
824 
825  /* Do nothing if device is already open */
826  if ( netdev->state & NETDEV_OPEN )
827  return 0;
828 
829  DBGC ( netdev, "NETDEV %s opening\n", netdev->name );
830 
831  /* Mark as opened */
833 
834  /* Open the device */
835  if ( ( rc = netdev->op->open ( netdev ) ) != 0 )
836  goto err;
837 
838  /* Add to head of open devices list */
840 
841  /* Notify drivers of device state change */
842  netdev_notify ( netdev );
843 
844  return 0;
845 
846  err:
847  netdev->state &= ~NETDEV_OPEN;
848  return rc;
849 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int(* open)(struct net_device *netdev)
Open network device.
Definition: netdevice.h:222
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:69
#define NETDEV_OPEN
Network device is open.
Definition: netdevice.h:438
#define DBGC(...)
Definition: compiler.h:505
unsigned int state
Current device state.
Definition: netdevice.h:395
struct net_device_operations * op
Network device operations.
Definition: netdevice.h:369
static struct net_device * netdev
Definition: gdbudp.c:52
static struct list_head open_net_devices
List of open network devices, in reverse order of opening.
Definition: netdevice.c:56
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
struct list_head open_list
List of open network devices.
Definition: netdevice.h:358
static void netdev_notify(struct net_device *netdev)
Notify drivers of network device or link state change.
Definition: netdevice.c:120

References DBGC, list_add, net_device::name, netdev, netdev_notify(), NETDEV_OPEN, net_device::op, net_device_operations::open, net_device::open_list, open_net_devices, rc, and net_device::state.

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

◆ netdev_close()

void netdev_close ( struct net_device netdev)

Close network device.

Parameters
netdevNetwork device

Definition at line 856 of file netdevice.c.

856  {
857  unsigned int num_configs;
858  unsigned int i;
859 
860  /* Do nothing if device is already closed */
861  if ( ! ( netdev->state & NETDEV_OPEN ) )
862  return;
863 
864  DBGC ( netdev, "NETDEV %s closing\n", netdev->name );
865 
866  /* Terminate any ongoing configurations. Use intf_close()
867  * rather than intf_restart() to allow the cancellation to be
868  * reported back to us if a configuration is actually in
869  * progress.
870  */
872  for ( i = 0 ; i < num_configs ; i++ )
874 
875  /* Remove from open devices list */
876  list_del ( &netdev->open_list );
877 
878  /* Mark as closed */
879  netdev->state &= ~NETDEV_OPEN;
880 
881  /* Notify drivers of device state change */
882  netdev_notify ( netdev );
883 
884  /* Close the device */
885  netdev->op->close ( netdev );
886 
887  /* Flush TX and RX queues */
890 }
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
#define NETDEV_OPEN
Network device is open.
Definition: netdevice.h:438
struct interface job
Job control interface.
Definition: netdevice.h:309
#define DBGC(...)
Definition: compiler.h:505
unsigned int state
Current device state.
Definition: netdevice.h:395
struct net_device_operations * op
Network device operations.
Definition: netdevice.h:369
#define ECANCELED
Operation canceled.
Definition: errno.h:343
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
struct net_device_configuration configs[0]
Network device configurations (variable length)
Definition: netdevice.h:434
static struct net_device * netdev
Definition: gdbudp.c:52
static void netdev_rx_flush(struct net_device *netdev)
Flush device's receive queue.
Definition: netdevice.c:609
void(* close)(struct net_device *netdev)
Close network device.
Definition: netdevice.h:230
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
struct list_head open_list
List of open network devices.
Definition: netdevice.h:358
#define NET_DEVICE_CONFIGURATORS
Network device configurator table.
Definition: netdevice.h:332
static void netdev_tx_flush(struct net_device *netdev)
Flush device's transmit queue.
Definition: netdevice.c:479
static void netdev_notify(struct net_device *netdev)
Notify drivers of network device or link state change.
Definition: netdevice.c:120
#define table_num_entries(table)
Get number of entries in linker table.
Definition: tables.h:308

References net_device_operations::close, net_device::configs, DBGC, ECANCELED, intf_close(), net_device_configuration::job, list_del, net_device::name, NET_DEVICE_CONFIGURATORS, netdev, netdev_notify(), NETDEV_OPEN, netdev_rx_flush(), netdev_tx_flush(), net_device::op, net_device::open_list, net_device::state, 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(), unregister_netdev(), vlan_close(), vlan_sync(), and xve_close().

◆ unregister_netdev()

void unregister_netdev ( struct net_device netdev)

Unregister network device.

Parameters
netdevNetwork device

Removes the network device from the list of network devices.

Definition at line 899 of file netdevice.c.

899  {
900  struct net_driver *driver;
901 
902  /* Ensure device is closed */
903  netdev_close ( netdev );
904 
905  /* Remove device */
907  if ( driver->remove )
908  driver->remove ( netdev );
909  }
910 
911  /* Unregister per-netdev configuration settings */
914 
915  /* Remove from device list */
916  DBGC ( netdev, "NETDEV %s unregistered\n", netdev->name );
917  list_del ( &netdev->list );
918  netdev_put ( netdev );
919 
920  /* Reset network device index if no devices remain */
921  if ( list_empty ( &net_devices ) )
922  netdev_index = 0;
923 }
void unregister_settings(struct settings *settings)
Unregister settings block.
Definition: settings.c:517
struct list_head list
List of network devices.
Definition: netdevice.h:356
#define DBGC(...)
Definition: compiler.h:505
#define for_each_table_entry_reverse(pointer, table)
Iterate through all entries within a linker table in reverse order.
Definition: tables.h:413
A network upper-layer driver.
Definition: netdevice.h:473
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition: netdevice.h:589
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:567
void(* remove)(struct net_device *netdev)
Remove device.
Definition: netdevice.h:491
static struct net_device * netdev
Definition: gdbudp.c:52
#define NET_DRIVERS
Network driver table.
Definition: netdevice.h:495
void netdev_close(struct net_device *netdev)
Close network device.
Definition: netdevice.c:856
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
static unsigned int netdev_index
Network device index.
Definition: netdevice.c:59
void clear_settings(struct settings *settings)
Clear settings block.
Definition: settings.c:1106
struct list_head net_devices
List of network devices.
Definition: netdevice.c:53

References clear_settings(), DBGC, for_each_table_entry_reverse, net_device::list, list_del, list_empty, net_device::name, net_devices, NET_DRIVERS, netdev, netdev_close(), netdev_index, netdev_put(), netdev_settings(), net_driver::remove, and unregister_settings().

Referenced by a3c90x_remove(), atl1e_remove(), axge_probe(), axge_remove(), b44_remove(), bnxt_remove_one(), dm96xx_probe(), dm96xx_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(), hermon_register_netdev(), hermon_unregister_netdev(), hunt_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(), 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(), smsc75xx_probe(), smsc75xx_remove(), smsc95xx_probe(), smsc95xx_remove(), snpnet_start(), snpnet_stop(), 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 
)

Enable or disable interrupts.

Parameters
netdevNetwork device
enableInterrupts should be enabled

Definition at line 930 of file netdevice.c.

930  {
931 
932  /* Enable or disable device interrupts, if applicable */
933  if ( netdev_irq_supported ( netdev ) )
934  netdev->op->irq ( netdev, enable );
935 
936  /* Record interrupt enabled state */
938  if ( enable )
940 }
unsigned int state
Current device state.
Definition: netdevice.h:395
struct net_device_operations * op
Network device operations.
Definition: netdevice.h:369
void(* irq)(struct net_device *netdev, int enable)
Enable or disable interrupts.
Definition: netdevice.h:276
static struct net_device * netdev
Definition: gdbudp.c:52
static int netdev_irq_supported(struct net_device *netdev)
Check whether or not network device supports interrupts.
Definition: netdevice.h:675
#define NETDEV_IRQ_ENABLED
Network device interrupts are enabled.
Definition: netdevice.h:441

References net_device_operations::irq, netdev, NETDEV_IRQ_ENABLED, netdev_irq_supported(), net_device::op, and net_device::state.

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)

Get network device by name.

Parameters
nameNetwork device name
Return values
netdevNetwork device, or NULL

Definition at line 948 of file netdevice.c.

948  {
949  struct net_device *netdev;
950 
951  /* Allow "netX" shortcut */
952  if ( strcmp ( name, "netX" ) == 0 )
953  return last_opened_netdev();
954 
955  /* Identify network device by name */
957  if ( strcmp ( netdev->name, name ) == 0 )
958  return netdev;
959  }
960 
961  return NULL;
962 }
const char * name
Definition: ath9k_hw.c:1984
struct list_head list
List of network devices.
Definition: netdevice.h:356
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:420
static struct net_device * netdev
Definition: gdbudp.c:52
struct net_device * last_opened_netdev(void)
Get most recently opened network device.
Definition: netdevice.c:1028
A network device.
Definition: netdevice.h:352
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:173
struct list_head net_devices
List of network devices.
Definition: netdevice.c:53
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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

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

◆ find_netdev_by_index()

struct net_device* find_netdev_by_index ( unsigned int  index)

Get network device by index.

Parameters
indexNetwork device index
Return values
netdevNetwork device, or NULL

Definition at line 970 of file netdevice.c.

970  {
971  struct net_device *netdev;
972 
973  /* Identify network device by index */
975  if ( netdev->index == index )
976  return netdev;
977  }
978 
979  return NULL;
980 }
struct list_head list
List of network devices.
Definition: netdevice.h:356
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:420
static struct net_device * netdev
Definition: gdbudp.c:52
A network device.
Definition: netdevice.h:352
unsigned int index
Index of this network device.
Definition: netdevice.h:360
struct list_head net_devices
List of network devices.
Definition: netdevice.c:53
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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

Referenced by ipv6_sock_ntoa().

◆ find_netdev_by_location()

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

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

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

Definition at line 989 of file netdevice.c.

990  {
991  struct net_device *netdev;
992 
994  if ( ( netdev->dev->desc.bus_type == bus_type ) &&
995  ( netdev->dev->desc.location == location ) )
996  return netdev;
997  }
998 
999  return NULL;
1000 }
struct list_head list
List of network devices.
Definition: netdevice.h:356
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:420
static struct net_device * netdev
Definition: gdbudp.c:52
unsigned int location
Location.
Definition: device.h:29
A network device.
Definition: netdevice.h:352
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
unsigned int bus_type
Bus type.
Definition: device.h:24
struct device_description desc
Device description.
Definition: device.h:79
struct list_head net_devices
List of network devices.
Definition: netdevice.c:53
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References device_description::bus_type, device::desc, net_device::dev, net_device::list, list_for_each_entry, device_description::location, net_devices, netdev, and NULL.

Referenced by pxenv_start_undi().

◆ find_netdev_by_ll_addr()

struct net_device* find_netdev_by_ll_addr ( struct ll_protocol ll_protocol,
const void *  ll_addr 
)

Get network device by link-layer address.

Parameters
ll_protocolLink-layer protocol
ll_addrLink-layer address
Return values
netdevNetwork device, or NULL

Definition at line 1009 of file netdevice.c.

1010  {
1011  struct net_device *netdev;
1012 
1014  if ( ( netdev->ll_protocol == ll_protocol ) &&
1015  ( memcmp ( netdev->ll_addr, ll_addr,
1016  ll_protocol->ll_addr_len ) == 0 ) )
1017  return netdev;
1018  }
1019 
1020  return NULL;
1021 }
uint8_t ll_addr_len
Link-layer address length.
Definition: netdevice.h:198
struct list_head list
List of network devices.
Definition: netdevice.h:356
A link-layer protocol.
Definition: netdevice.h:114
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:420
static struct net_device * netdev
Definition: gdbudp.c:52
A network device.
Definition: netdevice.h:352
struct list_head net_devices
List of network devices.
Definition: netdevice.c:53
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:387
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:114
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:372

References net_device::list, list_for_each_entry, net_device::ll_addr, ll_protocol::ll_addr_len, net_device::ll_protocol, memcmp(), net_devices, netdev, and NULL.

Referenced by ecm_fetch_mac(), and register_netdev().

◆ last_opened_netdev()

struct net_device* last_opened_netdev ( void  )

Get most recently opened network device.

Return values
netdevMost recently opened network device, or NULL

Definition at line 1028 of file netdevice.c.

1028  {
1029  struct net_device *netdev;
1030 
1032  open_list );
1033  if ( ! netdev )
1034  return NULL;
1035 
1036  assert ( netdev_is_open ( netdev ) );
1037  return netdev;
1038 }
#define list_first_entry(list, type, member)
Get the container of the first entry in a list.
Definition: list.h:333
static int netdev_is_open(struct net_device *netdev)
Check whether or not network device is open.
Definition: netdevice.h:664
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static struct net_device * netdev
Definition: gdbudp.c:52
static struct list_head open_net_devices
List of open network devices, in reverse order of opening.
Definition: netdevice.c:56
A network device.
Definition: netdevice.h:352
struct list_head open_list
List of open network devices.
Definition: netdevice.h:358
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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(), netdev_redirect(), 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 
)

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 1054 of file netdevice.c.

1056  {
1058  int rc;
1059 
1060  /* Add link-layer header */
1061  if ( ( rc = ll_protocol->push ( netdev, iobuf, ll_dest, ll_source,
1062  net_protocol->net_proto ) ) != 0 ) {
1063  /* Record error for diagnosis */
1064  netdev_tx_err ( netdev, iobuf, rc );
1065  return rc;
1066  }
1067 
1068  /* Transmit packet */
1069  return netdev_tx ( netdev, iobuf );
1070 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void netdev_tx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard transmitted packet.
Definition: netdevice.c:396
A link-layer protocol.
Definition: netdevice.h:114
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:127
static struct net_device * netdev
Definition: gdbudp.c:52
int netdev_tx(struct net_device *netdev, struct io_buffer *iobuf)
Transmit raw packet via network device.
Definition: netdevice.c:290
uint16_t net_proto
Network-layer protocol.
Definition: netdevice.h:99
A network-layer protocol.
Definition: netdevice.h:64
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:372

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

Referenced by aoecmd_tx(), arp_rx(), arp_tx_request(), 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_discovered(), neighbour_tx(), 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 
)

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 1083 of file netdevice.c.

1085  {
1086  struct net_protocol *net_protocol;
1087 
1088  /* Hand off to network-layer protocol, if any */
1090  if ( net_protocol->net_proto == net_proto )
1091  return net_protocol->rx ( iobuf, netdev, ll_dest,
1092  ll_source, flags );
1093  }
1094 
1095  DBGC ( netdev, "NETDEV %s unknown network protocol %04x\n",
1096  netdev->name, ntohs ( net_proto ) );
1097  free_iob ( iobuf );
1098  return -ENOTSUP;
1099 }
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
#define DBGC(...)
Definition: compiler.h:505
#define ntohs(value)
Definition: byteswap.h:136
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
static struct net_device * netdev
Definition: gdbudp.c:52
#define NET_PROTOCOLS
Network-layer protocol table.
Definition: netdevice.h:467
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:358
uint16_t net_proto
Network-layer protocol.
Definition: netdevice.h:99
A network-layer protocol.
Definition: netdevice.h:64
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
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:79
uint8_t flags
Flags.
Definition: ena.h:18

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

Referenced by net_poll().

◆ net_poll()

void net_poll ( void  )

Poll the network stack.

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

Definition at line 1107 of file netdevice.c.

1107  {
1108  struct net_device *netdev;
1109  struct io_buffer *iobuf;
1110  struct ll_protocol *ll_protocol;
1111  const void *ll_dest;
1112  const void *ll_source;
1113  uint16_t net_proto;
1114  unsigned int flags;
1115  int rc;
1116 
1117  /* Poll and process each network device */
1118  list_for_each_entry ( netdev, &net_devices, list ) {
1119 
1120  /* Poll for new packets */
1121  profile_start ( &net_poll_profiler );
1122  netdev_poll ( netdev );
1123  profile_stop ( &net_poll_profiler );
1124 
1125  /* Leave received packets on the queue if receive
1126  * queue processing is currently frozen. This will
1127  * happen when the raw packets are to be manually
1128  * dequeued using netdev_rx_dequeue(), rather than
1129  * processed via the usual networking stack.
1130  */
1131  if ( netdev_rx_frozen ( netdev ) )
1132  continue;
1133 
1134  /* Process all received packets */
1135  while ( ( iobuf = netdev_rx_dequeue ( netdev ) ) ) {
1136 
1137  DBGC2 ( netdev, "NETDEV %s processing %p (%p+%zx)\n",
1138  netdev->name, iobuf, iobuf->data,
1139  iob_len ( iobuf ) );
1140  profile_start ( &net_rx_profiler );
1141 
1142  /* Remove link-layer header */
1144  if ( ( rc = ll_protocol->pull ( netdev, iobuf,
1145  &ll_dest, &ll_source,
1146  &net_proto,
1147  &flags ) ) != 0 ) {
1148  free_iob ( iobuf );
1149  continue;
1150  }
1151 
1152  /* Hand packet to network layer */
1153  if ( ( rc = net_rx ( iob_disown ( iobuf ), netdev,
1154  net_proto, ll_dest,
1155  ll_source, flags ) ) != 0 ) {
1156  /* Record error for diagnosis */
1157  netdev_rx_err ( netdev, NULL, rc );
1158  }
1159  profile_stop ( &net_rx_profiler );
1160  }
1161  }
1162 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned short uint16_t
Definition: stdint.h:11
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:542
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:171
A link-layer protocol.
Definition: netdevice.h:114
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:212
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:420
static struct net_device * netdev
Definition: gdbudp.c:52
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:158
void netdev_poll(struct net_device *netdev)
Poll for completed and received packets on network device.
Definition: netdevice.c:568
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
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:1083
A network device.
Definition: netdevice.h:352
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:141
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
#define DBGC2(...)
Definition: compiler.h:522
void * data
Start of data.
Definition: iobuf.h:48
struct list_head net_devices
List of network devices.
Definition: netdevice.c:53
static int netdev_rx_frozen(struct net_device *netdev)
Check whether or not network device receive queue processing is frozen.
Definition: netdevice.h:698
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:372
struct io_buffer * netdev_rx_dequeue(struct net_device *netdev)
Remove packet from device's receive queue.
Definition: netdevice.c:593
A persistent I/O buffer.
Definition: iobuf.h:33
uint8_t flags
Flags.
Definition: ena.h:18

References io_buffer::data, DBGC2, flags, free_iob(), iob_disown, iob_len(), list_for_each_entry, net_device::ll_protocol, net_device::name, 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)

Find network device configurator.

Parameters
nameName
Return values
configuratorNetwork device configurator, or NULL

Definition at line 1259 of file netdevice.c.

1259  {
1260  struct net_device_configurator *configurator;
1261 
1263  if ( strcmp ( configurator->name, name ) == 0 )
1264  return configurator;
1265  }
1266  return NULL;
1267 }
const char * name
Definition: ath9k_hw.c:1984
const char * name
Name.
Definition: netdevice.h:315
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:358
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:173
A network device configurator.
Definition: netdevice.h:313
#define NET_DEVICE_CONFIGURATORS
Network device configurator table.
Definition: netdevice.h:332
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References for_each_table_entry, net_device_configurator::name, 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 
)

Start network device configuration.

Parameters
netdevNetwork device
configuratorNetwork device configurator
Return values
rcReturn status code

Definition at line 1276 of file netdevice.c.

1277  {
1278  struct net_device_configuration *config =
1280  int rc;
1281 
1282  /* Check applicability of configurator */
1284  DBGC ( netdev, "NETDEV %s does not support configuration via "
1285  "%s\n", netdev->name, configurator->name );
1286  return -ENOTSUP;
1287  }
1288 
1289  /* Terminate any ongoing configuration */
1290  intf_restart ( &config->job, -ECANCELED );
1291 
1292  /* Mark configuration as being in progress */
1293  config->rc = -EINPROGRESS_CONFIG;
1294 
1295  DBGC ( netdev, "NETDEV %s starting configuration via %s\n",
1297 
1298  /* Start configuration */
1299  if ( ( rc = configurator->start ( &config->job, netdev ) ) != 0 ) {
1300  DBGC ( netdev, "NETDEV %s could not start configuration via "
1301  "%s: %s\n", netdev->name, configurator->name,
1302  strerror ( rc ) );
1303  config->rc = rc;
1304  return rc;
1305  }
1306 
1307  return 0;
1308 }
#define EINPROGRESS_CONFIG
Default configuration-in-progress status code.
Definition: netdevice.c:81
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Name.
Definition: netdevice.h:315
void intf_restart(struct interface *intf, int rc)
Shut down and restart an object interface.
Definition: interface.c:342
int(* start)(struct interface *job, struct net_device *netdev)
Start configuring network device.
Definition: netdevice.h:328
struct interface job
Job control interface.
Definition: netdevice.h:309
#define DBGC(...)
Definition: compiler.h:505
#define ECANCELED
Operation canceled.
Definition: errno.h:343
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
static struct net_device * netdev
Definition: gdbudp.c:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static int netdev_configurator_applies(struct net_device *netdev, struct net_device_configurator *configurator)
Check if configurator applies to network device.
Definition: netdevice.h:629
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
int rc
Configuration status.
Definition: netdevice.h:307
struct net_device_configurator * configurator
Network device configurator.
Definition: netdevice.h:305
A network device configuration.
Definition: netdevice.h:301
static struct net_device_configuration * netdev_configuration(struct net_device *netdev, struct net_device_configurator *configurator)
Get network device configuration.
Definition: netdevice.h:614

References net_device_configuration::configurator, DBGC, ECANCELED, EINPROGRESS_CONFIG, ENOTSUP, intf_restart(), net_device_configuration::job, net_device_configurator::name, net_device::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)

Start network device configuration via all supported configurators.

Parameters
netdevNetwork device
Return values
rcReturn status code

Definition at line 1316 of file netdevice.c.

1316  {
1317  struct net_device_configurator *configurator;
1318  int rc;
1319 
1320  /* Start configuration for each configurator */
1322 
1323  /* Skip any inapplicable configurators */
1324  if ( ! netdev_configurator_applies ( netdev, configurator ) )
1325  continue;
1326 
1327  /* Start configuration */
1328  if ( ( rc = netdev_configure ( netdev, configurator ) ) != 0 )
1329  return rc;
1330  }
1331 
1332  return 0;
1333 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int netdev_configure(struct net_device *netdev, struct net_device_configurator *configurator)
Start network device configuration.
Definition: netdevice.c:1276
static struct net_device * netdev
Definition: gdbudp.c:52
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:358
static int netdev_configurator_applies(struct net_device *netdev, struct net_device_configurator *configurator)
Check if configurator applies to network device.
Definition: netdevice.h:629
A network device configurator.
Definition: netdevice.h:313
#define NET_DEVICE_CONFIGURATORS
Network device configurator table.
Definition: netdevice.h:332

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)

Check if network device configuration is in progress.

Parameters
netdevNetwork device
Return values
is_in_progressNetwork device configuration is in progress

Definition at line 1360 of file netdevice.c.

1360  {
1361 
1363 }
#define EINPROGRESS_CONFIG
Default configuration-in-progress status code.
Definition: netdevice.c:81
static struct net_device * netdev
Definition: gdbudp.c:52
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:1342

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)

Check if network device has at least one successful configuration.

Parameters
netdevNetwork device
configuratorConfigurator
Return values
rcReturn status code

Definition at line 1372 of file netdevice.c.

1372  {
1373 
1374  return netdev_has_configuration_rc ( netdev, 0 );
1375 }
static struct net_device * netdev
Definition: gdbudp.c:52
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:1342

References netdev, and netdev_has_configuration_rc().

Referenced by efi_pxe_dhcp(), and ifconf_progress().

◆ netdev_tx_complete()

static void netdev_tx_complete ( struct net_device netdev,
struct io_buffer iobuf 
)
inlinestatic

Complete network transmission.

Parameters
netdevNetwork device
iobufI/O buffer

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

Definition at line 758 of file netdevice.h.

759  {
760  netdev_tx_complete_err ( netdev, iobuf, 0 );
761 }
static struct net_device * netdev
Definition: gdbudp.c:52
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
Definition: netdevice.c:426

References netdev, and netdev_tx_complete_err().

Referenced by a3c90x_process_tx_packets(), atl1e_clean_tx_irq(), atl1e_clean_tx_ring(), b44_tx_complete(), bnxt_tx_complete(), efab_free_resources(), efab_transmit_done(), efx_hunt_close(), efx_hunt_transmit_done(), ifec_tx_process(), igbvf_process_tx_packets(), jme_tx_clean(), legacy_transmit(), myri10ge_interrupt_handler(), net80211_netdev_transmit(), netfront_poll_tx(), nii_poll_tx(), nv_process_tx_packets(), pcnet32_process_tx_packets(), phantom_poll(), pnic_transmit(), sis190_process_tx(), skge_tx_done(), sky2_tx_complete(), snpnet_poll_tx(), tg3_tx_complete(), undinet_transmit(), virtnet_process_tx_packets(), vmxnet3_poll_tx(), and vxge_xmit_compl().

◆ netdev_tx_complete_next()

static 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 770 of file netdevice.h.

770  {
772 }
static struct net_device * netdev
Definition: gdbudp.c:52
void netdev_tx_complete_next_err(struct net_device *netdev, int rc)
Complete network transmission.
Definition: netdevice.c:465

References netdev, and netdev_tx_complete_next_err().

Referenced by ena_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()

static void netdev_link_up ( struct net_device netdev)
inlinestatic

Mark network device as having link up.

Parameters
netdevNetwork device

Definition at line 780 of file netdevice.h.

780  {
781  netdev_link_err ( netdev, 0 );
782 }
static struct net_device * netdev
Definition: gdbudp.c:52
void netdev_link_err(struct net_device *netdev, int rc)
Mark network device as having a specific link state.
Definition: netdevice.c:163

References netdev, and netdev_link_err().

Referenced by __vxge_hw_vpath_alarm_process(), a3c90x_probe(), atl1e_check_link(), axge_check_link(), b44_probe(), bnxt_set_link(), dm96xx_link_nsr(), ecm_intr_complete(), efab_init_mac(), efab_probe(), ena_probe(), exanic_check_link(), flexboot_nodnic_state_change_netdev(), forcedeth_link_status(), hermon_state_change_netdev(), hunt_check_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(), 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(), snpnet_check_link(), snpnet_start(), 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

◆ null_netdev_operations

struct net_device_operations null_netdev_operations

Definition at line 59 of file nullnet.c.

Referenced by netdev_nullify().

◆ netdev_settings_operations

struct settings_operations netdev_settings_operations

Network device configuration settings operations.

Definition at line 358 of file netdev_settings.c.

Referenced by netdev_settings_init().