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