]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Nt32Pkg/SnpNt32Dxe/SnpNt32.c
UefiCpuPkg: Remove double \r
[mirror_edk2.git] / Nt32Pkg / SnpNt32Dxe / SnpNt32.c
index 67a3ac0038d8533d8605d389664db4686407690b..88c2e22badfab7414b9182d0b6e464bfd349e594 100644 (file)
@@ -1,13 +1,7 @@
 /** @file\r
 \r
-Copyright (c) 2006 - 2007, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 Module Name:\r
 \r
@@ -42,7 +36,7 @@ SNPNT32_GLOBAL_DATA         gSnpNt32GlobalData = {
   {\r
     0,\r
     0,\r
-    0\r
+    EfiLockUninitialized\r
   },                          //  Lock\r
   //\r
   //  Private functions\r
@@ -52,17 +46,420 @@ SNPNT32_GLOBAL_DATA         gSnpNt32GlobalData = {
   SnpNt32CloseInstance                    //  CloseInstance\r
 };\r
 \r
+/**\r
+  Changes the state of a network interface from "stopped" to "started".\r
+\r
+  @param  This Protocol instance pointer.\r
+\r
+  @retval EFI_SUCCESS           Always succeeds.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SnpNt32Start (\r
+  IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r
+  );\r
+  \r
+/**\r
+  Changes the state of a network interface from "started" to "stopped".\r
+\r
+  @param  This Protocol instance pointer.\r
+\r
+  @retval EFI_SUCCESS           Always succeeds.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SnpNt32Stop (\r
+  IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r
+  );\r
+  \r
+/**\r
+  Resets a network adapter and allocates the transmit and receive buffers \r
+  required by the network interface; optionally, also requests allocation \r
+  of additional transmit and receive buffers.\r
+\r
+  @param  This              Protocol instance pointer.\r
+  @param  ExtraRxBufferSize The size, in bytes, of the extra receive buffer space\r
+                            that the driver should allocate for the network interface.\r
+                            Some network interfaces will not be able to use the extra\r
+                            buffer, and the caller will not know if it is actually\r
+                            being used.\r
+  @param  ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space\r
+                            that the driver should allocate for the network interface.\r
+                            Some network interfaces will not be able to use the extra\r
+                            buffer, and the caller will not know if it is actually\r
+                            being used.\r
+\r
+  @retval EFI_SUCCESS           Always succeeds.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SnpNt32Initialize (\r
+  IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
+  IN UINTN                       ExtraRxBufferSize OPTIONAL,\r
+  IN UINTN                       ExtraTxBufferSize OPTIONAL\r
+  );\r
+  \r
+/**\r
+  Resets a network adapter and re-initializes it with the parameters that were \r
+  provided in the previous call to Initialize().  \r
+\r
+  @param  This                 Protocol instance pointer.\r
+  @param  ExtendedVerification Indicates that the driver may perform a more\r
+                               exhaustive verification operation of the device\r
+                               during reset.\r
+\r
+  @retval EFI_SUCCESS           Always succeeds.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SnpNt32Reset (\r
+  IN EFI_SIMPLE_NETWORK_PROTOCOL  *This,\r
+  IN BOOLEAN                      ExtendedVerification\r
+  );\r
+\r
+/**\r
+  Resets a network adapter and leaves it in a state that is safe for \r
+  another driver to initialize.\r
+\r
+  @param  This Protocol instance pointer.\r
+\r
+  @retval EFI_SUCCESS           Always succeeds.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SnpNt32Shutdown (\r
+  IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r
+  );\r
+\r
+/**\r
+  Manages the multicast receive filters of a network interface.\r
+\r
+  @param  This               Protocol instance pointer.\r
+  @param  EnableBits         A bit mask of receive filters to enable on the network interface.\r
+  @param  DisableBits        A bit mask of receive filters to disable on the network interface.\r
+  @param  ResetMcastFilter   Set to TRUE to reset the contents of the multicast receive\r
+                             filters on the network interface to their default values.\r
+  @param  McastFilterCount   Number of multicast HW MAC addresses in the new\r
+                             MCastFilter list. This value must be less than or equal to\r
+                             the MCastFilterCnt field of EFI_SIMPLE_NETWORK_MODE. This\r
+                             field is optional if ResetMCastFilter is TRUE.\r
+  @param  McastFilter        A pointer to a list of new multicast receive filter HW MAC\r
+                             addresses. This list will replace any existing multicast\r
+                             HW MAC address list. This field is optional if\r
+                             ResetMCastFilter is TRUE.\r
+\r
+  @retval EFI_SUCCESS           The multicast receive filter list was updated.\r
+  @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SnpNt32ReceiveFilters (\r
+  IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
+  IN UINT32                      EnableBits,\r
+  IN UINT32                      DisableBits,\r
+  IN BOOLEAN                     ResetMcastFilter,\r
+  IN UINTN                       McastFilterCount OPTIONAL,\r
+  IN EFI_MAC_ADDRESS             *McastFilter     OPTIONAL\r
+  );\r
+\r
+/**\r
+  Modifies or resets the current station address, if supported.\r
+\r
+  @param  This         Protocol instance pointer.\r
+  @param  Reset        Flag used to reset the station address to the network interfaces\r
+                       permanent address.\r
+  @param  NewMacAddr   New station address to be used for the network interface.\r
+\r
+  @retval EFI_UNSUPPORTED       Not supported yet.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SnpNt32StationAddress (\r
+  IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
+  IN BOOLEAN                     Reset,\r
+  IN EFI_MAC_ADDRESS             *NewMacAddr OPTIONAL\r
+  );\r
+\r
+/**\r
+  Resets or collects the statistics on a network interface.\r
+\r
+  @param  This            Protocol instance pointer.\r
+  @param  Reset           Set to TRUE to reset the statistics for the network interface.\r
+  @param  StatisticsSize  On input the size, in bytes, of StatisticsTable. On\r
+                          output the size, in bytes, of the resulting table of\r
+                          statistics.\r
+  @param  StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that\r
+                          contains the statistics.\r
+\r
+  @retval EFI_SUCCESS           The statistics were collected from the network interface.\r
+  @retval EFI_NOT_STARTED       The network interface has not been started.\r
+  @retval EFI_BUFFER_TOO_SMALL  The Statistics buffer was too small. The current buffer\r
+                                size needed to hold the statistics is returned in\r
+                                StatisticsSize.\r
+  @retval EFI_UNSUPPORTED       Not supported yet.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SnpNt32Statistics (\r
+  IN EFI_SIMPLE_NETWORK_PROTOCOL  * This,\r
+  IN BOOLEAN                      Reset,\r
+  IN OUT UINTN                    *StatisticsSize OPTIONAL,\r
+  OUT EFI_NETWORK_STATISTICS      *StatisticsTable OPTIONAL\r
+  );\r
+  \r
+/**\r
+  Converts a multicast IP address to a multicast HW MAC address.\r
+  \r
+  @param  This  Protocol instance pointer.\r
+  @param  Ipv6  Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set\r
+                to FALSE if the multicast IP address is IPv4 [RFC 791].\r
+  @param  Ip    The multicast IP address that is to be converted to a multicast\r
+                HW MAC address.\r
+  @param  Mac   The multicast HW MAC address that is to be generated from IP.\r
+\r
+  @retval EFI_SUCCESS           The multicast IP address was mapped to the multicast\r
+                                HW MAC address.\r
+  @retval EFI_NOT_STARTED       The network interface has not been started.\r
+  @retval EFI_BUFFER_TOO_SMALL  The Statistics buffer was too small. The current buffer\r
+                                size needed to hold the statistics is returned in\r
+                                StatisticsSize.\r
+  @retval EFI_UNSUPPORTED       Not supported yet.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SnpNt32McastIptoMac (\r
+  IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
+  IN BOOLEAN                     Ipv6,\r
+  IN EFI_IP_ADDRESS              *Ip,\r
+  OUT EFI_MAC_ADDRESS            *Mac\r
+  );\r
+\r
+/**\r
+  Performs read and write operations on the NVRAM device attached to a \r
+  network interface.\r
+\r
+  @param  This         Protocol instance pointer.\r
+  @param  ReadOrWrite  TRUE for read operations, FALSE for write operations.\r
+  @param  Offset       Byte offset in the NVRAM device at which to start the read or\r
+                       write operation. This must be a multiple of NvRamAccessSize and\r
+                       less than NvRamSize.\r
+  @param  BufferSize   The number of bytes to read or write from the NVRAM device.\r
+                       This must also be a multiple of NvramAccessSize.\r
+  @param  Buffer       A pointer to the data buffer.\r
+\r
+  @retval EFI_UNSUPPORTED       Not supported yet.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SnpNt32Nvdata (\r
+  IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
+  IN BOOLEAN                     ReadOrWrite,\r
+  IN UINTN                       Offset,\r
+  IN UINTN                       BufferSize,\r
+  IN OUT VOID                    *Buffer\r
+  );\r
+\r
+/**\r
+  Reads the current interrupt status and recycled transmit buffer status from \r
+  a network interface.\r
+\r
+  @param  This            Protocol instance pointer.\r
+  @param  InterruptStatus A pointer to the bit mask of the currently active interrupts\r
+                          If this is NULL, the interrupt status will not be read from\r
+                          the device. If this is not NULL, the interrupt status will\r
+                          be read from the device. When the  interrupt status is read,\r
+                          it will also be cleared. Clearing the transmit  interrupt\r
+                          does not empty the recycled transmit buffer array.\r
+  @param  TxBuffer        Recycled transmit buffer address. The network interface will\r
+                          not transmit if its internal recycled transmit buffer array\r
+                          is full. Reading the transmit buffer does not clear the\r
+                          transmit interrupt. If this is NULL, then the transmit buffer\r
+                          status will not be read. If there are no transmit buffers to\r
+                          recycle and TxBuf is not NULL, * TxBuf will be set to NULL.\r
+\r
+  @retval EFI_SUCCESS           Always succeeds.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SnpNt32GetStatus (\r
+  IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
+  OUT UINT32                     *InterruptStatus,\r
+  OUT VOID                       **TxBuffer\r
+  );\r
+\r
+/**\r
+  Places a packet in the transmit queue of a network interface.\r
+\r
+  @param  This       Protocol instance pointer.\r
+  @param  HeaderSize The size, in bytes, of the media header to be filled in by\r
+                     the Transmit() function. If HeaderSize is non-zero, then it\r
+                     must be equal to This->Mode->MediaHeaderSize and the DestAddr\r
+                     and Protocol parameters must not be NULL.\r
+  @param  BufferSize The size, in bytes, of the entire packet (media header and\r
+                     data) to be transmitted through the network interface.\r
+  @param  Buffer     A pointer to the packet (media header followed by data) to be\r
+                     transmitted. This parameter cannot be NULL. If HeaderSize is zero,\r
+                     then the media header in Buffer must already be filled in by the\r
+                     caller. If HeaderSize is non-zero, then the media header will be\r
+                     filled in by the Transmit() function.\r
+  @param  SrcAddr    The source HW MAC address. If HeaderSize is zero, then this parameter\r
+                     is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then\r
+                     This->Mode->CurrentAddress is used for the source HW MAC address.\r
+  @param  DestAddr   The destination HW MAC address. If HeaderSize is zero, then this\r
+                     parameter is ignored.\r
+  @param  Protocol   The type of header to build. If HeaderSize is zero, then this\r
+                     parameter is ignored. See RFC 1700, section "Ether Types", for\r
+                     examples.\r
+\r
+  @retval EFI_SUCCESS           The packet was placed on the transmit queue.\r
+  @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+  @retval EFI_ACCESS_DENIED     Error acquire global lock for operation.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SnpNt32Transmit (\r
+  IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
+  IN UINTN                       HeaderSize,\r
+  IN UINTN                       BufferSize,\r
+  IN VOID                        *Buffer,\r
+  IN EFI_MAC_ADDRESS             *SrcAddr OPTIONAL,\r
+  IN EFI_MAC_ADDRESS             *DestAddr OPTIONAL,\r
+  IN UINT16                      *Protocol OPTIONAL\r
+  );\r
+\r
+/**\r
+  Receives a packet from a network interface.\r
+\r
+  @param  This             Protocol instance pointer.\r
+  @param  HeaderSize       The size, in bytes, of the media header received on the network\r
+                           interface. If this parameter is NULL, then the media header size\r
+                           will not be returned.\r
+  @param  BuffSize         On entry, the size, in bytes, of Buffer. On exit, the size, in\r
+                           bytes, of the packet that was received on the network interface.\r
+  @param  Buffer           A pointer to the data buffer to receive both the media header and\r
+                           the data.\r
+  @param  SourceAddr       The source HW MAC address. If this parameter is NULL, the\r
+                           HW MAC source address will not be extracted from the media\r
+                           header.\r
+  @param  DestinationAddr  The destination HW MAC address. If this parameter is NULL,\r
+                           the HW MAC destination address will not be extracted from the\r
+                           media header.\r
+  @param  Protocol         The media header type. If this parameter is NULL, then the\r
+                           protocol will not be extracted from the media header. See\r
+                           RFC 1700 section "Ether Types" for examples.\r
+\r
+  @retval  EFI_SUCCESS           The received data was stored in Buffer, and BufferSize has\r
+                                 been updated to the number of bytes received.\r
+  @retval  EFI_NOT_READY         The network interface is too busy to accept this transmit\r
+                                 request.\r
+  @retval  EFI_BUFFER_TOO_SMALL  The BufferSize parameter is too small.\r
+  @retval  EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+  @retval  EFI_ACCESS_DENIED     Error acquire global lock for operation.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SnpNt32Receive (\r
+  IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
+  OUT UINTN                      *HeaderSize,\r
+  IN OUT UINTN                   *BuffSize,\r
+  OUT VOID                       *Buffer,\r
+  OUT EFI_MAC_ADDRESS            *SourceAddr,\r
+  OUT EFI_MAC_ADDRESS            *DestinationAddr,\r
+  OUT UINT16                     *Protocol\r
+  );\r
+\r
+SNPNT32_INSTANCE_DATA gSnpNt32InstanceTemplate = {\r
+  SNP_NT32_INSTANCE_SIGNATURE,            //  Signature\r
+  {\r
+    NULL,\r
+    NULL\r
+  },                                      //  Entry\r
+  NULL,                                   //  RecycledTxBuf\r
+  0,                                      //  RecycledTxBufCount\r
+  32,                                     //  MaxRecycledTxBuf\r
+  NULL,                                   //  GlobalData\r
+  NULL,                                   //  DeviceHandle\r
+  NULL,                                   //  DevicePath\r
+  {                                       //  Snp\r
+    EFI_SIMPLE_NETWORK_PROTOCOL_REVISION, //  Revision\r
+    SnpNt32Start,                         //  Start\r
+    SnpNt32Stop,                          //  Stop\r
+    SnpNt32Initialize,                    //  Initialize\r
+    SnpNt32Reset,                         //  Reset\r
+    SnpNt32Shutdown,                      //  Shutdown\r
+    SnpNt32ReceiveFilters,                //  ReceiveFilters\r
+    SnpNt32StationAddress,                //  StationAddress\r
+    SnpNt32Statistics,                    //  Statistics\r
+    SnpNt32McastIptoMac,                  //  MCastIpToMac\r
+    SnpNt32Nvdata,                        //  NvData\r
+    SnpNt32GetStatus,                     //  GetStatus\r
+    SnpNt32Transmit,                      //  Transmit\r
+    SnpNt32Receive,                       //  Receive\r
+    NULL,                                 //  WaitForPacket\r
+    NULL                                  //  Mode\r
+  },\r
+  {                                       //  Mode\r
+    EfiSimpleNetworkInitialized,          //  State\r
+    NET_ETHER_ADDR_LEN,                   //  HwAddressSize\r
+    NET_ETHER_HEADER_SIZE,                //  MediaHeaderSize\r
+    1500,                                 //  MaxPacketSize\r
+    0,                                    //  NvRamSize\r
+    0,                                    //  NvRamAccessSize\r
+    0,                                    //  ReceiveFilterMask\r
+    0,                                    //  ReceiveFilterSetting\r
+    MAX_MCAST_FILTER_CNT,                 //  MaxMCastFilterCount\r
+    0,                                    //  MCastFilterCount\r
+    {\r
+      0\r
+    },                                    //  MCastFilter\r
+    {\r
+      0\r
+    },                                    //  CurrentAddress\r
+    {\r
+      0\r
+    },                                    //  BroadcastAddress\r
+    {\r
+      0\r
+    },                                    //  PermanentAddress\r
+    NET_IFTYPE_ETHERNET,                  //  IfType\r
+    FALSE,                                //  MacAddressChangeable\r
+    FALSE,                                //  MultipleTxSupported\r
+    TRUE,                                 //  MediaPresentSupported\r
+    TRUE                                  //  MediaPresent\r
+  },\r
+  {\r
+    0\r
+  }                                       //  InterfaceInfo\r
+};\r
 \r
 /**\r
-  Test to see if this driver supports ControllerHandle.\r
+  Test to see if this driver supports ControllerHandle. This service\r
+  is called by the EFI boot service ConnectController(). In\r
+  order to make drivers as small as possible, there are a few calling\r
+  restrictions for this service. ConnectController() must\r
+  follow these calling restrictions. If any other agent wishes to call\r
+  Supported() it must also follow these calling restrictions.\r
 \r
-  @param  This                  Protocol instance pointer.\r
-  @param  ControllerHandle      Handle of device to test.\r
-  @param  RemainingDevicePath   Optional parameter use to pick a specific child\r
-                                device to start.\r
+  @param  This                Protocol instance pointer.\r
+  @param  ControllerHandle    Handle of device to test\r
+  @param  RemainingDevicePath Optional parameter use to pick a specific child\r
+                              device to start.\r
 \r
-  @retval EFI_SUCCES            This driver supports this device.\r
-  @retval other                 This driver does not support this device.\r
+  @retval EFI_SUCCESS         This driver supports this device\r
+  @retval EFI_UNSUPPORTED     This driver does not support this device\r
 \r
 **/\r
 EFI_STATUS\r
