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 */
180  void *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 {
214  void *resource;
215  } desc;
216  int bar;
217  EFI_STATUS efirc;
218  int rc;
219 
220  /* Locate PCI I/O protocol */
222  &pci_device, 0 ) ) != 0 ) {
223  DBGC ( nii, "NII %s could not locate PCI I/O protocol: %s\n",
224  nii->dev.name, strerror ( rc ) );
225  goto err_locate;
226  }
227  nii->pci_device = pci_device;
228 
229  /* Open PCI I/O protocol
230  *
231  * We cannot open this safely as a by-driver open, since doing
232  * so would disconnect the underlying NII driver. We must
233  * therefore use an unsafe open.
234  */
236  &nii->pci_io ) ) != 0 ) {
237  DBGC ( nii, "NII %s could not open PCI I/O protocol: %s\n",
238  nii->dev.name, strerror ( rc ) );
239  goto err_open;
240  }
241 
242  /* Identify memory and I/O BARs */
243  nii->mem_bar = PCI_MAX_BAR;
244  nii->io_bar = PCI_MAX_BAR;
245  for ( bar = ( PCI_MAX_BAR - 1 ) ; bar >= 0 ; bar-- ) {
246  efirc = nii->pci_io->GetBarAttributes ( nii->pci_io, bar, NULL,
247  &desc.resource );
248  if ( efirc == EFI_UNSUPPORTED ) {
249  /* BAR not present; ignore */
250  continue;
251  }
252  if ( efirc != 0 ) {
253  rc = -EEFI ( efirc );
254  DBGC ( nii, "NII %s could not get BAR %d attributes: "
255  "%s\n", nii->dev.name, bar, strerror ( rc ) );
256  goto err_get_bar_attributes;
257  }
258  if ( desc.acpi->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM ) {
259  nii->mem_bar = bar;
260  } else if ( desc.acpi->ResType == ACPI_ADDRESS_SPACE_TYPE_IO ) {
261  nii->io_bar = bar;
262  }
263  bs->FreePool ( desc.resource );
264  }
265  DBGC ( nii, "NII %s has ", nii->dev.name );
266  if ( nii->mem_bar < PCI_MAX_BAR ) {
267  DBGC ( nii, "memory BAR %d and ", nii->mem_bar );
268  } else {
269  DBGC ( nii, "no memory BAR and " );
270  }
271  if ( nii->io_bar < PCI_MAX_BAR ) {
272  DBGC ( nii, "I/O BAR %d\n", nii->io_bar );
273  } else {
274  DBGC ( nii, "no I/O BAR\n" );
275  }
276 
277  return 0;
278 
279  err_get_bar_attributes:
281  err_open:
282  err_locate:
283  return rc;
284 }
285 
286 /**
287  * Close PCI I/O protocol
288  *
289  * @v nii NII NIC
290  * @ret rc Return status code
291  */
292 static void nii_pci_close ( struct nii_nic *nii ) {
293  struct nii_mapping *map;
294  struct nii_mapping *tmp;
295 
296  /* Remove any stale mappings */
298  DBGC ( nii, "NII %s removing stale mapping %#llx\n",
299  nii->dev.name, ( ( unsigned long long ) map->addr ) );
300  nii->pci_io->Unmap ( nii->pci_io, map->mapping );
301  list_del ( &map->list );
302  free ( map );
303  }
304 
305  /* Close protocols */
307 }
308 
309 /**
310  * I/O callback
311  *
312  * @v unique_id NII NIC
313  * @v op Operations
314  * @v len Length of data
315  * @v addr Address
316  * @v data Data buffer
317  */
318 static EFIAPI VOID nii_io ( UINT64 unique_id, UINT8 op, UINT8 len, UINT64 addr,
319  UINT64 data ) {
320  struct nii_nic *nii = ( ( void * ) ( intptr_t ) unique_id );
324  unsigned int bar;
325  EFI_STATUS efirc;
326  int rc;
327 
328  /* Determine accessor and BAR */
329  if ( op & ( PXE_MEM_READ | PXE_MEM_WRITE ) ) {
330  access = &nii->pci_io->Mem;
331  bar = nii->mem_bar;
332  } else {
333  access = &nii->pci_io->Io;
334  bar = nii->io_bar;
335  }
336 
337  /* Determine operaton */
338  io = ( ( op & ( PXE_IO_WRITE | PXE_MEM_WRITE ) ) ?
339  access->Write : access->Read );
340 
341  /* Determine width */
342  width = ( fls ( len ) - 1 );
343 
344  /* Issue operation */
345  if ( ( efirc = io ( nii->pci_io, width, bar, addr, 1,
346  ( ( void * ) ( intptr_t ) data ) ) ) != 0 ) {
347  rc = -EEFI ( efirc );
348  DBGC ( nii, "NII %s I/O operation %#x failed: %s\n",
349  nii->dev.name, op, strerror ( rc ) );
350  /* No way to report failure */
351  return;
352  }
353 }
354 
355 /**
356  * Map callback
357  *
358  * @v unique_id NII NIC
359  * @v addr Address of memory to be mapped
360  * @v len Length of memory to be mapped
361  * @v dir Direction of data flow
362  * @v mapped Device mapped address to fill in
363  */
364 static EFIAPI VOID nii_map ( UINT64 unique_id, UINT64 addr, UINT32 len,
365  UINT32 dir, UINT64 mapped ) {
366  struct nii_nic *nii = ( ( void * ) ( intptr_t ) unique_id );
367  EFI_PHYSICAL_ADDRESS *phys = ( ( void * ) ( intptr_t ) mapped );
369  struct nii_mapping *map;
370  UINTN count = len;
371  EFI_STATUS efirc;
372  int rc;
373 
374  /* Return a zero mapped address on failure */
375  *phys = 0;
376 
377  /* Determine PCI mapping operation */
378  switch ( dir ) {
379  case TO_AND_FROM_DEVICE:
381  break;
382  case FROM_DEVICE:
384  break;
385  case TO_DEVICE:
387  break;
388  default:
389  DBGC ( nii, "NII %s unsupported mapping direction %d\n",
390  nii->dev.name, dir );
391  goto err_dir;
392  }
393 
394  /* Allocate a mapping record */
395  map = zalloc ( sizeof ( *map ) );
396  if ( ! map )
397  goto err_alloc;
398  map->addr = addr;
399 
400  /* Create map */
401  if ( ( efirc = nii->pci_io->Map ( nii->pci_io, op,
402  ( ( void * ) ( intptr_t ) addr ),
403  &count, phys, &map->mapping ) ) != 0){
404  rc = -EEFI ( efirc );
405  DBGC ( nii, "NII %s map operation failed: %s\n",
406  nii->dev.name, strerror ( rc ) );
407  goto err_map;
408  }
409 
410  /* Add to list of mappings */
411  list_add ( &map->list, &nii->mappings );
412  DBGC2 ( nii, "NII %s mapped %#llx+%#x->%#llx\n",
413  nii->dev.name, ( ( unsigned long long ) addr ),
414  len, ( ( unsigned long long ) *phys ) );
415  return;
416 
417  list_del ( &map->list );
418  err_map:
419  free ( map );
420  err_alloc:
421  err_dir:
422  return;
423 }
424 
425 /**
426  * Unmap callback
427  *
428  * @v unique_id NII NIC
429  * @v addr Address of mapped memory
430  * @v len Length of mapped memory
431  * @v dir Direction of data flow
432  * @v mapped Device mapped address
433  */
435  UINT32 dir __unused, UINT64 mapped ) {
436  struct nii_nic *nii = ( ( void * ) ( intptr_t ) unique_id );
437  struct nii_mapping *map;
438 
439  /* Locate mapping record */
440  list_for_each_entry ( map, &nii->mappings, list ) {
441  if ( map->addr == addr ) {
442  nii->pci_io->Unmap ( nii->pci_io, map->mapping );
443  list_del ( &map->list );
444  free ( map );
445  DBGC2 ( nii, "NII %s unmapped %#llx+%#x->%#llx\n",
446  nii->dev.name, ( ( unsigned long long ) addr ),
447  len, ( ( unsigned long long ) mapped ) );
448  return;
449  }
450  }
451 
452  DBGC ( nii, "NII %s non-existent mapping %#llx+%#x->%#llx\n",
453  nii->dev.name, ( ( unsigned long long ) addr ),
454  len, ( ( unsigned long long ) mapped ) );
455 }
456 
457 /**
458  * Sync callback
459  *
460  * @v unique_id NII NIC
461  * @v addr Address of mapped memory
462  * @v len Length of mapped memory
463  * @v dir Direction of data flow
464  * @v mapped Device mapped address
465  */
467  UINT32 len, UINT32 dir, UINT64 mapped ) {
468  const void *src;
469  void *dst;
470 
471  /* Do nothing if this is an identity mapping */
472  if ( addr == mapped )
473  return;
474 
475  /* Determine direction */
476  if ( dir == FROM_DEVICE ) {
477  src = ( ( void * ) ( intptr_t ) mapped );
478  dst = ( ( void * ) ( intptr_t ) addr );
479  } else {
480  src = ( ( void * ) ( intptr_t ) addr );
481  dst = ( ( void * ) ( intptr_t ) mapped );
482  }
483 
484  /* Copy data */
485  memcpy ( dst, src, len );
486 }
487 
488 /**
489  * Delay callback
490  *
491  * @v unique_id NII NIC
492  * @v microseconds Delay in microseconds
493  */
494 static EFIAPI VOID nii_delay ( UINT64 unique_id __unused, UINTN microseconds ) {
495 
496  udelay ( microseconds );
497 }
498 
499 /**
500  * Block callback
501  *
502  * @v unique_id NII NIC
503  * @v acquire Acquire lock
504  */
505 static EFIAPI VOID nii_block ( UINT64 unique_id, UINT32 acquire ) {
506  struct nii_nic *nii = ( ( void * ) ( intptr_t ) unique_id );
508 
509  /* This functionality (which is copied verbatim from the
510  * SnpDxe implementation of this function) appears to be
511  * totally brain-dead, since it produces no actual blocking
512  * behaviour.
513  */
514  if ( acquire ) {
515  nii->saved_tpl = bs->RaiseTPL ( TPL_NOTIFY );
516  } else {
517  bs->RestoreTPL ( nii->saved_tpl );
518  }
519 }
520 
521 /**
522  * Construct operation from opcode and flags
523  *
524  * @v opcode Opcode
525  * @v opflags Flags
526  * @ret op Operation
527  */
528 #define NII_OP( opcode, opflags ) ( (opcode) | ( (opflags) << 16 ) )
529 
530 /**
531  * Extract opcode from operation
532  *
533  * @v op Operation
534  * @ret opcode Opcode
535  */
536 #define NII_OPCODE( op ) ( (op) & 0xffff )
537 
538 /**
539  * Extract flags from operation
540  *
541  * @v op Operation
542  * @ret opflags Flags
543  */
544 #define NII_OPFLAGS( op ) ( (op) >> 16 )
545 
546 /**
547  * Issue command with parameter block and data block
548  *
549  * @v nii NII NIC
550  * @v op Operation
551  * @v cpb Command parameter block, or NULL
552  * @v cpb_len Command parameter block length
553  * @v db Data block, or NULL
554  * @v db_len Data block length
555  * @ret stat Status flags, or negative status code
556  */
557 static int nii_issue_cpb_db ( struct nii_nic *nii, unsigned int op, void *cpb,
558  size_t cpb_len, void *db, size_t db_len ) {
560  PXE_CDB cdb;
561  UINTN tpl;
562 
563  /* Prepare command descriptor block */
564  memset ( &cdb, 0, sizeof ( cdb ) );
565  cdb.OpCode = NII_OPCODE ( op );
566  cdb.OpFlags = NII_OPFLAGS ( op );
567  cdb.CPBaddr = ( ( intptr_t ) cpb );
568  cdb.CPBsize = cpb_len;
569  cdb.DBaddr = ( ( intptr_t ) db );
570  cdb.DBsize = db_len;
571  cdb.IFnum = nii->nii->IfNum;
572 
573  /* Raise task priority level */
574  tpl = bs->RaiseTPL ( efi_internal_tpl );
575 
576  /* Issue command */
577  DBGC2 ( nii, "NII %s issuing %02x:%04x ifnum %d%s%s\n",
578  nii->dev.name, cdb.OpCode, cdb.OpFlags, cdb.IFnum,
579  ( cpb ? " cpb" : "" ), ( db ? " db" : "" ) );
580  if ( cpb )
581  DBGC2_HD ( nii, cpb, cpb_len );
582  if ( db )
583  DBGC2_HD ( nii, db, db_len );
584  nii->issue ( ( intptr_t ) &cdb );
585 
586  /* Restore task priority level */
587  bs->RestoreTPL ( tpl );
588 
589  /* Check completion status */
590  if ( cdb.StatCode != PXE_STATCODE_SUCCESS )
591  return -cdb.StatCode;
592 
593  /* Return command-specific status flags */
594  return ( cdb.StatFlags & ~PXE_STATFLAGS_STATUS_MASK );
595 }
596 
597 /**
598  * Issue command with parameter block
599  *
600  * @v nii NII NIC
601  * @v op Operation
602  * @v cpb Command parameter block, or NULL
603  * @v cpb_len Command parameter block length
604  * @ret stat Status flags, or negative status code
605  */
606 static int nii_issue_cpb ( struct nii_nic *nii, unsigned int op, void *cpb,
607  size_t cpb_len ) {
608 
609  return nii_issue_cpb_db ( nii, op, cpb, cpb_len, NULL, 0 );
610 }
611 
612 /**
613  * Issue command with data block
614  *
615  * @v nii NII NIC
616  * @v op Operation
617  * @v db Data block, or NULL
618  * @v db_len Data block length
619  * @ret stat Status flags, or negative status code
620  */
621 static int nii_issue_db ( struct nii_nic *nii, unsigned int op, void *db,
622  size_t db_len ) {
623 
624  return nii_issue_cpb_db ( nii, op, NULL, 0, db, db_len );
625 }
626 
627 /**
628  * Issue command
629  *
630  *
631  * @v nii NII NIC
632  * @v op Operation
633  * @ret stat Status flags, or negative status code
634  */
635 static int nii_issue ( struct nii_nic *nii, unsigned int op ) {
636 
637  return nii_issue_cpb_db ( nii, op, NULL, 0, NULL, 0 );
638 }
639 
640 /**
641  * Start UNDI
642  *
643  * @v nii NII NIC
644  * @ret rc Return status code
645  */
646 static int nii_start_undi ( struct nii_nic *nii ) {
647  PXE_CPB_START_31 cpb;
648  int stat;
649  int rc;
650 
651  /* Construct parameter block */
652  memset ( &cpb, 0, sizeof ( cpb ) );
653  cpb.Delay = ( ( intptr_t ) nii_delay );
654  cpb.Block = ( ( intptr_t ) nii_block );
655  cpb.Mem_IO = ( ( intptr_t ) nii_io );
656  cpb.Map_Mem = ( ( intptr_t ) nii_map );
657  cpb.UnMap_Mem = ( ( intptr_t ) nii_unmap );
658  cpb.Sync_Mem = ( ( intptr_t ) nii_sync );
659  cpb.Unique_ID = ( ( intptr_t ) nii );
660 
661  /* Issue command */
662  if ( ( stat = nii_issue_cpb ( nii, PXE_OPCODE_START, &cpb,
663  sizeof ( cpb ) ) ) < 0 ) {
664  rc = -EIO_STAT ( stat );
665  DBGC ( nii, "NII %s could not start: %s\n",
666  nii->dev.name, strerror ( rc ) );
667  return rc;
668  }
669 
670  return 0;
671 }
672 
673 /**
674  * Stop UNDI
675  *
676  * @v nii NII NIC
677  */
678 static void nii_stop_undi ( struct nii_nic *nii ) {
679  int stat;
680  int rc;
681 
682  /* Issue command */
683  if ( ( stat = nii_issue ( nii, PXE_OPCODE_STOP ) ) < 0 ) {
684  rc = -EIO_STAT ( stat );
685  DBGC ( nii, "NII %s could not stop: %s\n",
686  nii->dev.name, strerror ( rc ) );
687  /* Nothing we can do about it */
688  return;
689  }
690 }
691 
692 /**
693  * Get initialisation information
694  *
695  * @v nii NII NIC
696  * @v netdev Network device to fill in
697  * @ret rc Return status code
698  */
699 static int nii_get_init_info ( struct nii_nic *nii,
700  struct net_device *netdev ) {
702  int stat;
703  int rc;
704 
705  /* Issue command */
707  sizeof ( db ) ) ) < 0 ) {
708  rc = -EIO_STAT ( stat );
709  DBGC ( nii, "NII %s could not get initialisation info: %s\n",
710  nii->dev.name, strerror ( rc ) );
711  return rc;
712  }
713 
714  /* Determine link layer protocol */
715  switch ( db.IFtype ) {
716  case PXE_IFTYPE_ETHERNET :
717  netdev->ll_protocol = &ethernet_protocol;
718  break;
719  default:
720  DBGC ( nii, "NII %s unknown interface type %#02x\n",
721  nii->dev.name, db.IFtype );
722  return -ENOTSUP;
723  }
724 
725  /* Sanity checks */
726  assert ( db.MediaHeaderLen == netdev->ll_protocol->ll_header_len );
727  assert ( db.HWaddrLen == netdev->ll_protocol->hw_addr_len );
728  assert ( db.HWaddrLen == netdev->ll_protocol->ll_addr_len );
729 
730  /* Extract parameters */
731  nii->buffer_len = db.MemoryRequired;
732  nii->mtu = ( db.FrameDataLen + db.MediaHeaderLen );
733  netdev->max_pkt_len = nii->mtu;
735 
736  return 0;
737 }
738 
739 /**
740  * Initialise UNDI
741  *
742  * @v nii NII NIC
743  * @v flags Flags
744  * @ret rc Return status code
745  */
746 static int nii_initialise_flags ( struct nii_nic *nii, unsigned int flags ) {
747  PXE_CPB_INITIALIZE cpb;
749  unsigned int op;
750  int stat;
751  int rc;
752 
753  /* Allocate memory buffer */
754  nii->buffer = umalloc ( nii->buffer_len );
755  if ( ! nii->buffer ) {
756  rc = -ENOMEM;
757  goto err_alloc;
758  }
759 
760  /* Construct parameter block */
761  memset ( &cpb, 0, sizeof ( cpb ) );
762  cpb.MemoryAddr = ( ( intptr_t ) nii->buffer );
763  cpb.MemoryLength = nii->buffer_len;
764 
765  /* Construct data block */
766  memset ( &db, 0, sizeof ( db ) );
767 
768  /* Issue command */
770  if ( ( stat = nii_issue_cpb_db ( nii, op, &cpb, sizeof ( cpb ),
771  &db, sizeof ( db ) ) ) < 0 ) {
772  rc = -EIO_STAT ( stat );
773  DBGC ( nii, "NII %s could not initialise: %s\n",
774  nii->dev.name, strerror ( rc ) );
775  goto err_initialize;
776  }
777 
778  return 0;
779 
780  err_initialize:
781  ufree ( nii->buffer );
782  err_alloc:
783  return rc;
784 }
785 
786 /**
787  * Initialise UNDI with cable detection
788  *
789  * @v nii NII NIC
790  * @ret rc Return status code
791  */
792 static int nii_initialise_cable ( struct nii_nic *nii ) {
793  unsigned int flags;
794 
795  /* Initialise UNDI */
797  return nii_initialise_flags ( nii, flags );
798 }
799 
800 /**
801  * Initialise UNDI
802  *
803  * @v nii NII NIC
804  * @ret rc Return status code
805  */
806 static int nii_initialise ( struct nii_nic *nii ) {
807  unsigned int flags;
808 
809  /* Initialise UNDI */
811  return nii_initialise_flags ( nii, flags );
812 }
813 
814 /**
815  * Shut down UNDI
816  *
817  * @v nii NII NIC
818  */
819 static void nii_shutdown ( struct nii_nic *nii ) {
820  int stat;
821  int rc;
822 
823  /* Issue command */
824  if ( ( stat = nii_issue ( nii, PXE_OPCODE_SHUTDOWN ) ) < 0 ) {
825  rc = -EIO_STAT ( stat );
826  DBGC ( nii, "NII %s could not shut down: %s\n",
827  nii->dev.name, strerror ( rc ) );
828  /* Leak memory to avoid corruption */
829  return;
830  }
831 
832  /* Free buffer */
833  ufree ( nii->buffer );
834 }
835 
836 /**
837  * Get station addresses
838  *
839  * @v nii NII NIC
840  * @v netdev Network device to fill in
841  * @ret rc Return status code
842  */
843 static int nii_get_station_address ( struct nii_nic *nii,
844  struct net_device *netdev ) {
846  unsigned int op;
847  int stat;
848  int rc;
849 
850  /* Initialise UNDI */
851  if ( ( rc = nii_initialise ( nii ) ) != 0 )
852  goto err_initialise;
853 
854  /* Issue command */
857  if ( ( stat = nii_issue_db ( nii, op, &db, sizeof ( db ) ) ) < 0 ) {
858  rc = -EIO_STAT ( stat );
859  DBGC ( nii, "NII %s could not get station address: %s\n",
860  nii->dev.name, strerror ( rc ) );
861  goto err_station_address;
862  }
863 
864  /* Copy MAC addresses */
865  memcpy ( netdev->ll_addr, db.StationAddr,
867  memcpy ( netdev->hw_addr, db.PermanentAddr,
869  memcpy ( nii->broadcast, db.BroadcastAddr,
870  sizeof ( nii->broadcast ) );
871 
872  err_station_address:
873  nii_shutdown ( nii );
874  err_initialise:
875  return rc;
876 }
877 
878 /**
879  * Set station address
880  *
881  * @v nii NII NIC
882  * @v netdev Network device
883  * @ret rc Return status code
884  */
885 static int nii_set_station_address ( struct nii_nic *nii,
886  struct net_device *netdev ) {
887  uint32_t implementation = nii->undi->Implementation;
889  unsigned int op;
890  int stat;
891  int rc;
892 
893  /* Fail if setting station address is unsupported */
895  return -ENOTSUP;
896 
897  /* Construct parameter block */
898  memset ( &cpb, 0, sizeof ( cpb ) );
901 
902  /* Issue command */
905  if ( ( stat = nii_issue_cpb ( nii, op, &cpb, sizeof ( cpb ) ) ) < 0 ) {
906  rc = -EIO_STAT ( stat );
907  DBGC ( nii, "NII %s could not set station address: %s\n",
908  nii->dev.name, strerror ( rc ) );
909  return rc;
910  }
911 
912  return 0;
913 }
914 
915 /**
916  * Set receive filters
917  *
918  * @v nii NII NIC
919  * @v flags Flags
920  * @ret rc Return status code
921  */
922 static int nii_set_rx_filters ( struct nii_nic *nii, unsigned int flags ) {
923  uint32_t implementation = nii->undi->Implementation;
924  unsigned int op;
925  int stat;
926  int rc;
927 
928  /* Construct receive filter set */
936 
937  /* Issue command */
939  if ( ( stat = nii_issue ( nii, op ) ) < 0 ) {
940  rc = -EIO_STAT ( stat );
941  DBGC ( nii, "NII %s could not %s%sable receive filters "
942  "%#04x: %s\n", nii->dev.name,
944  "en" : "" ),
946  "dis" : "" ), flags, strerror ( rc ) );
947  return rc;
948  }
949 
950  return 0;
951 }
952 
953 /**
954  * Enable receive filters
955  *
956  * @v nii NII NIC
957  * @ret rc Return status code
958  */
959 static int nii_enable_rx_filters ( struct nii_nic *nii ) {
960 
962 }
963 
964 /**
965  * Disable receive filters
966  *
967  * @v nii NII NIC
968  * @ret rc Return status code
969  */
970 static int nii_disable_rx_filters ( struct nii_nic *nii ) {
971 
973 }
974 
975 /**
976  * Transmit packet
977  *
978  * @v netdev Network device
979  * @v iobuf I/O buffer
980  * @ret rc Return status code
981  */
982 static int nii_transmit ( struct net_device *netdev,
983  struct io_buffer *iobuf ) {
984  struct nii_nic *nii = netdev->priv;
985  PXE_CPB_TRANSMIT cpb;
986  unsigned int op;
987  int stat;
988  int rc;
989 
990  /* Defer the packet if there is already a transmission in progress */
991  if ( nii->txbuf ) {
992  netdev_tx_defer ( netdev, iobuf );
993  return 0;
994  }
995 
996  /* Pad to minimum Ethernet length, to work around underlying
997  * drivers that do not correctly handle frame padding
998  * themselves.
999  */
1000  iob_pad ( iobuf, ETH_ZLEN );
1001 
1002  /* Construct parameter block */
1003  memset ( &cpb, 0, sizeof ( cpb ) );
1004  cpb.FrameAddr = ( ( intptr_t ) iobuf->data );
1005  cpb.DataLen = iob_len ( iobuf );
1006 
1007  /* Transmit packet */
1011  if ( ( stat = nii_issue_cpb ( nii, op, &cpb, sizeof ( cpb ) ) ) < 0 ) {
1012  rc = -EIO_STAT ( stat );
1013  DBGC ( nii, "NII %s could not transmit: %s\n",
1014  nii->dev.name, strerror ( rc ) );
1015  return rc;
1016  }
1017  nii->txbuf = iobuf;
1018 
1019  return 0;
1020 }
1021 
1022 /**
1023  * Poll for completed packets
1024  *
1025  * @v netdev Network device
1026  * @v stat Status flags
1027  */
1028 static void nii_poll_tx ( struct net_device *netdev, unsigned int stat ) {
1029  struct nii_nic *nii = netdev->priv;
1030  struct io_buffer *iobuf;
1031 
1032  /* Do nothing unless we have a completion */
1034  return;
1035 
1036  /* Ignore spurious completions reported by some devices */
1037  if ( ! nii->txbuf )
1038  return;
1039 
1040  /* Complete transmission */
1041  iobuf = nii->txbuf;
1042  nii->txbuf = NULL;
1043  netdev_tx_complete ( netdev, iobuf );
1044 }
1045 
1046 /**
1047  * Poll for received packets
1048  *
1049  * @v netdev Network device
1050  */
1051 static void nii_poll_rx ( struct net_device *netdev ) {
1052  struct nii_nic *nii = netdev->priv;
1053  PXE_CPB_RECEIVE cpb;
1055  unsigned int quota;
1056  int stat;
1057  int rc;
1058 
1059  /* Retrieve up to NII_RX_QUOTA packets */
1060  for ( quota = NII_RX_QUOTA ; quota ; quota-- ) {
1061 
1062  /* Allocate buffer, if required */
1063  if ( ! nii->rxbuf ) {
1064  nii->rxbuf = alloc_iob ( nii->mtu );
1065  if ( ! nii->rxbuf ) {
1066  /* Leave for next poll */
1067  break;
1068  }
1069  }
1070 
1071  /* Construct parameter block */
1072  memset ( &cpb, 0, sizeof ( cpb ) );
1073  cpb.BufferAddr = ( ( intptr_t ) nii->rxbuf->data );
1074  cpb.BufferLen = iob_tailroom ( nii->rxbuf );
1075 
1076  /* Issue command */
1078  &cpb, sizeof ( cpb ),
1079  &db, sizeof ( db ) ) ) < 0 ) {
1080 
1081  /* PXE_STATCODE_NO_DATA is just the usual "no packet"
1082  * status indicator; ignore it.
1083  */
1084  if ( stat == -PXE_STATCODE_NO_DATA )
1085  break;
1086 
1087  /* Anything else is an error */
1088  rc = -EIO_STAT ( stat );
1089  DBGC ( nii, "NII %s could not receive: %s\n",
1090  nii->dev.name, strerror ( rc ) );
1091  netdev_rx_err ( netdev, NULL, rc );
1092  break;
1093  }
1094 
1095  /* Hand off to network stack */
1096  iob_put ( nii->rxbuf, db.FrameLen );
1097  netdev_rx ( netdev, nii->rxbuf );
1098  nii->rxbuf = NULL;
1099  }
1100 }
1101 
1102 /**
1103  * Check for link state changes
1104  *
1105  * @v netdev Network device
1106  * @v stat Status flags
1107  */
1108 static void nii_poll_link ( struct net_device *netdev, unsigned int stat ) {
1109  int no_media = ( stat & PXE_STATFLAGS_GET_STATUS_NO_MEDIA );
1110 
1111  if ( no_media && netdev_link_ok ( netdev ) ) {
1113  } else if ( ( ! no_media ) && ( ! netdev_link_ok ( netdev ) ) ) {
1114  netdev_link_up ( netdev );
1115  }
1116 }
1117 
1118 /**
1119  * Poll for completed packets
1120  *
1121  * @v netdev Network device
1122  */
1123 static void nii_poll ( struct net_device *netdev ) {
1124  struct nii_nic *nii = netdev->priv;
1126  unsigned int op;
1127  int stat;
1128  int rc;
1129 
1130  /* Construct data block */
1131  memset ( &db, 0, sizeof ( db ) );
1132 
1133  /* Get status */
1137  ( nii->media ? PXE_OPFLAGS_GET_MEDIA_STATUS : 0 ) ) );
1138  if ( ( stat = nii_issue_db ( nii, op, &db, sizeof ( db ) ) ) < 0 ) {
1139  rc = -EIO_STAT ( stat );
1140  DBGC ( nii, "NII %s could not get status: %s\n",
1141  nii->dev.name, strerror ( rc ) );
1142  return;
1143  }
1144 
1145  /* Process any TX completions */
1146  nii_poll_tx ( netdev, stat );
1147 
1148  /* Process any RX completions */
1149  nii_poll_rx ( netdev );
1150 
1151  /* Check for link state changes */
1152  if ( nii->media )
1153  nii_poll_link ( netdev, stat );
1154 }
1155 
1156 /**
1157  * Open network device
1158  *
1159  * @v netdev Network device
1160  * @ret rc Return status code
1161  */
1162 static int nii_open ( struct net_device *netdev ) {
1163  struct nii_nic *nii = netdev->priv;
1164  int rc;
1165 
1166  /* Initialise NIC
1167  *
1168  * We don't care about link state here, and would prefer to
1169  * have the NIC initialise even if no cable is present, to
1170  * match the behaviour of all other iPXE drivers.
1171  *
1172  * Some Emulex NII drivers have a bug which prevents packets
1173  * from being sent or received unless we specifically ask it
1174  * to detect cable presence during initialisation.
1175  *
1176  * Unfortunately, some other NII drivers (e.g. Mellanox) may
1177  * time out and report failure if asked to detect cable
1178  * presence during initialisation on links that are physically
1179  * slow to reach link-up.
1180  *
1181  * Attempt to work around both of these problems by first
1182  * attempting to initialise with cable presence detection,
1183  * then falling back to initialising without cable presence
1184  * detection.
1185  */
1186  if ( ( rc = nii_initialise_cable ( nii ) ) != 0 ) {
1187  DBGC ( nii, "NII %s could not initialise with cable "
1188  "detection: %s\n", nii->dev.name, strerror ( rc ) );
1189  if ( ( rc = nii_initialise ( nii ) ) != 0 ) {
1190  DBGC ( nii, "NII %s could not initialise without "
1191  "cable detection: %s\n",
1192  nii->dev.name, strerror ( rc ) );
1193  goto err_initialise;
1194  }
1195  }
1196 
1197  /* Attempt to set station address */
1198  if ( ( rc = nii_set_station_address ( nii, netdev ) ) != 0 ) {
1199  DBGC ( nii, "NII %s could not set station address: %s\n",
1200  nii->dev.name, strerror ( rc ) );
1201  /* Treat as non-fatal */
1202  }
1203 
1204  /* Disable receive filters
1205  *
1206  * We have no reason to disable receive filters here (or
1207  * anywhere), but some NII drivers have a bug which prevents
1208  * packets from being received unless we attempt to disable
1209  * the receive filters.
1210  *
1211  * Ignore any failures, since we genuinely don't care if the
1212  * NII driver cannot disable the filters.
1213  */
1215 
1216  /* Enable receive filters */
1217  if ( ( rc = nii_enable_rx_filters ( nii ) ) != 0 )
1218  goto err_enable_rx_filters;
1219 
1220  return 0;
1221 
1222  err_enable_rx_filters:
1223  nii_shutdown ( nii );
1224  err_initialise:
1225  return rc;
1226 }
1227 
1228 /**
1229  * Close network device
1230  *
1231  * @v netdev Network device
1232  */
1233 static void nii_close ( struct net_device *netdev ) {
1234  struct nii_nic *nii = netdev->priv;
1235 
1236  /* Shut down NIC */
1237  nii_shutdown ( nii );
1238 
1239  /* Discard transmit buffer, if applicable */
1240  if ( nii->txbuf ) {
1242  nii->txbuf = NULL;
1243  }
1244 
1245  /* Discard receive buffer, if applicable */
1246  if ( nii->rxbuf ) {
1247  free_iob ( nii->rxbuf );
1248  nii->rxbuf = NULL;
1249  }
1250 }
1251 
1252 /** NII network device operations */
1254  .open = nii_open,
1255  .close = nii_close,
1256  .transmit = nii_transmit,
1257  .poll = nii_poll,
1258 };
1259 
1260 /**
1261  * Exclude existing drivers
1262  *
1263  * @v device EFI device handle
1264  * @ret rc Return status code
1265  */
1268  int rc;
1269 
1270  /* Exclude existing NII protocol drivers */
1271  if ( ( rc = efi_driver_exclude ( device, protocol ) ) != 0 ) {
1272  DBGC ( device, "NII %s could not exclude drivers: %s\n",
1273  efi_handle_name ( device ), strerror ( rc ) );
1274  return rc;
1275  }
1276 
1277  return 0;
1278 }
1279 
1280 /**
1281  * Attach driver to device
1282  *
1283  * @v efidev EFI device
1284  * @ret rc Return status code
1285  */
1286 int nii_start ( struct efi_device *efidev ) {
1287  EFI_HANDLE device = efidev->device;
1288  struct net_device *netdev;
1289  struct nii_nic *nii;
1290  int rc;
1291 
1292  /* Allocate and initialise structure */
1293  netdev = alloc_netdev ( sizeof ( *nii ) );
1294  if ( ! netdev ) {
1295  rc = -ENOMEM;
1296  goto err_alloc;
1297  }
1299  nii = netdev->priv;
1300  nii->efidev = efidev;
1301  INIT_LIST_HEAD ( &nii->mappings );
1302  netdev->ll_broadcast = nii->broadcast;
1304 
1305  /* Populate underlying device information */
1306  efi_device_info ( device, "NII", &nii->dev );
1307  nii->dev.driver_name = "NII";
1308  nii->dev.parent = &efidev->dev;
1309  list_add ( &nii->dev.siblings, &efidev->dev.children );
1310  INIT_LIST_HEAD ( &nii->dev.children );
1311  netdev->dev = &nii->dev;
1312 
1313  /* Open NII protocol */
1315  &nii->nii ) ) != 0 ) {
1316  DBGC ( nii, "NII %s cannot open NII protocol: %s\n",
1317  nii->dev.name, strerror ( rc ) );
1319  goto err_open_protocol;
1320  }
1321 
1322  /* Locate UNDI and entry point */
1323  nii->undi = ( ( void * ) ( intptr_t ) nii->nii->Id );
1324  if ( ! nii->undi ) {
1325  DBGC ( nii, "NII %s has no UNDI\n", nii->dev.name );
1326  rc = -ENODEV;
1327  goto err_no_undi;
1328  }
1329  if ( nii->undi->Implementation & PXE_ROMID_IMP_HW_UNDI ) {
1330  DBGC ( nii, "NII %s is a mythical hardware UNDI\n",
1331  nii->dev.name );
1332  rc = -ENOTSUP;
1333  goto err_hw_undi;
1334  }
1335  if ( nii->undi->Implementation & PXE_ROMID_IMP_SW_VIRT_ADDR ) {
1336  nii->issue = ( ( void * ) ( intptr_t ) nii->undi->EntryPoint );
1337  } else {
1338  nii->issue = ( ( ( void * ) nii->undi ) +
1339  nii->undi->EntryPoint );
1340  }
1341  DBGC ( nii, "NII %s using UNDI v%x.%x at %p entry %p impl %#08x\n",
1342  nii->dev.name, nii->nii->MajorVer, nii->nii->MinorVer,
1343  nii->undi, nii->issue, nii->undi->Implementation );
1344 
1345  /* Open PCI I/O protocols and locate BARs */
1346  if ( ( rc = nii_pci_open ( nii ) ) != 0 )
1347  goto err_pci_open;
1348 
1349  /* Start UNDI */
1350  if ( ( rc = nii_start_undi ( nii ) ) != 0 )
1351  goto err_start_undi;
1352 
1353  /* Get initialisation information */
1354  if ( ( rc = nii_get_init_info ( nii, netdev ) ) != 0 )
1355  goto err_get_init_info;
1356 
1357  /* Get MAC addresses */
1358  if ( ( rc = nii_get_station_address ( nii, netdev ) ) != 0 )
1359  goto err_get_station_address;
1360 
1361  /* Register network device */
1362  if ( ( rc = register_netdev ( netdev ) ) != 0 )
1363  goto err_register_netdev;
1364  DBGC ( nii, "NII %s registered as %s for %s\n", nii->dev.name,
1366 
1367  /* Set initial link state (if media detection is not supported) */
1368  if ( ! nii->media )
1369  netdev_link_up ( netdev );
1370 
1371  return 0;
1372 
1374  err_register_netdev:
1375  err_get_station_address:
1376  err_get_init_info:
1377  nii_stop_undi ( nii );
1378  err_start_undi:
1379  nii_pci_close ( nii );
1380  err_pci_open:
1381  err_hw_undi:
1382  err_no_undi:
1384  err_open_protocol:
1385  list_del ( &nii->dev.siblings );
1386  netdev_nullify ( netdev );
1387  netdev_put ( netdev );
1388  err_alloc:
1389  return rc;
1390 }
1391 
1392 /**
1393  * Detach driver from device
1394  *
1395  * @v efidev EFI device
1396  */
1397 void nii_stop ( struct efi_device *efidev ) {
1398  struct net_device *netdev = efidev_get_drvdata ( efidev );
1399  struct nii_nic *nii = netdev->priv;
1401 
1402  /* Unregister network device */
1404 
1405  /* Stop UNDI */
1406  nii_stop_undi ( nii );
1407 
1408  /* Close PCI I/O protocols */
1409  nii_pci_close ( nii );
1410 
1411  /* Close NII protocol */
1413 
1414  /* Free network device */
1415  list_del ( &nii->dev.siblings );
1416  netdev_nullify ( netdev );
1417  netdev_put ( netdev );
1418 }
EFI_GUID efi_nii31_protocol_guid
Network interface identifier protocol GUID (new version)
Definition: efi_guid.c:308
static int nii_disable_rx_filters(struct nii_nic *nii)
Disable receive filters.
Definition: nii.c:970
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:544
static __always_inline void ufree(void *ptr)
Free external memory.
Definition: umalloc.h:67
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2098
#define EFI_UNSUPPORTED
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:117
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:1108
static void netdev_tx_complete(struct net_device *netdev, struct io_buffer *iobuf)
Complete network transmission.
Definition: netdevice.h:766
#define iob_put(iobuf, len)
Definition: iobuf.h:124
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:174
static void nii_poll(struct net_device *netdev)
Poll for completed packets.
Definition: nii.c:1123
EFI_RAISE_TPL RaiseTPL
Definition: UefiSpec.h:1939
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.
uint32_t stat
Completion status.
Definition: dwmac.h:12
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
PACKED struct @539 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
The common definition of QWORD, DWORD, and WORD Address Space Descriptors.
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:69
128 bit buffer containing a unique identifier value.
Definition: Base.h:215
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:621
EFI_GUID efi_pci_io_protocol_guid
PCI I/O protocol GUID.
Definition: efi_guid.c:312
int nii_start(struct efi_device *efidev)
Attach driver to device.
Definition: nii.c:1286
static EFIAPI VOID nii_delay(UINT64 unique_id __unused, UINTN microseconds)
Delay callback.
Definition: nii.c:494
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:152
#define efi_open_unsafe(handle, protocol, interface)
Open protocol for unsafe persistent use.
Definition: efi.h:458
#define NII_OPCODE(op)
Extract opcode from operation.
Definition: nii.c:536
#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
#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:78
static int nii_initialise_flags(struct nii_nic *nii, unsigned int flags)
Initialise UNDI.
Definition: nii.c:746
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 FROM_DEVICE
Definition: UefiPxe.h:1083
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:344
#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
#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:1397
PXE_MAC_ADDR StationAddr
If supplied and supported, the current station MAC address will be changed.
Definition: UefiPxe.h:1338
unsigned long intptr_t
Definition: stdint.h:21
int nii_exclude(EFI_HANDLE device)
Exclude existing drivers.
Definition: nii.c:1266
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
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:130
EFI_TPL efi_internal_tpl
Internal task priority level.
Definition: efi_init.c:53
static EFIAPI VOID nii_sync(UINT64 unique_id __unused, UINT64 addr, UINT32 len, UINT32 dir, UINT64 mapped)
Sync callback.
Definition: nii.c:466
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:649
#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:1028
static EFIAPI VOID nii_map(UINT64 unique_id, UINT64 addr, UINT32 len, UINT32 dir, UINT64 mapped)
Map callback.
Definition: nii.c:364
#define ACPI_ADDRESS_SPACE_TYPE_MEM
Definition: Acpi10.h:100
static void nii_shutdown(struct nii_nic *nii)
Shut down UNDI.
Definition: nii.c:819
unsigned long tmp
Definition: linux_pci.h:64
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:518
struct net_device * alloc_netdev(size_t priv_len)
Allocate network device.
Definition: netdevice.c:721
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
struct ena_llq_option desc
Descriptor counts.
Definition: ena.h:20
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:76
void efi_close_unsafe(EFI_HANDLE handle, EFI_GUID *protocol)
Close protocol opened for unsafe persistent use.
Definition: efi_open.c:218
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static signed char phys[4]
Definition: epic100.c:88
#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:885
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:575
Ethernet protocol.
void efi_close_by_driver(EFI_HANDLE handle, EFI_GUID *protocol)
Close protocol opened for persistent use by a driver.
Definition: efi_open.c:278
static const void * src
Definition: string.h:47
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:1162
static int nii_set_rx_filters(struct nii_nic *nii, unsigned int flags)
Set receive filters.
Definition: nii.c:922
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 __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
#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:66
#define efi_open_by_driver(handle, protocol, interface)
Open protocol for persistent use by a driver.
Definition: efi.h:473
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:788
ring len
Length.
Definition: dwmac.h:231
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:318
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:639
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
static unsigned int count
Number of entries.
Definition: dwmac.h:225
#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:1253
#define PXE_ROMID_IMP_SW_VIRT_ADDR
Definition: UefiPxe.h:853
#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:652
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:661
EFI Boot Services Table.
Definition: UefiSpec.h:1930
#define DBGC2_HD(...)
Definition: compiler.h:524
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:210
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:159
static void * efidev_get_drvdata(struct efi_device *efidev)
Get EFI driver-private data.
Definition: efi_driver.h:94
static EFIAPI VOID nii_block(UINT64 unique_id, UINT32 acquire)
Block callback.
Definition: nii.c:505
uint32_t addr
Buffer address.
Definition: dwmac.h:20
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:792
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:179
#define ENODEV
No such device.
Definition: errno.h:509
int efi_driver_exclude(EFI_HANDLE device, EFI_GUID *protocol)
Try to disconnect an existing EFI driver.
Definition: efi_driver.c:437
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:531
#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:557
#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:1233
#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
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:635
#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:1949
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:806
EFI API.
static int nii_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: nii.c:982
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:959
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:843
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
void * buffer
Hardware transmit/receive buffer.
Definition: nii.c:180
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 int struct dma_mapping * map
Definition: dma.h:183
#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:646
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:52
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
struct list_head children
Devices attached to this device.
Definition: device.h:86
static __always_inline void * umalloc(size_t size)
Allocate external memory.
Definition: umalloc.h:56
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:292
static int nii_get_init_info(struct nii_nic *nii, struct net_device *netdev)
Get initialisation information.
Definition: nii.c:699
#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:434
size_t mtu
Maximum packet length.
Definition: nii.c:177
EFI_SYSTEM_TABLE * efi_systab
uint16_t protocol
Protocol ID.
Definition: stp.h:18
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:678
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:1940
#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:1051
#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:83
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
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:61
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:606
void efi_device_info(EFI_HANDLE device, const char *prefix, struct device *dev)
Get underlying device information.
Definition: efi_utils.c:188
#define NII_OP(opcode, opflags)
Construct operation from opcode and flags.
Definition: nii.c:528
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:37
struct io_buffer * rxbuf
Current receive buffer.
Definition: nii.c:193
#define PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE
Definition: UefiPxe.h:214