pm.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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)
  8. {
  9. struct ieee80211_local *local = hw_to_local(hw);
  10. struct ieee80211_sub_if_data *sdata;
  11. struct ieee80211_if_init_conf conf;
  12. struct sta_info *sta;
  13. unsigned long flags;
  14. ieee80211_scan_cancel(local);
  15. ieee80211_stop_queues_by_reason(hw,
  16. IEEE80211_QUEUE_STOP_REASON_SUSPEND);
  17. /* flush out all packets */
  18. synchronize_net();
  19. local->quiescing = true;
  20. /* make quiescing visible to timers everywhere */
  21. mb();
  22. flush_workqueue(local->hw.workqueue);
  23. /* Don't try to run timers while suspended. */
  24. del_timer_sync(&local->sta_cleanup);
  25. /*
  26. * Note that this particular timer doesn't need to be
  27. * restarted at resume.
  28. */
  29. cancel_work_sync(&local->dynamic_ps_enable_work);
  30. del_timer_sync(&local->dynamic_ps_timer);
  31. /* disable keys */
  32. list_for_each_entry(sdata, &local->interfaces, list)
  33. ieee80211_disable_keys(sdata);
  34. /* Tear down aggregation sessions */
  35. rcu_read_lock();
  36. if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
  37. list_for_each_entry_rcu(sta, &local->sta_list, list) {
  38. set_sta_flags(sta, WLAN_STA_SUSPEND);
  39. ieee80211_sta_tear_down_BA_sessions(sta);
  40. }
  41. }
  42. rcu_read_unlock();
  43. /* remove STAs */
  44. spin_lock_irqsave(&local->sta_lock, flags);
  45. list_for_each_entry(sta, &local->sta_list, list) {
  46. if (local->ops->sta_notify) {
  47. sdata = sta->sdata;
  48. if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  49. sdata = container_of(sdata->bss,
  50. struct ieee80211_sub_if_data,
  51. u.ap);
  52. drv_sta_notify(local, &sdata->vif, STA_NOTIFY_REMOVE,
  53. &sta->sta);
  54. }
  55. mesh_plink_quiesce(sta);
  56. }
  57. spin_unlock_irqrestore(&local->sta_lock, flags);
  58. /* remove all interfaces */
  59. list_for_each_entry(sdata, &local->interfaces, list) {
  60. switch(sdata->vif.type) {
  61. case NL80211_IFTYPE_STATION:
  62. ieee80211_sta_quiesce(sdata);
  63. break;
  64. case NL80211_IFTYPE_ADHOC:
  65. ieee80211_ibss_quiesce(sdata);
  66. break;
  67. case NL80211_IFTYPE_MESH_POINT:
  68. ieee80211_mesh_quiesce(sdata);
  69. break;
  70. case NL80211_IFTYPE_AP_VLAN:
  71. case NL80211_IFTYPE_MONITOR:
  72. /* don't tell driver about this */
  73. continue;
  74. default:
  75. break;
  76. }
  77. if (!netif_running(sdata->dev))
  78. continue;
  79. conf.vif = &sdata->vif;
  80. conf.type = sdata->vif.type;
  81. conf.mac_addr = sdata->dev->dev_addr;
  82. drv_remove_interface(local, &conf);
  83. }
  84. /* stop hardware - this must stop RX */
  85. if (local->open_count) {
  86. ieee80211_led_radio(local, false);
  87. drv_stop(local);
  88. }
  89. /*
  90. * flush again, in case driver queued work -- it
  91. * shouldn't be doing (or cancel everything in the
  92. * stop callback) that but better safe than sorry.
  93. */
  94. flush_workqueue(local->hw.workqueue);
  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. */