mac80211: purge remain-on-channel items when suspending
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / net / mac80211 / pm.c
CommitLineData
665af4fc
BC
1#include <net/mac80211.h>
2#include <net/rtnetlink.h>
3
4#include "ieee80211_i.h"
5bb644a0 5#include "mesh.h"
24487981 6#include "driver-ops.h"
665af4fc
BC
7#include "led.h"
8
eecc4800 9int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
665af4fc
BC
10{
11 struct ieee80211_local *local = hw_to_local(hw);
12 struct ieee80211_sub_if_data *sdata;
665af4fc
BC
13 struct sta_info *sta;
14
94f9b97b
JB
15 if (!local->open_count)
16 goto suspend;
17
4136c422 18 ieee80211_scan_cancel(local);
5bb644a0 19
164eb02d
SW
20 ieee80211_dfs_cac_cancel(local);
21
c8f994ee
JB
22 ieee80211_roc_purge(local, NULL);
23
ca45de77
JB
24 if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
25 mutex_lock(&local->sta_mtx);
26 list_for_each_entry(sta, &local->sta_list, list) {
c2c98fde 27 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
c82c4a80
JB
28 ieee80211_sta_tear_down_BA_sessions(
29 sta, AGG_STOP_LOCAL_REQUEST);
ca45de77
JB
30 }
31 mutex_unlock(&local->sta_mtx);
32 }
33
25420604 34 ieee80211_stop_queues_by_reason(hw,
445ea4e8
JB
35 IEEE80211_MAX_QUEUE_MAP,
36 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
25420604 37
5bb644a0
JB
38 /* flush out all packets */
39 synchronize_net();
40
39ecc01d 41 ieee80211_flush_queues(local, NULL);
ca45de77 42
5bb644a0
JB
43 local->quiescing = true;
44 /* make quiescing visible to timers everywhere */
45 mb();
46
42935eca 47 flush_workqueue(local->workqueue);
665af4fc 48
5bb644a0
JB
49 /* Don't try to run timers while suspended. */
50 del_timer_sync(&local->sta_cleanup);
51
52 /*
53 * Note that this particular timer doesn't need to be
54 * restarted at resume.
55 */
56 cancel_work_sync(&local->dynamic_ps_enable_work);
57 del_timer_sync(&local->dynamic_ps_timer);
58
eecc4800
JB
59 local->wowlan = wowlan && local->open_count;
60 if (local->wowlan) {
61 int err = drv_suspend(local, wowlan);
2b4562df 62 if (err < 0) {
eecc4800 63 local->quiescing = false;
3b08cf6b 64 local->wowlan = false;
9ea4fa15
ES
65 if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
66 mutex_lock(&local->sta_mtx);
67 list_for_each_entry(sta,
68 &local->sta_list, list) {
69 clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
70 }
71 mutex_unlock(&local->sta_mtx);
72 }
73 ieee80211_wake_queues_by_reason(hw,
445ea4e8 74 IEEE80211_MAX_QUEUE_MAP,
9ea4fa15 75 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
eecc4800 76 return err;
2b4562df
JB
77 } else if (err > 0) {
78 WARN_ON(err != 1);
81256969 79 return err;
2b4562df 80 } else {
2b4562df 81 goto suspend;
eecc4800 82 }
eecc4800
JB
83 }
84
2a419056
JB
85 /* tear down aggregation sessions and remove STAs */
86 mutex_lock(&local->sta_mtx);
87 list_for_each_entry(sta, &local->sta_list, list) {
f09603a2
JB
88 if (sta->uploaded) {
89 enum ieee80211_sta_state state;
90
f09603a2
JB
91 state = sta->sta_state;
92 for (; state > IEEE80211_STA_NOTEXIST; state--)
9d88c7f6 93 WARN_ON(drv_sta_state(local, sta->sdata, sta,
f09603a2
JB
94 state, state - 1));
95 }
665af4fc 96 }
34e89507 97 mutex_unlock(&local->sta_mtx);
665af4fc
BC
98
99 /* remove all interfaces */
100 list_for_each_entry(sdata, &local->interfaces, list) {
61e8a48c 101 if (!ieee80211_sdata_running(sdata))
5bb644a0 102 continue;
7b7eab6f 103 drv_remove_interface(local, sdata);
665af4fc 104 }
5bb644a0 105
4b6f1dd6 106 sdata = rtnl_dereference(local->monitor_sdata);
12e7f517 107 if (sdata)
4b6f1dd6 108 drv_remove_interface(local, sdata);
fe5f2559 109
12e7f517
SG
110 /*
111 * We disconnected on all interfaces before suspend, all channel
112 * contexts should be released.
113 */
114 WARN_ON(!list_empty(&local->chanctx_list));
4b6f1dd6 115
89c3a8ac 116 /* stop hardware - this must stop RX */
84f6a01c
JB
117 if (local->open_count)
118 ieee80211_stop_device(local);
89c3a8ac 119
eecc4800 120 suspend:
5bb644a0 121 local->suspended = true;
89c3a8ac
JB
122 /* need suspended to be visible before quiescing is false */
123 barrier();
5bb644a0
JB
124 local->quiescing = false;
125
665af4fc
BC
126 return 0;
127}
128
f2753ddb
JB
129/*
130 * __ieee80211_resume() is a static inline which just calls
131 * ieee80211_reconfig(), which is also needed for hardware
132 * hang/firmware failure/etc. recovery.
133 */
cd8f7cb4
JB
134
135void ieee80211_report_wowlan_wakeup(struct ieee80211_vif *vif,
136 struct cfg80211_wowlan_wakeup *wakeup,
137 gfp_t gfp)
138{
139 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
140
141 cfg80211_report_wowlan_wakeup(&sdata->wdev, wakeup, gfp);
142}
143EXPORT_SYMBOL(ieee80211_report_wowlan_wakeup);