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"
35 int wl1271_sta_init_templates_config(struct wl1271
*wl
)
39 /* send empty templates for fw memory reservation */
40 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_CFG_PROBE_REQ_2_4
, NULL
,
41 WL1271_CMD_TEMPL_MAX_SIZE
,
42 0, WL1271_RATE_AUTOMATIC
);
46 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_CFG_PROBE_REQ_5
,
47 NULL
, WL1271_CMD_TEMPL_MAX_SIZE
, 0,
48 WL1271_RATE_AUTOMATIC
);
52 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_NULL_DATA
, NULL
,
53 sizeof(struct wl12xx_null_data_template
),
54 0, WL1271_RATE_AUTOMATIC
);
58 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_PS_POLL
, NULL
,
59 sizeof(struct wl12xx_ps_poll_template
),
60 0, WL1271_RATE_AUTOMATIC
);
64 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_QOS_NULL_DATA
, NULL
,
66 (struct wl12xx_qos_null_data_template
),
67 0, WL1271_RATE_AUTOMATIC
);
71 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_PROBE_RESPONSE
, NULL
,
73 (struct wl12xx_probe_resp_template
),
74 0, WL1271_RATE_AUTOMATIC
);
78 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_BEACON
, NULL
,
80 (struct wl12xx_beacon_template
),
81 0, WL1271_RATE_AUTOMATIC
);
85 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_ARP_RSP
, NULL
,
87 (struct wl12xx_arp_rsp_template
),
88 0, WL1271_RATE_AUTOMATIC
);
92 for (i
= 0; i
< CMD_TEMPL_KLV_IDX_MAX
; i
++) {
93 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_KLV
, NULL
,
94 WL1271_CMD_TEMPL_MAX_SIZE
, i
,
95 WL1271_RATE_AUTOMATIC
);
103 static int wl1271_ap_init_deauth_template(struct wl1271
*wl
)
105 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 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_DEAUTH_AP
,
118 tmpl
, sizeof(*tmpl
), 0,
119 wl1271_tx_min_rate_get(wl
));
126 static int wl1271_ap_init_null_template(struct wl1271
*wl
)
128 struct ieee80211_hdr_3addr
*nullfunc
;
131 nullfunc
= kzalloc(sizeof(*nullfunc
), GFP_KERNEL
);
137 nullfunc
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
138 IEEE80211_STYPE_NULLFUNC
|
139 IEEE80211_FCTL_FROMDS
);
141 /* nullfunc->addr1 is filled by FW */
143 memcpy(nullfunc
->addr2
, wl
->mac_addr
, ETH_ALEN
);
144 memcpy(nullfunc
->addr3
, wl
->mac_addr
, ETH_ALEN
);
146 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_NULL_DATA
, nullfunc
,
147 sizeof(*nullfunc
), 0,
148 wl1271_tx_min_rate_get(wl
));
155 static int wl1271_ap_init_qos_null_template(struct wl1271
*wl
)
157 struct ieee80211_qos_hdr
*qosnull
;
160 qosnull
= kzalloc(sizeof(*qosnull
), GFP_KERNEL
);
166 qosnull
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
167 IEEE80211_STYPE_QOS_NULLFUNC
|
168 IEEE80211_FCTL_FROMDS
);
170 /* qosnull->addr1 is filled by FW */
172 memcpy(qosnull
->addr2
, wl
->mac_addr
, ETH_ALEN
);
173 memcpy(qosnull
->addr3
, wl
->mac_addr
, ETH_ALEN
);
175 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_QOS_NULL_DATA
, qosnull
,
177 wl1271_tx_min_rate_get(wl
));
184 static int wl1271_ap_init_templates_config(struct wl1271
*wl
)
189 * Put very large empty placeholders for all templates. These
190 * reserve memory for later.
192 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_AP_PROBE_RESPONSE
, NULL
,
194 (struct wl12xx_probe_resp_template
),
195 0, WL1271_RATE_AUTOMATIC
);
199 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_AP_BEACON
, NULL
,
201 (struct wl12xx_beacon_template
),
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 wl1271_init_rx_config(struct wl1271
*wl
, u32 config
, u32 filter
)
233 ret
= wl1271_acx_rx_msdu_life_time(wl
);
237 ret
= wl1271_acx_rx_config(wl
, config
, filter
);
244 int wl1271_init_phy_config(struct wl1271
*wl
)
248 ret
= wl1271_acx_pd_threshold(wl
);
252 ret
= wl1271_acx_slot(wl
, DEFAULT_SLOT_TIME
);
256 ret
= wl1271_acx_service_period_timeout(wl
);
260 ret
= wl1271_acx_rts_threshold(wl
, wl
->conf
.rx
.rts_threshold
);
267 static int wl1271_init_beacon_filter(struct wl1271
*wl
)
271 /* disable beacon filtering at this stage */
272 ret
= wl1271_acx_beacon_filter_opt(wl
, false);
276 ret
= wl1271_acx_beacon_filter_table(wl
);
283 int wl1271_init_pta(struct wl1271
*wl
)
287 ret
= wl1271_acx_sg_cfg(wl
);
291 ret
= wl1271_acx_sg_enable(wl
, wl
->sg_enabled
);
298 int wl1271_init_energy_detection(struct wl1271
*wl
)
302 ret
= wl1271_acx_cca_threshold(wl
);
309 static int wl1271_init_beacon_broadcast(struct wl1271
*wl
)
313 ret
= wl1271_acx_bcn_dtim_options(wl
);
320 static int wl1271_sta_hw_init(struct wl1271
*wl
)
324 ret
= wl1271_cmd_ext_radio_parms(wl
);
329 ret
= wl1271_acx_config_ps(wl
);
333 ret
= wl1271_sta_init_templates_config(wl
);
337 ret
= wl1271_acx_group_address_tbl(wl
, true, NULL
, 0);
341 /* Initialize connection monitoring thresholds */
342 ret
= wl1271_acx_conn_monit_params(wl
, false);
346 /* Beacon filtering */
347 ret
= wl1271_init_beacon_filter(wl
);
351 /* Bluetooth WLAN coexistence */
352 ret
= wl1271_init_pta(wl
);
356 /* Beacons and broadcast settings */
357 ret
= wl1271_init_beacon_broadcast(wl
);
361 /* Configure for ELP power saving */
362 ret
= wl1271_acx_sleep_auth(wl
, WL1271_PSM_ELP
);
366 /* Configure rssi/snr averaging weights */
367 ret
= wl1271_acx_rssi_snr_avg_weights(wl
);
371 ret
= wl1271_acx_sta_rate_policies(wl
);
375 ret
= wl1271_acx_sta_mem_cfg(wl
);
382 static int wl1271_sta_hw_init_post_mem(struct wl1271
*wl
)
386 ret
= wl1271_cmd_set_sta_default_wep_key(wl
, wl
->default_key
);
388 wl1271_warning("couldn't set default key");
392 /* disable all keep-alive templates */
393 for (i
= 0; i
< CMD_TEMPL_KLV_IDX_MAX
; i
++) {
394 ret
= wl1271_acx_keep_alive_config(wl
, i
,
395 ACX_KEEP_ALIVE_TPL_INVALID
);
400 /* disable the keep-alive feature */
401 ret
= wl1271_acx_keep_alive_mode(wl
, false);
408 static int wl1271_ap_hw_init(struct wl1271
*wl
)
412 ret
= wl1271_ap_init_templates_config(wl
);
416 /* Configure for power always on */
417 ret
= wl1271_acx_sleep_auth(wl
, WL1271_PSM_CAM
);
421 /* Configure initial TX rate classes */
422 for (i
= 0; i
< wl
->conf
.tx
.ac_conf_count
; i
++) {
423 ret
= wl1271_acx_ap_rate_policy(wl
,
424 &wl
->conf
.tx
.ap_rc_conf
[i
], i
);
429 ret
= wl1271_acx_ap_rate_policy(wl
,
430 &wl
->conf
.tx
.ap_mgmt_conf
,
431 ACX_TX_AP_MODE_MGMT_RATE
);
435 ret
= wl1271_acx_ap_rate_policy(wl
,
436 &wl
->conf
.tx
.ap_bcst_conf
,
437 ACX_TX_AP_MODE_BCST_RATE
);
441 ret
= wl1271_acx_max_tx_retry(wl
);
445 ret
= wl1271_acx_ap_mem_cfg(wl
);
452 static int wl1271_ap_hw_init_post_mem(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
);
471 static void wl1271_check_ba_support(struct wl1271
*wl
)
473 /* validate FW cose ver x.x.x.50-60.x */
474 if ((wl
->chip
.fw_ver
[3] >= WL12XX_BA_SUPPORT_FW_COST_VER2_START
) &&
475 (wl
->chip
.fw_ver
[3] < WL12XX_BA_SUPPORT_FW_COST_VER2_END
)) {
476 wl
->ba_support
= true;
480 wl
->ba_support
= false;
483 static int wl1271_set_ba_policies(struct wl1271
*wl
)
488 /* Reset the BA RX indicators */
489 wl
->ba_rx_bitmap
= 0;
491 /* validate that FW support BA */
492 wl1271_check_ba_support(wl
);
495 /* 802.11n initiator BA session setting */
496 for (tid_index
= 0; tid_index
< CONF_TX_MAX_TID_COUNT
;
498 ret
= wl1271_acx_set_ba_session(wl
, WLAN_BACK_INITIATOR
,
507 int wl1271_hw_init(struct wl1271
*wl
)
509 struct conf_tx_ac_category
*conf_ac
;
510 struct conf_tx_tid
*conf_tid
;
512 bool is_ap
= (wl
->bss_type
== BSS_TYPE_AP_BSS
);
514 ret
= wl1271_cmd_general_parms(wl
);
518 ret
= wl1271_cmd_radio_parms(wl
);
522 /* Mode specific init */
524 ret
= wl1271_ap_hw_init(wl
);
526 ret
= wl1271_sta_hw_init(wl
);
531 /* Default memory configuration */
532 ret
= wl1271_acx_init_mem_config(wl
);
537 ret
= wl1271_init_rx_config(wl
,
538 RX_CFG_PROMISCUOUS
| RX_CFG_TSF
,
539 RX_FILTER_OPTION_DEF
);
540 /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
541 RX_FILTER_OPTION_FILTER_ALL); */
543 goto out_free_memmap
;
545 /* PHY layer config */
546 ret
= wl1271_init_phy_config(wl
);
548 goto out_free_memmap
;
550 ret
= wl1271_acx_dco_itrim_params(wl
);
552 goto out_free_memmap
;
554 /* Configure TX patch complete interrupt behavior */
555 ret
= wl1271_acx_tx_config_options(wl
);
557 goto out_free_memmap
;
559 /* RX complete interrupt pacing */
560 ret
= wl1271_acx_init_rx_interrupt(wl
);
562 goto out_free_memmap
;
564 /* Energy detection */
565 ret
= wl1271_init_energy_detection(wl
);
567 goto out_free_memmap
;
569 /* Default fragmentation threshold */
570 ret
= wl1271_acx_frag_threshold(wl
, wl
->conf
.tx
.frag_threshold
);
572 goto out_free_memmap
;
574 /* Default TID/AC configuration */
575 BUG_ON(wl
->conf
.tx
.tid_conf_count
!= wl
->conf
.tx
.ac_conf_count
);
576 for (i
= 0; i
< wl
->conf
.tx
.tid_conf_count
; i
++) {
577 conf_ac
= &wl
->conf
.tx
.ac_conf
[i
];
578 ret
= wl1271_acx_ac_cfg(wl
, conf_ac
->ac
, conf_ac
->cw_min
,
579 conf_ac
->cw_max
, conf_ac
->aifsn
,
580 conf_ac
->tx_op_limit
);
582 goto out_free_memmap
;
584 conf_tid
= &wl
->conf
.tx
.tid_conf
[i
];
585 ret
= wl1271_acx_tid_cfg(wl
, conf_tid
->queue_id
,
586 conf_tid
->channel_type
,
589 conf_tid
->ack_policy
,
590 conf_tid
->apsd_conf
[0],
591 conf_tid
->apsd_conf
[1]);
593 goto out_free_memmap
;
596 /* Enable data path */
597 ret
= wl1271_cmd_data_path(wl
, 1);
599 goto out_free_memmap
;
601 /* Configure HW encryption */
602 ret
= wl1271_acx_feature_cfg(wl
);
604 goto out_free_memmap
;
607 ret
= wl1271_acx_pm_config(wl
);
609 goto out_free_memmap
;
611 /* Mode specific init - post mem init */
613 ret
= wl1271_ap_hw_init_post_mem(wl
);
615 ret
= wl1271_sta_hw_init_post_mem(wl
);
618 goto out_free_memmap
;
620 /* Configure initiator BA sessions policies */
621 ret
= wl1271_set_ba_policies(wl
);
623 goto out_free_memmap
;
628 kfree(wl
->target_mem_map
);
629 wl
->target_mem_map
= NULL
;