72#define SNP_INITIALIZE_RETRY_MAX 10
75#define SNP_INITIALIZE_RETRY_DELAY_MS 10
106 static char buf[
sizeof ( *mac ) * 3 ];
110 for ( i = 0 ; i <
len ; i++ ) {
111 used +=
ssnprintf ( &buf[used], (
sizeof ( buf ) - used ),
112 "%s%02x", ( used ?
":" :
"" ),
126 size_t mac_len =
mode->HwAddressSize;
133 DBGC2 (
snp,
"SNP %s st %d type %d hdr %d pkt %d rxflt %#x/%#x%s "
134 "nvram %d acc %d mcast %d/%d\n",
netdev->name,
mode->State,
135 mode->IfType,
mode->MediaHeaderSize,
mode->MaxPacketSize,
136 mode->ReceiveFilterSetting,
mode->ReceiveFilterMask,
137 (
mode->MultipleTxSupported ?
" multitx" :
"" ),
138 mode->NvRamSize,
mode->NvRamAccessSize,
139 mode->MCastFilterCount,
mode->MaxMCastFilterCount );
144 (
mode->MacAddressChangeable ?
"" :
"(f)" ) );
147 for ( i = 0 ; i <
mode->MCastFilterCount ; i++ ) {
152 (
mode->MediaPresentSupported ?
153 (
mode->MediaPresent ?
"present" :
"not present" ) :
154 "presence not supported" ) );
167 if ( !
mode->MediaPresentSupported )
212 DBGC (
snp,
"SNP %s could not transmit: %s\n",
236 if ( ( efirc = snp->
snp->
GetStatus ( snp->
snp, &irq, &txbuf ) ) != 0 ) {
238 DBGC ( snp,
"SNP %s could not get status: %s\n",
249 if ( ! snp->
txbuf ) {
250 DBGC ( snp,
"SNP %s reported spurious TX completion\n",
278 if ( !
snp->rxbuf ) {
280 if ( !
snp->rxbuf ) {
300 DBGC (
snp,
"SNP %s could not receive: %s\n",
359 for ( i = 0; i < (
sizeof ( filters ) /
sizeof ( filters[0] ) ); i++ ) {
366 DBGC (
snp,
"SNP %s could not set receive filters %#02x (have "
367 "%#02x): %s\n",
netdev->name, filters[i],
391 DBGC (
snp,
"SNP %s could not set station address before "
397 for ( retry = 0 ; ; ) {
405 DBGC (
snp,
"SNP %s could not initialise: %s\n",
411 if ( ( !
mode->MediaPresentSupported ) ||
mode->MediaPresent )
420 DBGC (
snp,
"SNP %s retrying initialisation (retry %d)\n",
435 DBGC (
snp,
"SNP %s could not shut down: %s\n",
444 DBGC (
snp,
"SNP %s could not set station address after "
477 DBGC (
snp,
"SNP %s could not shut down: %s\n",
518 DBGCP (
device,
"HANDLE %s is provided by this binary\n",
535 &parent, 1 ) ) == 0 ) {
536 DBGC2 (
device,
"HANDLE %s has %s-supporting parent ",
548 DBGC (
device,
"HANDLE %s is wireless: assuming vendor %s "
549 "driver is too unreliable to use\n",
589 DBGC (
device,
"SNP %s is wireless: assuming insomniac\n",
624 DBGC (
device,
"SNP %s cannot open SNP protocol for patching: "
641 DBGC (
device,
"SNP %s patched to inhibit shutdown\n",
660 memset ( patch, 0,
sizeof ( *patch ) );
665 DBGC (
device,
"SNP %s cannot open patched SNP protocol: %s\n",
679 DBGC (
device,
"SNP %s could not restore patched SNP "
710 DBGC (
device,
"SNP %s could not exclude drivers: %s\n",
741 DBGC (
device,
"SNP %s cannot open SNP protocol: %s\n",
745 goto err_open_protocol;
763 snp->dev.driver_name =
"SNP";
775 ( ( efirc =
snp->snp->
Start (
snp->snp ) ) != 0 ) ) {
777 DBGC (
device,
"SNP %s could not start: %s\n",
785 DBGC (
device,
"SNP %s could not shut down: %s\n",
791 if (
mode->HwAddressSize !=
netdev->ll_protocol->hw_addr_len ) {
792 DBGC (
device,
"SNP %s has invalid hardware address length "
795 goto err_hw_addr_len;
798 netdev->ll_protocol->hw_addr_len );
799 if (
mode->HwAddressSize !=
netdev->ll_protocol->ll_addr_len ) {
800 DBGC (
device,
"SNP %s has invalid link-layer address length "
803 goto err_ll_addr_len;
806 netdev->ll_protocol->ll_addr_len );
812 goto err_register_netdev;
857 ( ( efirc =
snp->snp->
Stop (
snp->snp ) ) != 0 ) ) {
UINT64 UINTN
Unsigned value of native width.
unsigned int UINT32
4-byte unsigned value.
#define NULL
NULL pointer (VOID *)
#define VOID
Undeclared type.
The EFI_SIMPLE_NETWORK_PROTOCOL provides services to initialize a network interface,...
#define EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST
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.
@ EfiSimpleNetworkInitialized
@ EfiSimpleNetworkStopped
struct _EFI_SIMPLE_NETWORK_PROTOCOL EFI_SIMPLE_NETWORK_PROTOCOL
#define EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST
#define EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST
#define EFI_SIMPLE_NETWORK_RECEIVE_UNICAST
EFI_STATUS(EFIAPI * EFI_SIMPLE_NETWORK_STOP)(IN EFI_SIMPLE_NETWORK_PROTOCOL *This)
Changes the state of a network interface from "started" to "stopped".
#define EFI_NOT_READY
Enumeration of EFI_STATUS.
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
GUID EFI_GUID
128-bit buffer containing a unique identifier value.
struct arbelprm_rc_send_wqe rc
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
int efi_driver_exclude(EFI_HANDLE device, EFI_GUID *protocol)
Try to disconnect an existing EFI driver.
static void * efidev_get_drvdata(struct efi_device *efidev)
Get EFI driver-private data.
static void efidev_set_drvdata(struct efi_device *efidev, void *priv)
Set EFI driver-private data.
EFI_GUID efi_simple_network_protocol_guid
Simple network protocol GUID.
const char * efi_guid_ntoa(CONST EFI_GUID *guid)
Convert GUID to a printable string.
EFI_GUID efi_wifi2_protocol_guid
WiFi 2 protocol GUID.
int efi_shutdown_in_progress
EFI shutdown is in progress.
void efi_close_by_driver(EFI_HANDLE handle, EFI_GUID *protocol)
Close protocol opened for persistent use by a driver.
struct efi_snp_device * find_snpdev(EFI_HANDLE handle)
Find SNP device by EFI device handle.
void efi_device_info(EFI_HANDLE device, const char *prefix, struct device *dev)
Get underlying device information.
int efi_locate_device(EFI_HANDLE device, EFI_GUID *protocol, EFI_HANDLE *parent, unsigned int skip)
Locate parent device supporting a given protocol.
uint8_t mac[ETH_ALEN]
MAC address.
uint16_t mode
Acceleration mode.
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
static struct net_device * netdev
#define __unused
Declare a variable or data structure as unused.
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
#define EPIPE
Broken pipe.
#define ENOMEM
Not enough space.
#define EBUSY
Device or resource busy.
#define ENOTSUP
Operation not supported.
#define ECANCELED
Operation canceled.
#define ENOTTY
Inappropriate I/O control operation.
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
#define efi_open_by_driver(handle, protocol, interface)
Open protocol for persistent use by a driver.
#define efi_open(handle, protocol, interface)
Open protocol for ephemeral use.
#define efi_test(handle, protocol)
Test protocol existence.
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
#define DBGC_EFI_OPENERS(...)
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * memset(void *dest, int character, size_t len) __nonnull
void iob_pad(struct io_buffer *iobuf, size_t min_len)
Pad I/O buffer.
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
#define iob_put(iobuf, len)
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
static size_t iob_tailroom(struct io_buffer *iobuf)
Calculate available space at end of an I/O buffer.
#define list_del(list)
Delete an entry from a list.
#define INIT_LIST_HEAD(list)
Initialise a list head.
#define list_add(new, head)
Add a new entry to the head of a list.
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
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.
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.
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.
Network device management.
static int netdev_link_ok(struct net_device *netdev)
Check link state of network device.
#define NETDEV_INSOMNIAC
Network device must be polled even when closed.
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
static int netdev_insomniac(struct net_device *netdev)
Check whether or not network device must be polled even while closed.
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
static void netdev_tx_complete(struct net_device *netdev, struct io_buffer *iobuf)
Complete network transmission.
static int snpnet_open(struct net_device *netdev)
Open network device.
int snpnet_supported(EFI_HANDLE device, EFI_GUID *protocol, int inhibit_wifi)
Check to see if driver supports a device.
int snpnet_start(struct efi_device *efidev)
Attach driver to device.
static void snpnet_check_link(struct net_device *netdev)
Check link state.
static int snpnet_insomniac_restore(EFI_HANDLE device, struct snp_insomniac_patch *patch)
Restore patched SNP protocol interface.
static EFI_STATUS EFIAPI snpnet_do_nothing(EFI_SIMPLE_NETWORK_PROTOCOL *snp __unused)
Ignore shutdown attempt.
#define SNP_RX_QUOTA
Maximum number of received packets per poll.
static int snpnet_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
static void snpnet_poll(struct net_device *netdev)
Poll for completed packets.
#define SNP_INITIALIZE_RETRY_DELAY_MS
Delay between each initialisation retry.
static struct net_device_operations snpnet_operations
SNP network device operations.
static void snpnet_dump_mode(struct net_device *netdev)
Dump SNP mode information (for debugging)
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.
#define SNP_INITIALIZE_RETRY_MAX
Maximum initialisation retry count.
static void snpnet_poll_tx(struct net_device *netdev)
Poll for completed packets.
static const char * snpnet_mac_text(EFI_MAC_ADDRESS *mac, size_t len)
Format SNP MAC address (for debugging)
int snpnet_exclude(EFI_HANDLE device)
Exclude existing drivers.
#define SNP_RX_PAD
Additional padding for receive buffers.
static int snpnet_insomniac_patch(EFI_HANDLE device, struct snp_insomniac_patch *patch)
Patch SNP protocol interface to prevent shutdown.
static int snpnet_rx_filters(struct net_device *netdev)
Set receive filters.
static void snpnet_poll_rx(struct net_device *netdev)
Poll for received packets.
void snpnet_stop(struct efi_device *efidev)
Detach driver from device.
uint16_t protocol
Protocol ID.
char * strerror(int errno)
Retrieve string representation of error number.
32-byte buffer containing a network Media Access Control address.
UINT32 ReceiveFilterMask
The multicast receive filter settings supported by the network interface.
UINT32 MediaHeaderSize
The size, in bytes, of the network interface's media header.
BOOLEAN MediaPresentSupported
TRUE if the presence of media can be determined; otherwise FALSE.
UINT32 MaxPacketSize
The maximum size, in bytes, of the packets supported by the network interface.
UINT32 ReceiveFilterSetting
The current multicast receive filter settings.
EFI_SIMPLE_NETWORK_INITIALIZE Initialize
EFI_SIMPLE_NETWORK_RECEIVE Receive
EFI_SIMPLE_NETWORK_START Start
EFI_SIMPLE_NETWORK_RECEIVE_FILTERS ReceiveFilters
EFI_SIMPLE_NETWORK_MODE * Mode
Pointer to the EFI_SIMPLE_NETWORK_MODE data for the device.
EFI_SIMPLE_NETWORK_SHUTDOWN Shutdown
EFI_SIMPLE_NETWORK_STATION_ADDRESS StationAddress
EFI_SIMPLE_NETWORK_TRANSMIT Transmit
EFI_SIMPLE_NETWORK_STOP Stop
EFI_SIMPLE_NETWORK_GET_STATUS GetStatus
struct list_head children
Devices attached to this device.
EFI_HANDLE device
EFI device handle.
struct device dev
Generic device.
void * data
Start of data.
Network device operations.
An SNP interface patch to inhibit shutdown for insomniac devices.
EFI_SIMPLE_NETWORK_SHUTDOWN shutdown
Original Shutdown() method.
EFI_SIMPLE_NETWORK_STOP stop
Original Stop() method.
size_t mtu
Maximum packet size.
struct io_buffer * txbuf
Current transmit buffer.
struct io_buffer * rxbuf
Current receive buffer.
EFI_SIMPLE_NETWORK_PROTOCOL * snp
Simple network protocol.
struct device dev
Generic device.
struct efi_device * efidev
EFI device.
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
int ssnprintf(char *buf, ssize_t ssize, const char *fmt,...)
Version of vsnprintf() that accepts a signed buffer size.