Commit | Line | Data |
---|---|---|
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 | ||
77572fd1 | 9 | /* return value indicates whether the driver should be further notified */ |
61e8a48c | 10 | static void ieee80211_quiesce(struct ieee80211_sub_if_data *sdata) |
77572fd1 EP |
11 | { |
12 | switch (sdata->vif.type) { | |
13 | case NL80211_IFTYPE_STATION: | |
14 | ieee80211_sta_quiesce(sdata); | |
61e8a48c | 15 | break; |
77572fd1 EP |
16 | case NL80211_IFTYPE_ADHOC: |
17 | ieee80211_ibss_quiesce(sdata); | |
61e8a48c | 18 | break; |
77572fd1 EP |
19 | case NL80211_IFTYPE_MESH_POINT: |
20 | ieee80211_mesh_quiesce(sdata); | |
61e8a48c | 21 | break; |
77572fd1 | 22 | default: |
61e8a48c | 23 | break; |
77572fd1 | 24 | } |
61e8a48c JB |
25 | |
26 | cancel_work_sync(&sdata->work); | |
77572fd1 EP |
27 | } |
28 | ||
eecc4800 | 29 | int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan) |
665af4fc BC |
30 | { |
31 | struct ieee80211_local *local = hw_to_local(hw); | |
32 | struct ieee80211_sub_if_data *sdata; | |
665af4fc | 33 | struct sta_info *sta; |
fe5f2559 | 34 | struct ieee80211_chanctx *ctx; |
665af4fc | 35 | |
94f9b97b JB |
36 | if (!local->open_count) |
37 | goto suspend; | |
38 | ||
4136c422 | 39 | ieee80211_scan_cancel(local); |
5bb644a0 | 40 | |
ca45de77 JB |
41 | if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) { |
42 | mutex_lock(&local->sta_mtx); | |
43 | list_for_each_entry(sta, &local->sta_list, list) { | |
c2c98fde | 44 | set_sta_flag(sta, WLAN_STA_BLOCK_BA); |
ca45de77 JB |
45 | ieee80211_sta_tear_down_BA_sessions(sta, true); |
46 | } | |
47 | mutex_unlock(&local->sta_mtx); | |
48 | } | |
49 | ||
25420604 JB |
50 | ieee80211_stop_queues_by_reason(hw, |
51 | IEEE80211_QUEUE_STOP_REASON_SUSPEND); | |
52 | ||
5bb644a0 JB |
53 | /* flush out all packets */ |
54 | synchronize_net(); | |
55 | ||
ca45de77 JB |
56 | drv_flush(local, false); |
57 | ||
5bb644a0 JB |
58 | local->quiescing = true; |
59 | /* make quiescing visible to timers everywhere */ | |
60 | mb(); | |
61 | ||
42935eca | 62 | flush_workqueue(local->workqueue); |
665af4fc | 63 | |
5bb644a0 JB |
64 | /* Don't try to run timers while suspended. */ |
65 | del_timer_sync(&local->sta_cleanup); | |
66 | ||
67 | /* | |
68 | * Note that this particular timer doesn't need to be | |
69 | * restarted at resume. | |
70 | */ | |
71 | cancel_work_sync(&local->dynamic_ps_enable_work); | |
72 | del_timer_sync(&local->dynamic_ps_timer); | |
73 | ||
eecc4800 JB |
74 | local->wowlan = wowlan && local->open_count; |
75 | if (local->wowlan) { | |
76 | int err = drv_suspend(local, wowlan); | |
2b4562df | 77 | if (err < 0) { |
eecc4800 | 78 | local->quiescing = false; |
3b08cf6b | 79 | local->wowlan = false; |
9ea4fa15 ES |
80 | if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) { |
81 | mutex_lock(&local->sta_mtx); | |
82 | list_for_each_entry(sta, | |
83 | &local->sta_list, list) { | |
84 | clear_sta_flag(sta, WLAN_STA_BLOCK_BA); | |
85 | } | |
86 | mutex_unlock(&local->sta_mtx); | |
87 | } | |
88 | ieee80211_wake_queues_by_reason(hw, | |
89 | IEEE80211_QUEUE_STOP_REASON_SUSPEND); | |
eecc4800 | 90 | return err; |
2b4562df JB |
91 | } else if (err > 0) { |
92 | WARN_ON(err != 1); | |
93 | local->wowlan = false; | |
94 | } else { | |
61e8a48c JB |
95 | list_for_each_entry(sdata, &local->interfaces, list) |
96 | if (ieee80211_sdata_running(sdata)) | |
97 | ieee80211_quiesce(sdata); | |
2b4562df | 98 | goto suspend; |
eecc4800 | 99 | } |
eecc4800 JB |
100 | } |
101 | ||
665af4fc BC |
102 | /* disable keys */ |
103 | list_for_each_entry(sdata, &local->interfaces, list) | |
104 | ieee80211_disable_keys(sdata); | |
105 | ||
2a419056 JB |
106 | /* tear down aggregation sessions and remove STAs */ |
107 | mutex_lock(&local->sta_mtx); | |
108 | list_for_each_entry(sta, &local->sta_list, list) { | |
f09603a2 JB |
109 | if (sta->uploaded) { |
110 | enum ieee80211_sta_state state; | |
111 | ||
f09603a2 JB |
112 | state = sta->sta_state; |
113 | for (; state > IEEE80211_STA_NOTEXIST; state--) | |
9d88c7f6 | 114 | WARN_ON(drv_sta_state(local, sta->sdata, sta, |
f09603a2 JB |
115 | state, state - 1)); |
116 | } | |
117 | ||
5bb644a0 | 118 | mesh_plink_quiesce(sta); |
665af4fc | 119 | } |
34e89507 | 120 | mutex_unlock(&local->sta_mtx); |
665af4fc BC |
121 | |
122 | /* remove all interfaces */ | |
123 | list_for_each_entry(sdata, &local->interfaces, list) { | |
ad2d223a | 124 | static u8 zero_addr[ETH_ALEN] = {}; |
b8dc1a35 | 125 | u32 changed = 0; |
529ba6e9 | 126 | |
61e8a48c | 127 | if (!ieee80211_sdata_running(sdata)) |
5bb644a0 | 128 | continue; |
665af4fc | 129 | |
61e8a48c JB |
130 | switch (sdata->vif.type) { |
131 | case NL80211_IFTYPE_AP_VLAN: | |
132 | case NL80211_IFTYPE_MONITOR: | |
133 | /* skip these */ | |
5bb644a0 | 134 | continue; |
529ba6e9 JB |
135 | case NL80211_IFTYPE_STATION: |
136 | if (sdata->vif.bss_conf.assoc) | |
137 | changed = BSS_CHANGED_ASSOC | | |
138 | BSS_CHANGED_BSSID | | |
139 | BSS_CHANGED_IDLE; | |
b8dc1a35 JB |
140 | break; |
141 | case NL80211_IFTYPE_AP: | |
142 | case NL80211_IFTYPE_ADHOC: | |
143 | case NL80211_IFTYPE_MESH_POINT: | |
144 | if (sdata->vif.bss_conf.enable_beacon) | |
145 | changed = BSS_CHANGED_BEACON_ENABLED; | |
146 | break; | |
61e8a48c | 147 | default: |
61e8a48c JB |
148 | break; |
149 | } | |
e874e658 | 150 | |
b8dc1a35 JB |
151 | ieee80211_quiesce(sdata); |
152 | ||
529ba6e9 JB |
153 | sdata->suspend_bss_conf = sdata->vif.bss_conf; |
154 | memset(&sdata->vif.bss_conf, 0, sizeof(sdata->vif.bss_conf)); | |
155 | sdata->vif.bss_conf.idle = true; | |
ad2d223a JB |
156 | if (sdata->suspend_bss_conf.bssid) |
157 | sdata->vif.bss_conf.bssid = zero_addr; | |
529ba6e9 JB |
158 | |
159 | /* disable beaconing or remove association */ | |
160 | ieee80211_bss_info_change_notify(sdata, changed); | |
97af7432 | 161 | |
1041638f JB |
162 | if (sdata->vif.type == NL80211_IFTYPE_AP && |
163 | rcu_access_pointer(sdata->u.ap.beacon)) | |
164 | drv_stop_ap(local, sdata); | |
165 | ||
fe5f2559 JB |
166 | if (local->use_chanctx) { |
167 | struct ieee80211_chanctx_conf *conf; | |
168 | ||
169 | mutex_lock(&local->chanctx_mtx); | |
170 | conf = rcu_dereference_protected( | |
171 | sdata->vif.chanctx_conf, | |
172 | lockdep_is_held(&local->chanctx_mtx)); | |
173 | if (conf) { | |
174 | ctx = container_of(conf, | |
175 | struct ieee80211_chanctx, | |
176 | conf); | |
177 | drv_unassign_vif_chanctx(local, sdata, ctx); | |
178 | } | |
179 | ||
180 | mutex_unlock(&local->chanctx_mtx); | |
181 | } | |
7b7eab6f | 182 | drv_remove_interface(local, sdata); |
665af4fc | 183 | } |
5bb644a0 | 184 | |
4b6f1dd6 | 185 | sdata = rtnl_dereference(local->monitor_sdata); |
fe5f2559 JB |
186 | if (sdata) { |
187 | if (local->use_chanctx) { | |
188 | struct ieee80211_chanctx_conf *conf; | |
189 | ||
190 | mutex_lock(&local->chanctx_mtx); | |
191 | conf = rcu_dereference_protected( | |
192 | sdata->vif.chanctx_conf, | |
193 | lockdep_is_held(&local->chanctx_mtx)); | |
194 | if (conf) { | |
195 | ctx = container_of(conf, | |
196 | struct ieee80211_chanctx, | |
197 | conf); | |
198 | drv_unassign_vif_chanctx(local, sdata, ctx); | |
199 | } | |
200 | ||
201 | mutex_unlock(&local->chanctx_mtx); | |
202 | } | |
203 | ||
4b6f1dd6 | 204 | drv_remove_interface(local, sdata); |
fe5f2559 JB |
205 | } |
206 | ||
207 | mutex_lock(&local->chanctx_mtx); | |
208 | list_for_each_entry(ctx, &local->chanctx_list, list) | |
209 | drv_remove_chanctx(local, ctx); | |
210 | mutex_unlock(&local->chanctx_mtx); | |
4b6f1dd6 | 211 | |
89c3a8ac | 212 | /* stop hardware - this must stop RX */ |
84f6a01c JB |
213 | if (local->open_count) |
214 | ieee80211_stop_device(local); | |
89c3a8ac | 215 | |
eecc4800 | 216 | suspend: |
5bb644a0 | 217 | local->suspended = true; |
89c3a8ac JB |
218 | /* need suspended to be visible before quiescing is false */ |
219 | barrier(); | |
5bb644a0 JB |
220 | local->quiescing = false; |
221 | ||
665af4fc BC |
222 | return 0; |
223 | } | |
224 | ||
f2753ddb JB |
225 | /* |
226 | * __ieee80211_resume() is a static inline which just calls | |
227 | * ieee80211_reconfig(), which is also needed for hardware | |
228 | * hang/firmware failure/etc. recovery. | |
229 | */ |