iwlwifi-5000: add iwl 5000 shared memory handlers
[deliverable/linux.git] / drivers / net / wireless / iwlwifi / iwl-5000.c
CommitLineData
5a6a256e
TW
1/******************************************************************************
2 *
3 * Copyright(c) 2007-2008 Intel Corporation. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
20 *
21 * Contact Information:
22 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
23 *
24 *****************************************************************************/
25
26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/version.h>
29#include <linux/init.h>
30#include <linux/pci.h>
31#include <linux/dma-mapping.h>
32#include <linux/delay.h>
33#include <linux/skbuff.h>
34#include <linux/netdevice.h>
35#include <linux/wireless.h>
36#include <net/mac80211.h>
37#include <linux/etherdevice.h>
38#include <asm/unaligned.h>
39
40#include "iwl-eeprom.h"
41#include "iwl-4965.h"
42#include "iwl-core.h"
43#include "iwl-io.h"
44#include "iwl-helpers.h"
45#include "iwl-5000-hw.h"
46
47#define IWL5000_UCODE_API "-1"
48
30d59260
TW
49static int iwl5000_apm_init(struct iwl_priv *priv)
50{
51 int ret = 0;
52
53 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
54 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
55
56 iwl_set_bit(priv, CSR_ANA_PLL_CFG, CSR50_ANA_PLL_CFG_VAL);
57
58 /* set "initialization complete" bit to move adapter
59 * D0U* --> D0A* state */
60 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
61
62 /* wait for clock stabilization */
63 ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
64 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
65 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
66 if (ret < 0) {
67 IWL_DEBUG_INFO("Failed to init the card\n");
68 return ret;
69 }
70
71 ret = iwl_grab_nic_access(priv);
72 if (ret)
73 return ret;
74
75 /* enable DMA */
76 iwl_write_prph(priv, APMG_CLK_EN_REG,
77 APMG_CLK_VAL_DMA_CLK_RQT);
78
79 udelay(20);
80
81 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
82 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
83
84 iwl_release_nic_access(priv);
85
86 return ret;
87}
88
25ae3986
TW
89/*
90 * EEPROM
91 */
92static u32 eeprom_indirect_address(const struct iwl_priv *priv, u32 address)
93{
94 u16 offset = 0;
95
96 if ((address & INDIRECT_ADDRESS) == 0)
97 return address;
98
99 switch (address & INDIRECT_TYPE_MSK) {
100 case INDIRECT_HOST:
101 offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_HOST);
102 break;
103 case INDIRECT_GENERAL:
104 offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_GENERAL);
105 break;
106 case INDIRECT_REGULATORY:
107 offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_REGULATORY);
108 break;
109 case INDIRECT_CALIBRATION:
110 offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_CALIBRATION);
111 break;
112 case INDIRECT_PROCESS_ADJST:
113 offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_PROCESS_ADJST);
114 break;
115 case INDIRECT_OTHERS:
116 offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_OTHERS);
117 break;
118 default:
119 IWL_ERROR("illegal indirect type: 0x%X\n",
120 address & INDIRECT_TYPE_MSK);
121 break;
122 }
123
124 /* translate the offset from words to byte */
125 return (address & ADDRESS_MSK) + (offset << 1);
126}
127
33fd5033
EG
128#ifdef CONFIG_IWL5000_RUN_TIME_CALIB
129
130static void iwl5000_gain_computation(struct iwl_priv *priv,
131 u32 average_noise[NUM_RX_CHAINS],
132 u16 min_average_noise_antenna_i,
133 u32 min_average_noise)
134{
135 int i;
136 s32 delta_g;
137 struct iwl_chain_noise_data *data = &priv->chain_noise_data;
138
139 /* Find Gain Code for the antennas B and C */
140 for (i = 1; i < NUM_RX_CHAINS; i++) {
141 if ((data->disconn_array[i])) {
142 data->delta_gain_code[i] = 0;
143 continue;
144 }
145 delta_g = (1000 * ((s32)average_noise[0] -
146 (s32)average_noise[i])) / 1500;
147 /* bound gain by 2 bits value max, 3rd bit is sign */
148 data->delta_gain_code[i] =
149 min(abs(delta_g), CHAIN_NOISE_MAX_DELTA_GAIN_CODE);
150
151 if (delta_g < 0)
152 /* set negative sign */
153 data->delta_gain_code[i] |= (1 << 2);
154 }
155
156 IWL_DEBUG_CALIB("Delta gains: ANT_B = %d ANT_C = %d\n",
157 data->delta_gain_code[1], data->delta_gain_code[2]);
158
159 if (!data->radio_write) {
160 struct iwl5000_calibration_chain_noise_gain_cmd cmd;
161 memset(&cmd, 0, sizeof(cmd));
162
163 cmd.op_code = IWL5000_PHY_CALIBRATE_CHAIN_NOISE_GAIN_CMD;
164 cmd.delta_gain_1 = data->delta_gain_code[1];
165 cmd.delta_gain_2 = data->delta_gain_code[2];
166 iwl_send_cmd_pdu_async(priv, REPLY_PHY_CALIBRATION_CMD,
167 sizeof(cmd), &cmd, NULL);
168
169 data->radio_write = 1;
170 data->state = IWL_CHAIN_NOISE_CALIBRATED;
171 }
172
173 data->chain_noise_a = 0;
174 data->chain_noise_b = 0;
175 data->chain_noise_c = 0;
176 data->chain_signal_a = 0;
177 data->chain_signal_b = 0;
178 data->chain_signal_c = 0;
179 data->beacon_count = 0;
180}
181
182static void iwl5000_chain_noise_reset(struct iwl_priv *priv)
183{
184 struct iwl_chain_noise_data *data = &priv->chain_noise_data;
185
186 if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl_is_associated(priv)) {
187 struct iwl5000_calibration_chain_noise_reset_cmd cmd;
188
189 memset(&cmd, 0, sizeof(cmd));
190 cmd.op_code = IWL5000_PHY_CALIBRATE_CHAIN_NOISE_RESET_CMD;
191 if (iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
192 sizeof(cmd), &cmd))
193 IWL_ERROR("Could not send REPLY_PHY_CALIBRATION_CMD\n");
194 data->state = IWL_CHAIN_NOISE_ACCUMULATE;
195 IWL_DEBUG_CALIB("Run chain_noise_calibrate\n");
196 }
197}
198
199static struct iwl_sensitivity_ranges iwl5000_sensitivity = {
200 .min_nrg_cck = 95,
201 .max_nrg_cck = 0,
202 .auto_corr_min_ofdm = 90,
203 .auto_corr_min_ofdm_mrc = 170,
204 .auto_corr_min_ofdm_x1 = 120,
205 .auto_corr_min_ofdm_mrc_x1 = 240,
206
207 .auto_corr_max_ofdm = 120,
208 .auto_corr_max_ofdm_mrc = 210,
209 .auto_corr_max_ofdm_x1 = 155,
210 .auto_corr_max_ofdm_mrc_x1 = 290,
211
212 .auto_corr_min_cck = 125,
213 .auto_corr_max_cck = 200,
214 .auto_corr_min_cck_mrc = 170,
215 .auto_corr_max_cck_mrc = 400,
216 .nrg_th_cck = 95,
217 .nrg_th_ofdm = 95,
218};
219
220#endif /* CONFIG_IWL5000_RUN_TIME_CALIB */
221
25ae3986
TW
222static const u8 *iwl5000_eeprom_query_addr(const struct iwl_priv *priv,
223 size_t offset)
224{
225 u32 address = eeprom_indirect_address(priv, offset);
226 BUG_ON(address >= priv->cfg->eeprom_size);
227 return &priv->eeprom[address];
228}
229
fdd3e8a4
TW
230static int iwl5000_hw_set_hw_params(struct iwl_priv *priv)
231{
232 if ((priv->cfg->mod_params->num_of_queues > IWL50_NUM_QUEUES) ||
233 (priv->cfg->mod_params->num_of_queues < IWL_MIN_NUM_QUEUES)) {
234 IWL_ERROR("invalid queues_num, should be between %d and %d\n",
235 IWL_MIN_NUM_QUEUES, IWL50_NUM_QUEUES);
236 return -EINVAL;
237 }
25ae3986 238
fdd3e8a4
TW
239 priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues;
240 priv->hw_params.sw_crypto = priv->cfg->mod_params->sw_crypto;
241 priv->hw_params.tx_cmd_len = sizeof(struct iwl4965_tx_cmd);
242 priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
243 priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
244 if (priv->cfg->mod_params->amsdu_size_8K)
245 priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_8K;
246 else
247 priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_4K;
248 priv->hw_params.max_pkt_size = priv->hw_params.rx_buf_size - 256;
249 priv->hw_params.max_stations = IWL5000_STATION_COUNT;
250 priv->hw_params.bcast_sta_id = IWL5000_BROADCAST_ID;
251 priv->hw_params.max_data_size = IWL50_RTC_DATA_SIZE;
252 priv->hw_params.max_inst_size = IWL50_RTC_INST_SIZE;
253 priv->hw_params.max_bsm_size = BSM_SRAM_SIZE;
254 priv->hw_params.fat_channel = BIT(IEEE80211_BAND_2GHZ) |
255 BIT(IEEE80211_BAND_5GHZ);
33fd5033
EG
256#ifdef CONFIG_IWL5000_RUN_TIME_CALIB
257 priv->hw_params.sens = &iwl5000_sensitivity;
258#endif
fdd3e8a4
TW
259
260 switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
261 case CSR_HW_REV_TYPE_5100:
262 case CSR_HW_REV_TYPE_5150:
263 priv->hw_params.tx_chains_num = 1;
264 priv->hw_params.rx_chains_num = 2;
265 /* FIXME: move to ANT_A, ANT_B, ANT_C enum */
1179f18d
TW
266 priv->hw_params.valid_tx_ant = ANT_A;
267 priv->hw_params.valid_rx_ant = ANT_AB;
fdd3e8a4
TW
268 break;
269 case CSR_HW_REV_TYPE_5300:
270 case CSR_HW_REV_TYPE_5350:
271 priv->hw_params.tx_chains_num = 3;
272 priv->hw_params.rx_chains_num = 3;
1179f18d
TW
273 priv->hw_params.valid_tx_ant = ANT_ABC;
274 priv->hw_params.valid_rx_ant = ANT_ABC;
fdd3e8a4
TW
275 break;
276 }
c031bf80
EG
277
278 switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
279 case CSR_HW_REV_TYPE_5100:
280 case CSR_HW_REV_TYPE_5300:
281 /* 5X00 wants in Celsius */
282 priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD;
283 break;
284 case CSR_HW_REV_TYPE_5150:
285 case CSR_HW_REV_TYPE_5350:
286 /* 5X50 wants in Kelvin */
287 priv->hw_params.ct_kill_threshold =
288 CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD);
289 break;
290 }
291
fdd3e8a4
TW
292 return 0;
293}
d4100dd9
RR
294
295static int iwl5000_alloc_shared_mem(struct iwl_priv *priv)
296{
297 priv->shared_virt = pci_alloc_consistent(priv->pci_dev,
298 sizeof(struct iwl5000_shared),
299 &priv->shared_phys);
300 if (!priv->shared_virt)
301 return -ENOMEM;
302
303 memset(priv->shared_virt, 0, sizeof(struct iwl5000_shared));
304
305 return 0;
306}
307
308static void iwl5000_free_shared_mem(struct iwl_priv *priv)
309{
310 if (priv->shared_virt)
311 pci_free_consistent(priv->pci_dev,
312 sizeof(struct iwl5000_shared),
313 priv->shared_virt,
314 priv->shared_phys);
315}
316
da8dec29
TW
317static struct iwl_hcmd_ops iwl5000_hcmd = {
318};
319
320static struct iwl_hcmd_utils_ops iwl5000_hcmd_utils = {
33fd5033
EG
321#ifdef CONFIG_IWL5000_RUN_TIME_CALIB
322 .gain_computation = iwl5000_gain_computation,
323 .chain_noise_reset = iwl5000_chain_noise_reset,
324#endif
da8dec29
TW
325};
326
327static struct iwl_lib_ops iwl5000_lib = {
fdd3e8a4 328 .set_hw_params = iwl5000_hw_set_hw_params,
d4100dd9
RR
329 .alloc_shared_mem = iwl5000_alloc_shared_mem,
330 .free_shared_mem = iwl5000_free_shared_mem,
30d59260
TW
331 .apm_ops = {
332 .init = iwl5000_apm_init,
88acbd3b 333 .set_pwr_src = iwl4965_set_pwr_src,
30d59260 334 },
da8dec29 335 .eeprom_ops = {
25ae3986
TW
336 .regulatory_bands = {
337 EEPROM_5000_REG_BAND_1_CHANNELS,
338 EEPROM_5000_REG_BAND_2_CHANNELS,
339 EEPROM_5000_REG_BAND_3_CHANNELS,
340 EEPROM_5000_REG_BAND_4_CHANNELS,
341 EEPROM_5000_REG_BAND_5_CHANNELS,
342 EEPROM_5000_REG_BAND_24_FAT_CHANNELS,
343 EEPROM_5000_REG_BAND_52_FAT_CHANNELS
344 },
da8dec29
TW
345 .verify_signature = iwlcore_eeprom_verify_signature,
346 .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
347 .release_semaphore = iwlcore_eeprom_release_semaphore,
25ae3986 348 .query_addr = iwl5000_eeprom_query_addr,
da8dec29
TW
349 },
350};
351
352static struct iwl_ops iwl5000_ops = {
353 .lib = &iwl5000_lib,
354 .hcmd = &iwl5000_hcmd,
355 .utils = &iwl5000_hcmd_utils,
356};
357
5a6a256e
TW
358static struct iwl_mod_params iwl50_mod_params = {
359 .num_of_queues = IWL50_NUM_QUEUES,
360 .enable_qos = 1,
361 .amsdu_size_8K = 1,
362 /* the rest are 0 by default */
363};
364
365
366struct iwl_cfg iwl5300_agn_cfg = {
367 .name = "5300AGN",
368 .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
369 .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
da8dec29 370 .ops = &iwl5000_ops,
25ae3986 371 .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
5a6a256e
TW
372 .mod_params = &iwl50_mod_params,
373};
374
375struct iwl_cfg iwl5100_agn_cfg = {
376 .name = "5100AGN",
377 .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
378 .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
da8dec29 379 .ops = &iwl5000_ops,
25ae3986 380 .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
5a6a256e
TW
381 .mod_params = &iwl50_mod_params,
382};
383
384struct iwl_cfg iwl5350_agn_cfg = {
385 .name = "5350AGN",
386 .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
387 .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
da8dec29 388 .ops = &iwl5000_ops,
25ae3986 389 .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
5a6a256e
TW
390 .mod_params = &iwl50_mod_params,
391};
392
393module_param_named(disable50, iwl50_mod_params.disable, int, 0444);
394MODULE_PARM_DESC(disable50,
395 "manually disable the 50XX radio (default 0 [radio on])");
396module_param_named(swcrypto50, iwl50_mod_params.sw_crypto, bool, 0444);
397MODULE_PARM_DESC(swcrypto50,
398 "using software crypto engine (default 0 [hardware])\n");
399module_param_named(debug50, iwl50_mod_params.debug, int, 0444);
400MODULE_PARM_DESC(debug50, "50XX debug output mask");
401module_param_named(queues_num50, iwl50_mod_params.num_of_queues, int, 0444);
402MODULE_PARM_DESC(queues_num50, "number of hw queues in 50xx series");
403module_param_named(qos_enable50, iwl50_mod_params.enable_qos, int, 0444);
404MODULE_PARM_DESC(qos_enable50, "enable all 50XX QoS functionality");
405module_param_named(amsdu_size_8K50, iwl50_mod_params.amsdu_size_8K, int, 0444);
406MODULE_PARM_DESC(amsdu_size_8K50, "enable 8K amsdu size in 50XX series");
407
408
This page took 0.040498 seconds and 5 git commands to generate.