proc: use seq_puts()/seq_putc() where possible
[linux-2.6/next.git] / drivers / net / wireless / wl12xx / init.c
blob785a5304bfc4435c592791589b19b504978b32dc
1 /*
2 * This file is part of wl1271
4 * Copyright (C) 2009 Nokia Corporation
6 * Contact: Luciano Coelho <luciano.coelho@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
20 * 02110-1301 USA
24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/slab.h>
28 #include "init.h"
29 #include "wl12xx_80211.h"
30 #include "acx.h"
31 #include "cmd.h"
32 #include "reg.h"
34 static int wl1271_init_hwenc_config(struct wl1271 *wl)
36 int ret;
38 ret = wl1271_acx_feature_cfg(wl);
39 if (ret < 0) {
40 wl1271_warning("couldn't set feature config");
41 return ret;
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;
50 return 0;
53 int wl1271_init_templates_config(struct wl1271 *wl)
55 int ret, i;
57 /* send empty templates for fw memory reservation */
58 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, NULL,
59 WL1271_CMD_TEMPL_MAX_SIZE,
60 0, WL1271_RATE_AUTOMATIC);
61 if (ret < 0)
62 return ret;
64 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
65 NULL, WL1271_CMD_TEMPL_MAX_SIZE, 0,
66 WL1271_RATE_AUTOMATIC);
67 if (ret < 0)
68 return ret;
70 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
71 sizeof(struct wl12xx_null_data_template),
72 0, WL1271_RATE_AUTOMATIC);
73 if (ret < 0)
74 return ret;
76 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, NULL,
77 sizeof(struct wl12xx_ps_poll_template),
78 0, WL1271_RATE_AUTOMATIC);
79 if (ret < 0)
80 return ret;
82 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
83 sizeof
84 (struct wl12xx_qos_null_data_template),
85 0, WL1271_RATE_AUTOMATIC);
86 if (ret < 0)
87 return ret;
89 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE, NULL,
90 sizeof
91 (struct wl12xx_probe_resp_template),
92 0, WL1271_RATE_AUTOMATIC);
93 if (ret < 0)
94 return ret;
96 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON, NULL,
97 sizeof
98 (struct wl12xx_beacon_template),
99 0, WL1271_RATE_AUTOMATIC);
100 if (ret < 0)
101 return ret;
103 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_ARP_RSP, NULL,
104 sizeof
105 (struct wl12xx_arp_rsp_template),
106 0, WL1271_RATE_AUTOMATIC);
107 if (ret < 0)
108 return ret;
110 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
111 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV, NULL,
112 WL1271_CMD_TEMPL_MAX_SIZE, i,
113 WL1271_RATE_AUTOMATIC);
114 if (ret < 0)
115 return ret;
118 return 0;
121 static int wl1271_init_rx_config(struct wl1271 *wl, u32 config, u32 filter)
123 int ret;
125 ret = wl1271_acx_rx_msdu_life_time(wl);
126 if (ret < 0)
127 return ret;
129 ret = wl1271_acx_rx_config(wl, config, filter);
130 if (ret < 0)
131 return ret;
133 return 0;
136 int wl1271_init_phy_config(struct wl1271 *wl)
138 int ret;
140 ret = wl1271_acx_pd_threshold(wl);
141 if (ret < 0)
142 return ret;
144 ret = wl1271_acx_slot(wl, DEFAULT_SLOT_TIME);
145 if (ret < 0)
146 return ret;
148 ret = wl1271_acx_group_address_tbl(wl, true, NULL, 0);
149 if (ret < 0)
150 return ret;
152 ret = wl1271_acx_service_period_timeout(wl);
153 if (ret < 0)
154 return ret;
156 ret = wl1271_acx_rts_threshold(wl, wl->conf.rx.rts_threshold);
157 if (ret < 0)
158 return ret;
160 return 0;
163 static int wl1271_init_beacon_filter(struct wl1271 *wl)
165 int ret;
167 /* disable beacon filtering at this stage */
168 ret = wl1271_acx_beacon_filter_opt(wl, false);
169 if (ret < 0)
170 return ret;
172 ret = wl1271_acx_beacon_filter_table(wl);
173 if (ret < 0)
174 return ret;
176 return 0;
179 int wl1271_init_pta(struct wl1271 *wl)
181 int ret;
183 ret = wl1271_acx_sg_cfg(wl);
184 if (ret < 0)
185 return ret;
187 ret = wl1271_acx_sg_enable(wl, wl->sg_enabled);
188 if (ret < 0)
189 return ret;
191 return 0;
194 int wl1271_init_energy_detection(struct wl1271 *wl)
196 int ret;
198 ret = wl1271_acx_cca_threshold(wl);
199 if (ret < 0)
200 return ret;
202 return 0;
205 static int wl1271_init_beacon_broadcast(struct wl1271 *wl)
207 int ret;
209 ret = wl1271_acx_bcn_dtim_options(wl);
210 if (ret < 0)
211 return ret;
213 return 0;
216 int wl1271_hw_init(struct wl1271 *wl)
218 struct conf_tx_ac_category *conf_ac;
219 struct conf_tx_tid *conf_tid;
220 int ret, i;
222 ret = wl1271_cmd_general_parms(wl);
223 if (ret < 0)
224 return ret;
226 ret = wl1271_cmd_radio_parms(wl);
227 if (ret < 0)
228 return ret;
230 ret = wl1271_cmd_ext_radio_parms(wl);
231 if (ret < 0)
232 return ret;
234 /* Template settings */
235 ret = wl1271_init_templates_config(wl);
236 if (ret < 0)
237 return ret;
239 /* Default memory configuration */
240 ret = wl1271_acx_init_mem_config(wl);
241 if (ret < 0)
242 return ret;
244 /* RX config */
245 ret = wl1271_init_rx_config(wl,
246 RX_CFG_PROMISCUOUS | RX_CFG_TSF,
247 RX_FILTER_OPTION_DEF);
248 /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
249 RX_FILTER_OPTION_FILTER_ALL); */
250 if (ret < 0)
251 goto out_free_memmap;
253 /* PHY layer config */
254 ret = wl1271_init_phy_config(wl);
255 if (ret < 0)
256 goto out_free_memmap;
258 ret = wl1271_acx_dco_itrim_params(wl);
259 if (ret < 0)
260 goto out_free_memmap;
262 /* Initialize connection monitoring thresholds */
263 ret = wl1271_acx_conn_monit_params(wl, false);
264 if (ret < 0)
265 goto out_free_memmap;
267 /* Beacon filtering */
268 ret = wl1271_init_beacon_filter(wl);
269 if (ret < 0)
270 goto out_free_memmap;
272 /* Configure TX patch complete interrupt behavior */
273 ret = wl1271_acx_tx_config_options(wl);
274 if (ret < 0)
275 goto out_free_memmap;
277 /* RX complete interrupt pacing */
278 ret = wl1271_acx_init_rx_interrupt(wl);
279 if (ret < 0)
280 goto out_free_memmap;
282 /* Bluetooth WLAN coexistence */
283 ret = wl1271_init_pta(wl);
284 if (ret < 0)
285 goto out_free_memmap;
287 /* Energy detection */
288 ret = wl1271_init_energy_detection(wl);
289 if (ret < 0)
290 goto out_free_memmap;
292 /* Beacons and boradcast settings */
293 ret = wl1271_init_beacon_broadcast(wl);
294 if (ret < 0)
295 goto out_free_memmap;
297 /* Default fragmentation threshold */
298 ret = wl1271_acx_frag_threshold(wl, wl->conf.tx.frag_threshold);
299 if (ret < 0)
300 goto out_free_memmap;
302 /* Default TID/AC configuration */
303 BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
304 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
305 conf_ac = &wl->conf.tx.ac_conf[i];
306 ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
307 conf_ac->cw_max, conf_ac->aifsn,
308 conf_ac->tx_op_limit);
309 if (ret < 0)
310 goto out_free_memmap;
312 conf_tid = &wl->conf.tx.tid_conf[i];
313 ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id,
314 conf_tid->channel_type,
315 conf_tid->tsid,
316 conf_tid->ps_scheme,
317 conf_tid->ack_policy,
318 conf_tid->apsd_conf[0],
319 conf_tid->apsd_conf[1]);
320 if (ret < 0)
321 goto out_free_memmap;
324 /* Configure TX rate classes */
325 ret = wl1271_acx_rate_policies(wl);
326 if (ret < 0)
327 goto out_free_memmap;
329 /* Enable data path */
330 ret = wl1271_cmd_data_path(wl, 1);
331 if (ret < 0)
332 goto out_free_memmap;
334 /* Configure for ELP power saving */
335 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
336 if (ret < 0)
337 goto out_free_memmap;
339 /* Configure HW encryption */
340 ret = wl1271_init_hwenc_config(wl);
341 if (ret < 0)
342 goto out_free_memmap;
344 /* configure PM */
345 ret = wl1271_acx_pm_config(wl);
346 if (ret < 0)
347 goto out_free_memmap;
349 /* disable all keep-alive templates */
350 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
351 ret = wl1271_acx_keep_alive_config(wl, i,
352 ACX_KEEP_ALIVE_TPL_INVALID);
353 if (ret < 0)
354 goto out_free_memmap;
357 /* disable the keep-alive feature */
358 ret = wl1271_acx_keep_alive_mode(wl, false);
359 if (ret < 0)
360 goto out_free_memmap;
362 /* Configure rssi/snr averaging weights */
363 ret = wl1271_acx_rssi_snr_avg_weights(wl);
364 if (ret < 0)
365 goto out_free_memmap;
367 return 0;
369 out_free_memmap:
370 kfree(wl->target_mem_map);
371 wl->target_mem_map = NULL;
373 return ret;