blob: 10d0b13e0e3c3908f2dc1dbe5dde5976507e4ee7 [file] [log] [blame]
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08001/******************************************************************************
2 *
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08003 * GPL LICENSE SUMMARY
4 *
Stanislaw Gruszkaaf038f42011-08-30 13:58:27 +02005 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -08006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
19 * USA
20 *
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
23 *
24 * Contact Information:
25 * Intel Linux Wireless <ilw@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -080028 *****************************************************************************/
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -080029
Stanislaw Gruszkaaf038f42011-08-30 13:58:27 +020030#ifndef __il_4965_h__
31#define __il_4965_h__
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -080032
Stanislaw Gruszkaaf038f42011-08-30 13:58:27 +020033#include "iwl-debug.h"
34
35struct il_rx_queue;
36struct il_rx_buf;
37struct il_rx_pkt;
38struct il_tx_queue;
39struct il_rxon_context;
40
41/* configuration for the _4965 devices */
42extern struct il_cfg il4965_cfg;
43
44extern struct il_mod_params il4965_mod_params;
45
46extern struct ieee80211_ops il4965_hw_ops;
47
48/* tx queue */
49void il4965_free_tfds_in_queue(struct il_priv *il,
50 int sta_id, int tid, int freed);
51
52/* RXON */
53void il4965_set_rxon_chain(struct il_priv *il,
54 struct il_rxon_context *ctx);
55
56/* uCode */
57int il4965_verify_ucode(struct il_priv *il);
58
59/* lib */
60void il4965_check_abort_status(struct il_priv *il,
61 u8 frame_count, u32 status);
62
63void il4965_rx_queue_reset(struct il_priv *il, struct il_rx_queue *rxq);
64int il4965_rx_init(struct il_priv *il, struct il_rx_queue *rxq);
65int il4965_hw_nic_init(struct il_priv *il);
66int il4965_dump_fh(struct il_priv *il, char **buf, bool display);
67
68/* rx */
69void il4965_rx_queue_restock(struct il_priv *il);
70void il4965_rx_replenish(struct il_priv *il);
71void il4965_rx_replenish_now(struct il_priv *il);
72void il4965_rx_queue_free(struct il_priv *il, struct il_rx_queue *rxq);
73int il4965_rxq_stop(struct il_priv *il);
74int il4965_hwrate_to_mac80211_idx(u32 rate_n_flags, enum ieee80211_band band);
Stanislaw Gruszka6e9848b42011-08-30 15:45:31 +020075void il4965_hdl_rx(struct il_priv *il,
Stanislaw Gruszkaaf038f42011-08-30 13:58:27 +020076 struct il_rx_buf *rxb);
Stanislaw Gruszka6e9848b42011-08-30 15:45:31 +020077void il4965_hdl_rx_phy(struct il_priv *il,
Stanislaw Gruszkaaf038f42011-08-30 13:58:27 +020078 struct il_rx_buf *rxb);
79void il4965_rx_handle(struct il_priv *il);
80
81/* tx */
82void il4965_hw_txq_free_tfd(struct il_priv *il, struct il_tx_queue *txq);
83int il4965_hw_txq_attach_buf_to_tfd(struct il_priv *il,
84 struct il_tx_queue *txq,
85 dma_addr_t addr, u16 len, u8 reset, u8 pad);
86int il4965_hw_tx_queue_init(struct il_priv *il,
87 struct il_tx_queue *txq);
88void il4965_hwrate_to_tx_control(struct il_priv *il, u32 rate_n_flags,
89 struct ieee80211_tx_info *info);
90int il4965_tx_skb(struct il_priv *il, struct sk_buff *skb);
91int il4965_tx_agg_start(struct il_priv *il, struct ieee80211_vif *vif,
92 struct ieee80211_sta *sta, u16 tid, u16 *ssn);
93int il4965_tx_agg_stop(struct il_priv *il, struct ieee80211_vif *vif,
94 struct ieee80211_sta *sta, u16 tid);
95int il4965_txq_check_empty(struct il_priv *il,
96 int sta_id, u8 tid, int txq_id);
Stanislaw Gruszka6e9848b42011-08-30 15:45:31 +020097void il4965_hdl_compressed_ba(struct il_priv *il,
Stanislaw Gruszkaaf038f42011-08-30 13:58:27 +020098 struct il_rx_buf *rxb);
99int il4965_tx_queue_reclaim(struct il_priv *il, int txq_id, int idx);
100void il4965_hw_txq_ctx_free(struct il_priv *il);
101int il4965_txq_ctx_alloc(struct il_priv *il);
102void il4965_txq_ctx_reset(struct il_priv *il);
103void il4965_txq_ctx_stop(struct il_priv *il);
104void il4965_txq_set_sched(struct il_priv *il, u32 mask);
105
106/*
107 * Acquire il->lock before calling this function !
108 */
109void il4965_set_wr_ptrs(struct il_priv *il, int txq_id, u32 idx);
110/**
111 * il4965_tx_queue_set_status - (optionally) start Tx/Cmd queue
112 * @tx_fifo_id: Tx DMA/FIFO channel (range 0-7) that the queue will feed
113 * @scd_retry: (1) Indicates queue will be used in aggregation mode
114 *
115 * NOTE: Acquire il->lock before calling this function !
116 */
117void il4965_tx_queue_set_status(struct il_priv *il,
118 struct il_tx_queue *txq,
119 int tx_fifo_id, int scd_retry);
120
121u8 il4965_toggle_tx_ant(struct il_priv *il, u8 ant_idx, u8 valid);
122
123/* rx */
Stanislaw Gruszkad2dfb332011-11-15 13:16:38 +0100124void il4965_hdl_missed_beacon(struct il_priv *il,
Stanislaw Gruszkaaf038f42011-08-30 13:58:27 +0200125 struct il_rx_buf *rxb);
126bool il4965_good_plcp_health(struct il_priv *il,
127 struct il_rx_pkt *pkt);
Stanislaw Gruszkad2dfb332011-11-15 13:16:38 +0100128void il4965_hdl_stats(struct il_priv *il,
Stanislaw Gruszkaaf038f42011-08-30 13:58:27 +0200129 struct il_rx_buf *rxb);
Stanislaw Gruszkad2dfb332011-11-15 13:16:38 +0100130void il4965_hdl_c_stats(struct il_priv *il,
Stanislaw Gruszkaaf038f42011-08-30 13:58:27 +0200131 struct il_rx_buf *rxb);
132
133/* scan */
134int il4965_request_scan(struct il_priv *il, struct ieee80211_vif *vif);
135
136/* station mgmt */
137int il4965_manage_ibss_station(struct il_priv *il,
138 struct ieee80211_vif *vif, bool add);
139
140/* hcmd */
141int il4965_send_beacon_cmd(struct il_priv *il);
142
143#ifdef CONFIG_IWLEGACY_DEBUG
144const char *il4965_get_tx_fail_reason(u32 status);
145#else
146static inline const char *
147il4965_get_tx_fail_reason(u32 status) { return ""; }
148#endif
149
150/* station management */
151int il4965_alloc_bcast_station(struct il_priv *il,
152 struct il_rxon_context *ctx);
153int il4965_add_bssid_station(struct il_priv *il,
154 struct il_rxon_context *ctx,
155 const u8 *addr, u8 *sta_id_r);
156int il4965_remove_default_wep_key(struct il_priv *il,
157 struct il_rxon_context *ctx,
158 struct ieee80211_key_conf *key);
159int il4965_set_default_wep_key(struct il_priv *il,
160 struct il_rxon_context *ctx,
161 struct ieee80211_key_conf *key);
162int il4965_restore_default_wep_keys(struct il_priv *il,
163 struct il_rxon_context *ctx);
164int il4965_set_dynamic_key(struct il_priv *il,
165 struct il_rxon_context *ctx,
166 struct ieee80211_key_conf *key, u8 sta_id);
167int il4965_remove_dynamic_key(struct il_priv *il,
168 struct il_rxon_context *ctx,
169 struct ieee80211_key_conf *key, u8 sta_id);
170void il4965_update_tkip_key(struct il_priv *il,
171 struct il_rxon_context *ctx,
172 struct ieee80211_key_conf *keyconf,
173 struct ieee80211_sta *sta, u32 iv32, u16 *phase1key);
174int il4965_sta_tx_modify_enable_tid(struct il_priv *il,
175 int sta_id, int tid);
176int il4965_sta_rx_agg_start(struct il_priv *il, struct ieee80211_sta *sta,
177 int tid, u16 ssn);
178int il4965_sta_rx_agg_stop(struct il_priv *il, struct ieee80211_sta *sta,
179 int tid);
180void il4965_sta_modify_sleep_tx_count(struct il_priv *il,
181 int sta_id, int cnt);
182int il4965_update_bcast_stations(struct il_priv *il);
183
184/* rate */
185static inline u8 il4965_hw_get_rate(__le32 rate_n_flags)
186{
187 return le32_to_cpu(rate_n_flags) & 0xFF;
188}
189
190static inline __le32 il4965_hw_set_rate_n_flags(u8 rate, u32 flags)
191{
192 return cpu_to_le32(flags|(u32)rate);
193}
194
195/* eeprom */
196void il4965_eeprom_get_mac(const struct il_priv *il, u8 *mac);
197int il4965_eeprom_acquire_semaphore(struct il_priv *il);
198void il4965_eeprom_release_semaphore(struct il_priv *il);
199int il4965_eeprom_check_version(struct il_priv *il);
200
201/* mac80211 handlers (for 4965) */
202void il4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
203int il4965_mac_start(struct ieee80211_hw *hw);
204void il4965_mac_stop(struct ieee80211_hw *hw);
205void il4965_configure_filter(struct ieee80211_hw *hw,
206 unsigned int changed_flags,
207 unsigned int *total_flags,
208 u64 multicast);
209int il4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
210 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
211 struct ieee80211_key_conf *key);
212void il4965_mac_update_tkip_key(struct ieee80211_hw *hw,
213 struct ieee80211_vif *vif,
214 struct ieee80211_key_conf *keyconf,
215 struct ieee80211_sta *sta,
216 u32 iv32, u16 *phase1key);
217int il4965_mac_ampdu_action(struct ieee80211_hw *hw,
218 struct ieee80211_vif *vif,
219 enum ieee80211_ampdu_mlme_action action,
220 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
221 u8 buf_size);
222int il4965_mac_sta_add(struct ieee80211_hw *hw,
223 struct ieee80211_vif *vif,
224 struct ieee80211_sta *sta);
225void il4965_mac_channel_switch(struct ieee80211_hw *hw,
226 struct ieee80211_channel_switch *ch_switch);
227
228void il4965_led_enable(struct il_priv *il);
229
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800230
231/* EEPROM */
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100232#define IL4965_EEPROM_IMG_SIZE 1024
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800233
234/*
235 * uCode queue management definitions ...
236 * The first queue used for block-ack aggregation is #7 (4965 only).
237 * All block-ack aggregation queues should map to Tx DMA/FIFO channel 7.
238 */
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100239#define IL49_FIRST_AMPDU_QUEUE 7
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800240
241/* Sizes and addresses for instruction and data memory (SRAM) in
242 * 4965's embedded processor. Driver access is via HBUS_TARG_MEM_* regs. */
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100243#define IL49_RTC_INST_LOWER_BOUND (0x000000)
244#define IL49_RTC_INST_UPPER_BOUND (0x018000)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800245
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100246#define IL49_RTC_DATA_LOWER_BOUND (0x800000)
247#define IL49_RTC_DATA_UPPER_BOUND (0x80A000)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800248
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100249#define IL49_RTC_INST_SIZE (IL49_RTC_INST_UPPER_BOUND - \
250 IL49_RTC_INST_LOWER_BOUND)
251#define IL49_RTC_DATA_SIZE (IL49_RTC_DATA_UPPER_BOUND - \
252 IL49_RTC_DATA_LOWER_BOUND)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800253
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100254#define IL49_MAX_INST_SIZE IL49_RTC_INST_SIZE
255#define IL49_MAX_DATA_SIZE IL49_RTC_DATA_SIZE
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800256
257/* Size of uCode instruction memory in bootstrap state machine */
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100258#define IL49_MAX_BSM_SIZE BSM_SRAM_SIZE
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800259
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200260static inline int il4965_hw_valid_rtc_data_addr(u32 addr)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800261{
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100262 return (addr >= IL49_RTC_DATA_LOWER_BOUND &&
263 addr < IL49_RTC_DATA_UPPER_BOUND);
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800264}
265
266/********************* START TEMPERATURE *************************************/
267
268/**
269 * 4965 temperature calculation.
270 *
271 * The driver must calculate the device temperature before calculating
272 * a txpower setting (amplifier gain is temperature dependent). The
273 * calculation uses 4 measurements, 3 of which (R1, R2, R3) are calibration
274 * values used for the life of the driver, and one of which (R4) is the
275 * real-time temperature indicator.
276 *
277 * uCode provides all 4 values to the driver via the "initialize alive"
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200278 * notification (see struct il4965_init_alive_resp). After the runtime uCode
Stanislaw Gruszkaebf0d902011-08-26 15:43:47 +0200279 * image loads, uCode updates the R4 value via stats notifications
Stanislaw Gruszka4d69c752011-08-30 15:26:35 +0200280 * (see N_STATS), which occur after each received beacon
281 * when associated, or can be requested via C_STATS.
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800282 *
283 * NOTE: uCode provides the R4 value as a 23-bit signed value. Driver
284 * must sign-extend to 32 bits before applying formula below.
285 *
286 * Formula:
287 *
288 * degrees Kelvin = ((97 * 259 * (R4 - R2) / (R3 - R1)) / 100) + 8
289 *
290 * NOTE: The basic formula is 259 * (R4-R2) / (R3-R1). The 97/100 is
291 * an additional correction, which should be centered around 0 degrees
292 * Celsius (273 degrees Kelvin). The 8 (3 percent of 273) compensates for
293 * centering the 97/100 correction around 0 degrees K.
294 *
295 * Add 273 to Kelvin value to find degrees Celsius, for comparing current
296 * temperature with factory-measured temperatures when calculating txpower
297 * settings.
298 */
299#define TEMPERATURE_CALIB_KELVIN_OFFSET 8
300#define TEMPERATURE_CALIB_A_VAL 259
301
302/* Limit range of calculated temperature to be between these Kelvin values */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200303#define IL_TX_POWER_TEMPERATURE_MIN (263)
304#define IL_TX_POWER_TEMPERATURE_MAX (410)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800305
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200306#define IL_TX_POWER_TEMPERATURE_OUT_OF_RANGE(t) \
Stanislaw Gruszka232913b2011-08-26 10:45:16 +0200307 ((t) < IL_TX_POWER_TEMPERATURE_MIN || \
308 (t) > IL_TX_POWER_TEMPERATURE_MAX)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800309
310/********************* END TEMPERATURE ***************************************/
311
312/********************* START TXPOWER *****************************************/
313
314/**
315 * 4965 txpower calculations rely on information from three sources:
316 *
317 * 1) EEPROM
318 * 2) "initialize" alive notification
Stanislaw Gruszkaebf0d902011-08-26 15:43:47 +0200319 * 3) stats notifications
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800320 *
321 * EEPROM data consists of:
322 *
323 * 1) Regulatory information (max txpower and channel usage flags) is provided
324 * separately for each channel that can possibly supported by 4965.
325 * 40 MHz wide (.11n HT40) channels are listed separately from 20 MHz
326 * (legacy) channels.
327 *
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200328 * See struct il4965_eeprom_channel for format, and struct il4965_eeprom
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800329 * for locations in EEPROM.
330 *
331 * 2) Factory txpower calibration information is provided separately for
332 * sub-bands of contiguous channels. 2.4GHz has just one sub-band,
333 * but 5 GHz has several sub-bands.
334 *
335 * In addition, per-band (2.4 and 5 Ghz) saturation txpowers are provided.
336 *
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200337 * See struct il4965_eeprom_calib_info (and the tree of structures
338 * contained within it) for format, and struct il4965_eeprom for
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800339 * locations in EEPROM.
340 *
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200341 * "Initialization alive" notification (see struct il4965_init_alive_resp)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800342 * consists of:
343 *
344 * 1) Temperature calculation parameters.
345 *
346 * 2) Power supply voltage measurement.
347 *
348 * 3) Tx gain compensation to balance 2 transmitters for MIMO use.
349 *
350 * Statistics notifications deliver:
351 *
352 * 1) Current values for temperature param R4.
353 */
354
355/**
356 * To calculate a txpower setting for a given desired target txpower, channel,
357 * modulation bit rate, and transmitter chain (4965 has 2 transmitters to
358 * support MIMO and transmit diversity), driver must do the following:
359 *
360 * 1) Compare desired txpower vs. (EEPROM) regulatory limit for this channel.
361 * Do not exceed regulatory limit; reduce target txpower if necessary.
362 *
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100363 * If setting up txpowers for MIMO rates (rate idxes 8-15, 24-31),
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800364 * 2 transmitters will be used simultaneously; driver must reduce the
365 * regulatory limit by 3 dB (half-power) for each transmitter, so the
366 * combined total output of the 2 transmitters is within regulatory limits.
367 *
368 *
369 * 2) Compare target txpower vs. (EEPROM) saturation txpower *reduced by
370 * backoff for this bit rate*. Do not exceed (saturation - backoff[rate]);
371 * reduce target txpower if necessary.
372 *
373 * Backoff values below are in 1/2 dB units (equivalent to steps in
374 * txpower gain tables):
375 *
376 * OFDM 6 - 36 MBit: 10 steps (5 dB)
377 * OFDM 48 MBit: 15 steps (7.5 dB)
378 * OFDM 54 MBit: 17 steps (8.5 dB)
379 * OFDM 60 MBit: 20 steps (10 dB)
380 * CCK all rates: 10 steps (5 dB)
381 *
382 * Backoff values apply to saturation txpower on a per-transmitter basis;
383 * when using MIMO (2 transmitters), each transmitter uses the same
384 * saturation level provided in EEPROM, and the same backoff values;
385 * no reduction (such as with regulatory txpower limits) is required.
386 *
387 * Saturation and Backoff values apply equally to 20 Mhz (legacy) channel
388 * widths and 40 Mhz (.11n HT40) channel widths; there is no separate
389 * factory measurement for ht40 channels.
390 *
391 * The result of this step is the final target txpower. The rest of
392 * the steps figure out the proper settings for the device to achieve
393 * that target txpower.
394 *
395 *
396 * 3) Determine (EEPROM) calibration sub band for the target channel, by
397 * comparing against first and last channels in each sub band
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200398 * (see struct il4965_eeprom_calib_subband_info).
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800399 *
400 *
401 * 4) Linearly interpolate (EEPROM) factory calibration measurement sets,
402 * referencing the 2 factory-measured (sample) channels within the sub band.
403 *
404 * Interpolation is based on difference between target channel's frequency
405 * and the sample channels' frequencies. Since channel numbers are based
406 * on frequency (5 MHz between each channel number), this is equivalent
407 * to interpolating based on channel number differences.
408 *
409 * Note that the sample channels may or may not be the channels at the
410 * edges of the sub band. The target channel may be "outside" of the
411 * span of the sampled channels.
412 *
413 * Driver may choose the pair (for 2 Tx chains) of measurements (see
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200414 * struct il4965_eeprom_calib_ch_info) for which the actual measured
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800415 * txpower comes closest to the desired txpower. Usually, though,
416 * the middle set of measurements is closest to the regulatory limits,
417 * and is therefore a good choice for all txpower calculations (this
418 * assumes that high accuracy is needed for maximizing legal txpower,
419 * while lower txpower configurations do not need as much accuracy).
420 *
421 * Driver should interpolate both members of the chosen measurement pair,
422 * i.e. for both Tx chains (radio transmitters), unless the driver knows
423 * that only one of the chains will be used (e.g. only one tx antenna
424 * connected, but this should be unusual). The rate scaling algorithm
425 * switches antennas to find best performance, so both Tx chains will
426 * be used (although only one at a time) even for non-MIMO transmissions.
427 *
428 * Driver should interpolate factory values for temperature, gain table
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100429 * idx, and actual power. The power amplifier detector values are
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800430 * not used by the driver.
431 *
432 * Sanity check: If the target channel happens to be one of the sample
433 * channels, the results should agree with the sample channel's
434 * measurements!
435 *
436 *
437 * 5) Find difference between desired txpower and (interpolated)
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100438 * factory-measured txpower. Using (interpolated) factory gain table idx
439 * (shown elsewhere) as a starting point, adjust this idx lower to
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800440 * increase txpower, or higher to decrease txpower, until the target
441 * txpower is reached. Each step in the gain table is 1/2 dB.
442 *
443 * For example, if factory measured txpower is 16 dBm, and target txpower
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100444 * is 13 dBm, add 6 steps to the factory gain idx to reduce txpower
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800445 * by 3 dB.
446 *
447 *
448 * 6) Find difference between current device temperature and (interpolated)
449 * factory-measured temperature for sub-band. Factory values are in
450 * degrees Celsius. To calculate current temperature, see comments for
451 * "4965 temperature calculation".
452 *
453 * If current temperature is higher than factory temperature, driver must
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100454 * increase gain (lower gain table idx), and vice verse.
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800455 *
456 * Temperature affects gain differently for different channels:
457 *
458 * 2.4 GHz all channels: 3.5 degrees per half-dB step
459 * 5 GHz channels 34-43: 4.5 degrees per half-dB step
460 * 5 GHz channels >= 44: 4.0 degrees per half-dB step
461 *
462 * NOTE: Temperature can increase rapidly when transmitting, especially
463 * with heavy traffic at high txpowers. Driver should update
464 * temperature calculations often under these conditions to
465 * maintain strong txpower in the face of rising temperature.
466 *
467 *
468 * 7) Find difference between current power supply voltage indicator
469 * (from "initialize alive") and factory-measured power supply voltage
470 * indicator (EEPROM).
471 *
472 * If the current voltage is higher (indicator is lower) than factory
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100473 * voltage, gain should be reduced (gain table idx increased) by:
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800474 *
475 * (eeprom - current) / 7
476 *
477 * If the current voltage is lower (indicator is higher) than factory
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100478 * voltage, gain should be increased (gain table idx decreased) by:
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800479 *
480 * 2 * (current - eeprom) / 7
481 *
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100482 * If number of idx steps in either direction turns out to be > 2,
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800483 * something is wrong ... just use 0.
484 *
485 * NOTE: Voltage compensation is independent of band/channel.
486 *
487 * NOTE: "Initialize" uCode measures current voltage, which is assumed
488 * to be constant after this initial measurement. Voltage
489 * compensation for txpower (number of steps in gain table)
490 * may be calculated once and used until the next uCode bootload.
491 *
492 *
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100493 * 8) If setting up txpowers for MIMO rates (rate idxes 8-15, 24-31),
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800494 * adjust txpower for each transmitter chain, so txpower is balanced
495 * between the two chains. There are 5 pairs of tx_atten[group][chain]
496 * values in "initialize alive", one pair for each of 5 channel ranges:
497 *
498 * Group 0: 5 GHz channel 34-43
499 * Group 1: 5 GHz channel 44-70
500 * Group 2: 5 GHz channel 71-124
501 * Group 3: 5 GHz channel 125-200
502 * Group 4: 2.4 GHz all channels
503 *
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100504 * Add the tx_atten[group][chain] value to the idx for the target chain.
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800505 * The values are signed, but are in pairs of 0 and a non-negative number,
506 * so as to reduce gain (if necessary) of the "hotter" channel. This
507 * avoids any need to double-check for regulatory compliance after
508 * this step.
509 *
510 *
511 * 9) If setting up for a CCK rate, lower the gain by adding a CCK compensation
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100512 * value to the idx:
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800513 *
514 * Hardware rev B: 9 steps (4.5 dB)
515 * Hardware rev C: 5 steps (2.5 dB)
516 *
517 * Hardware rev for 4965 can be determined by reading CSR_HW_REV_WA_REG,
518 * bits [3:2], 1 = B, 2 = C.
519 *
520 * NOTE: This compensation is in addition to any saturation backoff that
521 * might have been applied in an earlier step.
522 *
523 *
524 * 10) Select the gain table, based on band (2.4 vs 5 GHz).
525 *
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100526 * Limit the adjusted idx to stay within the table!
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800527 *
528 *
529 * 11) Read gain table entries for DSP and radio gain, place into appropriate
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200530 * location(s) in command (struct il4965_txpowertable_cmd).
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800531 */
532
533/**
534 * When MIMO is used (2 transmitters operating simultaneously), driver should
535 * limit each transmitter to deliver a max of 3 dB below the regulatory limit
536 * for the device. That is, use half power for each transmitter, so total
537 * txpower is within regulatory limits.
538 *
539 * The value "6" represents number of steps in gain table to reduce power 3 dB.
540 * Each step is 1/2 dB.
541 */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200542#define IL_TX_POWER_MIMO_REGULATORY_COMPENSATION (6)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800543
544/**
545 * CCK gain compensation.
546 *
547 * When calculating txpowers for CCK, after making sure that the target power
548 * is within regulatory and saturation limits, driver must additionally
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100549 * back off gain by adding these values to the gain table idx.
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800550 *
551 * Hardware rev for 4965 can be determined by reading CSR_HW_REV_WA_REG,
552 * bits [3:2], 1 = B, 2 = C.
553 */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200554#define IL_TX_POWER_CCK_COMPENSATION_B_STEP (9)
555#define IL_TX_POWER_CCK_COMPENSATION_C_STEP (5)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800556
557/*
558 * 4965 power supply voltage compensation for txpower
559 */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200560#define TX_POWER_IL_VOLTAGE_CODES_PER_03V (7)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800561
562/**
563 * Gain tables.
564 *
565 * The following tables contain pair of values for setting txpower, i.e.
566 * gain settings for the output of the device's digital signal processor (DSP),
567 * and for the analog gain structure of the transmitter.
568 *
569 * Each entry in the gain tables represents a step of 1/2 dB. Note that these
570 * are *relative* steps, not indications of absolute output power. Output
571 * power varies with temperature, voltage, and channel frequency, and also
572 * requires consideration of average power (to satisfy regulatory constraints),
573 * and peak power (to avoid distortion of the output signal).
574 *
575 * Each entry contains two values:
576 * 1) DSP gain (or sometimes called DSP attenuation). This is a fine-grained
577 * linear value that multiplies the output of the digital signal processor,
578 * before being sent to the analog radio.
579 * 2) Radio gain. This sets the analog gain of the radio Tx path.
580 * It is a coarser setting, and behaves in a logarithmic (dB) fashion.
581 *
582 * EEPROM contains factory calibration data for txpower. This maps actual
583 * measured txpower levels to gain settings in the "well known" tables
584 * below ("well-known" means here that both factory calibration *and* the
585 * driver work with the same table).
586 *
587 * There are separate tables for 2.4 GHz and 5 GHz bands. The 5 GHz table
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100588 * has an extension (into negative idxes), in case the driver needs to
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800589 * boost power setting for high device temperatures (higher than would be
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100590 * present during factory calibration). A 5 Ghz EEPROM idx of "40"
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800591 * corresponds to the 49th entry in the table used by the driver.
592 */
Stanislaw Gruszka2d09b062011-08-26 16:10:40 +0200593#define MIN_TX_GAIN_IDX (0) /* highest gain, lowest idx, 2.4 */
594#define MIN_TX_GAIN_IDX_52GHZ_EXT (-9) /* highest gain, lowest idx, 5 */
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800595
596/**
597 * 2.4 GHz gain table
598 *
599 * Index Dsp gain Radio gain
600 * 0 110 0x3f (highest gain)
601 * 1 104 0x3f
602 * 2 98 0x3f
603 * 3 110 0x3e
604 * 4 104 0x3e
605 * 5 98 0x3e
606 * 6 110 0x3d
607 * 7 104 0x3d
608 * 8 98 0x3d
609 * 9 110 0x3c
610 * 10 104 0x3c
611 * 11 98 0x3c
612 * 12 110 0x3b
613 * 13 104 0x3b
614 * 14 98 0x3b
615 * 15 110 0x3a
616 * 16 104 0x3a
617 * 17 98 0x3a
618 * 18 110 0x39
619 * 19 104 0x39
620 * 20 98 0x39
621 * 21 110 0x38
622 * 22 104 0x38
623 * 23 98 0x38
624 * 24 110 0x37
625 * 25 104 0x37
626 * 26 98 0x37
627 * 27 110 0x36
628 * 28 104 0x36
629 * 29 98 0x36
630 * 30 110 0x35
631 * 31 104 0x35
632 * 32 98 0x35
633 * 33 110 0x34
634 * 34 104 0x34
635 * 35 98 0x34
636 * 36 110 0x33
637 * 37 104 0x33
638 * 38 98 0x33
639 * 39 110 0x32
640 * 40 104 0x32
641 * 41 98 0x32
642 * 42 110 0x31
643 * 43 104 0x31
644 * 44 98 0x31
645 * 45 110 0x30
646 * 46 104 0x30
647 * 47 98 0x30
648 * 48 110 0x6
649 * 49 104 0x6
650 * 50 98 0x6
651 * 51 110 0x5
652 * 52 104 0x5
653 * 53 98 0x5
654 * 54 110 0x4
655 * 55 104 0x4
656 * 56 98 0x4
657 * 57 110 0x3
658 * 58 104 0x3
659 * 59 98 0x3
660 * 60 110 0x2
661 * 61 104 0x2
662 * 62 98 0x2
663 * 63 110 0x1
664 * 64 104 0x1
665 * 65 98 0x1
666 * 66 110 0x0
667 * 67 104 0x0
668 * 68 98 0x0
669 * 69 97 0
670 * 70 96 0
671 * 71 95 0
672 * 72 94 0
673 * 73 93 0
674 * 74 92 0
675 * 75 91 0
676 * 76 90 0
677 * 77 89 0
678 * 78 88 0
679 * 79 87 0
680 * 80 86 0
681 * 81 85 0
682 * 82 84 0
683 * 83 83 0
684 * 84 82 0
685 * 85 81 0
686 * 86 80 0
687 * 87 79 0
688 * 88 78 0
689 * 89 77 0
690 * 90 76 0
691 * 91 75 0
692 * 92 74 0
693 * 93 73 0
694 * 94 72 0
695 * 95 71 0
696 * 96 70 0
697 * 97 69 0
698 * 98 68 0
699 */
700
701/**
702 * 5 GHz gain table
703 *
704 * Index Dsp gain Radio gain
705 * -9 123 0x3F (highest gain)
706 * -8 117 0x3F
707 * -7 110 0x3F
708 * -6 104 0x3F
709 * -5 98 0x3F
710 * -4 110 0x3E
711 * -3 104 0x3E
712 * -2 98 0x3E
713 * -1 110 0x3D
714 * 0 104 0x3D
715 * 1 98 0x3D
716 * 2 110 0x3C
717 * 3 104 0x3C
718 * 4 98 0x3C
719 * 5 110 0x3B
720 * 6 104 0x3B
721 * 7 98 0x3B
722 * 8 110 0x3A
723 * 9 104 0x3A
724 * 10 98 0x3A
725 * 11 110 0x39
726 * 12 104 0x39
727 * 13 98 0x39
728 * 14 110 0x38
729 * 15 104 0x38
730 * 16 98 0x38
731 * 17 110 0x37
732 * 18 104 0x37
733 * 19 98 0x37
734 * 20 110 0x36
735 * 21 104 0x36
736 * 22 98 0x36
737 * 23 110 0x35
738 * 24 104 0x35
739 * 25 98 0x35
740 * 26 110 0x34
741 * 27 104 0x34
742 * 28 98 0x34
743 * 29 110 0x33
744 * 30 104 0x33
745 * 31 98 0x33
746 * 32 110 0x32
747 * 33 104 0x32
748 * 34 98 0x32
749 * 35 110 0x31
750 * 36 104 0x31
751 * 37 98 0x31
752 * 38 110 0x30
753 * 39 104 0x30
754 * 40 98 0x30
755 * 41 110 0x25
756 * 42 104 0x25
757 * 43 98 0x25
758 * 44 110 0x24
759 * 45 104 0x24
760 * 46 98 0x24
761 * 47 110 0x23
762 * 48 104 0x23
763 * 49 98 0x23
764 * 50 110 0x22
765 * 51 104 0x18
766 * 52 98 0x18
767 * 53 110 0x17
768 * 54 104 0x17
769 * 55 98 0x17
770 * 56 110 0x16
771 * 57 104 0x16
772 * 58 98 0x16
773 * 59 110 0x15
774 * 60 104 0x15
775 * 61 98 0x15
776 * 62 110 0x14
777 * 63 104 0x14
778 * 64 98 0x14
779 * 65 110 0x13
780 * 66 104 0x13
781 * 67 98 0x13
782 * 68 110 0x12
783 * 69 104 0x08
784 * 70 98 0x08
785 * 71 110 0x07
786 * 72 104 0x07
787 * 73 98 0x07
788 * 74 110 0x06
789 * 75 104 0x06
790 * 76 98 0x06
791 * 77 110 0x05
792 * 78 104 0x05
793 * 79 98 0x05
794 * 80 110 0x04
795 * 81 104 0x04
796 * 82 98 0x04
797 * 83 110 0x03
798 * 84 104 0x03
799 * 85 98 0x03
800 * 86 110 0x02
801 * 87 104 0x02
802 * 88 98 0x02
803 * 89 110 0x01
804 * 90 104 0x01
805 * 91 98 0x01
806 * 92 110 0x00
807 * 93 104 0x00
808 * 94 98 0x00
809 * 95 93 0x00
810 * 96 88 0x00
811 * 97 83 0x00
812 * 98 78 0x00
813 */
814
815
816/**
817 * Sanity checks and default values for EEPROM regulatory levels.
818 * If EEPROM values fall outside MIN/MAX range, use default values.
819 *
820 * Regulatory limits refer to the maximum average txpower allowed by
821 * regulatory agencies in the geographies in which the device is meant
822 * to be operated. These limits are SKU-specific (i.e. geography-specific),
823 * and channel-specific; each channel has an individual regulatory limit
824 * listed in the EEPROM.
825 *
826 * Units are in half-dBm (i.e. "34" means 17 dBm).
827 */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200828#define IL_TX_POWER_DEFAULT_REGULATORY_24 (34)
829#define IL_TX_POWER_DEFAULT_REGULATORY_52 (34)
830#define IL_TX_POWER_REGULATORY_MIN (0)
831#define IL_TX_POWER_REGULATORY_MAX (34)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800832
833/**
834 * Sanity checks and default values for EEPROM saturation levels.
835 * If EEPROM values fall outside MIN/MAX range, use default values.
836 *
837 * Saturation is the highest level that the output power amplifier can produce
838 * without significant clipping distortion. This is a "peak" power level.
839 * Different types of modulation (i.e. various "rates", and OFDM vs. CCK)
840 * require differing amounts of backoff, relative to their average power output,
841 * in order to avoid clipping distortion.
842 *
843 * Driver must make sure that it is violating neither the saturation limit,
844 * nor the regulatory limit, when calculating Tx power settings for various
845 * rates.
846 *
847 * Units are in half-dBm (i.e. "38" means 19 dBm).
848 */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200849#define IL_TX_POWER_DEFAULT_SATURATION_24 (38)
850#define IL_TX_POWER_DEFAULT_SATURATION_52 (38)
851#define IL_TX_POWER_SATURATION_MIN (20)
852#define IL_TX_POWER_SATURATION_MAX (50)
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800853
854/**
855 * Channel groups used for Tx Attenuation calibration (MIMO tx channel balance)
856 * and thermal Txpower calibration.
857 *
858 * When calculating txpower, driver must compensate for current device
859 * temperature; higher temperature requires higher gain. Driver must calculate
860 * current temperature (see "4965 temperature calculation"), then compare vs.
861 * factory calibration temperature in EEPROM; if current temperature is higher
862 * than factory temperature, driver must *increase* gain by proportions shown
863 * in table below. If current temperature is lower than factory, driver must
864 * *decrease* gain.
865 *
866 * Different frequency ranges require different compensation, as shown below.
867 */
868/* Group 0, 5.2 GHz ch 34-43: 4.5 degrees per 1/2 dB. */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200869#define CALIB_IL_TX_ATTEN_GR1_FCH 34
870#define CALIB_IL_TX_ATTEN_GR1_LCH 43
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800871
872/* Group 1, 5.3 GHz ch 44-70: 4.0 degrees per 1/2 dB. */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200873#define CALIB_IL_TX_ATTEN_GR2_FCH 44
874#define CALIB_IL_TX_ATTEN_GR2_LCH 70
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800875
876/* Group 2, 5.5 GHz ch 71-124: 4.0 degrees per 1/2 dB. */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200877#define CALIB_IL_TX_ATTEN_GR3_FCH 71
878#define CALIB_IL_TX_ATTEN_GR3_LCH 124
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800879
880/* Group 3, 5.7 GHz ch 125-200: 4.0 degrees per 1/2 dB. */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200881#define CALIB_IL_TX_ATTEN_GR4_FCH 125
882#define CALIB_IL_TX_ATTEN_GR4_LCH 200
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800883
884/* Group 4, 2.4 GHz all channels: 3.5 degrees per 1/2 dB. */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200885#define CALIB_IL_TX_ATTEN_GR5_FCH 1
886#define CALIB_IL_TX_ATTEN_GR5_LCH 20
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800887
888enum {
889 CALIB_CH_GROUP_1 = 0,
890 CALIB_CH_GROUP_2 = 1,
891 CALIB_CH_GROUP_3 = 2,
892 CALIB_CH_GROUP_4 = 3,
893 CALIB_CH_GROUP_5 = 4,
894 CALIB_CH_GROUP_MAX
895};
896
897/********************* END TXPOWER *****************************************/
898
899
900/**
901 * Tx/Rx Queues
902 *
903 * Most communication between driver and 4965 is via queues of data buffers.
904 * For example, all commands that the driver issues to device's embedded
905 * controller (uCode) are via the command queue (one of the Tx queues). All
906 * uCode command responses/replies/notifications, including Rx frames, are
907 * conveyed from uCode to driver via the Rx queue.
908 *
909 * Most support for these queues, including handshake support, resides in
910 * structures in host DRAM, shared between the driver and the device. When
911 * allocating this memory, the driver must make sure that data written by
912 * the host CPU updates DRAM immediately (and does not get "stuck" in CPU's
913 * cache memory), so DRAM and cache are consistent, and the device can
914 * immediately see changes made by the driver.
915 *
916 * 4965 supports up to 16 DRAM-based Tx queues, and services these queues via
917 * up to 7 DMA channels (FIFOs). Each Tx queue is supported by a circular array
918 * in DRAM containing 256 Transmit Frame Descriptors (TFDs).
919 */
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100920#define IL49_NUM_FIFOS 7
921#define IL49_CMD_FIFO_NUM 4
922#define IL49_NUM_QUEUES 16
923#define IL49_NUM_AMPDU_QUEUES 8
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800924
925
926/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200927 * struct il4965_schedq_bc_tbl
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800928 *
929 * Byte Count table
930 *
931 * Each Tx queue uses a byte-count table containing 320 entries:
932 * one 16-bit entry for each of 256 TFDs, plus an additional 64 entries that
Stanislaw Gruszka6ce1dc42011-08-26 15:49:28 +0200933 * duplicate the first 64 entries (to avoid wrap-around within a Tx win;
934 * max Tx win is 64 TFDs).
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800935 *
936 * When driver sets up a new TFD, it must also enter the total byte count
937 * of the frame to be transmitted into the corresponding entry in the byte
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100938 * count table for the chosen Tx queue. If the TFD idx is 0-63, the driver
939 * must duplicate the byte count entry in corresponding idx 256-319.
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800940 *
941 * padding puts each byte count table on a 1024-byte boundary;
942 * 4965 assumes tables are separated by 1024 bytes.
943 */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200944struct il4965_scd_bc_tbl {
Wey-Yi Guy4bc85c12011-02-21 11:11:05 -0800945 __le16 tfd_offset[TFD_QUEUE_BC_SIZE];
946 u8 pad[1024 - (TFD_QUEUE_BC_SIZE) * sizeof(__le16)];
947} __packed;
948
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800949
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100950#define IL4965_RTC_INST_LOWER_BOUND (0x000000)
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800951
952/* RSSI to dBm */
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100953#define IL4965_RSSI_OFFSET 44
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800954
955/* PCI registers */
956#define PCI_CFG_RETRY_TIMEOUT 0x041
957
958/* PCI register values */
959#define PCI_CFG_LINK_CTRL_VAL_L0S_EN 0x01
960#define PCI_CFG_LINK_CTRL_VAL_L1_EN 0x02
961
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100962#define IL4965_DEFAULT_TX_RETRY 15
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800963
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800964/* EEPROM */
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100965#define IL4965_FIRST_AMPDU_QUEUE 10
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800966
Stanislaw Gruszkaaf038f42011-08-30 13:58:27 +0200967/* Calibration */
968void il4965_chain_noise_calibration(struct il_priv *il, void *stat_resp);
969void il4965_sensitivity_calibration(struct il_priv *il, void *resp);
970void il4965_init_sensitivity(struct il_priv *il);
971void il4965_reset_run_time_calib(struct il_priv *il);
972void il4965_calib_free_results(struct il_priv *il);
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800973
Stanislaw Gruszkaaf038f42011-08-30 13:58:27 +0200974/* Debug */
975#ifdef CONFIG_IWLEGACY_DEBUGFS
976ssize_t il4965_ucode_rx_stats_read(struct file *file, char __user *user_buf,
977 size_t count, loff_t *ppos);
978ssize_t il4965_ucode_tx_stats_read(struct file *file, char __user *user_buf,
979 size_t count, loff_t *ppos);
980ssize_t il4965_ucode_general_stats_read(struct file *file,
981 char __user *user_buf, size_t count, loff_t *ppos);
982#else
983static ssize_t
984il4965_ucode_rx_stats_read(struct file *file, char __user *user_buf,
985 size_t count, loff_t *ppos)
986{
987 return 0;
988}
989static ssize_t
990il4965_ucode_tx_stats_read(struct file *file, char __user *user_buf,
991 size_t count, loff_t *ppos)
992{
993 return 0;
994}
995static ssize_t
996il4965_ucode_general_stats_read(struct file *file, char __user *user_buf,
997 size_t count, loff_t *ppos)
998{
999 return 0;
1000}
1001#endif
1002
Stanislaw Gruszkaeac3b212011-08-31 14:29:46 +02001003/****************************/
1004/* Flow Handler Definitions */
1005/****************************/
1006
1007/**
1008 * This I/O area is directly read/writable by driver (e.g. Linux uses writel())
1009 * Addresses are offsets from device's PCI hardware base address.
1010 */
1011#define FH49_MEM_LOWER_BOUND (0x1000)
1012#define FH49_MEM_UPPER_BOUND (0x2000)
1013
1014/**
1015 * Keep-Warm (KW) buffer base address.
1016 *
1017 * Driver must allocate a 4KByte buffer that is used by 4965 for keeping the
1018 * host DRAM powered on (via dummy accesses to DRAM) to maintain low-latency
1019 * DRAM access when 4965 is Txing or Rxing. The dummy accesses prevent host
1020 * from going into a power-savings mode that would cause higher DRAM latency,
1021 * and possible data over/under-runs, before all Tx/Rx is complete.
1022 *
1023 * Driver loads FH49_KW_MEM_ADDR_REG with the physical address (bits 35:4)
1024 * of the buffer, which must be 4K aligned. Once this is set up, the 4965
1025 * automatically invokes keep-warm accesses when normal accesses might not
1026 * be sufficient to maintain fast DRAM response.
1027 *
1028 * Bit fields:
1029 * 31-0: Keep-warm buffer physical base address [35:4], must be 4K aligned
1030 */
1031#define FH49_KW_MEM_ADDR_REG (FH49_MEM_LOWER_BOUND + 0x97C)
1032
1033
1034/**
1035 * TFD Circular Buffers Base (CBBC) addresses
1036 *
1037 * 4965 has 16 base pointer registers, one for each of 16 host-DRAM-resident
1038 * circular buffers (CBs/queues) containing Transmit Frame Descriptors (TFDs)
1039 * (see struct il_tfd_frame). These 16 pointer registers are offset by 0x04
1040 * bytes from one another. Each TFD circular buffer in DRAM must be 256-byte
1041 * aligned (address bits 0-7 must be 0).
1042 *
1043 * Bit fields in each pointer register:
1044 * 27-0: TFD CB physical base address [35:8], must be 256-byte aligned
1045 */
1046#define FH49_MEM_CBBC_LOWER_BOUND (FH49_MEM_LOWER_BOUND + 0x9D0)
1047#define FH49_MEM_CBBC_UPPER_BOUND (FH49_MEM_LOWER_BOUND + 0xA10)
1048
1049/* Find TFD CB base pointer for given queue (range 0-15). */
1050#define FH49_MEM_CBBC_QUEUE(x) (FH49_MEM_CBBC_LOWER_BOUND + (x) * 0x4)
1051
1052
1053/**
1054 * Rx SRAM Control and Status Registers (RSCSR)
1055 *
1056 * These registers provide handshake between driver and 4965 for the Rx queue
1057 * (this queue handles *all* command responses, notifications, Rx data, etc.
1058 * sent from 4965 uCode to host driver). Unlike Tx, there is only one Rx
1059 * queue, and only one Rx DMA/FIFO channel. Also unlike Tx, which can
1060 * concatenate up to 20 DRAM buffers to form a Tx frame, each Receive Buffer
1061 * Descriptor (RBD) points to only one Rx Buffer (RB); there is a 1:1
1062 * mapping between RBDs and RBs.
1063 *
1064 * Driver must allocate host DRAM memory for the following, and set the
1065 * physical address of each into 4965 registers:
1066 *
1067 * 1) Receive Buffer Descriptor (RBD) circular buffer (CB), typically with 256
1068 * entries (although any power of 2, up to 4096, is selectable by driver).
1069 * Each entry (1 dword) points to a receive buffer (RB) of consistent size
1070 * (typically 4K, although 8K or 16K are also selectable by driver).
1071 * Driver sets up RB size and number of RBDs in the CB via Rx config
1072 * register FH49_MEM_RCSR_CHNL0_CONFIG_REG.
1073 *
1074 * Bit fields within one RBD:
1075 * 27-0: Receive Buffer physical address bits [35:8], 256-byte aligned
1076 *
1077 * Driver sets physical address [35:8] of base of RBD circular buffer
1078 * into FH49_RSCSR_CHNL0_RBDCB_BASE_REG [27:0].
1079 *
1080 * 2) Rx status buffer, 8 bytes, in which 4965 indicates which Rx Buffers
1081 * (RBs) have been filled, via a "write pointer", actually the idx of
1082 * the RB's corresponding RBD within the circular buffer. Driver sets
1083 * physical address [35:4] into FH49_RSCSR_CHNL0_STTS_WPTR_REG [31:0].
1084 *
1085 * Bit fields in lower dword of Rx status buffer (upper dword not used
1086 * by driver; see struct il4965_shared, val0):
1087 * 31-12: Not used by driver
1088 * 11- 0: Index of last filled Rx buffer descriptor
1089 * (4965 writes, driver reads this value)
1090 *
1091 * As the driver prepares Receive Buffers (RBs) for 4965 to fill, driver must
1092 * enter pointers to these RBs into contiguous RBD circular buffer entries,
1093 * and update the 4965's "write" idx register,
1094 * FH49_RSCSR_CHNL0_RBDCB_WPTR_REG.
1095 *
1096 * This "write" idx corresponds to the *next* RBD that the driver will make
1097 * available, i.e. one RBD past the tail of the ready-to-fill RBDs within
1098 * the circular buffer. This value should initially be 0 (before preparing any
1099 * RBs), should be 8 after preparing the first 8 RBs (for example), and must
1100 * wrap back to 0 at the end of the circular buffer (but don't wrap before
1101 * "read" idx has advanced past 1! See below).
1102 * NOTE: 4965 EXPECTS THE WRITE IDX TO BE INCREMENTED IN MULTIPLES OF 8.
1103 *
1104 * As the 4965 fills RBs (referenced from contiguous RBDs within the circular
1105 * buffer), it updates the Rx status buffer in host DRAM, 2) described above,
1106 * to tell the driver the idx of the latest filled RBD. The driver must
1107 * read this "read" idx from DRAM after receiving an Rx interrupt from 4965.
1108 *
1109 * The driver must also internally keep track of a third idx, which is the
1110 * next RBD to process. When receiving an Rx interrupt, driver should process
1111 * all filled but unprocessed RBs up to, but not including, the RB
1112 * corresponding to the "read" idx. For example, if "read" idx becomes "1",
1113 * driver may process the RB pointed to by RBD 0. Depending on volume of
1114 * traffic, there may be many RBs to process.
1115 *
1116 * If read idx == write idx, 4965 thinks there is no room to put new data.
1117 * Due to this, the maximum number of filled RBs is 255, instead of 256. To
1118 * be safe, make sure that there is a gap of at least 2 RBDs between "write"
1119 * and "read" idxes; that is, make sure that there are no more than 254
1120 * buffers waiting to be filled.
1121 */
1122#define FH49_MEM_RSCSR_LOWER_BOUND (FH49_MEM_LOWER_BOUND + 0xBC0)
1123#define FH49_MEM_RSCSR_UPPER_BOUND (FH49_MEM_LOWER_BOUND + 0xC00)
1124#define FH49_MEM_RSCSR_CHNL0 (FH49_MEM_RSCSR_LOWER_BOUND)
1125
1126/**
1127 * Physical base address of 8-byte Rx Status buffer.
1128 * Bit fields:
1129 * 31-0: Rx status buffer physical base address [35:4], must 16-byte aligned.
1130 */
1131#define FH49_RSCSR_CHNL0_STTS_WPTR_REG (FH49_MEM_RSCSR_CHNL0)
1132
1133/**
1134 * Physical base address of Rx Buffer Descriptor Circular Buffer.
1135 * Bit fields:
1136 * 27-0: RBD CD physical base address [35:8], must be 256-byte aligned.
1137 */
1138#define FH49_RSCSR_CHNL0_RBDCB_BASE_REG (FH49_MEM_RSCSR_CHNL0 + 0x004)
1139
1140/**
1141 * Rx write pointer (idx, really!).
1142 * Bit fields:
1143 * 11-0: Index of driver's most recent prepared-to-be-filled RBD, + 1.
1144 * NOTE: For 256-entry circular buffer, use only bits [7:0].
1145 */
1146#define FH49_RSCSR_CHNL0_RBDCB_WPTR_REG (FH49_MEM_RSCSR_CHNL0 + 0x008)
1147#define FH49_RSCSR_CHNL0_WPTR (FH49_RSCSR_CHNL0_RBDCB_WPTR_REG)
1148
1149
1150/**
1151 * Rx Config/Status Registers (RCSR)
1152 * Rx Config Reg for channel 0 (only channel used)
1153 *
1154 * Driver must initialize FH49_MEM_RCSR_CHNL0_CONFIG_REG as follows for
1155 * normal operation (see bit fields).
1156 *
1157 * Clearing FH49_MEM_RCSR_CHNL0_CONFIG_REG to 0 turns off Rx DMA.
1158 * Driver should poll FH49_MEM_RSSR_RX_STATUS_REG for
1159 * FH49_RSSR_CHNL0_RX_STATUS_CHNL_IDLE (bit 24) before continuing.
1160 *
1161 * Bit fields:
1162 * 31-30: Rx DMA channel enable: '00' off/pause, '01' pause at end of frame,
1163 * '10' operate normally
1164 * 29-24: reserved
1165 * 23-20: # RBDs in circular buffer = 2^value; use "8" for 256 RBDs (normal),
1166 * min "5" for 32 RBDs, max "12" for 4096 RBDs.
1167 * 19-18: reserved
1168 * 17-16: size of each receive buffer; '00' 4K (normal), '01' 8K,
1169 * '10' 12K, '11' 16K.
1170 * 15-14: reserved
1171 * 13-12: IRQ destination; '00' none, '01' host driver (normal operation)
1172 * 11- 4: timeout for closing Rx buffer and interrupting host (units 32 usec)
1173 * typical value 0x10 (about 1/2 msec)
1174 * 3- 0: reserved
1175 */
1176#define FH49_MEM_RCSR_LOWER_BOUND (FH49_MEM_LOWER_BOUND + 0xC00)
1177#define FH49_MEM_RCSR_UPPER_BOUND (FH49_MEM_LOWER_BOUND + 0xCC0)
1178#define FH49_MEM_RCSR_CHNL0 (FH49_MEM_RCSR_LOWER_BOUND)
1179
1180#define FH49_MEM_RCSR_CHNL0_CONFIG_REG (FH49_MEM_RCSR_CHNL0)
1181
1182#define FH49_RCSR_CHNL0_RX_CONFIG_RB_TIMEOUT_MSK (0x00000FF0) /* bits 4-11 */
1183#define FH49_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_MSK (0x00001000) /* bits 12 */
1184#define FH49_RCSR_CHNL0_RX_CONFIG_SINGLE_FRAME_MSK (0x00008000) /* bit 15 */
1185#define FH49_RCSR_CHNL0_RX_CONFIG_RB_SIZE_MSK (0x00030000) /* bits 16-17 */
1186#define FH49_RCSR_CHNL0_RX_CONFIG_RBDBC_SIZE_MSK (0x00F00000) /* bits 20-23 */
1187#define FH49_RCSR_CHNL0_RX_CONFIG_DMA_CHNL_EN_MSK (0xC0000000) /* bits 30-31*/
1188
1189#define FH49_RCSR_RX_CONFIG_RBDCB_SIZE_POS (20)
1190#define FH49_RCSR_RX_CONFIG_REG_IRQ_RBTH_POS (4)
1191#define RX_RB_TIMEOUT (0x10)
1192
1193#define FH49_RCSR_RX_CONFIG_CHNL_EN_PAUSE_VAL (0x00000000)
1194#define FH49_RCSR_RX_CONFIG_CHNL_EN_PAUSE_EOF_VAL (0x40000000)
1195#define FH49_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL (0x80000000)
1196
1197#define FH49_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K (0x00000000)
1198#define FH49_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K (0x00010000)
1199#define FH49_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_12K (0x00020000)
1200#define FH49_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_16K (0x00030000)
1201
1202#define FH49_RCSR_CHNL0_RX_IGNORE_RXF_EMPTY (0x00000004)
1203#define FH49_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_NO_INT_VAL (0x00000000)
1204#define FH49_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL (0x00001000)
1205
1206/**
1207 * Rx Shared Status Registers (RSSR)
1208 *
1209 * After stopping Rx DMA channel (writing 0 to
1210 * FH49_MEM_RCSR_CHNL0_CONFIG_REG), driver must poll
1211 * FH49_MEM_RSSR_RX_STATUS_REG until Rx channel is idle.
1212 *
1213 * Bit fields:
1214 * 24: 1 = Channel 0 is idle
1215 *
1216 * FH49_MEM_RSSR_SHARED_CTRL_REG and FH49_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV
1217 * contain default values that should not be altered by the driver.
1218 */
1219#define FH49_MEM_RSSR_LOWER_BOUND (FH49_MEM_LOWER_BOUND + 0xC40)
1220#define FH49_MEM_RSSR_UPPER_BOUND (FH49_MEM_LOWER_BOUND + 0xD00)
1221
1222#define FH49_MEM_RSSR_SHARED_CTRL_REG (FH49_MEM_RSSR_LOWER_BOUND)
1223#define FH49_MEM_RSSR_RX_STATUS_REG (FH49_MEM_RSSR_LOWER_BOUND + 0x004)
1224#define FH49_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV\
1225 (FH49_MEM_RSSR_LOWER_BOUND + 0x008)
1226
1227#define FH49_RSSR_CHNL0_RX_STATUS_CHNL_IDLE (0x01000000)
1228
1229#define FH49_MEM_TFDIB_REG1_ADDR_BITSHIFT 28
1230
1231/* TFDB Area - TFDs buffer table */
1232#define FH49_MEM_TFDIB_DRAM_ADDR_LSB_MSK (0xFFFFFFFF)
1233#define FH49_TFDIB_LOWER_BOUND (FH49_MEM_LOWER_BOUND + 0x900)
1234#define FH49_TFDIB_UPPER_BOUND (FH49_MEM_LOWER_BOUND + 0x958)
1235#define FH49_TFDIB_CTRL0_REG(_chnl) (FH49_TFDIB_LOWER_BOUND + 0x8 * (_chnl))
1236#define FH49_TFDIB_CTRL1_REG(_chnl) (FH49_TFDIB_LOWER_BOUND + 0x8 * (_chnl) + 0x4)
1237
1238/**
1239 * Transmit DMA Channel Control/Status Registers (TCSR)
1240 *
1241 * 4965 has one configuration register for each of 8 Tx DMA/FIFO channels
1242 * supported in hardware (don't confuse these with the 16 Tx queues in DRAM,
1243 * which feed the DMA/FIFO channels); config regs are separated by 0x20 bytes.
1244 *
1245 * To use a Tx DMA channel, driver must initialize its
1246 * FH49_TCSR_CHNL_TX_CONFIG_REG(chnl) with:
1247 *
1248 * FH49_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
1249 * FH49_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL
1250 *
1251 * All other bits should be 0.
1252 *
1253 * Bit fields:
1254 * 31-30: Tx DMA channel enable: '00' off/pause, '01' pause at end of frame,
1255 * '10' operate normally
1256 * 29- 4: Reserved, set to "0"
1257 * 3: Enable internal DMA requests (1, normal operation), disable (0)
1258 * 2- 0: Reserved, set to "0"
1259 */
1260#define FH49_TCSR_LOWER_BOUND (FH49_MEM_LOWER_BOUND + 0xD00)
1261#define FH49_TCSR_UPPER_BOUND (FH49_MEM_LOWER_BOUND + 0xE60)
1262
1263/* Find Control/Status reg for given Tx DMA/FIFO channel */
1264#define FH49_TCSR_CHNL_NUM (7)
1265#define FH50_TCSR_CHNL_NUM (8)
1266
1267/* TCSR: tx_config register values */
1268#define FH49_TCSR_CHNL_TX_CONFIG_REG(_chnl) \
1269 (FH49_TCSR_LOWER_BOUND + 0x20 * (_chnl))
1270#define FH49_TCSR_CHNL_TX_CREDIT_REG(_chnl) \
1271 (FH49_TCSR_LOWER_BOUND + 0x20 * (_chnl) + 0x4)
1272#define FH49_TCSR_CHNL_TX_BUF_STS_REG(_chnl) \
1273 (FH49_TCSR_LOWER_BOUND + 0x20 * (_chnl) + 0x8)
1274
1275#define FH49_TCSR_TX_CONFIG_REG_VAL_MSG_MODE_TXF (0x00000000)
1276#define FH49_TCSR_TX_CONFIG_REG_VAL_MSG_MODE_DRV (0x00000001)
1277
1278#define FH49_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE (0x00000000)
1279#define FH49_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE (0x00000008)
1280
1281#define FH49_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_NOINT (0x00000000)
1282#define FH49_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD (0x00100000)
1283#define FH49_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_IFTFD (0x00200000)
1284
1285#define FH49_TCSR_TX_CONFIG_REG_VAL_CIRQ_RTC_NOINT (0x00000000)
1286#define FH49_TCSR_TX_CONFIG_REG_VAL_CIRQ_RTC_ENDTFD (0x00400000)
1287#define FH49_TCSR_TX_CONFIG_REG_VAL_CIRQ_RTC_IFTFD (0x00800000)
1288
1289#define FH49_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE (0x00000000)
1290#define FH49_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE_EOF (0x40000000)
1291#define FH49_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE (0x80000000)
1292
1293#define FH49_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_EMPTY (0x00000000)
1294#define FH49_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_WAIT (0x00002000)
1295#define FH49_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID (0x00000003)
1296
1297#define FH49_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_NUM (20)
1298#define FH49_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_IDX (12)
1299
1300/**
1301 * Tx Shared Status Registers (TSSR)
1302 *
1303 * After stopping Tx DMA channel (writing 0 to
1304 * FH49_TCSR_CHNL_TX_CONFIG_REG(chnl)), driver must poll
1305 * FH49_TSSR_TX_STATUS_REG until selected Tx channel is idle
1306 * (channel's buffers empty | no pending requests).
1307 *
1308 * Bit fields:
1309 * 31-24: 1 = Channel buffers empty (channel 7:0)
1310 * 23-16: 1 = No pending requests (channel 7:0)
1311 */
1312#define FH49_TSSR_LOWER_BOUND (FH49_MEM_LOWER_BOUND + 0xEA0)
1313#define FH49_TSSR_UPPER_BOUND (FH49_MEM_LOWER_BOUND + 0xEC0)
1314
1315#define FH49_TSSR_TX_STATUS_REG (FH49_TSSR_LOWER_BOUND + 0x010)
1316
1317/**
1318 * Bit fields for TSSR(Tx Shared Status & Control) error status register:
1319 * 31: Indicates an address error when accessed to internal memory
1320 * uCode/driver must write "1" in order to clear this flag
1321 * 30: Indicates that Host did not send the expected number of dwords to FH
1322 * uCode/driver must write "1" in order to clear this flag
1323 * 16-9:Each status bit is for one channel. Indicates that an (Error) ActDMA
1324 * command was received from the scheduler while the TRB was already full
1325 * with previous command
1326 * uCode/driver must write "1" in order to clear this flag
1327 * 7-0: Each status bit indicates a channel's TxCredit error. When an error
1328 * bit is set, it indicates that the FH has received a full indication
1329 * from the RTC TxFIFO and the current value of the TxCredit counter was
1330 * not equal to zero. This mean that the credit mechanism was not
1331 * synchronized to the TxFIFO status
1332 * uCode/driver must write "1" in order to clear this flag
1333 */
1334#define FH49_TSSR_TX_ERROR_REG (FH49_TSSR_LOWER_BOUND + 0x018)
1335
1336#define FH49_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE(_chnl) ((1 << (_chnl)) << 16)
1337
1338/* Tx service channels */
1339#define FH49_SRVC_CHNL (9)
1340#define FH49_SRVC_LOWER_BOUND (FH49_MEM_LOWER_BOUND + 0x9C8)
1341#define FH49_SRVC_UPPER_BOUND (FH49_MEM_LOWER_BOUND + 0x9D0)
1342#define FH49_SRVC_CHNL_SRAM_ADDR_REG(_chnl) \
1343 (FH49_SRVC_LOWER_BOUND + ((_chnl) - 9) * 0x4)
1344
1345#define FH49_TX_CHICKEN_BITS_REG (FH49_MEM_LOWER_BOUND + 0xE98)
1346/* Instruct FH to increment the retry count of a packet when
1347 * it is brought from the memory to TX-FIFO
1348 */
1349#define FH49_TX_CHICKEN_BITS_SCD_AUTO_RETRY_EN (0x00000002)
1350
1351/* Keep Warm Size */
1352#define IL_KW_SIZE 0x1000 /* 4k */
1353
Stanislaw Gruszkaaf038f42011-08-30 13:58:27 +02001354#endif /* __il_4965_h__ */