blob: 010ed69e0e50b56b3cbe9ed8a63b0a785ae57adf [file] [log] [blame]
Zhu Yib481de92007-09-25 17:54:57 -07001/******************************************************************************
2 *
Reinette Chatreeb7ae892008-03-11 16:17:17 -07003 * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved.
Zhu Yib481de92007-09-25 17:54:57 -07004 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
20 *
21 * Contact Information:
22 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 *****************************************************************************/
Ben Cahillfcd427b2007-11-29 11:10:00 +080026/*
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070027 * Please use this file (iwl-dev.h) for driver implementation definitions.
Tomas Winkler5a36ba02008-04-24 11:55:37 -070028 * Please use iwl-commands.h for uCode API definitions.
Ben Cahillfcd427b2007-11-29 11:10:00 +080029 * Please use iwl-4965-hw.h for hardware-related definitions.
30 */
31
Emmanuel Grumbachbe1f3ab62008-06-12 09:47:18 +080032#ifndef __iwl_dev_h__
33#define __iwl_dev_h__
Zhu Yib481de92007-09-25 17:54:57 -070034
Christoph Hellwig5d08cd12007-10-25 17:15:50 +080035#include <linux/pci.h> /* for struct pci_device_id */
36#include <linux/kernel.h>
37#include <net/ieee80211_radiotap.h>
38
Christoph Hellwig5d08cd12007-10-25 17:15:50 +080039#define DRV_NAME "iwl4965"
Mohamed Abbasad97edd2008-03-28 16:21:06 -070040#include "iwl-rfkill.h"
Assaf Krauss6bc913b2008-03-11 16:17:18 -070041#include "iwl-eeprom.h"
Christoph Hellwig5d08cd12007-10-25 17:15:50 +080042#include "iwl-4965-hw.h"
Tomas Winkler6f83eaa2008-03-04 18:09:28 -080043#include "iwl-csr.h"
Christoph Hellwig5d08cd12007-10-25 17:15:50 +080044#include "iwl-prph.h"
Tomas Winkler0a6857e2008-03-12 16:58:49 -070045#include "iwl-debug.h"
Mohamed Abbasab53d8a2008-03-25 16:33:36 -070046#include "iwl-led.h"
Mohamed Abbas5da4b552008-04-21 15:41:51 -070047#include "iwl-power.h"
Christoph Hellwig5d08cd12007-10-25 17:15:50 +080048
Ron Rindjunskyfed90172008-04-15 16:01:41 -070049/* configuration for the iwl4965 */
50extern struct iwl_cfg iwl4965_agn_cfg;
Tomas Winkler5a6a2562008-04-24 11:55:23 -070051extern struct iwl_cfg iwl5300_agn_cfg;
52extern struct iwl_cfg iwl5100_agn_cfg;
53extern struct iwl_cfg iwl5350_agn_cfg;
Esti Kummer47408632008-07-11 11:53:30 +080054extern struct iwl_cfg iwl5100_bg_cfg;
55extern struct iwl_cfg iwl5100_abg_cfg;
Ron Rindjunskyfed90172008-04-15 16:01:41 -070056
Ron Rindjunsky099b40b2008-04-21 15:41:53 -070057/* CT-KILL constants */
58#define CT_KILL_THRESHOLD 110 /* in Celsius */
Tomas Winkler4bf775c2008-03-04 18:09:31 -080059
Christoph Hellwig5d08cd12007-10-25 17:15:50 +080060/* Default noise level to report when noise measurement is not available.
61 * This may be because we're:
62 * 1) Not associated (4965, no beacon statistics being sent to driver)
63 * 2) Scanning (noise measurement does not apply to associated channel)
64 * 3) Receiving CCK (3945 delivers noise info only for OFDM frames)
65 * Use default noise value of -127 ... this is below the range of measurable
66 * Rx dBm for either 3945 or 4965, so it can indicate "unmeasurable" to user.
67 * Also, -127 works better than 0 when averaging frames with/without
68 * noise info (e.g. averaging might be done in app); measured dBm values are
69 * always negative ... using a negative value as the default keeps all
70 * averages within an s8's (used in some apps) range of negative values. */
71#define IWL_NOISE_MEAS_NOT_AVAILABLE (-127)
72
Christoph Hellwig5d08cd12007-10-25 17:15:50 +080073/*
74 * RTS threshold here is total size [2347] minus 4 FCS bytes
75 * Per spec:
76 * a value of 0 means RTS on all data/management packets
77 * a value > max MSDU size means no RTS
78 * else RTS for data/management frames where MPDU is larger
79 * than RTS value.
80 */
81#define DEFAULT_RTS_THRESHOLD 2347U
82#define MIN_RTS_THRESHOLD 0U
83#define MAX_RTS_THRESHOLD 2347U
84#define MAX_MSDU_SIZE 2304U
85#define MAX_MPDU_SIZE 2346U
86#define DEFAULT_BEACON_INTERVAL 100U
87#define DEFAULT_SHORT_RETRY_LIMIT 7U
88#define DEFAULT_LONG_RETRY_LIMIT 4U
89
Tomas Winklera55360e2008-05-05 10:22:28 +080090struct iwl_rx_mem_buffer {
Christoph Hellwig5d08cd12007-10-25 17:15:50 +080091 dma_addr_t dma_addr;
92 struct sk_buff *skb;
93 struct list_head list;
94};
95
Christoph Hellwig5d08cd12007-10-25 17:15:50 +080096/*
97 * Generic queue structure
98 *
99 * Contains common data for Rx and Tx queues
100 */
Tomas Winkler443cfd42008-05-15 13:53:57 +0800101struct iwl_queue {
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800102 int n_bd; /* number of BDs in this queue */
103 int write_ptr; /* 1-st empty entry (index) host_w*/
104 int read_ptr; /* last used entry (index) host_r*/
105 dma_addr_t dma_addr; /* physical addr for BD's */
106 int n_window; /* safe queue window */
107 u32 id;
108 int low_mark; /* low watermark, resume queue if free
109 * space more than this */
110 int high_mark; /* high watermark, stop queue if free
111 * space less than this */
112} __attribute__ ((packed));
113
114#define MAX_NUM_OF_TBS (20)
115
Ben Cahillbc472792007-11-29 11:09:49 +0800116/* One for each TFD */
Tomas Winkler8567c632008-05-15 13:53:58 +0800117struct iwl_tx_info {
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800118 struct sk_buff *skb[MAX_NUM_OF_TBS];
119};
120
121/**
Ron Rindjunsky16466902008-05-05 10:22:50 +0800122 * struct iwl_tx_queue - Tx Queue for DMA
Ben Cahillbc472792007-11-29 11:09:49 +0800123 * @q: generic Rx/Tx queue descriptor
124 * @bd: base of circular buffer of TFDs
125 * @cmd: array of command/Tx buffers
126 * @dma_addr_cmd: physical address of cmd/tx buffer array
127 * @txb: array of per-TFD driver data
128 * @need_update: indicates need to update read/write index
129 * @sched_retry: indicates queue is high-throughput aggregation (HT AGG) enabled
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800130 *
Ben Cahillbc472792007-11-29 11:09:49 +0800131 * A Tx queue consists of circular buffer of BDs (a.k.a. TFDs, transmit frame
132 * descriptors) and required locking structures.
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800133 */
Ron Rindjunsky16466902008-05-05 10:22:50 +0800134struct iwl_tx_queue {
Tomas Winkler443cfd42008-05-15 13:53:57 +0800135 struct iwl_queue q;
Ron Rindjunsky1053d352008-05-05 10:22:43 +0800136 struct iwl_tfd_frame *bd;
Tomas Winkler857485c2008-03-21 13:53:44 -0700137 struct iwl_cmd *cmd;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800138 dma_addr_t dma_addr_cmd;
Tomas Winkler8567c632008-05-15 13:53:58 +0800139 struct iwl_tx_info *txb;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800140 int need_update;
141 int sched_retry;
142 int active;
143};
144
145#define IWL_NUM_SCAN_RATES (2)
146
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800147struct iwl4965_channel_tgd_info {
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800148 u8 type;
149 s8 max_power;
150};
151
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800152struct iwl4965_channel_tgh_info {
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800153 s64 last_radar_time;
154};
155
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800156/*
157 * One for each channel, holds all channel setup data
158 * Some of the fields (e.g. eeprom and flags/max_power_avg) are redundant
159 * with one another!
160 */
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700161struct iwl_channel_info {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800162 struct iwl4965_channel_tgd_info tgd;
163 struct iwl4965_channel_tgh_info tgh;
Tomas Winkler073d3f52008-04-21 15:41:52 -0700164 struct iwl_eeprom_channel eeprom; /* EEPROM regulatory limit */
165 struct iwl_eeprom_channel fat_eeprom; /* EEPROM regulatory limit for
166 * FAT channel */
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800167
168 u8 channel; /* channel number */
169 u8 flags; /* flags copied from EEPROM */
170 s8 max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */
Ben Cahillfcd427b2007-11-29 11:10:00 +0800171 s8 curr_txpow; /* (dBm) regulatory/spectrum/user (not h/w) limit */
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800172 s8 min_power; /* always 0 */
173 s8 scan_power; /* (dBm) regul. eeprom, direct scans, any rate */
174
175 u8 group_index; /* 0-4, maps channel to group1/2/3/4/5 */
176 u8 band_index; /* 0-4, maps channel to band1/2/3/4/5 */
Johannes Berg8318d782008-01-24 19:38:38 +0100177 enum ieee80211_band band;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800178
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800179 /* FAT channel info */
180 s8 fat_max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */
181 s8 fat_curr_txpow; /* (dBm) regulatory/spectrum/user (not h/w) */
182 s8 fat_min_power; /* always 0 */
183 s8 fat_scan_power; /* (dBm) eeprom, direct scans, any rate */
184 u8 fat_flags; /* flags copied from EEPROM */
Ben Cahillfcd427b2007-11-29 11:10:00 +0800185 u8 fat_extension_channel; /* HT_IE_EXT_CHANNEL_* */
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800186};
187
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800188struct iwl4965_clip_group {
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800189 /* maximum power level to prevent clipping for each rate, derived by
190 * us from this band's saturation power in EEPROM */
191 const s8 clip_powers[IWL_MAX_RATES];
192};
193
194#include "iwl-4965-rs.h"
195
196#define IWL_TX_FIFO_AC0 0
197#define IWL_TX_FIFO_AC1 1
198#define IWL_TX_FIFO_AC2 2
199#define IWL_TX_FIFO_AC3 3
200#define IWL_TX_FIFO_HCCA_1 5
201#define IWL_TX_FIFO_HCCA_2 6
202#define IWL_TX_FIFO_NONE 7
203
204/* Minimum number of queues. MAX_NUM is defined in hw specific files */
205#define IWL_MIN_NUM_QUEUES 4
206
207/* Power management (not Tx power) structures */
208
Tomas Winkler6f4083a2008-04-16 16:34:49 -0700209enum iwl_pwr_src {
210 IWL_PWR_SRC_VMAIN,
211 IWL_PWR_SRC_VAUX,
212};
213
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800214#define IEEE80211_DATA_LEN 2304
215#define IEEE80211_4ADDR_LEN 30
216#define IEEE80211_HLEN (IEEE80211_4ADDR_LEN)
217#define IEEE80211_FRAME_LEN (IEEE80211_DATA_LEN + IEEE80211_HLEN)
218
Tomas Winklerfcab4232008-05-15 13:54:01 +0800219struct iwl_frame {
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800220 union {
221 struct ieee80211_hdr frame;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800222 struct iwl4965_tx_beacon_cmd beacon;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800223 u8 raw[IEEE80211_FRAME_LEN];
224 u8 cmd[360];
225 } u;
226 struct list_head list;
227};
228
229#define SEQ_TO_QUEUE(x) ((x >> 8) & 0xbf)
230#define QUEUE_TO_SEQ(x) ((x & 0xbf) << 8)
Johannes Berga0b484f2008-04-01 17:51:47 +0200231#define SEQ_TO_INDEX(x) ((u8)(x & 0xff))
232#define INDEX_TO_SEQ(x) ((u8)(x & 0xff))
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800233#define SEQ_HUGE_FRAME (0x4000)
234#define SEQ_RX_FRAME __constant_cpu_to_le16(0x8000)
235#define SEQ_TO_SN(seq) (((seq) & IEEE80211_SCTL_SEQ) >> 4)
236#define SN_TO_SEQ(ssn) (((ssn) << 4) & IEEE80211_SCTL_SEQ)
237#define MAX_SN ((IEEE80211_SCTL_SEQ) >> 4)
238
239enum {
240 /* CMD_SIZE_NORMAL = 0, */
241 CMD_SIZE_HUGE = (1 << 0),
242 /* CMD_SYNC = 0, */
243 CMD_ASYNC = (1 << 1),
244 /* CMD_NO_SKB = 0, */
245 CMD_WANT_SKB = (1 << 2),
246};
247
Tomas Winkler857485c2008-03-21 13:53:44 -0700248struct iwl_cmd;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700249struct iwl_priv;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800250
Tomas Winkler857485c2008-03-21 13:53:44 -0700251struct iwl_cmd_meta {
252 struct iwl_cmd_meta *source;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800253 union {
254 struct sk_buff *skb;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700255 int (*callback)(struct iwl_priv *priv,
Tomas Winkler857485c2008-03-21 13:53:44 -0700256 struct iwl_cmd *cmd, struct sk_buff *skb);
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800257 } __attribute__ ((packed)) u;
258
259 /* The CMD_SIZE_HUGE flag bit indicates that the command
260 * structure is stored at the end of the shared queue memory. */
261 u32 flags;
262
263} __attribute__ ((packed));
264
Emmanuel Grumbachd2f18bf2008-05-29 16:35:27 +0800265#define IWL_CMD_MAX_PAYLOAD 320
Ron Rindjunskybd68fb62008-05-29 16:34:49 +0800266
Ben Cahillbc472792007-11-29 11:09:49 +0800267/**
Tomas Winkler857485c2008-03-21 13:53:44 -0700268 * struct iwl_cmd
Ben Cahillbc472792007-11-29 11:09:49 +0800269 *
270 * For allocation of the command and tx queues, this establishes the overall
271 * size of the largest command we send to uCode, except for a scan command
272 * (which is relatively huge; space is allocated separately).
273 */
Tomas Winkler857485c2008-03-21 13:53:44 -0700274struct iwl_cmd {
275 struct iwl_cmd_meta meta; /* driver data */
276 struct iwl_cmd_header hdr; /* uCode API */
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800277 union {
Tomas Winkler133636d2008-05-05 10:22:34 +0800278 struct iwl_addsta_cmd addsta;
Tomas Winklerec1a7462008-07-11 11:53:37 +0800279 struct iwl_led_cmd led;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800280 u32 flags;
281 u8 val8;
282 u16 val16;
283 u32 val32;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800284 struct iwl4965_bt_cmd bt;
285 struct iwl4965_rxon_time_cmd rxon_time;
Mohamed Abbasca579612008-07-18 13:52:57 +0800286 struct iwl_powertable_cmd powertable;
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +0800287 struct iwl_qosparam_cmd qosparam;
Tomas Winkler83d527d2008-05-15 13:54:05 +0800288 struct iwl_tx_cmd tx;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800289 struct iwl4965_tx_beacon_cmd tx_beacon;
290 struct iwl4965_rxon_assoc_cmd rxon_assoc;
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800291 struct iwl_rem_sta_cmd rm_sta;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800292 u8 *indirect;
Ron Rindjunskybd68fb62008-05-29 16:34:49 +0800293 u8 payload[IWL_CMD_MAX_PAYLOAD];
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800294 } __attribute__ ((packed)) cmd;
295} __attribute__ ((packed));
296
Tomas Winkler857485c2008-03-21 13:53:44 -0700297struct iwl_host_cmd {
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800298 u8 id;
299 u16 len;
Tomas Winkler857485c2008-03-21 13:53:44 -0700300 struct iwl_cmd_meta meta;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800301 const void *data;
302};
303
Tomas Winkler857485c2008-03-21 13:53:44 -0700304#define TFD_MAX_PAYLOAD_SIZE (sizeof(struct iwl_cmd) - \
305 sizeof(struct iwl_cmd_meta))
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800306
307/*
308 * RX related structures and functions
309 */
310#define RX_FREE_BUFFERS 64
311#define RX_LOW_WATERMARK 8
312
313#define SUP_RATE_11A_MAX_NUM_CHANNELS 8
314#define SUP_RATE_11B_MAX_NUM_CHANNELS 4
315#define SUP_RATE_11G_MAX_NUM_CHANNELS 12
316
317/**
Tomas Winklera55360e2008-05-05 10:22:28 +0800318 * struct iwl_rx_queue - Rx queue
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800319 * @processed: Internal index to last handled Rx packet
320 * @read: Shared index to newest available Rx buffer
321 * @write: Shared index to oldest written Rx packet
322 * @free_count: Number of pre-allocated buffers in rx_free
323 * @rx_free: list of free SKBs for use
324 * @rx_used: List of Rx buffers with no SKB
325 * @need_update: flag to indicate we need to update read/write index
326 *
Tomas Winklera55360e2008-05-05 10:22:28 +0800327 * NOTE: rx_free and rx_used are used as a FIFO for iwl_rx_mem_buffers
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800328 */
Tomas Winklera55360e2008-05-05 10:22:28 +0800329struct iwl_rx_queue {
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800330 __le32 *bd;
331 dma_addr_t dma_addr;
Tomas Winklera55360e2008-05-05 10:22:28 +0800332 struct iwl_rx_mem_buffer pool[RX_QUEUE_SIZE + RX_FREE_BUFFERS];
333 struct iwl_rx_mem_buffer *queue[RX_QUEUE_SIZE];
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800334 u32 processed;
335 u32 read;
336 u32 write;
337 u32 free_count;
338 struct list_head rx_free;
339 struct list_head rx_used;
340 int need_update;
341 spinlock_t lock;
342};
343
344#define IWL_SUPPORTED_RATES_IE_LEN 8
345
346#define SCAN_INTERVAL 100
347
348#define MAX_A_CHANNELS 252
349#define MIN_A_CHANNELS 7
350
351#define MAX_B_CHANNELS 14
352#define MIN_B_CHANNELS 1
353
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800354#define MAX_TID_COUNT 9
355
356#define IWL_INVALID_RATE 0xFF
357#define IWL_INVALID_VALUE -1
358
Ben Cahillbc472792007-11-29 11:09:49 +0800359/**
Tomas Winkler6def9762008-05-05 10:22:31 +0800360 * struct iwl_ht_agg -- aggregation status while waiting for block-ack
Ben Cahillbc472792007-11-29 11:09:49 +0800361 * @txq_id: Tx queue used for Tx attempt
362 * @frame_count: # frames attempted by Tx command
363 * @wait_for_ba: Expect block-ack before next Tx reply
364 * @start_idx: Index of 1st Transmit Frame Descriptor (TFD) in Tx window
365 * @bitmap0: Low order bitmap, one bit for each frame pending ACK in Tx window
366 * @bitmap1: High order, one bit for each frame pending ACK in Tx window
367 * @rate_n_flags: Rate at which Tx was attempted
368 *
369 * If REPLY_TX indicates that aggregation was attempted, driver must wait
370 * for block ack (REPLY_COMPRESSED_BA). This struct stores tx reply info
371 * until block ack arrives.
372 */
Tomas Winkler6def9762008-05-05 10:22:31 +0800373struct iwl_ht_agg {
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800374 u16 txq_id;
375 u16 frame_count;
376 u16 wait_for_ba;
377 u16 start_idx;
Ron Rindjunskyfe01b472008-01-28 14:07:24 +0200378 u64 bitmap;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800379 u32 rate_n_flags;
Ron Rindjunskyfe01b472008-01-28 14:07:24 +0200380#define IWL_AGG_OFF 0
381#define IWL_AGG_ON 1
382#define IWL_EMPTYING_HW_QUEUE_ADDBA 2
383#define IWL_EMPTYING_HW_QUEUE_DELBA 3
384 u8 state;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800385};
Ron Rindjunskyfe01b472008-01-28 14:07:24 +0200386
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800387
Tomas Winkler6def9762008-05-05 10:22:31 +0800388struct iwl_tid_data {
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800389 u16 seq_number;
Ron Rindjunskyfe01b472008-01-28 14:07:24 +0200390 u16 tfds_in_queue;
Tomas Winkler6def9762008-05-05 10:22:31 +0800391 struct iwl_ht_agg agg;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800392};
393
Tomas Winkler6def9762008-05-05 10:22:31 +0800394struct iwl_hw_key {
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800395 enum ieee80211_key_alg alg;
396 int keylen;
Emmanuel Grumbach0211ddd2008-04-14 21:16:07 -0700397 u8 keyidx;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800398 u8 key[32];
399};
400
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800401union iwl4965_ht_rate_supp {
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800402 u16 rates;
403 struct {
404 u8 siso_rate;
405 u8 mimo_rate;
406 };
407};
408
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800409#define CFG_HT_RX_AMPDU_FACTOR_DEF (0x3)
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800410#define CFG_HT_MPDU_DENSITY_2USEC (0x5)
411#define CFG_HT_MPDU_DENSITY_DEF CFG_HT_MPDU_DENSITY_2USEC
412
Ron Rindjunsky9e0cc6d2007-11-26 16:14:36 +0200413struct iwl_ht_info {
414 /* self configuration data */
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800415 u8 is_ht;
Ron Rindjunsky9e0cc6d2007-11-26 16:14:36 +0200416 u8 supported_chan_width;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800417 u16 tx_mimo_ps_mode;
Ron Rindjunsky9e0cc6d2007-11-26 16:14:36 +0200418 u8 is_green_field;
Tomas Winklerbb542442007-12-05 20:59:59 +0200419 u8 sgf; /* HT_SHORT_GI_* short guard interval */
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800420 u8 max_amsdu_size;
421 u8 ampdu_factor;
422 u8 mpdu_density;
Ron Rindjunsky9e0cc6d2007-11-26 16:14:36 +0200423 u8 supp_mcs_set[16];
424 /* BSS related data */
425 u8 control_channel;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800426 u8 extension_chan_offset;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800427 u8 tx_chan_width;
Ron Rindjunsky9e0cc6d2007-11-26 16:14:36 +0200428 u8 ht_protection;
429 u8 non_GF_STA_present;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800430};
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800431
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +0800432union iwl_qos_capabity {
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800433 struct {
434 u8 edca_count:4; /* bit 0-3 */
435 u8 q_ack:1; /* bit 4 */
436 u8 queue_request:1; /* bit 5 */
437 u8 txop_request:1; /* bit 6 */
438 u8 reserved:1; /* bit 7 */
439 } q_AP;
440 struct {
441 u8 acvo_APSD:1; /* bit 0 */
442 u8 acvi_APSD:1; /* bit 1 */
443 u8 ac_bk_APSD:1; /* bit 2 */
444 u8 ac_be_APSD:1; /* bit 3 */
445 u8 q_ack:1; /* bit 4 */
446 u8 max_len:2; /* bit 5-6 */
447 u8 more_data_ack:1; /* bit 7 */
448 } q_STA;
449 u8 val;
450};
451
452/* QoS structures */
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +0800453struct iwl_qos_info {
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800454 int qos_enable;
455 int qos_active;
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +0800456 union iwl_qos_capabity qos_cap;
457 struct iwl_qosparam_cmd def_qos_parm;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800458};
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800459
460#define STA_PS_STATUS_WAKE 0
461#define STA_PS_STATUS_SLEEP 1
462
Tomas Winkler6def9762008-05-05 10:22:31 +0800463struct iwl_station_entry {
Tomas Winkler133636d2008-05-05 10:22:34 +0800464 struct iwl_addsta_cmd sta;
Tomas Winkler6def9762008-05-05 10:22:31 +0800465 struct iwl_tid_data tid[MAX_TID_COUNT];
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800466 u8 used;
467 u8 ps_status;
Tomas Winkler6def9762008-05-05 10:22:31 +0800468 struct iwl_hw_key keyinfo;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800469};
470
471/* one for each uCode image (inst/data, boot/init/runtime) */
472struct fw_desc {
473 void *v_addr; /* access by driver */
474 dma_addr_t p_addr; /* access by card's busmaster DMA */
475 u32 len; /* bytes */
476};
477
478/* uCode file layout */
Ron Rindjunsky14b3d332008-06-13 15:44:54 +0800479struct iwl_ucode {
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800480 __le32 ver; /* major/minor/subminor */
481 __le32 inst_size; /* bytes of runtime instructions */
482 __le32 data_size; /* bytes of runtime data */
483 __le32 init_size; /* bytes of initialization instructions */
484 __le32 init_data_size; /* bytes of initialization data */
485 __le32 boot_size; /* bytes of bootstrap instructions */
486 u8 data[0]; /* data in same order as "size" elements */
487};
488
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800489struct iwl4965_ibss_seq {
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800490 u8 mac[ETH_ALEN];
491 u16 seq_num;
492 u16 frag_num;
493 unsigned long packet_time;
494 struct list_head list;
495};
496
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -0700497struct iwl_sensitivity_ranges {
498 u16 min_nrg_cck;
499 u16 max_nrg_cck;
500
501 u16 nrg_th_cck;
502 u16 nrg_th_ofdm;
503
504 u16 auto_corr_min_ofdm;
505 u16 auto_corr_min_ofdm_mrc;
506 u16 auto_corr_min_ofdm_x1;
507 u16 auto_corr_min_ofdm_mrc_x1;
508
509 u16 auto_corr_max_ofdm;
510 u16 auto_corr_max_ofdm_mrc;
511 u16 auto_corr_max_ofdm_x1;
512 u16 auto_corr_max_ofdm_mrc_x1;
513
514 u16 auto_corr_max_cck;
515 u16 auto_corr_max_cck_mrc;
516 u16 auto_corr_min_cck;
517 u16 auto_corr_min_cck_mrc;
518};
519
Ron Rindjunsky099b40b2008-04-21 15:41:53 -0700520
521#define IWL_FAT_CHANNEL_52 BIT(IEEE80211_BAND_5GHZ)
522
Ben Cahillbc472792007-11-29 11:09:49 +0800523/**
Tomas Winkler5425e492008-04-15 16:01:38 -0700524 * struct iwl_hw_params
Ben Cahillbc472792007-11-29 11:09:49 +0800525 * @max_txq_num: Max # Tx queues supported
Ron Rindjunsky099b40b2008-04-21 15:41:53 -0700526 * @tx/rx_chains_num: Number of TX/RX chains
527 * @valid_tx/rx_ant: usable antennas
Ben Cahillbc472792007-11-29 11:09:49 +0800528 * @max_rxq_size: Max # Rx frames in Rx queue (must be power-of-2)
Ben Cahillbc472792007-11-29 11:09:49 +0800529 * @max_rxq_log: Log-base-2 of max_rxq_size
Ron Rindjunsky099b40b2008-04-21 15:41:53 -0700530 * @rx_buf_size: Rx buffer size
Ben Cahillbc472792007-11-29 11:09:49 +0800531 * @max_stations:
532 * @bcast_sta_id:
Ron Rindjunsky099b40b2008-04-21 15:41:53 -0700533 * @fat_channel: is 40MHz width possible in band 2.4
534 * BIT(IEEE80211_BAND_5GHZ) BIT(IEEE80211_BAND_5GHZ)
535 * @sw_crypto: 0 for hw, 1 for sw
536 * @max_xxx_size: for ucode uses
537 * @ct_kill_threshold: temperature threshold
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -0700538 * @struct iwl_sensitivity_ranges: range of sensitivity values
Ron Rindjunsky7f3e4bb2008-06-12 09:46:55 +0800539 * @first_ampdu_q: first HW queue available for ampdu
Ben Cahillbc472792007-11-29 11:09:49 +0800540 */
Tomas Winkler5425e492008-04-15 16:01:38 -0700541struct iwl_hw_params {
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800542 u16 max_txq_num;
Tomas Winklerec35cf22008-04-15 16:01:39 -0700543 u8 tx_chains_num;
544 u8 rx_chains_num;
545 u8 valid_tx_ant;
546 u8 valid_rx_ant;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800547 u16 max_rxq_size;
Tomas Winklerec35cf22008-04-15 16:01:39 -0700548 u16 max_rxq_log;
Ron Rindjunsky9ee1ba42007-11-26 16:14:42 +0200549 u32 rx_buf_size;
550 u32 max_pkt_size;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800551 u8 max_stations;
552 u8 bcast_sta_id;
Ron Rindjunsky099b40b2008-04-21 15:41:53 -0700553 u8 fat_channel;
554 u8 sw_crypto;
555 u32 max_inst_size;
556 u32 max_data_size;
557 u32 max_bsm_size;
558 u32 ct_kill_threshold; /* value in hw-dependent units */
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -0700559 const struct iwl_sensitivity_ranges *sens;
Ron Rindjunsky7f3e4bb2008-06-12 09:46:55 +0800560 u8 first_ampdu_q;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800561};
562
Emmanuel Grumbacha9841012008-05-15 13:54:08 +0800563#define HT_SHORT_GI_20MHZ (1 << 0)
564#define HT_SHORT_GI_40MHZ (1 << 1)
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800565
566
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800567#define IWL_RX_HDR(x) ((struct iwl4965_rx_frame_hdr *)(\
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800568 x->u.rx_frame.stats.payload + \
569 x->u.rx_frame.stats.phy_count))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800570#define IWL_RX_END(x) ((struct iwl4965_rx_frame_end *)(\
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800571 IWL_RX_HDR(x)->payload + \
572 le16_to_cpu(IWL_RX_HDR(x)->len)))
573#define IWL_RX_STATS(x) (&x->u.rx_frame.stats)
574#define IWL_RX_DATA(x) (IWL_RX_HDR(x)->payload)
575
576
577/******************************************************************************
578 *
579 * Functions implemented in iwl-base.c which are forward declared here
580 * for use by iwl-*.c
581 *
582 *****************************************************************************/
Tomas Winkler133636d2008-05-05 10:22:34 +0800583struct iwl_addsta_cmd;
584extern int iwl_send_add_sta(struct iwl_priv *priv,
585 struct iwl_addsta_cmd *sta, u8 flags);
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800586u8 iwl_add_station_flags(struct iwl_priv *priv, const u8 *addr, int is_ap,
587 u8 flags, struct ieee80211_ht_info *ht_info);
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700588extern unsigned int iwl4965_fill_beacon_frame(struct iwl_priv *priv,
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800589 struct ieee80211_hdr *hdr,
590 const u8 *dest, int left);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700591extern void iwl4965_update_chain_flags(struct iwl_priv *priv);
Tomas Winkler079a2532008-04-17 16:03:39 -0700592int iwl4965_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src);
Mohamed Abbasca579612008-07-18 13:52:57 +0800593extern int iwl4965_set_power(struct iwl_priv *priv, void *cmd);
Tomas Winkler079a2532008-04-17 16:03:39 -0700594
Tomas Winkler57bd1be2008-05-15 13:54:03 +0800595extern const u8 iwl_bcast_addr[ETH_ALEN];
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800596
597/******************************************************************************
598 *
599 * Functions implemented in iwl-[34]*.c which are forward declared here
600 * for use by iwl-base.c
601 *
602 * NOTE: The implementation of these functions are hardware specific
603 * which is why they are in the hardware specific files (vs. iwl-base.c)
604 *
605 * Naming convention --
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800606 * iwl4965_ <-- Its part of iwlwifi (should be changed to iwl4965_)
607 * iwl4965_hw_ <-- Hardware specific (implemented in iwl-XXXX.c by all HW)
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800608 * iwlXXXX_ <-- Hardware specific (implemented in iwl-XXXX.c for XXXX)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800609 * iwl4965_bg_ <-- Called from work queue context
610 * iwl4965_mac_ <-- mac80211 callback
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800611 *
612 ****************************************************************************/
Tomas Winklerb3bbacb2008-05-29 16:35:01 +0800613extern int iwl_rxq_stop(struct iwl_priv *priv);
Tomas Winklerda1bc452008-05-29 16:35:00 +0800614extern void iwl_txq_ctx_stop(struct iwl_priv *priv);
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700615extern unsigned int iwl4965_hw_get_beacon_cmd(struct iwl_priv *priv,
Tomas Winklerfcab4232008-05-15 13:54:01 +0800616 struct iwl_frame *frame, u8 rate);
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700617extern void iwl4965_disable_events(struct iwl_priv *priv);
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800618
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700619extern int iwl4965_hw_channel_switch(struct iwl_priv *priv, u16 channel);
Tomas Winkler443cfd42008-05-15 13:53:57 +0800620extern int iwl_queue_space(const struct iwl_queue *q);
Tomas Winklerfd4abac2008-05-15 13:54:07 +0800621static inline int iwl_queue_used(const struct iwl_queue *q, int i)
622{
623 return q->write_ptr > q->read_ptr ?
624 (i >= q->read_ptr && i < q->write_ptr) :
625 !(i < q->read_ptr && i >= q->write_ptr);
626}
627
628
629static inline u8 get_cmd_index(struct iwl_queue *q, u32 index, int is_huge)
630{
631 /* This is for scan command, the big buffer at end of command array */
632 if (is_huge)
633 return q->n_window; /* must be power of 2 */
634
635 /* Otherwise, use normal size buffers */
636 return index & (q->n_window - 1);
637}
638
639
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700640struct iwl_priv;
Zhu Yib481de92007-09-25 17:54:57 -0700641
642/*
643 * Forward declare iwl-4965.c functions for iwl-base.c
644 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700645extern void iwl4965_rf_kill_ct_config(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -0700646
Tomas Winkler78330fd2008-02-06 02:37:18 +0200647int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw,
Ron Rindjunsky9ab46172007-12-25 17:00:38 +0200648 enum ieee80211_ampdu_mlme_action action,
Ron Rindjunsky0df3ef42008-01-28 14:07:15 +0200649 const u8 *addr, u16 tid, u16 *ssn);
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700650int iwl4965_check_empty_hw_queue(struct iwl_priv *priv, int sta_id,
Ron Rindjunskyfe01b472008-01-28 14:07:24 +0200651 u8 tid, int txq_id);
Tomas Winkler78330fd2008-02-06 02:37:18 +0200652
Zhu Yib481de92007-09-25 17:54:57 -0700653/* Structures, enum, and defines specific to the 4965 */
654
Ron Rindjunsky16466902008-05-05 10:22:50 +0800655#define IWL_KW_SIZE 0x1000 /*4k */
Zhu Yib481de92007-09-25 17:54:57 -0700656
Ron Rindjunsky16466902008-05-05 10:22:50 +0800657struct iwl_kw {
Zhu Yib481de92007-09-25 17:54:57 -0700658 dma_addr_t dma_addr;
659 void *v_addr;
660 size_t size;
661};
662
Zhu Yib481de92007-09-25 17:54:57 -0700663#define IWL_CHANNEL_WIDTH_20MHZ 0
664#define IWL_CHANNEL_WIDTH_40MHZ 1
665
666#define IWL_MIMO_PS_STATIC 0
667#define IWL_MIMO_PS_NONE 3
668#define IWL_MIMO_PS_DYNAMIC 1
669#define IWL_MIMO_PS_INVALID 2
670
671#define IWL_OPERATION_MODE_AUTO 0
672#define IWL_OPERATION_MODE_HT_ONLY 1
673#define IWL_OPERATION_MODE_MIXED 2
674#define IWL_OPERATION_MODE_20MHZ 3
675
Tomas Winkler3195cdb2008-04-23 17:15:00 -0700676#define IWL_TX_CRC_SIZE 4
677#define IWL_TX_DELIMITER_SIZE 4
Zhu Yib481de92007-09-25 17:54:57 -0700678
Zhu Yib481de92007-09-25 17:54:57 -0700679#define TX_POWER_IWL_ILLEGAL_VOLTAGE -10000
Zhu Yib481de92007-09-25 17:54:57 -0700680
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800681struct iwl4965_lq_mngr {
Zhu Yib481de92007-09-25 17:54:57 -0700682 spinlock_t lock;
683 s32 max_window_size;
684 s32 *expected_tpt;
685 u8 *next_higher_rate;
686 u8 *next_lower_rate;
687 unsigned long stamp;
688 unsigned long stamp_last;
689 u32 flush_time;
690 u32 tx_packets;
Zhu Yib481de92007-09-25 17:54:57 -0700691};
692
Zhu Yib481de92007-09-25 17:54:57 -0700693/* Sensitivity and chain noise calibration */
694#define INTERFERENCE_DATA_AVAILABLE __constant_cpu_to_le32(1)
695#define INITIALIZATION_VALUE 0xFFFF
696#define CAL_NUM_OF_BEACONS 20
697#define MAXIMUM_ALLOWED_PATHLOSS 15
698
Zhu Yib481de92007-09-25 17:54:57 -0700699#define CHAIN_NOISE_MAX_DELTA_GAIN_CODE 3
700
701#define MAX_FA_OFDM 50
702#define MIN_FA_OFDM 5
703#define MAX_FA_CCK 50
704#define MIN_FA_CCK 5
705
Zhu Yib481de92007-09-25 17:54:57 -0700706#define AUTO_CORR_STEP_OFDM 1
707
Zhu Yib481de92007-09-25 17:54:57 -0700708#define AUTO_CORR_STEP_CCK 3
709#define AUTO_CORR_MAX_TH_CCK 160
710
Zhu Yib481de92007-09-25 17:54:57 -0700711#define NRG_DIFF 2
712#define NRG_STEP_CCK 2
713#define NRG_MARGIN 8
714#define MAX_NUMBER_CCK_NO_FA 100
715
716#define AUTO_CORR_CCK_MIN_VAL_DEF (125)
717
718#define CHAIN_A 0
719#define CHAIN_B 1
720#define CHAIN_C 2
721#define CHAIN_NOISE_DELTA_GAIN_INIT_VAL 4
722#define ALL_BAND_FILTER 0xFF00
723#define IN_BAND_FILTER 0xFF
724#define MIN_AVERAGE_NOISE_MAX_VALUE 0xFFFFFFFF
725
Tomas Winkler3195cdb2008-04-23 17:15:00 -0700726#define NRG_NUM_PREV_STAT_L 20
727#define NUM_RX_CHAINS 3
728
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800729enum iwl4965_false_alarm_state {
Zhu Yib481de92007-09-25 17:54:57 -0700730 IWL_FA_TOO_MANY = 0,
731 IWL_FA_TOO_FEW = 1,
732 IWL_FA_GOOD_RANGE = 2,
733};
734
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800735enum iwl4965_chain_noise_state {
Zhu Yib481de92007-09-25 17:54:57 -0700736 IWL_CHAIN_NOISE_ALIVE = 0, /* must be 0 */
737 IWL_CHAIN_NOISE_ACCUMULATE = 1,
738 IWL_CHAIN_NOISE_CALIBRATED = 2,
739};
740
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800741enum iwl4965_calib_enabled_state {
Zhu Yib481de92007-09-25 17:54:57 -0700742 IWL_CALIB_DISABLED = 0, /* must be 0 */
743 IWL_CALIB_ENABLED = 1,
744};
745
746struct statistics_general_data {
747 u32 beacon_silence_rssi_a;
748 u32 beacon_silence_rssi_b;
749 u32 beacon_silence_rssi_c;
750 u32 beacon_energy_a;
751 u32 beacon_energy_b;
752 u32 beacon_energy_c;
753};
754
Tomas Winkler7c616cb2008-05-29 16:35:05 +0800755struct iwl_calib_results {
756 void *tx_iq_res;
757 void *tx_iq_perd_res;
758 void *lo_res;
759 u32 tx_iq_res_len;
760 u32 tx_iq_perd_res_len;
761 u32 lo_res_len;
762};
763
Ron Rindjunskydbb983b2008-05-15 13:54:12 +0800764enum ucode_type {
765 UCODE_NONE = 0,
766 UCODE_INIT,
767 UCODE_RT
768};
769
Zhu Yib481de92007-09-25 17:54:57 -0700770/* Sensitivity calib data */
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -0700771struct iwl_sensitivity_data {
Zhu Yib481de92007-09-25 17:54:57 -0700772 u32 auto_corr_ofdm;
773 u32 auto_corr_ofdm_mrc;
774 u32 auto_corr_ofdm_x1;
775 u32 auto_corr_ofdm_mrc_x1;
776 u32 auto_corr_cck;
777 u32 auto_corr_cck_mrc;
778
779 u32 last_bad_plcp_cnt_ofdm;
780 u32 last_fa_cnt_ofdm;
781 u32 last_bad_plcp_cnt_cck;
782 u32 last_fa_cnt_cck;
783
784 u32 nrg_curr_state;
785 u32 nrg_prev_state;
786 u32 nrg_value[10];
787 u8 nrg_silence_rssi[NRG_NUM_PREV_STAT_L];
788 u32 nrg_silence_ref;
789 u32 nrg_energy_idx;
790 u32 nrg_silence_idx;
791 u32 nrg_th_cck;
792 s32 nrg_auto_corr_silence_diff;
793 u32 num_in_cck_no_fa;
794 u32 nrg_th_ofdm;
Zhu Yib481de92007-09-25 17:54:57 -0700795};
796
797/* Chain noise (differential Rx gain) calib data */
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -0700798struct iwl_chain_noise_data {
Zhu Yib481de92007-09-25 17:54:57 -0700799 u8 state;
800 u16 beacon_count;
801 u32 chain_noise_a;
802 u32 chain_noise_b;
803 u32 chain_noise_c;
804 u32 chain_signal_a;
805 u32 chain_signal_b;
806 u32 chain_signal_c;
807 u8 disconn_array[NUM_RX_CHAINS];
808 u8 delta_gain_code[NUM_RX_CHAINS];
809 u8 radio_write;
810};
811
Ben Cahillabceddb2007-11-29 11:09:50 +0800812#define EEPROM_SEM_TIMEOUT 10 /* milliseconds */
813#define EEPROM_SEM_RETRY_LIMIT 1000 /* number of attempts (not time) */
Zhu Yib481de92007-09-25 17:54:57 -0700814
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800815
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800816#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800817
818enum {
819 MEASUREMENT_READY = (1 << 0),
820 MEASUREMENT_ACTIVE = (1 << 1),
821};
822
823#endif
824
Ron Rindjunskydfe7d452008-04-15 16:01:45 -0700825#define IWL_MAX_NUM_QUEUES 20 /* FIXME: do dynamic allocation */
826
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700827struct iwl_priv {
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800828
829 /* ieee device used by generic ieee processing code */
830 struct ieee80211_hw *hw;
831 struct ieee80211_channel *ieee_channels;
832 struct ieee80211_rate *ieee_rates;
Tomas Winkler82b9a122008-03-04 18:09:30 -0800833 struct iwl_cfg *cfg;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800834
835 /* temporary frame storage list */
836 struct list_head free_frames;
837 int frames_count;
838
Johannes Berg8318d782008-01-24 19:38:38 +0100839 enum ieee80211_band band;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800840 int alloc_rxb_skb;
Zhu Yi12342c42007-12-20 11:27:32 +0800841 bool add_radiotap;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800842
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700843 void (*rx_handlers[REPLY_MAX])(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +0800844 struct iwl_rx_mem_buffer *rxb);
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800845
Johannes Berg8318d782008-01-24 19:38:38 +0100846 struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800847
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800848#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800849 /* spectrum measurement report caching */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800850 struct iwl4965_spectrum_notification measure_report;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800851 u8 measurement_status;
852#endif
853 /* ucode beacon time */
854 u32 ucode_beacon_time;
855
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800856 /* we allocate array of iwl4965_channel_info for NIC's valid channels.
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800857 * Access via channel # using indirect index array */
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700858 struct iwl_channel_info *channel_info; /* channel info array */
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800859 u8 channel_count; /* # of channels */
860
861 /* each calibration channel group in the EEPROM has a derived
862 * clip setting for each rate. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800863 const struct iwl4965_clip_group clip_groups[5];
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800864
865 /* thermal calibration */
866 s32 temperature; /* degrees Kelvin */
867 s32 last_temperature;
868
Tomas Winkler7c616cb2008-05-29 16:35:05 +0800869 /* init calibration results */
870 struct iwl_calib_results calib_results;
871
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800872 /* Scan related variables */
873 unsigned long last_scan_jiffies;
Mohamed Abbas7878a5a2007-11-29 11:10:13 +0800874 unsigned long next_scan_jiffies;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800875 unsigned long scan_start;
876 unsigned long scan_pass_start;
877 unsigned long scan_start_tsf;
878 int scan_bands;
879 int one_direct_scan;
880 u8 direct_ssid_len;
881 u8 direct_ssid[IW_ESSID_MAX_SIZE];
Tomas Winkler2a421b92008-06-12 09:47:10 +0800882 struct iwl_scan_cmd *scan;
Tomas Winklerf53696d2008-06-12 09:47:12 +0800883 u32 scan_tx_ant[IEEE80211_NUM_BANDS];
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800884
885 /* spinlock */
886 spinlock_t lock; /* protect general shared data */
887 spinlock_t hcmd_lock; /* protect hcmd */
888 struct mutex mutex;
889
890 /* basic pci-network driver stuff */
891 struct pci_dev *pci_dev;
892
893 /* pci hardware address support */
894 void __iomem *hw_base;
Tomas Winklerb661c812008-04-23 17:14:54 -0700895 u32 hw_rev;
896 u32 hw_wa_rev;
897 u8 rev_id;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800898
899 /* uCode images, save to reload in case of failure */
900 struct fw_desc ucode_code; /* runtime inst */
901 struct fw_desc ucode_data; /* runtime data original */
902 struct fw_desc ucode_data_backup; /* runtime data save/restore */
903 struct fw_desc ucode_init; /* initialization inst */
904 struct fw_desc ucode_init_data; /* initialization data */
905 struct fw_desc ucode_boot; /* bootstrap inst */
Ron Rindjunskydbb983b2008-05-15 13:54:12 +0800906 enum ucode_type ucode_type;
907 u8 ucode_write_complete; /* the image write is complete */
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800908
909
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800910 struct iwl4965_rxon_time_cmd rxon_timing;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800911
912 /* We declare this const so it can only be
913 * changed via explicit cast within the
914 * routines that actually update the physical
915 * hardware */
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800916 const struct iwl_rxon_cmd active_rxon;
917 struct iwl_rxon_cmd staging_rxon;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800918
919 int error_recovering;
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800920 struct iwl_rxon_cmd recovery_rxon;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800921
922 /* 1st responses from initialize and runtime uCode images.
923 * 4965's initialize alive response contains some calibration data. */
Tomas Winkler885ba202008-05-29 16:34:55 +0800924 struct iwl_init_alive_resp card_alive_init;
925 struct iwl_alive_resp card_alive;
Reinette Chatreeadd3c42008-04-14 21:16:12 -0700926#ifdef CONFIG_IWLWIFI_RFKILL
Adel Gadllah80fcc9e2008-07-01 17:49:50 +0200927 struct rfkill *rfkill;
Mohamed Abbasad97edd2008-03-28 16:21:06 -0700928#endif
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800929
Reinette Chatre36316122008-04-02 10:50:35 -0700930#ifdef CONFIG_IWLWIFI_LEDS
Tomas Winkler0eee6122008-07-11 11:53:36 +0800931 struct iwl_led led[IWL_LED_TRG_MAX];
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700932 unsigned long last_blink_time;
933 u8 last_blink_rate;
934 u8 allow_blinking;
935 u64 led_tpt;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800936#endif
937
938 u16 active_rate;
939 u16 active_rate_basic;
940
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800941 u8 assoc_station_added;
942 u8 use_ant_b_for_management_frame; /* Tx antenna selection */
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800943 u8 start_calib;
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -0700944 struct iwl_sensitivity_data sensitivity_data;
945 struct iwl_chain_noise_data chain_noise_data;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800946 __le16 sensitivity_tbl[HD_TABLE_SIZE];
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800947
Ron Rindjunsky9e0cc6d2007-11-26 16:14:36 +0200948 struct iwl_ht_info current_ht_config;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800949 u8 last_phy_res[100];
950
951 /* Rate scaling data */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800952 struct iwl4965_lq_mngr lq_mngr;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800953
954 /* Rate scaling data */
955 s8 data_retry_limit;
956 u8 retry_rate;
957
958 wait_queue_head_t wait_command_queue;
959
960 int activity_timer_active;
961
962 /* Rx and Tx DMA processing queues */
Tomas Winklera55360e2008-05-05 10:22:28 +0800963 struct iwl_rx_queue rxq;
Ron Rindjunsky16466902008-05-05 10:22:50 +0800964 struct iwl_tx_queue txq[IWL_MAX_NUM_QUEUES];
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800965 unsigned long txq_ctx_active_msk;
Ron Rindjunsky16466902008-05-05 10:22:50 +0800966 struct iwl_kw kw; /* keep warm address */
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800967 u32 scd_base_addr; /* scheduler sram base address */
968
969 unsigned long status;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800970
971 int last_rx_rssi; /* From Rx packet statisitics */
972 int last_rx_noise; /* From beacon statistics */
973
Tomas Winkler19758be2008-03-12 16:58:51 -0700974 /* counts mgmt, ctl, and data packets */
975 struct traffic_stats {
976 u32 cnt;
977 u64 bytes;
978 } tx_stats[3], rx_stats[3];
979
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700980 struct iwl_power_mgr power_data;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800981
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +0800982 struct iwl_notif_statistics statistics;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +0800983 unsigned long last_statistics_time;
984
985 /* context information */
986 u8 essid[IW_ESSID_MAX_SIZE];
987 u8 essid_len;
988 u16 rates_mask;
989
990 u32 power_mode;
991 u32 antenna;
992 u8 bssid[ETH_ALEN];
993 u16 rts_threshold;
994 u8 mac_addr[ETH_ALEN];
995
996 /*station table variables */
997 spinlock_t sta_lock;
998 int num_stations;
Tomas Winkler6def9762008-05-05 10:22:31 +0800999 struct iwl_station_entry stations[IWL_STATION_COUNT];
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07001000 struct iwl_wep_key wep_keys[WEP_KEYS_MAX];
1001 u8 default_wep_key;
1002 u8 key_mapping_key;
Emmanuel Grumbach80fb47a2008-04-14 21:16:08 -07001003 unsigned long ucode_key_table;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +08001004
1005 /* Indication if ieee80211_ops->open has been called */
Tomas Winkler69dc5d92008-03-25 16:33:41 -07001006 u8 is_open;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +08001007
1008 u8 mac80211_registered;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +08001009
Christoph Hellwig5d08cd12007-10-25 17:15:50 +08001010 /* Rx'd packet timing information */
1011 u32 last_beacon_time;
1012 u64 last_tsf;
1013
Christoph Hellwig5d08cd12007-10-25 17:15:50 +08001014 /* eeprom */
Tomas Winkler073d3f52008-04-21 15:41:52 -07001015 u8 *eeprom;
1016 struct iwl_eeprom_calib_info *calib_info;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +08001017
Tomas Winkler69dc5d92008-03-25 16:33:41 -07001018 enum ieee80211_if_types iw_mode;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +08001019
1020 struct sk_buff *ibss_beacon;
1021
1022 /* Last Rx'd beacon timestamp */
Tomas Winkler3109ece2008-03-28 16:33:35 -07001023 u64 timestamp;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +08001024 u16 beacon_int;
Johannes Berg32bfd352007-12-19 01:31:26 +01001025 struct ieee80211_vif *vif;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +08001026
Tomas Winkler5425e492008-04-15 16:01:38 -07001027 struct iwl_hw_params hw_params;
Tomas Winkler059ff822008-04-14 21:16:14 -07001028 /* driver/uCode shared Tx Byte Counts and Rx status */
1029 void *shared_virt;
Ron Rindjunskyd67f5482008-05-05 10:22:49 +08001030 int rb_closed_offset;
Tomas Winkler059ff822008-04-14 21:16:14 -07001031 /* Physical Pointer to Tx Byte Counts and Rx status */
1032 dma_addr_t shared_phys;
1033
Christoph Hellwig5d08cd12007-10-25 17:15:50 +08001034 /* Current association information needed to configure the
1035 * hardware */
1036 u16 assoc_id;
1037 u16 assoc_capability;
1038 u8 ps_mode;
1039
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08001040 struct iwl_qos_info qos_data;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +08001041
1042 struct workqueue_struct *workqueue;
1043
1044 struct work_struct up;
1045 struct work_struct restart;
1046 struct work_struct calibrated_work;
1047 struct work_struct scan_completed;
1048 struct work_struct rx_replenish;
1049 struct work_struct rf_kill;
1050 struct work_struct abort_scan;
1051 struct work_struct update_link_led;
1052 struct work_struct auth_work;
1053 struct work_struct report_work;
1054 struct work_struct request_scan;
1055 struct work_struct beacon_update;
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08001056 struct work_struct set_monitor;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +08001057
1058 struct tasklet_struct irq_tasklet;
1059
1060 struct delayed_work init_alive_start;
1061 struct delayed_work alive_start;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +08001062 struct delayed_work scan_check;
Tomas Winkler630fe9b2008-06-12 09:47:08 +08001063 /* TX Power */
1064 s8 tx_power_user_lmt;
1065 s8 tx_power_channel_lmt;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +08001066
1067#ifdef CONFIG_PM
1068 u32 pm_state[16];
1069#endif
1070
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001071#ifdef CONFIG_IWLWIFI_DEBUG
Christoph Hellwig5d08cd12007-10-25 17:15:50 +08001072 /* debugging info */
Ester Kummerbf403db2008-05-05 10:22:40 +08001073 u32 debug_level;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +08001074 u32 framecnt_to_us;
1075 atomic_t restrict_refcnt;
Tomas Winkler712b6cf2008-03-12 16:58:52 -07001076#ifdef CONFIG_IWLWIFI_DEBUGFS
1077 /* debugfs */
1078 struct iwl_debugfs *dbgfs;
1079#endif /* CONFIG_IWLWIFI_DEBUGFS */
1080#endif /* CONFIG_IWLWIFI_DEBUG */
Christoph Hellwig5d08cd12007-10-25 17:15:50 +08001081
1082 struct work_struct txpower_work;
Tomas Winkler445c2df2008-05-15 13:54:16 +08001083 u32 disable_sens_cal;
1084 u32 disable_chain_noise_cal;
Emmanuel Grumbach203566f2008-06-12 09:46:54 +08001085 u32 disable_tx_power_cal;
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08001086 struct work_struct run_time_calib_work;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +08001087 struct timer_list statistics_periodic;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001088}; /*iwl_priv */
Christoph Hellwig5d08cd12007-10-25 17:15:50 +08001089
Ron Rindjunsky36470742008-05-15 13:54:10 +08001090static inline void iwl_txq_ctx_activate(struct iwl_priv *priv, int txq_id)
1091{
1092 set_bit(txq_id, &priv->txq_ctx_active_msk);
1093}
1094
1095static inline void iwl_txq_ctx_deactivate(struct iwl_priv *priv, int txq_id)
1096{
1097 clear_bit(txq_id, &priv->txq_ctx_active_msk);
1098}
1099
Helmut Schaa994d31f2008-07-02 12:17:06 +02001100#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winklera332f8d2008-05-29 16:35:08 +08001101const char *iwl_get_tx_fail_reason(u32 status);
1102#else
1103static inline const char *iwl_get_tx_fail_reason(u32 status) { return ""; }
1104#endif
1105
1106
Tomas Winklera332f8d2008-05-29 16:35:08 +08001107static inline struct ieee80211_hdr *iwl_tx_queue_get_hdr(struct iwl_priv *priv,
1108 int txq_id, int idx)
1109{
1110 if (priv->txq[txq_id].txb[idx].skb[0])
1111 return (struct ieee80211_hdr *)priv->txq[txq_id].
1112 txb[idx].skb[0]->data;
1113 return NULL;
1114}
Tomas Winklera332f8d2008-05-29 16:35:08 +08001115
1116
Tomas Winkler3109ece2008-03-28 16:33:35 -07001117static inline int iwl_is_associated(struct iwl_priv *priv)
Christoph Hellwig5d08cd12007-10-25 17:15:50 +08001118{
1119 return (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0;
1120}
1121
Assaf Kraussbf85ea42008-03-14 10:38:49 -07001122static inline int is_channel_valid(const struct iwl_channel_info *ch_info)
Christoph Hellwig5d08cd12007-10-25 17:15:50 +08001123{
1124 if (ch_info == NULL)
1125 return 0;
1126 return (ch_info->flags & EEPROM_CHANNEL_VALID) ? 1 : 0;
1127}
1128
Assaf Kraussbf85ea42008-03-14 10:38:49 -07001129static inline int is_channel_radar(const struct iwl_channel_info *ch_info)
Christoph Hellwig5d08cd12007-10-25 17:15:50 +08001130{
1131 return (ch_info->flags & EEPROM_CHANNEL_RADAR) ? 1 : 0;
1132}
1133
Assaf Kraussbf85ea42008-03-14 10:38:49 -07001134static inline u8 is_channel_a_band(const struct iwl_channel_info *ch_info)
Christoph Hellwig5d08cd12007-10-25 17:15:50 +08001135{
Johannes Berg8318d782008-01-24 19:38:38 +01001136 return ch_info->band == IEEE80211_BAND_5GHZ;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +08001137}
1138
Assaf Kraussbf85ea42008-03-14 10:38:49 -07001139static inline u8 is_channel_bg_band(const struct iwl_channel_info *ch_info)
Christoph Hellwig5d08cd12007-10-25 17:15:50 +08001140{
Johannes Berg8318d782008-01-24 19:38:38 +01001141 return ch_info->band == IEEE80211_BAND_2GHZ;
Christoph Hellwig5d08cd12007-10-25 17:15:50 +08001142}
1143
Assaf Kraussbf85ea42008-03-14 10:38:49 -07001144static inline int is_channel_passive(const struct iwl_channel_info *ch)
Christoph Hellwig5d08cd12007-10-25 17:15:50 +08001145{
1146 return (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) ? 1 : 0;
1147}
1148
Assaf Kraussbf85ea42008-03-14 10:38:49 -07001149static inline int is_channel_ibss(const struct iwl_channel_info *ch)
Christoph Hellwig5d08cd12007-10-25 17:15:50 +08001150{
1151 return ((ch->flags & EEPROM_CHANNEL_IBSS)) ? 1 : 0;
1152}
1153
Ester Kummerbf403db2008-05-05 10:22:40 +08001154#ifdef CONFIG_IWLWIFI_DEBUG
1155static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level,
1156 void *p, u32 len)
1157{
1158 if (!(priv->debug_level & level))
1159 return;
1160
1161 print_hex_dump(KERN_DEBUG, "iwl data: ", DUMP_PREFIX_OFFSET, 16, 1,
1162 p, len, 1);
1163}
1164#else
1165static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level,
1166 void *p, u32 len)
1167{
1168}
1169#endif
1170
Assaf Krauss8622e702008-03-21 13:53:43 -07001171extern const struct iwl_channel_info *iwl_get_channel_info(
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001172 const struct iwl_priv *priv, enum ieee80211_band band, u16 channel);
Christoph Hellwig5d08cd12007-10-25 17:15:50 +08001173
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001174/* Requires full declaration of iwl_priv before including */
Christoph Hellwig5d08cd12007-10-25 17:15:50 +08001175
Emmanuel Grumbachbe1f3ab62008-06-12 09:47:18 +08001176#endif /* __iwl_dev_h__ */