pm.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. ieee80211_scan_cancel(local);
  34. if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
  35. mutex_lock(&local->sta_mtx);
  36. list_for_each_entry(sta, &local->sta_list, list) {
  37. set_sta_flags(sta, WLAN_STA_BLOCK_BA);
  38. ieee80211_sta_tear_down_BA_sessions(sta, true);
  39. }
  40. mutex_unlock(&local->sta_mtx);
  41. }
  42. ieee80211_stop_queues_by_reason(hw,
  43. IEEE80211_QUEUE_STOP_REASON_SUSPEND);
  44. /* flush out all packets */
  45. synchronize_net();
  46. drv_flush(local, false);
  47. local->quiescing = true;
  48. /* make quiescing visible to timers everywhere */
  49. mb();
  50. flush_workqueue(local->workqueue);
  51. /* Don't try to run timers while suspended. */
  52. del_timer_sync(&local->sta_cleanup);
  53. /*
  54. * Note that this particular timer doesn't need to be
  55. * restarted at resume.
  56. */
  57. cancel_work_sync(&local->dynamic_ps_enable_work);
  58. del_timer_sync(&local->dynamic_ps_timer);
  59. local->wowlan = wowlan && local->open_count;
  60. if (local->wowlan) {
  61. int err = drv_suspend(local, wowlan);
  62. if (err < 0) {
  63. local->quiescing = false;
  64. return err;
  65. } else if (err > 0) {
  66. WARN_ON(err != 1);
  67. local->wowlan = false;
  68. } else {
  69. list_for_each_entry(sdata, &local->interfaces, list) {
  70. cancel_work_sync(&sdata->work);
  71. ieee80211_quiesce(sdata);
  72. }
  73. goto suspend;
  74. }
  75. }
  76. /* disable keys */
  77. list_for_each_entry(sdata, &local->interfaces, list)
  78. ieee80211_disable_keys(sdata);
  79. /* tear down aggregation sessions and remove STAs */
  80. mutex_lock(&local->sta_mtx);
  81. list_for_each_entry(sta, &local->sta_list, list) {
  82. if (sta->uploaded) {
  83. sdata = sta->sdata;
  84. if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  85. sdata = container_of(sdata->bss,
  86. struct ieee80211_sub_if_data,
  87. u.ap);
  88. drv_sta_remove(local, sdata, &sta->sta);
  89. }
  90. mesh_plink_quiesce(sta);
  91. }
  92. mutex_unlock(&local->sta_mtx);
  93. /* remove all interfaces */
  94. list_for_each_entry(sdata, &local->interfaces, list) {
  95. cancel_work_sync(&sdata->work);
  96. if (!ieee80211_quiesce(sdata))
  97. continue;
  98. if (!ieee80211_sdata_running(sdata))
  99. continue;
  100. /* disable beaconing */
  101. ieee80211_bss_info_change_notify(sdata,
  102. BSS_CHANGED_BEACON_ENABLED);
  103. drv_remove_interface(local, &sdata->vif);
  104. }
  105. /* stop hardware - this must stop RX */
  106. if (local->open_count)
  107. ieee80211_stop_device(local);
  108. suspend:
  109. local->suspended = true;
  110. /* need suspended to be visible before quiescing is false */
  111. barrier();
  112. local->quiescing = false;
  113. return 0;
  114. }
  115. /*
  116. * __ieee80211_resume() is a static inline which just calls
  117. * ieee80211_reconfig(), which is also needed for hardware
  118. * hang/firmware failure/etc. recovery.
  119. */