blob: 53801d20176de64e64f4a550c053aefc4652c6a4 [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 Bergc82c4a82012-07-18 13:31:31 +020045 ieee80211_sta_tear_down_BA_sessions(
46 sta, AGG_STOP_LOCAL_REQUEST);
Johannes Bergca45de72011-04-21 13:38:00 +020047 }
48 mutex_unlock(&local->sta_mtx);
49 }
50
Johannes Berg25420602009-03-13 11:43:36 +010051 ieee80211_stop_queues_by_reason(hw,
52 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
53
Johannes Berg5bb644a2009-05-17 11:40:42 +020054 /* flush out all packets */
55 synchronize_net();
56
Johannes Bergca45de72011-04-21 13:38:00 +020057 drv_flush(local, false);
58
Johannes Berg5bb644a2009-05-17 11:40:42 +020059 local->quiescing = true;
60 /* make quiescing visible to timers everywhere */
61 mb();
62
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -040063 flush_workqueue(local->workqueue);
Bob Copeland665af4f2009-01-19 11:20:53 -050064
Johannes Berg5bb644a2009-05-17 11:40:42 +020065 /* Don't try to run timers while suspended. */
66 del_timer_sync(&local->sta_cleanup);
67
68 /*
69 * Note that this particular timer doesn't need to be
70 * restarted at resume.
71 */
72 cancel_work_sync(&local->dynamic_ps_enable_work);
73 del_timer_sync(&local->dynamic_ps_timer);
74
Johannes Bergeecc4802011-05-04 15:37:29 +020075 local->wowlan = wowlan && local->open_count;
76 if (local->wowlan) {
77 int err = drv_suspend(local, wowlan);
Johannes Berg2b4562d2011-07-02 00:02:01 +020078 if (err < 0) {
Johannes Bergeecc4802011-05-04 15:37:29 +020079 local->quiescing = false;
Pontus Fuchs3b08cf62012-05-31 12:34:47 +020080 local->wowlan = false;
Eyal Shapira9ea4fa12012-06-20 13:10:14 +030081 if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
82 mutex_lock(&local->sta_mtx);
83 list_for_each_entry(sta,
84 &local->sta_list, list) {
85 clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
86 }
87 mutex_unlock(&local->sta_mtx);
88 }
89 ieee80211_wake_queues_by_reason(hw,
90 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
Johannes Bergeecc4802011-05-04 15:37:29 +020091 return err;
Johannes Berg2b4562d2011-07-02 00:02:01 +020092 } else if (err > 0) {
93 WARN_ON(err != 1);
94 local->wowlan = false;
95 } else {
Johannes Berg61e8a482012-12-13 16:47:42 +010096 list_for_each_entry(sdata, &local->interfaces, list)
97 if (ieee80211_sdata_running(sdata))
98 ieee80211_quiesce(sdata);
Johannes Berg2b4562d2011-07-02 00:02:01 +020099 goto suspend;
Johannes Bergeecc4802011-05-04 15:37:29 +0200100 }
Johannes Bergeecc4802011-05-04 15:37:29 +0200101 }
102
Bob Copeland665af4f2009-01-19 11:20:53 -0500103 /* disable keys */
104 list_for_each_entry(sdata, &local->interfaces, list)
105 ieee80211_disable_keys(sdata);
106
Johannes Berg2a419052010-06-10 10:21:29 +0200107 /* tear down aggregation sessions and remove STAs */
108 mutex_lock(&local->sta_mtx);
109 list_for_each_entry(sta, &local->sta_list, list) {
Johannes Bergf09603a2012-01-20 13:55:21 +0100110 if (sta->uploaded) {
111 enum ieee80211_sta_state state;
112
Johannes Bergf09603a2012-01-20 13:55:21 +0100113 state = sta->sta_state;
114 for (; state > IEEE80211_STA_NOTEXIST; state--)
Jakub Kicinski9d88c7f2012-02-23 02:17:48 +0100115 WARN_ON(drv_sta_state(local, sta->sdata, sta,
Johannes Bergf09603a2012-01-20 13:55:21 +0100116 state, state - 1));
117 }
118
Johannes Berg5bb644a2009-05-17 11:40:42 +0200119 mesh_plink_quiesce(sta);
Bob Copeland665af4f2009-01-19 11:20:53 -0500120 }
Johannes Berg34e89502010-02-03 13:59:58 +0100121 mutex_unlock(&local->sta_mtx);
Bob Copeland665af4f2009-01-19 11:20:53 -0500122
123 /* remove all interfaces */
124 list_for_each_entry(sdata, &local->interfaces, list) {
Johannes Bergad2d2232012-12-14 14:34:25 +0100125 static u8 zero_addr[ETH_ALEN] = {};
Johannes Bergb8dc1a32012-12-14 14:22:10 +0100126 u32 changed = 0;
Johannes Berg529ba6e2012-12-13 17:16:45 +0100127
Johannes Berg9607e6b2009-12-23 13:15:31 +0100128 if (!ieee80211_sdata_running(sdata))
Johannes Berg5bb644a2009-05-17 11:40:42 +0200129 continue;
130
Johannes Berg61e8a482012-12-13 16:47:42 +0100131 switch (sdata->vif.type) {
132 case NL80211_IFTYPE_AP_VLAN:
133 case NL80211_IFTYPE_MONITOR:
134 /* skip these */
135 continue;
Johannes Berg529ba6e2012-12-13 17:16:45 +0100136 case NL80211_IFTYPE_STATION:
137 if (sdata->vif.bss_conf.assoc)
138 changed = BSS_CHANGED_ASSOC |
139 BSS_CHANGED_BSSID |
140 BSS_CHANGED_IDLE;
Johannes Bergb8dc1a32012-12-14 14:22:10 +0100141 break;
142 case NL80211_IFTYPE_AP:
143 case NL80211_IFTYPE_ADHOC:
144 case NL80211_IFTYPE_MESH_POINT:
145 if (sdata->vif.bss_conf.enable_beacon)
146 changed = BSS_CHANGED_BEACON_ENABLED;
147 break;
Johannes Berg61e8a482012-12-13 16:47:42 +0100148 default:
Johannes Berg61e8a482012-12-13 16:47:42 +0100149 break;
150 }
151
Johannes Bergb8dc1a32012-12-14 14:22:10 +0100152 ieee80211_quiesce(sdata);
153
Johannes Berg529ba6e2012-12-13 17:16:45 +0100154 sdata->suspend_bss_conf = sdata->vif.bss_conf;
155 memset(&sdata->vif.bss_conf, 0, sizeof(sdata->vif.bss_conf));
156 sdata->vif.bss_conf.idle = true;
Johannes Bergad2d2232012-12-14 14:34:25 +0100157 if (sdata->suspend_bss_conf.bssid)
158 sdata->vif.bss_conf.bssid = zero_addr;
Johannes Berg529ba6e2012-12-13 17:16:45 +0100159
160 /* disable beaconing or remove association */
161 ieee80211_bss_info_change_notify(sdata, changed);
Bob Copeland97af7432009-07-29 10:13:03 +0200162
Johannes Berg10416382012-10-19 15:44:42 +0200163 if (sdata->vif.type == NL80211_IFTYPE_AP &&
164 rcu_access_pointer(sdata->u.ap.beacon))
165 drv_stop_ap(local, sdata);
166
Johannes Bergfe5f2552012-11-19 22:19:08 +0100167 if (local->use_chanctx) {
168 struct ieee80211_chanctx_conf *conf;
169
170 mutex_lock(&local->chanctx_mtx);
171 conf = rcu_dereference_protected(
172 sdata->vif.chanctx_conf,
173 lockdep_is_held(&local->chanctx_mtx));
174 if (conf) {
175 ctx = container_of(conf,
176 struct ieee80211_chanctx,
177 conf);
178 drv_unassign_vif_chanctx(local, sdata, ctx);
179 }
180
181 mutex_unlock(&local->chanctx_mtx);
182 }
Johannes Berg7b7eab62011-11-03 14:41:13 +0100183 drv_remove_interface(local, sdata);
Bob Copeland665af4f2009-01-19 11:20:53 -0500184 }
185
Johannes Berg4b6f1dd2012-04-03 14:35:57 +0200186 sdata = rtnl_dereference(local->monitor_sdata);
Johannes Bergfe5f2552012-11-19 22:19:08 +0100187 if (sdata) {
188 if (local->use_chanctx) {
189 struct ieee80211_chanctx_conf *conf;
190
191 mutex_lock(&local->chanctx_mtx);
192 conf = rcu_dereference_protected(
193 sdata->vif.chanctx_conf,
194 lockdep_is_held(&local->chanctx_mtx));
195 if (conf) {
196 ctx = container_of(conf,
197 struct ieee80211_chanctx,
198 conf);
199 drv_unassign_vif_chanctx(local, sdata, ctx);
200 }
201
202 mutex_unlock(&local->chanctx_mtx);
203 }
204
Johannes Berg4b6f1dd2012-04-03 14:35:57 +0200205 drv_remove_interface(local, sdata);
Johannes Bergfe5f2552012-11-19 22:19:08 +0100206 }
207
208 mutex_lock(&local->chanctx_mtx);
209 list_for_each_entry(ctx, &local->chanctx_list, list)
210 drv_remove_chanctx(local, ctx);
211 mutex_unlock(&local->chanctx_mtx);
Johannes Berg4b6f1dd2012-04-03 14:35:57 +0200212
Johannes Berg89c3a8a2009-07-28 18:10:17 +0200213 /* stop hardware - this must stop RX */
Johannes Berg84f6a012009-08-20 20:02:20 +0200214 if (local->open_count)
215 ieee80211_stop_device(local);
Johannes Berg89c3a8a2009-07-28 18:10:17 +0200216
Johannes Bergeecc4802011-05-04 15:37:29 +0200217 suspend:
Johannes Berg5bb644a2009-05-17 11:40:42 +0200218 local->suspended = true;
Johannes Berg89c3a8a2009-07-28 18:10:17 +0200219 /* need suspended to be visible before quiescing is false */
220 barrier();
Johannes Berg5bb644a2009-05-17 11:40:42 +0200221 local->quiescing = false;
Bob Copelande874e652009-01-24 13:21:14 -0500222
Bob Copeland665af4f2009-01-19 11:20:53 -0500223 return 0;
224}
225
Johannes Bergf2753dd2009-04-14 10:09:24 +0200226/*
227 * __ieee80211_resume() is a static inline which just calls
228 * ieee80211_reconfig(), which is also needed for hardware
229 * hang/firmware failure/etc. recovery.
230 */
Johannes Bergcd8f7cb2013-01-22 12:34:29 +0100231
232void ieee80211_report_wowlan_wakeup(struct ieee80211_vif *vif,
233 struct cfg80211_wowlan_wakeup *wakeup,
234 gfp_t gfp)
235{
236 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
237
238 cfg80211_report_wowlan_wakeup(&sdata->wdev, wakeup, gfp);
239}
240EXPORT_SYMBOL(ieee80211_report_wowlan_wakeup);