OMAPDSS: VENC: fix NULL pointer dereference in DSS2 VENC sysfs debug attr on OMAP4
[zen-stable.git] / drivers / net / wireless / wl12xx / init.c
blobca7ee59e4505b297c104197bfde176e34336458b
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 "debug.h"
29 #include "init.h"
30 #include "wl12xx_80211.h"
31 #include "acx.h"
32 #include "cmd.h"
33 #include "reg.h"
34 #include "tx.h"
35 #include "io.h"
37 int wl1271_init_templates_config(struct wl1271 *wl)
39 int ret, i;
41 /* send empty templates for fw memory reservation */
42 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, NULL,
43 WL1271_CMD_TEMPL_DFLT_SIZE,
44 0, WL1271_RATE_AUTOMATIC);
45 if (ret < 0)
46 return ret;
48 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
49 NULL, WL1271_CMD_TEMPL_DFLT_SIZE, 0,
50 WL1271_RATE_AUTOMATIC);
51 if (ret < 0)
52 return ret;
54 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
55 sizeof(struct wl12xx_null_data_template),
56 0, WL1271_RATE_AUTOMATIC);
57 if (ret < 0)
58 return ret;
60 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, NULL,
61 sizeof(struct wl12xx_ps_poll_template),
62 0, WL1271_RATE_AUTOMATIC);
63 if (ret < 0)
64 return ret;
66 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
67 sizeof
68 (struct ieee80211_qos_hdr),
69 0, WL1271_RATE_AUTOMATIC);
70 if (ret < 0)
71 return ret;
73 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE, NULL,
74 WL1271_CMD_TEMPL_DFLT_SIZE,
75 0, WL1271_RATE_AUTOMATIC);
76 if (ret < 0)
77 return ret;
79 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON, NULL,
80 WL1271_CMD_TEMPL_DFLT_SIZE,
81 0, WL1271_RATE_AUTOMATIC);
82 if (ret < 0)
83 return ret;
85 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_ARP_RSP, NULL,
86 sizeof
87 (struct wl12xx_arp_rsp_template),
88 0, WL1271_RATE_AUTOMATIC);
89 if (ret < 0)
90 return ret;
93 * Put very large empty placeholders for all templates. These
94 * reserve memory for later.
96 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_PROBE_RESPONSE, NULL,
97 WL1271_CMD_TEMPL_MAX_SIZE,
98 0, WL1271_RATE_AUTOMATIC);
99 if (ret < 0)
100 return ret;
102 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_BEACON, NULL,
103 WL1271_CMD_TEMPL_MAX_SIZE,
104 0, WL1271_RATE_AUTOMATIC);
105 if (ret < 0)
106 return ret;
108 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP, NULL,
109 sizeof
110 (struct wl12xx_disconn_template),
111 0, WL1271_RATE_AUTOMATIC);
112 if (ret < 0)
113 return ret;
115 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
116 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV, NULL,
117 sizeof(struct ieee80211_qos_hdr),
118 i, WL1271_RATE_AUTOMATIC);
119 if (ret < 0)
120 return ret;
123 return 0;
126 static int wl1271_ap_init_deauth_template(struct wl1271 *wl,
127 struct wl12xx_vif *wlvif)
129 struct wl12xx_disconn_template *tmpl;
130 int ret;
131 u32 rate;
133 tmpl = kzalloc(sizeof(*tmpl), GFP_KERNEL);
134 if (!tmpl) {
135 ret = -ENOMEM;
136 goto out;
139 tmpl->header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT |
140 IEEE80211_STYPE_DEAUTH);
142 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
143 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP,
144 tmpl, sizeof(*tmpl), 0, rate);
146 out:
147 kfree(tmpl);
148 return ret;
151 static int wl1271_ap_init_null_template(struct wl1271 *wl,
152 struct ieee80211_vif *vif)
154 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
155 struct ieee80211_hdr_3addr *nullfunc;
156 int ret;
157 u32 rate;
159 nullfunc = kzalloc(sizeof(*nullfunc), GFP_KERNEL);
160 if (!nullfunc) {
161 ret = -ENOMEM;
162 goto out;
165 nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
166 IEEE80211_STYPE_NULLFUNC |
167 IEEE80211_FCTL_FROMDS);
169 /* nullfunc->addr1 is filled by FW */
171 memcpy(nullfunc->addr2, vif->addr, ETH_ALEN);
172 memcpy(nullfunc->addr3, vif->addr, ETH_ALEN);
174 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
175 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, nullfunc,
176 sizeof(*nullfunc), 0, rate);
178 out:
179 kfree(nullfunc);
180 return ret;
183 static int wl1271_ap_init_qos_null_template(struct wl1271 *wl,
184 struct ieee80211_vif *vif)
186 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
187 struct ieee80211_qos_hdr *qosnull;
188 int ret;
189 u32 rate;
191 qosnull = kzalloc(sizeof(*qosnull), GFP_KERNEL);
192 if (!qosnull) {
193 ret = -ENOMEM;
194 goto out;
197 qosnull->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
198 IEEE80211_STYPE_QOS_NULLFUNC |
199 IEEE80211_FCTL_FROMDS);
201 /* qosnull->addr1 is filled by FW */
203 memcpy(qosnull->addr2, vif->addr, ETH_ALEN);
204 memcpy(qosnull->addr3, vif->addr, ETH_ALEN);
206 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
207 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, qosnull,
208 sizeof(*qosnull), 0, rate);
210 out:
211 kfree(qosnull);
212 return ret;
215 static int wl12xx_init_rx_config(struct wl1271 *wl)
217 int ret;
219 ret = wl1271_acx_rx_msdu_life_time(wl);
220 if (ret < 0)
221 return ret;
223 return 0;
226 static int wl12xx_init_phy_vif_config(struct wl1271 *wl,
227 struct wl12xx_vif *wlvif)
229 int ret;
231 ret = wl1271_acx_slot(wl, wlvif, DEFAULT_SLOT_TIME);
232 if (ret < 0)
233 return ret;
235 ret = wl1271_acx_service_period_timeout(wl, wlvif);
236 if (ret < 0)
237 return ret;
239 ret = wl1271_acx_rts_threshold(wl, wlvif, wl->hw->wiphy->rts_threshold);
240 if (ret < 0)
241 return ret;
243 return 0;
246 static int wl1271_init_sta_beacon_filter(struct wl1271 *wl,
247 struct wl12xx_vif *wlvif)
249 int ret;
251 ret = wl1271_acx_beacon_filter_table(wl, wlvif);
252 if (ret < 0)
253 return ret;
255 /* enable beacon filtering */
256 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true);
257 if (ret < 0)
258 return ret;
260 return 0;
263 int wl1271_init_pta(struct wl1271 *wl)
265 int ret;
267 ret = wl12xx_acx_sg_cfg(wl);
268 if (ret < 0)
269 return ret;
271 ret = wl1271_acx_sg_enable(wl, wl->sg_enabled);
272 if (ret < 0)
273 return ret;
275 return 0;
278 int wl1271_init_energy_detection(struct wl1271 *wl)
280 int ret;
282 ret = wl1271_acx_cca_threshold(wl);
283 if (ret < 0)
284 return ret;
286 return 0;
289 static int wl1271_init_beacon_broadcast(struct wl1271 *wl,
290 struct wl12xx_vif *wlvif)
292 int ret;
294 ret = wl1271_acx_bcn_dtim_options(wl, wlvif);
295 if (ret < 0)
296 return ret;
298 return 0;
301 static int wl12xx_init_fwlog(struct wl1271 *wl)
303 int ret;
305 if (wl->quirks & WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED)
306 return 0;
308 ret = wl12xx_cmd_config_fwlog(wl);
309 if (ret < 0)
310 return ret;
312 return 0;
315 /* generic sta initialization (non vif-specific) */
316 static int wl1271_sta_hw_init(struct wl1271 *wl, struct wl12xx_vif *wlvif)
318 int ret;
320 /* PS config */
321 ret = wl12xx_acx_config_ps(wl, wlvif);
322 if (ret < 0)
323 return ret;
325 /* FM WLAN coexistence */
326 ret = wl1271_acx_fm_coex(wl);
327 if (ret < 0)
328 return ret;
330 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
331 if (ret < 0)
332 return ret;
334 return 0;
337 static int wl1271_sta_hw_init_post_mem(struct wl1271 *wl,
338 struct ieee80211_vif *vif)
340 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
341 int ret, i;
343 /* disable all keep-alive templates */
344 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
345 ret = wl1271_acx_keep_alive_config(wl, wlvif, i,
346 ACX_KEEP_ALIVE_TPL_INVALID);
347 if (ret < 0)
348 return ret;
351 /* disable the keep-alive feature */
352 ret = wl1271_acx_keep_alive_mode(wl, wlvif, false);
353 if (ret < 0)
354 return ret;
356 return 0;
359 /* generic ap initialization (non vif-specific) */
360 static int wl1271_ap_hw_init(struct wl1271 *wl, struct wl12xx_vif *wlvif)
362 int ret;
364 ret = wl1271_init_ap_rates(wl, wlvif);
365 if (ret < 0)
366 return ret;
368 return 0;
371 int wl1271_ap_init_templates(struct wl1271 *wl, struct ieee80211_vif *vif)
373 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
374 int ret;
376 ret = wl1271_ap_init_deauth_template(wl, wlvif);
377 if (ret < 0)
378 return ret;
380 ret = wl1271_ap_init_null_template(wl, vif);
381 if (ret < 0)
382 return ret;
384 ret = wl1271_ap_init_qos_null_template(wl, vif);
385 if (ret < 0)
386 return ret;
389 * when operating as AP we want to receive external beacons for
390 * configuring ERP protection.
392 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false);
393 if (ret < 0)
394 return ret;
396 return 0;
399 static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl,
400 struct ieee80211_vif *vif)
402 return wl1271_ap_init_templates(wl, vif);
405 int wl1271_init_ap_rates(struct wl1271 *wl, struct wl12xx_vif *wlvif)
407 int i, ret;
408 struct conf_tx_rate_class rc;
409 u32 supported_rates;
411 wl1271_debug(DEBUG_AP, "AP basic rate set: 0x%x",
412 wlvif->basic_rate_set);
414 if (wlvif->basic_rate_set == 0)
415 return -EINVAL;
417 rc.enabled_rates = wlvif->basic_rate_set;
418 rc.long_retry_limit = 10;
419 rc.short_retry_limit = 10;
420 rc.aflags = 0;
421 ret = wl1271_acx_ap_rate_policy(wl, &rc, wlvif->ap.mgmt_rate_idx);
422 if (ret < 0)
423 return ret;
425 /* use the min basic rate for AP broadcast/multicast */
426 rc.enabled_rates = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
427 rc.short_retry_limit = 10;
428 rc.long_retry_limit = 10;
429 rc.aflags = 0;
430 ret = wl1271_acx_ap_rate_policy(wl, &rc, wlvif->ap.bcast_rate_idx);
431 if (ret < 0)
432 return ret;
435 * If the basic rates contain OFDM rates, use OFDM only
436 * rates for unicast TX as well. Else use all supported rates.
438 if ((wlvif->basic_rate_set & CONF_TX_OFDM_RATES))
439 supported_rates = CONF_TX_OFDM_RATES;
440 else
441 supported_rates = CONF_TX_AP_ENABLED_RATES;
443 /* unconditionally enable HT rates */
444 supported_rates |= CONF_TX_MCS_RATES;
446 /* configure unicast TX rate classes */
447 for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
448 rc.enabled_rates = supported_rates;
449 rc.short_retry_limit = 10;
450 rc.long_retry_limit = 10;
451 rc.aflags = 0;
452 ret = wl1271_acx_ap_rate_policy(wl, &rc,
453 wlvif->ap.ucast_rate_idx[i]);
454 if (ret < 0)
455 return ret;
458 return 0;
461 static int wl1271_set_ba_policies(struct wl1271 *wl, struct wl12xx_vif *wlvif)
463 /* Reset the BA RX indicators */
464 wlvif->ba_allowed = true;
465 wl->ba_rx_session_count = 0;
467 /* BA is supported in STA/AP modes */
468 if (wlvif->bss_type != BSS_TYPE_AP_BSS &&
469 wlvif->bss_type != BSS_TYPE_STA_BSS) {
470 wlvif->ba_support = false;
471 return 0;
474 wlvif->ba_support = true;
476 /* 802.11n initiator BA session setting */
477 return wl12xx_acx_set_ba_initiator_policy(wl, wlvif);
480 int wl1271_chip_specific_init(struct wl1271 *wl)
482 int ret = 0;
484 if (wl->chip.id == CHIP_ID_1283_PG20) {
485 u32 host_cfg_bitmap = HOST_IF_CFG_RX_FIFO_ENABLE;
487 if (!(wl->quirks & WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT))
488 /* Enable SDIO padding */
489 host_cfg_bitmap |= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK;
491 /* Must be before wl1271_acx_init_mem_config() */
492 ret = wl1271_acx_host_if_cfg_bitmap(wl, host_cfg_bitmap);
493 if (ret < 0)
494 goto out;
496 out:
497 return ret;
500 /* vif-specifc initialization */
501 static int wl12xx_init_sta_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
503 int ret;
505 ret = wl1271_acx_group_address_tbl(wl, wlvif, true, NULL, 0);
506 if (ret < 0)
507 return ret;
509 /* Initialize connection monitoring thresholds */
510 ret = wl1271_acx_conn_monit_params(wl, wlvif, false);
511 if (ret < 0)
512 return ret;
514 /* Beacon filtering */
515 ret = wl1271_init_sta_beacon_filter(wl, wlvif);
516 if (ret < 0)
517 return ret;
519 /* Beacons and broadcast settings */
520 ret = wl1271_init_beacon_broadcast(wl, wlvif);
521 if (ret < 0)
522 return ret;
524 /* Configure rssi/snr averaging weights */
525 ret = wl1271_acx_rssi_snr_avg_weights(wl, wlvif);
526 if (ret < 0)
527 return ret;
529 return 0;
532 /* vif-specific intialization */
533 static int wl12xx_init_ap_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
535 int ret;
537 ret = wl1271_acx_ap_max_tx_retry(wl, wlvif);
538 if (ret < 0)
539 return ret;
541 /* initialize Tx power */
542 ret = wl1271_acx_tx_power(wl, wlvif, wlvif->power_level);
543 if (ret < 0)
544 return ret;
546 return 0;
549 int wl1271_init_vif_specific(struct wl1271 *wl, struct ieee80211_vif *vif)
551 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
552 struct conf_tx_ac_category *conf_ac;
553 struct conf_tx_tid *conf_tid;
554 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
555 int ret, i;
558 * consider all existing roles before configuring psm.
559 * TODO: reconfigure on interface removal.
561 if (!wl->ap_count) {
562 if (is_ap) {
563 /* Configure for power always on */
564 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
565 if (ret < 0)
566 return ret;
567 } else if (!wl->sta_count) {
568 /* Configure for ELP power saving */
569 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
570 if (ret < 0)
571 return ret;
575 /* Mode specific init */
576 if (is_ap) {
577 ret = wl1271_ap_hw_init(wl, wlvif);
578 if (ret < 0)
579 return ret;
581 ret = wl12xx_init_ap_role(wl, wlvif);
582 if (ret < 0)
583 return ret;
584 } else {
585 ret = wl1271_sta_hw_init(wl, wlvif);
586 if (ret < 0)
587 return ret;
589 ret = wl12xx_init_sta_role(wl, wlvif);
590 if (ret < 0)
591 return ret;
594 wl12xx_init_phy_vif_config(wl, wlvif);
596 /* Default TID/AC configuration */
597 BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
598 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
599 conf_ac = &wl->conf.tx.ac_conf[i];
600 ret = wl1271_acx_ac_cfg(wl, wlvif, conf_ac->ac,
601 conf_ac->cw_min, conf_ac->cw_max,
602 conf_ac->aifsn, conf_ac->tx_op_limit);
603 if (ret < 0)
604 return ret;
606 conf_tid = &wl->conf.tx.tid_conf[i];
607 ret = wl1271_acx_tid_cfg(wl, wlvif,
608 conf_tid->queue_id,
609 conf_tid->channel_type,
610 conf_tid->tsid,
611 conf_tid->ps_scheme,
612 conf_tid->ack_policy,
613 conf_tid->apsd_conf[0],
614 conf_tid->apsd_conf[1]);
615 if (ret < 0)
616 return ret;
619 /* Configure HW encryption */
620 ret = wl1271_acx_feature_cfg(wl, wlvif);
621 if (ret < 0)
622 return ret;
624 /* Mode specific init - post mem init */
625 if (is_ap)
626 ret = wl1271_ap_hw_init_post_mem(wl, vif);
627 else
628 ret = wl1271_sta_hw_init_post_mem(wl, vif);
630 if (ret < 0)
631 return ret;
633 /* Configure initiator BA sessions policies */
634 ret = wl1271_set_ba_policies(wl, wlvif);
635 if (ret < 0)
636 return ret;
638 return 0;
641 int wl1271_hw_init(struct wl1271 *wl)
643 int ret;
645 if (wl->chip.id == CHIP_ID_1283_PG20) {
646 ret = wl128x_cmd_general_parms(wl);
647 if (ret < 0)
648 return ret;
649 ret = wl128x_cmd_radio_parms(wl);
650 if (ret < 0)
651 return ret;
652 } else {
653 ret = wl1271_cmd_general_parms(wl);
654 if (ret < 0)
655 return ret;
656 ret = wl1271_cmd_radio_parms(wl);
657 if (ret < 0)
658 return ret;
659 ret = wl1271_cmd_ext_radio_parms(wl);
660 if (ret < 0)
661 return ret;
664 /* Chip-specific init */
665 ret = wl1271_chip_specific_init(wl);
666 if (ret < 0)
667 return ret;
669 /* Init templates */
670 ret = wl1271_init_templates_config(wl);
671 if (ret < 0)
672 return ret;
674 ret = wl12xx_acx_mem_cfg(wl);
675 if (ret < 0)
676 return ret;
678 /* Configure the FW logger */
679 ret = wl12xx_init_fwlog(wl);
680 if (ret < 0)
681 return ret;
683 /* Bluetooth WLAN coexistence */
684 ret = wl1271_init_pta(wl);
685 if (ret < 0)
686 return ret;
688 /* Default memory configuration */
689 ret = wl1271_acx_init_mem_config(wl);
690 if (ret < 0)
691 return ret;
693 /* RX config */
694 ret = wl12xx_init_rx_config(wl);
695 if (ret < 0)
696 goto out_free_memmap;
698 ret = wl1271_acx_dco_itrim_params(wl);
699 if (ret < 0)
700 goto out_free_memmap;
702 /* Configure TX patch complete interrupt behavior */
703 ret = wl1271_acx_tx_config_options(wl);
704 if (ret < 0)
705 goto out_free_memmap;
707 /* RX complete interrupt pacing */
708 ret = wl1271_acx_init_rx_interrupt(wl);
709 if (ret < 0)
710 goto out_free_memmap;
712 /* Energy detection */
713 ret = wl1271_init_energy_detection(wl);
714 if (ret < 0)
715 goto out_free_memmap;
717 /* Default fragmentation threshold */
718 ret = wl1271_acx_frag_threshold(wl, wl->hw->wiphy->frag_threshold);
719 if (ret < 0)
720 goto out_free_memmap;
722 /* Enable data path */
723 ret = wl1271_cmd_data_path(wl, 1);
724 if (ret < 0)
725 goto out_free_memmap;
727 /* configure PM */
728 ret = wl1271_acx_pm_config(wl);
729 if (ret < 0)
730 goto out_free_memmap;
732 ret = wl12xx_acx_set_rate_mgmt_params(wl);
733 if (ret < 0)
734 goto out_free_memmap;
736 /* configure hangover */
737 ret = wl12xx_acx_config_hangover(wl);
738 if (ret < 0)
739 goto out_free_memmap;
741 return 0;
743 out_free_memmap:
744 kfree(wl->target_mem_map);
745 wl->target_mem_map = NULL;
747 return ret;