blob: 0ccb5701c7f398377077d0ab3985f66b9f380837 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Johannes Berga05829a2021-01-22 16:19:43 +01002/*
3 * Portions
4 * Copyright (C) 2020-2021 Intel Corporation
5 */
Bob Copeland665af4f2009-01-19 11:20:53 -05006#include <net/mac80211.h>
7#include <net/rtnetlink.h>
8
9#include "ieee80211_i.h"
Johannes Berg5bb644a2009-05-17 11:40:42 +020010#include "mesh.h"
Johannes Berg24487982009-04-23 18:52:52 +020011#include "driver-ops.h"
Bob Copeland665af4f2009-01-19 11:20:53 -050012#include "led.h"
13
Eliad Peller0d440ea2015-10-25 10:59:33 +020014static void ieee80211_sched_scan_cancel(struct ieee80211_local *local)
15{
16 if (ieee80211_request_sched_scan_stop(local))
17 return;
Johannes Berga05829a2021-01-22 16:19:43 +010018 cfg80211_sched_scan_stopped_locked(local->hw.wiphy, 0);
Eliad Peller0d440ea2015-10-25 10:59:33 +020019}
20
Johannes Bergeecc4802011-05-04 15:37:29 +020021int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
Bob Copeland665af4f2009-01-19 11:20:53 -050022{
23 struct ieee80211_local *local = hw_to_local(hw);
24 struct ieee80211_sub_if_data *sdata;
Bob Copeland665af4f2009-01-19 11:20:53 -050025 struct sta_info *sta;
26
Johannes Berg94f9b972011-07-14 16:48:54 +020027 if (!local->open_count)
28 goto suspend;
29
Loic Poulainb33fb282021-10-21 10:45:27 +020030 local->suspending = true;
31 mb(); /* make suspending visible before any cancellation */
32
Stanislaw Gruszka4136c422010-10-06 11:22:10 +020033 ieee80211_scan_cancel(local);
Johannes Berg5bb644a2009-05-17 11:40:42 +020034
Simon Wunderlich164eb022013-02-08 18:16:20 +010035 ieee80211_dfs_cac_cancel(local);
36
Johannes Bergc8f994e2013-03-27 22:49:19 +010037 ieee80211_roc_purge(local, NULL);
38
Johannes Berg3c3e21e2013-03-27 23:20:27 +010039 ieee80211_del_virtual_monitor(local);
40
Eliad Peller27392712015-09-21 15:50:26 +030041 if (ieee80211_hw_check(hw, AMPDU_AGGREGATION) &&
42 !(wowlan && wowlan->any)) {
Johannes Bergca45de72011-04-21 13:38:00 +020043 mutex_lock(&local->sta_mtx);
44 list_for_each_entry(sta, &local->sta_list, list) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +020045 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
Johannes Bergc82c4a82012-07-18 13:31:31 +020046 ieee80211_sta_tear_down_BA_sessions(
47 sta, AGG_STOP_LOCAL_REQUEST);
Johannes Bergca45de72011-04-21 13:38:00 +020048 }
49 mutex_unlock(&local->sta_mtx);
50 }
51
Eliad Peller0d440ea2015-10-25 10:59:33 +020052 /* keep sched_scan only in case of 'any' trigger */
53 if (!(wowlan && wowlan->any))
54 ieee80211_sched_scan_cancel(local);
55
Johannes Berg25420602009-03-13 11:43:36 +010056 ieee80211_stop_queues_by_reason(hw,
Johannes Berg445ea4e2013-02-13 12:25:28 +010057 IEEE80211_MAX_QUEUE_MAP,
Luciano Coelhocca07b02014-06-13 16:30:05 +030058 IEEE80211_QUEUE_STOP_REASON_SUSPEND,
59 false);
Johannes Berg25420602009-03-13 11:43:36 +010060
Johannes Bergd34ba212013-12-04 22:46:11 +010061 /* flush out all packets */
Bob Copeland8ceb5952013-04-18 18:26:49 -040062 synchronize_net();
Johannes Berg5bb644a2009-05-17 11:40:42 +020063
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +020064 ieee80211_flush_queues(local, NULL, true);
Johannes Bergca45de72011-04-21 13:38:00 +020065
Johannes Berg5bb644a2009-05-17 11:40:42 +020066 local->quiescing = true;
67 /* make quiescing visible to timers everywhere */
68 mb();
69
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -040070 flush_workqueue(local->workqueue);
Bob Copeland665af4f2009-01-19 11:20:53 -050071
Johannes Berg5bb644a2009-05-17 11:40:42 +020072 /* Don't try to run timers while suspended. */
73 del_timer_sync(&local->sta_cleanup);
74
75 /*
76 * Note that this particular timer doesn't need to be
77 * restarted at resume.
78 */
79 cancel_work_sync(&local->dynamic_ps_enable_work);
80 del_timer_sync(&local->dynamic_ps_timer);
81
Luciano Coelho8bb6f4b2015-03-01 09:10:07 +020082 local->wowlan = wowlan;
Johannes Bergeecc4802011-05-04 15:37:29 +020083 if (local->wowlan) {
Johannes Bergef7c6722015-03-01 09:10:06 +020084 int err;
85
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
90 * that on its own.
91 * Thus, clean up in-progress auth/assoc first.
92 */
93 list_for_each_entry(sdata, &local->interfaces, list) {
94 if (!ieee80211_sdata_running(sdata))
95 continue;
96 if (sdata->vif.type != NL80211_IFTYPE_STATION)
97 continue;
98 ieee80211_mgd_quiesce(sdata);
Chaitanya T K541b6ed2015-06-10 19:12:31 +053099 /* 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.
107 */
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);
114 }
Johannes Bergef7c6722015-03-01 09:10:06 +0200115 }
116
117 err = drv_suspend(local, wowlan);
Johannes Berg2b4562d2011-07-02 00:02:01 +0200118 if (err < 0) {
Johannes Bergeecc4802011-05-04 15:37:29 +0200119 local->quiescing = false;
Pontus Fuchs3b08cf62012-05-31 12:34:47 +0200120 local->wowlan = false;
Johannes Berg30686bf2015-06-02 21:39:54 +0200121 if (ieee80211_hw_check(hw, AMPDU_AGGREGATION)) {
Eyal Shapira9ea4fa12012-06-20 13:10:14 +0300122 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);
126 }
127 mutex_unlock(&local->sta_mtx);
128 }
129 ieee80211_wake_queues_by_reason(hw,
Johannes Berg445ea4e2013-02-13 12:25:28 +0100130 IEEE80211_MAX_QUEUE_MAP,
Luciano Coelhocca07b02014-06-13 16:30:05 +0300131 IEEE80211_QUEUE_STOP_REASON_SUSPEND,
132 false);
Johannes Bergeecc4802011-05-04 15:37:29 +0200133 return err;
Johannes Berg2b4562d2011-07-02 00:02:01 +0200134 } else if (err > 0) {
135 WARN_ON(err != 1);
Johannes Berg23e37092015-03-01 09:10:08 +0200136 /* cfg80211 will call back into mac80211 to disconnect
137 * all interfaces, allow that to proceed properly
138 */
139 ieee80211_wake_queues_by_reason(hw,
140 IEEE80211_MAX_QUEUE_MAP,
141 IEEE80211_QUEUE_STOP_REASON_SUSPEND,
142 false);
Stanislaw Gruszka81256962013-02-28 10:55:25 +0100143 return err;
Johannes Berg2b4562d2011-07-02 00:02:01 +0200144 } else {
Johannes Berg2b4562d2011-07-02 00:02:01 +0200145 goto suspend;
Johannes Bergeecc4802011-05-04 15:37:29 +0200146 }
Johannes Bergeecc4802011-05-04 15:37:29 +0200147 }
148
Stanislaw Gruszkacd34f642013-07-23 13:56:50 +0200149 /* remove all interfaces that were created in the driver */
Bob Copeland665af4f2009-01-19 11:20:53 -0500150 list_for_each_entry(sdata, &local->interfaces, list) {
Johannes Berg1a1cb742014-03-19 09:55:55 +0100151 if (!ieee80211_sdata_running(sdata))
Johannes Berg5bb644a2009-05-17 11:40:42 +0200152 continue;
Johannes Berg1a1cb742014-03-19 09:55:55 +0100153 switch (sdata->vif.type) {
154 case NL80211_IFTYPE_AP_VLAN:
155 case NL80211_IFTYPE_MONITOR:
156 continue;
157 case NL80211_IFTYPE_STATION:
158 ieee80211_mgd_quiesce(sdata);
159 break;
160 default:
161 break;
162 }
Stanislaw Gruszkacd34f642013-07-23 13:56:50 +0200163
Matt Chena9e92002017-01-22 02:16:58 +0800164 flush_delayed_work(&sdata->dec_tailroom_needed_wk);
Johannes Berg7b7eab62011-11-03 14:41:13 +0100165 drv_remove_interface(local, sdata);
Bob Copeland665af4f2009-01-19 11:20:53 -0500166 }
167
Stanislaw Gruszka12e7f512013-02-28 10:55:26 +0100168 /*
169 * We disconnected on all interfaces before suspend, all channel
170 * contexts should be released.
171 */
172 WARN_ON(!list_empty(&local->chanctx_list));
Johannes Berg4b6f1dd2012-04-03 14:35:57 +0200173
Johannes Berg89c3a8a2009-07-28 18:10:17 +0200174 /* stop hardware - this must stop RX */
Johannes Berg4854f172016-09-13 15:39:29 +0200175 ieee80211_stop_device(local);
Johannes Berg89c3a8a2009-07-28 18:10:17 +0200176
Johannes Bergeecc4802011-05-04 15:37:29 +0200177 suspend:
Johannes Berg5bb644a2009-05-17 11:40:42 +0200178 local->suspended = true;
Johannes Berg89c3a8a2009-07-28 18:10:17 +0200179 /* need suspended to be visible before quiescing is false */
180 barrier();
Johannes Berg5bb644a2009-05-17 11:40:42 +0200181 local->quiescing = false;
Loic Poulainb33fb282021-10-21 10:45:27 +0200182 local->suspending = false;
Bob Copelande874e652009-01-24 13:21:14 -0500183
Bob Copeland665af4f2009-01-19 11:20:53 -0500184 return 0;
185}
186
Johannes Bergf2753dd2009-04-14 10:09:24 +0200187/*
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.
191 */
Johannes Bergcd8f7cb2013-01-22 12:34:29 +0100192
193void ieee80211_report_wowlan_wakeup(struct ieee80211_vif *vif,
194 struct cfg80211_wowlan_wakeup *wakeup,
195 gfp_t gfp)
196{
197 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
198
199 cfg80211_report_wowlan_wakeup(&sdata->wdev, wakeup, gfp);
200}
201EXPORT_SYMBOL(ieee80211_report_wowlan_wakeup);