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