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