pm.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. false);
  31. /* flush out all packets */
  32. synchronize_net();
  33. ieee80211_flush_queues(local, NULL, true);
  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. false);
  64. return err;
  65. } else if (err > 0) {
  66. WARN_ON(err != 1);
  67. return err;
  68. } else {
  69. goto suspend;
  70. }
  71. }
  72. /* remove all interfaces that were created in the driver */
  73. list_for_each_entry(sdata, &local->interfaces, list) {
  74. if (!ieee80211_sdata_running(sdata))
  75. continue;
  76. switch (sdata->vif.type) {
  77. case NL80211_IFTYPE_AP_VLAN:
  78. case NL80211_IFTYPE_MONITOR:
  79. continue;
  80. case NL80211_IFTYPE_STATION:
  81. ieee80211_mgd_quiesce(sdata);
  82. break;
  83. case NL80211_IFTYPE_WDS:
  84. /* tear down aggregation sessions and remove STAs */
  85. mutex_lock(&local->sta_mtx);
  86. sta = sdata->u.wds.sta;
  87. if (sta && sta->uploaded) {
  88. enum ieee80211_sta_state state;
  89. state = sta->sta_state;
  90. for (; state > IEEE80211_STA_NOTEXIST; state--)
  91. WARN_ON(drv_sta_state(local, sta->sdata,
  92. sta, state,
  93. state - 1));
  94. }
  95. mutex_unlock(&local->sta_mtx);
  96. break;
  97. default:
  98. break;
  99. }
  100. drv_remove_interface(local, sdata);
  101. }
  102. /*
  103. * We disconnected on all interfaces before suspend, all channel
  104. * contexts should be released.
  105. */
  106. WARN_ON(!list_empty(&local->chanctx_list));
  107. /* stop hardware - this must stop RX */
  108. if (local->open_count)
  109. ieee80211_stop_device(local);
  110. suspend:
  111. local->suspended = true;
  112. /* need suspended to be visible before quiescing is false */
  113. barrier();
  114. local->quiescing = false;
  115. return 0;
  116. }
  117. /*
  118. * __ieee80211_resume() is a static inline which just calls
  119. * ieee80211_reconfig(), which is also needed for hardware
  120. * hang/firmware failure/etc. recovery.
  121. */
  122. void ieee80211_report_wowlan_wakeup(struct ieee80211_vif *vif,
  123. struct cfg80211_wowlan_wakeup *wakeup,
  124. gfp_t gfp)
  125. {
  126. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  127. cfg80211_report_wowlan_wakeup(&sdata->wdev, wakeup, gfp);
  128. }
  129. EXPORT_SYMBOL(ieee80211_report_wowlan_wakeup);