pm.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <net/mac80211.h>
  3. #include <net/rtnetlink.h>
  4. #include "ieee80211_i.h"
  5. #include "mesh.h"
  6. #include "driver-ops.h"
  7. #include "led.h"
  8. static void ieee80211_sched_scan_cancel(struct ieee80211_local *local)
  9. {
  10. if (ieee80211_request_sched_scan_stop(local))
  11. return;
  12. cfg80211_sched_scan_stopped_rtnl(local->hw.wiphy, 0);
  13. }
  14. int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
  15. {
  16. struct ieee80211_local *local = hw_to_local(hw);
  17. struct ieee80211_sub_if_data *sdata;
  18. struct sta_info *sta;
  19. if (!local->open_count)
  20. goto suspend;
  21. ieee80211_scan_cancel(local);
  22. ieee80211_dfs_cac_cancel(local);
  23. ieee80211_roc_purge(local, NULL);
  24. ieee80211_del_virtual_monitor(local);
  25. if (ieee80211_hw_check(hw, AMPDU_AGGREGATION) &&
  26. !(wowlan && wowlan->any)) {
  27. mutex_lock(&local->sta_mtx);
  28. list_for_each_entry(sta, &local->sta_list, list) {
  29. set_sta_flag(sta, WLAN_STA_BLOCK_BA);
  30. ieee80211_sta_tear_down_BA_sessions(
  31. sta, AGG_STOP_LOCAL_REQUEST);
  32. }
  33. mutex_unlock(&local->sta_mtx);
  34. }
  35. /* keep sched_scan only in case of 'any' trigger */
  36. if (!(wowlan && wowlan->any))
  37. ieee80211_sched_scan_cancel(local);
  38. ieee80211_stop_queues_by_reason(hw,
  39. IEEE80211_MAX_QUEUE_MAP,
  40. IEEE80211_QUEUE_STOP_REASON_SUSPEND,
  41. false);
  42. /* flush out all packets */
  43. synchronize_net();
  44. ieee80211_flush_queues(local, NULL, true);
  45. local->quiescing = true;
  46. /* make quiescing visible to timers everywhere */
  47. mb();
  48. flush_workqueue(local->workqueue);
  49. /* Don't try to run timers while suspended. */
  50. del_timer_sync(&local->sta_cleanup);
  51. /*
  52. * Note that this particular timer doesn't need to be
  53. * restarted at resume.
  54. */
  55. cancel_work_sync(&local->dynamic_ps_enable_work);
  56. del_timer_sync(&local->dynamic_ps_timer);
  57. local->wowlan = wowlan;
  58. if (local->wowlan) {
  59. int err;
  60. /* Drivers don't expect to suspend while some operations like
  61. * authenticating or associating are in progress. It doesn't
  62. * make sense anyway to accept that, since the authentication
  63. * or association would never finish since the driver can't do
  64. * that on its own.
  65. * Thus, clean up in-progress auth/assoc first.
  66. */
  67. list_for_each_entry(sdata, &local->interfaces, list) {
  68. if (!ieee80211_sdata_running(sdata))
  69. continue;
  70. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  71. continue;
  72. ieee80211_mgd_quiesce(sdata);
  73. /* If suspended during TX in progress, and wowlan
  74. * is enabled (connection will be active) there
  75. * can be a race where the driver is put out
  76. * of power-save due to TX and during suspend
  77. * dynamic_ps_timer is cancelled and TX packet
  78. * is flushed, leaving the driver in ACTIVE even
  79. * after resuming until dynamic_ps_timer puts
  80. * driver back in DOZE.
  81. */
  82. if (sdata->u.mgd.associated &&
  83. sdata->u.mgd.powersave &&
  84. !(local->hw.conf.flags & IEEE80211_CONF_PS)) {
  85. local->hw.conf.flags |= IEEE80211_CONF_PS;
  86. ieee80211_hw_config(local,
  87. IEEE80211_CONF_CHANGE_PS);
  88. }
  89. }
  90. err = drv_suspend(local, wowlan);
  91. if (err < 0) {
  92. local->quiescing = false;
  93. local->wowlan = false;
  94. if (ieee80211_hw_check(hw, AMPDU_AGGREGATION)) {
  95. mutex_lock(&local->sta_mtx);
  96. list_for_each_entry(sta,
  97. &local->sta_list, list) {
  98. clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
  99. }
  100. mutex_unlock(&local->sta_mtx);
  101. }
  102. ieee80211_wake_queues_by_reason(hw,
  103. IEEE80211_MAX_QUEUE_MAP,
  104. IEEE80211_QUEUE_STOP_REASON_SUSPEND,
  105. false);
  106. return err;
  107. } else if (err > 0) {
  108. WARN_ON(err != 1);
  109. /* cfg80211 will call back into mac80211 to disconnect
  110. * all interfaces, allow that to proceed properly
  111. */
  112. ieee80211_wake_queues_by_reason(hw,
  113. IEEE80211_MAX_QUEUE_MAP,
  114. IEEE80211_QUEUE_STOP_REASON_SUSPEND,
  115. false);
  116. return err;
  117. } else {
  118. goto suspend;
  119. }
  120. }
  121. /* remove all interfaces that were created in the driver */
  122. list_for_each_entry(sdata, &local->interfaces, list) {
  123. if (!ieee80211_sdata_running(sdata))
  124. continue;
  125. switch (sdata->vif.type) {
  126. case NL80211_IFTYPE_AP_VLAN:
  127. case NL80211_IFTYPE_MONITOR:
  128. continue;
  129. case NL80211_IFTYPE_STATION:
  130. ieee80211_mgd_quiesce(sdata);
  131. break;
  132. case NL80211_IFTYPE_WDS:
  133. /* tear down aggregation sessions and remove STAs */
  134. mutex_lock(&local->sta_mtx);
  135. sta = sdata->u.wds.sta;
  136. if (sta && sta->uploaded) {
  137. enum ieee80211_sta_state state;
  138. state = sta->sta_state;
  139. for (; state > IEEE80211_STA_NOTEXIST; state--)
  140. WARN_ON(drv_sta_state(local, sta->sdata,
  141. sta, state,
  142. state - 1));
  143. }
  144. mutex_unlock(&local->sta_mtx);
  145. break;
  146. default:
  147. break;
  148. }
  149. flush_delayed_work(&sdata->dec_tailroom_needed_wk);
  150. drv_remove_interface(local, sdata);
  151. }
  152. /*
  153. * We disconnected on all interfaces before suspend, all channel
  154. * contexts should be released.
  155. */
  156. WARN_ON(!list_empty(&local->chanctx_list));
  157. /* stop hardware - this must stop RX */
  158. ieee80211_stop_device(local);
  159. suspend:
  160. local->suspended = true;
  161. /* need suspended to be visible before quiescing is false */
  162. barrier();
  163. local->quiescing = false;
  164. return 0;
  165. }
  166. /*
  167. * __ieee80211_resume() is a static inline which just calls
  168. * ieee80211_reconfig(), which is also needed for hardware
  169. * hang/firmware failure/etc. recovery.
  170. */
  171. void ieee80211_report_wowlan_wakeup(struct ieee80211_vif *vif,
  172. struct cfg80211_wowlan_wakeup *wakeup,
  173. gfp_t gfp)
  174. {
  175. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  176. cfg80211_report_wowlan_wakeup(&sdata->wdev, wakeup, gfp);
  177. }
  178. EXPORT_SYMBOL(ieee80211_report_wowlan_wakeup);