1 // SPDX-License-Identifier: GPL-2.0-only
3 * This file is part of wl1271
5 * Copyright (C) 2009 Nokia Corporation
7 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/slab.h>
16 #include "wl12xx_80211.h"
23 int wl1271_init_templates_config(struct wl1271
*wl
)
28 /* send empty templates for fw memory reservation */
29 ret
= wl1271_cmd_template_set(wl
, WL12XX_INVALID_ROLE_ID
,
30 wl
->scan_templ_id_2_4
, NULL
,
31 WL1271_CMD_TEMPL_MAX_SIZE
,
32 0, WL1271_RATE_AUTOMATIC
);
36 ret
= wl1271_cmd_template_set(wl
, WL12XX_INVALID_ROLE_ID
,
38 NULL
, WL1271_CMD_TEMPL_MAX_SIZE
, 0,
39 WL1271_RATE_AUTOMATIC
);
43 if (wl
->quirks
& WLCORE_QUIRK_DUAL_PROBE_TMPL
) {
44 ret
= wl1271_cmd_template_set(wl
, WL12XX_INVALID_ROLE_ID
,
45 wl
->sched_scan_templ_id_2_4
,
47 WL1271_CMD_TEMPL_MAX_SIZE
,
48 0, WL1271_RATE_AUTOMATIC
);
52 ret
= wl1271_cmd_template_set(wl
, WL12XX_INVALID_ROLE_ID
,
53 wl
->sched_scan_templ_id_5
,
55 WL1271_CMD_TEMPL_MAX_SIZE
,
56 0, WL1271_RATE_AUTOMATIC
);
61 ret
= wl1271_cmd_template_set(wl
, WL12XX_INVALID_ROLE_ID
,
62 CMD_TEMPL_NULL_DATA
, NULL
,
63 sizeof(struct wl12xx_null_data_template
),
64 0, WL1271_RATE_AUTOMATIC
);
68 ret
= wl1271_cmd_template_set(wl
, WL12XX_INVALID_ROLE_ID
,
69 CMD_TEMPL_PS_POLL
, NULL
,
70 sizeof(struct wl12xx_ps_poll_template
),
71 0, WL1271_RATE_AUTOMATIC
);
75 ret
= wl1271_cmd_template_set(wl
, WL12XX_INVALID_ROLE_ID
,
76 CMD_TEMPL_QOS_NULL_DATA
, NULL
,
78 (struct ieee80211_qos_hdr
),
79 0, WL1271_RATE_AUTOMATIC
);
83 ret
= wl1271_cmd_template_set(wl
, WL12XX_INVALID_ROLE_ID
,
84 CMD_TEMPL_PROBE_RESPONSE
, NULL
,
85 WL1271_CMD_TEMPL_DFLT_SIZE
,
86 0, WL1271_RATE_AUTOMATIC
);
90 ret
= wl1271_cmd_template_set(wl
, WL12XX_INVALID_ROLE_ID
,
91 CMD_TEMPL_BEACON
, NULL
,
92 WL1271_CMD_TEMPL_DFLT_SIZE
,
93 0, WL1271_RATE_AUTOMATIC
);
97 max_size
= sizeof(struct wl12xx_arp_rsp_template
) +
98 WL1271_EXTRA_SPACE_MAX
;
99 ret
= wl1271_cmd_template_set(wl
, WL12XX_INVALID_ROLE_ID
,
100 CMD_TEMPL_ARP_RSP
, NULL
,
102 0, WL1271_RATE_AUTOMATIC
);
107 * Put very large empty placeholders for all templates. These
108 * reserve memory for later.
110 ret
= wl1271_cmd_template_set(wl
, WL12XX_INVALID_ROLE_ID
,
111 CMD_TEMPL_AP_PROBE_RESPONSE
, NULL
,
112 WL1271_CMD_TEMPL_MAX_SIZE
,
113 0, WL1271_RATE_AUTOMATIC
);
117 ret
= wl1271_cmd_template_set(wl
, WL12XX_INVALID_ROLE_ID
,
118 CMD_TEMPL_AP_BEACON
, NULL
,
119 WL1271_CMD_TEMPL_MAX_SIZE
,
120 0, WL1271_RATE_AUTOMATIC
);
124 ret
= wl1271_cmd_template_set(wl
, WL12XX_INVALID_ROLE_ID
,
125 CMD_TEMPL_DEAUTH_AP
, NULL
,
127 (struct wl12xx_disconn_template
),
128 0, WL1271_RATE_AUTOMATIC
);
132 for (i
= 0; i
< WLCORE_MAX_KLV_TEMPLATES
; i
++) {
133 ret
= wl1271_cmd_template_set(wl
, WL12XX_INVALID_ROLE_ID
,
135 sizeof(struct ieee80211_qos_hdr
),
136 i
, WL1271_RATE_AUTOMATIC
);
144 static int wl1271_ap_init_deauth_template(struct wl1271
*wl
,
145 struct wl12xx_vif
*wlvif
)
147 struct wl12xx_disconn_template
*tmpl
;
151 tmpl
= kzalloc(sizeof(*tmpl
), GFP_KERNEL
);
157 tmpl
->header
.frame_ctl
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
158 IEEE80211_STYPE_DEAUTH
);
160 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->basic_rate_set
);
161 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
163 tmpl
, sizeof(*tmpl
), 0, rate
);
170 static int wl1271_ap_init_null_template(struct wl1271
*wl
,
171 struct ieee80211_vif
*vif
)
173 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
174 struct ieee80211_hdr_3addr
*nullfunc
;
178 nullfunc
= kzalloc(sizeof(*nullfunc
), GFP_KERNEL
);
184 nullfunc
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
185 IEEE80211_STYPE_NULLFUNC
|
186 IEEE80211_FCTL_FROMDS
);
188 /* nullfunc->addr1 is filled by FW */
190 memcpy(nullfunc
->addr2
, vif
->addr
, ETH_ALEN
);
191 memcpy(nullfunc
->addr3
, vif
->addr
, ETH_ALEN
);
193 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->basic_rate_set
);
194 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
195 CMD_TEMPL_NULL_DATA
, nullfunc
,
196 sizeof(*nullfunc
), 0, rate
);
203 static int wl1271_ap_init_qos_null_template(struct wl1271
*wl
,
204 struct ieee80211_vif
*vif
)
206 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
207 struct ieee80211_qos_hdr
*qosnull
;
211 qosnull
= kzalloc(sizeof(*qosnull
), GFP_KERNEL
);
217 qosnull
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
218 IEEE80211_STYPE_QOS_NULLFUNC
|
219 IEEE80211_FCTL_FROMDS
);
221 /* qosnull->addr1 is filled by FW */
223 memcpy(qosnull
->addr2
, vif
->addr
, ETH_ALEN
);
224 memcpy(qosnull
->addr3
, vif
->addr
, ETH_ALEN
);
226 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->basic_rate_set
);
227 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
228 CMD_TEMPL_QOS_NULL_DATA
, qosnull
,
229 sizeof(*qosnull
), 0, rate
);
236 static int wl12xx_init_rx_config(struct wl1271
*wl
)
240 ret
= wl1271_acx_rx_msdu_life_time(wl
);
247 static int wl12xx_init_phy_vif_config(struct wl1271
*wl
,
248 struct wl12xx_vif
*wlvif
)
252 ret
= wl1271_acx_slot(wl
, wlvif
, DEFAULT_SLOT_TIME
);
256 ret
= wl1271_acx_service_period_timeout(wl
, wlvif
);
260 ret
= wl1271_acx_rts_threshold(wl
, wlvif
, wl
->hw
->wiphy
->rts_threshold
);
267 static int wl1271_init_sta_beacon_filter(struct wl1271
*wl
,
268 struct wl12xx_vif
*wlvif
)
272 ret
= wl1271_acx_beacon_filter_table(wl
, wlvif
);
276 /* disable beacon filtering until we get the first beacon */
277 ret
= wl1271_acx_beacon_filter_opt(wl
, wlvif
, false);
284 int wl1271_init_pta(struct wl1271
*wl
)
288 ret
= wl12xx_acx_sg_cfg(wl
);
292 ret
= wl1271_acx_sg_enable(wl
, wl
->sg_enabled
);
299 int wl1271_init_energy_detection(struct wl1271
*wl
)
303 ret
= wl1271_acx_cca_threshold(wl
);
310 static int wl1271_init_beacon_broadcast(struct wl1271
*wl
,
311 struct wl12xx_vif
*wlvif
)
315 ret
= wl1271_acx_bcn_dtim_options(wl
, wlvif
);
322 static int wl12xx_init_fwlog(struct wl1271
*wl
)
326 if (wl
->quirks
& WLCORE_QUIRK_FWLOG_NOT_IMPLEMENTED
)
329 ret
= wl12xx_cmd_config_fwlog(wl
);
336 /* generic sta initialization (non vif-specific) */
337 int wl1271_sta_hw_init(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
342 ret
= wl12xx_acx_config_ps(wl
, wlvif
);
346 /* FM WLAN coexistence */
347 ret
= wl1271_acx_fm_coex(wl
);
351 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
358 static int wl1271_sta_hw_init_post_mem(struct wl1271
*wl
,
359 struct ieee80211_vif
*vif
)
361 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
364 /* disable the keep-alive feature */
365 ret
= wl1271_acx_keep_alive_mode(wl
, wlvif
, false);
372 /* generic ap initialization (non vif-specific) */
373 static int wl1271_ap_hw_init(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
377 ret
= wl1271_init_ap_rates(wl
, wlvif
);
381 /* configure AP sleep, if enabled */
382 ret
= wlcore_hw_ap_sleep(wl
);
389 int wl1271_ap_init_templates(struct wl1271
*wl
, struct ieee80211_vif
*vif
)
391 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
394 ret
= wl1271_ap_init_deauth_template(wl
, wlvif
);
398 ret
= wl1271_ap_init_null_template(wl
, vif
);
402 ret
= wl1271_ap_init_qos_null_template(wl
, vif
);
407 * when operating as AP we want to receive external beacons for
408 * configuring ERP protection.
410 ret
= wl1271_acx_beacon_filter_opt(wl
, wlvif
, false);
417 static int wl1271_ap_hw_init_post_mem(struct wl1271
*wl
,
418 struct ieee80211_vif
*vif
)
420 return wl1271_ap_init_templates(wl
, vif
);
423 int wl1271_init_ap_rates(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
426 struct conf_tx_rate_class rc
;
429 wl1271_debug(DEBUG_AP
, "AP basic rate set: 0x%x",
430 wlvif
->basic_rate_set
);
432 if (wlvif
->basic_rate_set
== 0)
435 rc
.enabled_rates
= wlvif
->basic_rate_set
;
436 rc
.long_retry_limit
= 10;
437 rc
.short_retry_limit
= 10;
439 ret
= wl1271_acx_ap_rate_policy(wl
, &rc
, wlvif
->ap
.mgmt_rate_idx
);
443 /* use the min basic rate for AP broadcast/multicast */
444 rc
.enabled_rates
= wl1271_tx_min_rate_get(wl
, wlvif
->basic_rate_set
);
445 rc
.short_retry_limit
= 10;
446 rc
.long_retry_limit
= 10;
448 ret
= wl1271_acx_ap_rate_policy(wl
, &rc
, wlvif
->ap
.bcast_rate_idx
);
453 * If the basic rates contain OFDM rates, use OFDM only
454 * rates for unicast TX as well. Else use all supported rates.
456 if (wl
->ofdm_only_ap
&& (wlvif
->basic_rate_set
& CONF_TX_OFDM_RATES
))
457 supported_rates
= CONF_TX_OFDM_RATES
;
459 supported_rates
= CONF_TX_ENABLED_RATES
;
461 /* unconditionally enable HT rates */
462 supported_rates
|= CONF_TX_MCS_RATES
;
464 /* get extra MIMO or wide-chan rates where the HW supports it */
465 supported_rates
|= wlcore_hw_ap_get_mimo_wide_rate_mask(wl
, wlvif
);
467 /* configure unicast TX rate classes */
468 for (i
= 0; i
< wl
->conf
.tx
.ac_conf_count
; i
++) {
469 rc
.enabled_rates
= supported_rates
;
470 rc
.short_retry_limit
= 10;
471 rc
.long_retry_limit
= 10;
473 ret
= wl1271_acx_ap_rate_policy(wl
, &rc
,
474 wlvif
->ap
.ucast_rate_idx
[i
]);
482 static int wl1271_set_ba_policies(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
484 /* Reset the BA RX indicators */
485 wlvif
->ba_allowed
= true;
486 wl
->ba_rx_session_count
= 0;
488 /* BA is supported in STA/AP modes */
489 if (wlvif
->bss_type
!= BSS_TYPE_AP_BSS
&&
490 wlvif
->bss_type
!= BSS_TYPE_STA_BSS
) {
491 wlvif
->ba_support
= false;
495 wlvif
->ba_support
= true;
497 /* 802.11n initiator BA session setting */
498 return wl12xx_acx_set_ba_initiator_policy(wl
, wlvif
);
501 /* vif-specifc initialization */
502 static int wl12xx_init_sta_role(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
506 ret
= wl1271_acx_group_address_tbl(wl
, wlvif
, true, NULL
, 0);
510 /* Initialize connection monitoring thresholds */
511 ret
= wl1271_acx_conn_monit_params(wl
, wlvif
, false);
515 /* Beacon filtering */
516 ret
= wl1271_init_sta_beacon_filter(wl
, wlvif
);
520 /* Beacons and broadcast settings */
521 ret
= wl1271_init_beacon_broadcast(wl
, wlvif
);
525 /* Configure rssi/snr averaging weights */
526 ret
= wl1271_acx_rssi_snr_avg_weights(wl
, wlvif
);
533 /* vif-specific initialization */
534 static int wl12xx_init_ap_role(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
538 ret
= wl1271_acx_ap_max_tx_retry(wl
, wlvif
);
542 /* initialize Tx power */
543 ret
= wl1271_acx_tx_power(wl
, wlvif
, wlvif
->power_level
);
547 if (wl
->radar_debug_mode
)
548 wlcore_cmd_generic_cfg(wl
, wlvif
,
549 WLCORE_CFG_FEATURE_RADAR_DEBUG
,
550 wl
->radar_debug_mode
, 0);
555 int wl1271_init_vif_specific(struct wl1271
*wl
, struct ieee80211_vif
*vif
)
557 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
558 struct conf_tx_ac_category
*conf_ac
;
559 struct conf_tx_tid
*conf_tid
;
560 bool is_ap
= (wlvif
->bss_type
== BSS_TYPE_AP_BSS
);
563 /* consider all existing roles before configuring psm. */
565 if (wl
->ap_count
== 0 && is_ap
) { /* first AP */
566 ret
= wl1271_acx_sleep_auth(wl
, WL1271_PSM_ELP
);
570 /* unmask ap events */
571 wl
->event_mask
|= wl
->ap_event_mask
;
572 ret
= wl1271_event_unmask(wl
);
575 /* first STA, no APs */
576 } else if (wl
->sta_count
== 0 && wl
->ap_count
== 0 && !is_ap
) {
577 u8 sta_auth
= wl
->conf
.conn
.sta_sleep_auth
;
578 /* Configure for power according to debugfs */
579 if (sta_auth
!= WL1271_PSM_ILLEGAL
)
580 ret
= wl1271_acx_sleep_auth(wl
, sta_auth
);
581 /* Configure for ELP power saving */
583 ret
= wl1271_acx_sleep_auth(wl
, WL1271_PSM_ELP
);
589 /* Mode specific init */
591 ret
= wl1271_ap_hw_init(wl
, wlvif
);
595 ret
= wl12xx_init_ap_role(wl
, wlvif
);
599 ret
= wl1271_sta_hw_init(wl
, wlvif
);
603 ret
= wl12xx_init_sta_role(wl
, wlvif
);
608 wl12xx_init_phy_vif_config(wl
, wlvif
);
610 /* Default TID/AC configuration */
611 BUG_ON(wl
->conf
.tx
.tid_conf_count
!= wl
->conf
.tx
.ac_conf_count
);
612 for (i
= 0; i
< wl
->conf
.tx
.tid_conf_count
; i
++) {
613 conf_ac
= &wl
->conf
.tx
.ac_conf
[i
];
614 ret
= wl1271_acx_ac_cfg(wl
, wlvif
, conf_ac
->ac
,
615 conf_ac
->cw_min
, conf_ac
->cw_max
,
616 conf_ac
->aifsn
, conf_ac
->tx_op_limit
);
620 conf_tid
= &wl
->conf
.tx
.tid_conf
[i
];
621 ret
= wl1271_acx_tid_cfg(wl
, wlvif
,
623 conf_tid
->channel_type
,
626 conf_tid
->ack_policy
,
627 conf_tid
->apsd_conf
[0],
628 conf_tid
->apsd_conf
[1]);
633 /* Configure HW encryption */
634 ret
= wl1271_acx_feature_cfg(wl
, wlvif
);
638 /* Mode specific init - post mem init */
640 ret
= wl1271_ap_hw_init_post_mem(wl
, vif
);
642 ret
= wl1271_sta_hw_init_post_mem(wl
, vif
);
647 /* Configure initiator BA sessions policies */
648 ret
= wl1271_set_ba_policies(wl
, wlvif
);
652 ret
= wlcore_hw_init_vif(wl
, wlvif
);
659 int wl1271_hw_init(struct wl1271
*wl
)
663 /* Chip-specific hw init */
664 ret
= wl
->ops
->hw_init(wl
);
669 ret
= wl1271_init_templates_config(wl
);
673 ret
= wl12xx_acx_mem_cfg(wl
);
677 /* Configure the FW logger */
678 ret
= wl12xx_init_fwlog(wl
);
682 ret
= wlcore_cmd_regdomain_config_locked(wl
);
686 /* Bluetooth WLAN coexistence */
687 ret
= wl1271_init_pta(wl
);
691 /* Default memory configuration */
692 ret
= wl1271_acx_init_mem_config(wl
);
697 ret
= wl12xx_init_rx_config(wl
);
699 goto out_free_memmap
;
701 ret
= wl1271_acx_dco_itrim_params(wl
);
703 goto out_free_memmap
;
705 /* Configure TX patch complete interrupt behavior */
706 ret
= wl1271_acx_tx_config_options(wl
);
708 goto out_free_memmap
;
710 /* RX complete interrupt pacing */
711 ret
= wl1271_acx_init_rx_interrupt(wl
);
713 goto out_free_memmap
;
715 /* Energy detection */
716 ret
= wl1271_init_energy_detection(wl
);
718 goto out_free_memmap
;
720 /* Default fragmentation threshold */
721 ret
= wl1271_acx_frag_threshold(wl
, wl
->hw
->wiphy
->frag_threshold
);
723 goto out_free_memmap
;
725 /* Enable data path */
726 ret
= wl1271_cmd_data_path(wl
, 1);
728 goto out_free_memmap
;
731 ret
= wl1271_acx_pm_config(wl
);
733 goto out_free_memmap
;
735 ret
= wl12xx_acx_set_rate_mgmt_params(wl
);
737 goto out_free_memmap
;
739 /* configure hangover */
740 ret
= wl12xx_acx_config_hangover(wl
);
742 goto out_free_memmap
;
747 kfree(wl
->target_mem_map
);
748 wl
->target_mem_map
= NULL
;