1 /******************************************************************************
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.
8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
11 * Copyright(c) 2018 - 2019 Intel Corporation
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of version 2 of the GNU General Public License as
15 * published by the Free Software Foundation.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * The full GNU General Public License is included in this distribution
23 * in the file called COPYING.
25 * Contact Information:
26 * Intel Linux Wireless <linuxwifi@intel.com>
27 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
32 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
33 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
34 * Copyright(c) 2018 - 2019 Intel Corporation
35 * All rights reserved.
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
41 * * Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * * Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in
45 * the documentation and/or other materials provided with the
47 * * Neither the name Intel Corporation nor the names of its
48 * contributors may be used to endorse or promote products derived
49 * from this software without specific prior written permission.
51 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
52 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
53 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
54 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
55 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
61 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 *****************************************************************************/
65 #include <linux/etherdevice.h>
66 #include <net/mac80211.h>
69 #include "fw/api/scan.h"
72 #define IWL_DENSE_EBS_SCAN_RATIO 5
73 #define IWL_SPARSE_EBS_SCAN_RATIO 1
75 #define IWL_SCAN_DWELL_ACTIVE 10
76 #define IWL_SCAN_DWELL_PASSIVE 110
77 #define IWL_SCAN_DWELL_FRAGMENTED 44
78 #define IWL_SCAN_DWELL_EXTENDED 90
79 #define IWL_SCAN_NUM_OF_FRAGS 3
82 /* adaptive dwell max budget time [TU] for full scan */
83 #define IWL_SCAN_ADWELL_MAX_BUDGET_FULL_SCAN 300
84 /* adaptive dwell max budget time [TU] for directed scan */
85 #define IWL_SCAN_ADWELL_MAX_BUDGET_DIRECTED_SCAN 100
86 /* adaptive dwell default high band APs number */
87 #define IWL_SCAN_ADWELL_DEFAULT_HB_N_APS 8
88 /* adaptive dwell default low band APs number */
89 #define IWL_SCAN_ADWELL_DEFAULT_LB_N_APS 2
90 /* adaptive dwell default APs number in social channels (1, 6, 11) */
91 #define IWL_SCAN_ADWELL_DEFAULT_N_APS_SOCIAL 10
93 struct iwl_mvm_scan_timing_params {
98 static struct iwl_mvm_scan_timing_params scan_timing[] = {
99 [IWL_SCAN_TYPE_UNASSOC] = {
103 [IWL_SCAN_TYPE_WILD] = {
107 [IWL_SCAN_TYPE_MILD] = {
111 [IWL_SCAN_TYPE_FRAGMENTED] = {
115 [IWL_SCAN_TYPE_FAST_BALANCE] = {
121 struct iwl_mvm_scan_params {
122 /* For CDB this is low band scan type, for non-CDB - type. */
123 enum iwl_mvm_scan_type type;
124 enum iwl_mvm_scan_type hb_type;
128 struct cfg80211_ssid *ssids;
129 struct ieee80211_channel **channels;
136 struct iwl_scan_probe_req preq;
137 struct cfg80211_match_set *match_sets;
139 struct cfg80211_sched_scan_plan *scan_plans;
140 u32 measurement_dwell;
143 static inline void *iwl_mvm_get_scan_req_umac_data(struct iwl_mvm *mvm)
145 struct iwl_scan_req_umac *cmd = mvm->scan_cmd;
147 if (iwl_mvm_is_adaptive_dwell_v2_supported(mvm))
148 return (void *)&cmd->v8.data;
150 if (iwl_mvm_is_adaptive_dwell_supported(mvm))
151 return (void *)&cmd->v7.data;
153 if (iwl_mvm_cdb_scan_api(mvm))
154 return (void *)&cmd->v6.data;
156 return (void *)&cmd->v1.data;
159 static inline struct iwl_scan_umac_chan_param *
160 iwl_mvm_get_scan_req_umac_channel(struct iwl_mvm *mvm)
162 struct iwl_scan_req_umac *cmd = mvm->scan_cmd;
164 if (iwl_mvm_is_adaptive_dwell_v2_supported(mvm))
165 return &cmd->v8.channel;
167 if (iwl_mvm_is_adaptive_dwell_supported(mvm))
168 return &cmd->v7.channel;
170 if (iwl_mvm_cdb_scan_api(mvm))
171 return &cmd->v6.channel;
173 return &cmd->v1.channel;
176 static u8 iwl_mvm_scan_rx_ant(struct iwl_mvm *mvm)
178 if (mvm->scan_rx_ant != ANT_NONE)
179 return mvm->scan_rx_ant;
180 return iwl_mvm_get_valid_rx_ant(mvm);
183 static inline __le16 iwl_mvm_scan_rx_chain(struct iwl_mvm *mvm)
188 rx_ant = iwl_mvm_scan_rx_ant(mvm);
189 rx_chain = rx_ant << PHY_RX_CHAIN_VALID_POS;
190 rx_chain |= rx_ant << PHY_RX_CHAIN_FORCE_MIMO_SEL_POS;
191 rx_chain |= rx_ant << PHY_RX_CHAIN_FORCE_SEL_POS;
192 rx_chain |= 0x1 << PHY_RX_CHAIN_DRIVER_FORCE_POS;
193 return cpu_to_le16(rx_chain);
196 static __le32 iwl_mvm_scan_rxon_flags(enum nl80211_band band)
198 if (band == NL80211_BAND_2GHZ)
199 return cpu_to_le32(PHY_BAND_24);
201 return cpu_to_le32(PHY_BAND_5);
205 iwl_mvm_scan_rate_n_flags(struct iwl_mvm *mvm, enum nl80211_band band,
210 iwl_mvm_toggle_tx_ant(mvm, &mvm->scan_last_antenna_idx);
211 tx_ant = BIT(mvm->scan_last_antenna_idx) << RATE_MCS_ANT_POS;
213 if (band == NL80211_BAND_2GHZ && !no_cck)
214 return cpu_to_le32(IWL_RATE_1M_PLCP | RATE_MCS_CCK_MSK |
217 return cpu_to_le32(IWL_RATE_6M_PLCP | tx_ant);
220 static void iwl_mvm_scan_condition_iterator(void *data, u8 *mac,
221 struct ieee80211_vif *vif)
223 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
224 int *global_cnt = data;
226 if (vif->type != NL80211_IFTYPE_P2P_DEVICE && mvmvif->phy_ctxt &&
227 mvmvif->phy_ctxt->id < NUM_PHY_CTX)
231 static enum iwl_mvm_traffic_load iwl_mvm_get_traffic_load(struct iwl_mvm *mvm)
233 return mvm->tcm.result.global_load;
236 static enum iwl_mvm_traffic_load
237 iwl_mvm_get_traffic_load_band(struct iwl_mvm *mvm, enum nl80211_band band)
239 return mvm->tcm.result.band_load[band];
242 struct iwl_is_dcm_with_go_iterator_data {
243 struct ieee80211_vif *current_vif;
244 bool is_dcm_with_p2p_go;
247 static void iwl_mvm_is_dcm_with_go_iterator(void *_data, u8 *mac,
248 struct ieee80211_vif *vif)
250 struct iwl_is_dcm_with_go_iterator_data *data = _data;
251 struct iwl_mvm_vif *other_mvmvif = iwl_mvm_vif_from_mac80211(vif);
252 struct iwl_mvm_vif *curr_mvmvif =
253 iwl_mvm_vif_from_mac80211(data->current_vif);
255 /* exclude the given vif */
256 if (vif == data->current_vif)
259 if (vif->type == NL80211_IFTYPE_AP && vif->p2p &&
260 other_mvmvif->phy_ctxt && curr_mvmvif->phy_ctxt &&
261 other_mvmvif->phy_ctxt->id != curr_mvmvif->phy_ctxt->id)
262 data->is_dcm_with_p2p_go = true;
266 iwl_mvm_scan_type _iwl_mvm_get_scan_type(struct iwl_mvm *mvm,
267 struct ieee80211_vif *vif,
268 enum iwl_mvm_traffic_load load,
273 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
274 IEEE80211_IFACE_ITER_NORMAL,
275 iwl_mvm_scan_condition_iterator,
278 return IWL_SCAN_TYPE_UNASSOC;
280 if (fw_has_api(&mvm->fw->ucode_capa,
281 IWL_UCODE_TLV_API_FRAGMENTED_SCAN)) {
282 if ((load == IWL_MVM_TRAFFIC_HIGH || low_latency) &&
283 (!vif || vif->type != NL80211_IFTYPE_P2P_DEVICE))
284 return IWL_SCAN_TYPE_FRAGMENTED;
286 /* in case of DCM with GO where BSS DTIM interval < 220msec
287 * set all scan requests as fast-balance scan
289 if (vif && vif->type == NL80211_IFTYPE_STATION &&
290 vif->bss_conf.dtim_period < 220) {
291 struct iwl_is_dcm_with_go_iterator_data data = {
293 .is_dcm_with_p2p_go = false,
296 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
297 IEEE80211_IFACE_ITER_NORMAL,
298 iwl_mvm_is_dcm_with_go_iterator,
300 if (data.is_dcm_with_p2p_go)
301 return IWL_SCAN_TYPE_FAST_BALANCE;
305 if (load >= IWL_MVM_TRAFFIC_MEDIUM || low_latency)
306 return IWL_SCAN_TYPE_MILD;
308 return IWL_SCAN_TYPE_WILD;
312 iwl_mvm_scan_type iwl_mvm_get_scan_type(struct iwl_mvm *mvm,
313 struct ieee80211_vif *vif)
315 enum iwl_mvm_traffic_load load;
318 load = iwl_mvm_get_traffic_load(mvm);
319 low_latency = iwl_mvm_low_latency(mvm);
321 return _iwl_mvm_get_scan_type(mvm, vif, load, low_latency);
325 iwl_mvm_scan_type iwl_mvm_get_scan_type_band(struct iwl_mvm *mvm,
326 struct ieee80211_vif *vif,
327 enum nl80211_band band)
329 enum iwl_mvm_traffic_load load;
332 load = iwl_mvm_get_traffic_load_band(mvm, band);
333 low_latency = iwl_mvm_low_latency_band(mvm, band);
335 return _iwl_mvm_get_scan_type(mvm, vif, load, low_latency);
339 iwl_mvm_get_measurement_dwell(struct iwl_mvm *mvm,
340 struct cfg80211_scan_request *req,
341 struct iwl_mvm_scan_params *params)
343 u32 duration = scan_timing[params->type].max_out_time;
348 if (iwl_mvm_is_cdb_supported(mvm)) {
349 u32 hb_time = scan_timing[params->hb_type].max_out_time;
351 duration = min_t(u32, duration, hb_time);
354 if (req->duration_mandatory && req->duration > duration) {
356 "Measurement scan - too long dwell %hu (max out time %u)\n",
362 return min_t(u32, (u32)req->duration, duration);
365 static inline bool iwl_mvm_rrm_scan_needed(struct iwl_mvm *mvm)
367 /* require rrm scan whenever the fw supports it */
368 return fw_has_capa(&mvm->fw->ucode_capa,
369 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT);
372 static int iwl_mvm_max_scan_ie_fw_cmd_room(struct iwl_mvm *mvm)
376 max_probe_len = SCAN_OFFLOAD_PROBE_REQ_SIZE;
378 /* we create the 802.11 header and SSID element */
379 max_probe_len -= 24 + 2;
381 /* DS parameter set element is added on 2.4GHZ band if required */
382 if (iwl_mvm_rrm_scan_needed(mvm))
385 return max_probe_len;
388 int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm)
390 int max_ie_len = iwl_mvm_max_scan_ie_fw_cmd_room(mvm);
392 /* TODO: [BUG] This function should return the maximum allowed size of
393 * scan IEs, however the LMAC scan api contains both 2GHZ and 5GHZ IEs
394 * in the same command. So the correct implementation of this function
395 * is just iwl_mvm_max_scan_ie_fw_cmd_room() / 2. Currently the scan
396 * command has only 512 bytes and it would leave us with about 240
397 * bytes for scan IEs, which is clearly not enough. So meanwhile
398 * we will report an incorrect value. This may result in a failure to
399 * issue a scan in unified_scan_lmac and unified_sched_scan_lmac
400 * functions with -ENOBUFS, if a large enough probe will be provided.
405 void iwl_mvm_rx_lmac_scan_iter_complete_notif(struct iwl_mvm *mvm,
406 struct iwl_rx_cmd_buffer *rxb)
408 struct iwl_rx_packet *pkt = rxb_addr(rxb);
409 struct iwl_lmac_scan_complete_notif *notif = (void *)pkt->data;
412 "Scan offload iteration complete: status=0x%x scanned channels=%d\n",
413 notif->status, notif->scanned_channels);
415 if (mvm->sched_scan_pass_all == SCHED_SCAN_PASS_ALL_FOUND) {
416 IWL_DEBUG_SCAN(mvm, "Pass all scheduled scan results found\n");
417 ieee80211_sched_scan_results(mvm->hw);
418 mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_ENABLED;
422 void iwl_mvm_rx_scan_match_found(struct iwl_mvm *mvm,
423 struct iwl_rx_cmd_buffer *rxb)
425 IWL_DEBUG_SCAN(mvm, "Scheduled scan results\n");
426 ieee80211_sched_scan_results(mvm->hw);
429 static const char *iwl_mvm_ebs_status_str(enum iwl_scan_ebs_status status)
432 case IWL_SCAN_EBS_SUCCESS:
434 case IWL_SCAN_EBS_INACTIVE:
436 case IWL_SCAN_EBS_FAILED:
437 case IWL_SCAN_EBS_CHAN_NOT_FOUND:
443 void iwl_mvm_rx_lmac_scan_complete_notif(struct iwl_mvm *mvm,
444 struct iwl_rx_cmd_buffer *rxb)
446 struct iwl_rx_packet *pkt = rxb_addr(rxb);
447 struct iwl_periodic_scan_complete *scan_notif = (void *)pkt->data;
448 bool aborted = (scan_notif->status == IWL_SCAN_OFFLOAD_ABORTED);
450 /* If this happens, the firmware has mistakenly sent an LMAC
451 * notification during UMAC scans -- warn and ignore it.
453 if (WARN_ON_ONCE(fw_has_capa(&mvm->fw->ucode_capa,
454 IWL_UCODE_TLV_CAPA_UMAC_SCAN)))
457 /* scan status must be locked for proper checking */
458 lockdep_assert_held(&mvm->mutex);
460 /* We first check if we were stopping a scan, in which case we
461 * just clear the stopping flag. Then we check if it was a
462 * firmware initiated stop, in which case we need to inform
464 * Note that we can have a stopping and a running scan
465 * simultaneously, but we can't have two different types of
466 * scans stopping or running at the same time (since LMAC
467 * doesn't support it).
470 if (mvm->scan_status & IWL_MVM_SCAN_STOPPING_SCHED) {
471 WARN_ON_ONCE(mvm->scan_status & IWL_MVM_SCAN_STOPPING_REGULAR);
473 IWL_DEBUG_SCAN(mvm, "Scheduled scan %s, EBS status %s\n",
474 aborted ? "aborted" : "completed",
475 iwl_mvm_ebs_status_str(scan_notif->ebs_status));
477 "Last line %d, Last iteration %d, Time after last iteration %d\n",
478 scan_notif->last_schedule_line,
479 scan_notif->last_schedule_iteration,
480 __le32_to_cpu(scan_notif->time_after_last_iter));
482 mvm->scan_status &= ~IWL_MVM_SCAN_STOPPING_SCHED;
483 } else if (mvm->scan_status & IWL_MVM_SCAN_STOPPING_REGULAR) {
484 IWL_DEBUG_SCAN(mvm, "Regular scan %s, EBS status %s\n",
485 aborted ? "aborted" : "completed",
486 iwl_mvm_ebs_status_str(scan_notif->ebs_status));
488 mvm->scan_status &= ~IWL_MVM_SCAN_STOPPING_REGULAR;
489 } else if (mvm->scan_status & IWL_MVM_SCAN_SCHED) {
490 WARN_ON_ONCE(mvm->scan_status & IWL_MVM_SCAN_REGULAR);
492 IWL_DEBUG_SCAN(mvm, "Scheduled scan %s, EBS status %s\n",
493 aborted ? "aborted" : "completed",
494 iwl_mvm_ebs_status_str(scan_notif->ebs_status));
496 "Last line %d, Last iteration %d, Time after last iteration %d (FW)\n",
497 scan_notif->last_schedule_line,
498 scan_notif->last_schedule_iteration,
499 __le32_to_cpu(scan_notif->time_after_last_iter));
501 mvm->scan_status &= ~IWL_MVM_SCAN_SCHED;
502 ieee80211_sched_scan_stopped(mvm->hw);
503 mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_DISABLED;
504 } else if (mvm->scan_status & IWL_MVM_SCAN_REGULAR) {
505 struct cfg80211_scan_info info = {
509 IWL_DEBUG_SCAN(mvm, "Regular scan %s, EBS status %s (FW)\n",
510 aborted ? "aborted" : "completed",
511 iwl_mvm_ebs_status_str(scan_notif->ebs_status));
513 mvm->scan_status &= ~IWL_MVM_SCAN_REGULAR;
514 ieee80211_scan_completed(mvm->hw, &info);
515 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
516 cancel_delayed_work(&mvm->scan_timeout_dwork);
517 iwl_mvm_resume_tcm(mvm);
520 "got scan complete notification but no scan is running\n");
523 mvm->last_ebs_successful =
524 scan_notif->ebs_status == IWL_SCAN_EBS_SUCCESS ||
525 scan_notif->ebs_status == IWL_SCAN_EBS_INACTIVE;
528 static int iwl_ssid_exist(u8 *ssid, u8 ssid_len, struct iwl_ssid_ie *ssid_list)
532 for (i = 0; i < PROBE_OPTION_MAX; i++) {
533 if (!ssid_list[i].len)
535 if (ssid_list[i].len == ssid_len &&
536 !memcmp(ssid_list->ssid, ssid, ssid_len))
542 /* We insert the SSIDs in an inverted order, because the FW will
545 static void iwl_scan_build_ssids(struct iwl_mvm_scan_params *params,
546 struct iwl_ssid_ie *ssids,
553 * copy SSIDs from match list.
554 * iwl_config_sched_scan_profiles() uses the order of these ssids to
557 for (i = 0, j = params->n_match_sets - 1;
558 j >= 0 && i < PROBE_OPTION_MAX;
560 /* skip empty SSID matchsets */
561 if (!params->match_sets[j].ssid.ssid_len)
563 ssids[i].id = WLAN_EID_SSID;
564 ssids[i].len = params->match_sets[j].ssid.ssid_len;
565 memcpy(ssids[i].ssid, params->match_sets[j].ssid.ssid,
569 /* add SSIDs from scan SSID list */
571 for (j = params->n_ssids - 1;
572 j >= 0 && i < PROBE_OPTION_MAX;
574 index = iwl_ssid_exist(params->ssids[j].ssid,
575 params->ssids[j].ssid_len,
578 ssids[i].id = WLAN_EID_SSID;
579 ssids[i].len = params->ssids[j].ssid_len;
580 memcpy(ssids[i].ssid, params->ssids[j].ssid,
582 *ssid_bitmap |= BIT(i);
584 *ssid_bitmap |= BIT(index);
590 iwl_mvm_config_sched_scan_profiles(struct iwl_mvm *mvm,
591 struct cfg80211_sched_scan_request *req)
593 struct iwl_scan_offload_profile *profile;
594 struct iwl_scan_offload_profile_cfg *profile_cfg;
595 struct iwl_scan_offload_blacklist *blacklist;
596 struct iwl_host_cmd cmd = {
597 .id = SCAN_OFFLOAD_UPDATE_PROFILES_CMD,
598 .len[1] = sizeof(*profile_cfg),
599 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
600 .dataflags[1] = IWL_HCMD_DFL_NOCOPY,
606 if (WARN_ON(req->n_match_sets > IWL_SCAN_MAX_PROFILES))
609 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_SHORT_BL)
610 blacklist_len = IWL_SCAN_SHORT_BLACKLIST_LEN;
612 blacklist_len = IWL_SCAN_MAX_BLACKLIST_LEN;
614 blacklist = kcalloc(blacklist_len, sizeof(*blacklist), GFP_KERNEL);
618 profile_cfg = kzalloc(sizeof(*profile_cfg), GFP_KERNEL);
624 cmd.data[0] = blacklist;
625 cmd.len[0] = sizeof(*blacklist) * blacklist_len;
626 cmd.data[1] = profile_cfg;
628 /* No blacklist configuration */
630 profile_cfg->num_profiles = req->n_match_sets;
631 profile_cfg->active_clients = SCAN_CLIENT_SCHED_SCAN;
632 profile_cfg->pass_match = SCAN_CLIENT_SCHED_SCAN;
633 profile_cfg->match_notify = SCAN_CLIENT_SCHED_SCAN;
634 if (!req->n_match_sets || !req->match_sets[0].ssid.ssid_len)
635 profile_cfg->any_beacon_notify = SCAN_CLIENT_SCHED_SCAN;
637 for (i = 0; i < req->n_match_sets; i++) {
638 profile = &profile_cfg->profiles[i];
639 profile->ssid_index = i;
640 /* Support any cipher and auth algorithm */
641 profile->unicast_cipher = 0xff;
642 profile->auth_alg = 0xff;
643 profile->network_type = IWL_NETWORK_TYPE_ANY;
644 profile->band_selection = IWL_SCAN_OFFLOAD_SELECT_ANY;
645 profile->client_bitmap = SCAN_CLIENT_SCHED_SCAN;
648 IWL_DEBUG_SCAN(mvm, "Sending scheduled scan profile config\n");
650 ret = iwl_mvm_send_cmd(mvm, &cmd);
658 static bool iwl_mvm_scan_pass_all(struct iwl_mvm *mvm,
659 struct cfg80211_sched_scan_request *req)
661 if (req->n_match_sets && req->match_sets[0].ssid.ssid_len) {
663 "Sending scheduled scan with filtering, n_match_sets %d\n",
665 mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_DISABLED;
669 IWL_DEBUG_SCAN(mvm, "Sending Scheduled scan without filtering\n");
671 mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_ENABLED;
675 static int iwl_mvm_lmac_scan_abort(struct iwl_mvm *mvm)
678 struct iwl_host_cmd cmd = {
679 .id = SCAN_OFFLOAD_ABORT_CMD,
681 u32 status = CAN_ABORT_STATUS;
683 ret = iwl_mvm_send_cmd_status(mvm, &cmd, &status);
687 if (status != CAN_ABORT_STATUS) {
689 * The scan abort will return 1 for success or
690 * 2 for "failure". A failure condition can be
691 * due to simply not being in an active scan which
692 * can occur if we send the scan abort before the
693 * microcode has notified us that a scan is completed.
695 IWL_DEBUG_SCAN(mvm, "SCAN OFFLOAD ABORT ret %d.\n", status);
702 static void iwl_mvm_scan_fill_tx_cmd(struct iwl_mvm *mvm,
703 struct iwl_scan_req_tx_cmd *tx_cmd,
706 tx_cmd[0].tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL |
708 tx_cmd[0].rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm,
711 tx_cmd[0].sta_id = mvm->aux_sta.sta_id;
713 tx_cmd[1].tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL |
715 tx_cmd[1].rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm,
718 tx_cmd[1].sta_id = mvm->aux_sta.sta_id;
722 iwl_mvm_lmac_scan_cfg_channels(struct iwl_mvm *mvm,
723 struct ieee80211_channel **channels,
724 int n_channels, u32 ssid_bitmap,
725 struct iwl_scan_req_lmac *cmd)
727 struct iwl_scan_channel_cfg_lmac *channel_cfg = (void *)&cmd->data;
730 for (i = 0; i < n_channels; i++) {
731 channel_cfg[i].channel_num =
732 cpu_to_le16(channels[i]->hw_value);
733 channel_cfg[i].iter_count = cpu_to_le16(1);
734 channel_cfg[i].iter_interval = 0;
735 channel_cfg[i].flags =
736 cpu_to_le32(IWL_UNIFIED_SCAN_CHANNEL_PARTIAL |
741 static u8 *iwl_mvm_copy_and_insert_ds_elem(struct iwl_mvm *mvm, const u8 *ies,
742 size_t len, u8 *const pos)
744 static const u8 before_ds_params[] = {
748 WLAN_EID_EXT_SUPP_RATES,
753 if (!iwl_mvm_rrm_scan_needed(mvm)) {
754 memcpy(newpos, ies, len);
758 offs = ieee80211_ie_split(ies, len,
760 ARRAY_SIZE(before_ds_params),
763 memcpy(newpos, ies, offs);
766 /* Add a placeholder for DS Parameter Set element */
767 *newpos++ = WLAN_EID_DS_PARAMS;
771 memcpy(newpos, ies + offs, len - offs);
772 newpos += len - offs;
777 #define WFA_TPC_IE_LEN 9
779 static void iwl_mvm_add_tpc_report_ie(u8 *pos)
781 pos[0] = WLAN_EID_VENDOR_SPECIFIC;
782 pos[1] = WFA_TPC_IE_LEN - 2;
783 pos[2] = (WLAN_OUI_MICROSOFT >> 16) & 0xff;
784 pos[3] = (WLAN_OUI_MICROSOFT >> 8) & 0xff;
785 pos[4] = WLAN_OUI_MICROSOFT & 0xff;
786 pos[5] = WLAN_OUI_TYPE_MICROSOFT_TPC;
788 /* pos[7] - tx power will be inserted by the FW */
794 iwl_mvm_build_scan_probe(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
795 struct ieee80211_scan_ies *ies,
796 struct iwl_mvm_scan_params *params)
798 struct ieee80211_mgmt *frame = (void *)params->preq.buf;
800 const u8 *mac_addr = params->flags & NL80211_SCAN_FLAG_RANDOM_ADDR ?
801 params->mac_addr : NULL;
804 * Unfortunately, right now the offload scan doesn't support randomising
805 * within the firmware, so until the firmware API is ready we implement
806 * it in the driver. This means that the scan iterations won't really be
807 * random, only when it's restarted, but at least that helps a bit.
810 get_random_mask_addr(frame->sa, mac_addr,
811 params->mac_addr_mask);
813 memcpy(frame->sa, vif->addr, ETH_ALEN);
815 frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
816 eth_broadcast_addr(frame->da);
817 eth_broadcast_addr(frame->bssid);
820 pos = frame->u.probe_req.variable;
821 *pos++ = WLAN_EID_SSID;
824 params->preq.mac_header.offset = 0;
825 params->preq.mac_header.len = cpu_to_le16(24 + 2);
827 /* Insert ds parameter set element on 2.4 GHz band */
828 newpos = iwl_mvm_copy_and_insert_ds_elem(mvm,
829 ies->ies[NL80211_BAND_2GHZ],
830 ies->len[NL80211_BAND_2GHZ],
832 params->preq.band_data[0].offset = cpu_to_le16(pos - params->preq.buf);
833 params->preq.band_data[0].len = cpu_to_le16(newpos - pos);
836 memcpy(pos, ies->ies[NL80211_BAND_5GHZ],
837 ies->len[NL80211_BAND_5GHZ]);
838 params->preq.band_data[1].offset = cpu_to_le16(pos - params->preq.buf);
839 params->preq.band_data[1].len =
840 cpu_to_le16(ies->len[NL80211_BAND_5GHZ]);
841 pos += ies->len[NL80211_BAND_5GHZ];
843 memcpy(pos, ies->common_ies, ies->common_ie_len);
844 params->preq.common_data.offset = cpu_to_le16(pos - params->preq.buf);
846 if (iwl_mvm_rrm_scan_needed(mvm) &&
847 !fw_has_capa(&mvm->fw->ucode_capa,
848 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT)) {
849 iwl_mvm_add_tpc_report_ie(pos + ies->common_ie_len);
850 params->preq.common_data.len = cpu_to_le16(ies->common_ie_len +
853 params->preq.common_data.len = cpu_to_le16(ies->common_ie_len);
857 static void iwl_mvm_scan_lmac_dwell(struct iwl_mvm *mvm,
858 struct iwl_scan_req_lmac *cmd,
859 struct iwl_mvm_scan_params *params)
861 cmd->active_dwell = IWL_SCAN_DWELL_ACTIVE;
862 cmd->passive_dwell = IWL_SCAN_DWELL_PASSIVE;
863 cmd->fragmented_dwell = IWL_SCAN_DWELL_FRAGMENTED;
864 cmd->extended_dwell = IWL_SCAN_DWELL_EXTENDED;
865 cmd->max_out_time = cpu_to_le32(scan_timing[params->type].max_out_time);
866 cmd->suspend_time = cpu_to_le32(scan_timing[params->type].suspend_time);
867 cmd->scan_prio = cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6);
870 static inline bool iwl_mvm_scan_fits(struct iwl_mvm *mvm, int n_ssids,
871 struct ieee80211_scan_ies *ies,
874 return ((n_ssids <= PROBE_OPTION_MAX) &&
875 (n_channels <= mvm->fw->ucode_capa.n_scan_channels) &
876 (ies->common_ie_len +
877 ies->len[NL80211_BAND_2GHZ] +
878 ies->len[NL80211_BAND_5GHZ] <=
879 iwl_mvm_max_scan_ie_fw_cmd_room(mvm)));
882 static inline bool iwl_mvm_scan_use_ebs(struct iwl_mvm *mvm,
883 struct ieee80211_vif *vif)
885 const struct iwl_ucode_capabilities *capa = &mvm->fw->ucode_capa;
888 if (iwl_mvm_is_cdb_supported(mvm))
889 low_latency = iwl_mvm_low_latency_band(mvm, NL80211_BAND_5GHZ);
891 low_latency = iwl_mvm_low_latency(mvm);
893 /* We can only use EBS if:
894 * 1. the feature is supported;
895 * 2. the last EBS was successful;
896 * 3. if only single scan, the single scan EBS API is supported;
897 * 4. it's not a p2p find operation.
898 * 5. we are not in low latency mode,
899 * or if fragmented ebs is supported by the FW
901 return ((capa->flags & IWL_UCODE_TLV_FLAGS_EBS_SUPPORT) &&
902 mvm->last_ebs_successful && IWL_MVM_ENABLE_EBS &&
903 vif->type != NL80211_IFTYPE_P2P_DEVICE &&
904 (!low_latency || iwl_mvm_is_frag_ebs_supported(mvm)));
907 static inline bool iwl_mvm_is_regular_scan(struct iwl_mvm_scan_params *params)
909 return params->n_scan_plans == 1 &&
910 params->scan_plans[0].iterations == 1;
913 static bool iwl_mvm_is_scan_fragmented(enum iwl_mvm_scan_type type)
915 return (type == IWL_SCAN_TYPE_FRAGMENTED ||
916 type == IWL_SCAN_TYPE_FAST_BALANCE);
919 static int iwl_mvm_scan_lmac_flags(struct iwl_mvm *mvm,
920 struct iwl_mvm_scan_params *params,
921 struct ieee80211_vif *vif)
925 if (params->n_ssids == 0)
926 flags |= IWL_MVM_LMAC_SCAN_FLAG_PASSIVE;
928 if (params->n_ssids == 1 && params->ssids[0].ssid_len != 0)
929 flags |= IWL_MVM_LMAC_SCAN_FLAG_PRE_CONNECTION;
931 if (iwl_mvm_is_scan_fragmented(params->type))
932 flags |= IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED;
934 if (iwl_mvm_rrm_scan_needed(mvm) &&
935 fw_has_capa(&mvm->fw->ucode_capa,
936 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
937 flags |= IWL_MVM_LMAC_SCAN_FLAGS_RRM_ENABLED;
939 if (params->pass_all)
940 flags |= IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL;
942 flags |= IWL_MVM_LMAC_SCAN_FLAG_MATCH;
944 #ifdef CONFIG_IWLWIFI_DEBUGFS
945 if (mvm->scan_iter_notif_enabled)
946 flags |= IWL_MVM_LMAC_SCAN_FLAG_ITER_COMPLETE;
949 if (mvm->sched_scan_pass_all == SCHED_SCAN_PASS_ALL_ENABLED)
950 flags |= IWL_MVM_LMAC_SCAN_FLAG_ITER_COMPLETE;
952 if (iwl_mvm_is_regular_scan(params) &&
953 vif->type != NL80211_IFTYPE_P2P_DEVICE &&
954 !iwl_mvm_is_scan_fragmented(params->type))
955 flags |= IWL_MVM_LMAC_SCAN_FLAG_EXTENDED_DWELL;
960 static int iwl_mvm_scan_lmac(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
961 struct iwl_mvm_scan_params *params)
963 struct iwl_scan_req_lmac *cmd = mvm->scan_cmd;
964 struct iwl_scan_probe_req *preq =
965 (void *)(cmd->data + sizeof(struct iwl_scan_channel_cfg_lmac) *
966 mvm->fw->ucode_capa.n_scan_channels);
970 lockdep_assert_held(&mvm->mutex);
972 memset(cmd, 0, ksize(cmd));
974 if (WARN_ON(params->n_scan_plans > IWL_MAX_SCHED_SCAN_PLANS))
977 iwl_mvm_scan_lmac_dwell(mvm, cmd, params);
979 cmd->rx_chain_select = iwl_mvm_scan_rx_chain(mvm);
980 cmd->iter_num = cpu_to_le32(1);
981 cmd->n_channels = (u8)params->n_channels;
983 cmd->delay = cpu_to_le32(params->delay);
985 cmd->scan_flags = cpu_to_le32(iwl_mvm_scan_lmac_flags(mvm, params,
988 cmd->flags = iwl_mvm_scan_rxon_flags(params->channels[0]->band);
989 cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP |
990 MAC_FILTER_IN_BEACON);
991 iwl_mvm_scan_fill_tx_cmd(mvm, cmd->tx_cmd, params->no_cck);
992 iwl_scan_build_ssids(params, cmd->direct_scan, &ssid_bitmap);
994 /* this API uses bits 1-20 instead of 0-19 */
997 for (i = 0; i < params->n_scan_plans; i++) {
998 struct cfg80211_sched_scan_plan *scan_plan =
999 ¶ms->scan_plans[i];
1001 cmd->schedule[i].delay =
1002 cpu_to_le16(scan_plan->interval);
1003 cmd->schedule[i].iterations = scan_plan->iterations;
1004 cmd->schedule[i].full_scan_mul = 1;
1008 * If the number of iterations of the last scan plan is set to
1009 * zero, it should run infinitely. However, this is not always the case.
1010 * For example, when regular scan is requested the driver sets one scan
1011 * plan with one iteration.
1013 if (!cmd->schedule[i - 1].iterations)
1014 cmd->schedule[i - 1].iterations = 0xff;
1016 if (iwl_mvm_scan_use_ebs(mvm, vif)) {
1017 cmd->channel_opt[0].flags =
1018 cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS |
1019 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
1020 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD);
1021 cmd->channel_opt[0].non_ebs_ratio =
1022 cpu_to_le16(IWL_DENSE_EBS_SCAN_RATIO);
1023 cmd->channel_opt[1].flags =
1024 cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS |
1025 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
1026 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD);
1027 cmd->channel_opt[1].non_ebs_ratio =
1028 cpu_to_le16(IWL_SPARSE_EBS_SCAN_RATIO);
1031 iwl_mvm_lmac_scan_cfg_channels(mvm, params->channels,
1032 params->n_channels, ssid_bitmap, cmd);
1034 *preq = params->preq;
1039 static int rate_to_scan_rate_flag(unsigned int rate)
1041 static const int rate_to_scan_rate[IWL_RATE_COUNT] = {
1042 [IWL_RATE_1M_INDEX] = SCAN_CONFIG_RATE_1M,
1043 [IWL_RATE_2M_INDEX] = SCAN_CONFIG_RATE_2M,
1044 [IWL_RATE_5M_INDEX] = SCAN_CONFIG_RATE_5M,
1045 [IWL_RATE_11M_INDEX] = SCAN_CONFIG_RATE_11M,
1046 [IWL_RATE_6M_INDEX] = SCAN_CONFIG_RATE_6M,
1047 [IWL_RATE_9M_INDEX] = SCAN_CONFIG_RATE_9M,
1048 [IWL_RATE_12M_INDEX] = SCAN_CONFIG_RATE_12M,
1049 [IWL_RATE_18M_INDEX] = SCAN_CONFIG_RATE_18M,
1050 [IWL_RATE_24M_INDEX] = SCAN_CONFIG_RATE_24M,
1051 [IWL_RATE_36M_INDEX] = SCAN_CONFIG_RATE_36M,
1052 [IWL_RATE_48M_INDEX] = SCAN_CONFIG_RATE_48M,
1053 [IWL_RATE_54M_INDEX] = SCAN_CONFIG_RATE_54M,
1056 return rate_to_scan_rate[rate];
1059 static __le32 iwl_mvm_scan_config_rates(struct iwl_mvm *mvm)
1061 struct ieee80211_supported_band *band;
1062 unsigned int rates = 0;
1065 band = &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
1066 for (i = 0; i < band->n_bitrates; i++)
1067 rates |= rate_to_scan_rate_flag(band->bitrates[i].hw_value);
1068 band = &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
1069 for (i = 0; i < band->n_bitrates; i++)
1070 rates |= rate_to_scan_rate_flag(band->bitrates[i].hw_value);
1072 /* Set both basic rates and supported rates */
1073 rates |= SCAN_CONFIG_SUPPORTED_RATE(rates);
1075 return cpu_to_le32(rates);
1078 static void iwl_mvm_fill_scan_dwell(struct iwl_mvm *mvm,
1079 struct iwl_scan_dwell *dwell)
1081 dwell->active = IWL_SCAN_DWELL_ACTIVE;
1082 dwell->passive = IWL_SCAN_DWELL_PASSIVE;
1083 dwell->fragmented = IWL_SCAN_DWELL_FRAGMENTED;
1084 dwell->extended = IWL_SCAN_DWELL_EXTENDED;
1087 static void iwl_mvm_fill_channels(struct iwl_mvm *mvm, u8 *channels,
1090 struct ieee80211_supported_band *band;
1093 band = &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
1094 for (i = 0; i < band->n_channels && j < max_channels; i++, j++)
1095 channels[j] = band->channels[i].hw_value;
1096 band = &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
1097 for (i = 0; i < band->n_channels && j < max_channels; i++, j++)
1098 channels[j] = band->channels[i].hw_value;
1101 static void iwl_mvm_fill_scan_config_v1(struct iwl_mvm *mvm, void *config,
1102 u32 flags, u8 channel_flags,
1105 enum iwl_mvm_scan_type type = iwl_mvm_get_scan_type(mvm, NULL);
1106 struct iwl_scan_config_v1 *cfg = config;
1108 cfg->flags = cpu_to_le32(flags);
1109 cfg->tx_chains = cpu_to_le32(iwl_mvm_get_valid_tx_ant(mvm));
1110 cfg->rx_chains = cpu_to_le32(iwl_mvm_scan_rx_ant(mvm));
1111 cfg->legacy_rates = iwl_mvm_scan_config_rates(mvm);
1112 cfg->out_of_channel_time = cpu_to_le32(scan_timing[type].max_out_time);
1113 cfg->suspend_time = cpu_to_le32(scan_timing[type].suspend_time);
1115 iwl_mvm_fill_scan_dwell(mvm, &cfg->dwell);
1117 memcpy(&cfg->mac_addr, &mvm->addresses[0].addr, ETH_ALEN);
1119 cfg->bcast_sta_id = mvm->aux_sta.sta_id;
1120 cfg->channel_flags = channel_flags;
1122 iwl_mvm_fill_channels(mvm, cfg->channel_array, max_channels);
1125 static void iwl_mvm_fill_scan_config(struct iwl_mvm *mvm, void *config,
1126 u32 flags, u8 channel_flags,
1129 struct iwl_scan_config *cfg = config;
1131 cfg->flags = cpu_to_le32(flags);
1132 cfg->tx_chains = cpu_to_le32(iwl_mvm_get_valid_tx_ant(mvm));
1133 cfg->rx_chains = cpu_to_le32(iwl_mvm_scan_rx_ant(mvm));
1134 cfg->legacy_rates = iwl_mvm_scan_config_rates(mvm);
1136 if (iwl_mvm_is_cdb_supported(mvm)) {
1137 enum iwl_mvm_scan_type lb_type, hb_type;
1139 lb_type = iwl_mvm_get_scan_type_band(mvm, NULL,
1141 hb_type = iwl_mvm_get_scan_type_band(mvm, NULL,
1144 cfg->out_of_channel_time[SCAN_LB_LMAC_IDX] =
1145 cpu_to_le32(scan_timing[lb_type].max_out_time);
1146 cfg->suspend_time[SCAN_LB_LMAC_IDX] =
1147 cpu_to_le32(scan_timing[lb_type].suspend_time);
1149 cfg->out_of_channel_time[SCAN_HB_LMAC_IDX] =
1150 cpu_to_le32(scan_timing[hb_type].max_out_time);
1151 cfg->suspend_time[SCAN_HB_LMAC_IDX] =
1152 cpu_to_le32(scan_timing[hb_type].suspend_time);
1154 enum iwl_mvm_scan_type type =
1155 iwl_mvm_get_scan_type(mvm, NULL);
1157 cfg->out_of_channel_time[SCAN_LB_LMAC_IDX] =
1158 cpu_to_le32(scan_timing[type].max_out_time);
1159 cfg->suspend_time[SCAN_LB_LMAC_IDX] =
1160 cpu_to_le32(scan_timing[type].suspend_time);
1163 iwl_mvm_fill_scan_dwell(mvm, &cfg->dwell);
1165 memcpy(&cfg->mac_addr, &mvm->addresses[0].addr, ETH_ALEN);
1167 cfg->bcast_sta_id = mvm->aux_sta.sta_id;
1168 cfg->channel_flags = channel_flags;
1170 iwl_mvm_fill_channels(mvm, cfg->channel_array, max_channels);
1173 int iwl_mvm_config_scan(struct iwl_mvm *mvm)
1177 struct iwl_host_cmd cmd = {
1178 .id = iwl_cmd_id(SCAN_CFG_CMD, IWL_ALWAYS_LONG_GROUP, 0),
1180 enum iwl_mvm_scan_type type;
1181 enum iwl_mvm_scan_type hb_type = IWL_SCAN_TYPE_NOT_SET;
1183 mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels +
1184 mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels;
1188 if (WARN_ON(num_channels > mvm->fw->ucode_capa.n_scan_channels))
1189 num_channels = mvm->fw->ucode_capa.n_scan_channels;
1191 if (iwl_mvm_is_cdb_supported(mvm)) {
1192 type = iwl_mvm_get_scan_type_band(mvm, NULL,
1194 hb_type = iwl_mvm_get_scan_type_band(mvm, NULL,
1196 if (type == mvm->scan_type && hb_type == mvm->hb_scan_type)
1199 type = iwl_mvm_get_scan_type(mvm, NULL);
1200 if (type == mvm->scan_type)
1204 if (iwl_mvm_cdb_scan_api(mvm))
1205 cmd_size = sizeof(struct iwl_scan_config);
1207 cmd_size = sizeof(struct iwl_scan_config_v1);
1208 cmd_size += mvm->fw->ucode_capa.n_scan_channels;
1210 cfg = kzalloc(cmd_size, GFP_KERNEL);
1214 flags = SCAN_CONFIG_FLAG_ACTIVATE |
1215 SCAN_CONFIG_FLAG_ALLOW_CHUB_REQS |
1216 SCAN_CONFIG_FLAG_SET_TX_CHAINS |
1217 SCAN_CONFIG_FLAG_SET_RX_CHAINS |
1218 SCAN_CONFIG_FLAG_SET_AUX_STA_ID |
1219 SCAN_CONFIG_FLAG_SET_ALL_TIMES |
1220 SCAN_CONFIG_FLAG_SET_LEGACY_RATES |
1221 SCAN_CONFIG_FLAG_SET_MAC_ADDR |
1222 SCAN_CONFIG_FLAG_SET_CHANNEL_FLAGS |
1223 SCAN_CONFIG_N_CHANNELS(num_channels) |
1224 (iwl_mvm_is_scan_fragmented(type) ?
1225 SCAN_CONFIG_FLAG_SET_FRAGMENTED :
1226 SCAN_CONFIG_FLAG_CLEAR_FRAGMENTED);
1228 channel_flags = IWL_CHANNEL_FLAG_EBS |
1229 IWL_CHANNEL_FLAG_ACCURATE_EBS |
1230 IWL_CHANNEL_FLAG_EBS_ADD |
1231 IWL_CHANNEL_FLAG_PRE_SCAN_PASSIVE2ACTIVE;
1234 * Check for fragmented scan on LMAC2 - high band.
1235 * LMAC1 - low band is checked above.
1237 if (iwl_mvm_cdb_scan_api(mvm)) {
1238 if (iwl_mvm_is_cdb_supported(mvm))
1239 flags |= (iwl_mvm_is_scan_fragmented(hb_type)) ?
1240 SCAN_CONFIG_FLAG_SET_LMAC2_FRAGMENTED :
1241 SCAN_CONFIG_FLAG_CLEAR_LMAC2_FRAGMENTED;
1242 iwl_mvm_fill_scan_config(mvm, cfg, flags, channel_flags,
1245 iwl_mvm_fill_scan_config_v1(mvm, cfg, flags, channel_flags,
1250 cmd.len[0] = cmd_size;
1251 cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
1253 IWL_DEBUG_SCAN(mvm, "Sending UMAC scan config\n");
1255 ret = iwl_mvm_send_cmd(mvm, &cmd);
1257 mvm->scan_type = type;
1258 mvm->hb_scan_type = hb_type;
1265 static int iwl_mvm_scan_uid_by_status(struct iwl_mvm *mvm, int status)
1269 for (i = 0; i < mvm->max_scans; i++)
1270 if (mvm->scan_uid_status[i] == status)
1276 static void iwl_mvm_scan_umac_dwell(struct iwl_mvm *mvm,
1277 struct iwl_scan_req_umac *cmd,
1278 struct iwl_mvm_scan_params *params)
1280 struct iwl_mvm_scan_timing_params *timing, *hb_timing;
1281 u8 active_dwell, passive_dwell;
1283 timing = &scan_timing[params->type];
1284 active_dwell = params->measurement_dwell ?
1285 params->measurement_dwell : IWL_SCAN_DWELL_ACTIVE;
1286 passive_dwell = params->measurement_dwell ?
1287 params->measurement_dwell : IWL_SCAN_DWELL_PASSIVE;
1289 if (iwl_mvm_is_adaptive_dwell_supported(mvm)) {
1290 cmd->v7.adwell_default_n_aps_social =
1291 IWL_SCAN_ADWELL_DEFAULT_N_APS_SOCIAL;
1292 cmd->v7.adwell_default_n_aps =
1293 IWL_SCAN_ADWELL_DEFAULT_LB_N_APS;
1295 if (iwl_mvm_is_adwell_hb_ap_num_supported(mvm))
1296 cmd->v9.adwell_default_hb_n_aps =
1297 IWL_SCAN_ADWELL_DEFAULT_HB_N_APS;
1299 /* if custom max budget was configured with debugfs */
1300 if (IWL_MVM_ADWELL_MAX_BUDGET)
1301 cmd->v7.adwell_max_budget =
1302 cpu_to_le16(IWL_MVM_ADWELL_MAX_BUDGET);
1303 else if (params->ssids && params->ssids[0].ssid_len)
1304 cmd->v7.adwell_max_budget =
1305 cpu_to_le16(IWL_SCAN_ADWELL_MAX_BUDGET_DIRECTED_SCAN);
1307 cmd->v7.adwell_max_budget =
1308 cpu_to_le16(IWL_SCAN_ADWELL_MAX_BUDGET_FULL_SCAN);
1310 cmd->v7.scan_priority = cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6);
1311 cmd->v7.max_out_time[SCAN_LB_LMAC_IDX] =
1312 cpu_to_le32(timing->max_out_time);
1313 cmd->v7.suspend_time[SCAN_LB_LMAC_IDX] =
1314 cpu_to_le32(timing->suspend_time);
1316 if (iwl_mvm_is_cdb_supported(mvm)) {
1317 hb_timing = &scan_timing[params->hb_type];
1319 cmd->v7.max_out_time[SCAN_HB_LMAC_IDX] =
1320 cpu_to_le32(hb_timing->max_out_time);
1321 cmd->v7.suspend_time[SCAN_HB_LMAC_IDX] =
1322 cpu_to_le32(hb_timing->suspend_time);
1325 if (!iwl_mvm_is_adaptive_dwell_v2_supported(mvm)) {
1326 cmd->v7.active_dwell = active_dwell;
1327 cmd->v7.passive_dwell = passive_dwell;
1328 cmd->v7.fragmented_dwell = IWL_SCAN_DWELL_FRAGMENTED;
1330 cmd->v8.active_dwell[SCAN_LB_LMAC_IDX] = active_dwell;
1331 cmd->v8.passive_dwell[SCAN_LB_LMAC_IDX] = passive_dwell;
1332 if (iwl_mvm_is_cdb_supported(mvm)) {
1333 cmd->v8.active_dwell[SCAN_HB_LMAC_IDX] =
1335 cmd->v8.passive_dwell[SCAN_HB_LMAC_IDX] =
1340 cmd->v1.extended_dwell = params->measurement_dwell ?
1341 params->measurement_dwell : IWL_SCAN_DWELL_EXTENDED;
1342 cmd->v1.active_dwell = active_dwell;
1343 cmd->v1.passive_dwell = passive_dwell;
1344 cmd->v1.fragmented_dwell = IWL_SCAN_DWELL_FRAGMENTED;
1346 if (iwl_mvm_is_cdb_supported(mvm)) {
1347 hb_timing = &scan_timing[params->hb_type];
1349 cmd->v6.max_out_time[SCAN_HB_LMAC_IDX] =
1350 cpu_to_le32(hb_timing->max_out_time);
1351 cmd->v6.suspend_time[SCAN_HB_LMAC_IDX] =
1352 cpu_to_le32(hb_timing->suspend_time);
1355 if (iwl_mvm_cdb_scan_api(mvm)) {
1356 cmd->v6.scan_priority =
1357 cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6);
1358 cmd->v6.max_out_time[SCAN_LB_LMAC_IDX] =
1359 cpu_to_le32(timing->max_out_time);
1360 cmd->v6.suspend_time[SCAN_LB_LMAC_IDX] =
1361 cpu_to_le32(timing->suspend_time);
1363 cmd->v1.scan_priority =
1364 cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6);
1365 cmd->v1.max_out_time =
1366 cpu_to_le32(timing->max_out_time);
1367 cmd->v1.suspend_time =
1368 cpu_to_le32(timing->suspend_time);
1372 if (iwl_mvm_is_regular_scan(params))
1373 cmd->ooc_priority = cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6);
1375 cmd->ooc_priority = cpu_to_le32(IWL_SCAN_PRIORITY_EXT_2);
1379 iwl_mvm_umac_scan_cfg_channels(struct iwl_mvm *mvm,
1380 struct ieee80211_channel **channels,
1381 int n_channels, u32 ssid_bitmap,
1382 struct iwl_scan_channel_cfg_umac *channel_cfg)
1386 for (i = 0; i < n_channels; i++) {
1387 channel_cfg[i].flags = cpu_to_le32(ssid_bitmap);
1388 channel_cfg[i].channel_num = channels[i]->hw_value;
1389 channel_cfg[i].iter_count = 1;
1390 channel_cfg[i].iter_interval = 0;
1394 static u16 iwl_mvm_scan_umac_flags(struct iwl_mvm *mvm,
1395 struct iwl_mvm_scan_params *params,
1396 struct ieee80211_vif *vif)
1400 if (params->n_ssids == 0)
1401 flags = IWL_UMAC_SCAN_GEN_FLAGS_PASSIVE;
1403 if (params->n_ssids == 1 && params->ssids[0].ssid_len != 0)
1404 flags |= IWL_UMAC_SCAN_GEN_FLAGS_PRE_CONNECT;
1406 if (iwl_mvm_is_scan_fragmented(params->type))
1407 flags |= IWL_UMAC_SCAN_GEN_FLAGS_FRAGMENTED;
1409 if (iwl_mvm_is_cdb_supported(mvm) &&
1410 iwl_mvm_is_scan_fragmented(params->hb_type))
1411 flags |= IWL_UMAC_SCAN_GEN_FLAGS_LMAC2_FRAGMENTED;
1413 if (iwl_mvm_rrm_scan_needed(mvm) &&
1414 fw_has_capa(&mvm->fw->ucode_capa,
1415 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
1416 flags |= IWL_UMAC_SCAN_GEN_FLAGS_RRM_ENABLED;
1418 if (params->pass_all)
1419 flags |= IWL_UMAC_SCAN_GEN_FLAGS_PASS_ALL;
1421 flags |= IWL_UMAC_SCAN_GEN_FLAGS_MATCH;
1423 if (!iwl_mvm_is_regular_scan(params))
1424 flags |= IWL_UMAC_SCAN_GEN_FLAGS_PERIODIC;
1426 if (params->measurement_dwell)
1427 flags |= IWL_UMAC_SCAN_GEN_FLAGS_ITER_COMPLETE;
1429 #ifdef CONFIG_IWLWIFI_DEBUGFS
1430 if (mvm->scan_iter_notif_enabled)
1431 flags |= IWL_UMAC_SCAN_GEN_FLAGS_ITER_COMPLETE;
1434 if (mvm->sched_scan_pass_all == SCHED_SCAN_PASS_ALL_ENABLED)
1435 flags |= IWL_UMAC_SCAN_GEN_FLAGS_ITER_COMPLETE;
1437 if (iwl_mvm_is_adaptive_dwell_supported(mvm) && IWL_MVM_ADWELL_ENABLE &&
1438 vif->type != NL80211_IFTYPE_P2P_DEVICE)
1439 flags |= IWL_UMAC_SCAN_GEN_FLAGS_ADAPTIVE_DWELL;
1442 * Extended dwell is relevant only for low band to start with, as it is
1443 * being used for social channles only (1, 6, 11), so we can check
1444 * only scan type on low band also for CDB.
1446 if (iwl_mvm_is_regular_scan(params) &&
1447 vif->type != NL80211_IFTYPE_P2P_DEVICE &&
1448 !iwl_mvm_is_scan_fragmented(params->type) &&
1449 !iwl_mvm_is_adaptive_dwell_supported(mvm) &&
1450 !iwl_mvm_is_oce_supported(mvm))
1451 flags |= IWL_UMAC_SCAN_GEN_FLAGS_EXTENDED_DWELL;
1453 if (iwl_mvm_is_oce_supported(mvm)) {
1454 if ((params->flags &
1455 NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE))
1456 flags |= IWL_UMAC_SCAN_GEN_FLAGS_PROB_REQ_HIGH_TX_RATE;
1457 /* Since IWL_UMAC_SCAN_GEN_FLAGS_EXTENDED_DWELL and
1458 * NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION shares
1459 * the same bit, we need to make sure that we use this bit here
1460 * only when IWL_UMAC_SCAN_GEN_FLAGS_EXTENDED_DWELL cannot be
1462 if ((params->flags &
1463 NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) &&
1464 !WARN_ON_ONCE(!iwl_mvm_is_adaptive_dwell_supported(mvm)))
1465 flags |= IWL_UMAC_SCAN_GEN_FLAGS_PROB_REQ_DEFER_SUPP;
1466 if ((params->flags & NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME))
1467 flags |= IWL_UMAC_SCAN_GEN_FLAGS_MAX_CHNL_TIME;
1473 static int iwl_mvm_scan_umac(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1474 struct iwl_mvm_scan_params *params,
1477 struct iwl_scan_req_umac *cmd = mvm->scan_cmd;
1478 struct iwl_scan_umac_chan_param *chan_param;
1479 void *cmd_data = iwl_mvm_get_scan_req_umac_data(mvm);
1480 struct iwl_scan_req_umac_tail *sec_part = cmd_data +
1481 sizeof(struct iwl_scan_channel_cfg_umac) *
1482 mvm->fw->ucode_capa.n_scan_channels;
1484 u32 ssid_bitmap = 0;
1485 u8 channel_flags = 0;
1487 struct iwl_mvm_vif *scan_vif = iwl_mvm_vif_from_mac80211(vif);
1489 chan_param = iwl_mvm_get_scan_req_umac_channel(mvm);
1491 lockdep_assert_held(&mvm->mutex);
1493 if (WARN_ON(params->n_scan_plans > IWL_MAX_SCHED_SCAN_PLANS))
1496 uid = iwl_mvm_scan_uid_by_status(mvm, 0);
1500 memset(cmd, 0, ksize(cmd));
1502 iwl_mvm_scan_umac_dwell(mvm, cmd, params);
1504 mvm->scan_uid_status[uid] = type;
1506 cmd->uid = cpu_to_le32(uid);
1507 gen_flags = iwl_mvm_scan_umac_flags(mvm, params, vif);
1508 cmd->general_flags = cpu_to_le16(gen_flags);
1509 if (iwl_mvm_is_adaptive_dwell_v2_supported(mvm)) {
1510 if (gen_flags & IWL_UMAC_SCAN_GEN_FLAGS_FRAGMENTED)
1511 cmd->v8.num_of_fragments[SCAN_LB_LMAC_IDX] =
1512 IWL_SCAN_NUM_OF_FRAGS;
1513 if (gen_flags & IWL_UMAC_SCAN_GEN_FLAGS_LMAC2_FRAGMENTED)
1514 cmd->v8.num_of_fragments[SCAN_HB_LMAC_IDX] =
1515 IWL_SCAN_NUM_OF_FRAGS;
1517 cmd->v8.general_flags2 =
1518 IWL_UMAC_SCAN_GEN_FLAGS2_ALLOW_CHNL_REORDER;
1521 cmd->scan_start_mac_id = scan_vif->id;
1523 if (type == IWL_MVM_SCAN_SCHED || type == IWL_MVM_SCAN_NETDETECT)
1524 cmd->flags = cpu_to_le32(IWL_UMAC_SCAN_FLAG_PREEMPTIVE);
1526 if (iwl_mvm_scan_use_ebs(mvm, vif)) {
1527 channel_flags = IWL_SCAN_CHANNEL_FLAG_EBS |
1528 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
1529 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD;
1531 /* set fragmented ebs for fragmented scan on HB channels */
1532 if (iwl_mvm_is_frag_ebs_supported(mvm)) {
1534 IWL_UMAC_SCAN_GEN_FLAGS_LMAC2_FRAGMENTED ||
1535 (!iwl_mvm_is_cdb_supported(mvm) &&
1536 gen_flags & IWL_UMAC_SCAN_GEN_FLAGS_FRAGMENTED))
1537 channel_flags |= IWL_SCAN_CHANNEL_FLAG_EBS_FRAG;
1541 chan_param->flags = channel_flags;
1542 chan_param->count = params->n_channels;
1544 iwl_scan_build_ssids(params, sec_part->direct_scan, &ssid_bitmap);
1546 iwl_mvm_umac_scan_cfg_channels(mvm, params->channels,
1547 params->n_channels, ssid_bitmap,
1550 for (i = 0; i < params->n_scan_plans; i++) {
1551 struct cfg80211_sched_scan_plan *scan_plan =
1552 ¶ms->scan_plans[i];
1554 sec_part->schedule[i].iter_count = scan_plan->iterations;
1555 sec_part->schedule[i].interval =
1556 cpu_to_le16(scan_plan->interval);
1560 * If the number of iterations of the last scan plan is set to
1561 * zero, it should run infinitely. However, this is not always the case.
1562 * For example, when regular scan is requested the driver sets one scan
1563 * plan with one iteration.
1565 if (!sec_part->schedule[i - 1].iter_count)
1566 sec_part->schedule[i - 1].iter_count = 0xff;
1568 sec_part->delay = cpu_to_le16(params->delay);
1569 sec_part->preq = params->preq;
1574 static int iwl_mvm_num_scans(struct iwl_mvm *mvm)
1576 return hweight32(mvm->scan_status & IWL_MVM_SCAN_MASK);
1579 static int iwl_mvm_check_running_scans(struct iwl_mvm *mvm, int type)
1581 bool unified_image = fw_has_capa(&mvm->fw->ucode_capa,
1582 IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG);
1584 /* This looks a bit arbitrary, but the idea is that if we run
1585 * out of possible simultaneous scans and the userspace is
1586 * trying to run a scan type that is already running, we
1587 * return -EBUSY. But if the userspace wants to start a
1588 * different type of scan, we stop the opposite type to make
1589 * space for the new request. The reason is backwards
1590 * compatibility with old wpa_supplicant that wouldn't stop a
1591 * scheduled scan before starting a normal scan.
1594 /* FW supports only a single periodic scan */
1595 if ((type == IWL_MVM_SCAN_SCHED || type == IWL_MVM_SCAN_NETDETECT) &&
1596 mvm->scan_status & (IWL_MVM_SCAN_SCHED | IWL_MVM_SCAN_NETDETECT))
1599 if (iwl_mvm_num_scans(mvm) < mvm->max_scans)
1602 /* Use a switch, even though this is a bitmask, so that more
1603 * than one bits set will fall in default and we will warn.
1606 case IWL_MVM_SCAN_REGULAR:
1607 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR_MASK)
1609 return iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
1610 case IWL_MVM_SCAN_SCHED:
1611 if (mvm->scan_status & IWL_MVM_SCAN_SCHED_MASK)
1613 return iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
1614 case IWL_MVM_SCAN_NETDETECT:
1615 /* For non-unified images, there's no need to stop
1616 * anything for net-detect since the firmware is
1617 * restarted anyway. This way, any sched scans that
1618 * were running will be restarted when we resume.
1623 /* If this is a unified image and we ran out of scans,
1624 * we need to stop something. Prefer stopping regular
1625 * scans, because the results are useless at this
1626 * point, and we should be able to keep running
1627 * another scheduled scan while suspended.
1629 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR_MASK)
1630 return iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR,
1632 if (mvm->scan_status & IWL_MVM_SCAN_SCHED_MASK)
1633 return iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED,
1635 /* Something is wrong if no scan was running but we
1647 #define SCAN_TIMEOUT 20000
1649 void iwl_mvm_scan_timeout_wk(struct work_struct *work)
1651 struct delayed_work *delayed_work = to_delayed_work(work);
1652 struct iwl_mvm *mvm = container_of(delayed_work, struct iwl_mvm,
1653 scan_timeout_dwork);
1655 IWL_ERR(mvm, "regular scan timed out\n");
1657 iwl_force_nmi(mvm->trans);
1660 static void iwl_mvm_fill_scan_type(struct iwl_mvm *mvm,
1661 struct iwl_mvm_scan_params *params,
1662 struct ieee80211_vif *vif)
1664 if (iwl_mvm_is_cdb_supported(mvm)) {
1666 iwl_mvm_get_scan_type_band(mvm, vif,
1669 iwl_mvm_get_scan_type_band(mvm, vif,
1672 params->type = iwl_mvm_get_scan_type(mvm, vif);
1676 int iwl_mvm_reg_scan_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1677 struct cfg80211_scan_request *req,
1678 struct ieee80211_scan_ies *ies)
1680 struct iwl_host_cmd hcmd = {
1681 .len = { iwl_mvm_scan_size(mvm), },
1682 .data = { mvm->scan_cmd, },
1683 .dataflags = { IWL_HCMD_DFL_NOCOPY, },
1685 struct iwl_mvm_scan_params params = {};
1687 struct cfg80211_sched_scan_plan scan_plan = { .iterations = 1 };
1689 lockdep_assert_held(&mvm->mutex);
1691 if (iwl_mvm_is_lar_supported(mvm) && !mvm->lar_regdom_set) {
1692 IWL_ERR(mvm, "scan while LAR regdomain is not set\n");
1696 ret = iwl_mvm_check_running_scans(mvm, IWL_MVM_SCAN_REGULAR);
1700 /* we should have failed registration if scan_cmd was NULL */
1701 if (WARN_ON(!mvm->scan_cmd))
1704 if (!iwl_mvm_scan_fits(mvm, req->n_ssids, ies, req->n_channels))
1707 params.n_ssids = req->n_ssids;
1708 params.flags = req->flags;
1709 params.n_channels = req->n_channels;
1711 params.ssids = req->ssids;
1712 params.channels = req->channels;
1713 params.mac_addr = req->mac_addr;
1714 params.mac_addr_mask = req->mac_addr_mask;
1715 params.no_cck = req->no_cck;
1716 params.pass_all = true;
1717 params.n_match_sets = 0;
1718 params.match_sets = NULL;
1720 params.scan_plans = &scan_plan;
1721 params.n_scan_plans = 1;
1723 iwl_mvm_fill_scan_type(mvm, ¶ms, vif);
1725 ret = iwl_mvm_get_measurement_dwell(mvm, req, ¶ms);
1729 params.measurement_dwell = ret;
1731 iwl_mvm_build_scan_probe(mvm, vif, ies, ¶ms);
1733 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
1734 hcmd.id = iwl_cmd_id(SCAN_REQ_UMAC, IWL_ALWAYS_LONG_GROUP, 0);
1735 ret = iwl_mvm_scan_umac(mvm, vif, ¶ms,
1736 IWL_MVM_SCAN_REGULAR);
1738 hcmd.id = SCAN_OFFLOAD_REQUEST_CMD;
1739 ret = iwl_mvm_scan_lmac(mvm, vif, ¶ms);
1745 iwl_mvm_pause_tcm(mvm, false);
1747 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1749 /* If the scan failed, it usually means that the FW was unable
1750 * to allocate the time events. Warn on it, but maybe we
1751 * should try to send the command again with different params.
1753 IWL_ERR(mvm, "Scan failed! ret %d\n", ret);
1754 iwl_mvm_resume_tcm(mvm);
1758 IWL_DEBUG_SCAN(mvm, "Scan request was sent successfully\n");
1759 mvm->scan_status |= IWL_MVM_SCAN_REGULAR;
1760 mvm->scan_vif = iwl_mvm_vif_from_mac80211(vif);
1761 iwl_mvm_ref(mvm, IWL_MVM_REF_SCAN);
1763 schedule_delayed_work(&mvm->scan_timeout_dwork,
1764 msecs_to_jiffies(SCAN_TIMEOUT));
1769 int iwl_mvm_sched_scan_start(struct iwl_mvm *mvm,
1770 struct ieee80211_vif *vif,
1771 struct cfg80211_sched_scan_request *req,
1772 struct ieee80211_scan_ies *ies,
1775 struct iwl_host_cmd hcmd = {
1776 .len = { iwl_mvm_scan_size(mvm), },
1777 .data = { mvm->scan_cmd, },
1778 .dataflags = { IWL_HCMD_DFL_NOCOPY, },
1780 struct iwl_mvm_scan_params params = {};
1783 lockdep_assert_held(&mvm->mutex);
1785 if (iwl_mvm_is_lar_supported(mvm) && !mvm->lar_regdom_set) {
1786 IWL_ERR(mvm, "sched-scan while LAR regdomain is not set\n");
1790 ret = iwl_mvm_check_running_scans(mvm, type);
1794 /* we should have failed registration if scan_cmd was NULL */
1795 if (WARN_ON(!mvm->scan_cmd))
1798 if (!iwl_mvm_scan_fits(mvm, req->n_ssids, ies, req->n_channels))
1801 params.n_ssids = req->n_ssids;
1802 params.flags = req->flags;
1803 params.n_channels = req->n_channels;
1804 params.ssids = req->ssids;
1805 params.channels = req->channels;
1806 params.mac_addr = req->mac_addr;
1807 params.mac_addr_mask = req->mac_addr_mask;
1808 params.no_cck = false;
1809 params.pass_all = iwl_mvm_scan_pass_all(mvm, req);
1810 params.n_match_sets = req->n_match_sets;
1811 params.match_sets = req->match_sets;
1812 if (!req->n_scan_plans)
1815 params.n_scan_plans = req->n_scan_plans;
1816 params.scan_plans = req->scan_plans;
1818 iwl_mvm_fill_scan_type(mvm, ¶ms, vif);
1820 /* In theory, LMAC scans can handle a 32-bit delay, but since
1821 * waiting for over 18 hours to start the scan is a bit silly
1822 * and to keep it aligned with UMAC scans (which only support
1823 * 16-bit delays), trim it down to 16-bits.
1825 if (req->delay > U16_MAX) {
1827 "delay value is > 16-bits, set to max possible\n");
1828 params.delay = U16_MAX;
1830 params.delay = req->delay;
1833 ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
1837 iwl_mvm_build_scan_probe(mvm, vif, ies, ¶ms);
1839 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
1840 hcmd.id = iwl_cmd_id(SCAN_REQ_UMAC, IWL_ALWAYS_LONG_GROUP, 0);
1841 ret = iwl_mvm_scan_umac(mvm, vif, ¶ms, type);
1843 hcmd.id = SCAN_OFFLOAD_REQUEST_CMD;
1844 ret = iwl_mvm_scan_lmac(mvm, vif, ¶ms);
1850 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1853 "Sched scan request was sent successfully\n");
1854 mvm->scan_status |= type;
1856 /* If the scan failed, it usually means that the FW was unable
1857 * to allocate the time events. Warn on it, but maybe we
1858 * should try to send the command again with different params.
1860 IWL_ERR(mvm, "Sched scan failed! ret %d\n", ret);
1866 void iwl_mvm_rx_umac_scan_complete_notif(struct iwl_mvm *mvm,
1867 struct iwl_rx_cmd_buffer *rxb)
1869 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1870 struct iwl_umac_scan_complete *notif = (void *)pkt->data;
1871 u32 uid = __le32_to_cpu(notif->uid);
1872 bool aborted = (notif->status == IWL_SCAN_OFFLOAD_ABORTED);
1874 if (WARN_ON(!(mvm->scan_uid_status[uid] & mvm->scan_status)))
1877 /* if the scan is already stopping, we don't need to notify mac80211 */
1878 if (mvm->scan_uid_status[uid] == IWL_MVM_SCAN_REGULAR) {
1879 struct cfg80211_scan_info info = {
1881 .scan_start_tsf = mvm->scan_start,
1884 memcpy(info.tsf_bssid, mvm->scan_vif->bssid, ETH_ALEN);
1885 ieee80211_scan_completed(mvm->hw, &info);
1886 mvm->scan_vif = NULL;
1887 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
1888 cancel_delayed_work(&mvm->scan_timeout_dwork);
1889 iwl_mvm_resume_tcm(mvm);
1890 } else if (mvm->scan_uid_status[uid] == IWL_MVM_SCAN_SCHED) {
1891 ieee80211_sched_scan_stopped(mvm->hw);
1892 mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_DISABLED;
1895 mvm->scan_status &= ~mvm->scan_uid_status[uid];
1897 "Scan completed, uid %u type %u, status %s, EBS status %s\n",
1898 uid, mvm->scan_uid_status[uid],
1899 notif->status == IWL_SCAN_OFFLOAD_COMPLETED ?
1900 "completed" : "aborted",
1901 iwl_mvm_ebs_status_str(notif->ebs_status));
1903 "Last line %d, Last iteration %d, Time from last iteration %d\n",
1904 notif->last_schedule, notif->last_iter,
1905 __le32_to_cpu(notif->time_from_last_iter));
1907 if (notif->ebs_status != IWL_SCAN_EBS_SUCCESS &&
1908 notif->ebs_status != IWL_SCAN_EBS_INACTIVE)
1909 mvm->last_ebs_successful = false;
1911 mvm->scan_uid_status[uid] = 0;
1913 iwl_fw_dbg_apply_point(&mvm->fwrt, IWL_FW_INI_APPLY_SCAN_COMPLETE);
1916 void iwl_mvm_rx_umac_scan_iter_complete_notif(struct iwl_mvm *mvm,
1917 struct iwl_rx_cmd_buffer *rxb)
1919 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1920 struct iwl_umac_scan_iter_complete_notif *notif = (void *)pkt->data;
1922 mvm->scan_start = le64_to_cpu(notif->start_tsf);
1925 "UMAC Scan iteration complete: status=0x%x scanned_channels=%d\n",
1926 notif->status, notif->scanned_channels);
1928 if (mvm->sched_scan_pass_all == SCHED_SCAN_PASS_ALL_FOUND) {
1929 IWL_DEBUG_SCAN(mvm, "Pass all scheduled scan results found\n");
1930 ieee80211_sched_scan_results(mvm->hw);
1931 mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_ENABLED;
1935 "UMAC Scan iteration complete: scan started at %llu (TSF)\n",
1939 static int iwl_mvm_umac_scan_abort(struct iwl_mvm *mvm, int type)
1941 struct iwl_umac_scan_abort cmd = {};
1944 lockdep_assert_held(&mvm->mutex);
1946 /* We should always get a valid index here, because we already
1947 * checked that this type of scan was running in the generic
1950 uid = iwl_mvm_scan_uid_by_status(mvm, type);
1951 if (WARN_ON_ONCE(uid < 0))
1954 cmd.uid = cpu_to_le32(uid);
1956 IWL_DEBUG_SCAN(mvm, "Sending scan abort, uid %u\n", uid);
1958 ret = iwl_mvm_send_cmd_pdu(mvm,
1959 iwl_cmd_id(SCAN_ABORT_UMAC,
1960 IWL_ALWAYS_LONG_GROUP, 0),
1961 0, sizeof(cmd), &cmd);
1963 mvm->scan_uid_status[uid] = type << IWL_MVM_SCAN_STOPPING_SHIFT;
1968 static int iwl_mvm_scan_stop_wait(struct iwl_mvm *mvm, int type)
1970 struct iwl_notification_wait wait_scan_done;
1971 static const u16 scan_done_notif[] = { SCAN_COMPLETE_UMAC,
1972 SCAN_OFFLOAD_COMPLETE, };
1975 lockdep_assert_held(&mvm->mutex);
1977 iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_done,
1979 ARRAY_SIZE(scan_done_notif),
1982 IWL_DEBUG_SCAN(mvm, "Preparing to stop scan, type %x\n", type);
1984 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
1985 ret = iwl_mvm_umac_scan_abort(mvm, type);
1987 ret = iwl_mvm_lmac_scan_abort(mvm);
1990 IWL_DEBUG_SCAN(mvm, "couldn't stop scan type %d\n", type);
1991 iwl_remove_notification(&mvm->notif_wait, &wait_scan_done);
1995 return iwl_wait_notification(&mvm->notif_wait, &wait_scan_done,
1999 int iwl_mvm_scan_size(struct iwl_mvm *mvm)
2001 int base_size = IWL_SCAN_REQ_UMAC_SIZE_V1;
2003 if (iwl_mvm_is_adaptive_dwell_v2_supported(mvm))
2004 base_size = IWL_SCAN_REQ_UMAC_SIZE_V8;
2005 else if (iwl_mvm_is_adaptive_dwell_supported(mvm))
2006 base_size = IWL_SCAN_REQ_UMAC_SIZE_V7;
2007 else if (iwl_mvm_cdb_scan_api(mvm))
2008 base_size = IWL_SCAN_REQ_UMAC_SIZE_V6;
2010 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2012 sizeof(struct iwl_scan_channel_cfg_umac) *
2013 mvm->fw->ucode_capa.n_scan_channels +
2014 sizeof(struct iwl_scan_req_umac_tail);
2016 return sizeof(struct iwl_scan_req_lmac) +
2017 sizeof(struct iwl_scan_channel_cfg_lmac) *
2018 mvm->fw->ucode_capa.n_scan_channels +
2019 sizeof(struct iwl_scan_probe_req);
2023 * This function is used in nic restart flow, to inform mac80211 about scans
2024 * that was aborted by restart flow or by an assert.
2026 void iwl_mvm_report_scan_aborted(struct iwl_mvm *mvm)
2028 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
2031 uid = iwl_mvm_scan_uid_by_status(mvm, IWL_MVM_SCAN_REGULAR);
2033 struct cfg80211_scan_info info = {
2037 ieee80211_scan_completed(mvm->hw, &info);
2038 mvm->scan_uid_status[uid] = 0;
2040 uid = iwl_mvm_scan_uid_by_status(mvm, IWL_MVM_SCAN_SCHED);
2041 if (uid >= 0 && !mvm->fw_restart) {
2042 ieee80211_sched_scan_stopped(mvm->hw);
2043 mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_DISABLED;
2044 mvm->scan_uid_status[uid] = 0;
2047 /* We shouldn't have any UIDs still set. Loop over all the
2048 * UIDs to make sure there's nothing left there and warn if
2051 for (i = 0; i < mvm->max_scans; i++) {
2052 if (WARN_ONCE(mvm->scan_uid_status[i],
2053 "UMAC scan UID %d status was not cleaned\n",
2055 mvm->scan_uid_status[i] = 0;
2058 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR) {
2059 struct cfg80211_scan_info info = {
2063 ieee80211_scan_completed(mvm->hw, &info);
2066 /* Sched scan will be restarted by mac80211 in
2067 * restart_hw, so do not report if FW is about to be
2070 if ((mvm->scan_status & IWL_MVM_SCAN_SCHED) &&
2072 ieee80211_sched_scan_stopped(mvm->hw);
2073 mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_DISABLED;
2078 int iwl_mvm_scan_stop(struct iwl_mvm *mvm, int type, bool notify)
2082 if (!(mvm->scan_status & type))
2085 if (iwl_mvm_is_radio_killed(mvm)) {
2090 ret = iwl_mvm_scan_stop_wait(mvm, type);
2092 mvm->scan_status |= type << IWL_MVM_SCAN_STOPPING_SHIFT;
2094 /* Clear the scan status so the next scan requests will
2095 * succeed and mark the scan as stopping, so that the Rx
2096 * handler doesn't do anything, as the scan was stopped from
2099 mvm->scan_status &= ~type;
2101 if (type == IWL_MVM_SCAN_REGULAR) {
2102 /* Since the rx handler won't do anything now, we have
2103 * to release the scan reference here.
2105 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
2106 cancel_delayed_work(&mvm->scan_timeout_dwork);
2108 struct cfg80211_scan_info info = {
2112 ieee80211_scan_completed(mvm->hw, &info);
2114 } else if (notify) {
2115 ieee80211_sched_scan_stopped(mvm->hw);
2116 mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_DISABLED;