iPXE
nii.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 #include <string.h>
27 #include <strings.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <errno.h>
31 #include <ipxe/netdevice.h>
32 #include <ipxe/ethernet.h>
33 #include <ipxe/if_ether.h>
34 #include <ipxe/umalloc.h>
35 #include <ipxe/efi/efi.h>
36 #include <ipxe/efi/efi_driver.h>
37 #include <ipxe/efi/efi_pci.h>
38 #include <ipxe/efi/efi_utils.h>
41 #include "nii.h"
42 
43 /** @file
44  *
45  * NII driver
46  *
47  */
48 
49 /* Error numbers generated by NII */
50 #define EIO_INVALID_CDB __einfo_error ( EINFO_EIO_INVALID_CDB )
51 #define EINFO_EIO_INVALID_CDB \
52  __einfo_uniqify ( EINFO_EIO, PXE_STATCODE_INVALID_CDB, \
53  "Invalid CDB" )
54 #define EIO_INVALID_CPB __einfo_error ( EINFO_EIO_INVALID_CPB )
55 #define EINFO_EIO_INVALID_CPB \
56  __einfo_uniqify ( EINFO_EIO, PXE_STATCODE_INVALID_CPB, \
57  "Invalid CPB" )
58 #define EIO_BUSY __einfo_error ( EINFO_EIO_BUSY )
59 #define EINFO_EIO_BUSY \
60  __einfo_uniqify ( EINFO_EIO, PXE_STATCODE_BUSY, \
61  "Busy" )
62 #define EIO_QUEUE_FULL __einfo_error ( EINFO_EIO_QUEUE_FULL )
63 #define EINFO_EIO_QUEUE_FULL \
64  __einfo_uniqify ( EINFO_EIO, PXE_STATCODE_QUEUE_FULL, \
65  "Queue full" )
66 #define EIO_ALREADY_STARTED __einfo_error ( EINFO_EIO_ALREADY_STARTED )
67 #define EINFO_EIO_ALREADY_STARTED \
68  __einfo_uniqify ( EINFO_EIO, PXE_STATCODE_ALREADY_STARTED, \
69  "Already started" )
70 #define EIO_NOT_STARTED __einfo_error ( EINFO_EIO_NOT_STARTED )
71 #define EINFO_EIO_NOT_STARTED \
72  __einfo_uniqify ( EINFO_EIO, PXE_STATCODE_NOT_STARTED, \
73  "Not started" )
74 #define EIO_NOT_SHUTDOWN __einfo_error ( EINFO_EIO_NOT_SHUTDOWN )
75 #define EINFO_EIO_NOT_SHUTDOWN \
76  __einfo_uniqify ( EINFO_EIO, PXE_STATCODE_NOT_SHUTDOWN, \
77  "Not shutdown" )
78 #define EIO_ALREADY_INITIALIZED __einfo_error ( EINFO_EIO_ALREADY_INITIALIZED )
79 #define EINFO_EIO_ALREADY_INITIALIZED \
80  __einfo_uniqify ( EINFO_EIO, PXE_STATCODE_ALREADY_INITIALIZED, \
81  "Already initialized" )
82 #define EIO_NOT_INITIALIZED __einfo_error ( EINFO_EIO_NOT_INITIALIZED )
83 #define EINFO_EIO_NOT_INITIALIZED \
84  __einfo_uniqify ( EINFO_EIO, PXE_STATCODE_NOT_INITIALIZED, \
85  "Not initialized" )
86 #define EIO_DEVICE_FAILURE __einfo_error ( EINFO_EIO_DEVICE_FAILURE )
87 #define EINFO_EIO_DEVICE_FAILURE \
88  __einfo_uniqify ( EINFO_EIO, PXE_STATCODE_DEVICE_FAILURE, \
89  "Device failure" )
90 #define EIO_NVDATA_FAILURE __einfo_error ( EINFO_EIO_NVDATA_FAILURE )
91 #define EINFO_EIO_NVDATA_FAILURE \
92  __einfo_uniqify ( EINFO_EIO, PXE_STATCODE_NVDATA_FAILURE, \
93  "Non-volatile data failure" )
94 #define EIO_UNSUPPORTED __einfo_error ( EINFO_EIO_UNSUPPORTED )
95 #define EINFO_EIO_UNSUPPORTED \
96  __einfo_uniqify ( EINFO_EIO, PXE_STATCODE_UNSUPPORTED, \
97  "Unsupported" )
98 #define EIO_BUFFER_FULL __einfo_error ( EINFO_EIO_BUFFER_FULL )
99 #define EINFO_EIO_BUFFER_FULL \
100  __einfo_uniqify ( EINFO_EIO, PXE_STATCODE_BUFFER_FULL, \
101  "Buffer full" )
102 #define EIO_INVALID_PARAMETER __einfo_error ( EINFO_EIO_INVALID_PARAMETER )
103 #define EINFO_EIO_INVALID_PARAMETER \
104  __einfo_uniqify ( EINFO_EIO, PXE_STATCODE_INVALID_PARAMETER, \
105  "Invalid parameter" )
106 #define EIO_INVALID_UNDI __einfo_error ( EINFO_EIO_INVALID_UNDI )
107 #define EINFO_EIO_INVALID_UNDI \
108  __einfo_uniqify ( EINFO_EIO, PXE_STATCODE_INVALID_UNDI, \
109  "Invalid UNDI" )
110 #define EIO_IPV4_NOT_SUPPORTED __einfo_error ( EINFO_EIO_IPV4_NOT_SUPPORTED )
111 #define EINFO_EIO_IPV4_NOT_SUPPORTED \
112  __einfo_uniqify ( EINFO_EIO, PXE_STATCODE_IPV4_NOT_SUPPORTED, \
113  "IPv4 not supported" )
114 #define EIO_IPV6_NOT_SUPPORTED __einfo_error ( EINFO_EIO_IPV6_NOT_SUPPORTED )
115 #define EINFO_EIO_IPV6_NOT_SUPPORTED \
116  __einfo_uniqify ( EINFO_EIO, PXE_STATCODE_IPV6_NOT_SUPPORTED, \
117  "IPv6 not supported" )
118 #define EIO_NOT_ENOUGH_MEMORY __einfo_error ( EINFO_EIO_NOT_ENOUGH_MEMORY )
119 #define EINFO_EIO_NOT_ENOUGH_MEMORY \
120  __einfo_uniqify ( EINFO_EIO, PXE_STATCODE_NOT_ENOUGH_MEMORY, \
121  "Not enough memory" )
122 #define EIO_NO_DATA __einfo_error ( EINFO_EIO_NO_DATA )
123 #define EINFO_EIO_NO_DATA \
124  __einfo_uniqify ( EINFO_EIO, PXE_STATCODE_NO_DATA, \
125  "No data" )
126 #define EIO_STAT( stat ) \
127  EUNIQ ( EINFO_EIO, -(stat), EIO_INVALID_CDB, EIO_INVALID_CPB, \
128  EIO_BUSY, EIO_QUEUE_FULL, EIO_ALREADY_STARTED, \
129  EIO_NOT_STARTED, EIO_NOT_SHUTDOWN, EIO_ALREADY_INITIALIZED, \
130  EIO_NOT_INITIALIZED, EIO_DEVICE_FAILURE, EIO_NVDATA_FAILURE, \
131  EIO_UNSUPPORTED, EIO_BUFFER_FULL, EIO_INVALID_PARAMETER, \
132  EIO_INVALID_UNDI, EIO_IPV4_NOT_SUPPORTED, \
133  EIO_IPV6_NOT_SUPPORTED, EIO_NOT_ENOUGH_MEMORY, EIO_NO_DATA )
134 
135 /** Maximum PCI BAR
136  *
137  * This is defined in <ipxe/efi/IndustryStandard/Pci22.h>, but we
138  * can't #include that since it collides with <ipxe/pci.h>.
139  */
140 #define PCI_MAX_BAR 6
141 
142 /** An NII memory mapping */
143 struct nii_mapping {
144  /** List of mappings */
145  struct list_head list;
146  /** Mapped address */
148  /** Mapping cookie created by PCI I/O protocol */
150 };
151 
152 /** An NII NIC */
153 struct nii_nic {
154  /** EFI device */
156  /** Network interface identifier protocol */
158  /** !PXE structure */
160  /** Entry point */
161  EFIAPI VOID ( * issue ) ( UINT64 cdb );
162  /** Generic device */
163  struct device dev;
164 
165  /** PCI device */
167  /** PCI I/O protocol */
169  /** Memory BAR */
170  unsigned int mem_bar;
171  /** I/O BAR */
172  unsigned int io_bar;
173 
174  /** Broadcast address */
176  /** Maximum packet length */
177  size_t mtu;
178 
179  /** Hardware transmit/receive buffer */
181  /** Hardware transmit/receive buffer length */
182  size_t buffer_len;
183 
184  /** Saved task priority level */
186 
187  /** Media status is supported */
188  int media;
189 
190  /** Current transmit buffer */
191  struct io_buffer *txbuf;
192  /** Current receive buffer */
193  struct io_buffer *rxbuf;
194 
195  /** Mapping list */
197 };
198 
199 /** Maximum number of received packets per poll */
200 #define NII_RX_QUOTA 4
201 
202 /**
203  * Open PCI I/O protocol and identify BARs
204  *
205  * @v nii NII NIC
206  * @ret rc Return status code
207  */
208 static int nii_pci_open ( struct nii_nic *nii ) {
210  EFI_HANDLE device = nii->efidev->device;
212  union {
213  EFI_PCI_IO_PROTOCOL *pci_io;
214  void *interface;
215  } pci_io;
216  union {
218  void *resource;
219  } desc;
220  int bar;
221  EFI_STATUS efirc;
222  int rc;
223 
224  /* Locate PCI I/O protocol */
226  &pci_device, 0 ) ) != 0 ) {
227  DBGC ( nii, "NII %s could not locate PCI I/O protocol: %s\n",
228  nii->dev.name, strerror ( rc ) );
229  goto err_locate;
230  }
231  nii->pci_device = pci_device;
232 
233  /* Open PCI I/O protocol */
234  if ( ( efirc = bs->OpenProtocol ( pci_device, &efi_pci_io_protocol_guid,
235  &pci_io.interface, efi_image_handle,
236  device,
238  rc = -EEFI ( efirc );
239  DBGC ( nii, "NII %s could not open PCI I/O protocol: %s\n",
240  nii->dev.name, strerror ( rc ) );
241  goto err_open;
242  }
243  nii->pci_io = pci_io.pci_io;
244 
245  /* Identify memory and I/O BARs */
246  nii->mem_bar = PCI_MAX_BAR;
247  nii->io_bar = PCI_MAX_BAR;
248  for ( bar = ( PCI_MAX_BAR - 1 ) ; bar >= 0 ; bar-- ) {
249  efirc = nii->pci_io->GetBarAttributes ( nii->pci_io, bar, NULL,
250  &desc.resource );
251  if ( efirc == EFI_UNSUPPORTED ) {
252  /* BAR not present; ignore */
253  continue;
254  }
255  if ( efirc != 0 ) {
256  rc = -EEFI ( efirc );
257  DBGC ( nii, "NII %s could not get BAR %d attributes: "
258  "%s\n", nii->dev.name, bar, strerror ( rc ) );
259  goto err_get_bar_attributes;
260  }
261  if ( desc.acpi->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM ) {
262  nii->mem_bar = bar;
263  } else if ( desc.acpi->ResType == ACPI_ADDRESS_SPACE_TYPE_IO ) {
264  nii->io_bar = bar;
265  }
266  bs->FreePool ( desc.resource );
267  }
268  DBGC ( nii, "NII %s has ", nii->dev.name );
269  if ( nii->mem_bar < PCI_MAX_BAR ) {
270  DBGC ( nii, "memory BAR %d and ", nii->mem_bar );
271  } else {
272  DBGC ( nii, "no memory BAR and " );
273  }
274  if ( nii->io_bar < PCI_MAX_BAR ) {
275  DBGC ( nii, "I/O BAR %d\n", nii->io_bar );
276  } else {
277  DBGC ( nii, "no I/O BAR\n" );
278  }
279 
280  return 0;
281 
282  err_get_bar_attributes:
285  err_open:
286  err_locate:
287  return rc;
288 }
289 
290 /**
291  * Close PCI I/O protocol
292  *
293  * @v nii NII NIC
294  * @ret rc Return status code
295  */
296 static void nii_pci_close ( struct nii_nic *nii ) {
298  struct nii_mapping *map;
299  struct nii_mapping *tmp;
300 
301  /* Remove any stale mappings */
303  DBGC ( nii, "NII %s removing stale mapping %#llx\n",
304  nii->dev.name, ( ( unsigned long long ) map->addr ) );
305  nii->pci_io->Unmap ( nii->pci_io, map->mapping );
306  list_del ( &map->list );
307  free ( map );
308  }
309 
310  /* Close protocols */
312  efi_image_handle, nii->efidev->device );
313 }
314 
315 /**
316  * I/O callback
317  *
318  * @v unique_id NII NIC
319  * @v op Operations
320  * @v len Length of data
321  * @v addr Address
322  * @v data Data buffer
323  */
324 static EFIAPI VOID nii_io ( UINT64 unique_id, UINT8 op, UINT8 len, UINT64 addr,
325  UINT64 data ) {
326  struct nii_nic *nii = ( ( void * ) ( intptr_t ) unique_id );
330  unsigned int bar;
331  EFI_STATUS efirc;
332  int rc;
333 
334  /* Determine accessor and BAR */
335  if ( op & ( PXE_MEM_READ | PXE_MEM_WRITE ) ) {
336  access = &nii->pci_io->Mem;
337  bar = nii->mem_bar;
338  } else {
339  access = &nii->pci_io->Io;
340  bar = nii->io_bar;
341  }
342 
343  /* Determine operaton */
344  io = ( ( op & ( PXE_IO_WRITE | PXE_MEM_WRITE ) ) ?
345  access->Write : access->Read );
346 
347  /* Determine width */
348  width = ( fls ( len ) - 1 );
349 
350  /* Issue operation */
351  if ( ( efirc = io ( nii->pci_io, width, bar, addr, 1,
352  ( ( void * ) ( intptr_t ) data ) ) ) != 0 ) {
353  rc = -EEFI ( efirc );
354  DBGC ( nii, "NII %s I/O operation %#x failed: %s\n",
355  nii->dev.name, op, strerror ( rc ) );
356  /* No way to report failure */
357  return;
358  }
359 }
360 
361 /**
362  * Map callback
363  *
364  * @v unique_id NII NIC
365  * @v addr Address of memory to be mapped
366  * @v len Length of memory to be mapped
367  * @v dir Direction of data flow
368  * @v mapped Device mapped address to fill in
369  */
370 static EFIAPI VOID nii_map ( UINT64 unique_id, UINT64 addr, UINT32 len,
371  UINT32 dir, UINT64 mapped ) {
372  struct nii_nic *nii = ( ( void * ) ( intptr_t ) unique_id );
373  EFI_PHYSICAL_ADDRESS *phys = ( ( void * ) ( intptr_t ) mapped );
375  struct nii_mapping *map;
376  UINTN count = len;
377  EFI_STATUS efirc;
378  int rc;
379 
380  /* Return a zero mapped address on failure */
381  *phys = 0;
382 
383  /* Determine PCI mapping operation */
384  switch ( dir ) {
385  case TO_AND_FROM_DEVICE:
387  break;
388  case FROM_DEVICE:
390  break;
391  case TO_DEVICE:
393  break;
394  default:
395  DBGC ( nii, "NII %s unsupported mapping direction %d\n",
396  nii->dev.name, dir );
397  goto err_dir;
398  }
399 
400  /* Allocate a mapping record */
401  map = zalloc ( sizeof ( *map ) );
402  if ( ! map )
403  goto err_alloc;
404  map->addr = addr;
405 
406  /* Create map */
407  if ( ( efirc = nii->pci_io->Map ( nii->pci_io, op,
408  ( ( void * ) ( intptr_t ) addr ),
409  &count, phys, &map->mapping ) ) != 0){
410  rc = -EEFI ( efirc );
411  DBGC ( nii, "NII %s map operation failed: %s\n",
412  nii->dev.name, strerror ( rc ) );
413  goto err_map;
414  }
415 
416  /* Add to list of mappings */
417  list_add ( &map->list, &nii->mappings );
418  DBGC2 ( nii, "NII %s mapped %#llx+%#x->%#llx\n",
419  nii->dev.name, ( ( unsigned long long ) addr ),
420  len, ( ( unsigned long long ) *phys ) );
421  return;
422 
423  list_del ( &map->list );
424  err_map:
425  free ( map );
426  err_alloc:
427  err_dir:
428  return;
429 }
430 
431 /**
432  * Unmap callback
433  *
434  * @v unique_id NII NIC
435  * @v addr Address of mapped memory
436  * @v len Length of mapped memory
437  * @v dir Direction of data flow
438  * @v mapped Device mapped address
439  */
441  UINT32 dir __unused, UINT64 mapped ) {
442  struct nii_nic *nii = ( ( void * ) ( intptr_t ) unique_id );
443  struct nii_mapping *map;
444 
445  /* Locate mapping record */
446  list_for_each_entry ( map, &nii->mappings, list ) {
447  if ( map->addr == addr ) {
448  nii->pci_io->Unmap ( nii->pci_io, map->mapping );
449  list_del ( &map->list );
450  free ( map );
451  DBGC2 ( nii, "NII %s unmapped %#llx+%#x->%#llx\n",
452  nii->dev.name, ( ( unsigned long long ) addr ),
453  len, ( ( unsigned long long ) mapped ) );
454  return;
455  }
456  }
457 
458  DBGC ( nii, "NII %s non-existent mapping %#llx+%#x->%#llx\n",
459  nii->dev.name, ( ( unsigned long long ) addr ),
460  len, ( ( unsigned long long ) mapped ) );
461 }
462 
463 /**
464  * Sync callback
465  *
466  * @v unique_id NII NIC
467  * @v addr Address of mapped memory
468  * @v len Length of mapped memory
469  * @v dir Direction of data flow
470  * @v mapped Device mapped address
471  */
473  UINT32 len, UINT32 dir, UINT64 mapped ) {
474  const void *src;
475  void *dst;
476 
477  /* Do nothing if this is an identity mapping */
478  if ( addr == mapped )
479  return;
480 
481  /* Determine direction */
482  if ( dir == FROM_DEVICE ) {
483  src = ( ( void * ) ( intptr_t ) mapped );
484  dst = ( ( void * ) ( intptr_t ) addr );
485  } else {
486  src = ( ( void * ) ( intptr_t ) addr );
487  dst = ( ( void * ) ( intptr_t ) mapped );
488  }
489 
490  /* Copy data */
491  memcpy ( dst, src, len );
492 }
493 
494 /**
495  * Delay callback
496  *
497  * @v unique_id NII NIC
498  * @v microseconds Delay in microseconds
499  */
500 static EFIAPI VOID nii_delay ( UINT64 unique_id __unused, UINTN microseconds ) {
501 
502  udelay ( microseconds );
503 }
504 
505 /**
506  * Block callback
507  *
508  * @v unique_id NII NIC
509  * @v acquire Acquire lock
510  */
511 static EFIAPI VOID nii_block ( UINT64 unique_id, UINT32 acquire ) {
512  struct nii_nic *nii = ( ( void * ) ( intptr_t ) unique_id );
514 
515  /* This functionality (which is copied verbatim from the
516  * SnpDxe implementation of this function) appears to be
517  * totally brain-dead, since it produces no actual blocking
518  * behaviour.
519  */
520  if ( acquire ) {
521  nii->saved_tpl = bs->RaiseTPL ( TPL_NOTIFY );
522  } else {
523  bs->RestoreTPL ( nii->saved_tpl );
524  }
525 }
526 
527 /**
528  * Construct operation from opcode and flags
529  *
530  * @v opcode Opcode
531  * @v opflags Flags
532  * @ret op Operation
533  */
534 #define NII_OP( opcode, opflags ) ( (opcode) | ( (opflags) << 16 ) )
535 
536 /**
537  * Extract opcode from operation
538  *
539  * @v op Operation
540  * @ret opcode Opcode
541  */
542 #define NII_OPCODE( op ) ( (op) & 0xffff )
543 
544 /**
545  * Extract flags from operation
546  *
547  * @v op Operation
548  * @ret opflags Flags
549  */
550 #define NII_OPFLAGS( op ) ( (op) >> 16 )
551 
552 /**
553  * Issue command with parameter block and data block
554  *
555  * @v nii NII NIC
556  * @v op Operation
557  * @v cpb Command parameter block, or NULL
558  * @v cpb_len Command parameter block length
559  * @v db Data block, or NULL
560  * @v db_len Data block length
561  * @ret stat Status flags, or negative status code
562  */
563 static int nii_issue_cpb_db ( struct nii_nic *nii, unsigned int op, void *cpb,
564  size_t cpb_len, void *db, size_t db_len ) {
566  PXE_CDB cdb;
567  UINTN tpl;
568 
569  /* Prepare command descriptor block */
570  memset ( &cdb, 0, sizeof ( cdb ) );
571  cdb.OpCode = NII_OPCODE ( op );
572  cdb.OpFlags = NII_OPFLAGS ( op );
573  cdb.CPBaddr = ( ( intptr_t ) cpb );
574  cdb.CPBsize = cpb_len;
575  cdb.DBaddr = ( ( intptr_t ) db );
576  cdb.DBsize = db_len;
577  cdb.IFnum = nii->nii->IfNum;
578 
579  /* Raise task priority level */
580  tpl = bs->RaiseTPL ( efi_internal_tpl );
581 
582  /* Issue command */
583  DBGC2 ( nii, "NII %s issuing %02x:%04x ifnum %d%s%s\n",
584  nii->dev.name, cdb.OpCode, cdb.OpFlags, cdb.IFnum,
585  ( cpb ? " cpb" : "" ), ( db ? " db" : "" ) );
586  if ( cpb )
587  DBGC2_HD ( nii, cpb, cpb_len );
588  if ( db )
589  DBGC2_HD ( nii, db, db_len );
590  nii->issue ( ( intptr_t ) &cdb );
591 
592  /* Restore task priority level */
593  bs->RestoreTPL ( tpl );
594 
595  /* Check completion status */
596  if ( cdb.StatCode != PXE_STATCODE_SUCCESS )
597  return -cdb.StatCode;
598 
599  /* Return command-specific status flags */
600  return ( cdb.StatFlags & ~PXE_STATFLAGS_STATUS_MASK );
601 }
602 
603 /**
604  * Issue command with parameter block
605  *
606  * @v nii NII NIC
607  * @v op Operation
608  * @v cpb Command parameter block, or NULL
609  * @v cpb_len Command parameter block length
610  * @ret stat Status flags, or negative status code
611  */
612 static int nii_issue_cpb ( struct nii_nic *nii, unsigned int op, void *cpb,
613  size_t cpb_len ) {
614 
615  return nii_issue_cpb_db ( nii, op, cpb, cpb_len, NULL, 0 );
616 }
617 
618 /**
619  * Issue command with data block
620  *
621  * @v nii NII NIC
622  * @v op Operation
623  * @v db Data block, or NULL
624  * @v db_len Data block length
625  * @ret stat Status flags, or negative status code
626  */
627 static int nii_issue_db ( struct nii_nic *nii, unsigned int op, void *db,
628  size_t db_len ) {
629 
630  return nii_issue_cpb_db ( nii, op, NULL, 0, db, db_len );
631 }
632 
633 /**
634  * Issue command
635  *
636  *
637  * @v nii NII NIC
638  * @v op Operation
639  * @ret stat Status flags, or negative status code
640  */
641 static int nii_issue ( struct nii_nic *nii, unsigned int op ) {
642 
643  return nii_issue_cpb_db ( nii, op, NULL, 0, NULL, 0 );
644 }
645 
646 /**
647  * Start UNDI
648  *
649  * @v nii NII NIC
650  * @ret rc Return status code
651  */
652 static int nii_start_undi ( struct nii_nic *nii ) {
653  PXE_CPB_START_31 cpb;
654  int stat;
655  int rc;
656 
657  /* Construct parameter block */
658  memset ( &cpb, 0, sizeof ( cpb ) );
659  cpb.Delay = ( ( intptr_t ) nii_delay );
660  cpb.Block = ( ( intptr_t ) nii_block );
661  cpb.Mem_IO = ( ( intptr_t ) nii_io );
662  cpb.Map_Mem = ( ( intptr_t ) nii_map );
663  cpb.UnMap_Mem = ( ( intptr_t ) nii_unmap );
664  cpb.Sync_Mem = ( ( intptr_t ) nii_sync );
665  cpb.Unique_ID = ( ( intptr_t ) nii );
666 
667  /* Issue command */
668  if ( ( stat = nii_issue_cpb ( nii, PXE_OPCODE_START, &cpb,
669  sizeof ( cpb ) ) ) < 0 ) {
670  rc = -EIO_STAT ( stat );
671  DBGC ( nii, "NII %s could not start: %s\n",
672  nii->dev.name, strerror ( rc ) );
673  return rc;
674  }
675 
676  return 0;
677 }
678 
679 /**
680  * Stop UNDI
681  *
682  * @v nii NII NIC
683  */
684 static void nii_stop_undi ( struct nii_nic *nii ) {
685  int stat;
686  int rc;
687 
688  /* Issue command */
689  if ( ( stat = nii_issue ( nii, PXE_OPCODE_STOP ) ) < 0 ) {
690  rc = -EIO_STAT ( stat );
691  DBGC ( nii, "NII %s could not stop: %s\n",
692  nii->dev.name, strerror ( rc ) );
693  /* Nothing we can do about it */
694  return;
695  }
696 }
697 
698 /**
699  * Get initialisation information
700  *
701  * @v nii NII NIC
702  * @v netdev Network device to fill in
703  * @ret rc Return status code
704  */
705 static int nii_get_init_info ( struct nii_nic *nii,
706  struct net_device *netdev ) {
708  int stat;
709  int rc;
710 
711  /* Issue command */
712  if ( ( stat = nii_issue_db ( nii, PXE_OPCODE_GET_INIT_INFO, &db,
713  sizeof ( db ) ) ) < 0 ) {
714  rc = -EIO_STAT ( stat );
715  DBGC ( nii, "NII %s could not get initialisation info: %s\n",
716  nii->dev.name, strerror ( rc ) );
717  return rc;
718  }
719 
720  /* Determine link layer protocol */
721  switch ( db.IFtype ) {
722  case PXE_IFTYPE_ETHERNET :
723  netdev->ll_protocol = &ethernet_protocol;
724  break;
725  default:
726  DBGC ( nii, "NII %s unknown interface type %#02x\n",
727  nii->dev.name, db.IFtype );
728  return -ENOTSUP;
729  }
730 
731  /* Sanity checks */
732  assert ( db.MediaHeaderLen == netdev->ll_protocol->ll_header_len );
733  assert ( db.HWaddrLen == netdev->ll_protocol->hw_addr_len );
734  assert ( db.HWaddrLen == netdev->ll_protocol->ll_addr_len );
735 
736  /* Extract parameters */
737  nii->buffer_len = db.MemoryRequired;
738  nii->mtu = ( db.FrameDataLen + db.MediaHeaderLen );
739  netdev->max_pkt_len = nii->mtu;
741 
742  return 0;
743 }
744 
745 /**
746  * Initialise UNDI
747  *
748  * @v nii NII NIC
749  * @v flags Flags
750  * @ret rc Return status code
751  */
752 static int nii_initialise_flags ( struct nii_nic *nii, unsigned int flags ) {
753  PXE_CPB_INITIALIZE cpb;
755  unsigned int op;
756  int stat;
757  int rc;
758 
759  /* Allocate memory buffer */
760  nii->buffer = umalloc ( nii->buffer_len );
761  if ( ! nii->buffer ) {
762  rc = -ENOMEM;
763  goto err_alloc;
764  }
765 
766  /* Construct parameter block */
767  memset ( &cpb, 0, sizeof ( cpb ) );
768  cpb.MemoryAddr = ( ( intptr_t ) nii->buffer );
769  cpb.MemoryLength = nii->buffer_len;
770 
771  /* Construct data block */
772  memset ( &db, 0, sizeof ( db ) );
773 
774  /* Issue command */
776  if ( ( stat = nii_issue_cpb_db ( nii, op, &cpb, sizeof ( cpb ),
777  &db, sizeof ( db ) ) ) < 0 ) {
778  rc = -EIO_STAT ( stat );
779  DBGC ( nii, "NII %s could not initialise: %s\n",
780  nii->dev.name, strerror ( rc ) );
781  goto err_initialize;
782  }
783 
784  return 0;
785 
786  err_initialize:
787  ufree ( nii->buffer );
788  err_alloc:
789  return rc;
790 }
791 
792 /**
793  * Initialise UNDI with cable detection
794  *
795  * @v nii NII NIC
796  * @ret rc Return status code
797  */
798 static int nii_initialise_cable ( struct nii_nic *nii ) {
799  unsigned int flags;
800 
801  /* Initialise UNDI */
803  return nii_initialise_flags ( nii, flags );
804 }
805 
806 /**
807  * Initialise UNDI
808  *
809  * @v nii NII NIC
810  * @ret rc Return status code
811  */
812 static int nii_initialise ( struct nii_nic *nii ) {
813  unsigned int flags;
814 
815  /* Initialise UNDI */
817  return nii_initialise_flags ( nii, flags );
818 }
819 
820 /**
821  * Shut down UNDI
822  *
823  * @v nii NII NIC
824  */
825 static void nii_shutdown ( struct nii_nic *nii ) {
826  int stat;
827  int rc;
828 
829  /* Issue command */
830  if ( ( stat = nii_issue ( nii, PXE_OPCODE_SHUTDOWN ) ) < 0 ) {
831  rc = -EIO_STAT ( stat );
832  DBGC ( nii, "NII %s could not shut down: %s\n",
833  nii->dev.name, strerror ( rc ) );
834  /* Leak memory to avoid corruption */
835  return;
836  }
837 
838  /* Free buffer */
839  ufree ( nii->buffer );
840 }
841 
842 /**
843  * Get station addresses
844  *
845  * @v nii NII NIC
846  * @v netdev Network device to fill in
847  * @ret rc Return status code
848  */
849 static int nii_get_station_address ( struct nii_nic *nii,
850  struct net_device *netdev ) {
852  unsigned int op;
853  int stat;
854  int rc;
855 
856  /* Initialise UNDI */
857  if ( ( rc = nii_initialise ( nii ) ) != 0 )
858  goto err_initialise;
859 
860  /* Issue command */
863  if ( ( stat = nii_issue_db ( nii, op, &db, sizeof ( db ) ) ) < 0 ) {
864  rc = -EIO_STAT ( stat );
865  DBGC ( nii, "NII %s could not get station address: %s\n",
866  nii->dev.name, strerror ( rc ) );
867  goto err_station_address;
868  }
869 
870  /* Copy MAC addresses */
871  memcpy ( netdev->ll_addr, db.StationAddr,
873  memcpy ( netdev->hw_addr, db.PermanentAddr,
875  memcpy ( nii->broadcast, db.BroadcastAddr,
876  sizeof ( nii->broadcast ) );
877 
878  err_station_address:
879  nii_shutdown ( nii );
880  err_initialise:
881  return rc;
882 }
883 
884 /**
885  * Set station address
886  *
887  * @v nii NII NIC
888  * @v netdev Network device
889  * @ret rc Return status code
890  */
891 static int nii_set_station_address ( struct nii_nic *nii,
892  struct net_device *netdev ) {
893  uint32_t implementation = nii->undi->Implementation;
895  unsigned int op;
896  int stat;
897  int rc;
898 
899  /* Fail if setting station address is unsupported */
901  return -ENOTSUP;
902 
903  /* Construct parameter block */
904  memset ( &cpb, 0, sizeof ( cpb ) );
907 
908  /* Issue command */
911  if ( ( stat = nii_issue_cpb ( nii, op, &cpb, sizeof ( cpb ) ) ) < 0 ) {
912  rc = -EIO_STAT ( stat );
913  DBGC ( nii, "NII %s could not set station address: %s\n",
914  nii->dev.name, strerror ( rc ) );
915  return rc;
916  }
917 
918  return 0;
919 }
920 
921 /**
922  * Set receive filters
923  *
924  * @v nii NII NIC
925  * @v flags Flags
926  * @ret rc Return status code
927  */
928 static int nii_set_rx_filters ( struct nii_nic *nii, unsigned int flags ) {
929  uint32_t implementation = nii->undi->Implementation;
930  unsigned int op;
931  int stat;
932  int rc;
933 
934  /* Construct receive filter set */
942 
943  /* Issue command */
945  if ( ( stat = nii_issue ( nii, op ) ) < 0 ) {
946  rc = -EIO_STAT ( stat );
947  DBGC ( nii, "NII %s could not %s%sable receive filters "
948  "%#04x: %s\n", nii->dev.name,
950  "en" : "" ),
952  "dis" : "" ), flags, strerror ( rc ) );
953  return rc;
954  }
955 
956  return 0;
957 }
958 
959 /**
960  * Enable receive filters
961  *
962  * @v nii NII NIC
963  * @ret rc Return status code
964  */
965 static int nii_enable_rx_filters ( struct nii_nic *nii ) {
966 
968 }
969 
970 /**
971  * Disable receive filters
972  *
973  * @v nii NII NIC
974  * @ret rc Return status code
975  */
976 static int nii_disable_rx_filters ( struct nii_nic *nii ) {
977 
979 }
980 
981 /**
982  * Transmit packet
983  *
984  * @v netdev Network device
985  * @v iobuf I/O buffer
986  * @ret rc Return status code
987  */
988 static int nii_transmit ( struct net_device *netdev,
989  struct io_buffer *iobuf ) {
990  struct nii_nic *nii = netdev->priv;
991  PXE_CPB_TRANSMIT cpb;
992  unsigned int op;
993  int stat;
994  int rc;
995 
996  /* Defer the packet if there is already a transmission in progress */
997  if ( nii->txbuf ) {
998  netdev_tx_defer ( netdev, iobuf );
999  return 0;
1000  }
1001 
1002  /* Pad to minimum Ethernet length, to work around underlying
1003  * drivers that do not correctly handle frame padding
1004  * themselves.
1005  */
1006  iob_pad ( iobuf, ETH_ZLEN );
1007 
1008  /* Construct parameter block */
1009  memset ( &cpb, 0, sizeof ( cpb ) );
1010  cpb.FrameAddr = ( ( intptr_t ) iobuf->data );
1011  cpb.DataLen = iob_len ( iobuf );
1012 
1013  /* Transmit packet */
1017  if ( ( stat = nii_issue_cpb ( nii, op, &cpb, sizeof ( cpb ) ) ) < 0 ) {
1018  rc = -EIO_STAT ( stat );
1019  DBGC ( nii, "NII %s could not transmit: %s\n",
1020  nii->dev.name, strerror ( rc ) );
1021  return rc;
1022  }
1023  nii->txbuf = iobuf;
1024 
1025  return 0;
1026 }
1027 
1028 /**
1029  * Poll for completed packets
1030  *
1031  * @v netdev Network device
1032  * @v stat Status flags
1033  */
1034 static void nii_poll_tx ( struct net_device *netdev, unsigned int stat ) {
1035  struct nii_nic *nii = netdev->priv;
1036  struct io_buffer *iobuf;
1037 
1038  /* Do nothing unless we have a completion */
1040  return;
1041 
1042  /* Ignore spurious completions reported by some devices */
1043  if ( ! nii->txbuf )
1044  return;
1045 
1046  /* Complete transmission */
1047  iobuf = nii->txbuf;
1048  nii->txbuf = NULL;
1049  netdev_tx_complete ( netdev, iobuf );
1050 }
1051 
1052 /**
1053  * Poll for received packets
1054  *
1055  * @v netdev Network device
1056  */
1057 static void nii_poll_rx ( struct net_device *netdev ) {
1058  struct nii_nic *nii = netdev->priv;
1059  PXE_CPB_RECEIVE cpb;
1061  unsigned int quota;
1062  int stat;
1063  int rc;
1064 
1065  /* Retrieve up to NII_RX_QUOTA packets */
1066  for ( quota = NII_RX_QUOTA ; quota ; quota-- ) {
1067 
1068  /* Allocate buffer, if required */
1069  if ( ! nii->rxbuf ) {
1070  nii->rxbuf = alloc_iob ( nii->mtu );
1071  if ( ! nii->rxbuf ) {
1072  /* Leave for next poll */
1073  break;
1074  }
1075  }
1076 
1077  /* Construct parameter block */
1078  memset ( &cpb, 0, sizeof ( cpb ) );
1079  cpb.BufferAddr = ( ( intptr_t ) nii->rxbuf->data );
1080  cpb.BufferLen = iob_tailroom ( nii->rxbuf );
1081 
1082  /* Issue command */
1083  if ( ( stat = nii_issue_cpb_db ( nii, PXE_OPCODE_RECEIVE,
1084  &cpb, sizeof ( cpb ),
1085  &db, sizeof ( db ) ) ) < 0 ) {
1086 
1087  /* PXE_STATCODE_NO_DATA is just the usual "no packet"
1088  * status indicator; ignore it.
1089  */
1090  if ( stat == -PXE_STATCODE_NO_DATA )
1091  break;
1092 
1093  /* Anything else is an error */
1094  rc = -EIO_STAT ( stat );
1095  DBGC ( nii, "NII %s could not receive: %s\n",
1096  nii->dev.name, strerror ( rc ) );
1097  netdev_rx_err ( netdev, NULL, rc );
1098  break;
1099  }
1100 
1101  /* Hand off to network stack */
1102  iob_put ( nii->rxbuf, db.FrameLen );
1103  netdev_rx ( netdev, nii->rxbuf );
1104  nii->rxbuf = NULL;
1105  }
1106 }
1107 
1108 /**
1109  * Check for link state changes
1110  *
1111  * @v netdev Network device
1112  * @v stat Status flags
1113  */
1114 static void nii_poll_link ( struct net_device *netdev, unsigned int stat ) {
1115  int no_media = ( stat & PXE_STATFLAGS_GET_STATUS_NO_MEDIA );
1116 
1117  if ( no_media && netdev_link_ok ( netdev ) ) {
1119  } else if ( ( ! no_media ) && ( ! netdev_link_ok ( netdev ) ) ) {
1120  netdev_link_up ( netdev );
1121  }
1122 }
1123 
1124 /**
1125  * Poll for completed packets
1126  *
1127  * @v netdev Network device
1128  */
1129 static void nii_poll ( struct net_device *netdev ) {
1130  struct nii_nic *nii = netdev->priv;
1132  unsigned int op;
1133  int stat;
1134  int rc;
1135 
1136  /* Construct data block */
1137  memset ( &db, 0, sizeof ( db ) );
1138 
1139  /* Get status */
1143  ( nii->media ? PXE_OPFLAGS_GET_MEDIA_STATUS : 0 ) ) );
1144  if ( ( stat = nii_issue_db ( nii, op, &db, sizeof ( db ) ) ) < 0 ) {
1145  rc = -EIO_STAT ( stat );
1146  DBGC ( nii, "NII %s could not get status: %s\n",
1147  nii->dev.name, strerror ( rc ) );
1148  return;
1149  }
1150 
1151  /* Process any TX completions */
1152  nii_poll_tx ( netdev, stat );
1153 
1154  /* Process any RX completions */
1155  nii_poll_rx ( netdev );
1156 
1157  /* Check for link state changes */
1158  if ( nii->media )
1159  nii_poll_link ( netdev, stat );
1160 }
1161 
1162 /**
1163  * Open network device
1164  *
1165  * @v netdev Network device
1166  * @ret rc Return status code
1167  */
1168 static int nii_open ( struct net_device *netdev ) {
1169  struct nii_nic *nii = netdev->priv;
1170  int rc;
1171 
1172  /* Initialise NIC
1173  *
1174  * We don't care about link state here, and would prefer to
1175  * have the NIC initialise even if no cable is present, to
1176  * match the behaviour of all other iPXE drivers.
1177  *
1178  * Some Emulex NII drivers have a bug which prevents packets
1179  * from being sent or received unless we specifically ask it
1180  * to detect cable presence during initialisation.
1181  *
1182  * Unfortunately, some other NII drivers (e.g. Mellanox) may
1183  * time out and report failure if asked to detect cable
1184  * presence during initialisation on links that are physically
1185  * slow to reach link-up.
1186  *
1187  * Attempt to work around both of these problems by first
1188  * attempting to initialise with cable presence detection,
1189  * then falling back to initialising without cable presence
1190  * detection.
1191  */
1192  if ( ( rc = nii_initialise_cable ( nii ) ) != 0 ) {
1193  DBGC ( nii, "NII %s could not initialise with cable "
1194  "detection: %s\n", nii->dev.name, strerror ( rc ) );
1195  if ( ( rc = nii_initialise ( nii ) ) != 0 ) {
1196  DBGC ( nii, "NII %s could not initialise without "
1197  "cable detection: %s\n",
1198  nii->dev.name, strerror ( rc ) );
1199  goto err_initialise;
1200  }
1201  }
1202 
1203  /* Attempt to set station address */
1204  if ( ( rc = nii_set_station_address ( nii, netdev ) ) != 0 ) {
1205  DBGC ( nii, "NII %s could not set station address: %s\n",
1206  nii->dev.name, strerror ( rc ) );
1207  /* Treat as non-fatal */
1208  }
1209 
1210  /* Disable receive filters
1211  *
1212  * We have no reason to disable receive filters here (or
1213  * anywhere), but some NII drivers have a bug which prevents
1214  * packets from being received unless we attempt to disable
1215  * the receive filters.
1216  *
1217  * Ignore any failures, since we genuinely don't care if the
1218  * NII driver cannot disable the filters.
1219  */
1221 
1222  /* Enable receive filters */
1223  if ( ( rc = nii_enable_rx_filters ( nii ) ) != 0 )
1224  goto err_enable_rx_filters;
1225 
1226  return 0;
1227 
1228  err_enable_rx_filters:
1229  nii_shutdown ( nii );
1230  err_initialise:
1231  return rc;
1232 }
1233 
1234 /**
1235  * Close network device
1236  *
1237  * @v netdev Network device
1238  */
1239 static void nii_close ( struct net_device *netdev ) {
1240  struct nii_nic *nii = netdev->priv;
1241 
1242  /* Shut down NIC */
1243  nii_shutdown ( nii );
1244 
1245  /* Discard transmit buffer, if applicable */
1246  if ( nii->txbuf ) {
1248  nii->txbuf = NULL;
1249  }
1250 
1251  /* Discard receive buffer, if applicable */
1252  if ( nii->rxbuf ) {
1253  free_iob ( nii->rxbuf );
1254  nii->rxbuf = NULL;
1255  }
1256 }
1257 
1258 /** NII network device operations */
1260  .open = nii_open,
1261  .close = nii_close,
1262  .transmit = nii_transmit,
1263  .poll = nii_poll,
1264 };
1265 
1266 /**
1267  * Attach driver to device
1268  *
1269  * @v efidev EFI device
1270  * @ret rc Return status code
1271  */
1272 int nii_start ( struct efi_device *efidev ) {
1274  EFI_HANDLE device = efidev->device;
1275  struct net_device *netdev;
1276  struct nii_nic *nii;
1277  void *interface;
1278  EFI_STATUS efirc;
1279  int rc;
1280 
1281  /* Allocate and initialise structure */
1282  netdev = alloc_netdev ( sizeof ( *nii ) );
1283  if ( ! netdev ) {
1284  rc = -ENOMEM;
1285  goto err_alloc;
1286  }
1288  nii = netdev->priv;
1289  nii->efidev = efidev;
1290  INIT_LIST_HEAD ( &nii->mappings );
1291  netdev->ll_broadcast = nii->broadcast;
1293 
1294  /* Populate underlying device information */
1295  efi_device_info ( device, "NII", &nii->dev );
1296  nii->dev.driver_name = "NII";
1297  nii->dev.parent = &efidev->dev;
1298  list_add ( &nii->dev.siblings, &efidev->dev.children );
1299  INIT_LIST_HEAD ( &nii->dev.children );
1300  netdev->dev = &nii->dev;
1301 
1302  /* Open NII protocol */
1303  if ( ( efirc = bs->OpenProtocol ( device, &efi_nii31_protocol_guid,
1307  rc = -EEFI ( efirc );
1308  DBGC ( nii, "NII %s cannot open NII protocol: %s\n",
1309  nii->dev.name, strerror ( rc ) );
1311  goto err_open_protocol;
1312  }
1313  nii->nii = interface;
1314 
1315  /* Locate UNDI and entry point */
1316  nii->undi = ( ( void * ) ( intptr_t ) nii->nii->Id );
1317  if ( ! nii->undi ) {
1318  DBGC ( nii, "NII %s has no UNDI\n", nii->dev.name );
1319  rc = -ENODEV;
1320  goto err_no_undi;
1321  }
1322  if ( nii->undi->Implementation & PXE_ROMID_IMP_HW_UNDI ) {
1323  DBGC ( nii, "NII %s is a mythical hardware UNDI\n",
1324  nii->dev.name );
1325  rc = -ENOTSUP;
1326  goto err_hw_undi;
1327  }
1328  if ( nii->undi->Implementation & PXE_ROMID_IMP_SW_VIRT_ADDR ) {
1329  nii->issue = ( ( void * ) ( intptr_t ) nii->undi->EntryPoint );
1330  } else {
1331  nii->issue = ( ( ( void * ) nii->undi ) +
1332  nii->undi->EntryPoint );
1333  }
1334  DBGC ( nii, "NII %s using UNDI v%x.%x at %p entry %p impl %#08x\n",
1335  nii->dev.name, nii->nii->MajorVer, nii->nii->MinorVer,
1336  nii->undi, nii->issue, nii->undi->Implementation );
1337 
1338  /* Open PCI I/O protocols and locate BARs */
1339  if ( ( rc = nii_pci_open ( nii ) ) != 0 )
1340  goto err_pci_open;
1341 
1342  /* Start UNDI */
1343  if ( ( rc = nii_start_undi ( nii ) ) != 0 )
1344  goto err_start_undi;
1345 
1346  /* Get initialisation information */
1347  if ( ( rc = nii_get_init_info ( nii, netdev ) ) != 0 )
1348  goto err_get_init_info;
1349 
1350  /* Get MAC addresses */
1351  if ( ( rc = nii_get_station_address ( nii, netdev ) ) != 0 )
1352  goto err_get_station_address;
1353 
1354  /* Register network device */
1355  if ( ( rc = register_netdev ( netdev ) ) != 0 )
1356  goto err_register_netdev;
1357  DBGC ( nii, "NII %s registered as %s for %s\n", nii->dev.name,
1359 
1360  /* Set initial link state (if media detection is not supported) */
1361  if ( ! nii->media )
1362  netdev_link_up ( netdev );
1363 
1364  return 0;
1365 
1367  err_register_netdev:
1368  err_get_station_address:
1369  err_get_init_info:
1370  nii_stop_undi ( nii );
1371  err_start_undi:
1372  nii_pci_close ( nii );
1373  err_pci_open:
1374  err_hw_undi:
1375  err_no_undi:
1378  err_open_protocol:
1379  list_del ( &nii->dev.siblings );
1380  netdev_nullify ( netdev );
1381  netdev_put ( netdev );
1382  err_alloc:
1383  return rc;
1384 }
1385 
1386 /**
1387  * Detach driver from device
1388  *
1389  * @v efidev EFI device
1390  */
1391 void nii_stop ( struct efi_device *efidev ) {
1393  struct net_device *netdev = efidev_get_drvdata ( efidev );
1394  struct nii_nic *nii = netdev->priv;
1396 
1397  /* Unregister network device */
1399 
1400  /* Stop UNDI */
1401  nii_stop_undi ( nii );
1402 
1403  /* Close PCI I/O protocols */
1404  nii_pci_close ( nii );
1405 
1406  /* Close NII protocol */
1409 
1410  /* Free network device */
1411  list_del ( &nii->dev.siblings );
1412  netdev_nullify ( netdev );
1413  netdev_put ( netdev );
1414 }
EFI_GUID efi_nii31_protocol_guid
Network interface identifier protocol GUID (new version)
Definition: efi_guid.c:279
static int nii_disable_rx_filters(struct nii_nic *nii)
Disable receive filters.
Definition: nii.c:976
NII driver.
EFI_TPL saved_tpl
Saved task priority level.
Definition: nii.c:185
#define NII_OPFLAGS(op)
Extract flags from operation.
Definition: nii.c:550
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2081
#define EFI_UNSUPPORTED
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:117
static const void * src
Definition: string.h:47
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:1114
static void netdev_tx_complete(struct net_device *netdev, struct io_buffer *iobuf)
Complete network transmission.
Definition: netdevice.h:752
#define iob_put(iobuf, len)
Definition: iobuf.h:120
UINT64 addr
Mapped address.
Definition: nii.c:147
PXE_UINT32 BufferLen
Length of receive buffer.
Definition: UefiPxe.h:1737
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:586
#define PXE_OPCODE_SHUTDOWN
Change the UNDI operational state from Initialized to Started.
Definition: UefiPxe.h:122
void netdev_tx_defer(struct net_device *netdev, struct io_buffer *iobuf)
Defer transmitted packet.
Definition: netdevice.c:412
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:171
static void nii_poll(struct net_device *netdev)
Poll for completed packets.
Definition: nii.c:1129
EFI_RAISE_TPL RaiseTPL
Definition: UefiSpec.h:1926
EFI_HANDLE pci_device
PCI device.
Definition: nii.c:166
PXE_UINT16 CPBsize
Definition: UefiPxe.h:878
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
EFI driver interface.
int(* open)(struct net_device *netdev)
Open network device.
Definition: netdevice.h:222
PXE_UINT32 MemoryLength
MemoryLength must be greater than or equal to MemoryRequired returned by the Get Init Info command.
Definition: UefiPxe.h:1254
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:69
PXE_UINT16 DBsize
Definition: UefiPxe.h:879
#define PXE_OPFLAGS_RECEIVE_FILTER_DISABLE
Definition: UefiPxe.h:273
Error codes.
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:627
EFI_GUID efi_pci_io_protocol_guid
PCI I/O protocol GUID.
Definition: efi_guid.c:283
int nii_start(struct efi_device *efidev)
Attach driver to device.
Definition: nii.c:1272
static EFIAPI VOID nii_delay(UINT64 unique_id __unused, UINTN microseconds)
Delay callback.
Definition: nii.c:500
An optional protocol that is used to describe details about the software layer that is used to produc...
A read operation from system memory by a bus master.
Definition: PciIo.h:83
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
#define NII_OPCODE(op)
Extract opcode from operation.
Definition: nii.c:542
#define PXE_ROMID_IMP_BROADCAST_RX_SUPPORTED
Definition: UefiPxe.h:868
PXE_UINT32 DataLen
Length of the data portion of the frame buffer in bytes.
Definition: UefiPxe.h:1674
PXE_OPFLAGS OpFlags
Definition: UefiPxe.h:877
EFI_PCI_IO_PROTOCOL_MAP Map
Definition: PciIo.h:525
uint64_t desc
Microcode descriptor list physical address.
Definition: ucode.h:12
#define DBGC(...)
Definition: compiler.h:505
#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:571
char name[40]
Name.
Definition: device.h:75
static int nii_initialise_flags(struct nii_nic *nii, unsigned int flags)
Initialise UNDI.
Definition: nii.c:752
const uint8_t * ll_broadcast
Link-layer broadcast address.
Definition: netdevice.h:389
#define PXE_ROMID_IMP_STATION_ADDR_SETTABLE
Definition: UefiPxe.h:865
unsigned int UINT32
Definition: ProcessorBind.h:98
#define EFI_OPEN_PROTOCOL_BY_DRIVER
Definition: UefiSpec.h:1347
#define FROM_DEVICE
Definition: UefiPxe.h:1083
#define EFI_OPEN_PROTOCOL_EXCLUSIVE
Definition: UefiSpec.h:1348
EFI Network Interface Identifier Protocol.
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
Definition: netdevice.c:230
#define DBGC_EFI_OPENERS(...)
Definition: efi.h:321
#define PXE_OPCODE_INITIALIZE
Changed UNDI operational state from Started to Initialized.
Definition: UefiPxe.h:112
#define EIO_STAT(stat)
Definition: nii.c:126
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:21
PACKED struct @530 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
The common definition of QWORD, DWORD, and WORD Address Space Descriptors.
#define PXE_OPFLAGS_GET_TRANSMITTED_BUFFERS
Return list of transmitted buffers for recycling.
Definition: UefiPxe.h:364
void nii_stop(struct efi_device *efidev)
Detach driver from device.
Definition: nii.c:1391
PXE_MAC_ADDR StationAddr
If supplied and supported, the current station MAC address will be changed.
Definition: UefiPxe.h:1338
userptr_t buffer
Hardware transmit/receive buffer.
Definition: nii.c:180
unsigned long intptr_t
Definition: stdint.h:21
uint32_t implementation
Implementation.
Definition: ena.h:12
#define PXE_OPFLAGS_RECEIVE_FILTER_BROADCAST
Enable broadcast packet receiving.
Definition: UefiPxe.h:292
#define PXE_OPFLAGS_INITIALIZE_DETECT_CABLE
Definition: UefiPxe.h:213
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1987
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:129
EFI_TPL efi_internal_tpl
Internal task priority level.
Definition: efi_init.c:52
static EFIAPI VOID nii_sync(UINT64 unique_id __unused, UINT64 addr, UINT32 len, UINT32 dir, UINT64 mapped)
Sync callback.
Definition: nii.c:472
unsigned char UINT8
UINT64 EFI_PHYSICAL_ADDRESS
64-bit physical memory address.
Definition: UefiBaseType.h:52
ACPI 1.0b definitions from the ACPI Specification, revision 1.0b.
#define TPL_NOTIFY
Definition: UefiSpec.h:639
#define PXE_IFTYPE_ETHERNET
This information is from the ARP section of RFC 1700.
Definition: UefiPxe.h:708
PXE_SW_UNDI * undi
!PXE structure
Definition: nii.c:159
EFI utilities.
#define PXE_OPCODE_STATION_ADDRESS
Read & change station MAC address.
Definition: UefiPxe.h:137
#define ECANCELED
Operation canceled.
Definition: errno.h:343
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
A doubly-linked list entry (or list head)
Definition: list.h:18
UINT64 Id
The address of the first byte of the identifying structure for this network interface.
static void nii_poll_tx(struct net_device *netdev, unsigned int stat)
Poll for completed packets.
Definition: nii.c:1034
static EFIAPI VOID nii_map(UINT64 unique_id, UINT64 addr, UINT32 len, UINT32 dir, UINT64 mapped)
Map callback.
Definition: nii.c:370
#define ACPI_ADDRESS_SPACE_TYPE_MEM
Definition: Acpi10.h:100
static void nii_shutdown(struct nii_nic *nii)
Shut down UNDI.
Definition: nii.c:825
unsigned long tmp
Definition: linux_pci.h:63
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:515
struct net_device * alloc_netdev(size_t priv_len)
Allocate network device.
Definition: netdevice.c:721
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
PXE_UINT64 FrameAddr
Address of first byte of frame buffer.
Definition: UefiPxe.h:1668
PXE_UINT64 MemoryAddr
Address of first (lowest) byte of the memory buffer.
Definition: UefiPxe.h:1248
#define ENOMEM
Not enough space.
Definition: errno.h:534
An NII NIC.
Definition: nii.c:153
A hardware device.
Definition: device.h:73
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static signed char phys[4]
Definition: epic100.c:88
uint32_t userptr_t
A pointer to a user buffer.
Definition: libkir.h:159
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
#define PXE_OPFLAGS_TRANSMIT_WHOLE
Definition: UefiPxe.h:392
#define PXE_OPCODE_TRANSMIT
Transmit packet(s).
Definition: UefiPxe.h:167
UINT64 Mem_IO
PXE_VOID Mem_IO(UINT64 UnqId, UINT8 read_write, UINT8 len, UINT64 port, UINT64 buf_addr);.
Definition: UefiPxe.h:1031
#define PXE_IO_WRITE
Definition: UefiPxe.h:1089
#define PXE_STATFLAGS_STATUS_MASK
Common StatFlags that can be returned by all commands.
Definition: UefiPxe.h:415
static int nii_set_station_address(struct nii_nic *nii, struct net_device *netdev)
Set station address.
Definition: nii.c:891
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:572
Ethernet protocol.
An object interface.
Definition: interface.h:124
uint8_t hw_addr_len
Hardware address length.
Definition: netdevice.h:196
static int nii_open(struct net_device *netdev)
Open network device.
Definition: nii.c:1168
static int nii_set_rx_filters(struct nii_nic *nii, unsigned int flags)
Set receive filters.
Definition: nii.c:928
void * priv
Driver private data.
Definition: netdevice.h:431
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:431
#define PCI_MAX_BAR
Maximum PCI BAR.
Definition: nii.c:140
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:182
static EFI_ACPI_TABLE_PROTOCOL * acpi
ACPI table protocol protocol.
Definition: efi_block.c:65
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:774
void udelay(unsigned long usecs)
Delay for a fixed number of microseconds.
Definition: timer.c:60
EFI_PCI_IO_PROTOCOL * pci_io
PCI I/O protocol.
Definition: nii.c:168
static EFIAPI VOID nii_io(UINT64 unique_id, UINT8 op, UINT8 len, UINT64 addr, UINT64 data)
I/O callback.
Definition: nii.c:324
EFI_PCI_IO_PROTOCOL_GET_BAR_ATTRIBUTES GetBarAttributes
Definition: PciIo.h:532
static int netdev_link_ok(struct net_device *netdev)
Check link state of network device.
Definition: netdevice.h:636
static struct net_device * netdev
Definition: gdbudp.c:52
EFI_PCI_IO_PROTOCOL_WIDTH
Definition: PciIo.h:30
#define PXE_OPFLAGS_GET_INTERRUPT_STATUS
UNDI Get Status.
Definition: UefiPxe.h:354
uint16_t count
Number of entries.
Definition: ena.h:22
#define PXE_OPFLAGS_RECEIVE_FILTER_ENABLE
Definition: UefiPxe.h:272
#define PXE_ROMID_IMP_HW_UNDI
Implementation flags.
Definition: UefiPxe.h:852
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:941
An NII memory mapping.
Definition: nii.c:143
static struct net_device_operations nii_operations
NII network device operations.
Definition: nii.c:1259
#define PXE_ROMID_IMP_SW_VIRT_ADDR
Definition: UefiPxe.h:853
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL
Definition: UefiSpec.h:1344
#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:458
UINT64 Map_Mem
PXE_VOID Map_Mem(UINT64 unq_id, UINT64 virtual_addr, UINT32 size, UINT32 Direction,...
Definition: UefiPxe.h:1048
unsigned int mem_bar
Memory BAR.
Definition: nii.c:170
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:808
PXE_UINT64 CPBaddr
Definition: UefiPxe.h:880
EFI_PCI_IO_PROTOCOL_UNMAP Unmap
Definition: PciIo.h:526
EFI_PCI_IO_PROTOCOL_IO_MEM Write
Write PCI controller registers in the PCI memory or I/O space.
Definition: PciIo.h:199
uint8_t flags
Flags.
Definition: ena.h:18
PXE_UINT64 BufferAddr
Address of first byte of receive buffer.
Definition: UefiPxe.h:1730
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
#define EFIAPI
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
EFI Boot Services Table.
Definition: UefiSpec.h:1917
#define DBGC2_HD(...)
Definition: compiler.h:524
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:34
int media
Media status is supported.
Definition: nii.c:188
#define TO_DEVICE
Definition: UefiPxe.h:1084
#define PXE_OPFLAGS_STATION_ADDRESS_WRITE
Definition: UefiPxe.h:316
A PCI device.
Definition: pci.h:206
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:759
PXE_MAC_ADDR broadcast
Broadcast address.
Definition: nii.c:175
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
static void * efidev_get_drvdata(struct efi_device *efidev)
Get EFI driver-private data.
Definition: efi_driver.h:85
static EFIAPI VOID nii_block(UINT64 unique_id, UINT32 acquire)
Block callback.
Definition: nii.c:511
User memory allocation.
#define PXE_ROMID_IMP_PROMISCUOUS_RX_SUPPORTED
Definition: UefiPxe.h:867
#define PXE_STATFLAGS_GET_STATUS_NO_MEDIA
This flag is set if there is no media detected.
Definition: UefiPxe.h:576
static int nii_initialise_cable(struct nii_nic *nii)
Initialise UNDI with cable detection.
Definition: nii.c:798
A network device.
Definition: netdevice.h:352
struct efi_device * efidev
EFI device.
Definition: nii.c:155
static size_t iob_tailroom(struct io_buffer *iobuf)
Calculate available space at end of an I/O buffer.
Definition: iobuf.h:175
#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:528
#define ACPI_ADDRESS_SPACE_TYPE_IO
Definition: Acpi10.h:101
#define PXE_OPFLAGS_TRANSMIT_DONT_BLOCK
Definition: UefiPxe.h:388
EFIAPI VOID(* issue)(UINT64 cdb)
Entry point.
Definition: nii.c:161
UINT64 UINTN
Unsigned value of native width.
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:563
#define PXE_OPFLAGS_RECEIVE_FILTER_UNICAST
Enable unicast packet receiving.
Definition: UefiPxe.h:286
#define PXE_STATFLAGS_GET_STATUS_NO_MEDIA_SUPPORTED
Definition: UefiPxe.h:443
An EFI device.
Definition: efi_driver.h:17
unsigned int io_bar
I/O BAR.
Definition: nii.c:172
static void nii_close(struct net_device *netdev)
Close network device.
Definition: nii.c:1239
#define PXE_OPCODE_STOP
Change UNDI operational state from Started to Stopped.
Definition: UefiPxe.h:97
#define PXE_OPCODE_GET_STATUS
Get & clear interrupt status.
Definition: UefiPxe.h:157
Provides both read and write access to system memory by both the processor and a bus master.
Definition: PciIo.h:92
#define ETH_ZLEN
Definition: if_ether.h:10
static __always_inline int struct dma_mapping * map
Definition: dma.h:181
int efi_locate_device(EFI_HANDLE device, EFI_GUID *protocol, EFI_HANDLE *parent, unsigned int skip)
Locate parent device supporting a given protocol.
Definition: efi_utils.c:45
static int nii_issue(struct nii_nic *nii, unsigned int op)
Issue command.
Definition: nii.c:641
#define VOID
Undeclared type.
Definition: Base.h:271
struct io_buffer * txbuf
Current transmit buffer.
Definition: nii.c:191
unsigned int uint32_t
Definition: stdint.h:12
unsigned long long UINT64
Definition: ProcessorBind.h:96
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1936
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL * nii
Network interface identifier protocol.
Definition: nii.c:157
EFI_PCI_IO_PROTOCOL_OPERATION
Definition: PciIo.h:79
static int nii_initialise(struct nii_nic *nii)
Initialise UNDI.
Definition: nii.c:812
EFI API.
static int nii_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: nii.c:988
Network device operations.
Definition: netdevice.h:213
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition: netdevice.c:548
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
Network device management.
static int nii_enable_rx_filters(struct nii_nic *nii)
Enable receive filters.
Definition: nii.c:965
static struct dmfe_private * db
Definition: dmfe.c:177
static int nii_get_station_address(struct nii_nic *nii, struct net_device *netdev)
Get station addresses.
Definition: nii.c:849
VOID * mapping
Mapping cookie created by PCI I/O protocol.
Definition: nii.c:149
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
Definition: netdevice.c:470
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
UINTN EFI_TPL
Task priority level.
Definition: UefiBaseType.h:43
#define PXE_STATCODE_NO_DATA
Definition: UefiPxe.h:624
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 DBGC2(...)
Definition: compiler.h:522
UINT64 Delay
PXE_VOID Delay(UINT64 UnqId, UINTN microseconds);.
Definition: UefiPxe.h:990
UINT64 Sync_Mem
PXE_VOID Sync_Mem(UINT64 unq_id, UINT64 virtual, UINT32 size, UINT32 Direction, UINT64 mapped_addr);.
Definition: UefiPxe.h:1071
static int nii_start_undi(struct nii_nic *nii)
Start UNDI.
Definition: nii.c:652
EFI_PCI_IO_PROTOCOL_IO_MEM Read
Read PCI controller registers in the PCI memory or I/O space.
Definition: PciIo.h:195
void * data
Start of data.
Definition: iobuf.h:48
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
u32 addr
Definition: sky2.h:8
struct list_head children
Devices attached to this device.
Definition: device.h:83
struct device dev
Generic device.
Definition: nii.c:163
#define TO_AND_FROM_DEVICE
Definition: UefiPxe.h:1082
EFI driver interface.
struct list_head list
List of mappings.
Definition: nii.c:145
UINT64 Block
PXE_VOID Block(UINT64 unq_id, UINT32 enable);.
Definition: UefiPxe.h:1006
UINT64 Unique_ID
protocol driver can provide anything for this Unique_ID, UNDI remembers that as just a 64bit value as...
Definition: UefiPxe.h:1079
#define PXE_OPFLAGS_RECEIVE_FILTER_ALL_MULTICAST
Enable promiscuous multicast packet receiving.
Definition: UefiPxe.h:310
#define PXE_OPCODE_RECEIVE
Receive packet.
Definition: UefiPxe.h:172
uint8_t data[48]
Additional event data.
Definition: ena.h:22
static void nii_pci_close(struct nii_nic *nii)
Close PCI I/O protocol.
Definition: nii.c:296
static int nii_get_init_info(struct nii_nic *nii, struct net_device *netdev)
Get initialisation information.
Definition: nii.c:705
#define PXE_OPCODE_RECEIVE_FILTERS
Read & change state of packet receive filters.
Definition: UefiPxe.h:132
#define PXE_OPFLAGS_RECEIVE_FILTER_PROMISCUOUS
Enable promiscuous packet receiving.
Definition: UefiPxe.h:304
size_t buffer_len
Hardware transmit/receive buffer length.
Definition: nii.c:182
PXE_UINT8 PXE_MAC_ADDR[PXE_MAC_LENGTH]
Definition: UefiPxe.h:676
static EFIAPI VOID nii_unmap(UINT64 unique_id, UINT64 addr, UINT32 len, UINT32 dir __unused, UINT64 mapped)
Unmap callback.
Definition: nii.c:440
size_t mtu
Maximum packet length.
Definition: nii.c:177
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1986
A write operation from system memory by a bus master.
Definition: PciIo.h:87
static void nii_stop_undi(struct nii_nic *nii)
Stop UNDI.
Definition: nii.c:684
UINT16 IfNum
The network interface number that is being identified by this Network Interface Identifier Protocol.
#define PXE_ROMID_IMP_PROMISCUOUS_MULTICAST_RX_SUPPORTED
Definition: UefiPxe.h:866
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:387
size_t max_pkt_len
Maximum packet length.
Definition: netdevice.h:409
EFI_RESTORE_TPL RestoreTPL
Definition: UefiSpec.h:1927
#define NII_RX_QUOTA
Maximum number of received packets per poll.
Definition: nii.c:200
static void nii_poll_rx(struct net_device *netdev)
Poll for received packets.
Definition: nii.c:1057
#define PXE_OPCODE_GET_INIT_INFO
Get UNDI initialization information.
Definition: UefiPxe.h:102
#define PXE_MEM_READ
Definition: UefiPxe.h:1090
#define PXE_OPFLAGS_STATION_ADDRESS_READ
UNDI Station Address.
Definition: UefiPxe.h:315
#define fls(x)
Find last (i.e.
Definition: strings.h:166
static void efidev_set_drvdata(struct efi_device *efidev, void *priv)
Set EFI driver-private data.
Definition: efi_driver.h:74
The EFI_PCI_IO_PROTOCOL provides the basic Memory, I/O, PCI configuration, and DMA interfaces used to...
Definition: PciIo.h:518
struct device dev
Generic device.
Definition: efi_driver.h:19
#define PXE_MEM_WRITE
Definition: UefiPxe.h:1091
uint32_t len
Length.
Definition: ena.h:14
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:381
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct list_head mappings
Mapping list.
Definition: nii.c:196
PXE_UINT16 IFnum
Definition: UefiPxe.h:884
#define PXE_OPCODE_START
Change UNDI operational state from Stopped to Started.
Definition: UefiPxe.h:92
String functions.
void iob_pad(struct io_buffer *iobuf, size_t min_len)
Pad I/O buffer.
Definition: iobpad.c:49
UINT64 UnMap_Mem
PXE_VOID UnMap_Mem(UINT64 unq_id, UINT64 virtual_addr, UINT32 size, UINT32 Direction,...
Definition: UefiPxe.h:1059
PXE_OPCODE OpCode
Definition: UefiPxe.h:876
#define PXE_OPFLAGS_GET_MEDIA_STATUS
Return current media status.
Definition: UefiPxe.h:369
Definition: efi.h:59
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:372
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:612
void efi_device_info(EFI_HANDLE device, const char *prefix, struct device *dev)
Get underlying device information.
Definition: efi_utils.c:209
#define NII_OP(opcode, opflags)
Construct operation from opcode and flags.
Definition: nii.c:534
String functions.
static int nii_pci_open(struct nii_nic *nii)
Open PCI I/O protocol and identify BARs.
Definition: nii.c:208
PXE_UINT64 DBaddr
Definition: UefiPxe.h:881
#define PXE_STATCODE_SUCCESS
Common StatCodes returned by all UNDI commands, UNDI protocol functions and BC protocol functions.
Definition: UefiPxe.h:604
void * memset(void *dest, int character, size_t len) __nonnull
A persistent I/O buffer.
Definition: iobuf.h:33
struct io_buffer * rxbuf
Current receive buffer.
Definition: nii.c:193
#define PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE
Definition: UefiPxe.h:214