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
80 #define IWL_SCAN_LAST_2_4_CHN 14
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
92 /* number of scan channels */
93 #define IWL_SCAN_NUM_CHANNELS 112
94 /* adaptive dwell default number of APs override */
95 #define IWL_SCAN_ADWELL_DEFAULT_N_APS_OVERRIDE 10
97 struct iwl_mvm_scan_timing_params
{
102 static struct iwl_mvm_scan_timing_params scan_timing
[] = {
103 [IWL_SCAN_TYPE_UNASSOC
] = {
107 [IWL_SCAN_TYPE_WILD
] = {
111 [IWL_SCAN_TYPE_MILD
] = {
115 [IWL_SCAN_TYPE_FRAGMENTED
] = {
119 [IWL_SCAN_TYPE_FAST_BALANCE
] = {
125 struct iwl_mvm_scan_params
{
126 /* For CDB this is low band scan type, for non-CDB - type. */
127 enum iwl_mvm_scan_type type
;
128 enum iwl_mvm_scan_type hb_type
;
132 struct cfg80211_ssid
*ssids
;
133 struct ieee80211_channel
**channels
;
140 struct iwl_scan_probe_req preq
;
141 struct cfg80211_match_set
*match_sets
;
143 struct cfg80211_sched_scan_plan
*scan_plans
;
144 u32 measurement_dwell
;
147 static inline void *iwl_mvm_get_scan_req_umac_data(struct iwl_mvm
*mvm
)
149 struct iwl_scan_req_umac
*cmd
= mvm
->scan_cmd
;
151 if (iwl_mvm_is_adaptive_dwell_v2_supported(mvm
))
152 return (void *)&cmd
->v8
.data
;
154 if (iwl_mvm_is_adaptive_dwell_supported(mvm
))
155 return (void *)&cmd
->v7
.data
;
157 if (iwl_mvm_cdb_scan_api(mvm
))
158 return (void *)&cmd
->v6
.data
;
160 return (void *)&cmd
->v1
.data
;
163 static inline struct iwl_scan_umac_chan_param
*
164 iwl_mvm_get_scan_req_umac_channel(struct iwl_mvm
*mvm
)
166 struct iwl_scan_req_umac
*cmd
= mvm
->scan_cmd
;
168 if (iwl_mvm_is_adaptive_dwell_v2_supported(mvm
))
169 return &cmd
->v8
.channel
;
171 if (iwl_mvm_is_adaptive_dwell_supported(mvm
))
172 return &cmd
->v7
.channel
;
174 if (iwl_mvm_cdb_scan_api(mvm
))
175 return &cmd
->v6
.channel
;
177 return &cmd
->v1
.channel
;
180 static u8
iwl_mvm_scan_rx_ant(struct iwl_mvm
*mvm
)
182 if (mvm
->scan_rx_ant
!= ANT_NONE
)
183 return mvm
->scan_rx_ant
;
184 return iwl_mvm_get_valid_rx_ant(mvm
);
187 static inline __le16
iwl_mvm_scan_rx_chain(struct iwl_mvm
*mvm
)
192 rx_ant
= iwl_mvm_scan_rx_ant(mvm
);
193 rx_chain
= rx_ant
<< PHY_RX_CHAIN_VALID_POS
;
194 rx_chain
|= rx_ant
<< PHY_RX_CHAIN_FORCE_MIMO_SEL_POS
;
195 rx_chain
|= rx_ant
<< PHY_RX_CHAIN_FORCE_SEL_POS
;
196 rx_chain
|= 0x1 << PHY_RX_CHAIN_DRIVER_FORCE_POS
;
197 return cpu_to_le16(rx_chain
);
201 iwl_mvm_scan_rate_n_flags(struct iwl_mvm
*mvm
, enum nl80211_band band
,
206 iwl_mvm_toggle_tx_ant(mvm
, &mvm
->scan_last_antenna_idx
);
207 tx_ant
= BIT(mvm
->scan_last_antenna_idx
) << RATE_MCS_ANT_POS
;
209 if (band
== NL80211_BAND_2GHZ
&& !no_cck
)
210 return cpu_to_le32(IWL_RATE_1M_PLCP
| RATE_MCS_CCK_MSK
|
213 return cpu_to_le32(IWL_RATE_6M_PLCP
| tx_ant
);
216 static void iwl_mvm_scan_condition_iterator(void *data
, u8
*mac
,
217 struct ieee80211_vif
*vif
)
219 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
220 int *global_cnt
= data
;
222 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
&& mvmvif
->phy_ctxt
&&
223 mvmvif
->phy_ctxt
->id
< NUM_PHY_CTX
)
227 static enum iwl_mvm_traffic_load
iwl_mvm_get_traffic_load(struct iwl_mvm
*mvm
)
229 return mvm
->tcm
.result
.global_load
;
232 static enum iwl_mvm_traffic_load
233 iwl_mvm_get_traffic_load_band(struct iwl_mvm
*mvm
, enum nl80211_band band
)
235 return mvm
->tcm
.result
.band_load
[band
];
238 struct iwl_is_dcm_with_go_iterator_data
{
239 struct ieee80211_vif
*current_vif
;
240 bool is_dcm_with_p2p_go
;
243 static void iwl_mvm_is_dcm_with_go_iterator(void *_data
, u8
*mac
,
244 struct ieee80211_vif
*vif
)
246 struct iwl_is_dcm_with_go_iterator_data
*data
= _data
;
247 struct iwl_mvm_vif
*other_mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
248 struct iwl_mvm_vif
*curr_mvmvif
=
249 iwl_mvm_vif_from_mac80211(data
->current_vif
);
251 /* exclude the given vif */
252 if (vif
== data
->current_vif
)
255 if (vif
->type
== NL80211_IFTYPE_AP
&& vif
->p2p
&&
256 other_mvmvif
->phy_ctxt
&& curr_mvmvif
->phy_ctxt
&&
257 other_mvmvif
->phy_ctxt
->id
!= curr_mvmvif
->phy_ctxt
->id
)
258 data
->is_dcm_with_p2p_go
= true;
262 iwl_mvm_scan_type
_iwl_mvm_get_scan_type(struct iwl_mvm
*mvm
,
263 struct ieee80211_vif
*vif
,
264 enum iwl_mvm_traffic_load load
,
269 ieee80211_iterate_active_interfaces_atomic(mvm
->hw
,
270 IEEE80211_IFACE_ITER_NORMAL
,
271 iwl_mvm_scan_condition_iterator
,
274 return IWL_SCAN_TYPE_UNASSOC
;
276 if (fw_has_api(&mvm
->fw
->ucode_capa
,
277 IWL_UCODE_TLV_API_FRAGMENTED_SCAN
)) {
278 if ((load
== IWL_MVM_TRAFFIC_HIGH
|| low_latency
) &&
279 (!vif
|| vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
))
280 return IWL_SCAN_TYPE_FRAGMENTED
;
282 /* in case of DCM with GO where BSS DTIM interval < 220msec
283 * set all scan requests as fast-balance scan
285 if (vif
&& vif
->type
== NL80211_IFTYPE_STATION
&&
286 vif
->bss_conf
.dtim_period
< 220) {
287 struct iwl_is_dcm_with_go_iterator_data data
= {
289 .is_dcm_with_p2p_go
= false,
292 ieee80211_iterate_active_interfaces_atomic(mvm
->hw
,
293 IEEE80211_IFACE_ITER_NORMAL
,
294 iwl_mvm_is_dcm_with_go_iterator
,
296 if (data
.is_dcm_with_p2p_go
)
297 return IWL_SCAN_TYPE_FAST_BALANCE
;
301 if (load
>= IWL_MVM_TRAFFIC_MEDIUM
|| low_latency
)
302 return IWL_SCAN_TYPE_MILD
;
304 return IWL_SCAN_TYPE_WILD
;
308 iwl_mvm_scan_type
iwl_mvm_get_scan_type(struct iwl_mvm
*mvm
,
309 struct ieee80211_vif
*vif
)
311 enum iwl_mvm_traffic_load load
;
314 load
= iwl_mvm_get_traffic_load(mvm
);
315 low_latency
= iwl_mvm_low_latency(mvm
);
317 return _iwl_mvm_get_scan_type(mvm
, vif
, load
, low_latency
);
321 iwl_mvm_scan_type
iwl_mvm_get_scan_type_band(struct iwl_mvm
*mvm
,
322 struct ieee80211_vif
*vif
,
323 enum nl80211_band band
)
325 enum iwl_mvm_traffic_load load
;
328 load
= iwl_mvm_get_traffic_load_band(mvm
, band
);
329 low_latency
= iwl_mvm_low_latency_band(mvm
, band
);
331 return _iwl_mvm_get_scan_type(mvm
, vif
, load
, low_latency
);
335 iwl_mvm_get_measurement_dwell(struct iwl_mvm
*mvm
,
336 struct cfg80211_scan_request
*req
,
337 struct iwl_mvm_scan_params
*params
)
339 u32 duration
= scan_timing
[params
->type
].max_out_time
;
344 if (iwl_mvm_is_cdb_supported(mvm
)) {
345 u32 hb_time
= scan_timing
[params
->hb_type
].max_out_time
;
347 duration
= min_t(u32
, duration
, hb_time
);
350 if (req
->duration_mandatory
&& req
->duration
> duration
) {
352 "Measurement scan - too long dwell %hu (max out time %u)\n",
358 return min_t(u32
, (u32
)req
->duration
, duration
);
361 static inline bool iwl_mvm_rrm_scan_needed(struct iwl_mvm
*mvm
)
363 /* require rrm scan whenever the fw supports it */
364 return fw_has_capa(&mvm
->fw
->ucode_capa
,
365 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT
);
368 static int iwl_mvm_max_scan_ie_fw_cmd_room(struct iwl_mvm
*mvm
)
372 max_probe_len
= SCAN_OFFLOAD_PROBE_REQ_SIZE
;
374 /* we create the 802.11 header and SSID element */
375 max_probe_len
-= 24 + 2;
377 /* DS parameter set element is added on 2.4GHZ band if required */
378 if (iwl_mvm_rrm_scan_needed(mvm
))
381 return max_probe_len
;
384 int iwl_mvm_max_scan_ie_len(struct iwl_mvm
*mvm
)
386 int max_ie_len
= iwl_mvm_max_scan_ie_fw_cmd_room(mvm
);
388 /* TODO: [BUG] This function should return the maximum allowed size of
389 * scan IEs, however the LMAC scan api contains both 2GHZ and 5GHZ IEs
390 * in the same command. So the correct implementation of this function
391 * is just iwl_mvm_max_scan_ie_fw_cmd_room() / 2. Currently the scan
392 * command has only 512 bytes and it would leave us with about 240
393 * bytes for scan IEs, which is clearly not enough. So meanwhile
394 * we will report an incorrect value. This may result in a failure to
395 * issue a scan in unified_scan_lmac and unified_sched_scan_lmac
396 * functions with -ENOBUFS, if a large enough probe will be provided.
401 void iwl_mvm_rx_lmac_scan_iter_complete_notif(struct iwl_mvm
*mvm
,
402 struct iwl_rx_cmd_buffer
*rxb
)
404 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
405 struct iwl_lmac_scan_complete_notif
*notif
= (void *)pkt
->data
;
408 "Scan offload iteration complete: status=0x%x scanned channels=%d\n",
409 notif
->status
, notif
->scanned_channels
);
411 if (mvm
->sched_scan_pass_all
== SCHED_SCAN_PASS_ALL_FOUND
) {
412 IWL_DEBUG_SCAN(mvm
, "Pass all scheduled scan results found\n");
413 ieee80211_sched_scan_results(mvm
->hw
);
414 mvm
->sched_scan_pass_all
= SCHED_SCAN_PASS_ALL_ENABLED
;
418 void iwl_mvm_rx_scan_match_found(struct iwl_mvm
*mvm
,
419 struct iwl_rx_cmd_buffer
*rxb
)
421 IWL_DEBUG_SCAN(mvm
, "Scheduled scan results\n");
422 ieee80211_sched_scan_results(mvm
->hw
);
425 static const char *iwl_mvm_ebs_status_str(enum iwl_scan_ebs_status status
)
428 case IWL_SCAN_EBS_SUCCESS
:
430 case IWL_SCAN_EBS_INACTIVE
:
432 case IWL_SCAN_EBS_FAILED
:
433 case IWL_SCAN_EBS_CHAN_NOT_FOUND
:
439 void iwl_mvm_rx_lmac_scan_complete_notif(struct iwl_mvm
*mvm
,
440 struct iwl_rx_cmd_buffer
*rxb
)
442 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
443 struct iwl_periodic_scan_complete
*scan_notif
= (void *)pkt
->data
;
444 bool aborted
= (scan_notif
->status
== IWL_SCAN_OFFLOAD_ABORTED
);
446 /* If this happens, the firmware has mistakenly sent an LMAC
447 * notification during UMAC scans -- warn and ignore it.
449 if (WARN_ON_ONCE(fw_has_capa(&mvm
->fw
->ucode_capa
,
450 IWL_UCODE_TLV_CAPA_UMAC_SCAN
)))
453 /* scan status must be locked for proper checking */
454 lockdep_assert_held(&mvm
->mutex
);
456 /* We first check if we were stopping a scan, in which case we
457 * just clear the stopping flag. Then we check if it was a
458 * firmware initiated stop, in which case we need to inform
460 * Note that we can have a stopping and a running scan
461 * simultaneously, but we can't have two different types of
462 * scans stopping or running at the same time (since LMAC
463 * doesn't support it).
466 if (mvm
->scan_status
& IWL_MVM_SCAN_STOPPING_SCHED
) {
467 WARN_ON_ONCE(mvm
->scan_status
& IWL_MVM_SCAN_STOPPING_REGULAR
);
469 IWL_DEBUG_SCAN(mvm
, "Scheduled scan %s, EBS status %s\n",
470 aborted
? "aborted" : "completed",
471 iwl_mvm_ebs_status_str(scan_notif
->ebs_status
));
473 "Last line %d, Last iteration %d, Time after last iteration %d\n",
474 scan_notif
->last_schedule_line
,
475 scan_notif
->last_schedule_iteration
,
476 __le32_to_cpu(scan_notif
->time_after_last_iter
));
478 mvm
->scan_status
&= ~IWL_MVM_SCAN_STOPPING_SCHED
;
479 } else if (mvm
->scan_status
& IWL_MVM_SCAN_STOPPING_REGULAR
) {
480 IWL_DEBUG_SCAN(mvm
, "Regular scan %s, EBS status %s\n",
481 aborted
? "aborted" : "completed",
482 iwl_mvm_ebs_status_str(scan_notif
->ebs_status
));
484 mvm
->scan_status
&= ~IWL_MVM_SCAN_STOPPING_REGULAR
;
485 } else if (mvm
->scan_status
& IWL_MVM_SCAN_SCHED
) {
486 WARN_ON_ONCE(mvm
->scan_status
& IWL_MVM_SCAN_REGULAR
);
488 IWL_DEBUG_SCAN(mvm
, "Scheduled scan %s, EBS status %s\n",
489 aborted
? "aborted" : "completed",
490 iwl_mvm_ebs_status_str(scan_notif
->ebs_status
));
492 "Last line %d, Last iteration %d, Time after last iteration %d (FW)\n",
493 scan_notif
->last_schedule_line
,
494 scan_notif
->last_schedule_iteration
,
495 __le32_to_cpu(scan_notif
->time_after_last_iter
));
497 mvm
->scan_status
&= ~IWL_MVM_SCAN_SCHED
;
498 ieee80211_sched_scan_stopped(mvm
->hw
);
499 mvm
->sched_scan_pass_all
= SCHED_SCAN_PASS_ALL_DISABLED
;
500 } else if (mvm
->scan_status
& IWL_MVM_SCAN_REGULAR
) {
501 struct cfg80211_scan_info info
= {
505 IWL_DEBUG_SCAN(mvm
, "Regular scan %s, EBS status %s (FW)\n",
506 aborted
? "aborted" : "completed",
507 iwl_mvm_ebs_status_str(scan_notif
->ebs_status
));
509 mvm
->scan_status
&= ~IWL_MVM_SCAN_REGULAR
;
510 ieee80211_scan_completed(mvm
->hw
, &info
);
511 cancel_delayed_work(&mvm
->scan_timeout_dwork
);
512 iwl_mvm_resume_tcm(mvm
);
515 "got scan complete notification but no scan is running\n");
518 mvm
->last_ebs_successful
=
519 scan_notif
->ebs_status
== IWL_SCAN_EBS_SUCCESS
||
520 scan_notif
->ebs_status
== IWL_SCAN_EBS_INACTIVE
;
523 static int iwl_ssid_exist(u8
*ssid
, u8 ssid_len
, struct iwl_ssid_ie
*ssid_list
)
527 for (i
= 0; i
< PROBE_OPTION_MAX
; i
++) {
528 if (!ssid_list
[i
].len
)
530 if (ssid_list
[i
].len
== ssid_len
&&
531 !memcmp(ssid_list
->ssid
, ssid
, ssid_len
))
537 /* We insert the SSIDs in an inverted order, because the FW will
540 static void iwl_scan_build_ssids(struct iwl_mvm_scan_params
*params
,
541 struct iwl_ssid_ie
*ssids
,
549 * copy SSIDs from match list.
550 * iwl_config_sched_scan_profiles() uses the order of these ssids to
553 for (i
= 0, j
= params
->n_match_sets
- 1;
554 j
>= 0 && i
< PROBE_OPTION_MAX
;
556 /* skip empty SSID matchsets */
557 if (!params
->match_sets
[j
].ssid
.ssid_len
)
559 ssids
[i
].id
= WLAN_EID_SSID
;
560 ssids
[i
].len
= params
->match_sets
[j
].ssid
.ssid_len
;
561 memcpy(ssids
[i
].ssid
, params
->match_sets
[j
].ssid
.ssid
,
565 /* add SSIDs from scan SSID list */
566 for (j
= params
->n_ssids
- 1;
567 j
>= 0 && i
< PROBE_OPTION_MAX
;
569 index
= iwl_ssid_exist(params
->ssids
[j
].ssid
,
570 params
->ssids
[j
].ssid_len
,
573 ssids
[i
].id
= WLAN_EID_SSID
;
574 ssids
[i
].len
= params
->ssids
[j
].ssid_len
;
575 memcpy(ssids
[i
].ssid
, params
->ssids
[j
].ssid
,
577 tmp_bitmap
|= BIT(i
);
579 tmp_bitmap
|= BIT(index
);
583 *ssid_bitmap
= tmp_bitmap
;
587 iwl_mvm_config_sched_scan_profiles(struct iwl_mvm
*mvm
,
588 struct cfg80211_sched_scan_request
*req
)
590 struct iwl_scan_offload_profile
*profile
;
591 struct iwl_scan_offload_profile_cfg
*profile_cfg
;
592 struct iwl_scan_offload_blacklist
*blacklist
;
593 struct iwl_host_cmd cmd
= {
594 .id
= SCAN_OFFLOAD_UPDATE_PROFILES_CMD
,
595 .len
[1] = sizeof(*profile_cfg
),
596 .dataflags
[0] = IWL_HCMD_DFL_NOCOPY
,
597 .dataflags
[1] = IWL_HCMD_DFL_NOCOPY
,
603 if (WARN_ON(req
->n_match_sets
> IWL_SCAN_MAX_PROFILES
))
606 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_SHORT_BL
)
607 blacklist_len
= IWL_SCAN_SHORT_BLACKLIST_LEN
;
609 blacklist_len
= IWL_SCAN_MAX_BLACKLIST_LEN
;
611 blacklist
= kcalloc(blacklist_len
, sizeof(*blacklist
), GFP_KERNEL
);
615 profile_cfg
= kzalloc(sizeof(*profile_cfg
), GFP_KERNEL
);
621 cmd
.data
[0] = blacklist
;
622 cmd
.len
[0] = sizeof(*blacklist
) * blacklist_len
;
623 cmd
.data
[1] = profile_cfg
;
625 /* No blacklist configuration */
627 profile_cfg
->num_profiles
= req
->n_match_sets
;
628 profile_cfg
->active_clients
= SCAN_CLIENT_SCHED_SCAN
;
629 profile_cfg
->pass_match
= SCAN_CLIENT_SCHED_SCAN
;
630 profile_cfg
->match_notify
= SCAN_CLIENT_SCHED_SCAN
;
631 if (!req
->n_match_sets
|| !req
->match_sets
[0].ssid
.ssid_len
)
632 profile_cfg
->any_beacon_notify
= SCAN_CLIENT_SCHED_SCAN
;
634 for (i
= 0; i
< req
->n_match_sets
; i
++) {
635 profile
= &profile_cfg
->profiles
[i
];
636 profile
->ssid_index
= i
;
637 /* Support any cipher and auth algorithm */
638 profile
->unicast_cipher
= 0xff;
639 profile
->auth_alg
= 0xff;
640 profile
->network_type
= IWL_NETWORK_TYPE_ANY
;
641 profile
->band_selection
= IWL_SCAN_OFFLOAD_SELECT_ANY
;
642 profile
->client_bitmap
= SCAN_CLIENT_SCHED_SCAN
;
645 IWL_DEBUG_SCAN(mvm
, "Sending scheduled scan profile config\n");
647 ret
= iwl_mvm_send_cmd(mvm
, &cmd
);
655 static bool iwl_mvm_scan_pass_all(struct iwl_mvm
*mvm
,
656 struct cfg80211_sched_scan_request
*req
)
658 if (req
->n_match_sets
&& req
->match_sets
[0].ssid
.ssid_len
) {
660 "Sending scheduled scan with filtering, n_match_sets %d\n",
662 mvm
->sched_scan_pass_all
= SCHED_SCAN_PASS_ALL_DISABLED
;
666 IWL_DEBUG_SCAN(mvm
, "Sending Scheduled scan without filtering\n");
668 mvm
->sched_scan_pass_all
= SCHED_SCAN_PASS_ALL_ENABLED
;
672 static int iwl_mvm_lmac_scan_abort(struct iwl_mvm
*mvm
)
675 struct iwl_host_cmd cmd
= {
676 .id
= SCAN_OFFLOAD_ABORT_CMD
,
678 u32 status
= CAN_ABORT_STATUS
;
680 ret
= iwl_mvm_send_cmd_status(mvm
, &cmd
, &status
);
684 if (status
!= CAN_ABORT_STATUS
) {
686 * The scan abort will return 1 for success or
687 * 2 for "failure". A failure condition can be
688 * due to simply not being in an active scan which
689 * can occur if we send the scan abort before the
690 * microcode has notified us that a scan is completed.
692 IWL_DEBUG_SCAN(mvm
, "SCAN OFFLOAD ABORT ret %d.\n", status
);
699 static void iwl_mvm_scan_fill_tx_cmd(struct iwl_mvm
*mvm
,
700 struct iwl_scan_req_tx_cmd
*tx_cmd
,
703 tx_cmd
[0].tx_flags
= cpu_to_le32(TX_CMD_FLG_SEQ_CTL
|
705 tx_cmd
[0].rate_n_flags
= iwl_mvm_scan_rate_n_flags(mvm
,
708 tx_cmd
[0].sta_id
= mvm
->aux_sta
.sta_id
;
710 tx_cmd
[1].tx_flags
= cpu_to_le32(TX_CMD_FLG_SEQ_CTL
|
712 tx_cmd
[1].rate_n_flags
= iwl_mvm_scan_rate_n_flags(mvm
,
715 tx_cmd
[1].sta_id
= mvm
->aux_sta
.sta_id
;
719 iwl_mvm_lmac_scan_cfg_channels(struct iwl_mvm
*mvm
,
720 struct ieee80211_channel
**channels
,
721 int n_channels
, u32 ssid_bitmap
,
722 struct iwl_scan_req_lmac
*cmd
)
724 struct iwl_scan_channel_cfg_lmac
*channel_cfg
= (void *)&cmd
->data
;
727 for (i
= 0; i
< n_channels
; i
++) {
728 channel_cfg
[i
].channel_num
=
729 cpu_to_le16(channels
[i
]->hw_value
);
730 channel_cfg
[i
].iter_count
= cpu_to_le16(1);
731 channel_cfg
[i
].iter_interval
= 0;
732 channel_cfg
[i
].flags
=
733 cpu_to_le32(IWL_UNIFIED_SCAN_CHANNEL_PARTIAL
|
738 static u8
*iwl_mvm_copy_and_insert_ds_elem(struct iwl_mvm
*mvm
, const u8
*ies
,
739 size_t len
, u8
*const pos
)
741 static const u8 before_ds_params
[] = {
745 WLAN_EID_EXT_SUPP_RATES
,
750 if (!iwl_mvm_rrm_scan_needed(mvm
)) {
751 memcpy(newpos
, ies
, len
);
755 offs
= ieee80211_ie_split(ies
, len
,
757 ARRAY_SIZE(before_ds_params
),
760 memcpy(newpos
, ies
, offs
);
763 /* Add a placeholder for DS Parameter Set element */
764 *newpos
++ = WLAN_EID_DS_PARAMS
;
768 memcpy(newpos
, ies
+ offs
, len
- offs
);
769 newpos
+= len
- offs
;
774 #define WFA_TPC_IE_LEN 9
776 static void iwl_mvm_add_tpc_report_ie(u8
*pos
)
778 pos
[0] = WLAN_EID_VENDOR_SPECIFIC
;
779 pos
[1] = WFA_TPC_IE_LEN
- 2;
780 pos
[2] = (WLAN_OUI_MICROSOFT
>> 16) & 0xff;
781 pos
[3] = (WLAN_OUI_MICROSOFT
>> 8) & 0xff;
782 pos
[4] = WLAN_OUI_MICROSOFT
& 0xff;
783 pos
[5] = WLAN_OUI_TYPE_MICROSOFT_TPC
;
785 /* pos[7] - tx power will be inserted by the FW */
791 iwl_mvm_build_scan_probe(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
792 struct ieee80211_scan_ies
*ies
,
793 struct iwl_mvm_scan_params
*params
)
795 struct ieee80211_mgmt
*frame
= (void *)params
->preq
.buf
;
797 const u8
*mac_addr
= params
->flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
?
798 params
->mac_addr
: NULL
;
801 * Unfortunately, right now the offload scan doesn't support randomising
802 * within the firmware, so until the firmware API is ready we implement
803 * it in the driver. This means that the scan iterations won't really be
804 * random, only when it's restarted, but at least that helps a bit.
807 get_random_mask_addr(frame
->sa
, mac_addr
,
808 params
->mac_addr_mask
);
810 memcpy(frame
->sa
, vif
->addr
, ETH_ALEN
);
812 frame
->frame_control
= cpu_to_le16(IEEE80211_STYPE_PROBE_REQ
);
813 eth_broadcast_addr(frame
->da
);
814 eth_broadcast_addr(frame
->bssid
);
817 pos
= frame
->u
.probe_req
.variable
;
818 *pos
++ = WLAN_EID_SSID
;
821 params
->preq
.mac_header
.offset
= 0;
822 params
->preq
.mac_header
.len
= cpu_to_le16(24 + 2);
824 /* Insert ds parameter set element on 2.4 GHz band */
825 newpos
= iwl_mvm_copy_and_insert_ds_elem(mvm
,
826 ies
->ies
[NL80211_BAND_2GHZ
],
827 ies
->len
[NL80211_BAND_2GHZ
],
829 params
->preq
.band_data
[0].offset
= cpu_to_le16(pos
- params
->preq
.buf
);
830 params
->preq
.band_data
[0].len
= cpu_to_le16(newpos
- pos
);
833 memcpy(pos
, ies
->ies
[NL80211_BAND_5GHZ
],
834 ies
->len
[NL80211_BAND_5GHZ
]);
835 params
->preq
.band_data
[1].offset
= cpu_to_le16(pos
- params
->preq
.buf
);
836 params
->preq
.band_data
[1].len
=
837 cpu_to_le16(ies
->len
[NL80211_BAND_5GHZ
]);
838 pos
+= ies
->len
[NL80211_BAND_5GHZ
];
840 memcpy(pos
, ies
->common_ies
, ies
->common_ie_len
);
841 params
->preq
.common_data
.offset
= cpu_to_le16(pos
- params
->preq
.buf
);
843 if (iwl_mvm_rrm_scan_needed(mvm
) &&
844 !fw_has_capa(&mvm
->fw
->ucode_capa
,
845 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT
)) {
846 iwl_mvm_add_tpc_report_ie(pos
+ ies
->common_ie_len
);
847 params
->preq
.common_data
.len
= cpu_to_le16(ies
->common_ie_len
+
850 params
->preq
.common_data
.len
= cpu_to_le16(ies
->common_ie_len
);
854 static void iwl_mvm_scan_lmac_dwell(struct iwl_mvm
*mvm
,
855 struct iwl_scan_req_lmac
*cmd
,
856 struct iwl_mvm_scan_params
*params
)
858 cmd
->active_dwell
= IWL_SCAN_DWELL_ACTIVE
;
859 cmd
->passive_dwell
= IWL_SCAN_DWELL_PASSIVE
;
860 cmd
->fragmented_dwell
= IWL_SCAN_DWELL_FRAGMENTED
;
861 cmd
->extended_dwell
= IWL_SCAN_DWELL_EXTENDED
;
862 cmd
->max_out_time
= cpu_to_le32(scan_timing
[params
->type
].max_out_time
);
863 cmd
->suspend_time
= cpu_to_le32(scan_timing
[params
->type
].suspend_time
);
864 cmd
->scan_prio
= cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6
);
867 static inline bool iwl_mvm_scan_fits(struct iwl_mvm
*mvm
, int n_ssids
,
868 struct ieee80211_scan_ies
*ies
,
871 return ((n_ssids
<= PROBE_OPTION_MAX
) &&
872 (n_channels
<= mvm
->fw
->ucode_capa
.n_scan_channels
) &
873 (ies
->common_ie_len
+
874 ies
->len
[NL80211_BAND_2GHZ
] +
875 ies
->len
[NL80211_BAND_5GHZ
] <=
876 iwl_mvm_max_scan_ie_fw_cmd_room(mvm
)));
879 static inline bool iwl_mvm_scan_use_ebs(struct iwl_mvm
*mvm
,
880 struct ieee80211_vif
*vif
)
882 const struct iwl_ucode_capabilities
*capa
= &mvm
->fw
->ucode_capa
;
885 if (iwl_mvm_is_cdb_supported(mvm
))
886 low_latency
= iwl_mvm_low_latency_band(mvm
, NL80211_BAND_5GHZ
);
888 low_latency
= iwl_mvm_low_latency(mvm
);
890 /* We can only use EBS if:
891 * 1. the feature is supported;
892 * 2. the last EBS was successful;
893 * 3. if only single scan, the single scan EBS API is supported;
894 * 4. it's not a p2p find operation.
895 * 5. we are not in low latency mode,
896 * or if fragmented ebs is supported by the FW
898 return ((capa
->flags
& IWL_UCODE_TLV_FLAGS_EBS_SUPPORT
) &&
899 mvm
->last_ebs_successful
&& IWL_MVM_ENABLE_EBS
&&
900 vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
&&
901 (!low_latency
|| iwl_mvm_is_frag_ebs_supported(mvm
)));
904 static inline bool iwl_mvm_is_regular_scan(struct iwl_mvm_scan_params
*params
)
906 return params
->n_scan_plans
== 1 &&
907 params
->scan_plans
[0].iterations
== 1;
910 static bool iwl_mvm_is_scan_fragmented(enum iwl_mvm_scan_type type
)
912 return (type
== IWL_SCAN_TYPE_FRAGMENTED
||
913 type
== IWL_SCAN_TYPE_FAST_BALANCE
);
916 static int iwl_mvm_scan_lmac_flags(struct iwl_mvm
*mvm
,
917 struct iwl_mvm_scan_params
*params
,
918 struct ieee80211_vif
*vif
)
922 if (params
->n_ssids
== 0)
923 flags
|= IWL_MVM_LMAC_SCAN_FLAG_PASSIVE
;
925 if (params
->n_ssids
== 1 && params
->ssids
[0].ssid_len
!= 0)
926 flags
|= IWL_MVM_LMAC_SCAN_FLAG_PRE_CONNECTION
;
928 if (iwl_mvm_is_scan_fragmented(params
->type
))
929 flags
|= IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED
;
931 if (iwl_mvm_rrm_scan_needed(mvm
) &&
932 fw_has_capa(&mvm
->fw
->ucode_capa
,
933 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT
))
934 flags
|= IWL_MVM_LMAC_SCAN_FLAGS_RRM_ENABLED
;
936 if (params
->pass_all
)
937 flags
|= IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL
;
939 flags
|= IWL_MVM_LMAC_SCAN_FLAG_MATCH
;
941 #ifdef CONFIG_IWLWIFI_DEBUGFS
942 if (mvm
->scan_iter_notif_enabled
)
943 flags
|= IWL_MVM_LMAC_SCAN_FLAG_ITER_COMPLETE
;
946 if (mvm
->sched_scan_pass_all
== SCHED_SCAN_PASS_ALL_ENABLED
)
947 flags
|= IWL_MVM_LMAC_SCAN_FLAG_ITER_COMPLETE
;
949 if (iwl_mvm_is_regular_scan(params
) &&
950 vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
&&
951 !iwl_mvm_is_scan_fragmented(params
->type
))
952 flags
|= IWL_MVM_LMAC_SCAN_FLAG_EXTENDED_DWELL
;
958 iwl_mvm_scan_set_legacy_probe_req(struct iwl_scan_probe_req_v1
*p_req
,
959 struct iwl_scan_probe_req
*src_p_req
)
963 p_req
->mac_header
= src_p_req
->mac_header
;
964 for (i
= 0; i
< SCAN_NUM_BAND_PROBE_DATA_V_1
; i
++)
965 p_req
->band_data
[i
] = src_p_req
->band_data
[i
];
966 p_req
->common_data
= src_p_req
->common_data
;
967 memcpy(p_req
->buf
, src_p_req
->buf
, sizeof(p_req
->buf
));
970 static int iwl_mvm_scan_lmac(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
971 struct iwl_mvm_scan_params
*params
)
973 struct iwl_scan_req_lmac
*cmd
= mvm
->scan_cmd
;
974 struct iwl_scan_probe_req_v1
*preq
=
975 (void *)(cmd
->data
+ sizeof(struct iwl_scan_channel_cfg_lmac
) *
976 mvm
->fw
->ucode_capa
.n_scan_channels
);
981 if (WARN_ON(params
->n_scan_plans
> IWL_MAX_SCHED_SCAN_PLANS
))
984 iwl_mvm_scan_lmac_dwell(mvm
, cmd
, params
);
986 cmd
->rx_chain_select
= iwl_mvm_scan_rx_chain(mvm
);
987 cmd
->iter_num
= cpu_to_le32(1);
988 cmd
->n_channels
= (u8
)params
->n_channels
;
990 cmd
->delay
= cpu_to_le32(params
->delay
);
992 cmd
->scan_flags
= cpu_to_le32(iwl_mvm_scan_lmac_flags(mvm
, params
,
995 band
= iwl_mvm_phy_band_from_nl80211(params
->channels
[0]->band
);
996 cmd
->flags
= cpu_to_le32(band
);
997 cmd
->filter_flags
= cpu_to_le32(MAC_FILTER_ACCEPT_GRP
|
998 MAC_FILTER_IN_BEACON
);
999 iwl_mvm_scan_fill_tx_cmd(mvm
, cmd
->tx_cmd
, params
->no_cck
);
1000 iwl_scan_build_ssids(params
, cmd
->direct_scan
, &ssid_bitmap
);
1002 /* this API uses bits 1-20 instead of 0-19 */
1005 for (i
= 0; i
< params
->n_scan_plans
; i
++) {
1006 struct cfg80211_sched_scan_plan
*scan_plan
=
1007 ¶ms
->scan_plans
[i
];
1009 cmd
->schedule
[i
].delay
=
1010 cpu_to_le16(scan_plan
->interval
);
1011 cmd
->schedule
[i
].iterations
= scan_plan
->iterations
;
1012 cmd
->schedule
[i
].full_scan_mul
= 1;
1016 * If the number of iterations of the last scan plan is set to
1017 * zero, it should run infinitely. However, this is not always the case.
1018 * For example, when regular scan is requested the driver sets one scan
1019 * plan with one iteration.
1021 if (!cmd
->schedule
[i
- 1].iterations
)
1022 cmd
->schedule
[i
- 1].iterations
= 0xff;
1024 if (iwl_mvm_scan_use_ebs(mvm
, vif
)) {
1025 cmd
->channel_opt
[0].flags
=
1026 cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS
|
1027 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE
|
1028 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD
);
1029 cmd
->channel_opt
[0].non_ebs_ratio
=
1030 cpu_to_le16(IWL_DENSE_EBS_SCAN_RATIO
);
1031 cmd
->channel_opt
[1].flags
=
1032 cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS
|
1033 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE
|
1034 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD
);
1035 cmd
->channel_opt
[1].non_ebs_ratio
=
1036 cpu_to_le16(IWL_SPARSE_EBS_SCAN_RATIO
);
1039 iwl_mvm_lmac_scan_cfg_channels(mvm
, params
->channels
,
1040 params
->n_channels
, ssid_bitmap
, cmd
);
1042 iwl_mvm_scan_set_legacy_probe_req(preq
, ¶ms
->preq
);
1047 static int rate_to_scan_rate_flag(unsigned int rate
)
1049 static const int rate_to_scan_rate
[IWL_RATE_COUNT
] = {
1050 [IWL_RATE_1M_INDEX
] = SCAN_CONFIG_RATE_1M
,
1051 [IWL_RATE_2M_INDEX
] = SCAN_CONFIG_RATE_2M
,
1052 [IWL_RATE_5M_INDEX
] = SCAN_CONFIG_RATE_5M
,
1053 [IWL_RATE_11M_INDEX
] = SCAN_CONFIG_RATE_11M
,
1054 [IWL_RATE_6M_INDEX
] = SCAN_CONFIG_RATE_6M
,
1055 [IWL_RATE_9M_INDEX
] = SCAN_CONFIG_RATE_9M
,
1056 [IWL_RATE_12M_INDEX
] = SCAN_CONFIG_RATE_12M
,
1057 [IWL_RATE_18M_INDEX
] = SCAN_CONFIG_RATE_18M
,
1058 [IWL_RATE_24M_INDEX
] = SCAN_CONFIG_RATE_24M
,
1059 [IWL_RATE_36M_INDEX
] = SCAN_CONFIG_RATE_36M
,
1060 [IWL_RATE_48M_INDEX
] = SCAN_CONFIG_RATE_48M
,
1061 [IWL_RATE_54M_INDEX
] = SCAN_CONFIG_RATE_54M
,
1064 return rate_to_scan_rate
[rate
];
1067 static __le32
iwl_mvm_scan_config_rates(struct iwl_mvm
*mvm
)
1069 struct ieee80211_supported_band
*band
;
1070 unsigned int rates
= 0;
1073 band
= &mvm
->nvm_data
->bands
[NL80211_BAND_2GHZ
];
1074 for (i
= 0; i
< band
->n_bitrates
; i
++)
1075 rates
|= rate_to_scan_rate_flag(band
->bitrates
[i
].hw_value
);
1076 band
= &mvm
->nvm_data
->bands
[NL80211_BAND_5GHZ
];
1077 for (i
= 0; i
< band
->n_bitrates
; i
++)
1078 rates
|= rate_to_scan_rate_flag(band
->bitrates
[i
].hw_value
);
1080 /* Set both basic rates and supported rates */
1081 rates
|= SCAN_CONFIG_SUPPORTED_RATE(rates
);
1083 return cpu_to_le32(rates
);
1086 static void iwl_mvm_fill_scan_dwell(struct iwl_mvm
*mvm
,
1087 struct iwl_scan_dwell
*dwell
)
1089 dwell
->active
= IWL_SCAN_DWELL_ACTIVE
;
1090 dwell
->passive
= IWL_SCAN_DWELL_PASSIVE
;
1091 dwell
->fragmented
= IWL_SCAN_DWELL_FRAGMENTED
;
1092 dwell
->extended
= IWL_SCAN_DWELL_EXTENDED
;
1095 static void iwl_mvm_fill_channels(struct iwl_mvm
*mvm
, u8
*channels
,
1098 struct ieee80211_supported_band
*band
;
1101 band
= &mvm
->nvm_data
->bands
[NL80211_BAND_2GHZ
];
1102 for (i
= 0; i
< band
->n_channels
&& j
< max_channels
; i
++, j
++)
1103 channels
[j
] = band
->channels
[i
].hw_value
;
1104 band
= &mvm
->nvm_data
->bands
[NL80211_BAND_5GHZ
];
1105 for (i
= 0; i
< band
->n_channels
&& j
< max_channels
; i
++, j
++)
1106 channels
[j
] = band
->channels
[i
].hw_value
;
1109 static void iwl_mvm_fill_scan_config_v1(struct iwl_mvm
*mvm
, void *config
,
1110 u32 flags
, u8 channel_flags
,
1113 enum iwl_mvm_scan_type type
= iwl_mvm_get_scan_type(mvm
, NULL
);
1114 struct iwl_scan_config_v1
*cfg
= config
;
1116 cfg
->flags
= cpu_to_le32(flags
);
1117 cfg
->tx_chains
= cpu_to_le32(iwl_mvm_get_valid_tx_ant(mvm
));
1118 cfg
->rx_chains
= cpu_to_le32(iwl_mvm_scan_rx_ant(mvm
));
1119 cfg
->legacy_rates
= iwl_mvm_scan_config_rates(mvm
);
1120 cfg
->out_of_channel_time
= cpu_to_le32(scan_timing
[type
].max_out_time
);
1121 cfg
->suspend_time
= cpu_to_le32(scan_timing
[type
].suspend_time
);
1123 iwl_mvm_fill_scan_dwell(mvm
, &cfg
->dwell
);
1125 memcpy(&cfg
->mac_addr
, &mvm
->addresses
[0].addr
, ETH_ALEN
);
1127 cfg
->bcast_sta_id
= mvm
->aux_sta
.sta_id
;
1128 cfg
->channel_flags
= channel_flags
;
1130 iwl_mvm_fill_channels(mvm
, cfg
->channel_array
, max_channels
);
1133 static void iwl_mvm_fill_scan_config_v2(struct iwl_mvm
*mvm
, void *config
,
1134 u32 flags
, u8 channel_flags
,
1137 struct iwl_scan_config_v2
*cfg
= config
;
1139 cfg
->flags
= cpu_to_le32(flags
);
1140 cfg
->tx_chains
= cpu_to_le32(iwl_mvm_get_valid_tx_ant(mvm
));
1141 cfg
->rx_chains
= cpu_to_le32(iwl_mvm_scan_rx_ant(mvm
));
1142 cfg
->legacy_rates
= iwl_mvm_scan_config_rates(mvm
);
1144 if (iwl_mvm_is_cdb_supported(mvm
)) {
1145 enum iwl_mvm_scan_type lb_type
, hb_type
;
1147 lb_type
= iwl_mvm_get_scan_type_band(mvm
, NULL
,
1149 hb_type
= iwl_mvm_get_scan_type_band(mvm
, NULL
,
1152 cfg
->out_of_channel_time
[SCAN_LB_LMAC_IDX
] =
1153 cpu_to_le32(scan_timing
[lb_type
].max_out_time
);
1154 cfg
->suspend_time
[SCAN_LB_LMAC_IDX
] =
1155 cpu_to_le32(scan_timing
[lb_type
].suspend_time
);
1157 cfg
->out_of_channel_time
[SCAN_HB_LMAC_IDX
] =
1158 cpu_to_le32(scan_timing
[hb_type
].max_out_time
);
1159 cfg
->suspend_time
[SCAN_HB_LMAC_IDX
] =
1160 cpu_to_le32(scan_timing
[hb_type
].suspend_time
);
1162 enum iwl_mvm_scan_type type
=
1163 iwl_mvm_get_scan_type(mvm
, NULL
);
1165 cfg
->out_of_channel_time
[SCAN_LB_LMAC_IDX
] =
1166 cpu_to_le32(scan_timing
[type
].max_out_time
);
1167 cfg
->suspend_time
[SCAN_LB_LMAC_IDX
] =
1168 cpu_to_le32(scan_timing
[type
].suspend_time
);
1171 iwl_mvm_fill_scan_dwell(mvm
, &cfg
->dwell
);
1173 memcpy(&cfg
->mac_addr
, &mvm
->addresses
[0].addr
, ETH_ALEN
);
1175 cfg
->bcast_sta_id
= mvm
->aux_sta
.sta_id
;
1176 cfg
->channel_flags
= channel_flags
;
1178 iwl_mvm_fill_channels(mvm
, cfg
->channel_array
, max_channels
);
1181 static int iwl_mvm_legacy_config_scan(struct iwl_mvm
*mvm
)
1185 struct iwl_host_cmd cmd
= {
1186 .id
= iwl_cmd_id(SCAN_CFG_CMD
, IWL_ALWAYS_LONG_GROUP
, 0),
1188 enum iwl_mvm_scan_type type
;
1189 enum iwl_mvm_scan_type hb_type
= IWL_SCAN_TYPE_NOT_SET
;
1191 mvm
->nvm_data
->bands
[NL80211_BAND_2GHZ
].n_channels
+
1192 mvm
->nvm_data
->bands
[NL80211_BAND_5GHZ
].n_channels
;
1196 if (WARN_ON(num_channels
> mvm
->fw
->ucode_capa
.n_scan_channels
))
1197 num_channels
= mvm
->fw
->ucode_capa
.n_scan_channels
;
1199 if (iwl_mvm_is_cdb_supported(mvm
)) {
1200 type
= iwl_mvm_get_scan_type_band(mvm
, NULL
,
1202 hb_type
= iwl_mvm_get_scan_type_band(mvm
, NULL
,
1204 if (type
== mvm
->scan_type
&& hb_type
== mvm
->hb_scan_type
)
1207 type
= iwl_mvm_get_scan_type(mvm
, NULL
);
1208 if (type
== mvm
->scan_type
)
1212 if (iwl_mvm_cdb_scan_api(mvm
))
1213 cmd_size
= sizeof(struct iwl_scan_config_v2
);
1215 cmd_size
= sizeof(struct iwl_scan_config_v1
);
1216 cmd_size
+= mvm
->fw
->ucode_capa
.n_scan_channels
;
1218 cfg
= kzalloc(cmd_size
, GFP_KERNEL
);
1222 flags
= SCAN_CONFIG_FLAG_ACTIVATE
|
1223 SCAN_CONFIG_FLAG_ALLOW_CHUB_REQS
|
1224 SCAN_CONFIG_FLAG_SET_TX_CHAINS
|
1225 SCAN_CONFIG_FLAG_SET_RX_CHAINS
|
1226 SCAN_CONFIG_FLAG_SET_AUX_STA_ID
|
1227 SCAN_CONFIG_FLAG_SET_ALL_TIMES
|
1228 SCAN_CONFIG_FLAG_SET_LEGACY_RATES
|
1229 SCAN_CONFIG_FLAG_SET_MAC_ADDR
|
1230 SCAN_CONFIG_FLAG_SET_CHANNEL_FLAGS
|
1231 SCAN_CONFIG_N_CHANNELS(num_channels
) |
1232 (iwl_mvm_is_scan_fragmented(type
) ?
1233 SCAN_CONFIG_FLAG_SET_FRAGMENTED
:
1234 SCAN_CONFIG_FLAG_CLEAR_FRAGMENTED
);
1236 channel_flags
= IWL_CHANNEL_FLAG_EBS
|
1237 IWL_CHANNEL_FLAG_ACCURATE_EBS
|
1238 IWL_CHANNEL_FLAG_EBS_ADD
|
1239 IWL_CHANNEL_FLAG_PRE_SCAN_PASSIVE2ACTIVE
;
1242 * Check for fragmented scan on LMAC2 - high band.
1243 * LMAC1 - low band is checked above.
1245 if (iwl_mvm_cdb_scan_api(mvm
)) {
1246 if (iwl_mvm_is_cdb_supported(mvm
))
1247 flags
|= (iwl_mvm_is_scan_fragmented(hb_type
)) ?
1248 SCAN_CONFIG_FLAG_SET_LMAC2_FRAGMENTED
:
1249 SCAN_CONFIG_FLAG_CLEAR_LMAC2_FRAGMENTED
;
1250 iwl_mvm_fill_scan_config_v2(mvm
, cfg
, flags
, channel_flags
,
1253 iwl_mvm_fill_scan_config_v1(mvm
, cfg
, flags
, channel_flags
,
1258 cmd
.len
[0] = cmd_size
;
1259 cmd
.dataflags
[0] = IWL_HCMD_DFL_NOCOPY
;
1261 IWL_DEBUG_SCAN(mvm
, "Sending UMAC scan config\n");
1263 ret
= iwl_mvm_send_cmd(mvm
, &cmd
);
1265 mvm
->scan_type
= type
;
1266 mvm
->hb_scan_type
= hb_type
;
1273 int iwl_mvm_config_scan(struct iwl_mvm
*mvm
)
1275 struct iwl_scan_config cfg
;
1276 struct iwl_host_cmd cmd
= {
1277 .id
= iwl_cmd_id(SCAN_CFG_CMD
, IWL_ALWAYS_LONG_GROUP
, 0),
1278 .len
[0] = sizeof(cfg
),
1280 .dataflags
[0] = IWL_HCMD_DFL_NOCOPY
,
1283 if (!iwl_mvm_is_reduced_config_scan_supported(mvm
))
1284 return iwl_mvm_legacy_config_scan(mvm
);
1286 memset(&cfg
, 0, sizeof(cfg
));
1288 cfg
.bcast_sta_id
= mvm
->aux_sta
.sta_id
;
1289 cfg
.tx_chains
= cpu_to_le32(iwl_mvm_get_valid_tx_ant(mvm
));
1290 cfg
.rx_chains
= cpu_to_le32(iwl_mvm_scan_rx_ant(mvm
));
1292 IWL_DEBUG_SCAN(mvm
, "Sending UMAC scan config\n");
1294 return iwl_mvm_send_cmd(mvm
, &cmd
);
1297 static int iwl_mvm_scan_uid_by_status(struct iwl_mvm
*mvm
, int status
)
1301 for (i
= 0; i
< mvm
->max_scans
; i
++)
1302 if (mvm
->scan_uid_status
[i
] == status
)
1308 static void iwl_mvm_scan_umac_dwell(struct iwl_mvm
*mvm
,
1309 struct iwl_scan_req_umac
*cmd
,
1310 struct iwl_mvm_scan_params
*params
)
1312 struct iwl_mvm_scan_timing_params
*timing
, *hb_timing
;
1313 u8 active_dwell
, passive_dwell
;
1315 timing
= &scan_timing
[params
->type
];
1316 active_dwell
= params
->measurement_dwell
?
1317 params
->measurement_dwell
: IWL_SCAN_DWELL_ACTIVE
;
1318 passive_dwell
= params
->measurement_dwell
?
1319 params
->measurement_dwell
: IWL_SCAN_DWELL_PASSIVE
;
1321 if (iwl_mvm_is_adaptive_dwell_supported(mvm
)) {
1322 cmd
->v7
.adwell_default_n_aps_social
=
1323 IWL_SCAN_ADWELL_DEFAULT_N_APS_SOCIAL
;
1324 cmd
->v7
.adwell_default_n_aps
=
1325 IWL_SCAN_ADWELL_DEFAULT_LB_N_APS
;
1327 if (iwl_mvm_is_adwell_hb_ap_num_supported(mvm
))
1328 cmd
->v9
.adwell_default_hb_n_aps
=
1329 IWL_SCAN_ADWELL_DEFAULT_HB_N_APS
;
1331 /* if custom max budget was configured with debugfs */
1332 if (IWL_MVM_ADWELL_MAX_BUDGET
)
1333 cmd
->v7
.adwell_max_budget
=
1334 cpu_to_le16(IWL_MVM_ADWELL_MAX_BUDGET
);
1335 else if (params
->ssids
&& params
->ssids
[0].ssid_len
)
1336 cmd
->v7
.adwell_max_budget
=
1337 cpu_to_le16(IWL_SCAN_ADWELL_MAX_BUDGET_DIRECTED_SCAN
);
1339 cmd
->v7
.adwell_max_budget
=
1340 cpu_to_le16(IWL_SCAN_ADWELL_MAX_BUDGET_FULL_SCAN
);
1342 cmd
->v7
.scan_priority
= cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6
);
1343 cmd
->v7
.max_out_time
[SCAN_LB_LMAC_IDX
] =
1344 cpu_to_le32(timing
->max_out_time
);
1345 cmd
->v7
.suspend_time
[SCAN_LB_LMAC_IDX
] =
1346 cpu_to_le32(timing
->suspend_time
);
1348 if (iwl_mvm_is_cdb_supported(mvm
)) {
1349 hb_timing
= &scan_timing
[params
->hb_type
];
1351 cmd
->v7
.max_out_time
[SCAN_HB_LMAC_IDX
] =
1352 cpu_to_le32(hb_timing
->max_out_time
);
1353 cmd
->v7
.suspend_time
[SCAN_HB_LMAC_IDX
] =
1354 cpu_to_le32(hb_timing
->suspend_time
);
1357 if (!iwl_mvm_is_adaptive_dwell_v2_supported(mvm
)) {
1358 cmd
->v7
.active_dwell
= active_dwell
;
1359 cmd
->v7
.passive_dwell
= passive_dwell
;
1360 cmd
->v7
.fragmented_dwell
= IWL_SCAN_DWELL_FRAGMENTED
;
1362 cmd
->v8
.active_dwell
[SCAN_LB_LMAC_IDX
] = active_dwell
;
1363 cmd
->v8
.passive_dwell
[SCAN_LB_LMAC_IDX
] = passive_dwell
;
1364 if (iwl_mvm_is_cdb_supported(mvm
)) {
1365 cmd
->v8
.active_dwell
[SCAN_HB_LMAC_IDX
] =
1367 cmd
->v8
.passive_dwell
[SCAN_HB_LMAC_IDX
] =
1372 cmd
->v1
.extended_dwell
= params
->measurement_dwell
?
1373 params
->measurement_dwell
: IWL_SCAN_DWELL_EXTENDED
;
1374 cmd
->v1
.active_dwell
= active_dwell
;
1375 cmd
->v1
.passive_dwell
= passive_dwell
;
1376 cmd
->v1
.fragmented_dwell
= IWL_SCAN_DWELL_FRAGMENTED
;
1378 if (iwl_mvm_is_cdb_supported(mvm
)) {
1379 hb_timing
= &scan_timing
[params
->hb_type
];
1381 cmd
->v6
.max_out_time
[SCAN_HB_LMAC_IDX
] =
1382 cpu_to_le32(hb_timing
->max_out_time
);
1383 cmd
->v6
.suspend_time
[SCAN_HB_LMAC_IDX
] =
1384 cpu_to_le32(hb_timing
->suspend_time
);
1387 if (iwl_mvm_cdb_scan_api(mvm
)) {
1388 cmd
->v6
.scan_priority
=
1389 cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6
);
1390 cmd
->v6
.max_out_time
[SCAN_LB_LMAC_IDX
] =
1391 cpu_to_le32(timing
->max_out_time
);
1392 cmd
->v6
.suspend_time
[SCAN_LB_LMAC_IDX
] =
1393 cpu_to_le32(timing
->suspend_time
);
1395 cmd
->v1
.scan_priority
=
1396 cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6
);
1397 cmd
->v1
.max_out_time
=
1398 cpu_to_le32(timing
->max_out_time
);
1399 cmd
->v1
.suspend_time
=
1400 cpu_to_le32(timing
->suspend_time
);
1404 if (iwl_mvm_is_regular_scan(params
))
1405 cmd
->ooc_priority
= cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6
);
1407 cmd
->ooc_priority
= cpu_to_le32(IWL_SCAN_PRIORITY_EXT_2
);
1410 static u32
iwl_mvm_scan_umac_ooc_priority(struct iwl_mvm_scan_params
*params
)
1412 return iwl_mvm_is_regular_scan(params
) ?
1413 IWL_SCAN_PRIORITY_EXT_6
:
1414 IWL_SCAN_PRIORITY_EXT_2
;
1418 iwl_mvm_scan_umac_dwell_v10(struct iwl_mvm
*mvm
,
1419 struct iwl_scan_general_params_v10
*general_params
,
1420 struct iwl_mvm_scan_params
*params
)
1422 struct iwl_mvm_scan_timing_params
*timing
, *hb_timing
;
1423 u8 active_dwell
, passive_dwell
;
1425 timing
= &scan_timing
[params
->type
];
1426 active_dwell
= params
->measurement_dwell
?
1427 params
->measurement_dwell
: IWL_SCAN_DWELL_ACTIVE
;
1428 passive_dwell
= params
->measurement_dwell
?
1429 params
->measurement_dwell
: IWL_SCAN_DWELL_PASSIVE
;
1431 general_params
->adwell_default_social_chn
=
1432 IWL_SCAN_ADWELL_DEFAULT_N_APS_SOCIAL
;
1433 general_params
->adwell_default_2g
= IWL_SCAN_ADWELL_DEFAULT_LB_N_APS
;
1434 general_params
->adwell_default_5g
= IWL_SCAN_ADWELL_DEFAULT_HB_N_APS
;
1436 /* if custom max budget was configured with debugfs */
1437 if (IWL_MVM_ADWELL_MAX_BUDGET
)
1438 general_params
->adwell_max_budget
=
1439 cpu_to_le16(IWL_MVM_ADWELL_MAX_BUDGET
);
1440 else if (params
->ssids
&& params
->ssids
[0].ssid_len
)
1441 general_params
->adwell_max_budget
=
1442 cpu_to_le16(IWL_SCAN_ADWELL_MAX_BUDGET_DIRECTED_SCAN
);
1444 general_params
->adwell_max_budget
=
1445 cpu_to_le16(IWL_SCAN_ADWELL_MAX_BUDGET_FULL_SCAN
);
1447 general_params
->scan_priority
= cpu_to_le32(IWL_SCAN_PRIORITY_EXT_6
);
1448 general_params
->max_out_of_time
[SCAN_LB_LMAC_IDX
] =
1449 cpu_to_le32(timing
->max_out_time
);
1450 general_params
->suspend_time
[SCAN_LB_LMAC_IDX
] =
1451 cpu_to_le32(timing
->suspend_time
);
1453 hb_timing
= &scan_timing
[params
->hb_type
];
1455 general_params
->max_out_of_time
[SCAN_HB_LMAC_IDX
] =
1456 cpu_to_le32(hb_timing
->max_out_time
);
1457 general_params
->suspend_time
[SCAN_HB_LMAC_IDX
] =
1458 cpu_to_le32(hb_timing
->suspend_time
);
1460 general_params
->active_dwell
[SCAN_LB_LMAC_IDX
] = active_dwell
;
1461 general_params
->passive_dwell
[SCAN_LB_LMAC_IDX
] = passive_dwell
;
1462 general_params
->active_dwell
[SCAN_HB_LMAC_IDX
] = active_dwell
;
1463 general_params
->passive_dwell
[SCAN_HB_LMAC_IDX
] = passive_dwell
;
1466 struct iwl_mvm_scan_channel_segment
{
1469 u8 first_channel_id
;
1471 u8 channel_spacing_shift
;
1475 static const struct iwl_mvm_scan_channel_segment scan_channel_segments
[] = {
1479 .first_channel_id
= 1,
1480 .last_channel_id
= 14,
1481 .channel_spacing_shift
= 0,
1487 .first_channel_id
= 36,
1488 .last_channel_id
= 144,
1489 .channel_spacing_shift
= 2,
1495 .first_channel_id
= 149,
1496 .last_channel_id
= 181,
1497 .channel_spacing_shift
= 2,
1502 static int iwl_mvm_scan_ch_and_band_to_idx(u8 channel_id
, u8 band
)
1509 for (i
= 0; i
< ARRAY_SIZE(scan_channel_segments
); i
++) {
1510 const struct iwl_mvm_scan_channel_segment
*ch_segment
=
1511 &scan_channel_segments
[i
];
1514 if (ch_segment
->band
!= band
||
1515 ch_segment
->first_channel_id
> channel_id
||
1516 ch_segment
->last_channel_id
< channel_id
)
1519 ch_offset
= (channel_id
- ch_segment
->first_channel_id
) >>
1520 ch_segment
->channel_spacing_shift
;
1522 index
= scan_channel_segments
[i
].start_idx
+ ch_offset
;
1523 if (index
< IWL_SCAN_NUM_CHANNELS
)
1532 static void iwl_mvm_scan_ch_add_n_aps_override(enum nl80211_iftype vif_type
,
1533 u8 ch_id
, u8 band
, u8
*ch_bitmap
,
1534 size_t bitmap_n_entries
)
1537 static const u8 p2p_go_friendly_chs
[] = {
1538 36, 40, 44, 48, 149, 153, 157, 161, 165,
1541 if (vif_type
!= NL80211_IFTYPE_P2P_DEVICE
)
1544 for (i
= 0; i
< ARRAY_SIZE(p2p_go_friendly_chs
); i
++) {
1545 if (p2p_go_friendly_chs
[i
] == ch_id
) {
1546 int ch_idx
, bitmap_idx
;
1548 ch_idx
= iwl_mvm_scan_ch_and_band_to_idx(ch_id
, band
);
1552 bitmap_idx
= ch_idx
/ 8;
1553 if (bitmap_idx
>= bitmap_n_entries
)
1556 ch_idx
= ch_idx
% 8;
1557 ch_bitmap
[bitmap_idx
] |= BIT(ch_idx
);
1565 iwl_mvm_umac_scan_cfg_channels(struct iwl_mvm
*mvm
,
1566 struct ieee80211_channel
**channels
,
1567 int n_channels
, u32 flags
,
1568 struct iwl_scan_channel_cfg_umac
*channel_cfg
)
1572 for (i
= 0; i
< n_channels
; i
++) {
1573 channel_cfg
[i
].flags
= cpu_to_le32(flags
);
1574 channel_cfg
[i
].v1
.channel_num
= channels
[i
]->hw_value
;
1575 if (iwl_mvm_is_scan_ext_chan_supported(mvm
)) {
1576 enum nl80211_band band
= channels
[i
]->band
;
1578 channel_cfg
[i
].v2
.band
=
1579 iwl_mvm_phy_band_from_nl80211(band
);
1580 channel_cfg
[i
].v2
.iter_count
= 1;
1581 channel_cfg
[i
].v2
.iter_interval
= 0;
1583 channel_cfg
[i
].v1
.iter_count
= 1;
1584 channel_cfg
[i
].v1
.iter_interval
= 0;
1590 iwl_mvm_umac_scan_cfg_channels_v4(struct iwl_mvm
*mvm
,
1591 struct ieee80211_channel
**channels
,
1592 struct iwl_scan_channel_params_v4
*cp
,
1593 int n_channels
, u32 flags
,
1594 enum nl80211_iftype vif_type
)
1596 u8
*bitmap
= cp
->adwell_ch_override_bitmap
;
1597 size_t bitmap_n_entries
= ARRAY_SIZE(cp
->adwell_ch_override_bitmap
);
1600 for (i
= 0; i
< n_channels
; i
++) {
1601 enum nl80211_band band
= channels
[i
]->band
;
1602 struct iwl_scan_channel_cfg_umac
*cfg
=
1603 &cp
->channel_config
[i
];
1605 cfg
->flags
= cpu_to_le32(flags
);
1606 cfg
->v2
.channel_num
= channels
[i
]->hw_value
;
1607 cfg
->v2
.band
= iwl_mvm_phy_band_from_nl80211(band
);
1608 cfg
->v2
.iter_count
= 1;
1609 cfg
->v2
.iter_interval
= 0;
1611 iwl_mvm_scan_ch_add_n_aps_override(vif_type
,
1612 cfg
->v2
.channel_num
,
1613 cfg
->v2
.band
, bitmap
,
1618 static u8
iwl_mvm_scan_umac_chan_flags_v2(struct iwl_mvm
*mvm
,
1619 struct iwl_mvm_scan_params
*params
,
1620 struct ieee80211_vif
*vif
)
1624 flags
|= IWL_SCAN_CHANNEL_FLAG_ENABLE_CHAN_ORDER
;
1626 if (iwl_mvm_scan_use_ebs(mvm
, vif
))
1627 flags
|= IWL_SCAN_CHANNEL_FLAG_EBS
|
1628 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE
|
1629 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD
;
1631 /* set fragmented ebs for fragmented scan on HB channels */
1632 if (iwl_mvm_is_scan_fragmented(params
->hb_type
))
1633 flags
|= IWL_SCAN_CHANNEL_FLAG_EBS_FRAG
;
1638 static u16
iwl_mvm_scan_umac_flags_v2(struct iwl_mvm
*mvm
,
1639 struct iwl_mvm_scan_params
*params
,
1640 struct ieee80211_vif
*vif
,
1645 if (params
->n_ssids
== 0)
1646 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_V2_FORCE_PASSIVE
;
1648 if (iwl_mvm_is_scan_fragmented(params
->type
))
1649 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_V2_FRAGMENTED_LMAC1
;
1651 if (iwl_mvm_is_scan_fragmented(params
->hb_type
))
1652 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_V2_FRAGMENTED_LMAC2
;
1654 if (params
->pass_all
)
1655 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_V2_PASS_ALL
;
1657 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_V2_MATCH
;
1659 if (!iwl_mvm_is_regular_scan(params
))
1660 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_V2_PERIODIC
;
1662 if (params
->measurement_dwell
||
1663 mvm
->sched_scan_pass_all
== SCHED_SCAN_PASS_ALL_ENABLED
)
1664 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_V2_NTFY_ITER_COMPLETE
;
1666 if (IWL_MVM_ADWELL_ENABLE
)
1667 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_V2_ADAPTIVE_DWELL
;
1669 if (type
== IWL_MVM_SCAN_SCHED
|| type
== IWL_MVM_SCAN_NETDETECT
)
1670 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_V2_PREEMPTIVE
;
1675 static u16
iwl_mvm_scan_umac_flags(struct iwl_mvm
*mvm
,
1676 struct iwl_mvm_scan_params
*params
,
1677 struct ieee80211_vif
*vif
)
1681 if (params
->n_ssids
== 0)
1682 flags
= IWL_UMAC_SCAN_GEN_FLAGS_PASSIVE
;
1684 if (params
->n_ssids
== 1 && params
->ssids
[0].ssid_len
!= 0)
1685 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_PRE_CONNECT
;
1687 if (iwl_mvm_is_scan_fragmented(params
->type
))
1688 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_FRAGMENTED
;
1690 if (iwl_mvm_is_cdb_supported(mvm
) &&
1691 iwl_mvm_is_scan_fragmented(params
->hb_type
))
1692 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_LMAC2_FRAGMENTED
;
1694 if (iwl_mvm_rrm_scan_needed(mvm
) &&
1695 fw_has_capa(&mvm
->fw
->ucode_capa
,
1696 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT
))
1697 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_RRM_ENABLED
;
1699 if (params
->pass_all
)
1700 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_PASS_ALL
;
1702 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_MATCH
;
1704 if (!iwl_mvm_is_regular_scan(params
))
1705 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_PERIODIC
;
1707 if (params
->measurement_dwell
)
1708 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_ITER_COMPLETE
;
1710 #ifdef CONFIG_IWLWIFI_DEBUGFS
1711 if (mvm
->scan_iter_notif_enabled
)
1712 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_ITER_COMPLETE
;
1715 if (mvm
->sched_scan_pass_all
== SCHED_SCAN_PASS_ALL_ENABLED
)
1716 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_ITER_COMPLETE
;
1718 if (iwl_mvm_is_adaptive_dwell_supported(mvm
) && IWL_MVM_ADWELL_ENABLE
)
1719 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_ADAPTIVE_DWELL
;
1722 * Extended dwell is relevant only for low band to start with, as it is
1723 * being used for social channles only (1, 6, 11), so we can check
1724 * only scan type on low band also for CDB.
1726 if (iwl_mvm_is_regular_scan(params
) &&
1727 vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
&&
1728 !iwl_mvm_is_scan_fragmented(params
->type
) &&
1729 !iwl_mvm_is_adaptive_dwell_supported(mvm
) &&
1730 !iwl_mvm_is_oce_supported(mvm
))
1731 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_EXTENDED_DWELL
;
1733 if (iwl_mvm_is_oce_supported(mvm
)) {
1734 if ((params
->flags
&
1735 NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE
))
1736 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_PROB_REQ_HIGH_TX_RATE
;
1737 /* Since IWL_UMAC_SCAN_GEN_FLAGS_EXTENDED_DWELL and
1738 * NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION shares
1739 * the same bit, we need to make sure that we use this bit here
1740 * only when IWL_UMAC_SCAN_GEN_FLAGS_EXTENDED_DWELL cannot be
1742 if ((params
->flags
&
1743 NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION
) &&
1744 !WARN_ON_ONCE(!iwl_mvm_is_adaptive_dwell_supported(mvm
)))
1745 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_PROB_REQ_DEFER_SUPP
;
1746 if ((params
->flags
& NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME
))
1747 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_MAX_CHNL_TIME
;
1754 iwl_mvm_fill_scan_sched_params(struct iwl_mvm_scan_params
*params
,
1755 struct iwl_scan_umac_schedule
*schedule
,
1759 if (WARN_ON(!params
->n_scan_plans
||
1760 params
->n_scan_plans
> IWL_MAX_SCHED_SCAN_PLANS
))
1763 for (i
= 0; i
< params
->n_scan_plans
; i
++) {
1764 struct cfg80211_sched_scan_plan
*scan_plan
=
1765 ¶ms
->scan_plans
[i
];
1767 schedule
[i
].iter_count
= scan_plan
->iterations
;
1768 schedule
[i
].interval
=
1769 cpu_to_le16(scan_plan
->interval
);
1773 * If the number of iterations of the last scan plan is set to
1774 * zero, it should run infinitely. However, this is not always the case.
1775 * For example, when regular scan is requested the driver sets one scan
1776 * plan with one iteration.
1778 if (!schedule
[params
->n_scan_plans
- 1].iter_count
)
1779 schedule
[params
->n_scan_plans
- 1].iter_count
= 0xff;
1781 *delay
= cpu_to_le16(params
->delay
);
1786 static int iwl_mvm_scan_umac(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
1787 struct iwl_mvm_scan_params
*params
,
1790 struct iwl_scan_req_umac
*cmd
= mvm
->scan_cmd
;
1791 struct iwl_scan_umac_chan_param
*chan_param
;
1792 void *cmd_data
= iwl_mvm_get_scan_req_umac_data(mvm
);
1793 void *sec_part
= cmd_data
+ sizeof(struct iwl_scan_channel_cfg_umac
) *
1794 mvm
->fw
->ucode_capa
.n_scan_channels
;
1795 struct iwl_scan_req_umac_tail_v2
*tail_v2
=
1796 (struct iwl_scan_req_umac_tail_v2
*)sec_part
;
1797 struct iwl_scan_req_umac_tail_v1
*tail_v1
;
1798 struct iwl_ssid_ie
*direct_scan
;
1800 u32 ssid_bitmap
= 0;
1801 u8 channel_flags
= 0;
1803 struct iwl_mvm_vif
*scan_vif
= iwl_mvm_vif_from_mac80211(vif
);
1805 chan_param
= iwl_mvm_get_scan_req_umac_channel(mvm
);
1807 iwl_mvm_scan_umac_dwell(mvm
, cmd
, params
);
1809 mvm
->scan_uid_status
[uid
] = type
;
1811 cmd
->uid
= cpu_to_le32(uid
);
1812 gen_flags
= iwl_mvm_scan_umac_flags(mvm
, params
, vif
);
1813 cmd
->general_flags
= cpu_to_le16(gen_flags
);
1814 if (iwl_mvm_is_adaptive_dwell_v2_supported(mvm
)) {
1815 if (gen_flags
& IWL_UMAC_SCAN_GEN_FLAGS_FRAGMENTED
)
1816 cmd
->v8
.num_of_fragments
[SCAN_LB_LMAC_IDX
] =
1817 IWL_SCAN_NUM_OF_FRAGS
;
1818 if (gen_flags
& IWL_UMAC_SCAN_GEN_FLAGS_LMAC2_FRAGMENTED
)
1819 cmd
->v8
.num_of_fragments
[SCAN_HB_LMAC_IDX
] =
1820 IWL_SCAN_NUM_OF_FRAGS
;
1822 cmd
->v8
.general_flags2
=
1823 IWL_UMAC_SCAN_GEN_FLAGS2_ALLOW_CHNL_REORDER
;
1826 cmd
->scan_start_mac_id
= scan_vif
->id
;
1828 if (type
== IWL_MVM_SCAN_SCHED
|| type
== IWL_MVM_SCAN_NETDETECT
)
1829 cmd
->flags
= cpu_to_le32(IWL_UMAC_SCAN_FLAG_PREEMPTIVE
);
1831 if (iwl_mvm_scan_use_ebs(mvm
, vif
)) {
1832 channel_flags
= IWL_SCAN_CHANNEL_FLAG_EBS
|
1833 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE
|
1834 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD
;
1836 /* set fragmented ebs for fragmented scan on HB channels */
1837 if (iwl_mvm_is_frag_ebs_supported(mvm
)) {
1839 IWL_UMAC_SCAN_GEN_FLAGS_LMAC2_FRAGMENTED
||
1840 (!iwl_mvm_is_cdb_supported(mvm
) &&
1841 gen_flags
& IWL_UMAC_SCAN_GEN_FLAGS_FRAGMENTED
))
1842 channel_flags
|= IWL_SCAN_CHANNEL_FLAG_EBS_FRAG
;
1846 chan_param
->flags
= channel_flags
;
1847 chan_param
->count
= params
->n_channels
;
1849 ret
= iwl_mvm_fill_scan_sched_params(params
, tail_v2
->schedule
,
1854 if (iwl_mvm_is_scan_ext_chan_supported(mvm
)) {
1855 tail_v2
->preq
= params
->preq
;
1856 direct_scan
= tail_v2
->direct_scan
;
1858 tail_v1
= (struct iwl_scan_req_umac_tail_v1
*)sec_part
;
1859 iwl_mvm_scan_set_legacy_probe_req(&tail_v1
->preq
,
1861 direct_scan
= tail_v1
->direct_scan
;
1863 iwl_scan_build_ssids(params
, direct_scan
, &ssid_bitmap
);
1864 iwl_mvm_umac_scan_cfg_channels(mvm
, params
->channels
,
1865 params
->n_channels
, ssid_bitmap
,
1871 iwl_mvm_scan_umac_fill_general_p_v10(struct iwl_mvm
*mvm
,
1872 struct iwl_mvm_scan_params
*params
,
1873 struct ieee80211_vif
*vif
,
1874 struct iwl_scan_general_params_v10
*gp
,
1877 struct iwl_mvm_vif
*scan_vif
= iwl_mvm_vif_from_mac80211(vif
);
1879 iwl_mvm_scan_umac_dwell_v10(mvm
, gp
, params
);
1881 gp
->flags
= cpu_to_le16(gen_flags
);
1883 if (gen_flags
& IWL_UMAC_SCAN_GEN_FLAGS_V2_FRAGMENTED_LMAC1
)
1884 gp
->num_of_fragments
[SCAN_LB_LMAC_IDX
] = IWL_SCAN_NUM_OF_FRAGS
;
1885 if (gen_flags
& IWL_UMAC_SCAN_GEN_FLAGS_V2_FRAGMENTED_LMAC2
)
1886 gp
->num_of_fragments
[SCAN_HB_LMAC_IDX
] = IWL_SCAN_NUM_OF_FRAGS
;
1888 gp
->scan_start_mac_id
= scan_vif
->id
;
1892 iwl_mvm_scan_umac_fill_probe_p_v3(struct iwl_mvm_scan_params
*params
,
1893 struct iwl_scan_probe_params_v3
*pp
)
1895 pp
->preq
= params
->preq
;
1896 pp
->ssid_num
= params
->n_ssids
;
1897 iwl_scan_build_ssids(params
, pp
->direct_scan
, NULL
);
1901 iwl_mvm_scan_umac_fill_probe_p_v4(struct iwl_mvm_scan_params
*params
,
1902 struct iwl_scan_probe_params_v4
*pp
,
1905 pp
->preq
= params
->preq
;
1906 iwl_scan_build_ssids(params
, pp
->direct_scan
, bitmap_ssid
);
1910 iwl_mvm_scan_umac_fill_ch_p_v4(struct iwl_mvm
*mvm
,
1911 struct iwl_mvm_scan_params
*params
,
1912 struct ieee80211_vif
*vif
,
1913 struct iwl_scan_channel_params_v4
*cp
,
1914 u32 channel_cfg_flags
)
1916 cp
->flags
= iwl_mvm_scan_umac_chan_flags_v2(mvm
, params
, vif
);
1917 cp
->count
= params
->n_channels
;
1918 cp
->num_of_aps_override
= IWL_SCAN_ADWELL_DEFAULT_N_APS_OVERRIDE
;
1920 iwl_mvm_umac_scan_cfg_channels_v4(mvm
, params
->channels
, cp
,
1927 static int iwl_mvm_scan_umac_v12(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
1928 struct iwl_mvm_scan_params
*params
, int type
,
1931 struct iwl_scan_req_umac_v12
*cmd
= mvm
->scan_cmd
;
1932 struct iwl_scan_req_params_v12
*scan_p
= &cmd
->scan_params
;
1936 mvm
->scan_uid_status
[uid
] = type
;
1938 cmd
->ooc_priority
= cpu_to_le32(iwl_mvm_scan_umac_ooc_priority(params
));
1939 cmd
->uid
= cpu_to_le32(uid
);
1941 gen_flags
= iwl_mvm_scan_umac_flags_v2(mvm
, params
, vif
, type
);
1942 iwl_mvm_scan_umac_fill_general_p_v10(mvm
, params
, vif
,
1943 &scan_p
->general_params
,
1946 ret
= iwl_mvm_fill_scan_sched_params(params
,
1947 scan_p
->periodic_params
.schedule
,
1948 &scan_p
->periodic_params
.delay
);
1952 iwl_mvm_scan_umac_fill_probe_p_v3(params
, &scan_p
->probe_params
);
1953 iwl_mvm_scan_umac_fill_ch_p_v4(mvm
, params
, vif
,
1954 &scan_p
->channel_params
, 0);
1959 static int iwl_mvm_scan_umac_v13(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
1960 struct iwl_mvm_scan_params
*params
, int type
,
1963 struct iwl_scan_req_umac_v13
*cmd
= mvm
->scan_cmd
;
1964 struct iwl_scan_req_params_v13
*scan_p
= &cmd
->scan_params
;
1967 u32 bitmap_ssid
= 0;
1969 mvm
->scan_uid_status
[uid
] = type
;
1971 cmd
->ooc_priority
= cpu_to_le32(iwl_mvm_scan_umac_ooc_priority(params
));
1972 cmd
->uid
= cpu_to_le32(uid
);
1974 gen_flags
= iwl_mvm_scan_umac_flags_v2(mvm
, params
, vif
, type
);
1975 iwl_mvm_scan_umac_fill_general_p_v10(mvm
, params
, vif
,
1976 &scan_p
->general_params
,
1979 ret
= iwl_mvm_fill_scan_sched_params(params
,
1980 scan_p
->periodic_params
.schedule
,
1981 &scan_p
->periodic_params
.delay
);
1985 iwl_mvm_scan_umac_fill_probe_p_v4(params
, &scan_p
->probe_params
,
1987 iwl_mvm_scan_umac_fill_ch_p_v4(mvm
, params
, vif
,
1988 &scan_p
->channel_params
, bitmap_ssid
);
1993 static int iwl_mvm_num_scans(struct iwl_mvm
*mvm
)
1995 return hweight32(mvm
->scan_status
& IWL_MVM_SCAN_MASK
);
1998 static int iwl_mvm_check_running_scans(struct iwl_mvm
*mvm
, int type
)
2000 bool unified_image
= fw_has_capa(&mvm
->fw
->ucode_capa
,
2001 IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG
);
2003 /* This looks a bit arbitrary, but the idea is that if we run
2004 * out of possible simultaneous scans and the userspace is
2005 * trying to run a scan type that is already running, we
2006 * return -EBUSY. But if the userspace wants to start a
2007 * different type of scan, we stop the opposite type to make
2008 * space for the new request. The reason is backwards
2009 * compatibility with old wpa_supplicant that wouldn't stop a
2010 * scheduled scan before starting a normal scan.
2013 /* FW supports only a single periodic scan */
2014 if ((type
== IWL_MVM_SCAN_SCHED
|| type
== IWL_MVM_SCAN_NETDETECT
) &&
2015 mvm
->scan_status
& (IWL_MVM_SCAN_SCHED
| IWL_MVM_SCAN_NETDETECT
))
2018 if (iwl_mvm_num_scans(mvm
) < mvm
->max_scans
)
2021 /* Use a switch, even though this is a bitmask, so that more
2022 * than one bits set will fall in default and we will warn.
2025 case IWL_MVM_SCAN_REGULAR
:
2026 if (mvm
->scan_status
& IWL_MVM_SCAN_REGULAR_MASK
)
2028 return iwl_mvm_scan_stop(mvm
, IWL_MVM_SCAN_SCHED
, true);
2029 case IWL_MVM_SCAN_SCHED
:
2030 if (mvm
->scan_status
& IWL_MVM_SCAN_SCHED_MASK
)
2032 return iwl_mvm_scan_stop(mvm
, IWL_MVM_SCAN_REGULAR
, true);
2033 case IWL_MVM_SCAN_NETDETECT
:
2034 /* For non-unified images, there's no need to stop
2035 * anything for net-detect since the firmware is
2036 * restarted anyway. This way, any sched scans that
2037 * were running will be restarted when we resume.
2042 /* If this is a unified image and we ran out of scans,
2043 * we need to stop something. Prefer stopping regular
2044 * scans, because the results are useless at this
2045 * point, and we should be able to keep running
2046 * another scheduled scan while suspended.
2048 if (mvm
->scan_status
& IWL_MVM_SCAN_REGULAR_MASK
)
2049 return iwl_mvm_scan_stop(mvm
, IWL_MVM_SCAN_REGULAR
,
2051 if (mvm
->scan_status
& IWL_MVM_SCAN_SCHED_MASK
)
2052 return iwl_mvm_scan_stop(mvm
, IWL_MVM_SCAN_SCHED
,
2054 /* Something is wrong if no scan was running but we
2066 #define SCAN_TIMEOUT 20000
2068 void iwl_mvm_scan_timeout_wk(struct work_struct
*work
)
2070 struct delayed_work
*delayed_work
= to_delayed_work(work
);
2071 struct iwl_mvm
*mvm
= container_of(delayed_work
, struct iwl_mvm
,
2072 scan_timeout_dwork
);
2074 IWL_ERR(mvm
, "regular scan timed out\n");
2076 iwl_force_nmi(mvm
->trans
);
2079 static void iwl_mvm_fill_scan_type(struct iwl_mvm
*mvm
,
2080 struct iwl_mvm_scan_params
*params
,
2081 struct ieee80211_vif
*vif
)
2083 if (iwl_mvm_is_cdb_supported(mvm
)) {
2085 iwl_mvm_get_scan_type_band(mvm
, vif
,
2088 iwl_mvm_get_scan_type_band(mvm
, vif
,
2091 params
->type
= iwl_mvm_get_scan_type(mvm
, vif
);
2095 struct iwl_scan_umac_handler
{
2097 int (*handler
)(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
2098 struct iwl_mvm_scan_params
*params
, int type
, int uid
);
2101 #define IWL_SCAN_UMAC_HANDLER(_ver) { \
2103 .handler = iwl_mvm_scan_umac_v##_ver, \
2106 static const struct iwl_scan_umac_handler iwl_scan_umac_handlers
[] = {
2107 /* set the newest version first to shorten the list traverse time */
2108 IWL_SCAN_UMAC_HANDLER(13),
2109 IWL_SCAN_UMAC_HANDLER(12),
2112 static int iwl_mvm_build_scan_cmd(struct iwl_mvm
*mvm
,
2113 struct ieee80211_vif
*vif
,
2114 struct iwl_host_cmd
*hcmd
,
2115 struct iwl_mvm_scan_params
*params
,
2121 lockdep_assert_held(&mvm
->mutex
);
2122 memset(mvm
->scan_cmd
, 0, ksize(mvm
->scan_cmd
));
2124 if (!fw_has_capa(&mvm
->fw
->ucode_capa
, IWL_UCODE_TLV_CAPA_UMAC_SCAN
)) {
2125 hcmd
->id
= SCAN_OFFLOAD_REQUEST_CMD
;
2127 return iwl_mvm_scan_lmac(mvm
, vif
, params
);
2130 uid
= iwl_mvm_scan_uid_by_status(mvm
, 0);
2134 hcmd
->id
= iwl_cmd_id(SCAN_REQ_UMAC
, IWL_ALWAYS_LONG_GROUP
, 0);
2136 scan_ver
= iwl_mvm_lookup_cmd_ver(mvm
->fw
, IWL_ALWAYS_LONG_GROUP
,
2139 for (i
= 0; i
< ARRAY_SIZE(iwl_scan_umac_handlers
); i
++) {
2140 const struct iwl_scan_umac_handler
*ver_handler
=
2141 &iwl_scan_umac_handlers
[i
];
2143 if (ver_handler
->version
!= scan_ver
)
2146 return ver_handler
->handler(mvm
, vif
, params
, type
, uid
);
2149 return iwl_mvm_scan_umac(mvm
, vif
, params
, type
, uid
);
2152 int iwl_mvm_reg_scan_start(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
2153 struct cfg80211_scan_request
*req
,
2154 struct ieee80211_scan_ies
*ies
)
2156 struct iwl_host_cmd hcmd
= {
2157 .len
= { iwl_mvm_scan_size(mvm
), },
2158 .data
= { mvm
->scan_cmd
, },
2159 .dataflags
= { IWL_HCMD_DFL_NOCOPY
, },
2161 struct iwl_mvm_scan_params params
= {};
2163 struct cfg80211_sched_scan_plan scan_plan
= { .iterations
= 1 };
2165 lockdep_assert_held(&mvm
->mutex
);
2167 if (iwl_mvm_is_lar_supported(mvm
) && !mvm
->lar_regdom_set
) {
2168 IWL_ERR(mvm
, "scan while LAR regdomain is not set\n");
2172 ret
= iwl_mvm_check_running_scans(mvm
, IWL_MVM_SCAN_REGULAR
);
2176 /* we should have failed registration if scan_cmd was NULL */
2177 if (WARN_ON(!mvm
->scan_cmd
))
2180 if (!iwl_mvm_scan_fits(mvm
, req
->n_ssids
, ies
, req
->n_channels
))
2183 params
.n_ssids
= req
->n_ssids
;
2184 params
.flags
= req
->flags
;
2185 params
.n_channels
= req
->n_channels
;
2187 params
.ssids
= req
->ssids
;
2188 params
.channels
= req
->channels
;
2189 params
.mac_addr
= req
->mac_addr
;
2190 params
.mac_addr_mask
= req
->mac_addr_mask
;
2191 params
.no_cck
= req
->no_cck
;
2192 params
.pass_all
= true;
2193 params
.n_match_sets
= 0;
2194 params
.match_sets
= NULL
;
2196 params
.scan_plans
= &scan_plan
;
2197 params
.n_scan_plans
= 1;
2199 iwl_mvm_fill_scan_type(mvm
, ¶ms
, vif
);
2201 ret
= iwl_mvm_get_measurement_dwell(mvm
, req
, ¶ms
);
2205 params
.measurement_dwell
= ret
;
2207 iwl_mvm_build_scan_probe(mvm
, vif
, ies
, ¶ms
);
2209 ret
= iwl_mvm_build_scan_cmd(mvm
, vif
, &hcmd
, ¶ms
,
2210 IWL_MVM_SCAN_REGULAR
);
2215 iwl_mvm_pause_tcm(mvm
, false);
2217 ret
= iwl_mvm_send_cmd(mvm
, &hcmd
);
2219 /* If the scan failed, it usually means that the FW was unable
2220 * to allocate the time events. Warn on it, but maybe we
2221 * should try to send the command again with different params.
2223 IWL_ERR(mvm
, "Scan failed! ret %d\n", ret
);
2224 iwl_mvm_resume_tcm(mvm
);
2228 IWL_DEBUG_SCAN(mvm
, "Scan request was sent successfully\n");
2229 mvm
->scan_status
|= IWL_MVM_SCAN_REGULAR
;
2230 mvm
->scan_vif
= iwl_mvm_vif_from_mac80211(vif
);
2232 schedule_delayed_work(&mvm
->scan_timeout_dwork
,
2233 msecs_to_jiffies(SCAN_TIMEOUT
));
2238 int iwl_mvm_sched_scan_start(struct iwl_mvm
*mvm
,
2239 struct ieee80211_vif
*vif
,
2240 struct cfg80211_sched_scan_request
*req
,
2241 struct ieee80211_scan_ies
*ies
,
2244 struct iwl_host_cmd hcmd
= {
2245 .len
= { iwl_mvm_scan_size(mvm
), },
2246 .data
= { mvm
->scan_cmd
, },
2247 .dataflags
= { IWL_HCMD_DFL_NOCOPY
, },
2249 struct iwl_mvm_scan_params params
= {};
2252 lockdep_assert_held(&mvm
->mutex
);
2254 if (iwl_mvm_is_lar_supported(mvm
) && !mvm
->lar_regdom_set
) {
2255 IWL_ERR(mvm
, "sched-scan while LAR regdomain is not set\n");
2259 ret
= iwl_mvm_check_running_scans(mvm
, type
);
2263 /* we should have failed registration if scan_cmd was NULL */
2264 if (WARN_ON(!mvm
->scan_cmd
))
2267 if (!iwl_mvm_scan_fits(mvm
, req
->n_ssids
, ies
, req
->n_channels
))
2270 params
.n_ssids
= req
->n_ssids
;
2271 params
.flags
= req
->flags
;
2272 params
.n_channels
= req
->n_channels
;
2273 params
.ssids
= req
->ssids
;
2274 params
.channels
= req
->channels
;
2275 params
.mac_addr
= req
->mac_addr
;
2276 params
.mac_addr_mask
= req
->mac_addr_mask
;
2277 params
.no_cck
= false;
2278 params
.pass_all
= iwl_mvm_scan_pass_all(mvm
, req
);
2279 params
.n_match_sets
= req
->n_match_sets
;
2280 params
.match_sets
= req
->match_sets
;
2281 if (!req
->n_scan_plans
)
2284 params
.n_scan_plans
= req
->n_scan_plans
;
2285 params
.scan_plans
= req
->scan_plans
;
2287 iwl_mvm_fill_scan_type(mvm
, ¶ms
, vif
);
2289 /* In theory, LMAC scans can handle a 32-bit delay, but since
2290 * waiting for over 18 hours to start the scan is a bit silly
2291 * and to keep it aligned with UMAC scans (which only support
2292 * 16-bit delays), trim it down to 16-bits.
2294 if (req
->delay
> U16_MAX
) {
2296 "delay value is > 16-bits, set to max possible\n");
2297 params
.delay
= U16_MAX
;
2299 params
.delay
= req
->delay
;
2302 ret
= iwl_mvm_config_sched_scan_profiles(mvm
, req
);
2306 iwl_mvm_build_scan_probe(mvm
, vif
, ies
, ¶ms
);
2308 ret
= iwl_mvm_build_scan_cmd(mvm
, vif
, &hcmd
, ¶ms
, type
);
2313 ret
= iwl_mvm_send_cmd(mvm
, &hcmd
);
2316 "Sched scan request was sent successfully\n");
2317 mvm
->scan_status
|= type
;
2319 /* If the scan failed, it usually means that the FW was unable
2320 * to allocate the time events. Warn on it, but maybe we
2321 * should try to send the command again with different params.
2323 IWL_ERR(mvm
, "Sched scan failed! ret %d\n", ret
);
2329 void iwl_mvm_rx_umac_scan_complete_notif(struct iwl_mvm
*mvm
,
2330 struct iwl_rx_cmd_buffer
*rxb
)
2332 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
2333 struct iwl_umac_scan_complete
*notif
= (void *)pkt
->data
;
2334 u32 uid
= __le32_to_cpu(notif
->uid
);
2335 bool aborted
= (notif
->status
== IWL_SCAN_OFFLOAD_ABORTED
);
2337 if (WARN_ON(!(mvm
->scan_uid_status
[uid
] & mvm
->scan_status
)))
2340 /* if the scan is already stopping, we don't need to notify mac80211 */
2341 if (mvm
->scan_uid_status
[uid
] == IWL_MVM_SCAN_REGULAR
) {
2342 struct cfg80211_scan_info info
= {
2344 .scan_start_tsf
= mvm
->scan_start
,
2347 memcpy(info
.tsf_bssid
, mvm
->scan_vif
->bssid
, ETH_ALEN
);
2348 ieee80211_scan_completed(mvm
->hw
, &info
);
2349 mvm
->scan_vif
= NULL
;
2350 cancel_delayed_work(&mvm
->scan_timeout_dwork
);
2351 iwl_mvm_resume_tcm(mvm
);
2352 } else if (mvm
->scan_uid_status
[uid
] == IWL_MVM_SCAN_SCHED
) {
2353 ieee80211_sched_scan_stopped(mvm
->hw
);
2354 mvm
->sched_scan_pass_all
= SCHED_SCAN_PASS_ALL_DISABLED
;
2357 mvm
->scan_status
&= ~mvm
->scan_uid_status
[uid
];
2359 "Scan completed, uid %u type %u, status %s, EBS status %s\n",
2360 uid
, mvm
->scan_uid_status
[uid
],
2361 notif
->status
== IWL_SCAN_OFFLOAD_COMPLETED
?
2362 "completed" : "aborted",
2363 iwl_mvm_ebs_status_str(notif
->ebs_status
));
2365 "Last line %d, Last iteration %d, Time from last iteration %d\n",
2366 notif
->last_schedule
, notif
->last_iter
,
2367 __le32_to_cpu(notif
->time_from_last_iter
));
2369 if (notif
->ebs_status
!= IWL_SCAN_EBS_SUCCESS
&&
2370 notif
->ebs_status
!= IWL_SCAN_EBS_INACTIVE
)
2371 mvm
->last_ebs_successful
= false;
2373 mvm
->scan_uid_status
[uid
] = 0;
2376 void iwl_mvm_rx_umac_scan_iter_complete_notif(struct iwl_mvm
*mvm
,
2377 struct iwl_rx_cmd_buffer
*rxb
)
2379 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
2380 struct iwl_umac_scan_iter_complete_notif
*notif
= (void *)pkt
->data
;
2382 mvm
->scan_start
= le64_to_cpu(notif
->start_tsf
);
2385 "UMAC Scan iteration complete: status=0x%x scanned_channels=%d\n",
2386 notif
->status
, notif
->scanned_channels
);
2388 if (mvm
->sched_scan_pass_all
== SCHED_SCAN_PASS_ALL_FOUND
) {
2389 IWL_DEBUG_SCAN(mvm
, "Pass all scheduled scan results found\n");
2390 ieee80211_sched_scan_results(mvm
->hw
);
2391 mvm
->sched_scan_pass_all
= SCHED_SCAN_PASS_ALL_ENABLED
;
2395 "UMAC Scan iteration complete: scan started at %llu (TSF)\n",
2399 static int iwl_mvm_umac_scan_abort(struct iwl_mvm
*mvm
, int type
)
2401 struct iwl_umac_scan_abort cmd
= {};
2404 lockdep_assert_held(&mvm
->mutex
);
2406 /* We should always get a valid index here, because we already
2407 * checked that this type of scan was running in the generic
2410 uid
= iwl_mvm_scan_uid_by_status(mvm
, type
);
2411 if (WARN_ON_ONCE(uid
< 0))
2414 cmd
.uid
= cpu_to_le32(uid
);
2416 IWL_DEBUG_SCAN(mvm
, "Sending scan abort, uid %u\n", uid
);
2418 ret
= iwl_mvm_send_cmd_pdu(mvm
,
2419 iwl_cmd_id(SCAN_ABORT_UMAC
,
2420 IWL_ALWAYS_LONG_GROUP
, 0),
2421 0, sizeof(cmd
), &cmd
);
2423 mvm
->scan_uid_status
[uid
] = type
<< IWL_MVM_SCAN_STOPPING_SHIFT
;
2428 static int iwl_mvm_scan_stop_wait(struct iwl_mvm
*mvm
, int type
)
2430 struct iwl_notification_wait wait_scan_done
;
2431 static const u16 scan_done_notif
[] = { SCAN_COMPLETE_UMAC
,
2432 SCAN_OFFLOAD_COMPLETE
, };
2435 lockdep_assert_held(&mvm
->mutex
);
2437 iwl_init_notification_wait(&mvm
->notif_wait
, &wait_scan_done
,
2439 ARRAY_SIZE(scan_done_notif
),
2442 IWL_DEBUG_SCAN(mvm
, "Preparing to stop scan, type %x\n", type
);
2444 if (fw_has_capa(&mvm
->fw
->ucode_capa
, IWL_UCODE_TLV_CAPA_UMAC_SCAN
))
2445 ret
= iwl_mvm_umac_scan_abort(mvm
, type
);
2447 ret
= iwl_mvm_lmac_scan_abort(mvm
);
2450 IWL_DEBUG_SCAN(mvm
, "couldn't stop scan type %d\n", type
);
2451 iwl_remove_notification(&mvm
->notif_wait
, &wait_scan_done
);
2455 return iwl_wait_notification(&mvm
->notif_wait
, &wait_scan_done
,
2459 #define IWL_SCAN_REQ_UMAC_HANDLE_SIZE(_ver) { \
2460 case (_ver): return sizeof(struct iwl_scan_req_umac_v##_ver); \
2463 static int iwl_scan_req_umac_get_size(u8 scan_ver
)
2466 IWL_SCAN_REQ_UMAC_HANDLE_SIZE(13);
2467 IWL_SCAN_REQ_UMAC_HANDLE_SIZE(12);
2473 int iwl_mvm_scan_size(struct iwl_mvm
*mvm
)
2475 int base_size
, tail_size
;
2476 u8 scan_ver
= iwl_mvm_lookup_cmd_ver(mvm
->fw
, IWL_ALWAYS_LONG_GROUP
,
2479 base_size
= iwl_scan_req_umac_get_size(scan_ver
);
2484 if (iwl_mvm_is_adaptive_dwell_v2_supported(mvm
))
2485 base_size
= IWL_SCAN_REQ_UMAC_SIZE_V8
;
2486 else if (iwl_mvm_is_adaptive_dwell_supported(mvm
))
2487 base_size
= IWL_SCAN_REQ_UMAC_SIZE_V7
;
2488 else if (iwl_mvm_cdb_scan_api(mvm
))
2489 base_size
= IWL_SCAN_REQ_UMAC_SIZE_V6
;
2491 base_size
= IWL_SCAN_REQ_UMAC_SIZE_V1
;
2493 if (fw_has_capa(&mvm
->fw
->ucode_capa
, IWL_UCODE_TLV_CAPA_UMAC_SCAN
)) {
2494 if (iwl_mvm_is_scan_ext_chan_supported(mvm
))
2495 tail_size
= sizeof(struct iwl_scan_req_umac_tail_v2
);
2497 tail_size
= sizeof(struct iwl_scan_req_umac_tail_v1
);
2500 sizeof(struct iwl_scan_channel_cfg_umac
) *
2501 mvm
->fw
->ucode_capa
.n_scan_channels
+
2504 return sizeof(struct iwl_scan_req_lmac
) +
2505 sizeof(struct iwl_scan_channel_cfg_lmac
) *
2506 mvm
->fw
->ucode_capa
.n_scan_channels
+
2507 sizeof(struct iwl_scan_probe_req_v1
);
2511 * This function is used in nic restart flow, to inform mac80211 about scans
2512 * that was aborted by restart flow or by an assert.
2514 void iwl_mvm_report_scan_aborted(struct iwl_mvm
*mvm
)
2516 if (fw_has_capa(&mvm
->fw
->ucode_capa
, IWL_UCODE_TLV_CAPA_UMAC_SCAN
)) {
2519 uid
= iwl_mvm_scan_uid_by_status(mvm
, IWL_MVM_SCAN_REGULAR
);
2521 struct cfg80211_scan_info info
= {
2525 ieee80211_scan_completed(mvm
->hw
, &info
);
2526 mvm
->scan_uid_status
[uid
] = 0;
2528 uid
= iwl_mvm_scan_uid_by_status(mvm
, IWL_MVM_SCAN_SCHED
);
2529 if (uid
>= 0 && !mvm
->fw_restart
) {
2530 ieee80211_sched_scan_stopped(mvm
->hw
);
2531 mvm
->sched_scan_pass_all
= SCHED_SCAN_PASS_ALL_DISABLED
;
2532 mvm
->scan_uid_status
[uid
] = 0;
2535 /* We shouldn't have any UIDs still set. Loop over all the
2536 * UIDs to make sure there's nothing left there and warn if
2539 for (i
= 0; i
< mvm
->max_scans
; i
++) {
2540 if (WARN_ONCE(mvm
->scan_uid_status
[i
],
2541 "UMAC scan UID %d status was not cleaned\n",
2543 mvm
->scan_uid_status
[i
] = 0;
2546 if (mvm
->scan_status
& IWL_MVM_SCAN_REGULAR
) {
2547 struct cfg80211_scan_info info
= {
2551 ieee80211_scan_completed(mvm
->hw
, &info
);
2554 /* Sched scan will be restarted by mac80211 in
2555 * restart_hw, so do not report if FW is about to be
2558 if ((mvm
->scan_status
& IWL_MVM_SCAN_SCHED
) &&
2560 ieee80211_sched_scan_stopped(mvm
->hw
);
2561 mvm
->sched_scan_pass_all
= SCHED_SCAN_PASS_ALL_DISABLED
;
2566 int iwl_mvm_scan_stop(struct iwl_mvm
*mvm
, int type
, bool notify
)
2570 if (!(mvm
->scan_status
& type
))
2573 if (iwl_mvm_is_radio_killed(mvm
)) {
2578 ret
= iwl_mvm_scan_stop_wait(mvm
, type
);
2580 mvm
->scan_status
|= type
<< IWL_MVM_SCAN_STOPPING_SHIFT
;
2582 /* Clear the scan status so the next scan requests will
2583 * succeed and mark the scan as stopping, so that the Rx
2584 * handler doesn't do anything, as the scan was stopped from
2587 mvm
->scan_status
&= ~type
;
2589 if (type
== IWL_MVM_SCAN_REGULAR
) {
2590 cancel_delayed_work(&mvm
->scan_timeout_dwork
);
2592 struct cfg80211_scan_info info
= {
2596 ieee80211_scan_completed(mvm
->hw
, &info
);
2598 } else if (notify
) {
2599 ieee80211_sched_scan_stopped(mvm
->hw
);
2600 mvm
->sched_scan_pass_all
= SCHED_SCAN_PASS_ALL_DISABLED
;