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 wl12xx_qos_null_data_template
),
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 WL1271_CMD_TEMPL_DFLT_SIZE
, i
,
118 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 int wl1271_init_phy_config(struct wl1271
*wl
)
230 ret
= wl1271_acx_pd_threshold(wl
);
237 static int wl12xx_init_phy_vif_config(struct wl1271
*wl
,
238 struct wl12xx_vif
*wlvif
)
242 ret
= wl1271_acx_slot(wl
, wlvif
, DEFAULT_SLOT_TIME
);
246 ret
= wl1271_acx_service_period_timeout(wl
, wlvif
);
250 ret
= wl1271_acx_rts_threshold(wl
, wlvif
, wl
->hw
->wiphy
->rts_threshold
);
257 static int wl1271_init_sta_beacon_filter(struct wl1271
*wl
,
258 struct wl12xx_vif
*wlvif
)
262 ret
= wl1271_acx_beacon_filter_table(wl
, wlvif
);
266 /* enable beacon filtering */
267 ret
= wl1271_acx_beacon_filter_opt(wl
, wlvif
, true);
274 int wl1271_init_pta(struct wl1271
*wl
)
278 ret
= wl12xx_acx_sg_cfg(wl
);
282 ret
= wl1271_acx_sg_enable(wl
, wl
->sg_enabled
);
289 int wl1271_init_energy_detection(struct wl1271
*wl
)
293 ret
= wl1271_acx_cca_threshold(wl
);
300 static int wl1271_init_beacon_broadcast(struct wl1271
*wl
,
301 struct wl12xx_vif
*wlvif
)
305 ret
= wl1271_acx_bcn_dtim_options(wl
, wlvif
);
312 static int wl12xx_init_fwlog(struct wl1271
*wl
)
316 if (wl
->quirks
& WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED
)
319 ret
= wl12xx_cmd_config_fwlog(wl
);
326 /* generic sta initialization (non vif-specific) */
327 static int wl1271_sta_hw_init(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
331 if (wl
->chip
.id
!= CHIP_ID_1283_PG20
) {
332 ret
= wl1271_cmd_ext_radio_parms(wl
);
338 ret
= wl12xx_acx_config_ps(wl
, wlvif
);
342 /* FM WLAN coexistence */
343 ret
= wl1271_acx_fm_coex(wl
);
347 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
354 static int wl1271_sta_hw_init_post_mem(struct wl1271
*wl
,
355 struct ieee80211_vif
*vif
)
357 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
360 /* disable all keep-alive templates */
361 for (i
= 0; i
< CMD_TEMPL_KLV_IDX_MAX
; i
++) {
362 ret
= wl1271_acx_keep_alive_config(wl
, wlvif
, i
,
363 ACX_KEEP_ALIVE_TPL_INVALID
);
368 /* disable the keep-alive feature */
369 ret
= wl1271_acx_keep_alive_mode(wl
, wlvif
, false);
376 /* generic ap initialization (non vif-specific) */
377 static int wl1271_ap_hw_init(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
381 ret
= wl1271_init_ap_rates(wl
, wlvif
);
388 int wl1271_ap_init_templates(struct wl1271
*wl
, struct ieee80211_vif
*vif
)
390 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
393 ret
= wl1271_ap_init_deauth_template(wl
, wlvif
);
397 ret
= wl1271_ap_init_null_template(wl
, vif
);
401 ret
= wl1271_ap_init_qos_null_template(wl
, vif
);
406 * when operating as AP we want to receive external beacons for
407 * configuring ERP protection.
409 ret
= wl1271_acx_beacon_filter_opt(wl
, wlvif
, false);
416 static int wl1271_ap_hw_init_post_mem(struct wl1271
*wl
,
417 struct ieee80211_vif
*vif
)
419 return wl1271_ap_init_templates(wl
, vif
);
422 int wl1271_init_ap_rates(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
425 struct conf_tx_rate_class rc
;
428 wl1271_debug(DEBUG_AP
, "AP basic rate set: 0x%x",
429 wlvif
->basic_rate_set
);
431 if (wlvif
->basic_rate_set
== 0)
434 rc
.enabled_rates
= wlvif
->basic_rate_set
;
435 rc
.long_retry_limit
= 10;
436 rc
.short_retry_limit
= 10;
438 ret
= wl1271_acx_ap_rate_policy(wl
, &rc
, wlvif
->ap
.mgmt_rate_idx
);
442 /* use the min basic rate for AP broadcast/multicast */
443 rc
.enabled_rates
= wl1271_tx_min_rate_get(wl
, wlvif
->basic_rate_set
);
444 rc
.short_retry_limit
= 10;
445 rc
.long_retry_limit
= 10;
447 ret
= wl1271_acx_ap_rate_policy(wl
, &rc
, wlvif
->ap
.bcast_rate_idx
);
452 * If the basic rates contain OFDM rates, use OFDM only
453 * rates for unicast TX as well. Else use all supported rates.
455 if ((wlvif
->basic_rate_set
& CONF_TX_OFDM_RATES
))
456 supported_rates
= CONF_TX_OFDM_RATES
;
458 supported_rates
= CONF_TX_AP_ENABLED_RATES
;
460 /* unconditionally enable HT rates */
461 supported_rates
|= CONF_TX_MCS_RATES
;
463 /* configure unicast TX rate classes */
464 for (i
= 0; i
< wl
->conf
.tx
.ac_conf_count
; i
++) {
465 rc
.enabled_rates
= supported_rates
;
466 rc
.short_retry_limit
= 10;
467 rc
.long_retry_limit
= 10;
469 ret
= wl1271_acx_ap_rate_policy(wl
, &rc
,
470 wlvif
->ap
.ucast_rate_idx
[i
]);
478 static int wl1271_set_ba_policies(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
480 /* Reset the BA RX indicators */
481 wlvif
->ba_allowed
= true;
482 wl
->ba_rx_session_count
= 0;
484 /* BA is supported in STA/AP modes */
485 if (wlvif
->bss_type
!= BSS_TYPE_AP_BSS
&&
486 wlvif
->bss_type
!= BSS_TYPE_STA_BSS
) {
487 wlvif
->ba_support
= false;
491 wlvif
->ba_support
= true;
493 /* 802.11n initiator BA session setting */
494 return wl12xx_acx_set_ba_initiator_policy(wl
, wlvif
);
497 int wl1271_chip_specific_init(struct wl1271
*wl
)
501 if (wl
->chip
.id
== CHIP_ID_1283_PG20
) {
502 u32 host_cfg_bitmap
= HOST_IF_CFG_RX_FIFO_ENABLE
;
504 if (!(wl
->quirks
& WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT
))
505 /* Enable SDIO padding */
506 host_cfg_bitmap
|= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK
;
508 /* Must be before wl1271_acx_init_mem_config() */
509 ret
= wl1271_acx_host_if_cfg_bitmap(wl
, host_cfg_bitmap
);
517 /* vif-specifc initialization */
518 static int wl12xx_init_sta_role(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
522 ret
= wl1271_acx_group_address_tbl(wl
, wlvif
, true, NULL
, 0);
526 /* Initialize connection monitoring thresholds */
527 ret
= wl1271_acx_conn_monit_params(wl
, wlvif
, false);
531 /* Beacon filtering */
532 ret
= wl1271_init_sta_beacon_filter(wl
, wlvif
);
536 /* Beacons and broadcast settings */
537 ret
= wl1271_init_beacon_broadcast(wl
, wlvif
);
541 /* Configure rssi/snr averaging weights */
542 ret
= wl1271_acx_rssi_snr_avg_weights(wl
, wlvif
);
549 /* vif-specific intialization */
550 static int wl12xx_init_ap_role(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
554 ret
= wl1271_acx_ap_max_tx_retry(wl
, wlvif
);
558 /* initialize Tx power */
559 ret
= wl1271_acx_tx_power(wl
, wlvif
, wlvif
->power_level
);
566 int wl1271_init_vif_specific(struct wl1271
*wl
, struct ieee80211_vif
*vif
)
568 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
569 struct conf_tx_ac_category
*conf_ac
;
570 struct conf_tx_tid
*conf_tid
;
571 bool is_ap
= (wlvif
->bss_type
== BSS_TYPE_AP_BSS
);
575 * consider all existing roles before configuring psm.
576 * TODO: reconfigure on interface removal.
580 /* Configure for power always on */
581 ret
= wl1271_acx_sleep_auth(wl
, WL1271_PSM_CAM
);
584 } else if (!wl
->sta_count
) {
585 /* Configure for ELP power saving */
586 ret
= wl1271_acx_sleep_auth(wl
, WL1271_PSM_ELP
);
592 /* Mode specific init */
594 ret
= wl1271_ap_hw_init(wl
, wlvif
);
598 ret
= wl12xx_init_ap_role(wl
, wlvif
);
602 ret
= wl1271_sta_hw_init(wl
, wlvif
);
606 ret
= wl12xx_init_sta_role(wl
, wlvif
);
611 wl12xx_init_phy_vif_config(wl
, wlvif
);
613 /* Default TID/AC configuration */
614 BUG_ON(wl
->conf
.tx
.tid_conf_count
!= wl
->conf
.tx
.ac_conf_count
);
615 for (i
= 0; i
< wl
->conf
.tx
.tid_conf_count
; i
++) {
616 conf_ac
= &wl
->conf
.tx
.ac_conf
[i
];
617 ret
= wl1271_acx_ac_cfg(wl
, wlvif
, conf_ac
->ac
,
618 conf_ac
->cw_min
, conf_ac
->cw_max
,
619 conf_ac
->aifsn
, conf_ac
->tx_op_limit
);
623 conf_tid
= &wl
->conf
.tx
.tid_conf
[i
];
624 ret
= wl1271_acx_tid_cfg(wl
, wlvif
,
626 conf_tid
->channel_type
,
629 conf_tid
->ack_policy
,
630 conf_tid
->apsd_conf
[0],
631 conf_tid
->apsd_conf
[1]);
636 /* Configure HW encryption */
637 ret
= wl1271_acx_feature_cfg(wl
, wlvif
);
641 /* Mode specific init - post mem init */
643 ret
= wl1271_ap_hw_init_post_mem(wl
, vif
);
645 ret
= wl1271_sta_hw_init_post_mem(wl
, vif
);
650 /* Configure initiator BA sessions policies */
651 ret
= wl1271_set_ba_policies(wl
, wlvif
);
658 int wl1271_hw_init(struct wl1271
*wl
)
662 if (wl
->chip
.id
== CHIP_ID_1283_PG20
)
663 ret
= wl128x_cmd_general_parms(wl
);
665 ret
= wl1271_cmd_general_parms(wl
);
669 if (wl
->chip
.id
== CHIP_ID_1283_PG20
)
670 ret
= wl128x_cmd_radio_parms(wl
);
672 ret
= wl1271_cmd_radio_parms(wl
);
676 /* Chip-specific init */
677 ret
= wl1271_chip_specific_init(wl
);
682 ret
= wl1271_init_templates_config(wl
);
686 ret
= wl12xx_acx_mem_cfg(wl
);
690 /* Configure the FW logger */
691 ret
= wl12xx_init_fwlog(wl
);
695 /* Bluetooth WLAN coexistence */
696 ret
= wl1271_init_pta(wl
);
700 /* Default memory configuration */
701 ret
= wl1271_acx_init_mem_config(wl
);
706 ret
= wl12xx_init_rx_config(wl
);
708 goto out_free_memmap
;
710 /* PHY layer config */
711 ret
= wl1271_init_phy_config(wl
);
713 goto out_free_memmap
;
715 ret
= wl1271_acx_dco_itrim_params(wl
);
717 goto out_free_memmap
;
719 /* Configure TX patch complete interrupt behavior */
720 ret
= wl1271_acx_tx_config_options(wl
);
722 goto out_free_memmap
;
724 /* RX complete interrupt pacing */
725 ret
= wl1271_acx_init_rx_interrupt(wl
);
727 goto out_free_memmap
;
729 /* Energy detection */
730 ret
= wl1271_init_energy_detection(wl
);
732 goto out_free_memmap
;
734 /* Default fragmentation threshold */
735 ret
= wl1271_acx_frag_threshold(wl
, wl
->hw
->wiphy
->frag_threshold
);
737 goto out_free_memmap
;
739 /* Enable data path */
740 ret
= wl1271_cmd_data_path(wl
, 1);
742 goto out_free_memmap
;
745 ret
= wl1271_acx_pm_config(wl
);
747 goto out_free_memmap
;
749 ret
= wl12xx_acx_set_rate_mgmt_params(wl
);
751 goto out_free_memmap
;
753 /* configure hangover */
754 ret
= wl12xx_acx_config_hangover(wl
);
756 goto out_free_memmap
;
761 kfree(wl
->target_mem_map
);
762 wl
->target_mem_map
= NULL
;