--- /dev/null
+/** @file\r
+\r
+ Implementation of the SNP.Shutdown() 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
+\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
+\r
+**/\r
+\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+#include "VirtioNet.h"\r
+\r
+/**\r
+ Resets a network adapter and leaves it in a state that is safe for another\r
+ driver to initialize.\r
+\r
+ @param This Protocol instance pointer.\r
+\r
+ @retval EFI_SUCCESS The network interface was shutdown.\r
+ @retval EFI_NOT_STARTED The network interface has not been started.\r
+ @retval EFI_INVALID_PARAMETER One or more of the parameters has an\r
+ unsupported value.\r
+ @retval EFI_DEVICE_ERROR The command could not be sent to the network\r
+ interface.\r
+ @retval EFI_UNSUPPORTED This function is not supported by the network\r
+ interface.\r
+\r
+**/\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+VirtioNetShutdown (\r
+ IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r
+ )\r
+{\r
+ VNET_DEV *Dev;\r
+ EFI_TPL OldTpl;\r
+ EFI_STATUS Status;\r
+\r
+ if (This == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ Dev = VIRTIO_NET_FROM_SNP (This);\r
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+ switch (Dev->Snm.State) {\r
+ case EfiSimpleNetworkStopped:\r
+ Status = EFI_NOT_STARTED;\r
+ goto Exit;\r
+ case EfiSimpleNetworkStarted:\r
+ Status = EFI_DEVICE_ERROR;\r
+ goto Exit;\r
+ default:\r
+ break;\r
+ }\r
+\r
+ VIRTIO_CFG_WRITE (Dev, Generic.VhdrDeviceStatus, 0);\r
+ VirtioNetShutdownRx (Dev);\r
+ VirtioNetShutdownTx (Dev);\r
+ VirtioRingUninit (&Dev->TxRing);\r
+ VirtioRingUninit (&Dev->RxRing);\r
+\r
+ Dev->Snm.State = EfiSimpleNetworkStarted;\r
+ Status = EFI_SUCCESS;\r
+\r
+Exit:\r
+ gBS->RestoreTPL (OldTpl);\r
+ return Status;\r
+}\r