blob: 65c593d34bf034b4c442e90a7b5c48f0b9cb8a4b [file] [log] [blame]
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001/******************************************************************************
2 *
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +02003 * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved.
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08004 *
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +02005 * 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
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08007 * published by the Free Software Foundation.
8 *
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +02009 * 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.
Wey-Yi Guybe663ab2011-02-21 11:27:26 -080013 *
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +020014 * 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
Wey-Yi Guybe663ab2011-02-21 11:27:26 -080017 *
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +020018 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
Wey-Yi Guybe663ab2011-02-21 11:27:26 -080020 *
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 *
Wey-Yi Guybe663ab2011-02-21 11:27:26 -080025 *****************************************************************************/
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +020026#ifndef __il_core_h__
27#define __il_core_h__
Wey-Yi Guybe663ab2011-02-21 11:27:26 -080028
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +020029#include <linux/interrupt.h>
30#include <linux/pci.h> /* for struct pci_device_id */
31#include <linux/kernel.h>
32#include <linux/leds.h>
33#include <linux/wait.h>
34#include <net/ieee80211_radiotap.h>
35
Stanislaw Gruszka99412002011-08-31 13:53:04 +020036#include "commands.h"
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +020037#include "iwl-eeprom.h"
38#include "csr.h"
39#include "iwl-prph.h"
40#include "iwl-debug.h"
41#include "iwl-led.h"
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +020042
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +020043struct il_host_cmd;
44struct il_cmd;
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +020045struct il_tx_queue;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -080046
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +020047#define RX_QUEUE_SIZE 256
48#define RX_QUEUE_MASK 255
49#define RX_QUEUE_SIZE_LOG 8
50
51/*
52 * RX related structures and functions
53 */
54#define RX_FREE_BUFFERS 64
55#define RX_LOW_WATERMARK 8
56
57#define U32_PAD(n) ((4-(n))&0x3)
58
59/* CT-KILL constants */
60#define CT_KILL_THRESHOLD_LEGACY 110 /* in Celsius */
61
62/* Default noise level to report when noise measurement is not available.
63 * This may be because we're:
64 * 1) Not associated (4965, no beacon stats being sent to driver)
65 * 2) Scanning (noise measurement does not apply to associated channel)
66 * 3) Receiving CCK (3945 delivers noise info only for OFDM frames)
67 * Use default noise value of -127 ... this is below the range of measurable
68 * Rx dBm for either 3945 or 4965, so it can indicate "unmeasurable" to user.
69 * Also, -127 works better than 0 when averaging frames with/without
70 * noise info (e.g. averaging might be done in app); measured dBm values are
71 * always negative ... using a negative value as the default keeps all
72 * averages within an s8's (used in some apps) range of negative values. */
73#define IL_NOISE_MEAS_NOT_AVAILABLE (-127)
74
75/*
76 * RTS threshold here is total size [2347] minus 4 FCS bytes
77 * Per spec:
78 * a value of 0 means RTS on all data/management packets
79 * a value > max MSDU size means no RTS
80 * else RTS for data/management frames where MPDU is larger
81 * than RTS value.
82 */
83#define DEFAULT_RTS_THRESHOLD 2347U
84#define MIN_RTS_THRESHOLD 0U
85#define MAX_RTS_THRESHOLD 2347U
86#define MAX_MSDU_SIZE 2304U
87#define MAX_MPDU_SIZE 2346U
88#define DEFAULT_BEACON_INTERVAL 100U
89#define DEFAULT_SHORT_RETRY_LIMIT 7U
90#define DEFAULT_LONG_RETRY_LIMIT 4U
91
92struct il_rx_buf {
93 dma_addr_t page_dma;
94 struct page *page;
95 struct list_head list;
96};
97
98#define rxb_addr(r) page_address(r->page)
99
100/* defined below */
101struct il_device_cmd;
102
103struct il_cmd_meta {
104 /* only for SYNC commands, iff the reply skb is wanted */
105 struct il_host_cmd *source;
106 /*
107 * only for ASYNC commands
108 * (which is somewhat stupid -- look at common.c for instance
109 * which duplicates a bunch of code because the callback isn't
110 * invoked for SYNC commands, if it were and its result passed
111 * through it would be simpler...)
112 */
113 void (*callback)(struct il_priv *il,
114 struct il_device_cmd *cmd,
115 struct il_rx_pkt *pkt);
116
117 /* The CMD_SIZE_HUGE flag bit indicates that the command
118 * structure is stored at the end of the shared queue memory. */
119 u32 flags;
120
121 DEFINE_DMA_UNMAP_ADDR(mapping);
122 DEFINE_DMA_UNMAP_LEN(len);
123};
124
125/*
126 * Generic queue structure
127 *
128 * Contains common data for Rx and Tx queues
129 */
130struct il_queue {
131 int n_bd; /* number of BDs in this queue */
132 int write_ptr; /* 1-st empty entry (idx) host_w*/
133 int read_ptr; /* last used entry (idx) host_r*/
134 /* use for monitoring and recovering the stuck queue */
135 dma_addr_t dma_addr; /* physical addr for BD's */
136 int n_win; /* safe queue win */
137 u32 id;
138 int low_mark; /* low watermark, resume queue if free
139 * space more than this */
140 int high_mark; /* high watermark, stop queue if free
141 * space less than this */
142};
143
144/* One for each TFD */
145struct il_tx_info {
146 struct sk_buff *skb;
147 struct il_rxon_context *ctx;
148};
149
150/**
151 * struct il_tx_queue - Tx Queue for DMA
152 * @q: generic Rx/Tx queue descriptor
153 * @bd: base of circular buffer of TFDs
154 * @cmd: array of command/TX buffer pointers
155 * @meta: array of meta data for each command/tx buffer
156 * @dma_addr_cmd: physical address of cmd/tx buffer array
157 * @txb: array of per-TFD driver data
158 * @time_stamp: time (in jiffies) of last read_ptr change
159 * @need_update: indicates need to update read/write idx
160 * @sched_retry: indicates queue is high-throughput aggregation (HT AGG) enabled
161 *
162 * A Tx queue consists of circular buffer of BDs (a.k.a. TFDs, transmit frame
163 * descriptors) and required locking structures.
164 */
165#define TFD_TX_CMD_SLOTS 256
166#define TFD_CMD_SLOTS 32
167
168struct il_tx_queue {
169 struct il_queue q;
170 void *tfds;
171 struct il_device_cmd **cmd;
172 struct il_cmd_meta *meta;
173 struct il_tx_info *txb;
174 unsigned long time_stamp;
175 u8 need_update;
176 u8 sched_retry;
177 u8 active;
178 u8 swq_id;
179};
180
181#define IL_NUM_SCAN_RATES (2)
182
183struct il4965_channel_tgd_info {
184 u8 type;
185 s8 max_power;
186};
187
188struct il4965_channel_tgh_info {
189 s64 last_radar_time;
190};
191
192#define IL4965_MAX_RATE (33)
193
194struct il3945_clip_group {
195 /* maximum power level to prevent clipping for each rate, derived by
196 * us from this band's saturation power in EEPROM */
197 const s8 clip_powers[IL_MAX_RATES];
198};
199
200/* current Tx power values to use, one for each rate for each channel.
201 * requested power is limited by:
202 * -- regulatory EEPROM limits for this channel
203 * -- hardware capabilities (clip-powers)
204 * -- spectrum management
205 * -- user preference (e.g. iwconfig)
206 * when requested power is set, base power idx must also be set. */
207struct il3945_channel_power_info {
208 struct il3945_tx_power tpc; /* actual radio and DSP gain settings */
209 s8 power_table_idx; /* actual (compenst'd) idx into gain table */
210 s8 base_power_idx; /* gain idx for power at factory temp. */
211 s8 requested_power; /* power (dBm) requested for this chnl/rate */
212};
213
214/* current scan Tx power values to use, one for each scan rate for each
215 * channel. */
216struct il3945_scan_power_info {
217 struct il3945_tx_power tpc; /* actual radio and DSP gain settings */
218 s8 power_table_idx; /* actual (compenst'd) idx into gain table */
219 s8 requested_power; /* scan pwr (dBm) requested for chnl/rate */
220};
221
222/*
223 * One for each channel, holds all channel setup data
224 * Some of the fields (e.g. eeprom and flags/max_power_avg) are redundant
225 * with one another!
226 */
227struct il_channel_info {
228 struct il4965_channel_tgd_info tgd;
229 struct il4965_channel_tgh_info tgh;
230 struct il_eeprom_channel eeprom; /* EEPROM regulatory limit */
231 struct il_eeprom_channel ht40_eeprom; /* EEPROM regulatory limit for
232 * HT40 channel */
233
234 u8 channel; /* channel number */
235 u8 flags; /* flags copied from EEPROM */
236 s8 max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */
237 s8 curr_txpow; /* (dBm) regulatory/spectrum/user (not h/w) limit */
238 s8 min_power; /* always 0 */
239 s8 scan_power; /* (dBm) regul. eeprom, direct scans, any rate */
240
241 u8 group_idx; /* 0-4, maps channel to group1/2/3/4/5 */
242 u8 band_idx; /* 0-4, maps channel to band1/2/3/4/5 */
243 enum ieee80211_band band;
244
245 /* HT40 channel info */
246 s8 ht40_max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */
247 u8 ht40_flags; /* flags copied from EEPROM */
248 u8 ht40_extension_channel; /* HT_IE_EXT_CHANNEL_* */
249
250 /* Radio/DSP gain settings for each "normal" data Tx rate.
251 * These include, in addition to RF and DSP gain, a few fields for
252 * remembering/modifying gain settings (idxes). */
253 struct il3945_channel_power_info power_info[IL4965_MAX_RATE];
254
255 /* Radio/DSP gain settings for each scan rate, for directed scans. */
256 struct il3945_scan_power_info scan_pwr_info[IL_NUM_SCAN_RATES];
257};
258
259#define IL_TX_FIFO_BK 0 /* shared */
260#define IL_TX_FIFO_BE 1
261#define IL_TX_FIFO_VI 2 /* shared */
262#define IL_TX_FIFO_VO 3
263#define IL_TX_FIFO_UNUSED -1
264
265/* Minimum number of queues. MAX_NUM is defined in hw specific files.
266 * Set the minimum to accommodate the 4 standard TX queues, 1 command
267 * queue, 2 (unused) HCCA queues, and 4 HT queues (one for each AC) */
268#define IL_MIN_NUM_QUEUES 10
269
270#define IL_DEFAULT_CMD_QUEUE_NUM 4
271
272#define IEEE80211_DATA_LEN 2304
273#define IEEE80211_4ADDR_LEN 30
274#define IEEE80211_HLEN (IEEE80211_4ADDR_LEN)
275#define IEEE80211_FRAME_LEN (IEEE80211_DATA_LEN + IEEE80211_HLEN)
276
277struct il_frame {
278 union {
279 struct ieee80211_hdr frame;
280 struct il_tx_beacon_cmd beacon;
281 u8 raw[IEEE80211_FRAME_LEN];
282 u8 cmd[360];
283 } u;
284 struct list_head list;
285};
286
287#define SEQ_TO_SN(seq) (((seq) & IEEE80211_SCTL_SEQ) >> 4)
288#define SN_TO_SEQ(ssn) (((ssn) << 4) & IEEE80211_SCTL_SEQ)
289#define MAX_SN ((IEEE80211_SCTL_SEQ) >> 4)
290
291enum {
292 CMD_SYNC = 0,
293 CMD_SIZE_NORMAL = 0,
294 CMD_NO_SKB = 0,
295 CMD_SIZE_HUGE = (1 << 0),
296 CMD_ASYNC = (1 << 1),
297 CMD_WANT_SKB = (1 << 2),
298 CMD_MAPPED = (1 << 3),
299};
300
301#define DEF_CMD_PAYLOAD_SIZE 320
302
303/**
304 * struct il_device_cmd
305 *
306 * For allocation of the command and tx queues, this establishes the overall
307 * size of the largest command we send to uCode, except for a scan command
308 * (which is relatively huge; space is allocated separately).
309 */
310struct il_device_cmd {
311 struct il_cmd_header hdr; /* uCode API */
312 union {
313 u32 flags;
314 u8 val8;
315 u16 val16;
316 u32 val32;
317 struct il_tx_cmd tx;
318 u8 payload[DEF_CMD_PAYLOAD_SIZE];
319 } __packed cmd;
320} __packed;
321
322#define TFD_MAX_PAYLOAD_SIZE (sizeof(struct il_device_cmd))
323
324
325struct il_host_cmd {
326 const void *data;
327 unsigned long reply_page;
328 void (*callback)(struct il_priv *il,
329 struct il_device_cmd *cmd,
330 struct il_rx_pkt *pkt);
331 u32 flags;
332 u16 len;
333 u8 id;
334};
335
336#define SUP_RATE_11A_MAX_NUM_CHANNELS 8
337#define SUP_RATE_11B_MAX_NUM_CHANNELS 4
338#define SUP_RATE_11G_MAX_NUM_CHANNELS 12
339
340/**
341 * struct il_rx_queue - Rx queue
342 * @bd: driver's pointer to buffer of receive buffer descriptors (rbd)
343 * @bd_dma: bus address of buffer of receive buffer descriptors (rbd)
344 * @read: Shared idx to newest available Rx buffer
345 * @write: Shared idx to oldest written Rx packet
346 * @free_count: Number of pre-allocated buffers in rx_free
347 * @rx_free: list of free SKBs for use
348 * @rx_used: List of Rx buffers with no SKB
349 * @need_update: flag to indicate we need to update read/write idx
350 * @rb_stts: driver's pointer to receive buffer status
351 * @rb_stts_dma: bus address of receive buffer status
352 *
353 * NOTE: rx_free and rx_used are used as a FIFO for il_rx_bufs
354 */
355struct il_rx_queue {
356 __le32 *bd;
357 dma_addr_t bd_dma;
358 struct il_rx_buf pool[RX_QUEUE_SIZE + RX_FREE_BUFFERS];
359 struct il_rx_buf *queue[RX_QUEUE_SIZE];
360 u32 read;
361 u32 write;
362 u32 free_count;
363 u32 write_actual;
364 struct list_head rx_free;
365 struct list_head rx_used;
366 int need_update;
367 struct il_rb_status *rb_stts;
368 dma_addr_t rb_stts_dma;
369 spinlock_t lock;
370};
371
372#define IL_SUPPORTED_RATES_IE_LEN 8
373
374#define MAX_TID_COUNT 9
375
376#define IL_INVALID_RATE 0xFF
377#define IL_INVALID_VALUE -1
378
379/**
380 * struct il_ht_agg -- aggregation status while waiting for block-ack
381 * @txq_id: Tx queue used for Tx attempt
382 * @frame_count: # frames attempted by Tx command
383 * @wait_for_ba: Expect block-ack before next Tx reply
384 * @start_idx: Index of 1st Transmit Frame Descriptor (TFD) in Tx win
385 * @bitmap0: Low order bitmap, one bit for each frame pending ACK in Tx win
386 * @bitmap1: High order, one bit for each frame pending ACK in Tx win
387 * @rate_n_flags: Rate at which Tx was attempted
388 *
389 * If C_TX indicates that aggregation was attempted, driver must wait
390 * for block ack (N_COMPRESSED_BA). This struct stores tx reply info
391 * until block ack arrives.
392 */
393struct il_ht_agg {
394 u16 txq_id;
395 u16 frame_count;
396 u16 wait_for_ba;
397 u16 start_idx;
398 u64 bitmap;
399 u32 rate_n_flags;
400#define IL_AGG_OFF 0
401#define IL_AGG_ON 1
402#define IL_EMPTYING_HW_QUEUE_ADDBA 2
403#define IL_EMPTYING_HW_QUEUE_DELBA 3
404 u8 state;
405};
406
407
408struct il_tid_data {
409 u16 seq_number; /* 4965 only */
410 u16 tfds_in_queue;
411 struct il_ht_agg agg;
412};
413
414struct il_hw_key {
415 u32 cipher;
416 int keylen;
417 u8 keyidx;
418 u8 key[32];
419};
420
421union il_ht_rate_supp {
422 u16 rates;
423 struct {
424 u8 siso_rate;
425 u8 mimo_rate;
426 };
427};
428
429#define CFG_HT_RX_AMPDU_FACTOR_8K (0x0)
430#define CFG_HT_RX_AMPDU_FACTOR_16K (0x1)
431#define CFG_HT_RX_AMPDU_FACTOR_32K (0x2)
432#define CFG_HT_RX_AMPDU_FACTOR_64K (0x3)
433#define CFG_HT_RX_AMPDU_FACTOR_DEF CFG_HT_RX_AMPDU_FACTOR_64K
434#define CFG_HT_RX_AMPDU_FACTOR_MAX CFG_HT_RX_AMPDU_FACTOR_64K
435#define CFG_HT_RX_AMPDU_FACTOR_MIN CFG_HT_RX_AMPDU_FACTOR_8K
436
437/*
438 * Maximal MPDU density for TX aggregation
439 * 4 - 2us density
440 * 5 - 4us density
441 * 6 - 8us density
442 * 7 - 16us density
443 */
444#define CFG_HT_MPDU_DENSITY_2USEC (0x4)
445#define CFG_HT_MPDU_DENSITY_4USEC (0x5)
446#define CFG_HT_MPDU_DENSITY_8USEC (0x6)
447#define CFG_HT_MPDU_DENSITY_16USEC (0x7)
448#define CFG_HT_MPDU_DENSITY_DEF CFG_HT_MPDU_DENSITY_4USEC
449#define CFG_HT_MPDU_DENSITY_MAX CFG_HT_MPDU_DENSITY_16USEC
450#define CFG_HT_MPDU_DENSITY_MIN (0x1)
451
452struct il_ht_config {
453 bool single_chain_sufficient;
454 enum ieee80211_smps_mode smps; /* current smps mode */
455};
456
457/* QoS structures */
458struct il_qos_info {
459 int qos_active;
460 struct il_qosparam_cmd def_qos_parm;
461};
462
463/*
464 * Structure should be accessed with sta_lock held. When station addition
465 * is in progress (IL_STA_UCODE_INPROGRESS) it is possible to access only
466 * the commands (il_addsta_cmd and il_link_quality_cmd) without
467 * sta_lock held.
468 */
469struct il_station_entry {
470 struct il_addsta_cmd sta;
471 struct il_tid_data tid[MAX_TID_COUNT];
472 u8 used, ctxid;
473 struct il_hw_key keyinfo;
474 struct il_link_quality_cmd *lq;
475};
476
477struct il_station_priv_common {
478 struct il_rxon_context *ctx;
479 u8 sta_id;
480};
481
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +0200482/**
483 * struct il_vif_priv - driver's ilate per-interface information
484 *
485 * When mac80211 allocates a virtual interface, it can allocate
486 * space for us to put data into.
487 */
488struct il_vif_priv {
489 struct il_rxon_context *ctx;
490 u8 ibss_bssid_sta_id;
491};
492
493/* one for each uCode image (inst/data, boot/init/runtime) */
494struct fw_desc {
495 void *v_addr; /* access by driver */
496 dma_addr_t p_addr; /* access by card's busmaster DMA */
497 u32 len; /* bytes */
498};
499
500/* uCode file layout */
501struct il_ucode_header {
502 __le32 ver; /* major/minor/API/serial */
503 struct {
504 __le32 inst_size; /* bytes of runtime code */
505 __le32 data_size; /* bytes of runtime data */
506 __le32 init_size; /* bytes of init code */
507 __le32 init_data_size; /* bytes of init data */
508 __le32 boot_size; /* bytes of bootstrap code */
509 u8 data[0]; /* in same order as sizes */
510 } v1;
511};
512
513struct il4965_ibss_seq {
514 u8 mac[ETH_ALEN];
515 u16 seq_num;
516 u16 frag_num;
517 unsigned long packet_time;
518 struct list_head list;
519};
520
521struct il_sensitivity_ranges {
522 u16 min_nrg_cck;
523 u16 max_nrg_cck;
524
525 u16 nrg_th_cck;
526 u16 nrg_th_ofdm;
527
528 u16 auto_corr_min_ofdm;
529 u16 auto_corr_min_ofdm_mrc;
530 u16 auto_corr_min_ofdm_x1;
531 u16 auto_corr_min_ofdm_mrc_x1;
532
533 u16 auto_corr_max_ofdm;
534 u16 auto_corr_max_ofdm_mrc;
535 u16 auto_corr_max_ofdm_x1;
536 u16 auto_corr_max_ofdm_mrc_x1;
537
538 u16 auto_corr_max_cck;
539 u16 auto_corr_max_cck_mrc;
540 u16 auto_corr_min_cck;
541 u16 auto_corr_min_cck_mrc;
542
543 u16 barker_corr_th_min;
544 u16 barker_corr_th_min_mrc;
545 u16 nrg_th_cca;
546};
547
548
549#define KELVIN_TO_CELSIUS(x) ((x)-273)
550#define CELSIUS_TO_KELVIN(x) ((x)+273)
551
552
553/**
554 * struct il_hw_params
555 * @max_txq_num: Max # Tx queues supported
556 * @dma_chnl_num: Number of Tx DMA/FIFO channels
557 * @scd_bc_tbls_size: size of scheduler byte count tables
558 * @tfd_size: TFD size
559 * @tx/rx_chains_num: Number of TX/RX chains
560 * @valid_tx/rx_ant: usable antennas
561 * @max_rxq_size: Max # Rx frames in Rx queue (must be power-of-2)
562 * @max_rxq_log: Log-base-2 of max_rxq_size
563 * @rx_page_order: Rx buffer page order
564 * @rx_wrt_ptr_reg: FH{39}_RSCSR_CHNL0_WPTR
565 * @max_stations:
566 * @ht40_channel: is 40MHz width possible in band 2.4
567 * BIT(IEEE80211_BAND_5GHZ) BIT(IEEE80211_BAND_5GHZ)
568 * @sw_crypto: 0 for hw, 1 for sw
569 * @max_xxx_size: for ucode uses
570 * @ct_kill_threshold: temperature threshold
571 * @beacon_time_tsf_bits: number of valid tsf bits for beacon time
572 * @struct il_sensitivity_ranges: range of sensitivity values
573 */
574struct il_hw_params {
575 u8 max_txq_num;
576 u8 dma_chnl_num;
577 u16 scd_bc_tbls_size;
578 u32 tfd_size;
579 u8 tx_chains_num;
580 u8 rx_chains_num;
581 u8 valid_tx_ant;
582 u8 valid_rx_ant;
583 u16 max_rxq_size;
584 u16 max_rxq_log;
585 u32 rx_page_order;
586 u32 rx_wrt_ptr_reg;
587 u8 max_stations;
588 u8 ht40_channel;
589 u8 max_beacon_itrvl; /* in 1024 ms */
590 u32 max_inst_size;
591 u32 max_data_size;
592 u32 max_bsm_size;
593 u32 ct_kill_threshold; /* value in hw-dependent units */
594 u16 beacon_time_tsf_bits;
595 const struct il_sensitivity_ranges *sens;
596};
597
598
599/******************************************************************************
600 *
601 * Functions implemented in core module which are forward declared here
602 * for use by iwl-[4-5].c
603 *
604 * NOTE: The implementation of these functions are not hardware specific
605 * which is why they are in the core module files.
606 *
607 * Naming convention --
608 * il_ <-- Is part of iwlwifi
609 * iwlXXXX_ <-- Hardware specific (implemented in iwl-XXXX.c for XXXX)
610 * il4965_bg_ <-- Called from work queue context
611 * il4965_mac_ <-- mac80211 callback
612 *
613 ****************************************************************************/
614extern void il4965_update_chain_flags(struct il_priv *il);
615extern const u8 il_bcast_addr[ETH_ALEN];
616extern int il_queue_space(const struct il_queue *q);
617static inline int il_queue_used(const struct il_queue *q, int i)
618{
619 return q->write_ptr >= q->read_ptr ?
620 (i >= q->read_ptr && i < q->write_ptr) :
621 !(i < q->read_ptr && i >= q->write_ptr);
622}
623
624
625static inline u8 il_get_cmd_idx(struct il_queue *q, u32 idx,
626 int is_huge)
627{
628 /*
629 * This is for init calibration result and scan command which
630 * required buffer > TFD_MAX_PAYLOAD_SIZE,
631 * the big buffer at end of command array
632 */
633 if (is_huge)
634 return q->n_win; /* must be power of 2 */
635
636 /* Otherwise, use normal size buffers */
637 return idx & (q->n_win - 1);
638}
639
640
641struct il_dma_ptr {
642 dma_addr_t dma;
643 void *addr;
644 size_t size;
645};
646
647#define IL_OPERATION_MODE_AUTO 0
648#define IL_OPERATION_MODE_HT_ONLY 1
649#define IL_OPERATION_MODE_MIXED 2
650#define IL_OPERATION_MODE_20MHZ 3
651
652#define IL_TX_CRC_SIZE 4
653#define IL_TX_DELIMITER_SIZE 4
654
655#define TX_POWER_IL_ILLEGAL_VOLTAGE -10000
656
657/* Sensitivity and chain noise calibration */
658#define INITIALIZATION_VALUE 0xFFFF
659#define IL4965_CAL_NUM_BEACONS 20
660#define IL_CAL_NUM_BEACONS 16
661#define MAXIMUM_ALLOWED_PATHLOSS 15
662
663#define CHAIN_NOISE_MAX_DELTA_GAIN_CODE 3
664
665#define MAX_FA_OFDM 50
666#define MIN_FA_OFDM 5
667#define MAX_FA_CCK 50
668#define MIN_FA_CCK 5
669
670#define AUTO_CORR_STEP_OFDM 1
671
672#define AUTO_CORR_STEP_CCK 3
673#define AUTO_CORR_MAX_TH_CCK 160
674
675#define NRG_DIFF 2
676#define NRG_STEP_CCK 2
677#define NRG_MARGIN 8
678#define MAX_NUMBER_CCK_NO_FA 100
679
680#define AUTO_CORR_CCK_MIN_VAL_DEF (125)
681
682#define CHAIN_A 0
683#define CHAIN_B 1
684#define CHAIN_C 2
685#define CHAIN_NOISE_DELTA_GAIN_INIT_VAL 4
686#define ALL_BAND_FILTER 0xFF00
687#define IN_BAND_FILTER 0xFF
688#define MIN_AVERAGE_NOISE_MAX_VALUE 0xFFFFFFFF
689
690#define NRG_NUM_PREV_STAT_L 20
691#define NUM_RX_CHAINS 3
692
693enum il4965_false_alarm_state {
694 IL_FA_TOO_MANY = 0,
695 IL_FA_TOO_FEW = 1,
696 IL_FA_GOOD_RANGE = 2,
697};
698
699enum il4965_chain_noise_state {
700 IL_CHAIN_NOISE_ALIVE = 0, /* must be 0 */
701 IL_CHAIN_NOISE_ACCUMULATE,
702 IL_CHAIN_NOISE_CALIBRATED,
703 IL_CHAIN_NOISE_DONE,
704};
705
706enum il4965_calib_enabled_state {
707 IL_CALIB_DISABLED = 0, /* must be 0 */
708 IL_CALIB_ENABLED = 1,
709};
710
711/*
712 * enum il_calib
713 * defines the order in which results of initial calibrations
714 * should be sent to the runtime uCode
715 */
716enum il_calib {
717 IL_CALIB_MAX,
718};
719
720/* Opaque calibration results */
721struct il_calib_result {
722 void *buf;
723 size_t buf_len;
724};
725
726enum ucode_type {
727 UCODE_NONE = 0,
728 UCODE_INIT,
729 UCODE_RT
730};
731
732/* Sensitivity calib data */
733struct il_sensitivity_data {
734 u32 auto_corr_ofdm;
735 u32 auto_corr_ofdm_mrc;
736 u32 auto_corr_ofdm_x1;
737 u32 auto_corr_ofdm_mrc_x1;
738 u32 auto_corr_cck;
739 u32 auto_corr_cck_mrc;
740
741 u32 last_bad_plcp_cnt_ofdm;
742 u32 last_fa_cnt_ofdm;
743 u32 last_bad_plcp_cnt_cck;
744 u32 last_fa_cnt_cck;
745
746 u32 nrg_curr_state;
747 u32 nrg_prev_state;
748 u32 nrg_value[10];
749 u8 nrg_silence_rssi[NRG_NUM_PREV_STAT_L];
750 u32 nrg_silence_ref;
751 u32 nrg_energy_idx;
752 u32 nrg_silence_idx;
753 u32 nrg_th_cck;
754 s32 nrg_auto_corr_silence_diff;
755 u32 num_in_cck_no_fa;
756 u32 nrg_th_ofdm;
757
758 u16 barker_corr_th_min;
759 u16 barker_corr_th_min_mrc;
760 u16 nrg_th_cca;
761};
762
763/* Chain noise (differential Rx gain) calib data */
764struct il_chain_noise_data {
765 u32 active_chains;
766 u32 chain_noise_a;
767 u32 chain_noise_b;
768 u32 chain_noise_c;
769 u32 chain_signal_a;
770 u32 chain_signal_b;
771 u32 chain_signal_c;
772 u16 beacon_count;
773 u8 disconn_array[NUM_RX_CHAINS];
774 u8 delta_gain_code[NUM_RX_CHAINS];
775 u8 radio_write;
776 u8 state;
777};
778
779#define EEPROM_SEM_TIMEOUT 10 /* milliseconds */
780#define EEPROM_SEM_RETRY_LIMIT 1000 /* number of attempts (not time) */
781
782#define IL_TRAFFIC_ENTRIES (256)
783#define IL_TRAFFIC_ENTRY_SIZE (64)
784
785enum {
786 MEASUREMENT_READY = (1 << 0),
787 MEASUREMENT_ACTIVE = (1 << 1),
788};
789
790/* interrupt stats */
791struct isr_stats {
792 u32 hw;
793 u32 sw;
794 u32 err_code;
795 u32 sch;
796 u32 alive;
797 u32 rfkill;
798 u32 ctkill;
799 u32 wakeup;
800 u32 rx;
801 u32 handlers[IL_CN_MAX];
802 u32 tx;
803 u32 unhandled;
804};
805
806/* management stats */
807enum il_mgmt_stats {
808 MANAGEMENT_ASSOC_REQ = 0,
809 MANAGEMENT_ASSOC_RESP,
810 MANAGEMENT_REASSOC_REQ,
811 MANAGEMENT_REASSOC_RESP,
812 MANAGEMENT_PROBE_REQ,
813 MANAGEMENT_PROBE_RESP,
814 MANAGEMENT_BEACON,
815 MANAGEMENT_ATIM,
816 MANAGEMENT_DISASSOC,
817 MANAGEMENT_AUTH,
818 MANAGEMENT_DEAUTH,
819 MANAGEMENT_ACTION,
820 MANAGEMENT_MAX,
821};
822/* control stats */
823enum il_ctrl_stats {
824 CONTROL_BACK_REQ = 0,
825 CONTROL_BACK,
826 CONTROL_PSPOLL,
827 CONTROL_RTS,
828 CONTROL_CTS,
829 CONTROL_ACK,
830 CONTROL_CFEND,
831 CONTROL_CFENDACK,
832 CONTROL_MAX,
833};
834
835struct traffic_stats {
836#ifdef CONFIG_IWLEGACY_DEBUGFS
837 u32 mgmt[MANAGEMENT_MAX];
838 u32 ctrl[CONTROL_MAX];
839 u32 data_cnt;
840 u64 data_bytes;
841#endif
842};
843
844/*
845 * host interrupt timeout value
846 * used with setting interrupt coalescing timer
847 * the CSR_INT_COALESCING is an 8 bit register in 32-usec unit
848 *
849 * default interrupt coalescing timer is 64 x 32 = 2048 usecs
850 * default interrupt coalescing calibration timer is 16 x 32 = 512 usecs
851 */
852#define IL_HOST_INT_TIMEOUT_MAX (0xFF)
853#define IL_HOST_INT_TIMEOUT_DEF (0x40)
854#define IL_HOST_INT_TIMEOUT_MIN (0x0)
855#define IL_HOST_INT_CALIB_TIMEOUT_MAX (0xFF)
856#define IL_HOST_INT_CALIB_TIMEOUT_DEF (0x10)
857#define IL_HOST_INT_CALIB_TIMEOUT_MIN (0x0)
858
859#define IL_DELAY_NEXT_FORCE_FW_RELOAD (HZ*5)
860
861/* TX queue watchdog timeouts in mSecs */
862#define IL_DEF_WD_TIMEOUT (2000)
863#define IL_LONG_WD_TIMEOUT (10000)
864#define IL_MAX_WD_TIMEOUT (120000)
865
866struct il_force_reset {
867 int reset_request_count;
868 int reset_success_count;
869 int reset_reject_count;
870 unsigned long reset_duration;
871 unsigned long last_force_reset_jiffies;
872};
873
874/* extend beacon time format bit shifting */
875/*
876 * for _3945 devices
877 * bits 31:24 - extended
878 * bits 23:0 - interval
879 */
880#define IL3945_EXT_BEACON_TIME_POS 24
881/*
882 * for _4965 devices
883 * bits 31:22 - extended
884 * bits 21:0 - interval
885 */
886#define IL4965_EXT_BEACON_TIME_POS 22
887
888struct il_rxon_context {
889 struct ieee80211_vif *vif;
890
891 const u8 *ac_to_fifo;
892 const u8 *ac_to_queue;
893 u8 mcast_queue;
894
895 /*
896 * We could use the vif to indicate active, but we
897 * also need it to be active during disabling when
898 * we already removed the vif for type setting.
899 */
900 bool always_active, is_active;
901
902 bool ht_need_multiple_chains;
903
904 int ctxid;
905
906 u32 interface_modes, exclusive_interface_modes;
907 u8 unused_devtype, ap_devtype, ibss_devtype, station_devtype;
908
909 /*
910 * We declare this const so it can only be
911 * changed via explicit cast within the
912 * routines that actually update the physical
913 * hardware.
914 */
915 const struct il_rxon_cmd active;
916 struct il_rxon_cmd staging;
917
918 struct il_rxon_time_cmd timing;
919
920 struct il_qos_info qos_data;
921
922 u8 bcast_sta_id, ap_sta_id;
923
924 u8 rxon_cmd, rxon_assoc_cmd, rxon_timing_cmd;
925 u8 qos_cmd;
926 u8 wep_key_cmd;
927
928 struct il_wep_key wep_keys[WEP_KEYS_MAX];
929 u8 key_mapping_keys;
930
931 __le32 station_flags;
932
933 struct {
934 bool non_gf_sta_present;
935 u8 protection;
936 bool enabled, is_40mhz;
937 u8 extension_chan_offset;
938 } ht;
939};
940
Stanislaw Gruszka99412002011-08-31 13:53:04 +0200941struct il_power_mgr {
942 struct il_powertable_cmd sleep_cmd;
943 struct il_powertable_cmd sleep_cmd_next;
944 int debug_sleep_level_override;
945 bool pci_pm;
946};
947
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +0200948struct il_priv {
949
950 /* ieee device used by generic ieee processing code */
951 struct ieee80211_hw *hw;
952 struct ieee80211_channel *ieee_channels;
953 struct ieee80211_rate *ieee_rates;
954 struct il_cfg *cfg;
955
956 /* temporary frame storage list */
957 struct list_head free_frames;
958 int frames_count;
959
960 enum ieee80211_band band;
961 int alloc_rxb_page;
962
963 void (*handlers[IL_CN_MAX])(struct il_priv *il,
964 struct il_rx_buf *rxb);
965
966 struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
967
968 /* spectrum measurement report caching */
969 struct il_spectrum_notification measure_report;
970 u8 measurement_status;
971
972 /* ucode beacon time */
973 u32 ucode_beacon_time;
974 int missed_beacon_threshold;
975
976 /* track IBSS manager (last beacon) status */
977 u32 ibss_manager;
978
979 /* force reset */
980 struct il_force_reset force_reset;
981
982 /* we allocate array of il_channel_info for NIC's valid channels.
983 * Access via channel # using indirect idx array */
984 struct il_channel_info *channel_info; /* channel info array */
985 u8 channel_count; /* # of channels */
986
987 /* thermal calibration */
988 s32 temperature; /* degrees Kelvin */
989 s32 last_temperature;
990
991 /* init calibration results */
992 struct il_calib_result calib_results[IL_CALIB_MAX];
993
994 /* Scan related variables */
995 unsigned long scan_start;
996 unsigned long scan_start_tsf;
997 void *scan_cmd;
998 enum ieee80211_band scan_band;
999 struct cfg80211_scan_request *scan_request;
1000 struct ieee80211_vif *scan_vif;
1001 u8 scan_tx_ant[IEEE80211_NUM_BANDS];
1002 u8 mgmt_tx_ant;
1003
1004 /* spinlock */
1005 spinlock_t lock; /* protect general shared data */
1006 spinlock_t hcmd_lock; /* protect hcmd */
1007 spinlock_t reg_lock; /* protect hw register access */
1008 struct mutex mutex;
1009
1010 /* basic pci-network driver stuff */
1011 struct pci_dev *pci_dev;
1012
1013 /* pci hardware address support */
1014 void __iomem *hw_base;
1015 u32 hw_rev;
1016 u32 hw_wa_rev;
1017 u8 rev_id;
1018
1019 /* command queue number */
1020 u8 cmd_queue;
1021
1022 /* max number of station keys */
1023 u8 sta_key_max_num;
1024
1025 /* EEPROM MAC addresses */
1026 struct mac_address addresses[1];
1027
1028 /* uCode images, save to reload in case of failure */
1029 int fw_idx; /* firmware we're trying to load */
1030 u32 ucode_ver; /* version of ucode, copy of
1031 il_ucode.ver */
1032 struct fw_desc ucode_code; /* runtime inst */
1033 struct fw_desc ucode_data; /* runtime data original */
1034 struct fw_desc ucode_data_backup; /* runtime data save/restore */
1035 struct fw_desc ucode_init; /* initialization inst */
1036 struct fw_desc ucode_init_data; /* initialization data */
1037 struct fw_desc ucode_boot; /* bootstrap inst */
1038 enum ucode_type ucode_type;
1039 u8 ucode_write_complete; /* the image write is complete */
1040 char firmware_name[25];
1041
1042 struct il_rxon_context ctx;
1043
1044 __le16 switch_channel;
1045
1046 /* 1st responses from initialize and runtime uCode images.
1047 * _4965's initialize alive response contains some calibration data. */
1048 struct il_init_alive_resp card_alive_init;
1049 struct il_alive_resp card_alive;
1050
1051 u16 active_rate;
1052
1053 u8 start_calib;
1054 struct il_sensitivity_data sensitivity_data;
1055 struct il_chain_noise_data chain_noise_data;
1056 __le16 sensitivity_tbl[HD_TBL_SIZE];
1057
1058 struct il_ht_config current_ht_config;
1059
1060 /* Rate scaling data */
1061 u8 retry_rate;
1062
1063 wait_queue_head_t wait_command_queue;
1064
1065 int activity_timer_active;
1066
1067 /* Rx and Tx DMA processing queues */
1068 struct il_rx_queue rxq;
1069 struct il_tx_queue *txq;
1070 unsigned long txq_ctx_active_msk;
1071 struct il_dma_ptr kw; /* keep warm address */
1072 struct il_dma_ptr scd_bc_tbls;
1073
1074 u32 scd_base_addr; /* scheduler sram base address */
1075
1076 unsigned long status;
1077
1078 /* counts mgmt, ctl, and data packets */
1079 struct traffic_stats tx_stats;
1080 struct traffic_stats rx_stats;
1081
1082 /* counts interrupts */
1083 struct isr_stats isr_stats;
1084
1085 struct il_power_mgr power_data;
1086
1087 /* context information */
1088 u8 bssid[ETH_ALEN]; /* used only on 3945 but filled by core */
1089
1090 /* station table variables */
1091
1092 /* Note: if lock and sta_lock are needed, lock must be acquired first */
1093 spinlock_t sta_lock;
1094 int num_stations;
1095 struct il_station_entry stations[IL_STATION_COUNT];
1096 unsigned long ucode_key_table;
1097
1098 /* queue refcounts */
1099#define IL_MAX_HW_QUEUES 32
1100 unsigned long queue_stopped[BITS_TO_LONGS(IL_MAX_HW_QUEUES)];
1101 /* for each AC */
1102 atomic_t queue_stop_count[4];
1103
1104 /* Indication if ieee80211_ops->open has been called */
1105 u8 is_open;
1106
1107 u8 mac80211_registered;
1108
1109 /* eeprom -- this is in the card's little endian byte order */
1110 u8 *eeprom;
1111 struct il_eeprom_calib_info *calib_info;
1112
1113 enum nl80211_iftype iw_mode;
1114
1115 /* Last Rx'd beacon timestamp */
1116 u64 timestamp;
1117
1118 union {
1119#if defined(CONFIG_IWL3945) || defined(CONFIG_IWL3945_MODULE)
1120 struct {
1121 void *shared_virt;
1122 dma_addr_t shared_phys;
1123
1124 struct delayed_work thermal_periodic;
1125 struct delayed_work rfkill_poll;
1126
1127 struct il3945_notif_stats stats;
1128#ifdef CONFIG_IWLEGACY_DEBUGFS
1129 struct il3945_notif_stats accum_stats;
1130 struct il3945_notif_stats delta_stats;
1131 struct il3945_notif_stats max_delta;
1132#endif
1133
1134 u32 sta_supp_rates;
1135 int last_rx_rssi; /* From Rx packet stats */
1136
1137 /* Rx'd packet timing information */
1138 u32 last_beacon_time;
1139 u64 last_tsf;
1140
1141 /*
1142 * each calibration channel group in the
1143 * EEPROM has a derived clip setting for
1144 * each rate.
1145 */
1146 const struct il3945_clip_group clip_groups[5];
1147
1148 } _3945;
1149#endif
1150#if defined(CONFIG_IWL4965) || defined(CONFIG_IWL4965_MODULE)
1151 struct {
1152 struct il_rx_phy_res last_phy_res;
1153 bool last_phy_res_valid;
1154
1155 struct completion firmware_loading_complete;
1156
1157 /*
1158 * chain noise reset and gain commands are the
1159 * two extra calibration commands follows the standard
1160 * phy calibration commands
1161 */
1162 u8 phy_calib_chain_noise_reset_cmd;
1163 u8 phy_calib_chain_noise_gain_cmd;
1164
1165 struct il_notif_stats stats;
1166#ifdef CONFIG_IWLEGACY_DEBUGFS
1167 struct il_notif_stats accum_stats;
1168 struct il_notif_stats delta_stats;
1169 struct il_notif_stats max_delta;
1170#endif
1171
1172 } _4965;
1173#endif
1174 };
1175
1176 struct il_hw_params hw_params;
1177
1178 u32 inta_mask;
1179
1180 struct workqueue_struct *workqueue;
1181
1182 struct work_struct restart;
1183 struct work_struct scan_completed;
1184 struct work_struct rx_replenish;
1185 struct work_struct abort_scan;
1186
1187 struct il_rxon_context *beacon_ctx;
1188 struct sk_buff *beacon_skb;
1189
1190 struct work_struct tx_flush;
1191
1192 struct tasklet_struct irq_tasklet;
1193
1194 struct delayed_work init_alive_start;
1195 struct delayed_work alive_start;
1196 struct delayed_work scan_check;
1197
1198 /* TX Power */
1199 s8 tx_power_user_lmt;
1200 s8 tx_power_device_lmt;
1201 s8 tx_power_next;
1202
1203
1204#ifdef CONFIG_IWLEGACY_DEBUG
1205 /* debugging info */
1206 u32 debug_level; /* per device debugging will override global
1207 il_debug_level if set */
1208#endif /* CONFIG_IWLEGACY_DEBUG */
1209#ifdef CONFIG_IWLEGACY_DEBUGFS
1210 /* debugfs */
1211 u16 tx_traffic_idx;
1212 u16 rx_traffic_idx;
1213 u8 *tx_traffic;
1214 u8 *rx_traffic;
1215 struct dentry *debugfs_dir;
1216 u32 dbgfs_sram_offset, dbgfs_sram_len;
1217 bool disable_ht40;
1218#endif /* CONFIG_IWLEGACY_DEBUGFS */
1219
1220 struct work_struct txpower_work;
1221 u32 disable_sens_cal;
1222 u32 disable_chain_noise_cal;
1223 u32 disable_tx_power_cal;
1224 struct work_struct run_time_calib_work;
1225 struct timer_list stats_periodic;
1226 struct timer_list watchdog;
1227 bool hw_ready;
1228
1229 struct led_classdev led;
1230 unsigned long blink_on, blink_off;
1231 bool led_registered;
1232}; /*il_priv */
1233
1234static inline void il_txq_ctx_activate(struct il_priv *il, int txq_id)
1235{
1236 set_bit(txq_id, &il->txq_ctx_active_msk);
1237}
1238
1239static inline void il_txq_ctx_deactivate(struct il_priv *il, int txq_id)
1240{
1241 clear_bit(txq_id, &il->txq_ctx_active_msk);
1242}
1243
1244#ifdef CONFIG_IWLEGACY_DEBUG
1245/*
1246 * il_get_debug_level: Return active debug level for device
1247 *
1248 * Using sysfs it is possible to set per device debug level. This debug
1249 * level will be used if set, otherwise the global debug level which can be
1250 * set via module parameter is used.
1251 */
1252static inline u32 il_get_debug_level(struct il_priv *il)
1253{
1254 if (il->debug_level)
1255 return il->debug_level;
1256 else
1257 return il_debug_level;
1258}
1259#else
1260static inline u32 il_get_debug_level(struct il_priv *il)
1261{
1262 return il_debug_level;
1263}
1264#endif
1265
1266
1267static inline struct ieee80211_hdr *
1268il_tx_queue_get_hdr(struct il_priv *il,
1269 int txq_id, int idx)
1270{
1271 if (il->txq[txq_id].txb[idx].skb)
1272 return (struct ieee80211_hdr *)il->txq[txq_id].
1273 txb[idx].skb->data;
1274 return NULL;
1275}
1276
1277static inline struct il_rxon_context *
1278il_rxon_ctx_from_vif(struct ieee80211_vif *vif)
1279{
1280 struct il_vif_priv *vif_priv = (void *)vif->drv_priv;
1281
1282 return vif_priv->ctx;
1283}
1284
1285#define for_each_context(il, _ctx) \
1286 for (_ctx = &il->ctx; _ctx == &il->ctx; _ctx++)
1287
1288static inline int il_is_associated(struct il_priv *il)
1289{
1290 return (il->ctx.active.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0;
1291}
1292
1293static inline int il_is_any_associated(struct il_priv *il)
1294{
1295 return il_is_associated(il);
1296}
1297
1298static inline int il_is_associated_ctx(struct il_rxon_context *ctx)
1299{
1300 return (ctx->active.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0;
1301}
1302
1303static inline int il_is_channel_valid(const struct il_channel_info *ch_info)
1304{
1305 if (ch_info == NULL)
1306 return 0;
1307 return (ch_info->flags & EEPROM_CHANNEL_VALID) ? 1 : 0;
1308}
1309
1310static inline int il_is_channel_radar(const struct il_channel_info *ch_info)
1311{
1312 return (ch_info->flags & EEPROM_CHANNEL_RADAR) ? 1 : 0;
1313}
1314
1315static inline u8 il_is_channel_a_band(const struct il_channel_info *ch_info)
1316{
1317 return ch_info->band == IEEE80211_BAND_5GHZ;
1318}
1319
1320static inline int
1321il_is_channel_passive(const struct il_channel_info *ch)
1322{
1323 return (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) ? 1 : 0;
1324}
1325
1326static inline int
1327il_is_channel_ibss(const struct il_channel_info *ch)
1328{
1329 return (ch->flags & EEPROM_CHANNEL_IBSS) ? 1 : 0;
1330}
1331
1332static inline void
1333__il_free_pages(struct il_priv *il, struct page *page)
1334{
1335 __free_pages(page, il->hw_params.rx_page_order);
1336 il->alloc_rxb_page--;
1337}
1338
1339static inline void il_free_pages(struct il_priv *il, unsigned long page)
1340{
1341 free_pages(page, il->hw_params.rx_page_order);
1342 il->alloc_rxb_page--;
1343}
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001344
1345#define IWLWIFI_VERSION "in-tree:"
1346#define DRV_COPYRIGHT "Copyright(c) 2003-2011 Intel Corporation"
1347#define DRV_AUTHOR "<ilw@linux.intel.com>"
1348
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001349#define IL_PCI_DEVICE(dev, subdev, cfg) \
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001350 .vendor = PCI_VENDOR_ID_INTEL, .device = (dev), \
1351 .subvendor = PCI_ANY_ID, .subdevice = (subdev), \
1352 .driver_data = (kernel_ulong_t)&(cfg)
1353
1354#define TIME_UNIT 1024
1355
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001356#define IL_SKU_G 0x1
1357#define IL_SKU_A 0x2
1358#define IL_SKU_N 0x8
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001359
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001360#define IL_CMD(x) case x: return #x
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001361
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +02001362/* Size of one Rx buffer in host DRAM */
1363#define IL_RX_BUF_SIZE_3K (3 * 1000) /* 3945 only */
1364#define IL_RX_BUF_SIZE_4K (4 * 1024)
1365#define IL_RX_BUF_SIZE_8K (8 * 1024)
1366
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001367struct il_hcmd_ops {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001368 int (*rxon_assoc)(struct il_priv *il, struct il_rxon_context *ctx);
1369 int (*commit_rxon)(struct il_priv *il, struct il_rxon_context *ctx);
1370 void (*set_rxon_chain)(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001371 struct il_rxon_context *ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001372};
1373
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001374struct il_hcmd_utils_ops {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001375 u16 (*get_hcmd_size)(u8 cmd_id, u16 len);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001376 u16 (*build_addsta_hcmd)(const struct il_addsta_cmd *cmd,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001377 u8 *data);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001378 int (*request_scan)(struct il_priv *il, struct ieee80211_vif *vif);
1379 void (*post_scan)(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001380};
1381
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001382struct il_apm_ops {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001383 int (*init)(struct il_priv *il);
1384 void (*config)(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001385};
1386
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001387struct il_debugfs_ops {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001388 ssize_t (*rx_stats_read)(struct file *file, char __user *user_buf,
1389 size_t count, loff_t *ppos);
1390 ssize_t (*tx_stats_read)(struct file *file, char __user *user_buf,
1391 size_t count, loff_t *ppos);
1392 ssize_t (*general_stats_read)(struct file *file, char __user *user_buf,
1393 size_t count, loff_t *ppos);
1394};
1395
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001396struct il_temp_ops {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001397 void (*temperature)(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001398};
1399
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001400struct il_lib_ops {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001401 /* set hw dependent parameters */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001402 int (*set_hw_params)(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001403 /* Handling TX */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001404 void (*txq_update_byte_cnt_tbl)(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001405 struct il_tx_queue *txq,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001406 u16 byte_cnt);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001407 int (*txq_attach_buf_to_tfd)(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001408 struct il_tx_queue *txq,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001409 dma_addr_t addr,
1410 u16 len, u8 reset, u8 pad);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001411 void (*txq_free_tfd)(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001412 struct il_tx_queue *txq);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001413 int (*txq_init)(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001414 struct il_tx_queue *txq);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001415 /* setup Rx handler */
Stanislaw Gruszkad0c72342011-08-30 15:39:42 +02001416 void (*handler_setup)(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001417 /* alive notification after init uCode load */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001418 void (*init_alive_start)(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001419 /* check validity of rtc data address */
1420 int (*is_valid_rtc_data_addr)(u32 addr);
1421 /* 1st ucode load */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001422 int (*load_ucode)(struct il_priv *il);
Stanislaw Gruszka1ba2f122011-06-08 15:28:27 +02001423
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001424 void (*dump_nic_error_log)(struct il_priv *il);
1425 int (*dump_fh)(struct il_priv *il, char **buf, bool display);
1426 int (*set_channel_switch)(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001427 struct ieee80211_channel_switch *ch_switch);
1428 /* power management */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001429 struct il_apm_ops apm_ops;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001430
1431 /* power */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001432 int (*send_tx_power) (struct il_priv *il);
1433 void (*update_chain_flags)(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001434
1435 /* eeprom operations (as defined in iwl-eeprom.h) */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001436 struct il_eeprom_ops eeprom_ops;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001437
1438 /* temperature */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001439 struct il_temp_ops temp_ops;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001440
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001441 struct il_debugfs_ops debugfs_ops;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001442
1443};
1444
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001445struct il_led_ops {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001446 int (*cmd)(struct il_priv *il, struct il_led_cmd *led_cmd);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001447};
1448
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001449struct il_legacy_ops {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001450 void (*post_associate)(struct il_priv *il);
1451 void (*config_ap)(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001452 /* station management */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001453 int (*update_bcast_stations)(struct il_priv *il);
1454 int (*manage_ibss_station)(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001455 struct ieee80211_vif *vif, bool add);
1456};
1457
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001458struct il_ops {
1459 const struct il_lib_ops *lib;
1460 const struct il_hcmd_ops *hcmd;
1461 const struct il_hcmd_utils_ops *utils;
1462 const struct il_led_ops *led;
1463 const struct il_nic_ops *nic;
1464 const struct il_legacy_ops *legacy;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001465 const struct ieee80211_ops *ieee80211_ops;
1466};
1467
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001468struct il_mod_params {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001469 int sw_crypto; /* def: 0 = using hardware encryption */
1470 int disable_hw_scan; /* def: 0 = use h/w scan */
1471 int num_of_queues; /* def: HW dependent */
1472 int disable_11n; /* def: 0 = 11n capabilities enabled */
1473 int amsdu_size_8K; /* def: 1 = enable 8K amsdu size */
1474 int antenna; /* def: 0 = both antennas (use diversity) */
1475 int restart_fw; /* def: 1 = restart firmware */
1476};
1477
1478/*
1479 * @led_compensation: compensate on the led on/off time per HW according
1480 * to the deviation to achieve the desired led frequency.
1481 * The detail algorithm is described in iwl-led.c
1482 * @chain_noise_num_beacons: number of beacons used to compute chain noise
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001483 * @wd_timeout: TX queues watchdog timeout
1484 * @temperature_kelvin: temperature report by uCode in kelvin
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001485 * @ucode_tracing: support ucode continuous tracing
1486 * @sensitivity_calib_by_driver: driver has the capability to perform
1487 * sensitivity calibration operation
1488 * @chain_noise_calib_by_driver: driver has the capability to perform
1489 * chain noise calibration operation
1490 */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001491struct il_base_params {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001492 int eeprom_size;
1493 int num_of_queues; /* def: HW dependent */
1494 int num_of_ampdu_queues;/* def: HW dependent */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001495 /* for il_apm_init() */
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001496 u32 pll_cfg_val;
1497 bool set_l0s;
1498 bool use_bsm;
1499
1500 u16 led_compensation;
1501 int chain_noise_num_beacons;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001502 unsigned int wd_timeout;
1503 bool temperature_kelvin;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001504 const bool ucode_tracing;
1505 const bool sensitivity_calib_by_driver;
1506 const bool chain_noise_calib_by_driver;
1507};
1508
1509/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001510 * struct il_cfg
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001511 * @fw_name_pre: Firmware filename prefix. The api version and extension
1512 * (.ucode) will be added to filename before loading from disk. The
1513 * filename is constructed as fw_name_pre<api>.ucode.
1514 * @ucode_api_max: Highest version of uCode API supported by driver.
1515 * @ucode_api_min: Lowest version of uCode API supported by driver.
1516 * @scan_antennas: available antenna for scan operation
1517 * @led_mode: 0=blinking, 1=On(RF On)/Off(RF Off)
1518 *
1519 * We enable the driver to be backward compatible wrt API version. The
1520 * driver specifies which APIs it supports (with @ucode_api_max being the
1521 * highest and @ucode_api_min the lowest). Firmware will only be loaded if
1522 * it has a supported API version. The firmware's API version will be
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001523 * stored in @il_priv, enabling the driver to make runtime changes based
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001524 * on firmware version used.
1525 *
1526 * For example,
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001527 * if (IL_UCODE_API(il->ucode_ver) >= 2) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001528 * Driver interacts with Firmware API version >= 2.
1529 * } else {
1530 * Driver interacts with Firmware API version 1.
1531 * }
1532 *
1533 * The ideal usage of this infrastructure is to treat a new ucode API
1534 * release as a new hardware revision. That is, through utilizing the
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001535 * il_hcmd_utils_ops etc. we accommodate different command structures
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001536 * and flows between hardware versions as well as their API
1537 * versions.
1538 *
1539 */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001540struct il_cfg {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001541 /* params specific to an individual device within a device family */
1542 const char *name;
1543 const char *fw_name_pre;
1544 const unsigned int ucode_api_max;
1545 const unsigned int ucode_api_min;
1546 u8 valid_tx_ant;
1547 u8 valid_rx_ant;
1548 unsigned int sku;
1549 u16 eeprom_ver;
1550 u16 eeprom_calib_ver;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001551 const struct il_ops *ops;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001552 /* module based parameters which can be set from modprobe cmd */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001553 const struct il_mod_params *mod_params;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001554 /* params not likely to change within a device family */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001555 struct il_base_params *base_params;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001556 /* params likely to change within a device family */
1557 u8 scan_rx_antennas[IEEE80211_NUM_BANDS];
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001558 enum il_led_mode led_mode;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001559};
1560
1561/***************************
1562 * L i b *
1563 ***************************/
1564
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001565struct ieee80211_hw *il_alloc_all(struct il_cfg *cfg);
1566int il_mac_conf_tx(struct ieee80211_hw *hw,
Eliad Peller8a3a3c82011-10-02 10:15:52 +02001567 struct ieee80211_vif *vif, u16 queue,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001568 const struct ieee80211_tx_queue_params *params);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001569int il_mac_tx_last_beacon(struct ieee80211_hw *hw);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001570void il_set_rxon_hwcrypto(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001571 struct il_rxon_context *ctx,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001572 int hw_decrypt);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001573int il_check_rxon_cmd(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001574 struct il_rxon_context *ctx);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001575int il_full_rxon_required(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001576 struct il_rxon_context *ctx);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001577int il_set_rxon_channel(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001578 struct ieee80211_channel *ch,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001579 struct il_rxon_context *ctx);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001580void il_set_flags_for_band(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001581 struct il_rxon_context *ctx,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001582 enum ieee80211_band band,
1583 struct ieee80211_vif *vif);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001584u8 il_get_single_channel_number(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001585 enum ieee80211_band band);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001586void il_set_rxon_ht(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001587 struct il_ht_config *ht_conf);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001588bool il_is_ht40_tx_allowed(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001589 struct il_rxon_context *ctx,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001590 struct ieee80211_sta_ht_cap *ht_cap);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001591void il_connection_init_rx_config(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001592 struct il_rxon_context *ctx);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001593void il_set_rate(struct il_priv *il);
1594int il_set_decrypted_flag(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001595 struct ieee80211_hdr *hdr,
1596 u32 decrypt_res,
1597 struct ieee80211_rx_status *stats);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001598void il_irq_handle_error(struct il_priv *il);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001599int il_mac_add_interface(struct ieee80211_hw *hw,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001600 struct ieee80211_vif *vif);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001601void il_mac_remove_interface(struct ieee80211_hw *hw,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001602 struct ieee80211_vif *vif);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001603int il_mac_change_interface(struct ieee80211_hw *hw,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001604 struct ieee80211_vif *vif,
1605 enum nl80211_iftype newtype, bool newp2p);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001606int il_alloc_txq_mem(struct il_priv *il);
1607void il_txq_mem(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001608
Stanislaw Gruszkad3175162011-11-15 11:25:42 +01001609#ifdef CONFIG_IWLEGACY_DEBUGFS
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001610int il_alloc_traffic_mem(struct il_priv *il);
1611void il_free_traffic_mem(struct il_priv *il);
1612void il_reset_traffic_log(struct il_priv *il);
1613void il_dbg_log_tx_data_frame(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001614 u16 length, struct ieee80211_hdr *header);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001615void il_dbg_log_rx_data_frame(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001616 u16 length, struct ieee80211_hdr *header);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001617const char *il_get_mgmt_string(int cmd);
1618const char *il_get_ctrl_string(int cmd);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001619void il_clear_traffic_stats(struct il_priv *il);
1620void il_update_stats(struct il_priv *il, bool is_tx, __le16 fc,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001621 u16 len);
1622#else
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001623static inline int il_alloc_traffic_mem(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001624{
1625 return 0;
1626}
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001627static inline void il_free_traffic_mem(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001628{
1629}
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001630static inline void il_reset_traffic_log(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001631{
1632}
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001633static inline void il_dbg_log_tx_data_frame(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001634 u16 length, struct ieee80211_hdr *header)
1635{
1636}
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001637static inline void il_dbg_log_rx_data_frame(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001638 u16 length, struct ieee80211_hdr *header)
1639{
1640}
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001641static inline void il_update_stats(struct il_priv *il, bool is_tx,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001642 __le16 fc, u16 len)
1643{
1644}
1645#endif
1646/*****************************************************
1647 * RX handlers.
1648 * **************************************************/
Stanislaw Gruszkad2dfb332011-11-15 13:16:38 +01001649void il_hdl_pm_sleep(struct il_priv *il,
Stanislaw Gruszkab73bb5f2011-08-26 14:37:54 +02001650 struct il_rx_buf *rxb);
Stanislaw Gruszkad2dfb332011-11-15 13:16:38 +01001651void il_hdl_pm_debug_stats(struct il_priv *il,
Stanislaw Gruszkab73bb5f2011-08-26 14:37:54 +02001652 struct il_rx_buf *rxb);
Stanislaw Gruszka6e9848b42011-08-30 15:45:31 +02001653void il_hdl_error(struct il_priv *il,
Stanislaw Gruszkab73bb5f2011-08-26 14:37:54 +02001654 struct il_rx_buf *rxb);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001655
1656/*****************************************************
1657* RX
1658******************************************************/
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001659void il_cmd_queue_unmap(struct il_priv *il);
1660void il_cmd_queue_free(struct il_priv *il);
1661int il_rx_queue_alloc(struct il_priv *il);
1662void il_rx_queue_update_write_ptr(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001663 struct il_rx_queue *q);
1664int il_rx_queue_space(const struct il_rx_queue *q);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001665void il_tx_cmd_complete(struct il_priv *il,
Stanislaw Gruszkab73bb5f2011-08-26 14:37:54 +02001666 struct il_rx_buf *rxb);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001667/* Handlers */
Stanislaw Gruszkad2dfb332011-11-15 13:16:38 +01001668void il_hdl_spectrum_measurement(struct il_priv *il,
Stanislaw Gruszkab73bb5f2011-08-26 14:37:54 +02001669 struct il_rx_buf *rxb);
Stanislaw Gruszkaebf0d902011-08-26 15:43:47 +02001670void il_recover_from_stats(struct il_priv *il,
Stanislaw Gruszkadcae1c62011-08-26 14:36:21 +02001671 struct il_rx_pkt *pkt);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001672void il_chswitch_done(struct il_priv *il, bool is_success);
Stanislaw Gruszkad2dfb332011-11-15 13:16:38 +01001673void il_hdl_csa(struct il_priv *il, struct il_rx_buf *rxb);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001674
1675/* TX helpers */
1676
1677/*****************************************************
1678* TX
1679******************************************************/
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001680void il_txq_update_write_ptr(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001681 struct il_tx_queue *txq);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001682int il_tx_queue_init(struct il_priv *il, struct il_tx_queue *txq,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001683 int slots_num, u32 txq_id);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001684void il_tx_queue_reset(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001685 struct il_tx_queue *txq,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001686 int slots_num, u32 txq_id);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001687void il_tx_queue_unmap(struct il_priv *il, int txq_id);
1688void il_tx_queue_free(struct il_priv *il, int txq_id);
1689void il_setup_watchdog(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001690/*****************************************************
1691 * TX power
1692 ****************************************************/
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001693int il_set_tx_power(struct il_priv *il, s8 tx_power, bool force);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001694
1695/*******************************************************************************
1696 * Rate
1697 ******************************************************************************/
1698
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001699u8 il_get_lowest_plcp(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001700 struct il_rxon_context *ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001701
1702/*******************************************************************************
1703 * Scanning
1704 ******************************************************************************/
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001705void il_init_scan_params(struct il_priv *il);
1706int il_scan_cancel(struct il_priv *il);
1707int il_scan_cancel_timeout(struct il_priv *il, unsigned long ms);
1708void il_force_scan_end(struct il_priv *il);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001709int il_mac_hw_scan(struct ieee80211_hw *hw,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001710 struct ieee80211_vif *vif,
1711 struct cfg80211_scan_request *req);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001712void il_internal_short_hw_scan(struct il_priv *il);
1713int il_force_reset(struct il_priv *il, bool external);
1714u16 il_fill_probe_req(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001715 struct ieee80211_mgmt *frame,
1716 const u8 *ta, const u8 *ie, int ie_len, int left);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001717void il_setup_rx_scan_handlers(struct il_priv *il);
1718u16 il_get_active_dwell_time(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001719 enum ieee80211_band band,
1720 u8 n_probes);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001721u16 il_get_passive_dwell_time(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001722 enum ieee80211_band band,
1723 struct ieee80211_vif *vif);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001724void il_setup_scan_deferred_work(struct il_priv *il);
1725void il_cancel_scan_deferred_work(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001726
1727/* For faster active scanning, scan will move to the next channel if fewer than
1728 * PLCP_QUIET_THRESH packets are heard on this channel within
1729 * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
1730 * time if it's a quiet channel (nothing responded to our probe, and there's
1731 * no other traffic).
1732 * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001733#define IL_ACTIVE_QUIET_TIME cpu_to_le16(10) /* msec */
1734#define IL_PLCP_QUIET_THRESH cpu_to_le16(1) /* packets */
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001735
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001736#define IL_SCAN_CHECK_WATCHDOG (HZ * 7)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001737
1738/*****************************************************
1739 * S e n d i n g H o s t C o m m a n d s *
1740 *****************************************************/
1741
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001742const char *il_get_cmd_string(u8 cmd);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001743int __must_check il_send_cmd_sync(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001744 struct il_host_cmd *cmd);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001745int il_send_cmd(struct il_priv *il, struct il_host_cmd *cmd);
1746int __must_check il_send_cmd_pdu(struct il_priv *il, u8 id,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001747 u16 len, const void *data);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001748int il_send_cmd_pdu_async(struct il_priv *il, u8 id, u16 len,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001749 const void *data,
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001750 void (*callback)(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001751 struct il_device_cmd *cmd,
Stanislaw Gruszkadcae1c62011-08-26 14:36:21 +02001752 struct il_rx_pkt *pkt));
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001753
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001754int il_enqueue_hcmd(struct il_priv *il, struct il_host_cmd *cmd);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001755
1756
1757/*****************************************************
1758 * PCI *
1759 *****************************************************/
1760
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001761static inline u16 il_pcie_link_ctl(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001762{
1763 int pos;
1764 u16 pci_lnk_ctl;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001765 pos = pci_pcie_cap(il->pci_dev);
1766 pci_read_config_word(il->pci_dev, pos + PCI_EXP_LNKCTL, &pci_lnk_ctl);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001767 return pci_lnk_ctl;
1768}
1769
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001770void il_bg_watchdog(unsigned long data);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001771u32 il_usecs_to_beacons(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001772 u32 usec, u32 beacon_interval);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001773__le32 il_add_beacon_time(struct il_priv *il, u32 base,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001774 u32 addon, u32 beacon_interval);
1775
1776#ifdef CONFIG_PM
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001777int il_pci_suspend(struct device *device);
1778int il_pci_resume(struct device *device);
1779extern const struct dev_pm_ops il_pm_ops;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001780
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001781#define IL_LEGACY_PM_OPS (&il_pm_ops)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001782
1783#else /* !CONFIG_PM */
1784
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001785#define IL_LEGACY_PM_OPS NULL
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001786
1787#endif /* !CONFIG_PM */
1788
1789/*****************************************************
1790* Error Handling Debugging
1791******************************************************/
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001792void il4965_dump_nic_error_log(struct il_priv *il);
Stanislaw Gruszkad3175162011-11-15 11:25:42 +01001793#ifdef CONFIG_IWLEGACY_DEBUG
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001794void il_print_rx_config_cmd(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001795 struct il_rxon_context *ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001796#else
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001797static inline void il_print_rx_config_cmd(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001798 struct il_rxon_context *ctx)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001799{
1800}
1801#endif
1802
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001803void il_clear_isr_stats(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001804
1805/*****************************************************
1806* GEOS
1807******************************************************/
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001808int il_init_geos(struct il_priv *il);
1809void il_free_geos(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001810
1811/*************** DRIVER STATUS FUNCTIONS *****/
1812
Stanislaw Gruszkaa6766cc2011-11-15 13:09:01 +01001813#define S_HCMD_ACTIVE 0 /* host command in progress */
1814/* 1 is unused (used to be S_HCMD_SYNC_ACTIVE) */
1815#define S_INT_ENABLED 2
1816#define S_RF_KILL_HW 3
1817#define S_CT_KILL 4
1818#define S_INIT 5
1819#define S_ALIVE 6
1820#define S_READY 7
1821#define S_TEMPERATURE 8
1822#define S_GEO_CONFIGURED 9
1823#define S_EXIT_PENDING 10
Stanislaw Gruszkadb7746f2011-11-15 13:11:50 +01001824#define S_STATS 12
Stanislaw Gruszkaa6766cc2011-11-15 13:09:01 +01001825#define S_SCANNING 13
1826#define S_SCAN_ABORTING 14
1827#define S_SCAN_HW 15
1828#define S_POWER_PMI 16
1829#define S_FW_ERROR 17
1830#define S_CHANNEL_SWITCH_PENDING 18
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001831
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001832static inline int il_is_ready(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001833{
1834 /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are
1835 * set but EXIT_PENDING is not */
Stanislaw Gruszkaa6766cc2011-11-15 13:09:01 +01001836 return test_bit(S_READY, &il->status) &&
1837 test_bit(S_GEO_CONFIGURED, &il->status) &&
1838 !test_bit(S_EXIT_PENDING, &il->status);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001839}
1840
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001841static inline int il_is_alive(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001842{
Stanislaw Gruszkaa6766cc2011-11-15 13:09:01 +01001843 return test_bit(S_ALIVE, &il->status);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001844}
1845
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001846static inline int il_is_init(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001847{
Stanislaw Gruszkaa6766cc2011-11-15 13:09:01 +01001848 return test_bit(S_INIT, &il->status);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001849}
1850
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001851static inline int il_is_rfkill_hw(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001852{
Stanislaw Gruszkaa6766cc2011-11-15 13:09:01 +01001853 return test_bit(S_RF_KILL_HW, &il->status);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001854}
1855
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001856static inline int il_is_rfkill(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001857{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001858 return il_is_rfkill_hw(il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001859}
1860
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001861static inline int il_is_ctkill(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001862{
Stanislaw Gruszkaa6766cc2011-11-15 13:09:01 +01001863 return test_bit(S_CT_KILL, &il->status);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001864}
1865
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001866static inline int il_is_ready_rf(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001867{
1868
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001869 if (il_is_rfkill(il))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001870 return 0;
1871
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001872 return il_is_ready(il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001873}
1874
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001875extern void il_send_bt_config(struct il_priv *il);
Stanislaw Gruszkaebf0d902011-08-26 15:43:47 +02001876extern int il_send_stats_request(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001877 u8 flags, bool clear);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001878void il_apm_stop(struct il_priv *il);
1879int il_apm_init(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001880
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001881int il_send_rxon_timing(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001882 struct il_rxon_context *ctx);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001883static inline int il_send_rxon_assoc(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001884 struct il_rxon_context *ctx)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001885{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001886 return il->cfg->ops->hcmd->rxon_assoc(il, ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001887}
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001888static inline int il_commit_rxon(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001889 struct il_rxon_context *ctx)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001890{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001891 return il->cfg->ops->hcmd->commit_rxon(il, ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001892}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001893static inline const struct ieee80211_supported_band *il_get_hw_mode(
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001894 struct il_priv *il, enum ieee80211_band band)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001895{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001896 return il->hw->wiphy->bands[band];
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001897}
1898
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001899/* mac80211 handlers */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001900int il_mac_config(struct ieee80211_hw *hw, u32 changed);
1901void il_mac_reset_tsf(struct ieee80211_hw *hw,
Eliad Peller37a41b42011-09-21 14:06:11 +03001902 struct ieee80211_vif *vif);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001903void il_mac_bss_info_changed(struct ieee80211_hw *hw,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001904 struct ieee80211_vif *vif,
1905 struct ieee80211_bss_conf *bss_conf,
1906 u32 changes);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001907void il_tx_cmd_protection(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001908 struct ieee80211_tx_info *info,
1909 __le16 fc, __le32 *tx_flags);
1910
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001911irqreturn_t il_isr(int irq, void *data);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001912
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +02001913
1914#include <linux/io.h>
1915
1916static inline void _il_write8(struct il_priv *il, u32 ofs, u8 val)
1917{
1918 iowrite8(val, il->hw_base + ofs);
1919}
1920#define il_write8(il, ofs, val) _il_write8(il, ofs, val)
1921
1922static inline void _il_wr(struct il_priv *il, u32 ofs, u32 val)
1923{
1924 iowrite32(val, il->hw_base + ofs);
1925}
1926
1927static inline u32 _il_rd(struct il_priv *il, u32 ofs)
1928{
1929 return ioread32(il->hw_base + ofs);
1930}
1931
1932#define IL_POLL_INTERVAL 10 /* microseconds */
1933static inline int
1934_il_poll_bit(struct il_priv *il, u32 addr,
1935 u32 bits, u32 mask, int timeout)
1936{
1937 int t = 0;
1938
1939 do {
1940 if ((_il_rd(il, addr) & mask) == (bits & mask))
1941 return t;
1942 udelay(IL_POLL_INTERVAL);
1943 t += IL_POLL_INTERVAL;
1944 } while (t < timeout);
1945
1946 return -ETIMEDOUT;
1947}
1948
1949static inline void _il_set_bit(struct il_priv *il, u32 reg, u32 mask)
1950{
1951 _il_wr(il, reg, _il_rd(il, reg) | mask);
1952}
1953
1954static inline void il_set_bit(struct il_priv *p, u32 r, u32 m)
1955{
1956 unsigned long reg_flags;
1957
1958 spin_lock_irqsave(&p->reg_lock, reg_flags);
1959 _il_set_bit(p, r, m);
1960 spin_unlock_irqrestore(&p->reg_lock, reg_flags);
1961}
1962
1963static inline void
1964_il_clear_bit(struct il_priv *il, u32 reg, u32 mask)
1965{
1966 _il_wr(il, reg, _il_rd(il, reg) & ~mask);
1967}
1968
1969static inline void il_clear_bit(struct il_priv *p, u32 r, u32 m)
1970{
1971 unsigned long reg_flags;
1972
1973 spin_lock_irqsave(&p->reg_lock, reg_flags);
1974 _il_clear_bit(p, r, m);
1975 spin_unlock_irqrestore(&p->reg_lock, reg_flags);
1976}
1977
1978static inline int _il_grab_nic_access(struct il_priv *il)
1979{
1980 int ret;
1981 u32 val;
1982
1983 /* this bit wakes up the NIC */
1984 _il_set_bit(il, CSR_GP_CNTRL,
1985 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
1986
1987 /*
1988 * These bits say the device is running, and should keep running for
1989 * at least a short while (at least as long as MAC_ACCESS_REQ stays 1),
1990 * but they do not indicate that embedded SRAM is restored yet;
1991 * 3945 and 4965 have volatile SRAM, and must save/restore contents
1992 * to/from host DRAM when sleeping/waking for power-saving.
1993 * Each direction takes approximately 1/4 millisecond; with this
1994 * overhead, it's a good idea to grab and hold MAC_ACCESS_REQUEST if a
1995 * series of register accesses are expected (e.g. reading Event Log),
1996 * to keep device from sleeping.
1997 *
1998 * CSR_UCODE_DRV_GP1 register bit MAC_SLEEP == 0 indicates that
1999 * SRAM is okay/restored. We don't check that here because this call
2000 * is just for hardware register access; but GP1 MAC_SLEEP check is a
2001 * good idea before accessing 3945/4965 SRAM (e.g. reading Event Log).
2002 *
2003 */
2004 ret = _il_poll_bit(il, CSR_GP_CNTRL,
2005 CSR_GP_CNTRL_REG_VAL_MAC_ACCESS_EN,
2006 (CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY |
2007 CSR_GP_CNTRL_REG_FLAG_GOING_TO_SLEEP), 15000);
2008 if (ret < 0) {
2009 val = _il_rd(il, CSR_GP_CNTRL);
2010 IL_ERR(
2011 "MAC is in deep sleep!. CSR_GP_CNTRL = 0x%08X\n", val);
2012 _il_wr(il, CSR_RESET,
2013 CSR_RESET_REG_FLAG_FORCE_NMI);
2014 return -EIO;
2015 }
2016
2017 return 0;
2018}
2019
2020static inline void _il_release_nic_access(struct il_priv *il)
2021{
2022 _il_clear_bit(il, CSR_GP_CNTRL,
2023 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
2024}
2025
2026static inline u32 il_rd(struct il_priv *il, u32 reg)
2027{
2028 u32 value;
2029 unsigned long reg_flags;
2030
2031 spin_lock_irqsave(&il->reg_lock, reg_flags);
2032 _il_grab_nic_access(il);
2033 value = _il_rd(il, reg);
2034 _il_release_nic_access(il);
2035 spin_unlock_irqrestore(&il->reg_lock, reg_flags);
2036 return value;
2037
2038}
2039
2040static inline void
2041il_wr(struct il_priv *il, u32 reg, u32 value)
2042{
2043 unsigned long reg_flags;
2044
2045 spin_lock_irqsave(&il->reg_lock, reg_flags);
2046 if (!_il_grab_nic_access(il)) {
2047 _il_wr(il, reg, value);
2048 _il_release_nic_access(il);
2049 }
2050 spin_unlock_irqrestore(&il->reg_lock, reg_flags);
2051}
2052
2053static inline void il_write_reg_buf(struct il_priv *il,
2054 u32 reg, u32 len, u32 *values)
2055{
2056 u32 count = sizeof(u32);
2057
2058 if (il != NULL && values != NULL) {
2059 for (; 0 < len; len -= count, reg += count, values++)
2060 il_wr(il, reg, *values);
2061 }
2062}
2063
2064static inline int il_poll_bit(struct il_priv *il, u32 addr,
2065 u32 mask, int timeout)
2066{
2067 int t = 0;
2068
2069 do {
2070 if ((il_rd(il, addr) & mask) == mask)
2071 return t;
2072 udelay(IL_POLL_INTERVAL);
2073 t += IL_POLL_INTERVAL;
2074 } while (t < timeout);
2075
2076 return -ETIMEDOUT;
2077}
2078
2079static inline u32 _il_rd_prph(struct il_priv *il, u32 reg)
2080{
2081 _il_wr(il, HBUS_TARG_PRPH_RADDR, reg | (3 << 24));
2082 rmb();
2083 return _il_rd(il, HBUS_TARG_PRPH_RDAT);
2084}
2085
2086static inline u32 il_rd_prph(struct il_priv *il, u32 reg)
2087{
2088 unsigned long reg_flags;
2089 u32 val;
2090
2091 spin_lock_irqsave(&il->reg_lock, reg_flags);
2092 _il_grab_nic_access(il);
2093 val = _il_rd_prph(il, reg);
2094 _il_release_nic_access(il);
2095 spin_unlock_irqrestore(&il->reg_lock, reg_flags);
2096 return val;
2097}
2098
2099static inline void _il_wr_prph(struct il_priv *il,
2100 u32 addr, u32 val)
2101{
2102 _il_wr(il, HBUS_TARG_PRPH_WADDR,
2103 ((addr & 0x0000FFFF) | (3 << 24)));
2104 wmb();
2105 _il_wr(il, HBUS_TARG_PRPH_WDAT, val);
2106}
2107
2108static inline void
2109il_wr_prph(struct il_priv *il, u32 addr, u32 val)
2110{
2111 unsigned long reg_flags;
2112
2113 spin_lock_irqsave(&il->reg_lock, reg_flags);
2114 if (!_il_grab_nic_access(il)) {
2115 _il_wr_prph(il, addr, val);
2116 _il_release_nic_access(il);
2117 }
2118 spin_unlock_irqrestore(&il->reg_lock, reg_flags);
2119}
2120
2121#define _il_set_bits_prph(il, reg, mask) \
2122_il_wr_prph(il, reg, (_il_rd_prph(il, reg) | mask))
2123
2124static inline void
2125il_set_bits_prph(struct il_priv *il, u32 reg, u32 mask)
2126{
2127 unsigned long reg_flags;
2128
2129 spin_lock_irqsave(&il->reg_lock, reg_flags);
2130 _il_grab_nic_access(il);
2131 _il_set_bits_prph(il, reg, mask);
2132 _il_release_nic_access(il);
2133 spin_unlock_irqrestore(&il->reg_lock, reg_flags);
2134}
2135
2136#define _il_set_bits_mask_prph(il, reg, bits, mask) \
2137_il_wr_prph(il, reg, \
2138 ((_il_rd_prph(il, reg) & mask) | bits))
2139
2140static inline void il_set_bits_mask_prph(struct il_priv *il, u32 reg,
2141 u32 bits, u32 mask)
2142{
2143 unsigned long reg_flags;
2144
2145 spin_lock_irqsave(&il->reg_lock, reg_flags);
2146 _il_grab_nic_access(il);
2147 _il_set_bits_mask_prph(il, reg, bits, mask);
2148 _il_release_nic_access(il);
2149 spin_unlock_irqrestore(&il->reg_lock, reg_flags);
2150}
2151
2152static inline void il_clear_bits_prph(struct il_priv
2153 *il, u32 reg, u32 mask)
2154{
2155 unsigned long reg_flags;
2156 u32 val;
2157
2158 spin_lock_irqsave(&il->reg_lock, reg_flags);
2159 _il_grab_nic_access(il);
2160 val = _il_rd_prph(il, reg);
2161 _il_wr_prph(il, reg, (val & ~mask));
2162 _il_release_nic_access(il);
2163 spin_unlock_irqrestore(&il->reg_lock, reg_flags);
2164}
2165
2166static inline u32 il_read_targ_mem(struct il_priv *il, u32 addr)
2167{
2168 unsigned long reg_flags;
2169 u32 value;
2170
2171 spin_lock_irqsave(&il->reg_lock, reg_flags);
2172 _il_grab_nic_access(il);
2173
2174 _il_wr(il, HBUS_TARG_MEM_RADDR, addr);
2175 rmb();
2176 value = _il_rd(il, HBUS_TARG_MEM_RDAT);
2177
2178 _il_release_nic_access(il);
2179 spin_unlock_irqrestore(&il->reg_lock, reg_flags);
2180 return value;
2181}
2182
2183static inline void
2184il_write_targ_mem(struct il_priv *il, u32 addr, u32 val)
2185{
2186 unsigned long reg_flags;
2187
2188 spin_lock_irqsave(&il->reg_lock, reg_flags);
2189 if (!_il_grab_nic_access(il)) {
2190 _il_wr(il, HBUS_TARG_MEM_WADDR, addr);
2191 wmb();
2192 _il_wr(il, HBUS_TARG_MEM_WDAT, val);
2193 _il_release_nic_access(il);
2194 }
2195 spin_unlock_irqrestore(&il->reg_lock, reg_flags);
2196}
2197
2198static inline void
2199il_write_targ_mem_buf(struct il_priv *il, u32 addr,
2200 u32 len, u32 *values)
2201{
2202 unsigned long reg_flags;
2203
2204 spin_lock_irqsave(&il->reg_lock, reg_flags);
2205 if (!_il_grab_nic_access(il)) {
2206 _il_wr(il, HBUS_TARG_MEM_WADDR, addr);
2207 wmb();
2208 for (; 0 < len; len -= sizeof(u32), values++)
2209 _il_wr(il,
2210 HBUS_TARG_MEM_WDAT, *values);
2211
2212 _il_release_nic_access(il);
2213 }
2214 spin_unlock_irqrestore(&il->reg_lock, reg_flags);
2215}
2216
2217#define HW_KEY_DYNAMIC 0
2218#define HW_KEY_DEFAULT 1
2219
2220#define IL_STA_DRIVER_ACTIVE BIT(0) /* driver entry is active */
2221#define IL_STA_UCODE_ACTIVE BIT(1) /* ucode entry is active */
2222#define IL_STA_UCODE_INPROGRESS BIT(2) /* ucode entry is in process of
2223 being activated */
2224#define IL_STA_LOCAL BIT(3) /* station state not directed by mac80211;
2225 (this is for the IBSS BSSID stations) */
2226#define IL_STA_BCAST BIT(4) /* this station is the special bcast station */
2227
2228
2229void il_restore_stations(struct il_priv *il,
2230 struct il_rxon_context *ctx);
2231void il_clear_ucode_stations(struct il_priv *il,
2232 struct il_rxon_context *ctx);
2233void il_dealloc_bcast_stations(struct il_priv *il);
2234int il_get_free_ucode_key_idx(struct il_priv *il);
2235int il_send_add_sta(struct il_priv *il,
2236 struct il_addsta_cmd *sta, u8 flags);
2237int il_add_station_common(struct il_priv *il,
2238 struct il_rxon_context *ctx,
2239 const u8 *addr, bool is_ap,
2240 struct ieee80211_sta *sta, u8 *sta_id_r);
2241int il_remove_station(struct il_priv *il,
2242 const u8 sta_id,
2243 const u8 *addr);
2244int il_mac_sta_remove(struct ieee80211_hw *hw,
2245 struct ieee80211_vif *vif,
2246 struct ieee80211_sta *sta);
2247
2248u8 il_prep_station(struct il_priv *il,
2249 struct il_rxon_context *ctx,
2250 const u8 *addr, bool is_ap,
2251 struct ieee80211_sta *sta);
2252
2253int il_send_lq_cmd(struct il_priv *il,
2254 struct il_rxon_context *ctx,
2255 struct il_link_quality_cmd *lq,
2256 u8 flags, bool init);
2257
2258/**
2259 * il_clear_driver_stations - clear knowledge of all stations from driver
2260 * @il: iwl il struct
2261 *
2262 * This is called during il_down() to make sure that in the case
2263 * we're coming there from a hardware restart mac80211 will be
2264 * able to reconfigure stations -- if we're getting there in the
2265 * normal down flow then the stations will already be cleared.
2266 */
2267static inline void il_clear_driver_stations(struct il_priv *il)
2268{
2269 unsigned long flags;
2270 struct il_rxon_context *ctx = &il->ctx;
2271
2272 spin_lock_irqsave(&il->sta_lock, flags);
2273 memset(il->stations, 0, sizeof(il->stations));
2274 il->num_stations = 0;
2275
2276 il->ucode_key_table = 0;
2277
2278 /*
2279 * Remove all key information that is not stored as part
2280 * of station information since mac80211 may not have had
2281 * a chance to remove all the keys. When device is
2282 * reconfigured by mac80211 after an error all keys will
2283 * be reconfigured.
2284 */
2285 memset(ctx->wep_keys, 0, sizeof(ctx->wep_keys));
2286 ctx->key_mapping_keys = 0;
2287
2288 spin_unlock_irqrestore(&il->sta_lock, flags);
2289}
2290
2291static inline int il_sta_id(struct ieee80211_sta *sta)
2292{
2293 if (WARN_ON(!sta))
2294 return IL_INVALID_STATION;
2295
2296 return ((struct il_station_priv_common *)sta->drv_priv)->sta_id;
2297}
2298
2299/**
2300 * il_sta_id_or_broadcast - return sta_id or broadcast sta
2301 * @il: iwl il
2302 * @context: the current context
2303 * @sta: mac80211 station
2304 *
2305 * In certain circumstances mac80211 passes a station pointer
2306 * that may be %NULL, for example during TX or key setup. In
2307 * that case, we need to use the broadcast station, so this
2308 * inline wraps that pattern.
2309 */
2310static inline int il_sta_id_or_broadcast(struct il_priv *il,
2311 struct il_rxon_context *context,
2312 struct ieee80211_sta *sta)
2313{
2314 int sta_id;
2315
2316 if (!sta)
2317 return context->bcast_sta_id;
2318
2319 sta_id = il_sta_id(sta);
2320
2321 /*
2322 * mac80211 should not be passing a partially
2323 * initialised station!
2324 */
2325 WARN_ON(sta_id == IL_INVALID_STATION);
2326
2327 return sta_id;
2328}
2329
2330/**
2331 * il_queue_inc_wrap - increment queue idx, wrap back to beginning
2332 * @idx -- current idx
2333 * @n_bd -- total number of entries in queue (must be power of 2)
2334 */
2335static inline int il_queue_inc_wrap(int idx, int n_bd)
2336{
2337 return ++idx & (n_bd - 1);
2338}
2339
2340/**
2341 * il_queue_dec_wrap - decrement queue idx, wrap back to end
2342 * @idx -- current idx
2343 * @n_bd -- total number of entries in queue (must be power of 2)
2344 */
2345static inline int il_queue_dec_wrap(int idx, int n_bd)
2346{
2347 return --idx & (n_bd - 1);
2348}
2349
2350/* TODO: Move fw_desc functions to iwl-pci.ko */
2351static inline void il_free_fw_desc(struct pci_dev *pci_dev,
2352 struct fw_desc *desc)
2353{
2354 if (desc->v_addr)
2355 dma_free_coherent(&pci_dev->dev, desc->len,
2356 desc->v_addr, desc->p_addr);
2357 desc->v_addr = NULL;
2358 desc->len = 0;
2359}
2360
2361static inline int il_alloc_fw_desc(struct pci_dev *pci_dev,
2362 struct fw_desc *desc)
2363{
2364 if (!desc->len) {
2365 desc->v_addr = NULL;
2366 return -EINVAL;
2367 }
2368
2369 desc->v_addr = dma_alloc_coherent(&pci_dev->dev, desc->len,
2370 &desc->p_addr, GFP_KERNEL);
2371 return (desc->v_addr != NULL) ? 0 : -ENOMEM;
2372}
2373
2374/*
2375 * we have 8 bits used like this:
2376 *
2377 * 7 6 5 4 3 2 1 0
2378 * | | | | | | | |
2379 * | | | | | | +-+-------- AC queue (0-3)
2380 * | | | | | |
2381 * | +-+-+-+-+------------ HW queue ID
2382 * |
2383 * +---------------------- unused
2384 */
2385static inline void
2386il_set_swq_id(struct il_tx_queue *txq, u8 ac, u8 hwq)
2387{
2388 BUG_ON(ac > 3); /* only have 2 bits */
2389 BUG_ON(hwq > 31); /* only use 5 bits */
2390
2391 txq->swq_id = (hwq << 2) | ac;
2392}
2393
2394static inline void il_wake_queue(struct il_priv *il,
2395 struct il_tx_queue *txq)
2396{
2397 u8 queue = txq->swq_id;
2398 u8 ac = queue & 3;
2399 u8 hwq = (queue >> 2) & 0x1f;
2400
2401 if (test_and_clear_bit(hwq, il->queue_stopped))
2402 if (atomic_dec_return(&il->queue_stop_count[ac]) <= 0)
2403 ieee80211_wake_queue(il->hw, ac);
2404}
2405
2406static inline void il_stop_queue(struct il_priv *il,
2407 struct il_tx_queue *txq)
2408{
2409 u8 queue = txq->swq_id;
2410 u8 ac = queue & 3;
2411 u8 hwq = (queue >> 2) & 0x1f;
2412
2413 if (!test_and_set_bit(hwq, il->queue_stopped))
2414 if (atomic_inc_return(&il->queue_stop_count[ac]) > 0)
2415 ieee80211_stop_queue(il->hw, ac);
2416}
2417
2418#ifdef ieee80211_stop_queue
2419#undef ieee80211_stop_queue
2420#endif
2421
2422#define ieee80211_stop_queue DO_NOT_USE_ieee80211_stop_queue
2423
2424#ifdef ieee80211_wake_queue
2425#undef ieee80211_wake_queue
2426#endif
2427
2428#define ieee80211_wake_queue DO_NOT_USE_ieee80211_wake_queue
2429
2430static inline void il_disable_interrupts(struct il_priv *il)
2431{
2432 clear_bit(S_INT_ENABLED, &il->status);
2433
2434 /* disable interrupts from uCode/NIC to host */
2435 _il_wr(il, CSR_INT_MASK, 0x00000000);
2436
2437 /* acknowledge/clear/reset any interrupts still pending
2438 * from uCode or flow handler (Rx/Tx DMA) */
2439 _il_wr(il, CSR_INT, 0xffffffff);
2440 _il_wr(il, CSR_FH_INT_STATUS, 0xffffffff);
2441 D_ISR("Disabled interrupts\n");
2442}
2443
2444static inline void il_enable_rfkill_int(struct il_priv *il)
2445{
2446 D_ISR("Enabling rfkill interrupt\n");
2447 _il_wr(il, CSR_INT_MASK, CSR_INT_BIT_RF_KILL);
2448}
2449
2450static inline void il_enable_interrupts(struct il_priv *il)
2451{
2452 D_ISR("Enabling interrupts\n");
2453 set_bit(S_INT_ENABLED, &il->status);
2454 _il_wr(il, CSR_INT_MASK, il->inta_mask);
2455}
2456
2457/**
2458 * il_beacon_time_mask_low - mask of lower 32 bit of beacon time
2459 * @il -- pointer to il_priv data structure
2460 * @tsf_bits -- number of bits need to shift for masking)
2461 */
2462static inline u32 il_beacon_time_mask_low(struct il_priv *il,
2463 u16 tsf_bits)
2464{
2465 return (1 << tsf_bits) - 1;
2466}
2467
2468/**
2469 * il_beacon_time_mask_high - mask of higher 32 bit of beacon time
2470 * @il -- pointer to il_priv data structure
2471 * @tsf_bits -- number of bits need to shift for masking)
2472 */
2473static inline u32 il_beacon_time_mask_high(struct il_priv *il,
2474 u16 tsf_bits)
2475{
2476 return ((1 << (32 - tsf_bits)) - 1) << tsf_bits;
2477}
2478
2479/**
2480 * struct il_rb_status - reseve buffer status host memory mapped FH registers
2481 *
2482 * @closed_rb_num [0:11] - Indicates the idx of the RB which was closed
2483 * @closed_fr_num [0:11] - Indicates the idx of the RX Frame which was closed
2484 * @finished_rb_num [0:11] - Indicates the idx of the current RB
2485 * in which the last frame was written to
2486 * @finished_fr_num [0:11] - Indicates the idx of the RX Frame
2487 * which was transferred
2488 */
2489struct il_rb_status {
2490 __le16 closed_rb_num;
2491 __le16 closed_fr_num;
2492 __le16 finished_rb_num;
2493 __le16 finished_fr_nam;
2494 __le32 __unused; /* 3945 only */
2495} __packed;
2496
2497
2498#define TFD_QUEUE_SIZE_MAX (256)
2499#define TFD_QUEUE_SIZE_BC_DUP (64)
2500#define TFD_QUEUE_BC_SIZE (TFD_QUEUE_SIZE_MAX + TFD_QUEUE_SIZE_BC_DUP)
2501#define IL_TX_DMA_MASK DMA_BIT_MASK(36)
2502#define IL_NUM_OF_TBS 20
2503
2504static inline u8 il_get_dma_hi_addr(dma_addr_t addr)
2505{
2506 return (sizeof(addr) > sizeof(u32) ? (addr >> 16) >> 16 : 0) & 0xF;
2507}
2508/**
2509 * struct il_tfd_tb transmit buffer descriptor within transmit frame descriptor
2510 *
2511 * This structure contains dma address and length of transmission address
2512 *
2513 * @lo: low [31:0] portion of the dma address of TX buffer
2514 * every even is unaligned on 16 bit boundary
2515 * @hi_n_len 0-3 [35:32] portion of dma
2516 * 4-15 length of the tx buffer
2517 */
2518struct il_tfd_tb {
2519 __le32 lo;
2520 __le16 hi_n_len;
2521} __packed;
2522
2523/**
2524 * struct il_tfd
2525 *
2526 * Transmit Frame Descriptor (TFD)
2527 *
2528 * @ __reserved1[3] reserved
2529 * @ num_tbs 0-4 number of active tbs
2530 * 5 reserved
2531 * 6-7 padding (not used)
2532 * @ tbs[20] transmit frame buffer descriptors
2533 * @ __pad padding
2534 *
2535 * Each Tx queue uses a circular buffer of 256 TFDs stored in host DRAM.
2536 * Both driver and device share these circular buffers, each of which must be
2537 * contiguous 256 TFDs x 128 bytes-per-TFD = 32 KBytes
2538 *
2539 * Driver must indicate the physical address of the base of each
2540 * circular buffer via the FH_MEM_CBBC_QUEUE registers.
2541 *
2542 * Each TFD contains pointer/size information for up to 20 data buffers
2543 * in host DRAM. These buffers collectively contain the (one) frame described
2544 * by the TFD. Each buffer must be a single contiguous block of memory within
2545 * itself, but buffers may be scattered in host DRAM. Each buffer has max size
2546 * of (4K - 4). The concatenates all of a TFD's buffers into a single
2547 * Tx frame, up to 8 KBytes in size.
2548 *
2549 * A maximum of 255 (not 256!) TFDs may be on a queue waiting for Tx.
2550 */
2551struct il_tfd {
2552 u8 __reserved1[3];
2553 u8 num_tbs;
2554 struct il_tfd_tb tbs[IL_NUM_OF_TBS];
2555 __le32 __pad;
2556} __packed;
2557/* PCI registers */
2558#define PCI_CFG_RETRY_TIMEOUT 0x041
2559
2560/* PCI register values */
2561#define PCI_CFG_LINK_CTRL_VAL_L0S_EN 0x01
2562#define PCI_CFG_LINK_CTRL_VAL_L1_EN 0x02
2563
Stanislaw Gruszka3fbbf9a2011-08-31 13:39:29 +02002564struct il_rate_info {
2565 u8 plcp; /* uCode API: RATE_6M_PLCP, etc. */
2566 u8 plcp_siso; /* uCode API: RATE_SISO_6M_PLCP, etc. */
2567 u8 plcp_mimo2; /* uCode API: RATE_MIMO2_6M_PLCP, etc. */
2568 u8 ieee; /* MAC header: RATE_6M_IEEE, etc. */
2569 u8 prev_ieee; /* previous rate in IEEE speeds */
2570 u8 next_ieee; /* next rate in IEEE speeds */
2571 u8 prev_rs; /* previous rate used in rs algo */
2572 u8 next_rs; /* next rate used in rs algo */
2573 u8 prev_rs_tgg; /* previous rate used in TGG rs algo */
2574 u8 next_rs_tgg; /* next rate used in TGG rs algo */
2575};
2576
2577struct il3945_rate_info {
2578 u8 plcp; /* uCode API: RATE_6M_PLCP, etc. */
2579 u8 ieee; /* MAC header: RATE_6M_IEEE, etc. */
2580 u8 prev_ieee; /* previous rate in IEEE speeds */
2581 u8 next_ieee; /* next rate in IEEE speeds */
2582 u8 prev_rs; /* previous rate used in rs algo */
2583 u8 next_rs; /* next rate used in rs algo */
2584 u8 prev_rs_tgg; /* previous rate used in TGG rs algo */
2585 u8 next_rs_tgg; /* next rate used in TGG rs algo */
2586 u8 table_rs_idx; /* idx in rate scale table cmd */
2587 u8 prev_table_rs; /* prev in rate table cmd */
2588};
2589
2590
2591/*
2592 * These serve as idxes into
2593 * struct il_rate_info il_rates[RATE_COUNT];
2594 */
2595enum {
2596 RATE_1M_IDX = 0,
2597 RATE_2M_IDX,
2598 RATE_5M_IDX,
2599 RATE_11M_IDX,
2600 RATE_6M_IDX,
2601 RATE_9M_IDX,
2602 RATE_12M_IDX,
2603 RATE_18M_IDX,
2604 RATE_24M_IDX,
2605 RATE_36M_IDX,
2606 RATE_48M_IDX,
2607 RATE_54M_IDX,
2608 RATE_60M_IDX,
2609 RATE_COUNT,
2610 RATE_COUNT_LEGACY = RATE_COUNT - 1, /* Excluding 60M */
2611 RATE_COUNT_3945 = RATE_COUNT - 1,
2612 RATE_INVM_IDX = RATE_COUNT,
2613 RATE_INVALID = RATE_COUNT,
2614};
2615
2616enum {
2617 RATE_6M_IDX_TBL = 0,
2618 RATE_9M_IDX_TBL,
2619 RATE_12M_IDX_TBL,
2620 RATE_18M_IDX_TBL,
2621 RATE_24M_IDX_TBL,
2622 RATE_36M_IDX_TBL,
2623 RATE_48M_IDX_TBL,
2624 RATE_54M_IDX_TBL,
2625 RATE_1M_IDX_TBL,
2626 RATE_2M_IDX_TBL,
2627 RATE_5M_IDX_TBL,
2628 RATE_11M_IDX_TBL,
2629 RATE_INVM_IDX_TBL = RATE_INVM_IDX - 1,
2630};
2631
2632enum {
2633 IL_FIRST_OFDM_RATE = RATE_6M_IDX,
2634 IL39_LAST_OFDM_RATE = RATE_54M_IDX,
2635 IL_LAST_OFDM_RATE = RATE_60M_IDX,
2636 IL_FIRST_CCK_RATE = RATE_1M_IDX,
2637 IL_LAST_CCK_RATE = RATE_11M_IDX,
2638};
2639
2640/* #define vs. enum to keep from defaulting to 'large integer' */
2641#define RATE_6M_MASK (1 << RATE_6M_IDX)
2642#define RATE_9M_MASK (1 << RATE_9M_IDX)
2643#define RATE_12M_MASK (1 << RATE_12M_IDX)
2644#define RATE_18M_MASK (1 << RATE_18M_IDX)
2645#define RATE_24M_MASK (1 << RATE_24M_IDX)
2646#define RATE_36M_MASK (1 << RATE_36M_IDX)
2647#define RATE_48M_MASK (1 << RATE_48M_IDX)
2648#define RATE_54M_MASK (1 << RATE_54M_IDX)
2649#define RATE_60M_MASK (1 << RATE_60M_IDX)
2650#define RATE_1M_MASK (1 << RATE_1M_IDX)
2651#define RATE_2M_MASK (1 << RATE_2M_IDX)
2652#define RATE_5M_MASK (1 << RATE_5M_IDX)
2653#define RATE_11M_MASK (1 << RATE_11M_IDX)
2654
2655/* uCode API values for legacy bit rates, both OFDM and CCK */
2656enum {
2657 RATE_6M_PLCP = 13,
2658 RATE_9M_PLCP = 15,
2659 RATE_12M_PLCP = 5,
2660 RATE_18M_PLCP = 7,
2661 RATE_24M_PLCP = 9,
2662 RATE_36M_PLCP = 11,
2663 RATE_48M_PLCP = 1,
2664 RATE_54M_PLCP = 3,
2665 RATE_60M_PLCP = 3,/*FIXME:RS:should be removed*/
2666 RATE_1M_PLCP = 10,
2667 RATE_2M_PLCP = 20,
2668 RATE_5M_PLCP = 55,
2669 RATE_11M_PLCP = 110,
2670 /*FIXME:RS:add RATE_LEGACY_INVM_PLCP = 0,*/
2671};
2672
2673/* uCode API values for OFDM high-throughput (HT) bit rates */
2674enum {
2675 RATE_SISO_6M_PLCP = 0,
2676 RATE_SISO_12M_PLCP = 1,
2677 RATE_SISO_18M_PLCP = 2,
2678 RATE_SISO_24M_PLCP = 3,
2679 RATE_SISO_36M_PLCP = 4,
2680 RATE_SISO_48M_PLCP = 5,
2681 RATE_SISO_54M_PLCP = 6,
2682 RATE_SISO_60M_PLCP = 7,
2683 RATE_MIMO2_6M_PLCP = 0x8,
2684 RATE_MIMO2_12M_PLCP = 0x9,
2685 RATE_MIMO2_18M_PLCP = 0xa,
2686 RATE_MIMO2_24M_PLCP = 0xb,
2687 RATE_MIMO2_36M_PLCP = 0xc,
2688 RATE_MIMO2_48M_PLCP = 0xd,
2689 RATE_MIMO2_54M_PLCP = 0xe,
2690 RATE_MIMO2_60M_PLCP = 0xf,
2691 RATE_SISO_INVM_PLCP,
2692 RATE_MIMO2_INVM_PLCP = RATE_SISO_INVM_PLCP,
2693};
2694
2695/* MAC header values for bit rates */
2696enum {
2697 RATE_6M_IEEE = 12,
2698 RATE_9M_IEEE = 18,
2699 RATE_12M_IEEE = 24,
2700 RATE_18M_IEEE = 36,
2701 RATE_24M_IEEE = 48,
2702 RATE_36M_IEEE = 72,
2703 RATE_48M_IEEE = 96,
2704 RATE_54M_IEEE = 108,
2705 RATE_60M_IEEE = 120,
2706 RATE_1M_IEEE = 2,
2707 RATE_2M_IEEE = 4,
2708 RATE_5M_IEEE = 11,
2709 RATE_11M_IEEE = 22,
2710};
2711
2712#define IL_CCK_BASIC_RATES_MASK \
2713 (RATE_1M_MASK | \
2714 RATE_2M_MASK)
2715
2716#define IL_CCK_RATES_MASK \
2717 (IL_CCK_BASIC_RATES_MASK | \
2718 RATE_5M_MASK | \
2719 RATE_11M_MASK)
2720
2721#define IL_OFDM_BASIC_RATES_MASK \
2722 (RATE_6M_MASK | \
2723 RATE_12M_MASK | \
2724 RATE_24M_MASK)
2725
2726#define IL_OFDM_RATES_MASK \
2727 (IL_OFDM_BASIC_RATES_MASK | \
2728 RATE_9M_MASK | \
2729 RATE_18M_MASK | \
2730 RATE_36M_MASK | \
2731 RATE_48M_MASK | \
2732 RATE_54M_MASK)
2733
2734#define IL_BASIC_RATES_MASK \
2735 (IL_OFDM_BASIC_RATES_MASK | \
2736 IL_CCK_BASIC_RATES_MASK)
2737
2738#define RATES_MASK ((1 << RATE_COUNT) - 1)
2739#define RATES_MASK_3945 ((1 << RATE_COUNT_3945) - 1)
2740
2741#define IL_INVALID_VALUE -1
2742
2743#define IL_MIN_RSSI_VAL -100
2744#define IL_MAX_RSSI_VAL 0
2745
2746/* These values specify how many Tx frame attempts before
2747 * searching for a new modulation mode */
2748#define IL_LEGACY_FAILURE_LIMIT 160
2749#define IL_LEGACY_SUCCESS_LIMIT 480
2750#define IL_LEGACY_TBL_COUNT 160
2751
2752#define IL_NONE_LEGACY_FAILURE_LIMIT 400
2753#define IL_NONE_LEGACY_SUCCESS_LIMIT 4500
2754#define IL_NONE_LEGACY_TBL_COUNT 1500
2755
2756/* Success ratio (ACKed / attempted tx frames) values (perfect is 128 * 100) */
2757#define IL_RS_GOOD_RATIO 12800 /* 100% */
2758#define RATE_SCALE_SWITCH 10880 /* 85% */
2759#define RATE_HIGH_TH 10880 /* 85% */
2760#define RATE_INCREASE_TH 6400 /* 50% */
2761#define RATE_DECREASE_TH 1920 /* 15% */
2762
2763/* possible actions when in legacy mode */
2764#define IL_LEGACY_SWITCH_ANTENNA1 0
2765#define IL_LEGACY_SWITCH_ANTENNA2 1
2766#define IL_LEGACY_SWITCH_SISO 2
2767#define IL_LEGACY_SWITCH_MIMO2_AB 3
2768#define IL_LEGACY_SWITCH_MIMO2_AC 4
2769#define IL_LEGACY_SWITCH_MIMO2_BC 5
2770
2771/* possible actions when in siso mode */
2772#define IL_SISO_SWITCH_ANTENNA1 0
2773#define IL_SISO_SWITCH_ANTENNA2 1
2774#define IL_SISO_SWITCH_MIMO2_AB 2
2775#define IL_SISO_SWITCH_MIMO2_AC 3
2776#define IL_SISO_SWITCH_MIMO2_BC 4
2777#define IL_SISO_SWITCH_GI 5
2778
2779/* possible actions when in mimo mode */
2780#define IL_MIMO2_SWITCH_ANTENNA1 0
2781#define IL_MIMO2_SWITCH_ANTENNA2 1
2782#define IL_MIMO2_SWITCH_SISO_A 2
2783#define IL_MIMO2_SWITCH_SISO_B 3
2784#define IL_MIMO2_SWITCH_SISO_C 4
2785#define IL_MIMO2_SWITCH_GI 5
2786
2787#define IL_MAX_SEARCH IL_MIMO2_SWITCH_GI
2788
2789#define IL_ACTION_LIMIT 3 /* # possible actions */
2790
2791#define LQ_SIZE 2 /* 2 mode tables: "Active" and "Search" */
2792
2793/* load per tid defines for A-MPDU activation */
2794#define IL_AGG_TPT_THREHOLD 0
2795#define IL_AGG_LOAD_THRESHOLD 10
2796#define IL_AGG_ALL_TID 0xff
2797#define TID_QUEUE_CELL_SPACING 50 /*mS */
2798#define TID_QUEUE_MAX_SIZE 20
2799#define TID_ROUND_VALUE 5 /* mS */
2800#define TID_MAX_LOAD_COUNT 8
2801
2802#define TID_MAX_TIME_DIFF ((TID_QUEUE_MAX_SIZE - 1) * TID_QUEUE_CELL_SPACING)
2803#define TIME_WRAP_AROUND(x, y) (((y) > (x)) ? (y) - (x) : (0-(x)) + (y))
2804
2805extern const struct il_rate_info il_rates[RATE_COUNT];
2806
2807enum il_table_type {
2808 LQ_NONE,
2809 LQ_G, /* legacy types */
2810 LQ_A,
2811 LQ_SISO, /* high-throughput types */
2812 LQ_MIMO2,
2813 LQ_MAX,
2814};
2815
2816#define is_legacy(tbl) ((tbl) == LQ_G || (tbl) == LQ_A)
2817#define is_siso(tbl) ((tbl) == LQ_SISO)
2818#define is_mimo2(tbl) ((tbl) == LQ_MIMO2)
2819#define is_mimo(tbl) (is_mimo2(tbl))
2820#define is_Ht(tbl) (is_siso(tbl) || is_mimo(tbl))
2821#define is_a_band(tbl) ((tbl) == LQ_A)
2822#define is_g_and(tbl) ((tbl) == LQ_G)
2823
2824#define ANT_NONE 0x0
2825#define ANT_A BIT(0)
2826#define ANT_B BIT(1)
2827#define ANT_AB (ANT_A | ANT_B)
2828#define ANT_C BIT(2)
2829#define ANT_AC (ANT_A | ANT_C)
2830#define ANT_BC (ANT_B | ANT_C)
2831#define ANT_ABC (ANT_AB | ANT_C)
2832
2833#define IL_MAX_MCS_DISPLAY_SIZE 12
2834
2835struct il_rate_mcs_info {
2836 char mbps[IL_MAX_MCS_DISPLAY_SIZE];
2837 char mcs[IL_MAX_MCS_DISPLAY_SIZE];
2838};
2839
2840/**
2841 * struct il_rate_scale_data -- tx success history for one rate
2842 */
2843struct il_rate_scale_data {
2844 u64 data; /* bitmap of successful frames */
2845 s32 success_counter; /* number of frames successful */
2846 s32 success_ratio; /* per-cent * 128 */
2847 s32 counter; /* number of frames attempted */
2848 s32 average_tpt; /* success ratio * expected throughput */
2849 unsigned long stamp;
2850};
2851
2852/**
2853 * struct il_scale_tbl_info -- tx params and success history for all rates
2854 *
2855 * There are two of these in struct il_lq_sta,
2856 * one for "active", and one for "search".
2857 */
2858struct il_scale_tbl_info {
2859 enum il_table_type lq_type;
2860 u8 ant_type;
2861 u8 is_SGI; /* 1 = short guard interval */
2862 u8 is_ht40; /* 1 = 40 MHz channel width */
2863 u8 is_dup; /* 1 = duplicated data streams */
2864 u8 action; /* change modulation; IL_[LEGACY/SISO/MIMO]_SWITCH_* */
2865 u8 max_search; /* maximun number of tables we can search */
2866 s32 *expected_tpt; /* throughput metrics; expected_tpt_G, etc. */
2867 u32 current_rate; /* rate_n_flags, uCode API format */
2868 struct il_rate_scale_data win[RATE_COUNT]; /* rate histories */
2869};
2870
2871struct il_traffic_load {
2872 unsigned long time_stamp; /* age of the oldest stats */
2873 u32 packet_count[TID_QUEUE_MAX_SIZE]; /* packet count in this time
2874 * slice */
2875 u32 total; /* total num of packets during the
2876 * last TID_MAX_TIME_DIFF */
2877 u8 queue_count; /* number of queues that has
2878 * been used since the last cleanup */
2879 u8 head; /* start of the circular buffer */
2880};
2881
2882/**
2883 * struct il_lq_sta -- driver's rate scaling ilate structure
2884 *
2885 * Pointer to this gets passed back and forth between driver and mac80211.
2886 */
2887struct il_lq_sta {
2888 u8 active_tbl; /* idx of active table, range 0-1 */
2889 u8 enable_counter; /* indicates HT mode */
2890 u8 stay_in_tbl; /* 1: disallow, 0: allow search for new mode */
2891 u8 search_better_tbl; /* 1: currently trying alternate mode */
2892 s32 last_tpt;
2893
2894 /* The following determine when to search for a new mode */
2895 u32 table_count_limit;
2896 u32 max_failure_limit; /* # failed frames before new search */
2897 u32 max_success_limit; /* # successful frames before new search */
2898 u32 table_count;
2899 u32 total_failed; /* total failed frames, any/all rates */
2900 u32 total_success; /* total successful frames, any/all rates */
2901 u64 flush_timer; /* time staying in mode before new search */
2902
2903 u8 action_counter; /* # mode-switch actions tried */
2904 u8 is_green;
2905 u8 is_dup;
2906 enum ieee80211_band band;
2907
2908 /* The following are bitmaps of rates; RATE_6M_MASK, etc. */
2909 u32 supp_rates;
2910 u16 active_legacy_rate;
2911 u16 active_siso_rate;
2912 u16 active_mimo2_rate;
2913 s8 max_rate_idx; /* Max rate set by user */
2914 u8 missed_rate_counter;
2915
2916 struct il_link_quality_cmd lq;
2917 struct il_scale_tbl_info lq_info[LQ_SIZE]; /* "active", "search" */
2918 struct il_traffic_load load[TID_MAX_LOAD_COUNT];
2919 u8 tx_agg_tid_en;
2920#ifdef CONFIG_MAC80211_DEBUGFS
2921 struct dentry *rs_sta_dbgfs_scale_table_file;
2922 struct dentry *rs_sta_dbgfs_stats_table_file;
2923 struct dentry *rs_sta_dbgfs_rate_scale_data_file;
2924 struct dentry *rs_sta_dbgfs_tx_agg_tid_en_file;
2925 u32 dbg_fixed_rate;
2926#endif
2927 struct il_priv *drv;
2928
2929 /* used to be in sta_info */
2930 int last_txrate_idx;
2931 /* last tx rate_n_flags */
2932 u32 last_rate_n_flags;
2933 /* packets destined for this STA are aggregated */
2934 u8 is_agg;
2935};
2936
2937/*
2938 * il_station_priv: Driver's ilate station information
2939 *
2940 * When mac80211 creates a station it reserves some space (hw->sta_data_size)
2941 * in the structure for use by driver. This structure is places in that
2942 * space.
2943 *
2944 * The common struct MUST be first because it is shared between
2945 * 3945 and 4965!
2946 */
2947struct il_station_priv {
2948 struct il_station_priv_common common;
2949 struct il_lq_sta lq_sta;
2950 atomic_t pending_frames;
2951 bool client;
2952 bool asleep;
2953};
2954
2955static inline u8 il4965_num_of_ant(u8 m)
2956{
2957 return !!(m & ANT_A) + !!(m & ANT_B) + !!(m & ANT_C);
2958}
2959
2960static inline u8 il4965_first_antenna(u8 mask)
2961{
2962 if (mask & ANT_A)
2963 return ANT_A;
2964 if (mask & ANT_B)
2965 return ANT_B;
2966 return ANT_C;
2967}
2968
2969
2970/**
2971 * il3945_rate_scale_init - Initialize the rate scale table based on assoc info
2972 *
2973 * The specific throughput table used is based on the type of network
2974 * the associated with, including A, B, G, and G w/ TGG protection
2975 */
2976extern void il3945_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id);
2977
2978/* Initialize station's rate scaling information after adding station */
2979extern void il4965_rs_rate_init(struct il_priv *il,
2980 struct ieee80211_sta *sta, u8 sta_id);
2981extern void il3945_rs_rate_init(struct il_priv *il,
2982 struct ieee80211_sta *sta, u8 sta_id);
2983
2984/**
2985 * il_rate_control_register - Register the rate control algorithm callbacks
2986 *
2987 * Since the rate control algorithm is hardware specific, there is no need
2988 * or reason to place it as a stand alone module. The driver can call
2989 * il_rate_control_register in order to register the rate control callbacks
2990 * with the mac80211 subsystem. This should be performed prior to calling
2991 * ieee80211_register_hw
2992 *
2993 */
2994extern int il4965_rate_control_register(void);
2995extern int il3945_rate_control_register(void);
2996
2997/**
2998 * il_rate_control_unregister - Unregister the rate control callbacks
2999 *
3000 * This should be called after calling ieee80211_unregister_hw, but before
3001 * the driver is unloaded.
3002 */
3003extern void il4965_rate_control_unregister(void);
3004extern void il3945_rate_control_unregister(void);
3005
Stanislaw Gruszka99412002011-08-31 13:53:04 +02003006extern int il_power_update_mode(struct il_priv *il, bool force);
3007extern void il_power_initialize(struct il_priv *il);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02003008#endif /* __il_core_h__ */