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"
36 int wl1271_init_templates_config(struct wl1271
*wl
)
41 /* send empty templates for fw memory reservation */
42 ret
= wl1271_cmd_template_set(wl
, WL12XX_INVALID_ROLE_ID
,
43 CMD_TEMPL_CFG_PROBE_REQ_2_4
, NULL
,
44 WL1271_CMD_TEMPL_MAX_SIZE
,
45 0, WL1271_RATE_AUTOMATIC
);
49 ret
= wl1271_cmd_template_set(wl
, WL12XX_INVALID_ROLE_ID
,
50 CMD_TEMPL_CFG_PROBE_REQ_5
,
51 NULL
, WL1271_CMD_TEMPL_MAX_SIZE
, 0,
52 WL1271_RATE_AUTOMATIC
);
56 ret
= wl1271_cmd_template_set(wl
, WL12XX_INVALID_ROLE_ID
,
57 CMD_TEMPL_NULL_DATA
, NULL
,
58 sizeof(struct wl12xx_null_data_template
),
59 0, WL1271_RATE_AUTOMATIC
);
63 ret
= wl1271_cmd_template_set(wl
, WL12XX_INVALID_ROLE_ID
,
64 CMD_TEMPL_PS_POLL
, NULL
,
65 sizeof(struct wl12xx_ps_poll_template
),
66 0, WL1271_RATE_AUTOMATIC
);
70 ret
= wl1271_cmd_template_set(wl
, WL12XX_INVALID_ROLE_ID
,
71 CMD_TEMPL_QOS_NULL_DATA
, NULL
,
73 (struct ieee80211_qos_hdr
),
74 0, WL1271_RATE_AUTOMATIC
);
78 ret
= wl1271_cmd_template_set(wl
, WL12XX_INVALID_ROLE_ID
,
79 CMD_TEMPL_PROBE_RESPONSE
, NULL
,
80 WL1271_CMD_TEMPL_DFLT_SIZE
,
81 0, WL1271_RATE_AUTOMATIC
);
85 ret
= wl1271_cmd_template_set(wl
, WL12XX_INVALID_ROLE_ID
,
86 CMD_TEMPL_BEACON
, NULL
,
87 WL1271_CMD_TEMPL_DFLT_SIZE
,
88 0, WL1271_RATE_AUTOMATIC
);
92 max_size
= sizeof(struct wl12xx_arp_rsp_template
) +
93 WL1271_EXTRA_SPACE_MAX
;
94 ret
= wl1271_cmd_template_set(wl
, WL12XX_INVALID_ROLE_ID
,
95 CMD_TEMPL_ARP_RSP
, NULL
,
97 0, WL1271_RATE_AUTOMATIC
);
102 * Put very large empty placeholders for all templates. These
103 * reserve memory for later.
105 ret
= wl1271_cmd_template_set(wl
, WL12XX_INVALID_ROLE_ID
,
106 CMD_TEMPL_AP_PROBE_RESPONSE
, NULL
,
107 WL1271_CMD_TEMPL_MAX_SIZE
,
108 0, WL1271_RATE_AUTOMATIC
);
112 ret
= wl1271_cmd_template_set(wl
, WL12XX_INVALID_ROLE_ID
,
113 CMD_TEMPL_AP_BEACON
, NULL
,
114 WL1271_CMD_TEMPL_MAX_SIZE
,
115 0, WL1271_RATE_AUTOMATIC
);
119 ret
= wl1271_cmd_template_set(wl
, WL12XX_INVALID_ROLE_ID
,
120 CMD_TEMPL_DEAUTH_AP
, NULL
,
122 (struct wl12xx_disconn_template
),
123 0, WL1271_RATE_AUTOMATIC
);
127 for (i
= 0; i
< CMD_TEMPL_KLV_IDX_MAX
; i
++) {
128 ret
= wl1271_cmd_template_set(wl
, WL12XX_INVALID_ROLE_ID
,
130 sizeof(struct ieee80211_qos_hdr
),
131 i
, WL1271_RATE_AUTOMATIC
);
139 static int wl1271_ap_init_deauth_template(struct wl1271
*wl
,
140 struct wl12xx_vif
*wlvif
)
142 struct wl12xx_disconn_template
*tmpl
;
146 tmpl
= kzalloc(sizeof(*tmpl
), GFP_KERNEL
);
152 tmpl
->header
.frame_ctl
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
153 IEEE80211_STYPE_DEAUTH
);
155 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->basic_rate_set
);
156 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
158 tmpl
, sizeof(*tmpl
), 0, rate
);
165 static int wl1271_ap_init_null_template(struct wl1271
*wl
,
166 struct ieee80211_vif
*vif
)
168 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
169 struct ieee80211_hdr_3addr
*nullfunc
;
173 nullfunc
= kzalloc(sizeof(*nullfunc
), GFP_KERNEL
);
179 nullfunc
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
180 IEEE80211_STYPE_NULLFUNC
|
181 IEEE80211_FCTL_FROMDS
);
183 /* nullfunc->addr1 is filled by FW */
185 memcpy(nullfunc
->addr2
, vif
->addr
, ETH_ALEN
);
186 memcpy(nullfunc
->addr3
, vif
->addr
, ETH_ALEN
);
188 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->basic_rate_set
);
189 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
190 CMD_TEMPL_NULL_DATA
, nullfunc
,
191 sizeof(*nullfunc
), 0, rate
);
198 static int wl1271_ap_init_qos_null_template(struct wl1271
*wl
,
199 struct ieee80211_vif
*vif
)
201 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
202 struct ieee80211_qos_hdr
*qosnull
;
206 qosnull
= kzalloc(sizeof(*qosnull
), GFP_KERNEL
);
212 qosnull
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
213 IEEE80211_STYPE_QOS_NULLFUNC
|
214 IEEE80211_FCTL_FROMDS
);
216 /* qosnull->addr1 is filled by FW */
218 memcpy(qosnull
->addr2
, vif
->addr
, ETH_ALEN
);
219 memcpy(qosnull
->addr3
, vif
->addr
, ETH_ALEN
);
221 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->basic_rate_set
);
222 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
223 CMD_TEMPL_QOS_NULL_DATA
, qosnull
,
224 sizeof(*qosnull
), 0, rate
);
231 static int wl12xx_init_rx_config(struct wl1271
*wl
)
235 ret
= wl1271_acx_rx_msdu_life_time(wl
);
242 static int wl12xx_init_phy_vif_config(struct wl1271
*wl
,
243 struct wl12xx_vif
*wlvif
)
247 ret
= wl1271_acx_slot(wl
, wlvif
, DEFAULT_SLOT_TIME
);
251 ret
= wl1271_acx_service_period_timeout(wl
, wlvif
);
255 ret
= wl1271_acx_rts_threshold(wl
, wlvif
, wl
->hw
->wiphy
->rts_threshold
);
262 static int wl1271_init_sta_beacon_filter(struct wl1271
*wl
,
263 struct wl12xx_vif
*wlvif
)
267 ret
= wl1271_acx_beacon_filter_table(wl
, wlvif
);
271 /* enable beacon filtering */
272 ret
= wl1271_acx_beacon_filter_opt(wl
, wlvif
, true);
279 int wl1271_init_pta(struct wl1271
*wl
)
283 ret
= wl12xx_acx_sg_cfg(wl
);
287 ret
= wl1271_acx_sg_enable(wl
, wl
->sg_enabled
);
294 int wl1271_init_energy_detection(struct wl1271
*wl
)
298 ret
= wl1271_acx_cca_threshold(wl
);
305 static int wl1271_init_beacon_broadcast(struct wl1271
*wl
,
306 struct wl12xx_vif
*wlvif
)
310 ret
= wl1271_acx_bcn_dtim_options(wl
, wlvif
);
317 static int wl12xx_init_fwlog(struct wl1271
*wl
)
321 if (wl
->quirks
& WLCORE_QUIRK_FWLOG_NOT_IMPLEMENTED
)
324 ret
= wl12xx_cmd_config_fwlog(wl
);
331 /* generic sta initialization (non vif-specific) */
332 static int wl1271_sta_hw_init(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
337 ret
= wl12xx_acx_config_ps(wl
, wlvif
);
341 /* FM WLAN coexistence */
342 ret
= wl1271_acx_fm_coex(wl
);
346 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
353 static int wl1271_sta_hw_init_post_mem(struct wl1271
*wl
,
354 struct ieee80211_vif
*vif
)
356 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
359 /* disable all keep-alive templates */
360 for (i
= 0; i
< CMD_TEMPL_KLV_IDX_MAX
; i
++) {
361 ret
= wl1271_acx_keep_alive_config(wl
, wlvif
, i
,
362 ACX_KEEP_ALIVE_TPL_INVALID
);
367 /* disable the keep-alive feature */
368 ret
= wl1271_acx_keep_alive_mode(wl
, wlvif
, false);
375 /* generic ap initialization (non vif-specific) */
376 static int wl1271_ap_hw_init(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
380 ret
= wl1271_init_ap_rates(wl
, wlvif
);
387 int wl1271_ap_init_templates(struct wl1271
*wl
, struct ieee80211_vif
*vif
)
389 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
392 ret
= wl1271_ap_init_deauth_template(wl
, wlvif
);
396 ret
= wl1271_ap_init_null_template(wl
, vif
);
400 ret
= wl1271_ap_init_qos_null_template(wl
, vif
);
405 * when operating as AP we want to receive external beacons for
406 * configuring ERP protection.
408 ret
= wl1271_acx_beacon_filter_opt(wl
, wlvif
, false);
415 static int wl1271_ap_hw_init_post_mem(struct wl1271
*wl
,
416 struct ieee80211_vif
*vif
)
418 return wl1271_ap_init_templates(wl
, vif
);
421 int wl1271_init_ap_rates(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
424 struct conf_tx_rate_class rc
;
427 wl1271_debug(DEBUG_AP
, "AP basic rate set: 0x%x",
428 wlvif
->basic_rate_set
);
430 if (wlvif
->basic_rate_set
== 0)
433 rc
.enabled_rates
= wlvif
->basic_rate_set
;
434 rc
.long_retry_limit
= 10;
435 rc
.short_retry_limit
= 10;
437 ret
= wl1271_acx_ap_rate_policy(wl
, &rc
, wlvif
->ap
.mgmt_rate_idx
);
441 /* use the min basic rate for AP broadcast/multicast */
442 rc
.enabled_rates
= wl1271_tx_min_rate_get(wl
, wlvif
->basic_rate_set
);
443 rc
.short_retry_limit
= 10;
444 rc
.long_retry_limit
= 10;
446 ret
= wl1271_acx_ap_rate_policy(wl
, &rc
, wlvif
->ap
.bcast_rate_idx
);
451 * If the basic rates contain OFDM rates, use OFDM only
452 * rates for unicast TX as well. Else use all supported rates.
454 if ((wlvif
->basic_rate_set
& CONF_TX_OFDM_RATES
))
455 supported_rates
= CONF_TX_OFDM_RATES
;
457 supported_rates
= CONF_TX_AP_ENABLED_RATES
;
459 /* unconditionally enable HT rates */
460 supported_rates
|= CONF_TX_MCS_RATES
;
462 /* configure unicast TX rate classes */
463 for (i
= 0; i
< wl
->conf
.tx
.ac_conf_count
; i
++) {
464 rc
.enabled_rates
= supported_rates
;
465 rc
.short_retry_limit
= 10;
466 rc
.long_retry_limit
= 10;
468 ret
= wl1271_acx_ap_rate_policy(wl
, &rc
,
469 wlvif
->ap
.ucast_rate_idx
[i
]);
477 static int wl1271_set_ba_policies(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
479 /* Reset the BA RX indicators */
480 wlvif
->ba_allowed
= true;
481 wl
->ba_rx_session_count
= 0;
483 /* BA is supported in STA/AP modes */
484 if (wlvif
->bss_type
!= BSS_TYPE_AP_BSS
&&
485 wlvif
->bss_type
!= BSS_TYPE_STA_BSS
) {
486 wlvif
->ba_support
= false;
490 wlvif
->ba_support
= true;
492 /* 802.11n initiator BA session setting */
493 return wl12xx_acx_set_ba_initiator_policy(wl
, wlvif
);
496 int wl1271_chip_specific_init(struct wl1271
*wl
)
500 if (wl
->chip
.id
== CHIP_ID_1283_PG20
) {
501 u32 host_cfg_bitmap
= HOST_IF_CFG_RX_FIFO_ENABLE
;
503 if (!(wl
->quirks
& WLCORE_QUIRK_NO_BLOCKSIZE_ALIGNMENT
))
504 /* Enable SDIO padding */
505 host_cfg_bitmap
|= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK
;
507 /* Must be before wl1271_acx_init_mem_config() */
508 ret
= wl1271_acx_host_if_cfg_bitmap(wl
, host_cfg_bitmap
);
516 /* vif-specifc initialization */
517 static int wl12xx_init_sta_role(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
521 ret
= wl1271_acx_group_address_tbl(wl
, wlvif
, true, NULL
, 0);
525 /* Initialize connection monitoring thresholds */
526 ret
= wl1271_acx_conn_monit_params(wl
, wlvif
, false);
530 /* Beacon filtering */
531 ret
= wl1271_init_sta_beacon_filter(wl
, wlvif
);
535 /* Beacons and broadcast settings */
536 ret
= wl1271_init_beacon_broadcast(wl
, wlvif
);
540 /* Configure rssi/snr averaging weights */
541 ret
= wl1271_acx_rssi_snr_avg_weights(wl
, wlvif
);
548 /* vif-specific intialization */
549 static int wl12xx_init_ap_role(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
553 ret
= wl1271_acx_ap_max_tx_retry(wl
, wlvif
);
557 /* initialize Tx power */
558 ret
= wl1271_acx_tx_power(wl
, wlvif
, wlvif
->power_level
);
565 int wl1271_init_vif_specific(struct wl1271
*wl
, struct ieee80211_vif
*vif
)
567 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
568 struct conf_tx_ac_category
*conf_ac
;
569 struct conf_tx_tid
*conf_tid
;
570 bool is_ap
= (wlvif
->bss_type
== BSS_TYPE_AP_BSS
);
574 * consider all existing roles before configuring psm.
575 * TODO: reconfigure on interface removal.
579 /* Configure for power always on */
580 ret
= wl1271_acx_sleep_auth(wl
, WL1271_PSM_CAM
);
583 } else if (!wl
->sta_count
) {
584 if (wl
->quirks
& WLCORE_QUIRK_NO_ELP
) {
585 /* Configure for power always on */
586 ret
= wl1271_acx_sleep_auth(wl
, WL1271_PSM_CAM
);
590 /* Configure for ELP power saving */
591 ret
= wl1271_acx_sleep_auth(wl
, WL1271_PSM_ELP
);
598 /* Mode specific init */
600 ret
= wl1271_ap_hw_init(wl
, wlvif
);
604 ret
= wl12xx_init_ap_role(wl
, wlvif
);
608 ret
= wl1271_sta_hw_init(wl
, wlvif
);
612 ret
= wl12xx_init_sta_role(wl
, wlvif
);
617 wl12xx_init_phy_vif_config(wl
, wlvif
);
619 /* Default TID/AC configuration */
620 BUG_ON(wl
->conf
.tx
.tid_conf_count
!= wl
->conf
.tx
.ac_conf_count
);
621 for (i
= 0; i
< wl
->conf
.tx
.tid_conf_count
; i
++) {
622 conf_ac
= &wl
->conf
.tx
.ac_conf
[i
];
623 ret
= wl1271_acx_ac_cfg(wl
, wlvif
, conf_ac
->ac
,
624 conf_ac
->cw_min
, conf_ac
->cw_max
,
625 conf_ac
->aifsn
, conf_ac
->tx_op_limit
);
629 conf_tid
= &wl
->conf
.tx
.tid_conf
[i
];
630 ret
= wl1271_acx_tid_cfg(wl
, wlvif
,
632 conf_tid
->channel_type
,
635 conf_tid
->ack_policy
,
636 conf_tid
->apsd_conf
[0],
637 conf_tid
->apsd_conf
[1]);
642 /* Configure HW encryption */
643 ret
= wl1271_acx_feature_cfg(wl
, wlvif
);
647 /* Mode specific init - post mem init */
649 ret
= wl1271_ap_hw_init_post_mem(wl
, vif
);
651 ret
= wl1271_sta_hw_init_post_mem(wl
, vif
);
656 /* Configure initiator BA sessions policies */
657 ret
= wl1271_set_ba_policies(wl
, wlvif
);
664 int wl1271_hw_init(struct wl1271
*wl
)
668 if (wl
->chip
.id
== CHIP_ID_1283_PG20
) {
669 ret
= wl128x_cmd_general_parms(wl
);
672 ret
= wl128x_cmd_radio_parms(wl
);
676 ret
= wl1271_cmd_general_parms(wl
);
679 ret
= wl1271_cmd_radio_parms(wl
);
682 ret
= wl1271_cmd_ext_radio_parms(wl
);
687 /* Chip-specific init */
688 ret
= wl1271_chip_specific_init(wl
);
693 ret
= wl1271_init_templates_config(wl
);
697 ret
= wl12xx_acx_mem_cfg(wl
);
701 /* Configure the FW logger */
702 ret
= wl12xx_init_fwlog(wl
);
706 /* Bluetooth WLAN coexistence */
707 ret
= wl1271_init_pta(wl
);
711 /* Default memory configuration */
712 ret
= wl1271_acx_init_mem_config(wl
);
717 ret
= wl12xx_init_rx_config(wl
);
719 goto out_free_memmap
;
721 ret
= wl1271_acx_dco_itrim_params(wl
);
723 goto out_free_memmap
;
725 /* Configure TX patch complete interrupt behavior */
726 ret
= wl1271_acx_tx_config_options(wl
);
728 goto out_free_memmap
;
730 /* RX complete interrupt pacing */
731 ret
= wl1271_acx_init_rx_interrupt(wl
);
733 goto out_free_memmap
;
735 /* Energy detection */
736 ret
= wl1271_init_energy_detection(wl
);
738 goto out_free_memmap
;
740 /* Default fragmentation threshold */
741 ret
= wl1271_acx_frag_threshold(wl
, wl
->hw
->wiphy
->frag_threshold
);
743 goto out_free_memmap
;
745 /* Enable data path */
746 ret
= wl1271_cmd_data_path(wl
, 1);
748 goto out_free_memmap
;
751 ret
= wl1271_acx_pm_config(wl
);
753 goto out_free_memmap
;
755 ret
= wl12xx_acx_set_rate_mgmt_params(wl
);
757 goto out_free_memmap
;
759 /* configure hangover */
760 ret
= wl12xx_acx_config_hangover(wl
);
762 goto out_free_memmap
;
767 kfree(wl
->target_mem_map
);
768 wl
->target_mem_map
= NULL
;