iPXE
Macros | Functions | Variables
netdevice.c File Reference

Network device management. More...

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <byteswap.h>
#include <string.h>
#include <errno.h>
#include <config/general.h>
#include <ipxe/if_ether.h>
#include <ipxe/iobuf.h>
#include <ipxe/tables.h>
#include <ipxe/process.h>
#include <ipxe/init.h>
#include <ipxe/malloc.h>
#include <ipxe/device.h>
#include <ipxe/errortab.h>
#include <ipxe/profile.h>
#include <ipxe/fault.h>
#include <ipxe/vlan.h>
#include <ipxe/netdevice.h>

Go to the source code of this file.

Macros

#define EUNKNOWN_LINK_STATUS   __einfo_error ( EINFO_EUNKNOWN_LINK_STATUS )
 Default unknown link status code. More...
 
#define EINFO_EUNKNOWN_LINK_STATUS   __einfo_uniqify ( EINFO_EINPROGRESS, 0x01, "Unknown" )
 
#define EUNUSED_CONFIG   __einfo_error ( EINFO_EUNUSED_CONFIG )
 Default not-yet-attempted-configuration status code. More...
 
#define EINFO_EUNUSED_CONFIG   __einfo_uniqify ( EINFO_EINPROGRESS, 0x02, "Unused" )
 
#define EINPROGRESS_CONFIG   __einfo_error ( EINFO_EINPROGRESS_CONFIG )
 Default configuration-in-progress status code. More...
 
#define EINFO_EINPROGRESS_CONFIG   __einfo_uniqify ( EINFO_EINPROGRESS, 0x03, "Incomplete" )
 
#define ENOTCONN_LINK_DOWN   __einfo_error ( EINFO_ENOTCONN_LINK_DOWN )
 Default link-down status code. More...
 
#define EINFO_ENOTCONN_LINK_DOWN   __einfo_uniqify ( EINFO_ENOTCONN, 0x01, "Down" )
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int netdev_has_ll_addr (struct net_device *netdev)
 Check whether or not network device has a link-layer address. More...
 
static void netdev_notify (struct net_device *netdev)
 Notify drivers of network device or link state change. 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...
 
static void netdev_link_block_expired (struct retry_timer *timer, int fail __unused)
 Handle network device link block timer expiry. More...
 
static void netdev_record_stat (struct net_device_stats *stats, int rc)
 Record network device statistic. 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...
 
static void netdev_tx_flush (struct net_device *netdev)
 Flush device's transmit queue. 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...
 
static void netdev_rx_flush (struct net_device *netdev)
 Flush device's receive queue. More...
 
static void netdev_config_close (struct net_device_configuration *config, int rc)
 Finish network device configuration. More...
 
static void free_netdev (struct refcnt *refcnt)
 Free network device. More...
 
struct net_devicealloc_netdev (size_t priv_len)
 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...
 
static void net_step (struct process *process __unused)
 Single-step the network stack. More...
 
__weak unsigned int vlan_tag (struct net_device *netdev __unused)
 Get the VLAN tag (when VLAN support is not present) More...
 
__weak void vlan_netdev_rx (struct net_device *netdev, unsigned int tag, struct io_buffer *iobuf)
 Add VLAN tag-stripped packet to queue (when VLAN support is not present) More...
 
__weak void vlan_netdev_rx_err (struct net_device *netdev, unsigned int tag __unused, struct io_buffer *iobuf, int rc)
 Discard received VLAN tag-stripped packet (when VLAN support is not present) More...
 
 PERMANENT_PROCESS (net_process, net_step)
 Networking stack process. More...
 
static unsigned int net_discard (void)
 Discard some cached network device data. More...
 
struct cache_discarder net_discarder __cache_discarder (CACHE_NORMAL)
 Network device cache discarder. 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...
 
static int netdev_has_configuration_rc (struct net_device *netdev, int rc)
 Check if network device has a configuration with a specified status code. 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...
 

Variables

struct list_head net_devices = LIST_HEAD_INIT ( net_devices )
 List of network devices. More...
 
static struct list_head open_net_devices = LIST_HEAD_INIT ( open_net_devices )
 List of open network devices, in reverse order of opening. More...
 
static unsigned int netdev_index = 0
 Network device index. More...
 
static struct profiler net_poll_profiler __profiler = { .name = "net.poll" }
 Network polling profiler. More...
 
struct errortab netdev_errors [] __errortab
 Human-readable message for the default link statuses. More...
 
static struct interface_operation netdev_config_ops []
 Network device configuration interface operations. More...
 
static struct interface_descriptor netdev_config_desc
 Network device configuration interface descriptor. More...
 

Detailed Description

Network device management.

Definition in file netdevice.c.

Macro Definition Documentation

◆ EUNKNOWN_LINK_STATUS

#define EUNKNOWN_LINK_STATUS   __einfo_error ( EINFO_EUNKNOWN_LINK_STATUS )

Default unknown link status code.

Definition at line 71 of file netdevice.c.

◆ EINFO_EUNKNOWN_LINK_STATUS

#define EINFO_EUNKNOWN_LINK_STATUS   __einfo_uniqify ( EINFO_EINPROGRESS, 0x01, "Unknown" )

Definition at line 72 of file netdevice.c.

◆ EUNUSED_CONFIG

#define EUNUSED_CONFIG   __einfo_error ( EINFO_EUNUSED_CONFIG )

Default not-yet-attempted-configuration status code.

Definition at line 76 of file netdevice.c.

◆ EINFO_EUNUSED_CONFIG

#define EINFO_EUNUSED_CONFIG   __einfo_uniqify ( EINFO_EINPROGRESS, 0x02, "Unused" )

Definition at line 77 of file netdevice.c.

◆ EINPROGRESS_CONFIG

#define EINPROGRESS_CONFIG   __einfo_error ( EINFO_EINPROGRESS_CONFIG )

Default configuration-in-progress status code.

Definition at line 81 of file netdevice.c.

◆ EINFO_EINPROGRESS_CONFIG

#define EINFO_EINPROGRESS_CONFIG   __einfo_uniqify ( EINFO_EINPROGRESS, 0x03, "Incomplete" )

Definition at line 82 of file netdevice.c.

◆ ENOTCONN_LINK_DOWN

#define ENOTCONN_LINK_DOWN   __einfo_error ( EINFO_ENOTCONN_LINK_DOWN )

Default link-down status code.

Definition at line 86 of file netdevice.c.

◆ EINFO_ENOTCONN_LINK_DOWN

