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