pm.c 5.5 KB

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