#define EINFO_ENOTCONN_LINK_DOWN   __einfo_uniqify ( EINFO_ENOTCONN, 0x01, "Down" )

Definition at line 87 of file netdevice.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ netdev_has_ll_addr()

static int netdev_has_ll_addr ( struct net_device netdev)
static

Check whether or not network device has a link-layer address.

Parameters
netdevNetwork device
Return values
has_ll_addrNetwork device has a link-layer address

Definition at line 104 of file netdevice.c.

104  {
105  uint8_t *ll_addr = netdev->ll_addr;
106  size_t remaining = sizeof ( netdev->ll_addr );
107 
108  while ( remaining-- ) {
109  if ( *(ll_addr++) != 0 )
110  return 1;
111  }
112  return 0;
113 }
static struct net_device * netdev
Definition: gdbudp.c:52
unsigned char uint8_t
Definition: stdint.h:10
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:381

References net_device::ll_addr, and netdev.

Referenced by register_netdev().

◆ netdev_notify()

static void netdev_notify ( struct net_device netdev)
static

Notify drivers of network device or link state change.

Parameters
netdevNetwork device

Definition at line 120 of file netdevice.c.

120  {
121  struct net_driver *driver;
122 
123  for_each_table_entry ( driver, NET_DRIVERS ) {
124  if ( driver->notify )
125  driver->notify ( netdev );
126  }
127 }
A network upper-layer driver.
Definition: netdevice.h:461
static struct net_device * netdev
Definition: gdbudp.c:52
#define NET_DRIVERS
Network driver table.
Definition: netdevice.h:483
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:358
void(* notify)(struct net_device *netdev)
Notify of device or link state change.
Definition: netdevice.h:474

References for_each_table_entry, NET_DRIVERS, netdev, and net_driver::notify.

Referenced by netdev_close(), netdev_link_err(), netdev_open(), netdev_rx_freeze(), and netdev_rx_unfreeze().

◆ 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:438
unsigned int state
Current device state.
Definition: netdevice.h:389
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:438
unsigned int state
Current device state.
Definition: netdevice.h:389
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:397
#define DBGC(...)
Definition: compiler.h:505
int link_rc
Link status code.
Definition: netdevice.h:395
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:358
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(), 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:395
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(), axge_intr_complete(), 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:397
#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:641
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:358
void timeout(int)

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

Referenced by 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:397
#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:641
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:358

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

Referenced by eth_slow_lacp_rx(), and stp_rx().

◆ netdev_link_block_expired()

static void netdev_link_block_expired ( struct retry_timer timer,
int fail  __unused 
)
static

Handle network device link block timer expiry.

Parameters
timerLink block timer
failFailure indicator

Definition at line 232 of file netdevice.c.

233  {
234  struct net_device *netdev =
236 
237  /* Assume link is no longer blocked */
238  DBGC ( netdev, "NETDEV %s link block expired\n", netdev->name );
239 }
struct retry_timer link_block
Link block timer.
Definition: netdevice.h:397
#define DBGC(...)
Definition: compiler.h:505
A timer.
Definition: timer.h:28
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
static struct net_device * netdev
Definition: gdbudp.c:52
A network device.
Definition: netdevice.h:348
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:358

References container_of, DBGC, net_device::link_block, net_device::name, and netdev.

Referenced by alloc_netdev().

◆ netdev_record_stat()

static void netdev_record_stat ( struct net_device_stats stats,
int  rc 
)
static

Record network device statistic.

Parameters
statsNetwork device statistics
rcStatus code

Definition at line 247 of file netdevice.c.

