iPXE
Data Structures | Macros | Functions | Variables
nii.c File Reference

NII driver. More...

#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <ipxe/netdevice.h>
#include <ipxe/ethernet.h>
#include <ipxe/umalloc.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_driver.h>
#include <ipxe/efi/efi_pci.h>
#include <ipxe/efi/efi_utils.h>
#include <ipxe/efi/Protocol/NetworkInterfaceIdentifier.h>
#include <ipxe/efi/IndustryStandard/Acpi10.h>
#include "nii.h"

Go to the source code of this file.

Data Structures

struct  nii_mapping
 An NII memory mapping. More...
 
struct  nii_nic
 An NII NIC. More...
 

Macros

#define EIO_INVALID_CDB   __einfo_error ( EINFO_EIO_INVALID_CDB )
 
#define EINFO_EIO_INVALID_CDB
 
#define EIO_INVALID_CPB   __einfo_error ( EINFO_EIO_INVALID_CPB )
 
#define EINFO_EIO_INVALID_CPB
 
#define EIO_BUSY   __einfo_error ( EINFO_EIO_BUSY )
 
#define EINFO_EIO_BUSY
 
#define EIO_QUEUE_FULL   __einfo_error ( EINFO_EIO_QUEUE_FULL )
 
#define EINFO_EIO_QUEUE_FULL
 
#define EIO_ALREADY_STARTED   __einfo_error ( EINFO_EIO_ALREADY_STARTED )
 
#define EINFO_EIO_ALREADY_STARTED
 
#define EIO_NOT_STARTED   __einfo_error ( EINFO_EIO_NOT_STARTED )
 
#define EINFO_EIO_NOT_STARTED
 
#define EIO_NOT_SHUTDOWN   __einfo_error ( EINFO_EIO_NOT_SHUTDOWN )
 
#define EINFO_EIO_NOT_SHUTDOWN
 
#define EIO_ALREADY_INITIALIZED   __einfo_error ( EINFO_EIO_ALREADY_INITIALIZED )
 
#define EINFO_EIO_ALREADY_INITIALIZED
 
#define EIO_NOT_INITIALIZED   __einfo_error ( EINFO_EIO_NOT_INITIALIZED )
 
#define EINFO_EIO_NOT_INITIALIZED
 
#define EIO_DEVICE_FAILURE   __einfo_error ( EINFO_EIO_DEVICE_FAILURE )
 
#define EINFO_EIO_DEVICE_FAILURE
 
#define EIO_NVDATA_FAILURE   __einfo_error ( EINFO_EIO_NVDATA_FAILURE )
 
#define EINFO_EIO_NVDATA_FAILURE
 
#define EIO_UNSUPPORTED   __einfo_error ( EINFO_EIO_UNSUPPORTED )
 
#define EINFO_EIO_UNSUPPORTED
 
#define EIO_BUFFER_FULL   __einfo_error ( EINFO_EIO_BUFFER_FULL )
 
#define EINFO_EIO_BUFFER_FULL
 
#define EIO_INVALID_PARAMETER   __einfo_error ( EINFO_EIO_INVALID_PARAMETER )
 
#define EINFO_EIO_INVALID_PARAMETER
 
#define EIO_INVALID_UNDI   __einfo_error ( EINFO_EIO_INVALID_UNDI )
 
#define EINFO_EIO_INVALID_UNDI
 
#define EIO_IPV4_NOT_SUPPORTED   __einfo_error ( EINFO_EIO_IPV4_NOT_SUPPORTED )
 
#define EINFO_EIO_IPV4_NOT_SUPPORTED
 
#define EIO_IPV6_NOT_SUPPORTED   __einfo_error ( EINFO_EIO_IPV6_NOT_SUPPORTED )
 
#define EINFO_EIO_IPV6_NOT_SUPPORTED
 
#define EIO_NOT_ENOUGH_MEMORY   __einfo_error ( EINFO_EIO_NOT_ENOUGH_MEMORY )
 
#define EINFO_EIO_NOT_ENOUGH_MEMORY
 
#define EIO_NO_DATA   __einfo_error ( EINFO_EIO_NO_DATA )
 
#define EINFO_EIO_NO_DATA
 
#define EIO_STAT(stat)
 
#define PCI_MAX_BAR   6
 Maximum PCI BAR. More...
 
#define NII_RX_QUOTA   4
 Maximum number of received packets per poll. More...
 
#define NII_OP(opcode, opflags)   ( (opcode) | ( (opflags) << 16 ) )
 Construct operation from opcode and flags. More...
 
#define NII_OPCODE(op)   ( (op) & 0xffff )
 Extract opcode from operation. More...
 
#define NII_OPFLAGS(op)   ( (op) >> 16 )
 Extract flags from operation. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int nii_pci_open (struct nii_nic *nii)
 Open PCI I/O protocol and identify BARs. More...
 
static void nii_pci_close (struct nii_nic *nii)
 Close PCI I/O protocol. More...
 
static EFIAPI VOID nii_io (UINT64 unique_id, UINT8 op, UINT8 len, UINT64 addr, UINT64 data)
 I/O callback. More...
 
static EFIAPI VOID nii_map (UINT64 unique_id, UINT64 addr, UINT32 len, UINT32 dir, UINT64 mapped)
 Map callback. More...
 
static EFIAPI VOID nii_unmap (UINT64 unique_id, UINT64 addr, UINT32 len, UINT32 dir __unused, UINT64 mapped)
 Unmap callback. More...
 
static EFIAPI VOID nii_sync (UINT64 unique_id __unused, UINT64 addr, UINT32 len, UINT32 dir, UINT64 mapped)
 Sync callback. More...
 
static EFIAPI VOID nii_delay (UINT64 unique_id __unused, UINTN microseconds)
 Delay callback. More...
 
static EFIAPI VOID nii_block (UINT64 unique_id, UINT32 acquire)
 Block callback. More...
 
static int nii_issue_cpb_db (struct nii_nic *nii, unsigned int op, void *cpb, size_t cpb_len, void *db, size_t db_len)
 Issue command with parameter block and data block. More...
 
static int nii_issue_cpb (struct nii_nic *nii, unsigned int op, void *cpb, size_t cpb_len)
 Issue command with parameter block. More...
 
static int nii_issue_db (struct nii_nic *nii, unsigned int op, void *db, size_t db_len)
 Issue command with data block. More...
 
static int nii_issue (struct nii_nic *nii, unsigned int op)
 Issue command. More...
 
static int nii_start_undi (struct nii_nic *nii)
 Start UNDI. More...
 
static void nii_stop_undi (struct nii_nic *nii)
 Stop UNDI. More...
 
static int nii_get_init_info (struct nii_nic *nii, struct net_device *netdev)
 Get initialisation information. More...
 
static int nii_initialise_flags (struct nii_nic *nii, unsigned int flags)
 Initialise UNDI. More...
 
static int nii_initialise (struct nii_nic *nii)
 Initialise UNDI. More...
 
static void nii_shutdown (struct nii_nic *nii)
 Shut down UNDI. More...
 
static int nii_get_station_address (struct nii_nic *nii, struct net_device *netdev)
 Get station addresses. More...
 
static int nii_set_station_address (struct nii_nic *nii, struct net_device *netdev)
 Set station address. More...
 
static int nii_set_rx_filters (struct nii_nic *nii)
 Set receive filters. More...
 
static int nii_transmit (struct net_device *netdev, struct io_buffer *iobuf)
 Transmit packet. More...
 
static void nii_poll_tx (struct net_device *netdev, unsigned int stat)
 Poll for completed packets. More...
 
static void nii_poll_rx (struct net_device *netdev)
 Poll for received packets. More...
 
static void nii_poll_link (struct net_device *netdev, unsigned int stat)
 Check for link state changes. More...
 
static void nii_poll (struct net_device *netdev)
 Poll for completed packets. More...
 
static int nii_open (struct net_device *netdev)
 Open network device. More...
 
static void nii_close (struct net_device *netdev)
 Close network device. 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...
 

Variables

static struct net_device_operations nii_operations
 NII network device operations. More...
 

Detailed Description

NII driver.

Definition in file nii.c.

Macro Definition Documentation

◆ EIO_INVALID_CDB

#define EIO_INVALID_CDB   __einfo_error ( EINFO_EIO_INVALID_CDB )

Definition at line 49 of file nii.c.

◆ EINFO_EIO_INVALID_CDB

#define EINFO_EIO_INVALID_CDB
Value:
"Invalid CDB" )
#define EINFO_EIO
Definition: errno.h:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180
#define PXE_STATCODE_INVALID_CDB
Definition: UefiPxe.h:613

Definition at line 50 of file nii.c.

◆ EIO_INVALID_CPB

#define EIO_INVALID_CPB   __einfo_error ( EINFO_EIO_INVALID_CPB )

Definition at line 53 of file nii.c.

◆ EINFO_EIO_INVALID_CPB

#define EINFO_EIO_INVALID_CPB
Value:
"Invalid CPB" )
#define EINFO_EIO
Definition: errno.h:434
#define PXE_STATCODE_INVALID_CPB
Definition: UefiPxe.h:614
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 54 of file nii.c.

◆ EIO_BUSY

#define EIO_BUSY   __einfo_error ( EINFO_EIO_BUSY )

Definition at line 57 of file nii.c.

◆ EINFO_EIO_BUSY

#define EINFO_EIO_BUSY
Value:
"Busy" )
#define PXE_STATCODE_BUSY
Definition: UefiPxe.h:615
#define EINFO_EIO
Definition: errno.h:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 58 of file nii.c.

◆ EIO_QUEUE_FULL

#define EIO_QUEUE_FULL   __einfo_error ( EINFO_EIO_QUEUE_FULL )

Definition at line 61 of file nii.c.

◆ EINFO_EIO_QUEUE_FULL

#define EINFO_EIO_QUEUE_FULL
Value:
"Queue full" )
#define PXE_STATCODE_QUEUE_FULL
Definition: UefiPxe.h:616
#define EINFO_EIO
Definition: errno.h:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 62 of file nii.c.

◆ EIO_ALREADY_STARTED

#define EIO_ALREADY_STARTED   __einfo_error ( EINFO_EIO_ALREADY_STARTED )

Definition at line 65 of file nii.c.

◆ EINFO_EIO_ALREADY_STARTED

#define EINFO_EIO_ALREADY_STARTED
Value:
"Already started" )
#define EINFO_EIO
Definition: errno.h:434
#define PXE_STATCODE_ALREADY_STARTED
Definition: UefiPxe.h:617
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 66 of file nii.c.

◆ EIO_NOT_STARTED

#define EIO_NOT_STARTED   __einfo_error ( EINFO_EIO_NOT_STARTED )

Definition at line 69 of file nii.c.

◆ EINFO_EIO_NOT_STARTED

#define EINFO_EIO_NOT_STARTED
Value:
"Not started" )
#define EINFO_EIO
Definition: errno.h:434
#define PXE_STATCODE_NOT_STARTED
Definition: UefiPxe.h:618
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 70 of file nii.c.

◆ EIO_NOT_SHUTDOWN

#define EIO_NOT_SHUTDOWN   __einfo_error ( EINFO_EIO_NOT_SHUTDOWN )

Definition at line 73 of file nii.c.

◆ EINFO_EIO_NOT_SHUTDOWN

#define EINFO_EIO_NOT_SHUTDOWN
Value:
"Not shutdown" )
#define EINFO_EIO
Definition: errno.h:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180
#define PXE_STATCODE_NOT_SHUTDOWN
Definition: UefiPxe.h:619

Definition at line 74 of file nii.c.

◆ EIO_ALREADY_INITIALIZED

#define EIO_ALREADY_INITIALIZED   __einfo_error ( EINFO_EIO_ALREADY_INITIALIZED )

