iPXE
Data Structures | Macros | Functions | Variables
snpnet.c File Reference

SNP NIC driver. More...

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ipxe/iobuf.h>
#include <ipxe/netdevice.h>
#include <ipxe/ethernet.h>
#include <ipxe/if_ether.h>
#include <ipxe/vsprintf.h>
#include <ipxe/timer.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/Protocol/SimpleNetwork.h>
#include <ipxe/efi/efi_driver.h>
#include <ipxe/efi/efi_utils.h>
#include <ipxe/efi/efi_snp.h>
#include "snpnet.h"

Go to the source code of this file.

Data Structures

struct  snp_nic
 An SNP NIC. More...
 
struct  snp_insomniac_patch
 An SNP interface patch to inhibit shutdown for insomniac devices. More...
 

Macros

#define SNP_RX_QUOTA   4
 Maximum number of received packets per poll. More...
 
#define SNP_INITIALIZE_RETRY_MAX   10
 Maximum initialisation retry count. More...
 
#define SNP_INITIALIZE_RETRY_DELAY_MS   10
 Delay between each initialisation retry. More...
 
#define SNP_RX_PAD   8
 Additional padding for receive buffers. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER)
 
static const char * snpnet_mac_text (EFI_MAC_ADDRESS *mac, size_t len)
 Format SNP MAC address (for debugging) More...
 
static void snpnet_dump_mode (struct net_device *netdev)
 Dump SNP mode information (for debugging) More...
 
static void snpnet_check_link (struct net_device *netdev)
 Check link state. More...
 
static int snpnet_transmit (struct net_device *netdev, struct io_buffer *iobuf)
 Transmit packet. More...
 
static void snpnet_poll_tx (struct net_device *netdev)
 Poll for completed packets. More...
 
static void snpnet_poll_rx (struct net_device *netdev)
 Poll for received packets. More...
 
static void snpnet_poll (struct net_device *netdev)
 Poll for completed packets. More...
 
static int snpnet_rx_filters (struct net_device *netdev)
 Set receive filters. More...
 
static int snpnet_open (struct net_device *netdev)
 Open network device. More...
 
static void snpnet_close (struct net_device *netdev)
 Close network device. More...
 
int snpnet_supported (EFI_HANDLE device, EFI_GUID *protocol, int inhibit_wifi)
 Check to see if driver supports a device. More...
 
static int snpnet_is_insomniac (EFI_HANDLE device)
 Check if device must be insomniac. More...
 
static EFI_STATUS EFIAPI snpnet_do_nothing (EFI_SIMPLE_NETWORK_PROTOCOL *snp __unused)
 Ignore shutdown attempt. More...
 
static int snpnet_insomniac_patch (EFI_HANDLE device, struct snp_insomniac_patch *patch)
 Patch SNP protocol interface to prevent shutdown. More...
 
static int snpnet_insomniac_restore (EFI_HANDLE device, struct snp_insomniac_patch *patch)
 Restore patched SNP protocol interface. More...
 
int snpnet_exclude (EFI_HANDLE device)
 Exclude existing drivers. More...
 
int snpnet_start (struct efi_device *efidev)
 Attach driver to device. More...
 
void snpnet_stop (struct efi_device *efidev)
 Detach driver from device. More...
 

Variables

static struct net_device_operations snpnet_operations
 SNP network device operations. More...
 

Detailed Description

SNP NIC driver.

Definition in file snpnet.c.

Macro Definition Documentation

◆ SNP_RX_QUOTA

#define SNP_RX_QUOTA   4

Maximum number of received packets per poll.

Definition at line 68 of file snpnet.c.

◆ SNP_INITIALIZE_RETRY_MAX

#define SNP_INITIALIZE_RETRY_MAX   10

Maximum initialisation retry count.

Definition at line 71 of file snpnet.c.

◆ SNP_INITIALIZE_RETRY_DELAY_MS

#define SNP_INITIALIZE_RETRY_DELAY_MS   10

Delay between each initialisation retry.

Definition at line 74 of file snpnet.c.

◆ SNP_RX_PAD

#define SNP_RX_PAD   8

Additional padding for receive buffers.

Some SNP implementations seem to require additional space in the allocated receive buffers, otherwise full-length packets will be silently dropped.

The EDK2 MnpDxe driver happens to allocate an additional 8 bytes of padding (4 for a VLAN tag, 4 for the Ethernet frame checksum). Match this behaviour since drivers are very likely to have been tested against MnpDxe.

Definition at line 87 of file snpnet.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER  )

◆ snpnet_mac_text()

static const char* snpnet_mac_text ( EFI_MAC_ADDRESS mac,
size_t  len 
)
static

Format SNP MAC address (for debugging)

Parameters
macMAC address
lenLength of MAC address
Return values
textMAC address as text

Definition at line 104 of file snpnet.c.

104  {
105  static char buf[ sizeof ( *mac ) * 3 /* "xx:" or "xx\0" */ ];
106  size_t used = 0;
107  unsigned int i;
108 
109  for ( i = 0 ; i < len ; i++ ) {
110  used += ssnprintf ( &buf[used], ( sizeof ( buf ) - used ),
111  "%s%02x", ( used ? ":" : "" ),
112  mac->Addr[i] );
113  }
114  return buf;
115 }
uint8_t mac[ETH_ALEN]
MAC address.
Definition: ena.h:24
int ssnprintf(char *buf, ssize_t ssize, const char *fmt,...)
Version of vsnprintf() that accepts a signed buffer size.
Definition: vsprintf.c:420
ring len
Length.
Definition: dwmac.h:231

References len, mac, and ssnprintf().

Referenced by snpnet_dump_mode().

◆ snpnet_dump_mode()

static void snpnet_dump_mode ( struct net_device netdev)
static

Dump SNP mode information (for debugging)

Parameters
netdevNetwork device

Definition at line 122 of file snpnet.c.

122  {
123  struct snp_nic *snp = netdev->priv;
125  size_t mac_len = mode->HwAddressSize;
126  unsigned int i;
127 
128  /* Do nothing unless debugging is enabled */
129  if ( ! DBG_EXTRA )
130  return;
131 
132  DBGC2 ( snp, "SNP %s st %d type %d hdr %d pkt %d rxflt %#x/%#x%s "
133  "nvram %d acc %d mcast %d/%d\n", netdev->name, mode->State,
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 );
139  DBGC2 ( snp, "SNP %s hw %s", netdev->name,
140  snpnet_mac_text ( &mode->PermanentAddress, mac_len ) );
141  DBGC2 ( snp, " addr %s%s",
142  snpnet_mac_text ( &mode->CurrentAddress, mac_len ),
143  ( mode->MacAddressChangeable ? "" : "(f)" ) );
144  DBGC2 ( snp, " bcast %s\n",
145  snpnet_mac_text ( &mode->BroadcastAddress, mac_len ) );
146  for ( i = 0 ; i < mode->MCastFilterCount ; i++ ) {
147  DBGC2 ( snp, "SNP %s mcast %s\n", netdev->name,
148  snpnet_mac_text ( &mode->MCastFilter[i], mac_len ) );
149  }
150  DBGC2 ( snp, "SNP %s media %s\n", netdev->name,
151  ( mode->MediaPresentSupported ?
152  ( mode->MediaPresent ? "present" : "not present" ) :
153  "presence not supported" ) );
154 }
EFI_SIMPLE_NETWORK_PROTOCOL * snp
Simple network protocol.
Definition: snpnet.c:50
uint16_t mode
Acceleration mode.
Definition: ena.h:26
EFI_SIMPLE_NETWORK_MODE * Mode
Pointer to the EFI_SIMPLE_NETWORK_MODE data for the device.
static const char * snpnet_mac_text(EFI_MAC_ADDRESS *mac, size_t len)
Format SNP MAC address (for debugging)
Definition: snpnet.c:104
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
An SNP NIC.
Definition: snpnet.c:46
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
#define DBGC2(...)
Definition: compiler.h:522
#define DBG_EXTRA
Definition: compiler.h:319