247  {
248  struct net_device_error *error;
249  struct net_device_error *least_common_error;
250  unsigned int i;
251 
252  /* If this is not an error, just update the good counter */
253  if ( rc == 0 ) {
254  stats->good++;
255  return;
256  }
257 
258  /* Update the bad counter */
259  stats->bad++;
260 
261  /* Locate the appropriate error record */
262  least_common_error = &stats->errors[0];
263  for ( i = 0 ; i < ( sizeof ( stats->errors ) /
264  sizeof ( stats->errors[0] ) ) ; i++ ) {
265  error = &stats->errors[i];
266  /* Update matching record, if found */
267  if ( error->rc == rc ) {
268  error->count++;
269  return;
270  }
271  if ( error->count < least_common_error->count )
272  least_common_error = error;
273  }
274 
275  /* Overwrite the least common error record */
276  least_common_error->rc = rc;
277  least_common_error->count = 1;
278 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct arbelprm_completion_with_error error
Definition: arbel.h:12
Network device error.
Definition: netdevice.h:276
unsigned int count
Error count.
Definition: netdevice.h:280
unsigned int bad
Count of error completions.
Definition: netdevice.h:291
struct net_device_error errors[NETDEV_MAX_UNIQUE_ERRORS]
Error breakdowns.
Definition: netdevice.h:293
unsigned int good
Count of successful completions.
Definition: netdevice.h:289
int rc
Error status code.
Definition: netdevice.h:278

References net_device_stats::bad, net_device_error::count, error, net_device_stats::errors, net_device_stats::good, net_device_error::rc, and rc.

Referenced by netdev_rx(), netdev_rx_err(), and netdev_tx_err().

◆ 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  /* Avoid calling transmit() on unopened network devices */
301  if ( ! netdev_is_open ( netdev ) ) {
302  rc = -ENETUNREACH;
303  goto err;
304  }
305 
306  /* Discard packet (for test purposes) if applicable */
307  if ( ( rc = inject_fault ( NETDEV_DISCARD_RATE ) ) != 0 )
308  goto err;
309 
310  /* Transmit packet */
311  if ( ( rc = netdev->op->transmit ( netdev, iobuf ) ) != 0 )
312  goto err;
313 
314  profile_stop ( &net_tx_profiler );
315  return 0;
316 
317  err:
318  netdev_tx_complete_err ( netdev, iobuf, rc );
319  return rc;
320 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define NETDEV_DISCARD_RATE
Definition: fault.h:15
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:171
struct net_device_operations * op
Network device operations.
Definition: netdevice.h:363
static int netdev_is_open(struct net_device *netdev)
Check whether or not network device is open.
Definition: netdevice.h:652
#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:411
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:151
int(* transmit)(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: netdevice.h:250
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
Definition: netdevice.c:395
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:358
struct list_head list
List of which this buffer is a member.
Definition: iobuf.h:39
#define DBGC2(...)
Definition: compiler.h:522
void * data
Start of data.
Definition: iobuf.h:44
#define ENETUNREACH
Network unreachable.
Definition: errno.h:488

References io_buffer::data, DBGC2, ENETUNREACH, iob_len(), io_buffer::list, list_add_tail, net_device::name, netdev, NETDEV_DISCARD_RATE, netdev_is_open(), netdev_tx_complete_err(), net_device::op, profile_start(), profile_stop(), rc, net_device_operations::transmit, and net_device::tx_queue.

Referenced by efi_snp_transmit(), gdbudp_recv(), gdbudp_send(), net80211_handle_auth(), net80211_netdev_transmit(), net80211_tx_mgmt(), net_tx(), 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).

Definition at line 344 of file netdevice.c.

344  {
345 
346  /* Catch data corruption as early as possible */
347  list_check_contains_entry ( iobuf, &netdev->tx_queue, list );
348 
349  /* Remove from transmit queue */
350  list_del ( &iobuf->list );
351 
352  /* Add to deferred transmit queue */
353  list_add_tail ( &iobuf->list, &netdev->tx_deferred );
354 
355  /* Record "out of space" statistic */
357 }
void netdev_tx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard transmitted packet.
Definition: netdevice.c:369
#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:411
static struct net_device * netdev
Definition: gdbudp.c:52
struct list_head tx_deferred
Deferred TX packet queue.
Definition: netdevice.h:413
struct list_head list
List of which this buffer is a member.
Definition: iobuf.h:39
#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.

Definition at line 369 of file netdevice.c.

370  {
371 
372  /* Update statistics counter */
374  if ( rc == 0 ) {
375  DBGC2 ( netdev, "NETDEV %s transmission %p complete\n",
376  netdev->name, iobuf );
377  } else {
378  DBGC ( netdev, "NETDEV %s transmission %p failed: %s\n",
379  netdev->name, iobuf, strerror ( rc ) );
380  }
381 
382  /* Discard packet */
383  free_iob ( iobuf );
384 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
#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:417
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:358
#define DBGC2(...)
Definition: compiler.h:522

References DBGC, DBGC2, free_iob(), 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(), 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 395 of file netdevice.c.

396  {
397 
398  /* Catch data corruption as early as possible */
399  list_check_contains_entry ( iobuf, &netdev->tx_queue, list );
400 
401  /* Dequeue and free I/O buffer */
402  list_del ( &iobuf->list );
403  netdev_tx_err ( netdev, iobuf, rc );
404 
405  /* Handle pending transmit queue */
406  while ( ( iobuf = list_first_entry ( &netdev->tx_deferred,
407  struct io_buffer, list ) ) ) {
408 
409  /* Remove from pending transmit queue */
410  list_del ( &iobuf->list );
411 
412  /* When any transmit completion fails, cancel all
413  * pending transmissions.
414  */
415  if ( rc != 0 ) {
416  netdev_tx_err ( netdev, iobuf, -ECANCELED );
417  continue;
418  }
419 
420  /* Otherwise, attempt to transmit the first pending packet */
421  netdev_tx ( netdev, iobuf );
422  break;
423  }
424 }
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:369
#define ECANCELED
Operation canceled.
Definition: errno.h:343
#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:411
static struct net_device * netdev
Definition: gdbudp.c:52
struct list_head tx_deferred
Deferred TX packet queue.
Definition: netdevice.h:413
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:39
#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:32

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(), 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 434 of file netdevice.c.

434  {
435  struct io_buffer *iobuf;
436 
437  if ( ( iobuf = list_first_entry ( &netdev->tx_queue, struct io_buffer,
438  list ) ) != NULL ) {
439  netdev_tx_complete_err ( netdev, iobuf, rc );
440  }
441 }
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:411
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:395
struct list_head list
List of which this buffer is a member.
Definition: iobuf.h:39
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
A persistent I/O buffer.
Definition: iobuf.h:32

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_tx_flush()

static void netdev_tx_flush ( struct net_device netdev)
static

Flush device's transmit queue.

Parameters
netdevNetwork device

Definition at line 448 of file netdevice.c.

448  {
449 
450  /* Discard any packets in the TX queue. This will also cause
451  * any packets in the deferred TX queue to be discarded
452  * automatically.
453  */
454  while ( ! list_empty ( &netdev->tx_queue ) ) {
456  }
457  assert ( list_empty ( &netdev->tx_queue ) );
459 }
void netdev_tx_complete_next_err(struct net_device *netdev, int rc)
Complete network transmission.
Definition: netdevice.c:434
#define ECANCELED
Operation canceled.
Definition: errno.h:343
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct list_head tx_queue
TX packet queue.
Definition: netdevice.h:411
static struct net_device * netdev
Definition: gdbudp.c:52
struct list_head tx_deferred
Deferred TX packet queue.
Definition: netdevice.h:413

References assert(), ECANCELED, list_empty, netdev, netdev_tx_complete_next_err(), net_device::tx_deferred, and net_device::tx_queue.

Referenced by free_netdev(), and netdev_close().

◆ netdev_rx()

void netdev_rx ( struct net_device netdev,
struct io_buffer iobuf 
)

Add packet to receive queue.

Parameters
netdevNetwork device
iobufI/O buffer, or NULL

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

Definition at line 470 of file netdevice.c.

470  {
471  int rc;
472 
473  DBGC2 ( netdev, "NETDEV %s received %p (%p+%zx)\n",
474  netdev->name, iobuf, iobuf->data, iob_len ( iobuf ) );
475 
476  /* Discard packet (for test purposes) if applicable */
477  if ( ( rc = inject_fault ( NETDEV_DISCARD_RATE ) ) != 0 ) {
478  netdev_rx_err ( netdev, iobuf, rc );
479  return;
480  }
481 
482  /* Enqueue packet */
483  list_add_tail ( &iobuf->list, &netdev->rx_queue );
484 
485  /* Update statistics counter */
487 }
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:501
#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:415
#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
struct net_device_stats rx_stats
RX statistics.
Definition: netdevice.h:419
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:358
struct list_head list
List of which this buffer is a member.
Definition: iobuf.h:39
#define DBGC2(...)
Definition: compiler.h:522
void * data
Start of data.
Definition: iobuf.h:44

References io_buffer::data, DBGC2, iob_len(), io_buffer::list, list_add_tail, 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(), 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(), 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(), 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.

Definition at line 501 of file netdevice.c.

502  {
503 
504  DBGC ( netdev, "NETDEV %s failed to receive %p: %s\n",
505  netdev->name, iobuf, strerror ( rc ) );
506 
507  /* Discard packet */
508  free_iob ( iobuf );
509 
510  /* Update statistics counter */
512 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
#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 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:419
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:358

References DBGC, free_iob(), 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(), 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(), 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(), 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 523 of file netdevice.c.

523  {
524 
525  if ( netdev_is_open ( netdev ) )
526  netdev->op->poll ( netdev );
527 }
struct net_device_operations * op
Network device operations.
Definition: netdevice.h:363
void(* poll)(struct net_device *netdev)
Poll for completed and received packets.
Definition: netdevice.h:263
static int netdev_is_open(struct net_device *netdev)
Check whether or not network device is open.
Definition: netdevice.h:652
static struct net_device * netdev
Definition: gdbudp.c:52

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

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

538  {
539  struct io_buffer *iobuf;
540 
541  iobuf = list_first_entry ( &netdev->rx_queue, struct io_buffer, list );
542  if ( ! iobuf )
543  return NULL;
544 
545  list_del ( &iobuf->list );
546  return iobuf;
547 }
struct list_head rx_queue
RX packet queue.
Definition: netdevice.h:415
#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:39
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
A persistent I/O buffer.
Definition: iobuf.h:32

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().

◆ netdev_rx_flush()

static void netdev_rx_flush ( struct net_device netdev)
static

Flush device's receive queue.

Parameters
netdevNetwork device

Definition at line 554 of file netdevice.c.

554  {
555  struct io_buffer *iobuf;
556 
557  /* Discard any packets in the RX queue */
558  while ( ( iobuf = netdev_rx_dequeue ( netdev ) ) ) {
559  netdev_rx_err ( netdev, iobuf, -ECANCELED );
560  }
561 }
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:501
#define ECANCELED
Operation canceled.
Definition: errno.h:343
static struct net_device * netdev
Definition: gdbudp.c:52
struct io_buffer * netdev_rx_dequeue(struct net_device *netdev)
Remove packet from device's receive queue.
Definition: netdevice.c:538
A persistent I/O buffer.
Definition: iobuf.h:32

References ECANCELED, netdev, netdev_rx_dequeue(), and netdev_rx_err().

Referenced by free_netdev(), and netdev_close().

◆ netdev_config_close()

static void netdev_config_close ( struct net_device_configuration config,
int  rc 
)
static

Finish network device configuration.

Parameters
configNetwork device configuration
rcReason for completion

Definition at line 569 of file netdevice.c.

570  {
571  struct net_device_configurator *configurator = config->configurator;
572  struct net_device *netdev = config->netdev;
573 
574  /* Restart interface */
575  intf_restart ( &config->job, rc );
576 
577  /* Record configuration result */
578  config->rc = rc;
579  if ( rc == 0 ) {
580  DBGC ( netdev, "NETDEV %s configured via %s\n",
581  netdev->name, configurator->name );
582  } else {
583  DBGC ( netdev, "NETDEV %s configuration via %s failed: %s\n",
584  netdev->name, configurator->name, strerror ( rc ) );
585  }
586 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Name.
Definition: netdevice.h:311
void intf_restart(struct interface *intf, int rc)
Shut down and restart an object interface.
Definition: interface.c:337
struct interface job
Job control interface.
Definition: netdevice.h:305
#define DBGC(...)
Definition: compiler.h:505
static struct net_device * netdev
Definition: gdbudp.c:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
A network device.
Definition: netdevice.h:348
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:358
struct net_device * netdev
Network device.
Definition: netdevice.h:299
int rc
Configuration status.
Definition: netdevice.h:303
A network device configurator.
Definition: netdevice.h:309
struct net_device_configurator * configurator
Network device configurator.
Definition: netdevice.h:301

References net_device_configuration::configurator, DBGC, intf_restart(), net_device_configuration::job, net_device_configurator::name, net_device::name, netdev, net_device_configuration::netdev, net_device_configuration::rc, rc, and strerror().

◆ free_netdev()

static void free_netdev ( struct refcnt refcnt)
static

Free network device.

Parameters
refcntNetwork device reference counter

Definition at line 603 of file netdevice.c.

603  {
604  struct net_device *netdev =
605  container_of ( refcnt, struct net_device, refcnt );
606 
611  free ( netdev );
612 }
struct retry_timer link_block
Link block timer.
Definition: netdevice.h:397
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition: netdevice.h:577
A reference counter.
Definition: refcnt.h:26
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
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:554
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
A network device.
Definition: netdevice.h:348
void stop_timer(struct retry_timer *timer)
Stop timer.
Definition: retry.c:117
void clear_settings(struct settings *settings)
Clear settings block.
Definition: settings.c:1106
static void netdev_tx_flush(struct net_device *netdev)
Flush device's transmit queue.
Definition: netdevice.c:448

References clear_settings(), container_of, free, net_device::link_block, netdev, netdev_rx_flush(), netdev_settings(), netdev_tx_flush(), and stop_timer().

Referenced by alloc_netdev().

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

622  {
623  struct net_device *netdev;
624  struct net_device_configurator *configurator;
625  struct net_device_configuration *config;
626  unsigned int num_configs;
627  size_t confs_len;
628  size_t total_len;
629 
631  confs_len = ( num_configs * sizeof ( netdev->configs[0] ) );
632  total_len = ( sizeof ( *netdev ) + confs_len + priv_len );
633  netdev = zalloc ( total_len );
634  if ( netdev ) {
638  &netdev->refcnt );
643  config = netdev->configs;
645  config->netdev = netdev;
646  config->configurator = configurator;
647  config->rc = -EUNUSED_CONFIG;
648  intf_init ( &config->job, &netdev_config_desc,
649  &netdev->refcnt );
650  config++;
651  }
652  netdev->priv = ( ( ( void * ) netdev ) + sizeof ( *netdev ) +
653  confs_len );
654  }
655  return netdev;
656 }
static void netdev_settings_init(struct net_device *netdev)
Initialise a per-netdevice configuration settings block.
Definition: netdevice.h:589
#define EUNKNOWN_LINK_STATUS
Default unknown link status code.
Definition: netdevice.c:71
struct interface job
Job control interface.
Definition: netdevice.h:305
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
struct retry_timer link_block
Link block timer.
Definition: netdevice.h:397
struct list_head rx_queue
RX packet queue.
Definition: netdevice.h:415
#define EUNUSED_CONFIG
Default not-yet-attempted-configuration status code.
Definition: netdevice.c:76
int link_rc
Link status code.
Definition: netdevice.h:395
void * priv
Driver private data.
Definition: netdevice.h:425
struct list_head tx_queue
TX packet queue.
Definition: netdevice.h:411
struct net_device_configuration configs[0]
Network device configurations (variable length)
Definition: netdevice.h:428
static struct net_device * netdev
Definition: gdbudp.c:52
struct list_head tx_deferred
Deferred TX packet queue.
Definition: netdevice.h:413
static struct interface_descriptor netdev_config_desc
Network device configuration interface descriptor.
Definition: netdevice.c:595
struct refcnt refcnt
Reference counter.
Definition: netdevice.h:350
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:348
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:299
int rc
Configuration status.
Definition: netdevice.h:303
A network device configurator.
Definition: netdevice.h:309
struct net_device_configurator * configurator
Network device configurator.
Definition: netdevice.h:301
static void free_netdev(struct refcnt *refcnt)
Free network device.
Definition: netdevice.c:603
#define NET_DEVICE_CONFIGURATORS
Network device configurator table.
Definition: netdevice.h:328
A network device configuration.
Definition: netdevice.h:297
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:173
#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 667 of file netdevice.c.

667  {
669  struct net_driver *driver;
670  struct net_device *duplicate;
671  uint32_t seed;
672  int rc;
673 
674  /* Set initial link-layer address, if not already set */
675  if ( ! netdev_has_ll_addr ( netdev ) ) {
677  }
678 
679  /* Set MTU, if not already set */
680  if ( ! netdev->mtu ) {
681  netdev->mtu = ( netdev->max_pkt_len -
683  }
684 
685  /* Reject network devices that are already available via a
686  * different hardware device.
687  */
689  if ( duplicate && ( duplicate->dev != netdev->dev ) ) {
690  DBGC ( netdev, "NETDEV rejecting duplicate (phys %s) of %s "
691  "(phys %s)\n", netdev->dev->name, duplicate->name,
692  duplicate->dev->name );
693  rc = -EEXIST;
694  goto err_duplicate;
695  }
696 
697  /* Reject named network devices that already exist */
698  if ( netdev->name[0] && ( duplicate = find_netdev ( netdev->name ) ) ) {
699  DBGC ( netdev, "NETDEV rejecting duplicate name %s\n",
700  duplicate->name );
701  rc = -EEXIST;
702  goto err_duplicate;
703  }
704 
705  /* Record device index and create device name */
706  if ( netdev->name[0] == '\0' ) {
707  snprintf ( netdev->name, sizeof ( netdev->name ), "net%d",
708  netdev_index );
709  }
711 
712  /* Use least significant bits of the link-layer address to
713  * improve the randomness of the (non-cryptographic) random
714  * number generator.
715  */
717  - sizeof ( seed ) ), sizeof ( seed ) );
718  srand ( rand() ^ seed );
719 
720  /* Add to device list */
721  netdev_get ( netdev );
723  DBGC ( netdev, "NETDEV %s registered (phys %s hwaddr %s)\n",
724  netdev->name, netdev->dev->name,
725  netdev_addr ( netdev ) );
726 
727  /* Register per-netdev configuration settings */
729  NULL, netdev->name ) ) != 0 ) {
730  DBGC ( netdev, "NETDEV %s could not register settings: %s\n",
731  netdev->name, strerror ( rc ) );
732  goto err_register_settings;
733  }
734 
735  /* Probe device */
736  for_each_table_entry ( driver, NET_DRIVERS ) {
737  if ( driver->probe && ( rc = driver->probe ( netdev ) ) != 0 ) {
738  DBGC ( netdev, "NETDEV %s could not add %s device: "
739  "%s\n", netdev->name, driver->name,
740  strerror ( rc ) );
741  goto err_probe;
742  }
743  }
744 
745  return 0;
746 
747  err_probe:
749  if ( driver->remove )
750  driver->remove ( netdev );
751  }
754  err_register_settings:
755  list_del ( &netdev->list );
756  netdev_put ( netdev );
757  err_duplicate:
758  return rc;
759 }
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:409
struct list_head list
List of network devices.
Definition: netdevice.h:352
#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:521
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:461
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition: netdevice.h:577
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:463
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:555
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:479
#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:483
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:348
static struct net_device * netdev_get(struct net_device *netdev)
Get reference to network device.
Definition: netdevice.h:544
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:360
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:358
unsigned int index
Index of this network device.
Definition: netdevice.h:356
struct net_device * find_netdev(const char *name)
Get network device by name.
Definition: netdevice.c:893
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:469
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:381
size_t max_pkt_len
Maximum packet length.
Definition: netdevice.h:403
#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:375
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:366
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:954

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(), 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(), 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(), 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 767 of file netdevice.c.

