2 * This file is part of wl1251
4 * Copyright (C) 2009 Nokia Corporation
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 #include <linux/kernel.h>
23 #include <linux/module.h>
24 #include <linux/slab.h>
27 #include "wl12xx_80211.h"
32 int wl1251_hw_init_hwenc_config(struct wl1251
*wl
)
36 ret
= wl1251_acx_feature_cfg(wl
, 0);
38 wl1251_warning("couldn't set feature config");
42 ret
= wl1251_acx_default_key(wl
, wl
->default_key
);
44 wl1251_warning("couldn't set default key");
51 int wl1251_hw_init_templates_config(struct wl1251
*wl
)
54 u8 partial_vbm
[PARTIAL_VBM_MAX
];
56 /* send empty templates for fw memory reservation */
57 ret
= wl1251_cmd_template_set(wl
, CMD_PROBE_REQ
, NULL
,
58 sizeof(struct wl12xx_probe_req_template
));
62 ret
= wl1251_cmd_template_set(wl
, CMD_NULL_DATA
, NULL
,
63 sizeof(struct wl12xx_null_data_template
));
67 ret
= wl1251_cmd_template_set(wl
, CMD_PS_POLL
, NULL
,
68 sizeof(struct wl12xx_ps_poll_template
));
72 ret
= wl1251_cmd_template_set(wl
, CMD_QOS_NULL_DATA
, NULL
,
74 (struct wl12xx_qos_null_data_template
));
78 ret
= wl1251_cmd_template_set(wl
, CMD_PROBE_RESP
, NULL
,
80 (struct wl12xx_probe_resp_template
));
84 ret
= wl1251_cmd_template_set(wl
, CMD_BEACON
, NULL
,
86 (struct wl12xx_beacon_template
));
90 /* tim templates, first reserve space then allocate an empty one */
91 memset(partial_vbm
, 0, PARTIAL_VBM_MAX
);
92 ret
= wl1251_cmd_vbm(wl
, TIM_ELE_ID
, partial_vbm
, PARTIAL_VBM_MAX
, 0);
96 ret
= wl1251_cmd_vbm(wl
, TIM_ELE_ID
, partial_vbm
, 1, 0);
103 int wl1251_hw_init_rx_config(struct wl1251
*wl
, u32 config
, u32 filter
)
107 ret
= wl1251_acx_rx_msdu_life_time(wl
, RX_MSDU_LIFETIME_DEF
);
111 ret
= wl1251_acx_rx_config(wl
, config
, filter
);
118 int wl1251_hw_init_phy_config(struct wl1251
*wl
)
122 ret
= wl1251_acx_pd_threshold(wl
);
126 ret
= wl1251_acx_slot(wl
, DEFAULT_SLOT_TIME
);
130 ret
= wl1251_acx_group_address_tbl(wl
, true, NULL
, 0);
134 ret
= wl1251_acx_service_period_timeout(wl
);
138 ret
= wl1251_acx_rts_threshold(wl
, RTS_THRESHOLD_DEF
);
145 int wl1251_hw_init_beacon_filter(struct wl1251
*wl
)
149 /* disable beacon filtering at this stage */
150 ret
= wl1251_acx_beacon_filter_opt(wl
, false);
154 ret
= wl1251_acx_beacon_filter_table(wl
);
161 int wl1251_hw_init_pta(struct wl1251
*wl
)
165 ret
= wl1251_acx_sg_enable(wl
);
169 ret
= wl1251_acx_sg_cfg(wl
);
176 int wl1251_hw_init_energy_detection(struct wl1251
*wl
)
180 ret
= wl1251_acx_cca_threshold(wl
);
187 int wl1251_hw_init_beacon_broadcast(struct wl1251
*wl
)
191 ret
= wl1251_acx_bcn_dtim_options(wl
);
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
)
207 ret
= wl1251_acx_mem_cfg(wl
);
211 wl
->target_mem_map
= kzalloc(sizeof(struct wl1251_acx_mem_map
),
213 if (!wl
->target_mem_map
) {
214 wl1251_error("couldn't allocate target memory map");
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
));
222 wl1251_error("couldn't retrieve firmware memory map");
223 kfree(wl
->target_mem_map
);
224 wl
->target_mem_map
= NULL
;
231 static int wl1251_hw_init_txq_fill(u8 qid
,
232 struct acx_tx_queue_qos_config
*config
,
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;
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;
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;
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;
263 wl1251_error("Invalid TX queue id: %d", qid
);
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
;
276 wl1251_debug(DEBUG_ACX
, "acx tx queue config");
278 config
= kzalloc(sizeof(*config
), GFP_KERNEL
);
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
);
290 ret
= wl1251_cmd_configure(wl
, ACX_TX_QUEUE_CFG
,
291 config
, sizeof(*config
));
296 wl1251_acx_ac_cfg(wl
, AC_BE
, CWMIN_BE
, CWMAX_BE
, AIFS_DIFS
, TXOP_BE
);
297 wl1251_acx_ac_cfg(wl
, AC_BK
, CWMIN_BK
, CWMAX_BK
, AIFS_DIFS
, TXOP_BK
);
298 wl1251_acx_ac_cfg(wl
, AC_VI
, CWMIN_VI
, CWMAX_VI
, AIFS_DIFS
, TXOP_VI
);
299 wl1251_acx_ac_cfg(wl
, AC_VO
, CWMIN_VO
, CWMAX_VO
, AIFS_DIFS
, TXOP_VO
);
306 static int wl1251_hw_init_data_path_config(struct wl1251
*wl
)
310 /* asking for the data path parameters */
311 wl
->data_path
= kzalloc(sizeof(struct acx_data_path_params_resp
),
316 ret
= wl1251_acx_data_path_params(wl
, wl
->data_path
);
318 kfree(wl
->data_path
);
319 wl
->data_path
= NULL
;
327 int wl1251_hw_init(struct wl1251
*wl
)
329 struct wl1251_acx_mem_map
*wl_mem_map
;
332 ret
= wl1251_hw_init_hwenc_config(wl
);
336 /* Template settings */
337 ret
= wl1251_hw_init_templates_config(wl
);
341 /* Default memory configuration */
342 ret
= wl1251_hw_init_mem_config(wl
);
346 /* Default data path configuration */
347 ret
= wl1251_hw_init_data_path_config(wl
);
349 goto out_free_memmap
;
352 ret
= wl1251_hw_init_rx_config(wl
,
353 RX_CFG_PROMISCUOUS
| RX_CFG_TSF
,
354 RX_FILTER_OPTION_DEF
);
355 /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
356 RX_FILTER_OPTION_FILTER_ALL); */
358 goto out_free_data_path
;
360 /* TX queues config */
361 ret
= wl1251_hw_init_tx_queue_config(wl
);
363 goto out_free_data_path
;
365 /* PHY layer config */
366 ret
= wl1251_hw_init_phy_config(wl
);
368 goto out_free_data_path
;
370 /* Initialize connection monitoring thresholds */
371 ret
= wl1251_acx_conn_monit_params(wl
);
373 goto out_free_data_path
;
375 /* Beacon filtering */
376 ret
= wl1251_hw_init_beacon_filter(wl
);
378 goto out_free_data_path
;
380 /* Bluetooth WLAN coexistence */
381 ret
= wl1251_hw_init_pta(wl
);
383 goto out_free_data_path
;
385 /* Energy detection */
386 ret
= wl1251_hw_init_energy_detection(wl
);
388 goto out_free_data_path
;
390 /* Beacons and boradcast settings */
391 ret
= wl1251_hw_init_beacon_broadcast(wl
);
393 goto out_free_data_path
;
395 /* Enable rx data path */
396 ret
= wl1251_cmd_data_path_rx(wl
, wl
->channel
, 1);
398 goto out_free_data_path
;
400 /* Enable tx data path */
401 ret
= wl1251_cmd_data_path_tx(wl
, wl
->channel
, 1);
403 goto out_free_data_path
;
405 /* Default power state */
406 ret
= wl1251_hw_init_power_auth(wl
);
408 goto out_free_data_path
;
410 wl_mem_map
= wl
->target_mem_map
;
411 wl1251_info("%d tx blocks at 0x%x, %d rx blocks at 0x%x",
412 wl_mem_map
->num_tx_mem_blocks
,
413 wl
->data_path
->tx_control_addr
,
414 wl_mem_map
->num_rx_mem_blocks
,
415 wl
->data_path
->rx_control_addr
);
420 kfree(wl
->data_path
);
423 kfree(wl
->target_mem_map
);