wl12xx: AP-mode - disable beacon filtering on start up
[linux-2.6.git] / drivers / net / wireless / wl12xx / 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 #include <linux/slab.h>
27
28 #include "init.h"
29 #include "wl12xx_80211.h"
30 #include "acx.h"
31 #include "cmd.h"
32 #include "reg.h"
33 #include "tx.h"
34 #include "io.h"
35
36 int wl1271_sta_init_templates_config(struct wl1271 *wl)
37 {
38         int ret, i;
39
40         /* send empty templates for fw memory reservation */
41         ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, NULL,
42                                       WL1271_CMD_TEMPL_MAX_SIZE,
43                                       0, WL1271_RATE_AUTOMATIC);
44         if (ret < 0)
45                 return ret;
46
47         ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
48                                       NULL, WL1271_CMD_TEMPL_MAX_SIZE, 0,
49                                       WL1271_RATE_AUTOMATIC);
50         if (ret < 0)
51                 return ret;
52
53         ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
54                                       sizeof(struct wl12xx_null_data_template),
55                                       0, WL1271_RATE_AUTOMATIC);
56         if (ret < 0)
57                 return ret;
58
59         ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, NULL,
60                                       sizeof(struct wl12xx_ps_poll_template),
61                                       0, WL1271_RATE_AUTOMATIC);
62         if (ret < 0)
63                 return ret;
64
65         ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
66                                       sizeof
67                                       (struct wl12xx_qos_null_data_template),
68                                       0, WL1271_RATE_AUTOMATIC);
69         if (ret < 0)
70                 return ret;
71
72         ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE, NULL,
73                                       sizeof
74                                       (struct wl12xx_probe_resp_template),
75                                       0, WL1271_RATE_AUTOMATIC);
76         if (ret < 0)
77                 return ret;
78
79         ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON, NULL,
80                                       sizeof
81                                       (struct wl12xx_beacon_template),
82                                       0, WL1271_RATE_AUTOMATIC);
83         if (ret < 0)
84                 return ret;
85
86         ret = wl1271_cmd_template_set(wl, CMD_TEMPL_ARP_RSP, NULL,
87                                       sizeof
88                                       (struct wl12xx_arp_rsp_template),
89                                       0, WL1271_RATE_AUTOMATIC);
90         if (ret < 0)
91                 return ret;
92
93         for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
94                 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV, NULL,
95                                               WL1271_CMD_TEMPL_MAX_SIZE, i,
96                                               WL1271_RATE_AUTOMATIC);
97                 if (ret < 0)
98                         return ret;
99         }
100
101         return 0;
102 }
103
104 static int wl1271_ap_init_deauth_template(struct wl1271 *wl)
105 {
106         struct wl12xx_disconn_template *tmpl;
107         int ret;
108
109         tmpl = kzalloc(sizeof(*tmpl), GFP_KERNEL);
110         if (!tmpl) {
111                 ret = -ENOMEM;
112                 goto out;
113         }
114
115         tmpl->header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT |
116                                              IEEE80211_STYPE_DEAUTH);
117
118         ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP,
119                                       tmpl, sizeof(*tmpl), 0,
120                                       wl1271_tx_min_rate_get(wl));
121
122 out:
123         kfree(tmpl);
124         return ret;
125 }
126
127 static int wl1271_ap_init_null_template(struct wl1271 *wl)
128 {
129         struct ieee80211_hdr_3addr *nullfunc;
130         int ret;
131
132         nullfunc = kzalloc(sizeof(*nullfunc), GFP_KERNEL);
133         if (!nullfunc) {
134                 ret = -ENOMEM;
135                 goto out;
136         }
137
138         nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
139                                               IEEE80211_STYPE_NULLFUNC |
140                                               IEEE80211_FCTL_FROMDS);
141
142         /* nullfunc->addr1 is filled by FW */
143
144         memcpy(nullfunc->addr2, wl->mac_addr, ETH_ALEN);
145         memcpy(nullfunc->addr3, wl->mac_addr, ETH_ALEN);
146
147         ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, nullfunc,
148                                       sizeof(*nullfunc), 0,
149                                       wl1271_tx_min_rate_get(wl));
150
151 out:
152         kfree(nullfunc);
153         return ret;
154 }
155
156 static int wl1271_ap_init_qos_null_template(struct wl1271 *wl)
157 {
158         struct ieee80211_qos_hdr *qosnull;
159         int ret;
160
161         qosnull = kzalloc(sizeof(*qosnull), GFP_KERNEL);
162         if (!qosnull) {
163                 ret = -ENOMEM;
164                 goto out;
165         }
166
167         qosnull->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
168                                              IEEE80211_STYPE_QOS_NULLFUNC |
169                                              IEEE80211_FCTL_FROMDS);
170
171         /* qosnull->addr1 is filled by FW */
172
173         memcpy(qosnull->addr2, wl->mac_addr, ETH_ALEN);
174         memcpy(qosnull->addr3, wl->mac_addr, ETH_ALEN);
175
176         ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, qosnull,
177                                       sizeof(*qosnull), 0,
178                                       wl1271_tx_min_rate_get(wl));
179
180 out:
181         kfree(qosnull);
182         return ret;
183 }
184
185 static int wl1271_ap_init_templates_config(struct wl1271 *wl)
186 {
187         int ret;
188
189         /*
190          * Put very large empty placeholders for all templates. These
191          * reserve memory for later.
192          */
193         ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_PROBE_RESPONSE, NULL,
194                                       sizeof
195                                       (struct wl12xx_probe_resp_template),
196                                       0, WL1271_RATE_AUTOMATIC);
197         if (ret < 0)
198                 return ret;
199
200         ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_BEACON, NULL,
201                                       sizeof
202                                       (struct wl12xx_beacon_template),
203                                       0, WL1271_RATE_AUTOMATIC);
204         if (ret < 0)
205                 return ret;
206
207         ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP, NULL,
208                                       sizeof
209                                       (struct wl12xx_disconn_template),
210                                       0, WL1271_RATE_AUTOMATIC);
211         if (ret < 0)
212                 return ret;
213
214         ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
215                                       sizeof(struct wl12xx_null_data_template),
216                                       0, WL1271_RATE_AUTOMATIC);
217         if (ret < 0)
218                 return ret;
219
220         ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
221                                       sizeof
222                                       (struct wl12xx_qos_null_data_template),
223                                       0, WL1271_RATE_AUTOMATIC);
224         if (ret < 0)
225                 return ret;
226
227         return 0;
228 }
229
230 static int wl1271_init_rx_config(struct wl1271 *wl, u32 config, u32 filter)
231 {
232         int ret;
233
234         ret = wl1271_acx_rx_msdu_life_time(wl);
235         if (ret < 0)
236                 return ret;
237
238         ret = wl1271_acx_rx_config(wl, config, filter);
239         if (ret < 0)
240                 return ret;
241
242         return 0;
243 }
244
245 int wl1271_init_phy_config(struct wl1271 *wl)
246 {
247         int ret;
248
249         ret = wl1271_acx_pd_threshold(wl);
250         if (ret < 0)
251                 return ret;
252
253         ret = wl1271_acx_slot(wl, DEFAULT_SLOT_TIME);
254         if (ret < 0)
255                 return ret;
256
257         ret = wl1271_acx_service_period_timeout(wl);
258         if (ret < 0)
259                 return ret;
260
261         ret = wl1271_acx_rts_threshold(wl, wl->hw->wiphy->rts_threshold);
262         if (ret < 0)
263                 return ret;
264
265         return 0;
266 }
267
268 static int wl1271_init_beacon_filter(struct wl1271 *wl)
269 {
270         int ret;
271
272         /* disable beacon filtering at this stage */
273         ret = wl1271_acx_beacon_filter_opt(wl, false);
274         if (ret < 0)
275                 return ret;
276
277         ret = wl1271_acx_beacon_filter_table(wl);
278         if (ret < 0)
279                 return ret;
280
281         return 0;
282 }
283
284 int wl1271_init_pta(struct wl1271 *wl)
285 {
286         int ret;
287
288         if (wl->bss_type == BSS_TYPE_AP_BSS)
289                 ret = wl1271_acx_ap_sg_cfg(wl);
290         else
291                 ret = wl1271_acx_sta_sg_cfg(wl);
292         if (ret < 0)
293                 return ret;
294
295         ret = wl1271_acx_sg_enable(wl, wl->sg_enabled);
296         if (ret < 0)
297                 return ret;
298
299         return 0;
300 }
301
302 int wl1271_init_energy_detection(struct wl1271 *wl)
303 {
304         int ret;
305
306         ret = wl1271_acx_cca_threshold(wl);
307         if (ret < 0)
308                 return ret;
309
310         return 0;
311 }
312
313 static int wl1271_init_beacon_broadcast(struct wl1271 *wl)
314 {
315         int ret;
316
317         ret = wl1271_acx_bcn_dtim_options(wl);
318         if (ret < 0)
319                 return ret;
320
321         return 0;
322 }
323
324 static int wl1271_sta_hw_init(struct wl1271 *wl)
325 {
326         int ret;
327
328         if (wl->chip.id != CHIP_ID_1283_PG20) {
329                 ret = wl1271_cmd_ext_radio_parms(wl);
330                 if (ret < 0)
331                         return ret;
332         }
333
334         /* PS config */
335         ret = wl1271_acx_config_ps(wl);
336         if (ret < 0)
337                 return ret;
338
339         ret = wl1271_sta_init_templates_config(wl);
340         if (ret < 0)
341                 return ret;
342
343         ret = wl1271_acx_group_address_tbl(wl, true, NULL, 0);
344         if (ret < 0)
345                 return ret;
346
347         /* Initialize connection monitoring thresholds */
348         ret = wl1271_acx_conn_monit_params(wl, false);
349         if (ret < 0)
350                 return ret;
351
352         /* Beacon filtering */
353         ret = wl1271_init_beacon_filter(wl);
354         if (ret < 0)
355                 return ret;
356
357         /* FM WLAN coexistence */
358         ret = wl1271_acx_fm_coex(wl);
359         if (ret < 0)
360                 return ret;
361
362         /* Beacons and broadcast settings */
363         ret = wl1271_init_beacon_broadcast(wl);
364         if (ret < 0)
365                 return ret;
366
367         /* Configure for ELP power saving */
368         ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
369         if (ret < 0)
370                 return ret;
371
372         /* Configure rssi/snr averaging weights */
373         ret = wl1271_acx_rssi_snr_avg_weights(wl);
374         if (ret < 0)
375                 return ret;
376
377         ret = wl1271_acx_sta_rate_policies(wl);
378         if (ret < 0)
379                 return ret;
380
381         ret = wl1271_acx_sta_max_tx_retry(wl);
382         if (ret < 0)
383                 return ret;
384
385         ret = wl1271_acx_sta_mem_cfg(wl);
386         if (ret < 0)
387                 return ret;
388
389         return 0;
390 }
391
392 static int wl1271_sta_hw_init_post_mem(struct wl1271 *wl)
393 {
394         int ret, i;
395
396         ret = wl1271_cmd_set_sta_default_wep_key(wl, wl->default_key);
397         if (ret < 0) {
398                 wl1271_warning("couldn't set default key");
399                 return ret;
400         }
401
402         /* disable all keep-alive templates */
403         for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
404                 ret = wl1271_acx_keep_alive_config(wl, i,
405                                                    ACX_KEEP_ALIVE_TPL_INVALID);
406                 if (ret < 0)
407                         return ret;
408         }
409
410         /* disable the keep-alive feature */
411         ret = wl1271_acx_keep_alive_mode(wl, false);
412         if (ret < 0)
413                 return ret;
414
415         return 0;
416 }
417
418 static int wl1271_ap_hw_init(struct wl1271 *wl)
419 {
420         int ret, i;
421
422         ret = wl1271_ap_init_templates_config(wl);
423         if (ret < 0)
424                 return ret;
425
426         /* Configure for power always on */
427         ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
428         if (ret < 0)
429                 return ret;
430
431         /* Configure initial TX rate classes */
432         for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
433                 ret = wl1271_acx_ap_rate_policy(wl,
434                                 &wl->conf.tx.ap_rc_conf[i], i);
435                 if (ret < 0)
436                         return ret;
437         }
438
439         ret = wl1271_acx_ap_rate_policy(wl,
440                                         &wl->conf.tx.ap_mgmt_conf,
441                                         ACX_TX_AP_MODE_MGMT_RATE);
442         if (ret < 0)
443                 return ret;
444
445         ret = wl1271_acx_ap_rate_policy(wl,
446                                         &wl->conf.tx.ap_bcst_conf,
447                                         ACX_TX_AP_MODE_BCST_RATE);
448         if (ret < 0)
449                 return ret;
450
451         ret = wl1271_acx_ap_max_tx_retry(wl);
452         if (ret < 0)
453                 return ret;
454
455         ret = wl1271_acx_ap_mem_cfg(wl);
456         if (ret < 0)
457                 return ret;
458
459         return 0;
460 }
461
462 static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl)
463 {
464         int ret;
465
466         ret = wl1271_ap_init_deauth_template(wl);
467         if (ret < 0)
468                 return ret;
469
470         ret = wl1271_ap_init_null_template(wl);
471         if (ret < 0)
472                 return ret;
473
474         ret = wl1271_ap_init_qos_null_template(wl);
475         if (ret < 0)
476                 return ret;
477
478         /*
479          * when operating as AP we want to receive external beacons for
480          * configuring ERP protection.
481          */
482         ret = wl1271_acx_set_ap_beacon_filter(wl, false);
483         if (ret < 0)
484                 return ret;
485
486         return 0;
487 }
488
489 static void wl1271_check_ba_support(struct wl1271 *wl)
490 {
491         /* validate FW cose ver x.x.x.50-60.x */
492         if ((wl->chip.fw_ver[3] >= WL12XX_BA_SUPPORT_FW_COST_VER2_START) &&
493             (wl->chip.fw_ver[3] < WL12XX_BA_SUPPORT_FW_COST_VER2_END)) {
494                 wl->ba_support = true;
495                 return;
496         }
497
498         wl->ba_support = false;
499 }
500
501 static int wl1271_set_ba_policies(struct wl1271 *wl)
502 {
503         u8 tid_index;
504         int ret = 0;
505
506         /* Reset the BA RX indicators */
507         wl->ba_rx_bitmap = 0;
508
509         /* validate that FW support BA */
510         wl1271_check_ba_support(wl);
511
512         if (wl->ba_support)
513                 /* 802.11n initiator BA session setting */
514                 for (tid_index = 0; tid_index < CONF_TX_MAX_TID_COUNT;
515                      ++tid_index) {
516                         ret = wl1271_acx_set_ba_session(wl, WLAN_BACK_INITIATOR,
517                                                         tid_index, true);
518                         if (ret < 0)
519                                 break;
520                 }
521
522         return ret;
523 }
524
525 int wl1271_chip_specific_init(struct wl1271 *wl)
526 {
527         int ret = 0;
528
529         if (wl->chip.id == CHIP_ID_1283_PG20) {
530                 u32 host_cfg_bitmap = HOST_IF_CFG_RX_FIFO_ENABLE;
531
532                 if (wl->quirks & WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT)
533                         /* Enable SDIO padding */
534                         host_cfg_bitmap |= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK;
535
536                 /* Must be before wl1271_acx_init_mem_config() */
537                 ret = wl1271_acx_host_if_cfg_bitmap(wl, host_cfg_bitmap);
538                 if (ret < 0)
539                         goto out;
540         }
541 out:
542         return ret;
543 }
544
545
546 int wl1271_hw_init(struct wl1271 *wl)
547 {
548         struct conf_tx_ac_category *conf_ac;
549         struct conf_tx_tid *conf_tid;
550         int ret, i;
551         bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
552
553         if (wl->chip.id == CHIP_ID_1283_PG20)
554                 ret = wl128x_cmd_general_parms(wl);
555         else
556                 ret = wl1271_cmd_general_parms(wl);
557         if (ret < 0)
558                 return ret;
559
560         if (wl->chip.id == CHIP_ID_1283_PG20)
561                 ret = wl128x_cmd_radio_parms(wl);
562         else
563                 ret = wl1271_cmd_radio_parms(wl);
564         if (ret < 0)
565                 return ret;
566
567         /* Chip-specific init */
568         ret = wl1271_chip_specific_init(wl);
569         if (ret < 0)
570                 return ret;
571
572         /* Mode specific init */
573         if (is_ap)
574                 ret = wl1271_ap_hw_init(wl);
575         else
576                 ret = wl1271_sta_hw_init(wl);
577
578         if (ret < 0)
579                 return ret;
580
581         /* Bluetooth WLAN coexistence */
582         ret = wl1271_init_pta(wl);
583         if (ret < 0)
584                 return ret;
585
586         /* Default memory configuration */
587         ret = wl1271_acx_init_mem_config(wl);
588         if (ret < 0)
589                 return ret;
590
591         /* RX config */
592         ret = wl1271_init_rx_config(wl,
593                                     RX_CFG_PROMISCUOUS | RX_CFG_TSF,
594                                     RX_FILTER_OPTION_DEF);
595         /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
596            RX_FILTER_OPTION_FILTER_ALL); */
597         if (ret < 0)
598                 goto out_free_memmap;
599
600         /* PHY layer config */
601         ret = wl1271_init_phy_config(wl);
602         if (ret < 0)
603                 goto out_free_memmap;
604
605         ret = wl1271_acx_dco_itrim_params(wl);
606         if (ret < 0)
607                 goto out_free_memmap;
608
609         /* Configure TX patch complete interrupt behavior */
610         ret = wl1271_acx_tx_config_options(wl);
611         if (ret < 0)
612                 goto out_free_memmap;
613
614         /* RX complete interrupt pacing */
615         ret = wl1271_acx_init_rx_interrupt(wl);
616         if (ret < 0)
617                 goto out_free_memmap;
618
619         /* Energy detection */
620         ret = wl1271_init_energy_detection(wl);
621         if (ret < 0)
622                 goto out_free_memmap;
623
624         /* Default fragmentation threshold */
625         ret = wl1271_acx_frag_threshold(wl, wl->hw->wiphy->frag_threshold);
626         if (ret < 0)
627                 goto out_free_memmap;
628
629         /* Default TID/AC configuration */
630         BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
631         for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
632                 conf_ac = &wl->conf.tx.ac_conf[i];
633                 ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
634                                         conf_ac->cw_max, conf_ac->aifsn,
635                                         conf_ac->tx_op_limit);
636                 if (ret < 0)
637                         goto out_free_memmap;
638
639                 conf_tid = &wl->conf.tx.tid_conf[i];
640                 ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id,
641                                          conf_tid->channel_type,
642                                          conf_tid->tsid,
643                                          conf_tid->ps_scheme,
644                                          conf_tid->ack_policy,
645                                          conf_tid->apsd_conf[0],
646                                          conf_tid->apsd_conf[1]);
647                 if (ret < 0)
648                         goto out_free_memmap;
649         }
650
651         /* Enable data path */
652         ret = wl1271_cmd_data_path(wl, 1);
653         if (ret < 0)
654                 goto out_free_memmap;
655
656         /* Configure HW encryption */
657         ret = wl1271_acx_feature_cfg(wl);
658         if (ret < 0)
659                 goto out_free_memmap;
660
661         /* configure PM */
662         ret = wl1271_acx_pm_config(wl);
663         if (ret < 0)
664                 goto out_free_memmap;
665
666         /* Mode specific init - post mem init */
667         if (is_ap)
668                 ret = wl1271_ap_hw_init_post_mem(wl);
669         else
670                 ret = wl1271_sta_hw_init_post_mem(wl);
671
672         if (ret < 0)
673                 goto out_free_memmap;
674
675         /* Configure initiator BA sessions policies */
676         ret = wl1271_set_ba_policies(wl);
677         if (ret < 0)
678                 goto out_free_memmap;
679
680         return 0;
681
682  out_free_memmap:
683         kfree(wl->target_mem_map);
684         wl->target_mem_map = NULL;
685
686         return ret;
687 }