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>
30 #include "wl12xx_80211.h"
37 int wl1271_init_templates_config(struct wl1271
*wl
)
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
);
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
);
54 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_NULL_DATA
, NULL
,
55 sizeof(struct wl12xx_null_data_template
),
56 0, WL1271_RATE_AUTOMATIC
);
60 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_PS_POLL
, NULL
,
61 sizeof(struct wl12xx_ps_poll_template
),
62 0, WL1271_RATE_AUTOMATIC
);
66 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_QOS_NULL_DATA
, NULL
,
68 (struct ieee80211_qos_hdr
),
69 0, WL1271_RATE_AUTOMATIC
);
73 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_PROBE_RESPONSE
, NULL
,
74 WL1271_CMD_TEMPL_DFLT_SIZE
,
75 0, WL1271_RATE_AUTOMATIC
);
79 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_BEACON
, NULL
,
80 WL1271_CMD_TEMPL_DFLT_SIZE
,
81 0, WL1271_RATE_AUTOMATIC
);
85 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_ARP_RSP
, NULL
,
87 (struct wl12xx_arp_rsp_template
),
88 0, WL1271_RATE_AUTOMATIC
);
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
);
102 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_AP_BEACON
, NULL
,
103 WL1271_CMD_TEMPL_MAX_SIZE
,
104 0, WL1271_RATE_AUTOMATIC
);
108 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_DEAUTH_AP
, NULL
,
110 (struct wl12xx_disconn_template
),
111 0, WL1271_RATE_AUTOMATIC
);
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
);
126 static int wl1271_ap_init_deauth_template(struct wl1271
*wl
,
127 struct wl12xx_vif
*wlvif
)
129 struct wl12xx_disconn_template
*tmpl
;
133 tmpl
= kzalloc(sizeof(*tmpl
), GFP_KERNEL
);
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
);
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
;
159 nullfunc
= kzalloc(sizeof(*nullfunc
), GFP_KERNEL
);
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
);
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
;
191 qosnull
= kzalloc(sizeof(*qosnull
), GFP_KERNEL
);
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
);
215 static int wl12xx_init_rx_config(struct wl1271
*wl
)
219 ret
= wl1271_acx_rx_msdu_life_time(wl
);
226 static int wl12xx_init_phy_vif_config(struct wl1271
*wl
,
227 struct wl12xx_vif
*wlvif
)
231 ret
= wl1271_acx_slot(wl
, wlvif
, DEFAULT_SLOT_TIME
);
235 ret
= wl1271_acx_service_period_timeout(wl
, wlvif
);
239 ret
= wl1271_acx_rts_threshold(wl
, wlvif
, wl
->hw
->wiphy
->rts_threshold
);
246 static int wl1271_init_sta_beacon_filter(struct wl1271
*wl
,
247 struct wl12xx_vif
*wlvif
)
251 ret
= wl1271_acx_beacon_filter_table(wl
, wlvif
);
255 /* enable beacon filtering */
256 ret
= wl1271_acx_beacon_filter_opt(wl
, wlvif
, true);
263 int wl1271_init_pta(struct wl1271
*wl
)
267 ret
= wl12xx_acx_sg_cfg(wl
);
271 ret
= wl1271_acx_sg_enable(wl
, wl
->sg_enabled
);
278 int wl1271_init_energy_detection(struct wl1271
*wl
)
282 ret
= wl1271_acx_cca_threshold(wl
);
289 static int wl1271_init_beacon_broadcast(struct wl1271
*wl
,
290 struct wl12xx_vif
*wlvif
)
294 ret
= wl1271_acx_bcn_dtim_options(wl
, wlvif
);
301 static int wl12xx_init_fwlog(struct wl1271
*wl
)
305 if (wl
->quirks
& WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED
)
308 ret
= wl12xx_cmd_config_fwlog(wl
);
315 /* generic sta initialization (non vif-specific) */
316 static int wl1271_sta_hw_init(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
321 ret
= wl12xx_acx_config_ps(wl
, wlvif
);
325 /* FM WLAN coexistence */
326 ret
= wl1271_acx_fm_coex(wl
);
330 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
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
);
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
);
351 /* disable the keep-alive feature */
352 ret
= wl1271_acx_keep_alive_mode(wl
, wlvif
, false);
359 /* generic ap initialization (non vif-specific) */
360 static int wl1271_ap_hw_init(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
364 ret
= wl1271_init_ap_rates(wl
, wlvif
);
371 int wl1271_ap_init_templates(struct wl1271
*wl
, struct ieee80211_vif
*vif
)
373 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
376 ret
= wl1271_ap_init_deauth_template(wl
, wlvif
);
380 ret
= wl1271_ap_init_null_template(wl
, vif
);
384 ret
= wl1271_ap_init_qos_null_template(wl
, vif
);
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);
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
)
408 struct conf_tx_rate_class rc
;
411 wl1271_debug(DEBUG_AP
, "AP basic rate set: 0x%x",
412 wlvif
->basic_rate_set
);
414 if (wlvif
->basic_rate_set
== 0)
417 rc
.enabled_rates
= wlvif
->basic_rate_set
;
418 rc
.long_retry_limit
= 10;
419 rc
.short_retry_limit
= 10;
421 ret
= wl1271_acx_ap_rate_policy(wl
, &rc
, wlvif
->ap
.mgmt_rate_idx
);
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;
430 ret
= wl1271_acx_ap_rate_policy(wl
, &rc
, wlvif
->ap
.bcast_rate_idx
);
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
;
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;
452 ret
= wl1271_acx_ap_rate_policy(wl
, &rc
,
453 wlvif
->ap
.ucast_rate_idx
[i
]);
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;
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
)
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
);
500 /* vif-specifc initialization */
501 static int wl12xx_init_sta_role(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
505 ret
= wl1271_acx_group_address_tbl(wl
, wlvif
, true, NULL
, 0);
509 /* Initialize connection monitoring thresholds */
510 ret
= wl1271_acx_conn_monit_params(wl
, wlvif
, false);
514 /* Beacon filtering */
515 ret
= wl1271_init_sta_beacon_filter(wl
, wlvif
);
519 /* Beacons and broadcast settings */
520 ret
= wl1271_init_beacon_broadcast(wl
, wlvif
);
524 /* Configure rssi/snr averaging weights */
525 ret
= wl1271_acx_rssi_snr_avg_weights(wl
, wlvif
);
532 /* vif-specific intialization */
533 static int wl12xx_init_ap_role(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
537 ret
= wl1271_acx_ap_max_tx_retry(wl
, wlvif
);
541 /* initialize Tx power */
542 ret
= wl1271_acx_tx_power(wl
, wlvif
, wlvif
->power_level
);
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
);
558 * consider all existing roles before configuring psm.
559 * TODO: reconfigure on interface removal.
563 /* Configure for power always on */
564 ret
= wl1271_acx_sleep_auth(wl
, WL1271_PSM_CAM
);
567 } else if (!wl
->sta_count
) {
568 /* Configure for ELP power saving */
569 ret
= wl1271_acx_sleep_auth(wl
, WL1271_PSM_ELP
);
575 /* Mode specific init */
577 ret
= wl1271_ap_hw_init(wl
, wlvif
);
581 ret
= wl12xx_init_ap_role(wl
, wlvif
);
585 ret
= wl1271_sta_hw_init(wl
, wlvif
);
589 ret
= wl12xx_init_sta_role(wl
, wlvif
);
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
);
606 conf_tid
= &wl
->conf
.tx
.tid_conf
[i
];
607 ret
= wl1271_acx_tid_cfg(wl
, wlvif
,
609 conf_tid
->channel_type
,
612 conf_tid
->ack_policy
,
613 conf_tid
->apsd_conf
[0],
614 conf_tid
->apsd_conf
[1]);
619 /* Configure HW encryption */
620 ret
= wl1271_acx_feature_cfg(wl
, wlvif
);
624 /* Mode specific init - post mem init */
626 ret
= wl1271_ap_hw_init_post_mem(wl
, vif
);
628 ret
= wl1271_sta_hw_init_post_mem(wl
, vif
);
633 /* Configure initiator BA sessions policies */
634 ret
= wl1271_set_ba_policies(wl
, wlvif
);
641 int wl1271_hw_init(struct wl1271
*wl
)
645 if (wl
->chip
.id
== CHIP_ID_1283_PG20
) {
646 ret
= wl128x_cmd_general_parms(wl
);
649 ret
= wl128x_cmd_radio_parms(wl
);
653 ret
= wl1271_cmd_general_parms(wl
);
656 ret
= wl1271_cmd_radio_parms(wl
);
659 ret
= wl1271_cmd_ext_radio_parms(wl
);
664 /* Chip-specific init */
665 ret
= wl1271_chip_specific_init(wl
);
670 ret
= wl1271_init_templates_config(wl
);
674 ret
= wl12xx_acx_mem_cfg(wl
);
678 /* Configure the FW logger */
679 ret
= wl12xx_init_fwlog(wl
);
683 /* Bluetooth WLAN coexistence */
684 ret
= wl1271_init_pta(wl
);
688 /* Default memory configuration */
689 ret
= wl1271_acx_init_mem_config(wl
);
694 ret
= wl12xx_init_rx_config(wl
);
696 goto out_free_memmap
;
698 ret
= wl1271_acx_dco_itrim_params(wl
);
700 goto out_free_memmap
;
702 /* Configure TX patch complete interrupt behavior */
703 ret
= wl1271_acx_tx_config_options(wl
);
705 goto out_free_memmap
;
707 /* RX complete interrupt pacing */
708 ret
= wl1271_acx_init_rx_interrupt(wl
);
710 goto out_free_memmap
;
712 /* Energy detection */
713 ret
= wl1271_init_energy_detection(wl
);
715 goto out_free_memmap
;
717 /* Default fragmentation threshold */
718 ret
= wl1271_acx_frag_threshold(wl
, wl
->hw
->wiphy
->frag_threshold
);
720 goto out_free_memmap
;
722 /* Enable data path */
723 ret
= wl1271_cmd_data_path(wl
, 1);
725 goto out_free_memmap
;
728 ret
= wl1271_acx_pm_config(wl
);
730 goto out_free_memmap
;
732 ret
= wl12xx_acx_set_rate_mgmt_params(wl
);
734 goto out_free_memmap
;
736 /* configure hangover */
737 ret
= wl12xx_acx_config_hangover(wl
);
739 goto out_free_memmap
;
744 kfree(wl
->target_mem_map
);
745 wl
->target_mem_map
= NULL
;