blob: f81fd30581d9e69cc91cc8be9a15d25e0094c2ac [file] [log] [blame]
Bob Copeland665af4f2009-01-19 11:20:53 -05001#include <net/mac80211.h>
2#include <net/rtnetlink.h>
3
4#include "ieee80211_i.h"
Johannes Berg5bb644a2009-05-17 11:40:42 +02005#include "mesh.h"
Johannes Berg24487982009-04-23 18:52:52 +02006#include "driver-ops.h"
Bob Copeland665af4f2009-01-19 11:20:53 -05007#include "led.h"
8
Eliad Peller77572fd2011-06-16 11:49:33 +03009/* return value indicates whether the driver should be further notified */
Johannes Berg61e8a482012-12-13 16:47:42 +010010static void ieee80211_quiesce(struct ieee80211_sub_if_data *sdata)
Eliad Peller77572fd2011-06-16 11:49:33 +030011{
12 switch (sdata->vif.type) {
13 case NL80211_IFTYPE_STATION:
14 ieee80211_sta_quiesce(sdata);
Johannes Berg61e8a482012-12-13 16:47:42 +010015 break;
Eliad Peller77572fd2011-06-16 11:49:33 +030016 case NL80211_IFTYPE_ADHOC:
17 ieee80211_ibss_quiesce(sdata);
Johannes Berg61e8a482012-12-13 16:47:42 +010018 break;
Eliad Peller77572fd2011-06-16 11:49:33 +030019 case NL80211_IFTYPE_MESH_POINT:
20 ieee80211_mesh_quiesce(sdata);
Johannes Berg61e8a482012-12-13 16:47:42 +010021 break;
Eliad Peller77572fd2011-06-16 11:49:33 +030022 default:
Johannes Berg61e8a482012-12-13 16:47:42 +010023 break;
Eliad Peller77572fd2011-06-16 11:49:33 +030024 }
Johannes Berg61e8a482012-12-13 16:47:42 +010025
26 cancel_work_sync(&sdata->work);
Eliad Peller77572fd2011-06-16 11:49:33 +030027}
28
Johannes Bergeecc4802011-05-04 15:37:29 +020029int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
Bob Copeland665af4f2009-01-19 11:20:53 -050030{
31 struct ieee80211_local *local = hw_to_local(hw);
32 struct ieee80211_sub_if_data *sdata;
Bob Copeland665af4f2009-01-19 11:20:53 -050033 struct sta_info *sta;
Johannes Bergfe5f2552012-11-19 22:19:08 +010034 struct ieee80211_chanctx *ctx;
Bob Copeland665af4f2009-01-19 11:20:53 -050035
Johannes Berg94f9b972011-07-14 16:48:54 +020036 if (!local->open_count)
37 goto suspend;
38
Stanislaw Gruszka4136c422010-10-06 11:22:10 +020039 ieee80211_scan_cancel(local);
Johannes Berg5bb644a2009-05-17 11:40:42 +020040
Johannes Bergca45de72011-04-21 13:38:00 +020041 if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
42 mutex_lock(&local->sta_mtx);
43 list_for_each_entry(sta, &local->sta_list, list) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +020044 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
Johannes Bergca45de72011-04-21 13:38:00 +020045 ieee80211_sta_tear_down_BA_sessions(sta, true);
46 }
47 mutex_unlock(&local->sta_mtx);
48 }
49
Johannes Berg25420602009-03-13 11:43:36 +010050 ieee80211_stop_queues_by_reason(hw,
51 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
52
Johannes Berg5bb644a2009-05-17 11:40:42 +020053 /* flush out all packets */
54 synchronize_net();
55
Johannes Bergca45de72011-04-21 13:38:00 +020056 drv_flush(local, false);
57
Johannes Berg5bb644a2009-05-17 11:40:42 +020058 local->quiescing = true;
59 /* make quiescing visible to timers everywhere */
60 mb();
61
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -040062 flush_workqueue(local->workqueue);
Bob Copeland665af4f2009-01-19 11:20:53 -050063
Johannes Berg5bb644a2009-05-17 11:40:42 +020064 /* 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
Johannes Bergeecc4802011-05-04 15:37:29 +020074 local->wowlan = wowlan && local->open_count;
75 if (local->wowlan) {
76 int err = drv_suspend(local, wowlan);
Johannes Berg2b4562d2011-07-02 00:02:01 +020077 if (err < 0) {
Johannes Bergeecc4802011-05-04 15:37:29 +020078 local->quiescing = false;
Pontus Fuchs3b08cf62012-05-31 12:34:47 +020079 local->wowlan = false;
Eyal Shapira9ea4fa12012-06-20 13:10:14 +030080 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);
Johannes Bergeecc4802011-05-04 15:37:29 +020090 return err;
Johannes Berg2b4562d2011-07-02 00:02:01 +020091 } else if (err > 0) {
92 WARN_ON(err != 1);
93 local->wowlan = false;
94 } else {
Johannes Berg61e8a482012-12-13 16:47:42 +010095 list_for_each_entry(sdata, &local->interfaces, list)
96 if (ieee80211_sdata_running(sdata))
97 ieee80211_quiesce(sdata);
Johannes Berg2b4562d2011-07-02 00:02:01 +020098 goto suspend;
Johannes Bergeecc4802011-05-04 15:37:29 +020099 }
Johannes Bergeecc4802011-05-04 15:37:29 +0200100 }
101
Bob Copeland665af4f2009-01-19 11:20:53 -0500102 /* disable keys */
103 list_for_each_entry(sdata, &local->interfaces, list)
104 ieee80211_disable_keys(sdata);
105
Johannes Berg2a419052010-06-10 10:21:29 +0200106 /* tear down aggregation sessions and remove STAs */
107 mutex_lock(&local->sta_mtx);
108 list_for_each_entry(sta, &local->sta_list, list) {
Johannes Bergf09603a2012-01-20 13:55:21 +0100109 if (sta->uploaded) {
110 enum ieee80211_sta_state state;
111
Johannes Bergf09603a2012-01-20 13:55:21 +0100112 state = sta->sta_state;
113 for (; state > IEEE80211_STA_NOTEXIST; state--)
Jakub Kicinski9d88c7f2012-02-23 02:17:48 +0100114 WARN_ON(drv_sta_state(local, sta->sdata, sta,
Johannes Bergf09603a2012-01-20 13:55:21 +0100115 state, state - 1));
116 }
117
Johannes Berg5bb644a2009-05-17 11:40:42 +0200118 mesh_plink_quiesce(sta);
Bob Copeland665af4f2009-01-19 11:20:53 -0500119 }
Johannes Berg34e89502010-02-03 13:59:58 +0100120 mutex_unlock(&local->sta_mtx);
Bob Copeland665af4f2009-01-19 11:20:53 -0500121
122 /* remove all interfaces */
123 list_for_each_entry(sdata, &local->interfaces, list) {
Johannes Bergad2d2232012-12-14 14:34:25 +0100124 static u8 zero_addr[ETH_ALEN] = {};
Johannes Bergb8dc1a32012-12-14 14:22:10 +0100125 u32 changed = 0;
Johannes Berg529ba6e2012-12-13 17:16:45 +0100126
Johannes Berg9607e6b2009-12-23 13:15:31 +0100127 if (!ieee80211_sdata_running(sdata))
Johannes Berg5bb644a2009-05-17 11:40:42 +0200128 continue;
129
Johannes Berg61e8a482012-12-13 16:47:42 +0100130 switch (sdata->vif.type) {
131 case NL80211_IFTYPE_AP_VLAN:
132 case NL80211_IFTYPE_MONITOR:
133 /* skip these */
134 continue;
Johannes Berg529ba6e2012-12-13 17:16:45 +0100135 case NL80211_IFTYPE_STATION:
136 if (sdata->vif.bss_conf.assoc)
137 changed = BSS_CHANGED_ASSOC |
138 BSS_CHANGED_BSSID |
139 BSS_CHANGED_IDLE;
Johannes Bergb8dc1a32012-12-14 14:22:10 +0100140 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;
Johannes Berg61e8a482012-12-13 16:47:42 +0100147 default:
Johannes Berg61e8a482012-12-13 16:47:42 +0100148 break;
149 }
150
Johannes Bergb8dc1a32012-12-14 14:22:10 +0100151 ieee80211_quiesce(sdata);
152
Johannes Berg529ba6e2012-12-13 17:16:45 +0100153 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;
Johannes Bergad2d2232012-12-14 14:34:25 +0100156 if (sdata->suspend_bss_conf.bssid)
157 sdata->vif.bss_conf.bssid = zero_addr;
Johannes Berg529ba6e2012-12-13 17:16:45 +0100158
159 /* disable beaconing or remove association */
160 ieee80211_bss_info_change_notify(sdata, changed);
Bob Copeland97af7432009-07-29 10:13:03 +0200161
Johannes Berg10416382012-10-19 15:44:42 +0200162 if (sdata->vif.type == NL80211_IFTYPE_AP &&
163 rcu_access_pointer(sdata->u.ap.beacon))
164 drv_stop_ap(local, sdata);
165
Johannes Bergfe5f2552012-11-19 22:19:08 +0100166 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 }
Johannes Berg7b7eab62011-11-03 14:41:13 +0100182 drv_remove_interface(local, sdata);
Bob Copeland665af4f2009-01-19 11:20:53 -0500183 }
184
Johannes Berg4b6f1dd2012-04-03 14:35:57 +0200185 sdata = rtnl_dereference(local->monitor_sdata);
Johannes Bergfe5f2552012-11-19 22:19:08 +0100186 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
Johannes Berg4b6f1dd2012-04-03 14:35:57 +0200204 drv_remove_interface(local, sdata);
Johannes Bergfe5f2552012-11-19 22:19:08 +0100205 }
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);
Johannes Berg4b6f1dd2012-04-03 14:35:57 +0200211
Johannes Berg89c3a8a2009-07-28 18:10:17 +0200212 /* stop hardware - this must stop RX */
Johannes Berg84f6a012009-08-20 20:02:20 +0200213 if (local->open_count)
214 ieee80211_stop_device(local);
Johannes Berg89c3a8a2009-07-28 18:10:17 +0200215
Johannes Bergeecc4802011-05-04 15:37:29 +0200216 suspend:
Johannes Berg5bb644a2009-05-17 11:40:42 +0200217 local->suspended = true;
Johannes Berg89c3a8a2009-07-28 18:10:17 +0200218 /* need suspended to be visible before quiescing is false */
219 barrier();
Johannes Berg5bb644a2009-05-17 11:40:42 +0200220 local->quiescing = false;
Bob Copelande874e652009-01-24 13:21:14 -0500221
Bob Copeland665af4f2009-01-19 11:20:53 -0500222 return 0;
223}
224
Johannes Bergf2753dd2009-04-14 10:09:24 +0200225/*
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 */