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