1 #include <net/mac80211.h>
2 #include <net/rtnetlink.h>
4 #include "ieee80211_i.h"
6 #include "driver-ops.h"
9 int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
11 struct ieee80211_local *local = hw_to_local(hw);
12 struct ieee80211_sub_if_data *sdata;
15 if (!local->open_count)
18 ieee80211_scan_cancel(local);
20 ieee80211_dfs_cac_cancel(local);
22 ieee80211_roc_purge(local, NULL);
24 ieee80211_del_virtual_monitor(local);
26 if (ieee80211_hw_check(hw, AMPDU_AGGREGATION) &&
27 !(wowlan && wowlan->any)) {
28 mutex_lock(&local->sta_mtx);
29 list_for_each_entry(sta, &local->sta_list, list) {
30 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
31 ieee80211_sta_tear_down_BA_sessions(
32 sta, AGG_STOP_LOCAL_REQUEST);
34 mutex_unlock(&local->sta_mtx);
37 ieee80211_stop_queues_by_reason(hw,
38 IEEE80211_MAX_QUEUE_MAP,
39 IEEE80211_QUEUE_STOP_REASON_SUSPEND,
42 /* flush out all packets */
45 ieee80211_flush_queues(local, NULL, true);
47 local->quiescing = true;
48 /* make quiescing visible to timers everywhere */
51 flush_workqueue(local->workqueue);
53 /* Don't try to run timers while suspended. */
54 del_timer_sync(&local->sta_cleanup);
57 * Note that this particular timer doesn't need to be
58 * restarted at resume.
60 cancel_work_sync(&local->dynamic_ps_enable_work);
61 del_timer_sync(&local->dynamic_ps_timer);
63 local->wowlan = wowlan;
67 /* Drivers don't expect to suspend while some operations like
68 * authenticating or associating are in progress. It doesn't
69 * make sense anyway to accept that, since the authentication
70 * or association would never finish since the driver can't do
72 * Thus, clean up in-progress auth/assoc first.
74 list_for_each_entry(sdata, &local->interfaces, list) {
75 if (!ieee80211_sdata_running(sdata))
77 if (sdata->vif.type != NL80211_IFTYPE_STATION)
79 ieee80211_mgd_quiesce(sdata);
80 /* If suspended during TX in progress, and wowlan
81 * is enabled (connection will be active) there
82 * can be a race where the driver is put out
83 * of power-save due to TX and during suspend
84 * dynamic_ps_timer is cancelled and TX packet
85 * is flushed, leaving the driver in ACTIVE even
86 * after resuming until dynamic_ps_timer puts
87 * driver back in DOZE.
89 if (sdata->u.mgd.associated &&
90 sdata->u.mgd.powersave &&
91 !(local->hw.conf.flags & IEEE80211_CONF_PS)) {
92 local->hw.conf.flags |= IEEE80211_CONF_PS;
93 ieee80211_hw_config(local,
94 IEEE80211_CONF_CHANGE_PS);
98 err = drv_suspend(local, wowlan);
100 local->quiescing = false;
101 local->wowlan = false;
102 if (ieee80211_hw_check(hw, AMPDU_AGGREGATION)) {
103 mutex_lock(&local->sta_mtx);
104 list_for_each_entry(sta,
105 &local->sta_list, list) {
106 clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
108 mutex_unlock(&local->sta_mtx);
110 ieee80211_wake_queues_by_reason(hw,
111 IEEE80211_MAX_QUEUE_MAP,
112 IEEE80211_QUEUE_STOP_REASON_SUSPEND,
115 } else if (err > 0) {
117 /* cfg80211 will call back into mac80211 to disconnect
118 * all interfaces, allow that to proceed properly
120 ieee80211_wake_queues_by_reason(hw,
121 IEEE80211_MAX_QUEUE_MAP,
122 IEEE80211_QUEUE_STOP_REASON_SUSPEND,
130 /* remove all interfaces that were created in the driver */
131 list_for_each_entry(sdata, &local->interfaces, list) {
132 if (!ieee80211_sdata_running(sdata))
134 switch (sdata->vif.type) {
135 case NL80211_IFTYPE_AP_VLAN:
136 case NL80211_IFTYPE_MONITOR:
138 case NL80211_IFTYPE_STATION:
139 ieee80211_mgd_quiesce(sdata);
141 case NL80211_IFTYPE_WDS:
142 /* tear down aggregation sessions and remove STAs */
143 mutex_lock(&local->sta_mtx);
144 sta = sdata->u.wds.sta;
145 if (sta && sta->uploaded) {
146 enum ieee80211_sta_state state;
148 state = sta->sta_state;
149 for (; state > IEEE80211_STA_NOTEXIST; state--)
150 WARN_ON(drv_sta_state(local, sta->sdata,
154 mutex_unlock(&local->sta_mtx);
160 drv_remove_interface(local, sdata);
164 * We disconnected on all interfaces before suspend, all channel
165 * contexts should be released.
167 WARN_ON(!list_empty(&local->chanctx_list));
169 /* stop hardware - this must stop RX */
170 if (local->open_count)
171 ieee80211_stop_device(local);
174 local->suspended = true;
175 /* need suspended to be visible before quiescing is false */
177 local->quiescing = false;
183 * __ieee80211_resume() is a static inline which just calls
184 * ieee80211_reconfig(), which is also needed for hardware
185 * hang/firmware failure/etc. recovery.
188 void ieee80211_report_wowlan_wakeup(struct ieee80211_vif *vif,
189 struct cfg80211_wowlan_wakeup *wakeup,
192 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
194 cfg80211_report_wowlan_wakeup(&sdata->wdev, wakeup, gfp);
196 EXPORT_SYMBOL(ieee80211_report_wowlan_wakeup);