68 #define EUNKNOWN_LINK_STATUS __einfo_error ( EINFO_EUNKNOWN_LINK_STATUS ) 69 #define EINFO_EUNKNOWN_LINK_STATUS \ 70 __einfo_uniqify ( EINFO_EINPROGRESS, 0x01, "Unknown" ) 73 #define EUNUSED_CONFIG __einfo_error ( EINFO_EUNUSED_CONFIG ) 74 #define EINFO_EUNUSED_CONFIG \ 75 __einfo_uniqify ( EINFO_EINPROGRESS, 0x02, "Unused" ) 78 #define EINPROGRESS_CONFIG __einfo_error ( EINFO_EINPROGRESS_CONFIG ) 79 #define EINFO_EINPROGRESS_CONFIG \ 80 __einfo_uniqify ( EINFO_EINPROGRESS, 0x03, "Incomplete" ) 83 #define ENOTCONN_LINK_DOWN __einfo_error ( EINFO_ENOTCONN_LINK_DOWN ) 84 #define EINFO_ENOTCONN_LINK_DOWN \ 85 __einfo_uniqify ( EINFO_ENOTCONN, 0x01, "Down" ) 105 while ( remaining-- ) {
106 if ( *(ll_addr++) != 0 )
120 unsigned int num_configs;
124 offset =
sizeof ( *netdev );
217 DBGC (
netdev,
"NETDEV %s link is down: %s\n",
251 DBGC (
netdev,
"NETDEV %s link blocked for %ld ticks\n",
306 least_common_error = &stats->
errors[0];
307 for ( i = 0 ; i < (
sizeof ( stats->
errors ) /
308 sizeof ( stats->
errors[0] ) ) ; i++ ) {
315 if (
error->count < least_common_error->
count )
316 least_common_error =
error;
320 least_common_error->
rc =
rc;
321 least_common_error->
count = 1;
337 DBGC2 (
netdev,
"NETDEV %s transmitting %p (%p+%zx)\n",
446 DBGC2 (
netdev,
"NETDEV %s transmission %p complete\n",
449 DBGC (
netdev,
"NETDEV %s transmission %p failed: %s\n",
551 DBGC2 (
netdev,
"NETDEV %s received %p (%p+%zx)\n",
589 DBGC (
netdev,
"NETDEV %s failed to receive %p: %s\n",
679 DBGC (
netdev,
"NETDEV %s configured via %s\n",
682 DBGC (
netdev,
"NETDEV %s configuration via %s failed: %s\n",
781 DBGC (
netdev,
"NETDEV rejecting duplicate name %s\n",
789 for ( i = 0 ; ; i++ ) {
808 - sizeof ( seed ) ),
sizeof ( seed ) );
814 DBGC (
netdev,
"NETDEV %s registered (phys %s hwaddr %s)\n",
821 DBGC (
netdev,
"NETDEV %s could not register settings: %s\n",
823 goto err_register_settings;
829 if ( driver->
probe &&
831 DBGC (
netdev,
"NETDEV %s could not add %s device: " 848 err_register_settings:
896 unsigned int num_configs;
911 for ( i = 0 ; i < num_configs ; i++ )
1030 unsigned int location ) {
1075 const void *ll_source ) {
1103 uint16_t net_proto,
const void *ll_dest,
const void *ll_source,
1104 unsigned int flags ) {
1114 DBGC (
netdev,
"NETDEV %s unknown network protocol %04x\n",
1130 const void *ll_dest;
1131 const void *ll_source;
1156 DBGC2 (
netdev,
"NETDEV %s processing %p (%p+%zx)\n",
1164 &ll_dest, &ll_source,
1174 ll_source,
flags ) ) != 0 ) {
1245 unsigned int discarded = 0;
1283 return configurator;
1303 DBGC (
netdev,
"NETDEV %s does not support configuration via " 1314 DBGC (
netdev,
"NETDEV %s starting configuration via %s\n",
1319 DBGC (
netdev,
"NETDEV %s could not start configuration via " 1362 unsigned int num_configs;
1366 for ( i = 0 ; i < num_configs ; i++ ) {
#define EINPROGRESS_CONFIG
Default configuration-in-progress status code.
An object interface operation.
struct arbelprm_rc_send_wqe rc
void intf_close(struct interface *intf, int rc)
Close an object interface.
static void netdev_settings_init(struct net_device *netdev)
Initialise a per-netdevice configuration settings block.
void intf_restart(struct interface *intf, int rc)
Shut down and restart an object interface.
int netdev_configuration_in_progress(struct net_device *netdev)
Check if network device configuration is in progress.
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
void netdev_tx_defer(struct net_device *netdev, struct io_buffer *iobuf)
Defer transmitted packet.
#define EUNKNOWN_LINK_STATUS
Default unknown link status code.
#define EBUSY
Device or resource busy.
uint8_t ll_header_len
Link-layer header length.
#define EINFO_EINPROGRESS_CONFIG
uint8_t ll_addr_len
Link-layer address length.
int(* start)(struct interface *job, struct net_device *netdev)
Start configuring network device.
#define NETDEV_RX_FROZEN
Network device receive queue processing is frozen.
struct dma_mapping map
DMA mapping.
void unregister_settings(struct settings *settings)
Unregister settings block.
int(* open)(struct net_device *netdev)
Open network device.
void net_poll(void)
Poll the network stack.
#define list_add(new, head)
Add a new entry to the head of a list.
void netdev_tx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard transmitted packet.
#define NETDEV_OPEN
Network device is open.
struct interface job
Job control interface.
#define ref_init(refcnt, free)
Initialise a reference counter.
#define EEXIST
File exists.
struct retry_timer link_block
Link block timer.
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
#define __einfo_errortab(einfo)
size_t mtu
Maximum transmission unit length.
struct arbelprm_completion_with_error error
struct list_head list
List of network devices.
#define NETDEV_DISCARD_RATE
int netdev_configure(struct net_device *netdev, struct net_device_configurator *configurator)
Start network device configuration.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
unsigned int state
Current device state.
static size_t netdev_priv_offset(struct net_driver *driver)
Get offset of network device driver private data.
PERMANENT_PROCESS(net_process, net_step)
Networking stack process.
struct dma_device * dma
DMA device.
void netdev_tx_complete_next_err(struct net_device *netdev, int rc)
Complete network transmission.
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
static void netdev_config_close(struct net_device_configuration *config, int rc)
Finish network device configuration.
static void netdev_record_stat(struct net_device_stats *stats, int rc)
Record network device statistic.
#define for_each_table_entry_reverse(pointer, table)
Iterate through all entries within a linker table in reverse order.
A data structure for storing profiling information.
static int netdev_link_blocked(struct net_device *netdev)
Check link block state of network device.
static void profile_stop(struct profiler *profiler)
Stop profiling.
struct net_device_operations * op
Network device operations.
static const char * netdev_addr(struct net_device *netdev)
Get printable network device link-layer address.
struct net_device_stats tx_stats
TX statistics.
unsigned int scope_id
Scope ID.
void(* init_addr)(const void *hw_addr, void *ll_addr)
Initialise link-layer address.
A network upper-layer driver.
int(* probe)(struct net_device *netdev, void *priv)
Probe device.
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
size_t priv_len
Size of private data.
static struct interface_operation netdev_config_ops[]
Network device configuration interface operations.
struct list_head rx_queue
RX packet queue.
unsigned int count
Error count.
#define ECANCELED
Operation canceled.
#define ENOTSUP
Operation not supported.
A doubly-linked list entry (or list head)
void(* poll)(struct net_device *netdev)
Poll for completed and received packets.
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.
Dynamic memory allocation.
static __always_inline int iob_map_tx(struct io_buffer *iobuf, struct dma_device *dma)
Map I/O buffer for transmit DMA.
int netdev_configure_all(struct net_device *netdev)
Start network device configuration via all supported configurators.
#define list_empty(list)
Test whether a list is empty.
#define EINFO_ENOTCONN_LINK_DOWN
#define list_first_entry(list, type, member)
Get the container of the first entry in a list.
struct net_device * alloc_netdev(size_t priv_len)
Allocate network device.
#define EUNUSED_CONFIG
Default not-yet-attempted-configuration status code.
#define list_del(list)
Delete an entry from a list.
void(* irq)(struct net_device *netdev, int enable)
Enable or disable interrupts.
#define iob_disown(iobuf)
Disown an I/O buffer.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static int netdev_is_open(struct net_device *netdev)
Check whether or not network device is open.
static __always_inline int dma_mapped(struct dma_mapping *map)
Check if DMA unmapping is required.
struct net_device_configurator * find_netdev_configurator(const char *name)
Find network device configurator.
int link_rc
Link status code.
void netdev_link_block(struct net_device *netdev, unsigned long timeout)
Mark network device link as being blocked.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
#define container_of(ptr, type, field)
Get containing structure.
unsigned int(* discard)(void)
Discard some cached data.
static void srand(unsigned int seed)
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
void * priv
Driver private data.
void * netdev_priv(struct net_device *netdev, struct net_driver *driver)
Get network device driver private data.
#define __unused
Declare a variable or data structure as unused.
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
static __always_inline void iob_unmap(struct io_buffer *iobuf)
Unmap I/O buffer for DMA.
void netdev_link_unblock(struct net_device *netdev)
Mark network device link as being unblocked.
struct list_head tx_queue
TX packet queue.
struct net_device_configuration configs[0]
Network device configurations (variable length)
static struct net_device * netdev
struct net_device * last_opened_netdev(void)
Get most recently opened network device.
struct list_head tx_deferred
Deferred TX packet queue.
static void netdev_rx_flush(struct net_device *netdev)
Flush device's receive queue.
static void profile_start(struct profiler *profiler)
Start profiling.
void unregister_netdev(struct net_device *netdev)
Unregister network device.
#define NET_DRIVERS
Network driver table.
unsigned int location
Location.
static struct interface_descriptor netdev_config_desc
Network device configuration interface descriptor.
#define NET_PROTOCOLS
Network-layer protocol table.
An object interface descriptor.
void netdev_poll(struct net_device *netdev)
Poll for completed and received packets on network device.
static struct list_head open_net_devices
List of open network devices, in reverse order of opening.
char * strerror(int errno)
Retrieve string representation of error number.
struct refcnt refcnt
Reference counter.
static void(* free)(struct refcnt *refcnt))
void * zalloc(size_t size)
Allocate cleared memory.
static struct profiler net_poll_profiler __profiler
Network polling profiler.
#define for_each_netdev(netdev)
Iterate over all network devices.
int register_netdev(struct net_device *netdev)
Register network device.
struct cache_discarder net_discarder __cache_discarder(CACHE_NORMAL)
Network device cache discarder.
struct net_device_stats rx_stats
RX statistics.
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
unsigned int bad
Count of error completions.
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
void netdev_irq(struct net_device *netdev, int enable)
Enable or disable interrupts.
int net_rx(struct io_buffer *iobuf, struct net_device *netdev, uint16_t net_proto, const void *ll_dest, const void *ll_source, unsigned int flags)
Process received network-layer packet.
void netdev_link_err(struct net_device *netdev, int rc)
Mark network device as having a specific link state.
#define ENODEV
No such device.
int netdev_tx(struct net_device *netdev, struct io_buffer *iobuf)
Transmit raw packet via network device.
struct net_device_error errors[NETDEV_MAX_UNIQUE_ERRORS]
Error breakdowns.
Network device statistics.
static struct net_device * netdev_get(struct net_device *netdev)
Get reference to network device.
void(* notify)(struct net_device *netdev, void *priv)
Notify of device or link state change.
static void netdev_link_block_expired(struct retry_timer *timer, int fail __unused)
Handle network device link block timer expiry.
void(* close)(struct net_device *netdev)
Close network device.
uint16_t net_proto
Network-layer protocol.
struct errortab netdev_errors [] __errortab
Human-readable message for the default link statuses.
struct net_device * find_netdev_by_scope_id(unsigned int scope_id)
Get network device by scope ID.
#define CACHE_NORMAL
Items with a normal replacement cost.
int(* transmit)(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
static unsigned int net_discard(void)
Discard some cached network device data.
static int netdev_has_ll_addr(struct net_device *netdev)
Check whether or not network device has a link-layer address.
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
struct device * dev
Underlying hardware device.
void netdev_close(struct net_device *netdev)
Close network device.
void netdev_rx_freeze(struct net_device *netdev)
Freeze network device receive queue processing.
A network-layer protocol.
void netdev_rx_unfreeze(struct net_device *netdev)
Unfreeze network device receive queue processing.
Network device management.
void start_timer_fixed(struct retry_timer *timer, unsigned long timeout)
Start timer with a specified timeout.
#define NETDEV_TX_IN_PROGRESS
Network device transmission is in progress.
static void net_step(struct process *process __unused)
Single-step the network stack.
static int netdev_configurator_applies(struct net_device *netdev, struct net_device_configurator *configurator)
Check if configurator applies to network device.
#define EINFO_EUNKNOWN_LINK_STATUS
#define NETDEV_POLL_IN_PROGRESS
Network device poll is in progress.
#define INIT_LIST_HEAD(list)
Initialise a list head.
#define INTF_DESC(object_type, intf, operations)
Define an object interface descriptor.
void stop_timer(struct retry_timer *timer)
Stop timer.
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
unsigned int good
Count of successful completions.
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.
unsigned int bus_type
Bus type.
char name[NETDEV_NAME_LEN]
Name of this network device.
struct list_head list
List of which this buffer is a member.
__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)
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.
#define ENOBUFS
No buffer space available.
#define EINFO_EUNUSED_CONFIG
static struct tlan_private * priv
int strcmp(const char *first, const char *second)
Compare strings.
struct net_device * netdev
Network device.
void(* remove)(struct net_device *netdev, void *priv)
Remove device.
struct net_device * find_netdev(const char *name)
Get network device by name.
void * data
Start of data.
int rc
Configuration status.
struct list_head open_list
List of open network devices.
A network device configurator.
__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 device_description desc
Device description.
#define __weak
Declare a function as weak (use before the definition)
__weak unsigned int vlan_tci(struct net_device *netdev __unused)
Get the VLAN tag control information (when VLAN support is not present)
struct net_device_configurator * configurator
Network device configurator.
#define table_end(table)
Get end of linker table.
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
static void free_netdev(struct refcnt *refcnt)
Free network device.
#define NET_DEVICE_CONFIGURATORS
Network device configurator table.
int register_settings(struct settings *settings, struct settings *parent, const char *name)
Register settings block.
uint16_t offset
Offset to command line.
void clear_settings(struct settings *settings)
Clear settings block.
struct list_head net_devices
List of network devices.
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
size_t max_pkt_len
Maximum packet length.
A network device configuration.
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
#define LIST_HEAD_INIT(list)
Initialise a static list head.
static int netdev_rx_frozen(struct net_device *netdev)
Check whether or not network device receive queue processing is frozen.
static void netdev_tx_flush(struct net_device *netdev)
Flush device's transmit queue.
uint64_t tag
Identity tag.
#define list_check_contains_entry(entry, head, member)
Check list contains a specified entry.
struct net_device * find_netdev_by_location(unsigned int bus_type, unsigned int location)
Get network device by PCI bus:dev.fn address.
int netdev_configuration_ok(struct net_device *netdev)
Check if network device has at least one successful configuration.
#define ENETUNREACH
Network unreachable.
#define for_each_table_entry_continue_reverse(pointer, table)
Iterate through all remaining entries within a linker table in reverse order.
static int netdev_has_configuration_rc(struct net_device *netdev, int rc)
Check if network device has a configuration with a specified status code.
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
#define NULL
NULL pointer (VOID *)
static int netdev_irq_supported(struct net_device *netdev)
Check whether or not network device supports interrupts.
int netdev_open(struct net_device *netdev)
Open network device.
#define ENOTCONN_LINK_DOWN
Default link-down status code.
#define NETDEV_IRQ_ENABLED
Network device interrupts are enabled.
static struct net_device_configuration * netdev_configuration(struct net_device *netdev, struct net_device_configurator *configurator)
Get network device configuration.
struct ll_protocol * ll_protocol
Link-layer protocol.
static void netdev_notify(struct net_device *netdev)
Notify drivers of network device or link state change.
int(* rx)(struct io_buffer *iobuf, struct net_device *netdev, const void *ll_dest, const void *ll_source, unsigned int flags)
Process received packet.
struct io_buffer * netdev_rx_dequeue(struct net_device *netdev)
Remove packet from device's receive queue.
#define table_num_entries(table)
Get number of entries in linker table.