pm.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
  8. {
  9. struct ieee80211_local *local = hw_to_local(hw);
  10. struct ieee80211_sub_if_data *sdata;
  11. struct sta_info *sta;
  12. if (!local->open_count)
  13. goto suspend;
  14. ieee80211_scan_cancel(local);
  15. ieee80211_dfs_cac_cancel(local);
  16. ieee80211_roc_purge(local, NULL);
  17. ieee80211_del_virtual_monitor(local);
  18. if (ieee80211_hw_check(hw, AMPDU_AGGREGATION)) {
  19. mutex_lock(&local->sta_mtx);
  20. list_for_each_entry(sta, &local->sta_list, list) {
  21. set_sta_flag(sta, WLAN_STA_BLOCK_BA);
  22. ieee80211_sta_tear_down_BA_sessions(
  23. sta, AGG_STOP_LOCAL_REQUEST);
  24. }
  25. mutex_unlock(&local->sta_mtx);
  26. }
  27. ieee80211_stop_queues_by_reason(hw,
  28. IEEE80211_MAX_QUEUE_MAP,
  29. IEEE80211_QUEUE_STOP_REASON_SUSPEND,
  30. false);
  31. /* flush out all packets */
  32. synchronize_net();
  33. ieee80211_flush_queues(local, NULL, true);
  34. local->quiescing = true;
  35. /* make quiescing visible to timers everywhere */
  36. mb();
  37. flush_workqueue(local->workqueue);
  38. /* Don't try to run timers while suspended. */
  39. del_timer_sync(&local->sta_cleanup);
  40. /*
  41. * Note that this particular timer doesn't need to be
  42. * restarted at resume.
  43. */
  44. cancel_work_sync(&local->dynamic_ps_enable_work);
  45. del_timer_sync(&local->dynamic_ps_timer);
  46. local->wowlan = wowlan;
  47. if (local->wowlan) {
  48. int err;
  49. /* Drivers don't expect to suspend while some operations like
  50. * authenticating or associating are in progress. It doesn't
  51. * make sense anyway to accept that, since the authentication
  52. * or association would never finish since the driver can't do
  53. * that on its own.
  54. * Thus, clean up in-progress auth/assoc first.
  55. */
  56. list_for_each_entry(sdata, &local->interfaces, list) {
  57. if (!ieee80211_sdata_running(sdata))
  58. continue;
  59. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  60. continue;
  61. ieee80211_mgd_quiesce(sdata);
  62. }
  63. err = drv_suspend(local, wowlan);
  64. if (err < 0) {
  65. local->quiescing = false;
  66. local->wowlan = false;
  67. if (ieee80211_hw_check(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_MAX_QUEUE_MAP,
  77. IEEE80211_QUEUE_STOP_REASON_SUSPEND,
  78. false);
  79. return err;
  80. } else if (err > 0) {
  81. WARN_ON(err != 1);
  82. /* cfg80211 will call back into mac80211 to disconnect
  83. * all interfaces, allow that to proceed properly
  84. */
  85. ieee80211_wake_queues_by_reason(hw,
  86. IEEE80211_MAX_QUEUE_MAP,
  87. IEEE80211_QUEUE_STOP_REASON_SUSPEND,
  88. false);
  89. return err;
  90. } else {
  91. goto suspend;
  92. }
  93. }
  94. /* remove all interfaces that were created in the driver */
  95. list_for_each_entry(sdata, &local->interfaces, list) {
  96. if (!ieee80211_sdata_running(sdata))
  97. continue;
  98. switch (sdata->vif.type) {
  99. case NL80211_IFTYPE_AP_VLAN:
  100. case NL80211_IFTYPE_MONITOR:
  101. continue;
  102. case NL80211_IFTYPE_STATION:
  103. ieee80211_mgd_quiesce(sdata);
  104. break;
  105. case NL80211_IFTYPE_WDS:
  106. /* tear down aggregation sessions and remove STAs */
  107. mutex_lock(&local->sta_mtx);
  108. sta = sdata->u.wds.sta;
  109. if (sta && sta->uploaded) {
  110. enum ieee80211_sta_state state;
  111. state = sta->sta_state;
  112. for (; state > IEEE80211_STA_NOTEXIST; state--)
  113. WARN_ON(drv_sta_state(local, sta->sdata,
  114. sta, state,
  115. state - 1));
  116. }
  117. mutex_unlock(&local->sta_mtx);
  118. break;
  119. default:
  120. break;
  121. }
  122. drv_remove_interface(local, sdata);
  123. }
  124. /*
  125. * We disconnected on all interfaces before suspend, all channel
  126. * contexts should be released.
  127. */
  128. WARN_ON(!list_empty(&local->chanctx_list));
  129. /* stop hardware - this must stop RX */
  130. if (local->open_count)
  131. ieee80211_stop_device(local);
  132. suspend:
  133. local->suspended = true;
  134. /* need suspended to be visible before quiescing is false */
  135. barrier();
  136. local->quiescing = false;
  137. return 0;
  138. }
  139. /*
  140. * __ieee80211_resume() is a static inline which just calls
  141. * ieee80211_reconfig(), which is also needed for hardware
  142. * hang/firmware failure/etc. recovery.
  143. */
  144. void ieee80211_report_wowlan_wakeup(struct ieee80211_vif *vif,
  145. struct cfg80211_wowlan_wakeup *wakeup,
  146. gfp_t gfp)
  147. {
  148. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  149. cfg80211_report_wowlan_wakeup(&sdata->wdev, wakeup, gfp);
  150. }
  151. EXPORT_SYMBOL(ieee80211_report_wowlan_wakeup);