pm.c 3.5 KB

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