5c2cf1e00ac7f1f5ad6f259b3ebc6681dc1ac669
[linux-2.6.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         ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
63                                       sizeof(struct wl12xx_null_data_template));
64         if (ret < 0)
65                 return ret;
66
67         ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, NULL,
68                                       sizeof(struct wl12xx_ps_poll_template));
69         if (ret < 0)
70                 return ret;
71
72         ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
73                                       sizeof
74                                       (struct wl12xx_qos_null_data_template));
75         if (ret < 0)
76                 return ret;
77
78         ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE, NULL,
79                                       sizeof
80                                       (struct wl12xx_probe_resp_template));
81         if (ret < 0)
82                 return ret;
83
84         ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON, NULL,
85                                       sizeof
86                                       (struct wl12xx_beacon_template));
87         if (ret < 0)
88                 return ret;
89
90         return 0;
91 }
92
93 static int wl1271_init_rx_config(struct wl1271 *wl, u32 config, u32 filter)
94 {
95         int ret;
96
97         ret = wl1271_acx_rx_msdu_life_time(wl);
98         if (ret < 0)
99                 return ret;
100
101         ret = wl1271_acx_rx_config(wl, config, filter);
102         if (ret < 0)
103                 return ret;
104
105         return 0;
106 }
107
108 static int wl1271_init_phy_config(struct wl1271 *wl)
109 {
110         int ret;
111
112         ret = wl1271_acx_pd_threshold(wl);
113         if (ret < 0)
114                 return ret;
115
116         ret = wl1271_acx_slot(wl, DEFAULT_SLOT_TIME);
117         if (ret < 0)
118                 return ret;
119
120         ret = wl1271_acx_group_address_tbl(wl, true, NULL, 0);
121         if (ret < 0)
122                 return ret;
123
124         ret = wl1271_acx_service_period_timeout(wl);
125         if (ret < 0)
126                 return ret;
127
128         ret = wl1271_acx_rts_threshold(wl, wl->conf.rx.rts_threshold);
129         if (ret < 0)
130                 return ret;
131
132         return 0;
133 }
134
135 static int wl1271_init_beacon_filter(struct wl1271 *wl)
136 {
137         int ret;
138
139         /* disable beacon filtering at this stage */
140         ret = wl1271_acx_beacon_filter_opt(wl, false);
141         if (ret < 0)
142                 return ret;
143
144         ret = wl1271_acx_beacon_filter_table(wl);
145         if (ret < 0)
146                 return ret;
147
148         return 0;
149 }
150
151 static int wl1271_init_pta(struct wl1271 *wl)
152 {
153         int ret;
154
155         ret = wl1271_acx_sg_enable(wl);
156         if (ret < 0)
157                 return ret;
158
159         ret = wl1271_acx_sg_cfg(wl);
160         if (ret < 0)
161                 return ret;
162
163         return 0;
164 }
165
166 static int wl1271_init_energy_detection(struct wl1271 *wl)
167 {
168         int ret;
169
170         ret = wl1271_acx_cca_threshold(wl);
171         if (ret < 0)
172                 return ret;
173
174         return 0;
175 }
176
177 static int wl1271_init_beacon_broadcast(struct wl1271 *wl)
178 {
179         int ret;
180
181         ret = wl1271_acx_bcn_dtim_options(wl);
182         if (ret < 0)
183                 return ret;
184
185         return 0;
186 }
187
188 static int wl1271_init_general_parms(struct wl1271 *wl)
189 {
190         struct wl1271_general_parms *gen_parms;
191         struct conf_general_parms *g = &wl->conf.init.genparam;
192         int ret;
193
194         gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
195         if (!gen_parms)
196                 return -ENOMEM;
197
198         gen_parms->id = TEST_CMD_INI_FILE_GENERAL_PARAM;
199
200         gen_parms->ref_clk = g->ref_clk;
201         gen_parms->settling_time = g->settling_time;
202         gen_parms->clk_valid_on_wakeup = g->clk_valid_on_wakeup;
203         gen_parms->dc2dcmode = g->dc2dcmode;
204         gen_parms->single_dual_band = g->single_dual_band;
205         gen_parms->tx_bip_fem_autodetect = g->tx_bip_fem_autodetect;
206         gen_parms->tx_bip_fem_manufacturer = g->tx_bip_fem_manufacturer;
207         gen_parms->settings = g->settings;
208
209         ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), 0);
210         if (ret < 0) {
211                 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
212                 return ret;
213         }
214
215         kfree(gen_parms);
216         return 0;
217 }
218
219 static int wl1271_init_radio_parms(struct wl1271 *wl)
220 {
221         struct wl1271_radio_parms *radio_parms;
222         struct conf_radio_parms *r = &wl->conf.init.radioparam;
223         int i, ret;
224
225         radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
226         if (!radio_parms)
227                 return -ENOMEM;
228
229         radio_parms->id = TEST_CMD_INI_FILE_RADIO_PARAM;
230
231         /* Static radio parameters */
232         radio_parms->rx_trace_loss = r->rx_trace_loss;
233         radio_parms->tx_trace_loss = r->tx_trace_loss;
234         memcpy(radio_parms->rx_rssi_and_proc_compens,
235                r->rx_rssi_and_proc_compens,
236                CONF_RSSI_AND_PROCESS_COMPENSATION_SIZE);
237
238         memcpy(radio_parms->rx_trace_loss_5, r->rx_trace_loss_5,
239                CONF_NUMBER_OF_SUB_BANDS_5);
240         memcpy(radio_parms->tx_trace_loss_5, r->tx_trace_loss_5,
241                CONF_NUMBER_OF_SUB_BANDS_5);
242         memcpy(radio_parms->rx_rssi_and_proc_compens_5,
243                r->rx_rssi_and_proc_compens_5,
244                CONF_RSSI_AND_PROCESS_COMPENSATION_SIZE);
245
246         /* Dynamic radio parameters */
247         radio_parms->tx_ref_pd_voltage = cpu_to_le16(r->tx_ref_pd_voltage);
248         radio_parms->tx_ref_power = r->tx_ref_power;
249         radio_parms->tx_offset_db = r->tx_offset_db;
250
251         memcpy(radio_parms->tx_rate_limits_normal, r->tx_rate_limits_normal,
252                CONF_NUMBER_OF_RATE_GROUPS);
253         memcpy(radio_parms->tx_rate_limits_degraded, r->tx_rate_limits_degraded,
254                CONF_NUMBER_OF_RATE_GROUPS);
255
256         memcpy(radio_parms->tx_channel_limits_11b, r->tx_channel_limits_11b,
257                CONF_NUMBER_OF_CHANNELS_2_4);
258         memcpy(radio_parms->tx_channel_limits_ofdm, r->tx_channel_limits_ofdm,
259                CONF_NUMBER_OF_CHANNELS_2_4);
260         memcpy(radio_parms->tx_pdv_rate_offsets, r->tx_pdv_rate_offsets,
261                CONF_NUMBER_OF_RATE_GROUPS);
262         memcpy(radio_parms->tx_ibias, r->tx_ibias, CONF_NUMBER_OF_RATE_GROUPS);
263
264         radio_parms->rx_fem_insertion_loss = r->rx_fem_insertion_loss;
265
266         for (i = 0; i < CONF_NUMBER_OF_SUB_BANDS_5; i++)
267                 radio_parms->tx_ref_pd_voltage_5[i] =
268                         cpu_to_le16(r->tx_ref_pd_voltage_5[i]);
269         memcpy(radio_parms->tx_ref_power_5, r->tx_ref_power_5,
270                CONF_NUMBER_OF_SUB_BANDS_5);
271         memcpy(radio_parms->tx_offset_db_5, r->tx_offset_db_5,
272                CONF_NUMBER_OF_SUB_BANDS_5);
273         memcpy(radio_parms->tx_rate_limits_normal_5,
274                r->tx_rate_limits_normal_5, CONF_NUMBER_OF_RATE_GROUPS);
275         memcpy(radio_parms->tx_rate_limits_degraded_5,
276                r->tx_rate_limits_degraded_5, CONF_NUMBER_OF_RATE_GROUPS);
277         memcpy(radio_parms->tx_channel_limits_ofdm_5,
278                r->tx_channel_limits_ofdm_5, CONF_NUMBER_OF_CHANNELS_5);
279         memcpy(radio_parms->tx_pdv_rate_offsets_5, r->tx_pdv_rate_offsets_5,
280                CONF_NUMBER_OF_RATE_GROUPS);
281         memcpy(radio_parms->tx_ibias_5, r->tx_ibias_5,
282                CONF_NUMBER_OF_RATE_GROUPS);
283         memcpy(radio_parms->rx_fem_insertion_loss_5,
284                r->rx_fem_insertion_loss_5, CONF_NUMBER_OF_SUB_BANDS_5);
285
286         ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
287         if (ret < 0)
288                 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
289
290         kfree(radio_parms);
291         return ret;
292 }
293
294 int wl1271_hw_init(struct wl1271 *wl)
295 {
296         int ret;
297
298         ret = wl1271_init_general_parms(wl);
299         if (ret < 0)
300                 return ret;
301
302         ret = wl1271_init_radio_parms(wl);
303         if (ret < 0)
304                 return ret;
305
306         /* Template settings */
307         ret = wl1271_init_templates_config(wl);
308         if (ret < 0)
309                 return ret;
310
311         /* Default memory configuration */
312         ret = wl1271_acx_init_mem_config(wl);
313         if (ret < 0)
314                 return ret;
315
316         /* RX config */
317         ret = wl1271_init_rx_config(wl,
318                                        RX_CFG_PROMISCUOUS | RX_CFG_TSF,
319                                        RX_FILTER_OPTION_DEF);
320         /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
321            RX_FILTER_OPTION_FILTER_ALL); */
322         if (ret < 0)
323                 goto out_free_memmap;
324
325         /* PHY layer config */
326         ret = wl1271_init_phy_config(wl);
327         if (ret < 0)
328                 goto out_free_memmap;
329
330         /* Initialize connection monitoring thresholds */
331         ret = wl1271_acx_conn_monit_params(wl);
332         if (ret < 0)
333                 goto out_free_memmap;
334
335         /* Beacon filtering */
336         ret = wl1271_init_beacon_filter(wl);
337         if (ret < 0)
338                 goto out_free_memmap;
339
340         /* Configure TX patch complete interrupt behavior */
341         ret = wl1271_acx_tx_config_options(wl);
342         if (ret < 0)
343                 goto out_free_memmap;
344
345         /* RX complete interrupt pacing */
346         ret = wl1271_acx_init_rx_interrupt(wl);
347         if (ret < 0)
348                 goto out_free_memmap;
349
350         /* Bluetooth WLAN coexistence */
351         ret = wl1271_init_pta(wl);
352         if (ret < 0)
353                 goto out_free_memmap;
354
355         /* Energy detection */
356         ret = wl1271_init_energy_detection(wl);
357         if (ret < 0)
358                 goto out_free_memmap;
359
360         /* Beacons and boradcast settings */
361         ret = wl1271_init_beacon_broadcast(wl);
362         if (ret < 0)
363                 goto out_free_memmap;
364
365         /* Default fragmentation threshold */
366         ret = wl1271_acx_frag_threshold(wl);
367         if (ret < 0)
368                 goto out_free_memmap;
369
370         /* Default TID configuration */
371         ret = wl1271_acx_tid_cfg(wl);
372         if (ret < 0)
373                 goto out_free_memmap;
374
375         /* Default AC configuration */
376         ret = wl1271_acx_ac_cfg(wl);
377         if (ret < 0)
378                 goto out_free_memmap;
379
380         /* Configure TX rate classes */
381         ret = wl1271_acx_rate_policies(wl, CONF_TX_RATE_MASK_ALL);
382         if (ret < 0)
383                 goto out_free_memmap;
384
385         /* Enable data path */
386         ret = wl1271_cmd_data_path(wl, wl->channel, 1);
387         if (ret < 0)
388                 goto out_free_memmap;
389
390         /* Configure for ELP power saving */
391         ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
392         if (ret < 0)
393                 goto out_free_memmap;
394
395         /* Configure HW encryption */
396         ret = wl1271_init_hwenc_config(wl);
397         if (ret < 0)
398                 goto out_free_memmap;
399
400         /* Configure smart reflex */
401         ret = wl1271_acx_smart_reflex(wl);
402         if (ret < 0)
403                 goto out_free_memmap;
404
405         return 0;
406
407  out_free_memmap:
408         kfree(wl->target_mem_map);
409         wl->target_mem_map = NULL;
410
411         return ret;
412 }