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
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)
37 ret = wl1251_acx_feature_cfg(wl);
39 wl1251_warning("couldn't set feature config");
43 ret = wl1251_acx_default_key(wl, wl->default_key);
45 wl1251_warning("couldn't set default key");
52 int wl1251_hw_init_templates_config(struct wl1251 *wl)
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));
63 ret = wl1251_cmd_template_set(wl, CMD_NULL_DATA, NULL,
64 sizeof(struct wl12xx_null_data_template));
68 ret = wl1251_cmd_template_set(wl, CMD_PS_POLL, NULL,
69 sizeof(struct wl12xx_ps_poll_template));
73 ret = wl1251_cmd_template_set(wl, CMD_QOS_NULL_DATA, NULL,
75 (struct wl12xx_qos_null_data_template));
79 ret = wl1251_cmd_template_set(wl, CMD_PROBE_RESP, NULL,
81 (struct wl12xx_probe_resp_template));
85 ret = wl1251_cmd_template_set(wl, CMD_BEACON, NULL,
87 (struct wl12xx_beacon_template));
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);
97 ret = wl1251_cmd_vbm(wl, TIM_ELE_ID, partial_vbm, 1, 0);
104 int wl1251_hw_init_rx_config(struct wl1251 *wl, u32 config, u32 filter)
108 ret = wl1251_acx_rx_msdu_life_time(wl, RX_MSDU_LIFETIME_DEF);
112 ret = wl1251_acx_rx_config(wl, config, filter);
119 int wl1251_hw_init_phy_config(struct wl1251 *wl)
123 ret = wl1251_acx_pd_threshold(wl);
127 ret = wl1251_acx_slot(wl, DEFAULT_SLOT_TIME);
131 ret = wl1251_acx_group_address_tbl(wl);
135 ret = wl1251_acx_service_period_timeout(wl);
139 ret = wl1251_acx_rts_threshold(wl, RTS_THRESHOLD_DEF);
146 int wl1251_hw_init_beacon_filter(struct wl1251 *wl)
150 /* disable beacon filtering at this stage */
151 ret = wl1251_acx_beacon_filter_opt(wl, false);
155 ret = wl1251_acx_beacon_filter_table(wl);
162 int wl1251_hw_init_pta(struct wl1251 *wl)
166 ret = wl1251_acx_sg_enable(wl);
170 ret = wl1251_acx_sg_cfg(wl);
177 int wl1251_hw_init_energy_detection(struct wl1251 *wl)
181 ret = wl1251_acx_cca_threshold(wl);
188 int wl1251_hw_init_beacon_broadcast(struct wl1251 *wl)
192 ret = wl1251_acx_bcn_dtim_options(wl);
199 int wl1251_hw_init_power_auth(struct wl1251 *wl)
201 return wl1251_acx_sleep_auth(wl, WL1251_PSM_CAM);
204 int wl1251_hw_init_mem_config(struct wl1251 *wl)
208 ret = wl1251_acx_mem_cfg(wl);
212 wl->target_mem_map = kzalloc(sizeof(struct wl1251_acx_mem_map),
214 if (!wl->target_mem_map) {
215 wl1251_error("couldn't allocate target memory map");
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));
223 wl1251_error("couldn't retrieve firmware memory map");
224 kfree(wl->target_mem_map);
225 wl->target_mem_map = NULL;
232 static int wl1251_hw_init_txq_fill(u8 qid,
233 struct acx_tx_queue_qos_config *config,
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;
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;
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;
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;
264 wl1251_error("Invalid TX queue id: %d", qid);
271 static int wl1251_hw_init_tx_queue_config(struct wl1251 *wl)
273 struct acx_tx_queue_qos_config *config;
274 struct wl1251_acx_mem_map *wl_mem_map = wl->target_mem_map;
277 wl1251_debug(DEBUG_ACX, "acx tx queue config");
279 config = kzalloc(sizeof(*config), GFP_KERNEL);
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);
291 ret = wl1251_cmd_configure(wl, ACX_TX_QUEUE_CFG,
292 config, sizeof(*config));
297 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);
307 static int wl1251_hw_init_data_path_config(struct wl1251 *wl)
311 /* asking for the data path parameters */
312 wl->data_path = kzalloc(sizeof(struct acx_data_path_params_resp),
314 if (!wl->data_path) {
315 wl1251_error("Couldnt allocate data path parameters");
319 ret = wl1251_acx_data_path_params(wl, wl->data_path);
321 kfree(wl->data_path);
322 wl->data_path = NULL;
330 int wl1251_hw_init(struct wl1251 *wl)
332 struct wl1251_acx_mem_map *wl_mem_map;
335 ret = wl1251_hw_init_hwenc_config(wl);
339 /* Template settings */
340 ret = wl1251_hw_init_templates_config(wl);
344 /* Default memory configuration */
345 ret = wl1251_hw_init_mem_config(wl);
349 /* Default data path configuration */
350 ret = wl1251_hw_init_data_path_config(wl);
352 goto out_free_memmap;
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); */
361 goto out_free_data_path;
363 /* TX queues config */
364 ret = wl1251_hw_init_tx_queue_config(wl);
366 goto out_free_data_path;
368 /* PHY layer config */
369 ret = wl1251_hw_init_phy_config(wl);
371 goto out_free_data_path;
373 /* Initialize connection monitoring thresholds */
374 ret = wl1251_acx_conn_monit_params(wl);
376 goto out_free_data_path;
378 /* Beacon filtering */
379 ret = wl1251_hw_init_beacon_filter(wl);
381 goto out_free_data_path;
383 /* Bluetooth WLAN coexistence */
384 ret = wl1251_hw_init_pta(wl);
386 goto out_free_data_path;
388 /* Energy detection */
389 ret = wl1251_hw_init_energy_detection(wl);
391 goto out_free_data_path;
393 /* Beacons and boradcast settings */
394 ret = wl1251_hw_init_beacon_broadcast(wl);
396 goto out_free_data_path;
398 /* Enable data path */
399 ret = wl1251_cmd_data_path(wl, wl->channel, 1);
401 goto out_free_data_path;
403 /* Default power state */
404 ret = wl1251_hw_init_power_auth(wl);
406 goto out_free_data_path;
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);
418 kfree(wl->data_path);
421 kfree(wl->target_mem_map);