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;
108 tmpl = kzalloc(sizeof(*tmpl), GFP_KERNEL);
114 tmpl->header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT |
115 IEEE80211_STYPE_DEAUTH);
117 rate = wl1271_tx_min_rate_get(wl, wl->basic_rate_set);
118 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP,
119 tmpl, sizeof(*tmpl), 0, rate);
126 static int wl1271_ap_init_null_template(struct wl1271 *wl)
128 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 rate = wl1271_tx_min_rate_get(wl, wl->basic_rate_set);
148 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, nullfunc,
149 sizeof(*nullfunc), 0, rate);
156 static int wl1271_ap_init_qos_null_template(struct wl1271 *wl)
158 struct ieee80211_qos_hdr *qosnull;
162 qosnull = kzalloc(sizeof(*qosnull), GFP_KERNEL);
168 qosnull->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
169 IEEE80211_STYPE_QOS_NULLFUNC |
170 IEEE80211_FCTL_FROMDS);
172 /* qosnull->addr1 is filled by FW */
174 memcpy(qosnull->addr2, wl->mac_addr, ETH_ALEN);
175 memcpy(qosnull->addr3, wl->mac_addr, ETH_ALEN);
177 rate = wl1271_tx_min_rate_get(wl, wl->basic_rate_set);
178 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, qosnull,
179 sizeof(*qosnull), 0, rate);
186 static int wl1271_ap_init_templates_config(struct wl1271 *wl)
191 * Put very large empty placeholders for all templates. These
192 * reserve memory for later.
194 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_PROBE_RESPONSE, NULL,
195 WL1271_CMD_TEMPL_MAX_SIZE,
196 0, WL1271_RATE_AUTOMATIC);
200 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_BEACON, NULL,
201 WL1271_CMD_TEMPL_MAX_SIZE,
202 0, WL1271_RATE_AUTOMATIC);
206 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP, NULL,
208 (struct wl12xx_disconn_template),
209 0, WL1271_RATE_AUTOMATIC);
213 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
214 sizeof(struct wl12xx_null_data_template),
215 0, WL1271_RATE_AUTOMATIC);
219 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
221 (struct wl12xx_qos_null_data_template),
222 0, WL1271_RATE_AUTOMATIC);
229 static int wl12xx_init_rx_config(struct wl1271 *wl)
233 ret = wl1271_acx_rx_msdu_life_time(wl);
240 int wl1271_init_phy_config(struct wl1271 *wl)
244 ret = wl1271_acx_pd_threshold(wl);
248 ret = wl1271_acx_slot(wl, DEFAULT_SLOT_TIME);
252 ret = wl1271_acx_service_period_timeout(wl);
256 ret = wl1271_acx_rts_threshold(wl, wl->hw->wiphy->rts_threshold);
263 static int wl1271_init_beacon_filter(struct wl1271 *wl)
267 /* disable beacon filtering at this stage */
268 ret = wl1271_acx_beacon_filter_opt(wl, false);
272 ret = wl1271_acx_beacon_filter_table(wl);
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)
309 ret = wl1271_acx_bcn_dtim_options(wl);
316 static int wl12xx_init_fwlog(struct wl1271 *wl)
320 if (wl->quirks & WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED)
323 ret = wl12xx_cmd_config_fwlog(wl);
330 static int wl1271_sta_hw_init(struct wl1271 *wl)
334 if (wl->chip.id != CHIP_ID_1283_PG20) {
335 ret = wl1271_cmd_ext_radio_parms(wl);
341 ret = wl1271_acx_config_ps(wl);
345 ret = wl1271_sta_init_templates_config(wl);
349 ret = wl1271_acx_group_address_tbl(wl, true, NULL, 0);
353 /* Initialize connection monitoring thresholds */
354 ret = wl1271_acx_conn_monit_params(wl, false);
358 /* Beacon filtering */
359 ret = wl1271_init_beacon_filter(wl);
363 /* FM WLAN coexistence */
364 ret = wl1271_acx_fm_coex(wl);
368 /* Beacons and broadcast settings */
369 ret = wl1271_init_beacon_broadcast(wl);
373 /* Configure for ELP power saving */
374 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
378 /* Configure rssi/snr averaging weights */
379 ret = wl1271_acx_rssi_snr_avg_weights(wl);
383 ret = wl1271_acx_sta_rate_policies(wl);
387 ret = wl12xx_acx_mem_cfg(wl);
391 /* Configure the FW logger */
392 ret = wl12xx_init_fwlog(wl);
399 static int wl1271_sta_hw_init_post_mem(struct wl1271 *wl)
403 /* disable all keep-alive templates */
404 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
405 ret = wl1271_acx_keep_alive_config(wl, i,
406 ACX_KEEP_ALIVE_TPL_INVALID);
411 /* disable the keep-alive feature */
412 ret = wl1271_acx_keep_alive_mode(wl, false);
419 static int wl1271_ap_hw_init(struct wl1271 *wl)
423 ret = wl1271_ap_init_templates_config(wl);
427 /* Configure for power always on */
428 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
432 ret = wl1271_init_ap_rates(wl);
436 ret = wl1271_acx_ap_max_tx_retry(wl);
440 ret = wl12xx_acx_mem_cfg(wl);
444 /* initialize Tx power */
445 ret = wl1271_acx_tx_power(wl, wl->power_level);
452 int wl1271_ap_init_templates(struct wl1271 *wl)
456 ret = wl1271_ap_init_deauth_template(wl);
460 ret = wl1271_ap_init_null_template(wl);
464 ret = wl1271_ap_init_qos_null_template(wl);
469 * when operating as AP we want to receive external beacons for
470 * configuring ERP protection.
472 ret = wl1271_acx_beacon_filter_opt(wl, false);
479 static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl)
481 return wl1271_ap_init_templates(wl);
484 int wl1271_init_ap_rates(struct wl1271 *wl)
487 struct conf_tx_rate_class rc;
490 wl1271_debug(DEBUG_AP, "AP basic rate set: 0x%x", wl->basic_rate_set);
492 if (wl->basic_rate_set == 0)
495 rc.enabled_rates = wl->basic_rate_set;
496 rc.long_retry_limit = 10;
497 rc.short_retry_limit = 10;
499 ret = wl1271_acx_ap_rate_policy(wl, &rc, ACX_TX_AP_MODE_MGMT_RATE);
503 /* use the min basic rate for AP broadcast/multicast */
504 rc.enabled_rates = wl1271_tx_min_rate_get(wl, wl->basic_rate_set);
505 rc.short_retry_limit = 10;
506 rc.long_retry_limit = 10;
508 ret = wl1271_acx_ap_rate_policy(wl, &rc, ACX_TX_AP_MODE_BCST_RATE);
513 * If the basic rates contain OFDM rates, use OFDM only
514 * rates for unicast TX as well. Else use all supported rates.
516 if ((wl->basic_rate_set & CONF_TX_OFDM_RATES))
517 supported_rates = CONF_TX_OFDM_RATES;
519 supported_rates = CONF_TX_AP_ENABLED_RATES;
521 /* unconditionally enable HT rates */
522 supported_rates |= CONF_TX_MCS_RATES;
524 /* configure unicast TX rate classes */
525 for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
526 rc.enabled_rates = supported_rates;
527 rc.short_retry_limit = 10;
528 rc.long_retry_limit = 10;
530 ret = wl1271_acx_ap_rate_policy(wl, &rc, i);
538 static int wl1271_set_ba_policies(struct wl1271 *wl)
540 /* Reset the BA RX indicators */
541 wl->ba_rx_bitmap = 0;
542 wl->ba_allowed = true;
543 wl->ba_rx_session_count = 0;
545 /* BA is supported in STA/AP modes */
546 if (wl->bss_type != BSS_TYPE_AP_BSS &&
547 wl->bss_type != BSS_TYPE_STA_BSS) {
548 wl->ba_support = false;
552 wl->ba_support = true;
554 /* 802.11n initiator BA session setting */
555 return wl12xx_acx_set_ba_initiator_policy(wl);
558 int wl1271_chip_specific_init(struct wl1271 *wl)
562 if (wl->chip.id == CHIP_ID_1283_PG20) {
563 u32 host_cfg_bitmap = HOST_IF_CFG_RX_FIFO_ENABLE;
565 if (wl->quirks & WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT)
566 /* Enable SDIO padding */
567 host_cfg_bitmap |= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK;
569 /* Must be before wl1271_acx_init_mem_config() */
570 ret = wl1271_acx_host_if_cfg_bitmap(wl, host_cfg_bitmap);
579 int wl1271_hw_init(struct wl1271 *wl)
581 struct conf_tx_ac_category *conf_ac;
582 struct conf_tx_tid *conf_tid;
584 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
586 if (wl->chip.id == CHIP_ID_1283_PG20)
587 ret = wl128x_cmd_general_parms(wl);
589 ret = wl1271_cmd_general_parms(wl);
593 if (wl->chip.id == CHIP_ID_1283_PG20)
594 ret = wl128x_cmd_radio_parms(wl);
596 ret = wl1271_cmd_radio_parms(wl);
600 /* Chip-specific init */
601 ret = wl1271_chip_specific_init(wl);
605 /* Mode specific init */
607 ret = wl1271_ap_hw_init(wl);
609 ret = wl1271_sta_hw_init(wl);
614 /* Bluetooth WLAN coexistence */
615 ret = wl1271_init_pta(wl);
619 /* Default memory configuration */
620 ret = wl1271_acx_init_mem_config(wl);
625 ret = wl12xx_init_rx_config(wl);
627 goto out_free_memmap;
629 /* PHY layer config */
630 ret = wl1271_init_phy_config(wl);
632 goto out_free_memmap;
634 ret = wl1271_acx_dco_itrim_params(wl);
636 goto out_free_memmap;
638 /* Configure TX patch complete interrupt behavior */
639 ret = wl1271_acx_tx_config_options(wl);
641 goto out_free_memmap;
643 /* RX complete interrupt pacing */
644 ret = wl1271_acx_init_rx_interrupt(wl);
646 goto out_free_memmap;
648 /* Energy detection */
649 ret = wl1271_init_energy_detection(wl);
651 goto out_free_memmap;
653 /* Default fragmentation threshold */
654 ret = wl1271_acx_frag_threshold(wl, wl->hw->wiphy->frag_threshold);
656 goto out_free_memmap;
658 /* Default TID/AC configuration */
659 BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
660 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
661 conf_ac = &wl->conf.tx.ac_conf[i];
662 ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
663 conf_ac->cw_max, conf_ac->aifsn,
664 conf_ac->tx_op_limit);
666 goto out_free_memmap;
668 conf_tid = &wl->conf.tx.tid_conf[i];
669 ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id,
670 conf_tid->channel_type,
673 conf_tid->ack_policy,
674 conf_tid->apsd_conf[0],
675 conf_tid->apsd_conf[1]);
677 goto out_free_memmap;
680 /* Enable data path */
681 ret = wl1271_cmd_data_path(wl, 1);
683 goto out_free_memmap;
685 /* Configure HW encryption */
686 ret = wl1271_acx_feature_cfg(wl);
688 goto out_free_memmap;
691 ret = wl1271_acx_pm_config(wl);
693 goto out_free_memmap;
695 /* Mode specific init - post mem init */
697 ret = wl1271_ap_hw_init_post_mem(wl);
699 ret = wl1271_sta_hw_init_post_mem(wl);
702 goto out_free_memmap;
704 ret = wl12xx_acx_set_rate_mgmt_params(wl);
706 goto out_free_memmap;
708 /* Configure initiator BA sessions policies */
709 ret = wl1271_set_ba_policies(wl);
711 goto out_free_memmap;
713 /* configure hangover */
714 ret = wl12xx_acx_config_hangover(wl);
716 goto out_free_memmap;
721 kfree(wl->target_mem_map);
722 wl->target_mem_map = NULL;