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 473 of file snpnet.c.

473  {
477  struct net_device *netdev;
478  struct snp_nic *snp;
479  void *interface;
480  EFI_STATUS efirc;
481  int rc;
482 
483  /* Open SNP protocol */
484  if ( ( efirc = bs->OpenProtocol ( device,
489  rc = -EEFI ( efirc );
490  DBGC ( device, "SNP %s cannot open SNP protocol: %s\n",
491  efi_handle_name ( device ), strerror ( rc ) );
494  goto err_open_protocol;
495  }
496 
497  /* Allocate and initialise structure */
498  netdev = alloc_etherdev ( sizeof ( *snp ) );
499  if ( ! netdev ) {
500  rc = -ENOMEM;
501  goto err_alloc;
502  }
504  snp = netdev->priv;
505  snp->efidev = efidev;
506  snp->snp = interface;
507  mode = snp->snp->Mode;
509 
510  /* Populate underlying device information */
511  efi_device_info ( device, "SNP", &snp->dev );
512  snp->dev.driver_name = "SNP";
513  snp->dev.parent = &efidev->dev;
514  list_add ( &snp->dev.siblings, &efidev->dev.children );
515  INIT_LIST_HEAD ( &snp->dev.children );
516  netdev->dev = &snp->dev;
517 
518  /* Bring to the Started state */
519  if ( ( mode->State == EfiSimpleNetworkStopped ) &&
520  ( ( efirc = snp->snp->Start ( snp->snp ) ) != 0 ) ) {
521  rc = -EEFI ( efirc );
522  DBGC ( device, "SNP %s could not start: %s\n",
523  efi_handle_name ( device ), strerror ( rc ) );
524  goto err_start;
525  }
526  if ( ( mode->State == EfiSimpleNetworkInitialized ) &&
527  ( ( efirc = snp->snp->Shutdown ( snp->snp ) ) != 0 ) ) {
528  rc = -EEFI ( efirc );
529  DBGC ( device, "SNP %s could not shut down: %s\n",
530  efi_handle_name ( device ), strerror ( rc ) );
531  goto err_shutdown;
532  }
533 
534  /* Populate network device parameters */
535  if ( mode->HwAddressSize != netdev->ll_protocol->hw_addr_len ) {
536  DBGC ( device, "SNP %s has invalid hardware address length "
537  "%d\n", efi_handle_name ( device ), mode->HwAddressSize);
538  rc = -ENOTSUP;
539  goto err_hw_addr_len;
540  }
543  if ( mode->HwAddressSize != netdev->ll_protocol->ll_addr_len ) {
544  DBGC ( device, "SNP %s has invalid link-layer address length "
545  "%d\n", efi_handle_name ( device ), mode->HwAddressSize);
546  rc = -ENOTSUP;
547  goto err_ll_addr_len;
548  }
549  memcpy ( netdev->ll_addr, &mode->CurrentAddress,
551  snp->mtu = ( snp->snp->Mode->MaxPacketSize +
552  snp->snp->Mode->MediaHeaderSize );
553 
554  /* Register network device */
555  if ( ( rc = register_netdev ( netdev ) ) != 0 )
556  goto err_register_netdev;
557  DBGC ( device, "SNP %s registered as %s\n",
559 
560  /* Set initial link state */
561  if ( snp->snp->Mode->MediaPresentSupported ) {
563  } else {
565  }
566 
567  return 0;
568 
570  err_register_netdev:
571  err_ll_addr_len:
572  err_hw_addr_len:
573  err_shutdown:
574  err_start:
575  list_del ( &snp->dev.siblings );
577  netdev_put ( netdev );
578  err_alloc:
581  err_open_protocol:
582  return rc;
583 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2030
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:162
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:48
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:1302
#define EFI_OPEN_PROTOCOL_EXCLUSIVE
Definition: UefiSpec.h:1303
BOOLEAN MediaPresentSupported
TRUE if the presence of media can be determined; otherwise FALSE.
#define DBGC_EFI_OPENERS(...)
Definition: efi.h:286
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:1936
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:510
#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:567
An object interface.
Definition: interface.h:124
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
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:778
static struct net_device * netdev
Definition: gdbudp.c:52
static void snpnet_check_link(struct net_device *netdev)
Check link state.
Definition: snpnet.c:138
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:894
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:722
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1866
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:34
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:719
A network device.
Definition: netdevice.h:352
An SNP NIC.
Definition: snpnet.c:44
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:523
EFI_SIMPLE_NETWORK_START Start
struct efi_device * efidev
EFI device.
Definition: snpnet.c:46
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
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:31
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:1935
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:72
struct device dev
Generic device.
Definition: efi_driver.h:19
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:460
Definition: efi.h:50
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:209
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 590 of file snpnet.c.

590  {
592  struct net_device *netdev = efidev_get_drvdata ( efidev );
593  struct snp_nic *snp = netdev->priv;
595  EFI_STATUS efirc;
596  int rc;
597 
598  /* Unregister network device */
600 
601  /* Stop SNP protocol (unless whole system shutdown is in progress) */
602  if ( ( ! efi_shutdown_in_progress ) &&
603  ( ( efirc = snp->snp->Stop ( snp->snp ) ) != 0 ) ) {
604  rc = -EEFI ( efirc );
605  DBGC ( device, "SNP %s could not stop: %s\n",
606  efi_handle_name ( device ), strerror ( rc ) );
607  /* Nothing we can do about this */
608  }
609 
610  /* Free network device */
611  list_del ( &snp->dev.siblings );
613  netdev_put ( netdev );
614 
615  /* Close SNP protocol */
618 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2030
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:162
EFI_SIMPLE_NETWORK_PROTOCOL * snp
Simple network protocol.
Definition: snpnet.c:48
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:1936
#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:567
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:894
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:722
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1866
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:34
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:352
An SNP NIC.
Definition: snpnet.c:44
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:523
struct efi_device * efidev
EFI device.
Definition: snpnet.c:46
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
EFI_SYSTEM_TABLE * efi_systab
EFI_SIMPLE_NETWORK_STOP Stop
Definition: efi.h:50
int efi_shutdown_in_progress
EFI shutdown is in progress.
Definition: efi_init.c:58

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