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