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, int inhibit_wifi)
 Check to see if driver supports a device. 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...
 

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,
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_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().