blob: 2e66929c34ef0f0974a607c4e3ccf1041cbf99dc [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
36#include "iwl-eeprom.h"
37#include "csr.h"
38#include "iwl-prph.h"
39#include "iwl-debug.h"
40#include "iwl-led.h"
41#include "iwl-power.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
941struct il_priv {
942
943 /* ieee device used by generic ieee processing code */
944 struct ieee80211_hw *hw;
945 struct ieee80211_channel *ieee_channels;
946 struct ieee80211_rate *ieee_rates;
947 struct il_cfg *cfg;
948
949 /* temporary frame storage list */
950 struct list_head free_frames;
951 int frames_count;
952
953 enum ieee80211_band band;
954 int alloc_rxb_page;
955
956 void (*handlers[IL_CN_MAX])(struct il_priv *il,
957 struct il_rx_buf *rxb);
958
959 struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
960
961 /* spectrum measurement report caching */
962 struct il_spectrum_notification measure_report;
963 u8 measurement_status;
964
965 /* ucode beacon time */
966 u32 ucode_beacon_time;
967 int missed_beacon_threshold;
968
969 /* track IBSS manager (last beacon) status */
970 u32 ibss_manager;
971
972 /* force reset */
973 struct il_force_reset force_reset;
974
975 /* we allocate array of il_channel_info for NIC's valid channels.
976 * Access via channel # using indirect idx array */
977 struct il_channel_info *channel_info; /* channel info array */
978 u8 channel_count; /* # of channels */
979
980 /* thermal calibration */
981 s32 temperature; /* degrees Kelvin */
982 s32 last_temperature;
983
984 /* init calibration results */
985 struct il_calib_result calib_results[IL_CALIB_MAX];
986
987 /* Scan related variables */
988 unsigned long scan_start;
989 unsigned long scan_start_tsf;
990 void *scan_cmd;
991 enum ieee80211_band scan_band;
992 struct cfg80211_scan_request *scan_request;
993 struct ieee80211_vif *scan_vif;
994 u8 scan_tx_ant[IEEE80211_NUM_BANDS];
995 u8 mgmt_tx_ant;
996
997 /* spinlock */
998 spinlock_t lock; /* protect general shared data */
999 spinlock_t hcmd_lock; /* protect hcmd */
1000 spinlock_t reg_lock; /* protect hw register access */
1001 struct mutex mutex;
1002
1003 /* basic pci-network driver stuff */
1004 struct pci_dev *pci_dev;
1005
1006 /* pci hardware address support */
1007 void __iomem *hw_base;
1008 u32 hw_rev;
1009 u32 hw_wa_rev;
1010 u8 rev_id;
1011
1012 /* command queue number */
1013 u8 cmd_queue;
1014
1015 /* max number of station keys */
1016 u8 sta_key_max_num;
1017
1018 /* EEPROM MAC addresses */
1019 struct mac_address addresses[1];
1020
1021 /* uCode images, save to reload in case of failure */
1022 int fw_idx; /* firmware we're trying to load */
1023 u32 ucode_ver; /* version of ucode, copy of
1024 il_ucode.ver */
1025 struct fw_desc ucode_code; /* runtime inst */
1026 struct fw_desc ucode_data; /* runtime data original */
1027 struct fw_desc ucode_data_backup; /* runtime data save/restore */
1028 struct fw_desc ucode_init; /* initialization inst */
1029 struct fw_desc ucode_init_data; /* initialization data */
1030 struct fw_desc ucode_boot; /* bootstrap inst */
1031 enum ucode_type ucode_type;
1032 u8 ucode_write_complete; /* the image write is complete */
1033 char firmware_name[25];
1034
1035 struct il_rxon_context ctx;
1036
1037 __le16 switch_channel;
1038
1039 /* 1st responses from initialize and runtime uCode images.
1040 * _4965's initialize alive response contains some calibration data. */
1041 struct il_init_alive_resp card_alive_init;
1042 struct il_alive_resp card_alive;
1043
1044 u16 active_rate;
1045
1046 u8 start_calib;
1047 struct il_sensitivity_data sensitivity_data;
1048 struct il_chain_noise_data chain_noise_data;
1049 __le16 sensitivity_tbl[HD_TBL_SIZE];
1050
1051 struct il_ht_config current_ht_config;
1052
1053 /* Rate scaling data */
1054 u8 retry_rate;
1055
1056 wait_queue_head_t wait_command_queue;
1057
1058 int activity_timer_active;
1059
1060 /* Rx and Tx DMA processing queues */
1061 struct il_rx_queue rxq;
1062 struct il_tx_queue *txq;
1063 unsigned long txq_ctx_active_msk;
1064 struct il_dma_ptr kw; /* keep warm address */
1065 struct il_dma_ptr scd_bc_tbls;
1066
1067 u32 scd_base_addr; /* scheduler sram base address */
1068
1069 unsigned long status;
1070
1071 /* counts mgmt, ctl, and data packets */
1072 struct traffic_stats tx_stats;
1073 struct traffic_stats rx_stats;
1074
1075 /* counts interrupts */
1076 struct isr_stats isr_stats;
1077
1078 struct il_power_mgr power_data;
1079
1080 /* context information */
1081 u8 bssid[ETH_ALEN]; /* used only on 3945 but filled by core */
1082
1083 /* station table variables */
1084
1085 /* Note: if lock and sta_lock are needed, lock must be acquired first */
1086 spinlock_t sta_lock;
1087 int num_stations;
1088 struct il_station_entry stations[IL_STATION_COUNT];
1089 unsigned long ucode_key_table;
1090
1091 /* queue refcounts */
1092#define IL_MAX_HW_QUEUES 32
1093 unsigned long queue_stopped[BITS_TO_LONGS(IL_MAX_HW_QUEUES)];
1094 /* for each AC */
1095 atomic_t queue_stop_count[4];
1096
1097 /* Indication if ieee80211_ops->open has been called */
1098 u8 is_open;
1099
1100 u8 mac80211_registered;
1101
1102 /* eeprom -- this is in the card's little endian byte order */
1103 u8 *eeprom;
1104 struct il_eeprom_calib_info *calib_info;
1105
1106 enum nl80211_iftype iw_mode;
1107
1108 /* Last Rx'd beacon timestamp */
1109 u64 timestamp;
1110
1111 union {
1112#if defined(CONFIG_IWL3945) || defined(CONFIG_IWL3945_MODULE)
1113 struct {
1114 void *shared_virt;
1115 dma_addr_t shared_phys;
1116
1117 struct delayed_work thermal_periodic;
1118 struct delayed_work rfkill_poll;
1119
1120 struct il3945_notif_stats stats;
1121#ifdef CONFIG_IWLEGACY_DEBUGFS
1122 struct il3945_notif_stats accum_stats;
1123 struct il3945_notif_stats delta_stats;
1124 struct il3945_notif_stats max_delta;
1125#endif
1126
1127 u32 sta_supp_rates;
1128 int last_rx_rssi; /* From Rx packet stats */
1129
1130 /* Rx'd packet timing information */
1131 u32 last_beacon_time;
1132 u64 last_tsf;
1133
1134 /*
1135 * each calibration channel group in the
1136 * EEPROM has a derived clip setting for
1137 * each rate.
1138 */
1139 const struct il3945_clip_group clip_groups[5];
1140
1141 } _3945;
1142#endif
1143#if defined(CONFIG_IWL4965) || defined(CONFIG_IWL4965_MODULE)
1144 struct {
1145 struct il_rx_phy_res last_phy_res;
1146 bool last_phy_res_valid;
1147
1148 struct completion firmware_loading_complete;
1149
1150 /*
1151 * chain noise reset and gain commands are the
1152 * two extra calibration commands follows the standard
1153 * phy calibration commands
1154 */
1155 u8 phy_calib_chain_noise_reset_cmd;
1156 u8 phy_calib_chain_noise_gain_cmd;
1157
1158 struct il_notif_stats stats;
1159#ifdef CONFIG_IWLEGACY_DEBUGFS
1160 struct il_notif_stats accum_stats;
1161 struct il_notif_stats delta_stats;
1162 struct il_notif_stats max_delta;
1163#endif
1164
1165 } _4965;
1166#endif
1167 };
1168
1169 struct il_hw_params hw_params;
1170
1171 u32 inta_mask;
1172
1173 struct workqueue_struct *workqueue;
1174
1175 struct work_struct restart;
1176 struct work_struct scan_completed;
1177 struct work_struct rx_replenish;
1178 struct work_struct abort_scan;
1179
1180 struct il_rxon_context *beacon_ctx;
1181 struct sk_buff *beacon_skb;
1182
1183 struct work_struct tx_flush;
1184
1185 struct tasklet_struct irq_tasklet;
1186
1187 struct delayed_work init_alive_start;
1188 struct delayed_work alive_start;
1189 struct delayed_work scan_check;
1190
1191 /* TX Power */
1192 s8 tx_power_user_lmt;
1193 s8 tx_power_device_lmt;
1194 s8 tx_power_next;
1195
1196
1197#ifdef CONFIG_IWLEGACY_DEBUG
1198 /* debugging info */
1199 u32 debug_level; /* per device debugging will override global
1200 il_debug_level if set */
1201#endif /* CONFIG_IWLEGACY_DEBUG */
1202#ifdef CONFIG_IWLEGACY_DEBUGFS
1203 /* debugfs */
1204 u16 tx_traffic_idx;
1205 u16 rx_traffic_idx;
1206 u8 *tx_traffic;
1207 u8 *rx_traffic;
1208 struct dentry *debugfs_dir;
1209 u32 dbgfs_sram_offset, dbgfs_sram_len;
1210 bool disable_ht40;
1211#endif /* CONFIG_IWLEGACY_DEBUGFS */
1212
1213 struct work_struct txpower_work;
1214 u32 disable_sens_cal;
1215 u32 disable_chain_noise_cal;
1216 u32 disable_tx_power_cal;
1217 struct work_struct run_time_calib_work;
1218 struct timer_list stats_periodic;
1219 struct timer_list watchdog;
1220 bool hw_ready;
1221
1222 struct led_classdev led;
1223 unsigned long blink_on, blink_off;
1224 bool led_registered;
1225}; /*il_priv */
1226
1227static inline void il_txq_ctx_activate(struct il_priv *il, int txq_id)
1228{
1229 set_bit(txq_id, &il->txq_ctx_active_msk);
1230}
1231
1232static inline void il_txq_ctx_deactivate(struct il_priv *il, int txq_id)
1233{
1234 clear_bit(txq_id, &il->txq_ctx_active_msk);
1235}
1236
1237#ifdef CONFIG_IWLEGACY_DEBUG
1238/*
1239 * il_get_debug_level: Return active debug level for device
1240 *
1241 * Using sysfs it is possible to set per device debug level. This debug
1242 * level will be used if set, otherwise the global debug level which can be
1243 * set via module parameter is used.
1244 */
1245static inline u32 il_get_debug_level(struct il_priv *il)
1246{
1247 if (il->debug_level)
1248 return il->debug_level;
1249 else
1250 return il_debug_level;
1251}
1252#else
1253static inline u32 il_get_debug_level(struct il_priv *il)
1254{
1255 return il_debug_level;
1256}
1257#endif
1258
1259
1260static inline struct ieee80211_hdr *
1261il_tx_queue_get_hdr(struct il_priv *il,
1262 int txq_id, int idx)
1263{
1264 if (il->txq[txq_id].txb[idx].skb)
1265 return (struct ieee80211_hdr *)il->txq[txq_id].
1266 txb[idx].skb->data;
1267 return NULL;
1268}
1269
1270static inline struct il_rxon_context *
1271il_rxon_ctx_from_vif(struct ieee80211_vif *vif)
1272{
1273 struct il_vif_priv *vif_priv = (void *)vif->drv_priv;
1274
1275 return vif_priv->ctx;
1276}
1277
1278#define for_each_context(il, _ctx) \
1279 for (_ctx = &il->ctx; _ctx == &il->ctx; _ctx++)
1280
1281static inline int il_is_associated(struct il_priv *il)
1282{
1283 return (il->ctx.active.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0;
1284}
1285
1286static inline int il_is_any_associated(struct il_priv *il)
1287{
1288 return il_is_associated(il);
1289}
1290
1291static inline int il_is_associated_ctx(struct il_rxon_context *ctx)
1292{
1293 return (ctx->active.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0;
1294}
1295
1296static inline int il_is_channel_valid(const struct il_channel_info *ch_info)
1297{
1298 if (ch_info == NULL)
1299 return 0;
1300 return (ch_info->flags & EEPROM_CHANNEL_VALID) ? 1 : 0;
1301}
1302
1303static inline int il_is_channel_radar(const struct il_channel_info *ch_info)
1304{
1305 return (ch_info->flags & EEPROM_CHANNEL_RADAR) ? 1 : 0;
1306}
1307
1308static inline u8 il_is_channel_a_band(const struct il_channel_info *ch_info)
1309{
1310 return ch_info->band == IEEE80211_BAND_5GHZ;
1311}
1312
1313static inline int
1314il_is_channel_passive(const struct il_channel_info *ch)
1315{
1316 return (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) ? 1 : 0;
1317}
1318
1319static inline int
1320il_is_channel_ibss(const struct il_channel_info *ch)
1321{
1322 return (ch->flags & EEPROM_CHANNEL_IBSS) ? 1 : 0;
1323}
1324
1325static inline void
1326__il_free_pages(struct il_priv *il, struct page *page)
1327{
1328 __free_pages(page, il->hw_params.rx_page_order);
1329 il->alloc_rxb_page--;
1330}
1331
1332static inline void il_free_pages(struct il_priv *il, unsigned long page)
1333{
1334 free_pages(page, il->hw_params.rx_page_order);
1335 il->alloc_rxb_page--;
1336}
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001337
1338#define IWLWIFI_VERSION "in-tree:"
1339#define DRV_COPYRIGHT "Copyright(c) 2003-2011 Intel Corporation"
1340#define DRV_AUTHOR "<ilw@linux.intel.com>"
1341
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001342#define IL_PCI_DEVICE(dev, subdev, cfg) \
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001343 .vendor = PCI_VENDOR_ID_INTEL, .device = (dev), \
1344 .subvendor = PCI_ANY_ID, .subdevice = (subdev), \
1345 .driver_data = (kernel_ulong_t)&(cfg)
1346
1347#define TIME_UNIT 1024
1348
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001349#define IL_SKU_G 0x1
1350#define IL_SKU_A 0x2
1351#define IL_SKU_N 0x8
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001352
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001353#define IL_CMD(x) case x: return #x
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001354
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +02001355/* Size of one Rx buffer in host DRAM */
1356#define IL_RX_BUF_SIZE_3K (3 * 1000) /* 3945 only */
1357#define IL_RX_BUF_SIZE_4K (4 * 1024)
1358#define IL_RX_BUF_SIZE_8K (8 * 1024)
1359
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001360struct il_hcmd_ops {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001361 int (*rxon_assoc)(struct il_priv *il, struct il_rxon_context *ctx);
1362 int (*commit_rxon)(struct il_priv *il, struct il_rxon_context *ctx);
1363 void (*set_rxon_chain)(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001364 struct il_rxon_context *ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001365};
1366
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001367struct il_hcmd_utils_ops {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001368 u16 (*get_hcmd_size)(u8 cmd_id, u16 len);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001369 u16 (*build_addsta_hcmd)(const struct il_addsta_cmd *cmd,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001370 u8 *data);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001371 int (*request_scan)(struct il_priv *il, struct ieee80211_vif *vif);
1372 void (*post_scan)(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001373};
1374
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001375struct il_apm_ops {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001376 int (*init)(struct il_priv *il);
1377 void (*config)(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001378};
1379
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001380struct il_debugfs_ops {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001381 ssize_t (*rx_stats_read)(struct file *file, char __user *user_buf,
1382 size_t count, loff_t *ppos);
1383 ssize_t (*tx_stats_read)(struct file *file, char __user *user_buf,
1384 size_t count, loff_t *ppos);
1385 ssize_t (*general_stats_read)(struct file *file, char __user *user_buf,
1386 size_t count, loff_t *ppos);
1387};
1388
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001389struct il_temp_ops {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001390 void (*temperature)(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001391};
1392
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001393struct il_lib_ops {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001394 /* set hw dependent parameters */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001395 int (*set_hw_params)(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001396 /* Handling TX */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001397 void (*txq_update_byte_cnt_tbl)(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001398 struct il_tx_queue *txq,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001399 u16 byte_cnt);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001400 int (*txq_attach_buf_to_tfd)(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001401 struct il_tx_queue *txq,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001402 dma_addr_t addr,
1403 u16 len, u8 reset, u8 pad);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001404 void (*txq_free_tfd)(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001405 struct il_tx_queue *txq);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001406 int (*txq_init)(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001407 struct il_tx_queue *txq);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001408 /* setup Rx handler */
Stanislaw Gruszkad0c72342011-08-30 15:39:42 +02001409 void (*handler_setup)(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001410 /* alive notification after init uCode load */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001411 void (*init_alive_start)(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001412 /* check validity of rtc data address */
1413 int (*is_valid_rtc_data_addr)(u32 addr);
1414 /* 1st ucode load */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001415 int (*load_ucode)(struct il_priv *il);
Stanislaw Gruszka1ba2f122011-06-08 15:28:27 +02001416
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001417 void (*dump_nic_error_log)(struct il_priv *il);
1418 int (*dump_fh)(struct il_priv *il, char **buf, bool display);
1419 int (*set_channel_switch)(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001420 struct ieee80211_channel_switch *ch_switch);
1421 /* power management */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001422 struct il_apm_ops apm_ops;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001423
1424 /* power */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001425 int (*send_tx_power) (struct il_priv *il);
1426 void (*update_chain_flags)(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001427
1428 /* eeprom operations (as defined in iwl-eeprom.h) */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001429 struct il_eeprom_ops eeprom_ops;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001430
1431 /* temperature */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001432 struct il_temp_ops temp_ops;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001433
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001434 struct il_debugfs_ops debugfs_ops;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001435
1436};
1437
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001438struct il_led_ops {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001439 int (*cmd)(struct il_priv *il, struct il_led_cmd *led_cmd);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001440};
1441
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001442struct il_legacy_ops {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001443 void (*post_associate)(struct il_priv *il);
1444 void (*config_ap)(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001445 /* station management */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001446 int (*update_bcast_stations)(struct il_priv *il);
1447 int (*manage_ibss_station)(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001448 struct ieee80211_vif *vif, bool add);
1449};
1450
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001451struct il_ops {
1452 const struct il_lib_ops *lib;
1453 const struct il_hcmd_ops *hcmd;
1454 const struct il_hcmd_utils_ops *utils;
1455 const struct il_led_ops *led;
1456 const struct il_nic_ops *nic;
1457 const struct il_legacy_ops *legacy;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001458 const struct ieee80211_ops *ieee80211_ops;
1459};
1460
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001461struct il_mod_params {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001462 int sw_crypto; /* def: 0 = using hardware encryption */
1463 int disable_hw_scan; /* def: 0 = use h/w scan */
1464 int num_of_queues; /* def: HW dependent */
1465 int disable_11n; /* def: 0 = 11n capabilities enabled */
1466 int amsdu_size_8K; /* def: 1 = enable 8K amsdu size */
1467 int antenna; /* def: 0 = both antennas (use diversity) */
1468 int restart_fw; /* def: 1 = restart firmware */
1469};
1470
1471/*
1472 * @led_compensation: compensate on the led on/off time per HW according
1473 * to the deviation to achieve the desired led frequency.
1474 * The detail algorithm is described in iwl-led.c
1475 * @chain_noise_num_beacons: number of beacons used to compute chain noise
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001476 * @wd_timeout: TX queues watchdog timeout
1477 * @temperature_kelvin: temperature report by uCode in kelvin
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001478 * @ucode_tracing: support ucode continuous tracing
1479 * @sensitivity_calib_by_driver: driver has the capability to perform
1480 * sensitivity calibration operation
1481 * @chain_noise_calib_by_driver: driver has the capability to perform
1482 * chain noise calibration operation
1483 */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001484struct il_base_params {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001485 int eeprom_size;
1486 int num_of_queues; /* def: HW dependent */
1487 int num_of_ampdu_queues;/* def: HW dependent */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001488 /* for il_apm_init() */
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001489 u32 pll_cfg_val;
1490 bool set_l0s;
1491 bool use_bsm;
1492
1493 u16 led_compensation;
1494 int chain_noise_num_beacons;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001495 unsigned int wd_timeout;
1496 bool temperature_kelvin;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001497 const bool ucode_tracing;
1498 const bool sensitivity_calib_by_driver;
1499 const bool chain_noise_calib_by_driver;
1500};
1501
1502/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001503 * struct il_cfg
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001504 * @fw_name_pre: Firmware filename prefix. The api version and extension
1505 * (.ucode) will be added to filename before loading from disk. The
1506 * filename is constructed as fw_name_pre<api>.ucode.
1507 * @ucode_api_max: Highest version of uCode API supported by driver.
1508 * @ucode_api_min: Lowest version of uCode API supported by driver.
1509 * @scan_antennas: available antenna for scan operation
1510 * @led_mode: 0=blinking, 1=On(RF On)/Off(RF Off)
1511 *
1512 * We enable the driver to be backward compatible wrt API version. The
1513 * driver specifies which APIs it supports (with @ucode_api_max being the
1514 * highest and @ucode_api_min the lowest). Firmware will only be loaded if
1515 * it has a supported API version. The firmware's API version will be
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001516 * stored in @il_priv, enabling the driver to make runtime changes based
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001517 * on firmware version used.
1518 *
1519 * For example,
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001520 * if (IL_UCODE_API(il->ucode_ver) >= 2) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001521 * Driver interacts with Firmware API version >= 2.
1522 * } else {
1523 * Driver interacts with Firmware API version 1.
1524 * }
1525 *
1526 * The ideal usage of this infrastructure is to treat a new ucode API
1527 * release as a new hardware revision. That is, through utilizing the
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001528 * il_hcmd_utils_ops etc. we accommodate different command structures
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001529 * and flows between hardware versions as well as their API
1530 * versions.
1531 *
1532 */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001533struct il_cfg {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001534 /* params specific to an individual device within a device family */
1535 const char *name;
1536 const char *fw_name_pre;
1537 const unsigned int ucode_api_max;
1538 const unsigned int ucode_api_min;
1539 u8 valid_tx_ant;
1540 u8 valid_rx_ant;
1541 unsigned int sku;
1542 u16 eeprom_ver;
1543 u16 eeprom_calib_ver;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001544 const struct il_ops *ops;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001545 /* module based parameters which can be set from modprobe cmd */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001546 const struct il_mod_params *mod_params;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001547 /* params not likely to change within a device family */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001548 struct il_base_params *base_params;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001549 /* params likely to change within a device family */
1550 u8 scan_rx_antennas[IEEE80211_NUM_BANDS];
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001551 enum il_led_mode led_mode;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001552};
1553
1554/***************************
1555 * L i b *
1556 ***************************/
1557
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001558struct ieee80211_hw *il_alloc_all(struct il_cfg *cfg);
1559int il_mac_conf_tx(struct ieee80211_hw *hw,
Eliad Peller8a3a3c82011-10-02 10:15:52 +02001560 struct ieee80211_vif *vif, u16 queue,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001561 const struct ieee80211_tx_queue_params *params);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001562int il_mac_tx_last_beacon(struct ieee80211_hw *hw);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001563void il_set_rxon_hwcrypto(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001564 struct il_rxon_context *ctx,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001565 int hw_decrypt);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001566int il_check_rxon_cmd(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001567 struct il_rxon_context *ctx);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001568int il_full_rxon_required(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001569 struct il_rxon_context *ctx);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001570int il_set_rxon_channel(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001571 struct ieee80211_channel *ch,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001572 struct il_rxon_context *ctx);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001573void il_set_flags_for_band(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001574 struct il_rxon_context *ctx,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001575 enum ieee80211_band band,
1576 struct ieee80211_vif *vif);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001577u8 il_get_single_channel_number(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001578 enum ieee80211_band band);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001579void il_set_rxon_ht(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001580 struct il_ht_config *ht_conf);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001581bool il_is_ht40_tx_allowed(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001582 struct il_rxon_context *ctx,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001583 struct ieee80211_sta_ht_cap *ht_cap);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001584void il_connection_init_rx_config(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001585 struct il_rxon_context *ctx);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001586void il_set_rate(struct il_priv *il);
1587int il_set_decrypted_flag(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001588 struct ieee80211_hdr *hdr,
1589 u32 decrypt_res,
1590 struct ieee80211_rx_status *stats);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001591void il_irq_handle_error(struct il_priv *il);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001592int il_mac_add_interface(struct ieee80211_hw *hw,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001593 struct ieee80211_vif *vif);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001594void il_mac_remove_interface(struct ieee80211_hw *hw,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001595 struct ieee80211_vif *vif);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001596int il_mac_change_interface(struct ieee80211_hw *hw,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001597 struct ieee80211_vif *vif,
1598 enum nl80211_iftype newtype, bool newp2p);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001599int il_alloc_txq_mem(struct il_priv *il);
1600void il_txq_mem(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001601
Stanislaw Gruszkad3175162011-11-15 11:25:42 +01001602#ifdef CONFIG_IWLEGACY_DEBUGFS
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001603int il_alloc_traffic_mem(struct il_priv *il);
1604void il_free_traffic_mem(struct il_priv *il);
1605void il_reset_traffic_log(struct il_priv *il);
1606void il_dbg_log_tx_data_frame(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001607 u16 length, struct ieee80211_hdr *header);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001608void il_dbg_log_rx_data_frame(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001609 u16 length, struct ieee80211_hdr *header);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001610const char *il_get_mgmt_string(int cmd);
1611const char *il_get_ctrl_string(int cmd);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001612void il_clear_traffic_stats(struct il_priv *il);
1613void il_update_stats(struct il_priv *il, bool is_tx, __le16 fc,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001614 u16 len);
1615#else
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001616static inline int il_alloc_traffic_mem(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001617{
1618 return 0;
1619}
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001620static inline void il_free_traffic_mem(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001621{
1622}
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001623static inline void il_reset_traffic_log(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001624{
1625}
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001626static inline void il_dbg_log_tx_data_frame(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001627 u16 length, struct ieee80211_hdr *header)
1628{
1629}
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001630static inline void il_dbg_log_rx_data_frame(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001631 u16 length, struct ieee80211_hdr *header)
1632{
1633}
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001634static inline void il_update_stats(struct il_priv *il, bool is_tx,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001635 __le16 fc, u16 len)
1636{
1637}
1638#endif
1639/*****************************************************
1640 * RX handlers.
1641 * **************************************************/
Stanislaw Gruszkad2dfb332011-11-15 13:16:38 +01001642void il_hdl_pm_sleep(struct il_priv *il,
Stanislaw Gruszkab73bb5f2011-08-26 14:37:54 +02001643 struct il_rx_buf *rxb);
Stanislaw Gruszkad2dfb332011-11-15 13:16:38 +01001644void il_hdl_pm_debug_stats(struct il_priv *il,
Stanislaw Gruszkab73bb5f2011-08-26 14:37:54 +02001645 struct il_rx_buf *rxb);
Stanislaw Gruszka6e9848b42011-08-30 15:45:31 +02001646void il_hdl_error(struct il_priv *il,
Stanislaw Gruszkab73bb5f2011-08-26 14:37:54 +02001647 struct il_rx_buf *rxb);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001648
1649/*****************************************************
1650* RX
1651******************************************************/
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001652void il_cmd_queue_unmap(struct il_priv *il);
1653void il_cmd_queue_free(struct il_priv *il);
1654int il_rx_queue_alloc(struct il_priv *il);
1655void il_rx_queue_update_write_ptr(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001656 struct il_rx_queue *q);
1657int il_rx_queue_space(const struct il_rx_queue *q);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001658void il_tx_cmd_complete(struct il_priv *il,
Stanislaw Gruszkab73bb5f2011-08-26 14:37:54 +02001659 struct il_rx_buf *rxb);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001660/* Handlers */
Stanislaw Gruszkad2dfb332011-11-15 13:16:38 +01001661void il_hdl_spectrum_measurement(struct il_priv *il,
Stanislaw Gruszkab73bb5f2011-08-26 14:37:54 +02001662 struct il_rx_buf *rxb);
Stanislaw Gruszkaebf0d902011-08-26 15:43:47 +02001663void il_recover_from_stats(struct il_priv *il,
Stanislaw Gruszkadcae1c62011-08-26 14:36:21 +02001664 struct il_rx_pkt *pkt);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001665void il_chswitch_done(struct il_priv *il, bool is_success);
Stanislaw Gruszkad2dfb332011-11-15 13:16:38 +01001666void il_hdl_csa(struct il_priv *il, struct il_rx_buf *rxb);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001667
1668/* TX helpers */
1669
1670/*****************************************************
1671* TX
1672******************************************************/
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001673void il_txq_update_write_ptr(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001674 struct il_tx_queue *txq);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001675int il_tx_queue_init(struct il_priv *il, struct il_tx_queue *txq,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001676 int slots_num, u32 txq_id);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001677void il_tx_queue_reset(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001678 struct il_tx_queue *txq,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001679 int slots_num, u32 txq_id);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001680void il_tx_queue_unmap(struct il_priv *il, int txq_id);
1681void il_tx_queue_free(struct il_priv *il, int txq_id);
1682void il_setup_watchdog(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001683/*****************************************************
1684 * TX power
1685 ****************************************************/
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001686int il_set_tx_power(struct il_priv *il, s8 tx_power, bool force);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001687
1688/*******************************************************************************
1689 * Rate
1690 ******************************************************************************/
1691
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001692u8 il_get_lowest_plcp(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001693 struct il_rxon_context *ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001694
1695/*******************************************************************************
1696 * Scanning
1697 ******************************************************************************/
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001698void il_init_scan_params(struct il_priv *il);
1699int il_scan_cancel(struct il_priv *il);
1700int il_scan_cancel_timeout(struct il_priv *il, unsigned long ms);
1701void il_force_scan_end(struct il_priv *il);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001702int il_mac_hw_scan(struct ieee80211_hw *hw,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001703 struct ieee80211_vif *vif,
1704 struct cfg80211_scan_request *req);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001705void il_internal_short_hw_scan(struct il_priv *il);
1706int il_force_reset(struct il_priv *il, bool external);
1707u16 il_fill_probe_req(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001708 struct ieee80211_mgmt *frame,
1709 const u8 *ta, const u8 *ie, int ie_len, int left);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001710void il_setup_rx_scan_handlers(struct il_priv *il);
1711u16 il_get_active_dwell_time(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001712 enum ieee80211_band band,
1713 u8 n_probes);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001714u16 il_get_passive_dwell_time(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001715 enum ieee80211_band band,
1716 struct ieee80211_vif *vif);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001717void il_setup_scan_deferred_work(struct il_priv *il);
1718void il_cancel_scan_deferred_work(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001719
1720/* For faster active scanning, scan will move to the next channel if fewer than
1721 * PLCP_QUIET_THRESH packets are heard on this channel within
1722 * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
1723 * time if it's a quiet channel (nothing responded to our probe, and there's
1724 * no other traffic).
1725 * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001726#define IL_ACTIVE_QUIET_TIME cpu_to_le16(10) /* msec */
1727#define IL_PLCP_QUIET_THRESH cpu_to_le16(1) /* packets */
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001728
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001729#define IL_SCAN_CHECK_WATCHDOG (HZ * 7)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001730
1731/*****************************************************
1732 * S e n d i n g H o s t C o m m a n d s *
1733 *****************************************************/
1734
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001735const char *il_get_cmd_string(u8 cmd);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001736int __must_check il_send_cmd_sync(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001737 struct il_host_cmd *cmd);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001738int il_send_cmd(struct il_priv *il, struct il_host_cmd *cmd);
1739int __must_check il_send_cmd_pdu(struct il_priv *il, u8 id,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001740 u16 len, const void *data);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001741int il_send_cmd_pdu_async(struct il_priv *il, u8 id, u16 len,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001742 const void *data,
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001743 void (*callback)(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001744 struct il_device_cmd *cmd,
Stanislaw Gruszkadcae1c62011-08-26 14:36:21 +02001745 struct il_rx_pkt *pkt));
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001746
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001747int il_enqueue_hcmd(struct il_priv *il, struct il_host_cmd *cmd);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001748
1749
1750/*****************************************************
1751 * PCI *
1752 *****************************************************/
1753
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001754static inline u16 il_pcie_link_ctl(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001755{
1756 int pos;
1757 u16 pci_lnk_ctl;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001758 pos = pci_pcie_cap(il->pci_dev);
1759 pci_read_config_word(il->pci_dev, pos + PCI_EXP_LNKCTL, &pci_lnk_ctl);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001760 return pci_lnk_ctl;
1761}
1762
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001763void il_bg_watchdog(unsigned long data);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001764u32 il_usecs_to_beacons(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001765 u32 usec, u32 beacon_interval);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001766__le32 il_add_beacon_time(struct il_priv *il, u32 base,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001767 u32 addon, u32 beacon_interval);
1768
1769#ifdef CONFIG_PM
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001770int il_pci_suspend(struct device *device);
1771int il_pci_resume(struct device *device);
1772extern const struct dev_pm_ops il_pm_ops;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001773
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001774#define IL_LEGACY_PM_OPS (&il_pm_ops)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001775
1776#else /* !CONFIG_PM */
1777
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001778#define IL_LEGACY_PM_OPS NULL
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001779
1780#endif /* !CONFIG_PM */
1781
1782/*****************************************************
1783* Error Handling Debugging
1784******************************************************/
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001785void il4965_dump_nic_error_log(struct il_priv *il);
Stanislaw Gruszkad3175162011-11-15 11:25:42 +01001786#ifdef CONFIG_IWLEGACY_DEBUG
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001787void il_print_rx_config_cmd(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001788 struct il_rxon_context *ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001789#else
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001790static inline void il_print_rx_config_cmd(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001791 struct il_rxon_context *ctx)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001792{
1793}
1794#endif
1795
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001796void il_clear_isr_stats(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001797
1798/*****************************************************
1799* GEOS
1800******************************************************/
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001801int il_init_geos(struct il_priv *il);
1802void il_free_geos(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001803
1804/*************** DRIVER STATUS FUNCTIONS *****/
1805
Stanislaw Gruszkaa6766cc2011-11-15 13:09:01 +01001806#define S_HCMD_ACTIVE 0 /* host command in progress */
1807/* 1 is unused (used to be S_HCMD_SYNC_ACTIVE) */
1808#define S_INT_ENABLED 2
1809#define S_RF_KILL_HW 3
1810#define S_CT_KILL 4
1811#define S_INIT 5
1812#define S_ALIVE 6
1813#define S_READY 7
1814#define S_TEMPERATURE 8
1815#define S_GEO_CONFIGURED 9
1816#define S_EXIT_PENDING 10
Stanislaw Gruszkadb7746f2011-11-15 13:11:50 +01001817#define S_STATS 12
Stanislaw Gruszkaa6766cc2011-11-15 13:09:01 +01001818#define S_SCANNING 13
1819#define S_SCAN_ABORTING 14
1820#define S_SCAN_HW 15
1821#define S_POWER_PMI 16
1822#define S_FW_ERROR 17
1823#define S_CHANNEL_SWITCH_PENDING 18
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001824
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001825static inline int il_is_ready(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001826{
1827 /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are
1828 * set but EXIT_PENDING is not */
Stanislaw Gruszkaa6766cc2011-11-15 13:09:01 +01001829 return test_bit(S_READY, &il->status) &&
1830 test_bit(S_GEO_CONFIGURED, &il->status) &&
1831 !test_bit(S_EXIT_PENDING, &il->status);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001832}
1833
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001834static inline int il_is_alive(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001835{
Stanislaw Gruszkaa6766cc2011-11-15 13:09:01 +01001836 return test_bit(S_ALIVE, &il->status);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001837}
1838
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001839static inline int il_is_init(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001840{
Stanislaw Gruszkaa6766cc2011-11-15 13:09:01 +01001841 return test_bit(S_INIT, &il->status);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001842}
1843
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001844static inline int il_is_rfkill_hw(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001845{
Stanislaw Gruszkaa6766cc2011-11-15 13:09:01 +01001846 return test_bit(S_RF_KILL_HW, &il->status);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001847}
1848
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001849static inline int il_is_rfkill(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001850{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001851 return il_is_rfkill_hw(il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001852}
1853
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001854static inline int il_is_ctkill(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001855{
Stanislaw Gruszkaa6766cc2011-11-15 13:09:01 +01001856 return test_bit(S_CT_KILL, &il->status);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001857}
1858
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001859static inline int il_is_ready_rf(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001860{
1861
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001862 if (il_is_rfkill(il))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001863 return 0;
1864
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001865 return il_is_ready(il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001866}
1867
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001868extern void il_send_bt_config(struct il_priv *il);
Stanislaw Gruszkaebf0d902011-08-26 15:43:47 +02001869extern int il_send_stats_request(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001870 u8 flags, bool clear);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001871void il_apm_stop(struct il_priv *il);
1872int il_apm_init(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001873
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001874int il_send_rxon_timing(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001875 struct il_rxon_context *ctx);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001876static inline int il_send_rxon_assoc(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001877 struct il_rxon_context *ctx)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001878{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001879 return il->cfg->ops->hcmd->rxon_assoc(il, ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001880}
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001881static inline int il_commit_rxon(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001882 struct il_rxon_context *ctx)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001883{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001884 return il->cfg->ops->hcmd->commit_rxon(il, ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001885}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001886static inline const struct ieee80211_supported_band *il_get_hw_mode(
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001887 struct il_priv *il, enum ieee80211_band band)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001888{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001889 return il->hw->wiphy->bands[band];
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001890}
1891
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001892/* mac80211 handlers */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001893int il_mac_config(struct ieee80211_hw *hw, u32 changed);
1894void il_mac_reset_tsf(struct ieee80211_hw *hw,
Eliad Peller37a41b42011-09-21 14:06:11 +03001895 struct ieee80211_vif *vif);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001896void il_mac_bss_info_changed(struct ieee80211_hw *hw,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001897 struct ieee80211_vif *vif,
1898 struct ieee80211_bss_conf *bss_conf,
1899 u32 changes);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001900void il_tx_cmd_protection(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001901 struct ieee80211_tx_info *info,
1902 __le16 fc, __le32 *tx_flags);
1903
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001904irqreturn_t il_isr(int irq, void *data);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001905
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +02001906
1907#include <linux/io.h>
1908
1909static inline void _il_write8(struct il_priv *il, u32 ofs, u8 val)
1910{
1911 iowrite8(val, il->hw_base + ofs);
1912}
1913#define il_write8(il, ofs, val) _il_write8(il, ofs, val)
1914
1915static inline void _il_wr(struct il_priv *il, u32 ofs, u32 val)
1916{
1917 iowrite32(val, il->hw_base + ofs);
1918}
1919
1920static inline u32 _il_rd(struct il_priv *il, u32 ofs)
1921{
1922 return ioread32(il->hw_base + ofs);
1923}
1924
1925#define IL_POLL_INTERVAL 10 /* microseconds */
1926static inline int
1927_il_poll_bit(struct il_priv *il, u32 addr,
1928 u32 bits, u32 mask, int timeout)
1929{
1930 int t = 0;
1931
1932 do {
1933 if ((_il_rd(il, addr) & mask) == (bits & mask))
1934 return t;
1935 udelay(IL_POLL_INTERVAL);
1936 t += IL_POLL_INTERVAL;
1937 } while (t < timeout);
1938
1939 return -ETIMEDOUT;
1940}
1941
1942static inline void _il_set_bit(struct il_priv *il, u32 reg, u32 mask)
1943{
1944 _il_wr(il, reg, _il_rd(il, reg) | mask);
1945}
1946
1947static inline void il_set_bit(struct il_priv *p, u32 r, u32 m)
1948{
1949 unsigned long reg_flags;
1950
1951 spin_lock_irqsave(&p->reg_lock, reg_flags);
1952 _il_set_bit(p, r, m);
1953 spin_unlock_irqrestore(&p->reg_lock, reg_flags);
1954}
1955
1956static inline void
1957_il_clear_bit(struct il_priv *il, u32 reg, u32 mask)
1958{
1959 _il_wr(il, reg, _il_rd(il, reg) & ~mask);
1960}
1961
1962static inline void il_clear_bit(struct il_priv *p, u32 r, u32 m)
1963{
1964 unsigned long reg_flags;
1965
1966 spin_lock_irqsave(&p->reg_lock, reg_flags);
1967 _il_clear_bit(p, r, m);
1968 spin_unlock_irqrestore(&p->reg_lock, reg_flags);
1969}
1970
1971static inline int _il_grab_nic_access(struct il_priv *il)
1972{
1973 int ret;
1974 u32 val;
1975
1976 /* this bit wakes up the NIC */
1977 _il_set_bit(il, CSR_GP_CNTRL,
1978 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
1979
1980 /*
1981 * These bits say the device is running, and should keep running for
1982 * at least a short while (at least as long as MAC_ACCESS_REQ stays 1),
1983 * but they do not indicate that embedded SRAM is restored yet;
1984 * 3945 and 4965 have volatile SRAM, and must save/restore contents
1985 * to/from host DRAM when sleeping/waking for power-saving.
1986 * Each direction takes approximately 1/4 millisecond; with this
1987 * overhead, it's a good idea to grab and hold MAC_ACCESS_REQUEST if a
1988 * series of register accesses are expected (e.g. reading Event Log),
1989 * to keep device from sleeping.
1990 *
1991 * CSR_UCODE_DRV_GP1 register bit MAC_SLEEP == 0 indicates that
1992 * SRAM is okay/restored. We don't check that here because this call
1993 * is just for hardware register access; but GP1 MAC_SLEEP check is a
1994 * good idea before accessing 3945/4965 SRAM (e.g. reading Event Log).
1995 *
1996 */
1997 ret = _il_poll_bit(il, CSR_GP_CNTRL,
1998 CSR_GP_CNTRL_REG_VAL_MAC_ACCESS_EN,
1999 (CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY |
2000 CSR_GP_CNTRL_REG_FLAG_GOING_TO_SLEEP), 15000);
2001 if (ret < 0) {
2002 val = _il_rd(il, CSR_GP_CNTRL);
2003 IL_ERR(
2004 "MAC is in deep sleep!. CSR_GP_CNTRL = 0x%08X\n", val);
2005 _il_wr(il, CSR_RESET,
2006 CSR_RESET_REG_FLAG_FORCE_NMI);
2007 return -EIO;
2008 }
2009
2010 return 0;
2011}
2012
2013static inline void _il_release_nic_access(struct il_priv *il)
2014{
2015 _il_clear_bit(il, CSR_GP_CNTRL,
2016 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
2017}
2018
2019static inline u32 il_rd(struct il_priv *il, u32 reg)
2020{
2021 u32 value;
2022 unsigned long reg_flags;
2023
2024 spin_lock_irqsave(&il->reg_lock, reg_flags);
2025 _il_grab_nic_access(il);
2026 value = _il_rd(il, reg);
2027 _il_release_nic_access(il);
2028 spin_unlock_irqrestore(&il->reg_lock, reg_flags);
2029 return value;
2030
2031}
2032
2033static inline void
2034il_wr(struct il_priv *il, u32 reg, u32 value)
2035{
2036 unsigned long reg_flags;
2037
2038 spin_lock_irqsave(&il->reg_lock, reg_flags);
2039 if (!_il_grab_nic_access(il)) {
2040 _il_wr(il, reg, value);
2041 _il_release_nic_access(il);
2042 }
2043 spin_unlock_irqrestore(&il->reg_lock, reg_flags);
2044}
2045
2046static inline void il_write_reg_buf(struct il_priv *il,
2047 u32 reg, u32 len, u32 *values)
2048{
2049 u32 count = sizeof(u32);
2050
2051 if (il != NULL && values != NULL) {
2052 for (; 0 < len; len -= count, reg += count, values++)
2053 il_wr(il, reg, *values);
2054 }
2055}
2056
2057static inline int il_poll_bit(struct il_priv *il, u32 addr,
2058 u32 mask, int timeout)
2059{
2060 int t = 0;
2061
2062 do {
2063 if ((il_rd(il, addr) & mask) == mask)
2064 return t;
2065 udelay(IL_POLL_INTERVAL);
2066 t += IL_POLL_INTERVAL;
2067 } while (t < timeout);
2068
2069 return -ETIMEDOUT;
2070}
2071
2072static inline u32 _il_rd_prph(struct il_priv *il, u32 reg)
2073{
2074 _il_wr(il, HBUS_TARG_PRPH_RADDR, reg | (3 << 24));
2075 rmb();
2076 return _il_rd(il, HBUS_TARG_PRPH_RDAT);
2077}
2078
2079static inline u32 il_rd_prph(struct il_priv *il, u32 reg)
2080{
2081 unsigned long reg_flags;
2082 u32 val;
2083
2084 spin_lock_irqsave(&il->reg_lock, reg_flags);
2085 _il_grab_nic_access(il);
2086 val = _il_rd_prph(il, reg);
2087 _il_release_nic_access(il);
2088 spin_unlock_irqrestore(&il->reg_lock, reg_flags);
2089 return val;
2090}
2091
2092static inline void _il_wr_prph(struct il_priv *il,
2093 u32 addr, u32 val)
2094{
2095 _il_wr(il, HBUS_TARG_PRPH_WADDR,
2096 ((addr & 0x0000FFFF) | (3 << 24)));
2097 wmb();
2098 _il_wr(il, HBUS_TARG_PRPH_WDAT, val);
2099}
2100
2101static inline void
2102il_wr_prph(struct il_priv *il, u32 addr, u32 val)
2103{
2104 unsigned long reg_flags;
2105
2106 spin_lock_irqsave(&il->reg_lock, reg_flags);
2107 if (!_il_grab_nic_access(il)) {
2108 _il_wr_prph(il, addr, val);
2109 _il_release_nic_access(il);
2110 }
2111 spin_unlock_irqrestore(&il->reg_lock, reg_flags);
2112}
2113
2114#define _il_set_bits_prph(il, reg, mask) \
2115_il_wr_prph(il, reg, (_il_rd_prph(il, reg) | mask))
2116
2117static inline void
2118il_set_bits_prph(struct il_priv *il, u32 reg, u32 mask)
2119{
2120 unsigned long reg_flags;
2121
2122 spin_lock_irqsave(&il->reg_lock, reg_flags);
2123 _il_grab_nic_access(il);
2124 _il_set_bits_prph(il, reg, mask);
2125 _il_release_nic_access(il);
2126 spin_unlock_irqrestore(&il->reg_lock, reg_flags);
2127}
2128
2129#define _il_set_bits_mask_prph(il, reg, bits, mask) \
2130_il_wr_prph(il, reg, \
2131 ((_il_rd_prph(il, reg) & mask) | bits))
2132
2133static inline void il_set_bits_mask_prph(struct il_priv *il, u32 reg,
2134 u32 bits, u32 mask)
2135{
2136 unsigned long reg_flags;
2137
2138 spin_lock_irqsave(&il->reg_lock, reg_flags);
2139 _il_grab_nic_access(il);
2140 _il_set_bits_mask_prph(il, reg, bits, mask);
2141 _il_release_nic_access(il);
2142 spin_unlock_irqrestore(&il->reg_lock, reg_flags);
2143}
2144
2145static inline void il_clear_bits_prph(struct il_priv
2146 *il, u32 reg, u32 mask)
2147{
2148 unsigned long reg_flags;
2149 u32 val;
2150
2151 spin_lock_irqsave(&il->reg_lock, reg_flags);
2152 _il_grab_nic_access(il);
2153 val = _il_rd_prph(il, reg);
2154 _il_wr_prph(il, reg, (val & ~mask));
2155 _il_release_nic_access(il);
2156 spin_unlock_irqrestore(&il->reg_lock, reg_flags);
2157}
2158
2159static inline u32 il_read_targ_mem(struct il_priv *il, u32 addr)
2160{
2161 unsigned long reg_flags;
2162 u32 value;
2163
2164 spin_lock_irqsave(&il->reg_lock, reg_flags);
2165 _il_grab_nic_access(il);
2166
2167 _il_wr(il, HBUS_TARG_MEM_RADDR, addr);
2168 rmb();
2169 value = _il_rd(il, HBUS_TARG_MEM_RDAT);
2170
2171 _il_release_nic_access(il);
2172 spin_unlock_irqrestore(&il->reg_lock, reg_flags);
2173 return value;
2174}
2175
2176static inline void
2177il_write_targ_mem(struct il_priv *il, u32 addr, u32 val)
2178{
2179 unsigned long reg_flags;
2180
2181 spin_lock_irqsave(&il->reg_lock, reg_flags);
2182 if (!_il_grab_nic_access(il)) {
2183 _il_wr(il, HBUS_TARG_MEM_WADDR, addr);
2184 wmb();
2185 _il_wr(il, HBUS_TARG_MEM_WDAT, val);
2186 _il_release_nic_access(il);
2187 }
2188 spin_unlock_irqrestore(&il->reg_lock, reg_flags);
2189}
2190
2191static inline void
2192il_write_targ_mem_buf(struct il_priv *il, u32 addr,
2193 u32 len, u32 *values)
2194{
2195 unsigned long reg_flags;
2196
2197 spin_lock_irqsave(&il->reg_lock, reg_flags);
2198 if (!_il_grab_nic_access(il)) {
2199 _il_wr(il, HBUS_TARG_MEM_WADDR, addr);
2200 wmb();
2201 for (; 0 < len; len -= sizeof(u32), values++)
2202 _il_wr(il,
2203 HBUS_TARG_MEM_WDAT, *values);
2204
2205 _il_release_nic_access(il);
2206 }
2207 spin_unlock_irqrestore(&il->reg_lock, reg_flags);
2208}
2209
2210#define HW_KEY_DYNAMIC 0
2211#define HW_KEY_DEFAULT 1
2212
2213#define IL_STA_DRIVER_ACTIVE BIT(0) /* driver entry is active */
2214#define IL_STA_UCODE_ACTIVE BIT(1) /* ucode entry is active */
2215#define IL_STA_UCODE_INPROGRESS BIT(2) /* ucode entry is in process of
2216 being activated */
2217#define IL_STA_LOCAL BIT(3) /* station state not directed by mac80211;
2218 (this is for the IBSS BSSID stations) */
2219#define IL_STA_BCAST BIT(4) /* this station is the special bcast station */
2220
2221
2222void il_restore_stations(struct il_priv *il,
2223 struct il_rxon_context *ctx);
2224void il_clear_ucode_stations(struct il_priv *il,
2225 struct il_rxon_context *ctx);
2226void il_dealloc_bcast_stations(struct il_priv *il);
2227int il_get_free_ucode_key_idx(struct il_priv *il);
2228int il_send_add_sta(struct il_priv *il,
2229 struct il_addsta_cmd *sta, u8 flags);
2230int il_add_station_common(struct il_priv *il,
2231 struct il_rxon_context *ctx,
2232 const u8 *addr, bool is_ap,
2233 struct ieee80211_sta *sta, u8 *sta_id_r);
2234int il_remove_station(struct il_priv *il,
2235 const u8 sta_id,
2236 const u8 *addr);
2237int il_mac_sta_remove(struct ieee80211_hw *hw,
2238 struct ieee80211_vif *vif,
2239 struct ieee80211_sta *sta);
2240
2241u8 il_prep_station(struct il_priv *il,
2242 struct il_rxon_context *ctx,
2243 const u8 *addr, bool is_ap,
2244 struct ieee80211_sta *sta);
2245
2246int il_send_lq_cmd(struct il_priv *il,
2247 struct il_rxon_context *ctx,
2248 struct il_link_quality_cmd *lq,
2249 u8 flags, bool init);
2250
2251/**
2252 * il_clear_driver_stations - clear knowledge of all stations from driver
2253 * @il: iwl il struct
2254 *
2255 * This is called during il_down() to make sure that in the case
2256 * we're coming there from a hardware restart mac80211 will be
2257 * able to reconfigure stations -- if we're getting there in the
2258 * normal down flow then the stations will already be cleared.
2259 */
2260static inline void il_clear_driver_stations(struct il_priv *il)
2261{
2262 unsigned long flags;
2263 struct il_rxon_context *ctx = &il->ctx;
2264
2265 spin_lock_irqsave(&il->sta_lock, flags);
2266 memset(il->stations, 0, sizeof(il->stations));
2267 il->num_stations = 0;
2268
2269 il->ucode_key_table = 0;
2270
2271 /*
2272 * Remove all key information that is not stored as part
2273 * of station information since mac80211 may not have had
2274 * a chance to remove all the keys. When device is
2275 * reconfigured by mac80211 after an error all keys will
2276 * be reconfigured.
2277 */
2278 memset(ctx->wep_keys, 0, sizeof(ctx->wep_keys));
2279 ctx->key_mapping_keys = 0;
2280
2281 spin_unlock_irqrestore(&il->sta_lock, flags);
2282}
2283
2284static inline int il_sta_id(struct ieee80211_sta *sta)
2285{
2286 if (WARN_ON(!sta))
2287 return IL_INVALID_STATION;
2288
2289 return ((struct il_station_priv_common *)sta->drv_priv)->sta_id;
2290}
2291
2292/**
2293 * il_sta_id_or_broadcast - return sta_id or broadcast sta
2294 * @il: iwl il
2295 * @context: the current context
2296 * @sta: mac80211 station
2297 *
2298 * In certain circumstances mac80211 passes a station pointer
2299 * that may be %NULL, for example during TX or key setup. In
2300 * that case, we need to use the broadcast station, so this
2301 * inline wraps that pattern.
2302 */
2303static inline int il_sta_id_or_broadcast(struct il_priv *il,
2304 struct il_rxon_context *context,
2305 struct ieee80211_sta *sta)
2306{
2307 int sta_id;
2308
2309 if (!sta)
2310 return context->bcast_sta_id;
2311
2312 sta_id = il_sta_id(sta);
2313
2314 /*
2315 * mac80211 should not be passing a partially
2316 * initialised station!
2317 */
2318 WARN_ON(sta_id == IL_INVALID_STATION);
2319
2320 return sta_id;
2321}
2322
2323/**
2324 * il_queue_inc_wrap - increment queue idx, wrap back to beginning
2325 * @idx -- current idx
2326 * @n_bd -- total number of entries in queue (must be power of 2)
2327 */
2328static inline int il_queue_inc_wrap(int idx, int n_bd)
2329{
2330 return ++idx & (n_bd - 1);
2331}
2332
2333/**
2334 * il_queue_dec_wrap - decrement queue idx, wrap back to end
2335 * @idx -- current idx
2336 * @n_bd -- total number of entries in queue (must be power of 2)
2337 */
2338static inline int il_queue_dec_wrap(int idx, int n_bd)
2339{
2340 return --idx & (n_bd - 1);
2341}
2342
2343/* TODO: Move fw_desc functions to iwl-pci.ko */
2344static inline void il_free_fw_desc(struct pci_dev *pci_dev,
2345 struct fw_desc *desc)
2346{
2347 if (desc->v_addr)
2348 dma_free_coherent(&pci_dev->dev, desc->len,
2349 desc->v_addr, desc->p_addr);
2350 desc->v_addr = NULL;
2351 desc->len = 0;
2352}
2353
2354static inline int il_alloc_fw_desc(struct pci_dev *pci_dev,
2355 struct fw_desc *desc)
2356{
2357 if (!desc->len) {
2358 desc->v_addr = NULL;
2359 return -EINVAL;
2360 }
2361
2362 desc->v_addr = dma_alloc_coherent(&pci_dev->dev, desc->len,
2363 &desc->p_addr, GFP_KERNEL);
2364 return (desc->v_addr != NULL) ? 0 : -ENOMEM;
2365}
2366
2367/*
2368 * we have 8 bits used like this:
2369 *
2370 * 7 6 5 4 3 2 1 0
2371 * | | | | | | | |
2372 * | | | | | | +-+-------- AC queue (0-3)
2373 * | | | | | |
2374 * | +-+-+-+-+------------ HW queue ID
2375 * |
2376 * +---------------------- unused
2377 */
2378static inline void
2379il_set_swq_id(struct il_tx_queue *txq, u8 ac, u8 hwq)
2380{
2381 BUG_ON(ac > 3); /* only have 2 bits */
2382 BUG_ON(hwq > 31); /* only use 5 bits */
2383
2384 txq->swq_id = (hwq << 2) | ac;
2385}
2386
2387static inline void il_wake_queue(struct il_priv *il,
2388 struct il_tx_queue *txq)
2389{
2390 u8 queue = txq->swq_id;
2391 u8 ac = queue & 3;
2392 u8 hwq = (queue >> 2) & 0x1f;
2393
2394 if (test_and_clear_bit(hwq, il->queue_stopped))
2395 if (atomic_dec_return(&il->queue_stop_count[ac]) <= 0)
2396 ieee80211_wake_queue(il->hw, ac);
2397}
2398
2399static inline void il_stop_queue(struct il_priv *il,
2400 struct il_tx_queue *txq)
2401{
2402 u8 queue = txq->swq_id;
2403 u8 ac = queue & 3;
2404 u8 hwq = (queue >> 2) & 0x1f;
2405
2406 if (!test_and_set_bit(hwq, il->queue_stopped))
2407 if (atomic_inc_return(&il->queue_stop_count[ac]) > 0)
2408 ieee80211_stop_queue(il->hw, ac);
2409}
2410
2411#ifdef ieee80211_stop_queue
2412#undef ieee80211_stop_queue
2413#endif
2414
2415#define ieee80211_stop_queue DO_NOT_USE_ieee80211_stop_queue
2416
2417#ifdef ieee80211_wake_queue
2418#undef ieee80211_wake_queue
2419#endif
2420
2421#define ieee80211_wake_queue DO_NOT_USE_ieee80211_wake_queue
2422
2423static inline void il_disable_interrupts(struct il_priv *il)
2424{
2425 clear_bit(S_INT_ENABLED, &il->status);
2426
2427 /* disable interrupts from uCode/NIC to host */
2428 _il_wr(il, CSR_INT_MASK, 0x00000000);
2429
2430 /* acknowledge/clear/reset any interrupts still pending
2431 * from uCode or flow handler (Rx/Tx DMA) */
2432 _il_wr(il, CSR_INT, 0xffffffff);
2433 _il_wr(il, CSR_FH_INT_STATUS, 0xffffffff);
2434 D_ISR("Disabled interrupts\n");
2435}
2436
2437static inline void il_enable_rfkill_int(struct il_priv *il)
2438{
2439 D_ISR("Enabling rfkill interrupt\n");
2440 _il_wr(il, CSR_INT_MASK, CSR_INT_BIT_RF_KILL);
2441}
2442
2443static inline void il_enable_interrupts(struct il_priv *il)
2444{
2445 D_ISR("Enabling interrupts\n");
2446 set_bit(S_INT_ENABLED, &il->status);
2447 _il_wr(il, CSR_INT_MASK, il->inta_mask);
2448}
2449
2450/**
2451 * il_beacon_time_mask_low - mask of lower 32 bit of beacon time
2452 * @il -- pointer to il_priv data structure
2453 * @tsf_bits -- number of bits need to shift for masking)
2454 */
2455static inline u32 il_beacon_time_mask_low(struct il_priv *il,
2456 u16 tsf_bits)
2457{
2458 return (1 << tsf_bits) - 1;
2459}
2460
2461/**
2462 * il_beacon_time_mask_high - mask of higher 32 bit of beacon time
2463 * @il -- pointer to il_priv data structure
2464 * @tsf_bits -- number of bits need to shift for masking)
2465 */
2466static inline u32 il_beacon_time_mask_high(struct il_priv *il,
2467 u16 tsf_bits)
2468{
2469 return ((1 << (32 - tsf_bits)) - 1) << tsf_bits;
2470}
2471
2472/**
2473 * struct il_rb_status - reseve buffer status host memory mapped FH registers
2474 *
2475 * @closed_rb_num [0:11] - Indicates the idx of the RB which was closed
2476 * @closed_fr_num [0:11] - Indicates the idx of the RX Frame which was closed
2477 * @finished_rb_num [0:11] - Indicates the idx of the current RB
2478 * in which the last frame was written to
2479 * @finished_fr_num [0:11] - Indicates the idx of the RX Frame
2480 * which was transferred
2481 */
2482struct il_rb_status {
2483 __le16 closed_rb_num;
2484 __le16 closed_fr_num;
2485 __le16 finished_rb_num;
2486 __le16 finished_fr_nam;
2487 __le32 __unused; /* 3945 only */
2488} __packed;
2489
2490
2491#define TFD_QUEUE_SIZE_MAX (256)
2492#define TFD_QUEUE_SIZE_BC_DUP (64)
2493#define TFD_QUEUE_BC_SIZE (TFD_QUEUE_SIZE_MAX + TFD_QUEUE_SIZE_BC_DUP)
2494#define IL_TX_DMA_MASK DMA_BIT_MASK(36)
2495#define IL_NUM_OF_TBS 20
2496
2497static inline u8 il_get_dma_hi_addr(dma_addr_t addr)
2498{
2499 return (sizeof(addr) > sizeof(u32) ? (addr >> 16) >> 16 : 0) & 0xF;
2500}
2501/**
2502 * struct il_tfd_tb transmit buffer descriptor within transmit frame descriptor
2503 *
2504 * This structure contains dma address and length of transmission address
2505 *
2506 * @lo: low [31:0] portion of the dma address of TX buffer
2507 * every even is unaligned on 16 bit boundary
2508 * @hi_n_len 0-3 [35:32] portion of dma
2509 * 4-15 length of the tx buffer
2510 */
2511struct il_tfd_tb {
2512 __le32 lo;
2513 __le16 hi_n_len;
2514} __packed;
2515
2516/**
2517 * struct il_tfd
2518 *
2519 * Transmit Frame Descriptor (TFD)
2520 *
2521 * @ __reserved1[3] reserved
2522 * @ num_tbs 0-4 number of active tbs
2523 * 5 reserved
2524 * 6-7 padding (not used)
2525 * @ tbs[20] transmit frame buffer descriptors
2526 * @ __pad padding
2527 *
2528 * Each Tx queue uses a circular buffer of 256 TFDs stored in host DRAM.
2529 * Both driver and device share these circular buffers, each of which must be
2530 * contiguous 256 TFDs x 128 bytes-per-TFD = 32 KBytes
2531 *
2532 * Driver must indicate the physical address of the base of each
2533 * circular buffer via the FH_MEM_CBBC_QUEUE registers.
2534 *
2535 * Each TFD contains pointer/size information for up to 20 data buffers
2536 * in host DRAM. These buffers collectively contain the (one) frame described
2537 * by the TFD. Each buffer must be a single contiguous block of memory within
2538 * itself, but buffers may be scattered in host DRAM. Each buffer has max size
2539 * of (4K - 4). The concatenates all of a TFD's buffers into a single
2540 * Tx frame, up to 8 KBytes in size.
2541 *
2542 * A maximum of 255 (not 256!) TFDs may be on a queue waiting for Tx.
2543 */
2544struct il_tfd {
2545 u8 __reserved1[3];
2546 u8 num_tbs;
2547 struct il_tfd_tb tbs[IL_NUM_OF_TBS];
2548 __le32 __pad;
2549} __packed;
2550/* PCI registers */
2551#define PCI_CFG_RETRY_TIMEOUT 0x041
2552
2553/* PCI register values */
2554#define PCI_CFG_LINK_CTRL_VAL_L0S_EN 0x01
2555#define PCI_CFG_LINK_CTRL_VAL_L1_EN 0x02
2556
Stanislaw Gruszka3fbbf9a2011-08-31 13:39:29 +02002557struct il_rate_info {
2558 u8 plcp; /* uCode API: RATE_6M_PLCP, etc. */
2559 u8 plcp_siso; /* uCode API: RATE_SISO_6M_PLCP, etc. */
2560 u8 plcp_mimo2; /* uCode API: RATE_MIMO2_6M_PLCP, etc. */
2561 u8 ieee; /* MAC header: RATE_6M_IEEE, etc. */
2562 u8 prev_ieee; /* previous rate in IEEE speeds */
2563 u8 next_ieee; /* next rate in IEEE speeds */
2564 u8 prev_rs; /* previous rate used in rs algo */
2565 u8 next_rs; /* next rate used in rs algo */
2566 u8 prev_rs_tgg; /* previous rate used in TGG rs algo */
2567 u8 next_rs_tgg; /* next rate used in TGG rs algo */
2568};
2569
2570struct il3945_rate_info {
2571 u8 plcp; /* uCode API: RATE_6M_PLCP, etc. */
2572 u8 ieee; /* MAC header: RATE_6M_IEEE, etc. */
2573 u8 prev_ieee; /* previous rate in IEEE speeds */
2574 u8 next_ieee; /* next rate in IEEE speeds */
2575 u8 prev_rs; /* previous rate used in rs algo */
2576 u8 next_rs; /* next rate used in rs algo */
2577 u8 prev_rs_tgg; /* previous rate used in TGG rs algo */
2578 u8 next_rs_tgg; /* next rate used in TGG rs algo */
2579 u8 table_rs_idx; /* idx in rate scale table cmd */
2580 u8 prev_table_rs; /* prev in rate table cmd */
2581};
2582
2583
2584/*
2585 * These serve as idxes into
2586 * struct il_rate_info il_rates[RATE_COUNT];
2587 */
2588enum {
2589 RATE_1M_IDX = 0,
2590 RATE_2M_IDX,
2591 RATE_5M_IDX,
2592 RATE_11M_IDX,
2593 RATE_6M_IDX,
2594 RATE_9M_IDX,
2595 RATE_12M_IDX,
2596 RATE_18M_IDX,
2597 RATE_24M_IDX,
2598 RATE_36M_IDX,
2599 RATE_48M_IDX,
2600 RATE_54M_IDX,
2601 RATE_60M_IDX,
2602 RATE_COUNT,
2603 RATE_COUNT_LEGACY = RATE_COUNT - 1, /* Excluding 60M */
2604 RATE_COUNT_3945 = RATE_COUNT - 1,
2605 RATE_INVM_IDX = RATE_COUNT,
2606 RATE_INVALID = RATE_COUNT,
2607};
2608
2609enum {
2610 RATE_6M_IDX_TBL = 0,
2611 RATE_9M_IDX_TBL,
2612 RATE_12M_IDX_TBL,
2613 RATE_18M_IDX_TBL,
2614 RATE_24M_IDX_TBL,
2615 RATE_36M_IDX_TBL,
2616 RATE_48M_IDX_TBL,
2617 RATE_54M_IDX_TBL,
2618 RATE_1M_IDX_TBL,
2619 RATE_2M_IDX_TBL,
2620 RATE_5M_IDX_TBL,
2621 RATE_11M_IDX_TBL,
2622 RATE_INVM_IDX_TBL = RATE_INVM_IDX - 1,
2623};
2624
2625enum {
2626 IL_FIRST_OFDM_RATE = RATE_6M_IDX,
2627 IL39_LAST_OFDM_RATE = RATE_54M_IDX,
2628 IL_LAST_OFDM_RATE = RATE_60M_IDX,
2629 IL_FIRST_CCK_RATE = RATE_1M_IDX,
2630 IL_LAST_CCK_RATE = RATE_11M_IDX,
2631};
2632
2633/* #define vs. enum to keep from defaulting to 'large integer' */
2634#define RATE_6M_MASK (1 << RATE_6M_IDX)
2635#define RATE_9M_MASK (1 << RATE_9M_IDX)
2636#define RATE_12M_MASK (1 << RATE_12M_IDX)
2637#define RATE_18M_MASK (1 << RATE_18M_IDX)
2638#define RATE_24M_MASK (1 << RATE_24M_IDX)
2639#define RATE_36M_MASK (1 << RATE_36M_IDX)
2640#define RATE_48M_MASK (1 << RATE_48M_IDX)
2641#define RATE_54M_MASK (1 << RATE_54M_IDX)
2642#define RATE_60M_MASK (1 << RATE_60M_IDX)
2643#define RATE_1M_MASK (1 << RATE_1M_IDX)
2644#define RATE_2M_MASK (1 << RATE_2M_IDX)
2645#define RATE_5M_MASK (1 << RATE_5M_IDX)
2646#define RATE_11M_MASK (1 << RATE_11M_IDX)
2647
2648/* uCode API values for legacy bit rates, both OFDM and CCK */
2649enum {
2650 RATE_6M_PLCP = 13,
2651 RATE_9M_PLCP = 15,
2652 RATE_12M_PLCP = 5,
2653 RATE_18M_PLCP = 7,
2654 RATE_24M_PLCP = 9,
2655 RATE_36M_PLCP = 11,
2656 RATE_48M_PLCP = 1,
2657 RATE_54M_PLCP = 3,
2658 RATE_60M_PLCP = 3,/*FIXME:RS:should be removed*/
2659 RATE_1M_PLCP = 10,
2660 RATE_2M_PLCP = 20,
2661 RATE_5M_PLCP = 55,
2662 RATE_11M_PLCP = 110,
2663 /*FIXME:RS:add RATE_LEGACY_INVM_PLCP = 0,*/
2664};
2665
2666/* uCode API values for OFDM high-throughput (HT) bit rates */
2667enum {
2668 RATE_SISO_6M_PLCP = 0,
2669 RATE_SISO_12M_PLCP = 1,
2670 RATE_SISO_18M_PLCP = 2,
2671 RATE_SISO_24M_PLCP = 3,
2672 RATE_SISO_36M_PLCP = 4,
2673 RATE_SISO_48M_PLCP = 5,
2674 RATE_SISO_54M_PLCP = 6,
2675 RATE_SISO_60M_PLCP = 7,
2676 RATE_MIMO2_6M_PLCP = 0x8,
2677 RATE_MIMO2_12M_PLCP = 0x9,
2678 RATE_MIMO2_18M_PLCP = 0xa,
2679 RATE_MIMO2_24M_PLCP = 0xb,
2680 RATE_MIMO2_36M_PLCP = 0xc,
2681 RATE_MIMO2_48M_PLCP = 0xd,
2682 RATE_MIMO2_54M_PLCP = 0xe,
2683 RATE_MIMO2_60M_PLCP = 0xf,
2684 RATE_SISO_INVM_PLCP,
2685 RATE_MIMO2_INVM_PLCP = RATE_SISO_INVM_PLCP,
2686};
2687
2688/* MAC header values for bit rates */
2689enum {
2690 RATE_6M_IEEE = 12,
2691 RATE_9M_IEEE = 18,
2692 RATE_12M_IEEE = 24,
2693 RATE_18M_IEEE = 36,
2694 RATE_24M_IEEE = 48,
2695 RATE_36M_IEEE = 72,
2696 RATE_48M_IEEE = 96,
2697 RATE_54M_IEEE = 108,
2698 RATE_60M_IEEE = 120,
2699 RATE_1M_IEEE = 2,
2700 RATE_2M_IEEE = 4,
2701 RATE_5M_IEEE = 11,
2702 RATE_11M_IEEE = 22,
2703};
2704
2705#define IL_CCK_BASIC_RATES_MASK \
2706 (RATE_1M_MASK | \
2707 RATE_2M_MASK)
2708
2709#define IL_CCK_RATES_MASK \
2710 (IL_CCK_BASIC_RATES_MASK | \
2711 RATE_5M_MASK | \
2712 RATE_11M_MASK)
2713
2714#define IL_OFDM_BASIC_RATES_MASK \
2715 (RATE_6M_MASK | \
2716 RATE_12M_MASK | \
2717 RATE_24M_MASK)
2718
2719#define IL_OFDM_RATES_MASK \
2720 (IL_OFDM_BASIC_RATES_MASK | \
2721 RATE_9M_MASK | \
2722 RATE_18M_MASK | \
2723 RATE_36M_MASK | \
2724 RATE_48M_MASK | \
2725 RATE_54M_MASK)
2726
2727#define IL_BASIC_RATES_MASK \
2728 (IL_OFDM_BASIC_RATES_MASK | \
2729 IL_CCK_BASIC_RATES_MASK)
2730
2731#define RATES_MASK ((1 << RATE_COUNT) - 1)
2732#define RATES_MASK_3945 ((1 << RATE_COUNT_3945) - 1)
2733
2734#define IL_INVALID_VALUE -1
2735
2736#define IL_MIN_RSSI_VAL -100
2737#define IL_MAX_RSSI_VAL 0
2738
2739/* These values specify how many Tx frame attempts before
2740 * searching for a new modulation mode */
2741#define IL_LEGACY_FAILURE_LIMIT 160
2742#define IL_LEGACY_SUCCESS_LIMIT 480
2743#define IL_LEGACY_TBL_COUNT 160
2744
2745#define IL_NONE_LEGACY_FAILURE_LIMIT 400
2746#define IL_NONE_LEGACY_SUCCESS_LIMIT 4500
2747#define IL_NONE_LEGACY_TBL_COUNT 1500
2748
2749/* Success ratio (ACKed / attempted tx frames) values (perfect is 128 * 100) */
2750#define IL_RS_GOOD_RATIO 12800 /* 100% */
2751#define RATE_SCALE_SWITCH 10880 /* 85% */
2752#define RATE_HIGH_TH 10880 /* 85% */
2753#define RATE_INCREASE_TH 6400 /* 50% */
2754#define RATE_DECREASE_TH 1920 /* 15% */
2755
2756/* possible actions when in legacy mode */
2757#define IL_LEGACY_SWITCH_ANTENNA1 0
2758#define IL_LEGACY_SWITCH_ANTENNA2 1
2759#define IL_LEGACY_SWITCH_SISO 2
2760#define IL_LEGACY_SWITCH_MIMO2_AB 3
2761#define IL_LEGACY_SWITCH_MIMO2_AC 4
2762#define IL_LEGACY_SWITCH_MIMO2_BC 5
2763
2764/* possible actions when in siso mode */
2765#define IL_SISO_SWITCH_ANTENNA1 0
2766#define IL_SISO_SWITCH_ANTENNA2 1
2767#define IL_SISO_SWITCH_MIMO2_AB 2
2768#define IL_SISO_SWITCH_MIMO2_AC 3
2769#define IL_SISO_SWITCH_MIMO2_BC 4
2770#define IL_SISO_SWITCH_GI 5
2771
2772/* possible actions when in mimo mode */
2773#define IL_MIMO2_SWITCH_ANTENNA1 0
2774#define IL_MIMO2_SWITCH_ANTENNA2 1
2775#define IL_MIMO2_SWITCH_SISO_A 2
2776#define IL_MIMO2_SWITCH_SISO_B 3
2777#define IL_MIMO2_SWITCH_SISO_C 4
2778#define IL_MIMO2_SWITCH_GI 5
2779
2780#define IL_MAX_SEARCH IL_MIMO2_SWITCH_GI
2781
2782#define IL_ACTION_LIMIT 3 /* # possible actions */
2783
2784#define LQ_SIZE 2 /* 2 mode tables: "Active" and "Search" */
2785
2786/* load per tid defines for A-MPDU activation */
2787#define IL_AGG_TPT_THREHOLD 0
2788#define IL_AGG_LOAD_THRESHOLD 10
2789#define IL_AGG_ALL_TID 0xff
2790#define TID_QUEUE_CELL_SPACING 50 /*mS */
2791#define TID_QUEUE_MAX_SIZE 20
2792#define TID_ROUND_VALUE 5 /* mS */
2793#define TID_MAX_LOAD_COUNT 8
2794
2795#define TID_MAX_TIME_DIFF ((TID_QUEUE_MAX_SIZE - 1) * TID_QUEUE_CELL_SPACING)
2796#define TIME_WRAP_AROUND(x, y) (((y) > (x)) ? (y) - (x) : (0-(x)) + (y))
2797
2798extern const struct il_rate_info il_rates[RATE_COUNT];
2799
2800enum il_table_type {
2801 LQ_NONE,
2802 LQ_G, /* legacy types */
2803 LQ_A,
2804 LQ_SISO, /* high-throughput types */
2805 LQ_MIMO2,
2806 LQ_MAX,
2807};
2808
2809#define is_legacy(tbl) ((tbl) == LQ_G || (tbl) == LQ_A)
2810#define is_siso(tbl) ((tbl) == LQ_SISO)
2811#define is_mimo2(tbl) ((tbl) == LQ_MIMO2)
2812#define is_mimo(tbl) (is_mimo2(tbl))
2813#define is_Ht(tbl) (is_siso(tbl) || is_mimo(tbl))
2814#define is_a_band(tbl) ((tbl) == LQ_A)
2815#define is_g_and(tbl) ((tbl) == LQ_G)
2816
2817#define ANT_NONE 0x0
2818#define ANT_A BIT(0)
2819#define ANT_B BIT(1)
2820#define ANT_AB (ANT_A | ANT_B)
2821#define ANT_C BIT(2)
2822#define ANT_AC (ANT_A | ANT_C)
2823#define ANT_BC (ANT_B | ANT_C)
2824#define ANT_ABC (ANT_AB | ANT_C)
2825
2826#define IL_MAX_MCS_DISPLAY_SIZE 12
2827
2828struct il_rate_mcs_info {
2829 char mbps[IL_MAX_MCS_DISPLAY_SIZE];
2830 char mcs[IL_MAX_MCS_DISPLAY_SIZE];
2831};
2832
2833/**
2834 * struct il_rate_scale_data -- tx success history for one rate
2835 */
2836struct il_rate_scale_data {
2837 u64 data; /* bitmap of successful frames */
2838 s32 success_counter; /* number of frames successful */
2839 s32 success_ratio; /* per-cent * 128 */
2840 s32 counter; /* number of frames attempted */
2841 s32 average_tpt; /* success ratio * expected throughput */
2842 unsigned long stamp;
2843};
2844
2845/**
2846 * struct il_scale_tbl_info -- tx params and success history for all rates
2847 *
2848 * There are two of these in struct il_lq_sta,
2849 * one for "active", and one for "search".
2850 */
2851struct il_scale_tbl_info {
2852 enum il_table_type lq_type;
2853 u8 ant_type;
2854 u8 is_SGI; /* 1 = short guard interval */
2855 u8 is_ht40; /* 1 = 40 MHz channel width */
2856 u8 is_dup; /* 1 = duplicated data streams */
2857 u8 action; /* change modulation; IL_[LEGACY/SISO/MIMO]_SWITCH_* */
2858 u8 max_search; /* maximun number of tables we can search */
2859 s32 *expected_tpt; /* throughput metrics; expected_tpt_G, etc. */
2860 u32 current_rate; /* rate_n_flags, uCode API format */
2861 struct il_rate_scale_data win[RATE_COUNT]; /* rate histories */
2862};
2863
2864struct il_traffic_load {
2865 unsigned long time_stamp; /* age of the oldest stats */
2866 u32 packet_count[TID_QUEUE_MAX_SIZE]; /* packet count in this time
2867 * slice */
2868 u32 total; /* total num of packets during the
2869 * last TID_MAX_TIME_DIFF */
2870 u8 queue_count; /* number of queues that has
2871 * been used since the last cleanup */
2872 u8 head; /* start of the circular buffer */
2873};
2874
2875/**
2876 * struct il_lq_sta -- driver's rate scaling ilate structure
2877 *
2878 * Pointer to this gets passed back and forth between driver and mac80211.
2879 */
2880struct il_lq_sta {
2881 u8 active_tbl; /* idx of active table, range 0-1 */
2882 u8 enable_counter; /* indicates HT mode */
2883 u8 stay_in_tbl; /* 1: disallow, 0: allow search for new mode */
2884 u8 search_better_tbl; /* 1: currently trying alternate mode */
2885 s32 last_tpt;
2886
2887 /* The following determine when to search for a new mode */
2888 u32 table_count_limit;
2889 u32 max_failure_limit; /* # failed frames before new search */
2890 u32 max_success_limit; /* # successful frames before new search */
2891 u32 table_count;
2892 u32 total_failed; /* total failed frames, any/all rates */
2893 u32 total_success; /* total successful frames, any/all rates */
2894 u64 flush_timer; /* time staying in mode before new search */
2895
2896 u8 action_counter; /* # mode-switch actions tried */
2897 u8 is_green;
2898 u8 is_dup;
2899 enum ieee80211_band band;
2900
2901 /* The following are bitmaps of rates; RATE_6M_MASK, etc. */
2902 u32 supp_rates;
2903 u16 active_legacy_rate;
2904 u16 active_siso_rate;
2905 u16 active_mimo2_rate;
2906 s8 max_rate_idx; /* Max rate set by user */
2907 u8 missed_rate_counter;
2908
2909 struct il_link_quality_cmd lq;
2910 struct il_scale_tbl_info lq_info[LQ_SIZE]; /* "active", "search" */
2911 struct il_traffic_load load[TID_MAX_LOAD_COUNT];
2912 u8 tx_agg_tid_en;
2913#ifdef CONFIG_MAC80211_DEBUGFS
2914 struct dentry *rs_sta_dbgfs_scale_table_file;
2915 struct dentry *rs_sta_dbgfs_stats_table_file;
2916 struct dentry *rs_sta_dbgfs_rate_scale_data_file;
2917 struct dentry *rs_sta_dbgfs_tx_agg_tid_en_file;
2918 u32 dbg_fixed_rate;
2919#endif
2920 struct il_priv *drv;
2921
2922 /* used to be in sta_info */
2923 int last_txrate_idx;
2924 /* last tx rate_n_flags */
2925 u32 last_rate_n_flags;
2926 /* packets destined for this STA are aggregated */
2927 u8 is_agg;
2928};
2929
2930/*
2931 * il_station_priv: Driver's ilate station information
2932 *
2933 * When mac80211 creates a station it reserves some space (hw->sta_data_size)
2934 * in the structure for use by driver. This structure is places in that
2935 * space.
2936 *
2937 * The common struct MUST be first because it is shared between
2938 * 3945 and 4965!
2939 */
2940struct il_station_priv {
2941 struct il_station_priv_common common;
2942 struct il_lq_sta lq_sta;
2943 atomic_t pending_frames;
2944 bool client;
2945 bool asleep;
2946};
2947
2948static inline u8 il4965_num_of_ant(u8 m)
2949{
2950 return !!(m & ANT_A) + !!(m & ANT_B) + !!(m & ANT_C);
2951}
2952
2953static inline u8 il4965_first_antenna(u8 mask)
2954{
2955 if (mask & ANT_A)
2956 return ANT_A;
2957 if (mask & ANT_B)
2958 return ANT_B;
2959 return ANT_C;
2960}
2961
2962
2963/**
2964 * il3945_rate_scale_init - Initialize the rate scale table based on assoc info
2965 *
2966 * The specific throughput table used is based on the type of network
2967 * the associated with, including A, B, G, and G w/ TGG protection
2968 */
2969extern void il3945_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id);
2970
2971/* Initialize station's rate scaling information after adding station */
2972extern void il4965_rs_rate_init(struct il_priv *il,
2973 struct ieee80211_sta *sta, u8 sta_id);
2974extern void il3945_rs_rate_init(struct il_priv *il,
2975 struct ieee80211_sta *sta, u8 sta_id);
2976
2977/**
2978 * il_rate_control_register - Register the rate control algorithm callbacks
2979 *
2980 * Since the rate control algorithm is hardware specific, there is no need
2981 * or reason to place it as a stand alone module. The driver can call
2982 * il_rate_control_register in order to register the rate control callbacks
2983 * with the mac80211 subsystem. This should be performed prior to calling
2984 * ieee80211_register_hw
2985 *
2986 */
2987extern int il4965_rate_control_register(void);
2988extern int il3945_rate_control_register(void);
2989
2990/**
2991 * il_rate_control_unregister - Unregister the rate control callbacks
2992 *
2993 * This should be called after calling ieee80211_unregister_hw, but before
2994 * the driver is unloaded.
2995 */
2996extern void il4965_rate_control_unregister(void);
2997extern void il3945_rate_control_unregister(void);
2998
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002999#endif /* __il_core_h__ */