pm.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 void 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. break;
  14. case NL80211_IFTYPE_ADHOC:
  15. ieee80211_ibss_quiesce(sdata);
  16. break;
  17. case NL80211_IFTYPE_MESH_POINT:
  18. ieee80211_mesh_quiesce(sdata);
  19. break;
  20. default:
  21. break;
  22. }
  23. cancel_work_sync(&sdata->work);
  24. }
  25. int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
  26. {
  27. struct ieee80211_local *local = hw_to_local(hw);
  28. struct ieee80211_sub_if_data *sdata;
  29. struct sta_info *sta;
  30. struct ieee80211_chanctx *ctx;
  31. if (!local->open_count)
  32. goto suspend;
  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_flag(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. local->wowlan = false;
  65. if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
  66. mutex_lock(&local->sta_mtx);
  67. list_for_each_entry(sta,
  68. &local->sta_list, list) {
  69. clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
  70. }
  71. mutex_unlock(&local->sta_mtx);
  72. }
  73. ieee80211_wake_queues_by_reason(hw,
  74. IEEE80211_QUEUE_STOP_REASON_SUSPEND);
  75. return err;
  76. } else if (err > 0) {
  77. WARN_ON(err != 1);
  78. local->wowlan = false;
  79. } else {
  80. list_for_each_entry(sdata, &local->interfaces, list)
  81. if (ieee80211_sdata_running(sdata))
  82. ieee80211_quiesce(sdata);
  83. goto suspend;
  84. }
  85. }
  86. /* disable keys */
  87. list_for_each_entry(sdata, &local->interfaces, list)
  88. ieee80211_disable_keys(sdata);
  89. /* tear down aggregation sessions and remove STAs */
  90. mutex_lock(&local->sta_mtx);
  91. list_for_each_entry(sta, &local->sta_list, list) {
  92. if (sta->uploaded) {
  93. enum ieee80211_sta_state state;
  94. state = sta->sta_state;
  95. for (; state > IEEE80211_STA_NOTEXIST; state--)
  96. WARN_ON(drv_sta_state(local, sta->sdata, sta,
  97. state, state - 1));
  98. }
  99. mesh_plink_quiesce(sta);
  100. }
  101. mutex_unlock(&local->sta_mtx);
  102. /* remove all interfaces */
  103. list_for_each_entry(sdata, &local->interfaces, list) {
  104. u32 changed = BSS_CHANGED_BEACON_ENABLED;
  105. if (!ieee80211_sdata_running(sdata))
  106. continue;
  107. switch (sdata->vif.type) {
  108. case NL80211_IFTYPE_AP_VLAN:
  109. case NL80211_IFTYPE_MONITOR:
  110. /* skip these */
  111. continue;
  112. case NL80211_IFTYPE_STATION:
  113. if (sdata->vif.bss_conf.assoc)
  114. changed = BSS_CHANGED_ASSOC |
  115. BSS_CHANGED_BSSID |
  116. BSS_CHANGED_IDLE;
  117. else
  118. changed = 0;
  119. /* fall through */
  120. default:
  121. ieee80211_quiesce(sdata);
  122. break;
  123. }
  124. sdata->suspend_bss_conf = sdata->vif.bss_conf;
  125. memset(&sdata->vif.bss_conf, 0, sizeof(sdata->vif.bss_conf));
  126. sdata->vif.bss_conf.idle = true;
  127. /* disable beaconing or remove association */
  128. ieee80211_bss_info_change_notify(sdata, changed);
  129. if (sdata->vif.type == NL80211_IFTYPE_AP &&
  130. rcu_access_pointer(sdata->u.ap.beacon))
  131. drv_stop_ap(local, sdata);
  132. if (local->use_chanctx) {
  133. struct ieee80211_chanctx_conf *conf;
  134. mutex_lock(&local->chanctx_mtx);
  135. conf = rcu_dereference_protected(
  136. sdata->vif.chanctx_conf,
  137. lockdep_is_held(&local->chanctx_mtx));
  138. if (conf) {
  139. ctx = container_of(conf,
  140. struct ieee80211_chanctx,
  141. conf);
  142. drv_unassign_vif_chanctx(local, sdata, ctx);
  143. }
  144. mutex_unlock(&local->chanctx_mtx);
  145. }
  146. drv_remove_interface(local, sdata);
  147. }
  148. sdata = rtnl_dereference(local->monitor_sdata);
  149. if (sdata) {
  150. if (local->use_chanctx) {
  151. struct ieee80211_chanctx_conf *conf;
  152. mutex_lock(&local->chanctx_mtx);
  153. conf = rcu_dereference_protected(
  154. sdata->vif.chanctx_conf,
  155. lockdep_is_held(&local->chanctx_mtx));
  156. if (conf) {
  157. ctx = container_of(conf,
  158. struct ieee80211_chanctx,
  159. conf);
  160. drv_unassign_vif_chanctx(local, sdata, ctx);
  161. }
  162. mutex_unlock(&local->chanctx_mtx);
  163. }
  164. drv_remove_interface(local, sdata);
  165. }
  166. mutex_lock(&local->chanctx_mtx);
  167. list_for_each_entry(ctx, &local->chanctx_list, list)
  168. drv_remove_chanctx(local, ctx);
  169. mutex_unlock(&local->chanctx_mtx);
  170. /* stop hardware - this must stop RX */
  171. if (local->open_count)
  172. ieee80211_stop_device(local);
  173. suspend:
  174. local->suspended = true;
  175. /* need suspended to be visible before quiescing is false */
  176. barrier();
  177. local->quiescing = false;
  178. return 0;
  179. }
  180. /*
  181. * __ieee80211_resume() is a static inline which just calls
  182. * ieee80211_reconfig(), which is also needed for hardware
  183. * hang/firmware failure/etc. recovery.
  184. */