iPXE
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.
int nii_start (struct efi_device *efidev)
 Attach driver to device.
void nii_stop (struct efi_device *efidev)
 Detach driver from device.

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 )

References EFI_HANDLE.

◆ nii_exclude()

int nii_exclude ( EFI_HANDLE device)
extern

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}
GUID EFI_GUID
128-bit buffer containing a unique identifier value.
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition efi_debug.c:652
int efi_driver_exclude(EFI_HANDLE device, EFI_GUID *protocol)
Try to disconnect an existing EFI driver.
Definition efi_driver.c:438
EFI_GUID efi_nii31_protocol_guid
Network interface identifier protocol GUID (new version)
Definition efi_guid.c:309
#define DBGC(...)
Definition compiler.h:505
uint16_t protocol
Protocol ID.
Definition stp.h:7
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
A hardware device.
Definition device.h:77

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

Referenced by __efi_driver().

◆ nii_start()

int nii_start ( struct efi_device * efidev)
extern

Attach driver to device.

Parameters
efidevEFI device
Return values
rcReturn status code

Definition at line 1287 of file nii.c.

1287 {
1288 EFI_HANDLE device = efidev->device;
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,
1366 netdev->name, efi_handle_name ( device ) );
1367
1368 /* Set initial link state (if media detection is not supported) */
1369 if ( ! nii->media )
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 );
1388 netdev_put ( netdev );
1389 err_alloc:
1390 return rc;
1391}
#define PXE_ROMID_IMP_HW_UNDI
Implementation flags.
Definition UefiPxe.h:853
#define PXE_ROMID_IMP_SW_VIRT_ADDR
Definition UefiPxe.h:854
unsigned long intptr_t
Definition stdint.h:21
static void efidev_set_drvdata(struct efi_device *efidev, void *priv)
Set EFI driver-private data.
Definition efi_driver.h:87
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 efi_device_info(EFI_HANDLE device, const char *prefix, struct device *dev)
Get underlying device information.
Definition efi_utils.c:189
static struct net_device * netdev
Definition gdbudp.c:53
#define ENOMEM
Not enough space.
Definition errno.h:535
#define ENOTSUP
Operation not supported.
Definition errno.h:590
#define ENODEV
No such device.
Definition errno.h:510
#define efi_open_by_driver(handle, protocol, interface)
Open protocol for persistent use by a driver.
Definition efi.h:474
#define EFI_HANDLE
Definition efi.h:53
#define DBGC_EFI_OPENERS(...)
Definition efi.h:345
#define list_del(list)
Delete an entry from a list.
Definition list.h:120
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition list.h:46
#define list_add(new, head)
Add a new entry to the head of a list.
Definition list.h:70
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition netdevice.c:942
struct net_device * alloc_netdev(size_t priv_len)
Allocate network device.
Definition netdevice.c:722
int register_netdev(struct net_device *netdev)
Register network device.
Definition netdevice.c:760
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition netdevice.h:789
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition netdevice.h:519
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition netdevice.h:532
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition netdevice.h:576
static int nii_pci_open(struct nii_nic *nii)
Open PCI I/O protocol and identify BARs.
Definition nii.c:209
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
static int nii_start_undi(struct nii_nic *nii)
Start UNDI.
Definition nii.c:647
static struct net_device_operations nii_operations
NII network device operations.
Definition nii.c:1254
static int nii_get_station_address(struct nii_nic *nii, struct net_device *netdev)
Get station addresses.
Definition nii.c:844
static int nii_get_init_info(struct nii_nic *nii, struct net_device *netdev)
Get initialisation information.
Definition nii.c:700
UINT64 Id
The address of the first byte of the identifying structure for this network interface.
struct list_head children
Devices attached to this device.
Definition device.h:87
EFI_HANDLE device
EFI device handle.
Definition efi_driver.h:22
struct device dev
Generic device.
Definition efi_driver.h:20
A network device.
Definition netdevice.h:353
An NII NIC.
Definition nii.c:154
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition nii.c:158
struct efi_device * efidev
EFI device.
Definition nii.c:156

References alloc_netdev(), device::children, DBGC, DBGC_EFI_OPENERS, efi_device::dev, efi_device::device, efi_close_by_driver(), efi_device_info(), EFI_HANDLE, 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, _EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL::MajorVer, _EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL::MinorVer, 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(), PXE_ROMID_IMP_HW_UNDI, PXE_ROMID_IMP_SW_VIRT_ADDR, rc, register_netdev(), strerror(), and unregister_netdev().

Referenced by __efi_driver().

◆ nii_stop()

void nii_stop ( struct efi_device * efidev)
extern

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 );
1418 netdev_put ( netdev );
1419}
static void * efidev_get_drvdata(struct efi_device *efidev)
Get EFI driver-private data.
Definition efi_driver.h:98

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

Referenced by __efi_driver().