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
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
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 <ilw@linux.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 * All rights reserved.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
42 * * Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * * Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in
46 * the documentation and/or other materials provided with the
48 * * Neither the name Intel Corporation nor the names of its
49 * contributors may be used to endorse or promote products derived
50 * from this software without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 *****************************************************************************/
66 #include <linux/etherdevice.h>
67 #include <net/mac80211.h>
70 #include "fw-api-scan.h"
72 #define IWL_DENSE_EBS_SCAN_RATIO 5
73 #define IWL_SPARSE_EBS_SCAN_RATIO 1
75 struct iwl_mvm_scan_params
{
78 bool passive_fragmented
;
82 struct cfg80211_ssid
*ssids
;
83 struct ieee80211_channel
**channels
;
84 u16 interval
; /* interval between scans (in secs) */
91 struct iwl_scan_probe_req preq
;
92 struct cfg80211_match_set
*match_sets
;
98 u8 full_scan_mul
; /* not used for UMAC */
102 static u8
iwl_mvm_scan_rx_ant(struct iwl_mvm
*mvm
)
104 if (mvm
->scan_rx_ant
!= ANT_NONE
)
105 return mvm
->scan_rx_ant
;
106 return iwl_mvm_get_valid_rx_ant(mvm
);
109 static inline __le16
iwl_mvm_scan_rx_chain(struct iwl_mvm
*mvm
)
114 rx_ant
= iwl_mvm_scan_rx_ant(mvm
);
115 rx_chain
= rx_ant
<< PHY_RX_CHAIN_VALID_POS
;
116 rx_chain
|= rx_ant
<< PHY_RX_CHAIN_FORCE_MIMO_SEL_POS
;
117 rx_chain
|= rx_ant
<< PHY_RX_CHAIN_FORCE_SEL_POS
;
118 rx_chain
|= 0x1 << PHY_RX_CHAIN_DRIVER_FORCE_POS
;
119 return cpu_to_le16(rx_chain
);
122 static __le32
iwl_mvm_scan_rxon_flags(enum ieee80211_band band
)
124 if (band
== IEEE80211_BAND_2GHZ
)
125 return cpu_to_le32(PHY_BAND_24
);
127 return cpu_to_le32(PHY_BAND_5
);
131 iwl_mvm_scan_rate_n_flags(struct iwl_mvm
*mvm
, enum ieee80211_band band
,
136 mvm
->scan_last_antenna_idx
=
137 iwl_mvm_next_antenna(mvm
, iwl_mvm_get_valid_tx_ant(mvm
),
138 mvm
->scan_last_antenna_idx
);
139 tx_ant
= BIT(mvm
->scan_last_antenna_idx
) << RATE_MCS_ANT_POS
;
141 if (band
== IEEE80211_BAND_2GHZ
&& !no_cck
)
142 return cpu_to_le32(IWL_RATE_1M_PLCP
| RATE_MCS_CCK_MSK
|
145 return cpu_to_le32(IWL_RATE_6M_PLCP
| tx_ant
);
148 static void iwl_mvm_scan_condition_iterator(void *data
, u8
*mac
,
149 struct ieee80211_vif
*vif
)
151 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
152 int *global_cnt
= data
;
154 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
&& mvmvif
->phy_ctxt
&&
155 mvmvif
->phy_ctxt
->id
< MAX_PHYS
)
159 static void iwl_mvm_scan_calc_dwell(struct iwl_mvm
*mvm
,
160 struct ieee80211_vif
*vif
,
161 struct iwl_mvm_scan_params
*params
)
164 u8 frag_passive_dwell
= 0;
166 ieee80211_iterate_active_interfaces_atomic(mvm
->hw
,
167 IEEE80211_IFACE_ITER_NORMAL
,
168 iwl_mvm_scan_condition_iterator
,
173 params
->suspend_time
= 30;
174 params
->max_out_time
= 120;
176 if (iwl_mvm_low_latency(mvm
)) {
177 if (fw_has_api(&mvm
->fw
->ucode_capa
,
178 IWL_UCODE_TLV_API_FRAGMENTED_SCAN
)) {
180 params
->suspend_time
= 105;
182 * If there is more than one active interface make
183 * passive scan more fragmented.
185 frag_passive_dwell
= 40;
186 params
->max_out_time
= frag_passive_dwell
;
188 params
->suspend_time
= 120;
189 params
->max_out_time
= 120;
193 if (frag_passive_dwell
&&
194 fw_has_api(&mvm
->fw
->ucode_capa
,
195 IWL_UCODE_TLV_API_FRAGMENTED_SCAN
)) {
197 * P2P device scan should not be fragmented to avoid negative
198 * impact on P2P device discovery. Configure max_out_time to be
199 * equal to dwell time on passive channel.
201 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
202 params
->max_out_time
= 120;
204 params
->passive_fragmented
= true;
208 if ((params
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
209 (params
->max_out_time
> 200))
210 params
->max_out_time
= 200;
214 if (params
->passive_fragmented
)
215 params
->fragmented_dwell
= frag_passive_dwell
;
218 * use only basic dwell time in scan command, regardless of the band or
219 * the number of the probes. FW will calculate the actual dwell time.
221 params
->passive_dwell
= 110;
222 params
->active_dwell
= 10;
226 "scan parameters: max_out_time %d, suspend_time %d, passive_fragmented %d\n",
227 params
->max_out_time
, params
->suspend_time
,
228 params
->passive_fragmented
);
231 static inline bool iwl_mvm_rrm_scan_needed(struct iwl_mvm
*mvm
)
233 /* require rrm scan whenever the fw supports it */
234 return fw_has_capa(&mvm
->fw
->ucode_capa
,
235 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT
);
238 static int iwl_mvm_max_scan_ie_fw_cmd_room(struct iwl_mvm
*mvm
)
242 max_probe_len
= SCAN_OFFLOAD_PROBE_REQ_SIZE
;
244 /* we create the 802.11 header and SSID element */
245 max_probe_len
-= 24 + 2;
247 /* DS parameter set element is added on 2.4GHZ band if required */
248 if (iwl_mvm_rrm_scan_needed(mvm
))
251 return max_probe_len
;
254 int iwl_mvm_max_scan_ie_len(struct iwl_mvm
*mvm
)
256 int max_ie_len
= iwl_mvm_max_scan_ie_fw_cmd_room(mvm
);
258 /* TODO: [BUG] This function should return the maximum allowed size of
259 * scan IEs, however the LMAC scan api contains both 2GHZ and 5GHZ IEs
260 * in the same command. So the correct implementation of this function
261 * is just iwl_mvm_max_scan_ie_fw_cmd_room() / 2. Currently the scan
262 * command has only 512 bytes and it would leave us with about 240
263 * bytes for scan IEs, which is clearly not enough. So meanwhile
264 * we will report an incorrect value. This may result in a failure to
265 * issue a scan in unified_scan_lmac and unified_sched_scan_lmac
266 * functions with -ENOBUFS, if a large enough probe will be provided.
271 static u8
*iwl_mvm_dump_channel_list(struct iwl_scan_results_notif
*res
,
272 int num_res
, u8
*buf
, size_t buf_size
)
275 u8
*pos
= buf
, *end
= buf
+ buf_size
;
277 for (i
= 0; pos
< end
&& i
< num_res
; i
++)
278 pos
+= snprintf(pos
, end
- pos
, " %u", res
[i
].channel
);
280 /* terminate the string in case the buffer was too short */
281 *(buf
+ buf_size
- 1) = '\0';
286 void iwl_mvm_rx_lmac_scan_iter_complete_notif(struct iwl_mvm
*mvm
,
287 struct iwl_rx_cmd_buffer
*rxb
)
289 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
290 struct iwl_lmac_scan_complete_notif
*notif
= (void *)pkt
->data
;
294 "Scan offload iteration complete: status=0x%x scanned channels=%d channels list: %s\n",
295 notif
->status
, notif
->scanned_channels
,
296 iwl_mvm_dump_channel_list(notif
->results
,
297 notif
->scanned_channels
, buf
,
301 void iwl_mvm_rx_scan_match_found(struct iwl_mvm
*mvm
,
302 struct iwl_rx_cmd_buffer
*rxb
)
304 IWL_DEBUG_SCAN(mvm
, "Scheduled scan results\n");
305 ieee80211_sched_scan_results(mvm
->hw
);
308 static const char *iwl_mvm_ebs_status_str(enum iwl_scan_ebs_status status
)
311 case IWL_SCAN_EBS_SUCCESS
:
313 case IWL_SCAN_EBS_INACTIVE
:
315 case IWL_SCAN_EBS_FAILED
:
316 case IWL_SCAN_EBS_CHAN_NOT_FOUND
:
322 void iwl_mvm_rx_lmac_scan_complete_notif(struct iwl_mvm
*mvm
,
323 struct iwl_rx_cmd_buffer
*rxb
)
325 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
326 struct iwl_periodic_scan_complete
*scan_notif
= (void *)pkt
->data
;
327 bool aborted
= (scan_notif
->status
== IWL_SCAN_OFFLOAD_ABORTED
);
329 /* scan status must be locked for proper checking */
330 lockdep_assert_held(&mvm
->mutex
);
332 /* We first check if we were stopping a scan, in which case we
333 * just clear the stopping flag. Then we check if it was a
334 * firmware initiated stop, in which case we need to inform
336 * Note that we can have a stopping and a running scan
337 * simultaneously, but we can't have two different types of
338 * scans stopping or running at the same time (since LMAC
339 * doesn't support it).
342 if (mvm
->scan_status
& IWL_MVM_SCAN_STOPPING_SCHED
) {
343 WARN_ON_ONCE(mvm
->scan_status
& IWL_MVM_SCAN_STOPPING_REGULAR
);
345 IWL_DEBUG_SCAN(mvm
, "Scheduled scan %s, EBS status %s\n",
346 aborted
? "aborted" : "completed",
347 iwl_mvm_ebs_status_str(scan_notif
->ebs_status
));
349 mvm
->scan_status
&= ~IWL_MVM_SCAN_STOPPING_SCHED
;
350 } else if (mvm
->scan_status
& IWL_MVM_SCAN_STOPPING_REGULAR
) {
351 IWL_DEBUG_SCAN(mvm
, "Regular scan %s, EBS status %s\n",
352 aborted
? "aborted" : "completed",
353 iwl_mvm_ebs_status_str(scan_notif
->ebs_status
));
355 mvm
->scan_status
&= ~IWL_MVM_SCAN_STOPPING_REGULAR
;
356 } else if (mvm
->scan_status
& IWL_MVM_SCAN_SCHED
) {
357 WARN_ON_ONCE(mvm
->scan_status
& IWL_MVM_SCAN_REGULAR
);
359 IWL_DEBUG_SCAN(mvm
, "Scheduled scan %s, EBS status %s (FW)\n",
360 aborted
? "aborted" : "completed",
361 iwl_mvm_ebs_status_str(scan_notif
->ebs_status
));
363 mvm
->scan_status
&= ~IWL_MVM_SCAN_SCHED
;
364 ieee80211_sched_scan_stopped(mvm
->hw
);
365 } else if (mvm
->scan_status
& IWL_MVM_SCAN_REGULAR
) {
366 IWL_DEBUG_SCAN(mvm
, "Regular scan %s, EBS status %s (FW)\n",
367 aborted
? "aborted" : "completed",
368 iwl_mvm_ebs_status_str(scan_notif
->ebs_status
));
370 mvm
->scan_status
&= ~IWL_MVM_SCAN_REGULAR
;
371 ieee80211_scan_completed(mvm
->hw
,
372 scan_notif
->status
== IWL_SCAN_OFFLOAD_ABORTED
);
373 iwl_mvm_unref(mvm
, IWL_MVM_REF_SCAN
);
376 mvm
->last_ebs_successful
=
377 scan_notif
->ebs_status
== IWL_SCAN_EBS_SUCCESS
||
378 scan_notif
->ebs_status
== IWL_SCAN_EBS_INACTIVE
;
381 static int iwl_ssid_exist(u8
*ssid
, u8 ssid_len
, struct iwl_ssid_ie
*ssid_list
)
385 for (i
= 0; i
< PROBE_OPTION_MAX
; i
++) {
386 if (!ssid_list
[i
].len
)
388 if (ssid_list
[i
].len
== ssid_len
&&
389 !memcmp(ssid_list
->ssid
, ssid
, ssid_len
))
395 /* We insert the SSIDs in an inverted order, because the FW will
398 static void iwl_scan_build_ssids(struct iwl_mvm_scan_params
*params
,
399 struct iwl_ssid_ie
*ssids
,
406 * copy SSIDs from match list.
407 * iwl_config_sched_scan_profiles() uses the order of these ssids to
410 for (i
= 0, j
= params
->n_match_sets
- 1;
411 j
>= 0 && i
< PROBE_OPTION_MAX
;
413 /* skip empty SSID matchsets */
414 if (!params
->match_sets
[j
].ssid
.ssid_len
)
416 ssids
[i
].id
= WLAN_EID_SSID
;
417 ssids
[i
].len
= params
->match_sets
[j
].ssid
.ssid_len
;
418 memcpy(ssids
[i
].ssid
, params
->match_sets
[j
].ssid
.ssid
,
422 /* add SSIDs from scan SSID list */
424 for (j
= params
->n_ssids
- 1;
425 j
>= 0 && i
< PROBE_OPTION_MAX
;
427 index
= iwl_ssid_exist(params
->ssids
[j
].ssid
,
428 params
->ssids
[j
].ssid_len
,
431 ssids
[i
].id
= WLAN_EID_SSID
;
432 ssids
[i
].len
= params
->ssids
[j
].ssid_len
;
433 memcpy(ssids
[i
].ssid
, params
->ssids
[j
].ssid
,
435 *ssid_bitmap
|= BIT(i
);
437 *ssid_bitmap
|= BIT(index
);
443 iwl_mvm_config_sched_scan_profiles(struct iwl_mvm
*mvm
,
444 struct cfg80211_sched_scan_request
*req
)
446 struct iwl_scan_offload_profile
*profile
;
447 struct iwl_scan_offload_profile_cfg
*profile_cfg
;
448 struct iwl_scan_offload_blacklist
*blacklist
;
449 struct iwl_host_cmd cmd
= {
450 .id
= SCAN_OFFLOAD_UPDATE_PROFILES_CMD
,
451 .len
[1] = sizeof(*profile_cfg
),
452 .dataflags
[0] = IWL_HCMD_DFL_NOCOPY
,
453 .dataflags
[1] = IWL_HCMD_DFL_NOCOPY
,
459 if (WARN_ON(req
->n_match_sets
> IWL_SCAN_MAX_PROFILES
))
462 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_SHORT_BL
)
463 blacklist_len
= IWL_SCAN_SHORT_BLACKLIST_LEN
;
465 blacklist_len
= IWL_SCAN_MAX_BLACKLIST_LEN
;
467 blacklist
= kzalloc(sizeof(*blacklist
) * blacklist_len
, GFP_KERNEL
);
471 profile_cfg
= kzalloc(sizeof(*profile_cfg
), GFP_KERNEL
);
477 cmd
.data
[0] = blacklist
;
478 cmd
.len
[0] = sizeof(*blacklist
) * blacklist_len
;
479 cmd
.data
[1] = profile_cfg
;
481 /* No blacklist configuration */
483 profile_cfg
->num_profiles
= req
->n_match_sets
;
484 profile_cfg
->active_clients
= SCAN_CLIENT_SCHED_SCAN
;
485 profile_cfg
->pass_match
= SCAN_CLIENT_SCHED_SCAN
;
486 profile_cfg
->match_notify
= SCAN_CLIENT_SCHED_SCAN
;
487 if (!req
->n_match_sets
|| !req
->match_sets
[0].ssid
.ssid_len
)
488 profile_cfg
->any_beacon_notify
= SCAN_CLIENT_SCHED_SCAN
;
490 for (i
= 0; i
< req
->n_match_sets
; i
++) {
491 profile
= &profile_cfg
->profiles
[i
];
492 profile
->ssid_index
= i
;
493 /* Support any cipher and auth algorithm */
494 profile
->unicast_cipher
= 0xff;
495 profile
->auth_alg
= 0xff;
496 profile
->network_type
= IWL_NETWORK_TYPE_ANY
;
497 profile
->band_selection
= IWL_SCAN_OFFLOAD_SELECT_ANY
;
498 profile
->client_bitmap
= SCAN_CLIENT_SCHED_SCAN
;
501 IWL_DEBUG_SCAN(mvm
, "Sending scheduled scan profile config\n");
503 ret
= iwl_mvm_send_cmd(mvm
, &cmd
);
511 static bool iwl_mvm_scan_pass_all(struct iwl_mvm
*mvm
,
512 struct cfg80211_sched_scan_request
*req
)
514 if (req
->n_match_sets
&& req
->match_sets
[0].ssid
.ssid_len
) {
516 "Sending scheduled scan with filtering, n_match_sets %d\n",
521 IWL_DEBUG_SCAN(mvm
, "Sending Scheduled scan without filtering\n");
525 static int iwl_mvm_lmac_scan_abort(struct iwl_mvm
*mvm
)
528 struct iwl_host_cmd cmd
= {
529 .id
= SCAN_OFFLOAD_ABORT_CMD
,
533 ret
= iwl_mvm_send_cmd_status(mvm
, &cmd
, &status
);
537 if (status
!= CAN_ABORT_STATUS
) {
539 * The scan abort will return 1 for success or
540 * 2 for "failure". A failure condition can be
541 * due to simply not being in an active scan which
542 * can occur if we send the scan abort before the
543 * microcode has notified us that a scan is completed.
545 IWL_DEBUG_SCAN(mvm
, "SCAN OFFLOAD ABORT ret %d.\n", status
);
552 static void iwl_mvm_scan_fill_tx_cmd(struct iwl_mvm
*mvm
,
553 struct iwl_scan_req_tx_cmd
*tx_cmd
,
556 tx_cmd
[0].tx_flags
= cpu_to_le32(TX_CMD_FLG_SEQ_CTL
|
558 tx_cmd
[0].rate_n_flags
= iwl_mvm_scan_rate_n_flags(mvm
,
561 tx_cmd
[0].sta_id
= mvm
->aux_sta
.sta_id
;
563 tx_cmd
[1].tx_flags
= cpu_to_le32(TX_CMD_FLG_SEQ_CTL
|
565 tx_cmd
[1].rate_n_flags
= iwl_mvm_scan_rate_n_flags(mvm
,
568 tx_cmd
[1].sta_id
= mvm
->aux_sta
.sta_id
;
572 iwl_mvm_lmac_scan_cfg_channels(struct iwl_mvm
*mvm
,
573 struct ieee80211_channel
**channels
,
574 int n_channels
, u32 ssid_bitmap
,
575 struct iwl_scan_req_lmac
*cmd
)
577 struct iwl_scan_channel_cfg_lmac
*channel_cfg
= (void *)&cmd
->data
;
580 for (i
= 0; i
< n_channels
; i
++) {
581 channel_cfg
[i
].channel_num
=
582 cpu_to_le16(channels
[i
]->hw_value
);
583 channel_cfg
[i
].iter_count
= cpu_to_le16(1);
584 channel_cfg
[i
].iter_interval
= 0;
585 channel_cfg
[i
].flags
=
586 cpu_to_le32(IWL_UNIFIED_SCAN_CHANNEL_PARTIAL
|
591 static u8
*iwl_mvm_copy_and_insert_ds_elem(struct iwl_mvm
*mvm
, const u8
*ies
,
592 size_t len
, u8
*const pos
)
594 static const u8 before_ds_params
[] = {
598 WLAN_EID_EXT_SUPP_RATES
,
603 if (!iwl_mvm_rrm_scan_needed(mvm
)) {
604 memcpy(newpos
, ies
, len
);
608 offs
= ieee80211_ie_split(ies
, len
,
610 ARRAY_SIZE(before_ds_params
),
613 memcpy(newpos
, ies
, offs
);
616 /* Add a placeholder for DS Parameter Set element */
617 *newpos
++ = WLAN_EID_DS_PARAMS
;
621 memcpy(newpos
, ies
+ offs
, len
- offs
);
622 newpos
+= len
- offs
;
628 iwl_mvm_build_scan_probe(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
629 struct ieee80211_scan_ies
*ies
,
630 struct iwl_mvm_scan_params
*params
)
632 struct ieee80211_mgmt
*frame
= (void *)params
->preq
.buf
;
634 const u8
*mac_addr
= params
->flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
?
635 params
->mac_addr
: NULL
;
638 * Unfortunately, right now the offload scan doesn't support randomising
639 * within the firmware, so until the firmware API is ready we implement
640 * it in the driver. This means that the scan iterations won't really be
641 * random, only when it's restarted, but at least that helps a bit.
644 get_random_mask_addr(frame
->sa
, mac_addr
,
645 params
->mac_addr_mask
);
647 memcpy(frame
->sa
, vif
->addr
, ETH_ALEN
);
649 frame
->frame_control
= cpu_to_le16(IEEE80211_STYPE_PROBE_REQ
);
650 eth_broadcast_addr(frame
->da
);
651 eth_broadcast_addr(frame
->bssid
);
654 pos
= frame
->u
.probe_req
.variable
;
655 *pos
++ = WLAN_EID_SSID
;
658 params
->preq
.mac_header
.offset
= 0;
659 params
->preq
.mac_header
.len
= cpu_to_le16(24 + 2);
661 /* Insert ds parameter set element on 2.4 GHz band */
662 newpos
= iwl_mvm_copy_and_insert_ds_elem(mvm
,
663 ies
->ies
[IEEE80211_BAND_2GHZ
],
664 ies
->len
[IEEE80211_BAND_2GHZ
],
666 params
->preq
.band_data
[0].offset
= cpu_to_le16(pos
- params
->preq
.buf
);
667 params
->preq
.band_data
[0].len
= cpu_to_le16(newpos
- pos
);
670 memcpy(pos
, ies
->ies
[IEEE80211_BAND_5GHZ
],
671 ies
->len
[IEEE80211_BAND_5GHZ
]);
672 params
->preq
.band_data
[1].offset
= cpu_to_le16(pos
- params
->preq
.buf
);
673 params
->preq
.band_data
[1].len
=
674 cpu_to_le16(ies
->len
[IEEE80211_BAND_5GHZ
]);
675 pos
+= ies
->len
[IEEE80211_BAND_5GHZ
];
677 memcpy(pos
, ies
->common_ies
, ies
->common_ie_len
);
678 params
->preq
.common_data
.offset
= cpu_to_le16(pos
- params
->preq
.buf
);
679 params
->preq
.common_data
.len
= cpu_to_le16(ies
->common_ie_len
);
682 static __le32
iwl_mvm_scan_priority(struct iwl_mvm
*mvm
,
683 enum iwl_scan_priority_ext prio
)
685 if (fw_has_api(&mvm
->fw
->ucode_capa
,
686 IWL_UCODE_TLV_API_EXT_SCAN_PRIORITY
))
687 return cpu_to_le32(prio
);
689 if (prio
<= IWL_SCAN_PRIORITY_EXT_2
)
690 return cpu_to_le32(IWL_SCAN_PRIORITY_LOW
);
692 if (prio
<= IWL_SCAN_PRIORITY_EXT_4
)
693 return cpu_to_le32(IWL_SCAN_PRIORITY_MEDIUM
);
695 return cpu_to_le32(IWL_SCAN_PRIORITY_HIGH
);
698 static void iwl_mvm_scan_lmac_dwell(struct iwl_mvm
*mvm
,
699 struct iwl_scan_req_lmac
*cmd
,
700 struct iwl_mvm_scan_params
*params
)
702 cmd
->active_dwell
= params
->active_dwell
;
703 cmd
->passive_dwell
= params
->passive_dwell
;
704 if (params
->passive_fragmented
)
705 cmd
->fragmented_dwell
= params
->fragmented_dwell
;
706 cmd
->max_out_time
= cpu_to_le32(params
->max_out_time
);
707 cmd
->suspend_time
= cpu_to_le32(params
->suspend_time
);
708 cmd
->scan_prio
= iwl_mvm_scan_priority(mvm
, IWL_SCAN_PRIORITY_EXT_6
);
711 static inline bool iwl_mvm_scan_fits(struct iwl_mvm
*mvm
, int n_ssids
,
712 struct ieee80211_scan_ies
*ies
,
715 return ((n_ssids
<= PROBE_OPTION_MAX
) &&
716 (n_channels
<= mvm
->fw
->ucode_capa
.n_scan_channels
) &
717 (ies
->common_ie_len
+
718 ies
->len
[NL80211_BAND_2GHZ
] +
719 ies
->len
[NL80211_BAND_5GHZ
] <=
720 iwl_mvm_max_scan_ie_fw_cmd_room(mvm
)));
723 static inline bool iwl_mvm_scan_use_ebs(struct iwl_mvm
*mvm
,
724 struct ieee80211_vif
*vif
,
727 const struct iwl_ucode_capabilities
*capa
= &mvm
->fw
->ucode_capa
;
729 /* We can only use EBS if:
730 * 1. the feature is supported;
731 * 2. the last EBS was successful;
732 * 3. if only single scan, the single scan EBS API is supported;
733 * 4. it's not a p2p find operation.
735 return ((capa
->flags
& IWL_UCODE_TLV_FLAGS_EBS_SUPPORT
) &&
736 mvm
->last_ebs_successful
&&
738 fw_has_api(capa
, IWL_UCODE_TLV_API_SINGLE_SCAN_EBS
)) &&
739 vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
);
742 static int iwl_mvm_scan_total_iterations(struct iwl_mvm_scan_params
*params
)
744 return params
->schedule
[0].iterations
+ params
->schedule
[1].iterations
;
747 static int iwl_mvm_scan_lmac_flags(struct iwl_mvm
*mvm
,
748 struct iwl_mvm_scan_params
*params
)
752 if (params
->n_ssids
== 0)
753 flags
|= IWL_MVM_LMAC_SCAN_FLAG_PASSIVE
;
755 if (params
->n_ssids
== 1 && params
->ssids
[0].ssid_len
!= 0)
756 flags
|= IWL_MVM_LMAC_SCAN_FLAG_PRE_CONNECTION
;
758 if (params
->passive_fragmented
)
759 flags
|= IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED
;
761 if (iwl_mvm_rrm_scan_needed(mvm
))
762 flags
|= IWL_MVM_LMAC_SCAN_FLAGS_RRM_ENABLED
;
764 if (params
->pass_all
)
765 flags
|= IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL
;
767 flags
|= IWL_MVM_LMAC_SCAN_FLAG_MATCH
;
769 #ifdef CONFIG_IWLWIFI_DEBUGFS
770 if (mvm
->scan_iter_notif_enabled
)
771 flags
|= IWL_MVM_LMAC_SCAN_FLAG_ITER_COMPLETE
;
777 static int iwl_mvm_scan_lmac(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
778 struct iwl_mvm_scan_params
*params
)
780 struct iwl_scan_req_lmac
*cmd
= mvm
->scan_cmd
;
781 struct iwl_scan_probe_req
*preq
=
782 (void *)(cmd
->data
+ sizeof(struct iwl_scan_channel_cfg_lmac
) *
783 mvm
->fw
->ucode_capa
.n_scan_channels
);
785 int n_iterations
= iwl_mvm_scan_total_iterations(params
);
787 lockdep_assert_held(&mvm
->mutex
);
789 memset(cmd
, 0, ksize(cmd
));
791 iwl_mvm_scan_lmac_dwell(mvm
, cmd
, params
);
793 cmd
->rx_chain_select
= iwl_mvm_scan_rx_chain(mvm
);
794 cmd
->iter_num
= cpu_to_le32(1);
795 cmd
->n_channels
= (u8
)params
->n_channels
;
797 cmd
->delay
= cpu_to_le32(params
->delay
);
799 cmd
->scan_flags
= cpu_to_le32(iwl_mvm_scan_lmac_flags(mvm
, params
));
801 cmd
->flags
= iwl_mvm_scan_rxon_flags(params
->channels
[0]->band
);
802 cmd
->filter_flags
= cpu_to_le32(MAC_FILTER_ACCEPT_GRP
|
803 MAC_FILTER_IN_BEACON
);
804 iwl_mvm_scan_fill_tx_cmd(mvm
, cmd
->tx_cmd
, params
->no_cck
);
805 iwl_scan_build_ssids(params
, cmd
->direct_scan
, &ssid_bitmap
);
807 /* this API uses bits 1-20 instead of 0-19 */
810 cmd
->schedule
[0].delay
= cpu_to_le16(params
->interval
);
811 cmd
->schedule
[0].iterations
= params
->schedule
[0].iterations
;
812 cmd
->schedule
[0].full_scan_mul
= params
->schedule
[0].full_scan_mul
;
813 cmd
->schedule
[1].delay
= cpu_to_le16(params
->interval
);
814 cmd
->schedule
[1].iterations
= params
->schedule
[1].iterations
;
815 cmd
->schedule
[1].full_scan_mul
= params
->schedule
[1].iterations
;
817 if (iwl_mvm_scan_use_ebs(mvm
, vif
, n_iterations
)) {
818 cmd
->channel_opt
[0].flags
=
819 cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS
|
820 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE
|
821 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD
);
822 cmd
->channel_opt
[0].non_ebs_ratio
=
823 cpu_to_le16(IWL_DENSE_EBS_SCAN_RATIO
);
824 cmd
->channel_opt
[1].flags
=
825 cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS
|
826 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE
|
827 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD
);
828 cmd
->channel_opt
[1].non_ebs_ratio
=
829 cpu_to_le16(IWL_SPARSE_EBS_SCAN_RATIO
);
832 iwl_mvm_lmac_scan_cfg_channels(mvm
, params
->channels
,
833 params
->n_channels
, ssid_bitmap
, cmd
);
835 *preq
= params
->preq
;
840 static int rate_to_scan_rate_flag(unsigned int rate
)
842 static const int rate_to_scan_rate
[IWL_RATE_COUNT
] = {
843 [IWL_RATE_1M_INDEX
] = SCAN_CONFIG_RATE_1M
,
844 [IWL_RATE_2M_INDEX
] = SCAN_CONFIG_RATE_2M
,
845 [IWL_RATE_5M_INDEX
] = SCAN_CONFIG_RATE_5M
,
846 [IWL_RATE_11M_INDEX
] = SCAN_CONFIG_RATE_11M
,
847 [IWL_RATE_6M_INDEX
] = SCAN_CONFIG_RATE_6M
,
848 [IWL_RATE_9M_INDEX
] = SCAN_CONFIG_RATE_9M
,
849 [IWL_RATE_12M_INDEX
] = SCAN_CONFIG_RATE_12M
,
850 [IWL_RATE_18M_INDEX
] = SCAN_CONFIG_RATE_18M
,
851 [IWL_RATE_24M_INDEX
] = SCAN_CONFIG_RATE_24M
,
852 [IWL_RATE_36M_INDEX
] = SCAN_CONFIG_RATE_36M
,
853 [IWL_RATE_48M_INDEX
] = SCAN_CONFIG_RATE_48M
,
854 [IWL_RATE_54M_INDEX
] = SCAN_CONFIG_RATE_54M
,
857 return rate_to_scan_rate
[rate
];
860 static __le32
iwl_mvm_scan_config_rates(struct iwl_mvm
*mvm
)
862 struct ieee80211_supported_band
*band
;
863 unsigned int rates
= 0;
866 band
= &mvm
->nvm_data
->bands
[IEEE80211_BAND_2GHZ
];
867 for (i
= 0; i
< band
->n_bitrates
; i
++)
868 rates
|= rate_to_scan_rate_flag(band
->bitrates
[i
].hw_value
);
869 band
= &mvm
->nvm_data
->bands
[IEEE80211_BAND_5GHZ
];
870 for (i
= 0; i
< band
->n_bitrates
; i
++)
871 rates
|= rate_to_scan_rate_flag(band
->bitrates
[i
].hw_value
);
873 /* Set both basic rates and supported rates */
874 rates
|= SCAN_CONFIG_SUPPORTED_RATE(rates
);
876 return cpu_to_le32(rates
);
879 int iwl_mvm_config_scan(struct iwl_mvm
*mvm
)
882 struct iwl_scan_config
*scan_config
;
883 struct ieee80211_supported_band
*band
;
885 mvm
->nvm_data
->bands
[IEEE80211_BAND_2GHZ
].n_channels
+
886 mvm
->nvm_data
->bands
[IEEE80211_BAND_5GHZ
].n_channels
;
887 int ret
, i
, j
= 0, cmd_size
;
888 struct iwl_host_cmd cmd
= {
889 .id
= iwl_cmd_id(SCAN_CFG_CMD
, IWL_ALWAYS_LONG_GROUP
, 0),
892 if (WARN_ON(num_channels
> mvm
->fw
->ucode_capa
.n_scan_channels
))
895 cmd_size
= sizeof(*scan_config
) + mvm
->fw
->ucode_capa
.n_scan_channels
;
897 scan_config
= kzalloc(cmd_size
, GFP_KERNEL
);
901 scan_config
->flags
= cpu_to_le32(SCAN_CONFIG_FLAG_ACTIVATE
|
902 SCAN_CONFIG_FLAG_ALLOW_CHUB_REQS
|
903 SCAN_CONFIG_FLAG_SET_TX_CHAINS
|
904 SCAN_CONFIG_FLAG_SET_RX_CHAINS
|
905 SCAN_CONFIG_FLAG_SET_ALL_TIMES
|
906 SCAN_CONFIG_FLAG_SET_LEGACY_RATES
|
907 SCAN_CONFIG_FLAG_SET_MAC_ADDR
|
908 SCAN_CONFIG_FLAG_SET_CHANNEL_FLAGS
|
909 SCAN_CONFIG_N_CHANNELS(num_channels
));
910 scan_config
->tx_chains
= cpu_to_le32(iwl_mvm_get_valid_tx_ant(mvm
));
911 scan_config
->rx_chains
= cpu_to_le32(iwl_mvm_scan_rx_ant(mvm
));
912 scan_config
->legacy_rates
= iwl_mvm_scan_config_rates(mvm
);
913 scan_config
->out_of_channel_time
= cpu_to_le32(170);
914 scan_config
->suspend_time
= cpu_to_le32(30);
915 scan_config
->dwell_active
= 20;
916 scan_config
->dwell_passive
= 110;
917 scan_config
->dwell_fragmented
= 20;
919 memcpy(&scan_config
->mac_addr
, &mvm
->addresses
[0].addr
, ETH_ALEN
);
921 scan_config
->bcast_sta_id
= mvm
->aux_sta
.sta_id
;
922 scan_config
->channel_flags
= IWL_CHANNEL_FLAG_EBS
|
923 IWL_CHANNEL_FLAG_ACCURATE_EBS
|
924 IWL_CHANNEL_FLAG_EBS_ADD
|
925 IWL_CHANNEL_FLAG_PRE_SCAN_PASSIVE2ACTIVE
;
927 band
= &mvm
->nvm_data
->bands
[IEEE80211_BAND_2GHZ
];
928 for (i
= 0; i
< band
->n_channels
; i
++, j
++)
929 scan_config
->channel_array
[j
] = band
->channels
[i
].hw_value
;
930 band
= &mvm
->nvm_data
->bands
[IEEE80211_BAND_5GHZ
];
931 for (i
= 0; i
< band
->n_channels
; i
++, j
++)
932 scan_config
->channel_array
[j
] = band
->channels
[i
].hw_value
;
934 cmd
.data
[0] = scan_config
;
935 cmd
.len
[0] = cmd_size
;
936 cmd
.dataflags
[0] = IWL_HCMD_DFL_NOCOPY
;
938 IWL_DEBUG_SCAN(mvm
, "Sending UMAC scan config\n");
940 ret
= iwl_mvm_send_cmd(mvm
, &cmd
);
946 static int iwl_mvm_scan_uid_by_status(struct iwl_mvm
*mvm
, int status
)
950 for (i
= 0; i
< mvm
->max_scans
; i
++)
951 if (mvm
->scan_uid_status
[i
] == status
)
957 static void iwl_mvm_scan_umac_dwell(struct iwl_mvm
*mvm
,
958 struct iwl_scan_req_umac
*cmd
,
959 struct iwl_mvm_scan_params
*params
)
961 cmd
->active_dwell
= params
->active_dwell
;
962 cmd
->passive_dwell
= params
->passive_dwell
;
963 if (params
->passive_fragmented
)
964 cmd
->fragmented_dwell
= params
->fragmented_dwell
;
965 cmd
->max_out_time
= cpu_to_le32(params
->max_out_time
);
966 cmd
->suspend_time
= cpu_to_le32(params
->suspend_time
);
968 iwl_mvm_scan_priority(mvm
, IWL_SCAN_PRIORITY_EXT_6
);
970 if (iwl_mvm_scan_total_iterations(params
) == 0)
972 iwl_mvm_scan_priority(mvm
, IWL_SCAN_PRIORITY_EXT_6
);
975 iwl_mvm_scan_priority(mvm
, IWL_SCAN_PRIORITY_EXT_2
);
979 iwl_mvm_umac_scan_cfg_channels(struct iwl_mvm
*mvm
,
980 struct ieee80211_channel
**channels
,
981 int n_channels
, u32 ssid_bitmap
,
982 struct iwl_scan_req_umac
*cmd
)
984 struct iwl_scan_channel_cfg_umac
*channel_cfg
= (void *)&cmd
->data
;
987 for (i
= 0; i
< n_channels
; i
++) {
988 channel_cfg
[i
].flags
= cpu_to_le32(ssid_bitmap
);
989 channel_cfg
[i
].channel_num
= channels
[i
]->hw_value
;
990 channel_cfg
[i
].iter_count
= 1;
991 channel_cfg
[i
].iter_interval
= 0;
995 static u32
iwl_mvm_scan_umac_flags(struct iwl_mvm
*mvm
,
996 struct iwl_mvm_scan_params
*params
)
1000 if (params
->n_ssids
== 0)
1001 flags
= IWL_UMAC_SCAN_GEN_FLAGS_PASSIVE
;
1003 if (params
->n_ssids
== 1 && params
->ssids
[0].ssid_len
!= 0)
1004 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_PRE_CONNECT
;
1006 if (params
->passive_fragmented
)
1007 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_FRAGMENTED
;
1009 if (iwl_mvm_rrm_scan_needed(mvm
))
1010 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_RRM_ENABLED
;
1012 if (params
->pass_all
)
1013 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_PASS_ALL
;
1015 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_MATCH
;
1017 if (iwl_mvm_scan_total_iterations(params
) > 1)
1018 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_PERIODIC
;
1020 #ifdef CONFIG_IWLWIFI_DEBUGFS
1021 if (mvm
->scan_iter_notif_enabled
)
1022 flags
|= IWL_UMAC_SCAN_GEN_FLAGS_ITER_COMPLETE
;
1027 static int iwl_mvm_scan_umac(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
1028 struct iwl_mvm_scan_params
*params
,
1031 struct iwl_scan_req_umac
*cmd
= mvm
->scan_cmd
;
1032 struct iwl_scan_req_umac_tail
*sec_part
= (void *)&cmd
->data
+
1033 sizeof(struct iwl_scan_channel_cfg_umac
) *
1034 mvm
->fw
->ucode_capa
.n_scan_channels
;
1036 u32 ssid_bitmap
= 0;
1037 int n_iterations
= iwl_mvm_scan_total_iterations(params
);
1039 lockdep_assert_held(&mvm
->mutex
);
1041 uid
= iwl_mvm_scan_uid_by_status(mvm
, 0);
1045 memset(cmd
, 0, ksize(cmd
));
1047 iwl_mvm_scan_umac_dwell(mvm
, cmd
, params
);
1049 mvm
->scan_uid_status
[uid
] = type
;
1051 cmd
->uid
= cpu_to_le32(uid
);
1052 cmd
->general_flags
= cpu_to_le32(iwl_mvm_scan_umac_flags(mvm
, params
));
1054 if (type
== IWL_MVM_SCAN_SCHED
)
1055 cmd
->flags
= cpu_to_le32(IWL_UMAC_SCAN_FLAG_PREEMPTIVE
);
1057 if (iwl_mvm_scan_use_ebs(mvm
, vif
, n_iterations
))
1058 cmd
->channel_flags
= IWL_SCAN_CHANNEL_FLAG_EBS
|
1059 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE
|
1060 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD
;
1062 cmd
->n_channels
= params
->n_channels
;
1064 iwl_scan_build_ssids(params
, sec_part
->direct_scan
, &ssid_bitmap
);
1066 iwl_mvm_umac_scan_cfg_channels(mvm
, params
->channels
,
1067 params
->n_channels
, ssid_bitmap
, cmd
);
1069 /* With UMAC we use only one schedule for now, so use the sum
1070 * of the iterations (with a a maximum of 255).
1072 sec_part
->schedule
[0].iter_count
=
1073 (n_iterations
> 255) ? 255 : n_iterations
;
1074 sec_part
->schedule
[0].interval
= cpu_to_le16(params
->interval
);
1076 sec_part
->delay
= cpu_to_le16(params
->delay
);
1077 sec_part
->preq
= params
->preq
;
1082 static int iwl_mvm_num_scans(struct iwl_mvm
*mvm
)
1084 return hweight32(mvm
->scan_status
& IWL_MVM_SCAN_MASK
);
1087 static int iwl_mvm_check_running_scans(struct iwl_mvm
*mvm
, int type
)
1089 /* This looks a bit arbitrary, but the idea is that if we run
1090 * out of possible simultaneous scans and the userspace is
1091 * trying to run a scan type that is already running, we
1092 * return -EBUSY. But if the userspace wants to start a
1093 * different type of scan, we stop the opposite type to make
1094 * space for the new request. The reason is backwards
1095 * compatibility with old wpa_supplicant that wouldn't stop a
1096 * scheduled scan before starting a normal scan.
1099 if (iwl_mvm_num_scans(mvm
) < mvm
->max_scans
)
1102 /* Use a switch, even though this is a bitmask, so that more
1103 * than one bits set will fall in default and we will warn.
1106 case IWL_MVM_SCAN_REGULAR
:
1107 if (mvm
->scan_status
& IWL_MVM_SCAN_REGULAR_MASK
)
1109 return iwl_mvm_scan_stop(mvm
, IWL_MVM_SCAN_SCHED
, true);
1110 case IWL_MVM_SCAN_SCHED
:
1111 if (mvm
->scan_status
& IWL_MVM_SCAN_SCHED_MASK
)
1113 iwl_mvm_scan_stop(mvm
, IWL_MVM_SCAN_REGULAR
, true);
1114 case IWL_MVM_SCAN_NETDETECT
:
1115 /* No need to stop anything for net-detect since the
1116 * firmware is restarted anyway. This way, any sched
1117 * scans that were running will be restarted when we
1129 int iwl_mvm_reg_scan_start(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
1130 struct cfg80211_scan_request
*req
,
1131 struct ieee80211_scan_ies
*ies
)
1133 struct iwl_host_cmd hcmd
= {
1134 .len
= { iwl_mvm_scan_size(mvm
), },
1135 .data
= { mvm
->scan_cmd
, },
1136 .dataflags
= { IWL_HCMD_DFL_NOCOPY
, },
1138 struct iwl_mvm_scan_params params
= {};
1141 lockdep_assert_held(&mvm
->mutex
);
1143 if (iwl_mvm_is_lar_supported(mvm
) && !mvm
->lar_regdom_set
) {
1144 IWL_ERR(mvm
, "scan while LAR regdomain is not set\n");
1148 ret
= iwl_mvm_check_running_scans(mvm
, IWL_MVM_SCAN_REGULAR
);
1152 iwl_mvm_ref(mvm
, IWL_MVM_REF_SCAN
);
1154 /* we should have failed registration if scan_cmd was NULL */
1155 if (WARN_ON(!mvm
->scan_cmd
))
1158 if (!iwl_mvm_scan_fits(mvm
, req
->n_ssids
, ies
, req
->n_channels
))
1161 params
.n_ssids
= req
->n_ssids
;
1162 params
.flags
= req
->flags
;
1163 params
.n_channels
= req
->n_channels
;
1165 params
.interval
= 0;
1166 params
.ssids
= req
->ssids
;
1167 params
.channels
= req
->channels
;
1168 params
.mac_addr
= req
->mac_addr
;
1169 params
.mac_addr_mask
= req
->mac_addr_mask
;
1170 params
.no_cck
= req
->no_cck
;
1171 params
.pass_all
= true;
1172 params
.n_match_sets
= 0;
1173 params
.match_sets
= NULL
;
1175 params
.schedule
[0].iterations
= 1;
1176 params
.schedule
[0].full_scan_mul
= 0;
1177 params
.schedule
[1].iterations
= 0;
1178 params
.schedule
[1].full_scan_mul
= 0;
1180 iwl_mvm_scan_calc_dwell(mvm
, vif
, ¶ms
);
1182 iwl_mvm_build_scan_probe(mvm
, vif
, ies
, ¶ms
);
1184 if (fw_has_capa(&mvm
->fw
->ucode_capa
, IWL_UCODE_TLV_CAPA_UMAC_SCAN
)) {
1185 hcmd
.id
= iwl_cmd_id(SCAN_REQ_UMAC
, IWL_ALWAYS_LONG_GROUP
, 0);
1186 ret
= iwl_mvm_scan_umac(mvm
, vif
, ¶ms
,
1187 IWL_MVM_SCAN_REGULAR
);
1189 hcmd
.id
= SCAN_OFFLOAD_REQUEST_CMD
;
1190 ret
= iwl_mvm_scan_lmac(mvm
, vif
, ¶ms
);
1196 ret
= iwl_mvm_send_cmd(mvm
, &hcmd
);
1198 IWL_DEBUG_SCAN(mvm
, "Scan request was sent successfully\n");
1199 mvm
->scan_status
|= IWL_MVM_SCAN_REGULAR
;
1201 /* If the scan failed, it usually means that the FW was unable
1202 * to allocate the time events. Warn on it, but maybe we
1203 * should try to send the command again with different params.
1205 IWL_ERR(mvm
, "Scan failed! ret %d\n", ret
);
1209 iwl_mvm_unref(mvm
, IWL_MVM_REF_SCAN
);
1214 int iwl_mvm_sched_scan_start(struct iwl_mvm
*mvm
,
1215 struct ieee80211_vif
*vif
,
1216 struct cfg80211_sched_scan_request
*req
,
1217 struct ieee80211_scan_ies
*ies
,
1220 struct iwl_host_cmd hcmd
= {
1221 .len
= { iwl_mvm_scan_size(mvm
), },
1222 .data
= { mvm
->scan_cmd
, },
1223 .dataflags
= { IWL_HCMD_DFL_NOCOPY
, },
1225 struct iwl_mvm_scan_params params
= {};
1228 lockdep_assert_held(&mvm
->mutex
);
1230 if (iwl_mvm_is_lar_supported(mvm
) && !mvm
->lar_regdom_set
) {
1231 IWL_ERR(mvm
, "sched-scan while LAR regdomain is not set\n");
1235 ret
= iwl_mvm_check_running_scans(mvm
, type
);
1239 /* we should have failed registration if scan_cmd was NULL */
1240 if (WARN_ON(!mvm
->scan_cmd
))
1243 if (!iwl_mvm_scan_fits(mvm
, req
->n_ssids
, ies
, req
->n_channels
))
1246 params
.n_ssids
= req
->n_ssids
;
1247 params
.flags
= req
->flags
;
1248 params
.n_channels
= req
->n_channels
;
1249 params
.ssids
= req
->ssids
;
1250 params
.channels
= req
->channels
;
1251 params
.mac_addr
= req
->mac_addr
;
1252 params
.mac_addr_mask
= req
->mac_addr_mask
;
1253 params
.no_cck
= false;
1254 params
.pass_all
= iwl_mvm_scan_pass_all(mvm
, req
);
1255 params
.n_match_sets
= req
->n_match_sets
;
1256 params
.match_sets
= req
->match_sets
;
1258 params
.schedule
[0].iterations
= IWL_FAST_SCHED_SCAN_ITERATIONS
;
1259 params
.schedule
[0].full_scan_mul
= 1;
1260 params
.schedule
[1].iterations
= 0xff;
1261 params
.schedule
[1].full_scan_mul
= IWL_FULL_SCAN_MULTIPLIER
;
1263 if (req
->interval
> U16_MAX
) {
1265 "interval value is > 16-bits, set to max possible\n");
1266 params
.interval
= U16_MAX
;
1268 params
.interval
= req
->interval
/ MSEC_PER_SEC
;
1271 /* In theory, LMAC scans can handle a 32-bit delay, but since
1272 * waiting for over 18 hours to start the scan is a bit silly
1273 * and to keep it aligned with UMAC scans (which only support
1274 * 16-bit delays), trim it down to 16-bits.
1276 if (req
->delay
> U16_MAX
) {
1278 "delay value is > 16-bits, set to max possible\n");
1279 params
.delay
= U16_MAX
;
1281 params
.delay
= req
->delay
;
1284 iwl_mvm_scan_calc_dwell(mvm
, vif
, ¶ms
);
1286 ret
= iwl_mvm_config_sched_scan_profiles(mvm
, req
);
1290 iwl_mvm_build_scan_probe(mvm
, vif
, ies
, ¶ms
);
1292 if (fw_has_capa(&mvm
->fw
->ucode_capa
, IWL_UCODE_TLV_CAPA_UMAC_SCAN
)) {
1293 hcmd
.id
= iwl_cmd_id(SCAN_REQ_UMAC
, IWL_ALWAYS_LONG_GROUP
, 0);
1294 ret
= iwl_mvm_scan_umac(mvm
, vif
, ¶ms
, IWL_MVM_SCAN_SCHED
);
1296 hcmd
.id
= SCAN_OFFLOAD_REQUEST_CMD
;
1297 ret
= iwl_mvm_scan_lmac(mvm
, vif
, ¶ms
);
1303 ret
= iwl_mvm_send_cmd(mvm
, &hcmd
);
1306 "Sched scan request was sent successfully\n");
1307 mvm
->scan_status
|= type
;
1309 /* If the scan failed, it usually means that the FW was unable
1310 * to allocate the time events. Warn on it, but maybe we
1311 * should try to send the command again with different params.
1313 IWL_ERR(mvm
, "Sched scan failed! ret %d\n", ret
);
1319 void iwl_mvm_rx_umac_scan_complete_notif(struct iwl_mvm
*mvm
,
1320 struct iwl_rx_cmd_buffer
*rxb
)
1322 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
1323 struct iwl_umac_scan_complete
*notif
= (void *)pkt
->data
;
1324 u32 uid
= __le32_to_cpu(notif
->uid
);
1325 bool aborted
= (notif
->status
== IWL_SCAN_OFFLOAD_ABORTED
);
1327 if (WARN_ON(!(mvm
->scan_uid_status
[uid
] & mvm
->scan_status
)))
1330 /* if the scan is already stopping, we don't need to notify mac80211 */
1331 if (mvm
->scan_uid_status
[uid
] == IWL_MVM_SCAN_REGULAR
) {
1332 ieee80211_scan_completed(mvm
->hw
, aborted
);
1333 iwl_mvm_unref(mvm
, IWL_MVM_REF_SCAN
);
1334 } else if (mvm
->scan_uid_status
[uid
] == IWL_MVM_SCAN_SCHED
) {
1335 ieee80211_sched_scan_stopped(mvm
->hw
);
1338 mvm
->scan_status
&= ~mvm
->scan_uid_status
[uid
];
1341 "Scan completed, uid %u type %u, status %s, EBS status %s\n",
1342 uid
, mvm
->scan_uid_status
[uid
],
1343 notif
->status
== IWL_SCAN_OFFLOAD_COMPLETED
?
1344 "completed" : "aborted",
1345 iwl_mvm_ebs_status_str(notif
->ebs_status
));
1347 if (notif
->ebs_status
!= IWL_SCAN_EBS_SUCCESS
&&
1348 notif
->ebs_status
!= IWL_SCAN_EBS_INACTIVE
)
1349 mvm
->last_ebs_successful
= false;
1351 mvm
->scan_uid_status
[uid
] = 0;
1354 void iwl_mvm_rx_umac_scan_iter_complete_notif(struct iwl_mvm
*mvm
,
1355 struct iwl_rx_cmd_buffer
*rxb
)
1357 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
1358 struct iwl_umac_scan_iter_complete_notif
*notif
= (void *)pkt
->data
;
1362 "UMAC Scan iteration complete: status=0x%x scanned_channels=%d channels list: %s\n",
1363 notif
->status
, notif
->scanned_channels
,
1364 iwl_mvm_dump_channel_list(notif
->results
,
1365 notif
->scanned_channels
, buf
,
1369 static int iwl_mvm_umac_scan_abort(struct iwl_mvm
*mvm
, int type
)
1371 struct iwl_umac_scan_abort cmd
= {};
1374 lockdep_assert_held(&mvm
->mutex
);
1376 /* We should always get a valid index here, because we already
1377 * checked that this type of scan was running in the generic
1380 uid
= iwl_mvm_scan_uid_by_status(mvm
, type
);
1381 if (WARN_ON_ONCE(uid
< 0))
1384 cmd
.uid
= cpu_to_le32(uid
);
1386 IWL_DEBUG_SCAN(mvm
, "Sending scan abort, uid %u\n", uid
);
1388 ret
= iwl_mvm_send_cmd_pdu(mvm
,
1389 iwl_cmd_id(SCAN_ABORT_UMAC
,
1390 IWL_ALWAYS_LONG_GROUP
, 0),
1391 0, sizeof(cmd
), &cmd
);
1393 mvm
->scan_uid_status
[uid
] = type
<< IWL_MVM_SCAN_STOPPING_SHIFT
;
1398 static int iwl_mvm_scan_stop_wait(struct iwl_mvm
*mvm
, int type
)
1400 struct iwl_notification_wait wait_scan_done
;
1401 static const u16 scan_done_notif
[] = { SCAN_COMPLETE_UMAC
,
1402 SCAN_OFFLOAD_COMPLETE
, };
1405 lockdep_assert_held(&mvm
->mutex
);
1407 iwl_init_notification_wait(&mvm
->notif_wait
, &wait_scan_done
,
1409 ARRAY_SIZE(scan_done_notif
),
1412 IWL_DEBUG_SCAN(mvm
, "Preparing to stop scan, type %x\n", type
);
1414 if (fw_has_capa(&mvm
->fw
->ucode_capa
, IWL_UCODE_TLV_CAPA_UMAC_SCAN
))
1415 ret
= iwl_mvm_umac_scan_abort(mvm
, type
);
1417 ret
= iwl_mvm_lmac_scan_abort(mvm
);
1420 IWL_DEBUG_SCAN(mvm
, "couldn't stop scan type %d\n", type
);
1421 iwl_remove_notification(&mvm
->notif_wait
, &wait_scan_done
);
1425 ret
= iwl_wait_notification(&mvm
->notif_wait
, &wait_scan_done
, 1 * HZ
);
1430 int iwl_mvm_scan_size(struct iwl_mvm
*mvm
)
1432 if (fw_has_capa(&mvm
->fw
->ucode_capa
, IWL_UCODE_TLV_CAPA_UMAC_SCAN
))
1433 return sizeof(struct iwl_scan_req_umac
) +
1434 sizeof(struct iwl_scan_channel_cfg_umac
) *
1435 mvm
->fw
->ucode_capa
.n_scan_channels
+
1436 sizeof(struct iwl_scan_req_umac_tail
);
1438 return sizeof(struct iwl_scan_req_lmac
) +
1439 sizeof(struct iwl_scan_channel_cfg_lmac
) *
1440 mvm
->fw
->ucode_capa
.n_scan_channels
+
1441 sizeof(struct iwl_scan_probe_req
);
1445 * This function is used in nic restart flow, to inform mac80211 about scans
1446 * that was aborted by restart flow or by an assert.
1448 void iwl_mvm_report_scan_aborted(struct iwl_mvm
*mvm
)
1450 if (fw_has_capa(&mvm
->fw
->ucode_capa
, IWL_UCODE_TLV_CAPA_UMAC_SCAN
)) {
1453 uid
= iwl_mvm_scan_uid_by_status(mvm
, IWL_MVM_SCAN_REGULAR
);
1455 ieee80211_scan_completed(mvm
->hw
, true);
1456 mvm
->scan_uid_status
[uid
] = 0;
1458 uid
= iwl_mvm_scan_uid_by_status(mvm
, IWL_MVM_SCAN_SCHED
);
1459 if (uid
>= 0 && !mvm
->restart_fw
) {
1460 ieee80211_sched_scan_stopped(mvm
->hw
);
1461 mvm
->scan_uid_status
[uid
] = 0;
1464 /* We shouldn't have any UIDs still set. Loop over all the
1465 * UIDs to make sure there's nothing left there and warn if
1468 for (i
= 0; i
< mvm
->max_scans
; i
++) {
1469 if (WARN_ONCE(mvm
->scan_uid_status
[i
],
1470 "UMAC scan UID %d status was not cleaned\n",
1472 mvm
->scan_uid_status
[i
] = 0;
1475 if (mvm
->scan_status
& IWL_MVM_SCAN_REGULAR
)
1476 ieee80211_scan_completed(mvm
->hw
, true);
1478 /* Sched scan will be restarted by mac80211 in
1479 * restart_hw, so do not report if FW is about to be
1482 if ((mvm
->scan_status
& IWL_MVM_SCAN_SCHED
) && !mvm
->restart_fw
)
1483 ieee80211_sched_scan_stopped(mvm
->hw
);
1487 int iwl_mvm_scan_stop(struct iwl_mvm
*mvm
, int type
, bool notify
)
1491 if (!(mvm
->scan_status
& type
))
1494 if (iwl_mvm_is_radio_killed(mvm
)) {
1499 ret
= iwl_mvm_scan_stop_wait(mvm
, type
);
1501 mvm
->scan_status
|= type
<< IWL_MVM_SCAN_STOPPING_SHIFT
;
1503 /* Clear the scan status so the next scan requests will
1504 * succeed and mark the scan as stopping, so that the Rx
1505 * handler doesn't do anything, as the scan was stopped from
1508 mvm
->scan_status
&= ~type
;
1510 if (type
== IWL_MVM_SCAN_REGULAR
) {
1511 /* Since the rx handler won't do anything now, we have
1512 * to release the scan reference here.
1514 iwl_mvm_unref(mvm
, IWL_MVM_REF_SCAN
);
1516 ieee80211_scan_completed(mvm
->hw
, true);
1517 } else if (notify
) {
1518 ieee80211_sched_scan_stopped(mvm
->hw
);