]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/VirtioNetDxe/SnpGetStatus.c
OvmfPkg/VirtioNetDxe: map caller-supplied Tx packet to device-address
[mirror_edk2.git] / OvmfPkg / VirtioNetDxe / SnpGetStatus.c
index adb57cf8fe5cdd43f8bd4fbd151702ba9eccb11d..9b1c352227b3953834f0edc5a53da45e96de6595 100644 (file)
@@ -4,7 +4,7 @@
   any.\r
 \r
   Copyright (C) 2013, Red Hat, Inc.\r
-  Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2014, 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
@@ -61,11 +61,12 @@ VirtioNetGetStatus (
   OUT VOID                       **TxBuf OPTIONAL\r
   )\r
 {\r
-  VNET_DEV   *Dev;\r
-  EFI_TPL    OldTpl;\r
-  EFI_STATUS Status;\r
-  UINT16     RxCurUsed;\r
-  UINT16     TxCurUsed;\r
+  VNET_DEV             *Dev;\r
+  EFI_TPL              OldTpl;\r
+  EFI_STATUS           Status;\r
+  UINT16               RxCurUsed;\r
+  UINT16               TxCurUsed;\r
+  EFI_PHYSICAL_ADDRESS DeviceAddress;\r
 \r
   if (This == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -90,11 +91,12 @@ VirtioNetGetStatus (
   if (Dev->Snm.MediaPresentSupported) {\r
     UINT16 LinkStatus;\r
 \r
-    Status = VIRTIO_CFG_READ (Dev, VhdrLinkStatus, &LinkStatus);\r
+    Status = VIRTIO_CFG_READ (Dev, LinkStatus, &LinkStatus);\r
     if (EFI_ERROR (Status)) {\r
       goto Exit;\r
     }\r
-    Dev->Snm.MediaPresent = !!(LinkStatus & VIRTIO_NET_S_LINK_UP);\r
+    Dev->Snm.MediaPresent =\r
+      (BOOLEAN) ((LinkStatus & VIRTIO_NET_S_LINK_UP) != 0);\r
   }\r
 \r
   //\r
@@ -140,14 +142,34 @@ VirtioNetGetStatus (
       ASSERT (DescIdx < (UINT32) (2 * Dev->TxMaxPending - 1));\r
 \r
       //\r
-      // report buffer address to caller that has been enqueued by caller\r
+      // get the device address that has been enqueued for the caller's\r
+      // transmit buffer\r
       //\r
-      *TxBuf = (VOID *)(UINTN) Dev->TxRing.Desc[DescIdx + 1].Addr;\r
+      DeviceAddress = Dev->TxRing.Desc[DescIdx + 1].Addr;\r
 \r
       //\r
       // now this descriptor can be used again to enqueue a transmit buffer\r
       //\r
       Dev->TxFreeStack[--Dev->TxCurPending] = (UINT16) DescIdx;\r
+\r
+      //\r
+      // Unmap the device address and perform the reverse mapping to find the\r
+      // caller buffer address.\r
+      //\r
+      Status = VirtioNetUnmapTxBuf (\r
+                 Dev,\r
+                 TxBuf,\r
+                 DeviceAddress\r
+                 );\r
+      if (EFI_ERROR (Status)) {\r
+        //\r
+        // VirtioNetUnmapTxBuf should never fail, if we have reached here\r
+        // that means our internal state has been corrupted\r
+        //\r
+        ASSERT (FALSE);\r
+        Status = EFI_DEVICE_ERROR;\r
+        goto Exit;\r
+      }\r
     }\r
   }\r
 \r