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