References DBG_EXTRA, DBGC2, mode, _EFI_SIMPLE_NETWORK_PROTOCOL::Mode, net_device::name, netdev, net_device::priv, snp_nic::snp, and snpnet_mac_text().

Referenced by snpnet_open().

◆ snpnet_check_link()

static void snpnet_check_link ( struct net_device netdev)
static

Check link state.

Parameters
netdevNetwork device

Definition at line 161 of file snpnet.c.

161  {
162  struct snp_nic *snp = netdev->priv;
164 
165  /* Do nothing unless media presence detection is supported */
166  if ( ! mode->MediaPresentSupported )
167  return;
168 
169  /* Report any link status change */
170  if ( mode->MediaPresent && ( ! netdev_link_ok ( netdev ) ) ) {
172  } else if ( ( ! mode->MediaPresent ) && netdev_link_ok ( netdev ) ) {
174  }
175 }
EFI_SIMPLE_NETWORK_PROTOCOL * snp
Simple network protocol.
Definition: snpnet.c:50
uint16_t mode
Acceleration mode.
Definition: ena.h:26
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
Definition: netdevice.c:230
EFI_SIMPLE_NETWORK_MODE * Mode
Pointer to the EFI_SIMPLE_NETWORK_MODE data for the device.
void * priv
Driver private data.
Definition: netdevice.h:431
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:788
static int netdev_link_ok(struct net_device *netdev)
Check link state of network device.
Definition: netdevice.h:639
static struct net_device * netdev
Definition: gdbudp.c:52
An SNP NIC.
Definition: snpnet.c:46

References mode, _EFI_SIMPLE_NETWORK_PROTOCOL::Mode, netdev, netdev_link_down(), netdev_link_ok(), netdev_link_up(), net_device::priv, and snp_nic::snp.

Referenced by snpnet_poll(), and snpnet_start().

◆ snpnet_transmit()

static int snpnet_transmit ( struct net_device netdev,
struct io_buffer iobuf 
)
static

Transmit packet.

Parameters
netdevNetwork device
iobufI/O buffer
Return values
rcReturn status code

Definition at line 184 of file snpnet.c.

