blob: 9409237435b60d02c0c88e25cdaa191ade7c6e12 [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 +0300104static u8 iwl_mvm_scan_rx_ant(struct iwl_mvm *mvm)
105{
106 if (mvm->scan_rx_ant != ANT_NONE)
107 return mvm->scan_rx_ant;
Moshe Harela0544272014-12-08 21:13:14 +0200108 return iwl_mvm_get_valid_rx_ant(mvm);
David Spinadeld2496222014-05-20 12:46:37 +0300109}
110
Johannes Berg8ca151b2013-01-24 14:25:36 +0100111static inline __le16 iwl_mvm_scan_rx_chain(struct iwl_mvm *mvm)
112{
113 u16 rx_chain;
Oren Givon91b05d12013-08-19 08:36:48 +0300114 u8 rx_ant;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100115
David Spinadeld2496222014-05-20 12:46:37 +0300116 rx_ant = iwl_mvm_scan_rx_ant(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100117 rx_chain = rx_ant << PHY_RX_CHAIN_VALID_POS;
118 rx_chain |= rx_ant << PHY_RX_CHAIN_FORCE_MIMO_SEL_POS;
119 rx_chain |= rx_ant << PHY_RX_CHAIN_FORCE_SEL_POS;
120 rx_chain |= 0x1 << PHY_RX_CHAIN_DRIVER_FORCE_POS;
121 return cpu_to_le16(rx_chain);
122}
123
David Spinadelfb98be52014-05-04 12:51:10 +0300124static __le32 iwl_mvm_scan_rxon_flags(enum ieee80211_band band)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100125{
David Spinadelfb98be52014-05-04 12:51:10 +0300126 if (band == IEEE80211_BAND_2GHZ)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100127 return cpu_to_le32(PHY_BAND_24);
128 else
129 return cpu_to_le32(PHY_BAND_5);
130}
131
132static inline __le32
133iwl_mvm_scan_rate_n_flags(struct iwl_mvm *mvm, enum ieee80211_band band,
134 bool no_cck)
135{
136 u32 tx_ant;
137
138 mvm->scan_last_antenna_idx =
Moshe Harela0544272014-12-08 21:13:14 +0200139 iwl_mvm_next_antenna(mvm, iwl_mvm_get_valid_tx_ant(mvm),
Johannes Berg8ca151b2013-01-24 14:25:36 +0100140 mvm->scan_last_antenna_idx);
141 tx_ant = BIT(mvm->scan_last_antenna_idx) << RATE_MCS_ANT_POS;
142
143 if (band == IEEE80211_BAND_2GHZ && !no_cck)
144 return cpu_to_le32(IWL_RATE_1M_PLCP | RATE_MCS_CCK_MSK |
145 tx_ant);
146 else
147 return cpu_to_le32(IWL_RATE_6M_PLCP | tx_ant);
148}
149
150/*
Johannes Berg8ca151b2013-01-24 14:25:36 +0100151 * If req->n_ssids > 0, it means we should do an active scan.
152 * In case of active scan w/o directed scan, we receive a zero-length SSID
153 * just to notify that this scan is active and not passive.
154 * In order to notify the FW of the number of SSIDs we wish to scan (including
155 * the zero-length one), we need to set the corresponding bits in chan->type,
David Spinadel20f1a5d2013-08-21 09:14:27 +0300156 * one for each SSID, and set the active bit (first). If the first SSID is
157 * already included in the probe template, so we need to set only
158 * req->n_ssids - 1 bits in addition to the first bit.
Johannes Berg8ca151b2013-01-24 14:25:36 +0100159 */
David Spinadel3cae0732014-12-29 15:43:48 +0200160static u16 iwl_mvm_get_active_dwell(struct iwl_mvm *mvm,
161 enum ieee80211_band band, int n_ssids)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100162{
David Spinadel3cae0732014-12-29 15:43:48 +0200163 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BASIC_DWELL)
164 return 10;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100165 if (band == IEEE80211_BAND_2GHZ)
David Spinadel39745332014-09-10 16:40:41 +0300166 return 20 + 3 * (n_ssids + 1);
167 return 10 + 2 * (n_ssids + 1);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100168}
169
David Spinadel3cae0732014-12-29 15:43:48 +0200170static u16 iwl_mvm_get_passive_dwell(struct iwl_mvm *mvm,
171 enum ieee80211_band band)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100172{
David Spinadel3cae0732014-12-29 15:43:48 +0200173 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BASIC_DWELL)
174 return 110;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100175 return band == IEEE80211_BAND_2GHZ ? 100 + 20 : 100 + 10;
176}
177
Alexander Bondar8a110d92014-03-12 17:31:19 +0200178static void iwl_mvm_scan_condition_iterator(void *data, u8 *mac,
179 struct ieee80211_vif *vif)
Haim Dreyfuss61f63252013-11-03 23:02:59 +0200180{
Alexander Bondar8a110d92014-03-12 17:31:19 +0200181 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Haim Dreyfussc3f8d0a2014-12-02 11:03:16 +0200182 int *global_cnt = data;
Haim Dreyfuss61f63252013-11-03 23:02:59 +0200183
David Spinadel1e2ebe02014-10-26 15:53:27 +0200184 if (vif->type != NL80211_IFTYPE_P2P_DEVICE && mvmvif->phy_ctxt &&
185 mvmvif->phy_ctxt->id < MAX_PHYS)
Haim Dreyfussc3f8d0a2014-12-02 11:03:16 +0200186 *global_cnt += 1;
Alexander Bondar8a110d92014-03-12 17:31:19 +0200187}
188
Luciano Coelho4b817052015-04-15 16:21:16 +0300189static void iwl_mvm_scan_calc_dwell(struct iwl_mvm *mvm,
190 struct ieee80211_vif *vif,
191 struct iwl_mvm_scan_params *params)
Alexander Bondar8a110d92014-03-12 17:31:19 +0200192{
Haim Dreyfussc3f8d0a2014-12-02 11:03:16 +0200193 int global_cnt = 0;
Alexander Bondar50df8a32014-03-12 20:30:51 +0200194 enum ieee80211_band band;
David Spinadel2ce89cd2014-07-22 13:11:18 +0300195 u8 frag_passive_dwell = 0;
Alexander Bondar8a110d92014-03-12 17:31:19 +0200196
197 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
198 IEEE80211_IFACE_ITER_NORMAL,
199 iwl_mvm_scan_condition_iterator,
Haim Dreyfussc3f8d0a2014-12-02 11:03:16 +0200200 &global_cnt);
Haim Dreyfussc3f8d0a2014-12-02 11:03:16 +0200201 if (!global_cnt)
Alexander Bondaref67f18d2014-03-30 10:47:08 +0300202 goto not_bound;
203
David Spinadel2ce89cd2014-07-22 13:11:18 +0300204 params->suspend_time = 30;
Haim Dreyfuss44e9cd72014-12-18 12:34:01 +0200205 params->max_out_time = 120;
Alexander Bondaref67f18d2014-03-30 10:47:08 +0300206
207 if (iwl_mvm_low_latency(mvm)) {
David Spinadel2ce89cd2014-07-22 13:11:18 +0300208 if (mvm->fw->ucode_capa.api[0] &
209 IWL_UCODE_TLV_API_FRAGMENTED_SCAN) {
210 params->suspend_time = 105;
Haim Dreyfussc3f8d0a2014-12-02 11:03:16 +0200211 /*
212 * If there is more than one active interface make
213 * passive scan more fragmented.
214 */
David Spinadelef177082015-02-15 14:45:33 +0200215 frag_passive_dwell = 40;
Haim Dreyfuss44e9cd72014-12-18 12:34:01 +0200216 params->max_out_time = frag_passive_dwell;
David Spinadel2ce89cd2014-07-22 13:11:18 +0300217 } else {
218 params->suspend_time = 120;
219 params->max_out_time = 120;
220 }
221 }
222
223 if (frag_passive_dwell && (mvm->fw->ucode_capa.api[0] &
224 IWL_UCODE_TLV_API_FRAGMENTED_SCAN)) {
225 /*
226 * P2P device scan should not be fragmented to avoid negative
227 * impact on P2P device discovery. Configure max_out_time to be
228 * equal to dwell time on passive channel. Take a longest
229 * possible value, one that corresponds to 2GHz band
230 */
231 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
232 u32 passive_dwell =
David Spinadel3cae0732014-12-29 15:43:48 +0200233 iwl_mvm_get_passive_dwell(mvm,
234 IEEE80211_BAND_2GHZ);
David Spinadel2ce89cd2014-07-22 13:11:18 +0300235 params->max_out_time = passive_dwell;
236 } else {
237 params->passive_fragmented = true;
238 }
Alexander Bondar50df8a32014-03-12 20:30:51 +0200239 }
240
Luciano Coelho4b817052015-04-15 16:21:16 +0300241 if ((params->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
Luciano Coelhoc1537662015-04-09 14:48:11 +0300242 (params->max_out_time > 200))
Johannes Bergab480032014-06-04 10:13:50 +0200243 params->max_out_time = 200;
244
Alexander Bondaref67f18d2014-03-30 10:47:08 +0300245not_bound:
246
Alexander Bondar50df8a32014-03-12 20:30:51 +0200247 for (band = IEEE80211_BAND_2GHZ; band < IEEE80211_NUM_BANDS; band++) {
David Spinadel2ce89cd2014-07-22 13:11:18 +0300248 if (params->passive_fragmented)
David Spinadel190f1022015-02-17 12:45:21 +0200249 params->dwell[band].fragmented = frag_passive_dwell;
250
251 params->dwell[band].passive = iwl_mvm_get_passive_dwell(mvm,
252 band);
Luciano Coelho4b817052015-04-15 16:21:16 +0300253 params->dwell[band].active =
254 iwl_mvm_get_active_dwell(mvm, band, params->n_ssids);
Alexander Bondar50df8a32014-03-12 20:30:51 +0200255 }
Luciano Coelho0616c622015-04-09 12:18:56 +0300256
257 IWL_DEBUG_SCAN(mvm,
258 "scan parameters: max_out_time %d, suspend_time %d, passive_fragmented %d\n",
259 params->max_out_time, params->suspend_time,
260 params->passive_fragmented);
261 IWL_DEBUG_SCAN(mvm,
262 "dwell[IEEE80211_BAND_2GHZ]: passive %d, active %d, fragmented %d\n",
263 params->dwell[IEEE80211_BAND_2GHZ].passive,
264 params->dwell[IEEE80211_BAND_2GHZ].active,
265 params->dwell[IEEE80211_BAND_2GHZ].fragmented);
266 IWL_DEBUG_SCAN(mvm,
267 "dwell[IEEE80211_BAND_5GHZ]: passive %d, active %d, fragmented %d\n",
268 params->dwell[IEEE80211_BAND_5GHZ].passive,
269 params->dwell[IEEE80211_BAND_5GHZ].active,
270 params->dwell[IEEE80211_BAND_5GHZ].fragmented);
Haim Dreyfuss61f63252013-11-03 23:02:59 +0200271}
272
Andrei Otcheretianski73897bd2014-07-09 18:59:14 +0300273static inline bool iwl_mvm_rrm_scan_needed(struct iwl_mvm *mvm)
274{
275 /* require rrm scan whenever the fw supports it */
276 return mvm->fw->ucode_capa.capa[0] &
277 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT;
278}
279
Luciano Coelho999d2562015-03-27 10:28:26 +0300280static int iwl_mvm_max_scan_ie_fw_cmd_room(struct iwl_mvm *mvm)
Andrei Otcheretianski48849a42014-09-09 10:58:49 +0300281{
282 int max_probe_len;
283
Luciano Coelho1f940382015-02-10 13:03:38 +0200284 max_probe_len = SCAN_OFFLOAD_PROBE_REQ_SIZE;
Andrei Otcheretianski48849a42014-09-09 10:58:49 +0300285
286 /* we create the 802.11 header and SSID element */
287 max_probe_len -= 24 + 2;
288
Andrei Otcheretianski66dc5272014-09-02 17:55:40 +0300289 /* DS parameter set element is added on 2.4GHZ band if required */
290 if (iwl_mvm_rrm_scan_needed(mvm))
291 max_probe_len -= 3;
292
Andrei Otcheretianski48849a42014-09-09 10:58:49 +0300293 return max_probe_len;
294}
295
Luciano Coelho999d2562015-03-27 10:28:26 +0300296int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm)
Andrei Otcheretianski48849a42014-09-09 10:58:49 +0300297{
Luciano Coelho999d2562015-03-27 10:28:26 +0300298 int max_ie_len = iwl_mvm_max_scan_ie_fw_cmd_room(mvm);
Andrei Otcheretianski48849a42014-09-09 10:58:49 +0300299
Andrei Otcheretianski48849a42014-09-09 10:58:49 +0300300 /* TODO: [BUG] This function should return the maximum allowed size of
301 * scan IEs, however the LMAC scan api contains both 2GHZ and 5GHZ IEs
302 * in the same command. So the correct implementation of this function
303 * is just iwl_mvm_max_scan_ie_fw_cmd_room() / 2. Currently the scan
304 * command has only 512 bytes and it would leave us with about 240
305 * bytes for scan IEs, which is clearly not enough. So meanwhile
306 * we will report an incorrect value. This may result in a failure to
307 * issue a scan in unified_scan_lmac and unified_sched_scan_lmac
308 * functions with -ENOBUFS, if a large enough probe will be provided.
309 */
310 return max_ie_len;
311}
312
Avraham Stern1fa1bcc2015-03-31 16:22:33 +0300313static u8 *iwl_mvm_dump_channel_list(struct iwl_scan_results_notif *res,
314 int num_res, u8 *buf, size_t buf_size)
315{
316 int i;
317 u8 *pos = buf, *end = buf + buf_size;
318
319 for (i = 0; pos < end && i < num_res; i++)
320 pos += snprintf(pos, end - pos, " %u", res[i].channel);
321
322 /* terminate the string in case the buffer was too short */
323 *(buf + buf_size - 1) = '\0';
324
325 return buf;
326}
327
Luciano Coelho6e56f012015-05-06 16:03:39 +0300328int iwl_mvm_rx_lmac_scan_iter_complete_notif(struct iwl_mvm *mvm,
329 struct iwl_rx_cmd_buffer *rxb,
330 struct iwl_device_cmd *cmd)
Alexander Bondare5d74642014-12-09 19:15:49 +0200331{
332 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Avraham Stern1083fd72015-03-31 16:14:41 +0300333 struct iwl_lmac_scan_complete_notif *notif = (void *)pkt->data;
Avraham Stern1fa1bcc2015-03-31 16:22:33 +0300334 u8 buf[256];
Alexander Bondare5d74642014-12-09 19:15:49 +0200335
336 IWL_DEBUG_SCAN(mvm,
Avraham Stern1fa1bcc2015-03-31 16:22:33 +0300337 "Scan offload iteration complete: status=0x%x scanned channels=%d channels list: %s\n",
338 notif->status, notif->scanned_channels,
339 iwl_mvm_dump_channel_list(notif->results,
340 notif->scanned_channels, buf,
341 sizeof(buf)));
Alexander Bondare5d74642014-12-09 19:15:49 +0200342 return 0;
343}
344
Luciano Coelho6e56f012015-05-06 16:03:39 +0300345int iwl_mvm_rx_scan_match_found(struct iwl_mvm *mvm,
346 struct iwl_rx_cmd_buffer *rxb,
347 struct iwl_device_cmd *cmd)
David Spinadel35a000b2013-08-28 09:29:43 +0300348{
David Spinadeld2496222014-05-20 12:46:37 +0300349 IWL_DEBUG_SCAN(mvm, "Scheduled scan results\n");
350 ieee80211_sched_scan_results(mvm->hw);
David Spinadel35a000b2013-08-28 09:29:43 +0300351
352 return 0;
353}
354
David Spinadelf0bf8592015-05-20 11:56:59 +0300355static const char *iwl_mvm_ebs_status_str(enum iwl_scan_ebs_status status)
356{
357 switch (status) {
358 case IWL_SCAN_EBS_SUCCESS:
359 return "successful";
360 case IWL_SCAN_EBS_INACTIVE:
361 return "inactive";
362 case IWL_SCAN_EBS_FAILED:
363 case IWL_SCAN_EBS_CHAN_NOT_FOUND:
364 default:
365 return "failed";
366 }
367}
368
Luciano Coelho6e56f012015-05-06 16:03:39 +0300369int iwl_mvm_rx_lmac_scan_complete_notif(struct iwl_mvm *mvm,
370 struct iwl_rx_cmd_buffer *rxb,
371 struct iwl_device_cmd *cmd)
David Spinadel35a000b2013-08-28 09:29:43 +0300372{
373 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Luciano Coelho9af91f42015-02-10 10:42:26 +0200374 struct iwl_periodic_scan_complete *scan_notif = (void *)pkt->data;
375 bool aborted = (scan_notif->status == IWL_SCAN_OFFLOAD_ABORTED);
David Spinadelfb98be52014-05-04 12:51:10 +0300376
Johannes Berga6623e82014-01-27 15:40:53 +0100377 /* scan status must be locked for proper checking */
378 lockdep_assert_held(&mvm->mutex);
379
Luciano Coelho9af91f42015-02-10 10:42:26 +0200380 /* We first check if we were stopping a scan, in which case we
381 * just clear the stopping flag. Then we check if it was a
382 * firmware initiated stop, in which case we need to inform
383 * mac80211.
384 * Note that we can have a stopping and a running scan
385 * simultaneously, but we can't have two different types of
386 * scans stopping or running at the same time (since LMAC
387 * doesn't support it).
388 */
Haim Dreyfusse820c2d2014-04-06 11:19:09 +0300389
Luciano Coelho9af91f42015-02-10 10:42:26 +0200390 if (mvm->scan_status & IWL_MVM_SCAN_STOPPING_SCHED) {
391 WARN_ON_ONCE(mvm->scan_status & IWL_MVM_SCAN_STOPPING_REGULAR);
David Spinadel35a000b2013-08-28 09:29:43 +0300392
Luciano Coelho9af91f42015-02-10 10:42:26 +0200393 IWL_DEBUG_SCAN(mvm, "Scheduled scan %s, EBS status %s\n",
394 aborted ? "aborted" : "completed",
David Spinadelf0bf8592015-05-20 11:56:59 +0300395 iwl_mvm_ebs_status_str(scan_notif->ebs_status));
Luciano Coelho9af91f42015-02-10 10:42:26 +0200396
397 mvm->scan_status &= ~IWL_MVM_SCAN_STOPPING_SCHED;
398 } else if (mvm->scan_status & IWL_MVM_SCAN_STOPPING_REGULAR) {
399 IWL_DEBUG_SCAN(mvm, "Regular scan %s, EBS status %s\n",
400 aborted ? "aborted" : "completed",
David Spinadelf0bf8592015-05-20 11:56:59 +0300401 iwl_mvm_ebs_status_str(scan_notif->ebs_status));
Luciano Coelho9af91f42015-02-10 10:42:26 +0200402
403 mvm->scan_status &= ~IWL_MVM_SCAN_STOPPING_REGULAR;
404 } else if (mvm->scan_status & IWL_MVM_SCAN_SCHED) {
405 WARN_ON_ONCE(mvm->scan_status & IWL_MVM_SCAN_REGULAR);
406
407 IWL_DEBUG_SCAN(mvm, "Scheduled scan %s, EBS status %s (FW)\n",
408 aborted ? "aborted" : "completed",
David Spinadelf0bf8592015-05-20 11:56:59 +0300409 iwl_mvm_ebs_status_str(scan_notif->ebs_status));
Luciano Coelho9af91f42015-02-10 10:42:26 +0200410
411 mvm->scan_status &= ~IWL_MVM_SCAN_SCHED;
Arik Nemtsov33ea27f2014-02-10 15:34:29 +0200412 ieee80211_sched_scan_stopped(mvm->hw);
Luciano Coelho9af91f42015-02-10 10:42:26 +0200413 } else if (mvm->scan_status & IWL_MVM_SCAN_REGULAR) {
414 IWL_DEBUG_SCAN(mvm, "Regular scan %s, EBS status %s (FW)\n",
415 aborted ? "aborted" : "completed",
David Spinadelf0bf8592015-05-20 11:56:59 +0300416 iwl_mvm_ebs_status_str(scan_notif->ebs_status));
Luciano Coelho9af91f42015-02-10 10:42:26 +0200417
418 mvm->scan_status &= ~IWL_MVM_SCAN_REGULAR;
David Spinadelfb98be52014-05-04 12:51:10 +0300419 ieee80211_scan_completed(mvm->hw,
Luciano Coelho1f940382015-02-10 13:03:38 +0200420 scan_notif->status == IWL_SCAN_OFFLOAD_ABORTED);
Eliad Peller4ff78182014-06-22 14:44:44 +0300421 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +0200422 }
David Spinadel35a000b2013-08-28 09:29:43 +0300423
David Spinadelf0bf8592015-05-20 11:56:59 +0300424 mvm->last_ebs_successful =
425 scan_notif->ebs_status == IWL_SCAN_EBS_SUCCESS ||
426 scan_notif->ebs_status == IWL_SCAN_EBS_INACTIVE;
Haim Dreyfusse820c2d2014-04-06 11:19:09 +0300427
David Spinadel35a000b2013-08-28 09:29:43 +0300428 return 0;
429}
430
David Spinadel35a000b2013-08-28 09:29:43 +0300431static int iwl_ssid_exist(u8 *ssid, u8 ssid_len, struct iwl_ssid_ie *ssid_list)
432{
433 int i;
434
435 for (i = 0; i < PROBE_OPTION_MAX; i++) {
436 if (!ssid_list[i].len)
437 break;
438 if (ssid_list[i].len == ssid_len &&
439 !memcmp(ssid_list->ssid, ssid, ssid_len))
440 return i;
441 }
442 return -1;
443}
444
Luciano Coelhoe2ec4f62015-04-02 17:49:04 +0300445/* We insert the SSIDs in an inverted order, because the FW will
446 * invert it back.
447 */
448static void iwl_scan_build_ssids(struct iwl_mvm_scan_params *params,
449 struct iwl_ssid_ie *ssids,
450 u32 *ssid_bitmap)
David Spinadel35a000b2013-08-28 09:29:43 +0300451{
452 int i, j;
453 int index;
454
455 /*
456 * copy SSIDs from match list.
457 * iwl_config_sched_scan_profiles() uses the order of these ssids to
458 * config match list.
459 */
Luciano Coelho1c1b5b22015-04-02 16:31:42 +0300460 for (i = 0, j = params->n_match_sets - 1;
461 j >= 0 && i < PROBE_OPTION_MAX;
462 i++, j--) {
Johannes Bergea73cbc2014-01-24 10:53:53 +0100463 /* skip empty SSID matchsets */
Luciano Coelho1c1b5b22015-04-02 16:31:42 +0300464 if (!params->match_sets[j].ssid.ssid_len)
Johannes Bergea73cbc2014-01-24 10:53:53 +0100465 continue;
Luciano Coelhoe2ec4f62015-04-02 17:49:04 +0300466 ssids[i].id = WLAN_EID_SSID;
467 ssids[i].len = params->match_sets[j].ssid.ssid_len;
468 memcpy(ssids[i].ssid, params->match_sets[j].ssid.ssid,
469 ssids[i].len);
David Spinadel35a000b2013-08-28 09:29:43 +0300470 }
471
472 /* add SSIDs from scan SSID list */
473 *ssid_bitmap = 0;
Luciano Coelho1c1b5b22015-04-02 16:31:42 +0300474 for (j = params->n_ssids - 1;
475 j >= 0 && i < PROBE_OPTION_MAX;
476 i++, j--) {
Luciano Coelhof7b788b2015-04-02 00:08:35 +0300477 index = iwl_ssid_exist(params->ssids[j].ssid,
478 params->ssids[j].ssid_len,
Luciano Coelhoe2ec4f62015-04-02 17:49:04 +0300479 ssids);
David Spinadel35a000b2013-08-28 09:29:43 +0300480 if (index < 0) {
Luciano Coelhoe2ec4f62015-04-02 17:49:04 +0300481 ssids[i].id = WLAN_EID_SSID;
482 ssids[i].len = params->ssids[j].ssid_len;
483 memcpy(ssids[i].ssid, params->ssids[j].ssid,
484 ssids[i].len);
485 *ssid_bitmap |= BIT(i);
David Spinadel35a000b2013-08-28 09:29:43 +0300486 } else {
Luciano Coelhoe2ec4f62015-04-02 17:49:04 +0300487 *ssid_bitmap |= BIT(index);
David Spinadel35a000b2013-08-28 09:29:43 +0300488 }
489 }
490}
491
Luciano Coelho416c9b52015-05-05 11:32:29 +0300492static int
493iwl_mvm_config_sched_scan_profiles(struct iwl_mvm *mvm,
494 struct cfg80211_sched_scan_request *req)
David Spinadel35a000b2013-08-28 09:29:43 +0300495{
496 struct iwl_scan_offload_profile *profile;
497 struct iwl_scan_offload_profile_cfg *profile_cfg;
498 struct iwl_scan_offload_blacklist *blacklist;
499 struct iwl_host_cmd cmd = {
500 .id = SCAN_OFFLOAD_UPDATE_PROFILES_CMD,
David Spinadel35a000b2013-08-28 09:29:43 +0300501 .len[1] = sizeof(*profile_cfg),
502 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
503 .dataflags[1] = IWL_HCMD_DFL_NOCOPY,
504 };
505 int blacklist_len;
506 int i;
507 int ret;
508
509 if (WARN_ON(req->n_match_sets > IWL_SCAN_MAX_PROFILES))
510 return -EIO;
511
512 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_SHORT_BL)
513 blacklist_len = IWL_SCAN_SHORT_BLACKLIST_LEN;
514 else
515 blacklist_len = IWL_SCAN_MAX_BLACKLIST_LEN;
516
517 blacklist = kzalloc(sizeof(*blacklist) * blacklist_len, GFP_KERNEL);
518 if (!blacklist)
519 return -ENOMEM;
520
521 profile_cfg = kzalloc(sizeof(*profile_cfg), GFP_KERNEL);
522 if (!profile_cfg) {
523 ret = -ENOMEM;
524 goto free_blacklist;
525 }
526
527 cmd.data[0] = blacklist;
528 cmd.len[0] = sizeof(*blacklist) * blacklist_len;
529 cmd.data[1] = profile_cfg;
530
531 /* No blacklist configuration */
532
533 profile_cfg->num_profiles = req->n_match_sets;
534 profile_cfg->active_clients = SCAN_CLIENT_SCHED_SCAN;
535 profile_cfg->pass_match = SCAN_CLIENT_SCHED_SCAN;
536 profile_cfg->match_notify = SCAN_CLIENT_SCHED_SCAN;
David Spinadel6e0bbe52013-12-30 09:59:45 +0200537 if (!req->n_match_sets || !req->match_sets[0].ssid.ssid_len)
538 profile_cfg->any_beacon_notify = SCAN_CLIENT_SCHED_SCAN;
David Spinadel35a000b2013-08-28 09:29:43 +0300539
540 for (i = 0; i < req->n_match_sets; i++) {
541 profile = &profile_cfg->profiles[i];
542 profile->ssid_index = i;
543 /* Support any cipher and auth algorithm */
544 profile->unicast_cipher = 0xff;
545 profile->auth_alg = 0xff;
546 profile->network_type = IWL_NETWORK_TYPE_ANY;
547 profile->band_selection = IWL_SCAN_OFFLOAD_SELECT_ANY;
548 profile->client_bitmap = SCAN_CLIENT_SCHED_SCAN;
549 }
550
551 IWL_DEBUG_SCAN(mvm, "Sending scheduled scan profile config\n");
552
553 ret = iwl_mvm_send_cmd(mvm, &cmd);
554 kfree(profile_cfg);
555free_blacklist:
556 kfree(blacklist);
557
558 return ret;
559}
560
David Spinadeld2496222014-05-20 12:46:37 +0300561static bool iwl_mvm_scan_pass_all(struct iwl_mvm *mvm,
562 struct cfg80211_sched_scan_request *req)
563{
564 if (req->n_match_sets && req->match_sets[0].ssid.ssid_len) {
565 IWL_DEBUG_SCAN(mvm,
566 "Sending scheduled scan with filtering, n_match_sets %d\n",
567 req->n_match_sets);
568 return false;
569 }
570
571 IWL_DEBUG_SCAN(mvm, "Sending Scheduled scan without filtering\n");
572 return true;
573}
574
Luciano Coelhof2461792015-05-07 15:23:19 +0300575static int iwl_mvm_lmac_scan_abort(struct iwl_mvm *mvm)
David Spinadel35a000b2013-08-28 09:29:43 +0300576{
577 int ret;
578 struct iwl_host_cmd cmd = {
579 .id = SCAN_OFFLOAD_ABORT_CMD,
David Spinadel35a000b2013-08-28 09:29:43 +0300580 };
581 u32 status;
582
David Spinadel35a000b2013-08-28 09:29:43 +0300583 ret = iwl_mvm_send_cmd_status(mvm, &cmd, &status);
584 if (ret)
585 return ret;
586
587 if (status != CAN_ABORT_STATUS) {
588 /*
589 * The scan abort will return 1 for success or
590 * 2 for "failure". A failure condition can be
591 * due to simply not being in an active scan which
592 * can occur if we send the scan abort before the
593 * microcode has notified us that a scan is completed.
594 */
595 IWL_DEBUG_SCAN(mvm, "SCAN OFFLOAD ABORT ret %d.\n", status);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +0200596 ret = -ENOENT;
David Spinadel35a000b2013-08-28 09:29:43 +0300597 }
598
599 return ret;
600}
601
Luciano Coelho65ff5562015-03-20 13:35:47 +0200602static void iwl_mvm_scan_fill_tx_cmd(struct iwl_mvm *mvm,
603 struct iwl_scan_req_tx_cmd *tx_cmd,
604 bool no_cck)
David Spinadelfb98be52014-05-04 12:51:10 +0300605{
606 tx_cmd[0].tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL |
607 TX_CMD_FLG_BT_DIS);
608 tx_cmd[0].rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm,
609 IEEE80211_BAND_2GHZ,
610 no_cck);
611 tx_cmd[0].sta_id = mvm->aux_sta.sta_id;
612
613 tx_cmd[1].tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL |
614 TX_CMD_FLG_BT_DIS);
615 tx_cmd[1].rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm,
616 IEEE80211_BAND_5GHZ,
617 no_cck);
618 tx_cmd[1].sta_id = mvm->aux_sta.sta_id;
619}
620
621static void
622iwl_mvm_lmac_scan_cfg_channels(struct iwl_mvm *mvm,
623 struct ieee80211_channel **channels,
624 int n_channels, u32 ssid_bitmap,
Luciano Coelho65ff5562015-03-20 13:35:47 +0200625 struct iwl_scan_req_lmac *cmd)
David Spinadelfb98be52014-05-04 12:51:10 +0300626{
627 struct iwl_scan_channel_cfg_lmac *channel_cfg = (void *)&cmd->data;
628 int i;
629
630 for (i = 0; i < n_channels; i++) {
631 channel_cfg[i].channel_num =
632 cpu_to_le16(channels[i]->hw_value);
633 channel_cfg[i].iter_count = cpu_to_le16(1);
634 channel_cfg[i].iter_interval = 0;
635 channel_cfg[i].flags =
636 cpu_to_le32(IWL_UNIFIED_SCAN_CHANNEL_PARTIAL |
637 ssid_bitmap);
638 }
639}
640
Andrei Otcheretianski66dc5272014-09-02 17:55:40 +0300641static u8 *iwl_mvm_copy_and_insert_ds_elem(struct iwl_mvm *mvm, const u8 *ies,
642 size_t len, u8 *const pos)
643{
644 static const u8 before_ds_params[] = {
645 WLAN_EID_SSID,
646 WLAN_EID_SUPP_RATES,
647 WLAN_EID_REQUEST,
648 WLAN_EID_EXT_SUPP_RATES,
649 };
650 size_t offs;
651 u8 *newpos = pos;
652
653 if (!iwl_mvm_rrm_scan_needed(mvm)) {
654 memcpy(newpos, ies, len);
655 return newpos + len;
656 }
657
658 offs = ieee80211_ie_split(ies, len,
659 before_ds_params,
660 ARRAY_SIZE(before_ds_params),
661 0);
662
663 memcpy(newpos, ies, offs);
664 newpos += offs;
665
666 /* Add a placeholder for DS Parameter Set element */
667 *newpos++ = WLAN_EID_DS_PARAMS;
668 *newpos++ = 1;
669 *newpos++ = 0;
670
671 memcpy(newpos, ies + offs, len - offs);
672 newpos += len - offs;
673
674 return newpos;
675}
676
David Spinadelfb98be52014-05-04 12:51:10 +0300677static void
Luciano Coelho65ff5562015-03-20 13:35:47 +0200678iwl_mvm_build_scan_probe(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
679 struct ieee80211_scan_ies *ies,
Luciano Coelho45d1b122015-04-15 16:34:13 +0300680 struct iwl_mvm_scan_params *params)
David Spinadelfb98be52014-05-04 12:51:10 +0300681{
Luciano Coelho45d1b122015-04-15 16:34:13 +0300682 struct ieee80211_mgmt *frame = (void *)params->preq.buf;
Andrei Otcheretianski66dc5272014-09-02 17:55:40 +0300683 u8 *pos, *newpos;
Luciano Coelho45d1b122015-04-15 16:34:13 +0300684 const u8 *mac_addr = params->flags & NL80211_SCAN_FLAG_RANDOM_ADDR ?
685 params->mac_addr : NULL;
David Spinadelfb98be52014-05-04 12:51:10 +0300686
Johannes Bergeffd05a2014-11-18 17:21:19 +0100687 /*
688 * Unfortunately, right now the offload scan doesn't support randomising
689 * within the firmware, so until the firmware API is ready we implement
690 * it in the driver. This means that the scan iterations won't really be
691 * random, only when it's restarted, but at least that helps a bit.
692 */
693 if (mac_addr)
Luciano Coelho45d1b122015-04-15 16:34:13 +0300694 get_random_mask_addr(frame->sa, mac_addr,
695 params->mac_addr_mask);
Johannes Bergeffd05a2014-11-18 17:21:19 +0100696 else
697 memcpy(frame->sa, vif->addr, ETH_ALEN);
698
David Spinadelfb98be52014-05-04 12:51:10 +0300699 frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
700 eth_broadcast_addr(frame->da);
David Spinadelfb98be52014-05-04 12:51:10 +0300701 eth_broadcast_addr(frame->bssid);
702 frame->seq_ctrl = 0;
703
704 pos = frame->u.probe_req.variable;
705 *pos++ = WLAN_EID_SSID;
706 *pos++ = 0;
707
Luciano Coelho45d1b122015-04-15 16:34:13 +0300708 params->preq.mac_header.offset = 0;
709 params->preq.mac_header.len = cpu_to_le16(24 + 2);
David Spinadelfb98be52014-05-04 12:51:10 +0300710
Andrei Otcheretianski66dc5272014-09-02 17:55:40 +0300711 /* Insert ds parameter set element on 2.4 GHz band */
712 newpos = iwl_mvm_copy_and_insert_ds_elem(mvm,
713 ies->ies[IEEE80211_BAND_2GHZ],
714 ies->len[IEEE80211_BAND_2GHZ],
715 pos);
Luciano Coelho45d1b122015-04-15 16:34:13 +0300716 params->preq.band_data[0].offset = cpu_to_le16(pos - params->preq.buf);
717 params->preq.band_data[0].len = cpu_to_le16(newpos - pos);
Andrei Otcheretianski66dc5272014-09-02 17:55:40 +0300718 pos = newpos;
David Spinadelfb98be52014-05-04 12:51:10 +0300719
720 memcpy(pos, ies->ies[IEEE80211_BAND_5GHZ],
721 ies->len[IEEE80211_BAND_5GHZ]);
Luciano Coelho45d1b122015-04-15 16:34:13 +0300722 params->preq.band_data[1].offset = cpu_to_le16(pos - params->preq.buf);
723 params->preq.band_data[1].len =
724 cpu_to_le16(ies->len[IEEE80211_BAND_5GHZ]);
David Spinadelfb98be52014-05-04 12:51:10 +0300725 pos += ies->len[IEEE80211_BAND_5GHZ];
726
727 memcpy(pos, ies->common_ies, ies->common_ie_len);
Luciano Coelho45d1b122015-04-15 16:34:13 +0300728 params->preq.common_data.offset = cpu_to_le16(pos - params->preq.buf);
729 params->preq.common_data.len = cpu_to_le16(ies->common_ie_len);
David Spinadelfb98be52014-05-04 12:51:10 +0300730}
731
Avraham Sternd7afbfc2015-05-12 12:19:48 +0300732static __le32 iwl_mvm_scan_priority(struct iwl_mvm *mvm,
733 enum iwl_scan_priority_ext prio)
734{
735 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_EXT_SCAN_PRIORITY)
736 return cpu_to_le32(prio);
737
738 if (prio <= IWL_SCAN_PRIORITY_EXT_2)
739 return cpu_to_le32(IWL_SCAN_PRIORITY_LOW);
740
741 if (prio <= IWL_SCAN_PRIORITY_EXT_4)
742 return cpu_to_le32(IWL_SCAN_PRIORITY_MEDIUM);
743
744 return cpu_to_le32(IWL_SCAN_PRIORITY_HIGH);
745}
746
Luciano Coelho133c8252015-04-20 15:29:03 +0300747static void iwl_mvm_scan_lmac_dwell(struct iwl_mvm *mvm,
748 struct iwl_scan_req_lmac *cmd,
749 struct iwl_mvm_scan_params *params)
David Spinadelfb98be52014-05-04 12:51:10 +0300750{
David Spinadel2ce89cd2014-07-22 13:11:18 +0300751 cmd->active_dwell = params->dwell[IEEE80211_BAND_2GHZ].active;
752 cmd->passive_dwell = params->dwell[IEEE80211_BAND_2GHZ].passive;
753 if (params->passive_fragmented)
754 cmd->fragmented_dwell =
David Spinadel190f1022015-02-17 12:45:21 +0200755 params->dwell[IEEE80211_BAND_2GHZ].fragmented;
David Spinadelfb98be52014-05-04 12:51:10 +0300756 cmd->max_out_time = cpu_to_le32(params->max_out_time);
757 cmd->suspend_time = cpu_to_le32(params->suspend_time);
Avraham Sternd7afbfc2015-05-12 12:19:48 +0300758 cmd->scan_prio = iwl_mvm_scan_priority(mvm, IWL_SCAN_PRIORITY_EXT_6);
David Spinadelfb98be52014-05-04 12:51:10 +0300759}
760
Luciano Coelho999d2562015-03-27 10:28:26 +0300761static inline bool iwl_mvm_scan_fits(struct iwl_mvm *mvm, int n_ssids,
762 struct ieee80211_scan_ies *ies,
763 int n_channels)
764{
765 return ((n_ssids <= PROBE_OPTION_MAX) &&
766 (n_channels <= mvm->fw->ucode_capa.n_scan_channels) &
767 (ies->common_ie_len +
768 ies->len[NL80211_BAND_2GHZ] +
769 ies->len[NL80211_BAND_5GHZ] <=
770 iwl_mvm_max_scan_ie_fw_cmd_room(mvm)));
771}
772
Luciano Coelho7d7de1e2015-04-17 09:53:55 +0300773static inline bool iwl_mvm_scan_use_ebs(struct iwl_mvm *mvm, int n_iterations)
774{
775 const struct iwl_ucode_capabilities *capa = &mvm->fw->ucode_capa;
776
777 /* We can only use EBS if:
778 * 1. the feature is supported;
779 * 2. the last EBS was successful;
780 * 3. if only single scan, the single scan EBS API is supported.
781 */
782 return ((capa->flags & IWL_UCODE_TLV_FLAGS_EBS_SUPPORT) &&
783 mvm->last_ebs_successful &&
784 (n_iterations > 1 ||
785 (capa->api[0] & IWL_UCODE_TLV_API_SINGLE_SCAN_EBS)));
786}
787
Luciano Coelho6f4dcc72015-04-20 14:37:16 +0300788static int iwl_mvm_scan_total_iterations(struct iwl_mvm_scan_params *params)
789{
790 return params->schedule[0].iterations + params->schedule[1].iterations;
791}
792
Luciano Coelho87515402015-04-20 14:47:49 +0300793static int iwl_mvm_scan_lmac_flags(struct iwl_mvm *mvm,
794 struct iwl_mvm_scan_params *params)
795{
796 int flags = 0;
797
798 if (params->n_ssids == 0)
799 flags |= IWL_MVM_LMAC_SCAN_FLAG_PASSIVE;
800
801 if (params->n_ssids == 1 && params->ssids[0].ssid_len != 0)
802 flags |= IWL_MVM_LMAC_SCAN_FLAG_PRE_CONNECTION;
803
804 if (params->passive_fragmented)
805 flags |= IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED;
806
807 if (iwl_mvm_rrm_scan_needed(mvm))
808 flags |= IWL_MVM_LMAC_SCAN_FLAGS_RRM_ENABLED;
809
810 if (params->pass_all)
811 flags |= IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL;
812 else
813 flags |= IWL_MVM_LMAC_SCAN_FLAG_MATCH;
814
815#ifdef CONFIG_IWLWIFI_DEBUGFS
816 if (mvm->scan_iter_notif_enabled)
817 flags |= IWL_MVM_LMAC_SCAN_FLAG_ITER_COMPLETE;
818#endif
819
820 return flags;
821}
822
Luciano Coelho6749dd82015-03-20 15:51:36 +0200823static int iwl_mvm_scan_lmac(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
Luciano Coelho3db7c6e2015-04-01 17:09:56 +0300824 struct iwl_mvm_scan_params *params)
David Spinadelfb98be52014-05-04 12:51:10 +0300825{
Luciano Coelho65ff5562015-03-20 13:35:47 +0200826 struct iwl_scan_req_lmac *cmd = mvm->scan_cmd;
Luciano Coelho45d1b122015-04-15 16:34:13 +0300827 struct iwl_scan_probe_req *preq =
828 (void *)(cmd->data + sizeof(struct iwl_scan_channel_cfg_lmac) *
829 mvm->fw->ucode_capa.n_scan_channels);
Luciano Coelho87515402015-04-20 14:47:49 +0300830 u32 ssid_bitmap = 0;
Luciano Coelho6f4dcc72015-04-20 14:37:16 +0300831 int n_iterations = iwl_mvm_scan_total_iterations(params);
David Spinadelfb98be52014-05-04 12:51:10 +0300832
833 lockdep_assert_held(&mvm->mutex);
834
Luciano Coelho133c8252015-04-20 15:29:03 +0300835 memset(cmd, 0, ksize(cmd));
David Spinadelfb98be52014-05-04 12:51:10 +0300836
Luciano Coelho133c8252015-04-20 15:29:03 +0300837 iwl_mvm_scan_lmac_dwell(mvm, cmd, params);
838
839 cmd->rx_chain_select = iwl_mvm_scan_rx_chain(mvm);
840 cmd->iter_num = cpu_to_le32(1);
Luciano Coelhof7b788b2015-04-02 00:08:35 +0300841 cmd->n_channels = (u8)params->n_channels;
David Spinadelfb98be52014-05-04 12:51:10 +0300842
Luciano Coelhof7b788b2015-04-02 00:08:35 +0300843 cmd->delay = cpu_to_le32(params->delay);
Luciano Coelho2250fd92014-12-03 10:52:26 +0200844
Luciano Coelho87515402015-04-20 14:47:49 +0300845 cmd->scan_flags = cpu_to_le32(iwl_mvm_scan_lmac_flags(mvm, params));
David Spinadelfb98be52014-05-04 12:51:10 +0300846
Luciano Coelhof7b788b2015-04-02 00:08:35 +0300847 cmd->flags = iwl_mvm_scan_rxon_flags(params->channels[0]->band);
David Spinadelfb98be52014-05-04 12:51:10 +0300848 cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP |
849 MAC_FILTER_IN_BEACON);
Luciano Coelhof7b788b2015-04-02 00:08:35 +0300850 iwl_mvm_scan_fill_tx_cmd(mvm, cmd->tx_cmd, params->no_cck);
Luciano Coelhoe2ec4f62015-04-02 17:49:04 +0300851 iwl_scan_build_ssids(params, cmd->direct_scan, &ssid_bitmap);
852
853 /* this API uses bits 1-20 instead of 0-19 */
854 ssid_bitmap <<= 1;
Luciano Coelhof7b788b2015-04-02 00:08:35 +0300855
856 cmd->schedule[0].delay = cpu_to_le16(params->interval);
Luciano Coelhocf5d3172015-04-16 20:13:28 +0300857 cmd->schedule[0].iterations = params->schedule[0].iterations;
858 cmd->schedule[0].full_scan_mul = params->schedule[0].full_scan_mul;
Luciano Coelhof7b788b2015-04-02 00:08:35 +0300859 cmd->schedule[1].delay = cpu_to_le16(params->interval);
Luciano Coelhocf5d3172015-04-16 20:13:28 +0300860 cmd->schedule[1].iterations = params->schedule[1].iterations;
861 cmd->schedule[1].full_scan_mul = params->schedule[1].iterations;
David Spinadelfb98be52014-05-04 12:51:10 +0300862
Luciano Coelho7d7de1e2015-04-17 09:53:55 +0300863 if (iwl_mvm_scan_use_ebs(mvm, n_iterations)) {
David Spinadel1f9c4182014-12-01 23:30:07 +0200864 cmd->channel_opt[0].flags =
865 cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS |
866 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
867 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD);
868 cmd->channel_opt[0].non_ebs_ratio =
869 cpu_to_le16(IWL_DENSE_EBS_SCAN_RATIO);
870 cmd->channel_opt[1].flags =
871 cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS |
872 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
873 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD);
874 cmd->channel_opt[1].non_ebs_ratio =
875 cpu_to_le16(IWL_SPARSE_EBS_SCAN_RATIO);
876 }
877
Luciano Coelhof7b788b2015-04-02 00:08:35 +0300878 iwl_mvm_lmac_scan_cfg_channels(mvm, params->channels,
879 params->n_channels, ssid_bitmap, cmd);
David Spinadelfb98be52014-05-04 12:51:10 +0300880
Luciano Coelho45d1b122015-04-15 16:34:13 +0300881 *preq = params->preq;
David Spinadelfb98be52014-05-04 12:51:10 +0300882
Luciano Coelho8df3e682015-04-01 17:37:44 +0300883 return 0;
David Spinadelfb98be52014-05-04 12:51:10 +0300884}
885
David Spinadeld2496222014-05-20 12:46:37 +0300886static int rate_to_scan_rate_flag(unsigned int rate)
887{
888 static const int rate_to_scan_rate[IWL_RATE_COUNT] = {
889 [IWL_RATE_1M_INDEX] = SCAN_CONFIG_RATE_1M,
890 [IWL_RATE_2M_INDEX] = SCAN_CONFIG_RATE_2M,
891 [IWL_RATE_5M_INDEX] = SCAN_CONFIG_RATE_5M,
892 [IWL_RATE_11M_INDEX] = SCAN_CONFIG_RATE_11M,
893 [IWL_RATE_6M_INDEX] = SCAN_CONFIG_RATE_6M,
894 [IWL_RATE_9M_INDEX] = SCAN_CONFIG_RATE_9M,
895 [IWL_RATE_12M_INDEX] = SCAN_CONFIG_RATE_12M,
896 [IWL_RATE_18M_INDEX] = SCAN_CONFIG_RATE_18M,
897 [IWL_RATE_24M_INDEX] = SCAN_CONFIG_RATE_24M,
898 [IWL_RATE_36M_INDEX] = SCAN_CONFIG_RATE_36M,
899 [IWL_RATE_48M_INDEX] = SCAN_CONFIG_RATE_48M,
900 [IWL_RATE_54M_INDEX] = SCAN_CONFIG_RATE_54M,
901 };
902
903 return rate_to_scan_rate[rate];
904}
905
906static __le32 iwl_mvm_scan_config_rates(struct iwl_mvm *mvm)
907{
908 struct ieee80211_supported_band *band;
909 unsigned int rates = 0;
910 int i;
911
912 band = &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
913 for (i = 0; i < band->n_bitrates; i++)
914 rates |= rate_to_scan_rate_flag(band->bitrates[i].hw_value);
915 band = &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
916 for (i = 0; i < band->n_bitrates; i++)
917 rates |= rate_to_scan_rate_flag(band->bitrates[i].hw_value);
918
919 /* Set both basic rates and supported rates */
920 rates |= SCAN_CONFIG_SUPPORTED_RATE(rates);
921
922 return cpu_to_le32(rates);
923}
924
925int iwl_mvm_config_scan(struct iwl_mvm *mvm)
926{
927
928 struct iwl_scan_config *scan_config;
929 struct ieee80211_supported_band *band;
930 int num_channels =
931 mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels +
932 mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels;
933 int ret, i, j = 0, cmd_size, data_size;
934 struct iwl_host_cmd cmd = {
935 .id = SCAN_CFG_CMD,
936 };
937
938 if (WARN_ON(num_channels > mvm->fw->ucode_capa.n_scan_channels))
939 return -ENOBUFS;
940
941 cmd_size = sizeof(*scan_config) + mvm->fw->ucode_capa.n_scan_channels;
942
943 scan_config = kzalloc(cmd_size, GFP_KERNEL);
944 if (!scan_config)
945 return -ENOMEM;
946
947 data_size = cmd_size - sizeof(struct iwl_mvm_umac_cmd_hdr);
948 scan_config->hdr.size = cpu_to_le16(data_size);
949 scan_config->flags = cpu_to_le32(SCAN_CONFIG_FLAG_ACTIVATE |
950 SCAN_CONFIG_FLAG_ALLOW_CHUB_REQS |
951 SCAN_CONFIG_FLAG_SET_TX_CHAINS |
952 SCAN_CONFIG_FLAG_SET_RX_CHAINS |
953 SCAN_CONFIG_FLAG_SET_ALL_TIMES |
954 SCAN_CONFIG_FLAG_SET_LEGACY_RATES |
955 SCAN_CONFIG_FLAG_SET_MAC_ADDR |
956 SCAN_CONFIG_FLAG_SET_CHANNEL_FLAGS|
957 SCAN_CONFIG_N_CHANNELS(num_channels));
Moshe Harela0544272014-12-08 21:13:14 +0200958 scan_config->tx_chains = cpu_to_le32(iwl_mvm_get_valid_tx_ant(mvm));
David Spinadeld2496222014-05-20 12:46:37 +0300959 scan_config->rx_chains = cpu_to_le32(iwl_mvm_scan_rx_ant(mvm));
960 scan_config->legacy_rates = iwl_mvm_scan_config_rates(mvm);
961 scan_config->out_of_channel_time = cpu_to_le32(170);
962 scan_config->suspend_time = cpu_to_le32(30);
963 scan_config->dwell_active = 20;
964 scan_config->dwell_passive = 110;
965 scan_config->dwell_fragmented = 20;
966
967 memcpy(&scan_config->mac_addr, &mvm->addresses[0].addr, ETH_ALEN);
968
969 scan_config->bcast_sta_id = mvm->aux_sta.sta_id;
970 scan_config->channel_flags = IWL_CHANNEL_FLAG_EBS |
971 IWL_CHANNEL_FLAG_ACCURATE_EBS |
972 IWL_CHANNEL_FLAG_EBS_ADD |
973 IWL_CHANNEL_FLAG_PRE_SCAN_PASSIVE2ACTIVE;
974
975 band = &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
976 for (i = 0; i < band->n_channels; i++, j++)
Ilan Peera25d40e2015-01-23 21:13:01 +0200977 scan_config->channel_array[j] = band->channels[i].hw_value;
David Spinadeld2496222014-05-20 12:46:37 +0300978 band = &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
979 for (i = 0; i < band->n_channels; i++, j++)
Ilan Peera25d40e2015-01-23 21:13:01 +0200980 scan_config->channel_array[j] = band->channels[i].hw_value;
David Spinadeld2496222014-05-20 12:46:37 +0300981
982 cmd.data[0] = scan_config;
983 cmd.len[0] = cmd_size;
984 cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
985
986 IWL_DEBUG_SCAN(mvm, "Sending UMAC scan config\n");
987
988 ret = iwl_mvm_send_cmd(mvm, &cmd);
989
990 kfree(scan_config);
991 return ret;
992}
993
Luciano Coelho6185af2a2015-05-07 11:13:24 +0300994static int iwl_mvm_scan_uid_by_status(struct iwl_mvm *mvm, int status)
David Spinadeld2496222014-05-20 12:46:37 +0300995{
996 int i;
997
Luciano Coelho507e4cd2015-03-19 22:58:33 +0200998 for (i = 0; i < mvm->max_scans; i++)
Luciano Coelho6185af2a2015-05-07 11:13:24 +0300999 if (mvm->scan_uid_status[i] == status)
David Spinadeld2496222014-05-20 12:46:37 +03001000 return i;
1001
Luciano Coelho6185af2a2015-05-07 11:13:24 +03001002 return -ENOENT;
David Spinadeld2496222014-05-20 12:46:37 +03001003}
1004
Luciano Coelho133c8252015-04-20 15:29:03 +03001005static void iwl_mvm_scan_umac_dwell(struct iwl_mvm *mvm,
David Spinadeld2496222014-05-20 12:46:37 +03001006 struct iwl_scan_req_umac *cmd,
1007 struct iwl_mvm_scan_params *params)
1008{
David Spinadeld2496222014-05-20 12:46:37 +03001009 cmd->active_dwell = params->dwell[IEEE80211_BAND_2GHZ].active;
1010 cmd->passive_dwell = params->dwell[IEEE80211_BAND_2GHZ].passive;
1011 if (params->passive_fragmented)
1012 cmd->fragmented_dwell =
David Spinadel190f1022015-02-17 12:45:21 +02001013 params->dwell[IEEE80211_BAND_2GHZ].fragmented;
David Spinadeld2496222014-05-20 12:46:37 +03001014 cmd->max_out_time = cpu_to_le32(params->max_out_time);
1015 cmd->suspend_time = cpu_to_le32(params->suspend_time);
Avraham Sternd7afbfc2015-05-12 12:19:48 +03001016 cmd->scan_priority =
1017 iwl_mvm_scan_priority(mvm, IWL_SCAN_PRIORITY_EXT_6);
Luciano Coelho133c8252015-04-20 15:29:03 +03001018
1019 if (iwl_mvm_scan_total_iterations(params) == 0)
Avraham Sternd7afbfc2015-05-12 12:19:48 +03001020 cmd->ooc_priority =
1021 iwl_mvm_scan_priority(mvm, IWL_SCAN_PRIORITY_EXT_6);
Luciano Coelho133c8252015-04-20 15:29:03 +03001022 else
Avraham Sternd7afbfc2015-05-12 12:19:48 +03001023 cmd->ooc_priority =
1024 iwl_mvm_scan_priority(mvm, IWL_SCAN_PRIORITY_EXT_2);
David Spinadeld2496222014-05-20 12:46:37 +03001025}
1026
1027static void
1028iwl_mvm_umac_scan_cfg_channels(struct iwl_mvm *mvm,
1029 struct ieee80211_channel **channels,
1030 int n_channels, u32 ssid_bitmap,
1031 struct iwl_scan_req_umac *cmd)
1032{
1033 struct iwl_scan_channel_cfg_umac *channel_cfg = (void *)&cmd->data;
1034 int i;
1035
1036 for (i = 0; i < n_channels; i++) {
1037 channel_cfg[i].flags = cpu_to_le32(ssid_bitmap);
1038 channel_cfg[i].channel_num = channels[i]->hw_value;
1039 channel_cfg[i].iter_count = 1;
1040 channel_cfg[i].iter_interval = 0;
1041 }
1042}
1043
Luciano Coelho6f4dcc72015-04-20 14:37:16 +03001044static u32 iwl_mvm_scan_umac_flags(struct iwl_mvm *mvm,
1045 struct iwl_mvm_scan_params *params)
David Spinadeld2496222014-05-20 12:46:37 +03001046{
1047 int flags = 0;
1048
Luciano Coelho6f4dcc72015-04-20 14:37:16 +03001049 if (params->n_ssids == 0)
David Spinadeld2496222014-05-20 12:46:37 +03001050 flags = IWL_UMAC_SCAN_GEN_FLAGS_PASSIVE;
1051
Luciano Coelho6f4dcc72015-04-20 14:37:16 +03001052 if (params->n_ssids == 1 && params->ssids[0].ssid_len != 0)
David Spinadeld2496222014-05-20 12:46:37 +03001053 flags |= IWL_UMAC_SCAN_GEN_FLAGS_PRE_CONNECT;
1054
Luciano Coelho6f4dcc72015-04-20 14:37:16 +03001055 if (params->passive_fragmented)
David Spinadeld2496222014-05-20 12:46:37 +03001056 flags |= IWL_UMAC_SCAN_GEN_FLAGS_FRAGMENTED;
1057
1058 if (iwl_mvm_rrm_scan_needed(mvm))
1059 flags |= IWL_UMAC_SCAN_GEN_FLAGS_RRM_ENABLED;
1060
Luciano Coelho6f4dcc72015-04-20 14:37:16 +03001061 if (params->pass_all)
1062 flags |= IWL_UMAC_SCAN_GEN_FLAGS_PASS_ALL;
1063 else
1064 flags |= IWL_UMAC_SCAN_GEN_FLAGS_MATCH;
1065
1066 if (iwl_mvm_scan_total_iterations(params) > 1)
1067 flags |= IWL_UMAC_SCAN_GEN_FLAGS_PERIODIC;
1068
Avraham Sternee9219b2015-03-23 15:09:27 +02001069#ifdef CONFIG_IWLWIFI_DEBUGFS
1070 if (mvm->scan_iter_notif_enabled)
1071 flags |= IWL_UMAC_SCAN_GEN_FLAGS_ITER_COMPLETE;
1072#endif
David Spinadeld2496222014-05-20 12:46:37 +03001073 return flags;
1074}
1075
Luciano Coelho6749dd82015-03-20 15:51:36 +02001076static int iwl_mvm_scan_umac(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
Luciano Coelho6185af2a2015-05-07 11:13:24 +03001077 struct iwl_mvm_scan_params *params,
1078 int type)
David Spinadeld2496222014-05-20 12:46:37 +03001079{
David Spinadeld2496222014-05-20 12:46:37 +03001080 struct iwl_scan_req_umac *cmd = mvm->scan_cmd;
1081 struct iwl_scan_req_umac_tail *sec_part = (void *)&cmd->data +
1082 sizeof(struct iwl_scan_channel_cfg_umac) *
1083 mvm->fw->ucode_capa.n_scan_channels;
Luciano Coelho6185af2a2015-05-07 11:13:24 +03001084 int uid;
Johannes Bergc8660dd2014-11-17 15:06:52 +01001085 u32 ssid_bitmap = 0;
Luciano Coelho6f4dcc72015-04-20 14:37:16 +03001086 int n_iterations = iwl_mvm_scan_total_iterations(params);
David Spinadeld2496222014-05-20 12:46:37 +03001087
1088 lockdep_assert_held(&mvm->mutex);
1089
Luciano Coelho6185af2a2015-05-07 11:13:24 +03001090 uid = iwl_mvm_scan_uid_by_status(mvm, 0);
1091 if (uid < 0)
1092 return uid;
David Spinadeld2496222014-05-20 12:46:37 +03001093
Luciano Coelho133c8252015-04-20 15:29:03 +03001094 memset(cmd, 0, ksize(cmd));
1095 cmd->hdr.size = cpu_to_le16(iwl_mvm_scan_size(mvm) -
1096 sizeof(struct iwl_mvm_umac_cmd_hdr));
David Spinadeld2496222014-05-20 12:46:37 +03001097
Luciano Coelho133c8252015-04-20 15:29:03 +03001098 iwl_mvm_scan_umac_dwell(mvm, cmd, params);
1099
Luciano Coelho6185af2a2015-05-07 11:13:24 +03001100 mvm->scan_uid_status[uid] = type;
Luciano Coelho8423cdc2015-04-17 14:49:58 +03001101
Luciano Coelho8423cdc2015-04-17 14:49:58 +03001102 cmd->uid = cpu_to_le32(uid);
Luciano Coelho6f4dcc72015-04-20 14:37:16 +03001103 cmd->general_flags = cpu_to_le32(iwl_mvm_scan_umac_flags(mvm, params));
Haim Dreyfuss4db65582015-01-05 15:00:35 +02001104
Luciano Coelho8423cdc2015-04-17 14:49:58 +03001105 if (iwl_mvm_scan_use_ebs(mvm, n_iterations))
Haim Dreyfuss4db65582015-01-05 15:00:35 +02001106 cmd->channel_flags = IWL_SCAN_CHANNEL_FLAG_EBS |
1107 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
1108 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD;
1109
Luciano Coelhof7b788b2015-04-02 00:08:35 +03001110 cmd->n_channels = params->n_channels;
David Spinadeld2496222014-05-20 12:46:37 +03001111
Luciano Coelhoe2ec4f62015-04-02 17:49:04 +03001112 iwl_scan_build_ssids(params, sec_part->direct_scan, &ssid_bitmap);
David Spinadeld2496222014-05-20 12:46:37 +03001113
Luciano Coelhof7b788b2015-04-02 00:08:35 +03001114 iwl_mvm_umac_scan_cfg_channels(mvm, params->channels,
1115 params->n_channels, ssid_bitmap, cmd);
David Spinadeld2496222014-05-20 12:46:37 +03001116
Luciano Coelhoa54cb642015-05-25 09:36:53 +03001117 /* With UMAC we use only one schedule for now, so use the sum
1118 * of the iterations (with a a maximum of 255).
Luciano Coelho8423cdc2015-04-17 14:49:58 +03001119 */
1120 sec_part->schedule[0].iter_count =
1121 (n_iterations > 255) ? 255 : n_iterations;
Luciano Coelhocf5d3172015-04-16 20:13:28 +03001122 sec_part->schedule[0].interval = cpu_to_le16(params->interval);
1123
Luciano Coelho283c2492015-04-17 11:18:46 +03001124 sec_part->delay = cpu_to_le16(params->delay);
Luciano Coelho45d1b122015-04-15 16:34:13 +03001125 sec_part->preq = params->preq;
David Spinadeld2496222014-05-20 12:46:37 +03001126
Luciano Coelho8df3e682015-04-01 17:37:44 +03001127 return 0;
David Spinadeld2496222014-05-20 12:46:37 +03001128}
1129
Luciano Coelho6749dd82015-03-20 15:51:36 +02001130static int iwl_mvm_num_scans(struct iwl_mvm *mvm)
1131{
1132 return hweight32(mvm->scan_status & IWL_MVM_SCAN_MASK);
1133}
1134
1135static int iwl_mvm_check_running_scans(struct iwl_mvm *mvm, int type)
1136{
1137 /* This looks a bit arbitrary, but the idea is that if we run
1138 * out of possible simultaneous scans and the userspace is
1139 * trying to run a scan type that is already running, we
1140 * return -EBUSY. But if the userspace wants to start a
1141 * different type of scan, we stop the opposite type to make
1142 * space for the new request. The reason is backwards
1143 * compatibility with old wpa_supplicant that wouldn't stop a
1144 * scheduled scan before starting a normal scan.
1145 */
1146
1147 if (iwl_mvm_num_scans(mvm) < mvm->max_scans)
1148 return 0;
1149
1150 /* Use a switch, even though this is a bitmask, so that more
1151 * than one bits set will fall in default and we will warn.
1152 */
1153 switch (type) {
1154 case IWL_MVM_SCAN_REGULAR:
1155 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR_MASK)
1156 return -EBUSY;
Luciano Coelhoc7d42482015-05-07 16:00:26 +03001157 return iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
Luciano Coelho6749dd82015-03-20 15:51:36 +02001158 case IWL_MVM_SCAN_SCHED:
1159 if (mvm->scan_status & IWL_MVM_SCAN_SCHED_MASK)
1160 return -EBUSY;
Luciano Coelhoc7d42482015-05-07 16:00:26 +03001161 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
Luciano Coelho19945df2015-03-20 16:11:28 +02001162 case IWL_MVM_SCAN_NETDETECT:
1163 /* No need to stop anything for net-detect since the
1164 * firmware is restarted anyway. This way, any sched
1165 * scans that were running will be restarted when we
1166 * resume.
1167 */
1168 return 0;
Luciano Coelho6749dd82015-03-20 15:51:36 +02001169 default:
1170 WARN_ON(1);
1171 break;
1172 }
1173
1174 return -EIO;
1175}
1176
1177int iwl_mvm_reg_scan_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1178 struct cfg80211_scan_request *req,
1179 struct ieee80211_scan_ies *ies)
1180{
Luciano Coelho3db7c6e2015-04-01 17:09:56 +03001181 struct iwl_host_cmd hcmd = {
1182 .len = { iwl_mvm_scan_size(mvm), },
1183 .data = { mvm->scan_cmd, },
1184 .dataflags = { IWL_HCMD_DFL_NOCOPY, },
1185 };
1186 struct iwl_mvm_scan_params params = {};
Luciano Coelho6749dd82015-03-20 15:51:36 +02001187 int ret;
1188
1189 lockdep_assert_held(&mvm->mutex);
1190
1191 if (iwl_mvm_is_lar_supported(mvm) && !mvm->lar_regdom_set) {
1192 IWL_ERR(mvm, "scan while LAR regdomain is not set\n");
1193 return -EBUSY;
1194 }
1195
1196 ret = iwl_mvm_check_running_scans(mvm, IWL_MVM_SCAN_REGULAR);
1197 if (ret)
1198 return ret;
1199
1200 iwl_mvm_ref(mvm, IWL_MVM_REF_SCAN);
1201
Luciano Coelho3db7c6e2015-04-01 17:09:56 +03001202 /* we should have failed registration if scan_cmd was NULL */
1203 if (WARN_ON(!mvm->scan_cmd))
1204 return -ENOMEM;
1205
1206 if (!iwl_mvm_scan_fits(mvm, req->n_ssids, ies, req->n_channels))
1207 return -ENOBUFS;
1208
Luciano Coelho4b817052015-04-15 16:21:16 +03001209 params.n_ssids = req->n_ssids;
1210 params.flags = req->flags;
Luciano Coelhof7b788b2015-04-02 00:08:35 +03001211 params.n_channels = req->n_channels;
1212 params.delay = 0;
1213 params.interval = 0;
1214 params.ssids = req->ssids;
1215 params.channels = req->channels;
1216 params.mac_addr = req->mac_addr;
1217 params.mac_addr_mask = req->mac_addr_mask;
1218 params.no_cck = req->no_cck;
1219 params.pass_all = true;
1220 params.n_match_sets = 0;
1221 params.match_sets = NULL;
Luciano Coelho3db7c6e2015-04-01 17:09:56 +03001222
Luciano Coelhocf5d3172015-04-16 20:13:28 +03001223 params.schedule[0].iterations = 1;
1224 params.schedule[0].full_scan_mul = 0;
1225 params.schedule[1].iterations = 0;
1226 params.schedule[1].full_scan_mul = 0;
1227
Luciano Coelho4b817052015-04-15 16:21:16 +03001228 iwl_mvm_scan_calc_dwell(mvm, vif, &params);
1229
Luciano Coelho45d1b122015-04-15 16:34:13 +03001230 iwl_mvm_build_scan_probe(mvm, vif, ies, &params);
1231
Luciano Coelho3db7c6e2015-04-01 17:09:56 +03001232 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN) {
1233 hcmd.id = SCAN_REQ_UMAC;
Luciano Coelho6185af2a2015-05-07 11:13:24 +03001234 ret = iwl_mvm_scan_umac(mvm, vif, &params,
1235 IWL_MVM_SCAN_REGULAR);
Luciano Coelho3db7c6e2015-04-01 17:09:56 +03001236 } else {
1237 hcmd.id = SCAN_OFFLOAD_REQUEST_CMD;
Luciano Coelho45d1b122015-04-15 16:34:13 +03001238 ret = iwl_mvm_scan_lmac(mvm, vif, &params);
Luciano Coelho3db7c6e2015-04-01 17:09:56 +03001239 }
1240
1241 if (ret)
1242 return ret;
1243
1244 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1245 if (!ret) {
1246 IWL_DEBUG_SCAN(mvm, "Scan request was sent successfully\n");
1247 mvm->scan_status |= IWL_MVM_SCAN_REGULAR;
1248 } else {
1249 /* If the scan failed, it usually means that the FW was unable
1250 * to allocate the time events. Warn on it, but maybe we
1251 * should try to send the command again with different params.
1252 */
1253 IWL_ERR(mvm, "Scan failed! ret %d\n", ret);
1254 }
Luciano Coelho6749dd82015-03-20 15:51:36 +02001255
1256 if (ret)
1257 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
1258
1259 return ret;
1260}
1261
Luciano Coelho65ff5562015-03-20 13:35:47 +02001262int iwl_mvm_sched_scan_start(struct iwl_mvm *mvm,
1263 struct ieee80211_vif *vif,
1264 struct cfg80211_sched_scan_request *req,
Luciano Coelho19945df2015-03-20 16:11:28 +02001265 struct ieee80211_scan_ies *ies,
1266 int type)
Luciano Coelho65ff5562015-03-20 13:35:47 +02001267{
Luciano Coelho8df3e682015-04-01 17:37:44 +03001268 struct iwl_host_cmd hcmd = {
1269 .len = { iwl_mvm_scan_size(mvm), },
1270 .data = { mvm->scan_cmd, },
1271 .dataflags = { IWL_HCMD_DFL_NOCOPY, },
1272 };
1273 struct iwl_mvm_scan_params params = {};
Luciano Coelho65ff5562015-03-20 13:35:47 +02001274 int ret;
1275
Luciano Coelho6749dd82015-03-20 15:51:36 +02001276 lockdep_assert_held(&mvm->mutex);
1277
1278 if (iwl_mvm_is_lar_supported(mvm) && !mvm->lar_regdom_set) {
1279 IWL_ERR(mvm, "sched-scan while LAR regdomain is not set\n");
1280 return -EBUSY;
1281 }
1282
Luciano Coelho19945df2015-03-20 16:11:28 +02001283 ret = iwl_mvm_check_running_scans(mvm, type);
Luciano Coelho6749dd82015-03-20 15:51:36 +02001284 if (ret)
1285 return ret;
1286
Luciano Coelho8df3e682015-04-01 17:37:44 +03001287 /* we should have failed registration if scan_cmd was NULL */
1288 if (WARN_ON(!mvm->scan_cmd))
1289 return -ENOMEM;
1290
1291 if (!iwl_mvm_scan_fits(mvm, req->n_ssids, ies, req->n_channels))
1292 return -ENOBUFS;
1293
Luciano Coelho4b817052015-04-15 16:21:16 +03001294 params.n_ssids = req->n_ssids;
1295 params.flags = req->flags;
Luciano Coelhof7b788b2015-04-02 00:08:35 +03001296 params.n_channels = req->n_channels;
Luciano Coelhof7b788b2015-04-02 00:08:35 +03001297 params.ssids = req->ssids;
1298 params.channels = req->channels;
1299 params.mac_addr = req->mac_addr;
1300 params.mac_addr_mask = req->mac_addr_mask;
1301 params.no_cck = false;
1302 params.pass_all = iwl_mvm_scan_pass_all(mvm, req);
1303 params.n_match_sets = req->n_match_sets;
1304 params.match_sets = req->match_sets;
1305
Luciano Coelhocf5d3172015-04-16 20:13:28 +03001306 params.schedule[0].iterations = IWL_FAST_SCHED_SCAN_ITERATIONS;
1307 params.schedule[0].full_scan_mul = 1;
1308 params.schedule[1].iterations = 0xff;
1309 params.schedule[1].full_scan_mul = IWL_FULL_SCAN_MULTIPLIER;
1310
Luciano Coelhof7b788b2015-04-02 00:08:35 +03001311 if (req->interval > U16_MAX) {
1312 IWL_DEBUG_SCAN(mvm,
1313 "interval value is > 16-bits, set to max possible\n");
1314 params.interval = U16_MAX;
1315 } else {
1316 params.interval = req->interval / MSEC_PER_SEC;
1317 }
Luciano Coelho8df3e682015-04-01 17:37:44 +03001318
Luciano Coelho283c2492015-04-17 11:18:46 +03001319 /* In theory, LMAC scans can handle a 32-bit delay, but since
1320 * waiting for over 18 hours to start the scan is a bit silly
1321 * and to keep it aligned with UMAC scans (which only support
1322 * 16-bit delays), trim it down to 16-bits.
1323 */
1324 if (req->delay > U16_MAX) {
1325 IWL_DEBUG_SCAN(mvm,
1326 "delay value is > 16-bits, set to max possible\n");
1327 params.delay = U16_MAX;
1328 } else {
1329 params.delay = req->delay;
1330 }
1331
Luciano Coelho4b817052015-04-15 16:21:16 +03001332 iwl_mvm_scan_calc_dwell(mvm, vif, &params);
1333
Luciano Coelho65ff5562015-03-20 13:35:47 +02001334 ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
1335 if (ret)
1336 return ret;
1337
Luciano Coelho45d1b122015-04-15 16:34:13 +03001338 iwl_mvm_build_scan_probe(mvm, vif, ies, &params);
1339
Luciano Coelho65ff5562015-03-20 13:35:47 +02001340 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN) {
Luciano Coelho8df3e682015-04-01 17:37:44 +03001341 hcmd.id = SCAN_REQ_UMAC;
Luciano Coelho6185af2a2015-05-07 11:13:24 +03001342 ret = iwl_mvm_scan_umac(mvm, vif, &params, IWL_MVM_SCAN_SCHED);
Luciano Coelho65ff5562015-03-20 13:35:47 +02001343 } else {
Luciano Coelho8df3e682015-04-01 17:37:44 +03001344 hcmd.id = SCAN_OFFLOAD_REQUEST_CMD;
Luciano Coelho7d7de1e2015-04-17 09:53:55 +03001345 ret = iwl_mvm_scan_lmac(mvm, vif, &params);
Luciano Coelho8df3e682015-04-01 17:37:44 +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,
1354 "Sched scan request was sent successfully\n");
1355 mvm->scan_status |= type;
1356 } else {
1357 /* If the scan failed, it usually means that the FW was unable
1358 * to allocate the time events. Warn on it, but maybe we
1359 * should try to send the command again with different params.
1360 */
1361 IWL_ERR(mvm, "Sched scan failed! ret %d\n", ret);
Luciano Coelho65ff5562015-03-20 13:35:47 +02001362 }
1363
1364 return ret;
1365}
1366
David Spinadeld2496222014-05-20 12:46:37 +03001367int iwl_mvm_rx_umac_scan_complete_notif(struct iwl_mvm *mvm,
1368 struct iwl_rx_cmd_buffer *rxb,
1369 struct iwl_device_cmd *cmd)
1370{
1371 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1372 struct iwl_umac_scan_complete *notif = (void *)pkt->data;
1373 u32 uid = __le32_to_cpu(notif->uid);
Luciano Coelho8d14ccd2015-05-07 17:05:30 +03001374 bool aborted = (notif->status == IWL_SCAN_OFFLOAD_ABORTED);
David Spinadeld2496222014-05-20 12:46:37 +03001375
Luciano Coelho8d14ccd2015-05-07 17:05:30 +03001376 if (WARN_ON(!(mvm->scan_uid_status[uid] & mvm->scan_status)))
David Spinadeld2496222014-05-20 12:46:37 +03001377 return 0;
1378
Luciano Coelho8d14ccd2015-05-07 17:05:30 +03001379 /* if the scan is already stopping, we don't need to notify mac80211 */
1380 if (mvm->scan_uid_status[uid] == IWL_MVM_SCAN_REGULAR) {
1381 ieee80211_scan_completed(mvm->hw, aborted);
1382 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
1383 } else if (mvm->scan_uid_status[uid] == IWL_MVM_SCAN_SCHED) {
1384 ieee80211_sched_scan_stopped(mvm->hw);
1385 }
1386
1387 mvm->scan_status &= ~mvm->scan_uid_status[uid];
1388
David Spinadeld2496222014-05-20 12:46:37 +03001389 IWL_DEBUG_SCAN(mvm,
Luciano Coelho8d14ccd2015-05-07 17:05:30 +03001390 "Scan completed, uid %u type %u, status %s, EBS status %s\n",
1391 uid, mvm->scan_uid_status[uid],
David Spinadeld2496222014-05-20 12:46:37 +03001392 notif->status == IWL_SCAN_OFFLOAD_COMPLETED ?
1393 "completed" : "aborted",
David Spinadelf0bf8592015-05-20 11:56:59 +03001394 iwl_mvm_ebs_status_str(notif->ebs_status));
David Spinadeld2496222014-05-20 12:46:37 +03001395
David Spinadelf0bf8592015-05-20 11:56:59 +03001396 if (notif->ebs_status != IWL_SCAN_EBS_SUCCESS &&
1397 notif->ebs_status != IWL_SCAN_EBS_INACTIVE)
Haim Dreyfuss5a4b2af2015-01-13 11:54:51 +02001398 mvm->last_ebs_successful = false;
1399
Luciano Coelho6185af2a2015-05-07 11:13:24 +03001400 mvm->scan_uid_status[uid] = 0;
David Spinadeld2496222014-05-20 12:46:37 +03001401
David Spinadeld2496222014-05-20 12:46:37 +03001402 return 0;
1403}
1404
Avraham Sternee9219b2015-03-23 15:09:27 +02001405int iwl_mvm_rx_umac_scan_iter_complete_notif(struct iwl_mvm *mvm,
1406 struct iwl_rx_cmd_buffer *rxb,
1407 struct iwl_device_cmd *cmd)
1408{
1409 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1410 struct iwl_umac_scan_iter_complete_notif *notif = (void *)pkt->data;
1411 u8 buf[256];
1412
1413 IWL_DEBUG_SCAN(mvm,
1414 "UMAC Scan iteration complete: status=0x%x scanned_channels=%d channels list: %s\n",
1415 notif->status, notif->scanned_channels,
1416 iwl_mvm_dump_channel_list(notif->results,
1417 notif->scanned_channels, buf,
1418 sizeof(buf)));
1419 return 0;
1420}
1421
Luciano Coelho434f3c12015-05-07 14:41:44 +03001422static int iwl_mvm_umac_scan_abort(struct iwl_mvm *mvm, int type)
David Spinadeld2496222014-05-20 12:46:37 +03001423{
1424 struct iwl_umac_scan_abort cmd = {
1425 .hdr.size = cpu_to_le16(sizeof(struct iwl_umac_scan_abort) -
1426 sizeof(struct iwl_mvm_umac_cmd_hdr)),
David Spinadeld2496222014-05-20 12:46:37 +03001427 };
Luciano Coelho434f3c12015-05-07 14:41:44 +03001428 int uid, ret;
David Spinadeld2496222014-05-20 12:46:37 +03001429
1430 lockdep_assert_held(&mvm->mutex);
1431
Luciano Coelho434f3c12015-05-07 14:41:44 +03001432 /* We should always get a valid index here, because we already
1433 * checked that this type of scan was running in the generic
1434 * code.
1435 */
1436 uid = iwl_mvm_scan_uid_by_status(mvm, type);
1437 if (WARN_ON_ONCE(uid < 0))
1438 return uid;
1439
1440 cmd.uid = cpu_to_le32(uid);
1441
David Spinadeld2496222014-05-20 12:46:37 +03001442 IWL_DEBUG_SCAN(mvm, "Sending scan abort, uid %u\n", uid);
1443
Luciano Coelho434f3c12015-05-07 14:41:44 +03001444 ret = iwl_mvm_send_cmd_pdu(mvm, SCAN_ABORT_UMAC, 0, sizeof(cmd), &cmd);
1445 if (!ret)
Luciano Coelho8d14ccd2015-05-07 17:05:30 +03001446 mvm->scan_uid_status[uid] = type << IWL_MVM_SCAN_STOPPING_SHIFT;
Luciano Coelho434f3c12015-05-07 14:41:44 +03001447
1448 return ret;
David Spinadeld2496222014-05-20 12:46:37 +03001449}
1450
Luciano Coelhof2461792015-05-07 15:23:19 +03001451static int iwl_mvm_scan_stop_wait(struct iwl_mvm *mvm, int type)
David Spinadeld2496222014-05-20 12:46:37 +03001452{
1453 struct iwl_notification_wait wait_scan_done;
Luciano Coelhof2461792015-05-07 15:23:19 +03001454 static const u8 scan_done_notif[] = { SCAN_COMPLETE_UMAC,
1455 SCAN_OFFLOAD_COMPLETE, };
Luciano Coelho434f3c12015-05-07 14:41:44 +03001456 int ret;
David Spinadeld2496222014-05-20 12:46:37 +03001457
Luciano Coelhof2461792015-05-07 15:23:19 +03001458 lockdep_assert_held(&mvm->mutex);
1459
David Spinadeld2496222014-05-20 12:46:37 +03001460 iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_done,
1461 scan_done_notif,
1462 ARRAY_SIZE(scan_done_notif),
Luciano Coelho434f3c12015-05-07 14:41:44 +03001463 NULL, NULL);
David Spinadeld2496222014-05-20 12:46:37 +03001464
1465 IWL_DEBUG_SCAN(mvm, "Preparing to stop scan, type %x\n", type);
1466
Luciano Coelhof2461792015-05-07 15:23:19 +03001467 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)
1468 ret = iwl_mvm_umac_scan_abort(mvm, type);
1469 else
1470 ret = iwl_mvm_lmac_scan_abort(mvm);
1471
David Spinadeld2496222014-05-20 12:46:37 +03001472 if (ret) {
Luciano Coelho434f3c12015-05-07 14:41:44 +03001473 IWL_DEBUG_SCAN(mvm, "couldn't stop scan type %d\n", type);
David Spinadeld2496222014-05-20 12:46:37 +03001474 iwl_remove_notification(&mvm->notif_wait, &wait_scan_done);
1475 return ret;
1476 }
1477
1478 ret = iwl_wait_notification(&mvm->notif_wait, &wait_scan_done, 1 * HZ);
David Spinadeld2496222014-05-20 12:46:37 +03001479
1480 return ret;
1481}
1482
1483int iwl_mvm_scan_size(struct iwl_mvm *mvm)
1484{
1485 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)
1486 return sizeof(struct iwl_scan_req_umac) +
1487 sizeof(struct iwl_scan_channel_cfg_umac) *
1488 mvm->fw->ucode_capa.n_scan_channels +
1489 sizeof(struct iwl_scan_req_umac_tail);
1490
Luciano Coelho65ff5562015-03-20 13:35:47 +02001491 return sizeof(struct iwl_scan_req_lmac) +
Luciano Coelho1f940382015-02-10 13:03:38 +02001492 sizeof(struct iwl_scan_channel_cfg_lmac) *
1493 mvm->fw->ucode_capa.n_scan_channels +
1494 sizeof(struct iwl_scan_probe_req);
David Spinadeld2496222014-05-20 12:46:37 +03001495}
David Spinadel4ffb3652015-03-10 10:06:02 +02001496
1497/*
1498 * This function is used in nic restart flow, to inform mac80211 about scans
1499 * that was aborted by restart flow or by an assert.
1500 */
1501void iwl_mvm_report_scan_aborted(struct iwl_mvm *mvm)
1502{
1503 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN) {
Luciano Coelho6185af2a2015-05-07 11:13:24 +03001504 int uid, i;
Alexander Bondar963221b2015-03-26 11:07:35 +02001505
Luciano Coelho6185af2a2015-05-07 11:13:24 +03001506 uid = iwl_mvm_scan_uid_by_status(mvm, IWL_MVM_SCAN_REGULAR);
1507 if (uid >= 0) {
David Spinadel4ffb3652015-03-10 10:06:02 +02001508 ieee80211_scan_completed(mvm->hw, true);
Luciano Coelho6185af2a2015-05-07 11:13:24 +03001509 mvm->scan_uid_status[uid] = 0;
Alexander Bondar963221b2015-03-26 11:07:35 +02001510 }
Luciano Coelho6185af2a2015-05-07 11:13:24 +03001511 uid = iwl_mvm_scan_uid_by_status(mvm, IWL_MVM_SCAN_SCHED);
1512 if (uid >= 0 && !mvm->restart_fw) {
David Spinadel4ffb3652015-03-10 10:06:02 +02001513 ieee80211_sched_scan_stopped(mvm->hw);
Luciano Coelho6185af2a2015-05-07 11:13:24 +03001514 mvm->scan_uid_status[uid] = 0;
Alexander Bondar963221b2015-03-26 11:07:35 +02001515 }
1516
1517 /* We shouldn't have any UIDs still set. Loop over all the
1518 * UIDs to make sure there's nothing left there and warn if
1519 * any is found.
1520 */
Luciano Coelho507e4cd2015-03-19 22:58:33 +02001521 for (i = 0; i < mvm->max_scans; i++) {
Luciano Coelho6185af2a2015-05-07 11:13:24 +03001522 if (WARN_ONCE(mvm->scan_uid_status[i],
1523 "UMAC scan UID %d status was not cleaned\n",
1524 i))
1525 mvm->scan_uid_status[i] = 0;
Alexander Bondar963221b2015-03-26 11:07:35 +02001526 }
David Spinadel4ffb3652015-03-10 10:06:02 +02001527 } else {
Luciano Coelho9af91f42015-02-10 10:42:26 +02001528 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
David Spinadel4ffb3652015-03-10 10:06:02 +02001529 ieee80211_scan_completed(mvm->hw, true);
Luciano Coelho9af91f42015-02-10 10:42:26 +02001530
1531 /* Sched scan will be restarted by mac80211 in
1532 * restart_hw, so do not report if FW is about to be
1533 * restarted.
1534 */
1535 if ((mvm->scan_status & IWL_MVM_SCAN_SCHED) && !mvm->restart_fw)
1536 ieee80211_sched_scan_stopped(mvm->hw);
David Spinadel4ffb3652015-03-10 10:06:02 +02001537 }
1538}
Luciano Coelhodfbf1562015-05-05 11:21:34 +03001539
Luciano Coelhoc7d42482015-05-07 16:00:26 +03001540int iwl_mvm_scan_stop(struct iwl_mvm *mvm, int type, bool notify)
Luciano Coelhodfbf1562015-05-05 11:21:34 +03001541{
1542 int ret;
1543
Luciano Coelhoc7d42482015-05-07 16:00:26 +03001544 if (!(mvm->scan_status & type))
Luciano Coelhodfbf1562015-05-05 11:21:34 +03001545 return 0;
1546
1547 if (iwl_mvm_is_radio_killed(mvm)) {
1548 ret = 0;
1549 goto out;
1550 }
1551
Luciano Coelhoc7d42482015-05-07 16:00:26 +03001552 ret = iwl_mvm_scan_stop_wait(mvm, type);
Luciano Coelhodfbf1562015-05-05 11:21:34 +03001553 if (!ret)
Luciano Coelhoc7d42482015-05-07 16:00:26 +03001554 mvm->scan_status |= type << IWL_MVM_SCAN_STOPPING_SHIFT;
Luciano Coelhodfbf1562015-05-05 11:21:34 +03001555out:
1556 /* Clear the scan status so the next scan requests will
1557 * succeed and mark the scan as stopping, so that the Rx
1558 * handler doesn't do anything, as the scan was stopped from
Luciano Coelhoc7d42482015-05-07 16:00:26 +03001559 * above.
Luciano Coelhodfbf1562015-05-05 11:21:34 +03001560 */
Luciano Coelhoc7d42482015-05-07 16:00:26 +03001561 mvm->scan_status &= ~type;
Luciano Coelhodfbf1562015-05-05 11:21:34 +03001562
Luciano Coelhoc7d42482015-05-07 16:00:26 +03001563 if (type == IWL_MVM_SCAN_REGULAR) {
1564 /* Since the rx handler won't do anything now, we have
1565 * to release the scan reference here.
1566 */
1567 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
1568 if (notify)
1569 ieee80211_scan_completed(mvm->hw, true);
1570 } else if (notify) {
Luciano Coelhodfbf1562015-05-05 11:21:34 +03001571 ieee80211_sched_scan_stopped(mvm->hw);
Luciano Coelhoc7d42482015-05-07 16:00:26 +03001572 }
Luciano Coelhodfbf1562015-05-05 11:21:34 +03001573
1574 return ret;
1575}