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