iwlwifi: mvm: enable passive fragmented scan changes
[deliverable/linux.git] / drivers / net / wireless / iwlwifi / mvm / scan.c
1 /******************************************************************************
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 *
8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
9 *
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
25 * in the file called COPYING.
26 *
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 *
33 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
34 * 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
73
74 struct iwl_mvm_scan_params {
75 u32 max_out_time;
76 u32 suspend_time;
77 bool passive_fragmented;
78 struct _dwell {
79 u16 passive;
80 u16 active;
81 } dwell[IEEE80211_NUM_BANDS];
82 };
83
84 static inline __le16 iwl_mvm_scan_rx_chain(struct iwl_mvm *mvm)
85 {
86 u16 rx_chain;
87 u8 rx_ant;
88
89 if (mvm->scan_rx_ant != ANT_NONE)
90 rx_ant = mvm->scan_rx_ant;
91 else
92 rx_ant = mvm->fw->valid_rx_ant;
93 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
100 static __le32 iwl_mvm_scan_rxon_flags(enum ieee80211_band band)
101 {
102 if (band == IEEE80211_BAND_2GHZ)
103 return cpu_to_le32(PHY_BAND_24);
104 else
105 return cpu_to_le32(PHY_BAND_5);
106 }
107
108 static inline __le32
109 iwl_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 =
115 iwl_mvm_next_antenna(mvm, mvm->fw->valid_tx_ant,
116 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 */
132 static void iwl_mvm_scan_fill_ssids(struct iwl_ssid_ie *cmd_ssid,
133 struct cfg80211_ssid *ssids,
134 int n_ssids, int first)
135 {
136 int fw_idx, req_idx;
137
138 for (req_idx = n_ssids - 1, fw_idx = 0; req_idx >= first;
139 req_idx--, fw_idx++) {
140 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);
145 }
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,
154 * 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.
157 */
158 static 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
165 static u16 iwl_mvm_get_passive_dwell(enum ieee80211_band band)
166 {
167 return band == IEEE80211_BAND_2GHZ ? 100 + 20 : 100 + 10;
168 }
169
170 static void iwl_mvm_scan_fill_channels(struct iwl_scan_cmd *cmd,
171 struct cfg80211_scan_request *req,
172 bool basic_ssid,
173 struct iwl_mvm_scan_params *params)
174 {
175 struct iwl_scan_channel *chan = (struct iwl_scan_channel *)
176 (cmd->data + le16_to_cpu(cmd->tx_cmd.len));
177 int i;
178 int type = BIT(req->n_ssids) - 1;
179 enum ieee80211_band band = req->channels[0]->band;
180
181 if (!basic_ssid)
182 type |= BIT(req->n_ssids);
183
184 for (i = 0; i < cmd->channel_count; i++) {
185 chan->channel = cpu_to_le16(req->channels[i]->hw_value);
186 chan->type = cpu_to_le32(type);
187 if (req->channels[i]->flags & IEEE80211_CHAN_NO_IR)
188 chan->type &= cpu_to_le32(~SCAN_CHANNEL_TYPE_ACTIVE);
189 chan->active_dwell = cpu_to_le16(params->dwell[band].active);
190 chan->passive_dwell = cpu_to_le16(params->dwell[band].passive);
191 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 */
204 static u16 iwl_mvm_fill_probe_req(struct ieee80211_mgmt *frame, const u8 *ta,
205 int n_ssids, const u8 *ssid, int ssid_len,
206 const u8 *band_ie, int band_ie_len,
207 const u8 *common_ie, int common_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 < band_ie_len + common_ie_len))
248 return len;
249
250 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;
260 }
261
262 return (u16)len;
263 }
264
265 static void iwl_mvm_scan_condition_iterator(void *data, u8 *mac,
266 struct ieee80211_vif *vif)
267 {
268 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
269 bool *global_bound = data;
270
271 if (mvmvif->phy_ctxt && mvmvif->phy_ctxt->id < MAX_PHYS)
272 *global_bound = true;
273 }
274
275 static void iwl_mvm_scan_calc_params(struct iwl_mvm *mvm,
276 struct ieee80211_vif *vif,
277 int n_ssids, u32 flags,
278 struct iwl_mvm_scan_params *params)
279 {
280 bool global_bound = false;
281 enum ieee80211_band band;
282 u8 frag_passive_dwell = 0;
283
284 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
285 IEEE80211_IFACE_ITER_NORMAL,
286 iwl_mvm_scan_condition_iterator,
287 &global_bound);
288
289 if (!global_bound)
290 goto not_bound;
291
292 params->suspend_time = 30;
293 params->max_out_time = 170;
294
295 if (iwl_mvm_low_latency(mvm)) {
296 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 }
322 }
323
324 if (flags & NL80211_SCAN_FLAG_LOW_PRIORITY)
325 params->max_out_time = 200;
326
327 not_bound:
328
329 for (band = IEEE80211_BAND_2GHZ; band < IEEE80211_NUM_BANDS; band++) {
330 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);
335 params->dwell[band].active = iwl_mvm_get_active_dwell(band,
336 n_ssids);
337 }
338 }
339
340 int 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, },
348 .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;
355 bool basic_ssid = !(mvm->fw->ucode_capa.flags &
356 IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID);
357 struct iwl_mvm_scan_params params = {};
358
359 lockdep_assert_held(&mvm->mutex);
360
361 /* we should have failed registration if scan_cmd was NULL */
362 if (WARN_ON(mvm->scan_cmd == NULL))
363 return -ENOMEM;
364
365 IWL_DEBUG_SCAN(mvm, "Handling mac80211 scan request\n");
366 mvm->scan_status = IWL_MVM_SCAN_OS;
367 memset(cmd, 0, ksize(cmd));
368
369 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);
373
374 iwl_mvm_scan_calc_params(mvm, vif, req->n_ssids, req->flags, &params);
375 cmd->max_out_time = cpu_to_le32(params.max_out_time);
376 cmd->suspend_time = cpu_to_le32(params.suspend_time);
377 if (params.passive_fragmented)
378 cmd->scan_flags |= SCAN_FLAGS_FRAGMENTED_SCAN;
379
380 cmd->rxon_flags = iwl_mvm_scan_rxon_flags(req->channels[0]->band);
381 cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP |
382 MAC_FILTER_IN_BEACON);
383
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
389 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);
397 cmd->scan_flags |= SCAN_FLAGS_PASSIVE2ACTIVE;
398 if (basic_ssid) {
399 ssid = req->ssids[0].ssid;
400 ssid_len = req->ssids[0].ssid_len;
401 }
402 } else {
403 cmd->passive2active = 0;
404 cmd->scan_flags &= ~SCAN_FLAGS_PASSIVE2ACTIVE;
405 }
406
407 iwl_mvm_scan_fill_ssids(cmd->direct_scan, req->ssids, req->n_ssids,
408 basic_ssid ? 1 : 0);
409
410 cmd->tx_cmd.tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL |
411 TX_CMD_FLG_BT_DIS);
412 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,
423 req->ie, req->ie_len, NULL, 0,
424 mvm->fw->ucode_capa.max_probe_length));
425
426 iwl_mvm_scan_fill_channels(cmd, req, basic_ssid, &params);
427
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
451 int 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
462 int 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
468 lockdep_assert_held(&mvm->mutex);
469
470 IWL_DEBUG_SCAN(mvm, "Scan complete: status=0x%x scanned channels=%d\n",
471 notif->status, notif->scanned_channels);
472
473 if (mvm->scan_status == IWL_MVM_SCAN_OS)
474 mvm->scan_status = IWL_MVM_SCAN_NONE;
475 ieee80211_scan_completed(mvm->hw, notif->status != SCAN_COMP_STATUS_OK);
476
477 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
478
479 return 0;
480 }
481
482 int iwl_mvm_rx_scan_offload_results(struct iwl_mvm *mvm,
483 struct iwl_rx_cmd_buffer *rxb,
484 struct iwl_device_cmd *cmd)
485 {
486 struct iwl_rx_packet *pkt = rxb_addr(rxb);
487 u8 client_bitmap = 0;
488
489 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 }
503 }
504
505 return 0;
506 }
507
508 static 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
525 /*
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 */
530 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
546 static int iwl_mvm_cancel_regular_scan(struct iwl_mvm *mvm)
547 {
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
553 if (mvm->scan_status == IWL_MVM_SCAN_NONE)
554 return 0;
555
556 if (iwl_mvm_is_radio_killed(mvm)) {
557 ieee80211_scan_completed(mvm->hw, true);
558 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
559 mvm->scan_status = IWL_MVM_SCAN_NONE;
560 return 0;
561 }
562
563 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
568 ret = iwl_mvm_send_cmd_pdu(mvm, SCAN_ABORT_CMD, 0, 0, NULL);
569 if (ret) {
570 IWL_ERR(mvm, "Couldn't send SCAN_ABORT_CMD: %d\n", ret);
571 /* mac80211's state will be cleaned in the nic_restart flow */
572 goto out_remove_notif;
573 }
574
575 return iwl_wait_notification(&mvm->notif_wait, &wait_scan_abort, HZ);
576
577 out_remove_notif:
578 iwl_remove_notification(&mvm->notif_wait, &wait_scan_abort);
579 return ret;
580 }
581
582 int 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);
587 u8 status, ebs_status;
588
589 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 }
602 /* scan status must be locked for proper checking */
603 lockdep_assert_held(&mvm->mutex);
604
605 IWL_DEBUG_SCAN(mvm,
606 "%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");
613
614
615 /* only call mac80211 completion if the stop was initiated by FW */
616 if (mvm->scan_status == IWL_MVM_SCAN_SCHED) {
617 mvm->scan_status = IWL_MVM_SCAN_NONE;
618 ieee80211_sched_scan_stopped(mvm->hw);
619 } 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);
623 }
624
625 mvm->last_ebs_successful = !ebs_status;
626
627 return 0;
628 }
629
630 static void iwl_scan_offload_build_tx_cmd(struct iwl_mvm *mvm,
631 struct ieee80211_vif *vif,
632 struct ieee80211_scan_ies *ies,
633 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,
648 ies->ies[band], ies->len[band],
649 ies->common_ies, ies->common_ie_len,
650 SCAN_OFFLOAD_PROBE_REQ_SIZE);
651 cmd->len = cpu_to_le16(cmd_len);
652 }
653
654 static void iwl_build_scan_cmd(struct iwl_mvm *mvm,
655 struct ieee80211_vif *vif,
656 struct cfg80211_sched_scan_request *req,
657 struct iwl_scan_offload_cmd *scan,
658 struct iwl_mvm_scan_params *params)
659 {
660 scan->channel_count = req->n_channels;
661 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);
665
666 scan->max_out_time = cpu_to_le32(params->max_out_time);
667 scan->suspend_time = cpu_to_le32(params->suspend_time);
668
669 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);
673
674 if (params->passive_fragmented)
675 scan->scan_flags |= SCAN_FLAGS_FRAGMENTED_SCAN;
676 }
677
678 static 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
692 static void iwl_scan_offload_build_ssid(struct cfg80211_sched_scan_request *req,
693 struct iwl_ssid_ie *direct_scan,
694 u32 *ssid_bitmap, bool basic_ssid)
695 {
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++) {
705 /* skip empty SSID matchsets */
706 if (!req->match_sets[i].ssid.ssid_len)
707 continue;
708 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);
712 }
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,
719 direct_scan);
720 if (index < 0) {
721 if (!req->ssids[j].ssid_len && basic_ssid)
722 continue;
723 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);
727 *ssid_bitmap |= BIT(i + 1);
728 i++;
729 } else {
730 *ssid_bitmap |= BIT(index + 1);
731 }
732 }
733 }
734
735 static void iwl_build_channel_cfg(struct iwl_mvm *mvm,
736 struct cfg80211_sched_scan_request *req,
737 u8 *channels_buffer,
738 enum ieee80211_band band,
739 int *head,
740 u32 ssid_bitmap,
741 struct iwl_mvm_scan_params *params)
742 {
743 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;
750 int i, index = 0;
751
752 for (i = 0; i < req->n_channels; i++) {
753 struct ieee80211_channel *chan = req->channels[i];
754
755 if (chan->band != band)
756 continue;
757
758 index = *head;
759 (*head)++;
760
761 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;
764
765 iter_count[index] = cpu_to_le16(1);
766 iter_interval[index] = 0;
767
768 if (!(chan->flags & IEEE80211_CHAN_NO_IR))
769 type[index] |=
770 cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_ACTIVE);
771
772 type[index] |= cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_FULL |
773 IWL_SCAN_OFFLOAD_CHANNEL_PARTIAL);
774
775 if (chan->flags & IEEE80211_CHAN_NO_HT40)
776 type[index] |=
777 cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_NARROW);
778
779 /* scan for all SSIDs from req->ssids */
780 type[index] |= cpu_to_le32(ssid_bitmap);
781 }
782 }
783
784 int iwl_mvm_config_sched_scan(struct iwl_mvm *mvm,
785 struct ieee80211_vif *vif,
786 struct cfg80211_sched_scan_request *req,
787 struct ieee80211_scan_ies *ies)
788 {
789 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;
792 u32 ssid_bitmap;
793 int cmd_len;
794 int ret;
795 u8 *probes;
796 bool basic_ssid = !(mvm->fw->ucode_capa.flags &
797 IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID);
798
799 struct iwl_scan_offload_cfg *scan_cfg;
800 struct iwl_host_cmd cmd = {
801 .id = SCAN_OFFLOAD_CONFIG_CMD,
802 };
803 struct iwl_mvm_scan_params params = {};
804
805 lockdep_assert_held(&mvm->mutex);
806
807 cmd_len = sizeof(struct iwl_scan_offload_cfg) +
808 mvm->fw->ucode_capa.n_scan_channels * IWL_SCAN_CHAN_SIZE +
809 2 * SCAN_OFFLOAD_PROBE_REQ_SIZE;
810
811 scan_cfg = kzalloc(cmd_len, GFP_KERNEL);
812 if (!scan_cfg)
813 return -ENOMEM;
814
815 probes = scan_cfg->data +
816 mvm->fw->ucode_capa.n_scan_channels * IWL_SCAN_CHAN_SIZE;
817
818 iwl_mvm_scan_calc_params(mvm, vif, req->n_ssids, 0, &params);
819 iwl_build_scan_cmd(mvm, vif, req, &scan_cfg->scan_cmd, &params);
820 scan_cfg->scan_cmd.len = cpu_to_le16(cmd_len);
821
822 iwl_scan_offload_build_ssid(req, scan_cfg->scan_cmd.direct_scan,
823 &ssid_bitmap, basic_ssid);
824 /* 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],
829 probes);
830 iwl_build_channel_cfg(mvm, req, scan_cfg->data,
831 IEEE80211_BAND_2GHZ, &head,
832 ssid_bitmap, &params);
833 }
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],
838 probes +
839 SCAN_OFFLOAD_PROBE_REQ_SIZE);
840 iwl_build_channel_cfg(mvm, req, scan_cfg->data,
841 IEEE80211_BAND_5GHZ, &head,
842 ssid_bitmap, &params);
843 }
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
856 int 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,
864 .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;
900 if (!req->n_match_sets || !req->match_sets[0].ssid.ssid_len)
901 profile_cfg->any_beacon_notify = SCAN_CLIENT_SCHED_SCAN;
902
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);
918 free_blacklist:
919 kfree(blacklist);
920
921 return ret;
922 }
923
924 int 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,
931 .schedule_line[0].delay = cpu_to_le16(req->interval / 1000),
932 .schedule_line[0].full_scan_mul = 1,
933
934 .schedule_line[1].iterations = 0xff,
935 .schedule_line[1].delay = cpu_to_le16(req->interval / 1000),
936 .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);
943 } else {
944 IWL_DEBUG_SCAN(mvm,
945 "Sending Scheduled scan without filtering\n");
946 scan_req.flags |= cpu_to_le16(IWL_SCAN_OFFLOAD_FLAG_PASS_ALL);
947 }
948
949 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
954 return iwl_mvm_send_cmd_pdu(mvm, SCAN_OFFLOAD_REQUEST_CMD, 0,
955 sizeof(scan_req), &scan_req);
956 }
957
958 static int iwl_mvm_send_scan_offload_abort(struct iwl_mvm *mvm)
959 {
960 int ret;
961 struct iwl_host_cmd cmd = {
962 .id = SCAN_OFFLOAD_ABORT_CMD,
963 };
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 */
969 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))
972 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);
987 ret = -ENOENT;
988 }
989
990 return ret;
991 }
992
993 int iwl_mvm_scan_offload_stop(struct iwl_mvm *mvm, bool notify)
994 {
995 int ret;
996 struct iwl_notification_wait wait_scan_done;
997 static const u8 scan_done_notif[] = { SCAN_OFFLOAD_COMPLETE, };
998 bool sched = mvm->scan_status == IWL_MVM_SCAN_SCHED;
999
1000 lockdep_assert_held(&mvm->mutex);
1001
1002 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");
1006 return 0;
1007 }
1008
1009 iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_done,
1010 scan_done_notif,
1011 ARRAY_SIZE(scan_done_notif),
1012 NULL, NULL);
1013
1014 ret = iwl_mvm_send_scan_offload_abort(mvm);
1015 if (ret) {
1016 IWL_DEBUG_SCAN(mvm, "Send stop %sscan failed %d\n",
1017 sched ? "offloaded " : "", ret);
1018 iwl_remove_notification(&mvm->notif_wait, &wait_scan_done);
1019 return ret;
1020 }
1021
1022 IWL_DEBUG_SCAN(mvm, "Successfully sent stop %sscan\n",
1023 sched ? "offloaded " : "");
1024
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
1036 if (notify) {
1037 if (sched)
1038 ieee80211_sched_scan_stopped(mvm->hw);
1039 else
1040 ieee80211_scan_completed(mvm->hw, true);
1041 }
1042
1043 return 0;
1044 }
1045
1046 static 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
1065 static void
1066 iwl_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
1085 static void
1086 iwl_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
1126 static void
1127 iwl_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 {
1131 memset(cmd, 0, ksize(cmd));
1132 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;
1137 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);
1141 cmd->iter_num = cpu_to_le32(1);
1142
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 }
1154 }
1155
1156 int 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
1250 int 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
1314 cmd->schedule[0].delay = cpu_to_le16(req->interval / MSEC_PER_SEC);
1315 cmd->schedule[0].iterations = IWL_FAST_SCHED_SCAN_ITERATIONS;
1316 cmd->schedule[0].full_scan_mul = 1;
1317
1318 cmd->schedule[1].delay = cpu_to_le16(req->interval / MSEC_PER_SEC);
1319 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
1345 int 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 }
This page took 0.077423 seconds and 5 git commands to generate.