On Tue, Nov 06, 2007 at 02:33:53AM -0800, akpm@linux-foundation.org wrote:
[mmotm.git] / drivers / net / wireless / wl12xx / wl1271_init.c
blobe45af075e67140fbc92dfa8f818fb04b6e5aa769
1 /*
2 * This file is part of wl1271
4 * Copyright (C) 2009 Nokia Corporation
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
24 #include <linux/kernel.h>
25 #include <linux/module.h>
27 #include "wl1271_init.h"
28 #include "wl12xx_80211.h"
29 #include "wl1271_acx.h"
30 #include "wl1271_cmd.h"
31 #include "wl1271_reg.h"
33 static int wl1271_init_hwenc_config(struct wl1271 *wl)
35 int ret;
37 ret = wl1271_acx_feature_cfg(wl);
38 if (ret < 0) {
39 wl1271_warning("couldn't set feature config");
40 return ret;
43 ret = wl1271_cmd_set_default_wep_key(wl, wl->default_key);
44 if (ret < 0) {
45 wl1271_warning("couldn't set default key");
46 return ret;
49 return 0;
52 static int wl1271_init_templates_config(struct wl1271 *wl)
54 int ret;
56 /* send empty templates for fw memory reservation */
57 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, NULL,
58 sizeof(struct wl12xx_probe_req_template));
59 if (ret < 0)
60 return ret;
62 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
63 sizeof(struct wl12xx_null_data_template));
64 if (ret < 0)
65 return ret;
67 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, NULL,
68 sizeof(struct wl12xx_ps_poll_template));
69 if (ret < 0)
70 return ret;
72 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
73 sizeof
74 (struct wl12xx_qos_null_data_template));
75 if (ret < 0)
76 return ret;
78 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE, NULL,
79 sizeof
80 (struct wl12xx_probe_resp_template));
81 if (ret < 0)
82 return ret;
84 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON, NULL,
85 sizeof
86 (struct wl12xx_beacon_template));
87 if (ret < 0)
88 return ret;
90 return 0;
93 static int wl1271_init_rx_config(struct wl1271 *wl, u32 config, u32 filter)
95 int ret;
97 ret = wl1271_acx_rx_msdu_life_time(wl, RX_MSDU_LIFETIME_DEF);
98 if (ret < 0)
99 return ret;
101 ret = wl1271_acx_rx_config(wl, config, filter);
102 if (ret < 0)
103 return ret;
105 return 0;
108 static int wl1271_init_phy_config(struct wl1271 *wl)
110 int ret;
112 ret = wl1271_acx_pd_threshold(wl);
113 if (ret < 0)
114 return ret;
116 ret = wl1271_acx_slot(wl, DEFAULT_SLOT_TIME);
117 if (ret < 0)
118 return ret;
120 ret = wl1271_acx_group_address_tbl(wl, true, NULL, 0);
121 if (ret < 0)
122 return ret;
124 ret = wl1271_acx_service_period_timeout(wl);
125 if (ret < 0)
126 return ret;
128 ret = wl1271_acx_rts_threshold(wl, RTS_THRESHOLD_DEF);
129 if (ret < 0)
130 return ret;
132 return 0;
135 static int wl1271_init_beacon_filter(struct wl1271 *wl)
137 int ret;
139 /* disable beacon filtering at this stage */
140 ret = wl1271_acx_beacon_filter_opt(wl, false);
141 if (ret < 0)
142 return ret;
144 ret = wl1271_acx_beacon_filter_table(wl);
145 if (ret < 0)
146 return ret;
148 return 0;
151 static int wl1271_init_pta(struct wl1271 *wl)
153 int ret;
155 ret = wl1271_acx_sg_enable(wl);
156 if (ret < 0)
157 return ret;
159 ret = wl1271_acx_sg_cfg(wl);
160 if (ret < 0)
161 return ret;
163 return 0;
166 static int wl1271_init_energy_detection(struct wl1271 *wl)
168 int ret;
170 ret = wl1271_acx_cca_threshold(wl);
171 if (ret < 0)
172 return ret;
174 return 0;
177 static int wl1271_init_beacon_broadcast(struct wl1271 *wl)
179 int ret;
181 ret = wl1271_acx_bcn_dtim_options(wl);
182 if (ret < 0)
183 return ret;
185 return 0;
188 static int wl1271_init_general_parms(struct wl1271 *wl)
190 struct wl1271_general_parms *gen_parms;
191 int ret;
193 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
194 if (!gen_parms)
195 return -ENOMEM;
197 gen_parms->id = TEST_CMD_INI_FILE_GENERAL_PARAM;
199 gen_parms->ref_clk = REF_CLK_38_4_E;
200 /* FIXME: magic numbers */
201 gen_parms->settling_time = 5;
202 gen_parms->clk_valid_on_wakeup = 0;
203 gen_parms->dc2dcmode = 0;
204 gen_parms->single_dual_band = 0;
205 gen_parms->tx_bip_fem_autodetect = 0;
206 gen_parms->tx_bip_fem_manufacturer = 1;
207 gen_parms->settings = 1;
209 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), 0);
210 if (ret < 0) {
211 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
212 return ret;
215 kfree(gen_parms);
216 return 0;
219 static int wl1271_init_radio_parms(struct wl1271 *wl)
222 * FIXME: All these magic numbers should be moved to some place where
223 * they can be configured (separate file?)
226 struct wl1271_radio_parms *radio_parms;
227 int ret;
228 u8 compensation[] = { 0xec, 0xf6, 0x00, 0x0c, 0x18, 0xf8, 0xfc, 0x00,
229 0x08, 0x10, 0xf0, 0xf8, 0x00, 0x0a, 0x14 };
231 u8 tx_rate_limits_normal[] = { 0x1e, 0x1f, 0x22, 0x24, 0x28, 0x29 };
232 u8 tx_rate_limits_degraded[] = { 0x1b, 0x1c, 0x1e, 0x20, 0x24, 0x25 };
234 u8 tx_channel_limits_11b[] = { 0x22, 0x50, 0x50, 0x50,
235 0x50, 0x50, 0x50, 0x50,
236 0x50, 0x50, 0x22, 0x50,
237 0x22, 0x50 };
239 u8 tx_channel_limits_ofdm[] = { 0x20, 0x50, 0x50, 0x50,
240 0x50, 0x50, 0x50, 0x50,
241 0x50, 0x50, 0x20, 0x50,
242 0x20, 0x50 };
244 u8 tx_pdv_rate_offsets[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
246 u8 tx_ibias[] = { 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x27 };
248 radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
249 if (!radio_parms)
250 return -ENOMEM;
252 radio_parms->id = TEST_CMD_INI_FILE_RADIO_PARAM;
254 /* Static radio parameters */
255 radio_parms->rx_trace_loss = 10;
256 radio_parms->tx_trace_loss = 10;
257 memcpy(radio_parms->rx_rssi_and_proc_compens, compensation,
258 sizeof(compensation));
260 /* We don't set the 5GHz -- N/A */
262 /* Dynamic radio parameters */
263 radio_parms->tx_ref_pd_voltage = cpu_to_le16(0x24e);
264 radio_parms->tx_ref_power = 0x78;
265 radio_parms->tx_offset_db = 0x0;
267 memcpy(radio_parms->tx_rate_limits_normal, tx_rate_limits_normal,
268 sizeof(tx_rate_limits_normal));
269 memcpy(radio_parms->tx_rate_limits_degraded, tx_rate_limits_degraded,
270 sizeof(tx_rate_limits_degraded));
272 memcpy(radio_parms->tx_channel_limits_11b, tx_channel_limits_11b,
273 sizeof(tx_channel_limits_11b));
274 memcpy(radio_parms->tx_channel_limits_ofdm, tx_channel_limits_ofdm,
275 sizeof(tx_channel_limits_ofdm));
276 memcpy(radio_parms->tx_pdv_rate_offsets, tx_pdv_rate_offsets,
277 sizeof(tx_pdv_rate_offsets));
278 memcpy(radio_parms->tx_ibias, tx_ibias,
279 sizeof(tx_ibias));
281 radio_parms->rx_fem_insertion_loss = 0x14;
283 ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
284 if (ret < 0)
285 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
287 kfree(radio_parms);
288 return ret;
291 int wl1271_hw_init(struct wl1271 *wl)
293 int ret;
295 ret = wl1271_init_general_parms(wl);
296 if (ret < 0)
297 return ret;
299 ret = wl1271_init_radio_parms(wl);
300 if (ret < 0)
301 return ret;
303 /* Template settings */
304 ret = wl1271_init_templates_config(wl);
305 if (ret < 0)
306 return ret;
308 /* Default memory configuration */
309 ret = wl1271_acx_init_mem_config(wl);
310 if (ret < 0)
311 return ret;
313 /* RX config */
314 ret = wl1271_init_rx_config(wl,
315 RX_CFG_PROMISCUOUS | RX_CFG_TSF,
316 RX_FILTER_OPTION_DEF);
317 /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
318 RX_FILTER_OPTION_FILTER_ALL); */
319 if (ret < 0)
320 goto out_free_memmap;
322 /* PHY layer config */
323 ret = wl1271_init_phy_config(wl);
324 if (ret < 0)
325 goto out_free_memmap;
327 /* Initialize connection monitoring thresholds */
328 ret = wl1271_acx_conn_monit_params(wl);
329 if (ret < 0)
330 goto out_free_memmap;
332 /* Beacon filtering */
333 ret = wl1271_init_beacon_filter(wl);
334 if (ret < 0)
335 goto out_free_memmap;
337 /* Configure TX patch complete interrupt behavior */
338 ret = wl1271_acx_tx_config_options(wl);
339 if (ret < 0)
340 goto out_free_memmap;
342 /* RX complete interrupt pacing */
343 ret = wl1271_acx_init_rx_interrupt(wl);
344 if (ret < 0)
345 goto out_free_memmap;
347 /* Bluetooth WLAN coexistence */
348 ret = wl1271_init_pta(wl);
349 if (ret < 0)
350 goto out_free_memmap;
352 /* Energy detection */
353 ret = wl1271_init_energy_detection(wl);
354 if (ret < 0)
355 goto out_free_memmap;
357 /* Beacons and boradcast settings */
358 ret = wl1271_init_beacon_broadcast(wl);
359 if (ret < 0)
360 goto out_free_memmap;
362 /* Default fragmentation threshold */
363 ret = wl1271_acx_frag_threshold(wl);
364 if (ret < 0)
365 goto out_free_memmap;
367 /* Default TID configuration */
368 ret = wl1271_acx_tid_cfg(wl);
369 if (ret < 0)
370 goto out_free_memmap;
372 /* Default AC configuration */
373 ret = wl1271_acx_ac_cfg(wl);
374 if (ret < 0)
375 goto out_free_memmap;
377 /* Configure TX rate classes */
378 ret = wl1271_acx_rate_policies(wl, ACX_RATE_MASK_ALL);
379 if (ret < 0)
380 goto out_free_memmap;
382 /* Enable data path */
383 ret = wl1271_cmd_data_path(wl, wl->channel, 1);
384 if (ret < 0)
385 goto out_free_memmap;
387 /* Configure for ELP power saving */
388 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
389 if (ret < 0)
390 goto out_free_memmap;
392 /* Configure HW encryption */
393 ret = wl1271_init_hwenc_config(wl);
394 if (ret < 0)
395 goto out_free_memmap;
397 /* Configure smart reflex */
398 ret = wl1271_acx_smart_reflex(wl);
399 if (ret < 0)
400 goto out_free_memmap;
402 return 0;
404 out_free_memmap:
405 kfree(wl->target_mem_map);
406 wl->target_mem_map = NULL;
408 return ret;