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 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 * You should have received a copy of the GNU General Public License
23 * along with this program
25 * The full GNU General Public License is included in this distribution
26 * in the file called COPYING.
28 * Contact Information:
29 * Intel Linux Wireless <linuxwifi@intel.com>
30 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
34 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
35 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
36 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
37 * Copyright(c) 2018 Intel Corporation
38 * All rights reserved.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
44 * * Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * * Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in
48 * the documentation and/or other materials provided with the
50 * * Neither the name Intel Corporation nor the names of its
51 * contributors may be used to endorse or promote products derived
52 * from this software without specific prior written permission.
54 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
55 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
56 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
57 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
58 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
59 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
60 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
61 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
62 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
63 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
64 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
66 *****************************************************************************/
68 #include <linux/etherdevice.h>
69 #include <net/mac80211.h>
72 #include "fw/api/scan.h"
75 #define IWL_DENSE_EBS_SCAN_RATIO 5
76 #define IWL_SPARSE_EBS_SCAN_RATIO 1
78 #define IWL_SCAN_DWELL_ACTIVE 10
79 #define IWL_SCAN_DWELL_PASSIVE 110
80 #define IWL_SCAN_DWELL_FRAGMENTED 44
81 #define IWL_SCAN_DWELL_EXTENDED 90
82 #define IWL_SCAN_NUM_OF_FRAGS 3
85 /* adaptive dwell max budget time [TU] for full scan */
86 #define IWL_SCAN_ADWELL_MAX_BUDGET_FULL_SCAN 300
87 /* adaptive dwell max budget time [TU] for directed scan */
88 #define IWL_SCAN_ADWELL_MAX_BUDGET_DIRECTED_SCAN 100
89 /* adaptive dwell default APs number */
90 #define IWL_SCAN_ADWELL_DEFAULT_N_APS 2
91 /* adaptive dwell default APs number in social channels (1, 6, 11) */
92 #define IWL_SCAN_ADWELL_DEFAULT_N_APS_SOCIAL 10
94 struct iwl_mvm_scan_timing_params {
99 static struct iwl_mvm_scan_timing_params scan_timing[] = {
100 [IWL_SCAN_TYPE_UNASSOC] = {
104 [IWL_SCAN_TYPE_WILD] = {
108 [IWL_SCAN_TYPE_MILD] = {
112 [IWL_SCAN_TYPE_FRAGMENTED] = {
118 struct iwl_mvm_scan_params {
119 /* For CDB this is low band scan type, for non-CDB - type. */
120 enum iwl_mvm_scan_type type;
121 enum iwl_mvm_scan_type hb_type;
125 struct cfg80211_ssid *ssids;
126 struct ieee80211_channel **channels;
133 struct iwl_scan_probe_req preq;
134 struct cfg80211_match_set *match_sets;
136 struct cfg80211_sched_scan_plan *scan_plans;
137 u32 measurement_dwell;
140 static inline void *iwl_mvm_get_scan_req_umac_data(struct iwl_mvm *mvm)
142 struct iwl_scan_req_umac *cmd = mvm->scan_cmd;
144 if (iwl_mvm_is_adaptive_dwell_v2_supported(mvm))
145 return (void *)&cmd->v8.data;
147 if (iwl_mvm_is_adaptive_dwell_supported(mvm))
148 return (void *)&cmd->v7.data;
150 if (iwl_mvm_cdb_scan_api(mvm))
151 return (void *)&cmd->v6.data;
153 return (void *)&cmd->v1.data;
156 static inline struct iwl_scan_umac_chan_param *
157 iwl_mvm_get_scan_req_umac_channel(struct iwl_mvm *mvm)
159 struct iwl_scan_req_umac *cmd = mvm->scan_cmd;
161 if (iwl_mvm_is_adaptive_dwell_v2_supported(mvm))
162 return &cmd->v8.channel;
164 if (iwl_mvm_is_adaptive_dwell_supported(mvm))
165 return &cmd->v7.channel;
167 if (iwl_mvm_cdb_scan_api(mvm))
168 return &cmd->v6.channel;
170 return &cmd->v1.channel;
173 static u8 iwl_mvm_scan_rx_ant(struct iwl_mvm *mvm)
175 if (mvm->scan_rx_ant != ANT_NONE)
176 return mvm->scan_rx_ant;
177 return iwl_mvm_get_valid_rx_ant(mvm);
180 static inline __le16 iwl_mvm_scan_rx_chain(struct iwl_mvm *mvm)
185 rx_ant = iwl_mvm_scan_rx_ant(mvm);
186 rx_chain = rx_ant << PHY_RX_CHAIN_VALID_POS;
187 rx_chain |= rx_ant << PHY_RX_CHAIN_FORCE_MIMO_SEL_POS;
188 rx_chain |= rx_ant << PHY_RX_CHAIN_FORCE_SEL_POS;
189 rx_chain |= 0x1 << PHY_RX_CHAIN_DRIVER_FORCE_POS;
190 return cpu_to_le16(rx_chain);
193 static __le32 iwl_mvm_scan_rxon_flags(enum nl80211_band band)
195 if (band == NL80211_BAND_2GHZ)
196 return cpu_to_le32(PHY_BAND_24);
198 return cpu_to_le32(PHY_BAND_5);
202 iwl_mvm_scan_rate_n_flags(struct iwl_mvm *mvm, enum nl80211_band band,
207 mvm->scan_last_antenna_idx =
208 iwl_mvm_next_antenna(mvm, iwl_mvm_get_valid_tx_ant(mvm),
209 mvm->scan_last_antenna_idx);
210 tx_ant = BIT(mvm->scan_last_antenna_idx) << RATE_MCS_ANT_POS;
212 if (band == NL80211_BAND_2GHZ && !no_cck)
213 return cpu_to_le32(IWL_RATE_1M_PLCP | RATE_MCS_CCK_MSK |
216 return cpu_to_le32(IWL_RATE_6M_PLCP | tx_ant);
219 static void iwl_mvm_scan_condition_iterator(void *data, u8 *mac,
220 struct ieee80211_vif *vif)
222 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
223 int *global_cnt = data;
225 if (vif->type != NL80211_IFTYPE_P2P_DEVICE && mvmvif->phy_ctxt &&
226 mvmvif->phy_ctxt->id < NUM_PHY_CTX)
230 static enum iwl_mvm_traffic_load iwl_mvm_get_traffic_load(struct iwl_mvm *mvm)
232 return mvm->tcm.result.global_load;
235 static enum iwl_mvm_traffic_load
236 iwl_mvm_get_traffic_load_band(struct iwl_mvm *mvm, enum nl80211_band band)
238 return mvm->tcm.result.band_load[band];
242 iwl_mvm_scan_type _iwl_mvm_get_scan_type(struct iwl_mvm *mvm, bool p2p_device,
243 enum iwl_mvm_traffic_load load,
248 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
249 IEEE80211_IFACE_ITER_NORMAL,
250 iwl_mvm_scan_condition_iterator,
253 return IWL_SCAN_TYPE_UNASSOC;
255 if ((load == IWL_MVM_TRAFFIC_HIGH || low_latency) && !p2p_device &&
256 fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_FRAGMENTED_SCAN))
257 return IWL_SCAN_TYPE_FRAGMENTED;
259 if (load >= IWL_MVM_TRAFFIC_MEDIUM || low_latency)
260 return IWL_SCAN_TYPE_MILD;
262 return IWL_SCAN_TYPE_WILD;
266 iwl_mvm_scan_type iwl_mvm_get_scan_type(struct iwl_mvm *mvm, bool p2p_device)
268 enum iwl_mvm_traffic_load load;
271 load = iwl_mvm_get_traffic_load(mvm);
272 low_latency = iwl_mvm_low_latency(mvm);
274 return _iwl_mvm_get_scan_type(mvm, p2p_device, load, low_latency);
278 iwl_mvm_scan_type iwl_mvm_get_scan_type_band(struct iwl_mvm *mvm,
280 enum nl80211_band band)
282 enum iwl_mvm_traffic_load load;
285 load = iwl_mvm_get_traffic_load_band(mvm, band);
286 low_latency = iwl_mvm_low_latency_band(mvm, band);
288 return _iwl_mvm_get_scan_type(mvm, p2p_device, load, low_latency);
292 iwl_mvm_get_measurement_dwell(struct iwl_mvm *mvm,
293 struct cfg80211_scan_request *req,
294 struct iwl_mvm_scan_params *params)
296 u32 duration = scan_timing[params->type].max_out_time;
301 if (iwl_mvm_is_cdb_supported(mvm)) {
302 u32 hb_time = scan_timing[params->hb_type].max_out_time;
304 duration = min_t(u32, duration, hb_time);
307 if (req->duration_mandatory && req->duration > duration) {
309 "Measurement scan - too long dwell %hu (max out time %u)\n",
315 return min_t(u32, (u32)req->duration, duration);
318 static inline bool iwl_mvm_rrm_scan_needed(struct iwl_mvm *mvm)
320 /* require rrm scan whenever the fw supports it */
321 return fw_has_capa(&mvm->fw->ucode_capa,
322 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT);
325 static int iwl_mvm_max_scan_ie_fw_cmd_room(struct iwl_mvm *mvm)
329 max_probe_len = SCAN_OFFLOAD_PROBE_REQ_SIZE;
331 /* we create the 802.11 header and SSID element */
332 max_probe_len -= 24 + 2;
334 /* DS parameter set element is added on 2.4GHZ band if required */
335 if (iwl_mvm_rrm_scan_needed(mvm))
338 return max_probe_len;
341 int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm)
343 int max_ie_len = iwl_mvm_max_scan_ie_fw_cmd_room(mvm);
345 /* TODO: [BUG] This function should return the maximum allowed size of
346 * scan IEs, however the LMAC scan api contains both 2GHZ and 5GHZ IEs
347 * in the same command. So the correct implementation of this function
348 * is just iwl_mvm_max_scan_ie_fw_cmd_room() / 2. Currently the scan
349 * command has only 512 bytes and it would leave us with about 240
350 * bytes for scan IEs, which is clearly not enough. So meanwhile
351 * we will report an incorrect value. This may result in a failure to
352 * issue a scan in unified_scan_lmac and unified_sched_scan_lmac
353 * functions with -ENOBUFS, if a large enough probe will be provided.
358 void iwl_mvm_rx_lmac_scan_iter_complete_notif(struct iwl_mvm *mvm,
359 struct iwl_rx_cmd_buffer *rxb)
361 struct iwl_rx_packet *pkt = rxb_addr(rxb);
362 struct iwl_lmac_scan_complete_notif *notif = (void *)pkt->data;
365 "Scan offload iteration complete: status=0x%x scanned channels=%d\n",
366 notif->status, notif->scanned_channels);
368 if (mvm->sched_scan_pass_all == SCHED_SCAN_PASS_ALL_FOUND) {
369 IWL_DEBUG_SCAN(mvm, "Pass all scheduled scan results found\n");
370 ieee80211_sched_scan_results(mvm->hw);
371 mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_ENABLED;
375 void iwl_mvm_rx_scan_match_found(struct iwl_mvm *mvm,
376 struct iwl_rx_cmd_buffer *rxb)
378 IWL_DEBUG_SCAN(mvm, "Scheduled scan results\n");
379 ieee80211_sched_scan_results(mvm->hw);
382 static const char *iwl_mvm_ebs_status_str(enum iwl_scan_ebs_status status)
385 case IWL_SCAN_EBS_SUCCESS:
387 case IWL_SCAN_EBS_INACTIVE:
389 case IWL_SCAN_EBS_FAILED:
390 case IWL_SCAN_EBS_CHAN_NOT_FOUND:
396 void iwl_mvm_rx_lmac_scan_complete_notif(struct iwl_mvm *mvm,
397 struct iwl_rx_cmd_buffer *rxb)
399 struct iwl_rx_packet *pkt = rxb_addr(rxb);
400 struct iwl_periodic_scan_complete *scan_notif = (void *)pkt->data;
401 bool aborted = (scan_notif->status == IWL_SCAN_OFFLOAD_ABORTED);
403 /* If this happens, the firmware has mistakenly sent an LMAC
404 * notification during UMAC scans -- warn and ignore it.
406 if (WARN_ON_ONCE(fw_has_capa(&mvm->fw->ucode_capa,
407 IWL_UCODE_TLV_CAPA_UMAC_SCAN)))
410 /* scan status must be locked for proper checking */
411 lockdep_assert_held(&mvm->mutex);
413 /* We first check if we were stopping a scan, in which case we
414 * just clear the stopping flag. Then we check if it was a
415 * firmware initiated stop, in which case we need to inform
417 * Note that we can have a stopping and a running scan
418 * simultaneously, but we can't have two different types of
419 * scans stopping or running at the same time (since LMAC
420 * doesn't support it).
423 if (mvm->scan_status & IWL_MVM_SCAN_STOPPING_SCHED) {
424 WARN_ON_ONCE(mvm->scan_status & IWL_MVM_SCAN_STOPPING_REGULAR);
426 IWL_DEBUG_SCAN(mvm, "Scheduled scan %s, EBS status %s\n",
427 aborted ? "aborted" : "completed",
428 iwl_mvm_ebs_status_str(scan_notif->ebs_status));
430 "Last line %d, Last iteration %d, Time after last iteration %d\n",
431 scan_notif->last_schedule_line,
432 scan_notif->last_schedule_iteration,
433 __le32_to_cpu(scan_notif->time_after_last_iter));
435 mvm->scan_status &= ~IWL_MVM_SCAN_STOPPING_SCHED;
436 } else if (mvm->scan_status & IWL_MVM_SCAN_STOPPING_REGULAR) {
437 IWL_DEBUG_SCAN(mvm, "Regular scan %s, EBS status %s\n",
438 aborted ? "aborted" : "completed",
439 iwl_mvm_ebs_status_str(scan_notif->ebs_status));
441 mvm->scan_status &= ~IWL_MVM_SCAN_STOPPING_REGULAR;
442 } else if (mvm->scan_status & IWL_MVM_SCAN_SCHED) {
443 WARN_ON_ONCE(mvm->scan_status & IWL_MVM_SCAN_REGULAR);
445 IWL_DEBUG_SCAN(mvm, "Scheduled scan %s, EBS status %s\n",
446 aborted ? "aborted" : "completed",
447 iwl_mvm_ebs_status_str(scan_notif->ebs_status));
449 "Last line %d, Last iteration %d, Time after last iteration %d (FW)\n",
450 scan_notif->last_schedule_line,
451 scan_notif->last_schedule_iteration,
452 __le32_to_cpu(scan_notif->time_after_last_iter));
454 mvm->scan_status &= ~IWL_MVM_SCAN_SCHED;
455 ieee80211_sched_scan_stopped(mvm->hw);
456 mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_DISABLED;
457 } else if (mvm->scan_status & IWL_MVM_SCAN_REGULAR) {
458 struct cfg80211_scan_info info = {
462 IWL_DEBUG_SCAN(mvm, "Regular scan %s, EBS status %s (FW)\n",
463 aborted ? "aborted" : "completed",
464 iwl_mvm_ebs_status_str(scan_notif->ebs_status));
466 mvm->scan_status &= ~IWL_MVM_SCAN_REGULAR;
467 ieee80211_scan_completed(mvm->hw, &info);
468 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
469 cancel_delayed_work(&mvm->scan_timeout_dwork);
470 iwl_mvm_resume_tcm(mvm);
473 "got scan complete notification but no scan is running\n");
476 mvm->last_ebs_successful =
477 scan_notif->ebs_status == IWL_SCAN_EBS_SUCCESS ||
478 scan_notif->ebs_status == IWL_SCAN_EBS_INACTIVE;
481 static int iwl_ssid_exist(u8 *ssid, u8 ssid_len, struct iwl_ssid_ie *ssid_list)
485 for (i = 0; i < PROBE_OPTION_MAX; i++) {
486 if (!ssid_list[i].len)
488 if (ssid_list[i].len == ssid_len &&
489 !memcmp(ssid_list->ssid, ssid, ssid_len))
495 /* We insert the SSIDs in an inverted order, because the FW will
498 static void iwl_scan_build_ssids(struct iwl_mvm_scan_params *params,
499 struct iwl_ssid_ie *ssids,
506 * copy SSIDs from match list.
507 * iwl_config_sched_scan_profiles() uses the order of these ssids to
510 for (i = 0, j = params->n_match_sets - 1;
511 j >= 0 && i < PROBE_OPTION_MAX;
513 /* skip empty SSID matchsets */
514 if (!params->match_sets[j].ssid.ssid_len)
516 ssids[i].id = WLAN_EID_SSID;
517 ssids[i].len = params->match_sets[j].ssid.ssid_len;
518 memcpy(ssids[i].ssid, params->match_sets[j].ssid.ssid,
522 /* add SSIDs from scan SSID list */
524 for (j = params->n_ssids - 1;
525 j >= 0 && i < PROBE_OPTION_MAX;
527 index = iwl_ssid_exist(params->ssids[j].ssid,
528 params->ssids[j].ssid_len,
531 ssids[i].id = WLAN_EID_SSID;
532 ssids[i].len = params->ssids[j].ssid_len;
533 memcpy(ssids[i].ssid, params->ssids[j].ssid,
535 *ssid_bitmap |= BIT(i);
537 *ssid_bitmap |= BIT(index);
543 iwl_mvm_config_sched_scan_profiles(struct iwl_mvm *mvm,
544 struct cfg80211_sched_scan_request *req)
546 struct iwl_scan_offload_profile *profile;
547 struct iwl_scan_offload_profile_cfg *profile_cfg;
548 struct iwl_scan_offload_blacklist *blacklist;
549 struct iwl_host_cmd cmd = {
550 .id = SCAN_OFFLOAD_UPDATE_PROFILES_CMD,
551 .len[1] = sizeof(*profile_cfg),
552 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
553 .dataflags[1] = IWL_HCMD_DFL_NOCOPY,
559 if (WARN_ON(req->n_match_sets > IWL_SCAN_MAX_PROFILES))
562 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_SHORT_BL)
563 blacklist_len = IWL_SCAN_SHORT_BLACKLIST_LEN;
565 blacklist_len = IWL_SCAN_MAX_BLACKLIST_LEN;
567 blacklist = kzalloc(sizeof(*blacklist) * blacklist_len, GFP_KERNEL);
571 profile_cfg = kzalloc(sizeof(*profile_cfg), GFP_KERNEL);
577 cmd.data[0] = blacklist;
578 cmd.len[0] = sizeof(*blacklist) * blacklist_len;
579 cmd.data[1] = profile_cfg;
581 /* No blacklist configuration */
583 profile_cfg->num_profiles = req->n_match_sets;
584 profile_cfg->active_clients = SCAN_CLIENT_SCHED_SCAN;
585 profile_cfg->pass_match = SCAN_CLIENT_SCHED_SCAN;
586 profile_cfg->match_notify = SCAN_CLIENT_SCHED_SCAN;
587 if (!req->n_match_sets || !req->match_sets[0].ssid.ssid_len)
588 profile_cfg->any_beacon_notify = SCAN_CLIENT_SCHED_SCAN;
590 for (i = 0; i < req->n_match_sets; i++) {
591 profile = &profile_cfg->profiles[i];
592 profile->ssid_index = i;
593 /* Support any cipher and auth algorithm */
594 profile->unicast_cipher = 0xff;
595 profile->auth_alg = 0xff;
596 profile->network_type = IWL_NETWORK_TYPE_ANY;
597 profile->band_selection = IWL_SCAN_OFFLOAD_SELECT_ANY;
598 profile->client_bitmap = SCAN_CLIENT_SCHED_SCAN;
601 IWL_DEBUG_SCAN(mvm, "Sending scheduled scan profile config\n");
603 ret = iwl_mvm_send_cmd(mvm, &cmd);
611 static bool iwl_mvm_scan_pass_all(struct iwl_mvm *mvm,
612 struct cfg80211_sched_scan_request *req)
614 if (req->n_match_sets && req->match_sets[0].ssid.ssid_len) {
616 "Sending scheduled scan with filtering, n_match_sets %d\n",
618 mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_DISABLED;
622 IWL_DEBUG_SCAN(mvm, "Sending Scheduled scan without filtering\n");
624 mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_ENABLED;
628 static int iwl_mvm_lmac_scan_abort(struct iwl_mvm *mvm)
631 struct iwl_host_cmd cmd = {
632 .id = SCAN_OFFLOAD_ABORT_CMD,
634 u32 status = CAN_ABORT_STATUS;
636 ret = iwl_mvm_send_cmd_status(mvm, &cmd, &status);
640 if (status != CAN_ABORT_STATUS) {
642 * The scan abort will return 1 for success or
643 * 2 for "failure". A failure condition can be
644 * due to simply not being in an active scan which
645 * can occur if we send the scan abort before the
646 * microcode has notified us that a scan is completed.
648 IWL_DEBUG_SCAN(mvm, "SCAN OFFLOAD ABORT ret %d.\n", status);
655 static void iwl_mvm_scan_fill_tx_cmd(struct iwl_mvm *mvm,
656 struct iwl_scan_req_tx_cmd *tx_cmd,
659 tx_cmd[0].tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL |
661 tx_cmd[0].rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm,
664 tx_cmd[0].sta_id = mvm->aux_sta.sta_id;
666 tx_cmd[1].tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL |
668 tx_cmd[1].rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm,
671 tx_cmd[1].sta_id = mvm->aux_sta.sta_id;
675 iwl_mvm_lmac_scan_cfg_channels(struct iwl_mvm *mvm,
676 struct ieee80211_channel **channels,
677 int n_channels, u32 ssid_bitmap,
678 struct iwl_scan_req_lmac *cmd)
680 struct iwl_scan_channel_cfg_lmac *channel_cfg = (void *)&cmd->data;
683 for (i = 0; i < n_channels; i++) {
684 channel_cfg[i].channel_num =
685 cpu_to_le16(channels[i]->hw_value);
686 channel_cfg[i].iter_count = cpu_to_le16(1);
687 channel_cfg[i].iter_interval = 0;
688 channel_cfg[i].flags =
689 cpu_to_le32(IWL_UNIFIED_SCAN_CHANNEL_PARTIAL |
694 static u8 *iwl_mvm_copy_and_insert_ds_elem(struct iwl_mvm *mvm, const u8 *ies,
695 size_t len, u8 *const pos)
697 static const u8 before_ds_params[] = {
701 WLAN_EID_EXT_SUPP_RATES,
706 if (!iwl_mvm_rrm_scan_needed(mvm)) {
707 memcpy(newpos, ies, len);
711 offs = ieee80211_ie_split(ies, len,
713 ARRAY_SIZE(before_ds_params),
716 memcpy(newpos, ies, offs);
719 /* Add a placeholder for DS Parameter Set element */
720 *newpos++ = WLAN_EID_DS_PARAMS;
724 memcpy(newpos, ies + offs, len - offs);
725 newpos += len - offs;
730 #define WFA_TPC_IE_LEN 9
732 static void iwl_mvm_add_tpc_report_ie(u8 *pos)
734 pos[0] = WLAN_EID_VENDOR_SPECIFIC;
735 pos[1] = WFA_TPC_IE_LEN - 2;
736 pos[2] = (WLAN_OUI_MICROSOFT >> 16) & 0xff;
737 pos[3] = (WLAN_OUI_MICROSOFT >> 8) & 0xff;
738 pos[4] = WLAN_OUI_MICROSOFT & 0xff;
739 pos[5] = WLAN_OUI_TYPE_MICROSOFT_TPC;
741 /* pos[7] - tx power will be inserted by the FW */
747 iwl_mvm_build_scan_probe(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
748 struct ieee80211_scan_ies *ies,
749 struct iwl_mvm_scan_params *params)
751 struct ieee80211_mgmt *frame = (void *)params->preq.buf;
753 const u8 *mac_addr = params->flags & NL80211_SCAN_FLAG_RANDOM_ADDR ?
754 params->mac_addr : NULL;
757 * Unfortunately, right now the offload scan doesn't support randomising
758 * within the firmware, so until the firmware API is ready we implement
759 * it in the driver. This means that the scan iterations won't really be
760 * random, only when it's restarted, but at least that helps a bit.
763 get_random_mask_addr(frame->sa, mac_addr,
764 params->mac_addr_mask);
766 memcpy(frame->sa, vif->addr, ETH_ALEN);
768 frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
769 eth_broadcast_addr(frame->da);
770 eth_broadcast_addr(frame->bssid);
773 pos = frame->u.probe_req.variable;
774 *pos++ = WLAN_EID_SSID;
777 params->preq.mac_header.offset = 0;
778 params->preq.mac_header.len = cpu_to_le16(24 + 2);
780 /* Insert ds parameter set element on 2.4 GHz band */
781 newpos = iwl_mvm_copy_and_insert_ds_elem(mvm,
782 ies->ies[NL80211_BAND_2GHZ],
783 ies->len[NL80211_BAND_2GHZ],
785 params->preq.band_data[0].offset = cpu_to_le16(pos - params->preq.buf);
786 params->preq.band_data[0].len = cpu_to_le16(newpos - pos);
789 memcpy(pos, ies->ies[NL80211_BAND_5GHZ],
790 ies->len[NL80211_BAND_5GHZ]);
791 params->preq.band_data[1].offset = cpu_to_le16(pos - params->preq.buf);
792 params->preq.band_data[1].len =
793 cpu_to_le16(ies->len[NL80211_BAND_5GHZ]);
794 pos += ies->len[NL80211_BAND_5GHZ];
796 memcpy(pos, ies->common_ies, ies->common_ie_len);
797 params->preq.common_data.offset = cpu_to_le16(pos - params->preq.buf);
799 if (iwl_mvm_rrm_scan_needed(mvm) &&
800 !fw_has_capa(&mvm->fw->ucode_capa,
801 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT)) {
802 iwl_mvm_add_tpc_report_ie(pos + ies->common_ie_len);
803 params->preq.common_data.len = cpu_to_le16(ies->common_ie_len +
806 params->preq.common_data.len = cpu_to_le16(ies->common_ie_len);
810 static void iwl_mvm_scan_lmac_dwell(struct iwl_mvm *mvm,
811 struct iwl_scan_req_lmac *cmd,
812 struct iwl_mvm_scan_params *params)
814 cmd->active_dwell = IWL_SCAN_DWELL_ACTIVE;
815 cmd->passive_dwell = IWL_SCAN_DWELL_PASSIVE;
816 cmd->fragmented_dwell = IWL_SCAN_DWELL_FRAGMENTED;
817 cmd->extended_dwell = IWL_SCAN_DWELL_EXTENDED;
818 cmd->max_out_time = cpu_to_le32(scan_timing[params->type].max_out_time);
819 cmd->suspend_time = cpu_to_le32(scan_timing[params->type].suspend_time);
820 cmd->scan_prio = cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6);
823 static inline bool iwl_mvm_scan_fits(struct iwl_mvm *mvm, int n_ssids,
824 struct ieee80211_scan_ies *ies,
827 return ((n_ssids <= PROBE_OPTION_MAX) &&
828 (n_channels <= mvm->fw->ucode_capa.n_scan_channels) &
829 (ies->common_ie_len +
830 ies->len[NL80211_BAND_2GHZ] +
831 ies->len[NL80211_BAND_5GHZ] <=
832 iwl_mvm_max_scan_ie_fw_cmd_room(mvm)));
835 static inline bool iwl_mvm_scan_use_ebs(struct iwl_mvm *mvm,
836 struct ieee80211_vif *vif)
838 const struct iwl_ucode_capabilities *capa = &mvm->fw->ucode_capa;
840 /* We can only use EBS if:
841 * 1. the feature is supported;
842 * 2. the last EBS was successful;
843 * 3. if only single scan, the single scan EBS API is supported;
844 * 4. it's not a p2p find operation.
846 return ((capa->flags & IWL_UCODE_TLV_FLAGS_EBS_SUPPORT) &&
847 mvm->last_ebs_successful && IWL_MVM_ENABLE_EBS &&
848 vif->type != NL80211_IFTYPE_P2P_DEVICE);
851 static inline bool iwl_mvm_is_regular_scan(struct iwl_mvm_scan_params *params)
853 return params->n_scan_plans == 1 &&
854 params->scan_plans[0].iterations == 1;
857 static int iwl_mvm_scan_lmac_flags(struct iwl_mvm *mvm,
858 struct iwl_mvm_scan_params *params,
859 struct ieee80211_vif *vif)
863 if (params->n_ssids == 0)
864 flags |= IWL_MVM_LMAC_SCAN_FLAG_PASSIVE;
866 if (params->n_ssids == 1 && params->ssids[0].ssid_len != 0)
867 flags |= IWL_MVM_LMAC_SCAN_FLAG_PRE_CONNECTION;
869 if (params->type == IWL_SCAN_TYPE_FRAGMENTED)
870 flags |= IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED;
872 if (iwl_mvm_rrm_scan_needed(mvm) &&
873 fw_has_capa(&mvm->fw->ucode_capa,
874 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
875 flags |= IWL_MVM_LMAC_SCAN_FLAGS_RRM_ENABLED;
877 if (params->pass_all)
878 flags |= IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL;
880 flags |= IWL_MVM_LMAC_SCAN_FLAG_MATCH;
882 #ifdef CONFIG_IWLWIFI_DEBUGFS
883 if (mvm->scan_iter_notif_enabled)
884 flags |= IWL_MVM_LMAC_SCAN_FLAG_ITER_COMPLETE;
887 if (mvm->sched_scan_pass_all == SCHED_SCAN_PASS_ALL_ENABLED)
888 flags |= IWL_MVM_LMAC_SCAN_FLAG_ITER_COMPLETE;
890 if (iwl_mvm_is_regular_scan(params) &&
891 vif->type != NL80211_IFTYPE_P2P_DEVICE &&
892 params->type != IWL_SCAN_TYPE_FRAGMENTED)
893 flags |= IWL_MVM_LMAC_SCAN_FLAG_EXTENDED_DWELL;
898 static int iwl_mvm_scan_lmac(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
899 struct iwl_mvm_scan_params *params)
901 struct iwl_scan_req_lmac *cmd = mvm->scan_cmd;
902 struct iwl_scan_probe_req *preq =
903 (void *)(cmd->data + sizeof(struct iwl_scan_channel_cfg_lmac) *
904 mvm->fw->ucode_capa.n_scan_channels);
908 lockdep_assert_held(&mvm->mutex);
910 memset(cmd, 0, ksize(cmd));
912 if (WARN_ON(params->n_scan_plans > IWL_MAX_SCHED_SCAN_PLANS))
915 iwl_mvm_scan_lmac_dwell(mvm, cmd, params);
917 cmd->rx_chain_select = iwl_mvm_scan_rx_chain(mvm);
918 cmd->iter_num = cpu_to_le32(1);
919 cmd->n_channels = (u8)params->n_channels;
921 cmd->delay = cpu_to_le32(params->delay);
923 cmd->scan_flags = cpu_to_le32(iwl_mvm_scan_lmac_flags(mvm, params,
926 cmd->flags = iwl_mvm_scan_rxon_flags(params->channels[0]->band);
927 cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP |
928 MAC_FILTER_IN_BEACON);
929 iwl_mvm_scan_fill_tx_cmd(mvm, cmd->tx_cmd, params->no_cck);
930 iwl_scan_build_ssids(params, cmd->direct_scan, &ssid_bitmap);
932 /* this API uses bits 1-20 instead of 0-19 */
935 for (i = 0; i < params->n_scan_plans; i++) {
936 struct cfg80211_sched_scan_plan *scan_plan =
937 ¶ms->scan_plans[i];
939 cmd->schedule[i].delay =
940 cpu_to_le16(scan_plan->interval);
941 cmd->schedule[i].iterations = scan_plan->iterations;
942 cmd->schedule[i].full_scan_mul = 1;
946 * If the number of iterations of the last scan plan is set to
947 * zero, it should run infinitely. However, this is not always the case.
948 * For example, when regular scan is requested the driver sets one scan
949 * plan with one iteration.
951 if (!cmd->schedule[i - 1].iterations)
952 cmd->schedule[i - 1].iterations = 0xff;
954 if (iwl_mvm_scan_use_ebs(mvm, vif)) {
955 cmd->channel_opt[0].flags =
956 cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS |
957 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
958 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD);
959 cmd->channel_opt[0].non_ebs_ratio =
960 cpu_to_le16(IWL_DENSE_EBS_SCAN_RATIO);
961 cmd->channel_opt[1].flags =
962 cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS |
963 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
964 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD);
965 cmd->channel_opt[1].non_ebs_ratio =
966 cpu_to_le16(IWL_SPARSE_EBS_SCAN_RATIO);
969 iwl_mvm_lmac_scan_cfg_channels(mvm, params->channels,
970 params->n_channels, ssid_bitmap, cmd);
972 *preq = params->preq;
977 static int rate_to_scan_rate_flag(unsigned int rate)
979 static const int rate_to_scan_rate[IWL_RATE_COUNT] = {
980 [IWL_RATE_1M_INDEX] = SCAN_CONFIG_RATE_1M,
981 [IWL_RATE_2M_INDEX] = SCAN_CONFIG_RATE_2M,
982 [IWL_RATE_5M_INDEX] = SCAN_CONFIG_RATE_5M,
983 [IWL_RATE_11M_INDEX] = SCAN_CONFIG_RATE_11M,
984 [IWL_RATE_6M_INDEX] = SCAN_CONFIG_RATE_6M,
985 [IWL_RATE_9M_INDEX] = SCAN_CONFIG_RATE_9M,
986 [IWL_RATE_12M_INDEX] = SCAN_CONFIG_RATE_12M,
987 [IWL_RATE_18M_INDEX] = SCAN_CONFIG_RATE_18M,
988 [IWL_RATE_24M_INDEX] = SCAN_CONFIG_RATE_24M,
989 [IWL_RATE_36M_INDEX] = SCAN_CONFIG_RATE_36M,
990 [IWL_RATE_48M_INDEX] = SCAN_CONFIG_RATE_48M,
991 [IWL_RATE_54M_INDEX] = SCAN_CONFIG_RATE_54M,
994 return rate_to_scan_rate[rate];
997 static __le32 iwl_mvm_scan_config_rates(struct iwl_mvm *mvm)
999 struct ieee80211_supported_band *band;
1000 unsigned int rates = 0;
1003 band = &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
1004 for (i = 0; i < band->n_bitrates; i++)
1005 rates |= rate_to_scan_rate_flag(band->bitrates[i].hw_value);
1006 band = &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
1007 for (i = 0; i < band->n_bitrates; i++)
1008 rates |= rate_to_scan_rate_flag(band->bitrates[i].hw_value);
1010 /* Set both basic rates and supported rates */
1011 rates |= SCAN_CONFIG_SUPPORTED_RATE(rates);
1013 return cpu_to_le32(rates);
1016 static void iwl_mvm_fill_scan_dwell(struct iwl_mvm *mvm,
1017 struct iwl_scan_dwell *dwell)
1019 dwell->active = IWL_SCAN_DWELL_ACTIVE;
1020 dwell->passive = IWL_SCAN_DWELL_PASSIVE;
1021 dwell->fragmented = IWL_SCAN_DWELL_FRAGMENTED;
1022 dwell->extended = IWL_SCAN_DWELL_EXTENDED;
1025 static void iwl_mvm_fill_channels(struct iwl_mvm *mvm, u8 *channels)
1027 struct ieee80211_supported_band *band;
1030 band = &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
1031 for (i = 0; i < band->n_channels; i++, j++)
1032 channels[j] = band->channels[i].hw_value;
1033 band = &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
1034 for (i = 0; i < band->n_channels; i++, j++)
1035 channels[j] = band->channels[i].hw_value;
1038 static void iwl_mvm_fill_scan_config_v1(struct iwl_mvm *mvm, void *config,
1039 u32 flags, u8 channel_flags)
1041 enum iwl_mvm_scan_type type = iwl_mvm_get_scan_type(mvm, false);
1042 struct iwl_scan_config_v1 *cfg = config;
1044 cfg->flags = cpu_to_le32(flags);
1045 cfg->tx_chains = cpu_to_le32(iwl_mvm_get_valid_tx_ant(mvm));
1046 cfg->rx_chains = cpu_to_le32(iwl_mvm_scan_rx_ant(mvm));
1047 cfg->legacy_rates = iwl_mvm_scan_config_rates(mvm);
1048 cfg->out_of_channel_time = cpu_to_le32(scan_timing[type].max_out_time);
1049 cfg->suspend_time = cpu_to_le32(scan_timing[type].suspend_time);
1051 iwl_mvm_fill_scan_dwell(mvm, &cfg->dwell);
1053 memcpy(&cfg->mac_addr, &mvm->addresses[0].addr, ETH_ALEN);
1055 cfg->bcast_sta_id = mvm->aux_sta.sta_id;
1056 cfg->channel_flags = channel_flags;
1058 iwl_mvm_fill_channels(mvm, cfg->channel_array);
1061 static void iwl_mvm_fill_scan_config(struct iwl_mvm *mvm, void *config,
1062 u32 flags, u8 channel_flags)
1064 struct iwl_scan_config *cfg = config;
1066 cfg->flags = cpu_to_le32(flags);
1067 cfg->tx_chains = cpu_to_le32(iwl_mvm_get_valid_tx_ant(mvm));
1068 cfg->rx_chains = cpu_to_le32(iwl_mvm_scan_rx_ant(mvm));
1069 cfg->legacy_rates = iwl_mvm_scan_config_rates(mvm);
1071 if (iwl_mvm_is_cdb_supported(mvm)) {
1072 enum iwl_mvm_scan_type lb_type, hb_type;
1074 lb_type = iwl_mvm_get_scan_type_band(mvm, false,
1076 hb_type = iwl_mvm_get_scan_type_band(mvm, false,
1079 cfg->out_of_channel_time[SCAN_LB_LMAC_IDX] =
1080 cpu_to_le32(scan_timing[lb_type].max_out_time);
1081 cfg->suspend_time[SCAN_LB_LMAC_IDX] =
1082 cpu_to_le32(scan_timing[lb_type].suspend_time);
1084 cfg->out_of_channel_time[SCAN_HB_LMAC_IDX] =
1085 cpu_to_le32(scan_timing[hb_type].max_out_time);
1086 cfg->suspend_time[SCAN_HB_LMAC_IDX] =
1087 cpu_to_le32(scan_timing[hb_type].suspend_time);
1089 enum iwl_mvm_scan_type type =
1090 iwl_mvm_get_scan_type(mvm, false);
1092 cfg->out_of_channel_time[SCAN_LB_LMAC_IDX] =
1093 cpu_to_le32(scan_timing[type].max_out_time);
1094 cfg->suspend_time[SCAN_LB_LMAC_IDX] =
1095 cpu_to_le32(scan_timing[type].suspend_time);
1098 iwl_mvm_fill_scan_dwell(mvm, &cfg->dwell);
1100 memcpy(&cfg->mac_addr, &mvm->addresses[0].addr, ETH_ALEN);
1102 cfg->bcast_sta_id = mvm->aux_sta.sta_id;
1103 cfg->channel_flags = channel_flags;
1105 iwl_mvm_fill_channels(mvm, cfg->channel_array);
1108 int iwl_mvm_config_scan(struct iwl_mvm *mvm)
1112 struct iwl_host_cmd cmd = {
1113 .id = iwl_cmd_id(SCAN_CFG_CMD, IWL_ALWAYS_LONG_GROUP, 0),
1115 enum iwl_mvm_scan_type type;
1116 enum iwl_mvm_scan_type hb_type = IWL_SCAN_TYPE_NOT_SET;
1118 mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels +
1119 mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels;
1123 if (WARN_ON(num_channels > mvm->fw->ucode_capa.n_scan_channels))
1126 if (iwl_mvm_is_cdb_supported(mvm)) {
1127 type = iwl_mvm_get_scan_type_band(mvm, false,
1129 hb_type = iwl_mvm_get_scan_type_band(mvm, false,
1131 if (type == mvm->scan_type && hb_type == mvm->hb_scan_type)
1134 type = iwl_mvm_get_scan_type(mvm, false);
1135 if (type == mvm->scan_type)
1139 if (iwl_mvm_cdb_scan_api(mvm))
1140 cmd_size = sizeof(struct iwl_scan_config);
1142 cmd_size = sizeof(struct iwl_scan_config_v1);
1143 cmd_size += mvm->fw->ucode_capa.n_scan_channels;
1145 cfg = kzalloc(cmd_size, GFP_KERNEL);
1149 flags = SCAN_CONFIG_FLAG_ACTIVATE |
1150 SCAN_CONFIG_FLAG_ALLOW_CHUB_REQS |
1151 SCAN_CONFIG_FLAG_SET_TX_CHAINS |
1152 SCAN_CONFIG_FLAG_SET_RX_CHAINS |
1153 SCAN_CONFIG_FLAG_SET_AUX_STA_ID |
1154 SCAN_CONFIG_FLAG_SET_ALL_TIMES |
1155 SCAN_CONFIG_FLAG_SET_LEGACY_RATES |
1156 SCAN_CONFIG_FLAG_SET_MAC_ADDR |
1157 SCAN_CONFIG_FLAG_SET_CHANNEL_FLAGS |
1158 SCAN_CONFIG_N_CHANNELS(num_channels) |
1159 (type == IWL_SCAN_TYPE_FRAGMENTED ?
1160 SCAN_CONFIG_FLAG_SET_FRAGMENTED :
1161 SCAN_CONFIG_FLAG_CLEAR_FRAGMENTED);
1163 channel_flags = IWL_CHANNEL_FLAG_EBS |
1164 IWL_CHANNEL_FLAG_ACCURATE_EBS |
1165 IWL_CHANNEL_FLAG_EBS_ADD |
1166 IWL_CHANNEL_FLAG_PRE_SCAN_PASSIVE2ACTIVE;
1169 * Check for fragmented scan on LMAC2 - high band.
1170 * LMAC1 - low band is checked above.
1172 if (iwl_mvm_cdb_scan_api(mvm)) {
1173 if (iwl_mvm_is_cdb_supported(mvm))
1174 flags |= (hb_type == IWL_SCAN_TYPE_FRAGMENTED) ?
1175 SCAN_CONFIG_FLAG_SET_LMAC2_FRAGMENTED :
1176 SCAN_CONFIG_FLAG_CLEAR_LMAC2_FRAGMENTED;
1177 iwl_mvm_fill_scan_config(mvm, cfg, flags, channel_flags);
1179 iwl_mvm_fill_scan_config_v1(mvm, cfg, flags, channel_flags);
1183 cmd.len[0] = cmd_size;
1184 cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
1186 IWL_DEBUG_SCAN(mvm, "Sending UMAC scan config\n");
1188 ret = iwl_mvm_send_cmd(mvm, &cmd);
1190 mvm->scan_type = type;
1191 mvm->hb_scan_type = hb_type;
1198 static int iwl_mvm_scan_uid_by_status(struct iwl_mvm *mvm, int status)
1202 for (i = 0; i < mvm->max_scans; i++)
1203 if (mvm->scan_uid_status[i] == status)
1209 static void iwl_mvm_scan_umac_dwell(struct iwl_mvm *mvm,
1210 struct iwl_scan_req_umac *cmd,
1211 struct iwl_mvm_scan_params *params)
1213 struct iwl_mvm_scan_timing_params *timing, *hb_timing;
1214 u8 active_dwell, passive_dwell;
1216 timing = &scan_timing[params->type];
1217 active_dwell = params->measurement_dwell ?
1218 params->measurement_dwell : IWL_SCAN_DWELL_ACTIVE;
1219 passive_dwell = params->measurement_dwell ?
1220 params->measurement_dwell : IWL_SCAN_DWELL_PASSIVE;
1222 if (iwl_mvm_is_adaptive_dwell_supported(mvm)) {
1223 cmd->v7.adwell_default_n_aps_social =
1224 IWL_SCAN_ADWELL_DEFAULT_N_APS_SOCIAL;
1225 cmd->v7.adwell_default_n_aps =
1226 IWL_SCAN_ADWELL_DEFAULT_N_APS;
1228 /* if custom max budget was configured with debugfs */
1229 if (IWL_MVM_ADWELL_MAX_BUDGET)
1230 cmd->v7.adwell_max_budget =
1231 cpu_to_le16(IWL_MVM_ADWELL_MAX_BUDGET);
1232 else if (params->ssids && params->ssids[0].ssid_len)
1233 cmd->v7.adwell_max_budget =
1234 cpu_to_le16(IWL_SCAN_ADWELL_MAX_BUDGET_DIRECTED_SCAN);
1236 cmd->v7.adwell_max_budget =
1237 cpu_to_le16(IWL_SCAN_ADWELL_MAX_BUDGET_FULL_SCAN);
1239 cmd->v7.scan_priority = cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6);
1240 cmd->v7.max_out_time[SCAN_LB_LMAC_IDX] =
1241 cpu_to_le32(timing->max_out_time);
1242 cmd->v7.suspend_time[SCAN_LB_LMAC_IDX] =
1243 cpu_to_le32(timing->suspend_time);
1245 if (iwl_mvm_is_cdb_supported(mvm)) {
1246 hb_timing = &scan_timing[params->hb_type];
1248 cmd->v7.max_out_time[SCAN_HB_LMAC_IDX] =
1249 cpu_to_le32(hb_timing->max_out_time);
1250 cmd->v7.suspend_time[SCAN_HB_LMAC_IDX] =
1251 cpu_to_le32(hb_timing->suspend_time);
1254 if (!iwl_mvm_is_adaptive_dwell_v2_supported(mvm)) {
1255 cmd->v7.active_dwell = active_dwell;
1256 cmd->v7.passive_dwell = passive_dwell;
1257 cmd->v7.fragmented_dwell = IWL_SCAN_DWELL_FRAGMENTED;
1259 cmd->v8.active_dwell[SCAN_LB_LMAC_IDX] = active_dwell;
1260 cmd->v8.passive_dwell[SCAN_LB_LMAC_IDX] = passive_dwell;
1261 if (iwl_mvm_is_cdb_supported(mvm)) {
1262 cmd->v8.active_dwell[SCAN_HB_LMAC_IDX] =
1264 cmd->v8.passive_dwell[SCAN_HB_LMAC_IDX] =
1269 cmd->v1.extended_dwell = params->measurement_dwell ?
1270 params->measurement_dwell : IWL_SCAN_DWELL_EXTENDED;
1271 cmd->v1.active_dwell = active_dwell;
1272 cmd->v1.passive_dwell = passive_dwell;
1273 cmd->v1.fragmented_dwell = IWL_SCAN_DWELL_FRAGMENTED;
1275 if (iwl_mvm_is_cdb_supported(mvm)) {
1276 hb_timing = &scan_timing[params->hb_type];
1278 cmd->v6.max_out_time[SCAN_HB_LMAC_IDX] =
1279 cpu_to_le32(hb_timing->max_out_time);
1280 cmd->v6.suspend_time[SCAN_HB_LMAC_IDX] =
1281 cpu_to_le32(hb_timing->suspend_time);
1284 if (iwl_mvm_cdb_scan_api(mvm)) {
1285 cmd->v6.scan_priority =
1286 cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6);
1287 cmd->v6.max_out_time[SCAN_LB_LMAC_IDX] =
1288 cpu_to_le32(timing->max_out_time);
1289 cmd->v6.suspend_time[SCAN_LB_LMAC_IDX] =
1290 cpu_to_le32(timing->suspend_time);
1292 cmd->v1.scan_priority =
1293 cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6);
1294 cmd->v1.max_out_time =
1295 cpu_to_le32(timing->max_out_time);
1296 cmd->v1.suspend_time =
1297 cpu_to_le32(timing->suspend_time);
1301 if (iwl_mvm_is_regular_scan(params))
1302 cmd->ooc_priority = cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6);
1304 cmd->ooc_priority = cpu_to_le32(IWL_SCAN_PRIORITY_EXT_2);
1308 iwl_mvm_umac_scan_cfg_channels(struct iwl_mvm *mvm,
1309 struct ieee80211_channel **channels,
1310 int n_channels, u32 ssid_bitmap,
1311 struct iwl_scan_channel_cfg_umac *channel_cfg)
1315 for (i = 0; i < n_channels; i++) {
1316 channel_cfg[i].flags = cpu_to_le32(ssid_bitmap);
1317 channel_cfg[i].channel_num = channels[i]->hw_value;
1318 channel_cfg[i].iter_count = 1;
1319 channel_cfg[i].iter_interval = 0;
1323 static u16 iwl_mvm_scan_umac_flags(struct iwl_mvm *mvm,
1324 struct iwl_mvm_scan_params *params,
1325 struct ieee80211_vif *vif)
1329 if (params->n_ssids == 0)
1330 flags = IWL_UMAC_SCAN_GEN_FLAGS_PASSIVE;
1332 if (params->n_ssids == 1 && params->ssids[0].ssid_len != 0)
1333 flags |= IWL_UMAC_SCAN_GEN_FLAGS_PRE_CONNECT;
1335 if (params->type == IWL_SCAN_TYPE_FRAGMENTED)
1336 flags |= IWL_UMAC_SCAN_GEN_FLAGS_FRAGMENTED;
1338 if (iwl_mvm_is_cdb_supported(mvm) &&
1339 params->hb_type == IWL_SCAN_TYPE_FRAGMENTED)
1340 flags |= IWL_UMAC_SCAN_GEN_FLAGS_LMAC2_FRAGMENTED;
1342 if (iwl_mvm_rrm_scan_needed(mvm) &&
1343 fw_has_capa(&mvm->fw->ucode_capa,
1344 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
1345 flags |= IWL_UMAC_SCAN_GEN_FLAGS_RRM_ENABLED;
1347 if (params->pass_all)
1348 flags |= IWL_UMAC_SCAN_GEN_FLAGS_PASS_ALL;
1350 flags |= IWL_UMAC_SCAN_GEN_FLAGS_MATCH;
1352 if (!iwl_mvm_is_regular_scan(params))
1353 flags |= IWL_UMAC_SCAN_GEN_FLAGS_PERIODIC;
1355 if (params->measurement_dwell)
1356 flags |= IWL_UMAC_SCAN_GEN_FLAGS_ITER_COMPLETE;
1358 #ifdef CONFIG_IWLWIFI_DEBUGFS
1359 if (mvm->scan_iter_notif_enabled)
1360 flags |= IWL_UMAC_SCAN_GEN_FLAGS_ITER_COMPLETE;
1363 if (mvm->sched_scan_pass_all == SCHED_SCAN_PASS_ALL_ENABLED)
1364 flags |= IWL_UMAC_SCAN_GEN_FLAGS_ITER_COMPLETE;
1366 if (iwl_mvm_is_adaptive_dwell_supported(mvm) && IWL_MVM_ADWELL_ENABLE &&
1367 vif->type != NL80211_IFTYPE_P2P_DEVICE)
1368 flags |= IWL_UMAC_SCAN_GEN_FLAGS_ADAPTIVE_DWELL;
1371 * Extended dwell is relevant only for low band to start with, as it is
1372 * being used for social channles only (1, 6, 11), so we can check
1373 * only scan type on low band also for CDB.
1375 if (iwl_mvm_is_regular_scan(params) &&
1376 vif->type != NL80211_IFTYPE_P2P_DEVICE &&
1377 params->type != IWL_SCAN_TYPE_FRAGMENTED &&
1378 !iwl_mvm_is_adaptive_dwell_supported(mvm) &&
1379 !iwl_mvm_is_oce_supported(mvm))
1380 flags |= IWL_UMAC_SCAN_GEN_FLAGS_EXTENDED_DWELL;
1382 if (iwl_mvm_is_oce_supported(mvm)) {
1383 if ((params->flags &
1384 NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE))
1385 flags |= IWL_UMAC_SCAN_GEN_FLAGS_PROB_REQ_HIGH_TX_RATE;
1386 /* Since IWL_UMAC_SCAN_GEN_FLAGS_EXTENDED_DWELL and
1387 * NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION shares
1388 * the same bit, we need to make sure that we use this bit here
1389 * only when IWL_UMAC_SCAN_GEN_FLAGS_EXTENDED_DWELL cannot be
1391 if ((params->flags &
1392 NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) &&
1393 !WARN_ON_ONCE(!iwl_mvm_is_adaptive_dwell_supported(mvm)))
1394 flags |= IWL_UMAC_SCAN_GEN_FLAGS_PROB_REQ_DEFER_SUPP;
1395 if ((params->flags & NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME))
1396 flags |= IWL_UMAC_SCAN_GEN_FLAGS_MAX_CHNL_TIME;
1402 static int iwl_mvm_scan_umac(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1403 struct iwl_mvm_scan_params *params,
1406 struct iwl_scan_req_umac *cmd = mvm->scan_cmd;
1407 struct iwl_scan_umac_chan_param *chan_param;
1408 void *cmd_data = iwl_mvm_get_scan_req_umac_data(mvm);
1409 struct iwl_scan_req_umac_tail *sec_part = cmd_data +
1410 sizeof(struct iwl_scan_channel_cfg_umac) *
1411 mvm->fw->ucode_capa.n_scan_channels;
1413 u32 ssid_bitmap = 0;
1414 u8 channel_flags = 0;
1416 struct iwl_mvm_vif *scan_vif = iwl_mvm_vif_from_mac80211(vif);
1418 chan_param = iwl_mvm_get_scan_req_umac_channel(mvm);
1420 lockdep_assert_held(&mvm->mutex);
1422 if (WARN_ON(params->n_scan_plans > IWL_MAX_SCHED_SCAN_PLANS))
1425 uid = iwl_mvm_scan_uid_by_status(mvm, 0);
1429 memset(cmd, 0, ksize(cmd));
1431 iwl_mvm_scan_umac_dwell(mvm, cmd, params);
1433 mvm->scan_uid_status[uid] = type;
1435 cmd->uid = cpu_to_le32(uid);
1436 gen_flags = iwl_mvm_scan_umac_flags(mvm, params, vif);
1437 cmd->general_flags = cpu_to_le16(gen_flags);
1438 if (iwl_mvm_is_adaptive_dwell_v2_supported(mvm)) {
1439 if (gen_flags & IWL_UMAC_SCAN_GEN_FLAGS_FRAGMENTED)
1440 cmd->v8.num_of_fragments[SCAN_LB_LMAC_IDX] =
1441 IWL_SCAN_NUM_OF_FRAGS;
1442 if (gen_flags & IWL_UMAC_SCAN_GEN_FLAGS_LMAC2_FRAGMENTED)
1443 cmd->v8.num_of_fragments[SCAN_HB_LMAC_IDX] =
1444 IWL_SCAN_NUM_OF_FRAGS;
1447 cmd->scan_start_mac_id = scan_vif->id;
1449 if (type == IWL_MVM_SCAN_SCHED || type == IWL_MVM_SCAN_NETDETECT)
1450 cmd->flags = cpu_to_le32(IWL_UMAC_SCAN_FLAG_PREEMPTIVE);
1452 if (iwl_mvm_scan_use_ebs(mvm, vif))
1453 channel_flags = IWL_SCAN_CHANNEL_FLAG_EBS |
1454 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
1455 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD;
1457 chan_param->flags = channel_flags;
1458 chan_param->count = params->n_channels;
1460 iwl_scan_build_ssids(params, sec_part->direct_scan, &ssid_bitmap);
1462 iwl_mvm_umac_scan_cfg_channels(mvm, params->channels,
1463 params->n_channels, ssid_bitmap,
1466 for (i = 0; i < params->n_scan_plans; i++) {
1467 struct cfg80211_sched_scan_plan *scan_plan =
1468 ¶ms->scan_plans[i];
1470 sec_part->schedule[i].iter_count = scan_plan->iterations;
1471 sec_part->schedule[i].interval =
1472 cpu_to_le16(scan_plan->interval);
1476 * If the number of iterations of the last scan plan is set to
1477 * zero, it should run infinitely. However, this is not always the case.
1478 * For example, when regular scan is requested the driver sets one scan
1479 * plan with one iteration.
1481 if (!sec_part->schedule[i - 1].iter_count)
1482 sec_part->schedule[i - 1].iter_count = 0xff;
1484 sec_part->delay = cpu_to_le16(params->delay);
1485 sec_part->preq = params->preq;
1490 static int iwl_mvm_num_scans(struct iwl_mvm *mvm)
1492 return hweight32(mvm->scan_status & IWL_MVM_SCAN_MASK);
1495 static int iwl_mvm_check_running_scans(struct iwl_mvm *mvm, int type)
1497 bool unified_image = fw_has_capa(&mvm->fw->ucode_capa,
1498 IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG);
1500 /* This looks a bit arbitrary, but the idea is that if we run
1501 * out of possible simultaneous scans and the userspace is
1502 * trying to run a scan type that is already running, we
1503 * return -EBUSY. But if the userspace wants to start a
1504 * different type of scan, we stop the opposite type to make
1505 * space for the new request. The reason is backwards
1506 * compatibility with old wpa_supplicant that wouldn't stop a
1507 * scheduled scan before starting a normal scan.
1510 if (iwl_mvm_num_scans(mvm) < mvm->max_scans)
1513 /* Use a switch, even though this is a bitmask, so that more
1514 * than one bits set will fall in default and we will warn.
1517 case IWL_MVM_SCAN_REGULAR:
1518 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR_MASK)
1520 return iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
1521 case IWL_MVM_SCAN_SCHED:
1522 if (mvm->scan_status & IWL_MVM_SCAN_SCHED_MASK)
1524 return iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
1525 case IWL_MVM_SCAN_NETDETECT:
1526 /* For non-unified images, there's no need to stop
1527 * anything for net-detect since the firmware is
1528 * restarted anyway. This way, any sched scans that
1529 * were running will be restarted when we resume.
1534 /* If this is a unified image and we ran out of scans,
1535 * we need to stop something. Prefer stopping regular
1536 * scans, because the results are useless at this
1537 * point, and we should be able to keep running
1538 * another scheduled scan while suspended.
1540 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR_MASK)
1541 return iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR,
1543 if (mvm->scan_status & IWL_MVM_SCAN_SCHED_MASK)
1544 return iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED,
1547 /* fall through, something is wrong if no scan was
1548 * running but we ran out of scans.
1558 #define SCAN_TIMEOUT 20000
1560 void iwl_mvm_scan_timeout_wk(struct work_struct *work)
1562 struct delayed_work *delayed_work = to_delayed_work(work);
1563 struct iwl_mvm *mvm = container_of(delayed_work, struct iwl_mvm,
1564 scan_timeout_dwork);
1566 IWL_ERR(mvm, "regular scan timed out\n");
1568 iwl_force_nmi(mvm->trans);
1571 static void iwl_mvm_fill_scan_type(struct iwl_mvm *mvm,
1572 struct iwl_mvm_scan_params *params,
1575 if (iwl_mvm_is_cdb_supported(mvm)) {
1577 iwl_mvm_get_scan_type_band(mvm, p2p,
1580 iwl_mvm_get_scan_type_band(mvm, p2p,
1583 params->type = iwl_mvm_get_scan_type(mvm, p2p);
1586 int iwl_mvm_reg_scan_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1587 struct cfg80211_scan_request *req,
1588 struct ieee80211_scan_ies *ies)
1590 struct iwl_host_cmd hcmd = {
1591 .len = { iwl_mvm_scan_size(mvm), },
1592 .data = { mvm->scan_cmd, },
1593 .dataflags = { IWL_HCMD_DFL_NOCOPY, },
1595 struct iwl_mvm_scan_params params = {};
1597 struct cfg80211_sched_scan_plan scan_plan = { .iterations = 1 };
1599 lockdep_assert_held(&mvm->mutex);
1601 if (iwl_mvm_is_lar_supported(mvm) && !mvm->lar_regdom_set) {
1602 IWL_ERR(mvm, "scan while LAR regdomain is not set\n");
1606 ret = iwl_mvm_check_running_scans(mvm, IWL_MVM_SCAN_REGULAR);
1610 /* we should have failed registration if scan_cmd was NULL */
1611 if (WARN_ON(!mvm->scan_cmd))
1614 if (!iwl_mvm_scan_fits(mvm, req->n_ssids, ies, req->n_channels))
1617 params.n_ssids = req->n_ssids;
1618 params.flags = req->flags;
1619 params.n_channels = req->n_channels;
1621 params.ssids = req->ssids;
1622 params.channels = req->channels;
1623 params.mac_addr = req->mac_addr;
1624 params.mac_addr_mask = req->mac_addr_mask;
1625 params.no_cck = req->no_cck;
1626 params.pass_all = true;
1627 params.n_match_sets = 0;
1628 params.match_sets = NULL;
1630 params.scan_plans = &scan_plan;
1631 params.n_scan_plans = 1;
1633 iwl_mvm_fill_scan_type(mvm, ¶ms,
1634 vif->type == NL80211_IFTYPE_P2P_DEVICE);
1636 ret = iwl_mvm_get_measurement_dwell(mvm, req, ¶ms);
1640 params.measurement_dwell = ret;
1642 iwl_mvm_build_scan_probe(mvm, vif, ies, ¶ms);
1644 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
1645 hcmd.id = iwl_cmd_id(SCAN_REQ_UMAC, IWL_ALWAYS_LONG_GROUP, 0);
1646 ret = iwl_mvm_scan_umac(mvm, vif, ¶ms,
1647 IWL_MVM_SCAN_REGULAR);
1649 hcmd.id = SCAN_OFFLOAD_REQUEST_CMD;
1650 ret = iwl_mvm_scan_lmac(mvm, vif, ¶ms);
1656 iwl_mvm_pause_tcm(mvm, false);
1658 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1660 /* If the scan failed, it usually means that the FW was unable
1661 * to allocate the time events. Warn on it, but maybe we
1662 * should try to send the command again with different params.
1664 IWL_ERR(mvm, "Scan failed! ret %d\n", ret);
1665 iwl_mvm_resume_tcm(mvm);
1669 IWL_DEBUG_SCAN(mvm, "Scan request was sent successfully\n");
1670 mvm->scan_status |= IWL_MVM_SCAN_REGULAR;
1671 mvm->scan_vif = iwl_mvm_vif_from_mac80211(vif);
1672 iwl_mvm_ref(mvm, IWL_MVM_REF_SCAN);
1674 schedule_delayed_work(&mvm->scan_timeout_dwork,
1675 msecs_to_jiffies(SCAN_TIMEOUT));
1680 int iwl_mvm_sched_scan_start(struct iwl_mvm *mvm,
1681 struct ieee80211_vif *vif,
1682 struct cfg80211_sched_scan_request *req,
1683 struct ieee80211_scan_ies *ies,
1686 struct iwl_host_cmd hcmd = {
1687 .len = { iwl_mvm_scan_size(mvm), },
1688 .data = { mvm->scan_cmd, },
1689 .dataflags = { IWL_HCMD_DFL_NOCOPY, },
1691 struct iwl_mvm_scan_params params = {};
1694 lockdep_assert_held(&mvm->mutex);
1696 if (iwl_mvm_is_lar_supported(mvm) && !mvm->lar_regdom_set) {
1697 IWL_ERR(mvm, "sched-scan while LAR regdomain is not set\n");
1701 ret = iwl_mvm_check_running_scans(mvm, type);
1705 /* we should have failed registration if scan_cmd was NULL */
1706 if (WARN_ON(!mvm->scan_cmd))
1709 if (!iwl_mvm_scan_fits(mvm, req->n_ssids, ies, req->n_channels))
1712 params.n_ssids = req->n_ssids;
1713 params.flags = req->flags;
1714 params.n_channels = req->n_channels;
1715 params.ssids = req->ssids;
1716 params.channels = req->channels;
1717 params.mac_addr = req->mac_addr;
1718 params.mac_addr_mask = req->mac_addr_mask;
1719 params.no_cck = false;
1720 params.pass_all = iwl_mvm_scan_pass_all(mvm, req);
1721 params.n_match_sets = req->n_match_sets;
1722 params.match_sets = req->match_sets;
1723 if (!req->n_scan_plans)
1726 params.n_scan_plans = req->n_scan_plans;
1727 params.scan_plans = req->scan_plans;
1729 iwl_mvm_fill_scan_type(mvm, ¶ms,
1730 vif->type == NL80211_IFTYPE_P2P_DEVICE);
1732 /* In theory, LMAC scans can handle a 32-bit delay, but since
1733 * waiting for over 18 hours to start the scan is a bit silly
1734 * and to keep it aligned with UMAC scans (which only support
1735 * 16-bit delays), trim it down to 16-bits.
1737 if (req->delay > U16_MAX) {
1739 "delay value is > 16-bits, set to max possible\n");
1740 params.delay = U16_MAX;
1742 params.delay = req->delay;
1745 ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
1749 iwl_mvm_build_scan_probe(mvm, vif, ies, ¶ms);
1751 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
1752 hcmd.id = iwl_cmd_id(SCAN_REQ_UMAC, IWL_ALWAYS_LONG_GROUP, 0);
1753 ret = iwl_mvm_scan_umac(mvm, vif, ¶ms, type);
1755 hcmd.id = SCAN_OFFLOAD_REQUEST_CMD;
1756 ret = iwl_mvm_scan_lmac(mvm, vif, ¶ms);
1762 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1765 "Sched scan request was sent successfully\n");
1766 mvm->scan_status |= type;
1768 /* If the scan failed, it usually means that the FW was unable
1769 * to allocate the time events. Warn on it, but maybe we
1770 * should try to send the command again with different params.
1772 IWL_ERR(mvm, "Sched scan failed! ret %d\n", ret);
1778 void iwl_mvm_rx_umac_scan_complete_notif(struct iwl_mvm *mvm,
1779 struct iwl_rx_cmd_buffer *rxb)
1781 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1782 struct iwl_umac_scan_complete *notif = (void *)pkt->data;
1783 u32 uid = __le32_to_cpu(notif->uid);
1784 bool aborted = (notif->status == IWL_SCAN_OFFLOAD_ABORTED);
1786 if (WARN_ON(!(mvm->scan_uid_status[uid] & mvm->scan_status)))
1789 /* if the scan is already stopping, we don't need to notify mac80211 */
1790 if (mvm->scan_uid_status[uid] == IWL_MVM_SCAN_REGULAR) {
1791 struct cfg80211_scan_info info = {
1793 .scan_start_tsf = mvm->scan_start,
1796 memcpy(info.tsf_bssid, mvm->scan_vif->bssid, ETH_ALEN);
1797 ieee80211_scan_completed(mvm->hw, &info);
1798 mvm->scan_vif = NULL;
1799 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
1800 cancel_delayed_work(&mvm->scan_timeout_dwork);
1801 iwl_mvm_resume_tcm(mvm);
1802 } else if (mvm->scan_uid_status[uid] == IWL_MVM_SCAN_SCHED) {
1803 ieee80211_sched_scan_stopped(mvm->hw);
1804 mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_DISABLED;
1807 mvm->scan_status &= ~mvm->scan_uid_status[uid];
1809 "Scan completed, uid %u type %u, status %s, EBS status %s\n",
1810 uid, mvm->scan_uid_status[uid],
1811 notif->status == IWL_SCAN_OFFLOAD_COMPLETED ?
1812 "completed" : "aborted",
1813 iwl_mvm_ebs_status_str(notif->ebs_status));
1815 "Last line %d, Last iteration %d, Time from last iteration %d\n",
1816 notif->last_schedule, notif->last_iter,
1817 __le32_to_cpu(notif->time_from_last_iter));
1819 if (notif->ebs_status != IWL_SCAN_EBS_SUCCESS &&
1820 notif->ebs_status != IWL_SCAN_EBS_INACTIVE)
1821 mvm->last_ebs_successful = false;
1823 mvm->scan_uid_status[uid] = 0;
1826 void iwl_mvm_rx_umac_scan_iter_complete_notif(struct iwl_mvm *mvm,
1827 struct iwl_rx_cmd_buffer *rxb)
1829 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1830 struct iwl_umac_scan_iter_complete_notif *notif = (void *)pkt->data;
1832 mvm->scan_start = le64_to_cpu(notif->start_tsf);
1835 "UMAC Scan iteration complete: status=0x%x scanned_channels=%d\n",
1836 notif->status, notif->scanned_channels);
1838 if (mvm->sched_scan_pass_all == SCHED_SCAN_PASS_ALL_FOUND) {
1839 IWL_DEBUG_SCAN(mvm, "Pass all scheduled scan results found\n");
1840 ieee80211_sched_scan_results(mvm->hw);
1841 mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_ENABLED;
1845 "UMAC Scan iteration complete: scan started at %llu (TSF)\n",
1849 static int iwl_mvm_umac_scan_abort(struct iwl_mvm *mvm, int type)
1851 struct iwl_umac_scan_abort cmd = {};
1854 lockdep_assert_held(&mvm->mutex);
1856 /* We should always get a valid index here, because we already
1857 * checked that this type of scan was running in the generic
1860 uid = iwl_mvm_scan_uid_by_status(mvm, type);
1861 if (WARN_ON_ONCE(uid < 0))
1864 cmd.uid = cpu_to_le32(uid);
1866 IWL_DEBUG_SCAN(mvm, "Sending scan abort, uid %u\n", uid);
1868 ret = iwl_mvm_send_cmd_pdu(mvm,
1869 iwl_cmd_id(SCAN_ABORT_UMAC,
1870 IWL_ALWAYS_LONG_GROUP, 0),
1871 0, sizeof(cmd), &cmd);
1873 mvm->scan_uid_status[uid] = type << IWL_MVM_SCAN_STOPPING_SHIFT;
1878 static int iwl_mvm_scan_stop_wait(struct iwl_mvm *mvm, int type)
1880 struct iwl_notification_wait wait_scan_done;
1881 static const u16 scan_done_notif[] = { SCAN_COMPLETE_UMAC,
1882 SCAN_OFFLOAD_COMPLETE, };
1885 lockdep_assert_held(&mvm->mutex);
1887 iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_done,
1889 ARRAY_SIZE(scan_done_notif),
1892 IWL_DEBUG_SCAN(mvm, "Preparing to stop scan, type %x\n", type);
1894 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
1895 ret = iwl_mvm_umac_scan_abort(mvm, type);
1897 ret = iwl_mvm_lmac_scan_abort(mvm);
1900 IWL_DEBUG_SCAN(mvm, "couldn't stop scan type %d\n", type);
1901 iwl_remove_notification(&mvm->notif_wait, &wait_scan_done);
1905 ret = iwl_wait_notification(&mvm->notif_wait, &wait_scan_done, 1 * HZ);
1910 int iwl_mvm_scan_size(struct iwl_mvm *mvm)
1912 int base_size = IWL_SCAN_REQ_UMAC_SIZE_V1;
1914 if (iwl_mvm_is_adaptive_dwell_v2_supported(mvm))
1915 base_size = IWL_SCAN_REQ_UMAC_SIZE_V8;
1916 else if (iwl_mvm_is_adaptive_dwell_supported(mvm))
1917 base_size = IWL_SCAN_REQ_UMAC_SIZE_V7;
1918 else if (iwl_mvm_cdb_scan_api(mvm))
1919 base_size = IWL_SCAN_REQ_UMAC_SIZE_V6;
1921 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
1923 sizeof(struct iwl_scan_channel_cfg_umac) *
1924 mvm->fw->ucode_capa.n_scan_channels +
1925 sizeof(struct iwl_scan_req_umac_tail);
1927 return sizeof(struct iwl_scan_req_lmac) +
1928 sizeof(struct iwl_scan_channel_cfg_lmac) *
1929 mvm->fw->ucode_capa.n_scan_channels +
1930 sizeof(struct iwl_scan_probe_req);
1934 * This function is used in nic restart flow, to inform mac80211 about scans
1935 * that was aborted by restart flow or by an assert.
1937 void iwl_mvm_report_scan_aborted(struct iwl_mvm *mvm)
1939 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
1942 uid = iwl_mvm_scan_uid_by_status(mvm, IWL_MVM_SCAN_REGULAR);
1944 struct cfg80211_scan_info info = {
1948 ieee80211_scan_completed(mvm->hw, &info);
1949 mvm->scan_uid_status[uid] = 0;
1951 uid = iwl_mvm_scan_uid_by_status(mvm, IWL_MVM_SCAN_SCHED);
1952 if (uid >= 0 && !mvm->fw_restart) {
1953 ieee80211_sched_scan_stopped(mvm->hw);
1954 mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_DISABLED;
1955 mvm->scan_uid_status[uid] = 0;
1958 /* We shouldn't have any UIDs still set. Loop over all the
1959 * UIDs to make sure there's nothing left there and warn if
1962 for (i = 0; i < mvm->max_scans; i++) {
1963 if (WARN_ONCE(mvm->scan_uid_status[i],
1964 "UMAC scan UID %d status was not cleaned\n",
1966 mvm->scan_uid_status[i] = 0;
1969 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR) {
1970 struct cfg80211_scan_info info = {
1974 ieee80211_scan_completed(mvm->hw, &info);
1977 /* Sched scan will be restarted by mac80211 in
1978 * restart_hw, so do not report if FW is about to be
1981 if ((mvm->scan_status & IWL_MVM_SCAN_SCHED) &&
1983 ieee80211_sched_scan_stopped(mvm->hw);
1984 mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_DISABLED;
1989 int iwl_mvm_scan_stop(struct iwl_mvm *mvm, int type, bool notify)
1993 if (!(mvm->scan_status & type))
1996 if (iwl_mvm_is_radio_killed(mvm)) {
2001 ret = iwl_mvm_scan_stop_wait(mvm, type);
2003 mvm->scan_status |= type << IWL_MVM_SCAN_STOPPING_SHIFT;
2005 /* Clear the scan status so the next scan requests will
2006 * succeed and mark the scan as stopping, so that the Rx
2007 * handler doesn't do anything, as the scan was stopped from
2010 mvm->scan_status &= ~type;
2012 if (type == IWL_MVM_SCAN_REGULAR) {
2013 /* Since the rx handler won't do anything now, we have
2014 * to release the scan reference here.
2016 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
2017 cancel_delayed_work(&mvm->scan_timeout_dwork);
2019 struct cfg80211_scan_info info = {
2023 ieee80211_scan_completed(mvm->hw, &info);
2025 } else if (notify) {
2026 ieee80211_sched_scan_stopped(mvm->hw);
2027 mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_DISABLED;