a801aaa760379ec211aac264bd1eb3d01b4d969c
[deliverable/linux.git] / drivers / net / wireless / ath / wcn36xx / main.c
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 "wcn36xx.h"
23
24 unsigned int wcn36xx_dbg_mask;
25 module_param_named(debug_mask, wcn36xx_dbg_mask, uint, 0644);
26 MODULE_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. */
44 static 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
62 static 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
95 static 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
110 static 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
121 static 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
142 static 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
167 static const struct wiphy_wowlan_support wowlan_support = {
168 .flags = WIPHY_WOWLAN_ANY
169 };
170
171 #endif
172
173 static 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
181 static int wcn36xx_start(struct ieee80211_hw *hw)
182 {
183 struct wcn36xx *wcn = hw->priv;
184 int ret;
185
186 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac start\n");
187
188 /* SMD initialization */
189 ret = wcn36xx_smd_open(wcn);
190 if (ret) {
191 wcn36xx_err("Failed to open smd channel: %d\n", ret);
192 goto out_err;
193 }
194
195 /* Allocate memory pools for Mgmt BD headers and Data BD headers */
196 ret = wcn36xx_dxe_allocate_mem_pools(wcn);
197 if (ret) {
198 wcn36xx_err("Failed to alloc DXE mempool: %d\n", ret);
199 goto out_smd_close;
200 }
201
202 ret = wcn36xx_dxe_alloc_ctl_blks(wcn);
203 if (ret) {
204 wcn36xx_err("Failed to alloc DXE ctl blocks: %d\n", ret);
205 goto out_free_dxe_pool;
206 }
207
208 wcn->hal_buf = kmalloc(WCN36XX_HAL_BUF_SIZE, GFP_KERNEL);
209 if (!wcn->hal_buf) {
210 wcn36xx_err("Failed to allocate smd buf\n");
211 ret = -ENOMEM;
212 goto out_free_dxe_ctl;
213 }
214
215 ret = wcn36xx_smd_load_nv(wcn);
216 if (ret) {
217 wcn36xx_err("Failed to push NV to chip\n");
218 goto out_free_smd_buf;
219 }
220
221 ret = wcn36xx_smd_start(wcn);
222 if (ret) {
223 wcn36xx_err("Failed to start chip\n");
224 goto out_free_smd_buf;
225 }
226
227 /* DMA channel initialization */
228 ret = wcn36xx_dxe_init(wcn);
229 if (ret) {
230 wcn36xx_err("DXE init failed\n");
231 goto out_smd_stop;
232 }
233
234 wcn36xx_debugfs_init(wcn);
235
236 if (!wcn36xx_is_fw_version(wcn, 1, 2, 2, 24)) {
237 ret = wcn36xx_smd_feature_caps_exchange(wcn);
238 if (ret)
239 wcn36xx_warn("Exchange feature caps failed\n");
240 }
241 INIT_LIST_HEAD(&wcn->vif_list);
242 return 0;
243
244 out_smd_stop:
245 wcn36xx_smd_stop(wcn);
246 out_free_smd_buf:
247 kfree(wcn->hal_buf);
248 out_free_dxe_pool:
249 wcn36xx_dxe_free_mem_pools(wcn);
250 out_free_dxe_ctl:
251 wcn36xx_dxe_free_ctl_blks(wcn);
252 out_smd_close:
253 wcn36xx_smd_close(wcn);
254 out_err:
255 return ret;
256 }
257
258 static void wcn36xx_stop(struct ieee80211_hw *hw)
259 {
260 struct wcn36xx *wcn = hw->priv;
261
262 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac stop\n");
263
264 wcn36xx_debugfs_exit(wcn);
265 wcn36xx_smd_stop(wcn);
266 wcn36xx_dxe_deinit(wcn);
267 wcn36xx_smd_close(wcn);
268
269 wcn36xx_dxe_free_mem_pools(wcn);
270 wcn36xx_dxe_free_ctl_blks(wcn);
271
272 kfree(wcn->hal_buf);
273 }
274
275 static int wcn36xx_config(struct ieee80211_hw *hw, u32 changed)
276 {
277 struct wcn36xx *wcn = hw->priv;
278 struct ieee80211_vif *vif = NULL;
279 struct wcn36xx_vif *tmp;
280
281 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac config changed 0x%08x\n", changed);
282
283 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
284 int ch = WCN36XX_HW_CHANNEL(wcn);
285 wcn36xx_dbg(WCN36XX_DBG_MAC, "wcn36xx_config channel switch=%d\n",
286 ch);
287 list_for_each_entry(tmp, &wcn->vif_list, list) {
288 vif = container_of((void *)tmp,
289 struct ieee80211_vif,
290 drv_priv);
291 wcn36xx_smd_switch_channel(wcn, vif, ch);
292 }
293 }
294
295 return 0;
296 }
297
298 #define WCN36XX_SUPPORTED_FILTERS (0)
299
300 static void wcn36xx_configure_filter(struct ieee80211_hw *hw,
301 unsigned int changed,
302 unsigned int *total, u64 multicast)
303 {
304 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac configure filter\n");
305
306 *total &= WCN36XX_SUPPORTED_FILTERS;
307 }
308
309 static void wcn36xx_tx(struct ieee80211_hw *hw,
310 struct ieee80211_tx_control *control,
311 struct sk_buff *skb)
312 {
313 struct wcn36xx *wcn = hw->priv;
314 struct wcn36xx_sta *sta_priv = NULL;
315
316 if (control->sta)
317 sta_priv = (struct wcn36xx_sta *)control->sta->drv_priv;
318
319 if (wcn36xx_start_tx(wcn, sta_priv, skb))
320 ieee80211_free_txskb(wcn->hw, skb);
321 }
322
323 static int wcn36xx_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
324 struct ieee80211_vif *vif,
325 struct ieee80211_sta *sta,
326 struct ieee80211_key_conf *key_conf)
327 {
328 struct wcn36xx *wcn = hw->priv;
329 struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
330 struct wcn36xx_sta *sta_priv = vif_priv->sta;
331 int ret = 0;
332 u8 key[WLAN_MAX_KEY_LEN];
333
334 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac80211 set key\n");
335 wcn36xx_dbg(WCN36XX_DBG_MAC, "Key: cmd=0x%x algo:0x%x, id:%d, len:%d flags 0x%x\n",
336 cmd, key_conf->cipher, key_conf->keyidx,
337 key_conf->keylen, key_conf->flags);
338 wcn36xx_dbg_dump(WCN36XX_DBG_MAC, "KEY: ",
339 key_conf->key,
340 key_conf->keylen);
341
342 switch (key_conf->cipher) {
343 case WLAN_CIPHER_SUITE_WEP40:
344 vif_priv->encrypt_type = WCN36XX_HAL_ED_WEP40;
345 break;
346 case WLAN_CIPHER_SUITE_WEP104:
347 vif_priv->encrypt_type = WCN36XX_HAL_ED_WEP40;
348 break;
349 case WLAN_CIPHER_SUITE_CCMP:
350 vif_priv->encrypt_type = WCN36XX_HAL_ED_CCMP;
351 break;
352 case WLAN_CIPHER_SUITE_TKIP:
353 vif_priv->encrypt_type = WCN36XX_HAL_ED_TKIP;
354 break;
355 default:
356 wcn36xx_err("Unsupported key type 0x%x\n",
357 key_conf->cipher);
358 ret = -EOPNOTSUPP;
359 goto out;
360 }
361
362 switch (cmd) {
363 case SET_KEY:
364 if (WCN36XX_HAL_ED_TKIP == vif_priv->encrypt_type) {
365 /*
366 * Supplicant is sending key in the wrong order:
367 * Temporal Key (16 b) - TX MIC (8 b) - RX MIC (8 b)
368 * but HW expects it to be in the order as described in
369 * IEEE 802.11 spec (see chapter 11.7) like this:
370 * Temporal Key (16 b) - RX MIC (8 b) - TX MIC (8 b)
371 */
372 memcpy(key, key_conf->key, 16);
373 memcpy(key + 16, key_conf->key + 24, 8);
374 memcpy(key + 24, key_conf->key + 16, 8);
375 } else {
376 memcpy(key, key_conf->key, key_conf->keylen);
377 }
378
379 if (IEEE80211_KEY_FLAG_PAIRWISE & key_conf->flags) {
380 sta_priv->is_data_encrypted = true;
381 /* Reconfigure bss with encrypt_type */
382 if (NL80211_IFTYPE_STATION == vif->type)
383 wcn36xx_smd_config_bss(wcn,
384 vif,
385 sta,
386 sta->addr,
387 true);
388
389 wcn36xx_smd_set_stakey(wcn,
390 vif_priv->encrypt_type,
391 key_conf->keyidx,
392 key_conf->keylen,
393 key,
394 get_sta_index(vif, sta_priv));
395 } else {
396 wcn36xx_smd_set_bsskey(wcn,
397 vif_priv->encrypt_type,
398 key_conf->keyidx,
399 key_conf->keylen,
400 key);
401 if ((WLAN_CIPHER_SUITE_WEP40 == key_conf->cipher) ||
402 (WLAN_CIPHER_SUITE_WEP104 == key_conf->cipher)) {
403 sta_priv->is_data_encrypted = true;
404 wcn36xx_smd_set_stakey(wcn,
405 vif_priv->encrypt_type,
406 key_conf->keyidx,
407 key_conf->keylen,
408 key,
409 get_sta_index(vif, sta_priv));
410 }
411 }
412 break;
413 case DISABLE_KEY:
414 if (!(IEEE80211_KEY_FLAG_PAIRWISE & key_conf->flags)) {
415 wcn36xx_smd_remove_bsskey(wcn,
416 vif_priv->encrypt_type,
417 key_conf->keyidx);
418 } else {
419 sta_priv->is_data_encrypted = false;
420 /* do not remove key if disassociated */
421 if (sta_priv->aid)
422 wcn36xx_smd_remove_stakey(wcn,
423 vif_priv->encrypt_type,
424 key_conf->keyidx,
425 get_sta_index(vif, sta_priv));
426 }
427 break;
428 default:
429 wcn36xx_err("Unsupported key cmd 0x%x\n", cmd);
430 ret = -EOPNOTSUPP;
431 goto out;
432 break;
433 }
434
435 out:
436 return ret;
437 }
438
439 static void wcn36xx_sw_scan_start(struct ieee80211_hw *hw)
440 {
441 struct wcn36xx *wcn = hw->priv;
442
443 wcn36xx_smd_init_scan(wcn, HAL_SYS_MODE_SCAN);
444 wcn36xx_smd_start_scan(wcn);
445 }
446
447 static void wcn36xx_sw_scan_complete(struct ieee80211_hw *hw)
448 {
449 struct wcn36xx *wcn = hw->priv;
450
451 wcn36xx_smd_end_scan(wcn);
452 wcn36xx_smd_finish_scan(wcn, HAL_SYS_MODE_SCAN);
453 }
454
455 static void wcn36xx_update_allowed_rates(struct ieee80211_sta *sta,
456 enum ieee80211_band band)
457 {
458 int i, size;
459 u16 *rates_table;
460 struct wcn36xx_sta *sta_priv = (struct wcn36xx_sta *)sta->drv_priv;
461 u32 rates = sta->supp_rates[band];
462
463 memset(&sta_priv->supported_rates, 0,
464 sizeof(sta_priv->supported_rates));
465 sta_priv->supported_rates.op_rate_mode = STA_11n;
466
467 size = ARRAY_SIZE(sta_priv->supported_rates.dsss_rates);
468 rates_table = sta_priv->supported_rates.dsss_rates;
469 if (band == IEEE80211_BAND_2GHZ) {
470 for (i = 0; i < size; i++) {
471 if (rates & 0x01) {
472 rates_table[i] = wcn_2ghz_rates[i].hw_value;
473 rates = rates >> 1;
474 }
475 }
476 }
477
478 size = ARRAY_SIZE(sta_priv->supported_rates.ofdm_rates);
479 rates_table = sta_priv->supported_rates.ofdm_rates;
480 for (i = 0; i < size; i++) {
481 if (rates & 0x01) {
482 rates_table[i] = wcn_5ghz_rates[i].hw_value;
483 rates = rates >> 1;
484 }
485 }
486
487 if (sta->ht_cap.ht_supported) {
488 BUILD_BUG_ON(sizeof(sta->ht_cap.mcs.rx_mask) >
489 sizeof(sta_priv->supported_rates.supported_mcs_set));
490 memcpy(sta_priv->supported_rates.supported_mcs_set,
491 sta->ht_cap.mcs.rx_mask,
492 sizeof(sta->ht_cap.mcs.rx_mask));
493 }
494 }
495 void wcn36xx_set_default_rates(struct wcn36xx_hal_supported_rates *rates)
496 {
497 u16 ofdm_rates[WCN36XX_HAL_NUM_OFDM_RATES] = {
498 HW_RATE_INDEX_6MBPS,
499 HW_RATE_INDEX_9MBPS,
500 HW_RATE_INDEX_12MBPS,
501 HW_RATE_INDEX_18MBPS,
502 HW_RATE_INDEX_24MBPS,
503 HW_RATE_INDEX_36MBPS,
504 HW_RATE_INDEX_48MBPS,
505 HW_RATE_INDEX_54MBPS
506 };
507 u16 dsss_rates[WCN36XX_HAL_NUM_DSSS_RATES] = {
508 HW_RATE_INDEX_1MBPS,
509 HW_RATE_INDEX_2MBPS,
510 HW_RATE_INDEX_5_5MBPS,
511 HW_RATE_INDEX_11MBPS
512 };
513
514 rates->op_rate_mode = STA_11n;
515 memcpy(rates->dsss_rates, dsss_rates,
516 sizeof(*dsss_rates) * WCN36XX_HAL_NUM_DSSS_RATES);
517 memcpy(rates->ofdm_rates, ofdm_rates,
518 sizeof(*ofdm_rates) * WCN36XX_HAL_NUM_OFDM_RATES);
519 rates->supported_mcs_set[0] = 0xFF;
520 }
521 static void wcn36xx_bss_info_changed(struct ieee80211_hw *hw,
522 struct ieee80211_vif *vif,
523 struct ieee80211_bss_conf *bss_conf,
524 u32 changed)
525 {
526 struct wcn36xx *wcn = hw->priv;
527 struct sk_buff *skb = NULL;
528 u16 tim_off, tim_len;
529 enum wcn36xx_hal_link_state link_state;
530 struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
531
532 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac bss info changed vif %p changed 0x%08x\n",
533 vif, changed);
534
535 if (changed & BSS_CHANGED_BEACON_INFO) {
536 wcn36xx_dbg(WCN36XX_DBG_MAC,
537 "mac bss changed dtim period %d\n",
538 bss_conf->dtim_period);
539
540 vif_priv->dtim_period = bss_conf->dtim_period;
541 }
542
543 if (changed & BSS_CHANGED_PS) {
544 wcn36xx_dbg(WCN36XX_DBG_MAC,
545 "mac bss PS set %d\n",
546 bss_conf->ps);
547 if (bss_conf->ps) {
548 wcn36xx_pmc_enter_bmps_state(wcn, vif);
549 } else {
550 wcn36xx_pmc_exit_bmps_state(wcn, vif);
551 }
552 }
553
554 if (changed & BSS_CHANGED_BSSID) {
555 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac bss changed_bssid %pM\n",
556 bss_conf->bssid);
557
558 if (!is_zero_ether_addr(bss_conf->bssid)) {
559 vif_priv->is_joining = true;
560 vif_priv->bss_index = 0xff;
561 wcn36xx_smd_join(wcn, bss_conf->bssid,
562 vif->addr, WCN36XX_HW_CHANNEL(wcn));
563 wcn36xx_smd_config_bss(wcn, vif, NULL,
564 bss_conf->bssid, false);
565 } else {
566 vif_priv->is_joining = false;
567 wcn36xx_smd_delete_bss(wcn, vif);
568 }
569 }
570
571 if (changed & BSS_CHANGED_SSID) {
572 wcn36xx_dbg(WCN36XX_DBG_MAC,
573 "mac bss changed ssid\n");
574 wcn36xx_dbg_dump(WCN36XX_DBG_MAC, "ssid ",
575 bss_conf->ssid, bss_conf->ssid_len);
576
577 vif_priv->ssid.length = bss_conf->ssid_len;
578 memcpy(&vif_priv->ssid.ssid,
579 bss_conf->ssid,
580 bss_conf->ssid_len);
581 }
582
583 if (changed & BSS_CHANGED_ASSOC) {
584 vif_priv->is_joining = false;
585 if (bss_conf->assoc) {
586 struct ieee80211_sta *sta;
587 struct wcn36xx_sta *sta_priv;
588
589 wcn36xx_dbg(WCN36XX_DBG_MAC,
590 "mac assoc bss %pM vif %pM AID=%d\n",
591 bss_conf->bssid,
592 vif->addr,
593 bss_conf->aid);
594
595 rcu_read_lock();
596 sta = ieee80211_find_sta(vif, bss_conf->bssid);
597 if (!sta) {
598 wcn36xx_err("sta %pM is not found\n",
599 bss_conf->bssid);
600 rcu_read_unlock();
601 goto out;
602 }
603 sta_priv = (struct wcn36xx_sta *)sta->drv_priv;
604
605 wcn36xx_update_allowed_rates(sta, WCN36XX_BAND(wcn));
606
607 wcn36xx_smd_set_link_st(wcn, bss_conf->bssid,
608 vif->addr,
609 WCN36XX_HAL_LINK_POSTASSOC_STATE);
610 wcn36xx_smd_config_bss(wcn, vif, sta,
611 bss_conf->bssid,
612 true);
613 sta_priv->aid = bss_conf->aid;
614 /*
615 * config_sta must be called from because this is the
616 * place where AID is available.
617 */
618 wcn36xx_smd_config_sta(wcn, vif, sta);
619 rcu_read_unlock();
620 } else {
621 wcn36xx_dbg(WCN36XX_DBG_MAC,
622 "disassociated bss %pM vif %pM AID=%d\n",
623 bss_conf->bssid,
624 vif->addr,
625 bss_conf->aid);
626 wcn36xx_smd_set_link_st(wcn,
627 bss_conf->bssid,
628 vif->addr,
629 WCN36XX_HAL_LINK_IDLE_STATE);
630 }
631 }
632
633 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
634 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac bss changed ap probe resp\n");
635 skb = ieee80211_proberesp_get(hw, vif);
636 if (!skb) {
637 wcn36xx_err("failed to alloc probereq skb\n");
638 goto out;
639 }
640
641 wcn36xx_smd_update_proberesp_tmpl(wcn, vif, skb);
642 dev_kfree_skb(skb);
643 }
644
645 if (changed & BSS_CHANGED_BEACON_ENABLED ||
646 changed & BSS_CHANGED_BEACON) {
647 wcn36xx_dbg(WCN36XX_DBG_MAC,
648 "mac bss changed beacon enabled %d\n",
649 bss_conf->enable_beacon);
650
651 if (bss_conf->enable_beacon) {
652 vif_priv->bss_index = 0xff;
653 wcn36xx_smd_config_bss(wcn, vif, NULL,
654 vif->addr, false);
655 skb = ieee80211_beacon_get_tim(hw, vif, &tim_off,
656 &tim_len);
657 if (!skb) {
658 wcn36xx_err("failed to alloc beacon skb\n");
659 goto out;
660 }
661 wcn36xx_smd_send_beacon(wcn, vif, skb, tim_off, 0);
662 dev_kfree_skb(skb);
663
664 if (vif->type == NL80211_IFTYPE_ADHOC ||
665 vif->type == NL80211_IFTYPE_MESH_POINT)
666 link_state = WCN36XX_HAL_LINK_IBSS_STATE;
667 else
668 link_state = WCN36XX_HAL_LINK_AP_STATE;
669
670 wcn36xx_smd_set_link_st(wcn, vif->addr, vif->addr,
671 link_state);
672 } else {
673 wcn36xx_smd_set_link_st(wcn, vif->addr, vif->addr,
674 WCN36XX_HAL_LINK_IDLE_STATE);
675 wcn36xx_smd_delete_bss(wcn, vif);
676 }
677 }
678 out:
679 return;
680 }
681
682 /* this is required when using IEEE80211_HW_HAS_RATE_CONTROL */
683 static int wcn36xx_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
684 {
685 struct wcn36xx *wcn = hw->priv;
686 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac set RTS threshold %d\n", value);
687
688 wcn36xx_smd_update_cfg(wcn, WCN36XX_HAL_CFG_RTS_THRESHOLD, value);
689 return 0;
690 }
691
692 static void wcn36xx_remove_interface(struct ieee80211_hw *hw,
693 struct ieee80211_vif *vif)
694 {
695 struct wcn36xx *wcn = hw->priv;
696 struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
697 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac remove interface vif %p\n", vif);
698
699 list_del(&vif_priv->list);
700 wcn36xx_smd_delete_sta_self(wcn, vif->addr);
701 }
702
703 static int wcn36xx_add_interface(struct ieee80211_hw *hw,
704 struct ieee80211_vif *vif)
705 {
706 struct wcn36xx *wcn = hw->priv;
707 struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
708
709 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac add interface vif %p type %d\n",
710 vif, vif->type);
711
712 if (!(NL80211_IFTYPE_STATION == vif->type ||
713 NL80211_IFTYPE_AP == vif->type ||
714 NL80211_IFTYPE_ADHOC == vif->type ||
715 NL80211_IFTYPE_MESH_POINT == vif->type)) {
716 wcn36xx_warn("Unsupported interface type requested: %d\n",
717 vif->type);
718 return -EOPNOTSUPP;
719 }
720
721 list_add(&vif_priv->list, &wcn->vif_list);
722 wcn36xx_smd_add_sta_self(wcn, vif);
723
724 return 0;
725 }
726
727 static int wcn36xx_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
728 struct ieee80211_sta *sta)
729 {
730 struct wcn36xx *wcn = hw->priv;
731 struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
732 struct wcn36xx_sta *sta_priv = (struct wcn36xx_sta *)sta->drv_priv;
733 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac sta add vif %p sta %pM\n",
734 vif, sta->addr);
735
736 vif_priv->sta = sta_priv;
737 sta_priv->vif = vif_priv;
738 /*
739 * For STA mode HW will be configured on BSS_CHANGED_ASSOC because
740 * at this stage AID is not available yet.
741 */
742 if (NL80211_IFTYPE_STATION != vif->type) {
743 wcn36xx_update_allowed_rates(sta, WCN36XX_BAND(wcn));
744 sta_priv->aid = sta->aid;
745 wcn36xx_smd_config_sta(wcn, vif, sta);
746 }
747 return 0;
748 }
749
750 static int wcn36xx_sta_remove(struct ieee80211_hw *hw,
751 struct ieee80211_vif *vif,
752 struct ieee80211_sta *sta)
753 {
754 struct wcn36xx *wcn = hw->priv;
755 struct wcn36xx_vif *vif_priv = (struct wcn36xx_vif *)vif->drv_priv;
756 struct wcn36xx_sta *sta_priv = (struct wcn36xx_sta *)sta->drv_priv;
757
758 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac sta remove vif %p sta %pM index %d\n",
759 vif, sta->addr, sta_priv->sta_index);
760
761 wcn36xx_smd_delete_sta(wcn, sta_priv->sta_index);
762 vif_priv->sta = NULL;
763 sta_priv->vif = NULL;
764 return 0;
765 }
766
767 #ifdef CONFIG_PM
768
769 static int wcn36xx_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wow)
770 {
771 struct wcn36xx *wcn = hw->priv;
772
773 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac suspend\n");
774
775 flush_workqueue(wcn->hal_ind_wq);
776 wcn36xx_smd_set_power_params(wcn, true);
777 return 0;
778 }
779
780 static int wcn36xx_resume(struct ieee80211_hw *hw)
781 {
782 struct wcn36xx *wcn = hw->priv;
783
784 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac resume\n");
785
786 flush_workqueue(wcn->hal_ind_wq);
787 wcn36xx_smd_set_power_params(wcn, false);
788 return 0;
789 }
790
791 #endif
792
793 static int wcn36xx_ampdu_action(struct ieee80211_hw *hw,
794 struct ieee80211_vif *vif,
795 enum ieee80211_ampdu_mlme_action action,
796 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
797 u8 buf_size)
798 {
799 struct wcn36xx *wcn = hw->priv;
800 struct wcn36xx_sta *sta_priv = NULL;
801
802 wcn36xx_dbg(WCN36XX_DBG_MAC, "mac ampdu action action %d tid %d\n",
803 action, tid);
804
805 sta_priv = (struct wcn36xx_sta *)sta->drv_priv;
806
807 switch (action) {
808 case IEEE80211_AMPDU_RX_START:
809 sta_priv->tid = tid;
810 wcn36xx_smd_add_ba_session(wcn, sta, tid, ssn, 0,
811 get_sta_index(vif, sta_priv));
812 wcn36xx_smd_add_ba(wcn);
813 wcn36xx_smd_trigger_ba(wcn, get_sta_index(vif, sta_priv));
814 ieee80211_start_tx_ba_session(sta, tid, 0);
815 break;
816 case IEEE80211_AMPDU_RX_STOP:
817 wcn36xx_smd_del_ba(wcn, tid, get_sta_index(vif, sta_priv));
818 break;
819 case IEEE80211_AMPDU_TX_START:
820 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
821 break;
822 case IEEE80211_AMPDU_TX_OPERATIONAL:
823 wcn36xx_smd_add_ba_session(wcn, sta, tid, ssn, 1,
824 get_sta_index(vif, sta_priv));
825 break;
826 case IEEE80211_AMPDU_TX_STOP_FLUSH:
827 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
828 case IEEE80211_AMPDU_TX_STOP_CONT:
829 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
830 break;
831 default:
832 wcn36xx_err("Unknown AMPDU action\n");
833 }
834
835 return 0;
836 }
837
838 static const struct ieee80211_ops wcn36xx_ops = {
839 .start = wcn36xx_start,
840 .stop = wcn36xx_stop,
841 .add_interface = wcn36xx_add_interface,
842 .remove_interface = wcn36xx_remove_interface,
843 #ifdef CONFIG_PM
844 .suspend = wcn36xx_suspend,
845 .resume = wcn36xx_resume,
846 #endif
847 .config = wcn36xx_config,
848 .configure_filter = wcn36xx_configure_filter,
849 .tx = wcn36xx_tx,
850 .set_key = wcn36xx_set_key,
851 .sw_scan_start = wcn36xx_sw_scan_start,
852 .sw_scan_complete = wcn36xx_sw_scan_complete,
853 .bss_info_changed = wcn36xx_bss_info_changed,
854 .set_rts_threshold = wcn36xx_set_rts_threshold,
855 .sta_add = wcn36xx_sta_add,
856 .sta_remove = wcn36xx_sta_remove,
857 .ampdu_action = wcn36xx_ampdu_action,
858 };
859
860 static int wcn36xx_init_ieee80211(struct wcn36xx *wcn)
861 {
862 int ret = 0;
863
864 static const u32 cipher_suites[] = {
865 WLAN_CIPHER_SUITE_WEP40,
866 WLAN_CIPHER_SUITE_WEP104,
867 WLAN_CIPHER_SUITE_TKIP,
868 WLAN_CIPHER_SUITE_CCMP,
869 };
870
871 wcn->hw->flags = IEEE80211_HW_SIGNAL_DBM |
872 IEEE80211_HW_HAS_RATE_CONTROL |
873 IEEE80211_HW_SUPPORTS_PS |
874 IEEE80211_HW_CONNECTION_MONITOR |
875 IEEE80211_HW_AMPDU_AGGREGATION |
876 IEEE80211_HW_TIMING_BEACON_ONLY;
877
878 wcn->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
879 BIT(NL80211_IFTYPE_AP) |
880 BIT(NL80211_IFTYPE_ADHOC) |
881 BIT(NL80211_IFTYPE_MESH_POINT);
882
883 wcn->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wcn_band_2ghz;
884 wcn->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &wcn_band_5ghz;
885
886 wcn->hw->wiphy->cipher_suites = cipher_suites;
887 wcn->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
888
889 wcn->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
890
891 #ifdef CONFIG_PM
892 wcn->hw->wiphy->wowlan = &wowlan_support;
893 #endif
894
895 wcn->hw->max_listen_interval = 200;
896
897 wcn->hw->queues = 4;
898
899 SET_IEEE80211_DEV(wcn->hw, wcn->dev);
900
901 wcn->hw->sta_data_size = sizeof(struct wcn36xx_sta);
902 wcn->hw->vif_data_size = sizeof(struct wcn36xx_vif);
903
904 return ret;
905 }
906
907 static int wcn36xx_platform_get_resources(struct wcn36xx *wcn,
908 struct platform_device *pdev)
909 {
910 struct resource *res;
911 /* Set TX IRQ */
912 res = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
913 "wcnss_wlantx_irq");
914 if (!res) {
915 wcn36xx_err("failed to get tx_irq\n");
916 return -ENOENT;
917 }
918 wcn->tx_irq = res->start;
919
920 /* Set RX IRQ */
921 res = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
922 "wcnss_wlanrx_irq");
923 if (!res) {
924 wcn36xx_err("failed to get rx_irq\n");
925 return -ENOENT;
926 }
927 wcn->rx_irq = res->start;
928
929 /* Map the memory */
930 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
931 "wcnss_mmio");
932 if (!res) {
933 wcn36xx_err("failed to get mmio\n");
934 return -ENOENT;
935 }
936 wcn->mmio = ioremap(res->start, resource_size(res));
937 if (!wcn->mmio) {
938 wcn36xx_err("failed to map io memory\n");
939 return -ENOMEM;
940 }
941 return 0;
942 }
943
944 static int wcn36xx_probe(struct platform_device *pdev)
945 {
946 struct ieee80211_hw *hw;
947 struct wcn36xx *wcn;
948 int ret;
949 u8 addr[ETH_ALEN];
950
951 wcn36xx_dbg(WCN36XX_DBG_MAC, "platform probe\n");
952
953 hw = ieee80211_alloc_hw(sizeof(struct wcn36xx), &wcn36xx_ops);
954 if (!hw) {
955 wcn36xx_err("failed to alloc hw\n");
956 ret = -ENOMEM;
957 goto out_err;
958 }
959 platform_set_drvdata(pdev, hw);
960 wcn = hw->priv;
961 wcn->hw = hw;
962 wcn->dev = &pdev->dev;
963 wcn->ctrl_ops = pdev->dev.platform_data;
964
965 mutex_init(&wcn->hal_mutex);
966
967 if (!wcn->ctrl_ops->get_hw_mac(addr)) {
968 wcn36xx_info("mac address: %pM\n", addr);
969 SET_IEEE80211_PERM_ADDR(wcn->hw, addr);
970 }
971
972 ret = wcn36xx_platform_get_resources(wcn, pdev);
973 if (ret)
974 goto out_wq;
975
976 wcn36xx_init_ieee80211(wcn);
977 ret = ieee80211_register_hw(wcn->hw);
978 if (ret)
979 goto out_unmap;
980
981 return 0;
982
983 out_unmap:
984 iounmap(wcn->mmio);
985 out_wq:
986 ieee80211_free_hw(hw);
987 out_err:
988 return ret;
989 }
990 static int wcn36xx_remove(struct platform_device *pdev)
991 {
992 struct ieee80211_hw *hw = platform_get_drvdata(pdev);
993 struct wcn36xx *wcn = hw->priv;
994 wcn36xx_dbg(WCN36XX_DBG_MAC, "platform remove\n");
995
996 release_firmware(wcn->nv);
997 mutex_destroy(&wcn->hal_mutex);
998
999 ieee80211_unregister_hw(hw);
1000 iounmap(wcn->mmio);
1001 ieee80211_free_hw(hw);
1002
1003 return 0;
1004 }
1005 static const struct platform_device_id wcn36xx_platform_id_table[] = {
1006 {
1007 .name = "wcn36xx",
1008 .driver_data = 0
1009 },
1010 {}
1011 };
1012 MODULE_DEVICE_TABLE(platform, wcn36xx_platform_id_table);
1013
1014 static struct platform_driver wcn36xx_driver = {
1015 .probe = wcn36xx_probe,
1016 .remove = wcn36xx_remove,
1017 .driver = {
1018 .name = "wcn36xx",
1019 .owner = THIS_MODULE,
1020 },
1021 .id_table = wcn36xx_platform_id_table,
1022 };
1023
1024 static int __init wcn36xx_init(void)
1025 {
1026 platform_driver_register(&wcn36xx_driver);
1027 return 0;
1028 }
1029 module_init(wcn36xx_init);
1030
1031 static void __exit wcn36xx_exit(void)
1032 {
1033 platform_driver_unregister(&wcn36xx_driver);
1034 }
1035 module_exit(wcn36xx_exit);
1036
1037 MODULE_LICENSE("Dual BSD/GPL");
1038 MODULE_AUTHOR("Eugene Krasnikov k.eugene.e@gmail.com");
1039 MODULE_FIRMWARE(WLAN_NV_FILE);
This page took 0.074901 seconds and 5 git commands to generate.