blob: 4887418b6ad33c9ba9851fe61e460edb15a768b7 [file] [log] [blame]
Johannes Berg8ca151b2013-01-24 14:25:36 +01001/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +02008 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Luciano Coelho9af91f42015-02-10 10:42:26 +02009 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010010 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
23 * USA
24 *
25 * The full GNU General Public License is included in this distribution
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020026 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010027 *
28 * Contact Information:
29 * Intel Linux Wireless <ilw@linux.intel.com>
30 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 *
32 * BSD LICENSE
33 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020034 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Luciano Coelho9af91f42015-02-10 10:42:26 +020035 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010036 * All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 *
42 * * Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * * Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in
46 * the documentation and/or other materials provided with the
47 * distribution.
48 * * Neither the name Intel Corporation nor the names of its
49 * contributors may be used to endorse or promote products derived
50 * from this software without specific prior written permission.
51 *
52 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 *
64 *****************************************************************************/
65
66#include <linux/etherdevice.h>
67#include <net/mac80211.h>
68
69#include "mvm.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010070#include "fw-api-scan.h"
71
Haim Dreyfussa1ed4022014-12-01 23:30:07 +020072#define IWL_DENSE_EBS_SCAN_RATIO 5
73#define IWL_SPARSE_EBS_SCAN_RATIO 1
Alexander Bondar8a110d92014-03-12 17:31:19 +020074
David Spinadel9437e992015-06-22 13:20:00 +030075enum iwl_mvm_traffic_load {
76 IWL_MVM_TRAFFIC_LOW,
77 IWL_MVM_TRAFFIC_MEDIUM,
78 IWL_MVM_TRAFFIC_HIGH,
79};
80
81struct iwl_mvm_scan_timing_params {
82 u32 dwell_active;
83 u32 dwell_passive;
84 u32 dwell_fragmented;
Alexander Bondar8a110d92014-03-12 17:31:19 +020085 u32 suspend_time;
David Spinadel9437e992015-06-22 13:20:00 +030086 u32 max_out_time;
87};
88
89static struct iwl_mvm_scan_timing_params scan_timing[] = {
90 [IWL_SCAN_TYPE_UNASSOC] = {
91 .dwell_active = 10,
92 .dwell_passive = 110,
93 .dwell_fragmented = 44,
94 .suspend_time = 0,
95 .max_out_time = 0,
96 },
97 [IWL_SCAN_TYPE_WILD] = {
98 .dwell_active = 10,
99 .dwell_passive = 110,
100 .dwell_fragmented = 44,
101 .suspend_time = 30,
102 .max_out_time = 120,
103 },
104 [IWL_SCAN_TYPE_MILD] = {
105 .dwell_active = 10,
106 .dwell_passive = 110,
107 .dwell_fragmented = 44,
108 .suspend_time = 120,
109 .max_out_time = 120,
110 },
111 [IWL_SCAN_TYPE_FRAGMENTED] = {
112 .dwell_active = 10,
113 .dwell_passive = 110,
114 .dwell_fragmented = 44,
115 .suspend_time = 95,
116 .max_out_time = 44,
117 },
118};
119
120struct iwl_mvm_scan_params {
121 enum iwl_mvm_scan_type type;
Luciano Coelhof7b788b2015-04-02 00:08:35 +0300122 u32 n_channels;
Luciano Coelho283c2492015-04-17 11:18:46 +0300123 u16 delay;
Luciano Coelhof7b788b2015-04-02 00:08:35 +0300124 int n_ssids;
125 struct cfg80211_ssid *ssids;
126 struct ieee80211_channel **channels;
Luciano Coelhof7b788b2015-04-02 00:08:35 +0300127 u32 flags;
128 u8 *mac_addr;
129 u8 *mac_addr_mask;
130 bool no_cck;
131 bool pass_all;
132 int n_match_sets;
Luciano Coelho45d1b122015-04-15 16:34:13 +0300133 struct iwl_scan_probe_req preq;
Luciano Coelhof7b788b2015-04-02 00:08:35 +0300134 struct cfg80211_match_set *match_sets;
Avraham Sterncd55cce2015-08-19 12:46:12 +0300135 int n_scan_plans;
136 struct cfg80211_sched_scan_plan *scan_plans;
Alexander Bondar8a110d92014-03-12 17:31:19 +0200137};
Johannes Berg8ca151b2013-01-24 14:25:36 +0100138
David Spinadeld2496222014-05-20 12:46:37 +0300139static u8 iwl_mvm_scan_rx_ant(struct iwl_mvm *mvm)
140{
141 if (mvm->scan_rx_ant != ANT_NONE)
142 return mvm->scan_rx_ant;
Moshe Harela0544272014-12-08 21:13:14 +0200143 return iwl_mvm_get_valid_rx_ant(mvm);
David Spinadeld2496222014-05-20 12:46:37 +0300144}
145
Johannes Berg8ca151b2013-01-24 14:25:36 +0100146static inline __le16 iwl_mvm_scan_rx_chain(struct iwl_mvm *mvm)
147{
148 u16 rx_chain;
Oren Givon91b05d12013-08-19 08:36:48 +0300149 u8 rx_ant;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100150
David Spinadeld2496222014-05-20 12:46:37 +0300151 rx_ant = iwl_mvm_scan_rx_ant(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100152 rx_chain = rx_ant << PHY_RX_CHAIN_VALID_POS;
153 rx_chain |= rx_ant << PHY_RX_CHAIN_FORCE_MIMO_SEL_POS;
154 rx_chain |= rx_ant << PHY_RX_CHAIN_FORCE_SEL_POS;
155 rx_chain |= 0x1 << PHY_RX_CHAIN_DRIVER_FORCE_POS;
156 return cpu_to_le16(rx_chain);
157}
158
David Spinadelfb98be52014-05-04 12:51:10 +0300159static __le32 iwl_mvm_scan_rxon_flags(enum ieee80211_band band)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100160{
David Spinadelfb98be52014-05-04 12:51:10 +0300161 if (band == IEEE80211_BAND_2GHZ)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100162 return cpu_to_le32(PHY_BAND_24);
163 else
164 return cpu_to_le32(PHY_BAND_5);
165}
166
167static inline __le32
168iwl_mvm_scan_rate_n_flags(struct iwl_mvm *mvm, enum ieee80211_band band,
169 bool no_cck)
170{
171 u32 tx_ant;
172
173 mvm->scan_last_antenna_idx =
Moshe Harela0544272014-12-08 21:13:14 +0200174 iwl_mvm_next_antenna(mvm, iwl_mvm_get_valid_tx_ant(mvm),
Johannes Berg8ca151b2013-01-24 14:25:36 +0100175 mvm->scan_last_antenna_idx);
176 tx_ant = BIT(mvm->scan_last_antenna_idx) << RATE_MCS_ANT_POS;
177
178 if (band == IEEE80211_BAND_2GHZ && !no_cck)
179 return cpu_to_le32(IWL_RATE_1M_PLCP | RATE_MCS_CCK_MSK |
180 tx_ant);
181 else
182 return cpu_to_le32(IWL_RATE_6M_PLCP | tx_ant);
183}
184
Alexander Bondar8a110d92014-03-12 17:31:19 +0200185static void iwl_mvm_scan_condition_iterator(void *data, u8 *mac,
186 struct ieee80211_vif *vif)
Haim Dreyfuss61f63252013-11-03 23:02:59 +0200187{
Alexander Bondar8a110d92014-03-12 17:31:19 +0200188 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Haim Dreyfussc3f8d0a2014-12-02 11:03:16 +0200189 int *global_cnt = data;
Haim Dreyfuss61f63252013-11-03 23:02:59 +0200190
David Spinadel1e2ebe02014-10-26 15:53:27 +0200191 if (vif->type != NL80211_IFTYPE_P2P_DEVICE && mvmvif->phy_ctxt &&
192 mvmvif->phy_ctxt->id < MAX_PHYS)
Haim Dreyfussc3f8d0a2014-12-02 11:03:16 +0200193 *global_cnt += 1;
Alexander Bondar8a110d92014-03-12 17:31:19 +0200194}
195
David Spinadel9437e992015-06-22 13:20:00 +0300196static enum iwl_mvm_traffic_load iwl_mvm_get_traffic_load(struct iwl_mvm *mvm)
197{
198 return IWL_MVM_TRAFFIC_LOW;
199}
200
201static enum
Avraham Stern355346b2015-11-26 11:22:33 +0200202iwl_mvm_scan_type iwl_mvm_get_scan_type(struct iwl_mvm *mvm, bool p2p_device)
Alexander Bondar8a110d92014-03-12 17:31:19 +0200203{
Haim Dreyfussc3f8d0a2014-12-02 11:03:16 +0200204 int global_cnt = 0;
David Spinadel9437e992015-06-22 13:20:00 +0300205 enum iwl_mvm_traffic_load load;
206 bool low_latency;
Alexander Bondar8a110d92014-03-12 17:31:19 +0200207
208 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
209 IEEE80211_IFACE_ITER_NORMAL,
210 iwl_mvm_scan_condition_iterator,
Haim Dreyfussc3f8d0a2014-12-02 11:03:16 +0200211 &global_cnt);
Haim Dreyfussc3f8d0a2014-12-02 11:03:16 +0200212 if (!global_cnt)
David Spinadel9437e992015-06-22 13:20:00 +0300213 return IWL_SCAN_TYPE_UNASSOC;
Alexander Bondaref67f18d2014-03-30 10:47:08 +0300214
David Spinadel9437e992015-06-22 13:20:00 +0300215 load = iwl_mvm_get_traffic_load(mvm);
216 low_latency = iwl_mvm_low_latency(mvm);
Alexander Bondaref67f18d2014-03-30 10:47:08 +0300217
Avraham Stern355346b2015-11-26 11:22:33 +0200218 if ((load == IWL_MVM_TRAFFIC_HIGH || low_latency) && !p2p_device &&
David Spinadel9437e992015-06-22 13:20:00 +0300219 fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_FRAGMENTED_SCAN))
220 return IWL_SCAN_TYPE_FRAGMENTED;
Johannes Berg859d9142015-06-01 17:11:11 +0200221
David Spinadel9437e992015-06-22 13:20:00 +0300222 if (load >= IWL_MVM_TRAFFIC_MEDIUM || low_latency)
223 return IWL_SCAN_TYPE_MILD;
David Spinadel2ce89cd2014-07-22 13:11:18 +0300224
David Spinadel9437e992015-06-22 13:20:00 +0300225 return IWL_SCAN_TYPE_WILD;
Haim Dreyfuss61f63252013-11-03 23:02:59 +0200226}
227
Andrei Otcheretianski73897bd2014-07-09 18:59:14 +0300228static inline bool iwl_mvm_rrm_scan_needed(struct iwl_mvm *mvm)
229{
230 /* require rrm scan whenever the fw supports it */
Johannes Berg859d9142015-06-01 17:11:11 +0200231 return fw_has_capa(&mvm->fw->ucode_capa,
232 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT);
Andrei Otcheretianski73897bd2014-07-09 18:59:14 +0300233}
234
Luciano Coelho999d2562015-03-27 10:28:26 +0300235static int iwl_mvm_max_scan_ie_fw_cmd_room(struct iwl_mvm *mvm)
Andrei Otcheretianski48849a42014-09-09 10:58:49 +0300236{
237 int max_probe_len;
238
Luciano Coelho1f940382015-02-10 13:03:38 +0200239 max_probe_len = SCAN_OFFLOAD_PROBE_REQ_SIZE;
Andrei Otcheretianski48849a42014-09-09 10:58:49 +0300240
241 /* we create the 802.11 header and SSID element */
242 max_probe_len -= 24 + 2;
243
Andrei Otcheretianski66dc5272014-09-02 17:55:40 +0300244 /* DS parameter set element is added on 2.4GHZ band if required */
245 if (iwl_mvm_rrm_scan_needed(mvm))
246 max_probe_len -= 3;
247
Andrei Otcheretianski48849a42014-09-09 10:58:49 +0300248 return max_probe_len;
249}
250
Luciano Coelho999d2562015-03-27 10:28:26 +0300251int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm)
Andrei Otcheretianski48849a42014-09-09 10:58:49 +0300252{
Luciano Coelho999d2562015-03-27 10:28:26 +0300253 int max_ie_len = iwl_mvm_max_scan_ie_fw_cmd_room(mvm);
Andrei Otcheretianski48849a42014-09-09 10:58:49 +0300254
Andrei Otcheretianski48849a42014-09-09 10:58:49 +0300255 /* TODO: [BUG] This function should return the maximum allowed size of
256 * scan IEs, however the LMAC scan api contains both 2GHZ and 5GHZ IEs
257 * in the same command. So the correct implementation of this function
258 * is just iwl_mvm_max_scan_ie_fw_cmd_room() / 2. Currently the scan
259 * command has only 512 bytes and it would leave us with about 240
260 * bytes for scan IEs, which is clearly not enough. So meanwhile
261 * we will report an incorrect value. This may result in a failure to
262 * issue a scan in unified_scan_lmac and unified_sched_scan_lmac
263 * functions with -ENOBUFS, if a large enough probe will be provided.
264 */
265 return max_ie_len;
266}
267
Avraham Stern1fa1bcc2015-03-31 16:22:33 +0300268static u8 *iwl_mvm_dump_channel_list(struct iwl_scan_results_notif *res,
269 int num_res, u8 *buf, size_t buf_size)
270{
271 int i;
272 u8 *pos = buf, *end = buf + buf_size;
273
274 for (i = 0; pos < end && i < num_res; i++)
275 pos += snprintf(pos, end - pos, " %u", res[i].channel);
276
277 /* terminate the string in case the buffer was too short */
278 *(buf + buf_size - 1) = '\0';
279
280 return buf;
281}
282
Johannes Berg04168412015-06-23 21:22:09 +0200283void iwl_mvm_rx_lmac_scan_iter_complete_notif(struct iwl_mvm *mvm,
284 struct iwl_rx_cmd_buffer *rxb)
Alexander Bondare5d74642014-12-09 19:15:49 +0200285{
286 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Avraham Stern1083fd72015-03-31 16:14:41 +0300287 struct iwl_lmac_scan_complete_notif *notif = (void *)pkt->data;
Avraham Stern1fa1bcc2015-03-31 16:22:33 +0300288 u8 buf[256];
Alexander Bondare5d74642014-12-09 19:15:49 +0200289
290 IWL_DEBUG_SCAN(mvm,
Avraham Stern1fa1bcc2015-03-31 16:22:33 +0300291 "Scan offload iteration complete: status=0x%x scanned channels=%d channels list: %s\n",
292 notif->status, notif->scanned_channels,
293 iwl_mvm_dump_channel_list(notif->results,
294 notif->scanned_channels, buf,
295 sizeof(buf)));
Alexander Bondare5d74642014-12-09 19:15:49 +0200296}
297
Johannes Berg04168412015-06-23 21:22:09 +0200298void iwl_mvm_rx_scan_match_found(struct iwl_mvm *mvm,
299 struct iwl_rx_cmd_buffer *rxb)
David Spinadel35a000b2013-08-28 09:29:43 +0300300{
David Spinadeld2496222014-05-20 12:46:37 +0300301 IWL_DEBUG_SCAN(mvm, "Scheduled scan results\n");
302 ieee80211_sched_scan_results(mvm->hw);
David Spinadel35a000b2013-08-28 09:29:43 +0300303}
304
David Spinadelf0bf8592015-05-20 11:56:59 +0300305static const char *iwl_mvm_ebs_status_str(enum iwl_scan_ebs_status status)
306{
307 switch (status) {
308 case IWL_SCAN_EBS_SUCCESS:
309 return "successful";
310 case IWL_SCAN_EBS_INACTIVE:
311 return "inactive";
312 case IWL_SCAN_EBS_FAILED:
313 case IWL_SCAN_EBS_CHAN_NOT_FOUND:
314 default:
315 return "failed";
316 }
317}
318
Johannes Berg04168412015-06-23 21:22:09 +0200319void iwl_mvm_rx_lmac_scan_complete_notif(struct iwl_mvm *mvm,
320 struct iwl_rx_cmd_buffer *rxb)
David Spinadel35a000b2013-08-28 09:29:43 +0300321{
322 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Luciano Coelho9af91f42015-02-10 10:42:26 +0200323 struct iwl_periodic_scan_complete *scan_notif = (void *)pkt->data;
324 bool aborted = (scan_notif->status == IWL_SCAN_OFFLOAD_ABORTED);
David Spinadelfb98be52014-05-04 12:51:10 +0300325
Luca Coelho72a335682015-11-06 10:57:11 +0200326 /* If this happens, the firmware has mistakenly sent an LMAC
327 * notification during UMAC scans -- warn and ignore it.
328 */
329 if (WARN_ON_ONCE(fw_has_capa(&mvm->fw->ucode_capa,
330 IWL_UCODE_TLV_CAPA_UMAC_SCAN)))
331 return;
332
Johannes Berga6623e82014-01-27 15:40:53 +0100333 /* scan status must be locked for proper checking */
334 lockdep_assert_held(&mvm->mutex);
335
Luciano Coelho9af91f42015-02-10 10:42:26 +0200336 /* We first check if we were stopping a scan, in which case we
337 * just clear the stopping flag. Then we check if it was a
338 * firmware initiated stop, in which case we need to inform
339 * mac80211.
340 * Note that we can have a stopping and a running scan
341 * simultaneously, but we can't have two different types of
342 * scans stopping or running at the same time (since LMAC
343 * doesn't support it).
344 */
Haim Dreyfusse820c2d2014-04-06 11:19:09 +0300345
Luciano Coelho9af91f42015-02-10 10:42:26 +0200346 if (mvm->scan_status & IWL_MVM_SCAN_STOPPING_SCHED) {
347 WARN_ON_ONCE(mvm->scan_status & IWL_MVM_SCAN_STOPPING_REGULAR);
David Spinadel35a000b2013-08-28 09:29:43 +0300348
Ayala Bekera7b3bc92015-08-20 04:00:38 +0300349 IWL_DEBUG_SCAN(mvm, "Scheduled scan %s, EBS status %s\n",
Luciano Coelho9af91f42015-02-10 10:42:26 +0200350 aborted ? "aborted" : "completed",
Ayala Bekera7b3bc92015-08-20 04:00:38 +0300351 iwl_mvm_ebs_status_str(scan_notif->ebs_status));
352 IWL_DEBUG_SCAN(mvm,
353 "Last line %d, Last iteration %d, Time after last iteration %d\n",
Ayala Beker1a84e772015-07-22 13:54:31 +0300354 scan_notif->last_schedule_line,
355 scan_notif->last_schedule_iteration,
356 __le32_to_cpu(scan_notif->time_after_last_iter));
Luciano Coelho9af91f42015-02-10 10:42:26 +0200357
358 mvm->scan_status &= ~IWL_MVM_SCAN_STOPPING_SCHED;
359 } else if (mvm->scan_status & IWL_MVM_SCAN_STOPPING_REGULAR) {
360 IWL_DEBUG_SCAN(mvm, "Regular scan %s, EBS status %s\n",
361 aborted ? "aborted" : "completed",
David Spinadelf0bf8592015-05-20 11:56:59 +0300362 iwl_mvm_ebs_status_str(scan_notif->ebs_status));
Luciano Coelho9af91f42015-02-10 10:42:26 +0200363
364 mvm->scan_status &= ~IWL_MVM_SCAN_STOPPING_REGULAR;
365 } else if (mvm->scan_status & IWL_MVM_SCAN_SCHED) {
366 WARN_ON_ONCE(mvm->scan_status & IWL_MVM_SCAN_REGULAR);
367
Ayala Bekera7b3bc92015-08-20 04:00:38 +0300368 IWL_DEBUG_SCAN(mvm, "Scheduled scan %s, EBS status %s\n",
Luciano Coelho9af91f42015-02-10 10:42:26 +0200369 aborted ? "aborted" : "completed",
Ayala Bekera7b3bc92015-08-20 04:00:38 +0300370 iwl_mvm_ebs_status_str(scan_notif->ebs_status));
371 IWL_DEBUG_SCAN(mvm,
372 "Last line %d, Last iteration %d, Time after last iteration %d (FW)\n",
Ayala Beker1a84e772015-07-22 13:54:31 +0300373 scan_notif->last_schedule_line,
374 scan_notif->last_schedule_iteration,
375 __le32_to_cpu(scan_notif->time_after_last_iter));
Luciano Coelho9af91f42015-02-10 10:42:26 +0200376
377 mvm->scan_status &= ~IWL_MVM_SCAN_SCHED;
Arik Nemtsov33ea27f2014-02-10 15:34:29 +0200378 ieee80211_sched_scan_stopped(mvm->hw);
Luciano Coelho9af91f42015-02-10 10:42:26 +0200379 } else if (mvm->scan_status & IWL_MVM_SCAN_REGULAR) {
380 IWL_DEBUG_SCAN(mvm, "Regular scan %s, EBS status %s (FW)\n",
381 aborted ? "aborted" : "completed",
David Spinadelf0bf8592015-05-20 11:56:59 +0300382 iwl_mvm_ebs_status_str(scan_notif->ebs_status));
Luciano Coelho9af91f42015-02-10 10:42:26 +0200383
384 mvm->scan_status &= ~IWL_MVM_SCAN_REGULAR;
David Spinadelfb98be52014-05-04 12:51:10 +0300385 ieee80211_scan_completed(mvm->hw,
Luciano Coelho1f940382015-02-10 13:03:38 +0200386 scan_notif->status == IWL_SCAN_OFFLOAD_ABORTED);
Eliad Peller4ff78182014-06-22 14:44:44 +0300387 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +0200388 }
David Spinadel35a000b2013-08-28 09:29:43 +0300389
David Spinadelf0bf8592015-05-20 11:56:59 +0300390 mvm->last_ebs_successful =
391 scan_notif->ebs_status == IWL_SCAN_EBS_SUCCESS ||
392 scan_notif->ebs_status == IWL_SCAN_EBS_INACTIVE;
David Spinadel35a000b2013-08-28 09:29:43 +0300393}
394
David Spinadel35a000b2013-08-28 09:29:43 +0300395static int iwl_ssid_exist(u8 *ssid, u8 ssid_len, struct iwl_ssid_ie *ssid_list)
396{
397 int i;
398
399 for (i = 0; i < PROBE_OPTION_MAX; i++) {
400 if (!ssid_list[i].len)
401 break;
402 if (ssid_list[i].len == ssid_len &&
403 !memcmp(ssid_list->ssid, ssid, ssid_len))
404 return i;
405 }
406 return -1;
407}
408
Luciano Coelhoe2ec4f62015-04-02 17:49:04 +0300409/* We insert the SSIDs in an inverted order, because the FW will
410 * invert it back.
411 */
412static void iwl_scan_build_ssids(struct iwl_mvm_scan_params *params,
413 struct iwl_ssid_ie *ssids,
414 u32 *ssid_bitmap)
David Spinadel35a000b2013-08-28 09:29:43 +0300415{
416 int i, j;
417 int index;
418
419 /*
420 * copy SSIDs from match list.
421 * iwl_config_sched_scan_profiles() uses the order of these ssids to
422 * config match list.
423 */
Luciano Coelho1c1b5b22015-04-02 16:31:42 +0300424 for (i = 0, j = params->n_match_sets - 1;
425 j >= 0 && i < PROBE_OPTION_MAX;
426 i++, j--) {
Johannes Bergea73cbc2014-01-24 10:53:53 +0100427 /* skip empty SSID matchsets */
Luciano Coelho1c1b5b22015-04-02 16:31:42 +0300428 if (!params->match_sets[j].ssid.ssid_len)
Johannes Bergea73cbc2014-01-24 10:53:53 +0100429 continue;
Luciano Coelhoe2ec4f62015-04-02 17:49:04 +0300430 ssids[i].id = WLAN_EID_SSID;
431 ssids[i].len = params->match_sets[j].ssid.ssid_len;
432 memcpy(ssids[i].ssid, params->match_sets[j].ssid.ssid,
433 ssids[i].len);
David Spinadel35a000b2013-08-28 09:29:43 +0300434 }
435
436 /* add SSIDs from scan SSID list */
437 *ssid_bitmap = 0;
Luciano Coelho1c1b5b22015-04-02 16:31:42 +0300438 for (j = params->n_ssids - 1;
439 j >= 0 && i < PROBE_OPTION_MAX;
440 i++, j--) {
Luciano Coelhof7b788b2015-04-02 00:08:35 +0300441 index = iwl_ssid_exist(params->ssids[j].ssid,
442 params->ssids[j].ssid_len,
Luciano Coelhoe2ec4f62015-04-02 17:49:04 +0300443 ssids);
David Spinadel35a000b2013-08-28 09:29:43 +0300444 if (index < 0) {
Luciano Coelhoe2ec4f62015-04-02 17:49:04 +0300445 ssids[i].id = WLAN_EID_SSID;
446 ssids[i].len = params->ssids[j].ssid_len;
447 memcpy(ssids[i].ssid, params->ssids[j].ssid,
448 ssids[i].len);
449 *ssid_bitmap |= BIT(i);
David Spinadel35a000b2013-08-28 09:29:43 +0300450 } else {
Luciano Coelhoe2ec4f62015-04-02 17:49:04 +0300451 *ssid_bitmap |= BIT(index);
David Spinadel35a000b2013-08-28 09:29:43 +0300452 }
453 }
454}
455
Luciano Coelho416c9b52015-05-05 11:32:29 +0300456static int
457iwl_mvm_config_sched_scan_profiles(struct iwl_mvm *mvm,
458 struct cfg80211_sched_scan_request *req)
David Spinadel35a000b2013-08-28 09:29:43 +0300459{
460 struct iwl_scan_offload_profile *profile;
461 struct iwl_scan_offload_profile_cfg *profile_cfg;
462 struct iwl_scan_offload_blacklist *blacklist;
463 struct iwl_host_cmd cmd = {
464 .id = SCAN_OFFLOAD_UPDATE_PROFILES_CMD,
David Spinadel35a000b2013-08-28 09:29:43 +0300465 .len[1] = sizeof(*profile_cfg),
466 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
467 .dataflags[1] = IWL_HCMD_DFL_NOCOPY,
468 };
469 int blacklist_len;
470 int i;
471 int ret;
472
473 if (WARN_ON(req->n_match_sets > IWL_SCAN_MAX_PROFILES))
Johannes Berg46eebec2015-09-11 12:09:22 +0200474 return -EIO;
David Spinadel35a000b2013-08-28 09:29:43 +0300475
476 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_SHORT_BL)
477 blacklist_len = IWL_SCAN_SHORT_BLACKLIST_LEN;
478 else
479 blacklist_len = IWL_SCAN_MAX_BLACKLIST_LEN;
480
481 blacklist = kzalloc(sizeof(*blacklist) * blacklist_len, GFP_KERNEL);
482 if (!blacklist)
483 return -ENOMEM;
484
485 profile_cfg = kzalloc(sizeof(*profile_cfg), GFP_KERNEL);
486 if (!profile_cfg) {
487 ret = -ENOMEM;
488 goto free_blacklist;
489 }
490
491 cmd.data[0] = blacklist;
492 cmd.len[0] = sizeof(*blacklist) * blacklist_len;
493 cmd.data[1] = profile_cfg;
494
495 /* No blacklist configuration */
496
497 profile_cfg->num_profiles = req->n_match_sets;
498 profile_cfg->active_clients = SCAN_CLIENT_SCHED_SCAN;
499 profile_cfg->pass_match = SCAN_CLIENT_SCHED_SCAN;
500 profile_cfg->match_notify = SCAN_CLIENT_SCHED_SCAN;
David Spinadel6e0bbe52013-12-30 09:59:45 +0200501 if (!req->n_match_sets || !req->match_sets[0].ssid.ssid_len)
502 profile_cfg->any_beacon_notify = SCAN_CLIENT_SCHED_SCAN;
David Spinadel35a000b2013-08-28 09:29:43 +0300503
504 for (i = 0; i < req->n_match_sets; i++) {
505 profile = &profile_cfg->profiles[i];
506 profile->ssid_index = i;
507 /* Support any cipher and auth algorithm */
508 profile->unicast_cipher = 0xff;
509 profile->auth_alg = 0xff;
510 profile->network_type = IWL_NETWORK_TYPE_ANY;
511 profile->band_selection = IWL_SCAN_OFFLOAD_SELECT_ANY;
512 profile->client_bitmap = SCAN_CLIENT_SCHED_SCAN;
513 }
514
515 IWL_DEBUG_SCAN(mvm, "Sending scheduled scan profile config\n");
516
517 ret = iwl_mvm_send_cmd(mvm, &cmd);
518 kfree(profile_cfg);
519free_blacklist:
520 kfree(blacklist);
521
522 return ret;
523}
524
David Spinadeld2496222014-05-20 12:46:37 +0300525static bool iwl_mvm_scan_pass_all(struct iwl_mvm *mvm,
526 struct cfg80211_sched_scan_request *req)
527{
528 if (req->n_match_sets && req->match_sets[0].ssid.ssid_len) {
529 IWL_DEBUG_SCAN(mvm,
530 "Sending scheduled scan with filtering, n_match_sets %d\n",
531 req->n_match_sets);
532 return false;
533 }
534
535 IWL_DEBUG_SCAN(mvm, "Sending Scheduled scan without filtering\n");
536 return true;
537}
538
Luciano Coelhof2461792015-05-07 15:23:19 +0300539static int iwl_mvm_lmac_scan_abort(struct iwl_mvm *mvm)
David Spinadel35a000b2013-08-28 09:29:43 +0300540{
541 int ret;
542 struct iwl_host_cmd cmd = {
543 .id = SCAN_OFFLOAD_ABORT_CMD,
David Spinadel35a000b2013-08-28 09:29:43 +0300544 };
545 u32 status;
546
David Spinadel35a000b2013-08-28 09:29:43 +0300547 ret = iwl_mvm_send_cmd_status(mvm, &cmd, &status);
548 if (ret)
549 return ret;
550
551 if (status != CAN_ABORT_STATUS) {
552 /*
553 * The scan abort will return 1 for success or
554 * 2 for "failure". A failure condition can be
555 * due to simply not being in an active scan which
556 * can occur if we send the scan abort before the
557 * microcode has notified us that a scan is completed.
558 */
559 IWL_DEBUG_SCAN(mvm, "SCAN OFFLOAD ABORT ret %d.\n", status);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +0200560 ret = -ENOENT;
David Spinadel35a000b2013-08-28 09:29:43 +0300561 }
562
563 return ret;
564}
565
Luciano Coelho65ff5562015-03-20 13:35:47 +0200566static void iwl_mvm_scan_fill_tx_cmd(struct iwl_mvm *mvm,
567 struct iwl_scan_req_tx_cmd *tx_cmd,
568 bool no_cck)
David Spinadelfb98be52014-05-04 12:51:10 +0300569{
570 tx_cmd[0].tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL |
571 TX_CMD_FLG_BT_DIS);
572 tx_cmd[0].rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm,
573 IEEE80211_BAND_2GHZ,
574 no_cck);
575 tx_cmd[0].sta_id = mvm->aux_sta.sta_id;
576
577 tx_cmd[1].tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL |
578 TX_CMD_FLG_BT_DIS);
579 tx_cmd[1].rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm,
580 IEEE80211_BAND_5GHZ,
581 no_cck);
582 tx_cmd[1].sta_id = mvm->aux_sta.sta_id;
583}
584
585static void
586iwl_mvm_lmac_scan_cfg_channels(struct iwl_mvm *mvm,
587 struct ieee80211_channel **channels,
588 int n_channels, u32 ssid_bitmap,
Luciano Coelho65ff5562015-03-20 13:35:47 +0200589 struct iwl_scan_req_lmac *cmd)
David Spinadelfb98be52014-05-04 12:51:10 +0300590{
591 struct iwl_scan_channel_cfg_lmac *channel_cfg = (void *)&cmd->data;
592 int i;
593
594 for (i = 0; i < n_channels; i++) {
595 channel_cfg[i].channel_num =
596 cpu_to_le16(channels[i]->hw_value);
597 channel_cfg[i].iter_count = cpu_to_le16(1);
598 channel_cfg[i].iter_interval = 0;
599 channel_cfg[i].flags =
600 cpu_to_le32(IWL_UNIFIED_SCAN_CHANNEL_PARTIAL |
601 ssid_bitmap);
602 }
603}
604
Andrei Otcheretianski66dc5272014-09-02 17:55:40 +0300605static u8 *iwl_mvm_copy_and_insert_ds_elem(struct iwl_mvm *mvm, const u8 *ies,
606 size_t len, u8 *const pos)
607{
608 static const u8 before_ds_params[] = {
609 WLAN_EID_SSID,
610 WLAN_EID_SUPP_RATES,
611 WLAN_EID_REQUEST,
612 WLAN_EID_EXT_SUPP_RATES,
613 };
614 size_t offs;
615 u8 *newpos = pos;
616
617 if (!iwl_mvm_rrm_scan_needed(mvm)) {
618 memcpy(newpos, ies, len);
619 return newpos + len;
620 }
621
622 offs = ieee80211_ie_split(ies, len,
623 before_ds_params,
624 ARRAY_SIZE(before_ds_params),
625 0);
626
627 memcpy(newpos, ies, offs);
628 newpos += offs;
629
630 /* Add a placeholder for DS Parameter Set element */
631 *newpos++ = WLAN_EID_DS_PARAMS;
632 *newpos++ = 1;
633 *newpos++ = 0;
634
635 memcpy(newpos, ies + offs, len - offs);
636 newpos += len - offs;
637
638 return newpos;
639}
640
David Spinadelfb98be52014-05-04 12:51:10 +0300641static void
Luciano Coelho65ff5562015-03-20 13:35:47 +0200642iwl_mvm_build_scan_probe(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
643 struct ieee80211_scan_ies *ies,
Luciano Coelho45d1b122015-04-15 16:34:13 +0300644 struct iwl_mvm_scan_params *params)
David Spinadelfb98be52014-05-04 12:51:10 +0300645{
Luciano Coelho45d1b122015-04-15 16:34:13 +0300646 struct ieee80211_mgmt *frame = (void *)params->preq.buf;
Andrei Otcheretianski66dc5272014-09-02 17:55:40 +0300647 u8 *pos, *newpos;
Luciano Coelho45d1b122015-04-15 16:34:13 +0300648 const u8 *mac_addr = params->flags & NL80211_SCAN_FLAG_RANDOM_ADDR ?
649 params->mac_addr : NULL;
David Spinadelfb98be52014-05-04 12:51:10 +0300650
Johannes Bergeffd05a2014-11-18 17:21:19 +0100651 /*
652 * Unfortunately, right now the offload scan doesn't support randomising
653 * within the firmware, so until the firmware API is ready we implement
654 * it in the driver. This means that the scan iterations won't really be
655 * random, only when it's restarted, but at least that helps a bit.
656 */
657 if (mac_addr)
Luciano Coelho45d1b122015-04-15 16:34:13 +0300658 get_random_mask_addr(frame->sa, mac_addr,
659 params->mac_addr_mask);
Johannes Bergeffd05a2014-11-18 17:21:19 +0100660 else
661 memcpy(frame->sa, vif->addr, ETH_ALEN);
662
David Spinadelfb98be52014-05-04 12:51:10 +0300663 frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
664 eth_broadcast_addr(frame->da);
David Spinadelfb98be52014-05-04 12:51:10 +0300665 eth_broadcast_addr(frame->bssid);
666 frame->seq_ctrl = 0;
667
668 pos = frame->u.probe_req.variable;
669 *pos++ = WLAN_EID_SSID;
670 *pos++ = 0;
671
Luciano Coelho45d1b122015-04-15 16:34:13 +0300672 params->preq.mac_header.offset = 0;
673 params->preq.mac_header.len = cpu_to_le16(24 + 2);
David Spinadelfb98be52014-05-04 12:51:10 +0300674
Andrei Otcheretianski66dc5272014-09-02 17:55:40 +0300675 /* Insert ds parameter set element on 2.4 GHz band */
676 newpos = iwl_mvm_copy_and_insert_ds_elem(mvm,
677 ies->ies[IEEE80211_BAND_2GHZ],
678 ies->len[IEEE80211_BAND_2GHZ],
679 pos);
Luciano Coelho45d1b122015-04-15 16:34:13 +0300680 params->preq.band_data[0].offset = cpu_to_le16(pos - params->preq.buf);
681 params->preq.band_data[0].len = cpu_to_le16(newpos - pos);
Andrei Otcheretianski66dc5272014-09-02 17:55:40 +0300682 pos = newpos;
David Spinadelfb98be52014-05-04 12:51:10 +0300683
684 memcpy(pos, ies->ies[IEEE80211_BAND_5GHZ],
685 ies->len[IEEE80211_BAND_5GHZ]);
Luciano Coelho45d1b122015-04-15 16:34:13 +0300686 params->preq.band_data[1].offset = cpu_to_le16(pos - params->preq.buf);
687 params->preq.band_data[1].len =
688 cpu_to_le16(ies->len[IEEE80211_BAND_5GHZ]);
David Spinadelfb98be52014-05-04 12:51:10 +0300689 pos += ies->len[IEEE80211_BAND_5GHZ];
690
691 memcpy(pos, ies->common_ies, ies->common_ie_len);
Luciano Coelho45d1b122015-04-15 16:34:13 +0300692 params->preq.common_data.offset = cpu_to_le16(pos - params->preq.buf);
693 params->preq.common_data.len = cpu_to_le16(ies->common_ie_len);
David Spinadelfb98be52014-05-04 12:51:10 +0300694}
695
Avraham Sternd7afbfc2015-05-12 12:19:48 +0300696static __le32 iwl_mvm_scan_priority(struct iwl_mvm *mvm,
697 enum iwl_scan_priority_ext prio)
698{
Johannes Berg859d9142015-06-01 17:11:11 +0200699 if (fw_has_api(&mvm->fw->ucode_capa,
700 IWL_UCODE_TLV_API_EXT_SCAN_PRIORITY))
Avraham Sternd7afbfc2015-05-12 12:19:48 +0300701 return cpu_to_le32(prio);
702
703 if (prio <= IWL_SCAN_PRIORITY_EXT_2)
704 return cpu_to_le32(IWL_SCAN_PRIORITY_LOW);
705
706 if (prio <= IWL_SCAN_PRIORITY_EXT_4)
707 return cpu_to_le32(IWL_SCAN_PRIORITY_MEDIUM);
708
709 return cpu_to_le32(IWL_SCAN_PRIORITY_HIGH);
710}
711
Luciano Coelho133c8252015-04-20 15:29:03 +0300712static void iwl_mvm_scan_lmac_dwell(struct iwl_mvm *mvm,
713 struct iwl_scan_req_lmac *cmd,
714 struct iwl_mvm_scan_params *params)
David Spinadelfb98be52014-05-04 12:51:10 +0300715{
David Spinadel9437e992015-06-22 13:20:00 +0300716 cmd->active_dwell = scan_timing[params->type].dwell_active;
717 cmd->passive_dwell = scan_timing[params->type].dwell_passive;
718 cmd->fragmented_dwell = scan_timing[params->type].dwell_fragmented;
719 cmd->max_out_time = cpu_to_le32(scan_timing[params->type].max_out_time);
720 cmd->suspend_time = cpu_to_le32(scan_timing[params->type].suspend_time);
Avraham Sternd7afbfc2015-05-12 12:19:48 +0300721 cmd->scan_prio = iwl_mvm_scan_priority(mvm, IWL_SCAN_PRIORITY_EXT_6);
David Spinadelfb98be52014-05-04 12:51:10 +0300722}
723
Luciano Coelho999d2562015-03-27 10:28:26 +0300724static inline bool iwl_mvm_scan_fits(struct iwl_mvm *mvm, int n_ssids,
725 struct ieee80211_scan_ies *ies,
726 int n_channels)
727{
728 return ((n_ssids <= PROBE_OPTION_MAX) &&
729 (n_channels <= mvm->fw->ucode_capa.n_scan_channels) &
730 (ies->common_ie_len +
731 ies->len[NL80211_BAND_2GHZ] +
732 ies->len[NL80211_BAND_5GHZ] <=
733 iwl_mvm_max_scan_ie_fw_cmd_room(mvm)));
734}
735
David Spinadel15286e22015-05-26 10:32:19 +0300736static inline bool iwl_mvm_scan_use_ebs(struct iwl_mvm *mvm,
Avraham Sterncd55cce2015-08-19 12:46:12 +0300737 struct ieee80211_vif *vif)
Luciano Coelho7d7de1e2015-04-17 09:53:55 +0300738{
739 const struct iwl_ucode_capabilities *capa = &mvm->fw->ucode_capa;
740
741 /* We can only use EBS if:
742 * 1. the feature is supported;
743 * 2. the last EBS was successful;
David Spinadel15286e22015-05-26 10:32:19 +0300744 * 3. if only single scan, the single scan EBS API is supported;
745 * 4. it's not a p2p find operation.
Luciano Coelho7d7de1e2015-04-17 09:53:55 +0300746 */
747 return ((capa->flags & IWL_UCODE_TLV_FLAGS_EBS_SUPPORT) &&
748 mvm->last_ebs_successful &&
David Spinadel15286e22015-05-26 10:32:19 +0300749 vif->type != NL80211_IFTYPE_P2P_DEVICE);
Luciano Coelho7d7de1e2015-04-17 09:53:55 +0300750}
751
Luciano Coelho87515402015-04-20 14:47:49 +0300752static int iwl_mvm_scan_lmac_flags(struct iwl_mvm *mvm,
753 struct iwl_mvm_scan_params *params)
754{
755 int flags = 0;
756
757 if (params->n_ssids == 0)
758 flags |= IWL_MVM_LMAC_SCAN_FLAG_PASSIVE;
759
760 if (params->n_ssids == 1 && params->ssids[0].ssid_len != 0)
761 flags |= IWL_MVM_LMAC_SCAN_FLAG_PRE_CONNECTION;
762
David Spinadel9437e992015-06-22 13:20:00 +0300763 if (params->type == IWL_SCAN_TYPE_FRAGMENTED)
Luciano Coelho87515402015-04-20 14:47:49 +0300764 flags |= IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED;
765
766 if (iwl_mvm_rrm_scan_needed(mvm))
767 flags |= IWL_MVM_LMAC_SCAN_FLAGS_RRM_ENABLED;
768
769 if (params->pass_all)
770 flags |= IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL;
771 else
772 flags |= IWL_MVM_LMAC_SCAN_FLAG_MATCH;
773
774#ifdef CONFIG_IWLWIFI_DEBUGFS
775 if (mvm->scan_iter_notif_enabled)
776 flags |= IWL_MVM_LMAC_SCAN_FLAG_ITER_COMPLETE;
777#endif
778
779 return flags;
780}
781
Luciano Coelho6749dd82015-03-20 15:51:36 +0200782static int iwl_mvm_scan_lmac(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
Luciano Coelho3db7c6e2015-04-01 17:09:56 +0300783 struct iwl_mvm_scan_params *params)
David Spinadelfb98be52014-05-04 12:51:10 +0300784{
Luciano Coelho65ff5562015-03-20 13:35:47 +0200785 struct iwl_scan_req_lmac *cmd = mvm->scan_cmd;
Luciano Coelho45d1b122015-04-15 16:34:13 +0300786 struct iwl_scan_probe_req *preq =
787 (void *)(cmd->data + sizeof(struct iwl_scan_channel_cfg_lmac) *
788 mvm->fw->ucode_capa.n_scan_channels);
Luciano Coelho87515402015-04-20 14:47:49 +0300789 u32 ssid_bitmap = 0;
Avraham Sterncd55cce2015-08-19 12:46:12 +0300790 int i;
David Spinadelfb98be52014-05-04 12:51:10 +0300791
792 lockdep_assert_held(&mvm->mutex);
793
Luciano Coelho133c8252015-04-20 15:29:03 +0300794 memset(cmd, 0, ksize(cmd));
David Spinadelfb98be52014-05-04 12:51:10 +0300795
Avraham Sterncd55cce2015-08-19 12:46:12 +0300796 if (WARN_ON(params->n_scan_plans > IWL_MAX_SCHED_SCAN_PLANS))
797 return -EINVAL;
798
Luciano Coelho133c8252015-04-20 15:29:03 +0300799 iwl_mvm_scan_lmac_dwell(mvm, cmd, params);
800
801 cmd->rx_chain_select = iwl_mvm_scan_rx_chain(mvm);
802 cmd->iter_num = cpu_to_le32(1);
Luciano Coelhof7b788b2015-04-02 00:08:35 +0300803 cmd->n_channels = (u8)params->n_channels;
David Spinadelfb98be52014-05-04 12:51:10 +0300804
Luciano Coelhof7b788b2015-04-02 00:08:35 +0300805 cmd->delay = cpu_to_le32(params->delay);
Luciano Coelho2250fd92014-12-03 10:52:26 +0200806
Luciano Coelho87515402015-04-20 14:47:49 +0300807 cmd->scan_flags = cpu_to_le32(iwl_mvm_scan_lmac_flags(mvm, params));
David Spinadelfb98be52014-05-04 12:51:10 +0300808
Luciano Coelhof7b788b2015-04-02 00:08:35 +0300809 cmd->flags = iwl_mvm_scan_rxon_flags(params->channels[0]->band);
David Spinadelfb98be52014-05-04 12:51:10 +0300810 cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP |
811 MAC_FILTER_IN_BEACON);
Luciano Coelhof7b788b2015-04-02 00:08:35 +0300812 iwl_mvm_scan_fill_tx_cmd(mvm, cmd->tx_cmd, params->no_cck);
Luciano Coelhoe2ec4f62015-04-02 17:49:04 +0300813 iwl_scan_build_ssids(params, cmd->direct_scan, &ssid_bitmap);
814
815 /* this API uses bits 1-20 instead of 0-19 */
816 ssid_bitmap <<= 1;
Luciano Coelhof7b788b2015-04-02 00:08:35 +0300817
Avraham Sterncd55cce2015-08-19 12:46:12 +0300818 for (i = 0; i < params->n_scan_plans; i++) {
Avraham Sterncd55cce2015-08-19 12:46:12 +0300819 struct cfg80211_sched_scan_plan *scan_plan =
820 &params->scan_plans[i];
David Spinadelfb98be52014-05-04 12:51:10 +0300821
Avraham Sterncd55cce2015-08-19 12:46:12 +0300822 cmd->schedule[i].delay =
823 cpu_to_le16(scan_plan->interval);
824 cmd->schedule[i].iterations = scan_plan->iterations;
825 cmd->schedule[i].full_scan_mul = 1;
826 }
827
828 /*
829 * If the number of iterations of the last scan plan is set to
830 * zero, it should run infinitely. However, this is not always the case.
831 * For example, when regular scan is requested the driver sets one scan
832 * plan with one iteration.
833 */
834 if (!cmd->schedule[i - 1].iterations)
Johannes Berg46eebec2015-09-11 12:09:22 +0200835 cmd->schedule[i - 1].iterations = 0xff;
Avraham Sterncd55cce2015-08-19 12:46:12 +0300836
837 if (iwl_mvm_scan_use_ebs(mvm, vif)) {
David Spinadel1f9c4182014-12-01 23:30:07 +0200838 cmd->channel_opt[0].flags =
839 cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS |
840 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
841 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD);
842 cmd->channel_opt[0].non_ebs_ratio =
843 cpu_to_le16(IWL_DENSE_EBS_SCAN_RATIO);
844 cmd->channel_opt[1].flags =
845 cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS |
846 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
847 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD);
848 cmd->channel_opt[1].non_ebs_ratio =
849 cpu_to_le16(IWL_SPARSE_EBS_SCAN_RATIO);
850 }
851
Luciano Coelhof7b788b2015-04-02 00:08:35 +0300852 iwl_mvm_lmac_scan_cfg_channels(mvm, params->channels,
853 params->n_channels, ssid_bitmap, cmd);
David Spinadelfb98be52014-05-04 12:51:10 +0300854
Luciano Coelho45d1b122015-04-15 16:34:13 +0300855 *preq = params->preq;
David Spinadelfb98be52014-05-04 12:51:10 +0300856
Luciano Coelho8df3e682015-04-01 17:37:44 +0300857 return 0;
David Spinadelfb98be52014-05-04 12:51:10 +0300858}
859
David Spinadeld2496222014-05-20 12:46:37 +0300860static int rate_to_scan_rate_flag(unsigned int rate)
861{
862 static const int rate_to_scan_rate[IWL_RATE_COUNT] = {
863 [IWL_RATE_1M_INDEX] = SCAN_CONFIG_RATE_1M,
864 [IWL_RATE_2M_INDEX] = SCAN_CONFIG_RATE_2M,
865 [IWL_RATE_5M_INDEX] = SCAN_CONFIG_RATE_5M,
866 [IWL_RATE_11M_INDEX] = SCAN_CONFIG_RATE_11M,
867 [IWL_RATE_6M_INDEX] = SCAN_CONFIG_RATE_6M,
868 [IWL_RATE_9M_INDEX] = SCAN_CONFIG_RATE_9M,
869 [IWL_RATE_12M_INDEX] = SCAN_CONFIG_RATE_12M,
870 [IWL_RATE_18M_INDEX] = SCAN_CONFIG_RATE_18M,
871 [IWL_RATE_24M_INDEX] = SCAN_CONFIG_RATE_24M,
872 [IWL_RATE_36M_INDEX] = SCAN_CONFIG_RATE_36M,
873 [IWL_RATE_48M_INDEX] = SCAN_CONFIG_RATE_48M,
874 [IWL_RATE_54M_INDEX] = SCAN_CONFIG_RATE_54M,
875 };
876
877 return rate_to_scan_rate[rate];
878}
879
880static __le32 iwl_mvm_scan_config_rates(struct iwl_mvm *mvm)
881{
882 struct ieee80211_supported_band *band;
883 unsigned int rates = 0;
884 int i;
885
886 band = &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
887 for (i = 0; i < band->n_bitrates; i++)
888 rates |= rate_to_scan_rate_flag(band->bitrates[i].hw_value);
889 band = &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
890 for (i = 0; i < band->n_bitrates; i++)
891 rates |= rate_to_scan_rate_flag(band->bitrates[i].hw_value);
892
893 /* Set both basic rates and supported rates */
894 rates |= SCAN_CONFIG_SUPPORTED_RATE(rates);
895
896 return cpu_to_le32(rates);
897}
898
899int iwl_mvm_config_scan(struct iwl_mvm *mvm)
900{
David Spinadeld2496222014-05-20 12:46:37 +0300901 struct iwl_scan_config *scan_config;
902 struct ieee80211_supported_band *band;
903 int num_channels =
904 mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels +
905 mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels;
Johannes Berg88742c92015-06-30 15:31:22 +0200906 int ret, i, j = 0, cmd_size;
David Spinadeld2496222014-05-20 12:46:37 +0300907 struct iwl_host_cmd cmd = {
Johannes Berg88742c92015-06-30 15:31:22 +0200908 .id = iwl_cmd_id(SCAN_CFG_CMD, IWL_ALWAYS_LONG_GROUP, 0),
David Spinadeld2496222014-05-20 12:46:37 +0300909 };
Avraham Stern355346b2015-11-26 11:22:33 +0200910 enum iwl_mvm_scan_type type = iwl_mvm_get_scan_type(mvm, false);
David Spinadeld2496222014-05-20 12:46:37 +0300911
912 if (WARN_ON(num_channels > mvm->fw->ucode_capa.n_scan_channels))
913 return -ENOBUFS;
914
Avraham Stern355346b2015-11-26 11:22:33 +0200915 if (type == mvm->scan_type)
916 return 0;
917
David Spinadeld2496222014-05-20 12:46:37 +0300918 cmd_size = sizeof(*scan_config) + mvm->fw->ucode_capa.n_scan_channels;
919
920 scan_config = kzalloc(cmd_size, GFP_KERNEL);
921 if (!scan_config)
922 return -ENOMEM;
923
David Spinadeld2496222014-05-20 12:46:37 +0300924 scan_config->flags = cpu_to_le32(SCAN_CONFIG_FLAG_ACTIVATE |
925 SCAN_CONFIG_FLAG_ALLOW_CHUB_REQS |
926 SCAN_CONFIG_FLAG_SET_TX_CHAINS |
927 SCAN_CONFIG_FLAG_SET_RX_CHAINS |
928 SCAN_CONFIG_FLAG_SET_ALL_TIMES |
929 SCAN_CONFIG_FLAG_SET_LEGACY_RATES |
930 SCAN_CONFIG_FLAG_SET_MAC_ADDR |
931 SCAN_CONFIG_FLAG_SET_CHANNEL_FLAGS|
Avraham Sternf9d71642015-11-10 14:56:24 +0200932 SCAN_CONFIG_N_CHANNELS(num_channels) |
Avraham Stern355346b2015-11-26 11:22:33 +0200933 (type == IWL_SCAN_TYPE_FRAGMENTED ?
Avraham Sternf9d71642015-11-10 14:56:24 +0200934 SCAN_CONFIG_FLAG_SET_FRAGMENTED :
935 SCAN_CONFIG_FLAG_CLEAR_FRAGMENTED));
Moshe Harela0544272014-12-08 21:13:14 +0200936 scan_config->tx_chains = cpu_to_le32(iwl_mvm_get_valid_tx_ant(mvm));
David Spinadeld2496222014-05-20 12:46:37 +0300937 scan_config->rx_chains = cpu_to_le32(iwl_mvm_scan_rx_ant(mvm));
938 scan_config->legacy_rates = iwl_mvm_scan_config_rates(mvm);
Avraham Stern355346b2015-11-26 11:22:33 +0200939 scan_config->out_of_channel_time =
940 cpu_to_le32(scan_timing[type].max_out_time);
941 scan_config->suspend_time = cpu_to_le32(scan_timing[type].suspend_time);
942 scan_config->dwell_active = scan_timing[type].dwell_active;
943 scan_config->dwell_passive = scan_timing[type].dwell_passive;
944 scan_config->dwell_fragmented = scan_timing[type].dwell_fragmented;
David Spinadeld2496222014-05-20 12:46:37 +0300945
946 memcpy(&scan_config->mac_addr, &mvm->addresses[0].addr, ETH_ALEN);
947
948 scan_config->bcast_sta_id = mvm->aux_sta.sta_id;
949 scan_config->channel_flags = IWL_CHANNEL_FLAG_EBS |
950 IWL_CHANNEL_FLAG_ACCURATE_EBS |
951 IWL_CHANNEL_FLAG_EBS_ADD |
952 IWL_CHANNEL_FLAG_PRE_SCAN_PASSIVE2ACTIVE;
953
954 band = &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
955 for (i = 0; i < band->n_channels; i++, j++)
Ilan Peera25d40e2015-01-23 21:13:01 +0200956 scan_config->channel_array[j] = band->channels[i].hw_value;
David Spinadeld2496222014-05-20 12:46:37 +0300957 band = &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
958 for (i = 0; i < band->n_channels; i++, j++)
Ilan Peera25d40e2015-01-23 21:13:01 +0200959 scan_config->channel_array[j] = band->channels[i].hw_value;
David Spinadeld2496222014-05-20 12:46:37 +0300960
961 cmd.data[0] = scan_config;
962 cmd.len[0] = cmd_size;
963 cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
964
965 IWL_DEBUG_SCAN(mvm, "Sending UMAC scan config\n");
966
967 ret = iwl_mvm_send_cmd(mvm, &cmd);
Avraham Stern355346b2015-11-26 11:22:33 +0200968 if (!ret)
969 mvm->scan_type = type;
David Spinadeld2496222014-05-20 12:46:37 +0300970
971 kfree(scan_config);
972 return ret;
973}
974
Luciano Coelho6185af2a2015-05-07 11:13:24 +0300975static int iwl_mvm_scan_uid_by_status(struct iwl_mvm *mvm, int status)
David Spinadeld2496222014-05-20 12:46:37 +0300976{
977 int i;
978
Luciano Coelho507e4cd2015-03-19 22:58:33 +0200979 for (i = 0; i < mvm->max_scans; i++)
Luciano Coelho6185af2a2015-05-07 11:13:24 +0300980 if (mvm->scan_uid_status[i] == status)
David Spinadeld2496222014-05-20 12:46:37 +0300981 return i;
982
Luciano Coelho6185af2a2015-05-07 11:13:24 +0300983 return -ENOENT;
David Spinadeld2496222014-05-20 12:46:37 +0300984}
985
Avraham Sterncd55cce2015-08-19 12:46:12 +0300986static inline bool iwl_mvm_is_regular_scan(struct iwl_mvm_scan_params *params)
987{
988 return params->n_scan_plans == 1 &&
989 params->scan_plans[0].iterations == 1;
990}
991
Luciano Coelho133c8252015-04-20 15:29:03 +0300992static void iwl_mvm_scan_umac_dwell(struct iwl_mvm *mvm,
David Spinadeld2496222014-05-20 12:46:37 +0300993 struct iwl_scan_req_umac *cmd,
994 struct iwl_mvm_scan_params *params)
995{
David Spinadel9437e992015-06-22 13:20:00 +0300996 cmd->active_dwell = scan_timing[params->type].dwell_active;
997 cmd->passive_dwell = scan_timing[params->type].dwell_passive;
998 cmd->fragmented_dwell = scan_timing[params->type].dwell_fragmented;
999 cmd->max_out_time = cpu_to_le32(scan_timing[params->type].max_out_time);
1000 cmd->suspend_time = cpu_to_le32(scan_timing[params->type].suspend_time);
Avraham Sternd7afbfc2015-05-12 12:19:48 +03001001 cmd->scan_priority =
1002 iwl_mvm_scan_priority(mvm, IWL_SCAN_PRIORITY_EXT_6);
Luciano Coelho133c8252015-04-20 15:29:03 +03001003
Avraham Sterncd55cce2015-08-19 12:46:12 +03001004 if (iwl_mvm_is_regular_scan(params))
Avraham Sternd7afbfc2015-05-12 12:19:48 +03001005 cmd->ooc_priority =
1006 iwl_mvm_scan_priority(mvm, IWL_SCAN_PRIORITY_EXT_6);
Luciano Coelho133c8252015-04-20 15:29:03 +03001007 else
Avraham Sternd7afbfc2015-05-12 12:19:48 +03001008 cmd->ooc_priority =
1009 iwl_mvm_scan_priority(mvm, IWL_SCAN_PRIORITY_EXT_2);
David Spinadeld2496222014-05-20 12:46:37 +03001010}
1011
1012static void
1013iwl_mvm_umac_scan_cfg_channels(struct iwl_mvm *mvm,
1014 struct ieee80211_channel **channels,
1015 int n_channels, u32 ssid_bitmap,
1016 struct iwl_scan_req_umac *cmd)
1017{
1018 struct iwl_scan_channel_cfg_umac *channel_cfg = (void *)&cmd->data;
1019 int i;
1020
1021 for (i = 0; i < n_channels; i++) {
1022 channel_cfg[i].flags = cpu_to_le32(ssid_bitmap);
1023 channel_cfg[i].channel_num = channels[i]->hw_value;
1024 channel_cfg[i].iter_count = 1;
1025 channel_cfg[i].iter_interval = 0;
1026 }
1027}
1028
Luciano Coelho6f4dcc72015-04-20 14:37:16 +03001029static u32 iwl_mvm_scan_umac_flags(struct iwl_mvm *mvm,
1030 struct iwl_mvm_scan_params *params)
David Spinadeld2496222014-05-20 12:46:37 +03001031{
1032 int flags = 0;
1033
Luciano Coelho6f4dcc72015-04-20 14:37:16 +03001034 if (params->n_ssids == 0)
David Spinadeld2496222014-05-20 12:46:37 +03001035 flags = IWL_UMAC_SCAN_GEN_FLAGS_PASSIVE;
1036
Luciano Coelho6f4dcc72015-04-20 14:37:16 +03001037 if (params->n_ssids == 1 && params->ssids[0].ssid_len != 0)
David Spinadeld2496222014-05-20 12:46:37 +03001038 flags |= IWL_UMAC_SCAN_GEN_FLAGS_PRE_CONNECT;
1039
David Spinadel9437e992015-06-22 13:20:00 +03001040 if (params->type == IWL_SCAN_TYPE_FRAGMENTED)
David Spinadeld2496222014-05-20 12:46:37 +03001041 flags |= IWL_UMAC_SCAN_GEN_FLAGS_FRAGMENTED;
1042
1043 if (iwl_mvm_rrm_scan_needed(mvm))
1044 flags |= IWL_UMAC_SCAN_GEN_FLAGS_RRM_ENABLED;
1045
Luciano Coelho6f4dcc72015-04-20 14:37:16 +03001046 if (params->pass_all)
1047 flags |= IWL_UMAC_SCAN_GEN_FLAGS_PASS_ALL;
1048 else
1049 flags |= IWL_UMAC_SCAN_GEN_FLAGS_MATCH;
1050
Avraham Sterncd55cce2015-08-19 12:46:12 +03001051 if (!iwl_mvm_is_regular_scan(params))
Luciano Coelho6f4dcc72015-04-20 14:37:16 +03001052 flags |= IWL_UMAC_SCAN_GEN_FLAGS_PERIODIC;
1053
Avraham Sternee9219b2015-03-23 15:09:27 +02001054#ifdef CONFIG_IWLWIFI_DEBUGFS
1055 if (mvm->scan_iter_notif_enabled)
1056 flags |= IWL_UMAC_SCAN_GEN_FLAGS_ITER_COMPLETE;
1057#endif
David Spinadeld2496222014-05-20 12:46:37 +03001058 return flags;
1059}
1060
Luciano Coelho6749dd82015-03-20 15:51:36 +02001061static int iwl_mvm_scan_umac(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
Luciano Coelho6185af2a2015-05-07 11:13:24 +03001062 struct iwl_mvm_scan_params *params,
1063 int type)
David Spinadeld2496222014-05-20 12:46:37 +03001064{
David Spinadeld2496222014-05-20 12:46:37 +03001065 struct iwl_scan_req_umac *cmd = mvm->scan_cmd;
1066 struct iwl_scan_req_umac_tail *sec_part = (void *)&cmd->data +
1067 sizeof(struct iwl_scan_channel_cfg_umac) *
1068 mvm->fw->ucode_capa.n_scan_channels;
Avraham Sterncd55cce2015-08-19 12:46:12 +03001069 int uid, i;
Johannes Bergc8660dd2014-11-17 15:06:52 +01001070 u32 ssid_bitmap = 0;
David Spinadeld2496222014-05-20 12:46:37 +03001071
1072 lockdep_assert_held(&mvm->mutex);
1073
Avraham Sterncd55cce2015-08-19 12:46:12 +03001074 if (WARN_ON(params->n_scan_plans > IWL_MAX_SCHED_SCAN_PLANS))
1075 return -EINVAL;
1076
Luciano Coelho6185af2a2015-05-07 11:13:24 +03001077 uid = iwl_mvm_scan_uid_by_status(mvm, 0);
1078 if (uid < 0)
1079 return uid;
David Spinadeld2496222014-05-20 12:46:37 +03001080
Luciano Coelho133c8252015-04-20 15:29:03 +03001081 memset(cmd, 0, ksize(cmd));
David Spinadeld2496222014-05-20 12:46:37 +03001082
Luciano Coelho133c8252015-04-20 15:29:03 +03001083 iwl_mvm_scan_umac_dwell(mvm, cmd, params);
1084
Luciano Coelho6185af2a2015-05-07 11:13:24 +03001085 mvm->scan_uid_status[uid] = type;
Luciano Coelho8423cdc2015-04-17 14:49:58 +03001086
Luciano Coelho8423cdc2015-04-17 14:49:58 +03001087 cmd->uid = cpu_to_le32(uid);
Luciano Coelho6f4dcc72015-04-20 14:37:16 +03001088 cmd->general_flags = cpu_to_le32(iwl_mvm_scan_umac_flags(mvm, params));
Haim Dreyfuss4db65582015-01-05 15:00:35 +02001089
Avraham Stern8465fe62015-06-21 12:06:13 +03001090 if (type == IWL_MVM_SCAN_SCHED)
1091 cmd->flags = cpu_to_le32(IWL_UMAC_SCAN_FLAG_PREEMPTIVE);
1092
Avraham Sterncd55cce2015-08-19 12:46:12 +03001093 if (iwl_mvm_scan_use_ebs(mvm, vif))
Haim Dreyfuss4db65582015-01-05 15:00:35 +02001094 cmd->channel_flags = IWL_SCAN_CHANNEL_FLAG_EBS |
1095 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
1096 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD;
1097
Luciano Coelhof7b788b2015-04-02 00:08:35 +03001098 cmd->n_channels = params->n_channels;
David Spinadeld2496222014-05-20 12:46:37 +03001099
Luciano Coelhoe2ec4f62015-04-02 17:49:04 +03001100 iwl_scan_build_ssids(params, sec_part->direct_scan, &ssid_bitmap);
David Spinadeld2496222014-05-20 12:46:37 +03001101
Luciano Coelhof7b788b2015-04-02 00:08:35 +03001102 iwl_mvm_umac_scan_cfg_channels(mvm, params->channels,
1103 params->n_channels, ssid_bitmap, cmd);
David Spinadeld2496222014-05-20 12:46:37 +03001104
Avraham Sterncd55cce2015-08-19 12:46:12 +03001105 for (i = 0; i < params->n_scan_plans; i++) {
Avraham Sterncd55cce2015-08-19 12:46:12 +03001106 struct cfg80211_sched_scan_plan *scan_plan =
1107 &params->scan_plans[i];
1108
Avraham Sterncd55cce2015-08-19 12:46:12 +03001109 sec_part->schedule[i].iter_count = scan_plan->iterations;
1110 sec_part->schedule[i].interval =
1111 cpu_to_le16(scan_plan->interval);
1112 }
1113
1114 /*
1115 * If the number of iterations of the last scan plan is set to
1116 * zero, it should run infinitely. However, this is not always the case.
1117 * For example, when regular scan is requested the driver sets one scan
1118 * plan with one iteration.
Luciano Coelho8423cdc2015-04-17 14:49:58 +03001119 */
Avraham Sterncd55cce2015-08-19 12:46:12 +03001120 if (!sec_part->schedule[i - 1].iter_count)
1121 sec_part->schedule[i - 1].iter_count = 0xff;
Luciano Coelhocf5d3172015-04-16 20:13:28 +03001122
Luciano Coelho283c2492015-04-17 11:18:46 +03001123 sec_part->delay = cpu_to_le16(params->delay);
Luciano Coelho45d1b122015-04-15 16:34:13 +03001124 sec_part->preq = params->preq;
David Spinadeld2496222014-05-20 12:46:37 +03001125
Luciano Coelho8df3e682015-04-01 17:37:44 +03001126 return 0;
David Spinadeld2496222014-05-20 12:46:37 +03001127}
1128
Luciano Coelho6749dd82015-03-20 15:51:36 +02001129static int iwl_mvm_num_scans(struct iwl_mvm *mvm)
1130{
1131 return hweight32(mvm->scan_status & IWL_MVM_SCAN_MASK);
1132}
1133
1134static int iwl_mvm_check_running_scans(struct iwl_mvm *mvm, int type)
1135{
1136 /* This looks a bit arbitrary, but the idea is that if we run
1137 * out of possible simultaneous scans and the userspace is
1138 * trying to run a scan type that is already running, we
1139 * return -EBUSY. But if the userspace wants to start a
1140 * different type of scan, we stop the opposite type to make
1141 * space for the new request. The reason is backwards
1142 * compatibility with old wpa_supplicant that wouldn't stop a
1143 * scheduled scan before starting a normal scan.
1144 */
1145
1146 if (iwl_mvm_num_scans(mvm) < mvm->max_scans)
1147 return 0;
1148
1149 /* Use a switch, even though this is a bitmask, so that more
1150 * than one bits set will fall in default and we will warn.
1151 */
1152 switch (type) {
1153 case IWL_MVM_SCAN_REGULAR:
1154 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR_MASK)
1155 return -EBUSY;
Luciano Coelhoc7d42482015-05-07 16:00:26 +03001156 return iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
Luciano Coelho6749dd82015-03-20 15:51:36 +02001157 case IWL_MVM_SCAN_SCHED:
1158 if (mvm->scan_status & IWL_MVM_SCAN_SCHED_MASK)
1159 return -EBUSY;
Nicholas Krause04b08992015-09-22 20:24:19 -04001160 return iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
Luciano Coelho19945df2015-03-20 16:11:28 +02001161 case IWL_MVM_SCAN_NETDETECT:
1162 /* No need to stop anything for net-detect since the
1163 * firmware is restarted anyway. This way, any sched
1164 * scans that were running will be restarted when we
1165 * resume.
1166 */
1167 return 0;
Luciano Coelho6749dd82015-03-20 15:51:36 +02001168 default:
1169 WARN_ON(1);
1170 break;
1171 }
1172
1173 return -EIO;
1174}
1175
1176int iwl_mvm_reg_scan_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1177 struct cfg80211_scan_request *req,
1178 struct ieee80211_scan_ies *ies)
1179{
Luciano Coelho3db7c6e2015-04-01 17:09:56 +03001180 struct iwl_host_cmd hcmd = {
1181 .len = { iwl_mvm_scan_size(mvm), },
1182 .data = { mvm->scan_cmd, },
1183 .dataflags = { IWL_HCMD_DFL_NOCOPY, },
1184 };
1185 struct iwl_mvm_scan_params params = {};
Luciano Coelho6749dd82015-03-20 15:51:36 +02001186 int ret;
Avraham Sterncd55cce2015-08-19 12:46:12 +03001187 struct cfg80211_sched_scan_plan scan_plan = { .iterations = 1 };
Luciano Coelho6749dd82015-03-20 15:51:36 +02001188
1189 lockdep_assert_held(&mvm->mutex);
1190
1191 if (iwl_mvm_is_lar_supported(mvm) && !mvm->lar_regdom_set) {
1192 IWL_ERR(mvm, "scan while LAR regdomain is not set\n");
1193 return -EBUSY;
1194 }
1195
1196 ret = iwl_mvm_check_running_scans(mvm, IWL_MVM_SCAN_REGULAR);
1197 if (ret)
1198 return ret;
1199
Luciano Coelho3db7c6e2015-04-01 17:09:56 +03001200 /* we should have failed registration if scan_cmd was NULL */
1201 if (WARN_ON(!mvm->scan_cmd))
1202 return -ENOMEM;
1203
1204 if (!iwl_mvm_scan_fits(mvm, req->n_ssids, ies, req->n_channels))
1205 return -ENOBUFS;
1206
Luciano Coelho4b817052015-04-15 16:21:16 +03001207 params.n_ssids = req->n_ssids;
1208 params.flags = req->flags;
Luciano Coelhof7b788b2015-04-02 00:08:35 +03001209 params.n_channels = req->n_channels;
1210 params.delay = 0;
Luciano Coelhof7b788b2015-04-02 00:08:35 +03001211 params.ssids = req->ssids;
1212 params.channels = req->channels;
1213 params.mac_addr = req->mac_addr;
1214 params.mac_addr_mask = req->mac_addr_mask;
1215 params.no_cck = req->no_cck;
1216 params.pass_all = true;
1217 params.n_match_sets = 0;
1218 params.match_sets = NULL;
Luciano Coelho3db7c6e2015-04-01 17:09:56 +03001219
Avraham Sterncd55cce2015-08-19 12:46:12 +03001220 params.scan_plans = &scan_plan;
1221 params.n_scan_plans = 1;
Luciano Coelhocf5d3172015-04-16 20:13:28 +03001222
Avraham Stern355346b2015-11-26 11:22:33 +02001223 params.type =
1224 iwl_mvm_get_scan_type(mvm,
1225 vif->type == NL80211_IFTYPE_P2P_DEVICE);
Luciano Coelho4b817052015-04-15 16:21:16 +03001226
Luciano Coelho45d1b122015-04-15 16:34:13 +03001227 iwl_mvm_build_scan_probe(mvm, vif, ies, &params);
1228
Johannes Berg859d9142015-06-01 17:11:11 +02001229 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
Johannes Berg88742c92015-06-30 15:31:22 +02001230 hcmd.id = iwl_cmd_id(SCAN_REQ_UMAC, IWL_ALWAYS_LONG_GROUP, 0);
Luciano Coelho6185af2a2015-05-07 11:13:24 +03001231 ret = iwl_mvm_scan_umac(mvm, vif, &params,
1232 IWL_MVM_SCAN_REGULAR);
Luciano Coelho3db7c6e2015-04-01 17:09:56 +03001233 } else {
1234 hcmd.id = SCAN_OFFLOAD_REQUEST_CMD;
Luciano Coelho45d1b122015-04-15 16:34:13 +03001235 ret = iwl_mvm_scan_lmac(mvm, vif, &params);
Luciano Coelho3db7c6e2015-04-01 17:09:56 +03001236 }
1237
1238 if (ret)
1239 return ret;
1240
1241 ret = iwl_mvm_send_cmd(mvm, &hcmd);
Eliad Peller78ba82f2015-10-15 10:58:48 +03001242 if (ret) {
Luciano Coelho3db7c6e2015-04-01 17:09:56 +03001243 /* If the scan failed, it usually means that the FW was unable
1244 * to allocate the time events. Warn on it, but maybe we
1245 * should try to send the command again with different params.
1246 */
1247 IWL_ERR(mvm, "Scan failed! ret %d\n", ret);
Eliad Peller78ba82f2015-10-15 10:58:48 +03001248 return ret;
Luciano Coelho3db7c6e2015-04-01 17:09:56 +03001249 }
Luciano Coelho6749dd82015-03-20 15:51:36 +02001250
Eliad Peller78ba82f2015-10-15 10:58:48 +03001251 IWL_DEBUG_SCAN(mvm, "Scan request was sent successfully\n");
1252 mvm->scan_status |= IWL_MVM_SCAN_REGULAR;
1253 iwl_mvm_ref(mvm, IWL_MVM_REF_SCAN);
Luciano Coelho6749dd82015-03-20 15:51:36 +02001254
Eliad Peller78ba82f2015-10-15 10:58:48 +03001255 return 0;
Luciano Coelho6749dd82015-03-20 15:51:36 +02001256}
1257
Luciano Coelho65ff5562015-03-20 13:35:47 +02001258int iwl_mvm_sched_scan_start(struct iwl_mvm *mvm,
1259 struct ieee80211_vif *vif,
1260 struct cfg80211_sched_scan_request *req,
Luciano Coelho19945df2015-03-20 16:11:28 +02001261 struct ieee80211_scan_ies *ies,
1262 int type)
Luciano Coelho65ff5562015-03-20 13:35:47 +02001263{
Luciano Coelho8df3e682015-04-01 17:37:44 +03001264 struct iwl_host_cmd hcmd = {
1265 .len = { iwl_mvm_scan_size(mvm), },
1266 .data = { mvm->scan_cmd, },
1267 .dataflags = { IWL_HCMD_DFL_NOCOPY, },
1268 };
1269 struct iwl_mvm_scan_params params = {};
Luciano Coelho65ff5562015-03-20 13:35:47 +02001270 int ret;
1271
Luciano Coelho6749dd82015-03-20 15:51:36 +02001272 lockdep_assert_held(&mvm->mutex);
1273
1274 if (iwl_mvm_is_lar_supported(mvm) && !mvm->lar_regdom_set) {
1275 IWL_ERR(mvm, "sched-scan while LAR regdomain is not set\n");
1276 return -EBUSY;
1277 }
1278
Luciano Coelho19945df2015-03-20 16:11:28 +02001279 ret = iwl_mvm_check_running_scans(mvm, type);
Luciano Coelho6749dd82015-03-20 15:51:36 +02001280 if (ret)
1281 return ret;
1282
Luciano Coelho8df3e682015-04-01 17:37:44 +03001283 /* we should have failed registration if scan_cmd was NULL */
1284 if (WARN_ON(!mvm->scan_cmd))
1285 return -ENOMEM;
1286
1287 if (!iwl_mvm_scan_fits(mvm, req->n_ssids, ies, req->n_channels))
1288 return -ENOBUFS;
1289
Luciano Coelho4b817052015-04-15 16:21:16 +03001290 params.n_ssids = req->n_ssids;
1291 params.flags = req->flags;
Luciano Coelhof7b788b2015-04-02 00:08:35 +03001292 params.n_channels = req->n_channels;
Luciano Coelhof7b788b2015-04-02 00:08:35 +03001293 params.ssids = req->ssids;
1294 params.channels = req->channels;
1295 params.mac_addr = req->mac_addr;
1296 params.mac_addr_mask = req->mac_addr_mask;
1297 params.no_cck = false;
1298 params.pass_all = iwl_mvm_scan_pass_all(mvm, req);
1299 params.n_match_sets = req->n_match_sets;
1300 params.match_sets = req->match_sets;
Avraham Sterncd55cce2015-08-19 12:46:12 +03001301 if (!req->n_scan_plans)
1302 return -EINVAL;
Luciano Coelhof7b788b2015-04-02 00:08:35 +03001303
Avraham Sterncd55cce2015-08-19 12:46:12 +03001304 params.n_scan_plans = req->n_scan_plans;
1305 params.scan_plans = req->scan_plans;
David Spinadel3b44a0e2015-06-21 11:57:36 +03001306
Avraham Stern355346b2015-11-26 11:22:33 +02001307 params.type =
1308 iwl_mvm_get_scan_type(mvm,
1309 vif->type == NL80211_IFTYPE_P2P_DEVICE);
Luciano Coelhocf5d3172015-04-16 20:13:28 +03001310
Luciano Coelho283c2492015-04-17 11:18:46 +03001311 /* In theory, LMAC scans can handle a 32-bit delay, but since
1312 * waiting for over 18 hours to start the scan is a bit silly
1313 * and to keep it aligned with UMAC scans (which only support
1314 * 16-bit delays), trim it down to 16-bits.
1315 */
1316 if (req->delay > U16_MAX) {
1317 IWL_DEBUG_SCAN(mvm,
1318 "delay value is > 16-bits, set to max possible\n");
1319 params.delay = U16_MAX;
1320 } else {
1321 params.delay = req->delay;
1322 }
1323
Luciano Coelho65ff5562015-03-20 13:35:47 +02001324 ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
1325 if (ret)
1326 return ret;
1327
Luciano Coelho45d1b122015-04-15 16:34:13 +03001328 iwl_mvm_build_scan_probe(mvm, vif, ies, &params);
1329
Johannes Berg859d9142015-06-01 17:11:11 +02001330 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
Johannes Berg88742c92015-06-30 15:31:22 +02001331 hcmd.id = iwl_cmd_id(SCAN_REQ_UMAC, IWL_ALWAYS_LONG_GROUP, 0);
Luciano Coelho6185af2a2015-05-07 11:13:24 +03001332 ret = iwl_mvm_scan_umac(mvm, vif, &params, IWL_MVM_SCAN_SCHED);
Luciano Coelho65ff5562015-03-20 13:35:47 +02001333 } else {
Luciano Coelho8df3e682015-04-01 17:37:44 +03001334 hcmd.id = SCAN_OFFLOAD_REQUEST_CMD;
Luciano Coelho7d7de1e2015-04-17 09:53:55 +03001335 ret = iwl_mvm_scan_lmac(mvm, vif, &params);
Luciano Coelho8df3e682015-04-01 17:37:44 +03001336 }
1337
1338 if (ret)
1339 return ret;
1340
1341 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1342 if (!ret) {
1343 IWL_DEBUG_SCAN(mvm,
1344 "Sched scan request was sent successfully\n");
1345 mvm->scan_status |= type;
1346 } else {
1347 /* If the scan failed, it usually means that the FW was unable
1348 * to allocate the time events. Warn on it, but maybe we
1349 * should try to send the command again with different params.
1350 */
1351 IWL_ERR(mvm, "Sched scan failed! ret %d\n", ret);
Luciano Coelho65ff5562015-03-20 13:35:47 +02001352 }
1353
1354 return ret;
1355}
1356
Johannes Berg04168412015-06-23 21:22:09 +02001357void iwl_mvm_rx_umac_scan_complete_notif(struct iwl_mvm *mvm,
1358 struct iwl_rx_cmd_buffer *rxb)
David Spinadeld2496222014-05-20 12:46:37 +03001359{
1360 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1361 struct iwl_umac_scan_complete *notif = (void *)pkt->data;
1362 u32 uid = __le32_to_cpu(notif->uid);
Luciano Coelho8d14ccd2015-05-07 17:05:30 +03001363 bool aborted = (notif->status == IWL_SCAN_OFFLOAD_ABORTED);
David Spinadeld2496222014-05-20 12:46:37 +03001364
Luciano Coelho8d14ccd2015-05-07 17:05:30 +03001365 if (WARN_ON(!(mvm->scan_uid_status[uid] & mvm->scan_status)))
Johannes Berg04168412015-06-23 21:22:09 +02001366 return;
David Spinadeld2496222014-05-20 12:46:37 +03001367
Luciano Coelho8d14ccd2015-05-07 17:05:30 +03001368 /* if the scan is already stopping, we don't need to notify mac80211 */
1369 if (mvm->scan_uid_status[uid] == IWL_MVM_SCAN_REGULAR) {
1370 ieee80211_scan_completed(mvm->hw, aborted);
1371 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
1372 } else if (mvm->scan_uid_status[uid] == IWL_MVM_SCAN_SCHED) {
1373 ieee80211_sched_scan_stopped(mvm->hw);
1374 }
1375
1376 mvm->scan_status &= ~mvm->scan_uid_status[uid];
David Spinadeld2496222014-05-20 12:46:37 +03001377 IWL_DEBUG_SCAN(mvm,
Ayala Bekera7b3bc92015-08-20 04:00:38 +03001378 "Scan completed, uid %u type %u, status %s, EBS status %s\n",
Luciano Coelho8d14ccd2015-05-07 17:05:30 +03001379 uid, mvm->scan_uid_status[uid],
David Spinadeld2496222014-05-20 12:46:37 +03001380 notif->status == IWL_SCAN_OFFLOAD_COMPLETED ?
1381 "completed" : "aborted",
Ayala Bekera7b3bc92015-08-20 04:00:38 +03001382 iwl_mvm_ebs_status_str(notif->ebs_status));
1383 IWL_DEBUG_SCAN(mvm,
1384 "Last line %d, Last iteration %d, Time from last iteration %d\n",
Ayala Beker1a84e772015-07-22 13:54:31 +03001385 notif->last_schedule, notif->last_iter,
1386 __le32_to_cpu(notif->time_from_last_iter));
David Spinadeld2496222014-05-20 12:46:37 +03001387
David Spinadelf0bf8592015-05-20 11:56:59 +03001388 if (notif->ebs_status != IWL_SCAN_EBS_SUCCESS &&
1389 notif->ebs_status != IWL_SCAN_EBS_INACTIVE)
Haim Dreyfuss5a4b2af2015-01-13 11:54:51 +02001390 mvm->last_ebs_successful = false;
1391
Luciano Coelho6185af2a2015-05-07 11:13:24 +03001392 mvm->scan_uid_status[uid] = 0;
David Spinadeld2496222014-05-20 12:46:37 +03001393}
1394
Johannes Berg04168412015-06-23 21:22:09 +02001395void iwl_mvm_rx_umac_scan_iter_complete_notif(struct iwl_mvm *mvm,
1396 struct iwl_rx_cmd_buffer *rxb)
Avraham Sternee9219b2015-03-23 15:09:27 +02001397{
1398 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1399 struct iwl_umac_scan_iter_complete_notif *notif = (void *)pkt->data;
1400 u8 buf[256];
1401
1402 IWL_DEBUG_SCAN(mvm,
1403 "UMAC Scan iteration complete: status=0x%x scanned_channels=%d channels list: %s\n",
1404 notif->status, notif->scanned_channels,
1405 iwl_mvm_dump_channel_list(notif->results,
1406 notif->scanned_channels, buf,
1407 sizeof(buf)));
Avraham Sternee9219b2015-03-23 15:09:27 +02001408}
1409
Luciano Coelho434f3c12015-05-07 14:41:44 +03001410static int iwl_mvm_umac_scan_abort(struct iwl_mvm *mvm, int type)
David Spinadeld2496222014-05-20 12:46:37 +03001411{
Johannes Berg88742c92015-06-30 15:31:22 +02001412 struct iwl_umac_scan_abort cmd = {};
Luciano Coelho434f3c12015-05-07 14:41:44 +03001413 int uid, ret;
David Spinadeld2496222014-05-20 12:46:37 +03001414
1415 lockdep_assert_held(&mvm->mutex);
1416
Luciano Coelho434f3c12015-05-07 14:41:44 +03001417 /* We should always get a valid index here, because we already
1418 * checked that this type of scan was running in the generic
1419 * code.
1420 */
1421 uid = iwl_mvm_scan_uid_by_status(mvm, type);
1422 if (WARN_ON_ONCE(uid < 0))
1423 return uid;
1424
1425 cmd.uid = cpu_to_le32(uid);
1426
David Spinadeld2496222014-05-20 12:46:37 +03001427 IWL_DEBUG_SCAN(mvm, "Sending scan abort, uid %u\n", uid);
1428
Johannes Berg88742c92015-06-30 15:31:22 +02001429 ret = iwl_mvm_send_cmd_pdu(mvm,
1430 iwl_cmd_id(SCAN_ABORT_UMAC,
1431 IWL_ALWAYS_LONG_GROUP, 0),
1432 0, sizeof(cmd), &cmd);
Luciano Coelho434f3c12015-05-07 14:41:44 +03001433 if (!ret)
Luciano Coelho8d14ccd2015-05-07 17:05:30 +03001434 mvm->scan_uid_status[uid] = type << IWL_MVM_SCAN_STOPPING_SHIFT;
Luciano Coelho434f3c12015-05-07 14:41:44 +03001435
1436 return ret;
David Spinadeld2496222014-05-20 12:46:37 +03001437}
1438
Luciano Coelhof2461792015-05-07 15:23:19 +03001439static int iwl_mvm_scan_stop_wait(struct iwl_mvm *mvm, int type)
David Spinadeld2496222014-05-20 12:46:37 +03001440{
1441 struct iwl_notification_wait wait_scan_done;
Sara Sharon6eb031d2015-07-13 14:50:47 +03001442 static const u16 scan_done_notif[] = { SCAN_COMPLETE_UMAC,
Luciano Coelhof2461792015-05-07 15:23:19 +03001443 SCAN_OFFLOAD_COMPLETE, };
Luciano Coelho434f3c12015-05-07 14:41:44 +03001444 int ret;
David Spinadeld2496222014-05-20 12:46:37 +03001445
Luciano Coelhof2461792015-05-07 15:23:19 +03001446 lockdep_assert_held(&mvm->mutex);
1447
David Spinadeld2496222014-05-20 12:46:37 +03001448 iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_done,
1449 scan_done_notif,
1450 ARRAY_SIZE(scan_done_notif),
Luciano Coelho434f3c12015-05-07 14:41:44 +03001451 NULL, NULL);
David Spinadeld2496222014-05-20 12:46:37 +03001452
1453 IWL_DEBUG_SCAN(mvm, "Preparing to stop scan, type %x\n", type);
1454
Johannes Berg859d9142015-06-01 17:11:11 +02001455 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
Luciano Coelhof2461792015-05-07 15:23:19 +03001456 ret = iwl_mvm_umac_scan_abort(mvm, type);
1457 else
1458 ret = iwl_mvm_lmac_scan_abort(mvm);
1459
David Spinadeld2496222014-05-20 12:46:37 +03001460 if (ret) {
Luciano Coelho434f3c12015-05-07 14:41:44 +03001461 IWL_DEBUG_SCAN(mvm, "couldn't stop scan type %d\n", type);
David Spinadeld2496222014-05-20 12:46:37 +03001462 iwl_remove_notification(&mvm->notif_wait, &wait_scan_done);
1463 return ret;
1464 }
1465
1466 ret = iwl_wait_notification(&mvm->notif_wait, &wait_scan_done, 1 * HZ);
David Spinadeld2496222014-05-20 12:46:37 +03001467
1468 return ret;
1469}
1470
1471int iwl_mvm_scan_size(struct iwl_mvm *mvm)
1472{
Johannes Berg859d9142015-06-01 17:11:11 +02001473 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
David Spinadeld2496222014-05-20 12:46:37 +03001474 return sizeof(struct iwl_scan_req_umac) +
1475 sizeof(struct iwl_scan_channel_cfg_umac) *
1476 mvm->fw->ucode_capa.n_scan_channels +
1477 sizeof(struct iwl_scan_req_umac_tail);
1478
Luciano Coelho65ff5562015-03-20 13:35:47 +02001479 return sizeof(struct iwl_scan_req_lmac) +
Luciano Coelho1f940382015-02-10 13:03:38 +02001480 sizeof(struct iwl_scan_channel_cfg_lmac) *
1481 mvm->fw->ucode_capa.n_scan_channels +
1482 sizeof(struct iwl_scan_probe_req);
David Spinadeld2496222014-05-20 12:46:37 +03001483}
David Spinadel4ffb3652015-03-10 10:06:02 +02001484
1485/*
1486 * This function is used in nic restart flow, to inform mac80211 about scans
1487 * that was aborted by restart flow or by an assert.
1488 */
1489void iwl_mvm_report_scan_aborted(struct iwl_mvm *mvm)
1490{
Johannes Berg859d9142015-06-01 17:11:11 +02001491 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
Luciano Coelho6185af2a2015-05-07 11:13:24 +03001492 int uid, i;
Alexander Bondar963221b2015-03-26 11:07:35 +02001493
Luciano Coelho6185af2a2015-05-07 11:13:24 +03001494 uid = iwl_mvm_scan_uid_by_status(mvm, IWL_MVM_SCAN_REGULAR);
1495 if (uid >= 0) {
David Spinadel4ffb3652015-03-10 10:06:02 +02001496 ieee80211_scan_completed(mvm->hw, true);
Luciano Coelho6185af2a2015-05-07 11:13:24 +03001497 mvm->scan_uid_status[uid] = 0;
Alexander Bondar963221b2015-03-26 11:07:35 +02001498 }
Luciano Coelho6185af2a2015-05-07 11:13:24 +03001499 uid = iwl_mvm_scan_uid_by_status(mvm, IWL_MVM_SCAN_SCHED);
1500 if (uid >= 0 && !mvm->restart_fw) {
David Spinadel4ffb3652015-03-10 10:06:02 +02001501 ieee80211_sched_scan_stopped(mvm->hw);
Luciano Coelho6185af2a2015-05-07 11:13:24 +03001502 mvm->scan_uid_status[uid] = 0;
Alexander Bondar963221b2015-03-26 11:07:35 +02001503 }
1504
1505 /* We shouldn't have any UIDs still set. Loop over all the
1506 * UIDs to make sure there's nothing left there and warn if
1507 * any is found.
1508 */
Luciano Coelho507e4cd2015-03-19 22:58:33 +02001509 for (i = 0; i < mvm->max_scans; i++) {
Luciano Coelho6185af2a2015-05-07 11:13:24 +03001510 if (WARN_ONCE(mvm->scan_uid_status[i],
1511 "UMAC scan UID %d status was not cleaned\n",
1512 i))
1513 mvm->scan_uid_status[i] = 0;
Alexander Bondar963221b2015-03-26 11:07:35 +02001514 }
David Spinadel4ffb3652015-03-10 10:06:02 +02001515 } else {
Luciano Coelho9af91f42015-02-10 10:42:26 +02001516 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
David Spinadel4ffb3652015-03-10 10:06:02 +02001517 ieee80211_scan_completed(mvm->hw, true);
Luciano Coelho9af91f42015-02-10 10:42:26 +02001518
1519 /* Sched scan will be restarted by mac80211 in
1520 * restart_hw, so do not report if FW is about to be
1521 * restarted.
1522 */
1523 if ((mvm->scan_status & IWL_MVM_SCAN_SCHED) && !mvm->restart_fw)
1524 ieee80211_sched_scan_stopped(mvm->hw);
David Spinadel4ffb3652015-03-10 10:06:02 +02001525 }
1526}
Luciano Coelhodfbf1562015-05-05 11:21:34 +03001527
Luciano Coelhoc7d42482015-05-07 16:00:26 +03001528int iwl_mvm_scan_stop(struct iwl_mvm *mvm, int type, bool notify)
Luciano Coelhodfbf1562015-05-05 11:21:34 +03001529{
1530 int ret;
1531
Luciano Coelhoc7d42482015-05-07 16:00:26 +03001532 if (!(mvm->scan_status & type))
Luciano Coelhodfbf1562015-05-05 11:21:34 +03001533 return 0;
1534
1535 if (iwl_mvm_is_radio_killed(mvm)) {
1536 ret = 0;
1537 goto out;
1538 }
1539
Luciano Coelhoc7d42482015-05-07 16:00:26 +03001540 ret = iwl_mvm_scan_stop_wait(mvm, type);
Luciano Coelhodfbf1562015-05-05 11:21:34 +03001541 if (!ret)
Luciano Coelhoc7d42482015-05-07 16:00:26 +03001542 mvm->scan_status |= type << IWL_MVM_SCAN_STOPPING_SHIFT;
Luciano Coelhodfbf1562015-05-05 11:21:34 +03001543out:
1544 /* Clear the scan status so the next scan requests will
1545 * succeed and mark the scan as stopping, so that the Rx
1546 * handler doesn't do anything, as the scan was stopped from
Luciano Coelhoc7d42482015-05-07 16:00:26 +03001547 * above.
Luciano Coelhodfbf1562015-05-05 11:21:34 +03001548 */
Luciano Coelhoc7d42482015-05-07 16:00:26 +03001549 mvm->scan_status &= ~type;
Luciano Coelhodfbf1562015-05-05 11:21:34 +03001550
Luciano Coelhoc7d42482015-05-07 16:00:26 +03001551 if (type == IWL_MVM_SCAN_REGULAR) {
1552 /* Since the rx handler won't do anything now, we have
1553 * to release the scan reference here.
1554 */
1555 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
1556 if (notify)
1557 ieee80211_scan_completed(mvm->hw, true);
1558 } else if (notify) {
Luciano Coelhodfbf1562015-05-05 11:21:34 +03001559 ieee80211_sched_scan_stopped(mvm->hw);
Luciano Coelhoc7d42482015-05-07 16:00:26 +03001560 }
Luciano Coelhodfbf1562015-05-05 11:21:34 +03001561
1562 return ret;
1563}