GNU Linux-libre 4.19.304-gnu1
[releases.git] / drivers / net / wireless / intel / iwlwifi / mvm / mvm.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  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
25  * USA
26  *
27  * The full GNU General Public License is included in this distribution
28  * in the file called COPYING.
29  *
30  * Contact Information:
31  *  Intel Linux Wireless <linuxwifi@intel.com>
32  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
33  *
34  * BSD LICENSE
35  *
36  * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
37  * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
38  * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
39  * Copyright(c) 2018        Intel Corporation
40  * All rights reserved.
41  *
42  * Redistribution and use in source and binary forms, with or without
43  * modification, are permitted provided that the following conditions
44  * are met:
45  *
46  *  * Redistributions of source code must retain the above copyright
47  *    notice, this list of conditions and the following disclaimer.
48  *  * Redistributions in binary form must reproduce the above copyright
49  *    notice, this list of conditions and the following disclaimer in
50  *    the documentation and/or other materials provided with the
51  *    distribution.
52  *  * Neither the name Intel Corporation nor the names of its
53  *    contributors may be used to endorse or promote products derived
54  *    from this software without specific prior written permission.
55  *
56  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
57  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
58  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
59  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
60  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
61  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
62  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
63  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
64  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
65  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
66  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67  *
68  *****************************************************************************/
69
70 #ifndef __IWL_MVM_H__
71 #define __IWL_MVM_H__
72
73 #include <linux/list.h>
74 #include <linux/spinlock.h>
75 #include <linux/leds.h>
76 #include <linux/in6.h>
77
78 #ifdef CONFIG_THERMAL
79 #include <linux/thermal.h>
80 #endif
81
82 #include "iwl-op-mode.h"
83 #include "iwl-trans.h"
84 #include "fw/notif-wait.h"
85 #include "iwl-eeprom-parse.h"
86 #include "fw/file.h"
87 #include "iwl-config.h"
88 #include "sta.h"
89 #include "fw-api.h"
90 #include "constants.h"
91 #include "tof.h"
92 #include "fw/runtime.h"
93 #include "fw/dbg.h"
94 #include "fw/acpi.h"
95 #include "iwl-nvm-parse.h"
96
97 #include <linux/average.h>
98
99 #define IWL_MVM_MAX_ADDRESSES           5
100 /* RSSI offset for WkP */
101 #define IWL_RSSI_OFFSET 50
102 #define IWL_MVM_MISSED_BEACONS_THRESHOLD 8
103 /* A TimeUnit is 1024 microsecond */
104 #define MSEC_TO_TU(_msec)       (_msec*1000/1024)
105
106 /* For GO, this value represents the number of TUs before CSA "beacon
107  * 0" TBTT when the CSA time-event needs to be scheduled to start.  It
108  * must be big enough to ensure that we switch in time.
109  */
110 #define IWL_MVM_CHANNEL_SWITCH_TIME_GO          40
111
112 /* For client, this value represents the number of TUs before CSA
113  * "beacon 1" TBTT, instead.  This is because we don't know when the
114  * GO/AP will be in the new channel, so we switch early enough.
115  */
116 #define IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT      10
117
118 /*
119  * This value (in TUs) is used to fine tune the CSA NoA end time which should
120  * be just before "beacon 0" TBTT.
121  */
122 #define IWL_MVM_CHANNEL_SWITCH_MARGIN 4
123
124 /*
125  * Number of beacons to transmit on a new channel until we unblock tx to
126  * the stations, even if we didn't identify them on a new channel
127  */
128 #define IWL_MVM_CS_UNBLOCK_TX_TIMEOUT 3
129
130 /* offchannel queue towards mac80211 */
131 #define IWL_MVM_OFFCHANNEL_QUEUE 0
132
133 extern const struct ieee80211_ops iwl_mvm_hw_ops;
134
135 /**
136  * struct iwl_mvm_mod_params - module parameters for iwlmvm
137  * @init_dbg: if true, then the NIC won't be stopped if the INIT fw asserted.
138  *      We will register to mac80211 to have testmode working. The NIC must not
139  *      be up'ed after the INIT fw asserted. This is useful to be able to use
140  *      proprietary tools over testmode to debug the INIT fw.
141  * @tfd_q_hang_detect: enabled the detection of hung transmit queues
142  * @power_scheme: one of enum iwl_power_scheme
143  */
144 struct iwl_mvm_mod_params {
145         bool init_dbg;
146         bool tfd_q_hang_detect;
147         int power_scheme;
148 };
149 extern struct iwl_mvm_mod_params iwlmvm_mod_params;
150
151 struct iwl_mvm_phy_ctxt {
152         u16 id;
153         u16 color;
154         u32 ref;
155
156         enum nl80211_chan_width width;
157
158         /*
159          * TODO: This should probably be removed. Currently here only for rate
160          * scaling algorithm
161          */
162         struct ieee80211_channel *channel;
163 };
164
165 struct iwl_mvm_time_event_data {
166         struct ieee80211_vif *vif;
167         struct list_head list;
168         unsigned long end_jiffies;
169         u32 duration;
170         bool running;
171         u32 uid;
172
173         /*
174          * The access to the 'id' field must be done when the
175          * mvm->time_event_lock is held, as it value is used to indicate
176          * if the te is in the time event list or not (when id == TE_MAX)
177          */
178         u32 id;
179 };
180
181  /* Power management */
182
183 /**
184  * enum iwl_power_scheme
185  * @IWL_POWER_LEVEL_CAM - Continuously Active Mode
186  * @IWL_POWER_LEVEL_BPS - Balanced Power Save (default)
187  * @IWL_POWER_LEVEL_LP  - Low Power
188  */
189 enum iwl_power_scheme {
190         IWL_POWER_SCHEME_CAM = 1,
191         IWL_POWER_SCHEME_BPS,
192         IWL_POWER_SCHEME_LP
193 };
194
195 #define IWL_CONN_MAX_LISTEN_INTERVAL    10
196 #define IWL_UAPSD_MAX_SP                IEEE80211_WMM_IE_STA_QOSINFO_SP_ALL
197
198 #ifdef CONFIG_IWLWIFI_DEBUGFS
199 enum iwl_dbgfs_pm_mask {
200         MVM_DEBUGFS_PM_KEEP_ALIVE = BIT(0),
201         MVM_DEBUGFS_PM_SKIP_OVER_DTIM = BIT(1),
202         MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS = BIT(2),
203         MVM_DEBUGFS_PM_RX_DATA_TIMEOUT = BIT(3),
204         MVM_DEBUGFS_PM_TX_DATA_TIMEOUT = BIT(4),
205         MVM_DEBUGFS_PM_LPRX_ENA = BIT(6),
206         MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD = BIT(7),
207         MVM_DEBUGFS_PM_SNOOZE_ENABLE = BIT(8),
208         MVM_DEBUGFS_PM_UAPSD_MISBEHAVING = BIT(9),
209         MVM_DEBUGFS_PM_USE_PS_POLL = BIT(10),
210 };
211
212 struct iwl_dbgfs_pm {
213         u16 keep_alive_seconds;
214         u32 rx_data_timeout;
215         u32 tx_data_timeout;
216         bool skip_over_dtim;
217         u8 skip_dtim_periods;
218         bool lprx_ena;
219         u32 lprx_rssi_threshold;
220         bool snooze_ena;
221         bool uapsd_misbehaving;
222         bool use_ps_poll;
223         int mask;
224 };
225
226 /* beacon filtering */
227
228 enum iwl_dbgfs_bf_mask {
229         MVM_DEBUGFS_BF_ENERGY_DELTA = BIT(0),
230         MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA = BIT(1),
231         MVM_DEBUGFS_BF_ROAMING_STATE = BIT(2),
232         MVM_DEBUGFS_BF_TEMP_THRESHOLD = BIT(3),
233         MVM_DEBUGFS_BF_TEMP_FAST_FILTER = BIT(4),
234         MVM_DEBUGFS_BF_TEMP_SLOW_FILTER = BIT(5),
235         MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER = BIT(6),
236         MVM_DEBUGFS_BF_DEBUG_FLAG = BIT(7),
237         MVM_DEBUGFS_BF_ESCAPE_TIMER = BIT(8),
238         MVM_DEBUGFS_BA_ESCAPE_TIMER = BIT(9),
239         MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT = BIT(10),
240 };
241
242 struct iwl_dbgfs_bf {
243         u32 bf_energy_delta;
244         u32 bf_roaming_energy_delta;
245         u32 bf_roaming_state;
246         u32 bf_temp_threshold;
247         u32 bf_temp_fast_filter;
248         u32 bf_temp_slow_filter;
249         u32 bf_enable_beacon_filter;
250         u32 bf_debug_flag;
251         u32 bf_escape_timer;
252         u32 ba_escape_timer;
253         u32 ba_enable_beacon_abort;
254         int mask;
255 };
256 #endif
257
258 enum iwl_mvm_smps_type_request {
259         IWL_MVM_SMPS_REQ_BT_COEX,
260         IWL_MVM_SMPS_REQ_TT,
261         IWL_MVM_SMPS_REQ_PROT,
262         NUM_IWL_MVM_SMPS_REQ,
263 };
264
265 enum iwl_mvm_ref_type {
266         IWL_MVM_REF_UCODE_DOWN,
267         IWL_MVM_REF_SCAN,
268         IWL_MVM_REF_ROC,
269         IWL_MVM_REF_ROC_AUX,
270         IWL_MVM_REF_P2P_CLIENT,
271         IWL_MVM_REF_AP_IBSS,
272         IWL_MVM_REF_USER,
273         IWL_MVM_REF_TX,
274         IWL_MVM_REF_TX_AGG,
275         IWL_MVM_REF_ADD_IF,
276         IWL_MVM_REF_START_AP,
277         IWL_MVM_REF_BSS_CHANGED,
278         IWL_MVM_REF_PREPARE_TX,
279         IWL_MVM_REF_PROTECT_TDLS,
280         IWL_MVM_REF_CHECK_CTKILL,
281         IWL_MVM_REF_PRPH_READ,
282         IWL_MVM_REF_PRPH_WRITE,
283         IWL_MVM_REF_NMI,
284         IWL_MVM_REF_TM_CMD,
285         IWL_MVM_REF_EXIT_WORK,
286         IWL_MVM_REF_PROTECT_CSA,
287         IWL_MVM_REF_FW_DBG_COLLECT,
288         IWL_MVM_REF_INIT_UCODE,
289         IWL_MVM_REF_SENDING_CMD,
290         IWL_MVM_REF_RX,
291
292         /* update debugfs.c when changing this */
293
294         IWL_MVM_REF_COUNT,
295 };
296
297 enum iwl_bt_force_ant_mode {
298         BT_FORCE_ANT_DIS = 0,
299         BT_FORCE_ANT_AUTO,
300         BT_FORCE_ANT_BT,
301         BT_FORCE_ANT_WIFI,
302
303         BT_FORCE_ANT_MAX,
304 };
305
306 /**
307 * struct iwl_mvm_low_latency_cause - low latency set causes
308 * @LOW_LATENCY_TRAFFIC: indicates low latency traffic was detected
309 * @LOW_LATENCY_DEBUGFS: low latency mode set from debugfs
310 * @LOW_LATENCY_VCMD: low latency mode set from vendor command
311 */
312 enum iwl_mvm_low_latency_cause {
313         LOW_LATENCY_TRAFFIC = BIT(0),
314         LOW_LATENCY_DEBUGFS = BIT(1),
315         LOW_LATENCY_VCMD = BIT(2),
316 };
317
318 /**
319 * struct iwl_mvm_vif_bf_data - beacon filtering related data
320 * @bf_enabled: indicates if beacon filtering is enabled
321 * @ba_enabled: indicated if beacon abort is enabled
322 * @ave_beacon_signal: average beacon signal
323 * @last_cqm_event: rssi of the last cqm event
324 * @bt_coex_min_thold: minimum threshold for BT coex
325 * @bt_coex_max_thold: maximum threshold for BT coex
326 * @last_bt_coex_event: rssi of the last BT coex event
327 */
328 struct iwl_mvm_vif_bf_data {
329         bool bf_enabled;
330         bool ba_enabled;
331         int ave_beacon_signal;
332         int last_cqm_event;
333         int bt_coex_min_thold;
334         int bt_coex_max_thold;
335         int last_bt_coex_event;
336 };
337
338 /**
339  * struct iwl_mvm_vif - data per Virtual Interface, it is a MAC context
340  * @id: between 0 and 3
341  * @color: to solve races upon MAC addition and removal
342  * @ap_sta_id: the sta_id of the AP - valid only if VIF type is STA
343  * @bssid: BSSID for this (client) interface
344  * @associated: indicates that we're currently associated, used only for
345  *      managing the firmware state in iwl_mvm_bss_info_changed_station()
346  * @ap_assoc_sta_count: count of stations associated to us - valid only
347  *      if VIF type is AP
348  * @uploaded: indicates the MAC context has been added to the device
349  * @ap_ibss_active: indicates that AP/IBSS is configured and that the interface
350  *      should get quota etc.
351  * @pm_enabled - Indicate if MAC power management is allowed
352  * @monitor_active: indicates that monitor context is configured, and that the
353  *      interface should get quota etc.
354  * @low_latency: indicates low latency is set, see
355  *      enum &iwl_mvm_low_latency_cause for causes.
356  * @ps_disabled: indicates that this interface requires PS to be disabled
357  * @queue_params: QoS params for this MAC
358  * @bcast_sta: station used for broadcast packets. Used by the following
359  *  vifs: P2P_DEVICE, GO and AP.
360  * @beacon_skb: the skb used to hold the AP/GO beacon template
361  * @smps_requests: the SMPS requests of different parts of the driver,
362  *      combined on update to yield the overall request to mac80211.
363  * @beacon_stats: beacon statistics, containing the # of received beacons,
364  *      # of received beacons accumulated over FW restart, and the current
365  *      average signal of beacons retrieved from the firmware
366  * @csa_failed: CSA failed to schedule time event, report an error later
367  * @features: hw features active for this vif
368  */
369 struct iwl_mvm_vif {
370         struct iwl_mvm *mvm;
371         u16 id;
372         u16 color;
373         u8 ap_sta_id;
374
375         u8 bssid[ETH_ALEN];
376         bool associated;
377         u8 ap_assoc_sta_count;
378
379         u16 cab_queue;
380
381         bool uploaded;
382         bool ap_ibss_active;
383         bool pm_enabled;
384         bool monitor_active;
385         u8 low_latency;
386         bool ps_disabled;
387         struct iwl_mvm_vif_bf_data bf_data;
388
389         struct {
390                 u32 num_beacons, accu_num_beacons;
391                 u8 avg_signal;
392         } beacon_stats;
393
394         u32 ap_beacon_time;
395
396         enum iwl_tsf_id tsf_id;
397
398         /*
399          * QoS data from mac80211, need to store this here
400          * as mac80211 has a separate callback but we need
401          * to have the data for the MAC context
402          */
403         struct ieee80211_tx_queue_params queue_params[IEEE80211_NUM_ACS];
404         struct iwl_mvm_time_event_data time_event_data;
405         struct iwl_mvm_time_event_data hs_time_event_data;
406
407         struct iwl_mvm_int_sta bcast_sta;
408         struct iwl_mvm_int_sta mcast_sta;
409
410         /*
411          * Assigned while mac80211 has the interface in a channel context,
412          * or, for P2P Device, while it exists.
413          */
414         struct iwl_mvm_phy_ctxt *phy_ctxt;
415
416 #ifdef CONFIG_PM
417         /* WoWLAN GTK rekey data */
418         struct {
419                 u8 kck[NL80211_KCK_LEN], kek[NL80211_KEK_LEN];
420                 __le64 replay_ctr;
421                 bool valid;
422         } rekey_data;
423
424         int tx_key_idx;
425
426         bool seqno_valid;
427         u16 seqno;
428 #endif
429
430 #if IS_ENABLED(CONFIG_IPV6)
431         /* IPv6 addresses for WoWLAN */
432         struct in6_addr target_ipv6_addrs[IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_MAX];
433         unsigned long tentative_addrs[BITS_TO_LONGS(IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_MAX)];
434         int num_target_ipv6_addrs;
435 #endif
436
437 #ifdef CONFIG_IWLWIFI_DEBUGFS
438         struct dentry *dbgfs_dir;
439         struct dentry *dbgfs_slink;
440         struct iwl_dbgfs_pm dbgfs_pm;
441         struct iwl_dbgfs_bf dbgfs_bf;
442         struct iwl_mac_power_cmd mac_pwr_cmd;
443         int dbgfs_quota_min;
444 #endif
445
446         enum ieee80211_smps_mode smps_requests[NUM_IWL_MVM_SMPS_REQ];
447
448         /* FW identified misbehaving AP */
449         u8 uapsd_misbehaving_bssid[ETH_ALEN];
450
451         struct delayed_work uapsd_nonagg_detected_wk;
452
453         /* Indicates that CSA countdown may be started */
454         bool csa_countdown;
455         bool csa_failed;
456         u16 csa_target_freq;
457
458         /* Indicates that we are waiting for a beacon on a new channel */
459         bool csa_bcn_pending;
460
461         /* TCP Checksum Offload */
462         netdev_features_t features;
463 };
464
465 static inline struct iwl_mvm_vif *
466 iwl_mvm_vif_from_mac80211(struct ieee80211_vif *vif)
467 {
468         if (!vif)
469                 return NULL;
470         return (void *)vif->drv_priv;
471 }
472
473 extern const u8 tid_to_mac80211_ac[];
474
475 #define IWL_MVM_SCAN_STOPPING_SHIFT     8
476
477 enum iwl_scan_status {
478         IWL_MVM_SCAN_REGULAR            = BIT(0),
479         IWL_MVM_SCAN_SCHED              = BIT(1),
480         IWL_MVM_SCAN_NETDETECT          = BIT(2),
481
482         IWL_MVM_SCAN_STOPPING_REGULAR   = BIT(8),
483         IWL_MVM_SCAN_STOPPING_SCHED     = BIT(9),
484         IWL_MVM_SCAN_STOPPING_NETDETECT = BIT(10),
485
486         IWL_MVM_SCAN_REGULAR_MASK       = IWL_MVM_SCAN_REGULAR |
487                                           IWL_MVM_SCAN_STOPPING_REGULAR,
488         IWL_MVM_SCAN_SCHED_MASK         = IWL_MVM_SCAN_SCHED |
489                                           IWL_MVM_SCAN_STOPPING_SCHED,
490         IWL_MVM_SCAN_NETDETECT_MASK     = IWL_MVM_SCAN_NETDETECT |
491                                           IWL_MVM_SCAN_STOPPING_NETDETECT,
492
493         IWL_MVM_SCAN_STOPPING_MASK      = 0xff << IWL_MVM_SCAN_STOPPING_SHIFT,
494         IWL_MVM_SCAN_MASK               = 0xff,
495 };
496
497 enum iwl_mvm_scan_type {
498         IWL_SCAN_TYPE_NOT_SET,
499         IWL_SCAN_TYPE_UNASSOC,
500         IWL_SCAN_TYPE_WILD,
501         IWL_SCAN_TYPE_MILD,
502         IWL_SCAN_TYPE_FRAGMENTED,
503 };
504
505 enum iwl_mvm_sched_scan_pass_all_states {
506         SCHED_SCAN_PASS_ALL_DISABLED,
507         SCHED_SCAN_PASS_ALL_ENABLED,
508         SCHED_SCAN_PASS_ALL_FOUND,
509 };
510
511 /**
512  * struct iwl_mvm_tt_mgnt - Thermal Throttling Management structure
513  * @ct_kill_exit: worker to exit thermal kill
514  * @dynamic_smps: Is thermal throttling enabled dynamic_smps?
515  * @tx_backoff: The current thremal throttling tx backoff in uSec.
516  * @min_backoff: The minimal tx backoff due to power restrictions
517  * @params: Parameters to configure the thermal throttling algorithm.
518  * @throttle: Is thermal throttling is active?
519  */
520 struct iwl_mvm_tt_mgmt {
521         struct delayed_work ct_kill_exit;
522         bool dynamic_smps;
523         u32 tx_backoff;
524         u32 min_backoff;
525         struct iwl_tt_params params;
526         bool throttle;
527 };
528
529 #ifdef CONFIG_THERMAL
530 /**
531  *struct iwl_mvm_thermal_device - thermal zone related data
532  * @temp_trips: temperature thresholds for report
533  * @fw_trips_index: keep indexes to original array - temp_trips
534  * @tzone: thermal zone device data
535 */
536 struct iwl_mvm_thermal_device {
537         s16 temp_trips[IWL_MAX_DTS_TRIPS];
538         u8 fw_trips_index[IWL_MAX_DTS_TRIPS];
539         struct thermal_zone_device *tzone;
540 };
541
542 /*
543  * struct iwl_mvm_cooling_device
544  * @cur_state: current state
545  * @cdev: struct thermal cooling device
546  */
547 struct iwl_mvm_cooling_device {
548         u32 cur_state;
549         struct thermal_cooling_device *cdev;
550 };
551 #endif
552
553 #define IWL_MVM_NUM_LAST_FRAMES_UCODE_RATES 8
554
555 struct iwl_mvm_frame_stats {
556         u32 legacy_frames;
557         u32 ht_frames;
558         u32 vht_frames;
559         u32 bw_20_frames;
560         u32 bw_40_frames;
561         u32 bw_80_frames;
562         u32 bw_160_frames;
563         u32 sgi_frames;
564         u32 ngi_frames;
565         u32 siso_frames;
566         u32 mimo2_frames;
567         u32 agg_frames;
568         u32 ampdu_count;
569         u32 success_frames;
570         u32 fail_frames;
571         u32 last_rates[IWL_MVM_NUM_LAST_FRAMES_UCODE_RATES];
572         int last_frame_idx;
573 };
574
575 enum {
576         D0I3_DEFER_WAKEUP,
577         D0I3_PENDING_WAKEUP,
578 };
579
580 #define IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE 0xff
581 #define IWL_MVM_DEBUG_SET_TEMPERATURE_MIN -100
582 #define IWL_MVM_DEBUG_SET_TEMPERATURE_MAX 200
583
584 enum iwl_mvm_tdls_cs_state {
585         IWL_MVM_TDLS_SW_IDLE = 0,
586         IWL_MVM_TDLS_SW_REQ_SENT,
587         IWL_MVM_TDLS_SW_RESP_RCVD,
588         IWL_MVM_TDLS_SW_REQ_RCVD,
589         IWL_MVM_TDLS_SW_ACTIVE,
590 };
591
592 enum iwl_mvm_traffic_load {
593         IWL_MVM_TRAFFIC_LOW,
594         IWL_MVM_TRAFFIC_MEDIUM,
595         IWL_MVM_TRAFFIC_HIGH,
596 };
597
598 DECLARE_EWMA(rate, 16, 16)
599
600 struct iwl_mvm_tcm_mac {
601         struct {
602                 u32 pkts[IEEE80211_NUM_ACS];
603                 u32 airtime;
604         } tx;
605         struct {
606                 u32 pkts[IEEE80211_NUM_ACS];
607                 u32 airtime;
608                 u32 last_ampdu_ref;
609         } rx;
610         struct {
611                 /* track AP's transfer in client mode */
612                 u64 rx_bytes;
613                 struct ewma_rate rate;
614                 bool detected;
615         } uapsd_nonagg_detect;
616         bool opened_rx_ba_sessions;
617 };
618
619 struct iwl_mvm_tcm {
620         struct delayed_work work;
621         spinlock_t lock; /* used when time elapsed */
622         unsigned long ts; /* timestamp when period ends */
623         unsigned long ll_ts;
624         unsigned long uapsd_nonagg_ts;
625         bool paused;
626         struct iwl_mvm_tcm_mac data[NUM_MAC_INDEX_DRIVER];
627         struct {
628                 u32 elapsed; /* milliseconds for this TCM period */
629                 u32 airtime[NUM_MAC_INDEX_DRIVER];
630                 enum iwl_mvm_traffic_load load[NUM_MAC_INDEX_DRIVER];
631                 enum iwl_mvm_traffic_load band_load[NUM_NL80211_BANDS];
632                 enum iwl_mvm_traffic_load global_load;
633                 bool low_latency[NUM_MAC_INDEX_DRIVER];
634                 bool change[NUM_MAC_INDEX_DRIVER];
635                 bool global_change;
636         } result;
637 };
638
639 /**
640  * struct iwl_mvm_reorder_buffer - per ra/tid/queue reorder buffer
641  * @head_sn: reorder window head sn
642  * @num_stored: number of mpdus stored in the buffer
643  * @buf_size: the reorder buffer size as set by the last addba request
644  * @queue: queue of this reorder buffer
645  * @last_amsdu: track last ASMDU SN for duplication detection
646  * @last_sub_index: track ASMDU sub frame index for duplication detection
647  * @reorder_timer: timer for frames are in the reorder buffer. For AMSDU
648  *      it is the time of last received sub-frame
649  * @removed: prevent timer re-arming
650  * @valid: reordering is valid for this queue
651  * @lock: protect reorder buffer internal state
652  * @mvm: mvm pointer, needed for frame timer context
653  */
654 struct iwl_mvm_reorder_buffer {
655         u16 head_sn;
656         u16 num_stored;
657         u16 buf_size;
658         int queue;
659         u16 last_amsdu;
660         u8 last_sub_index;
661         struct timer_list reorder_timer;
662         bool removed;
663         bool valid;
664         spinlock_t lock;
665         struct iwl_mvm *mvm;
666 } ____cacheline_aligned_in_smp;
667
668 /**
669  * struct _iwl_mvm_reorder_buf_entry - reorder buffer entry per-queue/per-seqno
670  * @frames: list of skbs stored
671  * @reorder_time: time the packet was stored in the reorder buffer
672  */
673 struct _iwl_mvm_reorder_buf_entry {
674         struct sk_buff_head frames;
675         unsigned long reorder_time;
676 };
677
678 /* make this indirection to get the aligned thing */
679 struct iwl_mvm_reorder_buf_entry {
680         struct _iwl_mvm_reorder_buf_entry e;
681 }
682 #ifndef __CHECKER__
683 /* sparse doesn't like this construct: "bad integer constant expression" */
684 __aligned(roundup_pow_of_two(sizeof(struct _iwl_mvm_reorder_buf_entry)))
685 #endif
686 ;
687
688 /**
689  * struct iwl_mvm_baid_data - BA session data
690  * @sta_id: station id
691  * @tid: tid of the session
692  * @baid baid of the session
693  * @timeout: the timeout set in the addba request
694  * @entries_per_queue: # of buffers per queue, this actually gets
695  *      aligned up to avoid cache line sharing between queues
696  * @last_rx: last rx jiffies, updated only if timeout passed from last update
697  * @session_timer: timer to check if BA session expired, runs at 2 * timeout
698  * @mvm: mvm pointer, needed for timer context
699  * @reorder_buf: reorder buffer, allocated per queue
700  * @reorder_buf_data: data
701  */
702 struct iwl_mvm_baid_data {
703         struct rcu_head rcu_head;
704         u8 sta_id;
705         u8 tid;
706         u8 baid;
707         u16 timeout;
708         u16 entries_per_queue;
709         unsigned long last_rx;
710         struct timer_list session_timer;
711         struct iwl_mvm_baid_data __rcu **rcu_ptr;
712         struct iwl_mvm *mvm;
713         struct iwl_mvm_reorder_buffer reorder_buf[IWL_MAX_RX_HW_QUEUES];
714         struct iwl_mvm_reorder_buf_entry entries[];
715 };
716
717 static inline struct iwl_mvm_baid_data *
718 iwl_mvm_baid_data_from_reorder_buf(struct iwl_mvm_reorder_buffer *buf)
719 {
720         return (void *)((u8 *)buf -
721                         offsetof(struct iwl_mvm_baid_data, reorder_buf) -
722                         sizeof(*buf) * buf->queue);
723 }
724
725 /*
726  * enum iwl_mvm_queue_status - queue status
727  * @IWL_MVM_QUEUE_FREE: the queue is not allocated nor reserved
728  *      Basically, this means that this queue can be used for any purpose
729  * @IWL_MVM_QUEUE_RESERVED: queue is reserved but not yet in use
730  *      This is the state of a queue that has been dedicated for some RATID
731  *      (agg'd or not), but that hasn't yet gone through the actual enablement
732  *      of iwl_mvm_enable_txq(), and therefore no traffic can go through it yet.
733  *      Note that in this state there is no requirement to already know what TID
734  *      should be used with this queue, it is just marked as a queue that will
735  *      be used, and shouldn't be allocated to anyone else.
736  * @IWL_MVM_QUEUE_READY: queue is ready to be used
737  *      This is the state of a queue that has been fully configured (including
738  *      SCD pointers, etc), has a specific RA/TID assigned to it, and can be
739  *      used to send traffic.
740  * @IWL_MVM_QUEUE_SHARED: queue is shared, or in a process of becoming shared
741  *      This is a state in which a single queue serves more than one TID, all of
742  *      which are not aggregated. Note that the queue is only associated to one
743  *      RA.
744  * @IWL_MVM_QUEUE_INACTIVE: queue is allocated but no traffic on it
745  *      This is a state of a queue that has had traffic on it, but during the
746  *      last %IWL_MVM_DQA_QUEUE_TIMEOUT time period there has been no traffic on
747  *      it. In this state, when a new queue is needed to be allocated but no
748  *      such free queue exists, an inactive queue might be freed and given to
749  *      the new RA/TID.
750  * @IWL_MVM_QUEUE_RECONFIGURING: queue is being reconfigured
751  *      This is the state of a queue that has had traffic pass through it, but
752  *      needs to be reconfigured for some reason, e.g. the queue needs to
753  *      become unshared and aggregations re-enabled on.
754  */
755 enum iwl_mvm_queue_status {
756         IWL_MVM_QUEUE_FREE,
757         IWL_MVM_QUEUE_RESERVED,
758         IWL_MVM_QUEUE_READY,
759         IWL_MVM_QUEUE_SHARED,
760         IWL_MVM_QUEUE_INACTIVE,
761         IWL_MVM_QUEUE_RECONFIGURING,
762 };
763
764 #define IWL_MVM_DQA_QUEUE_TIMEOUT       (5 * HZ)
765 #define IWL_MVM_INVALID_QUEUE           0xFFFF
766
767 #define IWL_MVM_NUM_CIPHERS             10
768
769 struct iwl_mvm_sar_profile {
770         bool enabled;
771         u8 table[ACPI_SAR_TABLE_SIZE];
772 };
773
774 struct iwl_mvm_geo_profile {
775         u8 values[ACPI_GEO_TABLE_SIZE];
776 };
777
778 struct iwl_mvm {
779         /* for logger access */
780         struct device *dev;
781
782         struct iwl_trans *trans;
783         const struct iwl_fw *fw;
784         const struct iwl_cfg *cfg;
785         struct iwl_phy_db *phy_db;
786         struct ieee80211_hw *hw;
787
788         /* for protecting access to iwl_mvm */
789         struct mutex mutex;
790         struct list_head async_handlers_list;
791         spinlock_t async_handlers_lock;
792         struct work_struct async_handlers_wk;
793
794         struct work_struct roc_done_wk;
795
796         unsigned long init_status;
797
798         unsigned long status;
799
800         u32 queue_sync_cookie;
801         atomic_t queue_sync_counter;
802         /*
803          * for beacon filtering -
804          * currently only one interface can be supported
805          */
806         struct iwl_mvm_vif *bf_allowed_vif;
807
808         bool hw_registered;
809         bool calibrating;
810         u32 error_event_table[2];
811         u32 log_event_table;
812         u32 umac_error_event_table;
813         bool support_umac_log;
814
815         u32 ampdu_ref;
816         bool ampdu_toggle;
817
818         struct iwl_notif_wait_data notif_wait;
819
820         union {
821                 struct mvm_statistics_rx_v3 rx_stats_v3;
822                 struct mvm_statistics_rx rx_stats;
823         };
824
825         struct {
826                 u64 rx_time;
827                 u64 tx_time;
828                 u64 on_time_rf;
829                 u64 on_time_scan;
830         } radio_stats, accu_radio_stats;
831
832         u16 hw_queue_to_mac80211[IWL_MAX_TVQM_QUEUES];
833
834         struct {
835                 u8 hw_queue_refcount;
836                 u8 ra_sta_id; /* The RA this queue is mapped to, if exists */
837                 bool reserved; /* Is this the TXQ reserved for a STA */
838                 u8 mac80211_ac; /* The mac80211 AC this queue is mapped to */
839                 u8 txq_tid; /* The TID "owner" of this queue*/
840                 u16 tid_bitmap; /* Bitmap of the TIDs mapped to this queue */
841                 /* Timestamp for inactivation per TID of this queue */
842                 unsigned long last_frame_time[IWL_MAX_TID_COUNT + 1];
843                 enum iwl_mvm_queue_status status;
844         } queue_info[IWL_MAX_HW_QUEUES];
845         spinlock_t queue_info_lock; /* For syncing queue mgmt operations */
846         struct work_struct add_stream_wk; /* To add streams to queues */
847
848         atomic_t mac80211_queue_stop_count[IEEE80211_MAX_QUEUES];
849
850         const char *nvm_file_name;
851         struct iwl_nvm_data *nvm_data;
852         /* NVM sections */
853         struct iwl_nvm_section nvm_sections[NVM_MAX_NUM_SECTIONS];
854
855         struct iwl_fw_runtime fwrt;
856
857         /* EEPROM MAC addresses */
858         struct mac_address addresses[IWL_MVM_MAX_ADDRESSES];
859
860         /* data related to data path */
861         struct iwl_rx_phy_info last_phy_info;
862         struct ieee80211_sta __rcu *fw_id_to_mac_id[IWL_MVM_STATION_COUNT];
863         unsigned long sta_deferred_frames[BITS_TO_LONGS(IWL_MVM_STATION_COUNT)];
864         u8 rx_ba_sessions;
865
866         /* configured by mac80211 */
867         u32 rts_threshold;
868
869         /* Scan status, cmd (pre-allocated) and auxiliary station */
870         unsigned int scan_status;
871         void *scan_cmd;
872         struct iwl_mcast_filter_cmd *mcast_filter_cmd;
873         /* For CDB this is low band scan type, for non-CDB - type. */
874         enum iwl_mvm_scan_type scan_type;
875         enum iwl_mvm_scan_type hb_scan_type;
876
877         enum iwl_mvm_sched_scan_pass_all_states sched_scan_pass_all;
878         struct delayed_work scan_timeout_dwork;
879
880         /* max number of simultaneous scans the FW supports */
881         unsigned int max_scans;
882
883         /* UMAC scan tracking */
884         u32 scan_uid_status[IWL_MVM_MAX_UMAC_SCANS];
885
886         /* start time of last scan in TSF of the mac that requested the scan */
887         u64 scan_start;
888
889         /* the vif that requested the current scan */
890         struct iwl_mvm_vif *scan_vif;
891
892         /* rx chain antennas set through debugfs for the scan command */
893         u8 scan_rx_ant;
894
895 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
896         /* broadcast filters to configure for each associated station */
897         const struct iwl_fw_bcast_filter *bcast_filters;
898 #ifdef CONFIG_IWLWIFI_DEBUGFS
899         struct {
900                 bool override;
901                 struct iwl_bcast_filter_cmd cmd;
902         } dbgfs_bcast_filtering;
903 #endif
904 #endif
905
906         /* Internal station */
907         struct iwl_mvm_int_sta aux_sta;
908         struct iwl_mvm_int_sta snif_sta;
909
910         bool last_ebs_successful;
911
912         u8 scan_last_antenna_idx; /* to toggle TX between antennas */
913         u8 mgmt_last_antenna_idx;
914
915         /* last smart fifo state that was successfully sent to firmware */
916         enum iwl_sf_state sf_state;
917
918 #ifdef CONFIG_IWLWIFI_DEBUGFS
919         struct dentry *debugfs_dir;
920         u32 dbgfs_sram_offset, dbgfs_sram_len;
921         u32 dbgfs_prph_reg_addr;
922         bool disable_power_off;
923         bool disable_power_off_d3;
924
925         bool scan_iter_notif_enabled;
926
927         struct debugfs_blob_wrapper nvm_hw_blob;
928         struct debugfs_blob_wrapper nvm_sw_blob;
929         struct debugfs_blob_wrapper nvm_calib_blob;
930         struct debugfs_blob_wrapper nvm_prod_blob;
931         struct debugfs_blob_wrapper nvm_phy_sku_blob;
932
933         struct iwl_mvm_frame_stats drv_rx_stats;
934         spinlock_t drv_stats_lock;
935         u16 dbgfs_rx_phyinfo;
936 #endif
937
938         struct iwl_mvm_phy_ctxt phy_ctxts[NUM_PHY_CTX];
939
940         struct list_head time_event_list;
941         spinlock_t time_event_lock;
942
943         /*
944          * A bitmap indicating the index of the key in use. The firmware
945          * can hold 16 keys at most. Reflect this fact.
946          */
947         unsigned long fw_key_table[BITS_TO_LONGS(STA_KEY_MAX_NUM)];
948         u8 fw_key_deleted[STA_KEY_MAX_NUM];
949
950         /* references taken by the driver and spinlock protecting them */
951         spinlock_t refs_lock;
952         u8 refs[IWL_MVM_REF_COUNT];
953
954         u8 vif_count;
955
956         /* -1 for always, 0 for never, >0 for that many times */
957         s8 fw_restart;
958
959 #ifdef CONFIG_IWLWIFI_LEDS
960         struct led_classdev led;
961 #endif
962
963         struct ieee80211_vif *p2p_device_vif;
964
965 #ifdef CONFIG_PM
966         struct wiphy_wowlan_support wowlan;
967         int gtk_ivlen, gtk_icvlen, ptk_ivlen, ptk_icvlen;
968
969         /* sched scan settings for net detect */
970         struct ieee80211_scan_ies nd_ies;
971         struct cfg80211_match_set *nd_match_sets;
972         int n_nd_match_sets;
973         struct ieee80211_channel **nd_channels;
974         int n_nd_channels;
975         bool net_detect;
976 #ifdef CONFIG_IWLWIFI_DEBUGFS
977         bool d3_wake_sysassert;
978         bool d3_test_active;
979         bool store_d3_resume_sram;
980         void *d3_resume_sram;
981         u32 d3_test_pme_ptr;
982         struct ieee80211_vif *keep_vif;
983         u32 last_netdetect_scans; /* no. of scans in the last net-detect wake */
984 #endif
985 #endif
986
987         /* d0i3 */
988         u8 d0i3_ap_sta_id;
989         bool d0i3_offloading;
990         struct work_struct d0i3_exit_work;
991         struct sk_buff_head d0i3_tx;
992         /* protect d0i3_suspend_flags */
993         struct mutex d0i3_suspend_mutex;
994         unsigned long d0i3_suspend_flags;
995         /* sync d0i3_tx queue and IWL_MVM_STATUS_IN_D0I3 status flag */
996         spinlock_t d0i3_tx_lock;
997         wait_queue_head_t d0i3_exit_waitq;
998         wait_queue_head_t rx_sync_waitq;
999
1000         /* BT-Coex */
1001         struct iwl_bt_coex_profile_notif last_bt_notif;
1002         struct iwl_bt_coex_ci_cmd last_bt_ci_cmd;
1003
1004         u8 bt_tx_prio;
1005         enum iwl_bt_force_ant_mode bt_force_ant_mode;
1006
1007         /* Aux ROC */
1008         struct list_head aux_roc_te_list;
1009
1010         /* Thermal Throttling and CTkill */
1011         struct iwl_mvm_tt_mgmt thermal_throttle;
1012 #ifdef CONFIG_THERMAL
1013         struct iwl_mvm_thermal_device tz_device;
1014         struct iwl_mvm_cooling_device cooling_dev;
1015 #endif
1016
1017         s32 temperature;        /* Celsius */
1018         /*
1019          * Debug option to set the NIC temperature. This option makes the
1020          * driver think this is the actual NIC temperature, and ignore the
1021          * real temperature that is received from the fw
1022          */
1023         bool temperature_test;  /* Debug test temperature is enabled */
1024
1025         unsigned long bt_coex_last_tcm_ts;
1026         struct iwl_mvm_tcm tcm;
1027
1028         u8 uapsd_noagg_bssid_write_idx;
1029         struct mac_address uapsd_noagg_bssids[IWL_MVM_UAPSD_NOAGG_BSSIDS_NUM]
1030                 __aligned(2);
1031
1032         struct iwl_time_quota_cmd last_quota_cmd;
1033
1034 #ifdef CONFIG_NL80211_TESTMODE
1035         u32 noa_duration;
1036         struct ieee80211_vif *noa_vif;
1037 #endif
1038
1039         /* Tx queues */
1040         u16 aux_queue;
1041         u16 snif_queue;
1042         u16 probe_queue;
1043         u16 p2p_dev_queue;
1044
1045         /* Indicate if device power save is allowed */
1046         u8 ps_disabled; /* u8 instead of bool to ease debugfs_create_* usage */
1047         unsigned int max_amsdu_len; /* used for debugfs only */
1048
1049         struct ieee80211_vif __rcu *csa_vif;
1050         struct ieee80211_vif __rcu *csa_tx_blocked_vif;
1051         u8 csa_tx_block_bcn_timeout;
1052
1053         /* system time of last beacon (for AP/GO interface) */
1054         u32 ap_last_beacon_gp2;
1055
1056         /* indicates that we transmitted the last beacon */
1057         bool ibss_manager;
1058
1059         bool lar_regdom_set;
1060         enum iwl_mcc_source mcc_src;
1061
1062         /* TDLS channel switch data */
1063         struct {
1064                 struct delayed_work dwork;
1065                 enum iwl_mvm_tdls_cs_state state;
1066
1067                 /*
1068                  * Current cs sta - might be different from periodic cs peer
1069                  * station. Value is meaningless when the cs-state is idle.
1070                  */
1071                 u8 cur_sta_id;
1072
1073                 /* TDLS periodic channel-switch peer */
1074                 struct {
1075                         u8 sta_id;
1076                         u8 op_class;
1077                         bool initiator; /* are we the link initiator */
1078                         struct cfg80211_chan_def chandef;
1079                         struct sk_buff *skb; /* ch sw template */
1080                         u32 ch_sw_tm_ie;
1081
1082                         /* timestamp of last ch-sw request sent (GP2 time) */
1083                         u32 sent_timestamp;
1084                 } peer;
1085         } tdls_cs;
1086
1087
1088         u32 ciphers[IWL_MVM_NUM_CIPHERS];
1089         struct ieee80211_cipher_scheme cs[IWL_UCODE_MAX_CS];
1090         struct iwl_mvm_tof_data tof_data;
1091
1092         struct ieee80211_vif *nan_vif;
1093 #define IWL_MAX_BAID    32
1094         struct iwl_mvm_baid_data __rcu *baid_map[IWL_MAX_BAID];
1095
1096         /*
1097          * Drop beacons from other APs in AP mode when there are no connected
1098          * clients.
1099          */
1100         bool drop_bcn_ap_mode;
1101
1102         struct delayed_work cs_tx_unblock_dwork;
1103
1104         /* does a monitor vif exist (only one can exist hence bool) */
1105         bool monitor_on;
1106 #ifdef CONFIG_ACPI
1107         struct iwl_mvm_sar_profile sar_profiles[ACPI_SAR_PROFILE_NUM];
1108         struct iwl_mvm_geo_profile geo_profiles[ACPI_NUM_GEO_PROFILES];
1109 #endif
1110 };
1111
1112 /* Extract MVM priv from op_mode and _hw */
1113 #define IWL_OP_MODE_GET_MVM(_iwl_op_mode)               \
1114         ((struct iwl_mvm *)(_iwl_op_mode)->op_mode_specific)
1115
1116 #define IWL_MAC80211_GET_MVM(_hw)                       \
1117         IWL_OP_MODE_GET_MVM((struct iwl_op_mode *)((_hw)->priv))
1118
1119 /**
1120  * enum iwl_mvm_status - MVM status bits
1121  * @IWL_MVM_STATUS_HW_RFKILL: HW RF-kill is asserted
1122  * @IWL_MVM_STATUS_HW_CTKILL: CT-kill is active
1123  * @IWL_MVM_STATUS_ROC_RUNNING: remain-on-channel is running
1124  * @IWL_MVM_STATUS_HW_RESTART_REQUESTED: HW restart was requested
1125  * @IWL_MVM_STATUS_IN_HW_RESTART: HW restart is active
1126  * @IWL_MVM_STATUS_IN_D0I3: NIC is in D0i3
1127  * @IWL_MVM_STATUS_ROC_AUX_RUNNING: AUX remain-on-channel is running
1128  * @IWL_MVM_STATUS_D3_RECONFIG: D3 reconfiguration is being done
1129  * @IWL_MVM_STATUS_FIRMWARE_RUNNING: firmware is running
1130  * @IWL_MVM_STATUS_NEED_FLUSH_P2P: need to flush P2P bcast STA
1131  */
1132 enum iwl_mvm_status {
1133         IWL_MVM_STATUS_HW_RFKILL,
1134         IWL_MVM_STATUS_HW_CTKILL,
1135         IWL_MVM_STATUS_ROC_RUNNING,
1136         IWL_MVM_STATUS_HW_RESTART_REQUESTED,
1137         IWL_MVM_STATUS_IN_HW_RESTART,
1138         IWL_MVM_STATUS_IN_D0I3,
1139         IWL_MVM_STATUS_ROC_AUX_RUNNING,
1140         IWL_MVM_STATUS_D3_RECONFIG,
1141         IWL_MVM_STATUS_FIRMWARE_RUNNING,
1142         IWL_MVM_STATUS_NEED_FLUSH_P2P,
1143 };
1144
1145 /* Keep track of completed init configuration */
1146 enum iwl_mvm_init_status {
1147         IWL_MVM_INIT_STATUS_THERMAL_INIT_COMPLETE = BIT(0),
1148         IWL_MVM_INIT_STATUS_LEDS_INIT_COMPLETE = BIT(1),
1149         IWL_MVM_INIT_STATUS_REG_HW_INIT_COMPLETE = BIT(2),
1150         IWL_MVM_INIT_STATUS_TOF_INIT_COMPLETE = BIT(3),
1151 };
1152
1153 static inline bool iwl_mvm_is_radio_killed(struct iwl_mvm *mvm)
1154 {
1155         return test_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status) ||
1156                test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status);
1157 }
1158
1159 static inline bool iwl_mvm_is_radio_hw_killed(struct iwl_mvm *mvm)
1160 {
1161         return test_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status);
1162 }
1163
1164 static inline bool iwl_mvm_firmware_running(struct iwl_mvm *mvm)
1165 {
1166         return test_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1167 }
1168
1169 /* Must be called with rcu_read_lock() held and it can only be
1170  * released when mvmsta is not needed anymore.
1171  */
1172 static inline struct iwl_mvm_sta *
1173 iwl_mvm_sta_from_staid_rcu(struct iwl_mvm *mvm, u8 sta_id)
1174 {
1175         struct ieee80211_sta *sta;
1176
1177         if (sta_id >= ARRAY_SIZE(mvm->fw_id_to_mac_id))
1178                 return NULL;
1179
1180         sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
1181
1182         /* This can happen if the station has been removed right now */
1183         if (IS_ERR_OR_NULL(sta))
1184                 return NULL;
1185
1186         return iwl_mvm_sta_from_mac80211(sta);
1187 }
1188
1189 static inline struct iwl_mvm_sta *
1190 iwl_mvm_sta_from_staid_protected(struct iwl_mvm *mvm, u8 sta_id)
1191 {
1192         struct ieee80211_sta *sta;
1193
1194         if (sta_id >= ARRAY_SIZE(mvm->fw_id_to_mac_id))
1195                 return NULL;
1196
1197         sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
1198                                         lockdep_is_held(&mvm->mutex));
1199
1200         /* This can happen if the station has been removed right now */
1201         if (IS_ERR_OR_NULL(sta))
1202                 return NULL;
1203
1204         return iwl_mvm_sta_from_mac80211(sta);
1205 }
1206
1207 static inline bool iwl_mvm_is_d0i3_supported(struct iwl_mvm *mvm)
1208 {
1209         return !iwlwifi_mod_params.d0i3_disable &&
1210                 fw_has_capa(&mvm->fw->ucode_capa,
1211                             IWL_UCODE_TLV_CAPA_D0I3_SUPPORT);
1212 }
1213
1214 static inline bool iwl_mvm_is_adaptive_dwell_supported(struct iwl_mvm *mvm)
1215 {
1216         return fw_has_api(&mvm->fw->ucode_capa,
1217                           IWL_UCODE_TLV_API_ADAPTIVE_DWELL);
1218 }
1219
1220 static inline bool iwl_mvm_is_adaptive_dwell_v2_supported(struct iwl_mvm *mvm)
1221 {
1222         return fw_has_api(&mvm->fw->ucode_capa,
1223                           IWL_UCODE_TLV_API_ADAPTIVE_DWELL_V2);
1224 }
1225
1226 static inline bool iwl_mvm_is_oce_supported(struct iwl_mvm *mvm)
1227 {
1228         /* OCE should never be enabled for LMAC scan FWs */
1229         return fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_OCE);
1230 }
1231
1232 static inline bool iwl_mvm_enter_d0i3_on_suspend(struct iwl_mvm *mvm)
1233 {
1234         /* For now we only use this mode to differentiate between
1235          * slave transports, which handle D0i3 entry in suspend by
1236          * themselves in conjunction with runtime PM D0i3.  So, this
1237          * function is used to check whether we need to do anything
1238          * when entering suspend or if the transport layer has already
1239          * done it.
1240          */
1241         return (mvm->trans->system_pm_mode == IWL_PLAT_PM_MODE_D0I3) &&
1242                 (mvm->trans->runtime_pm_mode != IWL_PLAT_PM_MODE_D0I3);
1243 }
1244
1245 static inline bool iwl_mvm_is_dqa_data_queue(struct iwl_mvm *mvm, u8 queue)
1246 {
1247         return (queue >= IWL_MVM_DQA_MIN_DATA_QUEUE) &&
1248                (queue <= IWL_MVM_DQA_MAX_DATA_QUEUE);
1249 }
1250
1251 static inline bool iwl_mvm_is_dqa_mgmt_queue(struct iwl_mvm *mvm, u8 queue)
1252 {
1253         return (queue >= IWL_MVM_DQA_MIN_MGMT_QUEUE) &&
1254                (queue <= IWL_MVM_DQA_MAX_MGMT_QUEUE);
1255 }
1256
1257 static inline bool iwl_mvm_is_lar_supported(struct iwl_mvm *mvm)
1258 {
1259         bool nvm_lar = mvm->nvm_data->lar_enabled;
1260         bool tlv_lar = fw_has_capa(&mvm->fw->ucode_capa,
1261                                    IWL_UCODE_TLV_CAPA_LAR_SUPPORT);
1262
1263         if (iwlwifi_mod_params.lar_disable)
1264                 return false;
1265
1266         /*
1267          * Enable LAR only if it is supported by the FW (TLV) &&
1268          * enabled in the NVM
1269          */
1270         if (mvm->cfg->nvm_type == IWL_NVM_EXT)
1271                 return nvm_lar && tlv_lar;
1272         else
1273                 return tlv_lar;
1274 }
1275
1276 static inline bool iwl_mvm_is_wifi_mcc_supported(struct iwl_mvm *mvm)
1277 {
1278         return fw_has_api(&mvm->fw->ucode_capa,
1279                           IWL_UCODE_TLV_API_WIFI_MCC_UPDATE) ||
1280                fw_has_capa(&mvm->fw->ucode_capa,
1281                            IWL_UCODE_TLV_CAPA_LAR_MULTI_MCC);
1282 }
1283
1284 static inline bool iwl_mvm_bt_is_rrc_supported(struct iwl_mvm *mvm)
1285 {
1286         return fw_has_capa(&mvm->fw->ucode_capa,
1287                            IWL_UCODE_TLV_CAPA_BT_COEX_RRC) &&
1288                 IWL_MVM_BT_COEX_RRC;
1289 }
1290
1291 static inline bool iwl_mvm_is_csum_supported(struct iwl_mvm *mvm)
1292 {
1293         return fw_has_capa(&mvm->fw->ucode_capa,
1294                            IWL_UCODE_TLV_CAPA_CSUM_SUPPORT) &&
1295                !IWL_MVM_HW_CSUM_DISABLE;
1296 }
1297
1298 static inline bool iwl_mvm_is_mplut_supported(struct iwl_mvm *mvm)
1299 {
1300         return fw_has_capa(&mvm->fw->ucode_capa,
1301                            IWL_UCODE_TLV_CAPA_BT_MPLUT_SUPPORT) &&
1302                 IWL_MVM_BT_COEX_MPLUT;
1303 }
1304
1305 static inline
1306 bool iwl_mvm_is_p2p_scm_uapsd_supported(struct iwl_mvm *mvm)
1307 {
1308         return fw_has_capa(&mvm->fw->ucode_capa,
1309                            IWL_UCODE_TLV_CAPA_P2P_SCM_UAPSD) &&
1310                 !(iwlwifi_mod_params.uapsd_disable &
1311                   IWL_DISABLE_UAPSD_P2P_CLIENT);
1312 }
1313
1314 static inline bool iwl_mvm_has_new_rx_api(struct iwl_mvm *mvm)
1315 {
1316         return fw_has_capa(&mvm->fw->ucode_capa,
1317                            IWL_UCODE_TLV_CAPA_MULTI_QUEUE_RX_SUPPORT);
1318 }
1319
1320 static inline bool iwl_mvm_has_new_tx_api(struct iwl_mvm *mvm)
1321 {
1322         /* TODO - replace with TLV once defined */
1323         return mvm->trans->cfg->use_tfh;
1324 }
1325
1326 static inline bool iwl_mvm_has_unified_ucode(struct iwl_mvm *mvm)
1327 {
1328         /* TODO - better define this */
1329         return mvm->trans->cfg->device_family >= IWL_DEVICE_FAMILY_22000;
1330 }
1331
1332 static inline bool iwl_mvm_is_cdb_supported(struct iwl_mvm *mvm)
1333 {
1334         /*
1335          * TODO:
1336          * The issue of how to determine CDB APIs and usage is still not fully
1337          * defined.
1338          * There is a compilation for CDB and non-CDB FW, but there may
1339          * be also runtime check.
1340          * For now there is a TLV for checking compilation mode, but a
1341          * runtime check will also have to be here - once defined.
1342          */
1343         return fw_has_capa(&mvm->fw->ucode_capa,
1344                            IWL_UCODE_TLV_CAPA_CDB_SUPPORT);
1345 }
1346
1347 static inline bool iwl_mvm_cdb_scan_api(struct iwl_mvm *mvm)
1348 {
1349         /*
1350          * TODO: should this be the same as iwl_mvm_is_cdb_supported()?
1351          * but then there's a little bit of code in scan that won't make
1352          * any sense...
1353          */
1354         return mvm->trans->cfg->device_family >= IWL_DEVICE_FAMILY_22000;
1355 }
1356
1357 static inline bool iwl_mvm_has_new_rx_stats_api(struct iwl_mvm *mvm)
1358 {
1359         return fw_has_api(&mvm->fw->ucode_capa,
1360                           IWL_UCODE_TLV_API_NEW_RX_STATS);
1361 }
1362
1363 static inline bool iwl_mvm_has_quota_low_latency(struct iwl_mvm *mvm)
1364 {
1365         return fw_has_api(&mvm->fw->ucode_capa,
1366                           IWL_UCODE_TLV_API_QUOTA_LOW_LATENCY);
1367 }
1368
1369 static inline bool iwl_mvm_has_tlc_offload(const struct iwl_mvm *mvm)
1370 {
1371         return fw_has_capa(&mvm->fw->ucode_capa,
1372                            IWL_UCODE_TLV_CAPA_TLC_OFFLOAD);
1373 }
1374
1375 static inline struct agg_tx_status *
1376 iwl_mvm_get_agg_status(struct iwl_mvm *mvm, void *tx_resp)
1377 {
1378         if (iwl_mvm_has_new_tx_api(mvm))
1379                 return &((struct iwl_mvm_tx_resp *)tx_resp)->status;
1380         else
1381                 return ((struct iwl_mvm_tx_resp_v3 *)tx_resp)->status;
1382 }
1383
1384 static inline bool iwl_mvm_is_tt_in_fw(struct iwl_mvm *mvm)
1385 {
1386 #ifdef CONFIG_THERMAL
1387         /* these two TLV are redundant since the responsibility to CT-kill by
1388          * FW happens only after we send at least one command of
1389          * temperature THs report.
1390          */
1391         return fw_has_capa(&mvm->fw->ucode_capa,
1392                            IWL_UCODE_TLV_CAPA_CT_KILL_BY_FW) &&
1393                fw_has_capa(&mvm->fw->ucode_capa,
1394                            IWL_UCODE_TLV_CAPA_TEMP_THS_REPORT_SUPPORT);
1395 #else /* CONFIG_THERMAL */
1396         return false;
1397 #endif /* CONFIG_THERMAL */
1398 }
1399
1400 static inline bool iwl_mvm_is_ctdp_supported(struct iwl_mvm *mvm)
1401 {
1402         return fw_has_capa(&mvm->fw->ucode_capa,
1403                            IWL_UCODE_TLV_CAPA_CTDP_SUPPORT);
1404 }
1405
1406 extern const u8 iwl_mvm_ac_to_tx_fifo[];
1407 extern const u8 iwl_mvm_ac_to_gen2_tx_fifo[];
1408
1409 static inline u8 iwl_mvm_mac_ac_to_tx_fifo(struct iwl_mvm *mvm,
1410                                            enum ieee80211_ac_numbers ac)
1411 {
1412         return iwl_mvm_has_new_tx_api(mvm) ?
1413                 iwl_mvm_ac_to_gen2_tx_fifo[ac] : iwl_mvm_ac_to_tx_fifo[ac];
1414 }
1415
1416 struct iwl_rate_info {
1417         u8 plcp;        /* uCode API:  IWL_RATE_6M_PLCP, etc. */
1418         u8 plcp_siso;   /* uCode API:  IWL_RATE_SISO_6M_PLCP, etc. */
1419         u8 plcp_mimo2;  /* uCode API:  IWL_RATE_MIMO2_6M_PLCP, etc. */
1420         u8 plcp_mimo3;  /* uCode API:  IWL_RATE_MIMO3_6M_PLCP, etc. */
1421         u8 ieee;        /* MAC header:  IWL_RATE_6M_IEEE, etc. */
1422 };
1423
1424 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm);
1425 int __iwl_mvm_mac_start(struct iwl_mvm *mvm);
1426
1427 /******************
1428  * MVM Methods
1429  ******************/
1430 /* uCode */
1431 int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm);
1432
1433 /* Utils */
1434 int iwl_mvm_legacy_rate_to_mac80211_idx(u32 rate_n_flags,
1435                                         enum nl80211_band band);
1436 void iwl_mvm_hwrate_to_tx_rate(u32 rate_n_flags,
1437                                enum nl80211_band band,
1438                                struct ieee80211_tx_rate *r);
1439 u8 iwl_mvm_mac80211_idx_to_hwrate(int rate_idx);
1440 void iwl_mvm_dump_nic_error_log(struct iwl_mvm *mvm);
1441 u8 first_antenna(u8 mask);
1442 u8 iwl_mvm_next_antenna(struct iwl_mvm *mvm, u8 valid, u8 last_idx);
1443 void iwl_mvm_get_sync_time(struct iwl_mvm *mvm, u32 *gp2, u64 *boottime);
1444
1445 /* Tx / Host Commands */
1446 int __must_check iwl_mvm_send_cmd(struct iwl_mvm *mvm,
1447                                   struct iwl_host_cmd *cmd);
1448 int __must_check iwl_mvm_send_cmd_pdu(struct iwl_mvm *mvm, u32 id,
1449                                       u32 flags, u16 len, const void *data);
1450 int __must_check iwl_mvm_send_cmd_status(struct iwl_mvm *mvm,
1451                                          struct iwl_host_cmd *cmd,
1452                                          u32 *status);
1453 int __must_check iwl_mvm_send_cmd_pdu_status(struct iwl_mvm *mvm, u32 id,
1454                                              u16 len, const void *data,
1455                                              u32 *status);
1456 int iwl_mvm_tx_skb(struct iwl_mvm *mvm, struct sk_buff *skb,
1457                    struct ieee80211_sta *sta);
1458 int iwl_mvm_tx_skb_non_sta(struct iwl_mvm *mvm, struct sk_buff *skb);
1459 void iwl_mvm_set_tx_cmd(struct iwl_mvm *mvm, struct sk_buff *skb,
1460                         struct iwl_tx_cmd *tx_cmd,
1461                         struct ieee80211_tx_info *info, u8 sta_id);
1462 void iwl_mvm_set_tx_cmd_rate(struct iwl_mvm *mvm, struct iwl_tx_cmd *tx_cmd,
1463                             struct ieee80211_tx_info *info,
1464                             struct ieee80211_sta *sta, __le16 fc);
1465 #ifdef CONFIG_IWLWIFI_DEBUG
1466 const char *iwl_mvm_get_tx_fail_reason(u32 status);
1467 #else
1468 static inline const char *iwl_mvm_get_tx_fail_reason(u32 status) { return ""; }
1469 #endif
1470 int iwl_mvm_flush_tx_path(struct iwl_mvm *mvm, u32 tfd_msk, u32 flags);
1471 int iwl_mvm_flush_sta(struct iwl_mvm *mvm, void *sta, bool internal, u32 flags);
1472 int iwl_mvm_flush_sta_tids(struct iwl_mvm *mvm, u32 sta_id,
1473                            u16 tids, u32 flags);
1474
1475 void iwl_mvm_async_handlers_purge(struct iwl_mvm *mvm);
1476
1477 static inline void iwl_mvm_set_tx_cmd_ccmp(struct ieee80211_tx_info *info,
1478                                            struct iwl_tx_cmd *tx_cmd)
1479 {
1480         struct ieee80211_key_conf *keyconf = info->control.hw_key;
1481
1482         tx_cmd->sec_ctl = TX_CMD_SEC_CCM;
1483         memcpy(tx_cmd->key, keyconf->key, keyconf->keylen);
1484 }
1485
1486 static inline void iwl_mvm_wait_for_async_handlers(struct iwl_mvm *mvm)
1487 {
1488         flush_work(&mvm->async_handlers_wk);
1489 }
1490
1491 /* Statistics */
1492 void iwl_mvm_handle_rx_statistics(struct iwl_mvm *mvm,
1493                                   struct iwl_rx_packet *pkt);
1494 void iwl_mvm_rx_statistics(struct iwl_mvm *mvm,
1495                            struct iwl_rx_cmd_buffer *rxb);
1496 int iwl_mvm_request_statistics(struct iwl_mvm *mvm, bool clear);
1497 void iwl_mvm_accu_radio_stats(struct iwl_mvm *mvm);
1498
1499 /* NVM */
1500 int iwl_nvm_init(struct iwl_mvm *mvm);
1501 int iwl_mvm_load_nvm_to_nic(struct iwl_mvm *mvm);
1502
1503 static inline u8 iwl_mvm_get_valid_tx_ant(struct iwl_mvm *mvm)
1504 {
1505         return mvm->nvm_data && mvm->nvm_data->valid_tx_ant ?
1506                mvm->fw->valid_tx_ant & mvm->nvm_data->valid_tx_ant :
1507                mvm->fw->valid_tx_ant;
1508 }
1509
1510 static inline u8 iwl_mvm_get_valid_rx_ant(struct iwl_mvm *mvm)
1511 {
1512         return mvm->nvm_data && mvm->nvm_data->valid_rx_ant ?
1513                mvm->fw->valid_rx_ant & mvm->nvm_data->valid_rx_ant :
1514                mvm->fw->valid_rx_ant;
1515 }
1516
1517 static inline u32 iwl_mvm_get_phy_config(struct iwl_mvm *mvm)
1518 {
1519         u32 phy_config = ~(FW_PHY_CFG_TX_CHAIN |
1520                            FW_PHY_CFG_RX_CHAIN);
1521         u32 valid_rx_ant = iwl_mvm_get_valid_rx_ant(mvm);
1522         u32 valid_tx_ant = iwl_mvm_get_valid_tx_ant(mvm);
1523
1524         phy_config |= valid_tx_ant << FW_PHY_CFG_TX_CHAIN_POS |
1525                       valid_rx_ant << FW_PHY_CFG_RX_CHAIN_POS;
1526
1527         return mvm->fw->phy_config & phy_config;
1528 }
1529
1530 int iwl_mvm_up(struct iwl_mvm *mvm);
1531 int iwl_mvm_load_d3_fw(struct iwl_mvm *mvm);
1532
1533 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm);
1534 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1535                                     struct iwl_bcast_filter_cmd *cmd);
1536
1537 /*
1538  * FW notifications / CMD responses handlers
1539  * Convention: iwl_mvm_rx_<NAME OF THE CMD>
1540  */
1541 void iwl_mvm_rx_rx_phy_cmd(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
1542 void iwl_mvm_rx_rx_mpdu(struct iwl_mvm *mvm, struct napi_struct *napi,
1543                         struct iwl_rx_cmd_buffer *rxb);
1544 void iwl_mvm_rx_mpdu_mq(struct iwl_mvm *mvm, struct napi_struct *napi,
1545                         struct iwl_rx_cmd_buffer *rxb, int queue);
1546 void iwl_mvm_rx_frame_release(struct iwl_mvm *mvm, struct napi_struct *napi,
1547                               struct iwl_rx_cmd_buffer *rxb, int queue);
1548 int iwl_mvm_notify_rx_queue(struct iwl_mvm *mvm, u32 rxq_mask,
1549                             const u8 *data, u32 count);
1550 void iwl_mvm_rx_queue_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb,
1551                             int queue);
1552 void iwl_mvm_rx_tx_cmd(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
1553 void iwl_mvm_mfu_assert_dump_notif(struct iwl_mvm *mvm,
1554                                    struct iwl_rx_cmd_buffer *rxb);
1555 void iwl_mvm_rx_ba_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
1556 void iwl_mvm_rx_ant_coupling_notif(struct iwl_mvm *mvm,
1557                                    struct iwl_rx_cmd_buffer *rxb);
1558 void iwl_mvm_rx_fw_error(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
1559 void iwl_mvm_rx_card_state_notif(struct iwl_mvm *mvm,
1560                                  struct iwl_rx_cmd_buffer *rxb);
1561 void iwl_mvm_rx_mfuart_notif(struct iwl_mvm *mvm,
1562                              struct iwl_rx_cmd_buffer *rxb);
1563 void iwl_mvm_rx_shared_mem_cfg_notif(struct iwl_mvm *mvm,
1564                                      struct iwl_rx_cmd_buffer *rxb);
1565
1566 /* MVM PHY */
1567 int iwl_mvm_phy_ctxt_add(struct iwl_mvm *mvm, struct iwl_mvm_phy_ctxt *ctxt,
1568                          struct cfg80211_chan_def *chandef,
1569                          u8 chains_static, u8 chains_dynamic);
1570 int iwl_mvm_phy_ctxt_changed(struct iwl_mvm *mvm, struct iwl_mvm_phy_ctxt *ctxt,
1571                              struct cfg80211_chan_def *chandef,
1572                              u8 chains_static, u8 chains_dynamic);
1573 void iwl_mvm_phy_ctxt_ref(struct iwl_mvm *mvm,
1574                           struct iwl_mvm_phy_ctxt *ctxt);
1575 void iwl_mvm_phy_ctxt_unref(struct iwl_mvm *mvm,
1576                             struct iwl_mvm_phy_ctxt *ctxt);
1577 int iwl_mvm_phy_ctx_count(struct iwl_mvm *mvm);
1578 u8 iwl_mvm_get_channel_width(struct cfg80211_chan_def *chandef);
1579 u8 iwl_mvm_get_ctrl_pos(struct cfg80211_chan_def *chandef);
1580
1581 /* MAC (virtual interface) programming */
1582 int iwl_mvm_mac_ctxt_init(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1583 int iwl_mvm_mac_ctxt_add(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1584 int iwl_mvm_mac_ctxt_changed(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1585                              bool force_assoc_off, const u8 *bssid_override);
1586 int iwl_mvm_mac_ctxt_remove(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1587 u32 iwl_mvm_mac_get_queues_mask(struct ieee80211_vif *vif);
1588 int iwl_mvm_mac_ctxt_beacon_changed(struct iwl_mvm *mvm,
1589                                     struct ieee80211_vif *vif);
1590 void iwl_mvm_rx_beacon_notif(struct iwl_mvm *mvm,
1591                              struct iwl_rx_cmd_buffer *rxb);
1592 void iwl_mvm_rx_missed_beacons_notif(struct iwl_mvm *mvm,
1593                                      struct iwl_rx_cmd_buffer *rxb);
1594 void iwl_mvm_rx_stored_beacon_notif(struct iwl_mvm *mvm,
1595                                     struct iwl_rx_cmd_buffer *rxb);
1596 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
1597                                struct iwl_rx_cmd_buffer *rxb);
1598 void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
1599 void iwl_mvm_window_status_notif(struct iwl_mvm *mvm,
1600                                  struct iwl_rx_cmd_buffer *rxb);
1601 void iwl_mvm_mac_ctxt_recalc_tsf_id(struct iwl_mvm *mvm,
1602                                     struct ieee80211_vif *vif);
1603 unsigned long iwl_mvm_get_used_hw_queues(struct iwl_mvm *mvm,
1604                                          struct ieee80211_vif *exclude_vif);
1605 void iwl_mvm_channel_switch_noa_notif(struct iwl_mvm *mvm,
1606                                       struct iwl_rx_cmd_buffer *rxb);
1607 /* Bindings */
1608 int iwl_mvm_binding_add_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1609 int iwl_mvm_binding_remove_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1610
1611 /* Quota management */
1612 static inline size_t iwl_mvm_quota_cmd_size(struct iwl_mvm *mvm)
1613 {
1614         return iwl_mvm_has_quota_low_latency(mvm) ?
1615                 sizeof(struct iwl_time_quota_cmd) :
1616                 sizeof(struct iwl_time_quota_cmd_v1);
1617 }
1618
1619 static inline struct iwl_time_quota_data
1620 *iwl_mvm_quota_cmd_get_quota(struct iwl_mvm *mvm,
1621                              struct iwl_time_quota_cmd *cmd,
1622                              int i)
1623 {
1624         struct iwl_time_quota_data_v1 *quotas;
1625
1626         if (iwl_mvm_has_quota_low_latency(mvm))
1627                 return &cmd->quotas[i];
1628
1629         quotas = (struct iwl_time_quota_data_v1 *)cmd->quotas;
1630         return (struct iwl_time_quota_data *)&quotas[i];
1631 }
1632
1633 int iwl_mvm_update_quotas(struct iwl_mvm *mvm, bool force_upload,
1634                           struct ieee80211_vif *disabled_vif);
1635
1636 /* Scanning */
1637 int iwl_mvm_reg_scan_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1638                            struct cfg80211_scan_request *req,
1639                            struct ieee80211_scan_ies *ies);
1640 int iwl_mvm_scan_size(struct iwl_mvm *mvm);
1641 int iwl_mvm_scan_stop(struct iwl_mvm *mvm, int type, bool notify);
1642 int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm);
1643 void iwl_mvm_report_scan_aborted(struct iwl_mvm *mvm);
1644 void iwl_mvm_scan_timeout_wk(struct work_struct *work);
1645
1646 /* Scheduled scan */
1647 void iwl_mvm_rx_lmac_scan_complete_notif(struct iwl_mvm *mvm,
1648                                          struct iwl_rx_cmd_buffer *rxb);
1649 void iwl_mvm_rx_lmac_scan_iter_complete_notif(struct iwl_mvm *mvm,
1650                                               struct iwl_rx_cmd_buffer *rxb);
1651 int iwl_mvm_sched_scan_start(struct iwl_mvm *mvm,
1652                              struct ieee80211_vif *vif,
1653                              struct cfg80211_sched_scan_request *req,
1654                              struct ieee80211_scan_ies *ies,
1655                              int type);
1656 void iwl_mvm_rx_scan_match_found(struct iwl_mvm *mvm,
1657                                  struct iwl_rx_cmd_buffer *rxb);
1658
1659 /* UMAC scan */
1660 int iwl_mvm_config_scan(struct iwl_mvm *mvm);
1661 void iwl_mvm_rx_umac_scan_complete_notif(struct iwl_mvm *mvm,
1662                                          struct iwl_rx_cmd_buffer *rxb);
1663 void iwl_mvm_rx_umac_scan_iter_complete_notif(struct iwl_mvm *mvm,
1664                                               struct iwl_rx_cmd_buffer *rxb);
1665
1666 /* MVM debugfs */
1667 #ifdef CONFIG_IWLWIFI_DEBUGFS
1668 int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm, struct dentry *dbgfs_dir);
1669 void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1670 void iwl_mvm_vif_dbgfs_clean(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1671 #else
1672 static inline int iwl_mvm_dbgfs_register(struct iwl_mvm *mvm,
1673                                          struct dentry *dbgfs_dir)
1674 {
1675         return 0;
1676 }
1677 static inline void
1678 iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1679 {
1680 }
1681 static inline void
1682 iwl_mvm_vif_dbgfs_clean(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1683 {
1684 }
1685 #endif /* CONFIG_IWLWIFI_DEBUGFS */
1686
1687 /* rate scaling */
1688 int iwl_mvm_send_lq_cmd(struct iwl_mvm *mvm, struct iwl_lq_cmd *lq, bool sync);
1689 void iwl_mvm_update_frame_stats(struct iwl_mvm *mvm, u32 rate, bool agg);
1690 int rs_pretty_print_rate(char *buf, int bufsz, const u32 rate);
1691 void rs_update_last_rssi(struct iwl_mvm *mvm,
1692                          struct iwl_mvm_sta *mvmsta,
1693                          struct ieee80211_rx_status *rx_status);
1694
1695 /* power management */
1696 int iwl_mvm_power_update_device(struct iwl_mvm *mvm);
1697 int iwl_mvm_power_update_mac(struct iwl_mvm *mvm);
1698 int iwl_mvm_power_update_ps(struct iwl_mvm *mvm);
1699 int iwl_mvm_power_mac_dbgfs_read(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1700                                  char *buf, int bufsz);
1701
1702 void iwl_mvm_power_vif_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1703 void iwl_mvm_power_uapsd_misbehaving_ap_notif(struct iwl_mvm *mvm,
1704                                               struct iwl_rx_cmd_buffer *rxb);
1705
1706 #ifdef CONFIG_IWLWIFI_LEDS
1707 int iwl_mvm_leds_init(struct iwl_mvm *mvm);
1708 void iwl_mvm_leds_exit(struct iwl_mvm *mvm);
1709 void iwl_mvm_leds_sync(struct iwl_mvm *mvm);
1710 #else
1711 static inline int iwl_mvm_leds_init(struct iwl_mvm *mvm)
1712 {
1713         return 0;
1714 }
1715 static inline void iwl_mvm_leds_exit(struct iwl_mvm *mvm)
1716 {
1717 }
1718 static inline void iwl_mvm_leds_sync(struct iwl_mvm *mvm)
1719 {
1720 }
1721 #endif
1722
1723 /* D3 (WoWLAN, NetDetect) */
1724 int iwl_mvm_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan);
1725 int iwl_mvm_resume(struct ieee80211_hw *hw);
1726 void iwl_mvm_set_wakeup(struct ieee80211_hw *hw, bool enabled);
1727 void iwl_mvm_set_rekey_data(struct ieee80211_hw *hw,
1728                             struct ieee80211_vif *vif,
1729                             struct cfg80211_gtk_rekey_data *data);
1730 void iwl_mvm_ipv6_addr_change(struct ieee80211_hw *hw,
1731                               struct ieee80211_vif *vif,
1732                               struct inet6_dev *idev);
1733 void iwl_mvm_set_default_unicast_key(struct ieee80211_hw *hw,
1734                                      struct ieee80211_vif *vif, int idx);
1735 extern const struct file_operations iwl_dbgfs_d3_test_ops;
1736 #ifdef CONFIG_PM
1737 int iwl_mvm_wowlan_config_key_params(struct iwl_mvm *mvm,
1738                                      struct ieee80211_vif *vif,
1739                                      bool host_awake,
1740                                      u32 cmd_flags);
1741 void iwl_mvm_d0i3_update_keys(struct iwl_mvm *mvm,
1742                               struct ieee80211_vif *vif,
1743                               struct iwl_wowlan_status *status);
1744 void iwl_mvm_set_last_nonqos_seq(struct iwl_mvm *mvm,
1745                                  struct ieee80211_vif *vif);
1746 #else
1747 static inline int iwl_mvm_wowlan_config_key_params(struct iwl_mvm *mvm,
1748                                                    struct ieee80211_vif *vif,
1749                                                    bool host_awake,
1750                                                    u32 cmd_flags)
1751 {
1752         return 0;
1753 }
1754
1755 static inline void iwl_mvm_d0i3_update_keys(struct iwl_mvm *mvm,
1756                                             struct ieee80211_vif *vif,
1757                                             struct iwl_wowlan_status *status)
1758 {
1759 }
1760
1761 static inline void
1762 iwl_mvm_set_last_nonqos_seq(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1763 {
1764 }
1765 #endif
1766 void iwl_mvm_set_wowlan_qos_seq(struct iwl_mvm_sta *mvm_ap_sta,
1767                                 struct iwl_wowlan_config_cmd *cmd);
1768 int iwl_mvm_send_proto_offload(struct iwl_mvm *mvm,
1769                                struct ieee80211_vif *vif,
1770                                bool disable_offloading,
1771                                bool offload_ns,
1772                                u32 cmd_flags);
1773
1774 /* D0i3 */
1775 void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type);
1776 void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type);
1777 int iwl_mvm_ref_sync(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type);
1778 bool iwl_mvm_ref_taken(struct iwl_mvm *mvm);
1779 void iwl_mvm_d0i3_enable_tx(struct iwl_mvm *mvm, __le16 *qos_seq);
1780 int iwl_mvm_enter_d0i3(struct iwl_op_mode *op_mode);
1781 int iwl_mvm_exit_d0i3(struct iwl_op_mode *op_mode);
1782 int _iwl_mvm_exit_d0i3(struct iwl_mvm *mvm);
1783
1784 /* BT Coex */
1785 int iwl_mvm_send_bt_init_conf(struct iwl_mvm *mvm);
1786 void iwl_mvm_rx_bt_coex_notif(struct iwl_mvm *mvm,
1787                               struct iwl_rx_cmd_buffer *rxb);
1788 void iwl_mvm_bt_rssi_event(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1789                            enum ieee80211_rssi_event_data);
1790 void iwl_mvm_bt_coex_vif_change(struct iwl_mvm *mvm);
1791 u16 iwl_mvm_coex_agg_time_limit(struct iwl_mvm *mvm,
1792                                 struct ieee80211_sta *sta);
1793 bool iwl_mvm_bt_coex_is_mimo_allowed(struct iwl_mvm *mvm,
1794                                      struct ieee80211_sta *sta);
1795 bool iwl_mvm_bt_coex_is_ant_avail(struct iwl_mvm *mvm, u8 ant);
1796 bool iwl_mvm_bt_coex_is_shared_ant_avail(struct iwl_mvm *mvm);
1797 bool iwl_mvm_bt_coex_is_tpc_allowed(struct iwl_mvm *mvm,
1798                                     enum nl80211_band band);
1799 u8 iwl_mvm_bt_coex_tx_prio(struct iwl_mvm *mvm, struct ieee80211_hdr *hdr,
1800                            struct ieee80211_tx_info *info, u8 ac);
1801
1802 /* beacon filtering */
1803 #ifdef CONFIG_IWLWIFI_DEBUGFS
1804 void
1805 iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif,
1806                                          struct iwl_beacon_filter_cmd *cmd);
1807 #else
1808 static inline void
1809 iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif,
1810                                          struct iwl_beacon_filter_cmd *cmd)
1811 {}
1812 #endif
1813 int iwl_mvm_update_d0i3_power_mode(struct iwl_mvm *mvm,
1814                                    struct ieee80211_vif *vif,
1815                                    bool enable, u32 flags);
1816 int iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
1817                                  struct ieee80211_vif *vif,
1818                                  u32 flags);
1819 int iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm,
1820                                   struct ieee80211_vif *vif,
1821                                   u32 flags);
1822 /* SMPS */
1823 void iwl_mvm_update_smps(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1824                                 enum iwl_mvm_smps_type_request req_type,
1825                                 enum ieee80211_smps_mode smps_request);
1826 bool iwl_mvm_rx_diversity_allowed(struct iwl_mvm *mvm);
1827
1828 /* Low latency */
1829 int iwl_mvm_update_low_latency(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1830                               bool low_latency,
1831                               enum iwl_mvm_low_latency_cause cause);
1832 /* get SystemLowLatencyMode - only needed for beacon threshold? */
1833 bool iwl_mvm_low_latency(struct iwl_mvm *mvm);
1834 bool iwl_mvm_low_latency_band(struct iwl_mvm *mvm, enum nl80211_band band);
1835
1836 /* get VMACLowLatencyMode */
1837 static inline bool iwl_mvm_vif_low_latency(struct iwl_mvm_vif *mvmvif)
1838 {
1839         /*
1840          * should this consider associated/active/... state?
1841          *
1842          * Normally low-latency should only be active on interfaces
1843          * that are active, but at least with debugfs it can also be
1844          * enabled on interfaces that aren't active. However, when
1845          * interface aren't active then they aren't added into the
1846          * binding, so this has no real impact. For now, just return
1847          * the current desired low-latency state.
1848          */
1849         return mvmvif->low_latency;
1850 }
1851
1852 static inline
1853 void iwl_mvm_vif_set_low_latency(struct iwl_mvm_vif *mvmvif, bool set,
1854                                  enum iwl_mvm_low_latency_cause cause)
1855 {
1856         if (set)
1857                 mvmvif->low_latency |= cause;
1858         else
1859                 mvmvif->low_latency &= ~cause;
1860 }
1861
1862 /* hw scheduler queue config */
1863 bool iwl_mvm_enable_txq(struct iwl_mvm *mvm, int queue, int mac80211_queue,
1864                         u16 ssn, const struct iwl_trans_txq_scd_cfg *cfg,
1865                         unsigned int wdg_timeout);
1866 int iwl_mvm_tvqm_enable_txq(struct iwl_mvm *mvm, int mac80211_queue,
1867                             u8 sta_id, u8 tid, unsigned int timeout);
1868
1869 int iwl_mvm_disable_txq(struct iwl_mvm *mvm, int queue, int mac80211_queue,
1870                         u8 tid, u8 flags);
1871 int iwl_mvm_find_free_queue(struct iwl_mvm *mvm, u8 sta_id, u8 minq, u8 maxq);
1872
1873 /* Return a bitmask with all the hw supported queues, except for the
1874  * command queue, which can't be flushed.
1875  */
1876 static inline u32 iwl_mvm_flushable_queues(struct iwl_mvm *mvm)
1877 {
1878         return ((BIT(mvm->cfg->base_params->num_of_queues) - 1) &
1879                 ~BIT(IWL_MVM_DQA_CMD_QUEUE));
1880 }
1881
1882 static inline void iwl_mvm_stop_device(struct iwl_mvm *mvm)
1883 {
1884         iwl_fw_cancel_timestamp(&mvm->fwrt);
1885         iwl_free_fw_paging(&mvm->fwrt);
1886         clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1887         iwl_fw_dump_conf_clear(&mvm->fwrt);
1888         iwl_trans_stop_device(mvm->trans);
1889 }
1890
1891 /* Stop/start all mac queues in a given bitmap */
1892 void iwl_mvm_start_mac_queues(struct iwl_mvm *mvm, unsigned long mq);
1893 void iwl_mvm_stop_mac_queues(struct iwl_mvm *mvm, unsigned long mq);
1894
1895 /* Re-configure the SCD for a queue that has already been configured */
1896 int iwl_mvm_reconfig_scd(struct iwl_mvm *mvm, int queue, int fifo, int sta_id,
1897                          int tid, int frame_limit, u16 ssn);
1898
1899 /* Thermal management and CT-kill */
1900 void iwl_mvm_tt_tx_backoff(struct iwl_mvm *mvm, u32 backoff);
1901 void iwl_mvm_tt_temp_changed(struct iwl_mvm *mvm, u32 temp);
1902 void iwl_mvm_temp_notif(struct iwl_mvm *mvm,
1903                         struct iwl_rx_cmd_buffer *rxb);
1904 void iwl_mvm_tt_handler(struct iwl_mvm *mvm);
1905 void iwl_mvm_thermal_initialize(struct iwl_mvm *mvm, u32 min_backoff);
1906 void iwl_mvm_thermal_exit(struct iwl_mvm *mvm);
1907 void iwl_mvm_set_hw_ctkill_state(struct iwl_mvm *mvm, bool state);
1908 int iwl_mvm_get_temp(struct iwl_mvm *mvm, s32 *temp);
1909 void iwl_mvm_ct_kill_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
1910 void iwl_mvm_enter_ctkill(struct iwl_mvm *mvm);
1911 int iwl_mvm_send_temp_report_ths_cmd(struct iwl_mvm *mvm);
1912 int iwl_mvm_ctdp_command(struct iwl_mvm *mvm, u32 op, u32 budget);
1913
1914 /* Location Aware Regulatory */
1915 struct iwl_mcc_update_resp *
1916 iwl_mvm_update_mcc(struct iwl_mvm *mvm, const char *alpha2,
1917                    enum iwl_mcc_source src_id);
1918 int iwl_mvm_init_mcc(struct iwl_mvm *mvm);
1919 void iwl_mvm_rx_chub_update_mcc(struct iwl_mvm *mvm,
1920                                 struct iwl_rx_cmd_buffer *rxb);
1921 struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy,
1922                                                   const char *alpha2,
1923                                                   enum iwl_mcc_source src_id,
1924                                                   bool *changed);
1925 struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm,
1926                                                           bool *changed);
1927 int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm);
1928 void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm);
1929
1930 /* smart fifo */
1931 int iwl_mvm_sf_update(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1932                       bool added_vif);
1933
1934 /* TDLS */
1935
1936 /*
1937  * We use TID 4 (VI) as a FW-used-only TID when TDLS connections are present.
1938  * This TID is marked as used vs the AP and all connected TDLS peers.
1939  */
1940 #define IWL_MVM_TDLS_FW_TID 4
1941
1942 int iwl_mvm_tdls_sta_count(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1943 void iwl_mvm_teardown_tdls_peers(struct iwl_mvm *mvm);
1944 void iwl_mvm_recalc_tdls_state(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1945                                bool sta_added);
1946 void iwl_mvm_mac_mgd_protect_tdls_discover(struct ieee80211_hw *hw,
1947                                            struct ieee80211_vif *vif);
1948 int iwl_mvm_tdls_channel_switch(struct ieee80211_hw *hw,
1949                                 struct ieee80211_vif *vif,
1950                                 struct ieee80211_sta *sta, u8 oper_class,
1951                                 struct cfg80211_chan_def *chandef,
1952                                 struct sk_buff *tmpl_skb, u32 ch_sw_tm_ie);
1953 void iwl_mvm_tdls_recv_channel_switch(struct ieee80211_hw *hw,
1954                                       struct ieee80211_vif *vif,
1955                                       struct ieee80211_tdls_ch_sw_params *params);
1956 void iwl_mvm_tdls_cancel_channel_switch(struct ieee80211_hw *hw,
1957                                         struct ieee80211_vif *vif,
1958                                         struct ieee80211_sta *sta);
1959 void iwl_mvm_rx_tdls_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
1960 void iwl_mvm_tdls_ch_switch_work(struct work_struct *work);
1961
1962 void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
1963                                      struct iwl_mvm_internal_rxq_notif *notif,
1964                                      u32 size);
1965 void iwl_mvm_reorder_timer_expired(struct timer_list *t);
1966 struct ieee80211_vif *iwl_mvm_get_bss_vif(struct iwl_mvm *mvm);
1967 bool iwl_mvm_is_vif_assoc(struct iwl_mvm *mvm);
1968
1969 void iwl_mvm_inactivity_check(struct iwl_mvm *mvm);
1970
1971 #define MVM_TCM_PERIOD_MSEC 500
1972 #define MVM_TCM_PERIOD (HZ * MVM_TCM_PERIOD_MSEC / 1000)
1973 #define MVM_LL_PERIOD (10 * HZ)
1974 void iwl_mvm_tcm_work(struct work_struct *work);
1975 void iwl_mvm_recalc_tcm(struct iwl_mvm *mvm);
1976 void iwl_mvm_pause_tcm(struct iwl_mvm *mvm, bool with_cancel);
1977 void iwl_mvm_resume_tcm(struct iwl_mvm *mvm);
1978 void iwl_mvm_tcm_add_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1979 void iwl_mvm_tcm_rm_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1980 u8 iwl_mvm_tcm_load_percentage(u32 airtime, u32 elapsed);
1981
1982 void iwl_mvm_nic_restart(struct iwl_mvm *mvm, bool fw_error);
1983 unsigned int iwl_mvm_get_wd_timeout(struct iwl_mvm *mvm,
1984                                     struct ieee80211_vif *vif,
1985                                     bool tdls, bool cmd_q);
1986 void iwl_mvm_connection_loss(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1987                              const char *errmsg);
1988 void iwl_mvm_event_frame_timeout_callback(struct iwl_mvm *mvm,
1989                                           struct ieee80211_vif *vif,
1990                                           const struct ieee80211_sta *sta,
1991                                           u16 tid);
1992
1993 int iwl_mvm_sar_select_profile(struct iwl_mvm *mvm, int prof_a, int prof_b);
1994 int iwl_mvm_get_sar_geo_profile(struct iwl_mvm *mvm);
1995 #ifdef CONFIG_IWLWIFI_DEBUGFS
1996 void iwl_mvm_sta_add_debugfs(struct ieee80211_hw *hw,
1997                              struct ieee80211_vif *vif,
1998                              struct ieee80211_sta *sta,
1999                              struct dentry *dir);
2000 #endif
2001
2002 #endif /* __IWL_MVM_H__ */