blob: d0275f34bf700397702f0f752d15388cc515d281 [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
Simon Wunderlich164eb022013-02-08 18:16:20 +010041 ieee80211_dfs_cac_cancel(local);
42
Johannes Bergca45de72011-04-21 13:38:00 +020043 if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
44 mutex_lock(&local->sta_mtx);
45 list_for_each_entry(sta, &local->sta_list, list) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +020046 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
Johannes Bergc82c4a82012-07-18 13:31:31 +020047 ieee80211_sta_tear_down_BA_sessions(
48 sta, AGG_STOP_LOCAL_REQUEST);
Johannes Bergca45de72011-04-21 13:38:00 +020049 }
50 mutex_unlock(&local->sta_mtx);
51 }
52
Johannes Berg25420602009-03-13 11:43:36 +010053 ieee80211_stop_queues_by_reason(hw,
54 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
55
Johannes Berg5bb644a2009-05-17 11:40:42 +020056 /* flush out all packets */
57 synchronize_net();
58
Johannes Bergca45de72011-04-21 13:38:00 +020059 drv_flush(local, false);
60
Johannes Berg5bb644a2009-05-17 11:40:42 +020061 local->quiescing = true;
62 /* make quiescing visible to timers everywhere */
63 mb();
64
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -040065 flush_workqueue(local->workqueue);
Bob Copeland665af4f2009-01-19 11:20:53 -050066
Johannes Berg5bb644a2009-05-17 11:40:42 +020067 /* Don't try to run timers while suspended. */
68 del_timer_sync(&local->sta_cleanup);
69
70 /*
71 * Note that this particular timer doesn't need to be
72 * restarted at resume.
73 */
74 cancel_work_sync(&local->dynamic_ps_enable_work);
75 del_timer_sync(&local->dynamic_ps_timer);
76
Johannes Bergeecc4802011-05-04 15:37:29 +020077 local->wowlan = wowlan && local->open_count;
78 if (local->wowlan) {
79 int err = drv_suspend(local, wowlan);
Johannes Berg2b4562d2011-07-02 00:02:01 +020080 if (err < 0) {
Johannes Bergeecc4802011-05-04 15:37:29 +020081 local->quiescing = false;
Pontus Fuchs3b08cf62012-05-31 12:34:47 +020082 local->wowlan = false;
Eyal Shapira9ea4fa12012-06-20 13:10:14 +030083 if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
84 mutex_lock(&local->sta_mtx);
85 list_for_each_entry(sta,
86 &local->sta_list, list) {
87 clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
88 }
89 mutex_unlock(&local->sta_mtx);
90 }
91 ieee80211_wake_queues_by_reason(hw,
92 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
Johannes Bergeecc4802011-05-04 15:37:29 +020093 return err;
Johannes Berg2b4562d2011-07-02 00:02:01 +020094 } else if (err > 0) {
95 WARN_ON(err != 1);
96 local->wowlan = false;
97 } else {
Johannes Berg61e8a482012-12-13 16:47:42 +010098 list_for_each_entry(sdata, &local->interfaces, list)
99 if (ieee80211_sdata_running(sdata))
100 ieee80211_quiesce(sdata);
Johannes Berg2b4562d2011-07-02 00:02:01 +0200101 goto suspend;
Johannes Bergeecc4802011-05-04 15:37:29 +0200102 }
Johannes Bergeecc4802011-05-04 15:37:29 +0200103 }
104
Bob Copeland665af4f2009-01-19 11:20:53 -0500105 /* disable keys */
106 list_for_each_entry(sdata, &local->interfaces, list)
107 ieee80211_disable_keys(sdata);
108
Johannes Berg2a419052010-06-10 10:21:29 +0200109 /* tear down aggregation sessions and remove STAs */
110 mutex_lock(&local->sta_mtx);
111 list_for_each_entry(sta, &local->sta_list, list) {
Johannes Bergf09603a2012-01-20 13:55:21 +0100112 if (sta->uploaded) {
113 enum ieee80211_sta_state state;
114
Johannes Bergf09603a2012-01-20 13:55:21 +0100115 state = sta->sta_state;
116 for (; state > IEEE80211_STA_NOTEXIST; state--)
Jakub Kicinski9d88c7f2012-02-23 02:17:48 +0100117 WARN_ON(drv_sta_state(local, sta->sdata, sta,
Johannes Bergf09603a2012-01-20 13:55:21 +0100118 state, state - 1));
119 }
120
Johannes Berg5bb644a2009-05-17 11:40:42 +0200121 mesh_plink_quiesce(sta);
Bob Copeland665af4f2009-01-19 11:20:53 -0500122 }
Johannes Berg34e89502010-02-03 13:59:58 +0100123 mutex_unlock(&local->sta_mtx);
Bob Copeland665af4f2009-01-19 11:20:53 -0500124
125 /* remove all interfaces */
126 list_for_each_entry(sdata, &local->interfaces, list) {
Johannes Bergad2d2232012-12-14 14:34:25 +0100127 static u8 zero_addr[ETH_ALEN] = {};
Johannes Bergb8dc1a32012-12-14 14:22:10 +0100128 u32 changed = 0;
Johannes Berg529ba6e2012-12-13 17:16:45 +0100129
Johannes Berg9607e6b2009-12-23 13:15:31 +0100130 if (!ieee80211_sdata_running(sdata))
Johannes Berg5bb644a2009-05-17 11:40:42 +0200131 continue;
132
Johannes Berg61e8a482012-12-13 16:47:42 +0100133 switch (sdata->vif.type) {
134 case NL80211_IFTYPE_AP_VLAN:
135 case NL80211_IFTYPE_MONITOR:
136 /* skip these */
137 continue;
Johannes Berg529ba6e2012-12-13 17:16:45 +0100138 case NL80211_IFTYPE_STATION:
139 if (sdata->vif.bss_conf.assoc)
140 changed = BSS_CHANGED_ASSOC |
141 BSS_CHANGED_BSSID |
142 BSS_CHANGED_IDLE;
Johannes Bergb8dc1a32012-12-14 14:22:10 +0100143 break;
144 case NL80211_IFTYPE_AP:
145 case NL80211_IFTYPE_ADHOC:
146 case NL80211_IFTYPE_MESH_POINT:
147 if (sdata->vif.bss_conf.enable_beacon)
148 changed = BSS_CHANGED_BEACON_ENABLED;
149 break;
Johannes Berg61e8a482012-12-13 16:47:42 +0100150 default:
Johannes Berg61e8a482012-12-13 16:47:42 +0100151 break;
152 }
153
Johannes Bergb8dc1a32012-12-14 14:22:10 +0100154 ieee80211_quiesce(sdata);
155
Johannes Berg529ba6e2012-12-13 17:16:45 +0100156 sdata->suspend_bss_conf = sdata->vif.bss_conf;
157 memset(&sdata->vif.bss_conf, 0, sizeof(sdata->vif.bss_conf));
158 sdata->vif.bss_conf.idle = true;
Johannes Bergad2d2232012-12-14 14:34:25 +0100159 if (sdata->suspend_bss_conf.bssid)
160 sdata->vif.bss_conf.bssid = zero_addr;
Johannes Berg529ba6e2012-12-13 17:16:45 +0100161
162 /* disable beaconing or remove association */
163 ieee80211_bss_info_change_notify(sdata, changed);
Bob Copeland97af7432009-07-29 10:13:03 +0200164
Johannes Berg10416382012-10-19 15:44:42 +0200165 if (sdata->vif.type == NL80211_IFTYPE_AP &&
166 rcu_access_pointer(sdata->u.ap.beacon))
167 drv_stop_ap(local, sdata);
168
Johannes Bergfe5f2552012-11-19 22:19:08 +0100169 if (local->use_chanctx) {
170 struct ieee80211_chanctx_conf *conf;
171
172 mutex_lock(&local->chanctx_mtx);
173 conf = rcu_dereference_protected(
174 sdata->vif.chanctx_conf,
175 lockdep_is_held(&local->chanctx_mtx));
176 if (conf) {
177 ctx = container_of(conf,
178 struct ieee80211_chanctx,
179 conf);
180 drv_unassign_vif_chanctx(local, sdata, ctx);
181 }
182
183 mutex_unlock(&local->chanctx_mtx);
184 }
Johannes Berg7b7eab62011-11-03 14:41:13 +0100185 drv_remove_interface(local, sdata);
Bob Copeland665af4f2009-01-19 11:20:53 -0500186 }
187
Johannes Berg4b6f1dd2012-04-03 14:35:57 +0200188 sdata = rtnl_dereference(local->monitor_sdata);
Johannes Bergfe5f2552012-11-19 22:19:08 +0100189 if (sdata) {
190 if (local->use_chanctx) {
191 struct ieee80211_chanctx_conf *conf;
192
193 mutex_lock(&local->chanctx_mtx);
194 conf = rcu_dereference_protected(
195 sdata->vif.chanctx_conf,
196 lockdep_is_held(&local->chanctx_mtx));
197 if (conf) {
198 ctx = container_of(conf,
199 struct ieee80211_chanctx,
200 conf);
201 drv_unassign_vif_chanctx(local, sdata, ctx);
202 }
203
204 mutex_unlock(&local->chanctx_mtx);
205 }
206
Johannes Berg4b6f1dd2012-04-03 14:35:57 +0200207 drv_remove_interface(local, sdata);
Johannes Bergfe5f2552012-11-19 22:19:08 +0100208 }
209
210 mutex_lock(&local->chanctx_mtx);
211 list_for_each_entry(ctx, &local->chanctx_list, list)
212 drv_remove_chanctx(local, ctx);
213 mutex_unlock(&local->chanctx_mtx);
Johannes Berg4b6f1dd2012-04-03 14:35:57 +0200214
Johannes Berg89c3a8a2009-07-28 18:10:17 +0200215 /* stop hardware - this must stop RX */
Johannes Berg84f6a012009-08-20 20:02:20 +0200216 if (local->open_count)
217 ieee80211_stop_device(local);
Johannes Berg89c3a8a2009-07-28 18:10:17 +0200218
Johannes Bergeecc4802011-05-04 15:37:29 +0200219 suspend:
Johannes Berg5bb644a2009-05-17 11:40:42 +0200220 local->suspended = true;
Johannes Berg89c3a8a2009-07-28 18:10:17 +0200221 /* need suspended to be visible before quiescing is false */
222 barrier();
Johannes Berg5bb644a2009-05-17 11:40:42 +0200223 local->quiescing = false;
Bob Copelande874e652009-01-24 13:21:14 -0500224
Bob Copeland665af4f2009-01-19 11:20:53 -0500225 return 0;
226}
227
Johannes Bergf2753dd2009-04-14 10:09:24 +0200228/*
229 * __ieee80211_resume() is a static inline which just calls
230 * ieee80211_reconfig(), which is also needed for hardware
231 * hang/firmware failure/etc. recovery.
232 */
Johannes Bergcd8f7cb2013-01-22 12:34:29 +0100233
234void ieee80211_report_wowlan_wakeup(struct ieee80211_vif *vif,
235 struct cfg80211_wowlan_wakeup *wakeup,
236 gfp_t gfp)
237{
238 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
239
240 cfg80211_report_wowlan_wakeup(&sdata->wdev, wakeup, gfp);
241}
242EXPORT_SYMBOL(ieee80211_report_wowlan_wakeup);