pm.c 5.2 KB

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