pm.c 5.3 KB

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