]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/SnpDxe/Snp.h
1. Add EFI_COMPONENT_NAME2_PROTOCOL.GetControllerName() support.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / Snp.h
1 /** @file
2 Declaration of strctures and functions for SnpDxe driver.
3
4 Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are licensed
6 and made available under the terms and conditions of the BSD License which
7 accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14 #ifndef _SNP_H_
15 #define _SNP_H_
16
17
18 #include <Uefi.h>
19
20 #include <Protocol/SimpleNetwork.h>
21 #include <Protocol/PciIo.h>
22 #include <Protocol/NetworkInterfaceIdentifier.h>
23 #include <Protocol/DevicePath.h>
24
25 #include <Guid/EventGroup.h>
26
27 #include <Library/DebugLib.h>
28 #include <Library/BaseMemoryLib.h>
29 #include <Library/UefiDriverEntryPoint.h>
30 #include <Library/UefiBootServicesTableLib.h>
31 #include <Library/BaseLib.h>
32 #include <Library/UefiLib.h>
33 #include <Library/MemoryAllocationLib.h>
34 #include <Library/PrintLib.h>
35
36 #include <IndustryStandard/Pci.h>
37
38 #define FOUR_GIGABYTES (UINT64) 0x100000000ULL
39
40
41 #define SNP_DRIVER_SIGNATURE SIGNATURE_32 ('s', 'n', 'd', 's')
42 #define MAX_MAP_LENGTH 100
43
44 #define PCI_BAR_IO_MASK 0x00000003
45 #define PCI_BAR_IO_MODE 0x00000001
46
47 #define PCI_BAR_MEM_MASK 0x0000000F
48 #define PCI_BAR_MEM_MODE 0x00000000
49 #define PCI_BAR_MEM_64BIT 0x00000004
50
51 typedef
52 EFI_STATUS
53 (EFIAPI *ISSUE_UNDI32_COMMAND) (
54 UINT64 Cdb
55 );
56
57 typedef struct {
58 UINT32 Signature;
59 EFI_LOCK Lock;
60
61 EFI_SIMPLE_NETWORK_PROTOCOL Snp;
62 EFI_SIMPLE_NETWORK_MODE Mode;
63
64 EFI_HANDLE DeviceHandle;
65 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
66
67 //
68 // Local instance data needed by SNP driver
69 //
70 // Pointer to S/W UNDI API entry point
71 // This will be NULL for H/W UNDI
72 //
73 ISSUE_UNDI32_COMMAND IssueUndi32Command;
74
75 BOOLEAN IsSwUndi;
76
77 //
78 // undi interface number, if one undi manages more nics
79 //
80 PXE_IFNUM IfNum;
81
82 //
83 // Allocated tx/rx buffer that was passed to UNDI Initialize.
84 //
85 UINT32 TxRxBufferSize;
86 VOID *TxRxBuffer;
87 //
88 // mappable buffers for receive and fill header for undi3.0
89 // these will be used if the user buffers are above 4GB limit (instead of
90 // mapping the user buffers)
91 //
92 UINT8 *ReceiveBufffer;
93 VOID *ReceiveBufferUnmap;
94 UINT8 *FillHeaderBuffer;
95 VOID *FillHeaderBufferUnmap;
96
97 EFI_PCI_IO_PROTOCOL *PciIo;
98 UINT8 IoBarIndex;
99 UINT8 MemoryBarIndex;
100
101 //
102 // Buffers for command descriptor block, command parameter block
103 // and data block.
104 //
105 PXE_CDB Cdb;
106 VOID *Cpb;
107 VOID *CpbUnmap;
108 VOID *Db;
109
110 //
111 // UNDI structure, we need to remember the init info for a long time!
112 //
113 PXE_DB_GET_INIT_INFO InitInfo;
114
115 VOID *SnpDriverUnmap;
116 //
117 // when ever we map an address, we must remember it's address and the un-map
118 // cookie so that we can unmap later
119 //
120 struct MAP_LIST {
121 EFI_PHYSICAL_ADDRESS VirtualAddress;
122 VOID *MapCookie;
123 } MapList[MAX_MAP_LENGTH];
124
125 EFI_EVENT ExitBootServicesEvent;
126
127 //
128 // Whether UNDI support reporting media status from GET_STATUS command,
129 // i.e. PXE_STATFLAGS_GET_STATUS_NO_MEDIA_SUPPORTED
130 //
131 BOOLEAN MediaStatusSupported;
132 } SNP_DRIVER;
133
134 #define EFI_SIMPLE_NETWORK_DEV_FROM_THIS(a) CR (a, SNP_DRIVER, Snp, SNP_DRIVER_SIGNATURE)
135
136 //
137 // Global Variables
138 //
139 extern EFI_DRIVER_BINDING_PROTOCOL gSimpleNetworkDriverBinding;
140 extern EFI_COMPONENT_NAME_PROTOCOL gSimpleNetworkComponentName;
141 extern EFI_COMPONENT_NAME2_PROTOCOL gSimpleNetworkComponentName2;
142
143 //
144 // Virtual to physical mapping for all UNDI 3.0s.
145 //
146 typedef struct _V2P V2P;
147
148 struct _V2P {
149 V2P *Next;
150 VOID *VirtualAddress;
151 UINTN BufferSize;
152 EFI_PHYSICAL_ADDRESS PhysicalAddress;
153 VOID *Unmap;
154 };
155
156 /**
157 This routine maps the given CPU address to a Device address. It creates a
158 an entry in the map list with the virtual and physical addresses and the
159 un map cookie.
160
161 @param V2p pointer to return a map list node pointer.
162 @param Type the direction in which the data flows from the given
163 virtual address device->cpu or cpu->device or both
164 ways.
165 @param VirtualAddress virtual address (or CPU address) to be mapped.
166 @param BufferSize size of the buffer to be mapped.
167
168 @retval EFI_SUCEESS routine has completed the mapping.
169 @retval other error as indicated.
170
171 **/
172 EFI_STATUS
173 AddV2p (
174 V2P **V2p,
175 EFI_PCI_IO_PROTOCOL_OPERATION Type,
176 VOID *VirtualAddress,
177 UINTN BufferSize
178 );
179
180 /**
181 This routine searches the linked list of mapped address nodes (for undi3.0
182 interface) to find the node that corresponds to the given virtual address and
183 returns a pointer to that node.
184
185 @param V2p pointer to return a map list node pointer.
186 @param VirtualAddress virtual address (or CPU address) to be searched in
187 the map list
188
189 @retval EFI_SUCEESS if a match found!
190 @retval Other match not found
191
192 **/
193 EFI_STATUS
194 FindV2p (
195 V2P **V2p,
196 VOID *VirtualAddress
197 );
198
199 /**
200 this routine calls undi to start the interface and changes the snp state.
201
202 @param Snp pointer to snp driver structure
203
204 @retval EFI_DEVICE_ERROR UNDI could not be started
205 @retval EFI_SUCCESS UNDI is started successfully
206
207 **/
208 EFI_STATUS
209 PxeStart (
210 IN SNP_DRIVER *Snp
211 );
212
213 /**
214 this routine calls undi to stop the interface and changes the snp state.
215
216 @param Snp pointer to snp driver structure
217
218 @retval EFI_INVALID_PARAMETER invalid parameter
219 @retval EFI_NOT_STARTED SNP is not started
220 @retval EFI_DEVICE_ERROR SNP is not initialized
221 @retval EFI_UNSUPPORTED operation unsupported
222
223 **/
224 EFI_STATUS
225 PxeStop (
226 SNP_DRIVER *Snp
227 );
228
229 /**
230 this routine calls undi to initialize the interface.
231
232 @param Snp pointer to snp driver structure
233 @param CableDetectFlag Do/don't detect the cable (depending on what undi supports)
234
235 @retval EFI_SUCCESS UNDI is initialized successfully
236 @retval EFI_DEVICE_ERROR UNDI could not be initialized
237 @retval Other other errors
238
239 **/
240 EFI_STATUS
241 PxeInit (
242 SNP_DRIVER *Snp,
243 UINT16 CableDetectFlag
244 );
245
246 /**
247 this routine calls undi to shut down the interface.
248
249 @param Snp pointer to snp driver structure
250
251 @retval EFI_SUCCESS UNDI is shut down successfully
252 @retval EFI_DEVICE_ERROR UNDI could not be shut down
253
254 **/
255 EFI_STATUS
256 PxeShutdown (
257 IN SNP_DRIVER *Snp
258 );
259
260 /**
261 this routine calls undi to read the MAC address of the NIC and updates the
262 mode structure with the address.
263
264 @param Snp pointer to snp driver structure.
265
266 @retval EFI_SUCCESS the MAC address of the NIC is read successfully.
267 @retval EFI_DEVICE_ERROR failed to read the MAC address of the NIC.
268
269 **/
270 EFI_STATUS
271 PxeGetStnAddr (
272 SNP_DRIVER *Snp
273 );
274
275 /**
276 This routine unmaps the given virtual address and frees the memory allocated
277 for the map list node corresponding to that address.
278
279 @param VirtualAddress virtual address (or CPU address) to be unmapped
280
281 @retval EFI_SUCEESS if successfully unmapped
282 @retval Other as indicated by the error
283
284 **/
285 EFI_STATUS
286 DelV2p (
287 VOID *VirtualAddress
288 );
289
290 /**
291 This is a callback routine supplied to UNDI at undi_start time.
292 UNDI call this routine when it wants to have exclusive access to a critical
293 section of the code/data.
294
295 @param Enable non-zero indicates acquire
296 zero indicates release
297
298 **/
299 VOID
300 EFIAPI
301 SnpUndi32CallbackBlock30 (
302 IN UINT32 Enable
303 );
304
305 /**
306 This is a callback routine supplied to UNDI at undi_start time.
307 UNDI call this routine with the number of micro seconds when it wants to
308 pause.
309
310 @param MicroSeconds number of micro seconds to pause, ususlly multiple of 10.
311
312 **/
313 VOID
314 EFIAPI
315 SnpUndi32CallbackDelay30 (
316 IN UINT64 MicroSeconds
317 );
318
319 /**
320 This is a callback routine supplied to UNDI at undi_start time.
321 This is the IO routine for UNDI. This is not currently being used by UNDI3.0
322 because Undi3.0 uses io/mem offsets relative to the beginning of the device
323 io/mem address and so it needs to use the PCI_IO_FUNCTION that abstracts the
324 start of the device's io/mem addresses. Since SNP cannot retrive the context
325 of the undi3.0 interface it cannot use the PCI_IO_FUNCTION that specific for
326 that NIC and uses one global IO functions structure, this does not work.
327 This however works fine for EFI1.0 Undis because they use absolute addresses
328 for io/mem access.
329
330 @param ReadOrWrite indicates read or write, IO or Memory
331 @param NumBytes number of bytes to read or write
332 @param Address IO or memory address to read from or write to
333 @param BufferAddr memory location to read into or that contains the bytes to
334 write
335
336 **/
337 VOID
338 EFIAPI
339 SnpUndi32CallbackMemio30 (
340 IN UINT8 ReadOrWrite,
341 IN UINT8 NumBytes,
342 IN UINT64 Address,
343 IN OUT UINT64 BufferAddr
344 );
345
346 /**
347 This is a callback routine supplied to UNDI at undi_start time.
348 UNDI call this routine with a virtual or CPU address that SNP provided to
349 convert it to a physical or device address. Since EFI uses the identical
350 mapping, this routine returns the physical address same as the virtual address
351 for most of the addresses. an address above 4GB cannot generally be used as a
352 device address, it needs to be mapped to a lower physical address. This
353 routine does not call the map routine itself, but it assumes that the mapping
354 was done at the time of providing the address to UNDI. This routine just
355 looks up the address in a map table (which is the v2p structure chain).
356
357 @param CpuAddr virtual address of a buffer.
358 @param DeviceAddrPtr pointer to the physical address.
359 The DeviceAddrPtr will contain 0 in case of any error.
360
361 **/
362 VOID
363 EFIAPI
364 SnpUndi32CallbackV2p30 (
365 IN UINT64 CpuAddr,
366 IN OUT UINT64 DeviceAddrPtr
367 );
368
369 /**
370 This is a callback routine supplied to UNDI3.1 at undi_start time.
371 UNDI call this routine when it wants to have exclusive access to a critical
372 section of the code/data.
373 New callbacks for 3.1:
374 there won't be a virtual2physical callback for UNDI 3.1 because undi3.1 uses
375 the MemMap call to map the required address by itself!
376
377 @param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this to
378 store Undi interface context (Undi does not read or write
379 this variable)
380 @param Enable non-zero indicates acquire
381 zero indicates release
382 **/
383 VOID
384 EFIAPI
385 SnpUndi32CallbackBlock (
386 IN UINT64 UniqueId,
387 IN UINT32 Enable
388 );
389
390 /**
391 This is a callback routine supplied to UNDI at undi_start time.
392 UNDI call this routine with the number of micro seconds when it wants to
393 pause.
394
395 @param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this to
396 store Undi interface context (Undi does not read or write
397 this variable)
398 @param MicroSeconds number of micro seconds to pause, ususlly multiple of 10.
399 **/
400 VOID
401 EFIAPI
402 SnpUndi32CallbackDelay (
403 IN UINT64 UniqueId,
404 IN UINT64 MicroSeconds
405 );
406
407 /**
408 This is a callback routine supplied to UNDI at undi_start time.
409 This is the IO routine for UNDI3.1 to start CPB.
410
411 @param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this
412 to store Undi interface context (Undi does not read or
413 write this variable)
414 @param ReadOrWrite indicates read or write, IO or Memory.
415 @param NumBytes number of bytes to read or write.
416 @param MemOrPortAddr IO or memory address to read from or write to.
417 @param BufferPtr memory location to read into or that contains the bytes
418 to write.
419 **/
420 VOID
421 EFIAPI
422 SnpUndi32CallbackMemio (
423 IN UINT64 UniqueId,
424 IN UINT8 ReadOrWrite,
425 IN UINT8 NumBytes,
426 IN UINT64 MemOrPortAddr,
427 IN OUT UINT64 BufferPtr
428 );
429
430 /**
431 This is a callback routine supplied to UNDI at undi_start time.
432 UNDI call this routine when it has to map a CPU address to a device
433 address.
434
435 @param UniqueId - This was supplied to UNDI at Undi_Start, SNP uses this to store
436 Undi interface context (Undi does not read or write this variable)
437 @param CpuAddr - Virtual address to be mapped!
438 @param NumBytes - size of memory to be mapped
439 @param Direction - direction of data flow for this memory's usage:
440 cpu->device, device->cpu or both ways
441 @param DeviceAddrPtr - pointer to return the mapped device address
442
443 **/
444 VOID
445 EFIAPI
446 SnpUndi32CallbackMap (
447 IN UINT64 UniqueId,
448 IN UINT64 CpuAddr,
449 IN UINT32 NumBytes,
450 IN UINT32 Direction,
451 IN OUT UINT64 DeviceAddrPtr
452 );
453
454 /**
455 This is a callback routine supplied to UNDI at undi_start time.
456 UNDI call this routine when it wants to unmap an address that was previously
457 mapped using map callback.
458
459 @param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this to store.
460 Undi interface context (Undi does not read or write this variable)
461 @param CpuAddr Virtual address that was mapped!
462 @param NumBytes size of memory mapped
463 @param Direction direction of data flow for this memory's usage:
464 cpu->device, device->cpu or both ways
465 @param DeviceAddr the mapped device address
466
467 **/
468 VOID
469 EFIAPI
470 SnpUndi32CallbackUnmap (
471 IN UINT64 UniqueId,
472 IN UINT64 CpuAddr,
473 IN UINT32 NumBytes,
474 IN UINT32 Direction,
475 IN UINT64 DeviceAddr
476 );
477
478 /**
479 This is a callback routine supplied to UNDI at undi_start time.
480 UNDI call this routine when it wants synchronize the virtual buffer contents
481 with the mapped buffer contents. The virtual and mapped buffers need not
482 correspond to the same physical memory (especially if the virtual address is
483 > 4GB). Depending on the direction for which the buffer is mapped, undi will
484 need to synchronize their contents whenever it writes to/reads from the buffer
485 using either the cpu address or the device address.
486
487 EFI does not provide a sync call, since virt=physical, we sould just do
488 the synchronization ourself here!
489
490 @param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this to store
491 Undi interface context (Undi does not read or write this variable)
492 @param CpuAddr Virtual address that was mapped!
493 @param NumBytes size of memory mapped.
494 @param Direction direction of data flow for this memory's usage:
495 cpu->device, device->cpu or both ways.
496 @param DeviceAddr the mapped device address.
497
498 **/
499 VOID
500 EFIAPI
501 SnpUndi32CallbackSync (
502 IN UINT64 UniqueId,
503 IN UINT64 CpuAddr,
504 IN UINT32 NumBytes,
505 IN UINT32 Direction,
506 IN UINT64 DeviceAddr
507 );
508
509 /**
510 Changes the state of a network interface from "stopped" to "started".
511
512 This function starts a network interface. If the network interface successfully
513 starts, then EFI_SUCCESS will be returned.
514
515 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
516
517 @retval EFI_SUCCESS The network interface was started.
518 @retval EFI_ALREADY_STARTED The network interface is already in the started state.
519 @retval EFI_INVALID_PARAMETER This parameter was NULL or did not point to a valid
520 EFI_SIMPLE_NETWORK_PROTOCOL structure.
521 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
522 @retval EFI_UNSUPPORTED This function is not supported by the network interface.
523
524 **/
525 EFI_STATUS
526 EFIAPI
527 SnpUndi32Start (
528 IN EFI_SIMPLE_NETWORK_PROTOCOL *This
529 );
530
531 /**
532 Changes the state of a network interface from "started" to "stopped".
533
534 This function stops a network interface. This call is only valid if the network
535 interface is in the started state. If the network interface was successfully
536 stopped, then EFI_SUCCESS will be returned.
537
538 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
539
540
541 @retval EFI_SUCCESS The network interface was stopped.
542 @retval EFI_NOT_STARTED The network interface has not been started.
543 @retval EFI_INVALID_PARAMETER This parameter was NULL or did not point to a valid
544 EFI_SIMPLE_NETWORK_PROTOCOL structure.
545 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
546 @retval EFI_UNSUPPORTED This function is not supported by the network interface.
547
548 **/
549 EFI_STATUS
550 EFIAPI
551 SnpUndi32Stop (
552 IN EFI_SIMPLE_NETWORK_PROTOCOL *This
553 );
554
555 /**
556 Resets a network adapter and allocates the transmit and receive buffers
557 required by the network interface; optionally, also requests allocation of
558 additional transmit and receive buffers.
559
560 This function allocates the transmit and receive buffers required by the network
561 interface. If this allocation fails, then EFI_OUT_OF_RESOURCES is returned.
562 If the allocation succeeds and the network interface is successfully initialized,
563 then EFI_SUCCESS will be returned.
564
565 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
566
567 @param ExtraRxBufferSize The size, in bytes, of the extra receive buffer space
568 that the driver should allocate for the network interface.
569 Some network interfaces will not be able to use the
570 extra buffer, and the caller will not know if it is
571 actually being used.
572 @param ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space
573 that the driver should allocate for the network interface.
574 Some network interfaces will not be able to use the
575 extra buffer, and the caller will not know if it is
576 actually being used.
577
578 @retval EFI_SUCCESS The network interface was initialized.
579 @retval EFI_NOT_STARTED The network interface has not been started.
580 @retval EFI_OUT_OF_RESOURCES There was not enough memory for the transmit and
581 receive buffers.
582 @retval EFI_INVALID_PARAMETER This parameter was NULL or did not point to a valid
583 EFI_SIMPLE_NETWORK_PROTOCOL structure.
584 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
585 @retval EFI_UNSUPPORTED The increased buffer size feature is not supported.
586
587 **/
588 EFI_STATUS
589 EFIAPI
590 SnpUndi32Initialize (
591 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
592 IN UINTN ExtraRxBufferSize OPTIONAL,
593 IN UINTN ExtraTxBufferSize OPTIONAL
594 );
595
596 /**
597 Resets a network adapter and reinitializes it with the parameters that were
598 provided in the previous call to Initialize().
599
600 This function resets a network adapter and reinitializes it with the parameters
601 that were provided in the previous call to Initialize(). The transmit and
602 receive queues are emptied and all pending interrupts are cleared.
603 Receive filters, the station address, the statistics, and the multicast-IP-to-HW
604 MAC addresses are not reset by this call. If the network interface was
605 successfully reset, then EFI_SUCCESS will be returned. If the driver has not
606 been initialized, EFI_DEVICE_ERROR will be returned.
607
608 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
609 @param ExtendedVerification Indicates that the driver may perform a more
610 exhaustive verification operation of the device
611 during reset.
612
613 @retval EFI_SUCCESS The network interface was reset.
614 @retval EFI_NOT_STARTED The network interface has not been started.
615 @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
616 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
617 @retval EFI_UNSUPPORTED This function is not supported by the network interface.
618
619 **/
620 EFI_STATUS
621 EFIAPI
622 SnpUndi32Reset (
623 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
624 IN BOOLEAN ExtendedVerification
625 );
626
627 /**
628 Resets a network adapter and leaves it in a state that is safe for another
629 driver to initialize.
630
631 This function releases the memory buffers assigned in the Initialize() call.
632 Pending transmits and receives are lost, and interrupts are cleared and disabled.
633 After this call, only the Initialize() and Stop() calls may be used. If the
634 network interface was successfully shutdown, then EFI_SUCCESS will be returned.
635 If the driver has not been initialized, EFI_DEVICE_ERROR will be returned.
636
637 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
638
639 @retval EFI_SUCCESS The network interface was shutdown.
640 @retval EFI_NOT_STARTED The network interface has not been started.
641 @retval EFI_INVALID_PARAMETER This parameter was NULL or did not point to a valid
642 EFI_SIMPLE_NETWORK_PROTOCOL structure.
643 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
644
645 **/
646 EFI_STATUS
647 EFIAPI
648 SnpUndi32Shutdown (
649 IN EFI_SIMPLE_NETWORK_PROTOCOL *This
650 );
651
652 /**
653 Manages the multicast receive filters of a network interface.
654
655 This function is used enable and disable the hardware and software receive
656 filters for the underlying network device.
657 The receive filter change is broken down into three steps:
658 * The filter mask bits that are set (ON) in the Enable parameter are added to
659 the current receive filter settings.
660 * The filter mask bits that are set (ON) in the Disable parameter are subtracted
661 from the updated receive filter settings.
662 * If the resulting receive filter setting is not supported by the hardware a
663 more liberal setting is selected.
664 If the same bits are set in the Enable and Disable parameters, then the bits
665 in the Disable parameter takes precedence.
666 If the ResetMCastFilter parameter is TRUE, then the multicast address list
667 filter is disabled (irregardless of what other multicast bits are set in the
668 Enable and Disable parameters). The SNP->Mode->MCastFilterCount field is set
669 to zero. The Snp->Mode->MCastFilter contents are undefined.
670 After enabling or disabling receive filter settings, software should verify
671 the new settings by checking the Snp->Mode->ReceiveFilterSettings,
672 Snp->Mode->MCastFilterCount and Snp->Mode->MCastFilter fields.
673 Note: Some network drivers and/or devices will automatically promote receive
674 filter settings if the requested setting can not be honored. For example, if
675 a request for four multicast addresses is made and the underlying hardware
676 only supports two multicast addresses the driver might set the promiscuous
677 or promiscuous multicast receive filters instead. The receiving software is
678 responsible for discarding any extra packets that get through the hardware
679 receive filters.
680 Note: Note: To disable all receive filter hardware, the network driver must
681 be Shutdown() and Stopped(). Calling ReceiveFilters() with Disable set to
682 Snp->Mode->ReceiveFilterSettings will make it so no more packets are
683 returned by the Receive() function, but the receive hardware may still be
684 moving packets into system memory before inspecting and discarding them.
685 Unexpected system errors, reboots and hangs can occur if an OS is loaded
686 and the network devices are not Shutdown() and Stopped().
687 If ResetMCastFilter is TRUE, then the multicast receive filter list on the
688 network interface will be reset to the default multicast receive filter list.
689 If ResetMCastFilter is FALSE, and this network interface allows the multicast
690 receive filter list to be modified, then the MCastFilterCnt and MCastFilter
691 are used to update the current multicast receive filter list. The modified
692 receive filter list settings can be found in the MCastFilter field of
693 EFI_SIMPLE_NETWORK_MODE. If the network interface does not allow the multicast
694 receive filter list to be modified, then EFI_INVALID_PARAMETER will be returned.
695 If the driver has not been initialized, EFI_DEVICE_ERROR will be returned.
696 If the receive filter mask and multicast receive filter list have been
697 successfully updated on the network interface, EFI_SUCCESS will be returned.
698
699 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
700 @param Enable A bit mask of receive filters to enable on the network
701 interface.
702 @param Disable A bit mask of receive filters to disable on the network
703 interface. For backward compatibility with EFI 1.1
704 platforms, the EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST bit
705 must be set when the ResetMCastFilter parameter is TRUE.
706 @param ResetMCastFilter Set to TRUE to reset the contents of the multicast
707 receive filters on the network interface to their
708 default values.
709 @param MCastFilterCnt Number of multicast HW MAC addresses in the new MCastFilter
710 list. This value must be less than or equal to the
711 MCastFilterCnt field of EFI_SIMPLE_NETWORK_MODE.
712 This field is optional if ResetMCastFilter is TRUE.
713 @param MCastFilter A pointer to a list of new multicast receive filter HW
714 MAC addresses. This list will replace any existing
715 multicast HW MAC address list. This field is optional
716 if ResetMCastFilter is TRUE.
717
718 @retval EFI_SUCCESS The multicast receive filter list was updated.
719 @retval EFI_NOT_STARTED The network interface has not been started.
720 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
721 * This is NULL
722 * There are bits set in Enable that are not set
723 in Snp->Mode->ReceiveFilterMask
724 * There are bits set in Disable that are not set
725 in Snp->Mode->ReceiveFilterMask
726 * Multicast is being enabled (the
727 EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST bit is
728 set in Enable, it is not set in Disable, and
729 ResetMCastFilter is FALSE) and MCastFilterCount
730 is zero
731 * Multicast is being enabled and MCastFilterCount
732 is greater than Snp->Mode->MaxMCastFilterCount
733 * Multicast is being enabled and MCastFilter is NULL
734 * Multicast is being enabled and one or more of
735 the addresses in the MCastFilter list are not
736 valid multicast MAC addresses
737 @retval EFI_DEVICE_ERROR One or more of the following conditions is TRUE:
738 * The network interface has been started but has
739 not been initialized
740 * An unexpected error was returned by the
741 underlying network driver or device
742 @retval EFI_UNSUPPORTED This function is not supported by the network
743 interface.
744
745 **/
746 EFI_STATUS
747 EFIAPI
748 SnpUndi32ReceiveFilters (
749 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
750 IN UINT32 Enable,
751 IN UINT32 Disable,
752 IN BOOLEAN ResetMCastFilter,
753 IN UINTN MCastFilterCnt, OPTIONAL
754 IN EFI_MAC_ADDRESS *MCastFilter OPTIONAL
755 );
756
757 /**
758 Modifies or resets the current station address, if supported.
759
760 This function modifies or resets the current station address of a network
761 interface, if supported. If Reset is TRUE, then the current station address is
762 set to the network interface's permanent address. If Reset is FALSE, and the
763 network interface allows its station address to be modified, then the current
764 station address is changed to the address specified by New. If the network
765 interface does not allow its station address to be modified, then
766 EFI_INVALID_PARAMETER will be returned. If the station address is successfully
767 updated on the network interface, EFI_SUCCESS will be returned. If the driver
768 has not been initialized, EFI_DEVICE_ERROR will be returned.
769
770 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
771 @param Reset Flag used to reset the station address to the network interface's
772 permanent address.
773 @param New New station address to be used for the network interface.
774
775
776 @retval EFI_SUCCESS The network interface's station address was updated.
777 @retval EFI_NOT_STARTED The Simple Network Protocol interface has not been
778 started by calling Start().
779 @retval EFI_INVALID_PARAMETER The New station address was not accepted by the NIC.
780 @retval EFI_INVALID_PARAMETER Reset is FALSE and New is NULL.
781 @retval EFI_DEVICE_ERROR The Simple Network Protocol interface has not
782 been initialized by calling Initialize().
783 @retval EFI_DEVICE_ERROR An error occurred attempting to set the new
784 station address.
785 @retval EFI_UNSUPPORTED The NIC does not support changing the network
786 interface's station address.
787
788 **/
789 EFI_STATUS
790 EFIAPI
791 SnpUndi32StationAddress (
792 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
793 IN BOOLEAN Reset,
794 IN EFI_MAC_ADDRESS *New OPTIONAL
795 );
796
797 /**
798 Resets or collects the statistics on a network interface.
799
800 This function resets or collects the statistics on a network interface. If the
801 size of the statistics table specified by StatisticsSize is not big enough for
802 all the statistics that are collected by the network interface, then a partial
803 buffer of statistics is returned in StatisticsTable, StatisticsSize is set to
804 the size required to collect all the available statistics, and
805 EFI_BUFFER_TOO_SMALL is returned.
806 If StatisticsSize is big enough for all the statistics, then StatisticsTable
807 will be filled, StatisticsSize will be set to the size of the returned
808 StatisticsTable structure, and EFI_SUCCESS is returned.
809 If the driver has not been initialized, EFI_DEVICE_ERROR will be returned.
810 If Reset is FALSE, and both StatisticsSize and StatisticsTable are NULL, then
811 no operations will be performed, and EFI_SUCCESS will be returned.
812 If Reset is TRUE, then all of the supported statistics counters on this network
813 interface will be reset to zero.
814
815 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
816 @param Reset Set to TRUE to reset the statistics for the network interface.
817 @param StatisticsSize On input the size, in bytes, of StatisticsTable. On output
818 the size, in bytes, of the resulting table of statistics.
819 @param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that
820 contains the statistics. Type EFI_NETWORK_STATISTICS is
821 defined in "Related Definitions" below.
822
823 @retval EFI_SUCCESS The requested operation succeeded.
824 @retval EFI_NOT_STARTED The Simple Network Protocol interface has not been
825 started by calling Start().
826 @retval EFI_BUFFER_TOO_SMALL StatisticsSize is not NULL and StatisticsTable is
827 NULL. The current buffer size that is needed to
828 hold all the statistics is returned in StatisticsSize.
829 @retval EFI_BUFFER_TOO_SMALL StatisticsSize is not NULL and StatisticsTable is
830 not NULL. The current buffer size that is needed
831 to hold all the statistics is returned in
832 StatisticsSize. A partial set of statistics is
833 returned in StatisticsTable.
834 @retval EFI_INVALID_PARAMETER StatisticsSize is NULL and StatisticsTable is not
835 NULL.
836 @retval EFI_DEVICE_ERROR The Simple Network Protocol interface has not
837 been initialized by calling Initialize().
838 @retval EFI_DEVICE_ERROR An error was encountered collecting statistics
839 from the NIC.
840 @retval EFI_UNSUPPORTED The NIC does not support collecting statistics
841 from the network interface.
842
843 **/
844 EFI_STATUS
845 EFIAPI
846 SnpUndi32Statistics (
847 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
848 IN BOOLEAN Reset,
849 IN OUT UINTN *StatisticsSize, OPTIONAL
850 IN OUT EFI_NETWORK_STATISTICS *StatisticsTable OPTIONAL
851 );
852
853 /**
854 Converts a multicast IP address to a multicast HW MAC address.
855
856 This function converts a multicast IP address to a multicast HW MAC address
857 for all packet transactions. If the mapping is accepted, then EFI_SUCCESS will
858 be returned.
859
860 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
861 @param IPv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460].
862 Set to FALSE if the multicast IP address is IPv4 [RFC 791].
863 @param IP The multicast IP address that is to be converted to a multicast
864 HW MAC address.
865 @param MAC The multicast HW MAC address that is to be generated from IP.
866
867 @retval EFI_SUCCESS The multicast IP address was mapped to the
868 multicast HW MAC address.
869 @retval EFI_NOT_STARTED The Simple Network Protocol interface has not
870 been started by calling Start().
871 @retval EFI_INVALID_PARAMETER IP is NULL.
872 @retval EFI_INVALID_PARAMETER MAC is NULL.
873 @retval EFI_INVALID_PARAMETER IP does not point to a valid IPv4 or IPv6
874 multicast address.
875 @retval EFI_DEVICE_ERROR The Simple Network Protocol interface has not
876 been initialized by calling Initialize().
877 @retval EFI_UNSUPPORTED IPv6 is TRUE and the implementation does not
878 support IPv6 multicast to MAC address conversion.
879
880 **/
881 EFI_STATUS
882 EFIAPI
883 SnpUndi32McastIpToMac (
884 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
885 IN BOOLEAN IPv6,
886 IN EFI_IP_ADDRESS *IP,
887 OUT EFI_MAC_ADDRESS *MAC
888 );
889
890 /**
891 Performs read and write operations on the NVRAM device attached to a network
892 interface.
893
894 This function performs read and write operations on the NVRAM device attached
895 to a network interface. If ReadWrite is TRUE, a read operation is performed.
896 If ReadWrite is FALSE, a write operation is performed. Offset specifies the
897 byte offset at which to start either operation. Offset must be a multiple of
898 NvRamAccessSize , and it must have a value between zero and NvRamSize.
899 BufferSize specifies the length of the read or write operation. BufferSize must
900 also be a multiple of NvRamAccessSize, and Offset + BufferSize must not exceed
901 NvRamSize.
902 If any of the above conditions is not met, then EFI_INVALID_PARAMETER will be
903 returned.
904 If all the conditions are met and the operation is "read," the NVRAM device
905 attached to the network interface will be read into Buffer and EFI_SUCCESS
906 will be returned. If this is a write operation, the contents of Buffer will be
907 used to update the contents of the NVRAM device attached to the network
908 interface and EFI_SUCCESS will be returned.
909
910 It does the basic checking on the input parameters and retrieves snp structure
911 and then calls the read_nvdata() call which does the actual reading
912
913 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
914 @param ReadWrite TRUE for read operations, FALSE for write operations.
915 @param Offset Byte offset in the NVRAM device at which to start the read or
916 write operation. This must be a multiple of NvRamAccessSize
917 and less than NvRamSize. (See EFI_SIMPLE_NETWORK_MODE)
918 @param BufferSize The number of bytes to read or write from the NVRAM device.
919 This must also be a multiple of NvramAccessSize.
920 @param Buffer A pointer to the data buffer.
921
922 @retval EFI_SUCCESS The NVRAM access was performed.
923 @retval EFI_NOT_STARTED The network interface has not been started.
924 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
925 * The This parameter is NULL
926 * The This parameter does not point to a valid
927 EFI_SIMPLE_NETWORK_PROTOCOL structure
928 * The Offset parameter is not a multiple of
929 EFI_SIMPLE_NETWORK_MODE.NvRamAccessSize
930 * The Offset parameter is not less than
931 EFI_SIMPLE_NETWORK_MODE.NvRamSize
932 * The BufferSize parameter is not a multiple of
933 EFI_SIMPLE_NETWORK_MODE.NvRamAccessSize
934 * The Buffer parameter is NULL
935 @retval EFI_DEVICE_ERROR The command could not be sent to the network
936 interface.
937 @retval EFI_UNSUPPORTED This function is not supported by the network
938 interface.
939
940 **/
941 EFI_STATUS
942 EFIAPI
943 SnpUndi32NvData (
944 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
945 IN BOOLEAN ReadWrite,
946 IN UINTN Offset,
947 IN UINTN BufferSize,
948 IN OUT VOID *Buffer
949 );
950
951 /**
952 Reads the current interrupt status and recycled transmit buffer status from a
953 network interface.
954
955 This function gets the current interrupt and recycled transmit buffer status
956 from the network interface. The interrupt status is returned as a bit mask in
957 InterruptStatus. If InterruptStatus is NULL, the interrupt status will not be
958 read. If TxBuf is not NULL, a recycled transmit buffer address will be retrieved.
959 If a recycled transmit buffer address is returned in TxBuf, then the buffer has
960 been successfully transmitted, and the status for that buffer is cleared. If
961 the status of the network interface is successfully collected, EFI_SUCCESS
962 will be returned. If the driver has not been initialized, EFI_DEVICE_ERROR will
963 be returned.
964
965 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
966 @param InterruptStatus A pointer to the bit mask of the currently active
967 interrupts (see "Related Definitions"). If this is NULL,
968 the interrupt status will not be read from the device.
969 If this is not NULL, the interrupt status will be read
970 from the device. When the interrupt status is read, it
971 will also be cleared. Clearing the transmit interrupt does
972 not empty the recycled transmit buffer array.
973 @param TxBuf Recycled transmit buffer address. The network interface
974 will not transmit if its internal recycled transmit
975 buffer array is full. Reading the transmit buffer does
976 not clear the transmit interrupt. If this is NULL, then
977 the transmit buffer status will not be read. If there
978 are no transmit buffers to recycle and TxBuf is not NULL,
979 TxBuf will be set to NULL.
980
981 @retval EFI_SUCCESS The status of the network interface was retrieved.
982 @retval EFI_NOT_STARTED The network interface has not been started.
983 @retval EFI_INVALID_PARAMETER This parameter was NULL or did not point to a valid
984 EFI_SIMPLE_NETWORK_PROTOCOL structure.
985 @retval EFI_DEVICE_ERROR The command could not be sent to the network
986 interface.
987
988 **/
989 EFI_STATUS
990 EFIAPI
991 SnpUndi32GetStatus (
992 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
993 OUT UINT32 *InterruptStatus, OPTIONAL
994 OUT VOID **TxBuf OPTIONAL
995 );
996
997 /**
998 Places a packet in the transmit queue of a network interface.
999
1000 This function places the packet specified by Header and Buffer on the transmit
1001 queue. If HeaderSize is nonzero and HeaderSize is not equal to
1002 This->Mode->MediaHeaderSize, then EFI_INVALID_PARAMETER will be returned. If
1003 BufferSize is less than This->Mode->MediaHeaderSize, then EFI_BUFFER_TOO_SMALL
1004 will be returned. If Buffer is NULL, then EFI_INVALID_PARAMETER will be
1005 returned. If HeaderSize is nonzero and DestAddr or Protocol is NULL, then
1006 EFI_INVALID_PARAMETER will be returned. If the transmit engine of the network
1007 interface is busy, then EFI_NOT_READY will be returned. If this packet can be
1008 accepted by the transmit engine of the network interface, the packet contents
1009 specified by Buffer will be placed on the transmit queue of the network
1010 interface, and EFI_SUCCESS will be returned. GetStatus() can be used to
1011 determine when the packet has actually been transmitted. The contents of the
1012 Buffer must not be modified until the packet has actually been transmitted.
1013 The Transmit() function performs nonblocking I/O. A caller who wants to perform
1014 blocking I/O, should call Transmit(), and then GetStatus() until the
1015 transmitted buffer shows up in the recycled transmit buffer.
1016 If the driver has not been initialized, EFI_DEVICE_ERROR will be returned.
1017
1018 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
1019 @param HeaderSize The size, in bytes, of the media header to be filled in by the
1020 Transmit() function. If HeaderSize is nonzero, then it must
1021 be equal to This->Mode->MediaHeaderSize and the DestAddr and
1022 Protocol parameters must not be NULL.
1023 @param BufferSize The size, in bytes, of the entire packet (media header and
1024 data) to be transmitted through the network interface.
1025 @param Buffer A pointer to the packet (media header followed by data) to be
1026 transmitted. This parameter cannot be NULL. If HeaderSize is
1027 zero, then the media header in Buffer must already be filled
1028 in by the caller. If HeaderSize is nonzero, then the media
1029 header will be filled in by the Transmit() function.
1030 @param SrcAddr The source HW MAC address. If HeaderSize is zero, then this
1031 parameter is ignored. If HeaderSize is nonzero and SrcAddr
1032 is NULL, then This->Mode->CurrentAddress is used for the
1033 source HW MAC address.
1034 @param DestAddr The destination HW MAC address. If HeaderSize is zero, then
1035 this parameter is ignored.
1036 @param Protocol The type of header to build. If HeaderSize is zero, then this
1037 parameter is ignored. See RFC 1700, section "Ether Types,"
1038 for examples.
1039
1040 @retval EFI_SUCCESS The packet was placed on the transmit queue.
1041 @retval EFI_NOT_STARTED The network interface has not been started.
1042 @retval EFI_NOT_READY The network interface is too busy to accept this
1043 transmit request.
1044 @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.
1045 @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported
1046 value.
1047 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
1048 @retval EFI_UNSUPPORTED This function is not supported by the network interface.
1049
1050 **/
1051 EFI_STATUS
1052 EFIAPI
1053 SnpUndi32Transmit (
1054 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
1055 IN UINTN HeaderSize,
1056 IN UINTN BufferSize,
1057 IN VOID *Buffer,
1058 IN EFI_MAC_ADDRESS *SrcAddr, OPTIONAL
1059 IN EFI_MAC_ADDRESS *DestAddr, OPTIONAL
1060 IN UINT16 *Protocol OPTIONAL
1061 );
1062
1063 /**
1064 Receives a packet from a network interface.
1065
1066 This function retrieves one packet from the receive queue of a network interface.
1067 If there are no packets on the receive queue, then EFI_NOT_READY will be
1068 returned. If there is a packet on the receive queue, and the size of the packet
1069 is smaller than BufferSize, then the contents of the packet will be placed in
1070 Buffer, and BufferSize will be updated with the actual size of the packet.
1071 In addition, if SrcAddr, DestAddr, and Protocol are not NULL, then these values
1072 will be extracted from the media header and returned. EFI_SUCCESS will be
1073 returned if a packet was successfully received.
1074 If BufferSize is smaller than the received packet, then the size of the receive
1075 packet will be placed in BufferSize and EFI_BUFFER_TOO_SMALL will be returned.
1076 If the driver has not been initialized, EFI_DEVICE_ERROR will be returned.
1077
1078 @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
1079 @param HeaderSize The size, in bytes, of the media header received on the network
1080 interface. If this parameter is NULL, then the media header size
1081 will not be returned.
1082 @param BufferSize On entry, the size, in bytes, of Buffer. On exit, the size, in
1083 bytes, of the packet that was received on the network interface.
1084 @param Buffer A pointer to the data buffer to receive both the media
1085 header and the data.
1086 @param SrcAddr The source HW MAC address. If this parameter is NULL, the HW
1087 MAC source address will not be extracted from the media header.
1088 @param DestAddr The destination HW MAC address. If this parameter is NULL,
1089 the HW MAC destination address will not be extracted from
1090 the media header.
1091 @param Protocol The media header type. If this parameter is NULL, then the
1092 protocol will not be extracted from the media header. See
1093 RFC 1700 section "Ether Types" for examples.
1094
1095 @retval EFI_SUCCESS The received data was stored in Buffer, and
1096 BufferSize has been updated to the number of
1097 bytes received.
1098 @retval EFI_NOT_STARTED The network interface has not been started.
1099 @retval EFI_NOT_READY No packets have been received on the network interface.
1100 @retval EFI_BUFFER_TOO_SMALL BufferSize is too small for the received packets.
1101 BufferSize has been updated to the required size.
1102 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
1103 * The This parameter is NULL
1104 * The This parameter does not point to a valid
1105 EFI_SIMPLE_NETWORK_PROTOCOL structure.
1106 * The BufferSize parameter is NULL
1107 * The Buffer parameter is NULL
1108 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
1109
1110 **/
1111 EFI_STATUS
1112 EFIAPI
1113 SnpUndi32Receive (
1114 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
1115 OUT UINTN *HeaderSize OPTIONAL,
1116 IN OUT UINTN *BufferSize,
1117 OUT VOID *Buffer,
1118 OUT EFI_MAC_ADDRESS *SrcAddr OPTIONAL,
1119 OUT EFI_MAC_ADDRESS *DestAddr OPTIONAL,
1120 OUT UINT16 *Protocol OPTIONAL
1121 );
1122
1123 /**
1124 Nofication call back function for WaitForPacket event.
1125
1126 @param Event EFI Event.
1127 @param SnpPtr Pointer to SNP_DRIVER structure.
1128
1129 **/
1130 VOID
1131 EFIAPI
1132 SnpWaitForPacketNotify (
1133 EFI_EVENT Event,
1134 VOID *SnpPtr
1135 );
1136
1137 #define SNP_MEM_PAGES(x) (((x) - 1) / 4096 + 1)
1138
1139
1140 #endif /* _SNP_H_ */