blob: 8044bba70ee789b377e1183cef516cd34d36d02b [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030027
28#include "wl1271_init.h"
29#include "wl12xx_80211.h"
30#include "wl1271_acx.h"
31#include "wl1271_cmd.h"
32#include "wl1271_reg.h"
33
34static int wl1271_init_hwenc_config(struct wl1271 *wl)
35{
36 int ret;
37
38 ret = wl1271_acx_feature_cfg(wl);
39 if (ret < 0) {
40 wl1271_warning("couldn't set feature config");
41 return ret;
42 }
43
44 ret = wl1271_cmd_set_default_wep_key(wl, wl->default_key);
45 if (ret < 0) {
46 wl1271_warning("couldn't set default key");
47 return ret;
48 }
49
50 return 0;
51}
52
Luciano Coelho12419cc2010-02-18 13:25:44 +020053int wl1271_init_templates_config(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030054{
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +020055 int ret, i;
Juuso Oikarinen11eb5422010-08-24 06:28:03 +030056 size_t size;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030057
58 /* send empty templates for fw memory reservation */
59 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, NULL,
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +020060 sizeof(struct wl12xx_probe_req_template),
Juuso Oikarinen606c1482010-04-01 11:38:21 +030061 0, WL1271_RATE_AUTOMATIC);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030062 if (ret < 0)
63 return ret;
64
Juuso Oikarinen11eb5422010-08-24 06:28:03 +030065 size = sizeof(struct wl12xx_probe_req_template);
66 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
67 NULL, size, 0,
68 WL1271_RATE_AUTOMATIC);
69 if (ret < 0)
70 return ret;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +030071
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 Coelho12419cc2010-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 Coelho12419cc2010-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 Coelho12419cc2010-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
Juuso Oikarinen644a4862010-10-05 13:11:56 +0200225 ret = wl1271_cmd_ext_radio_parms(wl);
226 if (ret < 0)
227 return ret;
228
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300229 /* Template settings */
230 ret = wl1271_init_templates_config(wl);
231 if (ret < 0)
232 return ret;
233
234 /* Default memory configuration */
235 ret = wl1271_acx_init_mem_config(wl);
236 if (ret < 0)
237 return ret;
238
239 /* RX config */
240 ret = wl1271_init_rx_config(wl,
Juuso Oikarineneb5b28d2009-10-13 12:47:45 +0300241 RX_CFG_PROMISCUOUS | RX_CFG_TSF,
242 RX_FILTER_OPTION_DEF);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300243 /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
244 RX_FILTER_OPTION_FILTER_ALL); */
245 if (ret < 0)
246 goto out_free_memmap;
247
248 /* PHY layer config */
249 ret = wl1271_init_phy_config(wl);
250 if (ret < 0)
251 goto out_free_memmap;
252
Luciano Coelho6e92b412009-12-11 15:40:50 +0200253 ret = wl1271_acx_dco_itrim_params(wl);
254 if (ret < 0)
255 goto out_free_memmap;
256
Juuso Oikarinen34415232009-10-08 21:56:33 +0300257 /* Initialize connection monitoring thresholds */
Juuso Oikarinen6ccbb922010-03-26 12:53:23 +0200258 ret = wl1271_acx_conn_monit_params(wl, false);
Juuso Oikarinen34415232009-10-08 21:56:33 +0300259 if (ret < 0)
260 goto out_free_memmap;
261
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300262 /* Beacon filtering */
263 ret = wl1271_init_beacon_filter(wl);
264 if (ret < 0)
265 goto out_free_memmap;
266
267 /* Configure TX patch complete interrupt behavior */
268 ret = wl1271_acx_tx_config_options(wl);
269 if (ret < 0)
270 goto out_free_memmap;
271
272 /* RX complete interrupt pacing */
273 ret = wl1271_acx_init_rx_interrupt(wl);
274 if (ret < 0)
275 goto out_free_memmap;
276
277 /* Bluetooth WLAN coexistence */
278 ret = wl1271_init_pta(wl);
279 if (ret < 0)
280 goto out_free_memmap;
281
282 /* Energy detection */
283 ret = wl1271_init_energy_detection(wl);
284 if (ret < 0)
285 goto out_free_memmap;
286
287 /* Beacons and boradcast settings */
288 ret = wl1271_init_beacon_broadcast(wl);
289 if (ret < 0)
290 goto out_free_memmap;
291
292 /* Default fragmentation threshold */
293 ret = wl1271_acx_frag_threshold(wl);
294 if (ret < 0)
295 goto out_free_memmap;
296
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200297 /* Default TID/AC configuration */
298 BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
Kalle Valof2054df2010-02-18 13:25:40 +0200299 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200300 conf_ac = &wl->conf.tx.ac_conf[i];
301 ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
302 conf_ac->cw_max, conf_ac->aifsn,
303 conf_ac->tx_op_limit);
304 if (ret < 0)
305 goto out_free_memmap;
306
Kalle Valof2054df2010-02-18 13:25:40 +0200307 conf_tid = &wl->conf.tx.tid_conf[i];
308 ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id,
309 conf_tid->channel_type,
310 conf_tid->tsid,
311 conf_tid->ps_scheme,
312 conf_tid->ack_policy,
313 conf_tid->apsd_conf[0],
314 conf_tid->apsd_conf[1]);
315 if (ret < 0)
316 goto out_free_memmap;
317 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300318
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300319 /* Configure TX rate classes */
Juuso Oikarinen830fb672009-12-11 15:41:06 +0200320 ret = wl1271_acx_rate_policies(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300321 if (ret < 0)
322 goto out_free_memmap;
323
324 /* Enable data path */
Luciano Coelho94210892009-12-11 15:40:55 +0200325 ret = wl1271_cmd_data_path(wl, 1);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300326 if (ret < 0)
327 goto out_free_memmap;
328
329 /* Configure for ELP power saving */
330 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
331 if (ret < 0)
332 goto out_free_memmap;
333
334 /* Configure HW encryption */
335 ret = wl1271_init_hwenc_config(wl);
336 if (ret < 0)
337 goto out_free_memmap;
338
Juuso Oikarinen38ad2d82009-12-11 15:41:08 +0200339 /* configure PM */
340 ret = wl1271_acx_pm_config(wl);
341 if (ret < 0)
342 goto out_free_memmap;
343
Juuso Oikarinenc1899552010-03-26 12:53:32 +0200344 /* disable all keep-alive templates */
345 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
346 ret = wl1271_acx_keep_alive_config(wl, i,
347 ACX_KEEP_ALIVE_TPL_INVALID);
348 if (ret < 0)
349 goto out_free_memmap;
350 }
351
352 /* disable the keep-alive feature */
353 ret = wl1271_acx_keep_alive_mode(wl, false);
354 if (ret < 0)
355 goto out_free_memmap;
356
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300357 /* Configure rssi/snr averaging weights */
358 ret = wl1271_acx_rssi_snr_avg_weights(wl);
359 if (ret < 0)
360 goto out_free_memmap;
361
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300362 return 0;
363
364 out_free_memmap:
365 kfree(wl->target_mem_map);
Juuso Oikarinen34415232009-10-08 21:56:33 +0300366 wl->target_mem_map = NULL;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300367
368 return ret;
369}