767  {
768  int rc;
769 
770  /* Do nothing if device is already open */
771  if ( netdev->state & NETDEV_OPEN )
772  return 0;
773 
774  DBGC ( netdev, "NETDEV %s opening\n", netdev->name );
775 
776  /* Mark as opened */
778 
779  /* Open the device */
780  if ( ( rc = netdev->op->open ( netdev ) ) != 0 )
781  goto err;
782 
783  /* Add to head of open devices list */
785 
786  /* Notify drivers of device state change */
787  netdev_notify ( netdev );
788 
789  return 0;
790 
791  err:
792  netdev->state &= ~NETDEV_OPEN;
793  return rc;
794 }
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:432
#define DBGC(...)
Definition: compiler.h:505
unsigned int state
Current device state.
Definition: netdevice.h:389
struct net_device_operations * op
Network device operations.
Definition: netdevice.h:363
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:358
struct list_head open_list
List of open network devices.
Definition: netdevice.h:354
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 801 of file netdevice.c.

801  {
802  unsigned int num_configs;
803  unsigned int i;
804 
805  /* Do nothing if device is already closed */
806  if ( ! ( netdev->state & NETDEV_OPEN ) )
807  return;
808 
809  DBGC ( netdev, "NETDEV %s closing\n", netdev->name );
810 
811  /* Terminate any ongoing configurations. Use intf_close()
812  * rather than intf_restart() to allow the cancellation to be
813  * reported back to us if a configuration is actually in
814  * progress.
815  */
817  for ( i = 0 ; i < num_configs ; i++ )
819 
820  /* Remove from open devices list */
821  list_del ( &netdev->open_list );
822 
823  /* Mark as closed */
824  netdev->state &= ~NETDEV_OPEN;
825 
826  /* Notify drivers of device state change */
827  netdev_notify ( netdev );
828 
829  /* Close the device */
830  netdev->op->close ( netdev );
831 
832  /* Flush TX and RX queues */
835 }
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:244
#define NETDEV_OPEN
Network device is open.
Definition: netdevice.h:432
struct interface job
Job control interface.
Definition: netdevice.h:305
#define DBGC(...)
Definition: compiler.h:505
unsigned int state
Current device state.
Definition: netdevice.h:389
struct net_device_operations * op
Network device operations.
Definition: netdevice.h:363
#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:428
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:554
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:358
struct list_head open_list
List of open network devices.
Definition: netdevice.h:354
#define NET_DEVICE_CONFIGURATORS
Network device configurator table.
Definition: netdevice.h:328
static void netdev_tx_flush(struct net_device *netdev)
Flush device's transmit queue.
Definition: netdevice.c:448
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(), 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 844 of file netdevice.c.

