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

1210  {
1213  struct net_device *netdev;
1214  struct nii_nic *nii;
1215  void *interface;
1216  EFI_STATUS efirc;
1217  int rc;
1218 
1219  /* Allocate and initialise structure */
1220  netdev = alloc_netdev ( sizeof ( *nii ) );
1221  if ( ! netdev ) {
1222  rc = -ENOMEM;
1223  goto err_alloc;
1224  }
1226  nii = netdev->priv;
1227  nii->efidev = efidev;
1228  INIT_LIST_HEAD ( &nii->mappings );
1229  netdev->ll_broadcast = nii->broadcast;
1231 
1232  /* Populate underlying device information */
1233  efi_device_info ( device, "NII", &nii->dev );
1234  nii->dev.driver_name = "NII";
1235  nii->dev.parent = &efidev->dev;
1236  list_add ( &nii->dev.siblings, &efidev->dev.children );
1237  INIT_LIST_HEAD ( &nii->dev.children );
1238  netdev->dev = &nii->dev;
1239 
1240  /* Open NII protocol */
1241  if ( ( efirc = bs->OpenProtocol ( device, &efi_nii31_protocol_guid,
1245  rc = -EEFI ( efirc );
1246  DBGC ( nii, "NII %s cannot open NII protocol: %s\n",
1247  nii->dev.name, strerror ( rc ) );
1249  goto err_open_protocol;
1250  }
1251  nii->nii = interface;
1252 
1253  /* Locate UNDI and entry point */
1254  nii->undi = ( ( void * ) ( intptr_t ) nii->nii->Id );
1255  if ( ! nii->undi ) {
1256  DBGC ( nii, "NII %s has no UNDI\n", nii->dev.name );
1257  rc = -ENODEV;
1258  goto err_no_undi;
1259  }
1260  if ( nii->undi->Implementation & PXE_ROMID_IMP_HW_UNDI ) {
1261  DBGC ( nii, "NII %s is a mythical hardware UNDI\n",
1262  nii->dev.name );
1263  rc = -ENOTSUP;
1264  goto err_hw_undi;
1265  }
1266  if ( nii->undi->Implementation & PXE_ROMID_IMP_SW_VIRT_ADDR ) {
1267  nii->issue = ( ( void * ) ( intptr_t ) nii->undi->EntryPoint );
1268  } else {
1269  nii->issue = ( ( ( void * ) nii->undi ) +
1270  nii->undi->EntryPoint );
1271  }
1272  DBGC ( nii, "NII %s using UNDI v%x.%x at %p entry %p impl %#08x\n",
1273  nii->dev.name, nii->nii->MajorVer, nii->nii->MinorVer,
1274  nii->undi, nii->issue, nii->undi->Implementation );
1275 
1276  /* Open PCI I/O protocols and locate BARs */
1277  if ( ( rc = nii_pci_open ( nii ) ) != 0 )
1278  goto err_pci_open;
1279 
1280  /* Start UNDI */
1281  if ( ( rc = nii_start_undi ( nii ) ) != 0 )
1282  goto err_start_undi;
1283 
1284  /* Get initialisation information */
1285  if ( ( rc = nii_get_init_info ( nii, netdev ) ) != 0 )
1286  goto err_get_init_info;
1287 
1288  /* Get MAC addresses */
1289  if ( ( rc = nii_get_station_address ( nii, netdev ) ) != 0 )
1290  goto err_get_station_address;
1291 
1292  /* Register network device */
1293  if ( ( rc = register_netdev ( netdev ) ) != 0 )
1294  goto err_register_netdev;
1295  DBGC ( nii, "NII %s registered as %s for %s\n", nii->dev.name,
1297 
1298  /* Set initial link state (if media detection is not supported) */
1299  if ( ! nii->media )
1300  netdev_link_up ( netdev );
1301 
1302  return 0;
1303 
1305  err_register_netdev:
1306  err_get_station_address:
1307  err_get_init_info:
1308  nii_stop_undi ( nii );
1309  err_start_undi:
1310  nii_pci_close ( nii );
1311  err_pci_open:
1312  err_hw_undi:
1313  err_no_undi:
1316  err_open_protocol:
1317  list_del ( &nii->dev.siblings );
1318  netdev_nullify ( netdev );
1319  netdev_put ( netdev );
1320  err_alloc:
1321  return rc;
1322 }
EFI_GUID efi_nii31_protocol_guid
Network interface identifier protocol GUID (new version)
Definition: efi_guid.c:212
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
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:157
#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:383
#define EFI_OPEN_PROTOCOL_BY_DRIVER
Definition: UefiSpec.h:1274
#define EFI_OPEN_PROTOCOL_EXCLUSIVE
Definition: UefiSpec.h:1275
#define DBGC_EFI_OPENERS(...)
Definition: efi.h:260
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:1906
#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:498
struct net_device * alloc_netdev(size_t priv_len)
Allocate network device.
Definition: netdevice.c:622
#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:152
A hardware device.
Definition: device.h:73
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:555
An object interface.
Definition: interface.h:109
void * priv
Driver private data.
Definition: netdevice.h:425
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:768
static struct net_device * netdev
Definition: gdbudp.c:52
#define PXE_ROMID_IMP_HW_UNDI
Implementation flags.
Definition: UefiPxe.h:859
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:844
static struct net_device_operations nii_operations
NII network device operations.
Definition: nii.c:1197
#define PXE_ROMID_IMP_SW_VIRT_ADDR
Definition: UefiPxe.h:860
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:713
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:30
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:667
A network device.
Definition: netdevice.h:348
struct efi_device * efidev
EFI device.
Definition: nii.c:154
#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:511
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition: nii.c:156
struct device * dev
Underlying hardware device.
Definition: netdevice.h:360
static int nii_get_station_address(struct nii_nic *nii, struct net_device *netdev)
Get station addresses.
Definition: nii.c:834
#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:358
static int nii_start_undi(struct nii_nic *nii)
Start UNDI.
Definition: nii.c:651
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
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:295
static int nii_get_init_info(struct nii_nic *nii, struct net_device *netdev)
Get initialisation information.
Definition: nii.c:704
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1905
static void nii_stop_undi(struct nii_nic *nii)
Stop UNDI.
Definition: nii.c:683
static void efidev_set_drvdata(struct efi_device *efidev, void *priv)
Set EFI driver-private data.
Definition: efi_driver.h:72
struct device dev
Generic device.
Definition: efi_driver.h:19
Definition: efi.h:55
void efi_device_info(EFI_HANDLE device, const char *prefix, struct device *dev)
Get underlying device information.
Definition: efi_utils.c:211
static int nii_pci_open(struct nii_nic *nii)
Open PCI I/O protocol and identify BARs.
Definition: nii.c:207

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

1329  {
1331  struct net_device *netdev = efidev_get_drvdata ( efidev );
1332  struct nii_nic *nii = netdev->priv;
1334 
1335  /* Unregister network device */
1337 
1338  /* Stop UNDI */
1339  nii_stop_undi ( nii );
1340 
1341  /* Close PCI I/O protocols */
1342  nii_pci_close ( nii );
1343 
1344  /* Close NII protocol */
1347 
1348  /* Free network device */
1349  list_del ( &nii->dev.siblings );
1350  netdev_nullify ( netdev );
1351  netdev_put ( netdev );
1352 }
EFI_GUID efi_nii31_protocol_guid
Network interface identifier protocol GUID (new version)
Definition: efi_guid.c:212
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:21
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1906
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
An NII NIC.
Definition: nii.c:152
A hardware device.
Definition: device.h:73
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:555
void * priv
Driver private data.
Definition: netdevice.h:425
static struct net_device * netdev
Definition: gdbudp.c:52
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:844
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:30
static void * efidev_get_drvdata(struct efi_device *efidev)
Get EFI driver-private data.
Definition: efi_driver.h:83
A network device.
Definition: netdevice.h:348
struct efi_device * efidev
EFI device.
Definition: nii.c:154
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:511
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition: nii.c:156
static void nii_pci_close(struct nii_nic *nii)
Close PCI I/O protocol.
Definition: nii.c:295
EFI_SYSTEM_TABLE * efi_systab
static void nii_stop_undi(struct nii_nic *nii)
Stop UNDI.
Definition: nii.c:683
Definition: efi.h:55

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