1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright (C) 2020-2021 Intel Corporation
6 #include <net/mac80211.h>
7 #include <net/rtnetlink.h>
9 #include "ieee80211_i.h"
11 #include "driver-ops.h"
14 static void ieee80211_sched_scan_cancel(struct ieee80211_local *local)
16 if (ieee80211_request_sched_scan_stop(local))
18 cfg80211_sched_scan_stopped_locked(local->hw.wiphy, 0);
21 int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
23 struct ieee80211_local *local = hw_to_local(hw);
24 struct ieee80211_sub_if_data *sdata;
27 if (!local->open_count)
30 local->suspending = true;
31 mb(); /* make suspending visible before any cancellation */
33 ieee80211_scan_cancel(local);
35 ieee80211_dfs_cac_cancel(local);
37 ieee80211_roc_purge(local, NULL);
39 ieee80211_del_virtual_monitor(local);
41 if (ieee80211_hw_check(hw, AMPDU_AGGREGATION) &&
42 !(wowlan && wowlan->any)) {
43 mutex_lock(&local->sta_mtx);
44 list_for_each_entry(sta, &local->sta_list, list) {
45 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
46 ieee80211_sta_tear_down_BA_sessions(
47 sta, AGG_STOP_LOCAL_REQUEST);
49 mutex_unlock(&local->sta_mtx);
52 /* keep sched_scan only in case of 'any' trigger */
53 if (!(wowlan && wowlan->any))
54 ieee80211_sched_scan_cancel(local);
56 ieee80211_stop_queues_by_reason(hw,
57 IEEE80211_MAX_QUEUE_MAP,
58 IEEE80211_QUEUE_STOP_REASON_SUSPEND,
61 /* flush out all packets */
64 ieee80211_flush_queues(local, NULL, true);
66 local->quiescing = true;
67 /* make quiescing visible to timers everywhere */
70 flush_workqueue(local->workqueue);
72 /* Don't try to run timers while suspended. */
73 del_timer_sync(&local->sta_cleanup);
76 * Note that this particular timer doesn't need to be
77 * restarted at resume.
79 cancel_work_sync(&local->dynamic_ps_enable_work);
80 del_timer_sync(&local->dynamic_ps_timer);
82 local->wowlan = wowlan;
86 /* Drivers don't expect to suspend while some operations like
87 * authenticating or associating are in progress. It doesn't
88 * make sense anyway to accept that, since the authentication
89 * or association would never finish since the driver can't do
91 * Thus, clean up in-progress auth/assoc first.
93 list_for_each_entry(sdata, &local->interfaces, list) {
94 if (!ieee80211_sdata_running(sdata))
96 if (sdata->vif.type != NL80211_IFTYPE_STATION)
98 ieee80211_mgd_quiesce(sdata);
99 /* If suspended during TX in progress, and wowlan
100 * is enabled (connection will be active) there
101 * can be a race where the driver is put out
102 * of power-save due to TX and during suspend
103 * dynamic_ps_timer is cancelled and TX packet
104 * is flushed, leaving the driver in ACTIVE even
105 * after resuming until dynamic_ps_timer puts
106 * driver back in DOZE.
108 if (sdata->u.mgd.associated &&
109 sdata->u.mgd.powersave &&
110 !(local->hw.conf.flags & IEEE80211_CONF_PS)) {
111 local->hw.conf.flags |= IEEE80211_CONF_PS;
112 ieee80211_hw_config(local,
113 IEEE80211_CONF_CHANGE_PS);
117 err = drv_suspend(local, wowlan);
119 local->quiescing = false;
120 local->wowlan = false;
121 if (ieee80211_hw_check(hw, AMPDU_AGGREGATION)) {
122 mutex_lock(&local->sta_mtx);
123 list_for_each_entry(sta,
124 &local->sta_list, list) {
125 clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
127 mutex_unlock(&local->sta_mtx);
129 ieee80211_wake_queues_by_reason(hw,
130 IEEE80211_MAX_QUEUE_MAP,
131 IEEE80211_QUEUE_STOP_REASON_SUSPEND,
134 } else if (err > 0) {
136 /* cfg80211 will call back into mac80211 to disconnect
137 * all interfaces, allow that to proceed properly
139 ieee80211_wake_queues_by_reason(hw,
140 IEEE80211_MAX_QUEUE_MAP,
141 IEEE80211_QUEUE_STOP_REASON_SUSPEND,
149 /* remove all interfaces that were created in the driver */
150 list_for_each_entry(sdata, &local->interfaces, list) {
151 if (!ieee80211_sdata_running(sdata))
153 switch (sdata->vif.type) {
154 case NL80211_IFTYPE_AP_VLAN:
155 case NL80211_IFTYPE_MONITOR:
157 case NL80211_IFTYPE_STATION:
158 ieee80211_mgd_quiesce(sdata);
164 flush_delayed_work(&sdata->dec_tailroom_needed_wk);
165 drv_remove_interface(local, sdata);
169 * We disconnected on all interfaces before suspend, all channel
170 * contexts should be released.
172 WARN_ON(!list_empty(&local->chanctx_list));
174 /* stop hardware - this must stop RX */
175 ieee80211_stop_device(local);
178 local->suspended = true;
179 /* need suspended to be visible before quiescing is false */
181 local->quiescing = false;
182 local->suspending = false;
188 * __ieee80211_resume() is a static inline which just calls
189 * ieee80211_reconfig(), which is also needed for hardware
190 * hang/firmware failure/etc. recovery.
193 void ieee80211_report_wowlan_wakeup(struct ieee80211_vif *vif,
194 struct cfg80211_wowlan_wakeup *wakeup,
197 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
199 cfg80211_report_wowlan_wakeup(&sdata->wdev, wakeup, gfp);
201 EXPORT_SYMBOL(ieee80211_report_wowlan_wakeup);