844  {
845  struct net_driver *driver;
846 
847  /* Ensure device is closed */
848  netdev_close ( netdev );
849 
850  /* Remove device */
852  if ( driver->remove )
853  driver->remove ( netdev );
854  }
855 
856  /* Unregister per-netdev configuration settings */
859 
860  /* Remove from device list */
861  DBGC ( netdev, "NETDEV %s unregistered\n", netdev->name );
862  list_del ( &netdev->list );
863  netdev_put ( netdev );
864 
865  /* Reset network device index if no devices remain */
866  if ( list_empty ( &net_devices ) )
867  netdev_index = 0;
868 }
void unregister_settings(struct settings *settings)
Unregister settings block.
Definition: settings.c:517
struct list_head list
List of network devices.
Definition: netdevice.h:352
#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:461
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition: netdevice.h:577
#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:555
void(* remove)(struct net_device *netdev)
Remove device.
Definition: netdevice.h:479
static struct net_device * netdev
Definition: gdbudp.c:52
#define NET_DRIVERS
Network driver table.
Definition: netdevice.h:483
void netdev_close(struct net_device *netdev)
Close network device.
Definition: netdevice.c:801
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:358
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(), 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(), 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(), 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 875 of file netdevice.c.

875  {
876 
877  /* Enable or disable device interrupts, if applicable */
878  if ( netdev_irq_supported ( netdev ) )
879  netdev->op->irq ( netdev, enable );
880 
881  /* Record interrupt enabled state */
883  if ( enable )
885 }
unsigned int state
Current device state.
Definition: netdevice.h:389
struct net_device_operations * op
Network device operations.
Definition: netdevice.h:363
void(* irq)(struct net_device *netdev, int enable)
Enable or disable interrupts.
Definition: netdevice.h:272
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:663
#define NETDEV_IRQ_ENABLED
Network device interrupts are enabled.
Definition: netdevice.h:435

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

