1 #include <net/mac80211.h>
2 #include <net/rtnetlink.h>
4 #include "ieee80211_i.h"
6 #include "driver-ops.h"
9 /* return value indicates whether the driver should be further notified */
10 static void ieee80211_quiesce(struct ieee80211_sub_if_data *sdata)
12 switch (sdata->vif.type) {
13 case NL80211_IFTYPE_STATION:
14 ieee80211_sta_quiesce(sdata);
16 case NL80211_IFTYPE_ADHOC:
17 ieee80211_ibss_quiesce(sdata);
19 case NL80211_IFTYPE_MESH_POINT:
20 ieee80211_mesh_quiesce(sdata);
26 cancel_work_sync(&sdata->work);
29 int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
31 struct ieee80211_local *local = hw_to_local(hw);
32 struct ieee80211_sub_if_data *sdata;
34 struct ieee80211_chanctx *ctx;
36 if (!local->open_count)
39 ieee80211_scan_cancel(local);
41 if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
42 mutex_lock(&local->sta_mtx);
43 list_for_each_entry(sta, &local->sta_list, list) {
44 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
45 ieee80211_sta_tear_down_BA_sessions(sta, true);
47 mutex_unlock(&local->sta_mtx);
50 ieee80211_stop_queues_by_reason(hw,
51 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
53 /* flush out all packets */
56 drv_flush(local, false);
58 local->quiescing = true;
59 /* make quiescing visible to timers everywhere */
62 flush_workqueue(local->workqueue);
64 /* Don't try to run timers while suspended. */
65 del_timer_sync(&local->sta_cleanup);
68 * Note that this particular timer doesn't need to be
69 * restarted at resume.
71 cancel_work_sync(&local->dynamic_ps_enable_work);
72 del_timer_sync(&local->dynamic_ps_timer);
74 local->wowlan = wowlan && local->open_count;
76 int err = drv_suspend(local, wowlan);
78 local->quiescing = false;
79 local->wowlan = false;
80 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);
86 mutex_unlock(&local->sta_mtx);
88 ieee80211_wake_queues_by_reason(hw,
89 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
93 local->wowlan = false;
95 list_for_each_entry(sdata, &local->interfaces, list)
96 if (ieee80211_sdata_running(sdata))
97 ieee80211_quiesce(sdata);
103 list_for_each_entry(sdata, &local->interfaces, list)
104 ieee80211_disable_keys(sdata);
106 /* tear down aggregation sessions and remove STAs */
107 mutex_lock(&local->sta_mtx);
108 list_for_each_entry(sta, &local->sta_list, list) {
110 enum ieee80211_sta_state state;
112 state = sta->sta_state;
113 for (; state > IEEE80211_STA_NOTEXIST; state--)
114 WARN_ON(drv_sta_state(local, sta->sdata, sta,
118 mesh_plink_quiesce(sta);
120 mutex_unlock(&local->sta_mtx);
122 /* remove all interfaces */
123 list_for_each_entry(sdata, &local->interfaces, list) {
124 static u8 zero_addr[ETH_ALEN] = {};
127 if (!ieee80211_sdata_running(sdata))
130 switch (sdata->vif.type) {
131 case NL80211_IFTYPE_AP_VLAN:
132 case NL80211_IFTYPE_MONITOR:
135 case NL80211_IFTYPE_STATION:
136 if (sdata->vif.bss_conf.assoc)
137 changed = BSS_CHANGED_ASSOC |
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;
151 ieee80211_quiesce(sdata);
153 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;
156 if (sdata->suspend_bss_conf.bssid)
157 sdata->vif.bss_conf.bssid = zero_addr;
159 /* disable beaconing or remove association */
160 ieee80211_bss_info_change_notify(sdata, changed);
162 if (sdata->vif.type == NL80211_IFTYPE_AP &&
163 rcu_access_pointer(sdata->u.ap.beacon))
164 drv_stop_ap(local, sdata);
166 if (local->use_chanctx) {
167 struct ieee80211_chanctx_conf *conf;
169 mutex_lock(&local->chanctx_mtx);
170 conf = rcu_dereference_protected(
171 sdata->vif.chanctx_conf,
172 lockdep_is_held(&local->chanctx_mtx));
174 ctx = container_of(conf,
175 struct ieee80211_chanctx,
177 drv_unassign_vif_chanctx(local, sdata, ctx);
180 mutex_unlock(&local->chanctx_mtx);
182 drv_remove_interface(local, sdata);
185 sdata = rtnl_dereference(local->monitor_sdata);
187 if (local->use_chanctx) {
188 struct ieee80211_chanctx_conf *conf;
190 mutex_lock(&local->chanctx_mtx);
191 conf = rcu_dereference_protected(
192 sdata->vif.chanctx_conf,
193 lockdep_is_held(&local->chanctx_mtx));
195 ctx = container_of(conf,
196 struct ieee80211_chanctx,
198 drv_unassign_vif_chanctx(local, sdata, ctx);
201 mutex_unlock(&local->chanctx_mtx);
204 drv_remove_interface(local, sdata);
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);
212 /* stop hardware - this must stop RX */
213 if (local->open_count)
214 ieee80211_stop_device(local);
217 local->suspended = true;
218 /* need suspended to be visible before quiescing is false */
220 local->quiescing = false;
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.