blob: c0ba7b0775b38632c29ed31941304dc68a9b4275 [file] [log] [blame]
Eugene Krasnikov8e84c252013-10-08 21:25:58 +01001/*
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>
Pontus Fuchs4bda7fa2014-02-12 19:04:43 +000020#include <linux/firmware.h>
Eugene Krasnikov8e84c252013-10-08 21:25:58 +010021#include <linux/platform_device.h>
22#include "wcn36xx.h"
23
24unsigned int wcn36xx_dbg_mask;
25module_param_named(debug_mask, wcn36xx_dbg_mask, uint, 0644);
26MODULE_PARM_DESC(debug_mask, "Debugging mask");
27
28#define CHAN2G(_freq, _idx) { \
29 .band = IEEE80211_BAND_2GHZ, \
30 .center_freq = (_freq), \
31 .hw_value = (_idx), \
32 .max_power = 25, \
33}
34
35#define CHAN5G(_freq, _idx) { \
36 .band = IEEE80211_BAND_5GHZ, \
37 .center_freq = (_freq), \
38 .hw_value = (_idx), \
39 .max_power = 25, \
40}
41
42/* The wcn firmware expects channel values to matching
43 * their mnemonic values. So use these for .hw_value. */
44static struct ieee80211_channel wcn_2ghz_channels[] = {
45 CHAN2G(2412, 1), /* Channel 1 */
46 CHAN2G(2417, 2), /* Channel 2 */
47 CHAN2G(2422, 3), /* Channel 3 */
48 CHAN2G(2427, 4), /* Channel 4 */
49 CHAN2G(2432, 5), /* Channel 5 */
50 CHAN2G(2437, 6), /* Channel 6 */
51 CHAN2G(2442, 7), /* Channel 7 */
52 CHAN2G(2447, 8), /* Channel 8 */
53 CHAN2G(2452, 9), /* Channel 9 */
54 CHAN2G(2457, 10), /* Channel 10 */
55 CHAN2G(2462, 11), /* Channel 11 */
56 CHAN2G(2467, 12), /* Channel 12 */
57 CHAN2G(2472, 13), /* Channel 13 */
58 CHAN2G(2484, 14) /* Channel 14 */
59
60};
61
62static struct ieee80211_channel wcn_5ghz_channels[] = {
63 CHAN5G(5180, 36),
64 CHAN5G(5200, 40),
65 CHAN5G(5220, 44),
66 CHAN5G(5240, 48),
67 CHAN5G(5260, 52),
68 CHAN5G(5280, 56),
69 CHAN5G(5300, 60),
70 CHAN5G(5320, 64),
71 CHAN5G(5500, 100),
72 CHAN5G(5520, 104),
73 CHAN5G(5540, 108),
74 CHAN5G(5560, 112),
75 CHAN5G(5580, 116),
76 CHAN5G(5600, 120),
77 CHAN5G(5620, 124),
78 CHAN5G(5640, 128),
79 CHAN5G(5660, 132),
80 CHAN5G(5700, 140),
81 CHAN5G(5745, 149),
82 CHAN5G(5765, 153),
83 CHAN5G(5785, 157),
84 CHAN5G(5805, 161),
85 CHAN5G(5825, 165)
86};
87
88#define RATE(_bitrate, _hw_rate, _flags) { \
89 .bitrate = (_bitrate), \
90 .flags = (_flags), \
91 .hw_value = (_hw_rate), \
92 .hw_value_short = (_hw_rate) \
93}
94
95static struct ieee80211_rate wcn_2ghz_rates[] = {
96 RATE(10, HW_RATE_INDEX_1MBPS, 0),
97 RATE(20, HW_RATE_INDEX_2MBPS, IEEE80211_RATE_SHORT_PREAMBLE),
98 RATE(55, HW_RATE_INDEX_5_5MBPS, IEEE80211_RATE_SHORT_PREAMBLE),
99 RATE(110, HW_RATE_INDEX_11MBPS, IEEE80211_RATE_SHORT_PREAMBLE),
100 RATE(60, HW_RATE_INDEX_6MBPS, 0),
101 RATE(90, HW_RATE_INDEX_9MBPS, 0),
102 RATE(120, HW_RATE_INDEX_12MBPS, 0),
103 RATE(180, HW_RATE_INDEX_18MBPS, 0),
104 RATE(240, HW_RATE_INDEX_24MBPS, 0),
105 RATE(360, HW_RATE_INDEX_36MBPS, 0),
106 RATE(480, HW_RATE_INDEX_48MBPS, 0),
107 RATE(540, HW_RATE_INDEX_54MBPS, 0)
108};
109
110static struct ieee80211_rate wcn_5ghz_rates[] = {
111 RATE(60, HW_RATE_INDEX_6MBPS, 0),
112 RATE(90, HW_RATE_INDEX_9MBPS, 0),
113 RATE(120, HW_RATE_INDEX_12MBPS, 0),
114 RATE(180, HW_RATE_INDEX_18MBPS, 0),
115 RATE(240, HW_RATE_INDEX_24MBPS, 0),
116 RATE(360, HW_RATE_INDEX_36MBPS, 0),
117 RATE(480, HW_RATE_INDEX_48MBPS, 0),
118 RATE(540, HW_RATE_INDEX_54MBPS, 0)
119};
120
121static struct ieee80211_supported_band wcn_band_2ghz = {
122 .channels = wcn_2ghz_channels,
123 .n_channels = ARRAY_SIZE(wcn_2ghz_channels),
124 .bitrates = wcn_2ghz_rates,
125 .n_bitrates = ARRAY_SIZE(wcn_2ghz_rates),
126 .ht_cap = {
127 .cap = IEEE80211_HT_CAP_GRN_FLD |
128 IEEE80211_HT_CAP_SGI_20 |
129 IEEE80211_HT_CAP_DSSSCCK40 |
130 IEEE80211_HT_CAP_LSIG_TXOP_PROT,
131 .ht_supported = true,
132 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
133 .ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
134 .mcs = {
135 .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
136 .rx_highest = cpu_to_le16(72),
137 .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
138 }
139 }
140};
141
142static struct ieee80211_supported_band wcn_band_5ghz = {
143 .channels = wcn_5ghz_channels,
144 .n_channels = ARRAY_SIZE(wcn_5ghz_channels),
145 .bitrates = wcn_5ghz_rates,
146 .n_bitrates = ARRAY_SIZE(wcn_5ghz_rates),
147 .ht_cap = {
148 .cap = IEEE80211_HT_CAP_GRN_FLD |
149 IEEE80211_HT_CAP_SGI_20 |
150 IEEE80211_HT_CAP_DSSSCCK40 |
151 IEEE80211_HT_CAP_LSIG_TXOP_PROT |
152 IEEE80211_HT_CAP_SGI_40 |
153 IEEE80211_HT_CAP_SUP_WIDTH_20_40,
154 .ht_supported = true,
155 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
156 .ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
157 .mcs = {
158 .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
159 .rx_highest = cpu_to_le16(72),
160 .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
161 }
162 }
163};
164
165#ifdef CONFIG_PM
166
167static const struct wiphy_wowlan_support wowlan_support = {
168 .flags = WIPHY_WOWLAN_ANY
169};
170
171#endif
172
173static inline u8 get_sta_index(struct ieee80211_vif *vif,
174 struct wcn36xx_sta *sta_priv)
175{
176 return NL80211_IFTYPE_STATION == vif->type ?
177 sta_priv->bss_sta_index :
178 sta_priv->sta_index;
179}
180
Pontus Fuchs2be66362014-02-12 19:04:44 +0000181static const char * const wcn36xx_caps_names[] = {
182 "MCC", /* 0 */
183 "P2P", /* 1 */
184 "DOT11AC", /* 2 */
185 "SLM_SESSIONIZATION", /* 3 */
186 "DOT11AC_OPMODE", /* 4 */
187 "SAP32STA", /* 5 */
188 "TDLS", /* 6 */
189 "P2P_GO_NOA_DECOUPLE_INIT_SCAN",/* 7 */
190 "WLANACTIVE_OFFLOAD", /* 8 */
191 "BEACON_OFFLOAD", /* 9 */
192 "SCAN_OFFLOAD", /* 10 */
193 "ROAM_OFFLOAD", /* 11 */
194 "BCN_MISS_OFFLOAD", /* 12 */
195 "STA_POWERSAVE", /* 13 */
196 "STA_ADVANCED_PWRSAVE", /* 14 */
197 "AP_UAPSD", /* 15 */
198 "AP_DFS", /* 16 */
199 "BLOCKACK", /* 17 */
200 "PHY_ERR", /* 18 */
201 "BCN_FILTER", /* 19 */
202 "RTT", /* 20 */
203 "RATECTRL", /* 21 */
204 "WOW" /* 22 */
205};
206
207static const char *wcn36xx_get_cap_name(enum place_holder_in_cap_bitmap x)
208{
209 if (x >= ARRAY_SIZE(wcn36xx_caps_names))
210 return "UNKNOWN";
211 return wcn36xx_caps_names[x];
212}
213
214static void wcn36xx_feat_caps_info(struct wcn36xx *wcn)
215{
216 int i;
217
218 for (i = 0; i < MAX_FEATURE_SUPPORTED; i++) {
219 if (get_feat_caps(wcn->fw_feat_caps, i))
220 wcn36xx_info("FW Cap %s\n", wcn36xx_get_cap_name(i));
221 }
222}
223
Pontus Fuchsf2ed5d22014-02-12 19:04:45 +0000224static void wcn36xx_detect_chip_version(struct wcn36xx *wcn)
225{
226 if (get_feat_caps(wcn->fw_feat_caps, DOT11AC)) {
227 wcn36xx_info("Chip is 3680\n");
228 wcn->chip_version = WCN36XX_CHIP_3680;
229 } else {
230 wcn36xx_info("Chip is 3660\n");
231 wcn->chip_version = WCN36XX_CHIP_3660;
232 }
233}
234
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100235static int wcn36xx_start(struct ieee80211_hw *hw)
236{
237 struct wcn36xx *wcn = hw->priv;
238 int ret;
239
240 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac start\n");
241
242 /* SMD initialization */
243 ret = wcn36xx_smd_open(wcn);
244 if (ret) {
245 wcn36xx_err("Failed to open smd channel: %d\n", ret);
246 goto out_err;
247 }
248
249 /* Allocate memory pools for Mgmt BD headers and Data BD headers */
250 ret = wcn36xx_dxe_allocate_mem_pools(wcn);
251 if (ret) {
252 wcn36xx_err("Failed to alloc DXE mempool: %d\n", ret);
253 goto out_smd_close;
254 }
255
256 ret = wcn36xx_dxe_alloc_ctl_blks(wcn);
257 if (ret) {
258 wcn36xx_err("Failed to alloc DXE ctl blocks: %d\n", ret);
259 goto out_free_dxe_pool;
260 }
261
262 wcn->hal_buf = kmalloc(WCN36XX_HAL_BUF_SIZE, GFP_KERNEL);
263 if (!wcn->hal_buf) {
264 wcn36xx_err("Failed to allocate smd buf\n");
265 ret = -ENOMEM;
266 goto out_free_dxe_ctl;
267 }
268
269 ret = wcn36xx_smd_load_nv(wcn);
270 if (ret) {
271 wcn36xx_err("Failed to push NV to chip\n");
272 goto out_free_smd_buf;
273 }
274
275 ret = wcn36xx_smd_start(wcn);
276 if (ret) {
277 wcn36xx_err("Failed to start chip\n");
278 goto out_free_smd_buf;
279 }
280
Pontus Fuchsf2ed5d22014-02-12 19:04:45 +0000281 if (!wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) {
282 ret = wcn36xx_smd_feature_caps_exchange(wcn);
283 if (ret)
284 wcn36xx_warn("Exchange feature caps failed\n");
285 else
286 wcn36xx_feat_caps_info(wcn);
287 }
288
289 wcn36xx_detect_chip_version(wcn);
Pontus Fuchs20a779e2016-04-18 22:00:52 -0700290 wcn36xx_smd_update_cfg(wcn, WCN36XX_HAL_CFG_ENABLE_MC_ADDR_LIST, 1);
Pontus Fuchsf2ed5d22014-02-12 19:04:45 +0000291
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100292 /* DMA channel initialization */
293 ret = wcn36xx_dxe_init(wcn);
294 if (ret) {
295 wcn36xx_err("DXE init failed\n");
296 goto out_smd_stop;
297 }
298
299 wcn36xx_debugfs_init(wcn);
300
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100301 INIT_LIST_HEAD(&wcn->vif_list);
Bob Copeland4b124622015-01-09 14:15:50 -0500302 spin_lock_init(&wcn->dxe_lock);
303
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100304 return 0;
305
306out_smd_stop:
307 wcn36xx_smd_stop(wcn);
308out_free_smd_buf:
309 kfree(wcn->hal_buf);
310out_free_dxe_pool:
311 wcn36xx_dxe_free_mem_pools(wcn);
312out_free_dxe_ctl:
313 wcn36xx_dxe_free_ctl_blks(wcn);
314out_smd_close:
315 wcn36xx_smd_close(wcn);
316out_err:
317 return ret;
318}
319
320static void wcn36xx_stop(struct ieee80211_hw *hw)
321{
322 struct wcn36xx *wcn = hw->priv;
323
324 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac stop\n");
325
326 wcn36xx_debugfs_exit(wcn);
327 wcn36xx_smd_stop(wcn);
328 wcn36xx_dxe_deinit(wcn);
329 wcn36xx_smd_close(wcn);
330
331 wcn36xx_dxe_free_mem_pools(wcn);
332 wcn36xx_dxe_free_ctl_blks(wcn);
333
334 kfree(wcn->hal_buf);
335}
336
337static int wcn36xx_config(struct ieee80211_hw *hw, u32 changed)
338{
339 struct wcn36xx *wcn = hw->priv;
340 struct ieee80211_vif *vif = NULL;
341 struct wcn36xx_vif *tmp;
342
343 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac config changed 0x%08x\n", changed);
344
345 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
346 int ch = WCN36XX_HW_CHANNEL(wcn);
347 wcn36xx_dbg(WCN36XX_DBG_MAC, "wcn36xx_config channel switch=%d\n",
348 ch);
349 list_for_each_entry(tmp, &wcn->vif_list, list) {
Pontus Fuchsce758772016-04-18 22:00:41 -0700350 vif = wcn36xx_priv_to_vif(tmp);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100351 wcn36xx_smd_switch_channel(wcn, vif, ch);
352 }
353 }
354
355 return 0;
356}
357
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100358static void wcn36xx_configure_filter(struct ieee80211_hw *hw,
359 unsigned int changed,
360 unsigned int *total, u64 multicast)
361{
Pontus Fuchs20a779e2016-04-18 22:00:52 -0700362 struct wcn36xx_hal_rcv_flt_mc_addr_list_type *fp;
363 struct wcn36xx *wcn = hw->priv;
364 struct wcn36xx_vif *tmp;
365 struct ieee80211_vif *vif = NULL;
366
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100367 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac configure filter\n");
368
Pontus Fuchs20a779e2016-04-18 22:00:52 -0700369 *total &= FIF_ALLMULTI;
370
371 fp = (void *)(unsigned long)multicast;
372 list_for_each_entry(tmp, &wcn->vif_list, list) {
373 vif = wcn36xx_priv_to_vif(tmp);
374
375 /* FW handles MC filtering only when connected as STA */
376 if (*total & FIF_ALLMULTI)
377 wcn36xx_smd_set_mc_list(wcn, vif, NULL);
378 else if (NL80211_IFTYPE_STATION == vif->type && tmp->sta_assoc)
379 wcn36xx_smd_set_mc_list(wcn, vif, fp);
380 }
381 kfree(fp);
382}
383
384static u64 wcn36xx_prepare_multicast(struct ieee80211_hw *hw,
385 struct netdev_hw_addr_list *mc_list)
386{
387 struct wcn36xx_hal_rcv_flt_mc_addr_list_type *fp;
388 struct netdev_hw_addr *ha;
389
390 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac prepare multicast list\n");
391 fp = kzalloc(sizeof(*fp), GFP_ATOMIC);
392 if (!fp) {
393 wcn36xx_err("Out of memory setting filters.\n");
394 return 0;
395 }
396
397 fp->mc_addr_count = 0;
398 /* update multicast filtering parameters */
399 if (netdev_hw_addr_list_count(mc_list) <=
400 WCN36XX_HAL_MAX_NUM_MULTICAST_ADDRESS) {
401 netdev_hw_addr_list_for_each(ha, mc_list) {
402 memcpy(fp->mc_addr[fp->mc_addr_count],
403 ha->addr, ETH_ALEN);
404 fp->mc_addr_count++;
405 }
406 }
407
408 return (u64)(unsigned long)fp;
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100409}
410
411static void wcn36xx_tx(struct ieee80211_hw *hw,
412 struct ieee80211_tx_control *control,
413 struct sk_buff *skb)
414{
415 struct wcn36xx *wcn = hw->priv;
416 struct wcn36xx_sta *sta_priv = NULL;
417
418 if (control->sta)
Pontus Fuchsa92e4692016-04-18 22:00:44 -0700419 sta_priv = wcn36xx_sta_to_priv(control->sta);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100420
421 if (wcn36xx_start_tx(wcn, sta_priv, skb))
422 ieee80211_free_txskb(wcn->hw, skb);
423}
424
425static int wcn36xx_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
426 struct ieee80211_vif *vif,
427 struct ieee80211_sta *sta,
428 struct ieee80211_key_conf *key_conf)
429{
430 struct wcn36xx *wcn = hw->priv;
Pontus Fuchsce758772016-04-18 22:00:41 -0700431 struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
Pontus Fuchs81c69262016-04-18 22:00:45 -0700432 struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(sta);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100433 int ret = 0;
434 u8 key[WLAN_MAX_KEY_LEN];
435
436 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac80211 set key\n");
437 wcn36xx_dbg(WCN36XX_DBG_MAC, "Key: cmd=0x%x algo:0x%x, id:%d, len:%d flags 0x%x\n",
438 cmd, key_conf->cipher, key_conf->keyidx,
439 key_conf->keylen, key_conf->flags);
440 wcn36xx_dbg_dump(WCN36XX_DBG_MAC, "KEY: ",
441 key_conf->key,
442 key_conf->keylen);
443
444 switch (key_conf->cipher) {
445 case WLAN_CIPHER_SUITE_WEP40:
446 vif_priv->encrypt_type = WCN36XX_HAL_ED_WEP40;
447 break;
448 case WLAN_CIPHER_SUITE_WEP104:
449 vif_priv->encrypt_type = WCN36XX_HAL_ED_WEP40;
450 break;
451 case WLAN_CIPHER_SUITE_CCMP:
452 vif_priv->encrypt_type = WCN36XX_HAL_ED_CCMP;
453 break;
454 case WLAN_CIPHER_SUITE_TKIP:
455 vif_priv->encrypt_type = WCN36XX_HAL_ED_TKIP;
456 break;
457 default:
458 wcn36xx_err("Unsupported key type 0x%x\n",
459 key_conf->cipher);
460 ret = -EOPNOTSUPP;
461 goto out;
462 }
463
464 switch (cmd) {
465 case SET_KEY:
466 if (WCN36XX_HAL_ED_TKIP == vif_priv->encrypt_type) {
467 /*
468 * Supplicant is sending key in the wrong order:
469 * Temporal Key (16 b) - TX MIC (8 b) - RX MIC (8 b)
470 * but HW expects it to be in the order as described in
471 * IEEE 802.11 spec (see chapter 11.7) like this:
472 * Temporal Key (16 b) - RX MIC (8 b) - TX MIC (8 b)
473 */
474 memcpy(key, key_conf->key, 16);
475 memcpy(key + 16, key_conf->key + 24, 8);
476 memcpy(key + 24, key_conf->key + 16, 8);
477 } else {
478 memcpy(key, key_conf->key, key_conf->keylen);
479 }
480
481 if (IEEE80211_KEY_FLAG_PAIRWISE & key_conf->flags) {
482 sta_priv->is_data_encrypted = true;
483 /* Reconfigure bss with encrypt_type */
484 if (NL80211_IFTYPE_STATION == vif->type)
485 wcn36xx_smd_config_bss(wcn,
486 vif,
487 sta,
488 sta->addr,
489 true);
490
491 wcn36xx_smd_set_stakey(wcn,
492 vif_priv->encrypt_type,
493 key_conf->keyidx,
494 key_conf->keylen,
495 key,
496 get_sta_index(vif, sta_priv));
497 } else {
498 wcn36xx_smd_set_bsskey(wcn,
499 vif_priv->encrypt_type,
500 key_conf->keyidx,
501 key_conf->keylen,
502 key);
503 if ((WLAN_CIPHER_SUITE_WEP40 == key_conf->cipher) ||
504 (WLAN_CIPHER_SUITE_WEP104 == key_conf->cipher)) {
505 sta_priv->is_data_encrypted = true;
506 wcn36xx_smd_set_stakey(wcn,
507 vif_priv->encrypt_type,
508 key_conf->keyidx,
509 key_conf->keylen,
510 key,
511 get_sta_index(vif, sta_priv));
512 }
513 }
514 break;
515 case DISABLE_KEY:
516 if (!(IEEE80211_KEY_FLAG_PAIRWISE & key_conf->flags)) {
Pontus Fuchs2716a8ac2016-04-18 22:00:50 -0700517 vif_priv->encrypt_type = WCN36XX_HAL_ED_NONE;
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100518 wcn36xx_smd_remove_bsskey(wcn,
519 vif_priv->encrypt_type,
520 key_conf->keyidx);
521 } else {
522 sta_priv->is_data_encrypted = false;
523 /* do not remove key if disassociated */
524 if (sta_priv->aid)
525 wcn36xx_smd_remove_stakey(wcn,
526 vif_priv->encrypt_type,
527 key_conf->keyidx,
528 get_sta_index(vif, sta_priv));
529 }
530 break;
531 default:
532 wcn36xx_err("Unsupported key cmd 0x%x\n", cmd);
533 ret = -EOPNOTSUPP;
534 goto out;
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100535 }
536
537out:
538 return ret;
539}
540
Johannes Berga344d672014-06-12 22:24:31 +0200541static void wcn36xx_sw_scan_start(struct ieee80211_hw *hw,
542 struct ieee80211_vif *vif,
543 const u8 *mac_addr)
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100544{
545 struct wcn36xx *wcn = hw->priv;
546
547 wcn36xx_smd_init_scan(wcn, HAL_SYS_MODE_SCAN);
548 wcn36xx_smd_start_scan(wcn);
549}
550
Johannes Berga344d672014-06-12 22:24:31 +0200551static void wcn36xx_sw_scan_complete(struct ieee80211_hw *hw,
552 struct ieee80211_vif *vif)
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100553{
554 struct wcn36xx *wcn = hw->priv;
555
556 wcn36xx_smd_end_scan(wcn);
557 wcn36xx_smd_finish_scan(wcn, HAL_SYS_MODE_SCAN);
558}
559
560static void wcn36xx_update_allowed_rates(struct ieee80211_sta *sta,
561 enum ieee80211_band band)
562{
563 int i, size;
564 u16 *rates_table;
Pontus Fuchsa92e4692016-04-18 22:00:44 -0700565 struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(sta);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100566 u32 rates = sta->supp_rates[band];
567
568 memset(&sta_priv->supported_rates, 0,
569 sizeof(sta_priv->supported_rates));
570 sta_priv->supported_rates.op_rate_mode = STA_11n;
571
572 size = ARRAY_SIZE(sta_priv->supported_rates.dsss_rates);
573 rates_table = sta_priv->supported_rates.dsss_rates;
574 if (band == IEEE80211_BAND_2GHZ) {
575 for (i = 0; i < size; i++) {
576 if (rates & 0x01) {
577 rates_table[i] = wcn_2ghz_rates[i].hw_value;
578 rates = rates >> 1;
579 }
580 }
581 }
582
583 size = ARRAY_SIZE(sta_priv->supported_rates.ofdm_rates);
584 rates_table = sta_priv->supported_rates.ofdm_rates;
585 for (i = 0; i < size; i++) {
586 if (rates & 0x01) {
587 rates_table[i] = wcn_5ghz_rates[i].hw_value;
588 rates = rates >> 1;
589 }
590 }
591
592 if (sta->ht_cap.ht_supported) {
593 BUILD_BUG_ON(sizeof(sta->ht_cap.mcs.rx_mask) >
594 sizeof(sta_priv->supported_rates.supported_mcs_set));
595 memcpy(sta_priv->supported_rates.supported_mcs_set,
596 sta->ht_cap.mcs.rx_mask,
597 sizeof(sta->ht_cap.mcs.rx_mask));
598 }
599}
600void wcn36xx_set_default_rates(struct wcn36xx_hal_supported_rates *rates)
601{
602 u16 ofdm_rates[WCN36XX_HAL_NUM_OFDM_RATES] = {
603 HW_RATE_INDEX_6MBPS,
604 HW_RATE_INDEX_9MBPS,
605 HW_RATE_INDEX_12MBPS,
606 HW_RATE_INDEX_18MBPS,
607 HW_RATE_INDEX_24MBPS,
608 HW_RATE_INDEX_36MBPS,
609 HW_RATE_INDEX_48MBPS,
610 HW_RATE_INDEX_54MBPS
611 };
612 u16 dsss_rates[WCN36XX_HAL_NUM_DSSS_RATES] = {
613 HW_RATE_INDEX_1MBPS,
614 HW_RATE_INDEX_2MBPS,
615 HW_RATE_INDEX_5_5MBPS,
616 HW_RATE_INDEX_11MBPS
617 };
618
619 rates->op_rate_mode = STA_11n;
620 memcpy(rates->dsss_rates, dsss_rates,
621 sizeof(*dsss_rates) * WCN36XX_HAL_NUM_DSSS_RATES);
622 memcpy(rates->ofdm_rates, ofdm_rates,
623 sizeof(*ofdm_rates) * WCN36XX_HAL_NUM_OFDM_RATES);
624 rates->supported_mcs_set[0] = 0xFF;
625}
626static void wcn36xx_bss_info_changed(struct ieee80211_hw *hw,
627 struct ieee80211_vif *vif,
628 struct ieee80211_bss_conf *bss_conf,
629 u32 changed)
630{
631 struct wcn36xx *wcn = hw->priv;
632 struct sk_buff *skb = NULL;
633 u16 tim_off, tim_len;
634 enum wcn36xx_hal_link_state link_state;
Pontus Fuchsce758772016-04-18 22:00:41 -0700635 struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100636
637 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac bss info changed vif %p changed 0x%08x\n",
638 vif, changed);
639
640 if (changed & BSS_CHANGED_BEACON_INFO) {
641 wcn36xx_dbg(WCN36XX_DBG_MAC,
642 "mac bss changed dtim period %d\n",
643 bss_conf->dtim_period);
644
645 vif_priv->dtim_period = bss_conf->dtim_period;
646 }
647
648 if (changed & BSS_CHANGED_PS) {
649 wcn36xx_dbg(WCN36XX_DBG_MAC,
650 "mac bss PS set %d\n",
651 bss_conf->ps);
652 if (bss_conf->ps) {
653 wcn36xx_pmc_enter_bmps_state(wcn, vif);
654 } else {
655 wcn36xx_pmc_exit_bmps_state(wcn, vif);
656 }
657 }
658
659 if (changed & BSS_CHANGED_BSSID) {
660 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac bss changed_bssid %pM\n",
661 bss_conf->bssid);
662
663 if (!is_zero_ether_addr(bss_conf->bssid)) {
664 vif_priv->is_joining = true;
Pontus Fuchs90023c02016-04-18 22:00:43 -0700665 vif_priv->bss_index = WCN36XX_HAL_BSS_INVALID_IDX;
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100666 wcn36xx_smd_join(wcn, bss_conf->bssid,
667 vif->addr, WCN36XX_HW_CHANNEL(wcn));
668 wcn36xx_smd_config_bss(wcn, vif, NULL,
669 bss_conf->bssid, false);
670 } else {
671 vif_priv->is_joining = false;
672 wcn36xx_smd_delete_bss(wcn, vif);
Pontus Fuchs2716a8ac2016-04-18 22:00:50 -0700673 vif_priv->encrypt_type = WCN36XX_HAL_ED_NONE;
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100674 }
675 }
676
677 if (changed & BSS_CHANGED_SSID) {
678 wcn36xx_dbg(WCN36XX_DBG_MAC,
679 "mac bss changed ssid\n");
680 wcn36xx_dbg_dump(WCN36XX_DBG_MAC, "ssid ",
681 bss_conf->ssid, bss_conf->ssid_len);
682
683 vif_priv->ssid.length = bss_conf->ssid_len;
684 memcpy(&vif_priv->ssid.ssid,
685 bss_conf->ssid,
686 bss_conf->ssid_len);
687 }
688
689 if (changed & BSS_CHANGED_ASSOC) {
690 vif_priv->is_joining = false;
691 if (bss_conf->assoc) {
692 struct ieee80211_sta *sta;
693 struct wcn36xx_sta *sta_priv;
694
695 wcn36xx_dbg(WCN36XX_DBG_MAC,
696 "mac assoc bss %pM vif %pM AID=%d\n",
697 bss_conf->bssid,
698 vif->addr,
699 bss_conf->aid);
700
Pontus Fuchs043ce542016-04-18 22:00:51 -0700701 vif_priv->sta_assoc = true;
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100702 rcu_read_lock();
703 sta = ieee80211_find_sta(vif, bss_conf->bssid);
704 if (!sta) {
705 wcn36xx_err("sta %pM is not found\n",
706 bss_conf->bssid);
707 rcu_read_unlock();
708 goto out;
709 }
Pontus Fuchsa92e4692016-04-18 22:00:44 -0700710 sta_priv = wcn36xx_sta_to_priv(sta);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100711
712 wcn36xx_update_allowed_rates(sta, WCN36XX_BAND(wcn));
713
714 wcn36xx_smd_set_link_st(wcn, bss_conf->bssid,
715 vif->addr,
716 WCN36XX_HAL_LINK_POSTASSOC_STATE);
717 wcn36xx_smd_config_bss(wcn, vif, sta,
718 bss_conf->bssid,
719 true);
720 sta_priv->aid = bss_conf->aid;
721 /*
722 * config_sta must be called from because this is the
723 * place where AID is available.
724 */
725 wcn36xx_smd_config_sta(wcn, vif, sta);
726 rcu_read_unlock();
727 } else {
728 wcn36xx_dbg(WCN36XX_DBG_MAC,
729 "disassociated bss %pM vif %pM AID=%d\n",
730 bss_conf->bssid,
731 vif->addr,
732 bss_conf->aid);
Pontus Fuchs043ce542016-04-18 22:00:51 -0700733 vif_priv->sta_assoc = false;
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100734 wcn36xx_smd_set_link_st(wcn,
735 bss_conf->bssid,
736 vif->addr,
737 WCN36XX_HAL_LINK_IDLE_STATE);
738 }
739 }
740
741 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
742 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac bss changed ap probe resp\n");
743 skb = ieee80211_proberesp_get(hw, vif);
744 if (!skb) {
745 wcn36xx_err("failed to alloc probereq skb\n");
746 goto out;
747 }
748
749 wcn36xx_smd_update_proberesp_tmpl(wcn, vif, skb);
750 dev_kfree_skb(skb);
751 }
752
Chun-Yeow Yeohb3e3f872013-10-31 14:07:45 +0800753 if (changed & BSS_CHANGED_BEACON_ENABLED ||
754 changed & BSS_CHANGED_BEACON) {
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100755 wcn36xx_dbg(WCN36XX_DBG_MAC,
756 "mac bss changed beacon enabled %d\n",
757 bss_conf->enable_beacon);
758
759 if (bss_conf->enable_beacon) {
Pontus Fuchs908628d2014-02-12 19:04:48 +0000760 vif_priv->dtim_period = bss_conf->dtim_period;
Pontus Fuchs90023c02016-04-18 22:00:43 -0700761 vif_priv->bss_index = WCN36XX_HAL_BSS_INVALID_IDX;
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100762 wcn36xx_smd_config_bss(wcn, vif, NULL,
763 vif->addr, false);
764 skb = ieee80211_beacon_get_tim(hw, vif, &tim_off,
765 &tim_len);
766 if (!skb) {
767 wcn36xx_err("failed to alloc beacon skb\n");
768 goto out;
769 }
770 wcn36xx_smd_send_beacon(wcn, vif, skb, tim_off, 0);
771 dev_kfree_skb(skb);
772
773 if (vif->type == NL80211_IFTYPE_ADHOC ||
774 vif->type == NL80211_IFTYPE_MESH_POINT)
775 link_state = WCN36XX_HAL_LINK_IBSS_STATE;
776 else
777 link_state = WCN36XX_HAL_LINK_AP_STATE;
778
779 wcn36xx_smd_set_link_st(wcn, vif->addr, vif->addr,
780 link_state);
781 } else {
782 wcn36xx_smd_set_link_st(wcn, vif->addr, vif->addr,
783 WCN36XX_HAL_LINK_IDLE_STATE);
784 wcn36xx_smd_delete_bss(wcn, vif);
785 }
786 }
787out:
788 return;
789}
790
791/* this is required when using IEEE80211_HW_HAS_RATE_CONTROL */
792static int wcn36xx_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
793{
794 struct wcn36xx *wcn = hw->priv;
795 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac set RTS threshold %d\n", value);
796
797 wcn36xx_smd_update_cfg(wcn, WCN36XX_HAL_CFG_RTS_THRESHOLD, value);
798 return 0;
799}
800
801static void wcn36xx_remove_interface(struct ieee80211_hw *hw,
802 struct ieee80211_vif *vif)
803{
804 struct wcn36xx *wcn = hw->priv;
Pontus Fuchsce758772016-04-18 22:00:41 -0700805 struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100806 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac remove interface vif %p\n", vif);
807
808 list_del(&vif_priv->list);
809 wcn36xx_smd_delete_sta_self(wcn, vif->addr);
810}
811
812static int wcn36xx_add_interface(struct ieee80211_hw *hw,
813 struct ieee80211_vif *vif)
814{
815 struct wcn36xx *wcn = hw->priv;
Pontus Fuchsce758772016-04-18 22:00:41 -0700816 struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100817
818 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac add interface vif %p type %d\n",
819 vif, vif->type);
820
821 if (!(NL80211_IFTYPE_STATION == vif->type ||
822 NL80211_IFTYPE_AP == vif->type ||
823 NL80211_IFTYPE_ADHOC == vif->type ||
824 NL80211_IFTYPE_MESH_POINT == vif->type)) {
825 wcn36xx_warn("Unsupported interface type requested: %d\n",
826 vif->type);
827 return -EOPNOTSUPP;
828 }
829
830 list_add(&vif_priv->list, &wcn->vif_list);
831 wcn36xx_smd_add_sta_self(wcn, vif);
832
833 return 0;
834}
835
836static int wcn36xx_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
837 struct ieee80211_sta *sta)
838{
839 struct wcn36xx *wcn = hw->priv;
Pontus Fuchsce758772016-04-18 22:00:41 -0700840 struct wcn36xx_vif *vif_priv = wcn36xx_vif_to_priv(vif);
Pontus Fuchsa92e4692016-04-18 22:00:44 -0700841 struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(sta);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100842 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac sta add vif %p sta %pM\n",
843 vif, sta->addr);
844
Bob Copelande26dc172015-01-09 14:15:52 -0500845 spin_lock_init(&sta_priv->ampdu_lock);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100846 sta_priv->vif = vif_priv;
847 /*
848 * For STA mode HW will be configured on BSS_CHANGED_ASSOC because
849 * at this stage AID is not available yet.
850 */
851 if (NL80211_IFTYPE_STATION != vif->type) {
852 wcn36xx_update_allowed_rates(sta, WCN36XX_BAND(wcn));
853 sta_priv->aid = sta->aid;
854 wcn36xx_smd_config_sta(wcn, vif, sta);
855 }
856 return 0;
857}
858
859static int wcn36xx_sta_remove(struct ieee80211_hw *hw,
860 struct ieee80211_vif *vif,
861 struct ieee80211_sta *sta)
862{
863 struct wcn36xx *wcn = hw->priv;
Pontus Fuchsa92e4692016-04-18 22:00:44 -0700864 struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(sta);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100865
866 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac sta remove vif %p sta %pM index %d\n",
867 vif, sta->addr, sta_priv->sta_index);
868
869 wcn36xx_smd_delete_sta(wcn, sta_priv->sta_index);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100870 sta_priv->vif = NULL;
871 return 0;
872}
873
874#ifdef CONFIG_PM
875
876static int wcn36xx_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wow)
877{
878 struct wcn36xx *wcn = hw->priv;
879
880 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac suspend\n");
881
882 flush_workqueue(wcn->hal_ind_wq);
883 wcn36xx_smd_set_power_params(wcn, true);
884 return 0;
885}
886
887static int wcn36xx_resume(struct ieee80211_hw *hw)
888{
889 struct wcn36xx *wcn = hw->priv;
890
891 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac resume\n");
892
893 flush_workqueue(wcn->hal_ind_wq);
894 wcn36xx_smd_set_power_params(wcn, false);
895 return 0;
896}
897
898#endif
899
900static int wcn36xx_ampdu_action(struct ieee80211_hw *hw,
901 struct ieee80211_vif *vif,
Sara Sharon50ea05e2015-12-30 16:06:04 +0200902 struct ieee80211_ampdu_params *params)
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100903{
904 struct wcn36xx *wcn = hw->priv;
Pontus Fuchsa92e4692016-04-18 22:00:44 -0700905 struct wcn36xx_sta *sta_priv = wcn36xx_sta_to_priv(params->sta);
Sara Sharon50ea05e2015-12-30 16:06:04 +0200906 struct ieee80211_sta *sta = params->sta;
907 enum ieee80211_ampdu_mlme_action action = params->action;
908 u16 tid = params->tid;
909 u16 *ssn = &params->ssn;
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100910
911 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac ampdu action action %d tid %d\n",
912 action, tid);
913
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100914 switch (action) {
915 case IEEE80211_AMPDU_RX_START:
916 sta_priv->tid = tid;
917 wcn36xx_smd_add_ba_session(wcn, sta, tid, ssn, 0,
918 get_sta_index(vif, sta_priv));
919 wcn36xx_smd_add_ba(wcn);
920 wcn36xx_smd_trigger_ba(wcn, get_sta_index(vif, sta_priv));
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100921 break;
922 case IEEE80211_AMPDU_RX_STOP:
923 wcn36xx_smd_del_ba(wcn, tid, get_sta_index(vif, sta_priv));
924 break;
925 case IEEE80211_AMPDU_TX_START:
Bob Copelande26dc172015-01-09 14:15:52 -0500926 spin_lock_bh(&sta_priv->ampdu_lock);
927 sta_priv->ampdu_state[tid] = WCN36XX_AMPDU_START;
928 spin_unlock_bh(&sta_priv->ampdu_lock);
929
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100930 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
931 break;
932 case IEEE80211_AMPDU_TX_OPERATIONAL:
Bob Copelande26dc172015-01-09 14:15:52 -0500933 spin_lock_bh(&sta_priv->ampdu_lock);
934 sta_priv->ampdu_state[tid] = WCN36XX_AMPDU_OPERATIONAL;
935 spin_unlock_bh(&sta_priv->ampdu_lock);
936
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100937 wcn36xx_smd_add_ba_session(wcn, sta, tid, ssn, 1,
938 get_sta_index(vif, sta_priv));
939 break;
940 case IEEE80211_AMPDU_TX_STOP_FLUSH:
941 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
942 case IEEE80211_AMPDU_TX_STOP_CONT:
Bob Copelande26dc172015-01-09 14:15:52 -0500943 spin_lock_bh(&sta_priv->ampdu_lock);
944 sta_priv->ampdu_state[tid] = WCN36XX_AMPDU_NONE;
945 spin_unlock_bh(&sta_priv->ampdu_lock);
946
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100947 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
948 break;
949 default:
950 wcn36xx_err("Unknown AMPDU action\n");
951 }
952
953 return 0;
954}
955
956static const struct ieee80211_ops wcn36xx_ops = {
957 .start = wcn36xx_start,
958 .stop = wcn36xx_stop,
959 .add_interface = wcn36xx_add_interface,
960 .remove_interface = wcn36xx_remove_interface,
961#ifdef CONFIG_PM
962 .suspend = wcn36xx_suspend,
963 .resume = wcn36xx_resume,
964#endif
965 .config = wcn36xx_config,
Pontus Fuchs20a779e2016-04-18 22:00:52 -0700966 .prepare_multicast = wcn36xx_prepare_multicast,
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100967 .configure_filter = wcn36xx_configure_filter,
968 .tx = wcn36xx_tx,
969 .set_key = wcn36xx_set_key,
970 .sw_scan_start = wcn36xx_sw_scan_start,
971 .sw_scan_complete = wcn36xx_sw_scan_complete,
972 .bss_info_changed = wcn36xx_bss_info_changed,
973 .set_rts_threshold = wcn36xx_set_rts_threshold,
974 .sta_add = wcn36xx_sta_add,
975 .sta_remove = wcn36xx_sta_remove,
976 .ampdu_action = wcn36xx_ampdu_action,
977};
978
979static int wcn36xx_init_ieee80211(struct wcn36xx *wcn)
980{
981 int ret = 0;
982
983 static const u32 cipher_suites[] = {
984 WLAN_CIPHER_SUITE_WEP40,
985 WLAN_CIPHER_SUITE_WEP104,
986 WLAN_CIPHER_SUITE_TKIP,
987 WLAN_CIPHER_SUITE_CCMP,
988 };
989
Johannes Berg30686bf2015-06-02 21:39:54 +0200990 ieee80211_hw_set(wcn->hw, TIMING_BEACON_ONLY);
991 ieee80211_hw_set(wcn->hw, AMPDU_AGGREGATION);
992 ieee80211_hw_set(wcn->hw, CONNECTION_MONITOR);
993 ieee80211_hw_set(wcn->hw, SUPPORTS_PS);
994 ieee80211_hw_set(wcn->hw, SIGNAL_DBM);
995 ieee80211_hw_set(wcn->hw, HAS_RATE_CONTROL);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +0100996
997 wcn->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
998 BIT(NL80211_IFTYPE_AP) |
999 BIT(NL80211_IFTYPE_ADHOC) |
1000 BIT(NL80211_IFTYPE_MESH_POINT);
1001
1002 wcn->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wcn_band_2ghz;
1003 wcn->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &wcn_band_5ghz;
1004
1005 wcn->hw->wiphy->cipher_suites = cipher_suites;
1006 wcn->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
1007
1008 wcn->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
1009
1010#ifdef CONFIG_PM
1011 wcn->hw->wiphy->wowlan = &wowlan_support;
1012#endif
1013
1014 wcn->hw->max_listen_interval = 200;
1015
1016 wcn->hw->queues = 4;
1017
1018 SET_IEEE80211_DEV(wcn->hw, wcn->dev);
1019
1020 wcn->hw->sta_data_size = sizeof(struct wcn36xx_sta);
1021 wcn->hw->vif_data_size = sizeof(struct wcn36xx_vif);
1022
1023 return ret;
1024}
1025
1026static int wcn36xx_platform_get_resources(struct wcn36xx *wcn,
1027 struct platform_device *pdev)
1028{
1029 struct resource *res;
1030 /* Set TX IRQ */
1031 res = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
1032 "wcnss_wlantx_irq");
1033 if (!res) {
1034 wcn36xx_err("failed to get tx_irq\n");
1035 return -ENOENT;
1036 }
1037 wcn->tx_irq = res->start;
1038
1039 /* Set RX IRQ */
1040 res = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
1041 "wcnss_wlanrx_irq");
1042 if (!res) {
1043 wcn36xx_err("failed to get rx_irq\n");
1044 return -ENOENT;
1045 }
1046 wcn->rx_irq = res->start;
1047
1048 /* Map the memory */
1049 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
1050 "wcnss_mmio");
1051 if (!res) {
1052 wcn36xx_err("failed to get mmio\n");
1053 return -ENOENT;
1054 }
1055 wcn->mmio = ioremap(res->start, resource_size(res));
1056 if (!wcn->mmio) {
1057 wcn36xx_err("failed to map io memory\n");
1058 return -ENOMEM;
1059 }
1060 return 0;
1061}
1062
1063static int wcn36xx_probe(struct platform_device *pdev)
1064{
1065 struct ieee80211_hw *hw;
1066 struct wcn36xx *wcn;
1067 int ret;
1068 u8 addr[ETH_ALEN];
1069
1070 wcn36xx_dbg(WCN36XX_DBG_MAC, "platform probe\n");
1071
1072 hw = ieee80211_alloc_hw(sizeof(struct wcn36xx), &wcn36xx_ops);
1073 if (!hw) {
1074 wcn36xx_err("failed to alloc hw\n");
1075 ret = -ENOMEM;
1076 goto out_err;
1077 }
1078 platform_set_drvdata(pdev, hw);
1079 wcn = hw->priv;
1080 wcn->hw = hw;
1081 wcn->dev = &pdev->dev;
1082 wcn->ctrl_ops = pdev->dev.platform_data;
1083
1084 mutex_init(&wcn->hal_mutex);
1085
1086 if (!wcn->ctrl_ops->get_hw_mac(addr)) {
1087 wcn36xx_info("mac address: %pM\n", addr);
1088 SET_IEEE80211_PERM_ADDR(wcn->hw, addr);
1089 }
1090
1091 ret = wcn36xx_platform_get_resources(wcn, pdev);
1092 if (ret)
1093 goto out_wq;
1094
1095 wcn36xx_init_ieee80211(wcn);
1096 ret = ieee80211_register_hw(wcn->hw);
1097 if (ret)
1098 goto out_unmap;
1099
1100 return 0;
1101
1102out_unmap:
1103 iounmap(wcn->mmio);
1104out_wq:
1105 ieee80211_free_hw(hw);
1106out_err:
1107 return ret;
1108}
1109static int wcn36xx_remove(struct platform_device *pdev)
1110{
1111 struct ieee80211_hw *hw = platform_get_drvdata(pdev);
1112 struct wcn36xx *wcn = hw->priv;
1113 wcn36xx_dbg(WCN36XX_DBG_MAC, "platform remove\n");
1114
Pontus Fuchs4bda7fa2014-02-12 19:04:43 +00001115 release_firmware(wcn->nv);
Eugene Krasnikov8e84c252013-10-08 21:25:58 +01001116 mutex_destroy(&wcn->hal_mutex);
1117
1118 ieee80211_unregister_hw(hw);
1119 iounmap(wcn->mmio);
1120 ieee80211_free_hw(hw);
1121
1122 return 0;
1123}
1124static const struct platform_device_id wcn36xx_platform_id_table[] = {
1125 {
1126 .name = "wcn36xx",
1127 .driver_data = 0
1128 },
1129 {}
1130};
1131MODULE_DEVICE_TABLE(platform, wcn36xx_platform_id_table);
1132
1133static struct platform_driver wcn36xx_driver = {
1134 .probe = wcn36xx_probe,
1135 .remove = wcn36xx_remove,
1136 .driver = {
1137 .name = "wcn36xx",
Eugene Krasnikov8e84c252013-10-08 21:25:58 +01001138 },
1139 .id_table = wcn36xx_platform_id_table,
1140};
1141
1142static int __init wcn36xx_init(void)
1143{
1144 platform_driver_register(&wcn36xx_driver);
1145 return 0;
1146}
1147module_init(wcn36xx_init);
1148
1149static void __exit wcn36xx_exit(void)
1150{
1151 platform_driver_unregister(&wcn36xx_driver);
1152}
1153module_exit(wcn36xx_exit);
1154
1155MODULE_LICENSE("Dual BSD/GPL");
1156MODULE_AUTHOR("Eugene Krasnikov k.eugene.e@gmail.com");
1157MODULE_FIRMWARE(WLAN_NV_FILE);