blob: 9ab3368290440f558b0d7ac32612c5e3f76b5168 [file] [log] [blame]
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 *
6 * Contact: Luciano Coelho <luciano.coelho@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
27#include "wl1271_init.h"
28#include "wl12xx_80211.h"
29#include "wl1271_acx.h"
30#include "wl1271_cmd.h"
31#include "wl1271_reg.h"
32
33static int wl1271_init_hwenc_config(struct wl1271 *wl)
34{
35 int ret;
36
37 ret = wl1271_acx_feature_cfg(wl);
38 if (ret < 0) {
39 wl1271_warning("couldn't set feature config");
40 return ret;
41 }
42
43 ret = wl1271_cmd_set_default_wep_key(wl, wl->default_key);
44 if (ret < 0) {
45 wl1271_warning("couldn't set default key");
46 return ret;
47 }
48
49 return 0;
50}
51
Luciano Coelho12419cce2010-02-18 13:25:44 +020052int wl1271_init_templates_config(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030053{
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +020054 int ret, i;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030055
56 /* send empty templates for fw memory reservation */
57 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, NULL,
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +020058 sizeof(struct wl12xx_probe_req_template),
Juuso Oikarinen606c1482010-04-01 11:38:21 +030059 0, WL1271_RATE_AUTOMATIC);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030060 if (ret < 0)
61 return ret;
62
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +030063 if (wl1271_11a_enabled()) {
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +020064 size_t size = sizeof(struct wl12xx_probe_req_template);
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +030065 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
Juuso Oikarinen606c1482010-04-01 11:38:21 +030066 NULL, size, 0,
67 WL1271_RATE_AUTOMATIC);
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +030068 if (ret < 0)
69 return ret;
70 }
71
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030072 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +020073 sizeof(struct wl12xx_null_data_template),
Juuso Oikarinen606c1482010-04-01 11:38:21 +030074 0, WL1271_RATE_AUTOMATIC);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030075 if (ret < 0)
76 return ret;
77
78 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, NULL,
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +020079 sizeof(struct wl12xx_ps_poll_template),
Juuso Oikarinen606c1482010-04-01 11:38:21 +030080 0, WL1271_RATE_AUTOMATIC);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030081 if (ret < 0)
82 return ret;
83
84 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
85 sizeof
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +020086 (struct wl12xx_qos_null_data_template),
Juuso Oikarinen606c1482010-04-01 11:38:21 +030087 0, WL1271_RATE_AUTOMATIC);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030088 if (ret < 0)
89 return ret;
90
91 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE, NULL,
92 sizeof
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +020093 (struct wl12xx_probe_resp_template),
Juuso Oikarinen606c1482010-04-01 11:38:21 +030094 0, WL1271_RATE_AUTOMATIC);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030095 if (ret < 0)
96 return ret;
97
98 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON, NULL,
99 sizeof
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200100 (struct wl12xx_beacon_template),
Juuso Oikarinen606c1482010-04-01 11:38:21 +0300101 0, WL1271_RATE_AUTOMATIC);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300102 if (ret < 0)
103 return ret;
104
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200105 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
106 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV, NULL,
Juuso Oikarinen606c1482010-04-01 11:38:21 +0300107 WL1271_CMD_TEMPL_MAX_SIZE, i,
108 WL1271_RATE_AUTOMATIC);
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200109 if (ret < 0)
110 return ret;
111 }
112
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300113 return 0;
114}
115
116static int wl1271_init_rx_config(struct wl1271 *wl, u32 config, u32 filter)
117{
118 int ret;
119
Juuso Oikarinen8793f9b2009-10-13 12:47:40 +0300120 ret = wl1271_acx_rx_msdu_life_time(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300121 if (ret < 0)
122 return ret;
123
124 ret = wl1271_acx_rx_config(wl, config, filter);
125 if (ret < 0)
126 return ret;
127
128 return 0;
129}
130
Luciano Coelho12419cce2010-02-18 13:25:44 +0200131int wl1271_init_phy_config(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300132{
133 int ret;
134
135 ret = wl1271_acx_pd_threshold(wl);
136 if (ret < 0)
137 return ret;
138
139 ret = wl1271_acx_slot(wl, DEFAULT_SLOT_TIME);
140 if (ret < 0)
141 return ret;
142
Juuso Oikarinenc87dec92009-10-08 21:56:31 +0300143 ret = wl1271_acx_group_address_tbl(wl, true, NULL, 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300144 if (ret < 0)
145 return ret;
146
147 ret = wl1271_acx_service_period_timeout(wl);
148 if (ret < 0)
149 return ret;
150
Juuso Oikarinen8793f9b2009-10-13 12:47:40 +0300151 ret = wl1271_acx_rts_threshold(wl, wl->conf.rx.rts_threshold);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300152 if (ret < 0)
153 return ret;
154
155 return 0;
156}
157
158static int wl1271_init_beacon_filter(struct wl1271 *wl)
159{
160 int ret;
161
Juuso Oikarinen19221672009-10-08 21:56:35 +0300162 /* disable beacon filtering at this stage */
163 ret = wl1271_acx_beacon_filter_opt(wl, false);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300164 if (ret < 0)
165 return ret;
166
167 ret = wl1271_acx_beacon_filter_table(wl);
168 if (ret < 0)
169 return ret;
170
171 return 0;
172}
173
Luciano Coelho12419cce2010-02-18 13:25:44 +0200174int wl1271_init_pta(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300175{
176 int ret;
177
Juuso Oikarinen1b00f542010-03-18 12:26:30 +0200178 ret = wl1271_acx_sg_cfg(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300179 if (ret < 0)
180 return ret;
181
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +0200182 ret = wl1271_acx_sg_enable(wl, wl->sg_enabled);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300183 if (ret < 0)
184 return ret;
185
186 return 0;
187}
188
Luciano Coelho12419cce2010-02-18 13:25:44 +0200189int wl1271_init_energy_detection(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300190{
191 int ret;
192
193 ret = wl1271_acx_cca_threshold(wl);
194 if (ret < 0)
195 return ret;
196
197 return 0;
198}
199
200static int wl1271_init_beacon_broadcast(struct wl1271 *wl)
201{
202 int ret;
203
204 ret = wl1271_acx_bcn_dtim_options(wl);
205 if (ret < 0)
206 return ret;
207
208 return 0;
209}
210
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300211int wl1271_hw_init(struct wl1271 *wl)
212{
Kalle Valo243eeb52010-02-18 13:25:39 +0200213 struct conf_tx_ac_category *conf_ac;
Kalle Valof2054df2010-02-18 13:25:40 +0200214 struct conf_tx_tid *conf_tid;
Kalle Valo243eeb52010-02-18 13:25:39 +0200215 int ret, i;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300216
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200217 ret = wl1271_cmd_general_parms(wl);
Luciano Coelho4a904062009-11-23 23:22:18 +0200218 if (ret < 0)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300219 return ret;
220
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200221 ret = wl1271_cmd_radio_parms(wl);
Luciano Coelho4a904062009-11-23 23:22:18 +0200222 if (ret < 0)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300223 return ret;
224
225 /* Template settings */
226 ret = wl1271_init_templates_config(wl);
227 if (ret < 0)
228 return ret;
229
230 /* Default memory configuration */
231 ret = wl1271_acx_init_mem_config(wl);
232 if (ret < 0)
233 return ret;
234
235 /* RX config */
236 ret = wl1271_init_rx_config(wl,
Juuso Oikarineneb5b28d2009-10-13 12:47:45 +0300237 RX_CFG_PROMISCUOUS | RX_CFG_TSF,
238 RX_FILTER_OPTION_DEF);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300239 /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
240 RX_FILTER_OPTION_FILTER_ALL); */
241 if (ret < 0)
242 goto out_free_memmap;
243
244 /* PHY layer config */
245 ret = wl1271_init_phy_config(wl);
246 if (ret < 0)
247 goto out_free_memmap;
248
Luciano Coelho6e92b412009-12-11 15:40:50 +0200249 ret = wl1271_acx_dco_itrim_params(wl);
250 if (ret < 0)
251 goto out_free_memmap;
252
Juuso Oikarinen34415232009-10-08 21:56:33 +0300253 /* Initialize connection monitoring thresholds */
Juuso Oikarinen6ccbb922010-03-26 12:53:23 +0200254 ret = wl1271_acx_conn_monit_params(wl, false);
Juuso Oikarinen34415232009-10-08 21:56:33 +0300255 if (ret < 0)
256 goto out_free_memmap;
257
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300258 /* Beacon filtering */
259 ret = wl1271_init_beacon_filter(wl);
260 if (ret < 0)
261 goto out_free_memmap;
262
263 /* Configure TX patch complete interrupt behavior */
264 ret = wl1271_acx_tx_config_options(wl);
265 if (ret < 0)
266 goto out_free_memmap;
267
268 /* RX complete interrupt pacing */
269 ret = wl1271_acx_init_rx_interrupt(wl);
270 if (ret < 0)
271 goto out_free_memmap;
272
273 /* Bluetooth WLAN coexistence */
274 ret = wl1271_init_pta(wl);
275 if (ret < 0)
276 goto out_free_memmap;
277
278 /* Energy detection */
279 ret = wl1271_init_energy_detection(wl);
280 if (ret < 0)
281 goto out_free_memmap;
282
283 /* Beacons and boradcast settings */
284 ret = wl1271_init_beacon_broadcast(wl);
285 if (ret < 0)
286 goto out_free_memmap;
287
288 /* Default fragmentation threshold */
289 ret = wl1271_acx_frag_threshold(wl);
290 if (ret < 0)
291 goto out_free_memmap;
292
293 /* Default TID configuration */
Kalle Valof2054df2010-02-18 13:25:40 +0200294 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
295 conf_tid = &wl->conf.tx.tid_conf[i];
296 ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id,
297 conf_tid->channel_type,
298 conf_tid->tsid,
299 conf_tid->ps_scheme,
300 conf_tid->ack_policy,
301 conf_tid->apsd_conf[0],
302 conf_tid->apsd_conf[1]);
303 if (ret < 0)
304 goto out_free_memmap;
305 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300306
307 /* Default AC configuration */
Kalle Valo243eeb52010-02-18 13:25:39 +0200308 for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
309 conf_ac = &wl->conf.tx.ac_conf[i];
310 ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
311 conf_ac->cw_max, conf_ac->aifsn,
312 conf_ac->tx_op_limit);
313 if (ret < 0)
314 goto out_free_memmap;
315 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300316
317 /* Configure TX rate classes */
Juuso Oikarinen830fb672009-12-11 15:41:06 +0200318 ret = wl1271_acx_rate_policies(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300319 if (ret < 0)
320 goto out_free_memmap;
321
322 /* Enable data path */
Luciano Coelho94210892009-12-11 15:40:55 +0200323 ret = wl1271_cmd_data_path(wl, 1);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300324 if (ret < 0)
325 goto out_free_memmap;
326
327 /* Configure for ELP power saving */
328 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
329 if (ret < 0)
330 goto out_free_memmap;
331
332 /* Configure HW encryption */
333 ret = wl1271_init_hwenc_config(wl);
334 if (ret < 0)
335 goto out_free_memmap;
336
Juuso Oikarinen38ad2d82009-12-11 15:41:08 +0200337 /* configure PM */
338 ret = wl1271_acx_pm_config(wl);
339 if (ret < 0)
340 goto out_free_memmap;
341
Juuso Oikarinenc1899552010-03-26 12:53:32 +0200342 /* disable all keep-alive templates */
343 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
344 ret = wl1271_acx_keep_alive_config(wl, i,
345 ACX_KEEP_ALIVE_TPL_INVALID);
346 if (ret < 0)
347 goto out_free_memmap;
348 }
349
350 /* disable the keep-alive feature */
351 ret = wl1271_acx_keep_alive_mode(wl, false);
352 if (ret < 0)
353 goto out_free_memmap;
354
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300355 return 0;
356
357 out_free_memmap:
358 kfree(wl->target_mem_map);
Juuso Oikarinen34415232009-10-08 21:56:33 +0300359 wl->target_mem_map = NULL;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300360
361 return ret;
362}