185  {
186  struct snp_nic *snp = netdev->priv;
187  EFI_STATUS efirc;
188  int rc;
189 
190  /* Do nothing if shutdown is in progress */
192  return -ECANCELED;
193 
194  /* Defer the packet if there is already a transmission in progress */
195  if ( snp->txbuf ) {
196  netdev_tx_defer ( netdev, iobuf );
197  return 0;
198  }
199 
200  /* Pad to minimum Ethernet length, to work around underlying
201  * drivers that do not correctly handle frame padding
202  * themselves.
203  */
204  iob_pad ( iobuf, ETH_ZLEN );
205 
206  /* Transmit packet */
207  if ( ( efirc = snp->snp->Transmit ( snp->snp, 0, iob_len ( iobuf ),
208  iobuf->data, NULL, NULL,
209  NULL ) ) != 0 ) {
210  rc = -EEFI ( efirc );
211  DBGC ( snp, "SNP %s could not transmit: %s\n",
212  netdev->name, strerror ( rc ) );
213  return rc;
214  }
215  snp->txbuf = iobuf;
216 
217  return 0;
218 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:174
void netdev_tx_defer(struct net_device *netdev, struct io_buffer *iobuf)
Defer transmitted packet.
Definition: netdevice.c:412
EFI_SIMPLE_NETWORK_PROTOCOL * snp
Simple network protocol.
Definition: snpnet.c:50
#define DBGC(...)
Definition: compiler.h:505
#define ECANCELED
Operation canceled.
Definition: errno.h:343
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
EFI_SIMPLE_NETWORK_TRANSMIT Transmit
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:159
An SNP NIC.
Definition: snpnet.c:46
#define ETH_ZLEN
Definition: if_ether.h:10
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
void * data
Start of data.
Definition: iobuf.h:52
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
void iob_pad(struct io_buffer *iobuf, size_t min_len)
Pad I/O buffer.
Definition: iobpad.c:49
int efi_shutdown_in_progress
EFI shutdown is in progress.
Definition: efi_init.c:59

References io_buffer::data, DBGC, ECANCELED, EEFI, efi_shutdown_in_progress, ETH_ZLEN, iob_len(), iob_pad(), net_device::name, netdev, netdev_tx_defer(), NULL, net_device::priv, rc, snp_nic::snp, strerror(), and _EFI_SIMPLE_NETWORK_PROTOCOL::Transmit.

◆ snpnet_poll_tx()

static void snpnet_poll_tx ( struct net_device netdev)
static

Poll for completed packets.

Parameters
netdevNetwork device

Definition at line 225 of file snpnet.c.

225  {
226  struct snp_nic *snp = netdev->priv;
227  struct io_buffer *iobuf;
228  UINT32 irq;
229  VOID *txbuf;
230  EFI_STATUS efirc;
231  int rc;
232 
233  /* Get status */
234  txbuf = NULL;
235  if ( ( efirc = snp->snp->GetStatus ( snp->snp, &irq, &txbuf ) ) != 0 ) {
236  rc = -EEFI ( efirc );
237  DBGC ( snp, "SNP %s could not get status: %s\n",
238  netdev->name, strerror ( rc ) );
239  netdev_rx_err ( netdev, NULL, rc );
240  return;
241  }
242 
243  /* Do nothing unless we have a completion */
244  if ( ! txbuf )
245  return;
246 
247  /* Sanity check */
248  if ( ! snp->txbuf ) {
249  DBGC ( snp, "SNP %s reported spurious TX completion\n",
250  netdev->name );
252  return;
253  }
254 
255  /* Complete transmission */
256  iobuf = snp->txbuf;
257  snp->txbuf = NULL;
258  netdev_tx_complete ( netdev, iobuf );
259 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void netdev_tx_complete(struct net_device *netdev, struct io_buffer *iobuf)
Complete network transmission.
Definition: netdevice.h:766
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:586
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:174
void netdev_tx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard transmitted packet.
Definition: netdevice.c:440
EFI_SIMPLE_NETWORK_PROTOCOL * snp
Simple network protocol.
Definition: snpnet.c:50
#define EPIPE
Broken pipe.
Definition: errno.h:619
#define DBGC(...)
Definition: compiler.h:505
unsigned int UINT32
Definition: ProcessorBind.h:98
struct io_buffer * txbuf
Current transmit buffer.
Definition: snpnet.c:62
void * priv
Driver private data.
Definition: netdevice.h:431
EFI_SIMPLE_NETWORK_GET_STATUS GetStatus
static struct net_device * netdev
Definition: gdbudp.c:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
An SNP NIC.
Definition: snpnet.c:46
#define VOID
Undeclared type.
Definition: Base.h:271
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
A persistent I/O buffer.
Definition: iobuf.h:37

References DBGC, EEFI, EPIPE, _EFI_SIMPLE_NETWORK_PROTOCOL::GetStatus, net_device::name, netdev, netdev_rx_err(), netdev_tx_complete(), netdev_tx_err(), NULL, net_device::priv, rc, snp_nic::snp, strerror(), snp_nic::txbuf, and VOID.

Referenced by snpnet_poll().

◆ snpnet_poll_rx()

static void snpnet_poll_rx ( struct net_device netdev)
static

Poll for received packets.

Parameters
netdevNetwork device

Definition at line 266 of file snpnet.c.

266  {
267  struct snp_nic *snp = netdev->priv;
268  UINTN len;
269  unsigned int quota;
270  EFI_STATUS efirc;
271  int rc;
272 
273  /* Retrieve up to SNP_RX_QUOTA packets */
274  for ( quota = SNP_RX_QUOTA ; quota ; quota-- ) {
275 
276  /* Allocate buffer, if required */
277  if ( ! snp->rxbuf ) {
278  snp->rxbuf = alloc_iob ( snp->mtu + SNP_RX_PAD );
279  if ( ! snp->rxbuf ) {
280  /* Leave for next poll */
281  break;
282  }
283  }
284 
285  /* Receive packet */
286  len = iob_tailroom ( snp->rxbuf );
287  if ( ( efirc = snp->snp->Receive ( snp->snp, NULL, &len,
288  snp->rxbuf->data, NULL,
289  NULL, NULL ) ) != 0 ) {
290 
291  /* EFI_NOT_READY is just the usual "no packet"
292  * status indication; ignore it.
293  */
294  if ( efirc == EFI_NOT_READY )
295  break;
296 
297  /* Anything else is an error */
298  rc = -EEFI ( efirc );
299  DBGC ( snp, "SNP %s could not receive: %s\n",
300  netdev->name, strerror ( rc ) );
301  netdev_rx_err ( netdev, NULL, rc );
302  break;
303  }
304 
305  /* Hand off to network stack */
306  iob_put ( snp->rxbuf, len );
307  netdev_rx ( netdev, snp->rxbuf );
308  snp->rxbuf = NULL;
309  }
310 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define iob_put(iobuf, len)
Definition: iobuf.h:124
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:586
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:174
#define SNP_RX_PAD
Additional padding for receive buffers.
Definition: snpnet.c:87
EFI_SIMPLE_NETWORK_PROTOCOL * snp
Simple network protocol.
Definition: snpnet.c:50
#define DBGC(...)
Definition: compiler.h:505
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:130
void * priv
Driver private data.
Definition: netdevice.h:431
ring len
Length.
Definition: dwmac.h:231
static struct net_device * netdev
Definition: gdbudp.c:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
An SNP NIC.
Definition: snpnet.c:46
static size_t iob_tailroom(struct io_buffer *iobuf)
Calculate available space at end of an I/O buffer.
Definition: iobuf.h:179
UINT64 UINTN
Unsigned value of native width.
#define EFI_NOT_READY
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:120
#define SNP_RX_QUOTA
Maximum number of received packets per poll.
Definition: snpnet.c:68
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition: netdevice.c:548
EFI_SIMPLE_NETWORK_RECEIVE Receive
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References alloc_iob(), DBGC, EEFI, EFI_NOT_READY, iob_put, iob_tailroom(), len, net_device::name, netdev, netdev_rx(), netdev_rx_err(), NULL, net_device::priv, rc, _EFI_SIMPLE_NETWORK_PROTOCOL::Receive, snp_nic::snp, SNP_RX_PAD, SNP_RX_QUOTA, and strerror().

Referenced by snpnet_poll().

◆ snpnet_poll()

static void snpnet_poll ( struct net_device netdev)
static

Poll for completed packets.

Parameters
netdevNetwork device

Definition at line 317 of file snpnet.c.

317  {
318 
319  /* Do nothing if shutdown is in progress */
321  return;
322 
323  /* Process any TX completions */
325 
326  /* Process any RX completions */
328 
329  /* Check for link state changes */
331 }
static struct net_device * netdev
Definition: gdbudp.c:52
static void snpnet_check_link(struct net_device *netdev)
Check link state.
Definition: snpnet.c:161
static void snpnet_poll_tx(struct net_device *netdev)
Poll for completed packets.
Definition: snpnet.c:225
static void snpnet_poll_rx(struct net_device *netdev)
Poll for received packets.
Definition: snpnet.c:266
int efi_shutdown_in_progress
EFI shutdown is in progress.
Definition: efi_init.c:59

References efi_shutdown_in_progress, netdev, snpnet_check_link(), snpnet_poll_rx(), and snpnet_poll_tx().

◆ snpnet_rx_filters()

static int snpnet_rx_filters ( struct net_device netdev)
static

Set receive filters.

Parameters
netdevNetwork device
Return values
rcReturn status code

Definition at line 339 of file snpnet.c.

339  {
340  struct snp_nic *snp = netdev->priv;
341  UINT32 filters[] = {
342  snp->snp->Mode->ReceiveFilterMask,
352  };
353  unsigned int i;
354  EFI_STATUS efirc;
355  int rc;
356 
357  /* Try possible receive filters in turn */
358  for ( i = 0; i < ( sizeof ( filters ) / sizeof ( filters[0] ) ); i++ ) {
359  efirc = snp->snp->ReceiveFilters ( snp->snp, filters[i],
361  0, NULL );
362  if ( efirc == 0 )
363  return 0;
364  rc = -EEFI ( efirc );
365  DBGC ( snp, "SNP %s could not set receive filters %#02x (have "
366  "%#02x): %s\n", netdev->name, filters[i],
367  snp->snp->Mode->ReceiveFilterSetting, strerror ( rc ) );
368  }
369 
370  return rc;
371 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:174
EFI_SIMPLE_NETWORK_PROTOCOL * snp
Simple network protocol.
Definition: snpnet.c:50
#define DBGC(...)
Definition: compiler.h:505
#define EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST
unsigned int UINT32
Definition: ProcessorBind.h:98
#define EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST
EFI_SIMPLE_NETWORK_MODE * Mode
Pointer to the EFI_SIMPLE_NETWORK_MODE data for the device.
UINT32 ReceiveFilterSetting
The current multicast receive filter settings.
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST
An SNP NIC.
Definition: snpnet.c:46
#define TRUE
Definition: tlan.h:46
#define EFI_SIMPLE_NETWORK_RECEIVE_UNICAST
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
UINT32 ReceiveFilterMask
The multicast receive filter settings supported by the network interface.
EFI_SIMPLE_NETWORK_RECEIVE_FILTERS ReceiveFilters
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References DBGC, EEFI, EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST, EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST, EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST, EFI_SIMPLE_NETWORK_RECEIVE_UNICAST, _EFI_SIMPLE_NETWORK_PROTOCOL::Mode, net_device::name, netdev, NULL, net_device::priv, rc, EFI_SIMPLE_NETWORK_MODE::ReceiveFilterMask, _EFI_SIMPLE_NETWORK_PROTOCOL::ReceiveFilters, EFI_SIMPLE_NETWORK_MODE::ReceiveFilterSetting, snp_nic::snp, strerror(), and TRUE.

Referenced by snpnet_open().

◆ snpnet_open()

static int snpnet_open ( struct net_device netdev)
static

Open network device.

Parameters
netdevNetwork device
Return values
rcReturn status code

Definition at line 379 of file snpnet.c.

379  {
380  struct snp_nic *snp = netdev->priv;
381  EFI_MAC_ADDRESS *mac = ( ( void * ) netdev->ll_addr );
383  EFI_STATUS efirc;
384  unsigned int retry;
385  int rc;
386 
387  /* Try setting MAC address (before initialising) */
388  if ( ( efirc = snp->snp->StationAddress ( snp->snp, FALSE, mac ) ) !=0){
389  rc = -EEFI ( efirc );
390  DBGC ( snp, "SNP %s could not set station address before "
391  "initialising: %s\n", netdev->name, strerror ( rc ) );
392  /* Ignore error */
393  }
394 
395  /* Initialise NIC, retrying multiple times if link stays down */
396  for ( retry = 0 ; ; ) {
397 
398  /* Initialise NIC, if not already initialised */
399  if ( ( mode->State != EfiSimpleNetworkInitialized ) &&
400  ( ( efirc = snp->snp->Initialize ( snp->snp,
401  0, 0 ) ) != 0 ) ) {
402  rc = -EEFI ( efirc );
404  DBGC ( snp, "SNP %s could not initialise: %s\n",
405  netdev->name, strerror ( rc ) );
406  return rc;
407  }
408 
409  /* Stop if we have link up (or no link detection capability) */
410  if ( ( ! mode->MediaPresentSupported ) || mode->MediaPresent )
411  break;
412 
413  /* Stop if we have exceeded our retry count. This is
414  * not a failure; it is plausible that we genuinely do
415  * not have link up.
416  */
417  if ( ++retry >= SNP_INITIALIZE_RETRY_MAX )
418  break;
419  DBGC ( snp, "SNP %s retrying initialisation (retry %d)\n",
420  netdev->name, retry );
421 
422  /* Delay to allow time for link to establish */
424 
425  /* Shut down and retry (unless device is insomniac);
426  * this is sometimes necessary in order to persuade
427  * the underlying SNP driver to actually update the
428  * link state.
429  */
430  if ( ( ! netdev_insomniac ( netdev ) ) &&
431  ( ( efirc = snp->snp->Shutdown ( snp->snp ) ) != 0 ) ) {
432  rc = -EEFI ( efirc );
434  DBGC ( snp, "SNP %s could not shut down: %s\n",
435  netdev->name, strerror ( rc ) );
436  return rc;
437  }
438  }
439 
440  /* Try setting MAC address (after initialising) */
441  if ( ( efirc = snp->snp->StationAddress ( snp->snp, FALSE, mac ) ) !=0){
442  rc = -EEFI ( efirc );
443  DBGC ( snp, "SNP %s could not set station address after "
444  "initialising: %s\n", netdev->name, strerror ( rc ) );
445  /* Ignore error */
446  }
447 
448  /* Set receive filters */
449  if ( ( rc = snpnet_rx_filters ( netdev ) ) != 0 ) {
450  /* Ignore error */
451  }
452 
453  /* Dump mode information (for debugging) */
455 
456  return 0;
457 }
EFI_SIMPLE_NETWORK_STATION_ADDRESS StationAddress
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void snpnet_dump_mode(struct net_device *netdev)
Dump SNP mode information (for debugging)
Definition: snpnet.c:122
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:174
EFI_SIMPLE_NETWORK_PROTOCOL * snp
Simple network protocol.
Definition: snpnet.c:50
32-byte buffer containing a network Media Access Control address.
Definition: UefiBaseType.h:97
uint16_t mode
Acceleration mode.
Definition: ena.h:26
static int netdev_insomniac(struct net_device *netdev)
Check whether or not network device must be polled even while closed.
Definition: netdevice.h:706
#define DBGC(...)
Definition: compiler.h:505
uint8_t mac[ETH_ALEN]
MAC address.
Definition: ena.h:24
EFI_SIMPLE_NETWORK_MODE * Mode
Pointer to the EFI_SIMPLE_NETWORK_MODE data for the device.
EFI_SIMPLE_NETWORK_INITIALIZE Initialize
void * priv
Driver private data.
Definition: netdevice.h:431
EFI_SIMPLE_NETWORK_SHUTDOWN Shutdown
static struct net_device * netdev
Definition: gdbudp.c:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
An SNP NIC.
Definition: snpnet.c:46
static int snpnet_rx_filters(struct net_device *netdev)
Set receive filters.
Definition: snpnet.c:339
#define SNP_INITIALIZE_RETRY_MAX
Maximum initialisation retry count.
Definition: snpnet.c:71
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
#define FALSE
Definition: tlan.h:45
#define SNP_INITIALIZE_RETRY_DELAY_MS
Delay between each initialisation retry.
Definition: snpnet.c:74
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:387

References DBGC, EEFI, EfiSimpleNetworkInitialized, FALSE, _EFI_SIMPLE_NETWORK_PROTOCOL::Initialize, net_device::ll_addr, mac, mdelay(), mode, _EFI_SIMPLE_NETWORK_PROTOCOL::Mode, net_device::name, netdev, netdev_insomniac(), net_device::priv, rc, _EFI_SIMPLE_NETWORK_PROTOCOL::Shutdown, snp_nic::snp, SNP_INITIALIZE_RETRY_DELAY_MS, SNP_INITIALIZE_RETRY_MAX, snpnet_dump_mode(), snpnet_rx_filters(), _EFI_SIMPLE_NETWORK_PROTOCOL::StationAddress, and strerror().

◆ snpnet_close()

static void snpnet_close ( struct net_device netdev)
static

Close network device.

Parameters
netdevNetwork device

Definition at line 464 of file snpnet.c.

464  {
465  struct snp_nic *snp = netdev->priv;
466  EFI_STATUS efirc;
467  int rc;
468 
469  /* Shut down NIC (unless whole system shutdown is in progress,
470  * or device is insomniac).
471  */
472  if ( ( ! efi_shutdown_in_progress ) &&
473  ( ! netdev_insomniac ( netdev ) ) &&
474  ( ( efirc = snp->snp->Shutdown ( snp->snp ) ) != 0 ) ) {
475  rc = -EEFI ( efirc );
476  DBGC ( snp, "SNP %s could not shut down: %s\n",
477  netdev->name, strerror ( rc ) );
478  /* Nothing we can do about this */
479  }
480 
481  /* Discard transmit buffer, if applicable */
482  if ( snp->txbuf ) {
484  snp->txbuf = NULL;
485  }
486 
487  /* Discard receive buffer, if applicable */
488  if ( snp->rxbuf ) {
489  free_iob ( snp->rxbuf );
490  snp->rxbuf = NULL;
491  }
492 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:174
EFI_SIMPLE_NETWORK_PROTOCOL * snp
Simple network protocol.
Definition: snpnet.c:50
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:152
static int netdev_insomniac(struct net_device *netdev)
Check whether or not network device must be polled even while closed.
Definition: netdevice.h:706
#define DBGC(...)
Definition: compiler.h:505
#define ECANCELED
Operation canceled.
Definition: errno.h:343
void * priv
Driver private data.
Definition: netdevice.h:431
EFI_SIMPLE_NETWORK_SHUTDOWN Shutdown
static struct net_device * netdev
Definition: gdbudp.c:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
An SNP NIC.
Definition: snpnet.c:46
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
Definition: netdevice.c:470
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
int efi_shutdown_in_progress
EFI shutdown is in progress.
Definition: efi_init.c:59

References DBGC, ECANCELED, EEFI, efi_shutdown_in_progress, free_iob(), net_device::name, netdev, netdev_insomniac(), netdev_tx_complete_err(), NULL, net_device::priv, rc, _EFI_SIMPLE_NETWORK_PROTOCOL::Shutdown, snp_nic::snp, and strerror().

◆ snpnet_supported()

int snpnet_supported ( EFI_HANDLE  device,
EFI_GUID protocol,
int  inhibit_wifi 
)

Check to see if driver supports a device.

Parameters
deviceEFI device handle
protocolProtocol GUID
inhibit_wifiInhibit wireless devices
Return values
rcReturn status code

Definition at line 510 of file snpnet.c.

511  {
512  EFI_HANDLE parent;
513  int rc;
514 
515  /* Check that this is not a device we are providing ourselves */
516  if ( find_snpdev ( device ) != NULL ) {
517  DBGCP ( device, "HANDLE %s is provided by this binary\n",
518  efi_handle_name ( device ) );
519  return -ENOTTY;
520  }
521 
522  /* Test for presence of protocol */
523  if ( ( rc = efi_test ( device, protocol ) ) != 0 ) {
524  DBGCP ( device, "HANDLE %s is not a %s device\n",
526  efi_guid_ntoa ( protocol ) );
527  return rc;
528  }
529 
530  /* Check that there are no instances of this protocol further
531  * up this device path.
532  */
533  if ( ( rc = efi_locate_device ( device, protocol,
534  &parent, 1 ) ) == 0 ) {
535  DBGC2 ( device, "HANDLE %s has %s-supporting parent ",
537  efi_guid_ntoa ( protocol ) );
538  DBGC2 ( device, "%s\n", efi_handle_name ( parent ) );
539  return -ENOTTY;
540  }
541  DBGC ( device, "HANDLE %s is a %s device\n",
543 
544  /* Check for wireless devices, if applicable */
545  if ( inhibit_wifi &&
546  ( ( efi_test ( device, &efi_wifi2_protocol_guid ) ) == 0 ) ) {
547  DBGC ( device, "HANDLE %s is wireless: assuming vendor %s "
548  "driver is too unreliable to use\n",
550  efi_guid_ntoa ( protocol ) );
551  return -ENOTTY;
552  }
553 
554  return 0;
555 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define efi_test(handle, protocol)
Test protocol existence.
Definition: efi.h:432
#define DBGC(...)
Definition: compiler.h:505
A hardware device.
Definition: device.h:76
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:652
int efi_locate_device(EFI_HANDLE device, EFI_GUID *protocol, EFI_HANDLE *parent, unsigned int skip)
Locate parent device supporting a given protocol.
Definition: efi_utils.c:45
const char * efi_guid_ntoa(CONST EFI_GUID *guid)
Convert GUID to a printable string.
Definition: efi_guid.c:725
EFI_GUID efi_wifi2_protocol_guid
WiFi 2 protocol GUID.
Definition: efi_guid.c:436
struct efi_snp_device * find_snpdev(EFI_HANDLE handle)
Find SNP device by EFI device handle.
Definition: efi_snp.c:2103
#define DBGC2(...)
Definition: compiler.h:522
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:594
#define DBGCP(...)
Definition: compiler.h:539
uint16_t protocol
Protocol ID.
Definition: stp.h:18
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
Definition: efi.h:61

References DBGC, DBGC2, DBGCP, efi_guid_ntoa(), efi_handle_name(), efi_locate_device(), efi_test, efi_wifi2_protocol_guid, ENOTTY, find_snpdev(), NULL, protocol, and rc.

Referenced by mnp_supported(), nii_supported(), and snp_supported().

◆ snpnet_is_insomniac()

static int snpnet_is_insomniac ( EFI_HANDLE  device)
static

Check if device must be insomniac.

Parameters
deviceEFI device handle
is_insomniacDevice must be insomniac

Definition at line 563 of file snpnet.c.

563  {
564  int rc;
565 
566  /* Check for wireless devices
567  *
568  * The UEFI model for wireless network configuration is
569  * somewhat underdefined. At the time of writing, the EDK2
570  * "UEFI WiFi Connection Manager" driver provides only one way
571  * to configure wireless network credentials, which is to
572  * enter them interactively via an HII form. Credentials are
573  * not stored (or exposed via any protocol interface), and so
574  * any temporary disconnection from the wireless network will
575  * inevitably leave the interface in an unusable state that
576  * cannot be recovered without user intervention.
577  *
578  * Experimentation shows that at least some wireless network
579  * drivers will disconnect from the wireless network when the
580  * SNP Shutdown() method is called, or if the device is not
581  * polled sufficiently frequently to maintain its association
582  * to the network. We therefore inhibit calls to Shutdown()
583  * and Stop() for any such SNP protocol interfaces, and mark
584  * our network device as insomniac so that it will be polled
585  * even when closed.
586  */
587  if ( ( rc = efi_test ( device, &efi_wifi2_protocol_guid ) ) == 0 ) {
588  DBGC ( device, "SNP %s is wireless: assuming insomniac\n",
589  efi_handle_name ( device ) );
590  return 1;
591  }
592 
593  return 0;
594 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define efi_test(handle, protocol)
Test protocol existence.
Definition: efi.h:432
#define DBGC(...)
Definition: compiler.h:505
A hardware device.
Definition: device.h:76
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:652
EFI_GUID efi_wifi2_protocol_guid
WiFi 2 protocol GUID.
Definition: efi_guid.c:436

References DBGC, efi_handle_name(), efi_test, efi_wifi2_protocol_guid, and rc.

Referenced by snpnet_exclude(), and snpnet_start().

◆ snpnet_do_nothing()

static EFI_STATUS EFIAPI snpnet_do_nothing ( EFI_SIMPLE_NETWORK_PROTOCOL *snp  __unused)
static

Ignore shutdown attempt.

Parameters
snpSNP interface
Return values
efircEFI status code

Definition at line 603 of file snpnet.c.

603  {
604 
605  return 0;
606 }

Referenced by snpnet_insomniac_patch(), and snpnet_insomniac_restore().

◆ snpnet_insomniac_patch()

static int snpnet_insomniac_patch ( EFI_HANDLE  device,
struct snp_insomniac_patch patch 
)
static

Patch SNP protocol interface to prevent shutdown.

Parameters
deviceEFI device handle
patchInterface patch
Return values
rcReturn status code

Definition at line 615 of file snpnet.c.

616  {
618  int rc;
619 
620  /* Open interface for ephemeral use */
622  &interface ) ) != 0 ) {
623  DBGC ( device, "SNP %s cannot open SNP protocol for patching: "
624  "%s\n", efi_handle_name ( device ), strerror ( rc ) );
625  return rc;
626  }
627 
628  /* Record original Shutdown() and Stop() methods */
629  patch->shutdown = interface->Shutdown;
630  patch->stop = interface->Stop;
631 
632  /* Inhibit other UEFI drivers' calls to Shutdown() and Stop()
633  *
634  * This is necessary since disconnecting the MnpDxe driver
635  * will attempt to shut down the SNP device, which would leave
636  * us with an unusable device.
637  */
638  interface->Shutdown = snpnet_do_nothing;
640  DBGC ( device, "SNP %s patched to inhibit shutdown\n",
641  efi_handle_name ( device ) );
642 
643  return 0;
644 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
The EFI_SIMPLE_NETWORK_PROTOCOL protocol is used to initialize access to a network adapter.
EFI_GUID efi_simple_network_protocol_guid
Simple network protocol GUID.
Definition: efi_guid.c:340
#define DBGC(...)
Definition: compiler.h:505
A hardware device.
Definition: device.h:76
EFI_SIMPLE_NETWORK_STOP stop
Original Stop() method.
Definition: snpnet.c:94
An object interface.
Definition: interface.h:124
EFI_SIMPLE_NETWORK_SHUTDOWN shutdown
Original Shutdown() method.
Definition: snpnet.c:92
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:652
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static EFI_STATUS EFIAPI snpnet_do_nothing(EFI_SIMPLE_NETWORK_PROTOCOL *snp __unused)
Ignore shutdown attempt.
Definition: snpnet.c:603
#define efi_open(handle, protocol, interface)
Open protocol for ephemeral use.
Definition: efi.h:443

References DBGC, efi_handle_name(), efi_open, efi_simple_network_protocol_guid, rc, snp_insomniac_patch::shutdown, snpnet_do_nothing(), snp_insomniac_patch::stop, and strerror().

Referenced by snpnet_exclude().

◆ snpnet_insomniac_restore()

static int snpnet_insomniac_restore ( EFI_HANDLE  device,
struct snp_insomniac_patch patch 
)
static

Restore patched SNP protocol interface.

Parameters
deviceEFI device handle
patchInterface patch to fill in
Return values
rcReturn status code

Definition at line 653 of file snpnet.c.

654  {
656  int rc;
657 
658  /* Avoid returning uninitialised data on error */
659  memset ( patch, 0, sizeof ( *patch ) );
660 
661  /* Open interface for ephemeral use */
663  &interface ) ) != 0 ) {
664  DBGC ( device, "SNP %s cannot open patched SNP protocol: %s\n",
665  efi_handle_name ( device ), strerror ( rc ) );
666  return rc;
667  }
668 
669  /* Restore original Shutdown() and Stop() methods, if possible */
670  if ( interface->Shutdown == snpnet_do_nothing )
671  interface->Shutdown = patch->shutdown;
672  if ( interface->Stop == snpnet_do_nothing )
673  interface->Stop = patch->stop;
674 
675  /* Check that original methods were restored (by us or others) */
676  if ( ( interface->Shutdown != patch->shutdown ) ||
677  ( interface->Stop != patch->stop ) ) {
678  DBGC ( device, "SNP %s could not restore patched SNP "
679  "protocol\n", efi_handle_name ( device ) );
680  return -EBUSY;
681  }
682 
683  return 0;
684 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
The EFI_SIMPLE_NETWORK_PROTOCOL protocol is used to initialize access to a network adapter.
#define EBUSY
Device or resource busy.
Definition: errno.h:338
EFI_GUID efi_simple_network_protocol_guid
Simple network protocol GUID.
Definition: efi_guid.c:340
#define DBGC(...)
Definition: compiler.h:505
A hardware device.
Definition: device.h:76
EFI_SIMPLE_NETWORK_STOP stop
Original Stop() method.
Definition: snpnet.c:94
An object interface.
Definition: interface.h:124
EFI_SIMPLE_NETWORK_SHUTDOWN shutdown
Original Shutdown() method.
Definition: snpnet.c:92
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:652
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static EFI_STATUS EFIAPI snpnet_do_nothing(EFI_SIMPLE_NETWORK_PROTOCOL *snp __unused)
Ignore shutdown attempt.
Definition: snpnet.c:603
#define efi_open(handle, protocol, interface)
Open protocol for ephemeral use.
Definition: efi.h:443
void * memset(void *dest, int character, size_t len) __nonnull

References DBGC, EBUSY, efi_handle_name(), efi_open, efi_simple_network_protocol_guid, memset(), rc, snp_insomniac_patch::shutdown, snpnet_do_nothing(), snp_insomniac_patch::stop, and strerror().

Referenced by snpnet_exclude().

◆ snpnet_exclude()

int snpnet_exclude ( EFI_HANDLE  device)

Exclude existing drivers.

Parameters
deviceEFI device handle
Return values
rcReturn status code

Definition at line 692 of file snpnet.c.

692  {
694  struct snp_insomniac_patch patch;
695  int insomniac;
696  int rc;
697 
698  /* Check if this is a device that must not ever be shut down */
699  insomniac = snpnet_is_insomniac ( device );
700 
701  /* Inhibit calls to Shutdown() and Stop(), if applicable */
702  if ( insomniac &&
703  ( ( rc = snpnet_insomniac_patch ( device, &patch ) ) != 0 ) ) {
704  goto err_patch;
705  }
706 
707  /* Exclude existing SNP drivers */
708  if ( ( rc = efi_driver_exclude ( device, protocol ) ) != 0 ) {
709  DBGC ( device, "SNP %s could not exclude drivers: %s\n",
710  efi_handle_name ( device ), strerror ( rc ) );
711  goto err_exclude;
712  }
713 
714  err_exclude:
715  if ( insomniac )
716  snpnet_insomniac_restore ( device, &patch );
717  err_patch:
718  return rc;
719 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
128 bit buffer containing a unique identifier value.
Definition: Base.h:215
EFI_GUID efi_simple_network_protocol_guid
Simple network protocol GUID.
Definition: efi_guid.c:340
#define DBGC(...)
Definition: compiler.h:505
static int snpnet_insomniac_restore(EFI_HANDLE device, struct snp_insomniac_patch *patch)
Restore patched SNP protocol interface.
Definition: snpnet.c:653
An SNP interface patch to inhibit shutdown for insomniac devices.
Definition: snpnet.c:90
A hardware device.
Definition: device.h:76
static int snpnet_is_insomniac(EFI_HANDLE device)
Check if device must be insomniac.
Definition: snpnet.c:563
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:652
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
int efi_driver_exclude(EFI_HANDLE device, EFI_GUID *protocol)
Try to disconnect an existing EFI driver.
Definition: efi_driver.c:437
static int snpnet_insomniac_patch(EFI_HANDLE device, struct snp_insomniac_patch *patch)
Patch SNP protocol interface to prevent shutdown.
Definition: snpnet.c:615
uint16_t protocol
Protocol ID.
Definition: stp.h:18

References DBGC, efi_driver_exclude(), efi_handle_name(), efi_simple_network_protocol_guid, protocol, rc, snpnet_insomniac_patch(), snpnet_insomniac_restore(), snpnet_is_insomniac(), and strerror().

◆ snpnet_start()

int snpnet_start ( struct efi_device efidev)

Attach driver to device.

Parameters
efidevEFI device
Return values
rcReturn status code

Definition at line 727 of file snpnet.c.

727  {
728  EFI_HANDLE device = efidev->device;
731  struct net_device *netdev;
732  struct snp_nic *snp;
733  EFI_STATUS efirc;
734  int rc;
735 
736  /* Open SNP protocol */
737  if ( ( rc = efi_open_by_driver ( device,
739  &interface ) ) != 0 ) {
740  DBGC ( device, "SNP %s cannot open SNP protocol: %s\n",
741  efi_handle_name ( device ), strerror ( rc ) );
744  goto err_open_protocol;
745  }
746 
747  /* Allocate and initialise structure */
748  netdev = alloc_etherdev ( sizeof ( *snp ) );
749  if ( ! netdev ) {
750  rc = -ENOMEM;
751  goto err_alloc;
752  }
754  snp = netdev->priv;
755  snp->efidev = efidev;
756  snp->snp = interface;
757  mode = snp->snp->Mode;
759 
760  /* Populate underlying device information */
761  efi_device_info ( device, "SNP", &snp->dev );
762  snp->dev.driver_name = "SNP";
763  snp->dev.parent = &efidev->dev;
764  list_add ( &snp->dev.siblings, &efidev->dev.children );
765  INIT_LIST_HEAD ( &snp->dev.children );
766  netdev->dev = &snp->dev;
767 
768  /* Check if device is insomniac */
769  if ( snpnet_is_insomniac ( device ) )
771 
772  /* Bring to the correct state for a closed interface */
773  if ( ( mode->State == EfiSimpleNetworkStopped ) &&
774  ( ( efirc = snp->snp->Start ( snp->snp ) ) != 0 ) ) {
775  rc = -EEFI ( efirc );
776  DBGC ( device, "SNP %s could not start: %s\n",
777  efi_handle_name ( device ), strerror ( rc ) );
778  goto err_start;
779  }
780  if ( ( mode->State == EfiSimpleNetworkInitialized ) &&
781  ( ! netdev_insomniac ( netdev ) ) &&
782  ( ( efirc = snp->snp->Shutdown ( snp->snp ) ) != 0 ) ) {
783  rc = -EEFI ( efirc );
784  DBGC ( device, "SNP %s could not shut down: %s\n",
785  efi_handle_name ( device ), strerror ( rc ) );
786  goto err_shutdown;
787  }
788 
789  /* Populate network device parameters */
790  if ( mode->HwAddressSize != netdev->ll_protocol->hw_addr_len ) {
791  DBGC ( device, "SNP %s has invalid hardware address length "
792  "%d\n", efi_handle_name ( device ), mode->HwAddressSize);
793  rc = -ENOTSUP;
794  goto err_hw_addr_len;
795  }
796  memcpy ( netdev->hw_addr, &mode->PermanentAddress,
798  if ( mode->HwAddressSize != netdev->ll_protocol->ll_addr_len ) {
799  DBGC ( device, "SNP %s has invalid link-layer address length "
800  "%d\n", efi_handle_name ( device ), mode->HwAddressSize);
801  rc = -ENOTSUP;
802  goto err_ll_addr_len;
803  }
804  memcpy ( netdev->ll_addr, &mode->CurrentAddress,
806  snp->mtu = ( snp->snp->Mode->MaxPacketSize +
807  snp->snp->Mode->MediaHeaderSize );
808 
809  /* Register network device */
810  if ( ( rc = register_netdev ( netdev ) ) != 0 )
811  goto err_register_netdev;
812  DBGC ( device, "SNP %s registered as %s\n",
814 
815  /* Set initial link state */
816  if ( snp->snp->Mode->MediaPresentSupported ) {
818  } else {
820  }
821 
822  return 0;
823 
825  err_register_netdev:
826  err_ll_addr_len:
827  err_hw_addr_len:
828  err_shutdown:
829  err_start:
830  list_del ( &snp->dev.siblings );
832  netdev_put ( netdev );
833  err_alloc:
835  err_open_protocol:
836  return rc;
837 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
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.
Definition: efi.h:174
uint8_t ll_addr_len
Link-layer address length.
Definition: netdevice.h:198
UINT32 MediaHeaderSize
The size, in bytes, of the network interface's media header.
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:69
EFI_SIMPLE_NETWORK_PROTOCOL * snp
Simple network protocol.
Definition: snpnet.c:50
uint16_t mode
Acceleration mode.
Definition: ena.h:26
static int netdev_insomniac(struct net_device *netdev)
Check whether or not network device must be polled even while closed.
Definition: netdevice.h:706
EFI_GUID efi_simple_network_protocol_guid
Simple network protocol GUID.
Definition: efi_guid.c:340
#define DBGC(...)
Definition: compiler.h:505
unsigned int state
Current device state.
Definition: netdevice.h:395
BOOLEAN MediaPresentSupported
TRUE if the presence of media can be determined; otherwise FALSE.
#define DBGC_EFI_OPENERS(...)
Definition: efi.h:344
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:21
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
EFI_SIMPLE_NETWORK_MODE * Mode
Pointer to the EFI_SIMPLE_NETWORK_MODE data for the device.
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:518
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
UINT32 MaxPacketSize
The maximum size, in bytes, of the packets supported by the network interface.
#define ENOMEM
Not enough space.
Definition: errno.h:534
A hardware device.
Definition: device.h:76
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:575
An object interface.
Definition: interface.h:124
void efi_close_by_driver(EFI_HANDLE handle, EFI_GUID *protocol)
Close protocol opened for persistent use by a driver.
Definition: efi_open.c:278
uint8_t hw_addr_len
Hardware address length.
Definition: netdevice.h:196
void * priv
Driver private data.
Definition: netdevice.h:431
EFI_SIMPLE_NETWORK_SHUTDOWN Shutdown
#define efi_open_by_driver(handle, protocol, interface)
Open protocol for persistent use by a driver.
Definition: efi.h:473
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:788
static struct net_device * netdev
Definition: gdbudp.c:52
static void snpnet_check_link(struct net_device *netdev)
Check link state.
Definition: snpnet.c:161
static int snpnet_is_insomniac(EFI_HANDLE device)
Check if device must be insomniac.
Definition: snpnet.c:563
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:941
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:652
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:759
A network device.
Definition: netdevice.h:352
An SNP NIC.
Definition: snpnet.c:46
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:531
EFI_SIMPLE_NETWORK_START Start
struct efi_device * efidev
EFI device.
Definition: snpnet.c:48
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
struct list_head children
Devices attached to this device.
Definition: device.h:86
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition: ethernet.c:264
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:387
static void efidev_set_drvdata(struct efi_device *efidev, void *priv)
Set EFI driver-private data.
Definition: efi_driver.h:83
struct device dev
Generic device.
Definition: efi_driver.h:19
#define NETDEV_INSOMNIAC
Network device must be polled even when closed.
Definition: netdevice.h:461
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:381
static struct net_device_operations snpnet_operations
SNP network device operations.
Definition: snpnet.c:495
Definition: efi.h:61
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:372
void efi_device_info(EFI_HANDLE device, const char *prefix, struct device *dev)
Get underlying device information.
Definition: efi_utils.c:188

References alloc_etherdev(), device::children, DBGC, DBGC_EFI_OPENERS, efi_device::dev, net_device::dev, efi_device::device, EEFI, efi_close_by_driver(), efi_device_info(), efi_handle_name(), efi_open_by_driver, efi_simple_network_protocol_guid, snp_nic::efidev, efidev_set_drvdata(), EfiSimpleNetworkInitialized, EfiSimpleNetworkStopped, ENOMEM, ENOTSUP, net_device::hw_addr, ll_protocol::hw_addr_len, INIT_LIST_HEAD, list_add, list_del, net_device::ll_addr, ll_protocol::ll_addr_len, net_device::ll_protocol, EFI_SIMPLE_NETWORK_MODE::MaxPacketSize, EFI_SIMPLE_NETWORK_MODE::MediaHeaderSize, EFI_SIMPLE_NETWORK_MODE::MediaPresentSupported, memcpy(), mode, _EFI_SIMPLE_NETWORK_PROTOCOL::Mode, net_device::name, netdev, netdev_init(), NETDEV_INSOMNIAC, netdev_insomniac(), netdev_link_up(), netdev_nullify(), netdev_put(), net_device::priv, rc, register_netdev(), _EFI_SIMPLE_NETWORK_PROTOCOL::Shutdown, snp_nic::snp, snpnet_check_link(), snpnet_is_insomniac(), snpnet_operations, _EFI_SIMPLE_NETWORK_PROTOCOL::Start, net_device::state, strerror(), and unregister_netdev().

◆ snpnet_stop()

void snpnet_stop ( struct efi_device efidev)

Detach driver from device.

Parameters
efidevEFI device

Definition at line 844 of file snpnet.c.

844  {
845  struct net_device *netdev = efidev_get_drvdata ( efidev );
846  struct snp_nic *snp = netdev->priv;
848  EFI_STATUS efirc;
849  int rc;
850 
851  /* Unregister network device */
853 
854  /* Stop SNP protocol (unless whole system shutdown is in progress) */
855  if ( ( ! efi_shutdown_in_progress ) &&
856  ( ( efirc = snp->snp->Stop ( snp->snp ) ) != 0 ) ) {
857  rc = -EEFI ( efirc );
858  DBGC ( device, "SNP %s could not stop: %s\n",
859  efi_handle_name ( device ), strerror ( rc ) );
860  /* Nothing we can do about this */
861  }
862 
863  /* Free network device */
864  list_del ( &snp->dev.siblings );
866  netdev_put ( netdev );
867 
868  /* Close SNP protocol */
870 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:174
EFI_SIMPLE_NETWORK_PROTOCOL * snp
Simple network protocol.
Definition: snpnet.c:50
EFI_GUID efi_simple_network_protocol_guid
Simple network protocol GUID.
Definition: efi_guid.c:340
#define DBGC(...)
Definition: compiler.h:505
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:21
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
A hardware device.
Definition: device.h:76
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:575
void efi_close_by_driver(EFI_HANDLE handle, EFI_GUID *protocol)
Close protocol opened for persistent use by a driver.
Definition: efi_open.c:278
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:941
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:652
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void * efidev_get_drvdata(struct efi_device *efidev)
Get EFI driver-private data.
Definition: efi_driver.h:94
A network device.
Definition: netdevice.h:352
An SNP NIC.
Definition: snpnet.c:46
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:531
struct efi_device * efidev
EFI device.
Definition: snpnet.c:48
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
EFI_SIMPLE_NETWORK_STOP Stop
Definition: efi.h:61
int efi_shutdown_in_progress
EFI shutdown is in progress.
Definition: efi_init.c:59

References DBGC, efi_device::device, EEFI, efi_close_by_driver(), efi_handle_name(), efi_shutdown_in_progress, efi_simple_network_protocol_guid, snp_nic::efidev, efidev_get_drvdata(), list_del, netdev, netdev_nullify(), netdev_put(), net_device::priv, rc, snp_nic::snp, _EFI_SIMPLE_NETWORK_PROTOCOL::Stop, strerror(), and unregister_netdev().

Variable Documentation

◆ snpnet_operations

struct net_device_operations snpnet_operations
static
Initial value:
= {
.open = snpnet_open,
.close = snpnet_close,
.transmit = snpnet_transmit,
.poll = snpnet_poll,
}
static void snpnet_poll(struct net_device *netdev)
Poll for completed packets.
Definition: snpnet.c:317
static int snpnet_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: snpnet.c:184
static void snpnet_close(struct net_device *netdev)
Close network device.
Definition: snpnet.c:464
static int snpnet_open(struct net_device *netdev)
Open network device.
Definition: snpnet.c:379

SNP network device operations.

Definition at line 495 of file snpnet.c.

Referenced by snpnet_start().