blob: 712c17ff6e2228e605d443b16546f50dfeae70eb [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 Berg529ba6e2012-12-13 17:16:45 +0100124 u32 changed = BSS_CHANGED_BEACON_ENABLED;
125
Johannes Berg9607e6b2009-12-23 13:15:31 +0100126 if (!ieee80211_sdata_running(sdata))
Johannes Berg5bb644a2009-05-17 11:40:42 +0200127 continue;
128
Johannes Berg61e8a482012-12-13 16:47:42 +0100129 switch (sdata->vif.type) {
130 case NL80211_IFTYPE_AP_VLAN:
131 case NL80211_IFTYPE_MONITOR:
132 /* skip these */
133 continue;
Johannes Berg529ba6e2012-12-13 17:16:45 +0100134 case NL80211_IFTYPE_STATION:
135 if (sdata->vif.bss_conf.assoc)
136 changed = BSS_CHANGED_ASSOC |
137 BSS_CHANGED_BSSID |
138 BSS_CHANGED_IDLE;
139 else
140 changed = 0;
141 /* fall through */
Johannes Berg61e8a482012-12-13 16:47:42 +0100142 default:
143 ieee80211_quiesce(sdata);
144 break;
145 }
146
Johannes Berg529ba6e2012-12-13 17:16:45 +0100147 sdata->suspend_bss_conf = sdata->vif.bss_conf;
148 memset(&sdata->vif.bss_conf, 0, sizeof(sdata->vif.bss_conf));
149 sdata->vif.bss_conf.idle = true;
150
151 /* disable beaconing or remove association */
152 ieee80211_bss_info_change_notify(sdata, changed);
Bob Copeland97af7432009-07-29 10:13:03 +0200153
Johannes Berg10416382012-10-19 15:44:42 +0200154 if (sdata->vif.type == NL80211_IFTYPE_AP &&
155 rcu_access_pointer(sdata->u.ap.beacon))
156 drv_stop_ap(local, sdata);
157
Johannes Bergfe5f2552012-11-19 22:19:08 +0100158 if (local->use_chanctx) {
159 struct ieee80211_chanctx_conf *conf;
160
161 mutex_lock(&local->chanctx_mtx);
162 conf = rcu_dereference_protected(
163 sdata->vif.chanctx_conf,
164 lockdep_is_held(&local->chanctx_mtx));
165 if (conf) {
166 ctx = container_of(conf,
167 struct ieee80211_chanctx,
168 conf);
169 drv_unassign_vif_chanctx(local, sdata, ctx);
170 }
171
172 mutex_unlock(&local->chanctx_mtx);
173 }
Johannes Berg7b7eab62011-11-03 14:41:13 +0100174 drv_remove_interface(local, sdata);
Bob Copeland665af4f2009-01-19 11:20:53 -0500175 }
176
Johannes Berg4b6f1dd2012-04-03 14:35:57 +0200177 sdata = rtnl_dereference(local->monitor_sdata);
Johannes Bergfe5f2552012-11-19 22:19:08 +0100178 if (sdata) {
179 if (local->use_chanctx) {
180 struct ieee80211_chanctx_conf *conf;
181
182 mutex_lock(&local->chanctx_mtx);
183 conf = rcu_dereference_protected(
184 sdata->vif.chanctx_conf,
185 lockdep_is_held(&local->chanctx_mtx));
186 if (conf) {
187 ctx = container_of(conf,
188 struct ieee80211_chanctx,
189 conf);
190 drv_unassign_vif_chanctx(local, sdata, ctx);
191 }
192
193 mutex_unlock(&local->chanctx_mtx);
194 }
195
Johannes Berg4b6f1dd2012-04-03 14:35:57 +0200196 drv_remove_interface(local, sdata);
Johannes Bergfe5f2552012-11-19 22:19:08 +0100197 }
198
199 mutex_lock(&local->chanctx_mtx);
200 list_for_each_entry(ctx, &local->chanctx_list, list)
201 drv_remove_chanctx(local, ctx);
202 mutex_unlock(&local->chanctx_mtx);
Johannes Berg4b6f1dd2012-04-03 14:35:57 +0200203
Johannes Berg89c3a8a2009-07-28 18:10:17 +0200204 /* stop hardware - this must stop RX */
Johannes Berg84f6a012009-08-20 20:02:20 +0200205 if (local->open_count)
206 ieee80211_stop_device(local);
Johannes Berg89c3a8a2009-07-28 18:10:17 +0200207
Johannes Bergeecc4802011-05-04 15:37:29 +0200208 suspend:
Johannes Berg5bb644a2009-05-17 11:40:42 +0200209 local->suspended = true;
Johannes Berg89c3a8a2009-07-28 18:10:17 +0200210 /* need suspended to be visible before quiescing is false */
211 barrier();
Johannes Berg5bb644a2009-05-17 11:40:42 +0200212 local->quiescing = false;
Bob Copelande874e652009-01-24 13:21:14 -0500213
Bob Copeland665af4f2009-01-19 11:20:53 -0500214 return 0;
215}
216
Johannes Bergf2753dd2009-04-14 10:09:24 +0200217/*
218 * __ieee80211_resume() is a static inline which just calls
219 * ieee80211_reconfig(), which is also needed for hardware
220 * hang/firmware failure/etc. recovery.
221 */