Definition at line 77 of file nii.c.

◆ EINFO_EIO_ALREADY_INITIALIZED

#define EINFO_EIO_ALREADY_INITIALIZED
Value:
"Already initialized" )
#define EINFO_EIO
Definition: errno.h:434
#define PXE_STATCODE_ALREADY_INITIALIZED
Definition: UefiPxe.h:620
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 78 of file nii.c.

◆ EIO_NOT_INITIALIZED

#define EIO_NOT_INITIALIZED   __einfo_error ( EINFO_EIO_NOT_INITIALIZED )

Definition at line 81 of file nii.c.

◆ EINFO_EIO_NOT_INITIALIZED

#define EINFO_EIO_NOT_INITIALIZED
Value:
"Not initialized" )
#define EINFO_EIO
Definition: errno.h:434
#define PXE_STATCODE_NOT_INITIALIZED
Definition: UefiPxe.h:621
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 82 of file nii.c.

◆ EIO_DEVICE_FAILURE

#define EIO_DEVICE_FAILURE   __einfo_error ( EINFO_EIO_DEVICE_FAILURE )

Definition at line 85 of file nii.c.

◆ EINFO_EIO_DEVICE_FAILURE

#define EINFO_EIO_DEVICE_FAILURE
Value:
"Device failure" )
#define PXE_STATCODE_DEVICE_FAILURE
Definition: UefiPxe.h:622
#define EINFO_EIO
Definition: errno.h:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 86 of file nii.c.

◆ EIO_NVDATA_FAILURE

#define EIO_NVDATA_FAILURE   __einfo_error ( EINFO_EIO_NVDATA_FAILURE )

Definition at line 89 of file nii.c.

◆ EINFO_EIO_NVDATA_FAILURE

#define EINFO_EIO_NVDATA_FAILURE
Value:
"Non-volatile data failure" )
#define PXE_STATCODE_NVDATA_FAILURE
Definition: UefiPxe.h:623
#define EINFO_EIO
Definition: errno.h:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 90 of file nii.c.

◆ EIO_UNSUPPORTED

#define EIO_UNSUPPORTED   __einfo_error ( EINFO_EIO_UNSUPPORTED )

Definition at line 93 of file nii.c.

◆ EINFO_EIO_UNSUPPORTED

#define EINFO_EIO_UNSUPPORTED
Value:
"Unsupported" )
#define EINFO_EIO
Definition: errno.h:434
#define PXE_STATCODE_UNSUPPORTED
Definition: UefiPxe.h:624
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 94 of file nii.c.

◆ EIO_BUFFER_FULL

#define EIO_BUFFER_FULL   __einfo_error ( EINFO_EIO_BUFFER_FULL )

Definition at line 97 of file nii.c.

◆ EINFO_EIO_BUFFER_FULL

#define EINFO_EIO_BUFFER_FULL
Value:
"Buffer full" )
#define EINFO_EIO
Definition: errno.h:434
#define PXE_STATCODE_BUFFER_FULL
Definition: UefiPxe.h:625
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 98 of file nii.c.

◆ EIO_INVALID_PARAMETER

#define EIO_INVALID_PARAMETER   __einfo_error ( EINFO_EIO_INVALID_PARAMETER )

Definition at line 101 of file nii.c.

◆ EINFO_EIO_INVALID_PARAMETER

#define EINFO_EIO_INVALID_PARAMETER
Value:
"Invalid parameter" )
#define EINFO_EIO
Definition: errno.h:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180
#define PXE_STATCODE_INVALID_PARAMETER
Definition: UefiPxe.h:626

Definition at line 102 of file nii.c.

◆ EIO_INVALID_UNDI

#define EIO_INVALID_UNDI   __einfo_error ( EINFO_EIO_INVALID_UNDI )

Definition at line 105 of file nii.c.

◆ EINFO_EIO_INVALID_UNDI

#define EINFO_EIO_INVALID_UNDI
Value:
"Invalid UNDI" )
#define PXE_STATCODE_INVALID_UNDI
Definition: UefiPxe.h:627
#define EINFO_EIO
Definition: errno.h:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 106 of file nii.c.

◆ EIO_IPV4_NOT_SUPPORTED

#define EIO_IPV4_NOT_SUPPORTED   __einfo_error ( EINFO_EIO_IPV4_NOT_SUPPORTED )

Definition at line 109 of file nii.c.

◆ EINFO_EIO_IPV4_NOT_SUPPORTED

#define EINFO_EIO_IPV4_NOT_SUPPORTED
Value:
"IPv4 not supported" )
#define PXE_STATCODE_IPV4_NOT_SUPPORTED
Definition: UefiPxe.h:628
#define EINFO_EIO
Definition: errno.h:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 110 of file nii.c.

◆ EIO_IPV6_NOT_SUPPORTED

#define EIO_IPV6_NOT_SUPPORTED   __einfo_error ( EINFO_EIO_IPV6_NOT_SUPPORTED )

Definition at line 113 of file nii.c.

◆ EINFO_EIO_IPV6_NOT_SUPPORTED

#define EINFO_EIO_IPV6_NOT_SUPPORTED
Value:
"IPv6 not supported" )
#define EINFO_EIO
Definition: errno.h:434
#define PXE_STATCODE_IPV6_NOT_SUPPORTED
Definition: UefiPxe.h:629
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 114 of file nii.c.

◆ EIO_NOT_ENOUGH_MEMORY

#define EIO_NOT_ENOUGH_MEMORY   __einfo_error ( EINFO_EIO_NOT_ENOUGH_MEMORY )

Definition at line 117 of file nii.c.

◆ EINFO_EIO_NOT_ENOUGH_MEMORY

#define EINFO_EIO_NOT_ENOUGH_MEMORY
Value:
"Not enough memory" )
#define PXE_STATCODE_NOT_ENOUGH_MEMORY
Definition: UefiPxe.h:630
#define EINFO_EIO
Definition: errno.h:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 118 of file nii.c.

◆ EIO_NO_DATA

#define EIO_NO_DATA   __einfo_error ( EINFO_EIO_NO_DATA )

Definition at line 121 of file nii.c.

◆ EINFO_EIO_NO_DATA

#define EINFO_EIO_NO_DATA
Value:
"No data" )
#define EINFO_EIO
Definition: errno.h:434
#define PXE_STATCODE_NO_DATA
Definition: UefiPxe.h:631
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 122 of file nii.c.

◆ EIO_STAT

#define EIO_STAT (   stat)
Value:
#define EIO_DEVICE_FAILURE
Definition: nii.c:85
#define EIO_ALREADY_INITIALIZED
Definition: nii.c:77
#define EIO_INVALID_CPB
Definition: nii.c:53
#define EIO_QUEUE_FULL
Definition: nii.c:61
#define EIO_BUFFER_FULL
Definition: nii.c:97
#define EIO_INVALID_CDB
Definition: nii.c:49
#define EIO_NOT_ENOUGH_MEMORY
Definition: nii.c:117
#define EIO_UNSUPPORTED
Definition: nii.c:93
#define EIO_IPV4_NOT_SUPPORTED
Definition: nii.c:109
#define EIO_INVALID_PARAMETER
Definition: nii.c:101
#define EIO_IPV6_NOT_SUPPORTED
Definition: nii.c:113
#define EINFO_EIO
Definition: errno.h:434
#define EIO_NOT_SHUTDOWN
Definition: nii.c:73
#define EIO_NVDATA_FAILURE
Definition: nii.c:89
#define EIO_BUSY
Definition: nii.c:57
#define EIO_NOT_INITIALIZED
Definition: nii.c:81
#define EIO_NO_DATA
Definition: nii.c:121
#define EIO_INVALID_UNDI
Definition: nii.c:105
#define EUNIQ(einfo_base, uniq,...)
Disambiguate a base error based on non-constant information.
Definition: errno.h:225
#define EIO_ALREADY_STARTED
Definition: nii.c:65
#define EIO_NOT_STARTED
Definition: nii.c:69

Definition at line 125 of file nii.c.

◆ PCI_MAX_BAR

#define PCI_MAX_BAR   6

Maximum PCI BAR.

This is defined in <ipxe/efi/IndustryStandard/Pci22.h>, but we can't #include that since it collides with <ipxe/pci.h>.

Definition at line 139 of file nii.c.

◆ NII_RX_QUOTA

#define NII_RX_QUOTA   4

Maximum number of received packets per poll.

Definition at line 199 of file nii.c.

◆ NII_OP

#define NII_OP (   opcode,
  opflags 
)    ( (opcode) | ( (opflags) << 16 ) )

Construct operation from opcode and flags.

Parameters
opcodeOpcode
opflagsFlags
Return values
opOperation

Definition at line 533 of file nii.c.

◆ NII_OPCODE

#define NII_OPCODE (   op)    ( (op) & 0xffff )

Extract opcode from operation.

Parameters
opOperation
Return values
opcodeOpcode

Definition at line 541 of file nii.c.

◆ NII_OPFLAGS

#define NII_OPFLAGS (   op)    ( (op) >> 16 )

Extract flags from operation.

Parameters
opOperation
Return values
opflagsFlags

Definition at line 549 of file nii.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ nii_pci_open()

static int nii_pci_open ( struct nii_nic nii)
static

Open PCI I/O protocol and identify BARs.

Parameters
niiNII NIC
Return values
rcReturn status code

Definition at line 207 of file nii.c.

