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