1 /******************************************************************************
2  *
3  * Copyright(c) 2003 - 2011 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  * Please use iwl-4965-hw.h for hardware-related definitions.
30  */
31 
32 #ifndef __iwl_legacy_dev_h__
33 #define __iwl_legacy_dev_h__
34 
35 #include <linux/pci.h> /* for struct pci_device_id */
36 #include <linux/kernel.h>
37 #include <linux/leds.h>
38 #include <linux/wait.h>
39 #include <net/ieee80211_radiotap.h>
40 
41 #include "iwl-eeprom.h"
42 #include "iwl-csr.h"
43 #include "iwl-prph.h"
44 #include "iwl-fh.h"
45 #include "iwl-debug.h"
46 #include "iwl-4965-hw.h"
47 #include "iwl-3945-hw.h"
48 #include "iwl-led.h"
49 #include "iwl-power.h"
50 #include "iwl-legacy-rs.h"
51 
52 struct iwl_tx_queue;
53 
54 /* CT-KILL constants */
55 #define CT_KILL_THRESHOLD_LEGACY   110 /* in Celsius */
56 
57 /* Default noise level to report when noise measurement is not available.
58  *   This may be because we're:
59  *   1)  Not associated (4965, no beacon statistics being sent to driver)
60  *   2)  Scanning (noise measurement does not apply to associated channel)
61  *   3)  Receiving CCK (3945 delivers noise info only for OFDM frames)
62  * Use default noise value of -127 ... this is below the range of measurable
63  *   Rx dBm for either 3945 or 4965, so it can indicate "unmeasurable" to user.
64  *   Also, -127 works better than 0 when averaging frames with/without
65  *   noise info (e.g. averaging might be done in app); measured dBm values are
66  *   always negative ... using a negative value as the default keeps all
67  *   averages within an s8's (used in some apps) range of negative values. */
68 #define IWL_NOISE_MEAS_NOT_AVAILABLE (-127)
69 
70 /*
71  * RTS threshold here is total size [2347] minus 4 FCS bytes
72  * Per spec:
73  *   a value of 0 means RTS on all data/management packets
74  *   a value > max MSDU size means no RTS
75  * else RTS for data/management frames where MPDU is larger
76  *   than RTS value.
77  */
78 #define DEFAULT_RTS_THRESHOLD     2347U
79 #define MIN_RTS_THRESHOLD         0U
80 #define MAX_RTS_THRESHOLD         2347U
81 #define MAX_MSDU_SIZE		  2304U
82 #define MAX_MPDU_SIZE		  2346U
83 #define DEFAULT_BEACON_INTERVAL   100U
84 #define	DEFAULT_SHORT_RETRY_LIMIT 7U
85 #define	DEFAULT_LONG_RETRY_LIMIT  4U
86 
87 struct iwl_rx_mem_buffer {
88 	dma_addr_t page_dma;
89 	struct page *page;
90 	struct list_head list;
91 };
92 
93 #define rxb_addr(r) page_address(r->page)
94 
95 /* defined below */
96 struct iwl_device_cmd;
97 
98 struct iwl_cmd_meta {
99 	/* only for SYNC commands, iff the reply skb is wanted */
100 	struct iwl_host_cmd *source;
101 	/*
102 	 * only for ASYNC commands
103 	 * (which is somewhat stupid -- look at iwl-sta.c for instance
104 	 * which duplicates a bunch of code because the callback isn't
105 	 * invoked for SYNC commands, if it were and its result passed
106 	 * through it would be simpler...)
107 	 */
108 	void (*callback)(struct iwl_priv *priv,
109 			 struct iwl_device_cmd *cmd,
110 			 struct iwl_rx_packet *pkt);
111 
112 	/* The CMD_SIZE_HUGE flag bit indicates that the command
113 	 * structure is stored at the end of the shared queue memory. */
114 	u32 flags;
115 
116 	DEFINE_DMA_UNMAP_ADDR(mapping);
117 	DEFINE_DMA_UNMAP_LEN(len);
118 };
119 
120 /*
121  * Generic queue structure
122  *
123  * Contains common data for Rx and Tx queues
124  */
125 struct iwl_queue {
126 	int n_bd;              /* number of BDs in this queue */
127 	int write_ptr;       /* 1-st empty entry (index) host_w*/
128 	int read_ptr;         /* last used entry (index) host_r*/
129 	/* use for monitoring and recovering the stuck queue */
130 	dma_addr_t dma_addr;   /* physical addr for BD's */
131 	int n_window;	       /* safe queue window */
132 	u32 id;
133 	int low_mark;	       /* low watermark, resume queue if free
134 				* space more than this */
135 	int high_mark;         /* high watermark, stop queue if free
136 				* space less than this */
137 } __packed;
138 
139 /* One for each TFD */
140 struct iwl_tx_info {
141 	struct sk_buff *skb;
142 	struct iwl_rxon_context *ctx;
143 };
144 
145 /**
146  * struct iwl_tx_queue - Tx Queue for DMA
147  * @q: generic Rx/Tx queue descriptor
148  * @bd: base of circular buffer of TFDs
149  * @cmd: array of command/TX buffer pointers
150  * @meta: array of meta data for each command/tx buffer
151  * @dma_addr_cmd: physical address of cmd/tx buffer array
152  * @txb: array of per-TFD driver data
153  * @time_stamp: time (in jiffies) of last read_ptr change
154  * @need_update: indicates need to update read/write index
155  * @sched_retry: indicates queue is high-throughput aggregation (HT AGG) enabled
156  *
157  * A Tx queue consists of circular buffer of BDs (a.k.a. TFDs, transmit frame
158  * descriptors) and required locking structures.
159  */
160 #define TFD_TX_CMD_SLOTS 256
161 #define TFD_CMD_SLOTS 32
162 
163 struct iwl_tx_queue {
164 	struct iwl_queue q;
165 	void *tfds;
166 	struct iwl_device_cmd **cmd;
167 	struct iwl_cmd_meta *meta;
168 	struct iwl_tx_info *txb;
169 	unsigned long time_stamp;
170 	u8 need_update;
171 	u8 sched_retry;
172 	u8 active;
173 	u8 swq_id;
174 };
175 
176 #define IWL_NUM_SCAN_RATES         (2)
177 
178 struct iwl4965_channel_tgd_info {
179 	u8 type;
180 	s8 max_power;
181 };
182 
183 struct iwl4965_channel_tgh_info {
184 	s64 last_radar_time;
185 };
186 
187 #define IWL4965_MAX_RATE (33)
188 
189 struct iwl3945_clip_group {
190 	/* maximum power level to prevent clipping for each rate, derived by
191 	 *   us from this band's saturation power in EEPROM */
192 	const s8 clip_powers[IWL_MAX_RATES];
193 };
194 
195 /* current Tx power values to use, one for each rate for each channel.
196  * requested power is limited by:
197  * -- regulatory EEPROM limits for this channel
198  * -- hardware capabilities (clip-powers)
199  * -- spectrum management
200  * -- user preference (e.g. iwconfig)
201  * when requested power is set, base power index must also be set. */
202 struct iwl3945_channel_power_info {
203 	struct iwl3945_tx_power tpc;	/* actual radio and DSP gain settings */
204 	s8 power_table_index;	/* actual (compenst'd) index into gain table */
205 	s8 base_power_index;	/* gain index for power at factory temp. */
206 	s8 requested_power;	/* power (dBm) requested for this chnl/rate */
207 };
208 
209 /* current scan Tx power values to use, one for each scan rate for each
210  * channel. */
211 struct iwl3945_scan_power_info {
212 	struct iwl3945_tx_power tpc;	/* actual radio and DSP gain settings */
213 	s8 power_table_index;	/* actual (compenst'd) index into gain table */
214 	s8 requested_power;	/* scan pwr (dBm) requested for chnl/rate */
215 };
216 
217 /*
218  * One for each channel, holds all channel setup data
219  * Some of the fields (e.g. eeprom and flags/max_power_avg) are redundant
220  *     with one another!
221  */
222 struct iwl_channel_info {
223 	struct iwl4965_channel_tgd_info tgd;
224 	struct iwl4965_channel_tgh_info tgh;
225 	struct iwl_eeprom_channel eeprom;	/* EEPROM regulatory limit */
226 	struct iwl_eeprom_channel ht40_eeprom;	/* EEPROM regulatory limit for
227 						 * HT40 channel */
228 
229 	u8 channel;	  /* channel number */
230 	u8 flags;	  /* flags copied from EEPROM */
231 	s8 max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */
232 	s8 curr_txpow;	  /* (dBm) regulatory/spectrum/user (not h/w) limit */
233 	s8 min_power;	  /* always 0 */
234 	s8 scan_power;	  /* (dBm) regul. eeprom, direct scans, any rate */
235 
236 	u8 group_index;	  /* 0-4, maps channel to group1/2/3/4/5 */
237 	u8 band_index;	  /* 0-4, maps channel to band1/2/3/4/5 */
238 	enum ieee80211_band band;
239 
240 	/* HT40 channel info */
241 	s8 ht40_max_power_avg;	/* (dBm) regul. eeprom, normal Tx, any rate */
242 	u8 ht40_flags;		/* flags copied from EEPROM */
243 	u8 ht40_extension_channel; /* HT_IE_EXT_CHANNEL_* */
244 
245 	/* Radio/DSP gain settings for each "normal" data Tx rate.
246 	 * These include, in addition to RF and DSP gain, a few fields for
247 	 *   remembering/modifying gain settings (indexes). */
248 	struct iwl3945_channel_power_info power_info[IWL4965_MAX_RATE];
249 
250 	/* Radio/DSP gain settings for each scan rate, for directed scans. */
251 	struct iwl3945_scan_power_info scan_pwr_info[IWL_NUM_SCAN_RATES];
252 };
253 
254 #define IWL_TX_FIFO_BK		0	/* shared */
255 #define IWL_TX_FIFO_BE		1
256 #define IWL_TX_FIFO_VI		2	/* shared */
257 #define IWL_TX_FIFO_VO		3
258 #define IWL_TX_FIFO_UNUSED	-1
259 
260 /* Minimum number of queues. MAX_NUM is defined in hw specific files.
261  * Set the minimum to accommodate the 4 standard TX queues, 1 command
262  * queue, 2 (unused) HCCA queues, and 4 HT queues (one for each AC) */
263 #define IWL_MIN_NUM_QUEUES	10
264 
265 #define IWL_DEFAULT_CMD_QUEUE_NUM	4
266 
267 #define IEEE80211_DATA_LEN              2304
268 #define IEEE80211_4ADDR_LEN             30
269 #define IEEE80211_HLEN                  (IEEE80211_4ADDR_LEN)
270 #define IEEE80211_FRAME_LEN             (IEEE80211_DATA_LEN + IEEE80211_HLEN)
271 
272 struct iwl_frame {
273 	union {
274 		struct ieee80211_hdr frame;
275 		struct iwl_tx_beacon_cmd beacon;
276 		u8 raw[IEEE80211_FRAME_LEN];
277 		u8 cmd[360];
278 	} u;
279 	struct list_head list;
280 };
281 
282 #define SEQ_TO_SN(seq) (((seq) & IEEE80211_SCTL_SEQ) >> 4)
283 #define SN_TO_SEQ(ssn) (((ssn) << 4) & IEEE80211_SCTL_SEQ)
284 #define MAX_SN ((IEEE80211_SCTL_SEQ) >> 4)
285 
286 enum {
287 	CMD_SYNC = 0,
288 	CMD_SIZE_NORMAL = 0,
289 	CMD_NO_SKB = 0,
290 	CMD_SIZE_HUGE = (1 << 0),
291 	CMD_ASYNC = (1 << 1),
292 	CMD_WANT_SKB = (1 << 2),
293 };
294 
295 #define DEF_CMD_PAYLOAD_SIZE 320
296 
297 /**
298  * struct iwl_device_cmd
299  *
300  * For allocation of the command and tx queues, this establishes the overall
301  * size of the largest command we send to uCode, except for a scan command
302  * (which is relatively huge; space is allocated separately).
303  */
304 struct iwl_device_cmd {
305 	struct iwl_cmd_header hdr;	/* uCode API */
306 	union {
307 		u32 flags;
308 		u8 val8;
309 		u16 val16;
310 		u32 val32;
311 		struct iwl_tx_cmd tx;
312 		u8 payload[DEF_CMD_PAYLOAD_SIZE];
313 	} __packed cmd;
314 } __packed;
315 
316 #define TFD_MAX_PAYLOAD_SIZE (sizeof(struct iwl_device_cmd))
317 
318 
319 struct iwl_host_cmd {
320 	const void *data;
321 	unsigned long reply_page;
322 	void (*callback)(struct iwl_priv *priv,
323 			 struct iwl_device_cmd *cmd,
324 			 struct iwl_rx_packet *pkt);
325 	u32 flags;
326 	u16 len;
327 	u8 id;
328 };
329 
330 #define SUP_RATE_11A_MAX_NUM_CHANNELS  8
331 #define SUP_RATE_11B_MAX_NUM_CHANNELS  4
332 #define SUP_RATE_11G_MAX_NUM_CHANNELS  12
333 
334 /**
335  * struct iwl_rx_queue - Rx queue
336  * @bd: driver's pointer to buffer of receive buffer descriptors (rbd)
337  * @bd_dma: bus address of buffer of receive buffer descriptors (rbd)
338  * @read: Shared index to newest available Rx buffer
339  * @write: Shared index to oldest written Rx packet
340  * @free_count: Number of pre-allocated buffers in rx_free
341  * @rx_free: list of free SKBs for use
342  * @rx_used: List of Rx buffers with no SKB
343  * @need_update: flag to indicate we need to update read/write index
344  * @rb_stts: driver's pointer to receive buffer status
345  * @rb_stts_dma: bus address of receive buffer status
346  *
347  * NOTE:  rx_free and rx_used are used as a FIFO for iwl_rx_mem_buffers
348  */
349 struct iwl_rx_queue {
350 	__le32 *bd;
351 	dma_addr_t bd_dma;
352 	struct iwl_rx_mem_buffer pool[RX_QUEUE_SIZE + RX_FREE_BUFFERS];
353 	struct iwl_rx_mem_buffer *queue[RX_QUEUE_SIZE];
354 	u32 read;
355 	u32 write;
356 	u32 free_count;
357 	u32 write_actual;
358 	struct list_head rx_free;
359 	struct list_head rx_used;
360 	int need_update;
361 	struct iwl_rb_status *rb_stts;
362 	dma_addr_t rb_stts_dma;
363 	spinlock_t lock;
364 };
365 
366 #define IWL_SUPPORTED_RATES_IE_LEN         8
367 
368 #define MAX_TID_COUNT        9
369 
370 #define IWL_INVALID_RATE     0xFF
371 #define IWL_INVALID_VALUE    -1
372 
373 /**
374  * struct iwl_ht_agg -- aggregation status while waiting for block-ack
375  * @txq_id: Tx queue used for Tx attempt
376  * @frame_count: # frames attempted by Tx command
377  * @wait_for_ba: Expect block-ack before next Tx reply
378  * @start_idx: Index of 1st Transmit Frame Descriptor (TFD) in Tx window
379  * @bitmap0: Low order bitmap, one bit for each frame pending ACK in Tx window
380  * @bitmap1: High order, one bit for each frame pending ACK in Tx window
381  * @rate_n_flags: Rate at which Tx was attempted
382  *
383  * If REPLY_TX indicates that aggregation was attempted, driver must wait
384  * for block ack (REPLY_COMPRESSED_BA).  This struct stores tx reply info
385  * until block ack arrives.
386  */
387 struct iwl_ht_agg {
388 	u16 txq_id;
389 	u16 frame_count;
390 	u16 wait_for_ba;
391 	u16 start_idx;
392 	u64 bitmap;
393 	u32 rate_n_flags;
394 #define IWL_AGG_OFF 0
395 #define IWL_AGG_ON 1
396 #define IWL_EMPTYING_HW_QUEUE_ADDBA 2
397 #define IWL_EMPTYING_HW_QUEUE_DELBA 3
398 	u8 state;
399 };
400 
401 
402 struct iwl_tid_data {
403 	u16 seq_number; /* 4965 only */
404 	u16 tfds_in_queue;
405 	struct iwl_ht_agg agg;
406 };
407 
408 struct iwl_hw_key {
409 	u32 cipher;
410 	int keylen;
411 	u8 keyidx;
412 	u8 key[32];
413 };
414 
415 union iwl_ht_rate_supp {
416 	u16 rates;
417 	struct {
418 		u8 siso_rate;
419 		u8 mimo_rate;
420 	};
421 };
422 
423 #define CFG_HT_RX_AMPDU_FACTOR_8K   (0x0)
424 #define CFG_HT_RX_AMPDU_FACTOR_16K  (0x1)
425 #define CFG_HT_RX_AMPDU_FACTOR_32K  (0x2)
426 #define CFG_HT_RX_AMPDU_FACTOR_64K  (0x3)
427 #define CFG_HT_RX_AMPDU_FACTOR_DEF  CFG_HT_RX_AMPDU_FACTOR_64K
428 #define CFG_HT_RX_AMPDU_FACTOR_MAX  CFG_HT_RX_AMPDU_FACTOR_64K
429 #define CFG_HT_RX_AMPDU_FACTOR_MIN  CFG_HT_RX_AMPDU_FACTOR_8K
430 
431 /*
432  * Maximal MPDU density for TX aggregation
433  * 4 - 2us density
434  * 5 - 4us density
435  * 6 - 8us density
436  * 7 - 16us density
437  */
438 #define CFG_HT_MPDU_DENSITY_2USEC   (0x4)
439 #define CFG_HT_MPDU_DENSITY_4USEC   (0x5)
440 #define CFG_HT_MPDU_DENSITY_8USEC   (0x6)
441 #define CFG_HT_MPDU_DENSITY_16USEC  (0x7)
442 #define CFG_HT_MPDU_DENSITY_DEF CFG_HT_MPDU_DENSITY_4USEC
443 #define CFG_HT_MPDU_DENSITY_MAX CFG_HT_MPDU_DENSITY_16USEC
444 #define CFG_HT_MPDU_DENSITY_MIN     (0x1)
445 
446 struct iwl_ht_config {
447 	bool single_chain_sufficient;
448 	enum ieee80211_smps_mode smps; /* current smps mode */
449 };
450 
451 /* QoS structures */
452 struct iwl_qos_info {
453 	int qos_active;
454 	struct iwl_qosparam_cmd def_qos_parm;
455 };
456 
457 /*
458  * Structure should be accessed with sta_lock held. When station addition
459  * is in progress (IWL_STA_UCODE_INPROGRESS) it is possible to access only
460  * the commands (iwl_legacy_addsta_cmd and iwl_link_quality_cmd) without
461  * sta_lock held.
462  */
463 struct iwl_station_entry {
464 	struct iwl_legacy_addsta_cmd sta;
465 	struct iwl_tid_data tid[MAX_TID_COUNT];
466 	u8 used, ctxid;
467 	struct iwl_hw_key keyinfo;
468 	struct iwl_link_quality_cmd *lq;
469 };
470 
471 struct iwl_station_priv_common {
472 	struct iwl_rxon_context *ctx;
473 	u8 sta_id;
474 };
475 
476 /*
477  * iwl_station_priv: Driver's private station information
478  *
479  * When mac80211 creates a station it reserves some space (hw->sta_data_size)
480  * in the structure for use by driver. This structure is places in that
481  * space.
482  *
483  * The common struct MUST be first because it is shared between
484  * 3945 and 4965!
485  */
486 struct iwl_station_priv {
487 	struct iwl_station_priv_common common;
488 	struct iwl_lq_sta lq_sta;
489 	atomic_t pending_frames;
490 	bool client;
491 	bool asleep;
492 };
493 
494 /**
495  * struct iwl_vif_priv - driver's private per-interface information
496  *
497  * When mac80211 allocates a virtual interface, it can allocate
498  * space for us to put data into.
499  */
500 struct iwl_vif_priv {
501 	struct iwl_rxon_context *ctx;
502 	u8 ibss_bssid_sta_id;
503 };
504 
505 /* one for each uCode image (inst/data, boot/init/runtime) */
506 struct fw_desc {
507 	void *v_addr;		/* access by driver */
508 	dma_addr_t p_addr;	/* access by card's busmaster DMA */
509 	u32 len;		/* bytes */
510 };
511 
512 /* uCode file layout */
513 struct iwl_ucode_header {
514 	__le32 ver;	/* major/minor/API/serial */
515 	struct {
516 		__le32 inst_size;	/* bytes of runtime code */
517 		__le32 data_size;	/* bytes of runtime data */
518 		__le32 init_size;	/* bytes of init code */
519 		__le32 init_data_size;	/* bytes of init data */
520 		__le32 boot_size;	/* bytes of bootstrap code */
521 		u8 data[0];		/* in same order as sizes */
522 	} v1;
523 };
524 
525 struct iwl4965_ibss_seq {
526 	u8 mac[ETH_ALEN];
527 	u16 seq_num;
528 	u16 frag_num;
529 	unsigned long packet_time;
530 	struct list_head list;
531 };
532 
533 struct iwl_sensitivity_ranges {
534 	u16 min_nrg_cck;
535 	u16 max_nrg_cck;
536 
537 	u16 nrg_th_cck;
538 	u16 nrg_th_ofdm;
539 
540 	u16 auto_corr_min_ofdm;
541 	u16 auto_corr_min_ofdm_mrc;
542 	u16 auto_corr_min_ofdm_x1;
543 	u16 auto_corr_min_ofdm_mrc_x1;
544 
545 	u16 auto_corr_max_ofdm;
546 	u16 auto_corr_max_ofdm_mrc;
547 	u16 auto_corr_max_ofdm_x1;
548 	u16 auto_corr_max_ofdm_mrc_x1;
549 
550 	u16 auto_corr_max_cck;
551 	u16 auto_corr_max_cck_mrc;
552 	u16 auto_corr_min_cck;
553 	u16 auto_corr_min_cck_mrc;
554 
555 	u16 barker_corr_th_min;
556 	u16 barker_corr_th_min_mrc;
557 	u16 nrg_th_cca;
558 };
559 
560 
561 #define KELVIN_TO_CELSIUS(x) ((x)-273)
562 #define CELSIUS_TO_KELVIN(x) ((x)+273)
563 
564 
565 /**
566  * struct iwl_hw_params
567  * @max_txq_num: Max # Tx queues supported
568  * @dma_chnl_num: Number of Tx DMA/FIFO channels
569  * @scd_bc_tbls_size: size of scheduler byte count tables
570  * @tfd_size: TFD size
571  * @tx/rx_chains_num: Number of TX/RX chains
572  * @valid_tx/rx_ant: usable antennas
573  * @max_rxq_size: Max # Rx frames in Rx queue (must be power-of-2)
574  * @max_rxq_log: Log-base-2 of max_rxq_size
575  * @rx_page_order: Rx buffer page order
576  * @rx_wrt_ptr_reg: FH{39}_RSCSR_CHNL0_WPTR
577  * @max_stations:
578  * @ht40_channel: is 40MHz width possible in band 2.4
579  * BIT(IEEE80211_BAND_5GHZ) BIT(IEEE80211_BAND_5GHZ)
580  * @sw_crypto: 0 for hw, 1 for sw
581  * @max_xxx_size: for ucode uses
582  * @ct_kill_threshold: temperature threshold
583  * @beacon_time_tsf_bits: number of valid tsf bits for beacon time
584  * @struct iwl_sensitivity_ranges: range of sensitivity values
585  */
586 struct iwl_hw_params {
587 	u8 max_txq_num;
588 	u8 dma_chnl_num;
589 	u16 scd_bc_tbls_size;
590 	u32 tfd_size;
591 	u8  tx_chains_num;
592 	u8  rx_chains_num;
593 	u8  valid_tx_ant;
594 	u8  valid_rx_ant;
595 	u16 max_rxq_size;
596 	u16 max_rxq_log;
597 	u32 rx_page_order;
598 	u32 rx_wrt_ptr_reg;
599 	u8  max_stations;
600 	u8  ht40_channel;
601 	u8  max_beacon_itrvl;	/* in 1024 ms */
602 	u32 max_inst_size;
603 	u32 max_data_size;
604 	u32 max_bsm_size;
605 	u32 ct_kill_threshold; /* value in hw-dependent units */
606 	u16 beacon_time_tsf_bits;
607 	const struct iwl_sensitivity_ranges *sens;
608 };
609 
610 
611 /******************************************************************************
612  *
613  * Functions implemented in core module which are forward declared here
614  * for use by iwl-[4-5].c
615  *
616  * NOTE:  The implementation of these functions are not hardware specific
617  * which is why they are in the core module files.
618  *
619  * Naming convention --
620  * iwl_         <-- Is part of iwlwifi
621  * iwlXXXX_     <-- Hardware specific (implemented in iwl-XXXX.c for XXXX)
622  * iwl4965_bg_      <-- Called from work queue context
623  * iwl4965_mac_     <-- mac80211 callback
624  *
625  ****************************************************************************/
626 extern void iwl4965_update_chain_flags(struct iwl_priv *priv);
627 extern const u8 iwlegacy_bcast_addr[ETH_ALEN];
628 extern int iwl_legacy_queue_space(const struct iwl_queue *q);
iwl_legacy_queue_used(const struct iwl_queue * q,int i)629 static inline int iwl_legacy_queue_used(const struct iwl_queue *q, int i)
630 {
631 	return q->write_ptr >= q->read_ptr ?
632 		(i >= q->read_ptr && i < q->write_ptr) :
633 		!(i < q->read_ptr && i >= q->write_ptr);
634 }
635 
636 
iwl_legacy_get_cmd_index(struct iwl_queue * q,u32 index,int is_huge)637 static inline u8 iwl_legacy_get_cmd_index(struct iwl_queue *q, u32 index,
638 								int is_huge)
639 {
640 	/*
641 	 * This is for init calibration result and scan command which
642 	 * required buffer > TFD_MAX_PAYLOAD_SIZE,
643 	 * the big buffer at end of command array
644 	 */
645 	if (is_huge)
646 		return q->n_window;	/* must be power of 2 */
647 
648 	/* Otherwise, use normal size buffers */
649 	return index & (q->n_window - 1);
650 }
651 
652 
653 struct iwl_dma_ptr {
654 	dma_addr_t dma;
655 	void *addr;
656 	size_t size;
657 };
658 
659 #define IWL_OPERATION_MODE_AUTO     0
660 #define IWL_OPERATION_MODE_HT_ONLY  1
661 #define IWL_OPERATION_MODE_MIXED    2
662 #define IWL_OPERATION_MODE_20MHZ    3
663 
664 #define IWL_TX_CRC_SIZE 4
665 #define IWL_TX_DELIMITER_SIZE 4
666 
667 #define TX_POWER_IWL_ILLEGAL_VOLTAGE -10000
668 
669 /* Sensitivity and chain noise calibration */
670 #define INITIALIZATION_VALUE		0xFFFF
671 #define IWL4965_CAL_NUM_BEACONS		20
672 #define IWL_CAL_NUM_BEACONS		16
673 #define MAXIMUM_ALLOWED_PATHLOSS	15
674 
675 #define CHAIN_NOISE_MAX_DELTA_GAIN_CODE 3
676 
677 #define MAX_FA_OFDM  50
678 #define MIN_FA_OFDM  5
679 #define MAX_FA_CCK   50
680 #define MIN_FA_CCK   5
681 
682 #define AUTO_CORR_STEP_OFDM       1
683 
684 #define AUTO_CORR_STEP_CCK     3
685 #define AUTO_CORR_MAX_TH_CCK   160
686 
687 #define NRG_DIFF               2
688 #define NRG_STEP_CCK           2
689 #define NRG_MARGIN             8
690 #define MAX_NUMBER_CCK_NO_FA 100
691 
692 #define AUTO_CORR_CCK_MIN_VAL_DEF    (125)
693 
694 #define CHAIN_A             0
695 #define CHAIN_B             1
696 #define CHAIN_C             2
697 #define CHAIN_NOISE_DELTA_GAIN_INIT_VAL 4
698 #define ALL_BAND_FILTER			0xFF00
699 #define IN_BAND_FILTER			0xFF
700 #define MIN_AVERAGE_NOISE_MAX_VALUE	0xFFFFFFFF
701 
702 #define NRG_NUM_PREV_STAT_L     20
703 #define NUM_RX_CHAINS           3
704 
705 enum iwl4965_false_alarm_state {
706 	IWL_FA_TOO_MANY = 0,
707 	IWL_FA_TOO_FEW = 1,
708 	IWL_FA_GOOD_RANGE = 2,
709 };
710 
711 enum iwl4965_chain_noise_state {
712 	IWL_CHAIN_NOISE_ALIVE = 0,  /* must be 0 */
713 	IWL_CHAIN_NOISE_ACCUMULATE,
714 	IWL_CHAIN_NOISE_CALIBRATED,
715 	IWL_CHAIN_NOISE_DONE,
716 };
717 
718 enum iwl4965_calib_enabled_state {
719 	IWL_CALIB_DISABLED = 0,  /* must be 0 */
720 	IWL_CALIB_ENABLED = 1,
721 };
722 
723 /*
724  * enum iwl_calib
725  * defines the order in which results of initial calibrations
726  * should be sent to the runtime uCode
727  */
728 enum iwl_calib {
729 	IWL_CALIB_MAX,
730 };
731 
732 /* Opaque calibration results */
733 struct iwl_calib_result {
734 	void *buf;
735 	size_t buf_len;
736 };
737 
738 enum ucode_type {
739 	UCODE_NONE = 0,
740 	UCODE_INIT,
741 	UCODE_RT
742 };
743 
744 /* Sensitivity calib data */
745 struct iwl_sensitivity_data {
746 	u32 auto_corr_ofdm;
747 	u32 auto_corr_ofdm_mrc;
748 	u32 auto_corr_ofdm_x1;
749 	u32 auto_corr_ofdm_mrc_x1;
750 	u32 auto_corr_cck;
751 	u32 auto_corr_cck_mrc;
752 
753 	u32 last_bad_plcp_cnt_ofdm;
754 	u32 last_fa_cnt_ofdm;
755 	u32 last_bad_plcp_cnt_cck;
756 	u32 last_fa_cnt_cck;
757 
758 	u32 nrg_curr_state;
759 	u32 nrg_prev_state;
760 	u32 nrg_value[10];
761 	u8  nrg_silence_rssi[NRG_NUM_PREV_STAT_L];
762 	u32 nrg_silence_ref;
763 	u32 nrg_energy_idx;
764 	u32 nrg_silence_idx;
765 	u32 nrg_th_cck;
766 	s32 nrg_auto_corr_silence_diff;
767 	u32 num_in_cck_no_fa;
768 	u32 nrg_th_ofdm;
769 
770 	u16 barker_corr_th_min;
771 	u16 barker_corr_th_min_mrc;
772 	u16 nrg_th_cca;
773 };
774 
775 /* Chain noise (differential Rx gain) calib data */
776 struct iwl_chain_noise_data {
777 	u32 active_chains;
778 	u32 chain_noise_a;
779 	u32 chain_noise_b;
780 	u32 chain_noise_c;
781 	u32 chain_signal_a;
782 	u32 chain_signal_b;
783 	u32 chain_signal_c;
784 	u16 beacon_count;
785 	u8 disconn_array[NUM_RX_CHAINS];
786 	u8 delta_gain_code[NUM_RX_CHAINS];
787 	u8 radio_write;
788 	u8 state;
789 };
790 
791 #define	EEPROM_SEM_TIMEOUT 10		/* milliseconds */
792 #define EEPROM_SEM_RETRY_LIMIT 1000	/* number of attempts (not time) */
793 
794 #define IWL_TRAFFIC_ENTRIES	(256)
795 #define IWL_TRAFFIC_ENTRY_SIZE  (64)
796 
797 enum {
798 	MEASUREMENT_READY = (1 << 0),
799 	MEASUREMENT_ACTIVE = (1 << 1),
800 };
801 
802 /* interrupt statistics */
803 struct isr_statistics {
804 	u32 hw;
805 	u32 sw;
806 	u32 err_code;
807 	u32 sch;
808 	u32 alive;
809 	u32 rfkill;
810 	u32 ctkill;
811 	u32 wakeup;
812 	u32 rx;
813 	u32 rx_handlers[REPLY_MAX];
814 	u32 tx;
815 	u32 unhandled;
816 };
817 
818 /* management statistics */
819 enum iwl_mgmt_stats {
820 	MANAGEMENT_ASSOC_REQ = 0,
821 	MANAGEMENT_ASSOC_RESP,
822 	MANAGEMENT_REASSOC_REQ,
823 	MANAGEMENT_REASSOC_RESP,
824 	MANAGEMENT_PROBE_REQ,
825 	MANAGEMENT_PROBE_RESP,
826 	MANAGEMENT_BEACON,
827 	MANAGEMENT_ATIM,
828 	MANAGEMENT_DISASSOC,
829 	MANAGEMENT_AUTH,
830 	MANAGEMENT_DEAUTH,
831 	MANAGEMENT_ACTION,
832 	MANAGEMENT_MAX,
833 };
834 /* control statistics */
835 enum iwl_ctrl_stats {
836 	CONTROL_BACK_REQ =  0,
837 	CONTROL_BACK,
838 	CONTROL_PSPOLL,
839 	CONTROL_RTS,
840 	CONTROL_CTS,
841 	CONTROL_ACK,
842 	CONTROL_CFEND,
843 	CONTROL_CFENDACK,
844 	CONTROL_MAX,
845 };
846 
847 struct traffic_stats {
848 #ifdef CONFIG_IWLWIFI_LEGACY_DEBUGFS
849 	u32 mgmt[MANAGEMENT_MAX];
850 	u32 ctrl[CONTROL_MAX];
851 	u32 data_cnt;
852 	u64 data_bytes;
853 #endif
854 };
855 
856 /*
857  * iwl_switch_rxon: "channel switch" structure
858  *
859  * @ switch_in_progress: channel switch in progress
860  * @ channel: new channel
861  */
862 struct iwl_switch_rxon {
863 	bool switch_in_progress;
864 	__le16 channel;
865 };
866 
867 /*
868  * schedule the timer to wake up every UCODE_TRACE_PERIOD milliseconds
869  * to perform continuous uCode event logging operation if enabled
870  */
871 #define UCODE_TRACE_PERIOD (100)
872 
873 /*
874  * iwl_event_log: current uCode event log position
875  *
876  * @ucode_trace: enable/disable ucode continuous trace timer
877  * @num_wraps: how many times the event buffer wraps
878  * @next_entry:  the entry just before the next one that uCode would fill
879  * @non_wraps_count: counter for no wrap detected when dump ucode events
880  * @wraps_once_count: counter for wrap once detected when dump ucode events
881  * @wraps_more_count: counter for wrap more than once detected
882  *		      when dump ucode events
883  */
884 struct iwl_event_log {
885 	bool ucode_trace;
886 	u32 num_wraps;
887 	u32 next_entry;
888 	int non_wraps_count;
889 	int wraps_once_count;
890 	int wraps_more_count;
891 };
892 
893 /*
894  * host interrupt timeout value
895  * used with setting interrupt coalescing timer
896  * the CSR_INT_COALESCING is an 8 bit register in 32-usec unit
897  *
898  * default interrupt coalescing timer is 64 x 32 = 2048 usecs
899  * default interrupt coalescing calibration timer is 16 x 32 = 512 usecs
900  */
901 #define IWL_HOST_INT_TIMEOUT_MAX	(0xFF)
902 #define IWL_HOST_INT_TIMEOUT_DEF	(0x40)
903 #define IWL_HOST_INT_TIMEOUT_MIN	(0x0)
904 #define IWL_HOST_INT_CALIB_TIMEOUT_MAX	(0xFF)
905 #define IWL_HOST_INT_CALIB_TIMEOUT_DEF	(0x10)
906 #define IWL_HOST_INT_CALIB_TIMEOUT_MIN	(0x0)
907 
908 /*
909  * This is the threshold value of plcp error rate per 100mSecs.  It is
910  * used to set and check for the validity of plcp_delta.
911  */
912 #define IWL_MAX_PLCP_ERR_THRESHOLD_MIN	(1)
913 #define IWL_MAX_PLCP_ERR_THRESHOLD_DEF	(50)
914 #define IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF	(100)
915 #define IWL_MAX_PLCP_ERR_EXT_LONG_THRESHOLD_DEF	(200)
916 #define IWL_MAX_PLCP_ERR_THRESHOLD_MAX	(255)
917 #define IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE	(0)
918 
919 #define IWL_DELAY_NEXT_FORCE_RF_RESET  (HZ*3)
920 #define IWL_DELAY_NEXT_FORCE_FW_RELOAD (HZ*5)
921 
922 /* TX queue watchdog timeouts in mSecs */
923 #define IWL_DEF_WD_TIMEOUT	(2000)
924 #define IWL_LONG_WD_TIMEOUT	(10000)
925 #define IWL_MAX_WD_TIMEOUT	(120000)
926 
927 enum iwl_reset {
928 	IWL_RF_RESET = 0,
929 	IWL_FW_RESET,
930 	IWL_MAX_FORCE_RESET,
931 };
932 
933 struct iwl_force_reset {
934 	int reset_request_count;
935 	int reset_success_count;
936 	int reset_reject_count;
937 	unsigned long reset_duration;
938 	unsigned long last_force_reset_jiffies;
939 };
940 
941 /* extend beacon time format bit shifting  */
942 /*
943  * for _3945 devices
944  * bits 31:24 - extended
945  * bits 23:0  - interval
946  */
947 #define IWL3945_EXT_BEACON_TIME_POS	24
948 /*
949  * for _4965 devices
950  * bits 31:22 - extended
951  * bits 21:0  - interval
952  */
953 #define IWL4965_EXT_BEACON_TIME_POS	22
954 
955 enum iwl_rxon_context_id {
956 	IWL_RXON_CTX_BSS,
957 
958 	NUM_IWL_RXON_CTX
959 };
960 
961 struct iwl_rxon_context {
962 	struct ieee80211_vif *vif;
963 
964 	const u8 *ac_to_fifo;
965 	const u8 *ac_to_queue;
966 	u8 mcast_queue;
967 
968 	/*
969 	 * We could use the vif to indicate active, but we
970 	 * also need it to be active during disabling when
971 	 * we already removed the vif for type setting.
972 	 */
973 	bool always_active, is_active;
974 
975 	bool ht_need_multiple_chains;
976 
977 	enum iwl_rxon_context_id ctxid;
978 
979 	u32 interface_modes, exclusive_interface_modes;
980 	u8 unused_devtype, ap_devtype, ibss_devtype, station_devtype;
981 
982 	/*
983 	 * We declare this const so it can only be
984 	 * changed via explicit cast within the
985 	 * routines that actually update the physical
986 	 * hardware.
987 	 */
988 	const struct iwl_legacy_rxon_cmd active;
989 	struct iwl_legacy_rxon_cmd staging;
990 
991 	struct iwl_rxon_time_cmd timing;
992 
993 	struct iwl_qos_info qos_data;
994 
995 	u8 bcast_sta_id, ap_sta_id;
996 
997 	u8 rxon_cmd, rxon_assoc_cmd, rxon_timing_cmd;
998 	u8 qos_cmd;
999 	u8 wep_key_cmd;
1000 
1001 	struct iwl_wep_key wep_keys[WEP_KEYS_MAX];
1002 	u8 key_mapping_keys;
1003 
1004 	__le32 station_flags;
1005 
1006 	struct {
1007 		bool non_gf_sta_present;
1008 		u8 protection;
1009 		bool enabled, is_40mhz;
1010 		u8 extension_chan_offset;
1011 	} ht;
1012 };
1013 
1014 struct iwl_priv {
1015 
1016 	/* ieee device used by generic ieee processing code */
1017 	struct ieee80211_hw *hw;
1018 	struct ieee80211_channel *ieee_channels;
1019 	struct ieee80211_rate *ieee_rates;
1020 	struct iwl_cfg *cfg;
1021 
1022 	/* temporary frame storage list */
1023 	struct list_head free_frames;
1024 	int frames_count;
1025 
1026 	enum ieee80211_band band;
1027 	int alloc_rxb_page;
1028 
1029 	void (*rx_handlers[REPLY_MAX])(struct iwl_priv *priv,
1030 				       struct iwl_rx_mem_buffer *rxb);
1031 
1032 	struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
1033 
1034 	/* spectrum measurement report caching */
1035 	struct iwl_spectrum_notification measure_report;
1036 	u8 measurement_status;
1037 
1038 	/* ucode beacon time */
1039 	u32 ucode_beacon_time;
1040 	int missed_beacon_threshold;
1041 
1042 	/* track IBSS manager (last beacon) status */
1043 	u32 ibss_manager;
1044 
1045 	/* storing the jiffies when the plcp error rate is received */
1046 	unsigned long plcp_jiffies;
1047 
1048 	/* force reset */
1049 	struct iwl_force_reset force_reset[IWL_MAX_FORCE_RESET];
1050 
1051 	/* we allocate array of iwl_channel_info for NIC's valid channels.
1052 	 *    Access via channel # using indirect index array */
1053 	struct iwl_channel_info *channel_info;	/* channel info array */
1054 	u8 channel_count;	/* # of channels */
1055 
1056 	/* thermal calibration */
1057 	s32 temperature;	/* degrees Kelvin */
1058 	s32 last_temperature;
1059 
1060 	/* init calibration results */
1061 	struct iwl_calib_result calib_results[IWL_CALIB_MAX];
1062 
1063 	/* Scan related variables */
1064 	unsigned long scan_start;
1065 	unsigned long scan_start_tsf;
1066 	void *scan_cmd;
1067 	enum ieee80211_band scan_band;
1068 	struct cfg80211_scan_request *scan_request;
1069 	struct ieee80211_vif *scan_vif;
1070 	bool is_internal_short_scan;
1071 	u8 scan_tx_ant[IEEE80211_NUM_BANDS];
1072 	u8 mgmt_tx_ant;
1073 
1074 	/* spinlock */
1075 	spinlock_t lock;	/* protect general shared data */
1076 	spinlock_t hcmd_lock;	/* protect hcmd */
1077 	spinlock_t reg_lock;	/* protect hw register access */
1078 	struct mutex mutex;
1079 	struct mutex sync_cmd_mutex; /* enable serialization of sync commands */
1080 
1081 	/* basic pci-network driver stuff */
1082 	struct pci_dev *pci_dev;
1083 
1084 	/* pci hardware address support */
1085 	void __iomem *hw_base;
1086 	u32  hw_rev;
1087 	u32  hw_wa_rev;
1088 	u8   rev_id;
1089 
1090 	/* microcode/device supports multiple contexts */
1091 	u8 valid_contexts;
1092 
1093 	/* command queue number */
1094 	u8 cmd_queue;
1095 
1096 	/* max number of station keys */
1097 	u8 sta_key_max_num;
1098 
1099 	/* EEPROM MAC addresses */
1100 	struct mac_address addresses[1];
1101 
1102 	/* uCode images, save to reload in case of failure */
1103 	int fw_index;			/* firmware we're trying to load */
1104 	u32 ucode_ver;			/* version of ucode, copy of
1105 					   iwl_ucode.ver */
1106 	struct fw_desc ucode_code;	/* runtime inst */
1107 	struct fw_desc ucode_data;	/* runtime data original */
1108 	struct fw_desc ucode_data_backup;	/* runtime data save/restore */
1109 	struct fw_desc ucode_init;	/* initialization inst */
1110 	struct fw_desc ucode_init_data;	/* initialization data */
1111 	struct fw_desc ucode_boot;	/* bootstrap inst */
1112 	enum ucode_type ucode_type;
1113 	u8 ucode_write_complete;	/* the image write is complete */
1114 	char firmware_name[25];
1115 
1116 	struct iwl_rxon_context contexts[NUM_IWL_RXON_CTX];
1117 
1118 	struct iwl_switch_rxon switch_rxon;
1119 
1120 	/* 1st responses from initialize and runtime uCode images.
1121 	 * _4965's initialize alive response contains some calibration data. */
1122 	struct iwl_init_alive_resp card_alive_init;
1123 	struct iwl_alive_resp card_alive;
1124 
1125 	u16 active_rate;
1126 
1127 	u8 start_calib;
1128 	struct iwl_sensitivity_data sensitivity_data;
1129 	struct iwl_chain_noise_data chain_noise_data;
1130 	__le16 sensitivity_tbl[HD_TABLE_SIZE];
1131 
1132 	struct iwl_ht_config current_ht_config;
1133 
1134 	/* Rate scaling data */
1135 	u8 retry_rate;
1136 
1137 	wait_queue_head_t wait_command_queue;
1138 
1139 	int activity_timer_active;
1140 
1141 	/* Rx and Tx DMA processing queues */
1142 	struct iwl_rx_queue rxq;
1143 	struct iwl_tx_queue *txq;
1144 	unsigned long txq_ctx_active_msk;
1145 	struct iwl_dma_ptr  kw;	/* keep warm address */
1146 	struct iwl_dma_ptr  scd_bc_tbls;
1147 
1148 	u32 scd_base_addr;	/* scheduler sram base address */
1149 
1150 	unsigned long status;
1151 
1152 	/* counts mgmt, ctl, and data packets */
1153 	struct traffic_stats tx_stats;
1154 	struct traffic_stats rx_stats;
1155 
1156 	/* counts interrupts */
1157 	struct isr_statistics isr_stats;
1158 
1159 	struct iwl_power_mgr power_data;
1160 
1161 	/* context information */
1162 	u8 bssid[ETH_ALEN]; /* used only on 3945 but filled by core */
1163 
1164 	/* station table variables */
1165 
1166 	/* Note: if lock and sta_lock are needed, lock must be acquired first */
1167 	spinlock_t sta_lock;
1168 	int num_stations;
1169 	struct iwl_station_entry stations[IWL_STATION_COUNT];
1170 	unsigned long ucode_key_table;
1171 
1172 	/* queue refcounts */
1173 #define IWL_MAX_HW_QUEUES	32
1174 	unsigned long queue_stopped[BITS_TO_LONGS(IWL_MAX_HW_QUEUES)];
1175 	/* for each AC */
1176 	atomic_t queue_stop_count[4];
1177 
1178 	/* Indication if ieee80211_ops->open has been called */
1179 	u8 is_open;
1180 
1181 	u8 mac80211_registered;
1182 
1183 	/* eeprom -- this is in the card's little endian byte order */
1184 	u8 *eeprom;
1185 	struct iwl_eeprom_calib_info *calib_info;
1186 
1187 	enum nl80211_iftype iw_mode;
1188 
1189 	/* Last Rx'd beacon timestamp */
1190 	u64 timestamp;
1191 
1192 	union {
1193 #if defined(CONFIG_IWL3945) || defined(CONFIG_IWL3945_MODULE)
1194 		struct {
1195 			void *shared_virt;
1196 			dma_addr_t shared_phys;
1197 
1198 			struct delayed_work thermal_periodic;
1199 			struct delayed_work rfkill_poll;
1200 
1201 			struct iwl3945_notif_statistics statistics;
1202 #ifdef CONFIG_IWLWIFI_LEGACY_DEBUGFS
1203 			struct iwl3945_notif_statistics accum_statistics;
1204 			struct iwl3945_notif_statistics delta_statistics;
1205 			struct iwl3945_notif_statistics max_delta;
1206 #endif
1207 
1208 			u32 sta_supp_rates;
1209 			int last_rx_rssi;	/* From Rx packet statistics */
1210 
1211 			/* Rx'd packet timing information */
1212 			u32 last_beacon_time;
1213 			u64 last_tsf;
1214 
1215 			/*
1216 			 * each calibration channel group in the
1217 			 * EEPROM has a derived clip setting for
1218 			 * each rate.
1219 			 */
1220 			const struct iwl3945_clip_group clip_groups[5];
1221 
1222 		} _3945;
1223 #endif
1224 #if defined(CONFIG_IWL4965) || defined(CONFIG_IWL4965_MODULE)
1225 		struct {
1226 			/*
1227 			 * reporting the number of tids has AGG on. 0 means
1228 			 * no AGGREGATION
1229 			 */
1230 			u8 agg_tids_count;
1231 
1232 			struct iwl_rx_phy_res last_phy_res;
1233 			bool last_phy_res_valid;
1234 
1235 			struct completion firmware_loading_complete;
1236 
1237 			/*
1238 			 * chain noise reset and gain commands are the
1239 			 * two extra calibration commands follows the standard
1240 			 * phy calibration commands
1241 			 */
1242 			u8 phy_calib_chain_noise_reset_cmd;
1243 			u8 phy_calib_chain_noise_gain_cmd;
1244 
1245 			struct iwl_notif_statistics statistics;
1246 #ifdef CONFIG_IWLWIFI_LEGACY_DEBUGFS
1247 			struct iwl_notif_statistics accum_statistics;
1248 			struct iwl_notif_statistics delta_statistics;
1249 			struct iwl_notif_statistics max_delta;
1250 #endif
1251 
1252 		} _4965;
1253 #endif
1254 	};
1255 
1256 	struct iwl_hw_params hw_params;
1257 
1258 	u32 inta_mask;
1259 
1260 	struct workqueue_struct *workqueue;
1261 
1262 	struct work_struct restart;
1263 	struct work_struct scan_completed;
1264 	struct work_struct rx_replenish;
1265 	struct work_struct abort_scan;
1266 
1267 	struct iwl_rxon_context *beacon_ctx;
1268 	struct sk_buff *beacon_skb;
1269 
1270 	struct work_struct start_internal_scan;
1271 	struct work_struct tx_flush;
1272 
1273 	struct tasklet_struct irq_tasklet;
1274 
1275 	struct delayed_work init_alive_start;
1276 	struct delayed_work alive_start;
1277 	struct delayed_work scan_check;
1278 
1279 	/* TX Power */
1280 	s8 tx_power_user_lmt;
1281 	s8 tx_power_device_lmt;
1282 	s8 tx_power_next;
1283 
1284 
1285 #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
1286 	/* debugging info */
1287 	u32 debug_level; /* per device debugging will override global
1288 			    iwlegacy_debug_level if set */
1289 #endif /* CONFIG_IWLWIFI_LEGACY_DEBUG */
1290 #ifdef CONFIG_IWLWIFI_LEGACY_DEBUGFS
1291 	/* debugfs */
1292 	u16 tx_traffic_idx;
1293 	u16 rx_traffic_idx;
1294 	u8 *tx_traffic;
1295 	u8 *rx_traffic;
1296 	struct dentry *debugfs_dir;
1297 	u32 dbgfs_sram_offset, dbgfs_sram_len;
1298 	bool disable_ht40;
1299 #endif /* CONFIG_IWLWIFI_LEGACY_DEBUGFS */
1300 
1301 	struct work_struct txpower_work;
1302 	u32 disable_sens_cal;
1303 	u32 disable_chain_noise_cal;
1304 	u32 disable_tx_power_cal;
1305 	struct work_struct run_time_calib_work;
1306 	struct timer_list statistics_periodic;
1307 	struct timer_list ucode_trace;
1308 	struct timer_list watchdog;
1309 	bool hw_ready;
1310 
1311 	struct iwl_event_log event_log;
1312 
1313 	struct led_classdev led;
1314 	unsigned long blink_on, blink_off;
1315 	bool led_registered;
1316 }; /*iwl_priv */
1317 
iwl_txq_ctx_activate(struct iwl_priv * priv,int txq_id)1318 static inline void iwl_txq_ctx_activate(struct iwl_priv *priv, int txq_id)
1319 {
1320 	set_bit(txq_id, &priv->txq_ctx_active_msk);
1321 }
1322 
iwl_txq_ctx_deactivate(struct iwl_priv * priv,int txq_id)1323 static inline void iwl_txq_ctx_deactivate(struct iwl_priv *priv, int txq_id)
1324 {
1325 	clear_bit(txq_id, &priv->txq_ctx_active_msk);
1326 }
1327 
1328 #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
1329 /*
1330  * iwl_legacy_get_debug_level: Return active debug level for device
1331  *
1332  * Using sysfs it is possible to set per device debug level. This debug
1333  * level will be used if set, otherwise the global debug level which can be
1334  * set via module parameter is used.
1335  */
iwl_legacy_get_debug_level(struct iwl_priv * priv)1336 static inline u32 iwl_legacy_get_debug_level(struct iwl_priv *priv)
1337 {
1338 	if (priv->debug_level)
1339 		return priv->debug_level;
1340 	else
1341 		return iwlegacy_debug_level;
1342 }
1343 #else
iwl_legacy_get_debug_level(struct iwl_priv * priv)1344 static inline u32 iwl_legacy_get_debug_level(struct iwl_priv *priv)
1345 {
1346 	return iwlegacy_debug_level;
1347 }
1348 #endif
1349 
1350 
1351 static inline struct ieee80211_hdr *
iwl_legacy_tx_queue_get_hdr(struct iwl_priv * priv,int txq_id,int idx)1352 iwl_legacy_tx_queue_get_hdr(struct iwl_priv *priv,
1353 						 int txq_id, int idx)
1354 {
1355 	if (priv->txq[txq_id].txb[idx].skb)
1356 		return (struct ieee80211_hdr *)priv->txq[txq_id].
1357 				txb[idx].skb->data;
1358 	return NULL;
1359 }
1360 
1361 static inline struct iwl_rxon_context *
iwl_legacy_rxon_ctx_from_vif(struct ieee80211_vif * vif)1362 iwl_legacy_rxon_ctx_from_vif(struct ieee80211_vif *vif)
1363 {
1364 	struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
1365 
1366 	return vif_priv->ctx;
1367 }
1368 
1369 #define for_each_context(priv, ctx)				\
1370 	for (ctx = &priv->contexts[IWL_RXON_CTX_BSS];		\
1371 	     ctx < &priv->contexts[NUM_IWL_RXON_CTX]; ctx++)	\
1372 		if (priv->valid_contexts & BIT(ctx->ctxid))
1373 
iwl_legacy_is_associated(struct iwl_priv * priv,enum iwl_rxon_context_id ctxid)1374 static inline int iwl_legacy_is_associated(struct iwl_priv *priv,
1375 				    enum iwl_rxon_context_id ctxid)
1376 {
1377 	return (priv->contexts[ctxid].active.filter_flags &
1378 			RXON_FILTER_ASSOC_MSK) ? 1 : 0;
1379 }
1380 
iwl_legacy_is_any_associated(struct iwl_priv * priv)1381 static inline int iwl_legacy_is_any_associated(struct iwl_priv *priv)
1382 {
1383 	return iwl_legacy_is_associated(priv, IWL_RXON_CTX_BSS);
1384 }
1385 
iwl_legacy_is_associated_ctx(struct iwl_rxon_context * ctx)1386 static inline int iwl_legacy_is_associated_ctx(struct iwl_rxon_context *ctx)
1387 {
1388 	return (ctx->active.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0;
1389 }
1390 
iwl_legacy_is_channel_valid(const struct iwl_channel_info * ch_info)1391 static inline int iwl_legacy_is_channel_valid(const struct iwl_channel_info *ch_info)
1392 {
1393 	if (ch_info == NULL)
1394 		return 0;
1395 	return (ch_info->flags & EEPROM_CHANNEL_VALID) ? 1 : 0;
1396 }
1397 
iwl_legacy_is_channel_radar(const struct iwl_channel_info * ch_info)1398 static inline int iwl_legacy_is_channel_radar(const struct iwl_channel_info *ch_info)
1399 {
1400 	return (ch_info->flags & EEPROM_CHANNEL_RADAR) ? 1 : 0;
1401 }
1402 
iwl_legacy_is_channel_a_band(const struct iwl_channel_info * ch_info)1403 static inline u8 iwl_legacy_is_channel_a_band(const struct iwl_channel_info *ch_info)
1404 {
1405 	return ch_info->band == IEEE80211_BAND_5GHZ;
1406 }
1407 
1408 static inline int
iwl_legacy_is_channel_passive(const struct iwl_channel_info * ch)1409 iwl_legacy_is_channel_passive(const struct iwl_channel_info *ch)
1410 {
1411 	return (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) ? 1 : 0;
1412 }
1413 
1414 static inline int
iwl_legacy_is_channel_ibss(const struct iwl_channel_info * ch)1415 iwl_legacy_is_channel_ibss(const struct iwl_channel_info *ch)
1416 {
1417 	return (ch->flags & EEPROM_CHANNEL_IBSS) ? 1 : 0;
1418 }
1419 
1420 static inline void
__iwl_legacy_free_pages(struct iwl_priv * priv,struct page * page)1421 __iwl_legacy_free_pages(struct iwl_priv *priv, struct page *page)
1422 {
1423 	__free_pages(page, priv->hw_params.rx_page_order);
1424 	priv->alloc_rxb_page--;
1425 }
1426 
iwl_legacy_free_pages(struct iwl_priv * priv,unsigned long page)1427 static inline void iwl_legacy_free_pages(struct iwl_priv *priv, unsigned long page)
1428 {
1429 	free_pages(page, priv->hw_params.rx_page_order);
1430 	priv->alloc_rxb_page--;
1431 }
1432 #endif				/* __iwl_legacy_dev_h__ */
1433