iwlwifi: mvm: remove deprecated scan API code
[deliverable/linux.git] / drivers / net / wireless / iwlwifi / mvm / scan.c
CommitLineData
8ca151b5
JB
1/******************************************************************************
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 *
51368bf7 8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
8b4139dc 9 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
8ca151b5
JB
10 *
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
410dc5aa 26 * in the file called COPYING.
8ca151b5
JB
27 *
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 *
51368bf7 34 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
8b4139dc 35 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
8ca151b5
JB
36 * 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"
70#include "iwl-eeprom-parse.h"
71#include "fw-api-scan.h"
72
73#define IWL_PLCP_QUIET_THRESH 1
74#define IWL_ACTIVE_QUIET_TIME 10
a1ed4025
HD
75#define IWL_DENSE_EBS_SCAN_RATIO 5
76#define IWL_SPARSE_EBS_SCAN_RATIO 1
8a110d9b
AB
77
78struct iwl_mvm_scan_params {
79 u32 max_out_time;
80 u32 suspend_time;
50df8a30
AB
81 bool passive_fragmented;
82 struct _dwell {
83 u16 passive;
84 u16 active;
85 } dwell[IEEE80211_NUM_BANDS];
8a110d9b 86};
8ca151b5 87
d2496221
DS
88enum iwl_umac_scan_uid_type {
89 IWL_UMAC_SCAN_UID_REG_SCAN = BIT(0),
90 IWL_UMAC_SCAN_UID_SCHED_SCAN = BIT(1),
91 IWL_UMAC_SCAN_UID_ALL = IWL_UMAC_SCAN_UID_REG_SCAN |
92 IWL_UMAC_SCAN_UID_SCHED_SCAN,
93};
94
95static int iwl_umac_scan_stop(struct iwl_mvm *mvm,
96 enum iwl_umac_scan_uid_type type, bool notify);
97
98static u8 iwl_mvm_scan_rx_ant(struct iwl_mvm *mvm)
99{
100 if (mvm->scan_rx_ant != ANT_NONE)
101 return mvm->scan_rx_ant;
a0544272 102 return iwl_mvm_get_valid_rx_ant(mvm);
d2496221
DS
103}
104
8ca151b5
JB
105static inline __le16 iwl_mvm_scan_rx_chain(struct iwl_mvm *mvm)
106{
107 u16 rx_chain;
91b05d10 108 u8 rx_ant;
8ca151b5 109
d2496221 110 rx_ant = iwl_mvm_scan_rx_ant(mvm);
8ca151b5
JB
111 rx_chain = rx_ant << PHY_RX_CHAIN_VALID_POS;
112 rx_chain |= rx_ant << PHY_RX_CHAIN_FORCE_MIMO_SEL_POS;
113 rx_chain |= rx_ant << PHY_RX_CHAIN_FORCE_SEL_POS;
114 rx_chain |= 0x1 << PHY_RX_CHAIN_DRIVER_FORCE_POS;
115 return cpu_to_le16(rx_chain);
116}
117
fb98be5e 118static __le32 iwl_mvm_scan_rxon_flags(enum ieee80211_band band)
8ca151b5 119{
fb98be5e 120 if (band == IEEE80211_BAND_2GHZ)
8ca151b5
JB
121 return cpu_to_le32(PHY_BAND_24);
122 else
123 return cpu_to_le32(PHY_BAND_5);
124}
125
126static inline __le32
127iwl_mvm_scan_rate_n_flags(struct iwl_mvm *mvm, enum ieee80211_band band,
128 bool no_cck)
129{
130 u32 tx_ant;
131
132 mvm->scan_last_antenna_idx =
a0544272 133 iwl_mvm_next_antenna(mvm, iwl_mvm_get_valid_tx_ant(mvm),
8ca151b5
JB
134 mvm->scan_last_antenna_idx);
135 tx_ant = BIT(mvm->scan_last_antenna_idx) << RATE_MCS_ANT_POS;
136
137 if (band == IEEE80211_BAND_2GHZ && !no_cck)
138 return cpu_to_le32(IWL_RATE_1M_PLCP | RATE_MCS_CCK_MSK |
139 tx_ant);
140 else
141 return cpu_to_le32(IWL_RATE_6M_PLCP | tx_ant);
142}
143
144/*
145 * We insert the SSIDs in an inverted order, because the FW will
146 * invert it back. The most prioritized SSID, which is first in the
147 * request list, is not copied here, but inserted directly to the probe
148 * request.
149 */
fb98be5e
DS
150static void iwl_mvm_scan_fill_ssids(struct iwl_ssid_ie *cmd_ssid,
151 struct cfg80211_ssid *ssids,
152 int n_ssids, int first)
8ca151b5
JB
153{
154 int fw_idx, req_idx;
155
fb98be5e 156 for (req_idx = n_ssids - 1, fw_idx = 0; req_idx >= first;
fe04e837 157 req_idx--, fw_idx++) {
fb98be5e
DS
158 cmd_ssid[fw_idx].id = WLAN_EID_SSID;
159 cmd_ssid[fw_idx].len = ssids[req_idx].ssid_len;
160 memcpy(cmd_ssid[fw_idx].ssid,
161 ssids[req_idx].ssid,
162 ssids[req_idx].ssid_len);
8ca151b5
JB
163 }
164}
165
166/*
167 * If req->n_ssids > 0, it means we should do an active scan.
168 * In case of active scan w/o directed scan, we receive a zero-length SSID
169 * just to notify that this scan is active and not passive.
170 * In order to notify the FW of the number of SSIDs we wish to scan (including
171 * the zero-length one), we need to set the corresponding bits in chan->type,
20f1a5de
DS
172 * one for each SSID, and set the active bit (first). If the first SSID is
173 * already included in the probe template, so we need to set only
174 * req->n_ssids - 1 bits in addition to the first bit.
8ca151b5 175 */
3cae0734
DS
176static u16 iwl_mvm_get_active_dwell(struct iwl_mvm *mvm,
177 enum ieee80211_band band, int n_ssids)
8ca151b5 178{
3cae0734
DS
179 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BASIC_DWELL)
180 return 10;
8ca151b5 181 if (band == IEEE80211_BAND_2GHZ)
39745337
DS
182 return 20 + 3 * (n_ssids + 1);
183 return 10 + 2 * (n_ssids + 1);
8ca151b5
JB
184}
185
3cae0734
DS
186static u16 iwl_mvm_get_passive_dwell(struct iwl_mvm *mvm,
187 enum ieee80211_band band)
8ca151b5 188{
3cae0734
DS
189 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_BASIC_DWELL)
190 return 110;
8ca151b5
JB
191 return band == IEEE80211_BAND_2GHZ ? 100 + 20 : 100 + 10;
192}
193
8a110d9b
AB
194static void iwl_mvm_scan_condition_iterator(void *data, u8 *mac,
195 struct ieee80211_vif *vif)
61f6325d 196{
8a110d9b 197 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
c3f8d0a3 198 int *global_cnt = data;
61f6325d 199
1e2ebe0e
DS
200 if (vif->type != NL80211_IFTYPE_P2P_DEVICE && mvmvif->phy_ctxt &&
201 mvmvif->phy_ctxt->id < MAX_PHYS)
c3f8d0a3 202 *global_cnt += 1;
8a110d9b
AB
203}
204
205static void iwl_mvm_scan_calc_params(struct iwl_mvm *mvm,
50df8a30 206 struct ieee80211_vif *vif,
ab480030 207 int n_ssids, u32 flags,
8a110d9b
AB
208 struct iwl_mvm_scan_params *params)
209{
c3f8d0a3 210 int global_cnt = 0;
50df8a30 211 enum ieee80211_band band;
2ce89cd6 212 u8 frag_passive_dwell = 0;
8a110d9b
AB
213
214 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
215 IEEE80211_IFACE_ITER_NORMAL,
216 iwl_mvm_scan_condition_iterator,
c3f8d0a3 217 &global_cnt);
ef67f18d 218
c3f8d0a3 219 if (!global_cnt)
ef67f18d
AB
220 goto not_bound;
221
2ce89cd6 222 params->suspend_time = 30;
44e9cd7e 223 params->max_out_time = 120;
ef67f18d
AB
224
225 if (iwl_mvm_low_latency(mvm)) {
2ce89cd6
DS
226 if (mvm->fw->ucode_capa.api[0] &
227 IWL_UCODE_TLV_API_FRAGMENTED_SCAN) {
228 params->suspend_time = 105;
c3f8d0a3
HD
229 /*
230 * If there is more than one active interface make
231 * passive scan more fragmented.
232 */
233 frag_passive_dwell = (global_cnt < 2) ? 40 : 20;
44e9cd7e 234 params->max_out_time = frag_passive_dwell;
2ce89cd6
DS
235 } else {
236 params->suspend_time = 120;
237 params->max_out_time = 120;
238 }
239 }
240
241 if (frag_passive_dwell && (mvm->fw->ucode_capa.api[0] &
242 IWL_UCODE_TLV_API_FRAGMENTED_SCAN)) {
243 /*
244 * P2P device scan should not be fragmented to avoid negative
245 * impact on P2P device discovery. Configure max_out_time to be
246 * equal to dwell time on passive channel. Take a longest
247 * possible value, one that corresponds to 2GHz band
248 */
249 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
250 u32 passive_dwell =
3cae0734
DS
251 iwl_mvm_get_passive_dwell(mvm,
252 IEEE80211_BAND_2GHZ);
2ce89cd6
DS
253 params->max_out_time = passive_dwell;
254 } else {
255 params->passive_fragmented = true;
256 }
50df8a30 257 }
8a110d9b 258
ab480030
JB
259 if (flags & NL80211_SCAN_FLAG_LOW_PRIORITY)
260 params->max_out_time = 200;
261
ef67f18d
AB
262not_bound:
263
50df8a30 264 for (band = IEEE80211_BAND_2GHZ; band < IEEE80211_NUM_BANDS; band++) {
2ce89cd6
DS
265 if (params->passive_fragmented)
266 params->dwell[band].passive = frag_passive_dwell;
267 else
268 params->dwell[band].passive =
3cae0734
DS
269 iwl_mvm_get_passive_dwell(mvm, band);
270 params->dwell[band].active = iwl_mvm_get_active_dwell(mvm, band,
50df8a30
AB
271 n_ssids);
272 }
61f6325d
HD
273}
274
73897bd1
AO
275static inline bool iwl_mvm_rrm_scan_needed(struct iwl_mvm *mvm)
276{
277 /* require rrm scan whenever the fw supports it */
278 return mvm->fw->ucode_capa.capa[0] &
279 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT;
280}
281
48849a41
AO
282static int iwl_mvm_max_scan_ie_fw_cmd_room(struct iwl_mvm *mvm,
283 bool is_sched_scan)
284{
285 int max_probe_len;
286
1f940386 287 max_probe_len = SCAN_OFFLOAD_PROBE_REQ_SIZE;
48849a41
AO
288
289 /* we create the 802.11 header and SSID element */
290 max_probe_len -= 24 + 2;
291
66dc5272
AO
292 /* DS parameter set element is added on 2.4GHZ band if required */
293 if (iwl_mvm_rrm_scan_needed(mvm))
294 max_probe_len -= 3;
295
48849a41
AO
296 return max_probe_len;
297}
298
299int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm, bool is_sched_scan)
300{
301 int max_ie_len = iwl_mvm_max_scan_ie_fw_cmd_room(mvm, is_sched_scan);
302
48849a41
AO
303 /* TODO: [BUG] This function should return the maximum allowed size of
304 * scan IEs, however the LMAC scan api contains both 2GHZ and 5GHZ IEs
305 * in the same command. So the correct implementation of this function
306 * is just iwl_mvm_max_scan_ie_fw_cmd_room() / 2. Currently the scan
307 * command has only 512 bytes and it would leave us with about 240
308 * bytes for scan IEs, which is clearly not enough. So meanwhile
309 * we will report an incorrect value. This may result in a failure to
310 * issue a scan in unified_scan_lmac and unified_sched_scan_lmac
311 * functions with -ENOBUFS, if a large enough probe will be provided.
312 */
313 return max_ie_len;
314}
315
e5d74646
AB
316int iwl_mvm_rx_scan_offload_iter_complete_notif(struct iwl_mvm *mvm,
317 struct iwl_rx_cmd_buffer *rxb,
318 struct iwl_device_cmd *cmd)
319{
320 struct iwl_rx_packet *pkt = rxb_addr(rxb);
321 struct iwl_scan_complete_notif *notif = (void *)pkt->data;
322
323 IWL_DEBUG_SCAN(mvm,
324 "Scan offload iteration complete: status=0x%x scanned channels=%d\n",
325 notif->status, notif->scanned_channels);
326 return 0;
327}
328
fb98be5e
DS
329int iwl_mvm_rx_scan_offload_results(struct iwl_mvm *mvm,
330 struct iwl_rx_cmd_buffer *rxb,
331 struct iwl_device_cmd *cmd)
35a000b7 332{
d2496221
DS
333 IWL_DEBUG_SCAN(mvm, "Scheduled scan results\n");
334 ieee80211_sched_scan_results(mvm->hw);
35a000b7
DS
335
336 return 0;
337}
338
35a000b7
DS
339int iwl_mvm_rx_scan_offload_complete_notif(struct iwl_mvm *mvm,
340 struct iwl_rx_cmd_buffer *rxb,
341 struct iwl_device_cmd *cmd)
342{
343 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1f940386 344 struct iwl_periodic_scan_complete *scan_notif;
35a000b7 345
1f940386 346 scan_notif = (void *)pkt->data;
fb98be5e 347
a6623e84
JB
348 /* scan status must be locked for proper checking */
349 lockdep_assert_held(&mvm->mutex);
350
e820c2da 351 IWL_DEBUG_SCAN(mvm,
fb98be5e
DS
352 "%s completed, status %s, EBS status %s\n",
353 mvm->scan_status == IWL_MVM_SCAN_SCHED ?
354 "Scheduled scan" : "Scan",
1f940386 355 scan_notif->status == IWL_SCAN_OFFLOAD_COMPLETED ?
fb98be5e 356 "completed" : "aborted",
1f940386 357 scan_notif->ebs_status == IWL_SCAN_EBS_SUCCESS ?
fb98be5e 358 "success" : "failed");
e820c2da 359
35a000b7 360
33ea27f6
AN
361 /* only call mac80211 completion if the stop was initiated by FW */
362 if (mvm->scan_status == IWL_MVM_SCAN_SCHED) {
a6623e84 363 mvm->scan_status = IWL_MVM_SCAN_NONE;
33ea27f6 364 ieee80211_sched_scan_stopped(mvm->hw);
fb98be5e
DS
365 } else if (mvm->scan_status == IWL_MVM_SCAN_OS) {
366 mvm->scan_status = IWL_MVM_SCAN_NONE;
367 ieee80211_scan_completed(mvm->hw,
1f940386 368 scan_notif->status == IWL_SCAN_OFFLOAD_ABORTED);
4ff78181 369 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
33ea27f6 370 }
35a000b7 371
1f940386 372 if (scan_notif->ebs_status)
5a4b2afa 373 mvm->last_ebs_successful = false;
e820c2da 374
35a000b7
DS
375 return 0;
376}
377
35a000b7
DS
378static int iwl_ssid_exist(u8 *ssid, u8 ssid_len, struct iwl_ssid_ie *ssid_list)
379{
380 int i;
381
382 for (i = 0; i < PROBE_OPTION_MAX; i++) {
383 if (!ssid_list[i].len)
384 break;
385 if (ssid_list[i].len == ssid_len &&
386 !memcmp(ssid_list->ssid, ssid, ssid_len))
387 return i;
388 }
389 return -1;
390}
391
392static void iwl_scan_offload_build_ssid(struct cfg80211_sched_scan_request *req,
fb98be5e
DS
393 struct iwl_ssid_ie *direct_scan,
394 u32 *ssid_bitmap, bool basic_ssid)
35a000b7
DS
395{
396 int i, j;
397 int index;
398
399 /*
400 * copy SSIDs from match list.
401 * iwl_config_sched_scan_profiles() uses the order of these ssids to
402 * config match list.
403 */
404 for (i = 0; i < req->n_match_sets && i < PROBE_OPTION_MAX; i++) {
ea73cbce
JB
405 /* skip empty SSID matchsets */
406 if (!req->match_sets[i].ssid.ssid_len)
407 continue;
fb98be5e
DS
408 direct_scan[i].id = WLAN_EID_SSID;
409 direct_scan[i].len = req->match_sets[i].ssid.ssid_len;
410 memcpy(direct_scan[i].ssid, req->match_sets[i].ssid.ssid,
411 direct_scan[i].len);
35a000b7
DS
412 }
413
414 /* add SSIDs from scan SSID list */
415 *ssid_bitmap = 0;
416 for (j = 0; j < req->n_ssids && i < PROBE_OPTION_MAX; j++) {
417 index = iwl_ssid_exist(req->ssids[j].ssid,
418 req->ssids[j].ssid_len,
fb98be5e 419 direct_scan);
35a000b7 420 if (index < 0) {
fb98be5e 421 if (!req->ssids[j].ssid_len && basic_ssid)
35a000b7 422 continue;
fb98be5e
DS
423 direct_scan[i].id = WLAN_EID_SSID;
424 direct_scan[i].len = req->ssids[j].ssid_len;
425 memcpy(direct_scan[i].ssid, req->ssids[j].ssid,
426 direct_scan[i].len);
35a000b7
DS
427 *ssid_bitmap |= BIT(i + 1);
428 i++;
429 } else {
430 *ssid_bitmap |= BIT(index + 1);
431 }
432 }
433}
434
35a000b7
DS
435int iwl_mvm_config_sched_scan_profiles(struct iwl_mvm *mvm,
436 struct cfg80211_sched_scan_request *req)
437{
438 struct iwl_scan_offload_profile *profile;
439 struct iwl_scan_offload_profile_cfg *profile_cfg;
440 struct iwl_scan_offload_blacklist *blacklist;
441 struct iwl_host_cmd cmd = {
442 .id = SCAN_OFFLOAD_UPDATE_PROFILES_CMD,
35a000b7
DS
443 .len[1] = sizeof(*profile_cfg),
444 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
445 .dataflags[1] = IWL_HCMD_DFL_NOCOPY,
446 };
447 int blacklist_len;
448 int i;
449 int ret;
450
451 if (WARN_ON(req->n_match_sets > IWL_SCAN_MAX_PROFILES))
452 return -EIO;
453
454 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_SHORT_BL)
455 blacklist_len = IWL_SCAN_SHORT_BLACKLIST_LEN;
456 else
457 blacklist_len = IWL_SCAN_MAX_BLACKLIST_LEN;
458
459 blacklist = kzalloc(sizeof(*blacklist) * blacklist_len, GFP_KERNEL);
460 if (!blacklist)
461 return -ENOMEM;
462
463 profile_cfg = kzalloc(sizeof(*profile_cfg), GFP_KERNEL);
464 if (!profile_cfg) {
465 ret = -ENOMEM;
466 goto free_blacklist;
467 }
468
469 cmd.data[0] = blacklist;
470 cmd.len[0] = sizeof(*blacklist) * blacklist_len;
471 cmd.data[1] = profile_cfg;
472
473 /* No blacklist configuration */
474
475 profile_cfg->num_profiles = req->n_match_sets;
476 profile_cfg->active_clients = SCAN_CLIENT_SCHED_SCAN;
477 profile_cfg->pass_match = SCAN_CLIENT_SCHED_SCAN;
478 profile_cfg->match_notify = SCAN_CLIENT_SCHED_SCAN;
6e0bbe5e
DS
479 if (!req->n_match_sets || !req->match_sets[0].ssid.ssid_len)
480 profile_cfg->any_beacon_notify = SCAN_CLIENT_SCHED_SCAN;
35a000b7
DS
481
482 for (i = 0; i < req->n_match_sets; i++) {
483 profile = &profile_cfg->profiles[i];
484 profile->ssid_index = i;
485 /* Support any cipher and auth algorithm */
486 profile->unicast_cipher = 0xff;
487 profile->auth_alg = 0xff;
488 profile->network_type = IWL_NETWORK_TYPE_ANY;
489 profile->band_selection = IWL_SCAN_OFFLOAD_SELECT_ANY;
490 profile->client_bitmap = SCAN_CLIENT_SCHED_SCAN;
491 }
492
493 IWL_DEBUG_SCAN(mvm, "Sending scheduled scan profile config\n");
494
495 ret = iwl_mvm_send_cmd(mvm, &cmd);
496 kfree(profile_cfg);
497free_blacklist:
498 kfree(blacklist);
499
500 return ret;
501}
502
d2496221
DS
503static bool iwl_mvm_scan_pass_all(struct iwl_mvm *mvm,
504 struct cfg80211_sched_scan_request *req)
505{
506 if (req->n_match_sets && req->match_sets[0].ssid.ssid_len) {
507 IWL_DEBUG_SCAN(mvm,
508 "Sending scheduled scan with filtering, n_match_sets %d\n",
509 req->n_match_sets);
510 return false;
511 }
512
513 IWL_DEBUG_SCAN(mvm, "Sending Scheduled scan without filtering\n");
514 return true;
515}
516
b141c235
LC
517int iwl_mvm_scan_offload_start(struct iwl_mvm *mvm,
518 struct ieee80211_vif *vif,
519 struct cfg80211_sched_scan_request *req,
520 struct ieee80211_scan_ies *ies)
521{
522 int ret;
523
b975e55a 524 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN) {
b141c235
LC
525 ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
526 if (ret)
527 return ret;
b975e55a 528 ret = iwl_mvm_sched_scan_umac(mvm, vif, req, ies);
b141c235 529 } else {
d2496221 530 mvm->scan_status = IWL_MVM_SCAN_SCHED;
b141c235
LC
531 ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
532 if (ret)
533 return ret;
1f940386 534 ret = iwl_mvm_unified_sched_scan_lmac(mvm, vif, req, ies);
b141c235
LC
535 }
536
537 return ret;
538}
539
fb98be5e 540static int iwl_mvm_send_scan_offload_abort(struct iwl_mvm *mvm)
35a000b7
DS
541{
542 int ret;
543 struct iwl_host_cmd cmd = {
544 .id = SCAN_OFFLOAD_ABORT_CMD,
35a000b7
DS
545 };
546 u32 status;
547
548 /* Exit instantly with error when device is not ready
549 * to receive scan abort command or it does not perform
550 * scheduled scan currently */
1f940386 551 if (mvm->scan_status == IWL_MVM_SCAN_NONE)
35a000b7
DS
552 return -EIO;
553
554 ret = iwl_mvm_send_cmd_status(mvm, &cmd, &status);
555 if (ret)
556 return ret;
557
558 if (status != CAN_ABORT_STATUS) {
559 /*
560 * The scan abort will return 1 for success or
561 * 2 for "failure". A failure condition can be
562 * due to simply not being in an active scan which
563 * can occur if we send the scan abort before the
564 * microcode has notified us that a scan is completed.
565 */
566 IWL_DEBUG_SCAN(mvm, "SCAN OFFLOAD ABORT ret %d.\n", status);
33ea27f6 567 ret = -ENOENT;
35a000b7
DS
568 }
569
570 return ret;
571}
572
fb98be5e 573int iwl_mvm_scan_offload_stop(struct iwl_mvm *mvm, bool notify)
35a000b7
DS
574{
575 int ret;
33ea27f6
AN
576 struct iwl_notification_wait wait_scan_done;
577 static const u8 scan_done_notif[] = { SCAN_OFFLOAD_COMPLETE, };
fb98be5e 578 bool sched = mvm->scan_status == IWL_MVM_SCAN_SCHED;
35a000b7
DS
579
580 lockdep_assert_held(&mvm->mutex);
581
d2496221
DS
582 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)
583 return iwl_umac_scan_stop(mvm, IWL_UMAC_SCAN_UID_SCHED_SCAN,
584 notify);
585
90ea15c1
EG
586 if (mvm->scan_status == IWL_MVM_SCAN_NONE)
587 return 0;
588
589 if (iwl_mvm_is_radio_killed(mvm))
590 goto out;
591
33ea27f6
AN
592 iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_done,
593 scan_done_notif,
594 ARRAY_SIZE(scan_done_notif),
595 NULL, NULL);
596
fb98be5e 597 ret = iwl_mvm_send_scan_offload_abort(mvm);
33ea27f6 598 if (ret) {
fb98be5e
DS
599 IWL_DEBUG_SCAN(mvm, "Send stop %sscan failed %d\n",
600 sched ? "offloaded " : "", ret);
33ea27f6
AN
601 iwl_remove_notification(&mvm->notif_wait, &wait_scan_done);
602 return ret;
603 }
604
fb98be5e
DS
605 IWL_DEBUG_SCAN(mvm, "Successfully sent stop %sscan\n",
606 sched ? "offloaded " : "");
33ea27f6
AN
607
608 ret = iwl_wait_notification(&mvm->notif_wait, &wait_scan_done, 1 * HZ);
609 if (ret)
610 return ret;
611
612 /*
613 * Clear the scan status so the next scan requests will succeed. This
614 * also ensures the Rx handler doesn't do anything, as the scan was
4ff78181
EP
615 * stopped from above. Since the rx handler won't do anything now,
616 * we have to release the scan reference here.
33ea27f6 617 */
4ff78181
EP
618 if (mvm->scan_status == IWL_MVM_SCAN_OS)
619 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
620
90ea15c1 621out:
33ea27f6
AN
622 mvm->scan_status = IWL_MVM_SCAN_NONE;
623
fb98be5e
DS
624 if (notify) {
625 if (sched)
626 ieee80211_sched_scan_stopped(mvm->hw);
627 else
628 ieee80211_scan_completed(mvm->hw, true);
629 }
636a2cdc 630
33ea27f6 631 return 0;
35a000b7 632}
fb98be5e
DS
633
634static void iwl_mvm_unified_scan_fill_tx_cmd(struct iwl_mvm *mvm,
635 struct iwl_scan_req_tx_cmd *tx_cmd,
636 bool no_cck)
637{
638 tx_cmd[0].tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL |
639 TX_CMD_FLG_BT_DIS);
640 tx_cmd[0].rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm,
641 IEEE80211_BAND_2GHZ,
642 no_cck);
643 tx_cmd[0].sta_id = mvm->aux_sta.sta_id;
644
645 tx_cmd[1].tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL |
646 TX_CMD_FLG_BT_DIS);
647 tx_cmd[1].rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm,
648 IEEE80211_BAND_5GHZ,
649 no_cck);
650 tx_cmd[1].sta_id = mvm->aux_sta.sta_id;
651}
652
653static void
654iwl_mvm_lmac_scan_cfg_channels(struct iwl_mvm *mvm,
655 struct ieee80211_channel **channels,
656 int n_channels, u32 ssid_bitmap,
657 struct iwl_scan_req_unified_lmac *cmd)
658{
659 struct iwl_scan_channel_cfg_lmac *channel_cfg = (void *)&cmd->data;
660 int i;
661
662 for (i = 0; i < n_channels; i++) {
663 channel_cfg[i].channel_num =
664 cpu_to_le16(channels[i]->hw_value);
665 channel_cfg[i].iter_count = cpu_to_le16(1);
666 channel_cfg[i].iter_interval = 0;
667 channel_cfg[i].flags =
668 cpu_to_le32(IWL_UNIFIED_SCAN_CHANNEL_PARTIAL |
669 ssid_bitmap);
670 }
671}
672
66dc5272
AO
673static u8 *iwl_mvm_copy_and_insert_ds_elem(struct iwl_mvm *mvm, const u8 *ies,
674 size_t len, u8 *const pos)
675{
676 static const u8 before_ds_params[] = {
677 WLAN_EID_SSID,
678 WLAN_EID_SUPP_RATES,
679 WLAN_EID_REQUEST,
680 WLAN_EID_EXT_SUPP_RATES,
681 };
682 size_t offs;
683 u8 *newpos = pos;
684
685 if (!iwl_mvm_rrm_scan_needed(mvm)) {
686 memcpy(newpos, ies, len);
687 return newpos + len;
688 }
689
690 offs = ieee80211_ie_split(ies, len,
691 before_ds_params,
692 ARRAY_SIZE(before_ds_params),
693 0);
694
695 memcpy(newpos, ies, offs);
696 newpos += offs;
697
698 /* Add a placeholder for DS Parameter Set element */
699 *newpos++ = WLAN_EID_DS_PARAMS;
700 *newpos++ = 1;
701 *newpos++ = 0;
702
703 memcpy(newpos, ies + offs, len - offs);
704 newpos += len - offs;
705
706 return newpos;
707}
708
fb98be5e
DS
709static void
710iwl_mvm_build_unified_scan_probe(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
711 struct ieee80211_scan_ies *ies,
effd05ac
JB
712 struct iwl_scan_probe_req *preq,
713 const u8 *mac_addr, const u8 *mac_addr_mask)
fb98be5e 714{
fb98be5e 715 struct ieee80211_mgmt *frame = (struct ieee80211_mgmt *)preq->buf;
66dc5272 716 u8 *pos, *newpos;
fb98be5e 717
effd05ac
JB
718 /*
719 * Unfortunately, right now the offload scan doesn't support randomising
720 * within the firmware, so until the firmware API is ready we implement
721 * it in the driver. This means that the scan iterations won't really be
722 * random, only when it's restarted, but at least that helps a bit.
723 */
724 if (mac_addr)
725 get_random_mask_addr(frame->sa, mac_addr, mac_addr_mask);
726 else
727 memcpy(frame->sa, vif->addr, ETH_ALEN);
728
fb98be5e
DS
729 frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
730 eth_broadcast_addr(frame->da);
fb98be5e
DS
731 eth_broadcast_addr(frame->bssid);
732 frame->seq_ctrl = 0;
733
734 pos = frame->u.probe_req.variable;
735 *pos++ = WLAN_EID_SSID;
736 *pos++ = 0;
737
738 preq->mac_header.offset = 0;
739 preq->mac_header.len = cpu_to_le16(24 + 2);
740
66dc5272
AO
741 /* Insert ds parameter set element on 2.4 GHz band */
742 newpos = iwl_mvm_copy_and_insert_ds_elem(mvm,
743 ies->ies[IEEE80211_BAND_2GHZ],
744 ies->len[IEEE80211_BAND_2GHZ],
745 pos);
fb98be5e 746 preq->band_data[0].offset = cpu_to_le16(pos - preq->buf);
66dc5272
AO
747 preq->band_data[0].len = cpu_to_le16(newpos - pos);
748 pos = newpos;
fb98be5e
DS
749
750 memcpy(pos, ies->ies[IEEE80211_BAND_5GHZ],
751 ies->len[IEEE80211_BAND_5GHZ]);
752 preq->band_data[1].offset = cpu_to_le16(pos - preq->buf);
753 preq->band_data[1].len = cpu_to_le16(ies->len[IEEE80211_BAND_5GHZ]);
754 pos += ies->len[IEEE80211_BAND_5GHZ];
755
756 memcpy(pos, ies->common_ies, ies->common_ie_len);
757 preq->common_data.offset = cpu_to_le16(pos - preq->buf);
758 preq->common_data.len = cpu_to_le16(ies->common_ie_len);
759}
760
761static void
762iwl_mvm_build_generic_unified_scan_cmd(struct iwl_mvm *mvm,
763 struct iwl_scan_req_unified_lmac *cmd,
764 struct iwl_mvm_scan_params *params)
765{
af91344c 766 memset(cmd, 0, ksize(cmd));
2ce89cd6
DS
767 cmd->active_dwell = params->dwell[IEEE80211_BAND_2GHZ].active;
768 cmd->passive_dwell = params->dwell[IEEE80211_BAND_2GHZ].passive;
769 if (params->passive_fragmented)
770 cmd->fragmented_dwell =
771 params->dwell[IEEE80211_BAND_2GHZ].passive;
fb98be5e
DS
772 cmd->rx_chain_select = iwl_mvm_scan_rx_chain(mvm);
773 cmd->max_out_time = cpu_to_le32(params->max_out_time);
774 cmd->suspend_time = cpu_to_le32(params->suspend_time);
775 cmd->scan_prio = cpu_to_le32(IWL_SCAN_PRIORITY_HIGH);
fb98be5e 776 cmd->iter_num = cpu_to_le32(1);
af91344c 777
73897bd1
AO
778 if (iwl_mvm_rrm_scan_needed(mvm))
779 cmd->scan_flags |=
780 cpu_to_le32(IWL_MVM_LMAC_SCAN_FLAGS_RRM_ENABLED);
fb98be5e
DS
781}
782
783int iwl_mvm_unified_scan_lmac(struct iwl_mvm *mvm,
784 struct ieee80211_vif *vif,
785 struct ieee80211_scan_request *req)
786{
787 struct iwl_host_cmd hcmd = {
788 .id = SCAN_OFFLOAD_REQUEST_CMD,
789 .len = { sizeof(struct iwl_scan_req_unified_lmac) +
790 sizeof(struct iwl_scan_channel_cfg_lmac) *
791 mvm->fw->ucode_capa.n_scan_channels +
792 sizeof(struct iwl_scan_probe_req), },
793 .data = { mvm->scan_cmd, },
794 .dataflags = { IWL_HCMD_DFL_NOCOPY, },
795 };
796 struct iwl_scan_req_unified_lmac *cmd = mvm->scan_cmd;
d2496221 797 struct iwl_scan_probe_req *preq;
fb98be5e
DS
798 struct iwl_mvm_scan_params params = {};
799 u32 flags;
c8660dd5 800 u32 ssid_bitmap = 0;
fb98be5e
DS
801 int ret, i;
802
803 lockdep_assert_held(&mvm->mutex);
804
805 /* we should have failed registration if scan_cmd was NULL */
806 if (WARN_ON(mvm->scan_cmd == NULL))
807 return -ENOMEM;
808
48849a41
AO
809 if (req->req.n_ssids > PROBE_OPTION_MAX ||
810 req->ies.common_ie_len + req->ies.len[NL80211_BAND_2GHZ] +
811 req->ies.len[NL80211_BAND_5GHZ] >
812 iwl_mvm_max_scan_ie_fw_cmd_room(mvm, false) ||
813 req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
814 return -ENOBUFS;
fb98be5e
DS
815
816 mvm->scan_status = IWL_MVM_SCAN_OS;
817
818 iwl_mvm_scan_calc_params(mvm, vif, req->req.n_ssids, req->req.flags,
819 &params);
820
821 iwl_mvm_build_generic_unified_scan_cmd(mvm, cmd, &params);
822
823 cmd->n_channels = (u8)req->req.n_channels;
824
825 flags = IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL;
826
827 if (req->req.n_ssids == 1 && req->req.ssids[0].ssid_len != 0)
828 flags |= IWL_MVM_LMAC_SCAN_FLAG_PRE_CONNECTION;
829
830 if (params.passive_fragmented)
831 flags |= IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED;
832
833 if (req->req.n_ssids == 0)
834 flags |= IWL_MVM_LMAC_SCAN_FLAG_PASSIVE;
835
73897bd1 836 cmd->scan_flags |= cpu_to_le32(flags);
fb98be5e
DS
837
838 cmd->flags = iwl_mvm_scan_rxon_flags(req->req.channels[0]->band);
839 cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP |
840 MAC_FILTER_IN_BEACON);
841 iwl_mvm_unified_scan_fill_tx_cmd(mvm, cmd->tx_cmd, req->req.no_cck);
842 iwl_mvm_scan_fill_ssids(cmd->direct_scan, req->req.ssids,
843 req->req.n_ssids, 0);
844
845 cmd->schedule[0].delay = 0;
846 cmd->schedule[0].iterations = 1;
847 cmd->schedule[0].full_scan_mul = 0;
848 cmd->schedule[1].delay = 0;
849 cmd->schedule[1].iterations = 0;
850 cmd->schedule[1].full_scan_mul = 0;
851
1f9c418f
DS
852 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_SINGLE_SCAN_EBS &&
853 mvm->last_ebs_successful) {
854 cmd->channel_opt[0].flags =
855 cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS |
856 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
857 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD);
858 cmd->channel_opt[0].non_ebs_ratio =
859 cpu_to_le16(IWL_DENSE_EBS_SCAN_RATIO);
860 cmd->channel_opt[1].flags =
861 cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS |
862 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
863 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD);
864 cmd->channel_opt[1].non_ebs_ratio =
865 cpu_to_le16(IWL_SPARSE_EBS_SCAN_RATIO);
866 }
867
fb98be5e
DS
868 for (i = 1; i <= req->req.n_ssids; i++)
869 ssid_bitmap |= BIT(i);
870
871 iwl_mvm_lmac_scan_cfg_channels(mvm, req->req.channels,
872 req->req.n_channels, ssid_bitmap,
873 cmd);
874
d2496221
DS
875 preq = (void *)(cmd->data + sizeof(struct iwl_scan_channel_cfg_lmac) *
876 mvm->fw->ucode_capa.n_scan_channels);
877
effd05ac
JB
878 iwl_mvm_build_unified_scan_probe(mvm, vif, &req->ies, preq,
879 req->req.flags & NL80211_SCAN_FLAG_RANDOM_ADDR ?
880 req->req.mac_addr : NULL,
881 req->req.mac_addr_mask);
fb98be5e
DS
882
883 ret = iwl_mvm_send_cmd(mvm, &hcmd);
884 if (!ret) {
885 IWL_DEBUG_SCAN(mvm, "Scan request was sent successfully\n");
886 } else {
887 /*
888 * If the scan failed, it usually means that the FW was unable
889 * to allocate the time events. Warn on it, but maybe we
890 * should try to send the command again with different params.
891 */
892 IWL_ERR(mvm, "Scan failed! ret %d\n", ret);
893 mvm->scan_status = IWL_MVM_SCAN_NONE;
894 ret = -EIO;
895 }
896 return ret;
897}
898
899int iwl_mvm_unified_sched_scan_lmac(struct iwl_mvm *mvm,
900 struct ieee80211_vif *vif,
901 struct cfg80211_sched_scan_request *req,
902 struct ieee80211_scan_ies *ies)
903{
904 struct iwl_host_cmd hcmd = {
905 .id = SCAN_OFFLOAD_REQUEST_CMD,
906 .len = { sizeof(struct iwl_scan_req_unified_lmac) +
907 sizeof(struct iwl_scan_channel_cfg_lmac) *
908 mvm->fw->ucode_capa.n_scan_channels +
909 sizeof(struct iwl_scan_probe_req), },
910 .data = { mvm->scan_cmd, },
911 .dataflags = { IWL_HCMD_DFL_NOCOPY, },
912 };
913 struct iwl_scan_req_unified_lmac *cmd = mvm->scan_cmd;
d2496221 914 struct iwl_scan_probe_req *preq;
fb98be5e
DS
915 struct iwl_mvm_scan_params params = {};
916 int ret;
917 u32 flags = 0, ssid_bitmap = 0;
918
919 lockdep_assert_held(&mvm->mutex);
920
921 /* we should have failed registration if scan_cmd was NULL */
922 if (WARN_ON(mvm->scan_cmd == NULL))
923 return -ENOMEM;
924
48849a41
AO
925 if (req->n_ssids > PROBE_OPTION_MAX ||
926 ies->common_ie_len + ies->len[NL80211_BAND_2GHZ] +
927 ies->len[NL80211_BAND_5GHZ] >
928 iwl_mvm_max_scan_ie_fw_cmd_room(mvm, true) ||
929 req->n_channels > mvm->fw->ucode_capa.n_scan_channels)
fb98be5e
DS
930 return -ENOBUFS;
931
932 iwl_mvm_scan_calc_params(mvm, vif, req->n_ssids, 0, &params);
933
934 iwl_mvm_build_generic_unified_scan_cmd(mvm, cmd, &params);
935
936 cmd->n_channels = (u8)req->n_channels;
937
d2496221 938 if (iwl_mvm_scan_pass_all(mvm, req))
fb98be5e 939 flags |= IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL;
7e2a3883
DS
940 else
941 flags |= IWL_MVM_LMAC_SCAN_FLAG_MATCH;
fb98be5e
DS
942
943 if (req->n_ssids == 1 && req->ssids[0].ssid_len != 0)
944 flags |= IWL_MVM_LMAC_SCAN_FLAG_PRE_CONNECTION;
945
946 if (params.passive_fragmented)
947 flags |= IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED;
948
949 if (req->n_ssids == 0)
950 flags |= IWL_MVM_LMAC_SCAN_FLAG_PASSIVE;
951
e5d74646
AB
952#ifdef CONFIG_IWLWIFI_DEBUGFS
953 if (mvm->scan_iter_notif_enabled)
954 flags |= IWL_MVM_LMAC_SCAN_FLAG_ITER_COMPLETE;
955#endif
956
73897bd1 957 cmd->scan_flags |= cpu_to_le32(flags);
fb98be5e
DS
958
959 cmd->flags = iwl_mvm_scan_rxon_flags(req->channels[0]->band);
960 cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP |
961 MAC_FILTER_IN_BEACON);
962 iwl_mvm_unified_scan_fill_tx_cmd(mvm, cmd->tx_cmd, false);
963 iwl_scan_offload_build_ssid(req, cmd->direct_scan, &ssid_bitmap, false);
964
b14fc2be 965 cmd->schedule[0].delay = cpu_to_le16(req->interval / MSEC_PER_SEC);
fb98be5e
DS
966 cmd->schedule[0].iterations = IWL_FAST_SCHED_SCAN_ITERATIONS;
967 cmd->schedule[0].full_scan_mul = 1;
968
b14fc2be 969 cmd->schedule[1].delay = cpu_to_le16(req->interval / MSEC_PER_SEC);
fb98be5e
DS
970 cmd->schedule[1].iterations = 0xff;
971 cmd->schedule[1].full_scan_mul = IWL_FULL_SCAN_MULTIPLIER;
972
1f9c418f
DS
973 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_EBS_SUPPORT &&
974 mvm->last_ebs_successful) {
975 cmd->channel_opt[0].flags =
976 cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS |
977 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
978 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD);
979 cmd->channel_opt[0].non_ebs_ratio =
980 cpu_to_le16(IWL_DENSE_EBS_SCAN_RATIO);
981 cmd->channel_opt[1].flags =
982 cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS |
983 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
984 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD);
985 cmd->channel_opt[1].non_ebs_ratio =
986 cpu_to_le16(IWL_SPARSE_EBS_SCAN_RATIO);
987 }
988
fb98be5e
DS
989 iwl_mvm_lmac_scan_cfg_channels(mvm, req->channels, req->n_channels,
990 ssid_bitmap, cmd);
991
d2496221
DS
992 preq = (void *)(cmd->data + sizeof(struct iwl_scan_channel_cfg_lmac) *
993 mvm->fw->ucode_capa.n_scan_channels);
994
effd05ac
JB
995 iwl_mvm_build_unified_scan_probe(mvm, vif, ies, preq,
996 req->flags & NL80211_SCAN_FLAG_RANDOM_ADDR ?
997 req->mac_addr : NULL,
998 req->mac_addr_mask);
fb98be5e
DS
999
1000 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1001 if (!ret) {
1002 IWL_DEBUG_SCAN(mvm,
1003 "Sched scan request was sent successfully\n");
1004 } else {
1005 /*
1006 * If the scan failed, it usually means that the FW was unable
1007 * to allocate the time events. Warn on it, but maybe we
1008 * should try to send the command again with different params.
1009 */
1010 IWL_ERR(mvm, "Sched scan failed! ret %d\n", ret);
1011 mvm->scan_status = IWL_MVM_SCAN_NONE;
1012 ret = -EIO;
1013 }
1014 return ret;
1015}
1016
1017
1018int iwl_mvm_cancel_scan(struct iwl_mvm *mvm)
1019{
d2496221
DS
1020 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)
1021 return iwl_umac_scan_stop(mvm, IWL_UMAC_SCAN_UID_REG_SCAN,
1022 true);
1023
9b520d84
EG
1024 if (mvm->scan_status == IWL_MVM_SCAN_NONE)
1025 return 0;
1026
1027 if (iwl_mvm_is_radio_killed(mvm)) {
1028 ieee80211_scan_completed(mvm->hw, true);
1029 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
1030 mvm->scan_status = IWL_MVM_SCAN_NONE;
1031 return 0;
1032 }
1033
1f940386 1034 return iwl_mvm_scan_offload_stop(mvm, true);
fb98be5e 1035}
d2496221
DS
1036
1037/* UMAC scan API */
1038
1039struct iwl_umac_scan_done {
1040 struct iwl_mvm *mvm;
1041 enum iwl_umac_scan_uid_type type;
1042};
1043
1044static int rate_to_scan_rate_flag(unsigned int rate)
1045{
1046 static const int rate_to_scan_rate[IWL_RATE_COUNT] = {
1047 [IWL_RATE_1M_INDEX] = SCAN_CONFIG_RATE_1M,
1048 [IWL_RATE_2M_INDEX] = SCAN_CONFIG_RATE_2M,
1049 [IWL_RATE_5M_INDEX] = SCAN_CONFIG_RATE_5M,
1050 [IWL_RATE_11M_INDEX] = SCAN_CONFIG_RATE_11M,
1051 [IWL_RATE_6M_INDEX] = SCAN_CONFIG_RATE_6M,
1052 [IWL_RATE_9M_INDEX] = SCAN_CONFIG_RATE_9M,
1053 [IWL_RATE_12M_INDEX] = SCAN_CONFIG_RATE_12M,
1054 [IWL_RATE_18M_INDEX] = SCAN_CONFIG_RATE_18M,
1055 [IWL_RATE_24M_INDEX] = SCAN_CONFIG_RATE_24M,
1056 [IWL_RATE_36M_INDEX] = SCAN_CONFIG_RATE_36M,
1057 [IWL_RATE_48M_INDEX] = SCAN_CONFIG_RATE_48M,
1058 [IWL_RATE_54M_INDEX] = SCAN_CONFIG_RATE_54M,
1059 };
1060
1061 return rate_to_scan_rate[rate];
1062}
1063
1064static __le32 iwl_mvm_scan_config_rates(struct iwl_mvm *mvm)
1065{
1066 struct ieee80211_supported_band *band;
1067 unsigned int rates = 0;
1068 int i;
1069
1070 band = &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
1071 for (i = 0; i < band->n_bitrates; i++)
1072 rates |= rate_to_scan_rate_flag(band->bitrates[i].hw_value);
1073 band = &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
1074 for (i = 0; i < band->n_bitrates; i++)
1075 rates |= rate_to_scan_rate_flag(band->bitrates[i].hw_value);
1076
1077 /* Set both basic rates and supported rates */
1078 rates |= SCAN_CONFIG_SUPPORTED_RATE(rates);
1079
1080 return cpu_to_le32(rates);
1081}
1082
1083int iwl_mvm_config_scan(struct iwl_mvm *mvm)
1084{
1085
1086 struct iwl_scan_config *scan_config;
1087 struct ieee80211_supported_band *band;
1088 int num_channels =
1089 mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels +
1090 mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels;
1091 int ret, i, j = 0, cmd_size, data_size;
1092 struct iwl_host_cmd cmd = {
1093 .id = SCAN_CFG_CMD,
1094 };
1095
1096 if (WARN_ON(num_channels > mvm->fw->ucode_capa.n_scan_channels))
1097 return -ENOBUFS;
1098
1099 cmd_size = sizeof(*scan_config) + mvm->fw->ucode_capa.n_scan_channels;
1100
1101 scan_config = kzalloc(cmd_size, GFP_KERNEL);
1102 if (!scan_config)
1103 return -ENOMEM;
1104
1105 data_size = cmd_size - sizeof(struct iwl_mvm_umac_cmd_hdr);
1106 scan_config->hdr.size = cpu_to_le16(data_size);
1107 scan_config->flags = cpu_to_le32(SCAN_CONFIG_FLAG_ACTIVATE |
1108 SCAN_CONFIG_FLAG_ALLOW_CHUB_REQS |
1109 SCAN_CONFIG_FLAG_SET_TX_CHAINS |
1110 SCAN_CONFIG_FLAG_SET_RX_CHAINS |
1111 SCAN_CONFIG_FLAG_SET_ALL_TIMES |
1112 SCAN_CONFIG_FLAG_SET_LEGACY_RATES |
1113 SCAN_CONFIG_FLAG_SET_MAC_ADDR |
1114 SCAN_CONFIG_FLAG_SET_CHANNEL_FLAGS|
1115 SCAN_CONFIG_N_CHANNELS(num_channels));
a0544272 1116 scan_config->tx_chains = cpu_to_le32(iwl_mvm_get_valid_tx_ant(mvm));
d2496221
DS
1117 scan_config->rx_chains = cpu_to_le32(iwl_mvm_scan_rx_ant(mvm));
1118 scan_config->legacy_rates = iwl_mvm_scan_config_rates(mvm);
1119 scan_config->out_of_channel_time = cpu_to_le32(170);
1120 scan_config->suspend_time = cpu_to_le32(30);
1121 scan_config->dwell_active = 20;
1122 scan_config->dwell_passive = 110;
1123 scan_config->dwell_fragmented = 20;
1124
1125 memcpy(&scan_config->mac_addr, &mvm->addresses[0].addr, ETH_ALEN);
1126
1127 scan_config->bcast_sta_id = mvm->aux_sta.sta_id;
1128 scan_config->channel_flags = IWL_CHANNEL_FLAG_EBS |
1129 IWL_CHANNEL_FLAG_ACCURATE_EBS |
1130 IWL_CHANNEL_FLAG_EBS_ADD |
1131 IWL_CHANNEL_FLAG_PRE_SCAN_PASSIVE2ACTIVE;
1132
1133 band = &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
1134 for (i = 0; i < band->n_channels; i++, j++)
a25d40e2 1135 scan_config->channel_array[j] = band->channels[i].hw_value;
d2496221
DS
1136 band = &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
1137 for (i = 0; i < band->n_channels; i++, j++)
a25d40e2 1138 scan_config->channel_array[j] = band->channels[i].hw_value;
d2496221
DS
1139
1140 cmd.data[0] = scan_config;
1141 cmd.len[0] = cmd_size;
1142 cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
1143
1144 IWL_DEBUG_SCAN(mvm, "Sending UMAC scan config\n");
1145
1146 ret = iwl_mvm_send_cmd(mvm, &cmd);
1147
1148 kfree(scan_config);
1149 return ret;
1150}
1151
1152static int iwl_mvm_find_scan_uid(struct iwl_mvm *mvm, u32 uid)
1153{
1154 int i;
1155
1156 for (i = 0; i < IWL_MVM_MAX_SIMULTANEOUS_SCANS; i++)
1157 if (mvm->scan_uid[i] == uid)
1158 return i;
1159
1160 return i;
1161}
1162
1163static int iwl_mvm_find_free_scan_uid(struct iwl_mvm *mvm)
1164{
1165 return iwl_mvm_find_scan_uid(mvm, 0);
1166}
1167
1168static bool iwl_mvm_find_scan_type(struct iwl_mvm *mvm,
1169 enum iwl_umac_scan_uid_type type)
1170{
1171 int i;
1172
1173 for (i = 0; i < IWL_MVM_MAX_SIMULTANEOUS_SCANS; i++)
1174 if (mvm->scan_uid[i] & type)
1175 return true;
1176
1177 return false;
1178}
1179
1180static u32 iwl_generate_scan_uid(struct iwl_mvm *mvm,
1181 enum iwl_umac_scan_uid_type type)
1182{
1183 u32 uid;
1184
1185 /* make sure exactly one bit is on in scan type */
1186 WARN_ON(hweight8(type) != 1);
1187
1188 /*
1189 * Make sure scan uids are unique. If one scan lasts long time while
1190 * others are completing frequently, the seq number will wrap up and
1191 * we may have more than one scan with the same uid.
1192 */
1193 do {
1194 uid = type | (mvm->scan_seq_num <<
1195 IWL_UMAC_SCAN_UID_SEQ_OFFSET);
1196 mvm->scan_seq_num++;
1197 } while (iwl_mvm_find_scan_uid(mvm, uid) <
1198 IWL_MVM_MAX_SIMULTANEOUS_SCANS);
1199
1200 IWL_DEBUG_SCAN(mvm, "Generated scan UID %u\n", uid);
1201
1202 return uid;
1203}
1204
1205static void
1206iwl_mvm_build_generic_umac_scan_cmd(struct iwl_mvm *mvm,
1207 struct iwl_scan_req_umac *cmd,
1208 struct iwl_mvm_scan_params *params)
1209{
1210 memset(cmd, 0, ksize(cmd));
1211 cmd->hdr.size = cpu_to_le16(iwl_mvm_scan_size(mvm) -
1212 sizeof(struct iwl_mvm_umac_cmd_hdr));
1213 cmd->active_dwell = params->dwell[IEEE80211_BAND_2GHZ].active;
1214 cmd->passive_dwell = params->dwell[IEEE80211_BAND_2GHZ].passive;
1215 if (params->passive_fragmented)
1216 cmd->fragmented_dwell =
1217 params->dwell[IEEE80211_BAND_2GHZ].passive;
1218 cmd->max_out_time = cpu_to_le32(params->max_out_time);
1219 cmd->suspend_time = cpu_to_le32(params->suspend_time);
1220 cmd->scan_priority = cpu_to_le32(IWL_SCAN_PRIORITY_HIGH);
1221}
1222
1223static void
1224iwl_mvm_umac_scan_cfg_channels(struct iwl_mvm *mvm,
1225 struct ieee80211_channel **channels,
1226 int n_channels, u32 ssid_bitmap,
1227 struct iwl_scan_req_umac *cmd)
1228{
1229 struct iwl_scan_channel_cfg_umac *channel_cfg = (void *)&cmd->data;
1230 int i;
1231
1232 for (i = 0; i < n_channels; i++) {
1233 channel_cfg[i].flags = cpu_to_le32(ssid_bitmap);
1234 channel_cfg[i].channel_num = channels[i]->hw_value;
1235 channel_cfg[i].iter_count = 1;
1236 channel_cfg[i].iter_interval = 0;
1237 }
1238}
1239
1240static u32 iwl_mvm_scan_umac_common_flags(struct iwl_mvm *mvm, int n_ssids,
1241 struct cfg80211_ssid *ssids,
1242 int fragmented)
1243{
1244 int flags = 0;
1245
1246 if (n_ssids == 0)
1247 flags = IWL_UMAC_SCAN_GEN_FLAGS_PASSIVE;
1248
1249 if (n_ssids == 1 && ssids[0].ssid_len != 0)
1250 flags |= IWL_UMAC_SCAN_GEN_FLAGS_PRE_CONNECT;
1251
1252 if (fragmented)
1253 flags |= IWL_UMAC_SCAN_GEN_FLAGS_FRAGMENTED;
1254
1255 if (iwl_mvm_rrm_scan_needed(mvm))
1256 flags |= IWL_UMAC_SCAN_GEN_FLAGS_RRM_ENABLED;
1257
1258 return flags;
1259}
1260
1261int iwl_mvm_scan_umac(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1262 struct ieee80211_scan_request *req)
1263{
1264 struct iwl_host_cmd hcmd = {
1265 .id = SCAN_REQ_UMAC,
1266 .len = { iwl_mvm_scan_size(mvm), },
1267 .data = { mvm->scan_cmd, },
1268 .dataflags = { IWL_HCMD_DFL_NOCOPY, },
1269 };
1270 struct iwl_scan_req_umac *cmd = mvm->scan_cmd;
1271 struct iwl_scan_req_umac_tail *sec_part = (void *)&cmd->data +
1272 sizeof(struct iwl_scan_channel_cfg_umac) *
1273 mvm->fw->ucode_capa.n_scan_channels;
1274 struct iwl_mvm_scan_params params = {};
1275 u32 uid, flags;
c8660dd5 1276 u32 ssid_bitmap = 0;
d2496221
DS
1277 int ret, i, uid_idx;
1278
1279 lockdep_assert_held(&mvm->mutex);
1280
1281 uid_idx = iwl_mvm_find_free_scan_uid(mvm);
1282 if (uid_idx >= IWL_MVM_MAX_SIMULTANEOUS_SCANS)
1283 return -EBUSY;
1284
1285 /* we should have failed registration if scan_cmd was NULL */
1286 if (WARN_ON(mvm->scan_cmd == NULL))
1287 return -ENOMEM;
1288
1289 if (WARN_ON(req->req.n_ssids > PROBE_OPTION_MAX ||
1290 req->ies.common_ie_len +
1291 req->ies.len[NL80211_BAND_2GHZ] +
1292 req->ies.len[NL80211_BAND_5GHZ] + 24 + 2 >
1293 SCAN_OFFLOAD_PROBE_REQ_SIZE || req->req.n_channels >
1294 mvm->fw->ucode_capa.n_scan_channels))
1295 return -ENOBUFS;
1296
1297 iwl_mvm_scan_calc_params(mvm, vif, req->req.n_ssids, req->req.flags,
1298 &params);
1299
1300 iwl_mvm_build_generic_umac_scan_cmd(mvm, cmd, &params);
1301
1302 uid = iwl_generate_scan_uid(mvm, IWL_UMAC_SCAN_UID_REG_SCAN);
1303 mvm->scan_uid[uid_idx] = uid;
1304 cmd->uid = cpu_to_le32(uid);
1305
1306 cmd->ooc_priority = cpu_to_le32(IWL_SCAN_PRIORITY_HIGH);
1307
1308 flags = iwl_mvm_scan_umac_common_flags(mvm, req->req.n_ssids,
1309 req->req.ssids,
1310 params.passive_fragmented);
1311
1312 flags |= IWL_UMAC_SCAN_GEN_FLAGS_PASS_ALL;
1313
1314 cmd->general_flags = cpu_to_le32(flags);
4db6558c
HD
1315
1316 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_SINGLE_SCAN_EBS &&
1317 mvm->last_ebs_successful)
1318 cmd->channel_flags = IWL_SCAN_CHANNEL_FLAG_EBS |
1319 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
1320 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD;
1321
d2496221
DS
1322 cmd->n_channels = req->req.n_channels;
1323
1324 for (i = 0; i < req->req.n_ssids; i++)
1325 ssid_bitmap |= BIT(i);
1326
1327 iwl_mvm_umac_scan_cfg_channels(mvm, req->req.channels,
1328 req->req.n_channels, ssid_bitmap, cmd);
1329
1330 sec_part->schedule[0].iter_count = 1;
1331 sec_part->delay = 0;
1332
effd05ac
JB
1333 iwl_mvm_build_unified_scan_probe(mvm, vif, &req->ies, &sec_part->preq,
1334 req->req.flags & NL80211_SCAN_FLAG_RANDOM_ADDR ?
1335 req->req.mac_addr : NULL,
1336 req->req.mac_addr_mask);
d2496221
DS
1337
1338 iwl_mvm_scan_fill_ssids(sec_part->direct_scan, req->req.ssids,
1339 req->req.n_ssids, 0);
1340
1341 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1342 if (!ret) {
1343 IWL_DEBUG_SCAN(mvm,
1344 "Scan request was sent successfully\n");
1345 } else {
1346 /*
1347 * If the scan failed, it usually means that the FW was unable
1348 * to allocate the time events. Warn on it, but maybe we
1349 * should try to send the command again with different params.
1350 */
1351 IWL_ERR(mvm, "Scan failed! ret %d\n", ret);
1352 }
1353 return ret;
1354}
1355
1356int iwl_mvm_sched_scan_umac(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1357 struct cfg80211_sched_scan_request *req,
1358 struct ieee80211_scan_ies *ies)
1359{
1360
1361 struct iwl_host_cmd hcmd = {
1362 .id = SCAN_REQ_UMAC,
1363 .len = { iwl_mvm_scan_size(mvm), },
1364 .data = { mvm->scan_cmd, },
1365 .dataflags = { IWL_HCMD_DFL_NOCOPY, },
1366 };
1367 struct iwl_scan_req_umac *cmd = mvm->scan_cmd;
1368 struct iwl_scan_req_umac_tail *sec_part = (void *)&cmd->data +
1369 sizeof(struct iwl_scan_channel_cfg_umac) *
1370 mvm->fw->ucode_capa.n_scan_channels;
1371 struct iwl_mvm_scan_params params = {};
1372 u32 uid, flags;
c8660dd5 1373 u32 ssid_bitmap = 0;
d2496221
DS
1374 int ret, uid_idx;
1375
1376 lockdep_assert_held(&mvm->mutex);
1377
1378 uid_idx = iwl_mvm_find_free_scan_uid(mvm);
1379 if (uid_idx >= IWL_MVM_MAX_SIMULTANEOUS_SCANS)
1380 return -EBUSY;
1381
1382 /* we should have failed registration if scan_cmd was NULL */
1383 if (WARN_ON(mvm->scan_cmd == NULL))
1384 return -ENOMEM;
1385
1386 if (WARN_ON(req->n_ssids > PROBE_OPTION_MAX ||
1387 ies->common_ie_len + ies->len[NL80211_BAND_2GHZ] +
1388 ies->len[NL80211_BAND_5GHZ] + 24 + 2 >
1389 SCAN_OFFLOAD_PROBE_REQ_SIZE || req->n_channels >
1390 mvm->fw->ucode_capa.n_scan_channels))
1391 return -ENOBUFS;
1392
1393 iwl_mvm_scan_calc_params(mvm, vif, req->n_ssids, req->flags,
1394 &params);
1395
1396 iwl_mvm_build_generic_umac_scan_cmd(mvm, cmd, &params);
1397
1398 cmd->flags = cpu_to_le32(IWL_UMAC_SCAN_FLAG_PREEMPTIVE);
1399
1400 uid = iwl_generate_scan_uid(mvm, IWL_UMAC_SCAN_UID_SCHED_SCAN);
1401 mvm->scan_uid[uid_idx] = uid;
1402 cmd->uid = cpu_to_le32(uid);
1403
1404 cmd->ooc_priority = cpu_to_le32(IWL_SCAN_PRIORITY_LOW);
1405
1406 flags = iwl_mvm_scan_umac_common_flags(mvm, req->n_ssids, req->ssids,
1407 params.passive_fragmented);
1408
1409 flags |= IWL_UMAC_SCAN_GEN_FLAGS_PERIODIC;
1410
1411 if (iwl_mvm_scan_pass_all(mvm, req))
1412 flags |= IWL_UMAC_SCAN_GEN_FLAGS_PASS_ALL;
1413 else
1414 flags |= IWL_UMAC_SCAN_GEN_FLAGS_MATCH;
1415
1416 cmd->general_flags = cpu_to_le32(flags);
1417
1418 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_EBS_SUPPORT &&
1419 mvm->last_ebs_successful)
1420 cmd->channel_flags = IWL_SCAN_CHANNEL_FLAG_EBS |
1421 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
1422 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD;
1423
1424 cmd->n_channels = req->n_channels;
1425
1426 iwl_scan_offload_build_ssid(req, sec_part->direct_scan, &ssid_bitmap,
1427 false);
1428
1429 /* This API uses bits 0-19 instead of 1-20. */
1430 ssid_bitmap = ssid_bitmap >> 1;
1431
1432 iwl_mvm_umac_scan_cfg_channels(mvm, req->channels, req->n_channels,
1433 ssid_bitmap, cmd);
1434
1435 sec_part->schedule[0].interval =
1436 cpu_to_le16(req->interval / MSEC_PER_SEC);
1437 sec_part->schedule[0].iter_count = 0xff;
1438
1439 sec_part->delay = 0;
1440
effd05ac
JB
1441 iwl_mvm_build_unified_scan_probe(mvm, vif, ies, &sec_part->preq,
1442 req->flags & NL80211_SCAN_FLAG_RANDOM_ADDR ?
1443 req->mac_addr : NULL,
1444 req->mac_addr_mask);
d2496221
DS
1445
1446 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1447 if (!ret) {
1448 IWL_DEBUG_SCAN(mvm,
1449 "Sched scan request was sent successfully\n");
1450 } else {
1451 /*
1452 * If the scan failed, it usually means that the FW was unable
1453 * to allocate the time events. Warn on it, but maybe we
1454 * should try to send the command again with different params.
1455 */
1456 IWL_ERR(mvm, "Sched scan failed! ret %d\n", ret);
1457 }
1458 return ret;
1459}
1460
1461int iwl_mvm_rx_umac_scan_complete_notif(struct iwl_mvm *mvm,
1462 struct iwl_rx_cmd_buffer *rxb,
1463 struct iwl_device_cmd *cmd)
1464{
1465 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1466 struct iwl_umac_scan_complete *notif = (void *)pkt->data;
1467 u32 uid = __le32_to_cpu(notif->uid);
1468 bool sched = !!(uid & IWL_UMAC_SCAN_UID_SCHED_SCAN);
1469 int uid_idx = iwl_mvm_find_scan_uid(mvm, uid);
1470
2992a324
DS
1471 /*
1472 * Scan uid may be set to zero in case of scan abort request from above.
1473 */
1474 if (uid_idx >= IWL_MVM_MAX_SIMULTANEOUS_SCANS)
d2496221
DS
1475 return 0;
1476
1477 IWL_DEBUG_SCAN(mvm,
1478 "Scan completed, uid %u type %s, status %s, EBS status %s\n",
1479 uid, sched ? "sched" : "regular",
1480 notif->status == IWL_SCAN_OFFLOAD_COMPLETED ?
1481 "completed" : "aborted",
1482 notif->ebs_status == IWL_SCAN_EBS_SUCCESS ?
1483 "success" : "failed");
1484
5a4b2afa
HD
1485 if (notif->ebs_status)
1486 mvm->last_ebs_successful = false;
1487
d2496221
DS
1488 mvm->scan_uid[uid_idx] = 0;
1489
1490 if (!sched) {
1491 ieee80211_scan_completed(mvm->hw,
1492 notif->status ==
1493 IWL_SCAN_OFFLOAD_ABORTED);
1494 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
1495 } else if (!iwl_mvm_find_scan_type(mvm, IWL_UMAC_SCAN_UID_SCHED_SCAN)) {
1496 ieee80211_sched_scan_stopped(mvm->hw);
1497 } else {
1498 IWL_DEBUG_SCAN(mvm, "Another sched scan is running\n");
1499 }
1500
1501 return 0;
1502}
1503
1504static bool iwl_scan_umac_done_check(struct iwl_notif_wait_data *notif_wait,
1505 struct iwl_rx_packet *pkt, void *data)
1506{
1507 struct iwl_umac_scan_done *scan_done = data;
1508 struct iwl_umac_scan_complete *notif = (void *)pkt->data;
1509 u32 uid = __le32_to_cpu(notif->uid);
1510 int uid_idx = iwl_mvm_find_scan_uid(scan_done->mvm, uid);
1511
1512 if (WARN_ON(pkt->hdr.cmd != SCAN_COMPLETE_UMAC))
1513 return false;
1514
1515 if (uid_idx >= IWL_MVM_MAX_SIMULTANEOUS_SCANS)
1516 return false;
1517
1518 /*
1519 * Clear scan uid of scans that was aborted from above and completed
5a4b2afa
HD
1520 * in FW so the RX handler does nothing. Set last_ebs_successful here if
1521 * needed.
d2496221
DS
1522 */
1523 scan_done->mvm->scan_uid[uid_idx] = 0;
1524
5a4b2afa
HD
1525 if (notif->ebs_status)
1526 scan_done->mvm->last_ebs_successful = false;
1527
d2496221
DS
1528 return !iwl_mvm_find_scan_type(scan_done->mvm, scan_done->type);
1529}
1530
1531static int iwl_umac_scan_abort_one(struct iwl_mvm *mvm, u32 uid)
1532{
1533 struct iwl_umac_scan_abort cmd = {
1534 .hdr.size = cpu_to_le16(sizeof(struct iwl_umac_scan_abort) -
1535 sizeof(struct iwl_mvm_umac_cmd_hdr)),
1536 .uid = cpu_to_le32(uid),
1537 };
1538
1539 lockdep_assert_held(&mvm->mutex);
1540
1541 IWL_DEBUG_SCAN(mvm, "Sending scan abort, uid %u\n", uid);
1542
1543 return iwl_mvm_send_cmd_pdu(mvm, SCAN_ABORT_UMAC, 0, sizeof(cmd), &cmd);
1544}
1545
1546static int iwl_umac_scan_stop(struct iwl_mvm *mvm,
1547 enum iwl_umac_scan_uid_type type, bool notify)
1548{
1549 struct iwl_notification_wait wait_scan_done;
1550 static const u8 scan_done_notif[] = { SCAN_COMPLETE_UMAC, };
1551 struct iwl_umac_scan_done scan_done = {
1552 .mvm = mvm,
1553 .type = type,
1554 };
1555 int i, ret = -EIO;
1556
1557 iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_done,
1558 scan_done_notif,
1559 ARRAY_SIZE(scan_done_notif),
1560 iwl_scan_umac_done_check, &scan_done);
1561
1562 IWL_DEBUG_SCAN(mvm, "Preparing to stop scan, type %x\n", type);
1563
1564 for (i = 0; i < IWL_MVM_MAX_SIMULTANEOUS_SCANS; i++) {
1565 if (mvm->scan_uid[i] & type) {
1566 int err;
1567
1568 if (iwl_mvm_is_radio_killed(mvm) &&
1569 (type & IWL_UMAC_SCAN_UID_REG_SCAN)) {
1570 ieee80211_scan_completed(mvm->hw, true);
1571 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
1572 break;
1573 }
1574
1575 err = iwl_umac_scan_abort_one(mvm, mvm->scan_uid[i]);
1576 if (!err)
1577 ret = 0;
1578 }
1579 }
1580
1581 if (ret) {
1582 IWL_DEBUG_SCAN(mvm, "Couldn't stop scan\n");
1583 iwl_remove_notification(&mvm->notif_wait, &wait_scan_done);
1584 return ret;
1585 }
1586
1587 ret = iwl_wait_notification(&mvm->notif_wait, &wait_scan_done, 1 * HZ);
1588 if (ret)
1589 return ret;
1590
1591 if (notify) {
1592 if (type & IWL_UMAC_SCAN_UID_SCHED_SCAN)
1593 ieee80211_sched_scan_stopped(mvm->hw);
1594 if (type & IWL_UMAC_SCAN_UID_REG_SCAN) {
1595 ieee80211_scan_completed(mvm->hw, true);
1596 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
1597 }
1598 }
1599
1600 return ret;
1601}
1602
1603int iwl_mvm_scan_size(struct iwl_mvm *mvm)
1604{
1605 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)
1606 return sizeof(struct iwl_scan_req_umac) +
1607 sizeof(struct iwl_scan_channel_cfg_umac) *
1608 mvm->fw->ucode_capa.n_scan_channels +
1609 sizeof(struct iwl_scan_req_umac_tail);
1610
1f940386
LC
1611 return sizeof(struct iwl_scan_req_unified_lmac) +
1612 sizeof(struct iwl_scan_channel_cfg_lmac) *
1613 mvm->fw->ucode_capa.n_scan_channels +
1614 sizeof(struct iwl_scan_probe_req);
d2496221 1615}
This page took 0.365205 seconds and 5 git commands to generate.