1 // SPDX-License-Identifier: GPL-2.0-only
3 * This file is part of wl1251
5 * Copyright (C) 2009 Nokia Corporation
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/slab.h>
13 #include "wl12xx_80211.h"
18 int wl1251_hw_init_hwenc_config(struct wl1251 *wl)
22 ret = wl1251_acx_feature_cfg(wl, 0);
24 wl1251_warning("couldn't set feature config");
28 ret = wl1251_acx_default_key(wl, wl->default_key);
30 wl1251_warning("couldn't set default key");
37 int wl1251_hw_init_templates_config(struct wl1251 *wl)
40 u8 partial_vbm[PARTIAL_VBM_MAX];
42 /* send empty templates for fw memory reservation */
43 ret = wl1251_cmd_template_set(wl, CMD_PROBE_REQ, NULL,
44 sizeof(struct wl12xx_probe_req_template));
48 ret = wl1251_cmd_template_set(wl, CMD_NULL_DATA, NULL,
49 sizeof(struct wl12xx_null_data_template));
53 ret = wl1251_cmd_template_set(wl, CMD_PS_POLL, NULL,
54 sizeof(struct wl12xx_ps_poll_template));
58 ret = wl1251_cmd_template_set(wl, CMD_QOS_NULL_DATA, NULL,
60 (struct wl12xx_qos_null_data_template));
64 ret = wl1251_cmd_template_set(wl, CMD_PROBE_RESP, NULL,
66 (struct wl12xx_probe_resp_template));
70 ret = wl1251_cmd_template_set(wl, CMD_BEACON, NULL,
72 (struct wl12xx_beacon_template));
76 /* tim templates, first reserve space then allocate an empty one */
77 memset(partial_vbm, 0, PARTIAL_VBM_MAX);
78 ret = wl1251_cmd_vbm(wl, TIM_ELE_ID, partial_vbm, PARTIAL_VBM_MAX, 0);
82 ret = wl1251_cmd_vbm(wl, TIM_ELE_ID, partial_vbm, 1, 0);
89 int wl1251_hw_init_rx_config(struct wl1251 *wl, u32 config, u32 filter)
93 ret = wl1251_acx_rx_msdu_life_time(wl, RX_MSDU_LIFETIME_DEF);
97 ret = wl1251_acx_rx_config(wl, config, filter);
104 int wl1251_hw_init_phy_config(struct wl1251 *wl)
108 ret = wl1251_acx_pd_threshold(wl);
112 ret = wl1251_acx_slot(wl, DEFAULT_SLOT_TIME);
116 ret = wl1251_acx_group_address_tbl(wl, true, NULL, 0);
120 ret = wl1251_acx_service_period_timeout(wl);
124 ret = wl1251_acx_rts_threshold(wl, RTS_THRESHOLD_DEF);
131 int wl1251_hw_init_beacon_filter(struct wl1251 *wl)
135 /* disable beacon filtering at this stage */
136 ret = wl1251_acx_beacon_filter_opt(wl, false);
140 ret = wl1251_acx_beacon_filter_table(wl);
147 int wl1251_hw_init_pta(struct wl1251 *wl)
151 ret = wl1251_acx_sg_enable(wl);
155 ret = wl1251_acx_sg_cfg(wl);
162 int wl1251_hw_init_energy_detection(struct wl1251 *wl)
166 ret = wl1251_acx_cca_threshold(wl);
173 int wl1251_hw_init_beacon_broadcast(struct wl1251 *wl)
177 ret = wl1251_acx_bcn_dtim_options(wl);
184 int wl1251_hw_init_power_auth(struct wl1251 *wl)
186 return wl1251_acx_sleep_auth(wl, WL1251_PSM_CAM);
189 int wl1251_hw_init_mem_config(struct wl1251 *wl)
193 ret = wl1251_acx_mem_cfg(wl);
197 wl->target_mem_map = kzalloc(sizeof(struct wl1251_acx_mem_map),
199 if (!wl->target_mem_map) {
200 wl1251_error("couldn't allocate target memory map");
204 /* we now ask for the firmware built memory map */
205 ret = wl1251_acx_mem_map(wl, wl->target_mem_map,
206 sizeof(struct wl1251_acx_mem_map));
208 wl1251_error("couldn't retrieve firmware memory map");
209 kfree(wl->target_mem_map);
210 wl->target_mem_map = NULL;
217 static int wl1251_hw_init_txq_fill(u8 qid,
218 struct acx_tx_queue_qos_config *config,
225 config->high_threshold =
226 (QOS_TX_HIGH_BE_DEF * num_blocks) / 100;
227 config->low_threshold =
228 (QOS_TX_LOW_BE_DEF * num_blocks) / 100;
231 config->high_threshold =
232 (QOS_TX_HIGH_BK_DEF * num_blocks) / 100;
233 config->low_threshold =
234 (QOS_TX_LOW_BK_DEF * num_blocks) / 100;
237 config->high_threshold =
238 (QOS_TX_HIGH_VI_DEF * num_blocks) / 100;
239 config->low_threshold =
240 (QOS_TX_LOW_VI_DEF * num_blocks) / 100;
243 config->high_threshold =
244 (QOS_TX_HIGH_VO_DEF * num_blocks) / 100;
245 config->low_threshold =
246 (QOS_TX_LOW_VO_DEF * num_blocks) / 100;
249 wl1251_error("Invalid TX queue id: %d", qid);
256 static int wl1251_hw_init_tx_queue_config(struct wl1251 *wl)
258 struct acx_tx_queue_qos_config *config;
259 struct wl1251_acx_mem_map *wl_mem_map = wl->target_mem_map;
262 wl1251_debug(DEBUG_ACX, "acx tx queue config");
264 config = kzalloc(sizeof(*config), GFP_KERNEL);
270 for (i = 0; i < MAX_NUM_OF_AC; i++) {
271 ret = wl1251_hw_init_txq_fill(i, config,
272 wl_mem_map->num_tx_mem_blocks);
276 ret = wl1251_cmd_configure(wl, ACX_TX_QUEUE_CFG,
277 config, sizeof(*config));
282 wl1251_acx_ac_cfg(wl, AC_BE, CWMIN_BE, CWMAX_BE, AIFS_DIFS, TXOP_BE);
283 wl1251_acx_ac_cfg(wl, AC_BK, CWMIN_BK, CWMAX_BK, AIFS_DIFS, TXOP_BK);
284 wl1251_acx_ac_cfg(wl, AC_VI, CWMIN_VI, CWMAX_VI, AIFS_DIFS, TXOP_VI);
285 wl1251_acx_ac_cfg(wl, AC_VO, CWMIN_VO, CWMAX_VO, AIFS_DIFS, TXOP_VO);
292 static int wl1251_hw_init_data_path_config(struct wl1251 *wl)
296 /* asking for the data path parameters */
297 wl->data_path = kzalloc(sizeof(struct acx_data_path_params_resp),
302 ret = wl1251_acx_data_path_params(wl, wl->data_path);
304 kfree(wl->data_path);
305 wl->data_path = NULL;
313 int wl1251_hw_init(struct wl1251 *wl)
315 struct wl1251_acx_mem_map *wl_mem_map;
318 ret = wl1251_hw_init_hwenc_config(wl);
322 /* Template settings */
323 ret = wl1251_hw_init_templates_config(wl);
327 /* Default memory configuration */
328 ret = wl1251_hw_init_mem_config(wl);
332 /* Default data path configuration */
333 ret = wl1251_hw_init_data_path_config(wl);
335 goto out_free_memmap;
338 ret = wl1251_hw_init_rx_config(wl,
339 RX_CFG_PROMISCUOUS | RX_CFG_TSF,
340 RX_FILTER_OPTION_DEF);
341 /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
342 RX_FILTER_OPTION_FILTER_ALL); */
344 goto out_free_data_path;
346 /* TX queues config */
347 ret = wl1251_hw_init_tx_queue_config(wl);
349 goto out_free_data_path;
351 /* PHY layer config */
352 ret = wl1251_hw_init_phy_config(wl);
354 goto out_free_data_path;
356 /* Initialize connection monitoring thresholds */
357 ret = wl1251_acx_conn_monit_params(wl);
359 goto out_free_data_path;
361 /* Beacon filtering */
362 ret = wl1251_hw_init_beacon_filter(wl);
364 goto out_free_data_path;
366 /* Bluetooth WLAN coexistence */
367 ret = wl1251_hw_init_pta(wl);
369 goto out_free_data_path;
371 /* Energy detection */
372 ret = wl1251_hw_init_energy_detection(wl);
374 goto out_free_data_path;
376 /* Beacons and broadcast settings */
377 ret = wl1251_hw_init_beacon_broadcast(wl);
379 goto out_free_data_path;
381 /* Enable rx data path */
382 ret = wl1251_cmd_data_path_rx(wl, wl->channel, 1);
384 goto out_free_data_path;
386 /* Enable tx data path */
387 ret = wl1251_cmd_data_path_tx(wl, wl->channel, 1);
389 goto out_free_data_path;
391 /* Default power state */
392 ret = wl1251_hw_init_power_auth(wl);
394 goto out_free_data_path;
396 wl_mem_map = wl->target_mem_map;
397 wl1251_info("%d tx blocks at 0x%x, %d rx blocks at 0x%x",
398 wl_mem_map->num_tx_mem_blocks,
399 wl->data_path->tx_control_addr,
400 wl_mem_map->num_rx_mem_blocks,
401 wl->data_path->rx_control_addr);
406 kfree(wl->data_path);
409 kfree(wl->target_mem_map);