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_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  )

◆ nii_exclude()

int nii_exclude ( EFI_HANDLE  device)

Exclude existing drivers.

Parameters
deviceEFI device handle
Return values
rcReturn status code

Definition at line 1266 of file nii.c.

1266  {
1268  int rc;
1269 
1270  /* Exclude existing NII protocol drivers */
1271  if ( ( rc = efi_driver_exclude ( device, protocol ) ) != 0 ) {
1272  DBGC ( device, "NII %s could not exclude drivers: %s\n",
1273  efi_handle_name ( device ), strerror ( rc ) );
1274  return rc;
1275  }
1276 
1277  return 0;
1278 }
EFI_GUID efi_nii31_protocol_guid
Network interface identifier protocol GUID (new version)
Definition: efi_guid.c:308
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
128 bit buffer containing a unique identifier value.
Definition: Base.h:215
#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
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
uint16_t protocol
Protocol ID.
Definition: stp.h:18

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 1286 of file nii.c.

1286  {
1288  struct net_device *netdev;
1289  struct nii_nic *nii;
1290  int rc;
1291 
1292  /* Allocate and initialise structure */
1293  netdev = alloc_netdev ( sizeof ( *nii ) );
1294  if ( ! netdev ) {
1295  rc = -ENOMEM;
1296  goto err_alloc;
1297  }
1299  nii = netdev->priv;
1300  nii->efidev = efidev;
1301  INIT_LIST_HEAD ( &nii->mappings );
1302  netdev->ll_broadcast = nii->broadcast;
1304 
1305  /* Populate underlying device information */
1306  efi_device_info ( device, "NII", &nii->dev );
1307  nii->dev.driver_name = "NII";
1308  nii->dev.parent = &efidev->dev;
1309  list_add ( &nii->dev.siblings, &efidev->dev.children );
1310  INIT_LIST_HEAD ( &nii->dev.children );
1311  netdev->dev = &nii->dev;
1312 
1313  /* Open NII protocol */
1315  &nii->nii ) ) != 0 ) {
1316  DBGC ( nii, "NII %s cannot open NII protocol: %s\n",
1317  nii->dev.name, strerror ( rc ) );
1319  goto err_open_protocol;
1320  }
1321 
1322  /* Locate UNDI and entry point */
1323  nii->undi = ( ( void * ) ( intptr_t ) nii->nii->Id );
1324  if ( ! nii->undi ) {
1325  DBGC ( nii, "NII %s has no UNDI\n", nii->dev.name );
1326  rc = -ENODEV;
1327  goto err_no_undi;
1328  }
1329  if ( nii->undi->Implementation & PXE_ROMID_IMP_HW_UNDI ) {
1330  DBGC ( nii, "NII %s is a mythical hardware UNDI\n",
1331  nii->dev.name );
1332  rc = -ENOTSUP;
1333  goto err_hw_undi;
1334  }
1335  if ( nii->undi->Implementation & PXE_ROMID_IMP_SW_VIRT_ADDR ) {
1336  nii->issue = ( ( void * ) ( intptr_t ) nii->undi->EntryPoint );
1337  } else {
1338  nii->issue = ( ( ( void * ) nii->undi ) +
1339  nii->undi->EntryPoint );
1340  }
1341  DBGC ( nii, "NII %s using UNDI v%x.%x at %p entry %p impl %#08x\n",
1342  nii->dev.name, nii->nii->MajorVer, nii->nii->MinorVer,
1343  nii->undi, nii->issue, nii->undi->Implementation );
1344 
1345  /* Open PCI I/O protocols and locate BARs */
1346  if ( ( rc = nii_pci_open ( nii ) ) != 0 )
1347  goto err_pci_open;
1348 
1349  /* Start UNDI */
1350  if ( ( rc = nii_start_undi ( nii ) ) != 0 )
1351  goto err_start_undi;
1352 
1353  /* Get initialisation information */
1354  if ( ( rc = nii_get_init_info ( nii, netdev ) ) != 0 )
1355  goto err_get_init_info;
1356 
1357  /* Get MAC addresses */
1358  if ( ( rc = nii_get_station_address ( nii, netdev ) ) != 0 )
1359  goto err_get_station_address;
1360 
1361  /* Register network device */
1362  if ( ( rc = register_netdev ( netdev ) ) != 0 )
1363  goto err_register_netdev;
1364  DBGC ( nii, "NII %s registered as %s for %s\n", nii->dev.name,
1366 
1367  /* Set initial link state (if media detection is not supported) */
1368  if ( ! nii->media )
1369  netdev_link_up ( netdev );
1370 
1371  return 0;
1372 
1374  err_register_netdev:
1375  err_get_station_address:
1376  err_get_init_info:
1377  nii_stop_undi ( nii );
1378  err_start_undi:
1379  nii_pci_close ( nii );
1380  err_pci_open:
1381  err_hw_undi:
1382  err_no_undi:
1384  err_open_protocol:
1385  list_del ( &nii->dev.siblings );
1386  netdev_nullify ( netdev );
1387  netdev_put ( netdev );
1388  err_alloc:
1389  return rc;
1390 }
EFI_GUID efi_nii31_protocol_guid
Network interface identifier protocol GUID (new version)
Definition: efi_guid.c:308
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:69
#define DBGC(...)
Definition: compiler.h:505
const uint8_t * ll_broadcast
Link-layer broadcast address.
Definition: netdevice.h:389
#define DBGC_EFI_OPENERS(...)
Definition: efi.h:344
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:21
unsigned long intptr_t
Definition: stdint.h:21
#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:518
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: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
#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
#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:1253
#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: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
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:531
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:843
#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:646
struct list_head children
Devices attached to this device.
Definition: device.h:86
static void nii_pci_close(struct nii_nic *nii)
Close PCI I/O protocol.
Definition: nii.c:292
static int nii_get_init_info(struct nii_nic *nii, struct net_device *netdev)
Get initialisation information.
Definition: nii.c:699
static void nii_stop_undi(struct nii_nic *nii)
Stop UNDI.
Definition: nii.c:678
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
Definition: efi.h:61
void efi_device_info(EFI_HANDLE device, const char *prefix, struct device *dev)
Get underlying device information.
Definition: efi_utils.c:188
static int nii_pci_open(struct nii_nic *nii)
Open PCI I/O protocol and identify BARs.
Definition: nii.c:208

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 1397 of file nii.c.

1397  {
1398  struct net_device *netdev = efidev_get_drvdata ( efidev );
1399  struct nii_nic *nii = netdev->priv;
1401 
1402  /* Unregister network device */
1404 
1405  /* Stop UNDI */
1406  nii_stop_undi ( nii );
1407 
1408  /* Close PCI I/O protocols */
1409  nii_pci_close ( nii );
1410 
1411  /* Close NII protocol */
1413 
1414  /* Free network device */
1415  list_del ( &nii->dev.siblings );
1416  netdev_nullify ( netdev );
1417  netdev_put ( netdev );
1418 }
EFI_GUID efi_nii31_protocol_guid
Network interface identifier protocol GUID (new version)
Definition: efi_guid.c:308
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
An NII NIC.
Definition: nii.c:153
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
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
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:531
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:292
static void nii_stop_undi(struct nii_nic *nii)
Stop UNDI.
Definition: nii.c:678
Definition: efi.h:61

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