iwl-2000.c revision 916b337310969dd5eef35be0988a6bf768c138f9
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 <linux/wireless.h>
34#include <net/mac80211.h>
35#include <linux/etherdevice.h>
36#include <asm/unaligned.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
48/* Highest firmware API version supported */
49#define IWL2030_UCODE_API_MAX 5
50#define IWL2000_UCODE_API_MAX 5
51#define IWL105_UCODE_API_MAX 5
52
53/* Lowest firmware API version supported */
54#define IWL2030_UCODE_API_MIN 5
55#define IWL2000_UCODE_API_MIN 5
56#define IWL105_UCODE_API_MIN 5
57
58#define IWL2030_FW_PRE "iwlwifi-2030-"
59#define IWL2030_MODULE_FIRMWARE(api) IWL2030_FW_PRE #api ".ucode"
60
61#define IWL2000_FW_PRE "iwlwifi-2000-"
62#define IWL2000_MODULE_FIRMWARE(api) IWL2000_FW_PRE #api ".ucode"
63
64#define IWL105_FW_PRE "iwlwifi-105-"
65#define IWL105_MODULE_FIRMWARE(api) IWL105_FW_PRE #api ".ucode"
66
67static void iwl2000_set_ct_threshold(struct iwl_priv *priv)
68{
69	/* want Celsius */
70	priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD;
71	priv->hw_params.ct_kill_exit_threshold = CT_KILL_EXIT_THRESHOLD;
72}
73
74/* NIC configuration for 2000 series */
75static void iwl2000_nic_config(struct iwl_priv *priv)
76{
77	u16 radio_cfg;
78
79	radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
80
81	/* write radio config values to register */
82	if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) <= EEPROM_RF_CONFIG_TYPE_MAX)
83		iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
84			    EEPROM_RF_CFG_TYPE_MSK(radio_cfg) |
85			    EEPROM_RF_CFG_STEP_MSK(radio_cfg) |
86			    EEPROM_RF_CFG_DASH_MSK(radio_cfg));
87
88	/* set CSR_HW_CONFIG_REG for uCode use */
89	iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
90		    CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
91		    CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
92
93	if (priv->cfg->iq_invert)
94		iwl_set_bit(priv, CSR_GP_DRIVER_REG,
95			    CSR_GP_DRIVER_REG_BIT_RADIO_IQ_INVER);
96
97	if (priv->cfg->disable_otp_refresh)
98		iwl_write_prph(priv, APMG_ANALOG_SVR_REG, 0x80000010);
99}
100
101static struct iwl_sensitivity_ranges iwl2000_sensitivity = {
102	.min_nrg_cck = 97,
103	.max_nrg_cck = 0, /* not used, set to 0 */
104	.auto_corr_min_ofdm = 80,
105	.auto_corr_min_ofdm_mrc = 128,
106	.auto_corr_min_ofdm_x1 = 105,
107	.auto_corr_min_ofdm_mrc_x1 = 192,
108
109	.auto_corr_max_ofdm = 145,
110	.auto_corr_max_ofdm_mrc = 232,
111	.auto_corr_max_ofdm_x1 = 110,
112	.auto_corr_max_ofdm_mrc_x1 = 232,
113
114	.auto_corr_min_cck = 125,
115	.auto_corr_max_cck = 175,
116	.auto_corr_min_cck_mrc = 160,
117	.auto_corr_max_cck_mrc = 310,
118	.nrg_th_cck = 97,
119	.nrg_th_ofdm = 100,
120
121	.barker_corr_th_min = 190,
122	.barker_corr_th_min_mrc = 390,
123	.nrg_th_cca = 62,
124};
125
126static int iwl2000_hw_set_hw_params(struct iwl_priv *priv)
127{
128	if (iwlagn_mod_params.num_of_queues >= IWL_MIN_NUM_QUEUES &&
129	    iwlagn_mod_params.num_of_queues <= IWLAGN_NUM_QUEUES)
130		priv->cfg->base_params->num_of_queues =
131			iwlagn_mod_params.num_of_queues;
132
133	priv->hw_params.max_txq_num = priv->cfg->base_params->num_of_queues;
134	priv->hw_params.dma_chnl_num = FH50_TCSR_CHNL_NUM;
135	priv->hw_params.scd_bc_tbls_size =
136		priv->cfg->base_params->num_of_queues *
137		sizeof(struct iwlagn_scd_bc_tbl);
138	priv->hw_params.tfd_size = sizeof(struct iwl_tfd);
139	priv->hw_params.max_stations = IWLAGN_STATION_COUNT;
140	priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWLAGN_BROADCAST_ID;
141
142	priv->hw_params.max_data_size = IWL60_RTC_DATA_SIZE;
143	priv->hw_params.max_inst_size = IWL60_RTC_INST_SIZE;
144
145	priv->hw_params.ht40_channel =  BIT(IEEE80211_BAND_2GHZ) |
146					BIT(IEEE80211_BAND_5GHZ);
147	priv->hw_params.rx_wrt_ptr_reg = FH_RSCSR_CHNL0_WPTR;
148
149	priv->hw_params.tx_chains_num = num_of_ant(priv->cfg->valid_tx_ant);
150	if (priv->cfg->rx_with_siso_diversity)
151		priv->hw_params.rx_chains_num = 1;
152	else
153		priv->hw_params.rx_chains_num =
154			num_of_ant(priv->cfg->valid_rx_ant);
155	priv->hw_params.valid_tx_ant = priv->cfg->valid_tx_ant;
156	priv->hw_params.valid_rx_ant = priv->cfg->valid_rx_ant;
157
158	iwl2000_set_ct_threshold(priv);
159
160	/* Set initial sensitivity parameters */
161	/* Set initial calibration set */
162	priv->hw_params.sens = &iwl2000_sensitivity;
163	priv->hw_params.calib_init_cfg =
164		BIT(IWL_CALIB_XTAL)             |
165		BIT(IWL_CALIB_LO)               |
166		BIT(IWL_CALIB_TX_IQ)            |
167		BIT(IWL_CALIB_BASE_BAND);
168	if (priv->cfg->need_dc_calib)
169		priv->hw_params.calib_rt_cfg |= BIT(IWL_CALIB_CFG_DC_IDX);
170	if (priv->cfg->need_temp_offset_calib)
171		priv->hw_params.calib_init_cfg |= BIT(IWL_CALIB_TEMP_OFFSET);
172
173	priv->hw_params.beacon_time_tsf_bits = IWLAGN_EXT_BEACON_TIME_POS;
174
175	return 0;
176}
177
178static struct iwl_lib_ops iwl2000_lib = {
179	.set_hw_params = iwl2000_hw_set_hw_params,
180	.rx_handler_setup = iwlagn_rx_handler_setup,
181	.setup_deferred_work = iwlagn_bt_setup_deferred_work,
182	.cancel_deferred_work = iwlagn_bt_cancel_deferred_work,
183	.is_valid_rtc_data_addr = iwlagn_hw_valid_rtc_data_addr,
184	.update_chain_flags = iwl_update_chain_flags,
185	.apm_ops = {
186		.init = iwl_apm_init,
187		.config = iwl2000_nic_config,
188	},
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		.query_addr = iwlagn_eeprom_query_addr,
200		.update_enhanced_txpower = iwlcore_eeprom_enhanced_txpower,
201	},
202	.temp_ops = {
203		.temperature = iwlagn_temperature,
204	},
205};
206
207static const struct iwl_ops iwl2000_ops = {
208	.lib = &iwl2000_lib,
209	.hcmd = &iwlagn_hcmd,
210	.utils = &iwlagn_hcmd_utils,
211};
212
213static const struct iwl_ops iwl2030_ops = {
214	.lib = &iwl2000_lib,
215	.hcmd = &iwlagn_bt_hcmd,
216	.utils = &iwlagn_hcmd_utils,
217};
218
219static const struct iwl_ops iwl105_ops = {
220	.lib = &iwl2000_lib,
221	.hcmd = &iwlagn_hcmd,
222	.utils = &iwlagn_hcmd_utils,
223};
224
225static const struct iwl_ops iwl135_ops = {
226	.lib = &iwl2000_lib,
227	.hcmd = &iwlagn_bt_hcmd,
228	.utils = &iwlagn_hcmd_utils,
229};
230
231static struct iwl_base_params iwl2000_base_params = {
232	.eeprom_size = OTP_LOW_IMAGE_SIZE,
233	.num_of_queues = IWLAGN_NUM_QUEUES,
234	.num_of_ampdu_queues = IWLAGN_NUM_AMPDU_QUEUES,
235	.pll_cfg_val = 0,
236	.max_ll_items = OTP_MAX_LL_ITEMS_2x00,
237	.shadow_ram_support = true,
238	.led_compensation = 51,
239	.chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
240	.adv_thermal_throttle = true,
241	.support_ct_kill_exit = true,
242	.plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF,
243	.chain_noise_scale = 1000,
244	.wd_timeout = IWL_DEF_WD_TIMEOUT,
245	.max_event_log_size = 512,
246	.shadow_reg_enable = true,
247};
248
249
250static struct iwl_base_params iwl2030_base_params = {
251	.eeprom_size = OTP_LOW_IMAGE_SIZE,
252	.num_of_queues = IWLAGN_NUM_QUEUES,
253	.num_of_ampdu_queues = IWLAGN_NUM_AMPDU_QUEUES,
254	.pll_cfg_val = 0,
255	.max_ll_items = OTP_MAX_LL_ITEMS_2x00,
256	.shadow_ram_support = true,
257	.led_compensation = 57,
258	.chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
259	.adv_thermal_throttle = true,
260	.support_ct_kill_exit = true,
261	.plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF,
262	.chain_noise_scale = 1000,
263	.wd_timeout = IWL_LONG_WD_TIMEOUT,
264	.max_event_log_size = 512,
265	.shadow_reg_enable = true,
266};
267
268static struct iwl_ht_params iwl2000_ht_params = {
269	.ht_greenfield_support = true,
270	.use_rts_for_aggregation = true, /* use rts/cts protection */
271};
272
273static struct iwl_bt_params iwl2030_bt_params = {
274	/* Due to bluetooth, we transmit 2.4 GHz probes only on antenna A */
275	.advanced_bt_coexist = true,
276	.agg_time_limit = BT_AGG_THRESHOLD_DEF,
277	.bt_init_traffic_load = IWL_BT_COEX_TRAFFIC_LOAD_NONE,
278	.bt_prio_boost = IWLAGN_BT_PRIO_BOOST_DEFAULT,
279	.bt_sco_disable = true,
280	.bt_session_2 = true,
281};
282
283#define IWL_DEVICE_2000						\
284	.fw_name_pre = IWL2000_FW_PRE,				\
285	.ucode_api_max = IWL2000_UCODE_API_MAX,			\
286	.ucode_api_min = IWL2000_UCODE_API_MIN,			\
287	.eeprom_ver = EEPROM_2000_EEPROM_VERSION,		\
288	.eeprom_calib_ver = EEPROM_2000_TX_POWER_VERSION,	\
289	.ops = &iwl2000_ops,					\
290	.base_params = &iwl2000_base_params,			\
291	.need_dc_calib = true,					\
292	.need_temp_offset_calib = true,				\
293	.led_mode = IWL_LED_RF_STATE,				\
294	.iq_invert = true,					\
295	.disable_otp_refresh = true				\
296
297struct iwl_cfg iwl2000_2bgn_cfg = {
298	.name = "2000 Series 2x2 BGN",
299	IWL_DEVICE_2000,
300	.ht_params = &iwl2000_ht_params,
301};
302
303struct iwl_cfg iwl2000_2bg_cfg = {
304	.name = "2000 Series 2x2 BG",
305	IWL_DEVICE_2000,
306};
307
308#define IWL_DEVICE_2030						\
309	.fw_name_pre = IWL2030_FW_PRE,				\
310	.ucode_api_max = IWL2030_UCODE_API_MAX,			\
311	.ucode_api_min = IWL2030_UCODE_API_MIN,			\
312	.eeprom_ver = EEPROM_2000_EEPROM_VERSION,		\
313	.eeprom_calib_ver = EEPROM_2000_TX_POWER_VERSION,	\
314	.ops = &iwl2030_ops,					\
315	.base_params = &iwl2030_base_params,			\
316	.bt_params = &iwl2030_bt_params,			\
317	.need_dc_calib = true,					\
318	.need_temp_offset_calib = true,				\
319	.led_mode = IWL_LED_RF_STATE,				\
320	.adv_pm = true,						\
321	.iq_invert = true					\
322
323struct iwl_cfg iwl2030_2bgn_cfg = {
324	.name = "2000 Series 2x2 BGN/BT",
325	IWL_DEVICE_2030,
326	.ht_params = &iwl2000_ht_params,
327};
328
329struct iwl_cfg iwl2030_2bg_cfg = {
330	.name = "2000 Series 2x2 BG/BT",
331	IWL_DEVICE_2030,
332};
333
334#define IWL_DEVICE_105						\
335	.fw_name_pre = IWL105_FW_PRE,				\
336	.ucode_api_max = IWL105_UCODE_API_MAX,			\
337	.ucode_api_min = IWL105_UCODE_API_MIN,			\
338	.eeprom_ver = EEPROM_2000_EEPROM_VERSION,		\
339	.eeprom_calib_ver = EEPROM_2000_TX_POWER_VERSION,	\
340	.ops = &iwl105_ops,					\
341	.base_params = &iwl2000_base_params,			\
342	.need_dc_calib = true,					\
343	.need_temp_offset_calib = true,				\
344	.led_mode = IWL_LED_RF_STATE,				\
345	.adv_pm = true,						\
346	.rx_with_siso_diversity = true				\
347
348struct iwl_cfg iwl105_bg_cfg = {
349	.name = "105 Series 1x1 BG",
350	IWL_DEVICE_105,
351};
352
353struct iwl_cfg iwl105_bgn_cfg = {
354	.name = "105 Series 1x1 BGN",
355	IWL_DEVICE_105,
356	.ht_params = &iwl2000_ht_params,
357};
358
359#define IWL_DEVICE_135						\
360	.fw_name_pre = IWL105_FW_PRE,				\
361	.ucode_api_max = IWL105_UCODE_API_MAX,			\
362	.ucode_api_min = IWL105_UCODE_API_MIN,			\
363	.eeprom_ver = EEPROM_2000_EEPROM_VERSION,		\
364	.eeprom_calib_ver = EEPROM_2000_TX_POWER_VERSION,	\
365	.ops = &iwl135_ops,					\
366	.base_params = &iwl2030_base_params,			\
367	.bt_params = &iwl2030_bt_params,			\
368	.need_dc_calib = true,					\
369	.need_temp_offset_calib = true,				\
370	.led_mode = IWL_LED_RF_STATE,				\
371	.adv_pm = true,						\
372	.rx_with_siso_diversity = true				\
373
374struct iwl_cfg iwl135_bg_cfg = {
375	.name = "105 Series 1x1 BG/BT",
376	IWL_DEVICE_135,
377};
378
379struct iwl_cfg iwl135_bgn_cfg = {
380	.name = "105 Series 1x1 BGN/BT",
381	IWL_DEVICE_135,
382	.ht_params = &iwl2000_ht_params,
383};
384
385MODULE_FIRMWARE(IWL2000_MODULE_FIRMWARE(IWL2000_UCODE_API_MAX));
386MODULE_FIRMWARE(IWL2030_MODULE_FIRMWARE(IWL2030_UCODE_API_MAX));
387MODULE_FIRMWARE(IWL105_MODULE_FIRMWARE(IWL105_UCODE_API_MAX));
388