blob: 5aad56ea71536fa1dbc5875d601f7bd76eaae961 [file] [log] [blame]
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001/*
Kalle Valo80301cd2009-06-12 14:17:39 +03002 * This file is part of wl1251
Kalle Valo2f01a1f2009-04-29 23:33:31 +03003 *
4 * Copyright (C) 2009 Nokia Corporation
5 *
6 * Contact: Kalle Valo <kalle.valo@nokia.com>
7 *
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.
11 *
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.
16 *
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
21 *
22 */
23
24#include <linux/kernel.h>
25#include <linux/module.h>
26
Kalle Valoef2f8d42009-06-12 14:17:19 +030027#include "wl1251_init.h"
Kalle Valo2f01a1f2009-04-29 23:33:31 +030028#include "wl12xx_80211.h"
Kalle Valoef2f8d42009-06-12 14:17:19 +030029#include "wl1251_acx.h"
30#include "wl1251_cmd.h"
Kalle Valo29d904c2009-08-07 13:35:11 +030031#include "wl1251_reg.h"
Kalle Valo2f01a1f2009-04-29 23:33:31 +030032
Kalle Valo80301cd2009-06-12 14:17:39 +030033int wl1251_hw_init_hwenc_config(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +030034{
35 int ret;
36
Kalle Valo80301cd2009-06-12 14:17:39 +030037 ret = wl1251_acx_feature_cfg(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030038 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +030039 wl1251_warning("couldn't set feature config");
Kalle Valo2f01a1f2009-04-29 23:33:31 +030040 return ret;
41 }
42
Kalle Valo80301cd2009-06-12 14:17:39 +030043 ret = wl1251_acx_default_key(wl, wl->default_key);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030044 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +030045 wl1251_warning("couldn't set default key");
Kalle Valo2f01a1f2009-04-29 23:33:31 +030046 return ret;
47 }
48
49 return 0;
50}
51
Kalle Valo80301cd2009-06-12 14:17:39 +030052int wl1251_hw_init_templates_config(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +030053{
54 int ret;
55 u8 partial_vbm[PARTIAL_VBM_MAX];
56
57 /* send empty templates for fw memory reservation */
Kalle Valo80301cd2009-06-12 14:17:39 +030058 ret = wl1251_cmd_template_set(wl, CMD_PROBE_REQ, NULL,
Kalle Valo2f01a1f2009-04-29 23:33:31 +030059 sizeof(struct wl12xx_probe_req_template));
60 if (ret < 0)
61 return ret;
62
Kalle Valo80301cd2009-06-12 14:17:39 +030063 ret = wl1251_cmd_template_set(wl, CMD_NULL_DATA, NULL,
Kalle Valo2f01a1f2009-04-29 23:33:31 +030064 sizeof(struct wl12xx_null_data_template));
65 if (ret < 0)
66 return ret;
67
Kalle Valo80301cd2009-06-12 14:17:39 +030068 ret = wl1251_cmd_template_set(wl, CMD_PS_POLL, NULL,
Kalle Valo2f01a1f2009-04-29 23:33:31 +030069 sizeof(struct wl12xx_ps_poll_template));
70 if (ret < 0)
71 return ret;
72
Kalle Valo80301cd2009-06-12 14:17:39 +030073 ret = wl1251_cmd_template_set(wl, CMD_QOS_NULL_DATA, NULL,
Kalle Valo2f01a1f2009-04-29 23:33:31 +030074 sizeof
75 (struct wl12xx_qos_null_data_template));
76 if (ret < 0)
77 return ret;
78
Kalle Valo80301cd2009-06-12 14:17:39 +030079 ret = wl1251_cmd_template_set(wl, CMD_PROBE_RESP, NULL,
Kalle Valo2f01a1f2009-04-29 23:33:31 +030080 sizeof
81 (struct wl12xx_probe_resp_template));
82 if (ret < 0)
83 return ret;
84
Kalle Valo80301cd2009-06-12 14:17:39 +030085 ret = wl1251_cmd_template_set(wl, CMD_BEACON, NULL,
Kalle Valo2f01a1f2009-04-29 23:33:31 +030086 sizeof
87 (struct wl12xx_beacon_template));
88 if (ret < 0)
89 return ret;
90
91 /* tim templates, first reserve space then allocate an empty one */
92 memset(partial_vbm, 0, PARTIAL_VBM_MAX);
Kalle Valo80301cd2009-06-12 14:17:39 +030093 ret = wl1251_cmd_vbm(wl, TIM_ELE_ID, partial_vbm, PARTIAL_VBM_MAX, 0);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030094 if (ret < 0)
95 return ret;
96
Kalle Valo80301cd2009-06-12 14:17:39 +030097 ret = wl1251_cmd_vbm(wl, TIM_ELE_ID, partial_vbm, 1, 0);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030098 if (ret < 0)
99 return ret;
100
101 return 0;
102}
103
Kalle Valo80301cd2009-06-12 14:17:39 +0300104int wl1251_hw_init_rx_config(struct wl1251 *wl, u32 config, u32 filter)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300105{
106 int ret;
107
Kalle Valo80301cd2009-06-12 14:17:39 +0300108 ret = wl1251_acx_rx_msdu_life_time(wl, RX_MSDU_LIFETIME_DEF);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300109 if (ret < 0)
110 return ret;
111
Kalle Valo80301cd2009-06-12 14:17:39 +0300112 ret = wl1251_acx_rx_config(wl, config, filter);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300113 if (ret < 0)
114 return ret;
115
116 return 0;
117}
118
Kalle Valo80301cd2009-06-12 14:17:39 +0300119int wl1251_hw_init_phy_config(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300120{
121 int ret;
122
Kalle Valo80301cd2009-06-12 14:17:39 +0300123 ret = wl1251_acx_pd_threshold(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300124 if (ret < 0)
125 return ret;
126
Kalle Valo80301cd2009-06-12 14:17:39 +0300127 ret = wl1251_acx_slot(wl, DEFAULT_SLOT_TIME);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300128 if (ret < 0)
129 return ret;
130
Kalle Valo80301cd2009-06-12 14:17:39 +0300131 ret = wl1251_acx_group_address_tbl(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300132 if (ret < 0)
133 return ret;
134
Kalle Valo80301cd2009-06-12 14:17:39 +0300135 ret = wl1251_acx_service_period_timeout(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300136 if (ret < 0)
137 return ret;
138
Kalle Valo80301cd2009-06-12 14:17:39 +0300139 ret = wl1251_acx_rts_threshold(wl, RTS_THRESHOLD_DEF);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300140 if (ret < 0)
141 return ret;
142
143 return 0;
144}
145
Kalle Valo80301cd2009-06-12 14:17:39 +0300146int wl1251_hw_init_beacon_filter(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300147{
148 int ret;
149
Juuso Oikarinen6b21a2c2009-11-17 18:48:30 +0200150 /* disable beacon filtering at this stage */
151 ret = wl1251_acx_beacon_filter_opt(wl, false);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300152 if (ret < 0)
153 return ret;
154
Kalle Valo80301cd2009-06-12 14:17:39 +0300155 ret = wl1251_acx_beacon_filter_table(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300156 if (ret < 0)
157 return ret;
158
159 return 0;
160}
161
Kalle Valo80301cd2009-06-12 14:17:39 +0300162int wl1251_hw_init_pta(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300163{
164 int ret;
165
Kalle Valo80301cd2009-06-12 14:17:39 +0300166 ret = wl1251_acx_sg_enable(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300167 if (ret < 0)
168 return ret;
169
Kalle Valo80301cd2009-06-12 14:17:39 +0300170 ret = wl1251_acx_sg_cfg(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300171 if (ret < 0)
172 return ret;
173
174 return 0;
175}
176
Kalle Valo80301cd2009-06-12 14:17:39 +0300177int wl1251_hw_init_energy_detection(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300178{
179 int ret;
180
Kalle Valo80301cd2009-06-12 14:17:39 +0300181 ret = wl1251_acx_cca_threshold(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300182 if (ret < 0)
183 return ret;
184
185 return 0;
186}
187
Kalle Valo80301cd2009-06-12 14:17:39 +0300188int wl1251_hw_init_beacon_broadcast(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300189{
190 int ret;
191
Kalle Valo80301cd2009-06-12 14:17:39 +0300192 ret = wl1251_acx_bcn_dtim_options(wl);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300193 if (ret < 0)
194 return ret;
195
196 return 0;
197}
198
Kalle Valo80301cd2009-06-12 14:17:39 +0300199int wl1251_hw_init_power_auth(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300200{
Kalle Valo80301cd2009-06-12 14:17:39 +0300201 return wl1251_acx_sleep_auth(wl, WL1251_PSM_CAM);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300202}
Kalle Valo0e71bb02009-08-07 13:33:57 +0300203
204int wl1251_hw_init_mem_config(struct wl1251 *wl)
205{
206 int ret;
207
208 ret = wl1251_acx_mem_cfg(wl);
209 if (ret < 0)
210 return ret;
211
212 wl->target_mem_map = kzalloc(sizeof(struct wl1251_acx_mem_map),
213 GFP_KERNEL);
214 if (!wl->target_mem_map) {
215 wl1251_error("couldn't allocate target memory map");
216 return -ENOMEM;
217 }
218
219 /* we now ask for the firmware built memory map */
220 ret = wl1251_acx_mem_map(wl, wl->target_mem_map,
221 sizeof(struct wl1251_acx_mem_map));
222 if (ret < 0) {
223 wl1251_error("couldn't retrieve firmware memory map");
224 kfree(wl->target_mem_map);
225 wl->target_mem_map = NULL;
226 return ret;
227 }
228
229 return 0;
230}
231
232static int wl1251_hw_init_txq_fill(u8 qid,
233 struct acx_tx_queue_qos_config *config,
234 u32 num_blocks)
235{
236 config->qid = qid;
237
238 switch (qid) {
239 case QOS_AC_BE:
240 config->high_threshold =
241 (QOS_TX_HIGH_BE_DEF * num_blocks) / 100;
242 config->low_threshold =
243 (QOS_TX_LOW_BE_DEF * num_blocks) / 100;
244 break;
245 case QOS_AC_BK:
246 config->high_threshold =
247 (QOS_TX_HIGH_BK_DEF * num_blocks) / 100;
248 config->low_threshold =
249 (QOS_TX_LOW_BK_DEF * num_blocks) / 100;
250 break;
251 case QOS_AC_VI:
252 config->high_threshold =
253 (QOS_TX_HIGH_VI_DEF * num_blocks) / 100;
254 config->low_threshold =
255 (QOS_TX_LOW_VI_DEF * num_blocks) / 100;
256 break;
257 case QOS_AC_VO:
258 config->high_threshold =
259 (QOS_TX_HIGH_VO_DEF * num_blocks) / 100;
260 config->low_threshold =
261 (QOS_TX_LOW_VO_DEF * num_blocks) / 100;
262 break;
263 default:
264 wl1251_error("Invalid TX queue id: %d", qid);
265 return -EINVAL;
266 }
267
268 return 0;
269}
270
271static int wl1251_hw_init_tx_queue_config(struct wl1251 *wl)
272{
273 struct acx_tx_queue_qos_config *config;
274 struct wl1251_acx_mem_map *wl_mem_map = wl->target_mem_map;
275 int ret, i;
276
277 wl1251_debug(DEBUG_ACX, "acx tx queue config");
278
279 config = kzalloc(sizeof(*config), GFP_KERNEL);
280 if (!config) {
281 ret = -ENOMEM;
282 goto out;
283 }
284
285 for (i = 0; i < MAX_NUM_OF_AC; i++) {
286 ret = wl1251_hw_init_txq_fill(i, config,
287 wl_mem_map->num_tx_mem_blocks);
288 if (ret < 0)
289 goto out;
290
291 ret = wl1251_cmd_configure(wl, ACX_TX_QUEUE_CFG,
292 config, sizeof(*config));
293 if (ret < 0)
294 goto out;
295 }
296
Kalle Valo86dff7a2009-11-30 10:18:19 +0200297 wl1251_acx_ac_cfg(wl, AC_BE, CWMIN_BE, CWMAX_BE, AIFS_DIFS, TXOP_BE);
298 wl1251_acx_ac_cfg(wl, AC_BK, CWMIN_BK, CWMAX_BK, AIFS_DIFS, TXOP_BK);
299 wl1251_acx_ac_cfg(wl, AC_VI, CWMIN_VI, CWMAX_VI, AIFS_DIFS, TXOP_VI);
300 wl1251_acx_ac_cfg(wl, AC_VO, CWMIN_VO, CWMAX_VO, AIFS_DIFS, TXOP_VO);
301
Kalle Valo0e71bb02009-08-07 13:33:57 +0300302out:
303 kfree(config);
304 return ret;
305}
306
307static int wl1251_hw_init_data_path_config(struct wl1251 *wl)
308{
309 int ret;
310
311 /* asking for the data path parameters */
312 wl->data_path = kzalloc(sizeof(struct acx_data_path_params_resp),
313 GFP_KERNEL);
314 if (!wl->data_path) {
315 wl1251_error("Couldnt allocate data path parameters");
316 return -ENOMEM;
317 }
318
319 ret = wl1251_acx_data_path_params(wl, wl->data_path);
320 if (ret < 0) {
321 kfree(wl->data_path);
322 wl->data_path = NULL;
323 return ret;
324 }
325
326 return 0;
327}
328
329
330int wl1251_hw_init(struct wl1251 *wl)
331{
332 struct wl1251_acx_mem_map *wl_mem_map;
333 int ret;
334
335 ret = wl1251_hw_init_hwenc_config(wl);
336 if (ret < 0)
337 return ret;
338
339 /* Template settings */
340 ret = wl1251_hw_init_templates_config(wl);
341 if (ret < 0)
342 return ret;
343
344 /* Default memory configuration */
345 ret = wl1251_hw_init_mem_config(wl);
346 if (ret < 0)
347 return ret;
348
349 /* Default data path configuration */
350 ret = wl1251_hw_init_data_path_config(wl);
351 if (ret < 0)
352 goto out_free_memmap;
353
354 /* RX config */
355 ret = wl1251_hw_init_rx_config(wl,
356 RX_CFG_PROMISCUOUS | RX_CFG_TSF,
357 RX_FILTER_OPTION_DEF);
358 /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
359 RX_FILTER_OPTION_FILTER_ALL); */
360 if (ret < 0)
361 goto out_free_data_path;
362
363 /* TX queues config */
364 ret = wl1251_hw_init_tx_queue_config(wl);
365 if (ret < 0)
366 goto out_free_data_path;
367
368 /* PHY layer config */
369 ret = wl1251_hw_init_phy_config(wl);
370 if (ret < 0)
371 goto out_free_data_path;
372
Juuso Oikarinen474c48c2009-11-17 18:48:14 +0200373 /* Initialize connection monitoring thresholds */
374 ret = wl1251_acx_conn_monit_params(wl);
375 if (ret < 0)
376 goto out_free_data_path;
377
Kalle Valo0e71bb02009-08-07 13:33:57 +0300378 /* Beacon filtering */
379 ret = wl1251_hw_init_beacon_filter(wl);
380 if (ret < 0)
381 goto out_free_data_path;
382
383 /* Bluetooth WLAN coexistence */
384 ret = wl1251_hw_init_pta(wl);
385 if (ret < 0)
386 goto out_free_data_path;
387
388 /* Energy detection */
389 ret = wl1251_hw_init_energy_detection(wl);
390 if (ret < 0)
391 goto out_free_data_path;
392
393 /* Beacons and boradcast settings */
394 ret = wl1251_hw_init_beacon_broadcast(wl);
395 if (ret < 0)
396 goto out_free_data_path;
397
398 /* Enable data path */
399 ret = wl1251_cmd_data_path(wl, wl->channel, 1);
400 if (ret < 0)
401 goto out_free_data_path;
402
403 /* Default power state */
404 ret = wl1251_hw_init_power_auth(wl);
405 if (ret < 0)
406 goto out_free_data_path;
407
408 wl_mem_map = wl->target_mem_map;
409 wl1251_info("%d tx blocks at 0x%x, %d rx blocks at 0x%x",
410 wl_mem_map->num_tx_mem_blocks,
411 wl->data_path->tx_control_addr,
412 wl_mem_map->num_rx_mem_blocks,
413 wl->data_path->rx_control_addr);
414
415 return 0;
416
417 out_free_data_path:
418 kfree(wl->data_path);
419
420 out_free_memmap:
421 kfree(wl->target_mem_map);
422
423 return ret;
424}