iPXE
Functions
nii.h File Reference

NII driver. More...

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
int nii_start (struct efi_device *efidev)
 Attach driver to device. More...
 
void nii_stop (struct efi_device *efidev)
 Detach driver from device. More...
 

Detailed Description

NII driver.

Definition in file nii.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ nii_start()

int nii_start ( struct efi_device efidev)

Attach driver to device.

Parameters
efidevEFI device
Return values
rcReturn status code

Definition at line 1272 of file nii.c.

1272  {
1275  struct net_device *netdev;
1276  struct nii_nic *nii;
1277  void *interface;
1278  EFI_STATUS efirc;
1279  int rc;
1280 
1281  /* Allocate and initialise structure */
1282  netdev = alloc_netdev ( sizeof ( *nii ) );
1283  if ( ! netdev ) {
1284  rc = -ENOMEM;
1285  goto err_alloc;
1286  }
1288  nii = netdev->priv;
1289  nii->efidev = efidev;
1290  INIT_LIST_HEAD ( &nii->mappings );
1291  netdev->ll_broadcast = nii->broadcast;
1293 
1294  /* Populate underlying device information */
1295  efi_device_info ( device, "NII", &nii->dev );
1296  nii->dev.driver_name = "NII";
1297  nii->dev.parent = &efidev->dev;
1298  list_add ( &nii->dev.siblings, &efidev->dev.children );
1299  INIT_LIST_HEAD ( &nii->dev.children );
1300  netdev->dev = &nii->dev;
1301 
1302  /* Open NII protocol */
1303  if ( ( efirc = bs->OpenProtocol ( device, &efi_nii31_protocol_guid,
1307  rc = -EEFI ( efirc );
1308  DBGC ( nii, "NII %s cannot open NII protocol: %s\n",
1309  nii->dev.name, strerror ( rc ) );
1311  goto err_open_protocol;
1312  }
1313  nii->nii = interface;
1314 
1315  /* Locate UNDI and entry point */
1316  nii->undi = ( ( void * ) ( intptr_t ) nii->nii->Id );
1317  if ( ! nii->undi ) {
1318  DBGC ( nii, "NII %s has no UNDI\n", nii->dev.name );
1319  rc = -ENODEV;
1320  goto err_no_undi;
1321  }
1322  if ( nii->undi->Implementation & PXE_ROMID_IMP_HW_UNDI ) {
1323  DBGC ( nii, "NII %s is a mythical hardware UNDI\n",
1324  nii->dev.name );
1325  rc = -ENOTSUP;
1326  goto err_hw_undi;
1327  }
1328  if ( nii->undi->Implementation & PXE_ROMID_IMP_SW_VIRT_ADDR ) {
1329  nii->issue = ( ( void * ) ( intptr_t ) nii->undi->EntryPoint );
1330  } else {
1331  nii->issue = ( ( ( void * ) nii->undi ) +
1332  nii->undi->EntryPoint );
1333  }
1334  DBGC ( nii, "NII %s using UNDI v%x.%x at %p entry %p impl %#08x\n",
1335  nii->dev.name, nii->nii->MajorVer, nii->nii->MinorVer,
1336  nii->undi, nii->issue, nii->undi->Implementation );
1337 
1338  /* Open PCI I/O protocols and locate BARs */
1339  if ( ( rc = nii_pci_open ( nii ) ) != 0 )
1340  goto err_pci_open;
1341 
1342  /* Start UNDI */
1343  if ( ( rc = nii_start_undi ( nii ) ) != 0 )
1344  goto err_start_undi;
1345 
1346  /* Get initialisation information */
1347  if ( ( rc = nii_get_init_info ( nii, netdev ) ) != 0 )
1348  goto err_get_init_info;
1349 
1350  /* Get MAC addresses */
1351  if ( ( rc = nii_get_station_address ( nii, netdev ) ) != 0 )
1352  goto err_get_station_address;
1353 
1354  /* Register network device */
1355  if ( ( rc = register_netdev ( netdev ) ) != 0 )
1356  goto err_register_netdev;
1357  DBGC ( nii, "NII %s registered as %s for %s\n", nii->dev.name,
1359 
1360  /* Set initial link state (if media detection is not supported) */
1361  if ( ! nii->media )
1362  netdev_link_up ( netdev );
1363 
1364  return 0;
1365 
1367  err_register_netdev:
1368  err_get_station_address:
1369  err_get_init_info:
1370  nii_stop_undi ( nii );
1371  err_start_undi:
1372  nii_pci_close ( nii );
1373  err_pci_open:
1374  err_hw_undi:
1375  err_no_undi:
1378  err_open_protocol:
1379  list_del ( &nii->dev.siblings );
1380  netdev_nullify ( netdev );
1381  netdev_put ( netdev );
1382  err_alloc:
1383  return rc;
1384 }
EFI_GUID efi_nii31_protocol_guid
Network interface identifier protocol GUID (new version)
Definition: efi_guid.c:279
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 list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:69
#define DBGC(...)
Definition: compiler.h:505
const uint8_t * ll_broadcast
Link-layer broadcast address.
Definition: netdevice.h:389
#define EFI_OPEN_PROTOCOL_BY_DRIVER
Definition: UefiSpec.h:1347
#define EFI_OPEN_PROTOCOL_EXCLUSIVE
Definition: UefiSpec.h:1348
#define DBGC_EFI_OPENERS(...)
Definition: efi.h:321
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:21
unsigned long intptr_t
Definition: stdint.h:21
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1987
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
UINT64 Id
The address of the first byte of the identifying structure for this network interface.
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:515
struct net_device * alloc_netdev(size_t priv_len)
Allocate network device.
Definition: netdevice.c:721
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
#define ENOMEM
Not enough space.
Definition: errno.h:534
An NII NIC.
Definition: nii.c:153
A hardware device.
Definition: device.h:73
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:572
An object interface.
Definition: interface.h:124
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:774
static struct net_device * netdev
Definition: gdbudp.c:52
#define PXE_ROMID_IMP_HW_UNDI
Implementation flags.
Definition: UefiPxe.h:852
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:941
static struct net_device_operations nii_operations
NII network device operations.
Definition: nii.c:1259
#define PXE_ROMID_IMP_SW_VIRT_ADDR
Definition: UefiPxe.h:853
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
struct efi_device * efidev
EFI device.
Definition: nii.c:155
#define ENODEV
No such device.
Definition: errno.h:509
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:528
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition: nii.c:157
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
static int nii_get_station_address(struct nii_nic *nii, struct net_device *netdev)
Get station addresses.
Definition: nii.c:849
#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
static int nii_start_undi(struct nii_nic *nii)
Start UNDI.
Definition: nii.c:652
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
static void nii_pci_close(struct nii_nic *nii)
Close PCI I/O protocol.
Definition: nii.c:296
static int nii_get_init_info(struct nii_nic *nii, struct net_device *netdev)
Get initialisation information.
Definition: nii.c:705
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1986
static void nii_stop_undi(struct nii_nic *nii)
Stop UNDI.
Definition: nii.c:684
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
Definition: efi.h:59
void efi_device_info(EFI_HANDLE device, const char *prefix, struct device *dev)
Get underlying device information.
Definition: efi_utils.c:209
static int nii_pci_open(struct nii_nic *nii)
Open PCI I/O protocol and identify BARs.
Definition: nii.c:208

References alloc_netdev(), EFI_SYSTEM_TABLE::BootServices, device::children, EFI_BOOT_SERVICES::CloseProtocol, DBGC, DBGC_EFI_OPENERS, efi_device::dev, net_device::dev, efi_device::device, EEFI, efi_device_info(), efi_handle_name(), efi_image_handle, efi_nii31_protocol_guid, EFI_OPEN_PROTOCOL_BY_DRIVER, EFI_OPEN_PROTOCOL_EXCLUSIVE, efi_systab, nii_nic::efidev, efidev_set_drvdata(), ENODEV, ENOMEM, ENOTSUP, _EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL::Id, INIT_LIST_HEAD, list_add, list_del, net_device::ll_broadcast, _EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL::MajorVer, _EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL::MinorVer, net_device::name, netdev, netdev_init(), netdev_link_up(), netdev_nullify(), netdev_put(), nii_nic::nii, nii_get_init_info(), nii_get_station_address(), nii_operations, nii_pci_close(), nii_pci_open(), nii_start_undi(), nii_stop_undi(), EFI_BOOT_SERVICES::OpenProtocol, net_device::priv, PXE_ROMID_IMP_HW_UNDI, PXE_ROMID_IMP_SW_VIRT_ADDR, rc, register_netdev(), strerror(), and unregister_netdev().

◆ nii_stop()

void nii_stop ( struct efi_device efidev)

Detach driver from device.

Parameters
efidevEFI device

Definition at line 1391 of file nii.c.

1391  {
1393  struct net_device *netdev = efidev_get_drvdata ( efidev );
1394  struct nii_nic *nii = netdev->priv;
1396 
1397  /* Unregister network device */
1399 
1400  /* Stop UNDI */
1401  nii_stop_undi ( nii );
1402 
1403  /* Close PCI I/O protocols */
1404  nii_pci_close ( nii );
1405 
1406  /* Close NII protocol */
1409 
1410  /* Free network device */
1411  list_del ( &nii->dev.siblings );
1412  netdev_nullify ( netdev );
1413  netdev_put ( netdev );
1414 }
EFI_GUID efi_nii31_protocol_guid
Network interface identifier protocol GUID (new version)
Definition: efi_guid.c:279
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2081
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
An NII NIC.
Definition: nii.c:153
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
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
struct efi_device * efidev
EFI device.
Definition: nii.c:155
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:528
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition: nii.c:157
static void nii_pci_close(struct nii_nic *nii)
Close PCI I/O protocol.
Definition: nii.c:296
EFI_SYSTEM_TABLE * efi_systab
static void nii_stop_undi(struct nii_nic *nii)
Stop UNDI.
Definition: nii.c:684
Definition: efi.h:59

References EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, efi_device::device, efi_image_handle, efi_nii31_protocol_guid, efi_systab, nii_nic::efidev, efidev_get_drvdata(), list_del, netdev, netdev_nullify(), netdev_put(), nii_nic::nii, nii_pci_close(), nii_stop_undi(), net_device::priv, and unregister_netdev().