pm.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 netif up, hardware is alive, shut it down */
  65. if (ndev->flags & IFF_UP) {
  66. rc = wil_down(wil);
  67. if (rc) {
  68. wil_err(wil, "wil_down : %d\n", rc);
  69. goto out;
  70. }
  71. }
  72. if (wil->platform_ops.suspend)
  73. rc = wil->platform_ops.suspend(wil->platform_handle);
  74. out:
  75. wil_dbg_pm(wil, "suspend: %s => %d\n",
  76. is_runtime ? "runtime" : "system", rc);
  77. return rc;
  78. }
  79. int wil_resume(struct wil6210_priv *wil, bool is_runtime)
  80. {
  81. int rc = 0;
  82. struct net_device *ndev = wil_to_ndev(wil);
  83. wil_dbg_pm(wil, "resume: %s\n", is_runtime ? "runtime" : "system");
  84. if (wil->platform_ops.resume) {
  85. rc = wil->platform_ops.resume(wil->platform_handle);
  86. if (rc) {
  87. wil_err(wil, "platform_ops.resume : %d\n", rc);
  88. goto out;
  89. }
  90. }
  91. /* if netif up, bring hardware up
  92. * During open(), IFF_UP set after actual device method
  93. * invocation. This prevent recursive call to wil_up()
  94. */
  95. if (ndev->flags & IFF_UP)
  96. rc = wil_up(wil);
  97. out:
  98. wil_dbg_pm(wil, "resume: %s => %d\n",
  99. is_runtime ? "runtime" : "system", rc);
  100. return rc;
  101. }