wl1271: modify wl1271_acx_ac_cfg() to use function parameters
[pandora-kernel.git] / drivers / net / wireless / wl12xx / wl1271_init.c
1 /*
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
33 static 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
52 static int wl1271_init_templates_config(struct wl1271 *wl)
53 {
54         int ret;
55
56         /* send empty templates for fw memory reservation */
57         ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, NULL,
58                                       sizeof(struct wl12xx_probe_req_template));
59         if (ret < 0)
60                 return ret;
61
62         if (wl1271_11a_enabled()) {
63                 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
64                                 NULL,
65                                 sizeof(struct wl12xx_probe_req_template));
66                 if (ret < 0)
67                         return ret;
68         }
69
70         ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
71                                       sizeof(struct wl12xx_null_data_template));
72         if (ret < 0)
73                 return ret;
74
75         ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, NULL,
76                                       sizeof(struct wl12xx_ps_poll_template));
77         if (ret < 0)
78                 return ret;
79
80         ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
81                                       sizeof
82                                       (struct wl12xx_qos_null_data_template));
83         if (ret < 0)
84                 return ret;
85
86         ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE, NULL,
87                                       sizeof
88                                       (struct wl12xx_probe_resp_template));
89         if (ret < 0)
90                 return ret;
91
92         ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON, NULL,
93                                       sizeof
94                                       (struct wl12xx_beacon_template));
95         if (ret < 0)
96                 return ret;
97
98         return 0;
99 }
100
101 static int wl1271_init_rx_config(struct wl1271 *wl, u32 config, u32 filter)
102 {
103         int ret;
104
105         ret = wl1271_acx_rx_msdu_life_time(wl);
106         if (ret < 0)
107                 return ret;
108
109         ret = wl1271_acx_rx_config(wl, config, filter);
110         if (ret < 0)
111                 return ret;
112
113         return 0;
114 }
115
116 static int wl1271_init_phy_config(struct wl1271 *wl)
117 {
118         int ret;
119
120         ret = wl1271_acx_pd_threshold(wl);
121         if (ret < 0)
122                 return ret;
123
124         ret = wl1271_acx_slot(wl, DEFAULT_SLOT_TIME);
125         if (ret < 0)
126                 return ret;
127
128         ret = wl1271_acx_group_address_tbl(wl, true, NULL, 0);
129         if (ret < 0)
130                 return ret;
131
132         ret = wl1271_acx_service_period_timeout(wl);
133         if (ret < 0)
134                 return ret;
135
136         ret = wl1271_acx_rts_threshold(wl, wl->conf.rx.rts_threshold);
137         if (ret < 0)
138                 return ret;
139
140         return 0;
141 }
142
143 static int wl1271_init_beacon_filter(struct wl1271 *wl)
144 {
145         int ret;
146
147         /* disable beacon filtering at this stage */
148         ret = wl1271_acx_beacon_filter_opt(wl, false);
149         if (ret < 0)
150                 return ret;
151
152         ret = wl1271_acx_beacon_filter_table(wl);
153         if (ret < 0)
154                 return ret;
155
156         return 0;
157 }
158
159 static int wl1271_init_pta(struct wl1271 *wl)
160 {
161         int ret;
162
163         ret = wl1271_acx_sg_enable(wl);
164         if (ret < 0)
165                 return ret;
166
167         ret = wl1271_acx_sg_cfg(wl);
168         if (ret < 0)
169                 return ret;
170
171         return 0;
172 }
173
174 static int wl1271_init_energy_detection(struct wl1271 *wl)
175 {
176         int ret;
177
178         ret = wl1271_acx_cca_threshold(wl);
179         if (ret < 0)
180                 return ret;
181
182         return 0;
183 }
184
185 static int wl1271_init_beacon_broadcast(struct wl1271 *wl)
186 {
187         int ret;
188
189         ret = wl1271_acx_bcn_dtim_options(wl);
190         if (ret < 0)
191                 return ret;
192
193         return 0;
194 }
195
196 int wl1271_hw_init(struct wl1271 *wl)
197 {
198         struct conf_tx_ac_category *conf_ac;
199         int ret, i;
200
201         ret = wl1271_cmd_general_parms(wl);
202         if (ret < 0)
203                 return ret;
204
205         ret = wl1271_cmd_radio_parms(wl);
206         if (ret < 0)
207                 return ret;
208
209         /* Template settings */
210         ret = wl1271_init_templates_config(wl);
211         if (ret < 0)
212                 return ret;
213
214         /* Default memory configuration */
215         ret = wl1271_acx_init_mem_config(wl);
216         if (ret < 0)
217                 return ret;
218
219         /* RX config */
220         ret = wl1271_init_rx_config(wl,
221                                     RX_CFG_PROMISCUOUS | RX_CFG_TSF,
222                                     RX_FILTER_OPTION_DEF);
223         /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
224            RX_FILTER_OPTION_FILTER_ALL); */
225         if (ret < 0)
226                 goto out_free_memmap;
227
228         /* PHY layer config */
229         ret = wl1271_init_phy_config(wl);
230         if (ret < 0)
231                 goto out_free_memmap;
232
233         ret = wl1271_acx_dco_itrim_params(wl);
234         if (ret < 0)
235                 goto out_free_memmap;
236
237         /* Initialize connection monitoring thresholds */
238         ret = wl1271_acx_conn_monit_params(wl);
239         if (ret < 0)
240                 goto out_free_memmap;
241
242         /* Beacon filtering */
243         ret = wl1271_init_beacon_filter(wl);
244         if (ret < 0)
245                 goto out_free_memmap;
246
247         /* Configure TX patch complete interrupt behavior */
248         ret = wl1271_acx_tx_config_options(wl);
249         if (ret < 0)
250                 goto out_free_memmap;
251
252         /* RX complete interrupt pacing */
253         ret = wl1271_acx_init_rx_interrupt(wl);
254         if (ret < 0)
255                 goto out_free_memmap;
256
257         /* Bluetooth WLAN coexistence */
258         ret = wl1271_init_pta(wl);
259         if (ret < 0)
260                 goto out_free_memmap;
261
262         /* Energy detection */
263         ret = wl1271_init_energy_detection(wl);
264         if (ret < 0)
265                 goto out_free_memmap;
266
267         /* Beacons and boradcast settings */
268         ret = wl1271_init_beacon_broadcast(wl);
269         if (ret < 0)
270                 goto out_free_memmap;
271
272         /* Default fragmentation threshold */
273         ret = wl1271_acx_frag_threshold(wl);
274         if (ret < 0)
275                 goto out_free_memmap;
276
277         /* Default TID configuration */
278         ret = wl1271_acx_tid_cfg(wl);
279         if (ret < 0)
280                 goto out_free_memmap;
281
282         /* Default AC configuration */
283         for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
284                 conf_ac = &wl->conf.tx.ac_conf[i];
285                 ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
286                                         conf_ac->cw_max, conf_ac->aifsn,
287                                         conf_ac->tx_op_limit);
288                 if (ret < 0)
289                         goto out_free_memmap;
290         }
291
292         /* Configure TX rate classes */
293         ret = wl1271_acx_rate_policies(wl);
294         if (ret < 0)
295                 goto out_free_memmap;
296
297         /* Enable data path */
298         ret = wl1271_cmd_data_path(wl, 1);
299         if (ret < 0)
300                 goto out_free_memmap;
301
302         /* Configure for ELP power saving */
303         ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
304         if (ret < 0)
305                 goto out_free_memmap;
306
307         /* Configure HW encryption */
308         ret = wl1271_init_hwenc_config(wl);
309         if (ret < 0)
310                 goto out_free_memmap;
311
312         /* configure PM */
313         ret = wl1271_acx_pm_config(wl);
314         if (ret < 0)
315                 goto out_free_memmap;
316
317         return 0;
318
319  out_free_memmap:
320         kfree(wl->target_mem_map);
321         wl->target_mem_map = NULL;
322
323         return ret;
324 }