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