pm.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. struct ieee80211_chanctx *ctx;
  34. if (!local->open_count)
  35. goto suspend;
  36. ieee80211_scan_cancel(local);
  37. if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
  38. mutex_lock(&local->sta_mtx);
  39. list_for_each_entry(sta, &local->sta_list, list) {
  40. set_sta_flag(sta, WLAN_STA_BLOCK_BA);
  41. ieee80211_sta_tear_down_BA_sessions(sta, true);
  42. }
  43. mutex_unlock(&local->sta_mtx);
  44. }
  45. ieee80211_stop_queues_by_reason(hw,
  46. IEEE80211_QUEUE_STOP_REASON_SUSPEND);
  47. /* flush out all packets */
  48. synchronize_net();
  49. drv_flush(local, false);
  50. local->quiescing = true;
  51. /* make quiescing visible to timers everywhere */
  52. mb();
  53. flush_workqueue(local->workqueue);
  54. /* Don't try to run timers while suspended. */
  55. del_timer_sync(&local->sta_cleanup);
  56. /*
  57. * Note that this particular timer doesn't need to be
  58. * restarted at resume.
  59. */
  60. cancel_work_sync(&local->dynamic_ps_enable_work);
  61. del_timer_sync(&local->dynamic_ps_timer);
  62. local->wowlan = wowlan && local->open_count;
  63. if (local->wowlan) {
  64. int err = drv_suspend(local, wowlan);
  65. if (err < 0) {
  66. local->quiescing = false;
  67. local->wowlan = false;
  68. if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
  69. mutex_lock(&local->sta_mtx);
  70. list_for_each_entry(sta,
  71. &local->sta_list, list) {
  72. clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
  73. }
  74. mutex_unlock(&local->sta_mtx);
  75. }
  76. ieee80211_wake_queues_by_reason(hw,
  77. IEEE80211_QUEUE_STOP_REASON_SUSPEND);
  78. return err;
  79. } else if (err > 0) {
  80. WARN_ON(err != 1);
  81. local->wowlan = false;
  82. } else {
  83. list_for_each_entry(sdata, &local->interfaces, list) {
  84. cancel_work_sync(&sdata->work);
  85. ieee80211_quiesce(sdata);
  86. }
  87. goto suspend;
  88. }
  89. }
  90. /* disable keys */
  91. list_for_each_entry(sdata, &local->interfaces, list)
  92. ieee80211_disable_keys(sdata);
  93. /* tear down aggregation sessions and remove STAs */
  94. mutex_lock(&local->sta_mtx);
  95. list_for_each_entry(sta, &local->sta_list, list) {
  96. if (sta->uploaded) {
  97. enum ieee80211_sta_state state;
  98. state = sta->sta_state;
  99. for (; state > IEEE80211_STA_NOTEXIST; state--)
  100. WARN_ON(drv_sta_state(local, sta->sdata, sta,
  101. state, state - 1));
  102. }
  103. mesh_plink_quiesce(sta);
  104. }
  105. mutex_unlock(&local->sta_mtx);
  106. /* remove all interfaces */
  107. list_for_each_entry(sdata, &local->interfaces, list) {
  108. cancel_work_sync(&sdata->work);
  109. if (!ieee80211_quiesce(sdata))
  110. continue;
  111. if (!ieee80211_sdata_running(sdata))
  112. continue;
  113. /* disable beaconing */
  114. ieee80211_bss_info_change_notify(sdata,
  115. BSS_CHANGED_BEACON_ENABLED);
  116. if (sdata->vif.type == NL80211_IFTYPE_AP &&
  117. rcu_access_pointer(sdata->u.ap.beacon))
  118. drv_stop_ap(local, sdata);
  119. if (local->use_chanctx) {
  120. struct ieee80211_chanctx_conf *conf;
  121. mutex_lock(&local->chanctx_mtx);
  122. conf = rcu_dereference_protected(
  123. sdata->vif.chanctx_conf,
  124. lockdep_is_held(&local->chanctx_mtx));
  125. if (conf) {
  126. ctx = container_of(conf,
  127. struct ieee80211_chanctx,
  128. conf);
  129. drv_unassign_vif_chanctx(local, sdata, ctx);
  130. }
  131. mutex_unlock(&local->chanctx_mtx);
  132. }
  133. drv_remove_interface(local, sdata);
  134. }
  135. sdata = rtnl_dereference(local->monitor_sdata);
  136. if (sdata) {
  137. if (local->use_chanctx) {
  138. struct ieee80211_chanctx_conf *conf;
  139. mutex_lock(&local->chanctx_mtx);
  140. conf = rcu_dereference_protected(
  141. sdata->vif.chanctx_conf,
  142. lockdep_is_held(&local->chanctx_mtx));
  143. if (conf) {
  144. ctx = container_of(conf,
  145. struct ieee80211_chanctx,
  146. conf);
  147. drv_unassign_vif_chanctx(local, sdata, ctx);
  148. }
  149. mutex_unlock(&local->chanctx_mtx);
  150. }
  151. drv_remove_interface(local, sdata);
  152. }
  153. mutex_lock(&local->chanctx_mtx);
  154. list_for_each_entry(ctx, &local->chanctx_list, list)
  155. drv_remove_chanctx(local, ctx);
  156. mutex_unlock(&local->chanctx_mtx);
  157. /* stop hardware - this must stop RX */
  158. if (local->open_count)
  159. ieee80211_stop_device(local);
  160. suspend:
  161. local->suspended = true;
  162. /* need suspended to be visible before quiescing is false */
  163. barrier();
  164. local->quiescing = false;
  165. return 0;
  166. }
  167. /*
  168. * __ieee80211_resume() is a static inline which just calls
  169. * ieee80211_reconfig(), which is also needed for hardware
  170. * hang/firmware failure/etc. recovery.
  171. */