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)
42 /* send empty templates for fw memory reservation */
43 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
44 CMD_TEMPL_CFG_PROBE_REQ_2_4, NULL,
45 WL1271_CMD_TEMPL_MAX_SIZE,
46 0, WL1271_RATE_AUTOMATIC);
50 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
51 CMD_TEMPL_CFG_PROBE_REQ_5,
52 NULL, WL1271_CMD_TEMPL_MAX_SIZE, 0,
53 WL1271_RATE_AUTOMATIC);
57 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
58 CMD_TEMPL_NULL_DATA, NULL,
59 sizeof(struct wl12xx_null_data_template),
60 0, WL1271_RATE_AUTOMATIC);
64 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
65 CMD_TEMPL_PS_POLL, NULL,
66 sizeof(struct wl12xx_ps_poll_template),
67 0, WL1271_RATE_AUTOMATIC);
71 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
72 CMD_TEMPL_QOS_NULL_DATA, NULL,
74 (struct ieee80211_qos_hdr),
75 0, WL1271_RATE_AUTOMATIC);
79 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
80 CMD_TEMPL_PROBE_RESPONSE, NULL,
81 WL1271_CMD_TEMPL_DFLT_SIZE,
82 0, WL1271_RATE_AUTOMATIC);
86 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
87 CMD_TEMPL_BEACON, NULL,
88 WL1271_CMD_TEMPL_DFLT_SIZE,
89 0, WL1271_RATE_AUTOMATIC);
93 max_size = sizeof(struct wl12xx_arp_rsp_template) +
94 WL1271_EXTRA_SPACE_MAX;
95 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
96 CMD_TEMPL_ARP_RSP, NULL,
98 0, WL1271_RATE_AUTOMATIC);
103 * Put very large empty placeholders for all templates. These
104 * reserve memory for later.
106 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
107 CMD_TEMPL_AP_PROBE_RESPONSE, NULL,
108 WL1271_CMD_TEMPL_MAX_SIZE,
109 0, WL1271_RATE_AUTOMATIC);
113 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
114 CMD_TEMPL_AP_BEACON, NULL,
115 WL1271_CMD_TEMPL_MAX_SIZE,
116 0, WL1271_RATE_AUTOMATIC);
120 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
121 CMD_TEMPL_DEAUTH_AP, NULL,
123 (struct wl12xx_disconn_template),
124 0, WL1271_RATE_AUTOMATIC);
128 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
129 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
131 sizeof(struct ieee80211_qos_hdr),
132 i, WL1271_RATE_AUTOMATIC);
140 static int wl1271_ap_init_deauth_template(struct wl1271 *wl,
141 struct wl12xx_vif *wlvif)
143 struct wl12xx_disconn_template *tmpl;
147 tmpl = kzalloc(sizeof(*tmpl), GFP_KERNEL);
153 tmpl->header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT |
154 IEEE80211_STYPE_DEAUTH);
156 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
157 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
159 tmpl, sizeof(*tmpl), 0, rate);
166 static int wl1271_ap_init_null_template(struct wl1271 *wl,
167 struct ieee80211_vif *vif)
169 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
170 struct ieee80211_hdr_3addr *nullfunc;
174 nullfunc = kzalloc(sizeof(*nullfunc), GFP_KERNEL);
180 nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
181 IEEE80211_STYPE_NULLFUNC |
182 IEEE80211_FCTL_FROMDS);
184 /* nullfunc->addr1 is filled by FW */
186 memcpy(nullfunc->addr2, vif->addr, ETH_ALEN);
187 memcpy(nullfunc->addr3, vif->addr, ETH_ALEN);
189 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
190 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
191 CMD_TEMPL_NULL_DATA, nullfunc,
192 sizeof(*nullfunc), 0, rate);
199 static int wl1271_ap_init_qos_null_template(struct wl1271 *wl,
200 struct ieee80211_vif *vif)
202 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
203 struct ieee80211_qos_hdr *qosnull;
207 qosnull = kzalloc(sizeof(*qosnull), GFP_KERNEL);
213 qosnull->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
214 IEEE80211_STYPE_QOS_NULLFUNC |
215 IEEE80211_FCTL_FROMDS);
217 /* qosnull->addr1 is filled by FW */
219 memcpy(qosnull->addr2, vif->addr, ETH_ALEN);
220 memcpy(qosnull->addr3, vif->addr, ETH_ALEN);
222 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
223 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
224 CMD_TEMPL_QOS_NULL_DATA, qosnull,
225 sizeof(*qosnull), 0, rate);
232 static int wl12xx_init_rx_config(struct wl1271 *wl)
236 ret = wl1271_acx_rx_msdu_life_time(wl);
243 static int wl12xx_init_phy_vif_config(struct wl1271 *wl,
244 struct wl12xx_vif *wlvif)
248 ret = wl1271_acx_slot(wl, wlvif, DEFAULT_SLOT_TIME);
252 ret = wl1271_acx_service_period_timeout(wl, wlvif);
256 ret = wl1271_acx_rts_threshold(wl, wlvif, wl->hw->wiphy->rts_threshold);
263 static int wl1271_init_sta_beacon_filter(struct wl1271 *wl,
264 struct wl12xx_vif *wlvif)
268 ret = wl1271_acx_beacon_filter_table(wl, wlvif);
272 /* enable beacon filtering */
273 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true);
280 int wl1271_init_pta(struct wl1271 *wl)
284 ret = wl12xx_acx_sg_cfg(wl);
288 ret = wl1271_acx_sg_enable(wl, wl->sg_enabled);
295 int wl1271_init_energy_detection(struct wl1271 *wl)
299 ret = wl1271_acx_cca_threshold(wl);
306 static int wl1271_init_beacon_broadcast(struct wl1271 *wl,
307 struct wl12xx_vif *wlvif)
311 ret = wl1271_acx_bcn_dtim_options(wl, wlvif);
318 static int wl12xx_init_fwlog(struct wl1271 *wl)
322 if (wl->quirks & WLCORE_QUIRK_FWLOG_NOT_IMPLEMENTED)
325 ret = wl12xx_cmd_config_fwlog(wl);
332 /* generic sta initialization (non vif-specific) */
333 static int wl1271_sta_hw_init(struct wl1271 *wl, struct wl12xx_vif *wlvif)
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 /* get extra MIMO or wide-chan rates where the HW supports it */
464 supported_rates |= wlcore_hw_ap_get_mimo_wide_rate_mask(wl, wlvif);
466 /* configure unicast TX rate classes */
467 for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
468 rc.enabled_rates = supported_rates;
469 rc.short_retry_limit = 10;
470 rc.long_retry_limit = 10;
472 ret = wl1271_acx_ap_rate_policy(wl, &rc,
473 wlvif->ap.ucast_rate_idx[i]);
481 static int wl1271_set_ba_policies(struct wl1271 *wl, struct wl12xx_vif *wlvif)
483 /* Reset the BA RX indicators */
484 wlvif->ba_allowed = true;
485 wl->ba_rx_session_count = 0;
487 /* BA is supported in STA/AP modes */
488 if (wlvif->bss_type != BSS_TYPE_AP_BSS &&
489 wlvif->bss_type != BSS_TYPE_STA_BSS) {
490 wlvif->ba_support = false;
494 wlvif->ba_support = true;
496 /* 802.11n initiator BA session setting */
497 return wl12xx_acx_set_ba_initiator_policy(wl, wlvif);
500 /* vif-specifc initialization */
501 static int wl12xx_init_sta_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
505 ret = wl1271_acx_group_address_tbl(wl, wlvif, true, NULL, 0);
509 /* Initialize connection monitoring thresholds */
510 ret = wl1271_acx_conn_monit_params(wl, wlvif, false);
514 /* Beacon filtering */
515 ret = wl1271_init_sta_beacon_filter(wl, wlvif);
519 /* Beacons and broadcast settings */
520 ret = wl1271_init_beacon_broadcast(wl, wlvif);
524 /* Configure rssi/snr averaging weights */
525 ret = wl1271_acx_rssi_snr_avg_weights(wl, wlvif);
532 /* vif-specific intialization */
533 static int wl12xx_init_ap_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
537 ret = wl1271_acx_ap_max_tx_retry(wl, wlvif);
541 /* initialize Tx power */
542 ret = wl1271_acx_tx_power(wl, wlvif, wlvif->power_level);
549 int wl1271_init_vif_specific(struct wl1271 *wl, struct ieee80211_vif *vif)
551 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
552 struct conf_tx_ac_category *conf_ac;
553 struct conf_tx_tid *conf_tid;
554 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
557 /* consider all existing roles before configuring psm. */
559 if (wl->ap_count == 0 && is_ap) { /* first AP */
560 /* Configure for power always on */
561 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
564 /* first STA, no APs */
565 } else if (wl->sta_count == 0 && wl->ap_count == 0 && !is_ap) {
566 u8 sta_auth = wl->conf.conn.sta_sleep_auth;
567 /* Configure for power according to debugfs */
568 if (sta_auth != WL1271_PSM_ILLEGAL)
569 ret = wl1271_acx_sleep_auth(wl, sta_auth);
570 /* Configure for power always on */
571 else if (wl->quirks & WLCORE_QUIRK_NO_ELP)
572 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
573 /* Configure for ELP power saving */
575 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
581 /* Mode specific init */
583 ret = wl1271_ap_hw_init(wl, wlvif);
587 ret = wl12xx_init_ap_role(wl, wlvif);
591 ret = wl1271_sta_hw_init(wl, wlvif);
595 ret = wl12xx_init_sta_role(wl, wlvif);
600 wl12xx_init_phy_vif_config(wl, wlvif);
602 /* Default TID/AC configuration */
603 BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
604 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
605 conf_ac = &wl->conf.tx.ac_conf[i];
606 ret = wl1271_acx_ac_cfg(wl, wlvif, conf_ac->ac,
607 conf_ac->cw_min, conf_ac->cw_max,
608 conf_ac->aifsn, conf_ac->tx_op_limit);
612 conf_tid = &wl->conf.tx.tid_conf[i];
613 ret = wl1271_acx_tid_cfg(wl, wlvif,
615 conf_tid->channel_type,
618 conf_tid->ack_policy,
619 conf_tid->apsd_conf[0],
620 conf_tid->apsd_conf[1]);
625 /* Configure HW encryption */
626 ret = wl1271_acx_feature_cfg(wl, wlvif);
630 /* Mode specific init - post mem init */
632 ret = wl1271_ap_hw_init_post_mem(wl, vif);
634 ret = wl1271_sta_hw_init_post_mem(wl, vif);
639 /* Configure initiator BA sessions policies */
640 ret = wl1271_set_ba_policies(wl, wlvif);
644 ret = wlcore_hw_init_vif(wl, wlvif);
651 int wl1271_hw_init(struct wl1271 *wl)
655 /* Chip-specific hw init */
656 ret = wl->ops->hw_init(wl);
661 ret = wl1271_init_templates_config(wl);
665 ret = wl12xx_acx_mem_cfg(wl);
669 /* Configure the FW logger */
670 ret = wl12xx_init_fwlog(wl);
674 /* Bluetooth WLAN coexistence */
675 ret = wl1271_init_pta(wl);
679 /* Default memory configuration */
680 ret = wl1271_acx_init_mem_config(wl);
685 ret = wl12xx_init_rx_config(wl);
687 goto out_free_memmap;
689 ret = wl1271_acx_dco_itrim_params(wl);
691 goto out_free_memmap;
693 /* Configure TX patch complete interrupt behavior */
694 ret = wl1271_acx_tx_config_options(wl);
696 goto out_free_memmap;
698 /* RX complete interrupt pacing */
699 ret = wl1271_acx_init_rx_interrupt(wl);
701 goto out_free_memmap;
703 /* Energy detection */
704 ret = wl1271_init_energy_detection(wl);
706 goto out_free_memmap;
708 /* Default fragmentation threshold */
709 ret = wl1271_acx_frag_threshold(wl, wl->hw->wiphy->frag_threshold);
711 goto out_free_memmap;
713 /* Enable data path */
714 ret = wl1271_cmd_data_path(wl, 1);
716 goto out_free_memmap;
719 ret = wl1271_acx_pm_config(wl);
721 goto out_free_memmap;
723 ret = wl12xx_acx_set_rate_mgmt_params(wl);
725 goto out_free_memmap;
727 /* configure hangover */
728 ret = wl12xx_acx_config_hangover(wl);
730 goto out_free_memmap;
735 kfree(wl->target_mem_map);
736 wl->target_mem_map = NULL;