893  {
894  struct net_device *netdev;
895 
896  /* Allow "netX" shortcut */
897  if ( strcmp ( name, "netX" ) == 0 )
898  return last_opened_netdev();
899 
900  /* Identify network device by name */
902  if ( strcmp ( netdev->name, name ) == 0 )
903  return netdev;
904  }
905 
906  return NULL;
907 }
const char * name
Definition: ath9k_hw.c:1984
struct list_head list
List of network devices.
Definition: netdevice.h:352
#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:973
A network device.
Definition: netdevice.h:348
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:358
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:157
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 915 of file netdevice.c.

915  {
916  struct net_device *netdev;
917 
918  /* Identify network device by index */
920  if ( netdev->index == index )
921  return netdev;
922  }
923 
924  return NULL;
925 }
struct list_head list
List of network devices.
Definition: netdevice.h:352
#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:348
unsigned int index
Index of this network device.
Definition: netdevice.h:356
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 934 of file netdevice.c.

935  {
936  struct net_device *netdev;
937 
939  if ( ( netdev->dev->desc.bus_type == bus_type ) &&
940  ( netdev->dev->desc.location == location ) )
941  return netdev;
942  }
943 
944  return NULL;
945 }
struct list_head list
List of network devices.
Definition: netdevice.h:352
#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:348
struct device * dev
Underlying hardware device.
Definition: netdevice.h:360
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 954 of file netdevice.c.

955  {
956  struct net_device *netdev;
957 
959  if ( ( netdev->ll_protocol == ll_protocol ) &&
961  ll_protocol->ll_addr_len ) == 0 ) )
962  return netdev;
963  }
964 
965  return NULL;
966 }
uint8_t ll_addr_len
Link-layer address length.
Definition: netdevice.h:198
struct list_head list
List of network devices.
Definition: netdevice.h:352
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:348
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:381
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:98
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:366

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

973  {
974  struct net_device *netdev;
975 
977  open_list );
978  if ( ! netdev )
979  return NULL;
980 
981  assert ( netdev_is_open ( netdev ) );
982  return netdev;
983 }
#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:652
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:348
struct list_head open_list
List of open network devices.
Definition: netdevice.h:354
#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 999 of file netdevice.c.

1001  {
1003  int rc;
1004 
1005  /* Add link-layer header */
1006  if ( ( rc = ll_protocol->push ( netdev, iobuf, ll_dest, ll_source,
1007  net_protocol->net_proto ) ) != 0 ) {
1008  /* Record error for diagnosis */
1009  netdev_tx_err ( netdev, iobuf, rc );
1010  return rc;
1011  }
1012 
1013  /* Transmit packet */
1014  return netdev_tx ( netdev, iobuf );
1015 }
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:369
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:366

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

1030  {
1031  struct net_protocol *net_protocol;
1032 
1033  /* Hand off to network-layer protocol, if any */
1035  if ( net_protocol->net_proto == net_proto )
1036  return net_protocol->rx ( iobuf, netdev, ll_dest,
1037  ll_source, flags );
1038  }
1039 
1040  DBGC ( netdev, "NETDEV %s unknown network protocol %04x\n",
1041  netdev->name, ntohs ( net_proto ) );
1042  free_iob ( iobuf );
1043  return -ENOTSUP;
1044 }
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
#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:455
#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:358
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 1052 of file netdevice.c.

