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_DFLT_SIZE
,
43 0, WL1271_RATE_AUTOMATIC
);
47 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_CFG_PROBE_REQ_5
,
48 NULL
, WL1271_CMD_TEMPL_DFLT_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
,
73 WL1271_CMD_TEMPL_DFLT_SIZE
,
74 0, WL1271_RATE_AUTOMATIC
);
78 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_BEACON
, NULL
,
79 WL1271_CMD_TEMPL_DFLT_SIZE
,
80 0, WL1271_RATE_AUTOMATIC
);
84 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_ARP_RSP
, NULL
,
86 (struct wl12xx_arp_rsp_template
),
87 0, WL1271_RATE_AUTOMATIC
);
91 for (i
= 0; i
< CMD_TEMPL_KLV_IDX_MAX
; i
++) {
92 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_KLV
, NULL
,
93 WL1271_CMD_TEMPL_DFLT_SIZE
, i
,
94 WL1271_RATE_AUTOMATIC
);
102 static int wl1271_ap_init_deauth_template(struct wl1271
*wl
)
104 struct wl12xx_disconn_template
*tmpl
;
107 tmpl
= kzalloc(sizeof(*tmpl
), GFP_KERNEL
);
113 tmpl
->header
.frame_ctl
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
114 IEEE80211_STYPE_DEAUTH
);
116 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_DEAUTH_AP
,
117 tmpl
, sizeof(*tmpl
), 0,
118 wl1271_tx_min_rate_get(wl
));
125 static int wl1271_ap_init_null_template(struct wl1271
*wl
)
127 struct ieee80211_hdr_3addr
*nullfunc
;
130 nullfunc
= kzalloc(sizeof(*nullfunc
), GFP_KERNEL
);
136 nullfunc
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
137 IEEE80211_STYPE_NULLFUNC
|
138 IEEE80211_FCTL_FROMDS
);
140 /* nullfunc->addr1 is filled by FW */
142 memcpy(nullfunc
->addr2
, wl
->mac_addr
, ETH_ALEN
);
143 memcpy(nullfunc
->addr3
, wl
->mac_addr
, ETH_ALEN
);
145 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_NULL_DATA
, nullfunc
,
146 sizeof(*nullfunc
), 0,
147 wl1271_tx_min_rate_get(wl
));
154 static int wl1271_ap_init_qos_null_template(struct wl1271
*wl
)
156 struct ieee80211_qos_hdr
*qosnull
;
159 qosnull
= kzalloc(sizeof(*qosnull
), GFP_KERNEL
);
165 qosnull
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
166 IEEE80211_STYPE_QOS_NULLFUNC
|
167 IEEE80211_FCTL_FROMDS
);
169 /* qosnull->addr1 is filled by FW */
171 memcpy(qosnull
->addr2
, wl
->mac_addr
, ETH_ALEN
);
172 memcpy(qosnull
->addr3
, wl
->mac_addr
, ETH_ALEN
);
174 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_QOS_NULL_DATA
, qosnull
,
176 wl1271_tx_min_rate_get(wl
));
183 static int wl1271_ap_init_templates_config(struct wl1271
*wl
)
188 * Put very large empty placeholders for all templates. These
189 * reserve memory for later.
191 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_AP_PROBE_RESPONSE
, NULL
,
192 WL1271_CMD_TEMPL_MAX_SIZE
,
193 0, WL1271_RATE_AUTOMATIC
);
197 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_AP_BEACON
, NULL
,
198 WL1271_CMD_TEMPL_MAX_SIZE
,
199 0, WL1271_RATE_AUTOMATIC
);
203 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_DEAUTH_AP
, NULL
,
205 (struct wl12xx_disconn_template
),
206 0, WL1271_RATE_AUTOMATIC
);
210 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_NULL_DATA
, NULL
,
211 sizeof(struct wl12xx_null_data_template
),
212 0, WL1271_RATE_AUTOMATIC
);
216 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_QOS_NULL_DATA
, NULL
,
218 (struct wl12xx_qos_null_data_template
),
219 0, WL1271_RATE_AUTOMATIC
);
226 static int wl12xx_init_rx_config(struct wl1271
*wl
)
230 ret
= wl1271_acx_rx_msdu_life_time(wl
);
237 int wl1271_init_phy_config(struct wl1271
*wl
)
241 ret
= wl1271_acx_pd_threshold(wl
);
245 ret
= wl1271_acx_slot(wl
, DEFAULT_SLOT_TIME
);
249 ret
= wl1271_acx_service_period_timeout(wl
);
253 ret
= wl1271_acx_rts_threshold(wl
, wl
->hw
->wiphy
->rts_threshold
);
260 static int wl1271_init_beacon_filter(struct wl1271
*wl
)
264 /* disable beacon filtering at this stage */
265 ret
= wl1271_acx_beacon_filter_opt(wl
, false);
269 ret
= wl1271_acx_beacon_filter_table(wl
);
276 int wl1271_init_pta(struct wl1271
*wl
)
280 ret
= wl12xx_acx_sg_cfg(wl
);
284 ret
= wl1271_acx_sg_enable(wl
, wl
->sg_enabled
);
291 int wl1271_init_energy_detection(struct wl1271
*wl
)
295 ret
= wl1271_acx_cca_threshold(wl
);
302 static int wl1271_init_beacon_broadcast(struct wl1271
*wl
)
306 ret
= wl1271_acx_bcn_dtim_options(wl
);
313 static int wl12xx_init_fwlog(struct wl1271
*wl
)
317 if (wl
->quirks
& WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED
)
320 ret
= wl12xx_cmd_config_fwlog(wl
);
327 static int wl1271_sta_hw_init(struct wl1271
*wl
)
331 if (wl
->chip
.id
!= CHIP_ID_1283_PG20
) {
332 ret
= wl1271_cmd_ext_radio_parms(wl
);
338 ret
= wl1271_acx_config_ps(wl
);
342 ret
= wl1271_sta_init_templates_config(wl
);
346 ret
= wl1271_acx_group_address_tbl(wl
, true, NULL
, 0);
350 /* Initialize connection monitoring thresholds */
351 ret
= wl1271_acx_conn_monit_params(wl
, false);
355 /* Beacon filtering */
356 ret
= wl1271_init_beacon_filter(wl
);
360 /* FM WLAN coexistence */
361 ret
= wl1271_acx_fm_coex(wl
);
365 /* Beacons and broadcast settings */
366 ret
= wl1271_init_beacon_broadcast(wl
);
370 /* Configure for ELP power saving */
371 ret
= wl1271_acx_sleep_auth(wl
, WL1271_PSM_ELP
);
375 /* Configure rssi/snr averaging weights */
376 ret
= wl1271_acx_rssi_snr_avg_weights(wl
);
380 ret
= wl1271_acx_sta_rate_policies(wl
);
384 ret
= wl12xx_acx_mem_cfg(wl
);
388 /* Configure the FW logger */
389 ret
= wl12xx_init_fwlog(wl
);
396 static int wl1271_sta_hw_init_post_mem(struct wl1271
*wl
)
400 /* disable all keep-alive templates */
401 for (i
= 0; i
< CMD_TEMPL_KLV_IDX_MAX
; i
++) {
402 ret
= wl1271_acx_keep_alive_config(wl
, i
,
403 ACX_KEEP_ALIVE_TPL_INVALID
);
408 /* disable the keep-alive feature */
409 ret
= wl1271_acx_keep_alive_mode(wl
, false);
416 static int wl1271_ap_hw_init(struct wl1271
*wl
)
420 ret
= wl1271_ap_init_templates_config(wl
);
424 /* Configure for power always on */
425 ret
= wl1271_acx_sleep_auth(wl
, WL1271_PSM_CAM
);
429 ret
= wl1271_init_ap_rates(wl
);
433 ret
= wl1271_acx_ap_max_tx_retry(wl
);
437 ret
= wl12xx_acx_mem_cfg(wl
);
441 /* initialize Tx power */
442 ret
= wl1271_acx_tx_power(wl
, wl
->power_level
);
449 int wl1271_ap_init_templates(struct wl1271
*wl
)
453 ret
= wl1271_ap_init_deauth_template(wl
);
457 ret
= wl1271_ap_init_null_template(wl
);
461 ret
= wl1271_ap_init_qos_null_template(wl
);
466 * when operating as AP we want to receive external beacons for
467 * configuring ERP protection.
469 ret
= wl1271_acx_beacon_filter_opt(wl
, false);
476 static int wl1271_ap_hw_init_post_mem(struct wl1271
*wl
)
478 return wl1271_ap_init_templates(wl
);
481 int wl1271_init_ap_rates(struct wl1271
*wl
)
484 struct conf_tx_rate_class rc
;
487 wl1271_debug(DEBUG_AP
, "AP basic rate set: 0x%x", wl
->basic_rate_set
);
489 if (wl
->basic_rate_set
== 0)
492 rc
.enabled_rates
= wl
->basic_rate_set
;
493 rc
.long_retry_limit
= 10;
494 rc
.short_retry_limit
= 10;
496 ret
= wl1271_acx_ap_rate_policy(wl
, &rc
, ACX_TX_AP_MODE_MGMT_RATE
);
500 /* use the min basic rate for AP broadcast/multicast */
501 rc
.enabled_rates
= wl1271_tx_min_rate_get(wl
);
502 rc
.short_retry_limit
= 10;
503 rc
.long_retry_limit
= 10;
505 ret
= wl1271_acx_ap_rate_policy(wl
, &rc
, ACX_TX_AP_MODE_BCST_RATE
);
510 * If the basic rates contain OFDM rates, use OFDM only
511 * rates for unicast TX as well. Else use all supported rates.
513 if ((wl
->basic_rate_set
& CONF_TX_OFDM_RATES
))
514 supported_rates
= CONF_TX_OFDM_RATES
;
516 supported_rates
= CONF_TX_AP_ENABLED_RATES
;
518 /* unconditionally enable HT rates */
519 supported_rates
|= CONF_TX_MCS_RATES
;
521 /* configure unicast TX rate classes */
522 for (i
= 0; i
< wl
->conf
.tx
.ac_conf_count
; i
++) {
523 rc
.enabled_rates
= supported_rates
;
524 rc
.short_retry_limit
= 10;
525 rc
.long_retry_limit
= 10;
527 ret
= wl1271_acx_ap_rate_policy(wl
, &rc
, i
);
535 static int wl1271_set_ba_policies(struct wl1271
*wl
)
537 /* Reset the BA RX indicators */
538 wl
->ba_rx_bitmap
= 0;
539 wl
->ba_allowed
= true;
540 wl
->ba_rx_session_count
= 0;
542 /* BA is supported in STA/AP modes */
543 if (wl
->bss_type
!= BSS_TYPE_AP_BSS
&&
544 wl
->bss_type
!= BSS_TYPE_STA_BSS
) {
545 wl
->ba_support
= false;
549 wl
->ba_support
= true;
551 /* 802.11n initiator BA session setting */
552 return wl12xx_acx_set_ba_initiator_policy(wl
);
555 int wl1271_chip_specific_init(struct wl1271
*wl
)
559 if (wl
->chip
.id
== CHIP_ID_1283_PG20
) {
560 u32 host_cfg_bitmap
= HOST_IF_CFG_RX_FIFO_ENABLE
;
562 if (wl
->quirks
& WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT
)
563 /* Enable SDIO padding */
564 host_cfg_bitmap
|= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK
;
566 /* Must be before wl1271_acx_init_mem_config() */
567 ret
= wl1271_acx_host_if_cfg_bitmap(wl
, host_cfg_bitmap
);
576 int wl1271_hw_init(struct wl1271
*wl
)
578 struct conf_tx_ac_category
*conf_ac
;
579 struct conf_tx_tid
*conf_tid
;
581 bool is_ap
= (wl
->bss_type
== BSS_TYPE_AP_BSS
);
583 if (wl
->chip
.id
== CHIP_ID_1283_PG20
)
584 ret
= wl128x_cmd_general_parms(wl
);
586 ret
= wl1271_cmd_general_parms(wl
);
590 if (wl
->chip
.id
== CHIP_ID_1283_PG20
)
591 ret
= wl128x_cmd_radio_parms(wl
);
593 ret
= wl1271_cmd_radio_parms(wl
);
597 /* Chip-specific init */
598 ret
= wl1271_chip_specific_init(wl
);
602 /* Mode specific init */
604 ret
= wl1271_ap_hw_init(wl
);
606 ret
= wl1271_sta_hw_init(wl
);
611 /* Bluetooth WLAN coexistence */
612 ret
= wl1271_init_pta(wl
);
616 /* Default memory configuration */
617 ret
= wl1271_acx_init_mem_config(wl
);
622 ret
= wl12xx_init_rx_config(wl
);
624 goto out_free_memmap
;
626 /* PHY layer config */
627 ret
= wl1271_init_phy_config(wl
);
629 goto out_free_memmap
;
631 ret
= wl1271_acx_dco_itrim_params(wl
);
633 goto out_free_memmap
;
635 /* Configure TX patch complete interrupt behavior */
636 ret
= wl1271_acx_tx_config_options(wl
);
638 goto out_free_memmap
;
640 /* RX complete interrupt pacing */
641 ret
= wl1271_acx_init_rx_interrupt(wl
);
643 goto out_free_memmap
;
645 /* Energy detection */
646 ret
= wl1271_init_energy_detection(wl
);
648 goto out_free_memmap
;
650 /* Default fragmentation threshold */
651 ret
= wl1271_acx_frag_threshold(wl
, wl
->hw
->wiphy
->frag_threshold
);
653 goto out_free_memmap
;
655 /* Default TID/AC configuration */
656 BUG_ON(wl
->conf
.tx
.tid_conf_count
!= wl
->conf
.tx
.ac_conf_count
);
657 for (i
= 0; i
< wl
->conf
.tx
.tid_conf_count
; i
++) {
658 conf_ac
= &wl
->conf
.tx
.ac_conf
[i
];
659 ret
= wl1271_acx_ac_cfg(wl
, conf_ac
->ac
, conf_ac
->cw_min
,
660 conf_ac
->cw_max
, conf_ac
->aifsn
,
661 conf_ac
->tx_op_limit
);
663 goto out_free_memmap
;
665 conf_tid
= &wl
->conf
.tx
.tid_conf
[i
];
666 ret
= wl1271_acx_tid_cfg(wl
, conf_tid
->queue_id
,
667 conf_tid
->channel_type
,
670 conf_tid
->ack_policy
,
671 conf_tid
->apsd_conf
[0],
672 conf_tid
->apsd_conf
[1]);
674 goto out_free_memmap
;
677 /* Enable data path */
678 ret
= wl1271_cmd_data_path(wl
, 1);
680 goto out_free_memmap
;
682 /* Configure HW encryption */
683 ret
= wl1271_acx_feature_cfg(wl
);
685 goto out_free_memmap
;
688 ret
= wl1271_acx_pm_config(wl
);
690 goto out_free_memmap
;
692 /* Mode specific init - post mem init */
694 ret
= wl1271_ap_hw_init_post_mem(wl
);
696 ret
= wl1271_sta_hw_init_post_mem(wl
);
699 goto out_free_memmap
;
701 ret
= wl12xx_acx_set_rate_mgmt_params(wl
);
703 goto out_free_memmap
;
705 /* Configure initiator BA sessions policies */
706 ret
= wl1271_set_ba_policies(wl
);
708 goto out_free_memmap
;
713 kfree(wl
->target_mem_map
);
714 wl
->target_mem_map
= NULL
;