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
24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/slab.h>
29 #include "wl12xx_80211.h"
36 int wl1271_sta_init_templates_config(struct wl1271
*wl
)
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
);
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
);
53 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_NULL_DATA
, NULL
,
54 sizeof(struct wl12xx_null_data_template
),
55 0, WL1271_RATE_AUTOMATIC
);
59 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_PS_POLL
, NULL
,
60 sizeof(struct wl12xx_ps_poll_template
),
61 0, WL1271_RATE_AUTOMATIC
);
65 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_QOS_NULL_DATA
, NULL
,
67 (struct wl12xx_qos_null_data_template
),
68 0, WL1271_RATE_AUTOMATIC
);
72 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_PROBE_RESPONSE
, NULL
,
74 (struct wl12xx_probe_resp_template
),
75 0, WL1271_RATE_AUTOMATIC
);
79 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_BEACON
, NULL
,
81 (struct wl12xx_beacon_template
),
82 0, WL1271_RATE_AUTOMATIC
);
86 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_ARP_RSP
, NULL
,
88 (struct wl12xx_arp_rsp_template
),
89 0, WL1271_RATE_AUTOMATIC
);
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
);
104 static int wl1271_ap_init_deauth_template(struct wl1271
*wl
)
106 struct wl12xx_disconn_template
*tmpl
;
109 tmpl
= kzalloc(sizeof(*tmpl
), GFP_KERNEL
);
115 tmpl
->header
.frame_ctl
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
116 IEEE80211_STYPE_DEAUTH
);
118 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_DEAUTH_AP
,
119 tmpl
, sizeof(*tmpl
), 0,
120 wl1271_tx_min_rate_get(wl
));
127 static int wl1271_ap_init_null_template(struct wl1271
*wl
)
129 struct ieee80211_hdr_3addr
*nullfunc
;
132 nullfunc
= kzalloc(sizeof(*nullfunc
), GFP_KERNEL
);
138 nullfunc
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
139 IEEE80211_STYPE_NULLFUNC
|
140 IEEE80211_FCTL_FROMDS
);
142 /* nullfunc->addr1 is filled by FW */
144 memcpy(nullfunc
->addr2
, wl
->mac_addr
, ETH_ALEN
);
145 memcpy(nullfunc
->addr3
, wl
->mac_addr
, ETH_ALEN
);
147 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_NULL_DATA
, nullfunc
,
148 sizeof(*nullfunc
), 0,
149 wl1271_tx_min_rate_get(wl
));
156 static int wl1271_ap_init_qos_null_template(struct wl1271
*wl
)
158 struct ieee80211_qos_hdr
*qosnull
;
161 qosnull
= kzalloc(sizeof(*qosnull
), GFP_KERNEL
);
167 qosnull
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
168 IEEE80211_STYPE_QOS_NULLFUNC
|
169 IEEE80211_FCTL_FROMDS
);
171 /* qosnull->addr1 is filled by FW */
173 memcpy(qosnull
->addr2
, wl
->mac_addr
, ETH_ALEN
);
174 memcpy(qosnull
->addr3
, wl
->mac_addr
, ETH_ALEN
);
176 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_QOS_NULL_DATA
, qosnull
,
178 wl1271_tx_min_rate_get(wl
));
185 static int wl1271_ap_init_templates_config(struct wl1271
*wl
)
190 * Put very large empty placeholders for all templates. These
191 * reserve memory for later.
193 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_AP_PROBE_RESPONSE
, NULL
,
195 (struct wl12xx_probe_resp_template
),
196 0, WL1271_RATE_AUTOMATIC
);
200 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_AP_BEACON
, NULL
,
202 (struct wl12xx_beacon_template
),
203 0, WL1271_RATE_AUTOMATIC
);
207 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_DEAUTH_AP
, NULL
,
209 (struct wl12xx_disconn_template
),
210 0, WL1271_RATE_AUTOMATIC
);
214 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_NULL_DATA
, NULL
,
215 sizeof(struct wl12xx_null_data_template
),
216 0, WL1271_RATE_AUTOMATIC
);
220 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_QOS_NULL_DATA
, NULL
,
222 (struct wl12xx_qos_null_data_template
),
223 0, WL1271_RATE_AUTOMATIC
);
230 static int wl1271_init_rx_config(struct wl1271
*wl
, u32 config
, u32 filter
)
234 ret
= wl1271_acx_rx_msdu_life_time(wl
);
238 ret
= wl1271_acx_rx_config(wl
, config
, filter
);
245 int wl1271_init_phy_config(struct wl1271
*wl
)
249 ret
= wl1271_acx_pd_threshold(wl
);
253 ret
= wl1271_acx_slot(wl
, DEFAULT_SLOT_TIME
);
257 ret
= wl1271_acx_service_period_timeout(wl
);
261 ret
= wl1271_acx_rts_threshold(wl
, wl
->hw
->wiphy
->rts_threshold
);
268 static int wl1271_init_beacon_filter(struct wl1271
*wl
)
272 /* disable beacon filtering at this stage */
273 ret
= wl1271_acx_beacon_filter_opt(wl
, false);
277 ret
= wl1271_acx_beacon_filter_table(wl
);
284 int wl1271_init_pta(struct wl1271
*wl
)
288 if (wl
->bss_type
== BSS_TYPE_AP_BSS
)
289 ret
= wl1271_acx_ap_sg_cfg(wl
);
291 ret
= wl1271_acx_sta_sg_cfg(wl
);
295 ret
= wl1271_acx_sg_enable(wl
, wl
->sg_enabled
);
302 int wl1271_init_energy_detection(struct wl1271
*wl
)
306 ret
= wl1271_acx_cca_threshold(wl
);
313 static int wl1271_init_beacon_broadcast(struct wl1271
*wl
)
317 ret
= wl1271_acx_bcn_dtim_options(wl
);
324 static int wl12xx_init_fwlog(struct wl1271
*wl
)
328 if (wl
->quirks
& WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED
)
331 ret
= wl12xx_cmd_config_fwlog(wl
);
338 static int wl1271_sta_hw_init(struct wl1271
*wl
)
342 if (wl
->chip
.id
!= CHIP_ID_1283_PG20
) {
343 ret
= wl1271_cmd_ext_radio_parms(wl
);
349 ret
= wl1271_acx_config_ps(wl
);
353 ret
= wl1271_sta_init_templates_config(wl
);
357 ret
= wl1271_acx_group_address_tbl(wl
, true, NULL
, 0);
361 /* Initialize connection monitoring thresholds */
362 ret
= wl1271_acx_conn_monit_params(wl
, false);
366 /* Beacon filtering */
367 ret
= wl1271_init_beacon_filter(wl
);
371 /* FM WLAN coexistence */
372 ret
= wl1271_acx_fm_coex(wl
);
376 /* Beacons and broadcast settings */
377 ret
= wl1271_init_beacon_broadcast(wl
);
381 /* Configure for ELP power saving */
382 ret
= wl1271_acx_sleep_auth(wl
, WL1271_PSM_ELP
);
386 /* Configure rssi/snr averaging weights */
387 ret
= wl1271_acx_rssi_snr_avg_weights(wl
);
391 ret
= wl1271_acx_sta_rate_policies(wl
);
395 ret
= wl1271_acx_sta_mem_cfg(wl
);
399 /* Configure the FW logger */
400 ret
= wl12xx_init_fwlog(wl
);
407 static int wl1271_sta_hw_init_post_mem(struct wl1271
*wl
)
411 ret
= wl1271_cmd_set_sta_default_wep_key(wl
, wl
->default_key
);
413 wl1271_warning("couldn't set default key");
417 /* disable all keep-alive templates */
418 for (i
= 0; i
< CMD_TEMPL_KLV_IDX_MAX
; i
++) {
419 ret
= wl1271_acx_keep_alive_config(wl
, i
,
420 ACX_KEEP_ALIVE_TPL_INVALID
);
425 /* disable the keep-alive feature */
426 ret
= wl1271_acx_keep_alive_mode(wl
, false);
433 static int wl1271_ap_hw_init(struct wl1271
*wl
)
437 ret
= wl1271_ap_init_templates_config(wl
);
441 /* Configure for power always on */
442 ret
= wl1271_acx_sleep_auth(wl
, WL1271_PSM_CAM
);
446 ret
= wl1271_init_ap_rates(wl
);
450 ret
= wl1271_acx_ap_max_tx_retry(wl
);
454 ret
= wl1271_acx_ap_mem_cfg(wl
);
458 /* initialize Tx power */
459 ret
= wl1271_acx_tx_power(wl
, wl
->power_level
);
466 int wl1271_ap_init_templates(struct wl1271
*wl
)
470 ret
= wl1271_ap_init_deauth_template(wl
);
474 ret
= wl1271_ap_init_null_template(wl
);
478 ret
= wl1271_ap_init_qos_null_template(wl
);
483 * when operating as AP we want to receive external beacons for
484 * configuring ERP protection.
486 ret
= wl1271_acx_set_ap_beacon_filter(wl
, false);
493 static int wl1271_ap_hw_init_post_mem(struct wl1271
*wl
)
495 return wl1271_ap_init_templates(wl
);
498 int wl1271_init_ap_rates(struct wl1271
*wl
)
501 struct conf_tx_rate_class rc
;
504 wl1271_debug(DEBUG_AP
, "AP basic rate set: 0x%x", wl
->basic_rate_set
);
506 if (wl
->basic_rate_set
== 0)
509 rc
.enabled_rates
= wl
->basic_rate_set
;
510 rc
.long_retry_limit
= 10;
511 rc
.short_retry_limit
= 10;
513 ret
= wl1271_acx_ap_rate_policy(wl
, &rc
, ACX_TX_AP_MODE_MGMT_RATE
);
517 /* use the min basic rate for AP broadcast/multicast */
518 rc
.enabled_rates
= wl1271_tx_min_rate_get(wl
);
519 rc
.short_retry_limit
= 10;
520 rc
.long_retry_limit
= 10;
522 ret
= wl1271_acx_ap_rate_policy(wl
, &rc
, ACX_TX_AP_MODE_BCST_RATE
);
527 * If the basic rates contain OFDM rates, use OFDM only
528 * rates for unicast TX as well. Else use all supported rates.
530 if ((wl
->basic_rate_set
& CONF_TX_OFDM_RATES
))
531 supported_rates
= CONF_TX_OFDM_RATES
;
533 supported_rates
= CONF_TX_AP_ENABLED_RATES
;
535 /* configure unicast TX rate classes */
536 for (i
= 0; i
< wl
->conf
.tx
.ac_conf_count
; i
++) {
537 rc
.enabled_rates
= supported_rates
;
538 rc
.short_retry_limit
= 10;
539 rc
.long_retry_limit
= 10;
541 ret
= wl1271_acx_ap_rate_policy(wl
, &rc
, i
);
549 static void wl1271_check_ba_support(struct wl1271
*wl
)
551 /* validate FW cose ver x.x.x.50-60.x */
552 if ((wl
->chip
.fw_ver
[3] >= WL12XX_BA_SUPPORT_FW_COST_VER2_START
) &&
553 (wl
->chip
.fw_ver
[3] < WL12XX_BA_SUPPORT_FW_COST_VER2_END
)) {
554 wl
->ba_support
= true;
558 wl
->ba_support
= false;
561 static int wl1271_set_ba_policies(struct wl1271
*wl
)
566 /* Reset the BA RX indicators */
567 wl
->ba_rx_bitmap
= 0;
568 wl
->ba_allowed
= true;
570 /* validate that FW support BA */
571 wl1271_check_ba_support(wl
);
574 /* 802.11n initiator BA session setting */
575 for (tid_index
= 0; tid_index
< CONF_TX_MAX_TID_COUNT
;
577 ret
= wl1271_acx_set_ba_session(wl
, WLAN_BACK_INITIATOR
,
586 int wl1271_chip_specific_init(struct wl1271
*wl
)
590 if (wl
->chip
.id
== CHIP_ID_1283_PG20
) {
591 u32 host_cfg_bitmap
= HOST_IF_CFG_RX_FIFO_ENABLE
;
593 if (wl
->quirks
& WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT
)
594 /* Enable SDIO padding */
595 host_cfg_bitmap
|= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK
;
597 /* Must be before wl1271_acx_init_mem_config() */
598 ret
= wl1271_acx_host_if_cfg_bitmap(wl
, host_cfg_bitmap
);
607 int wl1271_hw_init(struct wl1271
*wl
)
609 struct conf_tx_ac_category
*conf_ac
;
610 struct conf_tx_tid
*conf_tid
;
612 bool is_ap
= (wl
->bss_type
== BSS_TYPE_AP_BSS
);
614 if (wl
->chip
.id
== CHIP_ID_1283_PG20
)
615 ret
= wl128x_cmd_general_parms(wl
);
617 ret
= wl1271_cmd_general_parms(wl
);
621 if (wl
->chip
.id
== CHIP_ID_1283_PG20
)
622 ret
= wl128x_cmd_radio_parms(wl
);
624 ret
= wl1271_cmd_radio_parms(wl
);
628 /* Chip-specific init */
629 ret
= wl1271_chip_specific_init(wl
);
633 /* Mode specific init */
635 ret
= wl1271_ap_hw_init(wl
);
637 ret
= wl1271_sta_hw_init(wl
);
642 /* Bluetooth WLAN coexistence */
643 ret
= wl1271_init_pta(wl
);
647 /* Default memory configuration */
648 ret
= wl1271_acx_init_mem_config(wl
);
653 ret
= wl1271_init_rx_config(wl
,
654 RX_CFG_PROMISCUOUS
| RX_CFG_TSF
,
655 RX_FILTER_OPTION_DEF
);
656 /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
657 RX_FILTER_OPTION_FILTER_ALL); */
659 goto out_free_memmap
;
661 /* PHY layer config */
662 ret
= wl1271_init_phy_config(wl
);
664 goto out_free_memmap
;
666 ret
= wl1271_acx_dco_itrim_params(wl
);
668 goto out_free_memmap
;
670 /* Configure TX patch complete interrupt behavior */
671 ret
= wl1271_acx_tx_config_options(wl
);
673 goto out_free_memmap
;
675 /* RX complete interrupt pacing */
676 ret
= wl1271_acx_init_rx_interrupt(wl
);
678 goto out_free_memmap
;
680 /* Energy detection */
681 ret
= wl1271_init_energy_detection(wl
);
683 goto out_free_memmap
;
685 /* Default fragmentation threshold */
686 ret
= wl1271_acx_frag_threshold(wl
, wl
->hw
->wiphy
->frag_threshold
);
688 goto out_free_memmap
;
690 /* Default TID/AC configuration */
691 BUG_ON(wl
->conf
.tx
.tid_conf_count
!= wl
->conf
.tx
.ac_conf_count
);
692 for (i
= 0; i
< wl
->conf
.tx
.tid_conf_count
; i
++) {
693 conf_ac
= &wl
->conf
.tx
.ac_conf
[i
];
694 ret
= wl1271_acx_ac_cfg(wl
, conf_ac
->ac
, conf_ac
->cw_min
,
695 conf_ac
->cw_max
, conf_ac
->aifsn
,
696 conf_ac
->tx_op_limit
);
698 goto out_free_memmap
;
700 conf_tid
= &wl
->conf
.tx
.tid_conf
[i
];
701 ret
= wl1271_acx_tid_cfg(wl
, conf_tid
->queue_id
,
702 conf_tid
->channel_type
,
705 conf_tid
->ack_policy
,
706 conf_tid
->apsd_conf
[0],
707 conf_tid
->apsd_conf
[1]);
709 goto out_free_memmap
;
712 /* Enable data path */
713 ret
= wl1271_cmd_data_path(wl
, 1);
715 goto out_free_memmap
;
717 /* Configure HW encryption */
718 ret
= wl1271_acx_feature_cfg(wl
);
720 goto out_free_memmap
;
723 ret
= wl1271_acx_pm_config(wl
);
725 goto out_free_memmap
;
727 /* Mode specific init - post mem init */
729 ret
= wl1271_ap_hw_init_post_mem(wl
);
731 ret
= wl1271_sta_hw_init_post_mem(wl
);
734 goto out_free_memmap
;
736 /* Configure initiator BA sessions policies */
737 ret
= wl1271_set_ba_policies(wl
);
739 goto out_free_memmap
;
744 kfree(wl
->target_mem_map
);
745 wl
->target_mem_map
= NULL
;