1052  {
1053  struct net_device *netdev;
1054  struct io_buffer *iobuf;
1055  struct ll_protocol *ll_protocol;
1056  const void *ll_dest;
1057  const void *ll_source;
1058  uint16_t net_proto;
1059  unsigned int flags;
1060  int rc;
1061 
1062  /* Poll and process each network device */
1063  list_for_each_entry ( netdev, &net_devices, list ) {
1064 
1065  /* Poll for new packets */
1066  profile_start ( &net_poll_profiler );
1067  netdev_poll ( netdev );
1068  profile_stop ( &net_poll_profiler );
1069 
1070  /* Leave received packets on the queue if receive
1071  * queue processing is currently frozen. This will
1072  * happen when the raw packets are to be manually
1073  * dequeued using netdev_rx_dequeue(), rather than
1074  * processed via the usual networking stack.
1075  */
1076  if ( netdev_rx_frozen ( netdev ) )
1077  continue;
1078 
1079  /* Process all received packets */
1080  while ( ( iobuf = netdev_rx_dequeue ( netdev ) ) ) {
1081 
1082  DBGC2 ( netdev, "NETDEV %s processing %p (%p+%zx)\n",
1083  netdev->name, iobuf, iobuf->data,
1084  iob_len ( iobuf ) );
1085  profile_start ( &net_rx_profiler );
1086 
1087  /* Remove link-layer header */
1089  if ( ( rc = ll_protocol->pull ( netdev, iobuf,
1090  &ll_dest, &ll_source,
1091  &net_proto,
1092  &flags ) ) != 0 ) {
1093  free_iob ( iobuf );
1094  continue;
1095  }
1096 
1097  /* Hand packet to network layer */
1098  if ( ( rc = net_rx ( iob_disown ( iobuf ), netdev,
1099  net_proto, ll_dest,
1100  ll_source, flags ) ) != 0 ) {
1101  /* Record error for diagnosis */
1102  netdev_rx_err ( netdev, NULL, rc );
1103  }
1104  profile_stop ( &net_rx_profiler );
1105  }
1106  }
1107 }
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:501
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
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:208
#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:523
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
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:1028
A network device.
Definition: netdevice.h:348
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:358
#define DBGC2(...)
Definition: compiler.h:522
void * data
Start of data.
Definition: iobuf.h:44
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:686
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:366
struct io_buffer * netdev_rx_dequeue(struct net_device *netdev)
Remove packet from device's receive queue.
Definition: netdevice.c:538
A persistent I/O buffer.
Definition: iobuf.h:32
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().

◆ net_step()

static void net_step ( struct process *process  __unused)
static

Single-step the network stack.

Parameters
processNetwork stack process

Definition at line 1114 of file netdevice.c.

1114  {
1115  net_poll();
1116 }
void net_poll(void)
Poll the network stack.
Definition: netdevice.c:1052

References net_poll().

◆ vlan_tag()

__weak unsigned int vlan_tag ( struct net_device *netdev  __unused)

Get the VLAN tag (when VLAN support is not present)

Parameters
netdevNetwork device
Return values
tag0, indicating that device is not a VLAN device

Definition at line 1124 of file netdevice.c.

1124  {
1125  return 0;
1126 }

Referenced by efi_snp_probe(), and ibft_fill_nic().

◆ vlan_netdev_rx()

__weak void vlan_netdev_rx ( struct net_device netdev,
unsigned int  tag,
struct io_buffer iobuf 
)

Add VLAN tag-stripped packet to queue (when VLAN support is not present)

Parameters
netdevNetwork device
tagVLAN tag, or zero
iobufI/O buffer

Definition at line 1135 of file netdevice.c.

1136  {
1137 
1138  if ( tag == 0 ) {
1139  netdev_rx ( netdev, iobuf );
1140  } else {
1141  netdev_rx_err ( netdev, iobuf, -ENODEV );
1142  }
1143 }
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:501
static struct net_device * netdev
Definition: gdbudp.c:52
#define ENODEV
No such device.
Definition: errno.h:509
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition: netdevice.c:470
uint64_t tag
Identity tag.
Definition: edd.h:30

Referenced by hermon_eth_complete_recv(), and intelxl_poll_rx().

◆ vlan_netdev_rx_err()

__weak void vlan_netdev_rx_err ( struct net_device netdev,
unsigned int tag  __unused,
struct io_buffer iobuf,
int  rc 
)

Discard received VLAN tag-stripped packet (when VLAN support is not present)

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

Definition at line 1153 of file netdevice.c.

1155  {
1156 
1157  netdev_rx_err ( netdev, iobuf, rc );
1158 }
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:501
static struct net_device * netdev
Definition: gdbudp.c:52

Referenced by hermon_eth_complete_recv(), and intelxl_poll_rx().

◆ PERMANENT_PROCESS()

PERMANENT_PROCESS ( net_process  ,
net_step   
)

Networking stack process.

◆ net_discard()

static unsigned int net_discard ( void  )
static

Discard some cached network device data.

Return values
discardedNumber of cached items discarded

Definition at line 1168 of file netdevice.c.

1168  {
1169  struct net_device *netdev;
1170  struct io_buffer *iobuf;
1171  unsigned int discarded = 0;
1172 
1173  /* Try to drop one deferred TX packet from each network device */
1174  for_each_netdev ( netdev ) {
1175  if ( ( iobuf = list_first_entry ( &netdev->tx_deferred,
1176  struct io_buffer,
1177  list ) ) != NULL ) {
1178 
1179  /* Discard first deferred packet */
1180  list_del ( &iobuf->list );
1181  free_iob ( iobuf );
1182 
1183  /* Report discard */
1184  discarded++;
1185  }
1186  }
1187 
1188  return discarded;
1189 }
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
#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 tx_deferred
Deferred TX packet queue.
Definition: netdevice.h:413
#define for_each_netdev(netdev)
Iterate over all network devices.
Definition: netdevice.h:526
A network device.
Definition: netdevice.h:348
struct list_head list
List of which this buffer is a member.
Definition: iobuf.h:39
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
A persistent I/O buffer.
Definition: iobuf.h:32

References for_each_netdev, free_iob(), io_buffer::list, list_del, list_first_entry, netdev, NULL, and net_device::tx_deferred.

◆ __cache_discarder()

struct cache_discarder net_discarder __cache_discarder ( CACHE_NORMAL  )

Network device cache discarder.

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

1202  {
1203  struct net_device_configurator *configurator;
1204 
1206  if ( strcmp ( configurator->name, name ) == 0 )
1207  return configurator;
1208  }
1209  return NULL;
1210 }
const char * name
Definition: ath9k_hw.c:1984
const char * name
Name.
Definition: netdevice.h:311
#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:157
A network device configurator.
Definition: netdevice.h:309
#define NET_DEVICE_CONFIGURATORS
Network device configurator table.
Definition: netdevice.h:328
#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 1219 of file netdevice.c.

