68 #define SNP_RX_QUOTA 4 71 #define SNP_INITIALIZE_RETRY_MAX 10 74 #define SNP_INITIALIZE_RETRY_DELAY_MS 10 105 static char buf[
sizeof ( *mac ) * 3 ];
109 for ( i = 0 ; i <
len ; i++ ) {
110 used +=
ssnprintf ( &buf[used], (
sizeof ( buf ) - used ),
111 "%s%02x", ( used ?
":" :
"" ),
125 size_t mac_len =
mode->HwAddressSize;
132 DBGC2 (
snp,
"SNP %s st %d type %d hdr %d pkt %d rxflt %#x/%#x%s " 134 mode->IfType,
mode->MediaHeaderSize,
mode->MaxPacketSize,
135 mode->ReceiveFilterSetting,
mode->ReceiveFilterMask,
136 (
mode->MultipleTxSupported ?
" multitx" :
"" ),
137 mode->NvRamSize,
mode->NvRamAccessSize,
138 mode->MCastFilterCount,
mode->MaxMCastFilterCount );
143 (
mode->MacAddressChangeable ?
"" :
"(f)" ) );
146 for ( i = 0 ; i <
mode->MCastFilterCount ; i++ ) {
151 (
mode->MediaPresentSupported ?
152 (
mode->MediaPresent ?
"present" :
"not present" ) :
153 "presence not supported" ) );
166 if ( !
mode->MediaPresentSupported )
211 DBGC (
snp,
"SNP %s could not transmit: %s\n",
235 if ( ( efirc = snp->
snp->
GetStatus ( snp->
snp, &irq, &txbuf ) ) != 0 ) {
237 DBGC ( snp,
"SNP %s could not get status: %s\n",
248 if ( ! snp->
txbuf ) {
249 DBGC ( snp,
"SNP %s reported spurious TX completion\n",
277 if ( !
snp->rxbuf ) {
279 if ( !
snp->rxbuf ) {
299 DBGC (
snp,
"SNP %s could not receive: %s\n",
358 for ( i = 0; i < (
sizeof ( filters ) /
sizeof ( filters[0] ) ); i++ ) {
365 DBGC (
snp,
"SNP %s could not set receive filters %#02x (have " 390 DBGC (
snp,
"SNP %s could not set station address before " 396 for ( retry = 0 ; ; ) {
404 DBGC (
snp,
"SNP %s could not initialise: %s\n",
410 if ( ( !
mode->MediaPresentSupported ) ||
mode->MediaPresent )
419 DBGC (
snp,
"SNP %s retrying initialisation (retry %d)\n",
434 DBGC (
snp,
"SNP %s could not shut down: %s\n",
443 DBGC (
snp,
"SNP %s could not set station address after " 476 DBGC (
snp,
"SNP %s could not shut down: %s\n",
517 DBGCP (
device,
"HANDLE %s is provided by this binary\n",
534 &parent, 1 ) ) == 0 ) {
535 DBGC2 (
device,
"HANDLE %s has %s-supporting parent ",
547 DBGC (
device,
"HANDLE %s is wireless: assuming vendor %s " 548 "driver is too unreliable to use\n",
588 DBGC (
device,
"SNP %s is wireless: assuming insomniac\n",
623 DBGC (
device,
"SNP %s cannot open SNP protocol for patching: " 640 DBGC (
device,
"SNP %s patched to inhibit shutdown\n",
659 memset ( patch, 0,
sizeof ( *patch ) );
664 DBGC (
device,
"SNP %s cannot open patched SNP protocol: %s\n",
678 DBGC (
device,
"SNP %s could not restore patched SNP " 709 DBGC (
device,
"SNP %s could not exclude drivers: %s\n",
740 DBGC (
device,
"SNP %s cannot open SNP protocol: %s\n",
744 goto err_open_protocol;
762 snp->dev.driver_name =
"SNP";
774 ( ( efirc =
snp->snp->
Start (
snp->snp ) ) != 0 ) ) {
776 DBGC (
device,
"SNP %s could not start: %s\n",
784 DBGC (
device,
"SNP %s could not shut down: %s\n",
791 DBGC (
device,
"SNP %s has invalid hardware address length " 794 goto err_hw_addr_len;
799 DBGC (
device,
"SNP %s has invalid link-layer address length " 802 goto err_ll_addr_len;
811 goto err_register_netdev;
856 ( ( efirc =
snp->snp->
Stop (
snp->snp ) ) != 0 ) ) {
EFI_SIMPLE_NETWORK_STATION_ADDRESS StationAddress
struct arbelprm_rc_send_wqe rc
static void netdev_tx_complete(struct net_device *netdev, struct io_buffer *iobuf)
Complete network transmission.
#define iob_put(iobuf, len)
static void snpnet_dump_mode(struct net_device *netdev)
Dump SNP mode information (for debugging)
static void snpnet_poll(struct net_device *netdev)
Poll for completed packets.
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
The EFI_SIMPLE_NETWORK_PROTOCOL protocol is used to initialize access to a network adapter.
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
void netdev_tx_defer(struct net_device *netdev, struct io_buffer *iobuf)
Defer transmitted packet.
#define SNP_RX_PAD
Additional padding for receive buffers.
#define EBUSY
Device or resource busy.
uint8_t ll_addr_len
Link-layer address length.
UINT32 MediaHeaderSize
The size, in bytes, of the network interface's media header.
int(* open)(struct net_device *netdev)
Open network device.
#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.
128 bit buffer containing a unique identifier value.
EFI_SIMPLE_NETWORK_PROTOCOL * snp
Simple network protocol.
32-byte buffer containing a network Media Access Control address.
void snpnet_stop(struct efi_device *efidev)
Detach driver from device.
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
uint16_t mode
Acceleration mode.
static int snpnet_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
#define EPIPE
Broken pipe.
static int netdev_insomniac(struct net_device *netdev)
Check whether or not network device must be polled even while closed.
#define efi_test(handle, protocol)
Test protocol existence.
EFI_GUID efi_simple_network_protocol_guid
Simple network protocol GUID.
#define EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST
static int snpnet_insomniac_restore(EFI_HANDLE device, struct snp_insomniac_patch *patch)
Restore patched SNP protocol interface.
unsigned int state
Current device state.
BOOLEAN MediaPresentSupported
TRUE if the presence of media can be determined; otherwise FALSE.
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
#define DBGC_EFI_OPENERS(...)
EFI_HANDLE device
EFI device handle.
An SNP interface patch to inhibit shutdown for insomniac devices.
uint8_t mac[ETH_ALEN]
MAC address.
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
struct io_buffer * rxbuf
Current receive buffer.
#define EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST
#define ECANCELED
Operation canceled.
#define ENOTSUP
Operation not supported.
EFI_SIMPLE_NETWORK_MODE * Mode
Pointer to the EFI_SIMPLE_NETWORK_MODE data for the device.
int snpnet_start(struct efi_device *efidev)
Attach driver to device.
static const char * snpnet_mac_text(EFI_MAC_ADDRESS *mac, size_t len)
Format SNP MAC address (for debugging)
int ssnprintf(char *buf, ssize_t ssize, const char *fmt,...)
Version of vsnprintf() that accepts a signed buffer size.
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
#define list_del(list)
Delete an entry from a list.
UINT32 MaxPacketSize
The maximum size, in bytes, of the packets supported by the network interface.
#define ENOMEM
Not enough space.
EFI_SIMPLE_NETWORK_STOP stop
Original Stop() method.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
FILE_LICENCE(GPL2_OR_LATER)
UINT32 ReceiveFilterSetting
The current multicast receive filter settings.
EFI_SIMPLE_NETWORK_INITIALIZE Initialize
struct io_buffer * txbuf
Current transmit buffer.
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
void efi_close_by_driver(EFI_HANDLE handle, EFI_GUID *protocol)
Close protocol opened for persistent use by a driver.
uint8_t hw_addr_len
Hardware address length.
void * priv
Driver private data.
#define __unused
Declare a variable or data structure as unused.
EFI_SIMPLE_NETWORK_SHUTDOWN Shutdown
EFI_SIMPLE_NETWORK_SHUTDOWN shutdown
Original Shutdown() method.
EFI_SIMPLE_NETWORK_GET_STATUS GetStatus
#define efi_open_by_driver(handle, protocol, interface)
Open protocol for persistent use by a driver.
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
The EFI_SIMPLE_NETWORK_PROTOCOL provides services to initialize a network interface,...
static int netdev_link_ok(struct net_device *netdev)
Check link state of network device.
static struct net_device * netdev
static void snpnet_check_link(struct net_device *netdev)
Check link state.
EFI_SIMPLE_NETWORK_TRANSMIT Transmit
static void snpnet_close(struct net_device *netdev)
Close network device.
static int snpnet_is_insomniac(EFI_HANDLE device)
Check if device must be insomniac.
void unregister_netdev(struct net_device *netdev)
Unregister network device.
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
char * strerror(int errno)
Retrieve string representation of error number.
#define EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST
int snpnet_supported(EFI_HANDLE device, EFI_GUID *protocol, int inhibit_wifi)
Check to see if driver supports a device.
static EFI_STATUS EFIAPI snpnet_do_nothing(EFI_SIMPLE_NETWORK_PROTOCOL *snp __unused)
Ignore shutdown attempt.
int register_netdev(struct net_device *netdev)
Register network device.
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
static void * efidev_get_drvdata(struct efi_device *efidev)
Get EFI driver-private data.
static size_t iob_tailroom(struct io_buffer *iobuf)
Calculate available space at end of an I/O buffer.
#define efi_open(handle, protocol, interface)
Open protocol for ephemeral use.
int efi_driver_exclude(EFI_HANDLE device, EFI_GUID *protocol)
Try to disconnect an existing EFI driver.
struct device dev
Generic device.
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
UINT64 UINTN
Unsigned value of native width.
#define EFI_NOT_READY
Enumeration of EFI_STATUS.
#define SNP_RX_QUOTA
Maximum number of received packets per poll.
static int snpnet_open(struct net_device *netdev)
Open network device.
static int snpnet_rx_filters(struct net_device *netdev)
Set receive filters.
static void snpnet_poll_tx(struct net_device *netdev)
Poll for completed packets.
#define SNP_INITIALIZE_RETRY_MAX
Maximum initialisation retry count.
int efi_locate_device(EFI_HANDLE device, EFI_GUID *protocol, EFI_HANDLE *parent, unsigned int skip)
Locate parent device supporting a given protocol.
const char * efi_guid_ntoa(CONST EFI_GUID *guid)
Convert GUID to a printable string.
EFI_SIMPLE_NETWORK_START Start
#define VOID
Undeclared type.
EFI_STATUS(EFIAPI * EFI_SIMPLE_NETWORK_STOP)(IN EFI_SIMPLE_NETWORK_PROTOCOL *This)
Changes the state of a network interface from "started" to "stopped".
struct efi_device * efidev
EFI device.
Network device operations.
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
struct device * dev
Underlying hardware device.
static int snpnet_insomniac_patch(EFI_HANDLE device, struct snp_insomniac_patch *patch)
Patch SNP protocol interface to prevent shutdown.
EFI_SIMPLE_NETWORK_RECEIVE Receive
Network device management.
EFI_GUID efi_wifi2_protocol_guid
WiFi 2 protocol GUID.
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
struct efi_snp_device * find_snpdev(EFI_HANDLE handle)
Find SNP device by EFI device handle.
#define INIT_LIST_HEAD(list)
Initialise a list head.
#define EFI_SIMPLE_NETWORK_RECEIVE_UNICAST
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
char name[NETDEV_NAME_LEN]
Name of this network device.
#define ENOTTY
Inappropriate I/O control operation.
void * data
Start of data.
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
struct list_head children
Devices attached to this device.
UINT32 ReceiveFilterMask
The multicast receive filter settings supported by the network interface.
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
EFI_STATUS(EFIAPI * EFI_SIMPLE_NETWORK_SHUTDOWN)(IN EFI_SIMPLE_NETWORK_PROTOCOL *This)
Resets a network adapter and leaves it in a state that is safe for another driver to initialize.
static void snpnet_poll_rx(struct net_device *netdev)
Poll for received packets.
#define SNP_INITIALIZE_RETRY_DELAY_MS
Delay between each initialisation retry.
EFI_SIMPLE_NETWORK_RECEIVE_FILTERS ReceiveFilters
uint16_t protocol
Protocol ID.
int snpnet_exclude(EFI_HANDLE device)
Exclude existing drivers.
EFI_SIMPLE_NETWORK_STOP Stop
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
static void efidev_set_drvdata(struct efi_device *efidev, void *priv)
Set EFI driver-private data.
struct device dev
Generic device.
#define NETDEV_INSOMNIAC
Network device must be polled even when closed.
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
#define NULL
NULL pointer (VOID *)
void iob_pad(struct io_buffer *iobuf, size_t min_len)
Pad I/O buffer.
static struct net_device_operations snpnet_operations
SNP network device operations.
struct ll_protocol * ll_protocol
Link-layer protocol.
size_t mtu
Maximum packet size.
void efi_device_info(EFI_HANDLE device, const char *prefix, struct device *dev)
Get underlying device information.
void * memset(void *dest, int character, size_t len) __nonnull
int efi_shutdown_in_progress
EFI shutdown is in progress.