aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/wl12xx
diff options
context:
space:
mode:
authorGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
committerGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
commitc71c03bda1e86c9d5198c5d83f712e695c4f2a1e (patch)
treeecb166cb3e2b7e2adb3b5e292245fefd23381ac8 /drivers/net/wireless/wl12xx
parentea53c912f8a86a8567697115b6a0d8152beee5c8 (diff)
parent6a00f206debf8a5c8899055726ad127dbeeed098 (diff)
Merge branch 'mpi-master' into wip-k-fmlpwip-k-fmlp
Conflicts: litmus/sched_cedf.c
Diffstat (limited to 'drivers/net/wireless/wl12xx')
-rw-r--r--drivers/net/wireless/wl12xx/Kconfig99
-rw-r--r--drivers/net/wireless/wl12xx/Makefile28
-rw-r--r--drivers/net/wireless/wl12xx/acx.c (renamed from drivers/net/wireless/wl12xx/wl1271_acx.c)565
-rw-r--r--drivers/net/wireless/wl12xx/acx.h (renamed from drivers/net/wireless/wl12xx/wl1271_acx.h)384
-rw-r--r--drivers/net/wireless/wl12xx/boot.c (renamed from drivers/net/wireless/wl12xx/wl1271_boot.c)354
-rw-r--r--drivers/net/wireless/wl12xx/boot.h (renamed from drivers/net/wireless/wl12xx/wl1271_boot.h)61
-rw-r--r--drivers/net/wireless/wl12xx/cmd.c (renamed from drivers/net/wireless/wl12xx/wl1271_cmd.c)636
-rw-r--r--drivers/net/wireless/wl12xx/cmd.h (renamed from drivers/net/wireless/wl12xx/wl1271_cmd.h)290
-rw-r--r--drivers/net/wireless/wl12xx/conf.h (renamed from drivers/net/wireless/wl12xx/wl1271_conf.h)276
-rw-r--r--drivers/net/wireless/wl12xx/debugfs.c709
-rw-r--r--drivers/net/wireless/wl12xx/debugfs.h (renamed from drivers/net/wireless/wl12xx/wl1271_debugfs.h)6
-rw-r--r--drivers/net/wireless/wl12xx/event.c (renamed from drivers/net/wireless/wl12xx/wl1271_event.c)80
-rw-r--r--drivers/net/wireless/wl12xx/event.h (renamed from drivers/net/wireless/wl12xx/wl1271_event.h)17
-rw-r--r--drivers/net/wireless/wl12xx/ini.h (renamed from drivers/net/wireless/wl12xx/wl1271_ini.h)102
-rw-r--r--drivers/net/wireless/wl12xx/init.c723
-rw-r--r--drivers/net/wireless/wl12xx/init.h (renamed from drivers/net/wireless/wl12xx/wl1271_init.h)11
-rw-r--r--drivers/net/wireless/wl12xx/io.c (renamed from drivers/net/wireless/wl12xx/wl1271_io.c)16
-rw-r--r--drivers/net/wireless/wl12xx/io.h (renamed from drivers/net/wireless/wl12xx/wl1271_io.h)21
-rw-r--r--drivers/net/wireless/wl12xx/main.c4095
-rw-r--r--drivers/net/wireless/wl12xx/ps.c (renamed from drivers/net/wireless/wl12xx/wl1271_ps.c)137
-rw-r--r--drivers/net/wireless/wl12xx/ps.h (renamed from drivers/net/wireless/wl12xx/wl1271_ps.h)16
-rw-r--r--drivers/net/wireless/wl12xx/reg.h (renamed from drivers/net/wireless/wl12xx/wl1271_reg.h)15
-rw-r--r--drivers/net/wireless/wl12xx/rx.c244
-rw-r--r--drivers/net/wireless/wl12xx/rx.h (renamed from drivers/net/wireless/wl12xx/wl1271_rx.h)23
-rw-r--r--drivers/net/wireless/wl12xx/scan.c582
-rw-r--r--drivers/net/wireless/wl12xx/scan.h (renamed from drivers/net/wireless/wl12xx/wl1271_scan.h)129
-rw-r--r--drivers/net/wireless/wl12xx/sdio.c (renamed from drivers/net/wireless/wl12xx/wl1271_sdio.c)208
-rw-r--r--drivers/net/wireless/wl12xx/sdio_test.c534
-rw-r--r--drivers/net/wireless/wl12xx/spi.c (renamed from drivers/net/wireless/wl12xx/wl1271_spi.c)194
-rw-r--r--drivers/net/wireless/wl12xx/testmode.c (renamed from drivers/net/wireless/wl12xx/wl1271_testmode.c)41
-rw-r--r--drivers/net/wireless/wl12xx/testmode.h (renamed from drivers/net/wireless/wl12xx/wl1271_testmode.h)4
-rw-r--r--drivers/net/wireless/wl12xx/tx.c885
-rw-r--r--drivers/net/wireless/wl12xx/tx.h (renamed from drivers/net/wireless/wl12xx/wl1271_tx.h)101
-rw-r--r--drivers/net/wireless/wl12xx/wl1251.h432
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_acx.c1048
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_acx.h1413
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_boot.c559
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_boot.h41
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_cmd.c496
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_cmd.h417
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_debugfs.c543
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_debugfs.h33
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_event.c143
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_event.h121
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_init.c425
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_init.h88
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_io.c196
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_io.h84
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_main.c1442
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_ps.c196
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_ps.h37
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_reg.h657
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_rx.c192
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_rx.h124
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_sdio.c342
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_spi.c348
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_spi.h61
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_tx.c562
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_tx.h233
-rw-r--r--drivers/net/wireless/wl12xx/wl1271.h510
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_debugfs.c579
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_init.c368
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_main.c2491
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_rx.c156
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_scan.c257
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_tx.c464
-rw-r--r--drivers/net/wireless/wl12xx/wl12xx.h639
-rw-r--r--drivers/net/wireless/wl12xx/wl12xx_80211.h25
-rw-r--r--drivers/net/wireless/wl12xx/wl12xx_platform_data.c28
69 files changed, 11564 insertions, 15772 deletions
diff --git a/drivers/net/wireless/wl12xx/Kconfig b/drivers/net/wireless/wl12xx/Kconfig
index 2f98058be451..35ce7b0f4a60 100644
--- a/drivers/net/wireless/wl12xx/Kconfig
+++ b/drivers/net/wireless/wl12xx/Kconfig
@@ -1,77 +1,68 @@
1menuconfig WL12XX 1menuconfig WL12XX_MENU
2 tristate "TI wl12xx driver support" 2 tristate "TI wl12xx driver support"
3 depends on MAC80211 && EXPERIMENTAL 3 depends on MAC80211 && EXPERIMENTAL
4 ---help--- 4 ---help---
5 This will enable TI wl12xx driver support. The drivers make 5 This will enable TI wl12xx driver support for the following chips:
6 use of the mac80211 stack. 6 wl1271, wl1273, wl1281 and wl1283.
7 The drivers make use of the mac80211 stack.
7 8
8config WL1251 9config WL12XX
9 tristate "TI wl1251 support" 10 tristate "TI wl12xx support"
10 depends on WL12XX && GENERIC_HARDIRQS 11 depends on WL12XX_MENU && GENERIC_HARDIRQS
11 select FW_LOADER
12 select CRC7
13 ---help---
14 This module adds support for wireless adapters based on
15 TI wl1251 chipset.
16
17 If you choose to build a module, it'll be called wl1251. Say
18 N if unsure.
19
20config WL1251_SPI
21 tristate "TI wl1251 SPI support"
22 depends on WL1251 && SPI_MASTER
23 ---help---
24 This module adds support for the SPI interface of adapters using
25 TI wl1251 chipset. Select this if your platform is using
26 the SPI bus.
27
28 If you choose to build a module, it'll be called wl1251_spi.
29 Say N if unsure.
30
31config WL1251_SDIO
32 tristate "TI wl1251 SDIO support"
33 depends on WL1251 && MMC
34 ---help---
35 This module adds support for the SDIO interface of adapters using
36 TI wl1251 chipset. Select this if your platform is using
37 the SDIO bus.
38
39 If you choose to build a module, it'll be called
40 wl1251_sdio. Say N if unsure.
41
42config WL1271
43 tristate "TI wl1271 support"
44 depends on WL12XX && GENERIC_HARDIRQS
45 depends on INET 12 depends on INET
46 select FW_LOADER 13 select FW_LOADER
47 select CRC7 14 select CRC7
48 ---help--- 15 ---help---
49 This module adds support for wireless adapters based on the 16 This module adds support for wireless adapters based on TI wl1271 and
50 TI wl1271 chipset. 17 TI wl1273 chipsets. This module does *not* include support for wl1251.
18 For wl1251 support, use the separate homonymous driver instead.
51 19
52 If you choose to build a module, it'll be called wl1271. Say N if 20 If you choose to build a module, it will be called wl12xx. Say N if
53 unsure. 21 unsure.
54 22
55config WL1271_SPI 23config WL12XX_HT
56 tristate "TI wl1271 SPI support" 24 bool "TI wl12xx 802.11 HT support (EXPERIMENTAL)"
57 depends on WL1271 && SPI_MASTER 25 depends on WL12XX && EXPERIMENTAL
26 default n
27 ---help---
28 This will enable 802.11 HT support in the wl12xx module.
29
30 That configuration is temporary due to the code incomplete and
31 still in testing process.
32
33config WL12XX_SPI
34 tristate "TI wl12xx SPI support"
35 depends on WL12XX && SPI_MASTER
58 ---help--- 36 ---help---
59 This module adds support for the SPI interface of adapters using 37 This module adds support for the SPI interface of adapters using
60 TI wl1271 chipset. Select this if your platform is using 38 TI wl12xx chipsets. Select this if your platform is using
61 the SPI bus. 39 the SPI bus.
62 40
63 If you choose to build a module, it'll be called wl1251_spi. 41 If you choose to build a module, it'll be called wl12xx_spi.
64 Say N if unsure. 42 Say N if unsure.
65 43
66config WL1271_SDIO 44config WL12XX_SDIO
67 tristate "TI wl1271 SDIO support" 45 tristate "TI wl12xx SDIO support"
68 depends on WL1271 && MMC 46 depends on WL12XX && MMC
69 ---help--- 47 ---help---
70 This module adds support for the SDIO interface of adapters using 48 This module adds support for the SDIO interface of adapters using
71 TI wl1271 chipset. Select this if your platform is using 49 TI wl12xx chipsets. Select this if your platform is using
72 the SDIO bus. 50 the SDIO bus.
73 51
74 If you choose to build a module, it'll be called 52 If you choose to build a module, it'll be called wl12xx_sdio.
75 wl1271_sdio. Say N if unsure. 53 Say N if unsure.
76 54
55config WL12XX_SDIO_TEST
56 tristate "TI wl12xx SDIO testing support"
57 depends on WL12XX && MMC && WL12XX_SDIO
58 default n
59 ---help---
60 This module adds support for the SDIO bus testing with the
61 TI wl12xx chipsets. You probably don't want this unless you are
62 testing a new hardware platform. Select this if you want to test the
63 SDIO bus which is connected to the wl12xx chip.
77 64
65config WL12XX_PLATFORM_DATA
66 bool
67 depends on WL12XX_SDIO != n || WL1251_SDIO != n
68 default y
diff --git a/drivers/net/wireless/wl12xx/Makefile b/drivers/net/wireless/wl12xx/Makefile
index 078b4398ac1f..521c0414e52e 100644
--- a/drivers/net/wireless/wl12xx/Makefile
+++ b/drivers/net/wireless/wl12xx/Makefile
@@ -1,18 +1,16 @@
1wl1251-objs = wl1251_main.o wl1251_event.o \ 1wl12xx-objs = main.o cmd.o io.o event.o tx.o rx.o ps.o acx.o \
2 wl1251_tx.o wl1251_rx.o wl1251_ps.o wl1251_cmd.o \ 2 boot.o init.o debugfs.o scan.o
3 wl1251_acx.o wl1251_boot.o wl1251_init.o \
4 wl1251_debugfs.o wl1251_io.o
5 3
6obj-$(CONFIG_WL1251) += wl1251.o 4wl12xx_spi-objs = spi.o
7obj-$(CONFIG_WL1251_SPI) += wl1251_spi.o 5wl12xx_sdio-objs = sdio.o
8obj-$(CONFIG_WL1251_SDIO) += wl1251_sdio.o 6wl12xx_sdio_test-objs = sdio_test.o
9 7
10wl1271-objs = wl1271_main.o wl1271_cmd.o wl1271_io.o \ 8wl12xx-$(CONFIG_NL80211_TESTMODE) += testmode.o
11 wl1271_event.o wl1271_tx.o wl1271_rx.o \ 9obj-$(CONFIG_WL12XX) += wl12xx.o
12 wl1271_ps.o wl1271_acx.o wl1271_boot.o \ 10obj-$(CONFIG_WL12XX_SPI) += wl12xx_spi.o
13 wl1271_init.o wl1271_debugfs.o wl1271_scan.o 11obj-$(CONFIG_WL12XX_SDIO) += wl12xx_sdio.o
14 12
15wl1271-$(CONFIG_NL80211_TESTMODE) += wl1271_testmode.o 13obj-$(CONFIG_WL12XX_SDIO_TEST) += wl12xx_sdio_test.o
16obj-$(CONFIG_WL1271) += wl1271.o 14
17obj-$(CONFIG_WL1271_SPI) += wl1271_spi.o 15# small builtin driver bit
18obj-$(CONFIG_WL1271_SDIO) += wl1271_sdio.o 16obj-$(CONFIG_WL12XX_PLATFORM_DATA) += wl12xx_platform_data.o
diff --git a/drivers/net/wireless/wl12xx/wl1271_acx.c b/drivers/net/wireless/wl12xx/acx.c
index bb245f05af49..c6ee530e5bf7 100644
--- a/drivers/net/wireless/wl12xx/wl1271_acx.c
+++ b/drivers/net/wireless/wl12xx/acx.c
@@ -21,7 +21,7 @@
21 * 21 *
22 */ 22 */
23 23
24#include "wl1271_acx.h" 24#include "acx.h"
25 25
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/platform_device.h> 27#include <linux/platform_device.h>
@@ -29,10 +29,10 @@
29#include <linux/spi/spi.h> 29#include <linux/spi/spi.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31 31
32#include "wl1271.h" 32#include "wl12xx.h"
33#include "wl12xx_80211.h" 33#include "wl12xx_80211.h"
34#include "wl1271_reg.h" 34#include "reg.h"
35#include "wl1271_ps.h" 35#include "ps.h"
36 36
37int wl1271_acx_wake_up_conditions(struct wl1271 *wl) 37int wl1271_acx_wake_up_conditions(struct wl1271 *wl)
38{ 38{
@@ -86,40 +86,6 @@ out:
86 return ret; 86 return ret;
87} 87}
88 88
89int wl1271_acx_fw_version(struct wl1271 *wl, char *buf, size_t len)
90{
91 struct acx_revision *rev;
92 int ret;
93
94 wl1271_debug(DEBUG_ACX, "acx fw rev");
95
96 rev = kzalloc(sizeof(*rev), GFP_KERNEL);
97 if (!rev) {
98 ret = -ENOMEM;
99 goto out;
100 }
101
102 ret = wl1271_cmd_interrogate(wl, ACX_FW_REV, rev, sizeof(*rev));
103 if (ret < 0) {
104 wl1271_warning("ACX_FW_REV interrogate failed");
105 goto out;
106 }
107
108 /* be careful with the buffer sizes */
109 strncpy(buf, rev->fw_version, min(len, sizeof(rev->fw_version)));
110
111 /*
112 * if the firmware version string is exactly
113 * sizeof(rev->fw_version) long or fw_len is less than
114 * sizeof(rev->fw_version) it won't be null terminated
115 */
116 buf[min(len, sizeof(rev->fw_version)) - 1] = '\0';
117
118out:
119 kfree(rev);
120 return ret;
121}
122
123int wl1271_acx_tx_power(struct wl1271 *wl, int power) 89int wl1271_acx_tx_power(struct wl1271 *wl, int power)
124{ 90{
125 struct acx_current_tx_power *acx; 91 struct acx_current_tx_power *acx;
@@ -269,7 +235,7 @@ int wl1271_acx_pd_threshold(struct wl1271 *wl)
269 235
270out: 236out:
271 kfree(pd); 237 kfree(pd);
272 return 0; 238 return ret;
273} 239}
274 240
275int wl1271_acx_slot(struct wl1271 *wl, enum acx_slot_type slot_time) 241int wl1271_acx_slot(struct wl1271 *wl, enum acx_slot_type slot_time)
@@ -359,12 +325,19 @@ out:
359 return ret; 325 return ret;
360} 326}
361 327
362int wl1271_acx_rts_threshold(struct wl1271 *wl, u16 rts_threshold) 328int wl1271_acx_rts_threshold(struct wl1271 *wl, u32 rts_threshold)
363{ 329{
364 struct acx_rts_threshold *rts; 330 struct acx_rts_threshold *rts;
365 int ret; 331 int ret;
366 332
367 wl1271_debug(DEBUG_ACX, "acx rts threshold"); 333 /*
334 * If the RTS threshold is not configured or out of range, use the
335 * default value.
336 */
337 if (rts_threshold > IEEE80211_MAX_RTS_THRESHOLD)
338 rts_threshold = wl->conf.rx.rts_threshold;
339
340 wl1271_debug(DEBUG_ACX, "acx rts threshold: %d", rts_threshold);
368 341
369 rts = kzalloc(sizeof(*rts), GFP_KERNEL); 342 rts = kzalloc(sizeof(*rts), GFP_KERNEL);
370 if (!rts) { 343 if (!rts) {
@@ -372,7 +345,7 @@ int wl1271_acx_rts_threshold(struct wl1271 *wl, u16 rts_threshold)
372 goto out; 345 goto out;
373 } 346 }
374 347
375 rts->threshold = cpu_to_le16(rts_threshold); 348 rts->threshold = cpu_to_le16((u16)rts_threshold);
376 349
377 ret = wl1271_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts)); 350 ret = wl1271_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts));
378 if (ret < 0) { 351 if (ret < 0) {
@@ -574,13 +547,13 @@ out:
574 return ret; 547 return ret;
575} 548}
576 549
577int wl1271_acx_sg_cfg(struct wl1271 *wl) 550int wl1271_acx_sta_sg_cfg(struct wl1271 *wl)
578{ 551{
579 struct acx_bt_wlan_coex_param *param; 552 struct acx_sta_bt_wlan_coex_param *param;
580 struct conf_sg_settings *c = &wl->conf.sg; 553 struct conf_sg_settings *c = &wl->conf.sg;
581 int i, ret; 554 int i, ret;
582 555
583 wl1271_debug(DEBUG_ACX, "acx sg cfg"); 556 wl1271_debug(DEBUG_ACX, "acx sg sta cfg");
584 557
585 param = kzalloc(sizeof(*param), GFP_KERNEL); 558 param = kzalloc(sizeof(*param), GFP_KERNEL);
586 if (!param) { 559 if (!param) {
@@ -589,8 +562,38 @@ int wl1271_acx_sg_cfg(struct wl1271 *wl)
589 } 562 }
590 563
591 /* BT-WLAN coext parameters */ 564 /* BT-WLAN coext parameters */
592 for (i = 0; i < CONF_SG_PARAMS_MAX; i++) 565 for (i = 0; i < CONF_SG_STA_PARAMS_MAX; i++)
593 param->params[i] = cpu_to_le32(c->params[i]); 566 param->params[i] = cpu_to_le32(c->sta_params[i]);
567 param->param_idx = CONF_SG_PARAMS_ALL;
568
569 ret = wl1271_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param));
570 if (ret < 0) {
571 wl1271_warning("failed to set sg config: %d", ret);
572 goto out;
573 }
574
575out:
576 kfree(param);
577 return ret;
578}
579
580int wl1271_acx_ap_sg_cfg(struct wl1271 *wl)
581{
582 struct acx_ap_bt_wlan_coex_param *param;
583 struct conf_sg_settings *c = &wl->conf.sg;
584 int i, ret;
585
586 wl1271_debug(DEBUG_ACX, "acx sg ap cfg");
587
588 param = kzalloc(sizeof(*param), GFP_KERNEL);
589 if (!param) {
590 ret = -ENOMEM;
591 goto out;
592 }
593
594 /* BT-WLAN coext parameters */
595 for (i = 0; i < CONF_SG_AP_PARAMS_MAX; i++)
596 param->params[i] = cpu_to_le32(c->ap_params[i]);
594 param->param_idx = CONF_SG_PARAMS_ALL; 597 param->param_idx = CONF_SG_PARAMS_ALL;
595 598
596 ret = wl1271_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param)); 599 ret = wl1271_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param));
@@ -785,10 +788,10 @@ int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats)
785 return 0; 788 return 0;
786} 789}
787 790
788int wl1271_acx_rate_policies(struct wl1271 *wl) 791int wl1271_acx_sta_rate_policies(struct wl1271 *wl)
789{ 792{
790 struct acx_rate_policy *acx; 793 struct acx_sta_rate_policy *acx;
791 struct conf_tx_rate_class *c = &wl->conf.tx.rc_conf; 794 struct conf_tx_rate_class *c = &wl->conf.tx.sta_rc_conf;
792 int idx = 0; 795 int idx = 0;
793 int ret = 0; 796 int ret = 0;
794 797
@@ -817,6 +820,10 @@ int wl1271_acx_rate_policies(struct wl1271 *wl)
817 820
818 acx->rate_class_cnt = cpu_to_le32(ACX_TX_RATE_POLICY_CNT); 821 acx->rate_class_cnt = cpu_to_le32(ACX_TX_RATE_POLICY_CNT);
819 822
823 wl1271_debug(DEBUG_ACX, "basic_rate: 0x%x, full_rate: 0x%x",
824 acx->rate_class[ACX_TX_BASIC_RATE].enabled_rates,
825 acx->rate_class[ACX_TX_AP_FULL_RATE].enabled_rates);
826
820 ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx)); 827 ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
821 if (ret < 0) { 828 if (ret < 0) {
822 wl1271_warning("Setting of rate policies failed: %d", ret); 829 wl1271_warning("Setting of rate policies failed: %d", ret);
@@ -828,6 +835,39 @@ out:
828 return ret; 835 return ret;
829} 836}
830 837
838int wl1271_acx_ap_rate_policy(struct wl1271 *wl, struct conf_tx_rate_class *c,
839 u8 idx)
840{
841 struct acx_ap_rate_policy *acx;
842 int ret = 0;
843
844 wl1271_debug(DEBUG_ACX, "acx ap rate policy %d rates 0x%x",
845 idx, c->enabled_rates);
846
847 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
848 if (!acx) {
849 ret = -ENOMEM;
850 goto out;
851 }
852
853 acx->rate_policy.enabled_rates = cpu_to_le32(c->enabled_rates);
854 acx->rate_policy.short_retry_limit = c->short_retry_limit;
855 acx->rate_policy.long_retry_limit = c->long_retry_limit;
856 acx->rate_policy.aflags = c->aflags;
857
858 acx->rate_policy_idx = cpu_to_le32(idx);
859
860 ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
861 if (ret < 0) {
862 wl1271_warning("Setting of ap rate policy failed: %d", ret);
863 goto out;
864 }
865
866out:
867 kfree(acx);
868 return ret;
869}
870
831int wl1271_acx_ac_cfg(struct wl1271 *wl, u8 ac, u8 cw_min, u16 cw_max, 871int wl1271_acx_ac_cfg(struct wl1271 *wl, u8 ac, u8 cw_min, u16 cw_max,
832 u8 aifsn, u16 txop) 872 u8 aifsn, u16 txop)
833{ 873{
@@ -896,12 +936,19 @@ out:
896 return ret; 936 return ret;
897} 937}
898 938
899int wl1271_acx_frag_threshold(struct wl1271 *wl) 939int wl1271_acx_frag_threshold(struct wl1271 *wl, u32 frag_threshold)
900{ 940{
901 struct acx_frag_threshold *acx; 941 struct acx_frag_threshold *acx;
902 int ret = 0; 942 int ret = 0;
903 943
904 wl1271_debug(DEBUG_ACX, "acx frag threshold"); 944 /*
945 * If the fragmentation is not configured or out of range, use the
946 * default value.
947 */
948 if (frag_threshold > IEEE80211_MAX_FRAG_THRESHOLD)
949 frag_threshold = wl->conf.tx.frag_threshold;
950
951 wl1271_debug(DEBUG_ACX, "acx frag threshold: %d", frag_threshold);
905 952
906 acx = kzalloc(sizeof(*acx), GFP_KERNEL); 953 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
907 954
@@ -910,7 +957,7 @@ int wl1271_acx_frag_threshold(struct wl1271 *wl)
910 goto out; 957 goto out;
911 } 958 }
912 959
913 acx->frag_threshold = cpu_to_le16(wl->conf.tx.frag_threshold); 960 acx->frag_threshold = cpu_to_le16((u16)frag_threshold);
914 ret = wl1271_cmd_configure(wl, ACX_FRAG_CFG, acx, sizeof(*acx)); 961 ret = wl1271_cmd_configure(wl, ACX_FRAG_CFG, acx, sizeof(*acx));
915 if (ret < 0) { 962 if (ret < 0) {
916 wl1271_warning("Setting of frag threshold failed: %d", ret); 963 wl1271_warning("Setting of frag threshold failed: %d", ret);
@@ -949,9 +996,10 @@ out:
949 return ret; 996 return ret;
950} 997}
951 998
952int wl1271_acx_mem_cfg(struct wl1271 *wl) 999int wl1271_acx_ap_mem_cfg(struct wl1271 *wl)
953{ 1000{
954 struct wl1271_acx_config_memory *mem_conf; 1001 struct wl1271_acx_ap_config_memory *mem_conf;
1002 struct conf_memory_settings *mem;
955 int ret; 1003 int ret;
956 1004
957 wl1271_debug(DEBUG_ACX, "wl1271 mem cfg"); 1005 wl1271_debug(DEBUG_ACX, "wl1271 mem cfg");
@@ -962,11 +1010,21 @@ int wl1271_acx_mem_cfg(struct wl1271 *wl)
962 goto out; 1010 goto out;
963 } 1011 }
964 1012
1013 if (wl->chip.id == CHIP_ID_1283_PG20)
1014 /*
1015 * FIXME: The 128x AP FW does not yet support dynamic memory.
1016 * Use the base memory configuration for 128x for now. This
1017 * should be fine tuned in the future.
1018 */
1019 mem = &wl->conf.mem_wl128x;
1020 else
1021 mem = &wl->conf.mem_wl127x;
1022
965 /* memory config */ 1023 /* memory config */
966 mem_conf->num_stations = DEFAULT_NUM_STATIONS; 1024 mem_conf->num_stations = mem->num_stations;
967 mem_conf->rx_mem_block_num = ACX_RX_MEM_BLOCKS; 1025 mem_conf->rx_mem_block_num = mem->rx_block_num;
968 mem_conf->tx_min_mem_block_num = ACX_TX_MIN_MEM_BLOCKS; 1026 mem_conf->tx_min_mem_block_num = mem->tx_min_block_num;
969 mem_conf->num_ssid_profiles = ACX_NUM_SSID_PROFILES; 1027 mem_conf->num_ssid_profiles = mem->ssid_profiles;
970 mem_conf->total_tx_descriptors = cpu_to_le32(ACX_TX_DESCRIPTORS); 1028 mem_conf->total_tx_descriptors = cpu_to_le32(ACX_TX_DESCRIPTORS);
971 1029
972 ret = wl1271_cmd_configure(wl, ACX_MEM_CFG, mem_conf, 1030 ret = wl1271_cmd_configure(wl, ACX_MEM_CFG, mem_conf,
@@ -981,13 +1039,77 @@ out:
981 return ret; 1039 return ret;
982} 1040}
983 1041
984int wl1271_acx_init_mem_config(struct wl1271 *wl) 1042int wl1271_acx_sta_mem_cfg(struct wl1271 *wl)
985{ 1043{
1044 struct wl1271_acx_sta_config_memory *mem_conf;
1045 struct conf_memory_settings *mem;
986 int ret; 1046 int ret;
987 1047
988 ret = wl1271_acx_mem_cfg(wl); 1048 wl1271_debug(DEBUG_ACX, "wl1271 mem cfg");
989 if (ret < 0) 1049
990 return ret; 1050 mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL);
1051 if (!mem_conf) {
1052 ret = -ENOMEM;
1053 goto out;
1054 }
1055
1056 if (wl->chip.id == CHIP_ID_1283_PG20)
1057 mem = &wl->conf.mem_wl128x;
1058 else
1059 mem = &wl->conf.mem_wl127x;
1060
1061 /* memory config */
1062 mem_conf->num_stations = mem->num_stations;
1063 mem_conf->rx_mem_block_num = mem->rx_block_num;
1064 mem_conf->tx_min_mem_block_num = mem->tx_min_block_num;
1065 mem_conf->num_ssid_profiles = mem->ssid_profiles;
1066 mem_conf->total_tx_descriptors = cpu_to_le32(ACX_TX_DESCRIPTORS);
1067 mem_conf->dyn_mem_enable = mem->dynamic_memory;
1068 mem_conf->tx_free_req = mem->min_req_tx_blocks;
1069 mem_conf->rx_free_req = mem->min_req_rx_blocks;
1070 mem_conf->tx_min = mem->tx_min;
1071
1072 ret = wl1271_cmd_configure(wl, ACX_MEM_CFG, mem_conf,
1073 sizeof(*mem_conf));
1074 if (ret < 0) {
1075 wl1271_warning("wl1271 mem config failed: %d", ret);
1076 goto out;
1077 }
1078
1079out:
1080 kfree(mem_conf);
1081 return ret;
1082}
1083
1084int wl1271_acx_host_if_cfg_bitmap(struct wl1271 *wl, u32 host_cfg_bitmap)
1085{
1086 struct wl1271_acx_host_config_bitmap *bitmap_conf;
1087 int ret;
1088
1089 bitmap_conf = kzalloc(sizeof(*bitmap_conf), GFP_KERNEL);
1090 if (!bitmap_conf) {
1091 ret = -ENOMEM;
1092 goto out;
1093 }
1094
1095 bitmap_conf->host_cfg_bitmap = cpu_to_le32(host_cfg_bitmap);
1096
1097 ret = wl1271_cmd_configure(wl, ACX_HOST_IF_CFG_BITMAP,
1098 bitmap_conf, sizeof(*bitmap_conf));
1099 if (ret < 0) {
1100 wl1271_warning("wl1271 bitmap config opt failed: %d", ret);
1101 goto out;
1102 }
1103
1104out:
1105 kfree(bitmap_conf);
1106
1107 return ret;
1108}
1109
1110int wl1271_acx_init_mem_config(struct wl1271 *wl)
1111{
1112 int ret;
991 1113
992 wl->target_mem_map = kzalloc(sizeof(struct wl1271_acx_mem_map), 1114 wl->target_mem_map = kzalloc(sizeof(struct wl1271_acx_mem_map),
993 GFP_KERNEL); 1115 GFP_KERNEL);
@@ -1075,7 +1197,7 @@ out:
1075 return ret; 1197 return ret;
1076} 1198}
1077 1199
1078int wl1271_acx_arp_ip_filter(struct wl1271 *wl, bool enable, __be32 address) 1200int wl1271_acx_arp_ip_filter(struct wl1271 *wl, u8 enable, __be32 address)
1079{ 1201{
1080 struct wl1271_acx_arp_filter *acx; 1202 struct wl1271_acx_arp_filter *acx;
1081 int ret; 1203 int ret;
@@ -1091,7 +1213,7 @@ int wl1271_acx_arp_ip_filter(struct wl1271 *wl, bool enable, __be32 address)
1091 acx->version = ACX_IPV4_VERSION; 1213 acx->version = ACX_IPV4_VERSION;
1092 acx->enable = enable; 1214 acx->enable = enable;
1093 1215
1094 if (enable == true) 1216 if (enable)
1095 memcpy(acx->address, &address, ACX_IPV4_ADDR_SIZE); 1217 memcpy(acx->address, &address, ACX_IPV4_ADDR_SIZE);
1096 1218
1097 ret = wl1271_cmd_configure(wl, ACX_ARP_IP_FILTER, 1219 ret = wl1271_cmd_configure(wl, ACX_ARP_IP_FILTER,
@@ -1260,6 +1382,175 @@ out:
1260 return ret; 1382 return ret;
1261} 1383}
1262 1384
1385int wl1271_acx_set_ht_capabilities(struct wl1271 *wl,
1386 struct ieee80211_sta_ht_cap *ht_cap,
1387 bool allow_ht_operation)
1388{
1389 struct wl1271_acx_ht_capabilities *acx;
1390 u8 mac_address[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1391 int ret = 0;
1392 u32 ht_capabilites = 0;
1393
1394 wl1271_debug(DEBUG_ACX, "acx ht capabilities setting");
1395
1396 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1397 if (!acx) {
1398 ret = -ENOMEM;
1399 goto out;
1400 }
1401
1402 /* Allow HT Operation ? */
1403 if (allow_ht_operation) {
1404 ht_capabilites =
1405 WL1271_ACX_FW_CAP_HT_OPERATION;
1406 if (ht_cap->cap & IEEE80211_HT_CAP_GRN_FLD)
1407 ht_capabilites |=
1408 WL1271_ACX_FW_CAP_GREENFIELD_FRAME_FORMAT;
1409 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1410 ht_capabilites |=
1411 WL1271_ACX_FW_CAP_SHORT_GI_FOR_20MHZ_PACKETS;
1412 if (ht_cap->cap & IEEE80211_HT_CAP_LSIG_TXOP_PROT)
1413 ht_capabilites |=
1414 WL1271_ACX_FW_CAP_LSIG_TXOP_PROTECTION;
1415
1416 /* get data from A-MPDU parameters field */
1417 acx->ampdu_max_length = ht_cap->ampdu_factor;
1418 acx->ampdu_min_spacing = ht_cap->ampdu_density;
1419 }
1420
1421 memcpy(acx->mac_address, mac_address, ETH_ALEN);
1422 acx->ht_capabilites = cpu_to_le32(ht_capabilites);
1423
1424 ret = wl1271_cmd_configure(wl, ACX_PEER_HT_CAP, acx, sizeof(*acx));
1425 if (ret < 0) {
1426 wl1271_warning("acx ht capabilities setting failed: %d", ret);
1427 goto out;
1428 }
1429
1430out:
1431 kfree(acx);
1432 return ret;
1433}
1434
1435int wl1271_acx_set_ht_information(struct wl1271 *wl,
1436 u16 ht_operation_mode)
1437{
1438 struct wl1271_acx_ht_information *acx;
1439 int ret = 0;
1440
1441 wl1271_debug(DEBUG_ACX, "acx ht information setting");
1442
1443 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1444 if (!acx) {
1445 ret = -ENOMEM;
1446 goto out;
1447 }
1448
1449 acx->ht_protection =
1450 (u8)(ht_operation_mode & IEEE80211_HT_OP_MODE_PROTECTION);
1451 acx->rifs_mode = 0;
1452 acx->gf_protection =
1453 !!(ht_operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
1454 acx->ht_tx_burst_limit = 0;
1455 acx->dual_cts_protection = 0;
1456
1457 ret = wl1271_cmd_configure(wl, ACX_HT_BSS_OPERATION, acx, sizeof(*acx));
1458
1459 if (ret < 0) {
1460 wl1271_warning("acx ht information setting failed: %d", ret);
1461 goto out;
1462 }
1463
1464out:
1465 kfree(acx);
1466 return ret;
1467}
1468
1469/* Configure BA session initiator/receiver parameters setting in the FW. */
1470int wl1271_acx_set_ba_session(struct wl1271 *wl,
1471 enum ieee80211_back_parties direction,
1472 u8 tid_index, u8 policy)
1473{
1474 struct wl1271_acx_ba_session_policy *acx;
1475 int ret;
1476
1477 wl1271_debug(DEBUG_ACX, "acx ba session setting");
1478
1479 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1480 if (!acx) {
1481 ret = -ENOMEM;
1482 goto out;
1483 }
1484
1485 /* ANY role */
1486 acx->role_id = 0xff;
1487 acx->tid = tid_index;
1488 acx->enable = policy;
1489 acx->ba_direction = direction;
1490
1491 switch (direction) {
1492 case WLAN_BACK_INITIATOR:
1493 acx->win_size = wl->conf.ht.tx_ba_win_size;
1494 acx->inactivity_timeout = wl->conf.ht.inactivity_timeout;
1495 break;
1496 case WLAN_BACK_RECIPIENT:
1497 acx->win_size = RX_BA_WIN_SIZE;
1498 acx->inactivity_timeout = 0;
1499 break;
1500 default:
1501 wl1271_error("Incorrect acx command id=%x\n", direction);
1502 ret = -EINVAL;
1503 goto out;
1504 }
1505
1506 ret = wl1271_cmd_configure(wl,
1507 ACX_BA_SESSION_POLICY_CFG,
1508 acx,
1509 sizeof(*acx));
1510 if (ret < 0) {
1511 wl1271_warning("acx ba session setting failed: %d", ret);
1512 goto out;
1513 }
1514
1515out:
1516 kfree(acx);
1517 return ret;
1518}
1519
1520/* setup BA session receiver setting in the FW. */
1521int wl1271_acx_set_ba_receiver_session(struct wl1271 *wl, u8 tid_index, u16 ssn,
1522 bool enable)
1523{
1524 struct wl1271_acx_ba_receiver_setup *acx;
1525 int ret;
1526
1527 wl1271_debug(DEBUG_ACX, "acx ba receiver session setting");
1528
1529 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1530 if (!acx) {
1531 ret = -ENOMEM;
1532 goto out;
1533 }
1534
1535 /* Single link for now */
1536 acx->link_id = 1;
1537 acx->tid = tid_index;
1538 acx->enable = enable;
1539 acx->win_size = 0;
1540 acx->ssn = ssn;
1541
1542 ret = wl1271_cmd_configure(wl, ACX_BA_SESSION_RX_SETUP, acx,
1543 sizeof(*acx));
1544 if (ret < 0) {
1545 wl1271_warning("acx ba receiver session failed: %d", ret);
1546 goto out;
1547 }
1548
1549out:
1550 kfree(acx);
1551 return ret;
1552}
1553
1263int wl1271_acx_tsf_info(struct wl1271 *wl, u64 *mactime) 1554int wl1271_acx_tsf_info(struct wl1271 *wl, u64 *mactime)
1264{ 1555{
1265 struct wl1271_acx_fw_tsf_information *tsf_info; 1556 struct wl1271_acx_fw_tsf_information *tsf_info;
@@ -1285,3 +1576,147 @@ out:
1285 kfree(tsf_info); 1576 kfree(tsf_info);
1286 return ret; 1577 return ret;
1287} 1578}
1579
1580int wl1271_acx_max_tx_retry(struct wl1271 *wl)
1581{
1582 struct wl1271_acx_max_tx_retry *acx = NULL;
1583 int ret;
1584
1585 wl1271_debug(DEBUG_ACX, "acx max tx retry");
1586
1587 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1588 if (!acx)
1589 return -ENOMEM;
1590
1591 acx->max_tx_retry = cpu_to_le16(wl->conf.tx.ap_max_tx_retries);
1592
1593 ret = wl1271_cmd_configure(wl, ACX_MAX_TX_FAILURE, acx, sizeof(*acx));
1594 if (ret < 0) {
1595 wl1271_warning("acx max tx retry failed: %d", ret);
1596 goto out;
1597 }
1598
1599out:
1600 kfree(acx);
1601 return ret;
1602}
1603
1604int wl1271_acx_config_ps(struct wl1271 *wl)
1605{
1606 struct wl1271_acx_config_ps *config_ps;
1607 int ret;
1608
1609 wl1271_debug(DEBUG_ACX, "acx config ps");
1610
1611 config_ps = kzalloc(sizeof(*config_ps), GFP_KERNEL);
1612 if (!config_ps) {
1613 ret = -ENOMEM;
1614 goto out;
1615 }
1616
1617 config_ps->exit_retries = wl->conf.conn.psm_exit_retries;
1618 config_ps->enter_retries = wl->conf.conn.psm_entry_retries;
1619 config_ps->null_data_rate = cpu_to_le32(wl->basic_rate);
1620
1621 ret = wl1271_cmd_configure(wl, ACX_CONFIG_PS, config_ps,
1622 sizeof(*config_ps));
1623
1624 if (ret < 0) {
1625 wl1271_warning("acx config ps failed: %d", ret);
1626 goto out;
1627 }
1628
1629out:
1630 kfree(config_ps);
1631 return ret;
1632}
1633
1634int wl1271_acx_set_inconnection_sta(struct wl1271 *wl, u8 *addr)
1635{
1636 struct wl1271_acx_inconnection_sta *acx = NULL;
1637 int ret;
1638
1639 wl1271_debug(DEBUG_ACX, "acx set inconnaction sta %pM", addr);
1640
1641 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1642 if (!acx)
1643 return -ENOMEM;
1644
1645 memcpy(acx->addr, addr, ETH_ALEN);
1646
1647 ret = wl1271_cmd_configure(wl, ACX_UPDATE_INCONNECTION_STA_LIST,
1648 acx, sizeof(*acx));
1649 if (ret < 0) {
1650 wl1271_warning("acx set inconnaction sta failed: %d", ret);
1651 goto out;
1652 }
1653
1654out:
1655 kfree(acx);
1656 return ret;
1657}
1658
1659int wl1271_acx_set_ap_beacon_filter(struct wl1271 *wl, bool enable)
1660{
1661 struct acx_ap_beacon_filter *acx = NULL;
1662 int ret;
1663
1664 wl1271_debug(DEBUG_ACX, "acx set ap beacon filter: %d", enable);
1665
1666 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1667 if (!acx)
1668 return -ENOMEM;
1669
1670 acx->enable = enable ? 1 : 0;
1671
1672 ret = wl1271_cmd_configure(wl, ACX_AP_BEACON_FILTER_OPT,
1673 acx, sizeof(*acx));
1674 if (ret < 0) {
1675 wl1271_warning("acx set ap beacon filter failed: %d", ret);
1676 goto out;
1677 }
1678
1679out:
1680 kfree(acx);
1681 return ret;
1682}
1683
1684int wl1271_acx_fm_coex(struct wl1271 *wl)
1685{
1686 struct wl1271_acx_fm_coex *acx;
1687 int ret;
1688
1689 wl1271_debug(DEBUG_ACX, "acx fm coex setting");
1690
1691 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1692 if (!acx) {
1693 ret = -ENOMEM;
1694 goto out;
1695 }
1696
1697 acx->enable = wl->conf.fm_coex.enable;
1698 acx->swallow_period = wl->conf.fm_coex.swallow_period;
1699 acx->n_divider_fref_set_1 = wl->conf.fm_coex.n_divider_fref_set_1;
1700 acx->n_divider_fref_set_2 = wl->conf.fm_coex.n_divider_fref_set_2;
1701 acx->m_divider_fref_set_1 =
1702 cpu_to_le16(wl->conf.fm_coex.m_divider_fref_set_1);
1703 acx->m_divider_fref_set_2 =
1704 cpu_to_le16(wl->conf.fm_coex.m_divider_fref_set_2);
1705 acx->coex_pll_stabilization_time =
1706 cpu_to_le32(wl->conf.fm_coex.coex_pll_stabilization_time);
1707 acx->ldo_stabilization_time =
1708 cpu_to_le16(wl->conf.fm_coex.ldo_stabilization_time);
1709 acx->fm_disturbed_band_margin =
1710 wl->conf.fm_coex.fm_disturbed_band_margin;
1711 acx->swallow_clk_diff = wl->conf.fm_coex.swallow_clk_diff;
1712
1713 ret = wl1271_cmd_configure(wl, ACX_FM_COEX_CFG, acx, sizeof(*acx));
1714 if (ret < 0) {
1715 wl1271_warning("acx fm coex setting failed: %d", ret);
1716 goto out;
1717 }
1718
1719out:
1720 kfree(acx);
1721 return ret;
1722}
diff --git a/drivers/net/wireless/wl12xx/wl1271_acx.h b/drivers/net/wireless/wl12xx/acx.h
index 4235bc56f750..9a895e3cc613 100644
--- a/drivers/net/wireless/wl12xx/wl1271_acx.h
+++ b/drivers/net/wireless/wl12xx/acx.h
@@ -22,11 +22,11 @@
22 * 22 *
23 */ 23 */
24 24
25#ifndef __WL1271_ACX_H__ 25#ifndef __ACX_H__
26#define __WL1271_ACX_H__ 26#define __ACX_H__
27 27
28#include "wl1271.h" 28#include "wl12xx.h"
29#include "wl1271_cmd.h" 29#include "cmd.h"
30 30
31/************************************************************************* 31/*************************************************************************
32 32
@@ -47,9 +47,9 @@
47#define WL1271_ACX_INTR_HW_AVAILABLE BIT(5) 47#define WL1271_ACX_INTR_HW_AVAILABLE BIT(5)
48/* The MISC bit is used for aggregation of RX, TxComplete and TX rate update */ 48/* The MISC bit is used for aggregation of RX, TxComplete and TX rate update */
49#define WL1271_ACX_INTR_DATA BIT(6) 49#define WL1271_ACX_INTR_DATA BIT(6)
50/* Trace meassge on MBOX #A */ 50/* Trace message on MBOX #A */
51#define WL1271_ACX_INTR_TRACE_A BIT(7) 51#define WL1271_ACX_INTR_TRACE_A BIT(7)
52/* Trace meassge on MBOX #B */ 52/* Trace message on MBOX #B */
53#define WL1271_ACX_INTR_TRACE_B BIT(8) 53#define WL1271_ACX_INTR_TRACE_B BIT(8)
54 54
55#define WL1271_ACX_INTR_ALL 0xFFFFFFFF 55#define WL1271_ACX_INTR_ALL 0xFFFFFFFF
@@ -61,7 +61,8 @@
61 WL1271_ACX_INTR_HW_AVAILABLE | \ 61 WL1271_ACX_INTR_HW_AVAILABLE | \
62 WL1271_ACX_INTR_DATA) 62 WL1271_ACX_INTR_DATA)
63 63
64#define WL1271_INTR_MASK (WL1271_ACX_INTR_EVENT_A | \ 64#define WL1271_INTR_MASK (WL1271_ACX_INTR_WATCHDOG | \
65 WL1271_ACX_INTR_EVENT_A | \
65 WL1271_ACX_INTR_EVENT_B | \ 66 WL1271_ACX_INTR_EVENT_B | \
66 WL1271_ACX_INTR_HW_AVAILABLE | \ 67 WL1271_ACX_INTR_HW_AVAILABLE | \
67 WL1271_ACX_INTR_DATA) 68 WL1271_ACX_INTR_DATA)
@@ -100,35 +101,6 @@ struct acx_error_counter {
100 __le32 seq_num_miss; 101 __le32 seq_num_miss;
101} __packed; 102} __packed;
102 103
103struct acx_revision {
104 struct acx_header header;
105
106 /*
107 * The WiLink firmware version, an ASCII string x.x.x.x,
108 * that uniquely identifies the current firmware.
109 * The left most digit is incremented each time a
110 * significant change is made to the firmware, such as
111 * code redesign or new platform support.
112 * The second digit is incremented when major enhancements
113 * are added or major fixes are made.
114 * The third digit is incremented for each GA release.
115 * The fourth digit is incremented for each build.
116 * The first two digits identify a firmware release version,
117 * in other words, a unique set of features.
118 * The first three digits identify a GA release.
119 */
120 char fw_version[20];
121
122 /*
123 * This 4 byte field specifies the WiLink hardware version.
124 * bits 0 - 15: Reserved.
125 * bits 16 - 23: Version ID - The WiLink version ID
126 * (1 = first spin, 2 = second spin, and so on).
127 * bits 24 - 31: Chip ID - The WiLink chip ID.
128 */
129 __le32 hw_version;
130} __packed;
131
132enum wl1271_psm_mode { 104enum wl1271_psm_mode {
133 /* Active mode */ 105 /* Active mode */
134 WL1271_PSM_CAM = 0, 106 WL1271_PSM_CAM = 0,
@@ -161,7 +133,6 @@ enum {
161 133
162#define DEFAULT_UCAST_PRIORITY 0 134#define DEFAULT_UCAST_PRIORITY 0
163#define DEFAULT_RX_Q_PRIORITY 0 135#define DEFAULT_RX_Q_PRIORITY 0
164#define DEFAULT_NUM_STATIONS 1
165#define DEFAULT_RXQ_PRIORITY 0 /* low 0 .. 15 high */ 136#define DEFAULT_RXQ_PRIORITY 0 /* low 0 .. 15 high */
166#define DEFAULT_RXQ_TYPE 0x07 /* All frames, Data/Ctrl/Mgmt */ 137#define DEFAULT_RXQ_TYPE 0x07 /* All frames, Data/Ctrl/Mgmt */
167#define TRACE_BUFFER_MAX_SIZE 256 138#define TRACE_BUFFER_MAX_SIZE 256
@@ -332,7 +303,6 @@ struct acx_beacon_filter_option {
332 struct acx_header header; 303 struct acx_header header;
333 304
334 u8 enable; 305 u8 enable;
335
336 /* 306 /*
337 * The number of beacons without the unicast TIM 307 * The number of beacons without the unicast TIM
338 * bit set that the firmware buffers before 308 * bit set that the firmware buffers before
@@ -399,14 +369,23 @@ struct acx_bt_wlan_coex {
399 u8 pad[3]; 369 u8 pad[3];
400} __packed; 370} __packed;
401 371
402struct acx_bt_wlan_coex_param { 372struct acx_sta_bt_wlan_coex_param {
403 struct acx_header header; 373 struct acx_header header;
404 374
405 __le32 params[CONF_SG_PARAMS_MAX]; 375 __le32 params[CONF_SG_STA_PARAMS_MAX];
406 u8 param_idx; 376 u8 param_idx;
407 u8 padding[3]; 377 u8 padding[3];
408} __packed; 378} __packed;
409 379
380struct acx_ap_bt_wlan_coex_param {
381 struct acx_header header;
382
383 __le32 params[CONF_SG_AP_PARAMS_MAX];
384 u8 param_idx;
385 u8 padding[3];
386} __packed;
387
388
410struct acx_dco_itrim_params { 389struct acx_dco_itrim_params {
411 struct acx_header header; 390 struct acx_header header;
412 391
@@ -775,13 +754,23 @@ struct acx_rate_class {
775#define ACX_TX_BASIC_RATE 0 754#define ACX_TX_BASIC_RATE 0
776#define ACX_TX_AP_FULL_RATE 1 755#define ACX_TX_AP_FULL_RATE 1
777#define ACX_TX_RATE_POLICY_CNT 2 756#define ACX_TX_RATE_POLICY_CNT 2
778struct acx_rate_policy { 757struct acx_sta_rate_policy {
779 struct acx_header header; 758 struct acx_header header;
780 759
781 __le32 rate_class_cnt; 760 __le32 rate_class_cnt;
782 struct acx_rate_class rate_class[CONF_TX_MAX_RATE_CLASSES]; 761 struct acx_rate_class rate_class[CONF_TX_MAX_RATE_CLASSES];
783} __packed; 762} __packed;
784 763
764
765#define ACX_TX_AP_MODE_MGMT_RATE 4
766#define ACX_TX_AP_MODE_BCST_RATE 5
767struct acx_ap_rate_policy {
768 struct acx_header header;
769
770 __le32 rate_policy_idx;
771 struct acx_rate_class rate_policy;
772} __packed;
773
785struct acx_ac_cfg { 774struct acx_ac_cfg {
786 struct acx_header header; 775 struct acx_header header;
787 u8 ac; 776 u8 ac;
@@ -815,12 +804,19 @@ struct acx_tx_config_options {
815 __le16 tx_compl_threshold; /* number of packets */ 804 __le16 tx_compl_threshold; /* number of packets */
816} __packed; 805} __packed;
817 806
818#define ACX_RX_MEM_BLOCKS 70
819#define ACX_TX_MIN_MEM_BLOCKS 40
820#define ACX_TX_DESCRIPTORS 32 807#define ACX_TX_DESCRIPTORS 32
821#define ACX_NUM_SSID_PROFILES 1
822 808
823struct wl1271_acx_config_memory { 809struct wl1271_acx_ap_config_memory {
810 struct acx_header header;
811
812 u8 rx_mem_block_num;
813 u8 tx_min_mem_block_num;
814 u8 num_stations;
815 u8 num_ssid_profiles;
816 __le32 total_tx_descriptors;
817} __packed;
818
819struct wl1271_acx_sta_config_memory {
824 struct acx_header header; 820 struct acx_header header;
825 821
826 u8 rx_mem_block_num; 822 u8 rx_mem_block_num;
@@ -828,6 +824,10 @@ struct wl1271_acx_config_memory {
828 u8 num_stations; 824 u8 num_stations;
829 u8 num_ssid_profiles; 825 u8 num_ssid_profiles;
830 __le32 total_tx_descriptors; 826 __le32 total_tx_descriptors;
827 u8 dyn_mem_enable;
828 u8 tx_free_req;
829 u8 rx_free_req;
830 u8 tx_min;
831} __packed; 831} __packed;
832 832
833struct wl1271_acx_mem_map { 833struct wl1271_acx_mem_map {
@@ -896,10 +896,15 @@ struct wl1271_acx_bet_enable {
896#define ACX_IPV4_VERSION 4 896#define ACX_IPV4_VERSION 4
897#define ACX_IPV6_VERSION 6 897#define ACX_IPV6_VERSION 6
898#define ACX_IPV4_ADDR_SIZE 4 898#define ACX_IPV4_ADDR_SIZE 4
899
900/* bitmap of enabled arp_filter features */
901#define ACX_ARP_FILTER_ARP_FILTERING BIT(0)
902#define ACX_ARP_FILTER_AUTO_ARP BIT(1)
903
899struct wl1271_acx_arp_filter { 904struct wl1271_acx_arp_filter {
900 struct acx_header header; 905 struct acx_header header;
901 u8 version; /* ACX_IPV4_VERSION, ACX_IPV6_VERSION */ 906 u8 version; /* ACX_IPV4_VERSION, ACX_IPV6_VERSION */
902 u8 enable; /* 1 to enable ARP filtering, 0 to disable */ 907 u8 enable; /* bitmap of enabled ARP filtering features */
903 u8 padding[2]; 908 u8 padding[2];
904 u8 address[16]; /* The configured device IP address - all ARP 909 u8 address[16]; /* The configured device IP address - all ARP
905 requests directed to this IP address will pass 910 requests directed to this IP address will pass
@@ -942,6 +947,16 @@ struct wl1271_acx_keep_alive_config {
942 u8 padding; 947 u8 padding;
943} __packed; 948} __packed;
944 949
950#define HOST_IF_CFG_RX_FIFO_ENABLE BIT(0)
951#define HOST_IF_CFG_TX_EXTRA_BLKS_SWAP BIT(1)
952#define HOST_IF_CFG_TX_PAD_TO_SDIO_BLK BIT(3)
953
954struct wl1271_acx_host_config_bitmap {
955 struct acx_header header;
956
957 __le32 host_cfg_bitmap;
958} __packed;
959
945enum { 960enum {
946 WL1271_ACX_TRIG_TYPE_LEVEL = 0, 961 WL1271_ACX_TRIG_TYPE_LEVEL = 0,
947 WL1271_ACX_TRIG_TYPE_EDGE, 962 WL1271_ACX_TRIG_TYPE_EDGE,
@@ -993,6 +1008,140 @@ struct wl1271_acx_rssi_snr_avg_weights {
993 u8 snr_data; 1008 u8 snr_data;
994}; 1009};
995 1010
1011/*
1012 * ACX_PEER_HT_CAP
1013 * Configure HT capabilities - declare the capabilities of the peer
1014 * we are connected to.
1015 */
1016struct wl1271_acx_ht_capabilities {
1017 struct acx_header header;
1018
1019 /*
1020 * bit 0 - Allow HT Operation
1021 * bit 1 - Allow Greenfield format in TX
1022 * bit 2 - Allow Short GI in TX
1023 * bit 3 - Allow L-SIG TXOP Protection in TX
1024 * bit 4 - Allow HT Control fields in TX.
1025 * Note, driver will still leave space for HT control in packets
1026 * regardless of the value of this field. FW will be responsible
1027 * to drop the HT field from any frame when this Bit set to 0.
1028 * bit 5 - Allow RD initiation in TXOP. FW is allowed to initate RD.
1029 * Exact policy setting for this feature is TBD.
1030 * Note, this bit can only be set to 1 if bit 3 is set to 1.
1031 */
1032 __le32 ht_capabilites;
1033
1034 /*
1035 * Indicates to which peer these capabilities apply.
1036 * For infrastructure use ff:ff:ff:ff:ff:ff that indicates relevance
1037 * for all peers.
1038 * Only valid for IBSS/DLS operation.
1039 */
1040 u8 mac_address[ETH_ALEN];
1041
1042 /*
1043 * This the maximum A-MPDU length supported by the AP. The FW may not
1044 * exceed this length when sending A-MPDUs
1045 */
1046 u8 ampdu_max_length;
1047
1048 /* This is the minimal spacing required when sending A-MPDUs to the AP*/
1049 u8 ampdu_min_spacing;
1050} __packed;
1051
1052/* HT Capabilites Fw Bit Mask Mapping */
1053#define WL1271_ACX_FW_CAP_HT_OPERATION BIT(0)
1054#define WL1271_ACX_FW_CAP_GREENFIELD_FRAME_FORMAT BIT(1)
1055#define WL1271_ACX_FW_CAP_SHORT_GI_FOR_20MHZ_PACKETS BIT(2)
1056#define WL1271_ACX_FW_CAP_LSIG_TXOP_PROTECTION BIT(3)
1057#define WL1271_ACX_FW_CAP_HT_CONTROL_FIELDS BIT(4)
1058#define WL1271_ACX_FW_CAP_RD_INITIATION BIT(5)
1059
1060
1061/*
1062 * ACX_HT_BSS_OPERATION
1063 * Configure HT capabilities - AP rules for behavior in the BSS.
1064 */
1065struct wl1271_acx_ht_information {
1066 struct acx_header header;
1067
1068 /* Values: 0 - RIFS not allowed, 1 - RIFS allowed */
1069 u8 rifs_mode;
1070
1071 /* Values: 0 - 3 like in spec */
1072 u8 ht_protection;
1073
1074 /* Values: 0 - GF protection not required, 1 - GF protection required */
1075 u8 gf_protection;
1076
1077 /*Values: 0 - TX Burst limit not required, 1 - TX Burst Limit required*/
1078 u8 ht_tx_burst_limit;
1079
1080 /*
1081 * Values: 0 - Dual CTS protection not required,
1082 * 1 - Dual CTS Protection required
1083 * Note: When this value is set to 1 FW will protect all TXOP with RTS
1084 * frame and will not use CTS-to-self regardless of the value of the
1085 * ACX_CTS_PROTECTION information element
1086 */
1087 u8 dual_cts_protection;
1088
1089 u8 padding[3];
1090} __packed;
1091
1092#define RX_BA_WIN_SIZE 8
1093
1094struct wl1271_acx_ba_session_policy {
1095 struct acx_header header;
1096 /*
1097 * Specifies role Id, Range 0-7, 0xFF means ANY role.
1098 * Future use. For now this field is irrelevant
1099 */
1100 u8 role_id;
1101 /*
1102 * Specifies Link Id, Range 0-31, 0xFF means ANY Link Id.
1103 * Not applicable if Role Id is set to ANY.
1104 */
1105 u8 link_id;
1106
1107 u8 tid;
1108
1109 u8 enable;
1110
1111 /* Windows size in number of packets */
1112 u16 win_size;
1113
1114 /*
1115 * As initiator inactivity timeout in time units(TU) of 1024us.
1116 * As receiver reserved
1117 */
1118 u16 inactivity_timeout;
1119
1120 /* Initiator = 1/Receiver = 0 */
1121 u8 ba_direction;
1122
1123 u8 padding[3];
1124} __packed;
1125
1126struct wl1271_acx_ba_receiver_setup {
1127 struct acx_header header;
1128
1129 /* Specifies Link Id, Range 0-31, 0xFF means ANY Link Id */
1130 u8 link_id;
1131
1132 u8 tid;
1133
1134 u8 enable;
1135
1136 u8 padding[1];
1137
1138 /* Windows size in number of packets */
1139 u16 win_size;
1140
1141 /* BA session starting sequence number. RANGE 0-FFF */
1142 u16 ssn;
1143} __packed;
1144
996struct wl1271_acx_fw_tsf_information { 1145struct wl1271_acx_fw_tsf_information {
997 struct acx_header header; 1146 struct acx_header header;
998 1147
@@ -1004,6 +1153,99 @@ struct wl1271_acx_fw_tsf_information {
1004 u8 padding[3]; 1153 u8 padding[3];
1005} __packed; 1154} __packed;
1006 1155
1156struct wl1271_acx_max_tx_retry {
1157 struct acx_header header;
1158
1159 /*
1160 * the number of frames transmission failures before
1161 * issuing the aging event.
1162 */
1163 __le16 max_tx_retry;
1164 u8 padding_1[2];
1165} __packed;
1166
1167struct wl1271_acx_config_ps {
1168 struct acx_header header;
1169
1170 u8 exit_retries;
1171 u8 enter_retries;
1172 u8 padding[2];
1173 __le32 null_data_rate;
1174} __packed;
1175
1176struct wl1271_acx_inconnection_sta {
1177 struct acx_header header;
1178
1179 u8 addr[ETH_ALEN];
1180 u8 padding1[2];
1181} __packed;
1182
1183struct acx_ap_beacon_filter {
1184 struct acx_header header;
1185
1186 u8 enable;
1187 u8 pad[3];
1188} __packed;
1189
1190/*
1191 * ACX_FM_COEX_CFG
1192 * set the FM co-existence parameters.
1193 */
1194struct wl1271_acx_fm_coex {
1195 struct acx_header header;
1196 /* enable(1) / disable(0) the FM Coex feature */
1197 u8 enable;
1198 /*
1199 * Swallow period used in COEX PLL swallowing mechanism.
1200 * 0xFF = use FW default
1201 */
1202 u8 swallow_period;
1203 /*
1204 * The N divider used in COEX PLL swallowing mechanism for Fref of
1205 * 38.4/19.2 Mhz. 0xFF = use FW default
1206 */
1207 u8 n_divider_fref_set_1;
1208 /*
1209 * The N divider used in COEX PLL swallowing mechanism for Fref of
1210 * 26/52 Mhz. 0xFF = use FW default
1211 */
1212 u8 n_divider_fref_set_2;
1213 /*
1214 * The M divider used in COEX PLL swallowing mechanism for Fref of
1215 * 38.4/19.2 Mhz. 0xFFFF = use FW default
1216 */
1217 __le16 m_divider_fref_set_1;
1218 /*
1219 * The M divider used in COEX PLL swallowing mechanism for Fref of
1220 * 26/52 Mhz. 0xFFFF = use FW default
1221 */
1222 __le16 m_divider_fref_set_2;
1223 /*
1224 * The time duration in uSec required for COEX PLL to stabilize.
1225 * 0xFFFFFFFF = use FW default
1226 */
1227 __le32 coex_pll_stabilization_time;
1228 /*
1229 * The time duration in uSec required for LDO to stabilize.
1230 * 0xFFFFFFFF = use FW default
1231 */
1232 __le16 ldo_stabilization_time;
1233 /*
1234 * The disturbed frequency band margin around the disturbed frequency
1235 * center (single sided).
1236 * For example, if 2 is configured, the following channels will be
1237 * considered disturbed channel:
1238 * 80 +- 0.1 MHz, 91 +- 0.1 MHz, 98 +- 0.1 MHz, 102 +- 0.1 MH
1239 * 0xFF = use FW default
1240 */
1241 u8 fm_disturbed_band_margin;
1242 /*
1243 * The swallow clock difference of the swallowing mechanism.
1244 * 0xFF = use FW default
1245 */
1246 u8 swallow_clk_diff;
1247} __packed;
1248
1007enum { 1249enum {
1008 ACX_WAKE_UP_CONDITIONS = 0x0002, 1250 ACX_WAKE_UP_CONDITIONS = 0x0002,
1009 ACX_MEM_CFG = 0x0003, 1251 ACX_MEM_CFG = 0x0003,
@@ -1022,6 +1264,7 @@ enum {
1022 ACX_TID_CFG = 0x001A, 1264 ACX_TID_CFG = 0x001A,
1023 ACX_PS_RX_STREAMING = 0x001B, 1265 ACX_PS_RX_STREAMING = 0x001B,
1024 ACX_BEACON_FILTER_OPT = 0x001F, 1266 ACX_BEACON_FILTER_OPT = 0x001F,
1267 ACX_AP_BEACON_FILTER_OPT = 0x0020,
1025 ACX_NOISE_HIST = 0x0021, 1268 ACX_NOISE_HIST = 0x0021,
1026 ACX_HDK_VERSION = 0x0022, /* ??? */ 1269 ACX_HDK_VERSION = 0x0022, /* ??? */
1027 ACX_PD_THRESHOLD = 0x0023, 1270 ACX_PD_THRESHOLD = 0x0023,
@@ -1033,6 +1276,7 @@ enum {
1033 ACX_BCN_DTIM_OPTIONS = 0x0031, 1276 ACX_BCN_DTIM_OPTIONS = 0x0031,
1034 ACX_SG_ENABLE = 0x0032, 1277 ACX_SG_ENABLE = 0x0032,
1035 ACX_SG_CFG = 0x0033, 1278 ACX_SG_CFG = 0x0033,
1279 ACX_FM_COEX_CFG = 0x0034,
1036 ACX_BEACON_FILTER_TABLE = 0x0038, 1280 ACX_BEACON_FILTER_TABLE = 0x0038,
1037 ACX_ARP_IP_FILTER = 0x0039, 1281 ACX_ARP_IP_FILTER = 0x0039,
1038 ACX_ROAMING_STATISTICS_TBL = 0x003B, 1282 ACX_ROAMING_STATISTICS_TBL = 0x003B,
@@ -1055,29 +1299,29 @@ enum {
1055 ACX_RSSI_SNR_WEIGHTS = 0x0052, 1299 ACX_RSSI_SNR_WEIGHTS = 0x0052,
1056 ACX_KEEP_ALIVE_MODE = 0x0053, 1300 ACX_KEEP_ALIVE_MODE = 0x0053,
1057 ACX_SET_KEEP_ALIVE_CONFIG = 0x0054, 1301 ACX_SET_KEEP_ALIVE_CONFIG = 0x0054,
1058 ACX_BA_SESSION_RESPONDER_POLICY = 0x0055, 1302 ACX_BA_SESSION_POLICY_CFG = 0x0055,
1059 ACX_BA_SESSION_INITIATOR_POLICY = 0x0056, 1303 ACX_BA_SESSION_RX_SETUP = 0x0056,
1060 ACX_PEER_HT_CAP = 0x0057, 1304 ACX_PEER_HT_CAP = 0x0057,
1061 ACX_HT_BSS_OPERATION = 0x0058, 1305 ACX_HT_BSS_OPERATION = 0x0058,
1062 ACX_COEX_ACTIVITY = 0x0059, 1306 ACX_COEX_ACTIVITY = 0x0059,
1063 ACX_SET_SMART_REFLEX_DEBUG = 0x005A,
1064 ACX_SET_DCO_ITRIM_PARAMS = 0x0061, 1307 ACX_SET_DCO_ITRIM_PARAMS = 0x0061,
1308 ACX_GEN_FW_CMD = 0x0070,
1309 ACX_HOST_IF_CFG_BITMAP = 0x0071,
1310 ACX_MAX_TX_FAILURE = 0x0072,
1311 ACX_UPDATE_INCONNECTION_STA_LIST = 0x0073,
1065 DOT11_RX_MSDU_LIFE_TIME = 0x1004, 1312 DOT11_RX_MSDU_LIFE_TIME = 0x1004,
1066 DOT11_CUR_TX_PWR = 0x100D, 1313 DOT11_CUR_TX_PWR = 0x100D,
1067 DOT11_RX_DOT11_MODE = 0x1012, 1314 DOT11_RX_DOT11_MODE = 0x1012,
1068 DOT11_RTS_THRESHOLD = 0x1013, 1315 DOT11_RTS_THRESHOLD = 0x1013,
1069 DOT11_GROUP_ADDRESS_TBL = 0x1014, 1316 DOT11_GROUP_ADDRESS_TBL = 0x1014,
1070 ACX_PM_CONFIG = 0x1016, 1317 ACX_PM_CONFIG = 0x1016,
1071 1318 ACX_CONFIG_PS = 0x1017,
1072 MAX_DOT11_IE = DOT11_GROUP_ADDRESS_TBL, 1319 ACX_CONFIG_HANGOVER = 0x1018,
1073
1074 MAX_IE = 0xFFFF
1075}; 1320};
1076 1321
1077 1322
1078int wl1271_acx_wake_up_conditions(struct wl1271 *wl); 1323int wl1271_acx_wake_up_conditions(struct wl1271 *wl);
1079int wl1271_acx_sleep_auth(struct wl1271 *wl, u8 sleep_auth); 1324int wl1271_acx_sleep_auth(struct wl1271 *wl, u8 sleep_auth);
1080int wl1271_acx_fw_version(struct wl1271 *wl, char *buf, size_t len);
1081int wl1271_acx_tx_power(struct wl1271 *wl, int power); 1325int wl1271_acx_tx_power(struct wl1271 *wl, int power);
1082int wl1271_acx_feature_cfg(struct wl1271 *wl); 1326int wl1271_acx_feature_cfg(struct wl1271 *wl);
1083int wl1271_acx_mem_map(struct wl1271 *wl, 1327int wl1271_acx_mem_map(struct wl1271 *wl,
@@ -1089,13 +1333,14 @@ int wl1271_acx_slot(struct wl1271 *wl, enum acx_slot_type slot_time);
1089int wl1271_acx_group_address_tbl(struct wl1271 *wl, bool enable, 1333int wl1271_acx_group_address_tbl(struct wl1271 *wl, bool enable,
1090 void *mc_list, u32 mc_list_len); 1334 void *mc_list, u32 mc_list_len);
1091int wl1271_acx_service_period_timeout(struct wl1271 *wl); 1335int wl1271_acx_service_period_timeout(struct wl1271 *wl);
1092int wl1271_acx_rts_threshold(struct wl1271 *wl, u16 rts_threshold); 1336int wl1271_acx_rts_threshold(struct wl1271 *wl, u32 rts_threshold);
1093int wl1271_acx_dco_itrim_params(struct wl1271 *wl); 1337int wl1271_acx_dco_itrim_params(struct wl1271 *wl);
1094int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, bool enable_filter); 1338int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, bool enable_filter);
1095int wl1271_acx_beacon_filter_table(struct wl1271 *wl); 1339int wl1271_acx_beacon_filter_table(struct wl1271 *wl);
1096int wl1271_acx_conn_monit_params(struct wl1271 *wl, bool enable); 1340int wl1271_acx_conn_monit_params(struct wl1271 *wl, bool enable);
1097int wl1271_acx_sg_enable(struct wl1271 *wl, bool enable); 1341int wl1271_acx_sg_enable(struct wl1271 *wl, bool enable);
1098int wl1271_acx_sg_cfg(struct wl1271 *wl); 1342int wl1271_acx_sta_sg_cfg(struct wl1271 *wl);
1343int wl1271_acx_ap_sg_cfg(struct wl1271 *wl);
1099int wl1271_acx_cca_threshold(struct wl1271 *wl); 1344int wl1271_acx_cca_threshold(struct wl1271 *wl);
1100int wl1271_acx_bcn_dtim_options(struct wl1271 *wl); 1345int wl1271_acx_bcn_dtim_options(struct wl1271 *wl);
1101int wl1271_acx_aid(struct wl1271 *wl, u16 aid); 1346int wl1271_acx_aid(struct wl1271 *wl, u16 aid);
@@ -1104,26 +1349,45 @@ int wl1271_acx_set_preamble(struct wl1271 *wl, enum acx_preamble_type preamble);
1104int wl1271_acx_cts_protect(struct wl1271 *wl, 1349int wl1271_acx_cts_protect(struct wl1271 *wl,
1105 enum acx_ctsprotect_type ctsprotect); 1350 enum acx_ctsprotect_type ctsprotect);
1106int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats); 1351int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats);
1107int wl1271_acx_rate_policies(struct wl1271 *wl); 1352int wl1271_acx_sta_rate_policies(struct wl1271 *wl);
1353int wl1271_acx_ap_rate_policy(struct wl1271 *wl, struct conf_tx_rate_class *c,
1354 u8 idx);
1108int wl1271_acx_ac_cfg(struct wl1271 *wl, u8 ac, u8 cw_min, u16 cw_max, 1355int wl1271_acx_ac_cfg(struct wl1271 *wl, u8 ac, u8 cw_min, u16 cw_max,
1109 u8 aifsn, u16 txop); 1356 u8 aifsn, u16 txop);
1110int wl1271_acx_tid_cfg(struct wl1271 *wl, u8 queue_id, u8 channel_type, 1357int wl1271_acx_tid_cfg(struct wl1271 *wl, u8 queue_id, u8 channel_type,
1111 u8 tsid, u8 ps_scheme, u8 ack_policy, 1358 u8 tsid, u8 ps_scheme, u8 ack_policy,
1112 u32 apsd_conf0, u32 apsd_conf1); 1359 u32 apsd_conf0, u32 apsd_conf1);
1113int wl1271_acx_frag_threshold(struct wl1271 *wl); 1360int wl1271_acx_frag_threshold(struct wl1271 *wl, u32 frag_threshold);
1114int wl1271_acx_tx_config_options(struct wl1271 *wl); 1361int wl1271_acx_tx_config_options(struct wl1271 *wl);
1115int wl1271_acx_mem_cfg(struct wl1271 *wl); 1362int wl1271_acx_ap_mem_cfg(struct wl1271 *wl);
1363int wl1271_acx_sta_mem_cfg(struct wl1271 *wl);
1116int wl1271_acx_init_mem_config(struct wl1271 *wl); 1364int wl1271_acx_init_mem_config(struct wl1271 *wl);
1365int wl1271_acx_host_if_cfg_bitmap(struct wl1271 *wl, u32 host_cfg_bitmap);
1117int wl1271_acx_init_rx_interrupt(struct wl1271 *wl); 1366int wl1271_acx_init_rx_interrupt(struct wl1271 *wl);
1118int wl1271_acx_smart_reflex(struct wl1271 *wl); 1367int wl1271_acx_smart_reflex(struct wl1271 *wl);
1119int wl1271_acx_bet_enable(struct wl1271 *wl, bool enable); 1368int wl1271_acx_bet_enable(struct wl1271 *wl, bool enable);
1120int wl1271_acx_arp_ip_filter(struct wl1271 *wl, bool enable, __be32 address); 1369int wl1271_acx_arp_ip_filter(struct wl1271 *wl, u8 enable, __be32 address);
1121int wl1271_acx_pm_config(struct wl1271 *wl); 1370int wl1271_acx_pm_config(struct wl1271 *wl);
1122int wl1271_acx_keep_alive_mode(struct wl1271 *wl, bool enable); 1371int wl1271_acx_keep_alive_mode(struct wl1271 *wl, bool enable);
1123int wl1271_acx_keep_alive_config(struct wl1271 *wl, u8 index, u8 tpl_valid); 1372int wl1271_acx_keep_alive_config(struct wl1271 *wl, u8 index, u8 tpl_valid);
1124int wl1271_acx_rssi_snr_trigger(struct wl1271 *wl, bool enable, 1373int wl1271_acx_rssi_snr_trigger(struct wl1271 *wl, bool enable,
1125 s16 thold, u8 hyst); 1374 s16 thold, u8 hyst);
1126int wl1271_acx_rssi_snr_avg_weights(struct wl1271 *wl); 1375int wl1271_acx_rssi_snr_avg_weights(struct wl1271 *wl);
1376int wl1271_acx_set_ht_capabilities(struct wl1271 *wl,
1377 struct ieee80211_sta_ht_cap *ht_cap,
1378 bool allow_ht_operation);
1379int wl1271_acx_set_ht_information(struct wl1271 *wl,
1380 u16 ht_operation_mode);
1381int wl1271_acx_set_ba_session(struct wl1271 *wl,
1382 enum ieee80211_back_parties direction,
1383 u8 tid_index, u8 policy);
1384int wl1271_acx_set_ba_receiver_session(struct wl1271 *wl, u8 tid_index, u16 ssn,
1385 bool enable);
1127int wl1271_acx_tsf_info(struct wl1271 *wl, u64 *mactime); 1386int wl1271_acx_tsf_info(struct wl1271 *wl, u64 *mactime);
1387int wl1271_acx_max_tx_retry(struct wl1271 *wl);
1388int wl1271_acx_config_ps(struct wl1271 *wl);
1389int wl1271_acx_set_inconnection_sta(struct wl1271 *wl, u8 *addr);
1390int wl1271_acx_set_ap_beacon_filter(struct wl1271 *wl, bool enable);
1391int wl1271_acx_fm_coex(struct wl1271 *wl);
1128 1392
1129#endif /* __WL1271_ACX_H__ */ 1393#endif /* __WL1271_ACX_H__ */
diff --git a/drivers/net/wireless/wl12xx/wl1271_boot.c b/drivers/net/wireless/wl12xx/boot.c
index f36430b0336d..b07f8b7e5f11 100644
--- a/drivers/net/wireless/wl12xx/wl1271_boot.c
+++ b/drivers/net/wireless/wl12xx/boot.c
@@ -21,14 +21,15 @@
21 * 21 *
22 */ 22 */
23 23
24#include <linux/gpio.h>
25#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/wl12xx.h>
26 26
27#include "wl1271_acx.h" 27#include "acx.h"
28#include "wl1271_reg.h" 28#include "reg.h"
29#include "wl1271_boot.h" 29#include "boot.h"
30#include "wl1271_io.h" 30#include "io.h"
31#include "wl1271_event.h" 31#include "event.h"
32#include "rx.h"
32 33
33static struct wl1271_partition_set part_table[PART_TABLE_LEN] = { 34static struct wl1271_partition_set part_table[PART_TABLE_LEN] = {
34 [PART_DOWN] = { 35 [PART_DOWN] = {
@@ -101,6 +102,22 @@ static void wl1271_boot_set_ecpu_ctrl(struct wl1271 *wl, u32 flag)
101 wl1271_write32(wl, ACX_REG_ECPU_CONTROL, cpu_ctrl); 102 wl1271_write32(wl, ACX_REG_ECPU_CONTROL, cpu_ctrl);
102} 103}
103 104
105static void wl1271_parse_fw_ver(struct wl1271 *wl)
106{
107 int ret;
108
109 ret = sscanf(wl->chip.fw_ver_str + 4, "%u.%u.%u.%u.%u",
110 &wl->chip.fw_ver[0], &wl->chip.fw_ver[1],
111 &wl->chip.fw_ver[2], &wl->chip.fw_ver[3],
112 &wl->chip.fw_ver[4]);
113
114 if (ret != 5) {
115 wl1271_warning("fw version incorrect value");
116 memset(wl->chip.fw_ver, 0, sizeof(wl->chip.fw_ver));
117 return;
118 }
119}
120
104static void wl1271_boot_fw_version(struct wl1271 *wl) 121static void wl1271_boot_fw_version(struct wl1271 *wl)
105{ 122{
106 struct wl1271_static_data static_data; 123 struct wl1271_static_data static_data;
@@ -108,11 +125,13 @@ static void wl1271_boot_fw_version(struct wl1271 *wl)
108 wl1271_read(wl, wl->cmd_box_addr, &static_data, sizeof(static_data), 125 wl1271_read(wl, wl->cmd_box_addr, &static_data, sizeof(static_data),
109 false); 126 false);
110 127
111 strncpy(wl->chip.fw_ver, static_data.fw_version, 128 strncpy(wl->chip.fw_ver_str, static_data.fw_version,
112 sizeof(wl->chip.fw_ver)); 129 sizeof(wl->chip.fw_ver_str));
113 130
114 /* make sure the string is NULL-terminated */ 131 /* make sure the string is NULL-terminated */
115 wl->chip.fw_ver[sizeof(wl->chip.fw_ver) - 1] = '\0'; 132 wl->chip.fw_ver_str[sizeof(wl->chip.fw_ver_str) - 1] = '\0';
133
134 wl1271_parse_fw_ver(wl);
116} 135}
117 136
118static int wl1271_boot_upload_firmware_chunk(struct wl1271 *wl, void *buf, 137static int wl1271_boot_upload_firmware_chunk(struct wl1271 *wl, void *buf,
@@ -225,9 +244,57 @@ static int wl1271_boot_upload_nvs(struct wl1271 *wl)
225 if (wl->nvs == NULL) 244 if (wl->nvs == NULL)
226 return -ENODEV; 245 return -ENODEV;
227 246
228 /* only the first part of the NVS needs to be uploaded */ 247 if (wl->chip.id == CHIP_ID_1283_PG20) {
229 nvs_len = sizeof(wl->nvs->nvs); 248 struct wl128x_nvs_file *nvs = (struct wl128x_nvs_file *)wl->nvs;
230 nvs_ptr = (u8 *)wl->nvs->nvs; 249
250 if (wl->nvs_len == sizeof(struct wl128x_nvs_file)) {
251 if (nvs->general_params.dual_mode_select)
252 wl->enable_11a = true;
253 } else {
254 wl1271_error("nvs size is not as expected: %zu != %zu",
255 wl->nvs_len,
256 sizeof(struct wl128x_nvs_file));
257 kfree(wl->nvs);
258 wl->nvs = NULL;
259 wl->nvs_len = 0;
260 return -EILSEQ;
261 }
262
263 /* only the first part of the NVS needs to be uploaded */
264 nvs_len = sizeof(nvs->nvs);
265 nvs_ptr = (u8 *)nvs->nvs;
266
267 } else {
268 struct wl1271_nvs_file *nvs =
269 (struct wl1271_nvs_file *)wl->nvs;
270 /*
271 * FIXME: the LEGACY NVS image support (NVS's missing the 5GHz
272 * band configurations) can be removed when those NVS files stop
273 * floating around.
274 */
275 if (wl->nvs_len == sizeof(struct wl1271_nvs_file) ||
276 wl->nvs_len == WL1271_INI_LEGACY_NVS_FILE_SIZE) {
277 /* for now 11a is unsupported in AP mode */
278 if (wl->bss_type != BSS_TYPE_AP_BSS &&
279 nvs->general_params.dual_mode_select)
280 wl->enable_11a = true;
281 }
282
283 if (wl->nvs_len != sizeof(struct wl1271_nvs_file) &&
284 (wl->nvs_len != WL1271_INI_LEGACY_NVS_FILE_SIZE ||
285 wl->enable_11a)) {
286 wl1271_error("nvs size is not as expected: %zu != %zu",
287 wl->nvs_len, sizeof(struct wl1271_nvs_file));
288 kfree(wl->nvs);
289 wl->nvs = NULL;
290 wl->nvs_len = 0;
291 return -EILSEQ;
292 }
293
294 /* only the first part of the NVS needs to be uploaded */
295 nvs_len = sizeof(nvs->nvs);
296 nvs_ptr = (u8 *) nvs->nvs;
297 }
231 298
232 /* update current MAC address to NVS */ 299 /* update current MAC address to NVS */
233 nvs_ptr[11] = wl->mac_addr[0]; 300 nvs_ptr[11] = wl->mac_addr[0];
@@ -251,8 +318,10 @@ static int wl1271_boot_upload_nvs(struct wl1271 *wl)
251 burst_len = nvs_ptr[0]; 318 burst_len = nvs_ptr[0];
252 dest_addr = (nvs_ptr[1] & 0xfe) | ((u32)(nvs_ptr[2] << 8)); 319 dest_addr = (nvs_ptr[1] & 0xfe) | ((u32)(nvs_ptr[2] << 8));
253 320
254 /* FIXME: Due to our new wl1271_translate_reg_addr function, 321 /*
255 we need to add the REGISTER_BASE to the destination */ 322 * Due to our new wl1271_translate_reg_addr function,
323 * we need to add the REGISTER_BASE to the destination
324 */
256 dest_addr += REGISTERS_BASE; 325 dest_addr += REGISTERS_BASE;
257 326
258 /* We move our pointer to the data */ 327 /* We move our pointer to the data */
@@ -274,31 +343,24 @@ static int wl1271_boot_upload_nvs(struct wl1271 *wl)
274 343
275 /* 344 /*
276 * We've reached the first zero length, the first NVS table 345 * We've reached the first zero length, the first NVS table
277 * is 7 bytes further. 346 * is located at an aligned offset which is at least 7 bytes further.
347 * NOTE: The wl->nvs->nvs element must be first, in order to
348 * simplify the casting, we assume it is at the beginning of
349 * the wl->nvs structure.
278 */ 350 */
279 nvs_ptr += 7; 351 nvs_ptr = (u8 *)wl->nvs +
280 nvs_len -= nvs_ptr - (u8 *)wl->nvs->nvs; 352 ALIGN(nvs_ptr - (u8 *)wl->nvs + 7, 4);
281 nvs_len = ALIGN(nvs_len, 4); 353 nvs_len -= nvs_ptr - (u8 *)wl->nvs;
282 354
283 /* FIXME: The driver sets the partition here, but this is not needed,
284 since it sets to the same one as currently in use */
285 /* Now we must set the partition correctly */ 355 /* Now we must set the partition correctly */
286 wl1271_set_partition(wl, &part_table[PART_WORK]); 356 wl1271_set_partition(wl, &part_table[PART_WORK]);
287 357
288 /* Copy the NVS tables to a new block to ensure alignment */ 358 /* Copy the NVS tables to a new block to ensure alignment */
289 /* FIXME: We jump 3 more bytes before uploading the NVS. It seems 359 nvs_aligned = kmemdup(nvs_ptr, nvs_len, GFP_KERNEL);
290 that our NVS files have three extra zeros here. I'm not sure whether 360 if (!nvs_aligned)
291 the problem is in our NVS generation or we should really jumpt these 361 return -ENOMEM;
292 3 bytes here */
293 nvs_ptr += 3;
294
295 nvs_aligned = kmemdup(nvs_ptr, nvs_len, GFP_KERNEL); if
296 (!nvs_aligned) return -ENOMEM;
297 362
298 /* And finally we upload the NVS tables */ 363 /* And finally we upload the NVS tables */
299 /* FIXME: In wl1271, we upload everything at once.
300 No endianness handling needed here?! The ref driver doesn't do
301 anything about it at this point */
302 wl1271_write(wl, CMD_MBOX_ADDRESS, nvs_aligned, nvs_len, false); 364 wl1271_write(wl, CMD_MBOX_ADDRESS, nvs_aligned, nvs_len, false);
303 365
304 kfree(nvs_aligned); 366 kfree(nvs_aligned);
@@ -416,7 +478,14 @@ static int wl1271_boot_run_firmware(struct wl1271 *wl)
416 DISCONNECT_EVENT_COMPLETE_ID | 478 DISCONNECT_EVENT_COMPLETE_ID |
417 RSSI_SNR_TRIGGER_0_EVENT_ID | 479 RSSI_SNR_TRIGGER_0_EVENT_ID |
418 PSPOLL_DELIVERY_FAILURE_EVENT_ID | 480 PSPOLL_DELIVERY_FAILURE_EVENT_ID |
419 SOFT_GEMINI_SENSE_EVENT_ID; 481 SOFT_GEMINI_SENSE_EVENT_ID |
482 PERIODIC_SCAN_REPORT_EVENT_ID |
483 PERIODIC_SCAN_COMPLETE_EVENT_ID;
484
485 if (wl->bss_type == BSS_TYPE_AP_BSS)
486 wl->event_mask |= STA_REMOVE_COMPLETE_EVENT_ID;
487 else
488 wl->event_mask |= DUMMY_PACKET_EVENT_ID;
420 489
421 ret = wl1271_event_unmask(wl); 490 ret = wl1271_event_unmask(wl);
422 if (ret < 0) { 491 if (ret < 0) {
@@ -451,23 +520,164 @@ static void wl1271_boot_hw_version(struct wl1271 *wl)
451 fuse = (fuse & PG_VER_MASK) >> PG_VER_OFFSET; 520 fuse = (fuse & PG_VER_MASK) >> PG_VER_OFFSET;
452 521
453 wl->hw_pg_ver = (s8)fuse; 522 wl->hw_pg_ver = (s8)fuse;
523
524 if (((wl->hw_pg_ver & PG_MAJOR_VER_MASK) >> PG_MAJOR_VER_OFFSET) < 3)
525 wl->quirks |= WL12XX_QUIRK_END_OF_TRANSACTION;
454} 526}
455 527
456int wl1271_boot(struct wl1271 *wl) 528static int wl128x_switch_tcxo_to_fref(struct wl1271 *wl)
457{ 529{
458 int ret = 0; 530 u16 spare_reg;
459 u32 tmp, clk, pause; 531
532 /* Mask bits [2] & [8:4] in the sys_clk_cfg register */
533 spare_reg = wl1271_top_reg_read(wl, WL_SPARE_REG);
534 if (spare_reg == 0xFFFF)
535 return -EFAULT;
536 spare_reg |= (BIT(3) | BIT(5) | BIT(6));
537 wl1271_top_reg_write(wl, WL_SPARE_REG, spare_reg);
538
539 /* Enable FREF_CLK_REQ & mux MCS and coex PLLs to FREF */
540 wl1271_top_reg_write(wl, SYS_CLK_CFG_REG,
541 WL_CLK_REQ_TYPE_PG2 | MCS_PLL_CLK_SEL_FREF);
542
543 /* Delay execution for 15msec, to let the HW settle */
544 mdelay(15);
545
546 return 0;
547}
548
549static bool wl128x_is_tcxo_valid(struct wl1271 *wl)
550{
551 u16 tcxo_detection;
552
553 tcxo_detection = wl1271_top_reg_read(wl, TCXO_CLK_DETECT_REG);
554 if (tcxo_detection & TCXO_DET_FAILED)
555 return false;
556
557 return true;
558}
559
560static bool wl128x_is_fref_valid(struct wl1271 *wl)
561{
562 u16 fref_detection;
563
564 fref_detection = wl1271_top_reg_read(wl, FREF_CLK_DETECT_REG);
565 if (fref_detection & FREF_CLK_DETECT_FAIL)
566 return false;
567
568 return true;
569}
570
571static int wl128x_manually_configure_mcs_pll(struct wl1271 *wl)
572{
573 wl1271_top_reg_write(wl, MCS_PLL_M_REG, MCS_PLL_M_REG_VAL);
574 wl1271_top_reg_write(wl, MCS_PLL_N_REG, MCS_PLL_N_REG_VAL);
575 wl1271_top_reg_write(wl, MCS_PLL_CONFIG_REG, MCS_PLL_CONFIG_REG_VAL);
576
577 return 0;
578}
579
580static int wl128x_configure_mcs_pll(struct wl1271 *wl, int clk)
581{
582 u16 spare_reg;
583 u16 pll_config;
584 u8 input_freq;
585
586 /* Mask bits [3:1] in the sys_clk_cfg register */
587 spare_reg = wl1271_top_reg_read(wl, WL_SPARE_REG);
588 if (spare_reg == 0xFFFF)
589 return -EFAULT;
590 spare_reg |= BIT(2);
591 wl1271_top_reg_write(wl, WL_SPARE_REG, spare_reg);
592
593 /* Handle special cases of the TCXO clock */
594 if (wl->tcxo_clock == WL12XX_TCXOCLOCK_16_8 ||
595 wl->tcxo_clock == WL12XX_TCXOCLOCK_33_6)
596 return wl128x_manually_configure_mcs_pll(wl);
597
598 /* Set the input frequency according to the selected clock source */
599 input_freq = (clk & 1) + 1;
600
601 pll_config = wl1271_top_reg_read(wl, MCS_PLL_CONFIG_REG);
602 if (pll_config == 0xFFFF)
603 return -EFAULT;
604 pll_config |= (input_freq << MCS_SEL_IN_FREQ_SHIFT);
605 pll_config |= MCS_PLL_ENABLE_HP;
606 wl1271_top_reg_write(wl, MCS_PLL_CONFIG_REG, pll_config);
607
608 return 0;
609}
610
611/*
612 * WL128x has two clocks input - TCXO and FREF.
613 * TCXO is the main clock of the device, while FREF is used to sync
614 * between the GPS and the cellular modem.
615 * In cases where TCXO is 32.736MHz or 16.368MHz, the FREF will be used
616 * as the WLAN/BT main clock.
617 */
618static int wl128x_boot_clk(struct wl1271 *wl, int *selected_clock)
619{
620 u16 sys_clk_cfg;
621
622 /* For XTAL-only modes, FREF will be used after switching from TCXO */
623 if (wl->ref_clock == WL12XX_REFCLOCK_26_XTAL ||
624 wl->ref_clock == WL12XX_REFCLOCK_38_XTAL) {
625 if (!wl128x_switch_tcxo_to_fref(wl))
626 return -EINVAL;
627 goto fref_clk;
628 }
629
630 /* Query the HW, to determine which clock source we should use */
631 sys_clk_cfg = wl1271_top_reg_read(wl, SYS_CLK_CFG_REG);
632 if (sys_clk_cfg == 0xFFFF)
633 return -EINVAL;
634 if (sys_clk_cfg & PRCM_CM_EN_MUX_WLAN_FREF)
635 goto fref_clk;
636
637 /* If TCXO is either 32.736MHz or 16.368MHz, switch to FREF */
638 if (wl->tcxo_clock == WL12XX_TCXOCLOCK_16_368 ||
639 wl->tcxo_clock == WL12XX_TCXOCLOCK_32_736) {
640 if (!wl128x_switch_tcxo_to_fref(wl))
641 return -EINVAL;
642 goto fref_clk;
643 }
644
645 /* TCXO clock is selected */
646 if (!wl128x_is_tcxo_valid(wl))
647 return -EINVAL;
648 *selected_clock = wl->tcxo_clock;
649 goto config_mcs_pll;
650
651fref_clk:
652 /* FREF clock is selected */
653 if (!wl128x_is_fref_valid(wl))
654 return -EINVAL;
655 *selected_clock = wl->ref_clock;
656
657config_mcs_pll:
658 return wl128x_configure_mcs_pll(wl, *selected_clock);
659}
660
661static int wl127x_boot_clk(struct wl1271 *wl)
662{
663 u32 pause;
664 u32 clk;
460 665
461 wl1271_boot_hw_version(wl); 666 wl1271_boot_hw_version(wl);
462 667
463 if (REF_CLOCK == 0 || REF_CLOCK == 2 || REF_CLOCK == 4) 668 if (wl->ref_clock == CONF_REF_CLK_19_2_E ||
669 wl->ref_clock == CONF_REF_CLK_38_4_E ||
670 wl->ref_clock == CONF_REF_CLK_38_4_M_XTAL)
464 /* ref clk: 19.2/38.4/38.4-XTAL */ 671 /* ref clk: 19.2/38.4/38.4-XTAL */
465 clk = 0x3; 672 clk = 0x3;
466 else if (REF_CLOCK == 1 || REF_CLOCK == 3) 673 else if (wl->ref_clock == CONF_REF_CLK_26_E ||
674 wl->ref_clock == CONF_REF_CLK_52_E)
467 /* ref clk: 26/52 */ 675 /* ref clk: 26/52 */
468 clk = 0x5; 676 clk = 0x5;
677 else
678 return -EINVAL;
469 679
470 if (REF_CLOCK != 0) { 680 if (wl->ref_clock != CONF_REF_CLK_19_2_E) {
471 u16 val; 681 u16 val;
472 /* Set clock type (open drain) */ 682 /* Set clock type (open drain) */
473 val = wl1271_top_reg_read(wl, OCP_REG_CLK_TYPE); 683 val = wl1271_top_reg_read(wl, OCP_REG_CLK_TYPE);
@@ -493,13 +703,30 @@ int wl1271_boot(struct wl1271 *wl)
493 703
494 wl1271_debug(DEBUG_BOOT, "pause1 0x%x", pause); 704 wl1271_debug(DEBUG_BOOT, "pause1 0x%x", pause);
495 705
496 pause &= ~(WU_COUNTER_PAUSE_VAL); /* FIXME: This should probably be 706 pause &= ~(WU_COUNTER_PAUSE_VAL);
497 * WU_COUNTER_PAUSE_VAL instead of
498 * 0x3ff (magic number ). How does
499 * this work?! */
500 pause |= WU_COUNTER_PAUSE_VAL; 707 pause |= WU_COUNTER_PAUSE_VAL;
501 wl1271_write32(wl, WU_COUNTER_PAUSE, pause); 708 wl1271_write32(wl, WU_COUNTER_PAUSE, pause);
502 709
710 return 0;
711}
712
713/* uploads NVS and firmware */
714int wl1271_load_firmware(struct wl1271 *wl)
715{
716 int ret = 0;
717 u32 tmp, clk;
718 int selected_clock = -1;
719
720 if (wl->chip.id == CHIP_ID_1283_PG20) {
721 ret = wl128x_boot_clk(wl, &selected_clock);
722 if (ret < 0)
723 goto out;
724 } else {
725 ret = wl127x_boot_clk(wl);
726 if (ret < 0)
727 goto out;
728 }
729
503 /* Continue the ELP wake up sequence */ 730 /* Continue the ELP wake up sequence */
504 wl1271_write32(wl, WELP_ARM_COMMAND, WELP_ARM_COMMAND_VAL); 731 wl1271_write32(wl, WELP_ARM_COMMAND, WELP_ARM_COMMAND_VAL);
505 udelay(500); 732 udelay(500);
@@ -515,8 +742,12 @@ int wl1271_boot(struct wl1271 *wl)
515 742
516 wl1271_debug(DEBUG_BOOT, "clk2 0x%x", clk); 743 wl1271_debug(DEBUG_BOOT, "clk2 0x%x", clk);
517 744
518 /* 2 */ 745 if (wl->chip.id == CHIP_ID_1283_PG20) {
519 clk |= (REF_CLOCK << 1) << 4; 746 clk |= ((selected_clock & 0x3) << 1) << 4;
747 } else {
748 clk |= (wl->ref_clock << 1) << 4;
749 }
750
520 wl1271_write32(wl, DRPW_SCRATCH_START, clk); 751 wl1271_write32(wl, DRPW_SCRATCH_START, clk);
521 752
522 wl1271_set_partition(wl, &part_table[PART_WORK]); 753 wl1271_set_partition(wl, &part_table[PART_WORK]);
@@ -546,32 +777,47 @@ int wl1271_boot(struct wl1271 *wl)
546 /* 6. read the EEPROM parameters */ 777 /* 6. read the EEPROM parameters */
547 tmp = wl1271_read32(wl, SCR_PAD2); 778 tmp = wl1271_read32(wl, SCR_PAD2);
548 779
549 ret = wl1271_boot_write_irq_polarity(wl);
550 if (ret < 0)
551 goto out;
552
553 /* FIXME: Need to check whether this is really what we want */
554 wl1271_write32(wl, ACX_REG_INTERRUPT_MASK,
555 WL1271_ACX_ALL_EVENTS_VECTOR);
556
557 /* WL1271: The reference driver skips steps 7 to 10 (jumps directly 780 /* WL1271: The reference driver skips steps 7 to 10 (jumps directly
558 * to upload_fw) */ 781 * to upload_fw) */
559 782
783 if (wl->chip.id == CHIP_ID_1283_PG20)
784 wl1271_top_reg_write(wl, SDIO_IO_DS, wl->conf.hci_io_ds);
785
560 ret = wl1271_boot_upload_firmware(wl); 786 ret = wl1271_boot_upload_firmware(wl);
561 if (ret < 0) 787 if (ret < 0)
562 goto out; 788 goto out;
563 789
790out:
791 return ret;
792}
793EXPORT_SYMBOL_GPL(wl1271_load_firmware);
794
795int wl1271_boot(struct wl1271 *wl)
796{
797 int ret;
798
799 /* upload NVS and firmware */
800 ret = wl1271_load_firmware(wl);
801 if (ret)
802 return ret;
803
564 /* 10.5 start firmware */ 804 /* 10.5 start firmware */
565 ret = wl1271_boot_run_firmware(wl); 805 ret = wl1271_boot_run_firmware(wl);
566 if (ret < 0) 806 if (ret < 0)
567 goto out; 807 goto out;
568 808
809 ret = wl1271_boot_write_irq_polarity(wl);
810 if (ret < 0)
811 goto out;
812
813 wl1271_write32(wl, ACX_REG_INTERRUPT_MASK,
814 WL1271_ACX_ALL_EVENTS_VECTOR);
815
569 /* Enable firmware interrupts now */ 816 /* Enable firmware interrupts now */
570 wl1271_boot_enable_interrupts(wl); 817 wl1271_boot_enable_interrupts(wl);
571 818
572 /* set the wl1271 default filters */ 819 /* set the wl1271 default filters */
573 wl->rx_config = WL1271_DEFAULT_RX_CONFIG; 820 wl1271_set_default_filters(wl);
574 wl->rx_filter = WL1271_DEFAULT_RX_FILTER;
575 821
576 wl1271_event_mbox_config(wl); 822 wl1271_event_mbox_config(wl);
577 823
diff --git a/drivers/net/wireless/wl12xx/wl1271_boot.h b/drivers/net/wireless/wl12xx/boot.h
index f829699d597e..e8f8255bbabe 100644
--- a/drivers/net/wireless/wl12xx/wl1271_boot.h
+++ b/drivers/net/wireless/wl12xx/boot.h
@@ -24,9 +24,10 @@
24#ifndef __BOOT_H__ 24#ifndef __BOOT_H__
25#define __BOOT_H__ 25#define __BOOT_H__
26 26
27#include "wl1271.h" 27#include "wl12xx.h"
28 28
29int wl1271_boot(struct wl1271 *wl); 29int wl1271_boot(struct wl1271 *wl);
30int wl1271_load_firmware(struct wl1271 *wl);
30 31
31#define WL1271_NO_SUBBANDS 8 32#define WL1271_NO_SUBBANDS 8
32#define WL1271_NO_POWER_LEVELS 4 33#define WL1271_NO_POWER_LEVELS 4
@@ -46,7 +47,6 @@ struct wl1271_static_data {
46/* delay between retries */ 47/* delay between retries */
47#define INIT_LOOP_DELAY 50 48#define INIT_LOOP_DELAY 50
48 49
49#define REF_CLOCK 2
50#define WU_COUNTER_PAUSE_VAL 0x3FF 50#define WU_COUNTER_PAUSE_VAL 0x3FF
51#define WELP_ARM_COMMAND_VAL 0x4 51#define WELP_ARM_COMMAND_VAL 0x4
52 52
@@ -59,6 +59,11 @@ struct wl1271_static_data {
59#define PG_VER_MASK 0x3c 59#define PG_VER_MASK 0x3c
60#define PG_VER_OFFSET 2 60#define PG_VER_OFFSET 2
61 61
62#define PG_MAJOR_VER_MASK 0x3
63#define PG_MAJOR_VER_OFFSET 0x0
64#define PG_MINOR_VER_MASK 0xc
65#define PG_MINOR_VER_OFFSET 0x2
66
62#define CMD_MBOX_ADDRESS 0x407B4 67#define CMD_MBOX_ADDRESS 0x407B4
63 68
64#define POLARITY_LOW BIT(1) 69#define POLARITY_LOW BIT(1)
@@ -69,4 +74,56 @@ struct wl1271_static_data {
69#define FREF_CLK_POLARITY_BITS 0xfffff8ff 74#define FREF_CLK_POLARITY_BITS 0xfffff8ff
70#define CLK_REQ_OUTN_SEL 0x700 75#define CLK_REQ_OUTN_SEL 0x700
71 76
77/* PLL configuration algorithm for wl128x */
78#define SYS_CLK_CFG_REG 0x2200
79/* Bit[0] - 0-TCXO, 1-FREF */
80#define MCS_PLL_CLK_SEL_FREF BIT(0)
81/* Bit[3:2] - 01-TCXO, 10-FREF */
82#define WL_CLK_REQ_TYPE_FREF BIT(3)
83#define WL_CLK_REQ_TYPE_PG2 (BIT(3) | BIT(2))
84/* Bit[4] - 0-TCXO, 1-FREF */
85#define PRCM_CM_EN_MUX_WLAN_FREF BIT(4)
86
87#define TCXO_ILOAD_INT_REG 0x2264
88#define TCXO_CLK_DETECT_REG 0x2266
89
90#define TCXO_DET_FAILED BIT(4)
91
92#define FREF_ILOAD_INT_REG 0x2084
93#define FREF_CLK_DETECT_REG 0x2086
94#define FREF_CLK_DETECT_FAIL BIT(4)
95
96/* Use this reg for masking during driver access */
97#define WL_SPARE_REG 0x2320
98#define WL_SPARE_VAL BIT(2)
99/* Bit[6:5:3] - mask wl write SYS_CLK_CFG[8:5:2:4] */
100#define WL_SPARE_MASK_8526 (BIT(6) | BIT(5) | BIT(3))
101
102#define PLL_LOCK_COUNTERS_REG 0xD8C
103#define PLL_LOCK_COUNTERS_COEX 0x0F
104#define PLL_LOCK_COUNTERS_MCS 0xF0
105#define MCS_PLL_OVERRIDE_REG 0xD90
106#define MCS_PLL_CONFIG_REG 0xD92
107#define MCS_SEL_IN_FREQ_MASK 0x0070
108#define MCS_SEL_IN_FREQ_SHIFT 4
109#define MCS_PLL_CONFIG_REG_VAL 0x73
110#define MCS_PLL_ENABLE_HP (BIT(0) | BIT(1))
111
112#define MCS_PLL_M_REG 0xD94
113#define MCS_PLL_N_REG 0xD96
114#define MCS_PLL_M_REG_VAL 0xC8
115#define MCS_PLL_N_REG_VAL 0x07
116
117#define SDIO_IO_DS 0xd14
118
119/* SDIO/wSPI DS configuration values */
120enum {
121 HCI_IO_DS_8MA = 0,
122 HCI_IO_DS_4MA = 1, /* default */
123 HCI_IO_DS_6MA = 2,
124 HCI_IO_DS_2MA = 3,
125};
126
127/* end PLL configuration algorithm for wl128x */
128
72#endif 129#endif
diff --git a/drivers/net/wireless/wl12xx/wl1271_cmd.c b/drivers/net/wireless/wl12xx/cmd.c
index ce503ddd5a41..42935ac72663 100644
--- a/drivers/net/wireless/wl12xx/wl1271_cmd.c
+++ b/drivers/net/wireless/wl12xx/cmd.c
@@ -29,13 +29,14 @@
29#include <linux/ieee80211.h> 29#include <linux/ieee80211.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31 31
32#include "wl1271.h" 32#include "wl12xx.h"
33#include "wl1271_reg.h" 33#include "reg.h"
34#include "wl1271_io.h" 34#include "io.h"
35#include "wl1271_acx.h" 35#include "acx.h"
36#include "wl12xx_80211.h" 36#include "wl12xx_80211.h"
37#include "wl1271_cmd.h" 37#include "cmd.h"
38#include "wl1271_event.h" 38#include "event.h"
39#include "tx.h"
39 40
40#define WL1271_CMD_FAST_POLL_COUNT 50 41#define WL1271_CMD_FAST_POLL_COUNT 50
41 42
@@ -62,6 +63,7 @@ int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
62 cmd->status = 0; 63 cmd->status = 0;
63 64
64 WARN_ON(len % 4 != 0); 65 WARN_ON(len % 4 != 0);
66 WARN_ON(test_bit(WL1271_FLAG_IN_ELP, &wl->flags));
65 67
66 wl1271_write(wl, wl->cmd_box_addr, buf, len, false); 68 wl1271_write(wl, wl->cmd_box_addr, buf, len, false);
67 69
@@ -74,7 +76,7 @@ int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
74 if (time_after(jiffies, timeout)) { 76 if (time_after(jiffies, timeout)) {
75 wl1271_error("command complete timeout"); 77 wl1271_error("command complete timeout");
76 ret = -ETIMEDOUT; 78 ret = -ETIMEDOUT;
77 goto out; 79 goto fail;
78 } 80 }
79 81
80 poll_count++; 82 poll_count++;
@@ -95,18 +97,25 @@ int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
95 if (status != CMD_STATUS_SUCCESS) { 97 if (status != CMD_STATUS_SUCCESS) {
96 wl1271_error("command execute failure %d", status); 98 wl1271_error("command execute failure %d", status);
97 ret = -EIO; 99 ret = -EIO;
100 goto fail;
98 } 101 }
99 102
100 wl1271_write32(wl, ACX_REG_INTERRUPT_ACK, 103 wl1271_write32(wl, ACX_REG_INTERRUPT_ACK,
101 WL1271_ACX_INTR_CMD_COMPLETE); 104 WL1271_ACX_INTR_CMD_COMPLETE);
105 return 0;
102 106
103out: 107fail:
108 WARN_ON(1);
109 ieee80211_queue_work(wl->hw, &wl->recovery_work);
104 return ret; 110 return ret;
105} 111}
106 112
107int wl1271_cmd_general_parms(struct wl1271 *wl) 113int wl1271_cmd_general_parms(struct wl1271 *wl)
108{ 114{
109 struct wl1271_general_parms_cmd *gen_parms; 115 struct wl1271_general_parms_cmd *gen_parms;
116 struct wl1271_ini_general_params *gp =
117 &((struct wl1271_nvs_file *)wl->nvs)->general_params;
118 bool answer = false;
110 int ret; 119 int ret;
111 120
112 if (!wl->nvs) 121 if (!wl->nvs)
@@ -118,21 +127,79 @@ int wl1271_cmd_general_parms(struct wl1271 *wl)
118 127
119 gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM; 128 gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
120 129
121 memcpy(&gen_parms->general_params, &wl->nvs->general_params, 130 memcpy(&gen_parms->general_params, gp, sizeof(*gp));
122 sizeof(struct wl1271_ini_general_params));
123 131
124 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), 0); 132 if (gp->tx_bip_fem_auto_detect)
125 if (ret < 0) 133 answer = true;
134
135 /* Override the REF CLK from the NVS with the one from platform data */
136 gen_parms->general_params.ref_clock = wl->ref_clock;
137
138 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer);
139 if (ret < 0) {
126 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed"); 140 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
141 goto out;
142 }
143
144 gp->tx_bip_fem_manufacturer =
145 gen_parms->general_params.tx_bip_fem_manufacturer;
146
147 wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
148 answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
127 149
150out:
151 kfree(gen_parms);
152 return ret;
153}
154
155int wl128x_cmd_general_parms(struct wl1271 *wl)
156{
157 struct wl128x_general_parms_cmd *gen_parms;
158 struct wl128x_ini_general_params *gp =
159 &((struct wl128x_nvs_file *)wl->nvs)->general_params;
160 bool answer = false;
161 int ret;
162
163 if (!wl->nvs)
164 return -ENODEV;
165
166 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
167 if (!gen_parms)
168 return -ENOMEM;
169
170 gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
171
172 memcpy(&gen_parms->general_params, gp, sizeof(*gp));
173
174 if (gp->tx_bip_fem_auto_detect)
175 answer = true;
176
177 /* Replace REF and TCXO CLKs with the ones from platform data */
178 gen_parms->general_params.ref_clock = wl->ref_clock;
179 gen_parms->general_params.tcxo_ref_clock = wl->tcxo_clock;
180
181 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer);
182 if (ret < 0) {
183 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
184 goto out;
185 }
186
187 gp->tx_bip_fem_manufacturer =
188 gen_parms->general_params.tx_bip_fem_manufacturer;
189
190 wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
191 answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
192
193out:
128 kfree(gen_parms); 194 kfree(gen_parms);
129 return ret; 195 return ret;
130} 196}
131 197
132int wl1271_cmd_radio_parms(struct wl1271 *wl) 198int wl1271_cmd_radio_parms(struct wl1271 *wl)
133{ 199{
200 struct wl1271_nvs_file *nvs = (struct wl1271_nvs_file *)wl->nvs;
134 struct wl1271_radio_parms_cmd *radio_parms; 201 struct wl1271_radio_parms_cmd *radio_parms;
135 struct wl1271_ini_general_params *gp = &wl->nvs->general_params; 202 struct wl1271_ini_general_params *gp = &nvs->general_params;
136 int ret; 203 int ret;
137 204
138 if (!wl->nvs) 205 if (!wl->nvs)
@@ -145,18 +212,18 @@ int wl1271_cmd_radio_parms(struct wl1271 *wl)
145 radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM; 212 radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
146 213
147 /* 2.4GHz parameters */ 214 /* 2.4GHz parameters */
148 memcpy(&radio_parms->static_params_2, &wl->nvs->stat_radio_params_2, 215 memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2,
149 sizeof(struct wl1271_ini_band_params_2)); 216 sizeof(struct wl1271_ini_band_params_2));
150 memcpy(&radio_parms->dyn_params_2, 217 memcpy(&radio_parms->dyn_params_2,
151 &wl->nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params, 218 &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params,
152 sizeof(struct wl1271_ini_fem_params_2)); 219 sizeof(struct wl1271_ini_fem_params_2));
153 220
154 /* 5GHz parameters */ 221 /* 5GHz parameters */
155 memcpy(&radio_parms->static_params_5, 222 memcpy(&radio_parms->static_params_5,
156 &wl->nvs->stat_radio_params_5, 223 &nvs->stat_radio_params_5,
157 sizeof(struct wl1271_ini_band_params_5)); 224 sizeof(struct wl1271_ini_band_params_5));
158 memcpy(&radio_parms->dyn_params_5, 225 memcpy(&radio_parms->dyn_params_5,
159 &wl->nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params, 226 &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params,
160 sizeof(struct wl1271_ini_fem_params_5)); 227 sizeof(struct wl1271_ini_fem_params_5));
161 228
162 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ", 229 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
@@ -170,11 +237,88 @@ int wl1271_cmd_radio_parms(struct wl1271 *wl)
170 return ret; 237 return ret;
171} 238}
172 239
240int wl128x_cmd_radio_parms(struct wl1271 *wl)
241{
242 struct wl128x_nvs_file *nvs = (struct wl128x_nvs_file *)wl->nvs;
243 struct wl128x_radio_parms_cmd *radio_parms;
244 struct wl128x_ini_general_params *gp = &nvs->general_params;
245 int ret;
246
247 if (!wl->nvs)
248 return -ENODEV;
249
250 radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
251 if (!radio_parms)
252 return -ENOMEM;
253
254 radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
255
256 /* 2.4GHz parameters */
257 memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2,
258 sizeof(struct wl128x_ini_band_params_2));
259 memcpy(&radio_parms->dyn_params_2,
260 &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params,
261 sizeof(struct wl128x_ini_fem_params_2));
262
263 /* 5GHz parameters */
264 memcpy(&radio_parms->static_params_5,
265 &nvs->stat_radio_params_5,
266 sizeof(struct wl128x_ini_band_params_5));
267 memcpy(&radio_parms->dyn_params_5,
268 &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params,
269 sizeof(struct wl128x_ini_fem_params_5));
270
271 radio_parms->fem_vendor_and_options = nvs->fem_vendor_and_options;
272
273 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
274 radio_parms, sizeof(*radio_parms));
275
276 ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
277 if (ret < 0)
278 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
279
280 kfree(radio_parms);
281 return ret;
282}
283
284int wl1271_cmd_ext_radio_parms(struct wl1271 *wl)
285{
286 struct wl1271_ext_radio_parms_cmd *ext_radio_parms;
287 struct conf_rf_settings *rf = &wl->conf.rf;
288 int ret;
289
290 if (!wl->nvs)
291 return -ENODEV;
292
293 ext_radio_parms = kzalloc(sizeof(*ext_radio_parms), GFP_KERNEL);
294 if (!ext_radio_parms)
295 return -ENOMEM;
296
297 ext_radio_parms->test.id = TEST_CMD_INI_FILE_RF_EXTENDED_PARAM;
298
299 memcpy(ext_radio_parms->tx_per_channel_power_compensation_2,
300 rf->tx_per_channel_power_compensation_2,
301 CONF_TX_PWR_COMPENSATION_LEN_2);
302 memcpy(ext_radio_parms->tx_per_channel_power_compensation_5,
303 rf->tx_per_channel_power_compensation_5,
304 CONF_TX_PWR_COMPENSATION_LEN_5);
305
306 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_EXT_RADIO_PARAM: ",
307 ext_radio_parms, sizeof(*ext_radio_parms));
308
309 ret = wl1271_cmd_test(wl, ext_radio_parms, sizeof(*ext_radio_parms), 0);
310 if (ret < 0)
311 wl1271_warning("TEST_CMD_INI_FILE_RF_EXTENDED_PARAM failed");
312
313 kfree(ext_radio_parms);
314 return ret;
315}
316
173/* 317/*
174 * Poll the mailbox event field until any of the bits in the mask is set or a 318 * Poll the mailbox event field until any of the bits in the mask is set or a
175 * timeout occurs (WL1271_EVENT_TIMEOUT in msecs) 319 * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
176 */ 320 */
177static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask) 321static int wl1271_cmd_wait_for_event_or_timeout(struct wl1271 *wl, u32 mask)
178{ 322{
179 u32 events_vector, event; 323 u32 events_vector, event;
180 unsigned long timeout; 324 unsigned long timeout;
@@ -182,8 +326,11 @@ static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask)
182 timeout = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT); 326 timeout = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT);
183 327
184 do { 328 do {
185 if (time_after(jiffies, timeout)) 329 if (time_after(jiffies, timeout)) {
330 wl1271_debug(DEBUG_CMD, "timeout waiting for event %d",
331 (int)mask);
186 return -ETIMEDOUT; 332 return -ETIMEDOUT;
333 }
187 334
188 msleep(1); 335 msleep(1);
189 336
@@ -199,6 +346,19 @@ static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask)
199 return 0; 346 return 0;
200} 347}
201 348
349static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask)
350{
351 int ret;
352
353 ret = wl1271_cmd_wait_for_event_or_timeout(wl, mask);
354 if (ret != 0) {
355 ieee80211_queue_work(wl->hw, &wl->recovery_work);
356 return ret;
357 }
358
359 return 0;
360}
361
202int wl1271_cmd_join(struct wl1271 *wl, u8 bss_type) 362int wl1271_cmd_join(struct wl1271 *wl, u8 bss_type)
203{ 363{
204 struct wl1271_cmd_join *join; 364 struct wl1271_cmd_join *join;
@@ -222,6 +382,7 @@ int wl1271_cmd_join(struct wl1271 *wl, u8 bss_type)
222 join->rx_filter_options = cpu_to_le32(wl->rx_filter); 382 join->rx_filter_options = cpu_to_le32(wl->rx_filter);
223 join->bss_type = bss_type; 383 join->bss_type = bss_type;
224 join->basic_rate_set = cpu_to_le32(wl->basic_rate_set); 384 join->basic_rate_set = cpu_to_le32(wl->basic_rate_set);
385 join->supported_rate_set = cpu_to_le32(wl->rate_set);
225 386
226 if (wl->band == IEEE80211_BAND_5GHZ) 387 if (wl->band == IEEE80211_BAND_5GHZ)
227 join->bss_type |= WL1271_JOIN_CMD_BSS_TYPE_5GHZ; 388 join->bss_type |= WL1271_JOIN_CMD_BSS_TYPE_5GHZ;
@@ -239,6 +400,9 @@ int wl1271_cmd_join(struct wl1271 *wl, u8 bss_type)
239 wl->tx_security_last_seq = 0; 400 wl->tx_security_last_seq = 0;
240 wl->tx_security_seq = 0; 401 wl->tx_security_seq = 0;
241 402
403 wl1271_debug(DEBUG_CMD, "cmd join: basic_rate_set=0x%x, rate_set=0x%x",
404 join->basic_rate_set, join->supported_rate_set);
405
242 ret = wl1271_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join), 0); 406 ret = wl1271_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join), 0);
243 if (ret < 0) { 407 if (ret < 0) {
244 wl1271_error("failed to initiate cmd join"); 408 wl1271_error("failed to initiate cmd join");
@@ -290,7 +454,7 @@ int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
290 * @wl: wl struct 454 * @wl: wl struct
291 * @id: acx id 455 * @id: acx id
292 * @buf: buffer for the response, including all headers, must work with dma 456 * @buf: buffer for the response, including all headers, must work with dma
293 * @len: lenght of buf 457 * @len: length of buf
294 */ 458 */
295int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len) 459int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
296{ 460{
@@ -390,18 +554,11 @@ out:
390 return ret; 554 return ret;
391} 555}
392 556
393int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode, bool send) 557int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode)
394{ 558{
395 struct wl1271_cmd_ps_params *ps_params = NULL; 559 struct wl1271_cmd_ps_params *ps_params = NULL;
396 int ret = 0; 560 int ret = 0;
397 561
398 /* FIXME: this should be in ps.c */
399 ret = wl1271_acx_wake_up_conditions(wl);
400 if (ret < 0) {
401 wl1271_error("couldn't set wake up conditions");
402 goto out;
403 }
404
405 wl1271_debug(DEBUG_CMD, "cmd set ps mode"); 562 wl1271_debug(DEBUG_CMD, "cmd set ps mode");
406 563
407 ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL); 564 ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
@@ -411,10 +568,6 @@ int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode, bool send)
411 } 568 }
412 569
413 ps_params->ps_mode = ps_mode; 570 ps_params->ps_mode = ps_mode;
414 ps_params->send_null_data = send;
415 ps_params->retries = 5;
416 ps_params->hang_over_period = 1;
417 ps_params->null_data_rate = cpu_to_le32(wl->basic_rate_set);
418 571
419 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params, 572 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
420 sizeof(*ps_params), 0); 573 sizeof(*ps_params), 0);
@@ -428,41 +581,6 @@ out:
428 return ret; 581 return ret;
429} 582}
430 583
431int wl1271_cmd_read_memory(struct wl1271 *wl, u32 addr, void *answer,
432 size_t len)
433{
434 struct cmd_read_write_memory *cmd;
435 int ret = 0;
436
437 wl1271_debug(DEBUG_CMD, "cmd read memory");
438
439 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
440 if (!cmd) {
441 ret = -ENOMEM;
442 goto out;
443 }
444
445 WARN_ON(len > MAX_READ_SIZE);
446 len = min_t(size_t, len, MAX_READ_SIZE);
447
448 cmd->addr = cpu_to_le32(addr);
449 cmd->size = cpu_to_le32(len);
450
451 ret = wl1271_cmd_send(wl, CMD_READ_MEMORY, cmd, sizeof(*cmd),
452 sizeof(*cmd));
453 if (ret < 0) {
454 wl1271_error("read memory command failed: %d", ret);
455 goto out;
456 }
457
458 /* the read command got in */
459 memcpy(answer, cmd->value, len);
460
461out:
462 kfree(cmd);
463 return ret;
464}
465
466int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id, 584int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id,
467 void *buf, size_t buf_len, int index, u32 rates) 585 void *buf, size_t buf_len, int index, u32 rates)
468{ 586{
@@ -483,8 +601,8 @@ int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id,
483 cmd->len = cpu_to_le16(buf_len); 601 cmd->len = cpu_to_le16(buf_len);
484 cmd->template_type = template_id; 602 cmd->template_type = template_id;
485 cmd->enabled_rates = cpu_to_le32(rates); 603 cmd->enabled_rates = cpu_to_le32(rates);
486 cmd->short_retry_limit = wl->conf.tx.rc_conf.short_retry_limit; 604 cmd->short_retry_limit = wl->conf.tx.tmpl_short_retry_limit;
487 cmd->long_retry_limit = wl->conf.tx.rc_conf.long_retry_limit; 605 cmd->long_retry_limit = wl->conf.tx.tmpl_long_retry_limit;
488 cmd->index = index; 606 cmd->index = index;
489 607
490 if (buf) 608 if (buf)
@@ -523,7 +641,7 @@ int wl1271_cmd_build_null_data(struct wl1271 *wl)
523 } 641 }
524 642
525 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, ptr, size, 0, 643 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, ptr, size, 0,
526 WL1271_RATE_AUTOMATIC); 644 wl->basic_rate);
527 645
528out: 646out:
529 dev_kfree_skb(skb); 647 dev_kfree_skb(skb);
@@ -546,7 +664,7 @@ int wl1271_cmd_build_klv_null_data(struct wl1271 *wl)
546 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV, 664 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV,
547 skb->data, skb->len, 665 skb->data, skb->len,
548 CMD_TEMPL_KLV_IDX_NULL_DATA, 666 CMD_TEMPL_KLV_IDX_NULL_DATA,
549 WL1271_RATE_AUTOMATIC); 667 wl->basic_rate);
550 668
551out: 669out:
552 dev_kfree_skb(skb); 670 dev_kfree_skb(skb);
@@ -604,6 +722,75 @@ out:
604 return ret; 722 return ret;
605} 723}
606 724
725struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
726 struct sk_buff *skb)
727{
728 int ret;
729
730 if (!skb)
731 skb = ieee80211_ap_probereq_get(wl->hw, wl->vif);
732 if (!skb)
733 goto out;
734
735 wl1271_dump(DEBUG_SCAN, "AP PROBE REQ: ", skb->data, skb->len);
736
737 if (wl->band == IEEE80211_BAND_2GHZ)
738 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
739 skb->data, skb->len, 0,
740 wl->conf.tx.basic_rate);
741 else
742 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
743 skb->data, skb->len, 0,
744 wl->conf.tx.basic_rate_5);
745
746 if (ret < 0)
747 wl1271_error("Unable to set ap probe request template.");
748
749out:
750 return skb;
751}
752
753int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, __be32 ip_addr)
754{
755 int ret;
756 struct wl12xx_arp_rsp_template tmpl;
757 struct ieee80211_hdr_3addr *hdr;
758 struct arphdr *arp_hdr;
759
760 memset(&tmpl, 0, sizeof(tmpl));
761
762 /* mac80211 header */
763 hdr = &tmpl.hdr;
764 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
765 IEEE80211_STYPE_DATA |
766 IEEE80211_FCTL_TODS);
767 memcpy(hdr->addr1, wl->vif->bss_conf.bssid, ETH_ALEN);
768 memcpy(hdr->addr2, wl->vif->addr, ETH_ALEN);
769 memset(hdr->addr3, 0xff, ETH_ALEN);
770
771 /* llc layer */
772 memcpy(tmpl.llc_hdr, rfc1042_header, sizeof(rfc1042_header));
773 tmpl.llc_type = cpu_to_be16(ETH_P_ARP);
774
775 /* arp header */
776 arp_hdr = &tmpl.arp_hdr;
777 arp_hdr->ar_hrd = cpu_to_be16(ARPHRD_ETHER);
778 arp_hdr->ar_pro = cpu_to_be16(ETH_P_IP);
779 arp_hdr->ar_hln = ETH_ALEN;
780 arp_hdr->ar_pln = 4;
781 arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY);
782
783 /* arp payload */
784 memcpy(tmpl.sender_hw, wl->vif->addr, ETH_ALEN);
785 tmpl.sender_ip = ip_addr;
786
787 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_ARP_RSP,
788 &tmpl, sizeof(tmpl), 0,
789 wl->basic_rate);
790
791 return ret;
792}
793
607int wl1271_build_qos_null_data(struct wl1271 *wl) 794int wl1271_build_qos_null_data(struct wl1271 *wl)
608{ 795{
609 struct ieee80211_qos_hdr template; 796 struct ieee80211_qos_hdr template;
@@ -623,12 +810,12 @@ int wl1271_build_qos_null_data(struct wl1271 *wl)
623 810
624 return wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, &template, 811 return wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, &template,
625 sizeof(template), 0, 812 sizeof(template), 0,
626 WL1271_RATE_AUTOMATIC); 813 wl->basic_rate);
627} 814}
628 815
629int wl1271_cmd_set_default_wep_key(struct wl1271 *wl, u8 id) 816int wl1271_cmd_set_sta_default_wep_key(struct wl1271 *wl, u8 id)
630{ 817{
631 struct wl1271_cmd_set_keys *cmd; 818 struct wl1271_cmd_set_sta_keys *cmd;
632 int ret = 0; 819 int ret = 0;
633 820
634 wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id); 821 wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
@@ -655,11 +842,42 @@ out:
655 return ret; 842 return ret;
656} 843}
657 844
658int wl1271_cmd_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type, 845int wl1271_cmd_set_ap_default_wep_key(struct wl1271 *wl, u8 id)
846{
847 struct wl1271_cmd_set_ap_keys *cmd;
848 int ret = 0;
849
850 wl1271_debug(DEBUG_CMD, "cmd set_ap_default_wep_key %d", id);
851
852 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
853 if (!cmd) {
854 ret = -ENOMEM;
855 goto out;
856 }
857
858 cmd->hlid = WL1271_AP_BROADCAST_HLID;
859 cmd->key_id = id;
860 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
861 cmd->key_action = cpu_to_le16(KEY_SET_ID);
862 cmd->key_type = KEY_WEP;
863
864 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
865 if (ret < 0) {
866 wl1271_warning("cmd set_ap_default_wep_key failed: %d", ret);
867 goto out;
868 }
869
870out:
871 kfree(cmd);
872
873 return ret;
874}
875
876int wl1271_cmd_set_sta_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
659 u8 key_size, const u8 *key, const u8 *addr, 877 u8 key_size, const u8 *key, const u8 *addr,
660 u32 tx_seq_32, u16 tx_seq_16) 878 u32 tx_seq_32, u16 tx_seq_16)
661{ 879{
662 struct wl1271_cmd_set_keys *cmd; 880 struct wl1271_cmd_set_sta_keys *cmd;
663 int ret = 0; 881 int ret = 0;
664 882
665 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 883 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
@@ -712,6 +930,67 @@ out:
712 return ret; 930 return ret;
713} 931}
714 932
933int wl1271_cmd_set_ap_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
934 u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
935 u16 tx_seq_16)
936{
937 struct wl1271_cmd_set_ap_keys *cmd;
938 int ret = 0;
939 u8 lid_type;
940
941 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
942 if (!cmd)
943 return -ENOMEM;
944
945 if (hlid == WL1271_AP_BROADCAST_HLID) {
946 if (key_type == KEY_WEP)
947 lid_type = WEP_DEFAULT_LID_TYPE;
948 else
949 lid_type = BROADCAST_LID_TYPE;
950 } else {
951 lid_type = UNICAST_LID_TYPE;
952 }
953
954 wl1271_debug(DEBUG_CRYPT, "ap key action: %d id: %d lid: %d type: %d"
955 " hlid: %d", (int)action, (int)id, (int)lid_type,
956 (int)key_type, (int)hlid);
957
958 cmd->lid_key_type = lid_type;
959 cmd->hlid = hlid;
960 cmd->key_action = cpu_to_le16(action);
961 cmd->key_size = key_size;
962 cmd->key_type = key_type;
963 cmd->key_id = id;
964 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
965 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
966
967 if (key_type == KEY_TKIP) {
968 /*
969 * We get the key in the following form:
970 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
971 * but the target is expecting:
972 * TKIP - RX MIC - TX MIC
973 */
974 memcpy(cmd->key, key, 16);
975 memcpy(cmd->key + 16, key + 24, 8);
976 memcpy(cmd->key + 24, key + 16, 8);
977 } else {
978 memcpy(cmd->key, key, key_size);
979 }
980
981 wl1271_dump(DEBUG_CRYPT, "TARGET AP KEY: ", cmd, sizeof(*cmd));
982
983 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
984 if (ret < 0) {
985 wl1271_warning("could not set ap keys");
986 goto out;
987 }
988
989out:
990 kfree(cmd);
991 return ret;
992}
993
715int wl1271_cmd_disconnect(struct wl1271 *wl) 994int wl1271_cmd_disconnect(struct wl1271 *wl)
716{ 995{
717 struct wl1271_cmd_disconnect *cmd; 996 struct wl1271_cmd_disconnect *cmd;
@@ -746,3 +1025,208 @@ out_free:
746out: 1025out:
747 return ret; 1026 return ret;
748} 1027}
1028
1029int wl1271_cmd_set_sta_state(struct wl1271 *wl)
1030{
1031 struct wl1271_cmd_set_sta_state *cmd;
1032 int ret = 0;
1033
1034 wl1271_debug(DEBUG_CMD, "cmd set sta state");
1035
1036 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1037 if (!cmd) {
1038 ret = -ENOMEM;
1039 goto out;
1040 }
1041
1042 cmd->state = WL1271_CMD_STA_STATE_CONNECTED;
1043
1044 ret = wl1271_cmd_send(wl, CMD_SET_STA_STATE, cmd, sizeof(*cmd), 0);
1045 if (ret < 0) {
1046 wl1271_error("failed to send set STA state command");
1047 goto out_free;
1048 }
1049
1050out_free:
1051 kfree(cmd);
1052
1053out:
1054 return ret;
1055}
1056
1057int wl1271_cmd_start_bss(struct wl1271 *wl)
1058{
1059 struct wl1271_cmd_bss_start *cmd;
1060 struct ieee80211_bss_conf *bss_conf = &wl->vif->bss_conf;
1061 int ret;
1062
1063 wl1271_debug(DEBUG_CMD, "cmd start bss");
1064
1065 /*
1066 * FIXME: We currently do not support hidden SSID. The real SSID
1067 * should be fetched from mac80211 first.
1068 */
1069 if (wl->ssid_len == 0) {
1070 wl1271_warning("Hidden SSID currently not supported for AP");
1071 ret = -EINVAL;
1072 goto out;
1073 }
1074
1075 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1076 if (!cmd) {
1077 ret = -ENOMEM;
1078 goto out;
1079 }
1080
1081 memcpy(cmd->bssid, bss_conf->bssid, ETH_ALEN);
1082
1083 cmd->aging_period = cpu_to_le16(WL1271_AP_DEF_INACTIV_SEC);
1084 cmd->bss_index = WL1271_AP_BSS_INDEX;
1085 cmd->global_hlid = WL1271_AP_GLOBAL_HLID;
1086 cmd->broadcast_hlid = WL1271_AP_BROADCAST_HLID;
1087 cmd->basic_rate_set = cpu_to_le32(wl->basic_rate_set);
1088 cmd->beacon_interval = cpu_to_le16(wl->beacon_int);
1089 cmd->dtim_interval = bss_conf->dtim_period;
1090 cmd->beacon_expiry = WL1271_AP_DEF_BEACON_EXP;
1091 cmd->channel = wl->channel;
1092 cmd->ssid_len = wl->ssid_len;
1093 cmd->ssid_type = SSID_TYPE_PUBLIC;
1094 memcpy(cmd->ssid, wl->ssid, wl->ssid_len);
1095
1096 switch (wl->band) {
1097 case IEEE80211_BAND_2GHZ:
1098 cmd->band = RADIO_BAND_2_4GHZ;
1099 break;
1100 case IEEE80211_BAND_5GHZ:
1101 cmd->band = RADIO_BAND_5GHZ;
1102 break;
1103 default:
1104 wl1271_warning("bss start - unknown band: %d", (int)wl->band);
1105 cmd->band = RADIO_BAND_2_4GHZ;
1106 break;
1107 }
1108
1109 ret = wl1271_cmd_send(wl, CMD_BSS_START, cmd, sizeof(*cmd), 0);
1110 if (ret < 0) {
1111 wl1271_error("failed to initiate cmd start bss");
1112 goto out_free;
1113 }
1114
1115out_free:
1116 kfree(cmd);
1117
1118out:
1119 return ret;
1120}
1121
1122int wl1271_cmd_stop_bss(struct wl1271 *wl)
1123{
1124 struct wl1271_cmd_bss_start *cmd;
1125 int ret;
1126
1127 wl1271_debug(DEBUG_CMD, "cmd stop bss");
1128
1129 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1130 if (!cmd) {
1131 ret = -ENOMEM;
1132 goto out;
1133 }
1134
1135 cmd->bss_index = WL1271_AP_BSS_INDEX;
1136
1137 ret = wl1271_cmd_send(wl, CMD_BSS_STOP, cmd, sizeof(*cmd), 0);
1138 if (ret < 0) {
1139 wl1271_error("failed to initiate cmd stop bss");
1140 goto out_free;
1141 }
1142
1143out_free:
1144 kfree(cmd);
1145
1146out:
1147 return ret;
1148}
1149
1150int wl1271_cmd_add_sta(struct wl1271 *wl, struct ieee80211_sta *sta, u8 hlid)
1151{
1152 struct wl1271_cmd_add_sta *cmd;
1153 int ret;
1154
1155 wl1271_debug(DEBUG_CMD, "cmd add sta %d", (int)hlid);
1156
1157 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1158 if (!cmd) {
1159 ret = -ENOMEM;
1160 goto out;
1161 }
1162
1163 /* currently we don't support UAPSD */
1164 cmd->sp_len = 0;
1165
1166 memcpy(cmd->addr, sta->addr, ETH_ALEN);
1167 cmd->bss_index = WL1271_AP_BSS_INDEX;
1168 cmd->aid = sta->aid;
1169 cmd->hlid = hlid;
1170
1171 /*
1172 * FIXME: Does STA support QOS? We need to propagate this info from
1173 * hostapd. Currently not that important since this is only used for
1174 * sending the correct flavor of null-data packet in response to a
1175 * trigger.
1176 */
1177 cmd->wmm = 0;
1178
1179 cmd->supported_rates = cpu_to_le32(wl1271_tx_enabled_rates_get(wl,
1180 sta->supp_rates[wl->band]));
1181
1182 wl1271_debug(DEBUG_CMD, "new sta rates: 0x%x", cmd->supported_rates);
1183
1184 ret = wl1271_cmd_send(wl, CMD_ADD_STA, cmd, sizeof(*cmd), 0);
1185 if (ret < 0) {
1186 wl1271_error("failed to initiate cmd add sta");
1187 goto out_free;
1188 }
1189
1190out_free:
1191 kfree(cmd);
1192
1193out:
1194 return ret;
1195}
1196
1197int wl1271_cmd_remove_sta(struct wl1271 *wl, u8 hlid)
1198{
1199 struct wl1271_cmd_remove_sta *cmd;
1200 int ret;
1201
1202 wl1271_debug(DEBUG_CMD, "cmd remove sta %d", (int)hlid);
1203
1204 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1205 if (!cmd) {
1206 ret = -ENOMEM;
1207 goto out;
1208 }
1209
1210 cmd->hlid = hlid;
1211 /* We never send a deauth, mac80211 is in charge of this */
1212 cmd->reason_opcode = 0;
1213 cmd->send_deauth_flag = 0;
1214
1215 ret = wl1271_cmd_send(wl, CMD_REMOVE_STA, cmd, sizeof(*cmd), 0);
1216 if (ret < 0) {
1217 wl1271_error("failed to initiate cmd remove sta");
1218 goto out_free;
1219 }
1220
1221 /*
1222 * We are ok with a timeout here. The event is sometimes not sent
1223 * due to a firmware bug.
1224 */
1225 wl1271_cmd_wait_for_event_or_timeout(wl, STA_REMOVE_COMPLETE_EVENT_ID);
1226
1227out_free:
1228 kfree(cmd);
1229
1230out:
1231 return ret;
1232}
diff --git a/drivers/net/wireless/wl12xx/wl1271_cmd.h b/drivers/net/wireless/wl12xx/cmd.h
index af577ee8eb02..5cac95d9480c 100644
--- a/drivers/net/wireless/wl12xx/wl1271_cmd.h
+++ b/drivers/net/wireless/wl12xx/cmd.h
@@ -22,23 +22,26 @@
22 * 22 *
23 */ 23 */
24 24
25#ifndef __WL1271_CMD_H__ 25#ifndef __CMD_H__
26#define __WL1271_CMD_H__ 26#define __CMD_H__
27 27
28#include "wl1271.h" 28#include "wl12xx.h"
29 29
30struct acx_header; 30struct acx_header;
31 31
32int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len, 32int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
33 size_t res_len); 33 size_t res_len);
34int wl1271_cmd_general_parms(struct wl1271 *wl); 34int wl1271_cmd_general_parms(struct wl1271 *wl);
35int wl128x_cmd_general_parms(struct wl1271 *wl);
35int wl1271_cmd_radio_parms(struct wl1271 *wl); 36int wl1271_cmd_radio_parms(struct wl1271 *wl);
37int wl128x_cmd_radio_parms(struct wl1271 *wl);
38int wl1271_cmd_ext_radio_parms(struct wl1271 *wl);
36int wl1271_cmd_join(struct wl1271 *wl, u8 bss_type); 39int wl1271_cmd_join(struct wl1271 *wl, u8 bss_type);
37int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer); 40int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer);
38int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len); 41int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len);
39int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len); 42int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len);
40int wl1271_cmd_data_path(struct wl1271 *wl, bool enable); 43int wl1271_cmd_data_path(struct wl1271 *wl, bool enable);
41int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode, bool send); 44int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode);
42int wl1271_cmd_read_memory(struct wl1271 *wl, u32 addr, void *answer, 45int wl1271_cmd_read_memory(struct wl1271 *wl, u32 addr, void *answer,
43 size_t len); 46 size_t len);
44int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id, 47int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id,
@@ -48,13 +51,25 @@ int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid);
48int wl1271_cmd_build_probe_req(struct wl1271 *wl, 51int wl1271_cmd_build_probe_req(struct wl1271 *wl,
49 const u8 *ssid, size_t ssid_len, 52 const u8 *ssid, size_t ssid_len,
50 const u8 *ie, size_t ie_len, u8 band); 53 const u8 *ie, size_t ie_len, u8 band);
54struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
55 struct sk_buff *skb);
56int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, __be32 ip_addr);
51int wl1271_build_qos_null_data(struct wl1271 *wl); 57int wl1271_build_qos_null_data(struct wl1271 *wl);
52int wl1271_cmd_build_klv_null_data(struct wl1271 *wl); 58int wl1271_cmd_build_klv_null_data(struct wl1271 *wl);
53int wl1271_cmd_set_default_wep_key(struct wl1271 *wl, u8 id); 59int wl1271_cmd_set_sta_default_wep_key(struct wl1271 *wl, u8 id);
54int wl1271_cmd_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type, 60int wl1271_cmd_set_ap_default_wep_key(struct wl1271 *wl, u8 id);
55 u8 key_size, const u8 *key, const u8 *addr, 61int wl1271_cmd_set_sta_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
56 u32 tx_seq_32, u16 tx_seq_16); 62 u8 key_size, const u8 *key, const u8 *addr,
63 u32 tx_seq_32, u16 tx_seq_16);
64int wl1271_cmd_set_ap_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
65 u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
66 u16 tx_seq_16);
57int wl1271_cmd_disconnect(struct wl1271 *wl); 67int wl1271_cmd_disconnect(struct wl1271 *wl);
68int wl1271_cmd_set_sta_state(struct wl1271 *wl);
69int wl1271_cmd_start_bss(struct wl1271 *wl);
70int wl1271_cmd_stop_bss(struct wl1271 *wl);
71int wl1271_cmd_add_sta(struct wl1271 *wl, struct ieee80211_sta *sta, u8 hlid);
72int wl1271_cmd_remove_sta(struct wl1271 *wl, u8 hlid);
58 73
59enum wl1271_commands { 74enum wl1271_commands {
60 CMD_INTERROGATE = 1, /*use this to read information elements*/ 75 CMD_INTERROGATE = 1, /*use this to read information elements*/
@@ -93,6 +108,12 @@ enum wl1271_commands {
93 CMD_STOP_PERIODIC_SCAN = 51, 108 CMD_STOP_PERIODIC_SCAN = 51,
94 CMD_SET_STA_STATE = 52, 109 CMD_SET_STA_STATE = 52,
95 110
111 /* AP mode commands */
112 CMD_BSS_START = 60,
113 CMD_BSS_STOP = 61,
114 CMD_ADD_STA = 62,
115 CMD_REMOVE_STA = 63,
116
96 NUM_COMMANDS, 117 NUM_COMMANDS,
97 MAX_COMMAND_ID = 0xFFFF, 118 MAX_COMMAND_ID = 0xFFFF,
98}; 119};
@@ -120,6 +141,15 @@ enum cmd_templ {
120 CMD_TEMPL_CTS, /* 141 CMD_TEMPL_CTS, /*
121 * For CTS-to-self (FastCTS) mechanism 142 * For CTS-to-self (FastCTS) mechanism
122 * for BT/WLAN coexistence (SoftGemini). */ 143 * for BT/WLAN coexistence (SoftGemini). */
144 CMD_TEMPL_ARP_RSP,
145 CMD_TEMPL_LINK_MEASUREMENT_REPORT,
146
147 /* AP-mode specific */
148 CMD_TEMPL_AP_BEACON = 13,
149 CMD_TEMPL_AP_PROBE_RESPONSE,
150 CMD_TEMPL_AP_ARP_RSP,
151 CMD_TEMPL_DEAUTH_AP,
152
123 CMD_TEMPL_MAX = 0xff 153 CMD_TEMPL_MAX = 0xff
124}; 154};
125 155
@@ -160,41 +190,6 @@ enum {
160 MAX_COMMAND_STATUS = 0xff 190 MAX_COMMAND_STATUS = 0xff
161}; 191};
162 192
163
164/*
165 * CMD_READ_MEMORY
166 *
167 * The host issues this command to read the WiLink device memory/registers.
168 *
169 * Note: The Base Band address has special handling (16 bits registers and
170 * addresses). For more information, see the hardware specification.
171 */
172/*
173 * CMD_WRITE_MEMORY
174 *
175 * The host issues this command to write the WiLink device memory/registers.
176 *
177 * The Base Band address has special handling (16 bits registers and
178 * addresses). For more information, see the hardware specification.
179 */
180#define MAX_READ_SIZE 256
181
182struct cmd_read_write_memory {
183 struct wl1271_cmd_header header;
184
185 /* The address of the memory to read from or write to.*/
186 __le32 addr;
187
188 /* The amount of data in bytes to read from or write to the WiLink
189 * device.*/
190 __le32 size;
191
192 /* The actual value read from or written to the Wilink. The source
193 of this field is the Host in WRITE command or the Wilink in READ
194 command. */
195 u8 value[MAX_READ_SIZE];
196} __packed;
197
198#define CMDMBOX_HEADER_LEN 4 193#define CMDMBOX_HEADER_LEN 4
199#define CMDMBOX_INFO_ELEM_HEADER_LEN 4 194#define CMDMBOX_INFO_ELEM_HEADER_LEN 4
200 195
@@ -224,6 +219,7 @@ struct wl1271_cmd_join {
224 * ACK or CTS frames). 219 * ACK or CTS frames).
225 */ 220 */
226 __le32 basic_rate_set; 221 __le32 basic_rate_set;
222 __le32 supported_rate_set;
227 u8 dtim_interval; 223 u8 dtim_interval;
228 /* 224 /*
229 * bits 0-2: This bitwise field specifies the type 225 * bits 0-2: This bitwise field specifies the type
@@ -286,20 +282,11 @@ struct wl1271_cmd_ps_params {
286 struct wl1271_cmd_header header; 282 struct wl1271_cmd_header header;
287 283
288 u8 ps_mode; /* STATION_* */ 284 u8 ps_mode; /* STATION_* */
289 u8 send_null_data; /* Do we have to send NULL data packet ? */ 285 u8 padding[3];
290 u8 retries; /* Number of retires for the initial NULL data packet */
291
292 /*
293 * TUs during which the target stays awake after switching
294 * to power save mode.
295 */
296 u8 hang_over_period;
297 __le32 null_data_rate;
298} __packed; 286} __packed;
299 287
300/* HW encryption keys */ 288/* HW encryption keys */
301#define NUM_ACCESS_CATEGORIES_COPY 4 289#define NUM_ACCESS_CATEGORIES_COPY 4
302#define MAX_KEY_SIZE 32
303 290
304enum wl1271_cmd_key_action { 291enum wl1271_cmd_key_action {
305 KEY_ADD_OR_REPLACE = 1, 292 KEY_ADD_OR_REPLACE = 1,
@@ -313,12 +300,12 @@ enum wl1271_cmd_key_type {
313 KEY_WEP = 1, 300 KEY_WEP = 1,
314 KEY_TKIP = 2, 301 KEY_TKIP = 2,
315 KEY_AES = 3, 302 KEY_AES = 3,
316 KEY_GEM = 4 303 KEY_GEM = 4,
317}; 304};
318 305
319/* FIXME: Add description for key-types */ 306/* FIXME: Add description for key-types */
320 307
321struct wl1271_cmd_set_keys { 308struct wl1271_cmd_set_sta_keys {
322 struct wl1271_cmd_header header; 309 struct wl1271_cmd_header header;
323 310
324 /* Ignored for default WEP key */ 311 /* Ignored for default WEP key */
@@ -347,6 +334,57 @@ struct wl1271_cmd_set_keys {
347 __le32 ac_seq_num32[NUM_ACCESS_CATEGORIES_COPY]; 334 __le32 ac_seq_num32[NUM_ACCESS_CATEGORIES_COPY];
348} __packed; 335} __packed;
349 336
337enum wl1271_cmd_lid_key_type {
338 UNICAST_LID_TYPE = 0,
339 BROADCAST_LID_TYPE = 1,
340 WEP_DEFAULT_LID_TYPE = 2
341};
342
343struct wl1271_cmd_set_ap_keys {
344 struct wl1271_cmd_header header;
345
346 /*
347 * Indicates whether the HLID is a unicast key set
348 * or broadcast key set. A special value 0xFF is
349 * used to indicate that the HLID is on WEP-default
350 * (multi-hlids). of type wl1271_cmd_lid_key_type.
351 */
352 u8 hlid;
353
354 /*
355 * In WEP-default network (hlid == 0xFF) used to
356 * indicate which network STA/IBSS/AP role should be
357 * changed
358 */
359 u8 lid_key_type;
360
361 /*
362 * Key ID - For TKIP and AES key types, this field
363 * indicates the value that should be inserted into
364 * the KeyID field of frames transmitted using this
365 * key entry. For broadcast keys the index use as a
366 * marker for TX/RX key.
367 * For WEP default network (HLID=0xFF), this field
368 * indicates the ID of the key to add or remove.
369 */
370 u8 key_id;
371 u8 reserved_1;
372
373 /* key_action_e */
374 __le16 key_action;
375
376 /* key size in bytes */
377 u8 key_size;
378
379 /* key_type_e */
380 u8 key_type;
381
382 /* This field holds the security key data to add to the STA table */
383 u8 key[MAX_KEY_SIZE];
384 __le16 ac_seq_num16[NUM_ACCESS_CATEGORIES_COPY];
385 __le32 ac_seq_num32[NUM_ACCESS_CATEGORIES_COPY];
386} __packed;
387
350struct wl1271_cmd_test_header { 388struct wl1271_cmd_test_header {
351 u8 id; 389 u8 id;
352 u8 padding[3]; 390 u8 padding[3];
@@ -358,13 +396,11 @@ enum wl1271_channel_tune_bands {
358 WL1271_CHANNEL_TUNE_BAND_4_9 396 WL1271_CHANNEL_TUNE_BAND_4_9
359}; 397};
360 398
361#define WL1271_PD_REFERENCE_POINT_BAND_B_G 0 399#define WL1271_PD_REFERENCE_POINT_BAND_B_G 0
362 400
363#define TEST_CMD_P2G_CAL 0x02 401#define TEST_CMD_INI_FILE_RADIO_PARAM 0x19
364#define TEST_CMD_CHANNEL_TUNE 0x0d 402#define TEST_CMD_INI_FILE_GENERAL_PARAM 0x1E
365#define TEST_CMD_UPDATE_PD_REFERENCE_POINT 0x1d 403#define TEST_CMD_INI_FILE_RF_EXTENDED_PARAM 0x26
366#define TEST_CMD_INI_FILE_RADIO_PARAM 0x19
367#define TEST_CMD_INI_FILE_GENERAL_PARAM 0x1E
368 404
369struct wl1271_general_parms_cmd { 405struct wl1271_general_parms_cmd {
370 struct wl1271_cmd_header header; 406 struct wl1271_cmd_header header;
@@ -381,6 +417,21 @@ struct wl1271_general_parms_cmd {
381 u8 padding[3]; 417 u8 padding[3];
382} __packed; 418} __packed;
383 419
420struct wl128x_general_parms_cmd {
421 struct wl1271_cmd_header header;
422
423 struct wl1271_cmd_test_header test;
424
425 struct wl128x_ini_general_params general_params;
426
427 u8 sr_debug_table[WL1271_INI_MAX_SMART_REFLEX_PARAM];
428 u8 sr_sen_n_p;
429 u8 sr_sen_n_p_gain;
430 u8 sr_sen_nrn;
431 u8 sr_sen_prn;
432 u8 padding[3];
433} __packed;
434
384struct wl1271_radio_parms_cmd { 435struct wl1271_radio_parms_cmd {
385 struct wl1271_cmd_header header; 436 struct wl1271_cmd_header header;
386 437
@@ -397,51 +448,33 @@ struct wl1271_radio_parms_cmd {
397 u8 padding3[2]; 448 u8 padding3[2];
398} __packed; 449} __packed;
399 450
400struct wl1271_cmd_cal_channel_tune { 451struct wl128x_radio_parms_cmd {
401 struct wl1271_cmd_header header; 452 struct wl1271_cmd_header header;
402 453
403 struct wl1271_cmd_test_header test; 454 struct wl1271_cmd_test_header test;
404 455
405 u8 band; 456 /* Static radio parameters */
406 u8 channel; 457 struct wl128x_ini_band_params_2 static_params_2;
407 458 struct wl128x_ini_band_params_5 static_params_5;
408 __le16 radio_status;
409} __packed;
410
411struct wl1271_cmd_cal_update_ref_point {
412 struct wl1271_cmd_header header;
413 459
414 struct wl1271_cmd_test_header test; 460 u8 fem_vendor_and_options;
415 461
416 __le32 ref_power; 462 /* Dynamic radio parameters */
417 __le32 ref_detector; 463 struct wl128x_ini_fem_params_2 dyn_params_2;
418 u8 sub_band; 464 u8 padding2;
419 u8 padding[3]; 465 struct wl128x_ini_fem_params_5 dyn_params_5;
420} __packed; 466} __packed;
421 467
422#define MAX_TLV_LENGTH 400 468struct wl1271_ext_radio_parms_cmd {
423#define MAX_NVS_VERSION_LENGTH 12
424
425#define WL1271_CAL_P2G_BAND_B_G BIT(0)
426
427struct wl1271_cmd_cal_p2g {
428 struct wl1271_cmd_header header; 469 struct wl1271_cmd_header header;
429 470
430 struct wl1271_cmd_test_header test; 471 struct wl1271_cmd_test_header test;
431 472
432 __le16 len; 473 u8 tx_per_channel_power_compensation_2[CONF_TX_PWR_COMPENSATION_LEN_2];
433 u8 buf[MAX_TLV_LENGTH]; 474 u8 tx_per_channel_power_compensation_5[CONF_TX_PWR_COMPENSATION_LEN_5];
434 u8 type; 475 u8 padding[3];
435 u8 padding;
436
437 __le16 radio_status;
438 u8 nvs_version[MAX_NVS_VERSION_LENGTH];
439
440 u8 sub_band_mask;
441 u8 padding2;
442} __packed; 476} __packed;
443 477
444
445/* 478/*
446 * There are three types of disconnections: 479 * There are three types of disconnections:
447 * 480 *
@@ -469,4 +502,77 @@ struct wl1271_cmd_disconnect {
469 u8 padding; 502 u8 padding;
470} __packed; 503} __packed;
471 504
505#define WL1271_CMD_STA_STATE_CONNECTED 1
506
507struct wl1271_cmd_set_sta_state {
508 struct wl1271_cmd_header header;
509
510 u8 state;
511 u8 padding[3];
512} __packed;
513
514enum wl1271_ssid_type {
515 SSID_TYPE_PUBLIC = 0,
516 SSID_TYPE_HIDDEN = 1
517};
518
519struct wl1271_cmd_bss_start {
520 struct wl1271_cmd_header header;
521
522 /* wl1271_ssid_type */
523 u8 ssid_type;
524 u8 ssid_len;
525 u8 ssid[IW_ESSID_MAX_SIZE];
526 u8 padding_1[2];
527
528 /* Basic rate set */
529 __le32 basic_rate_set;
530 /* Aging period in seconds*/
531 __le16 aging_period;
532
533 /*
534 * This field specifies the time between target beacon
535 * transmission times (TBTTs), in time units (TUs).
536 * Valid values are 1 to 1024.
537 */
538 __le16 beacon_interval;
539 u8 bssid[ETH_ALEN];
540 u8 bss_index;
541 /* Radio band */
542 u8 band;
543 u8 channel;
544 /* The host link id for the AP's global queue */
545 u8 global_hlid;
546 /* The host link id for the AP's broadcast queue */
547 u8 broadcast_hlid;
548 /* DTIM count */
549 u8 dtim_interval;
550 /* Beacon expiry time in ms */
551 u8 beacon_expiry;
552 u8 padding_2[3];
553} __packed;
554
555struct wl1271_cmd_add_sta {
556 struct wl1271_cmd_header header;
557
558 u8 addr[ETH_ALEN];
559 u8 hlid;
560 u8 aid;
561 u8 psd_type[NUM_ACCESS_CATEGORIES_COPY];
562 __le32 supported_rates;
563 u8 bss_index;
564 u8 sp_len;
565 u8 wmm;
566 u8 padding1;
567} __packed;
568
569struct wl1271_cmd_remove_sta {
570 struct wl1271_cmd_header header;
571
572 u8 hlid;
573 u8 reason_opcode;
574 u8 send_deauth_flag;
575 u8 padding1;
576} __packed;
577
472#endif /* __WL1271_CMD_H__ */ 578#endif /* __WL1271_CMD_H__ */
diff --git a/drivers/net/wireless/wl12xx/wl1271_conf.h b/drivers/net/wireless/wl12xx/conf.h
index 0435ffda8f73..c83fefb6662f 100644
--- a/drivers/net/wireless/wl12xx/wl1271_conf.h
+++ b/drivers/net/wireless/wl12xx/conf.h
@@ -21,8 +21,8 @@
21 * 21 *
22 */ 22 */
23 23
24#ifndef __WL1271_CONF_H__ 24#ifndef __CONF_H__
25#define __WL1271_CONF_H__ 25#define __CONF_H__
26 26
27enum { 27enum {
28 CONF_HW_BIT_RATE_1MBPS = BIT(0), 28 CONF_HW_BIT_RATE_1MBPS = BIT(0),
@@ -396,12 +396,43 @@ enum {
396 CONF_SG_TEMP_PARAM_3, 396 CONF_SG_TEMP_PARAM_3,
397 CONF_SG_TEMP_PARAM_4, 397 CONF_SG_TEMP_PARAM_4,
398 CONF_SG_TEMP_PARAM_5, 398 CONF_SG_TEMP_PARAM_5,
399 CONF_SG_PARAMS_MAX, 399
400 /*
401 * AP beacon miss
402 *
403 * Range: 0 - 255
404 */
405 CONF_SG_AP_BEACON_MISS_TX,
406
407 /*
408 * AP RX window length
409 *
410 * Range: 0 - 50
411 */
412 CONF_SG_RX_WINDOW_LENGTH,
413
414 /*
415 * AP connection protection time
416 *
417 * Range: 0 - 5000
418 */
419 CONF_SG_AP_CONNECTION_PROTECTION_TIME,
420
421 CONF_SG_TEMP_PARAM_6,
422 CONF_SG_TEMP_PARAM_7,
423 CONF_SG_TEMP_PARAM_8,
424 CONF_SG_TEMP_PARAM_9,
425 CONF_SG_TEMP_PARAM_10,
426
427 CONF_SG_STA_PARAMS_MAX = CONF_SG_TEMP_PARAM_5 + 1,
428 CONF_SG_AP_PARAMS_MAX = CONF_SG_TEMP_PARAM_10 + 1,
429
400 CONF_SG_PARAMS_ALL = 0xff 430 CONF_SG_PARAMS_ALL = 0xff
401}; 431};
402 432
403struct conf_sg_settings { 433struct conf_sg_settings {
404 u32 params[CONF_SG_PARAMS_MAX]; 434 u32 sta_params[CONF_SG_STA_PARAMS_MAX];
435 u32 ap_params[CONF_SG_AP_PARAMS_MAX];
405 u8 state; 436 u8 state;
406}; 437};
407 438
@@ -496,6 +527,39 @@ struct conf_rx_settings {
496 CONF_HW_BIT_RATE_2MBPS) 527 CONF_HW_BIT_RATE_2MBPS)
497#define CONF_TX_RATE_RETRY_LIMIT 10 528#define CONF_TX_RATE_RETRY_LIMIT 10
498 529
530/*
531 * Rates supported for data packets when operating as AP. Note the absence
532 * of the 22Mbps rate. There is a FW limitation on 12 rates so we must drop
533 * one. The rate dropped is not mandatory under any operating mode.
534 */
535#define CONF_TX_AP_ENABLED_RATES (CONF_HW_BIT_RATE_1MBPS | \
536 CONF_HW_BIT_RATE_2MBPS | CONF_HW_BIT_RATE_5_5MBPS | \
537 CONF_HW_BIT_RATE_6MBPS | CONF_HW_BIT_RATE_9MBPS | \
538 CONF_HW_BIT_RATE_11MBPS | CONF_HW_BIT_RATE_12MBPS | \
539 CONF_HW_BIT_RATE_18MBPS | CONF_HW_BIT_RATE_24MBPS | \
540 CONF_HW_BIT_RATE_36MBPS | CONF_HW_BIT_RATE_48MBPS | \
541 CONF_HW_BIT_RATE_54MBPS)
542
543#define CONF_TX_OFDM_RATES (CONF_HW_BIT_RATE_6MBPS | \
544 CONF_HW_BIT_RATE_12MBPS | CONF_HW_BIT_RATE_24MBPS | \
545 CONF_HW_BIT_RATE_36MBPS | CONF_HW_BIT_RATE_48MBPS | \
546 CONF_HW_BIT_RATE_54MBPS)
547
548
549/*
550 * Default rates for management traffic when operating in AP mode. This
551 * should be configured according to the basic rate set of the AP
552 */
553#define CONF_TX_AP_DEFAULT_MGMT_RATES (CONF_HW_BIT_RATE_1MBPS | \
554 CONF_HW_BIT_RATE_2MBPS | CONF_HW_BIT_RATE_5_5MBPS)
555
556/*
557 * Default rates for working as IBSS. use 11b rates
558 */
559#define CONF_TX_IBSS_DEFAULT_RATES (CONF_HW_BIT_RATE_1MBPS | \
560 CONF_HW_BIT_RATE_2MBPS | CONF_HW_BIT_RATE_5_5MBPS | \
561 CONF_HW_BIT_RATE_11MBPS);
562
499struct conf_tx_rate_class { 563struct conf_tx_rate_class {
500 564
501 /* 565 /*
@@ -552,7 +616,7 @@ enum conf_tx_ac {
552 CONF_TX_AC_BK = 1, /* background */ 616 CONF_TX_AC_BK = 1, /* background */
553 CONF_TX_AC_VI = 2, /* video */ 617 CONF_TX_AC_VI = 2, /* video */
554 CONF_TX_AC_VO = 3, /* voice */ 618 CONF_TX_AC_VO = 3, /* voice */
555 CONF_TX_AC_CTS2SELF = 4, /* fictious AC, follows AC_VO */ 619 CONF_TX_AC_CTS2SELF = 4, /* fictitious AC, follows AC_VO */
556 CONF_TX_AC_ANY_TID = 0x1f 620 CONF_TX_AC_ANY_TID = 0x1f
557}; 621};
558 622
@@ -595,7 +659,7 @@ struct conf_tx_ac_category {
595 u16 tx_op_limit; 659 u16 tx_op_limit;
596}; 660};
597 661
598#define CONF_TX_MAX_TID_COUNT 7 662#define CONF_TX_MAX_TID_COUNT 8
599 663
600enum { 664enum {
601 CONF_CHANNEL_TYPE_DCF = 0, /* DC/LEGACY*/ 665 CONF_CHANNEL_TYPE_DCF = 0, /* DC/LEGACY*/
@@ -636,9 +700,9 @@ struct conf_tx_settings {
636 700
637 /* 701 /*
638 * Configuration for rate classes for TX (currently only one 702 * Configuration for rate classes for TX (currently only one
639 * rate class supported.) 703 * rate class supported). Used in non-AP mode.
640 */ 704 */
641 struct conf_tx_rate_class rc_conf; 705 struct conf_tx_rate_class sta_rc_conf;
642 706
643 /* 707 /*
644 * Configuration for access categories for TX rate control. 708 * Configuration for access categories for TX rate control.
@@ -647,6 +711,12 @@ struct conf_tx_settings {
647 struct conf_tx_ac_category ac_conf[CONF_TX_MAX_AC_COUNT]; 711 struct conf_tx_ac_category ac_conf[CONF_TX_MAX_AC_COUNT];
648 712
649 /* 713 /*
714 * AP-mode - allow this number of TX retries to a station before an
715 * event is triggered from FW.
716 */
717 u16 ap_max_tx_retries;
718
719 /*
650 * Configuration for TID parameters. 720 * Configuration for TID parameters.
651 */ 721 */
652 u8 tid_conf_count; 722 u8 tid_conf_count;
@@ -687,6 +757,12 @@ struct conf_tx_settings {
687 * Range: CONF_HW_BIT_RATE_* bit mask 757 * Range: CONF_HW_BIT_RATE_* bit mask
688 */ 758 */
689 u32 basic_rate_5; 759 u32 basic_rate_5;
760
761 /*
762 * TX retry limits for templates
763 */
764 u8 tmpl_short_retry_limit;
765 u8 tmpl_long_retry_limit;
690}; 766};
691 767
692enum { 768enum {
@@ -912,6 +988,30 @@ struct conf_conn_settings {
912 u8 psm_entry_retries; 988 u8 psm_entry_retries;
913 989
914 /* 990 /*
991 * Specifies the maximum number of times to try PSM exit if it fails
992 * (if sending the appropriate null-func message fails.)
993 *
994 * Range 0 - 255
995 */
996 u8 psm_exit_retries;
997
998 /*
999 * Specifies the maximum number of times to try transmit the PSM entry
1000 * null-func frame for each PSM entry attempt
1001 *
1002 * Range 0 - 255
1003 */
1004 u8 psm_entry_nullfunc_retries;
1005
1006 /*
1007 * Specifies the time to linger in active mode after successfully
1008 * transmitting the PSM entry null-func frame.
1009 *
1010 * Range 0 - 255 TU's
1011 */
1012 u8 psm_entry_hangover_period;
1013
1014 /*
915 * 1015 *
916 * Specifies the interval of the connection keep-alive null-func 1016 * Specifies the interval of the connection keep-alive null-func
917 * frame in ms. 1017 * frame in ms.
@@ -932,7 +1032,9 @@ enum {
932 CONF_REF_CLK_19_2_E, 1032 CONF_REF_CLK_19_2_E,
933 CONF_REF_CLK_26_E, 1033 CONF_REF_CLK_26_E,
934 CONF_REF_CLK_38_4_E, 1034 CONF_REF_CLK_38_4_E,
935 CONF_REF_CLK_52_E 1035 CONF_REF_CLK_52_E,
1036 CONF_REF_CLK_38_4_M_XTAL,
1037 CONF_REF_CLK_26_M_XTAL,
936}; 1038};
937 1039
938enum single_dual_band_enum { 1040enum single_dual_band_enum {
@@ -946,15 +1048,6 @@ enum single_dual_band_enum {
946#define CONF_NUMBER_OF_CHANNELS_2_4 14 1048#define CONF_NUMBER_OF_CHANNELS_2_4 14
947#define CONF_NUMBER_OF_CHANNELS_5 35 1049#define CONF_NUMBER_OF_CHANNELS_5 35
948 1050
949struct conf_radio_parms {
950 /*
951 * FEM parameter set to use
952 *
953 * Range: 0 or 1
954 */
955 u8 fem;
956};
957
958struct conf_itrim_settings { 1051struct conf_itrim_settings {
959 /* enable dco itrim */ 1052 /* enable dco itrim */
960 u8 enable; 1053 u8 enable;
@@ -1016,6 +1109,145 @@ struct conf_roam_trigger_settings {
1016 u8 avg_weight_snr_data; 1109 u8 avg_weight_snr_data;
1017}; 1110};
1018 1111
1112struct conf_scan_settings {
1113 /*
1114 * The minimum time to wait on each channel for active scans
1115 *
1116 * Range: u32 tu/1000
1117 */
1118 u32 min_dwell_time_active;
1119
1120 /*
1121 * The maximum time to wait on each channel for active scans
1122 *
1123 * Range: u32 tu/1000
1124 */
1125 u32 max_dwell_time_active;
1126
1127 /*
1128 * The minimum time to wait on each channel for passive scans
1129 *
1130 * Range: u32 tu/1000
1131 */
1132 u32 min_dwell_time_passive;
1133
1134 /*
1135 * The maximum time to wait on each channel for passive scans
1136 *
1137 * Range: u32 tu/1000
1138 */
1139 u32 max_dwell_time_passive;
1140
1141 /*
1142 * Number of probe requests to transmit on each active scan channel
1143 *
1144 * Range: u8
1145 */
1146 u16 num_probe_reqs;
1147
1148};
1149
1150struct conf_sched_scan_settings {
1151 /* minimum time to wait on the channel for active scans (in TUs) */
1152 u16 min_dwell_time_active;
1153
1154 /* maximum time to wait on the channel for active scans (in TUs) */
1155 u16 max_dwell_time_active;
1156
1157 /* time to wait on the channel for passive scans (in TUs) */
1158 u32 dwell_time_passive;
1159
1160 /* time to wait on the channel for DFS scans (in TUs) */
1161 u32 dwell_time_dfs;
1162
1163 /* number of probe requests to send on each channel in active scans */
1164 u8 num_probe_reqs;
1165
1166 /* RSSI threshold to be used for filtering */
1167 s8 rssi_threshold;
1168
1169 /* SNR threshold to be used for filtering */
1170 s8 snr_threshold;
1171};
1172
1173/* these are number of channels on the band divided by two, rounded up */
1174#define CONF_TX_PWR_COMPENSATION_LEN_2 7
1175#define CONF_TX_PWR_COMPENSATION_LEN_5 18
1176
1177struct conf_rf_settings {
1178 /*
1179 * Per channel power compensation for 2.4GHz
1180 *
1181 * Range: s8
1182 */
1183 u8 tx_per_channel_power_compensation_2[CONF_TX_PWR_COMPENSATION_LEN_2];
1184
1185 /*
1186 * Per channel power compensation for 5GHz
1187 *
1188 * Range: s8
1189 */
1190 u8 tx_per_channel_power_compensation_5[CONF_TX_PWR_COMPENSATION_LEN_5];
1191};
1192
1193struct conf_ht_setting {
1194 u16 tx_ba_win_size;
1195 u16 inactivity_timeout;
1196};
1197
1198struct conf_memory_settings {
1199 /* Number of stations supported in IBSS mode */
1200 u8 num_stations;
1201
1202 /* Number of ssid profiles used in IBSS mode */
1203 u8 ssid_profiles;
1204
1205 /* Number of memory buffers allocated to rx pool */
1206 u8 rx_block_num;
1207
1208 /* Minimum number of blocks allocated to tx pool */
1209 u8 tx_min_block_num;
1210
1211 /* Disable/Enable dynamic memory */
1212 u8 dynamic_memory;
1213
1214 /*
1215 * Minimum required free tx memory blocks in order to assure optimum
1216 * performance
1217 *
1218 * Range: 0-120
1219 */
1220 u8 min_req_tx_blocks;
1221
1222 /*
1223 * Minimum required free rx memory blocks in order to assure optimum
1224 * performance
1225 *
1226 * Range: 0-120
1227 */
1228 u8 min_req_rx_blocks;
1229
1230 /*
1231 * Minimum number of mem blocks (free+used) guaranteed for TX
1232 *
1233 * Range: 0-120
1234 */
1235 u8 tx_min;
1236};
1237
1238struct conf_fm_coex {
1239 u8 enable;
1240 u8 swallow_period;
1241 u8 n_divider_fref_set_1;
1242 u8 n_divider_fref_set_2;
1243 u16 m_divider_fref_set_1;
1244 u16 m_divider_fref_set_2;
1245 u32 coex_pll_stabilization_time;
1246 u16 ldo_stabilization_time;
1247 u8 fm_disturbed_band_margin;
1248 u8 swallow_clk_diff;
1249};
1250
1019struct conf_drv_settings { 1251struct conf_drv_settings {
1020 struct conf_sg_settings sg; 1252 struct conf_sg_settings sg;
1021 struct conf_rx_settings rx; 1253 struct conf_rx_settings rx;
@@ -1024,6 +1256,14 @@ struct conf_drv_settings {
1024 struct conf_itrim_settings itrim; 1256 struct conf_itrim_settings itrim;
1025 struct conf_pm_config_settings pm_config; 1257 struct conf_pm_config_settings pm_config;
1026 struct conf_roam_trigger_settings roam_trigger; 1258 struct conf_roam_trigger_settings roam_trigger;
1259 struct conf_scan_settings scan;
1260 struct conf_sched_scan_settings sched_scan;
1261 struct conf_rf_settings rf;
1262 struct conf_ht_setting ht;
1263 struct conf_memory_settings mem_wl127x;
1264 struct conf_memory_settings mem_wl128x;
1265 struct conf_fm_coex fm_coex;
1266 u8 hci_io_ds;
1027}; 1267};
1028 1268
1029#endif 1269#endif
diff --git a/drivers/net/wireless/wl12xx/debugfs.c b/drivers/net/wireless/wl12xx/debugfs.c
new file mode 100644
index 000000000000..f1f8df9b6cd7
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/debugfs.c
@@ -0,0 +1,709 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 *
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include "debugfs.h"
25
26#include <linux/skbuff.h>
27#include <linux/slab.h>
28
29#include "wl12xx.h"
30#include "acx.h"
31#include "ps.h"
32#include "io.h"
33
34/* ms */
35#define WL1271_DEBUGFS_STATS_LIFETIME 1000
36
37/* debugfs macros idea from mac80211 */
38#define DEBUGFS_FORMAT_BUFFER_SIZE 100
39static int wl1271_format_buffer(char __user *userbuf, size_t count,
40 loff_t *ppos, char *fmt, ...)
41{
42 va_list args;
43 char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
44 int res;
45
46 va_start(args, fmt);
47 res = vscnprintf(buf, sizeof(buf), fmt, args);
48 va_end(args);
49
50 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
51}
52
53#define DEBUGFS_READONLY_FILE(name, fmt, value...) \
54static ssize_t name## _read(struct file *file, char __user *userbuf, \
55 size_t count, loff_t *ppos) \
56{ \
57 struct wl1271 *wl = file->private_data; \
58 return wl1271_format_buffer(userbuf, count, ppos, \
59 fmt "\n", ##value); \
60} \
61 \
62static const struct file_operations name## _ops = { \
63 .read = name## _read, \
64 .open = wl1271_open_file_generic, \
65 .llseek = generic_file_llseek, \
66};
67
68#define DEBUGFS_ADD(name, parent) \
69 entry = debugfs_create_file(#name, 0400, parent, \
70 wl, &name## _ops); \
71 if (!entry || IS_ERR(entry)) \
72 goto err; \
73
74#define DEBUGFS_FWSTATS_FILE(sub, name, fmt) \
75static ssize_t sub## _ ##name## _read(struct file *file, \
76 char __user *userbuf, \
77 size_t count, loff_t *ppos) \
78{ \
79 struct wl1271 *wl = file->private_data; \
80 \
81 wl1271_debugfs_update_stats(wl); \
82 \
83 return wl1271_format_buffer(userbuf, count, ppos, fmt "\n", \
84 wl->stats.fw_stats->sub.name); \
85} \
86 \
87static const struct file_operations sub## _ ##name## _ops = { \
88 .read = sub## _ ##name## _read, \
89 .open = wl1271_open_file_generic, \
90 .llseek = generic_file_llseek, \
91};
92
93#define DEBUGFS_FWSTATS_ADD(sub, name) \
94 DEBUGFS_ADD(sub## _ ##name, stats)
95
96static void wl1271_debugfs_update_stats(struct wl1271 *wl)
97{
98 int ret;
99
100 mutex_lock(&wl->mutex);
101
102 ret = wl1271_ps_elp_wakeup(wl);
103 if (ret < 0)
104 goto out;
105
106 if (wl->state == WL1271_STATE_ON &&
107 time_after(jiffies, wl->stats.fw_stats_update +
108 msecs_to_jiffies(WL1271_DEBUGFS_STATS_LIFETIME))) {
109 wl1271_acx_statistics(wl, wl->stats.fw_stats);
110 wl->stats.fw_stats_update = jiffies;
111 }
112
113 wl1271_ps_elp_sleep(wl);
114
115out:
116 mutex_unlock(&wl->mutex);
117}
118
119static int wl1271_open_file_generic(struct inode *inode, struct file *file)
120{
121 file->private_data = inode->i_private;
122 return 0;
123}
124
125DEBUGFS_FWSTATS_FILE(tx, internal_desc_overflow, "%u");
126
127DEBUGFS_FWSTATS_FILE(rx, out_of_mem, "%u");
128DEBUGFS_FWSTATS_FILE(rx, hdr_overflow, "%u");
129DEBUGFS_FWSTATS_FILE(rx, hw_stuck, "%u");
130DEBUGFS_FWSTATS_FILE(rx, dropped, "%u");
131DEBUGFS_FWSTATS_FILE(rx, fcs_err, "%u");
132DEBUGFS_FWSTATS_FILE(rx, xfr_hint_trig, "%u");
133DEBUGFS_FWSTATS_FILE(rx, path_reset, "%u");
134DEBUGFS_FWSTATS_FILE(rx, reset_counter, "%u");
135
136DEBUGFS_FWSTATS_FILE(dma, rx_requested, "%u");
137DEBUGFS_FWSTATS_FILE(dma, rx_errors, "%u");
138DEBUGFS_FWSTATS_FILE(dma, tx_requested, "%u");
139DEBUGFS_FWSTATS_FILE(dma, tx_errors, "%u");
140
141DEBUGFS_FWSTATS_FILE(isr, cmd_cmplt, "%u");
142DEBUGFS_FWSTATS_FILE(isr, fiqs, "%u");
143DEBUGFS_FWSTATS_FILE(isr, rx_headers, "%u");
144DEBUGFS_FWSTATS_FILE(isr, rx_mem_overflow, "%u");
145DEBUGFS_FWSTATS_FILE(isr, rx_rdys, "%u");
146DEBUGFS_FWSTATS_FILE(isr, irqs, "%u");
147DEBUGFS_FWSTATS_FILE(isr, tx_procs, "%u");
148DEBUGFS_FWSTATS_FILE(isr, decrypt_done, "%u");
149DEBUGFS_FWSTATS_FILE(isr, dma0_done, "%u");
150DEBUGFS_FWSTATS_FILE(isr, dma1_done, "%u");
151DEBUGFS_FWSTATS_FILE(isr, tx_exch_complete, "%u");
152DEBUGFS_FWSTATS_FILE(isr, commands, "%u");
153DEBUGFS_FWSTATS_FILE(isr, rx_procs, "%u");
154DEBUGFS_FWSTATS_FILE(isr, hw_pm_mode_changes, "%u");
155DEBUGFS_FWSTATS_FILE(isr, host_acknowledges, "%u");
156DEBUGFS_FWSTATS_FILE(isr, pci_pm, "%u");
157DEBUGFS_FWSTATS_FILE(isr, wakeups, "%u");
158DEBUGFS_FWSTATS_FILE(isr, low_rssi, "%u");
159
160DEBUGFS_FWSTATS_FILE(wep, addr_key_count, "%u");
161DEBUGFS_FWSTATS_FILE(wep, default_key_count, "%u");
162/* skipping wep.reserved */
163DEBUGFS_FWSTATS_FILE(wep, key_not_found, "%u");
164DEBUGFS_FWSTATS_FILE(wep, decrypt_fail, "%u");
165DEBUGFS_FWSTATS_FILE(wep, packets, "%u");
166DEBUGFS_FWSTATS_FILE(wep, interrupt, "%u");
167
168DEBUGFS_FWSTATS_FILE(pwr, ps_enter, "%u");
169DEBUGFS_FWSTATS_FILE(pwr, elp_enter, "%u");
170DEBUGFS_FWSTATS_FILE(pwr, missing_bcns, "%u");
171DEBUGFS_FWSTATS_FILE(pwr, wake_on_host, "%u");
172DEBUGFS_FWSTATS_FILE(pwr, wake_on_timer_exp, "%u");
173DEBUGFS_FWSTATS_FILE(pwr, tx_with_ps, "%u");
174DEBUGFS_FWSTATS_FILE(pwr, tx_without_ps, "%u");
175DEBUGFS_FWSTATS_FILE(pwr, rcvd_beacons, "%u");
176DEBUGFS_FWSTATS_FILE(pwr, power_save_off, "%u");
177DEBUGFS_FWSTATS_FILE(pwr, enable_ps, "%u");
178DEBUGFS_FWSTATS_FILE(pwr, disable_ps, "%u");
179DEBUGFS_FWSTATS_FILE(pwr, fix_tsf_ps, "%u");
180/* skipping cont_miss_bcns_spread for now */
181DEBUGFS_FWSTATS_FILE(pwr, rcvd_awake_beacons, "%u");
182
183DEBUGFS_FWSTATS_FILE(mic, rx_pkts, "%u");
184DEBUGFS_FWSTATS_FILE(mic, calc_failure, "%u");
185
186DEBUGFS_FWSTATS_FILE(aes, encrypt_fail, "%u");
187DEBUGFS_FWSTATS_FILE(aes, decrypt_fail, "%u");
188DEBUGFS_FWSTATS_FILE(aes, encrypt_packets, "%u");
189DEBUGFS_FWSTATS_FILE(aes, decrypt_packets, "%u");
190DEBUGFS_FWSTATS_FILE(aes, encrypt_interrupt, "%u");
191DEBUGFS_FWSTATS_FILE(aes, decrypt_interrupt, "%u");
192
193DEBUGFS_FWSTATS_FILE(event, heart_beat, "%u");
194DEBUGFS_FWSTATS_FILE(event, calibration, "%u");
195DEBUGFS_FWSTATS_FILE(event, rx_mismatch, "%u");
196DEBUGFS_FWSTATS_FILE(event, rx_mem_empty, "%u");
197DEBUGFS_FWSTATS_FILE(event, rx_pool, "%u");
198DEBUGFS_FWSTATS_FILE(event, oom_late, "%u");
199DEBUGFS_FWSTATS_FILE(event, phy_transmit_error, "%u");
200DEBUGFS_FWSTATS_FILE(event, tx_stuck, "%u");
201
202DEBUGFS_FWSTATS_FILE(ps, pspoll_timeouts, "%u");
203DEBUGFS_FWSTATS_FILE(ps, upsd_timeouts, "%u");
204DEBUGFS_FWSTATS_FILE(ps, upsd_max_sptime, "%u");
205DEBUGFS_FWSTATS_FILE(ps, upsd_max_apturn, "%u");
206DEBUGFS_FWSTATS_FILE(ps, pspoll_max_apturn, "%u");
207DEBUGFS_FWSTATS_FILE(ps, pspoll_utilization, "%u");
208DEBUGFS_FWSTATS_FILE(ps, upsd_utilization, "%u");
209
210DEBUGFS_FWSTATS_FILE(rxpipe, rx_prep_beacon_drop, "%u");
211DEBUGFS_FWSTATS_FILE(rxpipe, descr_host_int_trig_rx_data, "%u");
212DEBUGFS_FWSTATS_FILE(rxpipe, beacon_buffer_thres_host_int_trig_rx_data, "%u");
213DEBUGFS_FWSTATS_FILE(rxpipe, missed_beacon_host_int_trig_rx_data, "%u");
214DEBUGFS_FWSTATS_FILE(rxpipe, tx_xfr_host_int_trig_rx_data, "%u");
215
216DEBUGFS_READONLY_FILE(retry_count, "%u", wl->stats.retry_count);
217DEBUGFS_READONLY_FILE(excessive_retries, "%u",
218 wl->stats.excessive_retries);
219
220static ssize_t tx_queue_len_read(struct file *file, char __user *userbuf,
221 size_t count, loff_t *ppos)
222{
223 struct wl1271 *wl = file->private_data;
224 u32 queue_len;
225 char buf[20];
226 int res;
227
228 queue_len = wl->tx_queue_count;
229
230 res = scnprintf(buf, sizeof(buf), "%u\n", queue_len);
231 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
232}
233
234static const struct file_operations tx_queue_len_ops = {
235 .read = tx_queue_len_read,
236 .open = wl1271_open_file_generic,
237 .llseek = default_llseek,
238};
239
240static ssize_t gpio_power_read(struct file *file, char __user *user_buf,
241 size_t count, loff_t *ppos)
242{
243 struct wl1271 *wl = file->private_data;
244 bool state = test_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
245
246 int res;
247 char buf[10];
248
249 res = scnprintf(buf, sizeof(buf), "%d\n", state);
250
251 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
252}
253
254static ssize_t gpio_power_write(struct file *file,
255 const char __user *user_buf,
256 size_t count, loff_t *ppos)
257{
258 struct wl1271 *wl = file->private_data;
259 char buf[10];
260 size_t len;
261 unsigned long value;
262 int ret;
263
264 len = min(count, sizeof(buf) - 1);
265 if (copy_from_user(buf, user_buf, len)) {
266 return -EFAULT;
267 }
268 buf[len] = '\0';
269
270 ret = kstrtoul(buf, 0, &value);
271 if (ret < 0) {
272 wl1271_warning("illegal value in gpio_power");
273 return -EINVAL;
274 }
275
276 mutex_lock(&wl->mutex);
277
278 if (value)
279 wl1271_power_on(wl);
280 else
281 wl1271_power_off(wl);
282
283 mutex_unlock(&wl->mutex);
284 return count;
285}
286
287static const struct file_operations gpio_power_ops = {
288 .read = gpio_power_read,
289 .write = gpio_power_write,
290 .open = wl1271_open_file_generic,
291 .llseek = default_llseek,
292};
293
294static ssize_t start_recovery_write(struct file *file,
295 const char __user *user_buf,
296 size_t count, loff_t *ppos)
297{
298 struct wl1271 *wl = file->private_data;
299
300 mutex_lock(&wl->mutex);
301 ieee80211_queue_work(wl->hw, &wl->recovery_work);
302 mutex_unlock(&wl->mutex);
303
304 return count;
305}
306
307static const struct file_operations start_recovery_ops = {
308 .write = start_recovery_write,
309 .open = wl1271_open_file_generic,
310 .llseek = default_llseek,
311};
312
313static ssize_t driver_state_read(struct file *file, char __user *user_buf,
314 size_t count, loff_t *ppos)
315{
316 struct wl1271 *wl = file->private_data;
317 int res = 0;
318 char buf[1024];
319
320 mutex_lock(&wl->mutex);
321
322#define DRIVER_STATE_PRINT(x, fmt) \
323 (res += scnprintf(buf + res, sizeof(buf) - res,\
324 #x " = " fmt "\n", wl->x))
325
326#define DRIVER_STATE_PRINT_LONG(x) DRIVER_STATE_PRINT(x, "%ld")
327#define DRIVER_STATE_PRINT_INT(x) DRIVER_STATE_PRINT(x, "%d")
328#define DRIVER_STATE_PRINT_STR(x) DRIVER_STATE_PRINT(x, "%s")
329#define DRIVER_STATE_PRINT_LHEX(x) DRIVER_STATE_PRINT(x, "0x%lx")
330#define DRIVER_STATE_PRINT_HEX(x) DRIVER_STATE_PRINT(x, "0x%x")
331
332 DRIVER_STATE_PRINT_INT(tx_blocks_available);
333 DRIVER_STATE_PRINT_INT(tx_allocated_blocks);
334 DRIVER_STATE_PRINT_INT(tx_frames_cnt);
335 DRIVER_STATE_PRINT_LHEX(tx_frames_map[0]);
336 DRIVER_STATE_PRINT_INT(tx_queue_count);
337 DRIVER_STATE_PRINT_INT(tx_packets_count);
338 DRIVER_STATE_PRINT_INT(tx_results_count);
339 DRIVER_STATE_PRINT_LHEX(flags);
340 DRIVER_STATE_PRINT_INT(tx_blocks_freed[0]);
341 DRIVER_STATE_PRINT_INT(tx_blocks_freed[1]);
342 DRIVER_STATE_PRINT_INT(tx_blocks_freed[2]);
343 DRIVER_STATE_PRINT_INT(tx_blocks_freed[3]);
344 DRIVER_STATE_PRINT_INT(tx_security_last_seq);
345 DRIVER_STATE_PRINT_INT(rx_counter);
346 DRIVER_STATE_PRINT_INT(session_counter);
347 DRIVER_STATE_PRINT_INT(state);
348 DRIVER_STATE_PRINT_INT(bss_type);
349 DRIVER_STATE_PRINT_INT(channel);
350 DRIVER_STATE_PRINT_HEX(rate_set);
351 DRIVER_STATE_PRINT_HEX(basic_rate_set);
352 DRIVER_STATE_PRINT_HEX(basic_rate);
353 DRIVER_STATE_PRINT_INT(band);
354 DRIVER_STATE_PRINT_INT(beacon_int);
355 DRIVER_STATE_PRINT_INT(psm_entry_retry);
356 DRIVER_STATE_PRINT_INT(ps_poll_failures);
357 DRIVER_STATE_PRINT_HEX(filters);
358 DRIVER_STATE_PRINT_HEX(rx_config);
359 DRIVER_STATE_PRINT_HEX(rx_filter);
360 DRIVER_STATE_PRINT_INT(power_level);
361 DRIVER_STATE_PRINT_INT(rssi_thold);
362 DRIVER_STATE_PRINT_INT(last_rssi_event);
363 DRIVER_STATE_PRINT_INT(sg_enabled);
364 DRIVER_STATE_PRINT_INT(enable_11a);
365 DRIVER_STATE_PRINT_INT(noise);
366 DRIVER_STATE_PRINT_LHEX(ap_hlid_map[0]);
367 DRIVER_STATE_PRINT_INT(last_tx_hlid);
368 DRIVER_STATE_PRINT_INT(ba_support);
369 DRIVER_STATE_PRINT_HEX(ba_rx_bitmap);
370 DRIVER_STATE_PRINT_HEX(ap_fw_ps_map);
371 DRIVER_STATE_PRINT_LHEX(ap_ps_map);
372 DRIVER_STATE_PRINT_HEX(quirks);
373 DRIVER_STATE_PRINT_HEX(irq);
374 DRIVER_STATE_PRINT_HEX(ref_clock);
375 DRIVER_STATE_PRINT_HEX(tcxo_clock);
376 DRIVER_STATE_PRINT_HEX(hw_pg_ver);
377 DRIVER_STATE_PRINT_HEX(platform_quirks);
378 DRIVER_STATE_PRINT_HEX(chip.id);
379 DRIVER_STATE_PRINT_STR(chip.fw_ver_str);
380 DRIVER_STATE_PRINT_INT(sched_scanning);
381
382#undef DRIVER_STATE_PRINT_INT
383#undef DRIVER_STATE_PRINT_LONG
384#undef DRIVER_STATE_PRINT_HEX
385#undef DRIVER_STATE_PRINT_LHEX
386#undef DRIVER_STATE_PRINT_STR
387#undef DRIVER_STATE_PRINT
388
389 mutex_unlock(&wl->mutex);
390
391 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
392}
393
394static const struct file_operations driver_state_ops = {
395 .read = driver_state_read,
396 .open = wl1271_open_file_generic,
397 .llseek = default_llseek,
398};
399
400static ssize_t dtim_interval_read(struct file *file, char __user *user_buf,
401 size_t count, loff_t *ppos)
402{
403 struct wl1271 *wl = file->private_data;
404 u8 value;
405
406 if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_DTIM ||
407 wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_DTIM)
408 value = wl->conf.conn.listen_interval;
409 else
410 value = 0;
411
412 return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
413}
414
415static ssize_t dtim_interval_write(struct file *file,
416 const char __user *user_buf,
417 size_t count, loff_t *ppos)
418{
419 struct wl1271 *wl = file->private_data;
420 char buf[10];
421 size_t len;
422 unsigned long value;
423 int ret;
424
425 len = min(count, sizeof(buf) - 1);
426 if (copy_from_user(buf, user_buf, len))
427 return -EFAULT;
428 buf[len] = '\0';
429
430 ret = kstrtoul(buf, 0, &value);
431 if (ret < 0) {
432 wl1271_warning("illegal value for dtim_interval");
433 return -EINVAL;
434 }
435
436 if (value < 1 || value > 10) {
437 wl1271_warning("dtim value is not in valid range");
438 return -ERANGE;
439 }
440
441 mutex_lock(&wl->mutex);
442
443 wl->conf.conn.listen_interval = value;
444 /* for some reason there are different event types for 1 and >1 */
445 if (value == 1)
446 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_DTIM;
447 else
448 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM;
449
450 /*
451 * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
452 * take effect on the next time we enter psm.
453 */
454 mutex_unlock(&wl->mutex);
455 return count;
456}
457
458static const struct file_operations dtim_interval_ops = {
459 .read = dtim_interval_read,
460 .write = dtim_interval_write,
461 .open = wl1271_open_file_generic,
462 .llseek = default_llseek,
463};
464
465static ssize_t beacon_interval_read(struct file *file, char __user *user_buf,
466 size_t count, loff_t *ppos)
467{
468 struct wl1271 *wl = file->private_data;
469 u8 value;
470
471 if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_BEACON ||
472 wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_BEACONS)
473 value = wl->conf.conn.listen_interval;
474 else
475 value = 0;
476
477 return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
478}
479
480static ssize_t beacon_interval_write(struct file *file,
481 const char __user *user_buf,
482 size_t count, loff_t *ppos)
483{
484 struct wl1271 *wl = file->private_data;
485 char buf[10];
486 size_t len;
487 unsigned long value;
488 int ret;
489
490 len = min(count, sizeof(buf) - 1);
491 if (copy_from_user(buf, user_buf, len))
492 return -EFAULT;
493 buf[len] = '\0';
494
495 ret = kstrtoul(buf, 0, &value);
496 if (ret < 0) {
497 wl1271_warning("illegal value for beacon_interval");
498 return -EINVAL;
499 }
500
501 if (value < 1 || value > 255) {
502 wl1271_warning("beacon interval value is not in valid range");
503 return -ERANGE;
504 }
505
506 mutex_lock(&wl->mutex);
507
508 wl->conf.conn.listen_interval = value;
509 /* for some reason there are different event types for 1 and >1 */
510 if (value == 1)
511 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_BEACON;
512 else
513 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_BEACONS;
514
515 /*
516 * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
517 * take effect on the next time we enter psm.
518 */
519 mutex_unlock(&wl->mutex);
520 return count;
521}
522
523static const struct file_operations beacon_interval_ops = {
524 .read = beacon_interval_read,
525 .write = beacon_interval_write,
526 .open = wl1271_open_file_generic,
527 .llseek = default_llseek,
528};
529
530static int wl1271_debugfs_add_files(struct wl1271 *wl,
531 struct dentry *rootdir)
532{
533 int ret = 0;
534 struct dentry *entry, *stats;
535
536 stats = debugfs_create_dir("fw-statistics", rootdir);
537 if (!stats || IS_ERR(stats)) {
538 entry = stats;
539 goto err;
540 }
541
542 DEBUGFS_FWSTATS_ADD(tx, internal_desc_overflow);
543
544 DEBUGFS_FWSTATS_ADD(rx, out_of_mem);
545 DEBUGFS_FWSTATS_ADD(rx, hdr_overflow);
546 DEBUGFS_FWSTATS_ADD(rx, hw_stuck);
547 DEBUGFS_FWSTATS_ADD(rx, dropped);
548 DEBUGFS_FWSTATS_ADD(rx, fcs_err);
549 DEBUGFS_FWSTATS_ADD(rx, xfr_hint_trig);
550 DEBUGFS_FWSTATS_ADD(rx, path_reset);
551 DEBUGFS_FWSTATS_ADD(rx, reset_counter);
552
553 DEBUGFS_FWSTATS_ADD(dma, rx_requested);
554 DEBUGFS_FWSTATS_ADD(dma, rx_errors);
555 DEBUGFS_FWSTATS_ADD(dma, tx_requested);
556 DEBUGFS_FWSTATS_ADD(dma, tx_errors);
557
558 DEBUGFS_FWSTATS_ADD(isr, cmd_cmplt);
559 DEBUGFS_FWSTATS_ADD(isr, fiqs);
560 DEBUGFS_FWSTATS_ADD(isr, rx_headers);
561 DEBUGFS_FWSTATS_ADD(isr, rx_mem_overflow);
562 DEBUGFS_FWSTATS_ADD(isr, rx_rdys);
563 DEBUGFS_FWSTATS_ADD(isr, irqs);
564 DEBUGFS_FWSTATS_ADD(isr, tx_procs);
565 DEBUGFS_FWSTATS_ADD(isr, decrypt_done);
566 DEBUGFS_FWSTATS_ADD(isr, dma0_done);
567 DEBUGFS_FWSTATS_ADD(isr, dma1_done);
568 DEBUGFS_FWSTATS_ADD(isr, tx_exch_complete);
569 DEBUGFS_FWSTATS_ADD(isr, commands);
570 DEBUGFS_FWSTATS_ADD(isr, rx_procs);
571 DEBUGFS_FWSTATS_ADD(isr, hw_pm_mode_changes);
572 DEBUGFS_FWSTATS_ADD(isr, host_acknowledges);
573 DEBUGFS_FWSTATS_ADD(isr, pci_pm);
574 DEBUGFS_FWSTATS_ADD(isr, wakeups);
575 DEBUGFS_FWSTATS_ADD(isr, low_rssi);
576
577 DEBUGFS_FWSTATS_ADD(wep, addr_key_count);
578 DEBUGFS_FWSTATS_ADD(wep, default_key_count);
579 /* skipping wep.reserved */
580 DEBUGFS_FWSTATS_ADD(wep, key_not_found);
581 DEBUGFS_FWSTATS_ADD(wep, decrypt_fail);
582 DEBUGFS_FWSTATS_ADD(wep, packets);
583 DEBUGFS_FWSTATS_ADD(wep, interrupt);
584
585 DEBUGFS_FWSTATS_ADD(pwr, ps_enter);
586 DEBUGFS_FWSTATS_ADD(pwr, elp_enter);
587 DEBUGFS_FWSTATS_ADD(pwr, missing_bcns);
588 DEBUGFS_FWSTATS_ADD(pwr, wake_on_host);
589 DEBUGFS_FWSTATS_ADD(pwr, wake_on_timer_exp);
590 DEBUGFS_FWSTATS_ADD(pwr, tx_with_ps);
591 DEBUGFS_FWSTATS_ADD(pwr, tx_without_ps);
592 DEBUGFS_FWSTATS_ADD(pwr, rcvd_beacons);
593 DEBUGFS_FWSTATS_ADD(pwr, power_save_off);
594 DEBUGFS_FWSTATS_ADD(pwr, enable_ps);
595 DEBUGFS_FWSTATS_ADD(pwr, disable_ps);
596 DEBUGFS_FWSTATS_ADD(pwr, fix_tsf_ps);
597 /* skipping cont_miss_bcns_spread for now */
598 DEBUGFS_FWSTATS_ADD(pwr, rcvd_awake_beacons);
599
600 DEBUGFS_FWSTATS_ADD(mic, rx_pkts);
601 DEBUGFS_FWSTATS_ADD(mic, calc_failure);
602
603 DEBUGFS_FWSTATS_ADD(aes, encrypt_fail);
604 DEBUGFS_FWSTATS_ADD(aes, decrypt_fail);
605 DEBUGFS_FWSTATS_ADD(aes, encrypt_packets);
606 DEBUGFS_FWSTATS_ADD(aes, decrypt_packets);
607 DEBUGFS_FWSTATS_ADD(aes, encrypt_interrupt);
608 DEBUGFS_FWSTATS_ADD(aes, decrypt_interrupt);
609
610 DEBUGFS_FWSTATS_ADD(event, heart_beat);
611 DEBUGFS_FWSTATS_ADD(event, calibration);
612 DEBUGFS_FWSTATS_ADD(event, rx_mismatch);
613 DEBUGFS_FWSTATS_ADD(event, rx_mem_empty);
614 DEBUGFS_FWSTATS_ADD(event, rx_pool);
615 DEBUGFS_FWSTATS_ADD(event, oom_late);
616 DEBUGFS_FWSTATS_ADD(event, phy_transmit_error);
617 DEBUGFS_FWSTATS_ADD(event, tx_stuck);
618
619 DEBUGFS_FWSTATS_ADD(ps, pspoll_timeouts);
620 DEBUGFS_FWSTATS_ADD(ps, upsd_timeouts);
621 DEBUGFS_FWSTATS_ADD(ps, upsd_max_sptime);
622 DEBUGFS_FWSTATS_ADD(ps, upsd_max_apturn);
623 DEBUGFS_FWSTATS_ADD(ps, pspoll_max_apturn);
624 DEBUGFS_FWSTATS_ADD(ps, pspoll_utilization);
625 DEBUGFS_FWSTATS_ADD(ps, upsd_utilization);
626
627 DEBUGFS_FWSTATS_ADD(rxpipe, rx_prep_beacon_drop);
628 DEBUGFS_FWSTATS_ADD(rxpipe, descr_host_int_trig_rx_data);
629 DEBUGFS_FWSTATS_ADD(rxpipe, beacon_buffer_thres_host_int_trig_rx_data);
630 DEBUGFS_FWSTATS_ADD(rxpipe, missed_beacon_host_int_trig_rx_data);
631 DEBUGFS_FWSTATS_ADD(rxpipe, tx_xfr_host_int_trig_rx_data);
632
633 DEBUGFS_ADD(tx_queue_len, rootdir);
634 DEBUGFS_ADD(retry_count, rootdir);
635 DEBUGFS_ADD(excessive_retries, rootdir);
636
637 DEBUGFS_ADD(gpio_power, rootdir);
638 DEBUGFS_ADD(start_recovery, rootdir);
639 DEBUGFS_ADD(driver_state, rootdir);
640 DEBUGFS_ADD(dtim_interval, rootdir);
641 DEBUGFS_ADD(beacon_interval, rootdir);
642
643 return 0;
644
645err:
646 if (IS_ERR(entry))
647 ret = PTR_ERR(entry);
648 else
649 ret = -ENOMEM;
650
651 return ret;
652}
653
654void wl1271_debugfs_reset(struct wl1271 *wl)
655{
656 if (!wl->stats.fw_stats)
657 return;
658
659 memset(wl->stats.fw_stats, 0, sizeof(*wl->stats.fw_stats));
660 wl->stats.retry_count = 0;
661 wl->stats.excessive_retries = 0;
662}
663
664int wl1271_debugfs_init(struct wl1271 *wl)
665{
666 int ret;
667 struct dentry *rootdir;
668
669 rootdir = debugfs_create_dir(KBUILD_MODNAME,
670 wl->hw->wiphy->debugfsdir);
671
672 if (IS_ERR(rootdir)) {
673 ret = PTR_ERR(rootdir);
674 goto err;
675 }
676
677 wl->stats.fw_stats = kzalloc(sizeof(*wl->stats.fw_stats),
678 GFP_KERNEL);
679
680 if (!wl->stats.fw_stats) {
681 ret = -ENOMEM;
682 goto err_fw;
683 }
684
685 wl->stats.fw_stats_update = jiffies;
686
687 ret = wl1271_debugfs_add_files(wl, rootdir);
688
689 if (ret < 0)
690 goto err_file;
691
692 return 0;
693
694err_file:
695 kfree(wl->stats.fw_stats);
696 wl->stats.fw_stats = NULL;
697
698err_fw:
699 debugfs_remove_recursive(rootdir);
700
701err:
702 return ret;
703}
704
705void wl1271_debugfs_exit(struct wl1271 *wl)
706{
707 kfree(wl->stats.fw_stats);
708 wl->stats.fw_stats = NULL;
709}
diff --git a/drivers/net/wireless/wl12xx/wl1271_debugfs.h b/drivers/net/wireless/wl12xx/debugfs.h
index 00a45b2669ad..254c5b292cf6 100644
--- a/drivers/net/wireless/wl12xx/wl1271_debugfs.h
+++ b/drivers/net/wireless/wl12xx/debugfs.h
@@ -21,10 +21,10 @@
21 * 21 *
22 */ 22 */
23 23
24#ifndef WL1271_DEBUGFS_H 24#ifndef __DEBUGFS_H__
25#define WL1271_DEBUGFS_H 25#define __DEBUGFS_H__
26 26
27#include "wl1271.h" 27#include "wl12xx.h"
28 28
29int wl1271_debugfs_init(struct wl1271 *wl); 29int wl1271_debugfs_init(struct wl1271 *wl);
30void wl1271_debugfs_exit(struct wl1271 *wl); 30void wl1271_debugfs_exit(struct wl1271 *wl);
diff --git a/drivers/net/wireless/wl12xx/wl1271_event.c b/drivers/net/wireless/wl12xx/event.c
index 25ce2cd5e3f3..c3c554cd6580 100644
--- a/drivers/net/wireless/wl12xx/wl1271_event.c
+++ b/drivers/net/wireless/wl12xx/event.c
@@ -21,18 +21,19 @@
21 * 21 *
22 */ 22 */
23 23
24#include "wl1271.h" 24#include "wl12xx.h"
25#include "wl1271_reg.h" 25#include "reg.h"
26#include "wl1271_io.h" 26#include "io.h"
27#include "wl1271_event.h" 27#include "event.h"
28#include "wl1271_ps.h" 28#include "ps.h"
29#include "wl1271_scan.h" 29#include "scan.h"
30#include "wl12xx_80211.h" 30#include "wl12xx_80211.h"
31 31
32void wl1271_pspoll_work(struct work_struct *work) 32void wl1271_pspoll_work(struct work_struct *work)
33{ 33{
34 struct delayed_work *dwork; 34 struct delayed_work *dwork;
35 struct wl1271 *wl; 35 struct wl1271 *wl;
36 int ret;
36 37
37 dwork = container_of(work, struct delayed_work, work); 38 dwork = container_of(work, struct delayed_work, work);
38 wl = container_of(dwork, struct wl1271, pspoll_work); 39 wl = container_of(dwork, struct wl1271, pspoll_work);
@@ -41,6 +42,9 @@ void wl1271_pspoll_work(struct work_struct *work)
41 42
42 mutex_lock(&wl->mutex); 43 mutex_lock(&wl->mutex);
43 44
45 if (unlikely(wl->state == WL1271_STATE_OFF))
46 goto out;
47
44 if (!test_and_clear_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags)) 48 if (!test_and_clear_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags))
45 goto out; 49 goto out;
46 50
@@ -52,8 +56,13 @@ void wl1271_pspoll_work(struct work_struct *work)
52 * delivery failure occurred, and no-one changed state since, so 56 * delivery failure occurred, and no-one changed state since, so
53 * we should go back to powersave. 57 * we should go back to powersave.
54 */ 58 */
55 wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE, true); 59 ret = wl1271_ps_elp_wakeup(wl);
60 if (ret < 0)
61 goto out;
62
63 wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE, wl->basic_rate, true);
56 64
65 wl1271_ps_elp_sleep(wl);
57out: 66out:
58 mutex_unlock(&wl->mutex); 67 mutex_unlock(&wl->mutex);
59}; 68};
@@ -70,7 +79,8 @@ static void wl1271_event_pspoll_delivery_fail(struct wl1271 *wl)
70 79
71 /* force active mode receive data from the AP */ 80 /* force active mode receive data from the AP */
72 if (test_bit(WL1271_FLAG_PSM, &wl->flags)) { 81 if (test_bit(WL1271_FLAG_PSM, &wl->flags)) {
73 ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE, true); 82 ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE,
83 wl->basic_rate, true);
74 if (ret < 0) 84 if (ret < 0)
75 return; 85 return;
76 set_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags); 86 set_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags);
@@ -91,6 +101,7 @@ static int wl1271_event_ps_report(struct wl1271 *wl,
91 bool *beacon_loss) 101 bool *beacon_loss)
92{ 102{
93 int ret = 0; 103 int ret = 0;
104 u32 total_retries = wl->conf.conn.psm_entry_retries;
94 105
95 wl1271_debug(DEBUG_EVENT, "ps_status: 0x%x", mbox->ps_status); 106 wl1271_debug(DEBUG_EVENT, "ps_status: 0x%x", mbox->ps_status);
96 107
@@ -104,10 +115,10 @@ static int wl1271_event_ps_report(struct wl1271 *wl,
104 break; 115 break;
105 } 116 }
106 117
107 if (wl->psm_entry_retry < wl->conf.conn.psm_entry_retries) { 118 if (wl->psm_entry_retry < total_retries) {
108 wl->psm_entry_retry++; 119 wl->psm_entry_retry++;
109 ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE, 120 ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE,
110 true); 121 wl->basic_rate, true);
111 } else { 122 } else {
112 wl1271_info("No ack to nullfunc from AP."); 123 wl1271_info("No ack to nullfunc from AP.");
113 wl->psm_entry_retry = 0; 124 wl->psm_entry_retry = 0;
@@ -127,25 +138,11 @@ static int wl1271_event_ps_report(struct wl1271 *wl,
127 if (ret < 0) 138 if (ret < 0)
128 break; 139 break;
129 140
130 /* go to extremely low power mode */ 141 if (wl->ps_compl) {
131 wl1271_ps_elp_sleep(wl); 142 complete(wl->ps_compl);
132 if (ret < 0) 143 wl->ps_compl = NULL;
133 break;
134 break;
135 case EVENT_EXIT_POWER_SAVE_FAIL:
136 wl1271_debug(DEBUG_PSM, "PSM exit failed");
137
138 if (test_bit(WL1271_FLAG_PSM, &wl->flags)) {
139 wl->psm_entry_retry = 0;
140 break;
141 } 144 }
142
143 /* make sure the firmware goes to active mode - the frame to
144 be sent next will indicate to the AP, that we are active. */
145 ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE,
146 false);
147 break; 145 break;
148 case EVENT_EXIT_POWER_SAVE_SUCCESS:
149 default: 146 default:
150 break; 147 break;
151 } 148 }
@@ -183,6 +180,7 @@ static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
183 int ret; 180 int ret;
184 u32 vector; 181 u32 vector;
185 bool beacon_loss = false; 182 bool beacon_loss = false;
183 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
186 184
187 wl1271_event_mbox_dump(mbox); 185 wl1271_event_mbox_dump(mbox);
188 186
@@ -197,6 +195,22 @@ static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
197 wl1271_scan_stm(wl); 195 wl1271_scan_stm(wl);
198 } 196 }
199 197
198 if (vector & PERIODIC_SCAN_REPORT_EVENT_ID) {
199 wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_REPORT_EVENT "
200 "(status 0x%0x)", mbox->scheduled_scan_status);
201
202 wl1271_scan_sched_scan_results(wl);
203 }
204
205 if (vector & PERIODIC_SCAN_COMPLETE_EVENT_ID) {
206 wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_COMPLETE_EVENT "
207 "(status 0x%0x)", mbox->scheduled_scan_status);
208 if (wl->sched_scanning) {
209 wl1271_scan_sched_scan_stop(wl);
210 ieee80211_sched_scan_stopped(wl->hw);
211 }
212 }
213
200 /* disable dynamic PS when requested by the firmware */ 214 /* disable dynamic PS when requested by the firmware */
201 if (vector & SOFT_GEMINI_SENSE_EVENT_ID && 215 if (vector & SOFT_GEMINI_SENSE_EVENT_ID &&
202 wl->bss_type == BSS_TYPE_STA_BSS) { 216 wl->bss_type == BSS_TYPE_STA_BSS) {
@@ -215,21 +229,21 @@ static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
215 * BSS_LOSE_EVENT, beacon loss has to be reported to the stack. 229 * BSS_LOSE_EVENT, beacon loss has to be reported to the stack.
216 * 230 *
217 */ 231 */
218 if (vector & BSS_LOSE_EVENT_ID) { 232 if ((vector & BSS_LOSE_EVENT_ID) && !is_ap) {
219 wl1271_info("Beacon loss detected."); 233 wl1271_info("Beacon loss detected.");
220 234
221 /* indicate to the stack, that beacons have been lost */ 235 /* indicate to the stack, that beacons have been lost */
222 beacon_loss = true; 236 beacon_loss = true;
223 } 237 }
224 238
225 if (vector & PS_REPORT_EVENT_ID) { 239 if ((vector & PS_REPORT_EVENT_ID) && !is_ap) {
226 wl1271_debug(DEBUG_EVENT, "PS_REPORT_EVENT"); 240 wl1271_debug(DEBUG_EVENT, "PS_REPORT_EVENT");
227 ret = wl1271_event_ps_report(wl, mbox, &beacon_loss); 241 ret = wl1271_event_ps_report(wl, mbox, &beacon_loss);
228 if (ret < 0) 242 if (ret < 0)
229 return ret; 243 return ret;
230 } 244 }
231 245
232 if (vector & PSPOLL_DELIVERY_FAILURE_EVENT_ID) 246 if ((vector & PSPOLL_DELIVERY_FAILURE_EVENT_ID) && !is_ap)
233 wl1271_event_pspoll_delivery_fail(wl); 247 wl1271_event_pspoll_delivery_fail(wl);
234 248
235 if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) { 249 if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) {
@@ -238,6 +252,12 @@ static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
238 wl1271_event_rssi_trigger(wl, mbox); 252 wl1271_event_rssi_trigger(wl, mbox);
239 } 253 }
240 254
255 if ((vector & DUMMY_PACKET_EVENT_ID) && !is_ap) {
256 wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID");
257 if (wl->vif)
258 wl1271_tx_dummy_packet(wl);
259 }
260
241 if (wl->vif && beacon_loss) 261 if (wl->vif && beacon_loss)
242 ieee80211_connection_loss(wl->vif); 262 ieee80211_connection_loss(wl->vif);
243 263
diff --git a/drivers/net/wireless/wl12xx/wl1271_event.h b/drivers/net/wireless/wl12xx/event.h
index e4751667cf5e..b6cf06e565a4 100644
--- a/drivers/net/wireless/wl12xx/wl1271_event.h
+++ b/drivers/net/wireless/wl12xx/event.h
@@ -22,8 +22,8 @@
22 * 22 *
23 */ 23 */
24 24
25#ifndef __WL1271_EVENT_H__ 25#ifndef __EVENT_H__
26#define __WL1271_EVENT_H__ 26#define __EVENT_H__
27 27
28/* 28/*
29 * Mbox events 29 * Mbox events
@@ -59,6 +59,10 @@ enum {
59 BSS_LOSE_EVENT_ID = BIT(18), 59 BSS_LOSE_EVENT_ID = BIT(18),
60 REGAINED_BSS_EVENT_ID = BIT(19), 60 REGAINED_BSS_EVENT_ID = BIT(19),
61 ROAMING_TRIGGER_MAX_TX_RETRY_EVENT_ID = BIT(20), 61 ROAMING_TRIGGER_MAX_TX_RETRY_EVENT_ID = BIT(20),
62 /* STA: dummy paket for dynamic mem blocks */
63 DUMMY_PACKET_EVENT_ID = BIT(21),
64 /* AP: STA remove complete */
65 STA_REMOVE_COMPLETE_EVENT_ID = BIT(21),
62 SOFT_GEMINI_SENSE_EVENT_ID = BIT(22), 66 SOFT_GEMINI_SENSE_EVENT_ID = BIT(22),
63 SOFT_GEMINI_PREDICTION_EVENT_ID = BIT(23), 67 SOFT_GEMINI_PREDICTION_EVENT_ID = BIT(23),
64 SOFT_GEMINI_AVALANCHE_EVENT_ID = BIT(24), 68 SOFT_GEMINI_AVALANCHE_EVENT_ID = BIT(24),
@@ -74,8 +78,6 @@ enum {
74enum { 78enum {
75 EVENT_ENTER_POWER_SAVE_FAIL = 0, 79 EVENT_ENTER_POWER_SAVE_FAIL = 0,
76 EVENT_ENTER_POWER_SAVE_SUCCESS, 80 EVENT_ENTER_POWER_SAVE_SUCCESS,
77 EVENT_EXIT_POWER_SAVE_FAIL,
78 EVENT_EXIT_POWER_SAVE_SUCCESS,
79}; 81};
80 82
81struct event_debug_report { 83struct event_debug_report {
@@ -115,7 +117,12 @@ struct event_mailbox {
115 u8 scheduled_scan_status; 117 u8 scheduled_scan_status;
116 u8 ps_status; 118 u8 ps_status;
117 119
118 u8 reserved_5[29]; 120 /* AP FW only */
121 u8 hlid_removed;
122 __le16 sta_aging_status;
123 __le16 sta_tx_retry_exceeded;
124
125 u8 reserved_5[24];
119} __packed; 126} __packed;
120 127
121int wl1271_event_unmask(struct wl1271 *wl); 128int wl1271_event_unmask(struct wl1271 *wl);
diff --git a/drivers/net/wireless/wl12xx/wl1271_ini.h b/drivers/net/wireless/wl12xx/ini.h
index 2313047d4015..1420c842b8f1 100644
--- a/drivers/net/wireless/wl12xx/wl1271_ini.h
+++ b/drivers/net/wireless/wl12xx/ini.h
@@ -21,8 +21,8 @@
21 * 21 *
22 */ 22 */
23 23
24#ifndef __WL1271_INI_H__ 24#ifndef __INI_H__
25#define __WL1271_INI_H__ 25#define __INI_H__
26 26
27#define WL1271_INI_MAX_SMART_REFLEX_PARAM 16 27#define WL1271_INI_MAX_SMART_REFLEX_PARAM 16
28 28
@@ -41,6 +41,28 @@ struct wl1271_ini_general_params {
41 u8 srf3[WL1271_INI_MAX_SMART_REFLEX_PARAM]; 41 u8 srf3[WL1271_INI_MAX_SMART_REFLEX_PARAM];
42} __packed; 42} __packed;
43 43
44#define WL128X_INI_MAX_SETTINGS_PARAM 4
45
46struct wl128x_ini_general_params {
47 u8 ref_clock;
48 u8 settling_time;
49 u8 clk_valid_on_wakeup;
50 u8 tcxo_ref_clock;
51 u8 tcxo_settling_time;
52 u8 tcxo_valid_on_wakeup;
53 u8 tcxo_ldo_voltage;
54 u8 xtal_itrim_val;
55 u8 platform_conf;
56 u8 dual_mode_select;
57 u8 tx_bip_fem_auto_detect;
58 u8 tx_bip_fem_manufacturer;
59 u8 general_settings[WL128X_INI_MAX_SETTINGS_PARAM];
60 u8 sr_state;
61 u8 srf1[WL1271_INI_MAX_SMART_REFLEX_PARAM];
62 u8 srf2[WL1271_INI_MAX_SMART_REFLEX_PARAM];
63 u8 srf3[WL1271_INI_MAX_SMART_REFLEX_PARAM];
64} __packed;
65
44#define WL1271_INI_RSSI_PROCESS_COMPENS_SIZE 15 66#define WL1271_INI_RSSI_PROCESS_COMPENS_SIZE 15
45 67
46struct wl1271_ini_band_params_2 { 68struct wl1271_ini_band_params_2 {
@@ -49,9 +71,16 @@ struct wl1271_ini_band_params_2 {
49 u8 rx_rssi_process_compens[WL1271_INI_RSSI_PROCESS_COMPENS_SIZE]; 71 u8 rx_rssi_process_compens[WL1271_INI_RSSI_PROCESS_COMPENS_SIZE];
50} __packed; 72} __packed;
51 73
52#define WL1271_INI_RATE_GROUP_COUNT 6
53#define WL1271_INI_CHANNEL_COUNT_2 14 74#define WL1271_INI_CHANNEL_COUNT_2 14
54 75
76struct wl128x_ini_band_params_2 {
77 u8 rx_trace_insertion_loss;
78 u8 tx_trace_loss[WL1271_INI_CHANNEL_COUNT_2];
79 u8 rx_rssi_process_compens[WL1271_INI_RSSI_PROCESS_COMPENS_SIZE];
80} __packed;
81
82#define WL1271_INI_RATE_GROUP_COUNT 6
83
55struct wl1271_ini_fem_params_2 { 84struct wl1271_ini_fem_params_2 {
56 __le16 tx_bip_ref_pd_voltage; 85 __le16 tx_bip_ref_pd_voltage;
57 u8 tx_bip_ref_power; 86 u8 tx_bip_ref_power;
@@ -68,6 +97,28 @@ struct wl1271_ini_fem_params_2 {
68 u8 normal_to_degraded_high_thr; 97 u8 normal_to_degraded_high_thr;
69} __packed; 98} __packed;
70 99
100#define WL128X_INI_RATE_GROUP_COUNT 7
101/* low and high temperatures */
102#define WL128X_INI_PD_VS_TEMPERATURE_RANGES 2
103
104struct wl128x_ini_fem_params_2 {
105 __le16 tx_bip_ref_pd_voltage;
106 u8 tx_bip_ref_power;
107 u8 tx_bip_ref_offset;
108 u8 tx_per_rate_pwr_limits_normal[WL128X_INI_RATE_GROUP_COUNT];
109 u8 tx_per_rate_pwr_limits_degraded[WL128X_INI_RATE_GROUP_COUNT];
110 u8 tx_per_rate_pwr_limits_extreme[WL128X_INI_RATE_GROUP_COUNT];
111 u8 tx_per_chan_pwr_limits_11b[WL1271_INI_CHANNEL_COUNT_2];
112 u8 tx_per_chan_pwr_limits_ofdm[WL1271_INI_CHANNEL_COUNT_2];
113 u8 tx_pd_vs_rate_offsets[WL128X_INI_RATE_GROUP_COUNT];
114 u8 tx_ibias[WL128X_INI_RATE_GROUP_COUNT + 1];
115 u8 tx_pd_vs_chan_offsets[WL1271_INI_CHANNEL_COUNT_2];
116 u8 tx_pd_vs_temperature[WL128X_INI_PD_VS_TEMPERATURE_RANGES];
117 u8 rx_fem_insertion_loss;
118 u8 degraded_low_to_normal_thr;
119 u8 normal_to_degraded_high_thr;
120} __packed;
121
71#define WL1271_INI_CHANNEL_COUNT_5 35 122#define WL1271_INI_CHANNEL_COUNT_5 35
72#define WL1271_INI_SUB_BAND_COUNT_5 7 123#define WL1271_INI_SUB_BAND_COUNT_5 7
73 124
@@ -77,6 +128,12 @@ struct wl1271_ini_band_params_5 {
77 u8 rx_rssi_process_compens[WL1271_INI_RSSI_PROCESS_COMPENS_SIZE]; 128 u8 rx_rssi_process_compens[WL1271_INI_RSSI_PROCESS_COMPENS_SIZE];
78} __packed; 129} __packed;
79 130
131struct wl128x_ini_band_params_5 {
132 u8 rx_trace_insertion_loss[WL1271_INI_SUB_BAND_COUNT_5];
133 u8 tx_trace_loss[WL1271_INI_CHANNEL_COUNT_5];
134 u8 rx_rssi_process_compens[WL1271_INI_RSSI_PROCESS_COMPENS_SIZE];
135} __packed;
136
80struct wl1271_ini_fem_params_5 { 137struct wl1271_ini_fem_params_5 {
81 __le16 tx_bip_ref_pd_voltage[WL1271_INI_SUB_BAND_COUNT_5]; 138 __le16 tx_bip_ref_pd_voltage[WL1271_INI_SUB_BAND_COUNT_5];
82 u8 tx_bip_ref_power[WL1271_INI_SUB_BAND_COUNT_5]; 139 u8 tx_bip_ref_power[WL1271_INI_SUB_BAND_COUNT_5];
@@ -92,6 +149,23 @@ struct wl1271_ini_fem_params_5 {
92 u8 normal_to_degraded_high_thr; 149 u8 normal_to_degraded_high_thr;
93} __packed; 150} __packed;
94 151
152struct wl128x_ini_fem_params_5 {
153 __le16 tx_bip_ref_pd_voltage[WL1271_INI_SUB_BAND_COUNT_5];
154 u8 tx_bip_ref_power[WL1271_INI_SUB_BAND_COUNT_5];
155 u8 tx_bip_ref_offset[WL1271_INI_SUB_BAND_COUNT_5];
156 u8 tx_per_rate_pwr_limits_normal[WL128X_INI_RATE_GROUP_COUNT];
157 u8 tx_per_rate_pwr_limits_degraded[WL128X_INI_RATE_GROUP_COUNT];
158 u8 tx_per_rate_pwr_limits_extreme[WL128X_INI_RATE_GROUP_COUNT];
159 u8 tx_per_chan_pwr_limits_ofdm[WL1271_INI_CHANNEL_COUNT_5];
160 u8 tx_pd_vs_rate_offsets[WL128X_INI_RATE_GROUP_COUNT];
161 u8 tx_ibias[WL128X_INI_RATE_GROUP_COUNT];
162 u8 tx_pd_vs_chan_offsets[WL1271_INI_CHANNEL_COUNT_5];
163 u8 tx_pd_vs_temperature[WL1271_INI_SUB_BAND_COUNT_5 *
164 WL128X_INI_PD_VS_TEMPERATURE_RANGES];
165 u8 rx_fem_insertion_loss[WL1271_INI_SUB_BAND_COUNT_5];
166 u8 degraded_low_to_normal_thr;
167 u8 normal_to_degraded_high_thr;
168} __packed;
95 169
96/* NVS data structure */ 170/* NVS data structure */
97#define WL1271_INI_NVS_SECTION_SIZE 468 171#define WL1271_INI_NVS_SECTION_SIZE 468
@@ -100,7 +174,7 @@ struct wl1271_ini_fem_params_5 {
100#define WL1271_INI_LEGACY_NVS_FILE_SIZE 800 174#define WL1271_INI_LEGACY_NVS_FILE_SIZE 800
101 175
102struct wl1271_nvs_file { 176struct wl1271_nvs_file {
103 /* NVS section */ 177 /* NVS section - must be first! */
104 u8 nvs[WL1271_INI_NVS_SECTION_SIZE]; 178 u8 nvs[WL1271_INI_NVS_SECTION_SIZE];
105 179
106 /* INI section */ 180 /* INI section */
@@ -120,4 +194,24 @@ struct wl1271_nvs_file {
120 } dyn_radio_params_5[WL1271_INI_FEM_MODULE_COUNT]; 194 } dyn_radio_params_5[WL1271_INI_FEM_MODULE_COUNT];
121} __packed; 195} __packed;
122 196
197struct wl128x_nvs_file {
198 /* NVS section - must be first! */
199 u8 nvs[WL1271_INI_NVS_SECTION_SIZE];
200
201 /* INI section */
202 struct wl128x_ini_general_params general_params;
203 u8 fem_vendor_and_options;
204 struct wl128x_ini_band_params_2 stat_radio_params_2;
205 u8 padding2;
206 struct {
207 struct wl128x_ini_fem_params_2 params;
208 u8 padding;
209 } dyn_radio_params_2[WL1271_INI_FEM_MODULE_COUNT];
210 struct wl128x_ini_band_params_5 stat_radio_params_5;
211 u8 padding3;
212 struct {
213 struct wl128x_ini_fem_params_5 params;
214 u8 padding;
215 } dyn_radio_params_5[WL1271_INI_FEM_MODULE_COUNT];
216} __packed;
123#endif 217#endif
diff --git a/drivers/net/wireless/wl12xx/init.c b/drivers/net/wireless/wl12xx/init.c
new file mode 100644
index 000000000000..a8f4f156c055
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/init.c
@@ -0,0 +1,723 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 *
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include <linux/kernel.h>
25#include <linux/module.h>
26#include <linux/slab.h>
27
28#include "init.h"
29#include "wl12xx_80211.h"
30#include "acx.h"
31#include "cmd.h"
32#include "reg.h"
33#include "tx.h"
34#include "io.h"
35
36int wl1271_sta_init_templates_config(struct wl1271 *wl)
37{
38 int ret, i;
39
40 /* send empty templates for fw memory reservation */
41 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, NULL,
42 WL1271_CMD_TEMPL_MAX_SIZE,
43 0, WL1271_RATE_AUTOMATIC);
44 if (ret < 0)
45 return ret;
46
47 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
48 NULL, WL1271_CMD_TEMPL_MAX_SIZE, 0,
49 WL1271_RATE_AUTOMATIC);
50 if (ret < 0)
51 return ret;
52
53 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
54 sizeof(struct wl12xx_null_data_template),
55 0, WL1271_RATE_AUTOMATIC);
56 if (ret < 0)
57 return ret;
58
59 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, NULL,
60 sizeof(struct wl12xx_ps_poll_template),
61 0, WL1271_RATE_AUTOMATIC);
62 if (ret < 0)
63 return ret;
64
65 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
66 sizeof
67 (struct wl12xx_qos_null_data_template),
68 0, WL1271_RATE_AUTOMATIC);
69 if (ret < 0)
70 return ret;
71
72 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE, NULL,
73 sizeof
74 (struct wl12xx_probe_resp_template),
75 0, WL1271_RATE_AUTOMATIC);
76 if (ret < 0)
77 return ret;
78
79 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON, NULL,
80 sizeof
81 (struct wl12xx_beacon_template),
82 0, WL1271_RATE_AUTOMATIC);
83 if (ret < 0)
84 return ret;
85
86 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_ARP_RSP, NULL,
87 sizeof
88 (struct wl12xx_arp_rsp_template),
89 0, WL1271_RATE_AUTOMATIC);
90 if (ret < 0)
91 return ret;
92
93 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
94 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV, NULL,
95 WL1271_CMD_TEMPL_MAX_SIZE, i,
96 WL1271_RATE_AUTOMATIC);
97 if (ret < 0)
98 return ret;
99 }
100
101 return 0;
102}
103
104static int wl1271_ap_init_deauth_template(struct wl1271 *wl)
105{
106 struct wl12xx_disconn_template *tmpl;
107 int ret;
108
109 tmpl = kzalloc(sizeof(*tmpl), GFP_KERNEL);
110 if (!tmpl) {
111 ret = -ENOMEM;
112 goto out;
113 }
114
115 tmpl->header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT |
116 IEEE80211_STYPE_DEAUTH);
117
118 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP,
119 tmpl, sizeof(*tmpl), 0,
120 wl1271_tx_min_rate_get(wl));
121
122out:
123 kfree(tmpl);
124 return ret;
125}
126
127static int wl1271_ap_init_null_template(struct wl1271 *wl)
128{
129 struct ieee80211_hdr_3addr *nullfunc;
130 int ret;
131
132 nullfunc = kzalloc(sizeof(*nullfunc), GFP_KERNEL);
133 if (!nullfunc) {
134 ret = -ENOMEM;
135 goto out;
136 }
137
138 nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
139 IEEE80211_STYPE_NULLFUNC |
140 IEEE80211_FCTL_FROMDS);
141
142 /* nullfunc->addr1 is filled by FW */
143
144 memcpy(nullfunc->addr2, wl->mac_addr, ETH_ALEN);
145 memcpy(nullfunc->addr3, wl->mac_addr, ETH_ALEN);
146
147 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, nullfunc,
148 sizeof(*nullfunc), 0,
149 wl1271_tx_min_rate_get(wl));
150
151out:
152 kfree(nullfunc);
153 return ret;
154}
155
156static int wl1271_ap_init_qos_null_template(struct wl1271 *wl)
157{
158 struct ieee80211_qos_hdr *qosnull;
159 int ret;
160
161 qosnull = kzalloc(sizeof(*qosnull), GFP_KERNEL);
162 if (!qosnull) {
163 ret = -ENOMEM;
164 goto out;
165 }
166
167 qosnull->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
168 IEEE80211_STYPE_QOS_NULLFUNC |
169 IEEE80211_FCTL_FROMDS);
170
171 /* qosnull->addr1 is filled by FW */
172
173 memcpy(qosnull->addr2, wl->mac_addr, ETH_ALEN);
174 memcpy(qosnull->addr3, wl->mac_addr, ETH_ALEN);
175
176 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, qosnull,
177 sizeof(*qosnull), 0,
178 wl1271_tx_min_rate_get(wl));
179
180out:
181 kfree(qosnull);
182 return ret;
183}
184
185static int wl1271_ap_init_templates_config(struct wl1271 *wl)
186{
187 int ret;
188
189 /*
190 * Put very large empty placeholders for all templates. These
191 * reserve memory for later.
192 */
193 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_PROBE_RESPONSE, NULL,
194 sizeof
195 (struct wl12xx_probe_resp_template),
196 0, WL1271_RATE_AUTOMATIC);
197 if (ret < 0)
198 return ret;
199
200 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_BEACON, NULL,
201 sizeof
202 (struct wl12xx_beacon_template),
203 0, WL1271_RATE_AUTOMATIC);
204 if (ret < 0)
205 return ret;
206
207 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP, NULL,
208 sizeof
209 (struct wl12xx_disconn_template),
210 0, WL1271_RATE_AUTOMATIC);
211 if (ret < 0)
212 return ret;
213
214 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
215 sizeof(struct wl12xx_null_data_template),
216 0, WL1271_RATE_AUTOMATIC);
217 if (ret < 0)
218 return ret;
219
220 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
221 sizeof
222 (struct wl12xx_qos_null_data_template),
223 0, WL1271_RATE_AUTOMATIC);
224 if (ret < 0)
225 return ret;
226
227 return 0;
228}
229
230static int wl1271_init_rx_config(struct wl1271 *wl, u32 config, u32 filter)
231{
232 int ret;
233
234 ret = wl1271_acx_rx_msdu_life_time(wl);
235 if (ret < 0)
236 return ret;
237
238 ret = wl1271_acx_rx_config(wl, config, filter);
239 if (ret < 0)
240 return ret;
241
242 return 0;
243}
244
245int wl1271_init_phy_config(struct wl1271 *wl)
246{
247 int ret;
248
249 ret = wl1271_acx_pd_threshold(wl);
250 if (ret < 0)
251 return ret;
252
253 ret = wl1271_acx_slot(wl, DEFAULT_SLOT_TIME);
254 if (ret < 0)
255 return ret;
256
257 ret = wl1271_acx_service_period_timeout(wl);
258 if (ret < 0)
259 return ret;
260
261 ret = wl1271_acx_rts_threshold(wl, wl->hw->wiphy->rts_threshold);
262 if (ret < 0)
263 return ret;
264
265 return 0;
266}
267
268static int wl1271_init_beacon_filter(struct wl1271 *wl)
269{
270 int ret;
271
272 /* disable beacon filtering at this stage */
273 ret = wl1271_acx_beacon_filter_opt(wl, false);
274 if (ret < 0)
275 return ret;
276
277 ret = wl1271_acx_beacon_filter_table(wl);
278 if (ret < 0)
279 return ret;
280
281 return 0;
282}
283
284int wl1271_init_pta(struct wl1271 *wl)
285{
286 int ret;
287
288 if (wl->bss_type == BSS_TYPE_AP_BSS)
289 ret = wl1271_acx_ap_sg_cfg(wl);
290 else
291 ret = wl1271_acx_sta_sg_cfg(wl);
292 if (ret < 0)
293 return ret;
294
295 ret = wl1271_acx_sg_enable(wl, wl->sg_enabled);
296 if (ret < 0)
297 return ret;
298
299 return 0;
300}
301
302int wl1271_init_energy_detection(struct wl1271 *wl)
303{
304 int ret;
305
306 ret = wl1271_acx_cca_threshold(wl);
307 if (ret < 0)
308 return ret;
309
310 return 0;
311}
312
313static int wl1271_init_beacon_broadcast(struct wl1271 *wl)
314{
315 int ret;
316
317 ret = wl1271_acx_bcn_dtim_options(wl);
318 if (ret < 0)
319 return ret;
320
321 return 0;
322}
323
324static int wl1271_sta_hw_init(struct wl1271 *wl)
325{
326 int ret;
327
328 if (wl->chip.id != CHIP_ID_1283_PG20) {
329 ret = wl1271_cmd_ext_radio_parms(wl);
330 if (ret < 0)
331 return ret;
332 }
333
334 /* PS config */
335 ret = wl1271_acx_config_ps(wl);
336 if (ret < 0)
337 return ret;
338
339 ret = wl1271_sta_init_templates_config(wl);
340 if (ret < 0)
341 return ret;
342
343 ret = wl1271_acx_group_address_tbl(wl, true, NULL, 0);
344 if (ret < 0)
345 return ret;
346
347 /* Initialize connection monitoring thresholds */
348 ret = wl1271_acx_conn_monit_params(wl, false);
349 if (ret < 0)
350 return ret;
351
352 /* Beacon filtering */
353 ret = wl1271_init_beacon_filter(wl);
354 if (ret < 0)
355 return ret;
356
357 /* FM WLAN coexistence */
358 ret = wl1271_acx_fm_coex(wl);
359 if (ret < 0)
360 return ret;
361
362 /* Beacons and broadcast settings */
363 ret = wl1271_init_beacon_broadcast(wl);
364 if (ret < 0)
365 return ret;
366
367 /* Configure for ELP power saving */
368 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
369 if (ret < 0)
370 return ret;
371
372 /* Configure rssi/snr averaging weights */
373 ret = wl1271_acx_rssi_snr_avg_weights(wl);
374 if (ret < 0)
375 return ret;
376
377 ret = wl1271_acx_sta_rate_policies(wl);
378 if (ret < 0)
379 return ret;
380
381 ret = wl1271_acx_sta_mem_cfg(wl);
382 if (ret < 0)
383 return ret;
384
385 return 0;
386}
387
388static int wl1271_sta_hw_init_post_mem(struct wl1271 *wl)
389{
390 int ret, i;
391
392 ret = wl1271_cmd_set_sta_default_wep_key(wl, wl->default_key);
393 if (ret < 0) {
394 wl1271_warning("couldn't set default key");
395 return ret;
396 }
397
398 /* disable all keep-alive templates */
399 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
400 ret = wl1271_acx_keep_alive_config(wl, i,
401 ACX_KEEP_ALIVE_TPL_INVALID);
402 if (ret < 0)
403 return ret;
404 }
405
406 /* disable the keep-alive feature */
407 ret = wl1271_acx_keep_alive_mode(wl, false);
408 if (ret < 0)
409 return ret;
410
411 return 0;
412}
413
414static int wl1271_ap_hw_init(struct wl1271 *wl)
415{
416 int ret;
417
418 ret = wl1271_ap_init_templates_config(wl);
419 if (ret < 0)
420 return ret;
421
422 /* Configure for power always on */
423 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
424 if (ret < 0)
425 return ret;
426
427 ret = wl1271_init_ap_rates(wl);
428 if (ret < 0)
429 return ret;
430
431 ret = wl1271_acx_max_tx_retry(wl);
432 if (ret < 0)
433 return ret;
434
435 ret = wl1271_acx_ap_mem_cfg(wl);
436 if (ret < 0)
437 return ret;
438
439 return 0;
440}
441
442int wl1271_ap_init_templates(struct wl1271 *wl)
443{
444 int ret;
445
446 ret = wl1271_ap_init_deauth_template(wl);
447 if (ret < 0)
448 return ret;
449
450 ret = wl1271_ap_init_null_template(wl);
451 if (ret < 0)
452 return ret;
453
454 ret = wl1271_ap_init_qos_null_template(wl);
455 if (ret < 0)
456 return ret;
457
458 /*
459 * when operating as AP we want to receive external beacons for
460 * configuring ERP protection.
461 */
462 ret = wl1271_acx_set_ap_beacon_filter(wl, false);
463 if (ret < 0)
464 return ret;
465
466 return 0;
467}
468
469static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl)
470{
471 return wl1271_ap_init_templates(wl);
472}
473
474int wl1271_init_ap_rates(struct wl1271 *wl)
475{
476 int i, ret;
477 struct conf_tx_rate_class rc;
478 u32 supported_rates;
479
480 wl1271_debug(DEBUG_AP, "AP basic rate set: 0x%x", wl->basic_rate_set);
481
482 if (wl->basic_rate_set == 0)
483 return -EINVAL;
484
485 rc.enabled_rates = wl->basic_rate_set;
486 rc.long_retry_limit = 10;
487 rc.short_retry_limit = 10;
488 rc.aflags = 0;
489 ret = wl1271_acx_ap_rate_policy(wl, &rc, ACX_TX_AP_MODE_MGMT_RATE);
490 if (ret < 0)
491 return ret;
492
493 /* use the min basic rate for AP broadcast/multicast */
494 rc.enabled_rates = wl1271_tx_min_rate_get(wl);
495 rc.short_retry_limit = 10;
496 rc.long_retry_limit = 10;
497 rc.aflags = 0;
498 ret = wl1271_acx_ap_rate_policy(wl, &rc, ACX_TX_AP_MODE_BCST_RATE);
499 if (ret < 0)
500 return ret;
501
502 /*
503 * If the basic rates contain OFDM rates, use OFDM only
504 * rates for unicast TX as well. Else use all supported rates.
505 */
506 if ((wl->basic_rate_set & CONF_TX_OFDM_RATES))
507 supported_rates = CONF_TX_OFDM_RATES;
508 else
509 supported_rates = CONF_TX_AP_ENABLED_RATES;
510
511 /* configure unicast TX rate classes */
512 for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
513 rc.enabled_rates = supported_rates;
514 rc.short_retry_limit = 10;
515 rc.long_retry_limit = 10;
516 rc.aflags = 0;
517 ret = wl1271_acx_ap_rate_policy(wl, &rc, i);
518 if (ret < 0)
519 return ret;
520 }
521
522 return 0;
523}
524
525static void wl1271_check_ba_support(struct wl1271 *wl)
526{
527 /* validate FW cose ver x.x.x.50-60.x */
528 if ((wl->chip.fw_ver[3] >= WL12XX_BA_SUPPORT_FW_COST_VER2_START) &&
529 (wl->chip.fw_ver[3] < WL12XX_BA_SUPPORT_FW_COST_VER2_END)) {
530 wl->ba_support = true;
531 return;
532 }
533
534 wl->ba_support = false;
535}
536
537static int wl1271_set_ba_policies(struct wl1271 *wl)
538{
539 u8 tid_index;
540 int ret = 0;
541
542 /* Reset the BA RX indicators */
543 wl->ba_rx_bitmap = 0;
544
545 /* validate that FW support BA */
546 wl1271_check_ba_support(wl);
547
548 if (wl->ba_support)
549 /* 802.11n initiator BA session setting */
550 for (tid_index = 0; tid_index < CONF_TX_MAX_TID_COUNT;
551 ++tid_index) {
552 ret = wl1271_acx_set_ba_session(wl, WLAN_BACK_INITIATOR,
553 tid_index, true);
554 if (ret < 0)
555 break;
556 }
557
558 return ret;
559}
560
561int wl1271_chip_specific_init(struct wl1271 *wl)
562{
563 int ret = 0;
564
565 if (wl->chip.id == CHIP_ID_1283_PG20) {
566 u32 host_cfg_bitmap = HOST_IF_CFG_RX_FIFO_ENABLE;
567
568 if (wl->quirks & WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT)
569 /* Enable SDIO padding */
570 host_cfg_bitmap |= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK;
571
572 /* Must be before wl1271_acx_init_mem_config() */
573 ret = wl1271_acx_host_if_cfg_bitmap(wl, host_cfg_bitmap);
574 if (ret < 0)
575 goto out;
576 }
577out:
578 return ret;
579}
580
581
582int wl1271_hw_init(struct wl1271 *wl)
583{
584 struct conf_tx_ac_category *conf_ac;
585 struct conf_tx_tid *conf_tid;
586 int ret, i;
587 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
588
589 if (wl->chip.id == CHIP_ID_1283_PG20)
590 ret = wl128x_cmd_general_parms(wl);
591 else
592 ret = wl1271_cmd_general_parms(wl);
593 if (ret < 0)
594 return ret;
595
596 if (wl->chip.id == CHIP_ID_1283_PG20)
597 ret = wl128x_cmd_radio_parms(wl);
598 else
599 ret = wl1271_cmd_radio_parms(wl);
600 if (ret < 0)
601 return ret;
602
603 /* Chip-specific init */
604 ret = wl1271_chip_specific_init(wl);
605 if (ret < 0)
606 return ret;
607
608 /* Mode specific init */
609 if (is_ap)
610 ret = wl1271_ap_hw_init(wl);
611 else
612 ret = wl1271_sta_hw_init(wl);
613
614 if (ret < 0)
615 return ret;
616
617 /* Bluetooth WLAN coexistence */
618 ret = wl1271_init_pta(wl);
619 if (ret < 0)
620 return ret;
621
622 /* Default memory configuration */
623 ret = wl1271_acx_init_mem_config(wl);
624 if (ret < 0)
625 return ret;
626
627 /* RX config */
628 ret = wl1271_init_rx_config(wl,
629 RX_CFG_PROMISCUOUS | RX_CFG_TSF,
630 RX_FILTER_OPTION_DEF);
631 /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
632 RX_FILTER_OPTION_FILTER_ALL); */
633 if (ret < 0)
634 goto out_free_memmap;
635
636 /* PHY layer config */
637 ret = wl1271_init_phy_config(wl);
638 if (ret < 0)
639 goto out_free_memmap;
640
641 ret = wl1271_acx_dco_itrim_params(wl);
642 if (ret < 0)
643 goto out_free_memmap;
644
645 /* Configure TX patch complete interrupt behavior */
646 ret = wl1271_acx_tx_config_options(wl);
647 if (ret < 0)
648 goto out_free_memmap;
649
650 /* RX complete interrupt pacing */
651 ret = wl1271_acx_init_rx_interrupt(wl);
652 if (ret < 0)
653 goto out_free_memmap;
654
655 /* Energy detection */
656 ret = wl1271_init_energy_detection(wl);
657 if (ret < 0)
658 goto out_free_memmap;
659
660 /* Default fragmentation threshold */
661 ret = wl1271_acx_frag_threshold(wl, wl->hw->wiphy->frag_threshold);
662 if (ret < 0)
663 goto out_free_memmap;
664
665 /* Default TID/AC configuration */
666 BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
667 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
668 conf_ac = &wl->conf.tx.ac_conf[i];
669 ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
670 conf_ac->cw_max, conf_ac->aifsn,
671 conf_ac->tx_op_limit);
672 if (ret < 0)
673 goto out_free_memmap;
674
675 conf_tid = &wl->conf.tx.tid_conf[i];
676 ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id,
677 conf_tid->channel_type,
678 conf_tid->tsid,
679 conf_tid->ps_scheme,
680 conf_tid->ack_policy,
681 conf_tid->apsd_conf[0],
682 conf_tid->apsd_conf[1]);
683 if (ret < 0)
684 goto out_free_memmap;
685 }
686
687 /* Enable data path */
688 ret = wl1271_cmd_data_path(wl, 1);
689 if (ret < 0)
690 goto out_free_memmap;
691
692 /* Configure HW encryption */
693 ret = wl1271_acx_feature_cfg(wl);
694 if (ret < 0)
695 goto out_free_memmap;
696
697 /* configure PM */
698 ret = wl1271_acx_pm_config(wl);
699 if (ret < 0)
700 goto out_free_memmap;
701
702 /* Mode specific init - post mem init */
703 if (is_ap)
704 ret = wl1271_ap_hw_init_post_mem(wl);
705 else
706 ret = wl1271_sta_hw_init_post_mem(wl);
707
708 if (ret < 0)
709 goto out_free_memmap;
710
711 /* Configure initiator BA sessions policies */
712 ret = wl1271_set_ba_policies(wl);
713 if (ret < 0)
714 goto out_free_memmap;
715
716 return 0;
717
718 out_free_memmap:
719 kfree(wl->target_mem_map);
720 wl->target_mem_map = NULL;
721
722 return ret;
723}
diff --git a/drivers/net/wireless/wl12xx/wl1271_init.h b/drivers/net/wireless/wl12xx/init.h
index bc26f8c53b91..3a3c230fd292 100644
--- a/drivers/net/wireless/wl12xx/wl1271_init.h
+++ b/drivers/net/wireless/wl12xx/init.h
@@ -21,16 +21,19 @@
21 * 21 *
22 */ 22 */
23 23
24#ifndef __WL1271_INIT_H__ 24#ifndef __INIT_H__
25#define __WL1271_INIT_H__ 25#define __INIT_H__
26 26
27#include "wl1271.h" 27#include "wl12xx.h"
28 28
29int wl1271_hw_init_power_auth(struct wl1271 *wl); 29int wl1271_hw_init_power_auth(struct wl1271 *wl);
30int wl1271_init_templates_config(struct wl1271 *wl); 30int wl1271_sta_init_templates_config(struct wl1271 *wl);
31int wl1271_init_phy_config(struct wl1271 *wl); 31int wl1271_init_phy_config(struct wl1271 *wl);
32int wl1271_init_pta(struct wl1271 *wl); 32int wl1271_init_pta(struct wl1271 *wl);
33int wl1271_init_energy_detection(struct wl1271 *wl); 33int wl1271_init_energy_detection(struct wl1271 *wl);
34int wl1271_chip_specific_init(struct wl1271 *wl);
34int wl1271_hw_init(struct wl1271 *wl); 35int wl1271_hw_init(struct wl1271 *wl);
36int wl1271_init_ap_rates(struct wl1271 *wl);
37int wl1271_ap_init_templates(struct wl1271 *wl);
35 38
36#endif 39#endif
diff --git a/drivers/net/wireless/wl12xx/wl1271_io.c b/drivers/net/wireless/wl12xx/io.c
index c8759acef131..da5c1ad942a4 100644
--- a/drivers/net/wireless/wl12xx/wl1271_io.c
+++ b/drivers/net/wireless/wl12xx/io.c
@@ -26,9 +26,10 @@
26#include <linux/crc7.h> 26#include <linux/crc7.h>
27#include <linux/spi/spi.h> 27#include <linux/spi/spi.h>
28 28
29#include "wl1271.h" 29#include "wl12xx.h"
30#include "wl12xx_80211.h" 30#include "wl12xx_80211.h"
31#include "wl1271_io.h" 31#include "io.h"
32#include "tx.h"
32 33
33#define OCP_CMD_LOOP 32 34#define OCP_CMD_LOOP 32
34 35
@@ -43,6 +44,16 @@
43#define OCP_STATUS_REQ_FAILED 0x20000 44#define OCP_STATUS_REQ_FAILED 0x20000
44#define OCP_STATUS_RESP_ERROR 0x30000 45#define OCP_STATUS_RESP_ERROR 0x30000
45 46
47bool wl1271_set_block_size(struct wl1271 *wl)
48{
49 if (wl->if_ops->set_block_size) {
50 wl->if_ops->set_block_size(wl, WL12XX_BUS_BLOCK_SIZE);
51 return true;
52 }
53
54 return false;
55}
56
46void wl1271_disable_interrupts(struct wl1271 *wl) 57void wl1271_disable_interrupts(struct wl1271 *wl)
47{ 58{
48 wl->if_ops->disable_irq(wl); 59 wl->if_ops->disable_irq(wl);
@@ -113,6 +124,7 @@ int wl1271_set_partition(struct wl1271 *wl,
113 124
114 return 0; 125 return 0;
115} 126}
127EXPORT_SYMBOL_GPL(wl1271_set_partition);
116 128
117void wl1271_io_reset(struct wl1271 *wl) 129void wl1271_io_reset(struct wl1271 *wl)
118{ 130{
diff --git a/drivers/net/wireless/wl12xx/wl1271_io.h b/drivers/net/wireless/wl12xx/io.h
index bc806c74c63a..beed621a8ae0 100644
--- a/drivers/net/wireless/wl12xx/wl1271_io.h
+++ b/drivers/net/wireless/wl12xx/io.h
@@ -22,10 +22,10 @@
22 * 22 *
23 */ 23 */
24 24
25#ifndef __WL1271_IO_H__ 25#ifndef __IO_H__
26#define __WL1271_IO_H__ 26#define __IO_H__
27 27
28#include "wl1271_reg.h" 28#include "reg.h"
29 29
30#define HW_ACCESS_MEMORY_MAX_RANGE 0x1FFC0 30#define HW_ACCESS_MEMORY_MAX_RANGE 0x1FFC0
31 31
@@ -94,7 +94,7 @@ static inline int wl1271_translate_addr(struct wl1271 *wl, int addr)
94 * translated region. 94 * translated region.
95 * 95 *
96 * The translated regions occur next to each other in physical device 96 * The translated regions occur next to each other in physical device
97 * memory, so just add the sizes of the preceeding address regions to 97 * memory, so just add the sizes of the preceding address regions to
98 * get the offset to the new region. 98 * get the offset to the new region.
99 * 99 *
100 * Currently, only the two first regions are addressed, and the 100 * Currently, only the two first regions are addressed, and the
@@ -144,10 +144,13 @@ static inline void wl1271_power_off(struct wl1271 *wl)
144 clear_bit(WL1271_FLAG_GPIO_POWER, &wl->flags); 144 clear_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
145} 145}
146 146
147static inline void wl1271_power_on(struct wl1271 *wl) 147static inline int wl1271_power_on(struct wl1271 *wl)
148{ 148{
149 wl->if_ops->power(wl, true); 149 int ret = wl->if_ops->power(wl, true);
150 set_bit(WL1271_FLAG_GPIO_POWER, &wl->flags); 150 if (ret == 0)
151 set_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
152
153 return ret;
151} 154}
152 155
153 156
@@ -165,5 +168,9 @@ void wl1271_unregister_hw(struct wl1271 *wl);
165int wl1271_init_ieee80211(struct wl1271 *wl); 168int wl1271_init_ieee80211(struct wl1271 *wl);
166struct ieee80211_hw *wl1271_alloc_hw(void); 169struct ieee80211_hw *wl1271_alloc_hw(void);
167int wl1271_free_hw(struct wl1271 *wl); 170int wl1271_free_hw(struct wl1271 *wl);
171irqreturn_t wl1271_irq(int irq, void *data);
172bool wl1271_set_block_size(struct wl1271 *wl);
173int wl1271_tx_dummy_packet(struct wl1271 *wl);
174void wl1271_configure_filters(struct wl1271 *wl, unsigned int filters);
168 175
169#endif 176#endif
diff --git a/drivers/net/wireless/wl12xx/main.c b/drivers/net/wireless/wl12xx/main.c
new file mode 100644
index 000000000000..e6497dc669df
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/main.c
@@ -0,0 +1,4095 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2008-2010 Nokia Corporation
5 *
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include <linux/module.h>
25#include <linux/firmware.h>
26#include <linux/delay.h>
27#include <linux/spi/spi.h>
28#include <linux/crc32.h>
29#include <linux/etherdevice.h>
30#include <linux/vmalloc.h>
31#include <linux/platform_device.h>
32#include <linux/slab.h>
33#include <linux/wl12xx.h>
34
35#include "wl12xx.h"
36#include "wl12xx_80211.h"
37#include "reg.h"
38#include "io.h"
39#include "event.h"
40#include "tx.h"
41#include "rx.h"
42#include "ps.h"
43#include "init.h"
44#include "debugfs.h"
45#include "cmd.h"
46#include "boot.h"
47#include "testmode.h"
48#include "scan.h"
49
50#define WL1271_BOOT_RETRIES 3
51
52static struct conf_drv_settings default_conf = {
53 .sg = {
54 .sta_params = {
55 [CONF_SG_BT_PER_THRESHOLD] = 7500,
56 [CONF_SG_HV3_MAX_OVERRIDE] = 0,
57 [CONF_SG_BT_NFS_SAMPLE_INTERVAL] = 400,
58 [CONF_SG_BT_LOAD_RATIO] = 200,
59 [CONF_SG_AUTO_PS_MODE] = 1,
60 [CONF_SG_AUTO_SCAN_PROBE_REQ] = 170,
61 [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_HV3] = 50,
62 [CONF_SG_ANTENNA_CONFIGURATION] = 0,
63 [CONF_SG_BEACON_MISS_PERCENT] = 60,
64 [CONF_SG_RATE_ADAPT_THRESH] = 12,
65 [CONF_SG_RATE_ADAPT_SNR] = 0,
66 [CONF_SG_WLAN_PS_BT_ACL_MASTER_MIN_BR] = 10,
67 [CONF_SG_WLAN_PS_BT_ACL_MASTER_MAX_BR] = 30,
68 [CONF_SG_WLAN_PS_MAX_BT_ACL_MASTER_BR] = 8,
69 [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MIN_BR] = 20,
70 [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MAX_BR] = 50,
71 /* Note: with UPSD, this should be 4 */
72 [CONF_SG_WLAN_PS_MAX_BT_ACL_SLAVE_BR] = 8,
73 [CONF_SG_WLAN_PS_BT_ACL_MASTER_MIN_EDR] = 7,
74 [CONF_SG_WLAN_PS_BT_ACL_MASTER_MAX_EDR] = 25,
75 [CONF_SG_WLAN_PS_MAX_BT_ACL_MASTER_EDR] = 20,
76 /* Note: with UPDS, this should be 15 */
77 [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MIN_EDR] = 8,
78 /* Note: with UPDS, this should be 50 */
79 [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MAX_EDR] = 40,
80 /* Note: with UPDS, this should be 10 */
81 [CONF_SG_WLAN_PS_MAX_BT_ACL_SLAVE_EDR] = 20,
82 [CONF_SG_RXT] = 1200,
83 [CONF_SG_TXT] = 1000,
84 [CONF_SG_ADAPTIVE_RXT_TXT] = 1,
85 [CONF_SG_PS_POLL_TIMEOUT] = 10,
86 [CONF_SG_UPSD_TIMEOUT] = 10,
87 [CONF_SG_WLAN_ACTIVE_BT_ACL_MASTER_MIN_EDR] = 7,
88 [CONF_SG_WLAN_ACTIVE_BT_ACL_MASTER_MAX_EDR] = 15,
89 [CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_MASTER_EDR] = 15,
90 [CONF_SG_WLAN_ACTIVE_BT_ACL_SLAVE_MIN_EDR] = 8,
91 [CONF_SG_WLAN_ACTIVE_BT_ACL_SLAVE_MAX_EDR] = 20,
92 [CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_SLAVE_EDR] = 15,
93 [CONF_SG_WLAN_ACTIVE_BT_ACL_MIN_BR] = 20,
94 [CONF_SG_WLAN_ACTIVE_BT_ACL_MAX_BR] = 50,
95 [CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_BR] = 10,
96 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_HV3] = 200,
97 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP] = 800,
98 [CONF_SG_PASSIVE_SCAN_A2DP_BT_TIME] = 75,
99 [CONF_SG_PASSIVE_SCAN_A2DP_WLAN_TIME] = 15,
100 [CONF_SG_HV3_MAX_SERVED] = 6,
101 [CONF_SG_DHCP_TIME] = 5000,
102 [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_A2DP] = 100,
103 },
104 .ap_params = {
105 [CONF_SG_BT_PER_THRESHOLD] = 7500,
106 [CONF_SG_HV3_MAX_OVERRIDE] = 0,
107 [CONF_SG_BT_NFS_SAMPLE_INTERVAL] = 400,
108 [CONF_SG_BT_LOAD_RATIO] = 50,
109 [CONF_SG_AUTO_PS_MODE] = 1,
110 [CONF_SG_AUTO_SCAN_PROBE_REQ] = 170,
111 [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_HV3] = 50,
112 [CONF_SG_ANTENNA_CONFIGURATION] = 0,
113 [CONF_SG_BEACON_MISS_PERCENT] = 60,
114 [CONF_SG_RATE_ADAPT_THRESH] = 64,
115 [CONF_SG_RATE_ADAPT_SNR] = 1,
116 [CONF_SG_WLAN_PS_BT_ACL_MASTER_MIN_BR] = 10,
117 [CONF_SG_WLAN_PS_BT_ACL_MASTER_MAX_BR] = 25,
118 [CONF_SG_WLAN_PS_MAX_BT_ACL_MASTER_BR] = 25,
119 [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MIN_BR] = 20,
120 [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MAX_BR] = 25,
121 [CONF_SG_WLAN_PS_MAX_BT_ACL_SLAVE_BR] = 25,
122 [CONF_SG_WLAN_PS_BT_ACL_MASTER_MIN_EDR] = 7,
123 [CONF_SG_WLAN_PS_BT_ACL_MASTER_MAX_EDR] = 25,
124 [CONF_SG_WLAN_PS_MAX_BT_ACL_MASTER_EDR] = 25,
125 [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MIN_EDR] = 8,
126 [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MAX_EDR] = 25,
127 [CONF_SG_WLAN_PS_MAX_BT_ACL_SLAVE_EDR] = 25,
128 [CONF_SG_RXT] = 1200,
129 [CONF_SG_TXT] = 1000,
130 [CONF_SG_ADAPTIVE_RXT_TXT] = 1,
131 [CONF_SG_PS_POLL_TIMEOUT] = 10,
132 [CONF_SG_UPSD_TIMEOUT] = 10,
133 [CONF_SG_WLAN_ACTIVE_BT_ACL_MASTER_MIN_EDR] = 7,
134 [CONF_SG_WLAN_ACTIVE_BT_ACL_MASTER_MAX_EDR] = 15,
135 [CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_MASTER_EDR] = 15,
136 [CONF_SG_WLAN_ACTIVE_BT_ACL_SLAVE_MIN_EDR] = 8,
137 [CONF_SG_WLAN_ACTIVE_BT_ACL_SLAVE_MAX_EDR] = 20,
138 [CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_SLAVE_EDR] = 15,
139 [CONF_SG_WLAN_ACTIVE_BT_ACL_MIN_BR] = 20,
140 [CONF_SG_WLAN_ACTIVE_BT_ACL_MAX_BR] = 50,
141 [CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_BR] = 10,
142 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_HV3] = 200,
143 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP] = 800,
144 [CONF_SG_PASSIVE_SCAN_A2DP_BT_TIME] = 75,
145 [CONF_SG_PASSIVE_SCAN_A2DP_WLAN_TIME] = 15,
146 [CONF_SG_HV3_MAX_SERVED] = 6,
147 [CONF_SG_DHCP_TIME] = 5000,
148 [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_A2DP] = 100,
149 [CONF_SG_TEMP_PARAM_1] = 0,
150 [CONF_SG_TEMP_PARAM_2] = 0,
151 [CONF_SG_TEMP_PARAM_3] = 0,
152 [CONF_SG_TEMP_PARAM_4] = 0,
153 [CONF_SG_TEMP_PARAM_5] = 0,
154 [CONF_SG_AP_BEACON_MISS_TX] = 3,
155 [CONF_SG_RX_WINDOW_LENGTH] = 6,
156 [CONF_SG_AP_CONNECTION_PROTECTION_TIME] = 50,
157 [CONF_SG_TEMP_PARAM_6] = 1,
158 },
159 .state = CONF_SG_PROTECTIVE,
160 },
161 .rx = {
162 .rx_msdu_life_time = 512000,
163 .packet_detection_threshold = 0,
164 .ps_poll_timeout = 15,
165 .upsd_timeout = 15,
166 .rts_threshold = IEEE80211_MAX_RTS_THRESHOLD,
167 .rx_cca_threshold = 0,
168 .irq_blk_threshold = 0xFFFF,
169 .irq_pkt_threshold = 0,
170 .irq_timeout = 600,
171 .queue_type = CONF_RX_QUEUE_TYPE_LOW_PRIORITY,
172 },
173 .tx = {
174 .tx_energy_detection = 0,
175 .sta_rc_conf = {
176 .enabled_rates = 0,
177 .short_retry_limit = 10,
178 .long_retry_limit = 10,
179 .aflags = 0,
180 },
181 .ac_conf_count = 4,
182 .ac_conf = {
183 [CONF_TX_AC_BE] = {
184 .ac = CONF_TX_AC_BE,
185 .cw_min = 15,
186 .cw_max = 63,
187 .aifsn = 3,
188 .tx_op_limit = 0,
189 },
190 [CONF_TX_AC_BK] = {
191 .ac = CONF_TX_AC_BK,
192 .cw_min = 15,
193 .cw_max = 63,
194 .aifsn = 7,
195 .tx_op_limit = 0,
196 },
197 [CONF_TX_AC_VI] = {
198 .ac = CONF_TX_AC_VI,
199 .cw_min = 15,
200 .cw_max = 63,
201 .aifsn = CONF_TX_AIFS_PIFS,
202 .tx_op_limit = 3008,
203 },
204 [CONF_TX_AC_VO] = {
205 .ac = CONF_TX_AC_VO,
206 .cw_min = 15,
207 .cw_max = 63,
208 .aifsn = CONF_TX_AIFS_PIFS,
209 .tx_op_limit = 1504,
210 },
211 },
212 .ap_max_tx_retries = 100,
213 .tid_conf_count = 4,
214 .tid_conf = {
215 [CONF_TX_AC_BE] = {
216 .queue_id = CONF_TX_AC_BE,
217 .channel_type = CONF_CHANNEL_TYPE_EDCF,
218 .tsid = CONF_TX_AC_BE,
219 .ps_scheme = CONF_PS_SCHEME_LEGACY,
220 .ack_policy = CONF_ACK_POLICY_LEGACY,
221 .apsd_conf = {0, 0},
222 },
223 [CONF_TX_AC_BK] = {
224 .queue_id = CONF_TX_AC_BK,
225 .channel_type = CONF_CHANNEL_TYPE_EDCF,
226 .tsid = CONF_TX_AC_BK,
227 .ps_scheme = CONF_PS_SCHEME_LEGACY,
228 .ack_policy = CONF_ACK_POLICY_LEGACY,
229 .apsd_conf = {0, 0},
230 },
231 [CONF_TX_AC_VI] = {
232 .queue_id = CONF_TX_AC_VI,
233 .channel_type = CONF_CHANNEL_TYPE_EDCF,
234 .tsid = CONF_TX_AC_VI,
235 .ps_scheme = CONF_PS_SCHEME_LEGACY,
236 .ack_policy = CONF_ACK_POLICY_LEGACY,
237 .apsd_conf = {0, 0},
238 },
239 [CONF_TX_AC_VO] = {
240 .queue_id = CONF_TX_AC_VO,
241 .channel_type = CONF_CHANNEL_TYPE_EDCF,
242 .tsid = CONF_TX_AC_VO,
243 .ps_scheme = CONF_PS_SCHEME_LEGACY,
244 .ack_policy = CONF_ACK_POLICY_LEGACY,
245 .apsd_conf = {0, 0},
246 },
247 },
248 .frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD,
249 .tx_compl_timeout = 700,
250 .tx_compl_threshold = 4,
251 .basic_rate = CONF_HW_BIT_RATE_1MBPS,
252 .basic_rate_5 = CONF_HW_BIT_RATE_6MBPS,
253 .tmpl_short_retry_limit = 10,
254 .tmpl_long_retry_limit = 10,
255 },
256 .conn = {
257 .wake_up_event = CONF_WAKE_UP_EVENT_DTIM,
258 .listen_interval = 1,
259 .bcn_filt_mode = CONF_BCN_FILT_MODE_ENABLED,
260 .bcn_filt_ie_count = 2,
261 .bcn_filt_ie = {
262 [0] = {
263 .ie = WLAN_EID_CHANNEL_SWITCH,
264 .rule = CONF_BCN_RULE_PASS_ON_APPEARANCE,
265 },
266 [1] = {
267 .ie = WLAN_EID_HT_INFORMATION,
268 .rule = CONF_BCN_RULE_PASS_ON_CHANGE,
269 },
270 },
271 .synch_fail_thold = 10,
272 .bss_lose_timeout = 100,
273 .beacon_rx_timeout = 10000,
274 .broadcast_timeout = 20000,
275 .rx_broadcast_in_ps = 1,
276 .ps_poll_threshold = 10,
277 .ps_poll_recovery_period = 700,
278 .bet_enable = CONF_BET_MODE_ENABLE,
279 .bet_max_consecutive = 50,
280 .psm_entry_retries = 5,
281 .psm_exit_retries = 16,
282 .psm_entry_nullfunc_retries = 3,
283 .psm_entry_hangover_period = 1,
284 .keep_alive_interval = 55000,
285 .max_listen_interval = 20,
286 },
287 .itrim = {
288 .enable = false,
289 .timeout = 50000,
290 },
291 .pm_config = {
292 .host_clk_settling_time = 5000,
293 .host_fast_wakeup_support = false
294 },
295 .roam_trigger = {
296 .trigger_pacing = 1,
297 .avg_weight_rssi_beacon = 20,
298 .avg_weight_rssi_data = 10,
299 .avg_weight_snr_beacon = 20,
300 .avg_weight_snr_data = 10,
301 },
302 .scan = {
303 .min_dwell_time_active = 7500,
304 .max_dwell_time_active = 30000,
305 .min_dwell_time_passive = 100000,
306 .max_dwell_time_passive = 100000,
307 .num_probe_reqs = 2,
308 },
309 .sched_scan = {
310 /* sched_scan requires dwell times in TU instead of TU/1000 */
311 .min_dwell_time_active = 8,
312 .max_dwell_time_active = 30,
313 .dwell_time_passive = 100,
314 .dwell_time_dfs = 150,
315 .num_probe_reqs = 2,
316 .rssi_threshold = -90,
317 .snr_threshold = 0,
318 },
319 .rf = {
320 .tx_per_channel_power_compensation_2 = {
321 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
322 },
323 .tx_per_channel_power_compensation_5 = {
324 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
325 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
326 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
327 },
328 },
329 .ht = {
330 .tx_ba_win_size = 64,
331 .inactivity_timeout = 10000,
332 },
333 .mem_wl127x = {
334 .num_stations = 1,
335 .ssid_profiles = 1,
336 .rx_block_num = 70,
337 .tx_min_block_num = 40,
338 .dynamic_memory = 1,
339 .min_req_tx_blocks = 100,
340 .min_req_rx_blocks = 22,
341 .tx_min = 27,
342 },
343 .mem_wl128x = {
344 .num_stations = 1,
345 .ssid_profiles = 1,
346 .rx_block_num = 40,
347 .tx_min_block_num = 40,
348 .dynamic_memory = 1,
349 .min_req_tx_blocks = 45,
350 .min_req_rx_blocks = 22,
351 .tx_min = 27,
352 },
353 .fm_coex = {
354 .enable = true,
355 .swallow_period = 5,
356 .n_divider_fref_set_1 = 0xff, /* default */
357 .n_divider_fref_set_2 = 12,
358 .m_divider_fref_set_1 = 148,
359 .m_divider_fref_set_2 = 0xffff, /* default */
360 .coex_pll_stabilization_time = 0xffffffff, /* default */
361 .ldo_stabilization_time = 0xffff, /* default */
362 .fm_disturbed_band_margin = 0xff, /* default */
363 .swallow_clk_diff = 0xff, /* default */
364 },
365 .hci_io_ds = HCI_IO_DS_6MA,
366};
367
368static void __wl1271_op_remove_interface(struct wl1271 *wl,
369 bool reset_tx_queues);
370static void wl1271_free_ap_keys(struct wl1271 *wl);
371
372
373static void wl1271_device_release(struct device *dev)
374{
375
376}
377
378static struct platform_device wl1271_device = {
379 .name = "wl1271",
380 .id = -1,
381
382 /* device model insists to have a release function */
383 .dev = {
384 .release = wl1271_device_release,
385 },
386};
387
388static DEFINE_MUTEX(wl_list_mutex);
389static LIST_HEAD(wl_list);
390
391static int wl1271_dev_notify(struct notifier_block *me, unsigned long what,
392 void *arg)
393{
394 struct net_device *dev = arg;
395 struct wireless_dev *wdev;
396 struct wiphy *wiphy;
397 struct ieee80211_hw *hw;
398 struct wl1271 *wl;
399 struct wl1271 *wl_temp;
400 int ret = 0;
401
402 /* Check that this notification is for us. */
403 if (what != NETDEV_CHANGE)
404 return NOTIFY_DONE;
405
406 wdev = dev->ieee80211_ptr;
407 if (wdev == NULL)
408 return NOTIFY_DONE;
409
410 wiphy = wdev->wiphy;
411 if (wiphy == NULL)
412 return NOTIFY_DONE;
413
414 hw = wiphy_priv(wiphy);
415 if (hw == NULL)
416 return NOTIFY_DONE;
417
418 wl_temp = hw->priv;
419 mutex_lock(&wl_list_mutex);
420 list_for_each_entry(wl, &wl_list, list) {
421 if (wl == wl_temp)
422 break;
423 }
424 mutex_unlock(&wl_list_mutex);
425 if (wl != wl_temp)
426 return NOTIFY_DONE;
427
428 mutex_lock(&wl->mutex);
429
430 if (wl->state == WL1271_STATE_OFF)
431 goto out;
432
433 if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags))
434 goto out;
435
436 ret = wl1271_ps_elp_wakeup(wl);
437 if (ret < 0)
438 goto out;
439
440 if ((dev->operstate == IF_OPER_UP) &&
441 !test_and_set_bit(WL1271_FLAG_STA_STATE_SENT, &wl->flags)) {
442 wl1271_cmd_set_sta_state(wl);
443 wl1271_info("Association completed.");
444 }
445
446 wl1271_ps_elp_sleep(wl);
447
448out:
449 mutex_unlock(&wl->mutex);
450
451 return NOTIFY_OK;
452}
453
454static int wl1271_reg_notify(struct wiphy *wiphy,
455 struct regulatory_request *request)
456{
457 struct ieee80211_supported_band *band;
458 struct ieee80211_channel *ch;
459 int i;
460
461 band = wiphy->bands[IEEE80211_BAND_5GHZ];
462 for (i = 0; i < band->n_channels; i++) {
463 ch = &band->channels[i];
464 if (ch->flags & IEEE80211_CHAN_DISABLED)
465 continue;
466
467 if (ch->flags & IEEE80211_CHAN_RADAR)
468 ch->flags |= IEEE80211_CHAN_NO_IBSS |
469 IEEE80211_CHAN_PASSIVE_SCAN;
470
471 }
472
473 return 0;
474}
475
476static void wl1271_conf_init(struct wl1271 *wl)
477{
478
479 /*
480 * This function applies the default configuration to the driver. This
481 * function is invoked upon driver load (spi probe.)
482 *
483 * The configuration is stored in a run-time structure in order to
484 * facilitate for run-time adjustment of any of the parameters. Making
485 * changes to the configuration structure will apply the new values on
486 * the next interface up (wl1271_op_start.)
487 */
488
489 /* apply driver default configuration */
490 memcpy(&wl->conf, &default_conf, sizeof(default_conf));
491}
492
493
494static int wl1271_plt_init(struct wl1271 *wl)
495{
496 struct conf_tx_ac_category *conf_ac;
497 struct conf_tx_tid *conf_tid;
498 int ret, i;
499
500 if (wl->chip.id == CHIP_ID_1283_PG20)
501 ret = wl128x_cmd_general_parms(wl);
502 else
503 ret = wl1271_cmd_general_parms(wl);
504 if (ret < 0)
505 return ret;
506
507 if (wl->chip.id == CHIP_ID_1283_PG20)
508 ret = wl128x_cmd_radio_parms(wl);
509 else
510 ret = wl1271_cmd_radio_parms(wl);
511 if (ret < 0)
512 return ret;
513
514 if (wl->chip.id != CHIP_ID_1283_PG20) {
515 ret = wl1271_cmd_ext_radio_parms(wl);
516 if (ret < 0)
517 return ret;
518 }
519 if (ret < 0)
520 return ret;
521
522 /* Chip-specific initializations */
523 ret = wl1271_chip_specific_init(wl);
524 if (ret < 0)
525 return ret;
526
527 ret = wl1271_sta_init_templates_config(wl);
528 if (ret < 0)
529 return ret;
530
531 ret = wl1271_acx_init_mem_config(wl);
532 if (ret < 0)
533 return ret;
534
535 /* PHY layer config */
536 ret = wl1271_init_phy_config(wl);
537 if (ret < 0)
538 goto out_free_memmap;
539
540 ret = wl1271_acx_dco_itrim_params(wl);
541 if (ret < 0)
542 goto out_free_memmap;
543
544 /* Initialize connection monitoring thresholds */
545 ret = wl1271_acx_conn_monit_params(wl, false);
546 if (ret < 0)
547 goto out_free_memmap;
548
549 /* Bluetooth WLAN coexistence */
550 ret = wl1271_init_pta(wl);
551 if (ret < 0)
552 goto out_free_memmap;
553
554 /* FM WLAN coexistence */
555 ret = wl1271_acx_fm_coex(wl);
556 if (ret < 0)
557 goto out_free_memmap;
558
559 /* Energy detection */
560 ret = wl1271_init_energy_detection(wl);
561 if (ret < 0)
562 goto out_free_memmap;
563
564 ret = wl1271_acx_sta_mem_cfg(wl);
565 if (ret < 0)
566 goto out_free_memmap;
567
568 /* Default fragmentation threshold */
569 ret = wl1271_acx_frag_threshold(wl, wl->conf.tx.frag_threshold);
570 if (ret < 0)
571 goto out_free_memmap;
572
573 /* Default TID/AC configuration */
574 BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
575 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
576 conf_ac = &wl->conf.tx.ac_conf[i];
577 ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
578 conf_ac->cw_max, conf_ac->aifsn,
579 conf_ac->tx_op_limit);
580 if (ret < 0)
581 goto out_free_memmap;
582
583 conf_tid = &wl->conf.tx.tid_conf[i];
584 ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id,
585 conf_tid->channel_type,
586 conf_tid->tsid,
587 conf_tid->ps_scheme,
588 conf_tid->ack_policy,
589 conf_tid->apsd_conf[0],
590 conf_tid->apsd_conf[1]);
591 if (ret < 0)
592 goto out_free_memmap;
593 }
594
595 /* Enable data path */
596 ret = wl1271_cmd_data_path(wl, 1);
597 if (ret < 0)
598 goto out_free_memmap;
599
600 /* Configure for CAM power saving (ie. always active) */
601 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
602 if (ret < 0)
603 goto out_free_memmap;
604
605 /* configure PM */
606 ret = wl1271_acx_pm_config(wl);
607 if (ret < 0)
608 goto out_free_memmap;
609
610 return 0;
611
612 out_free_memmap:
613 kfree(wl->target_mem_map);
614 wl->target_mem_map = NULL;
615
616 return ret;
617}
618
619static void wl1271_irq_ps_regulate_link(struct wl1271 *wl, u8 hlid, u8 tx_blks)
620{
621 bool fw_ps;
622
623 /* only regulate station links */
624 if (hlid < WL1271_AP_STA_HLID_START)
625 return;
626
627 fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
628
629 /*
630 * Wake up from high level PS if the STA is asleep with too little
631 * blocks in FW or if the STA is awake.
632 */
633 if (!fw_ps || tx_blks < WL1271_PS_STA_MAX_BLOCKS)
634 wl1271_ps_link_end(wl, hlid);
635
636 /* Start high-level PS if the STA is asleep with enough blocks in FW */
637 else if (fw_ps && tx_blks >= WL1271_PS_STA_MAX_BLOCKS)
638 wl1271_ps_link_start(wl, hlid, true);
639}
640
641static void wl1271_irq_update_links_status(struct wl1271 *wl,
642 struct wl1271_fw_ap_status *status)
643{
644 u32 cur_fw_ps_map;
645 u8 hlid;
646
647 cur_fw_ps_map = le32_to_cpu(status->link_ps_bitmap);
648 if (wl->ap_fw_ps_map != cur_fw_ps_map) {
649 wl1271_debug(DEBUG_PSM,
650 "link ps prev 0x%x cur 0x%x changed 0x%x",
651 wl->ap_fw_ps_map, cur_fw_ps_map,
652 wl->ap_fw_ps_map ^ cur_fw_ps_map);
653
654 wl->ap_fw_ps_map = cur_fw_ps_map;
655 }
656
657 for (hlid = WL1271_AP_STA_HLID_START; hlid < AP_MAX_LINKS; hlid++) {
658 u8 cnt = status->tx_lnk_free_blks[hlid] -
659 wl->links[hlid].prev_freed_blks;
660
661 wl->links[hlid].prev_freed_blks =
662 status->tx_lnk_free_blks[hlid];
663 wl->links[hlid].allocated_blks -= cnt;
664
665 wl1271_irq_ps_regulate_link(wl, hlid,
666 wl->links[hlid].allocated_blks);
667 }
668}
669
670static void wl1271_fw_status(struct wl1271 *wl,
671 struct wl1271_fw_full_status *full_status)
672{
673 struct wl1271_fw_common_status *status = &full_status->common;
674 struct timespec ts;
675 u32 old_tx_blk_count = wl->tx_blocks_available;
676 u32 freed_blocks = 0;
677 int i;
678
679 if (wl->bss_type == BSS_TYPE_AP_BSS) {
680 wl1271_raw_read(wl, FW_STATUS_ADDR, status,
681 sizeof(struct wl1271_fw_ap_status), false);
682 } else {
683 wl1271_raw_read(wl, FW_STATUS_ADDR, status,
684 sizeof(struct wl1271_fw_sta_status), false);
685 }
686
687 wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, "
688 "drv_rx_counter = %d, tx_results_counter = %d)",
689 status->intr,
690 status->fw_rx_counter,
691 status->drv_rx_counter,
692 status->tx_results_counter);
693
694 /* update number of available TX blocks */
695 for (i = 0; i < NUM_TX_QUEUES; i++) {
696 freed_blocks += le32_to_cpu(status->tx_released_blks[i]) -
697 wl->tx_blocks_freed[i];
698
699 wl->tx_blocks_freed[i] =
700 le32_to_cpu(status->tx_released_blks[i]);
701 }
702
703 wl->tx_allocated_blocks -= freed_blocks;
704
705 if (wl->bss_type == BSS_TYPE_AP_BSS) {
706 /* Update num of allocated TX blocks per link and ps status */
707 wl1271_irq_update_links_status(wl, &full_status->ap);
708 wl->tx_blocks_available += freed_blocks;
709 } else {
710 int avail = full_status->sta.tx_total - wl->tx_allocated_blocks;
711
712 /*
713 * The FW might change the total number of TX memblocks before
714 * we get a notification about blocks being released. Thus, the
715 * available blocks calculation might yield a temporary result
716 * which is lower than the actual available blocks. Keeping in
717 * mind that only blocks that were allocated can be moved from
718 * TX to RX, tx_blocks_available should never decrease here.
719 */
720 wl->tx_blocks_available = max((int)wl->tx_blocks_available,
721 avail);
722 }
723
724 /* if more blocks are available now, tx work can be scheduled */
725 if (wl->tx_blocks_available > old_tx_blk_count)
726 clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
727
728 /* update the host-chipset time offset */
729 getnstimeofday(&ts);
730 wl->time_offset = (timespec_to_ns(&ts) >> 10) -
731 (s64)le32_to_cpu(status->fw_localtime);
732}
733
734static void wl1271_flush_deferred_work(struct wl1271 *wl)
735{
736 struct sk_buff *skb;
737
738 /* Pass all received frames to the network stack */
739 while ((skb = skb_dequeue(&wl->deferred_rx_queue)))
740 ieee80211_rx_ni(wl->hw, skb);
741
742 /* Return sent skbs to the network stack */
743 while ((skb = skb_dequeue(&wl->deferred_tx_queue)))
744 ieee80211_tx_status(wl->hw, skb);
745}
746
747static void wl1271_netstack_work(struct work_struct *work)
748{
749 struct wl1271 *wl =
750 container_of(work, struct wl1271, netstack_work);
751
752 do {
753 wl1271_flush_deferred_work(wl);
754 } while (skb_queue_len(&wl->deferred_rx_queue));
755}
756
757#define WL1271_IRQ_MAX_LOOPS 256
758
759irqreturn_t wl1271_irq(int irq, void *cookie)
760{
761 int ret;
762 u32 intr;
763 int loopcount = WL1271_IRQ_MAX_LOOPS;
764 struct wl1271 *wl = (struct wl1271 *)cookie;
765 bool done = false;
766 unsigned int defer_count;
767 unsigned long flags;
768
769 /* TX might be handled here, avoid redundant work */
770 set_bit(WL1271_FLAG_TX_PENDING, &wl->flags);
771 cancel_work_sync(&wl->tx_work);
772
773 /*
774 * In case edge triggered interrupt must be used, we cannot iterate
775 * more than once without introducing race conditions with the hardirq.
776 */
777 if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
778 loopcount = 1;
779
780 mutex_lock(&wl->mutex);
781
782 wl1271_debug(DEBUG_IRQ, "IRQ work");
783
784 if (unlikely(wl->state == WL1271_STATE_OFF))
785 goto out;
786
787 ret = wl1271_ps_elp_wakeup(wl);
788 if (ret < 0)
789 goto out;
790
791 while (!done && loopcount--) {
792 /*
793 * In order to avoid a race with the hardirq, clear the flag
794 * before acknowledging the chip. Since the mutex is held,
795 * wl1271_ps_elp_wakeup cannot be called concurrently.
796 */
797 clear_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
798 smp_mb__after_clear_bit();
799
800 wl1271_fw_status(wl, wl->fw_status);
801 intr = le32_to_cpu(wl->fw_status->common.intr);
802 intr &= WL1271_INTR_MASK;
803 if (!intr) {
804 done = true;
805 continue;
806 }
807
808 if (unlikely(intr & WL1271_ACX_INTR_WATCHDOG)) {
809 wl1271_error("watchdog interrupt received! "
810 "starting recovery.");
811 ieee80211_queue_work(wl->hw, &wl->recovery_work);
812
813 /* restarting the chip. ignore any other interrupt. */
814 goto out;
815 }
816
817 if (likely(intr & WL1271_ACX_INTR_DATA)) {
818 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA");
819
820 wl1271_rx(wl, &wl->fw_status->common);
821
822 /* Check if any tx blocks were freed */
823 spin_lock_irqsave(&wl->wl_lock, flags);
824 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
825 wl->tx_queue_count) {
826 spin_unlock_irqrestore(&wl->wl_lock, flags);
827 /*
828 * In order to avoid starvation of the TX path,
829 * call the work function directly.
830 */
831 wl1271_tx_work_locked(wl);
832 } else {
833 spin_unlock_irqrestore(&wl->wl_lock, flags);
834 }
835
836 /* check for tx results */
837 if (wl->fw_status->common.tx_results_counter !=
838 (wl->tx_results_count & 0xff))
839 wl1271_tx_complete(wl);
840
841 /* Make sure the deferred queues don't get too long */
842 defer_count = skb_queue_len(&wl->deferred_tx_queue) +
843 skb_queue_len(&wl->deferred_rx_queue);
844 if (defer_count > WL1271_DEFERRED_QUEUE_LIMIT)
845 wl1271_flush_deferred_work(wl);
846 }
847
848 if (intr & WL1271_ACX_INTR_EVENT_A) {
849 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_A");
850 wl1271_event_handle(wl, 0);
851 }
852
853 if (intr & WL1271_ACX_INTR_EVENT_B) {
854 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_B");
855 wl1271_event_handle(wl, 1);
856 }
857
858 if (intr & WL1271_ACX_INTR_INIT_COMPLETE)
859 wl1271_debug(DEBUG_IRQ,
860 "WL1271_ACX_INTR_INIT_COMPLETE");
861
862 if (intr & WL1271_ACX_INTR_HW_AVAILABLE)
863 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE");
864 }
865
866 wl1271_ps_elp_sleep(wl);
867
868out:
869 spin_lock_irqsave(&wl->wl_lock, flags);
870 /* In case TX was not handled here, queue TX work */
871 clear_bit(WL1271_FLAG_TX_PENDING, &wl->flags);
872 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
873 wl->tx_queue_count)
874 ieee80211_queue_work(wl->hw, &wl->tx_work);
875 spin_unlock_irqrestore(&wl->wl_lock, flags);
876
877 mutex_unlock(&wl->mutex);
878
879 return IRQ_HANDLED;
880}
881EXPORT_SYMBOL_GPL(wl1271_irq);
882
883static int wl1271_fetch_firmware(struct wl1271 *wl)
884{
885 const struct firmware *fw;
886 const char *fw_name;
887 int ret;
888
889 switch (wl->bss_type) {
890 case BSS_TYPE_AP_BSS:
891 if (wl->chip.id == CHIP_ID_1283_PG20)
892 fw_name = WL128X_AP_FW_NAME;
893 else
894 fw_name = WL127X_AP_FW_NAME;
895 break;
896 case BSS_TYPE_IBSS:
897 case BSS_TYPE_STA_BSS:
898 if (wl->chip.id == CHIP_ID_1283_PG20)
899 fw_name = WL128X_FW_NAME;
900 else
901 fw_name = WL1271_FW_NAME;
902 break;
903 default:
904 wl1271_error("no compatible firmware for bss_type %d",
905 wl->bss_type);
906 return -EINVAL;
907 }
908
909 wl1271_debug(DEBUG_BOOT, "booting firmware %s", fw_name);
910
911 ret = request_firmware(&fw, fw_name, wl1271_wl_to_dev(wl));
912
913 if (ret < 0) {
914 wl1271_error("could not get firmware: %d", ret);
915 return ret;
916 }
917
918 if (fw->size % 4) {
919 wl1271_error("firmware size is not multiple of 32 bits: %zu",
920 fw->size);
921 ret = -EILSEQ;
922 goto out;
923 }
924
925 vfree(wl->fw);
926 wl->fw_len = fw->size;
927 wl->fw = vmalloc(wl->fw_len);
928
929 if (!wl->fw) {
930 wl1271_error("could not allocate memory for the firmware");
931 ret = -ENOMEM;
932 goto out;
933 }
934
935 memcpy(wl->fw, fw->data, wl->fw_len);
936 wl->fw_bss_type = wl->bss_type;
937 ret = 0;
938
939out:
940 release_firmware(fw);
941
942 return ret;
943}
944
945static int wl1271_fetch_nvs(struct wl1271 *wl)
946{
947 const struct firmware *fw;
948 int ret;
949
950 ret = request_firmware(&fw, WL12XX_NVS_NAME, wl1271_wl_to_dev(wl));
951
952 if (ret < 0) {
953 wl1271_error("could not get nvs file: %d", ret);
954 return ret;
955 }
956
957 wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL);
958
959 if (!wl->nvs) {
960 wl1271_error("could not allocate memory for the nvs file");
961 ret = -ENOMEM;
962 goto out;
963 }
964
965 wl->nvs_len = fw->size;
966
967out:
968 release_firmware(fw);
969
970 return ret;
971}
972
973static void wl1271_recovery_work(struct work_struct *work)
974{
975 struct wl1271 *wl =
976 container_of(work, struct wl1271, recovery_work);
977
978 mutex_lock(&wl->mutex);
979
980 if (wl->state != WL1271_STATE_ON)
981 goto out;
982
983 wl1271_info("Hardware recovery in progress. FW ver: %s pc: 0x%x",
984 wl->chip.fw_ver_str, wl1271_read32(wl, SCR_PAD4));
985
986 if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags))
987 ieee80211_connection_loss(wl->vif);
988
989 /* Prevent spurious TX during FW restart */
990 ieee80211_stop_queues(wl->hw);
991
992 if (wl->sched_scanning) {
993 ieee80211_sched_scan_stopped(wl->hw);
994 wl->sched_scanning = false;
995 }
996
997 /* reboot the chipset */
998 __wl1271_op_remove_interface(wl, false);
999 ieee80211_restart_hw(wl->hw);
1000
1001 /*
1002 * Its safe to enable TX now - the queues are stopped after a request
1003 * to restart the HW.
1004 */
1005 ieee80211_wake_queues(wl->hw);
1006
1007out:
1008 mutex_unlock(&wl->mutex);
1009}
1010
1011static void wl1271_fw_wakeup(struct wl1271 *wl)
1012{
1013 u32 elp_reg;
1014
1015 elp_reg = ELPCTRL_WAKE_UP;
1016 wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
1017}
1018
1019static int wl1271_setup(struct wl1271 *wl)
1020{
1021 wl->fw_status = kmalloc(sizeof(*wl->fw_status), GFP_KERNEL);
1022 if (!wl->fw_status)
1023 return -ENOMEM;
1024
1025 wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL);
1026 if (!wl->tx_res_if) {
1027 kfree(wl->fw_status);
1028 return -ENOMEM;
1029 }
1030
1031 return 0;
1032}
1033
1034static int wl1271_chip_wakeup(struct wl1271 *wl)
1035{
1036 struct wl1271_partition_set partition;
1037 int ret = 0;
1038
1039 msleep(WL1271_PRE_POWER_ON_SLEEP);
1040 ret = wl1271_power_on(wl);
1041 if (ret < 0)
1042 goto out;
1043 msleep(WL1271_POWER_ON_SLEEP);
1044 wl1271_io_reset(wl);
1045 wl1271_io_init(wl);
1046
1047 /* We don't need a real memory partition here, because we only want
1048 * to use the registers at this point. */
1049 memset(&partition, 0, sizeof(partition));
1050 partition.reg.start = REGISTERS_BASE;
1051 partition.reg.size = REGISTERS_DOWN_SIZE;
1052 wl1271_set_partition(wl, &partition);
1053
1054 /* ELP module wake up */
1055 wl1271_fw_wakeup(wl);
1056
1057 /* whal_FwCtrl_BootSm() */
1058
1059 /* 0. read chip id from CHIP_ID */
1060 wl->chip.id = wl1271_read32(wl, CHIP_ID_B);
1061
1062 /* 1. check if chip id is valid */
1063
1064 switch (wl->chip.id) {
1065 case CHIP_ID_1271_PG10:
1066 wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete",
1067 wl->chip.id);
1068
1069 ret = wl1271_setup(wl);
1070 if (ret < 0)
1071 goto out;
1072 break;
1073 case CHIP_ID_1271_PG20:
1074 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)",
1075 wl->chip.id);
1076
1077 /* end-of-transaction flag should be set in wl127x AP mode */
1078 if (wl->bss_type == BSS_TYPE_AP_BSS)
1079 wl->quirks |= WL12XX_QUIRK_END_OF_TRANSACTION;
1080
1081 ret = wl1271_setup(wl);
1082 if (ret < 0)
1083 goto out;
1084 break;
1085 case CHIP_ID_1283_PG20:
1086 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1283 PG20)",
1087 wl->chip.id);
1088
1089 ret = wl1271_setup(wl);
1090 if (ret < 0)
1091 goto out;
1092 if (wl1271_set_block_size(wl))
1093 wl->quirks |= WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT;
1094 break;
1095 case CHIP_ID_1283_PG10:
1096 default:
1097 wl1271_warning("unsupported chip id: 0x%x", wl->chip.id);
1098 ret = -ENODEV;
1099 goto out;
1100 }
1101
1102 /* Make sure the firmware type matches the BSS type */
1103 if (wl->fw == NULL || wl->fw_bss_type != wl->bss_type) {
1104 ret = wl1271_fetch_firmware(wl);
1105 if (ret < 0)
1106 goto out;
1107 }
1108
1109 /* No NVS from netlink, try to get it from the filesystem */
1110 if (wl->nvs == NULL) {
1111 ret = wl1271_fetch_nvs(wl);
1112 if (ret < 0)
1113 goto out;
1114 }
1115
1116out:
1117 return ret;
1118}
1119
1120static unsigned int wl1271_get_fw_ver_quirks(struct wl1271 *wl)
1121{
1122 unsigned int quirks = 0;
1123 unsigned int *fw_ver = wl->chip.fw_ver;
1124
1125 /* Only for wl127x */
1126 if ((fw_ver[FW_VER_CHIP] == FW_VER_CHIP_WL127X) &&
1127 /* Check STA version */
1128 (((fw_ver[FW_VER_IF_TYPE] == FW_VER_IF_TYPE_STA) &&
1129 (fw_ver[FW_VER_MINOR] < FW_VER_MINOR_1_SPARE_STA_MIN)) ||
1130 /* Check AP version */
1131 ((fw_ver[FW_VER_IF_TYPE] == FW_VER_IF_TYPE_AP) &&
1132 (fw_ver[FW_VER_MINOR] < FW_VER_MINOR_1_SPARE_AP_MIN))))
1133 quirks |= WL12XX_QUIRK_USE_2_SPARE_BLOCKS;
1134
1135 return quirks;
1136}
1137
1138int wl1271_plt_start(struct wl1271 *wl)
1139{
1140 int retries = WL1271_BOOT_RETRIES;
1141 int ret;
1142
1143 mutex_lock(&wl->mutex);
1144
1145 wl1271_notice("power up");
1146
1147 if (wl->state != WL1271_STATE_OFF) {
1148 wl1271_error("cannot go into PLT state because not "
1149 "in off state: %d", wl->state);
1150 ret = -EBUSY;
1151 goto out;
1152 }
1153
1154 wl->bss_type = BSS_TYPE_STA_BSS;
1155
1156 while (retries) {
1157 retries--;
1158 ret = wl1271_chip_wakeup(wl);
1159 if (ret < 0)
1160 goto power_off;
1161
1162 ret = wl1271_boot(wl);
1163 if (ret < 0)
1164 goto power_off;
1165
1166 ret = wl1271_plt_init(wl);
1167 if (ret < 0)
1168 goto irq_disable;
1169
1170 wl->state = WL1271_STATE_PLT;
1171 wl1271_notice("firmware booted in PLT mode (%s)",
1172 wl->chip.fw_ver_str);
1173
1174 /* Check if any quirks are needed with older fw versions */
1175 wl->quirks |= wl1271_get_fw_ver_quirks(wl);
1176 goto out;
1177
1178irq_disable:
1179 mutex_unlock(&wl->mutex);
1180 /* Unlocking the mutex in the middle of handling is
1181 inherently unsafe. In this case we deem it safe to do,
1182 because we need to let any possibly pending IRQ out of
1183 the system (and while we are WL1271_STATE_OFF the IRQ
1184 work function will not do anything.) Also, any other
1185 possible concurrent operations will fail due to the
1186 current state, hence the wl1271 struct should be safe. */
1187 wl1271_disable_interrupts(wl);
1188 wl1271_flush_deferred_work(wl);
1189 cancel_work_sync(&wl->netstack_work);
1190 mutex_lock(&wl->mutex);
1191power_off:
1192 wl1271_power_off(wl);
1193 }
1194
1195 wl1271_error("firmware boot in PLT mode failed despite %d retries",
1196 WL1271_BOOT_RETRIES);
1197out:
1198 mutex_unlock(&wl->mutex);
1199
1200 return ret;
1201}
1202
1203static int __wl1271_plt_stop(struct wl1271 *wl)
1204{
1205 int ret = 0;
1206
1207 wl1271_notice("power down");
1208
1209 if (wl->state != WL1271_STATE_PLT) {
1210 wl1271_error("cannot power down because not in PLT "
1211 "state: %d", wl->state);
1212 ret = -EBUSY;
1213 goto out;
1214 }
1215
1216 wl1271_power_off(wl);
1217
1218 wl->state = WL1271_STATE_OFF;
1219 wl->rx_counter = 0;
1220
1221 mutex_unlock(&wl->mutex);
1222 wl1271_disable_interrupts(wl);
1223 wl1271_flush_deferred_work(wl);
1224 cancel_work_sync(&wl->netstack_work);
1225 cancel_work_sync(&wl->recovery_work);
1226 mutex_lock(&wl->mutex);
1227out:
1228 return ret;
1229}
1230
1231int wl1271_plt_stop(struct wl1271 *wl)
1232{
1233 int ret;
1234
1235 mutex_lock(&wl->mutex);
1236 ret = __wl1271_plt_stop(wl);
1237 mutex_unlock(&wl->mutex);
1238 return ret;
1239}
1240
1241static void wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1242{
1243 struct wl1271 *wl = hw->priv;
1244 unsigned long flags;
1245 int q;
1246 u8 hlid = 0;
1247
1248 q = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
1249
1250 if (wl->bss_type == BSS_TYPE_AP_BSS)
1251 hlid = wl1271_tx_get_hlid(skb);
1252
1253 spin_lock_irqsave(&wl->wl_lock, flags);
1254
1255 wl->tx_queue_count++;
1256
1257 /*
1258 * The workqueue is slow to process the tx_queue and we need stop
1259 * the queue here, otherwise the queue will get too long.
1260 */
1261 if (wl->tx_queue_count >= WL1271_TX_QUEUE_HIGH_WATERMARK) {
1262 wl1271_debug(DEBUG_TX, "op_tx: stopping queues");
1263 ieee80211_stop_queues(wl->hw);
1264 set_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags);
1265 }
1266
1267 /* queue the packet */
1268 if (wl->bss_type == BSS_TYPE_AP_BSS) {
1269 wl1271_debug(DEBUG_TX, "queue skb hlid %d q %d", hlid, q);
1270 skb_queue_tail(&wl->links[hlid].tx_queue[q], skb);
1271 } else {
1272 skb_queue_tail(&wl->tx_queue[q], skb);
1273 }
1274
1275 /*
1276 * The chip specific setup must run before the first TX packet -
1277 * before that, the tx_work will not be initialized!
1278 */
1279
1280 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
1281 !test_bit(WL1271_FLAG_TX_PENDING, &wl->flags))
1282 ieee80211_queue_work(wl->hw, &wl->tx_work);
1283
1284 spin_unlock_irqrestore(&wl->wl_lock, flags);
1285}
1286
1287int wl1271_tx_dummy_packet(struct wl1271 *wl)
1288{
1289 unsigned long flags;
1290
1291 spin_lock_irqsave(&wl->wl_lock, flags);
1292 set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags);
1293 wl->tx_queue_count++;
1294 spin_unlock_irqrestore(&wl->wl_lock, flags);
1295
1296 /* The FW is low on RX memory blocks, so send the dummy packet asap */
1297 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags))
1298 wl1271_tx_work_locked(wl);
1299
1300 /*
1301 * If the FW TX is busy, TX work will be scheduled by the threaded
1302 * interrupt handler function
1303 */
1304 return 0;
1305}
1306
1307/*
1308 * The size of the dummy packet should be at least 1400 bytes. However, in
1309 * order to minimize the number of bus transactions, aligning it to 512 bytes
1310 * boundaries could be beneficial, performance wise
1311 */
1312#define TOTAL_TX_DUMMY_PACKET_SIZE (ALIGN(1400, 512))
1313
1314static struct sk_buff *wl12xx_alloc_dummy_packet(struct wl1271 *wl)
1315{
1316 struct sk_buff *skb;
1317 struct ieee80211_hdr_3addr *hdr;
1318 unsigned int dummy_packet_size;
1319
1320 dummy_packet_size = TOTAL_TX_DUMMY_PACKET_SIZE -
1321 sizeof(struct wl1271_tx_hw_descr) - sizeof(*hdr);
1322
1323 skb = dev_alloc_skb(TOTAL_TX_DUMMY_PACKET_SIZE);
1324 if (!skb) {
1325 wl1271_warning("Failed to allocate a dummy packet skb");
1326 return NULL;
1327 }
1328
1329 skb_reserve(skb, sizeof(struct wl1271_tx_hw_descr));
1330
1331 hdr = (struct ieee80211_hdr_3addr *) skb_put(skb, sizeof(*hdr));
1332 memset(hdr, 0, sizeof(*hdr));
1333 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
1334 IEEE80211_STYPE_NULLFUNC |
1335 IEEE80211_FCTL_TODS);
1336
1337 memset(skb_put(skb, dummy_packet_size), 0, dummy_packet_size);
1338
1339 /* Dummy packets require the TID to be management */
1340 skb->priority = WL1271_TID_MGMT;
1341
1342 /* Initialize all fields that might be used */
1343 skb_set_queue_mapping(skb, 0);
1344 memset(IEEE80211_SKB_CB(skb), 0, sizeof(struct ieee80211_tx_info));
1345
1346 return skb;
1347}
1348
1349
1350static struct notifier_block wl1271_dev_notifier = {
1351 .notifier_call = wl1271_dev_notify,
1352};
1353
1354#ifdef CONFIG_PM
1355static int wl1271_configure_suspend(struct wl1271 *wl)
1356{
1357 int ret;
1358
1359 if (wl->bss_type != BSS_TYPE_STA_BSS)
1360 return 0;
1361
1362 mutex_lock(&wl->mutex);
1363
1364 ret = wl1271_ps_elp_wakeup(wl);
1365 if (ret < 0)
1366 goto out_unlock;
1367
1368 /* enter psm if needed*/
1369 if (!test_bit(WL1271_FLAG_PSM, &wl->flags)) {
1370 DECLARE_COMPLETION_ONSTACK(compl);
1371
1372 wl->ps_compl = &compl;
1373 ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE,
1374 wl->basic_rate, true);
1375 if (ret < 0)
1376 goto out_sleep;
1377
1378 /* we must unlock here so we will be able to get events */
1379 wl1271_ps_elp_sleep(wl);
1380 mutex_unlock(&wl->mutex);
1381
1382 ret = wait_for_completion_timeout(
1383 &compl, msecs_to_jiffies(WL1271_PS_COMPLETE_TIMEOUT));
1384 if (ret <= 0) {
1385 wl1271_warning("couldn't enter ps mode!");
1386 ret = -EBUSY;
1387 goto out;
1388 }
1389
1390 /* take mutex again, and wakeup */
1391 mutex_lock(&wl->mutex);
1392
1393 ret = wl1271_ps_elp_wakeup(wl);
1394 if (ret < 0)
1395 goto out_unlock;
1396 }
1397out_sleep:
1398 wl1271_ps_elp_sleep(wl);
1399out_unlock:
1400 mutex_unlock(&wl->mutex);
1401out:
1402 return ret;
1403
1404}
1405
1406static void wl1271_configure_resume(struct wl1271 *wl)
1407{
1408 int ret;
1409
1410 if (wl->bss_type != BSS_TYPE_STA_BSS)
1411 return;
1412
1413 mutex_lock(&wl->mutex);
1414 ret = wl1271_ps_elp_wakeup(wl);
1415 if (ret < 0)
1416 goto out;
1417
1418 /* exit psm if it wasn't configured */
1419 if (!test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags))
1420 wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE,
1421 wl->basic_rate, true);
1422
1423 wl1271_ps_elp_sleep(wl);
1424out:
1425 mutex_unlock(&wl->mutex);
1426}
1427
1428static int wl1271_op_suspend(struct ieee80211_hw *hw,
1429 struct cfg80211_wowlan *wow)
1430{
1431 struct wl1271 *wl = hw->priv;
1432 wl1271_debug(DEBUG_MAC80211, "mac80211 suspend wow=%d", !!wow);
1433 wl->wow_enabled = !!wow;
1434 if (wl->wow_enabled) {
1435 int ret;
1436 ret = wl1271_configure_suspend(wl);
1437 if (ret < 0) {
1438 wl1271_warning("couldn't prepare device to suspend");
1439 return ret;
1440 }
1441 /* flush any remaining work */
1442 wl1271_debug(DEBUG_MAC80211, "flushing remaining works");
1443 flush_delayed_work(&wl->scan_complete_work);
1444
1445 /*
1446 * disable and re-enable interrupts in order to flush
1447 * the threaded_irq
1448 */
1449 wl1271_disable_interrupts(wl);
1450
1451 /*
1452 * set suspended flag to avoid triggering a new threaded_irq
1453 * work. no need for spinlock as interrupts are disabled.
1454 */
1455 set_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
1456
1457 wl1271_enable_interrupts(wl);
1458 flush_work(&wl->tx_work);
1459 flush_delayed_work(&wl->pspoll_work);
1460 flush_delayed_work(&wl->elp_work);
1461 }
1462 return 0;
1463}
1464
1465static int wl1271_op_resume(struct ieee80211_hw *hw)
1466{
1467 struct wl1271 *wl = hw->priv;
1468 wl1271_debug(DEBUG_MAC80211, "mac80211 resume wow=%d",
1469 wl->wow_enabled);
1470
1471 /*
1472 * re-enable irq_work enqueuing, and call irq_work directly if
1473 * there is a pending work.
1474 */
1475 if (wl->wow_enabled) {
1476 struct wl1271 *wl = hw->priv;
1477 unsigned long flags;
1478 bool run_irq_work = false;
1479
1480 spin_lock_irqsave(&wl->wl_lock, flags);
1481 clear_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
1482 if (test_and_clear_bit(WL1271_FLAG_PENDING_WORK, &wl->flags))
1483 run_irq_work = true;
1484 spin_unlock_irqrestore(&wl->wl_lock, flags);
1485
1486 if (run_irq_work) {
1487 wl1271_debug(DEBUG_MAC80211,
1488 "run postponed irq_work directly");
1489 wl1271_irq(0, wl);
1490 wl1271_enable_interrupts(wl);
1491 }
1492
1493 wl1271_configure_resume(wl);
1494 }
1495
1496 return 0;
1497}
1498#endif
1499
1500static int wl1271_op_start(struct ieee80211_hw *hw)
1501{
1502 wl1271_debug(DEBUG_MAC80211, "mac80211 start");
1503
1504 /*
1505 * We have to delay the booting of the hardware because
1506 * we need to know the local MAC address before downloading and
1507 * initializing the firmware. The MAC address cannot be changed
1508 * after boot, and without the proper MAC address, the firmware
1509 * will not function properly.
1510 *
1511 * The MAC address is first known when the corresponding interface
1512 * is added. That is where we will initialize the hardware.
1513 *
1514 * In addition, we currently have different firmwares for AP and managed
1515 * operation. We will know which to boot according to interface type.
1516 */
1517
1518 return 0;
1519}
1520
1521static void wl1271_op_stop(struct ieee80211_hw *hw)
1522{
1523 wl1271_debug(DEBUG_MAC80211, "mac80211 stop");
1524}
1525
1526static int wl1271_op_add_interface(struct ieee80211_hw *hw,
1527 struct ieee80211_vif *vif)
1528{
1529 struct wl1271 *wl = hw->priv;
1530 struct wiphy *wiphy = hw->wiphy;
1531 int retries = WL1271_BOOT_RETRIES;
1532 int ret = 0;
1533 bool booted = false;
1534
1535 wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
1536 vif->type, vif->addr);
1537
1538 mutex_lock(&wl->mutex);
1539 if (wl->vif) {
1540 wl1271_debug(DEBUG_MAC80211,
1541 "multiple vifs are not supported yet");
1542 ret = -EBUSY;
1543 goto out;
1544 }
1545
1546 /*
1547 * in some very corner case HW recovery scenarios its possible to
1548 * get here before __wl1271_op_remove_interface is complete, so
1549 * opt out if that is the case.
1550 */
1551 if (test_bit(WL1271_FLAG_IF_INITIALIZED, &wl->flags)) {
1552 ret = -EBUSY;
1553 goto out;
1554 }
1555
1556 switch (vif->type) {
1557 case NL80211_IFTYPE_STATION:
1558 wl->bss_type = BSS_TYPE_STA_BSS;
1559 wl->set_bss_type = BSS_TYPE_STA_BSS;
1560 break;
1561 case NL80211_IFTYPE_ADHOC:
1562 wl->bss_type = BSS_TYPE_IBSS;
1563 wl->set_bss_type = BSS_TYPE_STA_BSS;
1564 break;
1565 case NL80211_IFTYPE_AP:
1566 wl->bss_type = BSS_TYPE_AP_BSS;
1567 break;
1568 default:
1569 ret = -EOPNOTSUPP;
1570 goto out;
1571 }
1572
1573 memcpy(wl->mac_addr, vif->addr, ETH_ALEN);
1574
1575 if (wl->state != WL1271_STATE_OFF) {
1576 wl1271_error("cannot start because not in off state: %d",
1577 wl->state);
1578 ret = -EBUSY;
1579 goto out;
1580 }
1581
1582 while (retries) {
1583 retries--;
1584 ret = wl1271_chip_wakeup(wl);
1585 if (ret < 0)
1586 goto power_off;
1587
1588 ret = wl1271_boot(wl);
1589 if (ret < 0)
1590 goto power_off;
1591
1592 ret = wl1271_hw_init(wl);
1593 if (ret < 0)
1594 goto irq_disable;
1595
1596 booted = true;
1597 break;
1598
1599irq_disable:
1600 mutex_unlock(&wl->mutex);
1601 /* Unlocking the mutex in the middle of handling is
1602 inherently unsafe. In this case we deem it safe to do,
1603 because we need to let any possibly pending IRQ out of
1604 the system (and while we are WL1271_STATE_OFF the IRQ
1605 work function will not do anything.) Also, any other
1606 possible concurrent operations will fail due to the
1607 current state, hence the wl1271 struct should be safe. */
1608 wl1271_disable_interrupts(wl);
1609 wl1271_flush_deferred_work(wl);
1610 cancel_work_sync(&wl->netstack_work);
1611 mutex_lock(&wl->mutex);
1612power_off:
1613 wl1271_power_off(wl);
1614 }
1615
1616 if (!booted) {
1617 wl1271_error("firmware boot failed despite %d retries",
1618 WL1271_BOOT_RETRIES);
1619 goto out;
1620 }
1621
1622 wl->vif = vif;
1623 wl->state = WL1271_STATE_ON;
1624 set_bit(WL1271_FLAG_IF_INITIALIZED, &wl->flags);
1625 wl1271_info("firmware booted (%s)", wl->chip.fw_ver_str);
1626
1627 /* update hw/fw version info in wiphy struct */
1628 wiphy->hw_version = wl->chip.id;
1629 strncpy(wiphy->fw_version, wl->chip.fw_ver_str,
1630 sizeof(wiphy->fw_version));
1631
1632 /* Check if any quirks are needed with older fw versions */
1633 wl->quirks |= wl1271_get_fw_ver_quirks(wl);
1634
1635 /*
1636 * Now we know if 11a is supported (info from the NVS), so disable
1637 * 11a channels if not supported
1638 */
1639 if (!wl->enable_11a)
1640 wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels = 0;
1641
1642 wl1271_debug(DEBUG_MAC80211, "11a is %ssupported",
1643 wl->enable_11a ? "" : "not ");
1644
1645out:
1646 mutex_unlock(&wl->mutex);
1647
1648 mutex_lock(&wl_list_mutex);
1649 if (!ret)
1650 list_add(&wl->list, &wl_list);
1651 mutex_unlock(&wl_list_mutex);
1652
1653 return ret;
1654}
1655
1656static void __wl1271_op_remove_interface(struct wl1271 *wl,
1657 bool reset_tx_queues)
1658{
1659 int i;
1660
1661 wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface");
1662
1663 /* because of hardware recovery, we may get here twice */
1664 if (wl->state != WL1271_STATE_ON)
1665 return;
1666
1667 wl1271_info("down");
1668
1669 mutex_lock(&wl_list_mutex);
1670 list_del(&wl->list);
1671 mutex_unlock(&wl_list_mutex);
1672
1673 /* enable dyn ps just in case (if left on due to fw crash etc) */
1674 if (wl->bss_type == BSS_TYPE_STA_BSS)
1675 ieee80211_enable_dyn_ps(wl->vif);
1676
1677 if (wl->scan.state != WL1271_SCAN_STATE_IDLE) {
1678 wl->scan.state = WL1271_SCAN_STATE_IDLE;
1679 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
1680 wl->scan.req = NULL;
1681 ieee80211_scan_completed(wl->hw, true);
1682 }
1683
1684 /*
1685 * this must be before the cancel_work calls below, so that the work
1686 * functions don't perform further work.
1687 */
1688 wl->state = WL1271_STATE_OFF;
1689
1690 mutex_unlock(&wl->mutex);
1691
1692 wl1271_disable_interrupts(wl);
1693 wl1271_flush_deferred_work(wl);
1694 cancel_delayed_work_sync(&wl->scan_complete_work);
1695 cancel_work_sync(&wl->netstack_work);
1696 cancel_work_sync(&wl->tx_work);
1697 cancel_delayed_work_sync(&wl->pspoll_work);
1698 cancel_delayed_work_sync(&wl->elp_work);
1699
1700 mutex_lock(&wl->mutex);
1701
1702 /* let's notify MAC80211 about the remaining pending TX frames */
1703 wl1271_tx_reset(wl, reset_tx_queues);
1704 wl1271_power_off(wl);
1705
1706 memset(wl->bssid, 0, ETH_ALEN);
1707 memset(wl->ssid, 0, IW_ESSID_MAX_SIZE + 1);
1708 wl->ssid_len = 0;
1709 wl->bss_type = MAX_BSS_TYPE;
1710 wl->set_bss_type = MAX_BSS_TYPE;
1711 wl->band = IEEE80211_BAND_2GHZ;
1712
1713 wl->rx_counter = 0;
1714 wl->psm_entry_retry = 0;
1715 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
1716 wl->tx_blocks_available = 0;
1717 wl->tx_allocated_blocks = 0;
1718 wl->tx_results_count = 0;
1719 wl->tx_packets_count = 0;
1720 wl->tx_security_last_seq = 0;
1721 wl->tx_security_seq = 0;
1722 wl->time_offset = 0;
1723 wl->session_counter = 0;
1724 wl->rate_set = CONF_TX_RATE_MASK_BASIC;
1725 wl->vif = NULL;
1726 wl->filters = 0;
1727 wl1271_free_ap_keys(wl);
1728 memset(wl->ap_hlid_map, 0, sizeof(wl->ap_hlid_map));
1729 wl->ap_fw_ps_map = 0;
1730 wl->ap_ps_map = 0;
1731 wl->sched_scanning = false;
1732
1733 /*
1734 * this is performed after the cancel_work calls and the associated
1735 * mutex_lock, so that wl1271_op_add_interface does not accidentally
1736 * get executed before all these vars have been reset.
1737 */
1738 wl->flags = 0;
1739
1740 for (i = 0; i < NUM_TX_QUEUES; i++)
1741 wl->tx_blocks_freed[i] = 0;
1742
1743 wl1271_debugfs_reset(wl);
1744
1745 kfree(wl->fw_status);
1746 wl->fw_status = NULL;
1747 kfree(wl->tx_res_if);
1748 wl->tx_res_if = NULL;
1749 kfree(wl->target_mem_map);
1750 wl->target_mem_map = NULL;
1751}
1752
1753static void wl1271_op_remove_interface(struct ieee80211_hw *hw,
1754 struct ieee80211_vif *vif)
1755{
1756 struct wl1271 *wl = hw->priv;
1757
1758 mutex_lock(&wl->mutex);
1759 /*
1760 * wl->vif can be null here if someone shuts down the interface
1761 * just when hardware recovery has been started.
1762 */
1763 if (wl->vif) {
1764 WARN_ON(wl->vif != vif);
1765 __wl1271_op_remove_interface(wl, true);
1766 }
1767
1768 mutex_unlock(&wl->mutex);
1769 cancel_work_sync(&wl->recovery_work);
1770}
1771
1772void wl1271_configure_filters(struct wl1271 *wl, unsigned int filters)
1773{
1774 wl1271_set_default_filters(wl);
1775
1776 /* combine requested filters with current filter config */
1777 filters = wl->filters | filters;
1778
1779 wl1271_debug(DEBUG_FILTERS, "RX filters set: ");
1780
1781 if (filters & FIF_PROMISC_IN_BSS) {
1782 wl1271_debug(DEBUG_FILTERS, " - FIF_PROMISC_IN_BSS");
1783 wl->rx_config &= ~CFG_UNI_FILTER_EN;
1784 wl->rx_config |= CFG_BSSID_FILTER_EN;
1785 }
1786 if (filters & FIF_BCN_PRBRESP_PROMISC) {
1787 wl1271_debug(DEBUG_FILTERS, " - FIF_BCN_PRBRESP_PROMISC");
1788 wl->rx_config &= ~CFG_BSSID_FILTER_EN;
1789 wl->rx_config &= ~CFG_SSID_FILTER_EN;
1790 }
1791 if (filters & FIF_OTHER_BSS) {
1792 wl1271_debug(DEBUG_FILTERS, " - FIF_OTHER_BSS");
1793 wl->rx_config &= ~CFG_BSSID_FILTER_EN;
1794 }
1795 if (filters & FIF_CONTROL) {
1796 wl1271_debug(DEBUG_FILTERS, " - FIF_CONTROL");
1797 wl->rx_filter |= CFG_RX_CTL_EN;
1798 }
1799 if (filters & FIF_FCSFAIL) {
1800 wl1271_debug(DEBUG_FILTERS, " - FIF_FCSFAIL");
1801 wl->rx_filter |= CFG_RX_FCS_ERROR;
1802 }
1803}
1804
1805static int wl1271_dummy_join(struct wl1271 *wl)
1806{
1807 int ret = 0;
1808 /* we need to use a dummy BSSID for now */
1809 static const u8 dummy_bssid[ETH_ALEN] = { 0x0b, 0xad, 0xde,
1810 0xad, 0xbe, 0xef };
1811
1812 memcpy(wl->bssid, dummy_bssid, ETH_ALEN);
1813
1814 /* pass through frames from all BSS */
1815 wl1271_configure_filters(wl, FIF_OTHER_BSS);
1816
1817 ret = wl1271_cmd_join(wl, wl->set_bss_type);
1818 if (ret < 0)
1819 goto out;
1820
1821 set_bit(WL1271_FLAG_JOINED, &wl->flags);
1822
1823out:
1824 return ret;
1825}
1826
1827static int wl1271_join(struct wl1271 *wl, bool set_assoc)
1828{
1829 int ret;
1830
1831 /*
1832 * One of the side effects of the JOIN command is that is clears
1833 * WPA/WPA2 keys from the chipset. Performing a JOIN while associated
1834 * to a WPA/WPA2 access point will therefore kill the data-path.
1835 * Currently the only valid scenario for JOIN during association
1836 * is on roaming, in which case we will also be given new keys.
1837 * Keep the below message for now, unless it starts bothering
1838 * users who really like to roam a lot :)
1839 */
1840 if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags))
1841 wl1271_info("JOIN while associated.");
1842
1843 if (set_assoc)
1844 set_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags);
1845
1846 ret = wl1271_cmd_join(wl, wl->set_bss_type);
1847 if (ret < 0)
1848 goto out;
1849
1850 set_bit(WL1271_FLAG_JOINED, &wl->flags);
1851
1852 if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags))
1853 goto out;
1854
1855 /*
1856 * The join command disable the keep-alive mode, shut down its process,
1857 * and also clear the template config, so we need to reset it all after
1858 * the join. The acx_aid starts the keep-alive process, and the order
1859 * of the commands below is relevant.
1860 */
1861 ret = wl1271_acx_keep_alive_mode(wl, true);
1862 if (ret < 0)
1863 goto out;
1864
1865 ret = wl1271_acx_aid(wl, wl->aid);
1866 if (ret < 0)
1867 goto out;
1868
1869 ret = wl1271_cmd_build_klv_null_data(wl);
1870 if (ret < 0)
1871 goto out;
1872
1873 ret = wl1271_acx_keep_alive_config(wl, CMD_TEMPL_KLV_IDX_NULL_DATA,
1874 ACX_KEEP_ALIVE_TPL_VALID);
1875 if (ret < 0)
1876 goto out;
1877
1878out:
1879 return ret;
1880}
1881
1882static int wl1271_unjoin(struct wl1271 *wl)
1883{
1884 int ret;
1885
1886 /* to stop listening to a channel, we disconnect */
1887 ret = wl1271_cmd_disconnect(wl);
1888 if (ret < 0)
1889 goto out;
1890
1891 clear_bit(WL1271_FLAG_JOINED, &wl->flags);
1892 memset(wl->bssid, 0, ETH_ALEN);
1893
1894 /* stop filtering packets based on bssid */
1895 wl1271_configure_filters(wl, FIF_OTHER_BSS);
1896
1897out:
1898 return ret;
1899}
1900
1901static void wl1271_set_band_rate(struct wl1271 *wl)
1902{
1903 if (wl->band == IEEE80211_BAND_2GHZ)
1904 wl->basic_rate_set = wl->conf.tx.basic_rate;
1905 else
1906 wl->basic_rate_set = wl->conf.tx.basic_rate_5;
1907}
1908
1909static int wl1271_sta_handle_idle(struct wl1271 *wl, bool idle)
1910{
1911 int ret;
1912
1913 if (idle) {
1914 if (test_bit(WL1271_FLAG_JOINED, &wl->flags)) {
1915 ret = wl1271_unjoin(wl);
1916 if (ret < 0)
1917 goto out;
1918 }
1919 wl->rate_set = wl1271_tx_min_rate_get(wl);
1920 ret = wl1271_acx_sta_rate_policies(wl);
1921 if (ret < 0)
1922 goto out;
1923 ret = wl1271_acx_keep_alive_config(
1924 wl, CMD_TEMPL_KLV_IDX_NULL_DATA,
1925 ACX_KEEP_ALIVE_TPL_INVALID);
1926 if (ret < 0)
1927 goto out;
1928 set_bit(WL1271_FLAG_IDLE, &wl->flags);
1929 } else {
1930 /* increment the session counter */
1931 wl->session_counter++;
1932 if (wl->session_counter >= SESSION_COUNTER_MAX)
1933 wl->session_counter = 0;
1934
1935 /* The current firmware only supports sched_scan in idle */
1936 if (wl->sched_scanning) {
1937 wl1271_scan_sched_scan_stop(wl);
1938 ieee80211_sched_scan_stopped(wl->hw);
1939 }
1940
1941 ret = wl1271_dummy_join(wl);
1942 if (ret < 0)
1943 goto out;
1944 clear_bit(WL1271_FLAG_IDLE, &wl->flags);
1945 }
1946
1947out:
1948 return ret;
1949}
1950
1951static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
1952{
1953 struct wl1271 *wl = hw->priv;
1954 struct ieee80211_conf *conf = &hw->conf;
1955 int channel, ret = 0;
1956 bool is_ap;
1957
1958 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
1959
1960 wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d %s"
1961 " changed 0x%x",
1962 channel,
1963 conf->flags & IEEE80211_CONF_PS ? "on" : "off",
1964 conf->power_level,
1965 conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use",
1966 changed);
1967
1968 /*
1969 * mac80211 will go to idle nearly immediately after transmitting some
1970 * frames, such as the deauth. To make sure those frames reach the air,
1971 * wait here until the TX queue is fully flushed.
1972 */
1973 if ((changed & IEEE80211_CONF_CHANGE_IDLE) &&
1974 (conf->flags & IEEE80211_CONF_IDLE))
1975 wl1271_tx_flush(wl);
1976
1977 mutex_lock(&wl->mutex);
1978
1979 if (unlikely(wl->state == WL1271_STATE_OFF)) {
1980 /* we support configuring the channel and band while off */
1981 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL)) {
1982 wl->band = conf->channel->band;
1983 wl->channel = channel;
1984 }
1985
1986 goto out;
1987 }
1988
1989 is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
1990
1991 ret = wl1271_ps_elp_wakeup(wl);
1992 if (ret < 0)
1993 goto out;
1994
1995 /* if the channel changes while joined, join again */
1996 if (changed & IEEE80211_CONF_CHANGE_CHANNEL &&
1997 ((wl->band != conf->channel->band) ||
1998 (wl->channel != channel))) {
1999 wl->band = conf->channel->band;
2000 wl->channel = channel;
2001
2002 if (!is_ap) {
2003 /*
2004 * FIXME: the mac80211 should really provide a fixed
2005 * rate to use here. for now, just use the smallest
2006 * possible rate for the band as a fixed rate for
2007 * association frames and other control messages.
2008 */
2009 if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags))
2010 wl1271_set_band_rate(wl);
2011
2012 wl->basic_rate = wl1271_tx_min_rate_get(wl);
2013 ret = wl1271_acx_sta_rate_policies(wl);
2014 if (ret < 0)
2015 wl1271_warning("rate policy for channel "
2016 "failed %d", ret);
2017
2018 if (test_bit(WL1271_FLAG_JOINED, &wl->flags)) {
2019 ret = wl1271_join(wl, false);
2020 if (ret < 0)
2021 wl1271_warning("cmd join on channel "
2022 "failed %d", ret);
2023 }
2024 }
2025 }
2026
2027 if (changed & IEEE80211_CONF_CHANGE_IDLE && !is_ap) {
2028 ret = wl1271_sta_handle_idle(wl,
2029 conf->flags & IEEE80211_CONF_IDLE);
2030 if (ret < 0)
2031 wl1271_warning("idle mode change failed %d", ret);
2032 }
2033
2034 /*
2035 * if mac80211 changes the PSM mode, make sure the mode is not
2036 * incorrectly changed after the pspoll failure active window.
2037 */
2038 if (changed & IEEE80211_CONF_CHANGE_PS)
2039 clear_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags);
2040
2041 if (conf->flags & IEEE80211_CONF_PS &&
2042 !test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags)) {
2043 set_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags);
2044
2045 /*
2046 * We enter PSM only if we're already associated.
2047 * If we're not, we'll enter it when joining an SSID,
2048 * through the bss_info_changed() hook.
2049 */
2050 if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) {
2051 wl1271_debug(DEBUG_PSM, "psm enabled");
2052 ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE,
2053 wl->basic_rate, true);
2054 }
2055 } else if (!(conf->flags & IEEE80211_CONF_PS) &&
2056 test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags)) {
2057 wl1271_debug(DEBUG_PSM, "psm disabled");
2058
2059 clear_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags);
2060
2061 if (test_bit(WL1271_FLAG_PSM, &wl->flags))
2062 ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE,
2063 wl->basic_rate, true);
2064 }
2065
2066 if (conf->power_level != wl->power_level) {
2067 ret = wl1271_acx_tx_power(wl, conf->power_level);
2068 if (ret < 0)
2069 goto out_sleep;
2070
2071 wl->power_level = conf->power_level;
2072 }
2073
2074out_sleep:
2075 wl1271_ps_elp_sleep(wl);
2076
2077out:
2078 mutex_unlock(&wl->mutex);
2079
2080 return ret;
2081}
2082
2083struct wl1271_filter_params {
2084 bool enabled;
2085 int mc_list_length;
2086 u8 mc_list[ACX_MC_ADDRESS_GROUP_MAX][ETH_ALEN];
2087};
2088
2089static u64 wl1271_op_prepare_multicast(struct ieee80211_hw *hw,
2090 struct netdev_hw_addr_list *mc_list)
2091{
2092 struct wl1271_filter_params *fp;
2093 struct netdev_hw_addr *ha;
2094 struct wl1271 *wl = hw->priv;
2095
2096 if (unlikely(wl->state == WL1271_STATE_OFF))
2097 return 0;
2098
2099 fp = kzalloc(sizeof(*fp), GFP_ATOMIC);
2100 if (!fp) {
2101 wl1271_error("Out of memory setting filters.");
2102 return 0;
2103 }
2104
2105 /* update multicast filtering parameters */
2106 fp->mc_list_length = 0;
2107 if (netdev_hw_addr_list_count(mc_list) > ACX_MC_ADDRESS_GROUP_MAX) {
2108 fp->enabled = false;
2109 } else {
2110 fp->enabled = true;
2111 netdev_hw_addr_list_for_each(ha, mc_list) {
2112 memcpy(fp->mc_list[fp->mc_list_length],
2113 ha->addr, ETH_ALEN);
2114 fp->mc_list_length++;
2115 }
2116 }
2117
2118 return (u64)(unsigned long)fp;
2119}
2120
2121#define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
2122 FIF_ALLMULTI | \
2123 FIF_FCSFAIL | \
2124 FIF_BCN_PRBRESP_PROMISC | \
2125 FIF_CONTROL | \
2126 FIF_OTHER_BSS)
2127
2128static void wl1271_op_configure_filter(struct ieee80211_hw *hw,
2129 unsigned int changed,
2130 unsigned int *total, u64 multicast)
2131{
2132 struct wl1271_filter_params *fp = (void *)(unsigned long)multicast;
2133 struct wl1271 *wl = hw->priv;
2134 int ret;
2135
2136 wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter changed %x"
2137 " total %x", changed, *total);
2138
2139 mutex_lock(&wl->mutex);
2140
2141 *total &= WL1271_SUPPORTED_FILTERS;
2142 changed &= WL1271_SUPPORTED_FILTERS;
2143
2144 if (unlikely(wl->state == WL1271_STATE_OFF))
2145 goto out;
2146
2147 ret = wl1271_ps_elp_wakeup(wl);
2148 if (ret < 0)
2149 goto out;
2150
2151 if (wl->bss_type != BSS_TYPE_AP_BSS) {
2152 if (*total & FIF_ALLMULTI)
2153 ret = wl1271_acx_group_address_tbl(wl, false, NULL, 0);
2154 else if (fp)
2155 ret = wl1271_acx_group_address_tbl(wl, fp->enabled,
2156 fp->mc_list,
2157 fp->mc_list_length);
2158 if (ret < 0)
2159 goto out_sleep;
2160 }
2161
2162 /* determine, whether supported filter values have changed */
2163 if (changed == 0)
2164 goto out_sleep;
2165
2166 /* configure filters */
2167 wl->filters = *total;
2168 wl1271_configure_filters(wl, 0);
2169
2170 /* apply configured filters */
2171 ret = wl1271_acx_rx_config(wl, wl->rx_config, wl->rx_filter);
2172 if (ret < 0)
2173 goto out_sleep;
2174
2175out_sleep:
2176 wl1271_ps_elp_sleep(wl);
2177
2178out:
2179 mutex_unlock(&wl->mutex);
2180 kfree(fp);
2181}
2182
2183static int wl1271_record_ap_key(struct wl1271 *wl, u8 id, u8 key_type,
2184 u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
2185 u16 tx_seq_16)
2186{
2187 struct wl1271_ap_key *ap_key;
2188 int i;
2189
2190 wl1271_debug(DEBUG_CRYPT, "record ap key id %d", (int)id);
2191
2192 if (key_size > MAX_KEY_SIZE)
2193 return -EINVAL;
2194
2195 /*
2196 * Find next free entry in ap_keys. Also check we are not replacing
2197 * an existing key.
2198 */
2199 for (i = 0; i < MAX_NUM_KEYS; i++) {
2200 if (wl->recorded_ap_keys[i] == NULL)
2201 break;
2202
2203 if (wl->recorded_ap_keys[i]->id == id) {
2204 wl1271_warning("trying to record key replacement");
2205 return -EINVAL;
2206 }
2207 }
2208
2209 if (i == MAX_NUM_KEYS)
2210 return -EBUSY;
2211
2212 ap_key = kzalloc(sizeof(*ap_key), GFP_KERNEL);
2213 if (!ap_key)
2214 return -ENOMEM;
2215
2216 ap_key->id = id;
2217 ap_key->key_type = key_type;
2218 ap_key->key_size = key_size;
2219 memcpy(ap_key->key, key, key_size);
2220 ap_key->hlid = hlid;
2221 ap_key->tx_seq_32 = tx_seq_32;
2222 ap_key->tx_seq_16 = tx_seq_16;
2223
2224 wl->recorded_ap_keys[i] = ap_key;
2225 return 0;
2226}
2227
2228static void wl1271_free_ap_keys(struct wl1271 *wl)
2229{
2230 int i;
2231
2232 for (i = 0; i < MAX_NUM_KEYS; i++) {
2233 kfree(wl->recorded_ap_keys[i]);
2234 wl->recorded_ap_keys[i] = NULL;
2235 }
2236}
2237
2238static int wl1271_ap_init_hwenc(struct wl1271 *wl)
2239{
2240 int i, ret = 0;
2241 struct wl1271_ap_key *key;
2242 bool wep_key_added = false;
2243
2244 for (i = 0; i < MAX_NUM_KEYS; i++) {
2245 if (wl->recorded_ap_keys[i] == NULL)
2246 break;
2247
2248 key = wl->recorded_ap_keys[i];
2249 ret = wl1271_cmd_set_ap_key(wl, KEY_ADD_OR_REPLACE,
2250 key->id, key->key_type,
2251 key->key_size, key->key,
2252 key->hlid, key->tx_seq_32,
2253 key->tx_seq_16);
2254 if (ret < 0)
2255 goto out;
2256
2257 if (key->key_type == KEY_WEP)
2258 wep_key_added = true;
2259 }
2260
2261 if (wep_key_added) {
2262 ret = wl1271_cmd_set_ap_default_wep_key(wl, wl->default_key);
2263 if (ret < 0)
2264 goto out;
2265 }
2266
2267out:
2268 wl1271_free_ap_keys(wl);
2269 return ret;
2270}
2271
2272static int wl1271_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
2273 u8 key_size, const u8 *key, u32 tx_seq_32,
2274 u16 tx_seq_16, struct ieee80211_sta *sta)
2275{
2276 int ret;
2277 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
2278
2279 if (is_ap) {
2280 struct wl1271_station *wl_sta;
2281 u8 hlid;
2282
2283 if (sta) {
2284 wl_sta = (struct wl1271_station *)sta->drv_priv;
2285 hlid = wl_sta->hlid;
2286 } else {
2287 hlid = WL1271_AP_BROADCAST_HLID;
2288 }
2289
2290 if (!test_bit(WL1271_FLAG_AP_STARTED, &wl->flags)) {
2291 /*
2292 * We do not support removing keys after AP shutdown.
2293 * Pretend we do to make mac80211 happy.
2294 */
2295 if (action != KEY_ADD_OR_REPLACE)
2296 return 0;
2297
2298 ret = wl1271_record_ap_key(wl, id,
2299 key_type, key_size,
2300 key, hlid, tx_seq_32,
2301 tx_seq_16);
2302 } else {
2303 ret = wl1271_cmd_set_ap_key(wl, action,
2304 id, key_type, key_size,
2305 key, hlid, tx_seq_32,
2306 tx_seq_16);
2307 }
2308
2309 if (ret < 0)
2310 return ret;
2311 } else {
2312 const u8 *addr;
2313 static const u8 bcast_addr[ETH_ALEN] = {
2314 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2315 };
2316
2317 addr = sta ? sta->addr : bcast_addr;
2318
2319 if (is_zero_ether_addr(addr)) {
2320 /* We dont support TX only encryption */
2321 return -EOPNOTSUPP;
2322 }
2323
2324 /* The wl1271 does not allow to remove unicast keys - they
2325 will be cleared automatically on next CMD_JOIN. Ignore the
2326 request silently, as we dont want the mac80211 to emit
2327 an error message. */
2328 if (action == KEY_REMOVE && !is_broadcast_ether_addr(addr))
2329 return 0;
2330
2331 ret = wl1271_cmd_set_sta_key(wl, action,
2332 id, key_type, key_size,
2333 key, addr, tx_seq_32,
2334 tx_seq_16);
2335 if (ret < 0)
2336 return ret;
2337
2338 /* the default WEP key needs to be configured at least once */
2339 if (key_type == KEY_WEP) {
2340 ret = wl1271_cmd_set_sta_default_wep_key(wl,
2341 wl->default_key);
2342 if (ret < 0)
2343 return ret;
2344 }
2345 }
2346
2347 return 0;
2348}
2349
2350static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2351 struct ieee80211_vif *vif,
2352 struct ieee80211_sta *sta,
2353 struct ieee80211_key_conf *key_conf)
2354{
2355 struct wl1271 *wl = hw->priv;
2356 int ret;
2357 u32 tx_seq_32 = 0;
2358 u16 tx_seq_16 = 0;
2359 u8 key_type;
2360
2361 wl1271_debug(DEBUG_MAC80211, "mac80211 set key");
2362
2363 wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x sta: %p", cmd, sta);
2364 wl1271_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
2365 key_conf->cipher, key_conf->keyidx,
2366 key_conf->keylen, key_conf->flags);
2367 wl1271_dump(DEBUG_CRYPT, "KEY: ", key_conf->key, key_conf->keylen);
2368
2369 mutex_lock(&wl->mutex);
2370
2371 if (unlikely(wl->state == WL1271_STATE_OFF)) {
2372 ret = -EAGAIN;
2373 goto out_unlock;
2374 }
2375
2376 ret = wl1271_ps_elp_wakeup(wl);
2377 if (ret < 0)
2378 goto out_unlock;
2379
2380 switch (key_conf->cipher) {
2381 case WLAN_CIPHER_SUITE_WEP40:
2382 case WLAN_CIPHER_SUITE_WEP104:
2383 key_type = KEY_WEP;
2384
2385 key_conf->hw_key_idx = key_conf->keyidx;
2386 break;
2387 case WLAN_CIPHER_SUITE_TKIP:
2388 key_type = KEY_TKIP;
2389
2390 key_conf->hw_key_idx = key_conf->keyidx;
2391 tx_seq_32 = WL1271_TX_SECURITY_HI32(wl->tx_security_seq);
2392 tx_seq_16 = WL1271_TX_SECURITY_LO16(wl->tx_security_seq);
2393 break;
2394 case WLAN_CIPHER_SUITE_CCMP:
2395 key_type = KEY_AES;
2396
2397 key_conf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
2398 tx_seq_32 = WL1271_TX_SECURITY_HI32(wl->tx_security_seq);
2399 tx_seq_16 = WL1271_TX_SECURITY_LO16(wl->tx_security_seq);
2400 break;
2401 case WL1271_CIPHER_SUITE_GEM:
2402 key_type = KEY_GEM;
2403 tx_seq_32 = WL1271_TX_SECURITY_HI32(wl->tx_security_seq);
2404 tx_seq_16 = WL1271_TX_SECURITY_LO16(wl->tx_security_seq);
2405 break;
2406 default:
2407 wl1271_error("Unknown key algo 0x%x", key_conf->cipher);
2408
2409 ret = -EOPNOTSUPP;
2410 goto out_sleep;
2411 }
2412
2413 switch (cmd) {
2414 case SET_KEY:
2415 ret = wl1271_set_key(wl, KEY_ADD_OR_REPLACE,
2416 key_conf->keyidx, key_type,
2417 key_conf->keylen, key_conf->key,
2418 tx_seq_32, tx_seq_16, sta);
2419 if (ret < 0) {
2420 wl1271_error("Could not add or replace key");
2421 goto out_sleep;
2422 }
2423 break;
2424
2425 case DISABLE_KEY:
2426 ret = wl1271_set_key(wl, KEY_REMOVE,
2427 key_conf->keyidx, key_type,
2428 key_conf->keylen, key_conf->key,
2429 0, 0, sta);
2430 if (ret < 0) {
2431 wl1271_error("Could not remove key");
2432 goto out_sleep;
2433 }
2434 break;
2435
2436 default:
2437 wl1271_error("Unsupported key cmd 0x%x", cmd);
2438 ret = -EOPNOTSUPP;
2439 break;
2440 }
2441
2442out_sleep:
2443 wl1271_ps_elp_sleep(wl);
2444
2445out_unlock:
2446 mutex_unlock(&wl->mutex);
2447
2448 return ret;
2449}
2450
2451static int wl1271_op_hw_scan(struct ieee80211_hw *hw,
2452 struct ieee80211_vif *vif,
2453 struct cfg80211_scan_request *req)
2454{
2455 struct wl1271 *wl = hw->priv;
2456 int ret;
2457 u8 *ssid = NULL;
2458 size_t len = 0;
2459
2460 wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan");
2461
2462 if (req->n_ssids) {
2463 ssid = req->ssids[0].ssid;
2464 len = req->ssids[0].ssid_len;
2465 }
2466
2467 mutex_lock(&wl->mutex);
2468
2469 if (wl->state == WL1271_STATE_OFF) {
2470 /*
2471 * We cannot return -EBUSY here because cfg80211 will expect
2472 * a call to ieee80211_scan_completed if we do - in this case
2473 * there won't be any call.
2474 */
2475 ret = -EAGAIN;
2476 goto out;
2477 }
2478
2479 ret = wl1271_ps_elp_wakeup(wl);
2480 if (ret < 0)
2481 goto out;
2482
2483 ret = wl1271_scan(hw->priv, ssid, len, req);
2484
2485 wl1271_ps_elp_sleep(wl);
2486
2487out:
2488 mutex_unlock(&wl->mutex);
2489
2490 return ret;
2491}
2492
2493static int wl1271_op_sched_scan_start(struct ieee80211_hw *hw,
2494 struct ieee80211_vif *vif,
2495 struct cfg80211_sched_scan_request *req,
2496 struct ieee80211_sched_scan_ies *ies)
2497{
2498 struct wl1271 *wl = hw->priv;
2499 int ret;
2500
2501 wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_start");
2502
2503 mutex_lock(&wl->mutex);
2504
2505 ret = wl1271_ps_elp_wakeup(wl);
2506 if (ret < 0)
2507 goto out;
2508
2509 ret = wl1271_scan_sched_scan_config(wl, req, ies);
2510 if (ret < 0)
2511 goto out_sleep;
2512
2513 ret = wl1271_scan_sched_scan_start(wl);
2514 if (ret < 0)
2515 goto out_sleep;
2516
2517 wl->sched_scanning = true;
2518
2519out_sleep:
2520 wl1271_ps_elp_sleep(wl);
2521out:
2522 mutex_unlock(&wl->mutex);
2523 return ret;
2524}
2525
2526static void wl1271_op_sched_scan_stop(struct ieee80211_hw *hw,
2527 struct ieee80211_vif *vif)
2528{
2529 struct wl1271 *wl = hw->priv;
2530 int ret;
2531
2532 wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_stop");
2533
2534 mutex_lock(&wl->mutex);
2535
2536 ret = wl1271_ps_elp_wakeup(wl);
2537 if (ret < 0)
2538 goto out;
2539
2540 wl1271_scan_sched_scan_stop(wl);
2541
2542 wl1271_ps_elp_sleep(wl);
2543out:
2544 mutex_unlock(&wl->mutex);
2545}
2546
2547static int wl1271_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
2548{
2549 struct wl1271 *wl = hw->priv;
2550 int ret = 0;
2551
2552 mutex_lock(&wl->mutex);
2553
2554 if (unlikely(wl->state == WL1271_STATE_OFF)) {
2555 ret = -EAGAIN;
2556 goto out;
2557 }
2558
2559 ret = wl1271_ps_elp_wakeup(wl);
2560 if (ret < 0)
2561 goto out;
2562
2563 ret = wl1271_acx_frag_threshold(wl, value);
2564 if (ret < 0)
2565 wl1271_warning("wl1271_op_set_frag_threshold failed: %d", ret);
2566
2567 wl1271_ps_elp_sleep(wl);
2568
2569out:
2570 mutex_unlock(&wl->mutex);
2571
2572 return ret;
2573}
2574
2575static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2576{
2577 struct wl1271 *wl = hw->priv;
2578 int ret = 0;
2579
2580 mutex_lock(&wl->mutex);
2581
2582 if (unlikely(wl->state == WL1271_STATE_OFF)) {
2583 ret = -EAGAIN;
2584 goto out;
2585 }
2586
2587 ret = wl1271_ps_elp_wakeup(wl);
2588 if (ret < 0)
2589 goto out;
2590
2591 ret = wl1271_acx_rts_threshold(wl, value);
2592 if (ret < 0)
2593 wl1271_warning("wl1271_op_set_rts_threshold failed: %d", ret);
2594
2595 wl1271_ps_elp_sleep(wl);
2596
2597out:
2598 mutex_unlock(&wl->mutex);
2599
2600 return ret;
2601}
2602
2603static int wl1271_ssid_set(struct wl1271 *wl, struct sk_buff *skb,
2604 int offset)
2605{
2606 u8 ssid_len;
2607 const u8 *ptr = cfg80211_find_ie(WLAN_EID_SSID, skb->data + offset,
2608 skb->len - offset);
2609
2610 if (!ptr) {
2611 wl1271_error("No SSID in IEs!");
2612 return -ENOENT;
2613 }
2614
2615 ssid_len = ptr[1];
2616 if (ssid_len > IEEE80211_MAX_SSID_LEN) {
2617 wl1271_error("SSID is too long!");
2618 return -EINVAL;
2619 }
2620
2621 wl->ssid_len = ssid_len;
2622 memcpy(wl->ssid, ptr+2, ssid_len);
2623 return 0;
2624}
2625
2626static int wl1271_bss_erp_info_changed(struct wl1271 *wl,
2627 struct ieee80211_bss_conf *bss_conf,
2628 u32 changed)
2629{
2630 int ret = 0;
2631
2632 if (changed & BSS_CHANGED_ERP_SLOT) {
2633 if (bss_conf->use_short_slot)
2634 ret = wl1271_acx_slot(wl, SLOT_TIME_SHORT);
2635 else
2636 ret = wl1271_acx_slot(wl, SLOT_TIME_LONG);
2637 if (ret < 0) {
2638 wl1271_warning("Set slot time failed %d", ret);
2639 goto out;
2640 }
2641 }
2642
2643 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2644 if (bss_conf->use_short_preamble)
2645 wl1271_acx_set_preamble(wl, ACX_PREAMBLE_SHORT);
2646 else
2647 wl1271_acx_set_preamble(wl, ACX_PREAMBLE_LONG);
2648 }
2649
2650 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2651 if (bss_conf->use_cts_prot)
2652 ret = wl1271_acx_cts_protect(wl, CTSPROTECT_ENABLE);
2653 else
2654 ret = wl1271_acx_cts_protect(wl, CTSPROTECT_DISABLE);
2655 if (ret < 0) {
2656 wl1271_warning("Set ctsprotect failed %d", ret);
2657 goto out;
2658 }
2659 }
2660
2661out:
2662 return ret;
2663}
2664
2665static int wl1271_bss_beacon_info_changed(struct wl1271 *wl,
2666 struct ieee80211_vif *vif,
2667 struct ieee80211_bss_conf *bss_conf,
2668 u32 changed)
2669{
2670 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
2671 int ret = 0;
2672
2673 if ((changed & BSS_CHANGED_BEACON_INT)) {
2674 wl1271_debug(DEBUG_MASTER, "beacon interval updated: %d",
2675 bss_conf->beacon_int);
2676
2677 wl->beacon_int = bss_conf->beacon_int;
2678 }
2679
2680 if ((changed & BSS_CHANGED_BEACON)) {
2681 struct ieee80211_hdr *hdr;
2682 int ieoffset = offsetof(struct ieee80211_mgmt,
2683 u.beacon.variable);
2684 struct sk_buff *beacon = ieee80211_beacon_get(wl->hw, vif);
2685 u16 tmpl_id;
2686
2687 if (!beacon)
2688 goto out;
2689
2690 wl1271_debug(DEBUG_MASTER, "beacon updated");
2691
2692 ret = wl1271_ssid_set(wl, beacon, ieoffset);
2693 if (ret < 0) {
2694 dev_kfree_skb(beacon);
2695 goto out;
2696 }
2697 tmpl_id = is_ap ? CMD_TEMPL_AP_BEACON :
2698 CMD_TEMPL_BEACON;
2699 ret = wl1271_cmd_template_set(wl, tmpl_id,
2700 beacon->data,
2701 beacon->len, 0,
2702 wl1271_tx_min_rate_get(wl));
2703 if (ret < 0) {
2704 dev_kfree_skb(beacon);
2705 goto out;
2706 }
2707
2708 hdr = (struct ieee80211_hdr *) beacon->data;
2709 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2710 IEEE80211_STYPE_PROBE_RESP);
2711
2712 tmpl_id = is_ap ? CMD_TEMPL_AP_PROBE_RESPONSE :
2713 CMD_TEMPL_PROBE_RESPONSE;
2714 ret = wl1271_cmd_template_set(wl,
2715 tmpl_id,
2716 beacon->data,
2717 beacon->len, 0,
2718 wl1271_tx_min_rate_get(wl));
2719 dev_kfree_skb(beacon);
2720 if (ret < 0)
2721 goto out;
2722 }
2723
2724out:
2725 return ret;
2726}
2727
2728/* AP mode changes */
2729static void wl1271_bss_info_changed_ap(struct wl1271 *wl,
2730 struct ieee80211_vif *vif,
2731 struct ieee80211_bss_conf *bss_conf,
2732 u32 changed)
2733{
2734 int ret = 0;
2735
2736 if ((changed & BSS_CHANGED_BASIC_RATES)) {
2737 u32 rates = bss_conf->basic_rates;
2738
2739 wl->basic_rate_set = wl1271_tx_enabled_rates_get(wl, rates);
2740 wl->basic_rate = wl1271_tx_min_rate_get(wl);
2741
2742 ret = wl1271_init_ap_rates(wl);
2743 if (ret < 0) {
2744 wl1271_error("AP rate policy change failed %d", ret);
2745 goto out;
2746 }
2747
2748 ret = wl1271_ap_init_templates(wl);
2749 if (ret < 0)
2750 goto out;
2751 }
2752
2753 ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, changed);
2754 if (ret < 0)
2755 goto out;
2756
2757 if ((changed & BSS_CHANGED_BEACON_ENABLED)) {
2758 if (bss_conf->enable_beacon) {
2759 if (!test_bit(WL1271_FLAG_AP_STARTED, &wl->flags)) {
2760 ret = wl1271_cmd_start_bss(wl);
2761 if (ret < 0)
2762 goto out;
2763
2764 set_bit(WL1271_FLAG_AP_STARTED, &wl->flags);
2765 wl1271_debug(DEBUG_AP, "started AP");
2766
2767 ret = wl1271_ap_init_hwenc(wl);
2768 if (ret < 0)
2769 goto out;
2770 }
2771 } else {
2772 if (test_bit(WL1271_FLAG_AP_STARTED, &wl->flags)) {
2773 ret = wl1271_cmd_stop_bss(wl);
2774 if (ret < 0)
2775 goto out;
2776
2777 clear_bit(WL1271_FLAG_AP_STARTED, &wl->flags);
2778 wl1271_debug(DEBUG_AP, "stopped AP");
2779 }
2780 }
2781 }
2782
2783 if (changed & BSS_CHANGED_IBSS) {
2784 wl1271_debug(DEBUG_ADHOC, "ibss_joined: %d",
2785 bss_conf->ibss_joined);
2786
2787 if (bss_conf->ibss_joined) {
2788 u32 rates = bss_conf->basic_rates;
2789 wl->basic_rate_set = wl1271_tx_enabled_rates_get(wl,
2790 rates);
2791 wl->basic_rate = wl1271_tx_min_rate_get(wl);
2792
2793 /* by default, use 11b rates */
2794 wl->rate_set = CONF_TX_IBSS_DEFAULT_RATES;
2795 ret = wl1271_acx_sta_rate_policies(wl);
2796 if (ret < 0)
2797 goto out;
2798 }
2799 }
2800
2801 ret = wl1271_bss_erp_info_changed(wl, bss_conf, changed);
2802 if (ret < 0)
2803 goto out;
2804out:
2805 return;
2806}
2807
2808/* STA/IBSS mode changes */
2809static void wl1271_bss_info_changed_sta(struct wl1271 *wl,
2810 struct ieee80211_vif *vif,
2811 struct ieee80211_bss_conf *bss_conf,
2812 u32 changed)
2813{
2814 bool do_join = false, set_assoc = false;
2815 bool is_ibss = (wl->bss_type == BSS_TYPE_IBSS);
2816 u32 sta_rate_set = 0;
2817 int ret;
2818 struct ieee80211_sta *sta;
2819 bool sta_exists = false;
2820 struct ieee80211_sta_ht_cap sta_ht_cap;
2821
2822 if (is_ibss) {
2823 ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf,
2824 changed);
2825 if (ret < 0)
2826 goto out;
2827 }
2828
2829 if ((changed & BSS_CHANGED_BEACON_INT) && is_ibss)
2830 do_join = true;
2831
2832 /* Need to update the SSID (for filtering etc) */
2833 if ((changed & BSS_CHANGED_BEACON) && is_ibss)
2834 do_join = true;
2835
2836 if ((changed & BSS_CHANGED_BEACON_ENABLED) && is_ibss) {
2837 wl1271_debug(DEBUG_ADHOC, "ad-hoc beaconing: %s",
2838 bss_conf->enable_beacon ? "enabled" : "disabled");
2839
2840 if (bss_conf->enable_beacon)
2841 wl->set_bss_type = BSS_TYPE_IBSS;
2842 else
2843 wl->set_bss_type = BSS_TYPE_STA_BSS;
2844 do_join = true;
2845 }
2846
2847 if ((changed & BSS_CHANGED_CQM)) {
2848 bool enable = false;
2849 if (bss_conf->cqm_rssi_thold)
2850 enable = true;
2851 ret = wl1271_acx_rssi_snr_trigger(wl, enable,
2852 bss_conf->cqm_rssi_thold,
2853 bss_conf->cqm_rssi_hyst);
2854 if (ret < 0)
2855 goto out;
2856 wl->rssi_thold = bss_conf->cqm_rssi_thold;
2857 }
2858
2859 if ((changed & BSS_CHANGED_BSSID) &&
2860 /*
2861 * Now we know the correct bssid, so we send a new join command
2862 * and enable the BSSID filter
2863 */
2864 memcmp(wl->bssid, bss_conf->bssid, ETH_ALEN)) {
2865 memcpy(wl->bssid, bss_conf->bssid, ETH_ALEN);
2866
2867 if (!is_zero_ether_addr(wl->bssid)) {
2868 ret = wl1271_cmd_build_null_data(wl);
2869 if (ret < 0)
2870 goto out;
2871
2872 ret = wl1271_build_qos_null_data(wl);
2873 if (ret < 0)
2874 goto out;
2875
2876 /* filter out all packets not from this BSSID */
2877 wl1271_configure_filters(wl, 0);
2878
2879 /* Need to update the BSSID (for filtering etc) */
2880 do_join = true;
2881 }
2882 }
2883
2884 rcu_read_lock();
2885 sta = ieee80211_find_sta(vif, bss_conf->bssid);
2886 if (sta) {
2887 /* save the supp_rates of the ap */
2888 sta_rate_set = sta->supp_rates[wl->hw->conf.channel->band];
2889 if (sta->ht_cap.ht_supported)
2890 sta_rate_set |=
2891 (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET);
2892 sta_ht_cap = sta->ht_cap;
2893 sta_exists = true;
2894 }
2895 rcu_read_unlock();
2896
2897 if (sta_exists) {
2898 /* handle new association with HT and HT information change */
2899 if ((changed & BSS_CHANGED_HT) &&
2900 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
2901 ret = wl1271_acx_set_ht_capabilities(wl, &sta_ht_cap,
2902 true);
2903 if (ret < 0) {
2904 wl1271_warning("Set ht cap true failed %d",
2905 ret);
2906 goto out;
2907 }
2908 ret = wl1271_acx_set_ht_information(wl,
2909 bss_conf->ht_operation_mode);
2910 if (ret < 0) {
2911 wl1271_warning("Set ht information failed %d",
2912 ret);
2913 goto out;
2914 }
2915 }
2916 /* handle new association without HT and disassociation */
2917 else if (changed & BSS_CHANGED_ASSOC) {
2918 ret = wl1271_acx_set_ht_capabilities(wl, &sta_ht_cap,
2919 false);
2920 if (ret < 0) {
2921 wl1271_warning("Set ht cap false failed %d",
2922 ret);
2923 goto out;
2924 }
2925 }
2926 }
2927
2928 if ((changed & BSS_CHANGED_ASSOC)) {
2929 if (bss_conf->assoc) {
2930 u32 rates;
2931 int ieoffset;
2932 wl->aid = bss_conf->aid;
2933 set_assoc = true;
2934
2935 wl->ps_poll_failures = 0;
2936
2937 /*
2938 * use basic rates from AP, and determine lowest rate
2939 * to use with control frames.
2940 */
2941 rates = bss_conf->basic_rates;
2942 wl->basic_rate_set = wl1271_tx_enabled_rates_get(wl,
2943 rates);
2944 wl->basic_rate = wl1271_tx_min_rate_get(wl);
2945 if (sta_rate_set)
2946 wl->rate_set = wl1271_tx_enabled_rates_get(wl,
2947 sta_rate_set);
2948 ret = wl1271_acx_sta_rate_policies(wl);
2949 if (ret < 0)
2950 goto out;
2951
2952 /*
2953 * with wl1271, we don't need to update the
2954 * beacon_int and dtim_period, because the firmware
2955 * updates it by itself when the first beacon is
2956 * received after a join.
2957 */
2958 ret = wl1271_cmd_build_ps_poll(wl, wl->aid);
2959 if (ret < 0)
2960 goto out;
2961
2962 /*
2963 * Get a template for hardware connection maintenance
2964 */
2965 dev_kfree_skb(wl->probereq);
2966 wl->probereq = wl1271_cmd_build_ap_probe_req(wl, NULL);
2967 ieoffset = offsetof(struct ieee80211_mgmt,
2968 u.probe_req.variable);
2969 wl1271_ssid_set(wl, wl->probereq, ieoffset);
2970
2971 /* enable the connection monitoring feature */
2972 ret = wl1271_acx_conn_monit_params(wl, true);
2973 if (ret < 0)
2974 goto out;
2975
2976 /* If we want to go in PSM but we're not there yet */
2977 if (test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags) &&
2978 !test_bit(WL1271_FLAG_PSM, &wl->flags)) {
2979 enum wl1271_cmd_ps_mode mode;
2980
2981 mode = STATION_POWER_SAVE_MODE;
2982 ret = wl1271_ps_set_mode(wl, mode,
2983 wl->basic_rate,
2984 true);
2985 if (ret < 0)
2986 goto out;
2987 }
2988 } else {
2989 /* use defaults when not associated */
2990 bool was_assoc =
2991 !!test_and_clear_bit(WL1271_FLAG_STA_ASSOCIATED,
2992 &wl->flags);
2993 clear_bit(WL1271_FLAG_STA_STATE_SENT, &wl->flags);
2994 wl->aid = 0;
2995
2996 /* free probe-request template */
2997 dev_kfree_skb(wl->probereq);
2998 wl->probereq = NULL;
2999
3000 /* re-enable dynamic ps - just in case */
3001 ieee80211_enable_dyn_ps(wl->vif);
3002
3003 /* revert back to minimum rates for the current band */
3004 wl1271_set_band_rate(wl);
3005 wl->basic_rate = wl1271_tx_min_rate_get(wl);
3006 ret = wl1271_acx_sta_rate_policies(wl);
3007 if (ret < 0)
3008 goto out;
3009
3010 /* disable connection monitor features */
3011 ret = wl1271_acx_conn_monit_params(wl, false);
3012
3013 /* Disable the keep-alive feature */
3014 ret = wl1271_acx_keep_alive_mode(wl, false);
3015 if (ret < 0)
3016 goto out;
3017
3018 /* restore the bssid filter and go to dummy bssid */
3019 if (was_assoc) {
3020 wl1271_unjoin(wl);
3021 wl1271_dummy_join(wl);
3022 }
3023 }
3024 }
3025
3026 ret = wl1271_bss_erp_info_changed(wl, bss_conf, changed);
3027 if (ret < 0)
3028 goto out;
3029
3030 if (changed & BSS_CHANGED_ARP_FILTER) {
3031 __be32 addr = bss_conf->arp_addr_list[0];
3032 WARN_ON(wl->bss_type != BSS_TYPE_STA_BSS);
3033
3034 if (bss_conf->arp_addr_cnt == 1 &&
3035 bss_conf->arp_filter_enabled) {
3036 /*
3037 * The template should have been configured only upon
3038 * association. however, it seems that the correct ip
3039 * isn't being set (when sending), so we have to
3040 * reconfigure the template upon every ip change.
3041 */
3042 ret = wl1271_cmd_build_arp_rsp(wl, addr);
3043 if (ret < 0) {
3044 wl1271_warning("build arp rsp failed: %d", ret);
3045 goto out;
3046 }
3047
3048 ret = wl1271_acx_arp_ip_filter(wl,
3049 ACX_ARP_FILTER_ARP_FILTERING,
3050 addr);
3051 } else
3052 ret = wl1271_acx_arp_ip_filter(wl, 0, addr);
3053
3054 if (ret < 0)
3055 goto out;
3056 }
3057
3058 if (do_join) {
3059 ret = wl1271_join(wl, set_assoc);
3060 if (ret < 0) {
3061 wl1271_warning("cmd join failed %d", ret);
3062 goto out;
3063 }
3064 }
3065
3066out:
3067 return;
3068}
3069
3070static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
3071 struct ieee80211_vif *vif,
3072 struct ieee80211_bss_conf *bss_conf,
3073 u32 changed)
3074{
3075 struct wl1271 *wl = hw->priv;
3076 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
3077 int ret;
3078
3079 wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed 0x%x",
3080 (int)changed);
3081
3082 mutex_lock(&wl->mutex);
3083
3084 if (unlikely(wl->state == WL1271_STATE_OFF))
3085 goto out;
3086
3087 ret = wl1271_ps_elp_wakeup(wl);
3088 if (ret < 0)
3089 goto out;
3090
3091 if (is_ap)
3092 wl1271_bss_info_changed_ap(wl, vif, bss_conf, changed);
3093 else
3094 wl1271_bss_info_changed_sta(wl, vif, bss_conf, changed);
3095
3096 wl1271_ps_elp_sleep(wl);
3097
3098out:
3099 mutex_unlock(&wl->mutex);
3100}
3101
3102static int wl1271_op_conf_tx(struct ieee80211_hw *hw, u16 queue,
3103 const struct ieee80211_tx_queue_params *params)
3104{
3105 struct wl1271 *wl = hw->priv;
3106 u8 ps_scheme;
3107 int ret = 0;
3108
3109 mutex_lock(&wl->mutex);
3110
3111 wl1271_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue);
3112
3113 if (params->uapsd)
3114 ps_scheme = CONF_PS_SCHEME_UPSD_TRIGGER;
3115 else
3116 ps_scheme = CONF_PS_SCHEME_LEGACY;
3117
3118 if (wl->state == WL1271_STATE_OFF) {
3119 /*
3120 * If the state is off, the parameters will be recorded and
3121 * configured on init. This happens in AP-mode.
3122 */
3123 struct conf_tx_ac_category *conf_ac =
3124 &wl->conf.tx.ac_conf[wl1271_tx_get_queue(queue)];
3125 struct conf_tx_tid *conf_tid =
3126 &wl->conf.tx.tid_conf[wl1271_tx_get_queue(queue)];
3127
3128 conf_ac->ac = wl1271_tx_get_queue(queue);
3129 conf_ac->cw_min = (u8)params->cw_min;
3130 conf_ac->cw_max = params->cw_max;
3131 conf_ac->aifsn = params->aifs;
3132 conf_ac->tx_op_limit = params->txop << 5;
3133
3134 conf_tid->queue_id = wl1271_tx_get_queue(queue);
3135 conf_tid->channel_type = CONF_CHANNEL_TYPE_EDCF;
3136 conf_tid->tsid = wl1271_tx_get_queue(queue);
3137 conf_tid->ps_scheme = ps_scheme;
3138 conf_tid->ack_policy = CONF_ACK_POLICY_LEGACY;
3139 conf_tid->apsd_conf[0] = 0;
3140 conf_tid->apsd_conf[1] = 0;
3141 goto out;
3142 }
3143
3144 ret = wl1271_ps_elp_wakeup(wl);
3145 if (ret < 0)
3146 goto out;
3147
3148 /*
3149 * the txop is confed in units of 32us by the mac80211,
3150 * we need us
3151 */
3152 ret = wl1271_acx_ac_cfg(wl, wl1271_tx_get_queue(queue),
3153 params->cw_min, params->cw_max,
3154 params->aifs, params->txop << 5);
3155 if (ret < 0)
3156 goto out_sleep;
3157
3158 ret = wl1271_acx_tid_cfg(wl, wl1271_tx_get_queue(queue),
3159 CONF_CHANNEL_TYPE_EDCF,
3160 wl1271_tx_get_queue(queue),
3161 ps_scheme, CONF_ACK_POLICY_LEGACY,
3162 0, 0);
3163
3164out_sleep:
3165 wl1271_ps_elp_sleep(wl);
3166
3167out:
3168 mutex_unlock(&wl->mutex);
3169
3170 return ret;
3171}
3172
3173static u64 wl1271_op_get_tsf(struct ieee80211_hw *hw)
3174{
3175
3176 struct wl1271 *wl = hw->priv;
3177 u64 mactime = ULLONG_MAX;
3178 int ret;
3179
3180 wl1271_debug(DEBUG_MAC80211, "mac80211 get tsf");
3181
3182 mutex_lock(&wl->mutex);
3183
3184 if (unlikely(wl->state == WL1271_STATE_OFF))
3185 goto out;
3186
3187 ret = wl1271_ps_elp_wakeup(wl);
3188 if (ret < 0)
3189 goto out;
3190
3191 ret = wl1271_acx_tsf_info(wl, &mactime);
3192 if (ret < 0)
3193 goto out_sleep;
3194
3195out_sleep:
3196 wl1271_ps_elp_sleep(wl);
3197
3198out:
3199 mutex_unlock(&wl->mutex);
3200 return mactime;
3201}
3202
3203static int wl1271_op_get_survey(struct ieee80211_hw *hw, int idx,
3204 struct survey_info *survey)
3205{
3206 struct wl1271 *wl = hw->priv;
3207 struct ieee80211_conf *conf = &hw->conf;
3208
3209 if (idx != 0)
3210 return -ENOENT;
3211
3212 survey->channel = conf->channel;
3213 survey->filled = SURVEY_INFO_NOISE_DBM;
3214 survey->noise = wl->noise;
3215
3216 return 0;
3217}
3218
3219static int wl1271_allocate_sta(struct wl1271 *wl,
3220 struct ieee80211_sta *sta,
3221 u8 *hlid)
3222{
3223 struct wl1271_station *wl_sta;
3224 int id;
3225
3226 id = find_first_zero_bit(wl->ap_hlid_map, AP_MAX_STATIONS);
3227 if (id >= AP_MAX_STATIONS) {
3228 wl1271_warning("could not allocate HLID - too much stations");
3229 return -EBUSY;
3230 }
3231
3232 wl_sta = (struct wl1271_station *)sta->drv_priv;
3233 __set_bit(id, wl->ap_hlid_map);
3234 wl_sta->hlid = WL1271_AP_STA_HLID_START + id;
3235 *hlid = wl_sta->hlid;
3236 memcpy(wl->links[wl_sta->hlid].addr, sta->addr, ETH_ALEN);
3237 return 0;
3238}
3239
3240static void wl1271_free_sta(struct wl1271 *wl, u8 hlid)
3241{
3242 int id = hlid - WL1271_AP_STA_HLID_START;
3243
3244 if (WARN_ON(!test_bit(id, wl->ap_hlid_map)))
3245 return;
3246
3247 __clear_bit(id, wl->ap_hlid_map);
3248 memset(wl->links[hlid].addr, 0, ETH_ALEN);
3249 wl1271_tx_reset_link_queues(wl, hlid);
3250 __clear_bit(hlid, &wl->ap_ps_map);
3251 __clear_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
3252}
3253
3254static int wl1271_op_sta_add(struct ieee80211_hw *hw,
3255 struct ieee80211_vif *vif,
3256 struct ieee80211_sta *sta)
3257{
3258 struct wl1271 *wl = hw->priv;
3259 int ret = 0;
3260 u8 hlid;
3261
3262 mutex_lock(&wl->mutex);
3263
3264 if (unlikely(wl->state == WL1271_STATE_OFF))
3265 goto out;
3266
3267 if (wl->bss_type != BSS_TYPE_AP_BSS)
3268 goto out;
3269
3270 wl1271_debug(DEBUG_MAC80211, "mac80211 add sta %d", (int)sta->aid);
3271
3272 ret = wl1271_allocate_sta(wl, sta, &hlid);
3273 if (ret < 0)
3274 goto out;
3275
3276 ret = wl1271_ps_elp_wakeup(wl);
3277 if (ret < 0)
3278 goto out_free_sta;
3279
3280 ret = wl1271_cmd_add_sta(wl, sta, hlid);
3281 if (ret < 0)
3282 goto out_sleep;
3283
3284out_sleep:
3285 wl1271_ps_elp_sleep(wl);
3286
3287out_free_sta:
3288 if (ret < 0)
3289 wl1271_free_sta(wl, hlid);
3290
3291out:
3292 mutex_unlock(&wl->mutex);
3293 return ret;
3294}
3295
3296static int wl1271_op_sta_remove(struct ieee80211_hw *hw,
3297 struct ieee80211_vif *vif,
3298 struct ieee80211_sta *sta)
3299{
3300 struct wl1271 *wl = hw->priv;
3301 struct wl1271_station *wl_sta;
3302 int ret = 0, id;
3303
3304 mutex_lock(&wl->mutex);
3305
3306 if (unlikely(wl->state == WL1271_STATE_OFF))
3307 goto out;
3308
3309 if (wl->bss_type != BSS_TYPE_AP_BSS)
3310 goto out;
3311
3312 wl1271_debug(DEBUG_MAC80211, "mac80211 remove sta %d", (int)sta->aid);
3313
3314 wl_sta = (struct wl1271_station *)sta->drv_priv;
3315 id = wl_sta->hlid - WL1271_AP_STA_HLID_START;
3316 if (WARN_ON(!test_bit(id, wl->ap_hlid_map)))
3317 goto out;
3318
3319 ret = wl1271_ps_elp_wakeup(wl);
3320 if (ret < 0)
3321 goto out;
3322
3323 ret = wl1271_cmd_remove_sta(wl, wl_sta->hlid);
3324 if (ret < 0)
3325 goto out_sleep;
3326
3327 wl1271_free_sta(wl, wl_sta->hlid);
3328
3329out_sleep:
3330 wl1271_ps_elp_sleep(wl);
3331
3332out:
3333 mutex_unlock(&wl->mutex);
3334 return ret;
3335}
3336
3337static int wl1271_op_ampdu_action(struct ieee80211_hw *hw,
3338 struct ieee80211_vif *vif,
3339 enum ieee80211_ampdu_mlme_action action,
3340 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
3341 u8 buf_size)
3342{
3343 struct wl1271 *wl = hw->priv;
3344 int ret;
3345
3346 mutex_lock(&wl->mutex);
3347
3348 if (unlikely(wl->state == WL1271_STATE_OFF)) {
3349 ret = -EAGAIN;
3350 goto out;
3351 }
3352
3353 ret = wl1271_ps_elp_wakeup(wl);
3354 if (ret < 0)
3355 goto out;
3356
3357 switch (action) {
3358 case IEEE80211_AMPDU_RX_START:
3359 if (wl->ba_support) {
3360 ret = wl1271_acx_set_ba_receiver_session(wl, tid, *ssn,
3361 true);
3362 if (!ret)
3363 wl->ba_rx_bitmap |= BIT(tid);
3364 } else {
3365 ret = -ENOTSUPP;
3366 }
3367 break;
3368
3369 case IEEE80211_AMPDU_RX_STOP:
3370 ret = wl1271_acx_set_ba_receiver_session(wl, tid, 0, false);
3371 if (!ret)
3372 wl->ba_rx_bitmap &= ~BIT(tid);
3373 break;
3374
3375 /*
3376 * The BA initiator session management in FW independently.
3377 * Falling break here on purpose for all TX APDU commands.
3378 */
3379 case IEEE80211_AMPDU_TX_START:
3380 case IEEE80211_AMPDU_TX_STOP:
3381 case IEEE80211_AMPDU_TX_OPERATIONAL:
3382 ret = -EINVAL;
3383 break;
3384
3385 default:
3386 wl1271_error("Incorrect ampdu action id=%x\n", action);
3387 ret = -EINVAL;
3388 }
3389
3390 wl1271_ps_elp_sleep(wl);
3391
3392out:
3393 mutex_unlock(&wl->mutex);
3394
3395 return ret;
3396}
3397
3398static bool wl1271_tx_frames_pending(struct ieee80211_hw *hw)
3399{
3400 struct wl1271 *wl = hw->priv;
3401 bool ret = false;
3402
3403 mutex_lock(&wl->mutex);
3404
3405 if (unlikely(wl->state == WL1271_STATE_OFF))
3406 goto out;
3407
3408 /* packets are considered pending if in the TX queue or the FW */
3409 ret = (wl->tx_queue_count > 0) || (wl->tx_frames_cnt > 0);
3410
3411 /* the above is appropriate for STA mode for PS purposes */
3412 WARN_ON(wl->bss_type != BSS_TYPE_STA_BSS);
3413
3414out:
3415 mutex_unlock(&wl->mutex);
3416
3417 return ret;
3418}
3419
3420/* can't be const, mac80211 writes to this */
3421static struct ieee80211_rate wl1271_rates[] = {
3422 { .bitrate = 10,
3423 .hw_value = CONF_HW_BIT_RATE_1MBPS,
3424 .hw_value_short = CONF_HW_BIT_RATE_1MBPS, },
3425 { .bitrate = 20,
3426 .hw_value = CONF_HW_BIT_RATE_2MBPS,
3427 .hw_value_short = CONF_HW_BIT_RATE_2MBPS,
3428 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
3429 { .bitrate = 55,
3430 .hw_value = CONF_HW_BIT_RATE_5_5MBPS,
3431 .hw_value_short = CONF_HW_BIT_RATE_5_5MBPS,
3432 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
3433 { .bitrate = 110,
3434 .hw_value = CONF_HW_BIT_RATE_11MBPS,
3435 .hw_value_short = CONF_HW_BIT_RATE_11MBPS,
3436 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
3437 { .bitrate = 60,
3438 .hw_value = CONF_HW_BIT_RATE_6MBPS,
3439 .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
3440 { .bitrate = 90,
3441 .hw_value = CONF_HW_BIT_RATE_9MBPS,
3442 .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
3443 { .bitrate = 120,
3444 .hw_value = CONF_HW_BIT_RATE_12MBPS,
3445 .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
3446 { .bitrate = 180,
3447 .hw_value = CONF_HW_BIT_RATE_18MBPS,
3448 .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
3449 { .bitrate = 240,
3450 .hw_value = CONF_HW_BIT_RATE_24MBPS,
3451 .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
3452 { .bitrate = 360,
3453 .hw_value = CONF_HW_BIT_RATE_36MBPS,
3454 .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
3455 { .bitrate = 480,
3456 .hw_value = CONF_HW_BIT_RATE_48MBPS,
3457 .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
3458 { .bitrate = 540,
3459 .hw_value = CONF_HW_BIT_RATE_54MBPS,
3460 .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
3461};
3462
3463/* can't be const, mac80211 writes to this */
3464static struct ieee80211_channel wl1271_channels[] = {
3465 { .hw_value = 1, .center_freq = 2412, .max_power = 25 },
3466 { .hw_value = 2, .center_freq = 2417, .max_power = 25 },
3467 { .hw_value = 3, .center_freq = 2422, .max_power = 25 },
3468 { .hw_value = 4, .center_freq = 2427, .max_power = 25 },
3469 { .hw_value = 5, .center_freq = 2432, .max_power = 25 },
3470 { .hw_value = 6, .center_freq = 2437, .max_power = 25 },
3471 { .hw_value = 7, .center_freq = 2442, .max_power = 25 },
3472 { .hw_value = 8, .center_freq = 2447, .max_power = 25 },
3473 { .hw_value = 9, .center_freq = 2452, .max_power = 25 },
3474 { .hw_value = 10, .center_freq = 2457, .max_power = 25 },
3475 { .hw_value = 11, .center_freq = 2462, .max_power = 25 },
3476 { .hw_value = 12, .center_freq = 2467, .max_power = 25 },
3477 { .hw_value = 13, .center_freq = 2472, .max_power = 25 },
3478 { .hw_value = 14, .center_freq = 2484, .max_power = 25 },
3479};
3480
3481/* mapping to indexes for wl1271_rates */
3482static const u8 wl1271_rate_to_idx_2ghz[] = {
3483 /* MCS rates are used only with 11n */
3484 7, /* CONF_HW_RXTX_RATE_MCS7 */
3485 6, /* CONF_HW_RXTX_RATE_MCS6 */
3486 5, /* CONF_HW_RXTX_RATE_MCS5 */
3487 4, /* CONF_HW_RXTX_RATE_MCS4 */
3488 3, /* CONF_HW_RXTX_RATE_MCS3 */
3489 2, /* CONF_HW_RXTX_RATE_MCS2 */
3490 1, /* CONF_HW_RXTX_RATE_MCS1 */
3491 0, /* CONF_HW_RXTX_RATE_MCS0 */
3492
3493 11, /* CONF_HW_RXTX_RATE_54 */
3494 10, /* CONF_HW_RXTX_RATE_48 */
3495 9, /* CONF_HW_RXTX_RATE_36 */
3496 8, /* CONF_HW_RXTX_RATE_24 */
3497
3498 /* TI-specific rate */
3499 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_22 */
3500
3501 7, /* CONF_HW_RXTX_RATE_18 */
3502 6, /* CONF_HW_RXTX_RATE_12 */
3503 3, /* CONF_HW_RXTX_RATE_11 */
3504 5, /* CONF_HW_RXTX_RATE_9 */
3505 4, /* CONF_HW_RXTX_RATE_6 */
3506 2, /* CONF_HW_RXTX_RATE_5_5 */
3507 1, /* CONF_HW_RXTX_RATE_2 */
3508 0 /* CONF_HW_RXTX_RATE_1 */
3509};
3510
3511/* 11n STA capabilities */
3512#define HW_RX_HIGHEST_RATE 72
3513
3514#ifdef CONFIG_WL12XX_HT
3515#define WL12XX_HT_CAP { \
3516 .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 | \
3517 (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT), \
3518 .ht_supported = true, \
3519 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K, \
3520 .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, \
3521 .mcs = { \
3522 .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, \
3523 .rx_highest = cpu_to_le16(HW_RX_HIGHEST_RATE), \
3524 .tx_params = IEEE80211_HT_MCS_TX_DEFINED, \
3525 }, \
3526}
3527#else
3528#define WL12XX_HT_CAP { \
3529 .ht_supported = false, \
3530}
3531#endif
3532
3533/* can't be const, mac80211 writes to this */
3534static struct ieee80211_supported_band wl1271_band_2ghz = {
3535 .channels = wl1271_channels,
3536 .n_channels = ARRAY_SIZE(wl1271_channels),
3537 .bitrates = wl1271_rates,
3538 .n_bitrates = ARRAY_SIZE(wl1271_rates),
3539 .ht_cap = WL12XX_HT_CAP,
3540};
3541
3542/* 5 GHz data rates for WL1273 */
3543static struct ieee80211_rate wl1271_rates_5ghz[] = {
3544 { .bitrate = 60,
3545 .hw_value = CONF_HW_BIT_RATE_6MBPS,
3546 .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
3547 { .bitrate = 90,
3548 .hw_value = CONF_HW_BIT_RATE_9MBPS,
3549 .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
3550 { .bitrate = 120,
3551 .hw_value = CONF_HW_BIT_RATE_12MBPS,
3552 .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
3553 { .bitrate = 180,
3554 .hw_value = CONF_HW_BIT_RATE_18MBPS,
3555 .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
3556 { .bitrate = 240,
3557 .hw_value = CONF_HW_BIT_RATE_24MBPS,
3558 .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
3559 { .bitrate = 360,
3560 .hw_value = CONF_HW_BIT_RATE_36MBPS,
3561 .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
3562 { .bitrate = 480,
3563 .hw_value = CONF_HW_BIT_RATE_48MBPS,
3564 .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
3565 { .bitrate = 540,
3566 .hw_value = CONF_HW_BIT_RATE_54MBPS,
3567 .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
3568};
3569
3570/* 5 GHz band channels for WL1273 */
3571static struct ieee80211_channel wl1271_channels_5ghz[] = {
3572 { .hw_value = 7, .center_freq = 5035},
3573 { .hw_value = 8, .center_freq = 5040},
3574 { .hw_value = 9, .center_freq = 5045},
3575 { .hw_value = 11, .center_freq = 5055},
3576 { .hw_value = 12, .center_freq = 5060},
3577 { .hw_value = 16, .center_freq = 5080},
3578 { .hw_value = 34, .center_freq = 5170},
3579 { .hw_value = 36, .center_freq = 5180},
3580 { .hw_value = 38, .center_freq = 5190},
3581 { .hw_value = 40, .center_freq = 5200},
3582 { .hw_value = 42, .center_freq = 5210},
3583 { .hw_value = 44, .center_freq = 5220},
3584 { .hw_value = 46, .center_freq = 5230},
3585 { .hw_value = 48, .center_freq = 5240},
3586 { .hw_value = 52, .center_freq = 5260},
3587 { .hw_value = 56, .center_freq = 5280},
3588 { .hw_value = 60, .center_freq = 5300},
3589 { .hw_value = 64, .center_freq = 5320},
3590 { .hw_value = 100, .center_freq = 5500},
3591 { .hw_value = 104, .center_freq = 5520},
3592 { .hw_value = 108, .center_freq = 5540},
3593 { .hw_value = 112, .center_freq = 5560},
3594 { .hw_value = 116, .center_freq = 5580},
3595 { .hw_value = 120, .center_freq = 5600},
3596 { .hw_value = 124, .center_freq = 5620},
3597 { .hw_value = 128, .center_freq = 5640},
3598 { .hw_value = 132, .center_freq = 5660},
3599 { .hw_value = 136, .center_freq = 5680},
3600 { .hw_value = 140, .center_freq = 5700},
3601 { .hw_value = 149, .center_freq = 5745},
3602 { .hw_value = 153, .center_freq = 5765},
3603 { .hw_value = 157, .center_freq = 5785},
3604 { .hw_value = 161, .center_freq = 5805},
3605 { .hw_value = 165, .center_freq = 5825},
3606};
3607
3608/* mapping to indexes for wl1271_rates_5ghz */
3609static const u8 wl1271_rate_to_idx_5ghz[] = {
3610 /* MCS rates are used only with 11n */
3611 7, /* CONF_HW_RXTX_RATE_MCS7 */
3612 6, /* CONF_HW_RXTX_RATE_MCS6 */
3613 5, /* CONF_HW_RXTX_RATE_MCS5 */
3614 4, /* CONF_HW_RXTX_RATE_MCS4 */
3615 3, /* CONF_HW_RXTX_RATE_MCS3 */
3616 2, /* CONF_HW_RXTX_RATE_MCS2 */
3617 1, /* CONF_HW_RXTX_RATE_MCS1 */
3618 0, /* CONF_HW_RXTX_RATE_MCS0 */
3619
3620 7, /* CONF_HW_RXTX_RATE_54 */
3621 6, /* CONF_HW_RXTX_RATE_48 */
3622 5, /* CONF_HW_RXTX_RATE_36 */
3623 4, /* CONF_HW_RXTX_RATE_24 */
3624
3625 /* TI-specific rate */
3626 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_22 */
3627
3628 3, /* CONF_HW_RXTX_RATE_18 */
3629 2, /* CONF_HW_RXTX_RATE_12 */
3630 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_11 */
3631 1, /* CONF_HW_RXTX_RATE_9 */
3632 0, /* CONF_HW_RXTX_RATE_6 */
3633 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_5_5 */
3634 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_2 */
3635 CONF_HW_RXTX_RATE_UNSUPPORTED /* CONF_HW_RXTX_RATE_1 */
3636};
3637
3638static struct ieee80211_supported_band wl1271_band_5ghz = {
3639 .channels = wl1271_channels_5ghz,
3640 .n_channels = ARRAY_SIZE(wl1271_channels_5ghz),
3641 .bitrates = wl1271_rates_5ghz,
3642 .n_bitrates = ARRAY_SIZE(wl1271_rates_5ghz),
3643 .ht_cap = WL12XX_HT_CAP,
3644};
3645
3646static const u8 *wl1271_band_rate_to_idx[] = {
3647 [IEEE80211_BAND_2GHZ] = wl1271_rate_to_idx_2ghz,
3648 [IEEE80211_BAND_5GHZ] = wl1271_rate_to_idx_5ghz
3649};
3650
3651static const struct ieee80211_ops wl1271_ops = {
3652 .start = wl1271_op_start,
3653 .stop = wl1271_op_stop,
3654 .add_interface = wl1271_op_add_interface,
3655 .remove_interface = wl1271_op_remove_interface,
3656#ifdef CONFIG_PM
3657 .suspend = wl1271_op_suspend,
3658 .resume = wl1271_op_resume,
3659#endif
3660 .config = wl1271_op_config,
3661 .prepare_multicast = wl1271_op_prepare_multicast,
3662 .configure_filter = wl1271_op_configure_filter,
3663 .tx = wl1271_op_tx,
3664 .set_key = wl1271_op_set_key,
3665 .hw_scan = wl1271_op_hw_scan,
3666 .sched_scan_start = wl1271_op_sched_scan_start,
3667 .sched_scan_stop = wl1271_op_sched_scan_stop,
3668 .bss_info_changed = wl1271_op_bss_info_changed,
3669 .set_frag_threshold = wl1271_op_set_frag_threshold,
3670 .set_rts_threshold = wl1271_op_set_rts_threshold,
3671 .conf_tx = wl1271_op_conf_tx,
3672 .get_tsf = wl1271_op_get_tsf,
3673 .get_survey = wl1271_op_get_survey,
3674 .sta_add = wl1271_op_sta_add,
3675 .sta_remove = wl1271_op_sta_remove,
3676 .ampdu_action = wl1271_op_ampdu_action,
3677 .tx_frames_pending = wl1271_tx_frames_pending,
3678 CFG80211_TESTMODE_CMD(wl1271_tm_cmd)
3679};
3680
3681
3682u8 wl1271_rate_to_idx(int rate, enum ieee80211_band band)
3683{
3684 u8 idx;
3685
3686 BUG_ON(band >= sizeof(wl1271_band_rate_to_idx)/sizeof(u8 *));
3687
3688 if (unlikely(rate >= CONF_HW_RXTX_RATE_MAX)) {
3689 wl1271_error("Illegal RX rate from HW: %d", rate);
3690 return 0;
3691 }
3692
3693 idx = wl1271_band_rate_to_idx[band][rate];
3694 if (unlikely(idx == CONF_HW_RXTX_RATE_UNSUPPORTED)) {
3695 wl1271_error("Unsupported RX rate from HW: %d", rate);
3696 return 0;
3697 }
3698
3699 return idx;
3700}
3701
3702static ssize_t wl1271_sysfs_show_bt_coex_state(struct device *dev,
3703 struct device_attribute *attr,
3704 char *buf)
3705{
3706 struct wl1271 *wl = dev_get_drvdata(dev);
3707 ssize_t len;
3708
3709 len = PAGE_SIZE;
3710
3711 mutex_lock(&wl->mutex);
3712 len = snprintf(buf, len, "%d\n\n0 - off\n1 - on\n",
3713 wl->sg_enabled);
3714 mutex_unlock(&wl->mutex);
3715
3716 return len;
3717
3718}
3719
3720static ssize_t wl1271_sysfs_store_bt_coex_state(struct device *dev,
3721 struct device_attribute *attr,
3722 const char *buf, size_t count)
3723{
3724 struct wl1271 *wl = dev_get_drvdata(dev);
3725 unsigned long res;
3726 int ret;
3727
3728 ret = kstrtoul(buf, 10, &res);
3729 if (ret < 0) {
3730 wl1271_warning("incorrect value written to bt_coex_mode");
3731 return count;
3732 }
3733
3734 mutex_lock(&wl->mutex);
3735
3736 res = !!res;
3737
3738 if (res == wl->sg_enabled)
3739 goto out;
3740
3741 wl->sg_enabled = res;
3742
3743 if (wl->state == WL1271_STATE_OFF)
3744 goto out;
3745
3746 ret = wl1271_ps_elp_wakeup(wl);
3747 if (ret < 0)
3748 goto out;
3749
3750 wl1271_acx_sg_enable(wl, wl->sg_enabled);
3751 wl1271_ps_elp_sleep(wl);
3752
3753 out:
3754 mutex_unlock(&wl->mutex);
3755 return count;
3756}
3757
3758static DEVICE_ATTR(bt_coex_state, S_IRUGO | S_IWUSR,
3759 wl1271_sysfs_show_bt_coex_state,
3760 wl1271_sysfs_store_bt_coex_state);
3761
3762static ssize_t wl1271_sysfs_show_hw_pg_ver(struct device *dev,
3763 struct device_attribute *attr,
3764 char *buf)
3765{
3766 struct wl1271 *wl = dev_get_drvdata(dev);
3767 ssize_t len;
3768
3769 len = PAGE_SIZE;
3770
3771 mutex_lock(&wl->mutex);
3772 if (wl->hw_pg_ver >= 0)
3773 len = snprintf(buf, len, "%d\n", wl->hw_pg_ver);
3774 else
3775 len = snprintf(buf, len, "n/a\n");
3776 mutex_unlock(&wl->mutex);
3777
3778 return len;
3779}
3780
3781static DEVICE_ATTR(hw_pg_ver, S_IRUGO | S_IWUSR,
3782 wl1271_sysfs_show_hw_pg_ver, NULL);
3783
3784int wl1271_register_hw(struct wl1271 *wl)
3785{
3786 int ret;
3787
3788 if (wl->mac80211_registered)
3789 return 0;
3790
3791 ret = wl1271_fetch_nvs(wl);
3792 if (ret == 0) {
3793 /* NOTE: The wl->nvs->nvs element must be first, in
3794 * order to simplify the casting, we assume it is at
3795 * the beginning of the wl->nvs structure.
3796 */
3797 u8 *nvs_ptr = (u8 *)wl->nvs;
3798
3799 wl->mac_addr[0] = nvs_ptr[11];
3800 wl->mac_addr[1] = nvs_ptr[10];
3801 wl->mac_addr[2] = nvs_ptr[6];
3802 wl->mac_addr[3] = nvs_ptr[5];
3803 wl->mac_addr[4] = nvs_ptr[4];
3804 wl->mac_addr[5] = nvs_ptr[3];
3805 }
3806
3807 SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
3808
3809 ret = ieee80211_register_hw(wl->hw);
3810 if (ret < 0) {
3811 wl1271_error("unable to register mac80211 hw: %d", ret);
3812 return ret;
3813 }
3814
3815 wl->mac80211_registered = true;
3816
3817 wl1271_debugfs_init(wl);
3818
3819 register_netdevice_notifier(&wl1271_dev_notifier);
3820
3821 wl1271_notice("loaded");
3822
3823 return 0;
3824}
3825EXPORT_SYMBOL_GPL(wl1271_register_hw);
3826
3827void wl1271_unregister_hw(struct wl1271 *wl)
3828{
3829 if (wl->state == WL1271_STATE_PLT)
3830 __wl1271_plt_stop(wl);
3831
3832 unregister_netdevice_notifier(&wl1271_dev_notifier);
3833 ieee80211_unregister_hw(wl->hw);
3834 wl->mac80211_registered = false;
3835
3836}
3837EXPORT_SYMBOL_GPL(wl1271_unregister_hw);
3838
3839int wl1271_init_ieee80211(struct wl1271 *wl)
3840{
3841 static const u32 cipher_suites[] = {
3842 WLAN_CIPHER_SUITE_WEP40,
3843 WLAN_CIPHER_SUITE_WEP104,
3844 WLAN_CIPHER_SUITE_TKIP,
3845 WLAN_CIPHER_SUITE_CCMP,
3846 WL1271_CIPHER_SUITE_GEM,
3847 };
3848
3849 /* The tx descriptor buffer and the TKIP space. */
3850 wl->hw->extra_tx_headroom = WL1271_TKIP_IV_SPACE +
3851 sizeof(struct wl1271_tx_hw_descr);
3852
3853 /* unit us */
3854 /* FIXME: find a proper value */
3855 wl->hw->channel_change_time = 10000;
3856 wl->hw->max_listen_interval = wl->conf.conn.max_listen_interval;
3857
3858 wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
3859 IEEE80211_HW_BEACON_FILTER |
3860 IEEE80211_HW_SUPPORTS_PS |
3861 IEEE80211_HW_SUPPORTS_UAPSD |
3862 IEEE80211_HW_HAS_RATE_CONTROL |
3863 IEEE80211_HW_CONNECTION_MONITOR |
3864 IEEE80211_HW_SUPPORTS_CQM_RSSI |
3865 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
3866 IEEE80211_HW_SPECTRUM_MGMT |
3867 IEEE80211_HW_AP_LINK_PS;
3868
3869 wl->hw->wiphy->cipher_suites = cipher_suites;
3870 wl->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
3871
3872 wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
3873 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP);
3874 wl->hw->wiphy->max_scan_ssids = 1;
3875 /*
3876 * Maximum length of elements in scanning probe request templates
3877 * should be the maximum length possible for a template, without
3878 * the IEEE80211 header of the template
3879 */
3880 wl->hw->wiphy->max_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE -
3881 sizeof(struct ieee80211_header);
3882
3883 /* make sure all our channels fit in the scanned_ch bitmask */
3884 BUILD_BUG_ON(ARRAY_SIZE(wl1271_channels) +
3885 ARRAY_SIZE(wl1271_channels_5ghz) >
3886 WL1271_MAX_CHANNELS);
3887 /*
3888 * We keep local copies of the band structs because we need to
3889 * modify them on a per-device basis.
3890 */
3891 memcpy(&wl->bands[IEEE80211_BAND_2GHZ], &wl1271_band_2ghz,
3892 sizeof(wl1271_band_2ghz));
3893 memcpy(&wl->bands[IEEE80211_BAND_5GHZ], &wl1271_band_5ghz,
3894 sizeof(wl1271_band_5ghz));
3895
3896 wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
3897 &wl->bands[IEEE80211_BAND_2GHZ];
3898 wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
3899 &wl->bands[IEEE80211_BAND_5GHZ];
3900
3901 wl->hw->queues = 4;
3902 wl->hw->max_rates = 1;
3903
3904 wl->hw->wiphy->reg_notifier = wl1271_reg_notify;
3905
3906 SET_IEEE80211_DEV(wl->hw, wl1271_wl_to_dev(wl));
3907
3908 wl->hw->sta_data_size = sizeof(struct wl1271_station);
3909
3910 wl->hw->max_rx_aggregation_subframes = 8;
3911
3912 return 0;
3913}
3914EXPORT_SYMBOL_GPL(wl1271_init_ieee80211);
3915
3916#define WL1271_DEFAULT_CHANNEL 0
3917
3918struct ieee80211_hw *wl1271_alloc_hw(void)
3919{
3920 struct ieee80211_hw *hw;
3921 struct platform_device *plat_dev = NULL;
3922 struct wl1271 *wl;
3923 int i, j, ret;
3924 unsigned int order;
3925
3926 hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops);
3927 if (!hw) {
3928 wl1271_error("could not alloc ieee80211_hw");
3929 ret = -ENOMEM;
3930 goto err_hw_alloc;
3931 }
3932
3933 plat_dev = kmemdup(&wl1271_device, sizeof(wl1271_device), GFP_KERNEL);
3934 if (!plat_dev) {
3935 wl1271_error("could not allocate platform_device");
3936 ret = -ENOMEM;
3937 goto err_plat_alloc;
3938 }
3939
3940 wl = hw->priv;
3941 memset(wl, 0, sizeof(*wl));
3942
3943 INIT_LIST_HEAD(&wl->list);
3944
3945 wl->hw = hw;
3946 wl->plat_dev = plat_dev;
3947
3948 for (i = 0; i < NUM_TX_QUEUES; i++)
3949 skb_queue_head_init(&wl->tx_queue[i]);
3950
3951 for (i = 0; i < NUM_TX_QUEUES; i++)
3952 for (j = 0; j < AP_MAX_LINKS; j++)
3953 skb_queue_head_init(&wl->links[j].tx_queue[i]);
3954
3955 skb_queue_head_init(&wl->deferred_rx_queue);
3956 skb_queue_head_init(&wl->deferred_tx_queue);
3957
3958 INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work);
3959 INIT_DELAYED_WORK(&wl->pspoll_work, wl1271_pspoll_work);
3960 INIT_WORK(&wl->netstack_work, wl1271_netstack_work);
3961 INIT_WORK(&wl->tx_work, wl1271_tx_work);
3962 INIT_WORK(&wl->recovery_work, wl1271_recovery_work);
3963 INIT_DELAYED_WORK(&wl->scan_complete_work, wl1271_scan_complete_work);
3964 wl->channel = WL1271_DEFAULT_CHANNEL;
3965 wl->beacon_int = WL1271_DEFAULT_BEACON_INT;
3966 wl->default_key = 0;
3967 wl->rx_counter = 0;
3968 wl->rx_config = WL1271_DEFAULT_STA_RX_CONFIG;
3969 wl->rx_filter = WL1271_DEFAULT_STA_RX_FILTER;
3970 wl->psm_entry_retry = 0;
3971 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
3972 wl->basic_rate_set = CONF_TX_RATE_MASK_BASIC;
3973 wl->basic_rate = CONF_TX_RATE_MASK_BASIC;
3974 wl->rate_set = CONF_TX_RATE_MASK_BASIC;
3975 wl->band = IEEE80211_BAND_2GHZ;
3976 wl->vif = NULL;
3977 wl->flags = 0;
3978 wl->sg_enabled = true;
3979 wl->hw_pg_ver = -1;
3980 wl->bss_type = MAX_BSS_TYPE;
3981 wl->set_bss_type = MAX_BSS_TYPE;
3982 wl->fw_bss_type = MAX_BSS_TYPE;
3983 wl->last_tx_hlid = 0;
3984 wl->ap_ps_map = 0;
3985 wl->ap_fw_ps_map = 0;
3986 wl->quirks = 0;
3987 wl->platform_quirks = 0;
3988 wl->sched_scanning = false;
3989
3990 memset(wl->tx_frames_map, 0, sizeof(wl->tx_frames_map));
3991 for (i = 0; i < ACX_TX_DESCRIPTORS; i++)
3992 wl->tx_frames[i] = NULL;
3993
3994 spin_lock_init(&wl->wl_lock);
3995
3996 wl->state = WL1271_STATE_OFF;
3997 mutex_init(&wl->mutex);
3998
3999 /* Apply default driver configuration. */
4000 wl1271_conf_init(wl);
4001
4002 order = get_order(WL1271_AGGR_BUFFER_SIZE);
4003 wl->aggr_buf = (u8 *)__get_free_pages(GFP_KERNEL, order);
4004 if (!wl->aggr_buf) {
4005 ret = -ENOMEM;
4006 goto err_hw;
4007 }
4008
4009 wl->dummy_packet = wl12xx_alloc_dummy_packet(wl);
4010 if (!wl->dummy_packet) {
4011 ret = -ENOMEM;
4012 goto err_aggr;
4013 }
4014
4015 /* Register platform device */
4016 ret = platform_device_register(wl->plat_dev);
4017 if (ret) {
4018 wl1271_error("couldn't register platform device");
4019 goto err_dummy_packet;
4020 }
4021 dev_set_drvdata(&wl->plat_dev->dev, wl);
4022
4023 /* Create sysfs file to control bt coex state */
4024 ret = device_create_file(&wl->plat_dev->dev, &dev_attr_bt_coex_state);
4025 if (ret < 0) {
4026 wl1271_error("failed to create sysfs file bt_coex_state");
4027 goto err_platform;
4028 }
4029
4030 /* Create sysfs file to get HW PG version */
4031 ret = device_create_file(&wl->plat_dev->dev, &dev_attr_hw_pg_ver);
4032 if (ret < 0) {
4033 wl1271_error("failed to create sysfs file hw_pg_ver");
4034 goto err_bt_coex_state;
4035 }
4036
4037 return hw;
4038
4039err_bt_coex_state:
4040 device_remove_file(&wl->plat_dev->dev, &dev_attr_bt_coex_state);
4041
4042err_platform:
4043 platform_device_unregister(wl->plat_dev);
4044
4045err_dummy_packet:
4046 dev_kfree_skb(wl->dummy_packet);
4047
4048err_aggr:
4049 free_pages((unsigned long)wl->aggr_buf, order);
4050
4051err_hw:
4052 wl1271_debugfs_exit(wl);
4053 kfree(plat_dev);
4054
4055err_plat_alloc:
4056 ieee80211_free_hw(hw);
4057
4058err_hw_alloc:
4059
4060 return ERR_PTR(ret);
4061}
4062EXPORT_SYMBOL_GPL(wl1271_alloc_hw);
4063
4064int wl1271_free_hw(struct wl1271 *wl)
4065{
4066 platform_device_unregister(wl->plat_dev);
4067 dev_kfree_skb(wl->dummy_packet);
4068 free_pages((unsigned long)wl->aggr_buf,
4069 get_order(WL1271_AGGR_BUFFER_SIZE));
4070 kfree(wl->plat_dev);
4071
4072 wl1271_debugfs_exit(wl);
4073
4074 vfree(wl->fw);
4075 wl->fw = NULL;
4076 kfree(wl->nvs);
4077 wl->nvs = NULL;
4078
4079 kfree(wl->fw_status);
4080 kfree(wl->tx_res_if);
4081
4082 ieee80211_free_hw(wl->hw);
4083
4084 return 0;
4085}
4086EXPORT_SYMBOL_GPL(wl1271_free_hw);
4087
4088u32 wl12xx_debug_level = DEBUG_NONE;
4089EXPORT_SYMBOL_GPL(wl12xx_debug_level);
4090module_param_named(debug_level, wl12xx_debug_level, uint, S_IRUSR | S_IWUSR);
4091MODULE_PARM_DESC(debug_level, "wl12xx debugging level");
4092
4093MODULE_LICENSE("GPL");
4094MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
4095MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");
diff --git a/drivers/net/wireless/wl12xx/wl1271_ps.c b/drivers/net/wireless/wl12xx/ps.c
index a5e60e0403e5..b59b67711a17 100644
--- a/drivers/net/wireless/wl12xx/wl1271_ps.c
+++ b/drivers/net/wireless/wl12xx/ps.c
@@ -21,9 +21,10 @@
21 * 21 *
22 */ 22 */
23 23
24#include "wl1271_reg.h" 24#include "reg.h"
25#include "wl1271_ps.h" 25#include "ps.h"
26#include "wl1271_io.h" 26#include "io.h"
27#include "tx.h"
27 28
28#define WL1271_WAKEUP_TIMEOUT 500 29#define WL1271_WAKEUP_TIMEOUT 500
29 30
@@ -39,6 +40,13 @@ void wl1271_elp_work(struct work_struct *work)
39 40
40 mutex_lock(&wl->mutex); 41 mutex_lock(&wl->mutex);
41 42
43 if (unlikely(wl->state == WL1271_STATE_OFF))
44 goto out;
45
46 /* our work might have been already cancelled */
47 if (unlikely(!test_bit(WL1271_FLAG_ELP_REQUESTED, &wl->flags)))
48 goto out;
49
42 if (test_bit(WL1271_FLAG_IN_ELP, &wl->flags) || 50 if (test_bit(WL1271_FLAG_IN_ELP, &wl->flags) ||
43 (!test_bit(WL1271_FLAG_PSM, &wl->flags) && 51 (!test_bit(WL1271_FLAG_PSM, &wl->flags) &&
44 !test_bit(WL1271_FLAG_IDLE, &wl->flags))) 52 !test_bit(WL1271_FLAG_IDLE, &wl->flags)))
@@ -57,15 +65,19 @@ out:
57/* Routines to toggle sleep mode while in ELP */ 65/* Routines to toggle sleep mode while in ELP */
58void wl1271_ps_elp_sleep(struct wl1271 *wl) 66void wl1271_ps_elp_sleep(struct wl1271 *wl)
59{ 67{
60 if (test_bit(WL1271_FLAG_PSM, &wl->flags) || 68 /* we shouldn't get consecutive sleep requests */
61 test_bit(WL1271_FLAG_IDLE, &wl->flags)) { 69 if (WARN_ON(test_and_set_bit(WL1271_FLAG_ELP_REQUESTED, &wl->flags)))
62 cancel_delayed_work(&wl->elp_work); 70 return;
63 ieee80211_queue_delayed_work(wl->hw, &wl->elp_work, 71
64 msecs_to_jiffies(ELP_ENTRY_DELAY)); 72 if (!test_bit(WL1271_FLAG_PSM, &wl->flags) &&
65 } 73 !test_bit(WL1271_FLAG_IDLE, &wl->flags))
74 return;
75
76 ieee80211_queue_delayed_work(wl->hw, &wl->elp_work,
77 msecs_to_jiffies(ELP_ENTRY_DELAY));
66} 78}
67 79
68int wl1271_ps_elp_wakeup(struct wl1271 *wl, bool chip_awake) 80int wl1271_ps_elp_wakeup(struct wl1271 *wl)
69{ 81{
70 DECLARE_COMPLETION_ONSTACK(compl); 82 DECLARE_COMPLETION_ONSTACK(compl);
71 unsigned long flags; 83 unsigned long flags;
@@ -73,6 +85,16 @@ int wl1271_ps_elp_wakeup(struct wl1271 *wl, bool chip_awake)
73 u32 start_time = jiffies; 85 u32 start_time = jiffies;
74 bool pending = false; 86 bool pending = false;
75 87
88 /*
89 * we might try to wake up even if we didn't go to sleep
90 * before (e.g. on boot)
91 */
92 if (!test_and_clear_bit(WL1271_FLAG_ELP_REQUESTED, &wl->flags))
93 return 0;
94
95 /* don't cancel_sync as it might contend for a mutex and deadlock */
96 cancel_delayed_work(&wl->elp_work);
97
76 if (!test_bit(WL1271_FLAG_IN_ELP, &wl->flags)) 98 if (!test_bit(WL1271_FLAG_IN_ELP, &wl->flags))
77 return 0; 99 return 0;
78 100
@@ -83,7 +105,7 @@ int wl1271_ps_elp_wakeup(struct wl1271 *wl, bool chip_awake)
83 * the completion variable in one entity. 105 * the completion variable in one entity.
84 */ 106 */
85 spin_lock_irqsave(&wl->wl_lock, flags); 107 spin_lock_irqsave(&wl->wl_lock, flags);
86 if (work_pending(&wl->irq_work) || chip_awake) 108 if (test_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags))
87 pending = true; 109 pending = true;
88 else 110 else
89 wl->elp_compl = &compl; 111 wl->elp_compl = &compl;
@@ -96,6 +118,7 @@ int wl1271_ps_elp_wakeup(struct wl1271 *wl, bool chip_awake)
96 &compl, msecs_to_jiffies(WL1271_WAKEUP_TIMEOUT)); 118 &compl, msecs_to_jiffies(WL1271_WAKEUP_TIMEOUT));
97 if (ret == 0) { 119 if (ret == 0) {
98 wl1271_error("ELP wakeup timeout!"); 120 wl1271_error("ELP wakeup timeout!");
121 ieee80211_queue_work(wl->hw, &wl->recovery_work);
99 ret = -ETIMEDOUT; 122 ret = -ETIMEDOUT;
100 goto err; 123 goto err;
101 } else if (ret < 0) { 124 } else if (ret < 0) {
@@ -121,7 +144,7 @@ out:
121} 144}
122 145
123int wl1271_ps_set_mode(struct wl1271 *wl, enum wl1271_cmd_ps_mode mode, 146int wl1271_ps_set_mode(struct wl1271 *wl, enum wl1271_cmd_ps_mode mode,
124 bool send) 147 u32 rates, bool send)
125{ 148{
126 int ret; 149 int ret;
127 150
@@ -129,7 +152,13 @@ int wl1271_ps_set_mode(struct wl1271 *wl, enum wl1271_cmd_ps_mode mode,
129 case STATION_POWER_SAVE_MODE: 152 case STATION_POWER_SAVE_MODE:
130 wl1271_debug(DEBUG_PSM, "entering psm"); 153 wl1271_debug(DEBUG_PSM, "entering psm");
131 154
132 ret = wl1271_cmd_ps_mode(wl, STATION_POWER_SAVE_MODE, send); 155 ret = wl1271_acx_wake_up_conditions(wl);
156 if (ret < 0) {
157 wl1271_error("couldn't set wake up conditions");
158 return ret;
159 }
160
161 ret = wl1271_cmd_ps_mode(wl, STATION_POWER_SAVE_MODE);
133 if (ret < 0) 162 if (ret < 0)
134 return ret; 163 return ret;
135 164
@@ -138,9 +167,6 @@ int wl1271_ps_set_mode(struct wl1271 *wl, enum wl1271_cmd_ps_mode mode,
138 case STATION_ACTIVE_MODE: 167 case STATION_ACTIVE_MODE:
139 default: 168 default:
140 wl1271_debug(DEBUG_PSM, "leaving psm"); 169 wl1271_debug(DEBUG_PSM, "leaving psm");
141 ret = wl1271_ps_elp_wakeup(wl, false);
142 if (ret < 0)
143 return ret;
144 170
145 /* disable beacon early termination */ 171 /* disable beacon early termination */
146 ret = wl1271_acx_bet_enable(wl, false); 172 ret = wl1271_acx_bet_enable(wl, false);
@@ -152,7 +178,7 @@ int wl1271_ps_set_mode(struct wl1271 *wl, enum wl1271_cmd_ps_mode mode,
152 if (ret < 0) 178 if (ret < 0)
153 return ret; 179 return ret;
154 180
155 ret = wl1271_cmd_ps_mode(wl, STATION_ACTIVE_MODE, send); 181 ret = wl1271_cmd_ps_mode(wl, STATION_ACTIVE_MODE);
156 if (ret < 0) 182 if (ret < 0)
157 return ret; 183 return ret;
158 184
@@ -163,4 +189,81 @@ int wl1271_ps_set_mode(struct wl1271 *wl, enum wl1271_cmd_ps_mode mode,
163 return ret; 189 return ret;
164} 190}
165 191
192static void wl1271_ps_filter_frames(struct wl1271 *wl, u8 hlid)
193{
194 int i, filtered = 0;
195 struct sk_buff *skb;
196 struct ieee80211_tx_info *info;
197 unsigned long flags;
198
199 /* filter all frames currently the low level queus for this hlid */
200 for (i = 0; i < NUM_TX_QUEUES; i++) {
201 while ((skb = skb_dequeue(&wl->links[hlid].tx_queue[i]))) {
202 info = IEEE80211_SKB_CB(skb);
203 info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
204 info->status.rates[0].idx = -1;
205 ieee80211_tx_status(wl->hw, skb);
206 filtered++;
207 }
208 }
209
210 spin_lock_irqsave(&wl->wl_lock, flags);
211 wl->tx_queue_count -= filtered;
212 spin_unlock_irqrestore(&wl->wl_lock, flags);
213
214 wl1271_handle_tx_low_watermark(wl);
215}
216
217void wl1271_ps_link_start(struct wl1271 *wl, u8 hlid, bool clean_queues)
218{
219 struct ieee80211_sta *sta;
220
221 if (test_bit(hlid, &wl->ap_ps_map))
222 return;
223
224 wl1271_debug(DEBUG_PSM, "start mac80211 PSM on hlid %d blks %d "
225 "clean_queues %d", hlid, wl->links[hlid].allocated_blks,
226 clean_queues);
227
228 rcu_read_lock();
229 sta = ieee80211_find_sta(wl->vif, wl->links[hlid].addr);
230 if (!sta) {
231 wl1271_error("could not find sta %pM for starting ps",
232 wl->links[hlid].addr);
233 rcu_read_unlock();
234 return;
235 }
236
237 ieee80211_sta_ps_transition_ni(sta, true);
238 rcu_read_unlock();
239
240 /* do we want to filter all frames from this link's queues? */
241 if (clean_queues)
242 wl1271_ps_filter_frames(wl, hlid);
166 243
244 __set_bit(hlid, &wl->ap_ps_map);
245}
246
247void wl1271_ps_link_end(struct wl1271 *wl, u8 hlid)
248{
249 struct ieee80211_sta *sta;
250
251 if (!test_bit(hlid, &wl->ap_ps_map))
252 return;
253
254 wl1271_debug(DEBUG_PSM, "end mac80211 PSM on hlid %d", hlid);
255
256 __clear_bit(hlid, &wl->ap_ps_map);
257
258 rcu_read_lock();
259 sta = ieee80211_find_sta(wl->vif, wl->links[hlid].addr);
260 if (!sta) {
261 wl1271_error("could not find sta %pM for ending ps",
262 wl->links[hlid].addr);
263 goto end;
264 }
265
266 ieee80211_sta_ps_transition_ni(sta, false);
267end:
268 rcu_read_unlock();
269}
diff --git a/drivers/net/wireless/wl12xx/wl1271_ps.h b/drivers/net/wireless/wl12xx/ps.h
index 940276f517a4..25eb9bc9b628 100644
--- a/drivers/net/wireless/wl12xx/wl1271_ps.h
+++ b/drivers/net/wireless/wl12xx/ps.h
@@ -21,16 +21,20 @@
21 * 21 *
22 */ 22 */
23 23
24#ifndef __WL1271_PS_H__ 24#ifndef __PS_H__
25#define __WL1271_PS_H__ 25#define __PS_H__
26 26
27#include "wl1271.h" 27#include "wl12xx.h"
28#include "wl1271_acx.h" 28#include "acx.h"
29 29
30int wl1271_ps_set_mode(struct wl1271 *wl, enum wl1271_cmd_ps_mode mode, 30int wl1271_ps_set_mode(struct wl1271 *wl, enum wl1271_cmd_ps_mode mode,
31 bool send); 31 u32 rates, bool send);
32void wl1271_ps_elp_sleep(struct wl1271 *wl); 32void wl1271_ps_elp_sleep(struct wl1271 *wl);
33int wl1271_ps_elp_wakeup(struct wl1271 *wl, bool chip_awake); 33int wl1271_ps_elp_wakeup(struct wl1271 *wl);
34void wl1271_elp_work(struct work_struct *work); 34void wl1271_elp_work(struct work_struct *work);
35void wl1271_ps_link_start(struct wl1271 *wl, u8 hlid, bool clean_queues);
36void wl1271_ps_link_end(struct wl1271 *wl, u8 hlid);
37
38#define WL1271_PS_COMPLETE_TIMEOUT 500
35 39
36#endif /* __WL1271_PS_H__ */ 40#endif /* __WL1271_PS_H__ */
diff --git a/drivers/net/wireless/wl12xx/wl1271_reg.h b/drivers/net/wireless/wl12xx/reg.h
index 990960771528..440a4ee9cb42 100644
--- a/drivers/net/wireless/wl12xx/wl1271_reg.h
+++ b/drivers/net/wireless/wl12xx/reg.h
@@ -207,6 +207,8 @@
207 207
208#define CHIP_ID_1271_PG10 (0x4030101) 208#define CHIP_ID_1271_PG10 (0x4030101)
209#define CHIP_ID_1271_PG20 (0x4030111) 209#define CHIP_ID_1271_PG20 (0x4030111)
210#define CHIP_ID_1283_PG10 (0x05030101)
211#define CHIP_ID_1283_PG20 (0x05030111)
210 212
211#define ENABLE (REGISTERS_BASE + 0x5450) 213#define ENABLE (REGISTERS_BASE + 0x5450)
212 214
@@ -452,24 +454,11 @@
452#define HI_CFG_UART_TX_OUT_GPIO_14 0x00000200 454#define HI_CFG_UART_TX_OUT_GPIO_14 0x00000200
453#define HI_CFG_UART_TX_OUT_GPIO_7 0x00000400 455#define HI_CFG_UART_TX_OUT_GPIO_7 0x00000400
454 456
455/*
456 * NOTE: USE_ACTIVE_HIGH compilation flag should be defined in makefile
457 * for platforms using active high interrupt level
458 */
459#ifdef USE_ACTIVE_HIGH
460#define HI_CFG_DEF_VAL \ 457#define HI_CFG_DEF_VAL \
461 (HI_CFG_UART_ENABLE | \ 458 (HI_CFG_UART_ENABLE | \
462 HI_CFG_RST232_ENABLE | \ 459 HI_CFG_RST232_ENABLE | \
463 HI_CFG_CLOCK_REQ_SELECT | \ 460 HI_CFG_CLOCK_REQ_SELECT | \
464 HI_CFG_HOST_INT_ENABLE) 461 HI_CFG_HOST_INT_ENABLE)
465#else
466#define HI_CFG_DEF_VAL \
467 (HI_CFG_UART_ENABLE | \
468 HI_CFG_RST232_ENABLE | \
469 HI_CFG_CLOCK_REQ_SELECT | \
470 HI_CFG_HOST_INT_ENABLE)
471
472#endif
473 462
474#define REF_FREQ_19_2 0 463#define REF_FREQ_19_2 0
475#define REF_FREQ_26_0 1 464#define REF_FREQ_26_0 1
diff --git a/drivers/net/wireless/wl12xx/rx.c b/drivers/net/wireless/wl12xx/rx.c
new file mode 100644
index 000000000000..70091035e019
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/rx.c
@@ -0,0 +1,244 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 *
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include <linux/gfp.h>
25
26#include "wl12xx.h"
27#include "acx.h"
28#include "reg.h"
29#include "rx.h"
30#include "io.h"
31
32static u8 wl1271_rx_get_mem_block(struct wl1271_fw_common_status *status,
33 u32 drv_rx_counter)
34{
35 return le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]) &
36 RX_MEM_BLOCK_MASK;
37}
38
39static u32 wl1271_rx_get_buf_size(struct wl1271_fw_common_status *status,
40 u32 drv_rx_counter)
41{
42 return (le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]) &
43 RX_BUF_SIZE_MASK) >> RX_BUF_SIZE_SHIFT_DIV;
44}
45
46static void wl1271_rx_status(struct wl1271 *wl,
47 struct wl1271_rx_descriptor *desc,
48 struct ieee80211_rx_status *status,
49 u8 beacon)
50{
51 memset(status, 0, sizeof(struct ieee80211_rx_status));
52
53 if ((desc->flags & WL1271_RX_DESC_BAND_MASK) == WL1271_RX_DESC_BAND_BG)
54 status->band = IEEE80211_BAND_2GHZ;
55 else
56 status->band = IEEE80211_BAND_5GHZ;
57
58 status->rate_idx = wl1271_rate_to_idx(desc->rate, status->band);
59
60#ifdef CONFIG_WL12XX_HT
61 /* 11n support */
62 if (desc->rate <= CONF_HW_RXTX_RATE_MCS0)
63 status->flag |= RX_FLAG_HT;
64#endif
65
66 status->signal = desc->rssi;
67
68 /*
69 * FIXME: In wl1251, the SNR should be divided by two. In wl1271 we
70 * need to divide by two for now, but TI has been discussing about
71 * changing it. This needs to be rechecked.
72 */
73 wl->noise = desc->rssi - (desc->snr >> 1);
74
75 status->freq = ieee80211_channel_to_frequency(desc->channel,
76 status->band);
77
78 if (desc->flags & WL1271_RX_DESC_ENCRYPT_MASK) {
79 u8 desc_err_code = desc->status & WL1271_RX_DESC_STATUS_MASK;
80
81 status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED |
82 RX_FLAG_DECRYPTED;
83
84 if (unlikely(desc_err_code == WL1271_RX_DESC_MIC_FAIL)) {
85 status->flag |= RX_FLAG_MMIC_ERROR;
86 wl1271_warning("Michael MIC error");
87 }
88 }
89}
90
91static int wl1271_rx_handle_data(struct wl1271 *wl, u8 *data, u32 length)
92{
93 struct wl1271_rx_descriptor *desc;
94 struct sk_buff *skb;
95 struct ieee80211_hdr *hdr;
96 u8 *buf;
97 u8 beacon = 0;
98
99 /*
100 * In PLT mode we seem to get frames and mac80211 warns about them,
101 * workaround this by not retrieving them at all.
102 */
103 if (unlikely(wl->state == WL1271_STATE_PLT))
104 return -EINVAL;
105
106 /* the data read starts with the descriptor */
107 desc = (struct wl1271_rx_descriptor *) data;
108
109 switch (desc->status & WL1271_RX_DESC_STATUS_MASK) {
110 /* discard corrupted packets */
111 case WL1271_RX_DESC_DRIVER_RX_Q_FAIL:
112 case WL1271_RX_DESC_DECRYPT_FAIL:
113 wl1271_warning("corrupted packet in RX with status: 0x%x",
114 desc->status & WL1271_RX_DESC_STATUS_MASK);
115 return -EINVAL;
116 case WL1271_RX_DESC_SUCCESS:
117 case WL1271_RX_DESC_MIC_FAIL:
118 break;
119 default:
120 wl1271_error("invalid RX descriptor status: 0x%x",
121 desc->status & WL1271_RX_DESC_STATUS_MASK);
122 return -EINVAL;
123 }
124
125 skb = __dev_alloc_skb(length, GFP_KERNEL);
126 if (!skb) {
127 wl1271_error("Couldn't allocate RX frame");
128 return -ENOMEM;
129 }
130
131 buf = skb_put(skb, length);
132 memcpy(buf, data, length);
133
134 /* now we pull the descriptor out of the buffer */
135 skb_pull(skb, sizeof(*desc));
136
137 hdr = (struct ieee80211_hdr *)skb->data;
138 if (ieee80211_is_beacon(hdr->frame_control))
139 beacon = 1;
140
141 wl1271_rx_status(wl, desc, IEEE80211_SKB_RXCB(skb), beacon);
142
143 wl1271_debug(DEBUG_RX, "rx skb 0x%p: %d B %s", skb,
144 skb->len - desc->pad_len,
145 beacon ? "beacon" : "");
146
147 skb_trim(skb, skb->len - desc->pad_len);
148
149 skb_queue_tail(&wl->deferred_rx_queue, skb);
150 ieee80211_queue_work(wl->hw, &wl->netstack_work);
151
152 return 0;
153}
154
155void wl1271_rx(struct wl1271 *wl, struct wl1271_fw_common_status *status)
156{
157 struct wl1271_acx_mem_map *wl_mem_map = wl->target_mem_map;
158 u32 buf_size;
159 u32 fw_rx_counter = status->fw_rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
160 u32 drv_rx_counter = wl->rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
161 u32 rx_counter;
162 u32 mem_block;
163 u32 pkt_length;
164 u32 pkt_offset;
165
166 while (drv_rx_counter != fw_rx_counter) {
167 buf_size = 0;
168 rx_counter = drv_rx_counter;
169 while (rx_counter != fw_rx_counter) {
170 pkt_length = wl1271_rx_get_buf_size(status, rx_counter);
171 if (buf_size + pkt_length > WL1271_AGGR_BUFFER_SIZE)
172 break;
173 buf_size += pkt_length;
174 rx_counter++;
175 rx_counter &= NUM_RX_PKT_DESC_MOD_MASK;
176 }
177
178 if (buf_size == 0) {
179 wl1271_warning("received empty data");
180 break;
181 }
182
183 if (wl->chip.id != CHIP_ID_1283_PG20) {
184 /*
185 * Choose the block we want to read
186 * For aggregated packets, only the first memory block
187 * should be retrieved. The FW takes care of the rest.
188 */
189 mem_block = wl1271_rx_get_mem_block(status,
190 drv_rx_counter);
191
192 wl->rx_mem_pool_addr.addr = (mem_block << 8) +
193 le32_to_cpu(wl_mem_map->packet_memory_pool_start);
194
195 wl->rx_mem_pool_addr.addr_extra =
196 wl->rx_mem_pool_addr.addr + 4;
197
198 wl1271_write(wl, WL1271_SLV_REG_DATA,
199 &wl->rx_mem_pool_addr,
200 sizeof(wl->rx_mem_pool_addr), false);
201 }
202
203 /* Read all available packets at once */
204 wl1271_read(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf,
205 buf_size, true);
206
207 /* Split data into separate packets */
208 pkt_offset = 0;
209 while (pkt_offset < buf_size) {
210 pkt_length = wl1271_rx_get_buf_size(status,
211 drv_rx_counter);
212 /*
213 * the handle data call can only fail in memory-outage
214 * conditions, in that case the received frame will just
215 * be dropped.
216 */
217 wl1271_rx_handle_data(wl,
218 wl->aggr_buf + pkt_offset,
219 pkt_length);
220 wl->rx_counter++;
221 drv_rx_counter++;
222 drv_rx_counter &= NUM_RX_PKT_DESC_MOD_MASK;
223 pkt_offset += pkt_length;
224 }
225 }
226
227 /*
228 * Write the driver's packet counter to the FW. This is only required
229 * for older hardware revisions
230 */
231 if (wl->quirks & WL12XX_QUIRK_END_OF_TRANSACTION)
232 wl1271_write32(wl, RX_DRIVER_COUNTER_ADDRESS, wl->rx_counter);
233}
234
235void wl1271_set_default_filters(struct wl1271 *wl)
236{
237 if (wl->bss_type == BSS_TYPE_AP_BSS) {
238 wl->rx_config = WL1271_DEFAULT_AP_RX_CONFIG;
239 wl->rx_filter = WL1271_DEFAULT_AP_RX_FILTER;
240 } else {
241 wl->rx_config = WL1271_DEFAULT_STA_RX_CONFIG;
242 wl->rx_filter = WL1271_DEFAULT_STA_RX_FILTER;
243 }
244}
diff --git a/drivers/net/wireless/wl12xx/wl1271_rx.h b/drivers/net/wireless/wl12xx/rx.h
index 13a232333b13..75fabf836491 100644
--- a/drivers/net/wireless/wl12xx/wl1271_rx.h
+++ b/drivers/net/wireless/wl12xx/rx.h
@@ -22,18 +22,14 @@
22 * 22 *
23 */ 23 */
24 24
25#ifndef __WL1271_RX_H__ 25#ifndef __RX_H__
26#define __WL1271_RX_H__ 26#define __RX_H__
27 27
28#include <linux/bitops.h> 28#include <linux/bitops.h>
29 29
30#define WL1271_RX_MAX_RSSI -30 30#define WL1271_RX_MAX_RSSI -30
31#define WL1271_RX_MIN_RSSI -95 31#define WL1271_RX_MIN_RSSI -95
32 32
33#define WL1271_RX_ALIGN_TO 4
34#define WL1271_RX_ALIGN(len) (((len) + WL1271_RX_ALIGN_TO - 1) & \
35 ~(WL1271_RX_ALIGN_TO - 1))
36
37#define SHORT_PREAMBLE_BIT BIT(0) 33#define SHORT_PREAMBLE_BIT BIT(0)
38#define OFDM_RATE_BIT BIT(6) 34#define OFDM_RATE_BIT BIT(6)
39#define PBCC_RATE_BIT BIT(7) 35#define PBCC_RATE_BIT BIT(7)
@@ -86,8 +82,9 @@
86/* 82/*
87 * RX Descriptor status 83 * RX Descriptor status
88 * 84 *
89 * Bits 0-2 - status 85 * Bits 0-2 - error code
90 * Bits 3-7 - reserved 86 * Bits 3-5 - process_id tag (AP mode FW)
87 * Bits 6-7 - reserved
91 */ 88 */
92#define WL1271_RX_DESC_STATUS_MASK 0x07 89#define WL1271_RX_DESC_STATUS_MASK 0x07
93 90
@@ -110,12 +107,16 @@ struct wl1271_rx_descriptor {
110 u8 snr; 107 u8 snr;
111 __le32 timestamp; 108 __le32 timestamp;
112 u8 packet_class; 109 u8 packet_class;
113 u8 process_id; 110 union {
111 u8 process_id; /* STA FW */
112 u8 hlid; /* AP FW */
113 } __packed;
114 u8 pad_len; 114 u8 pad_len;
115 u8 reserved; 115 u8 reserved;
116} __packed; 116} __packed;
117 117
118void wl1271_rx(struct wl1271 *wl, struct wl1271_fw_status *status); 118void wl1271_rx(struct wl1271 *wl, struct wl1271_fw_common_status *status);
119u8 wl1271_rate_to_idx(struct wl1271 *wl, int rate); 119u8 wl1271_rate_to_idx(int rate, enum ieee80211_band band);
120void wl1271_set_default_filters(struct wl1271 *wl);
120 121
121#endif 122#endif
diff --git a/drivers/net/wireless/wl12xx/scan.c b/drivers/net/wireless/wl12xx/scan.c
new file mode 100644
index 000000000000..56f76abc754d
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/scan.c
@@ -0,0 +1,582 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2009-2010 Nokia Corporation
5 *
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include <linux/ieee80211.h>
25
26#include "wl12xx.h"
27#include "cmd.h"
28#include "scan.h"
29#include "acx.h"
30#include "ps.h"
31
32void wl1271_scan_complete_work(struct work_struct *work)
33{
34 struct delayed_work *dwork;
35 struct wl1271 *wl;
36
37 dwork = container_of(work, struct delayed_work, work);
38 wl = container_of(dwork, struct wl1271, scan_complete_work);
39
40 wl1271_debug(DEBUG_SCAN, "Scanning complete");
41
42 mutex_lock(&wl->mutex);
43
44 if (wl->state == WL1271_STATE_OFF)
45 goto out;
46
47 if (wl->scan.state == WL1271_SCAN_STATE_IDLE)
48 goto out;
49
50 wl->scan.state = WL1271_SCAN_STATE_IDLE;
51 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
52 wl->scan.req = NULL;
53 ieee80211_scan_completed(wl->hw, false);
54
55 /* restore hardware connection monitoring template */
56 if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) {
57 if (wl1271_ps_elp_wakeup(wl) == 0) {
58 wl1271_cmd_build_ap_probe_req(wl, wl->probereq);
59 wl1271_ps_elp_sleep(wl);
60 }
61 }
62
63 if (wl->scan.failed) {
64 wl1271_info("Scan completed due to error.");
65 ieee80211_queue_work(wl->hw, &wl->recovery_work);
66 }
67
68out:
69 mutex_unlock(&wl->mutex);
70
71}
72
73
74static int wl1271_get_scan_channels(struct wl1271 *wl,
75 struct cfg80211_scan_request *req,
76 struct basic_scan_channel_params *channels,
77 enum ieee80211_band band, bool passive)
78{
79 struct conf_scan_settings *c = &wl->conf.scan;
80 int i, j;
81 u32 flags;
82
83 for (i = 0, j = 0;
84 i < req->n_channels && j < WL1271_SCAN_MAX_CHANNELS;
85 i++) {
86
87 flags = req->channels[i]->flags;
88
89 if (!test_bit(i, wl->scan.scanned_ch) &&
90 !(flags & IEEE80211_CHAN_DISABLED) &&
91 ((!!(flags & IEEE80211_CHAN_PASSIVE_SCAN)) == passive) &&
92 (req->channels[i]->band == band)) {
93
94 wl1271_debug(DEBUG_SCAN, "band %d, center_freq %d ",
95 req->channels[i]->band,
96 req->channels[i]->center_freq);
97 wl1271_debug(DEBUG_SCAN, "hw_value %d, flags %X",
98 req->channels[i]->hw_value,
99 req->channels[i]->flags);
100 wl1271_debug(DEBUG_SCAN,
101 "max_antenna_gain %d, max_power %d",
102 req->channels[i]->max_antenna_gain,
103 req->channels[i]->max_power);
104 wl1271_debug(DEBUG_SCAN, "beacon_found %d",
105 req->channels[i]->beacon_found);
106
107 if (!passive) {
108 channels[j].min_duration =
109 cpu_to_le32(c->min_dwell_time_active);
110 channels[j].max_duration =
111 cpu_to_le32(c->max_dwell_time_active);
112 } else {
113 channels[j].min_duration =
114 cpu_to_le32(c->min_dwell_time_passive);
115 channels[j].max_duration =
116 cpu_to_le32(c->max_dwell_time_passive);
117 }
118 channels[j].early_termination = 0;
119 channels[j].tx_power_att = req->channels[i]->max_power;
120 channels[j].channel = req->channels[i]->hw_value;
121
122 memset(&channels[j].bssid_lsb, 0xff, 4);
123 memset(&channels[j].bssid_msb, 0xff, 2);
124
125 /* Mark the channels we already used */
126 set_bit(i, wl->scan.scanned_ch);
127
128 j++;
129 }
130 }
131
132 return j;
133}
134
135#define WL1271_NOTHING_TO_SCAN 1
136
137static int wl1271_scan_send(struct wl1271 *wl, enum ieee80211_band band,
138 bool passive, u32 basic_rate)
139{
140 struct wl1271_cmd_scan *cmd;
141 struct wl1271_cmd_trigger_scan_to *trigger;
142 int ret;
143 u16 scan_options = 0;
144
145 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
146 trigger = kzalloc(sizeof(*trigger), GFP_KERNEL);
147 if (!cmd || !trigger) {
148 ret = -ENOMEM;
149 goto out;
150 }
151
152 /* We always use high priority scans */
153 scan_options = WL1271_SCAN_OPT_PRIORITY_HIGH;
154
155 /* No SSIDs means that we have a forced passive scan */
156 if (passive || wl->scan.req->n_ssids == 0)
157 scan_options |= WL1271_SCAN_OPT_PASSIVE;
158
159 cmd->params.scan_options = cpu_to_le16(scan_options);
160
161 cmd->params.n_ch = wl1271_get_scan_channels(wl, wl->scan.req,
162 cmd->channels,
163 band, passive);
164 if (cmd->params.n_ch == 0) {
165 ret = WL1271_NOTHING_TO_SCAN;
166 goto out;
167 }
168
169 cmd->params.tx_rate = cpu_to_le32(basic_rate);
170 cmd->params.rx_config_options = cpu_to_le32(CFG_RX_ALL_GOOD);
171 cmd->params.rx_filter_options =
172 cpu_to_le32(CFG_RX_PRSP_EN | CFG_RX_MGMT_EN | CFG_RX_BCN_EN);
173
174 cmd->params.n_probe_reqs = wl->conf.scan.num_probe_reqs;
175 cmd->params.tx_rate = cpu_to_le32(basic_rate);
176 cmd->params.tid_trigger = 0;
177 cmd->params.scan_tag = WL1271_SCAN_DEFAULT_TAG;
178
179 if (band == IEEE80211_BAND_2GHZ)
180 cmd->params.band = WL1271_SCAN_BAND_2_4_GHZ;
181 else
182 cmd->params.band = WL1271_SCAN_BAND_5_GHZ;
183
184 if (wl->scan.ssid_len && wl->scan.ssid) {
185 cmd->params.ssid_len = wl->scan.ssid_len;
186 memcpy(cmd->params.ssid, wl->scan.ssid, wl->scan.ssid_len);
187 }
188
189 ret = wl1271_cmd_build_probe_req(wl, wl->scan.ssid, wl->scan.ssid_len,
190 wl->scan.req->ie, wl->scan.req->ie_len,
191 band);
192 if (ret < 0) {
193 wl1271_error("PROBE request template failed");
194 goto out;
195 }
196
197 /* disable the timeout */
198 trigger->timeout = 0;
199 ret = wl1271_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger,
200 sizeof(*trigger), 0);
201 if (ret < 0) {
202 wl1271_error("trigger scan to failed for hw scan");
203 goto out;
204 }
205
206 wl1271_dump(DEBUG_SCAN, "SCAN: ", cmd, sizeof(*cmd));
207
208 ret = wl1271_cmd_send(wl, CMD_SCAN, cmd, sizeof(*cmd), 0);
209 if (ret < 0) {
210 wl1271_error("SCAN failed");
211 goto out;
212 }
213
214out:
215 kfree(cmd);
216 kfree(trigger);
217 return ret;
218}
219
220void wl1271_scan_stm(struct wl1271 *wl)
221{
222 int ret = 0;
223
224 switch (wl->scan.state) {
225 case WL1271_SCAN_STATE_IDLE:
226 break;
227
228 case WL1271_SCAN_STATE_2GHZ_ACTIVE:
229 ret = wl1271_scan_send(wl, IEEE80211_BAND_2GHZ, false,
230 wl->conf.tx.basic_rate);
231 if (ret == WL1271_NOTHING_TO_SCAN) {
232 wl->scan.state = WL1271_SCAN_STATE_2GHZ_PASSIVE;
233 wl1271_scan_stm(wl);
234 }
235
236 break;
237
238 case WL1271_SCAN_STATE_2GHZ_PASSIVE:
239 ret = wl1271_scan_send(wl, IEEE80211_BAND_2GHZ, true,
240 wl->conf.tx.basic_rate);
241 if (ret == WL1271_NOTHING_TO_SCAN) {
242 if (wl->enable_11a)
243 wl->scan.state = WL1271_SCAN_STATE_5GHZ_ACTIVE;
244 else
245 wl->scan.state = WL1271_SCAN_STATE_DONE;
246 wl1271_scan_stm(wl);
247 }
248
249 break;
250
251 case WL1271_SCAN_STATE_5GHZ_ACTIVE:
252 ret = wl1271_scan_send(wl, IEEE80211_BAND_5GHZ, false,
253 wl->conf.tx.basic_rate_5);
254 if (ret == WL1271_NOTHING_TO_SCAN) {
255 wl->scan.state = WL1271_SCAN_STATE_5GHZ_PASSIVE;
256 wl1271_scan_stm(wl);
257 }
258
259 break;
260
261 case WL1271_SCAN_STATE_5GHZ_PASSIVE:
262 ret = wl1271_scan_send(wl, IEEE80211_BAND_5GHZ, true,
263 wl->conf.tx.basic_rate_5);
264 if (ret == WL1271_NOTHING_TO_SCAN) {
265 wl->scan.state = WL1271_SCAN_STATE_DONE;
266 wl1271_scan_stm(wl);
267 }
268
269 break;
270
271 case WL1271_SCAN_STATE_DONE:
272 wl->scan.failed = false;
273 cancel_delayed_work(&wl->scan_complete_work);
274 ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work,
275 msecs_to_jiffies(0));
276 break;
277
278 default:
279 wl1271_error("invalid scan state");
280 break;
281 }
282
283 if (ret < 0) {
284 cancel_delayed_work(&wl->scan_complete_work);
285 ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work,
286 msecs_to_jiffies(0));
287 }
288}
289
290int wl1271_scan(struct wl1271 *wl, const u8 *ssid, size_t ssid_len,
291 struct cfg80211_scan_request *req)
292{
293 /*
294 * cfg80211 should guarantee that we don't get more channels
295 * than what we have registered.
296 */
297 BUG_ON(req->n_channels > WL1271_MAX_CHANNELS);
298
299 if (wl->scan.state != WL1271_SCAN_STATE_IDLE)
300 return -EBUSY;
301
302 wl->scan.state = WL1271_SCAN_STATE_2GHZ_ACTIVE;
303
304 if (ssid_len && ssid) {
305 wl->scan.ssid_len = ssid_len;
306 memcpy(wl->scan.ssid, ssid, ssid_len);
307 } else {
308 wl->scan.ssid_len = 0;
309 }
310
311 wl->scan.req = req;
312 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
313
314 /* we assume failure so that timeout scenarios are handled correctly */
315 wl->scan.failed = true;
316 ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work,
317 msecs_to_jiffies(WL1271_SCAN_TIMEOUT));
318
319 wl1271_scan_stm(wl);
320
321 return 0;
322}
323
324static int
325wl1271_scan_get_sched_scan_channels(struct wl1271 *wl,
326 struct cfg80211_sched_scan_request *req,
327 struct conn_scan_ch_params *channels,
328 u32 band, bool radar, bool passive,
329 int start)
330{
331 struct conf_sched_scan_settings *c = &wl->conf.sched_scan;
332 int i, j;
333 u32 flags;
334 bool force_passive = !req->n_ssids;
335
336 for (i = 0, j = start;
337 i < req->n_channels && j < MAX_CHANNELS_ALL_BANDS;
338 i++) {
339 flags = req->channels[i]->flags;
340
341 if (force_passive)
342 flags |= IEEE80211_CHAN_PASSIVE_SCAN;
343
344 if ((req->channels[i]->band == band) &&
345 !(flags & IEEE80211_CHAN_DISABLED) &&
346 (!!(flags & IEEE80211_CHAN_RADAR) == radar) &&
347 /* if radar is set, we ignore the passive flag */
348 (radar ||
349 !!(flags & IEEE80211_CHAN_PASSIVE_SCAN) == passive)) {
350 wl1271_debug(DEBUG_SCAN, "band %d, center_freq %d ",
351 req->channels[i]->band,
352 req->channels[i]->center_freq);
353 wl1271_debug(DEBUG_SCAN, "hw_value %d, flags %X",
354 req->channels[i]->hw_value,
355 req->channels[i]->flags);
356 wl1271_debug(DEBUG_SCAN, "max_power %d",
357 req->channels[i]->max_power);
358
359 if (flags & IEEE80211_CHAN_RADAR) {
360 channels[j].flags |= SCAN_CHANNEL_FLAGS_DFS;
361 channels[j].passive_duration =
362 cpu_to_le16(c->dwell_time_dfs);
363 }
364 else if (flags & IEEE80211_CHAN_PASSIVE_SCAN) {
365 channels[j].passive_duration =
366 cpu_to_le16(c->dwell_time_passive);
367 } else {
368 channels[j].min_duration =
369 cpu_to_le16(c->min_dwell_time_active);
370 channels[j].max_duration =
371 cpu_to_le16(c->max_dwell_time_active);
372 }
373 channels[j].tx_power_att = req->channels[i]->max_power;
374 channels[j].channel = req->channels[i]->hw_value;
375
376 j++;
377 }
378 }
379
380 return j - start;
381}
382
383static int
384wl1271_scan_sched_scan_channels(struct wl1271 *wl,
385 struct cfg80211_sched_scan_request *req,
386 struct wl1271_cmd_sched_scan_config *cfg)
387{
388 int idx = 0;
389
390 cfg->passive[0] =
391 wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels,
392 IEEE80211_BAND_2GHZ,
393 false, true, idx);
394 idx += cfg->passive[0];
395
396 cfg->active[0] =
397 wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels,
398 IEEE80211_BAND_2GHZ,
399 false, false, idx);
400 /*
401 * 5GHz channels always start at position 14, not immediately
402 * after the last 2.4GHz channel
403 */
404 idx = 14;
405
406 cfg->passive[1] =
407 wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels,
408 IEEE80211_BAND_5GHZ,
409 false, true, idx);
410 idx += cfg->passive[1];
411
412 cfg->dfs =
413 wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels,
414 IEEE80211_BAND_5GHZ,
415 true, true, idx);
416 idx += cfg->dfs;
417
418 cfg->active[1] =
419 wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels,
420 IEEE80211_BAND_5GHZ,
421 false, false, idx);
422 idx += cfg->active[1];
423
424 wl1271_debug(DEBUG_SCAN, " 2.4GHz: active %d passive %d",
425 cfg->active[0], cfg->passive[0]);
426 wl1271_debug(DEBUG_SCAN, " 5GHz: active %d passive %d",
427 cfg->active[1], cfg->passive[1]);
428 wl1271_debug(DEBUG_SCAN, " DFS: %d", cfg->dfs);
429
430 return idx;
431}
432
433int wl1271_scan_sched_scan_config(struct wl1271 *wl,
434 struct cfg80211_sched_scan_request *req,
435 struct ieee80211_sched_scan_ies *ies)
436{
437 struct wl1271_cmd_sched_scan_config *cfg = NULL;
438 struct conf_sched_scan_settings *c = &wl->conf.sched_scan;
439 int i, total_channels, ret;
440 bool force_passive = !req->n_ssids;
441
442 wl1271_debug(DEBUG_CMD, "cmd sched_scan scan config");
443
444 cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
445 if (!cfg)
446 return -ENOMEM;
447
448 cfg->rssi_threshold = c->rssi_threshold;
449 cfg->snr_threshold = c->snr_threshold;
450 cfg->n_probe_reqs = c->num_probe_reqs;
451 /* cycles set to 0 it means infinite (until manually stopped) */
452 cfg->cycles = 0;
453 /* report APs when at least 1 is found */
454 cfg->report_after = 1;
455 /* don't stop scanning automatically when something is found */
456 cfg->terminate = 0;
457 cfg->tag = WL1271_SCAN_DEFAULT_TAG;
458 /* don't filter on BSS type */
459 cfg->bss_type = SCAN_BSS_TYPE_ANY;
460 /* currently NL80211 supports only a single interval */
461 for (i = 0; i < SCAN_MAX_CYCLE_INTERVALS; i++)
462 cfg->intervals[i] = cpu_to_le32(req->interval);
463
464 if (!force_passive && req->ssids[0].ssid_len && req->ssids[0].ssid) {
465 cfg->filter_type = SCAN_SSID_FILTER_SPECIFIC;
466 cfg->ssid_len = req->ssids[0].ssid_len;
467 memcpy(cfg->ssid, req->ssids[0].ssid,
468 req->ssids[0].ssid_len);
469 } else {
470 cfg->filter_type = SCAN_SSID_FILTER_ANY;
471 cfg->ssid_len = 0;
472 }
473
474 total_channels = wl1271_scan_sched_scan_channels(wl, req, cfg);
475 if (total_channels == 0) {
476 wl1271_error("scan channel list is empty");
477 ret = -EINVAL;
478 goto out;
479 }
480
481 if (!force_passive && cfg->active[0]) {
482 ret = wl1271_cmd_build_probe_req(wl, req->ssids[0].ssid,
483 req->ssids[0].ssid_len,
484 ies->ie[IEEE80211_BAND_2GHZ],
485 ies->len[IEEE80211_BAND_2GHZ],
486 IEEE80211_BAND_2GHZ);
487 if (ret < 0) {
488 wl1271_error("2.4GHz PROBE request template failed");
489 goto out;
490 }
491 }
492
493 if (!force_passive && cfg->active[1]) {
494 ret = wl1271_cmd_build_probe_req(wl, req->ssids[0].ssid,
495 req->ssids[0].ssid_len,
496 ies->ie[IEEE80211_BAND_5GHZ],
497 ies->len[IEEE80211_BAND_5GHZ],
498 IEEE80211_BAND_5GHZ);
499 if (ret < 0) {
500 wl1271_error("5GHz PROBE request template failed");
501 goto out;
502 }
503 }
504
505 wl1271_dump(DEBUG_SCAN, "SCAN_CFG: ", cfg, sizeof(*cfg));
506
507 ret = wl1271_cmd_send(wl, CMD_CONNECTION_SCAN_CFG, cfg,
508 sizeof(*cfg), 0);
509 if (ret < 0) {
510 wl1271_error("SCAN configuration failed");
511 goto out;
512 }
513out:
514 kfree(cfg);
515 return ret;
516}
517
518int wl1271_scan_sched_scan_start(struct wl1271 *wl)
519{
520 struct wl1271_cmd_sched_scan_start *start;
521 int ret = 0;
522
523 wl1271_debug(DEBUG_CMD, "cmd periodic scan start");
524
525 if (wl->bss_type != BSS_TYPE_STA_BSS)
526 return -EOPNOTSUPP;
527
528 if (!test_bit(WL1271_FLAG_IDLE, &wl->flags))
529 return -EBUSY;
530
531 start = kzalloc(sizeof(*start), GFP_KERNEL);
532 if (!start)
533 return -ENOMEM;
534
535 start->tag = WL1271_SCAN_DEFAULT_TAG;
536
537 ret = wl1271_cmd_send(wl, CMD_START_PERIODIC_SCAN, start,
538 sizeof(*start), 0);
539 if (ret < 0) {
540 wl1271_error("failed to send scan start command");
541 goto out_free;
542 }
543
544out_free:
545 kfree(start);
546 return ret;
547}
548
549void wl1271_scan_sched_scan_results(struct wl1271 *wl)
550{
551 wl1271_debug(DEBUG_SCAN, "got periodic scan results");
552
553 ieee80211_sched_scan_results(wl->hw);
554}
555
556void wl1271_scan_sched_scan_stop(struct wl1271 *wl)
557{
558 struct wl1271_cmd_sched_scan_stop *stop;
559 int ret = 0;
560
561 wl1271_debug(DEBUG_CMD, "cmd periodic scan stop");
562
563 /* FIXME: what to do if alloc'ing to stop fails? */
564 stop = kzalloc(sizeof(*stop), GFP_KERNEL);
565 if (!stop) {
566 wl1271_error("failed to alloc memory to send sched scan stop");
567 return;
568 }
569
570 stop->tag = WL1271_SCAN_DEFAULT_TAG;
571
572 ret = wl1271_cmd_send(wl, CMD_STOP_PERIODIC_SCAN, stop,
573 sizeof(*stop), 0);
574 if (ret < 0) {
575 wl1271_error("failed to send sched scan stop command");
576 goto out_free;
577 }
578 wl->sched_scanning = false;
579
580out_free:
581 kfree(stop);
582}
diff --git a/drivers/net/wireless/wl12xx/wl1271_scan.h b/drivers/net/wireless/wl12xx/scan.h
index f1815700f5f9..a0b6c5d67b07 100644
--- a/drivers/net/wireless/wl12xx/wl1271_scan.h
+++ b/drivers/net/wireless/wl12xx/scan.h
@@ -21,10 +21,10 @@
21 * 21 *
22 */ 22 */
23 23
24#ifndef __WL1271_SCAN_H__ 24#ifndef __SCAN_H__
25#define __WL1271_SCAN_H__ 25#define __SCAN_H__
26 26
27#include "wl1271.h" 27#include "wl12xx.h"
28 28
29int wl1271_scan(struct wl1271 *wl, const u8 *ssid, size_t ssid_len, 29int wl1271_scan(struct wl1271 *wl, const u8 *ssid, size_t ssid_len,
30 struct cfg80211_scan_request *req); 30 struct cfg80211_scan_request *req);
@@ -32,6 +32,13 @@ int wl1271_scan_build_probe_req(struct wl1271 *wl,
32 const u8 *ssid, size_t ssid_len, 32 const u8 *ssid, size_t ssid_len,
33 const u8 *ie, size_t ie_len, u8 band); 33 const u8 *ie, size_t ie_len, u8 band);
34void wl1271_scan_stm(struct wl1271 *wl); 34void wl1271_scan_stm(struct wl1271 *wl);
35void wl1271_scan_complete_work(struct work_struct *work);
36int wl1271_scan_sched_scan_config(struct wl1271 *wl,
37 struct cfg80211_sched_scan_request *req,
38 struct ieee80211_sched_scan_ies *ies);
39int wl1271_scan_sched_scan_start(struct wl1271 *wl);
40void wl1271_scan_sched_scan_stop(struct wl1271 *wl);
41void wl1271_scan_sched_scan_results(struct wl1271 *wl);
35 42
36#define WL1271_SCAN_MAX_CHANNELS 24 43#define WL1271_SCAN_MAX_CHANNELS 24
37#define WL1271_SCAN_DEFAULT_TAG 1 44#define WL1271_SCAN_DEFAULT_TAG 1
@@ -39,11 +46,10 @@ void wl1271_scan_stm(struct wl1271 *wl);
39#define WL1271_SCAN_OPT_ACTIVE 0 46#define WL1271_SCAN_OPT_ACTIVE 0
40#define WL1271_SCAN_OPT_PASSIVE 1 47#define WL1271_SCAN_OPT_PASSIVE 1
41#define WL1271_SCAN_OPT_PRIORITY_HIGH 4 48#define WL1271_SCAN_OPT_PRIORITY_HIGH 4
42#define WL1271_SCAN_CHAN_MIN_DURATION 30000 /* TU */
43#define WL1271_SCAN_CHAN_MAX_DURATION 60000 /* TU */
44#define WL1271_SCAN_BAND_2_4_GHZ 0 49#define WL1271_SCAN_BAND_2_4_GHZ 0
45#define WL1271_SCAN_BAND_5_GHZ 1 50#define WL1271_SCAN_BAND_5_GHZ 1
46#define WL1271_SCAN_PROBE_REQS 3 51
52#define WL1271_SCAN_TIMEOUT 10000 /* msec */
47 53
48enum { 54enum {
49 WL1271_SCAN_STATE_IDLE, 55 WL1271_SCAN_STATE_IDLE,
@@ -106,4 +112,115 @@ struct wl1271_cmd_trigger_scan_to {
106 __le32 timeout; 112 __le32 timeout;
107} __packed; 113} __packed;
108 114
115#define MAX_CHANNELS_ALL_BANDS 41
116#define SCAN_MAX_CYCLE_INTERVALS 16
117#define SCAN_MAX_BANDS 3
118
119enum {
120 SCAN_CHANNEL_TYPE_2GHZ_PASSIVE,
121 SCAN_CHANNEL_TYPE_2GHZ_ACTIVE,
122 SCAN_CHANNEL_TYPE_5GHZ_PASSIVE,
123 SCAN_CHANNEL_TYPE_5GHZ_ACTIVE,
124 SCAN_CHANNEL_TYPE_5GHZ_DFS,
125};
126
127enum {
128 SCAN_SSID_FILTER_ANY = 0,
129 SCAN_SSID_FILTER_SPECIFIC = 1,
130 SCAN_SSID_FILTER_LIST = 2,
131 SCAN_SSID_FILTER_DISABLED = 3
132};
133
134enum {
135 SCAN_BSS_TYPE_INDEPENDENT,
136 SCAN_BSS_TYPE_INFRASTRUCTURE,
137 SCAN_BSS_TYPE_ANY,
138};
139
140#define SCAN_CHANNEL_FLAGS_DFS BIT(0)
141#define SCAN_CHANNEL_FLAGS_DFS_ENABLED BIT(1)
142
143struct conn_scan_ch_params {
144 __le16 min_duration;
145 __le16 max_duration;
146 __le16 passive_duration;
147
148 u8 channel;
149 u8 tx_power_att;
150
151 /* bit 0: DFS channel; bit 1: DFS enabled */
152 u8 flags;
153
154 u8 padding[3];
155} __packed;
156
157struct wl1271_cmd_sched_scan_config {
158 struct wl1271_cmd_header header;
159
160 __le32 intervals[SCAN_MAX_CYCLE_INTERVALS];
161
162 s8 rssi_threshold; /* for filtering (in dBm) */
163 s8 snr_threshold; /* for filtering (in dB) */
164
165 u8 cycles; /* maximum number of scan cycles */
166 u8 report_after; /* report when this number of results are received */
167 u8 terminate; /* stop scanning after reporting */
168
169 u8 tag;
170 u8 bss_type; /* for filtering */
171 u8 filter_type;
172
173 u8 ssid_len; /* For SCAN_SSID_FILTER_SPECIFIC */
174 u8 ssid[IW_ESSID_MAX_SIZE];
175
176 u8 n_probe_reqs; /* Number of probes requests per channel */
177
178 u8 passive[SCAN_MAX_BANDS];
179 u8 active[SCAN_MAX_BANDS];
180
181 u8 dfs;
182
183 u8 padding[3];
184
185 struct conn_scan_ch_params channels[MAX_CHANNELS_ALL_BANDS];
186} __packed;
187
188
189#define SCHED_SCAN_MAX_SSIDS 8
190
191enum {
192 SCAN_SSID_TYPE_PUBLIC = 0,
193 SCAN_SSID_TYPE_HIDDEN = 1,
194};
195
196struct wl1271_ssid {
197 u8 type;
198 u8 len;
199 u8 ssid[IW_ESSID_MAX_SIZE];
200 /* u8 padding[2]; */
201} __packed;
202
203struct wl1271_cmd_sched_scan_ssid_list {
204 struct wl1271_cmd_header header;
205
206 u8 n_ssids;
207 struct wl1271_ssid ssids[SCHED_SCAN_MAX_SSIDS];
208 u8 padding[3];
209} __packed;
210
211struct wl1271_cmd_sched_scan_start {
212 struct wl1271_cmd_header header;
213
214 u8 tag;
215 u8 padding[3];
216} __packed;
217
218struct wl1271_cmd_sched_scan_stop {
219 struct wl1271_cmd_header header;
220
221 u8 tag;
222 u8 padding[3];
223} __packed;
224
225
109#endif /* __WL1271_SCAN_H__ */ 226#endif /* __WL1271_SCAN_H__ */
diff --git a/drivers/net/wireless/wl12xx/wl1271_sdio.c b/drivers/net/wireless/wl12xx/sdio.c
index 7059b5cccf0f..536e5065454b 100644
--- a/drivers/net/wireless/wl12xx/wl1271_sdio.c
+++ b/drivers/net/wireless/wl12xx/sdio.c
@@ -28,14 +28,14 @@
28#include <linux/mmc/sdio_func.h> 28#include <linux/mmc/sdio_func.h>
29#include <linux/mmc/sdio_ids.h> 29#include <linux/mmc/sdio_ids.h>
30#include <linux/mmc/card.h> 30#include <linux/mmc/card.h>
31#include <linux/mmc/host.h>
31#include <linux/gpio.h> 32#include <linux/gpio.h>
33#include <linux/wl12xx.h>
34#include <linux/pm_runtime.h>
32 35
33#include "wl1271.h" 36#include "wl12xx.h"
34#include "wl12xx_80211.h" 37#include "wl12xx_80211.h"
35#include "wl1271_io.h" 38#include "io.h"
36
37
38#define RX71_WL1271_IRQ_GPIO 42
39 39
40#ifndef SDIO_VENDOR_ID_TI 40#ifndef SDIO_VENDOR_ID_TI
41#define SDIO_VENDOR_ID_TI 0x0097 41#define SDIO_VENDOR_ID_TI 0x0097
@@ -51,6 +51,13 @@ static const struct sdio_device_id wl1271_devices[] = {
51}; 51};
52MODULE_DEVICE_TABLE(sdio, wl1271_devices); 52MODULE_DEVICE_TABLE(sdio, wl1271_devices);
53 53
54static void wl1271_sdio_set_block_size(struct wl1271 *wl, unsigned int blksz)
55{
56 sdio_claim_host(wl->if_priv);
57 sdio_set_block_size(wl->if_priv, blksz);
58 sdio_release_host(wl->if_priv);
59}
60
54static inline struct sdio_func *wl_to_func(struct wl1271 *wl) 61static inline struct sdio_func *wl_to_func(struct wl1271 *wl)
55{ 62{
56 return wl->if_priv; 63 return wl->if_priv;
@@ -61,7 +68,7 @@ static struct device *wl1271_sdio_wl_to_dev(struct wl1271 *wl)
61 return &(wl_to_func(wl)->dev); 68 return &(wl_to_func(wl)->dev);
62} 69}
63 70
64static irqreturn_t wl1271_irq(int irq, void *cookie) 71static irqreturn_t wl1271_hardirq(int irq, void *cookie)
65{ 72{
66 struct wl1271 *wl = cookie; 73 struct wl1271 *wl = cookie;
67 unsigned long flags; 74 unsigned long flags;
@@ -70,17 +77,24 @@ static irqreturn_t wl1271_irq(int irq, void *cookie)
70 77
71 /* complete the ELP completion */ 78 /* complete the ELP completion */
72 spin_lock_irqsave(&wl->wl_lock, flags); 79 spin_lock_irqsave(&wl->wl_lock, flags);
80 set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
73 if (wl->elp_compl) { 81 if (wl->elp_compl) {
74 complete(wl->elp_compl); 82 complete(wl->elp_compl);
75 wl->elp_compl = NULL; 83 wl->elp_compl = NULL;
76 } 84 }
77 85
78 if (!test_and_set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags)) 86 if (test_bit(WL1271_FLAG_SUSPENDED, &wl->flags)) {
79 ieee80211_queue_work(wl->hw, &wl->irq_work); 87 /* don't enqueue a work right now. mark it as pending */
80 set_bit(WL1271_FLAG_IRQ_PENDING, &wl->flags); 88 set_bit(WL1271_FLAG_PENDING_WORK, &wl->flags);
89 wl1271_debug(DEBUG_IRQ, "should not enqueue work");
90 disable_irq_nosync(wl->irq);
91 pm_wakeup_event(wl1271_sdio_wl_to_dev(wl), 0);
92 spin_unlock_irqrestore(&wl->wl_lock, flags);
93 return IRQ_HANDLED;
94 }
81 spin_unlock_irqrestore(&wl->wl_lock, flags); 95 spin_unlock_irqrestore(&wl->wl_lock, flags);
82 96
83 return IRQ_HANDLED; 97 return IRQ_WAKE_THREAD;
84} 98}
85 99
86static void wl1271_sdio_disable_interrupts(struct wl1271 *wl) 100static void wl1271_sdio_disable_interrupts(struct wl1271 *wl)
@@ -124,7 +138,6 @@ static void wl1271_sdio_raw_read(struct wl1271 *wl, int addr, void *buf,
124 138
125 if (ret) 139 if (ret)
126 wl1271_error("sdio read failed (%d)", ret); 140 wl1271_error("sdio read failed (%d)", ret);
127
128} 141}
129 142
130static void wl1271_sdio_raw_write(struct wl1271 *wl, int addr, void *buf, 143static void wl1271_sdio_raw_write(struct wl1271 *wl, int addr, void *buf,
@@ -147,26 +160,56 @@ static void wl1271_sdio_raw_write(struct wl1271 *wl, int addr, void *buf,
147 else 160 else
148 ret = sdio_memcpy_toio(func, addr, buf, len); 161 ret = sdio_memcpy_toio(func, addr, buf, len);
149 } 162 }
163
150 if (ret) 164 if (ret)
151 wl1271_error("sdio write failed (%d)", ret); 165 wl1271_error("sdio write failed (%d)", ret);
166}
167
168static int wl1271_sdio_power_on(struct wl1271 *wl)
169{
170 struct sdio_func *func = wl_to_func(wl);
171 int ret;
172
173 /* Make sure the card will not be powered off by runtime PM */
174 ret = pm_runtime_get_sync(&func->dev);
175 if (ret < 0)
176 goto out;
152 177
178 /* Runtime PM might be disabled, so power up the card manually */
179 ret = mmc_power_restore_host(func->card->host);
180 if (ret < 0)
181 goto out;
182
183 sdio_claim_host(func);
184 sdio_enable_func(func);
185
186out:
187 return ret;
153} 188}
154 189
155static void wl1271_sdio_set_power(struct wl1271 *wl, bool enable) 190static int wl1271_sdio_power_off(struct wl1271 *wl)
156{ 191{
157 struct sdio_func *func = wl_to_func(wl); 192 struct sdio_func *func = wl_to_func(wl);
193 int ret;
158 194
159 /* Let the SDIO stack handle wlan_enable control, so we 195 sdio_disable_func(func);
160 * keep host claimed while wlan is in use to keep wl1271 196 sdio_release_host(func);
161 * alive. 197
162 */ 198 /* Runtime PM might be disabled, so power off the card manually */
163 if (enable) { 199 ret = mmc_power_save_host(func->card->host);
164 sdio_claim_host(func); 200 if (ret < 0)
165 sdio_enable_func(func); 201 return ret;
166 } else { 202
167 sdio_disable_func(func); 203 /* Let runtime PM know the card is powered off */
168 sdio_release_host(func); 204 return pm_runtime_put_sync(&func->dev);
169 } 205}
206
207static int wl1271_sdio_set_power(struct wl1271 *wl, bool enable)
208{
209 if (enable)
210 return wl1271_sdio_power_on(wl);
211 else
212 return wl1271_sdio_power_off(wl);
170} 213}
171 214
172static struct wl1271_if_operations sdio_ops = { 215static struct wl1271_if_operations sdio_ops = {
@@ -177,14 +220,18 @@ static struct wl1271_if_operations sdio_ops = {
177 .power = wl1271_sdio_set_power, 220 .power = wl1271_sdio_set_power,
178 .dev = wl1271_sdio_wl_to_dev, 221 .dev = wl1271_sdio_wl_to_dev,
179 .enable_irq = wl1271_sdio_enable_interrupts, 222 .enable_irq = wl1271_sdio_enable_interrupts,
180 .disable_irq = wl1271_sdio_disable_interrupts 223 .disable_irq = wl1271_sdio_disable_interrupts,
224 .set_block_size = wl1271_sdio_set_block_size,
181}; 225};
182 226
183static int __devinit wl1271_probe(struct sdio_func *func, 227static int __devinit wl1271_probe(struct sdio_func *func,
184 const struct sdio_device_id *id) 228 const struct sdio_device_id *id)
185{ 229{
186 struct ieee80211_hw *hw; 230 struct ieee80211_hw *hw;
231 const struct wl12xx_platform_data *wlan_data;
187 struct wl1271 *wl; 232 struct wl1271 *wl;
233 unsigned long irqflags;
234 mmc_pm_flag_t mmcflags;
188 int ret; 235 int ret;
189 236
190 /* We are only able to handle the wlan function */ 237 /* We are only able to handle the wlan function */
@@ -203,23 +250,46 @@ static int __devinit wl1271_probe(struct sdio_func *func,
203 /* Grab access to FN0 for ELP reg. */ 250 /* Grab access to FN0 for ELP reg. */
204 func->card->quirks |= MMC_QUIRK_LENIENT_FN0; 251 func->card->quirks |= MMC_QUIRK_LENIENT_FN0;
205 252
206 wl->irq = gpio_to_irq(RX71_WL1271_IRQ_GPIO); 253 /* Use block mode for transferring over one block size of data */
207 if (wl->irq < 0) { 254 func->card->quirks |= MMC_QUIRK_BLKSZ_FOR_BYTE_MODE;
208 ret = wl->irq; 255
209 wl1271_error("could not get irq!"); 256 wlan_data = wl12xx_get_platform_data();
257 if (IS_ERR(wlan_data)) {
258 ret = PTR_ERR(wlan_data);
259 wl1271_error("missing wlan platform data: %d", ret);
210 goto out_free; 260 goto out_free;
211 } 261 }
212 262
213 ret = request_irq(wl->irq, wl1271_irq, 0, DRIVER_NAME, wl); 263 wl->irq = wlan_data->irq;
264 wl->ref_clock = wlan_data->board_ref_clock;
265 wl->tcxo_clock = wlan_data->board_tcxo_clock;
266 wl->platform_quirks = wlan_data->platform_quirks;
267
268 if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
269 irqflags = IRQF_TRIGGER_RISING;
270 else
271 irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT;
272
273 ret = request_threaded_irq(wl->irq, wl1271_hardirq, wl1271_irq,
274 irqflags,
275 DRIVER_NAME, wl);
214 if (ret < 0) { 276 if (ret < 0) {
215 wl1271_error("request_irq() failed: %d", ret); 277 wl1271_error("request_irq() failed: %d", ret);
216 goto out_free; 278 goto out_free;
217 } 279 }
218 280
219 set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING); 281 enable_irq_wake(wl->irq);
282 device_init_wakeup(wl1271_sdio_wl_to_dev(wl), 1);
220 283
221 disable_irq(wl->irq); 284 disable_irq(wl->irq);
222 285
286 /* if sdio can keep power while host is suspended, enable wow */
287 mmcflags = sdio_get_host_pm_caps(func);
288 wl1271_debug(DEBUG_SDIO, "sdio PM caps = 0x%x", mmcflags);
289
290 if (mmcflags & MMC_PM_KEEP_POWER)
291 hw->wiphy->wowlan.flags = WIPHY_WOWLAN_ANY;
292
223 ret = wl1271_init_ieee80211(wl); 293 ret = wl1271_init_ieee80211(wl);
224 if (ret) 294 if (ret)
225 goto out_irq; 295 goto out_irq;
@@ -230,6 +300,9 @@ static int __devinit wl1271_probe(struct sdio_func *func,
230 300
231 sdio_set_drvdata(func, wl); 301 sdio_set_drvdata(func, wl);
232 302
303 /* Tell PM core that we don't need the card to be powered now */
304 pm_runtime_put_noidle(&func->dev);
305
233 wl1271_notice("initialized"); 306 wl1271_notice("initialized");
234 307
235 return 0; 308 return 0;
@@ -237,7 +310,6 @@ static int __devinit wl1271_probe(struct sdio_func *func,
237 out_irq: 310 out_irq:
238 free_irq(wl->irq, wl); 311 free_irq(wl->irq, wl);
239 312
240
241 out_free: 313 out_free:
242 wl1271_free_hw(wl); 314 wl1271_free_hw(wl);
243 315
@@ -248,17 +320,84 @@ static void __devexit wl1271_remove(struct sdio_func *func)
248{ 320{
249 struct wl1271 *wl = sdio_get_drvdata(func); 321 struct wl1271 *wl = sdio_get_drvdata(func);
250 322
251 free_irq(wl->irq, wl); 323 /* Undo decrement done above in wl1271_probe */
324 pm_runtime_get_noresume(&func->dev);
252 325
253 wl1271_unregister_hw(wl); 326 wl1271_unregister_hw(wl);
327 device_init_wakeup(wl1271_sdio_wl_to_dev(wl), 0);
328 disable_irq_wake(wl->irq);
329 free_irq(wl->irq, wl);
254 wl1271_free_hw(wl); 330 wl1271_free_hw(wl);
255} 331}
256 332
333#ifdef CONFIG_PM
334static int wl1271_suspend(struct device *dev)
335{
336 /* Tell MMC/SDIO core it's OK to power down the card
337 * (if it isn't already), but not to remove it completely */
338 struct sdio_func *func = dev_to_sdio_func(dev);
339 struct wl1271 *wl = sdio_get_drvdata(func);
340 mmc_pm_flag_t sdio_flags;
341 int ret = 0;
342
343 wl1271_debug(DEBUG_MAC80211, "wl1271 suspend. wow_enabled: %d",
344 wl->wow_enabled);
345
346 /* check whether sdio should keep power */
347 if (wl->wow_enabled) {
348 sdio_flags = sdio_get_host_pm_caps(func);
349
350 if (!(sdio_flags & MMC_PM_KEEP_POWER)) {
351 wl1271_error("can't keep power while host "
352 "is suspended");
353 ret = -EINVAL;
354 goto out;
355 }
356
357 /* keep power while host suspended */
358 ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER);
359 if (ret) {
360 wl1271_error("error while trying to keep power");
361 goto out;
362 }
363
364 /* release host */
365 sdio_release_host(func);
366 }
367out:
368 return ret;
369}
370
371static int wl1271_resume(struct device *dev)
372{
373 struct sdio_func *func = dev_to_sdio_func(dev);
374 struct wl1271 *wl = sdio_get_drvdata(func);
375
376 wl1271_debug(DEBUG_MAC80211, "wl1271 resume");
377 if (wl->wow_enabled) {
378 /* claim back host */
379 sdio_claim_host(func);
380 }
381
382 return 0;
383}
384
385static const struct dev_pm_ops wl1271_sdio_pm_ops = {
386 .suspend = wl1271_suspend,
387 .resume = wl1271_resume,
388};
389#endif
390
257static struct sdio_driver wl1271_sdio_driver = { 391static struct sdio_driver wl1271_sdio_driver = {
258 .name = "wl1271_sdio", 392 .name = "wl1271_sdio",
259 .id_table = wl1271_devices, 393 .id_table = wl1271_devices,
260 .probe = wl1271_probe, 394 .probe = wl1271_probe,
261 .remove = __devexit_p(wl1271_remove), 395 .remove = __devexit_p(wl1271_remove),
396#ifdef CONFIG_PM
397 .drv = {
398 .pm = &wl1271_sdio_pm_ops,
399 },
400#endif
262}; 401};
263 402
264static int __init wl1271_init(void) 403static int __init wl1271_init(void)
@@ -286,6 +425,9 @@ module_init(wl1271_init);
286module_exit(wl1271_exit); 425module_exit(wl1271_exit);
287 426
288MODULE_LICENSE("GPL"); 427MODULE_LICENSE("GPL");
289MODULE_AUTHOR("Luciano Coelho <luciano.coelho@nokia.com>"); 428MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
290MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>"); 429MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");
291MODULE_FIRMWARE(WL1271_FW_NAME); 430MODULE_FIRMWARE(WL1271_FW_NAME);
431MODULE_FIRMWARE(WL128X_FW_NAME);
432MODULE_FIRMWARE(WL127X_AP_FW_NAME);
433MODULE_FIRMWARE(WL128X_AP_FW_NAME);
diff --git a/drivers/net/wireless/wl12xx/sdio_test.c b/drivers/net/wireless/wl12xx/sdio_test.c
new file mode 100644
index 000000000000..f28915392877
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/sdio_test.c
@@ -0,0 +1,534 @@
1/*
2 * SDIO testing driver for wl12xx
3 *
4 * Copyright (C) 2010 Nokia Corporation
5 *
6 * Contact: Roger Quadros <roger.quadros@nokia.com>
7 *
8 * wl12xx read/write routines taken from the main module
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * version 2 as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 * 02110-1301 USA
23 *
24 */
25
26#include <linux/irq.h>
27#include <linux/module.h>
28#include <linux/crc7.h>
29#include <linux/vmalloc.h>
30#include <linux/mmc/sdio_func.h>
31#include <linux/mmc/sdio_ids.h>
32#include <linux/mmc/card.h>
33#include <linux/gpio.h>
34#include <linux/wl12xx.h>
35#include <linux/kthread.h>
36#include <linux/firmware.h>
37#include <linux/pm_runtime.h>
38
39#include "wl12xx.h"
40#include "io.h"
41#include "boot.h"
42
43#ifndef SDIO_VENDOR_ID_TI
44#define SDIO_VENDOR_ID_TI 0x0097
45#endif
46
47#ifndef SDIO_DEVICE_ID_TI_WL1271
48#define SDIO_DEVICE_ID_TI_WL1271 0x4076
49#endif
50
51static bool rx, tx;
52
53module_param(rx, bool, S_IRUGO | S_IWUSR);
54MODULE_PARM_DESC(rx, "Perform rx test. Default (0). "
55 "This test continuously reads data from the SDIO device.\n");
56
57module_param(tx, bool, S_IRUGO | S_IWUSR);
58MODULE_PARM_DESC(tx, "Perform tx test. Default (0). "
59 "This test continuously writes data to the SDIO device.\n");
60
61struct wl1271_test {
62 struct wl1271 wl;
63 struct task_struct *test_task;
64};
65
66static const struct sdio_device_id wl1271_devices[] = {
67 { SDIO_DEVICE(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271) },
68 {}
69};
70
71static inline struct sdio_func *wl_to_func(struct wl1271 *wl)
72{
73 return wl->if_priv;
74}
75
76static struct device *wl1271_sdio_wl_to_dev(struct wl1271 *wl)
77{
78 return &(wl_to_func(wl)->dev);
79}
80
81static void wl1271_sdio_raw_read(struct wl1271 *wl, int addr, void *buf,
82 size_t len, bool fixed)
83{
84 int ret = 0;
85 struct sdio_func *func = wl_to_func(wl);
86
87 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) {
88 ((u8 *)buf)[0] = sdio_f0_readb(func, addr, &ret);
89 wl1271_debug(DEBUG_SDIO, "sdio read 52 addr 0x%x, byte 0x%02x",
90 addr, ((u8 *)buf)[0]);
91 } else {
92 if (fixed)
93 ret = sdio_readsb(func, buf, addr, len);
94 else
95 ret = sdio_memcpy_fromio(func, buf, addr, len);
96
97 wl1271_debug(DEBUG_SDIO, "sdio read 53 addr 0x%x, %zu bytes",
98 addr, len);
99 wl1271_dump_ascii(DEBUG_SDIO, "data: ", buf, len);
100 }
101
102 if (ret)
103 wl1271_error("sdio read failed (%d)", ret);
104}
105
106static void wl1271_sdio_raw_write(struct wl1271 *wl, int addr, void *buf,
107 size_t len, bool fixed)
108{
109 int ret = 0;
110 struct sdio_func *func = wl_to_func(wl);
111
112 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) {
113 sdio_f0_writeb(func, ((u8 *)buf)[0], addr, &ret);
114 wl1271_debug(DEBUG_SDIO, "sdio write 52 addr 0x%x, byte 0x%02x",
115 addr, ((u8 *)buf)[0]);
116 } else {
117 wl1271_debug(DEBUG_SDIO, "sdio write 53 addr 0x%x, %zu bytes",
118 addr, len);
119 wl1271_dump_ascii(DEBUG_SDIO, "data: ", buf, len);
120
121 if (fixed)
122 ret = sdio_writesb(func, addr, buf, len);
123 else
124 ret = sdio_memcpy_toio(func, addr, buf, len);
125 }
126 if (ret)
127 wl1271_error("sdio write failed (%d)", ret);
128
129}
130
131static int wl1271_sdio_set_power(struct wl1271 *wl, bool enable)
132{
133 struct sdio_func *func = wl_to_func(wl);
134 int ret;
135
136 /* Let the SDIO stack handle wlan_enable control, so we
137 * keep host claimed while wlan is in use to keep wl1271
138 * alive.
139 */
140 if (enable) {
141 /* Power up the card */
142 ret = pm_runtime_get_sync(&func->dev);
143 if (ret < 0)
144 goto out;
145 sdio_claim_host(func);
146 sdio_enable_func(func);
147 sdio_release_host(func);
148 } else {
149 sdio_claim_host(func);
150 sdio_disable_func(func);
151 sdio_release_host(func);
152
153 /* Power down the card */
154 ret = pm_runtime_put_sync(&func->dev);
155 }
156
157out:
158 return ret;
159}
160
161static void wl1271_sdio_disable_interrupts(struct wl1271 *wl)
162{
163}
164
165static void wl1271_sdio_enable_interrupts(struct wl1271 *wl)
166{
167}
168
169
170static struct wl1271_if_operations sdio_ops = {
171 .read = wl1271_sdio_raw_read,
172 .write = wl1271_sdio_raw_write,
173 .power = wl1271_sdio_set_power,
174 .dev = wl1271_sdio_wl_to_dev,
175 .enable_irq = wl1271_sdio_enable_interrupts,
176 .disable_irq = wl1271_sdio_disable_interrupts,
177};
178
179static void wl1271_fw_wakeup(struct wl1271 *wl)
180{
181 u32 elp_reg;
182
183 elp_reg = ELPCTRL_WAKE_UP;
184 wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
185}
186
187static int wl1271_fetch_firmware(struct wl1271 *wl)
188{
189 const struct firmware *fw;
190 int ret;
191
192 if (wl->chip.id == CHIP_ID_1283_PG20)
193 ret = request_firmware(&fw, WL128X_FW_NAME,
194 wl1271_wl_to_dev(wl));
195 else
196 ret = request_firmware(&fw, WL1271_FW_NAME,
197 wl1271_wl_to_dev(wl));
198
199 if (ret < 0) {
200 wl1271_error("could not get firmware: %d", ret);
201 return ret;
202 }
203
204 if (fw->size % 4) {
205 wl1271_error("firmware size is not multiple of 32 bits: %zu",
206 fw->size);
207 ret = -EILSEQ;
208 goto out;
209 }
210
211 wl->fw_len = fw->size;
212 wl->fw = vmalloc(wl->fw_len);
213
214 if (!wl->fw) {
215 wl1271_error("could not allocate memory for the firmware");
216 ret = -ENOMEM;
217 goto out;
218 }
219
220 memcpy(wl->fw, fw->data, wl->fw_len);
221
222 ret = 0;
223
224out:
225 release_firmware(fw);
226
227 return ret;
228}
229
230static int wl1271_fetch_nvs(struct wl1271 *wl)
231{
232 const struct firmware *fw;
233 int ret;
234
235 ret = request_firmware(&fw, WL12XX_NVS_NAME, wl1271_wl_to_dev(wl));
236
237 if (ret < 0) {
238 wl1271_error("could not get nvs file: %d", ret);
239 return ret;
240 }
241
242 wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL);
243
244 if (!wl->nvs) {
245 wl1271_error("could not allocate memory for the nvs file");
246 ret = -ENOMEM;
247 goto out;
248 }
249
250 wl->nvs_len = fw->size;
251
252out:
253 release_firmware(fw);
254
255 return ret;
256}
257
258static int wl1271_chip_wakeup(struct wl1271 *wl)
259{
260 struct wl1271_partition_set partition;
261 int ret;
262
263 msleep(WL1271_PRE_POWER_ON_SLEEP);
264 ret = wl1271_power_on(wl);
265 if (ret)
266 return ret;
267
268 msleep(WL1271_POWER_ON_SLEEP);
269
270 /* We don't need a real memory partition here, because we only want
271 * to use the registers at this point. */
272 memset(&partition, 0, sizeof(partition));
273 partition.reg.start = REGISTERS_BASE;
274 partition.reg.size = REGISTERS_DOWN_SIZE;
275 wl1271_set_partition(wl, &partition);
276
277 /* ELP module wake up */
278 wl1271_fw_wakeup(wl);
279
280 /* whal_FwCtrl_BootSm() */
281
282 /* 0. read chip id from CHIP_ID */
283 wl->chip.id = wl1271_read32(wl, CHIP_ID_B);
284
285 /* 1. check if chip id is valid */
286
287 switch (wl->chip.id) {
288 case CHIP_ID_1271_PG10:
289 wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete",
290 wl->chip.id);
291 break;
292 case CHIP_ID_1271_PG20:
293 wl1271_notice("chip id 0x%x (1271 PG20)",
294 wl->chip.id);
295 break;
296 case CHIP_ID_1283_PG20:
297 wl1271_notice("chip id 0x%x (1283 PG20)",
298 wl->chip.id);
299 break;
300 case CHIP_ID_1283_PG10:
301 default:
302 wl1271_warning("unsupported chip id: 0x%x", wl->chip.id);
303 return -ENODEV;
304 }
305
306 return ret;
307}
308
309static struct wl1271_partition_set part_down = {
310 .mem = {
311 .start = 0x00000000,
312 .size = 0x000177c0
313 },
314 .reg = {
315 .start = REGISTERS_BASE,
316 .size = 0x00008800
317 },
318 .mem2 = {
319 .start = 0x00000000,
320 .size = 0x00000000
321 },
322 .mem3 = {
323 .start = 0x00000000,
324 .size = 0x00000000
325 },
326};
327
328static int tester(void *data)
329{
330 struct wl1271 *wl = data;
331 struct sdio_func *func = wl_to_func(wl);
332 struct device *pdev = &func->dev;
333 int ret = 0;
334 bool rx_started = 0;
335 bool tx_started = 0;
336 uint8_t *tx_buf, *rx_buf;
337 int test_size = PAGE_SIZE;
338 u32 addr = 0;
339 struct wl1271_partition_set partition;
340
341 /* We assume chip is powered up and firmware fetched */
342
343 memcpy(&partition, &part_down, sizeof(partition));
344 partition.mem.start = addr;
345 wl1271_set_partition(wl, &partition);
346
347 tx_buf = kmalloc(test_size, GFP_KERNEL);
348 rx_buf = kmalloc(test_size, GFP_KERNEL);
349 if (!tx_buf || !rx_buf) {
350 dev_err(pdev,
351 "Could not allocate memory. Test will not run.\n");
352 ret = -ENOMEM;
353 goto free;
354 }
355
356 memset(tx_buf, 0x5a, test_size);
357
358 /* write something in data area so we can read it back */
359 wl1271_write(wl, addr, tx_buf, test_size, false);
360
361 while (!kthread_should_stop()) {
362 if (rx && !rx_started) {
363 dev_info(pdev, "starting rx test\n");
364 rx_started = 1;
365 } else if (!rx && rx_started) {
366 dev_info(pdev, "stopping rx test\n");
367 rx_started = 0;
368 }
369
370 if (tx && !tx_started) {
371 dev_info(pdev, "starting tx test\n");
372 tx_started = 1;
373 } else if (!tx && tx_started) {
374 dev_info(pdev, "stopping tx test\n");
375 tx_started = 0;
376 }
377
378 if (rx_started)
379 wl1271_read(wl, addr, rx_buf, test_size, false);
380
381 if (tx_started)
382 wl1271_write(wl, addr, tx_buf, test_size, false);
383
384 if (!rx_started && !tx_started)
385 msleep(100);
386 }
387
388free:
389 kfree(tx_buf);
390 kfree(rx_buf);
391 return ret;
392}
393
394static int __devinit wl1271_probe(struct sdio_func *func,
395 const struct sdio_device_id *id)
396{
397 const struct wl12xx_platform_data *wlan_data;
398 struct wl1271 *wl;
399 struct wl1271_test *wl_test;
400 int ret = 0;
401
402 /* wl1271 has 2 sdio functions we handle just the wlan part */
403 if (func->num != 0x02)
404 return -ENODEV;
405
406 wl_test = kzalloc(sizeof(struct wl1271_test), GFP_KERNEL);
407 if (!wl_test) {
408 dev_err(&func->dev, "Could not allocate memory\n");
409 return -ENOMEM;
410 }
411
412 wl = &wl_test->wl;
413
414 wl->if_priv = func;
415 wl->if_ops = &sdio_ops;
416
417 /* Grab access to FN0 for ELP reg. */
418 func->card->quirks |= MMC_QUIRK_LENIENT_FN0;
419
420 /* Use block mode for transferring over one block size of data */
421 func->card->quirks |= MMC_QUIRK_BLKSZ_FOR_BYTE_MODE;
422
423 wlan_data = wl12xx_get_platform_data();
424 if (IS_ERR(wlan_data)) {
425 ret = PTR_ERR(wlan_data);
426 dev_err(&func->dev, "missing wlan platform data: %d\n", ret);
427 goto out_free;
428 }
429
430 wl->irq = wlan_data->irq;
431 wl->ref_clock = wlan_data->board_ref_clock;
432 wl->tcxo_clock = wlan_data->board_tcxo_clock;
433
434 sdio_set_drvdata(func, wl_test);
435
436
437 /* power up the device */
438 ret = wl1271_chip_wakeup(wl);
439 if (ret) {
440 dev_err(&func->dev, "could not wake up chip\n");
441 goto out_free;
442 }
443
444 if (wl->fw == NULL) {
445 ret = wl1271_fetch_firmware(wl);
446 if (ret < 0) {
447 dev_err(&func->dev, "firmware fetch error\n");
448 goto out_off;
449 }
450 }
451
452 /* fetch NVS */
453 if (wl->nvs == NULL) {
454 ret = wl1271_fetch_nvs(wl);
455 if (ret < 0) {
456 dev_err(&func->dev, "NVS fetch error\n");
457 goto out_off;
458 }
459 }
460
461 ret = wl1271_load_firmware(wl);
462 if (ret < 0) {
463 dev_err(&func->dev, "firmware load error: %d\n", ret);
464 goto out_free;
465 }
466
467 dev_info(&func->dev, "initialized\n");
468
469 /* I/O testing will be done in the tester thread */
470
471 wl_test->test_task = kthread_run(tester, wl, "sdio_tester");
472 if (IS_ERR(wl_test->test_task)) {
473 dev_err(&func->dev, "unable to create kernel thread\n");
474 ret = PTR_ERR(wl_test->test_task);
475 goto out_free;
476 }
477
478 return 0;
479
480out_off:
481 /* power off the chip */
482 wl1271_power_off(wl);
483
484out_free:
485 kfree(wl_test);
486 return ret;
487}
488
489static void __devexit wl1271_remove(struct sdio_func *func)
490{
491 struct wl1271_test *wl_test = sdio_get_drvdata(func);
492
493 /* stop the I/O test thread */
494 kthread_stop(wl_test->test_task);
495
496 /* power off the chip */
497 wl1271_power_off(&wl_test->wl);
498
499 vfree(wl_test->wl.fw);
500 wl_test->wl.fw = NULL;
501 kfree(wl_test->wl.nvs);
502 wl_test->wl.nvs = NULL;
503
504 kfree(wl_test);
505}
506
507static struct sdio_driver wl1271_sdio_driver = {
508 .name = "wl12xx_sdio_test",
509 .id_table = wl1271_devices,
510 .probe = wl1271_probe,
511 .remove = __devexit_p(wl1271_remove),
512};
513
514static int __init wl1271_init(void)
515{
516 int ret;
517
518 ret = sdio_register_driver(&wl1271_sdio_driver);
519 if (ret < 0)
520 pr_err("failed to register sdio driver: %d\n", ret);
521
522 return ret;
523}
524module_init(wl1271_init);
525
526static void __exit wl1271_exit(void)
527{
528 sdio_unregister_driver(&wl1271_sdio_driver);
529}
530module_exit(wl1271_exit);
531
532MODULE_LICENSE("GPL");
533MODULE_AUTHOR("Roger Quadros <roger.quadros@nokia.com>");
534
diff --git a/drivers/net/wireless/wl12xx/wl1271_spi.c b/drivers/net/wireless/wl12xx/spi.c
index 4cb99c541e2a..51662bb68019 100644
--- a/drivers/net/wireless/wl12xx/wl1271_spi.c
+++ b/drivers/net/wireless/wl12xx/spi.c
@@ -25,14 +25,14 @@
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/crc7.h> 26#include <linux/crc7.h>
27#include <linux/spi/spi.h> 27#include <linux/spi/spi.h>
28#include <linux/spi/wl12xx.h> 28#include <linux/wl12xx.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30 30
31#include "wl1271.h" 31#include "wl12xx.h"
32#include "wl12xx_80211.h" 32#include "wl12xx_80211.h"
33#include "wl1271_io.h" 33#include "io.h"
34 34
35#include "wl1271_reg.h" 35#include "reg.h"
36 36
37#define WSPI_CMD_READ 0x40000000 37#define WSPI_CMD_READ 0x40000000
38#define WSPI_CMD_WRITE 0x00000000 38#define WSPI_CMD_WRITE 0x00000000
@@ -63,6 +63,11 @@
63 ((WL1271_BUSY_WORD_LEN - 4) / sizeof(u32)) 63 ((WL1271_BUSY_WORD_LEN - 4) / sizeof(u32))
64#define HW_ACCESS_WSPI_INIT_CMD_MASK 0 64#define HW_ACCESS_WSPI_INIT_CMD_MASK 0
65 65
66/* HW limitation: maximum possible chunk size is 4095 bytes */
67#define WSPI_MAX_CHUNK_SIZE 4092
68
69#define WSPI_MAX_NUM_OF_CHUNKS (WL1271_AGGR_BUFFER_SIZE / WSPI_MAX_CHUNK_SIZE)
70
66static inline struct spi_device *wl_to_spi(struct wl1271 *wl) 71static inline struct spi_device *wl_to_spi(struct wl1271 *wl)
67{ 72{
68 return wl->if_priv; 73 return wl->if_priv;
@@ -105,9 +110,9 @@ static void wl1271_spi_reset(struct wl1271 *wl)
105 spi_message_add_tail(&t, &m); 110 spi_message_add_tail(&t, &m);
106 111
107 spi_sync(wl_to_spi(wl), &m); 112 spi_sync(wl_to_spi(wl), &m);
108 kfree(cmd);
109 113
110 wl1271_dump(DEBUG_SPI, "spi reset -> ", cmd, WSPI_INIT_CMD_LEN); 114 wl1271_dump(DEBUG_SPI, "spi reset -> ", cmd, WSPI_INIT_CMD_LEN);
115 kfree(cmd);
111} 116}
112 117
113static void wl1271_spi_init(struct wl1271 *wl) 118static void wl1271_spi_init(struct wl1271 *wl)
@@ -202,120 +207,144 @@ static int wl1271_spi_read_busy(struct wl1271 *wl)
202static void wl1271_spi_raw_read(struct wl1271 *wl, int addr, void *buf, 207static void wl1271_spi_raw_read(struct wl1271 *wl, int addr, void *buf,
203 size_t len, bool fixed) 208 size_t len, bool fixed)
204{ 209{
205 struct spi_transfer t[3]; 210 struct spi_transfer t[2];
206 struct spi_message m; 211 struct spi_message m;
207 u32 *busy_buf; 212 u32 *busy_buf;
208 u32 *cmd; 213 u32 *cmd;
214 u32 chunk_len;
209 215
210 cmd = &wl->buffer_cmd; 216 while (len > 0) {
211 busy_buf = wl->buffer_busyword; 217 chunk_len = min((size_t)WSPI_MAX_CHUNK_SIZE, len);
212 218
213 *cmd = 0; 219 cmd = &wl->buffer_cmd;
214 *cmd |= WSPI_CMD_READ; 220 busy_buf = wl->buffer_busyword;
215 *cmd |= (len << WSPI_CMD_BYTE_LENGTH_OFFSET) & WSPI_CMD_BYTE_LENGTH;
216 *cmd |= addr & WSPI_CMD_BYTE_ADDR;
217 221
218 if (fixed) 222 *cmd = 0;
219 *cmd |= WSPI_CMD_FIXED; 223 *cmd |= WSPI_CMD_READ;
224 *cmd |= (chunk_len << WSPI_CMD_BYTE_LENGTH_OFFSET) &
225 WSPI_CMD_BYTE_LENGTH;
226 *cmd |= addr & WSPI_CMD_BYTE_ADDR;
220 227
221 spi_message_init(&m); 228 if (fixed)
222 memset(t, 0, sizeof(t)); 229 *cmd |= WSPI_CMD_FIXED;
223 230
224 t[0].tx_buf = cmd; 231 spi_message_init(&m);
225 t[0].len = 4; 232 memset(t, 0, sizeof(t));
226 t[0].cs_change = true;
227 spi_message_add_tail(&t[0], &m);
228 233
229 /* Busy and non busy words read */ 234 t[0].tx_buf = cmd;
230 t[1].rx_buf = busy_buf; 235 t[0].len = 4;
231 t[1].len = WL1271_BUSY_WORD_LEN; 236 t[0].cs_change = true;
232 t[1].cs_change = true; 237 spi_message_add_tail(&t[0], &m);
233 spi_message_add_tail(&t[1], &m);
234 238
235 spi_sync(wl_to_spi(wl), &m); 239 /* Busy and non busy words read */
240 t[1].rx_buf = busy_buf;
241 t[1].len = WL1271_BUSY_WORD_LEN;
242 t[1].cs_change = true;
243 spi_message_add_tail(&t[1], &m);
236 244
237 if (!(busy_buf[WL1271_BUSY_WORD_CNT - 1] & 0x1) && 245 spi_sync(wl_to_spi(wl), &m);
238 wl1271_spi_read_busy(wl)) {
239 memset(buf, 0, len);
240 return;
241 }
242 246
243 spi_message_init(&m); 247 if (!(busy_buf[WL1271_BUSY_WORD_CNT - 1] & 0x1) &&
244 memset(t, 0, sizeof(t)); 248 wl1271_spi_read_busy(wl)) {
249 memset(buf, 0, chunk_len);
250 return;
251 }
252
253 spi_message_init(&m);
254 memset(t, 0, sizeof(t));
245 255
246 t[0].rx_buf = buf; 256 t[0].rx_buf = buf;
247 t[0].len = len; 257 t[0].len = chunk_len;
248 t[0].cs_change = true; 258 t[0].cs_change = true;
249 spi_message_add_tail(&t[0], &m); 259 spi_message_add_tail(&t[0], &m);
250 260
251 spi_sync(wl_to_spi(wl), &m); 261 spi_sync(wl_to_spi(wl), &m);
252 262
253 wl1271_dump(DEBUG_SPI, "spi_read cmd -> ", cmd, sizeof(*cmd)); 263 wl1271_dump(DEBUG_SPI, "spi_read cmd -> ", cmd, sizeof(*cmd));
254 wl1271_dump(DEBUG_SPI, "spi_read buf <- ", buf, len); 264 wl1271_dump(DEBUG_SPI, "spi_read buf <- ", buf, chunk_len);
265
266 if (!fixed)
267 addr += chunk_len;
268 buf += chunk_len;
269 len -= chunk_len;
270 }
255} 271}
256 272
257static void wl1271_spi_raw_write(struct wl1271 *wl, int addr, void *buf, 273static void wl1271_spi_raw_write(struct wl1271 *wl, int addr, void *buf,
258 size_t len, bool fixed) 274 size_t len, bool fixed)
259{ 275{
260 struct spi_transfer t[2]; 276 struct spi_transfer t[2 * WSPI_MAX_NUM_OF_CHUNKS];
261 struct spi_message m; 277 struct spi_message m;
278 u32 commands[WSPI_MAX_NUM_OF_CHUNKS];
262 u32 *cmd; 279 u32 *cmd;
280 u32 chunk_len;
281 int i;
263 282
264 cmd = &wl->buffer_cmd; 283 WARN_ON(len > WL1271_AGGR_BUFFER_SIZE);
265
266 *cmd = 0;
267 *cmd |= WSPI_CMD_WRITE;
268 *cmd |= (len << WSPI_CMD_BYTE_LENGTH_OFFSET) & WSPI_CMD_BYTE_LENGTH;
269 *cmd |= addr & WSPI_CMD_BYTE_ADDR;
270
271 if (fixed)
272 *cmd |= WSPI_CMD_FIXED;
273 284
274 spi_message_init(&m); 285 spi_message_init(&m);
275 memset(t, 0, sizeof(t)); 286 memset(t, 0, sizeof(t));
276 287
277 t[0].tx_buf = cmd; 288 cmd = &commands[0];
278 t[0].len = sizeof(*cmd); 289 i = 0;
279 spi_message_add_tail(&t[0], &m); 290 while (len > 0) {
291 chunk_len = min((size_t)WSPI_MAX_CHUNK_SIZE, len);
280 292
281 t[1].tx_buf = buf; 293 *cmd = 0;
282 t[1].len = len; 294 *cmd |= WSPI_CMD_WRITE;
283 spi_message_add_tail(&t[1], &m); 295 *cmd |= (chunk_len << WSPI_CMD_BYTE_LENGTH_OFFSET) &
296 WSPI_CMD_BYTE_LENGTH;
297 *cmd |= addr & WSPI_CMD_BYTE_ADDR;
284 298
285 spi_sync(wl_to_spi(wl), &m); 299 if (fixed)
300 *cmd |= WSPI_CMD_FIXED;
286 301
287 wl1271_dump(DEBUG_SPI, "spi_write cmd -> ", cmd, sizeof(*cmd)); 302 t[i].tx_buf = cmd;
288 wl1271_dump(DEBUG_SPI, "spi_write buf -> ", buf, len); 303 t[i].len = sizeof(*cmd);
304 spi_message_add_tail(&t[i++], &m);
305
306 t[i].tx_buf = buf;
307 t[i].len = chunk_len;
308 spi_message_add_tail(&t[i++], &m);
309
310 wl1271_dump(DEBUG_SPI, "spi_write cmd -> ", cmd, sizeof(*cmd));
311 wl1271_dump(DEBUG_SPI, "spi_write buf -> ", buf, chunk_len);
312
313 if (!fixed)
314 addr += chunk_len;
315 buf += chunk_len;
316 len -= chunk_len;
317 cmd++;
318 }
319
320 spi_sync(wl_to_spi(wl), &m);
289} 321}
290 322
291static irqreturn_t wl1271_irq(int irq, void *cookie) 323static irqreturn_t wl1271_hardirq(int irq, void *cookie)
292{ 324{
293 struct wl1271 *wl; 325 struct wl1271 *wl = cookie;
294 unsigned long flags; 326 unsigned long flags;
295 327
296 wl1271_debug(DEBUG_IRQ, "IRQ"); 328 wl1271_debug(DEBUG_IRQ, "IRQ");
297 329
298 wl = cookie;
299
300 /* complete the ELP completion */ 330 /* complete the ELP completion */
301 spin_lock_irqsave(&wl->wl_lock, flags); 331 spin_lock_irqsave(&wl->wl_lock, flags);
332 set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
302 if (wl->elp_compl) { 333 if (wl->elp_compl) {
303 complete(wl->elp_compl); 334 complete(wl->elp_compl);
304 wl->elp_compl = NULL; 335 wl->elp_compl = NULL;
305 } 336 }
306
307 if (!test_and_set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags))
308 ieee80211_queue_work(wl->hw, &wl->irq_work);
309 set_bit(WL1271_FLAG_IRQ_PENDING, &wl->flags);
310 spin_unlock_irqrestore(&wl->wl_lock, flags); 337 spin_unlock_irqrestore(&wl->wl_lock, flags);
311 338
312 return IRQ_HANDLED; 339 return IRQ_WAKE_THREAD;
313} 340}
314 341
315static void wl1271_spi_set_power(struct wl1271 *wl, bool enable) 342static int wl1271_spi_set_power(struct wl1271 *wl, bool enable)
316{ 343{
317 if (wl->set_power) 344 if (wl->set_power)
318 wl->set_power(enable); 345 wl->set_power(enable);
346
347 return 0;
319} 348}
320 349
321static struct wl1271_if_operations spi_ops = { 350static struct wl1271_if_operations spi_ops = {
@@ -326,7 +355,8 @@ static struct wl1271_if_operations spi_ops = {
326 .power = wl1271_spi_set_power, 355 .power = wl1271_spi_set_power,
327 .dev = wl1271_spi_wl_to_dev, 356 .dev = wl1271_spi_wl_to_dev,
328 .enable_irq = wl1271_spi_enable_interrupts, 357 .enable_irq = wl1271_spi_enable_interrupts,
329 .disable_irq = wl1271_spi_disable_interrupts 358 .disable_irq = wl1271_spi_disable_interrupts,
359 .set_block_size = NULL,
330}; 360};
331 361
332static int __devinit wl1271_probe(struct spi_device *spi) 362static int __devinit wl1271_probe(struct spi_device *spi)
@@ -334,6 +364,7 @@ static int __devinit wl1271_probe(struct spi_device *spi)
334 struct wl12xx_platform_data *pdata; 364 struct wl12xx_platform_data *pdata;
335 struct ieee80211_hw *hw; 365 struct ieee80211_hw *hw;
336 struct wl1271 *wl; 366 struct wl1271 *wl;
367 unsigned long irqflags;
337 int ret; 368 int ret;
338 369
339 pdata = spi->dev.platform_data; 370 pdata = spi->dev.platform_data;
@@ -370,6 +401,15 @@ static int __devinit wl1271_probe(struct spi_device *spi)
370 goto out_free; 401 goto out_free;
371 } 402 }
372 403
404 wl->ref_clock = pdata->board_ref_clock;
405 wl->tcxo_clock = pdata->board_tcxo_clock;
406 wl->platform_quirks = pdata->platform_quirks;
407
408 if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
409 irqflags = IRQF_TRIGGER_RISING;
410 else
411 irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT;
412
373 wl->irq = spi->irq; 413 wl->irq = spi->irq;
374 if (wl->irq < 0) { 414 if (wl->irq < 0) {
375 wl1271_error("irq missing in platform data"); 415 wl1271_error("irq missing in platform data");
@@ -377,14 +417,14 @@ static int __devinit wl1271_probe(struct spi_device *spi)
377 goto out_free; 417 goto out_free;
378 } 418 }
379 419
380 ret = request_irq(wl->irq, wl1271_irq, 0, DRIVER_NAME, wl); 420 ret = request_threaded_irq(wl->irq, wl1271_hardirq, wl1271_irq,
421 irqflags,
422 DRIVER_NAME, wl);
381 if (ret < 0) { 423 if (ret < 0) {
382 wl1271_error("request_irq() failed: %d", ret); 424 wl1271_error("request_irq() failed: %d", ret);
383 goto out_free; 425 goto out_free;
384 } 426 }
385 427
386 set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
387
388 disable_irq(wl->irq); 428 disable_irq(wl->irq);
389 429
390 ret = wl1271_init_ieee80211(wl); 430 ret = wl1271_init_ieee80211(wl);
@@ -412,9 +452,8 @@ static int __devexit wl1271_remove(struct spi_device *spi)
412{ 452{
413 struct wl1271 *wl = dev_get_drvdata(&spi->dev); 453 struct wl1271 *wl = dev_get_drvdata(&spi->dev);
414 454
415 free_irq(wl->irq, wl);
416
417 wl1271_unregister_hw(wl); 455 wl1271_unregister_hw(wl);
456 free_irq(wl->irq, wl);
418 wl1271_free_hw(wl); 457 wl1271_free_hw(wl);
419 458
420 return 0; 459 return 0;
@@ -457,7 +496,10 @@ module_init(wl1271_init);
457module_exit(wl1271_exit); 496module_exit(wl1271_exit);
458 497
459MODULE_LICENSE("GPL"); 498MODULE_LICENSE("GPL");
460MODULE_AUTHOR("Luciano Coelho <luciano.coelho@nokia.com>"); 499MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
461MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>"); 500MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");
462MODULE_FIRMWARE(WL1271_FW_NAME); 501MODULE_FIRMWARE(WL1271_FW_NAME);
502MODULE_FIRMWARE(WL128X_FW_NAME);
503MODULE_FIRMWARE(WL127X_AP_FW_NAME);
504MODULE_FIRMWARE(WL128X_AP_FW_NAME);
463MODULE_ALIAS("spi:wl1271"); 505MODULE_ALIAS("spi:wl1271");
diff --git a/drivers/net/wireless/wl12xx/wl1271_testmode.c b/drivers/net/wireless/wl12xx/testmode.c
index 6e0952f79e9a..da351d7cd1f2 100644
--- a/drivers/net/wireless/wl12xx/wl1271_testmode.c
+++ b/drivers/net/wireless/wl12xx/testmode.c
@@ -20,13 +20,14 @@
20 * 02110-1301 USA 20 * 02110-1301 USA
21 * 21 *
22 */ 22 */
23#include "wl1271_testmode.h" 23#include "testmode.h"
24 24
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <net/genetlink.h> 26#include <net/genetlink.h>
27 27
28#include "wl1271.h" 28#include "wl12xx.h"
29#include "wl1271_acx.h" 29#include "acx.h"
30#include "reg.h"
30 31
31#define WL1271_TM_MAX_DATA_LENGTH 1024 32#define WL1271_TM_MAX_DATA_LENGTH 1024
32 33
@@ -37,6 +38,7 @@ enum wl1271_tm_commands {
37 WL1271_TM_CMD_CONFIGURE, 38 WL1271_TM_CMD_CONFIGURE,
38 WL1271_TM_CMD_NVS_PUSH, 39 WL1271_TM_CMD_NVS_PUSH,
39 WL1271_TM_CMD_SET_PLT_MODE, 40 WL1271_TM_CMD_SET_PLT_MODE,
41 WL1271_TM_CMD_RECOVER,
40 42
41 __WL1271_TM_CMD_AFTER_LAST 43 __WL1271_TM_CMD_AFTER_LAST
42}; 44};
@@ -199,24 +201,17 @@ static int wl1271_tm_cmd_nvs_push(struct wl1271 *wl, struct nlattr *tb[])
199 buf = nla_data(tb[WL1271_TM_ATTR_DATA]); 201 buf = nla_data(tb[WL1271_TM_ATTR_DATA]);
200 len = nla_len(tb[WL1271_TM_ATTR_DATA]); 202 len = nla_len(tb[WL1271_TM_ATTR_DATA]);
201 203
202 /*
203 * FIXME: the LEGACY NVS image support (NVS's missing the 5GHz band
204 * configurations) can be removed when those NVS files stop floating
205 * around.
206 */
207 if (len != sizeof(struct wl1271_nvs_file) &&
208 (len != WL1271_INI_LEGACY_NVS_FILE_SIZE ||
209 wl1271_11a_enabled())) {
210 wl1271_error("nvs size is not as expected: %zu != %zu",
211 len, sizeof(struct wl1271_nvs_file));
212 return -EMSGSIZE;
213 }
214
215 mutex_lock(&wl->mutex); 204 mutex_lock(&wl->mutex);
216 205
217 kfree(wl->nvs); 206 kfree(wl->nvs);
218 207
219 wl->nvs = kzalloc(sizeof(struct wl1271_nvs_file), GFP_KERNEL); 208 if ((wl->chip.id == CHIP_ID_1283_PG20) &&
209 (len != sizeof(struct wl128x_nvs_file)))
210 return -EINVAL;
211 else if (len != sizeof(struct wl1271_nvs_file))
212 return -EINVAL;
213
214 wl->nvs = kzalloc(len, GFP_KERNEL);
220 if (!wl->nvs) { 215 if (!wl->nvs) {
221 wl1271_error("could not allocate memory for the nvs file"); 216 wl1271_error("could not allocate memory for the nvs file");
222 ret = -ENOMEM; 217 ret = -ENOMEM;
@@ -224,6 +219,7 @@ static int wl1271_tm_cmd_nvs_push(struct wl1271 *wl, struct nlattr *tb[])
224 } 219 }
225 220
226 memcpy(wl->nvs, buf, len); 221 memcpy(wl->nvs, buf, len);
222 wl->nvs_len = len;
227 223
228 wl1271_debug(DEBUG_TESTMODE, "testmode pushed nvs"); 224 wl1271_debug(DEBUG_TESTMODE, "testmode pushed nvs");
229 225
@@ -260,6 +256,15 @@ static int wl1271_tm_cmd_set_plt_mode(struct wl1271 *wl, struct nlattr *tb[])
260 return ret; 256 return ret;
261} 257}
262 258
259static int wl1271_tm_cmd_recover(struct wl1271 *wl, struct nlattr *tb[])
260{
261 wl1271_debug(DEBUG_TESTMODE, "testmode cmd recover");
262
263 ieee80211_queue_work(wl->hw, &wl->recovery_work);
264
265 return 0;
266}
267
263int wl1271_tm_cmd(struct ieee80211_hw *hw, void *data, int len) 268int wl1271_tm_cmd(struct ieee80211_hw *hw, void *data, int len)
264{ 269{
265 struct wl1271 *wl = hw->priv; 270 struct wl1271 *wl = hw->priv;
@@ -284,6 +289,8 @@ int wl1271_tm_cmd(struct ieee80211_hw *hw, void *data, int len)
284 return wl1271_tm_cmd_nvs_push(wl, tb); 289 return wl1271_tm_cmd_nvs_push(wl, tb);
285 case WL1271_TM_CMD_SET_PLT_MODE: 290 case WL1271_TM_CMD_SET_PLT_MODE:
286 return wl1271_tm_cmd_set_plt_mode(wl, tb); 291 return wl1271_tm_cmd_set_plt_mode(wl, tb);
292 case WL1271_TM_CMD_RECOVER:
293 return wl1271_tm_cmd_recover(wl, tb);
287 default: 294 default:
288 return -EOPNOTSUPP; 295 return -EOPNOTSUPP;
289 } 296 }
diff --git a/drivers/net/wireless/wl12xx/wl1271_testmode.h b/drivers/net/wireless/wl12xx/testmode.h
index c196d28f9d9d..8071654259ea 100644
--- a/drivers/net/wireless/wl12xx/wl1271_testmode.h
+++ b/drivers/net/wireless/wl12xx/testmode.h
@@ -21,8 +21,8 @@
21 * 21 *
22 */ 22 */
23 23
24#ifndef __WL1271_TESTMODE_H__ 24#ifndef __TESTMODE_H__
25#define __WL1271_TESTMODE_H__ 25#define __TESTMODE_H__
26 26
27#include <net/mac80211.h> 27#include <net/mac80211.h>
28 28
diff --git a/drivers/net/wireless/wl12xx/tx.c b/drivers/net/wireless/wl12xx/tx.c
new file mode 100644
index 000000000000..ca3ab1c1acef
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/tx.c
@@ -0,0 +1,885 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 *
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include <linux/kernel.h>
25#include <linux/module.h>
26#include <linux/etherdevice.h>
27
28#include "wl12xx.h"
29#include "io.h"
30#include "reg.h"
31#include "ps.h"
32#include "tx.h"
33
34static int wl1271_set_default_wep_key(struct wl1271 *wl, u8 id)
35{
36 int ret;
37 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
38
39 if (is_ap)
40 ret = wl1271_cmd_set_ap_default_wep_key(wl, id);
41 else
42 ret = wl1271_cmd_set_sta_default_wep_key(wl, id);
43
44 if (ret < 0)
45 return ret;
46
47 wl1271_debug(DEBUG_CRYPT, "default wep key idx: %d", (int)id);
48 return 0;
49}
50
51static int wl1271_alloc_tx_id(struct wl1271 *wl, struct sk_buff *skb)
52{
53 int id;
54
55 id = find_first_zero_bit(wl->tx_frames_map, ACX_TX_DESCRIPTORS);
56 if (id >= ACX_TX_DESCRIPTORS)
57 return -EBUSY;
58
59 __set_bit(id, wl->tx_frames_map);
60 wl->tx_frames[id] = skb;
61 wl->tx_frames_cnt++;
62 return id;
63}
64
65static void wl1271_free_tx_id(struct wl1271 *wl, int id)
66{
67 if (__test_and_clear_bit(id, wl->tx_frames_map)) {
68 if (unlikely(wl->tx_frames_cnt == ACX_TX_DESCRIPTORS))
69 clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
70
71 wl->tx_frames[id] = NULL;
72 wl->tx_frames_cnt--;
73 }
74}
75
76static int wl1271_tx_update_filters(struct wl1271 *wl,
77 struct sk_buff *skb)
78{
79 struct ieee80211_hdr *hdr;
80
81 hdr = (struct ieee80211_hdr *)(skb->data +
82 sizeof(struct wl1271_tx_hw_descr));
83
84 /*
85 * stop bssid-based filtering before transmitting authentication
86 * requests. this way the hw will never drop authentication
87 * responses coming from BSSIDs it isn't familiar with (e.g. on
88 * roaming)
89 */
90 if (!ieee80211_is_auth(hdr->frame_control))
91 return 0;
92
93 wl1271_configure_filters(wl, FIF_OTHER_BSS);
94
95 return wl1271_acx_rx_config(wl, wl->rx_config, wl->rx_filter);
96}
97
98static void wl1271_tx_ap_update_inconnection_sta(struct wl1271 *wl,
99 struct sk_buff *skb)
100{
101 struct ieee80211_hdr *hdr;
102
103 /*
104 * add the station to the known list before transmitting the
105 * authentication response. this way it won't get de-authed by FW
106 * when transmitting too soon.
107 */
108 hdr = (struct ieee80211_hdr *)(skb->data +
109 sizeof(struct wl1271_tx_hw_descr));
110 if (ieee80211_is_auth(hdr->frame_control))
111 wl1271_acx_set_inconnection_sta(wl, hdr->addr1);
112}
113
114static void wl1271_tx_regulate_link(struct wl1271 *wl, u8 hlid)
115{
116 bool fw_ps;
117 u8 tx_blks;
118
119 /* only regulate station links */
120 if (hlid < WL1271_AP_STA_HLID_START)
121 return;
122
123 fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
124 tx_blks = wl->links[hlid].allocated_blks;
125
126 /*
127 * if in FW PS and there is enough data in FW we can put the link
128 * into high-level PS and clean out its TX queues.
129 */
130 if (fw_ps && tx_blks >= WL1271_PS_STA_MAX_BLOCKS)
131 wl1271_ps_link_start(wl, hlid, true);
132}
133
134u8 wl1271_tx_get_hlid(struct sk_buff *skb)
135{
136 struct ieee80211_tx_info *control = IEEE80211_SKB_CB(skb);
137
138 if (control->control.sta) {
139 struct wl1271_station *wl_sta;
140
141 wl_sta = (struct wl1271_station *)
142 control->control.sta->drv_priv;
143 return wl_sta->hlid;
144 } else {
145 struct ieee80211_hdr *hdr;
146
147 hdr = (struct ieee80211_hdr *)skb->data;
148 if (ieee80211_is_mgmt(hdr->frame_control))
149 return WL1271_AP_GLOBAL_HLID;
150 else
151 return WL1271_AP_BROADCAST_HLID;
152 }
153}
154
155static unsigned int wl12xx_calc_packet_alignment(struct wl1271 *wl,
156 unsigned int packet_length)
157{
158 if (wl->quirks & WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT)
159 return ALIGN(packet_length, WL12XX_BUS_BLOCK_SIZE);
160 else
161 return ALIGN(packet_length, WL1271_TX_ALIGN_TO);
162}
163
164static int wl1271_tx_allocate(struct wl1271 *wl, struct sk_buff *skb, u32 extra,
165 u32 buf_offset, u8 hlid)
166{
167 struct wl1271_tx_hw_descr *desc;
168 u32 total_len = skb->len + sizeof(struct wl1271_tx_hw_descr) + extra;
169 u32 len;
170 u32 total_blocks;
171 int id, ret = -EBUSY;
172 u32 spare_blocks;
173
174 if (unlikely(wl->quirks & WL12XX_QUIRK_USE_2_SPARE_BLOCKS))
175 spare_blocks = 2;
176 else
177 spare_blocks = 1;
178
179 if (buf_offset + total_len > WL1271_AGGR_BUFFER_SIZE)
180 return -EAGAIN;
181
182 /* allocate free identifier for the packet */
183 id = wl1271_alloc_tx_id(wl, skb);
184 if (id < 0)
185 return id;
186
187 /* approximate the number of blocks required for this packet
188 in the firmware */
189 len = wl12xx_calc_packet_alignment(wl, total_len);
190
191 total_blocks = (len + TX_HW_BLOCK_SIZE - 1) / TX_HW_BLOCK_SIZE +
192 spare_blocks;
193
194 if (total_blocks <= wl->tx_blocks_available) {
195 desc = (struct wl1271_tx_hw_descr *)skb_push(
196 skb, total_len - skb->len);
197
198 /* HW descriptor fields change between wl127x and wl128x */
199 if (wl->chip.id == CHIP_ID_1283_PG20) {
200 desc->wl128x_mem.total_mem_blocks = total_blocks;
201 } else {
202 desc->wl127x_mem.extra_blocks = spare_blocks;
203 desc->wl127x_mem.total_mem_blocks = total_blocks;
204 }
205
206 desc->id = id;
207
208 wl->tx_blocks_available -= total_blocks;
209 wl->tx_allocated_blocks += total_blocks;
210
211 if (wl->bss_type == BSS_TYPE_AP_BSS)
212 wl->links[hlid].allocated_blks += total_blocks;
213
214 ret = 0;
215
216 wl1271_debug(DEBUG_TX,
217 "tx_allocate: size: %d, blocks: %d, id: %d",
218 total_len, total_blocks, id);
219 } else {
220 wl1271_free_tx_id(wl, id);
221 }
222
223 return ret;
224}
225
226static bool wl12xx_is_dummy_packet(struct wl1271 *wl, struct sk_buff *skb)
227{
228 return wl->dummy_packet == skb;
229}
230
231static void wl1271_tx_fill_hdr(struct wl1271 *wl, struct sk_buff *skb,
232 u32 extra, struct ieee80211_tx_info *control,
233 u8 hlid)
234{
235 struct timespec ts;
236 struct wl1271_tx_hw_descr *desc;
237 int aligned_len, ac, rate_idx;
238 s64 hosttime;
239 u16 tx_attr;
240
241 desc = (struct wl1271_tx_hw_descr *) skb->data;
242
243 /* relocate space for security header */
244 if (extra) {
245 void *framestart = skb->data + sizeof(*desc);
246 u16 fc = *(u16 *)(framestart + extra);
247 int hdrlen = ieee80211_hdrlen(cpu_to_le16(fc));
248 memmove(framestart, framestart + extra, hdrlen);
249 }
250
251 /* configure packet life time */
252 getnstimeofday(&ts);
253 hosttime = (timespec_to_ns(&ts) >> 10);
254 desc->start_time = cpu_to_le32(hosttime - wl->time_offset);
255
256 if (wl->bss_type != BSS_TYPE_AP_BSS)
257 desc->life_time = cpu_to_le16(TX_HW_MGMT_PKT_LIFETIME_TU);
258 else
259 desc->life_time = cpu_to_le16(TX_HW_AP_MODE_PKT_LIFETIME_TU);
260
261 /* queue */
262 ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
263 desc->tid = skb->priority;
264
265 if (wl12xx_is_dummy_packet(wl, skb)) {
266 /*
267 * FW expects the dummy packet to have an invalid session id -
268 * any session id that is different than the one set in the join
269 */
270 tx_attr = ((~wl->session_counter) <<
271 TX_HW_ATTR_OFST_SESSION_COUNTER) &
272 TX_HW_ATTR_SESSION_COUNTER;
273
274 tx_attr |= TX_HW_ATTR_TX_DUMMY_REQ;
275 } else {
276 /* configure the tx attributes */
277 tx_attr =
278 wl->session_counter << TX_HW_ATTR_OFST_SESSION_COUNTER;
279 }
280
281 if (wl->bss_type != BSS_TYPE_AP_BSS) {
282 desc->aid = hlid;
283
284 /* if the packets are destined for AP (have a STA entry)
285 send them with AP rate policies, otherwise use default
286 basic rates */
287 if (control->control.sta)
288 rate_idx = ACX_TX_AP_FULL_RATE;
289 else
290 rate_idx = ACX_TX_BASIC_RATE;
291 } else {
292 desc->hlid = hlid;
293 switch (hlid) {
294 case WL1271_AP_GLOBAL_HLID:
295 rate_idx = ACX_TX_AP_MODE_MGMT_RATE;
296 break;
297 case WL1271_AP_BROADCAST_HLID:
298 rate_idx = ACX_TX_AP_MODE_BCST_RATE;
299 break;
300 default:
301 rate_idx = ac;
302 break;
303 }
304 }
305
306 tx_attr |= rate_idx << TX_HW_ATTR_OFST_RATE_POLICY;
307 desc->reserved = 0;
308
309 aligned_len = wl12xx_calc_packet_alignment(wl, skb->len);
310
311 if (wl->chip.id == CHIP_ID_1283_PG20) {
312 desc->wl128x_mem.extra_bytes = aligned_len - skb->len;
313 desc->length = cpu_to_le16(aligned_len >> 2);
314
315 wl1271_debug(DEBUG_TX, "tx_fill_hdr: hlid: %d "
316 "tx_attr: 0x%x len: %d life: %d mem: %d",
317 desc->hlid, tx_attr,
318 le16_to_cpu(desc->length),
319 le16_to_cpu(desc->life_time),
320 desc->wl128x_mem.total_mem_blocks);
321 } else {
322 int pad;
323
324 /* Store the aligned length in terms of words */
325 desc->length = cpu_to_le16(aligned_len >> 2);
326
327 /* calculate number of padding bytes */
328 pad = aligned_len - skb->len;
329 tx_attr |= pad << TX_HW_ATTR_OFST_LAST_WORD_PAD;
330
331 wl1271_debug(DEBUG_TX, "tx_fill_hdr: pad: %d hlid: %d "
332 "tx_attr: 0x%x len: %d life: %d mem: %d", pad,
333 desc->hlid, tx_attr,
334 le16_to_cpu(desc->length),
335 le16_to_cpu(desc->life_time),
336 desc->wl127x_mem.total_mem_blocks);
337 }
338
339 desc->tx_attr = cpu_to_le16(tx_attr);
340}
341
342/* caller must hold wl->mutex */
343static int wl1271_prepare_tx_frame(struct wl1271 *wl, struct sk_buff *skb,
344 u32 buf_offset)
345{
346 struct ieee80211_tx_info *info;
347 u32 extra = 0;
348 int ret = 0;
349 u32 total_len;
350 u8 hlid;
351
352 if (!skb)
353 return -EINVAL;
354
355 info = IEEE80211_SKB_CB(skb);
356
357 if (info->control.hw_key &&
358 info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP)
359 extra = WL1271_TKIP_IV_SPACE;
360
361 if (info->control.hw_key) {
362 bool is_wep;
363 u8 idx = info->control.hw_key->hw_key_idx;
364 u32 cipher = info->control.hw_key->cipher;
365
366 is_wep = (cipher == WLAN_CIPHER_SUITE_WEP40) ||
367 (cipher == WLAN_CIPHER_SUITE_WEP104);
368
369 if (unlikely(is_wep && wl->default_key != idx)) {
370 ret = wl1271_set_default_wep_key(wl, idx);
371 if (ret < 0)
372 return ret;
373 wl->default_key = idx;
374 }
375 }
376
377 if (wl->bss_type == BSS_TYPE_AP_BSS)
378 hlid = wl1271_tx_get_hlid(skb);
379 else
380 hlid = TX_HW_DEFAULT_AID;
381
382 ret = wl1271_tx_allocate(wl, skb, extra, buf_offset, hlid);
383 if (ret < 0)
384 return ret;
385
386 if (wl->bss_type == BSS_TYPE_AP_BSS) {
387 wl1271_tx_ap_update_inconnection_sta(wl, skb);
388 wl1271_tx_regulate_link(wl, hlid);
389 } else {
390 wl1271_tx_update_filters(wl, skb);
391 }
392
393 wl1271_tx_fill_hdr(wl, skb, extra, info, hlid);
394
395 /*
396 * The length of each packet is stored in terms of
397 * words. Thus, we must pad the skb data to make sure its
398 * length is aligned. The number of padding bytes is computed
399 * and set in wl1271_tx_fill_hdr.
400 * In special cases, we want to align to a specific block size
401 * (eg. for wl128x with SDIO we align to 256).
402 */
403 total_len = wl12xx_calc_packet_alignment(wl, skb->len);
404
405 memcpy(wl->aggr_buf + buf_offset, skb->data, skb->len);
406 memset(wl->aggr_buf + buf_offset + skb->len, 0, total_len - skb->len);
407
408 /* Revert side effects in the dummy packet skb, so it can be reused */
409 if (wl12xx_is_dummy_packet(wl, skb))
410 skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
411
412 return total_len;
413}
414
415u32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set)
416{
417 struct ieee80211_supported_band *band;
418 u32 enabled_rates = 0;
419 int bit;
420
421 band = wl->hw->wiphy->bands[wl->band];
422 for (bit = 0; bit < band->n_bitrates; bit++) {
423 if (rate_set & 0x1)
424 enabled_rates |= band->bitrates[bit].hw_value;
425 rate_set >>= 1;
426 }
427
428#ifdef CONFIG_WL12XX_HT
429 /* MCS rates indication are on bits 16 - 23 */
430 rate_set >>= HW_HT_RATES_OFFSET - band->n_bitrates;
431
432 for (bit = 0; bit < 8; bit++) {
433 if (rate_set & 0x1)
434 enabled_rates |= (CONF_HW_BIT_RATE_MCS_0 << bit);
435 rate_set >>= 1;
436 }
437#endif
438
439 return enabled_rates;
440}
441
442void wl1271_handle_tx_low_watermark(struct wl1271 *wl)
443{
444 unsigned long flags;
445
446 if (test_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags) &&
447 wl->tx_queue_count <= WL1271_TX_QUEUE_LOW_WATERMARK) {
448 /* firmware buffer has space, restart queues */
449 spin_lock_irqsave(&wl->wl_lock, flags);
450 ieee80211_wake_queues(wl->hw);
451 clear_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags);
452 spin_unlock_irqrestore(&wl->wl_lock, flags);
453 }
454}
455
456static struct sk_buff *wl1271_sta_skb_dequeue(struct wl1271 *wl)
457{
458 struct sk_buff *skb = NULL;
459 unsigned long flags;
460
461 skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_VO]);
462 if (skb)
463 goto out;
464 skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_VI]);
465 if (skb)
466 goto out;
467 skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_BE]);
468 if (skb)
469 goto out;
470 skb = skb_dequeue(&wl->tx_queue[CONF_TX_AC_BK]);
471
472out:
473 if (skb) {
474 spin_lock_irqsave(&wl->wl_lock, flags);
475 wl->tx_queue_count--;
476 spin_unlock_irqrestore(&wl->wl_lock, flags);
477 }
478
479 return skb;
480}
481
482static struct sk_buff *wl1271_ap_skb_dequeue(struct wl1271 *wl)
483{
484 struct sk_buff *skb = NULL;
485 unsigned long flags;
486 int i, h, start_hlid;
487
488 /* start from the link after the last one */
489 start_hlid = (wl->last_tx_hlid + 1) % AP_MAX_LINKS;
490
491 /* dequeue according to AC, round robin on each link */
492 for (i = 0; i < AP_MAX_LINKS; i++) {
493 h = (start_hlid + i) % AP_MAX_LINKS;
494
495 skb = skb_dequeue(&wl->links[h].tx_queue[CONF_TX_AC_VO]);
496 if (skb)
497 goto out;
498 skb = skb_dequeue(&wl->links[h].tx_queue[CONF_TX_AC_VI]);
499 if (skb)
500 goto out;
501 skb = skb_dequeue(&wl->links[h].tx_queue[CONF_TX_AC_BE]);
502 if (skb)
503 goto out;
504 skb = skb_dequeue(&wl->links[h].tx_queue[CONF_TX_AC_BK]);
505 if (skb)
506 goto out;
507 }
508
509out:
510 if (skb) {
511 wl->last_tx_hlid = h;
512 spin_lock_irqsave(&wl->wl_lock, flags);
513 wl->tx_queue_count--;
514 spin_unlock_irqrestore(&wl->wl_lock, flags);
515 } else {
516 wl->last_tx_hlid = 0;
517 }
518
519 return skb;
520}
521
522static struct sk_buff *wl1271_skb_dequeue(struct wl1271 *wl)
523{
524 unsigned long flags;
525 struct sk_buff *skb = NULL;
526
527 if (wl->bss_type == BSS_TYPE_AP_BSS)
528 skb = wl1271_ap_skb_dequeue(wl);
529 else
530 skb = wl1271_sta_skb_dequeue(wl);
531
532 if (!skb &&
533 test_and_clear_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags)) {
534 skb = wl->dummy_packet;
535 spin_lock_irqsave(&wl->wl_lock, flags);
536 wl->tx_queue_count--;
537 spin_unlock_irqrestore(&wl->wl_lock, flags);
538 }
539
540 return skb;
541}
542
543static void wl1271_skb_queue_head(struct wl1271 *wl, struct sk_buff *skb)
544{
545 unsigned long flags;
546 int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
547
548 if (wl12xx_is_dummy_packet(wl, skb)) {
549 set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags);
550 } else if (wl->bss_type == BSS_TYPE_AP_BSS) {
551 u8 hlid = wl1271_tx_get_hlid(skb);
552 skb_queue_head(&wl->links[hlid].tx_queue[q], skb);
553
554 /* make sure we dequeue the same packet next time */
555 wl->last_tx_hlid = (hlid + AP_MAX_LINKS - 1) % AP_MAX_LINKS;
556 } else {
557 skb_queue_head(&wl->tx_queue[q], skb);
558 }
559
560 spin_lock_irqsave(&wl->wl_lock, flags);
561 wl->tx_queue_count++;
562 spin_unlock_irqrestore(&wl->wl_lock, flags);
563}
564
565void wl1271_tx_work_locked(struct wl1271 *wl)
566{
567 struct sk_buff *skb;
568 u32 buf_offset = 0;
569 bool sent_packets = false;
570 int ret;
571
572 if (unlikely(wl->state == WL1271_STATE_OFF))
573 return;
574
575 while ((skb = wl1271_skb_dequeue(wl))) {
576 ret = wl1271_prepare_tx_frame(wl, skb, buf_offset);
577 if (ret == -EAGAIN) {
578 /*
579 * Aggregation buffer is full.
580 * Flush buffer and try again.
581 */
582 wl1271_skb_queue_head(wl, skb);
583 wl1271_write(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf,
584 buf_offset, true);
585 sent_packets = true;
586 buf_offset = 0;
587 continue;
588 } else if (ret == -EBUSY) {
589 /*
590 * Firmware buffer is full.
591 * Queue back last skb, and stop aggregating.
592 */
593 wl1271_skb_queue_head(wl, skb);
594 /* No work left, avoid scheduling redundant tx work */
595 set_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
596 goto out_ack;
597 } else if (ret < 0) {
598 dev_kfree_skb(skb);
599 goto out_ack;
600 }
601 buf_offset += ret;
602 wl->tx_packets_count++;
603 }
604
605out_ack:
606 if (buf_offset) {
607 wl1271_write(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf,
608 buf_offset, true);
609 sent_packets = true;
610 }
611 if (sent_packets) {
612 /*
613 * Interrupt the firmware with the new packets. This is only
614 * required for older hardware revisions
615 */
616 if (wl->quirks & WL12XX_QUIRK_END_OF_TRANSACTION)
617 wl1271_write32(wl, WL1271_HOST_WR_ACCESS,
618 wl->tx_packets_count);
619
620 wl1271_handle_tx_low_watermark(wl);
621 }
622}
623
624void wl1271_tx_work(struct work_struct *work)
625{
626 struct wl1271 *wl = container_of(work, struct wl1271, tx_work);
627 int ret;
628
629 mutex_lock(&wl->mutex);
630 ret = wl1271_ps_elp_wakeup(wl);
631 if (ret < 0)
632 goto out;
633
634 wl1271_tx_work_locked(wl);
635
636 wl1271_ps_elp_sleep(wl);
637out:
638 mutex_unlock(&wl->mutex);
639}
640
641static void wl1271_tx_complete_packet(struct wl1271 *wl,
642 struct wl1271_tx_hw_res_descr *result)
643{
644 struct ieee80211_tx_info *info;
645 struct sk_buff *skb;
646 int id = result->id;
647 int rate = -1;
648 u8 retries = 0;
649
650 /* check for id legality */
651 if (unlikely(id >= ACX_TX_DESCRIPTORS || wl->tx_frames[id] == NULL)) {
652 wl1271_warning("TX result illegal id: %d", id);
653 return;
654 }
655
656 skb = wl->tx_frames[id];
657 info = IEEE80211_SKB_CB(skb);
658
659 if (wl12xx_is_dummy_packet(wl, skb)) {
660 wl1271_free_tx_id(wl, id);
661 return;
662 }
663
664 /* update the TX status info */
665 if (result->status == TX_SUCCESS) {
666 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
667 info->flags |= IEEE80211_TX_STAT_ACK;
668 rate = wl1271_rate_to_idx(result->rate_class_index, wl->band);
669 retries = result->ack_failures;
670 } else if (result->status == TX_RETRY_EXCEEDED) {
671 wl->stats.excessive_retries++;
672 retries = result->ack_failures;
673 }
674
675 info->status.rates[0].idx = rate;
676 info->status.rates[0].count = retries;
677 info->status.rates[0].flags = 0;
678 info->status.ack_signal = -1;
679
680 wl->stats.retry_count += result->ack_failures;
681
682 /* update security sequence number */
683 wl->tx_security_seq += (result->lsb_security_sequence_number -
684 wl->tx_security_last_seq);
685 wl->tx_security_last_seq = result->lsb_security_sequence_number;
686
687 /* remove private header from packet */
688 skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
689
690 /* remove TKIP header space if present */
691 if (info->control.hw_key &&
692 info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) {
693 int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
694 memmove(skb->data + WL1271_TKIP_IV_SPACE, skb->data, hdrlen);
695 skb_pull(skb, WL1271_TKIP_IV_SPACE);
696 }
697
698 wl1271_debug(DEBUG_TX, "tx status id %u skb 0x%p failures %u rate 0x%x"
699 " status 0x%x",
700 result->id, skb, result->ack_failures,
701 result->rate_class_index, result->status);
702
703 /* return the packet to the stack */
704 skb_queue_tail(&wl->deferred_tx_queue, skb);
705 ieee80211_queue_work(wl->hw, &wl->netstack_work);
706 wl1271_free_tx_id(wl, result->id);
707}
708
709/* Called upon reception of a TX complete interrupt */
710void wl1271_tx_complete(struct wl1271 *wl)
711{
712 struct wl1271_acx_mem_map *memmap =
713 (struct wl1271_acx_mem_map *)wl->target_mem_map;
714 u32 count, fw_counter;
715 u32 i;
716
717 /* read the tx results from the chipset */
718 wl1271_read(wl, le32_to_cpu(memmap->tx_result),
719 wl->tx_res_if, sizeof(*wl->tx_res_if), false);
720 fw_counter = le32_to_cpu(wl->tx_res_if->tx_result_fw_counter);
721
722 /* write host counter to chipset (to ack) */
723 wl1271_write32(wl, le32_to_cpu(memmap->tx_result) +
724 offsetof(struct wl1271_tx_hw_res_if,
725 tx_result_host_counter), fw_counter);
726
727 count = fw_counter - wl->tx_results_count;
728 wl1271_debug(DEBUG_TX, "tx_complete received, packets: %d", count);
729
730 /* verify that the result buffer is not getting overrun */
731 if (unlikely(count > TX_HW_RESULT_QUEUE_LEN))
732 wl1271_warning("TX result overflow from chipset: %d", count);
733
734 /* process the results */
735 for (i = 0; i < count; i++) {
736 struct wl1271_tx_hw_res_descr *result;
737 u8 offset = wl->tx_results_count & TX_HW_RESULT_QUEUE_LEN_MASK;
738
739 /* process the packet */
740 result = &(wl->tx_res_if->tx_results_queue[offset]);
741 wl1271_tx_complete_packet(wl, result);
742
743 wl->tx_results_count++;
744 }
745}
746
747void wl1271_tx_reset_link_queues(struct wl1271 *wl, u8 hlid)
748{
749 struct sk_buff *skb;
750 int i, total = 0;
751 unsigned long flags;
752 struct ieee80211_tx_info *info;
753
754 for (i = 0; i < NUM_TX_QUEUES; i++) {
755 while ((skb = skb_dequeue(&wl->links[hlid].tx_queue[i]))) {
756 wl1271_debug(DEBUG_TX, "link freeing skb 0x%p", skb);
757 info = IEEE80211_SKB_CB(skb);
758 info->status.rates[0].idx = -1;
759 info->status.rates[0].count = 0;
760 ieee80211_tx_status(wl->hw, skb);
761 total++;
762 }
763 }
764
765 spin_lock_irqsave(&wl->wl_lock, flags);
766 wl->tx_queue_count -= total;
767 spin_unlock_irqrestore(&wl->wl_lock, flags);
768
769 wl1271_handle_tx_low_watermark(wl);
770}
771
772/* caller must hold wl->mutex and TX must be stopped */
773void wl1271_tx_reset(struct wl1271 *wl, bool reset_tx_queues)
774{
775 int i;
776 struct sk_buff *skb;
777 struct ieee80211_tx_info *info;
778
779 /* TX failure */
780 if (wl->bss_type == BSS_TYPE_AP_BSS) {
781 for (i = 0; i < AP_MAX_LINKS; i++) {
782 wl1271_tx_reset_link_queues(wl, i);
783 wl->links[i].allocated_blks = 0;
784 wl->links[i].prev_freed_blks = 0;
785 }
786
787 wl->last_tx_hlid = 0;
788 } else {
789 for (i = 0; i < NUM_TX_QUEUES; i++) {
790 while ((skb = skb_dequeue(&wl->tx_queue[i]))) {
791 wl1271_debug(DEBUG_TX, "freeing skb 0x%p",
792 skb);
793
794 if (!wl12xx_is_dummy_packet(wl, skb)) {
795 info = IEEE80211_SKB_CB(skb);
796 info->status.rates[0].idx = -1;
797 info->status.rates[0].count = 0;
798 ieee80211_tx_status(wl->hw, skb);
799 }
800 }
801 }
802 }
803
804 wl->tx_queue_count = 0;
805
806 /*
807 * Make sure the driver is at a consistent state, in case this
808 * function is called from a context other than interface removal.
809 * This call will always wake the TX queues.
810 */
811 if (reset_tx_queues)
812 wl1271_handle_tx_low_watermark(wl);
813
814 for (i = 0; i < ACX_TX_DESCRIPTORS; i++) {
815 if (wl->tx_frames[i] == NULL)
816 continue;
817
818 skb = wl->tx_frames[i];
819 wl1271_free_tx_id(wl, i);
820 wl1271_debug(DEBUG_TX, "freeing skb 0x%p", skb);
821
822 if (!wl12xx_is_dummy_packet(wl, skb)) {
823 /*
824 * Remove private headers before passing the skb to
825 * mac80211
826 */
827 info = IEEE80211_SKB_CB(skb);
828 skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
829 if (info->control.hw_key &&
830 info->control.hw_key->cipher ==
831 WLAN_CIPHER_SUITE_TKIP) {
832 int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
833 memmove(skb->data + WL1271_TKIP_IV_SPACE,
834 skb->data, hdrlen);
835 skb_pull(skb, WL1271_TKIP_IV_SPACE);
836 }
837
838 info->status.rates[0].idx = -1;
839 info->status.rates[0].count = 0;
840
841 ieee80211_tx_status(wl->hw, skb);
842 }
843 }
844}
845
846#define WL1271_TX_FLUSH_TIMEOUT 500000
847
848/* caller must *NOT* hold wl->mutex */
849void wl1271_tx_flush(struct wl1271 *wl)
850{
851 unsigned long timeout;
852 timeout = jiffies + usecs_to_jiffies(WL1271_TX_FLUSH_TIMEOUT);
853
854 while (!time_after(jiffies, timeout)) {
855 mutex_lock(&wl->mutex);
856 wl1271_debug(DEBUG_TX, "flushing tx buffer: %d %d",
857 wl->tx_frames_cnt, wl->tx_queue_count);
858 if ((wl->tx_frames_cnt == 0) && (wl->tx_queue_count == 0)) {
859 mutex_unlock(&wl->mutex);
860 return;
861 }
862 mutex_unlock(&wl->mutex);
863 msleep(1);
864 }
865
866 wl1271_warning("Unable to flush all TX buffers, timed out.");
867}
868
869u32 wl1271_tx_min_rate_get(struct wl1271 *wl)
870{
871 int i;
872 u32 rate = 0;
873
874 if (!wl->basic_rate_set) {
875 WARN_ON(1);
876 wl->basic_rate_set = wl->conf.tx.basic_rate;
877 }
878
879 for (i = 0; !rate; i++) {
880 if ((wl->basic_rate_set >> i) & 0x1)
881 rate = 1 << i;
882 }
883
884 return rate;
885}
diff --git a/drivers/net/wireless/wl12xx/wl1271_tx.h b/drivers/net/wireless/wl12xx/tx.h
index 48bf92621c03..832f9258d675 100644
--- a/drivers/net/wireless/wl12xx/wl1271_tx.h
+++ b/drivers/net/wireless/wl12xx/tx.h
@@ -22,13 +22,13 @@
22 * 22 *
23 */ 23 */
24 24
25#ifndef __WL1271_TX_H__ 25#ifndef __TX_H__
26#define __WL1271_TX_H__ 26#define __TX_H__
27 27
28#define TX_HW_BLOCK_SPARE 2
29#define TX_HW_BLOCK_SIZE 252 28#define TX_HW_BLOCK_SIZE 252
30 29
31#define TX_HW_MGMT_PKT_LIFETIME_TU 2000 30#define TX_HW_MGMT_PKT_LIFETIME_TU 2000
31#define TX_HW_AP_MODE_PKT_LIFETIME_TU 8000
32/* The chipset reference driver states, that the "aid" value 1 32/* The chipset reference driver states, that the "aid" value 1
33 * is for infra-BSS, but is still always used */ 33 * is for infra-BSS, but is still always used */
34#define TX_HW_DEFAULT_AID 1 34#define TX_HW_DEFAULT_AID 1
@@ -40,6 +40,7 @@
40 BIT(8) | BIT(9)) 40 BIT(8) | BIT(9))
41#define TX_HW_ATTR_LAST_WORD_PAD (BIT(10) | BIT(11)) 41#define TX_HW_ATTR_LAST_WORD_PAD (BIT(10) | BIT(11))
42#define TX_HW_ATTR_TX_CMPLT_REQ BIT(12) 42#define TX_HW_ATTR_TX_CMPLT_REQ BIT(12)
43#define TX_HW_ATTR_TX_DUMMY_REQ BIT(13)
43 44
44#define TX_HW_ATTR_OFST_SAVE_RETRIES 0 45#define TX_HW_ATTR_OFST_SAVE_RETRIES 0
45#define TX_HW_ATTR_OFST_HEADER_PAD 1 46#define TX_HW_ATTR_OFST_HEADER_PAD 1
@@ -52,24 +53,62 @@
52#define TX_HW_RESULT_QUEUE_LEN_MASK 0xf 53#define TX_HW_RESULT_QUEUE_LEN_MASK 0xf
53 54
54#define WL1271_TX_ALIGN_TO 4 55#define WL1271_TX_ALIGN_TO 4
55#define WL1271_TX_ALIGN(len) (((len) + WL1271_TX_ALIGN_TO - 1) & \
56 ~(WL1271_TX_ALIGN_TO - 1))
57#define WL1271_TKIP_IV_SPACE 4 56#define WL1271_TKIP_IV_SPACE 4
58 57
58/* Used for management frames and dummy packets */
59#define WL1271_TID_MGMT 7
60
61struct wl127x_tx_mem {
62 /*
63 * Number of extra memory blocks to allocate for this packet
64 * in addition to the number of blocks derived from the packet
65 * length.
66 */
67 u8 extra_blocks;
68 /*
69 * Total number of memory blocks allocated by the host for
70 * this packet. Must be equal or greater than the actual
71 * blocks number allocated by HW.
72 */
73 u8 total_mem_blocks;
74} __packed;
75
76struct wl128x_tx_mem {
77 /*
78 * Total number of memory blocks allocated by the host for
79 * this packet.
80 */
81 u8 total_mem_blocks;
82 /*
83 * Number of extra bytes, at the end of the frame. the host
84 * uses this padding to complete each frame to integer number
85 * of SDIO blocks.
86 */
87 u8 extra_bytes;
88} __packed;
89
90/*
91 * On wl128x based devices, when TX packets are aggregated, each packet
92 * size must be aligned to the SDIO block size. The maximum block size
93 * is bounded by the type of the padded bytes field that is sent to the
94 * FW. Currently the type is u8, so the maximum block size is 256 bytes.
95 */
96#define WL12XX_BUS_BLOCK_SIZE min(512u, \
97 (1u << (8 * sizeof(((struct wl128x_tx_mem *) 0)->extra_bytes))))
98
59struct wl1271_tx_hw_descr { 99struct wl1271_tx_hw_descr {
60 /* Length of packet in words, including descriptor+header+data */ 100 /* Length of packet in words, including descriptor+header+data */
61 __le16 length; 101 __le16 length;
62 /* Number of extra memory blocks to allocate for this packet in 102 union {
63 addition to the number of blocks derived from the packet length */ 103 struct wl127x_tx_mem wl127x_mem;
64 u8 extra_mem_blocks; 104 struct wl128x_tx_mem wl128x_mem;
65 /* Total number of memory blocks allocated by the host for this packet. 105 } __packed;
66 Must be equal or greater than the actual blocks number allocated by
67 HW!! */
68 u8 total_mem_blocks;
69 /* Device time (in us) when the packet arrived to the driver */ 106 /* Device time (in us) when the packet arrived to the driver */
70 __le32 start_time; 107 __le32 start_time;
71 /* Max delay in TUs until transmission. The last device time the 108 /*
72 packet can be transmitted is: startTime+(1024*LifeTime) */ 109 * Max delay in TUs until transmission. The last device time the
110 * packet can be transmitted is: start_time + (1024 * life_time)
111 */
73 __le16 life_time; 112 __le16 life_time;
74 /* Bitwise fields - see TX_ATTR... definitions above. */ 113 /* Bitwise fields - see TX_ATTR... definitions above. */
75 __le16 tx_attr; 114 __le16 tx_attr;
@@ -77,8 +116,12 @@ struct wl1271_tx_hw_descr {
77 u8 id; 116 u8 id;
78 /* The packet TID value (as User-Priority) */ 117 /* The packet TID value (as User-Priority) */
79 u8 tid; 118 u8 tid;
80 /* Identifier of the remote STA in IBSS, 1 in infra-BSS */ 119 union {
81 u8 aid; 120 /* STA - Identifier of the remote STA in IBSS, 1 in infra-BSS */
121 u8 aid;
122 /* AP - host link ID (HLID) */
123 u8 hlid;
124 } __packed;
82 u8 reserved; 125 u8 reserved;
83} __packed; 126} __packed;
84 127
@@ -139,28 +182,16 @@ static inline int wl1271_tx_get_queue(int queue)
139 } 182 }
140} 183}
141 184
142/* wl1271 tx descriptor needs the tid and we need to convert it from ac */
143static inline int wl1271_tx_ac_to_tid(int ac)
144{
145 switch (ac) {
146 case 0:
147 return 0;
148 case 1:
149 return 2;
150 case 2:
151 return 4;
152 case 3:
153 return 6;
154 default:
155 return 0;
156 }
157}
158
159void wl1271_tx_work(struct work_struct *work); 185void wl1271_tx_work(struct work_struct *work);
186void wl1271_tx_work_locked(struct wl1271 *wl);
160void wl1271_tx_complete(struct wl1271 *wl); 187void wl1271_tx_complete(struct wl1271 *wl);
161void wl1271_tx_reset(struct wl1271 *wl); 188void wl1271_tx_reset(struct wl1271 *wl, bool reset_tx_queues);
162void wl1271_tx_flush(struct wl1271 *wl); 189void wl1271_tx_flush(struct wl1271 *wl);
163u8 wl1271_rate_to_idx(struct wl1271 *wl, int rate); 190u8 wl1271_rate_to_idx(int rate, enum ieee80211_band band);
164u32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set); 191u32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set);
192u32 wl1271_tx_min_rate_get(struct wl1271 *wl);
193u8 wl1271_tx_get_hlid(struct sk_buff *skb);
194void wl1271_tx_reset_link_queues(struct wl1271 *wl, u8 hlid);
195void wl1271_handle_tx_low_watermark(struct wl1271 *wl);
165 196
166#endif 197#endif
diff --git a/drivers/net/wireless/wl12xx/wl1251.h b/drivers/net/wireless/wl12xx/wl1251.h
deleted file mode 100644
index 6b942a28e6a5..000000000000
--- a/drivers/net/wireless/wl12xx/wl1251.h
+++ /dev/null
@@ -1,432 +0,0 @@
1/*
2 * This file is part of wl1251
3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008-2009 Nokia Corporation
6 *
7 * Contact: Kalle Valo <kalle.valo@nokia.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25#ifndef __WL1251_H__
26#define __WL1251_H__
27
28#include <linux/mutex.h>
29#include <linux/list.h>
30#include <linux/bitops.h>
31#include <net/mac80211.h>
32
33#define DRIVER_NAME "wl1251"
34#define DRIVER_PREFIX DRIVER_NAME ": "
35
36enum {
37 DEBUG_NONE = 0,
38 DEBUG_IRQ = BIT(0),
39 DEBUG_SPI = BIT(1),
40 DEBUG_BOOT = BIT(2),
41 DEBUG_MAILBOX = BIT(3),
42 DEBUG_NETLINK = BIT(4),
43 DEBUG_EVENT = BIT(5),
44 DEBUG_TX = BIT(6),
45 DEBUG_RX = BIT(7),
46 DEBUG_SCAN = BIT(8),
47 DEBUG_CRYPT = BIT(9),
48 DEBUG_PSM = BIT(10),
49 DEBUG_MAC80211 = BIT(11),
50 DEBUG_CMD = BIT(12),
51 DEBUG_ACX = BIT(13),
52 DEBUG_ALL = ~0,
53};
54
55#define DEBUG_LEVEL (DEBUG_NONE)
56
57#define DEBUG_DUMP_LIMIT 1024
58
59#define wl1251_error(fmt, arg...) \
60 printk(KERN_ERR DRIVER_PREFIX "ERROR " fmt "\n", ##arg)
61
62#define wl1251_warning(fmt, arg...) \
63 printk(KERN_WARNING DRIVER_PREFIX "WARNING " fmt "\n", ##arg)
64
65#define wl1251_notice(fmt, arg...) \
66 printk(KERN_INFO DRIVER_PREFIX fmt "\n", ##arg)
67
68#define wl1251_info(fmt, arg...) \
69 printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg)
70
71#define wl1251_debug(level, fmt, arg...) \
72 do { \
73 if (level & DEBUG_LEVEL) \
74 printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg); \
75 } while (0)
76
77#define wl1251_dump(level, prefix, buf, len) \
78 do { \
79 if (level & DEBUG_LEVEL) \
80 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
81 DUMP_PREFIX_OFFSET, 16, 1, \
82 buf, \
83 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
84 0); \
85 } while (0)
86
87#define wl1251_dump_ascii(level, prefix, buf, len) \
88 do { \
89 if (level & DEBUG_LEVEL) \
90 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
91 DUMP_PREFIX_OFFSET, 16, 1, \
92 buf, \
93 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
94 true); \
95 } while (0)
96
97#define WL1251_DEFAULT_RX_CONFIG (CFG_UNI_FILTER_EN | \
98 CFG_BSSID_FILTER_EN)
99
100#define WL1251_DEFAULT_RX_FILTER (CFG_RX_PRSP_EN | \
101 CFG_RX_MGMT_EN | \
102 CFG_RX_DATA_EN | \
103 CFG_RX_CTL_EN | \
104 CFG_RX_BCN_EN | \
105 CFG_RX_AUTH_EN | \
106 CFG_RX_ASSOC_EN)
107
108#define WL1251_BUSY_WORD_LEN 8
109
110struct boot_attr {
111 u32 radio_type;
112 u8 mac_clock;
113 u8 arm_clock;
114 int firmware_debug;
115 u32 minor;
116 u32 major;
117 u32 bugfix;
118};
119
120enum wl1251_state {
121 WL1251_STATE_OFF,
122 WL1251_STATE_ON,
123 WL1251_STATE_PLT,
124};
125
126enum wl1251_partition_type {
127 PART_DOWN,
128 PART_WORK,
129 PART_DRPW,
130
131 PART_TABLE_LEN
132};
133
134struct wl1251_partition {
135 u32 size;
136 u32 start;
137};
138
139struct wl1251_partition_set {
140 struct wl1251_partition mem;
141 struct wl1251_partition reg;
142};
143
144struct wl1251;
145
146struct wl1251_stats {
147 struct acx_statistics *fw_stats;
148 unsigned long fw_stats_update;
149
150 unsigned int retry_count;
151 unsigned int excessive_retries;
152};
153
154struct wl1251_debugfs {
155 struct dentry *rootdir;
156 struct dentry *fw_statistics;
157
158 struct dentry *tx_internal_desc_overflow;
159
160 struct dentry *rx_out_of_mem;
161 struct dentry *rx_hdr_overflow;
162 struct dentry *rx_hw_stuck;
163 struct dentry *rx_dropped;
164 struct dentry *rx_fcs_err;
165 struct dentry *rx_xfr_hint_trig;
166 struct dentry *rx_path_reset;
167 struct dentry *rx_reset_counter;
168
169 struct dentry *dma_rx_requested;
170 struct dentry *dma_rx_errors;
171 struct dentry *dma_tx_requested;
172 struct dentry *dma_tx_errors;
173
174 struct dentry *isr_cmd_cmplt;
175 struct dentry *isr_fiqs;
176 struct dentry *isr_rx_headers;
177 struct dentry *isr_rx_mem_overflow;
178 struct dentry *isr_rx_rdys;
179 struct dentry *isr_irqs;
180 struct dentry *isr_tx_procs;
181 struct dentry *isr_decrypt_done;
182 struct dentry *isr_dma0_done;
183 struct dentry *isr_dma1_done;
184 struct dentry *isr_tx_exch_complete;
185 struct dentry *isr_commands;
186 struct dentry *isr_rx_procs;
187 struct dentry *isr_hw_pm_mode_changes;
188 struct dentry *isr_host_acknowledges;
189 struct dentry *isr_pci_pm;
190 struct dentry *isr_wakeups;
191 struct dentry *isr_low_rssi;
192
193 struct dentry *wep_addr_key_count;
194 struct dentry *wep_default_key_count;
195 /* skipping wep.reserved */
196 struct dentry *wep_key_not_found;
197 struct dentry *wep_decrypt_fail;
198 struct dentry *wep_packets;
199 struct dentry *wep_interrupt;
200
201 struct dentry *pwr_ps_enter;
202 struct dentry *pwr_elp_enter;
203 struct dentry *pwr_missing_bcns;
204 struct dentry *pwr_wake_on_host;
205 struct dentry *pwr_wake_on_timer_exp;
206 struct dentry *pwr_tx_with_ps;
207 struct dentry *pwr_tx_without_ps;
208 struct dentry *pwr_rcvd_beacons;
209 struct dentry *pwr_power_save_off;
210 struct dentry *pwr_enable_ps;
211 struct dentry *pwr_disable_ps;
212 struct dentry *pwr_fix_tsf_ps;
213 /* skipping cont_miss_bcns_spread for now */
214 struct dentry *pwr_rcvd_awake_beacons;
215
216 struct dentry *mic_rx_pkts;
217 struct dentry *mic_calc_failure;
218
219 struct dentry *aes_encrypt_fail;
220 struct dentry *aes_decrypt_fail;
221 struct dentry *aes_encrypt_packets;
222 struct dentry *aes_decrypt_packets;
223 struct dentry *aes_encrypt_interrupt;
224 struct dentry *aes_decrypt_interrupt;
225
226 struct dentry *event_heart_beat;
227 struct dentry *event_calibration;
228 struct dentry *event_rx_mismatch;
229 struct dentry *event_rx_mem_empty;
230 struct dentry *event_rx_pool;
231 struct dentry *event_oom_late;
232 struct dentry *event_phy_transmit_error;
233 struct dentry *event_tx_stuck;
234
235 struct dentry *ps_pspoll_timeouts;
236 struct dentry *ps_upsd_timeouts;
237 struct dentry *ps_upsd_max_sptime;
238 struct dentry *ps_upsd_max_apturn;
239 struct dentry *ps_pspoll_max_apturn;
240 struct dentry *ps_pspoll_utilization;
241 struct dentry *ps_upsd_utilization;
242
243 struct dentry *rxpipe_rx_prep_beacon_drop;
244 struct dentry *rxpipe_descr_host_int_trig_rx_data;
245 struct dentry *rxpipe_beacon_buffer_thres_host_int_trig_rx_data;
246 struct dentry *rxpipe_missed_beacon_host_int_trig_rx_data;
247 struct dentry *rxpipe_tx_xfr_host_int_trig_rx_data;
248
249 struct dentry *tx_queue_len;
250 struct dentry *tx_queue_status;
251
252 struct dentry *retry_count;
253 struct dentry *excessive_retries;
254};
255
256struct wl1251_if_operations {
257 void (*read)(struct wl1251 *wl, int addr, void *buf, size_t len);
258 void (*write)(struct wl1251 *wl, int addr, void *buf, size_t len);
259 void (*read_elp)(struct wl1251 *wl, int addr, u32 *val);
260 void (*write_elp)(struct wl1251 *wl, int addr, u32 val);
261 void (*reset)(struct wl1251 *wl);
262 void (*enable_irq)(struct wl1251 *wl);
263 void (*disable_irq)(struct wl1251 *wl);
264};
265
266struct wl1251 {
267 struct ieee80211_hw *hw;
268 bool mac80211_registered;
269
270 void *if_priv;
271 const struct wl1251_if_operations *if_ops;
272
273 void (*set_power)(bool enable);
274 int irq;
275 bool use_eeprom;
276
277 enum wl1251_state state;
278 struct mutex mutex;
279
280 int physical_mem_addr;
281 int physical_reg_addr;
282 int virtual_mem_addr;
283 int virtual_reg_addr;
284
285 int cmd_box_addr;
286 int event_box_addr;
287 struct boot_attr boot_attr;
288
289 u8 *fw;
290 size_t fw_len;
291 u8 *nvs;
292 size_t nvs_len;
293
294 u8 bssid[ETH_ALEN];
295 u8 mac_addr[ETH_ALEN];
296 u8 bss_type;
297 u8 listen_int;
298 int channel;
299
300 void *target_mem_map;
301 struct acx_data_path_params_resp *data_path;
302
303 /* Number of TX packets transferred to the FW, modulo 16 */
304 u32 data_in_count;
305
306 /* Frames scheduled for transmission, not handled yet */
307 struct sk_buff_head tx_queue;
308 bool tx_queue_stopped;
309
310 struct work_struct tx_work;
311 struct work_struct filter_work;
312
313 /* Pending TX frames */
314 struct sk_buff *tx_frames[16];
315
316 /*
317 * Index pointing to the next TX complete entry
318 * in the cyclic XT complete array we get from
319 * the FW.
320 */
321 u32 next_tx_complete;
322
323 /* FW Rx counter */
324 u32 rx_counter;
325
326 /* Rx frames handled */
327 u32 rx_handled;
328
329 /* Current double buffer */
330 u32 rx_current_buffer;
331 u32 rx_last_id;
332
333 /* The target interrupt mask */
334 u32 intr_mask;
335 struct work_struct irq_work;
336
337 /* The mbox event mask */
338 u32 event_mask;
339
340 /* Mailbox pointers */
341 u32 mbox_ptr[2];
342
343 /* Are we currently scanning */
344 bool scanning;
345
346 /* Default key (for WEP) */
347 u32 default_key;
348
349 unsigned int tx_mgmt_frm_rate;
350 unsigned int tx_mgmt_frm_mod;
351
352 unsigned int rx_config;
353 unsigned int rx_filter;
354
355 /* is firmware in elp mode */
356 bool elp;
357
358 struct delayed_work elp_work;
359
360 /* we can be in psm, but not in elp, we have to differentiate */
361 bool psm;
362
363 /* PSM mode requested */
364 bool psm_requested;
365
366 u16 beacon_int;
367 u8 dtim_period;
368
369 /* in dBm */
370 int power_level;
371
372 struct wl1251_stats stats;
373 struct wl1251_debugfs debugfs;
374
375 u32 buffer_32;
376 u32 buffer_cmd;
377 u8 buffer_busyword[WL1251_BUSY_WORD_LEN];
378 struct wl1251_rx_descriptor *rx_descriptor;
379
380 struct ieee80211_vif *vif;
381
382 u32 chip_id;
383 char fw_ver[21];
384
385 /* Most recently reported noise in dBm */
386 s8 noise;
387};
388
389int wl1251_plt_start(struct wl1251 *wl);
390int wl1251_plt_stop(struct wl1251 *wl);
391
392struct ieee80211_hw *wl1251_alloc_hw(void);
393int wl1251_free_hw(struct wl1251 *wl);
394int wl1251_init_ieee80211(struct wl1251 *wl);
395void wl1251_enable_interrupts(struct wl1251 *wl);
396void wl1251_disable_interrupts(struct wl1251 *wl);
397
398#define DEFAULT_HW_GEN_MODULATION_TYPE CCK_LONG /* Long Preamble */
399#define DEFAULT_HW_GEN_TX_RATE RATE_2MBPS
400#define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
401
402#define WL1251_DEFAULT_POWER_LEVEL 20
403
404#define WL1251_TX_QUEUE_MAX_LENGTH 20
405
406#define WL1251_DEFAULT_BEACON_INT 100
407#define WL1251_DEFAULT_DTIM_PERIOD 1
408
409#define WL1251_DEFAULT_CHANNEL 0
410
411#define CHIP_ID_1251_PG10 (0x7010101)
412#define CHIP_ID_1251_PG11 (0x7020101)
413#define CHIP_ID_1251_PG12 (0x7030101)
414#define CHIP_ID_1271_PG10 (0x4030101)
415#define CHIP_ID_1271_PG20 (0x4030111)
416
417#define WL1251_FW_NAME "wl1251-fw.bin"
418#define WL1251_NVS_NAME "wl1251-nvs.bin"
419
420#define WL1251_POWER_ON_SLEEP 10 /* in miliseconds */
421
422#define WL1251_PART_DOWN_MEM_START 0x0
423#define WL1251_PART_DOWN_MEM_SIZE 0x16800
424#define WL1251_PART_DOWN_REG_START REGISTERS_BASE
425#define WL1251_PART_DOWN_REG_SIZE REGISTERS_DOWN_SIZE
426
427#define WL1251_PART_WORK_MEM_START 0x28000
428#define WL1251_PART_WORK_MEM_SIZE 0x14000
429#define WL1251_PART_WORK_REG_START REGISTERS_BASE
430#define WL1251_PART_WORK_REG_SIZE REGISTERS_WORK_SIZE
431
432#endif
diff --git a/drivers/net/wireless/wl12xx/wl1251_acx.c b/drivers/net/wireless/wl12xx/wl1251_acx.c
deleted file mode 100644
index 91891f928070..000000000000
--- a/drivers/net/wireless/wl12xx/wl1251_acx.c
+++ /dev/null
@@ -1,1048 +0,0 @@
1#include "wl1251_acx.h"
2
3#include <linux/module.h>
4#include <linux/slab.h>
5#include <linux/crc7.h>
6
7#include "wl1251.h"
8#include "wl1251_reg.h"
9#include "wl1251_cmd.h"
10#include "wl1251_ps.h"
11
12int wl1251_acx_frame_rates(struct wl1251 *wl, u8 ctrl_rate, u8 ctrl_mod,
13 u8 mgt_rate, u8 mgt_mod)
14{
15 struct acx_fw_gen_frame_rates *rates;
16 int ret;
17
18 wl1251_debug(DEBUG_ACX, "acx frame rates");
19
20 rates = kzalloc(sizeof(*rates), GFP_KERNEL);
21 if (!rates) {
22 ret = -ENOMEM;
23 goto out;
24 }
25
26 rates->tx_ctrl_frame_rate = ctrl_rate;
27 rates->tx_ctrl_frame_mod = ctrl_mod;
28 rates->tx_mgt_frame_rate = mgt_rate;
29 rates->tx_mgt_frame_mod = mgt_mod;
30
31 ret = wl1251_cmd_configure(wl, ACX_FW_GEN_FRAME_RATES,
32 rates, sizeof(*rates));
33 if (ret < 0) {
34 wl1251_error("Failed to set FW rates and modulation");
35 goto out;
36 }
37
38out:
39 kfree(rates);
40 return ret;
41}
42
43
44int wl1251_acx_station_id(struct wl1251 *wl)
45{
46 struct acx_dot11_station_id *mac;
47 int ret, i;
48
49 wl1251_debug(DEBUG_ACX, "acx dot11_station_id");
50
51 mac = kzalloc(sizeof(*mac), GFP_KERNEL);
52 if (!mac) {
53 ret = -ENOMEM;
54 goto out;
55 }
56
57 for (i = 0; i < ETH_ALEN; i++)
58 mac->mac[i] = wl->mac_addr[ETH_ALEN - 1 - i];
59
60 ret = wl1251_cmd_configure(wl, DOT11_STATION_ID, mac, sizeof(*mac));
61 if (ret < 0)
62 goto out;
63
64out:
65 kfree(mac);
66 return ret;
67}
68
69int wl1251_acx_default_key(struct wl1251 *wl, u8 key_id)
70{
71 struct acx_dot11_default_key *default_key;
72 int ret;
73
74 wl1251_debug(DEBUG_ACX, "acx dot11_default_key (%d)", key_id);
75
76 default_key = kzalloc(sizeof(*default_key), GFP_KERNEL);
77 if (!default_key) {
78 ret = -ENOMEM;
79 goto out;
80 }
81
82 default_key->id = key_id;
83
84 ret = wl1251_cmd_configure(wl, DOT11_DEFAULT_KEY,
85 default_key, sizeof(*default_key));
86 if (ret < 0) {
87 wl1251_error("Couldn't set default key");
88 goto out;
89 }
90
91 wl->default_key = key_id;
92
93out:
94 kfree(default_key);
95 return ret;
96}
97
98int wl1251_acx_wake_up_conditions(struct wl1251 *wl, u8 wake_up_event,
99 u8 listen_interval)
100{
101 struct acx_wake_up_condition *wake_up;
102 int ret;
103
104 wl1251_debug(DEBUG_ACX, "acx wake up conditions");
105
106 wake_up = kzalloc(sizeof(*wake_up), GFP_KERNEL);
107 if (!wake_up) {
108 ret = -ENOMEM;
109 goto out;
110 }
111
112 wake_up->wake_up_event = wake_up_event;
113 wake_up->listen_interval = listen_interval;
114
115 ret = wl1251_cmd_configure(wl, ACX_WAKE_UP_CONDITIONS,
116 wake_up, sizeof(*wake_up));
117 if (ret < 0) {
118 wl1251_warning("could not set wake up conditions: %d", ret);
119 goto out;
120 }
121
122out:
123 kfree(wake_up);
124 return ret;
125}
126
127int wl1251_acx_sleep_auth(struct wl1251 *wl, u8 sleep_auth)
128{
129 struct acx_sleep_auth *auth;
130 int ret;
131
132 wl1251_debug(DEBUG_ACX, "acx sleep auth");
133
134 auth = kzalloc(sizeof(*auth), GFP_KERNEL);
135 if (!auth) {
136 ret = -ENOMEM;
137 goto out;
138 }
139
140 auth->sleep_auth = sleep_auth;
141
142 ret = wl1251_cmd_configure(wl, ACX_SLEEP_AUTH, auth, sizeof(*auth));
143 if (ret < 0)
144 return ret;
145
146out:
147 kfree(auth);
148 return ret;
149}
150
151int wl1251_acx_fw_version(struct wl1251 *wl, char *buf, size_t len)
152{
153 struct acx_revision *rev;
154 int ret;
155
156 wl1251_debug(DEBUG_ACX, "acx fw rev");
157
158 rev = kzalloc(sizeof(*rev), GFP_KERNEL);
159 if (!rev) {
160 ret = -ENOMEM;
161 goto out;
162 }
163
164 ret = wl1251_cmd_interrogate(wl, ACX_FW_REV, rev, sizeof(*rev));
165 if (ret < 0) {
166 wl1251_warning("ACX_FW_REV interrogate failed");
167 goto out;
168 }
169
170 /* be careful with the buffer sizes */
171 strncpy(buf, rev->fw_version, min(len, sizeof(rev->fw_version)));
172
173 /*
174 * if the firmware version string is exactly
175 * sizeof(rev->fw_version) long or fw_len is less than
176 * sizeof(rev->fw_version) it won't be null terminated
177 */
178 buf[min(len, sizeof(rev->fw_version)) - 1] = '\0';
179
180out:
181 kfree(rev);
182 return ret;
183}
184
185int wl1251_acx_tx_power(struct wl1251 *wl, int power)
186{
187 struct acx_current_tx_power *acx;
188 int ret;
189
190 wl1251_debug(DEBUG_ACX, "acx dot11_cur_tx_pwr");
191
192 if (power < 0 || power > 25)
193 return -EINVAL;
194
195 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
196 if (!acx) {
197 ret = -ENOMEM;
198 goto out;
199 }
200
201 acx->current_tx_power = power * 10;
202
203 ret = wl1251_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx));
204 if (ret < 0) {
205 wl1251_warning("configure of tx power failed: %d", ret);
206 goto out;
207 }
208
209out:
210 kfree(acx);
211 return ret;
212}
213
214int wl1251_acx_feature_cfg(struct wl1251 *wl)
215{
216 struct acx_feature_config *feature;
217 int ret;
218
219 wl1251_debug(DEBUG_ACX, "acx feature cfg");
220
221 feature = kzalloc(sizeof(*feature), GFP_KERNEL);
222 if (!feature) {
223 ret = -ENOMEM;
224 goto out;
225 }
226
227 /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */
228 feature->data_flow_options = 0;
229 feature->options = 0;
230
231 ret = wl1251_cmd_configure(wl, ACX_FEATURE_CFG,
232 feature, sizeof(*feature));
233 if (ret < 0) {
234 wl1251_error("Couldn't set HW encryption");
235 goto out;
236 }
237
238out:
239 kfree(feature);
240 return ret;
241}
242
243int wl1251_acx_mem_map(struct wl1251 *wl, struct acx_header *mem_map,
244 size_t len)
245{
246 int ret;
247
248 wl1251_debug(DEBUG_ACX, "acx mem map");
249
250 ret = wl1251_cmd_interrogate(wl, ACX_MEM_MAP, mem_map, len);
251 if (ret < 0)
252 return ret;
253
254 return 0;
255}
256
257int wl1251_acx_data_path_params(struct wl1251 *wl,
258 struct acx_data_path_params_resp *resp)
259{
260 struct acx_data_path_params *params;
261 int ret;
262
263 wl1251_debug(DEBUG_ACX, "acx data path params");
264
265 params = kzalloc(sizeof(*params), GFP_KERNEL);
266 if (!params) {
267 ret = -ENOMEM;
268 goto out;
269 }
270
271 params->rx_packet_ring_chunk_size = DP_RX_PACKET_RING_CHUNK_SIZE;
272 params->tx_packet_ring_chunk_size = DP_TX_PACKET_RING_CHUNK_SIZE;
273
274 params->rx_packet_ring_chunk_num = DP_RX_PACKET_RING_CHUNK_NUM;
275 params->tx_packet_ring_chunk_num = DP_TX_PACKET_RING_CHUNK_NUM;
276
277 params->tx_complete_threshold = 1;
278
279 params->tx_complete_ring_depth = FW_TX_CMPLT_BLOCK_SIZE;
280
281 params->tx_complete_timeout = DP_TX_COMPLETE_TIME_OUT;
282
283 ret = wl1251_cmd_configure(wl, ACX_DATA_PATH_PARAMS,
284 params, sizeof(*params));
285 if (ret < 0)
286 goto out;
287
288 /* FIXME: shouldn't this be ACX_DATA_PATH_RESP_PARAMS? */
289 ret = wl1251_cmd_interrogate(wl, ACX_DATA_PATH_PARAMS,
290 resp, sizeof(*resp));
291
292 if (ret < 0) {
293 wl1251_warning("failed to read data path parameters: %d", ret);
294 goto out;
295 } else if (resp->header.cmd.status != CMD_STATUS_SUCCESS) {
296 wl1251_warning("data path parameter acx status failed");
297 ret = -EIO;
298 goto out;
299 }
300
301out:
302 kfree(params);
303 return ret;
304}
305
306int wl1251_acx_rx_msdu_life_time(struct wl1251 *wl, u32 life_time)
307{
308 struct acx_rx_msdu_lifetime *acx;
309 int ret;
310
311 wl1251_debug(DEBUG_ACX, "acx rx msdu life time");
312
313 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
314 if (!acx) {
315 ret = -ENOMEM;
316 goto out;
317 }
318
319 acx->lifetime = life_time;
320 ret = wl1251_cmd_configure(wl, DOT11_RX_MSDU_LIFE_TIME,
321 acx, sizeof(*acx));
322 if (ret < 0) {
323 wl1251_warning("failed to set rx msdu life time: %d", ret);
324 goto out;
325 }
326
327out:
328 kfree(acx);
329 return ret;
330}
331
332int wl1251_acx_rx_config(struct wl1251 *wl, u32 config, u32 filter)
333{
334 struct acx_rx_config *rx_config;
335 int ret;
336
337 wl1251_debug(DEBUG_ACX, "acx rx config");
338
339 rx_config = kzalloc(sizeof(*rx_config), GFP_KERNEL);
340 if (!rx_config) {
341 ret = -ENOMEM;
342 goto out;
343 }
344
345 rx_config->config_options = config;
346 rx_config->filter_options = filter;
347
348 ret = wl1251_cmd_configure(wl, ACX_RX_CFG,
349 rx_config, sizeof(*rx_config));
350 if (ret < 0) {
351 wl1251_warning("failed to set rx config: %d", ret);
352 goto out;
353 }
354
355out:
356 kfree(rx_config);
357 return ret;
358}
359
360int wl1251_acx_pd_threshold(struct wl1251 *wl)
361{
362 struct acx_packet_detection *pd;
363 int ret;
364
365 wl1251_debug(DEBUG_ACX, "acx data pd threshold");
366
367 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
368 if (!pd) {
369 ret = -ENOMEM;
370 goto out;
371 }
372
373 /* FIXME: threshold value not set */
374
375 ret = wl1251_cmd_configure(wl, ACX_PD_THRESHOLD, pd, sizeof(*pd));
376 if (ret < 0) {
377 wl1251_warning("failed to set pd threshold: %d", ret);
378 goto out;
379 }
380
381out:
382 kfree(pd);
383 return 0;
384}
385
386int wl1251_acx_slot(struct wl1251 *wl, enum acx_slot_type slot_time)
387{
388 struct acx_slot *slot;
389 int ret;
390
391 wl1251_debug(DEBUG_ACX, "acx slot");
392
393 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
394 if (!slot) {
395 ret = -ENOMEM;
396 goto out;
397 }
398
399 slot->wone_index = STATION_WONE_INDEX;
400 slot->slot_time = slot_time;
401
402 ret = wl1251_cmd_configure(wl, ACX_SLOT, slot, sizeof(*slot));
403 if (ret < 0) {
404 wl1251_warning("failed to set slot time: %d", ret);
405 goto out;
406 }
407
408out:
409 kfree(slot);
410 return ret;
411}
412
413int wl1251_acx_group_address_tbl(struct wl1251 *wl)
414{
415 struct acx_dot11_grp_addr_tbl *acx;
416 int ret;
417
418 wl1251_debug(DEBUG_ACX, "acx group address tbl");
419
420 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
421 if (!acx) {
422 ret = -ENOMEM;
423 goto out;
424 }
425
426 /* MAC filtering */
427 acx->enabled = 0;
428 acx->num_groups = 0;
429 memset(acx->mac_table, 0, ADDRESS_GROUP_MAX_LEN);
430
431 ret = wl1251_cmd_configure(wl, DOT11_GROUP_ADDRESS_TBL,
432 acx, sizeof(*acx));
433 if (ret < 0) {
434 wl1251_warning("failed to set group addr table: %d", ret);
435 goto out;
436 }
437
438out:
439 kfree(acx);
440 return ret;
441}
442
443int wl1251_acx_service_period_timeout(struct wl1251 *wl)
444{
445 struct acx_rx_timeout *rx_timeout;
446 int ret;
447
448 rx_timeout = kzalloc(sizeof(*rx_timeout), GFP_KERNEL);
449 if (!rx_timeout) {
450 ret = -ENOMEM;
451 goto out;
452 }
453
454 wl1251_debug(DEBUG_ACX, "acx service period timeout");
455
456 rx_timeout->ps_poll_timeout = RX_TIMEOUT_PS_POLL_DEF;
457 rx_timeout->upsd_timeout = RX_TIMEOUT_UPSD_DEF;
458
459 ret = wl1251_cmd_configure(wl, ACX_SERVICE_PERIOD_TIMEOUT,
460 rx_timeout, sizeof(*rx_timeout));
461 if (ret < 0) {
462 wl1251_warning("failed to set service period timeout: %d",
463 ret);
464 goto out;
465 }
466
467out:
468 kfree(rx_timeout);
469 return ret;
470}
471
472int wl1251_acx_rts_threshold(struct wl1251 *wl, u16 rts_threshold)
473{
474 struct acx_rts_threshold *rts;
475 int ret;
476
477 wl1251_debug(DEBUG_ACX, "acx rts threshold");
478
479 rts = kzalloc(sizeof(*rts), GFP_KERNEL);
480 if (!rts) {
481 ret = -ENOMEM;
482 goto out;
483 }
484
485 rts->threshold = rts_threshold;
486
487 ret = wl1251_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts));
488 if (ret < 0) {
489 wl1251_warning("failed to set rts threshold: %d", ret);
490 goto out;
491 }
492
493out:
494 kfree(rts);
495 return ret;
496}
497
498int wl1251_acx_beacon_filter_opt(struct wl1251 *wl, bool enable_filter)
499{
500 struct acx_beacon_filter_option *beacon_filter;
501 int ret;
502
503 wl1251_debug(DEBUG_ACX, "acx beacon filter opt");
504
505 beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL);
506 if (!beacon_filter) {
507 ret = -ENOMEM;
508 goto out;
509 }
510
511 beacon_filter->enable = enable_filter;
512 beacon_filter->max_num_beacons = 0;
513
514 ret = wl1251_cmd_configure(wl, ACX_BEACON_FILTER_OPT,
515 beacon_filter, sizeof(*beacon_filter));
516 if (ret < 0) {
517 wl1251_warning("failed to set beacon filter opt: %d", ret);
518 goto out;
519 }
520
521out:
522 kfree(beacon_filter);
523 return ret;
524}
525
526int wl1251_acx_beacon_filter_table(struct wl1251 *wl)
527{
528 struct acx_beacon_filter_ie_table *ie_table;
529 int idx = 0;
530 int ret;
531
532 wl1251_debug(DEBUG_ACX, "acx beacon filter table");
533
534 ie_table = kzalloc(sizeof(*ie_table), GFP_KERNEL);
535 if (!ie_table) {
536 ret = -ENOMEM;
537 goto out;
538 }
539
540 /* configure default beacon pass-through rules */
541 ie_table->num_ie = 1;
542 ie_table->table[idx++] = BEACON_FILTER_IE_ID_CHANNEL_SWITCH_ANN;
543 ie_table->table[idx++] = BEACON_RULE_PASS_ON_APPEARANCE;
544
545 ret = wl1251_cmd_configure(wl, ACX_BEACON_FILTER_TABLE,
546 ie_table, sizeof(*ie_table));
547 if (ret < 0) {
548 wl1251_warning("failed to set beacon filter table: %d", ret);
549 goto out;
550 }
551
552out:
553 kfree(ie_table);
554 return ret;
555}
556
557int wl1251_acx_conn_monit_params(struct wl1251 *wl)
558{
559 struct acx_conn_monit_params *acx;
560 int ret;
561
562 wl1251_debug(DEBUG_ACX, "acx connection monitor parameters");
563
564 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
565 if (!acx) {
566 ret = -ENOMEM;
567 goto out;
568 }
569
570 acx->synch_fail_thold = SYNCH_FAIL_DEFAULT_THRESHOLD;
571 acx->bss_lose_timeout = NO_BEACON_DEFAULT_TIMEOUT;
572
573 ret = wl1251_cmd_configure(wl, ACX_CONN_MONIT_PARAMS,
574 acx, sizeof(*acx));
575 if (ret < 0) {
576 wl1251_warning("failed to set connection monitor "
577 "parameters: %d", ret);
578 goto out;
579 }
580
581out:
582 kfree(acx);
583 return ret;
584}
585
586int wl1251_acx_sg_enable(struct wl1251 *wl)
587{
588 struct acx_bt_wlan_coex *pta;
589 int ret;
590
591 wl1251_debug(DEBUG_ACX, "acx sg enable");
592
593 pta = kzalloc(sizeof(*pta), GFP_KERNEL);
594 if (!pta) {
595 ret = -ENOMEM;
596 goto out;
597 }
598
599 pta->enable = SG_ENABLE;
600
601 ret = wl1251_cmd_configure(wl, ACX_SG_ENABLE, pta, sizeof(*pta));
602 if (ret < 0) {
603 wl1251_warning("failed to set softgemini enable: %d", ret);
604 goto out;
605 }
606
607out:
608 kfree(pta);
609 return ret;
610}
611
612int wl1251_acx_sg_cfg(struct wl1251 *wl)
613{
614 struct acx_bt_wlan_coex_param *param;
615 int ret;
616
617 wl1251_debug(DEBUG_ACX, "acx sg cfg");
618
619 param = kzalloc(sizeof(*param), GFP_KERNEL);
620 if (!param) {
621 ret = -ENOMEM;
622 goto out;
623 }
624
625 /* BT-WLAN coext parameters */
626 param->min_rate = RATE_INDEX_24MBPS;
627 param->bt_hp_max_time = PTA_BT_HP_MAXTIME_DEF;
628 param->wlan_hp_max_time = PTA_WLAN_HP_MAX_TIME_DEF;
629 param->sense_disable_timer = PTA_SENSE_DISABLE_TIMER_DEF;
630 param->rx_time_bt_hp = PTA_PROTECTIVE_RX_TIME_DEF;
631 param->tx_time_bt_hp = PTA_PROTECTIVE_TX_TIME_DEF;
632 param->rx_time_bt_hp_fast = PTA_PROTECTIVE_RX_TIME_FAST_DEF;
633 param->tx_time_bt_hp_fast = PTA_PROTECTIVE_TX_TIME_FAST_DEF;
634 param->wlan_cycle_fast = PTA_CYCLE_TIME_FAST_DEF;
635 param->bt_anti_starvation_period = PTA_ANTI_STARVE_PERIOD_DEF;
636 param->next_bt_lp_packet = PTA_TIMEOUT_NEXT_BT_LP_PACKET_DEF;
637 param->wake_up_beacon = PTA_TIME_BEFORE_BEACON_DEF;
638 param->hp_dm_max_guard_time = PTA_HPDM_MAX_TIME_DEF;
639 param->next_wlan_packet = PTA_TIME_OUT_NEXT_WLAN_DEF;
640 param->antenna_type = PTA_ANTENNA_TYPE_DEF;
641 param->signal_type = PTA_SIGNALING_TYPE_DEF;
642 param->afh_leverage_on = PTA_AFH_LEVERAGE_ON_DEF;
643 param->quiet_cycle_num = PTA_NUMBER_QUIET_CYCLE_DEF;
644 param->max_cts = PTA_MAX_NUM_CTS_DEF;
645 param->wlan_packets_num = PTA_NUMBER_OF_WLAN_PACKETS_DEF;
646 param->bt_packets_num = PTA_NUMBER_OF_BT_PACKETS_DEF;
647 param->missed_rx_avalanche = PTA_RX_FOR_AVALANCHE_DEF;
648 param->wlan_elp_hp = PTA_ELP_HP_DEF;
649 param->bt_anti_starvation_cycles = PTA_ANTI_STARVE_NUM_CYCLE_DEF;
650 param->ack_mode_dual_ant = PTA_ACK_MODE_DEF;
651 param->pa_sd_enable = PTA_ALLOW_PA_SD_DEF;
652 param->pta_auto_mode_enable = PTA_AUTO_MODE_NO_CTS_DEF;
653 param->bt_hp_respected_num = PTA_BT_HP_RESPECTED_DEF;
654
655 ret = wl1251_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param));
656 if (ret < 0) {
657 wl1251_warning("failed to set sg config: %d", ret);
658 goto out;
659 }
660
661out:
662 kfree(param);
663 return ret;
664}
665
666int wl1251_acx_cca_threshold(struct wl1251 *wl)
667{
668 struct acx_energy_detection *detection;
669 int ret;
670
671 wl1251_debug(DEBUG_ACX, "acx cca threshold");
672
673 detection = kzalloc(sizeof(*detection), GFP_KERNEL);
674 if (!detection) {
675 ret = -ENOMEM;
676 goto out;
677 }
678
679 detection->rx_cca_threshold = CCA_THRSH_DISABLE_ENERGY_D;
680 detection->tx_energy_detection = 0;
681
682 ret = wl1251_cmd_configure(wl, ACX_CCA_THRESHOLD,
683 detection, sizeof(*detection));
684 if (ret < 0) {
685 wl1251_warning("failed to set cca threshold: %d", ret);
686 return ret;
687 }
688
689out:
690 kfree(detection);
691 return ret;
692}
693
694int wl1251_acx_bcn_dtim_options(struct wl1251 *wl)
695{
696 struct acx_beacon_broadcast *bb;
697 int ret;
698
699 wl1251_debug(DEBUG_ACX, "acx bcn dtim options");
700
701 bb = kzalloc(sizeof(*bb), GFP_KERNEL);
702 if (!bb) {
703 ret = -ENOMEM;
704 goto out;
705 }
706
707 bb->beacon_rx_timeout = BCN_RX_TIMEOUT_DEF_VALUE;
708 bb->broadcast_timeout = BROADCAST_RX_TIMEOUT_DEF_VALUE;
709 bb->rx_broadcast_in_ps = RX_BROADCAST_IN_PS_DEF_VALUE;
710 bb->ps_poll_threshold = CONSECUTIVE_PS_POLL_FAILURE_DEF;
711
712 ret = wl1251_cmd_configure(wl, ACX_BCN_DTIM_OPTIONS, bb, sizeof(*bb));
713 if (ret < 0) {
714 wl1251_warning("failed to set rx config: %d", ret);
715 goto out;
716 }
717
718out:
719 kfree(bb);
720 return ret;
721}
722
723int wl1251_acx_aid(struct wl1251 *wl, u16 aid)
724{
725 struct acx_aid *acx_aid;
726 int ret;
727
728 wl1251_debug(DEBUG_ACX, "acx aid");
729
730 acx_aid = kzalloc(sizeof(*acx_aid), GFP_KERNEL);
731 if (!acx_aid) {
732 ret = -ENOMEM;
733 goto out;
734 }
735
736 acx_aid->aid = aid;
737
738 ret = wl1251_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid));
739 if (ret < 0) {
740 wl1251_warning("failed to set aid: %d", ret);
741 goto out;
742 }
743
744out:
745 kfree(acx_aid);
746 return ret;
747}
748
749int wl1251_acx_event_mbox_mask(struct wl1251 *wl, u32 event_mask)
750{
751 struct acx_event_mask *mask;
752 int ret;
753
754 wl1251_debug(DEBUG_ACX, "acx event mbox mask");
755
756 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
757 if (!mask) {
758 ret = -ENOMEM;
759 goto out;
760 }
761
762 /* high event mask is unused */
763 mask->high_event_mask = 0xffffffff;
764
765 mask->event_mask = event_mask;
766
767 ret = wl1251_cmd_configure(wl, ACX_EVENT_MBOX_MASK,
768 mask, sizeof(*mask));
769 if (ret < 0) {
770 wl1251_warning("failed to set acx_event_mbox_mask: %d", ret);
771 goto out;
772 }
773
774out:
775 kfree(mask);
776 return ret;
777}
778
779int wl1251_acx_set_preamble(struct wl1251 *wl, enum acx_preamble_type preamble)
780{
781 struct acx_preamble *acx;
782 int ret;
783
784 wl1251_debug(DEBUG_ACX, "acx_set_preamble");
785
786 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
787 if (!acx) {
788 ret = -ENOMEM;
789 goto out;
790 }
791
792 acx->preamble = preamble;
793
794 ret = wl1251_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx));
795 if (ret < 0) {
796 wl1251_warning("Setting of preamble failed: %d", ret);
797 goto out;
798 }
799
800out:
801 kfree(acx);
802 return ret;
803}
804
805int wl1251_acx_cts_protect(struct wl1251 *wl,
806 enum acx_ctsprotect_type ctsprotect)
807{
808 struct acx_ctsprotect *acx;
809 int ret;
810
811 wl1251_debug(DEBUG_ACX, "acx_set_ctsprotect");
812
813 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
814 if (!acx) {
815 ret = -ENOMEM;
816 goto out;
817 }
818
819 acx->ctsprotect = ctsprotect;
820
821 ret = wl1251_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx));
822 if (ret < 0) {
823 wl1251_warning("Setting of ctsprotect failed: %d", ret);
824 goto out;
825 }
826
827out:
828 kfree(acx);
829 return ret;
830}
831
832int wl1251_acx_tsf_info(struct wl1251 *wl, u64 *mactime)
833{
834 struct acx_tsf_info *tsf_info;
835 int ret;
836
837 tsf_info = kzalloc(sizeof(*tsf_info), GFP_KERNEL);
838 if (!tsf_info) {
839 ret = -ENOMEM;
840 goto out;
841 }
842
843 ret = wl1251_cmd_interrogate(wl, ACX_TSF_INFO,
844 tsf_info, sizeof(*tsf_info));
845 if (ret < 0) {
846 wl1251_warning("ACX_FW_REV interrogate failed");
847 goto out;
848 }
849
850 *mactime = tsf_info->current_tsf_lsb |
851 (tsf_info->current_tsf_msb << 31);
852
853out:
854 kfree(tsf_info);
855 return ret;
856}
857
858int wl1251_acx_statistics(struct wl1251 *wl, struct acx_statistics *stats)
859{
860 int ret;
861
862 wl1251_debug(DEBUG_ACX, "acx statistics");
863
864 ret = wl1251_cmd_interrogate(wl, ACX_STATISTICS, stats,
865 sizeof(*stats));
866 if (ret < 0) {
867 wl1251_warning("acx statistics failed: %d", ret);
868 return -ENOMEM;
869 }
870
871 return 0;
872}
873
874int wl1251_acx_rate_policies(struct wl1251 *wl)
875{
876 struct acx_rate_policy *acx;
877 int ret = 0;
878
879 wl1251_debug(DEBUG_ACX, "acx rate policies");
880
881 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
882
883 if (!acx) {
884 ret = -ENOMEM;
885 goto out;
886 }
887
888 /* configure one default (one-size-fits-all) rate class */
889 acx->rate_class_cnt = 1;
890 acx->rate_class[0].enabled_rates = ACX_RATE_MASK_UNSPECIFIED;
891 acx->rate_class[0].short_retry_limit = ACX_RATE_RETRY_LIMIT;
892 acx->rate_class[0].long_retry_limit = ACX_RATE_RETRY_LIMIT;
893 acx->rate_class[0].aflags = 0;
894
895 ret = wl1251_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
896 if (ret < 0) {
897 wl1251_warning("Setting of rate policies failed: %d", ret);
898 goto out;
899 }
900
901out:
902 kfree(acx);
903 return ret;
904}
905
906int wl1251_acx_mem_cfg(struct wl1251 *wl)
907{
908 struct wl1251_acx_config_memory *mem_conf;
909 int ret, i;
910
911 wl1251_debug(DEBUG_ACX, "acx mem cfg");
912
913 mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL);
914 if (!mem_conf) {
915 ret = -ENOMEM;
916 goto out;
917 }
918
919 /* memory config */
920 mem_conf->mem_config.num_stations = cpu_to_le16(DEFAULT_NUM_STATIONS);
921 mem_conf->mem_config.rx_mem_block_num = 35;
922 mem_conf->mem_config.tx_min_mem_block_num = 64;
923 mem_conf->mem_config.num_tx_queues = MAX_TX_QUEUES;
924 mem_conf->mem_config.host_if_options = HOSTIF_PKT_RING;
925 mem_conf->mem_config.num_ssid_profiles = 1;
926 mem_conf->mem_config.debug_buffer_size =
927 cpu_to_le16(TRACE_BUFFER_MAX_SIZE);
928
929 /* RX queue config */
930 mem_conf->rx_queue_config.dma_address = 0;
931 mem_conf->rx_queue_config.num_descs = ACX_RX_DESC_DEF;
932 mem_conf->rx_queue_config.priority = DEFAULT_RXQ_PRIORITY;
933 mem_conf->rx_queue_config.type = DEFAULT_RXQ_TYPE;
934
935 /* TX queue config */
936 for (i = 0; i < MAX_TX_QUEUES; i++) {
937 mem_conf->tx_queue_config[i].num_descs = ACX_TX_DESC_DEF;
938 mem_conf->tx_queue_config[i].attributes = i;
939 }
940
941 ret = wl1251_cmd_configure(wl, ACX_MEM_CFG, mem_conf,
942 sizeof(*mem_conf));
943 if (ret < 0) {
944 wl1251_warning("wl1251 mem config failed: %d", ret);
945 goto out;
946 }
947
948out:
949 kfree(mem_conf);
950 return ret;
951}
952
953int wl1251_acx_wr_tbtt_and_dtim(struct wl1251 *wl, u16 tbtt, u8 dtim)
954{
955 struct wl1251_acx_wr_tbtt_and_dtim *acx;
956 int ret;
957
958 wl1251_debug(DEBUG_ACX, "acx tbtt and dtim");
959
960 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
961 if (!acx) {
962 ret = -ENOMEM;
963 goto out;
964 }
965
966 acx->tbtt = tbtt;
967 acx->dtim = dtim;
968
969 ret = wl1251_cmd_configure(wl, ACX_WR_TBTT_AND_DTIM,
970 acx, sizeof(*acx));
971 if (ret < 0) {
972 wl1251_warning("failed to set tbtt and dtim: %d", ret);
973 goto out;
974 }
975
976out:
977 kfree(acx);
978 return ret;
979}
980
981int wl1251_acx_ac_cfg(struct wl1251 *wl, u8 ac, u8 cw_min, u16 cw_max,
982 u8 aifs, u16 txop)
983{
984 struct wl1251_acx_ac_cfg *acx;
985 int ret = 0;
986
987 wl1251_debug(DEBUG_ACX, "acx ac cfg %d cw_ming %d cw_max %d "
988 "aifs %d txop %d", ac, cw_min, cw_max, aifs, txop);
989
990 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
991
992 if (!acx) {
993 ret = -ENOMEM;
994 goto out;
995 }
996
997 acx->ac = ac;
998 acx->cw_min = cw_min;
999 acx->cw_max = cw_max;
1000 acx->aifsn = aifs;
1001 acx->txop_limit = txop;
1002
1003 ret = wl1251_cmd_configure(wl, ACX_AC_CFG, acx, sizeof(*acx));
1004 if (ret < 0) {
1005 wl1251_warning("acx ac cfg failed: %d", ret);
1006 goto out;
1007 }
1008
1009out:
1010 kfree(acx);
1011 return ret;
1012}
1013
1014int wl1251_acx_tid_cfg(struct wl1251 *wl, u8 queue,
1015 enum wl1251_acx_channel_type type,
1016 u8 tsid, enum wl1251_acx_ps_scheme ps_scheme,
1017 enum wl1251_acx_ack_policy ack_policy)
1018{
1019 struct wl1251_acx_tid_cfg *acx;
1020 int ret = 0;
1021
1022 wl1251_debug(DEBUG_ACX, "acx tid cfg %d type %d tsid %d "
1023 "ps_scheme %d ack_policy %d", queue, type, tsid,
1024 ps_scheme, ack_policy);
1025
1026 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1027
1028 if (!acx) {
1029 ret = -ENOMEM;
1030 goto out;
1031 }
1032
1033 acx->queue = queue;
1034 acx->type = type;
1035 acx->tsid = tsid;
1036 acx->ps_scheme = ps_scheme;
1037 acx->ack_policy = ack_policy;
1038
1039 ret = wl1251_cmd_configure(wl, ACX_TID_CFG, acx, sizeof(*acx));
1040 if (ret < 0) {
1041 wl1251_warning("acx tid cfg failed: %d", ret);
1042 goto out;
1043 }
1044
1045out:
1046 kfree(acx);
1047 return ret;
1048}
diff --git a/drivers/net/wireless/wl12xx/wl1251_acx.h b/drivers/net/wireless/wl12xx/wl1251_acx.h
deleted file mode 100644
index 842df310d92a..000000000000
--- a/drivers/net/wireless/wl12xx/wl1251_acx.h
+++ /dev/null
@@ -1,1413 +0,0 @@
1/*
2 * This file is part of wl1251
3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation
6 *
7 * Contact: Kalle Valo <kalle.valo@nokia.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25#ifndef __WL1251_ACX_H__
26#define __WL1251_ACX_H__
27
28#include "wl1251.h"
29#include "wl1251_cmd.h"
30
31/* Target's information element */
32struct acx_header {
33 struct wl1251_cmd_header cmd;
34
35 /* acx (or information element) header */
36 u16 id;
37
38 /* payload length (not including headers */
39 u16 len;
40};
41
42struct acx_error_counter {
43 struct acx_header header;
44
45 /* The number of PLCP errors since the last time this */
46 /* information element was interrogated. This field is */
47 /* automatically cleared when it is interrogated.*/
48 u32 PLCP_error;
49
50 /* The number of FCS errors since the last time this */
51 /* information element was interrogated. This field is */
52 /* automatically cleared when it is interrogated.*/
53 u32 FCS_error;
54
55 /* The number of MPDUs without PLCP header errors received*/
56 /* since the last time this information element was interrogated. */
57 /* This field is automatically cleared when it is interrogated.*/
58 u32 valid_frame;
59
60 /* the number of missed sequence numbers in the squentially */
61 /* values of frames seq numbers */
62 u32 seq_num_miss;
63} __packed;
64
65struct acx_revision {
66 struct acx_header header;
67
68 /*
69 * The WiLink firmware version, an ASCII string x.x.x.x,
70 * that uniquely identifies the current firmware.
71 * The left most digit is incremented each time a
72 * significant change is made to the firmware, such as
73 * code redesign or new platform support.
74 * The second digit is incremented when major enhancements
75 * are added or major fixes are made.
76 * The third digit is incremented for each GA release.
77 * The fourth digit is incremented for each build.
78 * The first two digits identify a firmware release version,
79 * in other words, a unique set of features.
80 * The first three digits identify a GA release.
81 */
82 char fw_version[20];
83
84 /*
85 * This 4 byte field specifies the WiLink hardware version.
86 * bits 0 - 15: Reserved.
87 * bits 16 - 23: Version ID - The WiLink version ID
88 * (1 = first spin, 2 = second spin, and so on).
89 * bits 24 - 31: Chip ID - The WiLink chip ID.
90 */
91 u32 hw_version;
92} __packed;
93
94enum wl1251_psm_mode {
95 /* Active mode */
96 WL1251_PSM_CAM = 0,
97
98 /* Power save mode */
99 WL1251_PSM_PS = 1,
100
101 /* Extreme low power */
102 WL1251_PSM_ELP = 2,
103};
104
105struct acx_sleep_auth {
106 struct acx_header header;
107
108 /* The sleep level authorization of the device. */
109 /* 0 - Always active*/
110 /* 1 - Power down mode: light / fast sleep*/
111 /* 2 - ELP mode: Deep / Max sleep*/
112 u8 sleep_auth;
113 u8 padding[3];
114} __packed;
115
116enum {
117 HOSTIF_PCI_MASTER_HOST_INDIRECT,
118 HOSTIF_PCI_MASTER_HOST_DIRECT,
119 HOSTIF_SLAVE,
120 HOSTIF_PKT_RING,
121 HOSTIF_DONTCARE = 0xFF
122};
123
124#define DEFAULT_UCAST_PRIORITY 0
125#define DEFAULT_RX_Q_PRIORITY 0
126#define DEFAULT_NUM_STATIONS 1
127#define DEFAULT_RXQ_PRIORITY 0 /* low 0 .. 15 high */
128#define DEFAULT_RXQ_TYPE 0x07 /* All frames, Data/Ctrl/Mgmt */
129#define TRACE_BUFFER_MAX_SIZE 256
130
131#define DP_RX_PACKET_RING_CHUNK_SIZE 1600
132#define DP_TX_PACKET_RING_CHUNK_SIZE 1600
133#define DP_RX_PACKET_RING_CHUNK_NUM 2
134#define DP_TX_PACKET_RING_CHUNK_NUM 2
135#define DP_TX_COMPLETE_TIME_OUT 20
136#define FW_TX_CMPLT_BLOCK_SIZE 16
137
138struct acx_data_path_params {
139 struct acx_header header;
140
141 u16 rx_packet_ring_chunk_size;
142 u16 tx_packet_ring_chunk_size;
143
144 u8 rx_packet_ring_chunk_num;
145 u8 tx_packet_ring_chunk_num;
146
147 /*
148 * Maximum number of packets that can be gathered
149 * in the TX complete ring before an interrupt
150 * is generated.
151 */
152 u8 tx_complete_threshold;
153
154 /* Number of pending TX complete entries in cyclic ring.*/
155 u8 tx_complete_ring_depth;
156
157 /*
158 * Max num microseconds since a packet enters the TX
159 * complete ring until an interrupt is generated.
160 */
161 u32 tx_complete_timeout;
162} __packed;
163
164
165struct acx_data_path_params_resp {
166 struct acx_header header;
167
168 u16 rx_packet_ring_chunk_size;
169 u16 tx_packet_ring_chunk_size;
170
171 u8 rx_packet_ring_chunk_num;
172 u8 tx_packet_ring_chunk_num;
173
174 u8 pad[2];
175
176 u32 rx_packet_ring_addr;
177 u32 tx_packet_ring_addr;
178
179 u32 rx_control_addr;
180 u32 tx_control_addr;
181
182 u32 tx_complete_addr;
183} __packed;
184
185#define TX_MSDU_LIFETIME_MIN 0
186#define TX_MSDU_LIFETIME_MAX 3000
187#define TX_MSDU_LIFETIME_DEF 512
188#define RX_MSDU_LIFETIME_MIN 0
189#define RX_MSDU_LIFETIME_MAX 0xFFFFFFFF
190#define RX_MSDU_LIFETIME_DEF 512000
191
192struct acx_rx_msdu_lifetime {
193 struct acx_header header;
194
195 /*
196 * The maximum amount of time, in TU, before the
197 * firmware discards the MSDU.
198 */
199 u32 lifetime;
200} __packed;
201
202/*
203 * RX Config Options Table
204 * Bit Definition
205 * === ==========
206 * 31:14 Reserved
207 * 13 Copy RX Status - when set, write three receive status words
208 * to top of rx'd MPDUs.
209 * When cleared, do not write three status words (added rev 1.5)
210 * 12 Reserved
211 * 11 RX Complete upon FCS error - when set, give rx complete
212 * interrupt for FCS errors, after the rx filtering, e.g. unicast
213 * frames not to us with FCS error will not generate an interrupt.
214 * 10 SSID Filter Enable - When set, the WiLink discards all beacon,
215 * probe request, and probe response frames with an SSID that does
216 * not match the SSID specified by the host in the START/JOIN
217 * command.
218 * When clear, the WiLink receives frames with any SSID.
219 * 9 Broadcast Filter Enable - When set, the WiLink discards all
220 * broadcast frames. When clear, the WiLink receives all received
221 * broadcast frames.
222 * 8:6 Reserved
223 * 5 BSSID Filter Enable - When set, the WiLink discards any frames
224 * with a BSSID that does not match the BSSID specified by the
225 * host.
226 * When clear, the WiLink receives frames from any BSSID.
227 * 4 MAC Addr Filter - When set, the WiLink discards any frames
228 * with a destination address that does not match the MAC address
229 * of the adaptor.
230 * When clear, the WiLink receives frames destined to any MAC
231 * address.
232 * 3 Promiscuous - When set, the WiLink receives all valid frames
233 * (i.e., all frames that pass the FCS check).
234 * When clear, only frames that pass the other filters specified
235 * are received.
236 * 2 FCS - When set, the WiLink includes the FCS with the received
237 * frame.
238 * When cleared, the FCS is discarded.
239 * 1 PLCP header - When set, write all data from baseband to frame
240 * buffer including PHY header.
241 * 0 Reserved - Always equal to 0.
242 *
243 * RX Filter Options Table
244 * Bit Definition
245 * === ==========
246 * 31:12 Reserved - Always equal to 0.
247 * 11 Association - When set, the WiLink receives all association
248 * related frames (association request/response, reassocation
249 * request/response, and disassociation). When clear, these frames
250 * are discarded.
251 * 10 Auth/De auth - When set, the WiLink receives all authentication
252 * and de-authentication frames. When clear, these frames are
253 * discarded.
254 * 9 Beacon - When set, the WiLink receives all beacon frames.
255 * When clear, these frames are discarded.
256 * 8 Contention Free - When set, the WiLink receives all contention
257 * free frames.
258 * When clear, these frames are discarded.
259 * 7 Control - When set, the WiLink receives all control frames.
260 * When clear, these frames are discarded.
261 * 6 Data - When set, the WiLink receives all data frames.
262 * When clear, these frames are discarded.
263 * 5 FCS Error - When set, the WiLink receives frames that have FCS
264 * errors.
265 * When clear, these frames are discarded.
266 * 4 Management - When set, the WiLink receives all management
267 * frames.
268 * When clear, these frames are discarded.
269 * 3 Probe Request - When set, the WiLink receives all probe request
270 * frames.
271 * When clear, these frames are discarded.
272 * 2 Probe Response - When set, the WiLink receives all probe
273 * response frames.
274 * When clear, these frames are discarded.
275 * 1 RTS/CTS/ACK - When set, the WiLink receives all RTS, CTS and ACK
276 * frames.
277 * When clear, these frames are discarded.
278 * 0 Rsvd Type/Sub Type - When set, the WiLink receives all frames
279 * that have reserved frame types and sub types as defined by the
280 * 802.11 specification.
281 * When clear, these frames are discarded.
282 */
283struct acx_rx_config {
284 struct acx_header header;
285
286 u32 config_options;
287 u32 filter_options;
288} __packed;
289
290enum {
291 QOS_AC_BE = 0,
292 QOS_AC_BK,
293 QOS_AC_VI,
294 QOS_AC_VO,
295 QOS_HIGHEST_AC_INDEX = QOS_AC_VO,
296};
297
298#define MAX_NUM_OF_AC (QOS_HIGHEST_AC_INDEX+1)
299#define FIRST_AC_INDEX QOS_AC_BE
300#define MAX_NUM_OF_802_1d_TAGS 8
301#define AC_PARAMS_MAX_TSID 15
302#define MAX_APSD_CONF 0xffff
303
304#define QOS_TX_HIGH_MIN (0)
305#define QOS_TX_HIGH_MAX (100)
306
307#define QOS_TX_HIGH_BK_DEF (25)
308#define QOS_TX_HIGH_BE_DEF (35)
309#define QOS_TX_HIGH_VI_DEF (35)
310#define QOS_TX_HIGH_VO_DEF (35)
311
312#define QOS_TX_LOW_BK_DEF (15)
313#define QOS_TX_LOW_BE_DEF (25)
314#define QOS_TX_LOW_VI_DEF (25)
315#define QOS_TX_LOW_VO_DEF (25)
316
317struct acx_tx_queue_qos_config {
318 struct acx_header header;
319
320 u8 qid;
321 u8 pad[3];
322
323 /* Max number of blocks allowd in the queue */
324 u16 high_threshold;
325
326 /* Lowest memory blocks guaranteed for this queue */
327 u16 low_threshold;
328} __packed;
329
330struct acx_packet_detection {
331 struct acx_header header;
332
333 u32 threshold;
334} __packed;
335
336
337enum acx_slot_type {
338 SLOT_TIME_LONG = 0,
339 SLOT_TIME_SHORT = 1,
340 DEFAULT_SLOT_TIME = SLOT_TIME_SHORT,
341 MAX_SLOT_TIMES = 0xFF
342};
343
344#define STATION_WONE_INDEX 0
345
346struct acx_slot {
347 struct acx_header header;
348
349 u8 wone_index; /* Reserved */
350 u8 slot_time;
351 u8 reserved[6];
352} __packed;
353
354
355#define ADDRESS_GROUP_MAX (8)
356#define ADDRESS_GROUP_MAX_LEN (ETH_ALEN * ADDRESS_GROUP_MAX)
357
358struct acx_dot11_grp_addr_tbl {
359 struct acx_header header;
360
361 u8 enabled;
362 u8 num_groups;
363 u8 pad[2];
364 u8 mac_table[ADDRESS_GROUP_MAX_LEN];
365} __packed;
366
367
368#define RX_TIMEOUT_PS_POLL_MIN 0
369#define RX_TIMEOUT_PS_POLL_MAX (200000)
370#define RX_TIMEOUT_PS_POLL_DEF (15)
371#define RX_TIMEOUT_UPSD_MIN 0
372#define RX_TIMEOUT_UPSD_MAX (200000)
373#define RX_TIMEOUT_UPSD_DEF (15)
374
375struct acx_rx_timeout {
376 struct acx_header header;
377
378 /*
379 * The longest time the STA will wait to receive
380 * traffic from the AP after a PS-poll has been
381 * transmitted.
382 */
383 u16 ps_poll_timeout;
384
385 /*
386 * The longest time the STA will wait to receive
387 * traffic from the AP after a frame has been sent
388 * from an UPSD enabled queue.
389 */
390 u16 upsd_timeout;
391} __packed;
392
393#define RTS_THRESHOLD_MIN 0
394#define RTS_THRESHOLD_MAX 4096
395#define RTS_THRESHOLD_DEF 2347
396
397struct acx_rts_threshold {
398 struct acx_header header;
399
400 u16 threshold;
401 u8 pad[2];
402} __packed;
403
404struct acx_beacon_filter_option {
405 struct acx_header header;
406
407 u8 enable;
408
409 /*
410 * The number of beacons without the unicast TIM
411 * bit set that the firmware buffers before
412 * signaling the host about ready frames.
413 * When set to 0 and the filter is enabled, beacons
414 * without the unicast TIM bit set are dropped.
415 */
416 u8 max_num_beacons;
417 u8 pad[2];
418} __packed;
419
420/*
421 * ACXBeaconFilterEntry (not 221)
422 * Byte Offset Size (Bytes) Definition
423 * =========== ============ ==========
424 * 0 1 IE identifier
425 * 1 1 Treatment bit mask
426 *
427 * ACXBeaconFilterEntry (221)
428 * Byte Offset Size (Bytes) Definition
429 * =========== ============ ==========
430 * 0 1 IE identifier
431 * 1 1 Treatment bit mask
432 * 2 3 OUI
433 * 5 1 Type
434 * 6 2 Version
435 *
436 *
437 * Treatment bit mask - The information element handling:
438 * bit 0 - The information element is compared and transferred
439 * in case of change.
440 * bit 1 - The information element is transferred to the host
441 * with each appearance or disappearance.
442 * Note that both bits can be set at the same time.
443 */
444#define BEACON_FILTER_TABLE_MAX_IE_NUM (32)
445#define BEACON_FILTER_TABLE_MAX_VENDOR_SPECIFIC_IE_NUM (6)
446#define BEACON_FILTER_TABLE_IE_ENTRY_SIZE (2)
447#define BEACON_FILTER_TABLE_EXTRA_VENDOR_SPECIFIC_IE_SIZE (6)
448#define BEACON_FILTER_TABLE_MAX_SIZE ((BEACON_FILTER_TABLE_MAX_IE_NUM * \
449 BEACON_FILTER_TABLE_IE_ENTRY_SIZE) + \
450 (BEACON_FILTER_TABLE_MAX_VENDOR_SPECIFIC_IE_NUM * \
451 BEACON_FILTER_TABLE_EXTRA_VENDOR_SPECIFIC_IE_SIZE))
452
453#define BEACON_RULE_PASS_ON_CHANGE BIT(0)
454#define BEACON_RULE_PASS_ON_APPEARANCE BIT(1)
455
456#define BEACON_FILTER_IE_ID_CHANNEL_SWITCH_ANN (37)
457
458struct acx_beacon_filter_ie_table {
459 struct acx_header header;
460
461 u8 num_ie;
462 u8 table[BEACON_FILTER_TABLE_MAX_SIZE];
463 u8 pad[3];
464} __packed;
465
466#define SYNCH_FAIL_DEFAULT_THRESHOLD 10 /* number of beacons */
467#define NO_BEACON_DEFAULT_TIMEOUT (500) /* in microseconds */
468
469struct acx_conn_monit_params {
470 struct acx_header header;
471
472 u32 synch_fail_thold; /* number of beacons missed */
473 u32 bss_lose_timeout; /* number of TU's from synch fail */
474};
475
476enum {
477 SG_ENABLE = 0,
478 SG_DISABLE,
479 SG_SENSE_NO_ACTIVITY,
480 SG_SENSE_ACTIVE
481};
482
483struct acx_bt_wlan_coex {
484 struct acx_header header;
485
486 /*
487 * 0 -> PTA enabled
488 * 1 -> PTA disabled
489 * 2 -> sense no active mode, i.e.
490 * an interrupt is sent upon
491 * BT activity.
492 * 3 -> PTA is switched on in response
493 * to the interrupt sending.
494 */
495 u8 enable;
496 u8 pad[3];
497} __packed;
498
499#define PTA_ANTENNA_TYPE_DEF (0)
500#define PTA_BT_HP_MAXTIME_DEF (2000)
501#define PTA_WLAN_HP_MAX_TIME_DEF (5000)
502#define PTA_SENSE_DISABLE_TIMER_DEF (1350)
503#define PTA_PROTECTIVE_RX_TIME_DEF (1500)
504#define PTA_PROTECTIVE_TX_TIME_DEF (1500)
505#define PTA_TIMEOUT_NEXT_BT_LP_PACKET_DEF (3000)
506#define PTA_SIGNALING_TYPE_DEF (1)
507#define PTA_AFH_LEVERAGE_ON_DEF (0)
508#define PTA_NUMBER_QUIET_CYCLE_DEF (0)
509#define PTA_MAX_NUM_CTS_DEF (3)
510#define PTA_NUMBER_OF_WLAN_PACKETS_DEF (2)
511#define PTA_NUMBER_OF_BT_PACKETS_DEF (2)
512#define PTA_PROTECTIVE_RX_TIME_FAST_DEF (1500)
513#define PTA_PROTECTIVE_TX_TIME_FAST_DEF (3000)
514#define PTA_CYCLE_TIME_FAST_DEF (8700)
515#define PTA_RX_FOR_AVALANCHE_DEF (5)
516#define PTA_ELP_HP_DEF (0)
517#define PTA_ANTI_STARVE_PERIOD_DEF (500)
518#define PTA_ANTI_STARVE_NUM_CYCLE_DEF (4)
519#define PTA_ALLOW_PA_SD_DEF (1)
520#define PTA_TIME_BEFORE_BEACON_DEF (6300)
521#define PTA_HPDM_MAX_TIME_DEF (1600)
522#define PTA_TIME_OUT_NEXT_WLAN_DEF (2550)
523#define PTA_AUTO_MODE_NO_CTS_DEF (0)
524#define PTA_BT_HP_RESPECTED_DEF (3)
525#define PTA_WLAN_RX_MIN_RATE_DEF (24)
526#define PTA_ACK_MODE_DEF (1)
527
528struct acx_bt_wlan_coex_param {
529 struct acx_header header;
530
531 /*
532 * The minimum rate of a received WLAN packet in the STA,
533 * during protective mode, of which a new BT-HP request
534 * during this Rx will always be respected and gain the antenna.
535 */
536 u32 min_rate;
537
538 /* Max time the BT HP will be respected. */
539 u16 bt_hp_max_time;
540
541 /* Max time the WLAN HP will be respected. */
542 u16 wlan_hp_max_time;
543
544 /*
545 * The time between the last BT activity
546 * and the moment when the sense mode returns
547 * to SENSE_INACTIVE.
548 */
549 u16 sense_disable_timer;
550
551 /* Time before the next BT HP instance */
552 u16 rx_time_bt_hp;
553 u16 tx_time_bt_hp;
554
555 /* range: 10-20000 default: 1500 */
556 u16 rx_time_bt_hp_fast;
557 u16 tx_time_bt_hp_fast;
558
559 /* range: 2000-65535 default: 8700 */
560 u16 wlan_cycle_fast;
561
562 /* range: 0 - 15000 (Msec) default: 1000 */
563 u16 bt_anti_starvation_period;
564
565 /* range 400-10000(Usec) default: 3000 */
566 u16 next_bt_lp_packet;
567
568 /* Deafult: worst case for BT DH5 traffic */
569 u16 wake_up_beacon;
570
571 /* range: 0-50000(Usec) default: 1050 */
572 u16 hp_dm_max_guard_time;
573
574 /*
575 * This is to prevent both BT & WLAN antenna
576 * starvation.
577 * Range: 100-50000(Usec) default:2550
578 */
579 u16 next_wlan_packet;
580
581 /* 0 -> shared antenna */
582 u8 antenna_type;
583
584 /*
585 * 0 -> TI legacy
586 * 1 -> Palau
587 */
588 u8 signal_type;
589
590 /*
591 * BT AFH status
592 * 0 -> no AFH
593 * 1 -> from dedicated GPIO
594 * 2 -> AFH on (from host)
595 */
596 u8 afh_leverage_on;
597
598 /*
599 * The number of cycles during which no
600 * TX will be sent after 1 cycle of RX
601 * transaction in protective mode
602 */
603 u8 quiet_cycle_num;
604
605 /*
606 * The maximum number of CTSs that will
607 * be sent for receiving RX packet in
608 * protective mode
609 */
610 u8 max_cts;
611
612 /*
613 * The number of WLAN packets
614 * transferred in common mode before
615 * switching to BT.
616 */
617 u8 wlan_packets_num;
618
619 /*
620 * The number of BT packets
621 * transferred in common mode before
622 * switching to WLAN.
623 */
624 u8 bt_packets_num;
625
626 /* range: 1-255 default: 5 */
627 u8 missed_rx_avalanche;
628
629 /* range: 0-1 default: 1 */
630 u8 wlan_elp_hp;
631
632 /* range: 0 - 15 default: 4 */
633 u8 bt_anti_starvation_cycles;
634
635 u8 ack_mode_dual_ant;
636
637 /*
638 * Allow PA_SD assertion/de-assertion
639 * during enabled BT activity.
640 */
641 u8 pa_sd_enable;
642
643 /*
644 * Enable/Disable PTA in auto mode:
645 * Support Both Active & P.S modes
646 */
647 u8 pta_auto_mode_enable;
648
649 /* range: 0 - 20 default: 1 */
650 u8 bt_hp_respected_num;
651} __packed;
652
653#define CCA_THRSH_ENABLE_ENERGY_D 0x140A
654#define CCA_THRSH_DISABLE_ENERGY_D 0xFFEF
655
656struct acx_energy_detection {
657 struct acx_header header;
658
659 /* The RX Clear Channel Assessment threshold in the PHY */
660 u16 rx_cca_threshold;
661 u8 tx_energy_detection;
662 u8 pad;
663} __packed;
664
665#define BCN_RX_TIMEOUT_DEF_VALUE 10000
666#define BROADCAST_RX_TIMEOUT_DEF_VALUE 20000
667#define RX_BROADCAST_IN_PS_DEF_VALUE 1
668#define CONSECUTIVE_PS_POLL_FAILURE_DEF 4
669
670struct acx_beacon_broadcast {
671 struct acx_header header;
672
673 u16 beacon_rx_timeout;
674 u16 broadcast_timeout;
675
676 /* Enables receiving of broadcast packets in PS mode */
677 u8 rx_broadcast_in_ps;
678
679 /* Consecutive PS Poll failures before updating the host */
680 u8 ps_poll_threshold;
681 u8 pad[2];
682} __packed;
683
684struct acx_event_mask {
685 struct acx_header header;
686
687 u32 event_mask;
688 u32 high_event_mask; /* Unused */
689} __packed;
690
691#define CFG_RX_FCS BIT(2)
692#define CFG_RX_ALL_GOOD BIT(3)
693#define CFG_UNI_FILTER_EN BIT(4)
694#define CFG_BSSID_FILTER_EN BIT(5)
695#define CFG_MC_FILTER_EN BIT(6)
696#define CFG_MC_ADDR0_EN BIT(7)
697#define CFG_MC_ADDR1_EN BIT(8)
698#define CFG_BC_REJECT_EN BIT(9)
699#define CFG_SSID_FILTER_EN BIT(10)
700#define CFG_RX_INT_FCS_ERROR BIT(11)
701#define CFG_RX_INT_ENCRYPTED BIT(12)
702#define CFG_RX_WR_RX_STATUS BIT(13)
703#define CFG_RX_FILTER_NULTI BIT(14)
704#define CFG_RX_RESERVE BIT(15)
705#define CFG_RX_TIMESTAMP_TSF BIT(16)
706
707#define CFG_RX_RSV_EN BIT(0)
708#define CFG_RX_RCTS_ACK BIT(1)
709#define CFG_RX_PRSP_EN BIT(2)
710#define CFG_RX_PREQ_EN BIT(3)
711#define CFG_RX_MGMT_EN BIT(4)
712#define CFG_RX_FCS_ERROR BIT(5)
713#define CFG_RX_DATA_EN BIT(6)
714#define CFG_RX_CTL_EN BIT(7)
715#define CFG_RX_CF_EN BIT(8)
716#define CFG_RX_BCN_EN BIT(9)
717#define CFG_RX_AUTH_EN BIT(10)
718#define CFG_RX_ASSOC_EN BIT(11)
719
720#define SCAN_PASSIVE BIT(0)
721#define SCAN_5GHZ_BAND BIT(1)
722#define SCAN_TRIGGERED BIT(2)
723#define SCAN_PRIORITY_HIGH BIT(3)
724
725struct acx_fw_gen_frame_rates {
726 struct acx_header header;
727
728 u8 tx_ctrl_frame_rate; /* RATE_* */
729 u8 tx_ctrl_frame_mod; /* CCK_* or PBCC_* */
730 u8 tx_mgt_frame_rate;
731 u8 tx_mgt_frame_mod;
732} __packed;
733
734/* STA MAC */
735struct acx_dot11_station_id {
736 struct acx_header header;
737
738 u8 mac[ETH_ALEN];
739 u8 pad[2];
740} __packed;
741
742struct acx_feature_config {
743 struct acx_header header;
744
745 u32 options;
746 u32 data_flow_options;
747} __packed;
748
749struct acx_current_tx_power {
750 struct acx_header header;
751
752 u8 current_tx_power;
753 u8 padding[3];
754} __packed;
755
756struct acx_dot11_default_key {
757 struct acx_header header;
758
759 u8 id;
760 u8 pad[3];
761} __packed;
762
763struct acx_tsf_info {
764 struct acx_header header;
765
766 u32 current_tsf_msb;
767 u32 current_tsf_lsb;
768 u32 last_TBTT_msb;
769 u32 last_TBTT_lsb;
770 u8 last_dtim_count;
771 u8 pad[3];
772} __packed;
773
774enum acx_wake_up_event {
775 WAKE_UP_EVENT_BEACON_BITMAP = 0x01, /* Wake on every Beacon*/
776 WAKE_UP_EVENT_DTIM_BITMAP = 0x02, /* Wake on every DTIM*/
777 WAKE_UP_EVENT_N_DTIM_BITMAP = 0x04, /* Wake on every Nth DTIM */
778 WAKE_UP_EVENT_N_BEACONS_BITMAP = 0x08, /* Wake on every Nth Beacon */
779 WAKE_UP_EVENT_BITS_MASK = 0x0F
780};
781
782struct acx_wake_up_condition {
783 struct acx_header header;
784
785 u8 wake_up_event; /* Only one bit can be set */
786 u8 listen_interval;
787 u8 pad[2];
788} __packed;
789
790struct acx_aid {
791 struct acx_header header;
792
793 /*
794 * To be set when associated with an AP.
795 */
796 u16 aid;
797 u8 pad[2];
798} __packed;
799
800enum acx_preamble_type {
801 ACX_PREAMBLE_LONG = 0,
802 ACX_PREAMBLE_SHORT = 1
803};
804
805struct acx_preamble {
806 struct acx_header header;
807
808 /*
809 * When set, the WiLink transmits the frames with a short preamble and
810 * when cleared, the WiLink transmits the frames with a long preamble.
811 */
812 u8 preamble;
813 u8 padding[3];
814} __packed;
815
816enum acx_ctsprotect_type {
817 CTSPROTECT_DISABLE = 0,
818 CTSPROTECT_ENABLE = 1
819};
820
821struct acx_ctsprotect {
822 struct acx_header header;
823 u8 ctsprotect;
824 u8 padding[3];
825} __packed;
826
827struct acx_tx_statistics {
828 u32 internal_desc_overflow;
829} __packed;
830
831struct acx_rx_statistics {
832 u32 out_of_mem;
833 u32 hdr_overflow;
834 u32 hw_stuck;
835 u32 dropped;
836 u32 fcs_err;
837 u32 xfr_hint_trig;
838 u32 path_reset;
839 u32 reset_counter;
840} __packed;
841
842struct acx_dma_statistics {
843 u32 rx_requested;
844 u32 rx_errors;
845 u32 tx_requested;
846 u32 tx_errors;
847} __packed;
848
849struct acx_isr_statistics {
850 /* host command complete */
851 u32 cmd_cmplt;
852
853 /* fiqisr() */
854 u32 fiqs;
855
856 /* (INT_STS_ND & INT_TRIG_RX_HEADER) */
857 u32 rx_headers;
858
859 /* (INT_STS_ND & INT_TRIG_RX_CMPLT) */
860 u32 rx_completes;
861
862 /* (INT_STS_ND & INT_TRIG_NO_RX_BUF) */
863 u32 rx_mem_overflow;
864
865 /* (INT_STS_ND & INT_TRIG_S_RX_RDY) */
866 u32 rx_rdys;
867
868 /* irqisr() */
869 u32 irqs;
870
871 /* (INT_STS_ND & INT_TRIG_TX_PROC) */
872 u32 tx_procs;
873
874 /* (INT_STS_ND & INT_TRIG_DECRYPT_DONE) */
875 u32 decrypt_done;
876
877 /* (INT_STS_ND & INT_TRIG_DMA0) */
878 u32 dma0_done;
879
880 /* (INT_STS_ND & INT_TRIG_DMA1) */
881 u32 dma1_done;
882
883 /* (INT_STS_ND & INT_TRIG_TX_EXC_CMPLT) */
884 u32 tx_exch_complete;
885
886 /* (INT_STS_ND & INT_TRIG_COMMAND) */
887 u32 commands;
888
889 /* (INT_STS_ND & INT_TRIG_RX_PROC) */
890 u32 rx_procs;
891
892 /* (INT_STS_ND & INT_TRIG_PM_802) */
893 u32 hw_pm_mode_changes;
894
895 /* (INT_STS_ND & INT_TRIG_ACKNOWLEDGE) */
896 u32 host_acknowledges;
897
898 /* (INT_STS_ND & INT_TRIG_PM_PCI) */
899 u32 pci_pm;
900
901 /* (INT_STS_ND & INT_TRIG_ACM_WAKEUP) */
902 u32 wakeups;
903
904 /* (INT_STS_ND & INT_TRIG_LOW_RSSI) */
905 u32 low_rssi;
906} __packed;
907
908struct acx_wep_statistics {
909 /* WEP address keys configured */
910 u32 addr_key_count;
911
912 /* default keys configured */
913 u32 default_key_count;
914
915 u32 reserved;
916
917 /* number of times that WEP key not found on lookup */
918 u32 key_not_found;
919
920 /* number of times that WEP key decryption failed */
921 u32 decrypt_fail;
922
923 /* WEP packets decrypted */
924 u32 packets;
925
926 /* WEP decrypt interrupts */
927 u32 interrupt;
928} __packed;
929
930#define ACX_MISSED_BEACONS_SPREAD 10
931
932struct acx_pwr_statistics {
933 /* the amount of enters into power save mode (both PD & ELP) */
934 u32 ps_enter;
935
936 /* the amount of enters into ELP mode */
937 u32 elp_enter;
938
939 /* the amount of missing beacon interrupts to the host */
940 u32 missing_bcns;
941
942 /* the amount of wake on host-access times */
943 u32 wake_on_host;
944
945 /* the amount of wake on timer-expire */
946 u32 wake_on_timer_exp;
947
948 /* the number of packets that were transmitted with PS bit set */
949 u32 tx_with_ps;
950
951 /* the number of packets that were transmitted with PS bit clear */
952 u32 tx_without_ps;
953
954 /* the number of received beacons */
955 u32 rcvd_beacons;
956
957 /* the number of entering into PowerOn (power save off) */
958 u32 power_save_off;
959
960 /* the number of entries into power save mode */
961 u16 enable_ps;
962
963 /*
964 * the number of exits from power save, not including failed PS
965 * transitions
966 */
967 u16 disable_ps;
968
969 /*
970 * the number of times the TSF counter was adjusted because
971 * of drift
972 */
973 u32 fix_tsf_ps;
974
975 /* Gives statistics about the spread continuous missed beacons.
976 * The 16 LSB are dedicated for the PS mode.
977 * The 16 MSB are dedicated for the PS mode.
978 * cont_miss_bcns_spread[0] - single missed beacon.
979 * cont_miss_bcns_spread[1] - two continuous missed beacons.
980 * cont_miss_bcns_spread[2] - three continuous missed beacons.
981 * ...
982 * cont_miss_bcns_spread[9] - ten and more continuous missed beacons.
983 */
984 u32 cont_miss_bcns_spread[ACX_MISSED_BEACONS_SPREAD];
985
986 /* the number of beacons in awake mode */
987 u32 rcvd_awake_beacons;
988} __packed;
989
990struct acx_mic_statistics {
991 u32 rx_pkts;
992 u32 calc_failure;
993} __packed;
994
995struct acx_aes_statistics {
996 u32 encrypt_fail;
997 u32 decrypt_fail;
998 u32 encrypt_packets;
999 u32 decrypt_packets;
1000 u32 encrypt_interrupt;
1001 u32 decrypt_interrupt;
1002} __packed;
1003
1004struct acx_event_statistics {
1005 u32 heart_beat;
1006 u32 calibration;
1007 u32 rx_mismatch;
1008 u32 rx_mem_empty;
1009 u32 rx_pool;
1010 u32 oom_late;
1011 u32 phy_transmit_error;
1012 u32 tx_stuck;
1013} __packed;
1014
1015struct acx_ps_statistics {
1016 u32 pspoll_timeouts;
1017 u32 upsd_timeouts;
1018 u32 upsd_max_sptime;
1019 u32 upsd_max_apturn;
1020 u32 pspoll_max_apturn;
1021 u32 pspoll_utilization;
1022 u32 upsd_utilization;
1023} __packed;
1024
1025struct acx_rxpipe_statistics {
1026 u32 rx_prep_beacon_drop;
1027 u32 descr_host_int_trig_rx_data;
1028 u32 beacon_buffer_thres_host_int_trig_rx_data;
1029 u32 missed_beacon_host_int_trig_rx_data;
1030 u32 tx_xfr_host_int_trig_rx_data;
1031} __packed;
1032
1033struct acx_statistics {
1034 struct acx_header header;
1035
1036 struct acx_tx_statistics tx;
1037 struct acx_rx_statistics rx;
1038 struct acx_dma_statistics dma;
1039 struct acx_isr_statistics isr;
1040 struct acx_wep_statistics wep;
1041 struct acx_pwr_statistics pwr;
1042 struct acx_aes_statistics aes;
1043 struct acx_mic_statistics mic;
1044 struct acx_event_statistics event;
1045 struct acx_ps_statistics ps;
1046 struct acx_rxpipe_statistics rxpipe;
1047} __packed;
1048
1049#define ACX_MAX_RATE_CLASSES 8
1050#define ACX_RATE_MASK_UNSPECIFIED 0
1051#define ACX_RATE_RETRY_LIMIT 10
1052
1053struct acx_rate_class {
1054 u32 enabled_rates;
1055 u8 short_retry_limit;
1056 u8 long_retry_limit;
1057 u8 aflags;
1058 u8 reserved;
1059};
1060
1061struct acx_rate_policy {
1062 struct acx_header header;
1063
1064 u32 rate_class_cnt;
1065 struct acx_rate_class rate_class[ACX_MAX_RATE_CLASSES];
1066} __packed;
1067
1068struct wl1251_acx_memory {
1069 __le16 num_stations; /* number of STAs to be supported. */
1070 u16 reserved_1;
1071
1072 /*
1073 * Nmber of memory buffers for the RX mem pool.
1074 * The actual number may be less if there are
1075 * not enough blocks left for the minimum num
1076 * of TX ones.
1077 */
1078 u8 rx_mem_block_num;
1079 u8 reserved_2;
1080 u8 num_tx_queues; /* From 1 to 16 */
1081 u8 host_if_options; /* HOST_IF* */
1082 u8 tx_min_mem_block_num;
1083 u8 num_ssid_profiles;
1084 __le16 debug_buffer_size;
1085} __packed;
1086
1087
1088#define ACX_RX_DESC_MIN 1
1089#define ACX_RX_DESC_MAX 127
1090#define ACX_RX_DESC_DEF 32
1091struct wl1251_acx_rx_queue_config {
1092 u8 num_descs;
1093 u8 pad;
1094 u8 type;
1095 u8 priority;
1096 __le32 dma_address;
1097} __packed;
1098
1099#define ACX_TX_DESC_MIN 1
1100#define ACX_TX_DESC_MAX 127
1101#define ACX_TX_DESC_DEF 16
1102struct wl1251_acx_tx_queue_config {
1103 u8 num_descs;
1104 u8 pad[2];
1105 u8 attributes;
1106} __packed;
1107
1108#define MAX_TX_QUEUE_CONFIGS 5
1109#define MAX_TX_QUEUES 4
1110struct wl1251_acx_config_memory {
1111 struct acx_header header;
1112
1113 struct wl1251_acx_memory mem_config;
1114 struct wl1251_acx_rx_queue_config rx_queue_config;
1115 struct wl1251_acx_tx_queue_config tx_queue_config[MAX_TX_QUEUE_CONFIGS];
1116} __packed;
1117
1118struct wl1251_acx_mem_map {
1119 struct acx_header header;
1120
1121 void *code_start;
1122 void *code_end;
1123
1124 void *wep_defkey_start;
1125 void *wep_defkey_end;
1126
1127 void *sta_table_start;
1128 void *sta_table_end;
1129
1130 void *packet_template_start;
1131 void *packet_template_end;
1132
1133 void *queue_memory_start;
1134 void *queue_memory_end;
1135
1136 void *packet_memory_pool_start;
1137 void *packet_memory_pool_end;
1138
1139 void *debug_buffer1_start;
1140 void *debug_buffer1_end;
1141
1142 void *debug_buffer2_start;
1143 void *debug_buffer2_end;
1144
1145 /* Number of blocks FW allocated for TX packets */
1146 u32 num_tx_mem_blocks;
1147
1148 /* Number of blocks FW allocated for RX packets */
1149 u32 num_rx_mem_blocks;
1150} __packed;
1151
1152
1153struct wl1251_acx_wr_tbtt_and_dtim {
1154
1155 struct acx_header header;
1156
1157 /* Time in TUs between two consecutive beacons */
1158 u16 tbtt;
1159
1160 /*
1161 * DTIM period
1162 * For BSS: Number of TBTTs in a DTIM period (range: 1-10)
1163 * For IBSS: value shall be set to 1
1164 */
1165 u8 dtim;
1166 u8 padding;
1167} __packed;
1168
1169struct wl1251_acx_ac_cfg {
1170 struct acx_header header;
1171
1172 /*
1173 * Access Category - The TX queue's access category
1174 * (refer to AccessCategory_enum)
1175 */
1176 u8 ac;
1177
1178 /*
1179 * The contention window minimum size (in slots) for
1180 * the access class.
1181 */
1182 u8 cw_min;
1183
1184 /*
1185 * The contention window maximum size (in slots) for
1186 * the access class.
1187 */
1188 u16 cw_max;
1189
1190 /* The AIF value (in slots) for the access class. */
1191 u8 aifsn;
1192
1193 u8 reserved;
1194
1195 /* The TX Op Limit (in microseconds) for the access class. */
1196 u16 txop_limit;
1197} __packed;
1198
1199
1200enum wl1251_acx_channel_type {
1201 CHANNEL_TYPE_DCF = 0,
1202 CHANNEL_TYPE_EDCF = 1,
1203 CHANNEL_TYPE_HCCA = 2,
1204};
1205
1206enum wl1251_acx_ps_scheme {
1207 /* regular ps: simple sending of packets */
1208 WL1251_ACX_PS_SCHEME_LEGACY = 0,
1209
1210 /* sending a packet triggers a unscheduled apsd downstream */
1211 WL1251_ACX_PS_SCHEME_UPSD_TRIGGER = 1,
1212
1213 /* a pspoll packet will be sent before every data packet */
1214 WL1251_ACX_PS_SCHEME_LEGACY_PSPOLL = 2,
1215
1216 /* scheduled apsd mode */
1217 WL1251_ACX_PS_SCHEME_SAPSD = 3,
1218};
1219
1220enum wl1251_acx_ack_policy {
1221 WL1251_ACX_ACK_POLICY_LEGACY = 0,
1222 WL1251_ACX_ACK_POLICY_NO_ACK = 1,
1223 WL1251_ACX_ACK_POLICY_BLOCK = 2,
1224};
1225
1226struct wl1251_acx_tid_cfg {
1227 struct acx_header header;
1228
1229 /* tx queue id number (0-7) */
1230 u8 queue;
1231
1232 /* channel access type for the queue, enum wl1251_acx_channel_type */
1233 u8 type;
1234
1235 /* EDCA: ac index (0-3), HCCA: traffic stream id (8-15) */
1236 u8 tsid;
1237
1238 /* ps scheme of the specified queue, enum wl1251_acx_ps_scheme */
1239 u8 ps_scheme;
1240
1241 /* the tx queue ack policy, enum wl1251_acx_ack_policy */
1242 u8 ack_policy;
1243
1244 u8 padding[3];
1245
1246 /* not supported */
1247 u32 apsdconf[2];
1248} __packed;
1249
1250/*************************************************************************
1251
1252 Host Interrupt Register (WiLink -> Host)
1253
1254**************************************************************************/
1255
1256/* RX packet is ready in Xfer buffer #0 */
1257#define WL1251_ACX_INTR_RX0_DATA BIT(0)
1258
1259/* TX result(s) are in the TX complete buffer */
1260#define WL1251_ACX_INTR_TX_RESULT BIT(1)
1261
1262/* OBSOLETE */
1263#define WL1251_ACX_INTR_TX_XFR BIT(2)
1264
1265/* RX packet is ready in Xfer buffer #1 */
1266#define WL1251_ACX_INTR_RX1_DATA BIT(3)
1267
1268/* Event was entered to Event MBOX #A */
1269#define WL1251_ACX_INTR_EVENT_A BIT(4)
1270
1271/* Event was entered to Event MBOX #B */
1272#define WL1251_ACX_INTR_EVENT_B BIT(5)
1273
1274/* OBSOLETE */
1275#define WL1251_ACX_INTR_WAKE_ON_HOST BIT(6)
1276
1277/* Trace meassge on MBOX #A */
1278#define WL1251_ACX_INTR_TRACE_A BIT(7)
1279
1280/* Trace meassge on MBOX #B */
1281#define WL1251_ACX_INTR_TRACE_B BIT(8)
1282
1283/* Command processing completion */
1284#define WL1251_ACX_INTR_CMD_COMPLETE BIT(9)
1285
1286/* Init sequence is done */
1287#define WL1251_ACX_INTR_INIT_COMPLETE BIT(14)
1288
1289#define WL1251_ACX_INTR_ALL 0xFFFFFFFF
1290
1291enum {
1292 ACX_WAKE_UP_CONDITIONS = 0x0002,
1293 ACX_MEM_CFG = 0x0003,
1294 ACX_SLOT = 0x0004,
1295 ACX_QUEUE_HEAD = 0x0005, /* for MASTER mode only */
1296 ACX_AC_CFG = 0x0007,
1297 ACX_MEM_MAP = 0x0008,
1298 ACX_AID = 0x000A,
1299 ACX_RADIO_PARAM = 0x000B, /* Not used */
1300 ACX_CFG = 0x000C, /* Not used */
1301 ACX_FW_REV = 0x000D,
1302 ACX_MEDIUM_USAGE = 0x000F,
1303 ACX_RX_CFG = 0x0010,
1304 ACX_TX_QUEUE_CFG = 0x0011, /* FIXME: only used by wl1251 */
1305 ACX_BSS_IN_PS = 0x0012, /* for AP only */
1306 ACX_STATISTICS = 0x0013, /* Debug API */
1307 ACX_FEATURE_CFG = 0x0015,
1308 ACX_MISC_CFG = 0x0017, /* Not used */
1309 ACX_TID_CFG = 0x001A,
1310 ACX_BEACON_FILTER_OPT = 0x001F,
1311 ACX_LOW_RSSI = 0x0020,
1312 ACX_NOISE_HIST = 0x0021,
1313 ACX_HDK_VERSION = 0x0022, /* ??? */
1314 ACX_PD_THRESHOLD = 0x0023,
1315 ACX_DATA_PATH_PARAMS = 0x0024, /* WO */
1316 ACX_DATA_PATH_RESP_PARAMS = 0x0024, /* RO */
1317 ACX_CCA_THRESHOLD = 0x0025,
1318 ACX_EVENT_MBOX_MASK = 0x0026,
1319#ifdef FW_RUNNING_AS_AP
1320 ACX_DTIM_PERIOD = 0x0027, /* for AP only */
1321#else
1322 ACX_WR_TBTT_AND_DTIM = 0x0027, /* STA only */
1323#endif
1324 ACX_ACI_OPTION_CFG = 0x0029, /* OBSOLETE (for 1251)*/
1325 ACX_GPIO_CFG = 0x002A, /* Not used */
1326 ACX_GPIO_SET = 0x002B, /* Not used */
1327 ACX_PM_CFG = 0x002C, /* To Be Documented */
1328 ACX_CONN_MONIT_PARAMS = 0x002D,
1329 ACX_AVERAGE_RSSI = 0x002E, /* Not used */
1330 ACX_CONS_TX_FAILURE = 0x002F,
1331 ACX_BCN_DTIM_OPTIONS = 0x0031,
1332 ACX_SG_ENABLE = 0x0032,
1333 ACX_SG_CFG = 0x0033,
1334 ACX_ANTENNA_DIVERSITY_CFG = 0x0035, /* To Be Documented */
1335 ACX_LOW_SNR = 0x0037, /* To Be Documented */
1336 ACX_BEACON_FILTER_TABLE = 0x0038,
1337 ACX_ARP_IP_FILTER = 0x0039,
1338 ACX_ROAMING_STATISTICS_TBL = 0x003B,
1339 ACX_RATE_POLICY = 0x003D,
1340 ACX_CTS_PROTECTION = 0x003E,
1341 ACX_SLEEP_AUTH = 0x003F,
1342 ACX_PREAMBLE_TYPE = 0x0040,
1343 ACX_ERROR_CNT = 0x0041,
1344 ACX_FW_GEN_FRAME_RATES = 0x0042,
1345 ACX_IBSS_FILTER = 0x0044,
1346 ACX_SERVICE_PERIOD_TIMEOUT = 0x0045,
1347 ACX_TSF_INFO = 0x0046,
1348 ACX_CONFIG_PS_WMM = 0x0049,
1349 ACX_ENABLE_RX_DATA_FILTER = 0x004A,
1350 ACX_SET_RX_DATA_FILTER = 0x004B,
1351 ACX_GET_DATA_FILTER_STATISTICS = 0x004C,
1352 ACX_POWER_LEVEL_TABLE = 0x004D,
1353 ACX_BET_ENABLE = 0x0050,
1354 DOT11_STATION_ID = 0x1001,
1355 DOT11_RX_MSDU_LIFE_TIME = 0x1004,
1356 DOT11_CUR_TX_PWR = 0x100D,
1357 DOT11_DEFAULT_KEY = 0x1010,
1358 DOT11_RX_DOT11_MODE = 0x1012,
1359 DOT11_RTS_THRESHOLD = 0x1013,
1360 DOT11_GROUP_ADDRESS_TBL = 0x1014,
1361
1362 MAX_DOT11_IE = DOT11_GROUP_ADDRESS_TBL,
1363
1364 MAX_IE = 0xFFFF
1365};
1366
1367
1368int wl1251_acx_frame_rates(struct wl1251 *wl, u8 ctrl_rate, u8 ctrl_mod,
1369 u8 mgt_rate, u8 mgt_mod);
1370int wl1251_acx_station_id(struct wl1251 *wl);
1371int wl1251_acx_default_key(struct wl1251 *wl, u8 key_id);
1372int wl1251_acx_wake_up_conditions(struct wl1251 *wl, u8 wake_up_event,
1373 u8 listen_interval);
1374int wl1251_acx_sleep_auth(struct wl1251 *wl, u8 sleep_auth);
1375int wl1251_acx_fw_version(struct wl1251 *wl, char *buf, size_t len);
1376int wl1251_acx_tx_power(struct wl1251 *wl, int power);
1377int wl1251_acx_feature_cfg(struct wl1251 *wl);
1378int wl1251_acx_mem_map(struct wl1251 *wl,
1379 struct acx_header *mem_map, size_t len);
1380int wl1251_acx_data_path_params(struct wl1251 *wl,
1381 struct acx_data_path_params_resp *data_path);
1382int wl1251_acx_rx_msdu_life_time(struct wl1251 *wl, u32 life_time);
1383int wl1251_acx_rx_config(struct wl1251 *wl, u32 config, u32 filter);
1384int wl1251_acx_pd_threshold(struct wl1251 *wl);
1385int wl1251_acx_slot(struct wl1251 *wl, enum acx_slot_type slot_time);
1386int wl1251_acx_group_address_tbl(struct wl1251 *wl);
1387int wl1251_acx_service_period_timeout(struct wl1251 *wl);
1388int wl1251_acx_rts_threshold(struct wl1251 *wl, u16 rts_threshold);
1389int wl1251_acx_beacon_filter_opt(struct wl1251 *wl, bool enable_filter);
1390int wl1251_acx_beacon_filter_table(struct wl1251 *wl);
1391int wl1251_acx_conn_monit_params(struct wl1251 *wl);
1392int wl1251_acx_sg_enable(struct wl1251 *wl);
1393int wl1251_acx_sg_cfg(struct wl1251 *wl);
1394int wl1251_acx_cca_threshold(struct wl1251 *wl);
1395int wl1251_acx_bcn_dtim_options(struct wl1251 *wl);
1396int wl1251_acx_aid(struct wl1251 *wl, u16 aid);
1397int wl1251_acx_event_mbox_mask(struct wl1251 *wl, u32 event_mask);
1398int wl1251_acx_set_preamble(struct wl1251 *wl, enum acx_preamble_type preamble);
1399int wl1251_acx_cts_protect(struct wl1251 *wl,
1400 enum acx_ctsprotect_type ctsprotect);
1401int wl1251_acx_statistics(struct wl1251 *wl, struct acx_statistics *stats);
1402int wl1251_acx_tsf_info(struct wl1251 *wl, u64 *mactime);
1403int wl1251_acx_rate_policies(struct wl1251 *wl);
1404int wl1251_acx_mem_cfg(struct wl1251 *wl);
1405int wl1251_acx_wr_tbtt_and_dtim(struct wl1251 *wl, u16 tbtt, u8 dtim);
1406int wl1251_acx_ac_cfg(struct wl1251 *wl, u8 ac, u8 cw_min, u16 cw_max,
1407 u8 aifs, u16 txop);
1408int wl1251_acx_tid_cfg(struct wl1251 *wl, u8 queue,
1409 enum wl1251_acx_channel_type type,
1410 u8 tsid, enum wl1251_acx_ps_scheme ps_scheme,
1411 enum wl1251_acx_ack_policy ack_policy);
1412
1413#endif /* __WL1251_ACX_H__ */
diff --git a/drivers/net/wireless/wl12xx/wl1251_boot.c b/drivers/net/wireless/wl12xx/wl1251_boot.c
deleted file mode 100644
index 65e0416be5b6..000000000000
--- a/drivers/net/wireless/wl12xx/wl1251_boot.c
+++ /dev/null
@@ -1,559 +0,0 @@
1/*
2 * This file is part of wl1251
3 *
4 * Copyright (C) 2008 Nokia Corporation
5 *
6 * Contact: Kalle Valo <kalle.valo@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include <linux/gpio.h>
25#include <linux/slab.h>
26
27#include "wl1251_reg.h"
28#include "wl1251_boot.h"
29#include "wl1251_io.h"
30#include "wl1251_spi.h"
31#include "wl1251_event.h"
32#include "wl1251_acx.h"
33
34void wl1251_boot_target_enable_interrupts(struct wl1251 *wl)
35{
36 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_MASK, ~(wl->intr_mask));
37 wl1251_reg_write32(wl, HI_CFG, HI_CFG_DEF_VAL);
38}
39
40int wl1251_boot_soft_reset(struct wl1251 *wl)
41{
42 unsigned long timeout;
43 u32 boot_data;
44
45 /* perform soft reset */
46 wl1251_reg_write32(wl, ACX_REG_SLV_SOFT_RESET, ACX_SLV_SOFT_RESET_BIT);
47
48 /* SOFT_RESET is self clearing */
49 timeout = jiffies + usecs_to_jiffies(SOFT_RESET_MAX_TIME);
50 while (1) {
51 boot_data = wl1251_reg_read32(wl, ACX_REG_SLV_SOFT_RESET);
52 wl1251_debug(DEBUG_BOOT, "soft reset bootdata 0x%x", boot_data);
53 if ((boot_data & ACX_SLV_SOFT_RESET_BIT) == 0)
54 break;
55
56 if (time_after(jiffies, timeout)) {
57 /* 1.2 check pWhalBus->uSelfClearTime if the
58 * timeout was reached */
59 wl1251_error("soft reset timeout");
60 return -1;
61 }
62
63 udelay(SOFT_RESET_STALL_TIME);
64 }
65
66 /* disable Rx/Tx */
67 wl1251_reg_write32(wl, ENABLE, 0x0);
68
69 /* disable auto calibration on start*/
70 wl1251_reg_write32(wl, SPARE_A2, 0xffff);
71
72 return 0;
73}
74
75int wl1251_boot_init_seq(struct wl1251 *wl)
76{
77 u32 scr_pad6, init_data, tmp, elp_cmd, ref_freq;
78
79 /*
80 * col #1: INTEGER_DIVIDER
81 * col #2: FRACTIONAL_DIVIDER
82 * col #3: ATTN_BB
83 * col #4: ALPHA_BB
84 * col #5: STOP_TIME_BB
85 * col #6: BB_PLL_LOOP_FILTER
86 */
87 static const u32 LUT[REF_FREQ_NUM][LUT_PARAM_NUM] = {
88
89 { 83, 87381, 0xB, 5, 0xF00, 3}, /* REF_FREQ_19_2*/
90 { 61, 141154, 0xB, 5, 0x1450, 2}, /* REF_FREQ_26_0*/
91 { 41, 174763, 0xC, 6, 0x2D00, 1}, /* REF_FREQ_38_4*/
92 { 40, 0, 0xC, 6, 0x2EE0, 1}, /* REF_FREQ_40_0*/
93 { 47, 162280, 0xC, 6, 0x2760, 1} /* REF_FREQ_33_6 */
94 };
95
96 /* read NVS params */
97 scr_pad6 = wl1251_reg_read32(wl, SCR_PAD6);
98 wl1251_debug(DEBUG_BOOT, "scr_pad6 0x%x", scr_pad6);
99
100 /* read ELP_CMD */
101 elp_cmd = wl1251_reg_read32(wl, ELP_CMD);
102 wl1251_debug(DEBUG_BOOT, "elp_cmd 0x%x", elp_cmd);
103
104 /* set the BB calibration time to be 300 usec (PLL_CAL_TIME) */
105 ref_freq = scr_pad6 & 0x000000FF;
106 wl1251_debug(DEBUG_BOOT, "ref_freq 0x%x", ref_freq);
107
108 wl1251_reg_write32(wl, PLL_CAL_TIME, 0x9);
109
110 /*
111 * PG 1.2: set the clock buffer time to be 210 usec (CLK_BUF_TIME)
112 */
113 wl1251_reg_write32(wl, CLK_BUF_TIME, 0x6);
114
115 /*
116 * set the clock detect feature to work in the restart wu procedure
117 * (ELP_CFG_MODE[14]) and Select the clock source type
118 * (ELP_CFG_MODE[13:12])
119 */
120 tmp = ((scr_pad6 & 0x0000FF00) << 4) | 0x00004000;
121 wl1251_reg_write32(wl, ELP_CFG_MODE, tmp);
122
123 /* PG 1.2: enable the BB PLL fix. Enable the PLL_LIMP_CLK_EN_CMD */
124 elp_cmd |= 0x00000040;
125 wl1251_reg_write32(wl, ELP_CMD, elp_cmd);
126
127 /* PG 1.2: Set the BB PLL stable time to be 1000usec
128 * (PLL_STABLE_TIME) */
129 wl1251_reg_write32(wl, CFG_PLL_SYNC_CNT, 0x20);
130
131 /* PG 1.2: read clock request time */
132 init_data = wl1251_reg_read32(wl, CLK_REQ_TIME);
133
134 /*
135 * PG 1.2: set the clock request time to be ref_clk_settling_time -
136 * 1ms = 4ms
137 */
138 if (init_data > 0x21)
139 tmp = init_data - 0x21;
140 else
141 tmp = 0;
142 wl1251_reg_write32(wl, CLK_REQ_TIME, tmp);
143
144 /* set BB PLL configurations in RF AFE */
145 wl1251_reg_write32(wl, 0x003058cc, 0x4B5);
146
147 /* set RF_AFE_REG_5 */
148 wl1251_reg_write32(wl, 0x003058d4, 0x50);
149
150 /* set RF_AFE_CTRL_REG_2 */
151 wl1251_reg_write32(wl, 0x00305948, 0x11c001);
152
153 /*
154 * change RF PLL and BB PLL divider for VCO clock and adjust VCO
155 * bais current(RF_AFE_REG_13)
156 */
157 wl1251_reg_write32(wl, 0x003058f4, 0x1e);
158
159 /* set BB PLL configurations */
160 tmp = LUT[ref_freq][LUT_PARAM_INTEGER_DIVIDER] | 0x00017000;
161 wl1251_reg_write32(wl, 0x00305840, tmp);
162
163 /* set fractional divider according to Appendix C-BB PLL
164 * Calculations
165 */
166 tmp = LUT[ref_freq][LUT_PARAM_FRACTIONAL_DIVIDER];
167 wl1251_reg_write32(wl, 0x00305844, tmp);
168
169 /* set the initial data for the sigma delta */
170 wl1251_reg_write32(wl, 0x00305848, 0x3039);
171
172 /*
173 * set the accumulator attenuation value, calibration loop1
174 * (alpha), calibration loop2 (beta), calibration loop3 (gamma) and
175 * the VCO gain
176 */
177 tmp = (LUT[ref_freq][LUT_PARAM_ATTN_BB] << 16) |
178 (LUT[ref_freq][LUT_PARAM_ALPHA_BB] << 12) | 0x1;
179 wl1251_reg_write32(wl, 0x00305854, tmp);
180
181 /*
182 * set the calibration stop time after holdoff time expires and set
183 * settling time HOLD_OFF_TIME_BB
184 */
185 tmp = LUT[ref_freq][LUT_PARAM_STOP_TIME_BB] | 0x000A0000;
186 wl1251_reg_write32(wl, 0x00305858, tmp);
187
188 /*
189 * set BB PLL Loop filter capacitor3- BB_C3[2:0] and set BB PLL
190 * constant leakage current to linearize PFD to 0uA -
191 * BB_ILOOPF[7:3]
192 */
193 tmp = LUT[ref_freq][LUT_PARAM_BB_PLL_LOOP_FILTER] | 0x00000030;
194 wl1251_reg_write32(wl, 0x003058f8, tmp);
195
196 /*
197 * set regulator output voltage for n divider to
198 * 1.35-BB_REFDIV[1:0], set charge pump current- BB_CPGAIN[4:2],
199 * set BB PLL Loop filter capacitor2- BB_C2[7:5], set gain of BB
200 * PLL auto-call to normal mode- BB_CALGAIN_3DB[8]
201 */
202 wl1251_reg_write32(wl, 0x003058f0, 0x29);
203
204 /* enable restart wakeup sequence (ELP_CMD[0]) */
205 wl1251_reg_write32(wl, ELP_CMD, elp_cmd | 0x1);
206
207 /* restart sequence completed */
208 udelay(2000);
209
210 return 0;
211}
212
213static void wl1251_boot_set_ecpu_ctrl(struct wl1251 *wl, u32 flag)
214{
215 u32 cpu_ctrl;
216
217 /* 10.5.0 run the firmware (I) */
218 cpu_ctrl = wl1251_reg_read32(wl, ACX_REG_ECPU_CONTROL);
219
220 /* 10.5.1 run the firmware (II) */
221 cpu_ctrl &= ~flag;
222 wl1251_reg_write32(wl, ACX_REG_ECPU_CONTROL, cpu_ctrl);
223}
224
225int wl1251_boot_run_firmware(struct wl1251 *wl)
226{
227 int loop, ret;
228 u32 chip_id, acx_intr;
229
230 wl1251_boot_set_ecpu_ctrl(wl, ECPU_CONTROL_HALT);
231
232 chip_id = wl1251_reg_read32(wl, CHIP_ID_B);
233
234 wl1251_debug(DEBUG_BOOT, "chip id after firmware boot: 0x%x", chip_id);
235
236 if (chip_id != wl->chip_id) {
237 wl1251_error("chip id doesn't match after firmware boot");
238 return -EIO;
239 }
240
241 /* wait for init to complete */
242 loop = 0;
243 while (loop++ < INIT_LOOP) {
244 udelay(INIT_LOOP_DELAY);
245 acx_intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
246
247 if (acx_intr == 0xffffffff) {
248 wl1251_error("error reading hardware complete "
249 "init indication");
250 return -EIO;
251 }
252 /* check that ACX_INTR_INIT_COMPLETE is enabled */
253 else if (acx_intr & WL1251_ACX_INTR_INIT_COMPLETE) {
254 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_ACK,
255 WL1251_ACX_INTR_INIT_COMPLETE);
256 break;
257 }
258 }
259
260 if (loop > INIT_LOOP) {
261 wl1251_error("timeout waiting for the hardware to "
262 "complete initialization");
263 return -EIO;
264 }
265
266 /* get hardware config command mail box */
267 wl->cmd_box_addr = wl1251_reg_read32(wl, REG_COMMAND_MAILBOX_PTR);
268
269 /* get hardware config event mail box */
270 wl->event_box_addr = wl1251_reg_read32(wl, REG_EVENT_MAILBOX_PTR);
271
272 /* set the working partition to its "running" mode offset */
273 wl1251_set_partition(wl, WL1251_PART_WORK_MEM_START,
274 WL1251_PART_WORK_MEM_SIZE,
275 WL1251_PART_WORK_REG_START,
276 WL1251_PART_WORK_REG_SIZE);
277
278 wl1251_debug(DEBUG_MAILBOX, "cmd_box_addr 0x%x event_box_addr 0x%x",
279 wl->cmd_box_addr, wl->event_box_addr);
280
281 wl1251_acx_fw_version(wl, wl->fw_ver, sizeof(wl->fw_ver));
282
283 /*
284 * in case of full asynchronous mode the firmware event must be
285 * ready to receive event from the command mailbox
286 */
287
288 /* enable gpio interrupts */
289 wl1251_enable_interrupts(wl);
290
291 /* Enable target's interrupts */
292 wl->intr_mask = WL1251_ACX_INTR_RX0_DATA |
293 WL1251_ACX_INTR_RX1_DATA |
294 WL1251_ACX_INTR_TX_RESULT |
295 WL1251_ACX_INTR_EVENT_A |
296 WL1251_ACX_INTR_EVENT_B |
297 WL1251_ACX_INTR_INIT_COMPLETE;
298 wl1251_boot_target_enable_interrupts(wl);
299
300 wl->event_mask = SCAN_COMPLETE_EVENT_ID | BSS_LOSE_EVENT_ID |
301 SYNCHRONIZATION_TIMEOUT_EVENT_ID |
302 ROAMING_TRIGGER_LOW_RSSI_EVENT_ID |
303 ROAMING_TRIGGER_REGAINED_RSSI_EVENT_ID |
304 REGAINED_BSS_EVENT_ID | BT_PTA_SENSE_EVENT_ID |
305 BT_PTA_PREDICTION_EVENT_ID;
306
307 ret = wl1251_event_unmask(wl);
308 if (ret < 0) {
309 wl1251_error("EVENT mask setting failed");
310 return ret;
311 }
312
313 wl1251_event_mbox_config(wl);
314
315 /* firmware startup completed */
316 return 0;
317}
318
319static int wl1251_boot_upload_firmware(struct wl1251 *wl)
320{
321 int addr, chunk_num, partition_limit;
322 size_t fw_data_len, len;
323 u8 *p, *buf;
324
325 /* whal_FwCtrl_LoadFwImageSm() */
326
327 wl1251_debug(DEBUG_BOOT, "chip id before fw upload: 0x%x",
328 wl1251_reg_read32(wl, CHIP_ID_B));
329
330 /* 10.0 check firmware length and set partition */
331 fw_data_len = (wl->fw[4] << 24) | (wl->fw[5] << 16) |
332 (wl->fw[6] << 8) | (wl->fw[7]);
333
334 wl1251_debug(DEBUG_BOOT, "fw_data_len %zu chunk_size %d", fw_data_len,
335 CHUNK_SIZE);
336
337 if ((fw_data_len % 4) != 0) {
338 wl1251_error("firmware length not multiple of four");
339 return -EIO;
340 }
341
342 buf = kmalloc(CHUNK_SIZE, GFP_KERNEL);
343 if (!buf) {
344 wl1251_error("allocation for firmware upload chunk failed");
345 return -ENOMEM;
346 }
347
348 wl1251_set_partition(wl, WL1251_PART_DOWN_MEM_START,
349 WL1251_PART_DOWN_MEM_SIZE,
350 WL1251_PART_DOWN_REG_START,
351 WL1251_PART_DOWN_REG_SIZE);
352
353 /* 10.1 set partition limit and chunk num */
354 chunk_num = 0;
355 partition_limit = WL1251_PART_DOWN_MEM_SIZE;
356
357 while (chunk_num < fw_data_len / CHUNK_SIZE) {
358 /* 10.2 update partition, if needed */
359 addr = WL1251_PART_DOWN_MEM_START +
360 (chunk_num + 2) * CHUNK_SIZE;
361 if (addr > partition_limit) {
362 addr = WL1251_PART_DOWN_MEM_START +
363 chunk_num * CHUNK_SIZE;
364 partition_limit = chunk_num * CHUNK_SIZE +
365 WL1251_PART_DOWN_MEM_SIZE;
366 wl1251_set_partition(wl,
367 addr,
368 WL1251_PART_DOWN_MEM_SIZE,
369 WL1251_PART_DOWN_REG_START,
370 WL1251_PART_DOWN_REG_SIZE);
371 }
372
373 /* 10.3 upload the chunk */
374 addr = WL1251_PART_DOWN_MEM_START + chunk_num * CHUNK_SIZE;
375 p = wl->fw + FW_HDR_SIZE + chunk_num * CHUNK_SIZE;
376 wl1251_debug(DEBUG_BOOT, "uploading fw chunk 0x%p to 0x%x",
377 p, addr);
378
379 /* need to copy the chunk for dma */
380 len = CHUNK_SIZE;
381 memcpy(buf, p, len);
382 wl1251_mem_write(wl, addr, buf, len);
383
384 chunk_num++;
385 }
386
387 /* 10.4 upload the last chunk */
388 addr = WL1251_PART_DOWN_MEM_START + chunk_num * CHUNK_SIZE;
389 p = wl->fw + FW_HDR_SIZE + chunk_num * CHUNK_SIZE;
390
391 /* need to copy the chunk for dma */
392 len = fw_data_len % CHUNK_SIZE;
393 memcpy(buf, p, len);
394
395 wl1251_debug(DEBUG_BOOT, "uploading fw last chunk (%zu B) 0x%p to 0x%x",
396 len, p, addr);
397 wl1251_mem_write(wl, addr, buf, len);
398
399 kfree(buf);
400
401 return 0;
402}
403
404static int wl1251_boot_upload_nvs(struct wl1251 *wl)
405{
406 size_t nvs_len, nvs_bytes_written, burst_len;
407 int nvs_start, i;
408 u32 dest_addr, val;
409 u8 *nvs_ptr, *nvs;
410
411 nvs = wl->nvs;
412 if (nvs == NULL)
413 return -ENODEV;
414
415 nvs_ptr = nvs;
416
417 nvs_len = wl->nvs_len;
418 nvs_start = wl->fw_len;
419
420 /*
421 * Layout before the actual NVS tables:
422 * 1 byte : burst length.
423 * 2 bytes: destination address.
424 * n bytes: data to burst copy.
425 *
426 * This is ended by a 0 length, then the NVS tables.
427 */
428
429 while (nvs_ptr[0]) {
430 burst_len = nvs_ptr[0];
431 dest_addr = (nvs_ptr[1] & 0xfe) | ((u32)(nvs_ptr[2] << 8));
432
433 /* We move our pointer to the data */
434 nvs_ptr += 3;
435
436 for (i = 0; i < burst_len; i++) {
437 val = (nvs_ptr[0] | (nvs_ptr[1] << 8)
438 | (nvs_ptr[2] << 16) | (nvs_ptr[3] << 24));
439
440 wl1251_debug(DEBUG_BOOT,
441 "nvs burst write 0x%x: 0x%x",
442 dest_addr, val);
443 wl1251_mem_write32(wl, dest_addr, val);
444
445 nvs_ptr += 4;
446 dest_addr += 4;
447 }
448 }
449
450 /*
451 * We've reached the first zero length, the first NVS table
452 * is 7 bytes further.
453 */
454 nvs_ptr += 7;
455 nvs_len -= nvs_ptr - nvs;
456 nvs_len = ALIGN(nvs_len, 4);
457
458 /* Now we must set the partition correctly */
459 wl1251_set_partition(wl, nvs_start,
460 WL1251_PART_DOWN_MEM_SIZE,
461 WL1251_PART_DOWN_REG_START,
462 WL1251_PART_DOWN_REG_SIZE);
463
464 /* And finally we upload the NVS tables */
465 nvs_bytes_written = 0;
466 while (nvs_bytes_written < nvs_len) {
467 val = (nvs_ptr[0] | (nvs_ptr[1] << 8)
468 | (nvs_ptr[2] << 16) | (nvs_ptr[3] << 24));
469
470 val = cpu_to_le32(val);
471
472 wl1251_debug(DEBUG_BOOT,
473 "nvs write table 0x%x: 0x%x",
474 nvs_start, val);
475 wl1251_mem_write32(wl, nvs_start, val);
476
477 nvs_ptr += 4;
478 nvs_bytes_written += 4;
479 nvs_start += 4;
480 }
481
482 return 0;
483}
484
485int wl1251_boot(struct wl1251 *wl)
486{
487 int ret = 0, minor_minor_e2_ver;
488 u32 tmp, boot_data;
489
490 /* halt embedded ARM CPU while loading firmware */
491 wl1251_reg_write32(wl, ACX_REG_ECPU_CONTROL, ECPU_CONTROL_HALT);
492
493 ret = wl1251_boot_soft_reset(wl);
494 if (ret < 0)
495 goto out;
496
497 /* 2. start processing NVS file */
498 if (wl->use_eeprom) {
499 wl1251_reg_write32(wl, ACX_REG_EE_START, START_EEPROM_MGR);
500 /* Wait for EEPROM NVS burst read to complete */
501 msleep(40);
502 wl1251_reg_write32(wl, ACX_EEPROMLESS_IND_REG, USE_EEPROM);
503 } else {
504 ret = wl1251_boot_upload_nvs(wl);
505 if (ret < 0)
506 goto out;
507
508 /* write firmware's last address (ie. it's length) to
509 * ACX_EEPROMLESS_IND_REG */
510 wl1251_reg_write32(wl, ACX_EEPROMLESS_IND_REG, wl->fw_len);
511 }
512
513 /* 6. read the EEPROM parameters */
514 tmp = wl1251_reg_read32(wl, SCR_PAD2);
515
516 /* 7. read bootdata */
517 wl->boot_attr.radio_type = (tmp & 0x0000FF00) >> 8;
518 wl->boot_attr.major = (tmp & 0x00FF0000) >> 16;
519 tmp = wl1251_reg_read32(wl, SCR_PAD3);
520
521 /* 8. check bootdata and call restart sequence */
522 wl->boot_attr.minor = (tmp & 0x00FF0000) >> 16;
523 minor_minor_e2_ver = (tmp & 0xFF000000) >> 24;
524
525 wl1251_debug(DEBUG_BOOT, "radioType 0x%x majorE2Ver 0x%x "
526 "minorE2Ver 0x%x minor_minor_e2_ver 0x%x",
527 wl->boot_attr.radio_type, wl->boot_attr.major,
528 wl->boot_attr.minor, minor_minor_e2_ver);
529
530 ret = wl1251_boot_init_seq(wl);
531 if (ret < 0)
532 goto out;
533
534 /* 9. NVS processing done */
535 boot_data = wl1251_reg_read32(wl, ACX_REG_ECPU_CONTROL);
536
537 wl1251_debug(DEBUG_BOOT, "halt boot_data 0x%x", boot_data);
538
539 /* 10. check that ECPU_CONTROL_HALT bits are set in
540 * pWhalBus->uBootData and start uploading firmware
541 */
542 if ((boot_data & ECPU_CONTROL_HALT) == 0) {
543 wl1251_error("boot failed, ECPU_CONTROL_HALT not set");
544 ret = -EIO;
545 goto out;
546 }
547
548 ret = wl1251_boot_upload_firmware(wl);
549 if (ret < 0)
550 goto out;
551
552 /* 10.5 start firmware */
553 ret = wl1251_boot_run_firmware(wl);
554 if (ret < 0)
555 goto out;
556
557out:
558 return ret;
559}
diff --git a/drivers/net/wireless/wl12xx/wl1251_boot.h b/drivers/net/wireless/wl12xx/wl1251_boot.h
deleted file mode 100644
index 90063697e8f2..000000000000
--- a/drivers/net/wireless/wl12xx/wl1251_boot.h
+++ /dev/null
@@ -1,41 +0,0 @@
1/*
2 * This file is part of wl1251
3 *
4 * Copyright (C) 2008 Nokia Corporation
5 *
6 * Contact: Kalle Valo <kalle.valo@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#ifndef __BOOT_H__
25#define __BOOT_H__
26
27#include "wl1251.h"
28
29int wl1251_boot_soft_reset(struct wl1251 *wl);
30int wl1251_boot_init_seq(struct wl1251 *wl);
31int wl1251_boot_run_firmware(struct wl1251 *wl);
32void wl1251_boot_target_enable_interrupts(struct wl1251 *wl);
33int wl1251_boot(struct wl1251 *wl);
34
35/* number of times we try to read the INIT interrupt */
36#define INIT_LOOP 20000
37
38/* delay between retries */
39#define INIT_LOOP_DELAY 50
40
41#endif
diff --git a/drivers/net/wireless/wl12xx/wl1251_cmd.c b/drivers/net/wireless/wl12xx/wl1251_cmd.c
deleted file mode 100644
index ce3722f4c3e3..000000000000
--- a/drivers/net/wireless/wl12xx/wl1251_cmd.c
+++ /dev/null
@@ -1,496 +0,0 @@
1#include "wl1251_cmd.h"
2
3#include <linux/module.h>
4#include <linux/slab.h>
5#include <linux/crc7.h>
6
7#include "wl1251.h"
8#include "wl1251_reg.h"
9#include "wl1251_io.h"
10#include "wl1251_ps.h"
11#include "wl1251_acx.h"
12
13/**
14 * send command to firmware
15 *
16 * @wl: wl struct
17 * @id: command id
18 * @buf: buffer containing the command, must work with dma
19 * @len: length of the buffer
20 */
21int wl1251_cmd_send(struct wl1251 *wl, u16 id, void *buf, size_t len)
22{
23 struct wl1251_cmd_header *cmd;
24 unsigned long timeout;
25 u32 intr;
26 int ret = 0;
27
28 cmd = buf;
29 cmd->id = id;
30 cmd->status = 0;
31
32 WARN_ON(len % 4 != 0);
33
34 wl1251_mem_write(wl, wl->cmd_box_addr, buf, len);
35
36 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD);
37
38 timeout = jiffies + msecs_to_jiffies(WL1251_COMMAND_TIMEOUT);
39
40 intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
41 while (!(intr & WL1251_ACX_INTR_CMD_COMPLETE)) {
42 if (time_after(jiffies, timeout)) {
43 wl1251_error("command complete timeout");
44 ret = -ETIMEDOUT;
45 goto out;
46 }
47
48 msleep(1);
49
50 intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
51 }
52
53 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_ACK,
54 WL1251_ACX_INTR_CMD_COMPLETE);
55
56out:
57 return ret;
58}
59
60/**
61 * send test command to firmware
62 *
63 * @wl: wl struct
64 * @buf: buffer containing the command, with all headers, must work with dma
65 * @len: length of the buffer
66 * @answer: is answer needed
67 */
68int wl1251_cmd_test(struct wl1251 *wl, void *buf, size_t buf_len, u8 answer)
69{
70 int ret;
71
72 wl1251_debug(DEBUG_CMD, "cmd test");
73
74 ret = wl1251_cmd_send(wl, CMD_TEST, buf, buf_len);
75
76 if (ret < 0) {
77 wl1251_warning("TEST command failed");
78 return ret;
79 }
80
81 if (answer) {
82 struct wl1251_command *cmd_answer;
83
84 /*
85 * The test command got in, we can read the answer.
86 * The answer would be a wl1251_command, where the
87 * parameter array contains the actual answer.
88 */
89 wl1251_mem_read(wl, wl->cmd_box_addr, buf, buf_len);
90
91 cmd_answer = buf;
92
93 if (cmd_answer->header.status != CMD_STATUS_SUCCESS)
94 wl1251_error("TEST command answer error: %d",
95 cmd_answer->header.status);
96 }
97
98 return 0;
99}
100
101/**
102 * read acx from firmware
103 *
104 * @wl: wl struct
105 * @id: acx id
106 * @buf: buffer for the response, including all headers, must work with dma
107 * @len: lenght of buf
108 */
109int wl1251_cmd_interrogate(struct wl1251 *wl, u16 id, void *buf, size_t len)
110{
111 struct acx_header *acx = buf;
112 int ret;
113
114 wl1251_debug(DEBUG_CMD, "cmd interrogate");
115
116 acx->id = id;
117
118 /* payload length, does not include any headers */
119 acx->len = len - sizeof(*acx);
120
121 ret = wl1251_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx));
122 if (ret < 0) {
123 wl1251_error("INTERROGATE command failed");
124 goto out;
125 }
126
127 /* the interrogate command got in, we can read the answer */
128 wl1251_mem_read(wl, wl->cmd_box_addr, buf, len);
129
130 acx = buf;
131 if (acx->cmd.status != CMD_STATUS_SUCCESS)
132 wl1251_error("INTERROGATE command error: %d",
133 acx->cmd.status);
134
135out:
136 return ret;
137}
138
139/**
140 * write acx value to firmware
141 *
142 * @wl: wl struct
143 * @id: acx id
144 * @buf: buffer containing acx, including all headers, must work with dma
145 * @len: length of buf
146 */
147int wl1251_cmd_configure(struct wl1251 *wl, u16 id, void *buf, size_t len)
148{
149 struct acx_header *acx = buf;
150 int ret;
151
152 wl1251_debug(DEBUG_CMD, "cmd configure");
153
154 acx->id = id;
155
156 /* payload length, does not include any headers */
157 acx->len = len - sizeof(*acx);
158
159 ret = wl1251_cmd_send(wl, CMD_CONFIGURE, acx, len);
160 if (ret < 0) {
161 wl1251_warning("CONFIGURE command NOK");
162 return ret;
163 }
164
165 return 0;
166}
167
168int wl1251_cmd_vbm(struct wl1251 *wl, u8 identity,
169 void *bitmap, u16 bitmap_len, u8 bitmap_control)
170{
171 struct wl1251_cmd_vbm_update *vbm;
172 int ret;
173
174 wl1251_debug(DEBUG_CMD, "cmd vbm");
175
176 vbm = kzalloc(sizeof(*vbm), GFP_KERNEL);
177 if (!vbm) {
178 ret = -ENOMEM;
179 goto out;
180 }
181
182 /* Count and period will be filled by the target */
183 vbm->tim.bitmap_ctrl = bitmap_control;
184 if (bitmap_len > PARTIAL_VBM_MAX) {
185 wl1251_warning("cmd vbm len is %d B, truncating to %d",
186 bitmap_len, PARTIAL_VBM_MAX);
187 bitmap_len = PARTIAL_VBM_MAX;
188 }
189 memcpy(vbm->tim.pvb_field, bitmap, bitmap_len);
190 vbm->tim.identity = identity;
191 vbm->tim.length = bitmap_len + 3;
192
193 vbm->len = cpu_to_le16(bitmap_len + 5);
194
195 ret = wl1251_cmd_send(wl, CMD_VBM, vbm, sizeof(*vbm));
196 if (ret < 0) {
197 wl1251_error("VBM command failed");
198 goto out;
199 }
200
201out:
202 kfree(vbm);
203 return 0;
204}
205
206int wl1251_cmd_data_path(struct wl1251 *wl, u8 channel, bool enable)
207{
208 struct cmd_enabledisable_path *cmd;
209 int ret;
210 u16 cmd_rx, cmd_tx;
211
212 wl1251_debug(DEBUG_CMD, "cmd data path");
213
214 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
215 if (!cmd) {
216 ret = -ENOMEM;
217 goto out;
218 }
219
220 cmd->channel = channel;
221
222 if (enable) {
223 cmd_rx = CMD_ENABLE_RX;
224 cmd_tx = CMD_ENABLE_TX;
225 } else {
226 cmd_rx = CMD_DISABLE_RX;
227 cmd_tx = CMD_DISABLE_TX;
228 }
229
230 ret = wl1251_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd));
231 if (ret < 0) {
232 wl1251_error("rx %s cmd for channel %d failed",
233 enable ? "start" : "stop", channel);
234 goto out;
235 }
236
237 wl1251_debug(DEBUG_BOOT, "rx %s cmd channel %d",
238 enable ? "start" : "stop", channel);
239
240 ret = wl1251_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd));
241 if (ret < 0) {
242 wl1251_error("tx %s cmd for channel %d failed",
243 enable ? "start" : "stop", channel);
244 return ret;
245 }
246
247 wl1251_debug(DEBUG_BOOT, "tx %s cmd channel %d",
248 enable ? "start" : "stop", channel);
249
250out:
251 kfree(cmd);
252 return ret;
253}
254
255int wl1251_cmd_join(struct wl1251 *wl, u8 bss_type, u8 channel,
256 u16 beacon_interval, u8 dtim_interval)
257{
258 struct cmd_join *join;
259 int ret, i;
260 u8 *bssid;
261
262 join = kzalloc(sizeof(*join), GFP_KERNEL);
263 if (!join) {
264 ret = -ENOMEM;
265 goto out;
266 }
267
268 wl1251_debug(DEBUG_CMD, "cmd join%s ch %d %d/%d",
269 bss_type == BSS_TYPE_IBSS ? " ibss" : "",
270 channel, beacon_interval, dtim_interval);
271
272 /* Reverse order BSSID */
273 bssid = (u8 *) &join->bssid_lsb;
274 for (i = 0; i < ETH_ALEN; i++)
275 bssid[i] = wl->bssid[ETH_ALEN - i - 1];
276
277 join->rx_config_options = wl->rx_config;
278 join->rx_filter_options = wl->rx_filter;
279
280 /*
281 * FIXME: disable temporarily all filters because after commit
282 * 9cef8737 "mac80211: fix managed mode BSSID handling" broke
283 * association. The filter logic needs to be implemented properly
284 * and once that is done, this hack can be removed.
285 */
286 join->rx_config_options = 0;
287 join->rx_filter_options = WL1251_DEFAULT_RX_FILTER;
288
289 join->basic_rate_set = RATE_MASK_1MBPS | RATE_MASK_2MBPS |
290 RATE_MASK_5_5MBPS | RATE_MASK_11MBPS;
291
292 join->beacon_interval = beacon_interval;
293 join->dtim_interval = dtim_interval;
294 join->bss_type = bss_type;
295 join->channel = channel;
296 join->ctrl = JOIN_CMD_CTRL_TX_FLUSH;
297
298 ret = wl1251_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join));
299 if (ret < 0) {
300 wl1251_error("failed to initiate cmd join");
301 goto out;
302 }
303
304out:
305 kfree(join);
306 return ret;
307}
308
309int wl1251_cmd_ps_mode(struct wl1251 *wl, u8 ps_mode)
310{
311 struct wl1251_cmd_ps_params *ps_params = NULL;
312 int ret = 0;
313
314 wl1251_debug(DEBUG_CMD, "cmd set ps mode");
315
316 ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
317 if (!ps_params) {
318 ret = -ENOMEM;
319 goto out;
320 }
321
322 ps_params->ps_mode = ps_mode;
323 ps_params->send_null_data = 1;
324 ps_params->retries = 5;
325 ps_params->hang_over_period = 128;
326 ps_params->null_data_rate = 1; /* 1 Mbps */
327
328 ret = wl1251_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
329 sizeof(*ps_params));
330 if (ret < 0) {
331 wl1251_error("cmd set_ps_mode failed");
332 goto out;
333 }
334
335out:
336 kfree(ps_params);
337 return ret;
338}
339
340int wl1251_cmd_read_memory(struct wl1251 *wl, u32 addr, void *answer,
341 size_t len)
342{
343 struct cmd_read_write_memory *cmd;
344 int ret = 0;
345
346 wl1251_debug(DEBUG_CMD, "cmd read memory");
347
348 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
349 if (!cmd) {
350 ret = -ENOMEM;
351 goto out;
352 }
353
354 WARN_ON(len > MAX_READ_SIZE);
355 len = min_t(size_t, len, MAX_READ_SIZE);
356
357 cmd->addr = addr;
358 cmd->size = len;
359
360 ret = wl1251_cmd_send(wl, CMD_READ_MEMORY, cmd, sizeof(*cmd));
361 if (ret < 0) {
362 wl1251_error("read memory command failed: %d", ret);
363 goto out;
364 }
365
366 /* the read command got in, we can now read the answer */
367 wl1251_mem_read(wl, wl->cmd_box_addr, cmd, sizeof(*cmd));
368
369 if (cmd->header.status != CMD_STATUS_SUCCESS)
370 wl1251_error("error in read command result: %d",
371 cmd->header.status);
372
373 memcpy(answer, cmd->value, len);
374
375out:
376 kfree(cmd);
377 return ret;
378}
379
380int wl1251_cmd_template_set(struct wl1251 *wl, u16 cmd_id,
381 void *buf, size_t buf_len)
382{
383 struct wl1251_cmd_packet_template *cmd;
384 size_t cmd_len;
385 int ret = 0;
386
387 wl1251_debug(DEBUG_CMD, "cmd template %d", cmd_id);
388
389 WARN_ON(buf_len > WL1251_MAX_TEMPLATE_SIZE);
390 buf_len = min_t(size_t, buf_len, WL1251_MAX_TEMPLATE_SIZE);
391 cmd_len = ALIGN(sizeof(*cmd) + buf_len, 4);
392
393 cmd = kzalloc(cmd_len, GFP_KERNEL);
394 if (!cmd) {
395 ret = -ENOMEM;
396 goto out;
397 }
398
399 cmd->size = cpu_to_le16(buf_len);
400
401 if (buf)
402 memcpy(cmd->data, buf, buf_len);
403
404 ret = wl1251_cmd_send(wl, cmd_id, cmd, cmd_len);
405 if (ret < 0) {
406 wl1251_warning("cmd set_template failed: %d", ret);
407 goto out;
408 }
409
410out:
411 kfree(cmd);
412 return ret;
413}
414
415int wl1251_cmd_scan(struct wl1251 *wl, u8 *ssid, size_t ssid_len,
416 struct ieee80211_channel *channels[],
417 unsigned int n_channels, unsigned int n_probes)
418{
419 struct wl1251_cmd_scan *cmd;
420 int i, ret = 0;
421
422 wl1251_debug(DEBUG_CMD, "cmd scan");
423
424 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
425 if (!cmd)
426 return -ENOMEM;
427
428 cmd->params.rx_config_options = cpu_to_le32(CFG_RX_ALL_GOOD);
429 cmd->params.rx_filter_options = cpu_to_le32(CFG_RX_PRSP_EN |
430 CFG_RX_MGMT_EN |
431 CFG_RX_BCN_EN);
432 cmd->params.scan_options = 0;
433 cmd->params.num_channels = n_channels;
434 cmd->params.num_probe_requests = n_probes;
435 cmd->params.tx_rate = cpu_to_le16(1 << 1); /* 2 Mbps */
436 cmd->params.tid_trigger = 0;
437
438 for (i = 0; i < n_channels; i++) {
439 cmd->channels[i].min_duration =
440 cpu_to_le32(WL1251_SCAN_MIN_DURATION);
441 cmd->channels[i].max_duration =
442 cpu_to_le32(WL1251_SCAN_MAX_DURATION);
443 memset(&cmd->channels[i].bssid_lsb, 0xff, 4);
444 memset(&cmd->channels[i].bssid_msb, 0xff, 2);
445 cmd->channels[i].early_termination = 0;
446 cmd->channels[i].tx_power_att = 0;
447 cmd->channels[i].channel = channels[i]->hw_value;
448 }
449
450 cmd->params.ssid_len = ssid_len;
451 if (ssid)
452 memcpy(cmd->params.ssid, ssid, ssid_len);
453
454 ret = wl1251_cmd_send(wl, CMD_SCAN, cmd, sizeof(*cmd));
455 if (ret < 0) {
456 wl1251_error("cmd scan failed: %d", ret);
457 goto out;
458 }
459
460 wl1251_mem_read(wl, wl->cmd_box_addr, cmd, sizeof(*cmd));
461
462 if (cmd->header.status != CMD_STATUS_SUCCESS) {
463 wl1251_error("cmd scan status wasn't success: %d",
464 cmd->header.status);
465 ret = -EIO;
466 goto out;
467 }
468
469out:
470 kfree(cmd);
471 return ret;
472}
473
474int wl1251_cmd_trigger_scan_to(struct wl1251 *wl, u32 timeout)
475{
476 struct wl1251_cmd_trigger_scan_to *cmd;
477 int ret;
478
479 wl1251_debug(DEBUG_CMD, "cmd trigger scan to");
480
481 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
482 if (!cmd)
483 return -ENOMEM;
484
485 cmd->timeout = timeout;
486
487 ret = wl1251_cmd_send(wl, CMD_TRIGGER_SCAN_TO, cmd, sizeof(*cmd));
488 if (ret < 0) {
489 wl1251_error("cmd trigger scan to failed: %d", ret);
490 goto out;
491 }
492
493out:
494 kfree(cmd);
495 return ret;
496}
diff --git a/drivers/net/wireless/wl12xx/wl1251_cmd.h b/drivers/net/wireless/wl12xx/wl1251_cmd.h
deleted file mode 100644
index a9e4991369be..000000000000
--- a/drivers/net/wireless/wl12xx/wl1251_cmd.h
+++ /dev/null
@@ -1,417 +0,0 @@
1/*
2 * This file is part of wl1251
3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation
6 *
7 * Contact: Kalle Valo <kalle.valo@nokia.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25#ifndef __WL1251_CMD_H__
26#define __WL1251_CMD_H__
27
28#include "wl1251.h"
29
30#include <net/cfg80211.h>
31
32struct acx_header;
33
34int wl1251_cmd_send(struct wl1251 *wl, u16 type, void *buf, size_t buf_len);
35int wl1251_cmd_test(struct wl1251 *wl, void *buf, size_t buf_len, u8 answer);
36int wl1251_cmd_interrogate(struct wl1251 *wl, u16 id, void *buf, size_t len);
37int wl1251_cmd_configure(struct wl1251 *wl, u16 id, void *buf, size_t len);
38int wl1251_cmd_vbm(struct wl1251 *wl, u8 identity,
39 void *bitmap, u16 bitmap_len, u8 bitmap_control);
40int wl1251_cmd_data_path(struct wl1251 *wl, u8 channel, bool enable);
41int wl1251_cmd_join(struct wl1251 *wl, u8 bss_type, u8 channel,
42 u16 beacon_interval, u8 dtim_interval);
43int wl1251_cmd_ps_mode(struct wl1251 *wl, u8 ps_mode);
44int wl1251_cmd_read_memory(struct wl1251 *wl, u32 addr, void *answer,
45 size_t len);
46int wl1251_cmd_template_set(struct wl1251 *wl, u16 cmd_id,
47 void *buf, size_t buf_len);
48int wl1251_cmd_scan(struct wl1251 *wl, u8 *ssid, size_t ssid_len,
49 struct ieee80211_channel *channels[],
50 unsigned int n_channels, unsigned int n_probes);
51int wl1251_cmd_trigger_scan_to(struct wl1251 *wl, u32 timeout);
52
53/* unit ms */
54#define WL1251_COMMAND_TIMEOUT 2000
55
56enum wl1251_commands {
57 CMD_RESET = 0,
58 CMD_INTERROGATE = 1, /*use this to read information elements*/
59 CMD_CONFIGURE = 2, /*use this to write information elements*/
60 CMD_ENABLE_RX = 3,
61 CMD_ENABLE_TX = 4,
62 CMD_DISABLE_RX = 5,
63 CMD_DISABLE_TX = 6,
64 CMD_SCAN = 8,
65 CMD_STOP_SCAN = 9,
66 CMD_VBM = 10,
67 CMD_START_JOIN = 11,
68 CMD_SET_KEYS = 12,
69 CMD_READ_MEMORY = 13,
70 CMD_WRITE_MEMORY = 14,
71 CMD_BEACON = 19,
72 CMD_PROBE_RESP = 20,
73 CMD_NULL_DATA = 21,
74 CMD_PROBE_REQ = 22,
75 CMD_TEST = 23,
76 CMD_RADIO_CALIBRATE = 25, /* OBSOLETE */
77 CMD_ENABLE_RX_PATH = 27, /* OBSOLETE */
78 CMD_NOISE_HIST = 28,
79 CMD_RX_RESET = 29,
80 CMD_PS_POLL = 30,
81 CMD_QOS_NULL_DATA = 31,
82 CMD_LNA_CONTROL = 32,
83 CMD_SET_BCN_MODE = 33,
84 CMD_MEASUREMENT = 34,
85 CMD_STOP_MEASUREMENT = 35,
86 CMD_DISCONNECT = 36,
87 CMD_SET_PS_MODE = 37,
88 CMD_CHANNEL_SWITCH = 38,
89 CMD_STOP_CHANNEL_SWICTH = 39,
90 CMD_AP_DISCOVERY = 40,
91 CMD_STOP_AP_DISCOVERY = 41,
92 CMD_SPS_SCAN = 42,
93 CMD_STOP_SPS_SCAN = 43,
94 CMD_HEALTH_CHECK = 45,
95 CMD_DEBUG = 46,
96 CMD_TRIGGER_SCAN_TO = 47,
97
98 NUM_COMMANDS,
99 MAX_COMMAND_ID = 0xFFFF,
100};
101
102#define MAX_CMD_PARAMS 572
103
104struct wl1251_cmd_header {
105 u16 id;
106 u16 status;
107 /* payload */
108 u8 data[0];
109} __packed;
110
111struct wl1251_command {
112 struct wl1251_cmd_header header;
113 u8 parameters[MAX_CMD_PARAMS];
114};
115
116enum {
117 CMD_MAILBOX_IDLE = 0,
118 CMD_STATUS_SUCCESS = 1,
119 CMD_STATUS_UNKNOWN_CMD = 2,
120 CMD_STATUS_UNKNOWN_IE = 3,
121 CMD_STATUS_REJECT_MEAS_SG_ACTIVE = 11,
122 CMD_STATUS_RX_BUSY = 13,
123 CMD_STATUS_INVALID_PARAM = 14,
124 CMD_STATUS_TEMPLATE_TOO_LARGE = 15,
125 CMD_STATUS_OUT_OF_MEMORY = 16,
126 CMD_STATUS_STA_TABLE_FULL = 17,
127 CMD_STATUS_RADIO_ERROR = 18,
128 CMD_STATUS_WRONG_NESTING = 19,
129 CMD_STATUS_TIMEOUT = 21, /* Driver internal use.*/
130 CMD_STATUS_FW_RESET = 22, /* Driver internal use.*/
131 MAX_COMMAND_STATUS = 0xff
132};
133
134
135/*
136 * CMD_READ_MEMORY
137 *
138 * The host issues this command to read the WiLink device memory/registers.
139 *
140 * Note: The Base Band address has special handling (16 bits registers and
141 * addresses). For more information, see the hardware specification.
142 */
143/*
144 * CMD_WRITE_MEMORY
145 *
146 * The host issues this command to write the WiLink device memory/registers.
147 *
148 * The Base Band address has special handling (16 bits registers and
149 * addresses). For more information, see the hardware specification.
150 */
151#define MAX_READ_SIZE 256
152
153struct cmd_read_write_memory {
154 struct wl1251_cmd_header header;
155
156 /* The address of the memory to read from or write to.*/
157 u32 addr;
158
159 /* The amount of data in bytes to read from or write to the WiLink
160 * device.*/
161 u32 size;
162
163 /* The actual value read from or written to the Wilink. The source
164 of this field is the Host in WRITE command or the Wilink in READ
165 command. */
166 u8 value[MAX_READ_SIZE];
167};
168
169#define CMDMBOX_HEADER_LEN 4
170#define CMDMBOX_INFO_ELEM_HEADER_LEN 4
171
172#define WL1251_SCAN_MIN_DURATION 30000
173#define WL1251_SCAN_MAX_DURATION 60000
174
175#define WL1251_SCAN_NUM_PROBES 3
176
177struct wl1251_scan_parameters {
178 __le32 rx_config_options;
179 __le32 rx_filter_options;
180
181 /*
182 * Scan options:
183 * bit 0: When this bit is set, passive scan.
184 * bit 1: Band, when this bit is set we scan
185 * in the 5Ghz band.
186 * bit 2: voice mode, 0 for normal scan.
187 * bit 3: scan priority, 1 for high priority.
188 */
189 __le16 scan_options;
190
191 /* Number of channels to scan */
192 u8 num_channels;
193
194 /* Number opf probe requests to send, per channel */
195 u8 num_probe_requests;
196
197 /* Rate and modulation for probe requests */
198 __le16 tx_rate;
199
200 u8 tid_trigger;
201 u8 ssid_len;
202 u8 ssid[32];
203
204} __packed;
205
206struct wl1251_scan_ch_parameters {
207 __le32 min_duration; /* in TU */
208 __le32 max_duration; /* in TU */
209 u32 bssid_lsb;
210 u16 bssid_msb;
211
212 /*
213 * bits 0-3: Early termination count.
214 * bits 4-5: Early termination condition.
215 */
216 u8 early_termination;
217
218 u8 tx_power_att;
219 u8 channel;
220 u8 pad[3];
221} __packed;
222
223/* SCAN parameters */
224#define SCAN_MAX_NUM_OF_CHANNELS 16
225
226struct wl1251_cmd_scan {
227 struct wl1251_cmd_header header;
228
229 struct wl1251_scan_parameters params;
230 struct wl1251_scan_ch_parameters channels[SCAN_MAX_NUM_OF_CHANNELS];
231} __packed;
232
233enum {
234 BSS_TYPE_IBSS = 0,
235 BSS_TYPE_STA_BSS = 2,
236 BSS_TYPE_AP_BSS = 3,
237 MAX_BSS_TYPE = 0xFF
238};
239
240#define JOIN_CMD_CTRL_TX_FLUSH 0x80 /* Firmware flushes all Tx */
241#define JOIN_CMD_CTRL_EARLY_WAKEUP_ENABLE 0x01 /* Early wakeup time */
242
243
244struct cmd_join {
245 struct wl1251_cmd_header header;
246
247 u32 bssid_lsb;
248 u16 bssid_msb;
249 u16 beacon_interval; /* in TBTTs */
250 u32 rx_config_options;
251 u32 rx_filter_options;
252
253 /*
254 * The target uses this field to determine the rate at
255 * which to transmit control frame responses (such as
256 * ACK or CTS frames).
257 */
258 u16 basic_rate_set;
259 u8 dtim_interval;
260 u8 tx_ctrl_frame_rate; /* OBSOLETE */
261 u8 tx_ctrl_frame_mod; /* OBSOLETE */
262 /*
263 * bits 0-2: This bitwise field specifies the type
264 * of BSS to start or join (BSS_TYPE_*).
265 * bit 4: Band - The radio band in which to join
266 * or start.
267 * 0 - 2.4GHz band
268 * 1 - 5GHz band
269 * bits 3, 5-7: Reserved
270 */
271 u8 bss_type;
272 u8 channel;
273 u8 ssid_len;
274 u8 ssid[IW_ESSID_MAX_SIZE];
275 u8 ctrl; /* JOIN_CMD_CTRL_* */
276 u8 tx_mgt_frame_rate; /* OBSOLETE */
277 u8 tx_mgt_frame_mod; /* OBSOLETE */
278 u8 reserved;
279} __packed;
280
281struct cmd_enabledisable_path {
282 struct wl1251_cmd_header header;
283
284 u8 channel;
285 u8 padding[3];
286} __packed;
287
288#define WL1251_MAX_TEMPLATE_SIZE 300
289
290struct wl1251_cmd_packet_template {
291 struct wl1251_cmd_header header;
292
293 __le16 size;
294 u8 data[0];
295} __packed;
296
297#define TIM_ELE_ID 5
298#define PARTIAL_VBM_MAX 251
299
300struct wl1251_tim {
301 u8 identity;
302 u8 length;
303 u8 dtim_count;
304 u8 dtim_period;
305 u8 bitmap_ctrl;
306 u8 pvb_field[PARTIAL_VBM_MAX]; /* Partial Virtual Bitmap */
307} __packed;
308
309/* Virtual Bit Map update */
310struct wl1251_cmd_vbm_update {
311 struct wl1251_cmd_header header;
312 __le16 len;
313 u8 padding[2];
314 struct wl1251_tim tim;
315} __packed;
316
317enum wl1251_cmd_ps_mode {
318 STATION_ACTIVE_MODE,
319 STATION_POWER_SAVE_MODE
320};
321
322struct wl1251_cmd_ps_params {
323 struct wl1251_cmd_header header;
324
325 u8 ps_mode; /* STATION_* */
326 u8 send_null_data; /* Do we have to send NULL data packet ? */
327 u8 retries; /* Number of retires for the initial NULL data packet */
328
329 /*
330 * TUs during which the target stays awake after switching
331 * to power save mode.
332 */
333 u8 hang_over_period;
334 u16 null_data_rate;
335 u8 pad[2];
336} __packed;
337
338struct wl1251_cmd_trigger_scan_to {
339 struct wl1251_cmd_header header;
340
341 u32 timeout;
342};
343
344/* HW encryption keys */
345#define NUM_ACCESS_CATEGORIES_COPY 4
346#define MAX_KEY_SIZE 32
347
348/* When set, disable HW encryption */
349#define DF_ENCRYPTION_DISABLE 0x01
350/* When set, disable HW decryption */
351#define DF_SNIFF_MODE_ENABLE 0x80
352
353enum wl1251_cmd_key_action {
354 KEY_ADD_OR_REPLACE = 1,
355 KEY_REMOVE = 2,
356 KEY_SET_ID = 3,
357 MAX_KEY_ACTION = 0xffff,
358};
359
360enum wl1251_cmd_key_type {
361 KEY_WEP_DEFAULT = 0,
362 KEY_WEP_ADDR = 1,
363 KEY_AES_GROUP = 4,
364 KEY_AES_PAIRWISE = 5,
365 KEY_WEP_GROUP = 6,
366 KEY_TKIP_MIC_GROUP = 10,
367 KEY_TKIP_MIC_PAIRWISE = 11,
368};
369
370/*
371 *
372 * key_type_e key size key format
373 * ---------- --------- ----------
374 * 0x00 5, 13, 29 Key data
375 * 0x01 5, 13, 29 Key data
376 * 0x04 16 16 bytes of key data
377 * 0x05 16 16 bytes of key data
378 * 0x0a 32 16 bytes of TKIP key data
379 * 8 bytes of RX MIC key data
380 * 8 bytes of TX MIC key data
381 * 0x0b 32 16 bytes of TKIP key data
382 * 8 bytes of RX MIC key data
383 * 8 bytes of TX MIC key data
384 *
385 */
386
387struct wl1251_cmd_set_keys {
388 struct wl1251_cmd_header header;
389
390 /* Ignored for default WEP key */
391 u8 addr[ETH_ALEN];
392
393 /* key_action_e */
394 u16 key_action;
395
396 u16 reserved_1;
397
398 /* key size in bytes */
399 u8 key_size;
400
401 /* key_type_e */
402 u8 key_type;
403 u8 ssid_profile;
404
405 /*
406 * TKIP, AES: frame's key id field.
407 * For WEP default key: key id;
408 */
409 u8 id;
410 u8 reserved_2[6];
411 u8 key[MAX_KEY_SIZE];
412 u16 ac_seq_num16[NUM_ACCESS_CATEGORIES_COPY];
413 u32 ac_seq_num32[NUM_ACCESS_CATEGORIES_COPY];
414} __packed;
415
416
417#endif /* __WL1251_CMD_H__ */
diff --git a/drivers/net/wireless/wl12xx/wl1251_debugfs.c b/drivers/net/wireless/wl12xx/wl1251_debugfs.c
deleted file mode 100644
index 5e4465ac08fa..000000000000
--- a/drivers/net/wireless/wl12xx/wl1251_debugfs.c
+++ /dev/null
@@ -1,543 +0,0 @@
1/*
2 * This file is part of wl1251
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 *
6 * Contact: Kalle Valo <kalle.valo@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include "wl1251_debugfs.h"
25
26#include <linux/skbuff.h>
27#include <linux/slab.h>
28
29#include "wl1251.h"
30#include "wl1251_acx.h"
31#include "wl1251_ps.h"
32
33/* ms */
34#define WL1251_DEBUGFS_STATS_LIFETIME 1000
35
36/* debugfs macros idea from mac80211 */
37
38#define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \
39static ssize_t name## _read(struct file *file, char __user *userbuf, \
40 size_t count, loff_t *ppos) \
41{ \
42 struct wl1251 *wl = file->private_data; \
43 char buf[buflen]; \
44 int res; \
45 \
46 res = scnprintf(buf, buflen, fmt "\n", ##value); \
47 return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
48} \
49 \
50static const struct file_operations name## _ops = { \
51 .read = name## _read, \
52 .open = wl1251_open_file_generic, \
53};
54
55#define DEBUGFS_ADD(name, parent) \
56 wl->debugfs.name = debugfs_create_file(#name, 0400, parent, \
57 wl, &name## _ops); \
58 if (IS_ERR(wl->debugfs.name)) { \
59 ret = PTR_ERR(wl->debugfs.name); \
60 wl->debugfs.name = NULL; \
61 goto out; \
62 }
63
64#define DEBUGFS_DEL(name) \
65 do { \
66 debugfs_remove(wl->debugfs.name); \
67 wl->debugfs.name = NULL; \
68 } while (0)
69
70#define DEBUGFS_FWSTATS_FILE(sub, name, buflen, fmt) \
71static ssize_t sub## _ ##name## _read(struct file *file, \
72 char __user *userbuf, \
73 size_t count, loff_t *ppos) \
74{ \
75 struct wl1251 *wl = file->private_data; \
76 char buf[buflen]; \
77 int res; \
78 \
79 wl1251_debugfs_update_stats(wl); \
80 \
81 res = scnprintf(buf, buflen, fmt "\n", \
82 wl->stats.fw_stats->sub.name); \
83 return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
84} \
85 \
86static const struct file_operations sub## _ ##name## _ops = { \
87 .read = sub## _ ##name## _read, \
88 .open = wl1251_open_file_generic, \
89};
90
91#define DEBUGFS_FWSTATS_ADD(sub, name) \
92 DEBUGFS_ADD(sub## _ ##name, wl->debugfs.fw_statistics)
93
94#define DEBUGFS_FWSTATS_DEL(sub, name) \
95 DEBUGFS_DEL(sub## _ ##name)
96
97static void wl1251_debugfs_update_stats(struct wl1251 *wl)
98{
99 int ret;
100
101 mutex_lock(&wl->mutex);
102
103 ret = wl1251_ps_elp_wakeup(wl);
104 if (ret < 0)
105 goto out;
106
107 if (wl->state == WL1251_STATE_ON &&
108 time_after(jiffies, wl->stats.fw_stats_update +
109 msecs_to_jiffies(WL1251_DEBUGFS_STATS_LIFETIME))) {
110 wl1251_acx_statistics(wl, wl->stats.fw_stats);
111 wl->stats.fw_stats_update = jiffies;
112 }
113
114 wl1251_ps_elp_sleep(wl);
115
116out:
117 mutex_unlock(&wl->mutex);
118}
119
120static int wl1251_open_file_generic(struct inode *inode, struct file *file)
121{
122 file->private_data = inode->i_private;
123 return 0;
124}
125
126DEBUGFS_FWSTATS_FILE(tx, internal_desc_overflow, 20, "%u");
127
128DEBUGFS_FWSTATS_FILE(rx, out_of_mem, 20, "%u");
129DEBUGFS_FWSTATS_FILE(rx, hdr_overflow, 20, "%u");
130DEBUGFS_FWSTATS_FILE(rx, hw_stuck, 20, "%u");
131DEBUGFS_FWSTATS_FILE(rx, dropped, 20, "%u");
132DEBUGFS_FWSTATS_FILE(rx, fcs_err, 20, "%u");
133DEBUGFS_FWSTATS_FILE(rx, xfr_hint_trig, 20, "%u");
134DEBUGFS_FWSTATS_FILE(rx, path_reset, 20, "%u");
135DEBUGFS_FWSTATS_FILE(rx, reset_counter, 20, "%u");
136
137DEBUGFS_FWSTATS_FILE(dma, rx_requested, 20, "%u");
138DEBUGFS_FWSTATS_FILE(dma, rx_errors, 20, "%u");
139DEBUGFS_FWSTATS_FILE(dma, tx_requested, 20, "%u");
140DEBUGFS_FWSTATS_FILE(dma, tx_errors, 20, "%u");
141
142DEBUGFS_FWSTATS_FILE(isr, cmd_cmplt, 20, "%u");
143DEBUGFS_FWSTATS_FILE(isr, fiqs, 20, "%u");
144DEBUGFS_FWSTATS_FILE(isr, rx_headers, 20, "%u");
145DEBUGFS_FWSTATS_FILE(isr, rx_mem_overflow, 20, "%u");
146DEBUGFS_FWSTATS_FILE(isr, rx_rdys, 20, "%u");
147DEBUGFS_FWSTATS_FILE(isr, irqs, 20, "%u");
148DEBUGFS_FWSTATS_FILE(isr, tx_procs, 20, "%u");
149DEBUGFS_FWSTATS_FILE(isr, decrypt_done, 20, "%u");
150DEBUGFS_FWSTATS_FILE(isr, dma0_done, 20, "%u");
151DEBUGFS_FWSTATS_FILE(isr, dma1_done, 20, "%u");
152DEBUGFS_FWSTATS_FILE(isr, tx_exch_complete, 20, "%u");
153DEBUGFS_FWSTATS_FILE(isr, commands, 20, "%u");
154DEBUGFS_FWSTATS_FILE(isr, rx_procs, 20, "%u");
155DEBUGFS_FWSTATS_FILE(isr, hw_pm_mode_changes, 20, "%u");
156DEBUGFS_FWSTATS_FILE(isr, host_acknowledges, 20, "%u");
157DEBUGFS_FWSTATS_FILE(isr, pci_pm, 20, "%u");
158DEBUGFS_FWSTATS_FILE(isr, wakeups, 20, "%u");
159DEBUGFS_FWSTATS_FILE(isr, low_rssi, 20, "%u");
160
161DEBUGFS_FWSTATS_FILE(wep, addr_key_count, 20, "%u");
162DEBUGFS_FWSTATS_FILE(wep, default_key_count, 20, "%u");
163/* skipping wep.reserved */
164DEBUGFS_FWSTATS_FILE(wep, key_not_found, 20, "%u");
165DEBUGFS_FWSTATS_FILE(wep, decrypt_fail, 20, "%u");
166DEBUGFS_FWSTATS_FILE(wep, packets, 20, "%u");
167DEBUGFS_FWSTATS_FILE(wep, interrupt, 20, "%u");
168
169DEBUGFS_FWSTATS_FILE(pwr, ps_enter, 20, "%u");
170DEBUGFS_FWSTATS_FILE(pwr, elp_enter, 20, "%u");
171DEBUGFS_FWSTATS_FILE(pwr, missing_bcns, 20, "%u");
172DEBUGFS_FWSTATS_FILE(pwr, wake_on_host, 20, "%u");
173DEBUGFS_FWSTATS_FILE(pwr, wake_on_timer_exp, 20, "%u");
174DEBUGFS_FWSTATS_FILE(pwr, tx_with_ps, 20, "%u");
175DEBUGFS_FWSTATS_FILE(pwr, tx_without_ps, 20, "%u");
176DEBUGFS_FWSTATS_FILE(pwr, rcvd_beacons, 20, "%u");
177DEBUGFS_FWSTATS_FILE(pwr, power_save_off, 20, "%u");
178DEBUGFS_FWSTATS_FILE(pwr, enable_ps, 20, "%u");
179DEBUGFS_FWSTATS_FILE(pwr, disable_ps, 20, "%u");
180DEBUGFS_FWSTATS_FILE(pwr, fix_tsf_ps, 20, "%u");
181/* skipping cont_miss_bcns_spread for now */
182DEBUGFS_FWSTATS_FILE(pwr, rcvd_awake_beacons, 20, "%u");
183
184DEBUGFS_FWSTATS_FILE(mic, rx_pkts, 20, "%u");
185DEBUGFS_FWSTATS_FILE(mic, calc_failure, 20, "%u");
186
187DEBUGFS_FWSTATS_FILE(aes, encrypt_fail, 20, "%u");
188DEBUGFS_FWSTATS_FILE(aes, decrypt_fail, 20, "%u");
189DEBUGFS_FWSTATS_FILE(aes, encrypt_packets, 20, "%u");
190DEBUGFS_FWSTATS_FILE(aes, decrypt_packets, 20, "%u");
191DEBUGFS_FWSTATS_FILE(aes, encrypt_interrupt, 20, "%u");
192DEBUGFS_FWSTATS_FILE(aes, decrypt_interrupt, 20, "%u");
193
194DEBUGFS_FWSTATS_FILE(event, heart_beat, 20, "%u");
195DEBUGFS_FWSTATS_FILE(event, calibration, 20, "%u");
196DEBUGFS_FWSTATS_FILE(event, rx_mismatch, 20, "%u");
197DEBUGFS_FWSTATS_FILE(event, rx_mem_empty, 20, "%u");
198DEBUGFS_FWSTATS_FILE(event, rx_pool, 20, "%u");
199DEBUGFS_FWSTATS_FILE(event, oom_late, 20, "%u");
200DEBUGFS_FWSTATS_FILE(event, phy_transmit_error, 20, "%u");
201DEBUGFS_FWSTATS_FILE(event, tx_stuck, 20, "%u");
202
203DEBUGFS_FWSTATS_FILE(ps, pspoll_timeouts, 20, "%u");
204DEBUGFS_FWSTATS_FILE(ps, upsd_timeouts, 20, "%u");
205DEBUGFS_FWSTATS_FILE(ps, upsd_max_sptime, 20, "%u");
206DEBUGFS_FWSTATS_FILE(ps, upsd_max_apturn, 20, "%u");
207DEBUGFS_FWSTATS_FILE(ps, pspoll_max_apturn, 20, "%u");
208DEBUGFS_FWSTATS_FILE(ps, pspoll_utilization, 20, "%u");
209DEBUGFS_FWSTATS_FILE(ps, upsd_utilization, 20, "%u");
210
211DEBUGFS_FWSTATS_FILE(rxpipe, rx_prep_beacon_drop, 20, "%u");
212DEBUGFS_FWSTATS_FILE(rxpipe, descr_host_int_trig_rx_data, 20, "%u");
213DEBUGFS_FWSTATS_FILE(rxpipe, beacon_buffer_thres_host_int_trig_rx_data,
214 20, "%u");
215DEBUGFS_FWSTATS_FILE(rxpipe, missed_beacon_host_int_trig_rx_data, 20, "%u");
216DEBUGFS_FWSTATS_FILE(rxpipe, tx_xfr_host_int_trig_rx_data, 20, "%u");
217
218DEBUGFS_READONLY_FILE(retry_count, 20, "%u", wl->stats.retry_count);
219DEBUGFS_READONLY_FILE(excessive_retries, 20, "%u",
220 wl->stats.excessive_retries);
221
222static ssize_t tx_queue_len_read(struct file *file, char __user *userbuf,
223 size_t count, loff_t *ppos)
224{
225 struct wl1251 *wl = file->private_data;
226 u32 queue_len;
227 char buf[20];
228 int res;
229
230 queue_len = skb_queue_len(&wl->tx_queue);
231
232 res = scnprintf(buf, sizeof(buf), "%u\n", queue_len);
233 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
234}
235
236static const struct file_operations tx_queue_len_ops = {
237 .read = tx_queue_len_read,
238 .open = wl1251_open_file_generic,
239};
240
241static ssize_t tx_queue_status_read(struct file *file, char __user *userbuf,
242 size_t count, loff_t *ppos)
243{
244 struct wl1251 *wl = file->private_data;
245 char buf[3], status;
246 int len;
247
248 if (wl->tx_queue_stopped)
249 status = 's';
250 else
251 status = 'r';
252
253 len = scnprintf(buf, sizeof(buf), "%c\n", status);
254 return simple_read_from_buffer(userbuf, count, ppos, buf, len);
255}
256
257static const struct file_operations tx_queue_status_ops = {
258 .read = tx_queue_status_read,
259 .open = wl1251_open_file_generic,
260};
261
262static void wl1251_debugfs_delete_files(struct wl1251 *wl)
263{
264 DEBUGFS_FWSTATS_DEL(tx, internal_desc_overflow);
265
266 DEBUGFS_FWSTATS_DEL(rx, out_of_mem);
267 DEBUGFS_FWSTATS_DEL(rx, hdr_overflow);
268 DEBUGFS_FWSTATS_DEL(rx, hw_stuck);
269 DEBUGFS_FWSTATS_DEL(rx, dropped);
270 DEBUGFS_FWSTATS_DEL(rx, fcs_err);
271 DEBUGFS_FWSTATS_DEL(rx, xfr_hint_trig);
272 DEBUGFS_FWSTATS_DEL(rx, path_reset);
273 DEBUGFS_FWSTATS_DEL(rx, reset_counter);
274
275 DEBUGFS_FWSTATS_DEL(dma, rx_requested);
276 DEBUGFS_FWSTATS_DEL(dma, rx_errors);
277 DEBUGFS_FWSTATS_DEL(dma, tx_requested);
278 DEBUGFS_FWSTATS_DEL(dma, tx_errors);
279
280 DEBUGFS_FWSTATS_DEL(isr, cmd_cmplt);
281 DEBUGFS_FWSTATS_DEL(isr, fiqs);
282 DEBUGFS_FWSTATS_DEL(isr, rx_headers);
283 DEBUGFS_FWSTATS_DEL(isr, rx_mem_overflow);
284 DEBUGFS_FWSTATS_DEL(isr, rx_rdys);
285 DEBUGFS_FWSTATS_DEL(isr, irqs);
286 DEBUGFS_FWSTATS_DEL(isr, tx_procs);
287 DEBUGFS_FWSTATS_DEL(isr, decrypt_done);
288 DEBUGFS_FWSTATS_DEL(isr, dma0_done);
289 DEBUGFS_FWSTATS_DEL(isr, dma1_done);
290 DEBUGFS_FWSTATS_DEL(isr, tx_exch_complete);
291 DEBUGFS_FWSTATS_DEL(isr, commands);
292 DEBUGFS_FWSTATS_DEL(isr, rx_procs);
293 DEBUGFS_FWSTATS_DEL(isr, hw_pm_mode_changes);
294 DEBUGFS_FWSTATS_DEL(isr, host_acknowledges);
295 DEBUGFS_FWSTATS_DEL(isr, pci_pm);
296 DEBUGFS_FWSTATS_DEL(isr, wakeups);
297 DEBUGFS_FWSTATS_DEL(isr, low_rssi);
298
299 DEBUGFS_FWSTATS_DEL(wep, addr_key_count);
300 DEBUGFS_FWSTATS_DEL(wep, default_key_count);
301 /* skipping wep.reserved */
302 DEBUGFS_FWSTATS_DEL(wep, key_not_found);
303 DEBUGFS_FWSTATS_DEL(wep, decrypt_fail);
304 DEBUGFS_FWSTATS_DEL(wep, packets);
305 DEBUGFS_FWSTATS_DEL(wep, interrupt);
306
307 DEBUGFS_FWSTATS_DEL(pwr, ps_enter);
308 DEBUGFS_FWSTATS_DEL(pwr, elp_enter);
309 DEBUGFS_FWSTATS_DEL(pwr, missing_bcns);
310 DEBUGFS_FWSTATS_DEL(pwr, wake_on_host);
311 DEBUGFS_FWSTATS_DEL(pwr, wake_on_timer_exp);
312 DEBUGFS_FWSTATS_DEL(pwr, tx_with_ps);
313 DEBUGFS_FWSTATS_DEL(pwr, tx_without_ps);
314 DEBUGFS_FWSTATS_DEL(pwr, rcvd_beacons);
315 DEBUGFS_FWSTATS_DEL(pwr, power_save_off);
316 DEBUGFS_FWSTATS_DEL(pwr, enable_ps);
317 DEBUGFS_FWSTATS_DEL(pwr, disable_ps);
318 DEBUGFS_FWSTATS_DEL(pwr, fix_tsf_ps);
319 /* skipping cont_miss_bcns_spread for now */
320 DEBUGFS_FWSTATS_DEL(pwr, rcvd_awake_beacons);
321
322 DEBUGFS_FWSTATS_DEL(mic, rx_pkts);
323 DEBUGFS_FWSTATS_DEL(mic, calc_failure);
324
325 DEBUGFS_FWSTATS_DEL(aes, encrypt_fail);
326 DEBUGFS_FWSTATS_DEL(aes, decrypt_fail);
327 DEBUGFS_FWSTATS_DEL(aes, encrypt_packets);
328 DEBUGFS_FWSTATS_DEL(aes, decrypt_packets);
329 DEBUGFS_FWSTATS_DEL(aes, encrypt_interrupt);
330 DEBUGFS_FWSTATS_DEL(aes, decrypt_interrupt);
331
332 DEBUGFS_FWSTATS_DEL(event, heart_beat);
333 DEBUGFS_FWSTATS_DEL(event, calibration);
334 DEBUGFS_FWSTATS_DEL(event, rx_mismatch);
335 DEBUGFS_FWSTATS_DEL(event, rx_mem_empty);
336 DEBUGFS_FWSTATS_DEL(event, rx_pool);
337 DEBUGFS_FWSTATS_DEL(event, oom_late);
338 DEBUGFS_FWSTATS_DEL(event, phy_transmit_error);
339 DEBUGFS_FWSTATS_DEL(event, tx_stuck);
340
341 DEBUGFS_FWSTATS_DEL(ps, pspoll_timeouts);
342 DEBUGFS_FWSTATS_DEL(ps, upsd_timeouts);
343 DEBUGFS_FWSTATS_DEL(ps, upsd_max_sptime);
344 DEBUGFS_FWSTATS_DEL(ps, upsd_max_apturn);
345 DEBUGFS_FWSTATS_DEL(ps, pspoll_max_apturn);
346 DEBUGFS_FWSTATS_DEL(ps, pspoll_utilization);
347 DEBUGFS_FWSTATS_DEL(ps, upsd_utilization);
348
349 DEBUGFS_FWSTATS_DEL(rxpipe, rx_prep_beacon_drop);
350 DEBUGFS_FWSTATS_DEL(rxpipe, descr_host_int_trig_rx_data);
351 DEBUGFS_FWSTATS_DEL(rxpipe, beacon_buffer_thres_host_int_trig_rx_data);
352 DEBUGFS_FWSTATS_DEL(rxpipe, missed_beacon_host_int_trig_rx_data);
353 DEBUGFS_FWSTATS_DEL(rxpipe, tx_xfr_host_int_trig_rx_data);
354
355 DEBUGFS_DEL(tx_queue_len);
356 DEBUGFS_DEL(tx_queue_status);
357 DEBUGFS_DEL(retry_count);
358 DEBUGFS_DEL(excessive_retries);
359}
360
361static int wl1251_debugfs_add_files(struct wl1251 *wl)
362{
363 int ret = 0;
364
365 DEBUGFS_FWSTATS_ADD(tx, internal_desc_overflow);
366
367 DEBUGFS_FWSTATS_ADD(rx, out_of_mem);
368 DEBUGFS_FWSTATS_ADD(rx, hdr_overflow);
369 DEBUGFS_FWSTATS_ADD(rx, hw_stuck);
370 DEBUGFS_FWSTATS_ADD(rx, dropped);
371 DEBUGFS_FWSTATS_ADD(rx, fcs_err);
372 DEBUGFS_FWSTATS_ADD(rx, xfr_hint_trig);
373 DEBUGFS_FWSTATS_ADD(rx, path_reset);
374 DEBUGFS_FWSTATS_ADD(rx, reset_counter);
375
376 DEBUGFS_FWSTATS_ADD(dma, rx_requested);
377 DEBUGFS_FWSTATS_ADD(dma, rx_errors);
378 DEBUGFS_FWSTATS_ADD(dma, tx_requested);
379 DEBUGFS_FWSTATS_ADD(dma, tx_errors);
380
381 DEBUGFS_FWSTATS_ADD(isr, cmd_cmplt);
382 DEBUGFS_FWSTATS_ADD(isr, fiqs);
383 DEBUGFS_FWSTATS_ADD(isr, rx_headers);
384 DEBUGFS_FWSTATS_ADD(isr, rx_mem_overflow);
385 DEBUGFS_FWSTATS_ADD(isr, rx_rdys);
386 DEBUGFS_FWSTATS_ADD(isr, irqs);
387 DEBUGFS_FWSTATS_ADD(isr, tx_procs);
388 DEBUGFS_FWSTATS_ADD(isr, decrypt_done);
389 DEBUGFS_FWSTATS_ADD(isr, dma0_done);
390 DEBUGFS_FWSTATS_ADD(isr, dma1_done);
391 DEBUGFS_FWSTATS_ADD(isr, tx_exch_complete);
392 DEBUGFS_FWSTATS_ADD(isr, commands);
393 DEBUGFS_FWSTATS_ADD(isr, rx_procs);
394 DEBUGFS_FWSTATS_ADD(isr, hw_pm_mode_changes);
395 DEBUGFS_FWSTATS_ADD(isr, host_acknowledges);
396 DEBUGFS_FWSTATS_ADD(isr, pci_pm);
397 DEBUGFS_FWSTATS_ADD(isr, wakeups);
398 DEBUGFS_FWSTATS_ADD(isr, low_rssi);
399
400 DEBUGFS_FWSTATS_ADD(wep, addr_key_count);
401 DEBUGFS_FWSTATS_ADD(wep, default_key_count);
402 /* skipping wep.reserved */
403 DEBUGFS_FWSTATS_ADD(wep, key_not_found);
404 DEBUGFS_FWSTATS_ADD(wep, decrypt_fail);
405 DEBUGFS_FWSTATS_ADD(wep, packets);
406 DEBUGFS_FWSTATS_ADD(wep, interrupt);
407
408 DEBUGFS_FWSTATS_ADD(pwr, ps_enter);
409 DEBUGFS_FWSTATS_ADD(pwr, elp_enter);
410 DEBUGFS_FWSTATS_ADD(pwr, missing_bcns);
411 DEBUGFS_FWSTATS_ADD(pwr, wake_on_host);
412 DEBUGFS_FWSTATS_ADD(pwr, wake_on_timer_exp);
413 DEBUGFS_FWSTATS_ADD(pwr, tx_with_ps);
414 DEBUGFS_FWSTATS_ADD(pwr, tx_without_ps);
415 DEBUGFS_FWSTATS_ADD(pwr, rcvd_beacons);
416 DEBUGFS_FWSTATS_ADD(pwr, power_save_off);
417 DEBUGFS_FWSTATS_ADD(pwr, enable_ps);
418 DEBUGFS_FWSTATS_ADD(pwr, disable_ps);
419 DEBUGFS_FWSTATS_ADD(pwr, fix_tsf_ps);
420 /* skipping cont_miss_bcns_spread for now */
421 DEBUGFS_FWSTATS_ADD(pwr, rcvd_awake_beacons);
422
423 DEBUGFS_FWSTATS_ADD(mic, rx_pkts);
424 DEBUGFS_FWSTATS_ADD(mic, calc_failure);
425
426 DEBUGFS_FWSTATS_ADD(aes, encrypt_fail);
427 DEBUGFS_FWSTATS_ADD(aes, decrypt_fail);
428 DEBUGFS_FWSTATS_ADD(aes, encrypt_packets);
429 DEBUGFS_FWSTATS_ADD(aes, decrypt_packets);
430 DEBUGFS_FWSTATS_ADD(aes, encrypt_interrupt);
431 DEBUGFS_FWSTATS_ADD(aes, decrypt_interrupt);
432
433 DEBUGFS_FWSTATS_ADD(event, heart_beat);
434 DEBUGFS_FWSTATS_ADD(event, calibration);
435 DEBUGFS_FWSTATS_ADD(event, rx_mismatch);
436 DEBUGFS_FWSTATS_ADD(event, rx_mem_empty);
437 DEBUGFS_FWSTATS_ADD(event, rx_pool);
438 DEBUGFS_FWSTATS_ADD(event, oom_late);
439 DEBUGFS_FWSTATS_ADD(event, phy_transmit_error);
440 DEBUGFS_FWSTATS_ADD(event, tx_stuck);
441
442 DEBUGFS_FWSTATS_ADD(ps, pspoll_timeouts);
443 DEBUGFS_FWSTATS_ADD(ps, upsd_timeouts);
444 DEBUGFS_FWSTATS_ADD(ps, upsd_max_sptime);
445 DEBUGFS_FWSTATS_ADD(ps, upsd_max_apturn);
446 DEBUGFS_FWSTATS_ADD(ps, pspoll_max_apturn);
447 DEBUGFS_FWSTATS_ADD(ps, pspoll_utilization);
448 DEBUGFS_FWSTATS_ADD(ps, upsd_utilization);
449
450 DEBUGFS_FWSTATS_ADD(rxpipe, rx_prep_beacon_drop);
451 DEBUGFS_FWSTATS_ADD(rxpipe, descr_host_int_trig_rx_data);
452 DEBUGFS_FWSTATS_ADD(rxpipe, beacon_buffer_thres_host_int_trig_rx_data);
453 DEBUGFS_FWSTATS_ADD(rxpipe, missed_beacon_host_int_trig_rx_data);
454 DEBUGFS_FWSTATS_ADD(rxpipe, tx_xfr_host_int_trig_rx_data);
455
456 DEBUGFS_ADD(tx_queue_len, wl->debugfs.rootdir);
457 DEBUGFS_ADD(tx_queue_status, wl->debugfs.rootdir);
458 DEBUGFS_ADD(retry_count, wl->debugfs.rootdir);
459 DEBUGFS_ADD(excessive_retries, wl->debugfs.rootdir);
460
461out:
462 if (ret < 0)
463 wl1251_debugfs_delete_files(wl);
464
465 return ret;
466}
467
468void wl1251_debugfs_reset(struct wl1251 *wl)
469{
470 if (wl->stats.fw_stats != NULL)
471 memset(wl->stats.fw_stats, 0, sizeof(*wl->stats.fw_stats));
472 wl->stats.retry_count = 0;
473 wl->stats.excessive_retries = 0;
474}
475
476int wl1251_debugfs_init(struct wl1251 *wl)
477{
478 int ret;
479
480 wl->debugfs.rootdir = debugfs_create_dir(KBUILD_MODNAME, NULL);
481
482 if (IS_ERR(wl->debugfs.rootdir)) {
483 ret = PTR_ERR(wl->debugfs.rootdir);
484 wl->debugfs.rootdir = NULL;
485 goto err;
486 }
487
488 wl->debugfs.fw_statistics = debugfs_create_dir("fw-statistics",
489 wl->debugfs.rootdir);
490
491 if (IS_ERR(wl->debugfs.fw_statistics)) {
492 ret = PTR_ERR(wl->debugfs.fw_statistics);
493 wl->debugfs.fw_statistics = NULL;
494 goto err_root;
495 }
496
497 wl->stats.fw_stats = kzalloc(sizeof(*wl->stats.fw_stats),
498 GFP_KERNEL);
499
500 if (!wl->stats.fw_stats) {
501 ret = -ENOMEM;
502 goto err_fw;
503 }
504
505 wl->stats.fw_stats_update = jiffies;
506
507 ret = wl1251_debugfs_add_files(wl);
508
509 if (ret < 0)
510 goto err_file;
511
512 return 0;
513
514err_file:
515 kfree(wl->stats.fw_stats);
516 wl->stats.fw_stats = NULL;
517
518err_fw:
519 debugfs_remove(wl->debugfs.fw_statistics);
520 wl->debugfs.fw_statistics = NULL;
521
522err_root:
523 debugfs_remove(wl->debugfs.rootdir);
524 wl->debugfs.rootdir = NULL;
525
526err:
527 return ret;
528}
529
530void wl1251_debugfs_exit(struct wl1251 *wl)
531{
532 wl1251_debugfs_delete_files(wl);
533
534 kfree(wl->stats.fw_stats);
535 wl->stats.fw_stats = NULL;
536
537 debugfs_remove(wl->debugfs.fw_statistics);
538 wl->debugfs.fw_statistics = NULL;
539
540 debugfs_remove(wl->debugfs.rootdir);
541 wl->debugfs.rootdir = NULL;
542
543}
diff --git a/drivers/net/wireless/wl12xx/wl1251_debugfs.h b/drivers/net/wireless/wl12xx/wl1251_debugfs.h
deleted file mode 100644
index 6dc3d080853c..000000000000
--- a/drivers/net/wireless/wl12xx/wl1251_debugfs.h
+++ /dev/null
@@ -1,33 +0,0 @@
1/*
2 * This file is part of wl1251
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 *
6 * Contact: Kalle Valo <kalle.valo@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#ifndef WL1251_DEBUGFS_H
25#define WL1251_DEBUGFS_H
26
27#include "wl1251.h"
28
29int wl1251_debugfs_init(struct wl1251 *wl);
30void wl1251_debugfs_exit(struct wl1251 *wl);
31void wl1251_debugfs_reset(struct wl1251 *wl);
32
33#endif /* WL1251_DEBUGFS_H */
diff --git a/drivers/net/wireless/wl12xx/wl1251_event.c b/drivers/net/wireless/wl12xx/wl1251_event.c
deleted file mode 100644
index 020d764f9c13..000000000000
--- a/drivers/net/wireless/wl12xx/wl1251_event.c
+++ /dev/null
@@ -1,143 +0,0 @@
1/*
2 * This file is part of wl1251
3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation
6 *
7 * Contact: Kalle Valo <kalle.valo@nokia.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25#include "wl1251.h"
26#include "wl1251_reg.h"
27#include "wl1251_io.h"
28#include "wl1251_event.h"
29#include "wl1251_ps.h"
30
31static int wl1251_event_scan_complete(struct wl1251 *wl,
32 struct event_mailbox *mbox)
33{
34 wl1251_debug(DEBUG_EVENT, "status: 0x%x, channels: %d",
35 mbox->scheduled_scan_status,
36 mbox->scheduled_scan_channels);
37
38 if (wl->scanning) {
39 mutex_unlock(&wl->mutex);
40 ieee80211_scan_completed(wl->hw, false);
41 mutex_lock(&wl->mutex);
42 wl1251_debug(DEBUG_MAC80211, "mac80211 hw scan completed");
43 wl->scanning = false;
44 }
45
46 return 0;
47}
48
49static void wl1251_event_mbox_dump(struct event_mailbox *mbox)
50{
51 wl1251_debug(DEBUG_EVENT, "MBOX DUMP:");
52 wl1251_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector);
53 wl1251_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask);
54}
55
56static int wl1251_event_process(struct wl1251 *wl, struct event_mailbox *mbox)
57{
58 int ret;
59 u32 vector;
60
61 wl1251_event_mbox_dump(mbox);
62
63 vector = mbox->events_vector & ~(mbox->events_mask);
64 wl1251_debug(DEBUG_EVENT, "vector: 0x%x", vector);
65
66 if (vector & SCAN_COMPLETE_EVENT_ID) {
67 ret = wl1251_event_scan_complete(wl, mbox);
68 if (ret < 0)
69 return ret;
70 }
71
72 if (vector & BSS_LOSE_EVENT_ID) {
73 wl1251_debug(DEBUG_EVENT, "BSS_LOSE_EVENT");
74
75 if (wl->psm_requested && wl->psm) {
76 ret = wl1251_ps_set_mode(wl, STATION_ACTIVE_MODE);
77 if (ret < 0)
78 return ret;
79 }
80 }
81
82 if (vector & SYNCHRONIZATION_TIMEOUT_EVENT_ID && wl->psm) {
83 wl1251_debug(DEBUG_EVENT, "SYNCHRONIZATION_TIMEOUT_EVENT");
84
85 /* indicate to the stack, that beacons have been lost */
86 ieee80211_beacon_loss(wl->vif);
87 }
88
89 if (vector & REGAINED_BSS_EVENT_ID) {
90 if (wl->psm_requested) {
91 ret = wl1251_ps_set_mode(wl, STATION_POWER_SAVE_MODE);
92 if (ret < 0)
93 return ret;
94 }
95 }
96
97 return 0;
98}
99
100int wl1251_event_unmask(struct wl1251 *wl)
101{
102 int ret;
103
104 ret = wl1251_acx_event_mbox_mask(wl, ~(wl->event_mask));
105 if (ret < 0)
106 return ret;
107
108 return 0;
109}
110
111void wl1251_event_mbox_config(struct wl1251 *wl)
112{
113 wl->mbox_ptr[0] = wl1251_reg_read32(wl, REG_EVENT_MAILBOX_PTR);
114 wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox);
115
116 wl1251_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x",
117 wl->mbox_ptr[0], wl->mbox_ptr[1]);
118}
119
120int wl1251_event_handle(struct wl1251 *wl, u8 mbox_num)
121{
122 struct event_mailbox mbox;
123 int ret;
124
125 wl1251_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
126
127 if (mbox_num > 1)
128 return -EINVAL;
129
130 /* first we read the mbox descriptor */
131 wl1251_mem_read(wl, wl->mbox_ptr[mbox_num], &mbox,
132 sizeof(struct event_mailbox));
133
134 /* process the descriptor */
135 ret = wl1251_event_process(wl, &mbox);
136 if (ret < 0)
137 return ret;
138
139 /* then we let the firmware know it can go on...*/
140 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK);
141
142 return 0;
143}
diff --git a/drivers/net/wireless/wl12xx/wl1251_event.h b/drivers/net/wireless/wl12xx/wl1251_event.h
deleted file mode 100644
index f48a2b66bc5a..000000000000
--- a/drivers/net/wireless/wl12xx/wl1251_event.h
+++ /dev/null
@@ -1,121 +0,0 @@
1/*
2 * This file is part of wl1251
3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation
6 *
7 * Contact: Kalle Valo <kalle.valo@nokia.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25#ifndef __WL1251_EVENT_H__
26#define __WL1251_EVENT_H__
27
28/*
29 * Mbox events
30 *
31 * The event mechanism is based on a pair of event buffers (buffers A and
32 * B) at fixed locations in the target's memory. The host processes one
33 * buffer while the other buffer continues to collect events. If the host
34 * is not processing events, an interrupt is issued to signal that a buffer
35 * is ready. Once the host is done with processing events from one buffer,
36 * it signals the target (with an ACK interrupt) that the event buffer is
37 * free.
38 */
39
40enum {
41 RESERVED1_EVENT_ID = BIT(0),
42 RESERVED2_EVENT_ID = BIT(1),
43 MEASUREMENT_START_EVENT_ID = BIT(2),
44 SCAN_COMPLETE_EVENT_ID = BIT(3),
45 CALIBRATION_COMPLETE_EVENT_ID = BIT(4),
46 ROAMING_TRIGGER_LOW_RSSI_EVENT_ID = BIT(5),
47 PS_REPORT_EVENT_ID = BIT(6),
48 SYNCHRONIZATION_TIMEOUT_EVENT_ID = BIT(7),
49 HEALTH_REPORT_EVENT_ID = BIT(8),
50 ACI_DETECTION_EVENT_ID = BIT(9),
51 DEBUG_REPORT_EVENT_ID = BIT(10),
52 MAC_STATUS_EVENT_ID = BIT(11),
53 DISCONNECT_EVENT_COMPLETE_ID = BIT(12),
54 JOIN_EVENT_COMPLETE_ID = BIT(13),
55 CHANNEL_SWITCH_COMPLETE_EVENT_ID = BIT(14),
56 BSS_LOSE_EVENT_ID = BIT(15),
57 ROAMING_TRIGGER_MAX_TX_RETRY_EVENT_ID = BIT(16),
58 MEASUREMENT_COMPLETE_EVENT_ID = BIT(17),
59 AP_DISCOVERY_COMPLETE_EVENT_ID = BIT(18),
60 SCHEDULED_SCAN_COMPLETE_EVENT_ID = BIT(19),
61 PSPOLL_DELIVERY_FAILURE_EVENT_ID = BIT(20),
62 RESET_BSS_EVENT_ID = BIT(21),
63 REGAINED_BSS_EVENT_ID = BIT(22),
64 ROAMING_TRIGGER_REGAINED_RSSI_EVENT_ID = BIT(23),
65 ROAMING_TRIGGER_LOW_SNR_EVENT_ID = BIT(24),
66 ROAMING_TRIGGER_REGAINED_SNR_EVENT_ID = BIT(25),
67
68 DBG_EVENT_ID = BIT(26),
69 BT_PTA_SENSE_EVENT_ID = BIT(27),
70 BT_PTA_PREDICTION_EVENT_ID = BIT(28),
71 BT_PTA_AVALANCHE_EVENT_ID = BIT(29),
72
73 PLT_RX_CALIBRATION_COMPLETE_EVENT_ID = BIT(30),
74
75 EVENT_MBOX_ALL_EVENT_ID = 0x7fffffff,
76};
77
78struct event_debug_report {
79 u8 debug_event_id;
80 u8 num_params;
81 u16 pad;
82 u32 report_1;
83 u32 report_2;
84 u32 report_3;
85} __packed;
86
87struct event_mailbox {
88 u32 events_vector;
89 u32 events_mask;
90 u32 reserved_1;
91 u32 reserved_2;
92
93 char average_rssi_level;
94 u8 ps_status;
95 u8 channel_switch_status;
96 u8 scheduled_scan_status;
97
98 /* Channels scanned by the scheduled scan */
99 u16 scheduled_scan_channels;
100
101 /* If bit 0 is set -> target's fatal error */
102 u16 health_report;
103 u16 bad_fft_counter;
104 u8 bt_pta_sense_info;
105 u8 bt_pta_protective_info;
106 u32 reserved;
107 u32 debug_report[2];
108
109 /* Number of FCS errors since last event */
110 u32 fcs_err_counter;
111
112 struct event_debug_report report;
113 u8 average_snr_level;
114 u8 padding[19];
115} __packed;
116
117int wl1251_event_unmask(struct wl1251 *wl);
118void wl1251_event_mbox_config(struct wl1251 *wl);
119int wl1251_event_handle(struct wl1251 *wl, u8 mbox);
120
121#endif
diff --git a/drivers/net/wireless/wl12xx/wl1251_init.c b/drivers/net/wireless/wl12xx/wl1251_init.c
deleted file mode 100644
index b538bdd7b320..000000000000
--- a/drivers/net/wireless/wl12xx/wl1251_init.c
+++ /dev/null
@@ -1,425 +0,0 @@
1/*
2 * This file is part of wl1251
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 *
6 * Contact: Kalle Valo <kalle.valo@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include <linux/kernel.h>
25#include <linux/module.h>
26#include <linux/slab.h>
27
28#include "wl1251_init.h"
29#include "wl12xx_80211.h"
30#include "wl1251_acx.h"
31#include "wl1251_cmd.h"
32#include "wl1251_reg.h"
33
34int wl1251_hw_init_hwenc_config(struct wl1251 *wl)
35{
36 int ret;
37
38 ret = wl1251_acx_feature_cfg(wl);
39 if (ret < 0) {
40 wl1251_warning("couldn't set feature config");
41 return ret;
42 }
43
44 ret = wl1251_acx_default_key(wl, wl->default_key);
45 if (ret < 0) {
46 wl1251_warning("couldn't set default key");
47 return ret;
48 }
49
50 return 0;
51}
52
53int wl1251_hw_init_templates_config(struct wl1251 *wl)
54{
55 int ret;
56 u8 partial_vbm[PARTIAL_VBM_MAX];
57
58 /* send empty templates for fw memory reservation */
59 ret = wl1251_cmd_template_set(wl, CMD_PROBE_REQ, NULL,
60 sizeof(struct wl12xx_probe_req_template));
61 if (ret < 0)
62 return ret;
63
64 ret = wl1251_cmd_template_set(wl, CMD_NULL_DATA, NULL,
65 sizeof(struct wl12xx_null_data_template));
66 if (ret < 0)
67 return ret;
68
69 ret = wl1251_cmd_template_set(wl, CMD_PS_POLL, NULL,
70 sizeof(struct wl12xx_ps_poll_template));
71 if (ret < 0)
72 return ret;
73
74 ret = wl1251_cmd_template_set(wl, CMD_QOS_NULL_DATA, NULL,
75 sizeof
76 (struct wl12xx_qos_null_data_template));
77 if (ret < 0)
78 return ret;
79
80 ret = wl1251_cmd_template_set(wl, CMD_PROBE_RESP, NULL,
81 sizeof
82 (struct wl12xx_probe_resp_template));
83 if (ret < 0)
84 return ret;
85
86 ret = wl1251_cmd_template_set(wl, CMD_BEACON, NULL,
87 sizeof
88 (struct wl12xx_beacon_template));
89 if (ret < 0)
90 return ret;
91
92 /* tim templates, first reserve space then allocate an empty one */
93 memset(partial_vbm, 0, PARTIAL_VBM_MAX);
94 ret = wl1251_cmd_vbm(wl, TIM_ELE_ID, partial_vbm, PARTIAL_VBM_MAX, 0);
95 if (ret < 0)
96 return ret;
97
98 ret = wl1251_cmd_vbm(wl, TIM_ELE_ID, partial_vbm, 1, 0);
99 if (ret < 0)
100 return ret;
101
102 return 0;
103}
104
105int wl1251_hw_init_rx_config(struct wl1251 *wl, u32 config, u32 filter)
106{
107 int ret;
108
109 ret = wl1251_acx_rx_msdu_life_time(wl, RX_MSDU_LIFETIME_DEF);
110 if (ret < 0)
111 return ret;
112
113 ret = wl1251_acx_rx_config(wl, config, filter);
114 if (ret < 0)
115 return ret;
116
117 return 0;
118}
119
120int wl1251_hw_init_phy_config(struct wl1251 *wl)
121{
122 int ret;
123
124 ret = wl1251_acx_pd_threshold(wl);
125 if (ret < 0)
126 return ret;
127
128 ret = wl1251_acx_slot(wl, DEFAULT_SLOT_TIME);
129 if (ret < 0)
130 return ret;
131
132 ret = wl1251_acx_group_address_tbl(wl);
133 if (ret < 0)
134 return ret;
135
136 ret = wl1251_acx_service_period_timeout(wl);
137 if (ret < 0)
138 return ret;
139
140 ret = wl1251_acx_rts_threshold(wl, RTS_THRESHOLD_DEF);
141 if (ret < 0)
142 return ret;
143
144 return 0;
145}
146
147int wl1251_hw_init_beacon_filter(struct wl1251 *wl)
148{
149 int ret;
150
151 /* disable beacon filtering at this stage */
152 ret = wl1251_acx_beacon_filter_opt(wl, false);
153 if (ret < 0)
154 return ret;
155
156 ret = wl1251_acx_beacon_filter_table(wl);
157 if (ret < 0)
158 return ret;
159
160 return 0;
161}
162
163int wl1251_hw_init_pta(struct wl1251 *wl)
164{
165 int ret;
166
167 ret = wl1251_acx_sg_enable(wl);
168 if (ret < 0)
169 return ret;
170
171 ret = wl1251_acx_sg_cfg(wl);
172 if (ret < 0)
173 return ret;
174
175 return 0;
176}
177
178int wl1251_hw_init_energy_detection(struct wl1251 *wl)
179{
180 int ret;
181
182 ret = wl1251_acx_cca_threshold(wl);
183 if (ret < 0)
184 return ret;
185
186 return 0;
187}
188
189int wl1251_hw_init_beacon_broadcast(struct wl1251 *wl)
190{
191 int ret;
192
193 ret = wl1251_acx_bcn_dtim_options(wl);
194 if (ret < 0)
195 return ret;
196
197 return 0;
198}
199
200int wl1251_hw_init_power_auth(struct wl1251 *wl)
201{
202 return wl1251_acx_sleep_auth(wl, WL1251_PSM_CAM);
203}
204
205int wl1251_hw_init_mem_config(struct wl1251 *wl)
206{
207 int ret;
208
209 ret = wl1251_acx_mem_cfg(wl);
210 if (ret < 0)
211 return ret;
212
213 wl->target_mem_map = kzalloc(sizeof(struct wl1251_acx_mem_map),
214 GFP_KERNEL);
215 if (!wl->target_mem_map) {
216 wl1251_error("couldn't allocate target memory map");
217 return -ENOMEM;
218 }
219
220 /* we now ask for the firmware built memory map */
221 ret = wl1251_acx_mem_map(wl, wl->target_mem_map,
222 sizeof(struct wl1251_acx_mem_map));
223 if (ret < 0) {
224 wl1251_error("couldn't retrieve firmware memory map");
225 kfree(wl->target_mem_map);
226 wl->target_mem_map = NULL;
227 return ret;
228 }
229
230 return 0;
231}
232
233static int wl1251_hw_init_txq_fill(u8 qid,
234 struct acx_tx_queue_qos_config *config,
235 u32 num_blocks)
236{
237 config->qid = qid;
238
239 switch (qid) {
240 case QOS_AC_BE:
241 config->high_threshold =
242 (QOS_TX_HIGH_BE_DEF * num_blocks) / 100;
243 config->low_threshold =
244 (QOS_TX_LOW_BE_DEF * num_blocks) / 100;
245 break;
246 case QOS_AC_BK:
247 config->high_threshold =
248 (QOS_TX_HIGH_BK_DEF * num_blocks) / 100;
249 config->low_threshold =
250 (QOS_TX_LOW_BK_DEF * num_blocks) / 100;
251 break;
252 case QOS_AC_VI:
253 config->high_threshold =
254 (QOS_TX_HIGH_VI_DEF * num_blocks) / 100;
255 config->low_threshold =
256 (QOS_TX_LOW_VI_DEF * num_blocks) / 100;
257 break;
258 case QOS_AC_VO:
259 config->high_threshold =
260 (QOS_TX_HIGH_VO_DEF * num_blocks) / 100;
261 config->low_threshold =
262 (QOS_TX_LOW_VO_DEF * num_blocks) / 100;
263 break;
264 default:
265 wl1251_error("Invalid TX queue id: %d", qid);
266 return -EINVAL;
267 }
268
269 return 0;
270}
271
272static int wl1251_hw_init_tx_queue_config(struct wl1251 *wl)
273{
274 struct acx_tx_queue_qos_config *config;
275 struct wl1251_acx_mem_map *wl_mem_map = wl->target_mem_map;
276 int ret, i;
277
278 wl1251_debug(DEBUG_ACX, "acx tx queue config");
279
280 config = kzalloc(sizeof(*config), GFP_KERNEL);
281 if (!config) {
282 ret = -ENOMEM;
283 goto out;
284 }
285
286 for (i = 0; i < MAX_NUM_OF_AC; i++) {
287 ret = wl1251_hw_init_txq_fill(i, config,
288 wl_mem_map->num_tx_mem_blocks);
289 if (ret < 0)
290 goto out;
291
292 ret = wl1251_cmd_configure(wl, ACX_TX_QUEUE_CFG,
293 config, sizeof(*config));
294 if (ret < 0)
295 goto out;
296 }
297
298 wl1251_acx_ac_cfg(wl, AC_BE, CWMIN_BE, CWMAX_BE, AIFS_DIFS, TXOP_BE);
299 wl1251_acx_ac_cfg(wl, AC_BK, CWMIN_BK, CWMAX_BK, AIFS_DIFS, TXOP_BK);
300 wl1251_acx_ac_cfg(wl, AC_VI, CWMIN_VI, CWMAX_VI, AIFS_DIFS, TXOP_VI);
301 wl1251_acx_ac_cfg(wl, AC_VO, CWMIN_VO, CWMAX_VO, AIFS_DIFS, TXOP_VO);
302
303out:
304 kfree(config);
305 return ret;
306}
307
308static int wl1251_hw_init_data_path_config(struct wl1251 *wl)
309{
310 int ret;
311
312 /* asking for the data path parameters */
313 wl->data_path = kzalloc(sizeof(struct acx_data_path_params_resp),
314 GFP_KERNEL);
315 if (!wl->data_path) {
316 wl1251_error("Couldnt allocate data path parameters");
317 return -ENOMEM;
318 }
319
320 ret = wl1251_acx_data_path_params(wl, wl->data_path);
321 if (ret < 0) {
322 kfree(wl->data_path);
323 wl->data_path = NULL;
324 return ret;
325 }
326
327 return 0;
328}
329
330
331int wl1251_hw_init(struct wl1251 *wl)
332{
333 struct wl1251_acx_mem_map *wl_mem_map;
334 int ret;
335
336 ret = wl1251_hw_init_hwenc_config(wl);
337 if (ret < 0)
338 return ret;
339
340 /* Template settings */
341 ret = wl1251_hw_init_templates_config(wl);
342 if (ret < 0)
343 return ret;
344
345 /* Default memory configuration */
346 ret = wl1251_hw_init_mem_config(wl);
347 if (ret < 0)
348 return ret;
349
350 /* Default data path configuration */
351 ret = wl1251_hw_init_data_path_config(wl);
352 if (ret < 0)
353 goto out_free_memmap;
354
355 /* RX config */
356 ret = wl1251_hw_init_rx_config(wl,
357 RX_CFG_PROMISCUOUS | RX_CFG_TSF,
358 RX_FILTER_OPTION_DEF);
359 /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
360 RX_FILTER_OPTION_FILTER_ALL); */
361 if (ret < 0)
362 goto out_free_data_path;
363
364 /* TX queues config */
365 ret = wl1251_hw_init_tx_queue_config(wl);
366 if (ret < 0)
367 goto out_free_data_path;
368
369 /* PHY layer config */
370 ret = wl1251_hw_init_phy_config(wl);
371 if (ret < 0)
372 goto out_free_data_path;
373
374 /* Initialize connection monitoring thresholds */
375 ret = wl1251_acx_conn_monit_params(wl);
376 if (ret < 0)
377 goto out_free_data_path;
378
379 /* Beacon filtering */
380 ret = wl1251_hw_init_beacon_filter(wl);
381 if (ret < 0)
382 goto out_free_data_path;
383
384 /* Bluetooth WLAN coexistence */
385 ret = wl1251_hw_init_pta(wl);
386 if (ret < 0)
387 goto out_free_data_path;
388
389 /* Energy detection */
390 ret = wl1251_hw_init_energy_detection(wl);
391 if (ret < 0)
392 goto out_free_data_path;
393
394 /* Beacons and boradcast settings */
395 ret = wl1251_hw_init_beacon_broadcast(wl);
396 if (ret < 0)
397 goto out_free_data_path;
398
399 /* Enable data path */
400 ret = wl1251_cmd_data_path(wl, wl->channel, 1);
401 if (ret < 0)
402 goto out_free_data_path;
403
404 /* Default power state */
405 ret = wl1251_hw_init_power_auth(wl);
406 if (ret < 0)
407 goto out_free_data_path;
408
409 wl_mem_map = wl->target_mem_map;
410 wl1251_info("%d tx blocks at 0x%x, %d rx blocks at 0x%x",
411 wl_mem_map->num_tx_mem_blocks,
412 wl->data_path->tx_control_addr,
413 wl_mem_map->num_rx_mem_blocks,
414 wl->data_path->rx_control_addr);
415
416 return 0;
417
418 out_free_data_path:
419 kfree(wl->data_path);
420
421 out_free_memmap:
422 kfree(wl->target_mem_map);
423
424 return ret;
425}
diff --git a/drivers/net/wireless/wl12xx/wl1251_init.h b/drivers/net/wireless/wl12xx/wl1251_init.h
deleted file mode 100644
index 269cefb3e7d4..000000000000
--- a/drivers/net/wireless/wl12xx/wl1251_init.h
+++ /dev/null
@@ -1,88 +0,0 @@
1/*
2 * This file is part of wl1251
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 *
6 * Contact: Kalle Valo <kalle.valo@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#ifndef __WL1251_INIT_H__
25#define __WL1251_INIT_H__
26
27#include "wl1251.h"
28
29enum {
30 /* best effort/legacy */
31 AC_BE = 0,
32
33 /* background */
34 AC_BK = 1,
35
36 /* video */
37 AC_VI = 2,
38
39 /* voice */
40 AC_VO = 3,
41
42 /* broadcast dummy access category */
43 AC_BCAST = 4,
44
45 NUM_ACCESS_CATEGORIES = 4
46};
47
48/* following are defult values for the IE fields*/
49#define CWMIN_BK 15
50#define CWMIN_BE 15
51#define CWMIN_VI 7
52#define CWMIN_VO 3
53#define CWMAX_BK 1023
54#define CWMAX_BE 63
55#define CWMAX_VI 15
56#define CWMAX_VO 7
57
58/* slot number setting to start transmission at PIFS interval */
59#define AIFS_PIFS 1
60
61/*
62 * slot number setting to start transmission at DIFS interval - normal DCF
63 * access
64 */
65#define AIFS_DIFS 2
66
67#define AIFSN_BK 7
68#define AIFSN_BE 3
69#define AIFSN_VI AIFS_PIFS
70#define AIFSN_VO AIFS_PIFS
71#define TXOP_BK 0
72#define TXOP_BE 0
73#define TXOP_VI 3008
74#define TXOP_VO 1504
75
76int wl1251_hw_init_hwenc_config(struct wl1251 *wl);
77int wl1251_hw_init_templates_config(struct wl1251 *wl);
78int wl1251_hw_init_rx_config(struct wl1251 *wl, u32 config, u32 filter);
79int wl1251_hw_init_phy_config(struct wl1251 *wl);
80int wl1251_hw_init_beacon_filter(struct wl1251 *wl);
81int wl1251_hw_init_pta(struct wl1251 *wl);
82int wl1251_hw_init_energy_detection(struct wl1251 *wl);
83int wl1251_hw_init_beacon_broadcast(struct wl1251 *wl);
84int wl1251_hw_init_power_auth(struct wl1251 *wl);
85int wl1251_hw_init_mem_config(struct wl1251 *wl);
86int wl1251_hw_init(struct wl1251 *wl);
87
88#endif
diff --git a/drivers/net/wireless/wl12xx/wl1251_io.c b/drivers/net/wireless/wl12xx/wl1251_io.c
deleted file mode 100644
index f1c232e0887f..000000000000
--- a/drivers/net/wireless/wl12xx/wl1251_io.c
+++ /dev/null
@@ -1,196 +0,0 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (C) 2008 Nokia Corporation
5 *
6 * Contact: Kalle Valo <kalle.valo@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include "wl1251.h"
25#include "wl1251_reg.h"
26#include "wl1251_io.h"
27
28/* FIXME: this is static data nowadays and the table can be removed */
29static enum wl12xx_acx_int_reg wl1251_io_reg_table[ACX_REG_TABLE_LEN] = {
30 [ACX_REG_INTERRUPT_TRIG] = (REGISTERS_BASE + 0x0474),
31 [ACX_REG_INTERRUPT_TRIG_H] = (REGISTERS_BASE + 0x0478),
32 [ACX_REG_INTERRUPT_MASK] = (REGISTERS_BASE + 0x0494),
33 [ACX_REG_HINT_MASK_SET] = (REGISTERS_BASE + 0x0498),
34 [ACX_REG_HINT_MASK_CLR] = (REGISTERS_BASE + 0x049C),
35 [ACX_REG_INTERRUPT_NO_CLEAR] = (REGISTERS_BASE + 0x04B0),
36 [ACX_REG_INTERRUPT_CLEAR] = (REGISTERS_BASE + 0x04A4),
37 [ACX_REG_INTERRUPT_ACK] = (REGISTERS_BASE + 0x04A8),
38 [ACX_REG_SLV_SOFT_RESET] = (REGISTERS_BASE + 0x0000),
39 [ACX_REG_EE_START] = (REGISTERS_BASE + 0x080C),
40 [ACX_REG_ECPU_CONTROL] = (REGISTERS_BASE + 0x0804)
41};
42
43static int wl1251_translate_reg_addr(struct wl1251 *wl, int addr)
44{
45 /* If the address is lower than REGISTERS_BASE, it means that this is
46 * a chip-specific register address, so look it up in the registers
47 * table */
48 if (addr < REGISTERS_BASE) {
49 /* Make sure we don't go over the table */
50 if (addr >= ACX_REG_TABLE_LEN) {
51 wl1251_error("address out of range (%d)", addr);
52 return -EINVAL;
53 }
54 addr = wl1251_io_reg_table[addr];
55 }
56
57 return addr - wl->physical_reg_addr + wl->virtual_reg_addr;
58}
59
60static int wl1251_translate_mem_addr(struct wl1251 *wl, int addr)
61{
62 return addr - wl->physical_mem_addr + wl->virtual_mem_addr;
63}
64
65void wl1251_mem_read(struct wl1251 *wl, int addr, void *buf, size_t len)
66{
67 int physical;
68
69 physical = wl1251_translate_mem_addr(wl, addr);
70
71 wl->if_ops->read(wl, physical, buf, len);
72}
73
74void wl1251_mem_write(struct wl1251 *wl, int addr, void *buf, size_t len)
75{
76 int physical;
77
78 physical = wl1251_translate_mem_addr(wl, addr);
79
80 wl->if_ops->write(wl, physical, buf, len);
81}
82
83u32 wl1251_mem_read32(struct wl1251 *wl, int addr)
84{
85 return wl1251_read32(wl, wl1251_translate_mem_addr(wl, addr));
86}
87
88void wl1251_mem_write32(struct wl1251 *wl, int addr, u32 val)
89{
90 wl1251_write32(wl, wl1251_translate_mem_addr(wl, addr), val);
91}
92
93u32 wl1251_reg_read32(struct wl1251 *wl, int addr)
94{
95 return wl1251_read32(wl, wl1251_translate_reg_addr(wl, addr));
96}
97
98void wl1251_reg_write32(struct wl1251 *wl, int addr, u32 val)
99{
100 wl1251_write32(wl, wl1251_translate_reg_addr(wl, addr), val);
101}
102
103/* Set the partitions to access the chip addresses.
104 *
105 * There are two VIRTUAL partitions (the memory partition and the
106 * registers partition), which are mapped to two different areas of the
107 * PHYSICAL (hardware) memory. This function also makes other checks to
108 * ensure that the partitions are not overlapping. In the diagram below, the
109 * memory partition comes before the register partition, but the opposite is
110 * also supported.
111 *
112 * PHYSICAL address
113 * space
114 *
115 * | |
116 * ...+----+--> mem_start
117 * VIRTUAL address ... | |
118 * space ... | | [PART_0]
119 * ... | |
120 * 0x00000000 <--+----+... ...+----+--> mem_start + mem_size
121 * | | ... | |
122 * |MEM | ... | |
123 * | | ... | |
124 * part_size <--+----+... | | {unused area)
125 * | | ... | |
126 * |REG | ... | |
127 * part_size | | ... | |
128 * + <--+----+... ...+----+--> reg_start
129 * reg_size ... | |
130 * ... | | [PART_1]
131 * ... | |
132 * ...+----+--> reg_start + reg_size
133 * | |
134 *
135 */
136void wl1251_set_partition(struct wl1251 *wl,
137 u32 mem_start, u32 mem_size,
138 u32 reg_start, u32 reg_size)
139{
140 struct wl1251_partition partition[2];
141
142 wl1251_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
143 mem_start, mem_size);
144 wl1251_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
145 reg_start, reg_size);
146
147 /* Make sure that the two partitions together don't exceed the
148 * address range */
149 if ((mem_size + reg_size) > HW_ACCESS_MEMORY_MAX_RANGE) {
150 wl1251_debug(DEBUG_SPI, "Total size exceeds maximum virtual"
151 " address range. Truncating partition[0].");
152 mem_size = HW_ACCESS_MEMORY_MAX_RANGE - reg_size;
153 wl1251_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
154 mem_start, mem_size);
155 wl1251_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
156 reg_start, reg_size);
157 }
158
159 if ((mem_start < reg_start) &&
160 ((mem_start + mem_size) > reg_start)) {
161 /* Guarantee that the memory partition doesn't overlap the
162 * registers partition */
163 wl1251_debug(DEBUG_SPI, "End of partition[0] is "
164 "overlapping partition[1]. Adjusted.");
165 mem_size = reg_start - mem_start;
166 wl1251_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
167 mem_start, mem_size);
168 wl1251_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
169 reg_start, reg_size);
170 } else if ((reg_start < mem_start) &&
171 ((reg_start + reg_size) > mem_start)) {
172 /* Guarantee that the register partition doesn't overlap the
173 * memory partition */
174 wl1251_debug(DEBUG_SPI, "End of partition[1] is"
175 " overlapping partition[0]. Adjusted.");
176 reg_size = mem_start - reg_start;
177 wl1251_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
178 mem_start, mem_size);
179 wl1251_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
180 reg_start, reg_size);
181 }
182
183 partition[0].start = mem_start;
184 partition[0].size = mem_size;
185 partition[1].start = reg_start;
186 partition[1].size = reg_size;
187
188 wl->physical_mem_addr = mem_start;
189 wl->physical_reg_addr = reg_start;
190
191 wl->virtual_mem_addr = 0;
192 wl->virtual_reg_addr = mem_size;
193
194 wl->if_ops->write(wl, HW_ACCESS_PART0_SIZE_ADDR, partition,
195 sizeof(partition));
196}
diff --git a/drivers/net/wireless/wl12xx/wl1251_io.h b/drivers/net/wireless/wl12xx/wl1251_io.h
deleted file mode 100644
index c545e9d5f512..000000000000
--- a/drivers/net/wireless/wl12xx/wl1251_io.h
+++ /dev/null
@@ -1,84 +0,0 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (C) 2008 Nokia Corporation
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
19 *
20 */
21#ifndef __WL1251_IO_H__
22#define __WL1251_IO_H__
23
24#include "wl1251.h"
25
26#define HW_ACCESS_MEMORY_MAX_RANGE 0x1FFC0
27
28#define HW_ACCESS_PART0_SIZE_ADDR 0x1FFC0
29#define HW_ACCESS_PART0_START_ADDR 0x1FFC4
30#define HW_ACCESS_PART1_SIZE_ADDR 0x1FFC8
31#define HW_ACCESS_PART1_START_ADDR 0x1FFCC
32
33#define HW_ACCESS_REGISTER_SIZE 4
34
35#define HW_ACCESS_PRAM_MAX_RANGE 0x3c000
36
37static inline u32 wl1251_read32(struct wl1251 *wl, int addr)
38{
39 u32 response;
40
41 wl->if_ops->read(wl, addr, &response, sizeof(u32));
42
43 return response;
44}
45
46static inline void wl1251_write32(struct wl1251 *wl, int addr, u32 val)
47{
48 wl->if_ops->write(wl, addr, &val, sizeof(u32));
49}
50
51static inline u32 wl1251_read_elp(struct wl1251 *wl, int addr)
52{
53 u32 response;
54
55 if (wl->if_ops->read_elp)
56 wl->if_ops->read_elp(wl, addr, &response);
57 else
58 wl->if_ops->read(wl, addr, &response, sizeof(u32));
59
60 return response;
61}
62
63static inline void wl1251_write_elp(struct wl1251 *wl, int addr, u32 val)
64{
65 if (wl->if_ops->write_elp)
66 wl->if_ops->write_elp(wl, addr, val);
67 else
68 wl->if_ops->write(wl, addr, &val, sizeof(u32));
69}
70
71/* Memory target IO, address is translated to partition 0 */
72void wl1251_mem_read(struct wl1251 *wl, int addr, void *buf, size_t len);
73void wl1251_mem_write(struct wl1251 *wl, int addr, void *buf, size_t len);
74u32 wl1251_mem_read32(struct wl1251 *wl, int addr);
75void wl1251_mem_write32(struct wl1251 *wl, int addr, u32 val);
76/* Registers IO */
77u32 wl1251_reg_read32(struct wl1251 *wl, int addr);
78void wl1251_reg_write32(struct wl1251 *wl, int addr, u32 val);
79
80void wl1251_set_partition(struct wl1251 *wl,
81 u32 part_start, u32 part_size,
82 u32 reg_start, u32 reg_size);
83
84#endif
diff --git a/drivers/net/wireless/wl12xx/wl1251_main.c b/drivers/net/wireless/wl12xx/wl1251_main.c
deleted file mode 100644
index 861a5f33761e..000000000000
--- a/drivers/net/wireless/wl12xx/wl1251_main.c
+++ /dev/null
@@ -1,1442 +0,0 @@
1/*
2 * This file is part of wl1251
3 *
4 * Copyright (C) 2008-2009 Nokia Corporation
5 *
6 * Contact: Kalle Valo <kalle.valo@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include <linux/module.h>
25#include <linux/interrupt.h>
26#include <linux/firmware.h>
27#include <linux/delay.h>
28#include <linux/irq.h>
29#include <linux/crc32.h>
30#include <linux/etherdevice.h>
31#include <linux/vmalloc.h>
32#include <linux/slab.h>
33
34#include "wl1251.h"
35#include "wl12xx_80211.h"
36#include "wl1251_reg.h"
37#include "wl1251_io.h"
38#include "wl1251_cmd.h"
39#include "wl1251_event.h"
40#include "wl1251_tx.h"
41#include "wl1251_rx.h"
42#include "wl1251_ps.h"
43#include "wl1251_init.h"
44#include "wl1251_debugfs.h"
45#include "wl1251_boot.h"
46
47void wl1251_enable_interrupts(struct wl1251 *wl)
48{
49 wl->if_ops->enable_irq(wl);
50}
51
52void wl1251_disable_interrupts(struct wl1251 *wl)
53{
54 wl->if_ops->disable_irq(wl);
55}
56
57static void wl1251_power_off(struct wl1251 *wl)
58{
59 wl->set_power(false);
60}
61
62static void wl1251_power_on(struct wl1251 *wl)
63{
64 wl->set_power(true);
65}
66
67static int wl1251_fetch_firmware(struct wl1251 *wl)
68{
69 const struct firmware *fw;
70 struct device *dev = wiphy_dev(wl->hw->wiphy);
71 int ret;
72
73 ret = request_firmware(&fw, WL1251_FW_NAME, dev);
74
75 if (ret < 0) {
76 wl1251_error("could not get firmware: %d", ret);
77 return ret;
78 }
79
80 if (fw->size % 4) {
81 wl1251_error("firmware size is not multiple of 32 bits: %zu",
82 fw->size);
83 ret = -EILSEQ;
84 goto out;
85 }
86
87 wl->fw_len = fw->size;
88 wl->fw = vmalloc(wl->fw_len);
89
90 if (!wl->fw) {
91 wl1251_error("could not allocate memory for the firmware");
92 ret = -ENOMEM;
93 goto out;
94 }
95
96 memcpy(wl->fw, fw->data, wl->fw_len);
97
98 ret = 0;
99
100out:
101 release_firmware(fw);
102
103 return ret;
104}
105
106static int wl1251_fetch_nvs(struct wl1251 *wl)
107{
108 const struct firmware *fw;
109 struct device *dev = wiphy_dev(wl->hw->wiphy);
110 int ret;
111
112 ret = request_firmware(&fw, WL1251_NVS_NAME, dev);
113
114 if (ret < 0) {
115 wl1251_error("could not get nvs file: %d", ret);
116 return ret;
117 }
118
119 if (fw->size % 4) {
120 wl1251_error("nvs size is not multiple of 32 bits: %zu",
121 fw->size);
122 ret = -EILSEQ;
123 goto out;
124 }
125
126 wl->nvs_len = fw->size;
127 wl->nvs = kmemdup(fw->data, wl->nvs_len, GFP_KERNEL);
128
129 if (!wl->nvs) {
130 wl1251_error("could not allocate memory for the nvs file");
131 ret = -ENOMEM;
132 goto out;
133 }
134
135 ret = 0;
136
137out:
138 release_firmware(fw);
139
140 return ret;
141}
142
143static void wl1251_fw_wakeup(struct wl1251 *wl)
144{
145 u32 elp_reg;
146
147 elp_reg = ELPCTRL_WAKE_UP;
148 wl1251_write_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
149 elp_reg = wl1251_read_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
150
151 if (!(elp_reg & ELPCTRL_WLAN_READY))
152 wl1251_warning("WLAN not ready");
153}
154
155static int wl1251_chip_wakeup(struct wl1251 *wl)
156{
157 int ret = 0;
158
159 wl1251_power_on(wl);
160 msleep(WL1251_POWER_ON_SLEEP);
161 wl->if_ops->reset(wl);
162
163 /* We don't need a real memory partition here, because we only want
164 * to use the registers at this point. */
165 wl1251_set_partition(wl,
166 0x00000000,
167 0x00000000,
168 REGISTERS_BASE,
169 REGISTERS_DOWN_SIZE);
170
171 /* ELP module wake up */
172 wl1251_fw_wakeup(wl);
173
174 /* whal_FwCtrl_BootSm() */
175
176 /* 0. read chip id from CHIP_ID */
177 wl->chip_id = wl1251_reg_read32(wl, CHIP_ID_B);
178
179 /* 1. check if chip id is valid */
180
181 switch (wl->chip_id) {
182 case CHIP_ID_1251_PG12:
183 wl1251_debug(DEBUG_BOOT, "chip id 0x%x (1251 PG12)",
184 wl->chip_id);
185 break;
186 case CHIP_ID_1251_PG11:
187 wl1251_debug(DEBUG_BOOT, "chip id 0x%x (1251 PG11)",
188 wl->chip_id);
189 break;
190 case CHIP_ID_1251_PG10:
191 default:
192 wl1251_error("unsupported chip id: 0x%x", wl->chip_id);
193 ret = -ENODEV;
194 goto out;
195 }
196
197 if (wl->fw == NULL) {
198 ret = wl1251_fetch_firmware(wl);
199 if (ret < 0)
200 goto out;
201 }
202
203 if (wl->nvs == NULL && !wl->use_eeprom) {
204 /* No NVS from netlink, try to get it from the filesystem */
205 ret = wl1251_fetch_nvs(wl);
206 if (ret < 0)
207 goto out;
208 }
209
210out:
211 return ret;
212}
213
214#define WL1251_IRQ_LOOP_COUNT 10
215static void wl1251_irq_work(struct work_struct *work)
216{
217 u32 intr, ctr = WL1251_IRQ_LOOP_COUNT;
218 struct wl1251 *wl =
219 container_of(work, struct wl1251, irq_work);
220 int ret;
221
222 mutex_lock(&wl->mutex);
223
224 wl1251_debug(DEBUG_IRQ, "IRQ work");
225
226 if (wl->state == WL1251_STATE_OFF)
227 goto out;
228
229 ret = wl1251_ps_elp_wakeup(wl);
230 if (ret < 0)
231 goto out;
232
233 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_MASK, WL1251_ACX_INTR_ALL);
234
235 intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_CLEAR);
236 wl1251_debug(DEBUG_IRQ, "intr: 0x%x", intr);
237
238 do {
239 if (wl->data_path) {
240 wl->rx_counter = wl1251_mem_read32(
241 wl, wl->data_path->rx_control_addr);
242
243 /* We handle a frmware bug here */
244 switch ((wl->rx_counter - wl->rx_handled) & 0xf) {
245 case 0:
246 wl1251_debug(DEBUG_IRQ,
247 "RX: FW and host in sync");
248 intr &= ~WL1251_ACX_INTR_RX0_DATA;
249 intr &= ~WL1251_ACX_INTR_RX1_DATA;
250 break;
251 case 1:
252 wl1251_debug(DEBUG_IRQ, "RX: FW +1");
253 intr |= WL1251_ACX_INTR_RX0_DATA;
254 intr &= ~WL1251_ACX_INTR_RX1_DATA;
255 break;
256 case 2:
257 wl1251_debug(DEBUG_IRQ, "RX: FW +2");
258 intr |= WL1251_ACX_INTR_RX0_DATA;
259 intr |= WL1251_ACX_INTR_RX1_DATA;
260 break;
261 default:
262 wl1251_warning(
263 "RX: FW and host out of sync: %d",
264 wl->rx_counter - wl->rx_handled);
265 break;
266 }
267
268 wl->rx_handled = wl->rx_counter;
269
270 wl1251_debug(DEBUG_IRQ, "RX counter: %d",
271 wl->rx_counter);
272 }
273
274 intr &= wl->intr_mask;
275
276 if (intr == 0) {
277 wl1251_debug(DEBUG_IRQ, "INTR is 0");
278 goto out_sleep;
279 }
280
281 if (intr & WL1251_ACX_INTR_RX0_DATA) {
282 wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_RX0_DATA");
283 wl1251_rx(wl);
284 }
285
286 if (intr & WL1251_ACX_INTR_RX1_DATA) {
287 wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_RX1_DATA");
288 wl1251_rx(wl);
289 }
290
291 if (intr & WL1251_ACX_INTR_TX_RESULT) {
292 wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_TX_RESULT");
293 wl1251_tx_complete(wl);
294 }
295
296 if (intr & (WL1251_ACX_INTR_EVENT_A |
297 WL1251_ACX_INTR_EVENT_B)) {
298 wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_EVENT (0x%x)",
299 intr);
300 if (intr & WL1251_ACX_INTR_EVENT_A)
301 wl1251_event_handle(wl, 0);
302 else
303 wl1251_event_handle(wl, 1);
304 }
305
306 if (intr & WL1251_ACX_INTR_INIT_COMPLETE)
307 wl1251_debug(DEBUG_IRQ,
308 "WL1251_ACX_INTR_INIT_COMPLETE");
309
310 if (--ctr == 0)
311 break;
312
313 intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_CLEAR);
314 } while (intr);
315
316out_sleep:
317 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_MASK, ~(wl->intr_mask));
318 wl1251_ps_elp_sleep(wl);
319
320out:
321 mutex_unlock(&wl->mutex);
322}
323
324static int wl1251_join(struct wl1251 *wl, u8 bss_type, u8 channel,
325 u16 beacon_interval, u8 dtim_period)
326{
327 int ret;
328
329 ret = wl1251_acx_frame_rates(wl, DEFAULT_HW_GEN_TX_RATE,
330 DEFAULT_HW_GEN_MODULATION_TYPE,
331 wl->tx_mgmt_frm_rate,
332 wl->tx_mgmt_frm_mod);
333 if (ret < 0)
334 goto out;
335
336
337 ret = wl1251_cmd_join(wl, bss_type, channel, beacon_interval,
338 dtim_period);
339 if (ret < 0)
340 goto out;
341
342 /*
343 * FIXME: we should wait for JOIN_EVENT_COMPLETE_ID but to simplify
344 * locking we just sleep instead, for now
345 */
346 msleep(10);
347
348out:
349 return ret;
350}
351
352static void wl1251_filter_work(struct work_struct *work)
353{
354 struct wl1251 *wl =
355 container_of(work, struct wl1251, filter_work);
356 int ret;
357
358 mutex_lock(&wl->mutex);
359
360 if (wl->state == WL1251_STATE_OFF)
361 goto out;
362
363 ret = wl1251_ps_elp_wakeup(wl);
364 if (ret < 0)
365 goto out;
366
367 ret = wl1251_join(wl, wl->bss_type, wl->channel, wl->beacon_int,
368 wl->dtim_period);
369 if (ret < 0)
370 goto out_sleep;
371
372out_sleep:
373 wl1251_ps_elp_sleep(wl);
374
375out:
376 mutex_unlock(&wl->mutex);
377}
378
379static int wl1251_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
380{
381 struct wl1251 *wl = hw->priv;
382
383 skb_queue_tail(&wl->tx_queue, skb);
384
385 /*
386 * The chip specific setup must run before the first TX packet -
387 * before that, the tx_work will not be initialized!
388 */
389
390 ieee80211_queue_work(wl->hw, &wl->tx_work);
391
392 /*
393 * The workqueue is slow to process the tx_queue and we need stop
394 * the queue here, otherwise the queue will get too long.
395 */
396 if (skb_queue_len(&wl->tx_queue) >= WL1251_TX_QUEUE_MAX_LENGTH) {
397 wl1251_debug(DEBUG_TX, "op_tx: tx_queue full, stop queues");
398 ieee80211_stop_queues(wl->hw);
399
400 /*
401 * FIXME: this is racy, the variable is not properly
402 * protected. Maybe fix this by removing the stupid
403 * variable altogether and checking the real queue state?
404 */
405 wl->tx_queue_stopped = true;
406 }
407
408 return NETDEV_TX_OK;
409}
410
411static int wl1251_op_start(struct ieee80211_hw *hw)
412{
413 struct wl1251 *wl = hw->priv;
414 struct wiphy *wiphy = hw->wiphy;
415 int ret = 0;
416
417 wl1251_debug(DEBUG_MAC80211, "mac80211 start");
418
419 mutex_lock(&wl->mutex);
420
421 if (wl->state != WL1251_STATE_OFF) {
422 wl1251_error("cannot start because not in off state: %d",
423 wl->state);
424 ret = -EBUSY;
425 goto out;
426 }
427
428 ret = wl1251_chip_wakeup(wl);
429 if (ret < 0)
430 goto out;
431
432 ret = wl1251_boot(wl);
433 if (ret < 0)
434 goto out;
435
436 ret = wl1251_hw_init(wl);
437 if (ret < 0)
438 goto out;
439
440 ret = wl1251_acx_station_id(wl);
441 if (ret < 0)
442 goto out;
443
444 wl->state = WL1251_STATE_ON;
445
446 wl1251_info("firmware booted (%s)", wl->fw_ver);
447
448 /* update hw/fw version info in wiphy struct */
449 wiphy->hw_version = wl->chip_id;
450 strncpy(wiphy->fw_version, wl->fw_ver, sizeof(wiphy->fw_version));
451
452out:
453 if (ret < 0)
454 wl1251_power_off(wl);
455
456 mutex_unlock(&wl->mutex);
457
458 return ret;
459}
460
461static void wl1251_op_stop(struct ieee80211_hw *hw)
462{
463 struct wl1251 *wl = hw->priv;
464
465 wl1251_info("down");
466
467 wl1251_debug(DEBUG_MAC80211, "mac80211 stop");
468
469 mutex_lock(&wl->mutex);
470
471 WARN_ON(wl->state != WL1251_STATE_ON);
472
473 if (wl->scanning) {
474 mutex_unlock(&wl->mutex);
475 ieee80211_scan_completed(wl->hw, true);
476 mutex_lock(&wl->mutex);
477 wl->scanning = false;
478 }
479
480 wl->state = WL1251_STATE_OFF;
481
482 wl1251_disable_interrupts(wl);
483
484 mutex_unlock(&wl->mutex);
485
486 cancel_work_sync(&wl->irq_work);
487 cancel_work_sync(&wl->tx_work);
488 cancel_work_sync(&wl->filter_work);
489
490 mutex_lock(&wl->mutex);
491
492 /* let's notify MAC80211 about the remaining pending TX frames */
493 wl1251_tx_flush(wl);
494 wl1251_power_off(wl);
495
496 memset(wl->bssid, 0, ETH_ALEN);
497 wl->listen_int = 1;
498 wl->bss_type = MAX_BSS_TYPE;
499
500 wl->data_in_count = 0;
501 wl->rx_counter = 0;
502 wl->rx_handled = 0;
503 wl->rx_current_buffer = 0;
504 wl->rx_last_id = 0;
505 wl->next_tx_complete = 0;
506 wl->elp = false;
507 wl->psm = 0;
508 wl->tx_queue_stopped = false;
509 wl->power_level = WL1251_DEFAULT_POWER_LEVEL;
510 wl->channel = WL1251_DEFAULT_CHANNEL;
511
512 wl1251_debugfs_reset(wl);
513
514 mutex_unlock(&wl->mutex);
515}
516
517static int wl1251_op_add_interface(struct ieee80211_hw *hw,
518 struct ieee80211_vif *vif)
519{
520 struct wl1251 *wl = hw->priv;
521 int ret = 0;
522
523 wl1251_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
524 vif->type, vif->addr);
525
526 mutex_lock(&wl->mutex);
527 if (wl->vif) {
528 ret = -EBUSY;
529 goto out;
530 }
531
532 wl->vif = vif;
533
534 switch (vif->type) {
535 case NL80211_IFTYPE_STATION:
536 wl->bss_type = BSS_TYPE_STA_BSS;
537 break;
538 case NL80211_IFTYPE_ADHOC:
539 wl->bss_type = BSS_TYPE_IBSS;
540 break;
541 default:
542 ret = -EOPNOTSUPP;
543 goto out;
544 }
545
546 if (memcmp(wl->mac_addr, vif->addr, ETH_ALEN)) {
547 memcpy(wl->mac_addr, vif->addr, ETH_ALEN);
548 SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
549 ret = wl1251_acx_station_id(wl);
550 if (ret < 0)
551 goto out;
552 }
553
554out:
555 mutex_unlock(&wl->mutex);
556 return ret;
557}
558
559static void wl1251_op_remove_interface(struct ieee80211_hw *hw,
560 struct ieee80211_vif *vif)
561{
562 struct wl1251 *wl = hw->priv;
563
564 mutex_lock(&wl->mutex);
565 wl1251_debug(DEBUG_MAC80211, "mac80211 remove interface");
566 wl->vif = NULL;
567 mutex_unlock(&wl->mutex);
568}
569
570static int wl1251_build_qos_null_data(struct wl1251 *wl)
571{
572 struct ieee80211_qos_hdr template;
573
574 memset(&template, 0, sizeof(template));
575
576 memcpy(template.addr1, wl->bssid, ETH_ALEN);
577 memcpy(template.addr2, wl->mac_addr, ETH_ALEN);
578 memcpy(template.addr3, wl->bssid, ETH_ALEN);
579
580 template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
581 IEEE80211_STYPE_QOS_NULLFUNC |
582 IEEE80211_FCTL_TODS);
583
584 /* FIXME: not sure what priority to use here */
585 template.qos_ctrl = cpu_to_le16(0);
586
587 return wl1251_cmd_template_set(wl, CMD_QOS_NULL_DATA, &template,
588 sizeof(template));
589}
590
591static int wl1251_op_config(struct ieee80211_hw *hw, u32 changed)
592{
593 struct wl1251 *wl = hw->priv;
594 struct ieee80211_conf *conf = &hw->conf;
595 int channel, ret = 0;
596
597 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
598
599 wl1251_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d",
600 channel,
601 conf->flags & IEEE80211_CONF_PS ? "on" : "off",
602 conf->power_level);
603
604 mutex_lock(&wl->mutex);
605
606 ret = wl1251_ps_elp_wakeup(wl);
607 if (ret < 0)
608 goto out;
609
610 if (channel != wl->channel) {
611 wl->channel = channel;
612
613 ret = wl1251_join(wl, wl->bss_type, wl->channel,
614 wl->beacon_int, wl->dtim_period);
615 if (ret < 0)
616 goto out_sleep;
617 }
618
619 if (conf->flags & IEEE80211_CONF_PS && !wl->psm_requested) {
620 wl1251_debug(DEBUG_PSM, "psm enabled");
621
622 wl->psm_requested = true;
623
624 wl->dtim_period = conf->ps_dtim_period;
625
626 ret = wl1251_acx_wr_tbtt_and_dtim(wl, wl->beacon_int,
627 wl->dtim_period);
628
629 /*
630 * mac80211 enables PSM only if we're already associated.
631 */
632 ret = wl1251_ps_set_mode(wl, STATION_POWER_SAVE_MODE);
633 if (ret < 0)
634 goto out_sleep;
635 } else if (!(conf->flags & IEEE80211_CONF_PS) &&
636 wl->psm_requested) {
637 wl1251_debug(DEBUG_PSM, "psm disabled");
638
639 wl->psm_requested = false;
640
641 if (wl->psm) {
642 ret = wl1251_ps_set_mode(wl, STATION_ACTIVE_MODE);
643 if (ret < 0)
644 goto out_sleep;
645 }
646 }
647
648 if (conf->power_level != wl->power_level) {
649 ret = wl1251_acx_tx_power(wl, conf->power_level);
650 if (ret < 0)
651 goto out_sleep;
652
653 wl->power_level = conf->power_level;
654 }
655
656out_sleep:
657 wl1251_ps_elp_sleep(wl);
658
659out:
660 mutex_unlock(&wl->mutex);
661
662 return ret;
663}
664
665#define WL1251_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
666 FIF_ALLMULTI | \
667 FIF_FCSFAIL | \
668 FIF_BCN_PRBRESP_PROMISC | \
669 FIF_CONTROL | \
670 FIF_OTHER_BSS)
671
672static void wl1251_op_configure_filter(struct ieee80211_hw *hw,
673 unsigned int changed,
674 unsigned int *total,u64 multicast)
675{
676 struct wl1251 *wl = hw->priv;
677
678 wl1251_debug(DEBUG_MAC80211, "mac80211 configure filter");
679
680 *total &= WL1251_SUPPORTED_FILTERS;
681 changed &= WL1251_SUPPORTED_FILTERS;
682
683 if (changed == 0)
684 /* no filters which we support changed */
685 return;
686
687 /* FIXME: wl->rx_config and wl->rx_filter are not protected */
688
689 wl->rx_config = WL1251_DEFAULT_RX_CONFIG;
690 wl->rx_filter = WL1251_DEFAULT_RX_FILTER;
691
692 if (*total & FIF_PROMISC_IN_BSS) {
693 wl->rx_config |= CFG_BSSID_FILTER_EN;
694 wl->rx_config |= CFG_RX_ALL_GOOD;
695 }
696 if (*total & FIF_ALLMULTI)
697 /*
698 * CFG_MC_FILTER_EN in rx_config needs to be 0 to receive
699 * all multicast frames
700 */
701 wl->rx_config &= ~CFG_MC_FILTER_EN;
702 if (*total & FIF_FCSFAIL)
703 wl->rx_filter |= CFG_RX_FCS_ERROR;
704 if (*total & FIF_BCN_PRBRESP_PROMISC) {
705 wl->rx_config &= ~CFG_BSSID_FILTER_EN;
706 wl->rx_config &= ~CFG_SSID_FILTER_EN;
707 }
708 if (*total & FIF_CONTROL)
709 wl->rx_filter |= CFG_RX_CTL_EN;
710 if (*total & FIF_OTHER_BSS)
711 wl->rx_filter &= ~CFG_BSSID_FILTER_EN;
712
713 /*
714 * FIXME: workqueues need to be properly cancelled on stop(), for
715 * now let's just disable changing the filter settings. They will
716 * be updated any on config().
717 */
718 /* schedule_work(&wl->filter_work); */
719}
720
721/* HW encryption */
722static int wl1251_set_key_type(struct wl1251 *wl,
723 struct wl1251_cmd_set_keys *key,
724 enum set_key_cmd cmd,
725 struct ieee80211_key_conf *mac80211_key,
726 const u8 *addr)
727{
728 switch (mac80211_key->alg) {
729 case ALG_WEP:
730 if (is_broadcast_ether_addr(addr))
731 key->key_type = KEY_WEP_DEFAULT;
732 else
733 key->key_type = KEY_WEP_ADDR;
734
735 mac80211_key->hw_key_idx = mac80211_key->keyidx;
736 break;
737 case ALG_TKIP:
738 if (is_broadcast_ether_addr(addr))
739 key->key_type = KEY_TKIP_MIC_GROUP;
740 else
741 key->key_type = KEY_TKIP_MIC_PAIRWISE;
742
743 mac80211_key->hw_key_idx = mac80211_key->keyidx;
744 break;
745 case ALG_CCMP:
746 if (is_broadcast_ether_addr(addr))
747 key->key_type = KEY_AES_GROUP;
748 else
749 key->key_type = KEY_AES_PAIRWISE;
750 mac80211_key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
751 break;
752 default:
753 wl1251_error("Unknown key algo 0x%x", mac80211_key->alg);
754 return -EOPNOTSUPP;
755 }
756
757 return 0;
758}
759
760static int wl1251_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
761 struct ieee80211_vif *vif,
762 struct ieee80211_sta *sta,
763 struct ieee80211_key_conf *key)
764{
765 struct wl1251 *wl = hw->priv;
766 struct wl1251_cmd_set_keys *wl_cmd;
767 const u8 *addr;
768 int ret;
769
770 static const u8 bcast_addr[ETH_ALEN] =
771 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
772
773 wl1251_debug(DEBUG_MAC80211, "mac80211 set key");
774
775 wl_cmd = kzalloc(sizeof(*wl_cmd), GFP_KERNEL);
776 if (!wl_cmd) {
777 ret = -ENOMEM;
778 goto out;
779 }
780
781 addr = sta ? sta->addr : bcast_addr;
782
783 wl1251_debug(DEBUG_CRYPT, "CMD: 0x%x", cmd);
784 wl1251_dump(DEBUG_CRYPT, "ADDR: ", addr, ETH_ALEN);
785 wl1251_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
786 key->alg, key->keyidx, key->keylen, key->flags);
787 wl1251_dump(DEBUG_CRYPT, "KEY: ", key->key, key->keylen);
788
789 if (is_zero_ether_addr(addr)) {
790 /* We dont support TX only encryption */
791 ret = -EOPNOTSUPP;
792 goto out;
793 }
794
795 mutex_lock(&wl->mutex);
796
797 ret = wl1251_ps_elp_wakeup(wl);
798 if (ret < 0)
799 goto out_unlock;
800
801 switch (cmd) {
802 case SET_KEY:
803 wl_cmd->key_action = KEY_ADD_OR_REPLACE;
804 break;
805 case DISABLE_KEY:
806 wl_cmd->key_action = KEY_REMOVE;
807 break;
808 default:
809 wl1251_error("Unsupported key cmd 0x%x", cmd);
810 break;
811 }
812
813 ret = wl1251_set_key_type(wl, wl_cmd, cmd, key, addr);
814 if (ret < 0) {
815 wl1251_error("Set KEY type failed");
816 goto out_sleep;
817 }
818
819 if (wl_cmd->key_type != KEY_WEP_DEFAULT)
820 memcpy(wl_cmd->addr, addr, ETH_ALEN);
821
822 if ((wl_cmd->key_type == KEY_TKIP_MIC_GROUP) ||
823 (wl_cmd->key_type == KEY_TKIP_MIC_PAIRWISE)) {
824 /*
825 * We get the key in the following form:
826 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
827 * but the target is expecting:
828 * TKIP - RX MIC - TX MIC
829 */
830 memcpy(wl_cmd->key, key->key, 16);
831 memcpy(wl_cmd->key + 16, key->key + 24, 8);
832 memcpy(wl_cmd->key + 24, key->key + 16, 8);
833
834 } else {
835 memcpy(wl_cmd->key, key->key, key->keylen);
836 }
837 wl_cmd->key_size = key->keylen;
838
839 wl_cmd->id = key->keyidx;
840 wl_cmd->ssid_profile = 0;
841
842 wl1251_dump(DEBUG_CRYPT, "TARGET KEY: ", wl_cmd, sizeof(*wl_cmd));
843
844 ret = wl1251_cmd_send(wl, CMD_SET_KEYS, wl_cmd, sizeof(*wl_cmd));
845 if (ret < 0) {
846 wl1251_warning("could not set keys");
847 goto out_sleep;
848 }
849
850out_sleep:
851 wl1251_ps_elp_sleep(wl);
852
853out_unlock:
854 mutex_unlock(&wl->mutex);
855
856out:
857 kfree(wl_cmd);
858
859 return ret;
860}
861
862static int wl1251_op_hw_scan(struct ieee80211_hw *hw,
863 struct ieee80211_vif *vif,
864 struct cfg80211_scan_request *req)
865{
866 struct wl1251 *wl = hw->priv;
867 struct sk_buff *skb;
868 size_t ssid_len = 0;
869 u8 *ssid = NULL;
870 int ret;
871
872 wl1251_debug(DEBUG_MAC80211, "mac80211 hw scan");
873
874 if (req->n_ssids) {
875 ssid = req->ssids[0].ssid;
876 ssid_len = req->ssids[0].ssid_len;
877 }
878
879 mutex_lock(&wl->mutex);
880
881 if (wl->scanning) {
882 wl1251_debug(DEBUG_SCAN, "scan already in progress");
883 ret = -EINVAL;
884 goto out;
885 }
886
887 ret = wl1251_ps_elp_wakeup(wl);
888 if (ret < 0)
889 goto out;
890
891 skb = ieee80211_probereq_get(wl->hw, wl->vif, ssid, ssid_len,
892 req->ie, req->ie_len);
893 if (!skb) {
894 ret = -ENOMEM;
895 goto out;
896 }
897
898 ret = wl1251_cmd_template_set(wl, CMD_PROBE_REQ, skb->data,
899 skb->len);
900 dev_kfree_skb(skb);
901 if (ret < 0)
902 goto out_sleep;
903
904 ret = wl1251_cmd_trigger_scan_to(wl, 0);
905 if (ret < 0)
906 goto out_sleep;
907
908 wl->scanning = true;
909
910 ret = wl1251_cmd_scan(wl, ssid, ssid_len, req->channels,
911 req->n_channels, WL1251_SCAN_NUM_PROBES);
912 if (ret < 0) {
913 wl->scanning = false;
914 goto out_sleep;
915 }
916
917out_sleep:
918 wl1251_ps_elp_sleep(wl);
919
920out:
921 mutex_unlock(&wl->mutex);
922
923 return ret;
924}
925
926static int wl1251_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
927{
928 struct wl1251 *wl = hw->priv;
929 int ret;
930
931 mutex_lock(&wl->mutex);
932
933 ret = wl1251_ps_elp_wakeup(wl);
934 if (ret < 0)
935 goto out;
936
937 ret = wl1251_acx_rts_threshold(wl, (u16) value);
938 if (ret < 0)
939 wl1251_warning("wl1251_op_set_rts_threshold failed: %d", ret);
940
941 wl1251_ps_elp_sleep(wl);
942
943out:
944 mutex_unlock(&wl->mutex);
945
946 return ret;
947}
948
949static void wl1251_op_bss_info_changed(struct ieee80211_hw *hw,
950 struct ieee80211_vif *vif,
951 struct ieee80211_bss_conf *bss_conf,
952 u32 changed)
953{
954 struct wl1251 *wl = hw->priv;
955 struct sk_buff *beacon, *skb;
956 int ret;
957
958 wl1251_debug(DEBUG_MAC80211, "mac80211 bss info changed");
959
960 mutex_lock(&wl->mutex);
961
962 ret = wl1251_ps_elp_wakeup(wl);
963 if (ret < 0)
964 goto out;
965
966 if (changed & BSS_CHANGED_BSSID) {
967 memcpy(wl->bssid, bss_conf->bssid, ETH_ALEN);
968
969 skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
970 if (!skb)
971 goto out_sleep;
972
973 ret = wl1251_cmd_template_set(wl, CMD_NULL_DATA,
974 skb->data, skb->len);
975 dev_kfree_skb(skb);
976 if (ret < 0)
977 goto out_sleep;
978
979 ret = wl1251_build_qos_null_data(wl);
980 if (ret < 0)
981 goto out;
982
983 if (wl->bss_type != BSS_TYPE_IBSS) {
984 ret = wl1251_join(wl, wl->bss_type, wl->channel,
985 wl->beacon_int, wl->dtim_period);
986 if (ret < 0)
987 goto out_sleep;
988 }
989 }
990
991 if (changed & BSS_CHANGED_ASSOC) {
992 if (bss_conf->assoc) {
993 wl->beacon_int = bss_conf->beacon_int;
994
995 skb = ieee80211_pspoll_get(wl->hw, wl->vif);
996 if (!skb)
997 goto out_sleep;
998
999 ret = wl1251_cmd_template_set(wl, CMD_PS_POLL,
1000 skb->data,
1001 skb->len);
1002 dev_kfree_skb(skb);
1003 if (ret < 0)
1004 goto out_sleep;
1005
1006 ret = wl1251_acx_aid(wl, bss_conf->aid);
1007 if (ret < 0)
1008 goto out_sleep;
1009 } else {
1010 /* use defaults when not associated */
1011 wl->beacon_int = WL1251_DEFAULT_BEACON_INT;
1012 wl->dtim_period = WL1251_DEFAULT_DTIM_PERIOD;
1013 }
1014 }
1015 if (changed & BSS_CHANGED_ERP_SLOT) {
1016 if (bss_conf->use_short_slot)
1017 ret = wl1251_acx_slot(wl, SLOT_TIME_SHORT);
1018 else
1019 ret = wl1251_acx_slot(wl, SLOT_TIME_LONG);
1020 if (ret < 0) {
1021 wl1251_warning("Set slot time failed %d", ret);
1022 goto out_sleep;
1023 }
1024 }
1025
1026 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1027 if (bss_conf->use_short_preamble)
1028 wl1251_acx_set_preamble(wl, ACX_PREAMBLE_SHORT);
1029 else
1030 wl1251_acx_set_preamble(wl, ACX_PREAMBLE_LONG);
1031 }
1032
1033 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1034 if (bss_conf->use_cts_prot)
1035 ret = wl1251_acx_cts_protect(wl, CTSPROTECT_ENABLE);
1036 else
1037 ret = wl1251_acx_cts_protect(wl, CTSPROTECT_DISABLE);
1038 if (ret < 0) {
1039 wl1251_warning("Set ctsprotect failed %d", ret);
1040 goto out_sleep;
1041 }
1042 }
1043
1044 if (changed & BSS_CHANGED_BEACON) {
1045 beacon = ieee80211_beacon_get(hw, vif);
1046 ret = wl1251_cmd_template_set(wl, CMD_BEACON, beacon->data,
1047 beacon->len);
1048
1049 if (ret < 0) {
1050 dev_kfree_skb(beacon);
1051 goto out_sleep;
1052 }
1053
1054 ret = wl1251_cmd_template_set(wl, CMD_PROBE_RESP, beacon->data,
1055 beacon->len);
1056
1057 dev_kfree_skb(beacon);
1058
1059 if (ret < 0)
1060 goto out_sleep;
1061
1062 ret = wl1251_join(wl, wl->bss_type, wl->beacon_int,
1063 wl->channel, wl->dtim_period);
1064
1065 if (ret < 0)
1066 goto out_sleep;
1067 }
1068
1069out_sleep:
1070 wl1251_ps_elp_sleep(wl);
1071
1072out:
1073 mutex_unlock(&wl->mutex);
1074}
1075
1076
1077/* can't be const, mac80211 writes to this */
1078static struct ieee80211_rate wl1251_rates[] = {
1079 { .bitrate = 10,
1080 .hw_value = 0x1,
1081 .hw_value_short = 0x1, },
1082 { .bitrate = 20,
1083 .hw_value = 0x2,
1084 .hw_value_short = 0x2,
1085 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1086 { .bitrate = 55,
1087 .hw_value = 0x4,
1088 .hw_value_short = 0x4,
1089 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1090 { .bitrate = 110,
1091 .hw_value = 0x20,
1092 .hw_value_short = 0x20,
1093 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1094 { .bitrate = 60,
1095 .hw_value = 0x8,
1096 .hw_value_short = 0x8, },
1097 { .bitrate = 90,
1098 .hw_value = 0x10,
1099 .hw_value_short = 0x10, },
1100 { .bitrate = 120,
1101 .hw_value = 0x40,
1102 .hw_value_short = 0x40, },
1103 { .bitrate = 180,
1104 .hw_value = 0x80,
1105 .hw_value_short = 0x80, },
1106 { .bitrate = 240,
1107 .hw_value = 0x200,
1108 .hw_value_short = 0x200, },
1109 { .bitrate = 360,
1110 .hw_value = 0x400,
1111 .hw_value_short = 0x400, },
1112 { .bitrate = 480,
1113 .hw_value = 0x800,
1114 .hw_value_short = 0x800, },
1115 { .bitrate = 540,
1116 .hw_value = 0x1000,
1117 .hw_value_short = 0x1000, },
1118};
1119
1120/* can't be const, mac80211 writes to this */
1121static struct ieee80211_channel wl1251_channels[] = {
1122 { .hw_value = 1, .center_freq = 2412},
1123 { .hw_value = 2, .center_freq = 2417},
1124 { .hw_value = 3, .center_freq = 2422},
1125 { .hw_value = 4, .center_freq = 2427},
1126 { .hw_value = 5, .center_freq = 2432},
1127 { .hw_value = 6, .center_freq = 2437},
1128 { .hw_value = 7, .center_freq = 2442},
1129 { .hw_value = 8, .center_freq = 2447},
1130 { .hw_value = 9, .center_freq = 2452},
1131 { .hw_value = 10, .center_freq = 2457},
1132 { .hw_value = 11, .center_freq = 2462},
1133 { .hw_value = 12, .center_freq = 2467},
1134 { .hw_value = 13, .center_freq = 2472},
1135};
1136
1137static int wl1251_op_conf_tx(struct ieee80211_hw *hw, u16 queue,
1138 const struct ieee80211_tx_queue_params *params)
1139{
1140 enum wl1251_acx_ps_scheme ps_scheme;
1141 struct wl1251 *wl = hw->priv;
1142 int ret;
1143
1144 mutex_lock(&wl->mutex);
1145
1146 wl1251_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue);
1147
1148 ret = wl1251_ps_elp_wakeup(wl);
1149 if (ret < 0)
1150 goto out;
1151
1152 /* mac80211 uses units of 32 usec */
1153 ret = wl1251_acx_ac_cfg(wl, wl1251_tx_get_queue(queue),
1154 params->cw_min, params->cw_max,
1155 params->aifs, params->txop * 32);
1156 if (ret < 0)
1157 goto out_sleep;
1158
1159 if (params->uapsd)
1160 ps_scheme = WL1251_ACX_PS_SCHEME_UPSD_TRIGGER;
1161 else
1162 ps_scheme = WL1251_ACX_PS_SCHEME_LEGACY;
1163
1164 ret = wl1251_acx_tid_cfg(wl, wl1251_tx_get_queue(queue),
1165 CHANNEL_TYPE_EDCF,
1166 wl1251_tx_get_queue(queue), ps_scheme,
1167 WL1251_ACX_ACK_POLICY_LEGACY);
1168 if (ret < 0)
1169 goto out_sleep;
1170
1171out_sleep:
1172 wl1251_ps_elp_sleep(wl);
1173
1174out:
1175 mutex_unlock(&wl->mutex);
1176
1177 return ret;
1178}
1179
1180static int wl1251_op_get_survey(struct ieee80211_hw *hw, int idx,
1181 struct survey_info *survey)
1182{
1183 struct wl1251 *wl = hw->priv;
1184 struct ieee80211_conf *conf = &hw->conf;
1185
1186 if (idx != 0)
1187 return -ENOENT;
1188
1189 survey->channel = conf->channel;
1190 survey->filled = SURVEY_INFO_NOISE_DBM;
1191 survey->noise = wl->noise;
1192
1193 return 0;
1194}
1195
1196/* can't be const, mac80211 writes to this */
1197static struct ieee80211_supported_band wl1251_band_2ghz = {
1198 .channels = wl1251_channels,
1199 .n_channels = ARRAY_SIZE(wl1251_channels),
1200 .bitrates = wl1251_rates,
1201 .n_bitrates = ARRAY_SIZE(wl1251_rates),
1202};
1203
1204static const struct ieee80211_ops wl1251_ops = {
1205 .start = wl1251_op_start,
1206 .stop = wl1251_op_stop,
1207 .add_interface = wl1251_op_add_interface,
1208 .remove_interface = wl1251_op_remove_interface,
1209 .config = wl1251_op_config,
1210 .configure_filter = wl1251_op_configure_filter,
1211 .tx = wl1251_op_tx,
1212 .set_key = wl1251_op_set_key,
1213 .hw_scan = wl1251_op_hw_scan,
1214 .bss_info_changed = wl1251_op_bss_info_changed,
1215 .set_rts_threshold = wl1251_op_set_rts_threshold,
1216 .conf_tx = wl1251_op_conf_tx,
1217 .get_survey = wl1251_op_get_survey,
1218};
1219
1220static int wl1251_read_eeprom_byte(struct wl1251 *wl, off_t offset, u8 *data)
1221{
1222 unsigned long timeout;
1223
1224 wl1251_reg_write32(wl, EE_ADDR, offset);
1225 wl1251_reg_write32(wl, EE_CTL, EE_CTL_READ);
1226
1227 /* EE_CTL_READ clears when data is ready */
1228 timeout = jiffies + msecs_to_jiffies(100);
1229 while (1) {
1230 if (!(wl1251_reg_read32(wl, EE_CTL) & EE_CTL_READ))
1231 break;
1232
1233 if (time_after(jiffies, timeout))
1234 return -ETIMEDOUT;
1235
1236 msleep(1);
1237 }
1238
1239 *data = wl1251_reg_read32(wl, EE_DATA);
1240 return 0;
1241}
1242
1243static int wl1251_read_eeprom(struct wl1251 *wl, off_t offset,
1244 u8 *data, size_t len)
1245{
1246 size_t i;
1247 int ret;
1248
1249 wl1251_reg_write32(wl, EE_START, 0);
1250
1251 for (i = 0; i < len; i++) {
1252 ret = wl1251_read_eeprom_byte(wl, offset + i, &data[i]);
1253 if (ret < 0)
1254 return ret;
1255 }
1256
1257 return 0;
1258}
1259
1260static int wl1251_read_eeprom_mac(struct wl1251 *wl)
1261{
1262 u8 mac[ETH_ALEN];
1263 int i, ret;
1264
1265 wl1251_set_partition(wl, 0, 0, REGISTERS_BASE, REGISTERS_DOWN_SIZE);
1266
1267 ret = wl1251_read_eeprom(wl, 0x1c, mac, sizeof(mac));
1268 if (ret < 0) {
1269 wl1251_warning("failed to read MAC address from EEPROM");
1270 return ret;
1271 }
1272
1273 /* MAC is stored in reverse order */
1274 for (i = 0; i < ETH_ALEN; i++)
1275 wl->mac_addr[i] = mac[ETH_ALEN - i - 1];
1276
1277 return 0;
1278}
1279
1280static int wl1251_register_hw(struct wl1251 *wl)
1281{
1282 int ret;
1283
1284 if (wl->mac80211_registered)
1285 return 0;
1286
1287 SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
1288
1289 ret = ieee80211_register_hw(wl->hw);
1290 if (ret < 0) {
1291 wl1251_error("unable to register mac80211 hw: %d", ret);
1292 return ret;
1293 }
1294
1295 wl->mac80211_registered = true;
1296
1297 wl1251_notice("loaded");
1298
1299 return 0;
1300}
1301
1302int wl1251_init_ieee80211(struct wl1251 *wl)
1303{
1304 int ret;
1305
1306 /* The tx descriptor buffer and the TKIP space */
1307 wl->hw->extra_tx_headroom = sizeof(struct tx_double_buffer_desc)
1308 + WL1251_TKIP_IV_SPACE;
1309
1310 /* unit us */
1311 /* FIXME: find a proper value */
1312 wl->hw->channel_change_time = 10000;
1313
1314 wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
1315 IEEE80211_HW_SUPPORTS_PS |
1316 IEEE80211_HW_BEACON_FILTER |
1317 IEEE80211_HW_SUPPORTS_UAPSD;
1318
1319 wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1320 wl->hw->wiphy->max_scan_ssids = 1;
1321 wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl1251_band_2ghz;
1322
1323 wl->hw->queues = 4;
1324
1325 if (wl->use_eeprom)
1326 wl1251_read_eeprom_mac(wl);
1327
1328 ret = wl1251_register_hw(wl);
1329 if (ret)
1330 goto out;
1331
1332 wl1251_debugfs_init(wl);
1333 wl1251_notice("initialized");
1334
1335 ret = 0;
1336
1337out:
1338 return ret;
1339}
1340EXPORT_SYMBOL_GPL(wl1251_init_ieee80211);
1341
1342struct ieee80211_hw *wl1251_alloc_hw(void)
1343{
1344 struct ieee80211_hw *hw;
1345 struct wl1251 *wl;
1346 int i;
1347 static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf};
1348
1349 hw = ieee80211_alloc_hw(sizeof(*wl), &wl1251_ops);
1350 if (!hw) {
1351 wl1251_error("could not alloc ieee80211_hw");
1352 return ERR_PTR(-ENOMEM);
1353 }
1354
1355 wl = hw->priv;
1356 memset(wl, 0, sizeof(*wl));
1357
1358 wl->hw = hw;
1359
1360 wl->data_in_count = 0;
1361
1362 skb_queue_head_init(&wl->tx_queue);
1363
1364 INIT_WORK(&wl->filter_work, wl1251_filter_work);
1365 INIT_DELAYED_WORK(&wl->elp_work, wl1251_elp_work);
1366 wl->channel = WL1251_DEFAULT_CHANNEL;
1367 wl->scanning = false;
1368 wl->default_key = 0;
1369 wl->listen_int = 1;
1370 wl->rx_counter = 0;
1371 wl->rx_handled = 0;
1372 wl->rx_current_buffer = 0;
1373 wl->rx_last_id = 0;
1374 wl->rx_config = WL1251_DEFAULT_RX_CONFIG;
1375 wl->rx_filter = WL1251_DEFAULT_RX_FILTER;
1376 wl->elp = false;
1377 wl->psm = 0;
1378 wl->psm_requested = false;
1379 wl->tx_queue_stopped = false;
1380 wl->power_level = WL1251_DEFAULT_POWER_LEVEL;
1381 wl->beacon_int = WL1251_DEFAULT_BEACON_INT;
1382 wl->dtim_period = WL1251_DEFAULT_DTIM_PERIOD;
1383 wl->vif = NULL;
1384
1385 for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
1386 wl->tx_frames[i] = NULL;
1387
1388 wl->next_tx_complete = 0;
1389
1390 INIT_WORK(&wl->irq_work, wl1251_irq_work);
1391 INIT_WORK(&wl->tx_work, wl1251_tx_work);
1392
1393 /*
1394 * In case our MAC address is not correctly set,
1395 * we use a random but Nokia MAC.
1396 */
1397 memcpy(wl->mac_addr, nokia_oui, 3);
1398 get_random_bytes(wl->mac_addr + 3, 3);
1399
1400 wl->state = WL1251_STATE_OFF;
1401 mutex_init(&wl->mutex);
1402
1403 wl->tx_mgmt_frm_rate = DEFAULT_HW_GEN_TX_RATE;
1404 wl->tx_mgmt_frm_mod = DEFAULT_HW_GEN_MODULATION_TYPE;
1405
1406 wl->rx_descriptor = kmalloc(sizeof(*wl->rx_descriptor), GFP_KERNEL);
1407 if (!wl->rx_descriptor) {
1408 wl1251_error("could not allocate memory for rx descriptor");
1409 ieee80211_free_hw(hw);
1410 return ERR_PTR(-ENOMEM);
1411 }
1412
1413 return hw;
1414}
1415EXPORT_SYMBOL_GPL(wl1251_alloc_hw);
1416
1417int wl1251_free_hw(struct wl1251 *wl)
1418{
1419 ieee80211_unregister_hw(wl->hw);
1420
1421 wl1251_debugfs_exit(wl);
1422
1423 kfree(wl->target_mem_map);
1424 kfree(wl->data_path);
1425 vfree(wl->fw);
1426 wl->fw = NULL;
1427 kfree(wl->nvs);
1428 wl->nvs = NULL;
1429
1430 kfree(wl->rx_descriptor);
1431 wl->rx_descriptor = NULL;
1432
1433 ieee80211_free_hw(wl->hw);
1434
1435 return 0;
1436}
1437EXPORT_SYMBOL_GPL(wl1251_free_hw);
1438
1439MODULE_DESCRIPTION("TI wl1251 Wireles LAN Driver Core");
1440MODULE_LICENSE("GPL");
1441MODULE_AUTHOR("Kalle Valo <kalle.valo@nokia.com>");
1442MODULE_FIRMWARE(WL1251_FW_NAME);
diff --git a/drivers/net/wireless/wl12xx/wl1251_ps.c b/drivers/net/wireless/wl12xx/wl1251_ps.c
deleted file mode 100644
index b55cb2bd459a..000000000000
--- a/drivers/net/wireless/wl12xx/wl1251_ps.c
+++ /dev/null
@@ -1,196 +0,0 @@
1/*
2 * This file is part of wl1251
3 *
4 * Copyright (C) 2008 Nokia Corporation
5 *
6 * Contact: Kalle Valo <kalle.valo@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include "wl1251_reg.h"
25#include "wl1251_ps.h"
26#include "wl1251_cmd.h"
27#include "wl1251_io.h"
28
29/* in ms */
30#define WL1251_WAKEUP_TIMEOUT 100
31
32void wl1251_elp_work(struct work_struct *work)
33{
34 struct delayed_work *dwork;
35 struct wl1251 *wl;
36
37 dwork = container_of(work, struct delayed_work, work);
38 wl = container_of(dwork, struct wl1251, elp_work);
39
40 wl1251_debug(DEBUG_PSM, "elp work");
41
42 mutex_lock(&wl->mutex);
43
44 if (wl->elp || !wl->psm)
45 goto out;
46
47 wl1251_debug(DEBUG_PSM, "chip to elp");
48 wl1251_write_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP);
49 wl->elp = true;
50
51out:
52 mutex_unlock(&wl->mutex);
53}
54
55#define ELP_ENTRY_DELAY 5
56
57/* Routines to toggle sleep mode while in ELP */
58void wl1251_ps_elp_sleep(struct wl1251 *wl)
59{
60 unsigned long delay;
61
62 if (wl->psm) {
63 cancel_delayed_work(&wl->elp_work);
64 delay = msecs_to_jiffies(ELP_ENTRY_DELAY);
65 ieee80211_queue_delayed_work(wl->hw, &wl->elp_work, delay);
66 }
67}
68
69int wl1251_ps_elp_wakeup(struct wl1251 *wl)
70{
71 unsigned long timeout, start;
72 u32 elp_reg;
73
74 if (!wl->elp)
75 return 0;
76
77 wl1251_debug(DEBUG_PSM, "waking up chip from elp");
78
79 start = jiffies;
80 timeout = jiffies + msecs_to_jiffies(WL1251_WAKEUP_TIMEOUT);
81
82 wl1251_write_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_WAKE_UP);
83
84 elp_reg = wl1251_read_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
85
86 /*
87 * FIXME: we should wait for irq from chip but, as a temporary
88 * solution to simplify locking, let's poll instead
89 */
90 while (!(elp_reg & ELPCTRL_WLAN_READY)) {
91 if (time_after(jiffies, timeout)) {
92 wl1251_error("elp wakeup timeout");
93 return -ETIMEDOUT;
94 }
95 msleep(1);
96 elp_reg = wl1251_read_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
97 }
98
99 wl1251_debug(DEBUG_PSM, "wakeup time: %u ms",
100 jiffies_to_msecs(jiffies - start));
101
102 wl->elp = false;
103
104 return 0;
105}
106
107static int wl1251_ps_set_elp(struct wl1251 *wl, bool enable)
108{
109 int ret;
110
111 if (enable) {
112 wl1251_debug(DEBUG_PSM, "sleep auth psm/elp");
113
114 ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_ELP);
115 if (ret < 0)
116 return ret;
117
118 wl1251_ps_elp_sleep(wl);
119 } else {
120 wl1251_debug(DEBUG_PSM, "sleep auth cam");
121
122 /*
123 * When the target is in ELP, we can only
124 * access the ELP control register. Thus,
125 * we have to wake the target up before
126 * changing the power authorization.
127 */
128
129 wl1251_ps_elp_wakeup(wl);
130
131 ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_CAM);
132 if (ret < 0)
133 return ret;
134 }
135
136 return 0;
137}
138
139int wl1251_ps_set_mode(struct wl1251 *wl, enum wl1251_cmd_ps_mode mode)
140{
141 int ret;
142
143 switch (mode) {
144 case STATION_POWER_SAVE_MODE:
145 wl1251_debug(DEBUG_PSM, "entering psm");
146
147 /* enable beacon filtering */
148 ret = wl1251_acx_beacon_filter_opt(wl, true);
149 if (ret < 0)
150 return ret;
151
152 ret = wl1251_acx_wake_up_conditions(wl,
153 WAKE_UP_EVENT_DTIM_BITMAP,
154 wl->listen_int);
155 if (ret < 0)
156 return ret;
157
158 ret = wl1251_cmd_ps_mode(wl, STATION_POWER_SAVE_MODE);
159 if (ret < 0)
160 return ret;
161
162 ret = wl1251_ps_set_elp(wl, true);
163 if (ret < 0)
164 return ret;
165
166 wl->psm = 1;
167 break;
168 case STATION_ACTIVE_MODE:
169 default:
170 wl1251_debug(DEBUG_PSM, "leaving psm");
171 ret = wl1251_ps_set_elp(wl, false);
172 if (ret < 0)
173 return ret;
174
175 /* disable beacon filtering */
176 ret = wl1251_acx_beacon_filter_opt(wl, false);
177 if (ret < 0)
178 return ret;
179
180 ret = wl1251_acx_wake_up_conditions(wl,
181 WAKE_UP_EVENT_DTIM_BITMAP,
182 wl->listen_int);
183 if (ret < 0)
184 return ret;
185
186 ret = wl1251_cmd_ps_mode(wl, STATION_ACTIVE_MODE);
187 if (ret < 0)
188 return ret;
189
190 wl->psm = 0;
191 break;
192 }
193
194 return ret;
195}
196
diff --git a/drivers/net/wireless/wl12xx/wl1251_ps.h b/drivers/net/wireless/wl12xx/wl1251_ps.h
deleted file mode 100644
index c688ac57aee4..000000000000
--- a/drivers/net/wireless/wl12xx/wl1251_ps.h
+++ /dev/null
@@ -1,37 +0,0 @@
1#ifndef __WL1251_PS_H__
2#define __WL1251_PS_H__
3
4/*
5 * This file is part of wl1251
6 *
7 * Copyright (c) 1998-2007 Texas Instruments Incorporated
8 * Copyright (C) 2008 Nokia Corporation
9 *
10 * Contact: Kalle Valo <kalle.valo@nokia.com>
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * version 2 as published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 * 02110-1301 USA
25 *
26 */
27
28#include "wl1251.h"
29#include "wl1251_acx.h"
30
31int wl1251_ps_set_mode(struct wl1251 *wl, enum wl1251_cmd_ps_mode mode);
32void wl1251_ps_elp_sleep(struct wl1251 *wl);
33int wl1251_ps_elp_wakeup(struct wl1251 *wl);
34void wl1251_elp_work(struct work_struct *work);
35
36
37#endif /* __WL1251_PS_H__ */
diff --git a/drivers/net/wireless/wl12xx/wl1251_reg.h b/drivers/net/wireless/wl12xx/wl1251_reg.h
deleted file mode 100644
index d16edd9bf06c..000000000000
--- a/drivers/net/wireless/wl12xx/wl1251_reg.h
+++ /dev/null
@@ -1,657 +0,0 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation
6 *
7 * Contact: Kalle Valo <kalle.valo@nokia.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25#ifndef __REG_H__
26#define __REG_H__
27
28#include <linux/bitops.h>
29
30#define REGISTERS_BASE 0x00300000
31#define DRPW_BASE 0x00310000
32
33#define REGISTERS_DOWN_SIZE 0x00008800
34#define REGISTERS_WORK_SIZE 0x0000b000
35
36#define HW_ACCESS_ELP_CTRL_REG_ADDR 0x1FFFC
37
38/* ELP register commands */
39#define ELPCTRL_WAKE_UP 0x1
40#define ELPCTRL_WAKE_UP_WLAN_READY 0x5
41#define ELPCTRL_SLEEP 0x0
42/* ELP WLAN_READY bit */
43#define ELPCTRL_WLAN_READY 0x2
44
45/* Device Configuration registers*/
46#define SOR_CFG (REGISTERS_BASE + 0x0800)
47#define ECPU_CTRL (REGISTERS_BASE + 0x0804)
48#define HI_CFG (REGISTERS_BASE + 0x0808)
49
50/* EEPROM registers */
51#define EE_START (REGISTERS_BASE + 0x080C)
52#define EE_CTL (REGISTERS_BASE + 0x2000)
53#define EE_DATA (REGISTERS_BASE + 0x2004)
54#define EE_ADDR (REGISTERS_BASE + 0x2008)
55
56#define EE_CTL_READ 2
57
58#define CHIP_ID_B (REGISTERS_BASE + 0x5674)
59
60#define CHIP_ID_1251_PG10 (0x7010101)
61#define CHIP_ID_1251_PG11 (0x7020101)
62#define CHIP_ID_1251_PG12 (0x7030101)
63
64#define ENABLE (REGISTERS_BASE + 0x5450)
65
66/* Power Management registers */
67#define ELP_CFG_MODE (REGISTERS_BASE + 0x5804)
68#define ELP_CMD (REGISTERS_BASE + 0x5808)
69#define PLL_CAL_TIME (REGISTERS_BASE + 0x5810)
70#define CLK_REQ_TIME (REGISTERS_BASE + 0x5814)
71#define CLK_BUF_TIME (REGISTERS_BASE + 0x5818)
72
73#define CFG_PLL_SYNC_CNT (REGISTERS_BASE + 0x5820)
74
75/* Scratch Pad registers*/
76#define SCR_PAD0 (REGISTERS_BASE + 0x5608)
77#define SCR_PAD1 (REGISTERS_BASE + 0x560C)
78#define SCR_PAD2 (REGISTERS_BASE + 0x5610)
79#define SCR_PAD3 (REGISTERS_BASE + 0x5614)
80#define SCR_PAD4 (REGISTERS_BASE + 0x5618)
81#define SCR_PAD4_SET (REGISTERS_BASE + 0x561C)
82#define SCR_PAD4_CLR (REGISTERS_BASE + 0x5620)
83#define SCR_PAD5 (REGISTERS_BASE + 0x5624)
84#define SCR_PAD5_SET (REGISTERS_BASE + 0x5628)
85#define SCR_PAD5_CLR (REGISTERS_BASE + 0x562C)
86#define SCR_PAD6 (REGISTERS_BASE + 0x5630)
87#define SCR_PAD7 (REGISTERS_BASE + 0x5634)
88#define SCR_PAD8 (REGISTERS_BASE + 0x5638)
89#define SCR_PAD9 (REGISTERS_BASE + 0x563C)
90
91/* Spare registers*/
92#define SPARE_A1 (REGISTERS_BASE + 0x0994)
93#define SPARE_A2 (REGISTERS_BASE + 0x0998)
94#define SPARE_A3 (REGISTERS_BASE + 0x099C)
95#define SPARE_A4 (REGISTERS_BASE + 0x09A0)
96#define SPARE_A5 (REGISTERS_BASE + 0x09A4)
97#define SPARE_A6 (REGISTERS_BASE + 0x09A8)
98#define SPARE_A7 (REGISTERS_BASE + 0x09AC)
99#define SPARE_A8 (REGISTERS_BASE + 0x09B0)
100#define SPARE_B1 (REGISTERS_BASE + 0x5420)
101#define SPARE_B2 (REGISTERS_BASE + 0x5424)
102#define SPARE_B3 (REGISTERS_BASE + 0x5428)
103#define SPARE_B4 (REGISTERS_BASE + 0x542C)
104#define SPARE_B5 (REGISTERS_BASE + 0x5430)
105#define SPARE_B6 (REGISTERS_BASE + 0x5434)
106#define SPARE_B7 (REGISTERS_BASE + 0x5438)
107#define SPARE_B8 (REGISTERS_BASE + 0x543C)
108
109enum wl12xx_acx_int_reg {
110 ACX_REG_INTERRUPT_TRIG,
111 ACX_REG_INTERRUPT_TRIG_H,
112
113/*=============================================
114 Host Interrupt Mask Register - 32bit (RW)
115 ------------------------------------------
116 Setting a bit in this register masks the
117 corresponding interrupt to the host.
118 0 - RX0 - Rx first dubble buffer Data Interrupt
119 1 - TXD - Tx Data Interrupt
120 2 - TXXFR - Tx Transfer Interrupt
121 3 - RX1 - Rx second dubble buffer Data Interrupt
122 4 - RXXFR - Rx Transfer Interrupt
123 5 - EVENT_A - Event Mailbox interrupt
124 6 - EVENT_B - Event Mailbox interrupt
125 7 - WNONHST - Wake On Host Interrupt
126 8 - TRACE_A - Debug Trace interrupt
127 9 - TRACE_B - Debug Trace interrupt
128 10 - CDCMP - Command Complete Interrupt
129 11 -
130 12 -
131 13 -
132 14 - ICOMP - Initialization Complete Interrupt
133 16 - SG SE - Soft Gemini - Sense enable interrupt
134 17 - SG SD - Soft Gemini - Sense disable interrupt
135 18 - -
136 19 - -
137 20 - -
138 21- -
139 Default: 0x0001
140*==============================================*/
141 ACX_REG_INTERRUPT_MASK,
142
143/*=============================================
144 Host Interrupt Mask Set 16bit, (Write only)
145 ------------------------------------------
146 Setting a bit in this register sets
147 the corresponding bin in ACX_HINT_MASK register
148 without effecting the mask
149 state of other bits (0 = no effect).
150==============================================*/
151 ACX_REG_HINT_MASK_SET,
152
153/*=============================================
154 Host Interrupt Mask Clear 16bit,(Write only)
155 ------------------------------------------
156 Setting a bit in this register clears
157 the corresponding bin in ACX_HINT_MASK register
158 without effecting the mask
159 state of other bits (0 = no effect).
160=============================================*/
161 ACX_REG_HINT_MASK_CLR,
162
163/*=============================================
164 Host Interrupt Status Nondestructive Read
165 16bit,(Read only)
166 ------------------------------------------
167 The host can read this register to determine
168 which interrupts are active.
169 Reading this register doesn't
170 effect its content.
171=============================================*/
172 ACX_REG_INTERRUPT_NO_CLEAR,
173
174/*=============================================
175 Host Interrupt Status Clear on Read Register
176 16bit,(Read only)
177 ------------------------------------------
178 The host can read this register to determine
179 which interrupts are active.
180 Reading this register clears it,
181 thus making all interrupts inactive.
182==============================================*/
183 ACX_REG_INTERRUPT_CLEAR,
184
185/*=============================================
186 Host Interrupt Acknowledge Register
187 16bit,(Write only)
188 ------------------------------------------
189 The host can set individual bits in this
190 register to clear (acknowledge) the corresp.
191 interrupt status bits in the HINT_STS_CLR and
192 HINT_STS_ND registers, thus making the
193 assotiated interrupt inactive. (0-no effect)
194==============================================*/
195 ACX_REG_INTERRUPT_ACK,
196
197/*===============================================
198 Host Software Reset - 32bit RW
199 ------------------------------------------
200 [31:1] Reserved
201 0 SOFT_RESET Soft Reset - When this bit is set,
202 it holds the Wlan hardware in a soft reset state.
203 This reset disables all MAC and baseband processor
204 clocks except the CardBus/PCI interface clock.
205 It also initializes all MAC state machines except
206 the host interface. It does not reload the
207 contents of the EEPROM. When this bit is cleared
208 (not self-clearing), the Wlan hardware
209 exits the software reset state.
210===============================================*/
211 ACX_REG_SLV_SOFT_RESET,
212
213/*===============================================
214 EEPROM Burst Read Start - 32bit RW
215 ------------------------------------------
216 [31:1] Reserved
217 0 ACX_EE_START - EEPROM Burst Read Start 0
218 Setting this bit starts a burst read from
219 the external EEPROM.
220 If this bit is set (after reset) before an EEPROM read/write,
221 the burst read starts at EEPROM address 0.
222 Otherwise, it starts at the address
223 following the address of the previous access.
224 TheWlan hardware hardware clears this bit automatically.
225
226 Default: 0x00000000
227*================================================*/
228 ACX_REG_EE_START,
229
230/* Embedded ARM CPU Control */
231
232/*===============================================
233 Halt eCPU - 32bit RW
234 ------------------------------------------
235 0 HALT_ECPU Halt Embedded CPU - This bit is the
236 compliment of bit 1 (MDATA2) in the SOR_CFG register.
237 During a hardware reset, this bit holds
238 the inverse of MDATA2.
239 When downloading firmware from the host,
240 set this bit (pull down MDATA2).
241 The host clears this bit after downloading the firmware into
242 zero-wait-state SSRAM.
243 When loading firmware from Flash, clear this bit (pull up MDATA2)
244 so that the eCPU can run the bootloader code in Flash
245 HALT_ECPU eCPU State
246 --------------------
247 1 halt eCPU
248 0 enable eCPU
249 ===============================================*/
250 ACX_REG_ECPU_CONTROL,
251
252 ACX_REG_TABLE_LEN
253};
254
255#define ACX_SLV_SOFT_RESET_BIT BIT(0)
256#define ACX_REG_EEPROM_START_BIT BIT(0)
257
258/* Command/Information Mailbox Pointers */
259
260/*===============================================
261 Command Mailbox Pointer - 32bit RW
262 ------------------------------------------
263 This register holds the start address of
264 the command mailbox located in the Wlan hardware memory.
265 The host must read this pointer after a reset to
266 find the location of the command mailbox.
267 The Wlan hardware initializes the command mailbox
268 pointer with the default address of the command mailbox.
269 The command mailbox pointer is not valid until after
270 the host receives the Init Complete interrupt from
271 the Wlan hardware.
272 ===============================================*/
273#define REG_COMMAND_MAILBOX_PTR (SCR_PAD0)
274
275/*===============================================
276 Information Mailbox Pointer - 32bit RW
277 ------------------------------------------
278 This register holds the start address of
279 the information mailbox located in the Wlan hardware memory.
280 The host must read this pointer after a reset to find
281 the location of the information mailbox.
282 The Wlan hardware initializes the information mailbox pointer
283 with the default address of the information mailbox.
284 The information mailbox pointer is not valid
285 until after the host receives the Init Complete interrupt from
286 the Wlan hardware.
287 ===============================================*/
288#define REG_EVENT_MAILBOX_PTR (SCR_PAD1)
289
290
291/* Misc */
292
293#define REG_ENABLE_TX_RX (ENABLE)
294/*
295 * Rx configuration (filter) information element
296 * ---------------------------------------------
297 */
298#define REG_RX_CONFIG (RX_CFG)
299#define REG_RX_FILTER (RX_FILTER_CFG)
300
301
302#define RX_CFG_ENABLE_PHY_HEADER_PLCP 0x0002
303
304/* promiscuous - receives all valid frames */
305#define RX_CFG_PROMISCUOUS 0x0008
306
307/* receives frames from any BSSID */
308#define RX_CFG_BSSID 0x0020
309
310/* receives frames destined to any MAC address */
311#define RX_CFG_MAC 0x0010
312
313#define RX_CFG_ENABLE_ONLY_MY_DEST_MAC 0x0010
314#define RX_CFG_ENABLE_ANY_DEST_MAC 0x0000
315#define RX_CFG_ENABLE_ONLY_MY_BSSID 0x0020
316#define RX_CFG_ENABLE_ANY_BSSID 0x0000
317
318/* discards all broadcast frames */
319#define RX_CFG_DISABLE_BCAST 0x0200
320
321#define RX_CFG_ENABLE_ONLY_MY_SSID 0x0400
322#define RX_CFG_ENABLE_RX_CMPLT_FCS_ERROR 0x0800
323#define RX_CFG_COPY_RX_STATUS 0x2000
324#define RX_CFG_TSF 0x10000
325
326#define RX_CONFIG_OPTION_ANY_DST_MY_BSS (RX_CFG_ENABLE_ANY_DEST_MAC | \
327 RX_CFG_ENABLE_ONLY_MY_BSSID)
328
329#define RX_CONFIG_OPTION_MY_DST_ANY_BSS (RX_CFG_ENABLE_ONLY_MY_DEST_MAC\
330 | RX_CFG_ENABLE_ANY_BSSID)
331
332#define RX_CONFIG_OPTION_ANY_DST_ANY_BSS (RX_CFG_ENABLE_ANY_DEST_MAC | \
333 RX_CFG_ENABLE_ANY_BSSID)
334
335#define RX_CONFIG_OPTION_MY_DST_MY_BSS (RX_CFG_ENABLE_ONLY_MY_DEST_MAC\
336 | RX_CFG_ENABLE_ONLY_MY_BSSID)
337
338#define RX_CONFIG_OPTION_FOR_SCAN (RX_CFG_ENABLE_PHY_HEADER_PLCP \
339 | RX_CFG_ENABLE_RX_CMPLT_FCS_ERROR \
340 | RX_CFG_COPY_RX_STATUS | RX_CFG_TSF)
341
342#define RX_CONFIG_OPTION_FOR_MEASUREMENT (RX_CFG_ENABLE_ANY_DEST_MAC)
343
344#define RX_CONFIG_OPTION_FOR_JOIN (RX_CFG_ENABLE_ONLY_MY_BSSID | \
345 RX_CFG_ENABLE_ONLY_MY_DEST_MAC)
346
347#define RX_CONFIG_OPTION_FOR_IBSS_JOIN (RX_CFG_ENABLE_ONLY_MY_SSID | \
348 RX_CFG_ENABLE_ONLY_MY_DEST_MAC)
349
350#define RX_FILTER_OPTION_DEF (CFG_RX_MGMT_EN | CFG_RX_DATA_EN\
351 | CFG_RX_CTL_EN | CFG_RX_BCN_EN\
352 | CFG_RX_AUTH_EN | CFG_RX_ASSOC_EN)
353
354#define RX_FILTER_OPTION_FILTER_ALL 0
355
356#define RX_FILTER_OPTION_DEF_PRSP_BCN (CFG_RX_PRSP_EN | CFG_RX_MGMT_EN\
357 | CFG_RX_RCTS_ACK | CFG_RX_BCN_EN)
358
359#define RX_FILTER_OPTION_JOIN (CFG_RX_MGMT_EN | CFG_RX_DATA_EN\
360 | CFG_RX_BCN_EN | CFG_RX_AUTH_EN\
361 | CFG_RX_ASSOC_EN | CFG_RX_RCTS_ACK\
362 | CFG_RX_PRSP_EN)
363
364
365/*===============================================
366 EEPROM Read/Write Request 32bit RW
367 ------------------------------------------
368 1 EE_READ - EEPROM Read Request 1 - Setting this bit
369 loads a single byte of data into the EE_DATA
370 register from the EEPROM location specified in
371 the EE_ADDR register.
372 The Wlan hardware hardware clears this bit automatically.
373 EE_DATA is valid when this bit is cleared.
374
375 0 EE_WRITE - EEPROM Write Request - Setting this bit
376 writes a single byte of data from the EE_DATA register into the
377 EEPROM location specified in the EE_ADDR register.
378 The Wlan hardware hardware clears this bit automatically.
379*===============================================*/
380#define EE_CTL (REGISTERS_BASE + 0x2000)
381#define ACX_EE_CTL_REG EE_CTL
382#define EE_WRITE 0x00000001ul
383#define EE_READ 0x00000002ul
384
385/*===============================================
386 EEPROM Address - 32bit RW
387 ------------------------------------------
388 This register specifies the address
389 within the EEPROM from/to which to read/write data.
390 ===============================================*/
391#define EE_ADDR (REGISTERS_BASE + 0x2008)
392#define ACX_EE_ADDR_REG EE_ADDR
393
394/*===============================================
395 EEPROM Data - 32bit RW
396 ------------------------------------------
397 This register either holds the read 8 bits of
398 data from the EEPROM or the write data
399 to be written to the EEPROM.
400 ===============================================*/
401#define EE_DATA (REGISTERS_BASE + 0x2004)
402#define ACX_EE_DATA_REG EE_DATA
403
404#define EEPROM_ACCESS_TO 10000 /* timeout counter */
405#define START_EEPROM_MGR 0x00000001
406
407/*===============================================
408 EEPROM Base Address - 32bit RW
409 ------------------------------------------
410 This register holds the upper nine bits
411 [23:15] of the 24-bit Wlan hardware memory
412 address for burst reads from EEPROM accesses.
413 The EEPROM provides the lower 15 bits of this address.
414 The MSB of the address from the EEPROM is ignored.
415 ===============================================*/
416#define ACX_EE_CFG EE_CFG
417
418/*===============================================
419 GPIO Output Values -32bit, RW
420 ------------------------------------------
421 [31:16] Reserved
422 [15: 0] Specify the output values (at the output driver inputs) for
423 GPIO[15:0], respectively.
424 ===============================================*/
425#define ACX_GPIO_OUT_REG GPIO_OUT
426#define ACX_MAX_GPIO_LINES 15
427
428/*===============================================
429 Contention window -32bit, RW
430 ------------------------------------------
431 [31:26] Reserved
432 [25:16] Max (0x3ff)
433 [15:07] Reserved
434 [06:00] Current contention window value - default is 0x1F
435 ===============================================*/
436#define ACX_CONT_WIND_CFG_REG CONT_WIND_CFG
437#define ACX_CONT_WIND_MIN_MASK 0x0000007f
438#define ACX_CONT_WIND_MAX 0x03ff0000
439
440/*===============================================
441 HI_CFG Interface Configuration Register Values
442 ------------------------------------------
443 ===============================================*/
444#define HI_CFG_UART_ENABLE 0x00000004
445#define HI_CFG_RST232_ENABLE 0x00000008
446#define HI_CFG_CLOCK_REQ_SELECT 0x00000010
447#define HI_CFG_HOST_INT_ENABLE 0x00000020
448#define HI_CFG_VLYNQ_OUTPUT_ENABLE 0x00000040
449#define HI_CFG_HOST_INT_ACTIVE_LOW 0x00000080
450#define HI_CFG_UART_TX_OUT_GPIO_15 0x00000100
451#define HI_CFG_UART_TX_OUT_GPIO_14 0x00000200
452#define HI_CFG_UART_TX_OUT_GPIO_7 0x00000400
453
454/*
455 * NOTE: USE_ACTIVE_HIGH compilation flag should be defined in makefile
456 * for platforms using active high interrupt level
457 */
458#ifdef USE_ACTIVE_HIGH
459#define HI_CFG_DEF_VAL \
460 (HI_CFG_UART_ENABLE | \
461 HI_CFG_RST232_ENABLE | \
462 HI_CFG_CLOCK_REQ_SELECT | \
463 HI_CFG_HOST_INT_ENABLE)
464#else
465#define HI_CFG_DEF_VAL \
466 (HI_CFG_UART_ENABLE | \
467 HI_CFG_RST232_ENABLE | \
468 HI_CFG_CLOCK_REQ_SELECT | \
469 HI_CFG_HOST_INT_ENABLE)
470
471#endif
472
473#define REF_FREQ_19_2 0
474#define REF_FREQ_26_0 1
475#define REF_FREQ_38_4 2
476#define REF_FREQ_40_0 3
477#define REF_FREQ_33_6 4
478#define REF_FREQ_NUM 5
479
480#define LUT_PARAM_INTEGER_DIVIDER 0
481#define LUT_PARAM_FRACTIONAL_DIVIDER 1
482#define LUT_PARAM_ATTN_BB 2
483#define LUT_PARAM_ALPHA_BB 3
484#define LUT_PARAM_STOP_TIME_BB 4
485#define LUT_PARAM_BB_PLL_LOOP_FILTER 5
486#define LUT_PARAM_NUM 6
487
488#define ACX_EEPROMLESS_IND_REG (SCR_PAD4)
489#define USE_EEPROM 0
490#define SOFT_RESET_MAX_TIME 1000000
491#define SOFT_RESET_STALL_TIME 1000
492#define NVS_DATA_BUNDARY_ALIGNMENT 4
493
494
495/* Firmware image load chunk size */
496#define CHUNK_SIZE 512
497
498/* Firmware image header size */
499#define FW_HDR_SIZE 8
500
501#define ECPU_CONTROL_HALT 0x00000101
502
503
504/******************************************************************************
505
506 CHANNELS, BAND & REG DOMAINS definitions
507
508******************************************************************************/
509
510
511enum {
512 RADIO_BAND_2_4GHZ = 0, /* 2.4 Ghz band */
513 RADIO_BAND_5GHZ = 1, /* 5 Ghz band */
514 RADIO_BAND_JAPAN_4_9_GHZ = 2,
515 DEFAULT_BAND = RADIO_BAND_2_4GHZ,
516 INVALID_BAND = 0xFE,
517 MAX_RADIO_BANDS = 0xFF
518};
519
520enum {
521 NO_RATE = 0,
522 RATE_1MBPS = 0x0A,
523 RATE_2MBPS = 0x14,
524 RATE_5_5MBPS = 0x37,
525 RATE_6MBPS = 0x0B,
526 RATE_9MBPS = 0x0F,
527 RATE_11MBPS = 0x6E,
528 RATE_12MBPS = 0x0A,
529 RATE_18MBPS = 0x0E,
530 RATE_22MBPS = 0xDC,
531 RATE_24MBPS = 0x09,
532 RATE_36MBPS = 0x0D,
533 RATE_48MBPS = 0x08,
534 RATE_54MBPS = 0x0C
535};
536
537enum {
538 RATE_INDEX_1MBPS = 0,
539 RATE_INDEX_2MBPS = 1,
540 RATE_INDEX_5_5MBPS = 2,
541 RATE_INDEX_6MBPS = 3,
542 RATE_INDEX_9MBPS = 4,
543 RATE_INDEX_11MBPS = 5,
544 RATE_INDEX_12MBPS = 6,
545 RATE_INDEX_18MBPS = 7,
546 RATE_INDEX_22MBPS = 8,
547 RATE_INDEX_24MBPS = 9,
548 RATE_INDEX_36MBPS = 10,
549 RATE_INDEX_48MBPS = 11,
550 RATE_INDEX_54MBPS = 12,
551 RATE_INDEX_MAX = RATE_INDEX_54MBPS,
552 MAX_RATE_INDEX,
553 INVALID_RATE_INDEX = MAX_RATE_INDEX,
554 RATE_INDEX_ENUM_MAX_SIZE = 0x7FFFFFFF
555};
556
557enum {
558 RATE_MASK_1MBPS = 0x1,
559 RATE_MASK_2MBPS = 0x2,
560 RATE_MASK_5_5MBPS = 0x4,
561 RATE_MASK_11MBPS = 0x20,
562};
563
564#define SHORT_PREAMBLE_BIT BIT(0) /* CCK or Barker depending on the rate */
565#define OFDM_RATE_BIT BIT(6)
566#define PBCC_RATE_BIT BIT(7)
567
568enum {
569 CCK_LONG = 0,
570 CCK_SHORT = SHORT_PREAMBLE_BIT,
571 PBCC_LONG = PBCC_RATE_BIT,
572 PBCC_SHORT = PBCC_RATE_BIT | SHORT_PREAMBLE_BIT,
573 OFDM = OFDM_RATE_BIT
574};
575
576/******************************************************************************
577
578Transmit-Descriptor RATE-SET field definitions...
579
580Define a new "Rate-Set" for TX path that incorporates the
581Rate & Modulation info into a single 16-bit field.
582
583TxdRateSet_t:
584b15 - Indicates Preamble type (1=SHORT, 0=LONG).
585 Notes:
586 Must be LONG (0) for 1Mbps rate.
587 Does not apply (set to 0) for RevG-OFDM rates.
588b14 - Indicates PBCC encoding (1=PBCC, 0=not).
589 Notes:
590 Does not apply (set to 0) for rates 1 and 2 Mbps.
591 Does not apply (set to 0) for RevG-OFDM rates.
592b13 - Unused (set to 0).
593b12-b0 - Supported Rate indicator bits as defined below.
594
595******************************************************************************/
596
597
598/*************************************************************************
599
600 Interrupt Trigger Register (Host -> WiLink)
601
602**************************************************************************/
603
604/* Hardware to Embedded CPU Interrupts - first 32-bit register set */
605
606/*
607 * Host Command Interrupt. Setting this bit masks
608 * the interrupt that the host issues to inform
609 * the FW that it has sent a command
610 * to the Wlan hardware Command Mailbox.
611 */
612#define INTR_TRIG_CMD BIT(0)
613
614/*
615 * Host Event Acknowlegde Interrupt. The host
616 * sets this bit to acknowledge that it received
617 * the unsolicited information from the event
618 * mailbox.
619 */
620#define INTR_TRIG_EVENT_ACK BIT(1)
621
622/*
623 * The host sets this bit to inform the Wlan
624 * FW that a TX packet is in the XFER
625 * Buffer #0.
626 */
627#define INTR_TRIG_TX_PROC0 BIT(2)
628
629/*
630 * The host sets this bit to inform the FW
631 * that it read a packet from RX XFER
632 * Buffer #0.
633 */
634#define INTR_TRIG_RX_PROC0 BIT(3)
635
636#define INTR_TRIG_DEBUG_ACK BIT(4)
637
638#define INTR_TRIG_STATE_CHANGED BIT(5)
639
640
641/* Hardware to Embedded CPU Interrupts - second 32-bit register set */
642
643/*
644 * The host sets this bit to inform the FW
645 * that it read a packet from RX XFER
646 * Buffer #1.
647 */
648#define INTR_TRIG_RX_PROC1 BIT(17)
649
650/*
651 * The host sets this bit to inform the Wlan
652 * hardware that a TX packet is in the XFER
653 * Buffer #1.
654 */
655#define INTR_TRIG_TX_PROC1 BIT(18)
656
657#endif
diff --git a/drivers/net/wireless/wl12xx/wl1251_rx.c b/drivers/net/wireless/wl12xx/wl1251_rx.c
deleted file mode 100644
index 1b6294b3b996..000000000000
--- a/drivers/net/wireless/wl12xx/wl1251_rx.c
+++ /dev/null
@@ -1,192 +0,0 @@
1/*
2 * This file is part of wl1251
3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation
6 *
7 * Contact: Kalle Valo <kalle.valo@nokia.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25#include <linux/skbuff.h>
26#include <linux/gfp.h>
27#include <net/mac80211.h>
28
29#include "wl1251.h"
30#include "wl1251_reg.h"
31#include "wl1251_io.h"
32#include "wl1251_rx.h"
33#include "wl1251_cmd.h"
34#include "wl1251_acx.h"
35
36static void wl1251_rx_header(struct wl1251 *wl,
37 struct wl1251_rx_descriptor *desc)
38{
39 u32 rx_packet_ring_addr;
40
41 rx_packet_ring_addr = wl->data_path->rx_packet_ring_addr;
42 if (wl->rx_current_buffer)
43 rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size;
44
45 wl1251_mem_read(wl, rx_packet_ring_addr, desc, sizeof(*desc));
46}
47
48static void wl1251_rx_status(struct wl1251 *wl,
49 struct wl1251_rx_descriptor *desc,
50 struct ieee80211_rx_status *status,
51 u8 beacon)
52{
53 u64 mactime;
54 int ret;
55
56 memset(status, 0, sizeof(struct ieee80211_rx_status));
57
58 status->band = IEEE80211_BAND_2GHZ;
59 status->mactime = desc->timestamp;
60
61 /*
62 * The rx status timestamp is a 32 bits value while the TSF is a
63 * 64 bits one.
64 * For IBSS merging, TSF is mandatory, so we have to get it
65 * somehow, so we ask for ACX_TSF_INFO.
66 * That could be moved to the get_tsf() hook, but unfortunately,
67 * this one must be atomic, while our SPI routines can sleep.
68 */
69 if ((wl->bss_type == BSS_TYPE_IBSS) && beacon) {
70 ret = wl1251_acx_tsf_info(wl, &mactime);
71 if (ret == 0)
72 status->mactime = mactime;
73 }
74
75 status->signal = desc->rssi;
76
77 /*
78 * FIXME: guessing that snr needs to be divided by two, otherwise
79 * the values don't make any sense
80 */
81 wl->noise = desc->rssi - desc->snr / 2;
82
83 status->freq = ieee80211_channel_to_frequency(desc->channel);
84
85 status->flag |= RX_FLAG_TSFT;
86
87 if (desc->flags & RX_DESC_ENCRYPTION_MASK) {
88 status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED;
89
90 if (likely(!(desc->flags & RX_DESC_DECRYPT_FAIL)))
91 status->flag |= RX_FLAG_DECRYPTED;
92
93 if (unlikely(desc->flags & RX_DESC_MIC_FAIL))
94 status->flag |= RX_FLAG_MMIC_ERROR;
95 }
96
97 if (unlikely(!(desc->flags & RX_DESC_VALID_FCS)))
98 status->flag |= RX_FLAG_FAILED_FCS_CRC;
99
100
101 /* FIXME: set status->rate_idx */
102}
103
104static void wl1251_rx_body(struct wl1251 *wl,
105 struct wl1251_rx_descriptor *desc)
106{
107 struct sk_buff *skb;
108 struct ieee80211_rx_status status;
109 u8 *rx_buffer, beacon = 0;
110 u16 length, *fc;
111 u32 curr_id, last_id_inc, rx_packet_ring_addr;
112
113 length = WL1251_RX_ALIGN(desc->length - PLCP_HEADER_LENGTH);
114 curr_id = (desc->flags & RX_DESC_SEQNUM_MASK) >> RX_DESC_PACKETID_SHIFT;
115 last_id_inc = (wl->rx_last_id + 1) % (RX_MAX_PACKET_ID + 1);
116
117 if (last_id_inc != curr_id) {
118 wl1251_warning("curr ID:%d, last ID inc:%d",
119 curr_id, last_id_inc);
120 wl->rx_last_id = curr_id;
121 } else {
122 wl->rx_last_id = last_id_inc;
123 }
124
125 rx_packet_ring_addr = wl->data_path->rx_packet_ring_addr +
126 sizeof(struct wl1251_rx_descriptor) + 20;
127 if (wl->rx_current_buffer)
128 rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size;
129
130 skb = __dev_alloc_skb(length, GFP_KERNEL);
131 if (!skb) {
132 wl1251_error("Couldn't allocate RX frame");
133 return;
134 }
135
136 rx_buffer = skb_put(skb, length);
137 wl1251_mem_read(wl, rx_packet_ring_addr, rx_buffer, length);
138
139 /* The actual lenght doesn't include the target's alignment */
140 skb->len = desc->length - PLCP_HEADER_LENGTH;
141
142 fc = (u16 *)skb->data;
143
144 if ((*fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON)
145 beacon = 1;
146
147 wl1251_rx_status(wl, desc, &status, beacon);
148
149 wl1251_debug(DEBUG_RX, "rx skb 0x%p: %d B %s", skb, skb->len,
150 beacon ? "beacon" : "");
151
152 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
153 ieee80211_rx_ni(wl->hw, skb);
154}
155
156static void wl1251_rx_ack(struct wl1251 *wl)
157{
158 u32 data, addr;
159
160 if (wl->rx_current_buffer) {
161 addr = ACX_REG_INTERRUPT_TRIG_H;
162 data = INTR_TRIG_RX_PROC1;
163 } else {
164 addr = ACX_REG_INTERRUPT_TRIG;
165 data = INTR_TRIG_RX_PROC0;
166 }
167
168 wl1251_reg_write32(wl, addr, data);
169
170 /* Toggle buffer ring */
171 wl->rx_current_buffer = !wl->rx_current_buffer;
172}
173
174
175void wl1251_rx(struct wl1251 *wl)
176{
177 struct wl1251_rx_descriptor *rx_desc;
178
179 if (wl->state != WL1251_STATE_ON)
180 return;
181
182 rx_desc = wl->rx_descriptor;
183
184 /* We first read the frame's header */
185 wl1251_rx_header(wl, rx_desc);
186
187 /* Now we can read the body */
188 wl1251_rx_body(wl, rx_desc);
189
190 /* Finally, we need to ACK the RX */
191 wl1251_rx_ack(wl);
192}
diff --git a/drivers/net/wireless/wl12xx/wl1251_rx.h b/drivers/net/wireless/wl12xx/wl1251_rx.h
deleted file mode 100644
index da4e53406a0e..000000000000
--- a/drivers/net/wireless/wl12xx/wl1251_rx.h
+++ /dev/null
@@ -1,124 +0,0 @@
1/*
2 * This file is part of wl1251
3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation
6 *
7 * Contact: Kalle Valo <kalle.valo@nokia.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25#ifndef __WL1251_RX_H__
26#define __WL1251_RX_H__
27
28#include <linux/bitops.h>
29
30#include "wl1251.h"
31
32/*
33 * RX PATH
34 *
35 * The Rx path uses a double buffer and an rx_contro structure, each located
36 * at a fixed address in the device memory. The host keeps track of which
37 * buffer is available and alternates between them on a per packet basis.
38 * The size of each of the two buffers is large enough to hold the longest
39 * 802.3 packet.
40 * The RX path goes like that:
41 * 1) The target generates an interrupt each time a new packet is received.
42 * There are 2 RX interrupts, one for each buffer.
43 * 2) The host reads the received packet from one of the double buffers.
44 * 3) The host triggers a target interrupt.
45 * 4) The target prepares the next RX packet.
46 */
47
48#define WL1251_RX_MAX_RSSI -30
49#define WL1251_RX_MIN_RSSI -95
50
51#define WL1251_RX_ALIGN_TO 4
52#define WL1251_RX_ALIGN(len) (((len) + WL1251_RX_ALIGN_TO - 1) & \
53 ~(WL1251_RX_ALIGN_TO - 1))
54
55#define SHORT_PREAMBLE_BIT BIT(0)
56#define OFDM_RATE_BIT BIT(6)
57#define PBCC_RATE_BIT BIT(7)
58
59#define PLCP_HEADER_LENGTH 8
60#define RX_DESC_PACKETID_SHIFT 11
61#define RX_MAX_PACKET_ID 3
62
63#define RX_DESC_VALID_FCS 0x0001
64#define RX_DESC_MATCH_RXADDR1 0x0002
65#define RX_DESC_MCAST 0x0004
66#define RX_DESC_STAINTIM 0x0008
67#define RX_DESC_VIRTUAL_BM 0x0010
68#define RX_DESC_BCAST 0x0020
69#define RX_DESC_MATCH_SSID 0x0040
70#define RX_DESC_MATCH_BSSID 0x0080
71#define RX_DESC_ENCRYPTION_MASK 0x0300
72#define RX_DESC_MEASURMENT 0x0400
73#define RX_DESC_SEQNUM_MASK 0x1800
74#define RX_DESC_MIC_FAIL 0x2000
75#define RX_DESC_DECRYPT_FAIL 0x4000
76
77struct wl1251_rx_descriptor {
78 u32 timestamp; /* In microseconds */
79 u16 length; /* Paylod length, including headers */
80 u16 flags;
81
82 /*
83 * 0 - 802.11
84 * 1 - 802.3
85 * 2 - IP
86 * 3 - Raw Codec
87 */
88 u8 type;
89
90 /*
91 * Received Rate:
92 * 0x0A - 1MBPS
93 * 0x14 - 2MBPS
94 * 0x37 - 5_5MBPS
95 * 0x0B - 6MBPS
96 * 0x0F - 9MBPS
97 * 0x6E - 11MBPS
98 * 0x0A - 12MBPS
99 * 0x0E - 18MBPS
100 * 0xDC - 22MBPS
101 * 0x09 - 24MBPS
102 * 0x0D - 36MBPS
103 * 0x08 - 48MBPS
104 * 0x0C - 54MBPS
105 */
106 u8 rate;
107
108 u8 mod_pre; /* Modulation and preamble */
109 u8 channel;
110
111 /*
112 * 0 - 2.4 Ghz
113 * 1 - 5 Ghz
114 */
115 u8 band;
116
117 s8 rssi; /* in dB */
118 u8 rcpi; /* in dB */
119 u8 snr; /* in dB */
120} __packed;
121
122void wl1251_rx(struct wl1251 *wl);
123
124#endif
diff --git a/drivers/net/wireless/wl12xx/wl1251_sdio.c b/drivers/net/wireless/wl12xx/wl1251_sdio.c
deleted file mode 100644
index b901b6135654..000000000000
--- a/drivers/net/wireless/wl12xx/wl1251_sdio.c
+++ /dev/null
@@ -1,342 +0,0 @@
1/*
2 * wl12xx SDIO routines
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16 * 02110-1301 USA
17 *
18 * Copyright (C) 2005 Texas Instruments Incorporated
19 * Copyright (C) 2008 Google Inc
20 * Copyright (C) 2009 Bob Copeland (me@bobcopeland.com)
21 */
22#include <linux/module.h>
23#include <linux/mod_devicetable.h>
24#include <linux/mmc/sdio_func.h>
25#include <linux/mmc/sdio_ids.h>
26#include <linux/platform_device.h>
27#include <linux/spi/wl12xx.h>
28#include <linux/irq.h>
29
30#include "wl1251.h"
31
32#ifndef SDIO_VENDOR_ID_TI
33#define SDIO_VENDOR_ID_TI 0x104c
34#endif
35
36#ifndef SDIO_DEVICE_ID_TI_WL1251
37#define SDIO_DEVICE_ID_TI_WL1251 0x9066
38#endif
39
40struct wl1251_sdio {
41 struct sdio_func *func;
42 u32 elp_val;
43};
44
45static struct wl12xx_platform_data *wl12xx_board_data;
46
47static struct sdio_func *wl_to_func(struct wl1251 *wl)
48{
49 struct wl1251_sdio *wl_sdio = wl->if_priv;
50 return wl_sdio->func;
51}
52
53static void wl1251_sdio_interrupt(struct sdio_func *func)
54{
55 struct wl1251 *wl = sdio_get_drvdata(func);
56
57 wl1251_debug(DEBUG_IRQ, "IRQ");
58
59 /* FIXME should be synchronous for sdio */
60 ieee80211_queue_work(wl->hw, &wl->irq_work);
61}
62
63static const struct sdio_device_id wl1251_devices[] = {
64 { SDIO_DEVICE(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1251) },
65 {}
66};
67MODULE_DEVICE_TABLE(sdio, wl1251_devices);
68
69
70static void wl1251_sdio_read(struct wl1251 *wl, int addr,
71 void *buf, size_t len)
72{
73 int ret;
74 struct sdio_func *func = wl_to_func(wl);
75
76 sdio_claim_host(func);
77 ret = sdio_memcpy_fromio(func, buf, addr, len);
78 if (ret)
79 wl1251_error("sdio read failed (%d)", ret);
80 sdio_release_host(func);
81}
82
83static void wl1251_sdio_write(struct wl1251 *wl, int addr,
84 void *buf, size_t len)
85{
86 int ret;
87 struct sdio_func *func = wl_to_func(wl);
88
89 sdio_claim_host(func);
90 ret = sdio_memcpy_toio(func, addr, buf, len);
91 if (ret)
92 wl1251_error("sdio write failed (%d)", ret);
93 sdio_release_host(func);
94}
95
96static void wl1251_sdio_read_elp(struct wl1251 *wl, int addr, u32 *val)
97{
98 int ret = 0;
99 struct wl1251_sdio *wl_sdio = wl->if_priv;
100 struct sdio_func *func = wl_sdio->func;
101
102 /*
103 * The hardware only supports RAW (read after write) access for
104 * reading, regular sdio_readb won't work here (it interprets
105 * the unused bits of CMD52 as write data even if we send read
106 * request).
107 */
108 sdio_claim_host(func);
109 *val = sdio_writeb_readb(func, wl_sdio->elp_val, addr, &ret);
110 sdio_release_host(func);
111
112 if (ret)
113 wl1251_error("sdio_readb failed (%d)", ret);
114}
115
116static void wl1251_sdio_write_elp(struct wl1251 *wl, int addr, u32 val)
117{
118 int ret = 0;
119 struct wl1251_sdio *wl_sdio = wl->if_priv;
120 struct sdio_func *func = wl_sdio->func;
121
122 sdio_claim_host(func);
123 sdio_writeb(func, val, addr, &ret);
124 sdio_release_host(func);
125
126 if (ret)
127 wl1251_error("sdio_writeb failed (%d)", ret);
128 else
129 wl_sdio->elp_val = val;
130}
131
132static void wl1251_sdio_reset(struct wl1251 *wl)
133{
134}
135
136static void wl1251_sdio_enable_irq(struct wl1251 *wl)
137{
138 struct sdio_func *func = wl_to_func(wl);
139
140 sdio_claim_host(func);
141 sdio_claim_irq(func, wl1251_sdio_interrupt);
142 sdio_release_host(func);
143}
144
145static void wl1251_sdio_disable_irq(struct wl1251 *wl)
146{
147 struct sdio_func *func = wl_to_func(wl);
148
149 sdio_claim_host(func);
150 sdio_release_irq(func);
151 sdio_release_host(func);
152}
153
154/* Interrupts when using dedicated WLAN_IRQ pin */
155static irqreturn_t wl1251_line_irq(int irq, void *cookie)
156{
157 struct wl1251 *wl = cookie;
158
159 ieee80211_queue_work(wl->hw, &wl->irq_work);
160
161 return IRQ_HANDLED;
162}
163
164static void wl1251_enable_line_irq(struct wl1251 *wl)
165{
166 return enable_irq(wl->irq);
167}
168
169static void wl1251_disable_line_irq(struct wl1251 *wl)
170{
171 return disable_irq(wl->irq);
172}
173
174static void wl1251_sdio_set_power(bool enable)
175{
176}
177
178static struct wl1251_if_operations wl1251_sdio_ops = {
179 .read = wl1251_sdio_read,
180 .write = wl1251_sdio_write,
181 .write_elp = wl1251_sdio_write_elp,
182 .read_elp = wl1251_sdio_read_elp,
183 .reset = wl1251_sdio_reset,
184};
185
186static int wl1251_platform_probe(struct platform_device *pdev)
187{
188 if (pdev->id != -1) {
189 wl1251_error("can only handle single device");
190 return -ENODEV;
191 }
192
193 wl12xx_board_data = pdev->dev.platform_data;
194 return 0;
195}
196
197/*
198 * Dummy platform_driver for passing platform_data to this driver,
199 * until we have a way to pass this through SDIO subsystem or
200 * some other way.
201 */
202static struct platform_driver wl1251_platform_driver = {
203 .driver = {
204 .name = "wl1251_data",
205 .owner = THIS_MODULE,
206 },
207 .probe = wl1251_platform_probe,
208};
209
210static int wl1251_sdio_probe(struct sdio_func *func,
211 const struct sdio_device_id *id)
212{
213 int ret;
214 struct wl1251 *wl;
215 struct ieee80211_hw *hw;
216 struct wl1251_sdio *wl_sdio;
217
218 hw = wl1251_alloc_hw();
219 if (IS_ERR(hw))
220 return PTR_ERR(hw);
221
222 wl = hw->priv;
223
224 wl_sdio = kzalloc(sizeof(*wl_sdio), GFP_KERNEL);
225 if (wl_sdio == NULL) {
226 ret = -ENOMEM;
227 goto out_free_hw;
228 }
229
230 sdio_claim_host(func);
231 ret = sdio_enable_func(func);
232 if (ret)
233 goto release;
234
235 sdio_set_block_size(func, 512);
236 sdio_release_host(func);
237
238 SET_IEEE80211_DEV(hw, &func->dev);
239 wl_sdio->func = func;
240 wl->if_priv = wl_sdio;
241 wl->if_ops = &wl1251_sdio_ops;
242 wl->set_power = wl1251_sdio_set_power;
243
244 if (wl12xx_board_data != NULL) {
245 wl->set_power = wl12xx_board_data->set_power;
246 wl->irq = wl12xx_board_data->irq;
247 wl->use_eeprom = wl12xx_board_data->use_eeprom;
248 }
249
250 if (wl->irq) {
251 ret = request_irq(wl->irq, wl1251_line_irq, 0, "wl1251", wl);
252 if (ret < 0) {
253 wl1251_error("request_irq() failed: %d", ret);
254 goto disable;
255 }
256
257 set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
258 disable_irq(wl->irq);
259
260 wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
261 wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
262
263 wl1251_info("using dedicated interrupt line");
264 } else {
265 wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
266 wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
267
268 wl1251_info("using SDIO interrupt");
269 }
270
271 ret = wl1251_init_ieee80211(wl);
272 if (ret)
273 goto out_free_irq;
274
275 sdio_set_drvdata(func, wl);
276 return ret;
277
278out_free_irq:
279 if (wl->irq)
280 free_irq(wl->irq, wl);
281disable:
282 sdio_claim_host(func);
283 sdio_disable_func(func);
284release:
285 sdio_release_host(func);
286 kfree(wl_sdio);
287out_free_hw:
288 wl1251_free_hw(wl);
289 return ret;
290}
291
292static void __devexit wl1251_sdio_remove(struct sdio_func *func)
293{
294 struct wl1251 *wl = sdio_get_drvdata(func);
295 struct wl1251_sdio *wl_sdio = wl->if_priv;
296
297 if (wl->irq)
298 free_irq(wl->irq, wl);
299 kfree(wl_sdio);
300 wl1251_free_hw(wl);
301
302 sdio_claim_host(func);
303 sdio_release_irq(func);
304 sdio_disable_func(func);
305 sdio_release_host(func);
306}
307
308static struct sdio_driver wl1251_sdio_driver = {
309 .name = "wl1251_sdio",
310 .id_table = wl1251_devices,
311 .probe = wl1251_sdio_probe,
312 .remove = __devexit_p(wl1251_sdio_remove),
313};
314
315static int __init wl1251_sdio_init(void)
316{
317 int err;
318
319 err = platform_driver_register(&wl1251_platform_driver);
320 if (err) {
321 wl1251_error("failed to register platform driver: %d", err);
322 return err;
323 }
324
325 err = sdio_register_driver(&wl1251_sdio_driver);
326 if (err)
327 wl1251_error("failed to register sdio driver: %d", err);
328 return err;
329}
330
331static void __exit wl1251_sdio_exit(void)
332{
333 sdio_unregister_driver(&wl1251_sdio_driver);
334 platform_driver_unregister(&wl1251_platform_driver);
335 wl1251_notice("unloaded");
336}
337
338module_init(wl1251_sdio_init);
339module_exit(wl1251_sdio_exit);
340
341MODULE_LICENSE("GPL");
342MODULE_AUTHOR("Kalle Valo <kalle.valo@nokia.com>");
diff --git a/drivers/net/wireless/wl12xx/wl1251_spi.c b/drivers/net/wireless/wl12xx/wl1251_spi.c
deleted file mode 100644
index 27fdfaaeb074..000000000000
--- a/drivers/net/wireless/wl12xx/wl1251_spi.c
+++ /dev/null
@@ -1,348 +0,0 @@
1/*
2 * This file is part of wl1251
3 *
4 * Copyright (C) 2008 Nokia Corporation
5 *
6 * Contact: Kalle Valo <kalle.valo@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include <linux/irq.h>
25#include <linux/module.h>
26#include <linux/slab.h>
27#include <linux/crc7.h>
28#include <linux/spi/spi.h>
29#include <linux/spi/wl12xx.h>
30
31#include "wl1251.h"
32#include "wl1251_reg.h"
33#include "wl1251_spi.h"
34
35static irqreturn_t wl1251_irq(int irq, void *cookie)
36{
37 struct wl1251 *wl;
38
39 wl1251_debug(DEBUG_IRQ, "IRQ");
40
41 wl = cookie;
42
43 ieee80211_queue_work(wl->hw, &wl->irq_work);
44
45 return IRQ_HANDLED;
46}
47
48static struct spi_device *wl_to_spi(struct wl1251 *wl)
49{
50 return wl->if_priv;
51}
52
53static void wl1251_spi_reset(struct wl1251 *wl)
54{
55 u8 *cmd;
56 struct spi_transfer t;
57 struct spi_message m;
58
59 cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL);
60 if (!cmd) {
61 wl1251_error("could not allocate cmd for spi reset");
62 return;
63 }
64
65 memset(&t, 0, sizeof(t));
66 spi_message_init(&m);
67
68 memset(cmd, 0xff, WSPI_INIT_CMD_LEN);
69
70 t.tx_buf = cmd;
71 t.len = WSPI_INIT_CMD_LEN;
72 spi_message_add_tail(&t, &m);
73
74 spi_sync(wl_to_spi(wl), &m);
75
76 wl1251_dump(DEBUG_SPI, "spi reset -> ", cmd, WSPI_INIT_CMD_LEN);
77}
78
79static void wl1251_spi_wake(struct wl1251 *wl)
80{
81 u8 crc[WSPI_INIT_CMD_CRC_LEN], *cmd;
82 struct spi_transfer t;
83 struct spi_message m;
84
85 cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL);
86 if (!cmd) {
87 wl1251_error("could not allocate cmd for spi init");
88 return;
89 }
90
91 memset(crc, 0, sizeof(crc));
92 memset(&t, 0, sizeof(t));
93 spi_message_init(&m);
94
95 /*
96 * Set WSPI_INIT_COMMAND
97 * the data is being send from the MSB to LSB
98 */
99 cmd[2] = 0xff;
100 cmd[3] = 0xff;
101 cmd[1] = WSPI_INIT_CMD_START | WSPI_INIT_CMD_TX;
102 cmd[0] = 0;
103 cmd[7] = 0;
104 cmd[6] |= HW_ACCESS_WSPI_INIT_CMD_MASK << 3;
105 cmd[6] |= HW_ACCESS_WSPI_FIXED_BUSY_LEN & WSPI_INIT_CMD_FIXEDBUSY_LEN;
106
107 if (HW_ACCESS_WSPI_FIXED_BUSY_LEN == 0)
108 cmd[5] |= WSPI_INIT_CMD_DIS_FIXEDBUSY;
109 else
110 cmd[5] |= WSPI_INIT_CMD_EN_FIXEDBUSY;
111
112 cmd[5] |= WSPI_INIT_CMD_IOD | WSPI_INIT_CMD_IP | WSPI_INIT_CMD_CS
113 | WSPI_INIT_CMD_WSPI | WSPI_INIT_CMD_WS;
114
115 crc[0] = cmd[1];
116 crc[1] = cmd[0];
117 crc[2] = cmd[7];
118 crc[3] = cmd[6];
119 crc[4] = cmd[5];
120
121 cmd[4] |= crc7(0, crc, WSPI_INIT_CMD_CRC_LEN) << 1;
122 cmd[4] |= WSPI_INIT_CMD_END;
123
124 t.tx_buf = cmd;
125 t.len = WSPI_INIT_CMD_LEN;
126 spi_message_add_tail(&t, &m);
127
128 spi_sync(wl_to_spi(wl), &m);
129
130 wl1251_dump(DEBUG_SPI, "spi init -> ", cmd, WSPI_INIT_CMD_LEN);
131}
132
133static void wl1251_spi_reset_wake(struct wl1251 *wl)
134{
135 wl1251_spi_reset(wl);
136 wl1251_spi_wake(wl);
137}
138
139static void wl1251_spi_read(struct wl1251 *wl, int addr, void *buf,
140 size_t len)
141{
142 struct spi_transfer t[3];
143 struct spi_message m;
144 u8 *busy_buf;
145 u32 *cmd;
146
147 cmd = &wl->buffer_cmd;
148 busy_buf = wl->buffer_busyword;
149
150 *cmd = 0;
151 *cmd |= WSPI_CMD_READ;
152 *cmd |= (len << WSPI_CMD_BYTE_LENGTH_OFFSET) & WSPI_CMD_BYTE_LENGTH;
153 *cmd |= addr & WSPI_CMD_BYTE_ADDR;
154
155 spi_message_init(&m);
156 memset(t, 0, sizeof(t));
157
158 t[0].tx_buf = cmd;
159 t[0].len = 4;
160 spi_message_add_tail(&t[0], &m);
161
162 /* Busy and non busy words read */
163 t[1].rx_buf = busy_buf;
164 t[1].len = WL1251_BUSY_WORD_LEN;
165 spi_message_add_tail(&t[1], &m);
166
167 t[2].rx_buf = buf;
168 t[2].len = len;
169 spi_message_add_tail(&t[2], &m);
170
171 spi_sync(wl_to_spi(wl), &m);
172
173 /* FIXME: check busy words */
174
175 wl1251_dump(DEBUG_SPI, "spi_read cmd -> ", cmd, sizeof(*cmd));
176 wl1251_dump(DEBUG_SPI, "spi_read buf <- ", buf, len);
177}
178
179static void wl1251_spi_write(struct wl1251 *wl, int addr, void *buf,
180 size_t len)
181{
182 struct spi_transfer t[2];
183 struct spi_message m;
184 u32 *cmd;
185
186 cmd = &wl->buffer_cmd;
187
188 *cmd = 0;
189 *cmd |= WSPI_CMD_WRITE;
190 *cmd |= (len << WSPI_CMD_BYTE_LENGTH_OFFSET) & WSPI_CMD_BYTE_LENGTH;
191 *cmd |= addr & WSPI_CMD_BYTE_ADDR;
192
193 spi_message_init(&m);
194 memset(t, 0, sizeof(t));
195
196 t[0].tx_buf = cmd;
197 t[0].len = sizeof(*cmd);
198 spi_message_add_tail(&t[0], &m);
199
200 t[1].tx_buf = buf;
201 t[1].len = len;
202 spi_message_add_tail(&t[1], &m);
203
204 spi_sync(wl_to_spi(wl), &m);
205
206 wl1251_dump(DEBUG_SPI, "spi_write cmd -> ", cmd, sizeof(*cmd));
207 wl1251_dump(DEBUG_SPI, "spi_write buf -> ", buf, len);
208}
209
210static void wl1251_spi_enable_irq(struct wl1251 *wl)
211{
212 return enable_irq(wl->irq);
213}
214
215static void wl1251_spi_disable_irq(struct wl1251 *wl)
216{
217 return disable_irq(wl->irq);
218}
219
220static const struct wl1251_if_operations wl1251_spi_ops = {
221 .read = wl1251_spi_read,
222 .write = wl1251_spi_write,
223 .reset = wl1251_spi_reset_wake,
224 .enable_irq = wl1251_spi_enable_irq,
225 .disable_irq = wl1251_spi_disable_irq,
226};
227
228static int __devinit wl1251_spi_probe(struct spi_device *spi)
229{
230 struct wl12xx_platform_data *pdata;
231 struct ieee80211_hw *hw;
232 struct wl1251 *wl;
233 int ret;
234
235 pdata = spi->dev.platform_data;
236 if (!pdata) {
237 wl1251_error("no platform data");
238 return -ENODEV;
239 }
240
241 hw = wl1251_alloc_hw();
242 if (IS_ERR(hw))
243 return PTR_ERR(hw);
244
245 wl = hw->priv;
246
247 SET_IEEE80211_DEV(hw, &spi->dev);
248 dev_set_drvdata(&spi->dev, wl);
249 wl->if_priv = spi;
250 wl->if_ops = &wl1251_spi_ops;
251
252 /* This is the only SPI value that we need to set here, the rest
253 * comes from the board-peripherals file */
254 spi->bits_per_word = 32;
255
256 ret = spi_setup(spi);
257 if (ret < 0) {
258 wl1251_error("spi_setup failed");
259 goto out_free;
260 }
261
262 wl->set_power = pdata->set_power;
263 if (!wl->set_power) {
264 wl1251_error("set power function missing in platform data");
265 return -ENODEV;
266 }
267
268 wl->irq = spi->irq;
269 if (wl->irq < 0) {
270 wl1251_error("irq missing in platform data");
271 return -ENODEV;
272 }
273
274 wl->use_eeprom = pdata->use_eeprom;
275
276 ret = request_irq(wl->irq, wl1251_irq, 0, DRIVER_NAME, wl);
277 if (ret < 0) {
278 wl1251_error("request_irq() failed: %d", ret);
279 goto out_free;
280 }
281
282 set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
283
284 disable_irq(wl->irq);
285
286 ret = wl1251_init_ieee80211(wl);
287 if (ret)
288 goto out_irq;
289
290 return 0;
291
292 out_irq:
293 free_irq(wl->irq, wl);
294
295 out_free:
296 ieee80211_free_hw(hw);
297
298 return ret;
299}
300
301static int __devexit wl1251_spi_remove(struct spi_device *spi)
302{
303 struct wl1251 *wl = dev_get_drvdata(&spi->dev);
304
305 free_irq(wl->irq, wl);
306 wl1251_free_hw(wl);
307
308 return 0;
309}
310
311static struct spi_driver wl1251_spi_driver = {
312 .driver = {
313 .name = DRIVER_NAME,
314 .bus = &spi_bus_type,
315 .owner = THIS_MODULE,
316 },
317
318 .probe = wl1251_spi_probe,
319 .remove = __devexit_p(wl1251_spi_remove),
320};
321
322static int __init wl1251_spi_init(void)
323{
324 int ret;
325
326 ret = spi_register_driver(&wl1251_spi_driver);
327 if (ret < 0) {
328 wl1251_error("failed to register spi driver: %d", ret);
329 goto out;
330 }
331
332out:
333 return ret;
334}
335
336static void __exit wl1251_spi_exit(void)
337{
338 spi_unregister_driver(&wl1251_spi_driver);
339
340 wl1251_notice("unloaded");
341}
342
343module_init(wl1251_spi_init);
344module_exit(wl1251_spi_exit);
345
346MODULE_LICENSE("GPL");
347MODULE_AUTHOR("Kalle Valo <kalle.valo@nokia.com>");
348MODULE_ALIAS("spi:wl1251");
diff --git a/drivers/net/wireless/wl12xx/wl1251_spi.h b/drivers/net/wireless/wl12xx/wl1251_spi.h
deleted file mode 100644
index 2e273a97e7f3..000000000000
--- a/drivers/net/wireless/wl12xx/wl1251_spi.h
+++ /dev/null
@@ -1,61 +0,0 @@
1/*
2 * This file is part of wl1251
3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation
6 *
7 * Contact: Kalle Valo <kalle.valo@nokia.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25#ifndef __WL1251_SPI_H__
26#define __WL1251_SPI_H__
27
28#include "wl1251_cmd.h"
29#include "wl1251_acx.h"
30#include "wl1251_reg.h"
31
32#define WSPI_CMD_READ 0x40000000
33#define WSPI_CMD_WRITE 0x00000000
34#define WSPI_CMD_FIXED 0x20000000
35#define WSPI_CMD_BYTE_LENGTH 0x1FFE0000
36#define WSPI_CMD_BYTE_LENGTH_OFFSET 17
37#define WSPI_CMD_BYTE_ADDR 0x0001FFFF
38
39#define WSPI_INIT_CMD_CRC_LEN 5
40
41#define WSPI_INIT_CMD_START 0x00
42#define WSPI_INIT_CMD_TX 0x40
43/* the extra bypass bit is sampled by the TNET as '1' */
44#define WSPI_INIT_CMD_BYPASS_BIT 0x80
45#define WSPI_INIT_CMD_FIXEDBUSY_LEN 0x07
46#define WSPI_INIT_CMD_EN_FIXEDBUSY 0x80
47#define WSPI_INIT_CMD_DIS_FIXEDBUSY 0x00
48#define WSPI_INIT_CMD_IOD 0x40
49#define WSPI_INIT_CMD_IP 0x20
50#define WSPI_INIT_CMD_CS 0x10
51#define WSPI_INIT_CMD_WS 0x08
52#define WSPI_INIT_CMD_WSPI 0x01
53#define WSPI_INIT_CMD_END 0x01
54
55#define WSPI_INIT_CMD_LEN 8
56
57#define HW_ACCESS_WSPI_FIXED_BUSY_LEN \
58 ((WL1251_BUSY_WORD_LEN - 4) / sizeof(u32))
59#define HW_ACCESS_WSPI_INIT_CMD_MASK 0
60
61#endif /* __WL1251_SPI_H__ */
diff --git a/drivers/net/wireless/wl12xx/wl1251_tx.c b/drivers/net/wireless/wl12xx/wl1251_tx.c
deleted file mode 100644
index a38ec199187a..000000000000
--- a/drivers/net/wireless/wl12xx/wl1251_tx.c
+++ /dev/null
@@ -1,562 +0,0 @@
1/*
2 * This file is part of wl1251
3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation
6 *
7 * Contact: Kalle Valo <kalle.valo@nokia.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25#include <linux/kernel.h>
26#include <linux/module.h>
27
28#include "wl1251.h"
29#include "wl1251_reg.h"
30#include "wl1251_tx.h"
31#include "wl1251_ps.h"
32#include "wl1251_io.h"
33
34static bool wl1251_tx_double_buffer_busy(struct wl1251 *wl, u32 data_out_count)
35{
36 int used, data_in_count;
37
38 data_in_count = wl->data_in_count;
39
40 if (data_in_count < data_out_count)
41 /* data_in_count has wrapped */
42 data_in_count += TX_STATUS_DATA_OUT_COUNT_MASK + 1;
43
44 used = data_in_count - data_out_count;
45
46 WARN_ON(used < 0);
47 WARN_ON(used > DP_TX_PACKET_RING_CHUNK_NUM);
48
49 if (used >= DP_TX_PACKET_RING_CHUNK_NUM)
50 return true;
51 else
52 return false;
53}
54
55static int wl1251_tx_path_status(struct wl1251 *wl)
56{
57 u32 status, addr, data_out_count;
58 bool busy;
59
60 addr = wl->data_path->tx_control_addr;
61 status = wl1251_mem_read32(wl, addr);
62 data_out_count = status & TX_STATUS_DATA_OUT_COUNT_MASK;
63 busy = wl1251_tx_double_buffer_busy(wl, data_out_count);
64
65 if (busy)
66 return -EBUSY;
67
68 return 0;
69}
70
71static int wl1251_tx_id(struct wl1251 *wl, struct sk_buff *skb)
72{
73 int i;
74
75 for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
76 if (wl->tx_frames[i] == NULL) {
77 wl->tx_frames[i] = skb;
78 return i;
79 }
80
81 return -EBUSY;
82}
83
84static void wl1251_tx_control(struct tx_double_buffer_desc *tx_hdr,
85 struct ieee80211_tx_info *control, u16 fc)
86{
87 *(u16 *)&tx_hdr->control = 0;
88
89 tx_hdr->control.rate_policy = 0;
90
91 /* 802.11 packets */
92 tx_hdr->control.packet_type = 0;
93
94 if (control->flags & IEEE80211_TX_CTL_NO_ACK)
95 tx_hdr->control.ack_policy = 1;
96
97 tx_hdr->control.tx_complete = 1;
98
99 if ((fc & IEEE80211_FTYPE_DATA) &&
100 ((fc & IEEE80211_STYPE_QOS_DATA) ||
101 (fc & IEEE80211_STYPE_QOS_NULLFUNC)))
102 tx_hdr->control.qos = 1;
103}
104
105/* RSN + MIC = 8 + 8 = 16 bytes (worst case - AES). */
106#define MAX_MSDU_SECURITY_LENGTH 16
107#define MAX_MPDU_SECURITY_LENGTH 16
108#define WLAN_QOS_HDR_LEN 26
109#define MAX_MPDU_HEADER_AND_SECURITY (MAX_MPDU_SECURITY_LENGTH + \
110 WLAN_QOS_HDR_LEN)
111#define HW_BLOCK_SIZE 252
112static void wl1251_tx_frag_block_num(struct tx_double_buffer_desc *tx_hdr)
113{
114 u16 payload_len, frag_threshold, mem_blocks;
115 u16 num_mpdus, mem_blocks_per_frag;
116
117 frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
118 tx_hdr->frag_threshold = cpu_to_le16(frag_threshold);
119
120 payload_len = le16_to_cpu(tx_hdr->length) + MAX_MSDU_SECURITY_LENGTH;
121
122 if (payload_len > frag_threshold) {
123 mem_blocks_per_frag =
124 ((frag_threshold + MAX_MPDU_HEADER_AND_SECURITY) /
125 HW_BLOCK_SIZE) + 1;
126 num_mpdus = payload_len / frag_threshold;
127 mem_blocks = num_mpdus * mem_blocks_per_frag;
128 payload_len -= num_mpdus * frag_threshold;
129 num_mpdus++;
130
131 } else {
132 mem_blocks_per_frag = 0;
133 mem_blocks = 0;
134 num_mpdus = 1;
135 }
136
137 mem_blocks += (payload_len / HW_BLOCK_SIZE) + 1;
138
139 if (num_mpdus > 1)
140 mem_blocks += min(num_mpdus, mem_blocks_per_frag);
141
142 tx_hdr->num_mem_blocks = mem_blocks;
143}
144
145static int wl1251_tx_fill_hdr(struct wl1251 *wl, struct sk_buff *skb,
146 struct ieee80211_tx_info *control)
147{
148 struct tx_double_buffer_desc *tx_hdr;
149 struct ieee80211_rate *rate;
150 int id;
151 u16 fc;
152
153 if (!skb)
154 return -EINVAL;
155
156 id = wl1251_tx_id(wl, skb);
157 if (id < 0)
158 return id;
159
160 fc = *(u16 *)skb->data;
161 tx_hdr = (struct tx_double_buffer_desc *) skb_push(skb,
162 sizeof(*tx_hdr));
163
164 tx_hdr->length = cpu_to_le16(skb->len - sizeof(*tx_hdr));
165 rate = ieee80211_get_tx_rate(wl->hw, control);
166 tx_hdr->rate = cpu_to_le16(rate->hw_value);
167 tx_hdr->expiry_time = cpu_to_le32(1 << 16);
168 tx_hdr->id = id;
169
170 tx_hdr->xmit_queue = wl1251_tx_get_queue(skb_get_queue_mapping(skb));
171
172 wl1251_tx_control(tx_hdr, control, fc);
173 wl1251_tx_frag_block_num(tx_hdr);
174
175 return 0;
176}
177
178/* We copy the packet to the target */
179static int wl1251_tx_send_packet(struct wl1251 *wl, struct sk_buff *skb,
180 struct ieee80211_tx_info *control)
181{
182 struct tx_double_buffer_desc *tx_hdr;
183 int len;
184 u32 addr;
185
186 if (!skb)
187 return -EINVAL;
188
189 tx_hdr = (struct tx_double_buffer_desc *) skb->data;
190
191 if (control->control.hw_key &&
192 control->control.hw_key->alg == ALG_TKIP) {
193 int hdrlen;
194 __le16 fc;
195 u16 length;
196 u8 *pos;
197
198 fc = *(__le16 *)(skb->data + sizeof(*tx_hdr));
199 length = le16_to_cpu(tx_hdr->length) + WL1251_TKIP_IV_SPACE;
200 tx_hdr->length = cpu_to_le16(length);
201
202 hdrlen = ieee80211_hdrlen(fc);
203
204 pos = skb_push(skb, WL1251_TKIP_IV_SPACE);
205 memmove(pos, pos + WL1251_TKIP_IV_SPACE,
206 sizeof(*tx_hdr) + hdrlen);
207 }
208
209 /* Revisit. This is a workaround for getting non-aligned packets.
210 This happens at least with EAPOL packets from the user space.
211 Our DMA requires packets to be aligned on a 4-byte boundary.
212 */
213 if (unlikely((long)skb->data & 0x03)) {
214 int offset = (4 - (long)skb->data) & 0x03;
215 wl1251_debug(DEBUG_TX, "skb offset %d", offset);
216
217 /* check whether the current skb can be used */
218 if (!skb_cloned(skb) && (skb_tailroom(skb) >= offset)) {
219 unsigned char *src = skb->data;
220
221 /* align the buffer on a 4-byte boundary */
222 skb_reserve(skb, offset);
223 memmove(skb->data, src, skb->len);
224 tx_hdr = (struct tx_double_buffer_desc *) skb->data;
225 } else {
226 wl1251_info("No handler, fixme!");
227 return -EINVAL;
228 }
229 }
230
231 /* Our skb->data at this point includes the HW header */
232 len = WL1251_TX_ALIGN(skb->len);
233
234 if (wl->data_in_count & 0x1)
235 addr = wl->data_path->tx_packet_ring_addr +
236 wl->data_path->tx_packet_ring_chunk_size;
237 else
238 addr = wl->data_path->tx_packet_ring_addr;
239
240 wl1251_mem_write(wl, addr, skb->data, len);
241
242 wl1251_debug(DEBUG_TX, "tx id %u skb 0x%p payload %u rate 0x%x "
243 "queue %d", tx_hdr->id, skb, tx_hdr->length,
244 tx_hdr->rate, tx_hdr->xmit_queue);
245
246 return 0;
247}
248
249static void wl1251_tx_trigger(struct wl1251 *wl)
250{
251 u32 data, addr;
252
253 if (wl->data_in_count & 0x1) {
254 addr = ACX_REG_INTERRUPT_TRIG_H;
255 data = INTR_TRIG_TX_PROC1;
256 } else {
257 addr = ACX_REG_INTERRUPT_TRIG;
258 data = INTR_TRIG_TX_PROC0;
259 }
260
261 wl1251_reg_write32(wl, addr, data);
262
263 /* Bumping data in */
264 wl->data_in_count = (wl->data_in_count + 1) &
265 TX_STATUS_DATA_OUT_COUNT_MASK;
266}
267
268/* caller must hold wl->mutex */
269static int wl1251_tx_frame(struct wl1251 *wl, struct sk_buff *skb)
270{
271 struct ieee80211_tx_info *info;
272 int ret = 0;
273 u8 idx;
274
275 info = IEEE80211_SKB_CB(skb);
276
277 if (info->control.hw_key) {
278 idx = info->control.hw_key->hw_key_idx;
279 if (unlikely(wl->default_key != idx)) {
280 ret = wl1251_acx_default_key(wl, idx);
281 if (ret < 0)
282 return ret;
283 }
284 }
285
286 ret = wl1251_tx_path_status(wl);
287 if (ret < 0)
288 return ret;
289
290 ret = wl1251_tx_fill_hdr(wl, skb, info);
291 if (ret < 0)
292 return ret;
293
294 ret = wl1251_tx_send_packet(wl, skb, info);
295 if (ret < 0)
296 return ret;
297
298 wl1251_tx_trigger(wl);
299
300 return ret;
301}
302
303void wl1251_tx_work(struct work_struct *work)
304{
305 struct wl1251 *wl = container_of(work, struct wl1251, tx_work);
306 struct sk_buff *skb;
307 bool woken_up = false;
308 int ret;
309
310 mutex_lock(&wl->mutex);
311
312 if (unlikely(wl->state == WL1251_STATE_OFF))
313 goto out;
314
315 while ((skb = skb_dequeue(&wl->tx_queue))) {
316 if (!woken_up) {
317 ret = wl1251_ps_elp_wakeup(wl);
318 if (ret < 0)
319 goto out;
320 woken_up = true;
321 }
322
323 ret = wl1251_tx_frame(wl, skb);
324 if (ret == -EBUSY) {
325 /* firmware buffer is full, stop queues */
326 wl1251_debug(DEBUG_TX, "tx_work: fw buffer full, "
327 "stop queues");
328 ieee80211_stop_queues(wl->hw);
329 wl->tx_queue_stopped = true;
330 skb_queue_head(&wl->tx_queue, skb);
331 goto out;
332 } else if (ret < 0) {
333 dev_kfree_skb(skb);
334 goto out;
335 }
336 }
337
338out:
339 if (woken_up)
340 wl1251_ps_elp_sleep(wl);
341
342 mutex_unlock(&wl->mutex);
343}
344
345static const char *wl1251_tx_parse_status(u8 status)
346{
347 /* 8 bit status field, one character per bit plus null */
348 static char buf[9];
349 int i = 0;
350
351 memset(buf, 0, sizeof(buf));
352
353 if (status & TX_DMA_ERROR)
354 buf[i++] = 'm';
355 if (status & TX_DISABLED)
356 buf[i++] = 'd';
357 if (status & TX_RETRY_EXCEEDED)
358 buf[i++] = 'r';
359 if (status & TX_TIMEOUT)
360 buf[i++] = 't';
361 if (status & TX_KEY_NOT_FOUND)
362 buf[i++] = 'k';
363 if (status & TX_ENCRYPT_FAIL)
364 buf[i++] = 'e';
365 if (status & TX_UNAVAILABLE_PRIORITY)
366 buf[i++] = 'p';
367
368 /* bit 0 is unused apparently */
369
370 return buf;
371}
372
373static void wl1251_tx_packet_cb(struct wl1251 *wl,
374 struct tx_result *result)
375{
376 struct ieee80211_tx_info *info;
377 struct sk_buff *skb;
378 int hdrlen, ret;
379 u8 *frame;
380
381 skb = wl->tx_frames[result->id];
382 if (skb == NULL) {
383 wl1251_error("SKB for packet %d is NULL", result->id);
384 return;
385 }
386
387 info = IEEE80211_SKB_CB(skb);
388
389 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK) &&
390 (result->status == TX_SUCCESS))
391 info->flags |= IEEE80211_TX_STAT_ACK;
392
393 info->status.rates[0].count = result->ack_failures + 1;
394 wl->stats.retry_count += result->ack_failures;
395
396 /*
397 * We have to remove our private TX header before pushing
398 * the skb back to mac80211.
399 */
400 frame = skb_pull(skb, sizeof(struct tx_double_buffer_desc));
401 if (info->control.hw_key &&
402 info->control.hw_key->alg == ALG_TKIP) {
403 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
404 memmove(frame + WL1251_TKIP_IV_SPACE, frame, hdrlen);
405 skb_pull(skb, WL1251_TKIP_IV_SPACE);
406 }
407
408 wl1251_debug(DEBUG_TX, "tx status id %u skb 0x%p failures %u rate 0x%x"
409 " status 0x%x (%s)",
410 result->id, skb, result->ack_failures, result->rate,
411 result->status, wl1251_tx_parse_status(result->status));
412
413
414 ieee80211_tx_status(wl->hw, skb);
415
416 wl->tx_frames[result->id] = NULL;
417
418 if (wl->tx_queue_stopped) {
419 wl1251_debug(DEBUG_TX, "cb: queue was stopped");
420
421 skb = skb_dequeue(&wl->tx_queue);
422
423 /* The skb can be NULL because tx_work might have been
424 scheduled before the queue was stopped making the
425 queue empty */
426
427 if (skb) {
428 ret = wl1251_tx_frame(wl, skb);
429 if (ret == -EBUSY) {
430 /* firmware buffer is still full */
431 wl1251_debug(DEBUG_TX, "cb: fw buffer "
432 "still full");
433 skb_queue_head(&wl->tx_queue, skb);
434 return;
435 } else if (ret < 0) {
436 dev_kfree_skb(skb);
437 return;
438 }
439 }
440
441 wl1251_debug(DEBUG_TX, "cb: waking queues");
442 ieee80211_wake_queues(wl->hw);
443 wl->tx_queue_stopped = false;
444 }
445}
446
447/* Called upon reception of a TX complete interrupt */
448void wl1251_tx_complete(struct wl1251 *wl)
449{
450 int i, result_index, num_complete = 0;
451 struct tx_result result[FW_TX_CMPLT_BLOCK_SIZE], *result_ptr;
452
453 if (unlikely(wl->state != WL1251_STATE_ON))
454 return;
455
456 /* First we read the result */
457 wl1251_mem_read(wl, wl->data_path->tx_complete_addr,
458 result, sizeof(result));
459
460 result_index = wl->next_tx_complete;
461
462 for (i = 0; i < ARRAY_SIZE(result); i++) {
463 result_ptr = &result[result_index];
464
465 if (result_ptr->done_1 == 1 &&
466 result_ptr->done_2 == 1) {
467 wl1251_tx_packet_cb(wl, result_ptr);
468
469 result_ptr->done_1 = 0;
470 result_ptr->done_2 = 0;
471
472 result_index = (result_index + 1) &
473 (FW_TX_CMPLT_BLOCK_SIZE - 1);
474 num_complete++;
475 } else {
476 break;
477 }
478 }
479
480 /* Every completed frame needs to be acknowledged */
481 if (num_complete) {
482 /*
483 * If we've wrapped, we have to clear
484 * the results in 2 steps.
485 */
486 if (result_index > wl->next_tx_complete) {
487 /* Only 1 write is needed */
488 wl1251_mem_write(wl,
489 wl->data_path->tx_complete_addr +
490 (wl->next_tx_complete *
491 sizeof(struct tx_result)),
492 &result[wl->next_tx_complete],
493 num_complete *
494 sizeof(struct tx_result));
495
496
497 } else if (result_index < wl->next_tx_complete) {
498 /* 2 writes are needed */
499 wl1251_mem_write(wl,
500 wl->data_path->tx_complete_addr +
501 (wl->next_tx_complete *
502 sizeof(struct tx_result)),
503 &result[wl->next_tx_complete],
504 (FW_TX_CMPLT_BLOCK_SIZE -
505 wl->next_tx_complete) *
506 sizeof(struct tx_result));
507
508 wl1251_mem_write(wl,
509 wl->data_path->tx_complete_addr,
510 result,
511 (num_complete -
512 FW_TX_CMPLT_BLOCK_SIZE +
513 wl->next_tx_complete) *
514 sizeof(struct tx_result));
515
516 } else {
517 /* We have to write the whole array */
518 wl1251_mem_write(wl,
519 wl->data_path->tx_complete_addr,
520 result,
521 FW_TX_CMPLT_BLOCK_SIZE *
522 sizeof(struct tx_result));
523 }
524
525 }
526
527 wl->next_tx_complete = result_index;
528}
529
530/* caller must hold wl->mutex */
531void wl1251_tx_flush(struct wl1251 *wl)
532{
533 int i;
534 struct sk_buff *skb;
535 struct ieee80211_tx_info *info;
536
537 /* TX failure */
538/* control->flags = 0; FIXME */
539
540 while ((skb = skb_dequeue(&wl->tx_queue))) {
541 info = IEEE80211_SKB_CB(skb);
542
543 wl1251_debug(DEBUG_TX, "flushing skb 0x%p", skb);
544
545 if (!(info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS))
546 continue;
547
548 ieee80211_tx_status(wl->hw, skb);
549 }
550
551 for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
552 if (wl->tx_frames[i] != NULL) {
553 skb = wl->tx_frames[i];
554 info = IEEE80211_SKB_CB(skb);
555
556 if (!(info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS))
557 continue;
558
559 ieee80211_tx_status(wl->hw, skb);
560 wl->tx_frames[i] = NULL;
561 }
562}
diff --git a/drivers/net/wireless/wl12xx/wl1251_tx.h b/drivers/net/wireless/wl12xx/wl1251_tx.h
deleted file mode 100644
index f40eeb37f5aa..000000000000
--- a/drivers/net/wireless/wl12xx/wl1251_tx.h
+++ /dev/null
@@ -1,233 +0,0 @@
1/*
2 * This file is part of wl1251
3 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation
6 *
7 * Contact: Kalle Valo <kalle.valo@nokia.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25#ifndef __WL1251_TX_H__
26#define __WL1251_TX_H__
27
28#include <linux/bitops.h>
29#include "wl1251_acx.h"
30
31/*
32 *
33 * TX PATH
34 *
35 * The Tx path uses a double buffer and a tx_control structure, each located
36 * at a fixed address in the device's memory. On startup, the host retrieves
37 * the pointers to these addresses. A double buffer allows for continuous data
38 * flow towards the device. The host keeps track of which buffer is available
39 * and alternates between these two buffers on a per packet basis.
40 *
41 * The size of each of the two buffers is large enough to hold the longest
42 * 802.3 packet - maximum size Ethernet packet + header + descriptor.
43 * TX complete indication will be received a-synchronously in a TX done cyclic
44 * buffer which is composed of 16 tx_result descriptors structures and is used
45 * in a cyclic manner.
46 *
47 * The TX (HOST) procedure is as follows:
48 * 1. Read the Tx path status, that will give the data_out_count.
49 * 2. goto 1, if not possible.
50 * i.e. if data_in_count - data_out_count >= HwBuffer size (2 for double
51 * buffer).
52 * 3. Copy the packet (preceded by double_buffer_desc), if possible.
53 * i.e. if data_in_count - data_out_count < HwBuffer size (2 for double
54 * buffer).
55 * 4. increment data_in_count.
56 * 5. Inform the firmware by generating a firmware internal interrupt.
57 * 6. FW will increment data_out_count after it reads the buffer.
58 *
59 * The TX Complete procedure:
60 * 1. To get a TX complete indication the host enables the tx_complete flag in
61 * the TX descriptor Structure.
62 * 2. For each packet with a Tx Complete field set, the firmware adds the
63 * transmit results to the cyclic buffer (txDoneRing) and sets both done_1
64 * and done_2 to 1 to indicate driver ownership.
65 * 3. The firmware sends a Tx Complete interrupt to the host to trigger the
66 * host to process the new data. Note: interrupt will be send per packet if
67 * TX complete indication was requested in tx_control or per crossing
68 * aggregation threshold.
69 * 4. After receiving the Tx Complete interrupt, the host reads the
70 * TxDescriptorDone information in a cyclic manner and clears both done_1
71 * and done_2 fields.
72 *
73 */
74
75#define TX_COMPLETE_REQUIRED_BIT 0x80
76#define TX_STATUS_DATA_OUT_COUNT_MASK 0xf
77
78#define WL1251_TX_ALIGN_TO 4
79#define WL1251_TX_ALIGN(len) (((len) + WL1251_TX_ALIGN_TO - 1) & \
80 ~(WL1251_TX_ALIGN_TO - 1))
81#define WL1251_TKIP_IV_SPACE 4
82
83struct tx_control {
84 /* Rate Policy (class) index */
85 unsigned rate_policy:3;
86
87 /* When set, no ack policy is expected */
88 unsigned ack_policy:1;
89
90 /*
91 * Packet type:
92 * 0 -> 802.11
93 * 1 -> 802.3
94 * 2 -> IP
95 * 3 -> raw codec
96 */
97 unsigned packet_type:2;
98
99 /* If set, this is a QoS-Null or QoS-Data frame */
100 unsigned qos:1;
101
102 /*
103 * If set, the target triggers the tx complete INT
104 * upon frame sending completion.
105 */
106 unsigned tx_complete:1;
107
108 /* 2 bytes padding before packet header */
109 unsigned xfer_pad:1;
110
111 unsigned reserved:7;
112} __packed;
113
114
115struct tx_double_buffer_desc {
116 /* Length of payload, including headers. */
117 __le16 length;
118
119 /*
120 * A bit mask that specifies the initial rate to be used
121 * Possible values are:
122 * 0x0001 - 1Mbits
123 * 0x0002 - 2Mbits
124 * 0x0004 - 5.5Mbits
125 * 0x0008 - 6Mbits
126 * 0x0010 - 9Mbits
127 * 0x0020 - 11Mbits
128 * 0x0040 - 12Mbits
129 * 0x0080 - 18Mbits
130 * 0x0100 - 22Mbits
131 * 0x0200 - 24Mbits
132 * 0x0400 - 36Mbits
133 * 0x0800 - 48Mbits
134 * 0x1000 - 54Mbits
135 */
136 __le16 rate;
137
138 /* Time in us that a packet can spend in the target */
139 __le32 expiry_time;
140
141 /* index of the TX queue used for this packet */
142 u8 xmit_queue;
143
144 /* Used to identify a packet */
145 u8 id;
146
147 struct tx_control control;
148
149 /*
150 * The FW should cut the packet into fragments
151 * of this size.
152 */
153 __le16 frag_threshold;
154
155 /* Numbers of HW queue blocks to be allocated */
156 u8 num_mem_blocks;
157
158 u8 reserved;
159} __packed;
160
161enum {
162 TX_SUCCESS = 0,
163 TX_DMA_ERROR = BIT(7),
164 TX_DISABLED = BIT(6),
165 TX_RETRY_EXCEEDED = BIT(5),
166 TX_TIMEOUT = BIT(4),
167 TX_KEY_NOT_FOUND = BIT(3),
168 TX_ENCRYPT_FAIL = BIT(2),
169 TX_UNAVAILABLE_PRIORITY = BIT(1),
170};
171
172struct tx_result {
173 /*
174 * Ownership synchronization between the host and
175 * the firmware. If done_1 and done_2 are cleared,
176 * owned by the FW (no info ready).
177 */
178 u8 done_1;
179
180 /* same as double_buffer_desc->id */
181 u8 id;
182
183 /*
184 * Total air access duration consumed by this
185 * packet, including all retries and overheads.
186 */
187 u16 medium_usage;
188
189 /* Total media delay (from 1st EDCA AIFS counter until TX Complete). */
190 u32 medium_delay;
191
192 /* Time between host xfer and tx complete */
193 u32 fw_hnadling_time;
194
195 /* The LS-byte of the last TKIP sequence number. */
196 u8 lsb_seq_num;
197
198 /* Retry count */
199 u8 ack_failures;
200
201 /* At which rate we got a ACK */
202 u16 rate;
203
204 u16 reserved;
205
206 /* TX_* */
207 u8 status;
208
209 /* See done_1 */
210 u8 done_2;
211} __packed;
212
213static inline int wl1251_tx_get_queue(int queue)
214{
215 switch (queue) {
216 case 0:
217 return QOS_AC_VO;
218 case 1:
219 return QOS_AC_VI;
220 case 2:
221 return QOS_AC_BE;
222 case 3:
223 return QOS_AC_BK;
224 default:
225 return QOS_AC_BE;
226 }
227}
228
229void wl1251_tx_work(struct work_struct *work);
230void wl1251_tx_complete(struct wl1251 *wl);
231void wl1251_tx_flush(struct wl1251 *wl);
232
233#endif
diff --git a/drivers/net/wireless/wl12xx/wl1271.h b/drivers/net/wireless/wl12xx/wl1271.h
deleted file mode 100644
index dd3cee6ea5bb..000000000000
--- a/drivers/net/wireless/wl12xx/wl1271.h
+++ /dev/null
@@ -1,510 +0,0 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
5 * Copyright (C) 2008-2009 Nokia Corporation
6 *
7 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25#ifndef __WL1271_H__
26#define __WL1271_H__
27
28#include <linux/mutex.h>
29#include <linux/completion.h>
30#include <linux/spinlock.h>
31#include <linux/list.h>
32#include <linux/bitops.h>
33#include <net/mac80211.h>
34
35#include "wl1271_conf.h"
36#include "wl1271_ini.h"
37
38#define DRIVER_NAME "wl1271"
39#define DRIVER_PREFIX DRIVER_NAME ": "
40
41enum {
42 DEBUG_NONE = 0,
43 DEBUG_IRQ = BIT(0),
44 DEBUG_SPI = BIT(1),
45 DEBUG_BOOT = BIT(2),
46 DEBUG_MAILBOX = BIT(3),
47 DEBUG_TESTMODE = BIT(4),
48 DEBUG_EVENT = BIT(5),
49 DEBUG_TX = BIT(6),
50 DEBUG_RX = BIT(7),
51 DEBUG_SCAN = BIT(8),
52 DEBUG_CRYPT = BIT(9),
53 DEBUG_PSM = BIT(10),
54 DEBUG_MAC80211 = BIT(11),
55 DEBUG_CMD = BIT(12),
56 DEBUG_ACX = BIT(13),
57 DEBUG_SDIO = BIT(14),
58 DEBUG_FILTERS = BIT(15),
59 DEBUG_ADHOC = BIT(16),
60 DEBUG_ALL = ~0,
61};
62
63#define DEBUG_LEVEL (DEBUG_NONE)
64
65#define DEBUG_DUMP_LIMIT 1024
66
67#define wl1271_error(fmt, arg...) \
68 printk(KERN_ERR DRIVER_PREFIX "ERROR " fmt "\n", ##arg)
69
70#define wl1271_warning(fmt, arg...) \
71 printk(KERN_WARNING DRIVER_PREFIX "WARNING " fmt "\n", ##arg)
72
73#define wl1271_notice(fmt, arg...) \
74 printk(KERN_INFO DRIVER_PREFIX fmt "\n", ##arg)
75
76#define wl1271_info(fmt, arg...) \
77 printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg)
78
79#define wl1271_debug(level, fmt, arg...) \
80 do { \
81 if (level & DEBUG_LEVEL) \
82 printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg); \
83 } while (0)
84
85#define wl1271_dump(level, prefix, buf, len) \
86 do { \
87 if (level & DEBUG_LEVEL) \
88 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
89 DUMP_PREFIX_OFFSET, 16, 1, \
90 buf, \
91 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
92 0); \
93 } while (0)
94
95#define wl1271_dump_ascii(level, prefix, buf, len) \
96 do { \
97 if (level & DEBUG_LEVEL) \
98 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
99 DUMP_PREFIX_OFFSET, 16, 1, \
100 buf, \
101 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
102 true); \
103 } while (0)
104
105#define WL1271_DEFAULT_RX_CONFIG (CFG_UNI_FILTER_EN | \
106 CFG_BSSID_FILTER_EN | \
107 CFG_MC_FILTER_EN)
108
109#define WL1271_DEFAULT_RX_FILTER (CFG_RX_RCTS_ACK | CFG_RX_PRSP_EN | \
110 CFG_RX_MGMT_EN | CFG_RX_DATA_EN | \
111 CFG_RX_CTL_EN | CFG_RX_BCN_EN | \
112 CFG_RX_AUTH_EN | CFG_RX_ASSOC_EN)
113
114#define WL1271_FW_NAME "wl1271-fw.bin"
115#define WL1271_NVS_NAME "wl1271-nvs.bin"
116
117#define WL1271_TX_SECURITY_LO16(s) ((u16)((s) & 0xffff))
118#define WL1271_TX_SECURITY_HI32(s) ((u32)(((s) >> 16) & 0xffffffff))
119
120/*
121 * Enable/disable 802.11a support for WL1273
122 */
123#undef WL1271_80211A_ENABLED
124
125#define WL1271_BUSY_WORD_CNT 1
126#define WL1271_BUSY_WORD_LEN (WL1271_BUSY_WORD_CNT * sizeof(u32))
127
128#define WL1271_ELP_HW_STATE_ASLEEP 0
129#define WL1271_ELP_HW_STATE_IRQ 1
130
131#define WL1271_DEFAULT_BEACON_INT 100
132#define WL1271_DEFAULT_DTIM_PERIOD 1
133
134#define ACX_TX_DESCRIPTORS 32
135
136enum wl1271_state {
137 WL1271_STATE_OFF,
138 WL1271_STATE_ON,
139 WL1271_STATE_PLT,
140};
141
142enum wl1271_partition_type {
143 PART_DOWN,
144 PART_WORK,
145 PART_DRPW,
146
147 PART_TABLE_LEN
148};
149
150struct wl1271_partition {
151 u32 size;
152 u32 start;
153};
154
155struct wl1271_partition_set {
156 struct wl1271_partition mem;
157 struct wl1271_partition reg;
158 struct wl1271_partition mem2;
159 struct wl1271_partition mem3;
160};
161
162struct wl1271;
163
164/* FIXME: I'm not sure about this structure name */
165struct wl1271_chip {
166 u32 id;
167 char fw_ver[21];
168};
169
170struct wl1271_stats {
171 struct acx_statistics *fw_stats;
172 unsigned long fw_stats_update;
173
174 unsigned int retry_count;
175 unsigned int excessive_retries;
176};
177
178struct wl1271_debugfs {
179 struct dentry *rootdir;
180 struct dentry *fw_statistics;
181
182 struct dentry *tx_internal_desc_overflow;
183
184 struct dentry *rx_out_of_mem;
185 struct dentry *rx_hdr_overflow;
186 struct dentry *rx_hw_stuck;
187 struct dentry *rx_dropped;
188 struct dentry *rx_fcs_err;
189 struct dentry *rx_xfr_hint_trig;
190 struct dentry *rx_path_reset;
191 struct dentry *rx_reset_counter;
192
193 struct dentry *dma_rx_requested;
194 struct dentry *dma_rx_errors;
195 struct dentry *dma_tx_requested;
196 struct dentry *dma_tx_errors;
197
198 struct dentry *isr_cmd_cmplt;
199 struct dentry *isr_fiqs;
200 struct dentry *isr_rx_headers;
201 struct dentry *isr_rx_mem_overflow;
202 struct dentry *isr_rx_rdys;
203 struct dentry *isr_irqs;
204 struct dentry *isr_tx_procs;
205 struct dentry *isr_decrypt_done;
206 struct dentry *isr_dma0_done;
207 struct dentry *isr_dma1_done;
208 struct dentry *isr_tx_exch_complete;
209 struct dentry *isr_commands;
210 struct dentry *isr_rx_procs;
211 struct dentry *isr_hw_pm_mode_changes;
212 struct dentry *isr_host_acknowledges;
213 struct dentry *isr_pci_pm;
214 struct dentry *isr_wakeups;
215 struct dentry *isr_low_rssi;
216
217 struct dentry *wep_addr_key_count;
218 struct dentry *wep_default_key_count;
219 /* skipping wep.reserved */
220 struct dentry *wep_key_not_found;
221 struct dentry *wep_decrypt_fail;
222 struct dentry *wep_packets;
223 struct dentry *wep_interrupt;
224
225 struct dentry *pwr_ps_enter;
226 struct dentry *pwr_elp_enter;
227 struct dentry *pwr_missing_bcns;
228 struct dentry *pwr_wake_on_host;
229 struct dentry *pwr_wake_on_timer_exp;
230 struct dentry *pwr_tx_with_ps;
231 struct dentry *pwr_tx_without_ps;
232 struct dentry *pwr_rcvd_beacons;
233 struct dentry *pwr_power_save_off;
234 struct dentry *pwr_enable_ps;
235 struct dentry *pwr_disable_ps;
236 struct dentry *pwr_fix_tsf_ps;
237 /* skipping cont_miss_bcns_spread for now */
238 struct dentry *pwr_rcvd_awake_beacons;
239
240 struct dentry *mic_rx_pkts;
241 struct dentry *mic_calc_failure;
242
243 struct dentry *aes_encrypt_fail;
244 struct dentry *aes_decrypt_fail;
245 struct dentry *aes_encrypt_packets;
246 struct dentry *aes_decrypt_packets;
247 struct dentry *aes_encrypt_interrupt;
248 struct dentry *aes_decrypt_interrupt;
249
250 struct dentry *event_heart_beat;
251 struct dentry *event_calibration;
252 struct dentry *event_rx_mismatch;
253 struct dentry *event_rx_mem_empty;
254 struct dentry *event_rx_pool;
255 struct dentry *event_oom_late;
256 struct dentry *event_phy_transmit_error;
257 struct dentry *event_tx_stuck;
258
259 struct dentry *ps_pspoll_timeouts;
260 struct dentry *ps_upsd_timeouts;
261 struct dentry *ps_upsd_max_sptime;
262 struct dentry *ps_upsd_max_apturn;
263 struct dentry *ps_pspoll_max_apturn;
264 struct dentry *ps_pspoll_utilization;
265 struct dentry *ps_upsd_utilization;
266
267 struct dentry *rxpipe_rx_prep_beacon_drop;
268 struct dentry *rxpipe_descr_host_int_trig_rx_data;
269 struct dentry *rxpipe_beacon_buffer_thres_host_int_trig_rx_data;
270 struct dentry *rxpipe_missed_beacon_host_int_trig_rx_data;
271 struct dentry *rxpipe_tx_xfr_host_int_trig_rx_data;
272
273 struct dentry *tx_queue_len;
274
275 struct dentry *retry_count;
276 struct dentry *excessive_retries;
277 struct dentry *gpio_power;
278};
279
280#define NUM_TX_QUEUES 4
281#define NUM_RX_PKT_DESC 8
282
283/* FW status registers */
284struct wl1271_fw_status {
285 __le32 intr;
286 u8 fw_rx_counter;
287 u8 drv_rx_counter;
288 u8 reserved;
289 u8 tx_results_counter;
290 __le32 rx_pkt_descs[NUM_RX_PKT_DESC];
291 __le32 tx_released_blks[NUM_TX_QUEUES];
292 __le32 fw_localtime;
293 __le32 padding[2];
294} __packed;
295
296struct wl1271_rx_mem_pool_addr {
297 u32 addr;
298 u32 addr_extra;
299};
300
301struct wl1271_scan {
302 struct cfg80211_scan_request *req;
303 bool *scanned_ch;
304 u8 state;
305 u8 ssid[IW_ESSID_MAX_SIZE+1];
306 size_t ssid_len;
307};
308
309struct wl1271_if_operations {
310 void (*read)(struct wl1271 *wl, int addr, void *buf, size_t len,
311 bool fixed);
312 void (*write)(struct wl1271 *wl, int addr, void *buf, size_t len,
313 bool fixed);
314 void (*reset)(struct wl1271 *wl);
315 void (*init)(struct wl1271 *wl);
316 void (*power)(struct wl1271 *wl, bool enable);
317 struct device* (*dev)(struct wl1271 *wl);
318 void (*enable_irq)(struct wl1271 *wl);
319 void (*disable_irq)(struct wl1271 *wl);
320};
321
322struct wl1271 {
323 struct platform_device *plat_dev;
324 struct ieee80211_hw *hw;
325 bool mac80211_registered;
326
327 void *if_priv;
328
329 struct wl1271_if_operations *if_ops;
330
331 void (*set_power)(bool enable);
332 int irq;
333
334 spinlock_t wl_lock;
335
336 enum wl1271_state state;
337 struct mutex mutex;
338
339#define WL1271_FLAG_STA_RATES_CHANGED (0)
340#define WL1271_FLAG_STA_ASSOCIATED (1)
341#define WL1271_FLAG_JOINED (2)
342#define WL1271_FLAG_GPIO_POWER (3)
343#define WL1271_FLAG_TX_QUEUE_STOPPED (4)
344#define WL1271_FLAG_IN_ELP (5)
345#define WL1271_FLAG_PSM (6)
346#define WL1271_FLAG_PSM_REQUESTED (7)
347#define WL1271_FLAG_IRQ_PENDING (8)
348#define WL1271_FLAG_IRQ_RUNNING (9)
349#define WL1271_FLAG_IDLE (10)
350#define WL1271_FLAG_IDLE_REQUESTED (11)
351#define WL1271_FLAG_PSPOLL_FAILURE (12)
352 unsigned long flags;
353
354 struct wl1271_partition_set part;
355
356 struct wl1271_chip chip;
357
358 int cmd_box_addr;
359 int event_box_addr;
360
361 u8 *fw;
362 size_t fw_len;
363 struct wl1271_nvs_file *nvs;
364
365 s8 hw_pg_ver;
366
367 u8 bssid[ETH_ALEN];
368 u8 mac_addr[ETH_ALEN];
369 u8 bss_type;
370 u8 set_bss_type;
371 u8 ssid[IW_ESSID_MAX_SIZE + 1];
372 u8 ssid_len;
373 int channel;
374
375 struct wl1271_acx_mem_map *target_mem_map;
376
377 /* Accounting for allocated / available TX blocks on HW */
378 u32 tx_blocks_freed[NUM_TX_QUEUES];
379 u32 tx_blocks_available;
380 u32 tx_results_count;
381
382 /* Transmitted TX packets counter for chipset interface */
383 u32 tx_packets_count;
384
385 /* Time-offset between host and chipset clocks */
386 s64 time_offset;
387
388 /* Session counter for the chipset */
389 int session_counter;
390
391 /* Frames scheduled for transmission, not handled yet */
392 struct sk_buff_head tx_queue;
393
394 struct work_struct tx_work;
395
396 /* Pending TX frames */
397 struct sk_buff *tx_frames[ACX_TX_DESCRIPTORS];
398 int tx_frames_cnt;
399
400 /* Security sequence number counters */
401 u8 tx_security_last_seq;
402 s64 tx_security_seq;
403
404 /* FW Rx counter */
405 u32 rx_counter;
406
407 /* Rx memory pool address */
408 struct wl1271_rx_mem_pool_addr rx_mem_pool_addr;
409
410 /* The target interrupt mask */
411 struct work_struct irq_work;
412
413 /* The mbox event mask */
414 u32 event_mask;
415
416 /* Mailbox pointers */
417 u32 mbox_ptr[2];
418
419 /* Are we currently scanning */
420 struct wl1271_scan scan;
421
422 /* Our association ID */
423 u16 aid;
424
425 /* currently configured rate set */
426 u32 sta_rate_set;
427 u32 basic_rate_set;
428 u32 basic_rate;
429 u32 rate_set;
430
431 /* The current band */
432 enum ieee80211_band band;
433
434 /* Beaconing interval (needed for ad-hoc) */
435 u32 beacon_int;
436
437 /* Default key (for WEP) */
438 u32 default_key;
439
440 unsigned int filters;
441 unsigned int rx_config;
442 unsigned int rx_filter;
443
444 struct completion *elp_compl;
445 struct delayed_work elp_work;
446 struct delayed_work pspoll_work;
447
448 /* counter for ps-poll delivery failures */
449 int ps_poll_failures;
450
451 /* retry counter for PSM entries */
452 u8 psm_entry_retry;
453
454 /* in dBm */
455 int power_level;
456
457 int rssi_thold;
458 int last_rssi_event;
459
460 struct wl1271_stats stats;
461 struct wl1271_debugfs debugfs;
462
463 __le32 buffer_32;
464 u32 buffer_cmd;
465 u32 buffer_busyword[WL1271_BUSY_WORD_CNT];
466
467 struct wl1271_fw_status *fw_status;
468 struct wl1271_tx_hw_res_if *tx_res_if;
469
470 struct ieee80211_vif *vif;
471
472 /* Current chipset configuration */
473 struct conf_drv_settings conf;
474
475 bool sg_enabled;
476
477 struct list_head list;
478
479 /* Most recently reported noise in dBm */
480 s8 noise;
481};
482
483int wl1271_plt_start(struct wl1271 *wl);
484int wl1271_plt_stop(struct wl1271 *wl);
485
486#define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
487
488#define SESSION_COUNTER_MAX 7 /* maximum value for the session counter */
489
490#define WL1271_DEFAULT_POWER_LEVEL 0
491
492#define WL1271_TX_QUEUE_LOW_WATERMARK 10
493#define WL1271_TX_QUEUE_HIGH_WATERMARK 25
494
495/* WL1271 needs a 200ms sleep after power on, and a 20ms sleep before power
496 on in case is has been shut down shortly before */
497#define WL1271_PRE_POWER_ON_SLEEP 20 /* in miliseconds */
498#define WL1271_POWER_ON_SLEEP 200 /* in miliseconds */
499
500static inline bool wl1271_11a_enabled(void)
501{
502 /* FIXME: this could be determined based on the NVS-INI file */
503#ifdef WL1271_80211A_ENABLED
504 return true;
505#else
506 return false;
507#endif
508}
509
510#endif
diff --git a/drivers/net/wireless/wl12xx/wl1271_debugfs.c b/drivers/net/wireless/wl12xx/wl1271_debugfs.c
deleted file mode 100644
index c239ef4d0b8d..000000000000
--- a/drivers/net/wireless/wl12xx/wl1271_debugfs.c
+++ /dev/null
@@ -1,579 +0,0 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 *
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include "wl1271_debugfs.h"
25
26#include <linux/skbuff.h>
27#include <linux/slab.h>
28
29#include "wl1271.h"
30#include "wl1271_acx.h"
31#include "wl1271_ps.h"
32#include "wl1271_io.h"
33
34/* ms */
35#define WL1271_DEBUGFS_STATS_LIFETIME 1000
36
37/* debugfs macros idea from mac80211 */
38
39#define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \
40static ssize_t name## _read(struct file *file, char __user *userbuf, \
41 size_t count, loff_t *ppos) \
42{ \
43 struct wl1271 *wl = file->private_data; \
44 char buf[buflen]; \
45 int res; \
46 \
47 res = scnprintf(buf, buflen, fmt "\n", ##value); \
48 return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
49} \
50 \
51static const struct file_operations name## _ops = { \
52 .read = name## _read, \
53 .open = wl1271_open_file_generic, \
54};
55
56#define DEBUGFS_ADD(name, parent) \
57 wl->debugfs.name = debugfs_create_file(#name, 0400, parent, \
58 wl, &name## _ops); \
59 if (IS_ERR(wl->debugfs.name)) { \
60 ret = PTR_ERR(wl->debugfs.name); \
61 wl->debugfs.name = NULL; \
62 goto out; \
63 }
64
65#define DEBUGFS_DEL(name) \
66 do { \
67 debugfs_remove(wl->debugfs.name); \
68 wl->debugfs.name = NULL; \
69 } while (0)
70
71#define DEBUGFS_FWSTATS_FILE(sub, name, buflen, fmt) \
72static ssize_t sub## _ ##name## _read(struct file *file, \
73 char __user *userbuf, \
74 size_t count, loff_t *ppos) \
75{ \
76 struct wl1271 *wl = file->private_data; \
77 char buf[buflen]; \
78 int res; \
79 \
80 wl1271_debugfs_update_stats(wl); \
81 \
82 res = scnprintf(buf, buflen, fmt "\n", \
83 wl->stats.fw_stats->sub.name); \
84 return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
85} \
86 \
87static const struct file_operations sub## _ ##name## _ops = { \
88 .read = sub## _ ##name## _read, \
89 .open = wl1271_open_file_generic, \
90};
91
92#define DEBUGFS_FWSTATS_ADD(sub, name) \
93 DEBUGFS_ADD(sub## _ ##name, wl->debugfs.fw_statistics)
94
95#define DEBUGFS_FWSTATS_DEL(sub, name) \
96 DEBUGFS_DEL(sub## _ ##name)
97
98static void wl1271_debugfs_update_stats(struct wl1271 *wl)
99{
100 int ret;
101
102 mutex_lock(&wl->mutex);
103
104 ret = wl1271_ps_elp_wakeup(wl, false);
105 if (ret < 0)
106 goto out;
107
108 if (wl->state == WL1271_STATE_ON &&
109 time_after(jiffies, wl->stats.fw_stats_update +
110 msecs_to_jiffies(WL1271_DEBUGFS_STATS_LIFETIME))) {
111 wl1271_acx_statistics(wl, wl->stats.fw_stats);
112 wl->stats.fw_stats_update = jiffies;
113 }
114
115 wl1271_ps_elp_sleep(wl);
116
117out:
118 mutex_unlock(&wl->mutex);
119}
120
121static int wl1271_open_file_generic(struct inode *inode, struct file *file)
122{
123 file->private_data = inode->i_private;
124 return 0;
125}
126
127DEBUGFS_FWSTATS_FILE(tx, internal_desc_overflow, 20, "%u");
128
129DEBUGFS_FWSTATS_FILE(rx, out_of_mem, 20, "%u");
130DEBUGFS_FWSTATS_FILE(rx, hdr_overflow, 20, "%u");
131DEBUGFS_FWSTATS_FILE(rx, hw_stuck, 20, "%u");
132DEBUGFS_FWSTATS_FILE(rx, dropped, 20, "%u");
133DEBUGFS_FWSTATS_FILE(rx, fcs_err, 20, "%u");
134DEBUGFS_FWSTATS_FILE(rx, xfr_hint_trig, 20, "%u");
135DEBUGFS_FWSTATS_FILE(rx, path_reset, 20, "%u");
136DEBUGFS_FWSTATS_FILE(rx, reset_counter, 20, "%u");
137
138DEBUGFS_FWSTATS_FILE(dma, rx_requested, 20, "%u");
139DEBUGFS_FWSTATS_FILE(dma, rx_errors, 20, "%u");
140DEBUGFS_FWSTATS_FILE(dma, tx_requested, 20, "%u");
141DEBUGFS_FWSTATS_FILE(dma, tx_errors, 20, "%u");
142
143DEBUGFS_FWSTATS_FILE(isr, cmd_cmplt, 20, "%u");
144DEBUGFS_FWSTATS_FILE(isr, fiqs, 20, "%u");
145DEBUGFS_FWSTATS_FILE(isr, rx_headers, 20, "%u");
146DEBUGFS_FWSTATS_FILE(isr, rx_mem_overflow, 20, "%u");
147DEBUGFS_FWSTATS_FILE(isr, rx_rdys, 20, "%u");
148DEBUGFS_FWSTATS_FILE(isr, irqs, 20, "%u");
149DEBUGFS_FWSTATS_FILE(isr, tx_procs, 20, "%u");
150DEBUGFS_FWSTATS_FILE(isr, decrypt_done, 20, "%u");
151DEBUGFS_FWSTATS_FILE(isr, dma0_done, 20, "%u");
152DEBUGFS_FWSTATS_FILE(isr, dma1_done, 20, "%u");
153DEBUGFS_FWSTATS_FILE(isr, tx_exch_complete, 20, "%u");
154DEBUGFS_FWSTATS_FILE(isr, commands, 20, "%u");
155DEBUGFS_FWSTATS_FILE(isr, rx_procs, 20, "%u");
156DEBUGFS_FWSTATS_FILE(isr, hw_pm_mode_changes, 20, "%u");
157DEBUGFS_FWSTATS_FILE(isr, host_acknowledges, 20, "%u");
158DEBUGFS_FWSTATS_FILE(isr, pci_pm, 20, "%u");
159DEBUGFS_FWSTATS_FILE(isr, wakeups, 20, "%u");
160DEBUGFS_FWSTATS_FILE(isr, low_rssi, 20, "%u");
161
162DEBUGFS_FWSTATS_FILE(wep, addr_key_count, 20, "%u");
163DEBUGFS_FWSTATS_FILE(wep, default_key_count, 20, "%u");
164/* skipping wep.reserved */
165DEBUGFS_FWSTATS_FILE(wep, key_not_found, 20, "%u");
166DEBUGFS_FWSTATS_FILE(wep, decrypt_fail, 20, "%u");
167DEBUGFS_FWSTATS_FILE(wep, packets, 20, "%u");
168DEBUGFS_FWSTATS_FILE(wep, interrupt, 20, "%u");
169
170DEBUGFS_FWSTATS_FILE(pwr, ps_enter, 20, "%u");
171DEBUGFS_FWSTATS_FILE(pwr, elp_enter, 20, "%u");
172DEBUGFS_FWSTATS_FILE(pwr, missing_bcns, 20, "%u");
173DEBUGFS_FWSTATS_FILE(pwr, wake_on_host, 20, "%u");
174DEBUGFS_FWSTATS_FILE(pwr, wake_on_timer_exp, 20, "%u");
175DEBUGFS_FWSTATS_FILE(pwr, tx_with_ps, 20, "%u");
176DEBUGFS_FWSTATS_FILE(pwr, tx_without_ps, 20, "%u");
177DEBUGFS_FWSTATS_FILE(pwr, rcvd_beacons, 20, "%u");
178DEBUGFS_FWSTATS_FILE(pwr, power_save_off, 20, "%u");
179DEBUGFS_FWSTATS_FILE(pwr, enable_ps, 20, "%u");
180DEBUGFS_FWSTATS_FILE(pwr, disable_ps, 20, "%u");
181DEBUGFS_FWSTATS_FILE(pwr, fix_tsf_ps, 20, "%u");
182/* skipping cont_miss_bcns_spread for now */
183DEBUGFS_FWSTATS_FILE(pwr, rcvd_awake_beacons, 20, "%u");
184
185DEBUGFS_FWSTATS_FILE(mic, rx_pkts, 20, "%u");
186DEBUGFS_FWSTATS_FILE(mic, calc_failure, 20, "%u");
187
188DEBUGFS_FWSTATS_FILE(aes, encrypt_fail, 20, "%u");
189DEBUGFS_FWSTATS_FILE(aes, decrypt_fail, 20, "%u");
190DEBUGFS_FWSTATS_FILE(aes, encrypt_packets, 20, "%u");
191DEBUGFS_FWSTATS_FILE(aes, decrypt_packets, 20, "%u");
192DEBUGFS_FWSTATS_FILE(aes, encrypt_interrupt, 20, "%u");
193DEBUGFS_FWSTATS_FILE(aes, decrypt_interrupt, 20, "%u");
194
195DEBUGFS_FWSTATS_FILE(event, heart_beat, 20, "%u");
196DEBUGFS_FWSTATS_FILE(event, calibration, 20, "%u");
197DEBUGFS_FWSTATS_FILE(event, rx_mismatch, 20, "%u");
198DEBUGFS_FWSTATS_FILE(event, rx_mem_empty, 20, "%u");
199DEBUGFS_FWSTATS_FILE(event, rx_pool, 20, "%u");
200DEBUGFS_FWSTATS_FILE(event, oom_late, 20, "%u");
201DEBUGFS_FWSTATS_FILE(event, phy_transmit_error, 20, "%u");
202DEBUGFS_FWSTATS_FILE(event, tx_stuck, 20, "%u");
203
204DEBUGFS_FWSTATS_FILE(ps, pspoll_timeouts, 20, "%u");
205DEBUGFS_FWSTATS_FILE(ps, upsd_timeouts, 20, "%u");
206DEBUGFS_FWSTATS_FILE(ps, upsd_max_sptime, 20, "%u");
207DEBUGFS_FWSTATS_FILE(ps, upsd_max_apturn, 20, "%u");
208DEBUGFS_FWSTATS_FILE(ps, pspoll_max_apturn, 20, "%u");
209DEBUGFS_FWSTATS_FILE(ps, pspoll_utilization, 20, "%u");
210DEBUGFS_FWSTATS_FILE(ps, upsd_utilization, 20, "%u");
211
212DEBUGFS_FWSTATS_FILE(rxpipe, rx_prep_beacon_drop, 20, "%u");
213DEBUGFS_FWSTATS_FILE(rxpipe, descr_host_int_trig_rx_data, 20, "%u");
214DEBUGFS_FWSTATS_FILE(rxpipe, beacon_buffer_thres_host_int_trig_rx_data,
215 20, "%u");
216DEBUGFS_FWSTATS_FILE(rxpipe, missed_beacon_host_int_trig_rx_data, 20, "%u");
217DEBUGFS_FWSTATS_FILE(rxpipe, tx_xfr_host_int_trig_rx_data, 20, "%u");
218
219DEBUGFS_READONLY_FILE(retry_count, 20, "%u", wl->stats.retry_count);
220DEBUGFS_READONLY_FILE(excessive_retries, 20, "%u",
221 wl->stats.excessive_retries);
222
223static ssize_t tx_queue_len_read(struct file *file, char __user *userbuf,
224 size_t count, loff_t *ppos)
225{
226 struct wl1271 *wl = file->private_data;
227 u32 queue_len;
228 char buf[20];
229 int res;
230
231 queue_len = skb_queue_len(&wl->tx_queue);
232
233 res = scnprintf(buf, sizeof(buf), "%u\n", queue_len);
234 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
235}
236
237static const struct file_operations tx_queue_len_ops = {
238 .read = tx_queue_len_read,
239 .open = wl1271_open_file_generic,
240};
241
242static ssize_t gpio_power_read(struct file *file, char __user *user_buf,
243 size_t count, loff_t *ppos)
244{
245 struct wl1271 *wl = file->private_data;
246 bool state = test_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
247
248 int res;
249 char buf[10];
250
251 res = scnprintf(buf, sizeof(buf), "%d\n", state);
252
253 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
254}
255
256static ssize_t gpio_power_write(struct file *file,
257 const char __user *user_buf,
258 size_t count, loff_t *ppos)
259{
260 struct wl1271 *wl = file->private_data;
261 char buf[10];
262 size_t len;
263 unsigned long value;
264 int ret;
265
266 mutex_lock(&wl->mutex);
267
268 len = min(count, sizeof(buf) - 1);
269 if (copy_from_user(buf, user_buf, len)) {
270 ret = -EFAULT;
271 goto out;
272 }
273 buf[len] = '\0';
274
275 ret = strict_strtoul(buf, 0, &value);
276 if (ret < 0) {
277 wl1271_warning("illegal value in gpio_power");
278 goto out;
279 }
280
281 if (value)
282 wl1271_power_on(wl);
283 else
284 wl1271_power_off(wl);
285
286out:
287 mutex_unlock(&wl->mutex);
288 return count;
289}
290
291static const struct file_operations gpio_power_ops = {
292 .read = gpio_power_read,
293 .write = gpio_power_write,
294 .open = wl1271_open_file_generic
295};
296
297static void wl1271_debugfs_delete_files(struct wl1271 *wl)
298{
299 DEBUGFS_FWSTATS_DEL(tx, internal_desc_overflow);
300
301 DEBUGFS_FWSTATS_DEL(rx, out_of_mem);
302 DEBUGFS_FWSTATS_DEL(rx, hdr_overflow);
303 DEBUGFS_FWSTATS_DEL(rx, hw_stuck);
304 DEBUGFS_FWSTATS_DEL(rx, dropped);
305 DEBUGFS_FWSTATS_DEL(rx, fcs_err);
306 DEBUGFS_FWSTATS_DEL(rx, xfr_hint_trig);
307 DEBUGFS_FWSTATS_DEL(rx, path_reset);
308 DEBUGFS_FWSTATS_DEL(rx, reset_counter);
309
310 DEBUGFS_FWSTATS_DEL(dma, rx_requested);
311 DEBUGFS_FWSTATS_DEL(dma, rx_errors);
312 DEBUGFS_FWSTATS_DEL(dma, tx_requested);
313 DEBUGFS_FWSTATS_DEL(dma, tx_errors);
314
315 DEBUGFS_FWSTATS_DEL(isr, cmd_cmplt);
316 DEBUGFS_FWSTATS_DEL(isr, fiqs);
317 DEBUGFS_FWSTATS_DEL(isr, rx_headers);
318 DEBUGFS_FWSTATS_DEL(isr, rx_mem_overflow);
319 DEBUGFS_FWSTATS_DEL(isr, rx_rdys);
320 DEBUGFS_FWSTATS_DEL(isr, irqs);
321 DEBUGFS_FWSTATS_DEL(isr, tx_procs);
322 DEBUGFS_FWSTATS_DEL(isr, decrypt_done);
323 DEBUGFS_FWSTATS_DEL(isr, dma0_done);
324 DEBUGFS_FWSTATS_DEL(isr, dma1_done);
325 DEBUGFS_FWSTATS_DEL(isr, tx_exch_complete);
326 DEBUGFS_FWSTATS_DEL(isr, commands);
327 DEBUGFS_FWSTATS_DEL(isr, rx_procs);
328 DEBUGFS_FWSTATS_DEL(isr, hw_pm_mode_changes);
329 DEBUGFS_FWSTATS_DEL(isr, host_acknowledges);
330 DEBUGFS_FWSTATS_DEL(isr, pci_pm);
331 DEBUGFS_FWSTATS_DEL(isr, wakeups);
332 DEBUGFS_FWSTATS_DEL(isr, low_rssi);
333
334 DEBUGFS_FWSTATS_DEL(wep, addr_key_count);
335 DEBUGFS_FWSTATS_DEL(wep, default_key_count);
336 /* skipping wep.reserved */
337 DEBUGFS_FWSTATS_DEL(wep, key_not_found);
338 DEBUGFS_FWSTATS_DEL(wep, decrypt_fail);
339 DEBUGFS_FWSTATS_DEL(wep, packets);
340 DEBUGFS_FWSTATS_DEL(wep, interrupt);
341
342 DEBUGFS_FWSTATS_DEL(pwr, ps_enter);
343 DEBUGFS_FWSTATS_DEL(pwr, elp_enter);
344 DEBUGFS_FWSTATS_DEL(pwr, missing_bcns);
345 DEBUGFS_FWSTATS_DEL(pwr, wake_on_host);
346 DEBUGFS_FWSTATS_DEL(pwr, wake_on_timer_exp);
347 DEBUGFS_FWSTATS_DEL(pwr, tx_with_ps);
348 DEBUGFS_FWSTATS_DEL(pwr, tx_without_ps);
349 DEBUGFS_FWSTATS_DEL(pwr, rcvd_beacons);
350 DEBUGFS_FWSTATS_DEL(pwr, power_save_off);
351 DEBUGFS_FWSTATS_DEL(pwr, enable_ps);
352 DEBUGFS_FWSTATS_DEL(pwr, disable_ps);
353 DEBUGFS_FWSTATS_DEL(pwr, fix_tsf_ps);
354 /* skipping cont_miss_bcns_spread for now */
355 DEBUGFS_FWSTATS_DEL(pwr, rcvd_awake_beacons);
356
357 DEBUGFS_FWSTATS_DEL(mic, rx_pkts);
358 DEBUGFS_FWSTATS_DEL(mic, calc_failure);
359
360 DEBUGFS_FWSTATS_DEL(aes, encrypt_fail);
361 DEBUGFS_FWSTATS_DEL(aes, decrypt_fail);
362 DEBUGFS_FWSTATS_DEL(aes, encrypt_packets);
363 DEBUGFS_FWSTATS_DEL(aes, decrypt_packets);
364 DEBUGFS_FWSTATS_DEL(aes, encrypt_interrupt);
365 DEBUGFS_FWSTATS_DEL(aes, decrypt_interrupt);
366
367 DEBUGFS_FWSTATS_DEL(event, heart_beat);
368 DEBUGFS_FWSTATS_DEL(event, calibration);
369 DEBUGFS_FWSTATS_DEL(event, rx_mismatch);
370 DEBUGFS_FWSTATS_DEL(event, rx_mem_empty);
371 DEBUGFS_FWSTATS_DEL(event, rx_pool);
372 DEBUGFS_FWSTATS_DEL(event, oom_late);
373 DEBUGFS_FWSTATS_DEL(event, phy_transmit_error);
374 DEBUGFS_FWSTATS_DEL(event, tx_stuck);
375
376 DEBUGFS_FWSTATS_DEL(ps, pspoll_timeouts);
377 DEBUGFS_FWSTATS_DEL(ps, upsd_timeouts);
378 DEBUGFS_FWSTATS_DEL(ps, upsd_max_sptime);
379 DEBUGFS_FWSTATS_DEL(ps, upsd_max_apturn);
380 DEBUGFS_FWSTATS_DEL(ps, pspoll_max_apturn);
381 DEBUGFS_FWSTATS_DEL(ps, pspoll_utilization);
382 DEBUGFS_FWSTATS_DEL(ps, upsd_utilization);
383
384 DEBUGFS_FWSTATS_DEL(rxpipe, rx_prep_beacon_drop);
385 DEBUGFS_FWSTATS_DEL(rxpipe, descr_host_int_trig_rx_data);
386 DEBUGFS_FWSTATS_DEL(rxpipe, beacon_buffer_thres_host_int_trig_rx_data);
387 DEBUGFS_FWSTATS_DEL(rxpipe, missed_beacon_host_int_trig_rx_data);
388 DEBUGFS_FWSTATS_DEL(rxpipe, tx_xfr_host_int_trig_rx_data);
389
390 DEBUGFS_DEL(tx_queue_len);
391 DEBUGFS_DEL(retry_count);
392 DEBUGFS_DEL(excessive_retries);
393
394 DEBUGFS_DEL(gpio_power);
395}
396
397static int wl1271_debugfs_add_files(struct wl1271 *wl)
398{
399 int ret = 0;
400
401 DEBUGFS_FWSTATS_ADD(tx, internal_desc_overflow);
402
403 DEBUGFS_FWSTATS_ADD(rx, out_of_mem);
404 DEBUGFS_FWSTATS_ADD(rx, hdr_overflow);
405 DEBUGFS_FWSTATS_ADD(rx, hw_stuck);
406 DEBUGFS_FWSTATS_ADD(rx, dropped);
407 DEBUGFS_FWSTATS_ADD(rx, fcs_err);
408 DEBUGFS_FWSTATS_ADD(rx, xfr_hint_trig);
409 DEBUGFS_FWSTATS_ADD(rx, path_reset);
410 DEBUGFS_FWSTATS_ADD(rx, reset_counter);
411
412 DEBUGFS_FWSTATS_ADD(dma, rx_requested);
413 DEBUGFS_FWSTATS_ADD(dma, rx_errors);
414 DEBUGFS_FWSTATS_ADD(dma, tx_requested);
415 DEBUGFS_FWSTATS_ADD(dma, tx_errors);
416
417 DEBUGFS_FWSTATS_ADD(isr, cmd_cmplt);
418 DEBUGFS_FWSTATS_ADD(isr, fiqs);
419 DEBUGFS_FWSTATS_ADD(isr, rx_headers);
420 DEBUGFS_FWSTATS_ADD(isr, rx_mem_overflow);
421 DEBUGFS_FWSTATS_ADD(isr, rx_rdys);
422 DEBUGFS_FWSTATS_ADD(isr, irqs);
423 DEBUGFS_FWSTATS_ADD(isr, tx_procs);
424 DEBUGFS_FWSTATS_ADD(isr, decrypt_done);
425 DEBUGFS_FWSTATS_ADD(isr, dma0_done);
426 DEBUGFS_FWSTATS_ADD(isr, dma1_done);
427 DEBUGFS_FWSTATS_ADD(isr, tx_exch_complete);
428 DEBUGFS_FWSTATS_ADD(isr, commands);
429 DEBUGFS_FWSTATS_ADD(isr, rx_procs);
430 DEBUGFS_FWSTATS_ADD(isr, hw_pm_mode_changes);
431 DEBUGFS_FWSTATS_ADD(isr, host_acknowledges);
432 DEBUGFS_FWSTATS_ADD(isr, pci_pm);
433 DEBUGFS_FWSTATS_ADD(isr, wakeups);
434 DEBUGFS_FWSTATS_ADD(isr, low_rssi);
435
436 DEBUGFS_FWSTATS_ADD(wep, addr_key_count);
437 DEBUGFS_FWSTATS_ADD(wep, default_key_count);
438 /* skipping wep.reserved */
439 DEBUGFS_FWSTATS_ADD(wep, key_not_found);
440 DEBUGFS_FWSTATS_ADD(wep, decrypt_fail);
441 DEBUGFS_FWSTATS_ADD(wep, packets);
442 DEBUGFS_FWSTATS_ADD(wep, interrupt);
443
444 DEBUGFS_FWSTATS_ADD(pwr, ps_enter);
445 DEBUGFS_FWSTATS_ADD(pwr, elp_enter);
446 DEBUGFS_FWSTATS_ADD(pwr, missing_bcns);
447 DEBUGFS_FWSTATS_ADD(pwr, wake_on_host);
448 DEBUGFS_FWSTATS_ADD(pwr, wake_on_timer_exp);
449 DEBUGFS_FWSTATS_ADD(pwr, tx_with_ps);
450 DEBUGFS_FWSTATS_ADD(pwr, tx_without_ps);
451 DEBUGFS_FWSTATS_ADD(pwr, rcvd_beacons);
452 DEBUGFS_FWSTATS_ADD(pwr, power_save_off);
453 DEBUGFS_FWSTATS_ADD(pwr, enable_ps);
454 DEBUGFS_FWSTATS_ADD(pwr, disable_ps);
455 DEBUGFS_FWSTATS_ADD(pwr, fix_tsf_ps);
456 /* skipping cont_miss_bcns_spread for now */
457 DEBUGFS_FWSTATS_ADD(pwr, rcvd_awake_beacons);
458
459 DEBUGFS_FWSTATS_ADD(mic, rx_pkts);
460 DEBUGFS_FWSTATS_ADD(mic, calc_failure);
461
462 DEBUGFS_FWSTATS_ADD(aes, encrypt_fail);
463 DEBUGFS_FWSTATS_ADD(aes, decrypt_fail);
464 DEBUGFS_FWSTATS_ADD(aes, encrypt_packets);
465 DEBUGFS_FWSTATS_ADD(aes, decrypt_packets);
466 DEBUGFS_FWSTATS_ADD(aes, encrypt_interrupt);
467 DEBUGFS_FWSTATS_ADD(aes, decrypt_interrupt);
468
469 DEBUGFS_FWSTATS_ADD(event, heart_beat);
470 DEBUGFS_FWSTATS_ADD(event, calibration);
471 DEBUGFS_FWSTATS_ADD(event, rx_mismatch);
472 DEBUGFS_FWSTATS_ADD(event, rx_mem_empty);
473 DEBUGFS_FWSTATS_ADD(event, rx_pool);
474 DEBUGFS_FWSTATS_ADD(event, oom_late);
475 DEBUGFS_FWSTATS_ADD(event, phy_transmit_error);
476 DEBUGFS_FWSTATS_ADD(event, tx_stuck);
477
478 DEBUGFS_FWSTATS_ADD(ps, pspoll_timeouts);
479 DEBUGFS_FWSTATS_ADD(ps, upsd_timeouts);
480 DEBUGFS_FWSTATS_ADD(ps, upsd_max_sptime);
481 DEBUGFS_FWSTATS_ADD(ps, upsd_max_apturn);
482 DEBUGFS_FWSTATS_ADD(ps, pspoll_max_apturn);
483 DEBUGFS_FWSTATS_ADD(ps, pspoll_utilization);
484 DEBUGFS_FWSTATS_ADD(ps, upsd_utilization);
485
486 DEBUGFS_FWSTATS_ADD(rxpipe, rx_prep_beacon_drop);
487 DEBUGFS_FWSTATS_ADD(rxpipe, descr_host_int_trig_rx_data);
488 DEBUGFS_FWSTATS_ADD(rxpipe, beacon_buffer_thres_host_int_trig_rx_data);
489 DEBUGFS_FWSTATS_ADD(rxpipe, missed_beacon_host_int_trig_rx_data);
490 DEBUGFS_FWSTATS_ADD(rxpipe, tx_xfr_host_int_trig_rx_data);
491
492 DEBUGFS_ADD(tx_queue_len, wl->debugfs.rootdir);
493 DEBUGFS_ADD(retry_count, wl->debugfs.rootdir);
494 DEBUGFS_ADD(excessive_retries, wl->debugfs.rootdir);
495
496 DEBUGFS_ADD(gpio_power, wl->debugfs.rootdir);
497
498out:
499 if (ret < 0)
500 wl1271_debugfs_delete_files(wl);
501
502 return ret;
503}
504
505void wl1271_debugfs_reset(struct wl1271 *wl)
506{
507 memset(wl->stats.fw_stats, 0, sizeof(*wl->stats.fw_stats));
508 wl->stats.retry_count = 0;
509 wl->stats.excessive_retries = 0;
510}
511
512int wl1271_debugfs_init(struct wl1271 *wl)
513{
514 int ret;
515
516 wl->debugfs.rootdir = debugfs_create_dir(KBUILD_MODNAME, NULL);
517
518 if (IS_ERR(wl->debugfs.rootdir)) {
519 ret = PTR_ERR(wl->debugfs.rootdir);
520 wl->debugfs.rootdir = NULL;
521 goto err;
522 }
523
524 wl->debugfs.fw_statistics = debugfs_create_dir("fw-statistics",
525 wl->debugfs.rootdir);
526
527 if (IS_ERR(wl->debugfs.fw_statistics)) {
528 ret = PTR_ERR(wl->debugfs.fw_statistics);
529 wl->debugfs.fw_statistics = NULL;
530 goto err_root;
531 }
532
533 wl->stats.fw_stats = kzalloc(sizeof(*wl->stats.fw_stats),
534 GFP_KERNEL);
535
536 if (!wl->stats.fw_stats) {
537 ret = -ENOMEM;
538 goto err_fw;
539 }
540
541 wl->stats.fw_stats_update = jiffies;
542
543 ret = wl1271_debugfs_add_files(wl);
544
545 if (ret < 0)
546 goto err_file;
547
548 return 0;
549
550err_file:
551 kfree(wl->stats.fw_stats);
552 wl->stats.fw_stats = NULL;
553
554err_fw:
555 debugfs_remove(wl->debugfs.fw_statistics);
556 wl->debugfs.fw_statistics = NULL;
557
558err_root:
559 debugfs_remove(wl->debugfs.rootdir);
560 wl->debugfs.rootdir = NULL;
561
562err:
563 return ret;
564}
565
566void wl1271_debugfs_exit(struct wl1271 *wl)
567{
568 wl1271_debugfs_delete_files(wl);
569
570 kfree(wl->stats.fw_stats);
571 wl->stats.fw_stats = NULL;
572
573 debugfs_remove(wl->debugfs.fw_statistics);
574 wl->debugfs.fw_statistics = NULL;
575
576 debugfs_remove(wl->debugfs.rootdir);
577 wl->debugfs.rootdir = NULL;
578
579}
diff --git a/drivers/net/wireless/wl12xx/wl1271_init.c b/drivers/net/wireless/wl12xx/wl1271_init.c
deleted file mode 100644
index 4447af1557f5..000000000000
--- a/drivers/net/wireless/wl12xx/wl1271_init.c
+++ /dev/null
@@ -1,368 +0,0 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 *
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include <linux/kernel.h>
25#include <linux/module.h>
26#include <linux/slab.h>
27
28#include "wl1271_init.h"
29#include "wl12xx_80211.h"
30#include "wl1271_acx.h"
31#include "wl1271_cmd.h"
32#include "wl1271_reg.h"
33
34static int wl1271_init_hwenc_config(struct wl1271 *wl)
35{
36 int ret;
37
38 ret = wl1271_acx_feature_cfg(wl);
39 if (ret < 0) {
40 wl1271_warning("couldn't set feature config");
41 return ret;
42 }
43
44 ret = wl1271_cmd_set_default_wep_key(wl, wl->default_key);
45 if (ret < 0) {
46 wl1271_warning("couldn't set default key");
47 return ret;
48 }
49
50 return 0;
51}
52
53int wl1271_init_templates_config(struct wl1271 *wl)
54{
55 int ret, i;
56
57 /* send empty templates for fw memory reservation */
58 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, NULL,
59 sizeof(struct wl12xx_probe_req_template),
60 0, WL1271_RATE_AUTOMATIC);
61 if (ret < 0)
62 return ret;
63
64 if (wl1271_11a_enabled()) {
65 size_t size = sizeof(struct wl12xx_probe_req_template);
66 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
67 NULL, size, 0,
68 WL1271_RATE_AUTOMATIC);
69 if (ret < 0)
70 return ret;
71 }
72
73 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
74 sizeof(struct wl12xx_null_data_template),
75 0, WL1271_RATE_AUTOMATIC);
76 if (ret < 0)
77 return ret;
78
79 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, NULL,
80 sizeof(struct wl12xx_ps_poll_template),
81 0, WL1271_RATE_AUTOMATIC);
82 if (ret < 0)
83 return ret;
84
85 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
86 sizeof
87 (struct wl12xx_qos_null_data_template),
88 0, WL1271_RATE_AUTOMATIC);
89 if (ret < 0)
90 return ret;
91
92 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE, NULL,
93 sizeof
94 (struct wl12xx_probe_resp_template),
95 0, WL1271_RATE_AUTOMATIC);
96 if (ret < 0)
97 return ret;
98
99 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON, NULL,
100 sizeof
101 (struct wl12xx_beacon_template),
102 0, WL1271_RATE_AUTOMATIC);
103 if (ret < 0)
104 return ret;
105
106 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
107 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV, NULL,
108 WL1271_CMD_TEMPL_MAX_SIZE, i,
109 WL1271_RATE_AUTOMATIC);
110 if (ret < 0)
111 return ret;
112 }
113
114 return 0;
115}
116
117static int wl1271_init_rx_config(struct wl1271 *wl, u32 config, u32 filter)
118{
119 int ret;
120
121 ret = wl1271_acx_rx_msdu_life_time(wl);
122 if (ret < 0)
123 return ret;
124
125 ret = wl1271_acx_rx_config(wl, config, filter);
126 if (ret < 0)
127 return ret;
128
129 return 0;
130}
131
132int wl1271_init_phy_config(struct wl1271 *wl)
133{
134 int ret;
135
136 ret = wl1271_acx_pd_threshold(wl);
137 if (ret < 0)
138 return ret;
139
140 ret = wl1271_acx_slot(wl, DEFAULT_SLOT_TIME);
141 if (ret < 0)
142 return ret;
143
144 ret = wl1271_acx_group_address_tbl(wl, true, NULL, 0);
145 if (ret < 0)
146 return ret;
147
148 ret = wl1271_acx_service_period_timeout(wl);
149 if (ret < 0)
150 return ret;
151
152 ret = wl1271_acx_rts_threshold(wl, wl->conf.rx.rts_threshold);
153 if (ret < 0)
154 return ret;
155
156 return 0;
157}
158
159static int wl1271_init_beacon_filter(struct wl1271 *wl)
160{
161 int ret;
162
163 /* disable beacon filtering at this stage */
164 ret = wl1271_acx_beacon_filter_opt(wl, false);
165 if (ret < 0)
166 return ret;
167
168 ret = wl1271_acx_beacon_filter_table(wl);
169 if (ret < 0)
170 return ret;
171
172 return 0;
173}
174
175int wl1271_init_pta(struct wl1271 *wl)
176{
177 int ret;
178
179 ret = wl1271_acx_sg_cfg(wl);
180 if (ret < 0)
181 return ret;
182
183 ret = wl1271_acx_sg_enable(wl, wl->sg_enabled);
184 if (ret < 0)
185 return ret;
186
187 return 0;
188}
189
190int wl1271_init_energy_detection(struct wl1271 *wl)
191{
192 int ret;
193
194 ret = wl1271_acx_cca_threshold(wl);
195 if (ret < 0)
196 return ret;
197
198 return 0;
199}
200
201static int wl1271_init_beacon_broadcast(struct wl1271 *wl)
202{
203 int ret;
204
205 ret = wl1271_acx_bcn_dtim_options(wl);
206 if (ret < 0)
207 return ret;
208
209 return 0;
210}
211
212int wl1271_hw_init(struct wl1271 *wl)
213{
214 struct conf_tx_ac_category *conf_ac;
215 struct conf_tx_tid *conf_tid;
216 int ret, i;
217
218 ret = wl1271_cmd_general_parms(wl);
219 if (ret < 0)
220 return ret;
221
222 ret = wl1271_cmd_radio_parms(wl);
223 if (ret < 0)
224 return ret;
225
226 /* Template settings */
227 ret = wl1271_init_templates_config(wl);
228 if (ret < 0)
229 return ret;
230
231 /* Default memory configuration */
232 ret = wl1271_acx_init_mem_config(wl);
233 if (ret < 0)
234 return ret;
235
236 /* RX config */
237 ret = wl1271_init_rx_config(wl,
238 RX_CFG_PROMISCUOUS | RX_CFG_TSF,
239 RX_FILTER_OPTION_DEF);
240 /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
241 RX_FILTER_OPTION_FILTER_ALL); */
242 if (ret < 0)
243 goto out_free_memmap;
244
245 /* PHY layer config */
246 ret = wl1271_init_phy_config(wl);
247 if (ret < 0)
248 goto out_free_memmap;
249
250 ret = wl1271_acx_dco_itrim_params(wl);
251 if (ret < 0)
252 goto out_free_memmap;
253
254 /* Initialize connection monitoring thresholds */
255 ret = wl1271_acx_conn_monit_params(wl, false);
256 if (ret < 0)
257 goto out_free_memmap;
258
259 /* Beacon filtering */
260 ret = wl1271_init_beacon_filter(wl);
261 if (ret < 0)
262 goto out_free_memmap;
263
264 /* Configure TX patch complete interrupt behavior */
265 ret = wl1271_acx_tx_config_options(wl);
266 if (ret < 0)
267 goto out_free_memmap;
268
269 /* RX complete interrupt pacing */
270 ret = wl1271_acx_init_rx_interrupt(wl);
271 if (ret < 0)
272 goto out_free_memmap;
273
274 /* Bluetooth WLAN coexistence */
275 ret = wl1271_init_pta(wl);
276 if (ret < 0)
277 goto out_free_memmap;
278
279 /* Energy detection */
280 ret = wl1271_init_energy_detection(wl);
281 if (ret < 0)
282 goto out_free_memmap;
283
284 /* Beacons and boradcast settings */
285 ret = wl1271_init_beacon_broadcast(wl);
286 if (ret < 0)
287 goto out_free_memmap;
288
289 /* Default fragmentation threshold */
290 ret = wl1271_acx_frag_threshold(wl);
291 if (ret < 0)
292 goto out_free_memmap;
293
294 /* Default TID configuration */
295 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
296 conf_tid = &wl->conf.tx.tid_conf[i];
297 ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id,
298 conf_tid->channel_type,
299 conf_tid->tsid,
300 conf_tid->ps_scheme,
301 conf_tid->ack_policy,
302 conf_tid->apsd_conf[0],
303 conf_tid->apsd_conf[1]);
304 if (ret < 0)
305 goto out_free_memmap;
306 }
307
308 /* Default AC configuration */
309 for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
310 conf_ac = &wl->conf.tx.ac_conf[i];
311 ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
312 conf_ac->cw_max, conf_ac->aifsn,
313 conf_ac->tx_op_limit);
314 if (ret < 0)
315 goto out_free_memmap;
316 }
317
318 /* Configure TX rate classes */
319 ret = wl1271_acx_rate_policies(wl);
320 if (ret < 0)
321 goto out_free_memmap;
322
323 /* Enable data path */
324 ret = wl1271_cmd_data_path(wl, 1);
325 if (ret < 0)
326 goto out_free_memmap;
327
328 /* Configure for ELP power saving */
329 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
330 if (ret < 0)
331 goto out_free_memmap;
332
333 /* Configure HW encryption */
334 ret = wl1271_init_hwenc_config(wl);
335 if (ret < 0)
336 goto out_free_memmap;
337
338 /* configure PM */
339 ret = wl1271_acx_pm_config(wl);
340 if (ret < 0)
341 goto out_free_memmap;
342
343 /* disable all keep-alive templates */
344 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
345 ret = wl1271_acx_keep_alive_config(wl, i,
346 ACX_KEEP_ALIVE_TPL_INVALID);
347 if (ret < 0)
348 goto out_free_memmap;
349 }
350
351 /* disable the keep-alive feature */
352 ret = wl1271_acx_keep_alive_mode(wl, false);
353 if (ret < 0)
354 goto out_free_memmap;
355
356 /* Configure rssi/snr averaging weights */
357 ret = wl1271_acx_rssi_snr_avg_weights(wl);
358 if (ret < 0)
359 goto out_free_memmap;
360
361 return 0;
362
363 out_free_memmap:
364 kfree(wl->target_mem_map);
365 wl->target_mem_map = NULL;
366
367 return ret;
368}
diff --git a/drivers/net/wireless/wl12xx/wl1271_main.c b/drivers/net/wireless/wl12xx/wl1271_main.c
deleted file mode 100644
index 9d68f0012f05..000000000000
--- a/drivers/net/wireless/wl12xx/wl1271_main.c
+++ /dev/null
@@ -1,2491 +0,0 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2008-2010 Nokia Corporation
5 *
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include <linux/module.h>
25#include <linux/firmware.h>
26#include <linux/delay.h>
27#include <linux/spi/spi.h>
28#include <linux/crc32.h>
29#include <linux/etherdevice.h>
30#include <linux/vmalloc.h>
31#include <linux/platform_device.h>
32#include <linux/slab.h>
33
34#include "wl1271.h"
35#include "wl12xx_80211.h"
36#include "wl1271_reg.h"
37#include "wl1271_io.h"
38#include "wl1271_event.h"
39#include "wl1271_tx.h"
40#include "wl1271_rx.h"
41#include "wl1271_ps.h"
42#include "wl1271_init.h"
43#include "wl1271_debugfs.h"
44#include "wl1271_cmd.h"
45#include "wl1271_boot.h"
46#include "wl1271_testmode.h"
47#include "wl1271_scan.h"
48
49#define WL1271_BOOT_RETRIES 3
50
51static struct conf_drv_settings default_conf = {
52 .sg = {
53 .params = {
54 [CONF_SG_BT_PER_THRESHOLD] = 7500,
55 [CONF_SG_HV3_MAX_OVERRIDE] = 0,
56 [CONF_SG_BT_NFS_SAMPLE_INTERVAL] = 400,
57 [CONF_SG_BT_LOAD_RATIO] = 50,
58 [CONF_SG_AUTO_PS_MODE] = 1,
59 [CONF_SG_AUTO_SCAN_PROBE_REQ] = 170,
60 [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_HV3] = 50,
61 [CONF_SG_ANTENNA_CONFIGURATION] = 0,
62 [CONF_SG_BEACON_MISS_PERCENT] = 60,
63 [CONF_SG_RATE_ADAPT_THRESH] = 12,
64 [CONF_SG_RATE_ADAPT_SNR] = 0,
65 [CONF_SG_WLAN_PS_BT_ACL_MASTER_MIN_BR] = 10,
66 [CONF_SG_WLAN_PS_BT_ACL_MASTER_MAX_BR] = 30,
67 [CONF_SG_WLAN_PS_MAX_BT_ACL_MASTER_BR] = 8,
68 [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MIN_BR] = 20,
69 [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MAX_BR] = 50,
70 /* Note: with UPSD, this should be 4 */
71 [CONF_SG_WLAN_PS_MAX_BT_ACL_SLAVE_BR] = 8,
72 [CONF_SG_WLAN_PS_BT_ACL_MASTER_MIN_EDR] = 7,
73 [CONF_SG_WLAN_PS_BT_ACL_MASTER_MAX_EDR] = 25,
74 [CONF_SG_WLAN_PS_MAX_BT_ACL_MASTER_EDR] = 20,
75 /* Note: with UPDS, this should be 15 */
76 [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MIN_EDR] = 8,
77 /* Note: with UPDS, this should be 50 */
78 [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MAX_EDR] = 40,
79 /* Note: with UPDS, this should be 10 */
80 [CONF_SG_WLAN_PS_MAX_BT_ACL_SLAVE_EDR] = 20,
81 [CONF_SG_RXT] = 1200,
82 [CONF_SG_TXT] = 1000,
83 [CONF_SG_ADAPTIVE_RXT_TXT] = 1,
84 [CONF_SG_PS_POLL_TIMEOUT] = 10,
85 [CONF_SG_UPSD_TIMEOUT] = 10,
86 [CONF_SG_WLAN_ACTIVE_BT_ACL_MASTER_MIN_EDR] = 7,
87 [CONF_SG_WLAN_ACTIVE_BT_ACL_MASTER_MAX_EDR] = 15,
88 [CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_MASTER_EDR] = 15,
89 [CONF_SG_WLAN_ACTIVE_BT_ACL_SLAVE_MIN_EDR] = 8,
90 [CONF_SG_WLAN_ACTIVE_BT_ACL_SLAVE_MAX_EDR] = 20,
91 [CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_SLAVE_EDR] = 15,
92 [CONF_SG_WLAN_ACTIVE_BT_ACL_MIN_BR] = 20,
93 [CONF_SG_WLAN_ACTIVE_BT_ACL_MAX_BR] = 50,
94 [CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_BR] = 10,
95 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_HV3] = 200,
96 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP] = 800,
97 [CONF_SG_PASSIVE_SCAN_A2DP_BT_TIME] = 75,
98 [CONF_SG_PASSIVE_SCAN_A2DP_WLAN_TIME] = 15,
99 [CONF_SG_HV3_MAX_SERVED] = 6,
100 [CONF_SG_DHCP_TIME] = 5000,
101 [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_A2DP] = 100,
102 },
103 .state = CONF_SG_PROTECTIVE,
104 },
105 .rx = {
106 .rx_msdu_life_time = 512000,
107 .packet_detection_threshold = 0,
108 .ps_poll_timeout = 15,
109 .upsd_timeout = 15,
110 .rts_threshold = 2347,
111 .rx_cca_threshold = 0,
112 .irq_blk_threshold = 0xFFFF,
113 .irq_pkt_threshold = 0,
114 .irq_timeout = 600,
115 .queue_type = CONF_RX_QUEUE_TYPE_LOW_PRIORITY,
116 },
117 .tx = {
118 .tx_energy_detection = 0,
119 .rc_conf = {
120 .enabled_rates = 0,
121 .short_retry_limit = 10,
122 .long_retry_limit = 10,
123 .aflags = 0
124 },
125 .ac_conf_count = 4,
126 .ac_conf = {
127 [0] = {
128 .ac = CONF_TX_AC_BE,
129 .cw_min = 15,
130 .cw_max = 63,
131 .aifsn = 3,
132 .tx_op_limit = 0,
133 },
134 [1] = {
135 .ac = CONF_TX_AC_BK,
136 .cw_min = 15,
137 .cw_max = 63,
138 .aifsn = 7,
139 .tx_op_limit = 0,
140 },
141 [2] = {
142 .ac = CONF_TX_AC_VI,
143 .cw_min = 15,
144 .cw_max = 63,
145 .aifsn = CONF_TX_AIFS_PIFS,
146 .tx_op_limit = 3008,
147 },
148 [3] = {
149 .ac = CONF_TX_AC_VO,
150 .cw_min = 15,
151 .cw_max = 63,
152 .aifsn = CONF_TX_AIFS_PIFS,
153 .tx_op_limit = 1504,
154 },
155 },
156 .tid_conf_count = 7,
157 .tid_conf = {
158 [0] = {
159 .queue_id = 0,
160 .channel_type = CONF_CHANNEL_TYPE_DCF,
161 .tsid = CONF_TX_AC_BE,
162 .ps_scheme = CONF_PS_SCHEME_LEGACY,
163 .ack_policy = CONF_ACK_POLICY_LEGACY,
164 .apsd_conf = {0, 0},
165 },
166 [1] = {
167 .queue_id = 1,
168 .channel_type = CONF_CHANNEL_TYPE_DCF,
169 .tsid = CONF_TX_AC_BE,
170 .ps_scheme = CONF_PS_SCHEME_LEGACY,
171 .ack_policy = CONF_ACK_POLICY_LEGACY,
172 .apsd_conf = {0, 0},
173 },
174 [2] = {
175 .queue_id = 2,
176 .channel_type = CONF_CHANNEL_TYPE_DCF,
177 .tsid = CONF_TX_AC_BE,
178 .ps_scheme = CONF_PS_SCHEME_LEGACY,
179 .ack_policy = CONF_ACK_POLICY_LEGACY,
180 .apsd_conf = {0, 0},
181 },
182 [3] = {
183 .queue_id = 3,
184 .channel_type = CONF_CHANNEL_TYPE_DCF,
185 .tsid = CONF_TX_AC_BE,
186 .ps_scheme = CONF_PS_SCHEME_LEGACY,
187 .ack_policy = CONF_ACK_POLICY_LEGACY,
188 .apsd_conf = {0, 0},
189 },
190 [4] = {
191 .queue_id = 4,
192 .channel_type = CONF_CHANNEL_TYPE_DCF,
193 .tsid = CONF_TX_AC_BE,
194 .ps_scheme = CONF_PS_SCHEME_LEGACY,
195 .ack_policy = CONF_ACK_POLICY_LEGACY,
196 .apsd_conf = {0, 0},
197 },
198 [5] = {
199 .queue_id = 5,
200 .channel_type = CONF_CHANNEL_TYPE_DCF,
201 .tsid = CONF_TX_AC_BE,
202 .ps_scheme = CONF_PS_SCHEME_LEGACY,
203 .ack_policy = CONF_ACK_POLICY_LEGACY,
204 .apsd_conf = {0, 0},
205 },
206 [6] = {
207 .queue_id = 6,
208 .channel_type = CONF_CHANNEL_TYPE_DCF,
209 .tsid = CONF_TX_AC_BE,
210 .ps_scheme = CONF_PS_SCHEME_LEGACY,
211 .ack_policy = CONF_ACK_POLICY_LEGACY,
212 .apsd_conf = {0, 0},
213 }
214 },
215 .frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD,
216 .tx_compl_timeout = 700,
217 .tx_compl_threshold = 4,
218 .basic_rate = CONF_HW_BIT_RATE_1MBPS,
219 .basic_rate_5 = CONF_HW_BIT_RATE_6MBPS,
220 },
221 .conn = {
222 .wake_up_event = CONF_WAKE_UP_EVENT_DTIM,
223 .listen_interval = 1,
224 .bcn_filt_mode = CONF_BCN_FILT_MODE_ENABLED,
225 .bcn_filt_ie_count = 1,
226 .bcn_filt_ie = {
227 [0] = {
228 .ie = WLAN_EID_CHANNEL_SWITCH,
229 .rule = CONF_BCN_RULE_PASS_ON_APPEARANCE,
230 }
231 },
232 .synch_fail_thold = 10,
233 .bss_lose_timeout = 100,
234 .beacon_rx_timeout = 10000,
235 .broadcast_timeout = 20000,
236 .rx_broadcast_in_ps = 1,
237 .ps_poll_threshold = 10,
238 .ps_poll_recovery_period = 700,
239 .bet_enable = CONF_BET_MODE_ENABLE,
240 .bet_max_consecutive = 10,
241 .psm_entry_retries = 3,
242 .keep_alive_interval = 55000,
243 .max_listen_interval = 20,
244 },
245 .itrim = {
246 .enable = false,
247 .timeout = 50000,
248 },
249 .pm_config = {
250 .host_clk_settling_time = 5000,
251 .host_fast_wakeup_support = false
252 },
253 .roam_trigger = {
254 /* FIXME: due to firmware bug, must use value 1 for now */
255 .trigger_pacing = 1,
256 .avg_weight_rssi_beacon = 20,
257 .avg_weight_rssi_data = 10,
258 .avg_weight_snr_beacon = 20,
259 .avg_weight_snr_data = 10
260 }
261};
262
263static void wl1271_device_release(struct device *dev)
264{
265
266}
267
268static struct platform_device wl1271_device = {
269 .name = "wl1271",
270 .id = -1,
271
272 /* device model insists to have a release function */
273 .dev = {
274 .release = wl1271_device_release,
275 },
276};
277
278static LIST_HEAD(wl_list);
279
280static void wl1271_conf_init(struct wl1271 *wl)
281{
282
283 /*
284 * This function applies the default configuration to the driver. This
285 * function is invoked upon driver load (spi probe.)
286 *
287 * The configuration is stored in a run-time structure in order to
288 * facilitate for run-time adjustment of any of the parameters. Making
289 * changes to the configuration structure will apply the new values on
290 * the next interface up (wl1271_op_start.)
291 */
292
293 /* apply driver default configuration */
294 memcpy(&wl->conf, &default_conf, sizeof(default_conf));
295}
296
297
298static int wl1271_plt_init(struct wl1271 *wl)
299{
300 struct conf_tx_ac_category *conf_ac;
301 struct conf_tx_tid *conf_tid;
302 int ret, i;
303
304 ret = wl1271_cmd_general_parms(wl);
305 if (ret < 0)
306 return ret;
307
308 ret = wl1271_cmd_radio_parms(wl);
309 if (ret < 0)
310 return ret;
311
312 ret = wl1271_init_templates_config(wl);
313 if (ret < 0)
314 return ret;
315
316 ret = wl1271_acx_init_mem_config(wl);
317 if (ret < 0)
318 return ret;
319
320 /* PHY layer config */
321 ret = wl1271_init_phy_config(wl);
322 if (ret < 0)
323 goto out_free_memmap;
324
325 ret = wl1271_acx_dco_itrim_params(wl);
326 if (ret < 0)
327 goto out_free_memmap;
328
329 /* Initialize connection monitoring thresholds */
330 ret = wl1271_acx_conn_monit_params(wl, false);
331 if (ret < 0)
332 goto out_free_memmap;
333
334 /* Bluetooth WLAN coexistence */
335 ret = wl1271_init_pta(wl);
336 if (ret < 0)
337 goto out_free_memmap;
338
339 /* Energy detection */
340 ret = wl1271_init_energy_detection(wl);
341 if (ret < 0)
342 goto out_free_memmap;
343
344 /* Default fragmentation threshold */
345 ret = wl1271_acx_frag_threshold(wl);
346 if (ret < 0)
347 goto out_free_memmap;
348
349 /* Default TID configuration */
350 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
351 conf_tid = &wl->conf.tx.tid_conf[i];
352 ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id,
353 conf_tid->channel_type,
354 conf_tid->tsid,
355 conf_tid->ps_scheme,
356 conf_tid->ack_policy,
357 conf_tid->apsd_conf[0],
358 conf_tid->apsd_conf[1]);
359 if (ret < 0)
360 goto out_free_memmap;
361 }
362
363 /* Default AC configuration */
364 for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
365 conf_ac = &wl->conf.tx.ac_conf[i];
366 ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
367 conf_ac->cw_max, conf_ac->aifsn,
368 conf_ac->tx_op_limit);
369 if (ret < 0)
370 goto out_free_memmap;
371 }
372
373 /* Enable data path */
374 ret = wl1271_cmd_data_path(wl, 1);
375 if (ret < 0)
376 goto out_free_memmap;
377
378 /* Configure for CAM power saving (ie. always active) */
379 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
380 if (ret < 0)
381 goto out_free_memmap;
382
383 /* configure PM */
384 ret = wl1271_acx_pm_config(wl);
385 if (ret < 0)
386 goto out_free_memmap;
387
388 return 0;
389
390 out_free_memmap:
391 kfree(wl->target_mem_map);
392 wl->target_mem_map = NULL;
393
394 return ret;
395}
396
397static void wl1271_fw_status(struct wl1271 *wl,
398 struct wl1271_fw_status *status)
399{
400 struct timespec ts;
401 u32 total = 0;
402 int i;
403
404 wl1271_raw_read(wl, FW_STATUS_ADDR, status, sizeof(*status), false);
405
406 wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, "
407 "drv_rx_counter = %d, tx_results_counter = %d)",
408 status->intr,
409 status->fw_rx_counter,
410 status->drv_rx_counter,
411 status->tx_results_counter);
412
413 /* update number of available TX blocks */
414 for (i = 0; i < NUM_TX_QUEUES; i++) {
415 u32 cnt = le32_to_cpu(status->tx_released_blks[i]) -
416 wl->tx_blocks_freed[i];
417
418 wl->tx_blocks_freed[i] =
419 le32_to_cpu(status->tx_released_blks[i]);
420 wl->tx_blocks_available += cnt;
421 total += cnt;
422 }
423
424 /* if more blocks are available now, schedule some tx work */
425 if (total && !skb_queue_empty(&wl->tx_queue))
426 ieee80211_queue_work(wl->hw, &wl->tx_work);
427
428 /* update the host-chipset time offset */
429 getnstimeofday(&ts);
430 wl->time_offset = (timespec_to_ns(&ts) >> 10) -
431 (s64)le32_to_cpu(status->fw_localtime);
432}
433
434#define WL1271_IRQ_MAX_LOOPS 10
435
436static void wl1271_irq_work(struct work_struct *work)
437{
438 int ret;
439 u32 intr;
440 int loopcount = WL1271_IRQ_MAX_LOOPS;
441 unsigned long flags;
442 struct wl1271 *wl =
443 container_of(work, struct wl1271, irq_work);
444
445 mutex_lock(&wl->mutex);
446
447 wl1271_debug(DEBUG_IRQ, "IRQ work");
448
449 if (unlikely(wl->state == WL1271_STATE_OFF))
450 goto out;
451
452 ret = wl1271_ps_elp_wakeup(wl, true);
453 if (ret < 0)
454 goto out;
455
456 spin_lock_irqsave(&wl->wl_lock, flags);
457 while (test_bit(WL1271_FLAG_IRQ_PENDING, &wl->flags) && loopcount) {
458 clear_bit(WL1271_FLAG_IRQ_PENDING, &wl->flags);
459 spin_unlock_irqrestore(&wl->wl_lock, flags);
460 loopcount--;
461
462 wl1271_fw_status(wl, wl->fw_status);
463 intr = le32_to_cpu(wl->fw_status->intr);
464 if (!intr) {
465 wl1271_debug(DEBUG_IRQ, "Zero interrupt received.");
466 spin_lock_irqsave(&wl->wl_lock, flags);
467 continue;
468 }
469
470 intr &= WL1271_INTR_MASK;
471
472 if (intr & WL1271_ACX_INTR_DATA) {
473 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA");
474
475 /* check for tx results */
476 if (wl->fw_status->tx_results_counter !=
477 (wl->tx_results_count & 0xff))
478 wl1271_tx_complete(wl);
479
480 wl1271_rx(wl, wl->fw_status);
481 }
482
483 if (intr & WL1271_ACX_INTR_EVENT_A) {
484 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_A");
485 wl1271_event_handle(wl, 0);
486 }
487
488 if (intr & WL1271_ACX_INTR_EVENT_B) {
489 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_B");
490 wl1271_event_handle(wl, 1);
491 }
492
493 if (intr & WL1271_ACX_INTR_INIT_COMPLETE)
494 wl1271_debug(DEBUG_IRQ,
495 "WL1271_ACX_INTR_INIT_COMPLETE");
496
497 if (intr & WL1271_ACX_INTR_HW_AVAILABLE)
498 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE");
499
500 spin_lock_irqsave(&wl->wl_lock, flags);
501 }
502
503 if (test_bit(WL1271_FLAG_IRQ_PENDING, &wl->flags))
504 ieee80211_queue_work(wl->hw, &wl->irq_work);
505 else
506 clear_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
507 spin_unlock_irqrestore(&wl->wl_lock, flags);
508
509 wl1271_ps_elp_sleep(wl);
510
511out:
512 mutex_unlock(&wl->mutex);
513}
514
515static int wl1271_fetch_firmware(struct wl1271 *wl)
516{
517 const struct firmware *fw;
518 int ret;
519
520 ret = request_firmware(&fw, WL1271_FW_NAME, wl1271_wl_to_dev(wl));
521
522 if (ret < 0) {
523 wl1271_error("could not get firmware: %d", ret);
524 return ret;
525 }
526
527 if (fw->size % 4) {
528 wl1271_error("firmware size is not multiple of 32 bits: %zu",
529 fw->size);
530 ret = -EILSEQ;
531 goto out;
532 }
533
534 wl->fw_len = fw->size;
535 wl->fw = vmalloc(wl->fw_len);
536
537 if (!wl->fw) {
538 wl1271_error("could not allocate memory for the firmware");
539 ret = -ENOMEM;
540 goto out;
541 }
542
543 memcpy(wl->fw, fw->data, wl->fw_len);
544
545 ret = 0;
546
547out:
548 release_firmware(fw);
549
550 return ret;
551}
552
553static int wl1271_fetch_nvs(struct wl1271 *wl)
554{
555 const struct firmware *fw;
556 int ret;
557
558 ret = request_firmware(&fw, WL1271_NVS_NAME, wl1271_wl_to_dev(wl));
559
560 if (ret < 0) {
561 wl1271_error("could not get nvs file: %d", ret);
562 return ret;
563 }
564
565 /*
566 * FIXME: the LEGACY NVS image support (NVS's missing the 5GHz band
567 * configurations) can be removed when those NVS files stop floating
568 * around.
569 */
570 if (fw->size != sizeof(struct wl1271_nvs_file) &&
571 (fw->size != WL1271_INI_LEGACY_NVS_FILE_SIZE ||
572 wl1271_11a_enabled())) {
573 wl1271_error("nvs size is not as expected: %zu != %zu",
574 fw->size, sizeof(struct wl1271_nvs_file));
575 ret = -EILSEQ;
576 goto out;
577 }
578
579 wl->nvs = kmemdup(fw->data, sizeof(struct wl1271_nvs_file), GFP_KERNEL);
580
581 if (!wl->nvs) {
582 wl1271_error("could not allocate memory for the nvs file");
583 ret = -ENOMEM;
584 goto out;
585 }
586
587out:
588 release_firmware(fw);
589
590 return ret;
591}
592
593static void wl1271_fw_wakeup(struct wl1271 *wl)
594{
595 u32 elp_reg;
596
597 elp_reg = ELPCTRL_WAKE_UP;
598 wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
599}
600
601static int wl1271_setup(struct wl1271 *wl)
602{
603 wl->fw_status = kmalloc(sizeof(*wl->fw_status), GFP_KERNEL);
604 if (!wl->fw_status)
605 return -ENOMEM;
606
607 wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL);
608 if (!wl->tx_res_if) {
609 kfree(wl->fw_status);
610 return -ENOMEM;
611 }
612
613 INIT_WORK(&wl->irq_work, wl1271_irq_work);
614 INIT_WORK(&wl->tx_work, wl1271_tx_work);
615 return 0;
616}
617
618static int wl1271_chip_wakeup(struct wl1271 *wl)
619{
620 struct wl1271_partition_set partition;
621 int ret = 0;
622
623 msleep(WL1271_PRE_POWER_ON_SLEEP);
624 wl1271_power_on(wl);
625 msleep(WL1271_POWER_ON_SLEEP);
626 wl1271_io_reset(wl);
627 wl1271_io_init(wl);
628
629 /* We don't need a real memory partition here, because we only want
630 * to use the registers at this point. */
631 memset(&partition, 0, sizeof(partition));
632 partition.reg.start = REGISTERS_BASE;
633 partition.reg.size = REGISTERS_DOWN_SIZE;
634 wl1271_set_partition(wl, &partition);
635
636 /* ELP module wake up */
637 wl1271_fw_wakeup(wl);
638
639 /* whal_FwCtrl_BootSm() */
640
641 /* 0. read chip id from CHIP_ID */
642 wl->chip.id = wl1271_read32(wl, CHIP_ID_B);
643
644 /* 1. check if chip id is valid */
645
646 switch (wl->chip.id) {
647 case CHIP_ID_1271_PG10:
648 wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete",
649 wl->chip.id);
650
651 ret = wl1271_setup(wl);
652 if (ret < 0)
653 goto out;
654 break;
655 case CHIP_ID_1271_PG20:
656 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)",
657 wl->chip.id);
658
659 ret = wl1271_setup(wl);
660 if (ret < 0)
661 goto out;
662 break;
663 default:
664 wl1271_warning("unsupported chip id: 0x%x", wl->chip.id);
665 ret = -ENODEV;
666 goto out;
667 }
668
669 if (wl->fw == NULL) {
670 ret = wl1271_fetch_firmware(wl);
671 if (ret < 0)
672 goto out;
673 }
674
675 /* No NVS from netlink, try to get it from the filesystem */
676 if (wl->nvs == NULL) {
677 ret = wl1271_fetch_nvs(wl);
678 if (ret < 0)
679 goto out;
680 }
681
682out:
683 return ret;
684}
685
686int wl1271_plt_start(struct wl1271 *wl)
687{
688 int retries = WL1271_BOOT_RETRIES;
689 int ret;
690
691 mutex_lock(&wl->mutex);
692
693 wl1271_notice("power up");
694
695 if (wl->state != WL1271_STATE_OFF) {
696 wl1271_error("cannot go into PLT state because not "
697 "in off state: %d", wl->state);
698 ret = -EBUSY;
699 goto out;
700 }
701
702 while (retries) {
703 retries--;
704 ret = wl1271_chip_wakeup(wl);
705 if (ret < 0)
706 goto power_off;
707
708 ret = wl1271_boot(wl);
709 if (ret < 0)
710 goto power_off;
711
712 ret = wl1271_plt_init(wl);
713 if (ret < 0)
714 goto irq_disable;
715
716 wl->state = WL1271_STATE_PLT;
717 wl1271_notice("firmware booted in PLT mode (%s)",
718 wl->chip.fw_ver);
719 goto out;
720
721irq_disable:
722 wl1271_disable_interrupts(wl);
723 mutex_unlock(&wl->mutex);
724 /* Unlocking the mutex in the middle of handling is
725 inherently unsafe. In this case we deem it safe to do,
726 because we need to let any possibly pending IRQ out of
727 the system (and while we are WL1271_STATE_OFF the IRQ
728 work function will not do anything.) Also, any other
729 possible concurrent operations will fail due to the
730 current state, hence the wl1271 struct should be safe. */
731 cancel_work_sync(&wl->irq_work);
732 mutex_lock(&wl->mutex);
733power_off:
734 wl1271_power_off(wl);
735 }
736
737 wl1271_error("firmware boot in PLT mode failed despite %d retries",
738 WL1271_BOOT_RETRIES);
739out:
740 mutex_unlock(&wl->mutex);
741
742 return ret;
743}
744
745int wl1271_plt_stop(struct wl1271 *wl)
746{
747 int ret = 0;
748
749 mutex_lock(&wl->mutex);
750
751 wl1271_notice("power down");
752
753 if (wl->state != WL1271_STATE_PLT) {
754 wl1271_error("cannot power down because not in PLT "
755 "state: %d", wl->state);
756 ret = -EBUSY;
757 goto out;
758 }
759
760 wl1271_disable_interrupts(wl);
761 wl1271_power_off(wl);
762
763 wl->state = WL1271_STATE_OFF;
764 wl->rx_counter = 0;
765
766out:
767 mutex_unlock(&wl->mutex);
768
769 return ret;
770}
771
772
773static int wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
774{
775 struct wl1271 *wl = hw->priv;
776 struct ieee80211_conf *conf = &hw->conf;
777 struct ieee80211_tx_info *txinfo = IEEE80211_SKB_CB(skb);
778 struct ieee80211_sta *sta = txinfo->control.sta;
779 unsigned long flags;
780
781 /* peek into the rates configured in the STA entry */
782 spin_lock_irqsave(&wl->wl_lock, flags);
783 if (sta && sta->supp_rates[conf->channel->band] != wl->sta_rate_set) {
784 wl->sta_rate_set = sta->supp_rates[conf->channel->band];
785 set_bit(WL1271_FLAG_STA_RATES_CHANGED, &wl->flags);
786 }
787 spin_unlock_irqrestore(&wl->wl_lock, flags);
788
789 /* queue the packet */
790 skb_queue_tail(&wl->tx_queue, skb);
791
792 /*
793 * The chip specific setup must run before the first TX packet -
794 * before that, the tx_work will not be initialized!
795 */
796
797 ieee80211_queue_work(wl->hw, &wl->tx_work);
798
799 /*
800 * The workqueue is slow to process the tx_queue and we need stop
801 * the queue here, otherwise the queue will get too long.
802 */
803 if (skb_queue_len(&wl->tx_queue) >= WL1271_TX_QUEUE_HIGH_WATERMARK) {
804 wl1271_debug(DEBUG_TX, "op_tx: stopping queues");
805
806 spin_lock_irqsave(&wl->wl_lock, flags);
807 ieee80211_stop_queues(wl->hw);
808 set_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags);
809 spin_unlock_irqrestore(&wl->wl_lock, flags);
810 }
811
812 return NETDEV_TX_OK;
813}
814
815static int wl1271_op_start(struct ieee80211_hw *hw)
816{
817 wl1271_debug(DEBUG_MAC80211, "mac80211 start");
818
819 /*
820 * We have to delay the booting of the hardware because
821 * we need to know the local MAC address before downloading and
822 * initializing the firmware. The MAC address cannot be changed
823 * after boot, and without the proper MAC address, the firmware
824 * will not function properly.
825 *
826 * The MAC address is first known when the corresponding interface
827 * is added. That is where we will initialize the hardware.
828 */
829
830 return 0;
831}
832
833static void wl1271_op_stop(struct ieee80211_hw *hw)
834{
835 wl1271_debug(DEBUG_MAC80211, "mac80211 stop");
836}
837
838static int wl1271_op_add_interface(struct ieee80211_hw *hw,
839 struct ieee80211_vif *vif)
840{
841 struct wl1271 *wl = hw->priv;
842 struct wiphy *wiphy = hw->wiphy;
843 int retries = WL1271_BOOT_RETRIES;
844 int ret = 0;
845
846 wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
847 vif->type, vif->addr);
848
849 mutex_lock(&wl->mutex);
850 if (wl->vif) {
851 ret = -EBUSY;
852 goto out;
853 }
854
855 wl->vif = vif;
856
857 switch (vif->type) {
858 case NL80211_IFTYPE_STATION:
859 wl->bss_type = BSS_TYPE_STA_BSS;
860 wl->set_bss_type = BSS_TYPE_STA_BSS;
861 break;
862 case NL80211_IFTYPE_ADHOC:
863 wl->bss_type = BSS_TYPE_IBSS;
864 wl->set_bss_type = BSS_TYPE_STA_BSS;
865 break;
866 default:
867 ret = -EOPNOTSUPP;
868 goto out;
869 }
870
871 memcpy(wl->mac_addr, vif->addr, ETH_ALEN);
872
873 if (wl->state != WL1271_STATE_OFF) {
874 wl1271_error("cannot start because not in off state: %d",
875 wl->state);
876 ret = -EBUSY;
877 goto out;
878 }
879
880 while (retries) {
881 retries--;
882 ret = wl1271_chip_wakeup(wl);
883 if (ret < 0)
884 goto power_off;
885
886 ret = wl1271_boot(wl);
887 if (ret < 0)
888 goto power_off;
889
890 ret = wl1271_hw_init(wl);
891 if (ret < 0)
892 goto irq_disable;
893
894 wl->state = WL1271_STATE_ON;
895 wl1271_info("firmware booted (%s)", wl->chip.fw_ver);
896
897 /* update hw/fw version info in wiphy struct */
898 wiphy->hw_version = wl->chip.id;
899 strncpy(wiphy->fw_version, wl->chip.fw_ver,
900 sizeof(wiphy->fw_version));
901
902 goto out;
903
904irq_disable:
905 wl1271_disable_interrupts(wl);
906 mutex_unlock(&wl->mutex);
907 /* Unlocking the mutex in the middle of handling is
908 inherently unsafe. In this case we deem it safe to do,
909 because we need to let any possibly pending IRQ out of
910 the system (and while we are WL1271_STATE_OFF the IRQ
911 work function will not do anything.) Also, any other
912 possible concurrent operations will fail due to the
913 current state, hence the wl1271 struct should be safe. */
914 cancel_work_sync(&wl->irq_work);
915 mutex_lock(&wl->mutex);
916power_off:
917 wl1271_power_off(wl);
918 }
919
920 wl1271_error("firmware boot failed despite %d retries",
921 WL1271_BOOT_RETRIES);
922out:
923 mutex_unlock(&wl->mutex);
924
925 if (!ret)
926 list_add(&wl->list, &wl_list);
927
928 return ret;
929}
930
931static void wl1271_op_remove_interface(struct ieee80211_hw *hw,
932 struct ieee80211_vif *vif)
933{
934 struct wl1271 *wl = hw->priv;
935 int i;
936
937 mutex_lock(&wl->mutex);
938 wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface");
939
940 wl1271_info("down");
941
942 list_del(&wl->list);
943
944 WARN_ON(wl->state != WL1271_STATE_ON);
945
946 /* enable dyn ps just in case (if left on due to fw crash etc) */
947 if (wl->bss_type == BSS_TYPE_STA_BSS)
948 ieee80211_enable_dyn_ps(wl->vif);
949
950 if (wl->scan.state != WL1271_SCAN_STATE_IDLE) {
951 mutex_unlock(&wl->mutex);
952 ieee80211_scan_completed(wl->hw, true);
953 mutex_lock(&wl->mutex);
954 wl->scan.state = WL1271_SCAN_STATE_IDLE;
955 kfree(wl->scan.scanned_ch);
956 wl->scan.scanned_ch = NULL;
957 }
958
959 wl->state = WL1271_STATE_OFF;
960
961 wl1271_disable_interrupts(wl);
962
963 mutex_unlock(&wl->mutex);
964
965 cancel_work_sync(&wl->irq_work);
966 cancel_work_sync(&wl->tx_work);
967 cancel_delayed_work_sync(&wl->pspoll_work);
968
969 mutex_lock(&wl->mutex);
970
971 /* let's notify MAC80211 about the remaining pending TX frames */
972 wl1271_tx_reset(wl);
973 wl1271_power_off(wl);
974
975 memset(wl->bssid, 0, ETH_ALEN);
976 memset(wl->ssid, 0, IW_ESSID_MAX_SIZE + 1);
977 wl->ssid_len = 0;
978 wl->bss_type = MAX_BSS_TYPE;
979 wl->set_bss_type = MAX_BSS_TYPE;
980 wl->band = IEEE80211_BAND_2GHZ;
981
982 wl->rx_counter = 0;
983 wl->psm_entry_retry = 0;
984 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
985 wl->tx_blocks_available = 0;
986 wl->tx_results_count = 0;
987 wl->tx_packets_count = 0;
988 wl->tx_security_last_seq = 0;
989 wl->tx_security_seq = 0;
990 wl->time_offset = 0;
991 wl->session_counter = 0;
992 wl->rate_set = CONF_TX_RATE_MASK_BASIC;
993 wl->sta_rate_set = 0;
994 wl->flags = 0;
995 wl->vif = NULL;
996 wl->filters = 0;
997
998 for (i = 0; i < NUM_TX_QUEUES; i++)
999 wl->tx_blocks_freed[i] = 0;
1000
1001 wl1271_debugfs_reset(wl);
1002
1003 kfree(wl->fw_status);
1004 wl->fw_status = NULL;
1005 kfree(wl->tx_res_if);
1006 wl->tx_res_if = NULL;
1007 kfree(wl->target_mem_map);
1008 wl->target_mem_map = NULL;
1009
1010 mutex_unlock(&wl->mutex);
1011}
1012
1013static void wl1271_configure_filters(struct wl1271 *wl, unsigned int filters)
1014{
1015 wl->rx_config = WL1271_DEFAULT_RX_CONFIG;
1016 wl->rx_filter = WL1271_DEFAULT_RX_FILTER;
1017
1018 /* combine requested filters with current filter config */
1019 filters = wl->filters | filters;
1020
1021 wl1271_debug(DEBUG_FILTERS, "RX filters set: ");
1022
1023 if (filters & FIF_PROMISC_IN_BSS) {
1024 wl1271_debug(DEBUG_FILTERS, " - FIF_PROMISC_IN_BSS");
1025 wl->rx_config &= ~CFG_UNI_FILTER_EN;
1026 wl->rx_config |= CFG_BSSID_FILTER_EN;
1027 }
1028 if (filters & FIF_BCN_PRBRESP_PROMISC) {
1029 wl1271_debug(DEBUG_FILTERS, " - FIF_BCN_PRBRESP_PROMISC");
1030 wl->rx_config &= ~CFG_BSSID_FILTER_EN;
1031 wl->rx_config &= ~CFG_SSID_FILTER_EN;
1032 }
1033 if (filters & FIF_OTHER_BSS) {
1034 wl1271_debug(DEBUG_FILTERS, " - FIF_OTHER_BSS");
1035 wl->rx_config &= ~CFG_BSSID_FILTER_EN;
1036 }
1037 if (filters & FIF_CONTROL) {
1038 wl1271_debug(DEBUG_FILTERS, " - FIF_CONTROL");
1039 wl->rx_filter |= CFG_RX_CTL_EN;
1040 }
1041 if (filters & FIF_FCSFAIL) {
1042 wl1271_debug(DEBUG_FILTERS, " - FIF_FCSFAIL");
1043 wl->rx_filter |= CFG_RX_FCS_ERROR;
1044 }
1045}
1046
1047static int wl1271_dummy_join(struct wl1271 *wl)
1048{
1049 int ret = 0;
1050 /* we need to use a dummy BSSID for now */
1051 static const u8 dummy_bssid[ETH_ALEN] = { 0x0b, 0xad, 0xde,
1052 0xad, 0xbe, 0xef };
1053
1054 memcpy(wl->bssid, dummy_bssid, ETH_ALEN);
1055
1056 /* pass through frames from all BSS */
1057 wl1271_configure_filters(wl, FIF_OTHER_BSS);
1058
1059 ret = wl1271_cmd_join(wl, wl->set_bss_type);
1060 if (ret < 0)
1061 goto out;
1062
1063 set_bit(WL1271_FLAG_JOINED, &wl->flags);
1064
1065out:
1066 return ret;
1067}
1068
1069static int wl1271_join(struct wl1271 *wl, bool set_assoc)
1070{
1071 int ret;
1072
1073 /*
1074 * One of the side effects of the JOIN command is that is clears
1075 * WPA/WPA2 keys from the chipset. Performing a JOIN while associated
1076 * to a WPA/WPA2 access point will therefore kill the data-path.
1077 * Currently there is no supported scenario for JOIN during
1078 * association - if it becomes a supported scenario, the WPA/WPA2 keys
1079 * must be handled somehow.
1080 *
1081 */
1082 if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags))
1083 wl1271_info("JOIN while associated.");
1084
1085 if (set_assoc)
1086 set_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags);
1087
1088 ret = wl1271_cmd_join(wl, wl->set_bss_type);
1089 if (ret < 0)
1090 goto out;
1091
1092 set_bit(WL1271_FLAG_JOINED, &wl->flags);
1093
1094 if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags))
1095 goto out;
1096
1097 /*
1098 * The join command disable the keep-alive mode, shut down its process,
1099 * and also clear the template config, so we need to reset it all after
1100 * the join. The acx_aid starts the keep-alive process, and the order
1101 * of the commands below is relevant.
1102 */
1103 ret = wl1271_acx_keep_alive_mode(wl, true);
1104 if (ret < 0)
1105 goto out;
1106
1107 ret = wl1271_acx_aid(wl, wl->aid);
1108 if (ret < 0)
1109 goto out;
1110
1111 ret = wl1271_cmd_build_klv_null_data(wl);
1112 if (ret < 0)
1113 goto out;
1114
1115 ret = wl1271_acx_keep_alive_config(wl, CMD_TEMPL_KLV_IDX_NULL_DATA,
1116 ACX_KEEP_ALIVE_TPL_VALID);
1117 if (ret < 0)
1118 goto out;
1119
1120out:
1121 return ret;
1122}
1123
1124static int wl1271_unjoin(struct wl1271 *wl)
1125{
1126 int ret;
1127
1128 /* to stop listening to a channel, we disconnect */
1129 ret = wl1271_cmd_disconnect(wl);
1130 if (ret < 0)
1131 goto out;
1132
1133 clear_bit(WL1271_FLAG_JOINED, &wl->flags);
1134 memset(wl->bssid, 0, ETH_ALEN);
1135
1136 /* stop filterting packets based on bssid */
1137 wl1271_configure_filters(wl, FIF_OTHER_BSS);
1138
1139out:
1140 return ret;
1141}
1142
1143static void wl1271_set_band_rate(struct wl1271 *wl)
1144{
1145 if (wl->band == IEEE80211_BAND_2GHZ)
1146 wl->basic_rate_set = wl->conf.tx.basic_rate;
1147 else
1148 wl->basic_rate_set = wl->conf.tx.basic_rate_5;
1149}
1150
1151static u32 wl1271_min_rate_get(struct wl1271 *wl)
1152{
1153 int i;
1154 u32 rate = 0;
1155
1156 if (!wl->basic_rate_set) {
1157 WARN_ON(1);
1158 wl->basic_rate_set = wl->conf.tx.basic_rate;
1159 }
1160
1161 for (i = 0; !rate; i++) {
1162 if ((wl->basic_rate_set >> i) & 0x1)
1163 rate = 1 << i;
1164 }
1165
1166 return rate;
1167}
1168
1169static int wl1271_handle_idle(struct wl1271 *wl, bool idle)
1170{
1171 int ret;
1172
1173 if (idle) {
1174 if (test_bit(WL1271_FLAG_JOINED, &wl->flags)) {
1175 ret = wl1271_unjoin(wl);
1176 if (ret < 0)
1177 goto out;
1178 }
1179 wl->rate_set = wl1271_min_rate_get(wl);
1180 wl->sta_rate_set = 0;
1181 ret = wl1271_acx_rate_policies(wl);
1182 if (ret < 0)
1183 goto out;
1184 ret = wl1271_acx_keep_alive_config(
1185 wl, CMD_TEMPL_KLV_IDX_NULL_DATA,
1186 ACX_KEEP_ALIVE_TPL_INVALID);
1187 if (ret < 0)
1188 goto out;
1189 set_bit(WL1271_FLAG_IDLE, &wl->flags);
1190 } else {
1191 /* increment the session counter */
1192 wl->session_counter++;
1193 if (wl->session_counter >= SESSION_COUNTER_MAX)
1194 wl->session_counter = 0;
1195 ret = wl1271_dummy_join(wl);
1196 if (ret < 0)
1197 goto out;
1198 clear_bit(WL1271_FLAG_IDLE, &wl->flags);
1199 }
1200
1201out:
1202 return ret;
1203}
1204
1205static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
1206{
1207 struct wl1271 *wl = hw->priv;
1208 struct ieee80211_conf *conf = &hw->conf;
1209 int channel, ret = 0;
1210
1211 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
1212
1213 wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d %s",
1214 channel,
1215 conf->flags & IEEE80211_CONF_PS ? "on" : "off",
1216 conf->power_level,
1217 conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use");
1218
1219 /*
1220 * mac80211 will go to idle nearly immediately after transmitting some
1221 * frames, such as the deauth. To make sure those frames reach the air,
1222 * wait here until the TX queue is fully flushed.
1223 */
1224 if ((changed & IEEE80211_CONF_CHANGE_IDLE) &&
1225 (conf->flags & IEEE80211_CONF_IDLE))
1226 wl1271_tx_flush(wl);
1227
1228 mutex_lock(&wl->mutex);
1229
1230 if (unlikely(wl->state == WL1271_STATE_OFF))
1231 goto out;
1232
1233 ret = wl1271_ps_elp_wakeup(wl, false);
1234 if (ret < 0)
1235 goto out;
1236
1237 /* if the channel changes while joined, join again */
1238 if (changed & IEEE80211_CONF_CHANGE_CHANNEL &&
1239 ((wl->band != conf->channel->band) ||
1240 (wl->channel != channel))) {
1241 wl->band = conf->channel->band;
1242 wl->channel = channel;
1243
1244 /*
1245 * FIXME: the mac80211 should really provide a fixed rate
1246 * to use here. for now, just use the smallest possible rate
1247 * for the band as a fixed rate for association frames and
1248 * other control messages.
1249 */
1250 if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags))
1251 wl1271_set_band_rate(wl);
1252
1253 wl->basic_rate = wl1271_min_rate_get(wl);
1254 ret = wl1271_acx_rate_policies(wl);
1255 if (ret < 0)
1256 wl1271_warning("rate policy for update channel "
1257 "failed %d", ret);
1258
1259 if (test_bit(WL1271_FLAG_JOINED, &wl->flags)) {
1260 ret = wl1271_join(wl, false);
1261 if (ret < 0)
1262 wl1271_warning("cmd join to update channel "
1263 "failed %d", ret);
1264 }
1265 }
1266
1267 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1268 ret = wl1271_handle_idle(wl, conf->flags & IEEE80211_CONF_IDLE);
1269 if (ret < 0)
1270 wl1271_warning("idle mode change failed %d", ret);
1271 }
1272
1273 /*
1274 * if mac80211 changes the PSM mode, make sure the mode is not
1275 * incorrectly changed after the pspoll failure active window.
1276 */
1277 if (changed & IEEE80211_CONF_CHANGE_PS)
1278 clear_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags);
1279
1280 if (conf->flags & IEEE80211_CONF_PS &&
1281 !test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags)) {
1282 set_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags);
1283
1284 /*
1285 * We enter PSM only if we're already associated.
1286 * If we're not, we'll enter it when joining an SSID,
1287 * through the bss_info_changed() hook.
1288 */
1289 if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) {
1290 wl1271_debug(DEBUG_PSM, "psm enabled");
1291 ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE,
1292 true);
1293 }
1294 } else if (!(conf->flags & IEEE80211_CONF_PS) &&
1295 test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags)) {
1296 wl1271_debug(DEBUG_PSM, "psm disabled");
1297
1298 clear_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags);
1299
1300 if (test_bit(WL1271_FLAG_PSM, &wl->flags))
1301 ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE,
1302 true);
1303 }
1304
1305 if (conf->power_level != wl->power_level) {
1306 ret = wl1271_acx_tx_power(wl, conf->power_level);
1307 if (ret < 0)
1308 goto out_sleep;
1309
1310 wl->power_level = conf->power_level;
1311 }
1312
1313out_sleep:
1314 wl1271_ps_elp_sleep(wl);
1315
1316out:
1317 mutex_unlock(&wl->mutex);
1318
1319 return ret;
1320}
1321
1322struct wl1271_filter_params {
1323 bool enabled;
1324 int mc_list_length;
1325 u8 mc_list[ACX_MC_ADDRESS_GROUP_MAX][ETH_ALEN];
1326};
1327
1328static u64 wl1271_op_prepare_multicast(struct ieee80211_hw *hw,
1329 struct netdev_hw_addr_list *mc_list)
1330{
1331 struct wl1271_filter_params *fp;
1332 struct netdev_hw_addr *ha;
1333 struct wl1271 *wl = hw->priv;
1334
1335 if (unlikely(wl->state == WL1271_STATE_OFF))
1336 return 0;
1337
1338 fp = kzalloc(sizeof(*fp), GFP_ATOMIC);
1339 if (!fp) {
1340 wl1271_error("Out of memory setting filters.");
1341 return 0;
1342 }
1343
1344 /* update multicast filtering parameters */
1345 fp->mc_list_length = 0;
1346 if (netdev_hw_addr_list_count(mc_list) > ACX_MC_ADDRESS_GROUP_MAX) {
1347 fp->enabled = false;
1348 } else {
1349 fp->enabled = true;
1350 netdev_hw_addr_list_for_each(ha, mc_list) {
1351 memcpy(fp->mc_list[fp->mc_list_length],
1352 ha->addr, ETH_ALEN);
1353 fp->mc_list_length++;
1354 }
1355 }
1356
1357 return (u64)(unsigned long)fp;
1358}
1359
1360#define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
1361 FIF_ALLMULTI | \
1362 FIF_FCSFAIL | \
1363 FIF_BCN_PRBRESP_PROMISC | \
1364 FIF_CONTROL | \
1365 FIF_OTHER_BSS)
1366
1367static void wl1271_op_configure_filter(struct ieee80211_hw *hw,
1368 unsigned int changed,
1369 unsigned int *total, u64 multicast)
1370{
1371 struct wl1271_filter_params *fp = (void *)(unsigned long)multicast;
1372 struct wl1271 *wl = hw->priv;
1373 int ret;
1374
1375 wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter");
1376
1377 mutex_lock(&wl->mutex);
1378
1379 *total &= WL1271_SUPPORTED_FILTERS;
1380 changed &= WL1271_SUPPORTED_FILTERS;
1381
1382 if (unlikely(wl->state == WL1271_STATE_OFF))
1383 goto out;
1384
1385 ret = wl1271_ps_elp_wakeup(wl, false);
1386 if (ret < 0)
1387 goto out;
1388
1389
1390 if (*total & FIF_ALLMULTI)
1391 ret = wl1271_acx_group_address_tbl(wl, false, NULL, 0);
1392 else if (fp)
1393 ret = wl1271_acx_group_address_tbl(wl, fp->enabled,
1394 fp->mc_list,
1395 fp->mc_list_length);
1396 if (ret < 0)
1397 goto out_sleep;
1398
1399 /* determine, whether supported filter values have changed */
1400 if (changed == 0)
1401 goto out_sleep;
1402
1403 /* configure filters */
1404 wl->filters = *total;
1405 wl1271_configure_filters(wl, 0);
1406
1407 /* apply configured filters */
1408 ret = wl1271_acx_rx_config(wl, wl->rx_config, wl->rx_filter);
1409 if (ret < 0)
1410 goto out_sleep;
1411
1412out_sleep:
1413 wl1271_ps_elp_sleep(wl);
1414
1415out:
1416 mutex_unlock(&wl->mutex);
1417 kfree(fp);
1418}
1419
1420static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
1421 struct ieee80211_vif *vif,
1422 struct ieee80211_sta *sta,
1423 struct ieee80211_key_conf *key_conf)
1424{
1425 struct wl1271 *wl = hw->priv;
1426 const u8 *addr;
1427 int ret;
1428 u32 tx_seq_32 = 0;
1429 u16 tx_seq_16 = 0;
1430 u8 key_type;
1431
1432 static const u8 bcast_addr[ETH_ALEN] =
1433 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1434
1435 wl1271_debug(DEBUG_MAC80211, "mac80211 set key");
1436
1437 addr = sta ? sta->addr : bcast_addr;
1438
1439 wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x", cmd);
1440 wl1271_dump(DEBUG_CRYPT, "ADDR: ", addr, ETH_ALEN);
1441 wl1271_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
1442 key_conf->alg, key_conf->keyidx,
1443 key_conf->keylen, key_conf->flags);
1444 wl1271_dump(DEBUG_CRYPT, "KEY: ", key_conf->key, key_conf->keylen);
1445
1446 if (is_zero_ether_addr(addr)) {
1447 /* We dont support TX only encryption */
1448 ret = -EOPNOTSUPP;
1449 goto out;
1450 }
1451
1452 mutex_lock(&wl->mutex);
1453
1454 ret = wl1271_ps_elp_wakeup(wl, false);
1455 if (ret < 0)
1456 goto out_unlock;
1457
1458 switch (key_conf->alg) {
1459 case ALG_WEP:
1460 key_type = KEY_WEP;
1461
1462 key_conf->hw_key_idx = key_conf->keyidx;
1463 break;
1464 case ALG_TKIP:
1465 key_type = KEY_TKIP;
1466
1467 key_conf->hw_key_idx = key_conf->keyidx;
1468 tx_seq_32 = WL1271_TX_SECURITY_HI32(wl->tx_security_seq);
1469 tx_seq_16 = WL1271_TX_SECURITY_LO16(wl->tx_security_seq);
1470 break;
1471 case ALG_CCMP:
1472 key_type = KEY_AES;
1473
1474 key_conf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1475 tx_seq_32 = WL1271_TX_SECURITY_HI32(wl->tx_security_seq);
1476 tx_seq_16 = WL1271_TX_SECURITY_LO16(wl->tx_security_seq);
1477 break;
1478 default:
1479 wl1271_error("Unknown key algo 0x%x", key_conf->alg);
1480
1481 ret = -EOPNOTSUPP;
1482 goto out_sleep;
1483 }
1484
1485 switch (cmd) {
1486 case SET_KEY:
1487 ret = wl1271_cmd_set_key(wl, KEY_ADD_OR_REPLACE,
1488 key_conf->keyidx, key_type,
1489 key_conf->keylen, key_conf->key,
1490 addr, tx_seq_32, tx_seq_16);
1491 if (ret < 0) {
1492 wl1271_error("Could not add or replace key");
1493 goto out_sleep;
1494 }
1495
1496 /* the default WEP key needs to be configured at least once */
1497 if (key_type == KEY_WEP) {
1498 ret = wl1271_cmd_set_default_wep_key(wl,
1499 wl->default_key);
1500 if (ret < 0)
1501 goto out_sleep;
1502 }
1503 break;
1504
1505 case DISABLE_KEY:
1506 /* The wl1271 does not allow to remove unicast keys - they
1507 will be cleared automatically on next CMD_JOIN. Ignore the
1508 request silently, as we dont want the mac80211 to emit
1509 an error message. */
1510 if (!is_broadcast_ether_addr(addr))
1511 break;
1512
1513 ret = wl1271_cmd_set_key(wl, KEY_REMOVE,
1514 key_conf->keyidx, key_type,
1515 key_conf->keylen, key_conf->key,
1516 addr, 0, 0);
1517 if (ret < 0) {
1518 wl1271_error("Could not remove key");
1519 goto out_sleep;
1520 }
1521 break;
1522
1523 default:
1524 wl1271_error("Unsupported key cmd 0x%x", cmd);
1525 ret = -EOPNOTSUPP;
1526 break;
1527 }
1528
1529out_sleep:
1530 wl1271_ps_elp_sleep(wl);
1531
1532out_unlock:
1533 mutex_unlock(&wl->mutex);
1534
1535out:
1536 return ret;
1537}
1538
1539static int wl1271_op_hw_scan(struct ieee80211_hw *hw,
1540 struct ieee80211_vif *vif,
1541 struct cfg80211_scan_request *req)
1542{
1543 struct wl1271 *wl = hw->priv;
1544 int ret;
1545 u8 *ssid = NULL;
1546 size_t len = 0;
1547
1548 wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan");
1549
1550 if (req->n_ssids) {
1551 ssid = req->ssids[0].ssid;
1552 len = req->ssids[0].ssid_len;
1553 }
1554
1555 mutex_lock(&wl->mutex);
1556
1557 ret = wl1271_ps_elp_wakeup(wl, false);
1558 if (ret < 0)
1559 goto out;
1560
1561 if (wl1271_11a_enabled())
1562 ret = wl1271_scan(hw->priv, ssid, len, req);
1563 else
1564 ret = wl1271_scan(hw->priv, ssid, len, req);
1565
1566 wl1271_ps_elp_sleep(wl);
1567
1568out:
1569 mutex_unlock(&wl->mutex);
1570
1571 return ret;
1572}
1573
1574static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1575{
1576 struct wl1271 *wl = hw->priv;
1577 int ret = 0;
1578
1579 mutex_lock(&wl->mutex);
1580
1581 if (unlikely(wl->state == WL1271_STATE_OFF))
1582 goto out;
1583
1584 ret = wl1271_ps_elp_wakeup(wl, false);
1585 if (ret < 0)
1586 goto out;
1587
1588 ret = wl1271_acx_rts_threshold(wl, (u16) value);
1589 if (ret < 0)
1590 wl1271_warning("wl1271_op_set_rts_threshold failed: %d", ret);
1591
1592 wl1271_ps_elp_sleep(wl);
1593
1594out:
1595 mutex_unlock(&wl->mutex);
1596
1597 return ret;
1598}
1599
1600static void wl1271_ssid_set(struct wl1271 *wl, struct sk_buff *beacon)
1601{
1602 u8 *ptr = beacon->data +
1603 offsetof(struct ieee80211_mgmt, u.beacon.variable);
1604
1605 /* find the location of the ssid in the beacon */
1606 while (ptr < beacon->data + beacon->len) {
1607 if (ptr[0] == WLAN_EID_SSID) {
1608 wl->ssid_len = ptr[1];
1609 memcpy(wl->ssid, ptr+2, wl->ssid_len);
1610 return;
1611 }
1612 ptr += ptr[1];
1613 }
1614 wl1271_error("ad-hoc beacon template has no SSID!\n");
1615}
1616
1617static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
1618 struct ieee80211_vif *vif,
1619 struct ieee80211_bss_conf *bss_conf,
1620 u32 changed)
1621{
1622 enum wl1271_cmd_ps_mode mode;
1623 struct wl1271 *wl = hw->priv;
1624 bool do_join = false;
1625 bool set_assoc = false;
1626 int ret;
1627
1628 wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed");
1629
1630 mutex_lock(&wl->mutex);
1631
1632 ret = wl1271_ps_elp_wakeup(wl, false);
1633 if (ret < 0)
1634 goto out;
1635
1636 if ((changed && BSS_CHANGED_BEACON_INT) &&
1637 (wl->bss_type == BSS_TYPE_IBSS)) {
1638 wl1271_debug(DEBUG_ADHOC, "ad-hoc beacon interval updated: %d",
1639 bss_conf->beacon_int);
1640
1641 wl->beacon_int = bss_conf->beacon_int;
1642 do_join = true;
1643 }
1644
1645 if ((changed && BSS_CHANGED_BEACON) &&
1646 (wl->bss_type == BSS_TYPE_IBSS)) {
1647 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
1648
1649 wl1271_debug(DEBUG_ADHOC, "ad-hoc beacon updated");
1650
1651 if (beacon) {
1652 struct ieee80211_hdr *hdr;
1653
1654 wl1271_ssid_set(wl, beacon);
1655 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON,
1656 beacon->data,
1657 beacon->len, 0,
1658 wl1271_min_rate_get(wl));
1659
1660 if (ret < 0) {
1661 dev_kfree_skb(beacon);
1662 goto out_sleep;
1663 }
1664
1665 hdr = (struct ieee80211_hdr *) beacon->data;
1666 hdr->frame_control = cpu_to_le16(
1667 IEEE80211_FTYPE_MGMT |
1668 IEEE80211_STYPE_PROBE_RESP);
1669
1670 ret = wl1271_cmd_template_set(wl,
1671 CMD_TEMPL_PROBE_RESPONSE,
1672 beacon->data,
1673 beacon->len, 0,
1674 wl1271_min_rate_get(wl));
1675 dev_kfree_skb(beacon);
1676 if (ret < 0)
1677 goto out_sleep;
1678
1679 /* Need to update the SSID (for filtering etc) */
1680 do_join = true;
1681 }
1682 }
1683
1684 if ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1685 (wl->bss_type == BSS_TYPE_IBSS)) {
1686 wl1271_debug(DEBUG_ADHOC, "ad-hoc beaconing: %s",
1687 bss_conf->enable_beacon ? "enabled" : "disabled");
1688
1689 if (bss_conf->enable_beacon)
1690 wl->set_bss_type = BSS_TYPE_IBSS;
1691 else
1692 wl->set_bss_type = BSS_TYPE_STA_BSS;
1693 do_join = true;
1694 }
1695
1696 if (changed & BSS_CHANGED_CQM) {
1697 bool enable = false;
1698 if (bss_conf->cqm_rssi_thold)
1699 enable = true;
1700 ret = wl1271_acx_rssi_snr_trigger(wl, enable,
1701 bss_conf->cqm_rssi_thold,
1702 bss_conf->cqm_rssi_hyst);
1703 if (ret < 0)
1704 goto out;
1705 wl->rssi_thold = bss_conf->cqm_rssi_thold;
1706 }
1707
1708 if ((changed & BSS_CHANGED_BSSID) &&
1709 /*
1710 * Now we know the correct bssid, so we send a new join command
1711 * and enable the BSSID filter
1712 */
1713 memcmp(wl->bssid, bss_conf->bssid, ETH_ALEN)) {
1714 memcpy(wl->bssid, bss_conf->bssid, ETH_ALEN);
1715
1716 ret = wl1271_cmd_build_null_data(wl);
1717 if (ret < 0)
1718 goto out_sleep;
1719
1720 ret = wl1271_build_qos_null_data(wl);
1721 if (ret < 0)
1722 goto out_sleep;
1723
1724 /* filter out all packets not from this BSSID */
1725 wl1271_configure_filters(wl, 0);
1726
1727 /* Need to update the BSSID (for filtering etc) */
1728 do_join = true;
1729 }
1730
1731 if (changed & BSS_CHANGED_ASSOC) {
1732 if (bss_conf->assoc) {
1733 u32 rates;
1734 wl->aid = bss_conf->aid;
1735 set_assoc = true;
1736
1737 wl->ps_poll_failures = 0;
1738
1739 /*
1740 * use basic rates from AP, and determine lowest rate
1741 * to use with control frames.
1742 */
1743 rates = bss_conf->basic_rates;
1744 wl->basic_rate_set = wl1271_tx_enabled_rates_get(wl,
1745 rates);
1746 wl->basic_rate = wl1271_min_rate_get(wl);
1747 ret = wl1271_acx_rate_policies(wl);
1748 if (ret < 0)
1749 goto out_sleep;
1750
1751 /*
1752 * with wl1271, we don't need to update the
1753 * beacon_int and dtim_period, because the firmware
1754 * updates it by itself when the first beacon is
1755 * received after a join.
1756 */
1757 ret = wl1271_cmd_build_ps_poll(wl, wl->aid);
1758 if (ret < 0)
1759 goto out_sleep;
1760
1761 /*
1762 * The SSID is intentionally set to NULL here - the
1763 * firmware will set the probe request with a
1764 * broadcast SSID regardless of what we set in the
1765 * template.
1766 */
1767 ret = wl1271_cmd_build_probe_req(wl, NULL, 0,
1768 NULL, 0, wl->band);
1769
1770 /* enable the connection monitoring feature */
1771 ret = wl1271_acx_conn_monit_params(wl, true);
1772 if (ret < 0)
1773 goto out_sleep;
1774
1775 /* If we want to go in PSM but we're not there yet */
1776 if (test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags) &&
1777 !test_bit(WL1271_FLAG_PSM, &wl->flags)) {
1778 mode = STATION_POWER_SAVE_MODE;
1779 ret = wl1271_ps_set_mode(wl, mode, true);
1780 if (ret < 0)
1781 goto out_sleep;
1782 }
1783 } else {
1784 /* use defaults when not associated */
1785 clear_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags);
1786 wl->aid = 0;
1787
1788 /* re-enable dynamic ps - just in case */
1789 ieee80211_enable_dyn_ps(wl->vif);
1790
1791 /* revert back to minimum rates for the current band */
1792 wl1271_set_band_rate(wl);
1793 wl->basic_rate = wl1271_min_rate_get(wl);
1794 ret = wl1271_acx_rate_policies(wl);
1795 if (ret < 0)
1796 goto out_sleep;
1797
1798 /* disable connection monitor features */
1799 ret = wl1271_acx_conn_monit_params(wl, false);
1800
1801 /* Disable the keep-alive feature */
1802 ret = wl1271_acx_keep_alive_mode(wl, false);
1803
1804 if (ret < 0)
1805 goto out_sleep;
1806 }
1807
1808 }
1809
1810 if (changed & BSS_CHANGED_ERP_SLOT) {
1811 if (bss_conf->use_short_slot)
1812 ret = wl1271_acx_slot(wl, SLOT_TIME_SHORT);
1813 else
1814 ret = wl1271_acx_slot(wl, SLOT_TIME_LONG);
1815 if (ret < 0) {
1816 wl1271_warning("Set slot time failed %d", ret);
1817 goto out_sleep;
1818 }
1819 }
1820
1821 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1822 if (bss_conf->use_short_preamble)
1823 wl1271_acx_set_preamble(wl, ACX_PREAMBLE_SHORT);
1824 else
1825 wl1271_acx_set_preamble(wl, ACX_PREAMBLE_LONG);
1826 }
1827
1828 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1829 if (bss_conf->use_cts_prot)
1830 ret = wl1271_acx_cts_protect(wl, CTSPROTECT_ENABLE);
1831 else
1832 ret = wl1271_acx_cts_protect(wl, CTSPROTECT_DISABLE);
1833 if (ret < 0) {
1834 wl1271_warning("Set ctsprotect failed %d", ret);
1835 goto out_sleep;
1836 }
1837 }
1838
1839 if (changed & BSS_CHANGED_ARP_FILTER) {
1840 __be32 addr = bss_conf->arp_addr_list[0];
1841 WARN_ON(wl->bss_type != BSS_TYPE_STA_BSS);
1842
1843 if (bss_conf->arp_addr_cnt == 1 && bss_conf->arp_filter_enabled)
1844 ret = wl1271_acx_arp_ip_filter(wl, true, addr);
1845 else
1846 ret = wl1271_acx_arp_ip_filter(wl, false, addr);
1847
1848 if (ret < 0)
1849 goto out_sleep;
1850 }
1851
1852 if (do_join) {
1853 ret = wl1271_join(wl, set_assoc);
1854 if (ret < 0) {
1855 wl1271_warning("cmd join failed %d", ret);
1856 goto out_sleep;
1857 }
1858 }
1859
1860out_sleep:
1861 wl1271_ps_elp_sleep(wl);
1862
1863out:
1864 mutex_unlock(&wl->mutex);
1865}
1866
1867static int wl1271_op_conf_tx(struct ieee80211_hw *hw, u16 queue,
1868 const struct ieee80211_tx_queue_params *params)
1869{
1870 struct wl1271 *wl = hw->priv;
1871 u8 ps_scheme;
1872 int ret;
1873
1874 mutex_lock(&wl->mutex);
1875
1876 wl1271_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue);
1877
1878 ret = wl1271_ps_elp_wakeup(wl, false);
1879 if (ret < 0)
1880 goto out;
1881
1882 /* the txop is confed in units of 32us by the mac80211, we need us */
1883 ret = wl1271_acx_ac_cfg(wl, wl1271_tx_get_queue(queue),
1884 params->cw_min, params->cw_max,
1885 params->aifs, params->txop << 5);
1886 if (ret < 0)
1887 goto out_sleep;
1888
1889 if (params->uapsd)
1890 ps_scheme = CONF_PS_SCHEME_UPSD_TRIGGER;
1891 else
1892 ps_scheme = CONF_PS_SCHEME_LEGACY;
1893
1894 ret = wl1271_acx_tid_cfg(wl, wl1271_tx_get_queue(queue),
1895 CONF_CHANNEL_TYPE_EDCF,
1896 wl1271_tx_get_queue(queue),
1897 ps_scheme, CONF_ACK_POLICY_LEGACY, 0, 0);
1898 if (ret < 0)
1899 goto out_sleep;
1900
1901out_sleep:
1902 wl1271_ps_elp_sleep(wl);
1903
1904out:
1905 mutex_unlock(&wl->mutex);
1906
1907 return ret;
1908}
1909
1910static u64 wl1271_op_get_tsf(struct ieee80211_hw *hw)
1911{
1912
1913 struct wl1271 *wl = hw->priv;
1914 u64 mactime = ULLONG_MAX;
1915 int ret;
1916
1917 wl1271_debug(DEBUG_MAC80211, "mac80211 get tsf");
1918
1919 mutex_lock(&wl->mutex);
1920
1921 ret = wl1271_ps_elp_wakeup(wl, false);
1922 if (ret < 0)
1923 goto out;
1924
1925 ret = wl1271_acx_tsf_info(wl, &mactime);
1926 if (ret < 0)
1927 goto out_sleep;
1928
1929out_sleep:
1930 wl1271_ps_elp_sleep(wl);
1931
1932out:
1933 mutex_unlock(&wl->mutex);
1934 return mactime;
1935}
1936
1937static int wl1271_op_get_survey(struct ieee80211_hw *hw, int idx,
1938 struct survey_info *survey)
1939{
1940 struct wl1271 *wl = hw->priv;
1941 struct ieee80211_conf *conf = &hw->conf;
1942
1943 if (idx != 0)
1944 return -ENOENT;
1945
1946 survey->channel = conf->channel;
1947 survey->filled = SURVEY_INFO_NOISE_DBM;
1948 survey->noise = wl->noise;
1949
1950 return 0;
1951}
1952
1953/* can't be const, mac80211 writes to this */
1954static struct ieee80211_rate wl1271_rates[] = {
1955 { .bitrate = 10,
1956 .hw_value = CONF_HW_BIT_RATE_1MBPS,
1957 .hw_value_short = CONF_HW_BIT_RATE_1MBPS, },
1958 { .bitrate = 20,
1959 .hw_value = CONF_HW_BIT_RATE_2MBPS,
1960 .hw_value_short = CONF_HW_BIT_RATE_2MBPS,
1961 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1962 { .bitrate = 55,
1963 .hw_value = CONF_HW_BIT_RATE_5_5MBPS,
1964 .hw_value_short = CONF_HW_BIT_RATE_5_5MBPS,
1965 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1966 { .bitrate = 110,
1967 .hw_value = CONF_HW_BIT_RATE_11MBPS,
1968 .hw_value_short = CONF_HW_BIT_RATE_11MBPS,
1969 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1970 { .bitrate = 60,
1971 .hw_value = CONF_HW_BIT_RATE_6MBPS,
1972 .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
1973 { .bitrate = 90,
1974 .hw_value = CONF_HW_BIT_RATE_9MBPS,
1975 .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
1976 { .bitrate = 120,
1977 .hw_value = CONF_HW_BIT_RATE_12MBPS,
1978 .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
1979 { .bitrate = 180,
1980 .hw_value = CONF_HW_BIT_RATE_18MBPS,
1981 .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
1982 { .bitrate = 240,
1983 .hw_value = CONF_HW_BIT_RATE_24MBPS,
1984 .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
1985 { .bitrate = 360,
1986 .hw_value = CONF_HW_BIT_RATE_36MBPS,
1987 .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
1988 { .bitrate = 480,
1989 .hw_value = CONF_HW_BIT_RATE_48MBPS,
1990 .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
1991 { .bitrate = 540,
1992 .hw_value = CONF_HW_BIT_RATE_54MBPS,
1993 .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
1994};
1995
1996/* can't be const, mac80211 writes to this */
1997static struct ieee80211_channel wl1271_channels[] = {
1998 { .hw_value = 1, .center_freq = 2412, .max_power = 25 },
1999 { .hw_value = 2, .center_freq = 2417, .max_power = 25 },
2000 { .hw_value = 3, .center_freq = 2422, .max_power = 25 },
2001 { .hw_value = 4, .center_freq = 2427, .max_power = 25 },
2002 { .hw_value = 5, .center_freq = 2432, .max_power = 25 },
2003 { .hw_value = 6, .center_freq = 2437, .max_power = 25 },
2004 { .hw_value = 7, .center_freq = 2442, .max_power = 25 },
2005 { .hw_value = 8, .center_freq = 2447, .max_power = 25 },
2006 { .hw_value = 9, .center_freq = 2452, .max_power = 25 },
2007 { .hw_value = 10, .center_freq = 2457, .max_power = 25 },
2008 { .hw_value = 11, .center_freq = 2462, .max_power = 25 },
2009 { .hw_value = 12, .center_freq = 2467, .max_power = 25 },
2010 { .hw_value = 13, .center_freq = 2472, .max_power = 25 },
2011};
2012
2013/* mapping to indexes for wl1271_rates */
2014static const u8 wl1271_rate_to_idx_2ghz[] = {
2015 /* MCS rates are used only with 11n */
2016 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS7 */
2017 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS6 */
2018 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS5 */
2019 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS4 */
2020 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS3 */
2021 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS2 */
2022 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS1 */
2023 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS0 */
2024
2025 11, /* CONF_HW_RXTX_RATE_54 */
2026 10, /* CONF_HW_RXTX_RATE_48 */
2027 9, /* CONF_HW_RXTX_RATE_36 */
2028 8, /* CONF_HW_RXTX_RATE_24 */
2029
2030 /* TI-specific rate */
2031 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_22 */
2032
2033 7, /* CONF_HW_RXTX_RATE_18 */
2034 6, /* CONF_HW_RXTX_RATE_12 */
2035 3, /* CONF_HW_RXTX_RATE_11 */
2036 5, /* CONF_HW_RXTX_RATE_9 */
2037 4, /* CONF_HW_RXTX_RATE_6 */
2038 2, /* CONF_HW_RXTX_RATE_5_5 */
2039 1, /* CONF_HW_RXTX_RATE_2 */
2040 0 /* CONF_HW_RXTX_RATE_1 */
2041};
2042
2043/* can't be const, mac80211 writes to this */
2044static struct ieee80211_supported_band wl1271_band_2ghz = {
2045 .channels = wl1271_channels,
2046 .n_channels = ARRAY_SIZE(wl1271_channels),
2047 .bitrates = wl1271_rates,
2048 .n_bitrates = ARRAY_SIZE(wl1271_rates),
2049};
2050
2051/* 5 GHz data rates for WL1273 */
2052static struct ieee80211_rate wl1271_rates_5ghz[] = {
2053 { .bitrate = 60,
2054 .hw_value = CONF_HW_BIT_RATE_6MBPS,
2055 .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
2056 { .bitrate = 90,
2057 .hw_value = CONF_HW_BIT_RATE_9MBPS,
2058 .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
2059 { .bitrate = 120,
2060 .hw_value = CONF_HW_BIT_RATE_12MBPS,
2061 .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
2062 { .bitrate = 180,
2063 .hw_value = CONF_HW_BIT_RATE_18MBPS,
2064 .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
2065 { .bitrate = 240,
2066 .hw_value = CONF_HW_BIT_RATE_24MBPS,
2067 .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
2068 { .bitrate = 360,
2069 .hw_value = CONF_HW_BIT_RATE_36MBPS,
2070 .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
2071 { .bitrate = 480,
2072 .hw_value = CONF_HW_BIT_RATE_48MBPS,
2073 .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
2074 { .bitrate = 540,
2075 .hw_value = CONF_HW_BIT_RATE_54MBPS,
2076 .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
2077};
2078
2079/* 5 GHz band channels for WL1273 */
2080static struct ieee80211_channel wl1271_channels_5ghz[] = {
2081 { .hw_value = 183, .center_freq = 4915},
2082 { .hw_value = 184, .center_freq = 4920},
2083 { .hw_value = 185, .center_freq = 4925},
2084 { .hw_value = 187, .center_freq = 4935},
2085 { .hw_value = 188, .center_freq = 4940},
2086 { .hw_value = 189, .center_freq = 4945},
2087 { .hw_value = 192, .center_freq = 4960},
2088 { .hw_value = 196, .center_freq = 4980},
2089 { .hw_value = 7, .center_freq = 5035},
2090 { .hw_value = 8, .center_freq = 5040},
2091 { .hw_value = 9, .center_freq = 5045},
2092 { .hw_value = 11, .center_freq = 5055},
2093 { .hw_value = 12, .center_freq = 5060},
2094 { .hw_value = 16, .center_freq = 5080},
2095 { .hw_value = 34, .center_freq = 5170},
2096 { .hw_value = 36, .center_freq = 5180},
2097 { .hw_value = 38, .center_freq = 5190},
2098 { .hw_value = 40, .center_freq = 5200},
2099 { .hw_value = 42, .center_freq = 5210},
2100 { .hw_value = 44, .center_freq = 5220},
2101 { .hw_value = 46, .center_freq = 5230},
2102 { .hw_value = 48, .center_freq = 5240},
2103 { .hw_value = 52, .center_freq = 5260},
2104 { .hw_value = 56, .center_freq = 5280},
2105 { .hw_value = 60, .center_freq = 5300},
2106 { .hw_value = 64, .center_freq = 5320},
2107 { .hw_value = 100, .center_freq = 5500},
2108 { .hw_value = 104, .center_freq = 5520},
2109 { .hw_value = 108, .center_freq = 5540},
2110 { .hw_value = 112, .center_freq = 5560},
2111 { .hw_value = 116, .center_freq = 5580},
2112 { .hw_value = 120, .center_freq = 5600},
2113 { .hw_value = 124, .center_freq = 5620},
2114 { .hw_value = 128, .center_freq = 5640},
2115 { .hw_value = 132, .center_freq = 5660},
2116 { .hw_value = 136, .center_freq = 5680},
2117 { .hw_value = 140, .center_freq = 5700},
2118 { .hw_value = 149, .center_freq = 5745},
2119 { .hw_value = 153, .center_freq = 5765},
2120 { .hw_value = 157, .center_freq = 5785},
2121 { .hw_value = 161, .center_freq = 5805},
2122 { .hw_value = 165, .center_freq = 5825},
2123};
2124
2125/* mapping to indexes for wl1271_rates_5ghz */
2126static const u8 wl1271_rate_to_idx_5ghz[] = {
2127 /* MCS rates are used only with 11n */
2128 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS7 */
2129 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS6 */
2130 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS5 */
2131 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS4 */
2132 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS3 */
2133 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS2 */
2134 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS1 */
2135 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_MCS0 */
2136
2137 7, /* CONF_HW_RXTX_RATE_54 */
2138 6, /* CONF_HW_RXTX_RATE_48 */
2139 5, /* CONF_HW_RXTX_RATE_36 */
2140 4, /* CONF_HW_RXTX_RATE_24 */
2141
2142 /* TI-specific rate */
2143 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_22 */
2144
2145 3, /* CONF_HW_RXTX_RATE_18 */
2146 2, /* CONF_HW_RXTX_RATE_12 */
2147 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_11 */
2148 1, /* CONF_HW_RXTX_RATE_9 */
2149 0, /* CONF_HW_RXTX_RATE_6 */
2150 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_5_5 */
2151 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_2 */
2152 CONF_HW_RXTX_RATE_UNSUPPORTED /* CONF_HW_RXTX_RATE_1 */
2153};
2154
2155static struct ieee80211_supported_band wl1271_band_5ghz = {
2156 .channels = wl1271_channels_5ghz,
2157 .n_channels = ARRAY_SIZE(wl1271_channels_5ghz),
2158 .bitrates = wl1271_rates_5ghz,
2159 .n_bitrates = ARRAY_SIZE(wl1271_rates_5ghz),
2160};
2161
2162static const u8 *wl1271_band_rate_to_idx[] = {
2163 [IEEE80211_BAND_2GHZ] = wl1271_rate_to_idx_2ghz,
2164 [IEEE80211_BAND_5GHZ] = wl1271_rate_to_idx_5ghz
2165};
2166
2167static const struct ieee80211_ops wl1271_ops = {
2168 .start = wl1271_op_start,
2169 .stop = wl1271_op_stop,
2170 .add_interface = wl1271_op_add_interface,
2171 .remove_interface = wl1271_op_remove_interface,
2172 .config = wl1271_op_config,
2173 .prepare_multicast = wl1271_op_prepare_multicast,
2174 .configure_filter = wl1271_op_configure_filter,
2175 .tx = wl1271_op_tx,
2176 .set_key = wl1271_op_set_key,
2177 .hw_scan = wl1271_op_hw_scan,
2178 .bss_info_changed = wl1271_op_bss_info_changed,
2179 .set_rts_threshold = wl1271_op_set_rts_threshold,
2180 .conf_tx = wl1271_op_conf_tx,
2181 .get_tsf = wl1271_op_get_tsf,
2182 .get_survey = wl1271_op_get_survey,
2183 CFG80211_TESTMODE_CMD(wl1271_tm_cmd)
2184};
2185
2186
2187u8 wl1271_rate_to_idx(struct wl1271 *wl, int rate)
2188{
2189 u8 idx;
2190
2191 BUG_ON(wl->band >= sizeof(wl1271_band_rate_to_idx)/sizeof(u8 *));
2192
2193 if (unlikely(rate >= CONF_HW_RXTX_RATE_MAX)) {
2194 wl1271_error("Illegal RX rate from HW: %d", rate);
2195 return 0;
2196 }
2197
2198 idx = wl1271_band_rate_to_idx[wl->band][rate];
2199 if (unlikely(idx == CONF_HW_RXTX_RATE_UNSUPPORTED)) {
2200 wl1271_error("Unsupported RX rate from HW: %d", rate);
2201 return 0;
2202 }
2203
2204 return idx;
2205}
2206
2207static ssize_t wl1271_sysfs_show_bt_coex_state(struct device *dev,
2208 struct device_attribute *attr,
2209 char *buf)
2210{
2211 struct wl1271 *wl = dev_get_drvdata(dev);
2212 ssize_t len;
2213
2214 /* FIXME: what's the maximum length of buf? page size?*/
2215 len = 500;
2216
2217 mutex_lock(&wl->mutex);
2218 len = snprintf(buf, len, "%d\n\n0 - off\n1 - on\n",
2219 wl->sg_enabled);
2220 mutex_unlock(&wl->mutex);
2221
2222 return len;
2223
2224}
2225
2226static ssize_t wl1271_sysfs_store_bt_coex_state(struct device *dev,
2227 struct device_attribute *attr,
2228 const char *buf, size_t count)
2229{
2230 struct wl1271 *wl = dev_get_drvdata(dev);
2231 unsigned long res;
2232 int ret;
2233
2234 ret = strict_strtoul(buf, 10, &res);
2235
2236 if (ret < 0) {
2237 wl1271_warning("incorrect value written to bt_coex_mode");
2238 return count;
2239 }
2240
2241 mutex_lock(&wl->mutex);
2242
2243 res = !!res;
2244
2245 if (res == wl->sg_enabled)
2246 goto out;
2247
2248 wl->sg_enabled = res;
2249
2250 if (wl->state == WL1271_STATE_OFF)
2251 goto out;
2252
2253 ret = wl1271_ps_elp_wakeup(wl, false);
2254 if (ret < 0)
2255 goto out;
2256
2257 wl1271_acx_sg_enable(wl, wl->sg_enabled);
2258 wl1271_ps_elp_sleep(wl);
2259
2260 out:
2261 mutex_unlock(&wl->mutex);
2262 return count;
2263}
2264
2265static DEVICE_ATTR(bt_coex_state, S_IRUGO | S_IWUSR,
2266 wl1271_sysfs_show_bt_coex_state,
2267 wl1271_sysfs_store_bt_coex_state);
2268
2269static ssize_t wl1271_sysfs_show_hw_pg_ver(struct device *dev,
2270 struct device_attribute *attr,
2271 char *buf)
2272{
2273 struct wl1271 *wl = dev_get_drvdata(dev);
2274 ssize_t len;
2275
2276 /* FIXME: what's the maximum length of buf? page size?*/
2277 len = 500;
2278
2279 mutex_lock(&wl->mutex);
2280 if (wl->hw_pg_ver >= 0)
2281 len = snprintf(buf, len, "%d\n", wl->hw_pg_ver);
2282 else
2283 len = snprintf(buf, len, "n/a\n");
2284 mutex_unlock(&wl->mutex);
2285
2286 return len;
2287}
2288
2289static DEVICE_ATTR(hw_pg_ver, S_IRUGO | S_IWUSR,
2290 wl1271_sysfs_show_hw_pg_ver, NULL);
2291
2292int wl1271_register_hw(struct wl1271 *wl)
2293{
2294 int ret;
2295
2296 if (wl->mac80211_registered)
2297 return 0;
2298
2299 SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
2300
2301 ret = ieee80211_register_hw(wl->hw);
2302 if (ret < 0) {
2303 wl1271_error("unable to register mac80211 hw: %d", ret);
2304 return ret;
2305 }
2306
2307 wl->mac80211_registered = true;
2308
2309 wl1271_notice("loaded");
2310
2311 return 0;
2312}
2313EXPORT_SYMBOL_GPL(wl1271_register_hw);
2314
2315void wl1271_unregister_hw(struct wl1271 *wl)
2316{
2317 ieee80211_unregister_hw(wl->hw);
2318 wl->mac80211_registered = false;
2319
2320}
2321EXPORT_SYMBOL_GPL(wl1271_unregister_hw);
2322
2323int wl1271_init_ieee80211(struct wl1271 *wl)
2324{
2325 /* The tx descriptor buffer and the TKIP space. */
2326 wl->hw->extra_tx_headroom = WL1271_TKIP_IV_SPACE +
2327 sizeof(struct wl1271_tx_hw_descr);
2328
2329 /* unit us */
2330 /* FIXME: find a proper value */
2331 wl->hw->channel_change_time = 10000;
2332 wl->hw->max_listen_interval = wl->conf.conn.max_listen_interval;
2333
2334 wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
2335 IEEE80211_HW_BEACON_FILTER |
2336 IEEE80211_HW_SUPPORTS_PS |
2337 IEEE80211_HW_SUPPORTS_UAPSD |
2338 IEEE80211_HW_HAS_RATE_CONTROL |
2339 IEEE80211_HW_CONNECTION_MONITOR |
2340 IEEE80211_HW_SUPPORTS_CQM_RSSI;
2341
2342 wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
2343 BIT(NL80211_IFTYPE_ADHOC);
2344 wl->hw->wiphy->max_scan_ssids = 1;
2345 wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl1271_band_2ghz;
2346
2347 if (wl1271_11a_enabled())
2348 wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &wl1271_band_5ghz;
2349
2350 wl->hw->queues = 4;
2351 wl->hw->max_rates = 1;
2352
2353 SET_IEEE80211_DEV(wl->hw, wl1271_wl_to_dev(wl));
2354
2355 return 0;
2356}
2357EXPORT_SYMBOL_GPL(wl1271_init_ieee80211);
2358
2359#define WL1271_DEFAULT_CHANNEL 0
2360
2361struct ieee80211_hw *wl1271_alloc_hw(void)
2362{
2363 struct ieee80211_hw *hw;
2364 struct platform_device *plat_dev = NULL;
2365 struct wl1271 *wl;
2366 int i, ret;
2367
2368 hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops);
2369 if (!hw) {
2370 wl1271_error("could not alloc ieee80211_hw");
2371 ret = -ENOMEM;
2372 goto err_hw_alloc;
2373 }
2374
2375 plat_dev = kmemdup(&wl1271_device, sizeof(wl1271_device), GFP_KERNEL);
2376 if (!plat_dev) {
2377 wl1271_error("could not allocate platform_device");
2378 ret = -ENOMEM;
2379 goto err_plat_alloc;
2380 }
2381
2382 wl = hw->priv;
2383 memset(wl, 0, sizeof(*wl));
2384
2385 INIT_LIST_HEAD(&wl->list);
2386
2387 wl->hw = hw;
2388 wl->plat_dev = plat_dev;
2389
2390 skb_queue_head_init(&wl->tx_queue);
2391
2392 INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work);
2393 INIT_DELAYED_WORK(&wl->pspoll_work, wl1271_pspoll_work);
2394 wl->channel = WL1271_DEFAULT_CHANNEL;
2395 wl->beacon_int = WL1271_DEFAULT_BEACON_INT;
2396 wl->default_key = 0;
2397 wl->rx_counter = 0;
2398 wl->rx_config = WL1271_DEFAULT_RX_CONFIG;
2399 wl->rx_filter = WL1271_DEFAULT_RX_FILTER;
2400 wl->psm_entry_retry = 0;
2401 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
2402 wl->basic_rate_set = CONF_TX_RATE_MASK_BASIC;
2403 wl->basic_rate = CONF_TX_RATE_MASK_BASIC;
2404 wl->rate_set = CONF_TX_RATE_MASK_BASIC;
2405 wl->sta_rate_set = 0;
2406 wl->band = IEEE80211_BAND_2GHZ;
2407 wl->vif = NULL;
2408 wl->flags = 0;
2409 wl->sg_enabled = true;
2410 wl->hw_pg_ver = -1;
2411
2412 for (i = 0; i < ACX_TX_DESCRIPTORS; i++)
2413 wl->tx_frames[i] = NULL;
2414
2415 spin_lock_init(&wl->wl_lock);
2416
2417 wl->state = WL1271_STATE_OFF;
2418 mutex_init(&wl->mutex);
2419
2420 /* Apply default driver configuration. */
2421 wl1271_conf_init(wl);
2422
2423 wl1271_debugfs_init(wl);
2424
2425 /* Register platform device */
2426 ret = platform_device_register(wl->plat_dev);
2427 if (ret) {
2428 wl1271_error("couldn't register platform device");
2429 goto err_hw;
2430 }
2431 dev_set_drvdata(&wl->plat_dev->dev, wl);
2432
2433 /* Create sysfs file to control bt coex state */
2434 ret = device_create_file(&wl->plat_dev->dev, &dev_attr_bt_coex_state);
2435 if (ret < 0) {
2436 wl1271_error("failed to create sysfs file bt_coex_state");
2437 goto err_platform;
2438 }
2439
2440 /* Create sysfs file to get HW PG version */
2441 ret = device_create_file(&wl->plat_dev->dev, &dev_attr_hw_pg_ver);
2442 if (ret < 0) {
2443 wl1271_error("failed to create sysfs file hw_pg_ver");
2444 goto err_bt_coex_state;
2445 }
2446
2447 return hw;
2448
2449err_bt_coex_state:
2450 device_remove_file(&wl->plat_dev->dev, &dev_attr_bt_coex_state);
2451
2452err_platform:
2453 platform_device_unregister(wl->plat_dev);
2454
2455err_hw:
2456 wl1271_debugfs_exit(wl);
2457 kfree(plat_dev);
2458
2459err_plat_alloc:
2460 ieee80211_free_hw(hw);
2461
2462err_hw_alloc:
2463
2464 return ERR_PTR(ret);
2465}
2466EXPORT_SYMBOL_GPL(wl1271_alloc_hw);
2467
2468int wl1271_free_hw(struct wl1271 *wl)
2469{
2470 platform_device_unregister(wl->plat_dev);
2471 kfree(wl->plat_dev);
2472
2473 wl1271_debugfs_exit(wl);
2474
2475 vfree(wl->fw);
2476 wl->fw = NULL;
2477 kfree(wl->nvs);
2478 wl->nvs = NULL;
2479
2480 kfree(wl->fw_status);
2481 kfree(wl->tx_res_if);
2482
2483 ieee80211_free_hw(wl->hw);
2484
2485 return 0;
2486}
2487EXPORT_SYMBOL_GPL(wl1271_free_hw);
2488
2489MODULE_LICENSE("GPL");
2490MODULE_AUTHOR("Luciano Coelho <luciano.coelho@nokia.com>");
2491MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");
diff --git a/drivers/net/wireless/wl12xx/wl1271_rx.c b/drivers/net/wireless/wl12xx/wl1271_rx.c
deleted file mode 100644
index 019aa79cd9df..000000000000
--- a/drivers/net/wireless/wl12xx/wl1271_rx.c
+++ /dev/null
@@ -1,156 +0,0 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 *
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include <linux/gfp.h>
25
26#include "wl1271.h"
27#include "wl1271_acx.h"
28#include "wl1271_reg.h"
29#include "wl1271_rx.h"
30#include "wl1271_io.h"
31
32static u8 wl1271_rx_get_mem_block(struct wl1271_fw_status *status,
33 u32 drv_rx_counter)
34{
35 return le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]) &
36 RX_MEM_BLOCK_MASK;
37}
38
39static u32 wl1271_rx_get_buf_size(struct wl1271_fw_status *status,
40 u32 drv_rx_counter)
41{
42 return (le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]) &
43 RX_BUF_SIZE_MASK) >> RX_BUF_SIZE_SHIFT_DIV;
44}
45
46static void wl1271_rx_status(struct wl1271 *wl,
47 struct wl1271_rx_descriptor *desc,
48 struct ieee80211_rx_status *status,
49 u8 beacon)
50{
51 memset(status, 0, sizeof(struct ieee80211_rx_status));
52
53 status->band = wl->band;
54 status->rate_idx = wl1271_rate_to_idx(wl, desc->rate);
55
56 status->signal = desc->rssi;
57
58 /*
59 * FIXME: In wl1251, the SNR should be divided by two. In wl1271 we
60 * need to divide by two for now, but TI has been discussing about
61 * changing it. This needs to be rechecked.
62 */
63 wl->noise = desc->rssi - (desc->snr >> 1);
64
65 status->freq = ieee80211_channel_to_frequency(desc->channel);
66
67 if (desc->flags & WL1271_RX_DESC_ENCRYPT_MASK) {
68 status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED;
69
70 if (likely(!(desc->status & WL1271_RX_DESC_DECRYPT_FAIL)))
71 status->flag |= RX_FLAG_DECRYPTED;
72 if (unlikely(desc->status & WL1271_RX_DESC_MIC_FAIL))
73 status->flag |= RX_FLAG_MMIC_ERROR;
74 }
75}
76
77static void wl1271_rx_handle_data(struct wl1271 *wl, u32 length)
78{
79 struct ieee80211_rx_status rx_status;
80 struct wl1271_rx_descriptor *desc;
81 struct sk_buff *skb;
82 u16 *fc;
83 u8 *buf;
84 u8 beacon = 0;
85
86 /*
87 * In PLT mode we seem to get frames and mac80211 warns about them,
88 * workaround this by not retrieving them at all.
89 */
90 if (unlikely(wl->state == WL1271_STATE_PLT))
91 return;
92
93 skb = __dev_alloc_skb(length, GFP_KERNEL);
94 if (!skb) {
95 wl1271_error("Couldn't allocate RX frame");
96 return;
97 }
98
99 buf = skb_put(skb, length);
100 wl1271_read(wl, WL1271_SLV_MEM_DATA, buf, length, true);
101
102 /* the data read starts with the descriptor */
103 desc = (struct wl1271_rx_descriptor *) buf;
104
105 /* now we pull the descriptor out of the buffer */
106 skb_pull(skb, sizeof(*desc));
107
108 fc = (u16 *)skb->data;
109 if ((*fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON)
110 beacon = 1;
111
112 wl1271_rx_status(wl, desc, &rx_status, beacon);
113
114 wl1271_debug(DEBUG_RX, "rx skb 0x%p: %d B %s", skb, skb->len,
115 beacon ? "beacon" : "");
116
117 skb_trim(skb, skb->len - desc->pad_len);
118
119 memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
120 ieee80211_rx_ni(wl->hw, skb);
121}
122
123void wl1271_rx(struct wl1271 *wl, struct wl1271_fw_status *status)
124{
125 struct wl1271_acx_mem_map *wl_mem_map = wl->target_mem_map;
126 u32 buf_size;
127 u32 fw_rx_counter = status->fw_rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
128 u32 drv_rx_counter = wl->rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
129 u32 mem_block;
130
131 while (drv_rx_counter != fw_rx_counter) {
132 mem_block = wl1271_rx_get_mem_block(status, drv_rx_counter);
133 buf_size = wl1271_rx_get_buf_size(status, drv_rx_counter);
134
135 if (buf_size == 0) {
136 wl1271_warning("received empty data");
137 break;
138 }
139
140 wl->rx_mem_pool_addr.addr = (mem_block << 8) +
141 le32_to_cpu(wl_mem_map->packet_memory_pool_start);
142 wl->rx_mem_pool_addr.addr_extra =
143 wl->rx_mem_pool_addr.addr + 4;
144
145 /* Choose the block we want to read */
146 wl1271_write(wl, WL1271_SLV_REG_DATA, &wl->rx_mem_pool_addr,
147 sizeof(wl->rx_mem_pool_addr), false);
148
149 wl1271_rx_handle_data(wl, buf_size);
150
151 wl->rx_counter++;
152 drv_rx_counter = wl->rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
153 }
154
155 wl1271_write32(wl, RX_DRIVER_COUNTER_ADDRESS, wl->rx_counter);
156}
diff --git a/drivers/net/wireless/wl12xx/wl1271_scan.c b/drivers/net/wireless/wl12xx/wl1271_scan.c
deleted file mode 100644
index fec43eed8c55..000000000000
--- a/drivers/net/wireless/wl12xx/wl1271_scan.c
+++ /dev/null
@@ -1,257 +0,0 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2009-2010 Nokia Corporation
5 *
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include <linux/ieee80211.h>
25
26#include "wl1271.h"
27#include "wl1271_cmd.h"
28#include "wl1271_scan.h"
29#include "wl1271_acx.h"
30
31static int wl1271_get_scan_channels(struct wl1271 *wl,
32 struct cfg80211_scan_request *req,
33 struct basic_scan_channel_params *channels,
34 enum ieee80211_band band, bool passive)
35{
36 int i, j;
37 u32 flags;
38
39 for (i = 0, j = 0;
40 i < req->n_channels && j < WL1271_SCAN_MAX_CHANNELS;
41 i++) {
42
43 flags = req->channels[i]->flags;
44
45 if (!wl->scan.scanned_ch[i] &&
46 !(flags & IEEE80211_CHAN_DISABLED) &&
47 ((!!(flags & IEEE80211_CHAN_PASSIVE_SCAN)) == passive) &&
48 (req->channels[i]->band == band)) {
49
50 wl1271_debug(DEBUG_SCAN, "band %d, center_freq %d ",
51 req->channels[i]->band,
52 req->channels[i]->center_freq);
53 wl1271_debug(DEBUG_SCAN, "hw_value %d, flags %X",
54 req->channels[i]->hw_value,
55 req->channels[i]->flags);
56 wl1271_debug(DEBUG_SCAN,
57 "max_antenna_gain %d, max_power %d",
58 req->channels[i]->max_antenna_gain,
59 req->channels[i]->max_power);
60 wl1271_debug(DEBUG_SCAN, "beacon_found %d",
61 req->channels[i]->beacon_found);
62
63 channels[j].min_duration =
64 cpu_to_le32(WL1271_SCAN_CHAN_MIN_DURATION);
65 channels[j].max_duration =
66 cpu_to_le32(WL1271_SCAN_CHAN_MAX_DURATION);
67 channels[j].early_termination = 0;
68 channels[j].tx_power_att = req->channels[i]->max_power;
69 channels[j].channel = req->channels[i]->hw_value;
70
71 memset(&channels[j].bssid_lsb, 0xff, 4);
72 memset(&channels[j].bssid_msb, 0xff, 2);
73
74 /* Mark the channels we already used */
75 wl->scan.scanned_ch[i] = true;
76
77 j++;
78 }
79 }
80
81 return j;
82}
83
84#define WL1271_NOTHING_TO_SCAN 1
85
86static int wl1271_scan_send(struct wl1271 *wl, enum ieee80211_band band,
87 bool passive, u32 basic_rate)
88{
89 struct wl1271_cmd_scan *cmd;
90 struct wl1271_cmd_trigger_scan_to *trigger;
91 int ret;
92 u16 scan_options = 0;
93
94 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
95 trigger = kzalloc(sizeof(*trigger), GFP_KERNEL);
96 if (!cmd || !trigger) {
97 ret = -ENOMEM;
98 goto out;
99 }
100
101 /* We always use high priority scans */
102 scan_options = WL1271_SCAN_OPT_PRIORITY_HIGH;
103 if(passive)
104 scan_options |= WL1271_SCAN_OPT_PASSIVE;
105 cmd->params.scan_options = cpu_to_le16(scan_options);
106
107 cmd->params.n_ch = wl1271_get_scan_channels(wl, wl->scan.req,
108 cmd->channels,
109 band, passive);
110 if (cmd->params.n_ch == 0) {
111 ret = WL1271_NOTHING_TO_SCAN;
112 goto out;
113 }
114
115 cmd->params.tx_rate = cpu_to_le32(basic_rate);
116 cmd->params.rx_config_options = cpu_to_le32(CFG_RX_ALL_GOOD);
117 cmd->params.rx_filter_options =
118 cpu_to_le32(CFG_RX_PRSP_EN | CFG_RX_MGMT_EN | CFG_RX_BCN_EN);
119
120 cmd->params.n_probe_reqs = WL1271_SCAN_PROBE_REQS;
121 cmd->params.tx_rate = cpu_to_le32(basic_rate);
122 cmd->params.tid_trigger = 0;
123 cmd->params.scan_tag = WL1271_SCAN_DEFAULT_TAG;
124
125 if (band == IEEE80211_BAND_2GHZ)
126 cmd->params.band = WL1271_SCAN_BAND_2_4_GHZ;
127 else
128 cmd->params.band = WL1271_SCAN_BAND_5_GHZ;
129
130 if (wl->scan.ssid_len && wl->scan.ssid) {
131 cmd->params.ssid_len = wl->scan.ssid_len;
132 memcpy(cmd->params.ssid, wl->scan.ssid, wl->scan.ssid_len);
133 }
134
135 ret = wl1271_cmd_build_probe_req(wl, wl->scan.ssid, wl->scan.ssid_len,
136 wl->scan.req->ie, wl->scan.req->ie_len,
137 band);
138 if (ret < 0) {
139 wl1271_error("PROBE request template failed");
140 goto out;
141 }
142
143 /* disable the timeout */
144 trigger->timeout = 0;
145 ret = wl1271_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger,
146 sizeof(*trigger), 0);
147 if (ret < 0) {
148 wl1271_error("trigger scan to failed for hw scan");
149 goto out;
150 }
151
152 wl1271_dump(DEBUG_SCAN, "SCAN: ", cmd, sizeof(*cmd));
153
154 ret = wl1271_cmd_send(wl, CMD_SCAN, cmd, sizeof(*cmd), 0);
155 if (ret < 0) {
156 wl1271_error("SCAN failed");
157 goto out;
158 }
159
160out:
161 kfree(cmd);
162 kfree(trigger);
163 return ret;
164}
165
166void wl1271_scan_stm(struct wl1271 *wl)
167{
168 int ret;
169
170 switch (wl->scan.state) {
171 case WL1271_SCAN_STATE_IDLE:
172 break;
173
174 case WL1271_SCAN_STATE_2GHZ_ACTIVE:
175 ret = wl1271_scan_send(wl, IEEE80211_BAND_2GHZ, false,
176 wl->conf.tx.basic_rate);
177 if (ret == WL1271_NOTHING_TO_SCAN) {
178 wl->scan.state = WL1271_SCAN_STATE_2GHZ_PASSIVE;
179 wl1271_scan_stm(wl);
180 }
181
182 break;
183
184 case WL1271_SCAN_STATE_2GHZ_PASSIVE:
185 ret = wl1271_scan_send(wl, IEEE80211_BAND_2GHZ, true,
186 wl->conf.tx.basic_rate);
187 if (ret == WL1271_NOTHING_TO_SCAN) {
188 if (wl1271_11a_enabled())
189 wl->scan.state = WL1271_SCAN_STATE_5GHZ_ACTIVE;
190 else
191 wl->scan.state = WL1271_SCAN_STATE_DONE;
192 wl1271_scan_stm(wl);
193 }
194
195 break;
196
197 case WL1271_SCAN_STATE_5GHZ_ACTIVE:
198 ret = wl1271_scan_send(wl, IEEE80211_BAND_5GHZ, false,
199 wl->conf.tx.basic_rate_5);
200 if (ret == WL1271_NOTHING_TO_SCAN) {
201 wl->scan.state = WL1271_SCAN_STATE_5GHZ_PASSIVE;
202 wl1271_scan_stm(wl);
203 }
204
205 break;
206
207 case WL1271_SCAN_STATE_5GHZ_PASSIVE:
208 ret = wl1271_scan_send(wl, IEEE80211_BAND_5GHZ, true,
209 wl->conf.tx.basic_rate_5);
210 if (ret == WL1271_NOTHING_TO_SCAN) {
211 wl->scan.state = WL1271_SCAN_STATE_DONE;
212 wl1271_scan_stm(wl);
213 }
214
215 break;
216
217 case WL1271_SCAN_STATE_DONE:
218 mutex_unlock(&wl->mutex);
219 ieee80211_scan_completed(wl->hw, false);
220 mutex_lock(&wl->mutex);
221
222 kfree(wl->scan.scanned_ch);
223 wl->scan.scanned_ch = NULL;
224
225 wl->scan.state = WL1271_SCAN_STATE_IDLE;
226 break;
227
228 default:
229 wl1271_error("invalid scan state");
230 break;
231 }
232}
233
234int wl1271_scan(struct wl1271 *wl, const u8 *ssid, size_t ssid_len,
235 struct cfg80211_scan_request *req)
236{
237 if (wl->scan.state != WL1271_SCAN_STATE_IDLE)
238 return -EBUSY;
239
240 wl->scan.state = WL1271_SCAN_STATE_2GHZ_ACTIVE;
241
242 if (ssid_len && ssid) {
243 wl->scan.ssid_len = ssid_len;
244 memcpy(wl->scan.ssid, ssid, ssid_len);
245 } else {
246 wl->scan.ssid_len = 0;
247 }
248
249 wl->scan.req = req;
250
251 wl->scan.scanned_ch = kzalloc(req->n_channels *
252 sizeof(*wl->scan.scanned_ch),
253 GFP_KERNEL);
254 wl1271_scan_stm(wl);
255
256 return 0;
257}
diff --git a/drivers/net/wireless/wl12xx/wl1271_tx.c b/drivers/net/wireless/wl12xx/wl1271_tx.c
deleted file mode 100644
index c592cc2e9fe8..000000000000
--- a/drivers/net/wireless/wl12xx/wl1271_tx.c
+++ /dev/null
@@ -1,464 +0,0 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 *
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include <linux/kernel.h>
25#include <linux/module.h>
26
27#include "wl1271.h"
28#include "wl1271_io.h"
29#include "wl1271_reg.h"
30#include "wl1271_ps.h"
31#include "wl1271_tx.h"
32
33static int wl1271_tx_id(struct wl1271 *wl, struct sk_buff *skb)
34{
35 int i;
36 for (i = 0; i < ACX_TX_DESCRIPTORS; i++)
37 if (wl->tx_frames[i] == NULL) {
38 wl->tx_frames[i] = skb;
39 wl->tx_frames_cnt++;
40 return i;
41 }
42
43 return -EBUSY;
44}
45
46static int wl1271_tx_allocate(struct wl1271 *wl, struct sk_buff *skb, u32 extra)
47{
48 struct wl1271_tx_hw_descr *desc;
49 u32 total_len = skb->len + sizeof(struct wl1271_tx_hw_descr) + extra;
50 u32 total_blocks;
51 int id, ret = -EBUSY;
52
53 /* allocate free identifier for the packet */
54 id = wl1271_tx_id(wl, skb);
55 if (id < 0)
56 return id;
57
58 /* approximate the number of blocks required for this packet
59 in the firmware */
60 total_blocks = total_len + TX_HW_BLOCK_SIZE - 1;
61 total_blocks = total_blocks / TX_HW_BLOCK_SIZE + TX_HW_BLOCK_SPARE;
62 if (total_blocks <= wl->tx_blocks_available) {
63 desc = (struct wl1271_tx_hw_descr *)skb_push(
64 skb, total_len - skb->len);
65
66 desc->extra_mem_blocks = TX_HW_BLOCK_SPARE;
67 desc->total_mem_blocks = total_blocks;
68 desc->id = id;
69
70 wl->tx_blocks_available -= total_blocks;
71
72 ret = 0;
73
74 wl1271_debug(DEBUG_TX,
75 "tx_allocate: size: %d, blocks: %d, id: %d",
76 total_len, total_blocks, id);
77 } else {
78 wl->tx_frames[id] = NULL;
79 wl->tx_frames_cnt--;
80 }
81
82 return ret;
83}
84
85static int wl1271_tx_fill_hdr(struct wl1271 *wl, struct sk_buff *skb,
86 u32 extra, struct ieee80211_tx_info *control)
87{
88 struct timespec ts;
89 struct wl1271_tx_hw_descr *desc;
90 int pad, ac;
91 s64 hosttime;
92 u16 tx_attr;
93
94 desc = (struct wl1271_tx_hw_descr *) skb->data;
95
96 /* relocate space for security header */
97 if (extra) {
98 void *framestart = skb->data + sizeof(*desc);
99 u16 fc = *(u16 *)(framestart + extra);
100 int hdrlen = ieee80211_hdrlen(cpu_to_le16(fc));
101 memmove(framestart, framestart + extra, hdrlen);
102 }
103
104 /* configure packet life time */
105 getnstimeofday(&ts);
106 hosttime = (timespec_to_ns(&ts) >> 10);
107 desc->start_time = cpu_to_le32(hosttime - wl->time_offset);
108 desc->life_time = cpu_to_le16(TX_HW_MGMT_PKT_LIFETIME_TU);
109
110 /* configure the tx attributes */
111 tx_attr = wl->session_counter << TX_HW_ATTR_OFST_SESSION_COUNTER;
112
113 /* queue */
114 ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
115 desc->tid = wl1271_tx_ac_to_tid(ac);
116
117 desc->aid = TX_HW_DEFAULT_AID;
118 desc->reserved = 0;
119
120 /* align the length (and store in terms of words) */
121 pad = WL1271_TX_ALIGN(skb->len);
122 desc->length = cpu_to_le16(pad >> 2);
123
124 /* calculate number of padding bytes */
125 pad = pad - skb->len;
126 tx_attr |= pad << TX_HW_ATTR_OFST_LAST_WORD_PAD;
127
128 /* if the packets are destined for AP (have a STA entry) send them
129 with AP rate policies, otherwise use default basic rates */
130 if (control->control.sta)
131 tx_attr |= ACX_TX_AP_FULL_RATE << TX_HW_ATTR_OFST_RATE_POLICY;
132
133 desc->tx_attr = cpu_to_le16(tx_attr);
134
135 wl1271_debug(DEBUG_TX, "tx_fill_hdr: pad: %d", pad);
136 return 0;
137}
138
139static int wl1271_tx_send_packet(struct wl1271 *wl, struct sk_buff *skb,
140 struct ieee80211_tx_info *control)
141{
142
143 struct wl1271_tx_hw_descr *desc;
144 int len;
145
146 /* FIXME: This is a workaround for getting non-aligned packets.
147 This happens at least with EAPOL packets from the user space.
148 Our DMA requires packets to be aligned on a 4-byte boundary.
149 */
150 if (unlikely((long)skb->data & 0x03)) {
151 int offset = (4 - (long)skb->data) & 0x03;
152 wl1271_debug(DEBUG_TX, "skb offset %d", offset);
153
154 /* check whether the current skb can be used */
155 if (!skb_cloned(skb) && (skb_tailroom(skb) >= offset)) {
156 unsigned char *src = skb->data;
157
158 /* align the buffer on a 4-byte boundary */
159 skb_reserve(skb, offset);
160 memmove(skb->data, src, skb->len);
161 } else {
162 wl1271_info("No handler, fixme!");
163 return -EINVAL;
164 }
165 }
166
167 len = WL1271_TX_ALIGN(skb->len);
168
169 /* perform a fixed address block write with the packet */
170 wl1271_write(wl, WL1271_SLV_MEM_DATA, skb->data, len, true);
171
172 /* write packet new counter into the write access register */
173 wl->tx_packets_count++;
174
175 desc = (struct wl1271_tx_hw_descr *) skb->data;
176 wl1271_debug(DEBUG_TX, "tx id %u skb 0x%p payload %u (%u words)",
177 desc->id, skb, len, desc->length);
178
179 return 0;
180}
181
182/* caller must hold wl->mutex */
183static int wl1271_tx_frame(struct wl1271 *wl, struct sk_buff *skb)
184{
185 struct ieee80211_tx_info *info;
186 u32 extra = 0;
187 int ret = 0;
188 u8 idx;
189
190 if (!skb)
191 return -EINVAL;
192
193 info = IEEE80211_SKB_CB(skb);
194
195 if (info->control.hw_key &&
196 info->control.hw_key->alg == ALG_TKIP)
197 extra = WL1271_TKIP_IV_SPACE;
198
199 if (info->control.hw_key) {
200 idx = info->control.hw_key->hw_key_idx;
201
202 /* FIXME: do we have to do this if we're not using WEP? */
203 if (unlikely(wl->default_key != idx)) {
204 ret = wl1271_cmd_set_default_wep_key(wl, idx);
205 if (ret < 0)
206 return ret;
207 wl->default_key = idx;
208 }
209 }
210
211 ret = wl1271_tx_allocate(wl, skb, extra);
212 if (ret < 0)
213 return ret;
214
215 ret = wl1271_tx_fill_hdr(wl, skb, extra, info);
216 if (ret < 0)
217 return ret;
218
219 ret = wl1271_tx_send_packet(wl, skb, info);
220 if (ret < 0)
221 return ret;
222
223 return ret;
224}
225
226u32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set)
227{
228 struct ieee80211_supported_band *band;
229 u32 enabled_rates = 0;
230 int bit;
231
232 band = wl->hw->wiphy->bands[wl->band];
233 for (bit = 0; bit < band->n_bitrates; bit++) {
234 if (rate_set & 0x1)
235 enabled_rates |= band->bitrates[bit].hw_value;
236 rate_set >>= 1;
237 }
238
239 return enabled_rates;
240}
241
242void wl1271_tx_work(struct work_struct *work)
243{
244 struct wl1271 *wl = container_of(work, struct wl1271, tx_work);
245 struct sk_buff *skb;
246 bool woken_up = false;
247 u32 sta_rates = 0;
248 u32 prev_tx_packets_count;
249 int ret;
250
251 /* check if the rates supported by the AP have changed */
252 if (unlikely(test_and_clear_bit(WL1271_FLAG_STA_RATES_CHANGED,
253 &wl->flags))) {
254 unsigned long flags;
255 spin_lock_irqsave(&wl->wl_lock, flags);
256 sta_rates = wl->sta_rate_set;
257 spin_unlock_irqrestore(&wl->wl_lock, flags);
258 }
259
260 mutex_lock(&wl->mutex);
261
262 if (unlikely(wl->state == WL1271_STATE_OFF))
263 goto out;
264
265 prev_tx_packets_count = wl->tx_packets_count;
266
267 /* if rates have changed, re-configure the rate policy */
268 if (unlikely(sta_rates)) {
269 wl->rate_set = wl1271_tx_enabled_rates_get(wl, sta_rates);
270 wl1271_acx_rate_policies(wl);
271 }
272
273 while ((skb = skb_dequeue(&wl->tx_queue))) {
274 if (!woken_up) {
275 ret = wl1271_ps_elp_wakeup(wl, false);
276 if (ret < 0)
277 goto out_ack;
278 woken_up = true;
279 }
280
281 ret = wl1271_tx_frame(wl, skb);
282 if (ret == -EBUSY) {
283 /* firmware buffer is full, lets stop transmitting. */
284 skb_queue_head(&wl->tx_queue, skb);
285 goto out_ack;
286 } else if (ret < 0) {
287 dev_kfree_skb(skb);
288 goto out_ack;
289 }
290 }
291
292out_ack:
293 /* interrupt the firmware with the new packets */
294 if (prev_tx_packets_count != wl->tx_packets_count)
295 wl1271_write32(wl, WL1271_HOST_WR_ACCESS, wl->tx_packets_count);
296
297out:
298 if (woken_up)
299 wl1271_ps_elp_sleep(wl);
300
301 mutex_unlock(&wl->mutex);
302}
303
304static void wl1271_tx_complete_packet(struct wl1271 *wl,
305 struct wl1271_tx_hw_res_descr *result)
306{
307 struct ieee80211_tx_info *info;
308 struct sk_buff *skb;
309 int id = result->id;
310 int rate = -1;
311 u8 retries = 0;
312
313 /* check for id legality */
314 if (unlikely(id >= ACX_TX_DESCRIPTORS || wl->tx_frames[id] == NULL)) {
315 wl1271_warning("TX result illegal id: %d", id);
316 return;
317 }
318
319 skb = wl->tx_frames[id];
320 info = IEEE80211_SKB_CB(skb);
321
322 /* update the TX status info */
323 if (result->status == TX_SUCCESS) {
324 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
325 info->flags |= IEEE80211_TX_STAT_ACK;
326 rate = wl1271_rate_to_idx(wl, result->rate_class_index);
327 retries = result->ack_failures;
328 } else if (result->status == TX_RETRY_EXCEEDED) {
329 wl->stats.excessive_retries++;
330 retries = result->ack_failures;
331 }
332
333 info->status.rates[0].idx = rate;
334 info->status.rates[0].count = retries;
335 info->status.rates[0].flags = 0;
336 info->status.ack_signal = -1;
337
338 wl->stats.retry_count += result->ack_failures;
339
340 /* update security sequence number */
341 wl->tx_security_seq += (result->lsb_security_sequence_number -
342 wl->tx_security_last_seq);
343 wl->tx_security_last_seq = result->lsb_security_sequence_number;
344
345 /* remove private header from packet */
346 skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
347
348 /* remove TKIP header space if present */
349 if (info->control.hw_key &&
350 info->control.hw_key->alg == ALG_TKIP) {
351 int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
352 memmove(skb->data + WL1271_TKIP_IV_SPACE, skb->data, hdrlen);
353 skb_pull(skb, WL1271_TKIP_IV_SPACE);
354 }
355
356 wl1271_debug(DEBUG_TX, "tx status id %u skb 0x%p failures %u rate 0x%x"
357 " status 0x%x",
358 result->id, skb, result->ack_failures,
359 result->rate_class_index, result->status);
360
361 /* return the packet to the stack */
362 ieee80211_tx_status(wl->hw, skb);
363 wl->tx_frames[result->id] = NULL;
364 wl->tx_frames_cnt--;
365}
366
367/* Called upon reception of a TX complete interrupt */
368void wl1271_tx_complete(struct wl1271 *wl)
369{
370 struct wl1271_acx_mem_map *memmap =
371 (struct wl1271_acx_mem_map *)wl->target_mem_map;
372 u32 count, fw_counter;
373 u32 i;
374
375 /* read the tx results from the chipset */
376 wl1271_read(wl, le32_to_cpu(memmap->tx_result),
377 wl->tx_res_if, sizeof(*wl->tx_res_if), false);
378 fw_counter = le32_to_cpu(wl->tx_res_if->tx_result_fw_counter);
379
380 /* write host counter to chipset (to ack) */
381 wl1271_write32(wl, le32_to_cpu(memmap->tx_result) +
382 offsetof(struct wl1271_tx_hw_res_if,
383 tx_result_host_counter), fw_counter);
384
385 count = fw_counter - wl->tx_results_count;
386 wl1271_debug(DEBUG_TX, "tx_complete received, packets: %d", count);
387
388 /* verify that the result buffer is not getting overrun */
389 if (unlikely(count > TX_HW_RESULT_QUEUE_LEN))
390 wl1271_warning("TX result overflow from chipset: %d", count);
391
392 /* process the results */
393 for (i = 0; i < count; i++) {
394 struct wl1271_tx_hw_res_descr *result;
395 u8 offset = wl->tx_results_count & TX_HW_RESULT_QUEUE_LEN_MASK;
396
397 /* process the packet */
398 result = &(wl->tx_res_if->tx_results_queue[offset]);
399 wl1271_tx_complete_packet(wl, result);
400
401 wl->tx_results_count++;
402 }
403
404 if (test_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags) &&
405 skb_queue_len(&wl->tx_queue) <= WL1271_TX_QUEUE_LOW_WATERMARK) {
406 unsigned long flags;
407
408 /* firmware buffer has space, restart queues */
409 wl1271_debug(DEBUG_TX, "tx_complete: waking queues");
410 spin_lock_irqsave(&wl->wl_lock, flags);
411 ieee80211_wake_queues(wl->hw);
412 clear_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags);
413 spin_unlock_irqrestore(&wl->wl_lock, flags);
414 ieee80211_queue_work(wl->hw, &wl->tx_work);
415 }
416}
417
418/* caller must hold wl->mutex */
419void wl1271_tx_reset(struct wl1271 *wl)
420{
421 int i;
422 struct sk_buff *skb;
423
424 /* TX failure */
425/* control->flags = 0; FIXME */
426
427 while ((skb = skb_dequeue(&wl->tx_queue))) {
428 wl1271_debug(DEBUG_TX, "freeing skb 0x%p", skb);
429 ieee80211_tx_status(wl->hw, skb);
430 }
431
432 for (i = 0; i < ACX_TX_DESCRIPTORS; i++)
433 if (wl->tx_frames[i] != NULL) {
434 skb = wl->tx_frames[i];
435 wl->tx_frames[i] = NULL;
436 wl1271_debug(DEBUG_TX, "freeing skb 0x%p", skb);
437 ieee80211_tx_status(wl->hw, skb);
438 }
439 wl->tx_frames_cnt = 0;
440}
441
442#define WL1271_TX_FLUSH_TIMEOUT 500000
443
444/* caller must *NOT* hold wl->mutex */
445void wl1271_tx_flush(struct wl1271 *wl)
446{
447 unsigned long timeout;
448 timeout = jiffies + usecs_to_jiffies(WL1271_TX_FLUSH_TIMEOUT);
449
450 while (!time_after(jiffies, timeout)) {
451 mutex_lock(&wl->mutex);
452 wl1271_debug(DEBUG_TX, "flushing tx buffer: %d",
453 wl->tx_frames_cnt);
454 if ((wl->tx_frames_cnt == 0) &&
455 skb_queue_empty(&wl->tx_queue)) {
456 mutex_unlock(&wl->mutex);
457 return;
458 }
459 mutex_unlock(&wl->mutex);
460 msleep(1);
461 }
462
463 wl1271_warning("Unable to flush all TX buffers, timed out.");
464}
diff --git a/drivers/net/wireless/wl12xx/wl12xx.h b/drivers/net/wireless/wl12xx/wl12xx.h
new file mode 100644
index 000000000000..fbe8f46d1232
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/wl12xx.h
@@ -0,0 +1,639 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
5 * Copyright (C) 2008-2009 Nokia Corporation
6 *
7 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25#ifndef __WL12XX_H__
26#define __WL12XX_H__
27
28#include <linux/mutex.h>
29#include <linux/completion.h>
30#include <linux/spinlock.h>
31#include <linux/list.h>
32#include <linux/bitops.h>
33#include <net/mac80211.h>
34
35#include "conf.h"
36#include "ini.h"
37
38#define DRIVER_NAME "wl1271"
39#define DRIVER_PREFIX DRIVER_NAME ": "
40
41/*
42 * FW versions support BA 11n
43 * versions marks x.x.x.50-60.x
44 */
45#define WL12XX_BA_SUPPORT_FW_COST_VER2_START 50
46#define WL12XX_BA_SUPPORT_FW_COST_VER2_END 60
47
48enum {
49 DEBUG_NONE = 0,
50 DEBUG_IRQ = BIT(0),
51 DEBUG_SPI = BIT(1),
52 DEBUG_BOOT = BIT(2),
53 DEBUG_MAILBOX = BIT(3),
54 DEBUG_TESTMODE = BIT(4),
55 DEBUG_EVENT = BIT(5),
56 DEBUG_TX = BIT(6),
57 DEBUG_RX = BIT(7),
58 DEBUG_SCAN = BIT(8),
59 DEBUG_CRYPT = BIT(9),
60 DEBUG_PSM = BIT(10),
61 DEBUG_MAC80211 = BIT(11),
62 DEBUG_CMD = BIT(12),
63 DEBUG_ACX = BIT(13),
64 DEBUG_SDIO = BIT(14),
65 DEBUG_FILTERS = BIT(15),
66 DEBUG_ADHOC = BIT(16),
67 DEBUG_AP = BIT(17),
68 DEBUG_MASTER = (DEBUG_ADHOC | DEBUG_AP),
69 DEBUG_ALL = ~0,
70};
71
72extern u32 wl12xx_debug_level;
73
74#define DEBUG_DUMP_LIMIT 1024
75
76#define wl1271_error(fmt, arg...) \
77 pr_err(DRIVER_PREFIX "ERROR " fmt "\n", ##arg)
78
79#define wl1271_warning(fmt, arg...) \
80 pr_warning(DRIVER_PREFIX "WARNING " fmt "\n", ##arg)
81
82#define wl1271_notice(fmt, arg...) \
83 pr_info(DRIVER_PREFIX fmt "\n", ##arg)
84
85#define wl1271_info(fmt, arg...) \
86 pr_info(DRIVER_PREFIX fmt "\n", ##arg)
87
88#define wl1271_debug(level, fmt, arg...) \
89 do { \
90 if (level & wl12xx_debug_level) \
91 pr_debug(DRIVER_PREFIX fmt "\n", ##arg); \
92 } while (0)
93
94/* TODO: use pr_debug_hex_dump when it will be available */
95#define wl1271_dump(level, prefix, buf, len) \
96 do { \
97 if (level & wl12xx_debug_level) \
98 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
99 DUMP_PREFIX_OFFSET, 16, 1, \
100 buf, \
101 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
102 0); \
103 } while (0)
104
105#define wl1271_dump_ascii(level, prefix, buf, len) \
106 do { \
107 if (level & wl12xx_debug_level) \
108 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
109 DUMP_PREFIX_OFFSET, 16, 1, \
110 buf, \
111 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
112 true); \
113 } while (0)
114
115#define WL1271_DEFAULT_STA_RX_CONFIG (CFG_UNI_FILTER_EN | \
116 CFG_BSSID_FILTER_EN | \
117 CFG_MC_FILTER_EN)
118
119#define WL1271_DEFAULT_STA_RX_FILTER (CFG_RX_RCTS_ACK | CFG_RX_PRSP_EN | \
120 CFG_RX_MGMT_EN | CFG_RX_DATA_EN | \
121 CFG_RX_CTL_EN | CFG_RX_BCN_EN | \
122 CFG_RX_AUTH_EN | CFG_RX_ASSOC_EN)
123
124#define WL1271_DEFAULT_AP_RX_CONFIG 0
125
126#define WL1271_DEFAULT_AP_RX_FILTER (CFG_RX_RCTS_ACK | CFG_RX_PREQ_EN | \
127 CFG_RX_MGMT_EN | CFG_RX_DATA_EN | \
128 CFG_RX_CTL_EN | CFG_RX_AUTH_EN | \
129 CFG_RX_ASSOC_EN)
130
131
132
133#define WL1271_FW_NAME "ti-connectivity/wl1271-fw-2.bin"
134#define WL128X_FW_NAME "ti-connectivity/wl128x-fw.bin"
135#define WL127X_AP_FW_NAME "ti-connectivity/wl1271-fw-ap.bin"
136#define WL128X_AP_FW_NAME "ti-connectivity/wl128x-fw-ap.bin"
137
138/*
139 * wl127x and wl128x are using the same NVS file name. However, the
140 * ini parameters between them are different. The driver validates
141 * the correct NVS size in wl1271_boot_upload_nvs().
142 */
143#define WL12XX_NVS_NAME "ti-connectivity/wl1271-nvs.bin"
144
145#define WL1271_TX_SECURITY_LO16(s) ((u16)((s) & 0xffff))
146#define WL1271_TX_SECURITY_HI32(s) ((u32)(((s) >> 16) & 0xffffffff))
147
148#define WL1271_CIPHER_SUITE_GEM 0x00147201
149
150#define WL1271_BUSY_WORD_CNT 1
151#define WL1271_BUSY_WORD_LEN (WL1271_BUSY_WORD_CNT * sizeof(u32))
152
153#define WL1271_ELP_HW_STATE_ASLEEP 0
154#define WL1271_ELP_HW_STATE_IRQ 1
155
156#define WL1271_DEFAULT_BEACON_INT 100
157#define WL1271_DEFAULT_DTIM_PERIOD 1
158
159#define WL1271_AP_GLOBAL_HLID 0
160#define WL1271_AP_BROADCAST_HLID 1
161#define WL1271_AP_STA_HLID_START 2
162
163/*
164 * When in AP-mode, we allow (at least) this number of mem-blocks
165 * to be transmitted to FW for a STA in PS-mode. Only when packets are
166 * present in the FW buffers it will wake the sleeping STA. We want to put
167 * enough packets for the driver to transmit all of its buffered data before
168 * the STA goes to sleep again. But we don't want to take too much mem-blocks
169 * as it might hurt the throughput of active STAs.
170 * The number of blocks (18) is enough for 2 large packets.
171 */
172#define WL1271_PS_STA_MAX_BLOCKS (2 * 9)
173
174#define WL1271_AP_BSS_INDEX 0
175#define WL1271_AP_DEF_INACTIV_SEC 300
176#define WL1271_AP_DEF_BEACON_EXP 20
177
178#define ACX_TX_DESCRIPTORS 32
179
180#define WL1271_AGGR_BUFFER_SIZE (4 * PAGE_SIZE)
181
182enum wl1271_state {
183 WL1271_STATE_OFF,
184 WL1271_STATE_ON,
185 WL1271_STATE_PLT,
186};
187
188enum wl1271_partition_type {
189 PART_DOWN,
190 PART_WORK,
191 PART_DRPW,
192
193 PART_TABLE_LEN
194};
195
196struct wl1271_partition {
197 u32 size;
198 u32 start;
199};
200
201struct wl1271_partition_set {
202 struct wl1271_partition mem;
203 struct wl1271_partition reg;
204 struct wl1271_partition mem2;
205 struct wl1271_partition mem3;
206};
207
208struct wl1271;
209
210enum {
211 FW_VER_CHIP,
212 FW_VER_IF_TYPE,
213 FW_VER_MAJOR,
214 FW_VER_SUBTYPE,
215 FW_VER_MINOR,
216
217 NUM_FW_VER
218};
219
220#define FW_VER_CHIP_WL127X 6
221#define FW_VER_CHIP_WL128X 7
222
223#define FW_VER_IF_TYPE_STA 1
224#define FW_VER_IF_TYPE_AP 2
225
226#define FW_VER_MINOR_1_SPARE_STA_MIN 58
227#define FW_VER_MINOR_1_SPARE_AP_MIN 47
228
229struct wl1271_chip {
230 u32 id;
231 char fw_ver_str[ETHTOOL_BUSINFO_LEN];
232 unsigned int fw_ver[NUM_FW_VER];
233};
234
235struct wl1271_stats {
236 struct acx_statistics *fw_stats;
237 unsigned long fw_stats_update;
238
239 unsigned int retry_count;
240 unsigned int excessive_retries;
241};
242
243#define NUM_TX_QUEUES 4
244#define NUM_RX_PKT_DESC 8
245
246#define AP_MAX_STATIONS 5
247
248/* Broadcast and Global links + links to stations */
249#define AP_MAX_LINKS (AP_MAX_STATIONS + 2)
250
251/* FW status registers common for AP/STA */
252struct wl1271_fw_common_status {
253 __le32 intr;
254 u8 fw_rx_counter;
255 u8 drv_rx_counter;
256 u8 reserved;
257 u8 tx_results_counter;
258 __le32 rx_pkt_descs[NUM_RX_PKT_DESC];
259 __le32 tx_released_blks[NUM_TX_QUEUES];
260 __le32 fw_localtime;
261} __packed;
262
263/* FW status registers for AP */
264struct wl1271_fw_ap_status {
265 struct wl1271_fw_common_status common;
266
267 /* Next fields valid only in AP FW */
268
269 /*
270 * A bitmap (where each bit represents a single HLID)
271 * to indicate if the station is in PS mode.
272 */
273 __le32 link_ps_bitmap;
274
275 /* Number of freed MBs per HLID */
276 u8 tx_lnk_free_blks[AP_MAX_LINKS];
277 u8 padding_1[1];
278} __packed;
279
280/* FW status registers for STA */
281struct wl1271_fw_sta_status {
282 struct wl1271_fw_common_status common;
283
284 u8 tx_total;
285 u8 reserved1;
286 __le16 reserved2;
287 /* Total structure size is 68 bytes */
288 u32 padding;
289} __packed;
290
291struct wl1271_fw_full_status {
292 union {
293 struct wl1271_fw_common_status common;
294 struct wl1271_fw_sta_status sta;
295 struct wl1271_fw_ap_status ap;
296 };
297} __packed;
298
299
300struct wl1271_rx_mem_pool_addr {
301 u32 addr;
302 u32 addr_extra;
303};
304
305#define WL1271_MAX_CHANNELS 64
306struct wl1271_scan {
307 struct cfg80211_scan_request *req;
308 unsigned long scanned_ch[BITS_TO_LONGS(WL1271_MAX_CHANNELS)];
309 bool failed;
310 u8 state;
311 u8 ssid[IW_ESSID_MAX_SIZE+1];
312 size_t ssid_len;
313};
314
315struct wl1271_if_operations {
316 void (*read)(struct wl1271 *wl, int addr, void *buf, size_t len,
317 bool fixed);
318 void (*write)(struct wl1271 *wl, int addr, void *buf, size_t len,
319 bool fixed);
320 void (*reset)(struct wl1271 *wl);
321 void (*init)(struct wl1271 *wl);
322 int (*power)(struct wl1271 *wl, bool enable);
323 struct device* (*dev)(struct wl1271 *wl);
324 void (*enable_irq)(struct wl1271 *wl);
325 void (*disable_irq)(struct wl1271 *wl);
326 void (*set_block_size) (struct wl1271 *wl, unsigned int blksz);
327};
328
329#define MAX_NUM_KEYS 14
330#define MAX_KEY_SIZE 32
331
332struct wl1271_ap_key {
333 u8 id;
334 u8 key_type;
335 u8 key_size;
336 u8 key[MAX_KEY_SIZE];
337 u8 hlid;
338 u32 tx_seq_32;
339 u16 tx_seq_16;
340};
341
342enum wl12xx_flags {
343 WL1271_FLAG_STA_ASSOCIATED,
344 WL1271_FLAG_JOINED,
345 WL1271_FLAG_GPIO_POWER,
346 WL1271_FLAG_TX_QUEUE_STOPPED,
347 WL1271_FLAG_TX_PENDING,
348 WL1271_FLAG_IN_ELP,
349 WL1271_FLAG_ELP_REQUESTED,
350 WL1271_FLAG_PSM,
351 WL1271_FLAG_PSM_REQUESTED,
352 WL1271_FLAG_IRQ_RUNNING,
353 WL1271_FLAG_IDLE,
354 WL1271_FLAG_PSPOLL_FAILURE,
355 WL1271_FLAG_STA_STATE_SENT,
356 WL1271_FLAG_FW_TX_BUSY,
357 WL1271_FLAG_AP_STARTED,
358 WL1271_FLAG_IF_INITIALIZED,
359 WL1271_FLAG_DUMMY_PACKET_PENDING,
360 WL1271_FLAG_SUSPENDED,
361 WL1271_FLAG_PENDING_WORK,
362};
363
364struct wl1271_link {
365 /* AP-mode - TX queue per AC in link */
366 struct sk_buff_head tx_queue[NUM_TX_QUEUES];
367
368 /* accounting for allocated / available TX blocks in FW */
369 u8 allocated_blks;
370 u8 prev_freed_blks;
371
372 u8 addr[ETH_ALEN];
373};
374
375struct wl1271 {
376 struct platform_device *plat_dev;
377 struct ieee80211_hw *hw;
378 bool mac80211_registered;
379
380 void *if_priv;
381
382 struct wl1271_if_operations *if_ops;
383
384 void (*set_power)(bool enable);
385 int irq;
386 int ref_clock;
387
388 spinlock_t wl_lock;
389
390 enum wl1271_state state;
391 struct mutex mutex;
392
393 unsigned long flags;
394
395 struct wl1271_partition_set part;
396
397 struct wl1271_chip chip;
398
399 int cmd_box_addr;
400 int event_box_addr;
401
402 u8 *fw;
403 size_t fw_len;
404 u8 fw_bss_type;
405 void *nvs;
406 size_t nvs_len;
407
408 s8 hw_pg_ver;
409
410 u8 bssid[ETH_ALEN];
411 u8 mac_addr[ETH_ALEN];
412 u8 bss_type;
413 u8 set_bss_type;
414 u8 ssid[IW_ESSID_MAX_SIZE + 1];
415 u8 ssid_len;
416 int channel;
417
418 struct wl1271_acx_mem_map *target_mem_map;
419
420 /* Accounting for allocated / available TX blocks on HW */
421 u32 tx_blocks_freed[NUM_TX_QUEUES];
422 u32 tx_blocks_available;
423 u32 tx_allocated_blocks;
424 u32 tx_results_count;
425
426 /* Transmitted TX packets counter for chipset interface */
427 u32 tx_packets_count;
428
429 /* Time-offset between host and chipset clocks */
430 s64 time_offset;
431
432 /* Session counter for the chipset */
433 int session_counter;
434
435 /* Frames scheduled for transmission, not handled yet */
436 struct sk_buff_head tx_queue[NUM_TX_QUEUES];
437 int tx_queue_count;
438
439 /* Frames received, not handled yet by mac80211 */
440 struct sk_buff_head deferred_rx_queue;
441
442 /* Frames sent, not returned yet to mac80211 */
443 struct sk_buff_head deferred_tx_queue;
444
445 struct work_struct tx_work;
446
447 /* Pending TX frames */
448 unsigned long tx_frames_map[BITS_TO_LONGS(ACX_TX_DESCRIPTORS)];
449 struct sk_buff *tx_frames[ACX_TX_DESCRIPTORS];
450 int tx_frames_cnt;
451
452 /* Security sequence number counters */
453 u8 tx_security_last_seq;
454 s64 tx_security_seq;
455
456 /* FW Rx counter */
457 u32 rx_counter;
458
459 /* Rx memory pool address */
460 struct wl1271_rx_mem_pool_addr rx_mem_pool_addr;
461
462 /* Intermediate buffer, used for packet aggregation */
463 u8 *aggr_buf;
464
465 /* Reusable dummy packet template */
466 struct sk_buff *dummy_packet;
467
468 /* Network stack work */
469 struct work_struct netstack_work;
470
471 /* Hardware recovery work */
472 struct work_struct recovery_work;
473
474 /* The mbox event mask */
475 u32 event_mask;
476
477 /* Mailbox pointers */
478 u32 mbox_ptr[2];
479
480 /* Are we currently scanning */
481 struct wl1271_scan scan;
482 struct delayed_work scan_complete_work;
483
484 bool sched_scanning;
485
486 /* probe-req template for the current AP */
487 struct sk_buff *probereq;
488
489 /* Our association ID */
490 u16 aid;
491
492 /*
493 * currently configured rate set:
494 * bits 0-15 - 802.11abg rates
495 * bits 16-23 - 802.11n MCS index mask
496 * support only 1 stream, thus only 8 bits for the MCS rates (0-7).
497 */
498 u32 basic_rate_set;
499 u32 basic_rate;
500 u32 rate_set;
501
502 /* The current band */
503 enum ieee80211_band band;
504
505 /* Beaconing interval (needed for ad-hoc) */
506 u32 beacon_int;
507
508 /* Default key (for WEP) */
509 u32 default_key;
510
511 unsigned int filters;
512 unsigned int rx_config;
513 unsigned int rx_filter;
514
515 struct completion *elp_compl;
516 struct completion *ps_compl;
517 struct delayed_work elp_work;
518 struct delayed_work pspoll_work;
519
520 /* counter for ps-poll delivery failures */
521 int ps_poll_failures;
522
523 /* retry counter for PSM entries */
524 u8 psm_entry_retry;
525
526 /* in dBm */
527 int power_level;
528
529 int rssi_thold;
530 int last_rssi_event;
531
532 struct wl1271_stats stats;
533
534 __le32 buffer_32;
535 u32 buffer_cmd;
536 u32 buffer_busyword[WL1271_BUSY_WORD_CNT];
537
538 struct wl1271_fw_full_status *fw_status;
539 struct wl1271_tx_hw_res_if *tx_res_if;
540
541 struct ieee80211_vif *vif;
542
543 /* Current chipset configuration */
544 struct conf_drv_settings conf;
545
546 bool sg_enabled;
547
548 bool enable_11a;
549
550 struct list_head list;
551
552 /* Most recently reported noise in dBm */
553 s8 noise;
554
555 /* map for HLIDs of associated stations - when operating in AP mode */
556 unsigned long ap_hlid_map[BITS_TO_LONGS(AP_MAX_STATIONS)];
557
558 /* recoreded keys for AP-mode - set here before AP startup */
559 struct wl1271_ap_key *recorded_ap_keys[MAX_NUM_KEYS];
560
561 /* bands supported by this instance of wl12xx */
562 struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
563
564 /* RX BA constraint value */
565 bool ba_support;
566 u8 ba_rx_bitmap;
567
568 int tcxo_clock;
569
570 /*
571 * wowlan trigger was configured during suspend.
572 * (currently, only "ANY" trigger is supported)
573 */
574 bool wow_enabled;
575
576 /*
577 * AP-mode - links indexed by HLID. The global and broadcast links
578 * are always active.
579 */
580 struct wl1271_link links[AP_MAX_LINKS];
581
582 /* the hlid of the link where the last transmitted skb came from */
583 int last_tx_hlid;
584
585 /* AP-mode - a bitmap of links currently in PS mode according to FW */
586 u32 ap_fw_ps_map;
587
588 /* AP-mode - a bitmap of links currently in PS mode in mac80211 */
589 unsigned long ap_ps_map;
590
591 /* Quirks of specific hardware revisions */
592 unsigned int quirks;
593
594 /* Platform limitations */
595 unsigned int platform_quirks;
596};
597
598struct wl1271_station {
599 u8 hlid;
600};
601
602int wl1271_plt_start(struct wl1271 *wl);
603int wl1271_plt_stop(struct wl1271 *wl);
604
605#define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
606
607#define SESSION_COUNTER_MAX 7 /* maximum value for the session counter */
608
609#define WL1271_DEFAULT_POWER_LEVEL 0
610
611#define WL1271_TX_QUEUE_LOW_WATERMARK 10
612#define WL1271_TX_QUEUE_HIGH_WATERMARK 25
613
614#define WL1271_DEFERRED_QUEUE_LIMIT 64
615
616/* WL1271 needs a 200ms sleep after power on, and a 20ms sleep before power
617 on in case is has been shut down shortly before */
618#define WL1271_PRE_POWER_ON_SLEEP 20 /* in milliseconds */
619#define WL1271_POWER_ON_SLEEP 200 /* in milliseconds */
620
621/* Macros to handle wl1271.sta_rate_set */
622#define HW_BG_RATES_MASK 0xffff
623#define HW_HT_RATES_OFFSET 16
624
625/* Quirks */
626
627/* Each RX/TX transaction requires an end-of-transaction transfer */
628#define WL12XX_QUIRK_END_OF_TRANSACTION BIT(0)
629
630/*
631 * Older firmwares use 2 spare TX blocks
632 * (for STA < 6.1.3.50.58 or for AP < 6.2.0.0.47)
633 */
634#define WL12XX_QUIRK_USE_2_SPARE_BLOCKS BIT(1)
635
636/* WL128X requires aggregated packets to be aligned to the SDIO block size */
637#define WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT BIT(2)
638
639#endif
diff --git a/drivers/net/wireless/wl12xx/wl12xx_80211.h b/drivers/net/wireless/wl12xx/wl12xx_80211.h
index 184628027213..18fe542360f2 100644
--- a/drivers/net/wireless/wl12xx/wl12xx_80211.h
+++ b/drivers/net/wireless/wl12xx/wl12xx_80211.h
@@ -2,6 +2,7 @@
2#define __WL12XX_80211_H__ 2#define __WL12XX_80211_H__
3 3
4#include <linux/if_ether.h> /* ETH_ALEN */ 4#include <linux/if_ether.h> /* ETH_ALEN */
5#include <linux/if_arp.h>
5 6
6/* RATES */ 7/* RATES */
7#define IEEE80211_CCK_RATE_1MB 0x02 8#define IEEE80211_CCK_RATE_1MB 0x02
@@ -54,7 +55,6 @@
54 55
55/* This really should be 8, but not for our firmware */ 56/* This really should be 8, but not for our firmware */
56#define MAX_SUPPORTED_RATES 32 57#define MAX_SUPPORTED_RATES 32
57#define COUNTRY_STRING_LEN 3
58#define MAX_COUNTRY_TRIPLETS 32 58#define MAX_COUNTRY_TRIPLETS 32
59 59
60/* Headers */ 60/* Headers */
@@ -98,7 +98,7 @@ struct country_triplet {
98 98
99struct wl12xx_ie_country { 99struct wl12xx_ie_country {
100 struct wl12xx_ie_header header; 100 struct wl12xx_ie_header header;
101 u8 country_string[COUNTRY_STRING_LEN]; 101 u8 country_string[IEEE80211_COUNTRY_STRING_LEN];
102 struct country_triplet triplets[MAX_COUNTRY_TRIPLETS]; 102 struct country_triplet triplets[MAX_COUNTRY_TRIPLETS];
103} __packed; 103} __packed;
104 104
@@ -133,11 +133,17 @@ struct wl12xx_qos_null_data_template {
133 __le16 qos_ctl; 133 __le16 qos_ctl;
134} __packed; 134} __packed;
135 135
136struct wl12xx_probe_req_template { 136struct wl12xx_arp_rsp_template {
137 struct ieee80211_header header; 137 struct ieee80211_hdr_3addr hdr;
138 struct wl12xx_ie_ssid ssid; 138
139 struct wl12xx_ie_rates rates; 139 u8 llc_hdr[sizeof(rfc1042_header)];
140 struct wl12xx_ie_rates ext_rates; 140 __be16 llc_type;
141
142 struct arphdr arp_hdr;
143 u8 sender_hw[ETH_ALEN];
144 __be32 sender_ip;
145 u8 target_hw[ETH_ALEN];
146 __be32 target_ip;
141} __packed; 147} __packed;
142 148
143 149
@@ -153,4 +159,9 @@ struct wl12xx_probe_resp_template {
153 struct wl12xx_ie_country country; 159 struct wl12xx_ie_country country;
154} __packed; 160} __packed;
155 161
162struct wl12xx_disconn_template {
163 struct ieee80211_header header;
164 __le16 disconn_reason;
165} __packed;
166
156#endif 167#endif
diff --git a/drivers/net/wireless/wl12xx/wl12xx_platform_data.c b/drivers/net/wireless/wl12xx/wl12xx_platform_data.c
new file mode 100644
index 000000000000..973b11060a8f
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/wl12xx_platform_data.c
@@ -0,0 +1,28 @@
1#include <linux/module.h>
2#include <linux/err.h>
3#include <linux/wl12xx.h>
4
5static const struct wl12xx_platform_data *platform_data;
6
7int __init wl12xx_set_platform_data(const struct wl12xx_platform_data *data)
8{
9 if (platform_data)
10 return -EBUSY;
11 if (!data)
12 return -EINVAL;
13
14 platform_data = kmemdup(data, sizeof(*data), GFP_KERNEL);
15 if (!platform_data)
16 return -ENOMEM;
17
18 return 0;
19}
20
21const struct wl12xx_platform_data *wl12xx_get_platform_data(void)
22{
23 if (!platform_data)
24 return ERR_PTR(-ENODEV);
25
26 return platform_data;
27}
28EXPORT_SYMBOL(wl12xx_get_platform_data);