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)
 
 FILE_SECBOOT (PERMITTED)
 
int nii_exclude (EFI_HANDLE device)
 Exclude existing drivers. More...
 
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  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ nii_exclude()

int nii_exclude ( EFI_HANDLE  device)

Exclude existing drivers.

Parameters
deviceEFI device handle
Return values
rcReturn status code

Definition at line 1267 of file nii.c.

1267  {
1269  int rc;
1270 
1271  /* Exclude existing NII protocol drivers */
1272  if ( ( rc = efi_driver_exclude ( device, protocol ) ) != 0 ) {
1273  DBGC ( device, "NII %s could not exclude drivers: %s\n",
1274  efi_handle_name ( device ), strerror ( rc ) );
1275  return rc;
1276  }
1277 
1278  return 0;
1279 }
EFI_GUID efi_nii31_protocol_guid
Network interface identifier protocol GUID (new version)
Definition: efi_guid.c:309
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
128 bit buffer containing a unique identifier value.
Definition: Base.h:216
#define DBGC(...)
Definition: compiler.h:505
A hardware device.
Definition: device.h:77
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:79
int efi_driver_exclude(EFI_HANDLE device, EFI_GUID *protocol)
Try to disconnect an existing EFI driver.
Definition: efi_driver.c:438
uint16_t protocol
Protocol ID.
Definition: stp.h:19

References DBGC, efi_driver_exclude(), efi_handle_name(), efi_nii31_protocol_guid, protocol, rc, and strerror().

◆ nii_start()

int nii_start ( struct efi_device efidev)

Attach driver to device.

Parameters
efidevEFI device
Return values
rcReturn status code

Definition at line 1287 of file nii.c.

1287  {
1289  struct net_device *netdev;
1290  struct nii_nic *nii;
1291  int rc;
1292 
1293  /* Allocate and initialise structure */
1294  netdev = alloc_netdev ( sizeof ( *nii ) );
1295  if ( ! netdev ) {
1296  rc = -ENOMEM;
1297  goto err_alloc;
1298  }
1300  nii = netdev->priv;
1301  nii->efidev = efidev;
1302  INIT_LIST_HEAD ( &nii->mappings );
1303  netdev->ll_broadcast = nii->broadcast;
1305 
1306  /* Populate underlying device information */
1307  efi_device_info ( device, "NII", &nii->dev );
1308  nii->dev.driver_name = "NII";
1309  nii->dev.parent = &efidev->dev;
1310  list_add ( &nii->dev.siblings, &efidev->dev.children );
1311  INIT_LIST_HEAD ( &nii->dev.children );
1312  netdev->dev = &nii->dev;
1313 
1314  /* Open NII protocol */
1316  &nii->nii ) ) != 0 ) {
1317  DBGC ( nii, "NII %s cannot open NII protocol: %s\n",
1318  nii->dev.name, strerror ( rc ) );
1320  goto err_open_protocol;
1321  }
1322 
1323  /* Locate UNDI and entry point */
1324  nii->undi = ( ( void * ) ( intptr_t ) nii->nii->Id );
1325  if ( ! nii->undi ) {
1326  DBGC ( nii, "NII %s has no UNDI\n", nii->dev.name );
1327  rc = -ENODEV;
1328  goto err_no_undi;
1329  }
1330  if ( nii->undi->Implementation & PXE_ROMID_IMP_HW_UNDI ) {
1331  DBGC ( nii, "NII %s is a mythical hardware UNDI\n",
1332  nii->dev.name );
1333  rc = -ENOTSUP;
1334  goto err_hw_undi;
1335  }
1336  if ( nii->undi->Implementation & PXE_ROMID_IMP_SW_VIRT_ADDR ) {
1337  nii->issue = ( ( void * ) ( intptr_t ) nii->undi->EntryPoint );
1338  } else {
1339  nii->issue = ( ( ( void * ) nii->undi ) +
1340  nii->undi->EntryPoint );
1341  }
1342  DBGC ( nii, "NII %s using UNDI v%x.%x at %p entry %p impl %#08x\n",
1343  nii->dev.name, nii->nii->MajorVer, nii->nii->MinorVer,
1344  nii->undi, nii->issue, nii->undi->Implementation );
1345 
1346  /* Open PCI I/O protocols and locate BARs */
1347  if ( ( rc = nii_pci_open ( nii ) ) != 0 )
1348  goto err_pci_open;
1349 
1350  /* Start UNDI */
1351  if ( ( rc = nii_start_undi ( nii ) ) != 0 )
1352  goto err_start_undi;
1353 
1354  /* Get initialisation information */
1355  if ( ( rc = nii_get_init_info ( nii, netdev ) ) != 0 )
1356  goto err_get_init_info;
1357 
1358  /* Get MAC addresses */
1359  if ( ( rc = nii_get_station_address ( nii, netdev ) ) != 0 )
1360  goto err_get_station_address;
1361 
1362  /* Register network device */
1363  if ( ( rc = register_netdev ( netdev ) ) != 0 )
1364  goto err_register_netdev;
1365  DBGC ( nii, "NII %s registered as %s for %s\n", nii->dev.name,
1367 
1368  /* Set initial link state (if media detection is not supported) */
1369  if ( ! nii->media )
1370  netdev_link_up ( netdev );
1371 
1372  return 0;
1373 
1375  err_register_netdev:
1376  err_get_station_address:
1377  err_get_init_info:
1378  nii_stop_undi ( nii );
1379  err_start_undi:
1380  nii_pci_close ( nii );
1381  err_pci_open:
1382  err_hw_undi:
1383  err_no_undi:
1385  err_open_protocol:
1386  list_del ( &nii->dev.siblings );
1387  netdev_nullify ( netdev );
1388  netdev_put ( netdev );
1389  err_alloc:
1390  return rc;
1391 }
EFI_GUID efi_nii31_protocol_guid
Network interface identifier protocol GUID (new version)
Definition: efi_guid.c:309
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:70
#define DBGC(...)
Definition: compiler.h:505
const uint8_t * ll_broadcast
Link-layer broadcast address.
Definition: netdevice.h:390
#define DBGC_EFI_OPENERS(...)
Definition: efi.h:345
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:22
unsigned long intptr_t
Definition: stdint.h:21
#define ENOTSUP
Operation not supported.
Definition: errno.h:590
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:519
struct net_device * alloc_netdev(size_t priv_len)
Allocate network device.
Definition: netdevice.c:722
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
#define ENOMEM
Not enough space.
Definition: errno.h:535
An NII NIC.
Definition: nii.c:154
A hardware device.
Definition: device.h:77
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:576
void efi_close_by_driver(EFI_HANDLE handle, EFI_GUID *protocol)
Close protocol opened for persistent use by a driver.
Definition: efi_open.c:279
void * priv
Driver private data.
Definition: netdevice.h:432
#define efi_open_by_driver(handle, protocol, interface)
Open protocol for persistent use by a driver.
Definition: efi.h:474
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:789
static struct net_device * netdev
Definition: gdbudp.c:52
#define PXE_ROMID_IMP_HW_UNDI
Implementation flags.
Definition: UefiPxe.h:853
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:942
static struct net_device_operations nii_operations
NII network device operations.
Definition: nii.c:1254
#define PXE_ROMID_IMP_SW_VIRT_ADDR
Definition: UefiPxe.h:854
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:79
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:760
A network device.
Definition: netdevice.h:353
struct efi_device * efidev
EFI device.
Definition: nii.c:156
#define ENODEV
No such device.
Definition: errno.h:510
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:532
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition: nii.c:158
struct device * dev
Underlying hardware device.
Definition: netdevice.h:365
static int nii_get_station_address(struct nii_nic *nii, struct net_device *netdev)
Get station addresses.
Definition: nii.c:844
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:46
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:363
static int nii_start_undi(struct nii_nic *nii)
Start UNDI.
Definition: nii.c:647
struct list_head children
Devices attached to this device.
Definition: device.h:87
static void nii_pci_close(struct nii_nic *nii)
Close PCI I/O protocol.
Definition: nii.c:293
static int nii_get_init_info(struct nii_nic *nii, struct net_device *netdev)
Get initialisation information.
Definition: nii.c:700
static void nii_stop_undi(struct nii_nic *nii)
Stop UNDI.
Definition: nii.c:679
static void efidev_set_drvdata(struct efi_device *efidev, void *priv)
Set EFI driver-private data.
Definition: efi_driver.h:84
struct device dev
Generic device.
Definition: efi_driver.h:20
Definition: efi.h:62
void efi_device_info(EFI_HANDLE device, const char *prefix, struct device *dev)
Get underlying device information.
Definition: efi_utils.c:189
static int nii_pci_open(struct nii_nic *nii)
Open PCI I/O protocol and identify BARs.
Definition: nii.c:209

