pm.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. return err;
  67. } else if (err > 0) {
  68. WARN_ON(err != 1);
  69. local->wowlan = false;
  70. } else {
  71. list_for_each_entry(sdata, &local->interfaces, list) {
  72. cancel_work_sync(&sdata->work);
  73. ieee80211_quiesce(sdata);
  74. }
  75. goto suspend;
  76. }
  77. }
  78. /* disable keys */
  79. list_for_each_entry(sdata, &local->interfaces, list)
  80. ieee80211_disable_keys(sdata);
  81. /* tear down aggregation sessions and remove STAs */
  82. mutex_lock(&local->sta_mtx);
  83. list_for_each_entry(sta, &local->sta_list, list) {
  84. if (sta->uploaded) {
  85. enum ieee80211_sta_state state;
  86. state = sta->sta_state;
  87. for (; state > IEEE80211_STA_NOTEXIST; state--)
  88. WARN_ON(drv_sta_state(local, sta->sdata, sta,
  89. state, state - 1));
  90. }
  91. mesh_plink_quiesce(sta);
  92. }
  93. mutex_unlock(&local->sta_mtx);
  94. /* remove all interfaces */
  95. list_for_each_entry(sdata, &local->interfaces, list) {
  96. cancel_work_sync(&sdata->work);
  97. if (!ieee80211_quiesce(sdata))
  98. continue;
  99. if (!ieee80211_sdata_running(sdata))
  100. continue;
  101. /* disable beaconing */
  102. ieee80211_bss_info_change_notify(sdata,
  103. BSS_CHANGED_BEACON_ENABLED);
  104. drv_remove_interface(local, sdata);
  105. }
  106. /* stop hardware - this must stop RX */
  107. if (local->open_count)
  108. ieee80211_stop_device(local);
  109. suspend:
  110. local->suspended = true;
  111. /* need suspended to be visible before quiescing is false */
  112. barrier();
  113. local->quiescing = false;
  114. return 0;
  115. }
  116. /*
  117. * __ieee80211_resume() is a static inline which just calls
  118. * ieee80211_reconfig(), which is also needed for hardware
  119. * hang/firmware failure/etc. recovery.
  120. */