blob: b1d237fc5fb7f5ea0be278238c689de8fd4609e9 [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>
Stanislaw Gruszka47ef6942011-08-31 14:04:45 +020034#include <net/mac80211.h>
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +020035#include <net/ieee80211_radiotap.h>
36
Stanislaw Gruszka99412002011-08-31 13:53:04 +020037#include "commands.h"
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +020038#include "csr.h"
Stanislaw Gruszkae8c39d42011-08-31 14:09:39 +020039#include "prph.h"
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +020040
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +020041struct il_host_cmd;
42struct il_cmd;
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +020043struct il_tx_queue;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -080044
Stanislaw Gruszkaf02579e2011-08-31 14:49:56 +020045#define IL_ERR(f, a...) dev_err(&il->pci_dev->dev, f, ## a)
46#define IL_WARN(f, a...) dev_warn(&il->pci_dev->dev, f, ## a)
47#define IL_INFO(f, a...) dev_info(&il->pci_dev->dev, f, ## a)
48
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +020049#define RX_QUEUE_SIZE 256
50#define RX_QUEUE_MASK 255
51#define RX_QUEUE_SIZE_LOG 8
52
53/*
54 * RX related structures and functions
55 */
56#define RX_FREE_BUFFERS 64
57#define RX_LOW_WATERMARK 8
58
59#define U32_PAD(n) ((4-(n))&0x3)
60
61/* CT-KILL constants */
62#define CT_KILL_THRESHOLD_LEGACY 110 /* in Celsius */
63
64/* Default noise level to report when noise measurement is not available.
65 * This may be because we're:
66 * 1) Not associated (4965, no beacon stats being sent to driver)
67 * 2) Scanning (noise measurement does not apply to associated channel)
68 * 3) Receiving CCK (3945 delivers noise info only for OFDM frames)
69 * Use default noise value of -127 ... this is below the range of measurable
70 * Rx dBm for either 3945 or 4965, so it can indicate "unmeasurable" to user.
71 * Also, -127 works better than 0 when averaging frames with/without
72 * noise info (e.g. averaging might be done in app); measured dBm values are
73 * always negative ... using a negative value as the default keeps all
74 * averages within an s8's (used in some apps) range of negative values. */
75#define IL_NOISE_MEAS_NOT_AVAILABLE (-127)
76
77/*
78 * RTS threshold here is total size [2347] minus 4 FCS bytes
79 * Per spec:
80 * a value of 0 means RTS on all data/management packets
81 * a value > max MSDU size means no RTS
82 * else RTS for data/management frames where MPDU is larger
83 * than RTS value.
84 */
85#define DEFAULT_RTS_THRESHOLD 2347U
86#define MIN_RTS_THRESHOLD 0U
87#define MAX_RTS_THRESHOLD 2347U
88#define MAX_MSDU_SIZE 2304U
89#define MAX_MPDU_SIZE 2346U
90#define DEFAULT_BEACON_INTERVAL 100U
91#define DEFAULT_SHORT_RETRY_LIMIT 7U
92#define DEFAULT_LONG_RETRY_LIMIT 4U
93
94struct il_rx_buf {
95 dma_addr_t page_dma;
96 struct page *page;
97 struct list_head list;
98};
99
100#define rxb_addr(r) page_address(r->page)
101
102/* defined below */
103struct il_device_cmd;
104
105struct il_cmd_meta {
106 /* only for SYNC commands, iff the reply skb is wanted */
107 struct il_host_cmd *source;
108 /*
109 * only for ASYNC commands
110 * (which is somewhat stupid -- look at common.c for instance
111 * which duplicates a bunch of code because the callback isn't
112 * invoked for SYNC commands, if it were and its result passed
113 * through it would be simpler...)
114 */
115 void (*callback)(struct il_priv *il,
116 struct il_device_cmd *cmd,
117 struct il_rx_pkt *pkt);
118
119 /* The CMD_SIZE_HUGE flag bit indicates that the command
120 * structure is stored at the end of the shared queue memory. */
121 u32 flags;
122
123 DEFINE_DMA_UNMAP_ADDR(mapping);
124 DEFINE_DMA_UNMAP_LEN(len);
125};
126
127/*
128 * Generic queue structure
129 *
130 * Contains common data for Rx and Tx queues
131 */
132struct il_queue {
133 int n_bd; /* number of BDs in this queue */
134 int write_ptr; /* 1-st empty entry (idx) host_w*/
135 int read_ptr; /* last used entry (idx) host_r*/
136 /* use for monitoring and recovering the stuck queue */
137 dma_addr_t dma_addr; /* physical addr for BD's */
138 int n_win; /* safe queue win */
139 u32 id;
140 int low_mark; /* low watermark, resume queue if free
141 * space more than this */
142 int high_mark; /* high watermark, stop queue if free
143 * space less than this */
144};
145
146/* One for each TFD */
147struct il_tx_info {
148 struct sk_buff *skb;
149 struct il_rxon_context *ctx;
150};
151
152/**
153 * struct il_tx_queue - Tx Queue for DMA
154 * @q: generic Rx/Tx queue descriptor
155 * @bd: base of circular buffer of TFDs
156 * @cmd: array of command/TX buffer pointers
157 * @meta: array of meta data for each command/tx buffer
158 * @dma_addr_cmd: physical address of cmd/tx buffer array
159 * @txb: array of per-TFD driver data
160 * @time_stamp: time (in jiffies) of last read_ptr change
161 * @need_update: indicates need to update read/write idx
162 * @sched_retry: indicates queue is high-throughput aggregation (HT AGG) enabled
163 *
164 * A Tx queue consists of circular buffer of BDs (a.k.a. TFDs, transmit frame
165 * descriptors) and required locking structures.
166 */
167#define TFD_TX_CMD_SLOTS 256
168#define TFD_CMD_SLOTS 32
169
170struct il_tx_queue {
171 struct il_queue q;
172 void *tfds;
173 struct il_device_cmd **cmd;
174 struct il_cmd_meta *meta;
175 struct il_tx_info *txb;
176 unsigned long time_stamp;
177 u8 need_update;
178 u8 sched_retry;
179 u8 active;
180 u8 swq_id;
181};
182
Stanislaw Gruszka47ef6942011-08-31 14:04:45 +0200183/*
184 * EEPROM access time values:
185 *
186 * Driver initiates EEPROM read by writing byte address << 1 to CSR_EEPROM_REG.
187 * Driver then polls CSR_EEPROM_REG for CSR_EEPROM_REG_READ_VALID_MSK (0x1).
188 * When polling, wait 10 uSec between polling loops, up to a maximum 5000 uSec.
189 * Driver reads 16-bit value from bits 31-16 of CSR_EEPROM_REG.
190 */
191#define IL_EEPROM_ACCESS_TIMEOUT 5000 /* uSec */
192
193#define IL_EEPROM_SEM_TIMEOUT 10 /* microseconds */
194#define IL_EEPROM_SEM_RETRY_LIMIT 1000 /* number of attempts (not time) */
195
196
197/*
198 * Regulatory channel usage flags in EEPROM struct il4965_eeprom_channel.flags.
199 *
200 * IBSS and/or AP operation is allowed *only* on those channels with
201 * (VALID && IBSS && ACTIVE && !RADAR). This restriction is in place because
202 * RADAR detection is not supported by the 4965 driver, but is a
203 * requirement for establishing a new network for legal operation on channels
204 * requiring RADAR detection or restricting ACTIVE scanning.
205 *
206 * NOTE: "WIDE" flag does not indicate anything about "HT40" 40 MHz channels.
207 * It only indicates that 20 MHz channel use is supported; HT40 channel
208 * usage is indicated by a separate set of regulatory flags for each
209 * HT40 channel pair.
210 *
211 * NOTE: Using a channel inappropriately will result in a uCode error!
212 */
213#define IL_NUM_TX_CALIB_GROUPS 5
214enum {
215 EEPROM_CHANNEL_VALID = (1 << 0), /* usable for this SKU/geo */
216 EEPROM_CHANNEL_IBSS = (1 << 1), /* usable as an IBSS channel */
217 /* Bit 2 Reserved */
218 EEPROM_CHANNEL_ACTIVE = (1 << 3), /* active scanning allowed */
219 EEPROM_CHANNEL_RADAR = (1 << 4), /* radar detection required */
220 EEPROM_CHANNEL_WIDE = (1 << 5), /* 20 MHz channel okay */
221 /* Bit 6 Reserved (was Narrow Channel) */
222 EEPROM_CHANNEL_DFS = (1 << 7), /* dynamic freq selection candidate */
223};
224
225/* SKU Capabilities */
226/* 3945 only */
227#define EEPROM_SKU_CAP_SW_RF_KILL_ENABLE (1 << 0)
228#define EEPROM_SKU_CAP_HW_RF_KILL_ENABLE (1 << 1)
229
230/* *regulatory* channel data format in eeprom, one for each channel.
231 * There are separate entries for HT40 (40 MHz) vs. normal (20 MHz) channels. */
232struct il_eeprom_channel {
233 u8 flags; /* EEPROM_CHANNEL_* flags copied from EEPROM */
234 s8 max_power_avg; /* max power (dBm) on this chnl, limit 31 */
235} __packed;
236
237/* 3945 Specific */
238#define EEPROM_3945_EEPROM_VERSION (0x2f)
239
240/* 4965 has two radio transmitters (and 3 radio receivers) */
241#define EEPROM_TX_POWER_TX_CHAINS (2)
242
243/* 4965 has room for up to 8 sets of txpower calibration data */
244#define EEPROM_TX_POWER_BANDS (8)
245
246/* 4965 factory calibration measures txpower gain settings for
247 * each of 3 target output levels */
248#define EEPROM_TX_POWER_MEASUREMENTS (3)
249
250/* 4965 Specific */
251/* 4965 driver does not work with txpower calibration version < 5 */
252#define EEPROM_4965_TX_POWER_VERSION (5)
253#define EEPROM_4965_EEPROM_VERSION (0x2f)
254#define EEPROM_4965_CALIB_VERSION_OFFSET (2*0xB6) /* 2 bytes */
255#define EEPROM_4965_CALIB_TXPOWER_OFFSET (2*0xE8) /* 48 bytes */
256#define EEPROM_4965_BOARD_REVISION (2*0x4F) /* 2 bytes */
257#define EEPROM_4965_BOARD_PBA (2*0x56+1) /* 9 bytes */
258
259/* 2.4 GHz */
260extern const u8 il_eeprom_band_1[14];
261
262/*
263 * factory calibration data for one txpower level, on one channel,
264 * measured on one of the 2 tx chains (radio transmitter and associated
265 * antenna). EEPROM contains:
266 *
267 * 1) Temperature (degrees Celsius) of device when measurement was made.
268 *
269 * 2) Gain table idx used to achieve the target measurement power.
270 * This refers to the "well-known" gain tables (see 4965.h).
271 *
272 * 3) Actual measured output power, in half-dBm ("34" = 17 dBm).
273 *
274 * 4) RF power amplifier detector level measurement (not used).
275 */
276struct il_eeprom_calib_measure {
277 u8 temperature; /* Device temperature (Celsius) */
278 u8 gain_idx; /* Index into gain table */
279 u8 actual_pow; /* Measured RF output power, half-dBm */
280 s8 pa_det; /* Power amp detector level (not used) */
281} __packed;
282
283
284/*
285 * measurement set for one channel. EEPROM contains:
286 *
287 * 1) Channel number measured
288 *
289 * 2) Measurements for each of 3 power levels for each of 2 radio transmitters
290 * (a.k.a. "tx chains") (6 measurements altogether)
291 */
292struct il_eeprom_calib_ch_info {
293 u8 ch_num;
294 struct il_eeprom_calib_measure
295 measurements[EEPROM_TX_POWER_TX_CHAINS]
296 [EEPROM_TX_POWER_MEASUREMENTS];
297} __packed;
298
299/*
300 * txpower subband info.
301 *
302 * For each frequency subband, EEPROM contains the following:
303 *
304 * 1) First and last channels within range of the subband. "0" values
305 * indicate that this sample set is not being used.
306 *
307 * 2) Sample measurement sets for 2 channels close to the range endpoints.
308 */
309struct il_eeprom_calib_subband_info {
310 u8 ch_from; /* channel number of lowest channel in subband */
311 u8 ch_to; /* channel number of highest channel in subband */
312 struct il_eeprom_calib_ch_info ch1;
313 struct il_eeprom_calib_ch_info ch2;
314} __packed;
315
316
317/*
318 * txpower calibration info. EEPROM contains:
319 *
320 * 1) Factory-measured saturation power levels (maximum levels at which
321 * tx power amplifier can output a signal without too much distortion).
322 * There is one level for 2.4 GHz band and one for 5 GHz band. These
323 * values apply to all channels within each of the bands.
324 *
325 * 2) Factory-measured power supply voltage level. This is assumed to be
326 * constant (i.e. same value applies to all channels/bands) while the
327 * factory measurements are being made.
328 *
329 * 3) Up to 8 sets of factory-measured txpower calibration values.
330 * These are for different frequency ranges, since txpower gain
331 * characteristics of the analog radio circuitry vary with frequency.
332 *
333 * Not all sets need to be filled with data;
334 * struct il_eeprom_calib_subband_info contains range of channels
335 * (0 if unused) for each set of data.
336 */
337struct il_eeprom_calib_info {
338 u8 saturation_power24; /* half-dBm (e.g. "34" = 17 dBm) */
339 u8 saturation_power52; /* half-dBm */
340 __le16 voltage; /* signed */
341 struct il_eeprom_calib_subband_info
342 band_info[EEPROM_TX_POWER_BANDS];
343} __packed;
344
345
346/* General */
347#define EEPROM_DEVICE_ID (2*0x08) /* 2 bytes */
348#define EEPROM_MAC_ADDRESS (2*0x15) /* 6 bytes */
349#define EEPROM_BOARD_REVISION (2*0x35) /* 2 bytes */
350#define EEPROM_BOARD_PBA_NUMBER (2*0x3B+1) /* 9 bytes */
351#define EEPROM_VERSION (2*0x44) /* 2 bytes */
352#define EEPROM_SKU_CAP (2*0x45) /* 2 bytes */
353#define EEPROM_OEM_MODE (2*0x46) /* 2 bytes */
354#define EEPROM_WOWLAN_MODE (2*0x47) /* 2 bytes */
355#define EEPROM_RADIO_CONFIG (2*0x48) /* 2 bytes */
356#define EEPROM_NUM_MAC_ADDRESS (2*0x4C) /* 2 bytes */
357
358/* The following masks are to be applied on EEPROM_RADIO_CONFIG */
359#define EEPROM_RF_CFG_TYPE_MSK(x) (x & 0x3) /* bits 0-1 */
360#define EEPROM_RF_CFG_STEP_MSK(x) ((x >> 2) & 0x3) /* bits 2-3 */
361#define EEPROM_RF_CFG_DASH_MSK(x) ((x >> 4) & 0x3) /* bits 4-5 */
362#define EEPROM_RF_CFG_PNUM_MSK(x) ((x >> 6) & 0x3) /* bits 6-7 */
363#define EEPROM_RF_CFG_TX_ANT_MSK(x) ((x >> 8) & 0xF) /* bits 8-11 */
364#define EEPROM_RF_CFG_RX_ANT_MSK(x) ((x >> 12) & 0xF) /* bits 12-15 */
365
366#define EEPROM_3945_RF_CFG_TYPE_MAX 0x0
367#define EEPROM_4965_RF_CFG_TYPE_MAX 0x1
368
369/*
370 * Per-channel regulatory data.
371 *
372 * Each channel that *might* be supported by iwl has a fixed location
373 * in EEPROM containing EEPROM_CHANNEL_* usage flags (LSB) and max regulatory
374 * txpower (MSB).
375 *
376 * Entries immediately below are for 20 MHz channel width. HT40 (40 MHz)
377 * channels (only for 4965, not supported by 3945) appear later in the EEPROM.
378 *
379 * 2.4 GHz channels 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
380 */
381#define EEPROM_REGULATORY_SKU_ID (2*0x60) /* 4 bytes */
382#define EEPROM_REGULATORY_BAND_1 (2*0x62) /* 2 bytes */
383#define EEPROM_REGULATORY_BAND_1_CHANNELS (2*0x63) /* 28 bytes */
384
385/*
386 * 4.9 GHz channels 183, 184, 185, 187, 188, 189, 192, 196,
387 * 5.0 GHz channels 7, 8, 11, 12, 16
388 * (4915-5080MHz) (none of these is ever supported)
389 */
390#define EEPROM_REGULATORY_BAND_2 (2*0x71) /* 2 bytes */
391#define EEPROM_REGULATORY_BAND_2_CHANNELS (2*0x72) /* 26 bytes */
392
393/*
394 * 5.2 GHz channels 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
395 * (5170-5320MHz)
396 */
397#define EEPROM_REGULATORY_BAND_3 (2*0x7F) /* 2 bytes */
398#define EEPROM_REGULATORY_BAND_3_CHANNELS (2*0x80) /* 24 bytes */
399
400/*
401 * 5.5 GHz channels 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
402 * (5500-5700MHz)
403 */
404#define EEPROM_REGULATORY_BAND_4 (2*0x8C) /* 2 bytes */
405#define EEPROM_REGULATORY_BAND_4_CHANNELS (2*0x8D) /* 22 bytes */
406
407/*
408 * 5.7 GHz channels 145, 149, 153, 157, 161, 165
409 * (5725-5825MHz)
410 */
411#define EEPROM_REGULATORY_BAND_5 (2*0x98) /* 2 bytes */
412#define EEPROM_REGULATORY_BAND_5_CHANNELS (2*0x99) /* 12 bytes */
413
414/*
415 * 2.4 GHz HT40 channels 1 (5), 2 (6), 3 (7), 4 (8), 5 (9), 6 (10), 7 (11)
416 *
417 * The channel listed is the center of the lower 20 MHz half of the channel.
418 * The overall center frequency is actually 2 channels (10 MHz) above that,
419 * and the upper half of each HT40 channel is centered 4 channels (20 MHz) away
420 * from the lower half; e.g. the upper half of HT40 channel 1 is channel 5,
421 * and the overall HT40 channel width centers on channel 3.
422 *
423 * NOTE: The RXON command uses 20 MHz channel numbers to specify the
424 * control channel to which to tune. RXON also specifies whether the
425 * control channel is the upper or lower half of a HT40 channel.
426 *
427 * NOTE: 4965 does not support HT40 channels on 2.4 GHz.
428 */
429#define EEPROM_4965_REGULATORY_BAND_24_HT40_CHANNELS (2*0xA0) /* 14 bytes */
430
431/*
432 * 5.2 GHz HT40 channels 36 (40), 44 (48), 52 (56), 60 (64),
433 * 100 (104), 108 (112), 116 (120), 124 (128), 132 (136), 149 (153), 157 (161)
434 */
435#define EEPROM_4965_REGULATORY_BAND_52_HT40_CHANNELS (2*0xA8) /* 22 bytes */
436
437#define EEPROM_REGULATORY_BAND_NO_HT40 (0)
438
439struct il_eeprom_ops {
440 const u32 regulatory_bands[7];
441 int (*acquire_semaphore) (struct il_priv *il);
442 void (*release_semaphore) (struct il_priv *il);
443};
444
445
446int il_eeprom_init(struct il_priv *il);
447void il_eeprom_free(struct il_priv *il);
448const u8 *il_eeprom_query_addr(const struct il_priv *il,
449 size_t offset);
450u16 il_eeprom_query16(const struct il_priv *il, size_t offset);
451int il_init_channel_map(struct il_priv *il);
452void il_free_channel_map(struct il_priv *il);
453const struct il_channel_info *il_get_channel_info(
454 const struct il_priv *il,
455 enum ieee80211_band band, u16 channel);
456
457
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +0200458#define IL_NUM_SCAN_RATES (2)
459
460struct il4965_channel_tgd_info {
461 u8 type;
462 s8 max_power;
463};
464
465struct il4965_channel_tgh_info {
466 s64 last_radar_time;
467};
468
469#define IL4965_MAX_RATE (33)
470
471struct il3945_clip_group {
472 /* maximum power level to prevent clipping for each rate, derived by
473 * us from this band's saturation power in EEPROM */
474 const s8 clip_powers[IL_MAX_RATES];
475};
476
477/* current Tx power values to use, one for each rate for each channel.
478 * requested power is limited by:
479 * -- regulatory EEPROM limits for this channel
480 * -- hardware capabilities (clip-powers)
481 * -- spectrum management
482 * -- user preference (e.g. iwconfig)
483 * when requested power is set, base power idx must also be set. */
484struct il3945_channel_power_info {
485 struct il3945_tx_power tpc; /* actual radio and DSP gain settings */
486 s8 power_table_idx; /* actual (compenst'd) idx into gain table */
487 s8 base_power_idx; /* gain idx for power at factory temp. */
488 s8 requested_power; /* power (dBm) requested for this chnl/rate */
489};
490
491/* current scan Tx power values to use, one for each scan rate for each
492 * channel. */
493struct il3945_scan_power_info {
494 struct il3945_tx_power tpc; /* actual radio and DSP gain settings */
495 s8 power_table_idx; /* actual (compenst'd) idx into gain table */
496 s8 requested_power; /* scan pwr (dBm) requested for chnl/rate */
497};
498
499/*
500 * One for each channel, holds all channel setup data
501 * Some of the fields (e.g. eeprom and flags/max_power_avg) are redundant
502 * with one another!
503 */
504struct il_channel_info {
505 struct il4965_channel_tgd_info tgd;
506 struct il4965_channel_tgh_info tgh;
507 struct il_eeprom_channel eeprom; /* EEPROM regulatory limit */
508 struct il_eeprom_channel ht40_eeprom; /* EEPROM regulatory limit for
509 * HT40 channel */
510
511 u8 channel; /* channel number */
512 u8 flags; /* flags copied from EEPROM */
513 s8 max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */
514 s8 curr_txpow; /* (dBm) regulatory/spectrum/user (not h/w) limit */
515 s8 min_power; /* always 0 */
516 s8 scan_power; /* (dBm) regul. eeprom, direct scans, any rate */
517
518 u8 group_idx; /* 0-4, maps channel to group1/2/3/4/5 */
519 u8 band_idx; /* 0-4, maps channel to band1/2/3/4/5 */
520 enum ieee80211_band band;
521
522 /* HT40 channel info */
523 s8 ht40_max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */
524 u8 ht40_flags; /* flags copied from EEPROM */
525 u8 ht40_extension_channel; /* HT_IE_EXT_CHANNEL_* */
526
527 /* Radio/DSP gain settings for each "normal" data Tx rate.
528 * These include, in addition to RF and DSP gain, a few fields for
529 * remembering/modifying gain settings (idxes). */
530 struct il3945_channel_power_info power_info[IL4965_MAX_RATE];
531
532 /* Radio/DSP gain settings for each scan rate, for directed scans. */
533 struct il3945_scan_power_info scan_pwr_info[IL_NUM_SCAN_RATES];
534};
535
536#define IL_TX_FIFO_BK 0 /* shared */
537#define IL_TX_FIFO_BE 1
538#define IL_TX_FIFO_VI 2 /* shared */
539#define IL_TX_FIFO_VO 3
540#define IL_TX_FIFO_UNUSED -1
541
542/* Minimum number of queues. MAX_NUM is defined in hw specific files.
543 * Set the minimum to accommodate the 4 standard TX queues, 1 command
544 * queue, 2 (unused) HCCA queues, and 4 HT queues (one for each AC) */
545#define IL_MIN_NUM_QUEUES 10
546
547#define IL_DEFAULT_CMD_QUEUE_NUM 4
548
549#define IEEE80211_DATA_LEN 2304
550#define IEEE80211_4ADDR_LEN 30
551#define IEEE80211_HLEN (IEEE80211_4ADDR_LEN)
552#define IEEE80211_FRAME_LEN (IEEE80211_DATA_LEN + IEEE80211_HLEN)
553
554struct il_frame {
555 union {
556 struct ieee80211_hdr frame;
557 struct il_tx_beacon_cmd beacon;
558 u8 raw[IEEE80211_FRAME_LEN];
559 u8 cmd[360];
560 } u;
561 struct list_head list;
562};
563
564#define SEQ_TO_SN(seq) (((seq) & IEEE80211_SCTL_SEQ) >> 4)
565#define SN_TO_SEQ(ssn) (((ssn) << 4) & IEEE80211_SCTL_SEQ)
566#define MAX_SN ((IEEE80211_SCTL_SEQ) >> 4)
567
568enum {
569 CMD_SYNC = 0,
570 CMD_SIZE_NORMAL = 0,
571 CMD_NO_SKB = 0,
572 CMD_SIZE_HUGE = (1 << 0),
573 CMD_ASYNC = (1 << 1),
574 CMD_WANT_SKB = (1 << 2),
575 CMD_MAPPED = (1 << 3),
576};
577
578#define DEF_CMD_PAYLOAD_SIZE 320
579
580/**
581 * struct il_device_cmd
582 *
583 * For allocation of the command and tx queues, this establishes the overall
584 * size of the largest command we send to uCode, except for a scan command
585 * (which is relatively huge; space is allocated separately).
586 */
587struct il_device_cmd {
588 struct il_cmd_header hdr; /* uCode API */
589 union {
590 u32 flags;
591 u8 val8;
592 u16 val16;
593 u32 val32;
594 struct il_tx_cmd tx;
595 u8 payload[DEF_CMD_PAYLOAD_SIZE];
596 } __packed cmd;
597} __packed;
598
599#define TFD_MAX_PAYLOAD_SIZE (sizeof(struct il_device_cmd))
600
601
602struct il_host_cmd {
603 const void *data;
604 unsigned long reply_page;
605 void (*callback)(struct il_priv *il,
606 struct il_device_cmd *cmd,
607 struct il_rx_pkt *pkt);
608 u32 flags;
609 u16 len;
610 u8 id;
611};
612
613#define SUP_RATE_11A_MAX_NUM_CHANNELS 8
614#define SUP_RATE_11B_MAX_NUM_CHANNELS 4
615#define SUP_RATE_11G_MAX_NUM_CHANNELS 12
616
617/**
618 * struct il_rx_queue - Rx queue
619 * @bd: driver's pointer to buffer of receive buffer descriptors (rbd)
620 * @bd_dma: bus address of buffer of receive buffer descriptors (rbd)
621 * @read: Shared idx to newest available Rx buffer
622 * @write: Shared idx to oldest written Rx packet
623 * @free_count: Number of pre-allocated buffers in rx_free
624 * @rx_free: list of free SKBs for use
625 * @rx_used: List of Rx buffers with no SKB
626 * @need_update: flag to indicate we need to update read/write idx
627 * @rb_stts: driver's pointer to receive buffer status
628 * @rb_stts_dma: bus address of receive buffer status
629 *
630 * NOTE: rx_free and rx_used are used as a FIFO for il_rx_bufs
631 */
632struct il_rx_queue {
633 __le32 *bd;
634 dma_addr_t bd_dma;
635 struct il_rx_buf pool[RX_QUEUE_SIZE + RX_FREE_BUFFERS];
636 struct il_rx_buf *queue[RX_QUEUE_SIZE];
637 u32 read;
638 u32 write;
639 u32 free_count;
640 u32 write_actual;
641 struct list_head rx_free;
642 struct list_head rx_used;
643 int need_update;
644 struct il_rb_status *rb_stts;
645 dma_addr_t rb_stts_dma;
646 spinlock_t lock;
647};
648
649#define IL_SUPPORTED_RATES_IE_LEN 8
650
651#define MAX_TID_COUNT 9
652
653#define IL_INVALID_RATE 0xFF
654#define IL_INVALID_VALUE -1
655
656/**
657 * struct il_ht_agg -- aggregation status while waiting for block-ack
658 * @txq_id: Tx queue used for Tx attempt
659 * @frame_count: # frames attempted by Tx command
660 * @wait_for_ba: Expect block-ack before next Tx reply
661 * @start_idx: Index of 1st Transmit Frame Descriptor (TFD) in Tx win
662 * @bitmap0: Low order bitmap, one bit for each frame pending ACK in Tx win
663 * @bitmap1: High order, one bit for each frame pending ACK in Tx win
664 * @rate_n_flags: Rate at which Tx was attempted
665 *
666 * If C_TX indicates that aggregation was attempted, driver must wait
667 * for block ack (N_COMPRESSED_BA). This struct stores tx reply info
668 * until block ack arrives.
669 */
670struct il_ht_agg {
671 u16 txq_id;
672 u16 frame_count;
673 u16 wait_for_ba;
674 u16 start_idx;
675 u64 bitmap;
676 u32 rate_n_flags;
677#define IL_AGG_OFF 0
678#define IL_AGG_ON 1
679#define IL_EMPTYING_HW_QUEUE_ADDBA 2
680#define IL_EMPTYING_HW_QUEUE_DELBA 3
681 u8 state;
682};
683
684
685struct il_tid_data {
686 u16 seq_number; /* 4965 only */
687 u16 tfds_in_queue;
688 struct il_ht_agg agg;
689};
690
691struct il_hw_key {
692 u32 cipher;
693 int keylen;
694 u8 keyidx;
695 u8 key[32];
696};
697
698union il_ht_rate_supp {
699 u16 rates;
700 struct {
701 u8 siso_rate;
702 u8 mimo_rate;
703 };
704};
705
706#define CFG_HT_RX_AMPDU_FACTOR_8K (0x0)
707#define CFG_HT_RX_AMPDU_FACTOR_16K (0x1)
708#define CFG_HT_RX_AMPDU_FACTOR_32K (0x2)
709#define CFG_HT_RX_AMPDU_FACTOR_64K (0x3)
710#define CFG_HT_RX_AMPDU_FACTOR_DEF CFG_HT_RX_AMPDU_FACTOR_64K
711#define CFG_HT_RX_AMPDU_FACTOR_MAX CFG_HT_RX_AMPDU_FACTOR_64K
712#define CFG_HT_RX_AMPDU_FACTOR_MIN CFG_HT_RX_AMPDU_FACTOR_8K
713
714/*
715 * Maximal MPDU density for TX aggregation
716 * 4 - 2us density
717 * 5 - 4us density
718 * 6 - 8us density
719 * 7 - 16us density
720 */
721#define CFG_HT_MPDU_DENSITY_2USEC (0x4)
722#define CFG_HT_MPDU_DENSITY_4USEC (0x5)
723#define CFG_HT_MPDU_DENSITY_8USEC (0x6)
724#define CFG_HT_MPDU_DENSITY_16USEC (0x7)
725#define CFG_HT_MPDU_DENSITY_DEF CFG_HT_MPDU_DENSITY_4USEC
726#define CFG_HT_MPDU_DENSITY_MAX CFG_HT_MPDU_DENSITY_16USEC
727#define CFG_HT_MPDU_DENSITY_MIN (0x1)
728
729struct il_ht_config {
730 bool single_chain_sufficient;
731 enum ieee80211_smps_mode smps; /* current smps mode */
732};
733
734/* QoS structures */
735struct il_qos_info {
736 int qos_active;
737 struct il_qosparam_cmd def_qos_parm;
738};
739
740/*
741 * Structure should be accessed with sta_lock held. When station addition
742 * is in progress (IL_STA_UCODE_INPROGRESS) it is possible to access only
743 * the commands (il_addsta_cmd and il_link_quality_cmd) without
744 * sta_lock held.
745 */
746struct il_station_entry {
747 struct il_addsta_cmd sta;
748 struct il_tid_data tid[MAX_TID_COUNT];
749 u8 used, ctxid;
750 struct il_hw_key keyinfo;
751 struct il_link_quality_cmd *lq;
752};
753
754struct il_station_priv_common {
755 struct il_rxon_context *ctx;
756 u8 sta_id;
757};
758
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +0200759/**
760 * struct il_vif_priv - driver's ilate per-interface information
761 *
762 * When mac80211 allocates a virtual interface, it can allocate
763 * space for us to put data into.
764 */
765struct il_vif_priv {
766 struct il_rxon_context *ctx;
767 u8 ibss_bssid_sta_id;
768};
769
770/* one for each uCode image (inst/data, boot/init/runtime) */
771struct fw_desc {
772 void *v_addr; /* access by driver */
773 dma_addr_t p_addr; /* access by card's busmaster DMA */
774 u32 len; /* bytes */
775};
776
777/* uCode file layout */
778struct il_ucode_header {
779 __le32 ver; /* major/minor/API/serial */
780 struct {
781 __le32 inst_size; /* bytes of runtime code */
782 __le32 data_size; /* bytes of runtime data */
783 __le32 init_size; /* bytes of init code */
784 __le32 init_data_size; /* bytes of init data */
785 __le32 boot_size; /* bytes of bootstrap code */
786 u8 data[0]; /* in same order as sizes */
787 } v1;
788};
789
790struct il4965_ibss_seq {
791 u8 mac[ETH_ALEN];
792 u16 seq_num;
793 u16 frag_num;
794 unsigned long packet_time;
795 struct list_head list;
796};
797
798struct il_sensitivity_ranges {
799 u16 min_nrg_cck;
800 u16 max_nrg_cck;
801
802 u16 nrg_th_cck;
803 u16 nrg_th_ofdm;
804
805 u16 auto_corr_min_ofdm;
806 u16 auto_corr_min_ofdm_mrc;
807 u16 auto_corr_min_ofdm_x1;
808 u16 auto_corr_min_ofdm_mrc_x1;
809
810 u16 auto_corr_max_ofdm;
811 u16 auto_corr_max_ofdm_mrc;
812 u16 auto_corr_max_ofdm_x1;
813 u16 auto_corr_max_ofdm_mrc_x1;
814
815 u16 auto_corr_max_cck;
816 u16 auto_corr_max_cck_mrc;
817 u16 auto_corr_min_cck;
818 u16 auto_corr_min_cck_mrc;
819
820 u16 barker_corr_th_min;
821 u16 barker_corr_th_min_mrc;
822 u16 nrg_th_cca;
823};
824
825
826#define KELVIN_TO_CELSIUS(x) ((x)-273)
827#define CELSIUS_TO_KELVIN(x) ((x)+273)
828
829
830/**
831 * struct il_hw_params
832 * @max_txq_num: Max # Tx queues supported
833 * @dma_chnl_num: Number of Tx DMA/FIFO channels
834 * @scd_bc_tbls_size: size of scheduler byte count tables
835 * @tfd_size: TFD size
836 * @tx/rx_chains_num: Number of TX/RX chains
837 * @valid_tx/rx_ant: usable antennas
838 * @max_rxq_size: Max # Rx frames in Rx queue (must be power-of-2)
839 * @max_rxq_log: Log-base-2 of max_rxq_size
840 * @rx_page_order: Rx buffer page order
841 * @rx_wrt_ptr_reg: FH{39}_RSCSR_CHNL0_WPTR
842 * @max_stations:
843 * @ht40_channel: is 40MHz width possible in band 2.4
844 * BIT(IEEE80211_BAND_5GHZ) BIT(IEEE80211_BAND_5GHZ)
845 * @sw_crypto: 0 for hw, 1 for sw
846 * @max_xxx_size: for ucode uses
847 * @ct_kill_threshold: temperature threshold
848 * @beacon_time_tsf_bits: number of valid tsf bits for beacon time
849 * @struct il_sensitivity_ranges: range of sensitivity values
850 */
851struct il_hw_params {
852 u8 max_txq_num;
853 u8 dma_chnl_num;
854 u16 scd_bc_tbls_size;
855 u32 tfd_size;
856 u8 tx_chains_num;
857 u8 rx_chains_num;
858 u8 valid_tx_ant;
859 u8 valid_rx_ant;
860 u16 max_rxq_size;
861 u16 max_rxq_log;
862 u32 rx_page_order;
863 u32 rx_wrt_ptr_reg;
864 u8 max_stations;
865 u8 ht40_channel;
866 u8 max_beacon_itrvl; /* in 1024 ms */
867 u32 max_inst_size;
868 u32 max_data_size;
869 u32 max_bsm_size;
870 u32 ct_kill_threshold; /* value in hw-dependent units */
871 u16 beacon_time_tsf_bits;
872 const struct il_sensitivity_ranges *sens;
873};
874
875
876/******************************************************************************
877 *
878 * Functions implemented in core module which are forward declared here
879 * for use by iwl-[4-5].c
880 *
881 * NOTE: The implementation of these functions are not hardware specific
882 * which is why they are in the core module files.
883 *
884 * Naming convention --
885 * il_ <-- Is part of iwlwifi
886 * iwlXXXX_ <-- Hardware specific (implemented in iwl-XXXX.c for XXXX)
887 * il4965_bg_ <-- Called from work queue context
888 * il4965_mac_ <-- mac80211 callback
889 *
890 ****************************************************************************/
891extern void il4965_update_chain_flags(struct il_priv *il);
892extern const u8 il_bcast_addr[ETH_ALEN];
893extern int il_queue_space(const struct il_queue *q);
894static inline int il_queue_used(const struct il_queue *q, int i)
895{
896 return q->write_ptr >= q->read_ptr ?
897 (i >= q->read_ptr && i < q->write_ptr) :
898 !(i < q->read_ptr && i >= q->write_ptr);
899}
900
901
902static inline u8 il_get_cmd_idx(struct il_queue *q, u32 idx,
903 int is_huge)
904{
905 /*
906 * This is for init calibration result and scan command which
907 * required buffer > TFD_MAX_PAYLOAD_SIZE,
908 * the big buffer at end of command array
909 */
910 if (is_huge)
911 return q->n_win; /* must be power of 2 */
912
913 /* Otherwise, use normal size buffers */
914 return idx & (q->n_win - 1);
915}
916
917
918struct il_dma_ptr {
919 dma_addr_t dma;
920 void *addr;
921 size_t size;
922};
923
924#define IL_OPERATION_MODE_AUTO 0
925#define IL_OPERATION_MODE_HT_ONLY 1
926#define IL_OPERATION_MODE_MIXED 2
927#define IL_OPERATION_MODE_20MHZ 3
928
929#define IL_TX_CRC_SIZE 4
930#define IL_TX_DELIMITER_SIZE 4
931
932#define TX_POWER_IL_ILLEGAL_VOLTAGE -10000
933
934/* Sensitivity and chain noise calibration */
935#define INITIALIZATION_VALUE 0xFFFF
936#define IL4965_CAL_NUM_BEACONS 20
937#define IL_CAL_NUM_BEACONS 16
938#define MAXIMUM_ALLOWED_PATHLOSS 15
939
940#define CHAIN_NOISE_MAX_DELTA_GAIN_CODE 3
941
942#define MAX_FA_OFDM 50
943#define MIN_FA_OFDM 5
944#define MAX_FA_CCK 50
945#define MIN_FA_CCK 5
946
947#define AUTO_CORR_STEP_OFDM 1
948
949#define AUTO_CORR_STEP_CCK 3
950#define AUTO_CORR_MAX_TH_CCK 160
951
952#define NRG_DIFF 2
953#define NRG_STEP_CCK 2
954#define NRG_MARGIN 8
955#define MAX_NUMBER_CCK_NO_FA 100
956
957#define AUTO_CORR_CCK_MIN_VAL_DEF (125)
958
959#define CHAIN_A 0
960#define CHAIN_B 1
961#define CHAIN_C 2
962#define CHAIN_NOISE_DELTA_GAIN_INIT_VAL 4
963#define ALL_BAND_FILTER 0xFF00
964#define IN_BAND_FILTER 0xFF
965#define MIN_AVERAGE_NOISE_MAX_VALUE 0xFFFFFFFF
966
967#define NRG_NUM_PREV_STAT_L 20
968#define NUM_RX_CHAINS 3
969
970enum il4965_false_alarm_state {
971 IL_FA_TOO_MANY = 0,
972 IL_FA_TOO_FEW = 1,
973 IL_FA_GOOD_RANGE = 2,
974};
975
976enum il4965_chain_noise_state {
977 IL_CHAIN_NOISE_ALIVE = 0, /* must be 0 */
978 IL_CHAIN_NOISE_ACCUMULATE,
979 IL_CHAIN_NOISE_CALIBRATED,
980 IL_CHAIN_NOISE_DONE,
981};
982
983enum il4965_calib_enabled_state {
984 IL_CALIB_DISABLED = 0, /* must be 0 */
985 IL_CALIB_ENABLED = 1,
986};
987
988/*
989 * enum il_calib
990 * defines the order in which results of initial calibrations
991 * should be sent to the runtime uCode
992 */
993enum il_calib {
994 IL_CALIB_MAX,
995};
996
997/* Opaque calibration results */
998struct il_calib_result {
999 void *buf;
1000 size_t buf_len;
1001};
1002
1003enum ucode_type {
1004 UCODE_NONE = 0,
1005 UCODE_INIT,
1006 UCODE_RT
1007};
1008
1009/* Sensitivity calib data */
1010struct il_sensitivity_data {
1011 u32 auto_corr_ofdm;
1012 u32 auto_corr_ofdm_mrc;
1013 u32 auto_corr_ofdm_x1;
1014 u32 auto_corr_ofdm_mrc_x1;
1015 u32 auto_corr_cck;
1016 u32 auto_corr_cck_mrc;
1017
1018 u32 last_bad_plcp_cnt_ofdm;
1019 u32 last_fa_cnt_ofdm;
1020 u32 last_bad_plcp_cnt_cck;
1021 u32 last_fa_cnt_cck;
1022
1023 u32 nrg_curr_state;
1024 u32 nrg_prev_state;
1025 u32 nrg_value[10];
1026 u8 nrg_silence_rssi[NRG_NUM_PREV_STAT_L];
1027 u32 nrg_silence_ref;
1028 u32 nrg_energy_idx;
1029 u32 nrg_silence_idx;
1030 u32 nrg_th_cck;
1031 s32 nrg_auto_corr_silence_diff;
1032 u32 num_in_cck_no_fa;
1033 u32 nrg_th_ofdm;
1034
1035 u16 barker_corr_th_min;
1036 u16 barker_corr_th_min_mrc;
1037 u16 nrg_th_cca;
1038};
1039
1040/* Chain noise (differential Rx gain) calib data */
1041struct il_chain_noise_data {
1042 u32 active_chains;
1043 u32 chain_noise_a;
1044 u32 chain_noise_b;
1045 u32 chain_noise_c;
1046 u32 chain_signal_a;
1047 u32 chain_signal_b;
1048 u32 chain_signal_c;
1049 u16 beacon_count;
1050 u8 disconn_array[NUM_RX_CHAINS];
1051 u8 delta_gain_code[NUM_RX_CHAINS];
1052 u8 radio_write;
1053 u8 state;
1054};
1055
1056#define EEPROM_SEM_TIMEOUT 10 /* milliseconds */
1057#define EEPROM_SEM_RETRY_LIMIT 1000 /* number of attempts (not time) */
1058
1059#define IL_TRAFFIC_ENTRIES (256)
1060#define IL_TRAFFIC_ENTRY_SIZE (64)
1061
1062enum {
1063 MEASUREMENT_READY = (1 << 0),
1064 MEASUREMENT_ACTIVE = (1 << 1),
1065};
1066
1067/* interrupt stats */
1068struct isr_stats {
1069 u32 hw;
1070 u32 sw;
1071 u32 err_code;
1072 u32 sch;
1073 u32 alive;
1074 u32 rfkill;
1075 u32 ctkill;
1076 u32 wakeup;
1077 u32 rx;
1078 u32 handlers[IL_CN_MAX];
1079 u32 tx;
1080 u32 unhandled;
1081};
1082
1083/* management stats */
1084enum il_mgmt_stats {
1085 MANAGEMENT_ASSOC_REQ = 0,
1086 MANAGEMENT_ASSOC_RESP,
1087 MANAGEMENT_REASSOC_REQ,
1088 MANAGEMENT_REASSOC_RESP,
1089 MANAGEMENT_PROBE_REQ,
1090 MANAGEMENT_PROBE_RESP,
1091 MANAGEMENT_BEACON,
1092 MANAGEMENT_ATIM,
1093 MANAGEMENT_DISASSOC,
1094 MANAGEMENT_AUTH,
1095 MANAGEMENT_DEAUTH,
1096 MANAGEMENT_ACTION,
1097 MANAGEMENT_MAX,
1098};
1099/* control stats */
1100enum il_ctrl_stats {
1101 CONTROL_BACK_REQ = 0,
1102 CONTROL_BACK,
1103 CONTROL_PSPOLL,
1104 CONTROL_RTS,
1105 CONTROL_CTS,
1106 CONTROL_ACK,
1107 CONTROL_CFEND,
1108 CONTROL_CFENDACK,
1109 CONTROL_MAX,
1110};
1111
1112struct traffic_stats {
1113#ifdef CONFIG_IWLEGACY_DEBUGFS
1114 u32 mgmt[MANAGEMENT_MAX];
1115 u32 ctrl[CONTROL_MAX];
1116 u32 data_cnt;
1117 u64 data_bytes;
1118#endif
1119};
1120
1121/*
1122 * host interrupt timeout value
1123 * used with setting interrupt coalescing timer
1124 * the CSR_INT_COALESCING is an 8 bit register in 32-usec unit
1125 *
1126 * default interrupt coalescing timer is 64 x 32 = 2048 usecs
1127 * default interrupt coalescing calibration timer is 16 x 32 = 512 usecs
1128 */
1129#define IL_HOST_INT_TIMEOUT_MAX (0xFF)
1130#define IL_HOST_INT_TIMEOUT_DEF (0x40)
1131#define IL_HOST_INT_TIMEOUT_MIN (0x0)
1132#define IL_HOST_INT_CALIB_TIMEOUT_MAX (0xFF)
1133#define IL_HOST_INT_CALIB_TIMEOUT_DEF (0x10)
1134#define IL_HOST_INT_CALIB_TIMEOUT_MIN (0x0)
1135
1136#define IL_DELAY_NEXT_FORCE_FW_RELOAD (HZ*5)
1137
1138/* TX queue watchdog timeouts in mSecs */
1139#define IL_DEF_WD_TIMEOUT (2000)
1140#define IL_LONG_WD_TIMEOUT (10000)
1141#define IL_MAX_WD_TIMEOUT (120000)
1142
1143struct il_force_reset {
1144 int reset_request_count;
1145 int reset_success_count;
1146 int reset_reject_count;
1147 unsigned long reset_duration;
1148 unsigned long last_force_reset_jiffies;
1149};
1150
1151/* extend beacon time format bit shifting */
1152/*
1153 * for _3945 devices
1154 * bits 31:24 - extended
1155 * bits 23:0 - interval
1156 */
1157#define IL3945_EXT_BEACON_TIME_POS 24
1158/*
1159 * for _4965 devices
1160 * bits 31:22 - extended
1161 * bits 21:0 - interval
1162 */
1163#define IL4965_EXT_BEACON_TIME_POS 22
1164
1165struct il_rxon_context {
1166 struct ieee80211_vif *vif;
1167
1168 const u8 *ac_to_fifo;
1169 const u8 *ac_to_queue;
1170 u8 mcast_queue;
1171
1172 /*
1173 * We could use the vif to indicate active, but we
1174 * also need it to be active during disabling when
1175 * we already removed the vif for type setting.
1176 */
1177 bool always_active, is_active;
1178
1179 bool ht_need_multiple_chains;
1180
1181 int ctxid;
1182
1183 u32 interface_modes, exclusive_interface_modes;
1184 u8 unused_devtype, ap_devtype, ibss_devtype, station_devtype;
1185
1186 /*
1187 * We declare this const so it can only be
1188 * changed via explicit cast within the
1189 * routines that actually update the physical
1190 * hardware.
1191 */
1192 const struct il_rxon_cmd active;
1193 struct il_rxon_cmd staging;
1194
1195 struct il_rxon_time_cmd timing;
1196
1197 struct il_qos_info qos_data;
1198
1199 u8 bcast_sta_id, ap_sta_id;
1200
1201 u8 rxon_cmd, rxon_assoc_cmd, rxon_timing_cmd;
1202 u8 qos_cmd;
1203 u8 wep_key_cmd;
1204
1205 struct il_wep_key wep_keys[WEP_KEYS_MAX];
1206 u8 key_mapping_keys;
1207
1208 __le32 station_flags;
1209
1210 struct {
1211 bool non_gf_sta_present;
1212 u8 protection;
1213 bool enabled, is_40mhz;
1214 u8 extension_chan_offset;
1215 } ht;
1216};
1217
Stanislaw Gruszka99412002011-08-31 13:53:04 +02001218struct il_power_mgr {
1219 struct il_powertable_cmd sleep_cmd;
1220 struct il_powertable_cmd sleep_cmd_next;
1221 int debug_sleep_level_override;
1222 bool pci_pm;
1223};
1224
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +02001225struct il_priv {
1226
1227 /* ieee device used by generic ieee processing code */
1228 struct ieee80211_hw *hw;
1229 struct ieee80211_channel *ieee_channels;
1230 struct ieee80211_rate *ieee_rates;
1231 struct il_cfg *cfg;
1232
1233 /* temporary frame storage list */
1234 struct list_head free_frames;
1235 int frames_count;
1236
1237 enum ieee80211_band band;
1238 int alloc_rxb_page;
1239
1240 void (*handlers[IL_CN_MAX])(struct il_priv *il,
1241 struct il_rx_buf *rxb);
1242
1243 struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
1244
1245 /* spectrum measurement report caching */
1246 struct il_spectrum_notification measure_report;
1247 u8 measurement_status;
1248
1249 /* ucode beacon time */
1250 u32 ucode_beacon_time;
1251 int missed_beacon_threshold;
1252
1253 /* track IBSS manager (last beacon) status */
1254 u32 ibss_manager;
1255
1256 /* force reset */
1257 struct il_force_reset force_reset;
1258
1259 /* we allocate array of il_channel_info for NIC's valid channels.
1260 * Access via channel # using indirect idx array */
1261 struct il_channel_info *channel_info; /* channel info array */
1262 u8 channel_count; /* # of channels */
1263
1264 /* thermal calibration */
1265 s32 temperature; /* degrees Kelvin */
1266 s32 last_temperature;
1267
1268 /* init calibration results */
1269 struct il_calib_result calib_results[IL_CALIB_MAX];
1270
1271 /* Scan related variables */
1272 unsigned long scan_start;
1273 unsigned long scan_start_tsf;
1274 void *scan_cmd;
1275 enum ieee80211_band scan_band;
1276 struct cfg80211_scan_request *scan_request;
1277 struct ieee80211_vif *scan_vif;
1278 u8 scan_tx_ant[IEEE80211_NUM_BANDS];
1279 u8 mgmt_tx_ant;
1280
1281 /* spinlock */
1282 spinlock_t lock; /* protect general shared data */
1283 spinlock_t hcmd_lock; /* protect hcmd */
1284 spinlock_t reg_lock; /* protect hw register access */
1285 struct mutex mutex;
1286
1287 /* basic pci-network driver stuff */
1288 struct pci_dev *pci_dev;
1289
1290 /* pci hardware address support */
1291 void __iomem *hw_base;
1292 u32 hw_rev;
1293 u32 hw_wa_rev;
1294 u8 rev_id;
1295
1296 /* command queue number */
1297 u8 cmd_queue;
1298
1299 /* max number of station keys */
1300 u8 sta_key_max_num;
1301
1302 /* EEPROM MAC addresses */
1303 struct mac_address addresses[1];
1304
1305 /* uCode images, save to reload in case of failure */
1306 int fw_idx; /* firmware we're trying to load */
1307 u32 ucode_ver; /* version of ucode, copy of
1308 il_ucode.ver */
1309 struct fw_desc ucode_code; /* runtime inst */
1310 struct fw_desc ucode_data; /* runtime data original */
1311 struct fw_desc ucode_data_backup; /* runtime data save/restore */
1312 struct fw_desc ucode_init; /* initialization inst */
1313 struct fw_desc ucode_init_data; /* initialization data */
1314 struct fw_desc ucode_boot; /* bootstrap inst */
1315 enum ucode_type ucode_type;
1316 u8 ucode_write_complete; /* the image write is complete */
1317 char firmware_name[25];
1318
1319 struct il_rxon_context ctx;
1320
1321 __le16 switch_channel;
1322
1323 /* 1st responses from initialize and runtime uCode images.
1324 * _4965's initialize alive response contains some calibration data. */
1325 struct il_init_alive_resp card_alive_init;
1326 struct il_alive_resp card_alive;
1327
1328 u16 active_rate;
1329
1330 u8 start_calib;
1331 struct il_sensitivity_data sensitivity_data;
1332 struct il_chain_noise_data chain_noise_data;
1333 __le16 sensitivity_tbl[HD_TBL_SIZE];
1334
1335 struct il_ht_config current_ht_config;
1336
1337 /* Rate scaling data */
1338 u8 retry_rate;
1339
1340 wait_queue_head_t wait_command_queue;
1341
1342 int activity_timer_active;
1343
1344 /* Rx and Tx DMA processing queues */
1345 struct il_rx_queue rxq;
1346 struct il_tx_queue *txq;
1347 unsigned long txq_ctx_active_msk;
1348 struct il_dma_ptr kw; /* keep warm address */
1349 struct il_dma_ptr scd_bc_tbls;
1350
1351 u32 scd_base_addr; /* scheduler sram base address */
1352
1353 unsigned long status;
1354
1355 /* counts mgmt, ctl, and data packets */
1356 struct traffic_stats tx_stats;
1357 struct traffic_stats rx_stats;
1358
1359 /* counts interrupts */
1360 struct isr_stats isr_stats;
1361
1362 struct il_power_mgr power_data;
1363
1364 /* context information */
1365 u8 bssid[ETH_ALEN]; /* used only on 3945 but filled by core */
1366
1367 /* station table variables */
1368
1369 /* Note: if lock and sta_lock are needed, lock must be acquired first */
1370 spinlock_t sta_lock;
1371 int num_stations;
1372 struct il_station_entry stations[IL_STATION_COUNT];
1373 unsigned long ucode_key_table;
1374
1375 /* queue refcounts */
1376#define IL_MAX_HW_QUEUES 32
1377 unsigned long queue_stopped[BITS_TO_LONGS(IL_MAX_HW_QUEUES)];
1378 /* for each AC */
1379 atomic_t queue_stop_count[4];
1380
1381 /* Indication if ieee80211_ops->open has been called */
1382 u8 is_open;
1383
1384 u8 mac80211_registered;
1385
1386 /* eeprom -- this is in the card's little endian byte order */
1387 u8 *eeprom;
1388 struct il_eeprom_calib_info *calib_info;
1389
1390 enum nl80211_iftype iw_mode;
1391
1392 /* Last Rx'd beacon timestamp */
1393 u64 timestamp;
1394
1395 union {
1396#if defined(CONFIG_IWL3945) || defined(CONFIG_IWL3945_MODULE)
1397 struct {
1398 void *shared_virt;
1399 dma_addr_t shared_phys;
1400
1401 struct delayed_work thermal_periodic;
1402 struct delayed_work rfkill_poll;
1403
1404 struct il3945_notif_stats stats;
1405#ifdef CONFIG_IWLEGACY_DEBUGFS
1406 struct il3945_notif_stats accum_stats;
1407 struct il3945_notif_stats delta_stats;
1408 struct il3945_notif_stats max_delta;
1409#endif
1410
1411 u32 sta_supp_rates;
1412 int last_rx_rssi; /* From Rx packet stats */
1413
1414 /* Rx'd packet timing information */
1415 u32 last_beacon_time;
1416 u64 last_tsf;
1417
1418 /*
1419 * each calibration channel group in the
1420 * EEPROM has a derived clip setting for
1421 * each rate.
1422 */
1423 const struct il3945_clip_group clip_groups[5];
1424
1425 } _3945;
1426#endif
1427#if defined(CONFIG_IWL4965) || defined(CONFIG_IWL4965_MODULE)
1428 struct {
1429 struct il_rx_phy_res last_phy_res;
1430 bool last_phy_res_valid;
1431
1432 struct completion firmware_loading_complete;
1433
1434 /*
1435 * chain noise reset and gain commands are the
1436 * two extra calibration commands follows the standard
1437 * phy calibration commands
1438 */
1439 u8 phy_calib_chain_noise_reset_cmd;
1440 u8 phy_calib_chain_noise_gain_cmd;
1441
1442 struct il_notif_stats stats;
1443#ifdef CONFIG_IWLEGACY_DEBUGFS
1444 struct il_notif_stats accum_stats;
1445 struct il_notif_stats delta_stats;
1446 struct il_notif_stats max_delta;
1447#endif
1448
1449 } _4965;
1450#endif
1451 };
1452
1453 struct il_hw_params hw_params;
1454
1455 u32 inta_mask;
1456
1457 struct workqueue_struct *workqueue;
1458
1459 struct work_struct restart;
1460 struct work_struct scan_completed;
1461 struct work_struct rx_replenish;
1462 struct work_struct abort_scan;
1463
1464 struct il_rxon_context *beacon_ctx;
1465 struct sk_buff *beacon_skb;
1466
1467 struct work_struct tx_flush;
1468
1469 struct tasklet_struct irq_tasklet;
1470
1471 struct delayed_work init_alive_start;
1472 struct delayed_work alive_start;
1473 struct delayed_work scan_check;
1474
1475 /* TX Power */
1476 s8 tx_power_user_lmt;
1477 s8 tx_power_device_lmt;
1478 s8 tx_power_next;
1479
1480
1481#ifdef CONFIG_IWLEGACY_DEBUG
1482 /* debugging info */
1483 u32 debug_level; /* per device debugging will override global
1484 il_debug_level if set */
1485#endif /* CONFIG_IWLEGACY_DEBUG */
1486#ifdef CONFIG_IWLEGACY_DEBUGFS
1487 /* debugfs */
1488 u16 tx_traffic_idx;
1489 u16 rx_traffic_idx;
1490 u8 *tx_traffic;
1491 u8 *rx_traffic;
1492 struct dentry *debugfs_dir;
1493 u32 dbgfs_sram_offset, dbgfs_sram_len;
1494 bool disable_ht40;
1495#endif /* CONFIG_IWLEGACY_DEBUGFS */
1496
1497 struct work_struct txpower_work;
1498 u32 disable_sens_cal;
1499 u32 disable_chain_noise_cal;
1500 u32 disable_tx_power_cal;
1501 struct work_struct run_time_calib_work;
1502 struct timer_list stats_periodic;
1503 struct timer_list watchdog;
1504 bool hw_ready;
1505
1506 struct led_classdev led;
1507 unsigned long blink_on, blink_off;
1508 bool led_registered;
1509}; /*il_priv */
1510
1511static inline void il_txq_ctx_activate(struct il_priv *il, int txq_id)
1512{
1513 set_bit(txq_id, &il->txq_ctx_active_msk);
1514}
1515
1516static inline void il_txq_ctx_deactivate(struct il_priv *il, int txq_id)
1517{
1518 clear_bit(txq_id, &il->txq_ctx_active_msk);
1519}
1520
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +02001521static inline struct ieee80211_hdr *
1522il_tx_queue_get_hdr(struct il_priv *il,
1523 int txq_id, int idx)
1524{
1525 if (il->txq[txq_id].txb[idx].skb)
1526 return (struct ieee80211_hdr *)il->txq[txq_id].
1527 txb[idx].skb->data;
1528 return NULL;
1529}
1530
1531static inline struct il_rxon_context *
1532il_rxon_ctx_from_vif(struct ieee80211_vif *vif)
1533{
1534 struct il_vif_priv *vif_priv = (void *)vif->drv_priv;
1535
1536 return vif_priv->ctx;
1537}
1538
1539#define for_each_context(il, _ctx) \
1540 for (_ctx = &il->ctx; _ctx == &il->ctx; _ctx++)
1541
1542static inline int il_is_associated(struct il_priv *il)
1543{
1544 return (il->ctx.active.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0;
1545}
1546
1547static inline int il_is_any_associated(struct il_priv *il)
1548{
1549 return il_is_associated(il);
1550}
1551
1552static inline int il_is_associated_ctx(struct il_rxon_context *ctx)
1553{
1554 return (ctx->active.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0;
1555}
1556
1557static inline int il_is_channel_valid(const struct il_channel_info *ch_info)
1558{
1559 if (ch_info == NULL)
1560 return 0;
1561 return (ch_info->flags & EEPROM_CHANNEL_VALID) ? 1 : 0;
1562}
1563
1564static inline int il_is_channel_radar(const struct il_channel_info *ch_info)
1565{
1566 return (ch_info->flags & EEPROM_CHANNEL_RADAR) ? 1 : 0;
1567}
1568
1569static inline u8 il_is_channel_a_band(const struct il_channel_info *ch_info)
1570{
1571 return ch_info->band == IEEE80211_BAND_5GHZ;
1572}
1573
1574static inline int
1575il_is_channel_passive(const struct il_channel_info *ch)
1576{
1577 return (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) ? 1 : 0;
1578}
1579
1580static inline int
1581il_is_channel_ibss(const struct il_channel_info *ch)
1582{
1583 return (ch->flags & EEPROM_CHANNEL_IBSS) ? 1 : 0;
1584}
1585
Stanislaw Gruszka47ef6942011-08-31 14:04:45 +02001586
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +02001587static inline void
1588__il_free_pages(struct il_priv *il, struct page *page)
1589{
1590 __free_pages(page, il->hw_params.rx_page_order);
1591 il->alloc_rxb_page--;
1592}
1593
1594static inline void il_free_pages(struct il_priv *il, unsigned long page)
1595{
1596 free_pages(page, il->hw_params.rx_page_order);
1597 il->alloc_rxb_page--;
1598}
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001599
1600#define IWLWIFI_VERSION "in-tree:"
1601#define DRV_COPYRIGHT "Copyright(c) 2003-2011 Intel Corporation"
1602#define DRV_AUTHOR "<ilw@linux.intel.com>"
1603
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001604#define IL_PCI_DEVICE(dev, subdev, cfg) \
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001605 .vendor = PCI_VENDOR_ID_INTEL, .device = (dev), \
1606 .subvendor = PCI_ANY_ID, .subdevice = (subdev), \
1607 .driver_data = (kernel_ulong_t)&(cfg)
1608
1609#define TIME_UNIT 1024
1610
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001611#define IL_SKU_G 0x1
1612#define IL_SKU_A 0x2
1613#define IL_SKU_N 0x8
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001614
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001615#define IL_CMD(x) case x: return #x
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001616
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +02001617/* Size of one Rx buffer in host DRAM */
1618#define IL_RX_BUF_SIZE_3K (3 * 1000) /* 3945 only */
1619#define IL_RX_BUF_SIZE_4K (4 * 1024)
1620#define IL_RX_BUF_SIZE_8K (8 * 1024)
1621
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001622struct il_hcmd_ops {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001623 int (*rxon_assoc)(struct il_priv *il, struct il_rxon_context *ctx);
1624 int (*commit_rxon)(struct il_priv *il, struct il_rxon_context *ctx);
1625 void (*set_rxon_chain)(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001626 struct il_rxon_context *ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001627};
1628
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001629struct il_hcmd_utils_ops {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001630 u16 (*get_hcmd_size)(u8 cmd_id, u16 len);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001631 u16 (*build_addsta_hcmd)(const struct il_addsta_cmd *cmd,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001632 u8 *data);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001633 int (*request_scan)(struct il_priv *il, struct ieee80211_vif *vif);
1634 void (*post_scan)(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001635};
1636
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001637struct il_apm_ops {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001638 int (*init)(struct il_priv *il);
1639 void (*config)(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001640};
1641
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001642struct il_debugfs_ops {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001643 ssize_t (*rx_stats_read)(struct file *file, char __user *user_buf,
1644 size_t count, loff_t *ppos);
1645 ssize_t (*tx_stats_read)(struct file *file, char __user *user_buf,
1646 size_t count, loff_t *ppos);
1647 ssize_t (*general_stats_read)(struct file *file, char __user *user_buf,
1648 size_t count, loff_t *ppos);
1649};
1650
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001651struct il_temp_ops {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001652 void (*temperature)(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001653};
1654
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001655struct il_lib_ops {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001656 /* set hw dependent parameters */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001657 int (*set_hw_params)(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001658 /* Handling TX */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001659 void (*txq_update_byte_cnt_tbl)(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001660 struct il_tx_queue *txq,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001661 u16 byte_cnt);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001662 int (*txq_attach_buf_to_tfd)(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001663 struct il_tx_queue *txq,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001664 dma_addr_t addr,
1665 u16 len, u8 reset, u8 pad);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001666 void (*txq_free_tfd)(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001667 struct il_tx_queue *txq);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001668 int (*txq_init)(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001669 struct il_tx_queue *txq);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001670 /* setup Rx handler */
Stanislaw Gruszkad0c72342011-08-30 15:39:42 +02001671 void (*handler_setup)(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001672 /* alive notification after init uCode load */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001673 void (*init_alive_start)(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001674 /* check validity of rtc data address */
1675 int (*is_valid_rtc_data_addr)(u32 addr);
1676 /* 1st ucode load */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001677 int (*load_ucode)(struct il_priv *il);
Stanislaw Gruszka1ba2f122011-06-08 15:28:27 +02001678
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001679 void (*dump_nic_error_log)(struct il_priv *il);
1680 int (*dump_fh)(struct il_priv *il, char **buf, bool display);
1681 int (*set_channel_switch)(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001682 struct ieee80211_channel_switch *ch_switch);
1683 /* power management */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001684 struct il_apm_ops apm_ops;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001685
1686 /* power */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001687 int (*send_tx_power) (struct il_priv *il);
1688 void (*update_chain_flags)(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001689
Stanislaw Gruszka47ef6942011-08-31 14:04:45 +02001690 /* eeprom operations */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001691 struct il_eeprom_ops eeprom_ops;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001692
1693 /* temperature */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001694 struct il_temp_ops temp_ops;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001695
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001696 struct il_debugfs_ops debugfs_ops;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001697
1698};
1699
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001700struct il_led_ops {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001701 int (*cmd)(struct il_priv *il, struct il_led_cmd *led_cmd);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001702};
1703
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001704struct il_legacy_ops {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001705 void (*post_associate)(struct il_priv *il);
1706 void (*config_ap)(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001707 /* station management */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001708 int (*update_bcast_stations)(struct il_priv *il);
1709 int (*manage_ibss_station)(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001710 struct ieee80211_vif *vif, bool add);
1711};
1712
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001713struct il_ops {
1714 const struct il_lib_ops *lib;
1715 const struct il_hcmd_ops *hcmd;
1716 const struct il_hcmd_utils_ops *utils;
1717 const struct il_led_ops *led;
1718 const struct il_nic_ops *nic;
1719 const struct il_legacy_ops *legacy;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001720 const struct ieee80211_ops *ieee80211_ops;
1721};
1722
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001723struct il_mod_params {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001724 int sw_crypto; /* def: 0 = using hardware encryption */
1725 int disable_hw_scan; /* def: 0 = use h/w scan */
1726 int num_of_queues; /* def: HW dependent */
1727 int disable_11n; /* def: 0 = 11n capabilities enabled */
1728 int amsdu_size_8K; /* def: 1 = enable 8K amsdu size */
1729 int antenna; /* def: 0 = both antennas (use diversity) */
1730 int restart_fw; /* def: 1 = restart firmware */
1731};
1732
1733/*
1734 * @led_compensation: compensate on the led on/off time per HW according
1735 * to the deviation to achieve the desired led frequency.
Stanislaw Gruszka47ef6942011-08-31 14:04:45 +02001736 * The detail algorithm is described in common.c
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001737 * @chain_noise_num_beacons: number of beacons used to compute chain noise
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001738 * @wd_timeout: TX queues watchdog timeout
1739 * @temperature_kelvin: temperature report by uCode in kelvin
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001740 * @ucode_tracing: support ucode continuous tracing
1741 * @sensitivity_calib_by_driver: driver has the capability to perform
1742 * sensitivity calibration operation
1743 * @chain_noise_calib_by_driver: driver has the capability to perform
1744 * chain noise calibration operation
1745 */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001746struct il_base_params {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001747 int eeprom_size;
1748 int num_of_queues; /* def: HW dependent */
1749 int num_of_ampdu_queues;/* def: HW dependent */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001750 /* for il_apm_init() */
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001751 u32 pll_cfg_val;
1752 bool set_l0s;
1753 bool use_bsm;
1754
1755 u16 led_compensation;
1756 int chain_noise_num_beacons;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001757 unsigned int wd_timeout;
1758 bool temperature_kelvin;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001759 const bool ucode_tracing;
1760 const bool sensitivity_calib_by_driver;
1761 const bool chain_noise_calib_by_driver;
1762};
1763
Stanislaw Gruszka47ef6942011-08-31 14:04:45 +02001764#define IL_LED_SOLID 11
1765#define IL_DEF_LED_INTRVL cpu_to_le32(1000)
1766
1767#define IL_LED_ACTIVITY (0<<1)
1768#define IL_LED_LINK (1<<1)
1769
1770/*
1771 * LED mode
1772 * IL_LED_DEFAULT: use device default
1773 * IL_LED_RF_STATE: turn LED on/off based on RF state
1774 * LED ON = RF ON
1775 * LED OFF = RF OFF
1776 * IL_LED_BLINK: adjust led blink rate based on blink table
1777 */
1778enum il_led_mode {
1779 IL_LED_DEFAULT,
1780 IL_LED_RF_STATE,
1781 IL_LED_BLINK,
1782};
1783
1784void il_leds_init(struct il_priv *il);
1785void il_leds_exit(struct il_priv *il);
1786
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001787/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001788 * struct il_cfg
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001789 * @fw_name_pre: Firmware filename prefix. The api version and extension
1790 * (.ucode) will be added to filename before loading from disk. The
1791 * filename is constructed as fw_name_pre<api>.ucode.
1792 * @ucode_api_max: Highest version of uCode API supported by driver.
1793 * @ucode_api_min: Lowest version of uCode API supported by driver.
1794 * @scan_antennas: available antenna for scan operation
1795 * @led_mode: 0=blinking, 1=On(RF On)/Off(RF Off)
1796 *
1797 * We enable the driver to be backward compatible wrt API version. The
1798 * driver specifies which APIs it supports (with @ucode_api_max being the
1799 * highest and @ucode_api_min the lowest). Firmware will only be loaded if
1800 * it has a supported API version. The firmware's API version will be
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001801 * stored in @il_priv, enabling the driver to make runtime changes based
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001802 * on firmware version used.
1803 *
1804 * For example,
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001805 * if (IL_UCODE_API(il->ucode_ver) >= 2) {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001806 * Driver interacts with Firmware API version >= 2.
1807 * } else {
1808 * Driver interacts with Firmware API version 1.
1809 * }
1810 *
1811 * The ideal usage of this infrastructure is to treat a new ucode API
1812 * release as a new hardware revision. That is, through utilizing the
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001813 * il_hcmd_utils_ops etc. we accommodate different command structures
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001814 * and flows between hardware versions as well as their API
1815 * versions.
1816 *
1817 */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001818struct il_cfg {
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001819 /* params specific to an individual device within a device family */
1820 const char *name;
1821 const char *fw_name_pre;
1822 const unsigned int ucode_api_max;
1823 const unsigned int ucode_api_min;
1824 u8 valid_tx_ant;
1825 u8 valid_rx_ant;
1826 unsigned int sku;
1827 u16 eeprom_ver;
1828 u16 eeprom_calib_ver;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001829 const struct il_ops *ops;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001830 /* module based parameters which can be set from modprobe cmd */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001831 const struct il_mod_params *mod_params;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001832 /* params not likely to change within a device family */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001833 struct il_base_params *base_params;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001834 /* params likely to change within a device family */
1835 u8 scan_rx_antennas[IEEE80211_NUM_BANDS];
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001836 enum il_led_mode led_mode;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001837};
1838
1839/***************************
1840 * L i b *
1841 ***************************/
1842
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001843struct ieee80211_hw *il_alloc_all(struct il_cfg *cfg);
1844int il_mac_conf_tx(struct ieee80211_hw *hw,
Eliad Peller8a3a3c82011-10-02 10:15:52 +02001845 struct ieee80211_vif *vif, u16 queue,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001846 const struct ieee80211_tx_queue_params *params);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001847int il_mac_tx_last_beacon(struct ieee80211_hw *hw);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001848void il_set_rxon_hwcrypto(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001849 struct il_rxon_context *ctx,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001850 int hw_decrypt);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001851int il_check_rxon_cmd(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001852 struct il_rxon_context *ctx);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001853int il_full_rxon_required(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001854 struct il_rxon_context *ctx);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001855int il_set_rxon_channel(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001856 struct ieee80211_channel *ch,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001857 struct il_rxon_context *ctx);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001858void il_set_flags_for_band(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001859 struct il_rxon_context *ctx,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001860 enum ieee80211_band band,
1861 struct ieee80211_vif *vif);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001862u8 il_get_single_channel_number(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001863 enum ieee80211_band band);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001864void il_set_rxon_ht(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001865 struct il_ht_config *ht_conf);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001866bool il_is_ht40_tx_allowed(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001867 struct il_rxon_context *ctx,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001868 struct ieee80211_sta_ht_cap *ht_cap);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001869void il_connection_init_rx_config(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001870 struct il_rxon_context *ctx);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001871void il_set_rate(struct il_priv *il);
1872int il_set_decrypted_flag(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001873 struct ieee80211_hdr *hdr,
1874 u32 decrypt_res,
1875 struct ieee80211_rx_status *stats);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001876void il_irq_handle_error(struct il_priv *il);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001877int il_mac_add_interface(struct ieee80211_hw *hw,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001878 struct ieee80211_vif *vif);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001879void il_mac_remove_interface(struct ieee80211_hw *hw,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001880 struct ieee80211_vif *vif);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001881int il_mac_change_interface(struct ieee80211_hw *hw,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001882 struct ieee80211_vif *vif,
1883 enum nl80211_iftype newtype, bool newp2p);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001884int il_alloc_txq_mem(struct il_priv *il);
1885void il_txq_mem(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001886
Stanislaw Gruszkad3175162011-11-15 11:25:42 +01001887#ifdef CONFIG_IWLEGACY_DEBUGFS
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001888int il_alloc_traffic_mem(struct il_priv *il);
1889void il_free_traffic_mem(struct il_priv *il);
1890void il_reset_traffic_log(struct il_priv *il);
1891void il_dbg_log_tx_data_frame(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001892 u16 length, struct ieee80211_hdr *header);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001893void il_dbg_log_rx_data_frame(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001894 u16 length, struct ieee80211_hdr *header);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001895const char *il_get_mgmt_string(int cmd);
1896const char *il_get_ctrl_string(int cmd);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001897void il_clear_traffic_stats(struct il_priv *il);
1898void il_update_stats(struct il_priv *il, bool is_tx, __le16 fc,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001899 u16 len);
1900#else
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001901static inline int il_alloc_traffic_mem(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001902{
1903 return 0;
1904}
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001905static inline void il_free_traffic_mem(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001906{
1907}
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001908static inline void il_reset_traffic_log(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001909{
1910}
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001911static inline void il_dbg_log_tx_data_frame(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001912 u16 length, struct ieee80211_hdr *header)
1913{
1914}
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001915static inline void il_dbg_log_rx_data_frame(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001916 u16 length, struct ieee80211_hdr *header)
1917{
1918}
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001919static inline void il_update_stats(struct il_priv *il, bool is_tx,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001920 __le16 fc, u16 len)
1921{
1922}
1923#endif
1924/*****************************************************
1925 * RX handlers.
1926 * **************************************************/
Stanislaw Gruszkad2dfb332011-11-15 13:16:38 +01001927void il_hdl_pm_sleep(struct il_priv *il,
Stanislaw Gruszkab73bb5f2011-08-26 14:37:54 +02001928 struct il_rx_buf *rxb);
Stanislaw Gruszkad2dfb332011-11-15 13:16:38 +01001929void il_hdl_pm_debug_stats(struct il_priv *il,
Stanislaw Gruszkab73bb5f2011-08-26 14:37:54 +02001930 struct il_rx_buf *rxb);
Stanislaw Gruszka6e9848b42011-08-30 15:45:31 +02001931void il_hdl_error(struct il_priv *il,
Stanislaw Gruszkab73bb5f2011-08-26 14:37:54 +02001932 struct il_rx_buf *rxb);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001933
1934/*****************************************************
1935* RX
1936******************************************************/
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001937void il_cmd_queue_unmap(struct il_priv *il);
1938void il_cmd_queue_free(struct il_priv *il);
1939int il_rx_queue_alloc(struct il_priv *il);
1940void il_rx_queue_update_write_ptr(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001941 struct il_rx_queue *q);
1942int il_rx_queue_space(const struct il_rx_queue *q);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001943void il_tx_cmd_complete(struct il_priv *il,
Stanislaw Gruszkab73bb5f2011-08-26 14:37:54 +02001944 struct il_rx_buf *rxb);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001945/* Handlers */
Stanislaw Gruszkad2dfb332011-11-15 13:16:38 +01001946void il_hdl_spectrum_measurement(struct il_priv *il,
Stanislaw Gruszkab73bb5f2011-08-26 14:37:54 +02001947 struct il_rx_buf *rxb);
Stanislaw Gruszkaebf0d902011-08-26 15:43:47 +02001948void il_recover_from_stats(struct il_priv *il,
Stanislaw Gruszkadcae1c62011-08-26 14:36:21 +02001949 struct il_rx_pkt *pkt);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001950void il_chswitch_done(struct il_priv *il, bool is_success);
Stanislaw Gruszkad2dfb332011-11-15 13:16:38 +01001951void il_hdl_csa(struct il_priv *il, struct il_rx_buf *rxb);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001952
1953/* TX helpers */
1954
1955/*****************************************************
1956* TX
1957******************************************************/
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001958void il_txq_update_write_ptr(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001959 struct il_tx_queue *txq);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001960int il_tx_queue_init(struct il_priv *il, struct il_tx_queue *txq,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001961 int slots_num, u32 txq_id);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001962void il_tx_queue_reset(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001963 struct il_tx_queue *txq,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001964 int slots_num, u32 txq_id);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001965void il_tx_queue_unmap(struct il_priv *il, int txq_id);
1966void il_tx_queue_free(struct il_priv *il, int txq_id);
1967void il_setup_watchdog(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001968/*****************************************************
1969 * TX power
1970 ****************************************************/
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001971int il_set_tx_power(struct il_priv *il, s8 tx_power, bool force);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001972
1973/*******************************************************************************
1974 * Rate
1975 ******************************************************************************/
1976
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001977u8 il_get_lowest_plcp(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001978 struct il_rxon_context *ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001979
1980/*******************************************************************************
1981 * Scanning
1982 ******************************************************************************/
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001983void il_init_scan_params(struct il_priv *il);
1984int il_scan_cancel(struct il_priv *il);
1985int il_scan_cancel_timeout(struct il_priv *il, unsigned long ms);
1986void il_force_scan_end(struct il_priv *il);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001987int il_mac_hw_scan(struct ieee80211_hw *hw,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001988 struct ieee80211_vif *vif,
1989 struct cfg80211_scan_request *req);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001990void il_internal_short_hw_scan(struct il_priv *il);
1991int il_force_reset(struct il_priv *il, bool external);
1992u16 il_fill_probe_req(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001993 struct ieee80211_mgmt *frame,
1994 const u8 *ta, const u8 *ie, int ie_len, int left);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001995void il_setup_rx_scan_handlers(struct il_priv *il);
1996u16 il_get_active_dwell_time(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001997 enum ieee80211_band band,
1998 u8 n_probes);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001999u16 il_get_passive_dwell_time(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002000 enum ieee80211_band band,
2001 struct ieee80211_vif *vif);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002002void il_setup_scan_deferred_work(struct il_priv *il);
2003void il_cancel_scan_deferred_work(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002004
2005/* For faster active scanning, scan will move to the next channel if fewer than
2006 * PLCP_QUIET_THRESH packets are heard on this channel within
2007 * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
2008 * time if it's a quiet channel (nothing responded to our probe, and there's
2009 * no other traffic).
2010 * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002011#define IL_ACTIVE_QUIET_TIME cpu_to_le16(10) /* msec */
2012#define IL_PLCP_QUIET_THRESH cpu_to_le16(1) /* packets */
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002013
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002014#define IL_SCAN_CHECK_WATCHDOG (HZ * 7)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002015
2016/*****************************************************
2017 * S e n d i n g H o s t C o m m a n d s *
2018 *****************************************************/
2019
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002020const char *il_get_cmd_string(u8 cmd);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002021int __must_check il_send_cmd_sync(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002022 struct il_host_cmd *cmd);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002023int il_send_cmd(struct il_priv *il, struct il_host_cmd *cmd);
2024int __must_check il_send_cmd_pdu(struct il_priv *il, u8 id,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002025 u16 len, const void *data);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002026int il_send_cmd_pdu_async(struct il_priv *il, u8 id, u16 len,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002027 const void *data,
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002028 void (*callback)(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002029 struct il_device_cmd *cmd,
Stanislaw Gruszkadcae1c62011-08-26 14:36:21 +02002030 struct il_rx_pkt *pkt));
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002031
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002032int il_enqueue_hcmd(struct il_priv *il, struct il_host_cmd *cmd);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002033
2034
2035/*****************************************************
2036 * PCI *
2037 *****************************************************/
2038
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002039static inline u16 il_pcie_link_ctl(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002040{
2041 int pos;
2042 u16 pci_lnk_ctl;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002043 pos = pci_pcie_cap(il->pci_dev);
2044 pci_read_config_word(il->pci_dev, pos + PCI_EXP_LNKCTL, &pci_lnk_ctl);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002045 return pci_lnk_ctl;
2046}
2047
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002048void il_bg_watchdog(unsigned long data);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002049u32 il_usecs_to_beacons(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002050 u32 usec, u32 beacon_interval);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002051__le32 il_add_beacon_time(struct il_priv *il, u32 base,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002052 u32 addon, u32 beacon_interval);
2053
2054#ifdef CONFIG_PM
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002055int il_pci_suspend(struct device *device);
2056int il_pci_resume(struct device *device);
2057extern const struct dev_pm_ops il_pm_ops;
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002058
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002059#define IL_LEGACY_PM_OPS (&il_pm_ops)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002060
2061#else /* !CONFIG_PM */
2062
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002063#define IL_LEGACY_PM_OPS NULL
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002064
2065#endif /* !CONFIG_PM */
2066
2067/*****************************************************
2068* Error Handling Debugging
2069******************************************************/
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002070void il4965_dump_nic_error_log(struct il_priv *il);
Stanislaw Gruszkad3175162011-11-15 11:25:42 +01002071#ifdef CONFIG_IWLEGACY_DEBUG
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002072void il_print_rx_config_cmd(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002073 struct il_rxon_context *ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002074#else
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002075static inline void il_print_rx_config_cmd(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002076 struct il_rxon_context *ctx)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002077{
2078}
2079#endif
2080
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002081void il_clear_isr_stats(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002082
2083/*****************************************************
2084* GEOS
2085******************************************************/
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002086int il_init_geos(struct il_priv *il);
2087void il_free_geos(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002088
2089/*************** DRIVER STATUS FUNCTIONS *****/
2090
Stanislaw Gruszkaa6766cc2011-11-15 13:09:01 +01002091#define S_HCMD_ACTIVE 0 /* host command in progress */
2092/* 1 is unused (used to be S_HCMD_SYNC_ACTIVE) */
2093#define S_INT_ENABLED 2
2094#define S_RF_KILL_HW 3
2095#define S_CT_KILL 4
2096#define S_INIT 5
2097#define S_ALIVE 6
2098#define S_READY 7
2099#define S_TEMPERATURE 8
2100#define S_GEO_CONFIGURED 9
2101#define S_EXIT_PENDING 10
Stanislaw Gruszkadb7746f2011-11-15 13:11:50 +01002102#define S_STATS 12
Stanislaw Gruszkaa6766cc2011-11-15 13:09:01 +01002103#define S_SCANNING 13
2104#define S_SCAN_ABORTING 14
2105#define S_SCAN_HW 15
2106#define S_POWER_PMI 16
2107#define S_FW_ERROR 17
2108#define S_CHANNEL_SWITCH_PENDING 18
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002109
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002110static inline int il_is_ready(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002111{
2112 /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are
2113 * set but EXIT_PENDING is not */
Stanislaw Gruszkaa6766cc2011-11-15 13:09:01 +01002114 return test_bit(S_READY, &il->status) &&
2115 test_bit(S_GEO_CONFIGURED, &il->status) &&
2116 !test_bit(S_EXIT_PENDING, &il->status);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002117}
2118
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002119static inline int il_is_alive(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002120{
Stanislaw Gruszkaa6766cc2011-11-15 13:09:01 +01002121 return test_bit(S_ALIVE, &il->status);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002122}
2123
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002124static inline int il_is_init(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002125{
Stanislaw Gruszkaa6766cc2011-11-15 13:09:01 +01002126 return test_bit(S_INIT, &il->status);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002127}
2128
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002129static inline int il_is_rfkill_hw(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002130{
Stanislaw Gruszkaa6766cc2011-11-15 13:09:01 +01002131 return test_bit(S_RF_KILL_HW, &il->status);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002132}
2133
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002134static inline int il_is_rfkill(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002135{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002136 return il_is_rfkill_hw(il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002137}
2138
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002139static inline int il_is_ctkill(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002140{
Stanislaw Gruszkaa6766cc2011-11-15 13:09:01 +01002141 return test_bit(S_CT_KILL, &il->status);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002142}
2143
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002144static inline int il_is_ready_rf(struct il_priv *il)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002145{
2146
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002147 if (il_is_rfkill(il))
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002148 return 0;
2149
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002150 return il_is_ready(il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002151}
2152
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002153extern void il_send_bt_config(struct il_priv *il);
Stanislaw Gruszkaebf0d902011-08-26 15:43:47 +02002154extern int il_send_stats_request(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002155 u8 flags, bool clear);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002156void il_apm_stop(struct il_priv *il);
2157int il_apm_init(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002158
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002159int il_send_rxon_timing(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002160 struct il_rxon_context *ctx);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002161static inline int il_send_rxon_assoc(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002162 struct il_rxon_context *ctx)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002163{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002164 return il->cfg->ops->hcmd->rxon_assoc(il, ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002165}
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002166static inline int il_commit_rxon(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002167 struct il_rxon_context *ctx)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002168{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002169 return il->cfg->ops->hcmd->commit_rxon(il, ctx);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002170}
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002171static inline const struct ieee80211_supported_band *il_get_hw_mode(
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002172 struct il_priv *il, enum ieee80211_band band)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002173{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002174 return il->hw->wiphy->bands[band];
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002175}
2176
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002177/* mac80211 handlers */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002178int il_mac_config(struct ieee80211_hw *hw, u32 changed);
2179void il_mac_reset_tsf(struct ieee80211_hw *hw,
Eliad Peller37a41b42011-09-21 14:06:11 +03002180 struct ieee80211_vif *vif);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002181void il_mac_bss_info_changed(struct ieee80211_hw *hw,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002182 struct ieee80211_vif *vif,
2183 struct ieee80211_bss_conf *bss_conf,
2184 u32 changes);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002185void il_tx_cmd_protection(struct il_priv *il,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002186 struct ieee80211_tx_info *info,
2187 __le16 fc, __le32 *tx_flags);
2188
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002189irqreturn_t il_isr(int irq, void *data);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002190
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +02002191
2192#include <linux/io.h>
2193
2194static inline void _il_write8(struct il_priv *il, u32 ofs, u8 val)
2195{
2196 iowrite8(val, il->hw_base + ofs);
2197}
2198#define il_write8(il, ofs, val) _il_write8(il, ofs, val)
2199
2200static inline void _il_wr(struct il_priv *il, u32 ofs, u32 val)
2201{
2202 iowrite32(val, il->hw_base + ofs);
2203}
2204
2205static inline u32 _il_rd(struct il_priv *il, u32 ofs)
2206{
2207 return ioread32(il->hw_base + ofs);
2208}
2209
2210#define IL_POLL_INTERVAL 10 /* microseconds */
2211static inline int
2212_il_poll_bit(struct il_priv *il, u32 addr,
2213 u32 bits, u32 mask, int timeout)
2214{
2215 int t = 0;
2216
2217 do {
2218 if ((_il_rd(il, addr) & mask) == (bits & mask))
2219 return t;
2220 udelay(IL_POLL_INTERVAL);
2221 t += IL_POLL_INTERVAL;
2222 } while (t < timeout);
2223
2224 return -ETIMEDOUT;
2225}
2226
2227static inline void _il_set_bit(struct il_priv *il, u32 reg, u32 mask)
2228{
2229 _il_wr(il, reg, _il_rd(il, reg) | mask);
2230}
2231
2232static inline void il_set_bit(struct il_priv *p, u32 r, u32 m)
2233{
2234 unsigned long reg_flags;
2235
2236 spin_lock_irqsave(&p->reg_lock, reg_flags);
2237 _il_set_bit(p, r, m);
2238 spin_unlock_irqrestore(&p->reg_lock, reg_flags);
2239}
2240
2241static inline void
2242_il_clear_bit(struct il_priv *il, u32 reg, u32 mask)
2243{
2244 _il_wr(il, reg, _il_rd(il, reg) & ~mask);
2245}
2246
2247static inline void il_clear_bit(struct il_priv *p, u32 r, u32 m)
2248{
2249 unsigned long reg_flags;
2250
2251 spin_lock_irqsave(&p->reg_lock, reg_flags);
2252 _il_clear_bit(p, r, m);
2253 spin_unlock_irqrestore(&p->reg_lock, reg_flags);
2254}
2255
2256static inline int _il_grab_nic_access(struct il_priv *il)
2257{
2258 int ret;
2259 u32 val;
2260
2261 /* this bit wakes up the NIC */
2262 _il_set_bit(il, CSR_GP_CNTRL,
2263 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
2264
2265 /*
2266 * These bits say the device is running, and should keep running for
2267 * at least a short while (at least as long as MAC_ACCESS_REQ stays 1),
2268 * but they do not indicate that embedded SRAM is restored yet;
2269 * 3945 and 4965 have volatile SRAM, and must save/restore contents
2270 * to/from host DRAM when sleeping/waking for power-saving.
2271 * Each direction takes approximately 1/4 millisecond; with this
2272 * overhead, it's a good idea to grab and hold MAC_ACCESS_REQUEST if a
2273 * series of register accesses are expected (e.g. reading Event Log),
2274 * to keep device from sleeping.
2275 *
2276 * CSR_UCODE_DRV_GP1 register bit MAC_SLEEP == 0 indicates that
2277 * SRAM is okay/restored. We don't check that here because this call
2278 * is just for hardware register access; but GP1 MAC_SLEEP check is a
2279 * good idea before accessing 3945/4965 SRAM (e.g. reading Event Log).
2280 *
2281 */
2282 ret = _il_poll_bit(il, CSR_GP_CNTRL,
2283 CSR_GP_CNTRL_REG_VAL_MAC_ACCESS_EN,
2284 (CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY |
2285 CSR_GP_CNTRL_REG_FLAG_GOING_TO_SLEEP), 15000);
2286 if (ret < 0) {
2287 val = _il_rd(il, CSR_GP_CNTRL);
2288 IL_ERR(
2289 "MAC is in deep sleep!. CSR_GP_CNTRL = 0x%08X\n", val);
2290 _il_wr(il, CSR_RESET,
2291 CSR_RESET_REG_FLAG_FORCE_NMI);
2292 return -EIO;
2293 }
2294
2295 return 0;
2296}
2297
2298static inline void _il_release_nic_access(struct il_priv *il)
2299{
2300 _il_clear_bit(il, CSR_GP_CNTRL,
2301 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
2302}
2303
2304static inline u32 il_rd(struct il_priv *il, u32 reg)
2305{
2306 u32 value;
2307 unsigned long reg_flags;
2308
2309 spin_lock_irqsave(&il->reg_lock, reg_flags);
2310 _il_grab_nic_access(il);
2311 value = _il_rd(il, reg);
2312 _il_release_nic_access(il);
2313 spin_unlock_irqrestore(&il->reg_lock, reg_flags);
2314 return value;
2315
2316}
2317
2318static inline void
2319il_wr(struct il_priv *il, u32 reg, u32 value)
2320{
2321 unsigned long reg_flags;
2322
2323 spin_lock_irqsave(&il->reg_lock, reg_flags);
2324 if (!_il_grab_nic_access(il)) {
2325 _il_wr(il, reg, value);
2326 _il_release_nic_access(il);
2327 }
2328 spin_unlock_irqrestore(&il->reg_lock, reg_flags);
2329}
2330
2331static inline void il_write_reg_buf(struct il_priv *il,
2332 u32 reg, u32 len, u32 *values)
2333{
2334 u32 count = sizeof(u32);
2335
2336 if (il != NULL && values != NULL) {
2337 for (; 0 < len; len -= count, reg += count, values++)
2338 il_wr(il, reg, *values);
2339 }
2340}
2341
2342static inline int il_poll_bit(struct il_priv *il, u32 addr,
2343 u32 mask, int timeout)
2344{
2345 int t = 0;
2346
2347 do {
2348 if ((il_rd(il, addr) & mask) == mask)
2349 return t;
2350 udelay(IL_POLL_INTERVAL);
2351 t += IL_POLL_INTERVAL;
2352 } while (t < timeout);
2353
2354 return -ETIMEDOUT;
2355}
2356
2357static inline u32 _il_rd_prph(struct il_priv *il, u32 reg)
2358{
2359 _il_wr(il, HBUS_TARG_PRPH_RADDR, reg | (3 << 24));
2360 rmb();
2361 return _il_rd(il, HBUS_TARG_PRPH_RDAT);
2362}
2363
2364static inline u32 il_rd_prph(struct il_priv *il, u32 reg)
2365{
2366 unsigned long reg_flags;
2367 u32 val;
2368
2369 spin_lock_irqsave(&il->reg_lock, reg_flags);
2370 _il_grab_nic_access(il);
2371 val = _il_rd_prph(il, reg);
2372 _il_release_nic_access(il);
2373 spin_unlock_irqrestore(&il->reg_lock, reg_flags);
2374 return val;
2375}
2376
2377static inline void _il_wr_prph(struct il_priv *il,
2378 u32 addr, u32 val)
2379{
2380 _il_wr(il, HBUS_TARG_PRPH_WADDR,
2381 ((addr & 0x0000FFFF) | (3 << 24)));
2382 wmb();
2383 _il_wr(il, HBUS_TARG_PRPH_WDAT, val);
2384}
2385
2386static inline void
2387il_wr_prph(struct il_priv *il, u32 addr, u32 val)
2388{
2389 unsigned long reg_flags;
2390
2391 spin_lock_irqsave(&il->reg_lock, reg_flags);
2392 if (!_il_grab_nic_access(il)) {
2393 _il_wr_prph(il, addr, val);
2394 _il_release_nic_access(il);
2395 }
2396 spin_unlock_irqrestore(&il->reg_lock, reg_flags);
2397}
2398
2399#define _il_set_bits_prph(il, reg, mask) \
2400_il_wr_prph(il, reg, (_il_rd_prph(il, reg) | mask))
2401
2402static inline void
2403il_set_bits_prph(struct il_priv *il, u32 reg, u32 mask)
2404{
2405 unsigned long reg_flags;
2406
2407 spin_lock_irqsave(&il->reg_lock, reg_flags);
2408 _il_grab_nic_access(il);
2409 _il_set_bits_prph(il, reg, mask);
2410 _il_release_nic_access(il);
2411 spin_unlock_irqrestore(&il->reg_lock, reg_flags);
2412}
2413
2414#define _il_set_bits_mask_prph(il, reg, bits, mask) \
2415_il_wr_prph(il, reg, \
2416 ((_il_rd_prph(il, reg) & mask) | bits))
2417
2418static inline void il_set_bits_mask_prph(struct il_priv *il, u32 reg,
2419 u32 bits, u32 mask)
2420{
2421 unsigned long reg_flags;
2422
2423 spin_lock_irqsave(&il->reg_lock, reg_flags);
2424 _il_grab_nic_access(il);
2425 _il_set_bits_mask_prph(il, reg, bits, mask);
2426 _il_release_nic_access(il);
2427 spin_unlock_irqrestore(&il->reg_lock, reg_flags);
2428}
2429
2430static inline void il_clear_bits_prph(struct il_priv
2431 *il, u32 reg, u32 mask)
2432{
2433 unsigned long reg_flags;
2434 u32 val;
2435
2436 spin_lock_irqsave(&il->reg_lock, reg_flags);
2437 _il_grab_nic_access(il);
2438 val = _il_rd_prph(il, reg);
2439 _il_wr_prph(il, reg, (val & ~mask));
2440 _il_release_nic_access(il);
2441 spin_unlock_irqrestore(&il->reg_lock, reg_flags);
2442}
2443
2444static inline u32 il_read_targ_mem(struct il_priv *il, u32 addr)
2445{
2446 unsigned long reg_flags;
2447 u32 value;
2448
2449 spin_lock_irqsave(&il->reg_lock, reg_flags);
2450 _il_grab_nic_access(il);
2451
2452 _il_wr(il, HBUS_TARG_MEM_RADDR, addr);
2453 rmb();
2454 value = _il_rd(il, HBUS_TARG_MEM_RDAT);
2455
2456 _il_release_nic_access(il);
2457 spin_unlock_irqrestore(&il->reg_lock, reg_flags);
2458 return value;
2459}
2460
2461static inline void
2462il_write_targ_mem(struct il_priv *il, u32 addr, u32 val)
2463{
2464 unsigned long reg_flags;
2465
2466 spin_lock_irqsave(&il->reg_lock, reg_flags);
2467 if (!_il_grab_nic_access(il)) {
2468 _il_wr(il, HBUS_TARG_MEM_WADDR, addr);
2469 wmb();
2470 _il_wr(il, HBUS_TARG_MEM_WDAT, val);
2471 _il_release_nic_access(il);
2472 }
2473 spin_unlock_irqrestore(&il->reg_lock, reg_flags);
2474}
2475
2476static inline void
2477il_write_targ_mem_buf(struct il_priv *il, u32 addr,
2478 u32 len, u32 *values)
2479{
2480 unsigned long reg_flags;
2481
2482 spin_lock_irqsave(&il->reg_lock, reg_flags);
2483 if (!_il_grab_nic_access(il)) {
2484 _il_wr(il, HBUS_TARG_MEM_WADDR, addr);
2485 wmb();
2486 for (; 0 < len; len -= sizeof(u32), values++)
2487 _il_wr(il,
2488 HBUS_TARG_MEM_WDAT, *values);
2489
2490 _il_release_nic_access(il);
2491 }
2492 spin_unlock_irqrestore(&il->reg_lock, reg_flags);
2493}
2494
2495#define HW_KEY_DYNAMIC 0
2496#define HW_KEY_DEFAULT 1
2497
2498#define IL_STA_DRIVER_ACTIVE BIT(0) /* driver entry is active */
2499#define IL_STA_UCODE_ACTIVE BIT(1) /* ucode entry is active */
2500#define IL_STA_UCODE_INPROGRESS BIT(2) /* ucode entry is in process of
2501 being activated */
2502#define IL_STA_LOCAL BIT(3) /* station state not directed by mac80211;
2503 (this is for the IBSS BSSID stations) */
2504#define IL_STA_BCAST BIT(4) /* this station is the special bcast station */
2505
2506
2507void il_restore_stations(struct il_priv *il,
2508 struct il_rxon_context *ctx);
2509void il_clear_ucode_stations(struct il_priv *il,
2510 struct il_rxon_context *ctx);
2511void il_dealloc_bcast_stations(struct il_priv *il);
2512int il_get_free_ucode_key_idx(struct il_priv *il);
2513int il_send_add_sta(struct il_priv *il,
2514 struct il_addsta_cmd *sta, u8 flags);
2515int il_add_station_common(struct il_priv *il,
2516 struct il_rxon_context *ctx,
2517 const u8 *addr, bool is_ap,
2518 struct ieee80211_sta *sta, u8 *sta_id_r);
2519int il_remove_station(struct il_priv *il,
2520 const u8 sta_id,
2521 const u8 *addr);
2522int il_mac_sta_remove(struct ieee80211_hw *hw,
2523 struct ieee80211_vif *vif,
2524 struct ieee80211_sta *sta);
2525
2526u8 il_prep_station(struct il_priv *il,
2527 struct il_rxon_context *ctx,
2528 const u8 *addr, bool is_ap,
2529 struct ieee80211_sta *sta);
2530
2531int il_send_lq_cmd(struct il_priv *il,
2532 struct il_rxon_context *ctx,
2533 struct il_link_quality_cmd *lq,
2534 u8 flags, bool init);
2535
2536/**
2537 * il_clear_driver_stations - clear knowledge of all stations from driver
2538 * @il: iwl il struct
2539 *
2540 * This is called during il_down() to make sure that in the case
2541 * we're coming there from a hardware restart mac80211 will be
2542 * able to reconfigure stations -- if we're getting there in the
2543 * normal down flow then the stations will already be cleared.
2544 */
2545static inline void il_clear_driver_stations(struct il_priv *il)
2546{
2547 unsigned long flags;
2548 struct il_rxon_context *ctx = &il->ctx;
2549
2550 spin_lock_irqsave(&il->sta_lock, flags);
2551 memset(il->stations, 0, sizeof(il->stations));
2552 il->num_stations = 0;
2553
2554 il->ucode_key_table = 0;
2555
2556 /*
2557 * Remove all key information that is not stored as part
2558 * of station information since mac80211 may not have had
2559 * a chance to remove all the keys. When device is
2560 * reconfigured by mac80211 after an error all keys will
2561 * be reconfigured.
2562 */
2563 memset(ctx->wep_keys, 0, sizeof(ctx->wep_keys));
2564 ctx->key_mapping_keys = 0;
2565
2566 spin_unlock_irqrestore(&il->sta_lock, flags);
2567}
2568
2569static inline int il_sta_id(struct ieee80211_sta *sta)
2570{
2571 if (WARN_ON(!sta))
2572 return IL_INVALID_STATION;
2573
2574 return ((struct il_station_priv_common *)sta->drv_priv)->sta_id;
2575}
2576
2577/**
2578 * il_sta_id_or_broadcast - return sta_id or broadcast sta
2579 * @il: iwl il
2580 * @context: the current context
2581 * @sta: mac80211 station
2582 *
2583 * In certain circumstances mac80211 passes a station pointer
2584 * that may be %NULL, for example during TX or key setup. In
2585 * that case, we need to use the broadcast station, so this
2586 * inline wraps that pattern.
2587 */
2588static inline int il_sta_id_or_broadcast(struct il_priv *il,
2589 struct il_rxon_context *context,
2590 struct ieee80211_sta *sta)
2591{
2592 int sta_id;
2593
2594 if (!sta)
2595 return context->bcast_sta_id;
2596
2597 sta_id = il_sta_id(sta);
2598
2599 /*
2600 * mac80211 should not be passing a partially
2601 * initialised station!
2602 */
2603 WARN_ON(sta_id == IL_INVALID_STATION);
2604
2605 return sta_id;
2606}
2607
2608/**
2609 * il_queue_inc_wrap - increment queue idx, wrap back to beginning
2610 * @idx -- current idx
2611 * @n_bd -- total number of entries in queue (must be power of 2)
2612 */
2613static inline int il_queue_inc_wrap(int idx, int n_bd)
2614{
2615 return ++idx & (n_bd - 1);
2616}
2617
2618/**
2619 * il_queue_dec_wrap - decrement queue idx, wrap back to end
2620 * @idx -- current idx
2621 * @n_bd -- total number of entries in queue (must be power of 2)
2622 */
2623static inline int il_queue_dec_wrap(int idx, int n_bd)
2624{
2625 return --idx & (n_bd - 1);
2626}
2627
2628/* TODO: Move fw_desc functions to iwl-pci.ko */
2629static inline void il_free_fw_desc(struct pci_dev *pci_dev,
2630 struct fw_desc *desc)
2631{
2632 if (desc->v_addr)
2633 dma_free_coherent(&pci_dev->dev, desc->len,
2634 desc->v_addr, desc->p_addr);
2635 desc->v_addr = NULL;
2636 desc->len = 0;
2637}
2638
2639static inline int il_alloc_fw_desc(struct pci_dev *pci_dev,
2640 struct fw_desc *desc)
2641{
2642 if (!desc->len) {
2643 desc->v_addr = NULL;
2644 return -EINVAL;
2645 }
2646
2647 desc->v_addr = dma_alloc_coherent(&pci_dev->dev, desc->len,
2648 &desc->p_addr, GFP_KERNEL);
2649 return (desc->v_addr != NULL) ? 0 : -ENOMEM;
2650}
2651
2652/*
2653 * we have 8 bits used like this:
2654 *
2655 * 7 6 5 4 3 2 1 0
2656 * | | | | | | | |
2657 * | | | | | | +-+-------- AC queue (0-3)
2658 * | | | | | |
2659 * | +-+-+-+-+------------ HW queue ID
2660 * |
2661 * +---------------------- unused
2662 */
2663static inline void
2664il_set_swq_id(struct il_tx_queue *txq, u8 ac, u8 hwq)
2665{
2666 BUG_ON(ac > 3); /* only have 2 bits */
2667 BUG_ON(hwq > 31); /* only use 5 bits */
2668
2669 txq->swq_id = (hwq << 2) | ac;
2670}
2671
2672static inline void il_wake_queue(struct il_priv *il,
2673 struct il_tx_queue *txq)
2674{
2675 u8 queue = txq->swq_id;
2676 u8 ac = queue & 3;
2677 u8 hwq = (queue >> 2) & 0x1f;
2678
2679 if (test_and_clear_bit(hwq, il->queue_stopped))
2680 if (atomic_dec_return(&il->queue_stop_count[ac]) <= 0)
2681 ieee80211_wake_queue(il->hw, ac);
2682}
2683
2684static inline void il_stop_queue(struct il_priv *il,
2685 struct il_tx_queue *txq)
2686{
2687 u8 queue = txq->swq_id;
2688 u8 ac = queue & 3;
2689 u8 hwq = (queue >> 2) & 0x1f;
2690
2691 if (!test_and_set_bit(hwq, il->queue_stopped))
2692 if (atomic_inc_return(&il->queue_stop_count[ac]) > 0)
2693 ieee80211_stop_queue(il->hw, ac);
2694}
2695
2696#ifdef ieee80211_stop_queue
2697#undef ieee80211_stop_queue
2698#endif
2699
2700#define ieee80211_stop_queue DO_NOT_USE_ieee80211_stop_queue
2701
2702#ifdef ieee80211_wake_queue
2703#undef ieee80211_wake_queue
2704#endif
2705
2706#define ieee80211_wake_queue DO_NOT_USE_ieee80211_wake_queue
2707
2708static inline void il_disable_interrupts(struct il_priv *il)
2709{
2710 clear_bit(S_INT_ENABLED, &il->status);
2711
2712 /* disable interrupts from uCode/NIC to host */
2713 _il_wr(il, CSR_INT_MASK, 0x00000000);
2714
2715 /* acknowledge/clear/reset any interrupts still pending
2716 * from uCode or flow handler (Rx/Tx DMA) */
2717 _il_wr(il, CSR_INT, 0xffffffff);
2718 _il_wr(il, CSR_FH_INT_STATUS, 0xffffffff);
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +02002719}
2720
2721static inline void il_enable_rfkill_int(struct il_priv *il)
2722{
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +02002723 _il_wr(il, CSR_INT_MASK, CSR_INT_BIT_RF_KILL);
2724}
2725
2726static inline void il_enable_interrupts(struct il_priv *il)
2727{
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +02002728 set_bit(S_INT_ENABLED, &il->status);
2729 _il_wr(il, CSR_INT_MASK, il->inta_mask);
2730}
2731
2732/**
2733 * il_beacon_time_mask_low - mask of lower 32 bit of beacon time
2734 * @il -- pointer to il_priv data structure
2735 * @tsf_bits -- number of bits need to shift for masking)
2736 */
2737static inline u32 il_beacon_time_mask_low(struct il_priv *il,
2738 u16 tsf_bits)
2739{
2740 return (1 << tsf_bits) - 1;
2741}
2742
2743/**
2744 * il_beacon_time_mask_high - mask of higher 32 bit of beacon time
2745 * @il -- pointer to il_priv data structure
2746 * @tsf_bits -- number of bits need to shift for masking)
2747 */
2748static inline u32 il_beacon_time_mask_high(struct il_priv *il,
2749 u16 tsf_bits)
2750{
2751 return ((1 << (32 - tsf_bits)) - 1) << tsf_bits;
2752}
2753
2754/**
2755 * struct il_rb_status - reseve buffer status host memory mapped FH registers
2756 *
2757 * @closed_rb_num [0:11] - Indicates the idx of the RB which was closed
2758 * @closed_fr_num [0:11] - Indicates the idx of the RX Frame which was closed
2759 * @finished_rb_num [0:11] - Indicates the idx of the current RB
2760 * in which the last frame was written to
2761 * @finished_fr_num [0:11] - Indicates the idx of the RX Frame
2762 * which was transferred
2763 */
2764struct il_rb_status {
2765 __le16 closed_rb_num;
2766 __le16 closed_fr_num;
2767 __le16 finished_rb_num;
2768 __le16 finished_fr_nam;
2769 __le32 __unused; /* 3945 only */
2770} __packed;
2771
2772
2773#define TFD_QUEUE_SIZE_MAX (256)
2774#define TFD_QUEUE_SIZE_BC_DUP (64)
2775#define TFD_QUEUE_BC_SIZE (TFD_QUEUE_SIZE_MAX + TFD_QUEUE_SIZE_BC_DUP)
2776#define IL_TX_DMA_MASK DMA_BIT_MASK(36)
2777#define IL_NUM_OF_TBS 20
2778
2779static inline u8 il_get_dma_hi_addr(dma_addr_t addr)
2780{
2781 return (sizeof(addr) > sizeof(u32) ? (addr >> 16) >> 16 : 0) & 0xF;
2782}
2783/**
2784 * struct il_tfd_tb transmit buffer descriptor within transmit frame descriptor
2785 *
2786 * This structure contains dma address and length of transmission address
2787 *
2788 * @lo: low [31:0] portion of the dma address of TX buffer
2789 * every even is unaligned on 16 bit boundary
2790 * @hi_n_len 0-3 [35:32] portion of dma
2791 * 4-15 length of the tx buffer
2792 */
2793struct il_tfd_tb {
2794 __le32 lo;
2795 __le16 hi_n_len;
2796} __packed;
2797
2798/**
2799 * struct il_tfd
2800 *
2801 * Transmit Frame Descriptor (TFD)
2802 *
2803 * @ __reserved1[3] reserved
2804 * @ num_tbs 0-4 number of active tbs
2805 * 5 reserved
2806 * 6-7 padding (not used)
2807 * @ tbs[20] transmit frame buffer descriptors
2808 * @ __pad padding
2809 *
2810 * Each Tx queue uses a circular buffer of 256 TFDs stored in host DRAM.
2811 * Both driver and device share these circular buffers, each of which must be
2812 * contiguous 256 TFDs x 128 bytes-per-TFD = 32 KBytes
2813 *
2814 * Driver must indicate the physical address of the base of each
Stanislaw Gruszka9a95b372011-08-31 14:20:23 +02002815 * circular buffer via the FH49_MEM_CBBC_QUEUE registers.
Stanislaw Gruszkae94a4092011-08-31 13:23:20 +02002816 *
2817 * Each TFD contains pointer/size information for up to 20 data buffers
2818 * in host DRAM. These buffers collectively contain the (one) frame described
2819 * by the TFD. Each buffer must be a single contiguous block of memory within
2820 * itself, but buffers may be scattered in host DRAM. Each buffer has max size
2821 * of (4K - 4). The concatenates all of a TFD's buffers into a single
2822 * Tx frame, up to 8 KBytes in size.
2823 *
2824 * A maximum of 255 (not 256!) TFDs may be on a queue waiting for Tx.
2825 */
2826struct il_tfd {
2827 u8 __reserved1[3];
2828 u8 num_tbs;
2829 struct il_tfd_tb tbs[IL_NUM_OF_TBS];
2830 __le32 __pad;
2831} __packed;
2832/* PCI registers */
2833#define PCI_CFG_RETRY_TIMEOUT 0x041
2834
2835/* PCI register values */
2836#define PCI_CFG_LINK_CTRL_VAL_L0S_EN 0x01
2837#define PCI_CFG_LINK_CTRL_VAL_L1_EN 0x02
2838
Stanislaw Gruszka3fbbf9a2011-08-31 13:39:29 +02002839struct il_rate_info {
2840 u8 plcp; /* uCode API: RATE_6M_PLCP, etc. */
2841 u8 plcp_siso; /* uCode API: RATE_SISO_6M_PLCP, etc. */
2842 u8 plcp_mimo2; /* uCode API: RATE_MIMO2_6M_PLCP, etc. */
2843 u8 ieee; /* MAC header: RATE_6M_IEEE, etc. */
2844 u8 prev_ieee; /* previous rate in IEEE speeds */
2845 u8 next_ieee; /* next rate in IEEE speeds */
2846 u8 prev_rs; /* previous rate used in rs algo */
2847 u8 next_rs; /* next rate used in rs algo */
2848 u8 prev_rs_tgg; /* previous rate used in TGG rs algo */
2849 u8 next_rs_tgg; /* next rate used in TGG rs algo */
2850};
2851
2852struct il3945_rate_info {
2853 u8 plcp; /* uCode API: RATE_6M_PLCP, etc. */
2854 u8 ieee; /* MAC header: RATE_6M_IEEE, etc. */
2855 u8 prev_ieee; /* previous rate in IEEE speeds */
2856 u8 next_ieee; /* next rate in IEEE speeds */
2857 u8 prev_rs; /* previous rate used in rs algo */
2858 u8 next_rs; /* next rate used in rs algo */
2859 u8 prev_rs_tgg; /* previous rate used in TGG rs algo */
2860 u8 next_rs_tgg; /* next rate used in TGG rs algo */
2861 u8 table_rs_idx; /* idx in rate scale table cmd */
2862 u8 prev_table_rs; /* prev in rate table cmd */
2863};
2864
2865
2866/*
2867 * These serve as idxes into
2868 * struct il_rate_info il_rates[RATE_COUNT];
2869 */
2870enum {
2871 RATE_1M_IDX = 0,
2872 RATE_2M_IDX,
2873 RATE_5M_IDX,
2874 RATE_11M_IDX,
2875 RATE_6M_IDX,
2876 RATE_9M_IDX,
2877 RATE_12M_IDX,
2878 RATE_18M_IDX,
2879 RATE_24M_IDX,
2880 RATE_36M_IDX,
2881 RATE_48M_IDX,
2882 RATE_54M_IDX,
2883 RATE_60M_IDX,
2884 RATE_COUNT,
2885 RATE_COUNT_LEGACY = RATE_COUNT - 1, /* Excluding 60M */
2886 RATE_COUNT_3945 = RATE_COUNT - 1,
2887 RATE_INVM_IDX = RATE_COUNT,
2888 RATE_INVALID = RATE_COUNT,
2889};
2890
2891enum {
2892 RATE_6M_IDX_TBL = 0,
2893 RATE_9M_IDX_TBL,
2894 RATE_12M_IDX_TBL,
2895 RATE_18M_IDX_TBL,
2896 RATE_24M_IDX_TBL,
2897 RATE_36M_IDX_TBL,
2898 RATE_48M_IDX_TBL,
2899 RATE_54M_IDX_TBL,
2900 RATE_1M_IDX_TBL,
2901 RATE_2M_IDX_TBL,
2902 RATE_5M_IDX_TBL,
2903 RATE_11M_IDX_TBL,
2904 RATE_INVM_IDX_TBL = RATE_INVM_IDX - 1,
2905};
2906
2907enum {
2908 IL_FIRST_OFDM_RATE = RATE_6M_IDX,
2909 IL39_LAST_OFDM_RATE = RATE_54M_IDX,
2910 IL_LAST_OFDM_RATE = RATE_60M_IDX,
2911 IL_FIRST_CCK_RATE = RATE_1M_IDX,
2912 IL_LAST_CCK_RATE = RATE_11M_IDX,
2913};
2914
2915/* #define vs. enum to keep from defaulting to 'large integer' */
2916#define RATE_6M_MASK (1 << RATE_6M_IDX)
2917#define RATE_9M_MASK (1 << RATE_9M_IDX)
2918#define RATE_12M_MASK (1 << RATE_12M_IDX)
2919#define RATE_18M_MASK (1 << RATE_18M_IDX)
2920#define RATE_24M_MASK (1 << RATE_24M_IDX)
2921#define RATE_36M_MASK (1 << RATE_36M_IDX)
2922#define RATE_48M_MASK (1 << RATE_48M_IDX)
2923#define RATE_54M_MASK (1 << RATE_54M_IDX)
2924#define RATE_60M_MASK (1 << RATE_60M_IDX)
2925#define RATE_1M_MASK (1 << RATE_1M_IDX)
2926#define RATE_2M_MASK (1 << RATE_2M_IDX)
2927#define RATE_5M_MASK (1 << RATE_5M_IDX)
2928#define RATE_11M_MASK (1 << RATE_11M_IDX)
2929
2930/* uCode API values for legacy bit rates, both OFDM and CCK */
2931enum {
2932 RATE_6M_PLCP = 13,
2933 RATE_9M_PLCP = 15,
2934 RATE_12M_PLCP = 5,
2935 RATE_18M_PLCP = 7,
2936 RATE_24M_PLCP = 9,
2937 RATE_36M_PLCP = 11,
2938 RATE_48M_PLCP = 1,
2939 RATE_54M_PLCP = 3,
2940 RATE_60M_PLCP = 3,/*FIXME:RS:should be removed*/
2941 RATE_1M_PLCP = 10,
2942 RATE_2M_PLCP = 20,
2943 RATE_5M_PLCP = 55,
2944 RATE_11M_PLCP = 110,
2945 /*FIXME:RS:add RATE_LEGACY_INVM_PLCP = 0,*/
2946};
2947
2948/* uCode API values for OFDM high-throughput (HT) bit rates */
2949enum {
2950 RATE_SISO_6M_PLCP = 0,
2951 RATE_SISO_12M_PLCP = 1,
2952 RATE_SISO_18M_PLCP = 2,
2953 RATE_SISO_24M_PLCP = 3,
2954 RATE_SISO_36M_PLCP = 4,
2955 RATE_SISO_48M_PLCP = 5,
2956 RATE_SISO_54M_PLCP = 6,
2957 RATE_SISO_60M_PLCP = 7,
2958 RATE_MIMO2_6M_PLCP = 0x8,
2959 RATE_MIMO2_12M_PLCP = 0x9,
2960 RATE_MIMO2_18M_PLCP = 0xa,
2961 RATE_MIMO2_24M_PLCP = 0xb,
2962 RATE_MIMO2_36M_PLCP = 0xc,
2963 RATE_MIMO2_48M_PLCP = 0xd,
2964 RATE_MIMO2_54M_PLCP = 0xe,
2965 RATE_MIMO2_60M_PLCP = 0xf,
2966 RATE_SISO_INVM_PLCP,
2967 RATE_MIMO2_INVM_PLCP = RATE_SISO_INVM_PLCP,
2968};
2969
2970/* MAC header values for bit rates */
2971enum {
2972 RATE_6M_IEEE = 12,
2973 RATE_9M_IEEE = 18,
2974 RATE_12M_IEEE = 24,
2975 RATE_18M_IEEE = 36,
2976 RATE_24M_IEEE = 48,
2977 RATE_36M_IEEE = 72,
2978 RATE_48M_IEEE = 96,
2979 RATE_54M_IEEE = 108,
2980 RATE_60M_IEEE = 120,
2981 RATE_1M_IEEE = 2,
2982 RATE_2M_IEEE = 4,
2983 RATE_5M_IEEE = 11,
2984 RATE_11M_IEEE = 22,
2985};
2986
2987#define IL_CCK_BASIC_RATES_MASK \
2988 (RATE_1M_MASK | \
2989 RATE_2M_MASK)
2990
2991#define IL_CCK_RATES_MASK \
2992 (IL_CCK_BASIC_RATES_MASK | \
2993 RATE_5M_MASK | \
2994 RATE_11M_MASK)
2995
2996#define IL_OFDM_BASIC_RATES_MASK \
2997 (RATE_6M_MASK | \
2998 RATE_12M_MASK | \
2999 RATE_24M_MASK)
3000
3001#define IL_OFDM_RATES_MASK \
3002 (IL_OFDM_BASIC_RATES_MASK | \
3003 RATE_9M_MASK | \
3004 RATE_18M_MASK | \
3005 RATE_36M_MASK | \
3006 RATE_48M_MASK | \
3007 RATE_54M_MASK)
3008
3009#define IL_BASIC_RATES_MASK \
3010 (IL_OFDM_BASIC_RATES_MASK | \
3011 IL_CCK_BASIC_RATES_MASK)
3012
3013#define RATES_MASK ((1 << RATE_COUNT) - 1)
3014#define RATES_MASK_3945 ((1 << RATE_COUNT_3945) - 1)
3015
3016#define IL_INVALID_VALUE -1
3017
3018#define IL_MIN_RSSI_VAL -100
3019#define IL_MAX_RSSI_VAL 0
3020
3021/* These values specify how many Tx frame attempts before
3022 * searching for a new modulation mode */
3023#define IL_LEGACY_FAILURE_LIMIT 160
3024#define IL_LEGACY_SUCCESS_LIMIT 480
3025#define IL_LEGACY_TBL_COUNT 160
3026
3027#define IL_NONE_LEGACY_FAILURE_LIMIT 400
3028#define IL_NONE_LEGACY_SUCCESS_LIMIT 4500
3029#define IL_NONE_LEGACY_TBL_COUNT 1500
3030
3031/* Success ratio (ACKed / attempted tx frames) values (perfect is 128 * 100) */
3032#define IL_RS_GOOD_RATIO 12800 /* 100% */
3033#define RATE_SCALE_SWITCH 10880 /* 85% */
3034#define RATE_HIGH_TH 10880 /* 85% */
3035#define RATE_INCREASE_TH 6400 /* 50% */
3036#define RATE_DECREASE_TH 1920 /* 15% */
3037
3038/* possible actions when in legacy mode */
3039#define IL_LEGACY_SWITCH_ANTENNA1 0
3040#define IL_LEGACY_SWITCH_ANTENNA2 1
3041#define IL_LEGACY_SWITCH_SISO 2
3042#define IL_LEGACY_SWITCH_MIMO2_AB 3
3043#define IL_LEGACY_SWITCH_MIMO2_AC 4
3044#define IL_LEGACY_SWITCH_MIMO2_BC 5
3045
3046/* possible actions when in siso mode */
3047#define IL_SISO_SWITCH_ANTENNA1 0
3048#define IL_SISO_SWITCH_ANTENNA2 1
3049#define IL_SISO_SWITCH_MIMO2_AB 2
3050#define IL_SISO_SWITCH_MIMO2_AC 3
3051#define IL_SISO_SWITCH_MIMO2_BC 4
3052#define IL_SISO_SWITCH_GI 5
3053
3054/* possible actions when in mimo mode */
3055#define IL_MIMO2_SWITCH_ANTENNA1 0
3056#define IL_MIMO2_SWITCH_ANTENNA2 1
3057#define IL_MIMO2_SWITCH_SISO_A 2
3058#define IL_MIMO2_SWITCH_SISO_B 3
3059#define IL_MIMO2_SWITCH_SISO_C 4
3060#define IL_MIMO2_SWITCH_GI 5
3061
3062#define IL_MAX_SEARCH IL_MIMO2_SWITCH_GI
3063
3064#define IL_ACTION_LIMIT 3 /* # possible actions */
3065
3066#define LQ_SIZE 2 /* 2 mode tables: "Active" and "Search" */
3067
3068/* load per tid defines for A-MPDU activation */
3069#define IL_AGG_TPT_THREHOLD 0
3070#define IL_AGG_LOAD_THRESHOLD 10
3071#define IL_AGG_ALL_TID 0xff
3072#define TID_QUEUE_CELL_SPACING 50 /*mS */
3073#define TID_QUEUE_MAX_SIZE 20
3074#define TID_ROUND_VALUE 5 /* mS */
3075#define TID_MAX_LOAD_COUNT 8
3076
3077#define TID_MAX_TIME_DIFF ((TID_QUEUE_MAX_SIZE - 1) * TID_QUEUE_CELL_SPACING)
3078#define TIME_WRAP_AROUND(x, y) (((y) > (x)) ? (y) - (x) : (0-(x)) + (y))
3079
3080extern const struct il_rate_info il_rates[RATE_COUNT];
3081
3082enum il_table_type {
3083 LQ_NONE,
3084 LQ_G, /* legacy types */
3085 LQ_A,
3086 LQ_SISO, /* high-throughput types */
3087 LQ_MIMO2,
3088 LQ_MAX,
3089};
3090
3091#define is_legacy(tbl) ((tbl) == LQ_G || (tbl) == LQ_A)
3092#define is_siso(tbl) ((tbl) == LQ_SISO)
3093#define is_mimo2(tbl) ((tbl) == LQ_MIMO2)
3094#define is_mimo(tbl) (is_mimo2(tbl))
3095#define is_Ht(tbl) (is_siso(tbl) || is_mimo(tbl))
3096#define is_a_band(tbl) ((tbl) == LQ_A)
3097#define is_g_and(tbl) ((tbl) == LQ_G)
3098
3099#define ANT_NONE 0x0
3100#define ANT_A BIT(0)
3101#define ANT_B BIT(1)
3102#define ANT_AB (ANT_A | ANT_B)
3103#define ANT_C BIT(2)
3104#define ANT_AC (ANT_A | ANT_C)
3105#define ANT_BC (ANT_B | ANT_C)
3106#define ANT_ABC (ANT_AB | ANT_C)
3107
3108#define IL_MAX_MCS_DISPLAY_SIZE 12
3109
3110struct il_rate_mcs_info {
3111 char mbps[IL_MAX_MCS_DISPLAY_SIZE];
3112 char mcs[IL_MAX_MCS_DISPLAY_SIZE];
3113};
3114
3115/**
3116 * struct il_rate_scale_data -- tx success history for one rate
3117 */
3118struct il_rate_scale_data {
3119 u64 data; /* bitmap of successful frames */
3120 s32 success_counter; /* number of frames successful */
3121 s32 success_ratio; /* per-cent * 128 */
3122 s32 counter; /* number of frames attempted */
3123 s32 average_tpt; /* success ratio * expected throughput */
3124 unsigned long stamp;
3125};
3126
3127/**
3128 * struct il_scale_tbl_info -- tx params and success history for all rates
3129 *
3130 * There are two of these in struct il_lq_sta,
3131 * one for "active", and one for "search".
3132 */
3133struct il_scale_tbl_info {
3134 enum il_table_type lq_type;
3135 u8 ant_type;
3136 u8 is_SGI; /* 1 = short guard interval */
3137 u8 is_ht40; /* 1 = 40 MHz channel width */
3138 u8 is_dup; /* 1 = duplicated data streams */
3139 u8 action; /* change modulation; IL_[LEGACY/SISO/MIMO]_SWITCH_* */
3140 u8 max_search; /* maximun number of tables we can search */
3141 s32 *expected_tpt; /* throughput metrics; expected_tpt_G, etc. */
3142 u32 current_rate; /* rate_n_flags, uCode API format */
3143 struct il_rate_scale_data win[RATE_COUNT]; /* rate histories */
3144};
3145
3146struct il_traffic_load {
3147 unsigned long time_stamp; /* age of the oldest stats */
3148 u32 packet_count[TID_QUEUE_MAX_SIZE]; /* packet count in this time
3149 * slice */
3150 u32 total; /* total num of packets during the
3151 * last TID_MAX_TIME_DIFF */
3152 u8 queue_count; /* number of queues that has
3153 * been used since the last cleanup */
3154 u8 head; /* start of the circular buffer */
3155};
3156
3157/**
3158 * struct il_lq_sta -- driver's rate scaling ilate structure
3159 *
3160 * Pointer to this gets passed back and forth between driver and mac80211.
3161 */
3162struct il_lq_sta {
3163 u8 active_tbl; /* idx of active table, range 0-1 */
3164 u8 enable_counter; /* indicates HT mode */
3165 u8 stay_in_tbl; /* 1: disallow, 0: allow search for new mode */
3166 u8 search_better_tbl; /* 1: currently trying alternate mode */
3167 s32 last_tpt;
3168
3169 /* The following determine when to search for a new mode */
3170 u32 table_count_limit;
3171 u32 max_failure_limit; /* # failed frames before new search */
3172 u32 max_success_limit; /* # successful frames before new search */
3173 u32 table_count;
3174 u32 total_failed; /* total failed frames, any/all rates */
3175 u32 total_success; /* total successful frames, any/all rates */
3176 u64 flush_timer; /* time staying in mode before new search */
3177
3178 u8 action_counter; /* # mode-switch actions tried */
3179 u8 is_green;
3180 u8 is_dup;
3181 enum ieee80211_band band;
3182
3183 /* The following are bitmaps of rates; RATE_6M_MASK, etc. */
3184 u32 supp_rates;
3185 u16 active_legacy_rate;
3186 u16 active_siso_rate;
3187 u16 active_mimo2_rate;
3188 s8 max_rate_idx; /* Max rate set by user */
3189 u8 missed_rate_counter;
3190
3191 struct il_link_quality_cmd lq;
3192 struct il_scale_tbl_info lq_info[LQ_SIZE]; /* "active", "search" */
3193 struct il_traffic_load load[TID_MAX_LOAD_COUNT];
3194 u8 tx_agg_tid_en;
3195#ifdef CONFIG_MAC80211_DEBUGFS
3196 struct dentry *rs_sta_dbgfs_scale_table_file;
3197 struct dentry *rs_sta_dbgfs_stats_table_file;
3198 struct dentry *rs_sta_dbgfs_rate_scale_data_file;
3199 struct dentry *rs_sta_dbgfs_tx_agg_tid_en_file;
3200 u32 dbg_fixed_rate;
3201#endif
3202 struct il_priv *drv;
3203
3204 /* used to be in sta_info */
3205 int last_txrate_idx;
3206 /* last tx rate_n_flags */
3207 u32 last_rate_n_flags;
3208 /* packets destined for this STA are aggregated */
3209 u8 is_agg;
3210};
3211
3212/*
3213 * il_station_priv: Driver's ilate station information
3214 *
3215 * When mac80211 creates a station it reserves some space (hw->sta_data_size)
3216 * in the structure for use by driver. This structure is places in that
3217 * space.
3218 *
3219 * The common struct MUST be first because it is shared between
3220 * 3945 and 4965!
3221 */
3222struct il_station_priv {
3223 struct il_station_priv_common common;
3224 struct il_lq_sta lq_sta;
3225 atomic_t pending_frames;
3226 bool client;
3227 bool asleep;
3228};
3229
3230static inline u8 il4965_num_of_ant(u8 m)
3231{
3232 return !!(m & ANT_A) + !!(m & ANT_B) + !!(m & ANT_C);
3233}
3234
3235static inline u8 il4965_first_antenna(u8 mask)
3236{
3237 if (mask & ANT_A)
3238 return ANT_A;
3239 if (mask & ANT_B)
3240 return ANT_B;
3241 return ANT_C;
3242}
3243
3244
3245/**
3246 * il3945_rate_scale_init - Initialize the rate scale table based on assoc info
3247 *
3248 * The specific throughput table used is based on the type of network
3249 * the associated with, including A, B, G, and G w/ TGG protection
3250 */
3251extern void il3945_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id);
3252
3253/* Initialize station's rate scaling information after adding station */
3254extern void il4965_rs_rate_init(struct il_priv *il,
3255 struct ieee80211_sta *sta, u8 sta_id);
3256extern void il3945_rs_rate_init(struct il_priv *il,
3257 struct ieee80211_sta *sta, u8 sta_id);
3258
3259/**
3260 * il_rate_control_register - Register the rate control algorithm callbacks
3261 *
3262 * Since the rate control algorithm is hardware specific, there is no need
3263 * or reason to place it as a stand alone module. The driver can call
3264 * il_rate_control_register in order to register the rate control callbacks
3265 * with the mac80211 subsystem. This should be performed prior to calling
3266 * ieee80211_register_hw
3267 *
3268 */
3269extern int il4965_rate_control_register(void);
3270extern int il3945_rate_control_register(void);
3271
3272/**
3273 * il_rate_control_unregister - Unregister the rate control callbacks
3274 *
3275 * This should be called after calling ieee80211_unregister_hw, but before
3276 * the driver is unloaded.
3277 */
3278extern void il4965_rate_control_unregister(void);
3279extern void il3945_rate_control_unregister(void);
3280
Stanislaw Gruszka99412002011-08-31 13:53:04 +02003281extern int il_power_update_mode(struct il_priv *il, bool force);
3282extern void il_power_initialize(struct il_priv *il);
Stanislaw Gruszka47ef6942011-08-31 14:04:45 +02003283
Stanislaw Gruszkaf02579e2011-08-31 14:49:56 +02003284extern u32 il_debug_level;
3285
3286#ifdef CONFIG_IWLEGACY_DEBUG
3287/*
3288 * il_get_debug_level: Return active debug level for device
3289 *
3290 * Using sysfs it is possible to set per device debug level. This debug
3291 * level will be used if set, otherwise the global debug level which can be
3292 * set via module parameter is used.
3293 */
3294static inline u32 il_get_debug_level(struct il_priv *il)
3295{
3296 if (il->debug_level)
3297 return il->debug_level;
3298 else
3299 return il_debug_level;
3300}
3301#else
3302static inline u32 il_get_debug_level(struct il_priv *il)
3303{
3304 return il_debug_level;
3305}
3306#endif
3307
3308#define il_print_hex_error(il, p, len) \
3309do { \
3310 print_hex_dump(KERN_ERR, "iwl data: ", \
3311 DUMP_PREFIX_OFFSET, 16, 1, p, len, 1); \
3312} while (0)
3313
3314#ifdef CONFIG_IWLEGACY_DEBUG
3315#define IL_DBG(level, fmt, args...) \
3316do { \
3317 if (il_get_debug_level(il) & level) \
3318 dev_printk(KERN_ERR, &il->hw->wiphy->dev, \
3319 "%c %s " fmt, in_interrupt() ? 'I' : 'U', \
3320 __func__ , ## args); \
3321} while (0)
3322
3323#define il_print_hex_dump(il, level, p, len) \
3324do { \
3325 if (il_get_debug_level(il) & level) \
3326 print_hex_dump(KERN_DEBUG, "iwl data: ", \
3327 DUMP_PREFIX_OFFSET, 16, 1, p, len, 1); \
3328} while (0)
3329
3330#else
3331#define IL_DBG(level, fmt, args...)
3332static inline void il_print_hex_dump(struct il_priv *il, int level,
3333 const void *p, u32 len)
3334{}
3335#endif /* CONFIG_IWLEGACY_DEBUG */
3336
3337#ifdef CONFIG_IWLEGACY_DEBUGFS
3338int il_dbgfs_register(struct il_priv *il, const char *name);
3339void il_dbgfs_unregister(struct il_priv *il);
3340#else
3341static inline int
3342il_dbgfs_register(struct il_priv *il, const char *name)
3343{
3344 return 0;
3345}
3346static inline void il_dbgfs_unregister(struct il_priv *il)
3347{
3348}
3349#endif /* CONFIG_IWLEGACY_DEBUGFS */
3350
3351/*
3352 * To use the debug system:
3353 *
3354 * If you are defining a new debug classification, simply add it to the #define
3355 * list here in the form of
3356 *
3357 * #define IL_DL_xxxx VALUE
3358 *
3359 * where xxxx should be the name of the classification (for example, WEP).
3360 *
3361 * You then need to either add a IL_xxxx_DEBUG() macro definition for your
3362 * classification, or use IL_DBG(IL_DL_xxxx, ...) whenever you want
3363 * to send output to that classification.
3364 *
3365 * The active debug levels can be accessed via files
3366 *
3367 * /sys/module/iwl4965/parameters/debug
3368 * /sys/module/iwl3945/parameters/debug
3369 * /sys/class/net/wlan0/device/debug_level
3370 *
3371 * when CONFIG_IWLEGACY_DEBUG=y.
3372 */
3373
3374/* 0x0000000F - 0x00000001 */
3375#define IL_DL_INFO (1 << 0)
3376#define IL_DL_MAC80211 (1 << 1)
3377#define IL_DL_HCMD (1 << 2)
3378#define IL_DL_STATE (1 << 3)
3379/* 0x000000F0 - 0x00000010 */
3380#define IL_DL_MACDUMP (1 << 4)
3381#define IL_DL_HCMD_DUMP (1 << 5)
3382#define IL_DL_EEPROM (1 << 6)
3383#define IL_DL_RADIO (1 << 7)
3384/* 0x00000F00 - 0x00000100 */
3385#define IL_DL_POWER (1 << 8)
3386#define IL_DL_TEMP (1 << 9)
3387#define IL_DL_NOTIF (1 << 10)
3388#define IL_DL_SCAN (1 << 11)
3389/* 0x0000F000 - 0x00001000 */
3390#define IL_DL_ASSOC (1 << 12)
3391#define IL_DL_DROP (1 << 13)
3392#define IL_DL_TXPOWER (1 << 14)
3393#define IL_DL_AP (1 << 15)
3394/* 0x000F0000 - 0x00010000 */
3395#define IL_DL_FW (1 << 16)
3396#define IL_DL_RF_KILL (1 << 17)
3397#define IL_DL_FW_ERRORS (1 << 18)
3398#define IL_DL_LED (1 << 19)
3399/* 0x00F00000 - 0x00100000 */
3400#define IL_DL_RATE (1 << 20)
3401#define IL_DL_CALIB (1 << 21)
3402#define IL_DL_WEP (1 << 22)
3403#define IL_DL_TX (1 << 23)
3404/* 0x0F000000 - 0x01000000 */
3405#define IL_DL_RX (1 << 24)
3406#define IL_DL_ISR (1 << 25)
3407#define IL_DL_HT (1 << 26)
3408/* 0xF0000000 - 0x10000000 */
3409#define IL_DL_11H (1 << 28)
3410#define IL_DL_STATS (1 << 29)
3411#define IL_DL_TX_REPLY (1 << 30)
3412#define IL_DL_QOS (1 << 31)
3413
3414#define D_INFO(f, a...) IL_DBG(IL_DL_INFO, f, ## a)
3415#define D_MAC80211(f, a...) IL_DBG(IL_DL_MAC80211, f, ## a)
3416#define D_MACDUMP(f, a...) IL_DBG(IL_DL_MACDUMP, f, ## a)
3417#define D_TEMP(f, a...) IL_DBG(IL_DL_TEMP, f, ## a)
3418#define D_SCAN(f, a...) IL_DBG(IL_DL_SCAN, f, ## a)
3419#define D_RX(f, a...) IL_DBG(IL_DL_RX, f, ## a)
3420#define D_TX(f, a...) IL_DBG(IL_DL_TX, f, ## a)
3421#define D_ISR(f, a...) IL_DBG(IL_DL_ISR, f, ## a)
3422#define D_LED(f, a...) IL_DBG(IL_DL_LED, f, ## a)
3423#define D_WEP(f, a...) IL_DBG(IL_DL_WEP, f, ## a)
3424#define D_HC(f, a...) IL_DBG(IL_DL_HCMD, f, ## a)
3425#define D_HC_DUMP(f, a...) IL_DBG(IL_DL_HCMD_DUMP, f, ## a)
3426#define D_EEPROM(f, a...) IL_DBG(IL_DL_EEPROM, f, ## a)
3427#define D_CALIB(f, a...) IL_DBG(IL_DL_CALIB, f, ## a)
3428#define D_FW(f, a...) IL_DBG(IL_DL_FW, f, ## a)
3429#define D_RF_KILL(f, a...) IL_DBG(IL_DL_RF_KILL, f, ## a)
3430#define D_DROP(f, a...) IL_DBG(IL_DL_DROP, f, ## a)
3431#define D_AP(f, a...) IL_DBG(IL_DL_AP, f, ## a)
3432#define D_TXPOWER(f, a...) IL_DBG(IL_DL_TXPOWER, f, ## a)
3433#define D_RATE(f, a...) IL_DBG(IL_DL_RATE, f, ## a)
3434#define D_NOTIF(f, a...) IL_DBG(IL_DL_NOTIF, f, ## a)
3435#define D_ASSOC(f, a...) IL_DBG(IL_DL_ASSOC, f, ## a)
3436#define D_HT(f, a...) IL_DBG(IL_DL_HT, f, ## a)
3437#define D_STATS(f, a...) IL_DBG(IL_DL_STATS, f, ## a)
3438#define D_TX_REPLY(f, a...) IL_DBG(IL_DL_TX_REPLY, f, ## a)
3439#define D_QOS(f, a...) IL_DBG(IL_DL_QOS, f, ## a)
3440#define D_RADIO(f, a...) IL_DBG(IL_DL_RADIO, f, ## a)
3441#define D_POWER(f, a...) IL_DBG(IL_DL_POWER, f, ## a)
3442#define D_11H(f, a...) IL_DBG(IL_DL_11H, f, ## a)
3443
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02003444#endif /* __il_core_h__ */