GNU Linux-libre 4.19.245-gnu1
[releases.git] / drivers / net / wireless / intel / iwlwifi / fw / api / scan.h
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  * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10  * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
11  * Copyright(c) 2018        Intel Corporation
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of version 2 of the GNU General Public License as
15  * published by the Free Software Foundation.
16  *
17  * This program is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * General Public License for more details.
21  *
22  * The full GNU General Public License is included in this distribution
23  * in the file called COPYING.
24  *
25  * Contact Information:
26  *  Intel Linux Wireless <linuxwifi@intel.com>
27  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28  *
29  * BSD LICENSE
30  *
31  * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
32  * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
33  * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
34  * Copyright(c) 2018        Intel Corporation
35  * All rights reserved.
36  *
37  * Redistribution and use in source and binary forms, with or without
38  * modification, are permitted provided that the following conditions
39  * are met:
40  *
41  *  * Redistributions of source code must retain the above copyright
42  *    notice, this list of conditions and the following disclaimer.
43  *  * Redistributions in binary form must reproduce the above copyright
44  *    notice, this list of conditions and the following disclaimer in
45  *    the documentation and/or other materials provided with the
46  *    distribution.
47  *  * Neither the name Intel Corporation nor the names of its
48  *    contributors may be used to endorse or promote products derived
49  *    from this software without specific prior written permission.
50  *
51  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
52  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
53  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
54  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
55  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
61  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62  *
63  *****************************************************************************/
64
65 #ifndef __iwl_fw_api_scan_h__
66 #define __iwl_fw_api_scan_h__
67
68 /* Scan Commands, Responses, Notifications */
69
70 /* Max number of IEs for direct SSID scans in a command */
71 #define PROBE_OPTION_MAX                20
72
73 /**
74  * struct iwl_ssid_ie - directed scan network information element
75  *
76  * Up to 20 of these may appear in REPLY_SCAN_CMD,
77  * selected by "type" bit field in struct iwl_scan_channel;
78  * each channel may select different ssids from among the 20 entries.
79  * SSID IEs get transmitted in reverse order of entry.
80  *
81  * @id: element ID
82  * @len: element length
83  * @ssid: element (SSID) data
84  */
85 struct iwl_ssid_ie {
86         u8 id;
87         u8 len;
88         u8 ssid[IEEE80211_MAX_SSID_LEN];
89 } __packed; /* SCAN_DIRECT_SSID_IE_API_S_VER_1 */
90
91 /* scan offload */
92 #define IWL_SCAN_MAX_BLACKLIST_LEN      64
93 #define IWL_SCAN_SHORT_BLACKLIST_LEN    16
94 #define IWL_SCAN_MAX_PROFILES           11
95 #define SCAN_OFFLOAD_PROBE_REQ_SIZE     512
96
97 /* Default watchdog (in MS) for scheduled scan iteration */
98 #define IWL_SCHED_SCAN_WATCHDOG cpu_to_le16(15000)
99
100 #define IWL_GOOD_CRC_TH_DEFAULT cpu_to_le16(1)
101 #define CAN_ABORT_STATUS 1
102
103 #define IWL_FULL_SCAN_MULTIPLIER 5
104 #define IWL_FAST_SCHED_SCAN_ITERATIONS 3
105 #define IWL_MAX_SCHED_SCAN_PLANS 2
106
107 enum scan_framework_client {
108         SCAN_CLIENT_SCHED_SCAN          = BIT(0),
109         SCAN_CLIENT_NETDETECT           = BIT(1),
110         SCAN_CLIENT_ASSET_TRACKING      = BIT(2),
111 };
112
113 /**
114  * struct iwl_scan_offload_blacklist - SCAN_OFFLOAD_BLACKLIST_S
115  * @ssid:               MAC address to filter out
116  * @reported_rssi:      AP rssi reported to the host
117  * @client_bitmap: clients ignore this entry  - enum scan_framework_client
118  */
119 struct iwl_scan_offload_blacklist {
120         u8 ssid[ETH_ALEN];
121         u8 reported_rssi;
122         u8 client_bitmap;
123 } __packed;
124
125 enum iwl_scan_offload_network_type {
126         IWL_NETWORK_TYPE_BSS    = 1,
127         IWL_NETWORK_TYPE_IBSS   = 2,
128         IWL_NETWORK_TYPE_ANY    = 3,
129 };
130
131 enum iwl_scan_offload_band_selection {
132         IWL_SCAN_OFFLOAD_SELECT_2_4     = 0x4,
133         IWL_SCAN_OFFLOAD_SELECT_5_2     = 0x8,
134         IWL_SCAN_OFFLOAD_SELECT_ANY     = 0xc,
135 };
136
137 /**
138  * struct iwl_scan_offload_profile - SCAN_OFFLOAD_PROFILE_S
139  * @ssid_index:         index to ssid list in fixed part
140  * @unicast_cipher:     encryption algorithm to match - bitmap
141  * @auth_alg:           authentication algorithm to match - bitmap
142  * @network_type:       enum iwl_scan_offload_network_type
143  * @band_selection:     enum iwl_scan_offload_band_selection
144  * @client_bitmap:      clients waiting for match - enum scan_framework_client
145  * @reserved:           reserved
146  */
147 struct iwl_scan_offload_profile {
148         u8 ssid_index;
149         u8 unicast_cipher;
150         u8 auth_alg;
151         u8 network_type;
152         u8 band_selection;
153         u8 client_bitmap;
154         u8 reserved[2];
155 } __packed;
156
157 /**
158  * struct iwl_scan_offload_profile_cfg - SCAN_OFFLOAD_PROFILES_CFG_API_S_VER_1
159  * @profiles:           profiles to search for match
160  * @blacklist_len:      length of blacklist
161  * @num_profiles:       num of profiles in the list
162  * @match_notify:       clients waiting for match found notification
163  * @pass_match:         clients waiting for the results
164  * @active_clients:     active clients bitmap - enum scan_framework_client
165  * @any_beacon_notify:  clients waiting for match notification without match
166  * @reserved:           reserved
167  */
168 struct iwl_scan_offload_profile_cfg {
169         struct iwl_scan_offload_profile profiles[IWL_SCAN_MAX_PROFILES];
170         u8 blacklist_len;
171         u8 num_profiles;
172         u8 match_notify;
173         u8 pass_match;
174         u8 active_clients;
175         u8 any_beacon_notify;
176         u8 reserved[2];
177 } __packed;
178
179 /**
180  * struct iwl_scan_schedule_lmac - schedule of scan offload
181  * @delay:              delay between iterations, in seconds.
182  * @iterations:         num of scan iterations
183  * @full_scan_mul:      number of partial scans before each full scan
184  */
185 struct iwl_scan_schedule_lmac {
186         __le16 delay;
187         u8 iterations;
188         u8 full_scan_mul;
189 } __packed; /* SCAN_SCHEDULE_API_S */
190
191 enum iwl_scan_offload_complete_status {
192         IWL_SCAN_OFFLOAD_COMPLETED      = 1,
193         IWL_SCAN_OFFLOAD_ABORTED        = 2,
194 };
195
196 enum iwl_scan_ebs_status {
197         IWL_SCAN_EBS_SUCCESS,
198         IWL_SCAN_EBS_FAILED,
199         IWL_SCAN_EBS_CHAN_NOT_FOUND,
200         IWL_SCAN_EBS_INACTIVE,
201 };
202
203 /**
204  * struct iwl_scan_req_tx_cmd - SCAN_REQ_TX_CMD_API_S
205  * @tx_flags: combination of TX_CMD_FLG_*
206  * @rate_n_flags: rate for *all* Tx attempts, if TX_CMD_FLG_STA_RATE_MSK is
207  *      cleared. Combination of RATE_MCS_*
208  * @sta_id: index of destination station in FW station table
209  * @reserved: for alignment and future use
210  */
211 struct iwl_scan_req_tx_cmd {
212         __le32 tx_flags;
213         __le32 rate_n_flags;
214         u8 sta_id;
215         u8 reserved[3];
216 } __packed;
217
218 enum iwl_scan_channel_flags_lmac {
219         IWL_UNIFIED_SCAN_CHANNEL_FULL           = BIT(27),
220         IWL_UNIFIED_SCAN_CHANNEL_PARTIAL        = BIT(28),
221 };
222
223 /**
224  * struct iwl_scan_channel_cfg_lmac - SCAN_CHANNEL_CFG_S_VER2
225  * @flags:              bits 1-20: directed scan to i'th ssid
226  *                      other bits &enum iwl_scan_channel_flags_lmac
227  * @channel_num:        channel number 1-13 etc
228  * @iter_count:         scan iteration on this channel
229  * @iter_interval:      interval in seconds between iterations on one channel
230  */
231 struct iwl_scan_channel_cfg_lmac {
232         __le32 flags;
233         __le16 channel_num;
234         __le16 iter_count;
235         __le32 iter_interval;
236 } __packed;
237
238 /*
239  * struct iwl_scan_probe_segment - PROBE_SEGMENT_API_S_VER_1
240  * @offset: offset in the data block
241  * @len: length of the segment
242  */
243 struct iwl_scan_probe_segment {
244         __le16 offset;
245         __le16 len;
246 } __packed;
247
248 /* iwl_scan_probe_req - PROBE_REQUEST_FRAME_API_S_VER_2
249  * @mac_header: first (and common) part of the probe
250  * @band_data: band specific data
251  * @common_data: last (and common) part of the probe
252  * @buf: raw data block
253  */
254 struct iwl_scan_probe_req {
255         struct iwl_scan_probe_segment mac_header;
256         struct iwl_scan_probe_segment band_data[2];
257         struct iwl_scan_probe_segment common_data;
258         u8 buf[SCAN_OFFLOAD_PROBE_REQ_SIZE];
259 } __packed;
260
261 enum iwl_scan_channel_flags {
262         IWL_SCAN_CHANNEL_FLAG_EBS               = BIT(0),
263         IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE      = BIT(1),
264         IWL_SCAN_CHANNEL_FLAG_CACHE_ADD         = BIT(2),
265 };
266
267 /* struct iwl_scan_channel_opt - CHANNEL_OPTIMIZATION_API_S
268  * @flags: enum iwl_scan_channel_flags
269  * @non_ebs_ratio: defines the ratio of number of scan iterations where EBS is
270  *      involved.
271  *      1 - EBS is disabled.
272  *      2 - every second scan will be full scan(and so on).
273  */
274 struct iwl_scan_channel_opt {
275         __le16 flags;
276         __le16 non_ebs_ratio;
277 } __packed;
278
279 /**
280  * enum iwl_mvm_lmac_scan_flags - LMAC scan flags
281  * @IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL: pass all beacons and probe responses
282  *      without filtering.
283  * @IWL_MVM_LMAC_SCAN_FLAG_PASSIVE: force passive scan on all channels
284  * @IWL_MVM_LMAC_SCAN_FLAG_PRE_CONNECTION: single channel scan
285  * @IWL_MVM_LMAC_SCAN_FLAG_ITER_COMPLETE: send iteration complete notification
286  * @IWL_MVM_LMAC_SCAN_FLAG_MULTIPLE_SSIDS: multiple SSID matching
287  * @IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED: all passive scans will be fragmented
288  * @IWL_MVM_LMAC_SCAN_FLAGS_RRM_ENABLED: insert WFA vendor-specific TPC report
289  *      and DS parameter set IEs into probe requests.
290  * @IWL_MVM_LMAC_SCAN_FLAG_EXTENDED_DWELL: use extended dwell time on channels
291  *      1, 6 and 11.
292  * @IWL_MVM_LMAC_SCAN_FLAG_MATCH: Send match found notification on matches
293  */
294 enum iwl_mvm_lmac_scan_flags {
295         IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL         = BIT(0),
296         IWL_MVM_LMAC_SCAN_FLAG_PASSIVE          = BIT(1),
297         IWL_MVM_LMAC_SCAN_FLAG_PRE_CONNECTION   = BIT(2),
298         IWL_MVM_LMAC_SCAN_FLAG_ITER_COMPLETE    = BIT(3),
299         IWL_MVM_LMAC_SCAN_FLAG_MULTIPLE_SSIDS   = BIT(4),
300         IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED       = BIT(5),
301         IWL_MVM_LMAC_SCAN_FLAGS_RRM_ENABLED     = BIT(6),
302         IWL_MVM_LMAC_SCAN_FLAG_EXTENDED_DWELL   = BIT(7),
303         IWL_MVM_LMAC_SCAN_FLAG_MATCH            = BIT(9),
304 };
305
306 enum iwl_scan_priority {
307         IWL_SCAN_PRIORITY_LOW,
308         IWL_SCAN_PRIORITY_MEDIUM,
309         IWL_SCAN_PRIORITY_HIGH,
310 };
311
312 enum iwl_scan_priority_ext {
313         IWL_SCAN_PRIORITY_EXT_0_LOWEST,
314         IWL_SCAN_PRIORITY_EXT_1,
315         IWL_SCAN_PRIORITY_EXT_2,
316         IWL_SCAN_PRIORITY_EXT_3,
317         IWL_SCAN_PRIORITY_EXT_4,
318         IWL_SCAN_PRIORITY_EXT_5,
319         IWL_SCAN_PRIORITY_EXT_6,
320         IWL_SCAN_PRIORITY_EXT_7_HIGHEST,
321 };
322
323 /**
324  * struct iwl_scan_req_lmac - SCAN_REQUEST_CMD_API_S_VER_1
325  * @reserved1: for alignment and future use
326  * @n_channels: num of channels to scan
327  * @active_dwell: dwell time for active channels
328  * @passive_dwell: dwell time for passive channels
329  * @fragmented_dwell: dwell time for fragmented passive scan
330  * @extended_dwell: dwell time for channels 1, 6 and 11 (in certain cases)
331  * @reserved2: for alignment and future use
332  * @rx_chain_select: PHY_RX_CHAIN_* flags
333  * @scan_flags: &enum iwl_mvm_lmac_scan_flags
334  * @max_out_time: max time (in TU) to be out of associated channel
335  * @suspend_time: pause scan this long (TUs) when returning to service channel
336  * @flags: RXON flags
337  * @filter_flags: RXON filter
338  * @tx_cmd: tx command for active scan; for 2GHz and for 5GHz
339  * @direct_scan: list of SSIDs for directed active scan
340  * @scan_prio: enum iwl_scan_priority
341  * @iter_num: number of scan iterations
342  * @delay: delay in seconds before first iteration
343  * @schedule: two scheduling plans. The first one is finite, the second one can
344  *      be infinite.
345  * @channel_opt: channel optimization options, for full and partial scan
346  * @data: channel configuration and probe request packet.
347  */
348 struct iwl_scan_req_lmac {
349         /* SCAN_REQUEST_FIXED_PART_API_S_VER_7 */
350         __le32 reserved1;
351         u8 n_channels;
352         u8 active_dwell;
353         u8 passive_dwell;
354         u8 fragmented_dwell;
355         u8 extended_dwell;
356         u8 reserved2;
357         __le16 rx_chain_select;
358         __le32 scan_flags;
359         __le32 max_out_time;
360         __le32 suspend_time;
361         /* RX_ON_FLAGS_API_S_VER_1 */
362         __le32 flags;
363         __le32 filter_flags;
364         struct iwl_scan_req_tx_cmd tx_cmd[2];
365         struct iwl_ssid_ie direct_scan[PROBE_OPTION_MAX];
366         __le32 scan_prio;
367         /* SCAN_REQ_PERIODIC_PARAMS_API_S */
368         __le32 iter_num;
369         __le32 delay;
370         struct iwl_scan_schedule_lmac schedule[IWL_MAX_SCHED_SCAN_PLANS];
371         struct iwl_scan_channel_opt channel_opt[2];
372         u8 data[];
373 } __packed;
374
375 /**
376  * struct iwl_scan_results_notif - scan results for one channel -
377  *      SCAN_RESULT_NTF_API_S_VER_3
378  * @channel: which channel the results are from
379  * @band: 0 for 5.2 GHz, 1 for 2.4 GHz
380  * @probe_status: SCAN_PROBE_STATUS_*, indicates success of probe request
381  * @num_probe_not_sent: # of request that weren't sent due to not enough time
382  * @duration: duration spent in channel, in usecs
383  */
384 struct iwl_scan_results_notif {
385         u8 channel;
386         u8 band;
387         u8 probe_status;
388         u8 num_probe_not_sent;
389         __le32 duration;
390 } __packed;
391
392 /**
393  * struct iwl_lmac_scan_complete_notif - notifies end of scanning (all channels)
394  *      SCAN_COMPLETE_NTF_API_S_VER_3
395  * @scanned_channels: number of channels scanned (and number of valid results)
396  * @status: one of SCAN_COMP_STATUS_*
397  * @bt_status: BT on/off status
398  * @last_channel: last channel that was scanned
399  * @tsf_low: TSF timer (lower half) in usecs
400  * @tsf_high: TSF timer (higher half) in usecs
401  * @results: an array of scan results, only "scanned_channels" of them are valid
402  */
403 struct iwl_lmac_scan_complete_notif {
404         u8 scanned_channels;
405         u8 status;
406         u8 bt_status;
407         u8 last_channel;
408         __le32 tsf_low;
409         __le32 tsf_high;
410         struct iwl_scan_results_notif results[];
411 } __packed;
412
413 /**
414  * struct iwl_scan_offload_complete - PERIODIC_SCAN_COMPLETE_NTF_API_S_VER_2
415  * @last_schedule_line: last schedule line executed (fast or regular)
416  * @last_schedule_iteration: last scan iteration executed before scan abort
417  * @status: &enum iwl_scan_offload_complete_status
418  * @ebs_status: EBS success status &enum iwl_scan_ebs_status
419  * @time_after_last_iter: time in seconds elapsed after last iteration
420  * @reserved: reserved
421  */
422 struct iwl_periodic_scan_complete {
423         u8 last_schedule_line;
424         u8 last_schedule_iteration;
425         u8 status;
426         u8 ebs_status;
427         __le32 time_after_last_iter;
428         __le32 reserved;
429 } __packed;
430
431 /* UMAC Scan API */
432
433 /* The maximum of either of these cannot exceed 8, because we use an
434  * 8-bit mask (see IWL_MVM_SCAN_MASK in mvm.h).
435  */
436 #define IWL_MVM_MAX_UMAC_SCANS 8
437 #define IWL_MVM_MAX_LMAC_SCANS 1
438
439 enum scan_config_flags {
440         SCAN_CONFIG_FLAG_ACTIVATE                       = BIT(0),
441         SCAN_CONFIG_FLAG_DEACTIVATE                     = BIT(1),
442         SCAN_CONFIG_FLAG_FORBID_CHUB_REQS               = BIT(2),
443         SCAN_CONFIG_FLAG_ALLOW_CHUB_REQS                = BIT(3),
444         SCAN_CONFIG_FLAG_SET_TX_CHAINS                  = BIT(8),
445         SCAN_CONFIG_FLAG_SET_RX_CHAINS                  = BIT(9),
446         SCAN_CONFIG_FLAG_SET_AUX_STA_ID                 = BIT(10),
447         SCAN_CONFIG_FLAG_SET_ALL_TIMES                  = BIT(11),
448         SCAN_CONFIG_FLAG_SET_EFFECTIVE_TIMES            = BIT(12),
449         SCAN_CONFIG_FLAG_SET_CHANNEL_FLAGS              = BIT(13),
450         SCAN_CONFIG_FLAG_SET_LEGACY_RATES               = BIT(14),
451         SCAN_CONFIG_FLAG_SET_MAC_ADDR                   = BIT(15),
452         SCAN_CONFIG_FLAG_SET_FRAGMENTED                 = BIT(16),
453         SCAN_CONFIG_FLAG_CLEAR_FRAGMENTED               = BIT(17),
454         SCAN_CONFIG_FLAG_SET_CAM_MODE                   = BIT(18),
455         SCAN_CONFIG_FLAG_CLEAR_CAM_MODE                 = BIT(19),
456         SCAN_CONFIG_FLAG_SET_PROMISC_MODE               = BIT(20),
457         SCAN_CONFIG_FLAG_CLEAR_PROMISC_MODE             = BIT(21),
458         SCAN_CONFIG_FLAG_SET_LMAC2_FRAGMENTED           = BIT(22),
459         SCAN_CONFIG_FLAG_CLEAR_LMAC2_FRAGMENTED         = BIT(23),
460
461         /* Bits 26-31 are for num of channels in channel_array */
462 #define SCAN_CONFIG_N_CHANNELS(n) ((n) << 26)
463 };
464
465 enum scan_config_rates {
466         /* OFDM basic rates */
467         SCAN_CONFIG_RATE_6M     = BIT(0),
468         SCAN_CONFIG_RATE_9M     = BIT(1),
469         SCAN_CONFIG_RATE_12M    = BIT(2),
470         SCAN_CONFIG_RATE_18M    = BIT(3),
471         SCAN_CONFIG_RATE_24M    = BIT(4),
472         SCAN_CONFIG_RATE_36M    = BIT(5),
473         SCAN_CONFIG_RATE_48M    = BIT(6),
474         SCAN_CONFIG_RATE_54M    = BIT(7),
475         /* CCK basic rates */
476         SCAN_CONFIG_RATE_1M     = BIT(8),
477         SCAN_CONFIG_RATE_2M     = BIT(9),
478         SCAN_CONFIG_RATE_5M     = BIT(10),
479         SCAN_CONFIG_RATE_11M    = BIT(11),
480
481         /* Bits 16-27 are for supported rates */
482 #define SCAN_CONFIG_SUPPORTED_RATE(rate)        ((rate) << 16)
483 };
484
485 enum iwl_channel_flags {
486         IWL_CHANNEL_FLAG_EBS                            = BIT(0),
487         IWL_CHANNEL_FLAG_ACCURATE_EBS                   = BIT(1),
488         IWL_CHANNEL_FLAG_EBS_ADD                        = BIT(2),
489         IWL_CHANNEL_FLAG_PRE_SCAN_PASSIVE2ACTIVE        = BIT(3),
490 };
491
492 /**
493  * struct iwl_scan_dwell
494  * @active:             default dwell time for active scan
495  * @passive:            default dwell time for passive scan
496  * @fragmented:         default dwell time for fragmented scan
497  * @extended:           default dwell time for channels 1, 6 and 11
498  */
499 struct iwl_scan_dwell {
500         u8 active;
501         u8 passive;
502         u8 fragmented;
503         u8 extended;
504 } __packed;
505
506 /**
507  * struct iwl_scan_config
508  * @flags:                      enum scan_config_flags
509  * @tx_chains:                  valid_tx antenna - ANT_* definitions
510  * @rx_chains:                  valid_rx antenna - ANT_* definitions
511  * @legacy_rates:               default legacy rates - enum scan_config_rates
512  * @out_of_channel_time:        default max out of serving channel time
513  * @suspend_time:               default max suspend time
514  * @dwell:                      dwells for the scan
515  * @mac_addr:                   default mac address to be used in probes
516  * @bcast_sta_id:               the index of the station in the fw
517  * @channel_flags:              default channel flags - enum iwl_channel_flags
518  *                              scan_config_channel_flag
519  * @channel_array:              default supported channels
520  */
521 struct iwl_scan_config_v1 {
522         __le32 flags;
523         __le32 tx_chains;
524         __le32 rx_chains;
525         __le32 legacy_rates;
526         __le32 out_of_channel_time;
527         __le32 suspend_time;
528         struct iwl_scan_dwell dwell;
529         u8 mac_addr[ETH_ALEN];
530         u8 bcast_sta_id;
531         u8 channel_flags;
532         u8 channel_array[];
533 } __packed; /* SCAN_CONFIG_DB_CMD_API_S */
534
535 #define SCAN_TWO_LMACS 2
536 #define SCAN_LB_LMAC_IDX 0
537 #define SCAN_HB_LMAC_IDX 1
538
539 struct iwl_scan_config {
540         __le32 flags;
541         __le32 tx_chains;
542         __le32 rx_chains;
543         __le32 legacy_rates;
544         __le32 out_of_channel_time[SCAN_TWO_LMACS];
545         __le32 suspend_time[SCAN_TWO_LMACS];
546         struct iwl_scan_dwell dwell;
547         u8 mac_addr[ETH_ALEN];
548         u8 bcast_sta_id;
549         u8 channel_flags;
550         u8 channel_array[];
551 } __packed; /* SCAN_CONFIG_DB_CMD_API_S_3 */
552
553 /**
554  * enum iwl_umac_scan_flags - UMAC scan flags
555  * @IWL_UMAC_SCAN_FLAG_PREEMPTIVE: scan process triggered by this scan request
556  *      can be preempted by other scan requests with higher priority.
557  *      The low priority scan will be resumed when the higher proirity scan is
558  *      completed.
559  * @IWL_UMAC_SCAN_FLAG_START_NOTIF: notification will be sent to the driver
560  *      when scan starts.
561  */
562 enum iwl_umac_scan_flags {
563         IWL_UMAC_SCAN_FLAG_PREEMPTIVE           = BIT(0),
564         IWL_UMAC_SCAN_FLAG_START_NOTIF          = BIT(1),
565 };
566
567 enum iwl_umac_scan_uid_offsets {
568         IWL_UMAC_SCAN_UID_TYPE_OFFSET           = 0,
569         IWL_UMAC_SCAN_UID_SEQ_OFFSET            = 8,
570 };
571
572 enum iwl_umac_scan_general_flags {
573         IWL_UMAC_SCAN_GEN_FLAGS_PERIODIC                = BIT(0),
574         IWL_UMAC_SCAN_GEN_FLAGS_OVER_BT                 = BIT(1),
575         IWL_UMAC_SCAN_GEN_FLAGS_PASS_ALL                = BIT(2),
576         IWL_UMAC_SCAN_GEN_FLAGS_PASSIVE                 = BIT(3),
577         IWL_UMAC_SCAN_GEN_FLAGS_PRE_CONNECT             = BIT(4),
578         IWL_UMAC_SCAN_GEN_FLAGS_ITER_COMPLETE           = BIT(5),
579         IWL_UMAC_SCAN_GEN_FLAGS_MULTIPLE_SSID           = BIT(6),
580         IWL_UMAC_SCAN_GEN_FLAGS_FRAGMENTED              = BIT(7),
581         IWL_UMAC_SCAN_GEN_FLAGS_RRM_ENABLED             = BIT(8),
582         IWL_UMAC_SCAN_GEN_FLAGS_MATCH                   = BIT(9),
583         IWL_UMAC_SCAN_GEN_FLAGS_EXTENDED_DWELL          = BIT(10),
584         /* Extended dwell is obselete when adaptive dwell is used, making this
585          * bit reusable. Hence, probe request defer is used only when adaptive
586          * dwell is supported. */
587         IWL_UMAC_SCAN_GEN_FLAGS_PROB_REQ_DEFER_SUPP     = BIT(10),
588         IWL_UMAC_SCAN_GEN_FLAGS_LMAC2_FRAGMENTED        = BIT(11),
589         IWL_UMAC_SCAN_GEN_FLAGS_ADAPTIVE_DWELL          = BIT(13),
590         IWL_UMAC_SCAN_GEN_FLAGS_MAX_CHNL_TIME           = BIT(14),
591         IWL_UMAC_SCAN_GEN_FLAGS_PROB_REQ_HIGH_TX_RATE   = BIT(15),
592 };
593
594 /**
595  * enum iwl_umac_scan_general_flags2 - UMAC scan general flags #2
596  * @IWL_UMAC_SCAN_GEN_FLAGS2_NOTIF_PER_CHNL: Whether to send a complete
597  *      notification per channel or not.
598  */
599 enum iwl_umac_scan_general_flags2 {
600         IWL_UMAC_SCAN_GEN_FLAGS2_NOTIF_PER_CHNL = BIT(0),
601 };
602
603 /**
604  * struct iwl_scan_channel_cfg_umac
605  * @flags:              bitmap - 0-19:  directed scan to i'th ssid.
606  * @channel_num:        channel number 1-13 etc.
607  * @iter_count:         repetition count for the channel.
608  * @iter_interval:      interval between two scan iterations on one channel.
609  */
610 struct iwl_scan_channel_cfg_umac {
611         __le32 flags;
612         u8 channel_num;
613         u8 iter_count;
614         __le16 iter_interval;
615 } __packed; /* SCAN_CHANNEL_CFG_S_VER2 */
616
617 /**
618  * struct iwl_scan_umac_schedule
619  * @interval: interval in seconds between scan iterations
620  * @iter_count: num of scan iterations for schedule plan, 0xff for infinite loop
621  * @reserved: for alignment and future use
622  */
623 struct iwl_scan_umac_schedule {
624         __le16 interval;
625         u8 iter_count;
626         u8 reserved;
627 } __packed; /* SCAN_SCHED_PARAM_API_S_VER_1 */
628
629 /**
630  * struct iwl_scan_req_umac_tail - the rest of the UMAC scan request command
631  *      parameters following channels configuration array.
632  * @schedule: two scheduling plans.
633  * @delay: delay in TUs before starting the first scan iteration
634  * @reserved: for future use and alignment
635  * @preq: probe request with IEs blocks
636  * @direct_scan: list of SSIDs for directed active scan
637  */
638 struct iwl_scan_req_umac_tail {
639         /* SCAN_PERIODIC_PARAMS_API_S_VER_1 */
640         struct iwl_scan_umac_schedule schedule[IWL_MAX_SCHED_SCAN_PLANS];
641         __le16 delay;
642         __le16 reserved;
643         /* SCAN_PROBE_PARAMS_API_S_VER_1 */
644         struct iwl_scan_probe_req preq;
645         struct iwl_ssid_ie direct_scan[PROBE_OPTION_MAX];
646 } __packed;
647
648 /**
649  * struct iwl_scan_umac_chan_param
650  * @flags: channel flags &enum iwl_scan_channel_flags
651  * @count: num of channels in scan request
652  * @reserved: for future use and alignment
653  */
654 struct iwl_scan_umac_chan_param {
655         u8 flags;
656         u8 count;
657         __le16 reserved;
658 } __packed; /*SCAN_CHANNEL_PARAMS_API_S_VER_1 */
659
660 /**
661  * struct iwl_scan_req_umac
662  * @flags: &enum iwl_umac_scan_flags
663  * @uid: scan id, &enum iwl_umac_scan_uid_offsets
664  * @ooc_priority: out of channel priority - &enum iwl_scan_priority
665  * @general_flags: &enum iwl_umac_scan_general_flags
666  * @scan_start_mac_id: report the scan start TSF time according to this mac TSF
667  * @extended_dwell: dwell time for channels 1, 6 and 11
668  * @active_dwell: dwell time for active scan per LMAC
669  * @passive_dwell: dwell time for passive scan per LMAC
670  * @fragmented_dwell: dwell time for fragmented passive scan
671  * @adwell_default_n_aps: for adaptive dwell the default number of APs
672  *      per channel
673  * @adwell_default_n_aps_social: for adaptive dwell the default
674  *      number of APs per social (1,6,11) channel
675  * @general_flags2: &enum iwl_umac_scan_general_flags2
676  * @adwell_max_budget: for adaptive dwell the maximal budget of TU to be added
677  *      to total scan time
678  * @max_out_time: max out of serving channel time, per LMAC - for CDB there
679  *      are 2 LMACs
680  * @suspend_time: max suspend time, per LMAC - for CDB there are 2 LMACs
681  * @scan_priority: scan internal prioritization &enum iwl_scan_priority
682  * @num_of_fragments: Number of fragments needed for full coverage per band.
683  *      Relevant only for fragmented scan.
684  * @channel: &struct iwl_scan_umac_chan_param
685  * @reserved: for future use and alignment
686  * @reserved3: for future use and alignment
687  * @data: &struct iwl_scan_channel_cfg_umac and
688  *      &struct iwl_scan_req_umac_tail
689  */
690 struct iwl_scan_req_umac {
691         __le32 flags;
692         __le32 uid;
693         __le32 ooc_priority;
694         __le16 general_flags;
695         u8 reserved;
696         u8 scan_start_mac_id;
697         union {
698                 struct {
699                         u8 extended_dwell;
700                         u8 active_dwell;
701                         u8 passive_dwell;
702                         u8 fragmented_dwell;
703                         __le32 max_out_time;
704                         __le32 suspend_time;
705                         __le32 scan_priority;
706                         struct iwl_scan_umac_chan_param channel;
707                         u8 data[];
708                 } v1; /* SCAN_REQUEST_CMD_UMAC_API_S_VER_1 */
709                 struct {
710                         u8 extended_dwell;
711                         u8 active_dwell;
712                         u8 passive_dwell;
713                         u8 fragmented_dwell;
714                         __le32 max_out_time[SCAN_TWO_LMACS];
715                         __le32 suspend_time[SCAN_TWO_LMACS];
716                         __le32 scan_priority;
717                         struct iwl_scan_umac_chan_param channel;
718                         u8 data[];
719                 } v6; /* SCAN_REQUEST_CMD_UMAC_API_S_VER_6 */
720                 struct {
721                         u8 active_dwell;
722                         u8 passive_dwell;
723                         u8 fragmented_dwell;
724                         u8 adwell_default_n_aps;
725                         u8 adwell_default_n_aps_social;
726                         u8 reserved3;
727                         __le16 adwell_max_budget;
728                         __le32 max_out_time[SCAN_TWO_LMACS];
729                         __le32 suspend_time[SCAN_TWO_LMACS];
730                         __le32 scan_priority;
731                         struct iwl_scan_umac_chan_param channel;
732                         u8 data[];
733                 } v7; /* SCAN_REQUEST_CMD_UMAC_API_S_VER_7 */
734                 struct {
735                         u8 active_dwell[SCAN_TWO_LMACS];
736                         u8 reserved2;
737                         u8 adwell_default_n_aps;
738                         u8 adwell_default_n_aps_social;
739                         u8 general_flags2;
740                         __le16 adwell_max_budget;
741                         __le32 max_out_time[SCAN_TWO_LMACS];
742                         __le32 suspend_time[SCAN_TWO_LMACS];
743                         __le32 scan_priority;
744                         u8 passive_dwell[SCAN_TWO_LMACS];
745                         u8 num_of_fragments[SCAN_TWO_LMACS];
746                         struct iwl_scan_umac_chan_param channel;
747                         u8 data[];
748                 } v8; /* SCAN_REQUEST_CMD_UMAC_API_S_VER_8 */
749         };
750 } __packed;
751
752 #define IWL_SCAN_REQ_UMAC_SIZE_V8 sizeof(struct iwl_scan_req_umac)
753 #define IWL_SCAN_REQ_UMAC_SIZE_V7 48
754 #define IWL_SCAN_REQ_UMAC_SIZE_V6 44
755 #define IWL_SCAN_REQ_UMAC_SIZE_V1 36
756
757 /**
758  * struct iwl_umac_scan_abort
759  * @uid: scan id, &enum iwl_umac_scan_uid_offsets
760  * @flags: reserved
761  */
762 struct iwl_umac_scan_abort {
763         __le32 uid;
764         __le32 flags;
765 } __packed; /* SCAN_ABORT_CMD_UMAC_API_S_VER_1 */
766
767 /**
768  * struct iwl_umac_scan_complete
769  * @uid: scan id, &enum iwl_umac_scan_uid_offsets
770  * @last_schedule: last scheduling line
771  * @last_iter: last scan iteration number
772  * @status: &enum iwl_scan_offload_complete_status
773  * @ebs_status: &enum iwl_scan_ebs_status
774  * @time_from_last_iter: time elapsed from last iteration
775  * @reserved: for future use
776  */
777 struct iwl_umac_scan_complete {
778         __le32 uid;
779         u8 last_schedule;
780         u8 last_iter;
781         u8 status;
782         u8 ebs_status;
783         __le32 time_from_last_iter;
784         __le32 reserved;
785 } __packed; /* SCAN_COMPLETE_NTF_UMAC_API_S_VER_1 */
786
787 #define SCAN_OFFLOAD_MATCHING_CHANNELS_LEN 5
788 /**
789  * struct iwl_scan_offload_profile_match - match information
790  * @bssid: matched bssid
791  * @reserved: reserved
792  * @channel: channel where the match occurred
793  * @energy: energy
794  * @matching_feature: feature matches
795  * @matching_channels: bitmap of channels that matched, referencing
796  *      the channels passed in tue scan offload request
797  */
798 struct iwl_scan_offload_profile_match {
799         u8 bssid[ETH_ALEN];
800         __le16 reserved;
801         u8 channel;
802         u8 energy;
803         u8 matching_feature;
804         u8 matching_channels[SCAN_OFFLOAD_MATCHING_CHANNELS_LEN];
805 } __packed; /* SCAN_OFFLOAD_PROFILE_MATCH_RESULTS_S_VER_1 */
806
807 /**
808  * struct iwl_scan_offload_profiles_query - match results query response
809  * @matched_profiles: bitmap of matched profiles, referencing the
810  *      matches passed in the scan offload request
811  * @last_scan_age: age of the last offloaded scan
812  * @n_scans_done: number of offloaded scans done
813  * @gp2_d0u: GP2 when D0U occurred
814  * @gp2_invoked: GP2 when scan offload was invoked
815  * @resume_while_scanning: not used
816  * @self_recovery: obsolete
817  * @reserved: reserved
818  * @matches: array of match information, one for each match
819  */
820 struct iwl_scan_offload_profiles_query {
821         __le32 matched_profiles;
822         __le32 last_scan_age;
823         __le32 n_scans_done;
824         __le32 gp2_d0u;
825         __le32 gp2_invoked;
826         u8 resume_while_scanning;
827         u8 self_recovery;
828         __le16 reserved;
829         struct iwl_scan_offload_profile_match matches[IWL_SCAN_MAX_PROFILES];
830 } __packed; /* SCAN_OFFLOAD_PROFILES_QUERY_RSP_S_VER_2 */
831
832 /**
833  * struct iwl_umac_scan_iter_complete_notif - notifies end of scanning iteration
834  * @uid: scan id, &enum iwl_umac_scan_uid_offsets
835  * @scanned_channels: number of channels scanned and number of valid elements in
836  *      results array
837  * @status: one of SCAN_COMP_STATUS_*
838  * @bt_status: BT on/off status
839  * @last_channel: last channel that was scanned
840  * @start_tsf: TSF timer in usecs of the scan start time for the mac specified
841  *      in &struct iwl_scan_req_umac.
842  * @results: array of scan results, length in @scanned_channels
843  */
844 struct iwl_umac_scan_iter_complete_notif {
845         __le32 uid;
846         u8 scanned_channels;
847         u8 status;
848         u8 bt_status;
849         u8 last_channel;
850         __le64 start_tsf;
851         struct iwl_scan_results_notif results[];
852 } __packed; /* SCAN_ITER_COMPLETE_NTF_UMAC_API_S_VER_2 */
853
854 #endif /* __iwl_fw_api_scan_h__ */