1220  {
1221  struct net_device_configuration *config =
1223  int rc;
1224 
1225  /* Check applicability of configurator */
1227  DBGC ( netdev, "NETDEV %s does not support configuration via "
1228  "%s\n", netdev->name, configurator->name );
1229  return -ENOTSUP;
1230  }
1231 
1232  /* Terminate any ongoing configuration */
1233  intf_restart ( &config->job, -ECANCELED );
1234 
1235  /* Mark configuration as being in progress */
1236  config->rc = -EINPROGRESS_CONFIG;
1237 
1238  DBGC ( netdev, "NETDEV %s starting configuration via %s\n",
1240 
1241  /* Start configuration */
1242  if ( ( rc = configurator->start ( &config->job, netdev ) ) != 0 ) {
1243  DBGC ( netdev, "NETDEV %s could not start configuration via "
1244  "%s: %s\n", netdev->name, configurator->name,
1245  strerror ( rc ) );
1246  config->rc = rc;
1247  return rc;
1248  }
1249 
1250  return 0;
1251 }
#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:311
void intf_restart(struct interface *intf, int rc)
Shut down and restart an object interface.
Definition: interface.c:337
int(* start)(struct interface *job, struct net_device *netdev)
Start configuring network device.
Definition: netdevice.h:324
struct interface job
Job control interface.
Definition: netdevice.h:305
#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:617
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:358
int rc
Configuration status.
Definition: netdevice.h:303
struct net_device_configurator * configurator
Network device configurator.
Definition: netdevice.h:301
A network device configuration.
Definition: netdevice.h:297
static struct net_device_configuration * netdev_configuration(struct net_device *netdev, struct net_device_configurator *configurator)
Get network device configuration.
Definition: netdevice.h:602

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

1259  {
1260  struct net_device_configurator *configurator;
1261  int rc;
1262 
1263  /* Start configuration for each configurator */
1265 
1266  /* Skip any inapplicable configurators */
1267  if ( ! netdev_configurator_applies ( netdev, configurator ) )
1268  continue;
1269 
1270  /* Start configuration */
1271  if ( ( rc = netdev_configure ( netdev, configurator ) ) != 0 )
1272  return rc;
1273  }
1274 
1275  return 0;
1276 }
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:1219
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:617
A network device configurator.
Definition: netdevice.h:309
#define NET_DEVICE_CONFIGURATORS
Network device configurator table.
Definition: netdevice.h:328

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

Referenced by efi_pxe_dhcp(), and ifconf().

◆ netdev_has_configuration_rc()

static int netdev_has_configuration_rc ( struct net_device netdev,
int  rc 
)
static

Check if network device has a configuration with a specified status code.

Parameters
netdevNetwork device
rcStatus code
Return values
has_rcNetwork device has a configuration with this status code

Definition at line 1285 of file netdevice.c.

1285  {
1286  unsigned int num_configs;
1287  unsigned int i;
1288 
1289  num_configs = table_num_entries ( NET_DEVICE_CONFIGURATORS );
1290  for ( i = 0 ; i < num_configs ; i++ ) {
1291  if ( netdev->configs[i].rc == rc )
1292  return 1;
1293  }
1294  return 0;
1295 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct net_device_configuration configs[0]
Network device configurations (variable length)
Definition: netdevice.h:428
static struct net_device * netdev
Definition: gdbudp.c:52
int rc
Configuration status.
Definition: netdevice.h:303
#define NET_DEVICE_CONFIGURATORS
Network device configurator table.
Definition: netdevice.h:328
#define table_num_entries(table)
Get number of entries in linker table.
Definition: tables.h:308

References net_device::configs, NET_DEVICE_CONFIGURATORS, netdev, net_device_configuration::rc, rc, and table_num_entries.

Referenced by netdev_configuration_in_progress(), and netdev_configuration_ok().

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

1303  {
1304 
1306 }
#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:1285

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

1315  {
1316 
1317  return netdev_has_configuration_rc ( netdev, 0 );
1318 }
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:1285

References netdev, and netdev_has_configuration_rc().

Referenced by efi_pxe_dhcp(), and ifconf_progress().

Variable Documentation

◆ net_devices

struct list_head net_devices = LIST_HEAD_INIT ( net_devices )

◆ open_net_devices

struct list_head open_net_devices = LIST_HEAD_INIT ( open_net_devices )
static

List of open network devices, in reverse order of opening.

Definition at line 56 of file netdevice.c.

Referenced by last_opened_netdev(), and netdev_open().

◆ netdev_index

unsigned int netdev_index = 0
static

Network device index.

Definition at line 59 of file netdevice.c.

Referenced by register_netdev(), and unregister_netdev().

◆ __profiler

struct profiler net_tx_profiler __profiler = { .name = "net.poll" }
static

Network polling profiler.

Network transmit profiler.

Network receive profiler.

Definition at line 62 of file netdevice.c.

◆ __errortab

struct errortab netdev_errors [] __errortab
Initial value:
= {
}
#define EINFO_EINPROGRESS_CONFIG
Definition: netdevice.c:82
#define __einfo_errortab(einfo)
Definition: errortab.h:23
#define EINFO_ENOTCONN_LINK_DOWN
Definition: netdevice.c:87
#define EINFO_EUNKNOWN_LINK_STATUS
Definition: netdevice.c:72
#define EINFO_EUNUSED_CONFIG
Definition: netdevice.c:77

Human-readable message for the default link statuses.

Definition at line 91 of file netdevice.c.

◆ netdev_config_ops

struct interface_operation netdev_config_ops[]
static
Initial value:
= {
}
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:244
static void netdev_config_close(struct net_device_configuration *config, int rc)
Finish network device configuration.
Definition: netdevice.c:569
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32
A network device configuration.
Definition: netdevice.h:297

Network device configuration interface operations.

Definition at line 589 of file netdevice.c.

◆ netdev_config_desc

struct interface_descriptor netdev_config_desc
static
Initial value:
=
static struct interface_operation netdev_config_ops[]
Network device configuration interface operations.
Definition: netdevice.c:589
#define INTF_DESC(object_type, intf, operations)
Define an object interface descriptor.
Definition: interface.h:65
A network device configuration.
Definition: netdevice.h:297

Network device configuration interface descriptor.

Definition at line 595 of file netdevice.c.

Referenced by alloc_netdev().