References alloc_netdev(), device::children, DBGC, DBGC_EFI_OPENERS, efi_device::dev, net_device::dev, efi_device::device, efi_close_by_driver(), efi_device_info(), efi_handle_name(), efi_nii31_protocol_guid, efi_open_by_driver, 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(), 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 1398 of file nii.c.

1398  {
1399  struct net_device *netdev = efidev_get_drvdata ( efidev );
1400  struct nii_nic *nii = netdev->priv;
1402 
1403  /* Unregister network device */
1405 
1406  /* Stop UNDI */
1407  nii_stop_undi ( nii );
1408 
1409  /* Close PCI I/O protocols */
1410  nii_pci_close ( nii );
1411 
1412  /* Close NII protocol */
1414 
1415  /* Free network device */
1416  list_del ( &nii->dev.siblings );
1417  netdev_nullify ( netdev );
1418  netdev_put ( netdev );
1419 }
EFI_GUID efi_nii31_protocol_guid
Network interface identifier protocol GUID (new version)
Definition: efi_guid.c:309
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:22
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
An NII NIC.
Definition: nii.c:154
A hardware device.
Definition: device.h:77
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:576
void efi_close_by_driver(EFI_HANDLE handle, EFI_GUID *protocol)
Close protocol opened for persistent use by a driver.
Definition: efi_open.c:279
void * priv
Driver private data.
Definition: netdevice.h:432
static struct net_device * netdev
Definition: gdbudp.c:52
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:942
static void * efidev_get_drvdata(struct efi_device *efidev)
Get EFI driver-private data.
Definition: efi_driver.h:95
A network device.
Definition: netdevice.h:353
struct efi_device * efidev
EFI device.
Definition: nii.c:156
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:532
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition: nii.c:158
static void nii_pci_close(struct nii_nic *nii)
Close PCI I/O protocol.
Definition: nii.c:293
static void nii_stop_undi(struct nii_nic *nii)
Stop UNDI.
Definition: nii.c:679
Definition: efi.h:62

References efi_device::device, efi_close_by_driver(), efi_nii31_protocol_guid, 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().