pm.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright (c) 2014,2017 Qualcomm Atheros, Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "wil6210.h"
  17. int wil_can_suspend(struct wil6210_priv *wil, bool is_runtime)
  18. {
  19. int rc = 0;
  20. struct wireless_dev *wdev = wil->wdev;
  21. wil_dbg_pm(wil, "can_suspend: %s\n", is_runtime ? "runtime" : "system");
  22. if (!netif_running(wil_to_ndev(wil))) {
  23. /* can always sleep when down */
  24. wil_dbg_pm(wil, "Interface is down\n");
  25. goto out;
  26. }
  27. if (test_bit(wil_status_resetting, wil->status)) {
  28. wil_dbg_pm(wil, "Delay suspend when resetting\n");
  29. rc = -EBUSY;
  30. goto out;
  31. }
  32. if (wil->recovery_state != fw_recovery_idle) {
  33. wil_dbg_pm(wil, "Delay suspend during recovery\n");
  34. rc = -EBUSY;
  35. goto out;
  36. }
  37. /* interface is running */
  38. switch (wdev->iftype) {
  39. case NL80211_IFTYPE_MONITOR:
  40. case NL80211_IFTYPE_STATION:
  41. case NL80211_IFTYPE_P2P_CLIENT:
  42. if (test_bit(wil_status_fwconnecting, wil->status)) {
  43. wil_dbg_pm(wil, "Delay suspend when connecting\n");
  44. rc = -EBUSY;
  45. goto out;
  46. }
  47. break;
  48. /* AP-like interface - can't suspend */
  49. default:
  50. wil_dbg_pm(wil, "AP-like interface\n");
  51. rc = -EBUSY;
  52. break;
  53. }
  54. out:
  55. wil_dbg_pm(wil, "can_suspend: %s => %s (%d)\n",
  56. is_runtime ? "runtime" : "system", rc ? "No" : "Yes", rc);
  57. return rc;
  58. }
  59. int wil_suspend(struct wil6210_priv *wil, bool is_runtime)
  60. {
  61. int rc = 0;
  62. struct net_device *ndev = wil_to_ndev(wil);
  63. wil_dbg_pm(wil, "suspend: %s\n", is_runtime ? "runtime" : "system");
  64. if (test_bit(wil_status_suspended, wil->status)) {
  65. wil_dbg_pm(wil, "trying to suspend while suspended\n");
  66. return 0;
  67. }
  68. /* if netif up, hardware is alive, shut it down */
  69. if (ndev->flags & IFF_UP) {
  70. rc = wil_down(wil);
  71. if (rc) {
  72. wil_err(wil, "wil_down : %d\n", rc);
  73. goto out;
  74. }
  75. }
  76. /* Disable PCIe IRQ to prevent sporadic IRQs when PCIe is suspending */
  77. wil_dbg_pm(wil, "Disabling PCIe IRQ before suspending\n");
  78. wil_disable_irq(wil);
  79. if (wil->platform_ops.suspend) {
  80. rc = wil->platform_ops.suspend(wil->platform_handle);
  81. if (rc) {
  82. wil_enable_irq(wil);
  83. goto out;
  84. }
  85. }
  86. set_bit(wil_status_suspended, wil->status);
  87. out:
  88. wil_dbg_pm(wil, "suspend: %s => %d\n",
  89. is_runtime ? "runtime" : "system", rc);
  90. return rc;
  91. }
  92. int wil_resume(struct wil6210_priv *wil, bool is_runtime)
  93. {
  94. int rc = 0;
  95. struct net_device *ndev = wil_to_ndev(wil);
  96. wil_dbg_pm(wil, "resume: %s\n", is_runtime ? "runtime" : "system");
  97. if (wil->platform_ops.resume) {
  98. rc = wil->platform_ops.resume(wil->platform_handle);
  99. if (rc) {
  100. wil_err(wil, "platform_ops.resume : %d\n", rc);
  101. goto out;
  102. }
  103. }
  104. wil_dbg_pm(wil, "Enabling PCIe IRQ\n");
  105. wil_enable_irq(wil);
  106. /* if netif up, bring hardware up
  107. * During open(), IFF_UP set after actual device method
  108. * invocation. This prevent recursive call to wil_up().
  109. * wil_status_suspended will be cleared in wil_reset
  110. */
  111. if (ndev->flags & IFF_UP)
  112. rc = wil_up(wil);
  113. else
  114. clear_bit(wil_status_suspended, wil->status);
  115. out:
  116. wil_dbg_pm(wil, "resume: %s => %d\n",
  117. is_runtime ? "runtime" : "system", rc);
  118. return rc;
  119. }