pm.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
  17. mutex_lock(&local->sta_mtx);
  18. list_for_each_entry(sta, &local->sta_list, list) {
  19. set_sta_flag(sta, WLAN_STA_BLOCK_BA);
  20. ieee80211_sta_tear_down_BA_sessions(
  21. sta, AGG_STOP_LOCAL_REQUEST);
  22. }
  23. mutex_unlock(&local->sta_mtx);
  24. }
  25. ieee80211_stop_queues_by_reason(hw,
  26. IEEE80211_QUEUE_STOP_REASON_SUSPEND);
  27. /* flush out all packets */
  28. synchronize_net();
  29. drv_flush(local, false);
  30. local->quiescing = true;
  31. /* make quiescing visible to timers everywhere */
  32. mb();
  33. flush_workqueue(local->workqueue);
  34. /* Don't try to run timers while suspended. */
  35. del_timer_sync(&local->sta_cleanup);
  36. /*
  37. * Note that this particular timer doesn't need to be
  38. * restarted at resume.
  39. */
  40. cancel_work_sync(&local->dynamic_ps_enable_work);
  41. del_timer_sync(&local->dynamic_ps_timer);
  42. local->wowlan = wowlan && local->open_count;
  43. if (local->wowlan) {
  44. int err = drv_suspend(local, wowlan);
  45. if (err < 0) {
  46. local->quiescing = false;
  47. local->wowlan = false;
  48. if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
  49. mutex_lock(&local->sta_mtx);
  50. list_for_each_entry(sta,
  51. &local->sta_list, list) {
  52. clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
  53. }
  54. mutex_unlock(&local->sta_mtx);
  55. }
  56. ieee80211_wake_queues_by_reason(hw,
  57. IEEE80211_QUEUE_STOP_REASON_SUSPEND);
  58. return err;
  59. } else if (err > 0) {
  60. WARN_ON(err != 1);
  61. return err;
  62. } else {
  63. goto suspend;
  64. }
  65. }
  66. /* tear down aggregation sessions and remove STAs */
  67. mutex_lock(&local->sta_mtx);
  68. list_for_each_entry(sta, &local->sta_list, list) {
  69. if (sta->uploaded) {
  70. enum ieee80211_sta_state state;
  71. state = sta->sta_state;
  72. for (; state > IEEE80211_STA_NOTEXIST; state--)
  73. WARN_ON(drv_sta_state(local, sta->sdata, sta,
  74. state, state - 1));
  75. }
  76. }
  77. mutex_unlock(&local->sta_mtx);
  78. /* remove all interfaces */
  79. list_for_each_entry(sdata, &local->interfaces, list) {
  80. if (!ieee80211_sdata_running(sdata))
  81. continue;
  82. drv_remove_interface(local, sdata);
  83. }
  84. sdata = rtnl_dereference(local->monitor_sdata);
  85. if (sdata)
  86. drv_remove_interface(local, sdata);
  87. /*
  88. * We disconnected on all interfaces before suspend, all channel
  89. * contexts should be released.
  90. */
  91. WARN_ON(!list_empty(&local->chanctx_list));
  92. /* stop hardware - this must stop RX */
  93. if (local->open_count)
  94. ieee80211_stop_device(local);
  95. suspend:
  96. local->suspended = true;
  97. /* need suspended to be visible before quiescing is false */
  98. barrier();
  99. local->quiescing = false;
  100. return 0;
  101. }
  102. /*
  103. * __ieee80211_resume() is a static inline which just calls
  104. * ieee80211_reconfig(), which is also needed for hardware
  105. * hang/firmware failure/etc. recovery.
  106. */
  107. void ieee80211_report_wowlan_wakeup(struct ieee80211_vif *vif,
  108. struct cfg80211_wowlan_wakeup *wakeup,
  109. gfp_t gfp)
  110. {
  111. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  112. cfg80211_report_wowlan_wakeup(&sdata->wdev, wakeup, gfp);
  113. }
  114. EXPORT_SYMBOL(ieee80211_report_wowlan_wakeup);