207  {
209  EFI_HANDLE device = nii->efidev->device;
211  union {
212  EFI_PCI_IO_PROTOCOL *pci_io;
213  void *interface;
214  } pci_io;
215  union {
217  void *resource;
218  } desc;
219  int bar;
220  EFI_STATUS efirc;
221  int rc;
222 
223  /* Locate PCI I/O protocol */
225  &pci_device ) ) != 0 ) {
226  DBGC ( nii, "NII %s could not locate PCI I/O protocol: %s\n",
227  nii->dev.name, strerror ( rc ) );
228  goto err_locate;
229  }
230  nii->pci_device = pci_device;
231 
232  /* Open PCI I/O protocol */
233  if ( ( efirc = bs->OpenProtocol ( pci_device, &efi_pci_io_protocol_guid,
234  &pci_io.interface, efi_image_handle,
235  device,
237  rc = -EEFI ( efirc );
238  DBGC ( nii, "NII %s could not open PCI I/O protocol: %s\n",
239  nii->dev.name, strerror ( rc ) );
240  goto err_open;
241  }
242  nii->pci_io = pci_io.pci_io;
243 
244  /* Identify memory and I/O BARs */
245  nii->mem_bar = PCI_MAX_BAR;
246  nii->io_bar = PCI_MAX_BAR;
247  for ( bar = ( PCI_MAX_BAR - 1 ) ; bar >= 0 ; bar-- ) {
248  efirc = nii->pci_io->GetBarAttributes ( nii->pci_io, bar, NULL,
249  &desc.resource );
250  if ( efirc == EFI_UNSUPPORTED ) {
251  /* BAR not present; ignore */
252  continue;
253  }
254  if ( efirc != 0 ) {
255  rc = -EEFI ( efirc );
256  DBGC ( nii, "NII %s could not get BAR %d attributes: "
257  "%s\n", nii->dev.name, bar, strerror ( rc ) );
258  goto err_get_bar_attributes;
259  }
260  if ( desc.acpi->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM ) {
261  nii->mem_bar = bar;
262  } else if ( desc.acpi->ResType == ACPI_ADDRESS_SPACE_TYPE_IO ) {
263  nii->io_bar = bar;
264  }
265  bs->FreePool ( desc.resource );
266  }
267  DBGC ( nii, "NII %s has ", nii->dev.name );
268  if ( nii->mem_bar < PCI_MAX_BAR ) {
269  DBGC ( nii, "memory BAR %d and ", nii->mem_bar );
270  } else {
271  DBGC ( nii, "no memory BAR and " );
272  }
273  if ( nii->io_bar < PCI_MAX_BAR ) {
274  DBGC ( nii, "I/O BAR %d\n", nii->io_bar );
275  } else {
276  DBGC ( nii, "no I/O BAR\n" );
277  }
278 
279  return 0;
280 
281  err_get_bar_attributes:
284  err_open:
285  err_locate:
286  return rc;
287 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
#define EFI_UNSUPPORTED
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:123
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:159
EFI_HANDLE pci_device
PCI device.
Definition: nii.c:165
EFI_GUID efi_pci_io_protocol_guid
PCI I/O protocol GUID.
Definition: efi_guid.c:216
#define DBGC(...)
Definition: compiler.h:505
char name[40]
Name.
Definition: device.h:75
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:21
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1906
#define ACPI_ADDRESS_SPACE_TYPE_MEM
Definition: Acpi10.h:105
A hardware device.
Definition: device.h:73
An object interface.
Definition: interface.h:109
#define PCI_MAX_BAR
Maximum PCI BAR.
Definition: nii.c:139
static EFI_ACPI_TABLE_PROTOCOL * acpi
ACPI table protocol protocol.
Definition: efi_block.c:61
EFI_PCI_IO_PROTOCOL * pci_io
PCI I/O protocol.
Definition: nii.c:167
EFI_PCI_IO_PROTOCOL_GET_BAR_ATTRIBUTES GetBarAttributes
Definition: PciIo.h:539
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL
Definition: UefiSpec.h:1271
unsigned int mem_bar
Memory BAR.
Definition: nii.c:169
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:33
A PCI device.
Definition: pci.h:187
struct efi_device * efidev
EFI device.
Definition: nii.c:154
#define ACPI_ADDRESS_SPACE_TYPE_IO
Definition: Acpi10.h:106
unsigned int io_bar
I/O BAR.
Definition: nii.c:171
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1855
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
struct device dev
Generic device.
Definition: nii.c:162
PACKED struct @458 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
The commond definition of QWORD, DWORD, and WORD Address Space Descriptors.
int efi_locate_device(EFI_HANDLE device, EFI_GUID *protocol, EFI_HANDLE *parent)
Locate parent device supporting a given protocol.
Definition: efi_utils.c:73
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1905
The EFI_PCI_IO_PROTOCOL provides the basic Memory, I/O, PCI configuration, and DMA interfaces used to...
Definition: PciIo.h:525
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
Definition: efi.h:55

References acpi, ACPI_ADDRESS_SPACE_TYPE_IO, ACPI_ADDRESS_SPACE_TYPE_MEM, EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, DBGC, nii_nic::dev, efi_device::device, EEFI, efi_image_handle, efi_locate_device(), EFI_OPEN_PROTOCOL_GET_PROTOCOL, efi_pci_io_protocol_guid, efi_systab, EFI_UNSUPPORTED, nii_nic::efidev, EFI_BOOT_SERVICES::FreePool, _EFI_PCI_IO_PROTOCOL::GetBarAttributes, nii_nic::io_bar, nii_nic::mem_bar, device::name, NULL, EFI_BOOT_SERVICES::OpenProtocol, nii_nic::pci_device, nii_nic::pci_io, PCI_MAX_BAR, rc, and strerror().

Referenced by nii_start().

◆ nii_pci_close()

static void nii_pci_close ( struct nii_nic nii)
static

Close PCI I/O protocol.

Parameters
niiNII NIC
Return values
rcReturn status code

Definition at line 295 of file nii.c.

295  {
297  struct nii_mapping *map;
298  struct nii_mapping *tmp;
299 
300  /* Remove any stale mappings */
301  list_for_each_entry_safe ( map, tmp, &nii->mappings, list ) {
302  DBGC ( nii, "NII %s removing stale mapping %#llx\n",
303  nii->dev.name, ( ( unsigned long long ) map->addr ) );
304  nii->pci_io->Unmap ( nii->pci_io, map->mapping );
305  list_del ( &map->list );
306  free ( map );
307  }
308 
309  /* Close protocols */
311  efi_image_handle, nii->efidev->device );
312 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
UINT64 addr
Mapped address.
Definition: nii.c:146
EFI_HANDLE pci_device
PCI device.
Definition: nii.c:165
EFI_GUID efi_pci_io_protocol_guid
PCI I/O protocol GUID.
Definition: efi_guid.c:216
#define DBGC(...)
Definition: compiler.h:505
char name[40]
Name.
Definition: device.h:75
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
EFI_PCI_IO_PROTOCOL * pci_io
PCI I/O protocol.
Definition: nii.c:167
An NII memory mapping.
Definition: nii.c:142
#define list_for_each_entry_safe(pos, tmp, head, member)
Iterate over entries in a list, safe against deletion of the current entry.
Definition: list.h:447
EFI_PCI_IO_PROTOCOL_UNMAP Unmap
Definition: PciIo.h:533
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:33
uint8_t * tmp
Definition: entropy.h:156
struct efi_device * efidev
EFI device.
Definition: nii.c:154
VOID * mapping
Mapping cookie created by PCI I/O protocol.
Definition: nii.c:148
struct device dev
Generic device.
Definition: nii.c:162
struct list_head list
List of mappings.
Definition: nii.c:144
EFI_SYSTEM_TABLE * efi_systab
struct list_head mappings
Mapping list.
Definition: nii.c:195

References nii_mapping::addr, EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, DBGC, nii_nic::dev, efi_device::device, efi_image_handle, efi_pci_io_protocol_guid, efi_systab, nii_nic::efidev, free, nii_mapping::list, list_del, list_for_each_entry_safe, nii_mapping::mapping, nii_nic::mappings, device::name, nii_nic::pci_device, nii_nic::pci_io, tmp, and _EFI_PCI_IO_PROTOCOL::Unmap.

Referenced by nii_start(), and nii_stop().

◆ nii_io()

static EFIAPI VOID nii_io ( UINT64  unique_id,
UINT8  op,
UINT8  len,
UINT64  addr,
UINT64  data 
)
static

I/O callback.

Parameters
unique_idNII NIC
opOperations
lenLength of data
addrAddress
dataData buffer

Definition at line 323 of file nii.c.

324  {
325  struct nii_nic *nii = ( ( void * ) ( intptr_t ) unique_id );
329  unsigned int bar;
330  EFI_STATUS efirc;
331  int rc;
332 
333  /* Determine accessor and BAR */
334  if ( op & ( PXE_MEM_READ | PXE_MEM_WRITE ) ) {
335  access = &nii->pci_io->Mem;
336  bar = nii->mem_bar;
337  } else {
338  access = &nii->pci_io->Io;
339  bar = nii->io_bar;
340  }
341 
342  /* Determine operaton */
343  io = ( ( op & ( PXE_IO_WRITE | PXE_MEM_WRITE ) ) ?
344  access->Write : access->Read );
345 
346  /* Determine width */
347  width = ( fls ( len ) - 1 );
348 
349  /* Issue operation */
350  if ( ( efirc = io ( nii->pci_io, width, bar, addr, 1,
351  ( ( void * ) ( intptr_t ) data ) ) ) != 0 ) {
352  rc = -EEFI ( efirc );
353  DBGC ( nii, "NII %s I/O operation %#x failed: %s\n",
354  nii->dev.name, op, strerror ( rc ) );
355  /* No way to report failure */
356  return;
357  }
358 }
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:159
#define DBGC(...)
Definition: compiler.h:505
unsigned long intptr_t
Definition: stdint.h:21
An NII NIC.
Definition: nii.c:152
#define PXE_IO_WRITE
Definition: UefiPxe.h:1098
EFI_STATUS(EFIAPI * EFI_PCI_IO_PROTOCOL_IO_MEM)(IN EFI_PCI_IO_PROTOCOL *This, IN EFI_PCI_IO_PROTOCOL_WIDTH Width, IN UINT8 BarIndex, IN UINT64 Offset, IN UINTN Count, IN OUT VOID *Buffer)
Enable a PCI driver to access PCI controller registers in the PCI memory or I/O space.
Definition: PciIo.h:188
EFI_PCI_IO_PROTOCOL_WIDTH
Definition: PciIo.h:36
EFI_PCI_IO_PROTOCOL_IO_MEM Write
Write PCI controller registers in the PCI memory or I/O space.
Definition: PciIo.h:205
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
u32 addr
Definition: sky2.h:8
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition: nii.c:156
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
uint32_t len
Length.
Definition: ena.h:14
EFI_PCI_IO_PROTOCOL_IO_MEM Read
Read PCI controller registers in the PCI memory or I/O space.
Definition: PciIo.h:201
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
#define PXE_MEM_READ
Definition: UefiPxe.h:1099
#define fls(x)
Find last (i.e.
Definition: strings.h:166
#define PXE_MEM_WRITE
Definition: UefiPxe.h:1100

References addr, data, DBGC, EEFI, fls, len, nii_nic::nii, op, PXE_IO_WRITE, PXE_MEM_READ, PXE_MEM_WRITE, rc, EFI_PCI_IO_PROTOCOL_ACCESS::Read, strerror(), and EFI_PCI_IO_PROTOCOL_ACCESS::Write.

Referenced by nii_start_undi().

◆ nii_map()

static EFIAPI VOID nii_map ( UINT64  unique_id,
UINT64  addr,
UINT32  len,
UINT32  dir,
UINT64  mapped 
)
static

Map callback.

Parameters
unique_idNII NIC
addrAddress of memory to be mapped
lenLength of memory to be mapped
dirDirection of data flow
mappedDevice mapped address to fill in

Definition at line 369 of file nii.c.

370  {
371  struct nii_nic *nii = ( ( void * ) ( intptr_t ) unique_id );
372  EFI_PHYSICAL_ADDRESS *phys = ( ( void * ) ( intptr_t ) mapped );
374  struct nii_mapping *map;
375  UINTN count = len;
376  EFI_STATUS efirc;
377  int rc;
378 
379  /* Return a zero mapped address on failure */
380  *phys = 0;
381 
382  /* Determine PCI mapping operation */
383  switch ( dir ) {
384  case TO_AND_FROM_DEVICE:
386  break;
387  case FROM_DEVICE:
389  break;
390  case TO_DEVICE:
392  break;
393  default:
394  DBGC ( nii, "NII %s unsupported mapping direction %d\n",
395  nii->dev.name, dir );
396  goto err_dir;
397  }
398 
399  /* Allocate a mapping record */
400  map = zalloc ( sizeof ( *map ) );
401  if ( ! map )
402  goto err_alloc;
403  map->addr = addr;
404 
405  /* Create map */
406  if ( ( efirc = nii->pci_io->Map ( nii->pci_io, op,
407  ( ( void * ) ( intptr_t ) addr ),
408  &count, phys, &map->mapping ) ) != 0){
409  rc = -EEFI ( efirc );
410  DBGC ( nii, "NII %s map operation failed: %s\n",
411  nii->dev.name, strerror ( rc ) );
412  goto err_map;
413  }
414 
415  /* Add to list of mappings */
416  list_add ( &map->list, &nii->mappings );
417  DBGC2 ( nii, "NII %s mapped %#llx+%#x->%#llx\n",
418  nii->dev.name, ( ( unsigned long long ) addr ),
419  len, ( ( unsigned long long ) *phys ) );
420  return;
421 
422  list_del ( &map->list );
423  err_map:
424  free ( map );
425  err_alloc:
426  err_dir:
427  return;
428 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
UINT64 addr
Mapped address.
Definition: nii.c:146
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:159
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:69
A read operation from system memory by a bus master.
Definition: PciIo.h:89
EFI_PCI_IO_PROTOCOL_MAP Map
Definition: PciIo.h:532
#define DBGC(...)
Definition: compiler.h:505
char name[40]
Name.
Definition: device.h:75
#define FROM_DEVICE
Definition: UefiPxe.h:1092
unsigned long intptr_t
Definition: stdint.h:21
UINT64 EFI_PHYSICAL_ADDRESS
64-bit physical memory address.
Definition: UefiBaseType.h:56
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
An NII NIC.
Definition: nii.c:152
static signed char phys[4]
Definition: epic100.c:88
EFI_PCI_IO_PROTOCOL * pci_io
PCI I/O protocol.
Definition: nii.c:167
An NII memory mapping.
Definition: nii.c:142
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
#define TO_DEVICE
Definition: UefiPxe.h:1093
u32 addr
Definition: sky2.h:8
UINT64 UINTN
Unsigned value of native width.
Definition: ProcessorBind.h:71
Provides both read and write access to system memory by both the processor and a bus master.
Definition: PciIo.h:98
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition: nii.c:156
EFI_PCI_IO_PROTOCOL_OPERATION
Definition: PciIo.h:85
VOID * mapping
Mapping cookie created by PCI I/O protocol.
Definition: nii.c:148
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
struct device dev
Generic device.
Definition: nii.c:162
#define TO_AND_FROM_DEVICE
Definition: UefiPxe.h:1091
struct list_head list
List of mappings.
Definition: nii.c:144
uint16_t count
Number of entries.
Definition: ena.h:22
A write operation from system memory by a bus master.
Definition: PciIo.h:93
struct list_head mappings
Mapping list.
Definition: nii.c:195

References addr, nii_mapping::addr, count, DBGC, DBGC2, nii_nic::dev, EEFI, EfiPciIoOperationBusMasterCommonBuffer, EfiPciIoOperationBusMasterRead, EfiPciIoOperationBusMasterWrite, free, FROM_DEVICE, len, nii_mapping::list, list_add, list_del, _EFI_PCI_IO_PROTOCOL::Map, nii_mapping::mapping, nii_nic::mappings, device::name, nii_nic::nii, op, nii_nic::pci_io, phys, rc, strerror(), TO_AND_FROM_DEVICE, TO_DEVICE, and zalloc().

Referenced by nii_start_undi().

◆ nii_unmap()

static EFIAPI VOID nii_unmap ( UINT64  unique_id,
UINT64  addr,
UINT32  len,
UINT32 dir  __unused,
UINT64  mapped 
)
static

Unmap callback.

Parameters
unique_idNII NIC
addrAddress of mapped memory
lenLength of mapped memory
dirDirection of data flow
mappedDevice mapped address

Definition at line 439 of file nii.c.

440  {
441  struct nii_nic *nii = ( ( void * ) ( intptr_t ) unique_id );
442  struct nii_mapping *map;
443 
444  /* Locate mapping record */
445  list_for_each_entry ( map, &nii->mappings, list ) {
446  if ( map->addr == addr ) {
447  nii->pci_io->Unmap ( nii->pci_io, map->mapping );
448  list_del ( &map->list );
449  free ( map );
450  DBGC2 ( nii, "NII %s unmapped %#llx+%#x->%#llx\n",
451  nii->dev.name, ( ( unsigned long long ) addr ),
452  len, ( ( unsigned long long ) mapped ) );
453  return;
454  }
455  }
456 
457  DBGC ( nii, "NII %s non-existent mapping %#llx+%#x->%#llx\n",
458  nii->dev.name, ( ( unsigned long long ) addr ),
459  len, ( ( unsigned long long ) mapped ) );
460 }
UINT64 addr
Mapped address.
Definition: nii.c:146
#define DBGC(...)
Definition: compiler.h:505
char name[40]
Name.
Definition: device.h:75
unsigned long intptr_t
Definition: stdint.h:21
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
An NII NIC.
Definition: nii.c:152
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:420
EFI_PCI_IO_PROTOCOL * pci_io
PCI I/O protocol.
Definition: nii.c:167
An NII memory mapping.
Definition: nii.c:142
EFI_PCI_IO_PROTOCOL_UNMAP Unmap
Definition: PciIo.h:533
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
u32 addr
Definition: sky2.h:8
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition: nii.c:156
VOID * mapping
Mapping cookie created by PCI I/O protocol.
Definition: nii.c:148
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
struct device dev
Generic device.
Definition: nii.c:162
struct list_head list
List of mappings.
Definition: nii.c:144
struct list_head mappings
Mapping list.
Definition: nii.c:195

References addr, nii_mapping::addr, DBGC, DBGC2, nii_nic::dev, free, len, nii_mapping::list, list_del, list_for_each_entry, nii_mapping::mapping, nii_nic::mappings, device::name, nii_nic::nii, nii_nic::pci_io, and _EFI_PCI_IO_PROTOCOL::Unmap.

Referenced by nii_start_undi().

◆ nii_sync()

static EFIAPI VOID nii_sync ( UINT64 unique_id  __unused,
UINT64  addr,
UINT32  len,
UINT32  dir,
UINT64  mapped 
)
static

Sync callback.

Parameters
unique_idNII NIC
addrAddress of mapped memory
lenLength of mapped memory
dirDirection of data flow
mappedDevice mapped address

Definition at line 471 of file nii.c.

472  {
473  const void *src;
474  void *dst;
475 
476  /* Do nothing if this is an identity mapping */
477  if ( addr == mapped )
478  return;
479 
480  /* Determine direction */
481  if ( dir == FROM_DEVICE ) {
482  src = ( ( void * ) ( intptr_t ) mapped );
483  dst = ( ( void * ) ( intptr_t ) addr );
484  } else {
485  src = ( ( void * ) ( intptr_t ) addr );
486  dst = ( ( void * ) ( intptr_t ) mapped );
487  }
488 
489  /* Copy data */
490  memcpy ( dst, src, len );
491 }
#define FROM_DEVICE
Definition: UefiPxe.h:1092
unsigned long intptr_t
Definition: stdint.h:21
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static __always_inline void off_t userptr_t src
Definition: efi_uaccess.h:66
u32 addr
Definition: sky2.h:8
uint32_t len
Length.
Definition: ena.h:14

References addr, FROM_DEVICE, len, memcpy(), and src.

Referenced by nii_start_undi().

◆ nii_delay()

static EFIAPI VOID nii_delay ( UINT64 unique_id  __unused,
UINTN  microseconds 
)
static

Delay callback.

Parameters
unique_idNII NIC
microsecondsDelay in microseconds

Definition at line 499 of file nii.c.

499  {
500 
501  udelay ( microseconds );
502 }
void udelay(unsigned long usecs)
Delay for a fixed number of microseconds.
Definition: timer.c:60

References udelay().

Referenced by nii_start_undi().

◆ nii_block()

static EFIAPI VOID nii_block ( UINT64  unique_id,
UINT32  acquire 
)
static

Block callback.

Parameters
unique_idNII NIC
acquireAcquire lock

Definition at line 510 of file nii.c.

510  {
511  struct nii_nic *nii = ( ( void * ) ( intptr_t ) unique_id );
513 
514  /* This functionality (which is copied verbatim from the
515  * SnpDxe implementation of this function) appears to be
516  * totally brain-dead, since it produces no actual blocking
517  * behaviour.
518  */
519  if ( acquire ) {
520  nii->saved_tpl = bs->RaiseTPL ( TPL_NOTIFY );
521  } else {
522  bs->RestoreTPL ( nii->saved_tpl );
523  }
524 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
EFI_RAISE_TPL RaiseTPL
Definition: UefiSpec.h:1845
unsigned long intptr_t
Definition: stdint.h:21
#define TPL_NOTIFY
Definition: UefiSpec.h:592
An NII NIC.
Definition: nii.c:152
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition: nii.c:156
EFI_SYSTEM_TABLE * efi_systab
EFI_RESTORE_TPL RestoreTPL
Definition: UefiSpec.h:1846

References EFI_SYSTEM_TABLE::BootServices, efi_systab, nii_nic::nii, EFI_BOOT_SERVICES::RaiseTPL, EFI_BOOT_SERVICES::RestoreTPL, and TPL_NOTIFY.

Referenced by nii_start_undi().

◆ nii_issue_cpb_db()

static int nii_issue_cpb_db ( struct nii_nic nii,
unsigned int  op,
void *  cpb,
size_t  cpb_len,
void *  db,
size_t  db_len 
)
static

Issue command with parameter block and data block.

Parameters
niiNII NIC
opOperation
cpbCommand parameter block, or NULL
cpb_lenCommand parameter block length
dbData block, or NULL
db_lenData block length
Return values
statStatus flags, or negative status code

Definition at line 562 of file nii.c.

563  {
565  PXE_CDB cdb;
566  UINTN tpl;
567 
568  /* Prepare command descriptor block */
569  memset ( &cdb, 0, sizeof ( cdb ) );
570  cdb.OpCode = NII_OPCODE ( op );
571  cdb.OpFlags = NII_OPFLAGS ( op );
572  cdb.CPBaddr = ( ( intptr_t ) cpb );
573  cdb.CPBsize = cpb_len;
574  cdb.DBaddr = ( ( intptr_t ) db );
575  cdb.DBsize = db_len;
576  cdb.IFnum = nii->nii->IfNum;
577 
578  /* Raise task priority level */
579  tpl = bs->RaiseTPL ( TPL_CALLBACK );
580 
581  /* Issue command */
582  DBGC2 ( nii, "NII %s issuing %02x:%04x ifnum %d%s%s\n",
583  nii->dev.name, cdb.OpCode, cdb.OpFlags, cdb.IFnum,
584  ( cpb ? " cpb" : "" ), ( db ? " db" : "" ) );
585  if ( cpb )
586  DBGC2_HD ( nii, cpb, cpb_len );
587  if ( db )
588  DBGC2_HD ( nii, db, db_len );
589  nii->issue ( ( intptr_t ) &cdb );
590 
591  /* Restore task priority level */
592  bs->RestoreTPL ( tpl );
593 
594  /* Check completion status */
595  if ( cdb.StatCode != PXE_STATCODE_SUCCESS )
596  return -cdb.StatCode;
597 
598  /* Return command-specific status flags */
599  return ( cdb.StatFlags & ~PXE_STATFLAGS_STATUS_MASK );
600 }
#define NII_OPFLAGS(op)
Extract flags from operation.
Definition: nii.c:549
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
EFI_RAISE_TPL RaiseTPL
Definition: UefiSpec.h:1845
PXE_UINT16 CPBsize
Definition: UefiPxe.h:885
PXE_UINT16 DBsize
Definition: UefiPxe.h:886
#define NII_OPCODE(op)
Extract opcode from operation.
Definition: nii.c:541
PXE_OPFLAGS OpFlags
Definition: UefiPxe.h:884
unsigned long intptr_t
Definition: stdint.h:21
#define PXE_STATFLAGS_STATUS_MASK
Common StatFlags that can be returned by all commands.
Definition: UefiPxe.h:422
PXE_UINT64 CPBaddr
Definition: UefiPxe.h:887
EFI Boot Services Table.
Definition: UefiSpec.h:1836
#define DBGC2_HD(...)
Definition: compiler.h:524
#define TPL_CALLBACK
Definition: UefiSpec.h:591
UINT64 UINTN
Unsigned value of native width.
Definition: ProcessorBind.h:71
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition: nii.c:156
static struct dmfe_private * db
Definition: dmfe.c:177
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
#define DBGC2(...)
Definition: compiler.h:522
EFI_SYSTEM_TABLE * efi_systab
UINT16 IfNum
The network interface number that is being identified by this Network Interface Identifier Protocol.
EFI_RESTORE_TPL RestoreTPL
Definition: UefiSpec.h:1846
PXE_UINT16 IFnum
Definition: UefiPxe.h:891
PXE_OPCODE OpCode
Definition: UefiPxe.h:883
PXE_UINT64 DBaddr
Definition: UefiPxe.h:888
#define PXE_STATCODE_SUCCESS
Common StatCodes returned by all UNDI commands, UNDI protocol functions and BC protocol functions.
Definition: UefiPxe.h:611
void * memset(void *dest, int character, size_t len) __nonnull

References EFI_SYSTEM_TABLE::BootServices, s_pxe_cdb::CPBaddr, s_pxe_cdb::CPBsize, db, s_pxe_cdb::DBaddr, DBGC2, DBGC2_HD, s_pxe_cdb::DBsize, efi_systab, _EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL::IfNum, s_pxe_cdb::IFnum, memset(), nii_nic::nii, NII_OPCODE, NII_OPFLAGS, op, s_pxe_cdb::OpCode, s_pxe_cdb::OpFlags, PXE_STATCODE_SUCCESS, PXE_STATFLAGS_STATUS_MASK, EFI_BOOT_SERVICES::RaiseTPL, EFI_BOOT_SERVICES::RestoreTPL, and TPL_CALLBACK.

Referenced by nii_initialise_flags(), nii_issue(), nii_issue_cpb(), nii_issue_db(), and nii_poll_rx().

◆ nii_issue_cpb()

static int nii_issue_cpb ( struct nii_nic nii,
unsigned int  op,
void *  cpb,
size_t  cpb_len 
)
static

Issue command with parameter block.

Parameters
niiNII NIC
opOperation
cpbCommand parameter block, or NULL
cpb_lenCommand parameter block length
Return values
statStatus flags, or negative status code

Definition at line 611 of file nii.c.

612  {
613 
614  return nii_issue_cpb_db ( nii, op, cpb, cpb_len, NULL, 0 );
615 }
static int nii_issue_cpb_db(struct nii_nic *nii, unsigned int op, void *cpb, size_t cpb_len, void *db, size_t db_len)
Issue command with parameter block and data block.
Definition: nii.c:562
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition: nii.c:156
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References nii_nic::nii, nii_issue_cpb_db(), NULL, and op.

Referenced by nii_set_station_address(), nii_start_undi(), and nii_transmit().

◆ nii_issue_db()

static int nii_issue_db ( struct nii_nic nii,
unsigned int  op,
void *  db,
size_t  db_len 
)
static

Issue command with data block.

Parameters
niiNII NIC
opOperation
dbData block, or NULL
db_lenData block length
Return values
statStatus flags, or negative status code

Definition at line 626 of file nii.c.

627  {
628 
629  return nii_issue_cpb_db ( nii, op, NULL, 0, db, db_len );
630 }
static int nii_issue_cpb_db(struct nii_nic *nii, unsigned int op, void *cpb, size_t cpb_len, void *db, size_t db_len)
Issue command with parameter block and data block.
Definition: nii.c:562
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition: nii.c:156
static struct dmfe_private * db
Definition: dmfe.c:177
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References db, nii_nic::nii, nii_issue_cpb_db(), NULL, and op.

Referenced by nii_get_init_info(), nii_get_station_address(), and nii_poll().

◆ nii_issue()

static int nii_issue ( struct nii_nic nii,
unsigned int  op 
)
static

Issue command.

Parameters
niiNII NIC
opOperation
Return values
statStatus flags, or negative status code

Definition at line 640 of file nii.c.

640  {
641 
642  return nii_issue_cpb_db ( nii, op, NULL, 0, NULL, 0 );
643 }
static int nii_issue_cpb_db(struct nii_nic *nii, unsigned int op, void *cpb, size_t cpb_len, void *db, size_t db_len)
Issue command with parameter block and data block.
Definition: nii.c:562
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition: nii.c:156
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References nii_nic::nii, nii_issue_cpb_db(), NULL, and op.

Referenced by nii_set_rx_filters(), nii_shutdown(), and nii_stop_undi().

◆ nii_start_undi()

static int nii_start_undi ( struct nii_nic nii)
static

Start UNDI.

Parameters
niiNII NIC
Return values
rcReturn status code

Definition at line 651 of file nii.c.

651  {
652  PXE_CPB_START_31 cpb;
653  int stat;
654  int rc;
655 
656  /* Construct parameter block */
657  memset ( &cpb, 0, sizeof ( cpb ) );
658  cpb.Delay = ( ( intptr_t ) nii_delay );
659  cpb.Block = ( ( intptr_t ) nii_block );
660  cpb.Mem_IO = ( ( intptr_t ) nii_io );
661  cpb.Map_Mem = ( ( intptr_t ) nii_map );
662  cpb.UnMap_Mem = ( ( intptr_t ) nii_unmap );
663  cpb.Sync_Mem = ( ( intptr_t ) nii_sync );
664  cpb.Unique_ID = ( ( intptr_t ) nii );
665 
666  /* Issue command */
667  if ( ( stat = nii_issue_cpb ( nii, PXE_OPCODE_START, &cpb,
668  sizeof ( cpb ) ) ) < 0 ) {
669  rc = -EIO_STAT ( stat );
670  DBGC ( nii, "NII %s could not start: %s\n",
671  nii->dev.name, strerror ( rc ) );
672  return rc;
673  }
674 
675  return 0;
676 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static EFIAPI VOID nii_delay(UINT64 unique_id __unused, UINTN microseconds)
Delay callback.
Definition: nii.c:499
#define DBGC(...)
Definition: compiler.h:505
#define EIO_STAT(stat)
Definition: nii.c:125
unsigned long intptr_t
Definition: stdint.h:21
static EFIAPI VOID nii_sync(UINT64 unique_id __unused, UINT64 addr, UINT32 len, UINT32 dir, UINT64 mapped)
Sync callback.
Definition: nii.c:471
static EFIAPI VOID nii_map(UINT64 unique_id, UINT64 addr, UINT32 len, UINT32 dir, UINT64 mapped)
Map callback.
Definition: nii.c:369
UINT64 Mem_IO
PXE_VOID Mem_IO(UINT64 UnqId, UINT8 read_write, UINT8 len, UINT64 port, UINT64 buf_addr);.
Definition: UefiPxe.h:1040
static EFIAPI VOID nii_io(UINT64 unique_id, UINT8 op, UINT8 len, UINT64 addr, UINT64 data)
I/O callback.
Definition: nii.c:323
UINT64 Map_Mem
PXE_VOID Map_Mem(UINT64 unq_id, UINT64 virtual_addr, UINT32 size, UINT32 Direction,...
Definition: UefiPxe.h:1057
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static EFIAPI VOID nii_block(UINT64 unique_id, UINT32 acquire)
Block callback.
Definition: nii.c:510
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition: nii.c:156
UINT64 Delay
PXE_VOID Delay(UINT64 UnqId, UINTN microseconds);.
Definition: UefiPxe.h:999
UINT64 Sync_Mem
PXE_VOID Sync_Mem(UINT64 unq_id, UINT64 virtual, UINT32 size, UINT32 Direction, UINT64 mapped_addr);.
Definition: UefiPxe.h:1080
UINT64 Block
PXE_VOID Block(UINT64 unq_id, UINT32 enable);.
Definition: UefiPxe.h:1015
UINT64 Unique_ID
protocol driver can provide anything for this Unique_ID, UNDI remembers that as just a 64bit value as...
Definition: UefiPxe.h:1088
static EFIAPI VOID nii_unmap(UINT64 unique_id, UINT64 addr, UINT32 len, UINT32 dir __unused, UINT64 mapped)
Unmap callback.
Definition: nii.c:439
#define PXE_OPCODE_START
Change UNDI operational state from Stopped to Started.
Definition: UefiPxe.h:99
UINT64 UnMap_Mem
PXE_VOID UnMap_Mem(UINT64 unq_id, UINT64 virtual_addr, UINT32 size, UINT32 Direction,...
Definition: UefiPxe.h:1068
static int nii_issue_cpb(struct nii_nic *nii, unsigned int op, void *cpb, size_t cpb_len)
Issue command with parameter block.
Definition: nii.c:611
void * memset(void *dest, int character, size_t len) __nonnull

References s_pxe_cpb_start_31::Block, DBGC, s_pxe_cpb_start_31::Delay, EIO_STAT, s_pxe_cpb_start_31::Map_Mem, s_pxe_cpb_start_31::Mem_IO, memset(), nii_nic::nii, nii_block(), nii_delay(), nii_io(), nii_issue_cpb(), nii_map(), nii_sync(), nii_unmap(), PXE_OPCODE_START, rc, strerror(), s_pxe_cpb_start_31::Sync_Mem, s_pxe_cpb_start_31::Unique_ID, and s_pxe_cpb_start_31::UnMap_Mem.

Referenced by nii_start().

◆ nii_stop_undi()

static void nii_stop_undi ( struct nii_nic nii)
static

Stop UNDI.

Parameters
niiNII NIC

Definition at line 683 of file nii.c.

683  {
684  int stat;
685  int rc;
686 
687  /* Issue command */
688  if ( ( stat = nii_issue ( nii, PXE_OPCODE_STOP ) ) < 0 ) {
689  rc = -EIO_STAT ( stat );
690  DBGC ( nii, "NII %s could not stop: %s\n",
691  nii->dev.name, strerror ( rc ) );
692  /* Nothing we can do about it */
693  return;
694  }
695 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
#define EIO_STAT(stat)
Definition: nii.c:125
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define PXE_OPCODE_STOP
Change UNDI operational state from Started to Stopped.
Definition: UefiPxe.h:104
static int nii_issue(struct nii_nic *nii, unsigned int op)
Issue command.
Definition: nii.c:640
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition: nii.c:156

References DBGC, EIO_STAT, nii_nic::nii, nii_issue(), PXE_OPCODE_STOP, rc, and strerror().

Referenced by nii_start(), and nii_stop().

◆ nii_get_init_info()

static int nii_get_init_info ( struct nii_nic nii,
struct net_device netdev 
)
static

Get initialisation information.

Parameters
niiNII NIC
netdevNetwork device to fill in
Return values
rcReturn status code

Definition at line 704 of file nii.c.

705  {
707  int stat;
708  int rc;
709 
710  /* Issue command */
711  if ( ( stat = nii_issue_db ( nii, PXE_OPCODE_GET_INIT_INFO, &db,
712  sizeof ( db ) ) ) < 0 ) {
713  rc = -EIO_STAT ( stat );
714  DBGC ( nii, "NII %s could not get initialisation info: %s\n",
715  nii->dev.name, strerror ( rc ) );
716  return rc;
717  }
718 
719  /* Determine link layer protocol */
720  switch ( db.IFtype ) {
721  case PXE_IFTYPE_ETHERNET :
722  netdev->ll_protocol = &ethernet_protocol;
723  break;
724  default:
725  DBGC ( nii, "NII %s unknown interface type %#02x\n",
726  nii->dev.name, db.IFtype );
727  return -ENOTSUP;
728  }
729 
730  /* Sanity checks */
731  assert ( db.MediaHeaderLen == netdev->ll_protocol->ll_header_len );
732  assert ( db.HWaddrLen == netdev->ll_protocol->hw_addr_len );
733  assert ( db.HWaddrLen == netdev->ll_protocol->ll_addr_len );
734 
735  /* Extract parameters */
736  nii->buffer_len = db.MemoryRequired;
737  nii->mtu = ( db.FrameDataLen + db.MediaHeaderLen );
738  netdev->max_pkt_len = nii->mtu;
740 
741  return 0;
742 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint8_t ll_header_len
Link-layer header length.
Definition: netdevice.h:200
uint8_t ll_addr_len
Link-layer address length.
Definition: netdevice.h:198
static int nii_issue_db(struct nii_nic *nii, unsigned int op, void *db, size_t db_len)
Issue command with data block.
Definition: nii.c:626
#define DBGC(...)
Definition: compiler.h:505
#define EIO_STAT(stat)
Definition: nii.c:125
#define PXE_IFTYPE_ETHERNET
This information is from the ARP section of RFC 1700.
Definition: UefiPxe.h:715
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
uint8_t hw_addr_len
Hardware address length.
Definition: netdevice.h:196
static struct net_device * netdev
Definition: gdbudp.c:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define PXE_STATFLAGS_GET_STATUS_NO_MEDIA_SUPPORTED
Definition: UefiPxe.h:450
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition: nii.c:156
static struct dmfe_private * db
Definition: dmfe.c:177
size_t max_pkt_len
Maximum packet length.
Definition: netdevice.h:403
#define PXE_OPCODE_GET_INIT_INFO
Get UNDI initialization information.
Definition: UefiPxe.h:109
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:366

References assert(), db, DBGC, EIO_STAT, ENOTSUP, ll_protocol::hw_addr_len, ll_protocol::ll_addr_len, ll_protocol::ll_header_len, net_device::ll_protocol, net_device::max_pkt_len, netdev, nii_nic::nii, nii_issue_db(), PXE_IFTYPE_ETHERNET, PXE_OPCODE_GET_INIT_INFO, PXE_STATFLAGS_GET_STATUS_NO_MEDIA_SUPPORTED, rc, and strerror().

Referenced by nii_start().

◆ nii_initialise_flags()

static int nii_initialise_flags ( struct nii_nic nii,
unsigned int  flags 
)
static

Initialise UNDI.

Parameters
niiNII NIC
flagsFlags
Return values
rcReturn status code

Definition at line 751 of file nii.c.

751  {
752  PXE_CPB_INITIALIZE cpb;
754  unsigned int op;
755  int stat;
756  int rc;
757 
758  /* Allocate memory buffer */
759  nii->buffer = umalloc ( nii->buffer_len );
760  if ( ! nii->buffer ) {
761  rc = -ENOMEM;
762  goto err_alloc;
763  }
764 
765  /* Construct parameter block */
766  memset ( &cpb, 0, sizeof ( cpb ) );
767  cpb.MemoryAddr = ( ( intptr_t ) nii->buffer );
768  cpb.MemoryLength = nii->buffer_len;
769 
770  /* Construct data block */
771  memset ( &db, 0, sizeof ( db ) );
772 
773  /* Issue command */
775  if ( ( stat = nii_issue_cpb_db ( nii, op, &cpb, sizeof ( cpb ),
776  &db, sizeof ( db ) ) ) < 0 ) {
777  rc = -EIO_STAT ( stat );
778  DBGC ( nii, "NII %s could not initialise: %s\n",
779  nii->dev.name, strerror ( rc ) );
780  goto err_initialize;
781  }
782 
783  return 0;
784 
785  err_initialize:
786  ufree ( nii->buffer );
787  err_alloc:
788  return rc;
789 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
PXE_UINT32 MemoryLength
MemoryLength must be greater than or equal to MemoryRequired returned by the Get Init Info command.
Definition: UefiPxe.h:1263
#define DBGC(...)
Definition: compiler.h:505
#define PXE_OPCODE_INITIALIZE
Changed UNDI operational state from Started to Initialized.
Definition: UefiPxe.h:119
#define EIO_STAT(stat)
Definition: nii.c:125
unsigned long intptr_t
Definition: stdint.h:21
PXE_UINT64 MemoryAddr
Address of first (lowest) byte of the memory buffer.
Definition: UefiPxe.h:1257
#define ENOMEM
Not enough space.
Definition: errno.h:534
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static int nii_issue_cpb_db(struct nii_nic *nii, unsigned int op, void *cpb, size_t cpb_len, void *db, size_t db_len)
Issue command with parameter block and data block.
Definition: nii.c:562
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition: nii.c:156
static struct dmfe_private * db
Definition: dmfe.c:177
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
static __always_inline void ufree(userptr_t userptr)
Free external memory.
Definition: umalloc.h:65
static __always_inline userptr_t umalloc(size_t size)
Allocate external memory.
Definition: umalloc.h:54
#define NII_OP(opcode, opflags)
Construct operation from opcode and flags.
Definition: nii.c:533
void * memset(void *dest, int character, size_t len) __nonnull
uint8_t flags
Flags.
Definition: ena.h:18

References db, DBGC, EIO_STAT, ENOMEM, flags, s_pxe_cpb_initialize::MemoryAddr, s_pxe_cpb_initialize::MemoryLength, memset(), nii_nic::nii, nii_issue_cpb_db(), NII_OP, op, PXE_OPCODE_INITIALIZE, rc, strerror(), ufree(), and umalloc().

Referenced by nii_initialise(), and nii_open().

◆ nii_initialise()

static int nii_initialise ( struct nii_nic nii)
static

Initialise UNDI.

Parameters
niiNII NIC
Return values
rcReturn status code

Definition at line 797 of file nii.c.

797  {
798  unsigned int flags;
799 
800  /* Initialise UNDI */
802  return nii_initialise_flags ( nii, flags );
803 }
static int nii_initialise_flags(struct nii_nic *nii, unsigned int flags)
Initialise UNDI.
Definition: nii.c:751
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition: nii.c:156
uint8_t flags
Flags.
Definition: ena.h:18
#define PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE
Definition: UefiPxe.h:221

References flags, nii_nic::nii, nii_initialise_flags(), and PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE.

Referenced by nii_get_station_address().

◆ nii_shutdown()

static void nii_shutdown ( struct nii_nic nii)
static

Shut down UNDI.

Parameters
niiNII NIC

Definition at line 810 of file nii.c.

810  {
811  int stat;
812  int rc;
813 
814  /* Issue command */
815  if ( ( stat = nii_issue ( nii, PXE_OPCODE_SHUTDOWN ) ) < 0 ) {
816  rc = -EIO_STAT ( stat );
817  DBGC ( nii, "NII %s could not shut down: %s\n",
818  nii->dev.name, strerror ( rc ) );
819  /* Leak memory to avoid corruption */
820  return;
821  }
822 
823  /* Free buffer */
824  ufree ( nii->buffer );
825 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define PXE_OPCODE_SHUTDOWN
Change the UNDI operational state from Initialized to Started.
Definition: UefiPxe.h:129
#define DBGC(...)
Definition: compiler.h:505
#define EIO_STAT(stat)
Definition: nii.c:125
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static int nii_issue(struct nii_nic *nii, unsigned int op)
Issue command.
Definition: nii.c:640
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition: nii.c:156
static __always_inline void ufree(userptr_t userptr)
Free external memory.
Definition: umalloc.h:65

References DBGC, EIO_STAT, nii_nic::nii, nii_issue(), PXE_OPCODE_SHUTDOWN, rc, strerror(), and ufree().

Referenced by nii_close(), nii_get_station_address(), and nii_open().

◆ nii_get_station_address()

static int nii_get_station_address ( struct nii_nic nii,
struct net_device netdev 
)
static

Get station addresses.

Parameters
niiNII NIC
netdevNetwork device to fill in
Return values
rcReturn status code

Definition at line 834 of file nii.c.

835  {
837  unsigned int op;
838  int stat;
839  int rc;
840 
841  /* Initialise UNDI */
842  if ( ( rc = nii_initialise ( nii ) ) != 0 )
843  goto err_initialise;
844 
845  /* Issue command */
848  if ( ( stat = nii_issue_db ( nii, op, &db, sizeof ( db ) ) ) < 0 ) {
849  rc = -EIO_STAT ( stat );
850  DBGC ( nii, "NII %s could not get station address: %s\n",
851  nii->dev.name, strerror ( rc ) );
852  goto err_station_address;
853  }
854 
855  /* Copy MAC addresses */
856  memcpy ( netdev->ll_addr, db.StationAddr,
858  memcpy ( netdev->hw_addr, db.PermanentAddr,
860  memcpy ( nii->broadcast, db.BroadcastAddr,
861  sizeof ( nii->broadcast ) );
862 
863  err_station_address:
864  nii_shutdown ( nii );
865  err_initialise:
866  return rc;
867 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint8_t ll_addr_len
Link-layer address length.
Definition: netdevice.h:198
static int nii_issue_db(struct nii_nic *nii, unsigned int op, void *db, size_t db_len)
Issue command with data block.
Definition: nii.c:626
#define DBGC(...)
Definition: compiler.h:505
#define EIO_STAT(stat)
Definition: nii.c:125
#define PXE_OPCODE_STATION_ADDRESS
Read & change station MAC address.
Definition: UefiPxe.h:144
static void nii_shutdown(struct nii_nic *nii)
Shut down UNDI.
Definition: nii.c:810
void * memcpy(void *dest, const void *src, size_t len) __nonnull
uint8_t hw_addr_len
Hardware address length.
Definition: netdevice.h:196
static struct net_device * netdev
Definition: gdbudp.c:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition: nii.c:156
static int nii_initialise(struct nii_nic *nii)
Initialise UNDI.
Definition: nii.c:797
static struct dmfe_private * db
Definition: dmfe.c:177
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:381
#define PXE_OPFLAGS_STATION_ADDRESS_READ
UNDI Station Address.
Definition: UefiPxe.h:322
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:375
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:366
#define NII_OP(opcode, opflags)
Construct operation from opcode and flags.
Definition: nii.c:533

References db, DBGC, EIO_STAT, net_device::hw_addr, ll_protocol::hw_addr_len, net_device::ll_addr, ll_protocol::ll_addr_len, net_device::ll_protocol, memcpy(), netdev, nii_nic::nii, nii_initialise(), nii_issue_db(), NII_OP, nii_shutdown(), op, PXE_OPCODE_STATION_ADDRESS, PXE_OPFLAGS_STATION_ADDRESS_READ, rc, and strerror().

Referenced by nii_start().

◆ nii_set_station_address()

static int nii_set_station_address ( struct nii_nic nii,
struct net_device netdev 
)
static

Set station address.

Parameters
niiNII NIC
netdevNetwork device
Return values
rcReturn status code

Definition at line 876 of file nii.c.

877  {
878  uint32_t implementation = nii->undi->Implementation;
880  unsigned int op;
881  int stat;
882  int rc;
883 
884  /* Fail if setting station address is unsupported */
886  return -ENOTSUP;
887 
888  /* Construct parameter block */
889  memset ( &cpb, 0, sizeof ( cpb ) );
892 
893  /* Issue command */
896  if ( ( stat = nii_issue_cpb ( nii, op, &cpb, sizeof ( cpb ) ) ) < 0 ) {
897  rc = -EIO_STAT ( stat );
898  DBGC ( nii, "NII %s could not set station address: %s\n",
899  nii->dev.name, strerror ( rc ) );
900  return rc;
901  }
902 
903  return 0;
904 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint8_t ll_addr_len
Link-layer address length.
Definition: netdevice.h:198
#define DBGC(...)
Definition: compiler.h:505
#define PXE_ROMID_IMP_STATION_ADDR_SETTABLE
Definition: UefiPxe.h:872
#define EIO_STAT(stat)
Definition: nii.c:125
PXE_MAC_ADDR StationAddr
If supplied and supported, the current station MAC address will be changed.
Definition: UefiPxe.h:1347
uint32_t implementation
Implementation.
Definition: ena.h:12
#define PXE_OPCODE_STATION_ADDRESS
Read & change station MAC address.
Definition: UefiPxe.h:144
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static struct net_device * netdev
Definition: gdbudp.c:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define PXE_OPFLAGS_STATION_ADDRESS_WRITE
Definition: UefiPxe.h:323
unsigned int uint32_t
Definition: stdint.h:12
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition: nii.c:156
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:381
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:366
static int nii_issue_cpb(struct nii_nic *nii, unsigned int op, void *cpb, size_t cpb_len)
Issue command with parameter block.
Definition: nii.c:611
#define NII_OP(opcode, opflags)
Construct operation from opcode and flags.
Definition: nii.c:533
void * memset(void *dest, int character, size_t len) __nonnull

References DBGC, EIO_STAT, ENOTSUP, implementation, net_device::ll_addr, ll_protocol::ll_addr_len, net_device::ll_protocol, memcpy(), memset(), netdev, nii_nic::nii, nii_issue_cpb(), NII_OP, op, PXE_OPCODE_STATION_ADDRESS, PXE_OPFLAGS_STATION_ADDRESS_WRITE, PXE_ROMID_IMP_STATION_ADDR_SETTABLE, rc, s_pxe_cpb_station_address::StationAddr, and strerror().

Referenced by nii_open().

◆ nii_set_rx_filters()

static int nii_set_rx_filters ( struct nii_nic nii)
static

Set receive filters.

Parameters
niiNII NIC
Return values
rcReturn status code

Definition at line 912 of file nii.c.

912  {
913  uint32_t implementation = nii->undi->Implementation;
914  unsigned int flags;
915  unsigned int op;
916  int stat;
917  int rc;
918 
919  /* Construct receive filter set */
928 
929  /* Issue command */
931  if ( ( stat = nii_issue ( nii, op ) ) < 0 ) {
932  rc = -EIO_STAT ( stat );
933  DBGC ( nii, "NII %s could not set receive filters %#04x: %s\n",
934  nii->dev.name, flags, strerror ( rc ) );
935  return rc;
936  }
937 
938  return 0;
939 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define PXE_ROMID_IMP_BROADCAST_RX_SUPPORTED
Definition: UefiPxe.h:875
#define DBGC(...)
Definition: compiler.h:505
#define EIO_STAT(stat)
Definition: nii.c:125
uint32_t implementation
Implementation.
Definition: ena.h:12
#define PXE_OPFLAGS_RECEIVE_FILTER_BROADCAST
Enable broadcast packet receiving.
Definition: UefiPxe.h:299
#define PXE_OPFLAGS_RECEIVE_FILTER_ENABLE
Definition: UefiPxe.h:279
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define PXE_ROMID_IMP_PROMISCUOUS_RX_SUPPORTED
Definition: UefiPxe.h:874
#define PXE_OPFLAGS_RECEIVE_FILTER_UNICAST
Enable unicast packet receiving.
Definition: UefiPxe.h:293
static int nii_issue(struct nii_nic *nii, unsigned int op)
Issue command.
Definition: nii.c:640
unsigned int uint32_t
Definition: stdint.h:12
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition: nii.c:156
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
#define PXE_OPFLAGS_RECEIVE_FILTER_ALL_MULTICAST
Enable promiscuous multicast packet receiving.
Definition: UefiPxe.h:317
#define PXE_OPCODE_RECEIVE_FILTERS
Read & change state of packet receive filters.
Definition: UefiPxe.h:139
#define PXE_OPFLAGS_RECEIVE_FILTER_PROMISCUOUS
Enable promiscuous packet receiving.
Definition: UefiPxe.h:311
#define PXE_ROMID_IMP_PROMISCUOUS_MULTICAST_RX_SUPPORTED
Definition: UefiPxe.h:873
#define NII_OP(opcode, opflags)
Construct operation from opcode and flags.
Definition: nii.c:533
uint8_t flags
Flags.
Definition: ena.h:18

References DBGC, EIO_STAT, flags, implementation, nii_nic::nii, nii_issue(), NII_OP, op, PXE_OPCODE_RECEIVE_FILTERS, PXE_OPFLAGS_RECEIVE_FILTER_ALL_MULTICAST, PXE_OPFLAGS_RECEIVE_FILTER_BROADCAST, PXE_OPFLAGS_RECEIVE_FILTER_ENABLE, PXE_OPFLAGS_RECEIVE_FILTER_PROMISCUOUS, PXE_OPFLAGS_RECEIVE_FILTER_UNICAST, PXE_ROMID_IMP_BROADCAST_RX_SUPPORTED, PXE_ROMID_IMP_PROMISCUOUS_MULTICAST_RX_SUPPORTED, PXE_ROMID_IMP_PROMISCUOUS_RX_SUPPORTED, rc, and strerror().

Referenced by nii_open().

◆ nii_transmit()

static int nii_transmit ( struct net_device netdev,
struct io_buffer iobuf 
)
static

Transmit packet.

Parameters
netdevNetwork device
iobufI/O buffer
Return values
rcReturn status code

Definition at line 948 of file nii.c.

949  {
950  struct nii_nic *nii = netdev->priv;
951  PXE_CPB_TRANSMIT cpb;
952  unsigned int op;
953  int stat;
954  int rc;
955 
956  /* Defer the packet if there is already a transmission in progress */
957  if ( nii->txbuf ) {
958  netdev_tx_defer ( netdev, iobuf );
959  return 0;
960  }
961 
962  /* Construct parameter block */
963  memset ( &cpb, 0, sizeof ( cpb ) );
964  cpb.FrameAddr = virt_to_bus ( iobuf->data );
965  cpb.DataLen = iob_len ( iobuf );
967 
968  /* Transmit packet */
972  if ( ( stat = nii_issue_cpb ( nii, op, &cpb, sizeof ( cpb ) ) ) < 0 ) {
973  rc = -EIO_STAT ( stat );
974  DBGC ( nii, "NII %s could not transmit: %s\n",
975  nii->dev.name, strerror ( rc ) );
976  return rc;
977  }
978  nii->txbuf = iobuf;
979 
980  return 0;
981 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void netdev_tx_defer(struct net_device *netdev, struct io_buffer *iobuf)
Defer transmitted packet.
Definition: netdevice.c:344
uint8_t ll_header_len
Link-layer header length.
Definition: netdevice.h:200
PXE_UINT32 DataLen
Length of the data portion of the frame buffer in bytes.
Definition: UefiPxe.h:1684
#define DBGC(...)
Definition: compiler.h:505
#define EIO_STAT(stat)
Definition: nii.c:125
PXE_UINT64 FrameAddr
Address of first byte of frame buffer.
Definition: UefiPxe.h:1678
An NII NIC.
Definition: nii.c:152
#define PXE_OPFLAGS_TRANSMIT_WHOLE
Definition: UefiPxe.h:399
#define PXE_OPCODE_TRANSMIT
Transmit packet(s).
Definition: UefiPxe.h:174
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
void * priv
Driver private data.
Definition: netdevice.h:425
static struct net_device * netdev
Definition: gdbudp.c:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
#define PXE_OPFLAGS_TRANSMIT_DONT_BLOCK
Definition: UefiPxe.h:395
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition: nii.c:156
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
PXE_UINT16 MediaheaderLen
Length of the media header in bytes.
Definition: UefiPxe.h:1689
void * data
Start of data.
Definition: iobuf.h:44
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:366
static int nii_issue_cpb(struct nii_nic *nii, unsigned int op, void *cpb, size_t cpb_len)
Issue command with parameter block.
Definition: nii.c:611
#define NII_OP(opcode, opflags)
Construct operation from opcode and flags.
Definition: nii.c:533
void * memset(void *dest, int character, size_t len) __nonnull

References io_buffer::data, s_pxe_cpb_transmit::DataLen, DBGC, EIO_STAT, s_pxe_cpb_transmit::FrameAddr, iob_len(), ll_protocol::ll_header_len, net_device::ll_protocol, s_pxe_cpb_transmit::MediaheaderLen, memset(), netdev, netdev_tx_defer(), nii_nic::nii, nii_issue_cpb(), NII_OP, op, net_device::priv, PXE_OPCODE_TRANSMIT, PXE_OPFLAGS_TRANSMIT_DONT_BLOCK, PXE_OPFLAGS_TRANSMIT_WHOLE, rc, strerror(), and virt_to_bus().

◆ nii_poll_tx()

static void nii_poll_tx ( struct net_device netdev,
unsigned int  stat 
)
static

Poll for completed packets.

Parameters
netdevNetwork device
statStatus flags

Definition at line 989 of file nii.c.

989  {
990  struct nii_nic *nii = netdev->priv;
991  struct io_buffer *iobuf;
992 
993  /* Do nothing unless we have a completion */
995  return;
996 
997  /* Sanity check */
998  assert ( nii->txbuf != NULL );
999 
1000  /* Complete transmission */
1001  iobuf = nii->txbuf;
1002  nii->txbuf = NULL;
1003  netdev_tx_complete ( netdev, iobuf );
1004 }
static void netdev_tx_complete(struct net_device *netdev, struct io_buffer *iobuf)
Complete network transmission.
Definition: netdevice.h:746
#define PXE_STATFLAGS_GET_STATUS_NO_TXBUFS_WRITTEN
This flag is set if no transmitted buffer addresses were written into the DB.
Definition: UefiPxe.h:578
An NII NIC.
Definition: nii.c:152
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
void * priv
Driver private data.
Definition: netdevice.h:425
static struct net_device * netdev
Definition: gdbudp.c:52
struct io_buffer * txbuf
Current transmit buffer.
Definition: nii.c:190
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition: nii.c:156
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
A persistent I/O buffer.
Definition: iobuf.h:32

References assert(), netdev, netdev_tx_complete(), nii_nic::nii, NULL, net_device::priv, PXE_STATFLAGS_GET_STATUS_NO_TXBUFS_WRITTEN, and nii_nic::txbuf.

Referenced by nii_poll().

◆ nii_poll_rx()

static void nii_poll_rx ( struct net_device netdev)
static

Poll for received packets.

Parameters
netdevNetwork device

Definition at line 1011 of file nii.c.

1011  {
1012  struct nii_nic *nii = netdev->priv;
1013  PXE_CPB_RECEIVE cpb;
1015  unsigned int quota;
1016  int stat;
1017  int rc;
1018 
1019  /* Retrieve up to NII_RX_QUOTA packets */
1020  for ( quota = NII_RX_QUOTA ; quota ; quota-- ) {
1021 
1022  /* Allocate buffer, if required */
1023  if ( ! nii->rxbuf ) {
1024  nii->rxbuf = alloc_iob ( nii->mtu );
1025  if ( ! nii->rxbuf ) {
1026  /* Leave for next poll */
1027  break;
1028  }
1029  }
1030 
1031  /* Construct parameter block */
1032  memset ( &cpb, 0, sizeof ( cpb ) );
1033  cpb.BufferAddr = virt_to_bus ( nii->rxbuf->data );
1034  cpb.BufferLen = iob_tailroom ( nii->rxbuf );
1035 
1036  /* Issue command */
1037  if ( ( stat = nii_issue_cpb_db ( nii, PXE_OPCODE_RECEIVE,
1038  &cpb, sizeof ( cpb ),
1039  &db, sizeof ( db ) ) ) < 0 ) {
1040 
1041  /* PXE_STATCODE_NO_DATA is just the usual "no packet"
1042  * status indicator; ignore it.
1043  */
1044  if ( stat == -PXE_STATCODE_NO_DATA )
1045  break;
1046 
1047  /* Anything else is an error */
1048  rc = -EIO_STAT ( stat );
1049  DBGC ( nii, "NII %s could not receive: %s\n",
1050  nii->dev.name, strerror ( rc ) );
1051  netdev_rx_err ( netdev, NULL, rc );
1052  break;
1053  }
1054 
1055  /* Hand off to network stack */
1056  iob_put ( nii->rxbuf, db.FrameLen );
1057  netdev_rx ( netdev, nii->rxbuf );
1058  nii->rxbuf = NULL;
1059  }
1060 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define iob_put(iobuf, len)
Definition: iobuf.h:116
PXE_UINT32 BufferLen
Length of receive buffer.
Definition: UefiPxe.h:1748
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:501
#define DBGC(...)
Definition: compiler.h:505
#define EIO_STAT(stat)
Definition: nii.c:125
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:128
An NII NIC.
Definition: nii.c:152
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
void * priv
Driver private data.
Definition: netdevice.h:425
static struct net_device * netdev
Definition: gdbudp.c:52
PXE_UINT64 BufferAddr
Address of first byte of receive buffer.
Definition: UefiPxe.h:1741
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static size_t iob_tailroom(struct io_buffer *iobuf)
Calculate available space at end of an I/O buffer.
Definition: iobuf.h:171
static int nii_issue_cpb_db(struct nii_nic *nii, unsigned int op, void *cpb, size_t cpb_len, void *db, size_t db_len)
Issue command with parameter block and data block.
Definition: nii.c:562
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition: nii.c:156
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition: netdevice.c:470
static struct dmfe_private * db
Definition: dmfe.c:177
#define PXE_STATCODE_NO_DATA
Definition: UefiPxe.h:631
#define PXE_OPCODE_RECEIVE
Receive packet.
Definition: UefiPxe.h:179
#define NII_RX_QUOTA
Maximum number of received packets per poll.
Definition: nii.c:199
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
void * memset(void *dest, int character, size_t len) __nonnull

References alloc_iob(), s_pxe_cpb_receive::BufferAddr, s_pxe_cpb_receive::BufferLen, db, DBGC, EIO_STAT, iob_put, iob_tailroom(), memset(), netdev, netdev_rx(), netdev_rx_err(), nii_nic::nii, nii_issue_cpb_db(), NII_RX_QUOTA, NULL, net_device::priv, PXE_OPCODE_RECEIVE, PXE_STATCODE_NO_DATA, rc, strerror(), and virt_to_bus().

Referenced by nii_poll().

◆ nii_poll_link()

static void nii_poll_link ( struct net_device netdev,
unsigned int  stat 
)
static

Check for link state changes.

Parameters
netdevNetwork device
statStatus flags

Definition at line 1068 of file nii.c.

1068  {
1069  int no_media = ( stat & PXE_STATFLAGS_GET_STATUS_NO_MEDIA );
1070 
1071  if ( no_media && netdev_link_ok ( netdev ) ) {
1073  } else if ( ( ! no_media ) && ( ! netdev_link_ok ( netdev ) ) ) {
1074  netdev_link_up ( netdev );
1075  }
1076 }
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
Definition: netdevice.c:186
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:768
static int netdev_link_ok(struct net_device *netdev)
Check link state of network device.
Definition: netdevice.h:630
static struct net_device * netdev
Definition: gdbudp.c:52
#define PXE_STATFLAGS_GET_STATUS_NO_MEDIA
This flag is set if there is no media detected.
Definition: UefiPxe.h:583

References netdev, netdev_link_down(), netdev_link_ok(), netdev_link_up(), and PXE_STATFLAGS_GET_STATUS_NO_MEDIA.

Referenced by nii_poll().

◆ nii_poll()

static void nii_poll ( struct net_device netdev)
static

Poll for completed packets.

Parameters
netdevNetwork device

Definition at line 1083 of file nii.c.

1083  {
1084  struct nii_nic *nii = netdev->priv;
1086  unsigned int op;
1087  int stat;
1088  int rc;
1089 
1090  /* Construct data block */
1091  memset ( &db, 0, sizeof ( db ) );
1092 
1093  /* Get status */
1096  ( nii->txbuf ? PXE_OPFLAGS_GET_TRANSMITTED_BUFFERS : 0)|
1097  ( nii->media ? PXE_OPFLAGS_GET_MEDIA_STATUS : 0 ) ) );
1098  if ( ( stat = nii_issue_db ( nii, op, &db, sizeof ( db ) ) ) < 0 ) {
1099  rc = -EIO_STAT ( stat );
1100  DBGC ( nii, "NII %s could not get status: %s\n",
1101  nii->dev.name, strerror ( rc ) );
1102  return;
1103  }
1104 
1105  /* Process any TX completions */
1106  if ( nii->txbuf )
1107  nii_poll_tx ( netdev, stat );
1108 
1109  /* Process any RX completions */
1110  nii_poll_rx ( netdev );
1111 
1112  /* Check for link state changes */
1113  if ( nii->media )
1114  nii_poll_link ( netdev, stat );
1115 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void nii_poll_link(struct net_device *netdev, unsigned int stat)
Check for link state changes.
Definition: nii.c:1068
static int nii_issue_db(struct nii_nic *nii, unsigned int op, void *db, size_t db_len)
Issue command with data block.
Definition: nii.c:626
#define DBGC(...)
Definition: compiler.h:505
#define EIO_STAT(stat)
Definition: nii.c:125
#define PXE_OPFLAGS_GET_TRANSMITTED_BUFFERS
Return list of transmitted buffers for recycling.
Definition: UefiPxe.h:371
static void nii_poll_tx(struct net_device *netdev, unsigned int stat)
Poll for completed packets.
Definition: nii.c:989
An NII NIC.
Definition: nii.c:152
void * priv
Driver private data.
Definition: netdevice.h:425
static struct net_device * netdev
Definition: gdbudp.c:52
#define PXE_OPFLAGS_GET_INTERRUPT_STATUS
UNDI Get Status.
Definition: UefiPxe.h:361
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define PXE_OPCODE_GET_STATUS
Get & clear interrupt status.
Definition: UefiPxe.h:164
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition: nii.c:156
static struct dmfe_private * db
Definition: dmfe.c:177
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
static void nii_poll_rx(struct net_device *netdev)
Poll for received packets.
Definition: nii.c:1011
#define PXE_OPFLAGS_GET_MEDIA_STATUS
Return current media status.
Definition: UefiPxe.h:376
#define NII_OP(opcode, opflags)
Construct operation from opcode and flags.
Definition: nii.c:533
void * memset(void *dest, int character, size_t len) __nonnull

References db, DBGC, EIO_STAT, memset(), netdev, nii_nic::nii, nii_issue_db(), NII_OP, nii_poll_link(), nii_poll_rx(), nii_poll_tx(), op, net_device::priv, PXE_OPCODE_GET_STATUS, PXE_OPFLAGS_GET_INTERRUPT_STATUS, PXE_OPFLAGS_GET_MEDIA_STATUS, PXE_OPFLAGS_GET_TRANSMITTED_BUFFERS, rc, and strerror().

◆ nii_open()

static int nii_open ( struct net_device netdev)
static

Open network device.

Parameters
netdevNetwork device
Return values
rcReturn status code

Definition at line 1123 of file nii.c.

1123  {
1124  struct nii_nic *nii = netdev->priv;
1125  unsigned int flags;
1126  int rc;
1127 
1128  /* Initialise NIC
1129  *
1130  * We don't care about link state here, and would prefer to
1131  * have the NIC initialise even if no cable is present, to
1132  * match the behaviour of all other iPXE drivers.
1133  *
1134  * Some Emulex NII drivers have a bug which prevents packets
1135  * from being sent or received unless we specifically ask it
1136  * to detect cable presence during initialisation.
1137  *
1138  * Unfortunately, some other NII drivers (e.g. Mellanox) may
1139  * time out and report failure if asked to detect cable
1140  * presence during initialisation on links that are physically
1141  * slow to reach link-up.
1142  *
1143  * Attempt to work around both of these problems by requesting
1144  * cable detection at this point if any only if the driver is
1145  * not capable of reporting link status changes at runtime via
1146  * PXE_OPCODE_GET_STATUS.
1147  */
1150  if ( ( rc = nii_initialise_flags ( nii, flags ) ) != 0 )
1151  goto err_initialise;
1152 
1153  /* Attempt to set station address */
1154  if ( ( rc = nii_set_station_address ( nii, netdev ) ) != 0 ) {
1155  DBGC ( nii, "NII %s could not set station address: %s\n",
1156  nii->dev.name, strerror ( rc ) );
1157  /* Treat as non-fatal */
1158  }
1159 
1160  /* Set receive filters */
1161  if ( ( rc = nii_set_rx_filters ( nii ) ) != 0 )
1162  goto err_set_rx_filters;
1163 
1164  return 0;
1165 
1166  err_set_rx_filters:
1167  nii_shutdown ( nii );
1168  err_initialise:
1169  return rc;
1170 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
static int nii_initialise_flags(struct nii_nic *nii, unsigned int flags)
Initialise UNDI.
Definition: nii.c:751
#define PXE_OPFLAGS_INITIALIZE_DETECT_CABLE
Definition: UefiPxe.h:220
static void nii_shutdown(struct nii_nic *nii)
Shut down UNDI.
Definition: nii.c:810
An NII NIC.
Definition: nii.c:152
static int nii_set_station_address(struct nii_nic *nii, struct net_device *netdev)
Set station address.
Definition: nii.c:876
void * priv
Driver private data.
Definition: netdevice.h:425
static struct net_device * netdev
Definition: gdbudp.c:52
static int nii_set_rx_filters(struct nii_nic *nii)
Set receive filters.
Definition: nii.c:912
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition: nii.c:156
uint8_t flags
Flags.
Definition: ena.h:18
#define PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE
Definition: UefiPxe.h:221

References DBGC, flags, netdev, nii_nic::nii, nii_initialise_flags(), nii_set_rx_filters(), nii_set_station_address(), nii_shutdown(), net_device::priv, PXE_OPFLAGS_INITIALIZE_DETECT_CABLE, PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE, rc, and strerror().

◆ nii_close()

static void nii_close ( struct net_device netdev)
static

Close network device.

Parameters
netdevNetwork device

Definition at line 1177 of file nii.c.

1177  {
1178  struct nii_nic *nii = netdev->priv;
1179 
1180  /* Shut down NIC */
1181  nii_shutdown ( nii );
1182 
1183  /* Discard transmit buffer, if applicable */
1184  if ( nii->txbuf ) {
1186  nii->txbuf = NULL;
1187  }
1188 
1189  /* Discard receive buffer, if applicable */
1190  if ( nii->rxbuf ) {
1191  free_iob ( nii->rxbuf );
1192  nii->rxbuf = NULL;
1193  }
1194 }
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
#define ECANCELED
Operation canceled.
Definition: errno.h:343
static void nii_shutdown(struct nii_nic *nii)
Shut down UNDI.
Definition: nii.c:810
An NII NIC.
Definition: nii.c:152
void * priv
Driver private data.
Definition: netdevice.h:425
static struct net_device * netdev
Definition: gdbudp.c:52
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition: nii.c:156
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
Definition: netdevice.c:395
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References ECANCELED, free_iob(), netdev, netdev_tx_complete_err(), nii_nic::nii, nii_shutdown(), NULL, and net_device::priv.

◆ 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:159
#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:262
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:33
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:33
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().

Variable Documentation

◆ nii_operations

struct net_device_operations nii_operations
static
Initial value:
= {
.open = nii_open,
.close = nii_close,
.transmit = nii_transmit,
.poll = nii_poll,
}
static void nii_poll(struct net_device *netdev)
Poll for completed packets.
Definition: nii.c:1083
static int nii_open(struct net_device *netdev)
Open network device.
Definition: nii.c:1123
static void nii_close(struct net_device *netdev)
Close network device.
Definition: nii.c:1177
static int nii_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: nii.c:948

NII network device operations.

Definition at line 1197 of file nii.c.

Referenced by nii_start().