[ARM] pxa: Gumstix Verdex PCMCIA support
[linux-2.6/verdex.git] / drivers / net / wireless / wl12xx / wl1251_init.c
blobb2ee4f468fc41cf95277d4360de3502f42f39ffd
1 /*
2 * This file is part of wl1251
4 * Copyright (C) 2009 Nokia Corporation
6 * Contact: Kalle Valo <kalle.valo@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 "wl1251_init.h"
28 #include "wl12xx_80211.h"
29 #include "wl1251_acx.h"
30 #include "wl1251_cmd.h"
31 #include "wl1251_reg.h"
33 int wl1251_hw_init_hwenc_config(struct wl1251 *wl)
35 int ret;
37 ret = wl1251_acx_feature_cfg(wl);
38 if (ret < 0) {
39 wl1251_warning("couldn't set feature config");
40 return ret;
43 ret = wl1251_acx_default_key(wl, wl->default_key);
44 if (ret < 0) {
45 wl1251_warning("couldn't set default key");
46 return ret;
49 return 0;
52 int wl1251_hw_init_templates_config(struct wl1251 *wl)
54 int ret;
55 u8 partial_vbm[PARTIAL_VBM_MAX];
57 /* send empty templates for fw memory reservation */
58 ret = wl1251_cmd_template_set(wl, CMD_PROBE_REQ, NULL,
59 sizeof(struct wl12xx_probe_req_template));
60 if (ret < 0)
61 return ret;
63 ret = wl1251_cmd_template_set(wl, CMD_NULL_DATA, NULL,
64 sizeof(struct wl12xx_null_data_template));
65 if (ret < 0)
66 return ret;
68 ret = wl1251_cmd_template_set(wl, CMD_PS_POLL, NULL,
69 sizeof(struct wl12xx_ps_poll_template));
70 if (ret < 0)
71 return ret;
73 ret = wl1251_cmd_template_set(wl, CMD_QOS_NULL_DATA, NULL,
74 sizeof
75 (struct wl12xx_qos_null_data_template));
76 if (ret < 0)
77 return ret;
79 ret = wl1251_cmd_template_set(wl, CMD_PROBE_RESP, NULL,
80 sizeof
81 (struct wl12xx_probe_resp_template));
82 if (ret < 0)
83 return ret;
85 ret = wl1251_cmd_template_set(wl, CMD_BEACON, NULL,
86 sizeof
87 (struct wl12xx_beacon_template));
88 if (ret < 0)
89 return ret;
91 /* tim templates, first reserve space then allocate an empty one */
92 memset(partial_vbm, 0, PARTIAL_VBM_MAX);
93 ret = wl1251_cmd_vbm(wl, TIM_ELE_ID, partial_vbm, PARTIAL_VBM_MAX, 0);
94 if (ret < 0)
95 return ret;
97 ret = wl1251_cmd_vbm(wl, TIM_ELE_ID, partial_vbm, 1, 0);
98 if (ret < 0)
99 return ret;
101 return 0;
104 int wl1251_hw_init_rx_config(struct wl1251 *wl, u32 config, u32 filter)
106 int ret;
108 ret = wl1251_acx_rx_msdu_life_time(wl, RX_MSDU_LIFETIME_DEF);
109 if (ret < 0)
110 return ret;
112 ret = wl1251_acx_rx_config(wl, config, filter);
113 if (ret < 0)
114 return ret;
116 return 0;
119 int wl1251_hw_init_phy_config(struct wl1251 *wl)
121 int ret;
123 ret = wl1251_acx_pd_threshold(wl);
124 if (ret < 0)
125 return ret;
127 ret = wl1251_acx_slot(wl, DEFAULT_SLOT_TIME);
128 if (ret < 0)
129 return ret;
131 ret = wl1251_acx_group_address_tbl(wl);
132 if (ret < 0)
133 return ret;
135 ret = wl1251_acx_service_period_timeout(wl);
136 if (ret < 0)
137 return ret;
139 ret = wl1251_acx_rts_threshold(wl, RTS_THRESHOLD_DEF);
140 if (ret < 0)
141 return ret;
143 return 0;
146 int wl1251_hw_init_beacon_filter(struct wl1251 *wl)
148 int ret;
150 ret = wl1251_acx_beacon_filter_opt(wl);
151 if (ret < 0)
152 return ret;
154 ret = wl1251_acx_beacon_filter_table(wl);
155 if (ret < 0)
156 return ret;
158 return 0;
161 int wl1251_hw_init_pta(struct wl1251 *wl)
163 int ret;
165 ret = wl1251_acx_sg_enable(wl);
166 if (ret < 0)
167 return ret;
169 ret = wl1251_acx_sg_cfg(wl);
170 if (ret < 0)
171 return ret;
173 return 0;
176 int wl1251_hw_init_energy_detection(struct wl1251 *wl)
178 int ret;
180 ret = wl1251_acx_cca_threshold(wl);
181 if (ret < 0)
182 return ret;
184 return 0;
187 int wl1251_hw_init_beacon_broadcast(struct wl1251 *wl)
189 int ret;
191 ret = wl1251_acx_bcn_dtim_options(wl);
192 if (ret < 0)
193 return ret;
195 return 0;
198 int wl1251_hw_init_power_auth(struct wl1251 *wl)
200 return wl1251_acx_sleep_auth(wl, WL1251_PSM_CAM);
203 int wl1251_hw_init_mem_config(struct wl1251 *wl)
205 int ret;
207 ret = wl1251_acx_mem_cfg(wl);
208 if (ret < 0)
209 return ret;
211 wl->target_mem_map = kzalloc(sizeof(struct wl1251_acx_mem_map),
212 GFP_KERNEL);
213 if (!wl->target_mem_map) {
214 wl1251_error("couldn't allocate target memory map");
215 return -ENOMEM;
218 /* we now ask for the firmware built memory map */
219 ret = wl1251_acx_mem_map(wl, wl->target_mem_map,
220 sizeof(struct wl1251_acx_mem_map));
221 if (ret < 0) {
222 wl1251_error("couldn't retrieve firmware memory map");
223 kfree(wl->target_mem_map);
224 wl->target_mem_map = NULL;
225 return ret;
228 return 0;
231 static int wl1251_hw_init_txq_fill(u8 qid,
232 struct acx_tx_queue_qos_config *config,
233 u32 num_blocks)
235 config->qid = qid;
237 switch (qid) {
238 case QOS_AC_BE:
239 config->high_threshold =
240 (QOS_TX_HIGH_BE_DEF * num_blocks) / 100;
241 config->low_threshold =
242 (QOS_TX_LOW_BE_DEF * num_blocks) / 100;
243 break;
244 case QOS_AC_BK:
245 config->high_threshold =
246 (QOS_TX_HIGH_BK_DEF * num_blocks) / 100;
247 config->low_threshold =
248 (QOS_TX_LOW_BK_DEF * num_blocks) / 100;
249 break;
250 case QOS_AC_VI:
251 config->high_threshold =
252 (QOS_TX_HIGH_VI_DEF * num_blocks) / 100;
253 config->low_threshold =
254 (QOS_TX_LOW_VI_DEF * num_blocks) / 100;
255 break;
256 case QOS_AC_VO:
257 config->high_threshold =
258 (QOS_TX_HIGH_VO_DEF * num_blocks) / 100;
259 config->low_threshold =
260 (QOS_TX_LOW_VO_DEF * num_blocks) / 100;
261 break;
262 default:
263 wl1251_error("Invalid TX queue id: %d", qid);
264 return -EINVAL;
267 return 0;
270 static int wl1251_hw_init_tx_queue_config(struct wl1251 *wl)
272 struct acx_tx_queue_qos_config *config;
273 struct wl1251_acx_mem_map *wl_mem_map = wl->target_mem_map;
274 int ret, i;
276 wl1251_debug(DEBUG_ACX, "acx tx queue config");
278 config = kzalloc(sizeof(*config), GFP_KERNEL);
279 if (!config) {
280 ret = -ENOMEM;
281 goto out;
284 for (i = 0; i < MAX_NUM_OF_AC; i++) {
285 ret = wl1251_hw_init_txq_fill(i, config,
286 wl_mem_map->num_tx_mem_blocks);
287 if (ret < 0)
288 goto out;
290 ret = wl1251_cmd_configure(wl, ACX_TX_QUEUE_CFG,
291 config, sizeof(*config));
292 if (ret < 0)
293 goto out;
296 out:
297 kfree(config);
298 return ret;
301 static int wl1251_hw_init_data_path_config(struct wl1251 *wl)
303 int ret;
305 /* asking for the data path parameters */
306 wl->data_path = kzalloc(sizeof(struct acx_data_path_params_resp),
307 GFP_KERNEL);
308 if (!wl->data_path) {
309 wl1251_error("Couldnt allocate data path parameters");
310 return -ENOMEM;
313 ret = wl1251_acx_data_path_params(wl, wl->data_path);
314 if (ret < 0) {
315 kfree(wl->data_path);
316 wl->data_path = NULL;
317 return ret;
320 return 0;
324 int wl1251_hw_init(struct wl1251 *wl)
326 struct wl1251_acx_mem_map *wl_mem_map;
327 int ret;
329 ret = wl1251_hw_init_hwenc_config(wl);
330 if (ret < 0)
331 return ret;
333 /* Template settings */
334 ret = wl1251_hw_init_templates_config(wl);
335 if (ret < 0)
336 return ret;
338 /* Default memory configuration */
339 ret = wl1251_hw_init_mem_config(wl);
340 if (ret < 0)
341 return ret;
343 /* Default data path configuration */
344 ret = wl1251_hw_init_data_path_config(wl);
345 if (ret < 0)
346 goto out_free_memmap;
348 /* RX config */
349 ret = wl1251_hw_init_rx_config(wl,
350 RX_CFG_PROMISCUOUS | RX_CFG_TSF,
351 RX_FILTER_OPTION_DEF);
352 /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
353 RX_FILTER_OPTION_FILTER_ALL); */
354 if (ret < 0)
355 goto out_free_data_path;
357 /* TX queues config */
358 ret = wl1251_hw_init_tx_queue_config(wl);
359 if (ret < 0)
360 goto out_free_data_path;
362 /* PHY layer config */
363 ret = wl1251_hw_init_phy_config(wl);
364 if (ret < 0)
365 goto out_free_data_path;
367 /* Beacon filtering */
368 ret = wl1251_hw_init_beacon_filter(wl);
369 if (ret < 0)
370 goto out_free_data_path;
372 /* Bluetooth WLAN coexistence */
373 ret = wl1251_hw_init_pta(wl);
374 if (ret < 0)
375 goto out_free_data_path;
377 /* Energy detection */
378 ret = wl1251_hw_init_energy_detection(wl);
379 if (ret < 0)
380 goto out_free_data_path;
382 /* Beacons and boradcast settings */
383 ret = wl1251_hw_init_beacon_broadcast(wl);
384 if (ret < 0)
385 goto out_free_data_path;
387 /* Enable data path */
388 ret = wl1251_cmd_data_path(wl, wl->channel, 1);
389 if (ret < 0)
390 goto out_free_data_path;
392 /* Default power state */
393 ret = wl1251_hw_init_power_auth(wl);
394 if (ret < 0)
395 goto out_free_data_path;
397 wl_mem_map = wl->target_mem_map;
398 wl1251_info("%d tx blocks at 0x%x, %d rx blocks at 0x%x",
399 wl_mem_map->num_tx_mem_blocks,
400 wl->data_path->tx_control_addr,
401 wl_mem_map->num_rx_mem_blocks,
402 wl->data_path->rx_control_addr);
404 return 0;
406 out_free_data_path:
407 kfree(wl->data_path);
409 out_free_memmap:
410 kfree(wl->target_mem_map);
412 return ret;