pm.c 5.6 KB

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