pm.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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_MAX_QUEUE_MAP,
  27. IEEE80211_QUEUE_STOP_REASON_SUSPEND);
  28. /* flush out all packets */
  29. synchronize_net();
  30. ieee80211_flush_queues(local, NULL);
  31. local->quiescing = true;
  32. /* make quiescing visible to timers everywhere */
  33. mb();
  34. flush_workqueue(local->workqueue);
  35. /* Don't try to run timers while suspended. */
  36. del_timer_sync(&local->sta_cleanup);
  37. /*
  38. * Note that this particular timer doesn't need to be
  39. * restarted at resume.
  40. */
  41. cancel_work_sync(&local->dynamic_ps_enable_work);
  42. del_timer_sync(&local->dynamic_ps_timer);
  43. local->wowlan = wowlan && local->open_count;
  44. if (local->wowlan) {
  45. int err = drv_suspend(local, wowlan);
  46. if (err < 0) {
  47. local->quiescing = false;
  48. local->wowlan = false;
  49. if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
  50. mutex_lock(&local->sta_mtx);
  51. list_for_each_entry(sta,
  52. &local->sta_list, list) {
  53. clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
  54. }
  55. mutex_unlock(&local->sta_mtx);
  56. }
  57. ieee80211_wake_queues_by_reason(hw,
  58. IEEE80211_MAX_QUEUE_MAP,
  59. IEEE80211_QUEUE_STOP_REASON_SUSPEND);
  60. return err;
  61. } else if (err > 0) {
  62. WARN_ON(err != 1);
  63. return err;
  64. } else {
  65. goto suspend;
  66. }
  67. }
  68. /* tear down aggregation sessions and remove STAs */
  69. mutex_lock(&local->sta_mtx);
  70. list_for_each_entry(sta, &local->sta_list, list) {
  71. if (sta->uploaded) {
  72. enum ieee80211_sta_state state;
  73. state = sta->sta_state;
  74. for (; state > IEEE80211_STA_NOTEXIST; state--)
  75. WARN_ON(drv_sta_state(local, sta->sdata, sta,
  76. state, state - 1));
  77. }
  78. }
  79. mutex_unlock(&local->sta_mtx);
  80. /* remove all interfaces */
  81. list_for_each_entry(sdata, &local->interfaces, list) {
  82. if (!ieee80211_sdata_running(sdata))
  83. continue;
  84. drv_remove_interface(local, sdata);
  85. }
  86. sdata = rtnl_dereference(local->monitor_sdata);
  87. if (sdata)
  88. drv_remove_interface(local, sdata);
  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);