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