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