pm.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #include <net/mac80211.h>
  2. #include <net/rtnetlink.h>
  3. #include "ieee80211_i.h"
  4. #include "mesh.h"
  5. #include "driver-ops.h"
  6. #include "led.h"
  7. /* return value indicates whether the driver should be further notified */
  8. static bool ieee80211_quiesce(struct ieee80211_sub_if_data *sdata)
  9. {
  10. switch (sdata->vif.type) {
  11. case NL80211_IFTYPE_STATION:
  12. ieee80211_sta_quiesce(sdata);
  13. return true;
  14. case NL80211_IFTYPE_ADHOC:
  15. ieee80211_ibss_quiesce(sdata);
  16. return true;
  17. case NL80211_IFTYPE_MESH_POINT:
  18. ieee80211_mesh_quiesce(sdata);
  19. return true;
  20. case NL80211_IFTYPE_AP_VLAN:
  21. case NL80211_IFTYPE_MONITOR:
  22. /* don't tell driver about this */
  23. return false;
  24. default:
  25. return true;
  26. }
  27. }
  28. int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
  29. {
  30. struct ieee80211_local *local = hw_to_local(hw);
  31. struct ieee80211_sub_if_data *sdata;
  32. struct sta_info *sta;
  33. if (!local->open_count)
  34. goto suspend;
  35. ieee80211_scan_cancel(local);
  36. if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
  37. mutex_lock(&local->sta_mtx);
  38. list_for_each_entry(sta, &local->sta_list, list) {
  39. set_sta_flag(sta, WLAN_STA_BLOCK_BA);
  40. ieee80211_sta_tear_down_BA_sessions(sta, true);
  41. }
  42. mutex_unlock(&local->sta_mtx);
  43. }
  44. ieee80211_stop_queues_by_reason(hw,
  45. IEEE80211_QUEUE_STOP_REASON_SUSPEND);
  46. /* flush out all packets */
  47. synchronize_net();
  48. drv_flush(local, false);
  49. local->quiescing = true;
  50. /* make quiescing visible to timers everywhere */
  51. mb();
  52. flush_workqueue(local->workqueue);
  53. /* Don't try to run timers while suspended. */
  54. del_timer_sync(&local->sta_cleanup);
  55. /*
  56. * Note that this particular timer doesn't need to be
  57. * restarted at resume.
  58. */
  59. cancel_work_sync(&local->dynamic_ps_enable_work);
  60. del_timer_sync(&local->dynamic_ps_timer);
  61. local->wowlan = wowlan && local->open_count;
  62. if (local->wowlan) {
  63. int err = drv_suspend(local, wowlan);
  64. if (err < 0) {
  65. local->quiescing = false;
  66. local->wowlan = false;
  67. if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
  68. mutex_lock(&local->sta_mtx);
  69. list_for_each_entry(sta,
  70. &local->sta_list, list) {
  71. clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
  72. }
  73. mutex_unlock(&local->sta_mtx);
  74. }
  75. ieee80211_wake_queues_by_reason(hw,
  76. IEEE80211_QUEUE_STOP_REASON_SUSPEND);
  77. return err;
  78. } else if (err > 0) {
  79. WARN_ON(err != 1);
  80. local->wowlan = false;
  81. } else {
  82. list_for_each_entry(sdata, &local->interfaces, list) {
  83. cancel_work_sync(&sdata->work);
  84. ieee80211_quiesce(sdata);
  85. }
  86. goto suspend;
  87. }
  88. }
  89. /* disable keys */
  90. list_for_each_entry(sdata, &local->interfaces, list)
  91. ieee80211_disable_keys(sdata);
  92. /* tear down aggregation sessions and remove STAs */
  93. mutex_lock(&local->sta_mtx);
  94. list_for_each_entry(sta, &local->sta_list, list) {
  95. if (sta->uploaded) {
  96. enum ieee80211_sta_state state;
  97. state = sta->sta_state;
  98. for (; state > IEEE80211_STA_NOTEXIST; state--)
  99. WARN_ON(drv_sta_state(local, sta->sdata, sta,
  100. state, state - 1));
  101. }
  102. mesh_plink_quiesce(sta);
  103. }
  104. mutex_unlock(&local->sta_mtx);
  105. /* remove all interfaces */
  106. list_for_each_entry(sdata, &local->interfaces, list) {
  107. cancel_work_sync(&sdata->work);
  108. if (!ieee80211_quiesce(sdata))
  109. continue;
  110. if (!ieee80211_sdata_running(sdata))
  111. continue;
  112. /* disable beaconing */
  113. ieee80211_bss_info_change_notify(sdata,
  114. BSS_CHANGED_BEACON_ENABLED);
  115. drv_remove_interface(local, sdata);
  116. }
  117. sdata = rtnl_dereference(local->monitor_sdata);
  118. if (sdata)
  119. drv_remove_interface(local, sdata);
  120. /* stop hardware - this must stop RX */
  121. if (local->open_count)
  122. ieee80211_stop_device(local);
  123. suspend:
  124. local->suspended = true;
  125. /* need suspended to be visible before quiescing is false */
  126. barrier();
  127. local->quiescing = false;
  128. return 0;
  129. }
  130. /*
  131. * __ieee80211_resume() is a static inline which just calls
  132. * ieee80211_reconfig(), which is also needed for hardware
  133. * hang/firmware failure/etc. recovery.
  134. */