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_supported (EFI_HANDLE device, EFI_GUID *protocol)
 Check to see if driver supports a device. 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...
 

Detailed Description

SNP NIC driver.

Definition in file snpnet.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER  )

◆ snpnet_supported()

int snpnet_supported ( EFI_HANDLE  device,
EFI_GUID protocol 
)

Check to see if driver supports a device.

Parameters
deviceEFI device handle
protocolProtocol GUID
Return values
rcReturn status code

Definition at line 495 of file snpnet.c.

495  {
497  EFI_HANDLE parent;
498  EFI_STATUS efirc;
499  int rc;
500 
501  /* Check that this is not a device we are providing ourselves */
502  if ( find_snpdev ( device ) != NULL ) {
503  DBGCP ( device, "HANDLE %s is provided by this binary\n",
504  efi_handle_name ( device ) );
505  return -ENOTTY;
506  }
507 
508  /* Test for presence of protocol */
509  if ( ( efirc = bs->OpenProtocol ( device, protocol,
512  DBGCP ( device, "HANDLE %s is not a %s device\n",
514  efi_guid_ntoa ( protocol ) );
515  return -EEFI ( efirc );
516  }
517 
518  /* Check that there are no instances of this protocol further
519  * up this device path.
520  */
521  if ( ( rc = efi_locate_device ( device, protocol,
522  &parent, 1 ) ) == 0 ) {
523  DBGC2 ( device, "HANDLE %s has %s-supporting parent ",
525  efi_guid_ntoa ( protocol ) );
526  DBGC2 ( device, "%s\n", efi_handle_name ( parent ) );
527  return -ENOTTY;
528  }
529 
530  DBGC ( device, "HANDLE %s is a %s device\n",
532  return 0;
533 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2081
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:171
#define DBGC(...)
Definition: compiler.h:505
#define EFI_OPEN_PROTOCOL_TEST_PROTOCOL
Definition: UefiSpec.h:1345
A hardware device.
Definition: device.h:73
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:808
const char * efi_guid_ntoa(CONST EFI_GUID *guid)
Convert GUID to a printable string.
Definition: efi_debug.c:254
EFI Boot Services Table.
Definition: UefiSpec.h:1917
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:34
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
struct efi_snp_device * find_snpdev(EFI_HANDLE handle)
Find SNP device by EFI device handle.
Definition: efi_snp.c:2118
#define DBGC2(...)
Definition: compiler.h:522
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:594
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
#define DBGCP(...)
Definition: compiler.h:539
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1986
uint16_t protocol
Protocol ID.
Definition: stp.h:18
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
Definition: efi.h:59

References EFI_SYSTEM_TABLE::BootServices, DBGC, DBGC2, DBGCP, EEFI, efi_guid_ntoa(), efi_handle_name(), efi_image_handle, efi_locate_device(), EFI_OPEN_PROTOCOL_TEST_PROTOCOL, efi_systab, ENOTTY, find_snpdev(), NULL, EFI_BOOT_SERVICES::OpenProtocol, protocol, and rc.

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

◆ snpnet_start()

int snpnet_start ( struct efi_device efidev)

Attach driver to device.

Parameters
efidevEFI device
Return values
rcReturn status code

Definition at line 541 of file snpnet.c.

541  {
545  struct net_device *netdev;
546  struct snp_nic *snp;
547  void *interface;
548  EFI_STATUS efirc;
549  int rc;
550 
551  /* Open SNP protocol */
552  if ( ( efirc = bs->OpenProtocol ( device,
557  rc = -EEFI ( efirc );
558  DBGC ( device, "SNP %s cannot open SNP protocol: %s\n",
559  efi_handle_name ( device ), strerror ( rc ) );
562  goto err_open_protocol;
563  }
564 
565  /* Allocate and initialise structure */
566  netdev = alloc_etherdev ( sizeof ( *snp ) );
567  if ( ! netdev ) {
568  rc = -ENOMEM;
569  goto err_alloc;
570  }
572  snp = netdev->priv;
573  snp->efidev = efidev;
574  snp->snp = interface;
575  mode = snp->snp->Mode;
577 
578  /* Populate underlying device information */
579  efi_device_info ( device, "SNP", &snp->dev );
580  snp->dev.driver_name = "SNP";
581  snp->dev.parent = &efidev->dev;
582  list_add ( &snp->dev.siblings, &efidev->dev.children );
583  INIT_LIST_HEAD ( &snp->dev.children );
584  netdev->dev = &snp->dev;
585 
586  /* Bring to the Started state */
587  if ( ( mode->State == EfiSimpleNetworkStopped ) &&
588  ( ( efirc = snp->snp->Start ( snp->snp ) ) != 0 ) ) {
589  rc = -EEFI ( efirc );
590  DBGC ( device, "SNP %s could not start: %s\n",
591  efi_handle_name ( device ), strerror ( rc ) );
592  goto err_start;
593  }
594  if ( ( mode->State == EfiSimpleNetworkInitialized ) &&
595  ( ( efirc = snp->snp->Shutdown ( snp->snp ) ) != 0 ) ) {
596  rc = -EEFI ( efirc );
597  DBGC ( device, "SNP %s could not shut down: %s\n",
598  efi_handle_name ( device ), strerror ( rc ) );
599  goto err_shutdown;
600  }
601 
602  /* Populate network device parameters */
603  if ( mode->HwAddressSize != netdev->ll_protocol->hw_addr_len ) {
604  DBGC ( device, "SNP %s has invalid hardware address length "
605  "%d\n", efi_handle_name ( device ), mode->HwAddressSize);
606  rc = -ENOTSUP;
607  goto err_hw_addr_len;
608  }
611  if ( mode->HwAddressSize != netdev->ll_protocol->ll_addr_len ) {
612  DBGC ( device, "SNP %s has invalid link-layer address length "
613  "%d\n", efi_handle_name ( device ), mode->HwAddressSize);
614  rc = -ENOTSUP;
615  goto err_ll_addr_len;
616  }
617  memcpy ( netdev->ll_addr, &mode->CurrentAddress,
619  snp->mtu = ( snp->snp->Mode->MaxPacketSize +
620  snp->snp->Mode->MediaHeaderSize );
621 
622  /* Register network device */
623  if ( ( rc = register_netdev ( netdev ) ) != 0 )
624  goto err_register_netdev;
625  DBGC ( device, "SNP %s registered as %s\n",
627 
628  /* Set initial link state */
629  if ( snp->snp->Mode->MediaPresentSupported ) {
631  } else {
633  }
634 
635  return 0;
636 
638  err_register_netdev:
639  err_ll_addr_len:
640  err_hw_addr_len:
641  err_shutdown:
642  err_start:
643  list_del ( &snp->dev.siblings );
645  netdev_put ( netdev );
646  err_alloc:
649  err_open_protocol:
650  return rc;
651 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2081
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:171
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
EFI_GUID efi_simple_network_protocol_guid
Simple network protocol GUID.
Definition: efi_guid.c:307
#define DBGC(...)
Definition: compiler.h:505
#define EFI_OPEN_PROTOCOL_BY_DRIVER
Definition: UefiSpec.h:1347
#define EFI_OPEN_PROTOCOL_EXCLUSIVE
Definition: UefiSpec.h:1348
BOOLEAN MediaPresentSupported
TRUE if the presence of media can be determined; otherwise FALSE.
#define DBGC_EFI_OPENERS(...)
Definition: efi.h:321
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:1987
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:515
#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:572
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:774
static struct net_device * netdev
Definition: gdbudp.c:52
static void snpnet_check_link(struct net_device *netdev)
Check link state.
Definition: snpnet.c:153
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:808
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1917
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: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:528
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
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:1986
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:74
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:481
Definition: efi.h:59
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 658 of file snpnet.c.

658  {
660  struct net_device *netdev = efidev_get_drvdata ( efidev );
661  struct snp_nic *snp = netdev->priv;
663  EFI_STATUS efirc;
664  int rc;
665 
666  /* Unregister network device */
668 
669  /* Stop SNP protocol (unless whole system shutdown is in progress) */
670  if ( ( ! efi_shutdown_in_progress ) &&
671  ( ( efirc = snp->snp->Stop ( snp->snp ) ) != 0 ) ) {
672  rc = -EEFI ( efirc );
673  DBGC ( device, "SNP %s could not stop: %s\n",
674  efi_handle_name ( device ), strerror ( rc ) );
675  /* Nothing we can do about this */
676  }
677 
678  /* Free network device */
679  list_del ( &snp->dev.siblings );
681  netdev_put ( netdev );
682 
683  /* Close SNP protocol */
686 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2081
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:171
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:307
#define DBGC(...)
Definition: compiler.h:505
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:21
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1987
#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:572
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:808
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1917
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:85
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:528
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_SYSTEM_TABLE * efi_systab
EFI_SIMPLE_NETWORK_STOP Stop
Definition: efi.h:59
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().