blob: f3217831d23601410efb00f1b2fb3a7826707211 [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 Berg9607e6b2009-12-23 13:15:31 +0100124 if (!ieee80211_sdata_running(sdata))
Johannes Berg5bb644a2009-05-17 11:40:42 +0200125 continue;
126
Johannes Berg61e8a482012-12-13 16:47:42 +0100127 switch (sdata->vif.type) {
128 case NL80211_IFTYPE_AP_VLAN:
129 case NL80211_IFTYPE_MONITOR:
130 /* skip these */
131 continue;
132 default:
133 ieee80211_quiesce(sdata);
134 break;
135 }
136
Bob Copeland97af7432009-07-29 10:13:03 +0200137 /* disable beaconing */
138 ieee80211_bss_info_change_notify(sdata,
139 BSS_CHANGED_BEACON_ENABLED);
140
Johannes Berg10416382012-10-19 15:44:42 +0200141 if (sdata->vif.type == NL80211_IFTYPE_AP &&
142 rcu_access_pointer(sdata->u.ap.beacon))
143 drv_stop_ap(local, sdata);
144
Johannes Bergfe5f2552012-11-19 22:19:08 +0100145 if (local->use_chanctx) {
146 struct ieee80211_chanctx_conf *conf;
147
148 mutex_lock(&local->chanctx_mtx);
149 conf = rcu_dereference_protected(
150 sdata->vif.chanctx_conf,
151 lockdep_is_held(&local->chanctx_mtx));
152 if (conf) {
153 ctx = container_of(conf,
154 struct ieee80211_chanctx,
155 conf);
156 drv_unassign_vif_chanctx(local, sdata, ctx);
157 }
158
159 mutex_unlock(&local->chanctx_mtx);
160 }
Johannes Berg7b7eab62011-11-03 14:41:13 +0100161 drv_remove_interface(local, sdata);
Bob Copeland665af4f2009-01-19 11:20:53 -0500162 }
163
Johannes Berg4b6f1dd2012-04-03 14:35:57 +0200164 sdata = rtnl_dereference(local->monitor_sdata);
Johannes Bergfe5f2552012-11-19 22:19:08 +0100165 if (sdata) {
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 }
182
Johannes Berg4b6f1dd2012-04-03 14:35:57 +0200183 drv_remove_interface(local, sdata);
Johannes Bergfe5f2552012-11-19 22:19:08 +0100184 }
185
186 mutex_lock(&local->chanctx_mtx);
187 list_for_each_entry(ctx, &local->chanctx_list, list)
188 drv_remove_chanctx(local, ctx);
189 mutex_unlock(&local->chanctx_mtx);
Johannes Berg4b6f1dd2012-04-03 14:35:57 +0200190
Johannes Berg89c3a8a2009-07-28 18:10:17 +0200191 /* stop hardware - this must stop RX */
Johannes Berg84f6a012009-08-20 20:02:20 +0200192 if (local->open_count)
193 ieee80211_stop_device(local);
Johannes Berg89c3a8a2009-07-28 18:10:17 +0200194
Johannes Bergeecc4802011-05-04 15:37:29 +0200195 suspend:
Johannes Berg5bb644a2009-05-17 11:40:42 +0200196 local->suspended = true;
Johannes Berg89c3a8a2009-07-28 18:10:17 +0200197 /* need suspended to be visible before quiescing is false */
198 barrier();
Johannes Berg5bb644a2009-05-17 11:40:42 +0200199 local->quiescing = false;
Bob Copelande874e652009-01-24 13:21:14 -0500200
Bob Copeland665af4f2009-01-19 11:20:53 -0500201 return 0;
202}
203
Johannes Bergf2753dd2009-04-14 10:09:24 +0200204/*
205 * __ieee80211_resume() is a static inline which just calls
206 * ieee80211_reconfig(), which is also needed for hardware
207 * hang/firmware failure/etc. recovery.
208 */