pm.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. ieee80211_dfs_cac_cancel(local);
  35. if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
  36. mutex_lock(&local->sta_mtx);
  37. list_for_each_entry(sta, &local->sta_list, list) {
  38. set_sta_flag(sta, WLAN_STA_BLOCK_BA);
  39. ieee80211_sta_tear_down_BA_sessions(
  40. sta, AGG_STOP_LOCAL_REQUEST);
  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. local->wowlan = false;
  67. if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
  68. mutex_lock(&local->sta_mtx);
  69. list_for_each_entry(sta,
  70. &local->sta_list, list) {
  71. clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
  72. }
  73. mutex_unlock(&local->sta_mtx);
  74. }
  75. ieee80211_wake_queues_by_reason(hw,
  76. IEEE80211_QUEUE_STOP_REASON_SUSPEND);
  77. return err;
  78. } else if (err > 0) {
  79. WARN_ON(err != 1);
  80. local->wowlan = false;
  81. } else {
  82. list_for_each_entry(sdata, &local->interfaces, list)
  83. if (ieee80211_sdata_running(sdata))
  84. ieee80211_quiesce(sdata);
  85. goto suspend;
  86. }
  87. }
  88. /* disable keys */
  89. list_for_each_entry(sdata, &local->interfaces, list)
  90. ieee80211_disable_keys(sdata);
  91. /* tear down aggregation sessions and remove STAs */
  92. mutex_lock(&local->sta_mtx);
  93. list_for_each_entry(sta, &local->sta_list, list) {
  94. if (sta->uploaded) {
  95. enum ieee80211_sta_state state;
  96. state = sta->sta_state;
  97. for (; state > IEEE80211_STA_NOTEXIST; state--)
  98. WARN_ON(drv_sta_state(local, sta->sdata, sta,
  99. state, state - 1));
  100. }
  101. mesh_plink_quiesce(sta);
  102. }
  103. mutex_unlock(&local->sta_mtx);
  104. /* remove all interfaces */
  105. list_for_each_entry(sdata, &local->interfaces, list) {
  106. static u8 zero_addr[ETH_ALEN] = {};
  107. u32 changed = 0;
  108. if (!ieee80211_sdata_running(sdata))
  109. continue;
  110. switch (sdata->vif.type) {
  111. case NL80211_IFTYPE_AP_VLAN:
  112. case NL80211_IFTYPE_MONITOR:
  113. /* skip these */
  114. continue;
  115. case NL80211_IFTYPE_STATION:
  116. if (sdata->vif.bss_conf.assoc)
  117. changed = BSS_CHANGED_ASSOC |
  118. BSS_CHANGED_BSSID |
  119. BSS_CHANGED_IDLE;
  120. break;
  121. case NL80211_IFTYPE_AP:
  122. case NL80211_IFTYPE_ADHOC:
  123. case NL80211_IFTYPE_MESH_POINT:
  124. if (sdata->vif.bss_conf.enable_beacon)
  125. changed = BSS_CHANGED_BEACON_ENABLED;
  126. break;
  127. default:
  128. break;
  129. }
  130. ieee80211_quiesce(sdata);
  131. sdata->suspend_bss_conf = sdata->vif.bss_conf;
  132. memset(&sdata->vif.bss_conf, 0, sizeof(sdata->vif.bss_conf));
  133. sdata->vif.bss_conf.idle = true;
  134. if (sdata->suspend_bss_conf.bssid)
  135. sdata->vif.bss_conf.bssid = zero_addr;
  136. /* disable beaconing or remove association */
  137. ieee80211_bss_info_change_notify(sdata, changed);
  138. if (sdata->vif.type == NL80211_IFTYPE_AP &&
  139. rcu_access_pointer(sdata->u.ap.beacon))
  140. drv_stop_ap(local, sdata);
  141. if (local->use_chanctx) {
  142. struct ieee80211_chanctx_conf *conf;
  143. mutex_lock(&local->chanctx_mtx);
  144. conf = rcu_dereference_protected(
  145. sdata->vif.chanctx_conf,
  146. lockdep_is_held(&local->chanctx_mtx));
  147. if (conf) {
  148. ctx = container_of(conf,
  149. struct ieee80211_chanctx,
  150. conf);
  151. drv_unassign_vif_chanctx(local, sdata, ctx);
  152. }
  153. mutex_unlock(&local->chanctx_mtx);
  154. }
  155. drv_remove_interface(local, sdata);
  156. }
  157. sdata = rtnl_dereference(local->monitor_sdata);
  158. if (sdata) {
  159. if (local->use_chanctx) {
  160. struct ieee80211_chanctx_conf *conf;
  161. mutex_lock(&local->chanctx_mtx);
  162. conf = rcu_dereference_protected(
  163. sdata->vif.chanctx_conf,
  164. lockdep_is_held(&local->chanctx_mtx));
  165. if (conf) {
  166. ctx = container_of(conf,
  167. struct ieee80211_chanctx,
  168. conf);
  169. drv_unassign_vif_chanctx(local, sdata, ctx);
  170. }
  171. mutex_unlock(&local->chanctx_mtx);
  172. }
  173. drv_remove_interface(local, sdata);
  174. }
  175. mutex_lock(&local->chanctx_mtx);
  176. list_for_each_entry(ctx, &local->chanctx_list, list)
  177. drv_remove_chanctx(local, ctx);
  178. mutex_unlock(&local->chanctx_mtx);
  179. /* stop hardware - this must stop RX */
  180. if (local->open_count)
  181. ieee80211_stop_device(local);
  182. suspend:
  183. local->suspended = true;
  184. /* need suspended to be visible before quiescing is false */
  185. barrier();
  186. local->quiescing = false;
  187. return 0;
  188. }
  189. /*
  190. * __ieee80211_resume() is a static inline which just calls
  191. * ieee80211_reconfig(), which is also needed for hardware
  192. * hang/firmware failure/etc. recovery.
  193. */
  194. void ieee80211_report_wowlan_wakeup(struct ieee80211_vif *vif,
  195. struct cfg80211_wowlan_wakeup *wakeup,
  196. gfp_t gfp)
  197. {
  198. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  199. cfg80211_report_wowlan_wakeup(&sdata->wdev, wakeup, gfp);
  200. }
  201. EXPORT_SYMBOL(ieee80211_report_wowlan_wakeup);