pandora: defconfig: update
[pandora-kernel.git] / drivers / net / wireless / iwlwifi / iwl-5000.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2011 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 Linux Wireless <ilw@linux.intel.com>
23  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24  *
25  *****************************************************************************/
26
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/delay.h>
31 #include <linux/sched.h>
32 #include <linux/skbuff.h>
33 #include <linux/netdevice.h>
34 #include <net/mac80211.h>
35 #include <linux/etherdevice.h>
36 #include <asm/unaligned.h>
37 #include <linux/stringify.h>
38
39 #include "iwl-eeprom.h"
40 #include "iwl-dev.h"
41 #include "iwl-core.h"
42 #include "iwl-io.h"
43 #include "iwl-agn.h"
44 #include "iwl-agn-hw.h"
45 #include "iwl-trans.h"
46 #include "iwl-shared.h"
47 #include "iwl-cfg.h"
48
49 /* Highest firmware API version supported */
50 #define IWL5000_UCODE_API_MAX 5
51 #define IWL5150_UCODE_API_MAX 2
52
53 /* Oldest version we won't warn about */
54 #define IWL5000_UCODE_API_OK 5
55 #define IWL5150_UCODE_API_OK 2
56
57 /* Lowest firmware API version supported */
58 #define IWL5000_UCODE_API_MIN 1
59 #define IWL5150_UCODE_API_MIN 1
60
61 #define IWL5000_FW_PRE "iwlwifi-5000-"
62 #define IWL5000_MODULE_FIRMWARE(api) IWL5000_FW_PRE __stringify(api) ".ucode"
63
64 #define IWL5150_FW_PRE "iwlwifi-5150-"
65 #define IWL5150_MODULE_FIRMWARE(api) IWL5150_FW_PRE __stringify(api) ".ucode"
66
67 /* NIC configuration for 5000 series */
68 static void iwl5000_nic_config(struct iwl_priv *priv)
69 {
70         unsigned long flags;
71
72         iwl_rf_config(priv);
73
74         spin_lock_irqsave(&priv->shrd->lock, flags);
75
76         /* W/A : NIC is stuck in a reset state after Early PCIe power off
77          * (PCIe power is lost before PERST# is asserted),
78          * causing ME FW to lose ownership and not being able to obtain it back.
79          */
80         iwl_set_bits_mask_prph(bus(priv), APMG_PS_CTRL_REG,
81                                 APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS,
82                                 ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS);
83
84
85         spin_unlock_irqrestore(&priv->shrd->lock, flags);
86 }
87
88 static struct iwl_sensitivity_ranges iwl5000_sensitivity = {
89         .min_nrg_cck = 100,
90         .max_nrg_cck = 0, /* not used, set to 0 */
91         .auto_corr_min_ofdm = 90,
92         .auto_corr_min_ofdm_mrc = 170,
93         .auto_corr_min_ofdm_x1 = 105,
94         .auto_corr_min_ofdm_mrc_x1 = 220,
95
96         .auto_corr_max_ofdm = 120,
97         .auto_corr_max_ofdm_mrc = 210,
98         .auto_corr_max_ofdm_x1 = 120,
99         .auto_corr_max_ofdm_mrc_x1 = 240,
100
101         .auto_corr_min_cck = 125,
102         .auto_corr_max_cck = 200,
103         .auto_corr_min_cck_mrc = 200,
104         .auto_corr_max_cck_mrc = 400,
105         .nrg_th_cck = 100,
106         .nrg_th_ofdm = 100,
107
108         .barker_corr_th_min = 190,
109         .barker_corr_th_min_mrc = 390,
110         .nrg_th_cca = 62,
111 };
112
113 static struct iwl_sensitivity_ranges iwl5150_sensitivity = {
114         .min_nrg_cck = 95,
115         .max_nrg_cck = 0, /* not used, set to 0 */
116         .auto_corr_min_ofdm = 90,
117         .auto_corr_min_ofdm_mrc = 170,
118         .auto_corr_min_ofdm_x1 = 105,
119         .auto_corr_min_ofdm_mrc_x1 = 220,
120
121         .auto_corr_max_ofdm = 120,
122         .auto_corr_max_ofdm_mrc = 210,
123         /* max = min for performance bug in 5150 DSP */
124         .auto_corr_max_ofdm_x1 = 105,
125         .auto_corr_max_ofdm_mrc_x1 = 220,
126
127         .auto_corr_min_cck = 125,
128         .auto_corr_max_cck = 200,
129         .auto_corr_min_cck_mrc = 170,
130         .auto_corr_max_cck_mrc = 400,
131         .nrg_th_cck = 95,
132         .nrg_th_ofdm = 95,
133
134         .barker_corr_th_min = 190,
135         .barker_corr_th_min_mrc = 390,
136         .nrg_th_cca = 62,
137 };
138
139 #define IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF   (-5)
140
141 static s32 iwl_temp_calib_to_offset(struct iwl_priv *priv)
142 {
143         u16 temperature, voltage;
144         __le16 *temp_calib = (__le16 *)iwl_eeprom_query_addr(priv,
145                                 EEPROM_KELVIN_TEMPERATURE);
146
147         temperature = le16_to_cpu(temp_calib[0]);
148         voltage = le16_to_cpu(temp_calib[1]);
149
150         /* offset = temp - volt / coeff */
151         return (s32)(temperature - voltage / IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF);
152 }
153
154 static void iwl5150_set_ct_threshold(struct iwl_priv *priv)
155 {
156         const s32 volt2temp_coef = IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF;
157         s32 threshold = (s32)CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD_LEGACY) -
158                         iwl_temp_calib_to_offset(priv);
159
160         hw_params(priv).ct_kill_threshold = threshold * volt2temp_coef;
161 }
162
163 static void iwl5000_set_ct_threshold(struct iwl_priv *priv)
164 {
165         /* want Celsius */
166         hw_params(priv).ct_kill_threshold = CT_KILL_THRESHOLD_LEGACY;
167 }
168
169 static int iwl5000_hw_set_hw_params(struct iwl_priv *priv)
170 {
171         if (iwlagn_mod_params.num_of_queues >= IWL_MIN_NUM_QUEUES &&
172             iwlagn_mod_params.num_of_queues <= IWLAGN_NUM_QUEUES)
173                 priv->cfg->base_params->num_of_queues =
174                         iwlagn_mod_params.num_of_queues;
175
176         hw_params(priv).max_txq_num = priv->cfg->base_params->num_of_queues;
177         priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWLAGN_BROADCAST_ID;
178
179         hw_params(priv).max_data_size = IWLAGN_RTC_DATA_SIZE;
180         hw_params(priv).max_inst_size = IWLAGN_RTC_INST_SIZE;
181
182         hw_params(priv).ht40_channel =  BIT(IEEE80211_BAND_2GHZ) |
183                                         BIT(IEEE80211_BAND_5GHZ);
184
185         hw_params(priv).tx_chains_num = num_of_ant(priv->cfg->valid_tx_ant);
186         hw_params(priv).rx_chains_num = num_of_ant(priv->cfg->valid_rx_ant);
187         hw_params(priv).valid_tx_ant = priv->cfg->valid_tx_ant;
188         hw_params(priv).valid_rx_ant = priv->cfg->valid_rx_ant;
189
190         iwl5000_set_ct_threshold(priv);
191
192         /* Set initial sensitivity parameters */
193         /* Set initial calibration set */
194         hw_params(priv).sens = &iwl5000_sensitivity;
195         hw_params(priv).calib_init_cfg =
196                 BIT(IWL_CALIB_XTAL)             |
197                 BIT(IWL_CALIB_LO)               |
198                 BIT(IWL_CALIB_TX_IQ)            |
199                 BIT(IWL_CALIB_TX_IQ_PERD)       |
200                 BIT(IWL_CALIB_BASE_BAND);
201
202         return 0;
203 }
204
205 static int iwl5150_hw_set_hw_params(struct iwl_priv *priv)
206 {
207         if (iwlagn_mod_params.num_of_queues >= IWL_MIN_NUM_QUEUES &&
208             iwlagn_mod_params.num_of_queues <= IWLAGN_NUM_QUEUES)
209                 priv->cfg->base_params->num_of_queues =
210                         iwlagn_mod_params.num_of_queues;
211
212         hw_params(priv).max_txq_num = priv->cfg->base_params->num_of_queues;
213         priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWLAGN_BROADCAST_ID;
214
215         hw_params(priv).max_data_size = IWLAGN_RTC_DATA_SIZE;
216         hw_params(priv).max_inst_size = IWLAGN_RTC_INST_SIZE;
217
218         hw_params(priv).ht40_channel =  BIT(IEEE80211_BAND_2GHZ) |
219                                         BIT(IEEE80211_BAND_5GHZ);
220
221         hw_params(priv).tx_chains_num = num_of_ant(priv->cfg->valid_tx_ant);
222         hw_params(priv).rx_chains_num = num_of_ant(priv->cfg->valid_rx_ant);
223         hw_params(priv).valid_tx_ant = priv->cfg->valid_tx_ant;
224         hw_params(priv).valid_rx_ant = priv->cfg->valid_rx_ant;
225
226         iwl5150_set_ct_threshold(priv);
227
228         /* Set initial sensitivity parameters */
229         /* Set initial calibration set */
230         hw_params(priv).sens = &iwl5150_sensitivity;
231         hw_params(priv).calib_init_cfg =
232                 BIT(IWL_CALIB_LO)               |
233                 BIT(IWL_CALIB_TX_IQ)            |
234                 BIT(IWL_CALIB_BASE_BAND);
235         if (priv->cfg->need_dc_calib)
236                 hw_params(priv).calib_init_cfg |= BIT(IWL_CALIB_DC);
237
238         return 0;
239 }
240
241 static void iwl5150_temperature(struct iwl_priv *priv)
242 {
243         u32 vt = 0;
244         s32 offset =  iwl_temp_calib_to_offset(priv);
245
246         vt = le32_to_cpu(priv->statistics.common.temperature);
247         vt = vt / IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF + offset;
248         /* now vt hold the temperature in Kelvin */
249         priv->temperature = KELVIN_TO_CELSIUS(vt);
250         iwl_tt_handler(priv);
251 }
252
253 static int iwl5000_hw_channel_switch(struct iwl_priv *priv,
254                                      struct ieee80211_channel_switch *ch_switch)
255 {
256         /*
257          * MULTI-FIXME
258          * See iwlagn_mac_channel_switch.
259          */
260         struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
261         struct iwl5000_channel_switch_cmd cmd;
262         const struct iwl_channel_info *ch_info;
263         u32 switch_time_in_usec, ucode_switch_time;
264         u16 ch;
265         u32 tsf_low;
266         u8 switch_count;
267         u16 beacon_interval = le16_to_cpu(ctx->timing.beacon_interval);
268         struct ieee80211_vif *vif = ctx->vif;
269         struct iwl_host_cmd hcmd = {
270                 .id = REPLY_CHANNEL_SWITCH,
271                 .len = { sizeof(cmd), },
272                 .flags = CMD_SYNC,
273                 .data = { &cmd, },
274         };
275
276         cmd.band = priv->band == IEEE80211_BAND_2GHZ;
277         ch = ch_switch->channel->hw_value;
278         IWL_DEBUG_11H(priv, "channel switch from %d to %d\n",
279                       ctx->active.channel, ch);
280         cmd.channel = cpu_to_le16(ch);
281         cmd.rxon_flags = ctx->staging.flags;
282         cmd.rxon_filter_flags = ctx->staging.filter_flags;
283         switch_count = ch_switch->count;
284         tsf_low = ch_switch->timestamp & 0x0ffffffff;
285         /*
286          * calculate the ucode channel switch time
287          * adding TSF as one of the factor for when to switch
288          */
289         if ((priv->ucode_beacon_time > tsf_low) && beacon_interval) {
290                 if (switch_count > ((priv->ucode_beacon_time - tsf_low) /
291                     beacon_interval)) {
292                         switch_count -= (priv->ucode_beacon_time -
293                                 tsf_low) / beacon_interval;
294                 } else
295                         switch_count = 0;
296         }
297         if (switch_count <= 1)
298                 cmd.switch_time = cpu_to_le32(priv->ucode_beacon_time);
299         else {
300                 switch_time_in_usec =
301                         vif->bss_conf.beacon_int * switch_count * TIME_UNIT;
302                 ucode_switch_time = iwl_usecs_to_beacons(priv,
303                                                          switch_time_in_usec,
304                                                          beacon_interval);
305                 cmd.switch_time = iwl_add_beacon_time(priv,
306                                                       priv->ucode_beacon_time,
307                                                       ucode_switch_time,
308                                                       beacon_interval);
309         }
310         IWL_DEBUG_11H(priv, "uCode time for the switch is 0x%x\n",
311                       cmd.switch_time);
312         ch_info = iwl_get_channel_info(priv, priv->band, ch);
313         if (ch_info)
314                 cmd.expect_beacon = is_channel_radar(ch_info);
315         else {
316                 IWL_ERR(priv, "invalid channel switch from %u to %u\n",
317                         ctx->active.channel, ch);
318                 return -EFAULT;
319         }
320
321         return iwl_trans_send_cmd(trans(priv), &hcmd);
322 }
323
324 static struct iwl_lib_ops iwl5000_lib = {
325         .set_hw_params = iwl5000_hw_set_hw_params,
326         .set_channel_switch = iwl5000_hw_channel_switch,
327         .nic_config = iwl5000_nic_config,
328         .eeprom_ops = {
329                 .regulatory_bands = {
330                         EEPROM_REG_BAND_1_CHANNELS,
331                         EEPROM_REG_BAND_2_CHANNELS,
332                         EEPROM_REG_BAND_3_CHANNELS,
333                         EEPROM_REG_BAND_4_CHANNELS,
334                         EEPROM_REG_BAND_5_CHANNELS,
335                         EEPROM_REG_BAND_24_HT40_CHANNELS,
336                         EEPROM_REG_BAND_52_HT40_CHANNELS
337                 },
338         },
339         .temperature = iwlagn_temperature,
340 };
341
342 static struct iwl_lib_ops iwl5150_lib = {
343         .set_hw_params = iwl5150_hw_set_hw_params,
344         .set_channel_switch = iwl5000_hw_channel_switch,
345         .nic_config = iwl5000_nic_config,
346         .eeprom_ops = {
347                 .regulatory_bands = {
348                         EEPROM_REG_BAND_1_CHANNELS,
349                         EEPROM_REG_BAND_2_CHANNELS,
350                         EEPROM_REG_BAND_3_CHANNELS,
351                         EEPROM_REG_BAND_4_CHANNELS,
352                         EEPROM_REG_BAND_5_CHANNELS,
353                         EEPROM_REG_BAND_24_HT40_CHANNELS,
354                         EEPROM_REG_BAND_52_HT40_CHANNELS
355                 },
356         },
357         .temperature = iwl5150_temperature,
358 };
359
360 static struct iwl_base_params iwl5000_base_params = {
361         .eeprom_size = IWLAGN_EEPROM_IMG_SIZE,
362         .num_of_queues = IWLAGN_NUM_QUEUES,
363         .num_of_ampdu_queues = IWLAGN_NUM_AMPDU_QUEUES,
364         .pll_cfg_val = CSR50_ANA_PLL_CFG_VAL,
365         .led_compensation = 51,
366         .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
367         .chain_noise_scale = 1000,
368         .wd_timeout = IWL_LONG_WD_TIMEOUT,
369         .max_event_log_size = 512,
370         .no_idle_support = true,
371         .wd_disable = true,
372 };
373 static struct iwl_ht_params iwl5000_ht_params = {
374         .ht_greenfield_support = true,
375 };
376
377 #define IWL_DEVICE_5000                                         \
378         .fw_name_pre = IWL5000_FW_PRE,                          \
379         .ucode_api_max = IWL5000_UCODE_API_MAX,                 \
380         .ucode_api_ok = IWL5000_UCODE_API_OK,                   \
381         .ucode_api_min = IWL5000_UCODE_API_MIN,                 \
382         .eeprom_ver = EEPROM_5000_EEPROM_VERSION,               \
383         .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION,       \
384         .lib = &iwl5000_lib,                                    \
385         .base_params = &iwl5000_base_params,                    \
386         .led_mode = IWL_LED_BLINK
387
388 struct iwl_cfg iwl5300_agn_cfg = {
389         .name = "Intel(R) Ultimate N WiFi Link 5300 AGN",
390         IWL_DEVICE_5000,
391         /* at least EEPROM 0x11A has wrong info */
392         .valid_tx_ant = ANT_ABC,        /* .cfg overwrite */
393         .valid_rx_ant = ANT_ABC,        /* .cfg overwrite */
394         .ht_params = &iwl5000_ht_params,
395 };
396
397 struct iwl_cfg iwl5100_bgn_cfg = {
398         .name = "Intel(R) WiFi Link 5100 BGN",
399         IWL_DEVICE_5000,
400         .valid_tx_ant = ANT_B,          /* .cfg overwrite */
401         .valid_rx_ant = ANT_AB,         /* .cfg overwrite */
402         .ht_params = &iwl5000_ht_params,
403 };
404
405 struct iwl_cfg iwl5100_abg_cfg = {
406         .name = "Intel(R) WiFi Link 5100 ABG",
407         IWL_DEVICE_5000,
408         .valid_tx_ant = ANT_B,          /* .cfg overwrite */
409         .valid_rx_ant = ANT_AB,         /* .cfg overwrite */
410 };
411
412 struct iwl_cfg iwl5100_agn_cfg = {
413         .name = "Intel(R) WiFi Link 5100 AGN",
414         IWL_DEVICE_5000,
415         .valid_tx_ant = ANT_B,          /* .cfg overwrite */
416         .valid_rx_ant = ANT_AB,         /* .cfg overwrite */
417         .ht_params = &iwl5000_ht_params,
418 };
419
420 struct iwl_cfg iwl5350_agn_cfg = {
421         .name = "Intel(R) WiMAX/WiFi Link 5350 AGN",
422         .fw_name_pre = IWL5000_FW_PRE,
423         .ucode_api_max = IWL5000_UCODE_API_MAX,
424         .ucode_api_ok = IWL5000_UCODE_API_OK,
425         .ucode_api_min = IWL5000_UCODE_API_MIN,
426         .eeprom_ver = EEPROM_5050_EEPROM_VERSION,
427         .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION,
428         .lib = &iwl5000_lib,
429         .base_params = &iwl5000_base_params,
430         .ht_params = &iwl5000_ht_params,
431         .led_mode = IWL_LED_BLINK,
432         .internal_wimax_coex = true,
433 };
434
435 #define IWL_DEVICE_5150                                         \
436         .fw_name_pre = IWL5150_FW_PRE,                          \
437         .ucode_api_max = IWL5150_UCODE_API_MAX,                 \
438         .ucode_api_ok = IWL5150_UCODE_API_OK,                   \
439         .ucode_api_min = IWL5150_UCODE_API_MIN,                 \
440         .eeprom_ver = EEPROM_5050_EEPROM_VERSION,               \
441         .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION,       \
442         .lib = &iwl5150_lib,                                    \
443         .base_params = &iwl5000_base_params,                    \
444         .need_dc_calib = true,                                  \
445         .led_mode = IWL_LED_BLINK,                              \
446         .internal_wimax_coex = true
447
448 struct iwl_cfg iwl5150_agn_cfg = {
449         .name = "Intel(R) WiMAX/WiFi Link 5150 AGN",
450         IWL_DEVICE_5150,
451         .ht_params = &iwl5000_ht_params,
452
453 };
454
455 struct iwl_cfg iwl5150_abg_cfg = {
456         .name = "Intel(R) WiMAX/WiFi Link 5150 ABG",
457         IWL_DEVICE_5150,
458 };
459
460 MODULE_FIRMWARE(IWL5000_MODULE_FIRMWARE(IWL5000_UCODE_API_OK));
461 MODULE_FIRMWARE(IWL5150_MODULE_FIRMWARE(IWL5150_UCODE_API_OK));