blob: d01954dcc75d2a90d4dc9566b47156d44868aa9f [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.
Johannes Berg8ca151b2013-01-24 14:25:36 +01009 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020025 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010026 *
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020033 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8ca151b2013-01-24 14:25:36 +010034 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *
62 *****************************************************************************/
63
64#include <linux/etherdevice.h>
65#include <net/mac80211.h>
66
67#include "mvm.h"
68#include "iwl-eeprom-parse.h"
69#include "fw-api-scan.h"
70
71#define IWL_PLCP_QUIET_THRESH 1
72#define IWL_ACTIVE_QUIET_TIME 10
Alexander Bondar8a110d92014-03-12 17:31:19 +020073
74struct iwl_mvm_scan_params {
75 u32 max_out_time;
76 u32 suspend_time;
Alexander Bondar50df8a32014-03-12 20:30:51 +020077 bool passive_fragmented;
78 struct _dwell {
79 u16 passive;
80 u16 active;
81 } dwell[IEEE80211_NUM_BANDS];
Alexander Bondar8a110d92014-03-12 17:31:19 +020082};
Johannes Berg8ca151b2013-01-24 14:25:36 +010083
84static inline __le16 iwl_mvm_scan_rx_chain(struct iwl_mvm *mvm)
85{
86 u16 rx_chain;
Oren Givon91b05d12013-08-19 08:36:48 +030087 u8 rx_ant;
Johannes Berg8ca151b2013-01-24 14:25:36 +010088
Oren Givon91b05d12013-08-19 08:36:48 +030089 if (mvm->scan_rx_ant != ANT_NONE)
90 rx_ant = mvm->scan_rx_ant;
91 else
Johannes Berg4ed735e2014-02-12 21:47:44 +010092 rx_ant = mvm->fw->valid_rx_ant;
Johannes Berg8ca151b2013-01-24 14:25:36 +010093 rx_chain = rx_ant << PHY_RX_CHAIN_VALID_POS;
94 rx_chain |= rx_ant << PHY_RX_CHAIN_FORCE_MIMO_SEL_POS;
95 rx_chain |= rx_ant << PHY_RX_CHAIN_FORCE_SEL_POS;
96 rx_chain |= 0x1 << PHY_RX_CHAIN_DRIVER_FORCE_POS;
97 return cpu_to_le16(rx_chain);
98}
99
David Spinadelfb98be52014-05-04 12:51:10 +0300100static __le32 iwl_mvm_scan_rxon_flags(enum ieee80211_band band)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100101{
David Spinadelfb98be52014-05-04 12:51:10 +0300102 if (band == IEEE80211_BAND_2GHZ)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100103 return cpu_to_le32(PHY_BAND_24);
104 else
105 return cpu_to_le32(PHY_BAND_5);
106}
107
108static inline __le32
109iwl_mvm_scan_rate_n_flags(struct iwl_mvm *mvm, enum ieee80211_band band,
110 bool no_cck)
111{
112 u32 tx_ant;
113
114 mvm->scan_last_antenna_idx =
Johannes Berg4ed735e2014-02-12 21:47:44 +0100115 iwl_mvm_next_antenna(mvm, mvm->fw->valid_tx_ant,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100116 mvm->scan_last_antenna_idx);
117 tx_ant = BIT(mvm->scan_last_antenna_idx) << RATE_MCS_ANT_POS;
118
119 if (band == IEEE80211_BAND_2GHZ && !no_cck)
120 return cpu_to_le32(IWL_RATE_1M_PLCP | RATE_MCS_CCK_MSK |
121 tx_ant);
122 else
123 return cpu_to_le32(IWL_RATE_6M_PLCP | tx_ant);
124}
125
126/*
127 * We insert the SSIDs in an inverted order, because the FW will
128 * invert it back. The most prioritized SSID, which is first in the
129 * request list, is not copied here, but inserted directly to the probe
130 * request.
131 */
David Spinadelfb98be52014-05-04 12:51:10 +0300132static void iwl_mvm_scan_fill_ssids(struct iwl_ssid_ie *cmd_ssid,
133 struct cfg80211_ssid *ssids,
134 int n_ssids, int first)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100135{
136 int fw_idx, req_idx;
137
David Spinadelfb98be52014-05-04 12:51:10 +0300138 for (req_idx = n_ssids - 1, fw_idx = 0; req_idx >= first;
David Spinadelfe04e832013-07-04 15:17:48 +0300139 req_idx--, fw_idx++) {
David Spinadelfb98be52014-05-04 12:51:10 +0300140 cmd_ssid[fw_idx].id = WLAN_EID_SSID;
141 cmd_ssid[fw_idx].len = ssids[req_idx].ssid_len;
142 memcpy(cmd_ssid[fw_idx].ssid,
143 ssids[req_idx].ssid,
144 ssids[req_idx].ssid_len);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100145 }
146}
147
148/*
149 * If req->n_ssids > 0, it means we should do an active scan.
150 * In case of active scan w/o directed scan, we receive a zero-length SSID
151 * just to notify that this scan is active and not passive.
152 * In order to notify the FW of the number of SSIDs we wish to scan (including
153 * the zero-length one), we need to set the corresponding bits in chan->type,
David Spinadel20f1a5d2013-08-21 09:14:27 +0300154 * one for each SSID, and set the active bit (first). If the first SSID is
155 * already included in the probe template, so we need to set only
156 * req->n_ssids - 1 bits in addition to the first bit.
Johannes Berg8ca151b2013-01-24 14:25:36 +0100157 */
158static u16 iwl_mvm_get_active_dwell(enum ieee80211_band band, int n_ssids)
159{
160 if (band == IEEE80211_BAND_2GHZ)
161 return 30 + 3 * (n_ssids + 1);
162 return 20 + 2 * (n_ssids + 1);
163}
164
165static u16 iwl_mvm_get_passive_dwell(enum ieee80211_band band)
166{
167 return band == IEEE80211_BAND_2GHZ ? 100 + 20 : 100 + 10;
168}
169
170static void iwl_mvm_scan_fill_channels(struct iwl_scan_cmd *cmd,
David Spinadel20f1a5d2013-08-21 09:14:27 +0300171 struct cfg80211_scan_request *req,
Alexander Bondar50df8a32014-03-12 20:30:51 +0200172 bool basic_ssid,
173 struct iwl_mvm_scan_params *params)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100174{
Johannes Berg8ca151b2013-01-24 14:25:36 +0100175 struct iwl_scan_channel *chan = (struct iwl_scan_channel *)
176 (cmd->data + le16_to_cpu(cmd->tx_cmd.len));
177 int i;
David Spinadel20f1a5d2013-08-21 09:14:27 +0300178 int type = BIT(req->n_ssids) - 1;
Alexander Bondar50df8a32014-03-12 20:30:51 +0200179 enum ieee80211_band band = req->channels[0]->band;
David Spinadel20f1a5d2013-08-21 09:14:27 +0300180
181 if (!basic_ssid)
182 type |= BIT(req->n_ssids);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100183
184 for (i = 0; i < cmd->channel_count; i++) {
185 chan->channel = cpu_to_le16(req->channels[i]->hw_value);
David Spinadel20f1a5d2013-08-21 09:14:27 +0300186 chan->type = cpu_to_le32(type);
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200187 if (req->channels[i]->flags & IEEE80211_CHAN_NO_IR)
David Spinadelbb963c42013-07-23 14:13:32 +0300188 chan->type &= cpu_to_le32(~SCAN_CHANNEL_TYPE_ACTIVE);
Alexander Bondar50df8a32014-03-12 20:30:51 +0200189 chan->active_dwell = cpu_to_le16(params->dwell[band].active);
190 chan->passive_dwell = cpu_to_le16(params->dwell[band].passive);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100191 chan->iteration_count = cpu_to_le16(1);
192 chan++;
193 }
194}
195
196/*
197 * Fill in probe request with the following parameters:
198 * TA is our vif HW address, which mac80211 ensures we have.
199 * Packet is broadcasted, so this is both SA and DA.
200 * The probe request IE is made out of two: first comes the most prioritized
201 * SSID if a directed scan is requested. Second comes whatever extra
202 * information was given to us as the scan request IE.
203 */
204static u16 iwl_mvm_fill_probe_req(struct ieee80211_mgmt *frame, const u8 *ta,
205 int n_ssids, const u8 *ssid, int ssid_len,
David Spinadel633e2712014-02-06 16:15:23 +0200206 const u8 *band_ie, int band_ie_len,
207 const u8 *common_ie, int common_ie_len,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100208 int left)
209{
210 int len = 0;
211 u8 *pos = NULL;
212
213 /* Make sure there is enough space for the probe request,
214 * two mandatory IEs and the data */
215 left -= 24;
216 if (left < 0)
217 return 0;
218
219 frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
220 eth_broadcast_addr(frame->da);
221 memcpy(frame->sa, ta, ETH_ALEN);
222 eth_broadcast_addr(frame->bssid);
223 frame->seq_ctrl = 0;
224
225 len += 24;
226
227 /* for passive scans, no need to fill anything */
228 if (n_ssids == 0)
229 return (u16)len;
230
231 /* points to the payload of the request */
232 pos = &frame->u.probe_req.variable[0];
233
234 /* fill in our SSID IE */
235 left -= ssid_len + 2;
236 if (left < 0)
237 return 0;
238 *pos++ = WLAN_EID_SSID;
239 *pos++ = ssid_len;
240 if (ssid && ssid_len) { /* ssid_len may be == 0 even if ssid is valid */
241 memcpy(pos, ssid, ssid_len);
242 pos += ssid_len;
243 }
244
245 len += ssid_len + 2;
246
David Spinadel633e2712014-02-06 16:15:23 +0200247 if (WARN_ON(left < band_ie_len + common_ie_len))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100248 return len;
249
David Spinadel633e2712014-02-06 16:15:23 +0200250 if (band_ie && band_ie_len) {
251 memcpy(pos, band_ie, band_ie_len);
252 pos += band_ie_len;
253 len += band_ie_len;
254 }
255
256 if (common_ie && common_ie_len) {
257 memcpy(pos, common_ie, common_ie_len);
258 pos += common_ie_len;
259 len += common_ie_len;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100260 }
261
262 return (u16)len;
263}
264
Alexander Bondar8a110d92014-03-12 17:31:19 +0200265static void iwl_mvm_scan_condition_iterator(void *data, u8 *mac,
266 struct ieee80211_vif *vif)
Haim Dreyfuss61f63252013-11-03 23:02:59 +0200267{
Alexander Bondar8a110d92014-03-12 17:31:19 +0200268 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
269 bool *global_bound = data;
Haim Dreyfuss61f63252013-11-03 23:02:59 +0200270
Alexander Bondar8a110d92014-03-12 17:31:19 +0200271 if (mvmvif->phy_ctxt && mvmvif->phy_ctxt->id < MAX_PHYS)
272 *global_bound = true;
273}
274
275static void iwl_mvm_scan_calc_params(struct iwl_mvm *mvm,
Alexander Bondar50df8a32014-03-12 20:30:51 +0200276 struct ieee80211_vif *vif,
Johannes Bergab480032014-06-04 10:13:50 +0200277 int n_ssids, u32 flags,
Alexander Bondar8a110d92014-03-12 17:31:19 +0200278 struct iwl_mvm_scan_params *params)
279{
280 bool global_bound = false;
Alexander Bondar50df8a32014-03-12 20:30:51 +0200281 enum ieee80211_band band;
David Spinadel2ce89cd2014-07-22 13:11:18 +0300282 u8 frag_passive_dwell = 0;
Alexander Bondar8a110d92014-03-12 17:31:19 +0200283
284 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
285 IEEE80211_IFACE_ITER_NORMAL,
286 iwl_mvm_scan_condition_iterator,
287 &global_bound);
Alexander Bondar8a110d92014-03-12 17:31:19 +0200288
Alexander Bondaref67f18d2014-03-30 10:47:08 +0300289 if (!global_bound)
290 goto not_bound;
291
David Spinadel2ce89cd2014-07-22 13:11:18 +0300292 params->suspend_time = 30;
293 params->max_out_time = 170;
Alexander Bondaref67f18d2014-03-30 10:47:08 +0300294
295 if (iwl_mvm_low_latency(mvm)) {
David Spinadel2ce89cd2014-07-22 13:11:18 +0300296 if (mvm->fw->ucode_capa.api[0] &
297 IWL_UCODE_TLV_API_FRAGMENTED_SCAN) {
298 params->suspend_time = 105;
299 params->max_out_time = 70;
300 frag_passive_dwell = 20;
301 } else {
302 params->suspend_time = 120;
303 params->max_out_time = 120;
304 }
305 }
306
307 if (frag_passive_dwell && (mvm->fw->ucode_capa.api[0] &
308 IWL_UCODE_TLV_API_FRAGMENTED_SCAN)) {
309 /*
310 * P2P device scan should not be fragmented to avoid negative
311 * impact on P2P device discovery. Configure max_out_time to be
312 * equal to dwell time on passive channel. Take a longest
313 * possible value, one that corresponds to 2GHz band
314 */
315 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
316 u32 passive_dwell =
317 iwl_mvm_get_passive_dwell(IEEE80211_BAND_2GHZ);
318 params->max_out_time = passive_dwell;
319 } else {
320 params->passive_fragmented = true;
321 }
Alexander Bondar50df8a32014-03-12 20:30:51 +0200322 }
323
Johannes Bergab480032014-06-04 10:13:50 +0200324 if (flags & NL80211_SCAN_FLAG_LOW_PRIORITY)
325 params->max_out_time = 200;
326
Alexander Bondaref67f18d2014-03-30 10:47:08 +0300327not_bound:
328
Alexander Bondar50df8a32014-03-12 20:30:51 +0200329 for (band = IEEE80211_BAND_2GHZ; band < IEEE80211_NUM_BANDS; band++) {
David Spinadel2ce89cd2014-07-22 13:11:18 +0300330 if (params->passive_fragmented)
331 params->dwell[band].passive = frag_passive_dwell;
332 else
333 params->dwell[band].passive =
334 iwl_mvm_get_passive_dwell(band);
Alexander Bondar50df8a32014-03-12 20:30:51 +0200335 params->dwell[band].active = iwl_mvm_get_active_dwell(band,
336 n_ssids);
337 }
Haim Dreyfuss61f63252013-11-03 23:02:59 +0200338}
339
Johannes Berg8ca151b2013-01-24 14:25:36 +0100340int iwl_mvm_scan_request(struct iwl_mvm *mvm,
341 struct ieee80211_vif *vif,
342 struct cfg80211_scan_request *req)
343{
344 struct iwl_host_cmd hcmd = {
345 .id = SCAN_REQUEST_CMD,
346 .len = { 0, },
347 .data = { mvm->scan_cmd, },
Johannes Berg8ca151b2013-01-24 14:25:36 +0100348 .dataflags = { IWL_HCMD_DFL_NOCOPY, },
349 };
350 struct iwl_scan_cmd *cmd = mvm->scan_cmd;
351 int ret;
352 u32 status;
353 int ssid_len = 0;
354 u8 *ssid = NULL;
David Spinadel20f1a5d2013-08-21 09:14:27 +0300355 bool basic_ssid = !(mvm->fw->ucode_capa.flags &
356 IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID);
Alexander Bondar8a110d92014-03-12 17:31:19 +0200357 struct iwl_mvm_scan_params params = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +0100358
359 lockdep_assert_held(&mvm->mutex);
Emmanuel Grumbach748fa67c2014-03-27 10:06:29 +0200360
361 /* we should have failed registration if scan_cmd was NULL */
362 if (WARN_ON(mvm->scan_cmd == NULL))
363 return -ENOMEM;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100364
365 IWL_DEBUG_SCAN(mvm, "Handling mac80211 scan request\n");
366 mvm->scan_status = IWL_MVM_SCAN_OS;
David Spinadel05646792014-06-02 09:59:49 +0300367 memset(cmd, 0, ksize(cmd));
Alexander Bondar8a110d92014-03-12 17:31:19 +0200368
Johannes Berg8ca151b2013-01-24 14:25:36 +0100369 cmd->channel_count = (u8)req->n_channels;
370 cmd->quiet_time = cpu_to_le16(IWL_ACTIVE_QUIET_TIME);
371 cmd->quiet_plcp_th = cpu_to_le16(IWL_PLCP_QUIET_THRESH);
372 cmd->rxchain_sel_flags = iwl_mvm_scan_rx_chain(mvm);
Alexander Bondar8a110d92014-03-12 17:31:19 +0200373
Johannes Bergab480032014-06-04 10:13:50 +0200374 iwl_mvm_scan_calc_params(mvm, vif, req->n_ssids, req->flags, &params);
Alexander Bondar8a110d92014-03-12 17:31:19 +0200375 cmd->max_out_time = cpu_to_le32(params.max_out_time);
376 cmd->suspend_time = cpu_to_le32(params.suspend_time);
Alexander Bondar50df8a32014-03-12 20:30:51 +0200377 if (params.passive_fragmented)
378 cmd->scan_flags |= SCAN_FLAGS_FRAGMENTED_SCAN;
Alexander Bondar8a110d92014-03-12 17:31:19 +0200379
David Spinadelfb98be52014-05-04 12:51:10 +0300380 cmd->rxon_flags = iwl_mvm_scan_rxon_flags(req->channels[0]->band);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100381 cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP |
382 MAC_FILTER_IN_BEACON);
Ilan Peerd91b06d2013-02-11 08:50:45 +0200383
384 if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
385 cmd->type = cpu_to_le32(SCAN_TYPE_DISCOVERY_FORCED);
386 else
387 cmd->type = cpu_to_le32(SCAN_TYPE_FORCED);
388
Johannes Berg8ca151b2013-01-24 14:25:36 +0100389 cmd->repeats = cpu_to_le32(1);
390
391 /*
392 * If the user asked for passive scan, don't change to active scan if
393 * you see any activity on the channel - remain passive.
394 */
395 if (req->n_ssids > 0) {
396 cmd->passive2active = cpu_to_le16(1);
David Spinadel26e05cc2013-07-08 13:12:29 +0300397 cmd->scan_flags |= SCAN_FLAGS_PASSIVE2ACTIVE;
David Spinadel20f1a5d2013-08-21 09:14:27 +0300398 if (basic_ssid) {
399 ssid = req->ssids[0].ssid;
400 ssid_len = req->ssids[0].ssid_len;
401 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100402 } else {
403 cmd->passive2active = 0;
David Spinadel26e05cc2013-07-08 13:12:29 +0300404 cmd->scan_flags &= ~SCAN_FLAGS_PASSIVE2ACTIVE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100405 }
406
David Spinadelfb98be52014-05-04 12:51:10 +0300407 iwl_mvm_scan_fill_ssids(cmd->direct_scan, req->ssids, req->n_ssids,
408 basic_ssid ? 1 : 0);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100409
Emmanuel Grumbach8e2a8662014-01-28 12:27:31 +0200410 cmd->tx_cmd.tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL |
411 TX_CMD_FLG_BT_DIS);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100412 cmd->tx_cmd.sta_id = mvm->aux_sta.sta_id;
413 cmd->tx_cmd.life_time = cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE);
414 cmd->tx_cmd.rate_n_flags =
415 iwl_mvm_scan_rate_n_flags(mvm, req->channels[0]->band,
416 req->no_cck);
417
418 cmd->tx_cmd.len =
419 cpu_to_le16(iwl_mvm_fill_probe_req(
420 (struct ieee80211_mgmt *)cmd->data,
421 vif->addr,
422 req->n_ssids, ssid, ssid_len,
David Spinadel633e2712014-02-06 16:15:23 +0200423 req->ie, req->ie_len, NULL, 0,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100424 mvm->fw->ucode_capa.max_probe_length));
425
Alexander Bondar50df8a32014-03-12 20:30:51 +0200426 iwl_mvm_scan_fill_channels(cmd, req, basic_ssid, &params);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100427
428 cmd->len = cpu_to_le16(sizeof(struct iwl_scan_cmd) +
429 le16_to_cpu(cmd->tx_cmd.len) +
430 (cmd->channel_count * sizeof(struct iwl_scan_channel)));
431 hcmd.len[0] = le16_to_cpu(cmd->len);
432
433 status = SCAN_RESPONSE_OK;
434 ret = iwl_mvm_send_cmd_status(mvm, &hcmd, &status);
435 if (!ret && status == SCAN_RESPONSE_OK) {
436 IWL_DEBUG_SCAN(mvm, "Scan request was sent successfully\n");
437 } else {
438 /*
439 * If the scan failed, it usually means that the FW was unable
440 * to allocate the time events. Warn on it, but maybe we
441 * should try to send the command again with different params.
442 */
443 IWL_ERR(mvm, "Scan failed! status 0x%x ret %d\n",
444 status, ret);
445 mvm->scan_status = IWL_MVM_SCAN_NONE;
446 ret = -EIO;
447 }
448 return ret;
449}
450
451int iwl_mvm_rx_scan_response(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb,
452 struct iwl_device_cmd *cmd)
453{
454 struct iwl_rx_packet *pkt = rxb_addr(rxb);
455 struct iwl_cmd_response *resp = (void *)pkt->data;
456
457 IWL_DEBUG_SCAN(mvm, "Scan response received. status 0x%x\n",
458 le32_to_cpu(resp->status));
459 return 0;
460}
461
462int iwl_mvm_rx_scan_complete(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb,
463 struct iwl_device_cmd *cmd)
464{
465 struct iwl_rx_packet *pkt = rxb_addr(rxb);
466 struct iwl_scan_complete_notif *notif = (void *)pkt->data;
467
Arik Nemtsov91b80252014-02-10 12:49:39 +0200468 lockdep_assert_held(&mvm->mutex);
469
Johannes Berg8ca151b2013-01-24 14:25:36 +0100470 IWL_DEBUG_SCAN(mvm, "Scan complete: status=0x%x scanned channels=%d\n",
471 notif->status, notif->scanned_channels);
472
Arik Nemtsov91b80252014-02-10 12:49:39 +0200473 if (mvm->scan_status == IWL_MVM_SCAN_OS)
474 mvm->scan_status = IWL_MVM_SCAN_NONE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100475 ieee80211_scan_completed(mvm->hw, notif->status != SCAN_COMP_STATUS_OK);
476
Arik Nemtsov519e2022013-10-17 17:51:35 +0300477 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
478
Johannes Berg8ca151b2013-01-24 14:25:36 +0100479 return 0;
480}
481
David Spinadelfb98be52014-05-04 12:51:10 +0300482int iwl_mvm_rx_scan_offload_results(struct iwl_mvm *mvm,
483 struct iwl_rx_cmd_buffer *rxb,
484 struct iwl_device_cmd *cmd)
David Spinadel35a000b2013-08-28 09:29:43 +0300485{
486 struct iwl_rx_packet *pkt = rxb_addr(rxb);
David Spinadelfb98be52014-05-04 12:51:10 +0300487 u8 client_bitmap = 0;
David Spinadel35a000b2013-08-28 09:29:43 +0300488
David Spinadelfb98be52014-05-04 12:51:10 +0300489 if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN)) {
490 struct iwl_sched_scan_results *notif = (void *)pkt->data;
491
492 client_bitmap = notif->client_bitmap;
493 }
494
495 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN ||
496 client_bitmap & SCAN_CLIENT_SCHED_SCAN) {
497 if (mvm->scan_status == IWL_MVM_SCAN_SCHED) {
498 IWL_DEBUG_SCAN(mvm, "Scheduled scan results\n");
499 ieee80211_sched_scan_results(mvm->hw);
500 } else {
501 IWL_DEBUG_SCAN(mvm, "Scan results\n");
502 }
David Spinadel35a000b2013-08-28 09:29:43 +0300503 }
504
505 return 0;
506}
507
Johannes Berg8ca151b2013-01-24 14:25:36 +0100508static bool iwl_mvm_scan_abort_notif(struct iwl_notif_wait_data *notif_wait,
509 struct iwl_rx_packet *pkt, void *data)
510{
511 struct iwl_mvm *mvm =
512 container_of(notif_wait, struct iwl_mvm, notif_wait);
513 struct iwl_scan_complete_notif *notif;
514 u32 *resp;
515
516 switch (pkt->hdr.cmd) {
517 case SCAN_ABORT_CMD:
518 resp = (void *)pkt->data;
519 if (*resp == CAN_ABORT_STATUS) {
520 IWL_DEBUG_SCAN(mvm,
521 "Scan can be aborted, wait until completion\n");
522 return false;
523 }
524
Emmanuel Grumbach5a3e9f72013-09-15 14:39:02 +0300525 /*
526 * If scan cannot be aborted, it means that we had a
527 * SCAN_COMPLETE_NOTIFICATION in the pipe and it called
528 * ieee80211_scan_completed already.
529 */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100530 IWL_DEBUG_SCAN(mvm, "Scan cannot be aborted, exit now: %d\n",
531 *resp);
532 return true;
533
534 case SCAN_COMPLETE_NOTIFICATION:
535 notif = (void *)pkt->data;
536 IWL_DEBUG_SCAN(mvm, "Scan aborted: status 0x%x\n",
537 notif->status);
538 return true;
539
540 default:
541 WARN_ON(1);
542 return false;
543 };
544}
545
David Spinadelfb98be52014-05-04 12:51:10 +0300546static int iwl_mvm_cancel_regular_scan(struct iwl_mvm *mvm)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100547{
548 struct iwl_notification_wait wait_scan_abort;
549 static const u8 scan_abort_notif[] = { SCAN_ABORT_CMD,
550 SCAN_COMPLETE_NOTIFICATION };
551 int ret;
552
Emmanuel Grumbach5a3e9f72013-09-15 14:39:02 +0300553 if (mvm->scan_status == IWL_MVM_SCAN_NONE)
Arik Nemtsov91b80252014-02-10 12:49:39 +0200554 return 0;
Emmanuel Grumbach5a3e9f72013-09-15 14:39:02 +0300555
Emmanuel Grumbachaaa4e742013-12-19 22:20:58 +0200556 if (iwl_mvm_is_radio_killed(mvm)) {
557 ieee80211_scan_completed(mvm->hw, true);
Arik Nemtsov519e2022013-10-17 17:51:35 +0300558 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
Emmanuel Grumbachaaa4e742013-12-19 22:20:58 +0200559 mvm->scan_status = IWL_MVM_SCAN_NONE;
Arik Nemtsov91b80252014-02-10 12:49:39 +0200560 return 0;
Emmanuel Grumbachaaa4e742013-12-19 22:20:58 +0200561 }
562
Johannes Berg8ca151b2013-01-24 14:25:36 +0100563 iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_abort,
564 scan_abort_notif,
565 ARRAY_SIZE(scan_abort_notif),
566 iwl_mvm_scan_abort_notif, NULL);
567
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300568 ret = iwl_mvm_send_cmd_pdu(mvm, SCAN_ABORT_CMD, 0, 0, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100569 if (ret) {
570 IWL_ERR(mvm, "Couldn't send SCAN_ABORT_CMD: %d\n", ret);
David Spinadel992f81f2014-01-09 14:22:55 +0200571 /* mac80211's state will be cleaned in the nic_restart flow */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100572 goto out_remove_notif;
573 }
574
Arik Nemtsov91b80252014-02-10 12:49:39 +0200575 return iwl_wait_notification(&mvm->notif_wait, &wait_scan_abort, HZ);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100576
577out_remove_notif:
578 iwl_remove_notification(&mvm->notif_wait, &wait_scan_abort);
Arik Nemtsov91b80252014-02-10 12:49:39 +0200579 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100580}
David Spinadel35a000b2013-08-28 09:29:43 +0300581
582int iwl_mvm_rx_scan_offload_complete_notif(struct iwl_mvm *mvm,
583 struct iwl_rx_cmd_buffer *rxb,
584 struct iwl_device_cmd *cmd)
585{
586 struct iwl_rx_packet *pkt = rxb_addr(rxb);
David Spinadelfb98be52014-05-04 12:51:10 +0300587 u8 status, ebs_status;
David Spinadel35a000b2013-08-28 09:29:43 +0300588
David Spinadelfb98be52014-05-04 12:51:10 +0300589 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN) {
590 struct iwl_periodic_scan_complete *scan_notif;
591
592 scan_notif = (void *)pkt->data;
593 status = scan_notif->status;
594 ebs_status = scan_notif->ebs_status;
595 } else {
596 struct iwl_scan_offload_complete *scan_notif;
597
598 scan_notif = (void *)pkt->data;
599 status = scan_notif->status;
600 ebs_status = scan_notif->ebs_status;
601 }
Johannes Berga6623e82014-01-27 15:40:53 +0100602 /* scan status must be locked for proper checking */
603 lockdep_assert_held(&mvm->mutex);
604
Haim Dreyfusse820c2d2014-04-06 11:19:09 +0300605 IWL_DEBUG_SCAN(mvm,
David Spinadelfb98be52014-05-04 12:51:10 +0300606 "%s completed, status %s, EBS status %s\n",
607 mvm->scan_status == IWL_MVM_SCAN_SCHED ?
608 "Scheduled scan" : "Scan",
609 status == IWL_SCAN_OFFLOAD_COMPLETED ?
610 "completed" : "aborted",
611 ebs_status == IWL_SCAN_EBS_SUCCESS ?
612 "success" : "failed");
Haim Dreyfusse820c2d2014-04-06 11:19:09 +0300613
David Spinadel35a000b2013-08-28 09:29:43 +0300614
Arik Nemtsov33ea27f2014-02-10 15:34:29 +0200615 /* only call mac80211 completion if the stop was initiated by FW */
616 if (mvm->scan_status == IWL_MVM_SCAN_SCHED) {
Johannes Berga6623e82014-01-27 15:40:53 +0100617 mvm->scan_status = IWL_MVM_SCAN_NONE;
Arik Nemtsov33ea27f2014-02-10 15:34:29 +0200618 ieee80211_sched_scan_stopped(mvm->hw);
David Spinadelfb98be52014-05-04 12:51:10 +0300619 } else if (mvm->scan_status == IWL_MVM_SCAN_OS) {
620 mvm->scan_status = IWL_MVM_SCAN_NONE;
621 ieee80211_scan_completed(mvm->hw,
622 status == IWL_SCAN_OFFLOAD_ABORTED);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +0200623 }
David Spinadel35a000b2013-08-28 09:29:43 +0300624
David Spinadelfb98be52014-05-04 12:51:10 +0300625 mvm->last_ebs_successful = !ebs_status;
Haim Dreyfusse820c2d2014-04-06 11:19:09 +0300626
David Spinadel35a000b2013-08-28 09:29:43 +0300627 return 0;
628}
629
630static void iwl_scan_offload_build_tx_cmd(struct iwl_mvm *mvm,
631 struct ieee80211_vif *vif,
David Spinadel633e2712014-02-06 16:15:23 +0200632 struct ieee80211_scan_ies *ies,
David Spinadel35a000b2013-08-28 09:29:43 +0300633 enum ieee80211_band band,
634 struct iwl_tx_cmd *cmd,
635 u8 *data)
636{
637 u16 cmd_len;
638
639 cmd->tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL);
640 cmd->life_time = cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE);
641 cmd->sta_id = mvm->aux_sta.sta_id;
642
643 cmd->rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm, band, false);
644
645 cmd_len = iwl_mvm_fill_probe_req((struct ieee80211_mgmt *)data,
646 vif->addr,
647 1, NULL, 0,
David Spinadel633e2712014-02-06 16:15:23 +0200648 ies->ies[band], ies->len[band],
649 ies->common_ies, ies->common_ie_len,
David Spinadel35a000b2013-08-28 09:29:43 +0300650 SCAN_OFFLOAD_PROBE_REQ_SIZE);
651 cmd->len = cpu_to_le16(cmd_len);
652}
653
654static void iwl_build_scan_cmd(struct iwl_mvm *mvm,
655 struct ieee80211_vif *vif,
656 struct cfg80211_sched_scan_request *req,
Alexander Bondar50df8a32014-03-12 20:30:51 +0200657 struct iwl_scan_offload_cmd *scan,
658 struct iwl_mvm_scan_params *params)
David Spinadel35a000b2013-08-28 09:29:43 +0300659{
Eliad Peller89879412014-05-26 18:44:35 +0300660 scan->channel_count = req->n_channels;
David Spinadel35a000b2013-08-28 09:29:43 +0300661 scan->quiet_time = cpu_to_le16(IWL_ACTIVE_QUIET_TIME);
662 scan->quiet_plcp_th = cpu_to_le16(IWL_PLCP_QUIET_THRESH);
663 scan->good_CRC_th = IWL_GOOD_CRC_TH_DEFAULT;
664 scan->rx_chain = iwl_mvm_scan_rx_chain(mvm);
Alexander Bondar8a110d92014-03-12 17:31:19 +0200665
Alexander Bondar50df8a32014-03-12 20:30:51 +0200666 scan->max_out_time = cpu_to_le32(params->max_out_time);
667 scan->suspend_time = cpu_to_le32(params->suspend_time);
Alexander Bondar8a110d92014-03-12 17:31:19 +0200668
David Spinadel35a000b2013-08-28 09:29:43 +0300669 scan->filter_flags |= cpu_to_le32(MAC_FILTER_ACCEPT_GRP |
670 MAC_FILTER_IN_BEACON);
671 scan->scan_type = cpu_to_le32(SCAN_TYPE_BACKGROUND);
672 scan->rep_count = cpu_to_le32(1);
Alexander Bondar50df8a32014-03-12 20:30:51 +0200673
674 if (params->passive_fragmented)
675 scan->scan_flags |= SCAN_FLAGS_FRAGMENTED_SCAN;
David Spinadel35a000b2013-08-28 09:29:43 +0300676}
677
678static int iwl_ssid_exist(u8 *ssid, u8 ssid_len, struct iwl_ssid_ie *ssid_list)
679{
680 int i;
681
682 for (i = 0; i < PROBE_OPTION_MAX; i++) {
683 if (!ssid_list[i].len)
684 break;
685 if (ssid_list[i].len == ssid_len &&
686 !memcmp(ssid_list->ssid, ssid, ssid_len))
687 return i;
688 }
689 return -1;
690}
691
692static void iwl_scan_offload_build_ssid(struct cfg80211_sched_scan_request *req,
David Spinadelfb98be52014-05-04 12:51:10 +0300693 struct iwl_ssid_ie *direct_scan,
694 u32 *ssid_bitmap, bool basic_ssid)
David Spinadel35a000b2013-08-28 09:29:43 +0300695{
696 int i, j;
697 int index;
698
699 /*
700 * copy SSIDs from match list.
701 * iwl_config_sched_scan_profiles() uses the order of these ssids to
702 * config match list.
703 */
704 for (i = 0; i < req->n_match_sets && i < PROBE_OPTION_MAX; i++) {
Johannes Bergea73cbc2014-01-24 10:53:53 +0100705 /* skip empty SSID matchsets */
706 if (!req->match_sets[i].ssid.ssid_len)
707 continue;
David Spinadelfb98be52014-05-04 12:51:10 +0300708 direct_scan[i].id = WLAN_EID_SSID;
709 direct_scan[i].len = req->match_sets[i].ssid.ssid_len;
710 memcpy(direct_scan[i].ssid, req->match_sets[i].ssid.ssid,
711 direct_scan[i].len);
David Spinadel35a000b2013-08-28 09:29:43 +0300712 }
713
714 /* add SSIDs from scan SSID list */
715 *ssid_bitmap = 0;
716 for (j = 0; j < req->n_ssids && i < PROBE_OPTION_MAX; j++) {
717 index = iwl_ssid_exist(req->ssids[j].ssid,
718 req->ssids[j].ssid_len,
David Spinadelfb98be52014-05-04 12:51:10 +0300719 direct_scan);
David Spinadel35a000b2013-08-28 09:29:43 +0300720 if (index < 0) {
David Spinadelfb98be52014-05-04 12:51:10 +0300721 if (!req->ssids[j].ssid_len && basic_ssid)
David Spinadel35a000b2013-08-28 09:29:43 +0300722 continue;
David Spinadelfb98be52014-05-04 12:51:10 +0300723 direct_scan[i].id = WLAN_EID_SSID;
724 direct_scan[i].len = req->ssids[j].ssid_len;
725 memcpy(direct_scan[i].ssid, req->ssids[j].ssid,
726 direct_scan[i].len);
David Spinadel35a000b2013-08-28 09:29:43 +0300727 *ssid_bitmap |= BIT(i + 1);
728 i++;
729 } else {
730 *ssid_bitmap |= BIT(index + 1);
731 }
732 }
733}
734
735static void iwl_build_channel_cfg(struct iwl_mvm *mvm,
736 struct cfg80211_sched_scan_request *req,
David Spinadel762533b2014-06-05 11:20:43 +0300737 u8 *channels_buffer,
David Spinadel35a000b2013-08-28 09:29:43 +0300738 enum ieee80211_band band,
Eliad Peller89879412014-05-26 18:44:35 +0300739 int *head,
Alexander Bondar50df8a32014-03-12 20:30:51 +0200740 u32 ssid_bitmap,
741 struct iwl_mvm_scan_params *params)
David Spinadel35a000b2013-08-28 09:29:43 +0300742{
David Spinadel762533b2014-06-05 11:20:43 +0300743 u32 n_channels = mvm->fw->ucode_capa.n_scan_channels;
744 __le32 *type = (__le32 *)channels_buffer;
745 __le16 *channel_number = (__le16 *)(type + n_channels);
746 __le16 *iter_count = channel_number + n_channels;
747 __le32 *iter_interval = (__le32 *)(iter_count + n_channels);
748 u8 *active_dwell = (u8 *)(iter_interval + n_channels);
749 u8 *passive_dwell = active_dwell + n_channels;
Eliad Peller89879412014-05-26 18:44:35 +0300750 int i, index = 0;
David Spinadel35a000b2013-08-28 09:29:43 +0300751
Eliad Peller89879412014-05-26 18:44:35 +0300752 for (i = 0; i < req->n_channels; i++) {
753 struct ieee80211_channel *chan = req->channels[i];
David Spinadel35a000b2013-08-28 09:29:43 +0300754
Eliad Peller89879412014-05-26 18:44:35 +0300755 if (chan->band != band)
756 continue;
David Spinadel35a000b2013-08-28 09:29:43 +0300757
Eliad Peller89879412014-05-26 18:44:35 +0300758 index = *head;
759 (*head)++;
David Spinadel35a000b2013-08-28 09:29:43 +0300760
David Spinadel762533b2014-06-05 11:20:43 +0300761 channel_number[index] = cpu_to_le16(chan->hw_value);
762 active_dwell[index] = params->dwell[band].active;
763 passive_dwell[index] = params->dwell[band].passive;
David Spinadel35a000b2013-08-28 09:29:43 +0300764
David Spinadel762533b2014-06-05 11:20:43 +0300765 iter_count[index] = cpu_to_le16(1);
766 iter_interval[index] = 0;
David Spinadel35a000b2013-08-28 09:29:43 +0300767
Eliad Peller89879412014-05-26 18:44:35 +0300768 if (!(chan->flags & IEEE80211_CHAN_NO_IR))
David Spinadel762533b2014-06-05 11:20:43 +0300769 type[index] |=
David Spinadel35a000b2013-08-28 09:29:43 +0300770 cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_ACTIVE);
771
David Spinadel762533b2014-06-05 11:20:43 +0300772 type[index] |= cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_FULL |
773 IWL_SCAN_OFFLOAD_CHANNEL_PARTIAL);
David Spinadel35a000b2013-08-28 09:29:43 +0300774
Eliad Peller89879412014-05-26 18:44:35 +0300775 if (chan->flags & IEEE80211_CHAN_NO_HT40)
David Spinadel762533b2014-06-05 11:20:43 +0300776 type[index] |=
David Spinadel35a000b2013-08-28 09:29:43 +0300777 cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_NARROW);
778
779 /* scan for all SSIDs from req->ssids */
David Spinadel762533b2014-06-05 11:20:43 +0300780 type[index] |= cpu_to_le32(ssid_bitmap);
David Spinadel35a000b2013-08-28 09:29:43 +0300781 }
782}
783
784int iwl_mvm_config_sched_scan(struct iwl_mvm *mvm,
785 struct ieee80211_vif *vif,
786 struct cfg80211_sched_scan_request *req,
David Spinadel633e2712014-02-06 16:15:23 +0200787 struct ieee80211_scan_ies *ies)
David Spinadel35a000b2013-08-28 09:29:43 +0300788{
David Spinadel35a000b2013-08-28 09:29:43 +0300789 int band_2ghz = mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels;
790 int band_5ghz = mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels;
791 int head = 0;
David Spinadel35a000b2013-08-28 09:29:43 +0300792 u32 ssid_bitmap;
793 int cmd_len;
794 int ret;
David Spinadel762533b2014-06-05 11:20:43 +0300795 u8 *probes;
David Spinadelfb98be52014-05-04 12:51:10 +0300796 bool basic_ssid = !(mvm->fw->ucode_capa.flags &
797 IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID);
David Spinadel35a000b2013-08-28 09:29:43 +0300798
799 struct iwl_scan_offload_cfg *scan_cfg;
800 struct iwl_host_cmd cmd = {
801 .id = SCAN_OFFLOAD_CONFIG_CMD,
David Spinadel35a000b2013-08-28 09:29:43 +0300802 };
Alexander Bondar50df8a32014-03-12 20:30:51 +0200803 struct iwl_mvm_scan_params params = {};
David Spinadel35a000b2013-08-28 09:29:43 +0300804
805 lockdep_assert_held(&mvm->mutex);
806
David Spinadel35a000b2013-08-28 09:29:43 +0300807 cmd_len = sizeof(struct iwl_scan_offload_cfg) +
David Spinadel762533b2014-06-05 11:20:43 +0300808 mvm->fw->ucode_capa.n_scan_channels * IWL_SCAN_CHAN_SIZE +
Emmanuel Grumbach66092532014-02-20 14:58:30 +0200809 2 * SCAN_OFFLOAD_PROBE_REQ_SIZE;
David Spinadel35a000b2013-08-28 09:29:43 +0300810
811 scan_cfg = kzalloc(cmd_len, GFP_KERNEL);
812 if (!scan_cfg)
813 return -ENOMEM;
814
David Spinadel762533b2014-06-05 11:20:43 +0300815 probes = scan_cfg->data +
816 mvm->fw->ucode_capa.n_scan_channels * IWL_SCAN_CHAN_SIZE;
817
Johannes Bergab480032014-06-04 10:13:50 +0200818 iwl_mvm_scan_calc_params(mvm, vif, req->n_ssids, 0, &params);
Alexander Bondar50df8a32014-03-12 20:30:51 +0200819 iwl_build_scan_cmd(mvm, vif, req, &scan_cfg->scan_cmd, &params);
David Spinadel35a000b2013-08-28 09:29:43 +0300820 scan_cfg->scan_cmd.len = cpu_to_le16(cmd_len);
821
David Spinadelfb98be52014-05-04 12:51:10 +0300822 iwl_scan_offload_build_ssid(req, scan_cfg->scan_cmd.direct_scan,
823 &ssid_bitmap, basic_ssid);
David Spinadel35a000b2013-08-28 09:29:43 +0300824 /* build tx frames for supported bands */
825 if (band_2ghz) {
826 iwl_scan_offload_build_tx_cmd(mvm, vif, ies,
827 IEEE80211_BAND_2GHZ,
828 &scan_cfg->scan_cmd.tx_cmd[0],
David Spinadel762533b2014-06-05 11:20:43 +0300829 probes);
830 iwl_build_channel_cfg(mvm, req, scan_cfg->data,
Eliad Peller89879412014-05-26 18:44:35 +0300831 IEEE80211_BAND_2GHZ, &head,
Alexander Bondar50df8a32014-03-12 20:30:51 +0200832 ssid_bitmap, &params);
David Spinadel35a000b2013-08-28 09:29:43 +0300833 }
834 if (band_5ghz) {
835 iwl_scan_offload_build_tx_cmd(mvm, vif, ies,
836 IEEE80211_BAND_5GHZ,
837 &scan_cfg->scan_cmd.tx_cmd[1],
David Spinadel762533b2014-06-05 11:20:43 +0300838 probes +
David Spinadel35a000b2013-08-28 09:29:43 +0300839 SCAN_OFFLOAD_PROBE_REQ_SIZE);
David Spinadel762533b2014-06-05 11:20:43 +0300840 iwl_build_channel_cfg(mvm, req, scan_cfg->data,
Eliad Peller89879412014-05-26 18:44:35 +0300841 IEEE80211_BAND_5GHZ, &head,
Alexander Bondar50df8a32014-03-12 20:30:51 +0200842 ssid_bitmap, &params);
David Spinadel35a000b2013-08-28 09:29:43 +0300843 }
844
845 cmd.data[0] = scan_cfg;
846 cmd.len[0] = cmd_len;
847 cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
848
849 IWL_DEBUG_SCAN(mvm, "Sending scheduled scan config\n");
850
851 ret = iwl_mvm_send_cmd(mvm, &cmd);
852 kfree(scan_cfg);
853 return ret;
854}
855
856int iwl_mvm_config_sched_scan_profiles(struct iwl_mvm *mvm,
857 struct cfg80211_sched_scan_request *req)
858{
859 struct iwl_scan_offload_profile *profile;
860 struct iwl_scan_offload_profile_cfg *profile_cfg;
861 struct iwl_scan_offload_blacklist *blacklist;
862 struct iwl_host_cmd cmd = {
863 .id = SCAN_OFFLOAD_UPDATE_PROFILES_CMD,
David Spinadel35a000b2013-08-28 09:29:43 +0300864 .len[1] = sizeof(*profile_cfg),
865 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
866 .dataflags[1] = IWL_HCMD_DFL_NOCOPY,
867 };
868 int blacklist_len;
869 int i;
870 int ret;
871
872 if (WARN_ON(req->n_match_sets > IWL_SCAN_MAX_PROFILES))
873 return -EIO;
874
875 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_SHORT_BL)
876 blacklist_len = IWL_SCAN_SHORT_BLACKLIST_LEN;
877 else
878 blacklist_len = IWL_SCAN_MAX_BLACKLIST_LEN;
879
880 blacklist = kzalloc(sizeof(*blacklist) * blacklist_len, GFP_KERNEL);
881 if (!blacklist)
882 return -ENOMEM;
883
884 profile_cfg = kzalloc(sizeof(*profile_cfg), GFP_KERNEL);
885 if (!profile_cfg) {
886 ret = -ENOMEM;
887 goto free_blacklist;
888 }
889
890 cmd.data[0] = blacklist;
891 cmd.len[0] = sizeof(*blacklist) * blacklist_len;
892 cmd.data[1] = profile_cfg;
893
894 /* No blacklist configuration */
895
896 profile_cfg->num_profiles = req->n_match_sets;
897 profile_cfg->active_clients = SCAN_CLIENT_SCHED_SCAN;
898 profile_cfg->pass_match = SCAN_CLIENT_SCHED_SCAN;
899 profile_cfg->match_notify = SCAN_CLIENT_SCHED_SCAN;
David Spinadel6e0bbe52013-12-30 09:59:45 +0200900 if (!req->n_match_sets || !req->match_sets[0].ssid.ssid_len)
901 profile_cfg->any_beacon_notify = SCAN_CLIENT_SCHED_SCAN;
David Spinadel35a000b2013-08-28 09:29:43 +0300902
903 for (i = 0; i < req->n_match_sets; i++) {
904 profile = &profile_cfg->profiles[i];
905 profile->ssid_index = i;
906 /* Support any cipher and auth algorithm */
907 profile->unicast_cipher = 0xff;
908 profile->auth_alg = 0xff;
909 profile->network_type = IWL_NETWORK_TYPE_ANY;
910 profile->band_selection = IWL_SCAN_OFFLOAD_SELECT_ANY;
911 profile->client_bitmap = SCAN_CLIENT_SCHED_SCAN;
912 }
913
914 IWL_DEBUG_SCAN(mvm, "Sending scheduled scan profile config\n");
915
916 ret = iwl_mvm_send_cmd(mvm, &cmd);
917 kfree(profile_cfg);
918free_blacklist:
919 kfree(blacklist);
920
921 return ret;
922}
923
924int iwl_mvm_sched_scan_start(struct iwl_mvm *mvm,
925 struct cfg80211_sched_scan_request *req)
926{
927 struct iwl_scan_offload_req scan_req = {
928 .watchdog = IWL_SCHED_SCAN_WATCHDOG,
929
930 .schedule_line[0].iterations = IWL_FAST_SCHED_SCAN_ITERATIONS,
David Spinadelb14fc2b2014-06-25 13:17:53 +0300931 .schedule_line[0].delay = cpu_to_le16(req->interval / 1000),
David Spinadel35a000b2013-08-28 09:29:43 +0300932 .schedule_line[0].full_scan_mul = 1,
933
934 .schedule_line[1].iterations = 0xff,
David Spinadelb14fc2b2014-06-25 13:17:53 +0300935 .schedule_line[1].delay = cpu_to_le16(req->interval / 1000),
David Spinadel35a000b2013-08-28 09:29:43 +0300936 .schedule_line[1].full_scan_mul = IWL_FULL_SCAN_MULTIPLIER,
937 };
938
939 if (req->n_match_sets && req->match_sets[0].ssid.ssid_len) {
940 IWL_DEBUG_SCAN(mvm,
941 "Sending scheduled scan with filtering, filter len %d\n",
942 req->n_match_sets);
David Spinadel35a000b2013-08-28 09:29:43 +0300943 } else {
944 IWL_DEBUG_SCAN(mvm,
945 "Sending Scheduled scan without filtering\n");
Eliad Pellerde33fb52013-11-10 12:59:46 +0200946 scan_req.flags |= cpu_to_le16(IWL_SCAN_OFFLOAD_FLAG_PASS_ALL);
David Spinadel35a000b2013-08-28 09:29:43 +0300947 }
948
Haim Dreyfusse820c2d2014-04-06 11:19:09 +0300949 if (mvm->last_ebs_successful &&
950 mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_EBS_SUPPORT)
951 scan_req.flags |=
952 cpu_to_le16(IWL_SCAN_OFFLOAD_FLAG_EBS_ACCURATE_MODE);
953
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300954 return iwl_mvm_send_cmd_pdu(mvm, SCAN_OFFLOAD_REQUEST_CMD, 0,
David Spinadel35a000b2013-08-28 09:29:43 +0300955 sizeof(scan_req), &scan_req);
956}
957
David Spinadelfb98be52014-05-04 12:51:10 +0300958static int iwl_mvm_send_scan_offload_abort(struct iwl_mvm *mvm)
David Spinadel35a000b2013-08-28 09:29:43 +0300959{
960 int ret;
961 struct iwl_host_cmd cmd = {
962 .id = SCAN_OFFLOAD_ABORT_CMD,
David Spinadel35a000b2013-08-28 09:29:43 +0300963 };
964 u32 status;
965
966 /* Exit instantly with error when device is not ready
967 * to receive scan abort command or it does not perform
968 * scheduled scan currently */
David Spinadelfb98be52014-05-04 12:51:10 +0300969 if (mvm->scan_status != IWL_MVM_SCAN_SCHED &&
970 (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN) ||
971 mvm->scan_status != IWL_MVM_SCAN_OS))
David Spinadel35a000b2013-08-28 09:29:43 +0300972 return -EIO;
973
974 ret = iwl_mvm_send_cmd_status(mvm, &cmd, &status);
975 if (ret)
976 return ret;
977
978 if (status != CAN_ABORT_STATUS) {
979 /*
980 * The scan abort will return 1 for success or
981 * 2 for "failure". A failure condition can be
982 * due to simply not being in an active scan which
983 * can occur if we send the scan abort before the
984 * microcode has notified us that a scan is completed.
985 */
986 IWL_DEBUG_SCAN(mvm, "SCAN OFFLOAD ABORT ret %d.\n", status);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +0200987 ret = -ENOENT;
David Spinadel35a000b2013-08-28 09:29:43 +0300988 }
989
990 return ret;
991}
992
David Spinadelfb98be52014-05-04 12:51:10 +0300993int iwl_mvm_scan_offload_stop(struct iwl_mvm *mvm, bool notify)
David Spinadel35a000b2013-08-28 09:29:43 +0300994{
995 int ret;
Arik Nemtsov33ea27f2014-02-10 15:34:29 +0200996 struct iwl_notification_wait wait_scan_done;
997 static const u8 scan_done_notif[] = { SCAN_OFFLOAD_COMPLETE, };
David Spinadelfb98be52014-05-04 12:51:10 +0300998 bool sched = mvm->scan_status == IWL_MVM_SCAN_SCHED;
David Spinadel35a000b2013-08-28 09:29:43 +0300999
1000 lockdep_assert_held(&mvm->mutex);
1001
David Spinadelfb98be52014-05-04 12:51:10 +03001002 if (mvm->scan_status != IWL_MVM_SCAN_SCHED &&
1003 (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN) ||
1004 mvm->scan_status != IWL_MVM_SCAN_OS)) {
1005 IWL_DEBUG_SCAN(mvm, "No scan to stop\n");
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02001006 return 0;
David Spinadel35a000b2013-08-28 09:29:43 +03001007 }
1008
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02001009 iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_done,
1010 scan_done_notif,
1011 ARRAY_SIZE(scan_done_notif),
1012 NULL, NULL);
1013
David Spinadelfb98be52014-05-04 12:51:10 +03001014 ret = iwl_mvm_send_scan_offload_abort(mvm);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02001015 if (ret) {
David Spinadelfb98be52014-05-04 12:51:10 +03001016 IWL_DEBUG_SCAN(mvm, "Send stop %sscan failed %d\n",
1017 sched ? "offloaded " : "", ret);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02001018 iwl_remove_notification(&mvm->notif_wait, &wait_scan_done);
1019 return ret;
1020 }
1021
David Spinadelfb98be52014-05-04 12:51:10 +03001022 IWL_DEBUG_SCAN(mvm, "Successfully sent stop %sscan\n",
1023 sched ? "offloaded " : "");
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02001024
1025 ret = iwl_wait_notification(&mvm->notif_wait, &wait_scan_done, 1 * HZ);
1026 if (ret)
1027 return ret;
1028
1029 /*
1030 * Clear the scan status so the next scan requests will succeed. This
1031 * also ensures the Rx handler doesn't do anything, as the scan was
1032 * stopped from above.
1033 */
1034 mvm->scan_status = IWL_MVM_SCAN_NONE;
1035
David Spinadelfb98be52014-05-04 12:51:10 +03001036 if (notify) {
1037 if (sched)
1038 ieee80211_sched_scan_stopped(mvm->hw);
1039 else
1040 ieee80211_scan_completed(mvm->hw, true);
1041 }
David Spinadel636a2cd2014-05-01 15:57:22 +03001042
Arik Nemtsov33ea27f2014-02-10 15:34:29 +02001043 return 0;
David Spinadel35a000b2013-08-28 09:29:43 +03001044}
David Spinadelfb98be52014-05-04 12:51:10 +03001045
1046static void iwl_mvm_unified_scan_fill_tx_cmd(struct iwl_mvm *mvm,
1047 struct iwl_scan_req_tx_cmd *tx_cmd,
1048 bool no_cck)
1049{
1050 tx_cmd[0].tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL |
1051 TX_CMD_FLG_BT_DIS);
1052 tx_cmd[0].rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm,
1053 IEEE80211_BAND_2GHZ,
1054 no_cck);
1055 tx_cmd[0].sta_id = mvm->aux_sta.sta_id;
1056
1057 tx_cmd[1].tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL |
1058 TX_CMD_FLG_BT_DIS);
1059 tx_cmd[1].rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm,
1060 IEEE80211_BAND_5GHZ,
1061 no_cck);
1062 tx_cmd[1].sta_id = mvm->aux_sta.sta_id;
1063}
1064
1065static void
1066iwl_mvm_lmac_scan_cfg_channels(struct iwl_mvm *mvm,
1067 struct ieee80211_channel **channels,
1068 int n_channels, u32 ssid_bitmap,
1069 struct iwl_scan_req_unified_lmac *cmd)
1070{
1071 struct iwl_scan_channel_cfg_lmac *channel_cfg = (void *)&cmd->data;
1072 int i;
1073
1074 for (i = 0; i < n_channels; i++) {
1075 channel_cfg[i].channel_num =
1076 cpu_to_le16(channels[i]->hw_value);
1077 channel_cfg[i].iter_count = cpu_to_le16(1);
1078 channel_cfg[i].iter_interval = 0;
1079 channel_cfg[i].flags =
1080 cpu_to_le32(IWL_UNIFIED_SCAN_CHANNEL_PARTIAL |
1081 ssid_bitmap);
1082 }
1083}
1084
1085static void
1086iwl_mvm_build_unified_scan_probe(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1087 struct ieee80211_scan_ies *ies,
1088 struct iwl_scan_req_unified_lmac *cmd)
1089{
1090 struct iwl_scan_probe_req *preq = (void *)(cmd->data +
1091 sizeof(struct iwl_scan_channel_cfg_lmac) *
1092 mvm->fw->ucode_capa.n_scan_channels);
1093 struct ieee80211_mgmt *frame = (struct ieee80211_mgmt *)preq->buf;
1094 u8 *pos;
1095
1096 frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
1097 eth_broadcast_addr(frame->da);
1098 memcpy(frame->sa, vif->addr, ETH_ALEN);
1099 eth_broadcast_addr(frame->bssid);
1100 frame->seq_ctrl = 0;
1101
1102 pos = frame->u.probe_req.variable;
1103 *pos++ = WLAN_EID_SSID;
1104 *pos++ = 0;
1105
1106 preq->mac_header.offset = 0;
1107 preq->mac_header.len = cpu_to_le16(24 + 2);
1108
1109 memcpy(pos, ies->ies[IEEE80211_BAND_2GHZ],
1110 ies->len[IEEE80211_BAND_2GHZ]);
1111 preq->band_data[0].offset = cpu_to_le16(pos - preq->buf);
1112 preq->band_data[0].len = cpu_to_le16(ies->len[IEEE80211_BAND_2GHZ]);
1113 pos += ies->len[IEEE80211_BAND_2GHZ];
1114
1115 memcpy(pos, ies->ies[IEEE80211_BAND_5GHZ],
1116 ies->len[IEEE80211_BAND_5GHZ]);
1117 preq->band_data[1].offset = cpu_to_le16(pos - preq->buf);
1118 preq->band_data[1].len = cpu_to_le16(ies->len[IEEE80211_BAND_5GHZ]);
1119 pos += ies->len[IEEE80211_BAND_5GHZ];
1120
1121 memcpy(pos, ies->common_ies, ies->common_ie_len);
1122 preq->common_data.offset = cpu_to_le16(pos - preq->buf);
1123 preq->common_data.len = cpu_to_le16(ies->common_ie_len);
1124}
1125
1126static void
1127iwl_mvm_build_generic_unified_scan_cmd(struct iwl_mvm *mvm,
1128 struct iwl_scan_req_unified_lmac *cmd,
1129 struct iwl_mvm_scan_params *params)
1130{
David Spinadelaf913442014-06-12 19:29:40 +03001131 memset(cmd, 0, ksize(cmd));
David Spinadel2ce89cd2014-07-22 13:11:18 +03001132 cmd->active_dwell = params->dwell[IEEE80211_BAND_2GHZ].active;
1133 cmd->passive_dwell = params->dwell[IEEE80211_BAND_2GHZ].passive;
1134 if (params->passive_fragmented)
1135 cmd->fragmented_dwell =
1136 params->dwell[IEEE80211_BAND_2GHZ].passive;
David Spinadelfb98be52014-05-04 12:51:10 +03001137 cmd->rx_chain_select = iwl_mvm_scan_rx_chain(mvm);
1138 cmd->max_out_time = cpu_to_le32(params->max_out_time);
1139 cmd->suspend_time = cpu_to_le32(params->suspend_time);
1140 cmd->scan_prio = cpu_to_le32(IWL_SCAN_PRIORITY_HIGH);
David Spinadelfb98be52014-05-04 12:51:10 +03001141 cmd->iter_num = cpu_to_le32(1);
David Spinadelaf913442014-06-12 19:29:40 +03001142
1143 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_EBS_SUPPORT &&
1144 mvm->last_ebs_successful) {
1145 cmd->channel_opt[0].flags =
1146 cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS |
1147 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
1148 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD);
1149 cmd->channel_opt[1].flags =
1150 cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS |
1151 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
1152 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD);
1153 }
David Spinadelfb98be52014-05-04 12:51:10 +03001154}
1155
1156int iwl_mvm_unified_scan_lmac(struct iwl_mvm *mvm,
1157 struct ieee80211_vif *vif,
1158 struct ieee80211_scan_request *req)
1159{
1160 struct iwl_host_cmd hcmd = {
1161 .id = SCAN_OFFLOAD_REQUEST_CMD,
1162 .len = { sizeof(struct iwl_scan_req_unified_lmac) +
1163 sizeof(struct iwl_scan_channel_cfg_lmac) *
1164 mvm->fw->ucode_capa.n_scan_channels +
1165 sizeof(struct iwl_scan_probe_req), },
1166 .data = { mvm->scan_cmd, },
1167 .dataflags = { IWL_HCMD_DFL_NOCOPY, },
1168 };
1169 struct iwl_scan_req_unified_lmac *cmd = mvm->scan_cmd;
1170 struct iwl_mvm_scan_params params = {};
1171 u32 flags;
1172 int ssid_bitmap = 0;
1173 int ret, i;
1174
1175 lockdep_assert_held(&mvm->mutex);
1176
1177 /* we should have failed registration if scan_cmd was NULL */
1178 if (WARN_ON(mvm->scan_cmd == NULL))
1179 return -ENOMEM;
1180
1181 if (WARN_ON_ONCE(req->req.n_ssids > PROBE_OPTION_MAX ||
1182 req->ies.common_ie_len + req->ies.len[0] +
1183 req->ies.len[1] + 24 + 2 >
1184 SCAN_OFFLOAD_PROBE_REQ_SIZE ||
1185 req->req.n_channels >
1186 mvm->fw->ucode_capa.n_scan_channels))
1187 return -1;
1188
1189 mvm->scan_status = IWL_MVM_SCAN_OS;
1190
1191 iwl_mvm_scan_calc_params(mvm, vif, req->req.n_ssids, req->req.flags,
1192 &params);
1193
1194 iwl_mvm_build_generic_unified_scan_cmd(mvm, cmd, &params);
1195
1196 cmd->n_channels = (u8)req->req.n_channels;
1197
1198 flags = IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL;
1199
1200 if (req->req.n_ssids == 1 && req->req.ssids[0].ssid_len != 0)
1201 flags |= IWL_MVM_LMAC_SCAN_FLAG_PRE_CONNECTION;
1202
1203 if (params.passive_fragmented)
1204 flags |= IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED;
1205
1206 if (req->req.n_ssids == 0)
1207 flags |= IWL_MVM_LMAC_SCAN_FLAG_PASSIVE;
1208
1209 cmd->scan_flags = cpu_to_le32(flags);
1210
1211 cmd->flags = iwl_mvm_scan_rxon_flags(req->req.channels[0]->band);
1212 cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP |
1213 MAC_FILTER_IN_BEACON);
1214 iwl_mvm_unified_scan_fill_tx_cmd(mvm, cmd->tx_cmd, req->req.no_cck);
1215 iwl_mvm_scan_fill_ssids(cmd->direct_scan, req->req.ssids,
1216 req->req.n_ssids, 0);
1217
1218 cmd->schedule[0].delay = 0;
1219 cmd->schedule[0].iterations = 1;
1220 cmd->schedule[0].full_scan_mul = 0;
1221 cmd->schedule[1].delay = 0;
1222 cmd->schedule[1].iterations = 0;
1223 cmd->schedule[1].full_scan_mul = 0;
1224
1225 for (i = 1; i <= req->req.n_ssids; i++)
1226 ssid_bitmap |= BIT(i);
1227
1228 iwl_mvm_lmac_scan_cfg_channels(mvm, req->req.channels,
1229 req->req.n_channels, ssid_bitmap,
1230 cmd);
1231
1232 iwl_mvm_build_unified_scan_probe(mvm, vif, &req->ies, cmd);
1233
1234 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1235 if (!ret) {
1236 IWL_DEBUG_SCAN(mvm, "Scan request was sent successfully\n");
1237 } else {
1238 /*
1239 * If the scan failed, it usually means that the FW was unable
1240 * to allocate the time events. Warn on it, but maybe we
1241 * should try to send the command again with different params.
1242 */
1243 IWL_ERR(mvm, "Scan failed! ret %d\n", ret);
1244 mvm->scan_status = IWL_MVM_SCAN_NONE;
1245 ret = -EIO;
1246 }
1247 return ret;
1248}
1249
1250int iwl_mvm_unified_sched_scan_lmac(struct iwl_mvm *mvm,
1251 struct ieee80211_vif *vif,
1252 struct cfg80211_sched_scan_request *req,
1253 struct ieee80211_scan_ies *ies)
1254{
1255 struct iwl_host_cmd hcmd = {
1256 .id = SCAN_OFFLOAD_REQUEST_CMD,
1257 .len = { sizeof(struct iwl_scan_req_unified_lmac) +
1258 sizeof(struct iwl_scan_channel_cfg_lmac) *
1259 mvm->fw->ucode_capa.n_scan_channels +
1260 sizeof(struct iwl_scan_probe_req), },
1261 .data = { mvm->scan_cmd, },
1262 .dataflags = { IWL_HCMD_DFL_NOCOPY, },
1263 };
1264 struct iwl_scan_req_unified_lmac *cmd = mvm->scan_cmd;
1265 struct iwl_mvm_scan_params params = {};
1266 int ret;
1267 u32 flags = 0, ssid_bitmap = 0;
1268
1269 lockdep_assert_held(&mvm->mutex);
1270
1271 /* we should have failed registration if scan_cmd was NULL */
1272 if (WARN_ON(mvm->scan_cmd == NULL))
1273 return -ENOMEM;
1274
1275 if (WARN_ON_ONCE(req->n_ssids > PROBE_OPTION_MAX ||
1276 ies->common_ie_len + ies->len[0] + ies->len[1] + 24 + 2
1277 > SCAN_OFFLOAD_PROBE_REQ_SIZE ||
1278 req->n_channels > mvm->fw->ucode_capa.n_scan_channels))
1279 return -ENOBUFS;
1280
1281 iwl_mvm_scan_calc_params(mvm, vif, req->n_ssids, 0, &params);
1282
1283 iwl_mvm_build_generic_unified_scan_cmd(mvm, cmd, &params);
1284
1285 cmd->n_channels = (u8)req->n_channels;
1286
1287 if (req->n_match_sets && req->match_sets[0].ssid.ssid_len) {
1288 IWL_DEBUG_SCAN(mvm,
1289 "Sending scheduled scan with filtering, n_match_sets %d\n",
1290 req->n_match_sets);
1291 } else {
1292 IWL_DEBUG_SCAN(mvm,
1293 "Sending Scheduled scan without filtering\n");
1294 flags |= IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL;
1295 }
1296
1297 if (req->n_ssids == 1 && req->ssids[0].ssid_len != 0)
1298 flags |= IWL_MVM_LMAC_SCAN_FLAG_PRE_CONNECTION;
1299
1300 if (params.passive_fragmented)
1301 flags |= IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED;
1302
1303 if (req->n_ssids == 0)
1304 flags |= IWL_MVM_LMAC_SCAN_FLAG_PASSIVE;
1305
1306 cmd->scan_flags = cpu_to_le32(flags);
1307
1308 cmd->flags = iwl_mvm_scan_rxon_flags(req->channels[0]->band);
1309 cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP |
1310 MAC_FILTER_IN_BEACON);
1311 iwl_mvm_unified_scan_fill_tx_cmd(mvm, cmd->tx_cmd, false);
1312 iwl_scan_offload_build_ssid(req, cmd->direct_scan, &ssid_bitmap, false);
1313
David Spinadelb14fc2b2014-06-25 13:17:53 +03001314 cmd->schedule[0].delay = cpu_to_le16(req->interval / MSEC_PER_SEC);
David Spinadelfb98be52014-05-04 12:51:10 +03001315 cmd->schedule[0].iterations = IWL_FAST_SCHED_SCAN_ITERATIONS;
1316 cmd->schedule[0].full_scan_mul = 1;
1317
David Spinadelb14fc2b2014-06-25 13:17:53 +03001318 cmd->schedule[1].delay = cpu_to_le16(req->interval / MSEC_PER_SEC);
David Spinadelfb98be52014-05-04 12:51:10 +03001319 cmd->schedule[1].iterations = 0xff;
1320 cmd->schedule[1].full_scan_mul = IWL_FULL_SCAN_MULTIPLIER;
1321
1322 iwl_mvm_lmac_scan_cfg_channels(mvm, req->channels, req->n_channels,
1323 ssid_bitmap, cmd);
1324
1325 iwl_mvm_build_unified_scan_probe(mvm, vif, ies, cmd);
1326
1327 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1328 if (!ret) {
1329 IWL_DEBUG_SCAN(mvm,
1330 "Sched scan request was sent successfully\n");
1331 } else {
1332 /*
1333 * If the scan failed, it usually means that the FW was unable
1334 * to allocate the time events. Warn on it, but maybe we
1335 * should try to send the command again with different params.
1336 */
1337 IWL_ERR(mvm, "Sched scan failed! ret %d\n", ret);
1338 mvm->scan_status = IWL_MVM_SCAN_NONE;
1339 ret = -EIO;
1340 }
1341 return ret;
1342}
1343
1344
1345int iwl_mvm_cancel_scan(struct iwl_mvm *mvm)
1346{
1347 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN)
1348 return iwl_mvm_scan_offload_stop(mvm, true);
1349 return iwl_mvm_cancel_regular_scan(mvm);
1350}