@@ -75,7 +472,7 @@ SnpNt32DriverBindingSupported (
 {\r
 \r
   SNPNT32_GLOBAL_DATA   *GlobalData;\r
-  NET_LIST_ENTRY        *Entry;\r
+  LIST_ENTRY            *Entry;\r
   SNPNT32_INSTANCE_DATA *Instance;\r
 \r
   GlobalData = &gSnpNt32GlobalData;\r
@@ -95,14 +492,19 @@ SnpNt32DriverBindingSupported (
 \r
 \r
 /**\r
-  Start this driver on ControllerHandle.\r
+  Start this driver on ControllerHandle. This service is called by the\r
+  EFI boot service ConnectController(). In order to make\r
+  drivers as small as possible, there are a few calling restrictions for\r
+  this service. ConnectController() must follow these\r
+  calling restrictions. If any other agent wishes to call Start() it\r
+  must also follow these calling restrictions.\r
 \r
-  @param  This                  Protocol instance pointer.\r
-  @param  ControllerHandle      Handle of device to bind driver to.\r
-  @param  RemainingDevicePath   Optional parameter use to pick a specific child\r
-                                device to start.\r
+  @param  This                 Protocol instance pointer.\r
+  @param  ControllerHandle     Handle of device to bind driver to\r
+  @param  RemainingDevicePath  Optional parameter use to pick a specific child\r
+                               device to start.\r
 \r
-  @retval EFI_SUCCES            This driver is added to ControllerHandle.\r
+  @retval EFI_SUCCESS          Always succeeds.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -116,17 +518,21 @@ SnpNt32DriverBindingStart (
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
 /**\r
-  Stop this driver on ControllerHandle.\r
-\r
-  @param  This                  Protocol instance pointer.\r
-  @param  ControllerHandle      Handle of device to stop driver on.\r
-  @param  NumberOfChildren      Number of Handles in ChildHandleBuffer. If number\r
-                                of children is zero stop the entire bus driver.\r
-  @param  ChildHandleBuffer     List of Child Handles to Stop.\r
-\r
-  @retval EFI_SUCCES            This driver is removed ControllerHandle.\r
+  Stop this driver on ControllerHandle. This service is called by the\r
+  EFI boot service DisconnectController(). In order to\r
+  make drivers as small as possible, there are a few calling\r
+  restrictions for this service. DisconnectController()\r
+  must follow these calling restrictions. If any other agent wishes\r
+  to call Stop() it must also follow these calling restrictions.\r
+  \r
+  @param  This              Protocol instance pointer.\r
+  @param  ControllerHandle  Handle of device to stop driver on\r
+  @param  NumberOfChildren  Number of Handles in ChildHandleBuffer. If number of\r
+                            children is zero stop the entire bus driver.\r
+  @param  ChildHandleBuffer List of Child Handles to Stop.\r
+\r
+  @retval EFI_SUCCESS       Always succeeds.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -138,20 +544,20 @@ SnpNt32DriverBindingStop (
   IN  EFI_HANDLE                   *ChildHandleBuffer\r
   )\r
 {\r
-\r
   return EFI_SUCCESS;\r
 }\r
 \r
 \r
 /**\r
-  Start the SnpNt32 interface.\r
+  Changes the state of a network interface from "stopped" to "started".\r
 \r
-  @param  This                  Context pointer.\r
+  @param  This Protocol instance pointer.\r
 \r
-  @retval EFI_SUCCESS           The interface is started.\r
+  @retval EFI_SUCCESS           Always succeeds.\r
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 SnpNt32Start (\r
   IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r
   )\r
@@ -161,14 +567,15 @@ SnpNt32Start (
 \r
 \r
 /**\r
-  Stop the SnpNt32 interface.\r
+  Changes the state of a network interface from "started" to "stopped".\r
 \r
-  @param  This                  Context pointer.\r
+  @param  This Protocol instance pointer.\r
 \r
-  @retval EFI_SUCCESS           The interface is stopped.\r
+  @retval EFI_SUCCESS           Always succeeds.\r
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 SnpNt32Stop (\r
   IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r
   )\r
@@ -176,18 +583,28 @@ SnpNt32Stop (
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
 /**\r
-  Initialize the SnpNt32 interface.\r
-\r
-  @param  This                  Context pointer.\r
-  @param  ExtraRxBufferSize     Number of extra receive buffer.\r
-  @param  ExtraTxBufferSize     Number of extra transmit buffer.\r
-\r
-  @retval EFI_SUCCESS           The interface is initialized.\r
+  Resets a network adapter and allocates the transmit and receive buffers \r
+  required by the network interface; optionally, also requests allocation \r
+  of additional transmit and receive buffers.\r
+\r
+  @param  This              Protocol instance pointer.\r
+  @param  ExtraRxBufferSize The size, in bytes, of the extra receive buffer space\r
+                            that the driver should allocate for the network interface.\r
+                            Some network interfaces will not be able to use the extra\r
+                            buffer, and the caller will not know if it is actually\r
+                            being used.\r
+  @param  ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space\r
+                            that the driver should allocate for the network interface.\r
+                            Some network interfaces will not be able to use the extra\r
+                            buffer, and the caller will not know if it is actually\r
+                            being used.\r
+\r
+  @retval EFI_SUCCESS           Always succeeds.\r
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 SnpNt32Initialize (\r
   IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
   IN UINTN                       ExtraRxBufferSize OPTIONAL,\r
@@ -197,17 +614,20 @@ SnpNt32Initialize (
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
 /**\r
-  Reset the snpnt32 interface.\r
+  Resets a network adapter and re-initializes it with the parameters that were \r
+  provided in the previous call to Initialize().  \r
 \r
-  @param  This                  Context pointer.\r
-  @param  ExtendedVerification  Not implemented.\r
+  @param  This                 Protocol instance pointer.\r
+  @param  ExtendedVerification Indicates that the driver may perform a more\r
+                               exhaustive verification operation of the device\r
+                               during reset.\r
 \r
-  @retval EFI_SUCCESS           The interface is reseted.\r
+  @retval EFI_SUCCESS           Always succeeds.\r
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 SnpNt32Reset (\r
   IN EFI_SIMPLE_NETWORK_PROTOCOL  *This,\r
   IN BOOLEAN                      ExtendedVerification\r
@@ -216,16 +636,17 @@ SnpNt32Reset (
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
 /**\r
-  Shut down the snpnt32 interface.\r
+  Resets a network adapter and leaves it in a state that is safe for \r
+  another driver to initialize.\r
 \r
-  @param  This                  Context pointer.\r
+  @param  This Protocol instance pointer.\r
 \r
-  @retval EFI_SUCCESS           The interface is shut down.\r
+  @retval EFI_SUCCESS           Always succeeds.\r
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 SnpNt32Shutdown (\r
   IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r
   )\r
@@ -233,31 +654,36 @@ SnpNt32Shutdown (
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
 /**\r
-  Change the interface's receive filter setting.\r
-\r
-  @param  This                  Context pointer.\r
-  @param  EnableBits            The receive filters to enable.\r
-  @param  DisableBits           The receive filters to disable\r
-  @param  ResetMcastFilter      Reset the multicast filters or not.\r
-  @param  McastFilterCount      The count of multicast filter to set.\r
-  @param  McastFilter           Pointer to the arrya of multicast addresses to set.\r
-\r
-  @retval EFI_SUCCESS           The receive filter is updated.\r
-  @retval EFI_ACCESS_DENIED     The snpnt32 lock is already owned by another\r
-                                routine.\r
-  @retval EFI_DEVICE_ERROR      Failed to update the receive filter.\r
+  Manages the multicast receive filters of a network interface.\r
+\r
+  @param  This               Protocol instance pointer.\r
+  @param  EnableBits         A bit mask of receive filters to enable on the network interface.\r
+  @param  DisableBits        A bit mask of receive filters to disable on the network interface.\r
+  @param  ResetMcastFilter   Set to TRUE to reset the contents of the multicast receive\r
+                             filters on the network interface to their default values.\r
+  @param  McastFilterCount   Number of multicast HW MAC addresses in the new\r
+                             MCastFilter list. This value must be less than or equal to\r
+                             the MCastFilterCnt field of EFI_SIMPLE_NETWORK_MODE. This\r
+                             field is optional if ResetMCastFilter is TRUE.\r
+  @param  McastFilter        A pointer to a list of new multicast receive filter HW MAC\r
+                             addresses. This list will replace any existing multicast\r
+                             HW MAC address list. This field is optional if\r
+                             ResetMCastFilter is TRUE.\r
+\r
+  @retval EFI_SUCCESS           The multicast receive filter list was updated.\r
+  @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 SnpNt32ReceiveFilters (\r
   IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
   IN UINT32                      EnableBits,\r
   IN UINT32                      DisableBits,\r
   IN BOOLEAN                     ResetMcastFilter,\r
   IN UINTN                       McastFilterCount OPTIONAL,\r
-  IN EFI_MAC_ADDRESS             *McastFilter OPTIONAL\r
+  IN EFI_MAC_ADDRESS             *McastFilter     OPTIONAL\r
   )\r
 {\r
   SNPNT32_INSTANCE_DATA *Instance;\r
@@ -268,18 +694,18 @@ SnpNt32ReceiveFilters (
 \r
   GlobalData  = Instance->GlobalData;\r
 \r
-  if (EFI_ERROR (NET_TRYLOCK (&GlobalData->Lock))) {\r
+  if (EFI_ERROR (EfiAcquireLockOrFail (&GlobalData->Lock))) {\r
     return EFI_ACCESS_DENIED;\r
   }\r
 \r
   ReturnValue = GlobalData->NtNetUtilityTable.SetReceiveFilter (\r
                                                 Instance->InterfaceInfo.InterfaceIndex,\r
                                                 EnableBits,\r
-                                                McastFilterCount,\r
+                                                (UINT32)McastFilterCount,\r
                                                 McastFilter\r
                                                 );\r
 \r
-  NET_UNLOCK (&GlobalData->Lock);\r
+  EfiReleaseLock (&GlobalData->Lock);\r
 \r
   if (ReturnValue <= 0) {\r
     return EFI_DEVICE_ERROR;\r
@@ -288,18 +714,19 @@ SnpNt32ReceiveFilters (
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
 /**\r
-  Change or reset the mac address of the interface.\r
+  Modifies or resets the current station address, if supported.\r
 \r
-  @param  This                  Context pointer.\r
-  @param  reset                 Reset the mac address to the original one or not.\r
-  @param  NewMacAddr            Pointer to the new mac address to set.\r
+  @param  This         Protocol instance pointer.\r
+  @param  Reset        Flag used to reset the station address to the network interfaces\r
+                       permanent address.\r
+  @param  NewMacAddr   New station address to be used for the network interface.\r
 \r
   @retval EFI_UNSUPPORTED       Not supported yet.\r
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 SnpNt32StationAddress (\r
   IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
   IN BOOLEAN                     Reset,\r
@@ -309,45 +736,58 @@ SnpNt32StationAddress (
   return EFI_UNSUPPORTED;\r
 }\r
 \r
-\r
 /**\r
-  Get or reset the statistics data.\r
-\r
-  @param  This                  Context pointer.\r
-  @param  Reset                 Reset the statistics or not.\r
-  @param  StatisticsSize        The size of the buffer used to receive the\r
-                                statistics data.\r
-  @param  StatisticsTable       Pointer to the table used to receive the statistics\r
-                                data.\r
-\r
+  Resets or collects the statistics on a network interface.\r
+\r
+  @param  This            Protocol instance pointer.\r
+  @param  Reset           Set to TRUE to reset the statistics for the network interface.\r
+  @param  StatisticsSize  On input the size, in bytes, of StatisticsTable. On\r
+                          output the size, in bytes, of the resulting table of\r
+                          statistics.\r
+  @param  StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that\r
+                          contains the statistics.\r
+\r
+  @retval EFI_SUCCESS           The statistics were collected from the network interface.\r
+  @retval EFI_NOT_STARTED       The network interface has not been started.\r
+  @retval EFI_BUFFER_TOO_SMALL  The Statistics buffer was too small. The current buffer\r
+                                size needed to hold the statistics is returned in\r
+                                StatisticsSize.\r
   @retval EFI_UNSUPPORTED       Not supported yet.\r
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 SnpNt32Statistics (\r
   IN EFI_SIMPLE_NETWORK_PROTOCOL  * This,\r
   IN BOOLEAN                      Reset,\r
   IN OUT UINTN                    *StatisticsSize OPTIONAL,\r
-  IN OUT EFI_NETWORK_STATISTICS   *StatisticsTable OPTIONAL\r
+  OUT EFI_NETWORK_STATISTICS      *StatisticsTable OPTIONAL\r
   )\r
 {\r
   return EFI_UNSUPPORTED;\r
 }\r
 \r
-\r
 /**\r
-  Convert a multicast ip address to the multicast mac address.\r
-\r
-  @param  This                  Context pointer.\r
-  @param  Ipv6                  The Ip is an Ipv6 address or not.\r
-  @param  Ip                    Pointer to the Ip address to convert.\r
-  @param  Mac                   Pointer to the buffer used to hold the converted\r
-                                mac address.\r
-\r
+  Converts a multicast IP address to a multicast HW MAC address.\r
+\r
+  @param  This Protocol instance pointer.\r
+  @param  Ipv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set\r
+               to FALSE if the multicast IP address is IPv4 [RFC 791].\r
+  @param  Ip   The multicast IP address that is to be converted to a multicast\r
+               HW MAC address.\r
+  @param  Mac  The multicast HW MAC address that is to be generated from IP.\r
+\r
+  @retval EFI_SUCCESS           The multicast IP address was mapped to the multicast\r
+                                HW MAC address.\r
+  @retval EFI_NOT_STARTED       The network interface has not been started.\r
+  @retval EFI_BUFFER_TOO_SMALL  The Statistics buffer was too small. The current buffer\r
+                                size needed to hold the statistics is returned in\r
+                                StatisticsSize.\r
   @retval EFI_UNSUPPORTED       Not supported yet.\r
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 SnpNt32McastIptoMac (\r
   IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
   IN BOOLEAN                     Ipv6,\r
@@ -360,19 +800,23 @@ SnpNt32McastIptoMac (
 \r
 \r
 /**\r
-  Read or write the nv data.\r
-\r
-  @param  This                  Context pinter.\r
-  @param  ReadOrWrite           Read or write the nv data.\r
-  @param  Offset                The offset to the start of the nv data.\r
-  @param  BufferSize            Size of the buffer.\r
-  @param  Buffer                Pointer to the buffer containing the data to write\r
-                                or used to receive the data read.\r
+  Performs read and write operations on the NVRAM device attached to a \r
+  network interface.\r
+\r
+  @param  This         Protocol instance pointer.\r
+  @param  ReadOrWrite  TRUE for read operations, FALSE for write operations.\r
+  @param  Offset       Byte offset in the NVRAM device at which to start the read or\r
+                       write operation. This must be a multiple of NvRamAccessSize and\r
+                       less than NvRamSize.\r
+  @param  BufferSize   The number of bytes to read or write from the NVRAM device.\r
+                       This must also be a multiple of NvramAccessSize.\r
+  @param  Buffer       A pointer to the data buffer.\r
 \r
   @retval EFI_UNSUPPORTED       Not supported yet.\r
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 SnpNt32Nvdata (\r
   IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
   IN BOOLEAN                     ReadOrWrite,\r
@@ -386,27 +830,45 @@ SnpNt32Nvdata (
 \r
 \r
 /**\r
-  Get the status information of the interface.\r
-\r
-  @param  This                  Context pointer.\r
-  @param  InterruptStatus       The storage to hold the interrupt status.\r
-  @param  TxBuffer              Pointer to get the list of pointers of previously\r
-                                transmitted buffers whose transmission was\r
-                                completed asynchrnously.\r
-\r
-  @retval EFI_SUCCESS           The status is got.\r
+  Reads the current interrupt status and recycled transmit buffer status from \r
+  a network interface.\r
+\r
+  @param  This            Protocol instance pointer.\r
+  @param  InterruptStatus A pointer to the bit mask of the currently active interrupts\r
+                          If this is NULL, the interrupt status will not be read from\r
+                          the device. If this is not NULL, the interrupt status will\r
+                          be read from the device. When the  interrupt status is read,\r
+                          it will also be cleared. Clearing the transmit  interrupt\r
+                          does not empty the recycled transmit buffer array.\r
+  @param  TxBuffer        Recycled transmit buffer address. The network interface will\r
+                          not transmit if its internal recycled transmit buffer array\r
+                          is full. Reading the transmit buffer does not clear the\r
+                          transmit interrupt. If this is NULL, then the transmit buffer\r
+                          status will not be read. If there are no transmit buffers to\r
+                          recycle and TxBuf is not NULL, * TxBuf will be set to NULL.\r
+\r
+  @retval EFI_SUCCESS           Always succeeds.\r
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 SnpNt32GetStatus (\r
   IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
   OUT UINT32                     *InterruptStatus,\r
   OUT VOID                       **TxBuffer\r
   )\r
 {\r
+  SNPNT32_INSTANCE_DATA *Instance;\r
+\r
+  Instance    = SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This);\r
 \r
   if (TxBuffer != NULL) {\r
-    *((UINT8 **) TxBuffer) = (UINT8 *) 1;\r
+    if (Instance->RecycledTxBufCount != 0) {\r
+      Instance->RecycledTxBufCount --;\r
+      *((UINT8 **) TxBuffer)    = (UINT8 *) (UINTN)Instance->RecycledTxBuf[Instance->RecycledTxBufCount];\r
+    } else {\r
+      *((UINT8 **) TxBuffer)    = NULL;\r
+    }\r
   }\r
 \r
   if (InterruptStatus != NULL) {\r
@@ -418,25 +880,36 @@ SnpNt32GetStatus (
 \r
 \r
 /**\r
-  Transmit a packet.\r
-\r
-  @param  This                  Context pointer.\r
-  @param  HeaderSize            The media header size contained in the packet\r
-                                buffer.\r
-  @param  BufferSize            The size of the packet buffer.\r
-  @param  Buffer                Pointer to the buffer containing the packet data.\r
-  @param  SrcAddr               If non null, points to the source address of this\r
-                                packet.\r
-  @param  DestAddr              If non null, points to the destination address of\r
-                                this packet.\r
-  @param  Protocol              The protocol type of this packet.\r
-\r
-  @retval EFI_SUCCESS           The packet is transmitted or put into the transmit\r
-                                queue.\r
-  @retval other                 Some error occurs.\r
+  Places a packet in the transmit queue of a network interface.\r
+\r
+  @param  This       Protocol instance pointer.\r
+  @param  HeaderSize The size, in bytes, of the media header to be filled in by\r
+                     the Transmit() function. If HeaderSize is non-zero, then it\r
+                     must be equal to This->Mode->MediaHeaderSize and the DestAddr\r
+                     and Protocol parameters must not be NULL.\r
+  @param  BufferSize The size, in bytes, of the entire packet (media header and\r
+                     data) to be transmitted through the network interface.\r
+  @param  Buffer     A pointer to the packet (media header followed by data) to be\r
+                     transmitted. This parameter cannot be NULL. If HeaderSize is zero,\r
+                     then the media header in Buffer must already be filled in by the\r
+                     caller. If HeaderSize is non-zero, then the media header will be\r
+                     filled in by the Transmit() function.\r
+  @param  SrcAddr    The source HW MAC address. If HeaderSize is zero, then this parameter\r
+                     is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then\r
+                     This->Mode->CurrentAddress is used for the source HW MAC address.\r
+  @param  DestAddr   The destination HW MAC address. If HeaderSize is zero, then this\r
+                     parameter is ignored.\r
+  @param  Protocol   The type of header to build. If HeaderSize is zero, then this\r
+                     parameter is ignored. See RFC 1700, section "Ether Types", for\r
+                     examples.\r
+\r
+  @retval EFI_SUCCESS           The packet was placed on the transmit queue.\r
+  @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+  @retval EFI_ACCESS_DENIED     Error acquire global lock for operation.\r
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 SnpNt32Transmit (\r
   IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
   IN UINTN                       HeaderSize,\r
@@ -450,6 +923,7 @@ SnpNt32Transmit (
   SNPNT32_INSTANCE_DATA *Instance;\r
   SNPNT32_GLOBAL_DATA   *GlobalData;\r
   INT32                 ReturnValue;\r
+  UINT64                *Tmp;\r
 \r
   Instance    = SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This);\r
 \r
@@ -459,53 +933,79 @@ SnpNt32Transmit (
     SrcAddr = &Instance->Mode.CurrentAddress;\r
   }\r
 \r
-  if (EFI_ERROR (NET_TRYLOCK (&GlobalData->Lock))) {\r
+  if (EFI_ERROR (EfiAcquireLockOrFail (&GlobalData->Lock))) {\r
     return EFI_ACCESS_DENIED;\r
   }\r
 \r
   ReturnValue = GlobalData->NtNetUtilityTable.Transmit (\r
                                                 Instance->InterfaceInfo.InterfaceIndex,\r
-                                                HeaderSize,\r
-                                                BufferSize,\r
+                                                (UINT32)HeaderSize,\r
+                                                (UINT32)BufferSize,\r
                                                 Buffer,\r
                                                 SrcAddr,\r
                                                 DestAddr,\r
                                                 Protocol\r
                                                 );\r
 \r
-  NET_UNLOCK (&GlobalData->Lock);\r
+  EfiReleaseLock (&GlobalData->Lock);\r
 \r
   if (ReturnValue < 0) {\r
     return EFI_DEVICE_ERROR;\r
+  } else {\r
+    if ((Instance->MaxRecycledTxBuf + SNP_TX_BUFFER_INCREASEMENT) >= SNP_MAX_TX_BUFFER_NUM) {\r
+      return EFI_NOT_READY;\r
+    }\r
+\r
+    if (Instance->RecycledTxBufCount < Instance->MaxRecycledTxBuf) {\r
+      Instance->RecycledTxBuf[Instance->RecycledTxBufCount] = (UINT64) Buffer;\r
+      Instance->RecycledTxBufCount ++;\r
+    } else {\r
+      Tmp = AllocatePool (sizeof (UINT64) * (Instance->MaxRecycledTxBuf + SNP_TX_BUFFER_INCREASEMENT));\r
+      if (Tmp == NULL) {\r
+        return EFI_DEVICE_ERROR;\r
+      }\r
+      CopyMem (Tmp, Instance->RecycledTxBuf, sizeof (UINT64) * Instance->RecycledTxBufCount);\r
+      FreePool (Instance->RecycledTxBuf);\r
+      Instance->RecycledTxBuf    =  Tmp;\r
+      Instance->MaxRecycledTxBuf += SNP_TX_BUFFER_INCREASEMENT;\r
+    }\r
   }\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
 /**\r
-  Receive network data.\r
-\r
-  @param  This                  Context pointer.\r
-  @param  HeaderSize            Optional parameter and is a pointer to the header\r
-                                portion of the data received.\r
-  @param  BuffSize              Pointer to the length of the Buffer on entry and\r
-                                contains the length of the received data on return\r
-  @param  Buffer                Pointer to the memory for the received data\r
-  @param  SourceAddr            Optional parameter, is a pointer to contain the\r
-                                source ethernet address on return\r
-  @param  DestinationAddr       Optional parameter, is a pointer to contain the\r
-                                destination ethernet address on return.\r
-  @param  Protocol              Optional parameter, is a pointer to contain the\r
-                                Protocol type from the ethernet header on return.\r
-\r
-  @retval EFI_SUCCESS           A packet is received and put into the buffer.\r
-  @retval EFI_BUFFER_TOO_SMALL  The provided buffer is too small to receive the\r
-                                packet.\r
-  @retval EFI_NOT_READY         There is no packet received.\r
+  Receives a packet from a network interface.\r
+\r
+  @param  This             Protocol instance pointer.\r
+  @param  HeaderSize       The size, in bytes, of the media header received on the network\r
+                           interface. If this parameter is NULL, then the media header size\r
+                           will not be returned.\r
+  @param  BuffSize         On entry, the size, in bytes, of Buffer. On exit, the size, in\r
+                           bytes, of the packet that was received on the network interface.\r
+  @param  Buffer           A pointer to the data buffer to receive both the media header and\r
+                           the data.\r
+  @param  SourceAddr       The source HW MAC address. If this parameter is NULL, the\r
+                           HW MAC source address will not be extracted from the media\r
+                           header.\r
+  @param  DestinationAddr  The destination HW MAC address. If this parameter is NULL,\r
+                           the HW MAC destination address will not be extracted from the\r
+                           media header.\r
+  @param  Protocol         The media header type. If this parameter is NULL, then the\r
+                           protocol will not be extracted from the media header. See\r
+                           RFC 1700 section "Ether Types" for examples.\r
+\r
+  @retval  EFI_SUCCESS           The received data was stored in Buffer, and BufferSize has\r
+                                 been updated to the number of bytes received.\r
+  @retval  EFI_NOT_READY         The network interface is too busy to accept this transmit\r
+                                 request.\r
+  @retval  EFI_BUFFER_TOO_SMALL  The BufferSize parameter is too small.\r
+  @retval  EFI_DEVICE_ERROR      The command could not be sent to the network interface.\r
+  @retval  EFI_ACCESS_DENIED     Error acquire global lock for operation.\r
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 SnpNt32Receive (\r
   IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
   OUT UINTN                      *HeaderSize,\r
@@ -519,6 +1019,9 @@ SnpNt32Receive (
   SNPNT32_INSTANCE_DATA *Instance;\r
   SNPNT32_GLOBAL_DATA   *GlobalData;\r
   INT32                 ReturnValue;\r
+  UINTN                 BufSize;\r
+  \r
+  BufSize     = *BuffSize;\r
 \r
   Instance    = SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This);\r
 \r
@@ -526,7 +1029,7 @@ SnpNt32Receive (
 \r
   ASSERT (GlobalData->NtNetUtilityTable.Receive != NULL);\r
 \r
-  if (EFI_ERROR (NET_TRYLOCK (&GlobalData->Lock))) {\r
+  if (EFI_ERROR (EfiAcquireLockOrFail (&GlobalData->Lock))) {\r
     return EFI_ACCESS_DENIED;\r
   }\r
 \r
@@ -536,7 +1039,7 @@ SnpNt32Receive (
                                                 Buffer\r
                                                 );\r
 \r
-  NET_UNLOCK (&GlobalData->Lock);\r
+  EfiReleaseLock (&GlobalData->Lock);\r
 \r
   if (ReturnValue < 0) {\r
     if (ReturnValue == -100) {\r
@@ -553,84 +1056,22 @@ SnpNt32Receive (
   }\r
 \r
   if (SourceAddr != NULL) {\r
-    NetZeroMem (SourceAddr, sizeof (EFI_MAC_ADDRESS));\r
-    NetCopyMem (SourceAddr, ((UINT8 *) Buffer) + 6, 6);\r
+    ZeroMem (SourceAddr, sizeof (EFI_MAC_ADDRESS));\r
+    CopyMem (SourceAddr, ((UINT8 *) Buffer) + 6, 6);\r
   }\r
 \r
   if (DestinationAddr != NULL) {\r
-    NetZeroMem (DestinationAddr, sizeof (EFI_MAC_ADDRESS));\r
-    NetCopyMem (DestinationAddr, ((UINT8 *) Buffer), 6);\r
+    ZeroMem (DestinationAddr, sizeof (EFI_MAC_ADDRESS));\r
+    CopyMem (DestinationAddr, ((UINT8 *) Buffer), 6);\r
   }\r
 \r
   if (Protocol != NULL) {\r
     *Protocol = NTOHS (*((UINT16 *) (((UINT8 *) Buffer) + 12)));\r
   }\r
 \r
-  return EFI_SUCCESS;\r
+  return (*BuffSize <= BufSize) ? EFI_SUCCESS : EFI_BUFFER_TOO_SMALL; \r
 }\r
 \r
-SNPNT32_INSTANCE_DATA gSnpNt32InstanceTemplate = {\r
-  SNP_NT32_INSTANCE_SIGNATURE,            //  Signature\r
-  {\r
-    NULL,\r
-    NULL\r
-  },                                      //  Entry\r
-  NULL,                                   //  GlobalData\r
-  NULL,                                   //  DeviceHandle\r
-  NULL,                                   //  DevicePath\r
-  {                                       //  Snp\r
-    EFI_SIMPLE_NETWORK_PROTOCOL_REVISION, //  Revision\r
-    SnpNt32Start,                         //  Start\r
-    SnpNt32Stop,                          //  Stop\r
-    SnpNt32Initialize,                    //  Initialize\r
-    SnpNt32Reset,                         //  Reset\r
-    SnpNt32Shutdown,                      //  Shutdown\r
-    SnpNt32ReceiveFilters,                //  ReceiveFilters\r
-    SnpNt32StationAddress,                //  StationAddress\r
-    SnpNt32Statistics,                    //  Statistics\r
-    SnpNt32McastIptoMac,                  //  MCastIpToMac\r
-    SnpNt32Nvdata,                        //  NvData\r
-    SnpNt32GetStatus,                     //  GetStatus\r
-    SnpNt32Transmit,                      //  Transmit\r
-    SnpNt32Receive,                       //  Receive\r
-    NULL,                                 //  WaitForPacket\r
-    NULL                                  //  Mode\r
-  },\r
-  {                                       //  Mode\r
-    EfiSimpleNetworkInitialized,          //  State\r
-    NET_ETHER_ADDR_LEN,                   //  HwAddressSize\r
-    NET_ETHER_HEADER_SIZE,                //  MediaHeaderSize\r
-    1500,                                 //  MaxPacketSize\r
-    0,                                    //  NvRamSize\r
-    0,                                    //  NvRamAccessSize\r
-    0,                                    //  ReceiveFilterMask\r
-    0,                                    //  ReceiveFilterSetting\r
-    MAX_MCAST_FILTER_CNT,                 //  MaxMCastFilterCount\r
-    0,                                    //  MCastFilterCount\r
-    {\r
-      0\r
-    },                                    //  MCastFilter\r
-    {\r
-      0\r
-    },                                    //  CurrentAddress\r
-    {\r
-      0\r
-    },                                    //  BroadcastAddress\r
-    {\r
-      0\r
-    },                                    //  PermanentAddress\r
-    NET_IFTYPE_ETHERNET,                  //  IfType\r
-    FALSE,                                //  MacAddressChangeable\r
-    FALSE,                                //  MultipleTxSupported\r
-    FALSE,                                //  MediaPresentSupported\r
-    TRUE                                  //  MediaPresent\r
-  },\r
-  {\r
-    0\r
-  }                                       //  InterfaceInfo\r
-};\r
-\r
-\r
 /**\r
   Initialize the driver's global data.\r
 \r
@@ -638,11 +1079,14 @@ SNPNT32_INSTANCE_DATA gSnpNt32InstanceTemplate = {
 \r
   @retval EFI_SUCCESS           The global data is initialized.\r
   @retval EFI_NOT_FOUND         The required DLL is not found.\r
+  @retval EFI_DEVICE_ERROR      Error initialize network utility library.\r
+  @retval EFI_OUT_OF_RESOURCES  Out of resource.\r
+  @retval other                 Other errors.\r
 \r
 **/\r
 EFI_STATUS\r
 SnpNt32InitializeGlobalData (\r
-  IN SNPNT32_GLOBAL_DATA *This\r
+  IN OUT SNPNT32_GLOBAL_DATA *This\r
   )\r
 {\r
   EFI_STATUS            Status;\r
@@ -652,7 +1096,7 @@ SnpNt32InitializeGlobalData (
   BOOLEAN               NetUtilityLibInitDone;\r
   NT_NET_INTERFACE_INFO NetInterfaceInfoBuffer[MAX_INTERFACE_INFO_NUMBER];\r
   SNPNT32_INSTANCE_DATA *Instance;\r
-  NET_LIST_ENTRY        *Entry;\r
+  LIST_ENTRY            *Entry;\r
   UINT32                InterfaceCount;\r
 \r
   ASSERT (This != NULL);\r
@@ -660,13 +1104,13 @@ SnpNt32InitializeGlobalData (
   NetUtilityLibInitDone = FALSE;\r
   InterfaceCount        = MAX_INTERFACE_INFO_NUMBER;\r
 \r
-  NetListInit (&This->InstanceList);\r
-  NET_LOCK_INIT (&This->Lock);\r
+  InitializeListHead (&This->InstanceList);\r
+  EfiInitializeLock (&This->Lock, TPL_CALLBACK);\r
 \r
   //\r
   //  Get the WinNT thunk\r
   //\r
-  Status = gBS->LocateProtocol (&gEfiWinNtThunkProtocolGuid, NULL, &This->WinNtThunk);\r
+  Status = gBS->LocateProtocol (&gEfiWinNtThunkProtocolGuid, NULL, (VOID **)&This->WinNtThunk);\r
 \r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
@@ -686,9 +1130,9 @@ SnpNt32InitializeGlobalData (
   }\r
 \r
   This->NtNetUtilityTable.Initialize = (NT_NET_INITIALIZE) This->WinNtThunk->GetProcAddress (\r
-                                                                              This->NetworkLibraryHandle,\r
-                                                                              NETWORK_LIBRARY_INITIALIZE\r
-                                                                              );\r
+                                                                               This->NetworkLibraryHandle,\r
+                                                                               NETWORK_LIBRARY_INITIALIZE\r
+                                                                               );\r
 \r
   if (NULL == This->NtNetUtilityTable.Initialize) {\r
     Status = EFI_NOT_FOUND;\r
@@ -696,9 +1140,9 @@ SnpNt32InitializeGlobalData (
   }\r
 \r
   This->NtNetUtilityTable.Finalize = (NT_NET_FINALIZE) This->WinNtThunk->GetProcAddress (\r
-                                                                          This->NetworkLibraryHandle,\r
-                                                                          NETWORK_LIBRARY_FINALIZE\r
-                                                                          );\r
+                                                                           This->NetworkLibraryHandle,\r
+                                                                           NETWORK_LIBRARY_FINALIZE\r
+                                                                           );\r
 \r
   if (NULL == This->NtNetUtilityTable.Finalize) {\r
     Status = EFI_NOT_FOUND;\r
@@ -706,9 +1150,9 @@ SnpNt32InitializeGlobalData (
   }\r
 \r
   This->NtNetUtilityTable.SetReceiveFilter = (NT_NET_SET_RECEIVE_FILTER) This->WinNtThunk->GetProcAddress (\r
-                                                                                            This->NetworkLibraryHandle,\r
-                                                                                            NETWORK_LIBRARY_SET_RCV_FILTER\r
-                                                                                            );\r
+                                                                                             This->NetworkLibraryHandle,\r
+                                                                                             NETWORK_LIBRARY_SET_RCV_FILTER\r
+                                                                                             );\r
 \r
   if (NULL == This->NtNetUtilityTable.SetReceiveFilter) {\r
     Status = EFI_NOT_FOUND;\r
@@ -716,9 +1160,9 @@ SnpNt32InitializeGlobalData (
   }\r
 \r
   This->NtNetUtilityTable.Receive = (NT_NET_RECEIVE) This->WinNtThunk->GetProcAddress (\r
-                                                                        This->NetworkLibraryHandle,\r
-                                                                        NETWORK_LIBRARY_RECEIVE\r
-                                                                        );\r
+                                                                         This->NetworkLibraryHandle,\r
+                                                                         NETWORK_LIBRARY_RECEIVE\r
+                                                                         );\r
 \r
   if (NULL == This->NtNetUtilityTable.Receive) {\r
     Status = EFI_NOT_FOUND;\r
@@ -726,9 +1170,9 @@ SnpNt32InitializeGlobalData (
   }\r
 \r
   This->NtNetUtilityTable.Transmit = (NT_NET_TRANSMIT) This->WinNtThunk->GetProcAddress (\r
-                                                                          This->NetworkLibraryHandle,\r
-                                                                          NETWORK_LIBRARY_TRANSMIT\r
-                                                                          );\r
+                                                                           This->NetworkLibraryHandle,\r
+                                                                           NETWORK_LIBRARY_TRANSMIT\r
+                                                                           );\r
 \r
   if (NULL == This->NtNetUtilityTable.Transmit) {\r
     Status = EFI_NOT_FOUND;\r
@@ -755,7 +1199,7 @@ SnpNt32InitializeGlobalData (
   //\r
   for (Index = 0; Index < InterfaceCount; Index++) {\r
 \r
-    Instance = NetAllocatePool (sizeof (SNPNT32_INSTANCE_DATA));\r
+    Instance = AllocateZeroPool (sizeof (SNPNT32_INSTANCE_DATA));\r
 \r
     if (NULL == Instance) {\r
       Status = EFI_OUT_OF_RESOURCES;\r
@@ -764,41 +1208,49 @@ SnpNt32InitializeGlobalData (
     //\r
     //  Copy the content from a template\r
     //\r
-    NetCopyMem (Instance, &gSnpNt32InstanceTemplate, sizeof (SNPNT32_INSTANCE_DATA));\r
+    CopyMem (Instance, &gSnpNt32InstanceTemplate, sizeof (SNPNT32_INSTANCE_DATA));\r
+\r
+    //\r
+    // Allocate the RecycledTxBuf.\r
+    //\r
+    Instance->RecycledTxBuf = AllocatePool (sizeof (UINT64) * Instance->MaxRecycledTxBuf);\r
+    if (Instance->RecycledTxBuf == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
 \r
     //\r
     //  Set the interface information.\r
     //\r
-    Instance->InterfaceInfo = NetInterfaceInfoBuffer[Index];\r
+    CopyMem (&Instance->InterfaceInfo, &NetInterfaceInfoBuffer[Index], sizeof(Instance->InterfaceInfo));\r
     //\r
     //  Initialize this instance\r
     //\r
     Status = This->InitializeInstanceData (This, Instance);\r
     if (EFI_ERROR (Status)) {\r
 \r
-      NetFreePool (Instance);\r
+      gBS->FreePool (Instance);\r
       goto ErrorReturn;\r
     }\r
     //\r
     //  Insert this instance into the instance list\r
     //\r
-    NetListInsertTail (&This->InstanceList, &Instance->Entry);\r
+    InsertTailList (&This->InstanceList, &Instance->Entry);\r
   }\r
 \r
   return EFI_SUCCESS;\r
 \r
 ErrorReturn:\r
 \r
-  while (!NetListIsEmpty (&This->InstanceList)) {\r
+  while (!IsListEmpty (&This->InstanceList)) {\r
 \r
     Entry     = This->InstanceList.ForwardLink;\r
 \r
     Instance  = NET_LIST_USER_STRUCT_S (Entry, SNPNT32_INSTANCE_DATA, Entry, SNP_NT32_INSTANCE_SIGNATURE);\r
 \r
-    NetListRemoveEntry (Entry);\r
+    RemoveEntryList (Entry);\r
 \r
     This->CloseInstance (This, Instance);\r
-    NetFreePool (Instance);\r
+    gBS->FreePool (Instance);\r
   }\r
 \r
   if (NetUtilityLibInitDone) {\r
@@ -822,12 +1274,13 @@ ErrorReturn:
   @param  Instance              Pointer to the instance context data.\r
 \r
   @retval EFI_SUCCESS           The driver instance is initialized.\r
+  @retval other                 Initialization errors.\r
 \r
 **/\r
 EFI_STATUS\r
 SnpNt32InitializeInstanceData (\r
-  IN SNPNT32_GLOBAL_DATA    *This,\r
-  IN SNPNT32_INSTANCE_DATA  *Instance\r
+  IN SNPNT32_GLOBAL_DATA        *This,\r
+  IN OUT SNPNT32_INSTANCE_DATA  *Instance\r
   )\r
 {\r
   EFI_STATUS    Status;\r
@@ -844,8 +1297,8 @@ SnpNt32InitializeInstanceData (
   //\r
   //  Copy Current/PermanentAddress MAC address\r
   //\r
-  Instance->Mode.CurrentAddress   = Instance->InterfaceInfo.MacAddr;\r
-  Instance->Mode.PermanentAddress = Instance->InterfaceInfo.MacAddr;\r
+  CopyMem (&Instance->Mode.CurrentAddress, &Instance->InterfaceInfo.MacAddr, sizeof(Instance->Mode.CurrentAddress));\r
+  CopyMem (&Instance->Mode.PermanentAddress, &Instance->InterfaceInfo.MacAddr, sizeof(Instance->Mode.PermanentAddress));\r
 \r
   //\r
   //  Since the fake SNP is based on a real NIC, to avoid conflict with the host\r
@@ -857,16 +1310,16 @@ SnpNt32InitializeInstanceData (
   //\r
   //  Create a fake device path for the instance\r
   //\r
-  NetZeroMem (&Node, sizeof (Node));\r
+  ZeroMem (&Node, sizeof (Node));\r
 \r
   Node.DevPath.Type     = MESSAGING_DEVICE_PATH;\r
   Node.DevPath.SubType  = MSG_MAC_ADDR_DP;\r
   SetDevicePathNodeLength (&Node.DevPath, sizeof (MAC_ADDR_DEVICE_PATH));\r
 \r
-  NetCopyMem (\r
+  CopyMem (\r
     &Node.MacAddr.MacAddress,\r
     &Instance->Mode.CurrentAddress,\r
-    sizeof (EFI_MAC_ADDRESS)\r
+    NET_ETHER_ADDR_LEN\r
     );\r
 \r
   Node.MacAddr.IfType = Instance->Mode.IfType;\r
@@ -874,9 +1327,9 @@ SnpNt32InitializeInstanceData (
   SetDevicePathEndNode (&EndNode.DevPath);\r
 \r
   Instance->DevicePath = AppendDevicePathNode (\r
-                          &EndNode.DevPath,\r
-                          &Node.DevPath\r
-                          );\r
+                           &EndNode.DevPath,\r
+                           &Node.DevPath\r
+                           );\r
 \r
   //\r
   //  Create a fake device handle for the fake SNP\r
@@ -889,13 +1342,6 @@ SnpNt32InitializeInstanceData (
                   Instance->DevicePath,\r
                   NULL\r
                   );\r
-  if (EFI_ERROR (Status)) {\r
-    goto ErrorReturn;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-\r
-ErrorReturn:\r
   return Status;\r
 }\r
 \r
@@ -911,21 +1357,21 @@ ErrorReturn:
 **/\r
 EFI_STATUS\r
 SnpNt32CloseInstance (\r
-  IN SNPNT32_GLOBAL_DATA    *This,\r
-  IN SNPNT32_INSTANCE_DATA  *Instance\r
+  IN SNPNT32_GLOBAL_DATA        *This,\r
+  IN OUT SNPNT32_INSTANCE_DATA  *Instance\r
   )\r
 {\r
   ASSERT (This != NULL);\r
   ASSERT (Instance != NULL);\r
 \r
   gBS->UninstallMultipleProtocolInterfaces (\r
-        Instance->DeviceHandle,\r
-        &gEfiSimpleNetworkProtocolGuid,\r
-        &Instance->Snp,\r
-        &gEfiDevicePathProtocolGuid,\r
-        Instance->DevicePath,\r
-        NULL\r
-        );\r
+         Instance->DeviceHandle,\r
+         &gEfiSimpleNetworkProtocolGuid,\r
+         &Instance->Snp,\r
+         &gEfiDevicePathProtocolGuid,\r
+         Instance->DevicePath,\r
+         NULL\r
+         );\r
 \r
   if (Instance->DevicePath != NULL) {\r
     gBS->FreePool (Instance->DevicePath);\r
@@ -934,14 +1380,13 @@ SnpNt32CloseInstance (
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
 /**\r
-  Unload the SnpNt32 driver.\r
+  Unloads an image.\r
 \r
-  @param  ImageHandle           The handle of the driver image.\r
+  @param  ImageHandle           Handle that identifies the image to be unloaded.\r
 \r
-  @retval EFI_SUCCESS           The driver is unloaded.\r
-  @retval other                 Some error occurs.\r
+  @retval EFI_SUCCESS           The image has been unloaded.\r
+  @return Exit code from the image's unload handler\r
 \r
 **/\r
 EFI_STATUS\r
@@ -952,7 +1397,7 @@ SnpNt32Unload (
 {\r
   EFI_STATUS            Status;\r
   SNPNT32_GLOBAL_DATA   *This;\r
-  NET_LIST_ENTRY        *Entry;\r
+  LIST_ENTRY            *Entry;\r
   SNPNT32_INSTANCE_DATA *Instance;\r
 \r
   This    = &gSnpNt32GlobalData;\r
@@ -963,7 +1408,7 @@ SnpNt32Unload (
     return Status;\r
   }\r
 \r
-  while (!NetListIsEmpty (&This->InstanceList)) {\r
+  while (!IsListEmpty (&This->InstanceList)) {\r
     //\r
     //  Walkthrough the interfaces and remove all the SNP instance\r
     //\r
@@ -971,10 +1416,10 @@ SnpNt32Unload (
 \r
     Instance  = NET_LIST_USER_STRUCT_S (Entry, SNPNT32_INSTANCE_DATA, Entry, SNP_NT32_INSTANCE_SIGNATURE);\r
 \r
-    NetListRemoveEntry (Entry);\r
+    RemoveEntryList (Entry);\r
 \r
     This->CloseInstance (This, Instance);\r
-    NetFreePool (Instance);\r
+    gBS->FreePool (Instance);\r
   }\r
 \r
   if (This->NtNetUtilityTable.Finalize != NULL) {\r
@@ -986,30 +1431,23 @@ SnpNt32Unload (
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  This is the declaration of an EFI image entry point. This entry point is\r
+  the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including\r
+  both device drivers and bus drivers.\r
 \r
+  @param  ImageHandle           The firmware allocated handle for the UEFI image.\r
+  @param  SystemTable           A pointer to the EFI System Table.\r
+\r
+  @retval EFI_SUCCESS           The operation completed successfully.\r
+  @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack of resources.\r
+\r
+**/\r
 EFI_STATUS\r
-InitializeSnpNt32river (\r
+InitializeSnpNt32Driver (\r
   IN EFI_HANDLE        ImageHandle,\r
   IN EFI_SYSTEM_TABLE  *SystemTable\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Install DriverBinding Protocol for the Win NT Bus driver on the drivers\r
-  image handle.\r
-\r
-Arguments:\r
-\r
-  ImageHandle - The handle of this image.\r
-  SystemTable - Pointer to the EFI system table.\r
-\r
-Returns:\r
-\r
-  EFI_SUCEESS -  The protocols are installed and the SnpNt32 is initialized.\r
-  other       -  Some error occurs.\r
-\r
---*/\r
 {\r
 \r
   EFI_STATUS  Status;\r
@@ -1018,16 +1456,14 @@ Returns:
   // Install the Driver Protocols\r
   //\r
 \r
-  Status = NetLibInstallAllDriverProtocolsWithUnload (\r
-            ImageHandle,\r
-            SystemTable,\r
-            &gSnpNt32DriverBinding,\r
-            ImageHandle,\r
-            &gSnpNt32DriverComponentName,\r
-            NULL,\r
-            NULL,\r
-            SnpNt32Unload\r
-            );\r
+  Status = EfiLibInstallDriverBindingComponentName2 (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gSnpNt32DriverBinding,\r
+             ImageHandle,\r
+             &gSnpNt32DriverComponentName,\r
+             &gSnpNt32DriverComponentName2\r
+             );\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r