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