]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/VirtioNetDxe/SnpReceive.c
BaseTools: Add YAML files with path env and tool extdeps
[mirror_edk2.git] / OvmfPkg / VirtioNetDxe / SnpReceive.c
index eb3a2ba9b5ed4177da18d3af06116033e51a0df7..cdee9a2aee477f750b8015e245ca54420e59807f 100644 (file)
@@ -3,15 +3,9 @@
   Implementation of the SNP.Receive() function and its private helpers if any.\r
 \r
   Copyright (C) 2013, Red Hat, Inc.\r
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
 \r
-  This program and the accompanying materials are licensed and made available\r
-  under the terms and conditions of the BSD License which accompanies this\r
-  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, WITHOUT\r
-  WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -82,6 +76,7 @@ VirtioNetReceive (
   UINT8      *RxPtr;\r
   UINT16     AvailIdx;\r
   EFI_STATUS NotifyStatus;\r
+  UINTN      RxBufOffset;\r
 \r
   if (This == NULL || BufferSize == NULL || Buffer == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -105,6 +100,7 @@ VirtioNetReceive (
   //\r
   MemoryFence ();\r
   RxCurUsed = *Dev->RxRing.Used.Idx;\r
+  MemoryFence ();\r
 \r
   if (Dev->RxLastUsed == RxCurUsed) {\r
     Status = EFI_NOT_READY;\r
@@ -142,21 +138,23 @@ VirtioNetReceive (
     *HeaderSize = Dev->Snm.MediaHeaderSize;\r
   }\r
 \r
-  RxPtr = (UINT8 *)Dev->RxRing.Desc[DescIdx + 1].Addr;\r
+  RxBufOffset = (UINTN)(Dev->RxRing.Desc[DescIdx + 1].Addr -\r
+                        Dev->RxBufDeviceBase);\r
+  RxPtr = Dev->RxBuf + RxBufOffset;\r
   CopyMem (Buffer, RxPtr, RxLen);\r
 \r
   if (DestAddr != NULL) {\r
-    CopyMem (DestAddr, RxPtr, SIZE_OF_VNET (VhdrMac));\r
+    CopyMem (DestAddr, RxPtr, SIZE_OF_VNET (Mac));\r
   }\r
-  RxPtr += SIZE_OF_VNET (VhdrMac);\r
+  RxPtr += SIZE_OF_VNET (Mac);\r
 \r
   if (SrcAddr != NULL) {\r
-    CopyMem (SrcAddr, RxPtr, SIZE_OF_VNET (VhdrMac));\r
+    CopyMem (SrcAddr, RxPtr, SIZE_OF_VNET (Mac));\r
   }\r
-  RxPtr += SIZE_OF_VNET (VhdrMac);\r
+  RxPtr += SIZE_OF_VNET (Mac);\r
 \r
   if (Protocol != NULL) {\r
-    *Protocol = ((UINT16) RxPtr[0] << 8) | RxPtr[1];\r
+    *Protocol = (UINT16) ((RxPtr[0] << 8) | RxPtr[1]);\r
   }\r
   RxPtr += sizeof (UINT16);\r
 \r
@@ -169,15 +167,14 @@ RecycleDesc:
   // virtio-0.9.5, 2.4.1 Supplying Buffers to The Device\r
   //\r
   AvailIdx = *Dev->RxRing.Avail.Idx;\r
-  Dev->RxRing.Avail.Ring[AvailIdx++ % Dev->RxRing.QueueSize] = DescIdx;\r
+  Dev->RxRing.Avail.Ring[AvailIdx++ % Dev->RxRing.QueueSize] =\r
+    (UINT16) DescIdx;\r
 \r
   MemoryFence ();\r
   *Dev->RxRing.Avail.Idx = AvailIdx;\r
 \r
   MemoryFence ();\r
-  NotifyStatus = VIRTIO_CFG_WRITE (Dev, Generic.VhdrQueueNotify,\r
-                   VIRTIO_NET_Q_RX);\r
-\r
+  NotifyStatus = Dev->VirtIo->SetQueueNotify (Dev->VirtIo, VIRTIO_NET_Q_RX);\r
   if (!EFI_ERROR (Status)) { // earlier error takes precedence\r
     Status = NotifyStatus;\r
   }\r