69#define EUNKNOWN_LINK_STATUS __einfo_error ( EINFO_EUNKNOWN_LINK_STATUS )
70#define EINFO_EUNKNOWN_LINK_STATUS \
71 __einfo_uniqify ( EINFO_EINPROGRESS, 0x01, "Unknown" )
74#define EUNUSED_CONFIG __einfo_error ( EINFO_EUNUSED_CONFIG )
75#define EINFO_EUNUSED_CONFIG \
76 __einfo_uniqify ( EINFO_EINPROGRESS, 0x02, "Unused" )
79#define EINPROGRESS_CONFIG __einfo_error ( EINFO_EINPROGRESS_CONFIG )
80#define EINFO_EINPROGRESS_CONFIG \
81 __einfo_uniqify ( EINFO_EINPROGRESS, 0x03, "Incomplete" )
84#define ENOTCONN_LINK_DOWN __einfo_error ( EINFO_ENOTCONN_LINK_DOWN )
85#define EINFO_ENOTCONN_LINK_DOWN \
86 __einfo_uniqify ( EINFO_ENOTCONN, 0x01, "Down" )
104 size_t remaining =
sizeof (
netdev->ll_addr );
106 while ( remaining-- ) {
107 if ( *(ll_addr++) != 0 )
121 unsigned int num_configs;
125 offset =
sizeof ( *netdev );
129 offset += ( num_configs *
sizeof (
netdev->configs[0] ) );
215 if (
netdev->link_rc == 0 ) {
218 DBGC (
netdev,
"NETDEV %s link is down: %s\n",
236 if ( (
netdev->link_rc == 0 ) ||
252 DBGC (
netdev,
"NETDEV %s link blocked for %ld ticks\n",
307 least_common_error = &stats->
errors[0];
308 for ( i = 0 ; i < (
sizeof ( stats->
errors ) /
309 sizeof ( stats->
errors[0] ) ) ; i++ ) {
316 if (
error->count < least_common_error->
count )
317 least_common_error =
error;
321 least_common_error->
rc =
rc;
322 least_common_error->
count = 1;
338 DBGC2 (
netdev,
"NETDEV %s transmitting %p (%p+%zx)\n",
447 DBGC2 (
netdev,
"NETDEV %s transmission %p complete\n",
450 DBGC (
netdev,
"NETDEV %s transmission %p failed: %s\n",
552 DBGC2 (
netdev,
"NETDEV %s received %p (%p+%zx)\n",
590 DBGC (
netdev,
"NETDEV %s failed to receive %p: %s\n",
680 DBGC (
netdev,
"NETDEV %s configured via %s\n",
683 DBGC (
netdev,
"NETDEV %s configuration via %s failed: %s\n",
782 DBGC (
netdev,
"NETDEV rejecting duplicate name %s\n",
789 if (
netdev->name[0] ==
'\0' ) {
790 for ( i = 0 ; ; i++ ) {
809 - sizeof ( seed ) ),
sizeof ( seed ) );
815 DBGC (
netdev,
"NETDEV %s registered (phys %s hwaddr %s)\n",
822 DBGC (
netdev,
"NETDEV %s could not register settings: %s\n",
824 goto err_register_settings;
830 if ( driver->
probe &&
832 DBGC (
netdev,
"NETDEV %s could not add %s device: "
849 err_register_settings:
897 unsigned int num_configs;
912 for ( i = 0 ; i < num_configs ; i++ )
1031 unsigned int location ) {
1035 if ( (
netdev->dev->desc.bus_type == bus_type ) &&
1036 (
netdev->dev->desc.location == location ) )
1076 const void *ll_source ) {
1104 uint16_t net_proto,
const void *ll_dest,
const void *ll_source,
1105 unsigned int flags ) {
1115 DBGC (
netdev,
"NETDEV %s unknown network protocol %04x\n",
1131 const void *ll_dest;
1132 const void *ll_source;
1157 DBGC2 (
netdev,
"NETDEV %s processing %p (%p+%zx)\n",
1165 &ll_dest, &ll_source,
1175 ll_source,
flags ) ) != 0 ) {
1246 unsigned int discarded = 0;
1284 return configurator;
1304 DBGC (
netdev,
"NETDEV %s does not support configuration via "
1315 DBGC (
netdev,
"NETDEV %s starting configuration via %s\n",
1320 DBGC (
netdev,
"NETDEV %s could not start configuration via "
1363 unsigned int num_configs;
1367 for ( i = 0 ; i < num_configs ; i++ ) {
#define NULL
NULL pointer (VOID *)
struct arbelprm_rc_send_wqe rc
struct arbelprm_completion_with_error error
#define assert(condition)
Assert a condition at run-time.
uint16_t offset
Offset to command line.
#define NETDEV_DISCARD_RATE
uint64_t tag
Identity tag.
#define __einfo_errortab(einfo)
#define EINFO_EUNKNOWN_LINK_STATUS
#define EUNKNOWN_LINK_STATUS
Default link status code.
static struct net_device * netdev
#define __unused
Declare a variable or data structure as unused.
#define CACHE_NORMAL
Items with a normal replacement cost.
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
#define EEXIST
File exists.
#define ENETUNREACH
Network unreachable.
#define EBUSY
Device or resource busy.
#define ENOTSUP
Operation not supported.
#define ECANCELED
Operation canceled.
#define ENOBUFS
No buffer space available.
#define ENODEV
No such device.
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
#define __weak
Declare a function as weak (use before the definition)
#define __profiler
Declare a profiler.
static void profile_stop(struct profiler *profiler)
Stop profiling.
static void profile_start(struct profiler *profiler)
Start profiling.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void intf_close(struct interface *intf, int rc)
Close an object interface.
void intf_restart(struct interface *intf, int rc)
Shut down and restart an object interface.
#define INTF_DESC(object_type, intf, operations)
Define an object interface descriptor.
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
static __always_inline void iob_unmap(struct io_buffer *iobuf)
Unmap I/O buffer for DMA.
static __always_inline int iob_map_tx(struct io_buffer *iobuf, struct dma_device *dma)
Map I/O buffer for transmit DMA.
#define iob_disown(iobuf)
Disown an I/O buffer.
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
static __always_inline int dma_mapped(struct dma_mapping *map)
Check if DMA unmapping is required.
#define list_first_entry(list, type, member)
Get the container of the first entry in a list.
#define LIST_HEAD_INIT(list)
Initialise a static list head.
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
#define list_del(list)
Delete an entry from a list.
#define INIT_LIST_HEAD(list)
Initialise a list head.
#define list_empty(list)
Test whether a list is empty.
#define list_check_contains_entry(entry, head, member)
Check list contains a specified entry.
#define list_add(new, head)
Add a new entry to the head of a list.
void * zalloc(size_t size)
Allocate cleared memory.
Dynamic memory allocation.
#define __cache_discarder(cost)
Declare a cache discarder.
void netdev_rx_unfreeze(struct net_device *netdev)
Unfreeze network device receive queue processing.
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.
void netdev_link_err(struct net_device *netdev, int rc)
Mark network device as having a specific link state.
int netdev_configure_all(struct net_device *netdev)
Start network device configuration via all supported configurators.
#define EINFO_EUNUSED_CONFIG
__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)
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
__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)
struct net_device * find_netdev_by_scope_id(unsigned int scope_id)
Get network device by scope ID.
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
struct net_device * last_opened_netdev(void)
Get most recently opened network device.
#define EINFO_ENOTCONN_LINK_DOWN
static void net_step(struct process *process __unused)
Single-step the network stack.
void netdev_tx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard transmitted packet.
void unregister_netdev(struct net_device *netdev)
Unregister network device.
static void netdev_link_block_expired(struct retry_timer *timer, int fail __unused)
Handle network device link block timer expiry.
struct io_buffer * netdev_rx_dequeue(struct net_device *netdev)
Remove packet from device's receive queue.
int netdev_configuration_ok(struct net_device *netdev)
Check if network device has at least one successful configuration.
static struct list_head open_net_devices
List of open network devices, in reverse order of opening.
void netdev_tx_defer(struct net_device *netdev, struct io_buffer *iobuf)
Defer transmitted packet.
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
struct list_head net_devices
List of network devices.
void * netdev_priv(struct net_device *netdev, struct net_driver *driver)
Get network device driver private data.
static void free_netdev(struct refcnt *refcnt)
Free network device.
void netdev_rx_freeze(struct net_device *netdev)
Freeze network device receive queue processing.
struct net_device * alloc_netdev(size_t priv_len)
Allocate network device.
int netdev_open(struct net_device *netdev)
Open network device.
#define EINPROGRESS_CONFIG
Default configuration-in-progress status code.
static int netdev_has_ll_addr(struct net_device *netdev)
Check whether or not network device has a link-layer address.
void netdev_link_block(struct net_device *netdev, unsigned long timeout)
Mark network device link as being blocked.
static struct interface_descriptor netdev_config_desc
Network device configuration interface descriptor.
void netdev_tx_complete_next_err(struct net_device *netdev, int rc)
Complete network transmission.
void netdev_close(struct net_device *netdev)
Close network device.
void net_poll(void)
Poll the network stack.
static void netdev_record_stat(struct net_device_stats *stats, int rc)
Record network device statistic.
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
int register_netdev(struct net_device *netdev)
Register network device.
void netdev_link_unblock(struct net_device *netdev)
Mark network device link as being unblocked.
static void netdev_tx_flush(struct net_device *netdev)
Flush device's transmit queue.
static void netdev_notify(struct net_device *netdev)
Notify drivers of network device or link state change.
static void netdev_rx_flush(struct net_device *netdev)
Flush device's receive queue.
void netdev_irq(struct net_device *netdev, int enable)
Enable or disable interrupts.
struct net_device_configurator * find_netdev_configurator(const char *name)
Find network device configurator.
#define EINFO_EINPROGRESS_CONFIG
#define ENOTCONN_LINK_DOWN
Default link-down status code.
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.
__weak unsigned int vlan_tci(struct net_device *netdev __unused)
Get the VLAN tag control information (when VLAN support is not present)
static unsigned int net_discard(void)
Discard some cached network device data.
struct net_device * find_netdev(const char *name)
Get network device by name.
static struct interface_operation netdev_config_ops[]
Network device configuration interface operations.
int netdev_configure(struct net_device *netdev, struct net_device_configurator *configurator)
Start network device configuration.
#define EUNUSED_CONFIG
Default not-yet-attempted-configuration status code.
void netdev_poll(struct net_device *netdev)
Poll for completed and received packets on network device.
static int netdev_has_configuration_rc(struct net_device *netdev, int rc)
Check if network device has a configuration with a specified status code.
struct net_device * find_netdev_by_location(unsigned int bus_type, unsigned int location)
Get network device by PCI bus:dev.fn address.
static void netdev_config_close(struct net_device_configuration *config, int rc)
Finish network device configuration.
static size_t netdev_priv_offset(struct net_driver *driver)
Get offset of network device driver private data.
int netdev_configuration_in_progress(struct net_device *netdev)
Check if network device configuration is in progress.
int netdev_tx(struct net_device *netdev, struct io_buffer *iobuf)
Transmit raw packet via network device.
Network device management.
static int netdev_link_blocked(struct net_device *netdev)
Check link block state of network device.
#define for_each_netdev(netdev)
Iterate over all network devices.
static struct net_device * netdev_get(struct net_device *netdev)
Get reference to network device.
static void netdev_settings_init(struct net_device *netdev)
Initialise a per-netdevice configuration settings block.
#define NETDEV_RX_FROZEN
Network device receive queue processing is frozen.
#define NETDEV_TX_IN_PROGRESS
Network device transmission is in progress.
static int netdev_is_open(struct net_device *netdev)
Check whether or not network device is open.
static int netdev_irq_supported(struct net_device *netdev)
Check whether or not network device supports interrupts.
#define NET_DRIVERS
Network driver table.
#define NETDEV_INSOMNIAC
Network device must be polled even when closed.
#define NET_PROTOCOLS
Network-layer protocol table.
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
static int netdev_rx_frozen(struct net_device *netdev)
Check whether or not network device receive queue processing is frozen.
static const char * netdev_addr(struct net_device *netdev)
Get printable network device link-layer address.
#define NETDEV_IRQ_ENABLED
Network device interrupts are enabled.
#define NETDEV_POLL_IN_PROGRESS
Network device poll is in progress.
#define NET_DEVICE_CONFIGURATORS
Network device configurator table.
static struct net_device_configuration * netdev_configuration(struct net_device *netdev, struct net_device_configurator *configurator)
Get network device configuration.
static int netdev_configurator_applies(struct net_device *netdev, struct net_device_configurator *configurator)
Check if configurator applies to network device.
#define NETDEV_OPEN
Network device is open.
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
#define PERMANENT_PROCESS(name, step)
Define a permanent process.
static void(* free)(struct refcnt *refcnt))
#define ref_init(refcnt, free)
Initialise a reference counter.
void start_timer_fixed(struct retry_timer *timer, unsigned long timeout)
Start timer with a specified timeout.
void stop_timer(struct retry_timer *timer)
Stop timer.
int register_settings(struct settings *settings, struct settings *parent, const char *name)
Register settings block.
void clear_settings(struct settings *settings)
Clear settings block.
void unregister_settings(struct settings *settings)
Unregister settings block.
#define container_of(ptr, type, field)
Get containing structure.
static void srand(unsigned int seed)
char * strerror(int errno)
Retrieve string representation of error number.
int strcmp(const char *first, const char *second)
Compare strings.
An object interface descriptor.
An object interface operation.
void * data
Start of data.
struct list_head list
List of which this buffer is a member.
struct dma_mapping map
DMA mapping.
A doubly-linked list entry (or list head)
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.
void(* init_addr)(const void *hw_addr, void *ll_addr)
Initialise link-layer address.
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.
uint8_t ll_addr_len
Link-layer address length.
uint8_t ll_header_len
Link-layer header length.
A network device configuration.
int rc
Configuration status.
struct net_device_configurator * configurator
Network device configurator.
struct net_device * netdev
Network device.
struct interface job
Job control interface.
A network device configurator.
int(* start)(struct interface *job, struct net_device *netdev)
Start configuring network device.
unsigned int count
Error count.
Network device statistics.
unsigned int good
Count of successful completions.
struct net_device_error errors[NETDEV_MAX_UNIQUE_ERRORS]
Error breakdowns.
unsigned int bad
Count of error completions.
char name[NETDEV_NAME_LEN]
Name of this network device.
struct list_head open_list
List of open network devices.
struct retry_timer link_block
Link block timer.
struct list_head list
List of network devices.
unsigned int scope_id
Scope ID.
A network upper-layer driver.
int(* probe)(struct net_device *netdev, void *priv)
Probe device.
size_t priv_len
Size of private data.
void(* remove)(struct net_device *netdev, void *priv)
Remove device.
void(* notify)(struct net_device *netdev, void *priv)
Notify of device or link state change.
A network-layer protocol.
uint16_t net_proto
Network-layer protocol.
int(* rx)(struct io_buffer *iobuf, struct net_device *netdev, const void *ll_dest, const void *ll_source, unsigned int flags)
Process received packet.
A data structure for storing profiling information.
#define for_each_table_entry_continue_reverse(pointer, table)
Iterate through all remaining entries within a linker table in reverse order.
#define table_end(table)
Get end of linker table.
#define table_num_entries(table)
Get number of entries in linker table.
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
#define for_each_table_entry_reverse(pointer, table)
Iterate through all entries within a linker table in reverse order.
static struct tlan_private * priv
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.