1 /******************************************************************************
2  *
3  * Copyright(c) 2003 - 2012 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  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17  *
18  * The full GNU General Public License is included in this distribution in the
19  * file called LICENSE.
20  *
21  * Contact Information:
22  *  Intel Linux Wireless <ilw@linux.intel.com>
23  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24  *
25  *****************************************************************************/
26 /*
27  * Please use this file (iwl-dev.h) for driver implementation definitions.
28  * Please use iwl-commands.h for uCode API definitions.
29  */
30 
31 #ifndef __iwl_dev_h__
32 #define __iwl_dev_h__
33 
34 #include <linux/interrupt.h>
35 #include <linux/kernel.h>
36 #include <linux/wait.h>
37 #include <linux/leds.h>
38 #include <linux/slab.h>
39 #include <linux/mutex.h>
40 
41 #include "iwl-eeprom.h"
42 #include "iwl-csr.h"
43 #include "iwl-debug.h"
44 #include "iwl-agn-hw.h"
45 #include "iwl-led.h"
46 #include "iwl-power.h"
47 #include "iwl-agn-rs.h"
48 #include "iwl-agn-tt.h"
49 #include "iwl-trans.h"
50 #include "iwl-shared.h"
51 #include "iwl-op-mode.h"
52 #include "iwl-notif-wait.h"
53 
54 struct iwl_tx_queue;
55 
56 /* CT-KILL constants */
57 #define CT_KILL_THRESHOLD_LEGACY   110 /* in Celsius */
58 #define CT_KILL_THRESHOLD	   114 /* in Celsius */
59 #define CT_KILL_EXIT_THRESHOLD     95  /* in Celsius */
60 
61 /* Default noise level to report when noise measurement is not available.
62  *   This may be because we're:
63  *   1)  Not associated  no beacon statistics being sent to driver)
64  *   2)  Scanning (noise measurement does not apply to associated channel)
65  * Use default noise value of -127 ... this is below the range of measurable
66  *   Rx dBm for all agn devices, so it can indicate "unmeasurable" to user.
67  *   Also, -127 works better than 0 when averaging frames with/without
68  *   noise info (e.g. averaging might be done in app); measured dBm values are
69  *   always negative ... using a negative value as the default keeps all
70  *   averages within an s8's (used in some apps) range of negative values. */
71 #define IWL_NOISE_MEAS_NOT_AVAILABLE (-127)
72 
73 /*
74  * RTS threshold here is total size [2347] minus 4 FCS bytes
75  * Per spec:
76  *   a value of 0 means RTS on all data/management packets
77  *   a value > max MSDU size means no RTS
78  * else RTS for data/management frames where MPDU is larger
79  *   than RTS value.
80  */
81 #define DEFAULT_RTS_THRESHOLD     2347U
82 #define MIN_RTS_THRESHOLD         0U
83 #define MAX_RTS_THRESHOLD         2347U
84 #define MAX_MSDU_SIZE		  2304U
85 #define MAX_MPDU_SIZE		  2346U
86 #define DEFAULT_BEACON_INTERVAL   200U
87 #define	DEFAULT_SHORT_RETRY_LIMIT 7U
88 #define	DEFAULT_LONG_RETRY_LIMIT  4U
89 
90 #define IWL_NUM_SCAN_RATES         (2)
91 
92 /*
93  * One for each channel, holds all channel setup data
94  * Some of the fields (e.g. eeprom and flags/max_power_avg) are redundant
95  *     with one another!
96  */
97 struct iwl_channel_info {
98 	struct iwl_eeprom_channel eeprom;	/* EEPROM regulatory limit */
99 	struct iwl_eeprom_channel ht40_eeprom;	/* EEPROM regulatory limit for
100 						 * HT40 channel */
101 
102 	u8 channel;	  /* channel number */
103 	u8 flags;	  /* flags copied from EEPROM */
104 	s8 max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */
105 	s8 curr_txpow;	  /* (dBm) regulatory/spectrum/user (not h/w) limit */
106 	s8 min_power;	  /* always 0 */
107 	s8 scan_power;	  /* (dBm) regul. eeprom, direct scans, any rate */
108 
109 	u8 group_index;	  /* 0-4, maps channel to group1/2/3/4/5 */
110 	u8 band_index;	  /* 0-4, maps channel to band1/2/3/4/5 */
111 	enum ieee80211_band band;
112 
113 	/* HT40 channel info */
114 	s8 ht40_max_power_avg;	/* (dBm) regul. eeprom, normal Tx, any rate */
115 	u8 ht40_flags;		/* flags copied from EEPROM */
116 	u8 ht40_extension_channel; /* HT_IE_EXT_CHANNEL_* */
117 };
118 
119 /*
120  * Minimum number of queues. MAX_NUM is defined in hw specific files.
121  * Set the minimum to accommodate
122  *  - 4 standard TX queues
123  *  - the command queue
124  *  - 4 PAN TX queues
125  *  - the PAN multicast queue, and
126  *  - the AUX (TX during scan dwell) queue.
127  */
128 #define IWL_MIN_NUM_QUEUES	11
129 
130 /*
131  * Command queue depends on iPAN support.
132  */
133 #define IWL_DEFAULT_CMD_QUEUE_NUM	4
134 #define IWL_IPAN_CMD_QUEUE_NUM		9
135 
136 #define IEEE80211_DATA_LEN              2304
137 #define IEEE80211_4ADDR_LEN             30
138 #define IEEE80211_HLEN                  (IEEE80211_4ADDR_LEN)
139 #define IEEE80211_FRAME_LEN             (IEEE80211_DATA_LEN + IEEE80211_HLEN)
140 
141 #define SUP_RATE_11A_MAX_NUM_CHANNELS  8
142 #define SUP_RATE_11B_MAX_NUM_CHANNELS  4
143 #define SUP_RATE_11G_MAX_NUM_CHANNELS  12
144 
145 #define IWL_SUPPORTED_RATES_IE_LEN         8
146 
147 #define IWL_INVALID_RATE     0xFF
148 #define IWL_INVALID_VALUE    -1
149 
150 union iwl_ht_rate_supp {
151 	u16 rates;
152 	struct {
153 		u8 siso_rate;
154 		u8 mimo_rate;
155 	};
156 };
157 
158 #define CFG_HT_RX_AMPDU_FACTOR_8K   (0x0)
159 #define CFG_HT_RX_AMPDU_FACTOR_16K  (0x1)
160 #define CFG_HT_RX_AMPDU_FACTOR_32K  (0x2)
161 #define CFG_HT_RX_AMPDU_FACTOR_64K  (0x3)
162 #define CFG_HT_RX_AMPDU_FACTOR_DEF  CFG_HT_RX_AMPDU_FACTOR_64K
163 #define CFG_HT_RX_AMPDU_FACTOR_MAX  CFG_HT_RX_AMPDU_FACTOR_64K
164 #define CFG_HT_RX_AMPDU_FACTOR_MIN  CFG_HT_RX_AMPDU_FACTOR_8K
165 
166 /*
167  * Maximal MPDU density for TX aggregation
168  * 4 - 2us density
169  * 5 - 4us density
170  * 6 - 8us density
171  * 7 - 16us density
172  */
173 #define CFG_HT_MPDU_DENSITY_2USEC   (0x4)
174 #define CFG_HT_MPDU_DENSITY_4USEC   (0x5)
175 #define CFG_HT_MPDU_DENSITY_8USEC   (0x6)
176 #define CFG_HT_MPDU_DENSITY_16USEC  (0x7)
177 #define CFG_HT_MPDU_DENSITY_DEF CFG_HT_MPDU_DENSITY_4USEC
178 #define CFG_HT_MPDU_DENSITY_MAX CFG_HT_MPDU_DENSITY_16USEC
179 #define CFG_HT_MPDU_DENSITY_MIN     (0x1)
180 
181 struct iwl_ht_config {
182 	bool single_chain_sufficient;
183 	enum ieee80211_smps_mode smps; /* current smps mode */
184 };
185 
186 /* QoS structures */
187 struct iwl_qos_info {
188 	int qos_active;
189 	struct iwl_qosparam_cmd def_qos_parm;
190 };
191 
192 /**
193  * enum iwl_agg_state
194  *
195  * The state machine of the BA agreement establishment / tear down.
196  * These states relate to a specific RA / TID.
197  *
198  * @IWL_AGG_OFF: aggregation is not used
199  * @IWL_AGG_ON: aggregation session is up
200  * @IWL_EMPTYING_HW_QUEUE_ADDBA: establishing a BA session - waiting for the
201  *	HW queue to be empty from packets for this RA /TID.
202  * @IWL_EMPTYING_HW_QUEUE_DELBA: tearing down a BA session - waiting for the
203  *	HW queue to be empty from packets for this RA /TID.
204  */
205 enum iwl_agg_state {
206 	IWL_AGG_OFF = 0,
207 	IWL_AGG_ON,
208 	IWL_EMPTYING_HW_QUEUE_ADDBA,
209 	IWL_EMPTYING_HW_QUEUE_DELBA,
210 };
211 
212 /**
213  * struct iwl_ht_agg - aggregation state machine
214 
215  * This structs holds the states for the BA agreement establishment and tear
216  * down. It also holds the state during the BA session itself. This struct is
217  * duplicated for each RA / TID.
218 
219  * @rate_n_flags: Rate at which Tx was attempted. Holds the data between the
220  *	Tx response (REPLY_TX), and the block ack notification
221  *	(REPLY_COMPRESSED_BA).
222  * @state: state of the BA agreement establishment / tear down.
223  * @txq_id: Tx queue used by the BA session - used by the transport layer.
224  *	Needed by the upper layer for debugfs only.
225  * @ssn: the first packet to be sent in AGG HW queue in Tx AGG start flow, or
226  *	the first packet to be sent in legacy HW queue in Tx AGG stop flow.
227  *	Basically when next_reclaimed reaches ssn, we can tell mac80211 that
228  *	we are ready to finish the Tx AGG stop / start flow.
229  * @wait_for_ba: Expect block-ack before next Tx reply
230  */
231 struct iwl_ht_agg {
232 	u32 rate_n_flags;
233 	enum iwl_agg_state state;
234 	u16 txq_id;
235 	u16 ssn;
236 	bool wait_for_ba;
237 };
238 
239 /**
240  * struct iwl_tid_data - one for each RA / TID
241 
242  * This structs holds the states for each RA / TID.
243 
244  * @seq_number: the next WiFi sequence number to use
245  * @next_reclaimed: the WiFi sequence number of the next packet to be acked.
246  *	This is basically (last acked packet++).
247  * @agg: aggregation state machine
248  */
249 struct iwl_tid_data {
250 	u16 seq_number;
251 	u16 next_reclaimed;
252 	struct iwl_ht_agg agg;
253 };
254 
255 /*
256  * Structure should be accessed with sta_lock held. When station addition
257  * is in progress (IWL_STA_UCODE_INPROGRESS) it is possible to access only
258  * the commands (iwl_addsta_cmd and iwl_link_quality_cmd) without sta_lock
259  * held.
260  */
261 struct iwl_station_entry {
262 	struct iwl_addsta_cmd sta;
263 	u8 used, ctxid;
264 	struct iwl_link_quality_cmd *lq;
265 };
266 
267 /*
268  * iwl_station_priv: Driver's private station information
269  *
270  * When mac80211 creates a station it reserves some space (hw->sta_data_size)
271  * in the structure for use by driver. This structure is places in that
272  * space.
273  */
274 struct iwl_station_priv {
275 	struct iwl_rxon_context *ctx;
276 	struct iwl_lq_sta lq_sta;
277 	atomic_t pending_frames;
278 	bool client;
279 	bool asleep;
280 	u8 max_agg_bufsize;
281 	u8 sta_id;
282 };
283 
284 /**
285  * struct iwl_vif_priv - driver's private per-interface information
286  *
287  * When mac80211 allocates a virtual interface, it can allocate
288  * space for us to put data into.
289  */
290 struct iwl_vif_priv {
291 	struct iwl_rxon_context *ctx;
292 	u8 ibss_bssid_sta_id;
293 };
294 
295 struct iwl_sensitivity_ranges {
296 	u16 min_nrg_cck;
297 
298 	u16 nrg_th_cck;
299 	u16 nrg_th_ofdm;
300 
301 	u16 auto_corr_min_ofdm;
302 	u16 auto_corr_min_ofdm_mrc;
303 	u16 auto_corr_min_ofdm_x1;
304 	u16 auto_corr_min_ofdm_mrc_x1;
305 
306 	u16 auto_corr_max_ofdm;
307 	u16 auto_corr_max_ofdm_mrc;
308 	u16 auto_corr_max_ofdm_x1;
309 	u16 auto_corr_max_ofdm_mrc_x1;
310 
311 	u16 auto_corr_max_cck;
312 	u16 auto_corr_max_cck_mrc;
313 	u16 auto_corr_min_cck;
314 	u16 auto_corr_min_cck_mrc;
315 
316 	u16 barker_corr_th_min;
317 	u16 barker_corr_th_min_mrc;
318 	u16 nrg_th_cca;
319 };
320 
321 
322 #define KELVIN_TO_CELSIUS(x) ((x)-273)
323 #define CELSIUS_TO_KELVIN(x) ((x)+273)
324 
325 
326 /******************************************************************************
327  *
328  * Functions implemented in core module which are forward declared here
329  * for use by iwl-[4-5].c
330  *
331  * NOTE:  The implementation of these functions are not hardware specific
332  * which is why they are in the core module files.
333  *
334  * Naming convention --
335  * iwl_         <-- Is part of iwlwifi
336  * iwlXXXX_     <-- Hardware specific (implemented in iwl-XXXX.c for XXXX)
337  *
338  ****************************************************************************/
339 extern void iwl_update_chain_flags(struct iwl_priv *priv);
340 extern const u8 iwl_bcast_addr[ETH_ALEN];
341 
342 #define IWL_OPERATION_MODE_AUTO     0
343 #define IWL_OPERATION_MODE_HT_ONLY  1
344 #define IWL_OPERATION_MODE_MIXED    2
345 #define IWL_OPERATION_MODE_20MHZ    3
346 
347 #define TX_POWER_IWL_ILLEGAL_VOLTAGE -10000
348 
349 /* Sensitivity and chain noise calibration */
350 #define INITIALIZATION_VALUE		0xFFFF
351 #define IWL_CAL_NUM_BEACONS		16
352 #define MAXIMUM_ALLOWED_PATHLOSS	15
353 
354 #define CHAIN_NOISE_MAX_DELTA_GAIN_CODE 3
355 
356 #define MAX_FA_OFDM  50
357 #define MIN_FA_OFDM  5
358 #define MAX_FA_CCK   50
359 #define MIN_FA_CCK   5
360 
361 #define AUTO_CORR_STEP_OFDM       1
362 
363 #define AUTO_CORR_STEP_CCK     3
364 #define AUTO_CORR_MAX_TH_CCK   160
365 
366 #define NRG_DIFF               2
367 #define NRG_STEP_CCK           2
368 #define NRG_MARGIN             8
369 #define MAX_NUMBER_CCK_NO_FA 100
370 
371 #define AUTO_CORR_CCK_MIN_VAL_DEF    (125)
372 
373 #define CHAIN_A             0
374 #define CHAIN_B             1
375 #define CHAIN_C             2
376 #define CHAIN_NOISE_DELTA_GAIN_INIT_VAL 4
377 #define ALL_BAND_FILTER			0xFF00
378 #define IN_BAND_FILTER			0xFF
379 #define MIN_AVERAGE_NOISE_MAX_VALUE	0xFFFFFFFF
380 
381 #define NRG_NUM_PREV_STAT_L     20
382 #define NUM_RX_CHAINS           3
383 
384 enum iwlagn_false_alarm_state {
385 	IWL_FA_TOO_MANY = 0,
386 	IWL_FA_TOO_FEW = 1,
387 	IWL_FA_GOOD_RANGE = 2,
388 };
389 
390 enum iwlagn_chain_noise_state {
391 	IWL_CHAIN_NOISE_ALIVE = 0,  /* must be 0 */
392 	IWL_CHAIN_NOISE_ACCUMULATE,
393 	IWL_CHAIN_NOISE_CALIBRATED,
394 	IWL_CHAIN_NOISE_DONE,
395 };
396 
397 /* Sensitivity calib data */
398 struct iwl_sensitivity_data {
399 	u32 auto_corr_ofdm;
400 	u32 auto_corr_ofdm_mrc;
401 	u32 auto_corr_ofdm_x1;
402 	u32 auto_corr_ofdm_mrc_x1;
403 	u32 auto_corr_cck;
404 	u32 auto_corr_cck_mrc;
405 
406 	u32 last_bad_plcp_cnt_ofdm;
407 	u32 last_fa_cnt_ofdm;
408 	u32 last_bad_plcp_cnt_cck;
409 	u32 last_fa_cnt_cck;
410 
411 	u32 nrg_curr_state;
412 	u32 nrg_prev_state;
413 	u32 nrg_value[10];
414 	u8  nrg_silence_rssi[NRG_NUM_PREV_STAT_L];
415 	u32 nrg_silence_ref;
416 	u32 nrg_energy_idx;
417 	u32 nrg_silence_idx;
418 	u32 nrg_th_cck;
419 	s32 nrg_auto_corr_silence_diff;
420 	u32 num_in_cck_no_fa;
421 	u32 nrg_th_ofdm;
422 
423 	u16 barker_corr_th_min;
424 	u16 barker_corr_th_min_mrc;
425 	u16 nrg_th_cca;
426 };
427 
428 /* Chain noise (differential Rx gain) calib data */
429 struct iwl_chain_noise_data {
430 	u32 active_chains;
431 	u32 chain_noise_a;
432 	u32 chain_noise_b;
433 	u32 chain_noise_c;
434 	u32 chain_signal_a;
435 	u32 chain_signal_b;
436 	u32 chain_signal_c;
437 	u16 beacon_count;
438 	u8 disconn_array[NUM_RX_CHAINS];
439 	u8 delta_gain_code[NUM_RX_CHAINS];
440 	u8 radio_write;
441 	u8 state;
442 };
443 
444 enum {
445 	MEASUREMENT_READY = (1 << 0),
446 	MEASUREMENT_ACTIVE = (1 << 1),
447 };
448 
449 enum iwl_nvm_type {
450 	NVM_DEVICE_TYPE_EEPROM = 0,
451 	NVM_DEVICE_TYPE_OTP,
452 };
453 
454 /*
455  * Two types of OTP memory access modes
456  *   IWL_OTP_ACCESS_ABSOLUTE - absolute address mode,
457  * 			        based on physical memory addressing
458  *   IWL_OTP_ACCESS_RELATIVE - relative address mode,
459  * 			       based on logical memory addressing
460  */
461 enum iwl_access_mode {
462 	IWL_OTP_ACCESS_ABSOLUTE,
463 	IWL_OTP_ACCESS_RELATIVE,
464 };
465 
466 /* reply_tx_statistics (for _agn devices) */
467 struct reply_tx_error_statistics {
468 	u32 pp_delay;
469 	u32 pp_few_bytes;
470 	u32 pp_bt_prio;
471 	u32 pp_quiet_period;
472 	u32 pp_calc_ttak;
473 	u32 int_crossed_retry;
474 	u32 short_limit;
475 	u32 long_limit;
476 	u32 fifo_underrun;
477 	u32 drain_flow;
478 	u32 rfkill_flush;
479 	u32 life_expire;
480 	u32 dest_ps;
481 	u32 host_abort;
482 	u32 bt_retry;
483 	u32 sta_invalid;
484 	u32 frag_drop;
485 	u32 tid_disable;
486 	u32 fifo_flush;
487 	u32 insuff_cf_poll;
488 	u32 fail_hw_drop;
489 	u32 sta_color_mismatch;
490 	u32 unknown;
491 };
492 
493 /* reply_agg_tx_statistics (for _agn devices) */
494 struct reply_agg_tx_error_statistics {
495 	u32 underrun;
496 	u32 bt_prio;
497 	u32 few_bytes;
498 	u32 abort;
499 	u32 last_sent_ttl;
500 	u32 last_sent_try;
501 	u32 last_sent_bt_kill;
502 	u32 scd_query;
503 	u32 bad_crc32;
504 	u32 response;
505 	u32 dump_tx;
506 	u32 delay_tx;
507 	u32 unknown;
508 };
509 
510 /* management statistics */
511 enum iwl_mgmt_stats {
512 	MANAGEMENT_ASSOC_REQ = 0,
513 	MANAGEMENT_ASSOC_RESP,
514 	MANAGEMENT_REASSOC_REQ,
515 	MANAGEMENT_REASSOC_RESP,
516 	MANAGEMENT_PROBE_REQ,
517 	MANAGEMENT_PROBE_RESP,
518 	MANAGEMENT_BEACON,
519 	MANAGEMENT_ATIM,
520 	MANAGEMENT_DISASSOC,
521 	MANAGEMENT_AUTH,
522 	MANAGEMENT_DEAUTH,
523 	MANAGEMENT_ACTION,
524 	MANAGEMENT_MAX,
525 };
526 /* control statistics */
527 enum iwl_ctrl_stats {
528 	CONTROL_BACK_REQ =  0,
529 	CONTROL_BACK,
530 	CONTROL_PSPOLL,
531 	CONTROL_RTS,
532 	CONTROL_CTS,
533 	CONTROL_ACK,
534 	CONTROL_CFEND,
535 	CONTROL_CFENDACK,
536 	CONTROL_MAX,
537 };
538 
539 struct traffic_stats {
540 #ifdef CONFIG_IWLWIFI_DEBUGFS
541 	u32 mgmt[MANAGEMENT_MAX];
542 	u32 ctrl[CONTROL_MAX];
543 	u32 data_cnt;
544 	u64 data_bytes;
545 #endif
546 };
547 
548 /*
549  * schedule the timer to wake up every UCODE_TRACE_PERIOD milliseconds
550  * to perform continuous uCode event logging operation if enabled
551  */
552 #define UCODE_TRACE_PERIOD (10)
553 
554 /*
555  * iwl_event_log: current uCode event log position
556  *
557  * @ucode_trace: enable/disable ucode continuous trace timer
558  * @num_wraps: how many times the event buffer wraps
559  * @next_entry:  the entry just before the next one that uCode would fill
560  * @non_wraps_count: counter for no wrap detected when dump ucode events
561  * @wraps_once_count: counter for wrap once detected when dump ucode events
562  * @wraps_more_count: counter for wrap more than once detected
563  *		      when dump ucode events
564  */
565 struct iwl_event_log {
566 	bool ucode_trace;
567 	u32 num_wraps;
568 	u32 next_entry;
569 	int non_wraps_count;
570 	int wraps_once_count;
571 	int wraps_more_count;
572 };
573 
574 /*
575  * This is the threshold value of plcp error rate per 100mSecs.  It is
576  * used to set and check for the validity of plcp_delta.
577  */
578 #define IWL_MAX_PLCP_ERR_THRESHOLD_MIN	(1)
579 #define IWL_MAX_PLCP_ERR_THRESHOLD_DEF	(50)
580 #define IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF	(100)
581 #define IWL_MAX_PLCP_ERR_EXT_LONG_THRESHOLD_DEF	(200)
582 #define IWL_MAX_PLCP_ERR_THRESHOLD_MAX	(255)
583 #define IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE	(0)
584 
585 #define IWL_DELAY_NEXT_FORCE_RF_RESET  (HZ*3)
586 #define IWL_DELAY_NEXT_FORCE_FW_RELOAD (HZ*5)
587 
588 /* TX queue watchdog timeouts in mSecs */
589 #define IWL_DEF_WD_TIMEOUT	(2000)
590 #define IWL_LONG_WD_TIMEOUT	(10000)
591 #define IWL_MAX_WD_TIMEOUT	(120000)
592 
593 /* BT Antenna Coupling Threshold (dB) */
594 #define IWL_BT_ANTENNA_COUPLING_THRESHOLD	(35)
595 
596 /* Firmware reload counter and Timestamp */
597 #define IWL_MIN_RELOAD_DURATION		1000 /* 1000 ms */
598 #define IWL_MAX_CONTINUE_RELOAD_CNT	4
599 
600 
601 enum iwl_reset {
602 	IWL_RF_RESET = 0,
603 	IWL_FW_RESET,
604 	IWL_MAX_FORCE_RESET,
605 };
606 
607 struct iwl_force_reset {
608 	int reset_request_count;
609 	int reset_success_count;
610 	int reset_reject_count;
611 	unsigned long reset_duration;
612 	unsigned long last_force_reset_jiffies;
613 };
614 
615 /* extend beacon time format bit shifting  */
616 /*
617  * for _agn devices
618  * bits 31:22 - extended
619  * bits 21:0  - interval
620  */
621 #define IWLAGN_EXT_BEACON_TIME_POS	22
622 
623 struct iwl_rxon_context {
624 	struct ieee80211_vif *vif;
625 
626 	/*
627 	 * We could use the vif to indicate active, but we
628 	 * also need it to be active during disabling when
629 	 * we already removed the vif for type setting.
630 	 */
631 	bool always_active, is_active;
632 
633 	bool ht_need_multiple_chains;
634 
635 	enum iwl_rxon_context_id ctxid;
636 
637 	u32 interface_modes, exclusive_interface_modes;
638 	u8 unused_devtype, ap_devtype, ibss_devtype, station_devtype;
639 
640 	/*
641 	 * We declare this const so it can only be
642 	 * changed via explicit cast within the
643 	 * routines that actually update the physical
644 	 * hardware.
645 	 */
646 	const struct iwl_rxon_cmd active;
647 	struct iwl_rxon_cmd staging;
648 
649 	struct iwl_rxon_time_cmd timing;
650 
651 	struct iwl_qos_info qos_data;
652 
653 	u8 bcast_sta_id, ap_sta_id;
654 
655 	u8 rxon_cmd, rxon_assoc_cmd, rxon_timing_cmd;
656 	u8 qos_cmd;
657 	u8 wep_key_cmd;
658 
659 	struct iwl_wep_key wep_keys[WEP_KEYS_MAX];
660 	u8 key_mapping_keys;
661 
662 	__le32 station_flags;
663 
664 	int beacon_int;
665 
666 	struct {
667 		bool non_gf_sta_present;
668 		u8 protection;
669 		bool enabled, is_40mhz;
670 		u8 extension_chan_offset;
671 	} ht;
672 };
673 
674 enum iwl_scan_type {
675 	IWL_SCAN_NORMAL,
676 	IWL_SCAN_RADIO_RESET,
677 	IWL_SCAN_ROC,
678 };
679 
680 #ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
681 struct iwl_testmode_trace {
682 	u32 buff_size;
683 	u32 total_size;
684 	u32 num_chunks;
685 	u8 *cpu_addr;
686 	u8 *trace_addr;
687 	dma_addr_t dma_addr;
688 	bool trace_enabled;
689 };
690 struct iwl_testmode_mem {
691 	u32 buff_size;
692 	u32 num_chunks;
693 	u8 *buff_addr;
694 	bool read_in_progress;
695 };
696 #endif
697 
698 struct iwl_wipan_noa_data {
699 	struct rcu_head rcu_head;
700 	u32 length;
701 	u8 data[];
702 };
703 
704 #define IWL_OP_MODE_GET_DVM(_iwl_op_mode) \
705 	((struct iwl_priv *) ((_iwl_op_mode)->op_mode_specific))
706 
707 #define IWL_MAC80211_GET_DVM(_hw) \
708 	((struct iwl_priv *) ((struct iwl_op_mode *) \
709 	(_hw)->priv)->op_mode_specific)
710 
711 struct iwl_priv {
712 
713 	/*data shared among all the driver's layers */
714 	struct iwl_shared *shrd;
715 	const struct iwl_fw *fw;
716 	unsigned long status;
717 
718 	spinlock_t sta_lock;
719 	struct mutex mutex;
720 
721 	unsigned long transport_queue_stop;
722 	bool passive_no_rx;
723 
724 	/* ieee device used by generic ieee processing code */
725 	struct ieee80211_hw *hw;
726 	struct ieee80211_channel *ieee_channels;
727 	struct ieee80211_rate *ieee_rates;
728 
729 	struct list_head calib_results;
730 
731 	struct workqueue_struct *workqueue;
732 
733 	enum ieee80211_band band;
734 
735 	void (*pre_rx_handler)(struct iwl_priv *priv,
736 			       struct iwl_rx_cmd_buffer *rxb);
737 	int (*rx_handlers[REPLY_MAX])(struct iwl_priv *priv,
738 				       struct iwl_rx_cmd_buffer *rxb,
739 				       struct iwl_device_cmd *cmd);
740 
741 	struct iwl_notif_wait_data notif_wait;
742 
743 	struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
744 
745 	/* spectrum measurement report caching */
746 	struct iwl_spectrum_notification measure_report;
747 	u8 measurement_status;
748 
749 #define IWL_OWNERSHIP_DRIVER	0
750 #define IWL_OWNERSHIP_TM	1
751 	u8 ucode_owner;
752 
753 	/* ucode beacon time */
754 	u32 ucode_beacon_time;
755 	int missed_beacon_threshold;
756 
757 	/* track IBSS manager (last beacon) status */
758 	u32 ibss_manager;
759 
760 	/* jiffies when last recovery from statistics was performed */
761 	unsigned long rx_statistics_jiffies;
762 
763 	/*counters */
764 	u32 rx_handlers_stats[REPLY_MAX];
765 
766 	/* force reset */
767 	struct iwl_force_reset force_reset[IWL_MAX_FORCE_RESET];
768 
769 	/* firmware reload counter and timestamp */
770 	unsigned long reload_jiffies;
771 	int reload_count;
772 	bool ucode_loaded;
773 	bool init_ucode_run;		/* Don't run init uCode again */
774 
775 	/* we allocate array of iwl_channel_info for NIC's valid channels.
776 	 *    Access via channel # using indirect index array */
777 	struct iwl_channel_info *channel_info;	/* channel info array */
778 	u8 channel_count;	/* # of channels */
779 
780 	u8 plcp_delta_threshold;
781 
782 	/* thermal calibration */
783 	s32 temperature;	/* Celsius */
784 	s32 last_temperature;
785 
786 	struct iwl_wipan_noa_data __rcu *noa_data;
787 
788 	/* Scan related variables */
789 	unsigned long scan_start;
790 	unsigned long scan_start_tsf;
791 	void *scan_cmd;
792 	enum ieee80211_band scan_band;
793 	struct cfg80211_scan_request *scan_request;
794 	struct ieee80211_vif *scan_vif;
795 	enum iwl_scan_type scan_type;
796 	u8 scan_tx_ant[IEEE80211_NUM_BANDS];
797 	u8 mgmt_tx_ant;
798 
799 	/* max number of station keys */
800 	u8 sta_key_max_num;
801 
802 	bool new_scan_threshold_behaviour;
803 
804 	bool wowlan;
805 
806 	/* EEPROM MAC addresses */
807 	struct mac_address addresses[2];
808 
809 	struct iwl_rxon_context contexts[NUM_IWL_RXON_CTX];
810 
811 	__le16 switch_channel;
812 
813 	u16 active_rate;
814 
815 	u8 start_calib;
816 	struct iwl_sensitivity_data sensitivity_data;
817 	struct iwl_chain_noise_data chain_noise_data;
818 	__le16 sensitivity_tbl[HD_TABLE_SIZE];
819 	__le16 enhance_sensitivity_tbl[ENHANCE_HD_TABLE_ENTRIES];
820 
821 	struct iwl_ht_config current_ht_config;
822 
823 	/* Rate scaling data */
824 	u8 retry_rate;
825 
826 	int activity_timer_active;
827 
828 	/* counts mgmt, ctl, and data packets */
829 	struct traffic_stats tx_stats;
830 	struct traffic_stats rx_stats;
831 
832 	struct iwl_power_mgr power_data;
833 	struct iwl_tt_mgmt thermal_throttle;
834 
835 	/* station table variables */
836 	int num_stations;
837 	struct iwl_station_entry stations[IWLAGN_STATION_COUNT];
838 	unsigned long ucode_key_table;
839 	struct iwl_tid_data tid_data[IWLAGN_STATION_COUNT][IWL_MAX_TID_COUNT];
840 
841 	u8 mac80211_registered;
842 
843 	/* Indication if ieee80211_ops->open has been called */
844 	u8 is_open;
845 
846 	enum nl80211_iftype iw_mode;
847 
848 	/* Last Rx'd beacon timestamp */
849 	u64 timestamp;
850 
851 	struct {
852 		__le32 flag;
853 		struct statistics_general_common common;
854 		struct statistics_rx_non_phy rx_non_phy;
855 		struct statistics_rx_phy rx_ofdm;
856 		struct statistics_rx_ht_phy rx_ofdm_ht;
857 		struct statistics_rx_phy rx_cck;
858 		struct statistics_tx tx;
859 #ifdef CONFIG_IWLWIFI_DEBUGFS
860 		struct statistics_bt_activity bt_activity;
861 		__le32 num_bt_kills, accum_num_bt_kills;
862 #endif
863 		spinlock_t lock;
864 	} statistics;
865 #ifdef CONFIG_IWLWIFI_DEBUGFS
866 	struct {
867 		struct statistics_general_common common;
868 		struct statistics_rx_non_phy rx_non_phy;
869 		struct statistics_rx_phy rx_ofdm;
870 		struct statistics_rx_ht_phy rx_ofdm_ht;
871 		struct statistics_rx_phy rx_cck;
872 		struct statistics_tx tx;
873 		struct statistics_bt_activity bt_activity;
874 	} accum_stats, delta_stats, max_delta_stats;
875 #endif
876 
877 	/*
878 	 * reporting the number of tids has AGG on. 0 means
879 	 * no AGGREGATION
880 	 */
881 	u8 agg_tids_count;
882 
883 	struct iwl_rx_phy_res last_phy_res;
884 	bool last_phy_res_valid;
885 
886 	/*
887 	 * chain noise reset and gain commands are the
888 	 * two extra calibration commands follows the standard
889 	 * phy calibration commands
890 	 */
891 	u8 phy_calib_chain_noise_reset_cmd;
892 	u8 phy_calib_chain_noise_gain_cmd;
893 
894 	/* counts reply_tx error */
895 	struct reply_tx_error_statistics reply_tx_stats;
896 	struct reply_agg_tx_error_statistics reply_agg_tx_stats;
897 
898 	/* remain-on-channel offload support */
899 	struct ieee80211_channel *hw_roc_channel;
900 	struct delayed_work hw_roc_disable_work;
901 	enum nl80211_channel_type hw_roc_chantype;
902 	int hw_roc_duration;
903 	bool hw_roc_setup, hw_roc_start_notified;
904 
905 	/* bt coex */
906 	u8 bt_enable_flag;
907 	u8 bt_status;
908 	u8 bt_traffic_load, last_bt_traffic_load;
909 	bool bt_ch_announce;
910 	bool bt_full_concurrent;
911 	bool bt_ant_couple_ok;
912 	__le32 kill_ack_mask;
913 	__le32 kill_cts_mask;
914 	__le16 bt_valid;
915 	u16 bt_on_thresh;
916 	u16 bt_duration;
917 	u16 dynamic_frag_thresh;
918 	u8 bt_ci_compliance;
919 	struct work_struct bt_traffic_change_work;
920 	bool bt_enable_pspoll;
921 	struct iwl_rxon_context *cur_rssi_ctx;
922 	bool bt_is_sco;
923 
924 	struct work_struct restart;
925 	struct work_struct scan_completed;
926 	struct work_struct abort_scan;
927 
928 	struct work_struct beacon_update;
929 	struct iwl_rxon_context *beacon_ctx;
930 	struct sk_buff *beacon_skb;
931 	void *beacon_cmd;
932 
933 	struct work_struct tt_work;
934 	struct work_struct ct_enter;
935 	struct work_struct ct_exit;
936 	struct work_struct start_internal_scan;
937 	struct work_struct tx_flush;
938 	struct work_struct bt_full_concurrency;
939 	struct work_struct bt_runtime_config;
940 
941 	struct delayed_work scan_check;
942 
943 	/* TX Power */
944 	s8 tx_power_user_lmt;
945 	s8 tx_power_device_lmt;
946 	s8 tx_power_lmt_in_half_dbm; /* max tx power in half-dBm format */
947 	s8 tx_power_next;
948 
949 #ifdef CONFIG_IWLWIFI_DEBUGFS
950 	/* debugfs */
951 	u16 tx_traffic_idx;
952 	u16 rx_traffic_idx;
953 	u8 *tx_traffic;
954 	u8 *rx_traffic;
955 	struct dentry *debugfs_dir;
956 	u32 dbgfs_sram_offset, dbgfs_sram_len;
957 	bool disable_ht40;
958 	void *wowlan_sram;
959 #endif /* CONFIG_IWLWIFI_DEBUGFS */
960 
961 	struct work_struct txpower_work;
962 	u32 disable_sens_cal;
963 	u32 disable_chain_noise_cal;
964 	struct work_struct run_time_calib_work;
965 	struct timer_list statistics_periodic;
966 	struct timer_list ucode_trace;
967 	struct timer_list watchdog;
968 
969 	struct iwl_event_log event_log;
970 
971 	struct led_classdev led;
972 	unsigned long blink_on, blink_off;
973 	bool led_registered;
974 #ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
975 	struct iwl_testmode_trace testmode_trace;
976 	struct iwl_testmode_mem testmode_mem;
977 	u32 tm_fixed_rate;
978 #endif
979 
980 	/* WoWLAN GTK rekey data */
981 	u8 kck[NL80211_KCK_LEN], kek[NL80211_KEK_LEN];
982 	__le64 replay_ctr;
983 	__le16 last_seq_ctl;
984 	bool have_rekey_data;
985 }; /*iwl_priv */
986 
987 extern struct kmem_cache *iwl_tx_cmd_pool;
988 extern struct iwl_mod_params iwlagn_mod_params;
989 
990 static inline struct iwl_rxon_context *
iwl_rxon_ctx_from_vif(struct ieee80211_vif * vif)991 iwl_rxon_ctx_from_vif(struct ieee80211_vif *vif)
992 {
993 	struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
994 
995 	return vif_priv->ctx;
996 }
997 
998 #define for_each_context(priv, ctx)				\
999 	for (ctx = &priv->contexts[IWL_RXON_CTX_BSS];		\
1000 	     ctx < &priv->contexts[NUM_IWL_RXON_CTX]; ctx++)	\
1001 		if (priv->shrd->valid_contexts & BIT(ctx->ctxid))
1002 
iwl_is_associated_ctx(struct iwl_rxon_context * ctx)1003 static inline int iwl_is_associated_ctx(struct iwl_rxon_context *ctx)
1004 {
1005 	return (ctx->active.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0;
1006 }
1007 
iwl_is_associated(struct iwl_priv * priv,enum iwl_rxon_context_id ctxid)1008 static inline int iwl_is_associated(struct iwl_priv *priv,
1009 				    enum iwl_rxon_context_id ctxid)
1010 {
1011 	return iwl_is_associated_ctx(&priv->contexts[ctxid]);
1012 }
1013 
iwl_is_any_associated(struct iwl_priv * priv)1014 static inline int iwl_is_any_associated(struct iwl_priv *priv)
1015 {
1016 	struct iwl_rxon_context *ctx;
1017 	for_each_context(priv, ctx)
1018 		if (iwl_is_associated_ctx(ctx))
1019 			return true;
1020 	return false;
1021 }
1022 
is_channel_valid(const struct iwl_channel_info * ch_info)1023 static inline int is_channel_valid(const struct iwl_channel_info *ch_info)
1024 {
1025 	if (ch_info == NULL)
1026 		return 0;
1027 	return (ch_info->flags & EEPROM_CHANNEL_VALID) ? 1 : 0;
1028 }
1029 
is_channel_radar(const struct iwl_channel_info * ch_info)1030 static inline int is_channel_radar(const struct iwl_channel_info *ch_info)
1031 {
1032 	return (ch_info->flags & EEPROM_CHANNEL_RADAR) ? 1 : 0;
1033 }
1034 
is_channel_a_band(const struct iwl_channel_info * ch_info)1035 static inline u8 is_channel_a_band(const struct iwl_channel_info *ch_info)
1036 {
1037 	return ch_info->band == IEEE80211_BAND_5GHZ;
1038 }
1039 
is_channel_bg_band(const struct iwl_channel_info * ch_info)1040 static inline u8 is_channel_bg_band(const struct iwl_channel_info *ch_info)
1041 {
1042 	return ch_info->band == IEEE80211_BAND_2GHZ;
1043 }
1044 
is_channel_passive(const struct iwl_channel_info * ch)1045 static inline int is_channel_passive(const struct iwl_channel_info *ch)
1046 {
1047 	return (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) ? 1 : 0;
1048 }
1049 
is_channel_ibss(const struct iwl_channel_info * ch)1050 static inline int is_channel_ibss(const struct iwl_channel_info *ch)
1051 {
1052 	return ((ch->flags & EEPROM_CHANNEL_IBSS)) ? 1 : 0;
1053 }
1054 
1055 #endif				/* __iwl_dev_h__ */
1056