Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris...
[linux/fpc-iii.git] / net / mac80211 / pm.c
blobaf64fb8e8addb58e5933cc3a45a8043f55659f81
1 #include <net/mac80211.h>
2 #include <net/rtnetlink.h>
4 #include "ieee80211_i.h"
5 #include "mesh.h"
6 #include "driver-ops.h"
7 #include "led.h"
9 int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
11 struct ieee80211_local *local = hw_to_local(hw);
12 struct ieee80211_sub_if_data *sdata;
13 struct sta_info *sta;
15 if (!local->open_count)
16 goto suspend;
18 ieee80211_scan_cancel(local);
20 ieee80211_dfs_cac_cancel(local);
22 ieee80211_roc_purge(local, NULL);
24 ieee80211_del_virtual_monitor(local);
26 if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
27 mutex_lock(&local->sta_mtx);
28 list_for_each_entry(sta, &local->sta_list, list) {
29 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
30 ieee80211_sta_tear_down_BA_sessions(
31 sta, AGG_STOP_LOCAL_REQUEST);
33 mutex_unlock(&local->sta_mtx);
36 ieee80211_stop_queues_by_reason(hw,
37 IEEE80211_MAX_QUEUE_MAP,
38 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
40 /* flush out all packets */
41 synchronize_net();
43 ieee80211_flush_queues(local, NULL);
45 local->quiescing = true;
46 /* make quiescing visible to timers everywhere */
47 mb();
49 flush_workqueue(local->workqueue);
51 /* Don't try to run timers while suspended. */
52 del_timer_sync(&local->sta_cleanup);
55 * Note that this particular timer doesn't need to be
56 * restarted at resume.
58 cancel_work_sync(&local->dynamic_ps_enable_work);
59 del_timer_sync(&local->dynamic_ps_timer);
61 local->wowlan = wowlan && local->open_count;
62 if (local->wowlan) {
63 int err = drv_suspend(local, wowlan);
64 if (err < 0) {
65 local->quiescing = false;
66 local->wowlan = false;
67 if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
68 mutex_lock(&local->sta_mtx);
69 list_for_each_entry(sta,
70 &local->sta_list, list) {
71 clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
73 mutex_unlock(&local->sta_mtx);
75 ieee80211_wake_queues_by_reason(hw,
76 IEEE80211_MAX_QUEUE_MAP,
77 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
78 return err;
79 } else if (err > 0) {
80 WARN_ON(err != 1);
81 return err;
82 } else {
83 goto suspend;
87 /* tear down aggregation sessions and remove STAs */
88 mutex_lock(&local->sta_mtx);
89 list_for_each_entry(sta, &local->sta_list, list) {
90 if (sta->uploaded) {
91 enum ieee80211_sta_state state;
93 state = sta->sta_state;
94 for (; state > IEEE80211_STA_NOTEXIST; state--)
95 WARN_ON(drv_sta_state(local, sta->sdata, sta,
96 state, state - 1));
99 mutex_unlock(&local->sta_mtx);
101 /* remove all interfaces that were created in the driver */
102 list_for_each_entry(sdata, &local->interfaces, list) {
103 if (!ieee80211_sdata_running(sdata) ||
104 sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
105 sdata->vif.type == NL80211_IFTYPE_MONITOR)
106 continue;
108 drv_remove_interface(local, sdata);
112 * We disconnected on all interfaces before suspend, all channel
113 * contexts should be released.
115 WARN_ON(!list_empty(&local->chanctx_list));
117 /* stop hardware - this must stop RX */
118 if (local->open_count)
119 ieee80211_stop_device(local);
121 suspend:
122 local->suspended = true;
123 /* need suspended to be visible before quiescing is false */
124 barrier();
125 local->quiescing = false;
127 return 0;
131 * __ieee80211_resume() is a static inline which just calls
132 * ieee80211_reconfig(), which is also needed for hardware
133 * hang/firmware failure/etc. recovery.
136 void ieee80211_report_wowlan_wakeup(struct ieee80211_vif *vif,
137 struct cfg80211_wowlan_wakeup *wakeup,
138 gfp_t gfp)
140 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
142 cfg80211_report_wowlan_wakeup(&sdata->wdev, wakeup, gfp);
144 EXPORT_SYMBOL(ieee80211_report_wowlan_wakeup);