2 * Copyright (c) 2013 Eugene Krasnikov <k.eugene.e@gmail.com>
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19 #include <linux/module.h>
20 #include <linux/firmware.h>
21 #include <linux/platform_device.h>
22 #include <linux/of_address.h>
23 #include <linux/of_device.h>
24 #include <linux/of_irq.h>
25 #include <linux/rpmsg.h>
26 #include <linux/soc/qcom/smem_state.h>
27 #include <linux/soc/qcom/wcnss_ctrl.h>
30 unsigned int wcn36xx_dbg_mask;
31 module_param_named(debug_mask, wcn36xx_dbg_mask, uint, 0644);
32 MODULE_PARM_DESC(debug_mask, "Debugging mask");
34 #define CHAN2G(_freq, _idx) { \
35 .band = NL80211_BAND_2GHZ, \
36 .center_freq = (_freq), \
41 #define CHAN5G(_freq, _idx) { \
42 .band = NL80211_BAND_5GHZ, \
43 .center_freq = (_freq), \
48 /* The wcn firmware expects channel values to matching
49 * their mnemonic values. So use these for .hw_value. */
50 static struct ieee80211_channel wcn_2ghz_channels[] = {
51 CHAN2G(2412, 1), /* Channel 1 */
52 CHAN2G(2417, 2), /* Channel 2 */
53 CHAN2G(2422, 3), /* Channel 3 */
54 CHAN2G(2427, 4), /* Channel 4 */
55 CHAN2G(2432, 5), /* Channel 5 */
56 CHAN2G(2437, 6), /* Channel 6 */
57 CHAN2G(2442, 7), /* Channel 7 */
58 CHAN2G(2447, 8), /* Channel 8 */
59 CHAN2G(2452, 9), /* Channel 9 */
60 CHAN2G(2457, 10), /* Channel 10 */
61 CHAN2G(2462, 11), /* Channel 11 */
62 CHAN2G(2467, 12), /* Channel 12 */
63 CHAN2G(2472, 13), /* Channel 13 */
64 CHAN2G(2484, 14) /* Channel 14 */
68 static struct ieee80211_channel wcn_5ghz_channels[] = {
94 #define RATE(_bitrate, _hw_rate, _flags) { \
95 .bitrate = (_bitrate), \
97 .hw_value = (_hw_rate), \
98 .hw_value_short = (_hw_rate) \
101 static struct ieee80211_rate wcn_2ghz_rates[] = {
102 RATE(10, HW_RATE_INDEX_1MBPS, 0),
103 RATE(20, HW_RATE_INDEX_2MBPS, IEEE80211_RATE_SHORT_PREAMBLE),
104 RATE(55, HW_RATE_INDEX_5_5MBPS, IEEE80211_RATE_SHORT_PREAMBLE),
105 RATE(110, HW_RATE_INDEX_11MBPS, IEEE80211_RATE_SHORT_PREAMBLE),
106 RATE(60, HW_RATE_INDEX_6MBPS, 0),
107 RATE(90, HW_RATE_INDEX_9MBPS, 0),
108 RATE(120, HW_RATE_INDEX_12MBPS, 0),
109 RATE(180, HW_RATE_INDEX_18MBPS, 0),
110 RATE(240, HW_RATE_INDEX_24MBPS, 0),
111 RATE(360, HW_RATE_INDEX_36MBPS, 0),
112 RATE(480, HW_RATE_INDEX_48MBPS, 0),
113 RATE(540, HW_RATE_INDEX_54MBPS, 0)
116 static struct ieee80211_rate wcn_5ghz_rates[] = {
117 RATE(60, HW_RATE_INDEX_6MBPS, 0),
118 RATE(90, HW_RATE_INDEX_9MBPS, 0),
119 RATE(120, HW_RATE_INDEX_12MBPS, 0),
120 RATE(180, HW_RATE_INDEX_18MBPS, 0),
121 RATE(240, HW_RATE_INDEX_24MBPS, 0),
122 RATE(360, HW_RATE_INDEX_36MBPS, 0),
123 RATE(480, HW_RATE_INDEX_48MBPS, 0),
124 RATE(540, HW_RATE_INDEX_54MBPS, 0)
127 static struct ieee80211_supported_band wcn_band_2ghz = {
128 .channels = wcn_2ghz_channels,
129 .n_channels = ARRAY_SIZE(wcn_2ghz_channels),
130 .bitrates = wcn_2ghz_rates,
131 .n_bitrates = ARRAY_SIZE(wcn_2ghz_rates),
133 .cap = IEEE80211_HT_CAP_GRN_FLD |
134 IEEE80211_HT_CAP_SGI_20 |
135 IEEE80211_HT_CAP_DSSSCCK40 |
136 IEEE80211_HT_CAP_LSIG_TXOP_PROT,
137 .ht_supported = true,
138 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
139 .ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
141 .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
142 .rx_highest = cpu_to_le16(72),
143 .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
148 static struct ieee80211_supported_band wcn_band_5ghz = {
149 .channels = wcn_5ghz_channels,
150 .n_channels = ARRAY_SIZE(wcn_5ghz_channels),
151 .bitrates = wcn_5ghz_rates,
152 .n_bitrates = ARRAY_SIZE(wcn_5ghz_rates),
154 .cap = IEEE80211_HT_CAP_GRN_FLD |
155 IEEE80211_HT_CAP_SGI_20 |
156 IEEE80211_HT_CAP_DSSSCCK40 |
157 IEEE80211_HT_CAP_LSIG_TXOP_PROT |
158 IEEE80211_HT_CAP_SGI_40 |
159 IEEE80211_HT_CAP_SUP_WIDTH_20_40,
160 .ht_supported = true,
161 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
162 .ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
164 .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
165 .rx_highest = cpu_to_le16(72),
166 .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
173 static const struct wiphy_wowlan_support wowlan_support = {
174 .flags = WIPHY_WOWLAN_ANY
179 static inline u8 get_sta_index(struct ieee80211_vif *vif,
180 struct wcn36xx_sta *sta_priv)
182 return NL80211_IFTYPE_STATION == vif->type ?
183 sta_priv->bss_sta_index :
187 static const char * const wcn36xx_caps_names[] = {
191 "SLM_SESSIONIZATION", /* 3 */
192 "DOT11AC_OPMODE", /* 4 */
195 "P2P_GO_NOA_DECOUPLE_INIT_SCAN",/* 7 */
196 "WLANACTIVE_OFFLOAD", /* 8 */
197 "BEACON_OFFLOAD", /* 9 */
198 "SCAN_OFFLOAD", /* 10 */
199 "ROAM_OFFLOAD", /* 11 */
200 "BCN_MISS_OFFLOAD", /* 12 */
201 "STA_POWERSAVE", /* 13 */
202 "STA_ADVANCED_PWRSAVE", /* 14 */
207 "BCN_FILTER", /* 19 */
211 "WLAN_ROAM_SCAN_OFFLOAD", /* 23 */
212 "SPECULATIVE_PS_POLL", /* 24 */
214 "IBSS_HEARTBEAT_OFFLOAD", /* 26 */
215 "WLAN_SCAN_OFFLOAD", /* 27 */
216 "WLAN_PERIODIC_TX_PTRN", /* 28 */
217 "ADVANCE_TDLS", /* 29 */
218 "BATCH_SCAN", /* 30 */
219 "FW_IN_TX_PATH", /* 31 */
220 "EXTENDED_NSOFFLOAD_SLOT", /* 32 */
221 "CH_SWITCH_V1", /* 33 */
222 "HT40_OBSS_SCAN", /* 34 */
223 "UPDATE_CHANNEL_LIST", /* 35 */
224 "WLAN_MCADDR_FLT", /* 36 */
225 "WLAN_CH144", /* 37 */
227 "TDLS_SCAN_COEXISTENCE", /* 39 */
228 "LINK_LAYER_STATS_MEAS", /* 40 */
230 "EXTENDED_SCAN", /* 42 */
231 "DYNAMIC_WMM_PS", /* 43 */
232 "MAC_SPOOFED_SCAN", /* 44 */
233 "BMU_ERROR_GENERIC_RECOVERY", /* 45 */
236 "WPS_PRBRSP_TMPL", /* 48 */
237 "BCN_IE_FLT_DELTA", /* 49 */
238 "TDLS_OFF_CHANNEL", /* 51 */
240 "MGMT_FRAME_LOGGING", /* 53 */
241 "ENHANCED_TXBD_COMPLETION", /* 54 */
242 "LOGGING_ENHANCEMENT", /* 55 */
243 "EXT_SCAN_ENHANCED", /* 56 */
244 "MEMORY_DUMP_SUPPORTED", /* 57 */
245 "PER_PKT_STATS_SUPPORTED", /* 58 */
246 "EXT_LL_STAT", /* 60 */
247 "WIFI_CONFIG", /* 61 */
248 "ANTENNA_DIVERSITY_SELECTION", /* 62 */
251 static const char *wcn36xx_get_cap_name(enum place_holder_in_cap_bitmap x)
253 if (x >= ARRAY_SIZE(wcn36xx_caps_names))
255 return wcn36xx_caps_names[x];
258 static void wcn36xx_feat_caps_info(struct wcn36xx *wcn)
262 for (i = 0; i < MAX_FEATURE_SUPPORTED; i++) {
263 if (get_feat_caps(wcn->fw_feat_caps, i))
264 wcn36xx_info("FW Cap %s\n", wcn36xx_get_cap_name(i));
268 static int wcn36xx_start(struct ieee80211_hw *hw)
270 struct wcn36xx *wcn = hw->priv;
273 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac start\n");
275 /* SMD initialization */
276 ret = wcn36xx_smd_open(wcn);
278 wcn36xx_err("Failed to open smd channel: %d\n", ret);
282 /* Allocate memory pools for Mgmt BD headers and Data BD headers */
283 ret = wcn36xx_dxe_allocate_mem_pools(wcn);
285 wcn36xx_err("Failed to alloc DXE mempool: %d\n", ret);
289 ret = wcn36xx_dxe_alloc_ctl_blks(wcn);
291 wcn36xx_err("Failed to alloc DXE ctl blocks: %d\n", ret);
292 goto out_free_dxe_pool;
295 wcn->hal_buf = kmalloc(WCN36XX_HAL_BUF_SIZE, GFP_KERNEL);
297 wcn36xx_err("Failed to allocate smd buf\n");
299 goto out_free_dxe_ctl;
302 ret = wcn36xx_smd_load_nv(wcn);
304 wcn36xx_err("Failed to push NV to chip\n");
305 goto out_free_smd_buf;
308 ret = wcn36xx_smd_start(wcn);
310 wcn36xx_err("Failed to start chip\n");
311 goto out_free_smd_buf;
314 if (!wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) {
315 ret = wcn36xx_smd_feature_caps_exchange(wcn);
317 wcn36xx_warn("Exchange feature caps failed\n");
319 wcn36xx_feat_caps_info(wcn);
322 /* DMA channel initialization */
323 ret = wcn36xx_dxe_init(wcn);
325 wcn36xx_err("DXE init failed\n");
329 wcn36xx_debugfs_init(wcn);
331 INIT_LIST_HEAD(&wcn->vif_list);
332 spin_lock_init(&wcn->dxe_lock);
337 wcn36xx_smd_stop(wcn);
341 wcn36xx_dxe_free_ctl_blks(wcn);
343 wcn36xx_dxe_free_mem_pools(wcn);
345 wcn36xx_smd_close(wcn);
350 static void wcn36xx_stop(struct ieee80211_hw *hw)
352 struct wcn36xx *wcn = hw->priv;
354 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac stop\n");
356 wcn36xx_debugfs_exit(wcn);
357 wcn36xx_smd_stop(wcn);
358 wcn36xx_dxe_deinit(wcn);
359 wcn36xx_smd_close(wcn);
361 wcn36xx_dxe_free_mem_pools(wcn);
362 wcn36xx_dxe_free_ctl_blks(wcn);
367 static int wcn36xx_config(struct ieee80211_hw *hw, u32 changed)
369 struct wcn36xx *wcn = hw->priv;
370 struct ieee80211_vif *vif = NULL;
371 struct wcn36xx_vif *tmp;
373 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac config changed 0x%08x\n", changed);
375 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
376 int ch = WCN36XX_HW_CHANNEL(wcn);
377 wcn36xx_dbg(WCN36XX_DBG_MAC, "wcn36xx_config channel switch=%d\n",
379 list_for_each_entry(tmp, &wcn->vif_list, list) {
380 vif = wcn36xx_priv_to_vif(tmp);
381 wcn36xx_smd_switch_channel(wcn, vif, ch);
388 static void wcn36xx_configure_filter(struct ieee80211_hw *hw,
389 unsigned int changed,
390 unsigned int *total, u64 multicast)
392 struct wcn36xx_hal_rcv_flt_mc_addr_list_type *fp;
393 struct wcn36xx *wcn = hw->priv;
394 struct wcn36xx_vif *tmp;
395 struct ieee80211_vif *vif = NULL;
397 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac configure filter\n");
399 *total &= FIF_ALLMULTI;
401 fp = (void *)(unsigned long)multicast;
402 list_for_each_entry(tmp, &wcn->vif_list, list) {
403 vif = wcn36xx_priv_to_vif(tmp);
405 /* FW handles MC filtering only when connected as STA */
406 if (*total & FIF_ALLMULTI)
407 wcn36xx_smd_set_mc_list(wcn, vif, NULL);
408 else if (NL80211_IFTYPE_STATION == vif->type && tmp->sta_assoc)
409 wcn36xx_smd_set_mc_list(wcn, vif, fp);
414 static u64 wcn36xx_prepare_multicast(struct ieee80211_hw *hw,
415 struct netdev_hw_addr_list *mc_list)
417 struct wcn36xx_hal_rcv_flt_mc_addr_list_type *fp;
418 struct netdev_hw_addr *ha;
420 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac prepare multicast list\n");
421 fp = kzalloc(sizeof(*fp), GFP_ATOMIC);
423 wcn36xx_err("Out of memory setting filters.\n");
427 fp->mc_addr_count = 0;
428 /* update multicast filtering parameters */
429 if (netdev_hw_addr_list_count(mc_list) <=
430 WCN36XX_HAL_MAX_NUM_MULTICAST_ADDRESS) {
431 netdev_hw_addr_list_for_each(ha, mc_list) {
432 memcpy(fp->mc_addr[fp->mc_addr_count],
438 return (u64)(unsigned long)fp;
441 static void wcn36xx_tx(struct ieee80211_hw *hw,
442 struct ieee80211_tx_control *control,
445 struct wcn36xx *wcn = hw->priv;
446 struct wcn36xx_sta *sta_priv = NULL;
449 sta_priv = wcn36xx_sta_to_priv(control->sta);
451 if (wcn36xx_start_tx(wcn, sta_priv, skb))
452 ieee80211_free_txskb(wcn->hw, skb);
455 static int wcn36xx_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
456 struct ieee80211_vif *vif,
457 struct ieee80211_sta *sta,
458 struct ieee80211_key_conf *key_conf)
460 struct wcn36xx *wcn = hw->priv;
461 struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
462 struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(sta);
464 u8 key[WLAN_MAX_KEY_LEN];
466 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac80211 set key\n");
467 wcn36xx_dbg(WCN36XX_DBG_MAC, "Key: cmd=0x%x algo:0x%x, id:%d, len:%d flags 0x%x\n",
468 cmd, key_conf->cipher, key_conf->keyidx,
469 key_conf->keylen, key_conf->flags);
470 wcn36xx_dbg_dump(WCN36XX_DBG_MAC, "KEY: ",
474 switch (key_conf->cipher) {
475 case WLAN_CIPHER_SUITE_WEP40:
476 vif_priv->encrypt_type = WCN36XX_HAL_ED_WEP40;
478 case WLAN_CIPHER_SUITE_WEP104:
479 vif_priv->encrypt_type = WCN36XX_HAL_ED_WEP40;
481 case WLAN_CIPHER_SUITE_CCMP:
482 vif_priv->encrypt_type = WCN36XX_HAL_ED_CCMP;
484 case WLAN_CIPHER_SUITE_TKIP:
485 vif_priv->encrypt_type = WCN36XX_HAL_ED_TKIP;
488 wcn36xx_err("Unsupported key type 0x%x\n",
496 if (WCN36XX_HAL_ED_TKIP == vif_priv->encrypt_type) {
498 * Supplicant is sending key in the wrong order:
499 * Temporal Key (16 b) - TX MIC (8 b) - RX MIC (8 b)
500 * but HW expects it to be in the order as described in
501 * IEEE 802.11 spec (see chapter 11.7) like this:
502 * Temporal Key (16 b) - RX MIC (8 b) - TX MIC (8 b)
504 memcpy(key, key_conf->key, 16);
505 memcpy(key + 16, key_conf->key + 24, 8);
506 memcpy(key + 24, key_conf->key + 16, 8);
508 memcpy(key, key_conf->key, key_conf->keylen);
511 if (IEEE80211_KEY_FLAG_PAIRWISE & key_conf->flags) {
512 sta_priv->is_data_encrypted = true;
513 /* Reconfigure bss with encrypt_type */
514 if (NL80211_IFTYPE_STATION == vif->type)
515 wcn36xx_smd_config_bss(wcn,
521 wcn36xx_smd_set_stakey(wcn,
522 vif_priv->encrypt_type,
526 get_sta_index(vif, sta_priv));
528 wcn36xx_smd_set_bsskey(wcn,
529 vif_priv->encrypt_type,
533 if ((WLAN_CIPHER_SUITE_WEP40 == key_conf->cipher) ||
534 (WLAN_CIPHER_SUITE_WEP104 == key_conf->cipher)) {
535 sta_priv->is_data_encrypted = true;
536 wcn36xx_smd_set_stakey(wcn,
537 vif_priv->encrypt_type,
541 get_sta_index(vif, sta_priv));
546 if (!(IEEE80211_KEY_FLAG_PAIRWISE & key_conf->flags)) {
547 vif_priv->encrypt_type = WCN36XX_HAL_ED_NONE;
548 wcn36xx_smd_remove_bsskey(wcn,
549 vif_priv->encrypt_type,
552 sta_priv->is_data_encrypted = false;
553 /* do not remove key if disassociated */
555 wcn36xx_smd_remove_stakey(wcn,
556 vif_priv->encrypt_type,
558 get_sta_index(vif, sta_priv));
562 wcn36xx_err("Unsupported key cmd 0x%x\n", cmd);
571 static void wcn36xx_hw_scan_worker(struct work_struct *work)
573 struct wcn36xx *wcn = container_of(work, struct wcn36xx, scan_work);
574 struct cfg80211_scan_request *req = wcn->scan_req;
575 u8 channels[WCN36XX_HAL_PNO_MAX_NETW_CHANNELS_EX];
576 struct cfg80211_scan_info scan_info = {};
577 bool aborted = false;
580 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac80211 scan %d channels worker\n", req->n_channels);
582 for (i = 0; i < req->n_channels; i++)
583 channels[i] = req->channels[i]->hw_value;
585 wcn36xx_smd_update_scan_params(wcn, channels, req->n_channels);
587 wcn36xx_smd_init_scan(wcn, HAL_SYS_MODE_SCAN);
588 for (i = 0; i < req->n_channels; i++) {
589 mutex_lock(&wcn->scan_lock);
590 aborted = wcn->scan_aborted;
591 mutex_unlock(&wcn->scan_lock);
596 wcn->scan_freq = req->channels[i]->center_freq;
597 wcn->scan_band = req->channels[i]->band;
599 wcn36xx_smd_start_scan(wcn, req->channels[i]->hw_value);
601 wcn36xx_smd_end_scan(wcn, req->channels[i]->hw_value);
605 wcn36xx_smd_finish_scan(wcn, HAL_SYS_MODE_SCAN);
607 scan_info.aborted = aborted;
608 ieee80211_scan_completed(wcn->hw, &scan_info);
610 mutex_lock(&wcn->scan_lock);
611 wcn->scan_req = NULL;
612 mutex_unlock(&wcn->scan_lock);
615 static int wcn36xx_hw_scan(struct ieee80211_hw *hw,
616 struct ieee80211_vif *vif,
617 struct ieee80211_scan_request *hw_req)
619 struct wcn36xx *wcn = hw->priv;
621 mutex_lock(&wcn->scan_lock);
623 mutex_unlock(&wcn->scan_lock);
627 wcn->scan_aborted = false;
628 wcn->scan_req = &hw_req->req;
629 mutex_unlock(&wcn->scan_lock);
631 schedule_work(&wcn->scan_work);
636 static void wcn36xx_cancel_hw_scan(struct ieee80211_hw *hw,
637 struct ieee80211_vif *vif)
639 struct wcn36xx *wcn = hw->priv;
641 mutex_lock(&wcn->scan_lock);
642 wcn->scan_aborted = true;
643 mutex_unlock(&wcn->scan_lock);
645 cancel_work_sync(&wcn->scan_work);
648 static void wcn36xx_update_allowed_rates(struct ieee80211_sta *sta,
649 enum nl80211_band band)
653 struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(sta);
654 u32 rates = sta->supp_rates[band];
656 memset(&sta_priv->supported_rates, 0,
657 sizeof(sta_priv->supported_rates));
658 sta_priv->supported_rates.op_rate_mode = STA_11n;
660 size = ARRAY_SIZE(sta_priv->supported_rates.dsss_rates);
661 rates_table = sta_priv->supported_rates.dsss_rates;
662 if (band == NL80211_BAND_2GHZ) {
663 for (i = 0; i < size; i++) {
665 rates_table[i] = wcn_2ghz_rates[i].hw_value;
671 size = ARRAY_SIZE(sta_priv->supported_rates.ofdm_rates);
672 rates_table = sta_priv->supported_rates.ofdm_rates;
673 for (i = 0; i < size; i++) {
675 rates_table[i] = wcn_5ghz_rates[i].hw_value;
680 if (sta->ht_cap.ht_supported) {
681 BUILD_BUG_ON(sizeof(sta->ht_cap.mcs.rx_mask) >
682 sizeof(sta_priv->supported_rates.supported_mcs_set));
683 memcpy(sta_priv->supported_rates.supported_mcs_set,
684 sta->ht_cap.mcs.rx_mask,
685 sizeof(sta->ht_cap.mcs.rx_mask));
688 void wcn36xx_set_default_rates(struct wcn36xx_hal_supported_rates *rates)
690 u16 ofdm_rates[WCN36XX_HAL_NUM_OFDM_RATES] = {
693 HW_RATE_INDEX_12MBPS,
694 HW_RATE_INDEX_18MBPS,
695 HW_RATE_INDEX_24MBPS,
696 HW_RATE_INDEX_36MBPS,
697 HW_RATE_INDEX_48MBPS,
700 u16 dsss_rates[WCN36XX_HAL_NUM_DSSS_RATES] = {
703 HW_RATE_INDEX_5_5MBPS,
707 rates->op_rate_mode = STA_11n;
708 memcpy(rates->dsss_rates, dsss_rates,
709 sizeof(*dsss_rates) * WCN36XX_HAL_NUM_DSSS_RATES);
710 memcpy(rates->ofdm_rates, ofdm_rates,
711 sizeof(*ofdm_rates) * WCN36XX_HAL_NUM_OFDM_RATES);
712 rates->supported_mcs_set[0] = 0xFF;
714 static void wcn36xx_bss_info_changed(struct ieee80211_hw *hw,
715 struct ieee80211_vif *vif,
716 struct ieee80211_bss_conf *bss_conf,
719 struct wcn36xx *wcn = hw->priv;
720 struct sk_buff *skb = NULL;
721 u16 tim_off, tim_len;
722 enum wcn36xx_hal_link_state link_state;
723 struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
725 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac bss info changed vif %p changed 0x%08x\n",
728 if (changed & BSS_CHANGED_BEACON_INFO) {
729 wcn36xx_dbg(WCN36XX_DBG_MAC,
730 "mac bss changed dtim period %d\n",
731 bss_conf->dtim_period);
733 vif_priv->dtim_period = bss_conf->dtim_period;
736 if (changed & BSS_CHANGED_PS) {
737 wcn36xx_dbg(WCN36XX_DBG_MAC,
738 "mac bss PS set %d\n",
741 wcn36xx_pmc_enter_bmps_state(wcn, vif);
743 wcn36xx_pmc_exit_bmps_state(wcn, vif);
747 if (changed & BSS_CHANGED_BSSID) {
748 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac bss changed_bssid %pM\n",
751 if (!is_zero_ether_addr(bss_conf->bssid)) {
752 vif_priv->is_joining = true;
753 vif_priv->bss_index = WCN36XX_HAL_BSS_INVALID_IDX;
754 wcn36xx_smd_join(wcn, bss_conf->bssid,
755 vif->addr, WCN36XX_HW_CHANNEL(wcn));
756 wcn36xx_smd_config_bss(wcn, vif, NULL,
757 bss_conf->bssid, false);
759 vif_priv->is_joining = false;
760 wcn36xx_smd_delete_bss(wcn, vif);
761 vif_priv->encrypt_type = WCN36XX_HAL_ED_NONE;
765 if (changed & BSS_CHANGED_SSID) {
766 wcn36xx_dbg(WCN36XX_DBG_MAC,
767 "mac bss changed ssid\n");
768 wcn36xx_dbg_dump(WCN36XX_DBG_MAC, "ssid ",
769 bss_conf->ssid, bss_conf->ssid_len);
771 vif_priv->ssid.length = bss_conf->ssid_len;
772 memcpy(&vif_priv->ssid.ssid,
777 if (changed & BSS_CHANGED_ASSOC) {
778 vif_priv->is_joining = false;
779 if (bss_conf->assoc) {
780 struct ieee80211_sta *sta;
781 struct wcn36xx_sta *sta_priv;
783 wcn36xx_dbg(WCN36XX_DBG_MAC,
784 "mac assoc bss %pM vif %pM AID=%d\n",
789 vif_priv->sta_assoc = true;
791 sta = ieee80211_find_sta(vif, bss_conf->bssid);
793 wcn36xx_err("sta %pM is not found\n",
798 sta_priv = wcn36xx_sta_to_priv(sta);
800 wcn36xx_update_allowed_rates(sta, WCN36XX_BAND(wcn));
802 wcn36xx_smd_set_link_st(wcn, bss_conf->bssid,
804 WCN36XX_HAL_LINK_POSTASSOC_STATE);
805 wcn36xx_smd_config_bss(wcn, vif, sta,
808 sta_priv->aid = bss_conf->aid;
810 * config_sta must be called from because this is the
811 * place where AID is available.
813 wcn36xx_smd_config_sta(wcn, vif, sta);
816 wcn36xx_dbg(WCN36XX_DBG_MAC,
817 "disassociated bss %pM vif %pM AID=%d\n",
821 vif_priv->sta_assoc = false;
822 wcn36xx_smd_set_link_st(wcn,
825 WCN36XX_HAL_LINK_IDLE_STATE);
829 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
830 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac bss changed ap probe resp\n");
831 skb = ieee80211_proberesp_get(hw, vif);
833 wcn36xx_err("failed to alloc probereq skb\n");
837 wcn36xx_smd_update_proberesp_tmpl(wcn, vif, skb);
841 if (changed & BSS_CHANGED_BEACON_ENABLED ||
842 changed & BSS_CHANGED_BEACON) {
843 wcn36xx_dbg(WCN36XX_DBG_MAC,
844 "mac bss changed beacon enabled %d\n",
845 bss_conf->enable_beacon);
847 if (bss_conf->enable_beacon) {
848 vif_priv->dtim_period = bss_conf->dtim_period;
849 vif_priv->bss_index = WCN36XX_HAL_BSS_INVALID_IDX;
850 wcn36xx_smd_config_bss(wcn, vif, NULL,
852 skb = ieee80211_beacon_get_tim(hw, vif, &tim_off,
855 wcn36xx_err("failed to alloc beacon skb\n");
858 wcn36xx_smd_send_beacon(wcn, vif, skb, tim_off, 0);
861 if (vif->type == NL80211_IFTYPE_ADHOC ||
862 vif->type == NL80211_IFTYPE_MESH_POINT)
863 link_state = WCN36XX_HAL_LINK_IBSS_STATE;
865 link_state = WCN36XX_HAL_LINK_AP_STATE;
867 wcn36xx_smd_set_link_st(wcn, vif->addr, vif->addr,
870 wcn36xx_smd_delete_bss(wcn, vif);
871 wcn36xx_smd_set_link_st(wcn, vif->addr, vif->addr,
872 WCN36XX_HAL_LINK_IDLE_STATE);
879 /* this is required when using IEEE80211_HW_HAS_RATE_CONTROL */
880 static int wcn36xx_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
882 struct wcn36xx *wcn = hw->priv;
883 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac set RTS threshold %d\n", value);
885 wcn36xx_smd_update_cfg(wcn, WCN36XX_HAL_CFG_RTS_THRESHOLD, value);
889 static void wcn36xx_remove_interface(struct ieee80211_hw *hw,
890 struct ieee80211_vif *vif)
892 struct wcn36xx *wcn = hw->priv;
893 struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
894 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac remove interface vif %p\n", vif);
896 list_del(&vif_priv->list);
897 wcn36xx_smd_delete_sta_self(wcn, vif->addr);
900 static int wcn36xx_add_interface(struct ieee80211_hw *hw,
901 struct ieee80211_vif *vif)
903 struct wcn36xx *wcn = hw->priv;
904 struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
906 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac add interface vif %p type %d\n",
909 if (!(NL80211_IFTYPE_STATION == vif->type ||
910 NL80211_IFTYPE_AP == vif->type ||
911 NL80211_IFTYPE_ADHOC == vif->type ||
912 NL80211_IFTYPE_MESH_POINT == vif->type)) {
913 wcn36xx_warn("Unsupported interface type requested: %d\n",
918 list_add(&vif_priv->list, &wcn->vif_list);
919 wcn36xx_smd_add_sta_self(wcn, vif);
924 static int wcn36xx_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
925 struct ieee80211_sta *sta)
927 struct wcn36xx *wcn = hw->priv;
928 struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
929 struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(sta);
930 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac sta add vif %p sta %pM\n",
933 spin_lock_init(&sta_priv->ampdu_lock);
934 sta_priv->vif = vif_priv;
936 * For STA mode HW will be configured on BSS_CHANGED_ASSOC because
937 * at this stage AID is not available yet.
939 if (NL80211_IFTYPE_STATION != vif->type) {
940 wcn36xx_update_allowed_rates(sta, WCN36XX_BAND(wcn));
941 sta_priv->aid = sta->aid;
942 wcn36xx_smd_config_sta(wcn, vif, sta);
947 static int wcn36xx_sta_remove(struct ieee80211_hw *hw,
948 struct ieee80211_vif *vif,
949 struct ieee80211_sta *sta)
951 struct wcn36xx *wcn = hw->priv;
952 struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(sta);
954 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac sta remove vif %p sta %pM index %d\n",
955 vif, sta->addr, sta_priv->sta_index);
957 wcn36xx_smd_delete_sta(wcn, sta_priv->sta_index);
958 sta_priv->vif = NULL;
964 static int wcn36xx_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wow)
966 struct wcn36xx *wcn = hw->priv;
968 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac suspend\n");
970 flush_workqueue(wcn->hal_ind_wq);
971 wcn36xx_smd_set_power_params(wcn, true);
975 static int wcn36xx_resume(struct ieee80211_hw *hw)
977 struct wcn36xx *wcn = hw->priv;
979 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac resume\n");
981 flush_workqueue(wcn->hal_ind_wq);
982 wcn36xx_smd_set_power_params(wcn, false);
988 static int wcn36xx_ampdu_action(struct ieee80211_hw *hw,
989 struct ieee80211_vif *vif,
990 struct ieee80211_ampdu_params *params)
992 struct wcn36xx *wcn = hw->priv;
993 struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(params->sta);
994 struct ieee80211_sta *sta = params->sta;
995 enum ieee80211_ampdu_mlme_action action = params->action;
996 u16 tid = params->tid;
997 u16 *ssn = ¶ms->ssn;
999 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac ampdu action action %d tid %d\n",
1003 case IEEE80211_AMPDU_RX_START:
1004 sta_priv->tid = tid;
1005 wcn36xx_smd_add_ba_session(wcn, sta, tid, ssn, 0,
1006 get_sta_index(vif, sta_priv));
1007 wcn36xx_smd_add_ba(wcn);
1008 wcn36xx_smd_trigger_ba(wcn, get_sta_index(vif, sta_priv));
1010 case IEEE80211_AMPDU_RX_STOP:
1011 wcn36xx_smd_del_ba(wcn, tid, get_sta_index(vif, sta_priv));
1013 case IEEE80211_AMPDU_TX_START:
1014 spin_lock_bh(&sta_priv->ampdu_lock);
1015 sta_priv->ampdu_state[tid] = WCN36XX_AMPDU_START;
1016 spin_unlock_bh(&sta_priv->ampdu_lock);
1018 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1020 case IEEE80211_AMPDU_TX_OPERATIONAL:
1021 spin_lock_bh(&sta_priv->ampdu_lock);
1022 sta_priv->ampdu_state[tid] = WCN36XX_AMPDU_OPERATIONAL;
1023 spin_unlock_bh(&sta_priv->ampdu_lock);
1025 wcn36xx_smd_add_ba_session(wcn, sta, tid, ssn, 1,
1026 get_sta_index(vif, sta_priv));
1028 case IEEE80211_AMPDU_TX_STOP_FLUSH:
1029 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
1030 case IEEE80211_AMPDU_TX_STOP_CONT:
1031 spin_lock_bh(&sta_priv->ampdu_lock);
1032 sta_priv->ampdu_state[tid] = WCN36XX_AMPDU_NONE;
1033 spin_unlock_bh(&sta_priv->ampdu_lock);
1035 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1038 wcn36xx_err("Unknown AMPDU action\n");
1044 static const struct ieee80211_ops wcn36xx_ops = {
1045 .start = wcn36xx_start,
1046 .stop = wcn36xx_stop,
1047 .add_interface = wcn36xx_add_interface,
1048 .remove_interface = wcn36xx_remove_interface,
1050 .suspend = wcn36xx_suspend,
1051 .resume = wcn36xx_resume,
1053 .config = wcn36xx_config,
1054 .prepare_multicast = wcn36xx_prepare_multicast,
1055 .configure_filter = wcn36xx_configure_filter,
1057 .set_key = wcn36xx_set_key,
1058 .hw_scan = wcn36xx_hw_scan,
1059 .cancel_hw_scan = wcn36xx_cancel_hw_scan,
1060 .bss_info_changed = wcn36xx_bss_info_changed,
1061 .set_rts_threshold = wcn36xx_set_rts_threshold,
1062 .sta_add = wcn36xx_sta_add,
1063 .sta_remove = wcn36xx_sta_remove,
1064 .ampdu_action = wcn36xx_ampdu_action,
1067 static int wcn36xx_init_ieee80211(struct wcn36xx *wcn)
1071 static const u32 cipher_suites[] = {
1072 WLAN_CIPHER_SUITE_WEP40,
1073 WLAN_CIPHER_SUITE_WEP104,
1074 WLAN_CIPHER_SUITE_TKIP,
1075 WLAN_CIPHER_SUITE_CCMP,
1078 ieee80211_hw_set(wcn->hw, TIMING_BEACON_ONLY);
1079 ieee80211_hw_set(wcn->hw, AMPDU_AGGREGATION);
1080 ieee80211_hw_set(wcn->hw, CONNECTION_MONITOR);
1081 ieee80211_hw_set(wcn->hw, SUPPORTS_PS);
1082 ieee80211_hw_set(wcn->hw, SIGNAL_DBM);
1083 ieee80211_hw_set(wcn->hw, HAS_RATE_CONTROL);
1084 ieee80211_hw_set(wcn->hw, SINGLE_SCAN_ON_ALL_BANDS);
1086 wcn->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1087 BIT(NL80211_IFTYPE_AP) |
1088 BIT(NL80211_IFTYPE_ADHOC) |
1089 BIT(NL80211_IFTYPE_MESH_POINT);
1091 wcn->hw->wiphy->bands[NL80211_BAND_2GHZ] = &wcn_band_2ghz;
1092 wcn->hw->wiphy->bands[NL80211_BAND_5GHZ] = &wcn_band_5ghz;
1094 wcn->hw->wiphy->max_scan_ssids = WCN36XX_MAX_SCAN_SSIDS;
1095 wcn->hw->wiphy->max_scan_ie_len = WCN36XX_MAX_SCAN_IE_LEN;
1097 wcn->hw->wiphy->cipher_suites = cipher_suites;
1098 wcn->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
1100 wcn->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
1103 wcn->hw->wiphy->wowlan = &wowlan_support;
1106 wcn->hw->max_listen_interval = 200;
1108 wcn->hw->queues = 4;
1110 SET_IEEE80211_DEV(wcn->hw, wcn->dev);
1112 wcn->hw->sta_data_size = sizeof(struct wcn36xx_sta);
1113 wcn->hw->vif_data_size = sizeof(struct wcn36xx_vif);
1115 wiphy_ext_feature_set(wcn->hw->wiphy,
1116 NL80211_EXT_FEATURE_CQM_RSSI_LIST);
1121 static int wcn36xx_platform_get_resources(struct wcn36xx *wcn,
1122 struct platform_device *pdev)
1124 struct device_node *mmio_node;
1125 struct resource *res;
1130 res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "tx");
1132 wcn36xx_err("failed to get tx_irq\n");
1135 wcn->tx_irq = res->start;
1138 res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "rx");
1140 wcn36xx_err("failed to get rx_irq\n");
1143 wcn->rx_irq = res->start;
1145 /* Acquire SMSM tx enable handle */
1146 wcn->tx_enable_state = qcom_smem_state_get(&pdev->dev,
1147 "tx-enable", &wcn->tx_enable_state_bit);
1148 if (IS_ERR(wcn->tx_enable_state)) {
1149 wcn36xx_err("failed to get tx-enable state\n");
1150 return PTR_ERR(wcn->tx_enable_state);
1153 /* Acquire SMSM tx rings empty handle */
1154 wcn->tx_rings_empty_state = qcom_smem_state_get(&pdev->dev,
1155 "tx-rings-empty", &wcn->tx_rings_empty_state_bit);
1156 if (IS_ERR(wcn->tx_rings_empty_state)) {
1157 wcn36xx_err("failed to get tx-rings-empty state\n");
1158 return PTR_ERR(wcn->tx_rings_empty_state);
1161 mmio_node = of_parse_phandle(pdev->dev.parent->of_node, "qcom,mmio", 0);
1163 wcn36xx_err("failed to acquire qcom,mmio reference\n");
1167 wcn->is_pronto = !!of_device_is_compatible(mmio_node, "qcom,pronto");
1169 /* Map the CCU memory */
1170 index = of_property_match_string(mmio_node, "reg-names", "ccu");
1171 wcn->ccu_base = of_iomap(mmio_node, index);
1172 if (!wcn->ccu_base) {
1173 wcn36xx_err("failed to map ccu memory\n");
1178 /* Map the DXE memory */
1179 index = of_property_match_string(mmio_node, "reg-names", "dxe");
1180 wcn->dxe_base = of_iomap(mmio_node, index);
1181 if (!wcn->dxe_base) {
1182 wcn36xx_err("failed to map dxe memory\n");
1187 of_node_put(mmio_node);
1191 iounmap(wcn->ccu_base);
1193 of_node_put(mmio_node);
1197 static int wcn36xx_probe(struct platform_device *pdev)
1199 struct ieee80211_hw *hw;
1200 struct wcn36xx *wcn;
1205 wcn36xx_dbg(WCN36XX_DBG_MAC, "platform probe\n");
1207 wcnss = dev_get_drvdata(pdev->dev.parent);
1209 hw = ieee80211_alloc_hw(sizeof(struct wcn36xx), &wcn36xx_ops);
1211 wcn36xx_err("failed to alloc hw\n");
1215 platform_set_drvdata(pdev, hw);
1218 wcn->dev = &pdev->dev;
1219 mutex_init(&wcn->hal_mutex);
1220 mutex_init(&wcn->scan_lock);
1222 INIT_WORK(&wcn->scan_work, wcn36xx_hw_scan_worker);
1224 wcn->smd_channel = qcom_wcnss_open_channel(wcnss, "WLAN_CTRL", wcn36xx_smd_rsp_process, hw);
1225 if (IS_ERR(wcn->smd_channel)) {
1226 wcn36xx_err("failed to open WLAN_CTRL channel\n");
1227 ret = PTR_ERR(wcn->smd_channel);
1231 addr = of_get_property(pdev->dev.of_node, "local-mac-address", &ret);
1232 if (addr && ret != ETH_ALEN) {
1233 wcn36xx_err("invalid local-mac-address\n");
1237 wcn36xx_info("mac address: %pM\n", addr);
1238 SET_IEEE80211_PERM_ADDR(wcn->hw, addr);
1241 ret = wcn36xx_platform_get_resources(wcn, pdev);
1245 wcn36xx_init_ieee80211(wcn);
1246 ret = ieee80211_register_hw(wcn->hw);
1253 iounmap(wcn->ccu_base);
1254 iounmap(wcn->dxe_base);
1256 ieee80211_free_hw(hw);
1261 static int wcn36xx_remove(struct platform_device *pdev)
1263 struct ieee80211_hw *hw = platform_get_drvdata(pdev);
1264 struct wcn36xx *wcn = hw->priv;
1265 wcn36xx_dbg(WCN36XX_DBG_MAC, "platform remove\n");
1267 release_firmware(wcn->nv);
1269 ieee80211_unregister_hw(hw);
1271 qcom_smem_state_put(wcn->tx_enable_state);
1272 qcom_smem_state_put(wcn->tx_rings_empty_state);
1274 rpmsg_destroy_ept(wcn->smd_channel);
1276 iounmap(wcn->dxe_base);
1277 iounmap(wcn->ccu_base);
1279 mutex_destroy(&wcn->hal_mutex);
1280 ieee80211_free_hw(hw);
1285 static const struct of_device_id wcn36xx_of_match[] = {
1286 { .compatible = "qcom,wcnss-wlan" },
1289 MODULE_DEVICE_TABLE(of, wcn36xx_of_match);
1291 static struct platform_driver wcn36xx_driver = {
1292 .probe = wcn36xx_probe,
1293 .remove = wcn36xx_remove,
1296 .of_match_table = wcn36xx_of_match,
1300 module_platform_driver(wcn36xx_driver);
1302 MODULE_LICENSE("Dual BSD/GPL");
1303 MODULE_AUTHOR("Eugene Krasnikov k.eugene.e@gmail.com");
1304 MODULE_FIRMWARE(WLAN_NV_FILE);