blob: 349d8e67118b3108e95a4ebc10e582114e882526 [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
Johannes Berg8ca151b2013-01-24 14:25:36 +0100100static inline __le32
101iwl_mvm_scan_rxon_flags(struct cfg80211_scan_request *req)
102{
103 if (req->channels[0]->band == IEEE80211_BAND_2GHZ)
104 return cpu_to_le32(PHY_BAND_24);
105 else
106 return cpu_to_le32(PHY_BAND_5);
107}
108
109static inline __le32
110iwl_mvm_scan_rate_n_flags(struct iwl_mvm *mvm, enum ieee80211_band band,
111 bool no_cck)
112{
113 u32 tx_ant;
114
115 mvm->scan_last_antenna_idx =
Johannes Berg4ed735e2014-02-12 21:47:44 +0100116 iwl_mvm_next_antenna(mvm, mvm->fw->valid_tx_ant,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100117 mvm->scan_last_antenna_idx);
118 tx_ant = BIT(mvm->scan_last_antenna_idx) << RATE_MCS_ANT_POS;
119
120 if (band == IEEE80211_BAND_2GHZ && !no_cck)
121 return cpu_to_le32(IWL_RATE_1M_PLCP | RATE_MCS_CCK_MSK |
122 tx_ant);
123 else
124 return cpu_to_le32(IWL_RATE_6M_PLCP | tx_ant);
125}
126
127/*
128 * We insert the SSIDs in an inverted order, because the FW will
129 * invert it back. The most prioritized SSID, which is first in the
130 * request list, is not copied here, but inserted directly to the probe
131 * request.
132 */
133static void iwl_mvm_scan_fill_ssids(struct iwl_scan_cmd *cmd,
David Spinadel20f1a5d2013-08-21 09:14:27 +0300134 struct cfg80211_scan_request *req,
135 int first)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100136{
137 int fw_idx, req_idx;
138
David Spinadel20f1a5d2013-08-21 09:14:27 +0300139 for (req_idx = req->n_ssids - 1, fw_idx = 0; req_idx >= first;
David Spinadelfe04e832013-07-04 15:17:48 +0300140 req_idx--, fw_idx++) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100141 cmd->direct_scan[fw_idx].id = WLAN_EID_SSID;
142 cmd->direct_scan[fw_idx].len = req->ssids[req_idx].ssid_len;
143 memcpy(cmd->direct_scan[fw_idx].ssid,
144 req->ssids[req_idx].ssid,
145 req->ssids[req_idx].ssid_len);
146 }
147}
148
149/*
150 * If req->n_ssids > 0, it means we should do an active scan.
151 * In case of active scan w/o directed scan, we receive a zero-length SSID
152 * just to notify that this scan is active and not passive.
153 * In order to notify the FW of the number of SSIDs we wish to scan (including
154 * the zero-length one), we need to set the corresponding bits in chan->type,
David Spinadel20f1a5d2013-08-21 09:14:27 +0300155 * one for each SSID, and set the active bit (first). If the first SSID is
156 * already included in the probe template, so we need to set only
157 * req->n_ssids - 1 bits in addition to the first bit.
Johannes Berg8ca151b2013-01-24 14:25:36 +0100158 */
159static u16 iwl_mvm_get_active_dwell(enum ieee80211_band band, int n_ssids)
160{
161 if (band == IEEE80211_BAND_2GHZ)
162 return 30 + 3 * (n_ssids + 1);
163 return 20 + 2 * (n_ssids + 1);
164}
165
166static u16 iwl_mvm_get_passive_dwell(enum ieee80211_band band)
167{
168 return band == IEEE80211_BAND_2GHZ ? 100 + 20 : 100 + 10;
169}
170
171static void iwl_mvm_scan_fill_channels(struct iwl_scan_cmd *cmd,
David Spinadel20f1a5d2013-08-21 09:14:27 +0300172 struct cfg80211_scan_request *req,
Alexander Bondar50df8a32014-03-12 20:30:51 +0200173 bool basic_ssid,
174 struct iwl_mvm_scan_params *params)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100175{
Johannes Berg8ca151b2013-01-24 14:25:36 +0100176 struct iwl_scan_channel *chan = (struct iwl_scan_channel *)
177 (cmd->data + le16_to_cpu(cmd->tx_cmd.len));
178 int i;
David Spinadel20f1a5d2013-08-21 09:14:27 +0300179 int type = BIT(req->n_ssids) - 1;
Alexander Bondar50df8a32014-03-12 20:30:51 +0200180 enum ieee80211_band band = req->channels[0]->band;
David Spinadel20f1a5d2013-08-21 09:14:27 +0300181
182 if (!basic_ssid)
183 type |= BIT(req->n_ssids);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100184
185 for (i = 0; i < cmd->channel_count; i++) {
186 chan->channel = cpu_to_le16(req->channels[i]->hw_value);
David Spinadel20f1a5d2013-08-21 09:14:27 +0300187 chan->type = cpu_to_le32(type);
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200188 if (req->channels[i]->flags & IEEE80211_CHAN_NO_IR)
David Spinadelbb963c42013-07-23 14:13:32 +0300189 chan->type &= cpu_to_le32(~SCAN_CHANNEL_TYPE_ACTIVE);
Alexander Bondar50df8a32014-03-12 20:30:51 +0200190 chan->active_dwell = cpu_to_le16(params->dwell[band].active);
191 chan->passive_dwell = cpu_to_le16(params->dwell[band].passive);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100192 chan->iteration_count = cpu_to_le16(1);
193 chan++;
194 }
195}
196
197/*
198 * Fill in probe request with the following parameters:
199 * TA is our vif HW address, which mac80211 ensures we have.
200 * Packet is broadcasted, so this is both SA and DA.
201 * The probe request IE is made out of two: first comes the most prioritized
202 * SSID if a directed scan is requested. Second comes whatever extra
203 * information was given to us as the scan request IE.
204 */
205static u16 iwl_mvm_fill_probe_req(struct ieee80211_mgmt *frame, const u8 *ta,
206 int n_ssids, const u8 *ssid, int ssid_len,
207 const u8 *ie, int ie_len,
208 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
247 if (WARN_ON(left < ie_len))
248 return len;
249
250 if (ie && ie_len) {
251 memcpy(pos, ie, ie_len);
252 len += ie_len;
253 }
254
255 return (u16)len;
256}
257
Alexander Bondar8a110d92014-03-12 17:31:19 +0200258static void iwl_mvm_scan_condition_iterator(void *data, u8 *mac,
259 struct ieee80211_vif *vif)
Haim Dreyfuss61f63252013-11-03 23:02:59 +0200260{
Alexander Bondar8a110d92014-03-12 17:31:19 +0200261 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
262 bool *global_bound = data;
Haim Dreyfuss61f63252013-11-03 23:02:59 +0200263
Alexander Bondar8a110d92014-03-12 17:31:19 +0200264 if (mvmvif->phy_ctxt && mvmvif->phy_ctxt->id < MAX_PHYS)
265 *global_bound = true;
266}
267
268static void iwl_mvm_scan_calc_params(struct iwl_mvm *mvm,
Alexander Bondar50df8a32014-03-12 20:30:51 +0200269 struct ieee80211_vif *vif,
Johannes Bergab480032014-06-04 10:13:50 +0200270 int n_ssids, u32 flags,
Alexander Bondar8a110d92014-03-12 17:31:19 +0200271 struct iwl_mvm_scan_params *params)
272{
273 bool global_bound = false;
Alexander Bondar50df8a32014-03-12 20:30:51 +0200274 enum ieee80211_band band;
Alexander Bondar8a110d92014-03-12 17:31:19 +0200275
276 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
277 IEEE80211_IFACE_ITER_NORMAL,
278 iwl_mvm_scan_condition_iterator,
279 &global_bound);
Alexander Bondar8a110d92014-03-12 17:31:19 +0200280
Alexander Bondaref67f18d2014-03-30 10:47:08 +0300281 if (!global_bound)
282 goto not_bound;
283
284 params->suspend_time = 100;
285 params->max_out_time = 600;
286
287 if (iwl_mvm_low_latency(mvm)) {
288 params->suspend_time = 250;
289 params->max_out_time = 250;
Alexander Bondar50df8a32014-03-12 20:30:51 +0200290 }
291
Johannes Bergab480032014-06-04 10:13:50 +0200292 if (flags & NL80211_SCAN_FLAG_LOW_PRIORITY)
293 params->max_out_time = 200;
294
Alexander Bondaref67f18d2014-03-30 10:47:08 +0300295not_bound:
296
Alexander Bondar50df8a32014-03-12 20:30:51 +0200297 for (band = IEEE80211_BAND_2GHZ; band < IEEE80211_NUM_BANDS; band++) {
Alexander Bondaref67f18d2014-03-30 10:47:08 +0300298 params->dwell[band].passive = iwl_mvm_get_passive_dwell(band);
Alexander Bondar50df8a32014-03-12 20:30:51 +0200299 params->dwell[band].active = iwl_mvm_get_active_dwell(band,
300 n_ssids);
301 }
Haim Dreyfuss61f63252013-11-03 23:02:59 +0200302}
303
Johannes Berg8ca151b2013-01-24 14:25:36 +0100304int iwl_mvm_scan_request(struct iwl_mvm *mvm,
305 struct ieee80211_vif *vif,
306 struct cfg80211_scan_request *req)
307{
308 struct iwl_host_cmd hcmd = {
309 .id = SCAN_REQUEST_CMD,
310 .len = { 0, },
311 .data = { mvm->scan_cmd, },
Johannes Berg8ca151b2013-01-24 14:25:36 +0100312 .dataflags = { IWL_HCMD_DFL_NOCOPY, },
313 };
314 struct iwl_scan_cmd *cmd = mvm->scan_cmd;
315 int ret;
316 u32 status;
317 int ssid_len = 0;
318 u8 *ssid = NULL;
David Spinadel20f1a5d2013-08-21 09:14:27 +0300319 bool basic_ssid = !(mvm->fw->ucode_capa.flags &
320 IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID);
Alexander Bondar8a110d92014-03-12 17:31:19 +0200321 struct iwl_mvm_scan_params params = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +0100322
323 lockdep_assert_held(&mvm->mutex);
Emmanuel Grumbach748fa67c2014-03-27 10:06:29 +0200324
325 /* we should have failed registration if scan_cmd was NULL */
326 if (WARN_ON(mvm->scan_cmd == NULL))
327 return -ENOMEM;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100328
329 IWL_DEBUG_SCAN(mvm, "Handling mac80211 scan request\n");
330 mvm->scan_status = IWL_MVM_SCAN_OS;
David Spinadel05646792014-06-02 09:59:49 +0300331 memset(cmd, 0, ksize(cmd));
Alexander Bondar8a110d92014-03-12 17:31:19 +0200332
Johannes Berg8ca151b2013-01-24 14:25:36 +0100333 cmd->channel_count = (u8)req->n_channels;
334 cmd->quiet_time = cpu_to_le16(IWL_ACTIVE_QUIET_TIME);
335 cmd->quiet_plcp_th = cpu_to_le16(IWL_PLCP_QUIET_THRESH);
336 cmd->rxchain_sel_flags = iwl_mvm_scan_rx_chain(mvm);
Alexander Bondar8a110d92014-03-12 17:31:19 +0200337
Johannes Bergab480032014-06-04 10:13:50 +0200338 iwl_mvm_scan_calc_params(mvm, vif, req->n_ssids, req->flags, &params);
Alexander Bondar8a110d92014-03-12 17:31:19 +0200339 cmd->max_out_time = cpu_to_le32(params.max_out_time);
340 cmd->suspend_time = cpu_to_le32(params.suspend_time);
Alexander Bondar50df8a32014-03-12 20:30:51 +0200341 if (params.passive_fragmented)
342 cmd->scan_flags |= SCAN_FLAGS_FRAGMENTED_SCAN;
Alexander Bondar8a110d92014-03-12 17:31:19 +0200343
Johannes Berg8ca151b2013-01-24 14:25:36 +0100344 cmd->rxon_flags = iwl_mvm_scan_rxon_flags(req);
345 cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP |
346 MAC_FILTER_IN_BEACON);
Ilan Peerd91b06d2013-02-11 08:50:45 +0200347
348 if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
349 cmd->type = cpu_to_le32(SCAN_TYPE_DISCOVERY_FORCED);
350 else
351 cmd->type = cpu_to_le32(SCAN_TYPE_FORCED);
352
Johannes Berg8ca151b2013-01-24 14:25:36 +0100353 cmd->repeats = cpu_to_le32(1);
354
355 /*
356 * If the user asked for passive scan, don't change to active scan if
357 * you see any activity on the channel - remain passive.
358 */
359 if (req->n_ssids > 0) {
360 cmd->passive2active = cpu_to_le16(1);
David Spinadel26e05cc2013-07-08 13:12:29 +0300361 cmd->scan_flags |= SCAN_FLAGS_PASSIVE2ACTIVE;
David Spinadel20f1a5d2013-08-21 09:14:27 +0300362 if (basic_ssid) {
363 ssid = req->ssids[0].ssid;
364 ssid_len = req->ssids[0].ssid_len;
365 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100366 } else {
367 cmd->passive2active = 0;
David Spinadel26e05cc2013-07-08 13:12:29 +0300368 cmd->scan_flags &= ~SCAN_FLAGS_PASSIVE2ACTIVE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100369 }
370
David Spinadel20f1a5d2013-08-21 09:14:27 +0300371 iwl_mvm_scan_fill_ssids(cmd, req, basic_ssid ? 1 : 0);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100372
Emmanuel Grumbach8e2a8662014-01-28 12:27:31 +0200373 cmd->tx_cmd.tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL |
374 TX_CMD_FLG_BT_DIS);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100375 cmd->tx_cmd.sta_id = mvm->aux_sta.sta_id;
376 cmd->tx_cmd.life_time = cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE);
377 cmd->tx_cmd.rate_n_flags =
378 iwl_mvm_scan_rate_n_flags(mvm, req->channels[0]->band,
379 req->no_cck);
380
381 cmd->tx_cmd.len =
382 cpu_to_le16(iwl_mvm_fill_probe_req(
383 (struct ieee80211_mgmt *)cmd->data,
384 vif->addr,
385 req->n_ssids, ssid, ssid_len,
386 req->ie, req->ie_len,
387 mvm->fw->ucode_capa.max_probe_length));
388
Alexander Bondar50df8a32014-03-12 20:30:51 +0200389 iwl_mvm_scan_fill_channels(cmd, req, basic_ssid, &params);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100390
391 cmd->len = cpu_to_le16(sizeof(struct iwl_scan_cmd) +
392 le16_to_cpu(cmd->tx_cmd.len) +
393 (cmd->channel_count * sizeof(struct iwl_scan_channel)));
394 hcmd.len[0] = le16_to_cpu(cmd->len);
395
396 status = SCAN_RESPONSE_OK;
397 ret = iwl_mvm_send_cmd_status(mvm, &hcmd, &status);
398 if (!ret && status == SCAN_RESPONSE_OK) {
399 IWL_DEBUG_SCAN(mvm, "Scan request was sent successfully\n");
400 } else {
401 /*
402 * If the scan failed, it usually means that the FW was unable
403 * to allocate the time events. Warn on it, but maybe we
404 * should try to send the command again with different params.
405 */
406 IWL_ERR(mvm, "Scan failed! status 0x%x ret %d\n",
407 status, ret);
408 mvm->scan_status = IWL_MVM_SCAN_NONE;
409 ret = -EIO;
410 }
411 return ret;
412}
413
414int iwl_mvm_rx_scan_response(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb,
415 struct iwl_device_cmd *cmd)
416{
417 struct iwl_rx_packet *pkt = rxb_addr(rxb);
418 struct iwl_cmd_response *resp = (void *)pkt->data;
419
420 IWL_DEBUG_SCAN(mvm, "Scan response received. status 0x%x\n",
421 le32_to_cpu(resp->status));
422 return 0;
423}
424
425int iwl_mvm_rx_scan_complete(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb,
426 struct iwl_device_cmd *cmd)
427{
428 struct iwl_rx_packet *pkt = rxb_addr(rxb);
429 struct iwl_scan_complete_notif *notif = (void *)pkt->data;
430
Arik Nemtsov91b80252014-02-10 12:49:39 +0200431 lockdep_assert_held(&mvm->mutex);
432
Johannes Berg8ca151b2013-01-24 14:25:36 +0100433 IWL_DEBUG_SCAN(mvm, "Scan complete: status=0x%x scanned channels=%d\n",
434 notif->status, notif->scanned_channels);
435
Arik Nemtsov91b80252014-02-10 12:49:39 +0200436 if (mvm->scan_status == IWL_MVM_SCAN_OS)
437 mvm->scan_status = IWL_MVM_SCAN_NONE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100438 ieee80211_scan_completed(mvm->hw, notif->status != SCAN_COMP_STATUS_OK);
439
Arik Nemtsov519e2022013-10-17 17:51:35 +0300440 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
441
Johannes Berg8ca151b2013-01-24 14:25:36 +0100442 return 0;
443}
444
David Spinadel35a000b2013-08-28 09:29:43 +0300445int iwl_mvm_rx_sched_scan_results(struct iwl_mvm *mvm,
446 struct iwl_rx_cmd_buffer *rxb,
447 struct iwl_device_cmd *cmd)
448{
449 struct iwl_rx_packet *pkt = rxb_addr(rxb);
450 struct iwl_sched_scan_results *notif = (void *)pkt->data;
451
452 if (notif->client_bitmap & SCAN_CLIENT_SCHED_SCAN) {
453 IWL_DEBUG_SCAN(mvm, "Scheduled scan results\n");
454 ieee80211_sched_scan_results(mvm->hw);
455 }
456
457 return 0;
458}
459
Johannes Berg8ca151b2013-01-24 14:25:36 +0100460static bool iwl_mvm_scan_abort_notif(struct iwl_notif_wait_data *notif_wait,
461 struct iwl_rx_packet *pkt, void *data)
462{
463 struct iwl_mvm *mvm =
464 container_of(notif_wait, struct iwl_mvm, notif_wait);
465 struct iwl_scan_complete_notif *notif;
466 u32 *resp;
467
468 switch (pkt->hdr.cmd) {
469 case SCAN_ABORT_CMD:
470 resp = (void *)pkt->data;
471 if (*resp == CAN_ABORT_STATUS) {
472 IWL_DEBUG_SCAN(mvm,
473 "Scan can be aborted, wait until completion\n");
474 return false;
475 }
476
Emmanuel Grumbach5a3e9f72013-09-15 14:39:02 +0300477 /*
478 * If scan cannot be aborted, it means that we had a
479 * SCAN_COMPLETE_NOTIFICATION in the pipe and it called
480 * ieee80211_scan_completed already.
481 */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100482 IWL_DEBUG_SCAN(mvm, "Scan cannot be aborted, exit now: %d\n",
483 *resp);
484 return true;
485
486 case SCAN_COMPLETE_NOTIFICATION:
487 notif = (void *)pkt->data;
488 IWL_DEBUG_SCAN(mvm, "Scan aborted: status 0x%x\n",
489 notif->status);
490 return true;
491
492 default:
493 WARN_ON(1);
494 return false;
495 };
496}
497
Arik Nemtsov91b80252014-02-10 12:49:39 +0200498int iwl_mvm_cancel_scan(struct iwl_mvm *mvm)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100499{
500 struct iwl_notification_wait wait_scan_abort;
501 static const u8 scan_abort_notif[] = { SCAN_ABORT_CMD,
502 SCAN_COMPLETE_NOTIFICATION };
503 int ret;
504
Emmanuel Grumbach5a3e9f72013-09-15 14:39:02 +0300505 if (mvm->scan_status == IWL_MVM_SCAN_NONE)
Arik Nemtsov91b80252014-02-10 12:49:39 +0200506 return 0;
Emmanuel Grumbach5a3e9f72013-09-15 14:39:02 +0300507
Emmanuel Grumbachaaa4e742013-12-19 22:20:58 +0200508 if (iwl_mvm_is_radio_killed(mvm)) {
509 ieee80211_scan_completed(mvm->hw, true);
Arik Nemtsov519e2022013-10-17 17:51:35 +0300510 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
Emmanuel Grumbachaaa4e742013-12-19 22:20:58 +0200511 mvm->scan_status = IWL_MVM_SCAN_NONE;
Arik Nemtsov91b80252014-02-10 12:49:39 +0200512 return 0;
Emmanuel Grumbachaaa4e742013-12-19 22:20:58 +0200513 }
514
Johannes Berg8ca151b2013-01-24 14:25:36 +0100515 iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_abort,
516 scan_abort_notif,
517 ARRAY_SIZE(scan_abort_notif),
518 iwl_mvm_scan_abort_notif, NULL);
519
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300520 ret = iwl_mvm_send_cmd_pdu(mvm, SCAN_ABORT_CMD, 0, 0, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100521 if (ret) {
522 IWL_ERR(mvm, "Couldn't send SCAN_ABORT_CMD: %d\n", ret);
David Spinadel992f81f2014-01-09 14:22:55 +0200523 /* mac80211's state will be cleaned in the nic_restart flow */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100524 goto out_remove_notif;
525 }
526
Arik Nemtsov91b80252014-02-10 12:49:39 +0200527 return iwl_wait_notification(&mvm->notif_wait, &wait_scan_abort, HZ);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100528
529out_remove_notif:
530 iwl_remove_notification(&mvm->notif_wait, &wait_scan_abort);
Arik Nemtsov91b80252014-02-10 12:49:39 +0200531 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100532}
David Spinadel35a000b2013-08-28 09:29:43 +0300533
534int iwl_mvm_rx_scan_offload_complete_notif(struct iwl_mvm *mvm,
535 struct iwl_rx_cmd_buffer *rxb,
536 struct iwl_device_cmd *cmd)
537{
538 struct iwl_rx_packet *pkt = rxb_addr(rxb);
539 struct iwl_scan_offload_complete *scan_notif = (void *)pkt->data;
540
Johannes Berga6623e82014-01-27 15:40:53 +0100541 /* scan status must be locked for proper checking */
542 lockdep_assert_held(&mvm->mutex);
543
Haim Dreyfusse820c2d2014-04-06 11:19:09 +0300544 IWL_DEBUG_SCAN(mvm,
545 "Scheduled scan completed, status %s EBS status %s:%d\n",
David Spinadel35a000b2013-08-28 09:29:43 +0300546 scan_notif->status == IWL_SCAN_OFFLOAD_COMPLETED ?
Haim Dreyfusse820c2d2014-04-06 11:19:09 +0300547 "completed" : "aborted", scan_notif->ebs_status ==
548 IWL_SCAN_EBS_SUCCESS ? "success" : "failed",
549 scan_notif->ebs_status);
550
David Spinadel35a000b2013-08-28 09:29:43 +0300551
Arik Nemtsov33ea27f2014-02-10 15:34:29 +0200552 /* only call mac80211 completion if the stop was initiated by FW */
553 if (mvm->scan_status == IWL_MVM_SCAN_SCHED) {
Johannes Berga6623e82014-01-27 15:40:53 +0100554 mvm->scan_status = IWL_MVM_SCAN_NONE;
Arik Nemtsov33ea27f2014-02-10 15:34:29 +0200555 ieee80211_sched_scan_stopped(mvm->hw);
556 }
David Spinadel35a000b2013-08-28 09:29:43 +0300557
Haim Dreyfusse820c2d2014-04-06 11:19:09 +0300558 mvm->last_ebs_successful = !scan_notif->ebs_status;
559
David Spinadel35a000b2013-08-28 09:29:43 +0300560 return 0;
561}
562
563static void iwl_scan_offload_build_tx_cmd(struct iwl_mvm *mvm,
564 struct ieee80211_vif *vif,
565 struct ieee80211_sched_scan_ies *ies,
566 enum ieee80211_band band,
567 struct iwl_tx_cmd *cmd,
568 u8 *data)
569{
570 u16 cmd_len;
571
572 cmd->tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL);
573 cmd->life_time = cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE);
574 cmd->sta_id = mvm->aux_sta.sta_id;
575
576 cmd->rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm, band, false);
577
578 cmd_len = iwl_mvm_fill_probe_req((struct ieee80211_mgmt *)data,
579 vif->addr,
580 1, NULL, 0,
581 ies->ie[band], ies->len[band],
582 SCAN_OFFLOAD_PROBE_REQ_SIZE);
583 cmd->len = cpu_to_le16(cmd_len);
584}
585
586static void iwl_build_scan_cmd(struct iwl_mvm *mvm,
587 struct ieee80211_vif *vif,
588 struct cfg80211_sched_scan_request *req,
Alexander Bondar50df8a32014-03-12 20:30:51 +0200589 struct iwl_scan_offload_cmd *scan,
590 struct iwl_mvm_scan_params *params)
David Spinadel35a000b2013-08-28 09:29:43 +0300591{
Eliad Peller89879412014-05-26 18:44:35 +0300592 scan->channel_count = req->n_channels;
David Spinadel35a000b2013-08-28 09:29:43 +0300593 scan->quiet_time = cpu_to_le16(IWL_ACTIVE_QUIET_TIME);
594 scan->quiet_plcp_th = cpu_to_le16(IWL_PLCP_QUIET_THRESH);
595 scan->good_CRC_th = IWL_GOOD_CRC_TH_DEFAULT;
596 scan->rx_chain = iwl_mvm_scan_rx_chain(mvm);
Alexander Bondar8a110d92014-03-12 17:31:19 +0200597
Alexander Bondar50df8a32014-03-12 20:30:51 +0200598 scan->max_out_time = cpu_to_le32(params->max_out_time);
599 scan->suspend_time = cpu_to_le32(params->suspend_time);
Alexander Bondar8a110d92014-03-12 17:31:19 +0200600
David Spinadel35a000b2013-08-28 09:29:43 +0300601 scan->filter_flags |= cpu_to_le32(MAC_FILTER_ACCEPT_GRP |
602 MAC_FILTER_IN_BEACON);
603 scan->scan_type = cpu_to_le32(SCAN_TYPE_BACKGROUND);
604 scan->rep_count = cpu_to_le32(1);
Alexander Bondar50df8a32014-03-12 20:30:51 +0200605
606 if (params->passive_fragmented)
607 scan->scan_flags |= SCAN_FLAGS_FRAGMENTED_SCAN;
David Spinadel35a000b2013-08-28 09:29:43 +0300608}
609
610static int iwl_ssid_exist(u8 *ssid, u8 ssid_len, struct iwl_ssid_ie *ssid_list)
611{
612 int i;
613
614 for (i = 0; i < PROBE_OPTION_MAX; i++) {
615 if (!ssid_list[i].len)
616 break;
617 if (ssid_list[i].len == ssid_len &&
618 !memcmp(ssid_list->ssid, ssid, ssid_len))
619 return i;
620 }
621 return -1;
622}
623
624static void iwl_scan_offload_build_ssid(struct cfg80211_sched_scan_request *req,
625 struct iwl_scan_offload_cmd *scan,
626 u32 *ssid_bitmap)
627{
628 int i, j;
629 int index;
630
631 /*
632 * copy SSIDs from match list.
633 * iwl_config_sched_scan_profiles() uses the order of these ssids to
634 * config match list.
635 */
636 for (i = 0; i < req->n_match_sets && i < PROBE_OPTION_MAX; i++) {
Johannes Bergea73cbc2014-01-24 10:53:53 +0100637 /* skip empty SSID matchsets */
638 if (!req->match_sets[i].ssid.ssid_len)
639 continue;
David Spinadel35a000b2013-08-28 09:29:43 +0300640 scan->direct_scan[i].id = WLAN_EID_SSID;
641 scan->direct_scan[i].len = req->match_sets[i].ssid.ssid_len;
642 memcpy(scan->direct_scan[i].ssid, req->match_sets[i].ssid.ssid,
643 scan->direct_scan[i].len);
644 }
645
646 /* add SSIDs from scan SSID list */
647 *ssid_bitmap = 0;
648 for (j = 0; j < req->n_ssids && i < PROBE_OPTION_MAX; j++) {
649 index = iwl_ssid_exist(req->ssids[j].ssid,
650 req->ssids[j].ssid_len,
651 scan->direct_scan);
652 if (index < 0) {
653 if (!req->ssids[j].ssid_len)
654 continue;
655 scan->direct_scan[i].id = WLAN_EID_SSID;
656 scan->direct_scan[i].len = req->ssids[j].ssid_len;
657 memcpy(scan->direct_scan[i].ssid, req->ssids[j].ssid,
658 scan->direct_scan[i].len);
659 *ssid_bitmap |= BIT(i + 1);
660 i++;
661 } else {
662 *ssid_bitmap |= BIT(index + 1);
663 }
664 }
665}
666
667static void iwl_build_channel_cfg(struct iwl_mvm *mvm,
668 struct cfg80211_sched_scan_request *req,
David Spinadel762533b2014-06-05 11:20:43 +0300669 u8 *channels_buffer,
David Spinadel35a000b2013-08-28 09:29:43 +0300670 enum ieee80211_band band,
Eliad Peller89879412014-05-26 18:44:35 +0300671 int *head,
Alexander Bondar50df8a32014-03-12 20:30:51 +0200672 u32 ssid_bitmap,
673 struct iwl_mvm_scan_params *params)
David Spinadel35a000b2013-08-28 09:29:43 +0300674{
David Spinadel762533b2014-06-05 11:20:43 +0300675 u32 n_channels = mvm->fw->ucode_capa.n_scan_channels;
676 __le32 *type = (__le32 *)channels_buffer;
677 __le16 *channel_number = (__le16 *)(type + n_channels);
678 __le16 *iter_count = channel_number + n_channels;
679 __le32 *iter_interval = (__le32 *)(iter_count + n_channels);
680 u8 *active_dwell = (u8 *)(iter_interval + n_channels);
681 u8 *passive_dwell = active_dwell + n_channels;
Eliad Peller89879412014-05-26 18:44:35 +0300682 int i, index = 0;
David Spinadel35a000b2013-08-28 09:29:43 +0300683
Eliad Peller89879412014-05-26 18:44:35 +0300684 for (i = 0; i < req->n_channels; i++) {
685 struct ieee80211_channel *chan = req->channels[i];
David Spinadel35a000b2013-08-28 09:29:43 +0300686
Eliad Peller89879412014-05-26 18:44:35 +0300687 if (chan->band != band)
688 continue;
689
690 index = *head;
691 (*head)++;
692
David Spinadel762533b2014-06-05 11:20:43 +0300693 channel_number[index] = cpu_to_le16(chan->hw_value);
694 active_dwell[index] = params->dwell[band].active;
695 passive_dwell[index] = params->dwell[band].passive;
David Spinadel35a000b2013-08-28 09:29:43 +0300696
David Spinadel762533b2014-06-05 11:20:43 +0300697 iter_count[index] = cpu_to_le16(1);
698 iter_interval[index] = 0;
David Spinadel35a000b2013-08-28 09:29:43 +0300699
Eliad Peller89879412014-05-26 18:44:35 +0300700 if (!(chan->flags & IEEE80211_CHAN_NO_IR))
David Spinadel762533b2014-06-05 11:20:43 +0300701 type[index] |=
David Spinadel35a000b2013-08-28 09:29:43 +0300702 cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_ACTIVE);
703
David Spinadel762533b2014-06-05 11:20:43 +0300704 type[index] |= cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_FULL |
705 IWL_SCAN_OFFLOAD_CHANNEL_PARTIAL);
David Spinadel35a000b2013-08-28 09:29:43 +0300706
Eliad Peller89879412014-05-26 18:44:35 +0300707 if (chan->flags & IEEE80211_CHAN_NO_HT40)
David Spinadel762533b2014-06-05 11:20:43 +0300708 type[index] |=
David Spinadel35a000b2013-08-28 09:29:43 +0300709 cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_NARROW);
710
711 /* scan for all SSIDs from req->ssids */
David Spinadel762533b2014-06-05 11:20:43 +0300712 type[index] |= cpu_to_le32(ssid_bitmap);
David Spinadel35a000b2013-08-28 09:29:43 +0300713 }
714}
715
716int iwl_mvm_config_sched_scan(struct iwl_mvm *mvm,
717 struct ieee80211_vif *vif,
718 struct cfg80211_sched_scan_request *req,
719 struct ieee80211_sched_scan_ies *ies)
720{
David Spinadel35a000b2013-08-28 09:29:43 +0300721 int band_2ghz = mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels;
722 int band_5ghz = mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels;
723 int head = 0;
David Spinadel35a000b2013-08-28 09:29:43 +0300724 u32 ssid_bitmap;
725 int cmd_len;
726 int ret;
David Spinadel762533b2014-06-05 11:20:43 +0300727 u8 *probes;
David Spinadel35a000b2013-08-28 09:29:43 +0300728
729 struct iwl_scan_offload_cfg *scan_cfg;
730 struct iwl_host_cmd cmd = {
731 .id = SCAN_OFFLOAD_CONFIG_CMD,
David Spinadel35a000b2013-08-28 09:29:43 +0300732 };
Alexander Bondar50df8a32014-03-12 20:30:51 +0200733 struct iwl_mvm_scan_params params = {};
David Spinadel35a000b2013-08-28 09:29:43 +0300734
735 lockdep_assert_held(&mvm->mutex);
736
David Spinadel35a000b2013-08-28 09:29:43 +0300737 cmd_len = sizeof(struct iwl_scan_offload_cfg) +
David Spinadel762533b2014-06-05 11:20:43 +0300738 mvm->fw->ucode_capa.n_scan_channels * IWL_SCAN_CHAN_SIZE +
Emmanuel Grumbach66092532014-02-20 14:58:30 +0200739 2 * SCAN_OFFLOAD_PROBE_REQ_SIZE;
David Spinadel35a000b2013-08-28 09:29:43 +0300740
741 scan_cfg = kzalloc(cmd_len, GFP_KERNEL);
742 if (!scan_cfg)
743 return -ENOMEM;
744
David Spinadel762533b2014-06-05 11:20:43 +0300745 probes = scan_cfg->data +
746 mvm->fw->ucode_capa.n_scan_channels * IWL_SCAN_CHAN_SIZE;
747
Johannes Bergab480032014-06-04 10:13:50 +0200748 iwl_mvm_scan_calc_params(mvm, vif, req->n_ssids, 0, &params);
Alexander Bondar50df8a32014-03-12 20:30:51 +0200749 iwl_build_scan_cmd(mvm, vif, req, &scan_cfg->scan_cmd, &params);
David Spinadel35a000b2013-08-28 09:29:43 +0300750 scan_cfg->scan_cmd.len = cpu_to_le16(cmd_len);
751
752 iwl_scan_offload_build_ssid(req, &scan_cfg->scan_cmd, &ssid_bitmap);
753 /* build tx frames for supported bands */
754 if (band_2ghz) {
755 iwl_scan_offload_build_tx_cmd(mvm, vif, ies,
756 IEEE80211_BAND_2GHZ,
757 &scan_cfg->scan_cmd.tx_cmd[0],
David Spinadel762533b2014-06-05 11:20:43 +0300758 probes);
759 iwl_build_channel_cfg(mvm, req, scan_cfg->data,
Eliad Peller89879412014-05-26 18:44:35 +0300760 IEEE80211_BAND_2GHZ, &head,
Alexander Bondar50df8a32014-03-12 20:30:51 +0200761 ssid_bitmap, &params);
David Spinadel35a000b2013-08-28 09:29:43 +0300762 }
763 if (band_5ghz) {
764 iwl_scan_offload_build_tx_cmd(mvm, vif, ies,
765 IEEE80211_BAND_5GHZ,
766 &scan_cfg->scan_cmd.tx_cmd[1],
David Spinadel762533b2014-06-05 11:20:43 +0300767 probes +
David Spinadel35a000b2013-08-28 09:29:43 +0300768 SCAN_OFFLOAD_PROBE_REQ_SIZE);
David Spinadel762533b2014-06-05 11:20:43 +0300769 iwl_build_channel_cfg(mvm, req, scan_cfg->data,
Eliad Peller89879412014-05-26 18:44:35 +0300770 IEEE80211_BAND_5GHZ, &head,
Alexander Bondar50df8a32014-03-12 20:30:51 +0200771 ssid_bitmap, &params);
David Spinadel35a000b2013-08-28 09:29:43 +0300772 }
773
774 cmd.data[0] = scan_cfg;
775 cmd.len[0] = cmd_len;
776 cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
777
778 IWL_DEBUG_SCAN(mvm, "Sending scheduled scan config\n");
779
780 ret = iwl_mvm_send_cmd(mvm, &cmd);
781 kfree(scan_cfg);
782 return ret;
783}
784
785int iwl_mvm_config_sched_scan_profiles(struct iwl_mvm *mvm,
786 struct cfg80211_sched_scan_request *req)
787{
788 struct iwl_scan_offload_profile *profile;
789 struct iwl_scan_offload_profile_cfg *profile_cfg;
790 struct iwl_scan_offload_blacklist *blacklist;
791 struct iwl_host_cmd cmd = {
792 .id = SCAN_OFFLOAD_UPDATE_PROFILES_CMD,
David Spinadel35a000b2013-08-28 09:29:43 +0300793 .len[1] = sizeof(*profile_cfg),
794 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
795 .dataflags[1] = IWL_HCMD_DFL_NOCOPY,
796 };
797 int blacklist_len;
798 int i;
799 int ret;
800
801 if (WARN_ON(req->n_match_sets > IWL_SCAN_MAX_PROFILES))
802 return -EIO;
803
804 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_SHORT_BL)
805 blacklist_len = IWL_SCAN_SHORT_BLACKLIST_LEN;
806 else
807 blacklist_len = IWL_SCAN_MAX_BLACKLIST_LEN;
808
809 blacklist = kzalloc(sizeof(*blacklist) * blacklist_len, GFP_KERNEL);
810 if (!blacklist)
811 return -ENOMEM;
812
813 profile_cfg = kzalloc(sizeof(*profile_cfg), GFP_KERNEL);
814 if (!profile_cfg) {
815 ret = -ENOMEM;
816 goto free_blacklist;
817 }
818
819 cmd.data[0] = blacklist;
820 cmd.len[0] = sizeof(*blacklist) * blacklist_len;
821 cmd.data[1] = profile_cfg;
822
823 /* No blacklist configuration */
824
825 profile_cfg->num_profiles = req->n_match_sets;
826 profile_cfg->active_clients = SCAN_CLIENT_SCHED_SCAN;
827 profile_cfg->pass_match = SCAN_CLIENT_SCHED_SCAN;
828 profile_cfg->match_notify = SCAN_CLIENT_SCHED_SCAN;
David Spinadel6e0bbe52013-12-30 09:59:45 +0200829 if (!req->n_match_sets || !req->match_sets[0].ssid.ssid_len)
830 profile_cfg->any_beacon_notify = SCAN_CLIENT_SCHED_SCAN;
David Spinadel35a000b2013-08-28 09:29:43 +0300831
832 for (i = 0; i < req->n_match_sets; i++) {
833 profile = &profile_cfg->profiles[i];
834 profile->ssid_index = i;
835 /* Support any cipher and auth algorithm */
836 profile->unicast_cipher = 0xff;
837 profile->auth_alg = 0xff;
838 profile->network_type = IWL_NETWORK_TYPE_ANY;
839 profile->band_selection = IWL_SCAN_OFFLOAD_SELECT_ANY;
840 profile->client_bitmap = SCAN_CLIENT_SCHED_SCAN;
841 }
842
843 IWL_DEBUG_SCAN(mvm, "Sending scheduled scan profile config\n");
844
845 ret = iwl_mvm_send_cmd(mvm, &cmd);
846 kfree(profile_cfg);
847free_blacklist:
848 kfree(blacklist);
849
850 return ret;
851}
852
853int iwl_mvm_sched_scan_start(struct iwl_mvm *mvm,
854 struct cfg80211_sched_scan_request *req)
855{
856 struct iwl_scan_offload_req scan_req = {
857 .watchdog = IWL_SCHED_SCAN_WATCHDOG,
858
859 .schedule_line[0].iterations = IWL_FAST_SCHED_SCAN_ITERATIONS,
860 .schedule_line[0].delay = req->interval / 1000,
861 .schedule_line[0].full_scan_mul = 1,
862
863 .schedule_line[1].iterations = 0xff,
864 .schedule_line[1].delay = req->interval / 1000,
865 .schedule_line[1].full_scan_mul = IWL_FULL_SCAN_MULTIPLIER,
866 };
867
868 if (req->n_match_sets && req->match_sets[0].ssid.ssid_len) {
869 IWL_DEBUG_SCAN(mvm,
870 "Sending scheduled scan with filtering, filter len %d\n",
871 req->n_match_sets);
David Spinadel35a000b2013-08-28 09:29:43 +0300872 } else {
873 IWL_DEBUG_SCAN(mvm,
874 "Sending Scheduled scan without filtering\n");
Eliad Pellerde33fb52013-11-10 12:59:46 +0200875 scan_req.flags |= cpu_to_le16(IWL_SCAN_OFFLOAD_FLAG_PASS_ALL);
David Spinadel35a000b2013-08-28 09:29:43 +0300876 }
877
Haim Dreyfusse820c2d2014-04-06 11:19:09 +0300878 if (mvm->last_ebs_successful &&
879 mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_EBS_SUPPORT)
880 scan_req.flags |=
881 cpu_to_le16(IWL_SCAN_OFFLOAD_FLAG_EBS_ACCURATE_MODE);
882
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300883 return iwl_mvm_send_cmd_pdu(mvm, SCAN_OFFLOAD_REQUEST_CMD, 0,
David Spinadel35a000b2013-08-28 09:29:43 +0300884 sizeof(scan_req), &scan_req);
885}
886
887static int iwl_mvm_send_sched_scan_abort(struct iwl_mvm *mvm)
888{
889 int ret;
890 struct iwl_host_cmd cmd = {
891 .id = SCAN_OFFLOAD_ABORT_CMD,
David Spinadel35a000b2013-08-28 09:29:43 +0300892 };
893 u32 status;
894
895 /* Exit instantly with error when device is not ready
896 * to receive scan abort command or it does not perform
897 * scheduled scan currently */
898 if (mvm->scan_status != IWL_MVM_SCAN_SCHED)
899 return -EIO;
900
901 ret = iwl_mvm_send_cmd_status(mvm, &cmd, &status);
902 if (ret)
903 return ret;
904
905 if (status != CAN_ABORT_STATUS) {
906 /*
907 * The scan abort will return 1 for success or
908 * 2 for "failure". A failure condition can be
909 * due to simply not being in an active scan which
910 * can occur if we send the scan abort before the
911 * microcode has notified us that a scan is completed.
912 */
913 IWL_DEBUG_SCAN(mvm, "SCAN OFFLOAD ABORT ret %d.\n", status);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +0200914 ret = -ENOENT;
David Spinadel35a000b2013-08-28 09:29:43 +0300915 }
916
917 return ret;
918}
919
David Spinadel636a2cd2014-05-01 15:57:22 +0300920int iwl_mvm_sched_scan_stop(struct iwl_mvm *mvm, bool notify)
David Spinadel35a000b2013-08-28 09:29:43 +0300921{
922 int ret;
Arik Nemtsov33ea27f2014-02-10 15:34:29 +0200923 struct iwl_notification_wait wait_scan_done;
924 static const u8 scan_done_notif[] = { SCAN_OFFLOAD_COMPLETE, };
David Spinadel35a000b2013-08-28 09:29:43 +0300925
926 lockdep_assert_held(&mvm->mutex);
927
928 if (mvm->scan_status != IWL_MVM_SCAN_SCHED) {
929 IWL_DEBUG_SCAN(mvm, "No offloaded scan to stop\n");
Arik Nemtsov33ea27f2014-02-10 15:34:29 +0200930 return 0;
David Spinadel35a000b2013-08-28 09:29:43 +0300931 }
932
Arik Nemtsov33ea27f2014-02-10 15:34:29 +0200933 iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_done,
934 scan_done_notif,
935 ARRAY_SIZE(scan_done_notif),
936 NULL, NULL);
937
David Spinadel35a000b2013-08-28 09:29:43 +0300938 ret = iwl_mvm_send_sched_scan_abort(mvm);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +0200939 if (ret) {
David Spinadel35a000b2013-08-28 09:29:43 +0300940 IWL_DEBUG_SCAN(mvm, "Send stop offload scan failed %d\n", ret);
Arik Nemtsov33ea27f2014-02-10 15:34:29 +0200941 iwl_remove_notification(&mvm->notif_wait, &wait_scan_done);
942 return ret;
943 }
944
945 IWL_DEBUG_SCAN(mvm, "Successfully sent stop offload scan\n");
946
947 ret = iwl_wait_notification(&mvm->notif_wait, &wait_scan_done, 1 * HZ);
948 if (ret)
949 return ret;
950
951 /*
952 * Clear the scan status so the next scan requests will succeed. This
953 * also ensures the Rx handler doesn't do anything, as the scan was
954 * stopped from above.
955 */
956 mvm->scan_status = IWL_MVM_SCAN_NONE;
957
David Spinadel636a2cd2014-05-01 15:57:22 +0300958 if (notify)
959 ieee80211_sched_scan_stopped(mvm->hw);
960
Arik Nemtsov33ea27f2014-02-10 15:34:29 +0200961 return 0;
David Spinadel35a000b2013-08-28 09:29:43 +0300962}