1 /*
2 * Copyright (c) 2013 Eugene Krasnikov <k.eugene.e@gmail.com>
3 *
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.
7 *
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.
15 */
16
17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18
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>
28 #include "wcn36xx.h"
29 #include "testmode.h"
30
31 unsigned int wcn36xx_dbg_mask;
32 module_param_named(debug_mask, wcn36xx_dbg_mask, uint, 0644);
33 MODULE_PARM_DESC(debug_mask, "Debugging mask");
34
35 #define CHAN2G(_freq, _idx) { \
36 .band = NL80211_BAND_2GHZ, \
37 .center_freq = (_freq), \
38 .hw_value = (_idx), \
39 .max_power = 25, \
40 }
41
42 #define CHAN5G(_freq, _idx, _phy_val) { \
43 .band = NL80211_BAND_5GHZ, \
44 .center_freq = (_freq), \
45 .hw_value = (_phy_val) << HW_VALUE_PHY_SHIFT | HW_VALUE_CHANNEL(_idx), \
46 .max_power = 25, \
47 }
48
49 /* The wcn firmware expects channel values to matching
50 * their mnemonic values. So use these for .hw_value. */
51 static struct ieee80211_channel wcn_2ghz_channels[] = {
52 CHAN2G(2412, 1), /* Channel 1 */
53 CHAN2G(2417, 2), /* Channel 2 */
54 CHAN2G(2422, 3), /* Channel 3 */
55 CHAN2G(2427, 4), /* Channel 4 */
56 CHAN2G(2432, 5), /* Channel 5 */
57 CHAN2G(2437, 6), /* Channel 6 */
58 CHAN2G(2442, 7), /* Channel 7 */
59 CHAN2G(2447, 8), /* Channel 8 */
60 CHAN2G(2452, 9), /* Channel 9 */
61 CHAN2G(2457, 10), /* Channel 10 */
62 CHAN2G(2462, 11), /* Channel 11 */
63 CHAN2G(2467, 12), /* Channel 12 */
64 CHAN2G(2472, 13), /* Channel 13 */
65 CHAN2G(2484, 14) /* Channel 14 */
66
67 };
68
69 static struct ieee80211_channel wcn_5ghz_channels[] = {
70 CHAN5G(5180, 36, PHY_QUADRUPLE_CHANNEL_20MHZ_LOW_40MHZ_LOW),
71 CHAN5G(5200, 40, PHY_QUADRUPLE_CHANNEL_20MHZ_HIGH_40MHZ_LOW),
72 CHAN5G(5220, 44, PHY_QUADRUPLE_CHANNEL_20MHZ_LOW_40MHZ_HIGH),
73 CHAN5G(5240, 48, PHY_QUADRUPLE_CHANNEL_20MHZ_HIGH_40MHZ_HIGH),
74 CHAN5G(5260, 52, PHY_QUADRUPLE_CHANNEL_20MHZ_LOW_40MHZ_LOW),
75 CHAN5G(5280, 56, PHY_QUADRUPLE_CHANNEL_20MHZ_HIGH_40MHZ_LOW),
76 CHAN5G(5300, 60, PHY_QUADRUPLE_CHANNEL_20MHZ_LOW_40MHZ_HIGH),
77 CHAN5G(5320, 64, PHY_QUADRUPLE_CHANNEL_20MHZ_HIGH_40MHZ_HIGH),
78 CHAN5G(5500, 100, PHY_QUADRUPLE_CHANNEL_20MHZ_LOW_40MHZ_LOW),
79 CHAN5G(5520, 104, PHY_QUADRUPLE_CHANNEL_20MHZ_HIGH_40MHZ_LOW),
80 CHAN5G(5540, 108, PHY_QUADRUPLE_CHANNEL_20MHZ_LOW_40MHZ_HIGH),
81 CHAN5G(5560, 112, PHY_QUADRUPLE_CHANNEL_20MHZ_HIGH_40MHZ_HIGH),
82 CHAN5G(5580, 116, PHY_QUADRUPLE_CHANNEL_20MHZ_LOW_40MHZ_LOW),
83 CHAN5G(5600, 120, PHY_QUADRUPLE_CHANNEL_20MHZ_HIGH_40MHZ_LOW),
84 CHAN5G(5620, 124, PHY_QUADRUPLE_CHANNEL_20MHZ_LOW_40MHZ_HIGH),
85 CHAN5G(5640, 128, PHY_QUADRUPLE_CHANNEL_20MHZ_HIGH_40MHZ_HIGH),
86 CHAN5G(5660, 132, PHY_QUADRUPLE_CHANNEL_20MHZ_LOW_40MHZ_LOW),
87 CHAN5G(5700, 140, PHY_QUADRUPLE_CHANNEL_20MHZ_LOW_40MHZ_HIGH),
88 CHAN5G(5745, 149, PHY_QUADRUPLE_CHANNEL_20MHZ_LOW_40MHZ_LOW),
89 CHAN5G(5765, 153, PHY_QUADRUPLE_CHANNEL_20MHZ_HIGH_40MHZ_LOW),
90 CHAN5G(5785, 157, PHY_QUADRUPLE_CHANNEL_20MHZ_LOW_40MHZ_HIGH),
91 CHAN5G(5805, 161, PHY_QUADRUPLE_CHANNEL_20MHZ_HIGH_40MHZ_HIGH),
92 CHAN5G(5825, 165, 0)
93 };
94
95 #define RATE(_bitrate, _hw_rate, _flags) { \
96 .bitrate = (_bitrate), \
97 .flags = (_flags), \
98 .hw_value = (_hw_rate), \
99 .hw_value_short = (_hw_rate) \
100 }
101
102 static struct ieee80211_rate wcn_2ghz_rates[] = {
103 RATE(10, HW_RATE_INDEX_1MBPS, 0),
104 RATE(20, HW_RATE_INDEX_2MBPS, IEEE80211_RATE_SHORT_PREAMBLE),
105 RATE(55, HW_RATE_INDEX_5_5MBPS, IEEE80211_RATE_SHORT_PREAMBLE),
106 RATE(110, HW_RATE_INDEX_11MBPS, IEEE80211_RATE_SHORT_PREAMBLE),
107 RATE(60, HW_RATE_INDEX_6MBPS, 0),
108 RATE(90, HW_RATE_INDEX_9MBPS, 0),
109 RATE(120, HW_RATE_INDEX_12MBPS, 0),
110 RATE(180, HW_RATE_INDEX_18MBPS, 0),
111 RATE(240, HW_RATE_INDEX_24MBPS, 0),
112 RATE(360, HW_RATE_INDEX_36MBPS, 0),
113 RATE(480, HW_RATE_INDEX_48MBPS, 0),
114 RATE(540, HW_RATE_INDEX_54MBPS, 0)
115 };
116
117 static struct ieee80211_rate wcn_5ghz_rates[] = {
118 RATE(60, HW_RATE_INDEX_6MBPS, 0),
119 RATE(90, HW_RATE_INDEX_9MBPS, 0),
120 RATE(120, HW_RATE_INDEX_12MBPS, 0),
121 RATE(180, HW_RATE_INDEX_18MBPS, 0),
122 RATE(240, HW_RATE_INDEX_24MBPS, 0),
123 RATE(360, HW_RATE_INDEX_36MBPS, 0),
124 RATE(480, HW_RATE_INDEX_48MBPS, 0),
125 RATE(540, HW_RATE_INDEX_54MBPS, 0)
126 };
127
128 static struct ieee80211_supported_band wcn_band_2ghz = {
129 .channels = wcn_2ghz_channels,
130 .n_channels = ARRAY_SIZE(wcn_2ghz_channels),
131 .bitrates = wcn_2ghz_rates,
132 .n_bitrates = ARRAY_SIZE(wcn_2ghz_rates),
133 .ht_cap = {
134 .cap = IEEE80211_HT_CAP_GRN_FLD |
135 IEEE80211_HT_CAP_SGI_20 |
136 IEEE80211_HT_CAP_DSSSCCK40 |
137 IEEE80211_HT_CAP_LSIG_TXOP_PROT,
138 .ht_supported = true,
139 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
140 .ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
141 .mcs = {
142 .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
143 .rx_highest = cpu_to_le16(72),
144 .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
145 }
146 }
147 };
148
149 static struct ieee80211_supported_band wcn_band_5ghz = {
150 .channels = wcn_5ghz_channels,
151 .n_channels = ARRAY_SIZE(wcn_5ghz_channels),
152 .bitrates = wcn_5ghz_rates,
153 .n_bitrates = ARRAY_SIZE(wcn_5ghz_rates),
154 .ht_cap = {
155 .cap = IEEE80211_HT_CAP_GRN_FLD |
156 IEEE80211_HT_CAP_SGI_20 |
157 IEEE80211_HT_CAP_DSSSCCK40 |
158 IEEE80211_HT_CAP_LSIG_TXOP_PROT |
159 IEEE80211_HT_CAP_SGI_40 |
160 IEEE80211_HT_CAP_SUP_WIDTH_20_40,
161 .ht_supported = true,
162 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
163 .ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
164 .mcs = {
165 .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
166 .rx_highest = cpu_to_le16(150),
167 .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
168 }
169 }
170 };
171
172 #ifdef CONFIG_PM
173
174 static const struct wiphy_wowlan_support wowlan_support = {
175 .flags = WIPHY_WOWLAN_ANY
176 };
177
178 #endif
179
get_sta_index(struct ieee80211_vif * vif,struct wcn36xx_sta * sta_priv)180 static inline u8 get_sta_index(struct ieee80211_vif *vif,
181 struct wcn36xx_sta *sta_priv)
182 {
183 return NL80211_IFTYPE_STATION == vif->type ?
184 sta_priv->bss_sta_index :
185 sta_priv->sta_index;
186 }
187
188 static const char * const wcn36xx_caps_names[] = {
189 "MCC", /* 0 */
190 "P2P", /* 1 */
191 "DOT11AC", /* 2 */
192 "SLM_SESSIONIZATION", /* 3 */
193 "DOT11AC_OPMODE", /* 4 */
194 "SAP32STA", /* 5 */
195 "TDLS", /* 6 */
196 "P2P_GO_NOA_DECOUPLE_INIT_SCAN",/* 7 */
197 "WLANACTIVE_OFFLOAD", /* 8 */
198 "BEACON_OFFLOAD", /* 9 */
199 "SCAN_OFFLOAD", /* 10 */
200 "ROAM_OFFLOAD", /* 11 */
201 "BCN_MISS_OFFLOAD", /* 12 */
202 "STA_POWERSAVE", /* 13 */
203 "STA_ADVANCED_PWRSAVE", /* 14 */
204 "AP_UAPSD", /* 15 */
205 "AP_DFS", /* 16 */
206 "BLOCKACK", /* 17 */
207 "PHY_ERR", /* 18 */
208 "BCN_FILTER", /* 19 */
209 "RTT", /* 20 */
210 "RATECTRL", /* 21 */
211 "WOW", /* 22 */
212 "WLAN_ROAM_SCAN_OFFLOAD", /* 23 */
213 "SPECULATIVE_PS_POLL", /* 24 */
214 "SCAN_SCH", /* 25 */
215 "IBSS_HEARTBEAT_OFFLOAD", /* 26 */
216 "WLAN_SCAN_OFFLOAD", /* 27 */
217 "WLAN_PERIODIC_TX_PTRN", /* 28 */
218 "ADVANCE_TDLS", /* 29 */
219 "BATCH_SCAN", /* 30 */
220 "FW_IN_TX_PATH", /* 31 */
221 "EXTENDED_NSOFFLOAD_SLOT", /* 32 */
222 "CH_SWITCH_V1", /* 33 */
223 "HT40_OBSS_SCAN", /* 34 */
224 "UPDATE_CHANNEL_LIST", /* 35 */
225 "WLAN_MCADDR_FLT", /* 36 */
226 "WLAN_CH144", /* 37 */
227 "NAN", /* 38 */
228 "TDLS_SCAN_COEXISTENCE", /* 39 */
229 "LINK_LAYER_STATS_MEAS", /* 40 */
230 "MU_MIMO", /* 41 */
231 "EXTENDED_SCAN", /* 42 */
232 "DYNAMIC_WMM_PS", /* 43 */
233 "MAC_SPOOFED_SCAN", /* 44 */
234 "BMU_ERROR_GENERIC_RECOVERY", /* 45 */
235 "DISA", /* 46 */
236 "FW_STATS", /* 47 */
237 "WPS_PRBRSP_TMPL", /* 48 */
238 "BCN_IE_FLT_DELTA", /* 49 */
239 "TDLS_OFF_CHANNEL", /* 51 */
240 "RTT3", /* 52 */
241 "MGMT_FRAME_LOGGING", /* 53 */
242 "ENHANCED_TXBD_COMPLETION", /* 54 */
243 "LOGGING_ENHANCEMENT", /* 55 */
244 "EXT_SCAN_ENHANCED", /* 56 */
245 "MEMORY_DUMP_SUPPORTED", /* 57 */
246 "PER_PKT_STATS_SUPPORTED", /* 58 */
247 "EXT_LL_STAT", /* 60 */
248 "WIFI_CONFIG", /* 61 */
249 "ANTENNA_DIVERSITY_SELECTION", /* 62 */
250 };
251
wcn36xx_get_cap_name(enum place_holder_in_cap_bitmap x)252 static const char *wcn36xx_get_cap_name(enum place_holder_in_cap_bitmap x)
253 {
254 if (x >= ARRAY_SIZE(wcn36xx_caps_names))
255 return "UNKNOWN";
256 return wcn36xx_caps_names[x];
257 }
258
wcn36xx_feat_caps_info(struct wcn36xx * wcn)259 static void wcn36xx_feat_caps_info(struct wcn36xx *wcn)
260 {
261 int i;
262
263 for (i = 0; i < MAX_FEATURE_SUPPORTED; i++) {
264 if (get_feat_caps(wcn->fw_feat_caps, i))
265 wcn36xx_dbg(WCN36XX_DBG_MAC, "FW Cap %s\n", wcn36xx_get_cap_name(i));
266 }
267 }
268
wcn36xx_start(struct ieee80211_hw * hw)269 static int wcn36xx_start(struct ieee80211_hw *hw)
270 {
271 struct wcn36xx *wcn = hw->priv;
272 int ret;
273
274 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac start\n");
275
276 /* SMD initialization */
277 ret = wcn36xx_smd_open(wcn);
278 if (ret) {
279 wcn36xx_err("Failed to open smd channel: %d\n", ret);
280 goto out_err;
281 }
282
283 /* Allocate memory pools for Mgmt BD headers and Data BD headers */
284 ret = wcn36xx_dxe_allocate_mem_pools(wcn);
285 if (ret) {
286 wcn36xx_err("Failed to alloc DXE mempool: %d\n", ret);
287 goto out_smd_close;
288 }
289
290 ret = wcn36xx_dxe_alloc_ctl_blks(wcn);
291 if (ret) {
292 wcn36xx_err("Failed to alloc DXE ctl blocks: %d\n", ret);
293 goto out_free_dxe_pool;
294 }
295
296 ret = wcn36xx_smd_load_nv(wcn);
297 if (ret) {
298 wcn36xx_err("Failed to push NV to chip\n");
299 goto out_free_dxe_ctl;
300 }
301
302 ret = wcn36xx_smd_start(wcn);
303 if (ret) {
304 wcn36xx_err("Failed to start chip\n");
305 goto out_free_dxe_ctl;
306 }
307
308 if (!wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) {
309 ret = wcn36xx_smd_feature_caps_exchange(wcn);
310 if (ret)
311 wcn36xx_warn("Exchange feature caps failed\n");
312 else
313 wcn36xx_feat_caps_info(wcn);
314 }
315
316 /* DMA channel initialization */
317 ret = wcn36xx_dxe_init(wcn);
318 if (ret) {
319 wcn36xx_err("DXE init failed\n");
320 goto out_smd_stop;
321 }
322
323 wcn36xx_debugfs_init(wcn);
324
325 INIT_LIST_HEAD(&wcn->vif_list);
326 spin_lock_init(&wcn->dxe_lock);
327
328 return 0;
329
330 out_smd_stop:
331 wcn36xx_smd_stop(wcn);
332 out_free_dxe_ctl:
333 wcn36xx_dxe_free_ctl_blks(wcn);
334 out_free_dxe_pool:
335 wcn36xx_dxe_free_mem_pools(wcn);
336 out_smd_close:
337 wcn36xx_smd_close(wcn);
338 out_err:
339 return ret;
340 }
341
wcn36xx_stop(struct ieee80211_hw * hw)342 static void wcn36xx_stop(struct ieee80211_hw *hw)
343 {
344 struct wcn36xx *wcn = hw->priv;
345
346 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac stop\n");
347
348 mutex_lock(&wcn->scan_lock);
349 if (wcn->scan_req) {
350 struct cfg80211_scan_info scan_info = {
351 .aborted = true,
352 };
353
354 ieee80211_scan_completed(wcn->hw, &scan_info);
355 }
356 wcn->scan_req = NULL;
357 mutex_unlock(&wcn->scan_lock);
358
359 wcn36xx_debugfs_exit(wcn);
360 wcn36xx_smd_stop(wcn);
361 wcn36xx_dxe_deinit(wcn);
362 wcn36xx_smd_close(wcn);
363
364 wcn36xx_dxe_free_mem_pools(wcn);
365 wcn36xx_dxe_free_ctl_blks(wcn);
366 }
367
wcn36xx_change_ps(struct wcn36xx * wcn,bool enable)368 static void wcn36xx_change_ps(struct wcn36xx *wcn, bool enable)
369 {
370 struct ieee80211_vif *vif = NULL;
371 struct wcn36xx_vif *tmp;
372
373 list_for_each_entry(tmp, &wcn->vif_list, list) {
374 vif = wcn36xx_priv_to_vif(tmp);
375 if (enable && !wcn->sw_scan) {
376 if (vif->bss_conf.ps) /* ps allowed ? */
377 wcn36xx_pmc_enter_bmps_state(wcn, vif);
378 } else {
379 wcn36xx_pmc_exit_bmps_state(wcn, vif);
380 }
381 }
382 }
383
wcn36xx_change_opchannel(struct wcn36xx * wcn,int ch)384 static void wcn36xx_change_opchannel(struct wcn36xx *wcn, int ch)
385 {
386 struct ieee80211_vif *vif = NULL;
387 struct wcn36xx_vif *tmp;
388
389 list_for_each_entry(tmp, &wcn->vif_list, list) {
390 vif = wcn36xx_priv_to_vif(tmp);
391 wcn36xx_smd_switch_channel(wcn, vif, ch);
392 }
393 }
394
wcn36xx_config(struct ieee80211_hw * hw,u32 changed)395 static int wcn36xx_config(struct ieee80211_hw *hw, u32 changed)
396 {
397 struct wcn36xx *wcn = hw->priv;
398
399 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac config changed 0x%08x\n", changed);
400
401 mutex_lock(&wcn->conf_mutex);
402
403 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
404 int ch = WCN36XX_HW_CHANNEL(wcn);
405 wcn36xx_dbg(WCN36XX_DBG_MAC, "wcn36xx_config channel switch=%d\n",
406 ch);
407
408 if (wcn->sw_scan_opchannel == ch && wcn->sw_scan_channel) {
409 /* If channel is the initial operating channel, we may
410 * want to receive/transmit regular data packets, then
411 * simply stop the scan session and exit PS mode.
412 */
413 wcn36xx_smd_finish_scan(wcn, HAL_SYS_MODE_SCAN,
414 wcn->sw_scan_vif);
415 wcn->sw_scan_channel = 0;
416 } else if (wcn->sw_scan) {
417 /* A scan is ongoing, do not change the operating
418 * channel, but start a scan session on the channel.
419 */
420 wcn36xx_smd_init_scan(wcn, HAL_SYS_MODE_SCAN,
421 wcn->sw_scan_vif);
422 wcn36xx_smd_start_scan(wcn, ch);
423 wcn->sw_scan_channel = ch;
424 } else {
425 wcn36xx_change_opchannel(wcn, ch);
426 }
427 }
428
429 if (changed & IEEE80211_CONF_CHANGE_PS)
430 wcn36xx_change_ps(wcn, hw->conf.flags & IEEE80211_CONF_PS);
431
432 mutex_unlock(&wcn->conf_mutex);
433
434 return 0;
435 }
436
wcn36xx_configure_filter(struct ieee80211_hw * hw,unsigned int changed,unsigned int * total,u64 multicast)437 static void wcn36xx_configure_filter(struct ieee80211_hw *hw,
438 unsigned int changed,
439 unsigned int *total, u64 multicast)
440 {
441 struct wcn36xx_hal_rcv_flt_mc_addr_list_type *fp;
442 struct wcn36xx *wcn = hw->priv;
443 struct wcn36xx_vif *tmp;
444 struct ieee80211_vif *vif = NULL;
445
446 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac configure filter\n");
447
448 mutex_lock(&wcn->conf_mutex);
449
450 *total &= FIF_ALLMULTI;
451
452 fp = (void *)(unsigned long)multicast;
453 list_for_each_entry(tmp, &wcn->vif_list, list) {
454 vif = wcn36xx_priv_to_vif(tmp);
455
456 /* FW handles MC filtering only when connected as STA */
457 if (*total & FIF_ALLMULTI)
458 wcn36xx_smd_set_mc_list(wcn, vif, NULL);
459 else if (NL80211_IFTYPE_STATION == vif->type && tmp->sta_assoc)
460 wcn36xx_smd_set_mc_list(wcn, vif, fp);
461 }
462
463 mutex_unlock(&wcn->conf_mutex);
464 kfree(fp);
465 }
466
wcn36xx_prepare_multicast(struct ieee80211_hw * hw,struct netdev_hw_addr_list * mc_list)467 static u64 wcn36xx_prepare_multicast(struct ieee80211_hw *hw,
468 struct netdev_hw_addr_list *mc_list)
469 {
470 struct wcn36xx_hal_rcv_flt_mc_addr_list_type *fp;
471 struct netdev_hw_addr *ha;
472
473 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac prepare multicast list\n");
474 fp = kzalloc(sizeof(*fp), GFP_ATOMIC);
475 if (!fp) {
476 wcn36xx_err("Out of memory setting filters.\n");
477 return 0;
478 }
479
480 fp->mc_addr_count = 0;
481 /* update multicast filtering parameters */
482 if (netdev_hw_addr_list_count(mc_list) <=
483 WCN36XX_HAL_MAX_NUM_MULTICAST_ADDRESS) {
484 netdev_hw_addr_list_for_each(ha, mc_list) {
485 memcpy(fp->mc_addr[fp->mc_addr_count],
486 ha->addr, ETH_ALEN);
487 fp->mc_addr_count++;
488 }
489 }
490
491 return (u64)(unsigned long)fp;
492 }
493
wcn36xx_tx(struct ieee80211_hw * hw,struct ieee80211_tx_control * control,struct sk_buff * skb)494 static void wcn36xx_tx(struct ieee80211_hw *hw,
495 struct ieee80211_tx_control *control,
496 struct sk_buff *skb)
497 {
498 struct wcn36xx *wcn = hw->priv;
499 struct wcn36xx_sta *sta_priv = NULL;
500
501 if (control->sta)
502 sta_priv = wcn36xx_sta_to_priv(control->sta);
503
504 if (wcn36xx_start_tx(wcn, sta_priv, skb))
505 ieee80211_free_txskb(wcn->hw, skb);
506 }
507
wcn36xx_set_key(struct ieee80211_hw * hw,enum set_key_cmd cmd,struct ieee80211_vif * vif,struct ieee80211_sta * sta,struct ieee80211_key_conf * key_conf)508 static int wcn36xx_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
509 struct ieee80211_vif *vif,
510 struct ieee80211_sta *sta,
511 struct ieee80211_key_conf *key_conf)
512 {
513 struct wcn36xx *wcn = hw->priv;
514 struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
515 struct wcn36xx_sta *sta_priv = sta ? wcn36xx_sta_to_priv(sta) : NULL;
516 int ret = 0;
517 u8 key[WLAN_MAX_KEY_LEN];
518
519 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac80211 set key\n");
520 wcn36xx_dbg(WCN36XX_DBG_MAC, "Key: cmd=0x%x algo:0x%x, id:%d, len:%d flags 0x%x\n",
521 cmd, key_conf->cipher, key_conf->keyidx,
522 key_conf->keylen, key_conf->flags);
523 wcn36xx_dbg_dump(WCN36XX_DBG_MAC, "KEY: ",
524 key_conf->key,
525 key_conf->keylen);
526
527 mutex_lock(&wcn->conf_mutex);
528
529 switch (key_conf->cipher) {
530 case WLAN_CIPHER_SUITE_WEP40:
531 vif_priv->encrypt_type = WCN36XX_HAL_ED_WEP40;
532 break;
533 case WLAN_CIPHER_SUITE_WEP104:
534 vif_priv->encrypt_type = WCN36XX_HAL_ED_WEP104;
535 break;
536 case WLAN_CIPHER_SUITE_CCMP:
537 vif_priv->encrypt_type = WCN36XX_HAL_ED_CCMP;
538 break;
539 case WLAN_CIPHER_SUITE_TKIP:
540 vif_priv->encrypt_type = WCN36XX_HAL_ED_TKIP;
541 break;
542 default:
543 wcn36xx_err("Unsupported key type 0x%x\n",
544 key_conf->cipher);
545 ret = -EOPNOTSUPP;
546 goto out;
547 }
548
549 switch (cmd) {
550 case SET_KEY:
551 if (WCN36XX_HAL_ED_TKIP == vif_priv->encrypt_type) {
552 /*
553 * Supplicant is sending key in the wrong order:
554 * Temporal Key (16 b) - TX MIC (8 b) - RX MIC (8 b)
555 * but HW expects it to be in the order as described in
556 * IEEE 802.11 spec (see chapter 11.7) like this:
557 * Temporal Key (16 b) - RX MIC (8 b) - TX MIC (8 b)
558 */
559 memcpy(key, key_conf->key, 16);
560 memcpy(key + 16, key_conf->key + 24, 8);
561 memcpy(key + 24, key_conf->key + 16, 8);
562 } else {
563 memcpy(key, key_conf->key, key_conf->keylen);
564 }
565
566 if (IEEE80211_KEY_FLAG_PAIRWISE & key_conf->flags) {
567 sta_priv->is_data_encrypted = true;
568 /* Reconfigure bss with encrypt_type */
569 if (NL80211_IFTYPE_STATION == vif->type)
570 wcn36xx_smd_config_bss(wcn,
571 vif,
572 sta,
573 sta->addr,
574 true);
575
576 wcn36xx_smd_set_stakey(wcn,
577 vif_priv->encrypt_type,
578 key_conf->keyidx,
579 key_conf->keylen,
580 key,
581 get_sta_index(vif, sta_priv));
582 } else {
583 wcn36xx_smd_set_bsskey(wcn,
584 vif_priv->encrypt_type,
585 vif_priv->bss_index,
586 key_conf->keyidx,
587 key_conf->keylen,
588 key);
589
590 if ((WLAN_CIPHER_SUITE_WEP40 == key_conf->cipher) ||
591 (WLAN_CIPHER_SUITE_WEP104 == key_conf->cipher)) {
592 list_for_each_entry(sta_priv,
593 &vif_priv->sta_list, list) {
594 sta_priv->is_data_encrypted = true;
595 wcn36xx_smd_set_stakey(wcn,
596 vif_priv->encrypt_type,
597 key_conf->keyidx,
598 key_conf->keylen,
599 key,
600 get_sta_index(vif, sta_priv));
601 }
602 }
603 }
604 break;
605 case DISABLE_KEY:
606 if (!(IEEE80211_KEY_FLAG_PAIRWISE & key_conf->flags)) {
607 if (vif_priv->bss_index != WCN36XX_HAL_BSS_INVALID_IDX)
608 wcn36xx_smd_remove_bsskey(wcn,
609 vif_priv->encrypt_type,
610 vif_priv->bss_index,
611 key_conf->keyidx);
612
613 vif_priv->encrypt_type = WCN36XX_HAL_ED_NONE;
614 } else {
615 sta_priv->is_data_encrypted = false;
616 /* do not remove key if disassociated */
617 if (sta_priv->aid)
618 wcn36xx_smd_remove_stakey(wcn,
619 vif_priv->encrypt_type,
620 key_conf->keyidx,
621 get_sta_index(vif, sta_priv));
622 }
623 break;
624 default:
625 wcn36xx_err("Unsupported key cmd 0x%x\n", cmd);
626 ret = -EOPNOTSUPP;
627 goto out;
628 }
629
630 out:
631 mutex_unlock(&wcn->conf_mutex);
632
633 return ret;
634 }
635
wcn36xx_hw_scan(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_scan_request * hw_req)636 static int wcn36xx_hw_scan(struct ieee80211_hw *hw,
637 struct ieee80211_vif *vif,
638 struct ieee80211_scan_request *hw_req)
639 {
640 struct wcn36xx *wcn = hw->priv;
641 int i;
642
643 if (!get_feat_caps(wcn->fw_feat_caps, SCAN_OFFLOAD)) {
644 /* fallback to mac80211 software scan */
645 return 1;
646 }
647
648 /* For unknown reason, the hardware offloaded scan only works with
649 * 2.4Ghz channels, fallback to software scan in other cases.
650 */
651 for (i = 0; i < hw_req->req.n_channels; i++) {
652 if (hw_req->req.channels[i]->band != NL80211_BAND_2GHZ)
653 return 1;
654 }
655
656 mutex_lock(&wcn->scan_lock);
657 if (wcn->scan_req) {
658 mutex_unlock(&wcn->scan_lock);
659 return -EBUSY;
660 }
661
662 wcn->scan_aborted = false;
663 wcn->scan_req = &hw_req->req;
664
665 mutex_unlock(&wcn->scan_lock);
666
667 return wcn36xx_smd_start_hw_scan(wcn, vif, &hw_req->req);
668 }
669
wcn36xx_cancel_hw_scan(struct ieee80211_hw * hw,struct ieee80211_vif * vif)670 static void wcn36xx_cancel_hw_scan(struct ieee80211_hw *hw,
671 struct ieee80211_vif *vif)
672 {
673 struct wcn36xx *wcn = hw->priv;
674
675 mutex_lock(&wcn->scan_lock);
676 wcn->scan_aborted = true;
677 mutex_unlock(&wcn->scan_lock);
678
679 if (get_feat_caps(wcn->fw_feat_caps, SCAN_OFFLOAD)) {
680 /* ieee80211_scan_completed will be called on FW scan
681 * indication */
682 wcn36xx_smd_stop_hw_scan(wcn);
683 }
684 }
685
wcn36xx_sw_scan_start(struct ieee80211_hw * hw,struct ieee80211_vif * vif,const u8 * mac_addr)686 static void wcn36xx_sw_scan_start(struct ieee80211_hw *hw,
687 struct ieee80211_vif *vif,
688 const u8 *mac_addr)
689 {
690 struct wcn36xx *wcn = hw->priv;
691 struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
692
693 wcn->sw_scan = true;
694 wcn->sw_scan_vif = vif;
695 wcn->sw_scan_channel = 0;
696 if (vif_priv->sta_assoc)
697 wcn->sw_scan_opchannel = WCN36XX_HW_CHANNEL(wcn);
698 else
699 wcn->sw_scan_opchannel = 0;
700 }
701
wcn36xx_sw_scan_complete(struct ieee80211_hw * hw,struct ieee80211_vif * vif)702 static void wcn36xx_sw_scan_complete(struct ieee80211_hw *hw,
703 struct ieee80211_vif *vif)
704 {
705 struct wcn36xx *wcn = hw->priv;
706
707 /* ensure that any scan session is finished */
708 wcn36xx_smd_finish_scan(wcn, HAL_SYS_MODE_SCAN, wcn->sw_scan_vif);
709 wcn->sw_scan = false;
710 wcn->sw_scan_opchannel = 0;
711 }
712
wcn36xx_update_allowed_rates(struct ieee80211_sta * sta,enum nl80211_band band)713 static void wcn36xx_update_allowed_rates(struct ieee80211_sta *sta,
714 enum nl80211_band band)
715 {
716 int i, size;
717 u16 *rates_table;
718 struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(sta);
719 u32 rates = sta->supp_rates[band];
720
721 memset(&sta_priv->supported_rates, 0,
722 sizeof(sta_priv->supported_rates));
723 sta_priv->supported_rates.op_rate_mode = STA_11n;
724
725 size = ARRAY_SIZE(sta_priv->supported_rates.dsss_rates);
726 rates_table = sta_priv->supported_rates.dsss_rates;
727 if (band == NL80211_BAND_2GHZ) {
728 for (i = 0; i < size; i++) {
729 if (rates & 0x01) {
730 rates_table[i] = wcn_2ghz_rates[i].hw_value;
731 rates = rates >> 1;
732 }
733 }
734 }
735
736 size = ARRAY_SIZE(sta_priv->supported_rates.ofdm_rates);
737 rates_table = sta_priv->supported_rates.ofdm_rates;
738 for (i = 0; i < size; i++) {
739 if (rates & 0x01) {
740 rates_table[i] = wcn_5ghz_rates[i].hw_value;
741 rates = rates >> 1;
742 }
743 }
744
745 if (sta->ht_cap.ht_supported) {
746 BUILD_BUG_ON(sizeof(sta->ht_cap.mcs.rx_mask) >
747 sizeof(sta_priv->supported_rates.supported_mcs_set));
748 memcpy(sta_priv->supported_rates.supported_mcs_set,
749 sta->ht_cap.mcs.rx_mask,
750 sizeof(sta->ht_cap.mcs.rx_mask));
751 }
752
753 if (sta->vht_cap.vht_supported) {
754 sta_priv->supported_rates.op_rate_mode = STA_11ac;
755 sta_priv->supported_rates.vht_rx_mcs_map =
756 sta->vht_cap.vht_mcs.rx_mcs_map;
757 sta_priv->supported_rates.vht_tx_mcs_map =
758 sta->vht_cap.vht_mcs.tx_mcs_map;
759 }
760 }
761
wcn36xx_set_default_rates(struct wcn36xx_hal_supported_rates * rates)762 void wcn36xx_set_default_rates(struct wcn36xx_hal_supported_rates *rates)
763 {
764 u16 ofdm_rates[WCN36XX_HAL_NUM_OFDM_RATES] = {
765 HW_RATE_INDEX_6MBPS,
766 HW_RATE_INDEX_9MBPS,
767 HW_RATE_INDEX_12MBPS,
768 HW_RATE_INDEX_18MBPS,
769 HW_RATE_INDEX_24MBPS,
770 HW_RATE_INDEX_36MBPS,
771 HW_RATE_INDEX_48MBPS,
772 HW_RATE_INDEX_54MBPS
773 };
774 u16 dsss_rates[WCN36XX_HAL_NUM_DSSS_RATES] = {
775 HW_RATE_INDEX_1MBPS,
776 HW_RATE_INDEX_2MBPS,
777 HW_RATE_INDEX_5_5MBPS,
778 HW_RATE_INDEX_11MBPS
779 };
780
781 rates->op_rate_mode = STA_11n;
782 memcpy(rates->dsss_rates, dsss_rates,
783 sizeof(*dsss_rates) * WCN36XX_HAL_NUM_DSSS_RATES);
784 memcpy(rates->ofdm_rates, ofdm_rates,
785 sizeof(*ofdm_rates) * WCN36XX_HAL_NUM_OFDM_RATES);
786 rates->supported_mcs_set[0] = 0xFF;
787 }
788
wcn36xx_set_default_rates_v1(struct wcn36xx_hal_supported_rates_v1 * rates)789 void wcn36xx_set_default_rates_v1(struct wcn36xx_hal_supported_rates_v1 *rates)
790 {
791 rates->op_rate_mode = STA_11ac;
792 rates->vht_rx_mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9;
793 rates->vht_tx_mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9;
794 }
795
wcn36xx_bss_info_changed(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * bss_conf,u32 changed)796 static void wcn36xx_bss_info_changed(struct ieee80211_hw *hw,
797 struct ieee80211_vif *vif,
798 struct ieee80211_bss_conf *bss_conf,
799 u32 changed)
800 {
801 struct wcn36xx *wcn = hw->priv;
802 struct sk_buff *skb = NULL;
803 u16 tim_off, tim_len;
804 enum wcn36xx_hal_link_state link_state;
805 struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
806
807 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac bss info changed vif %p changed 0x%08x\n",
808 vif, changed);
809
810 mutex_lock(&wcn->conf_mutex);
811
812 if (changed & BSS_CHANGED_BEACON_INFO) {
813 wcn36xx_dbg(WCN36XX_DBG_MAC,
814 "mac bss changed dtim period %d\n",
815 bss_conf->dtim_period);
816
817 vif_priv->dtim_period = bss_conf->dtim_period;
818 }
819
820 if (changed & BSS_CHANGED_BSSID) {
821 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac bss changed_bssid %pM\n",
822 bss_conf->bssid);
823
824 if (!is_zero_ether_addr(bss_conf->bssid)) {
825 vif_priv->is_joining = true;
826 vif_priv->bss_index = WCN36XX_HAL_BSS_INVALID_IDX;
827 wcn36xx_smd_set_link_st(wcn, bss_conf->bssid, vif->addr,
828 WCN36XX_HAL_LINK_PREASSOC_STATE);
829 wcn36xx_smd_join(wcn, bss_conf->bssid,
830 vif->addr, WCN36XX_HW_CHANNEL(wcn));
831 wcn36xx_smd_config_bss(wcn, vif, NULL,
832 bss_conf->bssid, false);
833 } else {
834 vif_priv->is_joining = false;
835 wcn36xx_smd_delete_bss(wcn, vif);
836 wcn36xx_smd_set_link_st(wcn, bss_conf->bssid, vif->addr,
837 WCN36XX_HAL_LINK_IDLE_STATE);
838 vif_priv->encrypt_type = WCN36XX_HAL_ED_NONE;
839 }
840 }
841
842 if (changed & BSS_CHANGED_SSID) {
843 wcn36xx_dbg(WCN36XX_DBG_MAC,
844 "mac bss changed ssid\n");
845 wcn36xx_dbg_dump(WCN36XX_DBG_MAC, "ssid ",
846 bss_conf->ssid, bss_conf->ssid_len);
847
848 vif_priv->ssid.length = bss_conf->ssid_len;
849 memcpy(&vif_priv->ssid.ssid,
850 bss_conf->ssid,
851 bss_conf->ssid_len);
852 }
853
854 if (changed & BSS_CHANGED_ASSOC) {
855 vif_priv->is_joining = false;
856 if (bss_conf->assoc) {
857 struct ieee80211_sta *sta;
858 struct wcn36xx_sta *sta_priv;
859
860 wcn36xx_dbg(WCN36XX_DBG_MAC,
861 "mac assoc bss %pM vif %pM AID=%d\n",
862 bss_conf->bssid,
863 vif->addr,
864 bss_conf->aid);
865
866 vif_priv->sta_assoc = true;
867
868 /*
869 * Holding conf_mutex ensures mutal exclusion with
870 * wcn36xx_sta_remove() and as such ensures that sta
871 * won't be freed while we're operating on it. As such
872 * we do not need to hold the rcu_read_lock().
873 */
874 sta = ieee80211_find_sta(vif, bss_conf->bssid);
875 if (!sta) {
876 wcn36xx_err("sta %pM is not found\n",
877 bss_conf->bssid);
878 goto out;
879 }
880 sta_priv = wcn36xx_sta_to_priv(sta);
881
882 wcn36xx_update_allowed_rates(sta, WCN36XX_BAND(wcn));
883
884 wcn36xx_smd_set_link_st(wcn, bss_conf->bssid,
885 vif->addr,
886 WCN36XX_HAL_LINK_POSTASSOC_STATE);
887 wcn36xx_smd_config_bss(wcn, vif, sta,
888 bss_conf->bssid,
889 true);
890 sta_priv->aid = bss_conf->aid;
891 /*
892 * config_sta must be called from because this is the
893 * place where AID is available.
894 */
895 wcn36xx_smd_config_sta(wcn, vif, sta);
896 } else {
897 wcn36xx_dbg(WCN36XX_DBG_MAC,
898 "disassociated bss %pM vif %pM AID=%d\n",
899 bss_conf->bssid,
900 vif->addr,
901 bss_conf->aid);
902 vif_priv->sta_assoc = false;
903 wcn36xx_smd_set_link_st(wcn,
904 bss_conf->bssid,
905 vif->addr,
906 WCN36XX_HAL_LINK_IDLE_STATE);
907 }
908 }
909
910 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
911 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac bss changed ap probe resp\n");
912 skb = ieee80211_proberesp_get(hw, vif);
913 if (!skb) {
914 wcn36xx_err("failed to alloc probereq skb\n");
915 goto out;
916 }
917
918 wcn36xx_smd_update_proberesp_tmpl(wcn, vif, skb);
919 dev_kfree_skb(skb);
920 }
921
922 if (changed & BSS_CHANGED_BEACON_ENABLED ||
923 changed & BSS_CHANGED_BEACON) {
924 wcn36xx_dbg(WCN36XX_DBG_MAC,
925 "mac bss changed beacon enabled %d\n",
926 bss_conf->enable_beacon);
927
928 if (bss_conf->enable_beacon) {
929 vif_priv->dtim_period = bss_conf->dtim_period;
930 vif_priv->bss_index = WCN36XX_HAL_BSS_INVALID_IDX;
931 wcn36xx_smd_config_bss(wcn, vif, NULL,
932 vif->addr, false);
933 skb = ieee80211_beacon_get_tim(hw, vif, &tim_off,
934 &tim_len);
935 if (!skb) {
936 wcn36xx_err("failed to alloc beacon skb\n");
937 goto out;
938 }
939 wcn36xx_smd_send_beacon(wcn, vif, skb, tim_off, 0);
940 dev_kfree_skb(skb);
941
942 if (vif->type == NL80211_IFTYPE_ADHOC ||
943 vif->type == NL80211_IFTYPE_MESH_POINT)
944 link_state = WCN36XX_HAL_LINK_IBSS_STATE;
945 else
946 link_state = WCN36XX_HAL_LINK_AP_STATE;
947
948 wcn36xx_smd_set_link_st(wcn, vif->addr, vif->addr,
949 link_state);
950 } else {
951 wcn36xx_smd_delete_bss(wcn, vif);
952 wcn36xx_smd_set_link_st(wcn, vif->addr, vif->addr,
953 WCN36XX_HAL_LINK_IDLE_STATE);
954 }
955 }
956 out:
957
958 mutex_unlock(&wcn->conf_mutex);
959 }
960
961 /* this is required when using IEEE80211_HW_HAS_RATE_CONTROL */
wcn36xx_set_rts_threshold(struct ieee80211_hw * hw,u32 value)962 static int wcn36xx_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
963 {
964 struct wcn36xx *wcn = hw->priv;
965 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac set RTS threshold %d\n", value);
966
967 mutex_lock(&wcn->conf_mutex);
968 wcn36xx_smd_update_cfg(wcn, WCN36XX_HAL_CFG_RTS_THRESHOLD, value);
969 mutex_unlock(&wcn->conf_mutex);
970
971 return 0;
972 }
973
wcn36xx_remove_interface(struct ieee80211_hw * hw,struct ieee80211_vif * vif)974 static void wcn36xx_remove_interface(struct ieee80211_hw *hw,
975 struct ieee80211_vif *vif)
976 {
977 struct wcn36xx *wcn = hw->priv;
978 struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
979 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac remove interface vif %p\n", vif);
980
981 mutex_lock(&wcn->conf_mutex);
982
983 list_del(&vif_priv->list);
984 wcn36xx_smd_delete_sta_self(wcn, vif->addr);
985
986 mutex_unlock(&wcn->conf_mutex);
987 }
988
wcn36xx_add_interface(struct ieee80211_hw * hw,struct ieee80211_vif * vif)989 static int wcn36xx_add_interface(struct ieee80211_hw *hw,
990 struct ieee80211_vif *vif)
991 {
992 struct wcn36xx *wcn = hw->priv;
993 struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
994
995 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac add interface vif %p type %d\n",
996 vif, vif->type);
997
998 if (!(NL80211_IFTYPE_STATION == vif->type ||
999 NL80211_IFTYPE_AP == vif->type ||
1000 NL80211_IFTYPE_ADHOC == vif->type ||
1001 NL80211_IFTYPE_MESH_POINT == vif->type)) {
1002 wcn36xx_warn("Unsupported interface type requested: %d\n",
1003 vif->type);
1004 return -EOPNOTSUPP;
1005 }
1006
1007 mutex_lock(&wcn->conf_mutex);
1008
1009 vif_priv->bss_index = WCN36XX_HAL_BSS_INVALID_IDX;
1010 INIT_LIST_HEAD(&vif_priv->sta_list);
1011 list_add(&vif_priv->list, &wcn->vif_list);
1012 wcn36xx_smd_add_sta_self(wcn, vif);
1013
1014 mutex_unlock(&wcn->conf_mutex);
1015
1016 return 0;
1017 }
1018
wcn36xx_sta_add(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_sta * sta)1019 static int wcn36xx_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1020 struct ieee80211_sta *sta)
1021 {
1022 struct wcn36xx *wcn = hw->priv;
1023 struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
1024 struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(sta);
1025 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac sta add vif %p sta %pM\n",
1026 vif, sta->addr);
1027
1028 mutex_lock(&wcn->conf_mutex);
1029
1030 spin_lock_init(&sta_priv->ampdu_lock);
1031 sta_priv->vif = vif_priv;
1032 list_add(&sta_priv->list, &vif_priv->sta_list);
1033
1034 /*
1035 * For STA mode HW will be configured on BSS_CHANGED_ASSOC because
1036 * at this stage AID is not available yet.
1037 */
1038 if (NL80211_IFTYPE_STATION != vif->type) {
1039 wcn36xx_update_allowed_rates(sta, WCN36XX_BAND(wcn));
1040 sta_priv->aid = sta->aid;
1041 wcn36xx_smd_config_sta(wcn, vif, sta);
1042 }
1043
1044 mutex_unlock(&wcn->conf_mutex);
1045
1046 return 0;
1047 }
1048
wcn36xx_sta_remove(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_sta * sta)1049 static int wcn36xx_sta_remove(struct ieee80211_hw *hw,
1050 struct ieee80211_vif *vif,
1051 struct ieee80211_sta *sta)
1052 {
1053 struct wcn36xx *wcn = hw->priv;
1054 struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(sta);
1055
1056 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac sta remove vif %p sta %pM index %d\n",
1057 vif, sta->addr, sta_priv->sta_index);
1058
1059 mutex_lock(&wcn->conf_mutex);
1060
1061 list_del(&sta_priv->list);
1062 wcn36xx_smd_delete_sta(wcn, sta_priv->sta_index);
1063 sta_priv->vif = NULL;
1064
1065 mutex_unlock(&wcn->conf_mutex);
1066
1067 return 0;
1068 }
1069
1070 #ifdef CONFIG_PM
1071
wcn36xx_suspend(struct ieee80211_hw * hw,struct cfg80211_wowlan * wow)1072 static int wcn36xx_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wow)
1073 {
1074 struct wcn36xx *wcn = hw->priv;
1075
1076 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac suspend\n");
1077
1078 flush_workqueue(wcn->hal_ind_wq);
1079 wcn36xx_smd_set_power_params(wcn, true);
1080 return 0;
1081 }
1082
wcn36xx_resume(struct ieee80211_hw * hw)1083 static int wcn36xx_resume(struct ieee80211_hw *hw)
1084 {
1085 struct wcn36xx *wcn = hw->priv;
1086
1087 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac resume\n");
1088
1089 flush_workqueue(wcn->hal_ind_wq);
1090 wcn36xx_smd_set_power_params(wcn, false);
1091 return 0;
1092 }
1093
1094 #endif
1095
wcn36xx_ampdu_action(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_ampdu_params * params)1096 static int wcn36xx_ampdu_action(struct ieee80211_hw *hw,
1097 struct ieee80211_vif *vif,
1098 struct ieee80211_ampdu_params *params)
1099 {
1100 struct wcn36xx *wcn = hw->priv;
1101 struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(params->sta);
1102 struct ieee80211_sta *sta = params->sta;
1103 enum ieee80211_ampdu_mlme_action action = params->action;
1104 u16 tid = params->tid;
1105 u16 *ssn = ¶ms->ssn;
1106 int ret = 0;
1107 u8 session;
1108
1109 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac ampdu action action %d tid %d\n",
1110 action, tid);
1111
1112 mutex_lock(&wcn->conf_mutex);
1113
1114 switch (action) {
1115 case IEEE80211_AMPDU_RX_START:
1116 sta_priv->tid = tid;
1117 session = wcn36xx_smd_add_ba_session(wcn, sta, tid, ssn, 0,
1118 get_sta_index(vif, sta_priv));
1119 wcn36xx_smd_add_ba(wcn, session);
1120 wcn36xx_smd_trigger_ba(wcn, get_sta_index(vif, sta_priv), tid,
1121 session);
1122 break;
1123 case IEEE80211_AMPDU_RX_STOP:
1124 wcn36xx_smd_del_ba(wcn, tid, get_sta_index(vif, sta_priv));
1125 break;
1126 case IEEE80211_AMPDU_TX_START:
1127 spin_lock_bh(&sta_priv->ampdu_lock);
1128 sta_priv->ampdu_state[tid] = WCN36XX_AMPDU_START;
1129 spin_unlock_bh(&sta_priv->ampdu_lock);
1130
1131 ret = IEEE80211_AMPDU_TX_START_IMMEDIATE;
1132 break;
1133 case IEEE80211_AMPDU_TX_OPERATIONAL:
1134 spin_lock_bh(&sta_priv->ampdu_lock);
1135 sta_priv->ampdu_state[tid] = WCN36XX_AMPDU_OPERATIONAL;
1136 spin_unlock_bh(&sta_priv->ampdu_lock);
1137
1138 wcn36xx_smd_add_ba_session(wcn, sta, tid, ssn, 1,
1139 get_sta_index(vif, sta_priv));
1140 break;
1141 case IEEE80211_AMPDU_TX_STOP_FLUSH:
1142 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
1143 case IEEE80211_AMPDU_TX_STOP_CONT:
1144 spin_lock_bh(&sta_priv->ampdu_lock);
1145 sta_priv->ampdu_state[tid] = WCN36XX_AMPDU_NONE;
1146 spin_unlock_bh(&sta_priv->ampdu_lock);
1147
1148 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1149 break;
1150 default:
1151 wcn36xx_err("Unknown AMPDU action\n");
1152 }
1153
1154 mutex_unlock(&wcn->conf_mutex);
1155
1156 return ret;
1157 }
1158
1159 static const struct ieee80211_ops wcn36xx_ops = {
1160 .start = wcn36xx_start,
1161 .stop = wcn36xx_stop,
1162 .add_interface = wcn36xx_add_interface,
1163 .remove_interface = wcn36xx_remove_interface,
1164 #ifdef CONFIG_PM
1165 .suspend = wcn36xx_suspend,
1166 .resume = wcn36xx_resume,
1167 #endif
1168 .config = wcn36xx_config,
1169 .prepare_multicast = wcn36xx_prepare_multicast,
1170 .configure_filter = wcn36xx_configure_filter,
1171 .tx = wcn36xx_tx,
1172 .set_key = wcn36xx_set_key,
1173 .hw_scan = wcn36xx_hw_scan,
1174 .cancel_hw_scan = wcn36xx_cancel_hw_scan,
1175 .sw_scan_start = wcn36xx_sw_scan_start,
1176 .sw_scan_complete = wcn36xx_sw_scan_complete,
1177 .bss_info_changed = wcn36xx_bss_info_changed,
1178 .set_rts_threshold = wcn36xx_set_rts_threshold,
1179 .sta_add = wcn36xx_sta_add,
1180 .sta_remove = wcn36xx_sta_remove,
1181 .ampdu_action = wcn36xx_ampdu_action,
1182
1183 CFG80211_TESTMODE_CMD(wcn36xx_tm_cmd)
1184 };
1185
1186 static void
wcn36xx_set_ieee80211_vht_caps(struct ieee80211_sta_vht_cap * vht_cap)1187 wcn36xx_set_ieee80211_vht_caps(struct ieee80211_sta_vht_cap *vht_cap)
1188 {
1189 vht_cap->vht_supported = true;
1190
1191 vht_cap->cap = (IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895 |
1192 IEEE80211_VHT_CAP_SHORT_GI_80 |
1193 IEEE80211_VHT_CAP_RXSTBC_1 |
1194 IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
1195 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
1196 3 << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT |
1197 7 << IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT);
1198
1199 vht_cap->vht_mcs.rx_mcs_map =
1200 cpu_to_le16(IEEE80211_VHT_MCS_SUPPORT_0_9 |
1201 IEEE80211_VHT_MCS_NOT_SUPPORTED << 2 |
1202 IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 |
1203 IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
1204 IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
1205 IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
1206 IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
1207 IEEE80211_VHT_MCS_NOT_SUPPORTED << 14);
1208
1209 vht_cap->vht_mcs.rx_highest = cpu_to_le16(433);
1210 vht_cap->vht_mcs.tx_highest = vht_cap->vht_mcs.rx_highest;
1211
1212 vht_cap->vht_mcs.tx_mcs_map = vht_cap->vht_mcs.rx_mcs_map;
1213 }
1214
wcn36xx_init_ieee80211(struct wcn36xx * wcn)1215 static int wcn36xx_init_ieee80211(struct wcn36xx *wcn)
1216 {
1217 static const u32 cipher_suites[] = {
1218 WLAN_CIPHER_SUITE_WEP40,
1219 WLAN_CIPHER_SUITE_WEP104,
1220 WLAN_CIPHER_SUITE_TKIP,
1221 WLAN_CIPHER_SUITE_CCMP,
1222 };
1223
1224 ieee80211_hw_set(wcn->hw, TIMING_BEACON_ONLY);
1225 ieee80211_hw_set(wcn->hw, AMPDU_AGGREGATION);
1226 ieee80211_hw_set(wcn->hw, SUPPORTS_PS);
1227 ieee80211_hw_set(wcn->hw, SIGNAL_DBM);
1228 ieee80211_hw_set(wcn->hw, HAS_RATE_CONTROL);
1229 ieee80211_hw_set(wcn->hw, SINGLE_SCAN_ON_ALL_BANDS);
1230 ieee80211_hw_set(wcn->hw, REPORTS_TX_ACK_STATUS);
1231
1232 wcn->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1233 BIT(NL80211_IFTYPE_AP) |
1234 BIT(NL80211_IFTYPE_ADHOC) |
1235 BIT(NL80211_IFTYPE_MESH_POINT);
1236
1237 wcn->hw->wiphy->bands[NL80211_BAND_2GHZ] = &wcn_band_2ghz;
1238 if (wcn->rf_id != RF_IRIS_WCN3620)
1239 wcn->hw->wiphy->bands[NL80211_BAND_5GHZ] = &wcn_band_5ghz;
1240
1241 if (wcn->rf_id == RF_IRIS_WCN3680)
1242 wcn36xx_set_ieee80211_vht_caps(&wcn_band_5ghz.vht_cap);
1243
1244 wcn->hw->wiphy->max_scan_ssids = WCN36XX_MAX_SCAN_SSIDS;
1245 wcn->hw->wiphy->max_scan_ie_len = WCN36XX_MAX_SCAN_IE_LEN;
1246
1247 wcn->hw->wiphy->cipher_suites = cipher_suites;
1248 wcn->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
1249
1250 #ifdef CONFIG_PM
1251 wcn->hw->wiphy->wowlan = &wowlan_support;
1252 #endif
1253
1254 wcn->hw->max_listen_interval = 200;
1255
1256 wcn->hw->queues = 4;
1257
1258 SET_IEEE80211_DEV(wcn->hw, wcn->dev);
1259
1260 wcn->hw->sta_data_size = sizeof(struct wcn36xx_sta);
1261 wcn->hw->vif_data_size = sizeof(struct wcn36xx_vif);
1262
1263 wiphy_ext_feature_set(wcn->hw->wiphy,
1264 NL80211_EXT_FEATURE_CQM_RSSI_LIST);
1265
1266 return 0;
1267 }
1268
wcn36xx_platform_get_resources(struct wcn36xx * wcn,struct platform_device * pdev)1269 static int wcn36xx_platform_get_resources(struct wcn36xx *wcn,
1270 struct platform_device *pdev)
1271 {
1272 struct device_node *mmio_node;
1273 struct device_node *iris_node;
1274 struct resource *res;
1275 int index;
1276 int ret;
1277
1278 /* Set TX IRQ */
1279 res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "tx");
1280 if (!res) {
1281 wcn36xx_err("failed to get tx_irq\n");
1282 return -ENOENT;
1283 }
1284 wcn->tx_irq = res->start;
1285
1286 /* Set RX IRQ */
1287 res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "rx");
1288 if (!res) {
1289 wcn36xx_err("failed to get rx_irq\n");
1290 return -ENOENT;
1291 }
1292 wcn->rx_irq = res->start;
1293
1294 /* Acquire SMSM tx enable handle */
1295 wcn->tx_enable_state = qcom_smem_state_get(&pdev->dev,
1296 "tx-enable", &wcn->tx_enable_state_bit);
1297 if (IS_ERR(wcn->tx_enable_state)) {
1298 wcn36xx_err("failed to get tx-enable state\n");
1299 return PTR_ERR(wcn->tx_enable_state);
1300 }
1301
1302 /* Acquire SMSM tx rings empty handle */
1303 wcn->tx_rings_empty_state = qcom_smem_state_get(&pdev->dev,
1304 "tx-rings-empty", &wcn->tx_rings_empty_state_bit);
1305 if (IS_ERR(wcn->tx_rings_empty_state)) {
1306 wcn36xx_err("failed to get tx-rings-empty state\n");
1307 return PTR_ERR(wcn->tx_rings_empty_state);
1308 }
1309
1310 mmio_node = of_parse_phandle(pdev->dev.parent->of_node, "qcom,mmio", 0);
1311 if (!mmio_node) {
1312 wcn36xx_err("failed to acquire qcom,mmio reference\n");
1313 return -EINVAL;
1314 }
1315
1316 wcn->is_pronto = !!of_device_is_compatible(mmio_node, "qcom,pronto");
1317
1318 /* Map the CCU memory */
1319 index = of_property_match_string(mmio_node, "reg-names", "ccu");
1320 wcn->ccu_base = of_iomap(mmio_node, index);
1321 if (!wcn->ccu_base) {
1322 wcn36xx_err("failed to map ccu memory\n");
1323 ret = -ENOMEM;
1324 goto put_mmio_node;
1325 }
1326
1327 /* Map the DXE memory */
1328 index = of_property_match_string(mmio_node, "reg-names", "dxe");
1329 wcn->dxe_base = of_iomap(mmio_node, index);
1330 if (!wcn->dxe_base) {
1331 wcn36xx_err("failed to map dxe memory\n");
1332 ret = -ENOMEM;
1333 goto unmap_ccu;
1334 }
1335
1336 /* External RF module */
1337 iris_node = of_get_child_by_name(mmio_node, "iris");
1338 if (iris_node) {
1339 if (of_device_is_compatible(iris_node, "qcom,wcn3620"))
1340 wcn->rf_id = RF_IRIS_WCN3620;
1341 if (of_device_is_compatible(iris_node, "qcom,wcn3680"))
1342 wcn->rf_id = RF_IRIS_WCN3680;
1343 of_node_put(iris_node);
1344 }
1345
1346 of_node_put(mmio_node);
1347 return 0;
1348
1349 unmap_ccu:
1350 iounmap(wcn->ccu_base);
1351 put_mmio_node:
1352 of_node_put(mmio_node);
1353 return ret;
1354 }
1355
wcn36xx_probe(struct platform_device * pdev)1356 static int wcn36xx_probe(struct platform_device *pdev)
1357 {
1358 struct ieee80211_hw *hw;
1359 struct wcn36xx *wcn;
1360 void *wcnss;
1361 int ret;
1362 const u8 *addr;
1363
1364 wcn36xx_dbg(WCN36XX_DBG_MAC, "platform probe\n");
1365
1366 wcnss = dev_get_drvdata(pdev->dev.parent);
1367
1368 hw = ieee80211_alloc_hw(sizeof(struct wcn36xx), &wcn36xx_ops);
1369 if (!hw) {
1370 wcn36xx_err("failed to alloc hw\n");
1371 ret = -ENOMEM;
1372 goto out_err;
1373 }
1374 platform_set_drvdata(pdev, hw);
1375 wcn = hw->priv;
1376 wcn->hw = hw;
1377 wcn->dev = &pdev->dev;
1378 wcn->first_boot = true;
1379 mutex_init(&wcn->conf_mutex);
1380 mutex_init(&wcn->hal_mutex);
1381 mutex_init(&wcn->scan_lock);
1382
1383 wcn->hal_buf = devm_kmalloc(wcn->dev, WCN36XX_HAL_BUF_SIZE, GFP_KERNEL);
1384 if (!wcn->hal_buf) {
1385 ret = -ENOMEM;
1386 goto out_wq;
1387 }
1388
1389 ret = dma_set_mask_and_coherent(wcn->dev, DMA_BIT_MASK(32));
1390 if (ret < 0) {
1391 wcn36xx_err("failed to set DMA mask: %d\n", ret);
1392 goto out_wq;
1393 }
1394
1395 wcn->smd_channel = qcom_wcnss_open_channel(wcnss, "WLAN_CTRL", wcn36xx_smd_rsp_process, hw);
1396 if (IS_ERR(wcn->smd_channel)) {
1397 wcn36xx_err("failed to open WLAN_CTRL channel\n");
1398 ret = PTR_ERR(wcn->smd_channel);
1399 goto out_wq;
1400 }
1401
1402 addr = of_get_property(pdev->dev.of_node, "local-mac-address", &ret);
1403 if (addr && ret != ETH_ALEN) {
1404 wcn36xx_err("invalid local-mac-address\n");
1405 ret = -EINVAL;
1406 goto out_destroy_ept;
1407 } else if (addr) {
1408 wcn36xx_info("mac address: %pM\n", addr);
1409 SET_IEEE80211_PERM_ADDR(wcn->hw, addr);
1410 }
1411
1412 ret = wcn36xx_platform_get_resources(wcn, pdev);
1413 if (ret)
1414 goto out_destroy_ept;
1415
1416 wcn36xx_init_ieee80211(wcn);
1417 ret = ieee80211_register_hw(wcn->hw);
1418 if (ret)
1419 goto out_unmap;
1420
1421 return 0;
1422
1423 out_unmap:
1424 iounmap(wcn->ccu_base);
1425 iounmap(wcn->dxe_base);
1426 out_destroy_ept:
1427 rpmsg_destroy_ept(wcn->smd_channel);
1428 out_wq:
1429 ieee80211_free_hw(hw);
1430 out_err:
1431 return ret;
1432 }
1433
wcn36xx_remove(struct platform_device * pdev)1434 static int wcn36xx_remove(struct platform_device *pdev)
1435 {
1436 struct ieee80211_hw *hw = platform_get_drvdata(pdev);
1437 struct wcn36xx *wcn = hw->priv;
1438 wcn36xx_dbg(WCN36XX_DBG_MAC, "platform remove\n");
1439
1440 release_firmware(wcn->nv);
1441
1442 ieee80211_unregister_hw(hw);
1443
1444 qcom_smem_state_put(wcn->tx_enable_state);
1445 qcom_smem_state_put(wcn->tx_rings_empty_state);
1446
1447 rpmsg_destroy_ept(wcn->smd_channel);
1448
1449 iounmap(wcn->dxe_base);
1450 iounmap(wcn->ccu_base);
1451
1452 mutex_destroy(&wcn->hal_mutex);
1453 ieee80211_free_hw(hw);
1454
1455 return 0;
1456 }
1457
1458 static const struct of_device_id wcn36xx_of_match[] = {
1459 { .compatible = "qcom,wcnss-wlan" },
1460 {}
1461 };
1462 MODULE_DEVICE_TABLE(of, wcn36xx_of_match);
1463
1464 static struct platform_driver wcn36xx_driver = {
1465 .probe = wcn36xx_probe,
1466 .remove = wcn36xx_remove,
1467 .driver = {
1468 .name = "wcn36xx",
1469 .of_match_table = wcn36xx_of_match,
1470 },
1471 };
1472
1473 module_platform_driver(wcn36xx_driver);
1474
1475 MODULE_LICENSE("Dual BSD/GPL");
1476 MODULE_AUTHOR("Eugene Krasnikov k.eugene.e@gmail.com");
1477 MODULE_FIRMWARE(WLAN_NV_FILE);
1478