SnpShutdown.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /** @file
  2. Implementation of the SNP.Shutdown() function and its private helpers if any.
  3. Copyright (C) 2013, Red Hat, Inc.
  4. Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
  5. Copyright (c) 2017, AMD Inc, All rights reserved.<BR>
  6. SPDX-License-Identifier: BSD-2-Clause-Patent
  7. **/
  8. #include <Library/UefiBootServicesTableLib.h>
  9. #include "VirtioNet.h"
  10. /**
  11. Resets a network adapter and leaves it in a state that is safe for another
  12. driver to initialize.
  13. @param This Protocol instance pointer.
  14. @retval EFI_SUCCESS The network interface was shutdown.
  15. @retval EFI_NOT_STARTED The network interface has not been started.
  16. @retval EFI_INVALID_PARAMETER One or more of the parameters has an
  17. unsupported value.
  18. @retval EFI_DEVICE_ERROR The command could not be sent to the network
  19. interface.
  20. @retval EFI_UNSUPPORTED This function is not supported by the network
  21. interface.
  22. **/
  23. EFI_STATUS
  24. EFIAPI
  25. VirtioNetShutdown (
  26. IN EFI_SIMPLE_NETWORK_PROTOCOL *This
  27. )
  28. {
  29. VNET_DEV *Dev;
  30. EFI_TPL OldTpl;
  31. EFI_STATUS Status;
  32. if (This == NULL) {
  33. return EFI_INVALID_PARAMETER;
  34. }
  35. Dev = VIRTIO_NET_FROM_SNP (This);
  36. OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
  37. switch (Dev->Snm.State) {
  38. case EfiSimpleNetworkStopped:
  39. Status = EFI_NOT_STARTED;
  40. goto Exit;
  41. case EfiSimpleNetworkStarted:
  42. Status = EFI_DEVICE_ERROR;
  43. goto Exit;
  44. default:
  45. break;
  46. }
  47. Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0);
  48. VirtioNetShutdownRx (Dev);
  49. VirtioNetShutdownTx (Dev);
  50. VirtioNetUninitRing (Dev, &Dev->TxRing, Dev->TxRingMap);
  51. VirtioNetUninitRing (Dev, &Dev->RxRing, Dev->RxRingMap);
  52. Dev->Snm.State = EfiSimpleNetworkStarted;
  53. Status = EFI_SUCCESS;
  54. Exit:
  55. gBS->RestoreTPL (OldTpl);
  56. return Status;
  57. }