pm.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. ieee80211_scan_cancel(local);
  13. if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
  14. mutex_lock(&local->sta_mtx);
  15. list_for_each_entry(sta, &local->sta_list, list) {
  16. set_sta_flags(sta, WLAN_STA_BLOCK_BA);
  17. ieee80211_sta_tear_down_BA_sessions(sta, true);
  18. }
  19. mutex_unlock(&local->sta_mtx);
  20. }
  21. ieee80211_stop_queues_by_reason(hw,
  22. IEEE80211_QUEUE_STOP_REASON_SUSPEND);
  23. /* flush out all packets */
  24. synchronize_net();
  25. drv_flush(local, false);
  26. local->quiescing = true;
  27. /* make quiescing visible to timers everywhere */
  28. mb();
  29. flush_workqueue(local->workqueue);
  30. /* Don't try to run timers while suspended. */
  31. del_timer_sync(&local->sta_cleanup);
  32. /*
  33. * Note that this particular timer doesn't need to be
  34. * restarted at resume.
  35. */
  36. cancel_work_sync(&local->dynamic_ps_enable_work);
  37. del_timer_sync(&local->dynamic_ps_timer);
  38. local->wowlan = wowlan && local->open_count;
  39. if (local->wowlan) {
  40. int err = drv_suspend(local, wowlan);
  41. if (err) {
  42. local->quiescing = false;
  43. return err;
  44. }
  45. goto suspend;
  46. }
  47. /* disable keys */
  48. list_for_each_entry(sdata, &local->interfaces, list)
  49. ieee80211_disable_keys(sdata);
  50. /* tear down aggregation sessions and remove STAs */
  51. mutex_lock(&local->sta_mtx);
  52. list_for_each_entry(sta, &local->sta_list, list) {
  53. if (sta->uploaded) {
  54. sdata = sta->sdata;
  55. if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  56. sdata = container_of(sdata->bss,
  57. struct ieee80211_sub_if_data,
  58. u.ap);
  59. drv_sta_remove(local, sdata, &sta->sta);
  60. }
  61. mesh_plink_quiesce(sta);
  62. }
  63. mutex_unlock(&local->sta_mtx);
  64. /* remove all interfaces */
  65. list_for_each_entry(sdata, &local->interfaces, list) {
  66. cancel_work_sync(&sdata->work);
  67. switch(sdata->vif.type) {
  68. case NL80211_IFTYPE_STATION:
  69. ieee80211_sta_quiesce(sdata);
  70. break;
  71. case NL80211_IFTYPE_ADHOC:
  72. ieee80211_ibss_quiesce(sdata);
  73. break;
  74. case NL80211_IFTYPE_MESH_POINT:
  75. ieee80211_mesh_quiesce(sdata);
  76. break;
  77. case NL80211_IFTYPE_AP_VLAN:
  78. case NL80211_IFTYPE_MONITOR:
  79. /* don't tell driver about this */
  80. continue;
  81. default:
  82. break;
  83. }
  84. if (!ieee80211_sdata_running(sdata))
  85. continue;
  86. /* disable beaconing */
  87. ieee80211_bss_info_change_notify(sdata,
  88. BSS_CHANGED_BEACON_ENABLED);
  89. drv_remove_interface(local, &sdata->vif);
  90. }
  91. /* stop hardware - this must stop RX */
  92. if (local->open_count)
  93. ieee80211_stop_device(local);
  94. suspend:
  95. local->suspended = true;
  96. /* need suspended to be visible before quiescing is false */
  97. barrier();
  98. local->quiescing = false;
  99. return 0;
  100. }
  101. /*
  102. * __ieee80211_resume() is a static inline which just calls
  103. * ieee80211_reconfig(), which is also needed for hardware
  104. * hang/firmware failure/etc. recovery.
  105. */