iPXE
Functions
snpnet.h File Reference

SNP NIC driver. More...

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
 
int snpnet_start (struct efi_device *efidev)
 Attach driver to device. More...
 
void snpnet_stop (struct efi_device *efidev)
 Detach driver from device. More...
 

Detailed Description

SNP NIC driver.

Definition in file snpnet.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER  )

◆ snpnet_start()

int snpnet_start ( struct efi_device efidev)

Attach driver to device.

Parameters
efidevEFI device
Return values
rcReturn status code

Definition at line 422 of file snpnet.c.

422  {
426  struct net_device *netdev;
427  struct snp_nic *snp;
428  void *interface;
429  EFI_STATUS efirc;
430  int rc;
431 
432  /* Open SNP protocol */
433  if ( ( efirc = bs->OpenProtocol ( device,
438  rc = -EEFI ( efirc );
439  DBGC ( device, "SNP %s cannot open SNP protocol: %s\n",
440  efi_handle_name ( device ), strerror ( rc ) );
443  goto err_open_protocol;
444  }
445 
446  /* Allocate and initialise structure */
447  netdev = alloc_etherdev ( sizeof ( *snp ) );
448  if ( ! netdev ) {
449  rc = -ENOMEM;
450  goto err_alloc;
451  }
453  snp = netdev->priv;
454  snp->efidev = efidev;
455  snp->snp = interface;
456  mode = snp->snp->Mode;
458 
459  /* Populate underlying device information */
460  efi_device_info ( device, "SNP", &snp->dev );
461  snp->dev.driver_name = "SNP";
462  snp->dev.parent = &efidev->dev;
463  list_add ( &snp->dev.siblings, &efidev->dev.children );
464  INIT_LIST_HEAD ( &snp->dev.children );
465  netdev->dev = &snp->dev;
466 
467  /* Bring to the Started state */
468  if ( ( mode->State == EfiSimpleNetworkStopped ) &&
469  ( ( efirc = snp->snp->Start ( snp->snp ) ) != 0 ) ) {
470  rc = -EEFI ( efirc );
471  DBGC ( device, "SNP %s could not start: %s\n",
472  efi_handle_name ( device ), strerror ( rc ) );
473  goto err_start;
474  }
475  if ( ( mode->State == EfiSimpleNetworkInitialized ) &&
476  ( ( efirc = snp->snp->Shutdown ( snp->snp ) ) != 0 ) ) {
477  rc = -EEFI ( efirc );
478  DBGC ( device, "SNP %s could not shut down: %s\n",
479  efi_handle_name ( device ), strerror ( rc ) );
480  goto err_shutdown;
481  }
482 
483  /* Populate network device parameters */
484  if ( mode->HwAddressSize != netdev->ll_protocol->hw_addr_len ) {
485  DBGC ( device, "SNP %s has invalid hardware address length "
486  "%d\n", efi_handle_name ( device ), mode->HwAddressSize);
487  rc = -ENOTSUP;
488  goto err_hw_addr_len;
489  }
492  if ( mode->HwAddressSize != netdev->ll_protocol->ll_addr_len ) {
493  DBGC ( device, "SNP %s has invalid link-layer address length "
494  "%d\n", efi_handle_name ( device ), mode->HwAddressSize);
495  rc = -ENOTSUP;
496  goto err_ll_addr_len;
497  }
498  memcpy ( netdev->ll_addr, &mode->CurrentAddress,
500  snp->mtu = ( snp->snp->Mode->MaxPacketSize +
501  snp->snp->Mode->MediaHeaderSize );
502 
503  /* Register network device */
504  if ( ( rc = register_netdev ( netdev ) ) != 0 )
505  goto err_register_netdev;
506  DBGC ( device, "SNP %s registered as %s\n",
508 
509  /* Set initial link state */
510  if ( snp->snp->Mode->MediaPresentSupported ) {
512  } else {
514  }
515 
516  return 0;
517 
519  err_register_netdev:
520  err_ll_addr_len:
521  err_hw_addr_len:
522  err_shutdown:
523  err_start:
524  list_del ( &snp->dev.siblings );
526  netdev_put ( netdev );
527  err_alloc:
530  err_open_protocol:
531  return rc;
532 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
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:157
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:47
EFI_GUID efi_simple_network_protocol_guid
Simple network protocol GUID.
Definition: efi_guid.c:236
#define DBGC(...)
Definition: compiler.h:505
#define EFI_OPEN_PROTOCOL_BY_DRIVER
Definition: UefiSpec.h:1274
#define EFI_OPEN_PROTOCOL_EXCLUSIVE
Definition: UefiSpec.h:1275
BOOLEAN MediaPresentSupported
TRUE if the presence of media can be determined; otherwise FALSE.
#define DBGC_EFI_OPENERS(...)
Definition: efi.h:260
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:21
UINT32 State
Reports the current state of the network interface.
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1906
EFI_MAC_ADDRESS CurrentAddress
The current HW MAC address for the network interface.
#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:498
#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:73
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:555
An object interface.
Definition: interface.h:109
uint8_t hw_addr_len
Hardware address length.
Definition: netdevice.h:196
void * priv
Driver private data.
Definition: netdevice.h:425
EFI_SIMPLE_NETWORK_SHUTDOWN Shutdown
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:768
static struct net_device * netdev
Definition: gdbudp.c:52
static void snpnet_check_link(struct net_device *netdev)
Check link state.
Definition: snpnet.c:131
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:844
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:713
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:30
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:667
A network device.
Definition: netdevice.h:348
An SNP NIC.
Definition: snpnet.c:43
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:511
EFI_SIMPLE_NETWORK_START Start
struct efi_device * efidev
EFI device.
Definition: snpnet.c:45
struct device * dev
Underlying hardware device.
Definition: netdevice.h:360
#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:358
UINT32 HwAddressSize
The size, in bytes, of the network interface's HW address.
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
struct list_head children
Devices attached to this device.
Definition: device.h:83
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition: ethernet.c:264
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1905
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:381
static void efidev_set_drvdata(struct efi_device *efidev, void *priv)
Set EFI driver-private data.
Definition: efi_driver.h:72
struct device dev
Generic device.
Definition: efi_driver.h:19
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:375
static struct net_device_operations snpnet_operations
SNP network device operations.
Definition: snpnet.c:409
Definition: efi.h:55
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:366
void efi_device_info(EFI_HANDLE device, const char *prefix, struct device *dev)
Get underlying device information.
Definition: efi_utils.c:211
EFI_MAC_ADDRESS PermanentAddress
The permanent HW MAC address for the network interface.

References alloc_etherdev(), EFI_SYSTEM_TABLE::BootServices, device::children, EFI_BOOT_SERVICES::CloseProtocol, EFI_SIMPLE_NETWORK_MODE::CurrentAddress, DBGC, DBGC_EFI_OPENERS, efi_device::dev, net_device::dev, efi_device::device, EEFI, efi_device_info(), efi_handle_name(), efi_image_handle, EFI_OPEN_PROTOCOL_BY_DRIVER, EFI_OPEN_PROTOCOL_EXCLUSIVE, efi_simple_network_protocol_guid, efi_systab, snp_nic::efidev, efidev_set_drvdata(), EfiSimpleNetworkInitialized, EfiSimpleNetworkStopped, ENOMEM, ENOTSUP, net_device::hw_addr, ll_protocol::hw_addr_len, EFI_SIMPLE_NETWORK_MODE::HwAddressSize, 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(), _EFI_SIMPLE_NETWORK_PROTOCOL::Mode, net_device::name, netdev, netdev_init(), netdev_link_up(), netdev_nullify(), netdev_put(), EFI_BOOT_SERVICES::OpenProtocol, EFI_SIMPLE_NETWORK_MODE::PermanentAddress, net_device::priv, rc, register_netdev(), _EFI_SIMPLE_NETWORK_PROTOCOL::Shutdown, snp_nic::snp, snpnet_check_link(), snpnet_operations, _EFI_SIMPLE_NETWORK_PROTOCOL::Start, EFI_SIMPLE_NETWORK_MODE::State, strerror(), and unregister_netdev().

◆ snpnet_stop()

void snpnet_stop ( struct efi_device efidev)

Detach driver from device.

Parameters
efidevEFI device

Definition at line 539 of file snpnet.c.

539  {
541  struct net_device *netdev = efidev_get_drvdata ( efidev );
542  struct snp_nic *snp = netdev->priv;
544  EFI_STATUS efirc;
545  int rc;
546 
547  /* Unregister network device */
549 
550  /* Stop SNP protocol */
551  if ( ( efirc = snp->snp->Stop ( snp->snp ) ) != 0 ) {
552  rc = -EEFI ( efirc );
553  DBGC ( device, "SNP %s could not stop: %s\n",
554  efi_handle_name ( device ), strerror ( rc ) );
555  /* Nothing we can do about this */
556  }
557 
558  /* Free network device */
559  list_del ( &snp->dev.siblings );
561  netdev_put ( netdev );
562 
563  /* Close SNP protocol */
566 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
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:157
EFI_SIMPLE_NETWORK_PROTOCOL * snp
Simple network protocol.
Definition: snpnet.c:47
EFI_GUID efi_simple_network_protocol_guid
Simple network protocol GUID.
Definition: efi_guid.c:236
#define DBGC(...)
Definition: compiler.h:505
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:21
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1906
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
A hardware device.
Definition: device.h:73
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:555
void * priv
Driver private data.
Definition: netdevice.h:425
static struct net_device * netdev
Definition: gdbudp.c:52
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:844
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:713
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:30
static void * efidev_get_drvdata(struct efi_device *efidev)
Get EFI driver-private data.
Definition: efi_driver.h:83
A network device.
Definition: netdevice.h:348
An SNP NIC.
Definition: snpnet.c:43
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:511
struct efi_device * efidev
EFI device.
Definition: snpnet.c:45
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
EFI_SYSTEM_TABLE * efi_systab
EFI_SIMPLE_NETWORK_STOP Stop
Definition: efi.h:55

References EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, DBGC, efi_device::device, EEFI, efi_handle_name(), efi_image_handle, efi_simple_network_protocol_guid, efi_systab, 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().