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_MAX_SIZE,
43 0, WL1271_RATE_AUTOMATIC);
47 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
48 NULL, WL1271_CMD_TEMPL_MAX_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,
74 (struct wl12xx_probe_resp_template),
75 0, WL1271_RATE_AUTOMATIC);
79 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON, NULL,
81 (struct wl12xx_beacon_template),
82 0, WL1271_RATE_AUTOMATIC);
86 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_ARP_RSP, NULL,
88 (struct wl12xx_arp_rsp_template),
89 0, WL1271_RATE_AUTOMATIC);
93 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
94 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV, NULL,
95 WL1271_CMD_TEMPL_MAX_SIZE, i,
96 WL1271_RATE_AUTOMATIC);
104 static int wl1271_ap_init_deauth_template(struct wl1271 *wl)
106 struct wl12xx_disconn_template *tmpl;
109 tmpl = kzalloc(sizeof(*tmpl), GFP_KERNEL);
115 tmpl->header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT |
116 IEEE80211_STYPE_DEAUTH);
118 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP,
119 tmpl, sizeof(*tmpl), 0,
120 wl1271_tx_min_rate_get(wl));
127 static int wl1271_ap_init_null_template(struct wl1271 *wl)
129 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 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, nullfunc,
148 sizeof(*nullfunc), 0,
149 wl1271_tx_min_rate_get(wl));
156 static int wl1271_ap_init_qos_null_template(struct wl1271 *wl)
158 struct ieee80211_qos_hdr *qosnull;
161 qosnull = kzalloc(sizeof(*qosnull), GFP_KERNEL);
167 qosnull->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
168 IEEE80211_STYPE_QOS_NULLFUNC |
169 IEEE80211_FCTL_FROMDS);
171 /* qosnull->addr1 is filled by FW */
173 memcpy(qosnull->addr2, wl->mac_addr, ETH_ALEN);
174 memcpy(qosnull->addr3, wl->mac_addr, ETH_ALEN);
176 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, qosnull,
178 wl1271_tx_min_rate_get(wl));
185 static int wl1271_ap_init_templates_config(struct wl1271 *wl)
190 * Put very large empty placeholders for all templates. These
191 * reserve memory for later.
193 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_PROBE_RESPONSE, NULL,
195 (struct wl12xx_probe_resp_template),
196 0, WL1271_RATE_AUTOMATIC);
200 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_BEACON, NULL,
202 (struct wl12xx_beacon_template),
203 0, WL1271_RATE_AUTOMATIC);
207 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP, NULL,
209 (struct wl12xx_disconn_template),
210 0, WL1271_RATE_AUTOMATIC);
214 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
215 sizeof(struct wl12xx_null_data_template),
216 0, WL1271_RATE_AUTOMATIC);
220 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
222 (struct wl12xx_qos_null_data_template),
223 0, WL1271_RATE_AUTOMATIC);
230 static int wl1271_init_rx_config(struct wl1271 *wl, u32 config, u32 filter)
234 ret = wl1271_acx_rx_msdu_life_time(wl);
238 ret = wl1271_acx_rx_config(wl, config, filter);
245 int wl1271_init_phy_config(struct wl1271 *wl)
249 ret = wl1271_acx_pd_threshold(wl);
253 ret = wl1271_acx_slot(wl, DEFAULT_SLOT_TIME);
257 ret = wl1271_acx_service_period_timeout(wl);
261 ret = wl1271_acx_rts_threshold(wl, wl->hw->wiphy->rts_threshold);
268 static int wl1271_init_beacon_filter(struct wl1271 *wl)
272 /* disable beacon filtering at this stage */
273 ret = wl1271_acx_beacon_filter_opt(wl, false);
277 ret = wl1271_acx_beacon_filter_table(wl);
284 int wl1271_init_pta(struct wl1271 *wl)
288 if (wl->bss_type == BSS_TYPE_AP_BSS)
289 ret = wl1271_acx_ap_sg_cfg(wl);
291 ret = wl1271_acx_sta_sg_cfg(wl);
295 ret = wl1271_acx_sg_enable(wl, wl->sg_enabled);
302 int wl1271_init_energy_detection(struct wl1271 *wl)
306 ret = wl1271_acx_cca_threshold(wl);
313 static int wl1271_init_beacon_broadcast(struct wl1271 *wl)
317 ret = wl1271_acx_bcn_dtim_options(wl);
324 static int wl1271_sta_hw_init(struct wl1271 *wl)
328 if (wl->chip.id != CHIP_ID_1283_PG20) {
329 ret = wl1271_cmd_ext_radio_parms(wl);
335 ret = wl1271_acx_config_ps(wl);
339 ret = wl1271_sta_init_templates_config(wl);
343 ret = wl1271_acx_group_address_tbl(wl, true, NULL, 0);
347 /* Initialize connection monitoring thresholds */
348 ret = wl1271_acx_conn_monit_params(wl, false);
352 /* Beacon filtering */
353 ret = wl1271_init_beacon_filter(wl);
357 /* FM WLAN coexistence */
358 ret = wl1271_acx_fm_coex(wl);
362 /* Beacons and broadcast settings */
363 ret = wl1271_init_beacon_broadcast(wl);
367 /* Configure for ELP power saving */
368 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
372 /* Configure rssi/snr averaging weights */
373 ret = wl1271_acx_rssi_snr_avg_weights(wl);
377 ret = wl1271_acx_sta_rate_policies(wl);
381 ret = wl1271_acx_sta_mem_cfg(wl);
388 static int wl1271_sta_hw_init_post_mem(struct wl1271 *wl)
392 ret = wl1271_cmd_set_sta_default_wep_key(wl, wl->default_key);
394 wl1271_warning("couldn't set default key");
398 /* disable all keep-alive templates */
399 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
400 ret = wl1271_acx_keep_alive_config(wl, i,
401 ACX_KEEP_ALIVE_TPL_INVALID);
406 /* disable the keep-alive feature */
407 ret = wl1271_acx_keep_alive_mode(wl, false);
414 static int wl1271_ap_hw_init(struct wl1271 *wl)
418 ret = wl1271_ap_init_templates_config(wl);
422 /* Configure for power always on */
423 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
427 ret = wl1271_init_ap_rates(wl);
431 ret = wl1271_acx_max_tx_retry(wl);
435 ret = wl1271_acx_ap_mem_cfg(wl);
442 int wl1271_ap_init_templates(struct wl1271 *wl)
446 ret = wl1271_ap_init_deauth_template(wl);
450 ret = wl1271_ap_init_null_template(wl);
454 ret = wl1271_ap_init_qos_null_template(wl);
459 * when operating as AP we want to receive external beacons for
460 * configuring ERP protection.
462 ret = wl1271_acx_set_ap_beacon_filter(wl, false);
469 static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl)
471 return wl1271_ap_init_templates(wl);
474 int wl1271_init_ap_rates(struct wl1271 *wl)
477 struct conf_tx_rate_class rc;
480 wl1271_debug(DEBUG_AP, "AP basic rate set: 0x%x", wl->basic_rate_set);
482 if (wl->basic_rate_set == 0)
485 rc.enabled_rates = wl->basic_rate_set;
486 rc.long_retry_limit = 10;
487 rc.short_retry_limit = 10;
489 ret = wl1271_acx_ap_rate_policy(wl, &rc, ACX_TX_AP_MODE_MGMT_RATE);
493 /* use the min basic rate for AP broadcast/multicast */
494 rc.enabled_rates = wl1271_tx_min_rate_get(wl);
495 rc.short_retry_limit = 10;
496 rc.long_retry_limit = 10;
498 ret = wl1271_acx_ap_rate_policy(wl, &rc, ACX_TX_AP_MODE_BCST_RATE);
503 * If the basic rates contain OFDM rates, use OFDM only
504 * rates for unicast TX as well. Else use all supported rates.
506 if ((wl->basic_rate_set & CONF_TX_OFDM_RATES))
507 supported_rates = CONF_TX_OFDM_RATES;
509 supported_rates = CONF_TX_AP_ENABLED_RATES;
511 /* configure unicast TX rate classes */
512 for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
513 rc.enabled_rates = supported_rates;
514 rc.short_retry_limit = 10;
515 rc.long_retry_limit = 10;
517 ret = wl1271_acx_ap_rate_policy(wl, &rc, i);
525 static void wl1271_check_ba_support(struct wl1271 *wl)
527 /* validate FW cose ver x.x.x.50-60.x */
528 if ((wl->chip.fw_ver[3] >= WL12XX_BA_SUPPORT_FW_COST_VER2_START) &&
529 (wl->chip.fw_ver[3] < WL12XX_BA_SUPPORT_FW_COST_VER2_END)) {
530 wl->ba_support = true;
534 wl->ba_support = false;
537 static int wl1271_set_ba_policies(struct wl1271 *wl)
542 /* Reset the BA RX indicators */
543 wl->ba_rx_bitmap = 0;
544 wl->ba_allowed = true;
546 /* validate that FW support BA */
547 wl1271_check_ba_support(wl);
550 /* 802.11n initiator BA session setting */
551 for (tid_index = 0; tid_index < CONF_TX_MAX_TID_COUNT;
553 ret = wl1271_acx_set_ba_session(wl, WLAN_BACK_INITIATOR,
562 int wl1271_chip_specific_init(struct wl1271 *wl)
566 if (wl->chip.id == CHIP_ID_1283_PG20) {
567 u32 host_cfg_bitmap = HOST_IF_CFG_RX_FIFO_ENABLE;
569 if (wl->quirks & WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT)
570 /* Enable SDIO padding */
571 host_cfg_bitmap |= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK;
573 /* Must be before wl1271_acx_init_mem_config() */
574 ret = wl1271_acx_host_if_cfg_bitmap(wl, host_cfg_bitmap);
583 int wl1271_hw_init(struct wl1271 *wl)
585 struct conf_tx_ac_category *conf_ac;
586 struct conf_tx_tid *conf_tid;
588 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
590 if (wl->chip.id == CHIP_ID_1283_PG20)
591 ret = wl128x_cmd_general_parms(wl);
593 ret = wl1271_cmd_general_parms(wl);
597 if (wl->chip.id == CHIP_ID_1283_PG20)
598 ret = wl128x_cmd_radio_parms(wl);
600 ret = wl1271_cmd_radio_parms(wl);
604 /* Chip-specific init */
605 ret = wl1271_chip_specific_init(wl);
609 /* Mode specific init */
611 ret = wl1271_ap_hw_init(wl);
613 ret = wl1271_sta_hw_init(wl);
618 /* Bluetooth WLAN coexistence */
619 ret = wl1271_init_pta(wl);
623 /* Default memory configuration */
624 ret = wl1271_acx_init_mem_config(wl);
629 ret = wl1271_init_rx_config(wl,
630 RX_CFG_PROMISCUOUS | RX_CFG_TSF,
631 RX_FILTER_OPTION_DEF);
632 /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
633 RX_FILTER_OPTION_FILTER_ALL); */
635 goto out_free_memmap;
637 /* PHY layer config */
638 ret = wl1271_init_phy_config(wl);
640 goto out_free_memmap;
642 ret = wl1271_acx_dco_itrim_params(wl);
644 goto out_free_memmap;
646 /* Configure TX patch complete interrupt behavior */
647 ret = wl1271_acx_tx_config_options(wl);
649 goto out_free_memmap;
651 /* RX complete interrupt pacing */
652 ret = wl1271_acx_init_rx_interrupt(wl);
654 goto out_free_memmap;
656 /* Energy detection */
657 ret = wl1271_init_energy_detection(wl);
659 goto out_free_memmap;
661 /* Default fragmentation threshold */
662 ret = wl1271_acx_frag_threshold(wl, wl->hw->wiphy->frag_threshold);
664 goto out_free_memmap;
666 /* Default TID/AC configuration */
667 BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
668 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
669 conf_ac = &wl->conf.tx.ac_conf[i];
670 ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
671 conf_ac->cw_max, conf_ac->aifsn,
672 conf_ac->tx_op_limit);
674 goto out_free_memmap;
676 conf_tid = &wl->conf.tx.tid_conf[i];
677 ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id,
678 conf_tid->channel_type,
681 conf_tid->ack_policy,
682 conf_tid->apsd_conf[0],
683 conf_tid->apsd_conf[1]);
685 goto out_free_memmap;
688 /* Enable data path */
689 ret = wl1271_cmd_data_path(wl, 1);
691 goto out_free_memmap;
693 /* Configure HW encryption */
694 ret = wl1271_acx_feature_cfg(wl);
696 goto out_free_memmap;
699 ret = wl1271_acx_pm_config(wl);
701 goto out_free_memmap;
703 /* Mode specific init - post mem init */
705 ret = wl1271_ap_hw_init_post_mem(wl);
707 ret = wl1271_sta_hw_init_post_mem(wl);
710 goto out_free_memmap;
712 /* Configure initiator BA sessions policies */
713 ret = wl1271_set_ba_policies(wl);
715 goto out_free_memmap;
720 kfree(wl->target_mem_map);
721 wl->target_mem_map = NULL;