blob: e50fd3fd8ab0f9d44d6ef7c5e9898bbdbb2cfcb6 [file] [log] [blame]
Johannes Berg8ca151b2013-01-24 14:25:36 +01001/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +02008 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Luciano Coelho9af91f42015-02-10 10:42:26 +02009 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010010 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
23 * USA
24 *
25 * The full GNU General Public License is included in this distribution
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020026 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010027 *
28 * Contact Information:
29 * Intel Linux Wireless <ilw@linux.intel.com>
30 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 *
32 * BSD LICENSE
33 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020034 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Luciano Coelho9af91f42015-02-10 10:42:26 +020035 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010036 * All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 *
42 * * Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * * Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in
46 * the documentation and/or other materials provided with the
47 * distribution.
48 * * Neither the name Intel Corporation nor the names of its
49 * contributors may be used to endorse or promote products derived
50 * from this software without specific prior written permission.
51 *
52 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 *
64 *****************************************************************************/
65
66#include <linux/etherdevice.h>
67#include <net/mac80211.h>
68
69#include "mvm.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010070#include "fw-api-scan.h"
71
Haim Dreyfussa1ed4022014-12-01 23:30:07 +020072#define IWL_DENSE_EBS_SCAN_RATIO 5
73#define IWL_SPARSE_EBS_SCAN_RATIO 1
Alexander Bondar8a110d92014-03-12 17:31:19 +020074
75struct iwl_mvm_scan_params {
76 u32 max_out_time;
77 u32 suspend_time;
Alexander Bondar50df8a32014-03-12 20:30:51 +020078 bool passive_fragmented;
Luciano Coelhof7b788b2015-04-02 00:08:35 +030079 u32 n_channels;
Luciano Coelho283c2492015-04-17 11:18:46 +030080 u16 delay;
Luciano Coelhof7b788b2015-04-02 00:08:35 +030081 int n_ssids;
82 struct cfg80211_ssid *ssids;
83 struct ieee80211_channel **channels;
84 u16 interval; /* interval between scans (in secs) */
85 u32 flags;
86 u8 *mac_addr;
87 u8 *mac_addr_mask;
88 bool no_cck;
89 bool pass_all;
90 int n_match_sets;
Luciano Coelho45d1b122015-04-15 16:34:13 +030091 struct iwl_scan_probe_req preq;
Luciano Coelhof7b788b2015-04-02 00:08:35 +030092 struct cfg80211_match_set *match_sets;
Alexander Bondar50df8a32014-03-12 20:30:51 +020093 struct _dwell {
94 u16 passive;
95 u16 active;
David Spinadel190f1022015-02-17 12:45:21 +020096 u16 fragmented;
Alexander Bondar50df8a32014-03-12 20:30:51 +020097 } dwell[IEEE80211_NUM_BANDS];
Luciano Coelhocf5d3172015-04-16 20:13:28 +030098 struct {
99 u8 iterations;
100 u8 full_scan_mul; /* not used for UMAC */
101 } schedule[2];
Alexander Bondar8a110d92014-03-12 17:31:19 +0200102};
Johannes Berg8ca151b2013-01-24 14:25:36 +0100103
David Spinadeld2496222014-05-20 12:46:37 +0300104enum iwl_umac_scan_uid_type {
105 IWL_UMAC_SCAN_UID_REG_SCAN = BIT(0),
106 IWL_UMAC_SCAN_UID_SCHED_SCAN = BIT(1),
David Spinadeld2496222014-05-20 12:46:37 +0300107};
108
109static int iwl_umac_scan_stop(struct iwl_mvm *mvm,
110 enum iwl_umac_scan_uid_type type, bool notify);
111
112static u8 iwl_mvm_scan_rx_ant(struct iwl_mvm *mvm)
113{
114 if (mvm->scan_rx_ant != ANT_NONE)
115 return mvm->scan_rx_ant;
Moshe Harela0544272014-12-08 21:13:14 +0200116 return iwl_mvm_get_valid_rx_ant(mvm);
David Spinadeld2496222014-05-20 12:46:37 +0300117}
118
Johannes Berg8ca151b2013-01-24 14:25:36 +0100119static inline __le16 iwl_mvm_scan_rx_chain(struct iwl_mvm *mvm)
120{
121 u16 rx_chain;
Oren Givon91b05d12013-08-19 08:36:48 +0300122 u8 rx_ant;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100123
David Spinadeld2496222014-05-20 12:46:37 +0300124 rx_ant = iwl_mvm_scan_rx_ant(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100125 rx_chain = rx_ant << PHY_RX_CHAIN_VALID_POS;
126 rx_chain |= rx_ant << PHY_RX_CHAIN_FORCE_MIMO_SEL_POS;
127 rx_chain |= rx_ant << PHY_RX_CHAIN_FORCE_SEL_POS;
128 rx_chain |= 0x1 << PHY_RX_CHAIN_DRIVER_FORCE_POS;
129 return cpu_to_le16(rx_chain);
130}
131
David Spinadelfb98be52014-05-04 12:51:10 +0300132static __le32 iwl_mvm_scan_rxon_flags(enum ieee80211_band band)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100133{
David Spinadelfb98be52014-05-04 12:51:10 +0300134 if (band == IEEE80211_BAND_2GHZ)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100135 return cpu_to_le32(PHY_BAND_24);
136 else
137 return cpu_to_le32(PHY_BAND_5);
138}
139
140static inline __le32
141iwl_mvm_scan_rate_n_flags(struct iwl_mvm *mvm, enum ieee80211_band band,
142 bool no_cck)
143{
144 u32 tx_ant;
145
146 mvm->scan_last_antenna_idx =
Moshe Harela0544272014-12-08 21:13:14 +0200147 iwl_mvm_next_antenna(mvm, iwl_mvm_get_valid_tx_ant(mvm),
Johannes Berg8ca151b2013-01-24 14:25:36 +0100148 mvm->scan_last_antenna_idx);
149 tx_ant = BIT(mvm->scan_last_antenna_idx) << RATE_MCS_ANT_POS;
150
151 if (band == IEEE80211_BAND_2GHZ && !no_cck)
152 return cpu_to_le32(IWL_RATE_1M_PLCP | RATE_MCS_CCK_MSK |
153 tx_ant);
154 else
155 return cpu_to_le32(IWL_RATE_6M_PLCP | tx_ant);
156}
157
158/*
Johannes Berg8ca151b2013-01-24 14:25:36 +0100159 * If req->n_ssids > 0, it means we should do an active scan.
160 * In case of active scan w/o directed scan, we receive a zero-length SSID
161 * just to notify that this scan is active and not passive.
162 * In order to notify the FW of the number of SSIDs we wish to scan (including
163 * the zero-length one), we need to set the corresponding bits in chan->type,
David Spinadel20f1a5d2013-08-21 09:14:27 +0300164 * one for each SSID, and set the active bit (first). If the first SSID is
165 * already included in the probe template, so we need to set only
166 * req->n_ssids - 1 bits in addition to the first bit.
Johannes Berg8ca151b2013-01-24 14:25:36 +0100167 */
David Spinadel3cae0732014-12-29 15:43:48 +0200168static u16 iwl_mvm_get_active_dwell(struct iwl_mvm *mvm,
169 enum ieee80211_band band, int n_ssids)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100170{
David Spinadel3cae0732014-12-29 15:43:48 +0200171 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BASIC_DWELL)
172 return 10;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100173 if (band == IEEE80211_BAND_2GHZ)
David Spinadel39745332014-09-10 16:40:41 +0300174 return 20 + 3 * (n_ssids + 1);
175 return 10 + 2 * (n_ssids + 1);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100176}
177
David Spinadel3cae0732014-12-29 15:43:48 +0200178static u16 iwl_mvm_get_passive_dwell(struct iwl_mvm *mvm,
179 enum ieee80211_band band)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100180{
David Spinadel3cae0732014-12-29 15:43:48 +0200181 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BASIC_DWELL)
182 return 110;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100183 return band == IEEE80211_BAND_2GHZ ? 100 + 20 : 100 + 10;
184}
185
Alexander Bondar8a110d92014-03-12 17:31:19 +0200186static void iwl_mvm_scan_condition_iterator(void *data, u8 *mac,
187 struct ieee80211_vif *vif)
Haim Dreyfuss61f63252013-11-03 23:02:59 +0200188{
Alexander Bondar8a110d92014-03-12 17:31:19 +0200189 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Haim Dreyfussc3f8d0a2014-12-02 11:03:16 +0200190 int *global_cnt = data;
Haim Dreyfuss61f63252013-11-03 23:02:59 +0200191
David Spinadel1e2ebe02014-10-26 15:53:27 +0200192 if (vif->type != NL80211_IFTYPE_P2P_DEVICE && mvmvif->phy_ctxt &&
193 mvmvif->phy_ctxt->id < MAX_PHYS)
Haim Dreyfussc3f8d0a2014-12-02 11:03:16 +0200194 *global_cnt += 1;
Alexander Bondar8a110d92014-03-12 17:31:19 +0200195}
196
Luciano Coelho4b817052015-04-15 16:21:16 +0300197static void iwl_mvm_scan_calc_dwell(struct iwl_mvm *mvm,
198 struct ieee80211_vif *vif,
199 struct iwl_mvm_scan_params *params)
Alexander Bondar8a110d92014-03-12 17:31:19 +0200200{
Haim Dreyfussc3f8d0a2014-12-02 11:03:16 +0200201 int global_cnt = 0;
Alexander Bondar50df8a32014-03-12 20:30:51 +0200202 enum ieee80211_band band;
David Spinadel2ce89cd2014-07-22 13:11:18 +0300203 u8 frag_passive_dwell = 0;
Alexander Bondar8a110d92014-03-12 17:31:19 +0200204
205 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
206 IEEE80211_IFACE_ITER_NORMAL,
207 iwl_mvm_scan_condition_iterator,
Haim Dreyfussc3f8d0a2014-12-02 11:03:16 +0200208 &global_cnt);
Haim Dreyfussc3f8d0a2014-12-02 11:03:16 +0200209 if (!global_cnt)
Alexander Bondaref67f18d2014-03-30 10:47:08 +0300210 goto not_bound;
211
David Spinadel2ce89cd2014-07-22 13:11:18 +0300212 params->suspend_time = 30;
Haim Dreyfuss44e9cd72014-12-18 12:34:01 +0200213 params->max_out_time = 120;
Alexander Bondaref67f18d2014-03-30 10:47:08 +0300214
215 if (iwl_mvm_low_latency(mvm)) {
David Spinadel2ce89cd2014-07-22 13:11:18 +0300216 if (mvm->fw->ucode_capa.api[0] &
217 IWL_UCODE_TLV_API_FRAGMENTED_SCAN) {
218 params->suspend_time = 105;
Haim Dreyfussc3f8d0a2014-12-02 11:03:16 +0200219 /*
220 * If there is more than one active interface make
221 * passive scan more fragmented.
222 */
David Spinadelef177082015-02-15 14:45:33 +0200223 frag_passive_dwell = 40;
Haim Dreyfuss44e9cd72014-12-18 12:34:01 +0200224 params->max_out_time = frag_passive_dwell;
David Spinadel2ce89cd2014-07-22 13:11:18 +0300225 } else {
226 params->suspend_time = 120;
227 params->max_out_time = 120;
228 }
229 }
230
231 if (frag_passive_dwell && (mvm->fw->ucode_capa.api[0] &
232 IWL_UCODE_TLV_API_FRAGMENTED_SCAN)) {
233 /*
234 * P2P device scan should not be fragmented to avoid negative
235 * impact on P2P device discovery. Configure max_out_time to be
236 * equal to dwell time on passive channel. Take a longest
237 * possible value, one that corresponds to 2GHz band
238 */
239 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
240 u32 passive_dwell =
David Spinadel3cae0732014-12-29 15:43:48 +0200241 iwl_mvm_get_passive_dwell(mvm,
242 IEEE80211_BAND_2GHZ);
David Spinadel2ce89cd2014-07-22 13:11:18 +0300243 params->max_out_time = passive_dwell;
244 } else {
245 params->passive_fragmented = true;
246 }
Alexander Bondar50df8a32014-03-12 20:30:51 +0200247 }
248
Luciano Coelho4b817052015-04-15 16:21:16 +0300249 if ((params->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
Luciano Coelhoc1537662015-04-09 14:48:11 +0300250 (params->max_out_time > 200))
Johannes Bergab480032014-06-04 10:13:50 +0200251 params->max_out_time = 200;
252
Alexander Bondaref67f18d2014-03-30 10:47:08 +0300253not_bound:
254
Alexander Bondar50df8a32014-03-12 20:30:51 +0200255 for (band = IEEE80211_BAND_2GHZ; band < IEEE80211_NUM_BANDS; band++) {
David Spinadel2ce89cd2014-07-22 13:11:18 +0300256 if (params->passive_fragmented)
David Spinadel190f1022015-02-17 12:45:21 +0200257 params->dwell[band].fragmented = frag_passive_dwell;
258
259 params->dwell[band].passive = iwl_mvm_get_passive_dwell(mvm,
260 band);
Luciano Coelho4b817052015-04-15 16:21:16 +0300261 params->dwell[band].active =
262 iwl_mvm_get_active_dwell(mvm, band, params->n_ssids);
Alexander Bondar50df8a32014-03-12 20:30:51 +0200263 }
Luciano Coelho0616c622015-04-09 12:18:56 +0300264
265 IWL_DEBUG_SCAN(mvm,
266 "scan parameters: max_out_time %d, suspend_time %d, passive_fragmented %d\n",
267 params->max_out_time, params->suspend_time,
268 params->passive_fragmented);
269 IWL_DEBUG_SCAN(mvm,
270 "dwell[IEEE80211_BAND_2GHZ]: passive %d, active %d, fragmented %d\n",
271 params->dwell[IEEE80211_BAND_2GHZ].passive,
272 params->dwell[IEEE80211_BAND_2GHZ].active,
273 params->dwell[IEEE80211_BAND_2GHZ].fragmented);
274 IWL_DEBUG_SCAN(mvm,
275 "dwell[IEEE80211_BAND_5GHZ]: passive %d, active %d, fragmented %d\n",
276 params->dwell[IEEE80211_BAND_5GHZ].passive,
277 params->dwell[IEEE80211_BAND_5GHZ].active,
278 params->dwell[IEEE80211_BAND_5GHZ].fragmented);
Haim Dreyfuss61f63252013-11-03 23:02:59 +0200279}
280
Andrei Otcheretianski73897bd2014-07-09 18:59:14 +0300281static inline bool iwl_mvm_rrm_scan_needed(struct iwl_mvm *mvm)
282{
283 /* require rrm scan whenever the fw supports it */
284 return mvm->fw->ucode_capa.capa[0] &
285 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT;
286}
287
Luciano Coelho999d2562015-03-27 10:28:26 +0300288static int iwl_mvm_max_scan_ie_fw_cmd_room(struct iwl_mvm *mvm)
Andrei Otcheretianski48849a42014-09-09 10:58:49 +0300289{
290 int max_probe_len;
291
Luciano Coelho1f940382015-02-10 13:03:38 +0200292 max_probe_len = SCAN_OFFLOAD_PROBE_REQ_SIZE;
Andrei Otcheretianski48849a42014-09-09 10:58:49 +0300293
294 /* we create the 802.11 header and SSID element */
295 max_probe_len -= 24 + 2;
296
Andrei Otcheretianski66dc5272014-09-02 17:55:40 +0300297 /* DS parameter set element is added on 2.4GHZ band if required */
298 if (iwl_mvm_rrm_scan_needed(mvm))
299 max_probe_len -= 3;
300
Andrei Otcheretianski48849a42014-09-09 10:58:49 +0300301 return max_probe_len;
302}
303
Luciano Coelho999d2562015-03-27 10:28:26 +0300304int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm)
Andrei Otcheretianski48849a42014-09-09 10:58:49 +0300305{
Luciano Coelho999d2562015-03-27 10:28:26 +0300306 int max_ie_len = iwl_mvm_max_scan_ie_fw_cmd_room(mvm);
Andrei Otcheretianski48849a42014-09-09 10:58:49 +0300307
Andrei Otcheretianski48849a42014-09-09 10:58:49 +0300308 /* TODO: [BUG] This function should return the maximum allowed size of
309 * scan IEs, however the LMAC scan api contains both 2GHZ and 5GHZ IEs
310 * in the same command. So the correct implementation of this function
311 * is just iwl_mvm_max_scan_ie_fw_cmd_room() / 2. Currently the scan
312 * command has only 512 bytes and it would leave us with about 240
313 * bytes for scan IEs, which is clearly not enough. So meanwhile
314 * we will report an incorrect value. This may result in a failure to
315 * issue a scan in unified_scan_lmac and unified_sched_scan_lmac
316 * functions with -ENOBUFS, if a large enough probe will be provided.
317 */
318 return max_ie_len;
319}
320
Alexander Bondare5d74642014-12-09 19:15:49 +0200321int iwl_mvm_rx_scan_offload_iter_complete_notif(struct iwl_mvm *mvm,
322 struct iwl_rx_cmd_buffer *rxb,
323 struct iwl_device_cmd *cmd)
324{
325 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Avraham Stern1083fd72015-03-31 16:14:41 +0300326 struct iwl_lmac_scan_complete_notif *notif = (void *)pkt->data;
Alexander Bondare5d74642014-12-09 19:15:49 +0200327
328 IWL_DEBUG_SCAN(mvm,
329 "Scan offload iteration complete: status=0x%x scanned channels=%d\n",
330 notif->status, notif->scanned_channels);
331 return 0;
332}
333
David Spinadelfb98be52014-05-04 12:51:10 +0300334int iwl_mvm_rx_scan_offload_results(struct iwl_mvm *mvm,
335 struct iwl_rx_cmd_buffer *rxb,
336 struct iwl_device_cmd *cmd)
David Spinadel35a000b2013-08-28 09:29:43 +0300337{
David Spinadeld2496222014-05-20 12:46:37 +0300338 IWL_DEBUG_SCAN(mvm, "Scheduled scan results\n");
339 ieee80211_sched_scan_results(mvm->hw);
David Spinadel35a000b2013-08-28 09:29:43 +0300340
341 return 0;
342}
343
David Spinadel35a000b2013-08-28 09:29:43 +0300344int iwl_mvm_rx_scan_offload_complete_notif(struct iwl_mvm *mvm,
345 struct iwl_rx_cmd_buffer *rxb,
346 struct iwl_device_cmd *cmd)
347{
348 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Luciano Coelho9af91f42015-02-10 10:42:26 +0200349 struct iwl_periodic_scan_complete *scan_notif = (void *)pkt->data;
350 bool aborted = (scan_notif->status == IWL_SCAN_OFFLOAD_ABORTED);
351 bool ebs_successful = (scan_notif->ebs_status == IWL_SCAN_EBS_SUCCESS);
David Spinadelfb98be52014-05-04 12:51:10 +0300352
Johannes Berga6623e82014-01-27 15:40:53 +0100353 /* scan status must be locked for proper checking */
354 lockdep_assert_held(&mvm->mutex);
355
Luciano Coelho9af91f42015-02-10 10:42:26 +0200356 /* We first check if we were stopping a scan, in which case we
357 * just clear the stopping flag. Then we check if it was a
358 * firmware initiated stop, in which case we need to inform
359 * mac80211.
360 * Note that we can have a stopping and a running scan
361 * simultaneously, but we can't have two different types of
362 * scans stopping or running at the same time (since LMAC
363 * doesn't support it).
364 */
Haim Dreyfusse820c2d2014-04-06 11:19:09 +0300365
Luciano Coelho9af91f42015-02-10 10:42:26 +0200366 if (mvm->scan_status & IWL_MVM_SCAN_STOPPING_SCHED) {
367 WARN_ON_ONCE(mvm->scan_status & IWL_MVM_SCAN_STOPPING_REGULAR);
David Spinadel35a000b2013-08-28 09:29:43 +0300368
Luciano Coelho9af91f42015-02-10 10:42:26 +0200369 IWL_DEBUG_SCAN(mvm, "Scheduled scan %s, EBS status %s\n",
370 aborted ? "aborted" : "completed",
371 ebs_successful ? "successful" : "failed");
372
373 mvm->scan_status &= ~IWL_MVM_SCAN_STOPPING_SCHED;
374 } else if (mvm->scan_status & IWL_MVM_SCAN_STOPPING_REGULAR) {
375 IWL_DEBUG_SCAN(mvm, "Regular scan %s, EBS status %s\n",
376 aborted ? "aborted" : "completed",
377 ebs_successful ? "successful" : "failed");
378
379 mvm->scan_status &= ~IWL_MVM_SCAN_STOPPING_REGULAR;
380 } else if (mvm->scan_status & IWL_MVM_SCAN_SCHED) {
381 WARN_ON_ONCE(mvm->scan_status & IWL_MVM_SCAN_REGULAR);
382
383 IWL_DEBUG_SCAN(mvm, "Scheduled scan %s, EBS status %s (FW)\n",
384 aborted ? "aborted" : "completed",
385 ebs_successful ? "successful" : "failed");
386
387 mvm->scan_status &= ~IWL_MVM_SCAN_SCHED;
Arik Nemtsov33ea27f2014-02-10 15:34:29 +0200388 ieee80211_sched_scan_stopped(mvm->hw);
Luciano Coelho9af91f42015-02-10 10:42:26 +0200389 } else if (mvm->scan_status & IWL_MVM_SCAN_REGULAR) {
390 IWL_DEBUG_SCAN(mvm, "Regular scan %s, EBS status %s (FW)\n",
391 aborted ? "aborted" : "completed",
392 ebs_successful ? "successful" : "failed");
393
394 mvm->scan_status &= ~IWL_MVM_SCAN_REGULAR;
David Spinadelfb98be52014-05-04 12:51:10 +0300395 ieee80211_scan_completed(mvm->hw,
Luciano Coelho1f940382015-02-10 13:03:38 +0200396 scan_notif->status == IWL_SCAN_OFFLOAD_ABORTED);
Eliad Peller4ff78182014-06-22 14:44:44 +0300397 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +0200398 }
David Spinadel35a000b2013-08-28 09:29:43 +0300399
Luciano Coelho9af91f42015-02-10 10:42:26 +0200400 mvm->last_ebs_successful = ebs_successful;
Haim Dreyfusse820c2d2014-04-06 11:19:09 +0300401
David Spinadel35a000b2013-08-28 09:29:43 +0300402 return 0;
403}
404
David Spinadel35a000b2013-08-28 09:29:43 +0300405static int iwl_ssid_exist(u8 *ssid, u8 ssid_len, struct iwl_ssid_ie *ssid_list)
406{
407 int i;
408
409 for (i = 0; i < PROBE_OPTION_MAX; i++) {
410 if (!ssid_list[i].len)
411 break;
412 if (ssid_list[i].len == ssid_len &&
413 !memcmp(ssid_list->ssid, ssid, ssid_len))
414 return i;
415 }
416 return -1;
417}
418
Luciano Coelhoe2ec4f62015-04-02 17:49:04 +0300419/* We insert the SSIDs in an inverted order, because the FW will
420 * invert it back.
421 */
422static void iwl_scan_build_ssids(struct iwl_mvm_scan_params *params,
423 struct iwl_ssid_ie *ssids,
424 u32 *ssid_bitmap)
David Spinadel35a000b2013-08-28 09:29:43 +0300425{
426 int i, j;
427 int index;
428
429 /*
430 * copy SSIDs from match list.
431 * iwl_config_sched_scan_profiles() uses the order of these ssids to
432 * config match list.
433 */
Luciano Coelho1c1b5b22015-04-02 16:31:42 +0300434 for (i = 0, j = params->n_match_sets - 1;
435 j >= 0 && i < PROBE_OPTION_MAX;
436 i++, j--) {
Johannes Bergea73cbc2014-01-24 10:53:53 +0100437 /* skip empty SSID matchsets */
Luciano Coelho1c1b5b22015-04-02 16:31:42 +0300438 if (!params->match_sets[j].ssid.ssid_len)
Johannes Bergea73cbc2014-01-24 10:53:53 +0100439 continue;
Luciano Coelhoe2ec4f62015-04-02 17:49:04 +0300440 ssids[i].id = WLAN_EID_SSID;
441 ssids[i].len = params->match_sets[j].ssid.ssid_len;
442 memcpy(ssids[i].ssid, params->match_sets[j].ssid.ssid,
443 ssids[i].len);
David Spinadel35a000b2013-08-28 09:29:43 +0300444 }
445
446 /* add SSIDs from scan SSID list */
447 *ssid_bitmap = 0;
Luciano Coelho1c1b5b22015-04-02 16:31:42 +0300448 for (j = params->n_ssids - 1;
449 j >= 0 && i < PROBE_OPTION_MAX;
450 i++, j--) {
Luciano Coelhof7b788b2015-04-02 00:08:35 +0300451 index = iwl_ssid_exist(params->ssids[j].ssid,
452 params->ssids[j].ssid_len,
Luciano Coelhoe2ec4f62015-04-02 17:49:04 +0300453 ssids);
David Spinadel35a000b2013-08-28 09:29:43 +0300454 if (index < 0) {
Luciano Coelhoe2ec4f62015-04-02 17:49:04 +0300455 ssids[i].id = WLAN_EID_SSID;
456 ssids[i].len = params->ssids[j].ssid_len;
457 memcpy(ssids[i].ssid, params->ssids[j].ssid,
458 ssids[i].len);
459 *ssid_bitmap |= BIT(i);
David Spinadel35a000b2013-08-28 09:29:43 +0300460 } else {
Luciano Coelhoe2ec4f62015-04-02 17:49:04 +0300461 *ssid_bitmap |= BIT(index);
David Spinadel35a000b2013-08-28 09:29:43 +0300462 }
463 }
464}
465
David Spinadel35a000b2013-08-28 09:29:43 +0300466int iwl_mvm_config_sched_scan_profiles(struct iwl_mvm *mvm,
467 struct cfg80211_sched_scan_request *req)
468{
469 struct iwl_scan_offload_profile *profile;
470 struct iwl_scan_offload_profile_cfg *profile_cfg;
471 struct iwl_scan_offload_blacklist *blacklist;
472 struct iwl_host_cmd cmd = {
473 .id = SCAN_OFFLOAD_UPDATE_PROFILES_CMD,
David Spinadel35a000b2013-08-28 09:29:43 +0300474 .len[1] = sizeof(*profile_cfg),
475 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
476 .dataflags[1] = IWL_HCMD_DFL_NOCOPY,
477 };
478 int blacklist_len;
479 int i;
480 int ret;
481
482 if (WARN_ON(req->n_match_sets > IWL_SCAN_MAX_PROFILES))
483 return -EIO;
484
485 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_SHORT_BL)
486 blacklist_len = IWL_SCAN_SHORT_BLACKLIST_LEN;
487 else
488 blacklist_len = IWL_SCAN_MAX_BLACKLIST_LEN;
489
490 blacklist = kzalloc(sizeof(*blacklist) * blacklist_len, GFP_KERNEL);
491 if (!blacklist)
492 return -ENOMEM;
493
494 profile_cfg = kzalloc(sizeof(*profile_cfg), GFP_KERNEL);
495 if (!profile_cfg) {
496 ret = -ENOMEM;
497 goto free_blacklist;
498 }
499
500 cmd.data[0] = blacklist;
501 cmd.len[0] = sizeof(*blacklist) * blacklist_len;
502 cmd.data[1] = profile_cfg;
503
504 /* No blacklist configuration */
505
506 profile_cfg->num_profiles = req->n_match_sets;
507 profile_cfg->active_clients = SCAN_CLIENT_SCHED_SCAN;
508 profile_cfg->pass_match = SCAN_CLIENT_SCHED_SCAN;
509 profile_cfg->match_notify = SCAN_CLIENT_SCHED_SCAN;
David Spinadel6e0bbe52013-12-30 09:59:45 +0200510 if (!req->n_match_sets || !req->match_sets[0].ssid.ssid_len)
511 profile_cfg->any_beacon_notify = SCAN_CLIENT_SCHED_SCAN;
David Spinadel35a000b2013-08-28 09:29:43 +0300512
513 for (i = 0; i < req->n_match_sets; i++) {
514 profile = &profile_cfg->profiles[i];
515 profile->ssid_index = i;
516 /* Support any cipher and auth algorithm */
517 profile->unicast_cipher = 0xff;
518 profile->auth_alg = 0xff;
519 profile->network_type = IWL_NETWORK_TYPE_ANY;
520 profile->band_selection = IWL_SCAN_OFFLOAD_SELECT_ANY;
521 profile->client_bitmap = SCAN_CLIENT_SCHED_SCAN;
522 }
523
524 IWL_DEBUG_SCAN(mvm, "Sending scheduled scan profile config\n");
525
526 ret = iwl_mvm_send_cmd(mvm, &cmd);
527 kfree(profile_cfg);
528free_blacklist:
529 kfree(blacklist);
530
531 return ret;
532}
533
David Spinadeld2496222014-05-20 12:46:37 +0300534static bool iwl_mvm_scan_pass_all(struct iwl_mvm *mvm,
535 struct cfg80211_sched_scan_request *req)
536{
537 if (req->n_match_sets && req->match_sets[0].ssid.ssid_len) {
538 IWL_DEBUG_SCAN(mvm,
539 "Sending scheduled scan with filtering, n_match_sets %d\n",
540 req->n_match_sets);
541 return false;
542 }
543
544 IWL_DEBUG_SCAN(mvm, "Sending Scheduled scan without filtering\n");
545 return true;
546}
547
David Spinadelfb98be52014-05-04 12:51:10 +0300548static int iwl_mvm_send_scan_offload_abort(struct iwl_mvm *mvm)
David Spinadel35a000b2013-08-28 09:29:43 +0300549{
550 int ret;
551 struct iwl_host_cmd cmd = {
552 .id = SCAN_OFFLOAD_ABORT_CMD,
David Spinadel35a000b2013-08-28 09:29:43 +0300553 };
554 u32 status;
555
556 /* Exit instantly with error when device is not ready
557 * to receive scan abort command or it does not perform
558 * scheduled scan currently */
Luciano Coelho9af91f42015-02-10 10:42:26 +0200559 if (!mvm->scan_status)
David Spinadel35a000b2013-08-28 09:29:43 +0300560 return -EIO;
561
562 ret = iwl_mvm_send_cmd_status(mvm, &cmd, &status);
563 if (ret)
564 return ret;
565
566 if (status != CAN_ABORT_STATUS) {
567 /*
568 * The scan abort will return 1 for success or
569 * 2 for "failure". A failure condition can be
570 * due to simply not being in an active scan which
571 * can occur if we send the scan abort before the
572 * microcode has notified us that a scan is completed.
573 */
574 IWL_DEBUG_SCAN(mvm, "SCAN OFFLOAD ABORT ret %d.\n", status);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +0200575 ret = -ENOENT;
David Spinadel35a000b2013-08-28 09:29:43 +0300576 }
577
578 return ret;
579}
580
David Spinadelfb98be52014-05-04 12:51:10 +0300581int iwl_mvm_scan_offload_stop(struct iwl_mvm *mvm, bool notify)
David Spinadel35a000b2013-08-28 09:29:43 +0300582{
583 int ret;
Arik Nemtsov33ea27f2014-02-10 15:34:29 +0200584 struct iwl_notification_wait wait_scan_done;
585 static const u8 scan_done_notif[] = { SCAN_OFFLOAD_COMPLETE, };
Luciano Coelho9af91f42015-02-10 10:42:26 +0200586 bool sched = !!(mvm->scan_status & IWL_MVM_SCAN_SCHED);
David Spinadel35a000b2013-08-28 09:29:43 +0300587
588 lockdep_assert_held(&mvm->mutex);
589
David Spinadeld2496222014-05-20 12:46:37 +0300590 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)
591 return iwl_umac_scan_stop(mvm, IWL_UMAC_SCAN_UID_SCHED_SCAN,
592 notify);
593
Luciano Coelho9af91f42015-02-10 10:42:26 +0200594 /* FIXME: For now we only check if no scan is set here, since
595 * we only support LMAC in this flow and it doesn't support
596 * multiple scans.
597 */
598 if (!mvm->scan_status)
Emmanuel Grumbach90ea15c2015-01-18 21:39:30 +0200599 return 0;
600
Luciano Coelho54331db2015-02-05 00:39:22 +0200601 if (iwl_mvm_is_radio_killed(mvm)) {
602 ret = 0;
Emmanuel Grumbach90ea15c2015-01-18 21:39:30 +0200603 goto out;
Luciano Coelho54331db2015-02-05 00:39:22 +0200604 }
Emmanuel Grumbach90ea15c2015-01-18 21:39:30 +0200605
Arik Nemtsov33ea27f2014-02-10 15:34:29 +0200606 iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_done,
607 scan_done_notif,
608 ARRAY_SIZE(scan_done_notif),
609 NULL, NULL);
610
David Spinadelfb98be52014-05-04 12:51:10 +0300611 ret = iwl_mvm_send_scan_offload_abort(mvm);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +0200612 if (ret) {
David Spinadelfb98be52014-05-04 12:51:10 +0300613 IWL_DEBUG_SCAN(mvm, "Send stop %sscan failed %d\n",
614 sched ? "offloaded " : "", ret);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +0200615 iwl_remove_notification(&mvm->notif_wait, &wait_scan_done);
Luciano Coelho54331db2015-02-05 00:39:22 +0200616 goto out;
Arik Nemtsov33ea27f2014-02-10 15:34:29 +0200617 }
618
David Spinadelfb98be52014-05-04 12:51:10 +0300619 IWL_DEBUG_SCAN(mvm, "Successfully sent stop %sscan\n",
Luciano Coelho9af91f42015-02-10 10:42:26 +0200620 sched ? "scheduled " : "");
Arik Nemtsov33ea27f2014-02-10 15:34:29 +0200621
622 ret = iwl_wait_notification(&mvm->notif_wait, &wait_scan_done, 1 * HZ);
Luciano Coelho54331db2015-02-05 00:39:22 +0200623out:
Luciano Coelho9af91f42015-02-10 10:42:26 +0200624 /* Clear the scan status so the next scan requests will
625 * succeed and mark the scan as stopping, so that the Rx
626 * handler doesn't do anything, as the scan was stopped from
627 * above. Since the rx handler won't do anything now, we have
628 * to release the scan reference here.
Arik Nemtsov33ea27f2014-02-10 15:34:29 +0200629 */
Luciano Coelho9af91f42015-02-10 10:42:26 +0200630 if (mvm->scan_status == IWL_MVM_SCAN_REGULAR)
Eliad Peller4ff78182014-06-22 14:44:44 +0300631 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
632
Luciano Coelho9af91f42015-02-10 10:42:26 +0200633 if (sched) {
634 mvm->scan_status &= ~IWL_MVM_SCAN_SCHED;
635 mvm->scan_status |= IWL_MVM_SCAN_STOPPING_SCHED;
636 if (notify)
David Spinadelfb98be52014-05-04 12:51:10 +0300637 ieee80211_sched_scan_stopped(mvm->hw);
Luciano Coelho9af91f42015-02-10 10:42:26 +0200638 } else {
639 mvm->scan_status &= ~IWL_MVM_SCAN_REGULAR;
640 mvm->scan_status |= IWL_MVM_SCAN_STOPPING_REGULAR;
641 if (notify)
David Spinadelfb98be52014-05-04 12:51:10 +0300642 ieee80211_scan_completed(mvm->hw, true);
643 }
David Spinadel636a2cd2014-05-01 15:57:22 +0300644
Luciano Coelho54331db2015-02-05 00:39:22 +0200645 return ret;
David Spinadel35a000b2013-08-28 09:29:43 +0300646}
David Spinadelfb98be52014-05-04 12:51:10 +0300647
Luciano Coelho65ff5562015-03-20 13:35:47 +0200648static void iwl_mvm_scan_fill_tx_cmd(struct iwl_mvm *mvm,
649 struct iwl_scan_req_tx_cmd *tx_cmd,
650 bool no_cck)
David Spinadelfb98be52014-05-04 12:51:10 +0300651{
652 tx_cmd[0].tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL |
653 TX_CMD_FLG_BT_DIS);
654 tx_cmd[0].rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm,
655 IEEE80211_BAND_2GHZ,
656 no_cck);
657 tx_cmd[0].sta_id = mvm->aux_sta.sta_id;
658
659 tx_cmd[1].tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL |
660 TX_CMD_FLG_BT_DIS);
661 tx_cmd[1].rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm,
662 IEEE80211_BAND_5GHZ,
663 no_cck);
664 tx_cmd[1].sta_id = mvm->aux_sta.sta_id;
665}
666
667static void
668iwl_mvm_lmac_scan_cfg_channels(struct iwl_mvm *mvm,
669 struct ieee80211_channel **channels,
670 int n_channels, u32 ssid_bitmap,
Luciano Coelho65ff5562015-03-20 13:35:47 +0200671 struct iwl_scan_req_lmac *cmd)
David Spinadelfb98be52014-05-04 12:51:10 +0300672{
673 struct iwl_scan_channel_cfg_lmac *channel_cfg = (void *)&cmd->data;
674 int i;
675
676 for (i = 0; i < n_channels; i++) {
677 channel_cfg[i].channel_num =
678 cpu_to_le16(channels[i]->hw_value);
679 channel_cfg[i].iter_count = cpu_to_le16(1);
680 channel_cfg[i].iter_interval = 0;
681 channel_cfg[i].flags =
682 cpu_to_le32(IWL_UNIFIED_SCAN_CHANNEL_PARTIAL |
683 ssid_bitmap);
684 }
685}
686
Andrei Otcheretianski66dc5272014-09-02 17:55:40 +0300687static u8 *iwl_mvm_copy_and_insert_ds_elem(struct iwl_mvm *mvm, const u8 *ies,
688 size_t len, u8 *const pos)
689{
690 static const u8 before_ds_params[] = {
691 WLAN_EID_SSID,
692 WLAN_EID_SUPP_RATES,
693 WLAN_EID_REQUEST,
694 WLAN_EID_EXT_SUPP_RATES,
695 };
696 size_t offs;
697 u8 *newpos = pos;
698
699 if (!iwl_mvm_rrm_scan_needed(mvm)) {
700 memcpy(newpos, ies, len);
701 return newpos + len;
702 }
703
704 offs = ieee80211_ie_split(ies, len,
705 before_ds_params,
706 ARRAY_SIZE(before_ds_params),
707 0);
708
709 memcpy(newpos, ies, offs);
710 newpos += offs;
711
712 /* Add a placeholder for DS Parameter Set element */
713 *newpos++ = WLAN_EID_DS_PARAMS;
714 *newpos++ = 1;
715 *newpos++ = 0;
716
717 memcpy(newpos, ies + offs, len - offs);
718 newpos += len - offs;
719
720 return newpos;
721}
722
David Spinadelfb98be52014-05-04 12:51:10 +0300723static void
Luciano Coelho65ff5562015-03-20 13:35:47 +0200724iwl_mvm_build_scan_probe(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
725 struct ieee80211_scan_ies *ies,
Luciano Coelho45d1b122015-04-15 16:34:13 +0300726 struct iwl_mvm_scan_params *params)
David Spinadelfb98be52014-05-04 12:51:10 +0300727{
Luciano Coelho45d1b122015-04-15 16:34:13 +0300728 struct ieee80211_mgmt *frame = (void *)params->preq.buf;
Andrei Otcheretianski66dc5272014-09-02 17:55:40 +0300729 u8 *pos, *newpos;
Luciano Coelho45d1b122015-04-15 16:34:13 +0300730 const u8 *mac_addr = params->flags & NL80211_SCAN_FLAG_RANDOM_ADDR ?
731 params->mac_addr : NULL;
David Spinadelfb98be52014-05-04 12:51:10 +0300732
Johannes Bergeffd05a2014-11-18 17:21:19 +0100733 /*
734 * Unfortunately, right now the offload scan doesn't support randomising
735 * within the firmware, so until the firmware API is ready we implement
736 * it in the driver. This means that the scan iterations won't really be
737 * random, only when it's restarted, but at least that helps a bit.
738 */
739 if (mac_addr)
Luciano Coelho45d1b122015-04-15 16:34:13 +0300740 get_random_mask_addr(frame->sa, mac_addr,
741 params->mac_addr_mask);
Johannes Bergeffd05a2014-11-18 17:21:19 +0100742 else
743 memcpy(frame->sa, vif->addr, ETH_ALEN);
744
David Spinadelfb98be52014-05-04 12:51:10 +0300745 frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
746 eth_broadcast_addr(frame->da);
David Spinadelfb98be52014-05-04 12:51:10 +0300747 eth_broadcast_addr(frame->bssid);
748 frame->seq_ctrl = 0;
749
750 pos = frame->u.probe_req.variable;
751 *pos++ = WLAN_EID_SSID;
752 *pos++ = 0;
753
Luciano Coelho45d1b122015-04-15 16:34:13 +0300754 params->preq.mac_header.offset = 0;
755 params->preq.mac_header.len = cpu_to_le16(24 + 2);
David Spinadelfb98be52014-05-04 12:51:10 +0300756
Andrei Otcheretianski66dc5272014-09-02 17:55:40 +0300757 /* Insert ds parameter set element on 2.4 GHz band */
758 newpos = iwl_mvm_copy_and_insert_ds_elem(mvm,
759 ies->ies[IEEE80211_BAND_2GHZ],
760 ies->len[IEEE80211_BAND_2GHZ],
761 pos);
Luciano Coelho45d1b122015-04-15 16:34:13 +0300762 params->preq.band_data[0].offset = cpu_to_le16(pos - params->preq.buf);
763 params->preq.band_data[0].len = cpu_to_le16(newpos - pos);
Andrei Otcheretianski66dc5272014-09-02 17:55:40 +0300764 pos = newpos;
David Spinadelfb98be52014-05-04 12:51:10 +0300765
766 memcpy(pos, ies->ies[IEEE80211_BAND_5GHZ],
767 ies->len[IEEE80211_BAND_5GHZ]);
Luciano Coelho45d1b122015-04-15 16:34:13 +0300768 params->preq.band_data[1].offset = cpu_to_le16(pos - params->preq.buf);
769 params->preq.band_data[1].len =
770 cpu_to_le16(ies->len[IEEE80211_BAND_5GHZ]);
David Spinadelfb98be52014-05-04 12:51:10 +0300771 pos += ies->len[IEEE80211_BAND_5GHZ];
772
773 memcpy(pos, ies->common_ies, ies->common_ie_len);
Luciano Coelho45d1b122015-04-15 16:34:13 +0300774 params->preq.common_data.offset = cpu_to_le16(pos - params->preq.buf);
775 params->preq.common_data.len = cpu_to_le16(ies->common_ie_len);
David Spinadelfb98be52014-05-04 12:51:10 +0300776}
777
Luciano Coelho133c8252015-04-20 15:29:03 +0300778static void iwl_mvm_scan_lmac_dwell(struct iwl_mvm *mvm,
779 struct iwl_scan_req_lmac *cmd,
780 struct iwl_mvm_scan_params *params)
David Spinadelfb98be52014-05-04 12:51:10 +0300781{
David Spinadel2ce89cd2014-07-22 13:11:18 +0300782 cmd->active_dwell = params->dwell[IEEE80211_BAND_2GHZ].active;
783 cmd->passive_dwell = params->dwell[IEEE80211_BAND_2GHZ].passive;
784 if (params->passive_fragmented)
785 cmd->fragmented_dwell =
David Spinadel190f1022015-02-17 12:45:21 +0200786 params->dwell[IEEE80211_BAND_2GHZ].fragmented;
David Spinadelfb98be52014-05-04 12:51:10 +0300787 cmd->max_out_time = cpu_to_le32(params->max_out_time);
788 cmd->suspend_time = cpu_to_le32(params->suspend_time);
789 cmd->scan_prio = cpu_to_le32(IWL_SCAN_PRIORITY_HIGH);
David Spinadelfb98be52014-05-04 12:51:10 +0300790}
791
Luciano Coelho999d2562015-03-27 10:28:26 +0300792static inline bool iwl_mvm_scan_fits(struct iwl_mvm *mvm, int n_ssids,
793 struct ieee80211_scan_ies *ies,
794 int n_channels)
795{
796 return ((n_ssids <= PROBE_OPTION_MAX) &&
797 (n_channels <= mvm->fw->ucode_capa.n_scan_channels) &
798 (ies->common_ie_len +
799 ies->len[NL80211_BAND_2GHZ] +
800 ies->len[NL80211_BAND_5GHZ] <=
801 iwl_mvm_max_scan_ie_fw_cmd_room(mvm)));
802}
803
Luciano Coelho7d7de1e2015-04-17 09:53:55 +0300804static inline bool iwl_mvm_scan_use_ebs(struct iwl_mvm *mvm, int n_iterations)
805{
806 const struct iwl_ucode_capabilities *capa = &mvm->fw->ucode_capa;
807
808 /* We can only use EBS if:
809 * 1. the feature is supported;
810 * 2. the last EBS was successful;
811 * 3. if only single scan, the single scan EBS API is supported.
812 */
813 return ((capa->flags & IWL_UCODE_TLV_FLAGS_EBS_SUPPORT) &&
814 mvm->last_ebs_successful &&
815 (n_iterations > 1 ||
816 (capa->api[0] & IWL_UCODE_TLV_API_SINGLE_SCAN_EBS)));
817}
818
Luciano Coelho6f4dcc72015-04-20 14:37:16 +0300819static int iwl_mvm_scan_total_iterations(struct iwl_mvm_scan_params *params)
820{
821 return params->schedule[0].iterations + params->schedule[1].iterations;
822}
823
Luciano Coelho87515402015-04-20 14:47:49 +0300824static int iwl_mvm_scan_lmac_flags(struct iwl_mvm *mvm,
825 struct iwl_mvm_scan_params *params)
826{
827 int flags = 0;
828
829 if (params->n_ssids == 0)
830 flags |= IWL_MVM_LMAC_SCAN_FLAG_PASSIVE;
831
832 if (params->n_ssids == 1 && params->ssids[0].ssid_len != 0)
833 flags |= IWL_MVM_LMAC_SCAN_FLAG_PRE_CONNECTION;
834
835 if (params->passive_fragmented)
836 flags |= IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED;
837
838 if (iwl_mvm_rrm_scan_needed(mvm))
839 flags |= IWL_MVM_LMAC_SCAN_FLAGS_RRM_ENABLED;
840
841 if (params->pass_all)
842 flags |= IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL;
843 else
844 flags |= IWL_MVM_LMAC_SCAN_FLAG_MATCH;
845
846#ifdef CONFIG_IWLWIFI_DEBUGFS
847 if (mvm->scan_iter_notif_enabled)
848 flags |= IWL_MVM_LMAC_SCAN_FLAG_ITER_COMPLETE;
849#endif
850
851 return flags;
852}
853
Luciano Coelho6749dd82015-03-20 15:51:36 +0200854static int iwl_mvm_scan_lmac(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
Luciano Coelho3db7c6e2015-04-01 17:09:56 +0300855 struct iwl_mvm_scan_params *params)
David Spinadelfb98be52014-05-04 12:51:10 +0300856{
Luciano Coelho65ff5562015-03-20 13:35:47 +0200857 struct iwl_scan_req_lmac *cmd = mvm->scan_cmd;
Luciano Coelho45d1b122015-04-15 16:34:13 +0300858 struct iwl_scan_probe_req *preq =
859 (void *)(cmd->data + sizeof(struct iwl_scan_channel_cfg_lmac) *
860 mvm->fw->ucode_capa.n_scan_channels);
Luciano Coelho87515402015-04-20 14:47:49 +0300861 u32 ssid_bitmap = 0;
Luciano Coelho6f4dcc72015-04-20 14:37:16 +0300862 int n_iterations = iwl_mvm_scan_total_iterations(params);
David Spinadelfb98be52014-05-04 12:51:10 +0300863
864 lockdep_assert_held(&mvm->mutex);
865
Luciano Coelho133c8252015-04-20 15:29:03 +0300866 memset(cmd, 0, ksize(cmd));
David Spinadelfb98be52014-05-04 12:51:10 +0300867
Luciano Coelho133c8252015-04-20 15:29:03 +0300868 iwl_mvm_scan_lmac_dwell(mvm, cmd, params);
869
870 cmd->rx_chain_select = iwl_mvm_scan_rx_chain(mvm);
871 cmd->iter_num = cpu_to_le32(1);
Luciano Coelhof7b788b2015-04-02 00:08:35 +0300872 cmd->n_channels = (u8)params->n_channels;
David Spinadelfb98be52014-05-04 12:51:10 +0300873
Luciano Coelhof7b788b2015-04-02 00:08:35 +0300874 cmd->delay = cpu_to_le32(params->delay);
Luciano Coelho2250fd92014-12-03 10:52:26 +0200875
Luciano Coelho87515402015-04-20 14:47:49 +0300876 cmd->scan_flags = cpu_to_le32(iwl_mvm_scan_lmac_flags(mvm, params));
David Spinadelfb98be52014-05-04 12:51:10 +0300877
Luciano Coelhof7b788b2015-04-02 00:08:35 +0300878 cmd->flags = iwl_mvm_scan_rxon_flags(params->channels[0]->band);
David Spinadelfb98be52014-05-04 12:51:10 +0300879 cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP |
880 MAC_FILTER_IN_BEACON);
Luciano Coelhof7b788b2015-04-02 00:08:35 +0300881 iwl_mvm_scan_fill_tx_cmd(mvm, cmd->tx_cmd, params->no_cck);
Luciano Coelhoe2ec4f62015-04-02 17:49:04 +0300882 iwl_scan_build_ssids(params, cmd->direct_scan, &ssid_bitmap);
883
884 /* this API uses bits 1-20 instead of 0-19 */
885 ssid_bitmap <<= 1;
Luciano Coelhof7b788b2015-04-02 00:08:35 +0300886
887 cmd->schedule[0].delay = cpu_to_le16(params->interval);
Luciano Coelhocf5d3172015-04-16 20:13:28 +0300888 cmd->schedule[0].iterations = params->schedule[0].iterations;
889 cmd->schedule[0].full_scan_mul = params->schedule[0].full_scan_mul;
Luciano Coelhof7b788b2015-04-02 00:08:35 +0300890 cmd->schedule[1].delay = cpu_to_le16(params->interval);
Luciano Coelhocf5d3172015-04-16 20:13:28 +0300891 cmd->schedule[1].iterations = params->schedule[1].iterations;
892 cmd->schedule[1].full_scan_mul = params->schedule[1].iterations;
David Spinadelfb98be52014-05-04 12:51:10 +0300893
Luciano Coelho7d7de1e2015-04-17 09:53:55 +0300894 if (iwl_mvm_scan_use_ebs(mvm, n_iterations)) {
David Spinadel1f9c4182014-12-01 23:30:07 +0200895 cmd->channel_opt[0].flags =
896 cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS |
897 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
898 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD);
899 cmd->channel_opt[0].non_ebs_ratio =
900 cpu_to_le16(IWL_DENSE_EBS_SCAN_RATIO);
901 cmd->channel_opt[1].flags =
902 cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS |
903 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
904 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD);
905 cmd->channel_opt[1].non_ebs_ratio =
906 cpu_to_le16(IWL_SPARSE_EBS_SCAN_RATIO);
907 }
908
Luciano Coelhof7b788b2015-04-02 00:08:35 +0300909 iwl_mvm_lmac_scan_cfg_channels(mvm, params->channels,
910 params->n_channels, ssid_bitmap, cmd);
David Spinadelfb98be52014-05-04 12:51:10 +0300911
Luciano Coelho45d1b122015-04-15 16:34:13 +0300912 *preq = params->preq;
David Spinadelfb98be52014-05-04 12:51:10 +0300913
Luciano Coelho8df3e682015-04-01 17:37:44 +0300914 return 0;
David Spinadelfb98be52014-05-04 12:51:10 +0300915}
916
David Spinadelfb98be52014-05-04 12:51:10 +0300917int iwl_mvm_cancel_scan(struct iwl_mvm *mvm)
918{
David Spinadeld2496222014-05-20 12:46:37 +0300919 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)
920 return iwl_umac_scan_stop(mvm, IWL_UMAC_SCAN_UID_REG_SCAN,
921 true);
922
Luciano Coelho9af91f42015-02-10 10:42:26 +0200923 if (!(mvm->scan_status & IWL_MVM_SCAN_REGULAR))
Emmanuel Grumbach9b520d82014-11-04 15:54:11 +0200924 return 0;
925
926 if (iwl_mvm_is_radio_killed(mvm)) {
927 ieee80211_scan_completed(mvm->hw, true);
928 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
Luciano Coelho9af91f42015-02-10 10:42:26 +0200929 mvm->scan_status &= ~IWL_MVM_SCAN_REGULAR;
Emmanuel Grumbach9b520d82014-11-04 15:54:11 +0200930 return 0;
931 }
932
Luciano Coelho1f940382015-02-10 13:03:38 +0200933 return iwl_mvm_scan_offload_stop(mvm, true);
David Spinadelfb98be52014-05-04 12:51:10 +0300934}
David Spinadeld2496222014-05-20 12:46:37 +0300935
936/* UMAC scan API */
937
938struct iwl_umac_scan_done {
939 struct iwl_mvm *mvm;
940 enum iwl_umac_scan_uid_type type;
941};
942
943static int rate_to_scan_rate_flag(unsigned int rate)
944{
945 static const int rate_to_scan_rate[IWL_RATE_COUNT] = {
946 [IWL_RATE_1M_INDEX] = SCAN_CONFIG_RATE_1M,
947 [IWL_RATE_2M_INDEX] = SCAN_CONFIG_RATE_2M,
948 [IWL_RATE_5M_INDEX] = SCAN_CONFIG_RATE_5M,
949 [IWL_RATE_11M_INDEX] = SCAN_CONFIG_RATE_11M,
950 [IWL_RATE_6M_INDEX] = SCAN_CONFIG_RATE_6M,
951 [IWL_RATE_9M_INDEX] = SCAN_CONFIG_RATE_9M,
952 [IWL_RATE_12M_INDEX] = SCAN_CONFIG_RATE_12M,
953 [IWL_RATE_18M_INDEX] = SCAN_CONFIG_RATE_18M,
954 [IWL_RATE_24M_INDEX] = SCAN_CONFIG_RATE_24M,
955 [IWL_RATE_36M_INDEX] = SCAN_CONFIG_RATE_36M,
956 [IWL_RATE_48M_INDEX] = SCAN_CONFIG_RATE_48M,
957 [IWL_RATE_54M_INDEX] = SCAN_CONFIG_RATE_54M,
958 };
959
960 return rate_to_scan_rate[rate];
961}
962
963static __le32 iwl_mvm_scan_config_rates(struct iwl_mvm *mvm)
964{
965 struct ieee80211_supported_band *band;
966 unsigned int rates = 0;
967 int i;
968
969 band = &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
970 for (i = 0; i < band->n_bitrates; i++)
971 rates |= rate_to_scan_rate_flag(band->bitrates[i].hw_value);
972 band = &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
973 for (i = 0; i < band->n_bitrates; i++)
974 rates |= rate_to_scan_rate_flag(band->bitrates[i].hw_value);
975
976 /* Set both basic rates and supported rates */
977 rates |= SCAN_CONFIG_SUPPORTED_RATE(rates);
978
979 return cpu_to_le32(rates);
980}
981
982int iwl_mvm_config_scan(struct iwl_mvm *mvm)
983{
984
985 struct iwl_scan_config *scan_config;
986 struct ieee80211_supported_band *band;
987 int num_channels =
988 mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels +
989 mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels;
990 int ret, i, j = 0, cmd_size, data_size;
991 struct iwl_host_cmd cmd = {
992 .id = SCAN_CFG_CMD,
993 };
994
995 if (WARN_ON(num_channels > mvm->fw->ucode_capa.n_scan_channels))
996 return -ENOBUFS;
997
998 cmd_size = sizeof(*scan_config) + mvm->fw->ucode_capa.n_scan_channels;
999
1000 scan_config = kzalloc(cmd_size, GFP_KERNEL);
1001 if (!scan_config)
1002 return -ENOMEM;
1003
1004 data_size = cmd_size - sizeof(struct iwl_mvm_umac_cmd_hdr);
1005 scan_config->hdr.size = cpu_to_le16(data_size);
1006 scan_config->flags = cpu_to_le32(SCAN_CONFIG_FLAG_ACTIVATE |
1007 SCAN_CONFIG_FLAG_ALLOW_CHUB_REQS |
1008 SCAN_CONFIG_FLAG_SET_TX_CHAINS |
1009 SCAN_CONFIG_FLAG_SET_RX_CHAINS |
1010 SCAN_CONFIG_FLAG_SET_ALL_TIMES |
1011 SCAN_CONFIG_FLAG_SET_LEGACY_RATES |
1012 SCAN_CONFIG_FLAG_SET_MAC_ADDR |
1013 SCAN_CONFIG_FLAG_SET_CHANNEL_FLAGS|
1014 SCAN_CONFIG_N_CHANNELS(num_channels));
Moshe Harela0544272014-12-08 21:13:14 +02001015 scan_config->tx_chains = cpu_to_le32(iwl_mvm_get_valid_tx_ant(mvm));
David Spinadeld2496222014-05-20 12:46:37 +03001016 scan_config->rx_chains = cpu_to_le32(iwl_mvm_scan_rx_ant(mvm));
1017 scan_config->legacy_rates = iwl_mvm_scan_config_rates(mvm);
1018 scan_config->out_of_channel_time = cpu_to_le32(170);
1019 scan_config->suspend_time = cpu_to_le32(30);
1020 scan_config->dwell_active = 20;
1021 scan_config->dwell_passive = 110;
1022 scan_config->dwell_fragmented = 20;
1023
1024 memcpy(&scan_config->mac_addr, &mvm->addresses[0].addr, ETH_ALEN);
1025
1026 scan_config->bcast_sta_id = mvm->aux_sta.sta_id;
1027 scan_config->channel_flags = IWL_CHANNEL_FLAG_EBS |
1028 IWL_CHANNEL_FLAG_ACCURATE_EBS |
1029 IWL_CHANNEL_FLAG_EBS_ADD |
1030 IWL_CHANNEL_FLAG_PRE_SCAN_PASSIVE2ACTIVE;
1031
1032 band = &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
1033 for (i = 0; i < band->n_channels; i++, j++)
Ilan Peera25d40e2015-01-23 21:13:01 +02001034 scan_config->channel_array[j] = band->channels[i].hw_value;
David Spinadeld2496222014-05-20 12:46:37 +03001035 band = &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
1036 for (i = 0; i < band->n_channels; i++, j++)
Ilan Peera25d40e2015-01-23 21:13:01 +02001037 scan_config->channel_array[j] = band->channels[i].hw_value;
David Spinadeld2496222014-05-20 12:46:37 +03001038
1039 cmd.data[0] = scan_config;
1040 cmd.len[0] = cmd_size;
1041 cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
1042
1043 IWL_DEBUG_SCAN(mvm, "Sending UMAC scan config\n");
1044
1045 ret = iwl_mvm_send_cmd(mvm, &cmd);
1046
1047 kfree(scan_config);
1048 return ret;
1049}
1050
1051static int iwl_mvm_find_scan_uid(struct iwl_mvm *mvm, u32 uid)
1052{
1053 int i;
1054
Luciano Coelho507e4cd2015-03-19 22:58:33 +02001055 for (i = 0; i < mvm->max_scans; i++)
David Spinadeld2496222014-05-20 12:46:37 +03001056 if (mvm->scan_uid[i] == uid)
1057 return i;
1058
1059 return i;
1060}
1061
1062static int iwl_mvm_find_free_scan_uid(struct iwl_mvm *mvm)
1063{
1064 return iwl_mvm_find_scan_uid(mvm, 0);
1065}
1066
1067static bool iwl_mvm_find_scan_type(struct iwl_mvm *mvm,
1068 enum iwl_umac_scan_uid_type type)
1069{
1070 int i;
1071
Luciano Coelho507e4cd2015-03-19 22:58:33 +02001072 for (i = 0; i < mvm->max_scans; i++)
David Spinadeld2496222014-05-20 12:46:37 +03001073 if (mvm->scan_uid[i] & type)
1074 return true;
1075
1076 return false;
1077}
1078
Alexander Bondar963221b2015-03-26 11:07:35 +02001079static int iwl_mvm_find_first_scan(struct iwl_mvm *mvm,
1080 enum iwl_umac_scan_uid_type type)
1081{
1082 int i;
1083
Luciano Coelho507e4cd2015-03-19 22:58:33 +02001084 for (i = 0; i < mvm->max_scans; i++)
Alexander Bondar963221b2015-03-26 11:07:35 +02001085 if (mvm->scan_uid[i] & type)
1086 return i;
1087
1088 return i;
1089}
1090
David Spinadeld2496222014-05-20 12:46:37 +03001091static u32 iwl_generate_scan_uid(struct iwl_mvm *mvm,
1092 enum iwl_umac_scan_uid_type type)
1093{
1094 u32 uid;
1095
1096 /* make sure exactly one bit is on in scan type */
1097 WARN_ON(hweight8(type) != 1);
1098
1099 /*
1100 * Make sure scan uids are unique. If one scan lasts long time while
1101 * others are completing frequently, the seq number will wrap up and
1102 * we may have more than one scan with the same uid.
1103 */
1104 do {
1105 uid = type | (mvm->scan_seq_num <<
1106 IWL_UMAC_SCAN_UID_SEQ_OFFSET);
1107 mvm->scan_seq_num++;
Luciano Coelho507e4cd2015-03-19 22:58:33 +02001108 } while (iwl_mvm_find_scan_uid(mvm, uid) < mvm->max_scans);
David Spinadeld2496222014-05-20 12:46:37 +03001109
1110 IWL_DEBUG_SCAN(mvm, "Generated scan UID %u\n", uid);
1111
1112 return uid;
1113}
1114
Luciano Coelho133c8252015-04-20 15:29:03 +03001115static void iwl_mvm_scan_umac_dwell(struct iwl_mvm *mvm,
David Spinadeld2496222014-05-20 12:46:37 +03001116 struct iwl_scan_req_umac *cmd,
1117 struct iwl_mvm_scan_params *params)
1118{
David Spinadeld2496222014-05-20 12:46:37 +03001119 cmd->active_dwell = params->dwell[IEEE80211_BAND_2GHZ].active;
1120 cmd->passive_dwell = params->dwell[IEEE80211_BAND_2GHZ].passive;
1121 if (params->passive_fragmented)
1122 cmd->fragmented_dwell =
David Spinadel190f1022015-02-17 12:45:21 +02001123 params->dwell[IEEE80211_BAND_2GHZ].fragmented;
David Spinadeld2496222014-05-20 12:46:37 +03001124 cmd->max_out_time = cpu_to_le32(params->max_out_time);
1125 cmd->suspend_time = cpu_to_le32(params->suspend_time);
1126 cmd->scan_priority = cpu_to_le32(IWL_SCAN_PRIORITY_HIGH);
Luciano Coelho133c8252015-04-20 15:29:03 +03001127
1128 if (iwl_mvm_scan_total_iterations(params) == 0)
1129 cmd->ooc_priority = cpu_to_le32(IWL_SCAN_PRIORITY_HIGH);
1130 else
1131 cmd->ooc_priority = cpu_to_le32(IWL_SCAN_PRIORITY_LOW);
David Spinadeld2496222014-05-20 12:46:37 +03001132}
1133
1134static void
1135iwl_mvm_umac_scan_cfg_channels(struct iwl_mvm *mvm,
1136 struct ieee80211_channel **channels,
1137 int n_channels, u32 ssid_bitmap,
1138 struct iwl_scan_req_umac *cmd)
1139{
1140 struct iwl_scan_channel_cfg_umac *channel_cfg = (void *)&cmd->data;
1141 int i;
1142
1143 for (i = 0; i < n_channels; i++) {
1144 channel_cfg[i].flags = cpu_to_le32(ssid_bitmap);
1145 channel_cfg[i].channel_num = channels[i]->hw_value;
1146 channel_cfg[i].iter_count = 1;
1147 channel_cfg[i].iter_interval = 0;
1148 }
1149}
1150
Luciano Coelho6f4dcc72015-04-20 14:37:16 +03001151static u32 iwl_mvm_scan_umac_flags(struct iwl_mvm *mvm,
1152 struct iwl_mvm_scan_params *params)
David Spinadeld2496222014-05-20 12:46:37 +03001153{
1154 int flags = 0;
1155
Luciano Coelho6f4dcc72015-04-20 14:37:16 +03001156 if (params->n_ssids == 0)
David Spinadeld2496222014-05-20 12:46:37 +03001157 flags = IWL_UMAC_SCAN_GEN_FLAGS_PASSIVE;
1158
Luciano Coelho6f4dcc72015-04-20 14:37:16 +03001159 if (params->n_ssids == 1 && params->ssids[0].ssid_len != 0)
David Spinadeld2496222014-05-20 12:46:37 +03001160 flags |= IWL_UMAC_SCAN_GEN_FLAGS_PRE_CONNECT;
1161
Luciano Coelho6f4dcc72015-04-20 14:37:16 +03001162 if (params->passive_fragmented)
David Spinadeld2496222014-05-20 12:46:37 +03001163 flags |= IWL_UMAC_SCAN_GEN_FLAGS_FRAGMENTED;
1164
1165 if (iwl_mvm_rrm_scan_needed(mvm))
1166 flags |= IWL_UMAC_SCAN_GEN_FLAGS_RRM_ENABLED;
1167
Luciano Coelho6f4dcc72015-04-20 14:37:16 +03001168 if (params->pass_all)
1169 flags |= IWL_UMAC_SCAN_GEN_FLAGS_PASS_ALL;
1170 else
1171 flags |= IWL_UMAC_SCAN_GEN_FLAGS_MATCH;
1172
1173 if (iwl_mvm_scan_total_iterations(params) > 1)
1174 flags |= IWL_UMAC_SCAN_GEN_FLAGS_PERIODIC;
1175
David Spinadeld2496222014-05-20 12:46:37 +03001176 return flags;
1177}
1178
Luciano Coelho6749dd82015-03-20 15:51:36 +02001179static int iwl_mvm_scan_umac(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
Luciano Coelho3db7c6e2015-04-01 17:09:56 +03001180 struct iwl_mvm_scan_params *params)
David Spinadeld2496222014-05-20 12:46:37 +03001181{
David Spinadeld2496222014-05-20 12:46:37 +03001182 struct iwl_scan_req_umac *cmd = mvm->scan_cmd;
1183 struct iwl_scan_req_umac_tail *sec_part = (void *)&cmd->data +
1184 sizeof(struct iwl_scan_channel_cfg_umac) *
1185 mvm->fw->ucode_capa.n_scan_channels;
Luciano Coelho6f4dcc72015-04-20 14:37:16 +03001186 u32 uid;
Johannes Bergc8660dd2014-11-17 15:06:52 +01001187 u32 ssid_bitmap = 0;
Luciano Coelho6f4dcc72015-04-20 14:37:16 +03001188 int n_iterations = iwl_mvm_scan_total_iterations(params);
Luciano Coelho5ef766f2015-04-02 15:37:05 +03001189 int uid_idx;
David Spinadeld2496222014-05-20 12:46:37 +03001190
1191 lockdep_assert_held(&mvm->mutex);
1192
1193 uid_idx = iwl_mvm_find_free_scan_uid(mvm);
Luciano Coelho507e4cd2015-03-19 22:58:33 +02001194 if (uid_idx >= mvm->max_scans)
David Spinadeld2496222014-05-20 12:46:37 +03001195 return -EBUSY;
1196
Luciano Coelho133c8252015-04-20 15:29:03 +03001197 memset(cmd, 0, ksize(cmd));
1198 cmd->hdr.size = cpu_to_le16(iwl_mvm_scan_size(mvm) -
1199 sizeof(struct iwl_mvm_umac_cmd_hdr));
David Spinadeld2496222014-05-20 12:46:37 +03001200
Luciano Coelho133c8252015-04-20 15:29:03 +03001201 iwl_mvm_scan_umac_dwell(mvm, cmd, params);
1202
1203 if (n_iterations == 1)
Luciano Coelho8423cdc2015-04-17 14:49:58 +03001204 uid = iwl_generate_scan_uid(mvm, IWL_UMAC_SCAN_UID_REG_SCAN);
Luciano Coelho133c8252015-04-20 15:29:03 +03001205 else
Luciano Coelho8423cdc2015-04-17 14:49:58 +03001206 uid = iwl_generate_scan_uid(mvm, IWL_UMAC_SCAN_UID_SCHED_SCAN);
Luciano Coelho8423cdc2015-04-17 14:49:58 +03001207
1208 mvm->scan_uid[uid_idx] = uid;
1209 cmd->uid = cpu_to_le32(uid);
1210
Luciano Coelho6f4dcc72015-04-20 14:37:16 +03001211 cmd->general_flags = cpu_to_le32(iwl_mvm_scan_umac_flags(mvm, params));
Haim Dreyfuss4db65582015-01-05 15:00:35 +02001212
Luciano Coelho8423cdc2015-04-17 14:49:58 +03001213 if (iwl_mvm_scan_use_ebs(mvm, n_iterations))
Haim Dreyfuss4db65582015-01-05 15:00:35 +02001214 cmd->channel_flags = IWL_SCAN_CHANNEL_FLAG_EBS |
1215 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
1216 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD;
1217
Luciano Coelhof7b788b2015-04-02 00:08:35 +03001218 cmd->n_channels = params->n_channels;
David Spinadeld2496222014-05-20 12:46:37 +03001219
Luciano Coelhoe2ec4f62015-04-02 17:49:04 +03001220 iwl_scan_build_ssids(params, sec_part->direct_scan, &ssid_bitmap);
David Spinadeld2496222014-05-20 12:46:37 +03001221
Luciano Coelhof7b788b2015-04-02 00:08:35 +03001222 iwl_mvm_umac_scan_cfg_channels(mvm, params->channels,
1223 params->n_channels, ssid_bitmap, cmd);
David Spinadeld2496222014-05-20 12:46:37 +03001224
Luciano Coelho8423cdc2015-04-17 14:49:58 +03001225 /* With UMAC we can have only one schedule, so use the sum of
1226 * the iterations (with a a maximum of 255).
1227 */
1228 sec_part->schedule[0].iter_count =
1229 (n_iterations > 255) ? 255 : n_iterations;
Luciano Coelhocf5d3172015-04-16 20:13:28 +03001230 sec_part->schedule[0].interval = cpu_to_le16(params->interval);
1231
Luciano Coelho283c2492015-04-17 11:18:46 +03001232 sec_part->delay = cpu_to_le16(params->delay);
Luciano Coelho45d1b122015-04-15 16:34:13 +03001233 sec_part->preq = params->preq;
David Spinadeld2496222014-05-20 12:46:37 +03001234
Luciano Coelho8df3e682015-04-01 17:37:44 +03001235 return 0;
David Spinadeld2496222014-05-20 12:46:37 +03001236}
1237
Luciano Coelho6749dd82015-03-20 15:51:36 +02001238static int iwl_mvm_num_scans(struct iwl_mvm *mvm)
1239{
1240 return hweight32(mvm->scan_status & IWL_MVM_SCAN_MASK);
1241}
1242
1243static int iwl_mvm_check_running_scans(struct iwl_mvm *mvm, int type)
1244{
1245 /* This looks a bit arbitrary, but the idea is that if we run
1246 * out of possible simultaneous scans and the userspace is
1247 * trying to run a scan type that is already running, we
1248 * return -EBUSY. But if the userspace wants to start a
1249 * different type of scan, we stop the opposite type to make
1250 * space for the new request. The reason is backwards
1251 * compatibility with old wpa_supplicant that wouldn't stop a
1252 * scheduled scan before starting a normal scan.
1253 */
1254
1255 if (iwl_mvm_num_scans(mvm) < mvm->max_scans)
1256 return 0;
1257
1258 /* Use a switch, even though this is a bitmask, so that more
1259 * than one bits set will fall in default and we will warn.
1260 */
1261 switch (type) {
1262 case IWL_MVM_SCAN_REGULAR:
1263 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR_MASK)
1264 return -EBUSY;
1265 return iwl_mvm_scan_offload_stop(mvm, true);
1266 case IWL_MVM_SCAN_SCHED:
1267 if (mvm->scan_status & IWL_MVM_SCAN_SCHED_MASK)
1268 return -EBUSY;
1269 return iwl_mvm_cancel_scan(mvm);
Luciano Coelho19945df2015-03-20 16:11:28 +02001270 case IWL_MVM_SCAN_NETDETECT:
1271 /* No need to stop anything for net-detect since the
1272 * firmware is restarted anyway. This way, any sched
1273 * scans that were running will be restarted when we
1274 * resume.
1275 */
1276 return 0;
Luciano Coelho6749dd82015-03-20 15:51:36 +02001277 default:
1278 WARN_ON(1);
1279 break;
1280 }
1281
1282 return -EIO;
1283}
1284
1285int iwl_mvm_reg_scan_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1286 struct cfg80211_scan_request *req,
1287 struct ieee80211_scan_ies *ies)
1288{
Luciano Coelho3db7c6e2015-04-01 17:09:56 +03001289 struct iwl_host_cmd hcmd = {
1290 .len = { iwl_mvm_scan_size(mvm), },
1291 .data = { mvm->scan_cmd, },
1292 .dataflags = { IWL_HCMD_DFL_NOCOPY, },
1293 };
1294 struct iwl_mvm_scan_params params = {};
Luciano Coelho6749dd82015-03-20 15:51:36 +02001295 int ret;
1296
1297 lockdep_assert_held(&mvm->mutex);
1298
1299 if (iwl_mvm_is_lar_supported(mvm) && !mvm->lar_regdom_set) {
1300 IWL_ERR(mvm, "scan while LAR regdomain is not set\n");
1301 return -EBUSY;
1302 }
1303
1304 ret = iwl_mvm_check_running_scans(mvm, IWL_MVM_SCAN_REGULAR);
1305 if (ret)
1306 return ret;
1307
1308 iwl_mvm_ref(mvm, IWL_MVM_REF_SCAN);
1309
Luciano Coelho3db7c6e2015-04-01 17:09:56 +03001310 /* we should have failed registration if scan_cmd was NULL */
1311 if (WARN_ON(!mvm->scan_cmd))
1312 return -ENOMEM;
1313
1314 if (!iwl_mvm_scan_fits(mvm, req->n_ssids, ies, req->n_channels))
1315 return -ENOBUFS;
1316
Luciano Coelho4b817052015-04-15 16:21:16 +03001317 params.n_ssids = req->n_ssids;
1318 params.flags = req->flags;
Luciano Coelhof7b788b2015-04-02 00:08:35 +03001319 params.n_channels = req->n_channels;
1320 params.delay = 0;
1321 params.interval = 0;
1322 params.ssids = req->ssids;
1323 params.channels = req->channels;
1324 params.mac_addr = req->mac_addr;
1325 params.mac_addr_mask = req->mac_addr_mask;
1326 params.no_cck = req->no_cck;
1327 params.pass_all = true;
1328 params.n_match_sets = 0;
1329 params.match_sets = NULL;
Luciano Coelho3db7c6e2015-04-01 17:09:56 +03001330
Luciano Coelhocf5d3172015-04-16 20:13:28 +03001331 params.schedule[0].iterations = 1;
1332 params.schedule[0].full_scan_mul = 0;
1333 params.schedule[1].iterations = 0;
1334 params.schedule[1].full_scan_mul = 0;
1335
Luciano Coelho4b817052015-04-15 16:21:16 +03001336 iwl_mvm_scan_calc_dwell(mvm, vif, &params);
1337
Luciano Coelho45d1b122015-04-15 16:34:13 +03001338 iwl_mvm_build_scan_probe(mvm, vif, ies, &params);
1339
Luciano Coelho3db7c6e2015-04-01 17:09:56 +03001340 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN) {
1341 hcmd.id = SCAN_REQ_UMAC;
Luciano Coelho45d1b122015-04-15 16:34:13 +03001342 ret = iwl_mvm_scan_umac(mvm, vif, &params);
Luciano Coelho3db7c6e2015-04-01 17:09:56 +03001343 } else {
1344 hcmd.id = SCAN_OFFLOAD_REQUEST_CMD;
Luciano Coelho45d1b122015-04-15 16:34:13 +03001345 ret = iwl_mvm_scan_lmac(mvm, vif, &params);
Luciano Coelho3db7c6e2015-04-01 17:09:56 +03001346 }
1347
1348 if (ret)
1349 return ret;
1350
1351 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1352 if (!ret) {
1353 IWL_DEBUG_SCAN(mvm, "Scan request was sent successfully\n");
1354 mvm->scan_status |= IWL_MVM_SCAN_REGULAR;
1355 } else {
1356 /* If the scan failed, it usually means that the FW was unable
1357 * to allocate the time events. Warn on it, but maybe we
1358 * should try to send the command again with different params.
1359 */
1360 IWL_ERR(mvm, "Scan failed! ret %d\n", ret);
1361 }
Luciano Coelho6749dd82015-03-20 15:51:36 +02001362
1363 if (ret)
1364 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
1365
1366 return ret;
1367}
1368
Luciano Coelho65ff5562015-03-20 13:35:47 +02001369int iwl_mvm_sched_scan_start(struct iwl_mvm *mvm,
1370 struct ieee80211_vif *vif,
1371 struct cfg80211_sched_scan_request *req,
Luciano Coelho19945df2015-03-20 16:11:28 +02001372 struct ieee80211_scan_ies *ies,
1373 int type)
Luciano Coelho65ff5562015-03-20 13:35:47 +02001374{
Luciano Coelho8df3e682015-04-01 17:37:44 +03001375 struct iwl_host_cmd hcmd = {
1376 .len = { iwl_mvm_scan_size(mvm), },
1377 .data = { mvm->scan_cmd, },
1378 .dataflags = { IWL_HCMD_DFL_NOCOPY, },
1379 };
1380 struct iwl_mvm_scan_params params = {};
Luciano Coelho65ff5562015-03-20 13:35:47 +02001381 int ret;
1382
Luciano Coelho6749dd82015-03-20 15:51:36 +02001383 lockdep_assert_held(&mvm->mutex);
1384
1385 if (iwl_mvm_is_lar_supported(mvm) && !mvm->lar_regdom_set) {
1386 IWL_ERR(mvm, "sched-scan while LAR regdomain is not set\n");
1387 return -EBUSY;
1388 }
1389
Luciano Coelho19945df2015-03-20 16:11:28 +02001390 ret = iwl_mvm_check_running_scans(mvm, type);
Luciano Coelho6749dd82015-03-20 15:51:36 +02001391 if (ret)
1392 return ret;
1393
Luciano Coelho8df3e682015-04-01 17:37:44 +03001394 /* we should have failed registration if scan_cmd was NULL */
1395 if (WARN_ON(!mvm->scan_cmd))
1396 return -ENOMEM;
1397
1398 if (!iwl_mvm_scan_fits(mvm, req->n_ssids, ies, req->n_channels))
1399 return -ENOBUFS;
1400
Luciano Coelho4b817052015-04-15 16:21:16 +03001401 params.n_ssids = req->n_ssids;
1402 params.flags = req->flags;
Luciano Coelhof7b788b2015-04-02 00:08:35 +03001403 params.n_channels = req->n_channels;
Luciano Coelhof7b788b2015-04-02 00:08:35 +03001404 params.ssids = req->ssids;
1405 params.channels = req->channels;
1406 params.mac_addr = req->mac_addr;
1407 params.mac_addr_mask = req->mac_addr_mask;
1408 params.no_cck = false;
1409 params.pass_all = iwl_mvm_scan_pass_all(mvm, req);
1410 params.n_match_sets = req->n_match_sets;
1411 params.match_sets = req->match_sets;
1412
Luciano Coelhocf5d3172015-04-16 20:13:28 +03001413 params.schedule[0].iterations = IWL_FAST_SCHED_SCAN_ITERATIONS;
1414 params.schedule[0].full_scan_mul = 1;
1415 params.schedule[1].iterations = 0xff;
1416 params.schedule[1].full_scan_mul = IWL_FULL_SCAN_MULTIPLIER;
1417
Luciano Coelhof7b788b2015-04-02 00:08:35 +03001418 if (req->interval > U16_MAX) {
1419 IWL_DEBUG_SCAN(mvm,
1420 "interval value is > 16-bits, set to max possible\n");
1421 params.interval = U16_MAX;
1422 } else {
1423 params.interval = req->interval / MSEC_PER_SEC;
1424 }
Luciano Coelho8df3e682015-04-01 17:37:44 +03001425
Luciano Coelho283c2492015-04-17 11:18:46 +03001426 /* In theory, LMAC scans can handle a 32-bit delay, but since
1427 * waiting for over 18 hours to start the scan is a bit silly
1428 * and to keep it aligned with UMAC scans (which only support
1429 * 16-bit delays), trim it down to 16-bits.
1430 */
1431 if (req->delay > U16_MAX) {
1432 IWL_DEBUG_SCAN(mvm,
1433 "delay value is > 16-bits, set to max possible\n");
1434 params.delay = U16_MAX;
1435 } else {
1436 params.delay = req->delay;
1437 }
1438
Luciano Coelho4b817052015-04-15 16:21:16 +03001439 iwl_mvm_scan_calc_dwell(mvm, vif, &params);
1440
Luciano Coelho65ff5562015-03-20 13:35:47 +02001441 ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
1442 if (ret)
1443 return ret;
1444
Luciano Coelho45d1b122015-04-15 16:34:13 +03001445 iwl_mvm_build_scan_probe(mvm, vif, ies, &params);
1446
Luciano Coelho65ff5562015-03-20 13:35:47 +02001447 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN) {
Luciano Coelho8df3e682015-04-01 17:37:44 +03001448 hcmd.id = SCAN_REQ_UMAC;
Luciano Coelho8423cdc2015-04-17 14:49:58 +03001449 ret = iwl_mvm_scan_umac(mvm, vif, &params);
Luciano Coelho65ff5562015-03-20 13:35:47 +02001450 } else {
Luciano Coelho8df3e682015-04-01 17:37:44 +03001451 hcmd.id = SCAN_OFFLOAD_REQUEST_CMD;
Luciano Coelho7d7de1e2015-04-17 09:53:55 +03001452 ret = iwl_mvm_scan_lmac(mvm, vif, &params);
Luciano Coelho8df3e682015-04-01 17:37:44 +03001453 }
1454
1455 if (ret)
1456 return ret;
1457
1458 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1459 if (!ret) {
1460 IWL_DEBUG_SCAN(mvm,
1461 "Sched scan request was sent successfully\n");
1462 mvm->scan_status |= type;
1463 } else {
1464 /* If the scan failed, it usually means that the FW was unable
1465 * to allocate the time events. Warn on it, but maybe we
1466 * should try to send the command again with different params.
1467 */
1468 IWL_ERR(mvm, "Sched scan failed! ret %d\n", ret);
Luciano Coelho65ff5562015-03-20 13:35:47 +02001469 }
1470
1471 return ret;
1472}
1473
David Spinadeld2496222014-05-20 12:46:37 +03001474int iwl_mvm_rx_umac_scan_complete_notif(struct iwl_mvm *mvm,
1475 struct iwl_rx_cmd_buffer *rxb,
1476 struct iwl_device_cmd *cmd)
1477{
1478 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1479 struct iwl_umac_scan_complete *notif = (void *)pkt->data;
1480 u32 uid = __le32_to_cpu(notif->uid);
1481 bool sched = !!(uid & IWL_UMAC_SCAN_UID_SCHED_SCAN);
1482 int uid_idx = iwl_mvm_find_scan_uid(mvm, uid);
1483
David Spinadel2992a322014-11-10 11:16:53 +02001484 /*
1485 * Scan uid may be set to zero in case of scan abort request from above.
1486 */
Luciano Coelho507e4cd2015-03-19 22:58:33 +02001487 if (uid_idx >= mvm->max_scans)
David Spinadeld2496222014-05-20 12:46:37 +03001488 return 0;
1489
1490 IWL_DEBUG_SCAN(mvm,
1491 "Scan completed, uid %u type %s, status %s, EBS status %s\n",
1492 uid, sched ? "sched" : "regular",
1493 notif->status == IWL_SCAN_OFFLOAD_COMPLETED ?
1494 "completed" : "aborted",
1495 notif->ebs_status == IWL_SCAN_EBS_SUCCESS ?
1496 "success" : "failed");
1497
Haim Dreyfuss5a4b2af2015-01-13 11:54:51 +02001498 if (notif->ebs_status)
1499 mvm->last_ebs_successful = false;
1500
David Spinadeld2496222014-05-20 12:46:37 +03001501 mvm->scan_uid[uid_idx] = 0;
1502
1503 if (!sched) {
1504 ieee80211_scan_completed(mvm->hw,
1505 notif->status ==
1506 IWL_SCAN_OFFLOAD_ABORTED);
1507 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
1508 } else if (!iwl_mvm_find_scan_type(mvm, IWL_UMAC_SCAN_UID_SCHED_SCAN)) {
1509 ieee80211_sched_scan_stopped(mvm->hw);
1510 } else {
1511 IWL_DEBUG_SCAN(mvm, "Another sched scan is running\n");
1512 }
1513
1514 return 0;
1515}
1516
1517static bool iwl_scan_umac_done_check(struct iwl_notif_wait_data *notif_wait,
1518 struct iwl_rx_packet *pkt, void *data)
1519{
1520 struct iwl_umac_scan_done *scan_done = data;
1521 struct iwl_umac_scan_complete *notif = (void *)pkt->data;
1522 u32 uid = __le32_to_cpu(notif->uid);
1523 int uid_idx = iwl_mvm_find_scan_uid(scan_done->mvm, uid);
1524
1525 if (WARN_ON(pkt->hdr.cmd != SCAN_COMPLETE_UMAC))
1526 return false;
1527
Luciano Coelho507e4cd2015-03-19 22:58:33 +02001528 if (uid_idx >= scan_done->mvm->max_scans)
David Spinadeld2496222014-05-20 12:46:37 +03001529 return false;
1530
1531 /*
1532 * Clear scan uid of scans that was aborted from above and completed
Haim Dreyfuss5a4b2af2015-01-13 11:54:51 +02001533 * in FW so the RX handler does nothing. Set last_ebs_successful here if
1534 * needed.
David Spinadeld2496222014-05-20 12:46:37 +03001535 */
1536 scan_done->mvm->scan_uid[uid_idx] = 0;
1537
Haim Dreyfuss5a4b2af2015-01-13 11:54:51 +02001538 if (notif->ebs_status)
1539 scan_done->mvm->last_ebs_successful = false;
1540
David Spinadeld2496222014-05-20 12:46:37 +03001541 return !iwl_mvm_find_scan_type(scan_done->mvm, scan_done->type);
1542}
1543
1544static int iwl_umac_scan_abort_one(struct iwl_mvm *mvm, u32 uid)
1545{
1546 struct iwl_umac_scan_abort cmd = {
1547 .hdr.size = cpu_to_le16(sizeof(struct iwl_umac_scan_abort) -
1548 sizeof(struct iwl_mvm_umac_cmd_hdr)),
1549 .uid = cpu_to_le32(uid),
1550 };
1551
1552 lockdep_assert_held(&mvm->mutex);
1553
1554 IWL_DEBUG_SCAN(mvm, "Sending scan abort, uid %u\n", uid);
1555
1556 return iwl_mvm_send_cmd_pdu(mvm, SCAN_ABORT_UMAC, 0, sizeof(cmd), &cmd);
1557}
1558
1559static int iwl_umac_scan_stop(struct iwl_mvm *mvm,
1560 enum iwl_umac_scan_uid_type type, bool notify)
1561{
1562 struct iwl_notification_wait wait_scan_done;
1563 static const u8 scan_done_notif[] = { SCAN_COMPLETE_UMAC, };
1564 struct iwl_umac_scan_done scan_done = {
1565 .mvm = mvm,
1566 .type = type,
1567 };
1568 int i, ret = -EIO;
1569
1570 iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_done,
1571 scan_done_notif,
1572 ARRAY_SIZE(scan_done_notif),
1573 iwl_scan_umac_done_check, &scan_done);
1574
1575 IWL_DEBUG_SCAN(mvm, "Preparing to stop scan, type %x\n", type);
1576
Luciano Coelho507e4cd2015-03-19 22:58:33 +02001577 for (i = 0; i < mvm->max_scans; i++) {
David Spinadeld2496222014-05-20 12:46:37 +03001578 if (mvm->scan_uid[i] & type) {
1579 int err;
1580
1581 if (iwl_mvm_is_radio_killed(mvm) &&
1582 (type & IWL_UMAC_SCAN_UID_REG_SCAN)) {
1583 ieee80211_scan_completed(mvm->hw, true);
1584 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
1585 break;
1586 }
1587
1588 err = iwl_umac_scan_abort_one(mvm, mvm->scan_uid[i]);
1589 if (!err)
1590 ret = 0;
1591 }
1592 }
1593
1594 if (ret) {
1595 IWL_DEBUG_SCAN(mvm, "Couldn't stop scan\n");
1596 iwl_remove_notification(&mvm->notif_wait, &wait_scan_done);
1597 return ret;
1598 }
1599
1600 ret = iwl_wait_notification(&mvm->notif_wait, &wait_scan_done, 1 * HZ);
1601 if (ret)
1602 return ret;
1603
1604 if (notify) {
1605 if (type & IWL_UMAC_SCAN_UID_SCHED_SCAN)
1606 ieee80211_sched_scan_stopped(mvm->hw);
1607 if (type & IWL_UMAC_SCAN_UID_REG_SCAN) {
1608 ieee80211_scan_completed(mvm->hw, true);
1609 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
1610 }
1611 }
1612
1613 return ret;
1614}
1615
1616int iwl_mvm_scan_size(struct iwl_mvm *mvm)
1617{
1618 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)
1619 return sizeof(struct iwl_scan_req_umac) +
1620 sizeof(struct iwl_scan_channel_cfg_umac) *
1621 mvm->fw->ucode_capa.n_scan_channels +
1622 sizeof(struct iwl_scan_req_umac_tail);
1623
Luciano Coelho65ff5562015-03-20 13:35:47 +02001624 return sizeof(struct iwl_scan_req_lmac) +
Luciano Coelho1f940382015-02-10 13:03:38 +02001625 sizeof(struct iwl_scan_channel_cfg_lmac) *
1626 mvm->fw->ucode_capa.n_scan_channels +
1627 sizeof(struct iwl_scan_probe_req);
David Spinadeld2496222014-05-20 12:46:37 +03001628}
David Spinadel4ffb3652015-03-10 10:06:02 +02001629
1630/*
1631 * This function is used in nic restart flow, to inform mac80211 about scans
1632 * that was aborted by restart flow or by an assert.
1633 */
1634void iwl_mvm_report_scan_aborted(struct iwl_mvm *mvm)
1635{
1636 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN) {
Alexander Bondar963221b2015-03-26 11:07:35 +02001637 u32 uid, i;
1638
1639 uid = iwl_mvm_find_first_scan(mvm, IWL_UMAC_SCAN_UID_REG_SCAN);
Luciano Coelho507e4cd2015-03-19 22:58:33 +02001640 if (uid < mvm->max_scans) {
David Spinadel4ffb3652015-03-10 10:06:02 +02001641 ieee80211_scan_completed(mvm->hw, true);
Alexander Bondar963221b2015-03-26 11:07:35 +02001642 mvm->scan_uid[uid] = 0;
1643 }
1644 uid = iwl_mvm_find_first_scan(mvm,
1645 IWL_UMAC_SCAN_UID_SCHED_SCAN);
Luciano Coelho507e4cd2015-03-19 22:58:33 +02001646 if (uid < mvm->max_scans && !mvm->restart_fw) {
David Spinadel4ffb3652015-03-10 10:06:02 +02001647 ieee80211_sched_scan_stopped(mvm->hw);
Alexander Bondar963221b2015-03-26 11:07:35 +02001648 mvm->scan_uid[uid] = 0;
1649 }
1650
1651 /* We shouldn't have any UIDs still set. Loop over all the
1652 * UIDs to make sure there's nothing left there and warn if
1653 * any is found.
1654 */
Luciano Coelho507e4cd2015-03-19 22:58:33 +02001655 for (i = 0; i < mvm->max_scans; i++) {
Alexander Bondar963221b2015-03-26 11:07:35 +02001656 if (WARN_ONCE(mvm->scan_uid[i],
1657 "UMAC scan UID %d was not cleaned\n",
1658 mvm->scan_uid[i]))
1659 mvm->scan_uid[i] = 0;
1660 }
David Spinadel4ffb3652015-03-10 10:06:02 +02001661 } else {
Luciano Coelho9af91f42015-02-10 10:42:26 +02001662 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
David Spinadel4ffb3652015-03-10 10:06:02 +02001663 ieee80211_scan_completed(mvm->hw, true);
Luciano Coelho9af91f42015-02-10 10:42:26 +02001664
1665 /* Sched scan will be restarted by mac80211 in
1666 * restart_hw, so do not report if FW is about to be
1667 * restarted.
1668 */
1669 if ((mvm->scan_status & IWL_MVM_SCAN_SCHED) && !mvm->restart_fw)
1670 ieee80211_sched_scan_stopped(mvm->hw);
David Spinadel4ffb3652015-03-10 10:06:02 +02001671 }
1672}