1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /******************************************************************************
3  *
4  * Copyright(c) 2003 - 2014, 2020 Intel Corporation. All rights reserved.
5  *****************************************************************************/
6 /*
7  * Please use this file (dev.h) for driver implementation definitions.
8  * Please use commands.h for uCode API definitions.
9  */
10 
11 #ifndef __iwl_dev_h__
12 #define __iwl_dev_h__
13 
14 #include <linux/interrupt.h>
15 #include <linux/kernel.h>
16 #include <linux/wait.h>
17 #include <linux/leds.h>
18 #include <linux/slab.h>
19 #include <linux/mutex.h>
20 
21 #include "fw/img.h"
22 #include "iwl-eeprom-parse.h"
23 #include "iwl-csr.h"
24 #include "iwl-debug.h"
25 #include "iwl-agn-hw.h"
26 #include "iwl-op-mode.h"
27 #include "fw/notif-wait.h"
28 #include "iwl-trans.h"
29 
30 #include "led.h"
31 #include "power.h"
32 #include "rs.h"
33 #include "tt.h"
34 
35 /* CT-KILL constants */
36 #define CT_KILL_THRESHOLD_LEGACY   110 /* in Celsius */
37 #define CT_KILL_THRESHOLD	   114 /* in Celsius */
38 #define CT_KILL_EXIT_THRESHOLD     95  /* in Celsius */
39 
40 /* Default noise level to report when noise measurement is not available.
41  *   This may be because we're:
42  *   1)  Not associated  no beacon statistics being sent to driver)
43  *   2)  Scanning (noise measurement does not apply to associated channel)
44  * Use default noise value of -127 ... this is below the range of measurable
45  *   Rx dBm for all agn devices, so it can indicate "unmeasurable" to user.
46  *   Also, -127 works better than 0 when averaging frames with/without
47  *   noise info (e.g. averaging might be done in app); measured dBm values are
48  *   always negative ... using a negative value as the default keeps all
49  *   averages within an s8's (used in some apps) range of negative values. */
50 #define IWL_NOISE_MEAS_NOT_AVAILABLE (-127)
51 
52 /*
53  * RTS threshold here is total size [2347] minus 4 FCS bytes
54  * Per spec:
55  *   a value of 0 means RTS on all data/management packets
56  *   a value > max MSDU size means no RTS
57  * else RTS for data/management frames where MPDU is larger
58  *   than RTS value.
59  */
60 #define DEFAULT_RTS_THRESHOLD     2347U
61 #define MIN_RTS_THRESHOLD         0U
62 #define MAX_RTS_THRESHOLD         2347U
63 #define MAX_MSDU_SIZE		  2304U
64 #define MAX_MPDU_SIZE		  2346U
65 #define DEFAULT_BEACON_INTERVAL   200U
66 #define	DEFAULT_SHORT_RETRY_LIMIT 7U
67 #define	DEFAULT_LONG_RETRY_LIMIT  4U
68 
69 #define IWL_NUM_SCAN_RATES         (2)
70 
71 
72 #define IEEE80211_DATA_LEN              2304
73 #define IEEE80211_4ADDR_LEN             30
74 #define IEEE80211_HLEN                  (IEEE80211_4ADDR_LEN)
75 #define IEEE80211_FRAME_LEN             (IEEE80211_DATA_LEN + IEEE80211_HLEN)
76 
77 #define SUP_RATE_11A_MAX_NUM_CHANNELS  8
78 #define SUP_RATE_11B_MAX_NUM_CHANNELS  4
79 #define SUP_RATE_11G_MAX_NUM_CHANNELS  12
80 
81 #define IWL_SUPPORTED_RATES_IE_LEN         8
82 
83 #define IWL_INVALID_RATE     0xFF
84 #define IWL_INVALID_VALUE    -1
85 
86 union iwl_ht_rate_supp {
87 	u16 rates;
88 	struct {
89 		u8 siso_rate;
90 		u8 mimo_rate;
91 	};
92 };
93 
94 struct iwl_ht_config {
95 	bool single_chain_sufficient;
96 	enum ieee80211_smps_mode smps; /* current smps mode */
97 };
98 
99 /* QoS structures */
100 struct iwl_qos_info {
101 	int qos_active;
102 	struct iwl_qosparam_cmd def_qos_parm;
103 };
104 
105 /**
106  * enum iwl_agg_state
107  *
108  * The state machine of the BA agreement establishment / tear down.
109  * These states relate to a specific RA / TID.
110  *
111  * @IWL_AGG_OFF: aggregation is not used
112  * @IWL_AGG_STARTING: aggregation are starting (between start and oper)
113  * @IWL_AGG_ON: aggregation session is up
114  * @IWL_EMPTYING_HW_QUEUE_ADDBA: establishing a BA session - waiting for the
115  *	HW queue to be empty from packets for this RA /TID.
116  * @IWL_EMPTYING_HW_QUEUE_DELBA: tearing down a BA session - waiting for the
117  *	HW queue to be empty from packets for this RA /TID.
118  */
119 enum iwl_agg_state {
120 	IWL_AGG_OFF = 0,
121 	IWL_AGG_STARTING,
122 	IWL_AGG_ON,
123 	IWL_EMPTYING_HW_QUEUE_ADDBA,
124 	IWL_EMPTYING_HW_QUEUE_DELBA,
125 };
126 
127 /**
128  * struct iwl_ht_agg - aggregation state machine
129 
130  * This structs holds the states for the BA agreement establishment and tear
131  * down. It also holds the state during the BA session itself. This struct is
132  * duplicated for each RA / TID.
133 
134  * @rate_n_flags: Rate at which Tx was attempted. Holds the data between the
135  *	Tx response (REPLY_TX), and the block ack notification
136  *	(REPLY_COMPRESSED_BA).
137  * @state: state of the BA agreement establishment / tear down.
138  * @txq_id: Tx queue used by the BA session
139  * @ssn: the first packet to be sent in AGG HW queue in Tx AGG start flow, or
140  *	the first packet to be sent in legacy HW queue in Tx AGG stop flow.
141  *	Basically when next_reclaimed reaches ssn, we can tell mac80211 that
142  *	we are ready to finish the Tx AGG stop / start flow.
143  * @wait_for_ba: Expect block-ack before next Tx reply
144  */
145 struct iwl_ht_agg {
146 	u32 rate_n_flags;
147 	enum iwl_agg_state state;
148 	u16 txq_id;
149 	u16 ssn;
150 	bool wait_for_ba;
151 };
152 
153 /**
154  * struct iwl_tid_data - one for each RA / TID
155 
156  * This structs holds the states for each RA / TID.
157 
158  * @seq_number: the next WiFi sequence number to use
159  * @next_reclaimed: the WiFi sequence number of the next packet to be acked.
160  *	This is basically (last acked packet++).
161  * @agg: aggregation state machine
162  */
163 struct iwl_tid_data {
164 	u16 seq_number;
165 	u16 next_reclaimed;
166 	struct iwl_ht_agg agg;
167 };
168 
169 /*
170  * Structure should be accessed with sta_lock held. When station addition
171  * is in progress (IWL_STA_UCODE_INPROGRESS) it is possible to access only
172  * the commands (iwl_addsta_cmd and iwl_link_quality_cmd) without sta_lock
173  * held.
174  */
175 struct iwl_station_entry {
176 	struct iwl_addsta_cmd sta;
177 	u8 used, ctxid;
178 	struct iwl_link_quality_cmd *lq;
179 };
180 
181 /*
182  * iwl_station_priv: Driver's private station information
183  *
184  * When mac80211 creates a station it reserves some space (hw->sta_data_size)
185  * in the structure for use by driver. This structure is places in that
186  * space.
187  */
188 struct iwl_station_priv {
189 	struct iwl_rxon_context *ctx;
190 	struct iwl_lq_sta lq_sta;
191 	atomic_t pending_frames;
192 	bool client;
193 	bool asleep;
194 	u8 max_agg_bufsize;
195 	u8 sta_id;
196 };
197 
198 /**
199  * struct iwl_vif_priv - driver's private per-interface information
200  *
201  * When mac80211 allocates a virtual interface, it can allocate
202  * space for us to put data into.
203  */
204 struct iwl_vif_priv {
205 	struct iwl_rxon_context *ctx;
206 	u8 ibss_bssid_sta_id;
207 };
208 
209 struct iwl_sensitivity_ranges {
210 	u16 min_nrg_cck;
211 
212 	u16 nrg_th_cck;
213 	u16 nrg_th_ofdm;
214 
215 	u16 auto_corr_min_ofdm;
216 	u16 auto_corr_min_ofdm_mrc;
217 	u16 auto_corr_min_ofdm_x1;
218 	u16 auto_corr_min_ofdm_mrc_x1;
219 
220 	u16 auto_corr_max_ofdm;
221 	u16 auto_corr_max_ofdm_mrc;
222 	u16 auto_corr_max_ofdm_x1;
223 	u16 auto_corr_max_ofdm_mrc_x1;
224 
225 	u16 auto_corr_max_cck;
226 	u16 auto_corr_max_cck_mrc;
227 	u16 auto_corr_min_cck;
228 	u16 auto_corr_min_cck_mrc;
229 
230 	u16 barker_corr_th_min;
231 	u16 barker_corr_th_min_mrc;
232 	u16 nrg_th_cca;
233 };
234 
235 /******************************************************************************
236  *
237  * Functions implemented in core module which are forward declared here
238  * for use by iwl-[4-5].c
239  *
240  * NOTE:  The implementation of these functions are not hardware specific
241  * which is why they are in the core module files.
242  *
243  * Naming convention --
244  * iwl_         <-- Is part of iwlwifi
245  * iwlXXXX_     <-- Hardware specific (implemented in iwl-XXXX.c for XXXX)
246  *
247  ****************************************************************************/
248 void iwl_update_chain_flags(struct iwl_priv *priv);
249 extern const u8 iwl_bcast_addr[ETH_ALEN];
250 
251 #define IWL_OPERATION_MODE_AUTO     0
252 #define IWL_OPERATION_MODE_HT_ONLY  1
253 #define IWL_OPERATION_MODE_MIXED    2
254 #define IWL_OPERATION_MODE_20MHZ    3
255 
256 #define TX_POWER_IWL_ILLEGAL_VOLTAGE -10000
257 
258 /* Sensitivity and chain noise calibration */
259 #define INITIALIZATION_VALUE		0xFFFF
260 #define IWL_CAL_NUM_BEACONS		16
261 #define MAXIMUM_ALLOWED_PATHLOSS	15
262 
263 #define CHAIN_NOISE_MAX_DELTA_GAIN_CODE 3
264 
265 #define MAX_FA_OFDM  50
266 #define MIN_FA_OFDM  5
267 #define MAX_FA_CCK   50
268 #define MIN_FA_CCK   5
269 
270 #define AUTO_CORR_STEP_OFDM       1
271 
272 #define AUTO_CORR_STEP_CCK     3
273 #define AUTO_CORR_MAX_TH_CCK   160
274 
275 #define NRG_DIFF               2
276 #define NRG_STEP_CCK           2
277 #define NRG_MARGIN             8
278 #define MAX_NUMBER_CCK_NO_FA 100
279 
280 #define AUTO_CORR_CCK_MIN_VAL_DEF    (125)
281 
282 #define CHAIN_A             0
283 #define CHAIN_B             1
284 #define CHAIN_C             2
285 #define CHAIN_NOISE_DELTA_GAIN_INIT_VAL 4
286 #define ALL_BAND_FILTER			0xFF00
287 #define IN_BAND_FILTER			0xFF
288 #define MIN_AVERAGE_NOISE_MAX_VALUE	0xFFFFFFFF
289 
290 #define NRG_NUM_PREV_STAT_L     20
291 #define NUM_RX_CHAINS           3
292 
293 enum iwlagn_false_alarm_state {
294 	IWL_FA_TOO_MANY = 0,
295 	IWL_FA_TOO_FEW = 1,
296 	IWL_FA_GOOD_RANGE = 2,
297 };
298 
299 enum iwlagn_chain_noise_state {
300 	IWL_CHAIN_NOISE_ALIVE = 0,  /* must be 0 */
301 	IWL_CHAIN_NOISE_ACCUMULATE,
302 	IWL_CHAIN_NOISE_CALIBRATED,
303 	IWL_CHAIN_NOISE_DONE,
304 };
305 
306 /* Sensitivity calib data */
307 struct iwl_sensitivity_data {
308 	u32 auto_corr_ofdm;
309 	u32 auto_corr_ofdm_mrc;
310 	u32 auto_corr_ofdm_x1;
311 	u32 auto_corr_ofdm_mrc_x1;
312 	u32 auto_corr_cck;
313 	u32 auto_corr_cck_mrc;
314 
315 	u32 last_bad_plcp_cnt_ofdm;
316 	u32 last_fa_cnt_ofdm;
317 	u32 last_bad_plcp_cnt_cck;
318 	u32 last_fa_cnt_cck;
319 
320 	u32 nrg_curr_state;
321 	u32 nrg_prev_state;
322 	u32 nrg_value[10];
323 	u8  nrg_silence_rssi[NRG_NUM_PREV_STAT_L];
324 	u32 nrg_silence_ref;
325 	u32 nrg_energy_idx;
326 	u32 nrg_silence_idx;
327 	u32 nrg_th_cck;
328 	s32 nrg_auto_corr_silence_diff;
329 	u32 num_in_cck_no_fa;
330 	u32 nrg_th_ofdm;
331 
332 	u16 barker_corr_th_min;
333 	u16 barker_corr_th_min_mrc;
334 	u16 nrg_th_cca;
335 };
336 
337 /* Chain noise (differential Rx gain) calib data */
338 struct iwl_chain_noise_data {
339 	u32 active_chains;
340 	u32 chain_noise_a;
341 	u32 chain_noise_b;
342 	u32 chain_noise_c;
343 	u32 chain_signal_a;
344 	u32 chain_signal_b;
345 	u32 chain_signal_c;
346 	u16 beacon_count;
347 	u8 disconn_array[NUM_RX_CHAINS];
348 	u8 delta_gain_code[NUM_RX_CHAINS];
349 	u8 radio_write;
350 	u8 state;
351 };
352 
353 enum {
354 	MEASUREMENT_READY = (1 << 0),
355 	MEASUREMENT_ACTIVE = (1 << 1),
356 };
357 
358 /* reply_tx_statistics (for _agn devices) */
359 struct reply_tx_error_statistics {
360 	u32 pp_delay;
361 	u32 pp_few_bytes;
362 	u32 pp_bt_prio;
363 	u32 pp_quiet_period;
364 	u32 pp_calc_ttak;
365 	u32 int_crossed_retry;
366 	u32 short_limit;
367 	u32 long_limit;
368 	u32 fifo_underrun;
369 	u32 drain_flow;
370 	u32 rfkill_flush;
371 	u32 life_expire;
372 	u32 dest_ps;
373 	u32 host_abort;
374 	u32 bt_retry;
375 	u32 sta_invalid;
376 	u32 frag_drop;
377 	u32 tid_disable;
378 	u32 fifo_flush;
379 	u32 insuff_cf_poll;
380 	u32 fail_hw_drop;
381 	u32 sta_color_mismatch;
382 	u32 unknown;
383 };
384 
385 /* reply_agg_tx_statistics (for _agn devices) */
386 struct reply_agg_tx_error_statistics {
387 	u32 underrun;
388 	u32 bt_prio;
389 	u32 few_bytes;
390 	u32 abort;
391 	u32 last_sent_ttl;
392 	u32 last_sent_try;
393 	u32 last_sent_bt_kill;
394 	u32 scd_query;
395 	u32 bad_crc32;
396 	u32 response;
397 	u32 dump_tx;
398 	u32 delay_tx;
399 	u32 unknown;
400 };
401 
402 /*
403  * schedule the timer to wake up every UCODE_TRACE_PERIOD milliseconds
404  * to perform continuous uCode event logging operation if enabled
405  */
406 #define UCODE_TRACE_PERIOD (10)
407 
408 /*
409  * iwl_event_log: current uCode event log position
410  *
411  * @ucode_trace: enable/disable ucode continuous trace timer
412  * @num_wraps: how many times the event buffer wraps
413  * @next_entry:  the entry just before the next one that uCode would fill
414  * @non_wraps_count: counter for no wrap detected when dump ucode events
415  * @wraps_once_count: counter for wrap once detected when dump ucode events
416  * @wraps_more_count: counter for wrap more than once detected
417  *		      when dump ucode events
418  */
419 struct iwl_event_log {
420 	bool ucode_trace;
421 	u32 num_wraps;
422 	u32 next_entry;
423 	int non_wraps_count;
424 	int wraps_once_count;
425 	int wraps_more_count;
426 };
427 
428 #define IWL_DELAY_NEXT_FORCE_RF_RESET  (HZ*3)
429 
430 /* BT Antenna Coupling Threshold (dB) */
431 #define IWL_BT_ANTENNA_COUPLING_THRESHOLD	(35)
432 
433 /* Firmware reload counter and Timestamp */
434 #define IWL_MIN_RELOAD_DURATION		1000 /* 1000 ms */
435 #define IWL_MAX_CONTINUE_RELOAD_CNT	4
436 
437 
438 struct iwl_rf_reset {
439 	int reset_request_count;
440 	int reset_success_count;
441 	int reset_reject_count;
442 	unsigned long last_reset_jiffies;
443 };
444 
445 enum iwl_rxon_context_id {
446 	IWL_RXON_CTX_BSS,
447 	IWL_RXON_CTX_PAN,
448 
449 	NUM_IWL_RXON_CTX
450 };
451 
452 /* extend beacon time format bit shifting  */
453 /*
454  * for _agn devices
455  * bits 31:22 - extended
456  * bits 21:0  - interval
457  */
458 #define IWLAGN_EXT_BEACON_TIME_POS	22
459 
460 struct iwl_rxon_context {
461 	struct ieee80211_vif *vif;
462 
463 	u8 mcast_queue;
464 	u8 ac_to_queue[IEEE80211_NUM_ACS];
465 	u8 ac_to_fifo[IEEE80211_NUM_ACS];
466 
467 	/*
468 	 * We could use the vif to indicate active, but we
469 	 * also need it to be active during disabling when
470 	 * we already removed the vif for type setting.
471 	 */
472 	bool always_active, is_active;
473 
474 	bool ht_need_multiple_chains;
475 
476 	enum iwl_rxon_context_id ctxid;
477 
478 	u32 interface_modes, exclusive_interface_modes;
479 	u8 unused_devtype, ap_devtype, ibss_devtype, station_devtype;
480 
481 	/*
482 	 * We declare this const so it can only be
483 	 * changed via explicit cast within the
484 	 * routines that actually update the physical
485 	 * hardware.
486 	 */
487 	const struct iwl_rxon_cmd active;
488 	struct iwl_rxon_cmd staging;
489 
490 	struct iwl_rxon_time_cmd timing;
491 
492 	struct iwl_qos_info qos_data;
493 
494 	u8 bcast_sta_id, ap_sta_id;
495 
496 	u8 rxon_cmd, rxon_assoc_cmd, rxon_timing_cmd;
497 	u8 qos_cmd;
498 	u8 wep_key_cmd;
499 
500 	struct iwl_wep_key wep_keys[WEP_KEYS_MAX];
501 	u8 key_mapping_keys;
502 
503 	__le32 station_flags;
504 
505 	int beacon_int;
506 
507 	struct {
508 		bool non_gf_sta_present;
509 		u8 protection;
510 		bool enabled, is_40mhz;
511 		u8 extension_chan_offset;
512 	} ht;
513 };
514 
515 enum iwl_scan_type {
516 	IWL_SCAN_NORMAL,
517 	IWL_SCAN_RADIO_RESET,
518 };
519 
520 /**
521  * struct iwl_hw_params
522  *
523  * Holds the module parameters
524  *
525  * @tx_chains_num: Number of TX chains
526  * @rx_chains_num: Number of RX chains
527  * @ct_kill_threshold: temperature threshold - in hw dependent unit
528  * @ct_kill_exit_threshold: when to reeable the device - in hw dependent unit
529  *	relevant for 1000, 6000 and up
530  * @struct iwl_sensitivity_ranges: range of sensitivity values
531  * @use_rts_for_aggregation: use rts/cts protection for HT traffic
532  */
533 struct iwl_hw_params {
534 	u8  tx_chains_num;
535 	u8  rx_chains_num;
536 	bool use_rts_for_aggregation;
537 	u32 ct_kill_threshold;
538 	u32 ct_kill_exit_threshold;
539 
540 	const struct iwl_sensitivity_ranges *sens;
541 };
542 
543 /**
544  * struct iwl_dvm_bt_params - DVM specific BT (coex) parameters
545  * @advanced_bt_coexist: support advanced bt coexist
546  * @bt_init_traffic_load: specify initial bt traffic load
547  * @bt_prio_boost: default bt priority boost value
548  * @agg_time_limit: maximum number of uSec in aggregation
549  * @bt_sco_disable: uCode should not response to BT in SCO/ESCO mode
550  */
551 struct iwl_dvm_bt_params {
552 	bool advanced_bt_coexist;
553 	u8 bt_init_traffic_load;
554 	u32 bt_prio_boost;
555 	u16 agg_time_limit;
556 	bool bt_sco_disable;
557 	bool bt_session_2;
558 };
559 
560 /**
561  * struct iwl_dvm_cfg - DVM firmware specific device configuration
562  * @set_hw_params: set hardware parameters
563  * @set_channel_switch: send channel switch command
564  * @nic_config: apply device specific configuration
565  * @temperature: read temperature
566  * @adv_thermal_throttle: support advance thermal throttle
567  * @support_ct_kill_exit: support ct kill exit condition
568  * @plcp_delta_threshold: plcp error rate threshold used to trigger
569  *	radio tuning when there is a high receiving plcp error rate
570  * @chain_noise_scale: default chain noise scale used for gain computation
571  * @hd_v2: v2 of enhanced sensitivity value, used for 2000 series and up
572  * @no_idle_support: do not support idle mode
573  * @bt_params: pointer to BT parameters
574  * @need_temp_offset_calib: need to perform temperature offset calibration
575  * @no_xtal_calib: some devices do not need crystal calibration data,
576  *	don't send it to those
577  * @temp_offset_v2: support v2 of temperature offset calibration
578  * @adv_pm: advanced power management
579  */
580 struct iwl_dvm_cfg {
581 	void (*set_hw_params)(struct iwl_priv *priv);
582 	int (*set_channel_switch)(struct iwl_priv *priv,
583 				  struct ieee80211_channel_switch *ch_switch);
584 	void (*nic_config)(struct iwl_priv *priv);
585 	void (*temperature)(struct iwl_priv *priv);
586 
587 	const struct iwl_dvm_bt_params *bt_params;
588 	s32 chain_noise_scale;
589 	u8 plcp_delta_threshold;
590 	bool adv_thermal_throttle;
591 	bool support_ct_kill_exit;
592 	bool hd_v2;
593 	bool no_idle_support;
594 	bool need_temp_offset_calib;
595 	bool no_xtal_calib;
596 	bool temp_offset_v2;
597 	bool adv_pm;
598 };
599 
600 struct iwl_wipan_noa_data {
601 	struct rcu_head rcu_head;
602 	u32 length;
603 	u8 data[];
604 };
605 
606 /* Calibration disabling bit mask */
607 enum {
608 	IWL_CALIB_ENABLE_ALL			= 0,
609 
610 	IWL_SENSITIVITY_CALIB_DISABLED		= BIT(0),
611 	IWL_CHAIN_NOISE_CALIB_DISABLED		= BIT(1),
612 	IWL_TX_POWER_CALIB_DISABLED		= BIT(2),
613 
614 	IWL_CALIB_DISABLE_ALL			= 0xFFFFFFFF,
615 };
616 
617 #define IWL_OP_MODE_GET_DVM(_iwl_op_mode) \
618 	((struct iwl_priv *) ((_iwl_op_mode)->op_mode_specific))
619 
620 #define IWL_MAC80211_GET_DVM(_hw) \
621 	((struct iwl_priv *) ((struct iwl_op_mode *) \
622 	(_hw)->priv)->op_mode_specific)
623 
624 struct iwl_priv {
625 
626 	struct iwl_trans *trans;
627 	struct device *dev;		/* for debug prints only */
628 	const struct iwl_cfg *cfg;
629 	const struct iwl_fw *fw;
630 	const struct iwl_dvm_cfg *lib;
631 	unsigned long status;
632 
633 	spinlock_t sta_lock;
634 	struct mutex mutex;
635 
636 	unsigned long transport_queue_stop;
637 	bool passive_no_rx;
638 #define IWL_INVALID_MAC80211_QUEUE	0xff
639 	u8 queue_to_mac80211[IWL_MAX_HW_QUEUES];
640 	atomic_t queue_stop_count[IWL_MAX_HW_QUEUES];
641 
642 	unsigned long agg_q_alloc[BITS_TO_LONGS(IWL_MAX_HW_QUEUES)];
643 
644 	/* ieee device used by generic ieee processing code */
645 	struct ieee80211_hw *hw;
646 
647 	struct napi_struct *napi;
648 
649 	struct list_head calib_results;
650 
651 	struct workqueue_struct *workqueue;
652 
653 	struct iwl_hw_params hw_params;
654 
655 	enum nl80211_band band;
656 	u8 valid_contexts;
657 
658 	void (*rx_handlers[REPLY_MAX])(struct iwl_priv *priv,
659 				       struct iwl_rx_cmd_buffer *rxb);
660 
661 	struct iwl_notif_wait_data notif_wait;
662 
663 	/* spectrum measurement report caching */
664 	struct iwl_spectrum_notification measure_report;
665 	u8 measurement_status;
666 
667 	/* ucode beacon time */
668 	u32 ucode_beacon_time;
669 	int missed_beacon_threshold;
670 
671 	/* track IBSS manager (last beacon) status */
672 	u32 ibss_manager;
673 
674 	/* jiffies when last recovery from statistics was performed */
675 	unsigned long rx_statistics_jiffies;
676 
677 	/*counters */
678 	u32 rx_handlers_stats[REPLY_MAX];
679 
680 	/* rf reset */
681 	struct iwl_rf_reset rf_reset;
682 
683 	/* firmware reload counter and timestamp */
684 	unsigned long reload_jiffies;
685 	int reload_count;
686 	bool ucode_loaded;
687 
688 	u8 plcp_delta_threshold;
689 
690 	/* thermal calibration */
691 	s32 temperature;	/* Celsius */
692 	s32 last_temperature;
693 
694 	struct iwl_wipan_noa_data __rcu *noa_data;
695 
696 	/* Scan related variables */
697 	unsigned long scan_start;
698 	unsigned long scan_start_tsf;
699 	void *scan_cmd;
700 	enum nl80211_band scan_band;
701 	struct cfg80211_scan_request *scan_request;
702 	struct ieee80211_vif *scan_vif;
703 	enum iwl_scan_type scan_type;
704 	u8 scan_tx_ant[NUM_NL80211_BANDS];
705 	u8 mgmt_tx_ant;
706 
707 	/* max number of station keys */
708 	u8 sta_key_max_num;
709 
710 	bool new_scan_threshold_behaviour;
711 
712 	bool wowlan;
713 
714 	/* EEPROM MAC addresses */
715 	struct mac_address addresses[2];
716 
717 	struct iwl_rxon_context contexts[NUM_IWL_RXON_CTX];
718 
719 	__le16 switch_channel;
720 
721 	u8 start_calib;
722 	struct iwl_sensitivity_data sensitivity_data;
723 	struct iwl_chain_noise_data chain_noise_data;
724 	__le16 sensitivity_tbl[HD_TABLE_SIZE];
725 	__le16 enhance_sensitivity_tbl[ENHANCE_HD_TABLE_ENTRIES];
726 
727 	struct iwl_ht_config current_ht_config;
728 
729 	/* Rate scaling data */
730 	u8 retry_rate;
731 
732 	int activity_timer_active;
733 
734 	struct iwl_power_mgr power_data;
735 	struct iwl_tt_mgmt thermal_throttle;
736 
737 	/* station table variables */
738 	int num_stations;
739 	struct iwl_station_entry stations[IWLAGN_STATION_COUNT];
740 	unsigned long ucode_key_table;
741 	struct iwl_tid_data tid_data[IWLAGN_STATION_COUNT][IWL_MAX_TID_COUNT];
742 	atomic_t num_aux_in_flight;
743 
744 	u8 mac80211_registered;
745 
746 	/* Indication if ieee80211_ops->open has been called */
747 	u8 is_open;
748 
749 	enum nl80211_iftype iw_mode;
750 
751 	/* Last Rx'd beacon timestamp */
752 	u64 timestamp;
753 
754 	struct {
755 		__le32 flag;
756 		struct statistics_general_common common;
757 		struct statistics_rx_non_phy rx_non_phy;
758 		struct statistics_rx_phy rx_ofdm;
759 		struct statistics_rx_ht_phy rx_ofdm_ht;
760 		struct statistics_rx_phy rx_cck;
761 		struct statistics_tx tx;
762 #ifdef CONFIG_IWLWIFI_DEBUGFS
763 		struct statistics_bt_activity bt_activity;
764 		__le32 num_bt_kills, accum_num_bt_kills;
765 #endif
766 		spinlock_t lock;
767 	} statistics;
768 #ifdef CONFIG_IWLWIFI_DEBUGFS
769 	struct {
770 		struct statistics_general_common common;
771 		struct statistics_rx_non_phy rx_non_phy;
772 		struct statistics_rx_phy rx_ofdm;
773 		struct statistics_rx_ht_phy rx_ofdm_ht;
774 		struct statistics_rx_phy rx_cck;
775 		struct statistics_tx tx;
776 		struct statistics_bt_activity bt_activity;
777 	} accum_stats, delta_stats, max_delta_stats;
778 #endif
779 
780 	/*
781 	 * reporting the number of tids has AGG on. 0 means
782 	 * no AGGREGATION
783 	 */
784 	u8 agg_tids_count;
785 
786 	struct iwl_rx_phy_res last_phy_res;
787 	u32 ampdu_ref;
788 	bool last_phy_res_valid;
789 
790 	/*
791 	 * chain noise reset and gain commands are the
792 	 * two extra calibration commands follows the standard
793 	 * phy calibration commands
794 	 */
795 	u8 phy_calib_chain_noise_reset_cmd;
796 	u8 phy_calib_chain_noise_gain_cmd;
797 
798 	/* counts reply_tx error */
799 	struct reply_tx_error_statistics reply_tx_stats;
800 	struct reply_agg_tx_error_statistics reply_agg_tx_stats;
801 
802 	/* bt coex */
803 	u8 bt_enable_flag;
804 	u8 bt_status;
805 	u8 bt_traffic_load, last_bt_traffic_load;
806 	bool bt_ch_announce;
807 	bool bt_full_concurrent;
808 	__le32 kill_ack_mask;
809 	__le32 kill_cts_mask;
810 	__le16 bt_valid;
811 	bool reduced_txpower;
812 	u16 bt_on_thresh;
813 	u16 bt_duration;
814 	u16 dynamic_frag_thresh;
815 	u8 bt_ci_compliance;
816 	struct work_struct bt_traffic_change_work;
817 	bool bt_enable_pspoll;
818 	struct iwl_rxon_context *cur_rssi_ctx;
819 	bool bt_is_sco;
820 
821 	struct work_struct restart;
822 	struct work_struct scan_completed;
823 	struct work_struct abort_scan;
824 
825 	struct work_struct beacon_update;
826 	struct iwl_rxon_context *beacon_ctx;
827 	struct sk_buff *beacon_skb;
828 	void *beacon_cmd;
829 
830 	struct work_struct tt_work;
831 	struct work_struct ct_enter;
832 	struct work_struct ct_exit;
833 	struct work_struct start_internal_scan;
834 	struct work_struct tx_flush;
835 	struct work_struct bt_full_concurrency;
836 	struct work_struct bt_runtime_config;
837 
838 	struct delayed_work scan_check;
839 
840 	/* TX Power settings */
841 	s8 tx_power_user_lmt;
842 	s8 tx_power_next;
843 
844 #ifdef CONFIG_IWLWIFI_DEBUGFS
845 	/* debugfs */
846 	struct dentry *debugfs_dir;
847 	u32 dbgfs_sram_offset, dbgfs_sram_len;
848 	bool disable_ht40;
849 	void *wowlan_sram;
850 #endif /* CONFIG_IWLWIFI_DEBUGFS */
851 
852 	struct iwl_nvm_data *nvm_data;
853 	/* eeprom blob for debugfs */
854 	u8 *eeprom_blob;
855 	size_t eeprom_blob_size;
856 
857 	struct work_struct txpower_work;
858 	u32 calib_disabled;
859 	struct work_struct run_time_calib_work;
860 	struct timer_list statistics_periodic;
861 	struct timer_list ucode_trace;
862 
863 	struct iwl_event_log event_log;
864 
865 #ifdef CONFIG_IWLWIFI_LEDS
866 	struct led_classdev led;
867 	unsigned long blink_on, blink_off;
868 	bool led_registered;
869 #endif
870 
871 	/* WoWLAN GTK rekey data */
872 	u8 kck[NL80211_KCK_LEN], kek[NL80211_KEK_LEN];
873 	__le64 replay_ctr;
874 	__le16 last_seq_ctl;
875 	bool have_rekey_data;
876 #ifdef CONFIG_PM_SLEEP
877 	struct wiphy_wowlan_support wowlan_support;
878 #endif
879 
880 	/* device_pointers: pointers to ucode event tables */
881 	struct {
882 		u32 error_event_table;
883 		u32 log_event_table;
884 	} device_pointers;
885 
886 	/* indicator of loaded ucode image */
887 	enum iwl_ucode_type cur_ucode;
888 }; /*iwl_priv */
889 
890 static inline struct iwl_rxon_context *
iwl_rxon_ctx_from_vif(struct ieee80211_vif * vif)891 iwl_rxon_ctx_from_vif(struct ieee80211_vif *vif)
892 {
893 	struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
894 
895 	return vif_priv->ctx;
896 }
897 
898 #define for_each_context(priv, ctx)				\
899 	for (ctx = &priv->contexts[IWL_RXON_CTX_BSS];		\
900 	     ctx < &priv->contexts[NUM_IWL_RXON_CTX]; ctx++)	\
901 		if (priv->valid_contexts & BIT(ctx->ctxid))
902 
iwl_is_associated_ctx(struct iwl_rxon_context * ctx)903 static inline int iwl_is_associated_ctx(struct iwl_rxon_context *ctx)
904 {
905 	return (ctx->active.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0;
906 }
907 
iwl_is_associated(struct iwl_priv * priv,enum iwl_rxon_context_id ctxid)908 static inline int iwl_is_associated(struct iwl_priv *priv,
909 				    enum iwl_rxon_context_id ctxid)
910 {
911 	return iwl_is_associated_ctx(&priv->contexts[ctxid]);
912 }
913 
iwl_is_any_associated(struct iwl_priv * priv)914 static inline int iwl_is_any_associated(struct iwl_priv *priv)
915 {
916 	struct iwl_rxon_context *ctx;
917 	for_each_context(priv, ctx)
918 		if (iwl_is_associated_ctx(ctx))
919 			return true;
920 	return false;
921 }
922 
923 #endif				/* __iwl_dev_h__ */
924