pm.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 (hw->flags & IEEE80211_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. /* flush out all packets and station cleanup call_rcu()s */
  31. synchronize_net();
  32. rcu_barrier();
  33. ieee80211_flush_queues(local, NULL);
  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 && local->open_count;
  47. if (local->wowlan) {
  48. int err = drv_suspend(local, wowlan);
  49. if (err < 0) {
  50. local->quiescing = false;
  51. local->wowlan = false;
  52. if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
  53. mutex_lock(&local->sta_mtx);
  54. list_for_each_entry(sta,
  55. &local->sta_list, list) {
  56. clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
  57. }
  58. mutex_unlock(&local->sta_mtx);
  59. }
  60. ieee80211_wake_queues_by_reason(hw,
  61. IEEE80211_MAX_QUEUE_MAP,
  62. IEEE80211_QUEUE_STOP_REASON_SUSPEND);
  63. return err;
  64. } else if (err > 0) {
  65. WARN_ON(err != 1);
  66. return err;
  67. } else {
  68. goto suspend;
  69. }
  70. }
  71. /* tear down aggregation sessions and remove STAs */
  72. mutex_lock(&local->sta_mtx);
  73. list_for_each_entry(sta, &local->sta_list, list) {
  74. if (sta->uploaded) {
  75. enum ieee80211_sta_state state;
  76. state = sta->sta_state;
  77. for (; state > IEEE80211_STA_NOTEXIST; state--)
  78. WARN_ON(drv_sta_state(local, sta->sdata, sta,
  79. state, state - 1));
  80. }
  81. }
  82. mutex_unlock(&local->sta_mtx);
  83. /* remove all interfaces */
  84. list_for_each_entry(sdata, &local->interfaces, list) {
  85. if (!ieee80211_sdata_running(sdata))
  86. continue;
  87. drv_remove_interface(local, sdata);
  88. }
  89. /*
  90. * We disconnected on all interfaces before suspend, all channel
  91. * contexts should be released.
  92. */
  93. WARN_ON(!list_empty(&local->chanctx_list));
  94. /* stop hardware - this must stop RX */
  95. if (local->open_count)
  96. ieee80211_stop_device(local);
  97. suspend:
  98. local->suspended = true;
  99. /* need suspended to be visible before quiescing is false */
  100. barrier();
  101. local->quiescing = false;
  102. return 0;
  103. }
  104. /*
  105. * __ieee80211_resume() is a static inline which just calls
  106. * ieee80211_reconfig(), which is also needed for hardware
  107. * hang/firmware failure/etc. recovery.
  108. */
  109. void ieee80211_report_wowlan_wakeup(struct ieee80211_vif *vif,
  110. struct cfg80211_wowlan_wakeup *wakeup,
  111. gfp_t gfp)
  112. {
  113. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  114. cfg80211_report_wowlan_wakeup(&sdata->wdev, wakeup, gfp);
  115. }
  116. EXPORT_SYMBOL(ieee80211_report_wowlan_wakeup);