82719b7ec3493a37462d8a51edf404a9adf1ee07
[pandora-kernel.git] / drivers / net / wireless / iwlwifi / iwl-2000.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2008 - 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/skbuff.h>
32 #include <linux/netdevice.h>
33 #include <net/mac80211.h>
34 #include <linux/etherdevice.h>
35 #include <asm/unaligned.h>
36 #include <linux/stringify.h>
37
38 #include "iwl-eeprom.h"
39 #include "iwl-dev.h"
40 #include "iwl-core.h"
41 #include "iwl-io.h"
42 #include "iwl-sta.h"
43 #include "iwl-agn.h"
44 #include "iwl-helpers.h"
45 #include "iwl-agn-hw.h"
46 #include "iwl-6000-hw.h"
47 #include "iwl-shared.h"
48 #include "iwl-pci.h"
49
50 /* Highest firmware API version supported */
51 #define IWL2030_UCODE_API_MAX 6
52 #define IWL2000_UCODE_API_MAX 6
53 #define IWL105_UCODE_API_MAX 6
54 #define IWL135_UCODE_API_MAX 6
55
56 /* Oldest version we won't warn about */
57 #define IWL2030_UCODE_API_OK 5
58 #define IWL2000_UCODE_API_OK 5
59 #define IWL105_UCODE_API_OK 5
60 #define IWL135_UCODE_API_OK 5
61
62 /* Lowest firmware API version supported */
63 #define IWL2030_UCODE_API_MIN 5
64 #define IWL2000_UCODE_API_MIN 5
65 #define IWL105_UCODE_API_MIN 5
66 #define IWL135_UCODE_API_MIN 5
67
68 #define IWL2030_FW_PRE "iwlwifi-2030-"
69 #define IWL2030_MODULE_FIRMWARE(api) IWL2030_FW_PRE __stringify(api) ".ucode"
70
71 #define IWL2000_FW_PRE "iwlwifi-2000-"
72 #define IWL2000_MODULE_FIRMWARE(api) IWL2000_FW_PRE __stringify(api) ".ucode"
73
74 #define IWL105_FW_PRE "iwlwifi-105-"
75 #define IWL105_MODULE_FIRMWARE(api) IWL105_FW_PRE __stringify(api) ".ucode"
76
77 #define IWL135_FW_PRE "iwlwifi-135-"
78 #define IWL135_MODULE_FIRMWARE(api) IWL135_FW_PRE __stringify(api) ".ucode"
79
80 static void iwl2000_set_ct_threshold(struct iwl_priv *priv)
81 {
82         /* want Celsius */
83         hw_params(priv).ct_kill_threshold = CT_KILL_THRESHOLD;
84         hw_params(priv).ct_kill_exit_threshold = CT_KILL_EXIT_THRESHOLD;
85 }
86
87 /* NIC configuration for 2000 series */
88 static void iwl2000_nic_config(struct iwl_priv *priv)
89 {
90         iwl_rf_config(priv);
91
92         if (priv->cfg->iq_invert)
93                 iwl_set_bit(bus(priv), CSR_GP_DRIVER_REG,
94                             CSR_GP_DRIVER_REG_BIT_RADIO_IQ_INVER);
95 }
96
97 static struct iwl_sensitivity_ranges iwl2000_sensitivity = {
98         .min_nrg_cck = 97,
99         .max_nrg_cck = 0, /* not used, set to 0 */
100         .auto_corr_min_ofdm = 80,
101         .auto_corr_min_ofdm_mrc = 128,
102         .auto_corr_min_ofdm_x1 = 105,
103         .auto_corr_min_ofdm_mrc_x1 = 192,
104
105         .auto_corr_max_ofdm = 145,
106         .auto_corr_max_ofdm_mrc = 232,
107         .auto_corr_max_ofdm_x1 = 110,
108         .auto_corr_max_ofdm_mrc_x1 = 232,
109
110         .auto_corr_min_cck = 125,
111         .auto_corr_max_cck = 175,
112         .auto_corr_min_cck_mrc = 160,
113         .auto_corr_max_cck_mrc = 310,
114         .nrg_th_cck = 97,
115         .nrg_th_ofdm = 100,
116
117         .barker_corr_th_min = 190,
118         .barker_corr_th_min_mrc = 390,
119         .nrg_th_cca = 62,
120 };
121
122 static int iwl2000_hw_set_hw_params(struct iwl_priv *priv)
123 {
124         if (iwlagn_mod_params.num_of_queues >= IWL_MIN_NUM_QUEUES &&
125             iwlagn_mod_params.num_of_queues <= IWLAGN_NUM_QUEUES)
126                 priv->cfg->base_params->num_of_queues =
127                         iwlagn_mod_params.num_of_queues;
128
129         hw_params(priv).max_txq_num = priv->cfg->base_params->num_of_queues;
130         hw_params(priv).max_stations = IWLAGN_STATION_COUNT;
131         priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWLAGN_BROADCAST_ID;
132
133         hw_params(priv).max_data_size = IWL60_RTC_DATA_SIZE;
134         hw_params(priv).max_inst_size = IWL60_RTC_INST_SIZE;
135
136         hw_params(priv).ht40_channel =  BIT(IEEE80211_BAND_2GHZ);
137
138         hw_params(priv).tx_chains_num = num_of_ant(priv->cfg->valid_tx_ant);
139         if (priv->cfg->rx_with_siso_diversity)
140                 hw_params(priv).rx_chains_num = 1;
141         else
142                 hw_params(priv).rx_chains_num =
143                         num_of_ant(priv->cfg->valid_rx_ant);
144         hw_params(priv).valid_tx_ant = priv->cfg->valid_tx_ant;
145         hw_params(priv).valid_rx_ant = priv->cfg->valid_rx_ant;
146
147         iwl2000_set_ct_threshold(priv);
148
149         /* Set initial sensitivity parameters */
150         /* Set initial calibration set */
151         hw_params(priv).sens = &iwl2000_sensitivity;
152         hw_params(priv).calib_init_cfg =
153                 BIT(IWL_CALIB_XTAL)             |
154                 BIT(IWL_CALIB_LO)               |
155                 BIT(IWL_CALIB_TX_IQ)            |
156                 BIT(IWL_CALIB_BASE_BAND);
157         if (priv->cfg->need_dc_calib)
158                 hw_params(priv).calib_rt_cfg |= IWL_CALIB_CFG_DC_IDX;
159         if (priv->cfg->need_temp_offset_calib)
160                 hw_params(priv).calib_init_cfg |= BIT(IWL_CALIB_TEMP_OFFSET);
161
162         return 0;
163 }
164
165 static struct iwl_lib_ops iwl2000_lib = {
166         .set_hw_params = iwl2000_hw_set_hw_params,
167         .nic_config = iwl2000_nic_config,
168         .eeprom_ops = {
169                 .regulatory_bands = {
170                         EEPROM_REG_BAND_1_CHANNELS,
171                         EEPROM_REG_BAND_2_CHANNELS,
172                         EEPROM_REG_BAND_3_CHANNELS,
173                         EEPROM_REG_BAND_4_CHANNELS,
174                         EEPROM_REG_BAND_5_CHANNELS,
175                         EEPROM_6000_REG_BAND_24_HT40_CHANNELS,
176                         EEPROM_REGULATORY_BAND_NO_HT40,
177                 },
178                 .update_enhanced_txpower = iwl_eeprom_enhanced_txpower,
179         },
180         .temperature = iwlagn_temperature,
181 };
182
183 static struct iwl_lib_ops iwl2030_lib = {
184         .set_hw_params = iwl2000_hw_set_hw_params,
185         .bt_rx_handler_setup = iwlagn_bt_rx_handler_setup,
186         .bt_setup_deferred_work = iwlagn_bt_setup_deferred_work,
187         .cancel_deferred_work = iwlagn_bt_cancel_deferred_work,
188         .nic_config = iwl2000_nic_config,
189         .eeprom_ops = {
190                 .regulatory_bands = {
191                         EEPROM_REG_BAND_1_CHANNELS,
192                         EEPROM_REG_BAND_2_CHANNELS,
193                         EEPROM_REG_BAND_3_CHANNELS,
194                         EEPROM_REG_BAND_4_CHANNELS,
195                         EEPROM_REG_BAND_5_CHANNELS,
196                         EEPROM_6000_REG_BAND_24_HT40_CHANNELS,
197                         EEPROM_REGULATORY_BAND_NO_HT40,
198                 },
199                 .update_enhanced_txpower = iwl_eeprom_enhanced_txpower,
200         },
201         .temperature = iwlagn_temperature,
202 };
203
204 static struct iwl_base_params iwl2000_base_params = {
205         .eeprom_size = OTP_LOW_IMAGE_SIZE,
206         .num_of_queues = IWLAGN_NUM_QUEUES,
207         .num_of_ampdu_queues = IWLAGN_NUM_AMPDU_QUEUES,
208         .pll_cfg_val = 0,
209         .max_ll_items = OTP_MAX_LL_ITEMS_2x00,
210         .shadow_ram_support = true,
211         .led_compensation = 51,
212         .adv_thermal_throttle = true,
213         .support_ct_kill_exit = true,
214         .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF,
215         .chain_noise_scale = 1000,
216         .wd_timeout = IWL_DEF_WD_TIMEOUT,
217         .max_event_log_size = 512,
218         .shadow_reg_enable = true,
219         .hd_v2 = true,
220 };
221
222
223 static struct iwl_base_params iwl2030_base_params = {
224         .eeprom_size = OTP_LOW_IMAGE_SIZE,
225         .num_of_queues = IWLAGN_NUM_QUEUES,
226         .num_of_ampdu_queues = IWLAGN_NUM_AMPDU_QUEUES,
227         .pll_cfg_val = 0,
228         .max_ll_items = OTP_MAX_LL_ITEMS_2x00,
229         .shadow_ram_support = true,
230         .led_compensation = 57,
231         .adv_thermal_throttle = true,
232         .support_ct_kill_exit = true,
233         .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF,
234         .chain_noise_scale = 1000,
235         .wd_timeout = IWL_LONG_WD_TIMEOUT,
236         .max_event_log_size = 512,
237         .shadow_reg_enable = true,
238         .hd_v2 = true,
239 };
240
241 static struct iwl_ht_params iwl2000_ht_params = {
242         .ht_greenfield_support = true,
243         .use_rts_for_aggregation = true, /* use rts/cts protection */
244 };
245
246 static struct iwl_bt_params iwl2030_bt_params = {
247         /* Due to bluetooth, we transmit 2.4 GHz probes only on antenna A */
248         .advanced_bt_coexist = true,
249         .agg_time_limit = BT_AGG_THRESHOLD_DEF,
250         .bt_init_traffic_load = IWL_BT_COEX_TRAFFIC_LOAD_NONE,
251         .bt_prio_boost = IWLAGN_BT_PRIO_BOOST_DEFAULT,
252         .bt_sco_disable = true,
253         .bt_session_2 = true,
254 };
255
256 #define IWL_DEVICE_2000                                         \
257         .fw_name_pre = IWL2000_FW_PRE,                          \
258         .ucode_api_max = IWL2000_UCODE_API_MAX,                 \
259         .ucode_api_ok = IWL2000_UCODE_API_OK,                   \
260         .ucode_api_min = IWL2000_UCODE_API_MIN,                 \
261         .eeprom_ver = EEPROM_2000_EEPROM_VERSION,               \
262         .eeprom_calib_ver = EEPROM_2000_TX_POWER_VERSION,       \
263         .lib = &iwl2000_lib,                                    \
264         .base_params = &iwl2000_base_params,                    \
265         .need_dc_calib = true,                                  \
266         .need_temp_offset_calib = true,                         \
267         .led_mode = IWL_LED_RF_STATE,                           \
268         .iq_invert = true                                       \
269
270 struct iwl_cfg iwl2000_2bgn_cfg = {
271         .name = "2000 Series 2x2 BGN",
272         IWL_DEVICE_2000,
273         .ht_params = &iwl2000_ht_params,
274 };
275
276 struct iwl_cfg iwl2000_2bg_cfg = {
277         .name = "2000 Series 2x2 BG",
278         IWL_DEVICE_2000,
279 };
280
281 struct iwl_cfg iwl2000_2bgn_d_cfg = {
282         .name = "2000D Series 2x2 BGN",
283         IWL_DEVICE_2000,
284         .ht_params = &iwl2000_ht_params,
285 };
286
287 #define IWL_DEVICE_2030                                         \
288         .fw_name_pre = IWL2030_FW_PRE,                          \
289         .ucode_api_max = IWL2030_UCODE_API_MAX,                 \
290         .ucode_api_ok = IWL2030_UCODE_API_OK,                   \
291         .ucode_api_min = IWL2030_UCODE_API_MIN,                 \
292         .eeprom_ver = EEPROM_2000_EEPROM_VERSION,               \
293         .eeprom_calib_ver = EEPROM_2000_TX_POWER_VERSION,       \
294         .lib = &iwl2030_lib,                                    \
295         .base_params = &iwl2030_base_params,                    \
296         .bt_params = &iwl2030_bt_params,                        \
297         .need_dc_calib = true,                                  \
298         .need_temp_offset_calib = true,                         \
299         .led_mode = IWL_LED_RF_STATE,                           \
300         .adv_pm = true,                                         \
301         .iq_invert = true                                       \
302
303 struct iwl_cfg iwl2030_2bgn_cfg = {
304         .name = "2000 Series 2x2 BGN/BT",
305         IWL_DEVICE_2030,
306         .ht_params = &iwl2000_ht_params,
307 };
308
309 struct iwl_cfg iwl2030_2bg_cfg = {
310         .name = "2000 Series 2x2 BG/BT",
311         IWL_DEVICE_2030,
312 };
313
314 #define IWL_DEVICE_105                                          \
315         .fw_name_pre = IWL105_FW_PRE,                           \
316         .ucode_api_max = IWL105_UCODE_API_MAX,                  \
317         .ucode_api_ok = IWL105_UCODE_API_OK,                    \
318         .ucode_api_min = IWL105_UCODE_API_MIN,                  \
319         .eeprom_ver = EEPROM_2000_EEPROM_VERSION,               \
320         .eeprom_calib_ver = EEPROM_2000_TX_POWER_VERSION,       \
321         .lib = &iwl2000_lib,                                    \
322         .base_params = &iwl2000_base_params,                    \
323         .need_dc_calib = true,                                  \
324         .need_temp_offset_calib = true,                         \
325         .led_mode = IWL_LED_RF_STATE,                           \
326         .adv_pm = true,                                         \
327         .rx_with_siso_diversity = true,                         \
328         .iq_invert = true                                       \
329
330 struct iwl_cfg iwl105_bg_cfg = {
331         .name = "105 Series 1x1 BG",
332         IWL_DEVICE_105,
333 };
334
335 struct iwl_cfg iwl105_bgn_cfg = {
336         .name = "105 Series 1x1 BGN",
337         IWL_DEVICE_105,
338         .ht_params = &iwl2000_ht_params,
339 };
340
341 #define IWL_DEVICE_135                                          \
342         .fw_name_pre = IWL135_FW_PRE,                           \
343         .ucode_api_max = IWL135_UCODE_API_MAX,                  \
344         .ucode_api_ok = IWL135_UCODE_API_OK,                    \
345         .ucode_api_min = IWL135_UCODE_API_MIN,                  \
346         .eeprom_ver = EEPROM_2000_EEPROM_VERSION,               \
347         .eeprom_calib_ver = EEPROM_2000_TX_POWER_VERSION,       \
348         .lib = &iwl2030_lib,                                    \
349         .base_params = &iwl2030_base_params,                    \
350         .bt_params = &iwl2030_bt_params,                        \
351         .need_dc_calib = true,                                  \
352         .need_temp_offset_calib = true,                         \
353         .led_mode = IWL_LED_RF_STATE,                           \
354         .adv_pm = true,                                         \
355         .rx_with_siso_diversity = true,                         \
356         .iq_invert = true                                       \
357
358 struct iwl_cfg iwl135_bg_cfg = {
359         .name = "135 Series 1x1 BG/BT",
360         IWL_DEVICE_135,
361 };
362
363 struct iwl_cfg iwl135_bgn_cfg = {
364         .name = "135 Series 1x1 BGN/BT",
365         IWL_DEVICE_135,
366         .ht_params = &iwl2000_ht_params,
367 };
368
369 MODULE_FIRMWARE(IWL2000_MODULE_FIRMWARE(IWL2000_UCODE_API_MAX));
370 MODULE_FIRMWARE(IWL2030_MODULE_FIRMWARE(IWL2030_UCODE_API_MAX));
371 MODULE_FIRMWARE(IWL105_MODULE_FIRMWARE(IWL105_UCODE_API_MAX));
372 MODULE_FIRMWARE(IWL135_MODULE_FIRMWARE(IWL135_UCODE_API_MAX));