aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/ti
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/ti')
-rw-r--r--drivers/net/wireless/ti/Kconfig14
-rw-r--r--drivers/net/wireless/ti/Makefile4
-rw-r--r--drivers/net/wireless/ti/wl1251/Kconfig33
-rw-r--r--drivers/net/wireless/ti/wl1251/Makefile10
-rw-r--r--drivers/net/wireless/ti/wl1251/acx.c1097
-rw-r--r--drivers/net/wireless/ti/wl1251/acx.h1483
-rw-r--r--drivers/net/wireless/ti/wl1251/boot.c554
-rw-r--r--drivers/net/wireless/ti/wl1251/boot.h39
-rw-r--r--drivers/net/wireless/ti/wl1251/cmd.c496
-rw-r--r--drivers/net/wireless/ti/wl1251/cmd.h415
-rw-r--r--drivers/net/wireless/ti/wl1251/debugfs.c545
-rw-r--r--drivers/net/wireless/ti/wl1251/debugfs.h31
-rw-r--r--drivers/net/wireless/ti/wl1251/event.c188
-rw-r--r--drivers/net/wireless/ti/wl1251/event.h120
-rw-r--r--drivers/net/wireless/ti/wl1251/init.c423
-rw-r--r--drivers/net/wireless/ti/wl1251/init.h86
-rw-r--r--drivers/net/wireless/ti/wl1251/io.c194
-rw-r--r--drivers/net/wireless/ti/wl1251/io.h83
-rw-r--r--drivers/net/wireless/ti/wl1251/main.c1471
-rw-r--r--drivers/net/wireless/ti/wl1251/ps.c185
-rw-r--r--drivers/net/wireless/ti/wl1251/ps.h35
-rw-r--r--drivers/net/wireless/ti/wl1251/reg.h655
-rw-r--r--drivers/net/wireless/ti/wl1251/rx.c235
-rw-r--r--drivers/net/wireless/ti/wl1251/rx.h122
-rw-r--r--drivers/net/wireless/ti/wl1251/sdio.c374
-rw-r--r--drivers/net/wireless/ti/wl1251/spi.c355
-rw-r--r--drivers/net/wireless/ti/wl1251/spi.h59
-rw-r--r--drivers/net/wireless/ti/wl1251/tx.c560
-rw-r--r--drivers/net/wireless/ti/wl1251/tx.h231
-rw-r--r--drivers/net/wireless/ti/wl1251/wl1251.h446
-rw-r--r--drivers/net/wireless/ti/wl1251/wl12xx_80211.h155
-rw-r--r--drivers/net/wireless/ti/wl12xx/Kconfig8
-rw-r--r--drivers/net/wireless/ti/wl12xx/Makefile3
-rw-r--r--drivers/net/wireless/ti/wl12xx/acx.c53
-rw-r--r--drivers/net/wireless/ti/wl12xx/acx.h36
-rw-r--r--drivers/net/wireless/ti/wl12xx/cmd.c254
-rw-r--r--drivers/net/wireless/ti/wl12xx/cmd.h112
-rw-r--r--drivers/net/wireless/ti/wl12xx/conf.h50
-rw-r--r--drivers/net/wireless/ti/wl12xx/main.c1388
-rw-r--r--drivers/net/wireless/ti/wl12xx/reg.h556
-rw-r--r--drivers/net/wireless/ti/wl12xx/wl12xx.h31
-rw-r--r--drivers/net/wireless/ti/wlcore/Kconfig41
-rw-r--r--drivers/net/wireless/ti/wlcore/Makefile15
-rw-r--r--drivers/net/wireless/ti/wlcore/acx.c1716
-rw-r--r--drivers/net/wireless/ti/wlcore/acx.h1308
-rw-r--r--drivers/net/wireless/ti/wlcore/boot.c443
-rw-r--r--drivers/net/wireless/ti/wlcore/boot.h54
-rw-r--r--drivers/net/wireless/ti/wlcore/cmd.c1728
-rw-r--r--drivers/net/wireless/ti/wlcore/cmd.h646
-rw-r--r--drivers/net/wireless/ti/wlcore/conf.h1274
-rw-r--r--drivers/net/wireless/ti/wlcore/debug.h103
-rw-r--r--drivers/net/wireless/ti/wlcore/debugfs.c1204
-rw-r--r--drivers/net/wireless/ti/wlcore/debugfs.h33
-rw-r--r--drivers/net/wireless/ti/wlcore/event.c306
-rw-r--r--drivers/net/wireless/ti/wlcore/event.h140
-rw-r--r--drivers/net/wireless/ti/wlcore/hw_ops.h122
-rw-r--r--drivers/net/wireless/ti/wlcore/ini.h220
-rw-r--r--drivers/net/wireless/ti/wlcore/init.c737
-rw-r--r--drivers/net/wireless/ti/wlcore/init.h39
-rw-r--r--drivers/net/wireless/ti/wlcore/io.c173
-rw-r--r--drivers/net/wireless/ti/wlcore/io.h187
-rw-r--r--drivers/net/wireless/ti/wlcore/main.c5093
-rw-r--r--drivers/net/wireless/ti/wlcore/ps.c306
-rw-r--r--drivers/net/wireless/ti/wlcore/ps.h41
-rw-r--r--drivers/net/wireless/ti/wlcore/rx.c280
-rw-r--r--drivers/net/wireless/ti/wlcore/rx.h142
-rw-r--r--drivers/net/wireless/ti/wlcore/scan.c790
-rw-r--r--drivers/net/wireless/ti/wlcore/scan.h233
-rw-r--r--drivers/net/wireless/ti/wlcore/sdio.c378
-rw-r--r--drivers/net/wireless/ti/wlcore/spi.c440
-rw-r--r--drivers/net/wireless/ti/wlcore/testmode.c343
-rw-r--r--drivers/net/wireless/ti/wlcore/testmode.h31
-rw-r--r--drivers/net/wireless/ti/wlcore/tx.c1056
-rw-r--r--drivers/net/wireless/ti/wlcore/tx.h231
-rw-r--r--drivers/net/wireless/ti/wlcore/wl12xx.h466
-rw-r--r--drivers/net/wireless/ti/wlcore/wl12xx_80211.h137
-rw-r--r--drivers/net/wireless/ti/wlcore/wl12xx_platform_data.c49
-rw-r--r--drivers/net/wireless/ti/wlcore/wlcore.h448
78 files changed, 34142 insertions, 0 deletions
diff --git a/drivers/net/wireless/ti/Kconfig b/drivers/net/wireless/ti/Kconfig
new file mode 100644
index 000000000000..1a72932e2213
--- /dev/null
+++ b/drivers/net/wireless/ti/Kconfig
@@ -0,0 +1,14 @@
1menuconfig WL_TI
2 bool "TI Wireless LAN support"
3 ---help---
4 This section contains support for all the wireless drivers
5 for Texas Instruments WLAN chips, such as wl1251 and the wl12xx
6 family.
7
8if WL_TI
9source "drivers/net/wireless/ti/wl1251/Kconfig"
10source "drivers/net/wireless/ti/wl12xx/Kconfig"
11
12# keep last for automatic dependencies
13source "drivers/net/wireless/ti/wlcore/Kconfig"
14endif # WL_TI
diff --git a/drivers/net/wireless/ti/Makefile b/drivers/net/wireless/ti/Makefile
new file mode 100644
index 000000000000..0a565622d4a4
--- /dev/null
+++ b/drivers/net/wireless/ti/Makefile
@@ -0,0 +1,4 @@
1obj-$(CONFIG_WLCORE) += wlcore/
2obj-$(CONFIG_WL12XX) += wl12xx/
3obj-$(CONFIG_WL12XX_PLATFORM_DATA) += wlcore/
4obj-$(CONFIG_WL1251) += wl1251/
diff --git a/drivers/net/wireless/ti/wl1251/Kconfig b/drivers/net/wireless/ti/wl1251/Kconfig
new file mode 100644
index 000000000000..1fb65849414f
--- /dev/null
+++ b/drivers/net/wireless/ti/wl1251/Kconfig
@@ -0,0 +1,33 @@
1menuconfig WL1251
2 tristate "TI wl1251 driver support"
3 depends on MAC80211 && EXPERIMENTAL && GENERIC_HARDIRQS
4 select FW_LOADER
5 select CRC7
6 ---help---
7 This will enable TI wl1251 driver support. The drivers make
8 use of the mac80211 stack.
9
10 If you choose to build a module, it'll be called wl1251. Say
11 N if unsure.
12
13config WL1251_SPI
14 tristate "TI wl1251 SPI support"
15 depends on WL1251 && SPI_MASTER
16 ---help---
17 This module adds support for the SPI interface of adapters using
18 TI wl1251 chipset. Select this if your platform is using
19 the SPI bus.
20
21 If you choose to build a module, it'll be called wl1251_spi.
22 Say N if unsure.
23
24config WL1251_SDIO
25 tristate "TI wl1251 SDIO support"
26 depends on WL1251 && MMC
27 ---help---
28 This module adds support for the SDIO interface of adapters using
29 TI wl1251 chipset. Select this if your platform is using
30 the SDIO bus.
31
32 If you choose to build a module, it'll be called
33 wl1251_sdio. Say N if unsure.
diff --git a/drivers/net/wireless/ti/wl1251/Makefile b/drivers/net/wireless/ti/wl1251/Makefile
new file mode 100644
index 000000000000..a5c6328b5f72
--- /dev/null
+++ b/drivers/net/wireless/ti/wl1251/Makefile
@@ -0,0 +1,10 @@
1wl1251-objs = main.o event.o tx.o rx.o ps.o cmd.o \
2 acx.o boot.o init.o debugfs.o io.o
3wl1251_spi-objs += spi.o
4wl1251_sdio-objs += sdio.o
5
6obj-$(CONFIG_WL1251) += wl1251.o
7obj-$(CONFIG_WL1251_SPI) += wl1251_spi.o
8obj-$(CONFIG_WL1251_SDIO) += wl1251_sdio.o
9
10ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/net/wireless/ti/wl1251/acx.c b/drivers/net/wireless/ti/wl1251/acx.c
new file mode 100644
index 000000000000..ad87a1ac6462
--- /dev/null
+++ b/drivers/net/wireless/ti/wl1251/acx.c
@@ -0,0 +1,1097 @@
1#include "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 "reg.h"
9#include "cmd.h"
10#include "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
144out:
145 kfree(auth);
146 return ret;
147}
148
149int wl1251_acx_fw_version(struct wl1251 *wl, char *buf, size_t len)
150{
151 struct acx_revision *rev;
152 int ret;
153
154 wl1251_debug(DEBUG_ACX, "acx fw rev");
155
156 rev = kzalloc(sizeof(*rev), GFP_KERNEL);
157 if (!rev) {
158 ret = -ENOMEM;
159 goto out;
160 }
161
162 ret = wl1251_cmd_interrogate(wl, ACX_FW_REV, rev, sizeof(*rev));
163 if (ret < 0) {
164 wl1251_warning("ACX_FW_REV interrogate failed");
165 goto out;
166 }
167
168 /* be careful with the buffer sizes */
169 strncpy(buf, rev->fw_version, min(len, sizeof(rev->fw_version)));
170
171 /*
172 * if the firmware version string is exactly
173 * sizeof(rev->fw_version) long or fw_len is less than
174 * sizeof(rev->fw_version) it won't be null terminated
175 */
176 buf[min(len, sizeof(rev->fw_version)) - 1] = '\0';
177
178out:
179 kfree(rev);
180 return ret;
181}
182
183int wl1251_acx_tx_power(struct wl1251 *wl, int power)
184{
185 struct acx_current_tx_power *acx;
186 int ret;
187
188 wl1251_debug(DEBUG_ACX, "acx dot11_cur_tx_pwr");
189
190 if (power < 0 || power > 25)
191 return -EINVAL;
192
193 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
194 if (!acx) {
195 ret = -ENOMEM;
196 goto out;
197 }
198
199 acx->current_tx_power = power * 10;
200
201 ret = wl1251_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx));
202 if (ret < 0) {
203 wl1251_warning("configure of tx power failed: %d", ret);
204 goto out;
205 }
206
207out:
208 kfree(acx);
209 return ret;
210}
211
212int wl1251_acx_feature_cfg(struct wl1251 *wl)
213{
214 struct acx_feature_config *feature;
215 int ret;
216
217 wl1251_debug(DEBUG_ACX, "acx feature cfg");
218
219 feature = kzalloc(sizeof(*feature), GFP_KERNEL);
220 if (!feature) {
221 ret = -ENOMEM;
222 goto out;
223 }
224
225 /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */
226 feature->data_flow_options = 0;
227 feature->options = 0;
228
229 ret = wl1251_cmd_configure(wl, ACX_FEATURE_CFG,
230 feature, sizeof(*feature));
231 if (ret < 0) {
232 wl1251_error("Couldn't set HW encryption");
233 goto out;
234 }
235
236out:
237 kfree(feature);
238 return ret;
239}
240
241int wl1251_acx_mem_map(struct wl1251 *wl, struct acx_header *mem_map,
242 size_t len)
243{
244 int ret;
245
246 wl1251_debug(DEBUG_ACX, "acx mem map");
247
248 ret = wl1251_cmd_interrogate(wl, ACX_MEM_MAP, mem_map, len);
249 if (ret < 0)
250 return ret;
251
252 return 0;
253}
254
255int wl1251_acx_data_path_params(struct wl1251 *wl,
256 struct acx_data_path_params_resp *resp)
257{
258 struct acx_data_path_params *params;
259 int ret;
260
261 wl1251_debug(DEBUG_ACX, "acx data path params");
262
263 params = kzalloc(sizeof(*params), GFP_KERNEL);
264 if (!params) {
265 ret = -ENOMEM;
266 goto out;
267 }
268
269 params->rx_packet_ring_chunk_size = DP_RX_PACKET_RING_CHUNK_SIZE;
270 params->tx_packet_ring_chunk_size = DP_TX_PACKET_RING_CHUNK_SIZE;
271
272 params->rx_packet_ring_chunk_num = DP_RX_PACKET_RING_CHUNK_NUM;
273 params->tx_packet_ring_chunk_num = DP_TX_PACKET_RING_CHUNK_NUM;
274
275 params->tx_complete_threshold = 1;
276
277 params->tx_complete_ring_depth = FW_TX_CMPLT_BLOCK_SIZE;
278
279 params->tx_complete_timeout = DP_TX_COMPLETE_TIME_OUT;
280
281 ret = wl1251_cmd_configure(wl, ACX_DATA_PATH_PARAMS,
282 params, sizeof(*params));
283 if (ret < 0)
284 goto out;
285
286 /* FIXME: shouldn't this be ACX_DATA_PATH_RESP_PARAMS? */
287 ret = wl1251_cmd_interrogate(wl, ACX_DATA_PATH_PARAMS,
288 resp, sizeof(*resp));
289
290 if (ret < 0) {
291 wl1251_warning("failed to read data path parameters: %d", ret);
292 goto out;
293 } else if (resp->header.cmd.status != CMD_STATUS_SUCCESS) {
294 wl1251_warning("data path parameter acx status failed");
295 ret = -EIO;
296 goto out;
297 }
298
299out:
300 kfree(params);
301 return ret;
302}
303
304int wl1251_acx_rx_msdu_life_time(struct wl1251 *wl, u32 life_time)
305{
306 struct acx_rx_msdu_lifetime *acx;
307 int ret;
308
309 wl1251_debug(DEBUG_ACX, "acx rx msdu life time");
310
311 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
312 if (!acx) {
313 ret = -ENOMEM;
314 goto out;
315 }
316
317 acx->lifetime = life_time;
318 ret = wl1251_cmd_configure(wl, DOT11_RX_MSDU_LIFE_TIME,
319 acx, sizeof(*acx));
320 if (ret < 0) {
321 wl1251_warning("failed to set rx msdu life time: %d", ret);
322 goto out;
323 }
324
325out:
326 kfree(acx);
327 return ret;
328}
329
330int wl1251_acx_rx_config(struct wl1251 *wl, u32 config, u32 filter)
331{
332 struct acx_rx_config *rx_config;
333 int ret;
334
335 wl1251_debug(DEBUG_ACX, "acx rx config");
336
337 rx_config = kzalloc(sizeof(*rx_config), GFP_KERNEL);
338 if (!rx_config) {
339 ret = -ENOMEM;
340 goto out;
341 }
342
343 rx_config->config_options = config;
344 rx_config->filter_options = filter;
345
346 ret = wl1251_cmd_configure(wl, ACX_RX_CFG,
347 rx_config, sizeof(*rx_config));
348 if (ret < 0) {
349 wl1251_warning("failed to set rx config: %d", ret);
350 goto out;
351 }
352
353out:
354 kfree(rx_config);
355 return ret;
356}
357
358int wl1251_acx_pd_threshold(struct wl1251 *wl)
359{
360 struct acx_packet_detection *pd;
361 int ret;
362
363 wl1251_debug(DEBUG_ACX, "acx data pd threshold");
364
365 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
366 if (!pd) {
367 ret = -ENOMEM;
368 goto out;
369 }
370
371 /* FIXME: threshold value not set */
372
373 ret = wl1251_cmd_configure(wl, ACX_PD_THRESHOLD, pd, sizeof(*pd));
374 if (ret < 0) {
375 wl1251_warning("failed to set pd threshold: %d", ret);
376 goto out;
377 }
378
379out:
380 kfree(pd);
381 return ret;
382}
383
384int wl1251_acx_slot(struct wl1251 *wl, enum acx_slot_type slot_time)
385{
386 struct acx_slot *slot;
387 int ret;
388
389 wl1251_debug(DEBUG_ACX, "acx slot");
390
391 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
392 if (!slot) {
393 ret = -ENOMEM;
394 goto out;
395 }
396
397 slot->wone_index = STATION_WONE_INDEX;
398 slot->slot_time = slot_time;
399
400 ret = wl1251_cmd_configure(wl, ACX_SLOT, slot, sizeof(*slot));
401 if (ret < 0) {
402 wl1251_warning("failed to set slot time: %d", ret);
403 goto out;
404 }
405
406out:
407 kfree(slot);
408 return ret;
409}
410
411int wl1251_acx_group_address_tbl(struct wl1251 *wl)
412{
413 struct acx_dot11_grp_addr_tbl *acx;
414 int ret;
415
416 wl1251_debug(DEBUG_ACX, "acx group address tbl");
417
418 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
419 if (!acx) {
420 ret = -ENOMEM;
421 goto out;
422 }
423
424 /* MAC filtering */
425 acx->enabled = 0;
426 acx->num_groups = 0;
427 memset(acx->mac_table, 0, ADDRESS_GROUP_MAX_LEN);
428
429 ret = wl1251_cmd_configure(wl, DOT11_GROUP_ADDRESS_TBL,
430 acx, sizeof(*acx));
431 if (ret < 0) {
432 wl1251_warning("failed to set group addr table: %d", ret);
433 goto out;
434 }
435
436out:
437 kfree(acx);
438 return ret;
439}
440
441int wl1251_acx_service_period_timeout(struct wl1251 *wl)
442{
443 struct acx_rx_timeout *rx_timeout;
444 int ret;
445
446 rx_timeout = kzalloc(sizeof(*rx_timeout), GFP_KERNEL);
447 if (!rx_timeout) {
448 ret = -ENOMEM;
449 goto out;
450 }
451
452 wl1251_debug(DEBUG_ACX, "acx service period timeout");
453
454 rx_timeout->ps_poll_timeout = RX_TIMEOUT_PS_POLL_DEF;
455 rx_timeout->upsd_timeout = RX_TIMEOUT_UPSD_DEF;
456
457 ret = wl1251_cmd_configure(wl, ACX_SERVICE_PERIOD_TIMEOUT,
458 rx_timeout, sizeof(*rx_timeout));
459 if (ret < 0) {
460 wl1251_warning("failed to set service period timeout: %d",
461 ret);
462 goto out;
463 }
464
465out:
466 kfree(rx_timeout);
467 return ret;
468}
469
470int wl1251_acx_rts_threshold(struct wl1251 *wl, u16 rts_threshold)
471{
472 struct acx_rts_threshold *rts;
473 int ret;
474
475 wl1251_debug(DEBUG_ACX, "acx rts threshold");
476
477 rts = kzalloc(sizeof(*rts), GFP_KERNEL);
478 if (!rts) {
479 ret = -ENOMEM;
480 goto out;
481 }
482
483 rts->threshold = rts_threshold;
484
485 ret = wl1251_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts));
486 if (ret < 0) {
487 wl1251_warning("failed to set rts threshold: %d", ret);
488 goto out;
489 }
490
491out:
492 kfree(rts);
493 return ret;
494}
495
496int wl1251_acx_beacon_filter_opt(struct wl1251 *wl, bool enable_filter)
497{
498 struct acx_beacon_filter_option *beacon_filter;
499 int ret;
500
501 wl1251_debug(DEBUG_ACX, "acx beacon filter opt");
502
503 beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL);
504 if (!beacon_filter) {
505 ret = -ENOMEM;
506 goto out;
507 }
508
509 beacon_filter->enable = enable_filter;
510 beacon_filter->max_num_beacons = 0;
511
512 ret = wl1251_cmd_configure(wl, ACX_BEACON_FILTER_OPT,
513 beacon_filter, sizeof(*beacon_filter));
514 if (ret < 0) {
515 wl1251_warning("failed to set beacon filter opt: %d", ret);
516 goto out;
517 }
518
519out:
520 kfree(beacon_filter);
521 return ret;
522}
523
524int wl1251_acx_beacon_filter_table(struct wl1251 *wl)
525{
526 struct acx_beacon_filter_ie_table *ie_table;
527 int idx = 0;
528 int ret;
529
530 wl1251_debug(DEBUG_ACX, "acx beacon filter table");
531
532 ie_table = kzalloc(sizeof(*ie_table), GFP_KERNEL);
533 if (!ie_table) {
534 ret = -ENOMEM;
535 goto out;
536 }
537
538 /* configure default beacon pass-through rules */
539 ie_table->num_ie = 1;
540 ie_table->table[idx++] = BEACON_FILTER_IE_ID_CHANNEL_SWITCH_ANN;
541 ie_table->table[idx++] = BEACON_RULE_PASS_ON_APPEARANCE;
542
543 ret = wl1251_cmd_configure(wl, ACX_BEACON_FILTER_TABLE,
544 ie_table, sizeof(*ie_table));
545 if (ret < 0) {
546 wl1251_warning("failed to set beacon filter table: %d", ret);
547 goto out;
548 }
549
550out:
551 kfree(ie_table);
552 return ret;
553}
554
555int wl1251_acx_conn_monit_params(struct wl1251 *wl)
556{
557 struct acx_conn_monit_params *acx;
558 int ret;
559
560 wl1251_debug(DEBUG_ACX, "acx connection monitor parameters");
561
562 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
563 if (!acx) {
564 ret = -ENOMEM;
565 goto out;
566 }
567
568 acx->synch_fail_thold = SYNCH_FAIL_DEFAULT_THRESHOLD;
569 acx->bss_lose_timeout = NO_BEACON_DEFAULT_TIMEOUT;
570
571 ret = wl1251_cmd_configure(wl, ACX_CONN_MONIT_PARAMS,
572 acx, sizeof(*acx));
573 if (ret < 0) {
574 wl1251_warning("failed to set connection monitor "
575 "parameters: %d", ret);
576 goto out;
577 }
578
579out:
580 kfree(acx);
581 return ret;
582}
583
584int wl1251_acx_sg_enable(struct wl1251 *wl)
585{
586 struct acx_bt_wlan_coex *pta;
587 int ret;
588
589 wl1251_debug(DEBUG_ACX, "acx sg enable");
590
591 pta = kzalloc(sizeof(*pta), GFP_KERNEL);
592 if (!pta) {
593 ret = -ENOMEM;
594 goto out;
595 }
596
597 pta->enable = SG_ENABLE;
598
599 ret = wl1251_cmd_configure(wl, ACX_SG_ENABLE, pta, sizeof(*pta));
600 if (ret < 0) {
601 wl1251_warning("failed to set softgemini enable: %d", ret);
602 goto out;
603 }
604
605out:
606 kfree(pta);
607 return ret;
608}
609
610int wl1251_acx_sg_cfg(struct wl1251 *wl)
611{
612 struct acx_bt_wlan_coex_param *param;
613 int ret;
614
615 wl1251_debug(DEBUG_ACX, "acx sg cfg");
616
617 param = kzalloc(sizeof(*param), GFP_KERNEL);
618 if (!param) {
619 ret = -ENOMEM;
620 goto out;
621 }
622
623 /* BT-WLAN coext parameters */
624 param->min_rate = RATE_INDEX_24MBPS;
625 param->bt_hp_max_time = PTA_BT_HP_MAXTIME_DEF;
626 param->wlan_hp_max_time = PTA_WLAN_HP_MAX_TIME_DEF;
627 param->sense_disable_timer = PTA_SENSE_DISABLE_TIMER_DEF;
628 param->rx_time_bt_hp = PTA_PROTECTIVE_RX_TIME_DEF;
629 param->tx_time_bt_hp = PTA_PROTECTIVE_TX_TIME_DEF;
630 param->rx_time_bt_hp_fast = PTA_PROTECTIVE_RX_TIME_FAST_DEF;
631 param->tx_time_bt_hp_fast = PTA_PROTECTIVE_TX_TIME_FAST_DEF;
632 param->wlan_cycle_fast = PTA_CYCLE_TIME_FAST_DEF;
633 param->bt_anti_starvation_period = PTA_ANTI_STARVE_PERIOD_DEF;
634 param->next_bt_lp_packet = PTA_TIMEOUT_NEXT_BT_LP_PACKET_DEF;
635 param->wake_up_beacon = PTA_TIME_BEFORE_BEACON_DEF;
636 param->hp_dm_max_guard_time = PTA_HPDM_MAX_TIME_DEF;
637 param->next_wlan_packet = PTA_TIME_OUT_NEXT_WLAN_DEF;
638 param->antenna_type = PTA_ANTENNA_TYPE_DEF;
639 param->signal_type = PTA_SIGNALING_TYPE_DEF;
640 param->afh_leverage_on = PTA_AFH_LEVERAGE_ON_DEF;
641 param->quiet_cycle_num = PTA_NUMBER_QUIET_CYCLE_DEF;
642 param->max_cts = PTA_MAX_NUM_CTS_DEF;
643 param->wlan_packets_num = PTA_NUMBER_OF_WLAN_PACKETS_DEF;
644 param->bt_packets_num = PTA_NUMBER_OF_BT_PACKETS_DEF;
645 param->missed_rx_avalanche = PTA_RX_FOR_AVALANCHE_DEF;
646 param->wlan_elp_hp = PTA_ELP_HP_DEF;
647 param->bt_anti_starvation_cycles = PTA_ANTI_STARVE_NUM_CYCLE_DEF;
648 param->ack_mode_dual_ant = PTA_ACK_MODE_DEF;
649 param->pa_sd_enable = PTA_ALLOW_PA_SD_DEF;
650 param->pta_auto_mode_enable = PTA_AUTO_MODE_NO_CTS_DEF;
651 param->bt_hp_respected_num = PTA_BT_HP_RESPECTED_DEF;
652
653 ret = wl1251_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param));
654 if (ret < 0) {
655 wl1251_warning("failed to set sg config: %d", ret);
656 goto out;
657 }
658
659out:
660 kfree(param);
661 return ret;
662}
663
664int wl1251_acx_cca_threshold(struct wl1251 *wl)
665{
666 struct acx_energy_detection *detection;
667 int ret;
668
669 wl1251_debug(DEBUG_ACX, "acx cca threshold");
670
671 detection = kzalloc(sizeof(*detection), GFP_KERNEL);
672 if (!detection) {
673 ret = -ENOMEM;
674 goto out;
675 }
676
677 detection->rx_cca_threshold = CCA_THRSH_DISABLE_ENERGY_D;
678 detection->tx_energy_detection = 0;
679
680 ret = wl1251_cmd_configure(wl, ACX_CCA_THRESHOLD,
681 detection, sizeof(*detection));
682 if (ret < 0)
683 wl1251_warning("failed to set cca threshold: %d", ret);
684
685out:
686 kfree(detection);
687 return ret;
688}
689
690int wl1251_acx_bcn_dtim_options(struct wl1251 *wl)
691{
692 struct acx_beacon_broadcast *bb;
693 int ret;
694
695 wl1251_debug(DEBUG_ACX, "acx bcn dtim options");
696
697 bb = kzalloc(sizeof(*bb), GFP_KERNEL);
698 if (!bb) {
699 ret = -ENOMEM;
700 goto out;
701 }
702
703 bb->beacon_rx_timeout = BCN_RX_TIMEOUT_DEF_VALUE;
704 bb->broadcast_timeout = BROADCAST_RX_TIMEOUT_DEF_VALUE;
705 bb->rx_broadcast_in_ps = RX_BROADCAST_IN_PS_DEF_VALUE;
706 bb->ps_poll_threshold = CONSECUTIVE_PS_POLL_FAILURE_DEF;
707
708 ret = wl1251_cmd_configure(wl, ACX_BCN_DTIM_OPTIONS, bb, sizeof(*bb));
709 if (ret < 0) {
710 wl1251_warning("failed to set rx config: %d", ret);
711 goto out;
712 }
713
714out:
715 kfree(bb);
716 return ret;
717}
718
719int wl1251_acx_aid(struct wl1251 *wl, u16 aid)
720{
721 struct acx_aid *acx_aid;
722 int ret;
723
724 wl1251_debug(DEBUG_ACX, "acx aid");
725
726 acx_aid = kzalloc(sizeof(*acx_aid), GFP_KERNEL);
727 if (!acx_aid) {
728 ret = -ENOMEM;
729 goto out;
730 }
731
732 acx_aid->aid = aid;
733
734 ret = wl1251_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid));
735 if (ret < 0) {
736 wl1251_warning("failed to set aid: %d", ret);
737 goto out;
738 }
739
740out:
741 kfree(acx_aid);
742 return ret;
743}
744
745int wl1251_acx_event_mbox_mask(struct wl1251 *wl, u32 event_mask)
746{
747 struct acx_event_mask *mask;
748 int ret;
749
750 wl1251_debug(DEBUG_ACX, "acx event mbox mask");
751
752 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
753 if (!mask) {
754 ret = -ENOMEM;
755 goto out;
756 }
757
758 /* high event mask is unused */
759 mask->high_event_mask = 0xffffffff;
760
761 mask->event_mask = event_mask;
762
763 ret = wl1251_cmd_configure(wl, ACX_EVENT_MBOX_MASK,
764 mask, sizeof(*mask));
765 if (ret < 0) {
766 wl1251_warning("failed to set acx_event_mbox_mask: %d", ret);
767 goto out;
768 }
769
770out:
771 kfree(mask);
772 return ret;
773}
774
775int wl1251_acx_low_rssi(struct wl1251 *wl, s8 threshold, u8 weight,
776 u8 depth, enum wl1251_acx_low_rssi_type type)
777{
778 struct acx_low_rssi *rssi;
779 int ret;
780
781 wl1251_debug(DEBUG_ACX, "acx low rssi");
782
783 rssi = kzalloc(sizeof(*rssi), GFP_KERNEL);
784 if (!rssi)
785 return -ENOMEM;
786
787 rssi->threshold = threshold;
788 rssi->weight = weight;
789 rssi->depth = depth;
790 rssi->type = type;
791
792 ret = wl1251_cmd_configure(wl, ACX_LOW_RSSI, rssi, sizeof(*rssi));
793 if (ret < 0)
794 wl1251_warning("failed to set low rssi threshold: %d", ret);
795
796 kfree(rssi);
797 return ret;
798}
799
800int wl1251_acx_set_preamble(struct wl1251 *wl, enum acx_preamble_type preamble)
801{
802 struct acx_preamble *acx;
803 int ret;
804
805 wl1251_debug(DEBUG_ACX, "acx_set_preamble");
806
807 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
808 if (!acx) {
809 ret = -ENOMEM;
810 goto out;
811 }
812
813 acx->preamble = preamble;
814
815 ret = wl1251_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx));
816 if (ret < 0) {
817 wl1251_warning("Setting of preamble failed: %d", ret);
818 goto out;
819 }
820
821out:
822 kfree(acx);
823 return ret;
824}
825
826int wl1251_acx_cts_protect(struct wl1251 *wl,
827 enum acx_ctsprotect_type ctsprotect)
828{
829 struct acx_ctsprotect *acx;
830 int ret;
831
832 wl1251_debug(DEBUG_ACX, "acx_set_ctsprotect");
833
834 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
835 if (!acx) {
836 ret = -ENOMEM;
837 goto out;
838 }
839
840 acx->ctsprotect = ctsprotect;
841
842 ret = wl1251_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx));
843 if (ret < 0) {
844 wl1251_warning("Setting of ctsprotect failed: %d", ret);
845 goto out;
846 }
847
848out:
849 kfree(acx);
850 return ret;
851}
852
853int wl1251_acx_tsf_info(struct wl1251 *wl, u64 *mactime)
854{
855 struct acx_tsf_info *tsf_info;
856 int ret;
857
858 tsf_info = kzalloc(sizeof(*tsf_info), GFP_KERNEL);
859 if (!tsf_info) {
860 ret = -ENOMEM;
861 goto out;
862 }
863
864 ret = wl1251_cmd_interrogate(wl, ACX_TSF_INFO,
865 tsf_info, sizeof(*tsf_info));
866 if (ret < 0) {
867 wl1251_warning("ACX_FW_REV interrogate failed");
868 goto out;
869 }
870
871 *mactime = tsf_info->current_tsf_lsb |
872 (tsf_info->current_tsf_msb << 31);
873
874out:
875 kfree(tsf_info);
876 return ret;
877}
878
879int wl1251_acx_statistics(struct wl1251 *wl, struct acx_statistics *stats)
880{
881 int ret;
882
883 wl1251_debug(DEBUG_ACX, "acx statistics");
884
885 ret = wl1251_cmd_interrogate(wl, ACX_STATISTICS, stats,
886 sizeof(*stats));
887 if (ret < 0) {
888 wl1251_warning("acx statistics failed: %d", ret);
889 return -ENOMEM;
890 }
891
892 return 0;
893}
894
895int wl1251_acx_rate_policies(struct wl1251 *wl)
896{
897 struct acx_rate_policy *acx;
898 int ret = 0;
899
900 wl1251_debug(DEBUG_ACX, "acx rate policies");
901
902 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
903
904 if (!acx) {
905 ret = -ENOMEM;
906 goto out;
907 }
908
909 /* configure one default (one-size-fits-all) rate class */
910 acx->rate_class_cnt = 1;
911 acx->rate_class[0].enabled_rates = ACX_RATE_MASK_UNSPECIFIED;
912 acx->rate_class[0].short_retry_limit = ACX_RATE_RETRY_LIMIT;
913 acx->rate_class[0].long_retry_limit = ACX_RATE_RETRY_LIMIT;
914 acx->rate_class[0].aflags = 0;
915
916 ret = wl1251_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
917 if (ret < 0) {
918 wl1251_warning("Setting of rate policies failed: %d", ret);
919 goto out;
920 }
921
922out:
923 kfree(acx);
924 return ret;
925}
926
927int wl1251_acx_mem_cfg(struct wl1251 *wl)
928{
929 struct wl1251_acx_config_memory *mem_conf;
930 int ret, i;
931
932 wl1251_debug(DEBUG_ACX, "acx mem cfg");
933
934 mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL);
935 if (!mem_conf) {
936 ret = -ENOMEM;
937 goto out;
938 }
939
940 /* memory config */
941 mem_conf->mem_config.num_stations = cpu_to_le16(DEFAULT_NUM_STATIONS);
942 mem_conf->mem_config.rx_mem_block_num = 35;
943 mem_conf->mem_config.tx_min_mem_block_num = 64;
944 mem_conf->mem_config.num_tx_queues = MAX_TX_QUEUES;
945 mem_conf->mem_config.host_if_options = HOSTIF_PKT_RING;
946 mem_conf->mem_config.num_ssid_profiles = 1;
947 mem_conf->mem_config.debug_buffer_size =
948 cpu_to_le16(TRACE_BUFFER_MAX_SIZE);
949
950 /* RX queue config */
951 mem_conf->rx_queue_config.dma_address = 0;
952 mem_conf->rx_queue_config.num_descs = ACX_RX_DESC_DEF;
953 mem_conf->rx_queue_config.priority = DEFAULT_RXQ_PRIORITY;
954 mem_conf->rx_queue_config.type = DEFAULT_RXQ_TYPE;
955
956 /* TX queue config */
957 for (i = 0; i < MAX_TX_QUEUES; i++) {
958 mem_conf->tx_queue_config[i].num_descs = ACX_TX_DESC_DEF;
959 mem_conf->tx_queue_config[i].attributes = i;
960 }
961
962 ret = wl1251_cmd_configure(wl, ACX_MEM_CFG, mem_conf,
963 sizeof(*mem_conf));
964 if (ret < 0) {
965 wl1251_warning("wl1251 mem config failed: %d", ret);
966 goto out;
967 }
968
969out:
970 kfree(mem_conf);
971 return ret;
972}
973
974int wl1251_acx_wr_tbtt_and_dtim(struct wl1251 *wl, u16 tbtt, u8 dtim)
975{
976 struct wl1251_acx_wr_tbtt_and_dtim *acx;
977 int ret;
978
979 wl1251_debug(DEBUG_ACX, "acx tbtt and dtim");
980
981 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
982 if (!acx) {
983 ret = -ENOMEM;
984 goto out;
985 }
986
987 acx->tbtt = tbtt;
988 acx->dtim = dtim;
989
990 ret = wl1251_cmd_configure(wl, ACX_WR_TBTT_AND_DTIM,
991 acx, sizeof(*acx));
992 if (ret < 0) {
993 wl1251_warning("failed to set tbtt and dtim: %d", ret);
994 goto out;
995 }
996
997out:
998 kfree(acx);
999 return ret;
1000}
1001
1002int wl1251_acx_bet_enable(struct wl1251 *wl, enum wl1251_acx_bet_mode mode,
1003 u8 max_consecutive)
1004{
1005 struct wl1251_acx_bet_enable *acx;
1006 int ret;
1007
1008 wl1251_debug(DEBUG_ACX, "acx bet enable");
1009
1010 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1011 if (!acx) {
1012 ret = -ENOMEM;
1013 goto out;
1014 }
1015
1016 acx->enable = mode;
1017 acx->max_consecutive = max_consecutive;
1018
1019 ret = wl1251_cmd_configure(wl, ACX_BET_ENABLE, acx, sizeof(*acx));
1020 if (ret < 0) {
1021 wl1251_warning("wl1251 acx bet enable failed: %d", ret);
1022 goto out;
1023 }
1024
1025out:
1026 kfree(acx);
1027 return ret;
1028}
1029
1030int wl1251_acx_ac_cfg(struct wl1251 *wl, u8 ac, u8 cw_min, u16 cw_max,
1031 u8 aifs, u16 txop)
1032{
1033 struct wl1251_acx_ac_cfg *acx;
1034 int ret = 0;
1035
1036 wl1251_debug(DEBUG_ACX, "acx ac cfg %d cw_ming %d cw_max %d "
1037 "aifs %d txop %d", ac, cw_min, cw_max, aifs, txop);
1038
1039 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1040
1041 if (!acx) {
1042 ret = -ENOMEM;
1043 goto out;
1044 }
1045
1046 acx->ac = ac;
1047 acx->cw_min = cw_min;
1048 acx->cw_max = cw_max;
1049 acx->aifsn = aifs;
1050 acx->txop_limit = txop;
1051
1052 ret = wl1251_cmd_configure(wl, ACX_AC_CFG, acx, sizeof(*acx));
1053 if (ret < 0) {
1054 wl1251_warning("acx ac cfg failed: %d", ret);
1055 goto out;
1056 }
1057
1058out:
1059 kfree(acx);
1060 return ret;
1061}
1062
1063int wl1251_acx_tid_cfg(struct wl1251 *wl, u8 queue,
1064 enum wl1251_acx_channel_type type,
1065 u8 tsid, enum wl1251_acx_ps_scheme ps_scheme,
1066 enum wl1251_acx_ack_policy ack_policy)
1067{
1068 struct wl1251_acx_tid_cfg *acx;
1069 int ret = 0;
1070
1071 wl1251_debug(DEBUG_ACX, "acx tid cfg %d type %d tsid %d "
1072 "ps_scheme %d ack_policy %d", queue, type, tsid,
1073 ps_scheme, ack_policy);
1074
1075 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1076
1077 if (!acx) {
1078 ret = -ENOMEM;
1079 goto out;
1080 }
1081
1082 acx->queue = queue;
1083 acx->type = type;
1084 acx->tsid = tsid;
1085 acx->ps_scheme = ps_scheme;
1086 acx->ack_policy = ack_policy;
1087
1088 ret = wl1251_cmd_configure(wl, ACX_TID_CFG, acx, sizeof(*acx));
1089 if (ret < 0) {
1090 wl1251_warning("acx tid cfg failed: %d", ret);
1091 goto out;
1092 }
1093
1094out:
1095 kfree(acx);
1096 return ret;
1097}
diff --git a/drivers/net/wireless/ti/wl1251/acx.h b/drivers/net/wireless/ti/wl1251/acx.h
new file mode 100644
index 000000000000..c2ba100f9b1a
--- /dev/null
+++ b/drivers/net/wireless/ti/wl1251/acx.h
@@ -0,0 +1,1483 @@
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 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22
23#ifndef __WL1251_ACX_H__
24#define __WL1251_ACX_H__
25
26#include "wl1251.h"
27#include "cmd.h"
28
29/* Target's information element */
30struct acx_header {
31 struct wl1251_cmd_header cmd;
32
33 /* acx (or information element) header */
34 u16 id;
35
36 /* payload length (not including headers */
37 u16 len;
38} __packed;
39
40struct acx_error_counter {
41 struct acx_header header;
42
43 /* The number of PLCP errors since the last time this */
44 /* information element was interrogated. This field is */
45 /* automatically cleared when it is interrogated.*/
46 u32 PLCP_error;
47
48 /* The number of FCS errors since the last time this */
49 /* information element was interrogated. This field is */
50 /* automatically cleared when it is interrogated.*/
51 u32 FCS_error;
52
53 /* The number of MPDUs without PLCP header errors received*/
54 /* since the last time this information element was interrogated. */
55 /* This field is automatically cleared when it is interrogated.*/
56 u32 valid_frame;
57
58 /* the number of missed sequence numbers in the squentially */
59 /* values of frames seq numbers */
60 u32 seq_num_miss;
61} __packed;
62
63struct acx_revision {
64 struct acx_header header;
65
66 /*
67 * The WiLink firmware version, an ASCII string x.x.x.x,
68 * that uniquely identifies the current firmware.
69 * The left most digit is incremented each time a
70 * significant change is made to the firmware, such as
71 * code redesign or new platform support.
72 * The second digit is incremented when major enhancements
73 * are added or major fixes are made.
74 * The third digit is incremented for each GA release.
75 * The fourth digit is incremented for each build.
76 * The first two digits identify a firmware release version,
77 * in other words, a unique set of features.
78 * The first three digits identify a GA release.
79 */
80 char fw_version[20];
81
82 /*
83 * This 4 byte field specifies the WiLink hardware version.
84 * bits 0 - 15: Reserved.
85 * bits 16 - 23: Version ID - The WiLink version ID
86 * (1 = first spin, 2 = second spin, and so on).
87 * bits 24 - 31: Chip ID - The WiLink chip ID.
88 */
89 u32 hw_version;
90} __packed;
91
92enum wl1251_psm_mode {
93 /* Active mode */
94 WL1251_PSM_CAM = 0,
95
96 /* Power save mode */
97 WL1251_PSM_PS = 1,
98
99 /* Extreme low power */
100 WL1251_PSM_ELP = 2,
101};
102
103struct acx_sleep_auth {
104 struct acx_header header;
105
106 /* The sleep level authorization of the device. */
107 /* 0 - Always active*/
108 /* 1 - Power down mode: light / fast sleep*/
109 /* 2 - ELP mode: Deep / Max sleep*/
110 u8 sleep_auth;
111 u8 padding[3];
112} __packed;
113
114enum {
115 HOSTIF_PCI_MASTER_HOST_INDIRECT,
116 HOSTIF_PCI_MASTER_HOST_DIRECT,
117 HOSTIF_SLAVE,
118 HOSTIF_PKT_RING,
119 HOSTIF_DONTCARE = 0xFF
120};
121
122#define DEFAULT_UCAST_PRIORITY 0
123#define DEFAULT_RX_Q_PRIORITY 0
124#define DEFAULT_NUM_STATIONS 1
125#define DEFAULT_RXQ_PRIORITY 0 /* low 0 .. 15 high */
126#define DEFAULT_RXQ_TYPE 0x07 /* All frames, Data/Ctrl/Mgmt */
127#define TRACE_BUFFER_MAX_SIZE 256
128
129#define DP_RX_PACKET_RING_CHUNK_SIZE 1600
130#define DP_TX_PACKET_RING_CHUNK_SIZE 1600
131#define DP_RX_PACKET_RING_CHUNK_NUM 2
132#define DP_TX_PACKET_RING_CHUNK_NUM 2
133#define DP_TX_COMPLETE_TIME_OUT 20
134#define FW_TX_CMPLT_BLOCK_SIZE 16
135
136struct acx_data_path_params {
137 struct acx_header header;
138
139 u16 rx_packet_ring_chunk_size;
140 u16 tx_packet_ring_chunk_size;
141
142 u8 rx_packet_ring_chunk_num;
143 u8 tx_packet_ring_chunk_num;
144
145 /*
146 * Maximum number of packets that can be gathered
147 * in the TX complete ring before an interrupt
148 * is generated.
149 */
150 u8 tx_complete_threshold;
151
152 /* Number of pending TX complete entries in cyclic ring.*/
153 u8 tx_complete_ring_depth;
154
155 /*
156 * Max num microseconds since a packet enters the TX
157 * complete ring until an interrupt is generated.
158 */
159 u32 tx_complete_timeout;
160} __packed;
161
162
163struct acx_data_path_params_resp {
164 struct acx_header header;
165
166 u16 rx_packet_ring_chunk_size;
167 u16 tx_packet_ring_chunk_size;
168
169 u8 rx_packet_ring_chunk_num;
170 u8 tx_packet_ring_chunk_num;
171
172 u8 pad[2];
173
174 u32 rx_packet_ring_addr;
175 u32 tx_packet_ring_addr;
176
177 u32 rx_control_addr;
178 u32 tx_control_addr;
179
180 u32 tx_complete_addr;
181} __packed;
182
183#define TX_MSDU_LIFETIME_MIN 0
184#define TX_MSDU_LIFETIME_MAX 3000
185#define TX_MSDU_LIFETIME_DEF 512
186#define RX_MSDU_LIFETIME_MIN 0
187#define RX_MSDU_LIFETIME_MAX 0xFFFFFFFF
188#define RX_MSDU_LIFETIME_DEF 512000
189
190struct acx_rx_msdu_lifetime {
191 struct acx_header header;
192
193 /*
194 * The maximum amount of time, in TU, before the
195 * firmware discards the MSDU.
196 */
197 u32 lifetime;
198} __packed;
199
200/*
201 * RX Config Options Table
202 * Bit Definition
203 * === ==========
204 * 31:14 Reserved
205 * 13 Copy RX Status - when set, write three receive status words
206 * to top of rx'd MPDUs.
207 * When cleared, do not write three status words (added rev 1.5)
208 * 12 Reserved
209 * 11 RX Complete upon FCS error - when set, give rx complete
210 * interrupt for FCS errors, after the rx filtering, e.g. unicast
211 * frames not to us with FCS error will not generate an interrupt.
212 * 10 SSID Filter Enable - When set, the WiLink discards all beacon,
213 * probe request, and probe response frames with an SSID that does
214 * not match the SSID specified by the host in the START/JOIN
215 * command.
216 * When clear, the WiLink receives frames with any SSID.
217 * 9 Broadcast Filter Enable - When set, the WiLink discards all
218 * broadcast frames. When clear, the WiLink receives all received
219 * broadcast frames.
220 * 8:6 Reserved
221 * 5 BSSID Filter Enable - When set, the WiLink discards any frames
222 * with a BSSID that does not match the BSSID specified by the
223 * host.
224 * When clear, the WiLink receives frames from any BSSID.
225 * 4 MAC Addr Filter - When set, the WiLink discards any frames
226 * with a destination address that does not match the MAC address
227 * of the adaptor.
228 * When clear, the WiLink receives frames destined to any MAC
229 * address.
230 * 3 Promiscuous - When set, the WiLink receives all valid frames
231 * (i.e., all frames that pass the FCS check).
232 * When clear, only frames that pass the other filters specified
233 * are received.
234 * 2 FCS - When set, the WiLink includes the FCS with the received
235 * frame.
236 * When cleared, the FCS is discarded.
237 * 1 PLCP header - When set, write all data from baseband to frame
238 * buffer including PHY header.
239 * 0 Reserved - Always equal to 0.
240 *
241 * RX Filter Options Table
242 * Bit Definition
243 * === ==========
244 * 31:12 Reserved - Always equal to 0.
245 * 11 Association - When set, the WiLink receives all association
246 * related frames (association request/response, reassocation
247 * request/response, and disassociation). When clear, these frames
248 * are discarded.
249 * 10 Auth/De auth - When set, the WiLink receives all authentication
250 * and de-authentication frames. When clear, these frames are
251 * discarded.
252 * 9 Beacon - When set, the WiLink receives all beacon frames.
253 * When clear, these frames are discarded.
254 * 8 Contention Free - When set, the WiLink receives all contention
255 * free frames.
256 * When clear, these frames are discarded.
257 * 7 Control - When set, the WiLink receives all control frames.
258 * When clear, these frames are discarded.
259 * 6 Data - When set, the WiLink receives all data frames.
260 * When clear, these frames are discarded.
261 * 5 FCS Error - When set, the WiLink receives frames that have FCS
262 * errors.
263 * When clear, these frames are discarded.
264 * 4 Management - When set, the WiLink receives all management
265 * frames.
266 * When clear, these frames are discarded.
267 * 3 Probe Request - When set, the WiLink receives all probe request
268 * frames.
269 * When clear, these frames are discarded.
270 * 2 Probe Response - When set, the WiLink receives all probe
271 * response frames.
272 * When clear, these frames are discarded.
273 * 1 RTS/CTS/ACK - When set, the WiLink receives all RTS, CTS and ACK
274 * frames.
275 * When clear, these frames are discarded.
276 * 0 Rsvd Type/Sub Type - When set, the WiLink receives all frames
277 * that have reserved frame types and sub types as defined by the
278 * 802.11 specification.
279 * When clear, these frames are discarded.
280 */
281struct acx_rx_config {
282 struct acx_header header;
283
284 u32 config_options;
285 u32 filter_options;
286} __packed;
287
288enum {
289 QOS_AC_BE = 0,
290 QOS_AC_BK,
291 QOS_AC_VI,
292 QOS_AC_VO,
293 QOS_HIGHEST_AC_INDEX = QOS_AC_VO,
294};
295
296#define MAX_NUM_OF_AC (QOS_HIGHEST_AC_INDEX+1)
297#define FIRST_AC_INDEX QOS_AC_BE
298#define MAX_NUM_OF_802_1d_TAGS 8
299#define AC_PARAMS_MAX_TSID 15
300#define MAX_APSD_CONF 0xffff
301
302#define QOS_TX_HIGH_MIN (0)
303#define QOS_TX_HIGH_MAX (100)
304
305#define QOS_TX_HIGH_BK_DEF (25)
306#define QOS_TX_HIGH_BE_DEF (35)
307#define QOS_TX_HIGH_VI_DEF (35)
308#define QOS_TX_HIGH_VO_DEF (35)
309
310#define QOS_TX_LOW_BK_DEF (15)
311#define QOS_TX_LOW_BE_DEF (25)
312#define QOS_TX_LOW_VI_DEF (25)
313#define QOS_TX_LOW_VO_DEF (25)
314
315struct acx_tx_queue_qos_config {
316 struct acx_header header;
317
318 u8 qid;
319 u8 pad[3];
320
321 /* Max number of blocks allowd in the queue */
322 u16 high_threshold;
323
324 /* Lowest memory blocks guaranteed for this queue */
325 u16 low_threshold;
326} __packed;
327
328struct acx_packet_detection {
329 struct acx_header header;
330
331 u32 threshold;
332} __packed;
333
334
335enum acx_slot_type {
336 SLOT_TIME_LONG = 0,
337 SLOT_TIME_SHORT = 1,
338 DEFAULT_SLOT_TIME = SLOT_TIME_SHORT,
339 MAX_SLOT_TIMES = 0xFF
340};
341
342#define STATION_WONE_INDEX 0
343
344struct acx_slot {
345 struct acx_header header;
346
347 u8 wone_index; /* Reserved */
348 u8 slot_time;
349 u8 reserved[6];
350} __packed;
351
352
353#define ADDRESS_GROUP_MAX (8)
354#define ADDRESS_GROUP_MAX_LEN (ETH_ALEN * ADDRESS_GROUP_MAX)
355
356struct acx_dot11_grp_addr_tbl {
357 struct acx_header header;
358
359 u8 enabled;
360 u8 num_groups;
361 u8 pad[2];
362 u8 mac_table[ADDRESS_GROUP_MAX_LEN];
363} __packed;
364
365
366#define RX_TIMEOUT_PS_POLL_MIN 0
367#define RX_TIMEOUT_PS_POLL_MAX (200000)
368#define RX_TIMEOUT_PS_POLL_DEF (15)
369#define RX_TIMEOUT_UPSD_MIN 0
370#define RX_TIMEOUT_UPSD_MAX (200000)
371#define RX_TIMEOUT_UPSD_DEF (15)
372
373struct acx_rx_timeout {
374 struct acx_header header;
375
376 /*
377 * The longest time the STA will wait to receive
378 * traffic from the AP after a PS-poll has been
379 * transmitted.
380 */
381 u16 ps_poll_timeout;
382
383 /*
384 * The longest time the STA will wait to receive
385 * traffic from the AP after a frame has been sent
386 * from an UPSD enabled queue.
387 */
388 u16 upsd_timeout;
389} __packed;
390
391#define RTS_THRESHOLD_MIN 0
392#define RTS_THRESHOLD_MAX 4096
393#define RTS_THRESHOLD_DEF 2347
394
395struct acx_rts_threshold {
396 struct acx_header header;
397
398 u16 threshold;
399 u8 pad[2];
400} __packed;
401
402enum wl1251_acx_low_rssi_type {
403 /*
404 * The event is a "Level" indication which keeps triggering
405 * as long as the average RSSI is below the threshold.
406 */
407 WL1251_ACX_LOW_RSSI_TYPE_LEVEL = 0,
408
409 /*
410 * The event is an "Edge" indication which triggers
411 * only when the RSSI threshold is crossed from above.
412 */
413 WL1251_ACX_LOW_RSSI_TYPE_EDGE = 1,
414};
415
416struct acx_low_rssi {
417 struct acx_header header;
418
419 /*
420 * The threshold (in dBm) below (or above after low rssi
421 * indication) which the firmware generates an interrupt to the
422 * host. This parameter is signed.
423 */
424 s8 threshold;
425
426 /*
427 * The weight of the current RSSI sample, before adding the new
428 * sample, that is used to calculate the average RSSI.
429 */
430 u8 weight;
431
432 /*
433 * The number of Beacons/Probe response frames that will be
434 * received before issuing the Low or Regained RSSI event.
435 */
436 u8 depth;
437
438 /*
439 * Configures how the Low RSSI Event is triggered. Refer to
440 * enum wl1251_acx_low_rssi_type for more.
441 */
442 u8 type;
443} __packed;
444
445struct acx_beacon_filter_option {
446 struct acx_header header;
447
448 u8 enable;
449
450 /*
451 * The number of beacons without the unicast TIM
452 * bit set that the firmware buffers before
453 * signaling the host about ready frames.
454 * When set to 0 and the filter is enabled, beacons
455 * without the unicast TIM bit set are dropped.
456 */
457 u8 max_num_beacons;
458 u8 pad[2];
459} __packed;
460
461/*
462 * ACXBeaconFilterEntry (not 221)
463 * Byte Offset Size (Bytes) Definition
464 * =========== ============ ==========
465 * 0 1 IE identifier
466 * 1 1 Treatment bit mask
467 *
468 * ACXBeaconFilterEntry (221)
469 * Byte Offset Size (Bytes) Definition
470 * =========== ============ ==========
471 * 0 1 IE identifier
472 * 1 1 Treatment bit mask
473 * 2 3 OUI
474 * 5 1 Type
475 * 6 2 Version
476 *
477 *
478 * Treatment bit mask - The information element handling:
479 * bit 0 - The information element is compared and transferred
480 * in case of change.
481 * bit 1 - The information element is transferred to the host
482 * with each appearance or disappearance.
483 * Note that both bits can be set at the same time.
484 */
485#define BEACON_FILTER_TABLE_MAX_IE_NUM (32)
486#define BEACON_FILTER_TABLE_MAX_VENDOR_SPECIFIC_IE_NUM (6)
487#define BEACON_FILTER_TABLE_IE_ENTRY_SIZE (2)
488#define BEACON_FILTER_TABLE_EXTRA_VENDOR_SPECIFIC_IE_SIZE (6)
489#define BEACON_FILTER_TABLE_MAX_SIZE ((BEACON_FILTER_TABLE_MAX_IE_NUM * \
490 BEACON_FILTER_TABLE_IE_ENTRY_SIZE) + \
491 (BEACON_FILTER_TABLE_MAX_VENDOR_SPECIFIC_IE_NUM * \
492 BEACON_FILTER_TABLE_EXTRA_VENDOR_SPECIFIC_IE_SIZE))
493
494#define BEACON_RULE_PASS_ON_CHANGE BIT(0)
495#define BEACON_RULE_PASS_ON_APPEARANCE BIT(1)
496
497#define BEACON_FILTER_IE_ID_CHANNEL_SWITCH_ANN (37)
498
499struct acx_beacon_filter_ie_table {
500 struct acx_header header;
501
502 u8 num_ie;
503 u8 pad[3];
504 u8 table[BEACON_FILTER_TABLE_MAX_SIZE];
505} __packed;
506
507#define SYNCH_FAIL_DEFAULT_THRESHOLD 10 /* number of beacons */
508#define NO_BEACON_DEFAULT_TIMEOUT (500) /* in microseconds */
509
510struct acx_conn_monit_params {
511 struct acx_header header;
512
513 u32 synch_fail_thold; /* number of beacons missed */
514 u32 bss_lose_timeout; /* number of TU's from synch fail */
515} __packed;
516
517enum {
518 SG_ENABLE = 0,
519 SG_DISABLE,
520 SG_SENSE_NO_ACTIVITY,
521 SG_SENSE_ACTIVE
522};
523
524struct acx_bt_wlan_coex {
525 struct acx_header header;
526
527 /*
528 * 0 -> PTA enabled
529 * 1 -> PTA disabled
530 * 2 -> sense no active mode, i.e.
531 * an interrupt is sent upon
532 * BT activity.
533 * 3 -> PTA is switched on in response
534 * to the interrupt sending.
535 */
536 u8 enable;
537 u8 pad[3];
538} __packed;
539
540#define PTA_ANTENNA_TYPE_DEF (0)
541#define PTA_BT_HP_MAXTIME_DEF (2000)
542#define PTA_WLAN_HP_MAX_TIME_DEF (5000)
543#define PTA_SENSE_DISABLE_TIMER_DEF (1350)
544#define PTA_PROTECTIVE_RX_TIME_DEF (1500)
545#define PTA_PROTECTIVE_TX_TIME_DEF (1500)
546#define PTA_TIMEOUT_NEXT_BT_LP_PACKET_DEF (3000)
547#define PTA_SIGNALING_TYPE_DEF (1)
548#define PTA_AFH_LEVERAGE_ON_DEF (0)
549#define PTA_NUMBER_QUIET_CYCLE_DEF (0)
550#define PTA_MAX_NUM_CTS_DEF (3)
551#define PTA_NUMBER_OF_WLAN_PACKETS_DEF (2)
552#define PTA_NUMBER_OF_BT_PACKETS_DEF (2)
553#define PTA_PROTECTIVE_RX_TIME_FAST_DEF (1500)
554#define PTA_PROTECTIVE_TX_TIME_FAST_DEF (3000)
555#define PTA_CYCLE_TIME_FAST_DEF (8700)
556#define PTA_RX_FOR_AVALANCHE_DEF (5)
557#define PTA_ELP_HP_DEF (0)
558#define PTA_ANTI_STARVE_PERIOD_DEF (500)
559#define PTA_ANTI_STARVE_NUM_CYCLE_DEF (4)
560#define PTA_ALLOW_PA_SD_DEF (1)
561#define PTA_TIME_BEFORE_BEACON_DEF (6300)
562#define PTA_HPDM_MAX_TIME_DEF (1600)
563#define PTA_TIME_OUT_NEXT_WLAN_DEF (2550)
564#define PTA_AUTO_MODE_NO_CTS_DEF (0)
565#define PTA_BT_HP_RESPECTED_DEF (3)
566#define PTA_WLAN_RX_MIN_RATE_DEF (24)
567#define PTA_ACK_MODE_DEF (1)
568
569struct acx_bt_wlan_coex_param {
570 struct acx_header header;
571
572 /*
573 * The minimum rate of a received WLAN packet in the STA,
574 * during protective mode, of which a new BT-HP request
575 * during this Rx will always be respected and gain the antenna.
576 */
577 u32 min_rate;
578
579 /* Max time the BT HP will be respected. */
580 u16 bt_hp_max_time;
581
582 /* Max time the WLAN HP will be respected. */
583 u16 wlan_hp_max_time;
584
585 /*
586 * The time between the last BT activity
587 * and the moment when the sense mode returns
588 * to SENSE_INACTIVE.
589 */
590 u16 sense_disable_timer;
591
592 /* Time before the next BT HP instance */
593 u16 rx_time_bt_hp;
594 u16 tx_time_bt_hp;
595
596 /* range: 10-20000 default: 1500 */
597 u16 rx_time_bt_hp_fast;
598 u16 tx_time_bt_hp_fast;
599
600 /* range: 2000-65535 default: 8700 */
601 u16 wlan_cycle_fast;
602
603 /* range: 0 - 15000 (Msec) default: 1000 */
604 u16 bt_anti_starvation_period;
605
606 /* range 400-10000(Usec) default: 3000 */
607 u16 next_bt_lp_packet;
608
609 /* Deafult: worst case for BT DH5 traffic */
610 u16 wake_up_beacon;
611
612 /* range: 0-50000(Usec) default: 1050 */
613 u16 hp_dm_max_guard_time;
614
615 /*
616 * This is to prevent both BT & WLAN antenna
617 * starvation.
618 * Range: 100-50000(Usec) default:2550
619 */
620 u16 next_wlan_packet;
621
622 /* 0 -> shared antenna */
623 u8 antenna_type;
624
625 /*
626 * 0 -> TI legacy
627 * 1 -> Palau
628 */
629 u8 signal_type;
630
631 /*
632 * BT AFH status
633 * 0 -> no AFH
634 * 1 -> from dedicated GPIO
635 * 2 -> AFH on (from host)
636 */
637 u8 afh_leverage_on;
638
639 /*
640 * The number of cycles during which no
641 * TX will be sent after 1 cycle of RX
642 * transaction in protective mode
643 */
644 u8 quiet_cycle_num;
645
646 /*
647 * The maximum number of CTSs that will
648 * be sent for receiving RX packet in
649 * protective mode
650 */
651 u8 max_cts;
652
653 /*
654 * The number of WLAN packets
655 * transferred in common mode before
656 * switching to BT.
657 */
658 u8 wlan_packets_num;
659
660 /*
661 * The number of BT packets
662 * transferred in common mode before
663 * switching to WLAN.
664 */
665 u8 bt_packets_num;
666
667 /* range: 1-255 default: 5 */
668 u8 missed_rx_avalanche;
669
670 /* range: 0-1 default: 1 */
671 u8 wlan_elp_hp;
672
673 /* range: 0 - 15 default: 4 */
674 u8 bt_anti_starvation_cycles;
675
676 u8 ack_mode_dual_ant;
677
678 /*
679 * Allow PA_SD assertion/de-assertion
680 * during enabled BT activity.
681 */
682 u8 pa_sd_enable;
683
684 /*
685 * Enable/Disable PTA in auto mode:
686 * Support Both Active & P.S modes
687 */
688 u8 pta_auto_mode_enable;
689
690 /* range: 0 - 20 default: 1 */
691 u8 bt_hp_respected_num;
692} __packed;
693
694#define CCA_THRSH_ENABLE_ENERGY_D 0x140A
695#define CCA_THRSH_DISABLE_ENERGY_D 0xFFEF
696
697struct acx_energy_detection {
698 struct acx_header header;
699
700 /* The RX Clear Channel Assessment threshold in the PHY */
701 u16 rx_cca_threshold;
702 u8 tx_energy_detection;
703 u8 pad;
704} __packed;
705
706#define BCN_RX_TIMEOUT_DEF_VALUE 10000
707#define BROADCAST_RX_TIMEOUT_DEF_VALUE 20000
708#define RX_BROADCAST_IN_PS_DEF_VALUE 1
709#define CONSECUTIVE_PS_POLL_FAILURE_DEF 4
710
711struct acx_beacon_broadcast {
712 struct acx_header header;
713
714 u16 beacon_rx_timeout;
715 u16 broadcast_timeout;
716
717 /* Enables receiving of broadcast packets in PS mode */
718 u8 rx_broadcast_in_ps;
719
720 /* Consecutive PS Poll failures before updating the host */
721 u8 ps_poll_threshold;
722 u8 pad[2];
723} __packed;
724
725struct acx_event_mask {
726 struct acx_header header;
727
728 u32 event_mask;
729 u32 high_event_mask; /* Unused */
730} __packed;
731
732#define CFG_RX_FCS BIT(2)
733#define CFG_RX_ALL_GOOD BIT(3)
734#define CFG_UNI_FILTER_EN BIT(4)
735#define CFG_BSSID_FILTER_EN BIT(5)
736#define CFG_MC_FILTER_EN BIT(6)
737#define CFG_MC_ADDR0_EN BIT(7)
738#define CFG_MC_ADDR1_EN BIT(8)
739#define CFG_BC_REJECT_EN BIT(9)
740#define CFG_SSID_FILTER_EN BIT(10)
741#define CFG_RX_INT_FCS_ERROR BIT(11)
742#define CFG_RX_INT_ENCRYPTED BIT(12)
743#define CFG_RX_WR_RX_STATUS BIT(13)
744#define CFG_RX_FILTER_NULTI BIT(14)
745#define CFG_RX_RESERVE BIT(15)
746#define CFG_RX_TIMESTAMP_TSF BIT(16)
747
748#define CFG_RX_RSV_EN BIT(0)
749#define CFG_RX_RCTS_ACK BIT(1)
750#define CFG_RX_PRSP_EN BIT(2)
751#define CFG_RX_PREQ_EN BIT(3)
752#define CFG_RX_MGMT_EN BIT(4)
753#define CFG_RX_FCS_ERROR BIT(5)
754#define CFG_RX_DATA_EN BIT(6)
755#define CFG_RX_CTL_EN BIT(7)
756#define CFG_RX_CF_EN BIT(8)
757#define CFG_RX_BCN_EN BIT(9)
758#define CFG_RX_AUTH_EN BIT(10)
759#define CFG_RX_ASSOC_EN BIT(11)
760
761#define SCAN_PASSIVE BIT(0)
762#define SCAN_5GHZ_BAND BIT(1)
763#define SCAN_TRIGGERED BIT(2)
764#define SCAN_PRIORITY_HIGH BIT(3)
765
766struct acx_fw_gen_frame_rates {
767 struct acx_header header;
768
769 u8 tx_ctrl_frame_rate; /* RATE_* */
770 u8 tx_ctrl_frame_mod; /* CCK_* or PBCC_* */
771 u8 tx_mgt_frame_rate;
772 u8 tx_mgt_frame_mod;
773} __packed;
774
775/* STA MAC */
776struct acx_dot11_station_id {
777 struct acx_header header;
778
779 u8 mac[ETH_ALEN];
780 u8 pad[2];
781} __packed;
782
783struct acx_feature_config {
784 struct acx_header header;
785
786 u32 options;
787 u32 data_flow_options;
788} __packed;
789
790struct acx_current_tx_power {
791 struct acx_header header;
792
793 u8 current_tx_power;
794 u8 padding[3];
795} __packed;
796
797struct acx_dot11_default_key {
798 struct acx_header header;
799
800 u8 id;
801 u8 pad[3];
802} __packed;
803
804struct acx_tsf_info {
805 struct acx_header header;
806
807 u32 current_tsf_msb;
808 u32 current_tsf_lsb;
809 u32 last_TBTT_msb;
810 u32 last_TBTT_lsb;
811 u8 last_dtim_count;
812 u8 pad[3];
813} __packed;
814
815enum acx_wake_up_event {
816 WAKE_UP_EVENT_BEACON_BITMAP = 0x01, /* Wake on every Beacon*/
817 WAKE_UP_EVENT_DTIM_BITMAP = 0x02, /* Wake on every DTIM*/
818 WAKE_UP_EVENT_N_DTIM_BITMAP = 0x04, /* Wake on every Nth DTIM */
819 WAKE_UP_EVENT_N_BEACONS_BITMAP = 0x08, /* Wake on every Nth Beacon */
820 WAKE_UP_EVENT_BITS_MASK = 0x0F
821};
822
823struct acx_wake_up_condition {
824 struct acx_header header;
825
826 u8 wake_up_event; /* Only one bit can be set */
827 u8 listen_interval;
828 u8 pad[2];
829} __packed;
830
831struct acx_aid {
832 struct acx_header header;
833
834 /*
835 * To be set when associated with an AP.
836 */
837 u16 aid;
838 u8 pad[2];
839} __packed;
840
841enum acx_preamble_type {
842 ACX_PREAMBLE_LONG = 0,
843 ACX_PREAMBLE_SHORT = 1
844};
845
846struct acx_preamble {
847 struct acx_header header;
848
849 /*
850 * When set, the WiLink transmits the frames with a short preamble and
851 * when cleared, the WiLink transmits the frames with a long preamble.
852 */
853 u8 preamble;
854 u8 padding[3];
855} __packed;
856
857enum acx_ctsprotect_type {
858 CTSPROTECT_DISABLE = 0,
859 CTSPROTECT_ENABLE = 1
860};
861
862struct acx_ctsprotect {
863 struct acx_header header;
864 u8 ctsprotect;
865 u8 padding[3];
866} __packed;
867
868struct acx_tx_statistics {
869 u32 internal_desc_overflow;
870} __packed;
871
872struct acx_rx_statistics {
873 u32 out_of_mem;
874 u32 hdr_overflow;
875 u32 hw_stuck;
876 u32 dropped;
877 u32 fcs_err;
878 u32 xfr_hint_trig;
879 u32 path_reset;
880 u32 reset_counter;
881} __packed;
882
883struct acx_dma_statistics {
884 u32 rx_requested;
885 u32 rx_errors;
886 u32 tx_requested;
887 u32 tx_errors;
888} __packed;
889
890struct acx_isr_statistics {
891 /* host command complete */
892 u32 cmd_cmplt;
893
894 /* fiqisr() */
895 u32 fiqs;
896
897 /* (INT_STS_ND & INT_TRIG_RX_HEADER) */
898 u32 rx_headers;
899
900 /* (INT_STS_ND & INT_TRIG_RX_CMPLT) */
901 u32 rx_completes;
902
903 /* (INT_STS_ND & INT_TRIG_NO_RX_BUF) */
904 u32 rx_mem_overflow;
905
906 /* (INT_STS_ND & INT_TRIG_S_RX_RDY) */
907 u32 rx_rdys;
908
909 /* irqisr() */
910 u32 irqs;
911
912 /* (INT_STS_ND & INT_TRIG_TX_PROC) */
913 u32 tx_procs;
914
915 /* (INT_STS_ND & INT_TRIG_DECRYPT_DONE) */
916 u32 decrypt_done;
917
918 /* (INT_STS_ND & INT_TRIG_DMA0) */
919 u32 dma0_done;
920
921 /* (INT_STS_ND & INT_TRIG_DMA1) */
922 u32 dma1_done;
923
924 /* (INT_STS_ND & INT_TRIG_TX_EXC_CMPLT) */
925 u32 tx_exch_complete;
926
927 /* (INT_STS_ND & INT_TRIG_COMMAND) */
928 u32 commands;
929
930 /* (INT_STS_ND & INT_TRIG_RX_PROC) */
931 u32 rx_procs;
932
933 /* (INT_STS_ND & INT_TRIG_PM_802) */
934 u32 hw_pm_mode_changes;
935
936 /* (INT_STS_ND & INT_TRIG_ACKNOWLEDGE) */
937 u32 host_acknowledges;
938
939 /* (INT_STS_ND & INT_TRIG_PM_PCI) */
940 u32 pci_pm;
941
942 /* (INT_STS_ND & INT_TRIG_ACM_WAKEUP) */
943 u32 wakeups;
944
945 /* (INT_STS_ND & INT_TRIG_LOW_RSSI) */
946 u32 low_rssi;
947} __packed;
948
949struct acx_wep_statistics {
950 /* WEP address keys configured */
951 u32 addr_key_count;
952
953 /* default keys configured */
954 u32 default_key_count;
955
956 u32 reserved;
957
958 /* number of times that WEP key not found on lookup */
959 u32 key_not_found;
960
961 /* number of times that WEP key decryption failed */
962 u32 decrypt_fail;
963
964 /* WEP packets decrypted */
965 u32 packets;
966
967 /* WEP decrypt interrupts */
968 u32 interrupt;
969} __packed;
970
971#define ACX_MISSED_BEACONS_SPREAD 10
972
973struct acx_pwr_statistics {
974 /* the amount of enters into power save mode (both PD & ELP) */
975 u32 ps_enter;
976
977 /* the amount of enters into ELP mode */
978 u32 elp_enter;
979
980 /* the amount of missing beacon interrupts to the host */
981 u32 missing_bcns;
982
983 /* the amount of wake on host-access times */
984 u32 wake_on_host;
985
986 /* the amount of wake on timer-expire */
987 u32 wake_on_timer_exp;
988
989 /* the number of packets that were transmitted with PS bit set */
990 u32 tx_with_ps;
991
992 /* the number of packets that were transmitted with PS bit clear */
993 u32 tx_without_ps;
994
995 /* the number of received beacons */
996 u32 rcvd_beacons;
997
998 /* the number of entering into PowerOn (power save off) */
999 u32 power_save_off;
1000
1001 /* the number of entries into power save mode */
1002 u16 enable_ps;
1003
1004 /*
1005 * the number of exits from power save, not including failed PS
1006 * transitions
1007 */
1008 u16 disable_ps;
1009
1010 /*
1011 * the number of times the TSF counter was adjusted because
1012 * of drift
1013 */
1014 u32 fix_tsf_ps;
1015
1016 /* Gives statistics about the spread continuous missed beacons.
1017 * The 16 LSB are dedicated for the PS mode.
1018 * The 16 MSB are dedicated for the PS mode.
1019 * cont_miss_bcns_spread[0] - single missed beacon.
1020 * cont_miss_bcns_spread[1] - two continuous missed beacons.
1021 * cont_miss_bcns_spread[2] - three continuous missed beacons.
1022 * ...
1023 * cont_miss_bcns_spread[9] - ten and more continuous missed beacons.
1024 */
1025 u32 cont_miss_bcns_spread[ACX_MISSED_BEACONS_SPREAD];
1026
1027 /* the number of beacons in awake mode */
1028 u32 rcvd_awake_beacons;
1029} __packed;
1030
1031struct acx_mic_statistics {
1032 u32 rx_pkts;
1033 u32 calc_failure;
1034} __packed;
1035
1036struct acx_aes_statistics {
1037 u32 encrypt_fail;
1038 u32 decrypt_fail;
1039 u32 encrypt_packets;
1040 u32 decrypt_packets;
1041 u32 encrypt_interrupt;
1042 u32 decrypt_interrupt;
1043} __packed;
1044
1045struct acx_event_statistics {
1046 u32 heart_beat;
1047 u32 calibration;
1048 u32 rx_mismatch;
1049 u32 rx_mem_empty;
1050 u32 rx_pool;
1051 u32 oom_late;
1052 u32 phy_transmit_error;
1053 u32 tx_stuck;
1054} __packed;
1055
1056struct acx_ps_statistics {
1057 u32 pspoll_timeouts;
1058 u32 upsd_timeouts;
1059 u32 upsd_max_sptime;
1060 u32 upsd_max_apturn;
1061 u32 pspoll_max_apturn;
1062 u32 pspoll_utilization;
1063 u32 upsd_utilization;
1064} __packed;
1065
1066struct acx_rxpipe_statistics {
1067 u32 rx_prep_beacon_drop;
1068 u32 descr_host_int_trig_rx_data;
1069 u32 beacon_buffer_thres_host_int_trig_rx_data;
1070 u32 missed_beacon_host_int_trig_rx_data;
1071 u32 tx_xfr_host_int_trig_rx_data;
1072} __packed;
1073
1074struct acx_statistics {
1075 struct acx_header header;
1076
1077 struct acx_tx_statistics tx;
1078 struct acx_rx_statistics rx;
1079 struct acx_dma_statistics dma;
1080 struct acx_isr_statistics isr;
1081 struct acx_wep_statistics wep;
1082 struct acx_pwr_statistics pwr;
1083 struct acx_aes_statistics aes;
1084 struct acx_mic_statistics mic;
1085 struct acx_event_statistics event;
1086 struct acx_ps_statistics ps;
1087 struct acx_rxpipe_statistics rxpipe;
1088} __packed;
1089
1090#define ACX_MAX_RATE_CLASSES 8
1091#define ACX_RATE_MASK_UNSPECIFIED 0
1092#define ACX_RATE_RETRY_LIMIT 10
1093
1094struct acx_rate_class {
1095 u32 enabled_rates;
1096 u8 short_retry_limit;
1097 u8 long_retry_limit;
1098 u8 aflags;
1099 u8 reserved;
1100} __packed;
1101
1102struct acx_rate_policy {
1103 struct acx_header header;
1104
1105 u32 rate_class_cnt;
1106 struct acx_rate_class rate_class[ACX_MAX_RATE_CLASSES];
1107} __packed;
1108
1109struct wl1251_acx_memory {
1110 __le16 num_stations; /* number of STAs to be supported. */
1111 u16 reserved_1;
1112
1113 /*
1114 * Nmber of memory buffers for the RX mem pool.
1115 * The actual number may be less if there are
1116 * not enough blocks left for the minimum num
1117 * of TX ones.
1118 */
1119 u8 rx_mem_block_num;
1120 u8 reserved_2;
1121 u8 num_tx_queues; /* From 1 to 16 */
1122 u8 host_if_options; /* HOST_IF* */
1123 u8 tx_min_mem_block_num;
1124 u8 num_ssid_profiles;
1125 __le16 debug_buffer_size;
1126} __packed;
1127
1128
1129#define ACX_RX_DESC_MIN 1
1130#define ACX_RX_DESC_MAX 127
1131#define ACX_RX_DESC_DEF 32
1132struct wl1251_acx_rx_queue_config {
1133 u8 num_descs;
1134 u8 pad;
1135 u8 type;
1136 u8 priority;
1137 __le32 dma_address;
1138} __packed;
1139
1140#define ACX_TX_DESC_MIN 1
1141#define ACX_TX_DESC_MAX 127
1142#define ACX_TX_DESC_DEF 16
1143struct wl1251_acx_tx_queue_config {
1144 u8 num_descs;
1145 u8 pad[2];
1146 u8 attributes;
1147} __packed;
1148
1149#define MAX_TX_QUEUE_CONFIGS 5
1150#define MAX_TX_QUEUES 4
1151struct wl1251_acx_config_memory {
1152 struct acx_header header;
1153
1154 struct wl1251_acx_memory mem_config;
1155 struct wl1251_acx_rx_queue_config rx_queue_config;
1156 struct wl1251_acx_tx_queue_config tx_queue_config[MAX_TX_QUEUE_CONFIGS];
1157} __packed;
1158
1159struct wl1251_acx_mem_map {
1160 struct acx_header header;
1161
1162 void *code_start;
1163 void *code_end;
1164
1165 void *wep_defkey_start;
1166 void *wep_defkey_end;
1167
1168 void *sta_table_start;
1169 void *sta_table_end;
1170
1171 void *packet_template_start;
1172 void *packet_template_end;
1173
1174 void *queue_memory_start;
1175 void *queue_memory_end;
1176
1177 void *packet_memory_pool_start;
1178 void *packet_memory_pool_end;
1179
1180 void *debug_buffer1_start;
1181 void *debug_buffer1_end;
1182
1183 void *debug_buffer2_start;
1184 void *debug_buffer2_end;
1185
1186 /* Number of blocks FW allocated for TX packets */
1187 u32 num_tx_mem_blocks;
1188
1189 /* Number of blocks FW allocated for RX packets */
1190 u32 num_rx_mem_blocks;
1191} __packed;
1192
1193
1194struct wl1251_acx_wr_tbtt_and_dtim {
1195
1196 struct acx_header header;
1197
1198 /* Time in TUs between two consecutive beacons */
1199 u16 tbtt;
1200
1201 /*
1202 * DTIM period
1203 * For BSS: Number of TBTTs in a DTIM period (range: 1-10)
1204 * For IBSS: value shall be set to 1
1205 */
1206 u8 dtim;
1207 u8 padding;
1208} __packed;
1209
1210enum wl1251_acx_bet_mode {
1211 WL1251_ACX_BET_DISABLE = 0,
1212 WL1251_ACX_BET_ENABLE = 1,
1213};
1214
1215struct wl1251_acx_bet_enable {
1216 struct acx_header header;
1217
1218 /*
1219 * Specifies if beacon early termination procedure is enabled or
1220 * disabled, see enum wl1251_acx_bet_mode.
1221 */
1222 u8 enable;
1223
1224 /*
1225 * Specifies the maximum number of consecutive beacons that may be
1226 * early terminated. After this number is reached at least one full
1227 * beacon must be correctly received in FW before beacon ET
1228 * resumes. Range 0 - 255.
1229 */
1230 u8 max_consecutive;
1231
1232 u8 padding[2];
1233} __packed;
1234
1235struct wl1251_acx_ac_cfg {
1236 struct acx_header header;
1237
1238 /*
1239 * Access Category - The TX queue's access category
1240 * (refer to AccessCategory_enum)
1241 */
1242 u8 ac;
1243
1244 /*
1245 * The contention window minimum size (in slots) for
1246 * the access class.
1247 */
1248 u8 cw_min;
1249
1250 /*
1251 * The contention window maximum size (in slots) for
1252 * the access class.
1253 */
1254 u16 cw_max;
1255
1256 /* The AIF value (in slots) for the access class. */
1257 u8 aifsn;
1258
1259 u8 reserved;
1260
1261 /* The TX Op Limit (in microseconds) for the access class. */
1262 u16 txop_limit;
1263} __packed;
1264
1265
1266enum wl1251_acx_channel_type {
1267 CHANNEL_TYPE_DCF = 0,
1268 CHANNEL_TYPE_EDCF = 1,
1269 CHANNEL_TYPE_HCCA = 2,
1270};
1271
1272enum wl1251_acx_ps_scheme {
1273 /* regular ps: simple sending of packets */
1274 WL1251_ACX_PS_SCHEME_LEGACY = 0,
1275
1276 /* sending a packet triggers a unscheduled apsd downstream */
1277 WL1251_ACX_PS_SCHEME_UPSD_TRIGGER = 1,
1278
1279 /* a pspoll packet will be sent before every data packet */
1280 WL1251_ACX_PS_SCHEME_LEGACY_PSPOLL = 2,
1281
1282 /* scheduled apsd mode */
1283 WL1251_ACX_PS_SCHEME_SAPSD = 3,
1284};
1285
1286enum wl1251_acx_ack_policy {
1287 WL1251_ACX_ACK_POLICY_LEGACY = 0,
1288 WL1251_ACX_ACK_POLICY_NO_ACK = 1,
1289 WL1251_ACX_ACK_POLICY_BLOCK = 2,
1290};
1291
1292struct wl1251_acx_tid_cfg {
1293 struct acx_header header;
1294
1295 /* tx queue id number (0-7) */
1296 u8 queue;
1297
1298 /* channel access type for the queue, enum wl1251_acx_channel_type */
1299 u8 type;
1300
1301 /* EDCA: ac index (0-3), HCCA: traffic stream id (8-15) */
1302 u8 tsid;
1303
1304 /* ps scheme of the specified queue, enum wl1251_acx_ps_scheme */
1305 u8 ps_scheme;
1306
1307 /* the tx queue ack policy, enum wl1251_acx_ack_policy */
1308 u8 ack_policy;
1309
1310 u8 padding[3];
1311
1312 /* not supported */
1313 u32 apsdconf[2];
1314} __packed;
1315
1316/*************************************************************************
1317
1318 Host Interrupt Register (WiLink -> Host)
1319
1320**************************************************************************/
1321
1322/* RX packet is ready in Xfer buffer #0 */
1323#define WL1251_ACX_INTR_RX0_DATA BIT(0)
1324
1325/* TX result(s) are in the TX complete buffer */
1326#define WL1251_ACX_INTR_TX_RESULT BIT(1)
1327
1328/* OBSOLETE */
1329#define WL1251_ACX_INTR_TX_XFR BIT(2)
1330
1331/* RX packet is ready in Xfer buffer #1 */
1332#define WL1251_ACX_INTR_RX1_DATA BIT(3)
1333
1334/* Event was entered to Event MBOX #A */
1335#define WL1251_ACX_INTR_EVENT_A BIT(4)
1336
1337/* Event was entered to Event MBOX #B */
1338#define WL1251_ACX_INTR_EVENT_B BIT(5)
1339
1340/* OBSOLETE */
1341#define WL1251_ACX_INTR_WAKE_ON_HOST BIT(6)
1342
1343/* Trace message on MBOX #A */
1344#define WL1251_ACX_INTR_TRACE_A BIT(7)
1345
1346/* Trace message on MBOX #B */
1347#define WL1251_ACX_INTR_TRACE_B BIT(8)
1348
1349/* Command processing completion */
1350#define WL1251_ACX_INTR_CMD_COMPLETE BIT(9)
1351
1352/* Init sequence is done */
1353#define WL1251_ACX_INTR_INIT_COMPLETE BIT(14)
1354
1355#define WL1251_ACX_INTR_ALL 0xFFFFFFFF
1356
1357enum {
1358 ACX_WAKE_UP_CONDITIONS = 0x0002,
1359 ACX_MEM_CFG = 0x0003,
1360 ACX_SLOT = 0x0004,
1361 ACX_QUEUE_HEAD = 0x0005, /* for MASTER mode only */
1362 ACX_AC_CFG = 0x0007,
1363 ACX_MEM_MAP = 0x0008,
1364 ACX_AID = 0x000A,
1365 ACX_RADIO_PARAM = 0x000B, /* Not used */
1366 ACX_CFG = 0x000C, /* Not used */
1367 ACX_FW_REV = 0x000D,
1368 ACX_MEDIUM_USAGE = 0x000F,
1369 ACX_RX_CFG = 0x0010,
1370 ACX_TX_QUEUE_CFG = 0x0011, /* FIXME: only used by wl1251 */
1371 ACX_BSS_IN_PS = 0x0012, /* for AP only */
1372 ACX_STATISTICS = 0x0013, /* Debug API */
1373 ACX_FEATURE_CFG = 0x0015,
1374 ACX_MISC_CFG = 0x0017, /* Not used */
1375 ACX_TID_CFG = 0x001A,
1376 ACX_BEACON_FILTER_OPT = 0x001F,
1377 ACX_LOW_RSSI = 0x0020,
1378 ACX_NOISE_HIST = 0x0021,
1379 ACX_HDK_VERSION = 0x0022, /* ??? */
1380 ACX_PD_THRESHOLD = 0x0023,
1381 ACX_DATA_PATH_PARAMS = 0x0024, /* WO */
1382 ACX_DATA_PATH_RESP_PARAMS = 0x0024, /* RO */
1383 ACX_CCA_THRESHOLD = 0x0025,
1384 ACX_EVENT_MBOX_MASK = 0x0026,
1385#ifdef FW_RUNNING_AS_AP
1386 ACX_DTIM_PERIOD = 0x0027, /* for AP only */
1387#else
1388 ACX_WR_TBTT_AND_DTIM = 0x0027, /* STA only */
1389#endif
1390 ACX_ACI_OPTION_CFG = 0x0029, /* OBSOLETE (for 1251)*/
1391 ACX_GPIO_CFG = 0x002A, /* Not used */
1392 ACX_GPIO_SET = 0x002B, /* Not used */
1393 ACX_PM_CFG = 0x002C, /* To Be Documented */
1394 ACX_CONN_MONIT_PARAMS = 0x002D,
1395 ACX_AVERAGE_RSSI = 0x002E, /* Not used */
1396 ACX_CONS_TX_FAILURE = 0x002F,
1397 ACX_BCN_DTIM_OPTIONS = 0x0031,
1398 ACX_SG_ENABLE = 0x0032,
1399 ACX_SG_CFG = 0x0033,
1400 ACX_ANTENNA_DIVERSITY_CFG = 0x0035, /* To Be Documented */
1401 ACX_LOW_SNR = 0x0037, /* To Be Documented */
1402 ACX_BEACON_FILTER_TABLE = 0x0038,
1403 ACX_ARP_IP_FILTER = 0x0039,
1404 ACX_ROAMING_STATISTICS_TBL = 0x003B,
1405 ACX_RATE_POLICY = 0x003D,
1406 ACX_CTS_PROTECTION = 0x003E,
1407 ACX_SLEEP_AUTH = 0x003F,
1408 ACX_PREAMBLE_TYPE = 0x0040,
1409 ACX_ERROR_CNT = 0x0041,
1410 ACX_FW_GEN_FRAME_RATES = 0x0042,
1411 ACX_IBSS_FILTER = 0x0044,
1412 ACX_SERVICE_PERIOD_TIMEOUT = 0x0045,
1413 ACX_TSF_INFO = 0x0046,
1414 ACX_CONFIG_PS_WMM = 0x0049,
1415 ACX_ENABLE_RX_DATA_FILTER = 0x004A,
1416 ACX_SET_RX_DATA_FILTER = 0x004B,
1417 ACX_GET_DATA_FILTER_STATISTICS = 0x004C,
1418 ACX_POWER_LEVEL_TABLE = 0x004D,
1419 ACX_BET_ENABLE = 0x0050,
1420 DOT11_STATION_ID = 0x1001,
1421 DOT11_RX_MSDU_LIFE_TIME = 0x1004,
1422 DOT11_CUR_TX_PWR = 0x100D,
1423 DOT11_DEFAULT_KEY = 0x1010,
1424 DOT11_RX_DOT11_MODE = 0x1012,
1425 DOT11_RTS_THRESHOLD = 0x1013,
1426 DOT11_GROUP_ADDRESS_TBL = 0x1014,
1427
1428 MAX_DOT11_IE = DOT11_GROUP_ADDRESS_TBL,
1429
1430 MAX_IE = 0xFFFF
1431};
1432
1433
1434int wl1251_acx_frame_rates(struct wl1251 *wl, u8 ctrl_rate, u8 ctrl_mod,
1435 u8 mgt_rate, u8 mgt_mod);
1436int wl1251_acx_station_id(struct wl1251 *wl);
1437int wl1251_acx_default_key(struct wl1251 *wl, u8 key_id);
1438int wl1251_acx_wake_up_conditions(struct wl1251 *wl, u8 wake_up_event,
1439 u8 listen_interval);
1440int wl1251_acx_sleep_auth(struct wl1251 *wl, u8 sleep_auth);
1441int wl1251_acx_fw_version(struct wl1251 *wl, char *buf, size_t len);
1442int wl1251_acx_tx_power(struct wl1251 *wl, int power);
1443int wl1251_acx_feature_cfg(struct wl1251 *wl);
1444int wl1251_acx_mem_map(struct wl1251 *wl,
1445 struct acx_header *mem_map, size_t len);
1446int wl1251_acx_data_path_params(struct wl1251 *wl,
1447 struct acx_data_path_params_resp *data_path);
1448int wl1251_acx_rx_msdu_life_time(struct wl1251 *wl, u32 life_time);
1449int wl1251_acx_rx_config(struct wl1251 *wl, u32 config, u32 filter);
1450int wl1251_acx_pd_threshold(struct wl1251 *wl);
1451int wl1251_acx_slot(struct wl1251 *wl, enum acx_slot_type slot_time);
1452int wl1251_acx_group_address_tbl(struct wl1251 *wl);
1453int wl1251_acx_service_period_timeout(struct wl1251 *wl);
1454int wl1251_acx_rts_threshold(struct wl1251 *wl, u16 rts_threshold);
1455int wl1251_acx_beacon_filter_opt(struct wl1251 *wl, bool enable_filter);
1456int wl1251_acx_beacon_filter_table(struct wl1251 *wl);
1457int wl1251_acx_conn_monit_params(struct wl1251 *wl);
1458int wl1251_acx_sg_enable(struct wl1251 *wl);
1459int wl1251_acx_sg_cfg(struct wl1251 *wl);
1460int wl1251_acx_cca_threshold(struct wl1251 *wl);
1461int wl1251_acx_bcn_dtim_options(struct wl1251 *wl);
1462int wl1251_acx_aid(struct wl1251 *wl, u16 aid);
1463int wl1251_acx_event_mbox_mask(struct wl1251 *wl, u32 event_mask);
1464int wl1251_acx_low_rssi(struct wl1251 *wl, s8 threshold, u8 weight,
1465 u8 depth, enum wl1251_acx_low_rssi_type type);
1466int wl1251_acx_set_preamble(struct wl1251 *wl, enum acx_preamble_type preamble);
1467int wl1251_acx_cts_protect(struct wl1251 *wl,
1468 enum acx_ctsprotect_type ctsprotect);
1469int wl1251_acx_statistics(struct wl1251 *wl, struct acx_statistics *stats);
1470int wl1251_acx_tsf_info(struct wl1251 *wl, u64 *mactime);
1471int wl1251_acx_rate_policies(struct wl1251 *wl);
1472int wl1251_acx_mem_cfg(struct wl1251 *wl);
1473int wl1251_acx_wr_tbtt_and_dtim(struct wl1251 *wl, u16 tbtt, u8 dtim);
1474int wl1251_acx_bet_enable(struct wl1251 *wl, enum wl1251_acx_bet_mode mode,
1475 u8 max_consecutive);
1476int wl1251_acx_ac_cfg(struct wl1251 *wl, u8 ac, u8 cw_min, u16 cw_max,
1477 u8 aifs, u16 txop);
1478int wl1251_acx_tid_cfg(struct wl1251 *wl, u8 queue,
1479 enum wl1251_acx_channel_type type,
1480 u8 tsid, enum wl1251_acx_ps_scheme ps_scheme,
1481 enum wl1251_acx_ack_policy ack_policy);
1482
1483#endif /* __WL1251_ACX_H__ */
diff --git a/drivers/net/wireless/ti/wl1251/boot.c b/drivers/net/wireless/ti/wl1251/boot.c
new file mode 100644
index 000000000000..a2e5241382da
--- /dev/null
+++ b/drivers/net/wireless/ti/wl1251/boot.c
@@ -0,0 +1,554 @@
1/*
2 * This file is part of wl1251
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
22#include <linux/slab.h>
23
24#include "reg.h"
25#include "boot.h"
26#include "io.h"
27#include "spi.h"
28#include "event.h"
29#include "acx.h"
30
31void wl1251_boot_target_enable_interrupts(struct wl1251 *wl)
32{
33 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_MASK, ~(wl->intr_mask));
34 wl1251_reg_write32(wl, HI_CFG, HI_CFG_DEF_VAL);
35}
36
37int wl1251_boot_soft_reset(struct wl1251 *wl)
38{
39 unsigned long timeout;
40 u32 boot_data;
41
42 /* perform soft reset */
43 wl1251_reg_write32(wl, ACX_REG_SLV_SOFT_RESET, ACX_SLV_SOFT_RESET_BIT);
44
45 /* SOFT_RESET is self clearing */
46 timeout = jiffies + usecs_to_jiffies(SOFT_RESET_MAX_TIME);
47 while (1) {
48 boot_data = wl1251_reg_read32(wl, ACX_REG_SLV_SOFT_RESET);
49 wl1251_debug(DEBUG_BOOT, "soft reset bootdata 0x%x", boot_data);
50 if ((boot_data & ACX_SLV_SOFT_RESET_BIT) == 0)
51 break;
52
53 if (time_after(jiffies, timeout)) {
54 /* 1.2 check pWhalBus->uSelfClearTime if the
55 * timeout was reached */
56 wl1251_error("soft reset timeout");
57 return -1;
58 }
59
60 udelay(SOFT_RESET_STALL_TIME);
61 }
62
63 /* disable Rx/Tx */
64 wl1251_reg_write32(wl, ENABLE, 0x0);
65
66 /* disable auto calibration on start*/
67 wl1251_reg_write32(wl, SPARE_A2, 0xffff);
68
69 return 0;
70}
71
72int wl1251_boot_init_seq(struct wl1251 *wl)
73{
74 u32 scr_pad6, init_data, tmp, elp_cmd, ref_freq;
75
76 /*
77 * col #1: INTEGER_DIVIDER
78 * col #2: FRACTIONAL_DIVIDER
79 * col #3: ATTN_BB
80 * col #4: ALPHA_BB
81 * col #5: STOP_TIME_BB
82 * col #6: BB_PLL_LOOP_FILTER
83 */
84 static const u32 LUT[REF_FREQ_NUM][LUT_PARAM_NUM] = {
85
86 { 83, 87381, 0xB, 5, 0xF00, 3}, /* REF_FREQ_19_2*/
87 { 61, 141154, 0xB, 5, 0x1450, 2}, /* REF_FREQ_26_0*/
88 { 41, 174763, 0xC, 6, 0x2D00, 1}, /* REF_FREQ_38_4*/
89 { 40, 0, 0xC, 6, 0x2EE0, 1}, /* REF_FREQ_40_0*/
90 { 47, 162280, 0xC, 6, 0x2760, 1} /* REF_FREQ_33_6 */
91 };
92
93 /* read NVS params */
94 scr_pad6 = wl1251_reg_read32(wl, SCR_PAD6);
95 wl1251_debug(DEBUG_BOOT, "scr_pad6 0x%x", scr_pad6);
96
97 /* read ELP_CMD */
98 elp_cmd = wl1251_reg_read32(wl, ELP_CMD);
99 wl1251_debug(DEBUG_BOOT, "elp_cmd 0x%x", elp_cmd);
100
101 /* set the BB calibration time to be 300 usec (PLL_CAL_TIME) */
102 ref_freq = scr_pad6 & 0x000000FF;
103 wl1251_debug(DEBUG_BOOT, "ref_freq 0x%x", ref_freq);
104
105 wl1251_reg_write32(wl, PLL_CAL_TIME, 0x9);
106
107 /*
108 * PG 1.2: set the clock buffer time to be 210 usec (CLK_BUF_TIME)
109 */
110 wl1251_reg_write32(wl, CLK_BUF_TIME, 0x6);
111
112 /*
113 * set the clock detect feature to work in the restart wu procedure
114 * (ELP_CFG_MODE[14]) and Select the clock source type
115 * (ELP_CFG_MODE[13:12])
116 */
117 tmp = ((scr_pad6 & 0x0000FF00) << 4) | 0x00004000;
118 wl1251_reg_write32(wl, ELP_CFG_MODE, tmp);
119
120 /* PG 1.2: enable the BB PLL fix. Enable the PLL_LIMP_CLK_EN_CMD */
121 elp_cmd |= 0x00000040;
122 wl1251_reg_write32(wl, ELP_CMD, elp_cmd);
123
124 /* PG 1.2: Set the BB PLL stable time to be 1000usec
125 * (PLL_STABLE_TIME) */
126 wl1251_reg_write32(wl, CFG_PLL_SYNC_CNT, 0x20);
127
128 /* PG 1.2: read clock request time */
129 init_data = wl1251_reg_read32(wl, CLK_REQ_TIME);
130
131 /*
132 * PG 1.2: set the clock request time to be ref_clk_settling_time -
133 * 1ms = 4ms
134 */
135 if (init_data > 0x21)
136 tmp = init_data - 0x21;
137 else
138 tmp = 0;
139 wl1251_reg_write32(wl, CLK_REQ_TIME, tmp);
140
141 /* set BB PLL configurations in RF AFE */
142 wl1251_reg_write32(wl, 0x003058cc, 0x4B5);
143
144 /* set RF_AFE_REG_5 */
145 wl1251_reg_write32(wl, 0x003058d4, 0x50);
146
147 /* set RF_AFE_CTRL_REG_2 */
148 wl1251_reg_write32(wl, 0x00305948, 0x11c001);
149
150 /*
151 * change RF PLL and BB PLL divider for VCO clock and adjust VCO
152 * bais current(RF_AFE_REG_13)
153 */
154 wl1251_reg_write32(wl, 0x003058f4, 0x1e);
155
156 /* set BB PLL configurations */
157 tmp = LUT[ref_freq][LUT_PARAM_INTEGER_DIVIDER] | 0x00017000;
158 wl1251_reg_write32(wl, 0x00305840, tmp);
159
160 /* set fractional divider according to Appendix C-BB PLL
161 * Calculations
162 */
163 tmp = LUT[ref_freq][LUT_PARAM_FRACTIONAL_DIVIDER];
164 wl1251_reg_write32(wl, 0x00305844, tmp);
165
166 /* set the initial data for the sigma delta */
167 wl1251_reg_write32(wl, 0x00305848, 0x3039);
168
169 /*
170 * set the accumulator attenuation value, calibration loop1
171 * (alpha), calibration loop2 (beta), calibration loop3 (gamma) and
172 * the VCO gain
173 */
174 tmp = (LUT[ref_freq][LUT_PARAM_ATTN_BB] << 16) |
175 (LUT[ref_freq][LUT_PARAM_ALPHA_BB] << 12) | 0x1;
176 wl1251_reg_write32(wl, 0x00305854, tmp);
177
178 /*
179 * set the calibration stop time after holdoff time expires and set
180 * settling time HOLD_OFF_TIME_BB
181 */
182 tmp = LUT[ref_freq][LUT_PARAM_STOP_TIME_BB] | 0x000A0000;
183 wl1251_reg_write32(wl, 0x00305858, tmp);
184
185 /*
186 * set BB PLL Loop filter capacitor3- BB_C3[2:0] and set BB PLL
187 * constant leakage current to linearize PFD to 0uA -
188 * BB_ILOOPF[7:3]
189 */
190 tmp = LUT[ref_freq][LUT_PARAM_BB_PLL_LOOP_FILTER] | 0x00000030;
191 wl1251_reg_write32(wl, 0x003058f8, tmp);
192
193 /*
194 * set regulator output voltage for n divider to
195 * 1.35-BB_REFDIV[1:0], set charge pump current- BB_CPGAIN[4:2],
196 * set BB PLL Loop filter capacitor2- BB_C2[7:5], set gain of BB
197 * PLL auto-call to normal mode- BB_CALGAIN_3DB[8]
198 */
199 wl1251_reg_write32(wl, 0x003058f0, 0x29);
200
201 /* enable restart wakeup sequence (ELP_CMD[0]) */
202 wl1251_reg_write32(wl, ELP_CMD, elp_cmd | 0x1);
203
204 /* restart sequence completed */
205 udelay(2000);
206
207 return 0;
208}
209
210static void wl1251_boot_set_ecpu_ctrl(struct wl1251 *wl, u32 flag)
211{
212 u32 cpu_ctrl;
213
214 /* 10.5.0 run the firmware (I) */
215 cpu_ctrl = wl1251_reg_read32(wl, ACX_REG_ECPU_CONTROL);
216
217 /* 10.5.1 run the firmware (II) */
218 cpu_ctrl &= ~flag;
219 wl1251_reg_write32(wl, ACX_REG_ECPU_CONTROL, cpu_ctrl);
220}
221
222int wl1251_boot_run_firmware(struct wl1251 *wl)
223{
224 int loop, ret;
225 u32 chip_id, acx_intr;
226
227 wl1251_boot_set_ecpu_ctrl(wl, ECPU_CONTROL_HALT);
228
229 chip_id = wl1251_reg_read32(wl, CHIP_ID_B);
230
231 wl1251_debug(DEBUG_BOOT, "chip id after firmware boot: 0x%x", chip_id);
232
233 if (chip_id != wl->chip_id) {
234 wl1251_error("chip id doesn't match after firmware boot");
235 return -EIO;
236 }
237
238 /* wait for init to complete */
239 loop = 0;
240 while (loop++ < INIT_LOOP) {
241 udelay(INIT_LOOP_DELAY);
242 acx_intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
243
244 if (acx_intr == 0xffffffff) {
245 wl1251_error("error reading hardware complete "
246 "init indication");
247 return -EIO;
248 }
249 /* check that ACX_INTR_INIT_COMPLETE is enabled */
250 else if (acx_intr & WL1251_ACX_INTR_INIT_COMPLETE) {
251 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_ACK,
252 WL1251_ACX_INTR_INIT_COMPLETE);
253 break;
254 }
255 }
256
257 if (loop > INIT_LOOP) {
258 wl1251_error("timeout waiting for the hardware to "
259 "complete initialization");
260 return -EIO;
261 }
262
263 /* get hardware config command mail box */
264 wl->cmd_box_addr = wl1251_reg_read32(wl, REG_COMMAND_MAILBOX_PTR);
265
266 /* get hardware config event mail box */
267 wl->event_box_addr = wl1251_reg_read32(wl, REG_EVENT_MAILBOX_PTR);
268
269 /* set the working partition to its "running" mode offset */
270 wl1251_set_partition(wl, WL1251_PART_WORK_MEM_START,
271 WL1251_PART_WORK_MEM_SIZE,
272 WL1251_PART_WORK_REG_START,
273 WL1251_PART_WORK_REG_SIZE);
274
275 wl1251_debug(DEBUG_MAILBOX, "cmd_box_addr 0x%x event_box_addr 0x%x",
276 wl->cmd_box_addr, wl->event_box_addr);
277
278 wl1251_acx_fw_version(wl, wl->fw_ver, sizeof(wl->fw_ver));
279
280 /*
281 * in case of full asynchronous mode the firmware event must be
282 * ready to receive event from the command mailbox
283 */
284
285 /* enable gpio interrupts */
286 wl1251_enable_interrupts(wl);
287
288 /* Enable target's interrupts */
289 wl->intr_mask = WL1251_ACX_INTR_RX0_DATA |
290 WL1251_ACX_INTR_RX1_DATA |
291 WL1251_ACX_INTR_TX_RESULT |
292 WL1251_ACX_INTR_EVENT_A |
293 WL1251_ACX_INTR_EVENT_B |
294 WL1251_ACX_INTR_INIT_COMPLETE;
295 wl1251_boot_target_enable_interrupts(wl);
296
297 wl->event_mask = SCAN_COMPLETE_EVENT_ID | BSS_LOSE_EVENT_ID |
298 SYNCHRONIZATION_TIMEOUT_EVENT_ID |
299 ROAMING_TRIGGER_LOW_RSSI_EVENT_ID |
300 ROAMING_TRIGGER_REGAINED_RSSI_EVENT_ID |
301 REGAINED_BSS_EVENT_ID | BT_PTA_SENSE_EVENT_ID |
302 BT_PTA_PREDICTION_EVENT_ID | JOIN_EVENT_COMPLETE_ID;
303
304 ret = wl1251_event_unmask(wl);
305 if (ret < 0) {
306 wl1251_error("EVENT mask setting failed");
307 return ret;
308 }
309
310 wl1251_event_mbox_config(wl);
311
312 /* firmware startup completed */
313 return 0;
314}
315
316static int wl1251_boot_upload_firmware(struct wl1251 *wl)
317{
318 int addr, chunk_num, partition_limit;
319 size_t fw_data_len, len;
320 u8 *p, *buf;
321
322 /* whal_FwCtrl_LoadFwImageSm() */
323
324 wl1251_debug(DEBUG_BOOT, "chip id before fw upload: 0x%x",
325 wl1251_reg_read32(wl, CHIP_ID_B));
326
327 /* 10.0 check firmware length and set partition */
328 fw_data_len = (wl->fw[4] << 24) | (wl->fw[5] << 16) |
329 (wl->fw[6] << 8) | (wl->fw[7]);
330
331 wl1251_debug(DEBUG_BOOT, "fw_data_len %zu chunk_size %d", fw_data_len,
332 CHUNK_SIZE);
333
334 if ((fw_data_len % 4) != 0) {
335 wl1251_error("firmware length not multiple of four");
336 return -EIO;
337 }
338
339 buf = kmalloc(CHUNK_SIZE, GFP_KERNEL);
340 if (!buf) {
341 wl1251_error("allocation for firmware upload chunk failed");
342 return -ENOMEM;
343 }
344
345 wl1251_set_partition(wl, WL1251_PART_DOWN_MEM_START,
346 WL1251_PART_DOWN_MEM_SIZE,
347 WL1251_PART_DOWN_REG_START,
348 WL1251_PART_DOWN_REG_SIZE);
349
350 /* 10.1 set partition limit and chunk num */
351 chunk_num = 0;
352 partition_limit = WL1251_PART_DOWN_MEM_SIZE;
353
354 while (chunk_num < fw_data_len / CHUNK_SIZE) {
355 /* 10.2 update partition, if needed */
356 addr = WL1251_PART_DOWN_MEM_START +
357 (chunk_num + 2) * CHUNK_SIZE;
358 if (addr > partition_limit) {
359 addr = WL1251_PART_DOWN_MEM_START +
360 chunk_num * CHUNK_SIZE;
361 partition_limit = chunk_num * CHUNK_SIZE +
362 WL1251_PART_DOWN_MEM_SIZE;
363 wl1251_set_partition(wl,
364 addr,
365 WL1251_PART_DOWN_MEM_SIZE,
366 WL1251_PART_DOWN_REG_START,
367 WL1251_PART_DOWN_REG_SIZE);
368 }
369
370 /* 10.3 upload the chunk */
371 addr = WL1251_PART_DOWN_MEM_START + chunk_num * CHUNK_SIZE;
372 p = wl->fw + FW_HDR_SIZE + chunk_num * CHUNK_SIZE;
373 wl1251_debug(DEBUG_BOOT, "uploading fw chunk 0x%p to 0x%x",
374 p, addr);
375
376 /* need to copy the chunk for dma */
377 len = CHUNK_SIZE;
378 memcpy(buf, p, len);
379 wl1251_mem_write(wl, addr, buf, len);
380
381 chunk_num++;
382 }
383
384 /* 10.4 upload the last chunk */
385 addr = WL1251_PART_DOWN_MEM_START + chunk_num * CHUNK_SIZE;
386 p = wl->fw + FW_HDR_SIZE + chunk_num * CHUNK_SIZE;
387
388 /* need to copy the chunk for dma */
389 len = fw_data_len % CHUNK_SIZE;
390 memcpy(buf, p, len);
391
392 wl1251_debug(DEBUG_BOOT, "uploading fw last chunk (%zu B) 0x%p to 0x%x",
393 len, p, addr);
394 wl1251_mem_write(wl, addr, buf, len);
395
396 kfree(buf);
397
398 return 0;
399}
400
401static int wl1251_boot_upload_nvs(struct wl1251 *wl)
402{
403 size_t nvs_len, nvs_bytes_written, burst_len;
404 int nvs_start, i;
405 u32 dest_addr, val;
406 u8 *nvs_ptr, *nvs;
407
408 nvs = wl->nvs;
409 if (nvs == NULL)
410 return -ENODEV;
411
412 nvs_ptr = nvs;
413
414 nvs_len = wl->nvs_len;
415 nvs_start = wl->fw_len;
416
417 /*
418 * Layout before the actual NVS tables:
419 * 1 byte : burst length.
420 * 2 bytes: destination address.
421 * n bytes: data to burst copy.
422 *
423 * This is ended by a 0 length, then the NVS tables.
424 */
425
426 while (nvs_ptr[0]) {
427 burst_len = nvs_ptr[0];
428 dest_addr = (nvs_ptr[1] & 0xfe) | ((u32)(nvs_ptr[2] << 8));
429
430 /* We move our pointer to the data */
431 nvs_ptr += 3;
432
433 for (i = 0; i < burst_len; i++) {
434 val = (nvs_ptr[0] | (nvs_ptr[1] << 8)
435 | (nvs_ptr[2] << 16) | (nvs_ptr[3] << 24));
436
437 wl1251_debug(DEBUG_BOOT,
438 "nvs burst write 0x%x: 0x%x",
439 dest_addr, val);
440 wl1251_mem_write32(wl, dest_addr, val);
441
442 nvs_ptr += 4;
443 dest_addr += 4;
444 }
445 }
446
447 /*
448 * We've reached the first zero length, the first NVS table
449 * is 7 bytes further.
450 */
451 nvs_ptr += 7;
452 nvs_len -= nvs_ptr - nvs;
453 nvs_len = ALIGN(nvs_len, 4);
454
455 /* Now we must set the partition correctly */
456 wl1251_set_partition(wl, nvs_start,
457 WL1251_PART_DOWN_MEM_SIZE,
458 WL1251_PART_DOWN_REG_START,
459 WL1251_PART_DOWN_REG_SIZE);
460
461 /* And finally we upload the NVS tables */
462 nvs_bytes_written = 0;
463 while (nvs_bytes_written < nvs_len) {
464 val = (nvs_ptr[0] | (nvs_ptr[1] << 8)
465 | (nvs_ptr[2] << 16) | (nvs_ptr[3] << 24));
466
467 wl1251_debug(DEBUG_BOOT,
468 "nvs write table 0x%x: 0x%x",
469 nvs_start, val);
470 wl1251_mem_write32(wl, nvs_start, val);
471
472 nvs_ptr += 4;
473 nvs_bytes_written += 4;
474 nvs_start += 4;
475 }
476
477 return 0;
478}
479
480int wl1251_boot(struct wl1251 *wl)
481{
482 int ret = 0, minor_minor_e2_ver;
483 u32 tmp, boot_data;
484
485 /* halt embedded ARM CPU while loading firmware */
486 wl1251_reg_write32(wl, ACX_REG_ECPU_CONTROL, ECPU_CONTROL_HALT);
487
488 ret = wl1251_boot_soft_reset(wl);
489 if (ret < 0)
490 goto out;
491
492 /* 2. start processing NVS file */
493 if (wl->use_eeprom) {
494 wl1251_reg_write32(wl, ACX_REG_EE_START, START_EEPROM_MGR);
495 /* Wait for EEPROM NVS burst read to complete */
496 msleep(40);
497 wl1251_reg_write32(wl, ACX_EEPROMLESS_IND_REG, USE_EEPROM);
498 } else {
499 ret = wl1251_boot_upload_nvs(wl);
500 if (ret < 0)
501 goto out;
502
503 /* write firmware's last address (ie. it's length) to
504 * ACX_EEPROMLESS_IND_REG */
505 wl1251_reg_write32(wl, ACX_EEPROMLESS_IND_REG, wl->fw_len);
506 }
507
508 /* 6. read the EEPROM parameters */
509 tmp = wl1251_reg_read32(wl, SCR_PAD2);
510
511 /* 7. read bootdata */
512 wl->boot_attr.radio_type = (tmp & 0x0000FF00) >> 8;
513 wl->boot_attr.major = (tmp & 0x00FF0000) >> 16;
514 tmp = wl1251_reg_read32(wl, SCR_PAD3);
515
516 /* 8. check bootdata and call restart sequence */
517 wl->boot_attr.minor = (tmp & 0x00FF0000) >> 16;
518 minor_minor_e2_ver = (tmp & 0xFF000000) >> 24;
519
520 wl1251_debug(DEBUG_BOOT, "radioType 0x%x majorE2Ver 0x%x "
521 "minorE2Ver 0x%x minor_minor_e2_ver 0x%x",
522 wl->boot_attr.radio_type, wl->boot_attr.major,
523 wl->boot_attr.minor, minor_minor_e2_ver);
524
525 ret = wl1251_boot_init_seq(wl);
526 if (ret < 0)
527 goto out;
528
529 /* 9. NVS processing done */
530 boot_data = wl1251_reg_read32(wl, ACX_REG_ECPU_CONTROL);
531
532 wl1251_debug(DEBUG_BOOT, "halt boot_data 0x%x", boot_data);
533
534 /* 10. check that ECPU_CONTROL_HALT bits are set in
535 * pWhalBus->uBootData and start uploading firmware
536 */
537 if ((boot_data & ECPU_CONTROL_HALT) == 0) {
538 wl1251_error("boot failed, ECPU_CONTROL_HALT not set");
539 ret = -EIO;
540 goto out;
541 }
542
543 ret = wl1251_boot_upload_firmware(wl);
544 if (ret < 0)
545 goto out;
546
547 /* 10.5 start firmware */
548 ret = wl1251_boot_run_firmware(wl);
549 if (ret < 0)
550 goto out;
551
552out:
553 return ret;
554}
diff --git a/drivers/net/wireless/ti/wl1251/boot.h b/drivers/net/wireless/ti/wl1251/boot.h
new file mode 100644
index 000000000000..7661bc5e4662
--- /dev/null
+++ b/drivers/net/wireless/ti/wl1251/boot.h
@@ -0,0 +1,39 @@
1/*
2 * This file is part of wl1251
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
22#ifndef __BOOT_H__
23#define __BOOT_H__
24
25#include "wl1251.h"
26
27int wl1251_boot_soft_reset(struct wl1251 *wl);
28int wl1251_boot_init_seq(struct wl1251 *wl);
29int wl1251_boot_run_firmware(struct wl1251 *wl);
30void wl1251_boot_target_enable_interrupts(struct wl1251 *wl);
31int wl1251_boot(struct wl1251 *wl);
32
33/* number of times we try to read the INIT interrupt */
34#define INIT_LOOP 20000
35
36/* delay between retries */
37#define INIT_LOOP_DELAY 50
38
39#endif
diff --git a/drivers/net/wireless/ti/wl1251/cmd.c b/drivers/net/wireless/ti/wl1251/cmd.c
new file mode 100644
index 000000000000..d14d69d733a0
--- /dev/null
+++ b/drivers/net/wireless/ti/wl1251/cmd.c
@@ -0,0 +1,496 @@
1#include "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 "reg.h"
9#include "io.h"
10#include "ps.h"
11#include "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: length 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 ret;
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 goto out;
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/ti/wl1251/cmd.h b/drivers/net/wireless/ti/wl1251/cmd.h
new file mode 100644
index 000000000000..ee4f2b391822
--- /dev/null
+++ b/drivers/net/wireless/ti/wl1251/cmd.h
@@ -0,0 +1,415 @@
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 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22
23#ifndef __WL1251_CMD_H__
24#define __WL1251_CMD_H__
25
26#include "wl1251.h"
27
28#include <net/cfg80211.h>
29
30struct acx_header;
31
32int wl1251_cmd_send(struct wl1251 *wl, u16 type, void *buf, size_t buf_len);
33int wl1251_cmd_test(struct wl1251 *wl, void *buf, size_t buf_len, u8 answer);
34int wl1251_cmd_interrogate(struct wl1251 *wl, u16 id, void *buf, size_t len);
35int wl1251_cmd_configure(struct wl1251 *wl, u16 id, void *buf, size_t len);
36int wl1251_cmd_vbm(struct wl1251 *wl, u8 identity,
37 void *bitmap, u16 bitmap_len, u8 bitmap_control);
38int wl1251_cmd_data_path(struct wl1251 *wl, u8 channel, bool enable);
39int wl1251_cmd_join(struct wl1251 *wl, u8 bss_type, u8 channel,
40 u16 beacon_interval, u8 dtim_interval);
41int wl1251_cmd_ps_mode(struct wl1251 *wl, u8 ps_mode);
42int wl1251_cmd_read_memory(struct wl1251 *wl, u32 addr, void *answer,
43 size_t len);
44int wl1251_cmd_template_set(struct wl1251 *wl, u16 cmd_id,
45 void *buf, size_t buf_len);
46int wl1251_cmd_scan(struct wl1251 *wl, u8 *ssid, size_t ssid_len,
47 struct ieee80211_channel *channels[],
48 unsigned int n_channels, unsigned int n_probes);
49int wl1251_cmd_trigger_scan_to(struct wl1251 *wl, u32 timeout);
50
51/* unit ms */
52#define WL1251_COMMAND_TIMEOUT 2000
53
54enum wl1251_commands {
55 CMD_RESET = 0,
56 CMD_INTERROGATE = 1, /*use this to read information elements*/
57 CMD_CONFIGURE = 2, /*use this to write information elements*/
58 CMD_ENABLE_RX = 3,
59 CMD_ENABLE_TX = 4,
60 CMD_DISABLE_RX = 5,
61 CMD_DISABLE_TX = 6,
62 CMD_SCAN = 8,
63 CMD_STOP_SCAN = 9,
64 CMD_VBM = 10,
65 CMD_START_JOIN = 11,
66 CMD_SET_KEYS = 12,
67 CMD_READ_MEMORY = 13,
68 CMD_WRITE_MEMORY = 14,
69 CMD_BEACON = 19,
70 CMD_PROBE_RESP = 20,
71 CMD_NULL_DATA = 21,
72 CMD_PROBE_REQ = 22,
73 CMD_TEST = 23,
74 CMD_RADIO_CALIBRATE = 25, /* OBSOLETE */
75 CMD_ENABLE_RX_PATH = 27, /* OBSOLETE */
76 CMD_NOISE_HIST = 28,
77 CMD_RX_RESET = 29,
78 CMD_PS_POLL = 30,
79 CMD_QOS_NULL_DATA = 31,
80 CMD_LNA_CONTROL = 32,
81 CMD_SET_BCN_MODE = 33,
82 CMD_MEASUREMENT = 34,
83 CMD_STOP_MEASUREMENT = 35,
84 CMD_DISCONNECT = 36,
85 CMD_SET_PS_MODE = 37,
86 CMD_CHANNEL_SWITCH = 38,
87 CMD_STOP_CHANNEL_SWICTH = 39,
88 CMD_AP_DISCOVERY = 40,
89 CMD_STOP_AP_DISCOVERY = 41,
90 CMD_SPS_SCAN = 42,
91 CMD_STOP_SPS_SCAN = 43,
92 CMD_HEALTH_CHECK = 45,
93 CMD_DEBUG = 46,
94 CMD_TRIGGER_SCAN_TO = 47,
95
96 NUM_COMMANDS,
97 MAX_COMMAND_ID = 0xFFFF,
98};
99
100#define MAX_CMD_PARAMS 572
101
102struct wl1251_cmd_header {
103 u16 id;
104 u16 status;
105 /* payload */
106 u8 data[0];
107} __packed;
108
109struct wl1251_command {
110 struct wl1251_cmd_header header;
111 u8 parameters[MAX_CMD_PARAMS];
112} __packed;
113
114enum {
115 CMD_MAILBOX_IDLE = 0,
116 CMD_STATUS_SUCCESS = 1,
117 CMD_STATUS_UNKNOWN_CMD = 2,
118 CMD_STATUS_UNKNOWN_IE = 3,
119 CMD_STATUS_REJECT_MEAS_SG_ACTIVE = 11,
120 CMD_STATUS_RX_BUSY = 13,
121 CMD_STATUS_INVALID_PARAM = 14,
122 CMD_STATUS_TEMPLATE_TOO_LARGE = 15,
123 CMD_STATUS_OUT_OF_MEMORY = 16,
124 CMD_STATUS_STA_TABLE_FULL = 17,
125 CMD_STATUS_RADIO_ERROR = 18,
126 CMD_STATUS_WRONG_NESTING = 19,
127 CMD_STATUS_TIMEOUT = 21, /* Driver internal use.*/
128 CMD_STATUS_FW_RESET = 22, /* Driver internal use.*/
129 MAX_COMMAND_STATUS = 0xff
130};
131
132
133/*
134 * CMD_READ_MEMORY
135 *
136 * The host issues this command to read the WiLink device memory/registers.
137 *
138 * Note: The Base Band address has special handling (16 bits registers and
139 * addresses). For more information, see the hardware specification.
140 */
141/*
142 * CMD_WRITE_MEMORY
143 *
144 * The host issues this command to write the WiLink device memory/registers.
145 *
146 * The Base Band address has special handling (16 bits registers and
147 * addresses). For more information, see the hardware specification.
148 */
149#define MAX_READ_SIZE 256
150
151struct cmd_read_write_memory {
152 struct wl1251_cmd_header header;
153
154 /* The address of the memory to read from or write to.*/
155 u32 addr;
156
157 /* The amount of data in bytes to read from or write to the WiLink
158 * device.*/
159 u32 size;
160
161 /* The actual value read from or written to the Wilink. The source
162 of this field is the Host in WRITE command or the Wilink in READ
163 command. */
164 u8 value[MAX_READ_SIZE];
165} __packed;
166
167#define CMDMBOX_HEADER_LEN 4
168#define CMDMBOX_INFO_ELEM_HEADER_LEN 4
169
170#define WL1251_SCAN_MIN_DURATION 30000
171#define WL1251_SCAN_MAX_DURATION 60000
172
173#define WL1251_SCAN_NUM_PROBES 3
174
175struct wl1251_scan_parameters {
176 __le32 rx_config_options;
177 __le32 rx_filter_options;
178
179 /*
180 * Scan options:
181 * bit 0: When this bit is set, passive scan.
182 * bit 1: Band, when this bit is set we scan
183 * in the 5Ghz band.
184 * bit 2: voice mode, 0 for normal scan.
185 * bit 3: scan priority, 1 for high priority.
186 */
187 __le16 scan_options;
188
189 /* Number of channels to scan */
190 u8 num_channels;
191
192 /* Number opf probe requests to send, per channel */
193 u8 num_probe_requests;
194
195 /* Rate and modulation for probe requests */
196 __le16 tx_rate;
197
198 u8 tid_trigger;
199 u8 ssid_len;
200 u8 ssid[32];
201
202} __packed;
203
204struct wl1251_scan_ch_parameters {
205 __le32 min_duration; /* in TU */
206 __le32 max_duration; /* in TU */
207 u32 bssid_lsb;
208 u16 bssid_msb;
209
210 /*
211 * bits 0-3: Early termination count.
212 * bits 4-5: Early termination condition.
213 */
214 u8 early_termination;
215
216 u8 tx_power_att;
217 u8 channel;
218 u8 pad[3];
219} __packed;
220
221/* SCAN parameters */
222#define SCAN_MAX_NUM_OF_CHANNELS 16
223
224struct wl1251_cmd_scan {
225 struct wl1251_cmd_header header;
226
227 struct wl1251_scan_parameters params;
228 struct wl1251_scan_ch_parameters channels[SCAN_MAX_NUM_OF_CHANNELS];
229} __packed;
230
231enum {
232 BSS_TYPE_IBSS = 0,
233 BSS_TYPE_STA_BSS = 2,
234 BSS_TYPE_AP_BSS = 3,
235 MAX_BSS_TYPE = 0xFF
236};
237
238#define JOIN_CMD_CTRL_TX_FLUSH 0x80 /* Firmware flushes all Tx */
239#define JOIN_CMD_CTRL_EARLY_WAKEUP_ENABLE 0x01 /* Early wakeup time */
240
241
242struct cmd_join {
243 struct wl1251_cmd_header header;
244
245 u32 bssid_lsb;
246 u16 bssid_msb;
247 u16 beacon_interval; /* in TBTTs */
248 u32 rx_config_options;
249 u32 rx_filter_options;
250
251 /*
252 * The target uses this field to determine the rate at
253 * which to transmit control frame responses (such as
254 * ACK or CTS frames).
255 */
256 u16 basic_rate_set;
257 u8 dtim_interval;
258 u8 tx_ctrl_frame_rate; /* OBSOLETE */
259 u8 tx_ctrl_frame_mod; /* OBSOLETE */
260 /*
261 * bits 0-2: This bitwise field specifies the type
262 * of BSS to start or join (BSS_TYPE_*).
263 * bit 4: Band - The radio band in which to join
264 * or start.
265 * 0 - 2.4GHz band
266 * 1 - 5GHz band
267 * bits 3, 5-7: Reserved
268 */
269 u8 bss_type;
270 u8 channel;
271 u8 ssid_len;
272 u8 ssid[IEEE80211_MAX_SSID_LEN];
273 u8 ctrl; /* JOIN_CMD_CTRL_* */
274 u8 tx_mgt_frame_rate; /* OBSOLETE */
275 u8 tx_mgt_frame_mod; /* OBSOLETE */
276 u8 reserved;
277} __packed;
278
279struct cmd_enabledisable_path {
280 struct wl1251_cmd_header header;
281
282 u8 channel;
283 u8 padding[3];
284} __packed;
285
286#define WL1251_MAX_TEMPLATE_SIZE 300
287
288struct wl1251_cmd_packet_template {
289 struct wl1251_cmd_header header;
290
291 __le16 size;
292 u8 data[0];
293} __packed;
294
295#define TIM_ELE_ID 5
296#define PARTIAL_VBM_MAX 251
297
298struct wl1251_tim {
299 u8 identity;
300 u8 length;
301 u8 dtim_count;
302 u8 dtim_period;
303 u8 bitmap_ctrl;
304 u8 pvb_field[PARTIAL_VBM_MAX]; /* Partial Virtual Bitmap */
305} __packed;
306
307/* Virtual Bit Map update */
308struct wl1251_cmd_vbm_update {
309 struct wl1251_cmd_header header;
310 __le16 len;
311 u8 padding[2];
312 struct wl1251_tim tim;
313} __packed;
314
315enum wl1251_cmd_ps_mode {
316 CHIP_ACTIVE_MODE,
317 CHIP_POWER_SAVE_MODE
318};
319
320struct wl1251_cmd_ps_params {
321 struct wl1251_cmd_header header;
322
323 u8 ps_mode; /* STATION_* */
324 u8 send_null_data; /* Do we have to send NULL data packet ? */
325 u8 retries; /* Number of retires for the initial NULL data packet */
326
327 /*
328 * TUs during which the target stays awake after switching
329 * to power save mode.
330 */
331 u8 hang_over_period;
332 u16 null_data_rate;
333 u8 pad[2];
334} __packed;
335
336struct wl1251_cmd_trigger_scan_to {
337 struct wl1251_cmd_header header;
338
339 u32 timeout;
340} __packed;
341
342/* HW encryption keys */
343#define NUM_ACCESS_CATEGORIES_COPY 4
344#define MAX_KEY_SIZE 32
345
346/* When set, disable HW encryption */
347#define DF_ENCRYPTION_DISABLE 0x01
348/* When set, disable HW decryption */
349#define DF_SNIFF_MODE_ENABLE 0x80
350
351enum wl1251_cmd_key_action {
352 KEY_ADD_OR_REPLACE = 1,
353 KEY_REMOVE = 2,
354 KEY_SET_ID = 3,
355 MAX_KEY_ACTION = 0xffff,
356};
357
358enum wl1251_cmd_key_type {
359 KEY_WEP_DEFAULT = 0,
360 KEY_WEP_ADDR = 1,
361 KEY_AES_GROUP = 4,
362 KEY_AES_PAIRWISE = 5,
363 KEY_WEP_GROUP = 6,
364 KEY_TKIP_MIC_GROUP = 10,
365 KEY_TKIP_MIC_PAIRWISE = 11,
366};
367
368/*
369 *
370 * key_type_e key size key format
371 * ---------- --------- ----------
372 * 0x00 5, 13, 29 Key data
373 * 0x01 5, 13, 29 Key data
374 * 0x04 16 16 bytes of key data
375 * 0x05 16 16 bytes of key data
376 * 0x0a 32 16 bytes of TKIP key data
377 * 8 bytes of RX MIC key data
378 * 8 bytes of TX MIC key data
379 * 0x0b 32 16 bytes of TKIP key data
380 * 8 bytes of RX MIC key data
381 * 8 bytes of TX MIC key data
382 *
383 */
384
385struct wl1251_cmd_set_keys {
386 struct wl1251_cmd_header header;
387
388 /* Ignored for default WEP key */
389 u8 addr[ETH_ALEN];
390
391 /* key_action_e */
392 u16 key_action;
393
394 u16 reserved_1;
395
396 /* key size in bytes */
397 u8 key_size;
398
399 /* key_type_e */
400 u8 key_type;
401 u8 ssid_profile;
402
403 /*
404 * TKIP, AES: frame's key id field.
405 * For WEP default key: key id;
406 */
407 u8 id;
408 u8 reserved_2[6];
409 u8 key[MAX_KEY_SIZE];
410 u16 ac_seq_num16[NUM_ACCESS_CATEGORIES_COPY];
411 u32 ac_seq_num32[NUM_ACCESS_CATEGORIES_COPY];
412} __packed;
413
414
415#endif /* __WL1251_CMD_H__ */
diff --git a/drivers/net/wireless/ti/wl1251/debugfs.c b/drivers/net/wireless/ti/wl1251/debugfs.c
new file mode 100644
index 000000000000..6c274007d200
--- /dev/null
+++ b/drivers/net/wireless/ti/wl1251/debugfs.c
@@ -0,0 +1,545 @@
1/*
2 * This file is part of wl1251
3 *
4 * Copyright (C) 2009 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
22#include "debugfs.h"
23
24#include <linux/skbuff.h>
25#include <linux/slab.h>
26
27#include "wl1251.h"
28#include "acx.h"
29#include "ps.h"
30
31/* ms */
32#define WL1251_DEBUGFS_STATS_LIFETIME 1000
33
34/* debugfs macros idea from mac80211 */
35
36#define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \
37static ssize_t name## _read(struct file *file, char __user *userbuf, \
38 size_t count, loff_t *ppos) \
39{ \
40 struct wl1251 *wl = file->private_data; \
41 char buf[buflen]; \
42 int res; \
43 \
44 res = scnprintf(buf, buflen, fmt "\n", ##value); \
45 return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
46} \
47 \
48static const struct file_operations name## _ops = { \
49 .read = name## _read, \
50 .open = wl1251_open_file_generic, \
51 .llseek = generic_file_llseek, \
52};
53
54#define DEBUGFS_ADD(name, parent) \
55 wl->debugfs.name = debugfs_create_file(#name, 0400, parent, \
56 wl, &name## _ops); \
57 if (IS_ERR(wl->debugfs.name)) { \
58 ret = PTR_ERR(wl->debugfs.name); \
59 wl->debugfs.name = NULL; \
60 goto out; \
61 }
62
63#define DEBUGFS_DEL(name) \
64 do { \
65 debugfs_remove(wl->debugfs.name); \
66 wl->debugfs.name = NULL; \
67 } while (0)
68
69#define DEBUGFS_FWSTATS_FILE(sub, name, buflen, fmt) \
70static ssize_t sub## _ ##name## _read(struct file *file, \
71 char __user *userbuf, \
72 size_t count, loff_t *ppos) \
73{ \
74 struct wl1251 *wl = file->private_data; \
75 char buf[buflen]; \
76 int res; \
77 \
78 wl1251_debugfs_update_stats(wl); \
79 \
80 res = scnprintf(buf, buflen, fmt "\n", \
81 wl->stats.fw_stats->sub.name); \
82 return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
83} \
84 \
85static const struct file_operations sub## _ ##name## _ops = { \
86 .read = sub## _ ##name## _read, \
87 .open = wl1251_open_file_generic, \
88 .llseek = generic_file_llseek, \
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 .llseek = generic_file_llseek,
240};
241
242static ssize_t tx_queue_status_read(struct file *file, char __user *userbuf,
243 size_t count, loff_t *ppos)
244{
245 struct wl1251 *wl = file->private_data;
246 char buf[3], status;
247 int len;
248
249 if (wl->tx_queue_stopped)
250 status = 's';
251 else
252 status = 'r';
253
254 len = scnprintf(buf, sizeof(buf), "%c\n", status);
255 return simple_read_from_buffer(userbuf, count, ppos, buf, len);
256}
257
258static const struct file_operations tx_queue_status_ops = {
259 .read = tx_queue_status_read,
260 .open = wl1251_open_file_generic,
261 .llseek = generic_file_llseek,
262};
263
264static void wl1251_debugfs_delete_files(struct wl1251 *wl)
265{
266 DEBUGFS_FWSTATS_DEL(tx, internal_desc_overflow);
267
268 DEBUGFS_FWSTATS_DEL(rx, out_of_mem);
269 DEBUGFS_FWSTATS_DEL(rx, hdr_overflow);
270 DEBUGFS_FWSTATS_DEL(rx, hw_stuck);
271 DEBUGFS_FWSTATS_DEL(rx, dropped);
272 DEBUGFS_FWSTATS_DEL(rx, fcs_err);
273 DEBUGFS_FWSTATS_DEL(rx, xfr_hint_trig);
274 DEBUGFS_FWSTATS_DEL(rx, path_reset);
275 DEBUGFS_FWSTATS_DEL(rx, reset_counter);
276
277 DEBUGFS_FWSTATS_DEL(dma, rx_requested);
278 DEBUGFS_FWSTATS_DEL(dma, rx_errors);
279 DEBUGFS_FWSTATS_DEL(dma, tx_requested);
280 DEBUGFS_FWSTATS_DEL(dma, tx_errors);
281
282 DEBUGFS_FWSTATS_DEL(isr, cmd_cmplt);
283 DEBUGFS_FWSTATS_DEL(isr, fiqs);
284 DEBUGFS_FWSTATS_DEL(isr, rx_headers);
285 DEBUGFS_FWSTATS_DEL(isr, rx_mem_overflow);
286 DEBUGFS_FWSTATS_DEL(isr, rx_rdys);
287 DEBUGFS_FWSTATS_DEL(isr, irqs);
288 DEBUGFS_FWSTATS_DEL(isr, tx_procs);
289 DEBUGFS_FWSTATS_DEL(isr, decrypt_done);
290 DEBUGFS_FWSTATS_DEL(isr, dma0_done);
291 DEBUGFS_FWSTATS_DEL(isr, dma1_done);
292 DEBUGFS_FWSTATS_DEL(isr, tx_exch_complete);
293 DEBUGFS_FWSTATS_DEL(isr, commands);
294 DEBUGFS_FWSTATS_DEL(isr, rx_procs);
295 DEBUGFS_FWSTATS_DEL(isr, hw_pm_mode_changes);
296 DEBUGFS_FWSTATS_DEL(isr, host_acknowledges);
297 DEBUGFS_FWSTATS_DEL(isr, pci_pm);
298 DEBUGFS_FWSTATS_DEL(isr, wakeups);
299 DEBUGFS_FWSTATS_DEL(isr, low_rssi);
300
301 DEBUGFS_FWSTATS_DEL(wep, addr_key_count);
302 DEBUGFS_FWSTATS_DEL(wep, default_key_count);
303 /* skipping wep.reserved */
304 DEBUGFS_FWSTATS_DEL(wep, key_not_found);
305 DEBUGFS_FWSTATS_DEL(wep, decrypt_fail);
306 DEBUGFS_FWSTATS_DEL(wep, packets);
307 DEBUGFS_FWSTATS_DEL(wep, interrupt);
308
309 DEBUGFS_FWSTATS_DEL(pwr, ps_enter);
310 DEBUGFS_FWSTATS_DEL(pwr, elp_enter);
311 DEBUGFS_FWSTATS_DEL(pwr, missing_bcns);
312 DEBUGFS_FWSTATS_DEL(pwr, wake_on_host);
313 DEBUGFS_FWSTATS_DEL(pwr, wake_on_timer_exp);
314 DEBUGFS_FWSTATS_DEL(pwr, tx_with_ps);
315 DEBUGFS_FWSTATS_DEL(pwr, tx_without_ps);
316 DEBUGFS_FWSTATS_DEL(pwr, rcvd_beacons);
317 DEBUGFS_FWSTATS_DEL(pwr, power_save_off);
318 DEBUGFS_FWSTATS_DEL(pwr, enable_ps);
319 DEBUGFS_FWSTATS_DEL(pwr, disable_ps);
320 DEBUGFS_FWSTATS_DEL(pwr, fix_tsf_ps);
321 /* skipping cont_miss_bcns_spread for now */
322 DEBUGFS_FWSTATS_DEL(pwr, rcvd_awake_beacons);
323
324 DEBUGFS_FWSTATS_DEL(mic, rx_pkts);
325 DEBUGFS_FWSTATS_DEL(mic, calc_failure);
326
327 DEBUGFS_FWSTATS_DEL(aes, encrypt_fail);
328 DEBUGFS_FWSTATS_DEL(aes, decrypt_fail);
329 DEBUGFS_FWSTATS_DEL(aes, encrypt_packets);
330 DEBUGFS_FWSTATS_DEL(aes, decrypt_packets);
331 DEBUGFS_FWSTATS_DEL(aes, encrypt_interrupt);
332 DEBUGFS_FWSTATS_DEL(aes, decrypt_interrupt);
333
334 DEBUGFS_FWSTATS_DEL(event, heart_beat);
335 DEBUGFS_FWSTATS_DEL(event, calibration);
336 DEBUGFS_FWSTATS_DEL(event, rx_mismatch);
337 DEBUGFS_FWSTATS_DEL(event, rx_mem_empty);
338 DEBUGFS_FWSTATS_DEL(event, rx_pool);
339 DEBUGFS_FWSTATS_DEL(event, oom_late);
340 DEBUGFS_FWSTATS_DEL(event, phy_transmit_error);
341 DEBUGFS_FWSTATS_DEL(event, tx_stuck);
342
343 DEBUGFS_FWSTATS_DEL(ps, pspoll_timeouts);
344 DEBUGFS_FWSTATS_DEL(ps, upsd_timeouts);
345 DEBUGFS_FWSTATS_DEL(ps, upsd_max_sptime);
346 DEBUGFS_FWSTATS_DEL(ps, upsd_max_apturn);
347 DEBUGFS_FWSTATS_DEL(ps, pspoll_max_apturn);
348 DEBUGFS_FWSTATS_DEL(ps, pspoll_utilization);
349 DEBUGFS_FWSTATS_DEL(ps, upsd_utilization);
350
351 DEBUGFS_FWSTATS_DEL(rxpipe, rx_prep_beacon_drop);
352 DEBUGFS_FWSTATS_DEL(rxpipe, descr_host_int_trig_rx_data);
353 DEBUGFS_FWSTATS_DEL(rxpipe, beacon_buffer_thres_host_int_trig_rx_data);
354 DEBUGFS_FWSTATS_DEL(rxpipe, missed_beacon_host_int_trig_rx_data);
355 DEBUGFS_FWSTATS_DEL(rxpipe, tx_xfr_host_int_trig_rx_data);
356
357 DEBUGFS_DEL(tx_queue_len);
358 DEBUGFS_DEL(tx_queue_status);
359 DEBUGFS_DEL(retry_count);
360 DEBUGFS_DEL(excessive_retries);
361}
362
363static int wl1251_debugfs_add_files(struct wl1251 *wl)
364{
365 int ret = 0;
366
367 DEBUGFS_FWSTATS_ADD(tx, internal_desc_overflow);
368
369 DEBUGFS_FWSTATS_ADD(rx, out_of_mem);
370 DEBUGFS_FWSTATS_ADD(rx, hdr_overflow);
371 DEBUGFS_FWSTATS_ADD(rx, hw_stuck);
372 DEBUGFS_FWSTATS_ADD(rx, dropped);
373 DEBUGFS_FWSTATS_ADD(rx, fcs_err);
374 DEBUGFS_FWSTATS_ADD(rx, xfr_hint_trig);
375 DEBUGFS_FWSTATS_ADD(rx, path_reset);
376 DEBUGFS_FWSTATS_ADD(rx, reset_counter);
377
378 DEBUGFS_FWSTATS_ADD(dma, rx_requested);
379 DEBUGFS_FWSTATS_ADD(dma, rx_errors);
380 DEBUGFS_FWSTATS_ADD(dma, tx_requested);
381 DEBUGFS_FWSTATS_ADD(dma, tx_errors);
382
383 DEBUGFS_FWSTATS_ADD(isr, cmd_cmplt);
384 DEBUGFS_FWSTATS_ADD(isr, fiqs);
385 DEBUGFS_FWSTATS_ADD(isr, rx_headers);
386 DEBUGFS_FWSTATS_ADD(isr, rx_mem_overflow);
387 DEBUGFS_FWSTATS_ADD(isr, rx_rdys);
388 DEBUGFS_FWSTATS_ADD(isr, irqs);
389 DEBUGFS_FWSTATS_ADD(isr, tx_procs);
390 DEBUGFS_FWSTATS_ADD(isr, decrypt_done);
391 DEBUGFS_FWSTATS_ADD(isr, dma0_done);
392 DEBUGFS_FWSTATS_ADD(isr, dma1_done);
393 DEBUGFS_FWSTATS_ADD(isr, tx_exch_complete);
394 DEBUGFS_FWSTATS_ADD(isr, commands);
395 DEBUGFS_FWSTATS_ADD(isr, rx_procs);
396 DEBUGFS_FWSTATS_ADD(isr, hw_pm_mode_changes);
397 DEBUGFS_FWSTATS_ADD(isr, host_acknowledges);
398 DEBUGFS_FWSTATS_ADD(isr, pci_pm);
399 DEBUGFS_FWSTATS_ADD(isr, wakeups);
400 DEBUGFS_FWSTATS_ADD(isr, low_rssi);
401
402 DEBUGFS_FWSTATS_ADD(wep, addr_key_count);
403 DEBUGFS_FWSTATS_ADD(wep, default_key_count);
404 /* skipping wep.reserved */
405 DEBUGFS_FWSTATS_ADD(wep, key_not_found);
406 DEBUGFS_FWSTATS_ADD(wep, decrypt_fail);
407 DEBUGFS_FWSTATS_ADD(wep, packets);
408 DEBUGFS_FWSTATS_ADD(wep, interrupt);
409
410 DEBUGFS_FWSTATS_ADD(pwr, ps_enter);
411 DEBUGFS_FWSTATS_ADD(pwr, elp_enter);
412 DEBUGFS_FWSTATS_ADD(pwr, missing_bcns);
413 DEBUGFS_FWSTATS_ADD(pwr, wake_on_host);
414 DEBUGFS_FWSTATS_ADD(pwr, wake_on_timer_exp);
415 DEBUGFS_FWSTATS_ADD(pwr, tx_with_ps);
416 DEBUGFS_FWSTATS_ADD(pwr, tx_without_ps);
417 DEBUGFS_FWSTATS_ADD(pwr, rcvd_beacons);
418 DEBUGFS_FWSTATS_ADD(pwr, power_save_off);
419 DEBUGFS_FWSTATS_ADD(pwr, enable_ps);
420 DEBUGFS_FWSTATS_ADD(pwr, disable_ps);
421 DEBUGFS_FWSTATS_ADD(pwr, fix_tsf_ps);
422 /* skipping cont_miss_bcns_spread for now */
423 DEBUGFS_FWSTATS_ADD(pwr, rcvd_awake_beacons);
424
425 DEBUGFS_FWSTATS_ADD(mic, rx_pkts);
426 DEBUGFS_FWSTATS_ADD(mic, calc_failure);
427
428 DEBUGFS_FWSTATS_ADD(aes, encrypt_fail);
429 DEBUGFS_FWSTATS_ADD(aes, decrypt_fail);
430 DEBUGFS_FWSTATS_ADD(aes, encrypt_packets);
431 DEBUGFS_FWSTATS_ADD(aes, decrypt_packets);
432 DEBUGFS_FWSTATS_ADD(aes, encrypt_interrupt);
433 DEBUGFS_FWSTATS_ADD(aes, decrypt_interrupt);
434
435 DEBUGFS_FWSTATS_ADD(event, heart_beat);
436 DEBUGFS_FWSTATS_ADD(event, calibration);
437 DEBUGFS_FWSTATS_ADD(event, rx_mismatch);
438 DEBUGFS_FWSTATS_ADD(event, rx_mem_empty);
439 DEBUGFS_FWSTATS_ADD(event, rx_pool);
440 DEBUGFS_FWSTATS_ADD(event, oom_late);
441 DEBUGFS_FWSTATS_ADD(event, phy_transmit_error);
442 DEBUGFS_FWSTATS_ADD(event, tx_stuck);
443
444 DEBUGFS_FWSTATS_ADD(ps, pspoll_timeouts);
445 DEBUGFS_FWSTATS_ADD(ps, upsd_timeouts);
446 DEBUGFS_FWSTATS_ADD(ps, upsd_max_sptime);
447 DEBUGFS_FWSTATS_ADD(ps, upsd_max_apturn);
448 DEBUGFS_FWSTATS_ADD(ps, pspoll_max_apturn);
449 DEBUGFS_FWSTATS_ADD(ps, pspoll_utilization);
450 DEBUGFS_FWSTATS_ADD(ps, upsd_utilization);
451
452 DEBUGFS_FWSTATS_ADD(rxpipe, rx_prep_beacon_drop);
453 DEBUGFS_FWSTATS_ADD(rxpipe, descr_host_int_trig_rx_data);
454 DEBUGFS_FWSTATS_ADD(rxpipe, beacon_buffer_thres_host_int_trig_rx_data);
455 DEBUGFS_FWSTATS_ADD(rxpipe, missed_beacon_host_int_trig_rx_data);
456 DEBUGFS_FWSTATS_ADD(rxpipe, tx_xfr_host_int_trig_rx_data);
457
458 DEBUGFS_ADD(tx_queue_len, wl->debugfs.rootdir);
459 DEBUGFS_ADD(tx_queue_status, wl->debugfs.rootdir);
460 DEBUGFS_ADD(retry_count, wl->debugfs.rootdir);
461 DEBUGFS_ADD(excessive_retries, wl->debugfs.rootdir);
462
463out:
464 if (ret < 0)
465 wl1251_debugfs_delete_files(wl);
466
467 return ret;
468}
469
470void wl1251_debugfs_reset(struct wl1251 *wl)
471{
472 if (wl->stats.fw_stats != NULL)
473 memset(wl->stats.fw_stats, 0, sizeof(*wl->stats.fw_stats));
474 wl->stats.retry_count = 0;
475 wl->stats.excessive_retries = 0;
476}
477
478int wl1251_debugfs_init(struct wl1251 *wl)
479{
480 int ret;
481
482 wl->debugfs.rootdir = debugfs_create_dir(KBUILD_MODNAME, NULL);
483
484 if (IS_ERR(wl->debugfs.rootdir)) {
485 ret = PTR_ERR(wl->debugfs.rootdir);
486 wl->debugfs.rootdir = NULL;
487 goto err;
488 }
489
490 wl->debugfs.fw_statistics = debugfs_create_dir("fw-statistics",
491 wl->debugfs.rootdir);
492
493 if (IS_ERR(wl->debugfs.fw_statistics)) {
494 ret = PTR_ERR(wl->debugfs.fw_statistics);
495 wl->debugfs.fw_statistics = NULL;
496 goto err_root;
497 }
498
499 wl->stats.fw_stats = kzalloc(sizeof(*wl->stats.fw_stats),
500 GFP_KERNEL);
501
502 if (!wl->stats.fw_stats) {
503 ret = -ENOMEM;
504 goto err_fw;
505 }
506
507 wl->stats.fw_stats_update = jiffies;
508
509 ret = wl1251_debugfs_add_files(wl);
510
511 if (ret < 0)
512 goto err_file;
513
514 return 0;
515
516err_file:
517 kfree(wl->stats.fw_stats);
518 wl->stats.fw_stats = NULL;
519
520err_fw:
521 debugfs_remove(wl->debugfs.fw_statistics);
522 wl->debugfs.fw_statistics = NULL;
523
524err_root:
525 debugfs_remove(wl->debugfs.rootdir);
526 wl->debugfs.rootdir = NULL;
527
528err:
529 return ret;
530}
531
532void wl1251_debugfs_exit(struct wl1251 *wl)
533{
534 wl1251_debugfs_delete_files(wl);
535
536 kfree(wl->stats.fw_stats);
537 wl->stats.fw_stats = NULL;
538
539 debugfs_remove(wl->debugfs.fw_statistics);
540 wl->debugfs.fw_statistics = NULL;
541
542 debugfs_remove(wl->debugfs.rootdir);
543 wl->debugfs.rootdir = NULL;
544
545}
diff --git a/drivers/net/wireless/ti/wl1251/debugfs.h b/drivers/net/wireless/ti/wl1251/debugfs.h
new file mode 100644
index 000000000000..b3417c02a218
--- /dev/null
+++ b/drivers/net/wireless/ti/wl1251/debugfs.h
@@ -0,0 +1,31 @@
1/*
2 * This file is part of wl1251
3 *
4 * Copyright (C) 2009 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
22#ifndef WL1251_DEBUGFS_H
23#define WL1251_DEBUGFS_H
24
25#include "wl1251.h"
26
27int wl1251_debugfs_init(struct wl1251 *wl);
28void wl1251_debugfs_exit(struct wl1251 *wl);
29void wl1251_debugfs_reset(struct wl1251 *wl);
30
31#endif /* WL1251_DEBUGFS_H */
diff --git a/drivers/net/wireless/ti/wl1251/event.c b/drivers/net/wireless/ti/wl1251/event.c
new file mode 100644
index 000000000000..9f15ccaf8f05
--- /dev/null
+++ b/drivers/net/wireless/ti/wl1251/event.c
@@ -0,0 +1,188 @@
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 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22
23#include "wl1251.h"
24#include "reg.h"
25#include "io.h"
26#include "event.h"
27#include "ps.h"
28
29static int wl1251_event_scan_complete(struct wl1251 *wl,
30 struct event_mailbox *mbox)
31{
32 wl1251_debug(DEBUG_EVENT, "status: 0x%x, channels: %d",
33 mbox->scheduled_scan_status,
34 mbox->scheduled_scan_channels);
35
36 if (wl->scanning) {
37 ieee80211_scan_completed(wl->hw, false);
38 wl1251_debug(DEBUG_MAC80211, "mac80211 hw scan completed");
39 wl->scanning = false;
40 }
41
42 return 0;
43}
44
45static void wl1251_event_mbox_dump(struct event_mailbox *mbox)
46{
47 wl1251_debug(DEBUG_EVENT, "MBOX DUMP:");
48 wl1251_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector);
49 wl1251_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask);
50}
51
52static int wl1251_event_process(struct wl1251 *wl, struct event_mailbox *mbox)
53{
54 int ret;
55 u32 vector;
56
57 wl1251_event_mbox_dump(mbox);
58
59 vector = mbox->events_vector & ~(mbox->events_mask);
60 wl1251_debug(DEBUG_EVENT, "vector: 0x%x", vector);
61
62 if (vector & SCAN_COMPLETE_EVENT_ID) {
63 ret = wl1251_event_scan_complete(wl, mbox);
64 if (ret < 0)
65 return ret;
66 }
67
68 if (vector & BSS_LOSE_EVENT_ID) {
69 wl1251_debug(DEBUG_EVENT, "BSS_LOSE_EVENT");
70
71 if (wl->psm_requested &&
72 wl->station_mode != STATION_ACTIVE_MODE) {
73 ret = wl1251_ps_set_mode(wl, STATION_ACTIVE_MODE);
74 if (ret < 0)
75 return ret;
76 }
77 }
78
79 if (vector & SYNCHRONIZATION_TIMEOUT_EVENT_ID &&
80 wl->station_mode != STATION_ACTIVE_MODE) {
81 wl1251_debug(DEBUG_EVENT, "SYNCHRONIZATION_TIMEOUT_EVENT");
82
83 /* indicate to the stack, that beacons have been lost */
84 ieee80211_beacon_loss(wl->vif);
85 }
86
87 if (vector & REGAINED_BSS_EVENT_ID) {
88 if (wl->psm_requested) {
89 ret = wl1251_ps_set_mode(wl, STATION_POWER_SAVE_MODE);
90 if (ret < 0)
91 return ret;
92 }
93 }
94
95 if (wl->vif && wl->rssi_thold) {
96 if (vector & ROAMING_TRIGGER_LOW_RSSI_EVENT_ID) {
97 wl1251_debug(DEBUG_EVENT,
98 "ROAMING_TRIGGER_LOW_RSSI_EVENT");
99 ieee80211_cqm_rssi_notify(wl->vif,
100 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
101 GFP_KERNEL);
102 }
103
104 if (vector & ROAMING_TRIGGER_REGAINED_RSSI_EVENT_ID) {
105 wl1251_debug(DEBUG_EVENT,
106 "ROAMING_TRIGGER_REGAINED_RSSI_EVENT");
107 ieee80211_cqm_rssi_notify(wl->vif,
108 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
109 GFP_KERNEL);
110 }
111 }
112
113 return 0;
114}
115
116/*
117 * Poll the mailbox event field until any of the bits in the mask is set or a
118 * timeout occurs (WL1251_EVENT_TIMEOUT in msecs)
119 */
120int wl1251_event_wait(struct wl1251 *wl, u32 mask, int timeout_ms)
121{
122 u32 events_vector, event;
123 unsigned long timeout;
124
125 timeout = jiffies + msecs_to_jiffies(timeout_ms);
126
127 do {
128 if (time_after(jiffies, timeout))
129 return -ETIMEDOUT;
130
131 msleep(1);
132
133 /* read from both event fields */
134 wl1251_mem_read(wl, wl->mbox_ptr[0], &events_vector,
135 sizeof(events_vector));
136 event = events_vector & mask;
137 wl1251_mem_read(wl, wl->mbox_ptr[1], &events_vector,
138 sizeof(events_vector));
139 event |= events_vector & mask;
140 } while (!event);
141
142 return 0;
143}
144
145int wl1251_event_unmask(struct wl1251 *wl)
146{
147 int ret;
148
149 ret = wl1251_acx_event_mbox_mask(wl, ~(wl->event_mask));
150 if (ret < 0)
151 return ret;
152
153 return 0;
154}
155
156void wl1251_event_mbox_config(struct wl1251 *wl)
157{
158 wl->mbox_ptr[0] = wl1251_reg_read32(wl, REG_EVENT_MAILBOX_PTR);
159 wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox);
160
161 wl1251_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x",
162 wl->mbox_ptr[0], wl->mbox_ptr[1]);
163}
164
165int wl1251_event_handle(struct wl1251 *wl, u8 mbox_num)
166{
167 struct event_mailbox mbox;
168 int ret;
169
170 wl1251_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
171
172 if (mbox_num > 1)
173 return -EINVAL;
174
175 /* first we read the mbox descriptor */
176 wl1251_mem_read(wl, wl->mbox_ptr[mbox_num], &mbox,
177 sizeof(struct event_mailbox));
178
179 /* process the descriptor */
180 ret = wl1251_event_process(wl, &mbox);
181 if (ret < 0)
182 return ret;
183
184 /* then we let the firmware know it can go on...*/
185 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK);
186
187 return 0;
188}
diff --git a/drivers/net/wireless/ti/wl1251/event.h b/drivers/net/wireless/ti/wl1251/event.h
new file mode 100644
index 000000000000..30eb5d150bf7
--- /dev/null
+++ b/drivers/net/wireless/ti/wl1251/event.h
@@ -0,0 +1,120 @@
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 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22
23#ifndef __WL1251_EVENT_H__
24#define __WL1251_EVENT_H__
25
26/*
27 * Mbox events
28 *
29 * The event mechanism is based on a pair of event buffers (buffers A and
30 * B) at fixed locations in the target's memory. The host processes one
31 * buffer while the other buffer continues to collect events. If the host
32 * is not processing events, an interrupt is issued to signal that a buffer
33 * is ready. Once the host is done with processing events from one buffer,
34 * it signals the target (with an ACK interrupt) that the event buffer is
35 * free.
36 */
37
38enum {
39 RESERVED1_EVENT_ID = BIT(0),
40 RESERVED2_EVENT_ID = BIT(1),
41 MEASUREMENT_START_EVENT_ID = BIT(2),
42 SCAN_COMPLETE_EVENT_ID = BIT(3),
43 CALIBRATION_COMPLETE_EVENT_ID = BIT(4),
44 ROAMING_TRIGGER_LOW_RSSI_EVENT_ID = BIT(5),
45 PS_REPORT_EVENT_ID = BIT(6),
46 SYNCHRONIZATION_TIMEOUT_EVENT_ID = BIT(7),
47 HEALTH_REPORT_EVENT_ID = BIT(8),
48 ACI_DETECTION_EVENT_ID = BIT(9),
49 DEBUG_REPORT_EVENT_ID = BIT(10),
50 MAC_STATUS_EVENT_ID = BIT(11),
51 DISCONNECT_EVENT_COMPLETE_ID = BIT(12),
52 JOIN_EVENT_COMPLETE_ID = BIT(13),
53 CHANNEL_SWITCH_COMPLETE_EVENT_ID = BIT(14),
54 BSS_LOSE_EVENT_ID = BIT(15),
55 ROAMING_TRIGGER_MAX_TX_RETRY_EVENT_ID = BIT(16),
56 MEASUREMENT_COMPLETE_EVENT_ID = BIT(17),
57 AP_DISCOVERY_COMPLETE_EVENT_ID = BIT(18),
58 SCHEDULED_SCAN_COMPLETE_EVENT_ID = BIT(19),
59 PSPOLL_DELIVERY_FAILURE_EVENT_ID = BIT(20),
60 RESET_BSS_EVENT_ID = BIT(21),
61 REGAINED_BSS_EVENT_ID = BIT(22),
62 ROAMING_TRIGGER_REGAINED_RSSI_EVENT_ID = BIT(23),
63 ROAMING_TRIGGER_LOW_SNR_EVENT_ID = BIT(24),
64 ROAMING_TRIGGER_REGAINED_SNR_EVENT_ID = BIT(25),
65
66 DBG_EVENT_ID = BIT(26),
67 BT_PTA_SENSE_EVENT_ID = BIT(27),
68 BT_PTA_PREDICTION_EVENT_ID = BIT(28),
69 BT_PTA_AVALANCHE_EVENT_ID = BIT(29),
70
71 PLT_RX_CALIBRATION_COMPLETE_EVENT_ID = BIT(30),
72
73 EVENT_MBOX_ALL_EVENT_ID = 0x7fffffff,
74};
75
76struct event_debug_report {
77 u8 debug_event_id;
78 u8 num_params;
79 u16 pad;
80 u32 report_1;
81 u32 report_2;
82 u32 report_3;
83} __packed;
84
85struct event_mailbox {
86 u32 events_vector;
87 u32 events_mask;
88 u32 reserved_1;
89 u32 reserved_2;
90
91 char average_rssi_level;
92 u8 ps_status;
93 u8 channel_switch_status;
94 u8 scheduled_scan_status;
95
96 /* Channels scanned by the scheduled scan */
97 u16 scheduled_scan_channels;
98
99 /* If bit 0 is set -> target's fatal error */
100 u16 health_report;
101 u16 bad_fft_counter;
102 u8 bt_pta_sense_info;
103 u8 bt_pta_protective_info;
104 u32 reserved;
105 u32 debug_report[2];
106
107 /* Number of FCS errors since last event */
108 u32 fcs_err_counter;
109
110 struct event_debug_report report;
111 u8 average_snr_level;
112 u8 padding[19];
113} __packed;
114
115int wl1251_event_unmask(struct wl1251 *wl);
116void wl1251_event_mbox_config(struct wl1251 *wl);
117int wl1251_event_handle(struct wl1251 *wl, u8 mbox);
118int wl1251_event_wait(struct wl1251 *wl, u32 mask, int timeout_ms);
119
120#endif
diff --git a/drivers/net/wireless/ti/wl1251/init.c b/drivers/net/wireless/ti/wl1251/init.c
new file mode 100644
index 000000000000..89b43d35473c
--- /dev/null
+++ b/drivers/net/wireless/ti/wl1251/init.c
@@ -0,0 +1,423 @@
1/*
2 * This file is part of wl1251
3 *
4 * Copyright (C) 2009 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
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/slab.h>
25
26#include "init.h"
27#include "wl12xx_80211.h"
28#include "acx.h"
29#include "cmd.h"
30#include "reg.h"
31
32int wl1251_hw_init_hwenc_config(struct wl1251 *wl)
33{
34 int ret;
35
36 ret = wl1251_acx_feature_cfg(wl);
37 if (ret < 0) {
38 wl1251_warning("couldn't set feature config");
39 return ret;
40 }
41
42 ret = wl1251_acx_default_key(wl, wl->default_key);
43 if (ret < 0) {
44 wl1251_warning("couldn't set default key");
45 return ret;
46 }
47
48 return 0;
49}
50
51int wl1251_hw_init_templates_config(struct wl1251 *wl)
52{
53 int ret;
54 u8 partial_vbm[PARTIAL_VBM_MAX];
55
56 /* send empty templates for fw memory reservation */
57 ret = wl1251_cmd_template_set(wl, CMD_PROBE_REQ, NULL,
58 sizeof(struct wl12xx_probe_req_template));
59 if (ret < 0)
60 return ret;
61
62 ret = wl1251_cmd_template_set(wl, CMD_NULL_DATA, NULL,
63 sizeof(struct wl12xx_null_data_template));
64 if (ret < 0)
65 return ret;
66
67 ret = wl1251_cmd_template_set(wl, CMD_PS_POLL, NULL,
68 sizeof(struct wl12xx_ps_poll_template));
69 if (ret < 0)
70 return ret;
71
72 ret = wl1251_cmd_template_set(wl, CMD_QOS_NULL_DATA, NULL,
73 sizeof
74 (struct wl12xx_qos_null_data_template));
75 if (ret < 0)
76 return ret;
77
78 ret = wl1251_cmd_template_set(wl, CMD_PROBE_RESP, NULL,
79 sizeof
80 (struct wl12xx_probe_resp_template));
81 if (ret < 0)
82 return ret;
83
84 ret = wl1251_cmd_template_set(wl, CMD_BEACON, NULL,
85 sizeof
86 (struct wl12xx_beacon_template));
87 if (ret < 0)
88 return ret;
89
90 /* tim templates, first reserve space then allocate an empty one */
91 memset(partial_vbm, 0, PARTIAL_VBM_MAX);
92 ret = wl1251_cmd_vbm(wl, TIM_ELE_ID, partial_vbm, PARTIAL_VBM_MAX, 0);
93 if (ret < 0)
94 return ret;
95
96 ret = wl1251_cmd_vbm(wl, TIM_ELE_ID, partial_vbm, 1, 0);
97 if (ret < 0)
98 return ret;
99
100 return 0;
101}
102
103int wl1251_hw_init_rx_config(struct wl1251 *wl, u32 config, u32 filter)
104{
105 int ret;
106
107 ret = wl1251_acx_rx_msdu_life_time(wl, RX_MSDU_LIFETIME_DEF);
108 if (ret < 0)
109 return ret;
110
111 ret = wl1251_acx_rx_config(wl, config, filter);
112 if (ret < 0)
113 return ret;
114
115 return 0;
116}
117
118int wl1251_hw_init_phy_config(struct wl1251 *wl)
119{
120 int ret;
121
122 ret = wl1251_acx_pd_threshold(wl);
123 if (ret < 0)
124 return ret;
125
126 ret = wl1251_acx_slot(wl, DEFAULT_SLOT_TIME);
127 if (ret < 0)
128 return ret;
129
130 ret = wl1251_acx_group_address_tbl(wl);
131 if (ret < 0)
132 return ret;
133
134 ret = wl1251_acx_service_period_timeout(wl);
135 if (ret < 0)
136 return ret;
137
138 ret = wl1251_acx_rts_threshold(wl, RTS_THRESHOLD_DEF);
139 if (ret < 0)
140 return ret;
141
142 return 0;
143}
144
145int wl1251_hw_init_beacon_filter(struct wl1251 *wl)
146{
147 int ret;
148
149 /* disable beacon filtering at this stage */
150 ret = wl1251_acx_beacon_filter_opt(wl, false);
151 if (ret < 0)
152 return ret;
153
154 ret = wl1251_acx_beacon_filter_table(wl);
155 if (ret < 0)
156 return ret;
157
158 return 0;
159}
160
161int wl1251_hw_init_pta(struct wl1251 *wl)
162{
163 int ret;
164
165 ret = wl1251_acx_sg_enable(wl);
166 if (ret < 0)
167 return ret;
168
169 ret = wl1251_acx_sg_cfg(wl);
170 if (ret < 0)
171 return ret;
172
173 return 0;
174}
175
176int wl1251_hw_init_energy_detection(struct wl1251 *wl)
177{
178 int ret;
179
180 ret = wl1251_acx_cca_threshold(wl);
181 if (ret < 0)
182 return ret;
183
184 return 0;
185}
186
187int wl1251_hw_init_beacon_broadcast(struct wl1251 *wl)
188{
189 int ret;
190
191 ret = wl1251_acx_bcn_dtim_options(wl);
192 if (ret < 0)
193 return ret;
194
195 return 0;
196}
197
198int wl1251_hw_init_power_auth(struct wl1251 *wl)
199{
200 return wl1251_acx_sleep_auth(wl, WL1251_PSM_CAM);
201}
202
203int wl1251_hw_init_mem_config(struct wl1251 *wl)
204{
205 int ret;
206
207 ret = wl1251_acx_mem_cfg(wl);
208 if (ret < 0)
209 return ret;
210
211 wl->target_mem_map = kzalloc(sizeof(struct wl1251_acx_mem_map),
212 GFP_KERNEL);
213 if (!wl->target_mem_map) {
214 wl1251_error("couldn't allocate target memory map");
215 return -ENOMEM;
216 }
217
218 /* we now ask for the firmware built memory map */
219 ret = wl1251_acx_mem_map(wl, wl->target_mem_map,
220 sizeof(struct wl1251_acx_mem_map));
221 if (ret < 0) {
222 wl1251_error("couldn't retrieve firmware memory map");
223 kfree(wl->target_mem_map);
224 wl->target_mem_map = NULL;
225 return ret;
226 }
227
228 return 0;
229}
230
231static int wl1251_hw_init_txq_fill(u8 qid,
232 struct acx_tx_queue_qos_config *config,
233 u32 num_blocks)
234{
235 config->qid = qid;
236
237 switch (qid) {
238 case QOS_AC_BE:
239 config->high_threshold =
240 (QOS_TX_HIGH_BE_DEF * num_blocks) / 100;
241 config->low_threshold =
242 (QOS_TX_LOW_BE_DEF * num_blocks) / 100;
243 break;
244 case QOS_AC_BK:
245 config->high_threshold =
246 (QOS_TX_HIGH_BK_DEF * num_blocks) / 100;
247 config->low_threshold =
248 (QOS_TX_LOW_BK_DEF * num_blocks) / 100;
249 break;
250 case QOS_AC_VI:
251 config->high_threshold =
252 (QOS_TX_HIGH_VI_DEF * num_blocks) / 100;
253 config->low_threshold =
254 (QOS_TX_LOW_VI_DEF * num_blocks) / 100;
255 break;
256 case QOS_AC_VO:
257 config->high_threshold =
258 (QOS_TX_HIGH_VO_DEF * num_blocks) / 100;
259 config->low_threshold =
260 (QOS_TX_LOW_VO_DEF * num_blocks) / 100;
261 break;
262 default:
263 wl1251_error("Invalid TX queue id: %d", qid);
264 return -EINVAL;
265 }
266
267 return 0;
268}
269
270static int wl1251_hw_init_tx_queue_config(struct wl1251 *wl)
271{
272 struct acx_tx_queue_qos_config *config;
273 struct wl1251_acx_mem_map *wl_mem_map = wl->target_mem_map;
274 int ret, i;
275
276 wl1251_debug(DEBUG_ACX, "acx tx queue config");
277
278 config = kzalloc(sizeof(*config), GFP_KERNEL);
279 if (!config) {
280 ret = -ENOMEM;
281 goto out;
282 }
283
284 for (i = 0; i < MAX_NUM_OF_AC; i++) {
285 ret = wl1251_hw_init_txq_fill(i, config,
286 wl_mem_map->num_tx_mem_blocks);
287 if (ret < 0)
288 goto out;
289
290 ret = wl1251_cmd_configure(wl, ACX_TX_QUEUE_CFG,
291 config, sizeof(*config));
292 if (ret < 0)
293 goto out;
294 }
295
296 wl1251_acx_ac_cfg(wl, AC_BE, CWMIN_BE, CWMAX_BE, AIFS_DIFS, TXOP_BE);
297 wl1251_acx_ac_cfg(wl, AC_BK, CWMIN_BK, CWMAX_BK, AIFS_DIFS, TXOP_BK);
298 wl1251_acx_ac_cfg(wl, AC_VI, CWMIN_VI, CWMAX_VI, AIFS_DIFS, TXOP_VI);
299 wl1251_acx_ac_cfg(wl, AC_VO, CWMIN_VO, CWMAX_VO, AIFS_DIFS, TXOP_VO);
300
301out:
302 kfree(config);
303 return ret;
304}
305
306static int wl1251_hw_init_data_path_config(struct wl1251 *wl)
307{
308 int ret;
309
310 /* asking for the data path parameters */
311 wl->data_path = kzalloc(sizeof(struct acx_data_path_params_resp),
312 GFP_KERNEL);
313 if (!wl->data_path) {
314 wl1251_error("Couldnt allocate data path parameters");
315 return -ENOMEM;
316 }
317
318 ret = wl1251_acx_data_path_params(wl, wl->data_path);
319 if (ret < 0) {
320 kfree(wl->data_path);
321 wl->data_path = NULL;
322 return ret;
323 }
324
325 return 0;
326}
327
328
329int wl1251_hw_init(struct wl1251 *wl)
330{
331 struct wl1251_acx_mem_map *wl_mem_map;
332 int ret;
333
334 ret = wl1251_hw_init_hwenc_config(wl);
335 if (ret < 0)
336 return ret;
337
338 /* Template settings */
339 ret = wl1251_hw_init_templates_config(wl);
340 if (ret < 0)
341 return ret;
342
343 /* Default memory configuration */
344 ret = wl1251_hw_init_mem_config(wl);
345 if (ret < 0)
346 return ret;
347
348 /* Default data path configuration */
349 ret = wl1251_hw_init_data_path_config(wl);
350 if (ret < 0)
351 goto out_free_memmap;
352
353 /* RX config */
354 ret = wl1251_hw_init_rx_config(wl,
355 RX_CFG_PROMISCUOUS | RX_CFG_TSF,
356 RX_FILTER_OPTION_DEF);
357 /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
358 RX_FILTER_OPTION_FILTER_ALL); */
359 if (ret < 0)
360 goto out_free_data_path;
361
362 /* TX queues config */
363 ret = wl1251_hw_init_tx_queue_config(wl);
364 if (ret < 0)
365 goto out_free_data_path;
366
367 /* PHY layer config */
368 ret = wl1251_hw_init_phy_config(wl);
369 if (ret < 0)
370 goto out_free_data_path;
371
372 /* Initialize connection monitoring thresholds */
373 ret = wl1251_acx_conn_monit_params(wl);
374 if (ret < 0)
375 goto out_free_data_path;
376
377 /* Beacon filtering */
378 ret = wl1251_hw_init_beacon_filter(wl);
379 if (ret < 0)
380 goto out_free_data_path;
381
382 /* Bluetooth WLAN coexistence */
383 ret = wl1251_hw_init_pta(wl);
384 if (ret < 0)
385 goto out_free_data_path;
386
387 /* Energy detection */
388 ret = wl1251_hw_init_energy_detection(wl);
389 if (ret < 0)
390 goto out_free_data_path;
391
392 /* Beacons and boradcast settings */
393 ret = wl1251_hw_init_beacon_broadcast(wl);
394 if (ret < 0)
395 goto out_free_data_path;
396
397 /* Enable data path */
398 ret = wl1251_cmd_data_path(wl, wl->channel, 1);
399 if (ret < 0)
400 goto out_free_data_path;
401
402 /* Default power state */
403 ret = wl1251_hw_init_power_auth(wl);
404 if (ret < 0)
405 goto out_free_data_path;
406
407 wl_mem_map = wl->target_mem_map;
408 wl1251_info("%d tx blocks at 0x%x, %d rx blocks at 0x%x",
409 wl_mem_map->num_tx_mem_blocks,
410 wl->data_path->tx_control_addr,
411 wl_mem_map->num_rx_mem_blocks,
412 wl->data_path->rx_control_addr);
413
414 return 0;
415
416 out_free_data_path:
417 kfree(wl->data_path);
418
419 out_free_memmap:
420 kfree(wl->target_mem_map);
421
422 return ret;
423}
diff --git a/drivers/net/wireless/ti/wl1251/init.h b/drivers/net/wireless/ti/wl1251/init.h
new file mode 100644
index 000000000000..543f17582ead
--- /dev/null
+++ b/drivers/net/wireless/ti/wl1251/init.h
@@ -0,0 +1,86 @@
1/*
2 * This file is part of wl1251
3 *
4 * Copyright (C) 2009 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
22#ifndef __WL1251_INIT_H__
23#define __WL1251_INIT_H__
24
25#include "wl1251.h"
26
27enum {
28 /* best effort/legacy */
29 AC_BE = 0,
30
31 /* background */
32 AC_BK = 1,
33
34 /* video */
35 AC_VI = 2,
36
37 /* voice */
38 AC_VO = 3,
39
40 /* broadcast dummy access category */
41 AC_BCAST = 4,
42
43 NUM_ACCESS_CATEGORIES = 4
44};
45
46/* following are defult values for the IE fields*/
47#define CWMIN_BK 15
48#define CWMIN_BE 15
49#define CWMIN_VI 7
50#define CWMIN_VO 3
51#define CWMAX_BK 1023
52#define CWMAX_BE 63
53#define CWMAX_VI 15
54#define CWMAX_VO 7
55
56/* slot number setting to start transmission at PIFS interval */
57#define AIFS_PIFS 1
58
59/*
60 * slot number setting to start transmission at DIFS interval - normal DCF
61 * access
62 */
63#define AIFS_DIFS 2
64
65#define AIFSN_BK 7
66#define AIFSN_BE 3
67#define AIFSN_VI AIFS_PIFS
68#define AIFSN_VO AIFS_PIFS
69#define TXOP_BK 0
70#define TXOP_BE 0
71#define TXOP_VI 3008
72#define TXOP_VO 1504
73
74int wl1251_hw_init_hwenc_config(struct wl1251 *wl);
75int wl1251_hw_init_templates_config(struct wl1251 *wl);
76int wl1251_hw_init_rx_config(struct wl1251 *wl, u32 config, u32 filter);
77int wl1251_hw_init_phy_config(struct wl1251 *wl);
78int wl1251_hw_init_beacon_filter(struct wl1251 *wl);
79int wl1251_hw_init_pta(struct wl1251 *wl);
80int wl1251_hw_init_energy_detection(struct wl1251 *wl);
81int wl1251_hw_init_beacon_broadcast(struct wl1251 *wl);
82int wl1251_hw_init_power_auth(struct wl1251 *wl);
83int wl1251_hw_init_mem_config(struct wl1251 *wl);
84int wl1251_hw_init(struct wl1251 *wl);
85
86#endif
diff --git a/drivers/net/wireless/ti/wl1251/io.c b/drivers/net/wireless/ti/wl1251/io.c
new file mode 100644
index 000000000000..cdcadbf6ac2c
--- /dev/null
+++ b/drivers/net/wireless/ti/wl1251/io.c
@@ -0,0 +1,194 @@
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
22#include "wl1251.h"
23#include "reg.h"
24#include "io.h"
25
26/* FIXME: this is static data nowadays and the table can be removed */
27static enum wl12xx_acx_int_reg wl1251_io_reg_table[ACX_REG_TABLE_LEN] = {
28 [ACX_REG_INTERRUPT_TRIG] = (REGISTERS_BASE + 0x0474),
29 [ACX_REG_INTERRUPT_TRIG_H] = (REGISTERS_BASE + 0x0478),
30 [ACX_REG_INTERRUPT_MASK] = (REGISTERS_BASE + 0x0494),
31 [ACX_REG_HINT_MASK_SET] = (REGISTERS_BASE + 0x0498),
32 [ACX_REG_HINT_MASK_CLR] = (REGISTERS_BASE + 0x049C),
33 [ACX_REG_INTERRUPT_NO_CLEAR] = (REGISTERS_BASE + 0x04B0),
34 [ACX_REG_INTERRUPT_CLEAR] = (REGISTERS_BASE + 0x04A4),
35 [ACX_REG_INTERRUPT_ACK] = (REGISTERS_BASE + 0x04A8),
36 [ACX_REG_SLV_SOFT_RESET] = (REGISTERS_BASE + 0x0000),
37 [ACX_REG_EE_START] = (REGISTERS_BASE + 0x080C),
38 [ACX_REG_ECPU_CONTROL] = (REGISTERS_BASE + 0x0804)
39};
40
41static int wl1251_translate_reg_addr(struct wl1251 *wl, int addr)
42{
43 /* If the address is lower than REGISTERS_BASE, it means that this is
44 * a chip-specific register address, so look it up in the registers
45 * table */
46 if (addr < REGISTERS_BASE) {
47 /* Make sure we don't go over the table */
48 if (addr >= ACX_REG_TABLE_LEN) {
49 wl1251_error("address out of range (%d)", addr);
50 return -EINVAL;
51 }
52 addr = wl1251_io_reg_table[addr];
53 }
54
55 return addr - wl->physical_reg_addr + wl->virtual_reg_addr;
56}
57
58static int wl1251_translate_mem_addr(struct wl1251 *wl, int addr)
59{
60 return addr - wl->physical_mem_addr + wl->virtual_mem_addr;
61}
62
63void wl1251_mem_read(struct wl1251 *wl, int addr, void *buf, size_t len)
64{
65 int physical;
66
67 physical = wl1251_translate_mem_addr(wl, addr);
68
69 wl->if_ops->read(wl, physical, buf, len);
70}
71
72void wl1251_mem_write(struct wl1251 *wl, int addr, void *buf, size_t len)
73{
74 int physical;
75
76 physical = wl1251_translate_mem_addr(wl, addr);
77
78 wl->if_ops->write(wl, physical, buf, len);
79}
80
81u32 wl1251_mem_read32(struct wl1251 *wl, int addr)
82{
83 return wl1251_read32(wl, wl1251_translate_mem_addr(wl, addr));
84}
85
86void wl1251_mem_write32(struct wl1251 *wl, int addr, u32 val)
87{
88 wl1251_write32(wl, wl1251_translate_mem_addr(wl, addr), val);
89}
90
91u32 wl1251_reg_read32(struct wl1251 *wl, int addr)
92{
93 return wl1251_read32(wl, wl1251_translate_reg_addr(wl, addr));
94}
95
96void wl1251_reg_write32(struct wl1251 *wl, int addr, u32 val)
97{
98 wl1251_write32(wl, wl1251_translate_reg_addr(wl, addr), val);
99}
100
101/* Set the partitions to access the chip addresses.
102 *
103 * There are two VIRTUAL partitions (the memory partition and the
104 * registers partition), which are mapped to two different areas of the
105 * PHYSICAL (hardware) memory. This function also makes other checks to
106 * ensure that the partitions are not overlapping. In the diagram below, the
107 * memory partition comes before the register partition, but the opposite is
108 * also supported.
109 *
110 * PHYSICAL address
111 * space
112 *
113 * | |
114 * ...+----+--> mem_start
115 * VIRTUAL address ... | |
116 * space ... | | [PART_0]
117 * ... | |
118 * 0x00000000 <--+----+... ...+----+--> mem_start + mem_size
119 * | | ... | |
120 * |MEM | ... | |
121 * | | ... | |
122 * part_size <--+----+... | | {unused area)
123 * | | ... | |
124 * |REG | ... | |
125 * part_size | | ... | |
126 * + <--+----+... ...+----+--> reg_start
127 * reg_size ... | |
128 * ... | | [PART_1]
129 * ... | |
130 * ...+----+--> reg_start + reg_size
131 * | |
132 *
133 */
134void wl1251_set_partition(struct wl1251 *wl,
135 u32 mem_start, u32 mem_size,
136 u32 reg_start, u32 reg_size)
137{
138 struct wl1251_partition partition[2];
139
140 wl1251_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
141 mem_start, mem_size);
142 wl1251_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
143 reg_start, reg_size);
144
145 /* Make sure that the two partitions together don't exceed the
146 * address range */
147 if ((mem_size + reg_size) > HW_ACCESS_MEMORY_MAX_RANGE) {
148 wl1251_debug(DEBUG_SPI, "Total size exceeds maximum virtual"
149 " address range. Truncating partition[0].");
150 mem_size = HW_ACCESS_MEMORY_MAX_RANGE - reg_size;
151 wl1251_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
152 mem_start, mem_size);
153 wl1251_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
154 reg_start, reg_size);
155 }
156
157 if ((mem_start < reg_start) &&
158 ((mem_start + mem_size) > reg_start)) {
159 /* Guarantee that the memory partition doesn't overlap the
160 * registers partition */
161 wl1251_debug(DEBUG_SPI, "End of partition[0] is "
162 "overlapping partition[1]. Adjusted.");
163 mem_size = reg_start - mem_start;
164 wl1251_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
165 mem_start, mem_size);
166 wl1251_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
167 reg_start, reg_size);
168 } else if ((reg_start < mem_start) &&
169 ((reg_start + reg_size) > mem_start)) {
170 /* Guarantee that the register partition doesn't overlap the
171 * memory partition */
172 wl1251_debug(DEBUG_SPI, "End of partition[1] is"
173 " overlapping partition[0]. Adjusted.");
174 reg_size = mem_start - reg_start;
175 wl1251_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
176 mem_start, mem_size);
177 wl1251_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
178 reg_start, reg_size);
179 }
180
181 partition[0].start = mem_start;
182 partition[0].size = mem_size;
183 partition[1].start = reg_start;
184 partition[1].size = reg_size;
185
186 wl->physical_mem_addr = mem_start;
187 wl->physical_reg_addr = reg_start;
188
189 wl->virtual_mem_addr = 0;
190 wl->virtual_reg_addr = mem_size;
191
192 wl->if_ops->write(wl, HW_ACCESS_PART0_SIZE_ADDR, partition,
193 sizeof(partition));
194}
diff --git a/drivers/net/wireless/ti/wl1251/io.h b/drivers/net/wireless/ti/wl1251/io.h
new file mode 100644
index 000000000000..d382877c34cc
--- /dev/null
+++ b/drivers/net/wireless/ti/wl1251/io.h
@@ -0,0 +1,83 @@
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 wl->if_ops->read(wl, addr, &wl->buffer_32, sizeof(wl->buffer_32));
40
41 return le32_to_cpu(wl->buffer_32);
42}
43
44static inline void wl1251_write32(struct wl1251 *wl, int addr, u32 val)
45{
46 wl->buffer_32 = cpu_to_le32(val);
47 wl->if_ops->write(wl, addr, &wl->buffer_32, sizeof(wl->buffer_32));
48}
49
50static inline u32 wl1251_read_elp(struct wl1251 *wl, int addr)
51{
52 u32 response;
53
54 if (wl->if_ops->read_elp)
55 wl->if_ops->read_elp(wl, addr, &response);
56 else
57 wl->if_ops->read(wl, addr, &response, sizeof(u32));
58
59 return response;
60}
61
62static inline void wl1251_write_elp(struct wl1251 *wl, int addr, u32 val)
63{
64 if (wl->if_ops->write_elp)
65 wl->if_ops->write_elp(wl, addr, val);
66 else
67 wl->if_ops->write(wl, addr, &val, sizeof(u32));
68}
69
70/* Memory target IO, address is translated to partition 0 */
71void wl1251_mem_read(struct wl1251 *wl, int addr, void *buf, size_t len);
72void wl1251_mem_write(struct wl1251 *wl, int addr, void *buf, size_t len);
73u32 wl1251_mem_read32(struct wl1251 *wl, int addr);
74void wl1251_mem_write32(struct wl1251 *wl, int addr, u32 val);
75/* Registers IO */
76u32 wl1251_reg_read32(struct wl1251 *wl, int addr);
77void wl1251_reg_write32(struct wl1251 *wl, int addr, u32 val);
78
79void wl1251_set_partition(struct wl1251 *wl,
80 u32 part_start, u32 part_size,
81 u32 reg_start, u32 reg_size);
82
83#endif
diff --git a/drivers/net/wireless/ti/wl1251/main.c b/drivers/net/wireless/ti/wl1251/main.c
new file mode 100644
index 000000000000..41302c7b1ad0
--- /dev/null
+++ b/drivers/net/wireless/ti/wl1251/main.c
@@ -0,0 +1,1471 @@
1/*
2 * This file is part of wl1251
3 *
4 * Copyright (C) 2008-2009 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
22#include <linux/module.h>
23#include <linux/interrupt.h>
24#include <linux/firmware.h>
25#include <linux/delay.h>
26#include <linux/irq.h>
27#include <linux/crc32.h>
28#include <linux/etherdevice.h>
29#include <linux/vmalloc.h>
30#include <linux/slab.h>
31
32#include "wl1251.h"
33#include "wl12xx_80211.h"
34#include "reg.h"
35#include "io.h"
36#include "cmd.h"
37#include "event.h"
38#include "tx.h"
39#include "rx.h"
40#include "ps.h"
41#include "init.h"
42#include "debugfs.h"
43#include "boot.h"
44
45void wl1251_enable_interrupts(struct wl1251 *wl)
46{
47 wl->if_ops->enable_irq(wl);
48}
49
50void wl1251_disable_interrupts(struct wl1251 *wl)
51{
52 wl->if_ops->disable_irq(wl);
53}
54
55static int wl1251_power_off(struct wl1251 *wl)
56{
57 return wl->if_ops->power(wl, false);
58}
59
60static int wl1251_power_on(struct wl1251 *wl)
61{
62 return wl->if_ops->power(wl, true);
63}
64
65static int wl1251_fetch_firmware(struct wl1251 *wl)
66{
67 const struct firmware *fw;
68 struct device *dev = wiphy_dev(wl->hw->wiphy);
69 int ret;
70
71 ret = request_firmware(&fw, WL1251_FW_NAME, dev);
72
73 if (ret < 0) {
74 wl1251_error("could not get firmware: %d", ret);
75 return ret;
76 }
77
78 if (fw->size % 4) {
79 wl1251_error("firmware size is not multiple of 32 bits: %zu",
80 fw->size);
81 ret = -EILSEQ;
82 goto out;
83 }
84
85 wl->fw_len = fw->size;
86 wl->fw = vmalloc(wl->fw_len);
87
88 if (!wl->fw) {
89 wl1251_error("could not allocate memory for the firmware");
90 ret = -ENOMEM;
91 goto out;
92 }
93
94 memcpy(wl->fw, fw->data, wl->fw_len);
95
96 ret = 0;
97
98out:
99 release_firmware(fw);
100
101 return ret;
102}
103
104static int wl1251_fetch_nvs(struct wl1251 *wl)
105{
106 const struct firmware *fw;
107 struct device *dev = wiphy_dev(wl->hw->wiphy);
108 int ret;
109
110 ret = request_firmware(&fw, WL1251_NVS_NAME, dev);
111
112 if (ret < 0) {
113 wl1251_error("could not get nvs file: %d", ret);
114 return ret;
115 }
116
117 if (fw->size % 4) {
118 wl1251_error("nvs size is not multiple of 32 bits: %zu",
119 fw->size);
120 ret = -EILSEQ;
121 goto out;
122 }
123
124 wl->nvs_len = fw->size;
125 wl->nvs = kmemdup(fw->data, wl->nvs_len, GFP_KERNEL);
126
127 if (!wl->nvs) {
128 wl1251_error("could not allocate memory for the nvs file");
129 ret = -ENOMEM;
130 goto out;
131 }
132
133 ret = 0;
134
135out:
136 release_firmware(fw);
137
138 return ret;
139}
140
141static void wl1251_fw_wakeup(struct wl1251 *wl)
142{
143 u32 elp_reg;
144
145 elp_reg = ELPCTRL_WAKE_UP;
146 wl1251_write_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
147 elp_reg = wl1251_read_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
148
149 if (!(elp_reg & ELPCTRL_WLAN_READY))
150 wl1251_warning("WLAN not ready");
151}
152
153static int wl1251_chip_wakeup(struct wl1251 *wl)
154{
155 int ret;
156
157 ret = wl1251_power_on(wl);
158 if (ret < 0)
159 return ret;
160
161 msleep(WL1251_POWER_ON_SLEEP);
162 wl->if_ops->reset(wl);
163
164 /* We don't need a real memory partition here, because we only want
165 * to use the registers at this point. */
166 wl1251_set_partition(wl,
167 0x00000000,
168 0x00000000,
169 REGISTERS_BASE,
170 REGISTERS_DOWN_SIZE);
171
172 /* ELP module wake up */
173 wl1251_fw_wakeup(wl);
174
175 /* whal_FwCtrl_BootSm() */
176
177 /* 0. read chip id from CHIP_ID */
178 wl->chip_id = wl1251_reg_read32(wl, CHIP_ID_B);
179
180 /* 1. check if chip id is valid */
181
182 switch (wl->chip_id) {
183 case CHIP_ID_1251_PG12:
184 wl1251_debug(DEBUG_BOOT, "chip id 0x%x (1251 PG12)",
185 wl->chip_id);
186 break;
187 case CHIP_ID_1251_PG11:
188 wl1251_debug(DEBUG_BOOT, "chip id 0x%x (1251 PG11)",
189 wl->chip_id);
190 break;
191 case CHIP_ID_1251_PG10:
192 default:
193 wl1251_error("unsupported chip id: 0x%x", wl->chip_id);
194 ret = -ENODEV;
195 goto out;
196 }
197
198 if (wl->fw == NULL) {
199 ret = wl1251_fetch_firmware(wl);
200 if (ret < 0)
201 goto out;
202 }
203
204 if (wl->nvs == NULL && !wl->use_eeprom) {
205 /* No NVS from netlink, try to get it from the filesystem */
206 ret = wl1251_fetch_nvs(wl);
207 if (ret < 0)
208 goto out;
209 }
210
211out:
212 return ret;
213}
214
215#define WL1251_IRQ_LOOP_COUNT 10
216static void wl1251_irq_work(struct work_struct *work)
217{
218 u32 intr, ctr = WL1251_IRQ_LOOP_COUNT;
219 struct wl1251 *wl =
220 container_of(work, struct wl1251, irq_work);
221 int ret;
222
223 mutex_lock(&wl->mutex);
224
225 wl1251_debug(DEBUG_IRQ, "IRQ work");
226
227 if (wl->state == WL1251_STATE_OFF)
228 goto out;
229
230 ret = wl1251_ps_elp_wakeup(wl);
231 if (ret < 0)
232 goto out;
233
234 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_MASK, WL1251_ACX_INTR_ALL);
235
236 intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_CLEAR);
237 wl1251_debug(DEBUG_IRQ, "intr: 0x%x", intr);
238
239 do {
240 if (wl->data_path) {
241 wl->rx_counter = wl1251_mem_read32(
242 wl, wl->data_path->rx_control_addr);
243
244 /* We handle a frmware bug here */
245 switch ((wl->rx_counter - wl->rx_handled) & 0xf) {
246 case 0:
247 wl1251_debug(DEBUG_IRQ,
248 "RX: FW and host in sync");
249 intr &= ~WL1251_ACX_INTR_RX0_DATA;
250 intr &= ~WL1251_ACX_INTR_RX1_DATA;
251 break;
252 case 1:
253 wl1251_debug(DEBUG_IRQ, "RX: FW +1");
254 intr |= WL1251_ACX_INTR_RX0_DATA;
255 intr &= ~WL1251_ACX_INTR_RX1_DATA;
256 break;
257 case 2:
258 wl1251_debug(DEBUG_IRQ, "RX: FW +2");
259 intr |= WL1251_ACX_INTR_RX0_DATA;
260 intr |= WL1251_ACX_INTR_RX1_DATA;
261 break;
262 default:
263 wl1251_warning(
264 "RX: FW and host out of sync: %d",
265 wl->rx_counter - wl->rx_handled);
266 break;
267 }
268
269 wl->rx_handled = wl->rx_counter;
270
271 wl1251_debug(DEBUG_IRQ, "RX counter: %d",
272 wl->rx_counter);
273 }
274
275 intr &= wl->intr_mask;
276
277 if (intr == 0) {
278 wl1251_debug(DEBUG_IRQ, "INTR is 0");
279 goto out_sleep;
280 }
281
282 if (intr & WL1251_ACX_INTR_RX0_DATA) {
283 wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_RX0_DATA");
284 wl1251_rx(wl);
285 }
286
287 if (intr & WL1251_ACX_INTR_RX1_DATA) {
288 wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_RX1_DATA");
289 wl1251_rx(wl);
290 }
291
292 if (intr & WL1251_ACX_INTR_TX_RESULT) {
293 wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_TX_RESULT");
294 wl1251_tx_complete(wl);
295 }
296
297 if (intr & WL1251_ACX_INTR_EVENT_A) {
298 wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_EVENT_A");
299 wl1251_event_handle(wl, 0);
300 }
301
302 if (intr & WL1251_ACX_INTR_EVENT_B) {
303 wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_EVENT_B");
304 wl1251_event_handle(wl, 1);
305 }
306
307 if (intr & WL1251_ACX_INTR_INIT_COMPLETE)
308 wl1251_debug(DEBUG_IRQ,
309 "WL1251_ACX_INTR_INIT_COMPLETE");
310
311 if (--ctr == 0)
312 break;
313
314 intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_CLEAR);
315 } while (intr);
316
317out_sleep:
318 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_MASK, ~(wl->intr_mask));
319 wl1251_ps_elp_sleep(wl);
320
321out:
322 mutex_unlock(&wl->mutex);
323}
324
325static int wl1251_join(struct wl1251 *wl, u8 bss_type, u8 channel,
326 u16 beacon_interval, u8 dtim_period)
327{
328 int ret;
329
330 ret = wl1251_acx_frame_rates(wl, DEFAULT_HW_GEN_TX_RATE,
331 DEFAULT_HW_GEN_MODULATION_TYPE,
332 wl->tx_mgmt_frm_rate,
333 wl->tx_mgmt_frm_mod);
334 if (ret < 0)
335 goto out;
336
337
338 ret = wl1251_cmd_join(wl, bss_type, channel, beacon_interval,
339 dtim_period);
340 if (ret < 0)
341 goto out;
342
343 ret = wl1251_event_wait(wl, JOIN_EVENT_COMPLETE_ID, 100);
344 if (ret < 0)
345 wl1251_warning("join timeout");
346
347out:
348 return ret;
349}
350
351static void wl1251_filter_work(struct work_struct *work)
352{
353 struct wl1251 *wl =
354 container_of(work, struct wl1251, filter_work);
355 int ret;
356
357 mutex_lock(&wl->mutex);
358
359 if (wl->state == WL1251_STATE_OFF)
360 goto out;
361
362 ret = wl1251_ps_elp_wakeup(wl);
363 if (ret < 0)
364 goto out;
365
366 ret = wl1251_join(wl, wl->bss_type, wl->channel, wl->beacon_int,
367 wl->dtim_period);
368 if (ret < 0)
369 goto out_sleep;
370
371out_sleep:
372 wl1251_ps_elp_sleep(wl);
373
374out:
375 mutex_unlock(&wl->mutex);
376}
377
378static void wl1251_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
379{
380 struct wl1251 *wl = hw->priv;
381 unsigned long flags;
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_HIGH_WATERMARK) {
397 wl1251_debug(DEBUG_TX, "op_tx: tx_queue full, stop queues");
398
399 spin_lock_irqsave(&wl->wl_lock, flags);
400 ieee80211_stop_queues(wl->hw);
401 wl->tx_queue_stopped = true;
402 spin_unlock_irqrestore(&wl->wl_lock, flags);
403 }
404}
405
406static int wl1251_op_start(struct ieee80211_hw *hw)
407{
408 struct wl1251 *wl = hw->priv;
409 struct wiphy *wiphy = hw->wiphy;
410 int ret = 0;
411
412 wl1251_debug(DEBUG_MAC80211, "mac80211 start");
413
414 mutex_lock(&wl->mutex);
415
416 if (wl->state != WL1251_STATE_OFF) {
417 wl1251_error("cannot start because not in off state: %d",
418 wl->state);
419 ret = -EBUSY;
420 goto out;
421 }
422
423 ret = wl1251_chip_wakeup(wl);
424 if (ret < 0)
425 goto out;
426
427 ret = wl1251_boot(wl);
428 if (ret < 0)
429 goto out;
430
431 ret = wl1251_hw_init(wl);
432 if (ret < 0)
433 goto out;
434
435 ret = wl1251_acx_station_id(wl);
436 if (ret < 0)
437 goto out;
438
439 wl->state = WL1251_STATE_ON;
440
441 wl1251_info("firmware booted (%s)", wl->fw_ver);
442
443 /* update hw/fw version info in wiphy struct */
444 wiphy->hw_version = wl->chip_id;
445 strncpy(wiphy->fw_version, wl->fw_ver, sizeof(wiphy->fw_version));
446
447out:
448 if (ret < 0)
449 wl1251_power_off(wl);
450
451 mutex_unlock(&wl->mutex);
452
453 return ret;
454}
455
456static void wl1251_op_stop(struct ieee80211_hw *hw)
457{
458 struct wl1251 *wl = hw->priv;
459
460 wl1251_info("down");
461
462 wl1251_debug(DEBUG_MAC80211, "mac80211 stop");
463
464 mutex_lock(&wl->mutex);
465
466 WARN_ON(wl->state != WL1251_STATE_ON);
467
468 if (wl->scanning) {
469 ieee80211_scan_completed(wl->hw, true);
470 wl->scanning = false;
471 }
472
473 wl->state = WL1251_STATE_OFF;
474
475 wl1251_disable_interrupts(wl);
476
477 mutex_unlock(&wl->mutex);
478
479 cancel_work_sync(&wl->irq_work);
480 cancel_work_sync(&wl->tx_work);
481 cancel_work_sync(&wl->filter_work);
482
483 mutex_lock(&wl->mutex);
484
485 /* let's notify MAC80211 about the remaining pending TX frames */
486 wl1251_tx_flush(wl);
487 wl1251_power_off(wl);
488
489 memset(wl->bssid, 0, ETH_ALEN);
490 wl->listen_int = 1;
491 wl->bss_type = MAX_BSS_TYPE;
492
493 wl->data_in_count = 0;
494 wl->rx_counter = 0;
495 wl->rx_handled = 0;
496 wl->rx_current_buffer = 0;
497 wl->rx_last_id = 0;
498 wl->next_tx_complete = 0;
499 wl->elp = false;
500 wl->station_mode = STATION_ACTIVE_MODE;
501 wl->tx_queue_stopped = false;
502 wl->power_level = WL1251_DEFAULT_POWER_LEVEL;
503 wl->rssi_thold = 0;
504 wl->channel = WL1251_DEFAULT_CHANNEL;
505
506 wl1251_debugfs_reset(wl);
507
508 mutex_unlock(&wl->mutex);
509}
510
511static int wl1251_op_add_interface(struct ieee80211_hw *hw,
512 struct ieee80211_vif *vif)
513{
514 struct wl1251 *wl = hw->priv;
515 int ret = 0;
516
517 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
518 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
519
520 wl1251_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
521 vif->type, vif->addr);
522
523 mutex_lock(&wl->mutex);
524 if (wl->vif) {
525 ret = -EBUSY;
526 goto out;
527 }
528
529 wl->vif = vif;
530
531 switch (vif->type) {
532 case NL80211_IFTYPE_STATION:
533 wl->bss_type = BSS_TYPE_STA_BSS;
534 break;
535 case NL80211_IFTYPE_ADHOC:
536 wl->bss_type = BSS_TYPE_IBSS;
537 break;
538 default:
539 ret = -EOPNOTSUPP;
540 goto out;
541 }
542
543 if (memcmp(wl->mac_addr, vif->addr, ETH_ALEN)) {
544 memcpy(wl->mac_addr, vif->addr, ETH_ALEN);
545 SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
546 ret = wl1251_acx_station_id(wl);
547 if (ret < 0)
548 goto out;
549 }
550
551out:
552 mutex_unlock(&wl->mutex);
553 return ret;
554}
555
556static void wl1251_op_remove_interface(struct ieee80211_hw *hw,
557 struct ieee80211_vif *vif)
558{
559 struct wl1251 *wl = hw->priv;
560
561 mutex_lock(&wl->mutex);
562 wl1251_debug(DEBUG_MAC80211, "mac80211 remove interface");
563 wl->vif = NULL;
564 mutex_unlock(&wl->mutex);
565}
566
567static int wl1251_build_qos_null_data(struct wl1251 *wl)
568{
569 struct ieee80211_qos_hdr template;
570
571 memset(&template, 0, sizeof(template));
572
573 memcpy(template.addr1, wl->bssid, ETH_ALEN);
574 memcpy(template.addr2, wl->mac_addr, ETH_ALEN);
575 memcpy(template.addr3, wl->bssid, ETH_ALEN);
576
577 template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
578 IEEE80211_STYPE_QOS_NULLFUNC |
579 IEEE80211_FCTL_TODS);
580
581 /* FIXME: not sure what priority to use here */
582 template.qos_ctrl = cpu_to_le16(0);
583
584 return wl1251_cmd_template_set(wl, CMD_QOS_NULL_DATA, &template,
585 sizeof(template));
586}
587
588static int wl1251_op_config(struct ieee80211_hw *hw, u32 changed)
589{
590 struct wl1251 *wl = hw->priv;
591 struct ieee80211_conf *conf = &hw->conf;
592 int channel, ret = 0;
593
594 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
595
596 wl1251_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d",
597 channel,
598 conf->flags & IEEE80211_CONF_PS ? "on" : "off",
599 conf->power_level);
600
601 mutex_lock(&wl->mutex);
602
603 ret = wl1251_ps_elp_wakeup(wl);
604 if (ret < 0)
605 goto out;
606
607 if (channel != wl->channel) {
608 wl->channel = channel;
609
610 ret = wl1251_join(wl, wl->bss_type, wl->channel,
611 wl->beacon_int, wl->dtim_period);
612 if (ret < 0)
613 goto out_sleep;
614 }
615
616 if (conf->flags & IEEE80211_CONF_PS && !wl->psm_requested) {
617 wl1251_debug(DEBUG_PSM, "psm enabled");
618
619 wl->psm_requested = true;
620
621 wl->dtim_period = conf->ps_dtim_period;
622
623 ret = wl1251_acx_wr_tbtt_and_dtim(wl, wl->beacon_int,
624 wl->dtim_period);
625
626 /*
627 * mac80211 enables PSM only if we're already associated.
628 */
629 ret = wl1251_ps_set_mode(wl, STATION_POWER_SAVE_MODE);
630 if (ret < 0)
631 goto out_sleep;
632 } else if (!(conf->flags & IEEE80211_CONF_PS) &&
633 wl->psm_requested) {
634 wl1251_debug(DEBUG_PSM, "psm disabled");
635
636 wl->psm_requested = false;
637
638 if (wl->station_mode != STATION_ACTIVE_MODE) {
639 ret = wl1251_ps_set_mode(wl, STATION_ACTIVE_MODE);
640 if (ret < 0)
641 goto out_sleep;
642 }
643 }
644
645 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
646 if (conf->flags & IEEE80211_CONF_IDLE) {
647 ret = wl1251_ps_set_mode(wl, STATION_IDLE);
648 if (ret < 0)
649 goto out_sleep;
650 } else {
651 ret = wl1251_ps_set_mode(wl, STATION_ACTIVE_MODE);
652 if (ret < 0)
653 goto out_sleep;
654 ret = wl1251_join(wl, wl->bss_type, wl->channel,
655 wl->beacon_int, wl->dtim_period);
656 if (ret < 0)
657 goto out_sleep;
658 }
659 }
660
661 if (conf->power_level != wl->power_level) {
662 ret = wl1251_acx_tx_power(wl, conf->power_level);
663 if (ret < 0)
664 goto out_sleep;
665
666 wl->power_level = conf->power_level;
667 }
668
669out_sleep:
670 wl1251_ps_elp_sleep(wl);
671
672out:
673 mutex_unlock(&wl->mutex);
674
675 return ret;
676}
677
678#define WL1251_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
679 FIF_ALLMULTI | \
680 FIF_FCSFAIL | \
681 FIF_BCN_PRBRESP_PROMISC | \
682 FIF_CONTROL | \
683 FIF_OTHER_BSS)
684
685static void wl1251_op_configure_filter(struct ieee80211_hw *hw,
686 unsigned int changed,
687 unsigned int *total,u64 multicast)
688{
689 struct wl1251 *wl = hw->priv;
690
691 wl1251_debug(DEBUG_MAC80211, "mac80211 configure filter");
692
693 *total &= WL1251_SUPPORTED_FILTERS;
694 changed &= WL1251_SUPPORTED_FILTERS;
695
696 if (changed == 0)
697 /* no filters which we support changed */
698 return;
699
700 /* FIXME: wl->rx_config and wl->rx_filter are not protected */
701
702 wl->rx_config = WL1251_DEFAULT_RX_CONFIG;
703 wl->rx_filter = WL1251_DEFAULT_RX_FILTER;
704
705 if (*total & FIF_PROMISC_IN_BSS) {
706 wl->rx_config |= CFG_BSSID_FILTER_EN;
707 wl->rx_config |= CFG_RX_ALL_GOOD;
708 }
709 if (*total & FIF_ALLMULTI)
710 /*
711 * CFG_MC_FILTER_EN in rx_config needs to be 0 to receive
712 * all multicast frames
713 */
714 wl->rx_config &= ~CFG_MC_FILTER_EN;
715 if (*total & FIF_FCSFAIL)
716 wl->rx_filter |= CFG_RX_FCS_ERROR;
717 if (*total & FIF_BCN_PRBRESP_PROMISC) {
718 wl->rx_config &= ~CFG_BSSID_FILTER_EN;
719 wl->rx_config &= ~CFG_SSID_FILTER_EN;
720 }
721 if (*total & FIF_CONTROL)
722 wl->rx_filter |= CFG_RX_CTL_EN;
723 if (*total & FIF_OTHER_BSS)
724 wl->rx_filter &= ~CFG_BSSID_FILTER_EN;
725
726 /*
727 * FIXME: workqueues need to be properly cancelled on stop(), for
728 * now let's just disable changing the filter settings. They will
729 * be updated any on config().
730 */
731 /* schedule_work(&wl->filter_work); */
732}
733
734/* HW encryption */
735static int wl1251_set_key_type(struct wl1251 *wl,
736 struct wl1251_cmd_set_keys *key,
737 enum set_key_cmd cmd,
738 struct ieee80211_key_conf *mac80211_key,
739 const u8 *addr)
740{
741 switch (mac80211_key->cipher) {
742 case WLAN_CIPHER_SUITE_WEP40:
743 case WLAN_CIPHER_SUITE_WEP104:
744 if (is_broadcast_ether_addr(addr))
745 key->key_type = KEY_WEP_DEFAULT;
746 else
747 key->key_type = KEY_WEP_ADDR;
748
749 mac80211_key->hw_key_idx = mac80211_key->keyidx;
750 break;
751 case WLAN_CIPHER_SUITE_TKIP:
752 if (is_broadcast_ether_addr(addr))
753 key->key_type = KEY_TKIP_MIC_GROUP;
754 else
755 key->key_type = KEY_TKIP_MIC_PAIRWISE;
756
757 mac80211_key->hw_key_idx = mac80211_key->keyidx;
758 break;
759 case WLAN_CIPHER_SUITE_CCMP:
760 if (is_broadcast_ether_addr(addr))
761 key->key_type = KEY_AES_GROUP;
762 else
763 key->key_type = KEY_AES_PAIRWISE;
764 mac80211_key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
765 break;
766 default:
767 wl1251_error("Unknown key cipher 0x%x", mac80211_key->cipher);
768 return -EOPNOTSUPP;
769 }
770
771 return 0;
772}
773
774static int wl1251_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
775 struct ieee80211_vif *vif,
776 struct ieee80211_sta *sta,
777 struct ieee80211_key_conf *key)
778{
779 struct wl1251 *wl = hw->priv;
780 struct wl1251_cmd_set_keys *wl_cmd;
781 const u8 *addr;
782 int ret;
783
784 static const u8 bcast_addr[ETH_ALEN] =
785 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
786
787 wl1251_debug(DEBUG_MAC80211, "mac80211 set key");
788
789 wl_cmd = kzalloc(sizeof(*wl_cmd), GFP_KERNEL);
790 if (!wl_cmd) {
791 ret = -ENOMEM;
792 goto out;
793 }
794
795 addr = sta ? sta->addr : bcast_addr;
796
797 wl1251_debug(DEBUG_CRYPT, "CMD: 0x%x", cmd);
798 wl1251_dump(DEBUG_CRYPT, "ADDR: ", addr, ETH_ALEN);
799 wl1251_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
800 key->cipher, key->keyidx, key->keylen, key->flags);
801 wl1251_dump(DEBUG_CRYPT, "KEY: ", key->key, key->keylen);
802
803 if (is_zero_ether_addr(addr)) {
804 /* We dont support TX only encryption */
805 ret = -EOPNOTSUPP;
806 goto out;
807 }
808
809 mutex_lock(&wl->mutex);
810
811 ret = wl1251_ps_elp_wakeup(wl);
812 if (ret < 0)
813 goto out_unlock;
814
815 switch (cmd) {
816 case SET_KEY:
817 wl_cmd->key_action = KEY_ADD_OR_REPLACE;
818 break;
819 case DISABLE_KEY:
820 wl_cmd->key_action = KEY_REMOVE;
821 break;
822 default:
823 wl1251_error("Unsupported key cmd 0x%x", cmd);
824 break;
825 }
826
827 ret = wl1251_set_key_type(wl, wl_cmd, cmd, key, addr);
828 if (ret < 0) {
829 wl1251_error("Set KEY type failed");
830 goto out_sleep;
831 }
832
833 if (wl_cmd->key_type != KEY_WEP_DEFAULT)
834 memcpy(wl_cmd->addr, addr, ETH_ALEN);
835
836 if ((wl_cmd->key_type == KEY_TKIP_MIC_GROUP) ||
837 (wl_cmd->key_type == KEY_TKIP_MIC_PAIRWISE)) {
838 /*
839 * We get the key in the following form:
840 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
841 * but the target is expecting:
842 * TKIP - RX MIC - TX MIC
843 */
844 memcpy(wl_cmd->key, key->key, 16);
845 memcpy(wl_cmd->key + 16, key->key + 24, 8);
846 memcpy(wl_cmd->key + 24, key->key + 16, 8);
847
848 } else {
849 memcpy(wl_cmd->key, key->key, key->keylen);
850 }
851 wl_cmd->key_size = key->keylen;
852
853 wl_cmd->id = key->keyidx;
854 wl_cmd->ssid_profile = 0;
855
856 wl1251_dump(DEBUG_CRYPT, "TARGET KEY: ", wl_cmd, sizeof(*wl_cmd));
857
858 ret = wl1251_cmd_send(wl, CMD_SET_KEYS, wl_cmd, sizeof(*wl_cmd));
859 if (ret < 0) {
860 wl1251_warning("could not set keys");
861 goto out_sleep;
862 }
863
864out_sleep:
865 wl1251_ps_elp_sleep(wl);
866
867out_unlock:
868 mutex_unlock(&wl->mutex);
869
870out:
871 kfree(wl_cmd);
872
873 return ret;
874}
875
876static int wl1251_op_hw_scan(struct ieee80211_hw *hw,
877 struct ieee80211_vif *vif,
878 struct cfg80211_scan_request *req)
879{
880 struct wl1251 *wl = hw->priv;
881 struct sk_buff *skb;
882 size_t ssid_len = 0;
883 u8 *ssid = NULL;
884 int ret;
885
886 wl1251_debug(DEBUG_MAC80211, "mac80211 hw scan");
887
888 if (req->n_ssids) {
889 ssid = req->ssids[0].ssid;
890 ssid_len = req->ssids[0].ssid_len;
891 }
892
893 mutex_lock(&wl->mutex);
894
895 if (wl->scanning) {
896 wl1251_debug(DEBUG_SCAN, "scan already in progress");
897 ret = -EINVAL;
898 goto out;
899 }
900
901 ret = wl1251_ps_elp_wakeup(wl);
902 if (ret < 0)
903 goto out;
904
905 skb = ieee80211_probereq_get(wl->hw, wl->vif, ssid, ssid_len,
906 req->ie, req->ie_len);
907 if (!skb) {
908 ret = -ENOMEM;
909 goto out;
910 }
911
912 ret = wl1251_cmd_template_set(wl, CMD_PROBE_REQ, skb->data,
913 skb->len);
914 dev_kfree_skb(skb);
915 if (ret < 0)
916 goto out_sleep;
917
918 ret = wl1251_cmd_trigger_scan_to(wl, 0);
919 if (ret < 0)
920 goto out_sleep;
921
922 wl->scanning = true;
923
924 ret = wl1251_cmd_scan(wl, ssid, ssid_len, req->channels,
925 req->n_channels, WL1251_SCAN_NUM_PROBES);
926 if (ret < 0) {
927 wl->scanning = false;
928 goto out_sleep;
929 }
930
931out_sleep:
932 wl1251_ps_elp_sleep(wl);
933
934out:
935 mutex_unlock(&wl->mutex);
936
937 return ret;
938}
939
940static int wl1251_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
941{
942 struct wl1251 *wl = hw->priv;
943 int ret;
944
945 mutex_lock(&wl->mutex);
946
947 ret = wl1251_ps_elp_wakeup(wl);
948 if (ret < 0)
949 goto out;
950
951 ret = wl1251_acx_rts_threshold(wl, (u16) value);
952 if (ret < 0)
953 wl1251_warning("wl1251_op_set_rts_threshold failed: %d", ret);
954
955 wl1251_ps_elp_sleep(wl);
956
957out:
958 mutex_unlock(&wl->mutex);
959
960 return ret;
961}
962
963static void wl1251_op_bss_info_changed(struct ieee80211_hw *hw,
964 struct ieee80211_vif *vif,
965 struct ieee80211_bss_conf *bss_conf,
966 u32 changed)
967{
968 struct wl1251 *wl = hw->priv;
969 struct sk_buff *beacon, *skb;
970 int ret;
971
972 wl1251_debug(DEBUG_MAC80211, "mac80211 bss info changed");
973
974 mutex_lock(&wl->mutex);
975
976 ret = wl1251_ps_elp_wakeup(wl);
977 if (ret < 0)
978 goto out;
979
980 if (changed & BSS_CHANGED_CQM) {
981 ret = wl1251_acx_low_rssi(wl, bss_conf->cqm_rssi_thold,
982 WL1251_DEFAULT_LOW_RSSI_WEIGHT,
983 WL1251_DEFAULT_LOW_RSSI_DEPTH,
984 WL1251_ACX_LOW_RSSI_TYPE_EDGE);
985 if (ret < 0)
986 goto out;
987 wl->rssi_thold = bss_conf->cqm_rssi_thold;
988 }
989
990 if (changed & BSS_CHANGED_BSSID) {
991 memcpy(wl->bssid, bss_conf->bssid, ETH_ALEN);
992
993 skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
994 if (!skb)
995 goto out_sleep;
996
997 ret = wl1251_cmd_template_set(wl, CMD_NULL_DATA,
998 skb->data, skb->len);
999 dev_kfree_skb(skb);
1000 if (ret < 0)
1001 goto out_sleep;
1002
1003 ret = wl1251_build_qos_null_data(wl);
1004 if (ret < 0)
1005 goto out;
1006
1007 if (wl->bss_type != BSS_TYPE_IBSS) {
1008 ret = wl1251_join(wl, wl->bss_type, wl->channel,
1009 wl->beacon_int, wl->dtim_period);
1010 if (ret < 0)
1011 goto out_sleep;
1012 }
1013 }
1014
1015 if (changed & BSS_CHANGED_ASSOC) {
1016 if (bss_conf->assoc) {
1017 wl->beacon_int = bss_conf->beacon_int;
1018
1019 skb = ieee80211_pspoll_get(wl->hw, wl->vif);
1020 if (!skb)
1021 goto out_sleep;
1022
1023 ret = wl1251_cmd_template_set(wl, CMD_PS_POLL,
1024 skb->data,
1025 skb->len);
1026 dev_kfree_skb(skb);
1027 if (ret < 0)
1028 goto out_sleep;
1029
1030 ret = wl1251_acx_aid(wl, bss_conf->aid);
1031 if (ret < 0)
1032 goto out_sleep;
1033 } else {
1034 /* use defaults when not associated */
1035 wl->beacon_int = WL1251_DEFAULT_BEACON_INT;
1036 wl->dtim_period = WL1251_DEFAULT_DTIM_PERIOD;
1037 }
1038 }
1039 if (changed & BSS_CHANGED_ERP_SLOT) {
1040 if (bss_conf->use_short_slot)
1041 ret = wl1251_acx_slot(wl, SLOT_TIME_SHORT);
1042 else
1043 ret = wl1251_acx_slot(wl, SLOT_TIME_LONG);
1044 if (ret < 0) {
1045 wl1251_warning("Set slot time failed %d", ret);
1046 goto out_sleep;
1047 }
1048 }
1049
1050 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1051 if (bss_conf->use_short_preamble)
1052 wl1251_acx_set_preamble(wl, ACX_PREAMBLE_SHORT);
1053 else
1054 wl1251_acx_set_preamble(wl, ACX_PREAMBLE_LONG);
1055 }
1056
1057 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1058 if (bss_conf->use_cts_prot)
1059 ret = wl1251_acx_cts_protect(wl, CTSPROTECT_ENABLE);
1060 else
1061 ret = wl1251_acx_cts_protect(wl, CTSPROTECT_DISABLE);
1062 if (ret < 0) {
1063 wl1251_warning("Set ctsprotect failed %d", ret);
1064 goto out_sleep;
1065 }
1066 }
1067
1068 if (changed & BSS_CHANGED_BEACON) {
1069 beacon = ieee80211_beacon_get(hw, vif);
1070 if (!beacon)
1071 goto out_sleep;
1072
1073 ret = wl1251_cmd_template_set(wl, CMD_BEACON, beacon->data,
1074 beacon->len);
1075
1076 if (ret < 0) {
1077 dev_kfree_skb(beacon);
1078 goto out_sleep;
1079 }
1080
1081 ret = wl1251_cmd_template_set(wl, CMD_PROBE_RESP, beacon->data,
1082 beacon->len);
1083
1084 dev_kfree_skb(beacon);
1085
1086 if (ret < 0)
1087 goto out_sleep;
1088
1089 ret = wl1251_join(wl, wl->bss_type, wl->beacon_int,
1090 wl->channel, wl->dtim_period);
1091
1092 if (ret < 0)
1093 goto out_sleep;
1094 }
1095
1096out_sleep:
1097 wl1251_ps_elp_sleep(wl);
1098
1099out:
1100 mutex_unlock(&wl->mutex);
1101}
1102
1103
1104/* can't be const, mac80211 writes to this */
1105static struct ieee80211_rate wl1251_rates[] = {
1106 { .bitrate = 10,
1107 .hw_value = 0x1,
1108 .hw_value_short = 0x1, },
1109 { .bitrate = 20,
1110 .hw_value = 0x2,
1111 .hw_value_short = 0x2,
1112 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1113 { .bitrate = 55,
1114 .hw_value = 0x4,
1115 .hw_value_short = 0x4,
1116 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1117 { .bitrate = 110,
1118 .hw_value = 0x20,
1119 .hw_value_short = 0x20,
1120 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
1121 { .bitrate = 60,
1122 .hw_value = 0x8,
1123 .hw_value_short = 0x8, },
1124 { .bitrate = 90,
1125 .hw_value = 0x10,
1126 .hw_value_short = 0x10, },
1127 { .bitrate = 120,
1128 .hw_value = 0x40,
1129 .hw_value_short = 0x40, },
1130 { .bitrate = 180,
1131 .hw_value = 0x80,
1132 .hw_value_short = 0x80, },
1133 { .bitrate = 240,
1134 .hw_value = 0x200,
1135 .hw_value_short = 0x200, },
1136 { .bitrate = 360,
1137 .hw_value = 0x400,
1138 .hw_value_short = 0x400, },
1139 { .bitrate = 480,
1140 .hw_value = 0x800,
1141 .hw_value_short = 0x800, },
1142 { .bitrate = 540,
1143 .hw_value = 0x1000,
1144 .hw_value_short = 0x1000, },
1145};
1146
1147/* can't be const, mac80211 writes to this */
1148static struct ieee80211_channel wl1251_channels[] = {
1149 { .hw_value = 1, .center_freq = 2412},
1150 { .hw_value = 2, .center_freq = 2417},
1151 { .hw_value = 3, .center_freq = 2422},
1152 { .hw_value = 4, .center_freq = 2427},
1153 { .hw_value = 5, .center_freq = 2432},
1154 { .hw_value = 6, .center_freq = 2437},
1155 { .hw_value = 7, .center_freq = 2442},
1156 { .hw_value = 8, .center_freq = 2447},
1157 { .hw_value = 9, .center_freq = 2452},
1158 { .hw_value = 10, .center_freq = 2457},
1159 { .hw_value = 11, .center_freq = 2462},
1160 { .hw_value = 12, .center_freq = 2467},
1161 { .hw_value = 13, .center_freq = 2472},
1162};
1163
1164static int wl1251_op_conf_tx(struct ieee80211_hw *hw,
1165 struct ieee80211_vif *vif, u16 queue,
1166 const struct ieee80211_tx_queue_params *params)
1167{
1168 enum wl1251_acx_ps_scheme ps_scheme;
1169 struct wl1251 *wl = hw->priv;
1170 int ret;
1171
1172 mutex_lock(&wl->mutex);
1173
1174 wl1251_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue);
1175
1176 ret = wl1251_ps_elp_wakeup(wl);
1177 if (ret < 0)
1178 goto out;
1179
1180 /* mac80211 uses units of 32 usec */
1181 ret = wl1251_acx_ac_cfg(wl, wl1251_tx_get_queue(queue),
1182 params->cw_min, params->cw_max,
1183 params->aifs, params->txop * 32);
1184 if (ret < 0)
1185 goto out_sleep;
1186
1187 if (params->uapsd)
1188 ps_scheme = WL1251_ACX_PS_SCHEME_UPSD_TRIGGER;
1189 else
1190 ps_scheme = WL1251_ACX_PS_SCHEME_LEGACY;
1191
1192 ret = wl1251_acx_tid_cfg(wl, wl1251_tx_get_queue(queue),
1193 CHANNEL_TYPE_EDCF,
1194 wl1251_tx_get_queue(queue), ps_scheme,
1195 WL1251_ACX_ACK_POLICY_LEGACY);
1196 if (ret < 0)
1197 goto out_sleep;
1198
1199out_sleep:
1200 wl1251_ps_elp_sleep(wl);
1201
1202out:
1203 mutex_unlock(&wl->mutex);
1204
1205 return ret;
1206}
1207
1208static int wl1251_op_get_survey(struct ieee80211_hw *hw, int idx,
1209 struct survey_info *survey)
1210{
1211 struct wl1251 *wl = hw->priv;
1212 struct ieee80211_conf *conf = &hw->conf;
1213
1214 if (idx != 0)
1215 return -ENOENT;
1216
1217 survey->channel = conf->channel;
1218 survey->filled = SURVEY_INFO_NOISE_DBM;
1219 survey->noise = wl->noise;
1220
1221 return 0;
1222}
1223
1224/* can't be const, mac80211 writes to this */
1225static struct ieee80211_supported_band wl1251_band_2ghz = {
1226 .channels = wl1251_channels,
1227 .n_channels = ARRAY_SIZE(wl1251_channels),
1228 .bitrates = wl1251_rates,
1229 .n_bitrates = ARRAY_SIZE(wl1251_rates),
1230};
1231
1232static const struct ieee80211_ops wl1251_ops = {
1233 .start = wl1251_op_start,
1234 .stop = wl1251_op_stop,
1235 .add_interface = wl1251_op_add_interface,
1236 .remove_interface = wl1251_op_remove_interface,
1237 .config = wl1251_op_config,
1238 .configure_filter = wl1251_op_configure_filter,
1239 .tx = wl1251_op_tx,
1240 .set_key = wl1251_op_set_key,
1241 .hw_scan = wl1251_op_hw_scan,
1242 .bss_info_changed = wl1251_op_bss_info_changed,
1243 .set_rts_threshold = wl1251_op_set_rts_threshold,
1244 .conf_tx = wl1251_op_conf_tx,
1245 .get_survey = wl1251_op_get_survey,
1246};
1247
1248static int wl1251_read_eeprom_byte(struct wl1251 *wl, off_t offset, u8 *data)
1249{
1250 unsigned long timeout;
1251
1252 wl1251_reg_write32(wl, EE_ADDR, offset);
1253 wl1251_reg_write32(wl, EE_CTL, EE_CTL_READ);
1254
1255 /* EE_CTL_READ clears when data is ready */
1256 timeout = jiffies + msecs_to_jiffies(100);
1257 while (1) {
1258 if (!(wl1251_reg_read32(wl, EE_CTL) & EE_CTL_READ))
1259 break;
1260
1261 if (time_after(jiffies, timeout))
1262 return -ETIMEDOUT;
1263
1264 msleep(1);
1265 }
1266
1267 *data = wl1251_reg_read32(wl, EE_DATA);
1268 return 0;
1269}
1270
1271static int wl1251_read_eeprom(struct wl1251 *wl, off_t offset,
1272 u8 *data, size_t len)
1273{
1274 size_t i;
1275 int ret;
1276
1277 wl1251_reg_write32(wl, EE_START, 0);
1278
1279 for (i = 0; i < len; i++) {
1280 ret = wl1251_read_eeprom_byte(wl, offset + i, &data[i]);
1281 if (ret < 0)
1282 return ret;
1283 }
1284
1285 return 0;
1286}
1287
1288static int wl1251_read_eeprom_mac(struct wl1251 *wl)
1289{
1290 u8 mac[ETH_ALEN];
1291 int i, ret;
1292
1293 wl1251_set_partition(wl, 0, 0, REGISTERS_BASE, REGISTERS_DOWN_SIZE);
1294
1295 ret = wl1251_read_eeprom(wl, 0x1c, mac, sizeof(mac));
1296 if (ret < 0) {
1297 wl1251_warning("failed to read MAC address from EEPROM");
1298 return ret;
1299 }
1300
1301 /* MAC is stored in reverse order */
1302 for (i = 0; i < ETH_ALEN; i++)
1303 wl->mac_addr[i] = mac[ETH_ALEN - i - 1];
1304
1305 return 0;
1306}
1307
1308static int wl1251_register_hw(struct wl1251 *wl)
1309{
1310 int ret;
1311
1312 if (wl->mac80211_registered)
1313 return 0;
1314
1315 SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
1316
1317 ret = ieee80211_register_hw(wl->hw);
1318 if (ret < 0) {
1319 wl1251_error("unable to register mac80211 hw: %d", ret);
1320 return ret;
1321 }
1322
1323 wl->mac80211_registered = true;
1324
1325 wl1251_notice("loaded");
1326
1327 return 0;
1328}
1329
1330int wl1251_init_ieee80211(struct wl1251 *wl)
1331{
1332 int ret;
1333
1334 /* The tx descriptor buffer and the TKIP space */
1335 wl->hw->extra_tx_headroom = sizeof(struct tx_double_buffer_desc)
1336 + WL1251_TKIP_IV_SPACE;
1337
1338 /* unit us */
1339 /* FIXME: find a proper value */
1340 wl->hw->channel_change_time = 10000;
1341
1342 wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
1343 IEEE80211_HW_SUPPORTS_PS |
1344 IEEE80211_HW_SUPPORTS_UAPSD;
1345
1346 wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1347 BIT(NL80211_IFTYPE_ADHOC);
1348 wl->hw->wiphy->max_scan_ssids = 1;
1349 wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl1251_band_2ghz;
1350
1351 wl->hw->queues = 4;
1352
1353 if (wl->use_eeprom)
1354 wl1251_read_eeprom_mac(wl);
1355
1356 ret = wl1251_register_hw(wl);
1357 if (ret)
1358 goto out;
1359
1360 wl1251_debugfs_init(wl);
1361 wl1251_notice("initialized");
1362
1363 ret = 0;
1364
1365out:
1366 return ret;
1367}
1368EXPORT_SYMBOL_GPL(wl1251_init_ieee80211);
1369
1370struct ieee80211_hw *wl1251_alloc_hw(void)
1371{
1372 struct ieee80211_hw *hw;
1373 struct wl1251 *wl;
1374 int i;
1375 static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf};
1376
1377 hw = ieee80211_alloc_hw(sizeof(*wl), &wl1251_ops);
1378 if (!hw) {
1379 wl1251_error("could not alloc ieee80211_hw");
1380 return ERR_PTR(-ENOMEM);
1381 }
1382
1383 wl = hw->priv;
1384 memset(wl, 0, sizeof(*wl));
1385
1386 wl->hw = hw;
1387
1388 wl->data_in_count = 0;
1389
1390 skb_queue_head_init(&wl->tx_queue);
1391
1392 INIT_WORK(&wl->filter_work, wl1251_filter_work);
1393 INIT_DELAYED_WORK(&wl->elp_work, wl1251_elp_work);
1394 wl->channel = WL1251_DEFAULT_CHANNEL;
1395 wl->scanning = false;
1396 wl->default_key = 0;
1397 wl->listen_int = 1;
1398 wl->rx_counter = 0;
1399 wl->rx_handled = 0;
1400 wl->rx_current_buffer = 0;
1401 wl->rx_last_id = 0;
1402 wl->rx_config = WL1251_DEFAULT_RX_CONFIG;
1403 wl->rx_filter = WL1251_DEFAULT_RX_FILTER;
1404 wl->elp = false;
1405 wl->station_mode = STATION_ACTIVE_MODE;
1406 wl->psm_requested = false;
1407 wl->tx_queue_stopped = false;
1408 wl->power_level = WL1251_DEFAULT_POWER_LEVEL;
1409 wl->rssi_thold = 0;
1410 wl->beacon_int = WL1251_DEFAULT_BEACON_INT;
1411 wl->dtim_period = WL1251_DEFAULT_DTIM_PERIOD;
1412 wl->vif = NULL;
1413
1414 for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
1415 wl->tx_frames[i] = NULL;
1416
1417 wl->next_tx_complete = 0;
1418
1419 INIT_WORK(&wl->irq_work, wl1251_irq_work);
1420 INIT_WORK(&wl->tx_work, wl1251_tx_work);
1421
1422 /*
1423 * In case our MAC address is not correctly set,
1424 * we use a random but Nokia MAC.
1425 */
1426 memcpy(wl->mac_addr, nokia_oui, 3);
1427 get_random_bytes(wl->mac_addr + 3, 3);
1428
1429 wl->state = WL1251_STATE_OFF;
1430 mutex_init(&wl->mutex);
1431
1432 wl->tx_mgmt_frm_rate = DEFAULT_HW_GEN_TX_RATE;
1433 wl->tx_mgmt_frm_mod = DEFAULT_HW_GEN_MODULATION_TYPE;
1434
1435 wl->rx_descriptor = kmalloc(sizeof(*wl->rx_descriptor), GFP_KERNEL);
1436 if (!wl->rx_descriptor) {
1437 wl1251_error("could not allocate memory for rx descriptor");
1438 ieee80211_free_hw(hw);
1439 return ERR_PTR(-ENOMEM);
1440 }
1441
1442 return hw;
1443}
1444EXPORT_SYMBOL_GPL(wl1251_alloc_hw);
1445
1446int wl1251_free_hw(struct wl1251 *wl)
1447{
1448 ieee80211_unregister_hw(wl->hw);
1449
1450 wl1251_debugfs_exit(wl);
1451
1452 kfree(wl->target_mem_map);
1453 kfree(wl->data_path);
1454 vfree(wl->fw);
1455 wl->fw = NULL;
1456 kfree(wl->nvs);
1457 wl->nvs = NULL;
1458
1459 kfree(wl->rx_descriptor);
1460 wl->rx_descriptor = NULL;
1461
1462 ieee80211_free_hw(wl->hw);
1463
1464 return 0;
1465}
1466EXPORT_SYMBOL_GPL(wl1251_free_hw);
1467
1468MODULE_DESCRIPTION("TI wl1251 Wireles LAN Driver Core");
1469MODULE_LICENSE("GPL");
1470MODULE_AUTHOR("Kalle Valo <kvalo@adurom.com>");
1471MODULE_FIRMWARE(WL1251_FW_NAME);
diff --git a/drivers/net/wireless/ti/wl1251/ps.c b/drivers/net/wireless/ti/wl1251/ps.c
new file mode 100644
index 000000000000..db719f7d2692
--- /dev/null
+++ b/drivers/net/wireless/ti/wl1251/ps.c
@@ -0,0 +1,185 @@
1/*
2 * This file is part of wl1251
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
22#include "reg.h"
23#include "ps.h"
24#include "cmd.h"
25#include "io.h"
26
27/* in ms */
28#define WL1251_WAKEUP_TIMEOUT 100
29
30void wl1251_elp_work(struct work_struct *work)
31{
32 struct delayed_work *dwork;
33 struct wl1251 *wl;
34
35 dwork = container_of(work, struct delayed_work, work);
36 wl = container_of(dwork, struct wl1251, elp_work);
37
38 wl1251_debug(DEBUG_PSM, "elp work");
39
40 mutex_lock(&wl->mutex);
41
42 if (wl->elp || wl->station_mode == STATION_ACTIVE_MODE)
43 goto out;
44
45 wl1251_debug(DEBUG_PSM, "chip to elp");
46 wl1251_write_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP);
47 wl->elp = true;
48
49out:
50 mutex_unlock(&wl->mutex);
51}
52
53#define ELP_ENTRY_DELAY 5
54
55/* Routines to toggle sleep mode while in ELP */
56void wl1251_ps_elp_sleep(struct wl1251 *wl)
57{
58 unsigned long delay;
59
60 if (wl->station_mode != STATION_ACTIVE_MODE) {
61 delay = msecs_to_jiffies(ELP_ENTRY_DELAY);
62 ieee80211_queue_delayed_work(wl->hw, &wl->elp_work, delay);
63 }
64}
65
66int wl1251_ps_elp_wakeup(struct wl1251 *wl)
67{
68 unsigned long timeout, start;
69 u32 elp_reg;
70
71 if (delayed_work_pending(&wl->elp_work))
72 cancel_delayed_work(&wl->elp_work);
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
107int wl1251_ps_set_mode(struct wl1251 *wl, enum wl1251_station_mode mode)
108{
109 int ret;
110
111 switch (mode) {
112 case STATION_POWER_SAVE_MODE:
113 wl1251_debug(DEBUG_PSM, "entering psm");
114
115 /* enable beacon filtering */
116 ret = wl1251_acx_beacon_filter_opt(wl, true);
117 if (ret < 0)
118 return ret;
119
120 ret = wl1251_acx_wake_up_conditions(wl,
121 WAKE_UP_EVENT_DTIM_BITMAP,
122 wl->listen_int);
123 if (ret < 0)
124 return ret;
125
126 ret = wl1251_acx_bet_enable(wl, WL1251_ACX_BET_ENABLE,
127 WL1251_DEFAULT_BET_CONSECUTIVE);
128 if (ret < 0)
129 return ret;
130
131 ret = wl1251_cmd_ps_mode(wl, CHIP_POWER_SAVE_MODE);
132 if (ret < 0)
133 return ret;
134
135 ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_ELP);
136 if (ret < 0)
137 return ret;
138 break;
139 case STATION_IDLE:
140 wl1251_debug(DEBUG_PSM, "entering idle");
141
142 ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_ELP);
143 if (ret < 0)
144 return ret;
145
146 ret = wl1251_cmd_template_set(wl, CMD_DISCONNECT, NULL, 0);
147 if (ret < 0)
148 return ret;
149 break;
150 case STATION_ACTIVE_MODE:
151 default:
152 wl1251_debug(DEBUG_PSM, "leaving psm");
153
154 ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_CAM);
155 if (ret < 0)
156 return ret;
157
158 /* disable BET */
159 ret = wl1251_acx_bet_enable(wl, WL1251_ACX_BET_DISABLE,
160 WL1251_DEFAULT_BET_CONSECUTIVE);
161 if (ret < 0)
162 return ret;
163
164 /* disable beacon filtering */
165 ret = wl1251_acx_beacon_filter_opt(wl, false);
166 if (ret < 0)
167 return ret;
168
169 ret = wl1251_acx_wake_up_conditions(wl,
170 WAKE_UP_EVENT_DTIM_BITMAP,
171 wl->listen_int);
172 if (ret < 0)
173 return ret;
174
175 ret = wl1251_cmd_ps_mode(wl, CHIP_ACTIVE_MODE);
176 if (ret < 0)
177 return ret;
178
179 break;
180 }
181 wl->station_mode = mode;
182
183 return ret;
184}
185
diff --git a/drivers/net/wireless/ti/wl1251/ps.h b/drivers/net/wireless/ti/wl1251/ps.h
new file mode 100644
index 000000000000..75efad246d67
--- /dev/null
+++ b/drivers/net/wireless/ti/wl1251/ps.h
@@ -0,0 +1,35 @@
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 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22
23#ifndef __WL1251_PS_H__
24#define __WL1251_PS_H__
25
26#include "wl1251.h"
27#include "acx.h"
28
29int wl1251_ps_set_mode(struct wl1251 *wl, enum wl1251_station_mode mode);
30void wl1251_ps_elp_sleep(struct wl1251 *wl);
31int wl1251_ps_elp_wakeup(struct wl1251 *wl);
32void wl1251_elp_work(struct work_struct *work);
33
34
35#endif /* __WL1251_PS_H__ */
diff --git a/drivers/net/wireless/ti/wl1251/reg.h b/drivers/net/wireless/ti/wl1251/reg.h
new file mode 100644
index 000000000000..a5809019c5c1
--- /dev/null
+++ b/drivers/net/wireless/ti/wl1251/reg.h
@@ -0,0 +1,655 @@
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 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22
23#ifndef __REG_H__
24#define __REG_H__
25
26#include <linux/bitops.h>
27
28#define REGISTERS_BASE 0x00300000
29#define DRPW_BASE 0x00310000
30
31#define REGISTERS_DOWN_SIZE 0x00008800
32#define REGISTERS_WORK_SIZE 0x0000b000
33
34#define HW_ACCESS_ELP_CTRL_REG_ADDR 0x1FFFC
35
36/* ELP register commands */
37#define ELPCTRL_WAKE_UP 0x1
38#define ELPCTRL_WAKE_UP_WLAN_READY 0x5
39#define ELPCTRL_SLEEP 0x0
40/* ELP WLAN_READY bit */
41#define ELPCTRL_WLAN_READY 0x2
42
43/* Device Configuration registers*/
44#define SOR_CFG (REGISTERS_BASE + 0x0800)
45#define ECPU_CTRL (REGISTERS_BASE + 0x0804)
46#define HI_CFG (REGISTERS_BASE + 0x0808)
47
48/* EEPROM registers */
49#define EE_START (REGISTERS_BASE + 0x080C)
50#define EE_CTL (REGISTERS_BASE + 0x2000)
51#define EE_DATA (REGISTERS_BASE + 0x2004)
52#define EE_ADDR (REGISTERS_BASE + 0x2008)
53
54#define EE_CTL_READ 2
55
56#define CHIP_ID_B (REGISTERS_BASE + 0x5674)
57
58#define CHIP_ID_1251_PG10 (0x7010101)
59#define CHIP_ID_1251_PG11 (0x7020101)
60#define CHIP_ID_1251_PG12 (0x7030101)
61
62#define ENABLE (REGISTERS_BASE + 0x5450)
63
64/* Power Management registers */
65#define ELP_CFG_MODE (REGISTERS_BASE + 0x5804)
66#define ELP_CMD (REGISTERS_BASE + 0x5808)
67#define PLL_CAL_TIME (REGISTERS_BASE + 0x5810)
68#define CLK_REQ_TIME (REGISTERS_BASE + 0x5814)
69#define CLK_BUF_TIME (REGISTERS_BASE + 0x5818)
70
71#define CFG_PLL_SYNC_CNT (REGISTERS_BASE + 0x5820)
72
73/* Scratch Pad registers*/
74#define SCR_PAD0 (REGISTERS_BASE + 0x5608)
75#define SCR_PAD1 (REGISTERS_BASE + 0x560C)
76#define SCR_PAD2 (REGISTERS_BASE + 0x5610)
77#define SCR_PAD3 (REGISTERS_BASE + 0x5614)
78#define SCR_PAD4 (REGISTERS_BASE + 0x5618)
79#define SCR_PAD4_SET (REGISTERS_BASE + 0x561C)
80#define SCR_PAD4_CLR (REGISTERS_BASE + 0x5620)
81#define SCR_PAD5 (REGISTERS_BASE + 0x5624)
82#define SCR_PAD5_SET (REGISTERS_BASE + 0x5628)
83#define SCR_PAD5_CLR (REGISTERS_BASE + 0x562C)
84#define SCR_PAD6 (REGISTERS_BASE + 0x5630)
85#define SCR_PAD7 (REGISTERS_BASE + 0x5634)
86#define SCR_PAD8 (REGISTERS_BASE + 0x5638)
87#define SCR_PAD9 (REGISTERS_BASE + 0x563C)
88
89/* Spare registers*/
90#define SPARE_A1 (REGISTERS_BASE + 0x0994)
91#define SPARE_A2 (REGISTERS_BASE + 0x0998)
92#define SPARE_A3 (REGISTERS_BASE + 0x099C)
93#define SPARE_A4 (REGISTERS_BASE + 0x09A0)
94#define SPARE_A5 (REGISTERS_BASE + 0x09A4)
95#define SPARE_A6 (REGISTERS_BASE + 0x09A8)
96#define SPARE_A7 (REGISTERS_BASE + 0x09AC)
97#define SPARE_A8 (REGISTERS_BASE + 0x09B0)
98#define SPARE_B1 (REGISTERS_BASE + 0x5420)
99#define SPARE_B2 (REGISTERS_BASE + 0x5424)
100#define SPARE_B3 (REGISTERS_BASE + 0x5428)
101#define SPARE_B4 (REGISTERS_BASE + 0x542C)
102#define SPARE_B5 (REGISTERS_BASE + 0x5430)
103#define SPARE_B6 (REGISTERS_BASE + 0x5434)
104#define SPARE_B7 (REGISTERS_BASE + 0x5438)
105#define SPARE_B8 (REGISTERS_BASE + 0x543C)
106
107enum wl12xx_acx_int_reg {
108 ACX_REG_INTERRUPT_TRIG,
109 ACX_REG_INTERRUPT_TRIG_H,
110
111/*=============================================
112 Host Interrupt Mask Register - 32bit (RW)
113 ------------------------------------------
114 Setting a bit in this register masks the
115 corresponding interrupt to the host.
116 0 - RX0 - Rx first dubble buffer Data Interrupt
117 1 - TXD - Tx Data Interrupt
118 2 - TXXFR - Tx Transfer Interrupt
119 3 - RX1 - Rx second dubble buffer Data Interrupt
120 4 - RXXFR - Rx Transfer Interrupt
121 5 - EVENT_A - Event Mailbox interrupt
122 6 - EVENT_B - Event Mailbox interrupt
123 7 - WNONHST - Wake On Host Interrupt
124 8 - TRACE_A - Debug Trace interrupt
125 9 - TRACE_B - Debug Trace interrupt
126 10 - CDCMP - Command Complete Interrupt
127 11 -
128 12 -
129 13 -
130 14 - ICOMP - Initialization Complete Interrupt
131 16 - SG SE - Soft Gemini - Sense enable interrupt
132 17 - SG SD - Soft Gemini - Sense disable interrupt
133 18 - -
134 19 - -
135 20 - -
136 21- -
137 Default: 0x0001
138*==============================================*/
139 ACX_REG_INTERRUPT_MASK,
140
141/*=============================================
142 Host Interrupt Mask Set 16bit, (Write only)
143 ------------------------------------------
144 Setting a bit in this register sets
145 the corresponding bin in ACX_HINT_MASK register
146 without effecting the mask
147 state of other bits (0 = no effect).
148==============================================*/
149 ACX_REG_HINT_MASK_SET,
150
151/*=============================================
152 Host Interrupt Mask Clear 16bit,(Write only)
153 ------------------------------------------
154 Setting a bit in this register clears
155 the corresponding bin in ACX_HINT_MASK register
156 without effecting the mask
157 state of other bits (0 = no effect).
158=============================================*/
159 ACX_REG_HINT_MASK_CLR,
160
161/*=============================================
162 Host Interrupt Status Nondestructive Read
163 16bit,(Read only)
164 ------------------------------------------
165 The host can read this register to determine
166 which interrupts are active.
167 Reading this register doesn't
168 effect its content.
169=============================================*/
170 ACX_REG_INTERRUPT_NO_CLEAR,
171
172/*=============================================
173 Host Interrupt Status Clear on Read Register
174 16bit,(Read only)
175 ------------------------------------------
176 The host can read this register to determine
177 which interrupts are active.
178 Reading this register clears it,
179 thus making all interrupts inactive.
180==============================================*/
181 ACX_REG_INTERRUPT_CLEAR,
182
183/*=============================================
184 Host Interrupt Acknowledge Register
185 16bit,(Write only)
186 ------------------------------------------
187 The host can set individual bits in this
188 register to clear (acknowledge) the corresp.
189 interrupt status bits in the HINT_STS_CLR and
190 HINT_STS_ND registers, thus making the
191 assotiated interrupt inactive. (0-no effect)
192==============================================*/
193 ACX_REG_INTERRUPT_ACK,
194
195/*===============================================
196 Host Software Reset - 32bit RW
197 ------------------------------------------
198 [31:1] Reserved
199 0 SOFT_RESET Soft Reset - When this bit is set,
200 it holds the Wlan hardware in a soft reset state.
201 This reset disables all MAC and baseband processor
202 clocks except the CardBus/PCI interface clock.
203 It also initializes all MAC state machines except
204 the host interface. It does not reload the
205 contents of the EEPROM. When this bit is cleared
206 (not self-clearing), the Wlan hardware
207 exits the software reset state.
208===============================================*/
209 ACX_REG_SLV_SOFT_RESET,
210
211/*===============================================
212 EEPROM Burst Read Start - 32bit RW
213 ------------------------------------------
214 [31:1] Reserved
215 0 ACX_EE_START - EEPROM Burst Read Start 0
216 Setting this bit starts a burst read from
217 the external EEPROM.
218 If this bit is set (after reset) before an EEPROM read/write,
219 the burst read starts at EEPROM address 0.
220 Otherwise, it starts at the address
221 following the address of the previous access.
222 TheWlan hardware hardware clears this bit automatically.
223
224 Default: 0x00000000
225*================================================*/
226 ACX_REG_EE_START,
227
228/* Embedded ARM CPU Control */
229
230/*===============================================
231 Halt eCPU - 32bit RW
232 ------------------------------------------
233 0 HALT_ECPU Halt Embedded CPU - This bit is the
234 compliment of bit 1 (MDATA2) in the SOR_CFG register.
235 During a hardware reset, this bit holds
236 the inverse of MDATA2.
237 When downloading firmware from the host,
238 set this bit (pull down MDATA2).
239 The host clears this bit after downloading the firmware into
240 zero-wait-state SSRAM.
241 When loading firmware from Flash, clear this bit (pull up MDATA2)
242 so that the eCPU can run the bootloader code in Flash
243 HALT_ECPU eCPU State
244 --------------------
245 1 halt eCPU
246 0 enable eCPU
247 ===============================================*/
248 ACX_REG_ECPU_CONTROL,
249
250 ACX_REG_TABLE_LEN
251};
252
253#define ACX_SLV_SOFT_RESET_BIT BIT(0)
254#define ACX_REG_EEPROM_START_BIT BIT(0)
255
256/* Command/Information Mailbox Pointers */
257
258/*===============================================
259 Command Mailbox Pointer - 32bit RW
260 ------------------------------------------
261 This register holds the start address of
262 the command mailbox located in the Wlan hardware memory.
263 The host must read this pointer after a reset to
264 find the location of the command mailbox.
265 The Wlan hardware initializes the command mailbox
266 pointer with the default address of the command mailbox.
267 The command mailbox pointer is not valid until after
268 the host receives the Init Complete interrupt from
269 the Wlan hardware.
270 ===============================================*/
271#define REG_COMMAND_MAILBOX_PTR (SCR_PAD0)
272
273/*===============================================
274 Information Mailbox Pointer - 32bit RW
275 ------------------------------------------
276 This register holds the start address of
277 the information mailbox located in the Wlan hardware memory.
278 The host must read this pointer after a reset to find
279 the location of the information mailbox.
280 The Wlan hardware initializes the information mailbox pointer
281 with the default address of the information mailbox.
282 The information mailbox pointer is not valid
283 until after the host receives the Init Complete interrupt from
284 the Wlan hardware.
285 ===============================================*/
286#define REG_EVENT_MAILBOX_PTR (SCR_PAD1)
287
288
289/* Misc */
290
291#define REG_ENABLE_TX_RX (ENABLE)
292/*
293 * Rx configuration (filter) information element
294 * ---------------------------------------------
295 */
296#define REG_RX_CONFIG (RX_CFG)
297#define REG_RX_FILTER (RX_FILTER_CFG)
298
299
300#define RX_CFG_ENABLE_PHY_HEADER_PLCP 0x0002
301
302/* promiscuous - receives all valid frames */
303#define RX_CFG_PROMISCUOUS 0x0008
304
305/* receives frames from any BSSID */
306#define RX_CFG_BSSID 0x0020
307
308/* receives frames destined to any MAC address */
309#define RX_CFG_MAC 0x0010
310
311#define RX_CFG_ENABLE_ONLY_MY_DEST_MAC 0x0010
312#define RX_CFG_ENABLE_ANY_DEST_MAC 0x0000
313#define RX_CFG_ENABLE_ONLY_MY_BSSID 0x0020
314#define RX_CFG_ENABLE_ANY_BSSID 0x0000
315
316/* discards all broadcast frames */
317#define RX_CFG_DISABLE_BCAST 0x0200
318
319#define RX_CFG_ENABLE_ONLY_MY_SSID 0x0400
320#define RX_CFG_ENABLE_RX_CMPLT_FCS_ERROR 0x0800
321#define RX_CFG_COPY_RX_STATUS 0x2000
322#define RX_CFG_TSF 0x10000
323
324#define RX_CONFIG_OPTION_ANY_DST_MY_BSS (RX_CFG_ENABLE_ANY_DEST_MAC | \
325 RX_CFG_ENABLE_ONLY_MY_BSSID)
326
327#define RX_CONFIG_OPTION_MY_DST_ANY_BSS (RX_CFG_ENABLE_ONLY_MY_DEST_MAC\
328 | RX_CFG_ENABLE_ANY_BSSID)
329
330#define RX_CONFIG_OPTION_ANY_DST_ANY_BSS (RX_CFG_ENABLE_ANY_DEST_MAC | \
331 RX_CFG_ENABLE_ANY_BSSID)
332
333#define RX_CONFIG_OPTION_MY_DST_MY_BSS (RX_CFG_ENABLE_ONLY_MY_DEST_MAC\
334 | RX_CFG_ENABLE_ONLY_MY_BSSID)
335
336#define RX_CONFIG_OPTION_FOR_SCAN (RX_CFG_ENABLE_PHY_HEADER_PLCP \
337 | RX_CFG_ENABLE_RX_CMPLT_FCS_ERROR \
338 | RX_CFG_COPY_RX_STATUS | RX_CFG_TSF)
339
340#define RX_CONFIG_OPTION_FOR_MEASUREMENT (RX_CFG_ENABLE_ANY_DEST_MAC)
341
342#define RX_CONFIG_OPTION_FOR_JOIN (RX_CFG_ENABLE_ONLY_MY_BSSID | \
343 RX_CFG_ENABLE_ONLY_MY_DEST_MAC)
344
345#define RX_CONFIG_OPTION_FOR_IBSS_JOIN (RX_CFG_ENABLE_ONLY_MY_SSID | \
346 RX_CFG_ENABLE_ONLY_MY_DEST_MAC)
347
348#define RX_FILTER_OPTION_DEF (CFG_RX_MGMT_EN | CFG_RX_DATA_EN\
349 | CFG_RX_CTL_EN | CFG_RX_BCN_EN\
350 | CFG_RX_AUTH_EN | CFG_RX_ASSOC_EN)
351
352#define RX_FILTER_OPTION_FILTER_ALL 0
353
354#define RX_FILTER_OPTION_DEF_PRSP_BCN (CFG_RX_PRSP_EN | CFG_RX_MGMT_EN\
355 | CFG_RX_RCTS_ACK | CFG_RX_BCN_EN)
356
357#define RX_FILTER_OPTION_JOIN (CFG_RX_MGMT_EN | CFG_RX_DATA_EN\
358 | CFG_RX_BCN_EN | CFG_RX_AUTH_EN\
359 | CFG_RX_ASSOC_EN | CFG_RX_RCTS_ACK\
360 | CFG_RX_PRSP_EN)
361
362
363/*===============================================
364 EEPROM Read/Write Request 32bit RW
365 ------------------------------------------
366 1 EE_READ - EEPROM Read Request 1 - Setting this bit
367 loads a single byte of data into the EE_DATA
368 register from the EEPROM location specified in
369 the EE_ADDR register.
370 The Wlan hardware hardware clears this bit automatically.
371 EE_DATA is valid when this bit is cleared.
372
373 0 EE_WRITE - EEPROM Write Request - Setting this bit
374 writes a single byte of data from the EE_DATA register into the
375 EEPROM location specified in the EE_ADDR register.
376 The Wlan hardware hardware clears this bit automatically.
377*===============================================*/
378#define EE_CTL (REGISTERS_BASE + 0x2000)
379#define ACX_EE_CTL_REG EE_CTL
380#define EE_WRITE 0x00000001ul
381#define EE_READ 0x00000002ul
382
383/*===============================================
384 EEPROM Address - 32bit RW
385 ------------------------------------------
386 This register specifies the address
387 within the EEPROM from/to which to read/write data.
388 ===============================================*/
389#define EE_ADDR (REGISTERS_BASE + 0x2008)
390#define ACX_EE_ADDR_REG EE_ADDR
391
392/*===============================================
393 EEPROM Data - 32bit RW
394 ------------------------------------------
395 This register either holds the read 8 bits of
396 data from the EEPROM or the write data
397 to be written to the EEPROM.
398 ===============================================*/
399#define EE_DATA (REGISTERS_BASE + 0x2004)
400#define ACX_EE_DATA_REG EE_DATA
401
402#define EEPROM_ACCESS_TO 10000 /* timeout counter */
403#define START_EEPROM_MGR 0x00000001
404
405/*===============================================
406 EEPROM Base Address - 32bit RW
407 ------------------------------------------
408 This register holds the upper nine bits
409 [23:15] of the 24-bit Wlan hardware memory
410 address for burst reads from EEPROM accesses.
411 The EEPROM provides the lower 15 bits of this address.
412 The MSB of the address from the EEPROM is ignored.
413 ===============================================*/
414#define ACX_EE_CFG EE_CFG
415
416/*===============================================
417 GPIO Output Values -32bit, RW
418 ------------------------------------------
419 [31:16] Reserved
420 [15: 0] Specify the output values (at the output driver inputs) for
421 GPIO[15:0], respectively.
422 ===============================================*/
423#define ACX_GPIO_OUT_REG GPIO_OUT
424#define ACX_MAX_GPIO_LINES 15
425
426/*===============================================
427 Contention window -32bit, RW
428 ------------------------------------------
429 [31:26] Reserved
430 [25:16] Max (0x3ff)
431 [15:07] Reserved
432 [06:00] Current contention window value - default is 0x1F
433 ===============================================*/
434#define ACX_CONT_WIND_CFG_REG CONT_WIND_CFG
435#define ACX_CONT_WIND_MIN_MASK 0x0000007f
436#define ACX_CONT_WIND_MAX 0x03ff0000
437
438/*===============================================
439 HI_CFG Interface Configuration Register Values
440 ------------------------------------------
441 ===============================================*/
442#define HI_CFG_UART_ENABLE 0x00000004
443#define HI_CFG_RST232_ENABLE 0x00000008
444#define HI_CFG_CLOCK_REQ_SELECT 0x00000010
445#define HI_CFG_HOST_INT_ENABLE 0x00000020
446#define HI_CFG_VLYNQ_OUTPUT_ENABLE 0x00000040
447#define HI_CFG_HOST_INT_ACTIVE_LOW 0x00000080
448#define HI_CFG_UART_TX_OUT_GPIO_15 0x00000100
449#define HI_CFG_UART_TX_OUT_GPIO_14 0x00000200
450#define HI_CFG_UART_TX_OUT_GPIO_7 0x00000400
451
452/*
453 * NOTE: USE_ACTIVE_HIGH compilation flag should be defined in makefile
454 * for platforms using active high interrupt level
455 */
456#ifdef USE_ACTIVE_HIGH
457#define HI_CFG_DEF_VAL \
458 (HI_CFG_UART_ENABLE | \
459 HI_CFG_RST232_ENABLE | \
460 HI_CFG_CLOCK_REQ_SELECT | \
461 HI_CFG_HOST_INT_ENABLE)
462#else
463#define HI_CFG_DEF_VAL \
464 (HI_CFG_UART_ENABLE | \
465 HI_CFG_RST232_ENABLE | \
466 HI_CFG_CLOCK_REQ_SELECT | \
467 HI_CFG_HOST_INT_ENABLE)
468
469#endif
470
471#define REF_FREQ_19_2 0
472#define REF_FREQ_26_0 1
473#define REF_FREQ_38_4 2
474#define REF_FREQ_40_0 3
475#define REF_FREQ_33_6 4
476#define REF_FREQ_NUM 5
477
478#define LUT_PARAM_INTEGER_DIVIDER 0
479#define LUT_PARAM_FRACTIONAL_DIVIDER 1
480#define LUT_PARAM_ATTN_BB 2
481#define LUT_PARAM_ALPHA_BB 3
482#define LUT_PARAM_STOP_TIME_BB 4
483#define LUT_PARAM_BB_PLL_LOOP_FILTER 5
484#define LUT_PARAM_NUM 6
485
486#define ACX_EEPROMLESS_IND_REG (SCR_PAD4)
487#define USE_EEPROM 0
488#define SOFT_RESET_MAX_TIME 1000000
489#define SOFT_RESET_STALL_TIME 1000
490#define NVS_DATA_BUNDARY_ALIGNMENT 4
491
492
493/* Firmware image load chunk size */
494#define CHUNK_SIZE 512
495
496/* Firmware image header size */
497#define FW_HDR_SIZE 8
498
499#define ECPU_CONTROL_HALT 0x00000101
500
501
502/******************************************************************************
503
504 CHANNELS, BAND & REG DOMAINS definitions
505
506******************************************************************************/
507
508
509enum {
510 RADIO_BAND_2_4GHZ = 0, /* 2.4 Ghz band */
511 RADIO_BAND_5GHZ = 1, /* 5 Ghz band */
512 RADIO_BAND_JAPAN_4_9_GHZ = 2,
513 DEFAULT_BAND = RADIO_BAND_2_4GHZ,
514 INVALID_BAND = 0xFE,
515 MAX_RADIO_BANDS = 0xFF
516};
517
518enum {
519 NO_RATE = 0,
520 RATE_1MBPS = 0x0A,
521 RATE_2MBPS = 0x14,
522 RATE_5_5MBPS = 0x37,
523 RATE_6MBPS = 0x0B,
524 RATE_9MBPS = 0x0F,
525 RATE_11MBPS = 0x6E,
526 RATE_12MBPS = 0x0A,
527 RATE_18MBPS = 0x0E,
528 RATE_22MBPS = 0xDC,
529 RATE_24MBPS = 0x09,
530 RATE_36MBPS = 0x0D,
531 RATE_48MBPS = 0x08,
532 RATE_54MBPS = 0x0C
533};
534
535enum {
536 RATE_INDEX_1MBPS = 0,
537 RATE_INDEX_2MBPS = 1,
538 RATE_INDEX_5_5MBPS = 2,
539 RATE_INDEX_6MBPS = 3,
540 RATE_INDEX_9MBPS = 4,
541 RATE_INDEX_11MBPS = 5,
542 RATE_INDEX_12MBPS = 6,
543 RATE_INDEX_18MBPS = 7,
544 RATE_INDEX_22MBPS = 8,
545 RATE_INDEX_24MBPS = 9,
546 RATE_INDEX_36MBPS = 10,
547 RATE_INDEX_48MBPS = 11,
548 RATE_INDEX_54MBPS = 12,
549 RATE_INDEX_MAX = RATE_INDEX_54MBPS,
550 MAX_RATE_INDEX,
551 INVALID_RATE_INDEX = MAX_RATE_INDEX,
552 RATE_INDEX_ENUM_MAX_SIZE = 0x7FFFFFFF
553};
554
555enum {
556 RATE_MASK_1MBPS = 0x1,
557 RATE_MASK_2MBPS = 0x2,
558 RATE_MASK_5_5MBPS = 0x4,
559 RATE_MASK_11MBPS = 0x20,
560};
561
562#define SHORT_PREAMBLE_BIT BIT(0) /* CCK or Barker depending on the rate */
563#define OFDM_RATE_BIT BIT(6)
564#define PBCC_RATE_BIT BIT(7)
565
566enum {
567 CCK_LONG = 0,
568 CCK_SHORT = SHORT_PREAMBLE_BIT,
569 PBCC_LONG = PBCC_RATE_BIT,
570 PBCC_SHORT = PBCC_RATE_BIT | SHORT_PREAMBLE_BIT,
571 OFDM = OFDM_RATE_BIT
572};
573
574/******************************************************************************
575
576Transmit-Descriptor RATE-SET field definitions...
577
578Define a new "Rate-Set" for TX path that incorporates the
579Rate & Modulation info into a single 16-bit field.
580
581TxdRateSet_t:
582b15 - Indicates Preamble type (1=SHORT, 0=LONG).
583 Notes:
584 Must be LONG (0) for 1Mbps rate.
585 Does not apply (set to 0) for RevG-OFDM rates.
586b14 - Indicates PBCC encoding (1=PBCC, 0=not).
587 Notes:
588 Does not apply (set to 0) for rates 1 and 2 Mbps.
589 Does not apply (set to 0) for RevG-OFDM rates.
590b13 - Unused (set to 0).
591b12-b0 - Supported Rate indicator bits as defined below.
592
593******************************************************************************/
594
595
596/*************************************************************************
597
598 Interrupt Trigger Register (Host -> WiLink)
599
600**************************************************************************/
601
602/* Hardware to Embedded CPU Interrupts - first 32-bit register set */
603
604/*
605 * Host Command Interrupt. Setting this bit masks
606 * the interrupt that the host issues to inform
607 * the FW that it has sent a command
608 * to the Wlan hardware Command Mailbox.
609 */
610#define INTR_TRIG_CMD BIT(0)
611
612/*
613 * Host Event Acknowlegde Interrupt. The host
614 * sets this bit to acknowledge that it received
615 * the unsolicited information from the event
616 * mailbox.
617 */
618#define INTR_TRIG_EVENT_ACK BIT(1)
619
620/*
621 * The host sets this bit to inform the Wlan
622 * FW that a TX packet is in the XFER
623 * Buffer #0.
624 */
625#define INTR_TRIG_TX_PROC0 BIT(2)
626
627/*
628 * The host sets this bit to inform the FW
629 * that it read a packet from RX XFER
630 * Buffer #0.
631 */
632#define INTR_TRIG_RX_PROC0 BIT(3)
633
634#define INTR_TRIG_DEBUG_ACK BIT(4)
635
636#define INTR_TRIG_STATE_CHANGED BIT(5)
637
638
639/* Hardware to Embedded CPU Interrupts - second 32-bit register set */
640
641/*
642 * The host sets this bit to inform the FW
643 * that it read a packet from RX XFER
644 * Buffer #1.
645 */
646#define INTR_TRIG_RX_PROC1 BIT(17)
647
648/*
649 * The host sets this bit to inform the Wlan
650 * hardware that a TX packet is in the XFER
651 * Buffer #1.
652 */
653#define INTR_TRIG_TX_PROC1 BIT(18)
654
655#endif
diff --git a/drivers/net/wireless/ti/wl1251/rx.c b/drivers/net/wireless/ti/wl1251/rx.c
new file mode 100644
index 000000000000..6af35265c900
--- /dev/null
+++ b/drivers/net/wireless/ti/wl1251/rx.c
@@ -0,0 +1,235 @@
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 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22
23#include <linux/skbuff.h>
24#include <linux/gfp.h>
25#include <net/mac80211.h>
26
27#include "wl1251.h"
28#include "reg.h"
29#include "io.h"
30#include "rx.h"
31#include "cmd.h"
32#include "acx.h"
33
34static void wl1251_rx_header(struct wl1251 *wl,
35 struct wl1251_rx_descriptor *desc)
36{
37 u32 rx_packet_ring_addr;
38
39 rx_packet_ring_addr = wl->data_path->rx_packet_ring_addr;
40 if (wl->rx_current_buffer)
41 rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size;
42
43 wl1251_mem_read(wl, rx_packet_ring_addr, desc, sizeof(*desc));
44}
45
46static void wl1251_rx_status(struct wl1251 *wl,
47 struct wl1251_rx_descriptor *desc,
48 struct ieee80211_rx_status *status,
49 u8 beacon)
50{
51 u64 mactime;
52 int ret;
53
54 memset(status, 0, sizeof(struct ieee80211_rx_status));
55
56 status->band = IEEE80211_BAND_2GHZ;
57 status->mactime = desc->timestamp;
58
59 /*
60 * The rx status timestamp is a 32 bits value while the TSF is a
61 * 64 bits one.
62 * For IBSS merging, TSF is mandatory, so we have to get it
63 * somehow, so we ask for ACX_TSF_INFO.
64 * That could be moved to the get_tsf() hook, but unfortunately,
65 * this one must be atomic, while our SPI routines can sleep.
66 */
67 if ((wl->bss_type == BSS_TYPE_IBSS) && beacon) {
68 ret = wl1251_acx_tsf_info(wl, &mactime);
69 if (ret == 0)
70 status->mactime = mactime;
71 }
72
73 status->signal = desc->rssi;
74
75 /*
76 * FIXME: guessing that snr needs to be divided by two, otherwise
77 * the values don't make any sense
78 */
79 wl->noise = desc->rssi - desc->snr / 2;
80
81 status->freq = ieee80211_channel_to_frequency(desc->channel,
82 status->band);
83
84 status->flag |= RX_FLAG_MACTIME_MPDU;
85
86 if (desc->flags & RX_DESC_ENCRYPTION_MASK) {
87 status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED;
88
89 if (likely(!(desc->flags & RX_DESC_DECRYPT_FAIL)))
90 status->flag |= RX_FLAG_DECRYPTED;
91
92 if (unlikely(desc->flags & RX_DESC_MIC_FAIL))
93 status->flag |= RX_FLAG_MMIC_ERROR;
94 }
95
96 if (unlikely(!(desc->flags & RX_DESC_VALID_FCS)))
97 status->flag |= RX_FLAG_FAILED_FCS_CRC;
98
99 switch (desc->rate) {
100 /* skip 1 and 12 Mbps because they have same value 0x0a */
101 case RATE_2MBPS:
102 status->rate_idx = 1;
103 break;
104 case RATE_5_5MBPS:
105 status->rate_idx = 2;
106 break;
107 case RATE_11MBPS:
108 status->rate_idx = 3;
109 break;
110 case RATE_6MBPS:
111 status->rate_idx = 4;
112 break;
113 case RATE_9MBPS:
114 status->rate_idx = 5;
115 break;
116 case RATE_18MBPS:
117 status->rate_idx = 7;
118 break;
119 case RATE_24MBPS:
120 status->rate_idx = 8;
121 break;
122 case RATE_36MBPS:
123 status->rate_idx = 9;
124 break;
125 case RATE_48MBPS:
126 status->rate_idx = 10;
127 break;
128 case RATE_54MBPS:
129 status->rate_idx = 11;
130 break;
131 }
132
133 /* for 1 and 12 Mbps we have to check the modulation */
134 if (desc->rate == RATE_1MBPS) {
135 if (!(desc->mod_pre & OFDM_RATE_BIT))
136 /* CCK -> RATE_1MBPS */
137 status->rate_idx = 0;
138 else
139 /* OFDM -> RATE_12MBPS */
140 status->rate_idx = 6;
141 }
142
143 if (desc->mod_pre & SHORT_PREAMBLE_BIT)
144 status->flag |= RX_FLAG_SHORTPRE;
145}
146
147static void wl1251_rx_body(struct wl1251 *wl,
148 struct wl1251_rx_descriptor *desc)
149{
150 struct sk_buff *skb;
151 struct ieee80211_rx_status status;
152 u8 *rx_buffer, beacon = 0;
153 u16 length, *fc;
154 u32 curr_id, last_id_inc, rx_packet_ring_addr;
155
156 length = WL1251_RX_ALIGN(desc->length - PLCP_HEADER_LENGTH);
157 curr_id = (desc->flags & RX_DESC_SEQNUM_MASK) >> RX_DESC_PACKETID_SHIFT;
158 last_id_inc = (wl->rx_last_id + 1) % (RX_MAX_PACKET_ID + 1);
159
160 if (last_id_inc != curr_id) {
161 wl1251_warning("curr ID:%d, last ID inc:%d",
162 curr_id, last_id_inc);
163 wl->rx_last_id = curr_id;
164 } else {
165 wl->rx_last_id = last_id_inc;
166 }
167
168 rx_packet_ring_addr = wl->data_path->rx_packet_ring_addr +
169 sizeof(struct wl1251_rx_descriptor) + 20;
170 if (wl->rx_current_buffer)
171 rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size;
172
173 skb = __dev_alloc_skb(length, GFP_KERNEL);
174 if (!skb) {
175 wl1251_error("Couldn't allocate RX frame");
176 return;
177 }
178
179 rx_buffer = skb_put(skb, length);
180 wl1251_mem_read(wl, rx_packet_ring_addr, rx_buffer, length);
181
182 /* The actual length doesn't include the target's alignment */
183 skb->len = desc->length - PLCP_HEADER_LENGTH;
184
185 fc = (u16 *)skb->data;
186
187 if ((*fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON)
188 beacon = 1;
189
190 wl1251_rx_status(wl, desc, &status, beacon);
191
192 wl1251_debug(DEBUG_RX, "rx skb 0x%p: %d B %s", skb, skb->len,
193 beacon ? "beacon" : "");
194
195 memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
196 ieee80211_rx_ni(wl->hw, skb);
197}
198
199static void wl1251_rx_ack(struct wl1251 *wl)
200{
201 u32 data, addr;
202
203 if (wl->rx_current_buffer) {
204 addr = ACX_REG_INTERRUPT_TRIG_H;
205 data = INTR_TRIG_RX_PROC1;
206 } else {
207 addr = ACX_REG_INTERRUPT_TRIG;
208 data = INTR_TRIG_RX_PROC0;
209 }
210
211 wl1251_reg_write32(wl, addr, data);
212
213 /* Toggle buffer ring */
214 wl->rx_current_buffer = !wl->rx_current_buffer;
215}
216
217
218void wl1251_rx(struct wl1251 *wl)
219{
220 struct wl1251_rx_descriptor *rx_desc;
221
222 if (wl->state != WL1251_STATE_ON)
223 return;
224
225 rx_desc = wl->rx_descriptor;
226
227 /* We first read the frame's header */
228 wl1251_rx_header(wl, rx_desc);
229
230 /* Now we can read the body */
231 wl1251_rx_body(wl, rx_desc);
232
233 /* Finally, we need to ACK the RX */
234 wl1251_rx_ack(wl);
235}
diff --git a/drivers/net/wireless/ti/wl1251/rx.h b/drivers/net/wireless/ti/wl1251/rx.h
new file mode 100644
index 000000000000..4448f635a4d8
--- /dev/null
+++ b/drivers/net/wireless/ti/wl1251/rx.h
@@ -0,0 +1,122 @@
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 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22
23#ifndef __WL1251_RX_H__
24#define __WL1251_RX_H__
25
26#include <linux/bitops.h>
27
28#include "wl1251.h"
29
30/*
31 * RX PATH
32 *
33 * The Rx path uses a double buffer and an rx_contro structure, each located
34 * at a fixed address in the device memory. The host keeps track of which
35 * buffer is available and alternates between them on a per packet basis.
36 * The size of each of the two buffers is large enough to hold the longest
37 * 802.3 packet.
38 * The RX path goes like that:
39 * 1) The target generates an interrupt each time a new packet is received.
40 * There are 2 RX interrupts, one for each buffer.
41 * 2) The host reads the received packet from one of the double buffers.
42 * 3) The host triggers a target interrupt.
43 * 4) The target prepares the next RX packet.
44 */
45
46#define WL1251_RX_MAX_RSSI -30
47#define WL1251_RX_MIN_RSSI -95
48
49#define WL1251_RX_ALIGN_TO 4
50#define WL1251_RX_ALIGN(len) (((len) + WL1251_RX_ALIGN_TO - 1) & \
51 ~(WL1251_RX_ALIGN_TO - 1))
52
53#define SHORT_PREAMBLE_BIT BIT(0)
54#define OFDM_RATE_BIT BIT(6)
55#define PBCC_RATE_BIT BIT(7)
56
57#define PLCP_HEADER_LENGTH 8
58#define RX_DESC_PACKETID_SHIFT 11
59#define RX_MAX_PACKET_ID 3
60
61#define RX_DESC_VALID_FCS 0x0001
62#define RX_DESC_MATCH_RXADDR1 0x0002
63#define RX_DESC_MCAST 0x0004
64#define RX_DESC_STAINTIM 0x0008
65#define RX_DESC_VIRTUAL_BM 0x0010
66#define RX_DESC_BCAST 0x0020
67#define RX_DESC_MATCH_SSID 0x0040
68#define RX_DESC_MATCH_BSSID 0x0080
69#define RX_DESC_ENCRYPTION_MASK 0x0300
70#define RX_DESC_MEASURMENT 0x0400
71#define RX_DESC_SEQNUM_MASK 0x1800
72#define RX_DESC_MIC_FAIL 0x2000
73#define RX_DESC_DECRYPT_FAIL 0x4000
74
75struct wl1251_rx_descriptor {
76 u32 timestamp; /* In microseconds */
77 u16 length; /* Paylod length, including headers */
78 u16 flags;
79
80 /*
81 * 0 - 802.11
82 * 1 - 802.3
83 * 2 - IP
84 * 3 - Raw Codec
85 */
86 u8 type;
87
88 /*
89 * Received Rate:
90 * 0x0A - 1MBPS
91 * 0x14 - 2MBPS
92 * 0x37 - 5_5MBPS
93 * 0x0B - 6MBPS
94 * 0x0F - 9MBPS
95 * 0x6E - 11MBPS
96 * 0x0A - 12MBPS
97 * 0x0E - 18MBPS
98 * 0xDC - 22MBPS
99 * 0x09 - 24MBPS
100 * 0x0D - 36MBPS
101 * 0x08 - 48MBPS
102 * 0x0C - 54MBPS
103 */
104 u8 rate;
105
106 u8 mod_pre; /* Modulation and preamble */
107 u8 channel;
108
109 /*
110 * 0 - 2.4 Ghz
111 * 1 - 5 Ghz
112 */
113 u8 band;
114
115 s8 rssi; /* in dB */
116 u8 rcpi; /* in dB */
117 u8 snr; /* in dB */
118} __packed;
119
120void wl1251_rx(struct wl1251 *wl);
121
122#endif
diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
new file mode 100644
index 000000000000..f78694295c39
--- /dev/null
+++ b/drivers/net/wireless/ti/wl1251/sdio.c
@@ -0,0 +1,374 @@
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/interrupt.h>
23#include <linux/module.h>
24#include <linux/mod_devicetable.h>
25#include <linux/mmc/sdio_func.h>
26#include <linux/mmc/sdio_ids.h>
27#include <linux/platform_device.h>
28#include <linux/wl12xx.h>
29#include <linux/irq.h>
30#include <linux/pm_runtime.h>
31
32#include "wl1251.h"
33
34#ifndef SDIO_VENDOR_ID_TI
35#define SDIO_VENDOR_ID_TI 0x104c
36#endif
37
38#ifndef SDIO_DEVICE_ID_TI_WL1251
39#define SDIO_DEVICE_ID_TI_WL1251 0x9066
40#endif
41
42struct wl1251_sdio {
43 struct sdio_func *func;
44 u32 elp_val;
45};
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 int wl1251_sdio_set_power(struct wl1251 *wl, bool enable)
175{
176 struct sdio_func *func = wl_to_func(wl);
177 int ret;
178
179 if (enable) {
180 /*
181 * Power is controlled by runtime PM, but we still call board
182 * callback in case it wants to do any additional setup,
183 * for example enabling clock buffer for the module.
184 */
185 if (wl->set_power)
186 wl->set_power(true);
187
188 ret = pm_runtime_get_sync(&func->dev);
189 if (ret < 0)
190 goto out;
191
192 sdio_claim_host(func);
193 sdio_enable_func(func);
194 sdio_release_host(func);
195 } else {
196 sdio_claim_host(func);
197 sdio_disable_func(func);
198 sdio_release_host(func);
199
200 ret = pm_runtime_put_sync(&func->dev);
201 if (ret < 0)
202 goto out;
203
204 if (wl->set_power)
205 wl->set_power(false);
206 }
207
208out:
209 return ret;
210}
211
212static struct wl1251_if_operations wl1251_sdio_ops = {
213 .read = wl1251_sdio_read,
214 .write = wl1251_sdio_write,
215 .write_elp = wl1251_sdio_write_elp,
216 .read_elp = wl1251_sdio_read_elp,
217 .reset = wl1251_sdio_reset,
218 .power = wl1251_sdio_set_power,
219};
220
221static int wl1251_sdio_probe(struct sdio_func *func,
222 const struct sdio_device_id *id)
223{
224 int ret;
225 struct wl1251 *wl;
226 struct ieee80211_hw *hw;
227 struct wl1251_sdio *wl_sdio;
228 const struct wl12xx_platform_data *wl12xx_board_data;
229
230 hw = wl1251_alloc_hw();
231 if (IS_ERR(hw))
232 return PTR_ERR(hw);
233
234 wl = hw->priv;
235
236 wl_sdio = kzalloc(sizeof(*wl_sdio), GFP_KERNEL);
237 if (wl_sdio == NULL) {
238 ret = -ENOMEM;
239 goto out_free_hw;
240 }
241
242 sdio_claim_host(func);
243 ret = sdio_enable_func(func);
244 if (ret)
245 goto release;
246
247 sdio_set_block_size(func, 512);
248 sdio_release_host(func);
249
250 SET_IEEE80211_DEV(hw, &func->dev);
251 wl_sdio->func = func;
252 wl->if_priv = wl_sdio;
253 wl->if_ops = &wl1251_sdio_ops;
254
255 wl12xx_board_data = wl12xx_get_platform_data();
256 if (!IS_ERR(wl12xx_board_data)) {
257 wl->set_power = wl12xx_board_data->set_power;
258 wl->irq = wl12xx_board_data->irq;
259 wl->use_eeprom = wl12xx_board_data->use_eeprom;
260 }
261
262 if (wl->irq) {
263 ret = request_irq(wl->irq, wl1251_line_irq, 0, "wl1251", wl);
264 if (ret < 0) {
265 wl1251_error("request_irq() failed: %d", ret);
266 goto disable;
267 }
268
269 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
270 disable_irq(wl->irq);
271
272 wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
273 wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
274
275 wl1251_info("using dedicated interrupt line");
276 } else {
277 wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
278 wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
279
280 wl1251_info("using SDIO interrupt");
281 }
282
283 ret = wl1251_init_ieee80211(wl);
284 if (ret)
285 goto out_free_irq;
286
287 sdio_set_drvdata(func, wl);
288
289 /* Tell PM core that we don't need the card to be powered now */
290 pm_runtime_put_noidle(&func->dev);
291
292 return ret;
293
294out_free_irq:
295 if (wl->irq)
296 free_irq(wl->irq, wl);
297disable:
298 sdio_claim_host(func);
299 sdio_disable_func(func);
300release:
301 sdio_release_host(func);
302 kfree(wl_sdio);
303out_free_hw:
304 wl1251_free_hw(wl);
305 return ret;
306}
307
308static void __devexit wl1251_sdio_remove(struct sdio_func *func)
309{
310 struct wl1251 *wl = sdio_get_drvdata(func);
311 struct wl1251_sdio *wl_sdio = wl->if_priv;
312
313 /* Undo decrement done above in wl1251_probe */
314 pm_runtime_get_noresume(&func->dev);
315
316 if (wl->irq)
317 free_irq(wl->irq, wl);
318 kfree(wl_sdio);
319 wl1251_free_hw(wl);
320
321 sdio_claim_host(func);
322 sdio_release_irq(func);
323 sdio_disable_func(func);
324 sdio_release_host(func);
325}
326
327static int wl1251_suspend(struct device *dev)
328{
329 /*
330 * Tell MMC/SDIO core it's OK to power down the card
331 * (if it isn't already), but not to remove it completely.
332 */
333 return 0;
334}
335
336static int wl1251_resume(struct device *dev)
337{
338 return 0;
339}
340
341static const struct dev_pm_ops wl1251_sdio_pm_ops = {
342 .suspend = wl1251_suspend,
343 .resume = wl1251_resume,
344};
345
346static struct sdio_driver wl1251_sdio_driver = {
347 .name = "wl1251_sdio",
348 .id_table = wl1251_devices,
349 .probe = wl1251_sdio_probe,
350 .remove = __devexit_p(wl1251_sdio_remove),
351 .drv.pm = &wl1251_sdio_pm_ops,
352};
353
354static int __init wl1251_sdio_init(void)
355{
356 int err;
357
358 err = sdio_register_driver(&wl1251_sdio_driver);
359 if (err)
360 wl1251_error("failed to register sdio driver: %d", err);
361 return err;
362}
363
364static void __exit wl1251_sdio_exit(void)
365{
366 sdio_unregister_driver(&wl1251_sdio_driver);
367 wl1251_notice("unloaded");
368}
369
370module_init(wl1251_sdio_init);
371module_exit(wl1251_sdio_exit);
372
373MODULE_LICENSE("GPL");
374MODULE_AUTHOR("Kalle Valo <kvalo@adurom.com>");
diff --git a/drivers/net/wireless/ti/wl1251/spi.c b/drivers/net/wireless/ti/wl1251/spi.c
new file mode 100644
index 000000000000..6248c354fc5c
--- /dev/null
+++ b/drivers/net/wireless/ti/wl1251/spi.c
@@ -0,0 +1,355 @@
1/*
2 * This file is part of wl1251
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
22#include <linux/interrupt.h>
23#include <linux/irq.h>
24#include <linux/module.h>
25#include <linux/slab.h>
26#include <linux/crc7.h>
27#include <linux/spi/spi.h>
28#include <linux/wl12xx.h>
29
30#include "wl1251.h"
31#include "reg.h"
32#include "spi.h"
33
34static irqreturn_t wl1251_irq(int irq, void *cookie)
35{
36 struct wl1251 *wl;
37
38 wl1251_debug(DEBUG_IRQ, "IRQ");
39
40 wl = cookie;
41
42 ieee80211_queue_work(wl->hw, &wl->irq_work);
43
44 return IRQ_HANDLED;
45}
46
47static struct spi_device *wl_to_spi(struct wl1251 *wl)
48{
49 return wl->if_priv;
50}
51
52static void wl1251_spi_reset(struct wl1251 *wl)
53{
54 u8 *cmd;
55 struct spi_transfer t;
56 struct spi_message m;
57
58 cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL);
59 if (!cmd) {
60 wl1251_error("could not allocate cmd for spi reset");
61 return;
62 }
63
64 memset(&t, 0, sizeof(t));
65 spi_message_init(&m);
66
67 memset(cmd, 0xff, WSPI_INIT_CMD_LEN);
68
69 t.tx_buf = cmd;
70 t.len = WSPI_INIT_CMD_LEN;
71 spi_message_add_tail(&t, &m);
72
73 spi_sync(wl_to_spi(wl), &m);
74
75 wl1251_dump(DEBUG_SPI, "spi reset -> ", cmd, WSPI_INIT_CMD_LEN);
76}
77
78static void wl1251_spi_wake(struct wl1251 *wl)
79{
80 u8 crc[WSPI_INIT_CMD_CRC_LEN], *cmd;
81 struct spi_transfer t;
82 struct spi_message m;
83
84 cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL);
85 if (!cmd) {
86 wl1251_error("could not allocate cmd for spi init");
87 return;
88 }
89
90 memset(crc, 0, sizeof(crc));
91 memset(&t, 0, sizeof(t));
92 spi_message_init(&m);
93
94 /*
95 * Set WSPI_INIT_COMMAND
96 * the data is being send from the MSB to LSB
97 */
98 cmd[2] = 0xff;
99 cmd[3] = 0xff;
100 cmd[1] = WSPI_INIT_CMD_START | WSPI_INIT_CMD_TX;
101 cmd[0] = 0;
102 cmd[7] = 0;
103 cmd[6] |= HW_ACCESS_WSPI_INIT_CMD_MASK << 3;
104 cmd[6] |= HW_ACCESS_WSPI_FIXED_BUSY_LEN & WSPI_INIT_CMD_FIXEDBUSY_LEN;
105
106 if (HW_ACCESS_WSPI_FIXED_BUSY_LEN == 0)
107 cmd[5] |= WSPI_INIT_CMD_DIS_FIXEDBUSY;
108 else
109 cmd[5] |= WSPI_INIT_CMD_EN_FIXEDBUSY;
110
111 cmd[5] |= WSPI_INIT_CMD_IOD | WSPI_INIT_CMD_IP | WSPI_INIT_CMD_CS
112 | WSPI_INIT_CMD_WSPI | WSPI_INIT_CMD_WS;
113
114 crc[0] = cmd[1];
115 crc[1] = cmd[0];
116 crc[2] = cmd[7];
117 crc[3] = cmd[6];
118 crc[4] = cmd[5];
119
120 cmd[4] |= crc7(0, crc, WSPI_INIT_CMD_CRC_LEN) << 1;
121 cmd[4] |= WSPI_INIT_CMD_END;
122
123 t.tx_buf = cmd;
124 t.len = WSPI_INIT_CMD_LEN;
125 spi_message_add_tail(&t, &m);
126
127 spi_sync(wl_to_spi(wl), &m);
128
129 wl1251_dump(DEBUG_SPI, "spi init -> ", cmd, WSPI_INIT_CMD_LEN);
130}
131
132static void wl1251_spi_reset_wake(struct wl1251 *wl)
133{
134 wl1251_spi_reset(wl);
135 wl1251_spi_wake(wl);
136}
137
138static void wl1251_spi_read(struct wl1251 *wl, int addr, void *buf,
139 size_t len)
140{
141 struct spi_transfer t[3];
142 struct spi_message m;
143 u8 *busy_buf;
144 u32 *cmd;
145
146 cmd = &wl->buffer_cmd;
147 busy_buf = wl->buffer_busyword;
148
149 *cmd = 0;
150 *cmd |= WSPI_CMD_READ;
151 *cmd |= (len << WSPI_CMD_BYTE_LENGTH_OFFSET) & WSPI_CMD_BYTE_LENGTH;
152 *cmd |= addr & WSPI_CMD_BYTE_ADDR;
153
154 spi_message_init(&m);
155 memset(t, 0, sizeof(t));
156
157 t[0].tx_buf = cmd;
158 t[0].len = 4;
159 spi_message_add_tail(&t[0], &m);
160
161 /* Busy and non busy words read */
162 t[1].rx_buf = busy_buf;
163 t[1].len = WL1251_BUSY_WORD_LEN;
164 spi_message_add_tail(&t[1], &m);
165
166 t[2].rx_buf = buf;
167 t[2].len = len;
168 spi_message_add_tail(&t[2], &m);
169
170 spi_sync(wl_to_spi(wl), &m);
171
172 /* FIXME: check busy words */
173
174 wl1251_dump(DEBUG_SPI, "spi_read cmd -> ", cmd, sizeof(*cmd));
175 wl1251_dump(DEBUG_SPI, "spi_read buf <- ", buf, len);
176}
177
178static void wl1251_spi_write(struct wl1251 *wl, int addr, void *buf,
179 size_t len)
180{
181 struct spi_transfer t[2];
182 struct spi_message m;
183 u32 *cmd;
184
185 cmd = &wl->buffer_cmd;
186
187 *cmd = 0;
188 *cmd |= WSPI_CMD_WRITE;
189 *cmd |= (len << WSPI_CMD_BYTE_LENGTH_OFFSET) & WSPI_CMD_BYTE_LENGTH;
190 *cmd |= addr & WSPI_CMD_BYTE_ADDR;
191
192 spi_message_init(&m);
193 memset(t, 0, sizeof(t));
194
195 t[0].tx_buf = cmd;
196 t[0].len = sizeof(*cmd);
197 spi_message_add_tail(&t[0], &m);
198
199 t[1].tx_buf = buf;
200 t[1].len = len;
201 spi_message_add_tail(&t[1], &m);
202
203 spi_sync(wl_to_spi(wl), &m);
204
205 wl1251_dump(DEBUG_SPI, "spi_write cmd -> ", cmd, sizeof(*cmd));
206 wl1251_dump(DEBUG_SPI, "spi_write buf -> ", buf, len);
207}
208
209static void wl1251_spi_enable_irq(struct wl1251 *wl)
210{
211 return enable_irq(wl->irq);
212}
213
214static void wl1251_spi_disable_irq(struct wl1251 *wl)
215{
216 return disable_irq(wl->irq);
217}
218
219static int wl1251_spi_set_power(struct wl1251 *wl, bool enable)
220{
221 if (wl->set_power)
222 wl->set_power(enable);
223
224 return 0;
225}
226
227static const struct wl1251_if_operations wl1251_spi_ops = {
228 .read = wl1251_spi_read,
229 .write = wl1251_spi_write,
230 .reset = wl1251_spi_reset_wake,
231 .enable_irq = wl1251_spi_enable_irq,
232 .disable_irq = wl1251_spi_disable_irq,
233 .power = wl1251_spi_set_power,
234};
235
236static int __devinit wl1251_spi_probe(struct spi_device *spi)
237{
238 struct wl12xx_platform_data *pdata;
239 struct ieee80211_hw *hw;
240 struct wl1251 *wl;
241 int ret;
242
243 pdata = spi->dev.platform_data;
244 if (!pdata) {
245 wl1251_error("no platform data");
246 return -ENODEV;
247 }
248
249 hw = wl1251_alloc_hw();
250 if (IS_ERR(hw))
251 return PTR_ERR(hw);
252
253 wl = hw->priv;
254
255 SET_IEEE80211_DEV(hw, &spi->dev);
256 dev_set_drvdata(&spi->dev, wl);
257 wl->if_priv = spi;
258 wl->if_ops = &wl1251_spi_ops;
259
260 /* This is the only SPI value that we need to set here, the rest
261 * comes from the board-peripherals file */
262 spi->bits_per_word = 32;
263
264 ret = spi_setup(spi);
265 if (ret < 0) {
266 wl1251_error("spi_setup failed");
267 goto out_free;
268 }
269
270 wl->set_power = pdata->set_power;
271 if (!wl->set_power) {
272 wl1251_error("set power function missing in platform data");
273 return -ENODEV;
274 }
275
276 wl->irq = spi->irq;
277 if (wl->irq < 0) {
278 wl1251_error("irq missing in platform data");
279 return -ENODEV;
280 }
281
282 wl->use_eeprom = pdata->use_eeprom;
283
284 ret = request_irq(wl->irq, wl1251_irq, 0, DRIVER_NAME, wl);
285 if (ret < 0) {
286 wl1251_error("request_irq() failed: %d", ret);
287 goto out_free;
288 }
289
290 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
291
292 disable_irq(wl->irq);
293
294 ret = wl1251_init_ieee80211(wl);
295 if (ret)
296 goto out_irq;
297
298 return 0;
299
300 out_irq:
301 free_irq(wl->irq, wl);
302
303 out_free:
304 ieee80211_free_hw(hw);
305
306 return ret;
307}
308
309static int __devexit wl1251_spi_remove(struct spi_device *spi)
310{
311 struct wl1251 *wl = dev_get_drvdata(&spi->dev);
312
313 free_irq(wl->irq, wl);
314 wl1251_free_hw(wl);
315
316 return 0;
317}
318
319static struct spi_driver wl1251_spi_driver = {
320 .driver = {
321 .name = DRIVER_NAME,
322 .owner = THIS_MODULE,
323 },
324
325 .probe = wl1251_spi_probe,
326 .remove = __devexit_p(wl1251_spi_remove),
327};
328
329static int __init wl1251_spi_init(void)
330{
331 int ret;
332
333 ret = spi_register_driver(&wl1251_spi_driver);
334 if (ret < 0) {
335 wl1251_error("failed to register spi driver: %d", ret);
336 goto out;
337 }
338
339out:
340 return ret;
341}
342
343static void __exit wl1251_spi_exit(void)
344{
345 spi_unregister_driver(&wl1251_spi_driver);
346
347 wl1251_notice("unloaded");
348}
349
350module_init(wl1251_spi_init);
351module_exit(wl1251_spi_exit);
352
353MODULE_LICENSE("GPL");
354MODULE_AUTHOR("Kalle Valo <kvalo@adurom.com>");
355MODULE_ALIAS("spi:wl1251");
diff --git a/drivers/net/wireless/ti/wl1251/spi.h b/drivers/net/wireless/ti/wl1251/spi.h
new file mode 100644
index 000000000000..16d506955cc0
--- /dev/null
+++ b/drivers/net/wireless/ti/wl1251/spi.h
@@ -0,0 +1,59 @@
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 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22
23#ifndef __WL1251_SPI_H__
24#define __WL1251_SPI_H__
25
26#include "cmd.h"
27#include "acx.h"
28#include "reg.h"
29
30#define WSPI_CMD_READ 0x40000000
31#define WSPI_CMD_WRITE 0x00000000
32#define WSPI_CMD_FIXED 0x20000000
33#define WSPI_CMD_BYTE_LENGTH 0x1FFE0000
34#define WSPI_CMD_BYTE_LENGTH_OFFSET 17
35#define WSPI_CMD_BYTE_ADDR 0x0001FFFF
36
37#define WSPI_INIT_CMD_CRC_LEN 5
38
39#define WSPI_INIT_CMD_START 0x00
40#define WSPI_INIT_CMD_TX 0x40
41/* the extra bypass bit is sampled by the TNET as '1' */
42#define WSPI_INIT_CMD_BYPASS_BIT 0x80
43#define WSPI_INIT_CMD_FIXEDBUSY_LEN 0x07
44#define WSPI_INIT_CMD_EN_FIXEDBUSY 0x80
45#define WSPI_INIT_CMD_DIS_FIXEDBUSY 0x00
46#define WSPI_INIT_CMD_IOD 0x40
47#define WSPI_INIT_CMD_IP 0x20
48#define WSPI_INIT_CMD_CS 0x10
49#define WSPI_INIT_CMD_WS 0x08
50#define WSPI_INIT_CMD_WSPI 0x01
51#define WSPI_INIT_CMD_END 0x01
52
53#define WSPI_INIT_CMD_LEN 8
54
55#define HW_ACCESS_WSPI_FIXED_BUSY_LEN \
56 ((WL1251_BUSY_WORD_LEN - 4) / sizeof(u32))
57#define HW_ACCESS_WSPI_INIT_CMD_MASK 0
58
59#endif /* __WL1251_SPI_H__ */
diff --git a/drivers/net/wireless/ti/wl1251/tx.c b/drivers/net/wireless/ti/wl1251/tx.c
new file mode 100644
index 000000000000..28121c590a2b
--- /dev/null
+++ b/drivers/net/wireless/ti/wl1251/tx.c
@@ -0,0 +1,560 @@
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 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22
23#include <linux/kernel.h>
24#include <linux/module.h>
25
26#include "wl1251.h"
27#include "reg.h"
28#include "tx.h"
29#include "ps.h"
30#include "io.h"
31
32static bool wl1251_tx_double_buffer_busy(struct wl1251 *wl, u32 data_out_count)
33{
34 int used, data_in_count;
35
36 data_in_count = wl->data_in_count;
37
38 if (data_in_count < data_out_count)
39 /* data_in_count has wrapped */
40 data_in_count += TX_STATUS_DATA_OUT_COUNT_MASK + 1;
41
42 used = data_in_count - data_out_count;
43
44 WARN_ON(used < 0);
45 WARN_ON(used > DP_TX_PACKET_RING_CHUNK_NUM);
46
47 if (used >= DP_TX_PACKET_RING_CHUNK_NUM)
48 return true;
49 else
50 return false;
51}
52
53static int wl1251_tx_path_status(struct wl1251 *wl)
54{
55 u32 status, addr, data_out_count;
56 bool busy;
57
58 addr = wl->data_path->tx_control_addr;
59 status = wl1251_mem_read32(wl, addr);
60 data_out_count = status & TX_STATUS_DATA_OUT_COUNT_MASK;
61 busy = wl1251_tx_double_buffer_busy(wl, data_out_count);
62
63 if (busy)
64 return -EBUSY;
65
66 return 0;
67}
68
69static int wl1251_tx_id(struct wl1251 *wl, struct sk_buff *skb)
70{
71 int i;
72
73 for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
74 if (wl->tx_frames[i] == NULL) {
75 wl->tx_frames[i] = skb;
76 return i;
77 }
78
79 return -EBUSY;
80}
81
82static void wl1251_tx_control(struct tx_double_buffer_desc *tx_hdr,
83 struct ieee80211_tx_info *control, u16 fc)
84{
85 *(u16 *)&tx_hdr->control = 0;
86
87 tx_hdr->control.rate_policy = 0;
88
89 /* 802.11 packets */
90 tx_hdr->control.packet_type = 0;
91
92 if (control->flags & IEEE80211_TX_CTL_NO_ACK)
93 tx_hdr->control.ack_policy = 1;
94
95 tx_hdr->control.tx_complete = 1;
96
97 if ((fc & IEEE80211_FTYPE_DATA) &&
98 ((fc & IEEE80211_STYPE_QOS_DATA) ||
99 (fc & IEEE80211_STYPE_QOS_NULLFUNC)))
100 tx_hdr->control.qos = 1;
101}
102
103/* RSN + MIC = 8 + 8 = 16 bytes (worst case - AES). */
104#define MAX_MSDU_SECURITY_LENGTH 16
105#define MAX_MPDU_SECURITY_LENGTH 16
106#define WLAN_QOS_HDR_LEN 26
107#define MAX_MPDU_HEADER_AND_SECURITY (MAX_MPDU_SECURITY_LENGTH + \
108 WLAN_QOS_HDR_LEN)
109#define HW_BLOCK_SIZE 252
110static void wl1251_tx_frag_block_num(struct tx_double_buffer_desc *tx_hdr)
111{
112 u16 payload_len, frag_threshold, mem_blocks;
113 u16 num_mpdus, mem_blocks_per_frag;
114
115 frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
116 tx_hdr->frag_threshold = cpu_to_le16(frag_threshold);
117
118 payload_len = le16_to_cpu(tx_hdr->length) + MAX_MSDU_SECURITY_LENGTH;
119
120 if (payload_len > frag_threshold) {
121 mem_blocks_per_frag =
122 ((frag_threshold + MAX_MPDU_HEADER_AND_SECURITY) /
123 HW_BLOCK_SIZE) + 1;
124 num_mpdus = payload_len / frag_threshold;
125 mem_blocks = num_mpdus * mem_blocks_per_frag;
126 payload_len -= num_mpdus * frag_threshold;
127 num_mpdus++;
128
129 } else {
130 mem_blocks_per_frag = 0;
131 mem_blocks = 0;
132 num_mpdus = 1;
133 }
134
135 mem_blocks += (payload_len / HW_BLOCK_SIZE) + 1;
136
137 if (num_mpdus > 1)
138 mem_blocks += min(num_mpdus, mem_blocks_per_frag);
139
140 tx_hdr->num_mem_blocks = mem_blocks;
141}
142
143static int wl1251_tx_fill_hdr(struct wl1251 *wl, struct sk_buff *skb,
144 struct ieee80211_tx_info *control)
145{
146 struct tx_double_buffer_desc *tx_hdr;
147 struct ieee80211_rate *rate;
148 int id;
149 u16 fc;
150
151 if (!skb)
152 return -EINVAL;
153
154 id = wl1251_tx_id(wl, skb);
155 if (id < 0)
156 return id;
157
158 fc = *(u16 *)skb->data;
159 tx_hdr = (struct tx_double_buffer_desc *) skb_push(skb,
160 sizeof(*tx_hdr));
161
162 tx_hdr->length = cpu_to_le16(skb->len - sizeof(*tx_hdr));
163 rate = ieee80211_get_tx_rate(wl->hw, control);
164 tx_hdr->rate = cpu_to_le16(rate->hw_value);
165 tx_hdr->expiry_time = cpu_to_le32(1 << 16);
166 tx_hdr->id = id;
167
168 tx_hdr->xmit_queue = wl1251_tx_get_queue(skb_get_queue_mapping(skb));
169
170 wl1251_tx_control(tx_hdr, control, fc);
171 wl1251_tx_frag_block_num(tx_hdr);
172
173 return 0;
174}
175
176/* We copy the packet to the target */
177static int wl1251_tx_send_packet(struct wl1251 *wl, struct sk_buff *skb,
178 struct ieee80211_tx_info *control)
179{
180 struct tx_double_buffer_desc *tx_hdr;
181 int len;
182 u32 addr;
183
184 if (!skb)
185 return -EINVAL;
186
187 tx_hdr = (struct tx_double_buffer_desc *) skb->data;
188
189 if (control->control.hw_key &&
190 control->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) {
191 int hdrlen;
192 __le16 fc;
193 u16 length;
194 u8 *pos;
195
196 fc = *(__le16 *)(skb->data + sizeof(*tx_hdr));
197 length = le16_to_cpu(tx_hdr->length) + WL1251_TKIP_IV_SPACE;
198 tx_hdr->length = cpu_to_le16(length);
199
200 hdrlen = ieee80211_hdrlen(fc);
201
202 pos = skb_push(skb, WL1251_TKIP_IV_SPACE);
203 memmove(pos, pos + WL1251_TKIP_IV_SPACE,
204 sizeof(*tx_hdr) + hdrlen);
205 }
206
207 /* Revisit. This is a workaround for getting non-aligned packets.
208 This happens at least with EAPOL packets from the user space.
209 Our DMA requires packets to be aligned on a 4-byte boundary.
210 */
211 if (unlikely((long)skb->data & 0x03)) {
212 int offset = (4 - (long)skb->data) & 0x03;
213 wl1251_debug(DEBUG_TX, "skb offset %d", offset);
214
215 /* check whether the current skb can be used */
216 if (skb_cloned(skb) || (skb_tailroom(skb) < offset)) {
217 struct sk_buff *newskb = skb_copy_expand(skb, 0, 3,
218 GFP_KERNEL);
219
220 if (unlikely(newskb == NULL)) {
221 wl1251_error("Can't allocate skb!");
222 return -EINVAL;
223 }
224
225 tx_hdr = (struct tx_double_buffer_desc *) newskb->data;
226
227 dev_kfree_skb_any(skb);
228 wl->tx_frames[tx_hdr->id] = skb = newskb;
229
230 offset = (4 - (long)skb->data) & 0x03;
231 wl1251_debug(DEBUG_TX, "new skb offset %d", offset);
232 }
233
234 /* align the buffer on a 4-byte boundary */
235 if (offset) {
236 unsigned char *src = skb->data;
237 skb_reserve(skb, offset);
238 memmove(skb->data, src, skb->len);
239 tx_hdr = (struct tx_double_buffer_desc *) skb->data;
240 }
241 }
242
243 /* Our skb->data at this point includes the HW header */
244 len = WL1251_TX_ALIGN(skb->len);
245
246 if (wl->data_in_count & 0x1)
247 addr = wl->data_path->tx_packet_ring_addr +
248 wl->data_path->tx_packet_ring_chunk_size;
249 else
250 addr = wl->data_path->tx_packet_ring_addr;
251
252 wl1251_mem_write(wl, addr, skb->data, len);
253
254 wl1251_debug(DEBUG_TX, "tx id %u skb 0x%p payload %u rate 0x%x "
255 "queue %d", tx_hdr->id, skb, tx_hdr->length,
256 tx_hdr->rate, tx_hdr->xmit_queue);
257
258 return 0;
259}
260
261static void wl1251_tx_trigger(struct wl1251 *wl)
262{
263 u32 data, addr;
264
265 if (wl->data_in_count & 0x1) {
266 addr = ACX_REG_INTERRUPT_TRIG_H;
267 data = INTR_TRIG_TX_PROC1;
268 } else {
269 addr = ACX_REG_INTERRUPT_TRIG;
270 data = INTR_TRIG_TX_PROC0;
271 }
272
273 wl1251_reg_write32(wl, addr, data);
274
275 /* Bumping data in */
276 wl->data_in_count = (wl->data_in_count + 1) &
277 TX_STATUS_DATA_OUT_COUNT_MASK;
278}
279
280/* caller must hold wl->mutex */
281static int wl1251_tx_frame(struct wl1251 *wl, struct sk_buff *skb)
282{
283 struct ieee80211_tx_info *info;
284 int ret = 0;
285 u8 idx;
286
287 info = IEEE80211_SKB_CB(skb);
288
289 if (info->control.hw_key) {
290 idx = info->control.hw_key->hw_key_idx;
291 if (unlikely(wl->default_key != idx)) {
292 ret = wl1251_acx_default_key(wl, idx);
293 if (ret < 0)
294 return ret;
295 }
296 }
297
298 ret = wl1251_tx_path_status(wl);
299 if (ret < 0)
300 return ret;
301
302 ret = wl1251_tx_fill_hdr(wl, skb, info);
303 if (ret < 0)
304 return ret;
305
306 ret = wl1251_tx_send_packet(wl, skb, info);
307 if (ret < 0)
308 return ret;
309
310 wl1251_tx_trigger(wl);
311
312 return ret;
313}
314
315void wl1251_tx_work(struct work_struct *work)
316{
317 struct wl1251 *wl = container_of(work, struct wl1251, tx_work);
318 struct sk_buff *skb;
319 bool woken_up = false;
320 int ret;
321
322 mutex_lock(&wl->mutex);
323
324 if (unlikely(wl->state == WL1251_STATE_OFF))
325 goto out;
326
327 while ((skb = skb_dequeue(&wl->tx_queue))) {
328 if (!woken_up) {
329 ret = wl1251_ps_elp_wakeup(wl);
330 if (ret < 0)
331 goto out;
332 woken_up = true;
333 }
334
335 ret = wl1251_tx_frame(wl, skb);
336 if (ret == -EBUSY) {
337 skb_queue_head(&wl->tx_queue, skb);
338 goto out;
339 } else if (ret < 0) {
340 dev_kfree_skb(skb);
341 goto out;
342 }
343 }
344
345out:
346 if (woken_up)
347 wl1251_ps_elp_sleep(wl);
348
349 mutex_unlock(&wl->mutex);
350}
351
352static const char *wl1251_tx_parse_status(u8 status)
353{
354 /* 8 bit status field, one character per bit plus null */
355 static char buf[9];
356 int i = 0;
357
358 memset(buf, 0, sizeof(buf));
359
360 if (status & TX_DMA_ERROR)
361 buf[i++] = 'm';
362 if (status & TX_DISABLED)
363 buf[i++] = 'd';
364 if (status & TX_RETRY_EXCEEDED)
365 buf[i++] = 'r';
366 if (status & TX_TIMEOUT)
367 buf[i++] = 't';
368 if (status & TX_KEY_NOT_FOUND)
369 buf[i++] = 'k';
370 if (status & TX_ENCRYPT_FAIL)
371 buf[i++] = 'e';
372 if (status & TX_UNAVAILABLE_PRIORITY)
373 buf[i++] = 'p';
374
375 /* bit 0 is unused apparently */
376
377 return buf;
378}
379
380static void wl1251_tx_packet_cb(struct wl1251 *wl,
381 struct tx_result *result)
382{
383 struct ieee80211_tx_info *info;
384 struct sk_buff *skb;
385 int hdrlen;
386 u8 *frame;
387
388 skb = wl->tx_frames[result->id];
389 if (skb == NULL) {
390 wl1251_error("SKB for packet %d is NULL", result->id);
391 return;
392 }
393
394 info = IEEE80211_SKB_CB(skb);
395
396 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK) &&
397 (result->status == TX_SUCCESS))
398 info->flags |= IEEE80211_TX_STAT_ACK;
399
400 info->status.rates[0].count = result->ack_failures + 1;
401 wl->stats.retry_count += result->ack_failures;
402
403 /*
404 * We have to remove our private TX header before pushing
405 * the skb back to mac80211.
406 */
407 frame = skb_pull(skb, sizeof(struct tx_double_buffer_desc));
408 if (info->control.hw_key &&
409 info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) {
410 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
411 memmove(frame + WL1251_TKIP_IV_SPACE, frame, hdrlen);
412 skb_pull(skb, WL1251_TKIP_IV_SPACE);
413 }
414
415 wl1251_debug(DEBUG_TX, "tx status id %u skb 0x%p failures %u rate 0x%x"
416 " status 0x%x (%s)",
417 result->id, skb, result->ack_failures, result->rate,
418 result->status, wl1251_tx_parse_status(result->status));
419
420
421 ieee80211_tx_status(wl->hw, skb);
422
423 wl->tx_frames[result->id] = NULL;
424}
425
426/* Called upon reception of a TX complete interrupt */
427void wl1251_tx_complete(struct wl1251 *wl)
428{
429 int i, result_index, num_complete = 0, queue_len;
430 struct tx_result result[FW_TX_CMPLT_BLOCK_SIZE], *result_ptr;
431 unsigned long flags;
432
433 if (unlikely(wl->state != WL1251_STATE_ON))
434 return;
435
436 /* First we read the result */
437 wl1251_mem_read(wl, wl->data_path->tx_complete_addr,
438 result, sizeof(result));
439
440 result_index = wl->next_tx_complete;
441
442 for (i = 0; i < ARRAY_SIZE(result); i++) {
443 result_ptr = &result[result_index];
444
445 if (result_ptr->done_1 == 1 &&
446 result_ptr->done_2 == 1) {
447 wl1251_tx_packet_cb(wl, result_ptr);
448
449 result_ptr->done_1 = 0;
450 result_ptr->done_2 = 0;
451
452 result_index = (result_index + 1) &
453 (FW_TX_CMPLT_BLOCK_SIZE - 1);
454 num_complete++;
455 } else {
456 break;
457 }
458 }
459
460 queue_len = skb_queue_len(&wl->tx_queue);
461
462 if ((num_complete > 0) && (queue_len > 0)) {
463 /* firmware buffer has space, reschedule tx_work */
464 wl1251_debug(DEBUG_TX, "tx_complete: reschedule tx_work");
465 ieee80211_queue_work(wl->hw, &wl->tx_work);
466 }
467
468 if (wl->tx_queue_stopped &&
469 queue_len <= WL1251_TX_QUEUE_LOW_WATERMARK) {
470 /* tx_queue has space, restart queues */
471 wl1251_debug(DEBUG_TX, "tx_complete: waking queues");
472 spin_lock_irqsave(&wl->wl_lock, flags);
473 ieee80211_wake_queues(wl->hw);
474 wl->tx_queue_stopped = false;
475 spin_unlock_irqrestore(&wl->wl_lock, flags);
476 }
477
478 /* Every completed frame needs to be acknowledged */
479 if (num_complete) {
480 /*
481 * If we've wrapped, we have to clear
482 * the results in 2 steps.
483 */
484 if (result_index > wl->next_tx_complete) {
485 /* Only 1 write is needed */
486 wl1251_mem_write(wl,
487 wl->data_path->tx_complete_addr +
488 (wl->next_tx_complete *
489 sizeof(struct tx_result)),
490 &result[wl->next_tx_complete],
491 num_complete *
492 sizeof(struct tx_result));
493
494
495 } else if (result_index < wl->next_tx_complete) {
496 /* 2 writes are needed */
497 wl1251_mem_write(wl,
498 wl->data_path->tx_complete_addr +
499 (wl->next_tx_complete *
500 sizeof(struct tx_result)),
501 &result[wl->next_tx_complete],
502 (FW_TX_CMPLT_BLOCK_SIZE -
503 wl->next_tx_complete) *
504 sizeof(struct tx_result));
505
506 wl1251_mem_write(wl,
507 wl->data_path->tx_complete_addr,
508 result,
509 (num_complete -
510 FW_TX_CMPLT_BLOCK_SIZE +
511 wl->next_tx_complete) *
512 sizeof(struct tx_result));
513
514 } else {
515 /* We have to write the whole array */
516 wl1251_mem_write(wl,
517 wl->data_path->tx_complete_addr,
518 result,
519 FW_TX_CMPLT_BLOCK_SIZE *
520 sizeof(struct tx_result));
521 }
522
523 }
524
525 wl->next_tx_complete = result_index;
526}
527
528/* caller must hold wl->mutex */
529void wl1251_tx_flush(struct wl1251 *wl)
530{
531 int i;
532 struct sk_buff *skb;
533 struct ieee80211_tx_info *info;
534
535 /* TX failure */
536/* control->flags = 0; FIXME */
537
538 while ((skb = skb_dequeue(&wl->tx_queue))) {
539 info = IEEE80211_SKB_CB(skb);
540
541 wl1251_debug(DEBUG_TX, "flushing skb 0x%p", skb);
542
543 if (!(info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS))
544 continue;
545
546 ieee80211_tx_status(wl->hw, skb);
547 }
548
549 for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
550 if (wl->tx_frames[i] != NULL) {
551 skb = wl->tx_frames[i];
552 info = IEEE80211_SKB_CB(skb);
553
554 if (!(info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS))
555 continue;
556
557 ieee80211_tx_status(wl->hw, skb);
558 wl->tx_frames[i] = NULL;
559 }
560}
diff --git a/drivers/net/wireless/ti/wl1251/tx.h b/drivers/net/wireless/ti/wl1251/tx.h
new file mode 100644
index 000000000000..81338d39b43e
--- /dev/null
+++ b/drivers/net/wireless/ti/wl1251/tx.h
@@ -0,0 +1,231 @@
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 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22
23#ifndef __WL1251_TX_H__
24#define __WL1251_TX_H__
25
26#include <linux/bitops.h>
27#include "acx.h"
28
29/*
30 *
31 * TX PATH
32 *
33 * The Tx path uses a double buffer and a tx_control structure, each located
34 * at a fixed address in the device's memory. On startup, the host retrieves
35 * the pointers to these addresses. A double buffer allows for continuous data
36 * flow towards the device. The host keeps track of which buffer is available
37 * and alternates between these two buffers on a per packet basis.
38 *
39 * The size of each of the two buffers is large enough to hold the longest
40 * 802.3 packet - maximum size Ethernet packet + header + descriptor.
41 * TX complete indication will be received a-synchronously in a TX done cyclic
42 * buffer which is composed of 16 tx_result descriptors structures and is used
43 * in a cyclic manner.
44 *
45 * The TX (HOST) procedure is as follows:
46 * 1. Read the Tx path status, that will give the data_out_count.
47 * 2. goto 1, if not possible.
48 * i.e. if data_in_count - data_out_count >= HwBuffer size (2 for double
49 * buffer).
50 * 3. Copy the packet (preceded by double_buffer_desc), if possible.
51 * i.e. if data_in_count - data_out_count < HwBuffer size (2 for double
52 * buffer).
53 * 4. increment data_in_count.
54 * 5. Inform the firmware by generating a firmware internal interrupt.
55 * 6. FW will increment data_out_count after it reads the buffer.
56 *
57 * The TX Complete procedure:
58 * 1. To get a TX complete indication the host enables the tx_complete flag in
59 * the TX descriptor Structure.
60 * 2. For each packet with a Tx Complete field set, the firmware adds the
61 * transmit results to the cyclic buffer (txDoneRing) and sets both done_1
62 * and done_2 to 1 to indicate driver ownership.
63 * 3. The firmware sends a Tx Complete interrupt to the host to trigger the
64 * host to process the new data. Note: interrupt will be send per packet if
65 * TX complete indication was requested in tx_control or per crossing
66 * aggregation threshold.
67 * 4. After receiving the Tx Complete interrupt, the host reads the
68 * TxDescriptorDone information in a cyclic manner and clears both done_1
69 * and done_2 fields.
70 *
71 */
72
73#define TX_COMPLETE_REQUIRED_BIT 0x80
74#define TX_STATUS_DATA_OUT_COUNT_MASK 0xf
75
76#define WL1251_TX_ALIGN_TO 4
77#define WL1251_TX_ALIGN(len) (((len) + WL1251_TX_ALIGN_TO - 1) & \
78 ~(WL1251_TX_ALIGN_TO - 1))
79#define WL1251_TKIP_IV_SPACE 4
80
81struct tx_control {
82 /* Rate Policy (class) index */
83 unsigned rate_policy:3;
84
85 /* When set, no ack policy is expected */
86 unsigned ack_policy:1;
87
88 /*
89 * Packet type:
90 * 0 -> 802.11
91 * 1 -> 802.3
92 * 2 -> IP
93 * 3 -> raw codec
94 */
95 unsigned packet_type:2;
96
97 /* If set, this is a QoS-Null or QoS-Data frame */
98 unsigned qos:1;
99
100 /*
101 * If set, the target triggers the tx complete INT
102 * upon frame sending completion.
103 */
104 unsigned tx_complete:1;
105
106 /* 2 bytes padding before packet header */
107 unsigned xfer_pad:1;
108
109 unsigned reserved:7;
110} __packed;
111
112
113struct tx_double_buffer_desc {
114 /* Length of payload, including headers. */
115 __le16 length;
116
117 /*
118 * A bit mask that specifies the initial rate to be used
119 * Possible values are:
120 * 0x0001 - 1Mbits
121 * 0x0002 - 2Mbits
122 * 0x0004 - 5.5Mbits
123 * 0x0008 - 6Mbits
124 * 0x0010 - 9Mbits
125 * 0x0020 - 11Mbits
126 * 0x0040 - 12Mbits
127 * 0x0080 - 18Mbits
128 * 0x0100 - 22Mbits
129 * 0x0200 - 24Mbits
130 * 0x0400 - 36Mbits
131 * 0x0800 - 48Mbits
132 * 0x1000 - 54Mbits
133 */
134 __le16 rate;
135
136 /* Time in us that a packet can spend in the target */
137 __le32 expiry_time;
138
139 /* index of the TX queue used for this packet */
140 u8 xmit_queue;
141
142 /* Used to identify a packet */
143 u8 id;
144
145 struct tx_control control;
146
147 /*
148 * The FW should cut the packet into fragments
149 * of this size.
150 */
151 __le16 frag_threshold;
152
153 /* Numbers of HW queue blocks to be allocated */
154 u8 num_mem_blocks;
155
156 u8 reserved;
157} __packed;
158
159enum {
160 TX_SUCCESS = 0,
161 TX_DMA_ERROR = BIT(7),
162 TX_DISABLED = BIT(6),
163 TX_RETRY_EXCEEDED = BIT(5),
164 TX_TIMEOUT = BIT(4),
165 TX_KEY_NOT_FOUND = BIT(3),
166 TX_ENCRYPT_FAIL = BIT(2),
167 TX_UNAVAILABLE_PRIORITY = BIT(1),
168};
169
170struct tx_result {
171 /*
172 * Ownership synchronization between the host and
173 * the firmware. If done_1 and done_2 are cleared,
174 * owned by the FW (no info ready).
175 */
176 u8 done_1;
177
178 /* same as double_buffer_desc->id */
179 u8 id;
180
181 /*
182 * Total air access duration consumed by this
183 * packet, including all retries and overheads.
184 */
185 u16 medium_usage;
186
187 /* Total media delay (from 1st EDCA AIFS counter until TX Complete). */
188 u32 medium_delay;
189
190 /* Time between host xfer and tx complete */
191 u32 fw_hnadling_time;
192
193 /* The LS-byte of the last TKIP sequence number. */
194 u8 lsb_seq_num;
195
196 /* Retry count */
197 u8 ack_failures;
198
199 /* At which rate we got a ACK */
200 u16 rate;
201
202 u16 reserved;
203
204 /* TX_* */
205 u8 status;
206
207 /* See done_1 */
208 u8 done_2;
209} __packed;
210
211static inline int wl1251_tx_get_queue(int queue)
212{
213 switch (queue) {
214 case 0:
215 return QOS_AC_VO;
216 case 1:
217 return QOS_AC_VI;
218 case 2:
219 return QOS_AC_BE;
220 case 3:
221 return QOS_AC_BK;
222 default:
223 return QOS_AC_BE;
224 }
225}
226
227void wl1251_tx_work(struct work_struct *work);
228void wl1251_tx_complete(struct wl1251 *wl);
229void wl1251_tx_flush(struct wl1251 *wl);
230
231#endif
diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
new file mode 100644
index 000000000000..9d8f5816c6f9
--- /dev/null
+++ b/drivers/net/wireless/ti/wl1251/wl1251.h
@@ -0,0 +1,446 @@
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 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22
23#ifndef __WL1251_H__
24#define __WL1251_H__
25
26#include <linux/mutex.h>
27#include <linux/list.h>
28#include <linux/bitops.h>
29#include <net/mac80211.h>
30
31#define DRIVER_NAME "wl1251"
32#define DRIVER_PREFIX DRIVER_NAME ": "
33
34enum {
35 DEBUG_NONE = 0,
36 DEBUG_IRQ = BIT(0),
37 DEBUG_SPI = BIT(1),
38 DEBUG_BOOT = BIT(2),
39 DEBUG_MAILBOX = BIT(3),
40 DEBUG_NETLINK = BIT(4),
41 DEBUG_EVENT = BIT(5),
42 DEBUG_TX = BIT(6),
43 DEBUG_RX = BIT(7),
44 DEBUG_SCAN = BIT(8),
45 DEBUG_CRYPT = BIT(9),
46 DEBUG_PSM = BIT(10),
47 DEBUG_MAC80211 = BIT(11),
48 DEBUG_CMD = BIT(12),
49 DEBUG_ACX = BIT(13),
50 DEBUG_ALL = ~0,
51};
52
53#define DEBUG_LEVEL (DEBUG_NONE)
54
55#define DEBUG_DUMP_LIMIT 1024
56
57#define wl1251_error(fmt, arg...) \
58 printk(KERN_ERR DRIVER_PREFIX "ERROR " fmt "\n", ##arg)
59
60#define wl1251_warning(fmt, arg...) \
61 printk(KERN_WARNING DRIVER_PREFIX "WARNING " fmt "\n", ##arg)
62
63#define wl1251_notice(fmt, arg...) \
64 printk(KERN_INFO DRIVER_PREFIX fmt "\n", ##arg)
65
66#define wl1251_info(fmt, arg...) \
67 printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg)
68
69#define wl1251_debug(level, fmt, arg...) \
70 do { \
71 if (level & DEBUG_LEVEL) \
72 printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg); \
73 } while (0)
74
75#define wl1251_dump(level, prefix, buf, len) \
76 do { \
77 if (level & DEBUG_LEVEL) \
78 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
79 DUMP_PREFIX_OFFSET, 16, 1, \
80 buf, \
81 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
82 0); \
83 } while (0)
84
85#define wl1251_dump_ascii(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 true); \
93 } while (0)
94
95#define WL1251_DEFAULT_RX_CONFIG (CFG_UNI_FILTER_EN | \
96 CFG_BSSID_FILTER_EN)
97
98#define WL1251_DEFAULT_RX_FILTER (CFG_RX_PRSP_EN | \
99 CFG_RX_MGMT_EN | \
100 CFG_RX_DATA_EN | \
101 CFG_RX_CTL_EN | \
102 CFG_RX_BCN_EN | \
103 CFG_RX_AUTH_EN | \
104 CFG_RX_ASSOC_EN)
105
106#define WL1251_BUSY_WORD_LEN 8
107
108struct boot_attr {
109 u32 radio_type;
110 u8 mac_clock;
111 u8 arm_clock;
112 int firmware_debug;
113 u32 minor;
114 u32 major;
115 u32 bugfix;
116};
117
118enum wl1251_state {
119 WL1251_STATE_OFF,
120 WL1251_STATE_ON,
121 WL1251_STATE_PLT,
122};
123
124enum wl1251_partition_type {
125 PART_DOWN,
126 PART_WORK,
127 PART_DRPW,
128
129 PART_TABLE_LEN
130};
131
132enum wl1251_station_mode {
133 STATION_ACTIVE_MODE,
134 STATION_POWER_SAVE_MODE,
135 STATION_IDLE,
136};
137
138struct wl1251_partition {
139 u32 size;
140 u32 start;
141};
142
143struct wl1251_partition_set {
144 struct wl1251_partition mem;
145 struct wl1251_partition reg;
146};
147
148struct wl1251;
149
150struct wl1251_stats {
151 struct acx_statistics *fw_stats;
152 unsigned long fw_stats_update;
153
154 unsigned int retry_count;
155 unsigned int excessive_retries;
156};
157
158struct wl1251_debugfs {
159 struct dentry *rootdir;
160 struct dentry *fw_statistics;
161
162 struct dentry *tx_internal_desc_overflow;
163
164 struct dentry *rx_out_of_mem;
165 struct dentry *rx_hdr_overflow;
166 struct dentry *rx_hw_stuck;
167 struct dentry *rx_dropped;
168 struct dentry *rx_fcs_err;
169 struct dentry *rx_xfr_hint_trig;
170 struct dentry *rx_path_reset;
171 struct dentry *rx_reset_counter;
172
173 struct dentry *dma_rx_requested;
174 struct dentry *dma_rx_errors;
175 struct dentry *dma_tx_requested;
176 struct dentry *dma_tx_errors;
177
178 struct dentry *isr_cmd_cmplt;
179 struct dentry *isr_fiqs;
180 struct dentry *isr_rx_headers;
181 struct dentry *isr_rx_mem_overflow;
182 struct dentry *isr_rx_rdys;
183 struct dentry *isr_irqs;
184 struct dentry *isr_tx_procs;
185 struct dentry *isr_decrypt_done;
186 struct dentry *isr_dma0_done;
187 struct dentry *isr_dma1_done;
188 struct dentry *isr_tx_exch_complete;
189 struct dentry *isr_commands;
190 struct dentry *isr_rx_procs;
191 struct dentry *isr_hw_pm_mode_changes;
192 struct dentry *isr_host_acknowledges;
193 struct dentry *isr_pci_pm;
194 struct dentry *isr_wakeups;
195 struct dentry *isr_low_rssi;
196
197 struct dentry *wep_addr_key_count;
198 struct dentry *wep_default_key_count;
199 /* skipping wep.reserved */
200 struct dentry *wep_key_not_found;
201 struct dentry *wep_decrypt_fail;
202 struct dentry *wep_packets;
203 struct dentry *wep_interrupt;
204
205 struct dentry *pwr_ps_enter;
206 struct dentry *pwr_elp_enter;
207 struct dentry *pwr_missing_bcns;
208 struct dentry *pwr_wake_on_host;
209 struct dentry *pwr_wake_on_timer_exp;
210 struct dentry *pwr_tx_with_ps;
211 struct dentry *pwr_tx_without_ps;
212 struct dentry *pwr_rcvd_beacons;
213 struct dentry *pwr_power_save_off;
214 struct dentry *pwr_enable_ps;
215 struct dentry *pwr_disable_ps;
216 struct dentry *pwr_fix_tsf_ps;
217 /* skipping cont_miss_bcns_spread for now */
218 struct dentry *pwr_rcvd_awake_beacons;
219
220 struct dentry *mic_rx_pkts;
221 struct dentry *mic_calc_failure;
222
223 struct dentry *aes_encrypt_fail;
224 struct dentry *aes_decrypt_fail;
225 struct dentry *aes_encrypt_packets;
226 struct dentry *aes_decrypt_packets;
227 struct dentry *aes_encrypt_interrupt;
228 struct dentry *aes_decrypt_interrupt;
229
230 struct dentry *event_heart_beat;
231 struct dentry *event_calibration;
232 struct dentry *event_rx_mismatch;
233 struct dentry *event_rx_mem_empty;
234 struct dentry *event_rx_pool;
235 struct dentry *event_oom_late;
236 struct dentry *event_phy_transmit_error;
237 struct dentry *event_tx_stuck;
238
239 struct dentry *ps_pspoll_timeouts;
240 struct dentry *ps_upsd_timeouts;
241 struct dentry *ps_upsd_max_sptime;
242 struct dentry *ps_upsd_max_apturn;
243 struct dentry *ps_pspoll_max_apturn;
244 struct dentry *ps_pspoll_utilization;
245 struct dentry *ps_upsd_utilization;
246
247 struct dentry *rxpipe_rx_prep_beacon_drop;
248 struct dentry *rxpipe_descr_host_int_trig_rx_data;
249 struct dentry *rxpipe_beacon_buffer_thres_host_int_trig_rx_data;
250 struct dentry *rxpipe_missed_beacon_host_int_trig_rx_data;
251 struct dentry *rxpipe_tx_xfr_host_int_trig_rx_data;
252
253 struct dentry *tx_queue_len;
254 struct dentry *tx_queue_status;
255
256 struct dentry *retry_count;
257 struct dentry *excessive_retries;
258};
259
260struct wl1251_if_operations {
261 void (*read)(struct wl1251 *wl, int addr, void *buf, size_t len);
262 void (*write)(struct wl1251 *wl, int addr, void *buf, size_t len);
263 void (*read_elp)(struct wl1251 *wl, int addr, u32 *val);
264 void (*write_elp)(struct wl1251 *wl, int addr, u32 val);
265 int (*power)(struct wl1251 *wl, bool enable);
266 void (*reset)(struct wl1251 *wl);
267 void (*enable_irq)(struct wl1251 *wl);
268 void (*disable_irq)(struct wl1251 *wl);
269};
270
271struct wl1251 {
272 struct ieee80211_hw *hw;
273 bool mac80211_registered;
274
275 void *if_priv;
276 const struct wl1251_if_operations *if_ops;
277
278 void (*set_power)(bool enable);
279 int irq;
280 bool use_eeprom;
281
282 spinlock_t wl_lock;
283
284 enum wl1251_state state;
285 struct mutex mutex;
286
287 int physical_mem_addr;
288 int physical_reg_addr;
289 int virtual_mem_addr;
290 int virtual_reg_addr;
291
292 int cmd_box_addr;
293 int event_box_addr;
294 struct boot_attr boot_attr;
295
296 u8 *fw;
297 size_t fw_len;
298 u8 *nvs;
299 size_t nvs_len;
300
301 u8 bssid[ETH_ALEN];
302 u8 mac_addr[ETH_ALEN];
303 u8 bss_type;
304 u8 listen_int;
305 int channel;
306
307 void *target_mem_map;
308 struct acx_data_path_params_resp *data_path;
309
310 /* Number of TX packets transferred to the FW, modulo 16 */
311 u32 data_in_count;
312
313 /* Frames scheduled for transmission, not handled yet */
314 struct sk_buff_head tx_queue;
315 bool tx_queue_stopped;
316
317 struct work_struct tx_work;
318 struct work_struct filter_work;
319
320 /* Pending TX frames */
321 struct sk_buff *tx_frames[16];
322
323 /*
324 * Index pointing to the next TX complete entry
325 * in the cyclic XT complete array we get from
326 * the FW.
327 */
328 u32 next_tx_complete;
329
330 /* FW Rx counter */
331 u32 rx_counter;
332
333 /* Rx frames handled */
334 u32 rx_handled;
335
336 /* Current double buffer */
337 u32 rx_current_buffer;
338 u32 rx_last_id;
339
340 /* The target interrupt mask */
341 u32 intr_mask;
342 struct work_struct irq_work;
343
344 /* The mbox event mask */
345 u32 event_mask;
346
347 /* Mailbox pointers */
348 u32 mbox_ptr[2];
349
350 /* Are we currently scanning */
351 bool scanning;
352
353 /* Default key (for WEP) */
354 u32 default_key;
355
356 unsigned int tx_mgmt_frm_rate;
357 unsigned int tx_mgmt_frm_mod;
358
359 unsigned int rx_config;
360 unsigned int rx_filter;
361
362 /* is firmware in elp mode */
363 bool elp;
364
365 struct delayed_work elp_work;
366
367 enum wl1251_station_mode station_mode;
368
369 /* PSM mode requested */
370 bool psm_requested;
371
372 u16 beacon_int;
373 u8 dtim_period;
374
375 /* in dBm */
376 int power_level;
377
378 int rssi_thold;
379
380 struct wl1251_stats stats;
381 struct wl1251_debugfs debugfs;
382
383 __le32 buffer_32;
384 u32 buffer_cmd;
385 u8 buffer_busyword[WL1251_BUSY_WORD_LEN];
386 struct wl1251_rx_descriptor *rx_descriptor;
387
388 struct ieee80211_vif *vif;
389
390 u32 chip_id;
391 char fw_ver[21];
392
393 /* Most recently reported noise in dBm */
394 s8 noise;
395};
396
397int wl1251_plt_start(struct wl1251 *wl);
398int wl1251_plt_stop(struct wl1251 *wl);
399
400struct ieee80211_hw *wl1251_alloc_hw(void);
401int wl1251_free_hw(struct wl1251 *wl);
402int wl1251_init_ieee80211(struct wl1251 *wl);
403void wl1251_enable_interrupts(struct wl1251 *wl);
404void wl1251_disable_interrupts(struct wl1251 *wl);
405
406#define DEFAULT_HW_GEN_MODULATION_TYPE CCK_LONG /* Long Preamble */
407#define DEFAULT_HW_GEN_TX_RATE RATE_2MBPS
408#define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
409
410#define WL1251_DEFAULT_POWER_LEVEL 20
411
412#define WL1251_TX_QUEUE_LOW_WATERMARK 10
413#define WL1251_TX_QUEUE_HIGH_WATERMARK 25
414
415#define WL1251_DEFAULT_BEACON_INT 100
416#define WL1251_DEFAULT_DTIM_PERIOD 1
417
418#define WL1251_DEFAULT_CHANNEL 0
419
420#define WL1251_DEFAULT_BET_CONSECUTIVE 10
421
422#define CHIP_ID_1251_PG10 (0x7010101)
423#define CHIP_ID_1251_PG11 (0x7020101)
424#define CHIP_ID_1251_PG12 (0x7030101)
425#define CHIP_ID_1271_PG10 (0x4030101)
426#define CHIP_ID_1271_PG20 (0x4030111)
427
428#define WL1251_FW_NAME "wl1251-fw.bin"
429#define WL1251_NVS_NAME "wl1251-nvs.bin"
430
431#define WL1251_POWER_ON_SLEEP 10 /* in milliseconds */
432
433#define WL1251_PART_DOWN_MEM_START 0x0
434#define WL1251_PART_DOWN_MEM_SIZE 0x16800
435#define WL1251_PART_DOWN_REG_START REGISTERS_BASE
436#define WL1251_PART_DOWN_REG_SIZE REGISTERS_DOWN_SIZE
437
438#define WL1251_PART_WORK_MEM_START 0x28000
439#define WL1251_PART_WORK_MEM_SIZE 0x14000
440#define WL1251_PART_WORK_REG_START REGISTERS_BASE
441#define WL1251_PART_WORK_REG_SIZE REGISTERS_WORK_SIZE
442
443#define WL1251_DEFAULT_LOW_RSSI_WEIGHT 10
444#define WL1251_DEFAULT_LOW_RSSI_DEPTH 10
445
446#endif
diff --git a/drivers/net/wireless/ti/wl1251/wl12xx_80211.h b/drivers/net/wireless/ti/wl1251/wl12xx_80211.h
new file mode 100644
index 000000000000..04ed51495772
--- /dev/null
+++ b/drivers/net/wireless/ti/wl1251/wl12xx_80211.h
@@ -0,0 +1,155 @@
1#ifndef __WL12XX_80211_H__
2#define __WL12XX_80211_H__
3
4#include <linux/if_ether.h> /* ETH_ALEN */
5
6/* RATES */
7#define IEEE80211_CCK_RATE_1MB 0x02
8#define IEEE80211_CCK_RATE_2MB 0x04
9#define IEEE80211_CCK_RATE_5MB 0x0B
10#define IEEE80211_CCK_RATE_11MB 0x16
11#define IEEE80211_OFDM_RATE_6MB 0x0C
12#define IEEE80211_OFDM_RATE_9MB 0x12
13#define IEEE80211_OFDM_RATE_12MB 0x18
14#define IEEE80211_OFDM_RATE_18MB 0x24
15#define IEEE80211_OFDM_RATE_24MB 0x30
16#define IEEE80211_OFDM_RATE_36MB 0x48
17#define IEEE80211_OFDM_RATE_48MB 0x60
18#define IEEE80211_OFDM_RATE_54MB 0x6C
19#define IEEE80211_BASIC_RATE_MASK 0x80
20
21#define IEEE80211_CCK_RATE_1MB_MASK (1<<0)
22#define IEEE80211_CCK_RATE_2MB_MASK (1<<1)
23#define IEEE80211_CCK_RATE_5MB_MASK (1<<2)
24#define IEEE80211_CCK_RATE_11MB_MASK (1<<3)
25#define IEEE80211_OFDM_RATE_6MB_MASK (1<<4)
26#define IEEE80211_OFDM_RATE_9MB_MASK (1<<5)
27#define IEEE80211_OFDM_RATE_12MB_MASK (1<<6)
28#define IEEE80211_OFDM_RATE_18MB_MASK (1<<7)
29#define IEEE80211_OFDM_RATE_24MB_MASK (1<<8)
30#define IEEE80211_OFDM_RATE_36MB_MASK (1<<9)
31#define IEEE80211_OFDM_RATE_48MB_MASK (1<<10)
32#define IEEE80211_OFDM_RATE_54MB_MASK (1<<11)
33
34#define IEEE80211_CCK_RATES_MASK 0x0000000F
35#define IEEE80211_CCK_BASIC_RATES_MASK (IEEE80211_CCK_RATE_1MB_MASK | \
36 IEEE80211_CCK_RATE_2MB_MASK)
37#define IEEE80211_CCK_DEFAULT_RATES_MASK (IEEE80211_CCK_BASIC_RATES_MASK | \
38 IEEE80211_CCK_RATE_5MB_MASK | \
39 IEEE80211_CCK_RATE_11MB_MASK)
40
41#define IEEE80211_OFDM_RATES_MASK 0x00000FF0
42#define IEEE80211_OFDM_BASIC_RATES_MASK (IEEE80211_OFDM_RATE_6MB_MASK | \
43 IEEE80211_OFDM_RATE_12MB_MASK | \
44 IEEE80211_OFDM_RATE_24MB_MASK)
45#define IEEE80211_OFDM_DEFAULT_RATES_MASK (IEEE80211_OFDM_BASIC_RATES_MASK | \
46 IEEE80211_OFDM_RATE_9MB_MASK | \
47 IEEE80211_OFDM_RATE_18MB_MASK | \
48 IEEE80211_OFDM_RATE_36MB_MASK | \
49 IEEE80211_OFDM_RATE_48MB_MASK | \
50 IEEE80211_OFDM_RATE_54MB_MASK)
51#define IEEE80211_DEFAULT_RATES_MASK (IEEE80211_OFDM_DEFAULT_RATES_MASK | \
52 IEEE80211_CCK_DEFAULT_RATES_MASK)
53
54
55/* This really should be 8, but not for our firmware */
56#define MAX_SUPPORTED_RATES 32
57#define MAX_COUNTRY_TRIPLETS 32
58
59/* Headers */
60struct ieee80211_header {
61 __le16 frame_ctl;
62 __le16 duration_id;
63 u8 da[ETH_ALEN];
64 u8 sa[ETH_ALEN];
65 u8 bssid[ETH_ALEN];
66 __le16 seq_ctl;
67 u8 payload[0];
68} __packed;
69
70struct wl12xx_ie_header {
71 u8 id;
72 u8 len;
73} __packed;
74
75/* IEs */
76
77struct wl12xx_ie_ssid {
78 struct wl12xx_ie_header header;
79 char ssid[IEEE80211_MAX_SSID_LEN];
80} __packed;
81
82struct wl12xx_ie_rates {
83 struct wl12xx_ie_header header;
84 u8 rates[MAX_SUPPORTED_RATES];
85} __packed;
86
87struct wl12xx_ie_ds_params {
88 struct wl12xx_ie_header header;
89 u8 channel;
90} __packed;
91
92struct country_triplet {
93 u8 channel;
94 u8 num_channels;
95 u8 max_tx_power;
96} __packed;
97
98struct wl12xx_ie_country {
99 struct wl12xx_ie_header header;
100 u8 country_string[IEEE80211_COUNTRY_STRING_LEN];
101 struct country_triplet triplets[MAX_COUNTRY_TRIPLETS];
102} __packed;
103
104
105/* Templates */
106
107struct wl12xx_beacon_template {
108 struct ieee80211_header header;
109 __le32 time_stamp[2];
110 __le16 beacon_interval;
111 __le16 capability;
112 struct wl12xx_ie_ssid ssid;
113 struct wl12xx_ie_rates rates;
114 struct wl12xx_ie_rates ext_rates;
115 struct wl12xx_ie_ds_params ds_params;
116 struct wl12xx_ie_country country;
117} __packed;
118
119struct wl12xx_null_data_template {
120 struct ieee80211_header header;
121} __packed;
122
123struct wl12xx_ps_poll_template {
124 __le16 fc;
125 __le16 aid;
126 u8 bssid[ETH_ALEN];
127 u8 ta[ETH_ALEN];
128} __packed;
129
130struct wl12xx_qos_null_data_template {
131 struct ieee80211_header header;
132 __le16 qos_ctl;
133} __packed;
134
135struct wl12xx_probe_req_template {
136 struct ieee80211_header header;
137 struct wl12xx_ie_ssid ssid;
138 struct wl12xx_ie_rates rates;
139 struct wl12xx_ie_rates ext_rates;
140} __packed;
141
142
143struct wl12xx_probe_resp_template {
144 struct ieee80211_header header;
145 __le32 time_stamp[2];
146 __le16 beacon_interval;
147 __le16 capability;
148 struct wl12xx_ie_ssid ssid;
149 struct wl12xx_ie_rates rates;
150 struct wl12xx_ie_rates ext_rates;
151 struct wl12xx_ie_ds_params ds_params;
152 struct wl12xx_ie_country country;
153} __packed;
154
155#endif
diff --git a/drivers/net/wireless/ti/wl12xx/Kconfig b/drivers/net/wireless/ti/wl12xx/Kconfig
new file mode 100644
index 000000000000..5b92329122c4
--- /dev/null
+++ b/drivers/net/wireless/ti/wl12xx/Kconfig
@@ -0,0 +1,8 @@
1config WL12XX
2 tristate "TI wl12xx support"
3 select WLCORE
4 ---help---
5 This module adds support for wireless adapters based on TI wl1271,
6 wl1273, wl1281 and wl1283 chipsets. This module does *not* include
7 support for wl1251. For wl1251 support, use the separate homonymous
8 driver instead.
diff --git a/drivers/net/wireless/ti/wl12xx/Makefile b/drivers/net/wireless/ti/wl12xx/Makefile
new file mode 100644
index 000000000000..87f64b14db35
--- /dev/null
+++ b/drivers/net/wireless/ti/wl12xx/Makefile
@@ -0,0 +1,3 @@
1wl12xx-objs = main.o cmd.o acx.o
2
3obj-$(CONFIG_WL12XX) += wl12xx.o
diff --git a/drivers/net/wireless/ti/wl12xx/acx.c b/drivers/net/wireless/ti/wl12xx/acx.c
new file mode 100644
index 000000000000..bea06b2d7bf4
--- /dev/null
+++ b/drivers/net/wireless/ti/wl12xx/acx.c
@@ -0,0 +1,53 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (C) 2008-2009 Nokia Corporation
5 * Copyright (C) 2011 Texas Instruments Inc.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22
23#include "../wlcore/cmd.h"
24#include "../wlcore/debug.h"
25#include "../wlcore/acx.h"
26
27#include "acx.h"
28
29int wl1271_acx_host_if_cfg_bitmap(struct wl1271 *wl, u32 host_cfg_bitmap)
30{
31 struct wl1271_acx_host_config_bitmap *bitmap_conf;
32 int ret;
33
34 bitmap_conf = kzalloc(sizeof(*bitmap_conf), GFP_KERNEL);
35 if (!bitmap_conf) {
36 ret = -ENOMEM;
37 goto out;
38 }
39
40 bitmap_conf->host_cfg_bitmap = cpu_to_le32(host_cfg_bitmap);
41
42 ret = wl1271_cmd_configure(wl, ACX_HOST_IF_CFG_BITMAP,
43 bitmap_conf, sizeof(*bitmap_conf));
44 if (ret < 0) {
45 wl1271_warning("wl1271 bitmap config opt failed: %d", ret);
46 goto out;
47 }
48
49out:
50 kfree(bitmap_conf);
51
52 return ret;
53}
diff --git a/drivers/net/wireless/ti/wl12xx/acx.h b/drivers/net/wireless/ti/wl12xx/acx.h
new file mode 100644
index 000000000000..d1f5aba0afce
--- /dev/null
+++ b/drivers/net/wireless/ti/wl12xx/acx.h
@@ -0,0 +1,36 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (C) 1998-2009, 2011 Texas Instruments. All rights reserved.
5 * Copyright (C) 2008-2010 Nokia Corporation
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22
23#ifndef __WL12XX_ACX_H__
24#define __WL12XX_ACX_H__
25
26#include "../wlcore/wlcore.h"
27
28struct wl1271_acx_host_config_bitmap {
29 struct acx_header header;
30
31 __le32 host_cfg_bitmap;
32} __packed;
33
34int wl1271_acx_host_if_cfg_bitmap(struct wl1271 *wl, u32 host_cfg_bitmap);
35
36#endif /* __WL12XX_ACX_H__ */
diff --git a/drivers/net/wireless/ti/wl12xx/cmd.c b/drivers/net/wireless/ti/wl12xx/cmd.c
new file mode 100644
index 000000000000..8ffaeb5f2147
--- /dev/null
+++ b/drivers/net/wireless/ti/wl12xx/cmd.c
@@ -0,0 +1,254 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (C) 2009-2010 Nokia Corporation
5 * Copyright (C) 2011 Texas Instruments Inc.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22
23#include "../wlcore/cmd.h"
24#include "../wlcore/debug.h"
25
26#include "wl12xx.h"
27#include "cmd.h"
28
29int wl1271_cmd_ext_radio_parms(struct wl1271 *wl)
30{
31 struct wl1271_ext_radio_parms_cmd *ext_radio_parms;
32 struct wl12xx_priv *priv = wl->priv;
33 struct wl12xx_conf_rf *rf = &priv->conf.rf;
34 int ret;
35
36 if (!wl->nvs)
37 return -ENODEV;
38
39 ext_radio_parms = kzalloc(sizeof(*ext_radio_parms), GFP_KERNEL);
40 if (!ext_radio_parms)
41 return -ENOMEM;
42
43 ext_radio_parms->test.id = TEST_CMD_INI_FILE_RF_EXTENDED_PARAM;
44
45 memcpy(ext_radio_parms->tx_per_channel_power_compensation_2,
46 rf->tx_per_channel_power_compensation_2,
47 CONF_TX_PWR_COMPENSATION_LEN_2);
48 memcpy(ext_radio_parms->tx_per_channel_power_compensation_5,
49 rf->tx_per_channel_power_compensation_5,
50 CONF_TX_PWR_COMPENSATION_LEN_5);
51
52 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_EXT_RADIO_PARAM: ",
53 ext_radio_parms, sizeof(*ext_radio_parms));
54
55 ret = wl1271_cmd_test(wl, ext_radio_parms, sizeof(*ext_radio_parms), 0);
56 if (ret < 0)
57 wl1271_warning("TEST_CMD_INI_FILE_RF_EXTENDED_PARAM failed");
58
59 kfree(ext_radio_parms);
60 return ret;
61}
62
63int wl1271_cmd_general_parms(struct wl1271 *wl)
64{
65 struct wl1271_general_parms_cmd *gen_parms;
66 struct wl1271_ini_general_params *gp =
67 &((struct wl1271_nvs_file *)wl->nvs)->general_params;
68 bool answer = false;
69 int ret;
70
71 if (!wl->nvs)
72 return -ENODEV;
73
74 if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
75 wl1271_warning("FEM index from INI out of bounds");
76 return -EINVAL;
77 }
78
79 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
80 if (!gen_parms)
81 return -ENOMEM;
82
83 gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
84
85 memcpy(&gen_parms->general_params, gp, sizeof(*gp));
86
87 if (gp->tx_bip_fem_auto_detect)
88 answer = true;
89
90 /* Override the REF CLK from the NVS with the one from platform data */
91 gen_parms->general_params.ref_clock = wl->ref_clock;
92
93 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer);
94 if (ret < 0) {
95 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
96 goto out;
97 }
98
99 gp->tx_bip_fem_manufacturer =
100 gen_parms->general_params.tx_bip_fem_manufacturer;
101
102 if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
103 wl1271_warning("FEM index from FW out of bounds");
104 ret = -EINVAL;
105 goto out;
106 }
107
108 wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
109 answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
110
111out:
112 kfree(gen_parms);
113 return ret;
114}
115
116int wl128x_cmd_general_parms(struct wl1271 *wl)
117{
118 struct wl128x_general_parms_cmd *gen_parms;
119 struct wl128x_ini_general_params *gp =
120 &((struct wl128x_nvs_file *)wl->nvs)->general_params;
121 bool answer = false;
122 int ret;
123
124 if (!wl->nvs)
125 return -ENODEV;
126
127 if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
128 wl1271_warning("FEM index from ini out of bounds");
129 return -EINVAL;
130 }
131
132 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
133 if (!gen_parms)
134 return -ENOMEM;
135
136 gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
137
138 memcpy(&gen_parms->general_params, gp, sizeof(*gp));
139
140 if (gp->tx_bip_fem_auto_detect)
141 answer = true;
142
143 /* Replace REF and TCXO CLKs with the ones from platform data */
144 gen_parms->general_params.ref_clock = wl->ref_clock;
145 gen_parms->general_params.tcxo_ref_clock = wl->tcxo_clock;
146
147 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer);
148 if (ret < 0) {
149 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
150 goto out;
151 }
152
153 gp->tx_bip_fem_manufacturer =
154 gen_parms->general_params.tx_bip_fem_manufacturer;
155
156 if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
157 wl1271_warning("FEM index from FW out of bounds");
158 ret = -EINVAL;
159 goto out;
160 }
161
162 wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
163 answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
164
165out:
166 kfree(gen_parms);
167 return ret;
168}
169
170int wl1271_cmd_radio_parms(struct wl1271 *wl)
171{
172 struct wl1271_nvs_file *nvs = (struct wl1271_nvs_file *)wl->nvs;
173 struct wl1271_radio_parms_cmd *radio_parms;
174 struct wl1271_ini_general_params *gp = &nvs->general_params;
175 int ret;
176
177 if (!wl->nvs)
178 return -ENODEV;
179
180 radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
181 if (!radio_parms)
182 return -ENOMEM;
183
184 radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
185
186 /* 2.4GHz parameters */
187 memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2,
188 sizeof(struct wl1271_ini_band_params_2));
189 memcpy(&radio_parms->dyn_params_2,
190 &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params,
191 sizeof(struct wl1271_ini_fem_params_2));
192
193 /* 5GHz parameters */
194 memcpy(&radio_parms->static_params_5,
195 &nvs->stat_radio_params_5,
196 sizeof(struct wl1271_ini_band_params_5));
197 memcpy(&radio_parms->dyn_params_5,
198 &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params,
199 sizeof(struct wl1271_ini_fem_params_5));
200
201 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
202 radio_parms, sizeof(*radio_parms));
203
204 ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
205 if (ret < 0)
206 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
207
208 kfree(radio_parms);
209 return ret;
210}
211
212int wl128x_cmd_radio_parms(struct wl1271 *wl)
213{
214 struct wl128x_nvs_file *nvs = (struct wl128x_nvs_file *)wl->nvs;
215 struct wl128x_radio_parms_cmd *radio_parms;
216 struct wl128x_ini_general_params *gp = &nvs->general_params;
217 int ret;
218
219 if (!wl->nvs)
220 return -ENODEV;
221
222 radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
223 if (!radio_parms)
224 return -ENOMEM;
225
226 radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
227
228 /* 2.4GHz parameters */
229 memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2,
230 sizeof(struct wl128x_ini_band_params_2));
231 memcpy(&radio_parms->dyn_params_2,
232 &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params,
233 sizeof(struct wl128x_ini_fem_params_2));
234
235 /* 5GHz parameters */
236 memcpy(&radio_parms->static_params_5,
237 &nvs->stat_radio_params_5,
238 sizeof(struct wl128x_ini_band_params_5));
239 memcpy(&radio_parms->dyn_params_5,
240 &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params,
241 sizeof(struct wl128x_ini_fem_params_5));
242
243 radio_parms->fem_vendor_and_options = nvs->fem_vendor_and_options;
244
245 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
246 radio_parms, sizeof(*radio_parms));
247
248 ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
249 if (ret < 0)
250 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
251
252 kfree(radio_parms);
253 return ret;
254}
diff --git a/drivers/net/wireless/ti/wl12xx/cmd.h b/drivers/net/wireless/ti/wl12xx/cmd.h
new file mode 100644
index 000000000000..140a0e8829d5
--- /dev/null
+++ b/drivers/net/wireless/ti/wl12xx/cmd.h
@@ -0,0 +1,112 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (C) 1998-2009, 2011 Texas Instruments. All rights reserved.
5 * Copyright (C) 2009 Nokia Corporation
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22
23#ifndef __WL12XX_CMD_H__
24#define __WL12XX_CMD_H__
25
26#include "conf.h"
27
28#define TEST_CMD_INI_FILE_RADIO_PARAM 0x19
29#define TEST_CMD_INI_FILE_GENERAL_PARAM 0x1E
30
31struct wl1271_general_parms_cmd {
32 struct wl1271_cmd_header header;
33
34 struct wl1271_cmd_test_header test;
35
36 struct wl1271_ini_general_params general_params;
37
38 u8 sr_debug_table[WL1271_INI_MAX_SMART_REFLEX_PARAM];
39 u8 sr_sen_n_p;
40 u8 sr_sen_n_p_gain;
41 u8 sr_sen_nrn;
42 u8 sr_sen_prn;
43 u8 padding[3];
44} __packed;
45
46struct wl128x_general_parms_cmd {
47 struct wl1271_cmd_header header;
48
49 struct wl1271_cmd_test_header test;
50
51 struct wl128x_ini_general_params general_params;
52
53 u8 sr_debug_table[WL1271_INI_MAX_SMART_REFLEX_PARAM];
54 u8 sr_sen_n_p;
55 u8 sr_sen_n_p_gain;
56 u8 sr_sen_nrn;
57 u8 sr_sen_prn;
58 u8 padding[3];
59} __packed;
60
61struct wl1271_radio_parms_cmd {
62 struct wl1271_cmd_header header;
63
64 struct wl1271_cmd_test_header test;
65
66 /* Static radio parameters */
67 struct wl1271_ini_band_params_2 static_params_2;
68 struct wl1271_ini_band_params_5 static_params_5;
69
70 /* Dynamic radio parameters */
71 struct wl1271_ini_fem_params_2 dyn_params_2;
72 u8 padding2;
73 struct wl1271_ini_fem_params_5 dyn_params_5;
74 u8 padding3[2];
75} __packed;
76
77struct wl128x_radio_parms_cmd {
78 struct wl1271_cmd_header header;
79
80 struct wl1271_cmd_test_header test;
81
82 /* Static radio parameters */
83 struct wl128x_ini_band_params_2 static_params_2;
84 struct wl128x_ini_band_params_5 static_params_5;
85
86 u8 fem_vendor_and_options;
87
88 /* Dynamic radio parameters */
89 struct wl128x_ini_fem_params_2 dyn_params_2;
90 u8 padding2;
91 struct wl128x_ini_fem_params_5 dyn_params_5;
92} __packed;
93
94#define TEST_CMD_INI_FILE_RF_EXTENDED_PARAM 0x26
95
96struct wl1271_ext_radio_parms_cmd {
97 struct wl1271_cmd_header header;
98
99 struct wl1271_cmd_test_header test;
100
101 u8 tx_per_channel_power_compensation_2[CONF_TX_PWR_COMPENSATION_LEN_2];
102 u8 tx_per_channel_power_compensation_5[CONF_TX_PWR_COMPENSATION_LEN_5];
103 u8 padding[3];
104} __packed;
105
106int wl1271_cmd_general_parms(struct wl1271 *wl);
107int wl128x_cmd_general_parms(struct wl1271 *wl);
108int wl1271_cmd_radio_parms(struct wl1271 *wl);
109int wl128x_cmd_radio_parms(struct wl1271 *wl);
110int wl1271_cmd_ext_radio_parms(struct wl1271 *wl);
111
112#endif /* __WL12XX_CMD_H__ */
diff --git a/drivers/net/wireless/ti/wl12xx/conf.h b/drivers/net/wireless/ti/wl12xx/conf.h
new file mode 100644
index 000000000000..75e29897a0f5
--- /dev/null
+++ b/drivers/net/wireless/ti/wl12xx/conf.h
@@ -0,0 +1,50 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (C) 2011 Texas Instruments Inc.
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
22#ifndef __WL12XX_CONF_H__
23#define __WL12XX_CONF_H__
24
25/* these are number of channels on the band divided by two, rounded up */
26#define CONF_TX_PWR_COMPENSATION_LEN_2 7
27#define CONF_TX_PWR_COMPENSATION_LEN_5 18
28
29struct wl12xx_conf_rf {
30 /*
31 * Per channel power compensation for 2.4GHz
32 *
33 * Range: s8
34 */
35 u8 tx_per_channel_power_compensation_2[CONF_TX_PWR_COMPENSATION_LEN_2];
36
37 /*
38 * Per channel power compensation for 5GHz
39 *
40 * Range: s8
41 */
42 u8 tx_per_channel_power_compensation_5[CONF_TX_PWR_COMPENSATION_LEN_5];
43};
44
45struct wl12xx_priv_conf {
46 struct wl12xx_conf_rf rf;
47 struct conf_memory_settings mem_wl127x;
48};
49
50#endif /* __WL12XX_CONF_H__ */
diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
new file mode 100644
index 000000000000..d7dd3def07b5
--- /dev/null
+++ b/drivers/net/wireless/ti/wl12xx/main.c
@@ -0,0 +1,1388 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2008-2010 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
22#include <linux/module.h>
23#include <linux/platform_device.h>
24
25#include <linux/err.h>
26
27#include <linux/wl12xx.h>
28
29#include "../wlcore/wlcore.h"
30#include "../wlcore/debug.h"
31#include "../wlcore/io.h"
32#include "../wlcore/acx.h"
33#include "../wlcore/tx.h"
34#include "../wlcore/rx.h"
35#include "../wlcore/io.h"
36#include "../wlcore/boot.h"
37
38#include "wl12xx.h"
39#include "reg.h"
40#include "cmd.h"
41#include "acx.h"
42
43static struct wlcore_conf wl12xx_conf = {
44 .sg = {
45 .params = {
46 [CONF_SG_ACL_BT_MASTER_MIN_BR] = 10,
47 [CONF_SG_ACL_BT_MASTER_MAX_BR] = 180,
48 [CONF_SG_ACL_BT_SLAVE_MIN_BR] = 10,
49 [CONF_SG_ACL_BT_SLAVE_MAX_BR] = 180,
50 [CONF_SG_ACL_BT_MASTER_MIN_EDR] = 10,
51 [CONF_SG_ACL_BT_MASTER_MAX_EDR] = 80,
52 [CONF_SG_ACL_BT_SLAVE_MIN_EDR] = 10,
53 [CONF_SG_ACL_BT_SLAVE_MAX_EDR] = 80,
54 [CONF_SG_ACL_WLAN_PS_MASTER_BR] = 8,
55 [CONF_SG_ACL_WLAN_PS_SLAVE_BR] = 8,
56 [CONF_SG_ACL_WLAN_PS_MASTER_EDR] = 20,
57 [CONF_SG_ACL_WLAN_PS_SLAVE_EDR] = 20,
58 [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_BR] = 20,
59 [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_BR] = 35,
60 [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_BR] = 16,
61 [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_BR] = 35,
62 [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_EDR] = 32,
63 [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_EDR] = 50,
64 [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_EDR] = 28,
65 [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_EDR] = 50,
66 [CONF_SG_ACL_ACTIVE_SCAN_WLAN_BR] = 10,
67 [CONF_SG_ACL_ACTIVE_SCAN_WLAN_EDR] = 20,
68 [CONF_SG_ACL_PASSIVE_SCAN_BT_BR] = 75,
69 [CONF_SG_ACL_PASSIVE_SCAN_WLAN_BR] = 15,
70 [CONF_SG_ACL_PASSIVE_SCAN_BT_EDR] = 27,
71 [CONF_SG_ACL_PASSIVE_SCAN_WLAN_EDR] = 17,
72 /* active scan params */
73 [CONF_SG_AUTO_SCAN_PROBE_REQ] = 170,
74 [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_HV3] = 50,
75 [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_A2DP] = 100,
76 /* passive scan params */
77 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_BR] = 800,
78 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_EDR] = 200,
79 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_HV3] = 200,
80 /* passive scan in dual antenna params */
81 [CONF_SG_CONSECUTIVE_HV3_IN_PASSIVE_SCAN] = 0,
82 [CONF_SG_BCN_HV3_COLLISION_THRESH_IN_PASSIVE_SCAN] = 0,
83 [CONF_SG_TX_RX_PROTECTION_BWIDTH_IN_PASSIVE_SCAN] = 0,
84 /* general params */
85 [CONF_SG_STA_FORCE_PS_IN_BT_SCO] = 1,
86 [CONF_SG_ANTENNA_CONFIGURATION] = 0,
87 [CONF_SG_BEACON_MISS_PERCENT] = 60,
88 [CONF_SG_DHCP_TIME] = 5000,
89 [CONF_SG_RXT] = 1200,
90 [CONF_SG_TXT] = 1000,
91 [CONF_SG_ADAPTIVE_RXT_TXT] = 1,
92 [CONF_SG_GENERAL_USAGE_BIT_MAP] = 3,
93 [CONF_SG_HV3_MAX_SERVED] = 6,
94 [CONF_SG_PS_POLL_TIMEOUT] = 10,
95 [CONF_SG_UPSD_TIMEOUT] = 10,
96 [CONF_SG_CONSECUTIVE_CTS_THRESHOLD] = 2,
97 [CONF_SG_STA_RX_WINDOW_AFTER_DTIM] = 5,
98 [CONF_SG_STA_CONNECTION_PROTECTION_TIME] = 30,
99 /* AP params */
100 [CONF_AP_BEACON_MISS_TX] = 3,
101 [CONF_AP_RX_WINDOW_AFTER_BEACON] = 10,
102 [CONF_AP_BEACON_WINDOW_INTERVAL] = 2,
103 [CONF_AP_CONNECTION_PROTECTION_TIME] = 0,
104 [CONF_AP_BT_ACL_VAL_BT_SERVE_TIME] = 25,
105 [CONF_AP_BT_ACL_VAL_WL_SERVE_TIME] = 25,
106 /* CTS Diluting params */
107 [CONF_SG_CTS_DILUTED_BAD_RX_PACKETS_TH] = 0,
108 [CONF_SG_CTS_CHOP_IN_DUAL_ANT_SCO_MASTER] = 0,
109 },
110 .state = CONF_SG_PROTECTIVE,
111 },
112 .rx = {
113 .rx_msdu_life_time = 512000,
114 .packet_detection_threshold = 0,
115 .ps_poll_timeout = 15,
116 .upsd_timeout = 15,
117 .rts_threshold = IEEE80211_MAX_RTS_THRESHOLD,
118 .rx_cca_threshold = 0,
119 .irq_blk_threshold = 0xFFFF,
120 .irq_pkt_threshold = 0,
121 .irq_timeout = 600,
122 .queue_type = CONF_RX_QUEUE_TYPE_LOW_PRIORITY,
123 },
124 .tx = {
125 .tx_energy_detection = 0,
126 .sta_rc_conf = {
127 .enabled_rates = 0,
128 .short_retry_limit = 10,
129 .long_retry_limit = 10,
130 .aflags = 0,
131 },
132 .ac_conf_count = 4,
133 .ac_conf = {
134 [CONF_TX_AC_BE] = {
135 .ac = CONF_TX_AC_BE,
136 .cw_min = 15,
137 .cw_max = 63,
138 .aifsn = 3,
139 .tx_op_limit = 0,
140 },
141 [CONF_TX_AC_BK] = {
142 .ac = CONF_TX_AC_BK,
143 .cw_min = 15,
144 .cw_max = 63,
145 .aifsn = 7,
146 .tx_op_limit = 0,
147 },
148 [CONF_TX_AC_VI] = {
149 .ac = CONF_TX_AC_VI,
150 .cw_min = 15,
151 .cw_max = 63,
152 .aifsn = CONF_TX_AIFS_PIFS,
153 .tx_op_limit = 3008,
154 },
155 [CONF_TX_AC_VO] = {
156 .ac = CONF_TX_AC_VO,
157 .cw_min = 15,
158 .cw_max = 63,
159 .aifsn = CONF_TX_AIFS_PIFS,
160 .tx_op_limit = 1504,
161 },
162 },
163 .max_tx_retries = 100,
164 .ap_aging_period = 300,
165 .tid_conf_count = 4,
166 .tid_conf = {
167 [CONF_TX_AC_BE] = {
168 .queue_id = CONF_TX_AC_BE,
169 .channel_type = CONF_CHANNEL_TYPE_EDCF,
170 .tsid = CONF_TX_AC_BE,
171 .ps_scheme = CONF_PS_SCHEME_LEGACY,
172 .ack_policy = CONF_ACK_POLICY_LEGACY,
173 .apsd_conf = {0, 0},
174 },
175 [CONF_TX_AC_BK] = {
176 .queue_id = CONF_TX_AC_BK,
177 .channel_type = CONF_CHANNEL_TYPE_EDCF,
178 .tsid = CONF_TX_AC_BK,
179 .ps_scheme = CONF_PS_SCHEME_LEGACY,
180 .ack_policy = CONF_ACK_POLICY_LEGACY,
181 .apsd_conf = {0, 0},
182 },
183 [CONF_TX_AC_VI] = {
184 .queue_id = CONF_TX_AC_VI,
185 .channel_type = CONF_CHANNEL_TYPE_EDCF,
186 .tsid = CONF_TX_AC_VI,
187 .ps_scheme = CONF_PS_SCHEME_LEGACY,
188 .ack_policy = CONF_ACK_POLICY_LEGACY,
189 .apsd_conf = {0, 0},
190 },
191 [CONF_TX_AC_VO] = {
192 .queue_id = CONF_TX_AC_VO,
193 .channel_type = CONF_CHANNEL_TYPE_EDCF,
194 .tsid = CONF_TX_AC_VO,
195 .ps_scheme = CONF_PS_SCHEME_LEGACY,
196 .ack_policy = CONF_ACK_POLICY_LEGACY,
197 .apsd_conf = {0, 0},
198 },
199 },
200 .frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD,
201 .tx_compl_timeout = 700,
202 .tx_compl_threshold = 4,
203 .basic_rate = CONF_HW_BIT_RATE_1MBPS,
204 .basic_rate_5 = CONF_HW_BIT_RATE_6MBPS,
205 .tmpl_short_retry_limit = 10,
206 .tmpl_long_retry_limit = 10,
207 .tx_watchdog_timeout = 5000,
208 },
209 .conn = {
210 .wake_up_event = CONF_WAKE_UP_EVENT_DTIM,
211 .listen_interval = 1,
212 .suspend_wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM,
213 .suspend_listen_interval = 3,
214 .bcn_filt_mode = CONF_BCN_FILT_MODE_ENABLED,
215 .bcn_filt_ie_count = 2,
216 .bcn_filt_ie = {
217 [0] = {
218 .ie = WLAN_EID_CHANNEL_SWITCH,
219 .rule = CONF_BCN_RULE_PASS_ON_APPEARANCE,
220 },
221 [1] = {
222 .ie = WLAN_EID_HT_OPERATION,
223 .rule = CONF_BCN_RULE_PASS_ON_CHANGE,
224 },
225 },
226 .synch_fail_thold = 10,
227 .bss_lose_timeout = 100,
228 .beacon_rx_timeout = 10000,
229 .broadcast_timeout = 20000,
230 .rx_broadcast_in_ps = 1,
231 .ps_poll_threshold = 10,
232 .bet_enable = CONF_BET_MODE_ENABLE,
233 .bet_max_consecutive = 50,
234 .psm_entry_retries = 8,
235 .psm_exit_retries = 16,
236 .psm_entry_nullfunc_retries = 3,
237 .dynamic_ps_timeout = 40,
238 .forced_ps = false,
239 .keep_alive_interval = 55000,
240 .max_listen_interval = 20,
241 },
242 .itrim = {
243 .enable = false,
244 .timeout = 50000,
245 },
246 .pm_config = {
247 .host_clk_settling_time = 5000,
248 .host_fast_wakeup_support = false
249 },
250 .roam_trigger = {
251 .trigger_pacing = 1,
252 .avg_weight_rssi_beacon = 20,
253 .avg_weight_rssi_data = 10,
254 .avg_weight_snr_beacon = 20,
255 .avg_weight_snr_data = 10,
256 },
257 .scan = {
258 .min_dwell_time_active = 7500,
259 .max_dwell_time_active = 30000,
260 .min_dwell_time_passive = 100000,
261 .max_dwell_time_passive = 100000,
262 .num_probe_reqs = 2,
263 .split_scan_timeout = 50000,
264 },
265 .sched_scan = {
266 /*
267 * Values are in TU/1000 but since sched scan FW command
268 * params are in TUs rounding up may occur.
269 */
270 .base_dwell_time = 7500,
271 .max_dwell_time_delta = 22500,
272 /* based on 250bits per probe @1Mbps */
273 .dwell_time_delta_per_probe = 2000,
274 /* based on 250bits per probe @6Mbps (plus a bit more) */
275 .dwell_time_delta_per_probe_5 = 350,
276 .dwell_time_passive = 100000,
277 .dwell_time_dfs = 150000,
278 .num_probe_reqs = 2,
279 .rssi_threshold = -90,
280 .snr_threshold = 0,
281 },
282 .ht = {
283 .rx_ba_win_size = 8,
284 .tx_ba_win_size = 64,
285 .inactivity_timeout = 10000,
286 .tx_ba_tid_bitmap = CONF_TX_BA_ENABLED_TID_BITMAP,
287 },
288 /*
289 * Memory config for wl127x chips is given in the
290 * wl12xx_default_priv_conf struct. The below configuration is
291 * for wl128x chips.
292 */
293 .mem = {
294 .num_stations = 1,
295 .ssid_profiles = 1,
296 .rx_block_num = 40,
297 .tx_min_block_num = 40,
298 .dynamic_memory = 1,
299 .min_req_tx_blocks = 45,
300 .min_req_rx_blocks = 22,
301 .tx_min = 27,
302 },
303 .fm_coex = {
304 .enable = true,
305 .swallow_period = 5,
306 .n_divider_fref_set_1 = 0xff, /* default */
307 .n_divider_fref_set_2 = 12,
308 .m_divider_fref_set_1 = 148,
309 .m_divider_fref_set_2 = 0xffff, /* default */
310 .coex_pll_stabilization_time = 0xffffffff, /* default */
311 .ldo_stabilization_time = 0xffff, /* default */
312 .fm_disturbed_band_margin = 0xff, /* default */
313 .swallow_clk_diff = 0xff, /* default */
314 },
315 .rx_streaming = {
316 .duration = 150,
317 .queues = 0x1,
318 .interval = 20,
319 .always = 0,
320 },
321 .fwlog = {
322 .mode = WL12XX_FWLOG_ON_DEMAND,
323 .mem_blocks = 2,
324 .severity = 0,
325 .timestamp = WL12XX_FWLOG_TIMESTAMP_DISABLED,
326 .output = WL12XX_FWLOG_OUTPUT_HOST,
327 .threshold = 0,
328 },
329 .rate = {
330 .rate_retry_score = 32000,
331 .per_add = 8192,
332 .per_th1 = 2048,
333 .per_th2 = 4096,
334 .max_per = 8100,
335 .inverse_curiosity_factor = 5,
336 .tx_fail_low_th = 4,
337 .tx_fail_high_th = 10,
338 .per_alpha_shift = 4,
339 .per_add_shift = 13,
340 .per_beta1_shift = 10,
341 .per_beta2_shift = 8,
342 .rate_check_up = 2,
343 .rate_check_down = 12,
344 .rate_retry_policy = {
345 0x00, 0x00, 0x00, 0x00, 0x00,
346 0x00, 0x00, 0x00, 0x00, 0x00,
347 0x00, 0x00, 0x00,
348 },
349 },
350 .hangover = {
351 .recover_time = 0,
352 .hangover_period = 20,
353 .dynamic_mode = 1,
354 .early_termination_mode = 1,
355 .max_period = 20,
356 .min_period = 1,
357 .increase_delta = 1,
358 .decrease_delta = 2,
359 .quiet_time = 4,
360 .increase_time = 1,
361 .window_size = 16,
362 },
363};
364
365static struct wl12xx_priv_conf wl12xx_default_priv_conf = {
366 .rf = {
367 .tx_per_channel_power_compensation_2 = {
368 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
369 },
370 .tx_per_channel_power_compensation_5 = {
371 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
372 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
373 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
374 },
375 },
376 .mem_wl127x = {
377 .num_stations = 1,
378 .ssid_profiles = 1,
379 .rx_block_num = 70,
380 .tx_min_block_num = 40,
381 .dynamic_memory = 1,
382 .min_req_tx_blocks = 100,
383 .min_req_rx_blocks = 22,
384 .tx_min = 27,
385 },
386
387};
388
389#define WL12XX_TX_HW_BLOCK_SPARE_DEFAULT 1
390#define WL12XX_TX_HW_BLOCK_GEM_SPARE 2
391#define WL12XX_TX_HW_BLOCK_SIZE 252
392
393static const u8 wl12xx_rate_to_idx_2ghz[] = {
394 /* MCS rates are used only with 11n */
395 7, /* WL12XX_CONF_HW_RXTX_RATE_MCS7_SGI */
396 7, /* WL12XX_CONF_HW_RXTX_RATE_MCS7 */
397 6, /* WL12XX_CONF_HW_RXTX_RATE_MCS6 */
398 5, /* WL12XX_CONF_HW_RXTX_RATE_MCS5 */
399 4, /* WL12XX_CONF_HW_RXTX_RATE_MCS4 */
400 3, /* WL12XX_CONF_HW_RXTX_RATE_MCS3 */
401 2, /* WL12XX_CONF_HW_RXTX_RATE_MCS2 */
402 1, /* WL12XX_CONF_HW_RXTX_RATE_MCS1 */
403 0, /* WL12XX_CONF_HW_RXTX_RATE_MCS0 */
404
405 11, /* WL12XX_CONF_HW_RXTX_RATE_54 */
406 10, /* WL12XX_CONF_HW_RXTX_RATE_48 */
407 9, /* WL12XX_CONF_HW_RXTX_RATE_36 */
408 8, /* WL12XX_CONF_HW_RXTX_RATE_24 */
409
410 /* TI-specific rate */
411 CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL12XX_CONF_HW_RXTX_RATE_22 */
412
413 7, /* WL12XX_CONF_HW_RXTX_RATE_18 */
414 6, /* WL12XX_CONF_HW_RXTX_RATE_12 */
415 3, /* WL12XX_CONF_HW_RXTX_RATE_11 */
416 5, /* WL12XX_CONF_HW_RXTX_RATE_9 */
417 4, /* WL12XX_CONF_HW_RXTX_RATE_6 */
418 2, /* WL12XX_CONF_HW_RXTX_RATE_5_5 */
419 1, /* WL12XX_CONF_HW_RXTX_RATE_2 */
420 0 /* WL12XX_CONF_HW_RXTX_RATE_1 */
421};
422
423static const u8 wl12xx_rate_to_idx_5ghz[] = {
424 /* MCS rates are used only with 11n */
425 7, /* WL12XX_CONF_HW_RXTX_RATE_MCS7_SGI */
426 7, /* WL12XX_CONF_HW_RXTX_RATE_MCS7 */
427 6, /* WL12XX_CONF_HW_RXTX_RATE_MCS6 */
428 5, /* WL12XX_CONF_HW_RXTX_RATE_MCS5 */
429 4, /* WL12XX_CONF_HW_RXTX_RATE_MCS4 */
430 3, /* WL12XX_CONF_HW_RXTX_RATE_MCS3 */
431 2, /* WL12XX_CONF_HW_RXTX_RATE_MCS2 */
432 1, /* WL12XX_CONF_HW_RXTX_RATE_MCS1 */
433 0, /* WL12XX_CONF_HW_RXTX_RATE_MCS0 */
434
435 7, /* WL12XX_CONF_HW_RXTX_RATE_54 */
436 6, /* WL12XX_CONF_HW_RXTX_RATE_48 */
437 5, /* WL12XX_CONF_HW_RXTX_RATE_36 */
438 4, /* WL12XX_CONF_HW_RXTX_RATE_24 */
439
440 /* TI-specific rate */
441 CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL12XX_CONF_HW_RXTX_RATE_22 */
442
443 3, /* WL12XX_CONF_HW_RXTX_RATE_18 */
444 2, /* WL12XX_CONF_HW_RXTX_RATE_12 */
445 CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL12XX_CONF_HW_RXTX_RATE_11 */
446 1, /* WL12XX_CONF_HW_RXTX_RATE_9 */
447 0, /* WL12XX_CONF_HW_RXTX_RATE_6 */
448 CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL12XX_CONF_HW_RXTX_RATE_5_5 */
449 CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL12XX_CONF_HW_RXTX_RATE_2 */
450 CONF_HW_RXTX_RATE_UNSUPPORTED /* WL12XX_CONF_HW_RXTX_RATE_1 */
451};
452
453static const u8 *wl12xx_band_rate_to_idx[] = {
454 [IEEE80211_BAND_2GHZ] = wl12xx_rate_to_idx_2ghz,
455 [IEEE80211_BAND_5GHZ] = wl12xx_rate_to_idx_5ghz
456};
457
458enum wl12xx_hw_rates {
459 WL12XX_CONF_HW_RXTX_RATE_MCS7_SGI = 0,
460 WL12XX_CONF_HW_RXTX_RATE_MCS7,
461 WL12XX_CONF_HW_RXTX_RATE_MCS6,
462 WL12XX_CONF_HW_RXTX_RATE_MCS5,
463 WL12XX_CONF_HW_RXTX_RATE_MCS4,
464 WL12XX_CONF_HW_RXTX_RATE_MCS3,
465 WL12XX_CONF_HW_RXTX_RATE_MCS2,
466 WL12XX_CONF_HW_RXTX_RATE_MCS1,
467 WL12XX_CONF_HW_RXTX_RATE_MCS0,
468 WL12XX_CONF_HW_RXTX_RATE_54,
469 WL12XX_CONF_HW_RXTX_RATE_48,
470 WL12XX_CONF_HW_RXTX_RATE_36,
471 WL12XX_CONF_HW_RXTX_RATE_24,
472 WL12XX_CONF_HW_RXTX_RATE_22,
473 WL12XX_CONF_HW_RXTX_RATE_18,
474 WL12XX_CONF_HW_RXTX_RATE_12,
475 WL12XX_CONF_HW_RXTX_RATE_11,
476 WL12XX_CONF_HW_RXTX_RATE_9,
477 WL12XX_CONF_HW_RXTX_RATE_6,
478 WL12XX_CONF_HW_RXTX_RATE_5_5,
479 WL12XX_CONF_HW_RXTX_RATE_2,
480 WL12XX_CONF_HW_RXTX_RATE_1,
481 WL12XX_CONF_HW_RXTX_RATE_MAX,
482};
483
484static struct wlcore_partition_set wl12xx_ptable[PART_TABLE_LEN] = {
485 [PART_DOWN] = {
486 .mem = {
487 .start = 0x00000000,
488 .size = 0x000177c0
489 },
490 .reg = {
491 .start = REGISTERS_BASE,
492 .size = 0x00008800
493 },
494 .mem2 = {
495 .start = 0x00000000,
496 .size = 0x00000000
497 },
498 .mem3 = {
499 .start = 0x00000000,
500 .size = 0x00000000
501 },
502 },
503
504 [PART_BOOT] = { /* in wl12xx we can use a mix of work and down
505 * partition here */
506 .mem = {
507 .start = 0x00040000,
508 .size = 0x00014fc0
509 },
510 .reg = {
511 .start = REGISTERS_BASE,
512 .size = 0x00008800
513 },
514 .mem2 = {
515 .start = 0x00000000,
516 .size = 0x00000000
517 },
518 .mem3 = {
519 .start = 0x00000000,
520 .size = 0x00000000
521 },
522 },
523
524 [PART_WORK] = {
525 .mem = {
526 .start = 0x00040000,
527 .size = 0x00014fc0
528 },
529 .reg = {
530 .start = REGISTERS_BASE,
531 .size = 0x0000a000
532 },
533 .mem2 = {
534 .start = 0x003004f8,
535 .size = 0x00000004
536 },
537 .mem3 = {
538 .start = 0x00040404,
539 .size = 0x00000000
540 },
541 },
542
543 [PART_DRPW] = {
544 .mem = {
545 .start = 0x00040000,
546 .size = 0x00014fc0
547 },
548 .reg = {
549 .start = DRPW_BASE,
550 .size = 0x00006000
551 },
552 .mem2 = {
553 .start = 0x00000000,
554 .size = 0x00000000
555 },
556 .mem3 = {
557 .start = 0x00000000,
558 .size = 0x00000000
559 }
560 }
561};
562
563static const int wl12xx_rtable[REG_TABLE_LEN] = {
564 [REG_ECPU_CONTROL] = WL12XX_REG_ECPU_CONTROL,
565 [REG_INTERRUPT_NO_CLEAR] = WL12XX_REG_INTERRUPT_NO_CLEAR,
566 [REG_INTERRUPT_ACK] = WL12XX_REG_INTERRUPT_ACK,
567 [REG_COMMAND_MAILBOX_PTR] = WL12XX_REG_COMMAND_MAILBOX_PTR,
568 [REG_EVENT_MAILBOX_PTR] = WL12XX_REG_EVENT_MAILBOX_PTR,
569 [REG_INTERRUPT_TRIG] = WL12XX_REG_INTERRUPT_TRIG,
570 [REG_INTERRUPT_MASK] = WL12XX_REG_INTERRUPT_MASK,
571 [REG_PC_ON_RECOVERY] = WL12XX_SCR_PAD4,
572 [REG_CHIP_ID_B] = WL12XX_CHIP_ID_B,
573 [REG_CMD_MBOX_ADDRESS] = WL12XX_CMD_MBOX_ADDRESS,
574
575 /* data access memory addresses, used with partition translation */
576 [REG_SLV_MEM_DATA] = WL1271_SLV_MEM_DATA,
577 [REG_SLV_REG_DATA] = WL1271_SLV_REG_DATA,
578
579 /* raw data access memory addresses */
580 [REG_RAW_FW_STATUS_ADDR] = FW_STATUS_ADDR,
581};
582
583/* TODO: maybe move to a new header file? */
584#define WL127X_FW_NAME_MULTI "ti-connectivity/wl127x-fw-4-mr.bin"
585#define WL127X_FW_NAME_SINGLE "ti-connectivity/wl127x-fw-4-sr.bin"
586#define WL127X_PLT_FW_NAME "ti-connectivity/wl127x-fw-4-plt.bin"
587
588#define WL128X_FW_NAME_MULTI "ti-connectivity/wl128x-fw-4-mr.bin"
589#define WL128X_FW_NAME_SINGLE "ti-connectivity/wl128x-fw-4-sr.bin"
590#define WL128X_PLT_FW_NAME "ti-connectivity/wl128x-fw-4-plt.bin"
591
592static void wl127x_prepare_read(struct wl1271 *wl, u32 rx_desc, u32 len)
593{
594 if (wl->chip.id != CHIP_ID_1283_PG20) {
595 struct wl1271_acx_mem_map *wl_mem_map = wl->target_mem_map;
596 struct wl1271_rx_mem_pool_addr rx_mem_addr;
597
598 /*
599 * Choose the block we want to read
600 * For aggregated packets, only the first memory block
601 * should be retrieved. The FW takes care of the rest.
602 */
603 u32 mem_block = rx_desc & RX_MEM_BLOCK_MASK;
604
605 rx_mem_addr.addr = (mem_block << 8) +
606 le32_to_cpu(wl_mem_map->packet_memory_pool_start);
607
608 rx_mem_addr.addr_extra = rx_mem_addr.addr + 4;
609
610 wl1271_write(wl, WL1271_SLV_REG_DATA,
611 &rx_mem_addr, sizeof(rx_mem_addr), false);
612 }
613}
614
615static int wl12xx_identify_chip(struct wl1271 *wl)
616{
617 int ret = 0;
618
619 switch (wl->chip.id) {
620 case CHIP_ID_1271_PG10:
621 wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete",
622 wl->chip.id);
623
624 /* clear the alignment quirk, since we don't support it */
625 wl->quirks &= ~WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN;
626
627 wl->quirks |= WLCORE_QUIRK_LEGACY_NVS;
628 wl->sr_fw_name = WL127X_FW_NAME_SINGLE;
629 wl->mr_fw_name = WL127X_FW_NAME_MULTI;
630 memcpy(&wl->conf.mem, &wl12xx_default_priv_conf.mem_wl127x,
631 sizeof(wl->conf.mem));
632
633 /* read data preparation is only needed by wl127x */
634 wl->ops->prepare_read = wl127x_prepare_read;
635
636 break;
637
638 case CHIP_ID_1271_PG20:
639 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)",
640 wl->chip.id);
641
642 /* clear the alignment quirk, since we don't support it */
643 wl->quirks &= ~WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN;
644
645 wl->quirks |= WLCORE_QUIRK_LEGACY_NVS;
646 wl->plt_fw_name = WL127X_PLT_FW_NAME;
647 wl->sr_fw_name = WL127X_FW_NAME_SINGLE;
648 wl->mr_fw_name = WL127X_FW_NAME_MULTI;
649 memcpy(&wl->conf.mem, &wl12xx_default_priv_conf.mem_wl127x,
650 sizeof(wl->conf.mem));
651
652 /* read data preparation is only needed by wl127x */
653 wl->ops->prepare_read = wl127x_prepare_read;
654
655 break;
656
657 case CHIP_ID_1283_PG20:
658 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1283 PG20)",
659 wl->chip.id);
660 wl->plt_fw_name = WL128X_PLT_FW_NAME;
661 wl->sr_fw_name = WL128X_FW_NAME_SINGLE;
662 wl->mr_fw_name = WL128X_FW_NAME_MULTI;
663 break;
664 case CHIP_ID_1283_PG10:
665 default:
666 wl1271_warning("unsupported chip id: 0x%x", wl->chip.id);
667 ret = -ENODEV;
668 goto out;
669 }
670
671out:
672 return ret;
673}
674
675static void wl12xx_top_reg_write(struct wl1271 *wl, int addr, u16 val)
676{
677 /* write address >> 1 + 0x30000 to OCP_POR_CTR */
678 addr = (addr >> 1) + 0x30000;
679 wl1271_write32(wl, WL12XX_OCP_POR_CTR, addr);
680
681 /* write value to OCP_POR_WDATA */
682 wl1271_write32(wl, WL12XX_OCP_DATA_WRITE, val);
683
684 /* write 1 to OCP_CMD */
685 wl1271_write32(wl, WL12XX_OCP_CMD, OCP_CMD_WRITE);
686}
687
688static u16 wl12xx_top_reg_read(struct wl1271 *wl, int addr)
689{
690 u32 val;
691 int timeout = OCP_CMD_LOOP;
692
693 /* write address >> 1 + 0x30000 to OCP_POR_CTR */
694 addr = (addr >> 1) + 0x30000;
695 wl1271_write32(wl, WL12XX_OCP_POR_CTR, addr);
696
697 /* write 2 to OCP_CMD */
698 wl1271_write32(wl, WL12XX_OCP_CMD, OCP_CMD_READ);
699
700 /* poll for data ready */
701 do {
702 val = wl1271_read32(wl, WL12XX_OCP_DATA_READ);
703 } while (!(val & OCP_READY_MASK) && --timeout);
704
705 if (!timeout) {
706 wl1271_warning("Top register access timed out.");
707 return 0xffff;
708 }
709
710 /* check data status and return if OK */
711 if ((val & OCP_STATUS_MASK) == OCP_STATUS_OK)
712 return val & 0xffff;
713 else {
714 wl1271_warning("Top register access returned error.");
715 return 0xffff;
716 }
717}
718
719static int wl128x_switch_tcxo_to_fref(struct wl1271 *wl)
720{
721 u16 spare_reg;
722
723 /* Mask bits [2] & [8:4] in the sys_clk_cfg register */
724 spare_reg = wl12xx_top_reg_read(wl, WL_SPARE_REG);
725 if (spare_reg == 0xFFFF)
726 return -EFAULT;
727 spare_reg |= (BIT(3) | BIT(5) | BIT(6));
728 wl12xx_top_reg_write(wl, WL_SPARE_REG, spare_reg);
729
730 /* Enable FREF_CLK_REQ & mux MCS and coex PLLs to FREF */
731 wl12xx_top_reg_write(wl, SYS_CLK_CFG_REG,
732 WL_CLK_REQ_TYPE_PG2 | MCS_PLL_CLK_SEL_FREF);
733
734 /* Delay execution for 15msec, to let the HW settle */
735 mdelay(15);
736
737 return 0;
738}
739
740static bool wl128x_is_tcxo_valid(struct wl1271 *wl)
741{
742 u16 tcxo_detection;
743
744 tcxo_detection = wl12xx_top_reg_read(wl, TCXO_CLK_DETECT_REG);
745 if (tcxo_detection & TCXO_DET_FAILED)
746 return false;
747
748 return true;
749}
750
751static bool wl128x_is_fref_valid(struct wl1271 *wl)
752{
753 u16 fref_detection;
754
755 fref_detection = wl12xx_top_reg_read(wl, FREF_CLK_DETECT_REG);
756 if (fref_detection & FREF_CLK_DETECT_FAIL)
757 return false;
758
759 return true;
760}
761
762static int wl128x_manually_configure_mcs_pll(struct wl1271 *wl)
763{
764 wl12xx_top_reg_write(wl, MCS_PLL_M_REG, MCS_PLL_M_REG_VAL);
765 wl12xx_top_reg_write(wl, MCS_PLL_N_REG, MCS_PLL_N_REG_VAL);
766 wl12xx_top_reg_write(wl, MCS_PLL_CONFIG_REG, MCS_PLL_CONFIG_REG_VAL);
767
768 return 0;
769}
770
771static int wl128x_configure_mcs_pll(struct wl1271 *wl, int clk)
772{
773 u16 spare_reg;
774 u16 pll_config;
775 u8 input_freq;
776
777 /* Mask bits [3:1] in the sys_clk_cfg register */
778 spare_reg = wl12xx_top_reg_read(wl, WL_SPARE_REG);
779 if (spare_reg == 0xFFFF)
780 return -EFAULT;
781 spare_reg |= BIT(2);
782 wl12xx_top_reg_write(wl, WL_SPARE_REG, spare_reg);
783
784 /* Handle special cases of the TCXO clock */
785 if (wl->tcxo_clock == WL12XX_TCXOCLOCK_16_8 ||
786 wl->tcxo_clock == WL12XX_TCXOCLOCK_33_6)
787 return wl128x_manually_configure_mcs_pll(wl);
788
789 /* Set the input frequency according to the selected clock source */
790 input_freq = (clk & 1) + 1;
791
792 pll_config = wl12xx_top_reg_read(wl, MCS_PLL_CONFIG_REG);
793 if (pll_config == 0xFFFF)
794 return -EFAULT;
795 pll_config |= (input_freq << MCS_SEL_IN_FREQ_SHIFT);
796 pll_config |= MCS_PLL_ENABLE_HP;
797 wl12xx_top_reg_write(wl, MCS_PLL_CONFIG_REG, pll_config);
798
799 return 0;
800}
801
802/*
803 * WL128x has two clocks input - TCXO and FREF.
804 * TCXO is the main clock of the device, while FREF is used to sync
805 * between the GPS and the cellular modem.
806 * In cases where TCXO is 32.736MHz or 16.368MHz, the FREF will be used
807 * as the WLAN/BT main clock.
808 */
809static int wl128x_boot_clk(struct wl1271 *wl, int *selected_clock)
810{
811 u16 sys_clk_cfg;
812
813 /* For XTAL-only modes, FREF will be used after switching from TCXO */
814 if (wl->ref_clock == WL12XX_REFCLOCK_26_XTAL ||
815 wl->ref_clock == WL12XX_REFCLOCK_38_XTAL) {
816 if (!wl128x_switch_tcxo_to_fref(wl))
817 return -EINVAL;
818 goto fref_clk;
819 }
820
821 /* Query the HW, to determine which clock source we should use */
822 sys_clk_cfg = wl12xx_top_reg_read(wl, SYS_CLK_CFG_REG);
823 if (sys_clk_cfg == 0xFFFF)
824 return -EINVAL;
825 if (sys_clk_cfg & PRCM_CM_EN_MUX_WLAN_FREF)
826 goto fref_clk;
827
828 /* If TCXO is either 32.736MHz or 16.368MHz, switch to FREF */
829 if (wl->tcxo_clock == WL12XX_TCXOCLOCK_16_368 ||
830 wl->tcxo_clock == WL12XX_TCXOCLOCK_32_736) {
831 if (!wl128x_switch_tcxo_to_fref(wl))
832 return -EINVAL;
833 goto fref_clk;
834 }
835
836 /* TCXO clock is selected */
837 if (!wl128x_is_tcxo_valid(wl))
838 return -EINVAL;
839 *selected_clock = wl->tcxo_clock;
840 goto config_mcs_pll;
841
842fref_clk:
843 /* FREF clock is selected */
844 if (!wl128x_is_fref_valid(wl))
845 return -EINVAL;
846 *selected_clock = wl->ref_clock;
847
848config_mcs_pll:
849 return wl128x_configure_mcs_pll(wl, *selected_clock);
850}
851
852static int wl127x_boot_clk(struct wl1271 *wl)
853{
854 u32 pause;
855 u32 clk;
856
857 if (WL127X_PG_GET_MAJOR(wl->hw_pg_ver) < 3)
858 wl->quirks |= WLCORE_QUIRK_END_OF_TRANSACTION;
859
860 if (wl->ref_clock == CONF_REF_CLK_19_2_E ||
861 wl->ref_clock == CONF_REF_CLK_38_4_E ||
862 wl->ref_clock == CONF_REF_CLK_38_4_M_XTAL)
863 /* ref clk: 19.2/38.4/38.4-XTAL */
864 clk = 0x3;
865 else if (wl->ref_clock == CONF_REF_CLK_26_E ||
866 wl->ref_clock == CONF_REF_CLK_52_E)
867 /* ref clk: 26/52 */
868 clk = 0x5;
869 else
870 return -EINVAL;
871
872 if (wl->ref_clock != CONF_REF_CLK_19_2_E) {
873 u16 val;
874 /* Set clock type (open drain) */
875 val = wl12xx_top_reg_read(wl, OCP_REG_CLK_TYPE);
876 val &= FREF_CLK_TYPE_BITS;
877 wl12xx_top_reg_write(wl, OCP_REG_CLK_TYPE, val);
878
879 /* Set clock pull mode (no pull) */
880 val = wl12xx_top_reg_read(wl, OCP_REG_CLK_PULL);
881 val |= NO_PULL;
882 wl12xx_top_reg_write(wl, OCP_REG_CLK_PULL, val);
883 } else {
884 u16 val;
885 /* Set clock polarity */
886 val = wl12xx_top_reg_read(wl, OCP_REG_CLK_POLARITY);
887 val &= FREF_CLK_POLARITY_BITS;
888 val |= CLK_REQ_OUTN_SEL;
889 wl12xx_top_reg_write(wl, OCP_REG_CLK_POLARITY, val);
890 }
891
892 wl1271_write32(wl, WL12XX_PLL_PARAMETERS, clk);
893
894 pause = wl1271_read32(wl, WL12XX_PLL_PARAMETERS);
895
896 wl1271_debug(DEBUG_BOOT, "pause1 0x%x", pause);
897
898 pause &= ~(WU_COUNTER_PAUSE_VAL);
899 pause |= WU_COUNTER_PAUSE_VAL;
900 wl1271_write32(wl, WL12XX_WU_COUNTER_PAUSE, pause);
901
902 return 0;
903}
904
905static int wl1271_boot_soft_reset(struct wl1271 *wl)
906{
907 unsigned long timeout;
908 u32 boot_data;
909
910 /* perform soft reset */
911 wl1271_write32(wl, WL12XX_SLV_SOFT_RESET, ACX_SLV_SOFT_RESET_BIT);
912
913 /* SOFT_RESET is self clearing */
914 timeout = jiffies + usecs_to_jiffies(SOFT_RESET_MAX_TIME);
915 while (1) {
916 boot_data = wl1271_read32(wl, WL12XX_SLV_SOFT_RESET);
917 wl1271_debug(DEBUG_BOOT, "soft reset bootdata 0x%x", boot_data);
918 if ((boot_data & ACX_SLV_SOFT_RESET_BIT) == 0)
919 break;
920
921 if (time_after(jiffies, timeout)) {
922 /* 1.2 check pWhalBus->uSelfClearTime if the
923 * timeout was reached */
924 wl1271_error("soft reset timeout");
925 return -1;
926 }
927
928 udelay(SOFT_RESET_STALL_TIME);
929 }
930
931 /* disable Rx/Tx */
932 wl1271_write32(wl, WL12XX_ENABLE, 0x0);
933
934 /* disable auto calibration on start*/
935 wl1271_write32(wl, WL12XX_SPARE_A2, 0xffff);
936
937 return 0;
938}
939
940static int wl12xx_pre_boot(struct wl1271 *wl)
941{
942 int ret = 0;
943 u32 clk;
944 int selected_clock = -1;
945
946 if (wl->chip.id == CHIP_ID_1283_PG20) {
947 ret = wl128x_boot_clk(wl, &selected_clock);
948 if (ret < 0)
949 goto out;
950 } else {
951 ret = wl127x_boot_clk(wl);
952 if (ret < 0)
953 goto out;
954 }
955
956 /* Continue the ELP wake up sequence */
957 wl1271_write32(wl, WL12XX_WELP_ARM_COMMAND, WELP_ARM_COMMAND_VAL);
958 udelay(500);
959
960 wlcore_set_partition(wl, &wl->ptable[PART_DRPW]);
961
962 /* Read-modify-write DRPW_SCRATCH_START register (see next state)
963 to be used by DRPw FW. The RTRIM value will be added by the FW
964 before taking DRPw out of reset */
965
966 clk = wl1271_read32(wl, WL12XX_DRPW_SCRATCH_START);
967
968 wl1271_debug(DEBUG_BOOT, "clk2 0x%x", clk);
969
970 if (wl->chip.id == CHIP_ID_1283_PG20)
971 clk |= ((selected_clock & 0x3) << 1) << 4;
972 else
973 clk |= (wl->ref_clock << 1) << 4;
974
975 wl1271_write32(wl, WL12XX_DRPW_SCRATCH_START, clk);
976
977 wlcore_set_partition(wl, &wl->ptable[PART_WORK]);
978
979 /* Disable interrupts */
980 wlcore_write_reg(wl, REG_INTERRUPT_MASK, WL1271_ACX_INTR_ALL);
981
982 ret = wl1271_boot_soft_reset(wl);
983 if (ret < 0)
984 goto out;
985
986out:
987 return ret;
988}
989
990static void wl12xx_pre_upload(struct wl1271 *wl)
991{
992 u32 tmp;
993
994 /* write firmware's last address (ie. it's length) to
995 * ACX_EEPROMLESS_IND_REG */
996 wl1271_debug(DEBUG_BOOT, "ACX_EEPROMLESS_IND_REG");
997
998 wl1271_write32(wl, WL12XX_EEPROMLESS_IND, WL12XX_EEPROMLESS_IND);
999
1000 tmp = wlcore_read_reg(wl, REG_CHIP_ID_B);
1001
1002 wl1271_debug(DEBUG_BOOT, "chip id 0x%x", tmp);
1003
1004 /* 6. read the EEPROM parameters */
1005 tmp = wl1271_read32(wl, WL12XX_SCR_PAD2);
1006
1007 /* WL1271: The reference driver skips steps 7 to 10 (jumps directly
1008 * to upload_fw) */
1009
1010 if (wl->chip.id == CHIP_ID_1283_PG20)
1011 wl12xx_top_reg_write(wl, SDIO_IO_DS, HCI_IO_DS_6MA);
1012}
1013
1014static void wl12xx_enable_interrupts(struct wl1271 *wl)
1015{
1016 u32 polarity;
1017
1018 polarity = wl12xx_top_reg_read(wl, OCP_REG_POLARITY);
1019
1020 /* We use HIGH polarity, so unset the LOW bit */
1021 polarity &= ~POLARITY_LOW;
1022 wl12xx_top_reg_write(wl, OCP_REG_POLARITY, polarity);
1023
1024 wlcore_write_reg(wl, REG_INTERRUPT_MASK, WL1271_ACX_ALL_EVENTS_VECTOR);
1025
1026 wlcore_enable_interrupts(wl);
1027 wlcore_write_reg(wl, REG_INTERRUPT_MASK,
1028 WL1271_ACX_INTR_ALL & ~(WL1271_INTR_MASK));
1029
1030 wl1271_write32(wl, WL12XX_HI_CFG, HI_CFG_DEF_VAL);
1031}
1032
1033static int wl12xx_boot(struct wl1271 *wl)
1034{
1035 int ret;
1036
1037 ret = wl12xx_pre_boot(wl);
1038 if (ret < 0)
1039 goto out;
1040
1041 ret = wlcore_boot_upload_nvs(wl);
1042 if (ret < 0)
1043 goto out;
1044
1045 wl12xx_pre_upload(wl);
1046
1047 ret = wlcore_boot_upload_firmware(wl);
1048 if (ret < 0)
1049 goto out;
1050
1051 ret = wlcore_boot_run_firmware(wl);
1052 if (ret < 0)
1053 goto out;
1054
1055 wl12xx_enable_interrupts(wl);
1056
1057out:
1058 return ret;
1059}
1060
1061static void wl12xx_trigger_cmd(struct wl1271 *wl, int cmd_box_addr,
1062 void *buf, size_t len)
1063{
1064 wl1271_write(wl, cmd_box_addr, buf, len, false);
1065 wlcore_write_reg(wl, REG_INTERRUPT_TRIG, WL12XX_INTR_TRIG_CMD);
1066}
1067
1068static void wl12xx_ack_event(struct wl1271 *wl)
1069{
1070 wlcore_write_reg(wl, REG_INTERRUPT_TRIG, WL12XX_INTR_TRIG_EVENT_ACK);
1071}
1072
1073static u32 wl12xx_calc_tx_blocks(struct wl1271 *wl, u32 len, u32 spare_blks)
1074{
1075 u32 blk_size = WL12XX_TX_HW_BLOCK_SIZE;
1076 u32 align_len = wlcore_calc_packet_alignment(wl, len);
1077
1078 return (align_len + blk_size - 1) / blk_size + spare_blks;
1079}
1080
1081static void
1082wl12xx_set_tx_desc_blocks(struct wl1271 *wl, struct wl1271_tx_hw_descr *desc,
1083 u32 blks, u32 spare_blks)
1084{
1085 if (wl->chip.id == CHIP_ID_1283_PG20) {
1086 desc->wl128x_mem.total_mem_blocks = blks;
1087 } else {
1088 desc->wl127x_mem.extra_blocks = spare_blks;
1089 desc->wl127x_mem.total_mem_blocks = blks;
1090 }
1091}
1092
1093static void
1094wl12xx_set_tx_desc_data_len(struct wl1271 *wl, struct wl1271_tx_hw_descr *desc,
1095 struct sk_buff *skb)
1096{
1097 u32 aligned_len = wlcore_calc_packet_alignment(wl, skb->len);
1098
1099 if (wl->chip.id == CHIP_ID_1283_PG20) {
1100 desc->wl128x_mem.extra_bytes = aligned_len - skb->len;
1101 desc->length = cpu_to_le16(aligned_len >> 2);
1102
1103 wl1271_debug(DEBUG_TX,
1104 "tx_fill_hdr: hlid: %d len: %d life: %d mem: %d extra: %d",
1105 desc->hlid,
1106 le16_to_cpu(desc->length),
1107 le16_to_cpu(desc->life_time),
1108 desc->wl128x_mem.total_mem_blocks,
1109 desc->wl128x_mem.extra_bytes);
1110 } else {
1111 /* calculate number of padding bytes */
1112 int pad = aligned_len - skb->len;
1113 desc->tx_attr |=
1114 cpu_to_le16(pad << TX_HW_ATTR_OFST_LAST_WORD_PAD);
1115
1116 /* Store the aligned length in terms of words */
1117 desc->length = cpu_to_le16(aligned_len >> 2);
1118
1119 wl1271_debug(DEBUG_TX,
1120 "tx_fill_hdr: pad: %d hlid: %d len: %d life: %d mem: %d",
1121 pad, desc->hlid,
1122 le16_to_cpu(desc->length),
1123 le16_to_cpu(desc->life_time),
1124 desc->wl127x_mem.total_mem_blocks);
1125 }
1126}
1127
1128static enum wl_rx_buf_align
1129wl12xx_get_rx_buf_align(struct wl1271 *wl, u32 rx_desc)
1130{
1131 if (rx_desc & RX_BUF_UNALIGNED_PAYLOAD)
1132 return WLCORE_RX_BUF_UNALIGNED;
1133
1134 return WLCORE_RX_BUF_ALIGNED;
1135}
1136
1137static u32 wl12xx_get_rx_packet_len(struct wl1271 *wl, void *rx_data,
1138 u32 data_len)
1139{
1140 struct wl1271_rx_descriptor *desc = rx_data;
1141
1142 /* invalid packet */
1143 if (data_len < sizeof(*desc) ||
1144 data_len < sizeof(*desc) + desc->pad_len)
1145 return 0;
1146
1147 return data_len - sizeof(*desc) - desc->pad_len;
1148}
1149
1150static void wl12xx_tx_delayed_compl(struct wl1271 *wl)
1151{
1152 if (wl->fw_status->tx_results_counter == (wl->tx_results_count & 0xff))
1153 return;
1154
1155 wl1271_tx_complete(wl);
1156}
1157
1158static int wl12xx_hw_init(struct wl1271 *wl)
1159{
1160 int ret;
1161
1162 if (wl->chip.id == CHIP_ID_1283_PG20) {
1163 u32 host_cfg_bitmap = HOST_IF_CFG_RX_FIFO_ENABLE;
1164
1165 ret = wl128x_cmd_general_parms(wl);
1166 if (ret < 0)
1167 goto out;
1168 ret = wl128x_cmd_radio_parms(wl);
1169 if (ret < 0)
1170 goto out;
1171
1172 if (wl->quirks & WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN)
1173 /* Enable SDIO padding */
1174 host_cfg_bitmap |= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK;
1175
1176 /* Must be before wl1271_acx_init_mem_config() */
1177 ret = wl1271_acx_host_if_cfg_bitmap(wl, host_cfg_bitmap);
1178 if (ret < 0)
1179 goto out;
1180 } else {
1181 ret = wl1271_cmd_general_parms(wl);
1182 if (ret < 0)
1183 goto out;
1184 ret = wl1271_cmd_radio_parms(wl);
1185 if (ret < 0)
1186 goto out;
1187 ret = wl1271_cmd_ext_radio_parms(wl);
1188 if (ret < 0)
1189 goto out;
1190 }
1191out:
1192 return ret;
1193}
1194
1195static u32 wl12xx_sta_get_ap_rate_mask(struct wl1271 *wl,
1196 struct wl12xx_vif *wlvif)
1197{
1198 return wlvif->rate_set;
1199}
1200
1201static int wl12xx_identify_fw(struct wl1271 *wl)
1202{
1203 unsigned int *fw_ver = wl->chip.fw_ver;
1204
1205 /* Only new station firmwares support routing fw logs to the host */
1206 if ((fw_ver[FW_VER_IF_TYPE] == FW_VER_IF_TYPE_STA) &&
1207 (fw_ver[FW_VER_MINOR] < FW_VER_MINOR_FWLOG_STA_MIN))
1208 wl->quirks |= WLCORE_QUIRK_FWLOG_NOT_IMPLEMENTED;
1209
1210 /* This feature is not yet supported for AP mode */
1211 if (fw_ver[FW_VER_IF_TYPE] == FW_VER_IF_TYPE_AP)
1212 wl->quirks |= WLCORE_QUIRK_FWLOG_NOT_IMPLEMENTED;
1213
1214 return 0;
1215}
1216
1217static void wl12xx_conf_init(struct wl1271 *wl)
1218{
1219 struct wl12xx_priv *priv = wl->priv;
1220
1221 /* apply driver default configuration */
1222 memcpy(&wl->conf, &wl12xx_conf, sizeof(wl12xx_conf));
1223
1224 /* apply default private configuration */
1225 memcpy(&priv->conf, &wl12xx_default_priv_conf, sizeof(priv->conf));
1226}
1227
1228static bool wl12xx_mac_in_fuse(struct wl1271 *wl)
1229{
1230 bool supported = false;
1231 u8 major, minor;
1232
1233 if (wl->chip.id == CHIP_ID_1283_PG20) {
1234 major = WL128X_PG_GET_MAJOR(wl->hw_pg_ver);
1235 minor = WL128X_PG_GET_MINOR(wl->hw_pg_ver);
1236
1237 /* in wl128x we have the MAC address if the PG is >= (2, 1) */
1238 if (major > 2 || (major == 2 && minor >= 1))
1239 supported = true;
1240 } else {
1241 major = WL127X_PG_GET_MAJOR(wl->hw_pg_ver);
1242 minor = WL127X_PG_GET_MINOR(wl->hw_pg_ver);
1243
1244 /* in wl127x we have the MAC address if the PG is >= (3, 1) */
1245 if (major == 3 && minor >= 1)
1246 supported = true;
1247 }
1248
1249 wl1271_debug(DEBUG_PROBE,
1250 "PG Ver major = %d minor = %d, MAC %s present",
1251 major, minor, supported ? "is" : "is not");
1252
1253 return supported;
1254}
1255
1256static void wl12xx_get_fuse_mac(struct wl1271 *wl)
1257{
1258 u32 mac1, mac2;
1259
1260 wlcore_set_partition(wl, &wl->ptable[PART_DRPW]);
1261
1262 mac1 = wl1271_read32(wl, WL12XX_REG_FUSE_BD_ADDR_1);
1263 mac2 = wl1271_read32(wl, WL12XX_REG_FUSE_BD_ADDR_2);
1264
1265 /* these are the two parts of the BD_ADDR */
1266 wl->fuse_oui_addr = ((mac2 & 0xffff) << 8) +
1267 ((mac1 & 0xff000000) >> 24);
1268 wl->fuse_nic_addr = mac1 & 0xffffff;
1269
1270 wlcore_set_partition(wl, &wl->ptable[PART_DOWN]);
1271}
1272
1273static s8 wl12xx_get_pg_ver(struct wl1271 *wl)
1274{
1275 u32 die_info;
1276
1277 if (wl->chip.id == CHIP_ID_1283_PG20)
1278 die_info = wl12xx_top_reg_read(wl, WL128X_REG_FUSE_DATA_2_1);
1279 else
1280 die_info = wl12xx_top_reg_read(wl, WL127X_REG_FUSE_DATA_2_1);
1281
1282 return (s8) (die_info & PG_VER_MASK) >> PG_VER_OFFSET;
1283}
1284
1285static void wl12xx_get_mac(struct wl1271 *wl)
1286{
1287 if (wl12xx_mac_in_fuse(wl))
1288 wl12xx_get_fuse_mac(wl);
1289}
1290
1291static struct wlcore_ops wl12xx_ops = {
1292 .identify_chip = wl12xx_identify_chip,
1293 .identify_fw = wl12xx_identify_fw,
1294 .boot = wl12xx_boot,
1295 .trigger_cmd = wl12xx_trigger_cmd,
1296 .ack_event = wl12xx_ack_event,
1297 .calc_tx_blocks = wl12xx_calc_tx_blocks,
1298 .set_tx_desc_blocks = wl12xx_set_tx_desc_blocks,
1299 .set_tx_desc_data_len = wl12xx_set_tx_desc_data_len,
1300 .get_rx_buf_align = wl12xx_get_rx_buf_align,
1301 .get_rx_packet_len = wl12xx_get_rx_packet_len,
1302 .tx_immediate_compl = NULL,
1303 .tx_delayed_compl = wl12xx_tx_delayed_compl,
1304 .hw_init = wl12xx_hw_init,
1305 .init_vif = NULL,
1306 .sta_get_ap_rate_mask = wl12xx_sta_get_ap_rate_mask,
1307 .get_pg_ver = wl12xx_get_pg_ver,
1308 .get_mac = wl12xx_get_mac,
1309};
1310
1311static struct ieee80211_sta_ht_cap wl12xx_ht_cap = {
1312 .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 |
1313 (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT),
1314 .ht_supported = true,
1315 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K,
1316 .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8,
1317 .mcs = {
1318 .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
1319 .rx_highest = cpu_to_le16(72),
1320 .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
1321 },
1322};
1323
1324static int __devinit wl12xx_probe(struct platform_device *pdev)
1325{
1326 struct wl1271 *wl;
1327 struct ieee80211_hw *hw;
1328 struct wl12xx_priv *priv;
1329
1330 hw = wlcore_alloc_hw(sizeof(*priv));
1331 if (IS_ERR(hw)) {
1332 wl1271_error("can't allocate hw");
1333 return PTR_ERR(hw);
1334 }
1335
1336 wl = hw->priv;
1337 wl->ops = &wl12xx_ops;
1338 wl->ptable = wl12xx_ptable;
1339 wl->rtable = wl12xx_rtable;
1340 wl->num_tx_desc = 16;
1341 wl->normal_tx_spare = WL12XX_TX_HW_BLOCK_SPARE_DEFAULT;
1342 wl->gem_tx_spare = WL12XX_TX_HW_BLOCK_GEM_SPARE;
1343 wl->band_rate_to_idx = wl12xx_band_rate_to_idx;
1344 wl->hw_tx_rate_tbl_size = WL12XX_CONF_HW_RXTX_RATE_MAX;
1345 wl->hw_min_ht_rate = WL12XX_CONF_HW_RXTX_RATE_MCS0;
1346 wl->fw_status_priv_len = 0;
1347 memcpy(&wl->ht_cap, &wl12xx_ht_cap, sizeof(wl12xx_ht_cap));
1348 wl12xx_conf_init(wl);
1349
1350 return wlcore_probe(wl, pdev);
1351}
1352
1353static const struct platform_device_id wl12xx_id_table[] __devinitconst = {
1354 { "wl12xx", 0 },
1355 { } /* Terminating Entry */
1356};
1357MODULE_DEVICE_TABLE(platform, wl12xx_id_table);
1358
1359static struct platform_driver wl12xx_driver = {
1360 .probe = wl12xx_probe,
1361 .remove = __devexit_p(wlcore_remove),
1362 .id_table = wl12xx_id_table,
1363 .driver = {
1364 .name = "wl12xx_driver",
1365 .owner = THIS_MODULE,
1366 }
1367};
1368
1369static int __init wl12xx_init(void)
1370{
1371 return platform_driver_register(&wl12xx_driver);
1372}
1373module_init(wl12xx_init);
1374
1375static void __exit wl12xx_exit(void)
1376{
1377 platform_driver_unregister(&wl12xx_driver);
1378}
1379module_exit(wl12xx_exit);
1380
1381MODULE_LICENSE("GPL v2");
1382MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
1383MODULE_FIRMWARE(WL127X_FW_NAME_SINGLE);
1384MODULE_FIRMWARE(WL127X_FW_NAME_MULTI);
1385MODULE_FIRMWARE(WL127X_PLT_FW_NAME);
1386MODULE_FIRMWARE(WL128X_FW_NAME_SINGLE);
1387MODULE_FIRMWARE(WL128X_FW_NAME_MULTI);
1388MODULE_FIRMWARE(WL128X_PLT_FW_NAME);
diff --git a/drivers/net/wireless/ti/wl12xx/reg.h b/drivers/net/wireless/ti/wl12xx/reg.h
new file mode 100644
index 000000000000..79ede02e2587
--- /dev/null
+++ b/drivers/net/wireless/ti/wl12xx/reg.h
@@ -0,0 +1,556 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
5 * Copyright (C) 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 __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 FW_STATUS_ADDR (0x14FC0 + 0xA000)
37
38/*===============================================
39 Host Software Reset - 32bit RW
40 ------------------------------------------
41 [31:1] Reserved
42 0 SOFT_RESET Soft Reset - When this bit is set,
43 it holds the Wlan hardware in a soft reset state.
44 This reset disables all MAC and baseband processor
45 clocks except the CardBus/PCI interface clock.
46 It also initializes all MAC state machines except
47 the host interface. It does not reload the
48 contents of the EEPROM. When this bit is cleared
49 (not self-clearing), the Wlan hardware
50 exits the software reset state.
51===============================================*/
52#define WL12XX_SLV_SOFT_RESET (REGISTERS_BASE + 0x0000)
53
54#define WL1271_SLV_REG_DATA (REGISTERS_BASE + 0x0008)
55#define WL1271_SLV_REG_ADATA (REGISTERS_BASE + 0x000c)
56#define WL1271_SLV_MEM_DATA (REGISTERS_BASE + 0x0018)
57
58#define WL12XX_REG_INTERRUPT_TRIG (REGISTERS_BASE + 0x0474)
59#define WL12XX_REG_INTERRUPT_TRIG_H (REGISTERS_BASE + 0x0478)
60
61/*=============================================
62 Host Interrupt Mask Register - 32bit (RW)
63 ------------------------------------------
64 Setting a bit in this register masks the
65 corresponding interrupt to the host.
66 0 - RX0 - Rx first dubble buffer Data Interrupt
67 1 - TXD - Tx Data Interrupt
68 2 - TXXFR - Tx Transfer Interrupt
69 3 - RX1 - Rx second dubble buffer Data Interrupt
70 4 - RXXFR - Rx Transfer Interrupt
71 5 - EVENT_A - Event Mailbox interrupt
72 6 - EVENT_B - Event Mailbox interrupt
73 7 - WNONHST - Wake On Host Interrupt
74 8 - TRACE_A - Debug Trace interrupt
75 9 - TRACE_B - Debug Trace interrupt
76 10 - CDCMP - Command Complete Interrupt
77 11 -
78 12 -
79 13 -
80 14 - ICOMP - Initialization Complete Interrupt
81 16 - SG SE - Soft Gemini - Sense enable interrupt
82 17 - SG SD - Soft Gemini - Sense disable interrupt
83 18 - -
84 19 - -
85 20 - -
86 21- -
87 Default: 0x0001
88*==============================================*/
89#define WL12XX_REG_INTERRUPT_MASK (REGISTERS_BASE + 0x04DC)
90
91/*=============================================
92 Host Interrupt Mask Set 16bit, (Write only)
93 ------------------------------------------
94 Setting a bit in this register sets
95 the corresponding bin in ACX_HINT_MASK register
96 without effecting the mask
97 state of other bits (0 = no effect).
98==============================================*/
99#define ACX_REG_HINT_MASK_SET (REGISTERS_BASE + 0x04E0)
100
101/*=============================================
102 Host Interrupt Mask Clear 16bit,(Write only)
103 ------------------------------------------
104 Setting a bit in this register clears
105 the corresponding bin in ACX_HINT_MASK register
106 without effecting the mask
107 state of other bits (0 = no effect).
108=============================================*/
109#define ACX_REG_HINT_MASK_CLR (REGISTERS_BASE + 0x04E4)
110
111/*=============================================
112 Host Interrupt Status Nondestructive Read
113 16bit,(Read only)
114 ------------------------------------------
115 The host can read this register to determine
116 which interrupts are active.
117 Reading this register doesn't
118 effect its content.
119=============================================*/
120#define WL12XX_REG_INTERRUPT_NO_CLEAR (REGISTERS_BASE + 0x04E8)
121
122/*=============================================
123 Host Interrupt Status Clear on Read Register
124 16bit,(Read only)
125 ------------------------------------------
126 The host can read this register to determine
127 which interrupts are active.
128 Reading this register clears it,
129 thus making all interrupts inactive.
130==============================================*/
131#define ACX_REG_INTERRUPT_CLEAR (REGISTERS_BASE + 0x04F8)
132
133/*=============================================
134 Host Interrupt Acknowledge Register
135 16bit,(Write only)
136 ------------------------------------------
137 The host can set individual bits in this
138 register to clear (acknowledge) the corresp.
139 interrupt status bits in the HINT_STS_CLR and
140 HINT_STS_ND registers, thus making the
141 assotiated interrupt inactive. (0-no effect)
142==============================================*/
143#define WL12XX_REG_INTERRUPT_ACK (REGISTERS_BASE + 0x04F0)
144
145#define WL12XX_REG_RX_DRIVER_COUNTER (REGISTERS_BASE + 0x0538)
146
147/* Device Configuration registers*/
148#define SOR_CFG (REGISTERS_BASE + 0x0800)
149
150/* Embedded ARM CPU Control */
151
152/*===============================================
153 Halt eCPU - 32bit RW
154 ------------------------------------------
155 0 HALT_ECPU Halt Embedded CPU - This bit is the
156 compliment of bit 1 (MDATA2) in the SOR_CFG register.
157 During a hardware reset, this bit holds
158 the inverse of MDATA2.
159 When downloading firmware from the host,
160 set this bit (pull down MDATA2).
161 The host clears this bit after downloading the firmware into
162 zero-wait-state SSRAM.
163 When loading firmware from Flash, clear this bit (pull up MDATA2)
164 so that the eCPU can run the bootloader code in Flash
165 HALT_ECPU eCPU State
166 --------------------
167 1 halt eCPU
168 0 enable eCPU
169 ===============================================*/
170#define WL12XX_REG_ECPU_CONTROL (REGISTERS_BASE + 0x0804)
171
172#define WL12XX_HI_CFG (REGISTERS_BASE + 0x0808)
173
174/*===============================================
175 EEPROM Burst Read Start - 32bit RW
176 ------------------------------------------
177 [31:1] Reserved
178 0 ACX_EE_START - EEPROM Burst Read Start 0
179 Setting this bit starts a burst read from
180 the external EEPROM.
181 If this bit is set (after reset) before an EEPROM read/write,
182 the burst read starts at EEPROM address 0.
183 Otherwise, it starts at the address
184 following the address of the previous access.
185 TheWlan hardware hardware clears this bit automatically.
186
187 Default: 0x00000000
188*================================================*/
189#define ACX_REG_EE_START (REGISTERS_BASE + 0x080C)
190
191#define WL12XX_OCP_POR_CTR (REGISTERS_BASE + 0x09B4)
192#define WL12XX_OCP_DATA_WRITE (REGISTERS_BASE + 0x09B8)
193#define WL12XX_OCP_DATA_READ (REGISTERS_BASE + 0x09BC)
194#define WL12XX_OCP_CMD (REGISTERS_BASE + 0x09C0)
195
196#define WL12XX_HOST_WR_ACCESS (REGISTERS_BASE + 0x09F8)
197
198#define WL12XX_CHIP_ID_B (REGISTERS_BASE + 0x5674)
199
200#define WL12XX_ENABLE (REGISTERS_BASE + 0x5450)
201
202/* Power Management registers */
203#define WL12XX_ELP_CFG_MODE (REGISTERS_BASE + 0x5804)
204#define WL12XX_ELP_CMD (REGISTERS_BASE + 0x5808)
205#define WL12XX_PLL_CAL_TIME (REGISTERS_BASE + 0x5810)
206#define WL12XX_CLK_REQ_TIME (REGISTERS_BASE + 0x5814)
207#define WL12XX_CLK_BUF_TIME (REGISTERS_BASE + 0x5818)
208
209#define WL12XX_CFG_PLL_SYNC_CNT (REGISTERS_BASE + 0x5820)
210
211/* Scratch Pad registers*/
212#define WL12XX_SCR_PAD0 (REGISTERS_BASE + 0x5608)
213#define WL12XX_SCR_PAD1 (REGISTERS_BASE + 0x560C)
214#define WL12XX_SCR_PAD2 (REGISTERS_BASE + 0x5610)
215#define WL12XX_SCR_PAD3 (REGISTERS_BASE + 0x5614)
216#define WL12XX_SCR_PAD4 (REGISTERS_BASE + 0x5618)
217#define WL12XX_SCR_PAD4_SET (REGISTERS_BASE + 0x561C)
218#define WL12XX_SCR_PAD4_CLR (REGISTERS_BASE + 0x5620)
219#define WL12XX_SCR_PAD5 (REGISTERS_BASE + 0x5624)
220#define WL12XX_SCR_PAD5_SET (REGISTERS_BASE + 0x5628)
221#define WL12XX_SCR_PAD5_CLR (REGISTERS_BASE + 0x562C)
222#define WL12XX_SCR_PAD6 (REGISTERS_BASE + 0x5630)
223#define WL12XX_SCR_PAD7 (REGISTERS_BASE + 0x5634)
224#define WL12XX_SCR_PAD8 (REGISTERS_BASE + 0x5638)
225#define WL12XX_SCR_PAD9 (REGISTERS_BASE + 0x563C)
226
227/* Spare registers*/
228#define WL12XX_SPARE_A1 (REGISTERS_BASE + 0x0994)
229#define WL12XX_SPARE_A2 (REGISTERS_BASE + 0x0998)
230#define WL12XX_SPARE_A3 (REGISTERS_BASE + 0x099C)
231#define WL12XX_SPARE_A4 (REGISTERS_BASE + 0x09A0)
232#define WL12XX_SPARE_A5 (REGISTERS_BASE + 0x09A4)
233#define WL12XX_SPARE_A6 (REGISTERS_BASE + 0x09A8)
234#define WL12XX_SPARE_A7 (REGISTERS_BASE + 0x09AC)
235#define WL12XX_SPARE_A8 (REGISTERS_BASE + 0x09B0)
236#define WL12XX_SPARE_B1 (REGISTERS_BASE + 0x5420)
237#define WL12XX_SPARE_B2 (REGISTERS_BASE + 0x5424)
238#define WL12XX_SPARE_B3 (REGISTERS_BASE + 0x5428)
239#define WL12XX_SPARE_B4 (REGISTERS_BASE + 0x542C)
240#define WL12XX_SPARE_B5 (REGISTERS_BASE + 0x5430)
241#define WL12XX_SPARE_B6 (REGISTERS_BASE + 0x5434)
242#define WL12XX_SPARE_B7 (REGISTERS_BASE + 0x5438)
243#define WL12XX_SPARE_B8 (REGISTERS_BASE + 0x543C)
244
245#define WL12XX_PLL_PARAMETERS (REGISTERS_BASE + 0x6040)
246#define WL12XX_WU_COUNTER_PAUSE (REGISTERS_BASE + 0x6008)
247#define WL12XX_WELP_ARM_COMMAND (REGISTERS_BASE + 0x6100)
248#define WL12XX_DRPW_SCRATCH_START (DRPW_BASE + 0x002C)
249
250#define WL12XX_CMD_MBOX_ADDRESS 0x407B4
251
252#define ACX_REG_EEPROM_START_BIT BIT(1)
253
254/* Command/Information Mailbox Pointers */
255
256/*===============================================
257 Command Mailbox Pointer - 32bit RW
258 ------------------------------------------
259 This register holds the start address of
260 the command mailbox located in the Wlan hardware memory.
261 The host must read this pointer after a reset to
262 find the location of the command mailbox.
263 The Wlan hardware initializes the command mailbox
264 pointer with the default address of the command mailbox.
265 The command mailbox pointer is not valid until after
266 the host receives the Init Complete interrupt from
267 the Wlan hardware.
268 ===============================================*/
269#define WL12XX_REG_COMMAND_MAILBOX_PTR (WL12XX_SCR_PAD0)
270
271/*===============================================
272 Information Mailbox Pointer - 32bit RW
273 ------------------------------------------
274 This register holds the start address of
275 the information mailbox located in the Wlan hardware memory.
276 The host must read this pointer after a reset to find
277 the location of the information mailbox.
278 The Wlan hardware initializes the information mailbox pointer
279 with the default address of the information mailbox.
280 The information mailbox pointer is not valid
281 until after the host receives the Init Complete interrupt from
282 the Wlan hardware.
283 ===============================================*/
284#define WL12XX_REG_EVENT_MAILBOX_PTR (WL12XX_SCR_PAD1)
285
286/*===============================================
287 EEPROM Read/Write Request 32bit RW
288 ------------------------------------------
289 1 EE_READ - EEPROM Read Request 1 - Setting this bit
290 loads a single byte of data into the EE_DATA
291 register from the EEPROM location specified in
292 the EE_ADDR register.
293 The Wlan hardware hardware clears this bit automatically.
294 EE_DATA is valid when this bit is cleared.
295
296 0 EE_WRITE - EEPROM Write Request - Setting this bit
297 writes a single byte of data from the EE_DATA register into the
298 EEPROM location specified in the EE_ADDR register.
299 The Wlan hardware hardware clears this bit automatically.
300*===============================================*/
301#define ACX_EE_CTL_REG EE_CTL
302#define EE_WRITE 0x00000001ul
303#define EE_READ 0x00000002ul
304
305/*===============================================
306 EEPROM Address - 32bit RW
307 ------------------------------------------
308 This register specifies the address
309 within the EEPROM from/to which to read/write data.
310 ===============================================*/
311#define ACX_EE_ADDR_REG EE_ADDR
312
313/*===============================================
314 EEPROM Data - 32bit RW
315 ------------------------------------------
316 This register either holds the read 8 bits of
317 data from the EEPROM or the write data
318 to be written to the EEPROM.
319 ===============================================*/
320#define ACX_EE_DATA_REG EE_DATA
321
322/*===============================================
323 EEPROM Base Address - 32bit RW
324 ------------------------------------------
325 This register holds the upper nine bits
326 [23:15] of the 24-bit Wlan hardware memory
327 address for burst reads from EEPROM accesses.
328 The EEPROM provides the lower 15 bits of this address.
329 The MSB of the address from the EEPROM is ignored.
330 ===============================================*/
331#define ACX_EE_CFG EE_CFG
332
333/*===============================================
334 GPIO Output Values -32bit, RW
335 ------------------------------------------
336 [31:16] Reserved
337 [15: 0] Specify the output values (at the output driver inputs) for
338 GPIO[15:0], respectively.
339 ===============================================*/
340#define ACX_GPIO_OUT_REG GPIO_OUT
341#define ACX_MAX_GPIO_LINES 15
342
343/*===============================================
344 Contention window -32bit, RW
345 ------------------------------------------
346 [31:26] Reserved
347 [25:16] Max (0x3ff)
348 [15:07] Reserved
349 [06:00] Current contention window value - default is 0x1F
350 ===============================================*/
351#define ACX_CONT_WIND_CFG_REG CONT_WIND_CFG
352#define ACX_CONT_WIND_MIN_MASK 0x0000007f
353#define ACX_CONT_WIND_MAX 0x03ff0000
354
355#define REF_FREQ_19_2 0
356#define REF_FREQ_26_0 1
357#define REF_FREQ_38_4 2
358#define REF_FREQ_40_0 3
359#define REF_FREQ_33_6 4
360#define REF_FREQ_NUM 5
361
362#define LUT_PARAM_INTEGER_DIVIDER 0
363#define LUT_PARAM_FRACTIONAL_DIVIDER 1
364#define LUT_PARAM_ATTN_BB 2
365#define LUT_PARAM_ALPHA_BB 3
366#define LUT_PARAM_STOP_TIME_BB 4
367#define LUT_PARAM_BB_PLL_LOOP_FILTER 5
368#define LUT_PARAM_NUM 6
369
370#define WL12XX_EEPROMLESS_IND (WL12XX_SCR_PAD4)
371#define USE_EEPROM 0
372#define NVS_DATA_BUNDARY_ALIGNMENT 4
373
374/* Firmware image header size */
375#define FW_HDR_SIZE 8
376
377/******************************************************************************
378
379 CHANNELS, BAND & REG DOMAINS definitions
380
381******************************************************************************/
382
383#define SHORT_PREAMBLE_BIT BIT(0) /* CCK or Barker depending on the rate */
384#define OFDM_RATE_BIT BIT(6)
385#define PBCC_RATE_BIT BIT(7)
386
387enum {
388 CCK_LONG = 0,
389 CCK_SHORT = SHORT_PREAMBLE_BIT,
390 PBCC_LONG = PBCC_RATE_BIT,
391 PBCC_SHORT = PBCC_RATE_BIT | SHORT_PREAMBLE_BIT,
392 OFDM = OFDM_RATE_BIT
393};
394
395/******************************************************************************
396
397Transmit-Descriptor RATE-SET field definitions...
398
399Define a new "Rate-Set" for TX path that incorporates the
400Rate & Modulation info into a single 16-bit field.
401
402TxdRateSet_t:
403b15 - Indicates Preamble type (1=SHORT, 0=LONG).
404 Notes:
405 Must be LONG (0) for 1Mbps rate.
406 Does not apply (set to 0) for RevG-OFDM rates.
407b14 - Indicates PBCC encoding (1=PBCC, 0=not).
408 Notes:
409 Does not apply (set to 0) for rates 1 and 2 Mbps.
410 Does not apply (set to 0) for RevG-OFDM rates.
411b13 - Unused (set to 0).
412b12-b0 - Supported Rate indicator bits as defined below.
413
414******************************************************************************/
415
416#define OCP_CMD_LOOP 32
417#define OCP_CMD_WRITE 0x1
418#define OCP_CMD_READ 0x2
419#define OCP_READY_MASK BIT(18)
420#define OCP_STATUS_MASK (BIT(16) | BIT(17))
421#define OCP_STATUS_NO_RESP 0x00000
422#define OCP_STATUS_OK 0x10000
423#define OCP_STATUS_REQ_FAILED 0x20000
424#define OCP_STATUS_RESP_ERROR 0x30000
425
426#define OCP_REG_POLARITY 0x0064
427#define OCP_REG_CLK_TYPE 0x0448
428#define OCP_REG_CLK_POLARITY 0x0cb2
429#define OCP_REG_CLK_PULL 0x0cb4
430
431#define POLARITY_LOW BIT(1)
432#define NO_PULL (BIT(14) | BIT(15))
433
434#define FREF_CLK_TYPE_BITS 0xfffffe7f
435#define CLK_REQ_PRCM 0x100
436#define FREF_CLK_POLARITY_BITS 0xfffff8ff
437#define CLK_REQ_OUTN_SEL 0x700
438
439#define WU_COUNTER_PAUSE_VAL 0x3FF
440
441/* PLL configuration algorithm for wl128x */
442#define SYS_CLK_CFG_REG 0x2200
443/* Bit[0] - 0-TCXO, 1-FREF */
444#define MCS_PLL_CLK_SEL_FREF BIT(0)
445/* Bit[3:2] - 01-TCXO, 10-FREF */
446#define WL_CLK_REQ_TYPE_FREF BIT(3)
447#define WL_CLK_REQ_TYPE_PG2 (BIT(3) | BIT(2))
448/* Bit[4] - 0-TCXO, 1-FREF */
449#define PRCM_CM_EN_MUX_WLAN_FREF BIT(4)
450
451#define TCXO_ILOAD_INT_REG 0x2264
452#define TCXO_CLK_DETECT_REG 0x2266
453
454#define TCXO_DET_FAILED BIT(4)
455
456#define FREF_ILOAD_INT_REG 0x2084
457#define FREF_CLK_DETECT_REG 0x2086
458#define FREF_CLK_DETECT_FAIL BIT(4)
459
460/* Use this reg for masking during driver access */
461#define WL_SPARE_REG 0x2320
462#define WL_SPARE_VAL BIT(2)
463/* Bit[6:5:3] - mask wl write SYS_CLK_CFG[8:5:2:4] */
464#define WL_SPARE_MASK_8526 (BIT(6) | BIT(5) | BIT(3))
465
466#define PLL_LOCK_COUNTERS_REG 0xD8C
467#define PLL_LOCK_COUNTERS_COEX 0x0F
468#define PLL_LOCK_COUNTERS_MCS 0xF0
469#define MCS_PLL_OVERRIDE_REG 0xD90
470#define MCS_PLL_CONFIG_REG 0xD92
471#define MCS_SEL_IN_FREQ_MASK 0x0070
472#define MCS_SEL_IN_FREQ_SHIFT 4
473#define MCS_PLL_CONFIG_REG_VAL 0x73
474#define MCS_PLL_ENABLE_HP (BIT(0) | BIT(1))
475
476#define MCS_PLL_M_REG 0xD94
477#define MCS_PLL_N_REG 0xD96
478#define MCS_PLL_M_REG_VAL 0xC8
479#define MCS_PLL_N_REG_VAL 0x07
480
481#define SDIO_IO_DS 0xd14
482
483/* SDIO/wSPI DS configuration values */
484enum {
485 HCI_IO_DS_8MA = 0,
486 HCI_IO_DS_4MA = 1, /* default */
487 HCI_IO_DS_6MA = 2,
488 HCI_IO_DS_2MA = 3,
489};
490
491/* end PLL configuration algorithm for wl128x */
492
493/*
494 * Host Command Interrupt. Setting this bit masks
495 * the interrupt that the host issues to inform
496 * the FW that it has sent a command
497 * to the Wlan hardware Command Mailbox.
498 */
499#define WL12XX_INTR_TRIG_CMD BIT(0)
500
501/*
502 * Host Event Acknowlegde Interrupt. The host
503 * sets this bit to acknowledge that it received
504 * the unsolicited information from the event
505 * mailbox.
506 */
507#define WL12XX_INTR_TRIG_EVENT_ACK BIT(1)
508
509/*===============================================
510 HI_CFG Interface Configuration Register Values
511 ------------------------------------------
512 ===============================================*/
513#define HI_CFG_UART_ENABLE 0x00000004
514#define HI_CFG_RST232_ENABLE 0x00000008
515#define HI_CFG_CLOCK_REQ_SELECT 0x00000010
516#define HI_CFG_HOST_INT_ENABLE 0x00000020
517#define HI_CFG_VLYNQ_OUTPUT_ENABLE 0x00000040
518#define HI_CFG_HOST_INT_ACTIVE_LOW 0x00000080
519#define HI_CFG_UART_TX_OUT_GPIO_15 0x00000100
520#define HI_CFG_UART_TX_OUT_GPIO_14 0x00000200
521#define HI_CFG_UART_TX_OUT_GPIO_7 0x00000400
522
523#define HI_CFG_DEF_VAL \
524 (HI_CFG_UART_ENABLE | \
525 HI_CFG_RST232_ENABLE | \
526 HI_CFG_CLOCK_REQ_SELECT | \
527 HI_CFG_HOST_INT_ENABLE)
528
529#define WL127X_REG_FUSE_DATA_2_1 0x050a
530#define WL128X_REG_FUSE_DATA_2_1 0x2152
531#define PG_VER_MASK 0x3c
532#define PG_VER_OFFSET 2
533
534#define WL127X_PG_MAJOR_VER_MASK 0x3
535#define WL127X_PG_MAJOR_VER_OFFSET 0x0
536#define WL127X_PG_MINOR_VER_MASK 0xc
537#define WL127X_PG_MINOR_VER_OFFSET 0x2
538
539#define WL128X_PG_MAJOR_VER_MASK 0xc
540#define WL128X_PG_MAJOR_VER_OFFSET 0x2
541#define WL128X_PG_MINOR_VER_MASK 0x3
542#define WL128X_PG_MINOR_VER_OFFSET 0x0
543
544#define WL127X_PG_GET_MAJOR(pg_ver) ((pg_ver & WL127X_PG_MAJOR_VER_MASK) >> \
545 WL127X_PG_MAJOR_VER_OFFSET)
546#define WL127X_PG_GET_MINOR(pg_ver) ((pg_ver & WL127X_PG_MINOR_VER_MASK) >> \
547 WL127X_PG_MINOR_VER_OFFSET)
548#define WL128X_PG_GET_MAJOR(pg_ver) ((pg_ver & WL128X_PG_MAJOR_VER_MASK) >> \
549 WL128X_PG_MAJOR_VER_OFFSET)
550#define WL128X_PG_GET_MINOR(pg_ver) ((pg_ver & WL128X_PG_MINOR_VER_MASK) >> \
551 WL128X_PG_MINOR_VER_OFFSET)
552
553#define WL12XX_REG_FUSE_BD_ADDR_1 0x00310eb4
554#define WL12XX_REG_FUSE_BD_ADDR_2 0x00310eb8
555
556#endif
diff --git a/drivers/net/wireless/ti/wl12xx/wl12xx.h b/drivers/net/wireless/ti/wl12xx/wl12xx.h
new file mode 100644
index 000000000000..74cd332e23ef
--- /dev/null
+++ b/drivers/net/wireless/ti/wl12xx/wl12xx.h
@@ -0,0 +1,31 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (C) 2011 Texas Instruments Inc.
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
22#ifndef __WL12XX_PRIV_H__
23#define __WL12XX_PRIV_H__
24
25#include "conf.h"
26
27struct wl12xx_priv {
28 struct wl12xx_priv_conf conf;
29};
30
31#endif /* __WL12XX_PRIV_H__ */
diff --git a/drivers/net/wireless/ti/wlcore/Kconfig b/drivers/net/wireless/ti/wlcore/Kconfig
new file mode 100644
index 000000000000..9d04c38938bc
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/Kconfig
@@ -0,0 +1,41 @@
1config WLCORE
2 tristate "TI wlcore support"
3 depends on WL_TI && GENERIC_HARDIRQS
4 depends on INET
5 select FW_LOADER
6 ---help---
7 This module contains the main code for TI WLAN chips. It abstracts
8 hardware-specific differences among different chipset families.
9 Each chipset family needs to implement its own lower-level module
10 that will depend on this module for the common code.
11
12 If you choose to build a module, it will be called wlcore. Say N if
13 unsure.
14
15config WLCORE_SPI
16 tristate "TI wlcore SPI support"
17 depends on WLCORE && SPI_MASTER
18 select CRC7
19 ---help---
20 This module adds support for the SPI interface of adapters using
21 TI WLAN chipsets. Select this if your platform is using
22 the SPI bus.
23
24 If you choose to build a module, it'll be called wlcore_spi.
25 Say N if unsure.
26
27config WLCORE_SDIO
28 tristate "TI wlcore SDIO support"
29 depends on WLCORE && MMC
30 ---help---
31 This module adds support for the SDIO interface of adapters using
32 TI WLAN chipsets. Select this if your platform is using
33 the SDIO bus.
34
35 If you choose to build a module, it'll be called wlcore_sdio.
36 Say N if unsure.
37
38config WL12XX_PLATFORM_DATA
39 bool
40 depends on WLCORE_SDIO != n || WL1251_SDIO != n
41 default y
diff --git a/drivers/net/wireless/ti/wlcore/Makefile b/drivers/net/wireless/ti/wlcore/Makefile
new file mode 100644
index 000000000000..d9fba9e32130
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/Makefile
@@ -0,0 +1,15 @@
1wlcore-objs = main.o cmd.o io.o event.o tx.o rx.o ps.o acx.o \
2 boot.o init.o debugfs.o scan.o
3
4wlcore_spi-objs = spi.o
5wlcore_sdio-objs = sdio.o
6
7wlcore-$(CONFIG_NL80211_TESTMODE) += testmode.o
8obj-$(CONFIG_WLCORE) += wlcore.o
9obj-$(CONFIG_WLCORE_SPI) += wlcore_spi.o
10obj-$(CONFIG_WLCORE_SDIO) += wlcore_sdio.o
11
12# small builtin driver bit
13obj-$(CONFIG_WL12XX_PLATFORM_DATA) += wl12xx_platform_data.o
14
15ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/net/wireless/ti/wlcore/acx.c b/drivers/net/wireless/ti/wlcore/acx.c
new file mode 100644
index 000000000000..5912541a925e
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/acx.c
@@ -0,0 +1,1716 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2008-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 "acx.h"
25
26#include <linux/module.h>
27#include <linux/platform_device.h>
28#include <linux/spi/spi.h>
29#include <linux/slab.h>
30
31#include "wlcore.h"
32#include "debug.h"
33#include "wl12xx_80211.h"
34#include "ps.h"
35#include "hw_ops.h"
36
37int wl1271_acx_wake_up_conditions(struct wl1271 *wl, struct wl12xx_vif *wlvif,
38 u8 wake_up_event, u8 listen_interval)
39{
40 struct acx_wake_up_condition *wake_up;
41 int ret;
42
43 wl1271_debug(DEBUG_ACX, "acx wake up conditions (wake_up_event %d listen_interval %d)",
44 wake_up_event, listen_interval);
45
46 wake_up = kzalloc(sizeof(*wake_up), GFP_KERNEL);
47 if (!wake_up) {
48 ret = -ENOMEM;
49 goto out;
50 }
51
52 wake_up->role_id = wlvif->role_id;
53 wake_up->wake_up_event = wake_up_event;
54 wake_up->listen_interval = listen_interval;
55
56 ret = wl1271_cmd_configure(wl, ACX_WAKE_UP_CONDITIONS,
57 wake_up, sizeof(*wake_up));
58 if (ret < 0) {
59 wl1271_warning("could not set wake up conditions: %d", ret);
60 goto out;
61 }
62
63out:
64 kfree(wake_up);
65 return ret;
66}
67
68int wl1271_acx_sleep_auth(struct wl1271 *wl, u8 sleep_auth)
69{
70 struct acx_sleep_auth *auth;
71 int ret;
72
73 wl1271_debug(DEBUG_ACX, "acx sleep auth");
74
75 auth = kzalloc(sizeof(*auth), GFP_KERNEL);
76 if (!auth) {
77 ret = -ENOMEM;
78 goto out;
79 }
80
81 auth->sleep_auth = sleep_auth;
82
83 ret = wl1271_cmd_configure(wl, ACX_SLEEP_AUTH, auth, sizeof(*auth));
84
85out:
86 kfree(auth);
87 return ret;
88}
89
90int wl1271_acx_tx_power(struct wl1271 *wl, struct wl12xx_vif *wlvif,
91 int power)
92{
93 struct acx_current_tx_power *acx;
94 int ret;
95
96 wl1271_debug(DEBUG_ACX, "acx dot11_cur_tx_pwr %d", power);
97
98 if (power < 0 || power > 25)
99 return -EINVAL;
100
101 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
102 if (!acx) {
103 ret = -ENOMEM;
104 goto out;
105 }
106
107 acx->role_id = wlvif->role_id;
108 acx->current_tx_power = power * 10;
109
110 ret = wl1271_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx));
111 if (ret < 0) {
112 wl1271_warning("configure of tx power failed: %d", ret);
113 goto out;
114 }
115
116out:
117 kfree(acx);
118 return ret;
119}
120
121int wl1271_acx_feature_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif)
122{
123 struct acx_feature_config *feature;
124 int ret;
125
126 wl1271_debug(DEBUG_ACX, "acx feature cfg");
127
128 feature = kzalloc(sizeof(*feature), GFP_KERNEL);
129 if (!feature) {
130 ret = -ENOMEM;
131 goto out;
132 }
133
134 /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */
135 feature->role_id = wlvif->role_id;
136 feature->data_flow_options = 0;
137 feature->options = 0;
138
139 ret = wl1271_cmd_configure(wl, ACX_FEATURE_CFG,
140 feature, sizeof(*feature));
141 if (ret < 0) {
142 wl1271_error("Couldnt set HW encryption");
143 goto out;
144 }
145
146out:
147 kfree(feature);
148 return ret;
149}
150
151int wl1271_acx_mem_map(struct wl1271 *wl, struct acx_header *mem_map,
152 size_t len)
153{
154 int ret;
155
156 wl1271_debug(DEBUG_ACX, "acx mem map");
157
158 ret = wl1271_cmd_interrogate(wl, ACX_MEM_MAP, mem_map, len);
159 if (ret < 0)
160 return ret;
161
162 return 0;
163}
164
165int wl1271_acx_rx_msdu_life_time(struct wl1271 *wl)
166{
167 struct acx_rx_msdu_lifetime *acx;
168 int ret;
169
170 wl1271_debug(DEBUG_ACX, "acx rx msdu life time");
171
172 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
173 if (!acx) {
174 ret = -ENOMEM;
175 goto out;
176 }
177
178 acx->lifetime = cpu_to_le32(wl->conf.rx.rx_msdu_life_time);
179 ret = wl1271_cmd_configure(wl, DOT11_RX_MSDU_LIFE_TIME,
180 acx, sizeof(*acx));
181 if (ret < 0) {
182 wl1271_warning("failed to set rx msdu life time: %d", ret);
183 goto out;
184 }
185
186out:
187 kfree(acx);
188 return ret;
189}
190
191int wl1271_acx_slot(struct wl1271 *wl, struct wl12xx_vif *wlvif,
192 enum acx_slot_type slot_time)
193{
194 struct acx_slot *slot;
195 int ret;
196
197 wl1271_debug(DEBUG_ACX, "acx slot");
198
199 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
200 if (!slot) {
201 ret = -ENOMEM;
202 goto out;
203 }
204
205 slot->role_id = wlvif->role_id;
206 slot->wone_index = STATION_WONE_INDEX;
207 slot->slot_time = slot_time;
208
209 ret = wl1271_cmd_configure(wl, ACX_SLOT, slot, sizeof(*slot));
210 if (ret < 0) {
211 wl1271_warning("failed to set slot time: %d", ret);
212 goto out;
213 }
214
215out:
216 kfree(slot);
217 return ret;
218}
219
220int wl1271_acx_group_address_tbl(struct wl1271 *wl, struct wl12xx_vif *wlvif,
221 bool enable, void *mc_list, u32 mc_list_len)
222{
223 struct acx_dot11_grp_addr_tbl *acx;
224 int ret;
225
226 wl1271_debug(DEBUG_ACX, "acx group address tbl");
227
228 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
229 if (!acx) {
230 ret = -ENOMEM;
231 goto out;
232 }
233
234 /* MAC filtering */
235 acx->role_id = wlvif->role_id;
236 acx->enabled = enable;
237 acx->num_groups = mc_list_len;
238 memcpy(acx->mac_table, mc_list, mc_list_len * ETH_ALEN);
239
240 ret = wl1271_cmd_configure(wl, DOT11_GROUP_ADDRESS_TBL,
241 acx, sizeof(*acx));
242 if (ret < 0) {
243 wl1271_warning("failed to set group addr table: %d", ret);
244 goto out;
245 }
246
247out:
248 kfree(acx);
249 return ret;
250}
251
252int wl1271_acx_service_period_timeout(struct wl1271 *wl,
253 struct wl12xx_vif *wlvif)
254{
255 struct acx_rx_timeout *rx_timeout;
256 int ret;
257
258 rx_timeout = kzalloc(sizeof(*rx_timeout), GFP_KERNEL);
259 if (!rx_timeout) {
260 ret = -ENOMEM;
261 goto out;
262 }
263
264 wl1271_debug(DEBUG_ACX, "acx service period timeout");
265
266 rx_timeout->role_id = wlvif->role_id;
267 rx_timeout->ps_poll_timeout = cpu_to_le16(wl->conf.rx.ps_poll_timeout);
268 rx_timeout->upsd_timeout = cpu_to_le16(wl->conf.rx.upsd_timeout);
269
270 ret = wl1271_cmd_configure(wl, ACX_SERVICE_PERIOD_TIMEOUT,
271 rx_timeout, sizeof(*rx_timeout));
272 if (ret < 0) {
273 wl1271_warning("failed to set service period timeout: %d",
274 ret);
275 goto out;
276 }
277
278out:
279 kfree(rx_timeout);
280 return ret;
281}
282
283int wl1271_acx_rts_threshold(struct wl1271 *wl, struct wl12xx_vif *wlvif,
284 u32 rts_threshold)
285{
286 struct acx_rts_threshold *rts;
287 int ret;
288
289 /*
290 * If the RTS threshold is not configured or out of range, use the
291 * default value.
292 */
293 if (rts_threshold > IEEE80211_MAX_RTS_THRESHOLD)
294 rts_threshold = wl->conf.rx.rts_threshold;
295
296 wl1271_debug(DEBUG_ACX, "acx rts threshold: %d", rts_threshold);
297
298 rts = kzalloc(sizeof(*rts), GFP_KERNEL);
299 if (!rts) {
300 ret = -ENOMEM;
301 goto out;
302 }
303
304 rts->role_id = wlvif->role_id;
305 rts->threshold = cpu_to_le16((u16)rts_threshold);
306
307 ret = wl1271_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts));
308 if (ret < 0) {
309 wl1271_warning("failed to set rts threshold: %d", ret);
310 goto out;
311 }
312
313out:
314 kfree(rts);
315 return ret;
316}
317
318int wl1271_acx_dco_itrim_params(struct wl1271 *wl)
319{
320 struct acx_dco_itrim_params *dco;
321 struct conf_itrim_settings *c = &wl->conf.itrim;
322 int ret;
323
324 wl1271_debug(DEBUG_ACX, "acx dco itrim parameters");
325
326 dco = kzalloc(sizeof(*dco), GFP_KERNEL);
327 if (!dco) {
328 ret = -ENOMEM;
329 goto out;
330 }
331
332 dco->enable = c->enable;
333 dco->timeout = cpu_to_le32(c->timeout);
334
335 ret = wl1271_cmd_configure(wl, ACX_SET_DCO_ITRIM_PARAMS,
336 dco, sizeof(*dco));
337 if (ret < 0) {
338 wl1271_warning("failed to set dco itrim parameters: %d", ret);
339 goto out;
340 }
341
342out:
343 kfree(dco);
344 return ret;
345}
346
347int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, struct wl12xx_vif *wlvif,
348 bool enable_filter)
349{
350 struct acx_beacon_filter_option *beacon_filter = NULL;
351 int ret = 0;
352
353 wl1271_debug(DEBUG_ACX, "acx beacon filter opt");
354
355 if (enable_filter &&
356 wl->conf.conn.bcn_filt_mode == CONF_BCN_FILT_MODE_DISABLED)
357 goto out;
358
359 beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL);
360 if (!beacon_filter) {
361 ret = -ENOMEM;
362 goto out;
363 }
364
365 beacon_filter->role_id = wlvif->role_id;
366 beacon_filter->enable = enable_filter;
367
368 /*
369 * When set to zero, and the filter is enabled, beacons
370 * without the unicast TIM bit set are dropped.
371 */
372 beacon_filter->max_num_beacons = 0;
373
374 ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_OPT,
375 beacon_filter, sizeof(*beacon_filter));
376 if (ret < 0) {
377 wl1271_warning("failed to set beacon filter opt: %d", ret);
378 goto out;
379 }
380
381out:
382 kfree(beacon_filter);
383 return ret;
384}
385
386int wl1271_acx_beacon_filter_table(struct wl1271 *wl,
387 struct wl12xx_vif *wlvif)
388{
389 struct acx_beacon_filter_ie_table *ie_table;
390 int i, idx = 0;
391 int ret;
392 bool vendor_spec = false;
393
394 wl1271_debug(DEBUG_ACX, "acx beacon filter table");
395
396 ie_table = kzalloc(sizeof(*ie_table), GFP_KERNEL);
397 if (!ie_table) {
398 ret = -ENOMEM;
399 goto out;
400 }
401
402 /* configure default beacon pass-through rules */
403 ie_table->role_id = wlvif->role_id;
404 ie_table->num_ie = 0;
405 for (i = 0; i < wl->conf.conn.bcn_filt_ie_count; i++) {
406 struct conf_bcn_filt_rule *r = &(wl->conf.conn.bcn_filt_ie[i]);
407 ie_table->table[idx++] = r->ie;
408 ie_table->table[idx++] = r->rule;
409
410 if (r->ie == WLAN_EID_VENDOR_SPECIFIC) {
411 /* only one vendor specific ie allowed */
412 if (vendor_spec)
413 continue;
414
415 /* for vendor specific rules configure the
416 additional fields */
417 memcpy(&(ie_table->table[idx]), r->oui,
418 CONF_BCN_IE_OUI_LEN);
419 idx += CONF_BCN_IE_OUI_LEN;
420 ie_table->table[idx++] = r->type;
421 memcpy(&(ie_table->table[idx]), r->version,
422 CONF_BCN_IE_VER_LEN);
423 idx += CONF_BCN_IE_VER_LEN;
424 vendor_spec = true;
425 }
426
427 ie_table->num_ie++;
428 }
429
430 ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_TABLE,
431 ie_table, sizeof(*ie_table));
432 if (ret < 0) {
433 wl1271_warning("failed to set beacon filter table: %d", ret);
434 goto out;
435 }
436
437out:
438 kfree(ie_table);
439 return ret;
440}
441
442#define ACX_CONN_MONIT_DISABLE_VALUE 0xffffffff
443
444int wl1271_acx_conn_monit_params(struct wl1271 *wl, struct wl12xx_vif *wlvif,
445 bool enable)
446{
447 struct acx_conn_monit_params *acx;
448 u32 threshold = ACX_CONN_MONIT_DISABLE_VALUE;
449 u32 timeout = ACX_CONN_MONIT_DISABLE_VALUE;
450 int ret;
451
452 wl1271_debug(DEBUG_ACX, "acx connection monitor parameters: %s",
453 enable ? "enabled" : "disabled");
454
455 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
456 if (!acx) {
457 ret = -ENOMEM;
458 goto out;
459 }
460
461 if (enable) {
462 threshold = wl->conf.conn.synch_fail_thold;
463 timeout = wl->conf.conn.bss_lose_timeout;
464 }
465
466 acx->role_id = wlvif->role_id;
467 acx->synch_fail_thold = cpu_to_le32(threshold);
468 acx->bss_lose_timeout = cpu_to_le32(timeout);
469
470 ret = wl1271_cmd_configure(wl, ACX_CONN_MONIT_PARAMS,
471 acx, sizeof(*acx));
472 if (ret < 0) {
473 wl1271_warning("failed to set connection monitor "
474 "parameters: %d", ret);
475 goto out;
476 }
477
478out:
479 kfree(acx);
480 return ret;
481}
482
483
484int wl1271_acx_sg_enable(struct wl1271 *wl, bool enable)
485{
486 struct acx_bt_wlan_coex *pta;
487 int ret;
488
489 wl1271_debug(DEBUG_ACX, "acx sg enable");
490
491 pta = kzalloc(sizeof(*pta), GFP_KERNEL);
492 if (!pta) {
493 ret = -ENOMEM;
494 goto out;
495 }
496
497 if (enable)
498 pta->enable = wl->conf.sg.state;
499 else
500 pta->enable = CONF_SG_DISABLE;
501
502 ret = wl1271_cmd_configure(wl, ACX_SG_ENABLE, pta, sizeof(*pta));
503 if (ret < 0) {
504 wl1271_warning("failed to set softgemini enable: %d", ret);
505 goto out;
506 }
507
508out:
509 kfree(pta);
510 return ret;
511}
512
513int wl12xx_acx_sg_cfg(struct wl1271 *wl)
514{
515 struct acx_bt_wlan_coex_param *param;
516 struct conf_sg_settings *c = &wl->conf.sg;
517 int i, ret;
518
519 wl1271_debug(DEBUG_ACX, "acx sg cfg");
520
521 param = kzalloc(sizeof(*param), GFP_KERNEL);
522 if (!param) {
523 ret = -ENOMEM;
524 goto out;
525 }
526
527 /* BT-WLAN coext parameters */
528 for (i = 0; i < CONF_SG_PARAMS_MAX; i++)
529 param->params[i] = cpu_to_le32(c->params[i]);
530 param->param_idx = CONF_SG_PARAMS_ALL;
531
532 ret = wl1271_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param));
533 if (ret < 0) {
534 wl1271_warning("failed to set sg config: %d", ret);
535 goto out;
536 }
537
538out:
539 kfree(param);
540 return ret;
541}
542
543int wl1271_acx_cca_threshold(struct wl1271 *wl)
544{
545 struct acx_energy_detection *detection;
546 int ret;
547
548 wl1271_debug(DEBUG_ACX, "acx cca threshold");
549
550 detection = kzalloc(sizeof(*detection), GFP_KERNEL);
551 if (!detection) {
552 ret = -ENOMEM;
553 goto out;
554 }
555
556 detection->rx_cca_threshold = cpu_to_le16(wl->conf.rx.rx_cca_threshold);
557 detection->tx_energy_detection = wl->conf.tx.tx_energy_detection;
558
559 ret = wl1271_cmd_configure(wl, ACX_CCA_THRESHOLD,
560 detection, sizeof(*detection));
561 if (ret < 0)
562 wl1271_warning("failed to set cca threshold: %d", ret);
563
564out:
565 kfree(detection);
566 return ret;
567}
568
569int wl1271_acx_bcn_dtim_options(struct wl1271 *wl, struct wl12xx_vif *wlvif)
570{
571 struct acx_beacon_broadcast *bb;
572 int ret;
573
574 wl1271_debug(DEBUG_ACX, "acx bcn dtim options");
575
576 bb = kzalloc(sizeof(*bb), GFP_KERNEL);
577 if (!bb) {
578 ret = -ENOMEM;
579 goto out;
580 }
581
582 bb->role_id = wlvif->role_id;
583 bb->beacon_rx_timeout = cpu_to_le16(wl->conf.conn.beacon_rx_timeout);
584 bb->broadcast_timeout = cpu_to_le16(wl->conf.conn.broadcast_timeout);
585 bb->rx_broadcast_in_ps = wl->conf.conn.rx_broadcast_in_ps;
586 bb->ps_poll_threshold = wl->conf.conn.ps_poll_threshold;
587
588 ret = wl1271_cmd_configure(wl, ACX_BCN_DTIM_OPTIONS, bb, sizeof(*bb));
589 if (ret < 0) {
590 wl1271_warning("failed to set rx config: %d", ret);
591 goto out;
592 }
593
594out:
595 kfree(bb);
596 return ret;
597}
598
599int wl1271_acx_aid(struct wl1271 *wl, struct wl12xx_vif *wlvif, u16 aid)
600{
601 struct acx_aid *acx_aid;
602 int ret;
603
604 wl1271_debug(DEBUG_ACX, "acx aid");
605
606 acx_aid = kzalloc(sizeof(*acx_aid), GFP_KERNEL);
607 if (!acx_aid) {
608 ret = -ENOMEM;
609 goto out;
610 }
611
612 acx_aid->role_id = wlvif->role_id;
613 acx_aid->aid = cpu_to_le16(aid);
614
615 ret = wl1271_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid));
616 if (ret < 0) {
617 wl1271_warning("failed to set aid: %d", ret);
618 goto out;
619 }
620
621out:
622 kfree(acx_aid);
623 return ret;
624}
625
626int wl1271_acx_event_mbox_mask(struct wl1271 *wl, u32 event_mask)
627{
628 struct acx_event_mask *mask;
629 int ret;
630
631 wl1271_debug(DEBUG_ACX, "acx event mbox mask");
632
633 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
634 if (!mask) {
635 ret = -ENOMEM;
636 goto out;
637 }
638
639 /* high event mask is unused */
640 mask->high_event_mask = cpu_to_le32(0xffffffff);
641 mask->event_mask = cpu_to_le32(event_mask);
642
643 ret = wl1271_cmd_configure(wl, ACX_EVENT_MBOX_MASK,
644 mask, sizeof(*mask));
645 if (ret < 0) {
646 wl1271_warning("failed to set acx_event_mbox_mask: %d", ret);
647 goto out;
648 }
649
650out:
651 kfree(mask);
652 return ret;
653}
654
655int wl1271_acx_set_preamble(struct wl1271 *wl, struct wl12xx_vif *wlvif,
656 enum acx_preamble_type preamble)
657{
658 struct acx_preamble *acx;
659 int ret;
660
661 wl1271_debug(DEBUG_ACX, "acx_set_preamble");
662
663 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
664 if (!acx) {
665 ret = -ENOMEM;
666 goto out;
667 }
668
669 acx->role_id = wlvif->role_id;
670 acx->preamble = preamble;
671
672 ret = wl1271_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx));
673 if (ret < 0) {
674 wl1271_warning("Setting of preamble failed: %d", ret);
675 goto out;
676 }
677
678out:
679 kfree(acx);
680 return ret;
681}
682
683int wl1271_acx_cts_protect(struct wl1271 *wl, struct wl12xx_vif *wlvif,
684 enum acx_ctsprotect_type ctsprotect)
685{
686 struct acx_ctsprotect *acx;
687 int ret;
688
689 wl1271_debug(DEBUG_ACX, "acx_set_ctsprotect");
690
691 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
692 if (!acx) {
693 ret = -ENOMEM;
694 goto out;
695 }
696
697 acx->role_id = wlvif->role_id;
698 acx->ctsprotect = ctsprotect;
699
700 ret = wl1271_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx));
701 if (ret < 0) {
702 wl1271_warning("Setting of ctsprotect failed: %d", ret);
703 goto out;
704 }
705
706out:
707 kfree(acx);
708 return ret;
709}
710
711int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats)
712{
713 int ret;
714
715 wl1271_debug(DEBUG_ACX, "acx statistics");
716
717 ret = wl1271_cmd_interrogate(wl, ACX_STATISTICS, stats,
718 sizeof(*stats));
719 if (ret < 0) {
720 wl1271_warning("acx statistics failed: %d", ret);
721 return -ENOMEM;
722 }
723
724 return 0;
725}
726
727int wl1271_acx_sta_rate_policies(struct wl1271 *wl, struct wl12xx_vif *wlvif)
728{
729 struct acx_rate_policy *acx;
730 struct conf_tx_rate_class *c = &wl->conf.tx.sta_rc_conf;
731 int ret = 0;
732
733 wl1271_debug(DEBUG_ACX, "acx rate policies");
734
735 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
736
737 if (!acx) {
738 ret = -ENOMEM;
739 goto out;
740 }
741
742 wl1271_debug(DEBUG_ACX, "basic_rate: 0x%x, full_rate: 0x%x",
743 wlvif->basic_rate, wlvif->rate_set);
744
745 /* configure one basic rate class */
746 acx->rate_policy_idx = cpu_to_le32(wlvif->sta.basic_rate_idx);
747 acx->rate_policy.enabled_rates = cpu_to_le32(wlvif->basic_rate);
748 acx->rate_policy.short_retry_limit = c->short_retry_limit;
749 acx->rate_policy.long_retry_limit = c->long_retry_limit;
750 acx->rate_policy.aflags = c->aflags;
751
752 ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
753 if (ret < 0) {
754 wl1271_warning("Setting of rate policies failed: %d", ret);
755 goto out;
756 }
757
758 /* configure one AP supported rate class */
759 acx->rate_policy_idx = cpu_to_le32(wlvif->sta.ap_rate_idx);
760
761 /* the AP policy is HW specific */
762 acx->rate_policy.enabled_rates =
763 cpu_to_le32(wlcore_hw_sta_get_ap_rate_mask(wl, wlvif));
764 acx->rate_policy.short_retry_limit = c->short_retry_limit;
765 acx->rate_policy.long_retry_limit = c->long_retry_limit;
766 acx->rate_policy.aflags = c->aflags;
767
768 ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
769 if (ret < 0) {
770 wl1271_warning("Setting of rate policies failed: %d", ret);
771 goto out;
772 }
773
774 /*
775 * configure one rate class for basic p2p operations.
776 * (p2p packets should always go out with OFDM rates, even
777 * if we are currently connected to 11b AP)
778 */
779 acx->rate_policy_idx = cpu_to_le32(wlvif->sta.p2p_rate_idx);
780 acx->rate_policy.enabled_rates =
781 cpu_to_le32(CONF_TX_RATE_MASK_BASIC_P2P);
782 acx->rate_policy.short_retry_limit = c->short_retry_limit;
783 acx->rate_policy.long_retry_limit = c->long_retry_limit;
784 acx->rate_policy.aflags = c->aflags;
785
786 ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
787 if (ret < 0) {
788 wl1271_warning("Setting of rate policies failed: %d", ret);
789 goto out;
790 }
791
792out:
793 kfree(acx);
794 return ret;
795}
796
797int wl1271_acx_ap_rate_policy(struct wl1271 *wl, struct conf_tx_rate_class *c,
798 u8 idx)
799{
800 struct acx_rate_policy *acx;
801 int ret = 0;
802
803 wl1271_debug(DEBUG_ACX, "acx ap rate policy %d rates 0x%x",
804 idx, c->enabled_rates);
805
806 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
807 if (!acx) {
808 ret = -ENOMEM;
809 goto out;
810 }
811
812 acx->rate_policy.enabled_rates = cpu_to_le32(c->enabled_rates);
813 acx->rate_policy.short_retry_limit = c->short_retry_limit;
814 acx->rate_policy.long_retry_limit = c->long_retry_limit;
815 acx->rate_policy.aflags = c->aflags;
816
817 acx->rate_policy_idx = cpu_to_le32(idx);
818
819 ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
820 if (ret < 0) {
821 wl1271_warning("Setting of ap rate policy failed: %d", ret);
822 goto out;
823 }
824
825out:
826 kfree(acx);
827 return ret;
828}
829
830int wl1271_acx_ac_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif,
831 u8 ac, u8 cw_min, u16 cw_max, u8 aifsn, u16 txop)
832{
833 struct acx_ac_cfg *acx;
834 int ret = 0;
835
836 wl1271_debug(DEBUG_ACX, "acx ac cfg %d cw_ming %d cw_max %d "
837 "aifs %d txop %d", ac, cw_min, cw_max, aifsn, txop);
838
839 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
840
841 if (!acx) {
842 ret = -ENOMEM;
843 goto out;
844 }
845
846 acx->role_id = wlvif->role_id;
847 acx->ac = ac;
848 acx->cw_min = cw_min;
849 acx->cw_max = cpu_to_le16(cw_max);
850 acx->aifsn = aifsn;
851 acx->tx_op_limit = cpu_to_le16(txop);
852
853 ret = wl1271_cmd_configure(wl, ACX_AC_CFG, acx, sizeof(*acx));
854 if (ret < 0) {
855 wl1271_warning("acx ac cfg failed: %d", ret);
856 goto out;
857 }
858
859out:
860 kfree(acx);
861 return ret;
862}
863
864int wl1271_acx_tid_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif,
865 u8 queue_id, u8 channel_type,
866 u8 tsid, u8 ps_scheme, u8 ack_policy,
867 u32 apsd_conf0, u32 apsd_conf1)
868{
869 struct acx_tid_config *acx;
870 int ret = 0;
871
872 wl1271_debug(DEBUG_ACX, "acx tid config");
873
874 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
875
876 if (!acx) {
877 ret = -ENOMEM;
878 goto out;
879 }
880
881 acx->role_id = wlvif->role_id;
882 acx->queue_id = queue_id;
883 acx->channel_type = channel_type;
884 acx->tsid = tsid;
885 acx->ps_scheme = ps_scheme;
886 acx->ack_policy = ack_policy;
887 acx->apsd_conf[0] = cpu_to_le32(apsd_conf0);
888 acx->apsd_conf[1] = cpu_to_le32(apsd_conf1);
889
890 ret = wl1271_cmd_configure(wl, ACX_TID_CFG, acx, sizeof(*acx));
891 if (ret < 0) {
892 wl1271_warning("Setting of tid config failed: %d", ret);
893 goto out;
894 }
895
896out:
897 kfree(acx);
898 return ret;
899}
900
901int wl1271_acx_frag_threshold(struct wl1271 *wl, u32 frag_threshold)
902{
903 struct acx_frag_threshold *acx;
904 int ret = 0;
905
906 /*
907 * If the fragmentation is not configured or out of range, use the
908 * default value.
909 */
910 if (frag_threshold > IEEE80211_MAX_FRAG_THRESHOLD)
911 frag_threshold = wl->conf.tx.frag_threshold;
912
913 wl1271_debug(DEBUG_ACX, "acx frag threshold: %d", frag_threshold);
914
915 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
916
917 if (!acx) {
918 ret = -ENOMEM;
919 goto out;
920 }
921
922 acx->frag_threshold = cpu_to_le16((u16)frag_threshold);
923 ret = wl1271_cmd_configure(wl, ACX_FRAG_CFG, acx, sizeof(*acx));
924 if (ret < 0) {
925 wl1271_warning("Setting of frag threshold failed: %d", ret);
926 goto out;
927 }
928
929out:
930 kfree(acx);
931 return ret;
932}
933
934int wl1271_acx_tx_config_options(struct wl1271 *wl)
935{
936 struct acx_tx_config_options *acx;
937 int ret = 0;
938
939 wl1271_debug(DEBUG_ACX, "acx tx config options");
940
941 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
942
943 if (!acx) {
944 ret = -ENOMEM;
945 goto out;
946 }
947
948 acx->tx_compl_timeout = cpu_to_le16(wl->conf.tx.tx_compl_timeout);
949 acx->tx_compl_threshold = cpu_to_le16(wl->conf.tx.tx_compl_threshold);
950 ret = wl1271_cmd_configure(wl, ACX_TX_CONFIG_OPT, acx, sizeof(*acx));
951 if (ret < 0) {
952 wl1271_warning("Setting of tx options failed: %d", ret);
953 goto out;
954 }
955
956out:
957 kfree(acx);
958 return ret;
959}
960
961int wl12xx_acx_mem_cfg(struct wl1271 *wl)
962{
963 struct wl12xx_acx_config_memory *mem_conf;
964 struct conf_memory_settings *mem;
965 int ret;
966
967 wl1271_debug(DEBUG_ACX, "wl1271 mem cfg");
968
969 mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL);
970 if (!mem_conf) {
971 ret = -ENOMEM;
972 goto out;
973 }
974
975 mem = &wl->conf.mem;
976
977 /* memory config */
978 mem_conf->num_stations = mem->num_stations;
979 mem_conf->rx_mem_block_num = mem->rx_block_num;
980 mem_conf->tx_min_mem_block_num = mem->tx_min_block_num;
981 mem_conf->num_ssid_profiles = mem->ssid_profiles;
982 mem_conf->total_tx_descriptors = cpu_to_le32(wl->num_tx_desc);
983 mem_conf->dyn_mem_enable = mem->dynamic_memory;
984 mem_conf->tx_free_req = mem->min_req_tx_blocks;
985 mem_conf->rx_free_req = mem->min_req_rx_blocks;
986 mem_conf->tx_min = mem->tx_min;
987 mem_conf->fwlog_blocks = wl->conf.fwlog.mem_blocks;
988
989 ret = wl1271_cmd_configure(wl, ACX_MEM_CFG, mem_conf,
990 sizeof(*mem_conf));
991 if (ret < 0) {
992 wl1271_warning("wl1271 mem config failed: %d", ret);
993 goto out;
994 }
995
996out:
997 kfree(mem_conf);
998 return ret;
999}
1000
1001int wl1271_acx_init_mem_config(struct wl1271 *wl)
1002{
1003 int ret;
1004
1005 wl->target_mem_map = kzalloc(sizeof(struct wl1271_acx_mem_map),
1006 GFP_KERNEL);
1007 if (!wl->target_mem_map) {
1008 wl1271_error("couldn't allocate target memory map");
1009 return -ENOMEM;
1010 }
1011
1012 /* we now ask for the firmware built memory map */
1013 ret = wl1271_acx_mem_map(wl, (void *)wl->target_mem_map,
1014 sizeof(struct wl1271_acx_mem_map));
1015 if (ret < 0) {
1016 wl1271_error("couldn't retrieve firmware memory map");
1017 kfree(wl->target_mem_map);
1018 wl->target_mem_map = NULL;
1019 return ret;
1020 }
1021
1022 /* initialize TX block book keeping */
1023 wl->tx_blocks_available =
1024 le32_to_cpu(wl->target_mem_map->num_tx_mem_blocks);
1025 wl1271_debug(DEBUG_TX, "available tx blocks: %d",
1026 wl->tx_blocks_available);
1027
1028 return 0;
1029}
1030
1031int wl1271_acx_init_rx_interrupt(struct wl1271 *wl)
1032{
1033 struct wl1271_acx_rx_config_opt *rx_conf;
1034 int ret;
1035
1036 wl1271_debug(DEBUG_ACX, "wl1271 rx interrupt config");
1037
1038 rx_conf = kzalloc(sizeof(*rx_conf), GFP_KERNEL);
1039 if (!rx_conf) {
1040 ret = -ENOMEM;
1041 goto out;
1042 }
1043
1044 rx_conf->threshold = cpu_to_le16(wl->conf.rx.irq_pkt_threshold);
1045 rx_conf->timeout = cpu_to_le16(wl->conf.rx.irq_timeout);
1046 rx_conf->mblk_threshold = cpu_to_le16(wl->conf.rx.irq_blk_threshold);
1047 rx_conf->queue_type = wl->conf.rx.queue_type;
1048
1049 ret = wl1271_cmd_configure(wl, ACX_RX_CONFIG_OPT, rx_conf,
1050 sizeof(*rx_conf));
1051 if (ret < 0) {
1052 wl1271_warning("wl1271 rx config opt failed: %d", ret);
1053 goto out;
1054 }
1055
1056out:
1057 kfree(rx_conf);
1058 return ret;
1059}
1060
1061int wl1271_acx_bet_enable(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1062 bool enable)
1063{
1064 struct wl1271_acx_bet_enable *acx = NULL;
1065 int ret = 0;
1066
1067 wl1271_debug(DEBUG_ACX, "acx bet enable");
1068
1069 if (enable && wl->conf.conn.bet_enable == CONF_BET_MODE_DISABLE)
1070 goto out;
1071
1072 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1073 if (!acx) {
1074 ret = -ENOMEM;
1075 goto out;
1076 }
1077
1078 acx->role_id = wlvif->role_id;
1079 acx->enable = enable ? CONF_BET_MODE_ENABLE : CONF_BET_MODE_DISABLE;
1080 acx->max_consecutive = wl->conf.conn.bet_max_consecutive;
1081
1082 ret = wl1271_cmd_configure(wl, ACX_BET_ENABLE, acx, sizeof(*acx));
1083 if (ret < 0) {
1084 wl1271_warning("acx bet enable failed: %d", ret);
1085 goto out;
1086 }
1087
1088out:
1089 kfree(acx);
1090 return ret;
1091}
1092
1093int wl1271_acx_arp_ip_filter(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1094 u8 enable, __be32 address)
1095{
1096 struct wl1271_acx_arp_filter *acx;
1097 int ret;
1098
1099 wl1271_debug(DEBUG_ACX, "acx arp ip filter, enable: %d", enable);
1100
1101 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1102 if (!acx) {
1103 ret = -ENOMEM;
1104 goto out;
1105 }
1106
1107 acx->role_id = wlvif->role_id;
1108 acx->version = ACX_IPV4_VERSION;
1109 acx->enable = enable;
1110
1111 if (enable)
1112 memcpy(acx->address, &address, ACX_IPV4_ADDR_SIZE);
1113
1114 ret = wl1271_cmd_configure(wl, ACX_ARP_IP_FILTER,
1115 acx, sizeof(*acx));
1116 if (ret < 0) {
1117 wl1271_warning("failed to set arp ip filter: %d", ret);
1118 goto out;
1119 }
1120
1121out:
1122 kfree(acx);
1123 return ret;
1124}
1125
1126int wl1271_acx_pm_config(struct wl1271 *wl)
1127{
1128 struct wl1271_acx_pm_config *acx = NULL;
1129 struct conf_pm_config_settings *c = &wl->conf.pm_config;
1130 int ret = 0;
1131
1132 wl1271_debug(DEBUG_ACX, "acx pm config");
1133
1134 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1135 if (!acx) {
1136 ret = -ENOMEM;
1137 goto out;
1138 }
1139
1140 acx->host_clk_settling_time = cpu_to_le32(c->host_clk_settling_time);
1141 acx->host_fast_wakeup_support = c->host_fast_wakeup_support;
1142
1143 ret = wl1271_cmd_configure(wl, ACX_PM_CONFIG, acx, sizeof(*acx));
1144 if (ret < 0) {
1145 wl1271_warning("acx pm config failed: %d", ret);
1146 goto out;
1147 }
1148
1149out:
1150 kfree(acx);
1151 return ret;
1152}
1153
1154int wl1271_acx_keep_alive_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1155 bool enable)
1156{
1157 struct wl1271_acx_keep_alive_mode *acx = NULL;
1158 int ret = 0;
1159
1160 wl1271_debug(DEBUG_ACX, "acx keep alive mode: %d", enable);
1161
1162 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1163 if (!acx) {
1164 ret = -ENOMEM;
1165 goto out;
1166 }
1167
1168 acx->role_id = wlvif->role_id;
1169 acx->enabled = enable;
1170
1171 ret = wl1271_cmd_configure(wl, ACX_KEEP_ALIVE_MODE, acx, sizeof(*acx));
1172 if (ret < 0) {
1173 wl1271_warning("acx keep alive mode failed: %d", ret);
1174 goto out;
1175 }
1176
1177out:
1178 kfree(acx);
1179 return ret;
1180}
1181
1182int wl1271_acx_keep_alive_config(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1183 u8 index, u8 tpl_valid)
1184{
1185 struct wl1271_acx_keep_alive_config *acx = NULL;
1186 int ret = 0;
1187
1188 wl1271_debug(DEBUG_ACX, "acx keep alive config");
1189
1190 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1191 if (!acx) {
1192 ret = -ENOMEM;
1193 goto out;
1194 }
1195
1196 acx->role_id = wlvif->role_id;
1197 acx->period = cpu_to_le32(wl->conf.conn.keep_alive_interval);
1198 acx->index = index;
1199 acx->tpl_validation = tpl_valid;
1200 acx->trigger = ACX_KEEP_ALIVE_NO_TX;
1201
1202 ret = wl1271_cmd_configure(wl, ACX_SET_KEEP_ALIVE_CONFIG,
1203 acx, sizeof(*acx));
1204 if (ret < 0) {
1205 wl1271_warning("acx keep alive config failed: %d", ret);
1206 goto out;
1207 }
1208
1209out:
1210 kfree(acx);
1211 return ret;
1212}
1213
1214int wl1271_acx_rssi_snr_trigger(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1215 bool enable, s16 thold, u8 hyst)
1216{
1217 struct wl1271_acx_rssi_snr_trigger *acx = NULL;
1218 int ret = 0;
1219
1220 wl1271_debug(DEBUG_ACX, "acx rssi snr trigger");
1221
1222 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1223 if (!acx) {
1224 ret = -ENOMEM;
1225 goto out;
1226 }
1227
1228 wlvif->last_rssi_event = -1;
1229
1230 acx->role_id = wlvif->role_id;
1231 acx->pacing = cpu_to_le16(wl->conf.roam_trigger.trigger_pacing);
1232 acx->metric = WL1271_ACX_TRIG_METRIC_RSSI_BEACON;
1233 acx->type = WL1271_ACX_TRIG_TYPE_EDGE;
1234 if (enable)
1235 acx->enable = WL1271_ACX_TRIG_ENABLE;
1236 else
1237 acx->enable = WL1271_ACX_TRIG_DISABLE;
1238
1239 acx->index = WL1271_ACX_TRIG_IDX_RSSI;
1240 acx->dir = WL1271_ACX_TRIG_DIR_BIDIR;
1241 acx->threshold = cpu_to_le16(thold);
1242 acx->hysteresis = hyst;
1243
1244 ret = wl1271_cmd_configure(wl, ACX_RSSI_SNR_TRIGGER, acx, sizeof(*acx));
1245 if (ret < 0) {
1246 wl1271_warning("acx rssi snr trigger setting failed: %d", ret);
1247 goto out;
1248 }
1249
1250out:
1251 kfree(acx);
1252 return ret;
1253}
1254
1255int wl1271_acx_rssi_snr_avg_weights(struct wl1271 *wl,
1256 struct wl12xx_vif *wlvif)
1257{
1258 struct wl1271_acx_rssi_snr_avg_weights *acx = NULL;
1259 struct conf_roam_trigger_settings *c = &wl->conf.roam_trigger;
1260 int ret = 0;
1261
1262 wl1271_debug(DEBUG_ACX, "acx rssi snr avg weights");
1263
1264 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1265 if (!acx) {
1266 ret = -ENOMEM;
1267 goto out;
1268 }
1269
1270 acx->role_id = wlvif->role_id;
1271 acx->rssi_beacon = c->avg_weight_rssi_beacon;
1272 acx->rssi_data = c->avg_weight_rssi_data;
1273 acx->snr_beacon = c->avg_weight_snr_beacon;
1274 acx->snr_data = c->avg_weight_snr_data;
1275
1276 ret = wl1271_cmd_configure(wl, ACX_RSSI_SNR_WEIGHTS, acx, sizeof(*acx));
1277 if (ret < 0) {
1278 wl1271_warning("acx rssi snr trigger weights failed: %d", ret);
1279 goto out;
1280 }
1281
1282out:
1283 kfree(acx);
1284 return ret;
1285}
1286
1287int wl1271_acx_set_ht_capabilities(struct wl1271 *wl,
1288 struct ieee80211_sta_ht_cap *ht_cap,
1289 bool allow_ht_operation, u8 hlid)
1290{
1291 struct wl1271_acx_ht_capabilities *acx;
1292 int ret = 0;
1293 u32 ht_capabilites = 0;
1294
1295 wl1271_debug(DEBUG_ACX, "acx ht capabilities setting "
1296 "sta supp: %d sta cap: %d", ht_cap->ht_supported,
1297 ht_cap->cap);
1298
1299 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1300 if (!acx) {
1301 ret = -ENOMEM;
1302 goto out;
1303 }
1304
1305 if (allow_ht_operation && ht_cap->ht_supported) {
1306 /* no need to translate capabilities - use the spec values */
1307 ht_capabilites = ht_cap->cap;
1308
1309 /*
1310 * this bit is not employed by the spec but only by FW to
1311 * indicate peer HT support
1312 */
1313 ht_capabilites |= WL12XX_HT_CAP_HT_OPERATION;
1314
1315 /* get data from A-MPDU parameters field */
1316 acx->ampdu_max_length = ht_cap->ampdu_factor;
1317 acx->ampdu_min_spacing = ht_cap->ampdu_density;
1318 }
1319
1320 acx->hlid = hlid;
1321 acx->ht_capabilites = cpu_to_le32(ht_capabilites);
1322
1323 ret = wl1271_cmd_configure(wl, ACX_PEER_HT_CAP, acx, sizeof(*acx));
1324 if (ret < 0) {
1325 wl1271_warning("acx ht capabilities setting failed: %d", ret);
1326 goto out;
1327 }
1328
1329out:
1330 kfree(acx);
1331 return ret;
1332}
1333
1334int wl1271_acx_set_ht_information(struct wl1271 *wl,
1335 struct wl12xx_vif *wlvif,
1336 u16 ht_operation_mode)
1337{
1338 struct wl1271_acx_ht_information *acx;
1339 int ret = 0;
1340
1341 wl1271_debug(DEBUG_ACX, "acx ht information setting");
1342
1343 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1344 if (!acx) {
1345 ret = -ENOMEM;
1346 goto out;
1347 }
1348
1349 acx->role_id = wlvif->role_id;
1350 acx->ht_protection =
1351 (u8)(ht_operation_mode & IEEE80211_HT_OP_MODE_PROTECTION);
1352 acx->rifs_mode = 0;
1353 acx->gf_protection =
1354 !!(ht_operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
1355 acx->ht_tx_burst_limit = 0;
1356 acx->dual_cts_protection = 0;
1357
1358 ret = wl1271_cmd_configure(wl, ACX_HT_BSS_OPERATION, acx, sizeof(*acx));
1359
1360 if (ret < 0) {
1361 wl1271_warning("acx ht information setting failed: %d", ret);
1362 goto out;
1363 }
1364
1365out:
1366 kfree(acx);
1367 return ret;
1368}
1369
1370/* Configure BA session initiator/receiver parameters setting in the FW. */
1371int wl12xx_acx_set_ba_initiator_policy(struct wl1271 *wl,
1372 struct wl12xx_vif *wlvif)
1373{
1374 struct wl1271_acx_ba_initiator_policy *acx;
1375 int ret;
1376
1377 wl1271_debug(DEBUG_ACX, "acx ba initiator policy");
1378
1379 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1380 if (!acx) {
1381 ret = -ENOMEM;
1382 goto out;
1383 }
1384
1385 /* set for the current role */
1386 acx->role_id = wlvif->role_id;
1387 acx->tid_bitmap = wl->conf.ht.tx_ba_tid_bitmap;
1388 acx->win_size = wl->conf.ht.tx_ba_win_size;
1389 acx->inactivity_timeout = wl->conf.ht.inactivity_timeout;
1390
1391 ret = wl1271_cmd_configure(wl,
1392 ACX_BA_SESSION_INIT_POLICY,
1393 acx,
1394 sizeof(*acx));
1395 if (ret < 0) {
1396 wl1271_warning("acx ba initiator policy failed: %d", ret);
1397 goto out;
1398 }
1399
1400out:
1401 kfree(acx);
1402 return ret;
1403}
1404
1405/* setup BA session receiver setting in the FW. */
1406int wl12xx_acx_set_ba_receiver_session(struct wl1271 *wl, u8 tid_index,
1407 u16 ssn, bool enable, u8 peer_hlid)
1408{
1409 struct wl1271_acx_ba_receiver_setup *acx;
1410 int ret;
1411
1412 wl1271_debug(DEBUG_ACX, "acx ba receiver session setting");
1413
1414 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1415 if (!acx) {
1416 ret = -ENOMEM;
1417 goto out;
1418 }
1419
1420 acx->hlid = peer_hlid;
1421 acx->tid = tid_index;
1422 acx->enable = enable;
1423 acx->win_size = wl->conf.ht.rx_ba_win_size;
1424 acx->ssn = ssn;
1425
1426 ret = wl1271_cmd_configure(wl, ACX_BA_SESSION_RX_SETUP, acx,
1427 sizeof(*acx));
1428 if (ret < 0) {
1429 wl1271_warning("acx ba receiver session failed: %d", ret);
1430 goto out;
1431 }
1432
1433out:
1434 kfree(acx);
1435 return ret;
1436}
1437
1438int wl12xx_acx_tsf_info(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1439 u64 *mactime)
1440{
1441 struct wl12xx_acx_fw_tsf_information *tsf_info;
1442 int ret;
1443
1444 tsf_info = kzalloc(sizeof(*tsf_info), GFP_KERNEL);
1445 if (!tsf_info) {
1446 ret = -ENOMEM;
1447 goto out;
1448 }
1449
1450 tsf_info->role_id = wlvif->role_id;
1451
1452 ret = wl1271_cmd_interrogate(wl, ACX_TSF_INFO,
1453 tsf_info, sizeof(*tsf_info));
1454 if (ret < 0) {
1455 wl1271_warning("acx tsf info interrogate failed");
1456 goto out;
1457 }
1458
1459 *mactime = le32_to_cpu(tsf_info->current_tsf_low) |
1460 ((u64) le32_to_cpu(tsf_info->current_tsf_high) << 32);
1461
1462out:
1463 kfree(tsf_info);
1464 return ret;
1465}
1466
1467int wl1271_acx_ps_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1468 bool enable)
1469{
1470 struct wl1271_acx_ps_rx_streaming *rx_streaming;
1471 u32 conf_queues, enable_queues;
1472 int i, ret = 0;
1473
1474 wl1271_debug(DEBUG_ACX, "acx ps rx streaming");
1475
1476 rx_streaming = kzalloc(sizeof(*rx_streaming), GFP_KERNEL);
1477 if (!rx_streaming) {
1478 ret = -ENOMEM;
1479 goto out;
1480 }
1481
1482 conf_queues = wl->conf.rx_streaming.queues;
1483 if (enable)
1484 enable_queues = conf_queues;
1485 else
1486 enable_queues = 0;
1487
1488 for (i = 0; i < 8; i++) {
1489 /*
1490 * Skip non-changed queues, to avoid redundant acxs.
1491 * this check assumes conf.rx_streaming.queues can't
1492 * be changed while rx_streaming is enabled.
1493 */
1494 if (!(conf_queues & BIT(i)))
1495 continue;
1496
1497 rx_streaming->role_id = wlvif->role_id;
1498 rx_streaming->tid = i;
1499 rx_streaming->enable = enable_queues & BIT(i);
1500 rx_streaming->period = wl->conf.rx_streaming.interval;
1501 rx_streaming->timeout = wl->conf.rx_streaming.interval;
1502
1503 ret = wl1271_cmd_configure(wl, ACX_PS_RX_STREAMING,
1504 rx_streaming,
1505 sizeof(*rx_streaming));
1506 if (ret < 0) {
1507 wl1271_warning("acx ps rx streaming failed: %d", ret);
1508 goto out;
1509 }
1510 }
1511out:
1512 kfree(rx_streaming);
1513 return ret;
1514}
1515
1516int wl1271_acx_ap_max_tx_retry(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1517{
1518 struct wl1271_acx_ap_max_tx_retry *acx = NULL;
1519 int ret;
1520
1521 wl1271_debug(DEBUG_ACX, "acx ap max tx retry");
1522
1523 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1524 if (!acx)
1525 return -ENOMEM;
1526
1527 acx->role_id = wlvif->role_id;
1528 acx->max_tx_retry = cpu_to_le16(wl->conf.tx.max_tx_retries);
1529
1530 ret = wl1271_cmd_configure(wl, ACX_MAX_TX_FAILURE, acx, sizeof(*acx));
1531 if (ret < 0) {
1532 wl1271_warning("acx ap max tx retry failed: %d", ret);
1533 goto out;
1534 }
1535
1536out:
1537 kfree(acx);
1538 return ret;
1539}
1540
1541int wl12xx_acx_config_ps(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1542{
1543 struct wl1271_acx_config_ps *config_ps;
1544 int ret;
1545
1546 wl1271_debug(DEBUG_ACX, "acx config ps");
1547
1548 config_ps = kzalloc(sizeof(*config_ps), GFP_KERNEL);
1549 if (!config_ps) {
1550 ret = -ENOMEM;
1551 goto out;
1552 }
1553
1554 config_ps->exit_retries = wl->conf.conn.psm_exit_retries;
1555 config_ps->enter_retries = wl->conf.conn.psm_entry_retries;
1556 config_ps->null_data_rate = cpu_to_le32(wlvif->basic_rate);
1557
1558 ret = wl1271_cmd_configure(wl, ACX_CONFIG_PS, config_ps,
1559 sizeof(*config_ps));
1560
1561 if (ret < 0) {
1562 wl1271_warning("acx config ps failed: %d", ret);
1563 goto out;
1564 }
1565
1566out:
1567 kfree(config_ps);
1568 return ret;
1569}
1570
1571int wl1271_acx_set_inconnection_sta(struct wl1271 *wl, u8 *addr)
1572{
1573 struct wl1271_acx_inconnection_sta *acx = NULL;
1574 int ret;
1575
1576 wl1271_debug(DEBUG_ACX, "acx set inconnaction sta %pM", addr);
1577
1578 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1579 if (!acx)
1580 return -ENOMEM;
1581
1582 memcpy(acx->addr, addr, ETH_ALEN);
1583
1584 ret = wl1271_cmd_configure(wl, ACX_UPDATE_INCONNECTION_STA_LIST,
1585 acx, sizeof(*acx));
1586 if (ret < 0) {
1587 wl1271_warning("acx set inconnaction sta failed: %d", ret);
1588 goto out;
1589 }
1590
1591out:
1592 kfree(acx);
1593 return ret;
1594}
1595
1596int wl1271_acx_fm_coex(struct wl1271 *wl)
1597{
1598 struct wl1271_acx_fm_coex *acx;
1599 int ret;
1600
1601 wl1271_debug(DEBUG_ACX, "acx fm coex setting");
1602
1603 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1604 if (!acx) {
1605 ret = -ENOMEM;
1606 goto out;
1607 }
1608
1609 acx->enable = wl->conf.fm_coex.enable;
1610 acx->swallow_period = wl->conf.fm_coex.swallow_period;
1611 acx->n_divider_fref_set_1 = wl->conf.fm_coex.n_divider_fref_set_1;
1612 acx->n_divider_fref_set_2 = wl->conf.fm_coex.n_divider_fref_set_2;
1613 acx->m_divider_fref_set_1 =
1614 cpu_to_le16(wl->conf.fm_coex.m_divider_fref_set_1);
1615 acx->m_divider_fref_set_2 =
1616 cpu_to_le16(wl->conf.fm_coex.m_divider_fref_set_2);
1617 acx->coex_pll_stabilization_time =
1618 cpu_to_le32(wl->conf.fm_coex.coex_pll_stabilization_time);
1619 acx->ldo_stabilization_time =
1620 cpu_to_le16(wl->conf.fm_coex.ldo_stabilization_time);
1621 acx->fm_disturbed_band_margin =
1622 wl->conf.fm_coex.fm_disturbed_band_margin;
1623 acx->swallow_clk_diff = wl->conf.fm_coex.swallow_clk_diff;
1624
1625 ret = wl1271_cmd_configure(wl, ACX_FM_COEX_CFG, acx, sizeof(*acx));
1626 if (ret < 0) {
1627 wl1271_warning("acx fm coex setting failed: %d", ret);
1628 goto out;
1629 }
1630
1631out:
1632 kfree(acx);
1633 return ret;
1634}
1635
1636int wl12xx_acx_set_rate_mgmt_params(struct wl1271 *wl)
1637{
1638 struct wl12xx_acx_set_rate_mgmt_params *acx = NULL;
1639 struct conf_rate_policy_settings *conf = &wl->conf.rate;
1640 int ret;
1641
1642 wl1271_debug(DEBUG_ACX, "acx set rate mgmt params");
1643
1644 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1645 if (!acx)
1646 return -ENOMEM;
1647
1648 acx->index = ACX_RATE_MGMT_ALL_PARAMS;
1649 acx->rate_retry_score = cpu_to_le16(conf->rate_retry_score);
1650 acx->per_add = cpu_to_le16(conf->per_add);
1651 acx->per_th1 = cpu_to_le16(conf->per_th1);
1652 acx->per_th2 = cpu_to_le16(conf->per_th2);
1653 acx->max_per = cpu_to_le16(conf->max_per);
1654 acx->inverse_curiosity_factor = conf->inverse_curiosity_factor;
1655 acx->tx_fail_low_th = conf->tx_fail_low_th;
1656 acx->tx_fail_high_th = conf->tx_fail_high_th;
1657 acx->per_alpha_shift = conf->per_alpha_shift;
1658 acx->per_add_shift = conf->per_add_shift;
1659 acx->per_beta1_shift = conf->per_beta1_shift;
1660 acx->per_beta2_shift = conf->per_beta2_shift;
1661 acx->rate_check_up = conf->rate_check_up;
1662 acx->rate_check_down = conf->rate_check_down;
1663 memcpy(acx->rate_retry_policy, conf->rate_retry_policy,
1664 sizeof(acx->rate_retry_policy));
1665
1666 ret = wl1271_cmd_configure(wl, ACX_SET_RATE_MGMT_PARAMS,
1667 acx, sizeof(*acx));
1668 if (ret < 0) {
1669 wl1271_warning("acx set rate mgmt params failed: %d", ret);
1670 goto out;
1671 }
1672
1673out:
1674 kfree(acx);
1675 return ret;
1676}
1677
1678int wl12xx_acx_config_hangover(struct wl1271 *wl)
1679{
1680 struct wl12xx_acx_config_hangover *acx;
1681 struct conf_hangover_settings *conf = &wl->conf.hangover;
1682 int ret;
1683
1684 wl1271_debug(DEBUG_ACX, "acx config hangover");
1685
1686 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1687 if (!acx) {
1688 ret = -ENOMEM;
1689 goto out;
1690 }
1691
1692 acx->recover_time = cpu_to_le32(conf->recover_time);
1693 acx->hangover_period = conf->hangover_period;
1694 acx->dynamic_mode = conf->dynamic_mode;
1695 acx->early_termination_mode = conf->early_termination_mode;
1696 acx->max_period = conf->max_period;
1697 acx->min_period = conf->min_period;
1698 acx->increase_delta = conf->increase_delta;
1699 acx->decrease_delta = conf->decrease_delta;
1700 acx->quiet_time = conf->quiet_time;
1701 acx->increase_time = conf->increase_time;
1702 acx->window_size = acx->window_size;
1703
1704 ret = wl1271_cmd_configure(wl, ACX_CONFIG_HANGOVER, acx,
1705 sizeof(*acx));
1706
1707 if (ret < 0) {
1708 wl1271_warning("acx config hangover failed: %d", ret);
1709 goto out;
1710 }
1711
1712out:
1713 kfree(acx);
1714 return ret;
1715
1716}
diff --git a/drivers/net/wireless/ti/wlcore/acx.h b/drivers/net/wireless/ti/wlcore/acx.h
new file mode 100644
index 000000000000..b2f88831b7a9
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/acx.h
@@ -0,0 +1,1308 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
5 * Copyright (C) 2008-2010 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 __ACX_H__
26#define __ACX_H__
27
28#include "wlcore.h"
29#include "cmd.h"
30
31/*************************************************************************
32
33 Host Interrupt Register (WiLink -> Host)
34
35**************************************************************************/
36/* HW Initiated interrupt Watchdog timer expiration */
37#define WL1271_ACX_INTR_WATCHDOG BIT(0)
38/* Init sequence is done (masked interrupt, detection through polling only ) */
39#define WL1271_ACX_INTR_INIT_COMPLETE BIT(1)
40/* Event was entered to Event MBOX #A*/
41#define WL1271_ACX_INTR_EVENT_A BIT(2)
42/* Event was entered to Event MBOX #B*/
43#define WL1271_ACX_INTR_EVENT_B BIT(3)
44/* Command processing completion*/
45#define WL1271_ACX_INTR_CMD_COMPLETE BIT(4)
46/* Signaling the host on HW wakeup */
47#define WL1271_ACX_INTR_HW_AVAILABLE BIT(5)
48/* The MISC bit is used for aggregation of RX, TxComplete and TX rate update */
49#define WL1271_ACX_INTR_DATA BIT(6)
50/* Trace message on MBOX #A */
51#define WL1271_ACX_INTR_TRACE_A BIT(7)
52/* Trace message on MBOX #B */
53#define WL1271_ACX_INTR_TRACE_B BIT(8)
54
55#define WL1271_ACX_INTR_ALL 0xFFFFFFFF
56#define WL1271_ACX_ALL_EVENTS_VECTOR (WL1271_ACX_INTR_WATCHDOG | \
57 WL1271_ACX_INTR_INIT_COMPLETE | \
58 WL1271_ACX_INTR_EVENT_A | \
59 WL1271_ACX_INTR_EVENT_B | \
60 WL1271_ACX_INTR_CMD_COMPLETE | \
61 WL1271_ACX_INTR_HW_AVAILABLE | \
62 WL1271_ACX_INTR_DATA)
63
64#define WL1271_INTR_MASK (WL1271_ACX_INTR_WATCHDOG | \
65 WL1271_ACX_INTR_EVENT_A | \
66 WL1271_ACX_INTR_EVENT_B | \
67 WL1271_ACX_INTR_HW_AVAILABLE | \
68 WL1271_ACX_INTR_DATA)
69
70/* Target's information element */
71struct acx_header {
72 struct wl1271_cmd_header cmd;
73
74 /* acx (or information element) header */
75 __le16 id;
76
77 /* payload length (not including headers */
78 __le16 len;
79} __packed;
80
81struct acx_error_counter {
82 struct acx_header header;
83
84 /* The number of PLCP errors since the last time this */
85 /* information element was interrogated. This field is */
86 /* automatically cleared when it is interrogated.*/
87 __le32 PLCP_error;
88
89 /* The number of FCS errors since the last time this */
90 /* information element was interrogated. This field is */
91 /* automatically cleared when it is interrogated.*/
92 __le32 FCS_error;
93
94 /* The number of MPDUs without PLCP header errors received*/
95 /* since the last time this information element was interrogated. */
96 /* This field is automatically cleared when it is interrogated.*/
97 __le32 valid_frame;
98
99 /* the number of missed sequence numbers in the squentially */
100 /* values of frames seq numbers */
101 __le32 seq_num_miss;
102} __packed;
103
104enum wl12xx_role {
105 WL1271_ROLE_STA = 0,
106 WL1271_ROLE_IBSS,
107 WL1271_ROLE_AP,
108 WL1271_ROLE_DEVICE,
109 WL1271_ROLE_P2P_CL,
110 WL1271_ROLE_P2P_GO,
111
112 WL12XX_INVALID_ROLE_TYPE = 0xff
113};
114
115enum wl1271_psm_mode {
116 /* Active mode */
117 WL1271_PSM_CAM = 0,
118
119 /* Power save mode */
120 WL1271_PSM_PS = 1,
121
122 /* Extreme low power */
123 WL1271_PSM_ELP = 2,
124};
125
126struct acx_sleep_auth {
127 struct acx_header header;
128
129 /* The sleep level authorization of the device. */
130 /* 0 - Always active*/
131 /* 1 - Power down mode: light / fast sleep*/
132 /* 2 - ELP mode: Deep / Max sleep*/
133 u8 sleep_auth;
134 u8 padding[3];
135} __packed;
136
137enum {
138 HOSTIF_PCI_MASTER_HOST_INDIRECT,
139 HOSTIF_PCI_MASTER_HOST_DIRECT,
140 HOSTIF_SLAVE,
141 HOSTIF_PKT_RING,
142 HOSTIF_DONTCARE = 0xFF
143};
144
145#define DEFAULT_UCAST_PRIORITY 0
146#define DEFAULT_RX_Q_PRIORITY 0
147#define DEFAULT_RXQ_PRIORITY 0 /* low 0 .. 15 high */
148#define DEFAULT_RXQ_TYPE 0x07 /* All frames, Data/Ctrl/Mgmt */
149#define TRACE_BUFFER_MAX_SIZE 256
150
151#define DP_RX_PACKET_RING_CHUNK_SIZE 1600
152#define DP_TX_PACKET_RING_CHUNK_SIZE 1600
153#define DP_RX_PACKET_RING_CHUNK_NUM 2
154#define DP_TX_PACKET_RING_CHUNK_NUM 2
155#define DP_TX_COMPLETE_TIME_OUT 20
156
157#define TX_MSDU_LIFETIME_MIN 0
158#define TX_MSDU_LIFETIME_MAX 3000
159#define TX_MSDU_LIFETIME_DEF 512
160#define RX_MSDU_LIFETIME_MIN 0
161#define RX_MSDU_LIFETIME_MAX 0xFFFFFFFF
162#define RX_MSDU_LIFETIME_DEF 512000
163
164struct acx_rx_msdu_lifetime {
165 struct acx_header header;
166
167 /*
168 * The maximum amount of time, in TU, before the
169 * firmware discards the MSDU.
170 */
171 __le32 lifetime;
172} __packed;
173
174enum acx_slot_type {
175 SLOT_TIME_LONG = 0,
176 SLOT_TIME_SHORT = 1,
177 DEFAULT_SLOT_TIME = SLOT_TIME_SHORT,
178 MAX_SLOT_TIMES = 0xFF
179};
180
181#define STATION_WONE_INDEX 0
182
183struct acx_slot {
184 struct acx_header header;
185
186 u8 role_id;
187 u8 wone_index; /* Reserved */
188 u8 slot_time;
189 u8 reserved[5];
190} __packed;
191
192
193#define ACX_MC_ADDRESS_GROUP_MAX (8)
194#define ADDRESS_GROUP_MAX_LEN (ETH_ALEN * ACX_MC_ADDRESS_GROUP_MAX)
195
196struct acx_dot11_grp_addr_tbl {
197 struct acx_header header;
198
199 u8 role_id;
200 u8 enabled;
201 u8 num_groups;
202 u8 pad[1];
203 u8 mac_table[ADDRESS_GROUP_MAX_LEN];
204} __packed;
205
206struct acx_rx_timeout {
207 struct acx_header header;
208
209 u8 role_id;
210 u8 reserved;
211 __le16 ps_poll_timeout;
212 __le16 upsd_timeout;
213 u8 padding[2];
214} __packed;
215
216struct acx_rts_threshold {
217 struct acx_header header;
218
219 u8 role_id;
220 u8 reserved;
221 __le16 threshold;
222} __packed;
223
224struct acx_beacon_filter_option {
225 struct acx_header header;
226
227 u8 role_id;
228 u8 enable;
229 /*
230 * The number of beacons without the unicast TIM
231 * bit set that the firmware buffers before
232 * signaling the host about ready frames.
233 * When set to 0 and the filter is enabled, beacons
234 * without the unicast TIM bit set are dropped.
235 */
236 u8 max_num_beacons;
237 u8 pad[1];
238} __packed;
239
240/*
241 * ACXBeaconFilterEntry (not 221)
242 * Byte Offset Size (Bytes) Definition
243 * =========== ============ ==========
244 * 0 1 IE identifier
245 * 1 1 Treatment bit mask
246 *
247 * ACXBeaconFilterEntry (221)
248 * Byte Offset Size (Bytes) Definition
249 * =========== ============ ==========
250 * 0 1 IE identifier
251 * 1 1 Treatment bit mask
252 * 2 3 OUI
253 * 5 1 Type
254 * 6 2 Version
255 *
256 *
257 * Treatment bit mask - The information element handling:
258 * bit 0 - The information element is compared and transferred
259 * in case of change.
260 * bit 1 - The information element is transferred to the host
261 * with each appearance or disappearance.
262 * Note that both bits can be set at the same time.
263 */
264#define BEACON_FILTER_TABLE_MAX_IE_NUM (32)
265#define BEACON_FILTER_TABLE_MAX_VENDOR_SPECIFIC_IE_NUM (6)
266#define BEACON_FILTER_TABLE_IE_ENTRY_SIZE (2)
267#define BEACON_FILTER_TABLE_EXTRA_VENDOR_SPECIFIC_IE_SIZE (6)
268#define BEACON_FILTER_TABLE_MAX_SIZE ((BEACON_FILTER_TABLE_MAX_IE_NUM * \
269 BEACON_FILTER_TABLE_IE_ENTRY_SIZE) + \
270 (BEACON_FILTER_TABLE_MAX_VENDOR_SPECIFIC_IE_NUM * \
271 BEACON_FILTER_TABLE_EXTRA_VENDOR_SPECIFIC_IE_SIZE))
272
273struct acx_beacon_filter_ie_table {
274 struct acx_header header;
275
276 u8 role_id;
277 u8 num_ie;
278 u8 pad[2];
279 u8 table[BEACON_FILTER_TABLE_MAX_SIZE];
280} __packed;
281
282struct acx_conn_monit_params {
283 struct acx_header header;
284
285 u8 role_id;
286 u8 padding[3];
287 __le32 synch_fail_thold; /* number of beacons missed */
288 __le32 bss_lose_timeout; /* number of TU's from synch fail */
289} __packed;
290
291struct acx_bt_wlan_coex {
292 struct acx_header header;
293
294 u8 enable;
295 u8 pad[3];
296} __packed;
297
298struct acx_bt_wlan_coex_param {
299 struct acx_header header;
300
301 __le32 params[CONF_SG_PARAMS_MAX];
302 u8 param_idx;
303 u8 padding[3];
304} __packed;
305
306struct acx_dco_itrim_params {
307 struct acx_header header;
308
309 u8 enable;
310 u8 padding[3];
311 __le32 timeout;
312} __packed;
313
314struct acx_energy_detection {
315 struct acx_header header;
316
317 /* The RX Clear Channel Assessment threshold in the PHY */
318 __le16 rx_cca_threshold;
319 u8 tx_energy_detection;
320 u8 pad;
321} __packed;
322
323struct acx_beacon_broadcast {
324 struct acx_header header;
325
326 u8 role_id;
327 /* Enables receiving of broadcast packets in PS mode */
328 u8 rx_broadcast_in_ps;
329
330 __le16 beacon_rx_timeout;
331 __le16 broadcast_timeout;
332
333 /* Consecutive PS Poll failures before updating the host */
334 u8 ps_poll_threshold;
335 u8 pad[1];
336} __packed;
337
338struct acx_event_mask {
339 struct acx_header header;
340
341 __le32 event_mask;
342 __le32 high_event_mask; /* Unused */
343} __packed;
344
345#define SCAN_PASSIVE BIT(0)
346#define SCAN_5GHZ_BAND BIT(1)
347#define SCAN_TRIGGERED BIT(2)
348#define SCAN_PRIORITY_HIGH BIT(3)
349
350/* When set, disable HW encryption */
351#define DF_ENCRYPTION_DISABLE 0x01
352#define DF_SNIFF_MODE_ENABLE 0x80
353
354struct acx_feature_config {
355 struct acx_header header;
356
357 u8 role_id;
358 u8 padding[3];
359 __le32 options;
360 __le32 data_flow_options;
361} __packed;
362
363struct acx_current_tx_power {
364 struct acx_header header;
365
366 u8 role_id;
367 u8 current_tx_power;
368 u8 padding[2];
369} __packed;
370
371struct acx_wake_up_condition {
372 struct acx_header header;
373
374 u8 role_id;
375 u8 wake_up_event; /* Only one bit can be set */
376 u8 listen_interval;
377 u8 pad[1];
378} __packed;
379
380struct acx_aid {
381 struct acx_header header;
382
383 /*
384 * To be set when associated with an AP.
385 */
386 u8 role_id;
387 u8 reserved;
388 __le16 aid;
389} __packed;
390
391enum acx_preamble_type {
392 ACX_PREAMBLE_LONG = 0,
393 ACX_PREAMBLE_SHORT = 1
394};
395
396struct acx_preamble {
397 struct acx_header header;
398
399 /*
400 * When set, the WiLink transmits the frames with a short preamble and
401 * when cleared, the WiLink transmits the frames with a long preamble.
402 */
403 u8 role_id;
404 u8 preamble;
405 u8 padding[2];
406} __packed;
407
408enum acx_ctsprotect_type {
409 CTSPROTECT_DISABLE = 0,
410 CTSPROTECT_ENABLE = 1
411};
412
413struct acx_ctsprotect {
414 struct acx_header header;
415 u8 role_id;
416 u8 ctsprotect;
417 u8 padding[2];
418} __packed;
419
420struct acx_tx_statistics {
421 __le32 internal_desc_overflow;
422} __packed;
423
424struct acx_rx_statistics {
425 __le32 out_of_mem;
426 __le32 hdr_overflow;
427 __le32 hw_stuck;
428 __le32 dropped;
429 __le32 fcs_err;
430 __le32 xfr_hint_trig;
431 __le32 path_reset;
432 __le32 reset_counter;
433} __packed;
434
435struct acx_dma_statistics {
436 __le32 rx_requested;
437 __le32 rx_errors;
438 __le32 tx_requested;
439 __le32 tx_errors;
440} __packed;
441
442struct acx_isr_statistics {
443 /* host command complete */
444 __le32 cmd_cmplt;
445
446 /* fiqisr() */
447 __le32 fiqs;
448
449 /* (INT_STS_ND & INT_TRIG_RX_HEADER) */
450 __le32 rx_headers;
451
452 /* (INT_STS_ND & INT_TRIG_RX_CMPLT) */
453 __le32 rx_completes;
454
455 /* (INT_STS_ND & INT_TRIG_NO_RX_BUF) */
456 __le32 rx_mem_overflow;
457
458 /* (INT_STS_ND & INT_TRIG_S_RX_RDY) */
459 __le32 rx_rdys;
460
461 /* irqisr() */
462 __le32 irqs;
463
464 /* (INT_STS_ND & INT_TRIG_TX_PROC) */
465 __le32 tx_procs;
466
467 /* (INT_STS_ND & INT_TRIG_DECRYPT_DONE) */
468 __le32 decrypt_done;
469
470 /* (INT_STS_ND & INT_TRIG_DMA0) */
471 __le32 dma0_done;
472
473 /* (INT_STS_ND & INT_TRIG_DMA1) */
474 __le32 dma1_done;
475
476 /* (INT_STS_ND & INT_TRIG_TX_EXC_CMPLT) */
477 __le32 tx_exch_complete;
478
479 /* (INT_STS_ND & INT_TRIG_COMMAND) */
480 __le32 commands;
481
482 /* (INT_STS_ND & INT_TRIG_RX_PROC) */
483 __le32 rx_procs;
484
485 /* (INT_STS_ND & INT_TRIG_PM_802) */
486 __le32 hw_pm_mode_changes;
487
488 /* (INT_STS_ND & INT_TRIG_ACKNOWLEDGE) */
489 __le32 host_acknowledges;
490
491 /* (INT_STS_ND & INT_TRIG_PM_PCI) */
492 __le32 pci_pm;
493
494 /* (INT_STS_ND & INT_TRIG_ACM_WAKEUP) */
495 __le32 wakeups;
496
497 /* (INT_STS_ND & INT_TRIG_LOW_RSSI) */
498 __le32 low_rssi;
499} __packed;
500
501struct acx_wep_statistics {
502 /* WEP address keys configured */
503 __le32 addr_key_count;
504
505 /* default keys configured */
506 __le32 default_key_count;
507
508 __le32 reserved;
509
510 /* number of times that WEP key not found on lookup */
511 __le32 key_not_found;
512
513 /* number of times that WEP key decryption failed */
514 __le32 decrypt_fail;
515
516 /* WEP packets decrypted */
517 __le32 packets;
518
519 /* WEP decrypt interrupts */
520 __le32 interrupt;
521} __packed;
522
523#define ACX_MISSED_BEACONS_SPREAD 10
524
525struct acx_pwr_statistics {
526 /* the amount of enters into power save mode (both PD & ELP) */
527 __le32 ps_enter;
528
529 /* the amount of enters into ELP mode */
530 __le32 elp_enter;
531
532 /* the amount of missing beacon interrupts to the host */
533 __le32 missing_bcns;
534
535 /* the amount of wake on host-access times */
536 __le32 wake_on_host;
537
538 /* the amount of wake on timer-expire */
539 __le32 wake_on_timer_exp;
540
541 /* the number of packets that were transmitted with PS bit set */
542 __le32 tx_with_ps;
543
544 /* the number of packets that were transmitted with PS bit clear */
545 __le32 tx_without_ps;
546
547 /* the number of received beacons */
548 __le32 rcvd_beacons;
549
550 /* the number of entering into PowerOn (power save off) */
551 __le32 power_save_off;
552
553 /* the number of entries into power save mode */
554 __le16 enable_ps;
555
556 /*
557 * the number of exits from power save, not including failed PS
558 * transitions
559 */
560 __le16 disable_ps;
561
562 /*
563 * the number of times the TSF counter was adjusted because
564 * of drift
565 */
566 __le32 fix_tsf_ps;
567
568 /* Gives statistics about the spread continuous missed beacons.
569 * The 16 LSB are dedicated for the PS mode.
570 * The 16 MSB are dedicated for the PS mode.
571 * cont_miss_bcns_spread[0] - single missed beacon.
572 * cont_miss_bcns_spread[1] - two continuous missed beacons.
573 * cont_miss_bcns_spread[2] - three continuous missed beacons.
574 * ...
575 * cont_miss_bcns_spread[9] - ten and more continuous missed beacons.
576 */
577 __le32 cont_miss_bcns_spread[ACX_MISSED_BEACONS_SPREAD];
578
579 /* the number of beacons in awake mode */
580 __le32 rcvd_awake_beacons;
581} __packed;
582
583struct acx_mic_statistics {
584 __le32 rx_pkts;
585 __le32 calc_failure;
586} __packed;
587
588struct acx_aes_statistics {
589 __le32 encrypt_fail;
590 __le32 decrypt_fail;
591 __le32 encrypt_packets;
592 __le32 decrypt_packets;
593 __le32 encrypt_interrupt;
594 __le32 decrypt_interrupt;
595} __packed;
596
597struct acx_event_statistics {
598 __le32 heart_beat;
599 __le32 calibration;
600 __le32 rx_mismatch;
601 __le32 rx_mem_empty;
602 __le32 rx_pool;
603 __le32 oom_late;
604 __le32 phy_transmit_error;
605 __le32 tx_stuck;
606} __packed;
607
608struct acx_ps_statistics {
609 __le32 pspoll_timeouts;
610 __le32 upsd_timeouts;
611 __le32 upsd_max_sptime;
612 __le32 upsd_max_apturn;
613 __le32 pspoll_max_apturn;
614 __le32 pspoll_utilization;
615 __le32 upsd_utilization;
616} __packed;
617
618struct acx_rxpipe_statistics {
619 __le32 rx_prep_beacon_drop;
620 __le32 descr_host_int_trig_rx_data;
621 __le32 beacon_buffer_thres_host_int_trig_rx_data;
622 __le32 missed_beacon_host_int_trig_rx_data;
623 __le32 tx_xfr_host_int_trig_rx_data;
624} __packed;
625
626struct acx_statistics {
627 struct acx_header header;
628
629 struct acx_tx_statistics tx;
630 struct acx_rx_statistics rx;
631 struct acx_dma_statistics dma;
632 struct acx_isr_statistics isr;
633 struct acx_wep_statistics wep;
634 struct acx_pwr_statistics pwr;
635 struct acx_aes_statistics aes;
636 struct acx_mic_statistics mic;
637 struct acx_event_statistics event;
638 struct acx_ps_statistics ps;
639 struct acx_rxpipe_statistics rxpipe;
640} __packed;
641
642struct acx_rate_class {
643 __le32 enabled_rates;
644 u8 short_retry_limit;
645 u8 long_retry_limit;
646 u8 aflags;
647 u8 reserved;
648};
649
650struct acx_rate_policy {
651 struct acx_header header;
652
653 __le32 rate_policy_idx;
654 struct acx_rate_class rate_policy;
655} __packed;
656
657struct acx_ac_cfg {
658 struct acx_header header;
659 u8 role_id;
660 u8 ac;
661 u8 aifsn;
662 u8 cw_min;
663 __le16 cw_max;
664 __le16 tx_op_limit;
665} __packed;
666
667struct acx_tid_config {
668 struct acx_header header;
669 u8 role_id;
670 u8 queue_id;
671 u8 channel_type;
672 u8 tsid;
673 u8 ps_scheme;
674 u8 ack_policy;
675 u8 padding[2];
676 __le32 apsd_conf[2];
677} __packed;
678
679struct acx_frag_threshold {
680 struct acx_header header;
681 __le16 frag_threshold;
682 u8 padding[2];
683} __packed;
684
685struct acx_tx_config_options {
686 struct acx_header header;
687 __le16 tx_compl_timeout; /* msec */
688 __le16 tx_compl_threshold; /* number of packets */
689} __packed;
690
691struct wl12xx_acx_config_memory {
692 struct acx_header header;
693
694 u8 rx_mem_block_num;
695 u8 tx_min_mem_block_num;
696 u8 num_stations;
697 u8 num_ssid_profiles;
698 __le32 total_tx_descriptors;
699 u8 dyn_mem_enable;
700 u8 tx_free_req;
701 u8 rx_free_req;
702 u8 tx_min;
703 u8 fwlog_blocks;
704 u8 padding[3];
705} __packed;
706
707struct wl1271_acx_mem_map {
708 struct acx_header header;
709
710 __le32 code_start;
711 __le32 code_end;
712
713 __le32 wep_defkey_start;
714 __le32 wep_defkey_end;
715
716 __le32 sta_table_start;
717 __le32 sta_table_end;
718
719 __le32 packet_template_start;
720 __le32 packet_template_end;
721
722 /* Address of the TX result interface (control block) */
723 __le32 tx_result;
724 __le32 tx_result_queue_start;
725
726 __le32 queue_memory_start;
727 __le32 queue_memory_end;
728
729 __le32 packet_memory_pool_start;
730 __le32 packet_memory_pool_end;
731
732 __le32 debug_buffer1_start;
733 __le32 debug_buffer1_end;
734
735 __le32 debug_buffer2_start;
736 __le32 debug_buffer2_end;
737
738 /* Number of blocks FW allocated for TX packets */
739 __le32 num_tx_mem_blocks;
740
741 /* Number of blocks FW allocated for RX packets */
742 __le32 num_rx_mem_blocks;
743
744 /* the following 4 fields are valid in SLAVE mode only */
745 u8 *tx_cbuf;
746 u8 *rx_cbuf;
747 __le32 rx_ctrl;
748 __le32 tx_ctrl;
749} __packed;
750
751struct wl1271_acx_rx_config_opt {
752 struct acx_header header;
753
754 __le16 mblk_threshold;
755 __le16 threshold;
756 __le16 timeout;
757 u8 queue_type;
758 u8 reserved;
759} __packed;
760
761
762struct wl1271_acx_bet_enable {
763 struct acx_header header;
764
765 u8 role_id;
766 u8 enable;
767 u8 max_consecutive;
768 u8 padding[1];
769} __packed;
770
771#define ACX_IPV4_VERSION 4
772#define ACX_IPV6_VERSION 6
773#define ACX_IPV4_ADDR_SIZE 4
774
775/* bitmap of enabled arp_filter features */
776#define ACX_ARP_FILTER_ARP_FILTERING BIT(0)
777#define ACX_ARP_FILTER_AUTO_ARP BIT(1)
778
779struct wl1271_acx_arp_filter {
780 struct acx_header header;
781 u8 role_id;
782 u8 version; /* ACX_IPV4_VERSION, ACX_IPV6_VERSION */
783 u8 enable; /* bitmap of enabled ARP filtering features */
784 u8 padding[1];
785 u8 address[16]; /* The configured device IP address - all ARP
786 requests directed to this IP address will pass
787 through. For IPv4, the first four bytes are
788 used. */
789} __packed;
790
791struct wl1271_acx_pm_config {
792 struct acx_header header;
793
794 __le32 host_clk_settling_time;
795 u8 host_fast_wakeup_support;
796 u8 padding[3];
797} __packed;
798
799struct wl1271_acx_keep_alive_mode {
800 struct acx_header header;
801
802 u8 role_id;
803 u8 enabled;
804 u8 padding[2];
805} __packed;
806
807enum {
808 ACX_KEEP_ALIVE_NO_TX = 0,
809 ACX_KEEP_ALIVE_PERIOD_ONLY
810};
811
812enum {
813 ACX_KEEP_ALIVE_TPL_INVALID = 0,
814 ACX_KEEP_ALIVE_TPL_VALID
815};
816
817struct wl1271_acx_keep_alive_config {
818 struct acx_header header;
819
820 u8 role_id;
821 u8 index;
822 u8 tpl_validation;
823 u8 trigger;
824 __le32 period;
825} __packed;
826
827/* TODO: maybe this needs to be moved somewhere else? */
828#define HOST_IF_CFG_RX_FIFO_ENABLE BIT(0)
829#define HOST_IF_CFG_TX_EXTRA_BLKS_SWAP BIT(1)
830#define HOST_IF_CFG_TX_PAD_TO_SDIO_BLK BIT(3)
831
832enum {
833 WL1271_ACX_TRIG_TYPE_LEVEL = 0,
834 WL1271_ACX_TRIG_TYPE_EDGE,
835};
836
837enum {
838 WL1271_ACX_TRIG_DIR_LOW = 0,
839 WL1271_ACX_TRIG_DIR_HIGH,
840 WL1271_ACX_TRIG_DIR_BIDIR,
841};
842
843enum {
844 WL1271_ACX_TRIG_ENABLE = 1,
845 WL1271_ACX_TRIG_DISABLE,
846};
847
848enum {
849 WL1271_ACX_TRIG_METRIC_RSSI_BEACON = 0,
850 WL1271_ACX_TRIG_METRIC_RSSI_DATA,
851 WL1271_ACX_TRIG_METRIC_SNR_BEACON,
852 WL1271_ACX_TRIG_METRIC_SNR_DATA,
853};
854
855enum {
856 WL1271_ACX_TRIG_IDX_RSSI = 0,
857 WL1271_ACX_TRIG_COUNT = 8,
858};
859
860struct wl1271_acx_rssi_snr_trigger {
861 struct acx_header header;
862
863 u8 role_id;
864 u8 metric;
865 u8 type;
866 u8 dir;
867 __le16 threshold;
868 __le16 pacing; /* 0 - 60000 ms */
869 u8 hysteresis;
870 u8 index;
871 u8 enable;
872 u8 padding[1];
873};
874
875struct wl1271_acx_rssi_snr_avg_weights {
876 struct acx_header header;
877
878 u8 role_id;
879 u8 padding[3];
880 u8 rssi_beacon;
881 u8 rssi_data;
882 u8 snr_beacon;
883 u8 snr_data;
884};
885
886
887/* special capability bit (not employed by the 802.11n spec) */
888#define WL12XX_HT_CAP_HT_OPERATION BIT(16)
889
890/*
891 * ACX_PEER_HT_CAP
892 * Configure HT capabilities - declare the capabilities of the peer
893 * we are connected to.
894 */
895struct wl1271_acx_ht_capabilities {
896 struct acx_header header;
897
898 /* bitmask of capability bits supported by the peer */
899 __le32 ht_capabilites;
900
901 /* Indicates to which link these capabilities apply. */
902 u8 hlid;
903
904 /*
905 * This the maximum A-MPDU length supported by the AP. The FW may not
906 * exceed this length when sending A-MPDUs
907 */
908 u8 ampdu_max_length;
909
910 /* This is the minimal spacing required when sending A-MPDUs to the AP*/
911 u8 ampdu_min_spacing;
912
913 u8 padding;
914} __packed;
915
916/*
917 * ACX_HT_BSS_OPERATION
918 * Configure HT capabilities - AP rules for behavior in the BSS.
919 */
920struct wl1271_acx_ht_information {
921 struct acx_header header;
922
923 u8 role_id;
924
925 /* Values: 0 - RIFS not allowed, 1 - RIFS allowed */
926 u8 rifs_mode;
927
928 /* Values: 0 - 3 like in spec */
929 u8 ht_protection;
930
931 /* Values: 0 - GF protection not required, 1 - GF protection required */
932 u8 gf_protection;
933
934 /*Values: 0 - TX Burst limit not required, 1 - TX Burst Limit required*/
935 u8 ht_tx_burst_limit;
936
937 /*
938 * Values: 0 - Dual CTS protection not required,
939 * 1 - Dual CTS Protection required
940 * Note: When this value is set to 1 FW will protect all TXOP with RTS
941 * frame and will not use CTS-to-self regardless of the value of the
942 * ACX_CTS_PROTECTION information element
943 */
944 u8 dual_cts_protection;
945
946 u8 padding[2];
947} __packed;
948
949#define RX_BA_MAX_SESSIONS 2
950
951struct wl1271_acx_ba_initiator_policy {
952 struct acx_header header;
953
954 /* Specifies role Id, Range 0-7, 0xFF means ANY role. */
955 u8 role_id;
956
957 /*
958 * Per TID setting for allowing TX BA. Set a bit to 1 to allow
959 * TX BA sessions for the corresponding TID.
960 */
961 u8 tid_bitmap;
962
963 /* Windows size in number of packets */
964 u8 win_size;
965
966 u8 padding1[1];
967
968 /* As initiator inactivity timeout in time units(TU) of 1024us */
969 u16 inactivity_timeout;
970
971 u8 padding[2];
972} __packed;
973
974struct wl1271_acx_ba_receiver_setup {
975 struct acx_header header;
976
977 /* Specifies link id, range 0-31 */
978 u8 hlid;
979
980 u8 tid;
981
982 u8 enable;
983
984 /* Windows size in number of packets */
985 u8 win_size;
986
987 /* BA session starting sequence number. RANGE 0-FFF */
988 u16 ssn;
989
990 u8 padding[2];
991} __packed;
992
993struct wl12xx_acx_fw_tsf_information {
994 struct acx_header header;
995
996 u8 role_id;
997 u8 padding1[3];
998 __le32 current_tsf_high;
999 __le32 current_tsf_low;
1000 __le32 last_bttt_high;
1001 __le32 last_tbtt_low;
1002 u8 last_dtim_count;
1003 u8 padding2[3];
1004} __packed;
1005
1006struct wl1271_acx_ps_rx_streaming {
1007 struct acx_header header;
1008
1009 u8 role_id;
1010 u8 tid;
1011 u8 enable;
1012
1013 /* interval between triggers (10-100 msec) */
1014 u8 period;
1015
1016 /* timeout before first trigger (0-200 msec) */
1017 u8 timeout;
1018 u8 padding[3];
1019} __packed;
1020
1021struct wl1271_acx_ap_max_tx_retry {
1022 struct acx_header header;
1023
1024 u8 role_id;
1025 u8 padding_1;
1026
1027 /*
1028 * the number of frames transmission failures before
1029 * issuing the aging event.
1030 */
1031 __le16 max_tx_retry;
1032} __packed;
1033
1034struct wl1271_acx_config_ps {
1035 struct acx_header header;
1036
1037 u8 exit_retries;
1038 u8 enter_retries;
1039 u8 padding[2];
1040 __le32 null_data_rate;
1041} __packed;
1042
1043struct wl1271_acx_inconnection_sta {
1044 struct acx_header header;
1045
1046 u8 addr[ETH_ALEN];
1047 u8 padding1[2];
1048} __packed;
1049
1050/*
1051 * ACX_FM_COEX_CFG
1052 * set the FM co-existence parameters.
1053 */
1054struct wl1271_acx_fm_coex {
1055 struct acx_header header;
1056 /* enable(1) / disable(0) the FM Coex feature */
1057 u8 enable;
1058 /*
1059 * Swallow period used in COEX PLL swallowing mechanism.
1060 * 0xFF = use FW default
1061 */
1062 u8 swallow_period;
1063 /*
1064 * The N divider used in COEX PLL swallowing mechanism for Fref of
1065 * 38.4/19.2 Mhz. 0xFF = use FW default
1066 */
1067 u8 n_divider_fref_set_1;
1068 /*
1069 * The N divider used in COEX PLL swallowing mechanism for Fref of
1070 * 26/52 Mhz. 0xFF = use FW default
1071 */
1072 u8 n_divider_fref_set_2;
1073 /*
1074 * The M divider used in COEX PLL swallowing mechanism for Fref of
1075 * 38.4/19.2 Mhz. 0xFFFF = use FW default
1076 */
1077 __le16 m_divider_fref_set_1;
1078 /*
1079 * The M divider used in COEX PLL swallowing mechanism for Fref of
1080 * 26/52 Mhz. 0xFFFF = use FW default
1081 */
1082 __le16 m_divider_fref_set_2;
1083 /*
1084 * The time duration in uSec required for COEX PLL to stabilize.
1085 * 0xFFFFFFFF = use FW default
1086 */
1087 __le32 coex_pll_stabilization_time;
1088 /*
1089 * The time duration in uSec required for LDO to stabilize.
1090 * 0xFFFFFFFF = use FW default
1091 */
1092 __le16 ldo_stabilization_time;
1093 /*
1094 * The disturbed frequency band margin around the disturbed frequency
1095 * center (single sided).
1096 * For example, if 2 is configured, the following channels will be
1097 * considered disturbed channel:
1098 * 80 +- 0.1 MHz, 91 +- 0.1 MHz, 98 +- 0.1 MHz, 102 +- 0.1 MH
1099 * 0xFF = use FW default
1100 */
1101 u8 fm_disturbed_band_margin;
1102 /*
1103 * The swallow clock difference of the swallowing mechanism.
1104 * 0xFF = use FW default
1105 */
1106 u8 swallow_clk_diff;
1107} __packed;
1108
1109#define ACX_RATE_MGMT_ALL_PARAMS 0xff
1110struct wl12xx_acx_set_rate_mgmt_params {
1111 struct acx_header header;
1112
1113 u8 index; /* 0xff to configure all params */
1114 u8 padding1;
1115 __le16 rate_retry_score;
1116 __le16 per_add;
1117 __le16 per_th1;
1118 __le16 per_th2;
1119 __le16 max_per;
1120 u8 inverse_curiosity_factor;
1121 u8 tx_fail_low_th;
1122 u8 tx_fail_high_th;
1123 u8 per_alpha_shift;
1124 u8 per_add_shift;
1125 u8 per_beta1_shift;
1126 u8 per_beta2_shift;
1127 u8 rate_check_up;
1128 u8 rate_check_down;
1129 u8 rate_retry_policy[ACX_RATE_MGMT_NUM_OF_RATES];
1130 u8 padding2[2];
1131} __packed;
1132
1133struct wl12xx_acx_config_hangover {
1134 struct acx_header header;
1135
1136 __le32 recover_time;
1137 u8 hangover_period;
1138 u8 dynamic_mode;
1139 u8 early_termination_mode;
1140 u8 max_period;
1141 u8 min_period;
1142 u8 increase_delta;
1143 u8 decrease_delta;
1144 u8 quiet_time;
1145 u8 increase_time;
1146 u8 window_size;
1147 u8 padding[2];
1148} __packed;
1149
1150enum {
1151 ACX_WAKE_UP_CONDITIONS = 0x0000,
1152 ACX_MEM_CFG = 0x0001,
1153 ACX_SLOT = 0x0002,
1154 ACX_AC_CFG = 0x0003,
1155 ACX_MEM_MAP = 0x0004,
1156 ACX_AID = 0x0005,
1157 ACX_MEDIUM_USAGE = 0x0006,
1158 ACX_STATISTICS = 0x0007,
1159 ACX_PWR_CONSUMPTION_STATISTICS = 0x0008,
1160 ACX_TID_CFG = 0x0009,
1161 ACX_PS_RX_STREAMING = 0x000A,
1162 ACX_BEACON_FILTER_OPT = 0x000B,
1163 ACX_NOISE_HIST = 0x000C,
1164 ACX_HDK_VERSION = 0x000D,
1165 ACX_PD_THRESHOLD = 0x000E,
1166 ACX_TX_CONFIG_OPT = 0x000F,
1167 ACX_CCA_THRESHOLD = 0x0010,
1168 ACX_EVENT_MBOX_MASK = 0x0011,
1169 ACX_CONN_MONIT_PARAMS = 0x0012,
1170 ACX_DISABLE_BROADCASTS = 0x0013,
1171 ACX_BCN_DTIM_OPTIONS = 0x0014,
1172 ACX_SG_ENABLE = 0x0015,
1173 ACX_SG_CFG = 0x0016,
1174 ACX_FM_COEX_CFG = 0x0017,
1175 ACX_BEACON_FILTER_TABLE = 0x0018,
1176 ACX_ARP_IP_FILTER = 0x0019,
1177 ACX_ROAMING_STATISTICS_TBL = 0x001A,
1178 ACX_RATE_POLICY = 0x001B,
1179 ACX_CTS_PROTECTION = 0x001C,
1180 ACX_SLEEP_AUTH = 0x001D,
1181 ACX_PREAMBLE_TYPE = 0x001E,
1182 ACX_ERROR_CNT = 0x001F,
1183 ACX_IBSS_FILTER = 0x0020,
1184 ACX_SERVICE_PERIOD_TIMEOUT = 0x0021,
1185 ACX_TSF_INFO = 0x0022,
1186 ACX_CONFIG_PS_WMM = 0x0023,
1187 ACX_ENABLE_RX_DATA_FILTER = 0x0024,
1188 ACX_SET_RX_DATA_FILTER = 0x0025,
1189 ACX_GET_DATA_FILTER_STATISTICS = 0x0026,
1190 ACX_RX_CONFIG_OPT = 0x0027,
1191 ACX_FRAG_CFG = 0x0028,
1192 ACX_BET_ENABLE = 0x0029,
1193 ACX_RSSI_SNR_TRIGGER = 0x002A,
1194 ACX_RSSI_SNR_WEIGHTS = 0x002B,
1195 ACX_KEEP_ALIVE_MODE = 0x002C,
1196 ACX_SET_KEEP_ALIVE_CONFIG = 0x002D,
1197 ACX_BA_SESSION_INIT_POLICY = 0x002E,
1198 ACX_BA_SESSION_RX_SETUP = 0x002F,
1199 ACX_PEER_HT_CAP = 0x0030,
1200 ACX_HT_BSS_OPERATION = 0x0031,
1201 ACX_COEX_ACTIVITY = 0x0032,
1202 ACX_BURST_MODE = 0x0033,
1203 ACX_SET_RATE_MGMT_PARAMS = 0x0034,
1204 ACX_GET_RATE_MGMT_PARAMS = 0x0035,
1205 ACX_SET_RATE_ADAPT_PARAMS = 0x0036,
1206 ACX_SET_DCO_ITRIM_PARAMS = 0x0037,
1207 ACX_GEN_FW_CMD = 0x0038,
1208 ACX_HOST_IF_CFG_BITMAP = 0x0039,
1209 ACX_MAX_TX_FAILURE = 0x003A,
1210 ACX_UPDATE_INCONNECTION_STA_LIST = 0x003B,
1211 DOT11_RX_MSDU_LIFE_TIME = 0x003C,
1212 DOT11_CUR_TX_PWR = 0x003D,
1213 DOT11_RTS_THRESHOLD = 0x003E,
1214 DOT11_GROUP_ADDRESS_TBL = 0x003F,
1215 ACX_PM_CONFIG = 0x0040,
1216 ACX_CONFIG_PS = 0x0041,
1217 ACX_CONFIG_HANGOVER = 0x0042,
1218 ACX_FEATURE_CFG = 0x0043,
1219 ACX_PROTECTION_CFG = 0x0044,
1220};
1221
1222
1223int wl1271_acx_wake_up_conditions(struct wl1271 *wl,
1224 struct wl12xx_vif *wlvif,
1225 u8 wake_up_event, u8 listen_interval);
1226int wl1271_acx_sleep_auth(struct wl1271 *wl, u8 sleep_auth);
1227int wl1271_acx_tx_power(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1228 int power);
1229int wl1271_acx_feature_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif);
1230int wl1271_acx_mem_map(struct wl1271 *wl,
1231 struct acx_header *mem_map, size_t len);
1232int wl1271_acx_rx_msdu_life_time(struct wl1271 *wl);
1233int wl1271_acx_slot(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1234 enum acx_slot_type slot_time);
1235int wl1271_acx_group_address_tbl(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1236 bool enable, void *mc_list, u32 mc_list_len);
1237int wl1271_acx_service_period_timeout(struct wl1271 *wl,
1238 struct wl12xx_vif *wlvif);
1239int wl1271_acx_rts_threshold(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1240 u32 rts_threshold);
1241int wl1271_acx_dco_itrim_params(struct wl1271 *wl);
1242int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1243 bool enable_filter);
1244int wl1271_acx_beacon_filter_table(struct wl1271 *wl,
1245 struct wl12xx_vif *wlvif);
1246int wl1271_acx_conn_monit_params(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1247 bool enable);
1248int wl1271_acx_sg_enable(struct wl1271 *wl, bool enable);
1249int wl12xx_acx_sg_cfg(struct wl1271 *wl);
1250int wl1271_acx_cca_threshold(struct wl1271 *wl);
1251int wl1271_acx_bcn_dtim_options(struct wl1271 *wl, struct wl12xx_vif *wlvif);
1252int wl1271_acx_aid(struct wl1271 *wl, struct wl12xx_vif *wlvif, u16 aid);
1253int wl1271_acx_event_mbox_mask(struct wl1271 *wl, u32 event_mask);
1254int wl1271_acx_set_preamble(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1255 enum acx_preamble_type preamble);
1256int wl1271_acx_cts_protect(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1257 enum acx_ctsprotect_type ctsprotect);
1258int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats);
1259int wl1271_acx_sta_rate_policies(struct wl1271 *wl, struct wl12xx_vif *wlvif);
1260int wl1271_acx_ap_rate_policy(struct wl1271 *wl, struct conf_tx_rate_class *c,
1261 u8 idx);
1262int wl1271_acx_ac_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1263 u8 ac, u8 cw_min, u16 cw_max, u8 aifsn, u16 txop);
1264int wl1271_acx_tid_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1265 u8 queue_id, u8 channel_type,
1266 u8 tsid, u8 ps_scheme, u8 ack_policy,
1267 u32 apsd_conf0, u32 apsd_conf1);
1268int wl1271_acx_frag_threshold(struct wl1271 *wl, u32 frag_threshold);
1269int wl1271_acx_tx_config_options(struct wl1271 *wl);
1270int wl12xx_acx_mem_cfg(struct wl1271 *wl);
1271int wl1271_acx_init_mem_config(struct wl1271 *wl);
1272int wl1271_acx_init_rx_interrupt(struct wl1271 *wl);
1273int wl1271_acx_smart_reflex(struct wl1271 *wl);
1274int wl1271_acx_bet_enable(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1275 bool enable);
1276int wl1271_acx_arp_ip_filter(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1277 u8 enable, __be32 address);
1278int wl1271_acx_pm_config(struct wl1271 *wl);
1279int wl1271_acx_keep_alive_mode(struct wl1271 *wl, struct wl12xx_vif *vif,
1280 bool enable);
1281int wl1271_acx_keep_alive_config(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1282 u8 index, u8 tpl_valid);
1283int wl1271_acx_rssi_snr_trigger(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1284 bool enable, s16 thold, u8 hyst);
1285int wl1271_acx_rssi_snr_avg_weights(struct wl1271 *wl,
1286 struct wl12xx_vif *wlvif);
1287int wl1271_acx_set_ht_capabilities(struct wl1271 *wl,
1288 struct ieee80211_sta_ht_cap *ht_cap,
1289 bool allow_ht_operation, u8 hlid);
1290int wl1271_acx_set_ht_information(struct wl1271 *wl,
1291 struct wl12xx_vif *wlvif,
1292 u16 ht_operation_mode);
1293int wl12xx_acx_set_ba_initiator_policy(struct wl1271 *wl,
1294 struct wl12xx_vif *wlvif);
1295int wl12xx_acx_set_ba_receiver_session(struct wl1271 *wl, u8 tid_index,
1296 u16 ssn, bool enable, u8 peer_hlid);
1297int wl12xx_acx_tsf_info(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1298 u64 *mactime);
1299int wl1271_acx_ps_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1300 bool enable);
1301int wl1271_acx_ap_max_tx_retry(struct wl1271 *wl, struct wl12xx_vif *wlvif);
1302int wl12xx_acx_config_ps(struct wl1271 *wl, struct wl12xx_vif *wlvif);
1303int wl1271_acx_set_inconnection_sta(struct wl1271 *wl, u8 *addr);
1304int wl1271_acx_fm_coex(struct wl1271 *wl);
1305int wl12xx_acx_set_rate_mgmt_params(struct wl1271 *wl);
1306int wl12xx_acx_config_hangover(struct wl1271 *wl);
1307
1308#endif /* __WL1271_ACX_H__ */
diff --git a/drivers/net/wireless/ti/wlcore/boot.c b/drivers/net/wireless/ti/wlcore/boot.c
new file mode 100644
index 000000000000..3a2207db5405
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/boot.c
@@ -0,0 +1,443 @@
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/slab.h>
25#include <linux/wl12xx.h>
26#include <linux/export.h>
27
28#include "debug.h"
29#include "acx.h"
30#include "boot.h"
31#include "io.h"
32#include "event.h"
33#include "rx.h"
34#include "hw_ops.h"
35
36static void wl1271_boot_set_ecpu_ctrl(struct wl1271 *wl, u32 flag)
37{
38 u32 cpu_ctrl;
39
40 /* 10.5.0 run the firmware (I) */
41 cpu_ctrl = wlcore_read_reg(wl, REG_ECPU_CONTROL);
42
43 /* 10.5.1 run the firmware (II) */
44 cpu_ctrl |= flag;
45 wlcore_write_reg(wl, REG_ECPU_CONTROL, cpu_ctrl);
46}
47
48static int wlcore_parse_fw_ver(struct wl1271 *wl)
49{
50 int ret;
51
52 ret = sscanf(wl->chip.fw_ver_str + 4, "%u.%u.%u.%u.%u",
53 &wl->chip.fw_ver[0], &wl->chip.fw_ver[1],
54 &wl->chip.fw_ver[2], &wl->chip.fw_ver[3],
55 &wl->chip.fw_ver[4]);
56
57 if (ret != 5) {
58 wl1271_warning("fw version incorrect value");
59 memset(wl->chip.fw_ver, 0, sizeof(wl->chip.fw_ver));
60 return -EINVAL;
61 }
62
63 ret = wlcore_identify_fw(wl);
64 if (ret < 0)
65 return ret;
66
67 return 0;
68}
69
70static int wlcore_boot_fw_version(struct wl1271 *wl)
71{
72 struct wl1271_static_data *static_data;
73 int ret;
74
75 static_data = kmalloc(sizeof(*static_data), GFP_DMA);
76 if (!static_data) {
77 wl1271_error("Couldn't allocate memory for static data!");
78 return -ENOMEM;
79 }
80
81 wl1271_read(wl, wl->cmd_box_addr, static_data, sizeof(*static_data),
82 false);
83
84 strncpy(wl->chip.fw_ver_str, static_data->fw_version,
85 sizeof(wl->chip.fw_ver_str));
86
87 kfree(static_data);
88
89 /* make sure the string is NULL-terminated */
90 wl->chip.fw_ver_str[sizeof(wl->chip.fw_ver_str) - 1] = '\0';
91
92 ret = wlcore_parse_fw_ver(wl);
93 if (ret < 0)
94 return ret;
95
96 return 0;
97}
98
99static int wl1271_boot_upload_firmware_chunk(struct wl1271 *wl, void *buf,
100 size_t fw_data_len, u32 dest)
101{
102 struct wlcore_partition_set partition;
103 int addr, chunk_num, partition_limit;
104 u8 *p, *chunk;
105
106 /* whal_FwCtrl_LoadFwImageSm() */
107
108 wl1271_debug(DEBUG_BOOT, "starting firmware upload");
109
110 wl1271_debug(DEBUG_BOOT, "fw_data_len %zd chunk_size %d",
111 fw_data_len, CHUNK_SIZE);
112
113 if ((fw_data_len % 4) != 0) {
114 wl1271_error("firmware length not multiple of four");
115 return -EIO;
116 }
117
118 chunk = kmalloc(CHUNK_SIZE, GFP_KERNEL);
119 if (!chunk) {
120 wl1271_error("allocation for firmware upload chunk failed");
121 return -ENOMEM;
122 }
123
124 memcpy(&partition, &wl->ptable[PART_DOWN], sizeof(partition));
125 partition.mem.start = dest;
126 wlcore_set_partition(wl, &partition);
127
128 /* 10.1 set partition limit and chunk num */
129 chunk_num = 0;
130 partition_limit = wl->ptable[PART_DOWN].mem.size;
131
132 while (chunk_num < fw_data_len / CHUNK_SIZE) {
133 /* 10.2 update partition, if needed */
134 addr = dest + (chunk_num + 2) * CHUNK_SIZE;
135 if (addr > partition_limit) {
136 addr = dest + chunk_num * CHUNK_SIZE;
137 partition_limit = chunk_num * CHUNK_SIZE +
138 wl->ptable[PART_DOWN].mem.size;
139 partition.mem.start = addr;
140 wlcore_set_partition(wl, &partition);
141 }
142
143 /* 10.3 upload the chunk */
144 addr = dest + chunk_num * CHUNK_SIZE;
145 p = buf + chunk_num * CHUNK_SIZE;
146 memcpy(chunk, p, CHUNK_SIZE);
147 wl1271_debug(DEBUG_BOOT, "uploading fw chunk 0x%p to 0x%x",
148 p, addr);
149 wl1271_write(wl, addr, chunk, CHUNK_SIZE, false);
150
151 chunk_num++;
152 }
153
154 /* 10.4 upload the last chunk */
155 addr = dest + chunk_num * CHUNK_SIZE;
156 p = buf + chunk_num * CHUNK_SIZE;
157 memcpy(chunk, p, fw_data_len % CHUNK_SIZE);
158 wl1271_debug(DEBUG_BOOT, "uploading fw last chunk (%zd B) 0x%p to 0x%x",
159 fw_data_len % CHUNK_SIZE, p, addr);
160 wl1271_write(wl, addr, chunk, fw_data_len % CHUNK_SIZE, false);
161
162 kfree(chunk);
163 return 0;
164}
165
166int wlcore_boot_upload_firmware(struct wl1271 *wl)
167{
168 u32 chunks, addr, len;
169 int ret = 0;
170 u8 *fw;
171
172 fw = wl->fw;
173 chunks = be32_to_cpup((__be32 *) fw);
174 fw += sizeof(u32);
175
176 wl1271_debug(DEBUG_BOOT, "firmware chunks to be uploaded: %u", chunks);
177
178 while (chunks--) {
179 addr = be32_to_cpup((__be32 *) fw);
180 fw += sizeof(u32);
181 len = be32_to_cpup((__be32 *) fw);
182 fw += sizeof(u32);
183
184 if (len > 300000) {
185 wl1271_info("firmware chunk too long: %u", len);
186 return -EINVAL;
187 }
188 wl1271_debug(DEBUG_BOOT, "chunk %d addr 0x%x len %u",
189 chunks, addr, len);
190 ret = wl1271_boot_upload_firmware_chunk(wl, fw, len, addr);
191 if (ret != 0)
192 break;
193 fw += len;
194 }
195
196 return ret;
197}
198EXPORT_SYMBOL_GPL(wlcore_boot_upload_firmware);
199
200int wlcore_boot_upload_nvs(struct wl1271 *wl)
201{
202 size_t nvs_len, burst_len;
203 int i;
204 u32 dest_addr, val;
205 u8 *nvs_ptr, *nvs_aligned;
206
207 if (wl->nvs == NULL)
208 return -ENODEV;
209
210 if (wl->quirks & WLCORE_QUIRK_LEGACY_NVS) {
211 struct wl1271_nvs_file *nvs =
212 (struct wl1271_nvs_file *)wl->nvs;
213 /*
214 * FIXME: the LEGACY NVS image support (NVS's missing the 5GHz
215 * band configurations) can be removed when those NVS files stop
216 * floating around.
217 */
218 if (wl->nvs_len == sizeof(struct wl1271_nvs_file) ||
219 wl->nvs_len == WL1271_INI_LEGACY_NVS_FILE_SIZE) {
220 if (nvs->general_params.dual_mode_select)
221 wl->enable_11a = true;
222 }
223
224 if (wl->nvs_len != sizeof(struct wl1271_nvs_file) &&
225 (wl->nvs_len != WL1271_INI_LEGACY_NVS_FILE_SIZE ||
226 wl->enable_11a)) {
227 wl1271_error("nvs size is not as expected: %zu != %zu",
228 wl->nvs_len, sizeof(struct wl1271_nvs_file));
229 kfree(wl->nvs);
230 wl->nvs = NULL;
231 wl->nvs_len = 0;
232 return -EILSEQ;
233 }
234
235 /* only the first part of the NVS needs to be uploaded */
236 nvs_len = sizeof(nvs->nvs);
237 nvs_ptr = (u8 *) nvs->nvs;
238 } else {
239 struct wl128x_nvs_file *nvs = (struct wl128x_nvs_file *)wl->nvs;
240
241 if (wl->nvs_len == sizeof(struct wl128x_nvs_file)) {
242 if (nvs->general_params.dual_mode_select)
243 wl->enable_11a = true;
244 } else {
245 wl1271_error("nvs size is not as expected: %zu != %zu",
246 wl->nvs_len,
247 sizeof(struct wl128x_nvs_file));
248 kfree(wl->nvs);
249 wl->nvs = NULL;
250 wl->nvs_len = 0;
251 return -EILSEQ;
252 }
253
254 /* only the first part of the NVS needs to be uploaded */
255 nvs_len = sizeof(nvs->nvs);
256 nvs_ptr = (u8 *)nvs->nvs;
257 }
258
259 /* update current MAC address to NVS */
260 nvs_ptr[11] = wl->addresses[0].addr[0];
261 nvs_ptr[10] = wl->addresses[0].addr[1];
262 nvs_ptr[6] = wl->addresses[0].addr[2];
263 nvs_ptr[5] = wl->addresses[0].addr[3];
264 nvs_ptr[4] = wl->addresses[0].addr[4];
265 nvs_ptr[3] = wl->addresses[0].addr[5];
266
267 /*
268 * Layout before the actual NVS tables:
269 * 1 byte : burst length.
270 * 2 bytes: destination address.
271 * n bytes: data to burst copy.
272 *
273 * This is ended by a 0 length, then the NVS tables.
274 */
275
276 /* FIXME: Do we need to check here whether the LSB is 1? */
277 while (nvs_ptr[0]) {
278 burst_len = nvs_ptr[0];
279 dest_addr = (nvs_ptr[1] & 0xfe) | ((u32)(nvs_ptr[2] << 8));
280
281 /*
282 * Due to our new wl1271_translate_reg_addr function,
283 * we need to add the register partition start address
284 * to the destination
285 */
286 dest_addr += wl->curr_part.reg.start;
287
288 /* We move our pointer to the data */
289 nvs_ptr += 3;
290
291 for (i = 0; i < burst_len; i++) {
292 if (nvs_ptr + 3 >= (u8 *) wl->nvs + nvs_len)
293 goto out_badnvs;
294
295 val = (nvs_ptr[0] | (nvs_ptr[1] << 8)
296 | (nvs_ptr[2] << 16) | (nvs_ptr[3] << 24));
297
298 wl1271_debug(DEBUG_BOOT,
299 "nvs burst write 0x%x: 0x%x",
300 dest_addr, val);
301 wl1271_write32(wl, dest_addr, val);
302
303 nvs_ptr += 4;
304 dest_addr += 4;
305 }
306
307 if (nvs_ptr >= (u8 *) wl->nvs + nvs_len)
308 goto out_badnvs;
309 }
310
311 /*
312 * We've reached the first zero length, the first NVS table
313 * is located at an aligned offset which is at least 7 bytes further.
314 * NOTE: The wl->nvs->nvs element must be first, in order to
315 * simplify the casting, we assume it is at the beginning of
316 * the wl->nvs structure.
317 */
318 nvs_ptr = (u8 *)wl->nvs +
319 ALIGN(nvs_ptr - (u8 *)wl->nvs + 7, 4);
320
321 if (nvs_ptr >= (u8 *) wl->nvs + nvs_len)
322 goto out_badnvs;
323
324 nvs_len -= nvs_ptr - (u8 *)wl->nvs;
325
326 /* Now we must set the partition correctly */
327 wlcore_set_partition(wl, &wl->ptable[PART_WORK]);
328
329 /* Copy the NVS tables to a new block to ensure alignment */
330 nvs_aligned = kmemdup(nvs_ptr, nvs_len, GFP_KERNEL);
331 if (!nvs_aligned)
332 return -ENOMEM;
333
334 /* And finally we upload the NVS tables */
335 wlcore_write_data(wl, REG_CMD_MBOX_ADDRESS,
336 nvs_aligned, nvs_len, false);
337
338 kfree(nvs_aligned);
339 return 0;
340
341out_badnvs:
342 wl1271_error("nvs data is malformed");
343 return -EILSEQ;
344}
345EXPORT_SYMBOL_GPL(wlcore_boot_upload_nvs);
346
347int wlcore_boot_run_firmware(struct wl1271 *wl)
348{
349 int loop, ret;
350 u32 chip_id, intr;
351
352 /* Make sure we have the boot partition */
353 wlcore_set_partition(wl, &wl->ptable[PART_BOOT]);
354
355 wl1271_boot_set_ecpu_ctrl(wl, ECPU_CONTROL_HALT);
356
357 chip_id = wlcore_read_reg(wl, REG_CHIP_ID_B);
358
359 wl1271_debug(DEBUG_BOOT, "chip id after firmware boot: 0x%x", chip_id);
360
361 if (chip_id != wl->chip.id) {
362 wl1271_error("chip id doesn't match after firmware boot");
363 return -EIO;
364 }
365
366 /* wait for init to complete */
367 loop = 0;
368 while (loop++ < INIT_LOOP) {
369 udelay(INIT_LOOP_DELAY);
370 intr = wlcore_read_reg(wl, REG_INTERRUPT_NO_CLEAR);
371
372 if (intr == 0xffffffff) {
373 wl1271_error("error reading hardware complete "
374 "init indication");
375 return -EIO;
376 }
377 /* check that ACX_INTR_INIT_COMPLETE is enabled */
378 else if (intr & WL1271_ACX_INTR_INIT_COMPLETE) {
379 wlcore_write_reg(wl, REG_INTERRUPT_ACK,
380 WL1271_ACX_INTR_INIT_COMPLETE);
381 break;
382 }
383 }
384
385 if (loop > INIT_LOOP) {
386 wl1271_error("timeout waiting for the hardware to "
387 "complete initialization");
388 return -EIO;
389 }
390
391 /* get hardware config command mail box */
392 wl->cmd_box_addr = wlcore_read_reg(wl, REG_COMMAND_MAILBOX_PTR);
393
394 wl1271_debug(DEBUG_MAILBOX, "cmd_box_addr 0x%x", wl->cmd_box_addr);
395
396 /* get hardware config event mail box */
397 wl->mbox_ptr[0] = wlcore_read_reg(wl, REG_EVENT_MAILBOX_PTR);
398 wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox);
399
400 wl1271_debug(DEBUG_MAILBOX, "MBOX ptrs: 0x%x 0x%x",
401 wl->mbox_ptr[0], wl->mbox_ptr[1]);
402
403 ret = wlcore_boot_fw_version(wl);
404 if (ret < 0) {
405 wl1271_error("couldn't boot firmware");
406 return ret;
407 }
408
409 /*
410 * in case of full asynchronous mode the firmware event must be
411 * ready to receive event from the command mailbox
412 */
413
414 /* unmask required mbox events */
415 wl->event_mask = BSS_LOSE_EVENT_ID |
416 SCAN_COMPLETE_EVENT_ID |
417 ROLE_STOP_COMPLETE_EVENT_ID |
418 RSSI_SNR_TRIGGER_0_EVENT_ID |
419 PSPOLL_DELIVERY_FAILURE_EVENT_ID |
420 SOFT_GEMINI_SENSE_EVENT_ID |
421 PERIODIC_SCAN_REPORT_EVENT_ID |
422 PERIODIC_SCAN_COMPLETE_EVENT_ID |
423 DUMMY_PACKET_EVENT_ID |
424 PEER_REMOVE_COMPLETE_EVENT_ID |
425 BA_SESSION_RX_CONSTRAINT_EVENT_ID |
426 REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID |
427 INACTIVE_STA_EVENT_ID |
428 MAX_TX_RETRY_EVENT_ID |
429 CHANNEL_SWITCH_COMPLETE_EVENT_ID;
430
431 ret = wl1271_event_unmask(wl);
432 if (ret < 0) {
433 wl1271_error("EVENT mask setting failed");
434 return ret;
435 }
436
437 /* set the working partition to its "running" mode offset */
438 wlcore_set_partition(wl, &wl->ptable[PART_WORK]);
439
440 /* firmware startup completed */
441 return 0;
442}
443EXPORT_SYMBOL_GPL(wlcore_boot_run_firmware);
diff --git a/drivers/net/wireless/ti/wlcore/boot.h b/drivers/net/wireless/ti/wlcore/boot.h
new file mode 100644
index 000000000000..094981dd2227
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/boot.h
@@ -0,0 +1,54 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2008-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#ifndef __BOOT_H__
25#define __BOOT_H__
26
27#include "wlcore.h"
28
29int wlcore_boot_upload_firmware(struct wl1271 *wl);
30int wlcore_boot_upload_nvs(struct wl1271 *wl);
31int wlcore_boot_run_firmware(struct wl1271 *wl);
32
33#define WL1271_NO_SUBBANDS 8
34#define WL1271_NO_POWER_LEVELS 4
35#define WL1271_FW_VERSION_MAX_LEN 20
36
37struct wl1271_static_data {
38 u8 mac_address[ETH_ALEN];
39 u8 padding[2];
40 u8 fw_version[WL1271_FW_VERSION_MAX_LEN];
41 u32 hw_version;
42 u8 tx_power_table[WL1271_NO_SUBBANDS][WL1271_NO_POWER_LEVELS];
43};
44
45/* number of times we try to read the INIT interrupt */
46#define INIT_LOOP 20000
47
48/* delay between retries */
49#define INIT_LOOP_DELAY 50
50
51#define WU_COUNTER_PAUSE_VAL 0x3FF
52#define WELP_ARM_COMMAND_VAL 0x4
53
54#endif
diff --git a/drivers/net/wireless/ti/wlcore/cmd.c b/drivers/net/wireless/ti/wlcore/cmd.c
new file mode 100644
index 000000000000..5c4716c6f040
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/cmd.c
@@ -0,0 +1,1728 @@
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/module.h>
25#include <linux/platform_device.h>
26#include <linux/spi/spi.h>
27#include <linux/etherdevice.h>
28#include <linux/ieee80211.h>
29#include <linux/slab.h>
30
31#include "wlcore.h"
32#include "debug.h"
33#include "io.h"
34#include "acx.h"
35#include "wl12xx_80211.h"
36#include "cmd.h"
37#include "event.h"
38#include "tx.h"
39
40#define WL1271_CMD_FAST_POLL_COUNT 50
41
42/*
43 * send command to firmware
44 *
45 * @wl: wl struct
46 * @id: command id
47 * @buf: buffer containing the command, must work with dma
48 * @len: length of the buffer
49 */
50int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
51 size_t res_len)
52{
53 struct wl1271_cmd_header *cmd;
54 unsigned long timeout;
55 u32 intr;
56 int ret = 0;
57 u16 status;
58 u16 poll_count = 0;
59
60 cmd = buf;
61 cmd->id = cpu_to_le16(id);
62 cmd->status = 0;
63
64 WARN_ON(len % 4 != 0);
65 WARN_ON(test_bit(WL1271_FLAG_IN_ELP, &wl->flags));
66
67 wl1271_write(wl, wl->cmd_box_addr, buf, len, false);
68
69 /*
70 * TODO: we just need this because one bit is in a different
71 * place. Is there any better way?
72 */
73 wl->ops->trigger_cmd(wl, wl->cmd_box_addr, buf, len);
74
75 timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT);
76
77 intr = wlcore_read_reg(wl, REG_INTERRUPT_NO_CLEAR);
78 while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) {
79 if (time_after(jiffies, timeout)) {
80 wl1271_error("command complete timeout");
81 ret = -ETIMEDOUT;
82 goto fail;
83 }
84
85 poll_count++;
86 if (poll_count < WL1271_CMD_FAST_POLL_COUNT)
87 udelay(10);
88 else
89 msleep(1);
90
91 intr = wlcore_read_reg(wl, REG_INTERRUPT_NO_CLEAR);
92 }
93
94 /* read back the status code of the command */
95 if (res_len == 0)
96 res_len = sizeof(struct wl1271_cmd_header);
97 wl1271_read(wl, wl->cmd_box_addr, cmd, res_len, false);
98
99 status = le16_to_cpu(cmd->status);
100 if (status != CMD_STATUS_SUCCESS) {
101 wl1271_error("command execute failure %d", status);
102 ret = -EIO;
103 goto fail;
104 }
105
106 wlcore_write_reg(wl, REG_INTERRUPT_ACK, WL1271_ACX_INTR_CMD_COMPLETE);
107 return 0;
108
109fail:
110 WARN_ON(1);
111 wl12xx_queue_recovery_work(wl);
112 return ret;
113}
114
115/*
116 * Poll the mailbox event field until any of the bits in the mask is set or a
117 * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
118 */
119static int wl1271_cmd_wait_for_event_or_timeout(struct wl1271 *wl, u32 mask)
120{
121 u32 *events_vector;
122 u32 event;
123 unsigned long timeout;
124 int ret = 0;
125
126 events_vector = kmalloc(sizeof(*events_vector), GFP_DMA);
127
128 timeout = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT);
129
130 do {
131 if (time_after(jiffies, timeout)) {
132 wl1271_debug(DEBUG_CMD, "timeout waiting for event %d",
133 (int)mask);
134 ret = -ETIMEDOUT;
135 goto out;
136 }
137
138 msleep(1);
139
140 /* read from both event fields */
141 wl1271_read(wl, wl->mbox_ptr[0], events_vector,
142 sizeof(*events_vector), false);
143 event = *events_vector & mask;
144 wl1271_read(wl, wl->mbox_ptr[1], events_vector,
145 sizeof(*events_vector), false);
146 event |= *events_vector & mask;
147 } while (!event);
148
149out:
150 kfree(events_vector);
151 return ret;
152}
153
154static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask)
155{
156 int ret;
157
158 ret = wl1271_cmd_wait_for_event_or_timeout(wl, mask);
159 if (ret != 0) {
160 wl12xx_queue_recovery_work(wl);
161 return ret;
162 }
163
164 return 0;
165}
166
167int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 *addr, u8 role_type,
168 u8 *role_id)
169{
170 struct wl12xx_cmd_role_enable *cmd;
171 int ret;
172
173 wl1271_debug(DEBUG_CMD, "cmd role enable");
174
175 if (WARN_ON(*role_id != WL12XX_INVALID_ROLE_ID))
176 return -EBUSY;
177
178 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
179 if (!cmd) {
180 ret = -ENOMEM;
181 goto out;
182 }
183
184 /* get role id */
185 cmd->role_id = find_first_zero_bit(wl->roles_map, WL12XX_MAX_ROLES);
186 if (cmd->role_id >= WL12XX_MAX_ROLES) {
187 ret = -EBUSY;
188 goto out_free;
189 }
190
191 memcpy(cmd->mac_address, addr, ETH_ALEN);
192 cmd->role_type = role_type;
193
194 ret = wl1271_cmd_send(wl, CMD_ROLE_ENABLE, cmd, sizeof(*cmd), 0);
195 if (ret < 0) {
196 wl1271_error("failed to initiate cmd role enable");
197 goto out_free;
198 }
199
200 __set_bit(cmd->role_id, wl->roles_map);
201 *role_id = cmd->role_id;
202
203out_free:
204 kfree(cmd);
205
206out:
207 return ret;
208}
209
210int wl12xx_cmd_role_disable(struct wl1271 *wl, u8 *role_id)
211{
212 struct wl12xx_cmd_role_disable *cmd;
213 int ret;
214
215 wl1271_debug(DEBUG_CMD, "cmd role disable");
216
217 if (WARN_ON(*role_id == WL12XX_INVALID_ROLE_ID))
218 return -ENOENT;
219
220 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
221 if (!cmd) {
222 ret = -ENOMEM;
223 goto out;
224 }
225 cmd->role_id = *role_id;
226
227 ret = wl1271_cmd_send(wl, CMD_ROLE_DISABLE, cmd, sizeof(*cmd), 0);
228 if (ret < 0) {
229 wl1271_error("failed to initiate cmd role disable");
230 goto out_free;
231 }
232
233 __clear_bit(*role_id, wl->roles_map);
234 *role_id = WL12XX_INVALID_ROLE_ID;
235
236out_free:
237 kfree(cmd);
238
239out:
240 return ret;
241}
242
243int wl12xx_allocate_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid)
244{
245 unsigned long flags;
246 u8 link = find_first_zero_bit(wl->links_map, WL12XX_MAX_LINKS);
247 if (link >= WL12XX_MAX_LINKS)
248 return -EBUSY;
249
250 /* these bits are used by op_tx */
251 spin_lock_irqsave(&wl->wl_lock, flags);
252 __set_bit(link, wl->links_map);
253 __set_bit(link, wlvif->links_map);
254 spin_unlock_irqrestore(&wl->wl_lock, flags);
255 *hlid = link;
256 return 0;
257}
258
259void wl12xx_free_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid)
260{
261 unsigned long flags;
262
263 if (*hlid == WL12XX_INVALID_LINK_ID)
264 return;
265
266 /* these bits are used by op_tx */
267 spin_lock_irqsave(&wl->wl_lock, flags);
268 __clear_bit(*hlid, wl->links_map);
269 __clear_bit(*hlid, wlvif->links_map);
270 spin_unlock_irqrestore(&wl->wl_lock, flags);
271
272 /*
273 * At this point op_tx() will not add more packets to the queues. We
274 * can purge them.
275 */
276 wl1271_tx_reset_link_queues(wl, *hlid);
277
278 *hlid = WL12XX_INVALID_LINK_ID;
279}
280
281static int wl12xx_get_new_session_id(struct wl1271 *wl,
282 struct wl12xx_vif *wlvif)
283{
284 if (wlvif->session_counter >= SESSION_COUNTER_MAX)
285 wlvif->session_counter = 0;
286
287 wlvif->session_counter++;
288
289 return wlvif->session_counter;
290}
291
292static int wl12xx_cmd_role_start_dev(struct wl1271 *wl,
293 struct wl12xx_vif *wlvif)
294{
295 struct wl12xx_cmd_role_start *cmd;
296 int ret;
297
298 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
299 if (!cmd) {
300 ret = -ENOMEM;
301 goto out;
302 }
303
304 wl1271_debug(DEBUG_CMD, "cmd role start dev %d", wlvif->dev_role_id);
305
306 cmd->role_id = wlvif->dev_role_id;
307 if (wlvif->band == IEEE80211_BAND_5GHZ)
308 cmd->band = WLCORE_BAND_5GHZ;
309 cmd->channel = wlvif->channel;
310
311 if (wlvif->dev_hlid == WL12XX_INVALID_LINK_ID) {
312 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->dev_hlid);
313 if (ret)
314 goto out_free;
315 }
316 cmd->device.hlid = wlvif->dev_hlid;
317 cmd->device.session = wl12xx_get_new_session_id(wl, wlvif);
318
319 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d",
320 cmd->role_id, cmd->device.hlid, cmd->device.session);
321
322 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
323 if (ret < 0) {
324 wl1271_error("failed to initiate cmd role enable");
325 goto err_hlid;
326 }
327
328 goto out_free;
329
330err_hlid:
331 /* clear links on error */
332 wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid);
333
334out_free:
335 kfree(cmd);
336
337out:
338 return ret;
339}
340
341static int wl12xx_cmd_role_stop_dev(struct wl1271 *wl,
342 struct wl12xx_vif *wlvif)
343{
344 struct wl12xx_cmd_role_stop *cmd;
345 int ret;
346
347 if (WARN_ON(wlvif->dev_hlid == WL12XX_INVALID_LINK_ID))
348 return -EINVAL;
349
350 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
351 if (!cmd) {
352 ret = -ENOMEM;
353 goto out;
354 }
355
356 wl1271_debug(DEBUG_CMD, "cmd role stop dev");
357
358 cmd->role_id = wlvif->dev_role_id;
359 cmd->disc_type = DISCONNECT_IMMEDIATE;
360 cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
361
362 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
363 if (ret < 0) {
364 wl1271_error("failed to initiate cmd role stop");
365 goto out_free;
366 }
367
368 ret = wl1271_cmd_wait_for_event(wl, ROLE_STOP_COMPLETE_EVENT_ID);
369 if (ret < 0) {
370 wl1271_error("cmd role stop dev event completion error");
371 goto out_free;
372 }
373
374 wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid);
375
376out_free:
377 kfree(cmd);
378
379out:
380 return ret;
381}
382
383int wl12xx_cmd_role_start_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
384{
385 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
386 struct wl12xx_cmd_role_start *cmd;
387 int ret;
388
389 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
390 if (!cmd) {
391 ret = -ENOMEM;
392 goto out;
393 }
394
395 wl1271_debug(DEBUG_CMD, "cmd role start sta %d", wlvif->role_id);
396
397 cmd->role_id = wlvif->role_id;
398 if (wlvif->band == IEEE80211_BAND_5GHZ)
399 cmd->band = WLCORE_BAND_5GHZ;
400 cmd->channel = wlvif->channel;
401 cmd->sta.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
402 cmd->sta.beacon_interval = cpu_to_le16(wlvif->beacon_int);
403 cmd->sta.ssid_type = WL12XX_SSID_TYPE_ANY;
404 cmd->sta.ssid_len = wlvif->ssid_len;
405 memcpy(cmd->sta.ssid, wlvif->ssid, wlvif->ssid_len);
406 memcpy(cmd->sta.bssid, vif->bss_conf.bssid, ETH_ALEN);
407 cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set);
408
409 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
410 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
411 if (ret)
412 goto out_free;
413 }
414 cmd->sta.hlid = wlvif->sta.hlid;
415 cmd->sta.session = wl12xx_get_new_session_id(wl, wlvif);
416 cmd->sta.remote_rates = cpu_to_le32(wlvif->rate_set);
417
418 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
419 "basic_rate_set: 0x%x, remote_rates: 0x%x",
420 wlvif->role_id, cmd->sta.hlid, cmd->sta.session,
421 wlvif->basic_rate_set, wlvif->rate_set);
422
423 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
424 if (ret < 0) {
425 wl1271_error("failed to initiate cmd role start sta");
426 goto err_hlid;
427 }
428
429 goto out_free;
430
431err_hlid:
432 /* clear links on error. */
433 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
434
435out_free:
436 kfree(cmd);
437
438out:
439 return ret;
440}
441
442/* use this function to stop ibss as well */
443int wl12xx_cmd_role_stop_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
444{
445 struct wl12xx_cmd_role_stop *cmd;
446 int ret;
447
448 if (WARN_ON(wlvif->sta.hlid == WL12XX_INVALID_LINK_ID))
449 return -EINVAL;
450
451 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
452 if (!cmd) {
453 ret = -ENOMEM;
454 goto out;
455 }
456
457 wl1271_debug(DEBUG_CMD, "cmd role stop sta %d", wlvif->role_id);
458
459 cmd->role_id = wlvif->role_id;
460 cmd->disc_type = DISCONNECT_IMMEDIATE;
461 cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
462
463 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
464 if (ret < 0) {
465 wl1271_error("failed to initiate cmd role stop sta");
466 goto out_free;
467 }
468
469 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
470
471out_free:
472 kfree(cmd);
473
474out:
475 return ret;
476}
477
478int wl12xx_cmd_role_start_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
479{
480 struct wl12xx_cmd_role_start *cmd;
481 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
482 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
483 int ret;
484
485 wl1271_debug(DEBUG_CMD, "cmd role start ap %d", wlvif->role_id);
486
487 /* trying to use hidden SSID with an old hostapd version */
488 if (wlvif->ssid_len == 0 && !bss_conf->hidden_ssid) {
489 wl1271_error("got a null SSID from beacon/bss");
490 ret = -EINVAL;
491 goto out;
492 }
493
494 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
495 if (!cmd) {
496 ret = -ENOMEM;
497 goto out;
498 }
499
500 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.global_hlid);
501 if (ret < 0)
502 goto out_free;
503
504 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.bcast_hlid);
505 if (ret < 0)
506 goto out_free_global;
507
508 cmd->role_id = wlvif->role_id;
509 cmd->ap.aging_period = cpu_to_le16(wl->conf.tx.ap_aging_period);
510 cmd->ap.bss_index = WL1271_AP_BSS_INDEX;
511 cmd->ap.global_hlid = wlvif->ap.global_hlid;
512 cmd->ap.broadcast_hlid = wlvif->ap.bcast_hlid;
513 cmd->ap.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
514 cmd->ap.beacon_interval = cpu_to_le16(wlvif->beacon_int);
515 cmd->ap.dtim_interval = bss_conf->dtim_period;
516 cmd->ap.beacon_expiry = WL1271_AP_DEF_BEACON_EXP;
517 /* FIXME: Change when adding DFS */
518 cmd->ap.reset_tsf = 1; /* By default reset AP TSF */
519 cmd->channel = wlvif->channel;
520
521 if (!bss_conf->hidden_ssid) {
522 /* take the SSID from the beacon for backward compatibility */
523 cmd->ap.ssid_type = WL12XX_SSID_TYPE_PUBLIC;
524 cmd->ap.ssid_len = wlvif->ssid_len;
525 memcpy(cmd->ap.ssid, wlvif->ssid, wlvif->ssid_len);
526 } else {
527 cmd->ap.ssid_type = WL12XX_SSID_TYPE_HIDDEN;
528 cmd->ap.ssid_len = bss_conf->ssid_len;
529 memcpy(cmd->ap.ssid, bss_conf->ssid, bss_conf->ssid_len);
530 }
531
532 cmd->ap.local_rates = cpu_to_le32(0xffffffff);
533
534 switch (wlvif->band) {
535 case IEEE80211_BAND_2GHZ:
536 cmd->band = WLCORE_BAND_2_4GHZ;
537 break;
538 case IEEE80211_BAND_5GHZ:
539 cmd->band = WLCORE_BAND_5GHZ;
540 break;
541 default:
542 wl1271_warning("ap start - unknown band: %d", (int)wlvif->band);
543 cmd->band = WLCORE_BAND_2_4GHZ;
544 break;
545 }
546
547 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
548 if (ret < 0) {
549 wl1271_error("failed to initiate cmd role start ap");
550 goto out_free_bcast;
551 }
552
553 goto out_free;
554
555out_free_bcast:
556 wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid);
557
558out_free_global:
559 wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid);
560
561out_free:
562 kfree(cmd);
563
564out:
565 return ret;
566}
567
568int wl12xx_cmd_role_stop_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
569{
570 struct wl12xx_cmd_role_stop *cmd;
571 int ret;
572
573 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
574 if (!cmd) {
575 ret = -ENOMEM;
576 goto out;
577 }
578
579 wl1271_debug(DEBUG_CMD, "cmd role stop ap %d", wlvif->role_id);
580
581 cmd->role_id = wlvif->role_id;
582
583 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
584 if (ret < 0) {
585 wl1271_error("failed to initiate cmd role stop ap");
586 goto out_free;
587 }
588
589 wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid);
590 wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid);
591
592out_free:
593 kfree(cmd);
594
595out:
596 return ret;
597}
598
599int wl12xx_cmd_role_start_ibss(struct wl1271 *wl, struct wl12xx_vif *wlvif)
600{
601 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
602 struct wl12xx_cmd_role_start *cmd;
603 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
604 int ret;
605
606 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
607 if (!cmd) {
608 ret = -ENOMEM;
609 goto out;
610 }
611
612 wl1271_debug(DEBUG_CMD, "cmd role start ibss %d", wlvif->role_id);
613
614 cmd->role_id = wlvif->role_id;
615 if (wlvif->band == IEEE80211_BAND_5GHZ)
616 cmd->band = WLCORE_BAND_5GHZ;
617 cmd->channel = wlvif->channel;
618 cmd->ibss.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
619 cmd->ibss.beacon_interval = cpu_to_le16(wlvif->beacon_int);
620 cmd->ibss.dtim_interval = bss_conf->dtim_period;
621 cmd->ibss.ssid_type = WL12XX_SSID_TYPE_ANY;
622 cmd->ibss.ssid_len = wlvif->ssid_len;
623 memcpy(cmd->ibss.ssid, wlvif->ssid, wlvif->ssid_len);
624 memcpy(cmd->ibss.bssid, vif->bss_conf.bssid, ETH_ALEN);
625 cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set);
626
627 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
628 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
629 if (ret)
630 goto out_free;
631 }
632 cmd->ibss.hlid = wlvif->sta.hlid;
633 cmd->ibss.remote_rates = cpu_to_le32(wlvif->rate_set);
634
635 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
636 "basic_rate_set: 0x%x, remote_rates: 0x%x",
637 wlvif->role_id, cmd->sta.hlid, cmd->sta.session,
638 wlvif->basic_rate_set, wlvif->rate_set);
639
640 wl1271_debug(DEBUG_CMD, "vif->bss_conf.bssid = %pM",
641 vif->bss_conf.bssid);
642
643 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
644 if (ret < 0) {
645 wl1271_error("failed to initiate cmd role enable");
646 goto err_hlid;
647 }
648
649 goto out_free;
650
651err_hlid:
652 /* clear links on error. */
653 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
654
655out_free:
656 kfree(cmd);
657
658out:
659 return ret;
660}
661
662
663/**
664 * send test command to firmware
665 *
666 * @wl: wl struct
667 * @buf: buffer containing the command, with all headers, must work with dma
668 * @len: length of the buffer
669 * @answer: is answer needed
670 */
671int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
672{
673 int ret;
674 size_t res_len = 0;
675
676 wl1271_debug(DEBUG_CMD, "cmd test");
677
678 if (answer)
679 res_len = buf_len;
680
681 ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
682
683 if (ret < 0) {
684 wl1271_warning("TEST command failed");
685 return ret;
686 }
687
688 return ret;
689}
690EXPORT_SYMBOL_GPL(wl1271_cmd_test);
691
692/**
693 * read acx from firmware
694 *
695 * @wl: wl struct
696 * @id: acx id
697 * @buf: buffer for the response, including all headers, must work with dma
698 * @len: length of buf
699 */
700int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
701{
702 struct acx_header *acx = buf;
703 int ret;
704
705 wl1271_debug(DEBUG_CMD, "cmd interrogate");
706
707 acx->id = cpu_to_le16(id);
708
709 /* payload length, does not include any headers */
710 acx->len = cpu_to_le16(len - sizeof(*acx));
711
712 ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
713 if (ret < 0)
714 wl1271_error("INTERROGATE command failed");
715
716 return ret;
717}
718
719/**
720 * write acx value to firmware
721 *
722 * @wl: wl struct
723 * @id: acx id
724 * @buf: buffer containing acx, including all headers, must work with dma
725 * @len: length of buf
726 */
727int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
728{
729 struct acx_header *acx = buf;
730 int ret;
731
732 wl1271_debug(DEBUG_CMD, "cmd configure (%d)", id);
733
734 acx->id = cpu_to_le16(id);
735
736 /* payload length, does not include any headers */
737 acx->len = cpu_to_le16(len - sizeof(*acx));
738
739 ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0);
740 if (ret < 0) {
741 wl1271_warning("CONFIGURE command NOK");
742 return ret;
743 }
744
745 return 0;
746}
747EXPORT_SYMBOL_GPL(wl1271_cmd_configure);
748
749int wl1271_cmd_data_path(struct wl1271 *wl, bool enable)
750{
751 struct cmd_enabledisable_path *cmd;
752 int ret;
753 u16 cmd_rx, cmd_tx;
754
755 wl1271_debug(DEBUG_CMD, "cmd data path");
756
757 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
758 if (!cmd) {
759 ret = -ENOMEM;
760 goto out;
761 }
762
763 /* the channel here is only used for calibration, so hardcoded to 1 */
764 cmd->channel = 1;
765
766 if (enable) {
767 cmd_rx = CMD_ENABLE_RX;
768 cmd_tx = CMD_ENABLE_TX;
769 } else {
770 cmd_rx = CMD_DISABLE_RX;
771 cmd_tx = CMD_DISABLE_TX;
772 }
773
774 ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
775 if (ret < 0) {
776 wl1271_error("rx %s cmd for channel %d failed",
777 enable ? "start" : "stop", cmd->channel);
778 goto out;
779 }
780
781 wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
782 enable ? "start" : "stop", cmd->channel);
783
784 ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
785 if (ret < 0) {
786 wl1271_error("tx %s cmd for channel %d failed",
787 enable ? "start" : "stop", cmd->channel);
788 goto out;
789 }
790
791 wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
792 enable ? "start" : "stop", cmd->channel);
793
794out:
795 kfree(cmd);
796 return ret;
797}
798
799int wl1271_cmd_ps_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
800 u8 ps_mode, u16 auto_ps_timeout)
801{
802 struct wl1271_cmd_ps_params *ps_params = NULL;
803 int ret = 0;
804
805 wl1271_debug(DEBUG_CMD, "cmd set ps mode");
806
807 ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
808 if (!ps_params) {
809 ret = -ENOMEM;
810 goto out;
811 }
812
813 ps_params->role_id = wlvif->role_id;
814 ps_params->ps_mode = ps_mode;
815 ps_params->auto_ps_timeout = auto_ps_timeout;
816
817 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
818 sizeof(*ps_params), 0);
819 if (ret < 0) {
820 wl1271_error("cmd set_ps_mode failed");
821 goto out;
822 }
823
824out:
825 kfree(ps_params);
826 return ret;
827}
828
829int wl1271_cmd_template_set(struct wl1271 *wl, u8 role_id,
830 u16 template_id, void *buf, size_t buf_len,
831 int index, u32 rates)
832{
833 struct wl1271_cmd_template_set *cmd;
834 int ret = 0;
835
836 wl1271_debug(DEBUG_CMD, "cmd template_set %d (role %d)",
837 template_id, role_id);
838
839 WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE);
840 buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE);
841
842 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
843 if (!cmd) {
844 ret = -ENOMEM;
845 goto out;
846 }
847
848 /* during initialization wlvif is NULL */
849 cmd->role_id = role_id;
850 cmd->len = cpu_to_le16(buf_len);
851 cmd->template_type = template_id;
852 cmd->enabled_rates = cpu_to_le32(rates);
853 cmd->short_retry_limit = wl->conf.tx.tmpl_short_retry_limit;
854 cmd->long_retry_limit = wl->conf.tx.tmpl_long_retry_limit;
855 cmd->index = index;
856
857 if (buf)
858 memcpy(cmd->template_data, buf, buf_len);
859
860 ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
861 if (ret < 0) {
862 wl1271_warning("cmd set_template failed: %d", ret);
863 goto out_free;
864 }
865
866out_free:
867 kfree(cmd);
868
869out:
870 return ret;
871}
872
873int wl12xx_cmd_build_null_data(struct wl1271 *wl, struct wl12xx_vif *wlvif)
874{
875 struct sk_buff *skb = NULL;
876 int size;
877 void *ptr;
878 int ret = -ENOMEM;
879
880
881 if (wlvif->bss_type == BSS_TYPE_IBSS) {
882 size = sizeof(struct wl12xx_null_data_template);
883 ptr = NULL;
884 } else {
885 skb = ieee80211_nullfunc_get(wl->hw,
886 wl12xx_wlvif_to_vif(wlvif));
887 if (!skb)
888 goto out;
889 size = skb->len;
890 ptr = skb->data;
891 }
892
893 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
894 CMD_TEMPL_NULL_DATA, ptr, size, 0,
895 wlvif->basic_rate);
896
897out:
898 dev_kfree_skb(skb);
899 if (ret)
900 wl1271_warning("cmd buld null data failed %d", ret);
901
902 return ret;
903
904}
905
906int wl12xx_cmd_build_klv_null_data(struct wl1271 *wl,
907 struct wl12xx_vif *wlvif)
908{
909 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
910 struct sk_buff *skb = NULL;
911 int ret = -ENOMEM;
912
913 skb = ieee80211_nullfunc_get(wl->hw, vif);
914 if (!skb)
915 goto out;
916
917 ret = wl1271_cmd_template_set(wl, wlvif->role_id, CMD_TEMPL_KLV,
918 skb->data, skb->len,
919 CMD_TEMPL_KLV_IDX_NULL_DATA,
920 wlvif->basic_rate);
921
922out:
923 dev_kfree_skb(skb);
924 if (ret)
925 wl1271_warning("cmd build klv null data failed %d", ret);
926
927 return ret;
928
929}
930
931int wl1271_cmd_build_ps_poll(struct wl1271 *wl, struct wl12xx_vif *wlvif,
932 u16 aid)
933{
934 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
935 struct sk_buff *skb;
936 int ret = 0;
937
938 skb = ieee80211_pspoll_get(wl->hw, vif);
939 if (!skb)
940 goto out;
941
942 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
943 CMD_TEMPL_PS_POLL, skb->data,
944 skb->len, 0, wlvif->basic_rate_set);
945
946out:
947 dev_kfree_skb(skb);
948 return ret;
949}
950
951int wl12xx_cmd_build_probe_req(struct wl1271 *wl, struct wl12xx_vif *wlvif,
952 u8 role_id, u8 band,
953 const u8 *ssid, size_t ssid_len,
954 const u8 *ie, size_t ie_len)
955{
956 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
957 struct sk_buff *skb;
958 int ret;
959 u32 rate;
960
961 skb = ieee80211_probereq_get(wl->hw, vif, ssid, ssid_len,
962 ie, ie_len);
963 if (!skb) {
964 ret = -ENOMEM;
965 goto out;
966 }
967
968 wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len);
969
970 rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[band]);
971 if (band == IEEE80211_BAND_2GHZ)
972 ret = wl1271_cmd_template_set(wl, role_id,
973 CMD_TEMPL_CFG_PROBE_REQ_2_4,
974 skb->data, skb->len, 0, rate);
975 else
976 ret = wl1271_cmd_template_set(wl, role_id,
977 CMD_TEMPL_CFG_PROBE_REQ_5,
978 skb->data, skb->len, 0, rate);
979
980out:
981 dev_kfree_skb(skb);
982 return ret;
983}
984
985struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
986 struct wl12xx_vif *wlvif,
987 struct sk_buff *skb)
988{
989 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
990 int ret;
991 u32 rate;
992
993 if (!skb)
994 skb = ieee80211_ap_probereq_get(wl->hw, vif);
995 if (!skb)
996 goto out;
997
998 wl1271_dump(DEBUG_SCAN, "AP PROBE REQ: ", skb->data, skb->len);
999
1000 rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[wlvif->band]);
1001 if (wlvif->band == IEEE80211_BAND_2GHZ)
1002 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
1003 CMD_TEMPL_CFG_PROBE_REQ_2_4,
1004 skb->data, skb->len, 0, rate);
1005 else
1006 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
1007 CMD_TEMPL_CFG_PROBE_REQ_5,
1008 skb->data, skb->len, 0, rate);
1009
1010 if (ret < 0)
1011 wl1271_error("Unable to set ap probe request template.");
1012
1013out:
1014 return skb;
1015}
1016
1017int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1018{
1019 int ret, extra;
1020 u16 fc;
1021 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1022 struct sk_buff *skb;
1023 struct wl12xx_arp_rsp_template *tmpl;
1024 struct ieee80211_hdr_3addr *hdr;
1025 struct arphdr *arp_hdr;
1026
1027 skb = dev_alloc_skb(sizeof(*hdr) + sizeof(__le16) + sizeof(*tmpl) +
1028 WL1271_EXTRA_SPACE_MAX);
1029 if (!skb) {
1030 wl1271_error("failed to allocate buffer for arp rsp template");
1031 return -ENOMEM;
1032 }
1033
1034 skb_reserve(skb, sizeof(*hdr) + WL1271_EXTRA_SPACE_MAX);
1035
1036 tmpl = (struct wl12xx_arp_rsp_template *)skb_put(skb, sizeof(*tmpl));
1037 memset(tmpl, 0, sizeof(tmpl));
1038
1039 /* llc layer */
1040 memcpy(tmpl->llc_hdr, rfc1042_header, sizeof(rfc1042_header));
1041 tmpl->llc_type = cpu_to_be16(ETH_P_ARP);
1042
1043 /* arp header */
1044 arp_hdr = &tmpl->arp_hdr;
1045 arp_hdr->ar_hrd = cpu_to_be16(ARPHRD_ETHER);
1046 arp_hdr->ar_pro = cpu_to_be16(ETH_P_IP);
1047 arp_hdr->ar_hln = ETH_ALEN;
1048 arp_hdr->ar_pln = 4;
1049 arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY);
1050
1051 /* arp payload */
1052 memcpy(tmpl->sender_hw, vif->addr, ETH_ALEN);
1053 tmpl->sender_ip = wlvif->ip_addr;
1054
1055 /* encryption space */
1056 switch (wlvif->encryption_type) {
1057 case KEY_TKIP:
1058 extra = WL1271_EXTRA_SPACE_TKIP;
1059 break;
1060 case KEY_AES:
1061 extra = WL1271_EXTRA_SPACE_AES;
1062 break;
1063 case KEY_NONE:
1064 case KEY_WEP:
1065 case KEY_GEM:
1066 extra = 0;
1067 break;
1068 default:
1069 wl1271_warning("Unknown encryption type: %d",
1070 wlvif->encryption_type);
1071 ret = -EINVAL;
1072 goto out;
1073 }
1074
1075 if (extra) {
1076 u8 *space = skb_push(skb, extra);
1077 memset(space, 0, extra);
1078 }
1079
1080 /* QoS header - BE */
1081 if (wlvif->sta.qos)
1082 memset(skb_push(skb, sizeof(__le16)), 0, sizeof(__le16));
1083
1084 /* mac80211 header */
1085 hdr = (struct ieee80211_hdr_3addr *)skb_push(skb, sizeof(*hdr));
1086 memset(hdr, 0, sizeof(hdr));
1087 fc = IEEE80211_FTYPE_DATA | IEEE80211_FCTL_TODS;
1088 if (wlvif->sta.qos)
1089 fc |= IEEE80211_STYPE_QOS_DATA;
1090 else
1091 fc |= IEEE80211_STYPE_DATA;
1092 if (wlvif->encryption_type != KEY_NONE)
1093 fc |= IEEE80211_FCTL_PROTECTED;
1094
1095 hdr->frame_control = cpu_to_le16(fc);
1096 memcpy(hdr->addr1, vif->bss_conf.bssid, ETH_ALEN);
1097 memcpy(hdr->addr2, vif->addr, ETH_ALEN);
1098 memset(hdr->addr3, 0xff, ETH_ALEN);
1099
1100 ret = wl1271_cmd_template_set(wl, wlvif->role_id, CMD_TEMPL_ARP_RSP,
1101 skb->data, skb->len, 0,
1102 wlvif->basic_rate);
1103out:
1104 dev_kfree_skb(skb);
1105 return ret;
1106}
1107
1108int wl1271_build_qos_null_data(struct wl1271 *wl, struct ieee80211_vif *vif)
1109{
1110 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
1111 struct ieee80211_qos_hdr template;
1112
1113 memset(&template, 0, sizeof(template));
1114
1115 memcpy(template.addr1, vif->bss_conf.bssid, ETH_ALEN);
1116 memcpy(template.addr2, vif->addr, ETH_ALEN);
1117 memcpy(template.addr3, vif->bss_conf.bssid, ETH_ALEN);
1118
1119 template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
1120 IEEE80211_STYPE_QOS_NULLFUNC |
1121 IEEE80211_FCTL_TODS);
1122
1123 /* FIXME: not sure what priority to use here */
1124 template.qos_ctrl = cpu_to_le16(0);
1125
1126 return wl1271_cmd_template_set(wl, wlvif->role_id,
1127 CMD_TEMPL_QOS_NULL_DATA, &template,
1128 sizeof(template), 0,
1129 wlvif->basic_rate);
1130}
1131
1132int wl12xx_cmd_set_default_wep_key(struct wl1271 *wl, u8 id, u8 hlid)
1133{
1134 struct wl1271_cmd_set_keys *cmd;
1135 int ret = 0;
1136
1137 wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
1138
1139 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1140 if (!cmd) {
1141 ret = -ENOMEM;
1142 goto out;
1143 }
1144
1145 cmd->hlid = hlid;
1146 cmd->key_id = id;
1147 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
1148 cmd->key_action = cpu_to_le16(KEY_SET_ID);
1149 cmd->key_type = KEY_WEP;
1150
1151 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
1152 if (ret < 0) {
1153 wl1271_warning("cmd set_default_wep_key failed: %d", ret);
1154 goto out;
1155 }
1156
1157out:
1158 kfree(cmd);
1159
1160 return ret;
1161}
1162
1163int wl1271_cmd_set_sta_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1164 u16 action, u8 id, u8 key_type,
1165 u8 key_size, const u8 *key, const u8 *addr,
1166 u32 tx_seq_32, u16 tx_seq_16)
1167{
1168 struct wl1271_cmd_set_keys *cmd;
1169 int ret = 0;
1170
1171 /* hlid might have already been deleted */
1172 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)
1173 return 0;
1174
1175 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1176 if (!cmd) {
1177 ret = -ENOMEM;
1178 goto out;
1179 }
1180
1181 cmd->hlid = wlvif->sta.hlid;
1182
1183 if (key_type == KEY_WEP)
1184 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
1185 else if (is_broadcast_ether_addr(addr))
1186 cmd->lid_key_type = BROADCAST_LID_TYPE;
1187 else
1188 cmd->lid_key_type = UNICAST_LID_TYPE;
1189
1190 cmd->key_action = cpu_to_le16(action);
1191 cmd->key_size = key_size;
1192 cmd->key_type = key_type;
1193
1194 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
1195 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
1196
1197 cmd->key_id = id;
1198
1199 if (key_type == KEY_TKIP) {
1200 /*
1201 * We get the key in the following form:
1202 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1203 * but the target is expecting:
1204 * TKIP - RX MIC - TX MIC
1205 */
1206 memcpy(cmd->key, key, 16);
1207 memcpy(cmd->key + 16, key + 24, 8);
1208 memcpy(cmd->key + 24, key + 16, 8);
1209
1210 } else {
1211 memcpy(cmd->key, key, key_size);
1212 }
1213
1214 wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
1215
1216 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
1217 if (ret < 0) {
1218 wl1271_warning("could not set keys");
1219 goto out;
1220 }
1221
1222out:
1223 kfree(cmd);
1224
1225 return ret;
1226}
1227
1228/*
1229 * TODO: merge with sta/ibss into 1 set_key function.
1230 * note there are slight diffs
1231 */
1232int wl1271_cmd_set_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1233 u16 action, u8 id, u8 key_type,
1234 u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
1235 u16 tx_seq_16)
1236{
1237 struct wl1271_cmd_set_keys *cmd;
1238 int ret = 0;
1239 u8 lid_type;
1240
1241 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1242 if (!cmd)
1243 return -ENOMEM;
1244
1245 if (hlid == wlvif->ap.bcast_hlid) {
1246 if (key_type == KEY_WEP)
1247 lid_type = WEP_DEFAULT_LID_TYPE;
1248 else
1249 lid_type = BROADCAST_LID_TYPE;
1250 } else {
1251 lid_type = UNICAST_LID_TYPE;
1252 }
1253
1254 wl1271_debug(DEBUG_CRYPT, "ap key action: %d id: %d lid: %d type: %d"
1255 " hlid: %d", (int)action, (int)id, (int)lid_type,
1256 (int)key_type, (int)hlid);
1257
1258 cmd->lid_key_type = lid_type;
1259 cmd->hlid = hlid;
1260 cmd->key_action = cpu_to_le16(action);
1261 cmd->key_size = key_size;
1262 cmd->key_type = key_type;
1263 cmd->key_id = id;
1264 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
1265 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
1266
1267 if (key_type == KEY_TKIP) {
1268 /*
1269 * We get the key in the following form:
1270 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1271 * but the target is expecting:
1272 * TKIP - RX MIC - TX MIC
1273 */
1274 memcpy(cmd->key, key, 16);
1275 memcpy(cmd->key + 16, key + 24, 8);
1276 memcpy(cmd->key + 24, key + 16, 8);
1277 } else {
1278 memcpy(cmd->key, key, key_size);
1279 }
1280
1281 wl1271_dump(DEBUG_CRYPT, "TARGET AP KEY: ", cmd, sizeof(*cmd));
1282
1283 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
1284 if (ret < 0) {
1285 wl1271_warning("could not set ap keys");
1286 goto out;
1287 }
1288
1289out:
1290 kfree(cmd);
1291 return ret;
1292}
1293
1294int wl12xx_cmd_set_peer_state(struct wl1271 *wl, u8 hlid)
1295{
1296 struct wl12xx_cmd_set_peer_state *cmd;
1297 int ret = 0;
1298
1299 wl1271_debug(DEBUG_CMD, "cmd set peer state (hlid=%d)", hlid);
1300
1301 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1302 if (!cmd) {
1303 ret = -ENOMEM;
1304 goto out;
1305 }
1306
1307 cmd->hlid = hlid;
1308 cmd->state = WL1271_CMD_STA_STATE_CONNECTED;
1309
1310 ret = wl1271_cmd_send(wl, CMD_SET_PEER_STATE, cmd, sizeof(*cmd), 0);
1311 if (ret < 0) {
1312 wl1271_error("failed to send set peer state command");
1313 goto out_free;
1314 }
1315
1316out_free:
1317 kfree(cmd);
1318
1319out:
1320 return ret;
1321}
1322
1323int wl12xx_cmd_add_peer(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1324 struct ieee80211_sta *sta, u8 hlid)
1325{
1326 struct wl12xx_cmd_add_peer *cmd;
1327 int i, ret;
1328 u32 sta_rates;
1329
1330 wl1271_debug(DEBUG_CMD, "cmd add peer %d", (int)hlid);
1331
1332 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1333 if (!cmd) {
1334 ret = -ENOMEM;
1335 goto out;
1336 }
1337
1338 memcpy(cmd->addr, sta->addr, ETH_ALEN);
1339 cmd->bss_index = WL1271_AP_BSS_INDEX;
1340 cmd->aid = sta->aid;
1341 cmd->hlid = hlid;
1342 cmd->sp_len = sta->max_sp;
1343 cmd->wmm = sta->wme ? 1 : 0;
1344
1345 for (i = 0; i < NUM_ACCESS_CATEGORIES_COPY; i++)
1346 if (sta->wme && (sta->uapsd_queues & BIT(i)))
1347 cmd->psd_type[i] = WL1271_PSD_UPSD_TRIGGER;
1348 else
1349 cmd->psd_type[i] = WL1271_PSD_LEGACY;
1350
1351 sta_rates = sta->supp_rates[wlvif->band];
1352 if (sta->ht_cap.ht_supported)
1353 sta_rates |= sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET;
1354
1355 cmd->supported_rates =
1356 cpu_to_le32(wl1271_tx_enabled_rates_get(wl, sta_rates,
1357 wlvif->band));
1358
1359 wl1271_debug(DEBUG_CMD, "new peer rates=0x%x queues=0x%x",
1360 cmd->supported_rates, sta->uapsd_queues);
1361
1362 ret = wl1271_cmd_send(wl, CMD_ADD_PEER, cmd, sizeof(*cmd), 0);
1363 if (ret < 0) {
1364 wl1271_error("failed to initiate cmd add peer");
1365 goto out_free;
1366 }
1367
1368out_free:
1369 kfree(cmd);
1370
1371out:
1372 return ret;
1373}
1374
1375int wl12xx_cmd_remove_peer(struct wl1271 *wl, u8 hlid)
1376{
1377 struct wl12xx_cmd_remove_peer *cmd;
1378 int ret;
1379
1380 wl1271_debug(DEBUG_CMD, "cmd remove peer %d", (int)hlid);
1381
1382 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1383 if (!cmd) {
1384 ret = -ENOMEM;
1385 goto out;
1386 }
1387
1388 cmd->hlid = hlid;
1389 /* We never send a deauth, mac80211 is in charge of this */
1390 cmd->reason_opcode = 0;
1391 cmd->send_deauth_flag = 0;
1392
1393 ret = wl1271_cmd_send(wl, CMD_REMOVE_PEER, cmd, sizeof(*cmd), 0);
1394 if (ret < 0) {
1395 wl1271_error("failed to initiate cmd remove peer");
1396 goto out_free;
1397 }
1398
1399 /*
1400 * We are ok with a timeout here. The event is sometimes not sent
1401 * due to a firmware bug.
1402 */
1403 wl1271_cmd_wait_for_event_or_timeout(wl,
1404 PEER_REMOVE_COMPLETE_EVENT_ID);
1405
1406out_free:
1407 kfree(cmd);
1408
1409out:
1410 return ret;
1411}
1412
1413int wl12xx_cmd_config_fwlog(struct wl1271 *wl)
1414{
1415 struct wl12xx_cmd_config_fwlog *cmd;
1416 int ret = 0;
1417
1418 wl1271_debug(DEBUG_CMD, "cmd config firmware logger");
1419
1420 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1421 if (!cmd) {
1422 ret = -ENOMEM;
1423 goto out;
1424 }
1425
1426 cmd->logger_mode = wl->conf.fwlog.mode;
1427 cmd->log_severity = wl->conf.fwlog.severity;
1428 cmd->timestamp = wl->conf.fwlog.timestamp;
1429 cmd->output = wl->conf.fwlog.output;
1430 cmd->threshold = wl->conf.fwlog.threshold;
1431
1432 ret = wl1271_cmd_send(wl, CMD_CONFIG_FWLOGGER, cmd, sizeof(*cmd), 0);
1433 if (ret < 0) {
1434 wl1271_error("failed to send config firmware logger command");
1435 goto out_free;
1436 }
1437
1438out_free:
1439 kfree(cmd);
1440
1441out:
1442 return ret;
1443}
1444
1445int wl12xx_cmd_start_fwlog(struct wl1271 *wl)
1446{
1447 struct wl12xx_cmd_start_fwlog *cmd;
1448 int ret = 0;
1449
1450 wl1271_debug(DEBUG_CMD, "cmd start firmware logger");
1451
1452 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1453 if (!cmd) {
1454 ret = -ENOMEM;
1455 goto out;
1456 }
1457
1458 ret = wl1271_cmd_send(wl, CMD_START_FWLOGGER, cmd, sizeof(*cmd), 0);
1459 if (ret < 0) {
1460 wl1271_error("failed to send start firmware logger command");
1461 goto out_free;
1462 }
1463
1464out_free:
1465 kfree(cmd);
1466
1467out:
1468 return ret;
1469}
1470
1471int wl12xx_cmd_stop_fwlog(struct wl1271 *wl)
1472{
1473 struct wl12xx_cmd_stop_fwlog *cmd;
1474 int ret = 0;
1475
1476 wl1271_debug(DEBUG_CMD, "cmd stop firmware logger");
1477
1478 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1479 if (!cmd) {
1480 ret = -ENOMEM;
1481 goto out;
1482 }
1483
1484 ret = wl1271_cmd_send(wl, CMD_STOP_FWLOGGER, cmd, sizeof(*cmd), 0);
1485 if (ret < 0) {
1486 wl1271_error("failed to send stop firmware logger command");
1487 goto out_free;
1488 }
1489
1490out_free:
1491 kfree(cmd);
1492
1493out:
1494 return ret;
1495}
1496
1497static int wl12xx_cmd_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1498 u8 role_id)
1499{
1500 struct wl12xx_cmd_roc *cmd;
1501 int ret = 0;
1502
1503 wl1271_debug(DEBUG_CMD, "cmd roc %d (%d)", wlvif->channel, role_id);
1504
1505 if (WARN_ON(role_id == WL12XX_INVALID_ROLE_ID))
1506 return -EINVAL;
1507
1508 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1509 if (!cmd) {
1510 ret = -ENOMEM;
1511 goto out;
1512 }
1513
1514 cmd->role_id = role_id;
1515 cmd->channel = wlvif->channel;
1516 switch (wlvif->band) {
1517 case IEEE80211_BAND_2GHZ:
1518 cmd->band = WLCORE_BAND_2_4GHZ;
1519 break;
1520 case IEEE80211_BAND_5GHZ:
1521 cmd->band = WLCORE_BAND_5GHZ;
1522 break;
1523 default:
1524 wl1271_error("roc - unknown band: %d", (int)wlvif->band);
1525 ret = -EINVAL;
1526 goto out_free;
1527 }
1528
1529
1530 ret = wl1271_cmd_send(wl, CMD_REMAIN_ON_CHANNEL, cmd, sizeof(*cmd), 0);
1531 if (ret < 0) {
1532 wl1271_error("failed to send ROC command");
1533 goto out_free;
1534 }
1535
1536out_free:
1537 kfree(cmd);
1538
1539out:
1540 return ret;
1541}
1542
1543static int wl12xx_cmd_croc(struct wl1271 *wl, u8 role_id)
1544{
1545 struct wl12xx_cmd_croc *cmd;
1546 int ret = 0;
1547
1548 wl1271_debug(DEBUG_CMD, "cmd croc (%d)", role_id);
1549
1550 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1551 if (!cmd) {
1552 ret = -ENOMEM;
1553 goto out;
1554 }
1555 cmd->role_id = role_id;
1556
1557 ret = wl1271_cmd_send(wl, CMD_CANCEL_REMAIN_ON_CHANNEL, cmd,
1558 sizeof(*cmd), 0);
1559 if (ret < 0) {
1560 wl1271_error("failed to send ROC command");
1561 goto out_free;
1562 }
1563
1564out_free:
1565 kfree(cmd);
1566
1567out:
1568 return ret;
1569}
1570
1571int wl12xx_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 role_id)
1572{
1573 int ret = 0;
1574
1575 if (WARN_ON(test_bit(role_id, wl->roc_map)))
1576 return 0;
1577
1578 ret = wl12xx_cmd_roc(wl, wlvif, role_id);
1579 if (ret < 0)
1580 goto out;
1581
1582 ret = wl1271_cmd_wait_for_event(wl,
1583 REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID);
1584 if (ret < 0) {
1585 wl1271_error("cmd roc event completion error");
1586 goto out;
1587 }
1588
1589 __set_bit(role_id, wl->roc_map);
1590out:
1591 return ret;
1592}
1593
1594int wl12xx_croc(struct wl1271 *wl, u8 role_id)
1595{
1596 int ret = 0;
1597
1598 if (WARN_ON(!test_bit(role_id, wl->roc_map)))
1599 return 0;
1600
1601 ret = wl12xx_cmd_croc(wl, role_id);
1602 if (ret < 0)
1603 goto out;
1604
1605 __clear_bit(role_id, wl->roc_map);
1606
1607 /*
1608 * Rearm the tx watchdog when removing the last ROC. This prevents
1609 * recoveries due to just finished ROCs - when Tx hasn't yet had
1610 * a chance to get out.
1611 */
1612 if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) >= WL12XX_MAX_ROLES)
1613 wl12xx_rearm_tx_watchdog_locked(wl);
1614out:
1615 return ret;
1616}
1617
1618int wl12xx_cmd_channel_switch(struct wl1271 *wl,
1619 struct wl12xx_vif *wlvif,
1620 struct ieee80211_channel_switch *ch_switch)
1621{
1622 struct wl12xx_cmd_channel_switch *cmd;
1623 int ret;
1624
1625 wl1271_debug(DEBUG_ACX, "cmd channel switch");
1626
1627 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1628 if (!cmd) {
1629 ret = -ENOMEM;
1630 goto out;
1631 }
1632
1633 cmd->role_id = wlvif->role_id;
1634 cmd->channel = ch_switch->channel->hw_value;
1635 cmd->switch_time = ch_switch->count;
1636 cmd->stop_tx = ch_switch->block_tx;
1637
1638 /* FIXME: control from mac80211 in the future */
1639 cmd->post_switch_tx_disable = 0; /* Enable TX on the target channel */
1640
1641 ret = wl1271_cmd_send(wl, CMD_CHANNEL_SWITCH, cmd, sizeof(*cmd), 0);
1642 if (ret < 0) {
1643 wl1271_error("failed to send channel switch command");
1644 goto out_free;
1645 }
1646
1647out_free:
1648 kfree(cmd);
1649
1650out:
1651 return ret;
1652}
1653
1654int wl12xx_cmd_stop_channel_switch(struct wl1271 *wl)
1655{
1656 struct wl12xx_cmd_stop_channel_switch *cmd;
1657 int ret;
1658
1659 wl1271_debug(DEBUG_ACX, "cmd stop channel switch");
1660
1661 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1662 if (!cmd) {
1663 ret = -ENOMEM;
1664 goto out;
1665 }
1666
1667 ret = wl1271_cmd_send(wl, CMD_STOP_CHANNEL_SWICTH, cmd, sizeof(*cmd), 0);
1668 if (ret < 0) {
1669 wl1271_error("failed to stop channel switch command");
1670 goto out_free;
1671 }
1672
1673out_free:
1674 kfree(cmd);
1675
1676out:
1677 return ret;
1678}
1679
1680/* start dev role and roc on its channel */
1681int wl12xx_start_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1682{
1683 int ret;
1684
1685 if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS ||
1686 wlvif->bss_type == BSS_TYPE_IBSS)))
1687 return -EINVAL;
1688
1689 ret = wl12xx_cmd_role_start_dev(wl, wlvif);
1690 if (ret < 0)
1691 goto out;
1692
1693 ret = wl12xx_roc(wl, wlvif, wlvif->dev_role_id);
1694 if (ret < 0)
1695 goto out_stop;
1696
1697 return 0;
1698
1699out_stop:
1700 wl12xx_cmd_role_stop_dev(wl, wlvif);
1701out:
1702 return ret;
1703}
1704
1705/* croc dev hlid, and stop the role */
1706int wl12xx_stop_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1707{
1708 int ret;
1709
1710 if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS ||
1711 wlvif->bss_type == BSS_TYPE_IBSS)))
1712 return -EINVAL;
1713
1714 /* flush all pending packets */
1715 wl1271_tx_work_locked(wl);
1716
1717 if (test_bit(wlvif->dev_role_id, wl->roc_map)) {
1718 ret = wl12xx_croc(wl, wlvif->dev_role_id);
1719 if (ret < 0)
1720 goto out;
1721 }
1722
1723 ret = wl12xx_cmd_role_stop_dev(wl, wlvif);
1724 if (ret < 0)
1725 goto out;
1726out:
1727 return ret;
1728}
diff --git a/drivers/net/wireless/ti/wlcore/cmd.h b/drivers/net/wireless/ti/wlcore/cmd.h
new file mode 100644
index 000000000000..a46ae07cb77e
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/cmd.h
@@ -0,0 +1,646 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
5 * Copyright (C) 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 __CMD_H__
26#define __CMD_H__
27
28#include "wlcore.h"
29
30struct acx_header;
31
32int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
33 size_t res_len);
34int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 *addr, u8 role_type,
35 u8 *role_id);
36int wl12xx_cmd_role_disable(struct wl1271 *wl, u8 *role_id);
37int wl12xx_cmd_role_start_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif);
38int wl12xx_cmd_role_stop_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif);
39int wl12xx_cmd_role_start_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif);
40int wl12xx_cmd_role_stop_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif);
41int wl12xx_cmd_role_start_ibss(struct wl1271 *wl, struct wl12xx_vif *wlvif);
42int wl12xx_start_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif);
43int wl12xx_stop_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif);
44int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer);
45int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len);
46int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len);
47int wl1271_cmd_data_path(struct wl1271 *wl, bool enable);
48int wl1271_cmd_ps_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
49 u8 ps_mode, u16 auto_ps_timeout);
50int wl1271_cmd_read_memory(struct wl1271 *wl, u32 addr, void *answer,
51 size_t len);
52int wl1271_cmd_template_set(struct wl1271 *wl, u8 role_id,
53 u16 template_id, void *buf, size_t buf_len,
54 int index, u32 rates);
55int wl12xx_cmd_build_null_data(struct wl1271 *wl, struct wl12xx_vif *wlvif);
56int wl1271_cmd_build_ps_poll(struct wl1271 *wl, struct wl12xx_vif *wlvif,
57 u16 aid);
58int wl12xx_cmd_build_probe_req(struct wl1271 *wl, struct wl12xx_vif *wlvif,
59 u8 role_id, u8 band,
60 const u8 *ssid, size_t ssid_len,
61 const u8 *ie, size_t ie_len);
62struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
63 struct wl12xx_vif *wlvif,
64 struct sk_buff *skb);
65int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, struct wl12xx_vif *wlvif);
66int wl1271_build_qos_null_data(struct wl1271 *wl, struct ieee80211_vif *vif);
67int wl12xx_cmd_build_klv_null_data(struct wl1271 *wl,
68 struct wl12xx_vif *wlvif);
69int wl12xx_cmd_set_default_wep_key(struct wl1271 *wl, u8 id, u8 hlid);
70int wl1271_cmd_set_sta_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
71 u16 action, u8 id, u8 key_type,
72 u8 key_size, const u8 *key, const u8 *addr,
73 u32 tx_seq_32, u16 tx_seq_16);
74int wl1271_cmd_set_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
75 u16 action, u8 id, u8 key_type,
76 u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
77 u16 tx_seq_16);
78int wl12xx_cmd_set_peer_state(struct wl1271 *wl, u8 hlid);
79int wl12xx_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 role_id);
80int wl12xx_croc(struct wl1271 *wl, u8 role_id);
81int wl12xx_cmd_add_peer(struct wl1271 *wl, struct wl12xx_vif *wlvif,
82 struct ieee80211_sta *sta, u8 hlid);
83int wl12xx_cmd_remove_peer(struct wl1271 *wl, u8 hlid);
84int wl12xx_cmd_config_fwlog(struct wl1271 *wl);
85int wl12xx_cmd_start_fwlog(struct wl1271 *wl);
86int wl12xx_cmd_stop_fwlog(struct wl1271 *wl);
87int wl12xx_cmd_channel_switch(struct wl1271 *wl,
88 struct wl12xx_vif *wlvif,
89 struct ieee80211_channel_switch *ch_switch);
90int wl12xx_cmd_stop_channel_switch(struct wl1271 *wl);
91int wl12xx_allocate_link(struct wl1271 *wl, struct wl12xx_vif *wlvif,
92 u8 *hlid);
93void wl12xx_free_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid);
94
95enum wl1271_commands {
96 CMD_INTERROGATE = 1, /* use this to read information elements */
97 CMD_CONFIGURE = 2, /* use this to write information elements */
98 CMD_ENABLE_RX = 3,
99 CMD_ENABLE_TX = 4,
100 CMD_DISABLE_RX = 5,
101 CMD_DISABLE_TX = 6,
102 CMD_SCAN = 7,
103 CMD_STOP_SCAN = 8,
104 CMD_SET_KEYS = 9,
105 CMD_READ_MEMORY = 10,
106 CMD_WRITE_MEMORY = 11,
107 CMD_SET_TEMPLATE = 12,
108 CMD_TEST = 13,
109 CMD_NOISE_HIST = 14,
110 CMD_QUIET_ELEMENT_SET_STATE = 15,
111 CMD_SET_BCN_MODE = 16,
112
113 CMD_MEASUREMENT = 17,
114 CMD_STOP_MEASUREMENT = 18,
115 CMD_SET_PS_MODE = 19,
116 CMD_CHANNEL_SWITCH = 20,
117 CMD_STOP_CHANNEL_SWICTH = 21,
118 CMD_AP_DISCOVERY = 22,
119 CMD_STOP_AP_DISCOVERY = 23,
120 CMD_HEALTH_CHECK = 24,
121 CMD_DEBUG = 25,
122 CMD_TRIGGER_SCAN_TO = 26,
123 CMD_CONNECTION_SCAN_CFG = 27,
124 CMD_CONNECTION_SCAN_SSID_CFG = 28,
125 CMD_START_PERIODIC_SCAN = 29,
126 CMD_STOP_PERIODIC_SCAN = 30,
127 CMD_SET_PEER_STATE = 31,
128 CMD_REMAIN_ON_CHANNEL = 32,
129 CMD_CANCEL_REMAIN_ON_CHANNEL = 33,
130 CMD_CONFIG_FWLOGGER = 34,
131 CMD_START_FWLOGGER = 35,
132 CMD_STOP_FWLOGGER = 36,
133
134 /* Access point commands */
135 CMD_ADD_PEER = 37,
136 CMD_REMOVE_PEER = 38,
137
138 /* Role API */
139 CMD_ROLE_ENABLE = 39,
140 CMD_ROLE_DISABLE = 40,
141 CMD_ROLE_START = 41,
142 CMD_ROLE_STOP = 42,
143
144 /* DFS */
145 CMD_START_RADAR_DETECTION = 43,
146 CMD_STOP_RADAR_DETECTION = 44,
147
148 /* WIFI Direct */
149 CMD_WFD_START_DISCOVERY = 45,
150 CMD_WFD_STOP_DISCOVERY = 46,
151 CMD_WFD_ATTRIBUTE_CONFIG = 47,
152 CMD_NOP = 48,
153 CMD_LAST_COMMAND,
154
155 MAX_COMMAND_ID = 0xFFFF,
156};
157
158#define MAX_CMD_PARAMS 572
159
160enum {
161 CMD_TEMPL_KLV_IDX_NULL_DATA = 0,
162 CMD_TEMPL_KLV_IDX_MAX = 4
163};
164
165enum cmd_templ {
166 CMD_TEMPL_NULL_DATA = 0,
167 CMD_TEMPL_BEACON,
168 CMD_TEMPL_CFG_PROBE_REQ_2_4,
169 CMD_TEMPL_CFG_PROBE_REQ_5,
170 CMD_TEMPL_PROBE_RESPONSE,
171 CMD_TEMPL_QOS_NULL_DATA,
172 CMD_TEMPL_PS_POLL,
173 CMD_TEMPL_KLV,
174 CMD_TEMPL_DISCONNECT,
175 CMD_TEMPL_PROBE_REQ_2_4, /* for firmware internal use only */
176 CMD_TEMPL_PROBE_REQ_5, /* for firmware internal use only */
177 CMD_TEMPL_BAR, /* for firmware internal use only */
178 CMD_TEMPL_CTS, /*
179 * For CTS-to-self (FastCTS) mechanism
180 * for BT/WLAN coexistence (SoftGemini). */
181 CMD_TEMPL_AP_BEACON,
182 CMD_TEMPL_AP_PROBE_RESPONSE,
183 CMD_TEMPL_ARP_RSP,
184 CMD_TEMPL_DEAUTH_AP,
185 CMD_TEMPL_TEMPORARY,
186 CMD_TEMPL_LINK_MEASUREMENT_REPORT,
187
188 CMD_TEMPL_MAX = 0xff
189};
190
191/* unit ms */
192#define WL1271_COMMAND_TIMEOUT 2000
193#define WL1271_CMD_TEMPL_DFLT_SIZE 252
194#define WL1271_CMD_TEMPL_MAX_SIZE 512
195#define WL1271_EVENT_TIMEOUT 750
196
197struct wl1271_cmd_header {
198 __le16 id;
199 __le16 status;
200 /* payload */
201 u8 data[0];
202} __packed;
203
204#define WL1271_CMD_MAX_PARAMS 572
205
206struct wl1271_command {
207 struct wl1271_cmd_header header;
208 u8 parameters[WL1271_CMD_MAX_PARAMS];
209} __packed;
210
211enum {
212 CMD_MAILBOX_IDLE = 0,
213 CMD_STATUS_SUCCESS = 1,
214 CMD_STATUS_UNKNOWN_CMD = 2,
215 CMD_STATUS_UNKNOWN_IE = 3,
216 CMD_STATUS_REJECT_MEAS_SG_ACTIVE = 11,
217 CMD_STATUS_RX_BUSY = 13,
218 CMD_STATUS_INVALID_PARAM = 14,
219 CMD_STATUS_TEMPLATE_TOO_LARGE = 15,
220 CMD_STATUS_OUT_OF_MEMORY = 16,
221 CMD_STATUS_STA_TABLE_FULL = 17,
222 CMD_STATUS_RADIO_ERROR = 18,
223 CMD_STATUS_WRONG_NESTING = 19,
224 CMD_STATUS_TIMEOUT = 21, /* Driver internal use.*/
225 CMD_STATUS_FW_RESET = 22, /* Driver internal use.*/
226 CMD_STATUS_TEMPLATE_OOM = 23,
227 CMD_STATUS_NO_RX_BA_SESSION = 24,
228 MAX_COMMAND_STATUS = 0xff
229};
230
231#define CMDMBOX_HEADER_LEN 4
232#define CMDMBOX_INFO_ELEM_HEADER_LEN 4
233
234enum {
235 BSS_TYPE_IBSS = 0,
236 BSS_TYPE_STA_BSS = 2,
237 BSS_TYPE_AP_BSS = 3,
238 MAX_BSS_TYPE = 0xFF
239};
240
241#define WL1271_JOIN_CMD_CTRL_TX_FLUSH 0x80 /* Firmware flushes all Tx */
242#define WL1271_JOIN_CMD_TX_SESSION_OFFSET 1
243#define WL1271_JOIN_CMD_BSS_TYPE_5GHZ 0x10
244
245struct wl12xx_cmd_role_enable {
246 struct wl1271_cmd_header header;
247
248 u8 role_id;
249 u8 role_type;
250 u8 mac_address[ETH_ALEN];
251} __packed;
252
253struct wl12xx_cmd_role_disable {
254 struct wl1271_cmd_header header;
255
256 u8 role_id;
257 u8 padding[3];
258} __packed;
259
260enum wlcore_band {
261 WLCORE_BAND_2_4GHZ = 0,
262 WLCORE_BAND_5GHZ = 1,
263 WLCORE_BAND_JAPAN_4_9_GHZ = 2,
264 WLCORE_BAND_DEFAULT = WLCORE_BAND_2_4GHZ,
265 WLCORE_BAND_INVALID = 0x7E,
266 WLCORE_BAND_MAX_RADIO = 0x7F,
267};
268
269struct wl12xx_cmd_role_start {
270 struct wl1271_cmd_header header;
271
272 u8 role_id;
273 u8 band;
274 u8 channel;
275 u8 padding;
276
277 union {
278 struct {
279 u8 hlid;
280 u8 session;
281 u8 padding_1[54];
282 } __packed device;
283 /* sta & p2p_cli use the same struct */
284 struct {
285 u8 bssid[ETH_ALEN];
286 u8 hlid; /* data hlid */
287 u8 session;
288 __le32 remote_rates; /* remote supported rates */
289
290 /*
291 * The target uses this field to determine the rate at
292 * which to transmit control frame responses (such as
293 * ACK or CTS frames).
294 */
295 __le32 basic_rate_set;
296 __le32 local_rates; /* local supported rates */
297
298 u8 ssid_type;
299 u8 ssid_len;
300 u8 ssid[IEEE80211_MAX_SSID_LEN];
301
302 __le16 beacon_interval; /* in TBTTs */
303 } __packed sta;
304 struct {
305 u8 bssid[ETH_ALEN];
306 u8 hlid; /* data hlid */
307 u8 dtim_interval;
308 __le32 remote_rates; /* remote supported rates */
309
310 __le32 basic_rate_set;
311 __le32 local_rates; /* local supported rates */
312
313 u8 ssid_type;
314 u8 ssid_len;
315 u8 ssid[IEEE80211_MAX_SSID_LEN];
316
317 __le16 beacon_interval; /* in TBTTs */
318
319 u8 padding_1[4];
320 } __packed ibss;
321 /* ap & p2p_go use the same struct */
322 struct {
323 __le16 aging_period; /* in secs */
324 u8 beacon_expiry; /* in ms */
325 u8 bss_index;
326 /* The host link id for the AP's global queue */
327 u8 global_hlid;
328 /* The host link id for the AP's broadcast queue */
329 u8 broadcast_hlid;
330
331 __le16 beacon_interval; /* in TBTTs */
332
333 __le32 basic_rate_set;
334 __le32 local_rates; /* local supported rates */
335
336 u8 dtim_interval;
337
338 u8 ssid_type;
339 u8 ssid_len;
340 u8 ssid[IEEE80211_MAX_SSID_LEN];
341
342 u8 reset_tsf;
343
344 u8 padding_1[4];
345 } __packed ap;
346 };
347} __packed;
348
349struct wl12xx_cmd_role_stop {
350 struct wl1271_cmd_header header;
351
352 u8 role_id;
353 u8 disc_type; /* only STA and P2P_CLI */
354 __le16 reason; /* only STA and P2P_CLI */
355} __packed;
356
357struct cmd_enabledisable_path {
358 struct wl1271_cmd_header header;
359
360 u8 channel;
361 u8 padding[3];
362} __packed;
363
364#define WL1271_RATE_AUTOMATIC 0
365
366struct wl1271_cmd_template_set {
367 struct wl1271_cmd_header header;
368
369 u8 role_id;
370 u8 template_type;
371 __le16 len;
372 u8 index; /* relevant only for KLV_TEMPLATE type */
373 u8 padding[3];
374
375 __le32 enabled_rates;
376 u8 short_retry_limit;
377 u8 long_retry_limit;
378 u8 aflags;
379 u8 reserved;
380
381 u8 template_data[WL1271_CMD_TEMPL_MAX_SIZE];
382} __packed;
383
384#define TIM_ELE_ID 5
385#define PARTIAL_VBM_MAX 251
386
387struct wl1271_tim {
388 u8 identity;
389 u8 length;
390 u8 dtim_count;
391 u8 dtim_period;
392 u8 bitmap_ctrl;
393 u8 pvb_field[PARTIAL_VBM_MAX]; /* Partial Virtual Bitmap */
394} __packed;
395
396enum wl1271_cmd_ps_mode {
397 STATION_AUTO_PS_MODE, /* Dynamic Power Save */
398 STATION_ACTIVE_MODE,
399 STATION_POWER_SAVE_MODE
400};
401
402struct wl1271_cmd_ps_params {
403 struct wl1271_cmd_header header;
404
405 u8 role_id;
406 u8 ps_mode; /* STATION_* */
407 u16 auto_ps_timeout;
408} __packed;
409
410/* HW encryption keys */
411#define NUM_ACCESS_CATEGORIES_COPY 4
412
413enum wl1271_cmd_key_action {
414 KEY_ADD_OR_REPLACE = 1,
415 KEY_REMOVE = 2,
416 KEY_SET_ID = 3,
417 MAX_KEY_ACTION = 0xffff,
418};
419
420enum wl1271_cmd_lid_key_type {
421 UNICAST_LID_TYPE = 0,
422 BROADCAST_LID_TYPE = 1,
423 WEP_DEFAULT_LID_TYPE = 2
424};
425
426enum wl1271_cmd_key_type {
427 KEY_NONE = 0,
428 KEY_WEP = 1,
429 KEY_TKIP = 2,
430 KEY_AES = 3,
431 KEY_GEM = 4,
432};
433
434struct wl1271_cmd_set_keys {
435 struct wl1271_cmd_header header;
436
437 /*
438 * Indicates whether the HLID is a unicast key set
439 * or broadcast key set. A special value 0xFF is
440 * used to indicate that the HLID is on WEP-default
441 * (multi-hlids). of type wl1271_cmd_lid_key_type.
442 */
443 u8 hlid;
444
445 /*
446 * In WEP-default network (hlid == 0xFF) used to
447 * indicate which network STA/IBSS/AP role should be
448 * changed
449 */
450 u8 lid_key_type;
451
452 /*
453 * Key ID - For TKIP and AES key types, this field
454 * indicates the value that should be inserted into
455 * the KeyID field of frames transmitted using this
456 * key entry. For broadcast keys the index use as a
457 * marker for TX/RX key.
458 * For WEP default network (HLID=0xFF), this field
459 * indicates the ID of the key to add or remove.
460 */
461 u8 key_id;
462 u8 reserved_1;
463
464 /* key_action_e */
465 __le16 key_action;
466
467 /* key size in bytes */
468 u8 key_size;
469
470 /* key_type_e */
471 u8 key_type;
472
473 /* This field holds the security key data to add to the STA table */
474 u8 key[MAX_KEY_SIZE];
475 __le16 ac_seq_num16[NUM_ACCESS_CATEGORIES_COPY];
476 __le32 ac_seq_num32[NUM_ACCESS_CATEGORIES_COPY];
477} __packed;
478
479struct wl1271_cmd_test_header {
480 u8 id;
481 u8 padding[3];
482} __packed;
483
484enum wl1271_channel_tune_bands {
485 WL1271_CHANNEL_TUNE_BAND_2_4,
486 WL1271_CHANNEL_TUNE_BAND_5,
487 WL1271_CHANNEL_TUNE_BAND_4_9
488};
489
490#define WL1271_PD_REFERENCE_POINT_BAND_B_G 0
491
492/*
493 * There are three types of disconnections:
494 *
495 * DISCONNECT_IMMEDIATE: the fw doesn't send any frames
496 * DISCONNECT_DEAUTH: the fw generates a DEAUTH request with the reason
497 * we have passed
498 * DISCONNECT_DISASSOC: the fw generates a DESASSOC request with the reason
499 * we have passed
500 */
501enum wl1271_disconnect_type {
502 DISCONNECT_IMMEDIATE,
503 DISCONNECT_DEAUTH,
504 DISCONNECT_DISASSOC
505};
506
507#define WL1271_CMD_STA_STATE_CONNECTED 1
508
509struct wl12xx_cmd_set_peer_state {
510 struct wl1271_cmd_header header;
511
512 u8 hlid;
513 u8 state;
514 u8 padding[2];
515} __packed;
516
517struct wl12xx_cmd_roc {
518 struct wl1271_cmd_header header;
519
520 u8 role_id;
521 u8 channel;
522 u8 band;
523 u8 padding;
524};
525
526struct wl12xx_cmd_croc {
527 struct wl1271_cmd_header header;
528
529 u8 role_id;
530 u8 padding[3];
531};
532
533enum wl12xx_ssid_type {
534 WL12XX_SSID_TYPE_PUBLIC = 0,
535 WL12XX_SSID_TYPE_HIDDEN = 1,
536 WL12XX_SSID_TYPE_ANY = 2,
537};
538
539enum wl1271_psd_type {
540 WL1271_PSD_LEGACY = 0,
541 WL1271_PSD_UPSD_TRIGGER = 1,
542 WL1271_PSD_LEGACY_PSPOLL = 2,
543 WL1271_PSD_SAPSD = 3
544};
545
546struct wl12xx_cmd_add_peer {
547 struct wl1271_cmd_header header;
548
549 u8 addr[ETH_ALEN];
550 u8 hlid;
551 u8 aid;
552 u8 psd_type[NUM_ACCESS_CATEGORIES_COPY];
553 __le32 supported_rates;
554 u8 bss_index;
555 u8 sp_len;
556 u8 wmm;
557 u8 padding1;
558} __packed;
559
560struct wl12xx_cmd_remove_peer {
561 struct wl1271_cmd_header header;
562
563 u8 hlid;
564 u8 reason_opcode;
565 u8 send_deauth_flag;
566 u8 padding1;
567} __packed;
568
569/*
570 * Continuous mode - packets are transferred to the host periodically
571 * via the data path.
572 * On demand - Log messages are stored in a cyclic buffer in the
573 * firmware, and only transferred to the host when explicitly requested
574 */
575enum wl12xx_fwlogger_log_mode {
576 WL12XX_FWLOG_CONTINUOUS,
577 WL12XX_FWLOG_ON_DEMAND
578};
579
580/* Include/exclude timestamps from the log messages */
581enum wl12xx_fwlogger_timestamp {
582 WL12XX_FWLOG_TIMESTAMP_DISABLED,
583 WL12XX_FWLOG_TIMESTAMP_ENABLED
584};
585
586/*
587 * Logs can be routed to the debug pinouts (where available), to the host bus
588 * (SDIO/SPI), or dropped
589 */
590enum wl12xx_fwlogger_output {
591 WL12XX_FWLOG_OUTPUT_NONE,
592 WL12XX_FWLOG_OUTPUT_DBG_PINS,
593 WL12XX_FWLOG_OUTPUT_HOST,
594};
595
596struct wl12xx_cmd_config_fwlog {
597 struct wl1271_cmd_header header;
598
599 /* See enum wl12xx_fwlogger_log_mode */
600 u8 logger_mode;
601
602 /* Minimum log level threshold */
603 u8 log_severity;
604
605 /* Include/exclude timestamps from the log messages */
606 u8 timestamp;
607
608 /* See enum wl1271_fwlogger_output */
609 u8 output;
610
611 /* Regulates the frequency of log messages */
612 u8 threshold;
613
614 u8 padding[3];
615} __packed;
616
617struct wl12xx_cmd_start_fwlog {
618 struct wl1271_cmd_header header;
619} __packed;
620
621struct wl12xx_cmd_stop_fwlog {
622 struct wl1271_cmd_header header;
623} __packed;
624
625struct wl12xx_cmd_channel_switch {
626 struct wl1271_cmd_header header;
627
628 u8 role_id;
629
630 /* The new serving channel */
631 u8 channel;
632 /* Relative time of the serving channel switch in TBTT units */
633 u8 switch_time;
634 /* Stop the role TX, should expect it after radar detection */
635 u8 stop_tx;
636 /* The target channel tx status 1-stopped 0-open*/
637 u8 post_switch_tx_disable;
638
639 u8 padding[3];
640} __packed;
641
642struct wl12xx_cmd_stop_channel_switch {
643 struct wl1271_cmd_header header;
644} __packed;
645
646#endif /* __WL1271_CMD_H__ */
diff --git a/drivers/net/wireless/ti/wlcore/conf.h b/drivers/net/wireless/ti/wlcore/conf.h
new file mode 100644
index 000000000000..fef0db4213bc
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/conf.h
@@ -0,0 +1,1274 @@
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#ifndef __CONF_H__
25#define __CONF_H__
26
27enum {
28 CONF_HW_BIT_RATE_1MBPS = BIT(0),
29 CONF_HW_BIT_RATE_2MBPS = BIT(1),
30 CONF_HW_BIT_RATE_5_5MBPS = BIT(2),
31 CONF_HW_BIT_RATE_6MBPS = BIT(3),
32 CONF_HW_BIT_RATE_9MBPS = BIT(4),
33 CONF_HW_BIT_RATE_11MBPS = BIT(5),
34 CONF_HW_BIT_RATE_12MBPS = BIT(6),
35 CONF_HW_BIT_RATE_18MBPS = BIT(7),
36 CONF_HW_BIT_RATE_22MBPS = BIT(8),
37 CONF_HW_BIT_RATE_24MBPS = BIT(9),
38 CONF_HW_BIT_RATE_36MBPS = BIT(10),
39 CONF_HW_BIT_RATE_48MBPS = BIT(11),
40 CONF_HW_BIT_RATE_54MBPS = BIT(12),
41 CONF_HW_BIT_RATE_MCS_0 = BIT(13),
42 CONF_HW_BIT_RATE_MCS_1 = BIT(14),
43 CONF_HW_BIT_RATE_MCS_2 = BIT(15),
44 CONF_HW_BIT_RATE_MCS_3 = BIT(16),
45 CONF_HW_BIT_RATE_MCS_4 = BIT(17),
46 CONF_HW_BIT_RATE_MCS_5 = BIT(18),
47 CONF_HW_BIT_RATE_MCS_6 = BIT(19),
48 CONF_HW_BIT_RATE_MCS_7 = BIT(20)
49};
50
51enum {
52 CONF_HW_RATE_INDEX_1MBPS = 0,
53 CONF_HW_RATE_INDEX_2MBPS = 1,
54 CONF_HW_RATE_INDEX_5_5MBPS = 2,
55 CONF_HW_RATE_INDEX_6MBPS = 3,
56 CONF_HW_RATE_INDEX_9MBPS = 4,
57 CONF_HW_RATE_INDEX_11MBPS = 5,
58 CONF_HW_RATE_INDEX_12MBPS = 6,
59 CONF_HW_RATE_INDEX_18MBPS = 7,
60 CONF_HW_RATE_INDEX_22MBPS = 8,
61 CONF_HW_RATE_INDEX_24MBPS = 9,
62 CONF_HW_RATE_INDEX_36MBPS = 10,
63 CONF_HW_RATE_INDEX_48MBPS = 11,
64 CONF_HW_RATE_INDEX_54MBPS = 12,
65 CONF_HW_RATE_INDEX_MAX = CONF_HW_RATE_INDEX_54MBPS,
66};
67
68#define CONF_HW_RXTX_RATE_UNSUPPORTED 0xff
69
70enum {
71 CONF_SG_DISABLE = 0,
72 CONF_SG_PROTECTIVE,
73 CONF_SG_OPPORTUNISTIC
74};
75
76enum {
77 /*
78 * Configure the min and max time BT gains the antenna
79 * in WLAN / BT master basic rate
80 *
81 * Range: 0 - 255 (ms)
82 */
83 CONF_SG_ACL_BT_MASTER_MIN_BR = 0,
84 CONF_SG_ACL_BT_MASTER_MAX_BR,
85
86 /*
87 * Configure the min and max time BT gains the antenna
88 * in WLAN / BT slave basic rate
89 *
90 * Range: 0 - 255 (ms)
91 */
92 CONF_SG_ACL_BT_SLAVE_MIN_BR,
93 CONF_SG_ACL_BT_SLAVE_MAX_BR,
94
95 /*
96 * Configure the min and max time BT gains the antenna
97 * in WLAN / BT master EDR
98 *
99 * Range: 0 - 255 (ms)
100 */
101 CONF_SG_ACL_BT_MASTER_MIN_EDR,
102 CONF_SG_ACL_BT_MASTER_MAX_EDR,
103
104 /*
105 * Configure the min and max time BT gains the antenna
106 * in WLAN / BT slave EDR
107 *
108 * Range: 0 - 255 (ms)
109 */
110 CONF_SG_ACL_BT_SLAVE_MIN_EDR,
111 CONF_SG_ACL_BT_SLAVE_MAX_EDR,
112
113 /*
114 * The maximum time WLAN can gain the antenna
115 * in WLAN PSM / BT master/slave BR
116 *
117 * Range: 0 - 255 (ms)
118 */
119 CONF_SG_ACL_WLAN_PS_MASTER_BR,
120 CONF_SG_ACL_WLAN_PS_SLAVE_BR,
121
122 /*
123 * The maximum time WLAN can gain the antenna
124 * in WLAN PSM / BT master/slave EDR
125 *
126 * Range: 0 - 255 (ms)
127 */
128 CONF_SG_ACL_WLAN_PS_MASTER_EDR,
129 CONF_SG_ACL_WLAN_PS_SLAVE_EDR,
130
131 /* TODO: explain these values */
132 CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_BR,
133 CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_BR,
134 CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_BR,
135 CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_BR,
136 CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_EDR,
137 CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_EDR,
138 CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_EDR,
139 CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_EDR,
140
141 CONF_SG_ACL_ACTIVE_SCAN_WLAN_BR,
142 CONF_SG_ACL_ACTIVE_SCAN_WLAN_EDR,
143 CONF_SG_ACL_PASSIVE_SCAN_BT_BR,
144 CONF_SG_ACL_PASSIVE_SCAN_WLAN_BR,
145 CONF_SG_ACL_PASSIVE_SCAN_BT_EDR,
146 CONF_SG_ACL_PASSIVE_SCAN_WLAN_EDR,
147
148 /*
149 * Compensation percentage of probe requests when scan initiated
150 * during BT voice/ACL link.
151 *
152 * Range: 0 - 255 (%)
153 */
154 CONF_SG_AUTO_SCAN_PROBE_REQ,
155
156 /*
157 * Compensation percentage of probe requests when active scan initiated
158 * during BT voice
159 *
160 * Range: 0 - 255 (%)
161 */
162 CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_HV3,
163
164 /*
165 * Compensation percentage of WLAN active scan window if initiated
166 * during BT A2DP
167 *
168 * Range: 0 - 1000 (%)
169 */
170 CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_A2DP,
171
172 /*
173 * Compensation percentage of WLAN passive scan window if initiated
174 * during BT A2DP BR
175 *
176 * Range: 0 - 1000 (%)
177 */
178 CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_BR,
179
180 /*
181 * Compensation percentage of WLAN passive scan window if initiated
182 * during BT A2DP EDR
183 *
184 * Range: 0 - 1000 (%)
185 */
186 CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_EDR,
187
188 /*
189 * Compensation percentage of WLAN passive scan window if initiated
190 * during BT voice
191 *
192 * Range: 0 - 1000 (%)
193 */
194 CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_HV3,
195
196 /* TODO: explain these values */
197 CONF_SG_CONSECUTIVE_HV3_IN_PASSIVE_SCAN,
198 CONF_SG_BCN_HV3_COLLISION_THRESH_IN_PASSIVE_SCAN,
199 CONF_SG_TX_RX_PROTECTION_BWIDTH_IN_PASSIVE_SCAN,
200
201 /*
202 * Defines whether the SG will force WLAN host to enter/exit PSM
203 *
204 * Range: 1 - SG can force, 0 - host handles PSM
205 */
206 CONF_SG_STA_FORCE_PS_IN_BT_SCO,
207
208 /*
209 * Defines antenna configuration (single/dual antenna)
210 *
211 * Range: 0 - single antenna, 1 - dual antenna
212 */
213 CONF_SG_ANTENNA_CONFIGURATION,
214
215 /*
216 * The threshold (percent) of max consecutive beacon misses before
217 * increasing priority of beacon reception.
218 *
219 * Range: 0 - 100 (%)
220 */
221 CONF_SG_BEACON_MISS_PERCENT,
222
223 /*
224 * Protection time of the DHCP procedure.
225 *
226 * Range: 0 - 100000 (ms)
227 */
228 CONF_SG_DHCP_TIME,
229
230 /*
231 * RX guard time before the beginning of a new BT voice frame during
232 * which no new WLAN trigger frame is transmitted.
233 *
234 * Range: 0 - 100000 (us)
235 */
236 CONF_SG_RXT,
237
238 /*
239 * TX guard time before the beginning of a new BT voice frame during
240 * which no new WLAN frame is transmitted.
241 *
242 * Range: 0 - 100000 (us)
243 */
244
245 CONF_SG_TXT,
246
247 /*
248 * Enable adaptive RXT/TXT algorithm. If disabled, the host values
249 * will be utilized.
250 *
251 * Range: 0 - disable, 1 - enable
252 */
253 CONF_SG_ADAPTIVE_RXT_TXT,
254
255 /* TODO: explain this value */
256 CONF_SG_GENERAL_USAGE_BIT_MAP,
257
258 /*
259 * Number of consecutive BT voice frames not interrupted by WLAN
260 *
261 * Range: 0 - 100
262 */
263 CONF_SG_HV3_MAX_SERVED,
264
265 /*
266 * The used WLAN legacy service period during active BT ACL link
267 *
268 * Range: 0 - 255 (ms)
269 */
270 CONF_SG_PS_POLL_TIMEOUT,
271
272 /*
273 * The used WLAN UPSD service period during active BT ACL link
274 *
275 * Range: 0 - 255 (ms)
276 */
277 CONF_SG_UPSD_TIMEOUT,
278
279 CONF_SG_CONSECUTIVE_CTS_THRESHOLD,
280 CONF_SG_STA_RX_WINDOW_AFTER_DTIM,
281 CONF_SG_STA_CONNECTION_PROTECTION_TIME,
282
283 /* AP params */
284 CONF_AP_BEACON_MISS_TX,
285 CONF_AP_RX_WINDOW_AFTER_BEACON,
286 CONF_AP_BEACON_WINDOW_INTERVAL,
287 CONF_AP_CONNECTION_PROTECTION_TIME,
288 CONF_AP_BT_ACL_VAL_BT_SERVE_TIME,
289 CONF_AP_BT_ACL_VAL_WL_SERVE_TIME,
290
291 /* CTS Diluting params */
292 CONF_SG_CTS_DILUTED_BAD_RX_PACKETS_TH,
293 CONF_SG_CTS_CHOP_IN_DUAL_ANT_SCO_MASTER,
294
295 CONF_SG_TEMP_PARAM_1,
296 CONF_SG_TEMP_PARAM_2,
297 CONF_SG_TEMP_PARAM_3,
298 CONF_SG_TEMP_PARAM_4,
299 CONF_SG_TEMP_PARAM_5,
300 CONF_SG_TEMP_PARAM_6,
301 CONF_SG_TEMP_PARAM_7,
302 CONF_SG_TEMP_PARAM_8,
303 CONF_SG_TEMP_PARAM_9,
304 CONF_SG_TEMP_PARAM_10,
305
306 CONF_SG_PARAMS_MAX,
307 CONF_SG_PARAMS_ALL = 0xff
308};
309
310struct conf_sg_settings {
311 u32 params[CONF_SG_PARAMS_MAX];
312 u8 state;
313};
314
315enum conf_rx_queue_type {
316 CONF_RX_QUEUE_TYPE_LOW_PRIORITY, /* All except the high priority */
317 CONF_RX_QUEUE_TYPE_HIGH_PRIORITY, /* Management and voice packets */
318};
319
320struct conf_rx_settings {
321 /*
322 * The maximum amount of time, in TU, before the
323 * firmware discards the MSDU.
324 *
325 * Range: 0 - 0xFFFFFFFF
326 */
327 u32 rx_msdu_life_time;
328
329 /*
330 * Packet detection threshold in the PHY.
331 *
332 * FIXME: details unknown.
333 */
334 u32 packet_detection_threshold;
335
336 /*
337 * The longest time the STA will wait to receive traffic from the AP
338 * after a PS-poll has been transmitted.
339 *
340 * Range: 0 - 200000
341 */
342 u16 ps_poll_timeout;
343 /*
344 * The longest time the STA will wait to receive traffic from the AP
345 * after a frame has been sent from an UPSD enabled queue.
346 *
347 * Range: 0 - 200000
348 */
349 u16 upsd_timeout;
350
351 /*
352 * The number of octets in an MPDU, below which an RTS/CTS
353 * handshake is not performed.
354 *
355 * Range: 0 - 4096
356 */
357 u16 rts_threshold;
358
359 /*
360 * The RX Clear Channel Assessment threshold in the PHY
361 * (the energy threshold).
362 *
363 * Range: ENABLE_ENERGY_D == 0x140A
364 * DISABLE_ENERGY_D == 0xFFEF
365 */
366 u16 rx_cca_threshold;
367
368 /*
369 * Occupied Rx mem-blocks number which requires interrupting the host
370 * (0 = no buffering, 0xffff = disabled).
371 *
372 * Range: u16
373 */
374 u16 irq_blk_threshold;
375
376 /*
377 * Rx packets number which requires interrupting the host
378 * (0 = no buffering).
379 *
380 * Range: u16
381 */
382 u16 irq_pkt_threshold;
383
384 /*
385 * Max time in msec the FW may delay RX-Complete interrupt.
386 *
387 * Range: 1 - 100
388 */
389 u16 irq_timeout;
390
391 /*
392 * The RX queue type.
393 *
394 * Range: RX_QUEUE_TYPE_RX_LOW_PRIORITY, RX_QUEUE_TYPE_RX_HIGH_PRIORITY,
395 */
396 u8 queue_type;
397};
398
399#define CONF_TX_MAX_RATE_CLASSES 10
400
401#define CONF_TX_RATE_MASK_UNSPECIFIED 0
402#define CONF_TX_RATE_MASK_BASIC (CONF_HW_BIT_RATE_1MBPS | \
403 CONF_HW_BIT_RATE_2MBPS)
404#define CONF_TX_RATE_RETRY_LIMIT 10
405
406/* basic rates for p2p operations (probe req/resp, etc.) */
407#define CONF_TX_RATE_MASK_BASIC_P2P (CONF_HW_BIT_RATE_6MBPS | \
408 CONF_HW_BIT_RATE_12MBPS | CONF_HW_BIT_RATE_24MBPS)
409
410/*
411 * Rates supported for data packets when operating as AP. Note the absence
412 * of the 22Mbps rate. There is a FW limitation on 12 rates so we must drop
413 * one. The rate dropped is not mandatory under any operating mode.
414 */
415#define CONF_TX_AP_ENABLED_RATES (CONF_HW_BIT_RATE_1MBPS | \
416 CONF_HW_BIT_RATE_2MBPS | CONF_HW_BIT_RATE_5_5MBPS | \
417 CONF_HW_BIT_RATE_6MBPS | CONF_HW_BIT_RATE_9MBPS | \
418 CONF_HW_BIT_RATE_11MBPS | CONF_HW_BIT_RATE_12MBPS | \
419 CONF_HW_BIT_RATE_18MBPS | CONF_HW_BIT_RATE_24MBPS | \
420 CONF_HW_BIT_RATE_36MBPS | CONF_HW_BIT_RATE_48MBPS | \
421 CONF_HW_BIT_RATE_54MBPS)
422
423#define CONF_TX_CCK_RATES (CONF_HW_BIT_RATE_1MBPS | \
424 CONF_HW_BIT_RATE_2MBPS | CONF_HW_BIT_RATE_5_5MBPS | \
425 CONF_HW_BIT_RATE_11MBPS)
426
427#define CONF_TX_OFDM_RATES (CONF_HW_BIT_RATE_6MBPS | \
428 CONF_HW_BIT_RATE_12MBPS | CONF_HW_BIT_RATE_24MBPS | \
429 CONF_HW_BIT_RATE_36MBPS | CONF_HW_BIT_RATE_48MBPS | \
430 CONF_HW_BIT_RATE_54MBPS)
431
432#define CONF_TX_MCS_RATES (CONF_HW_BIT_RATE_MCS_0 | \
433 CONF_HW_BIT_RATE_MCS_1 | CONF_HW_BIT_RATE_MCS_2 | \
434 CONF_HW_BIT_RATE_MCS_3 | CONF_HW_BIT_RATE_MCS_4 | \
435 CONF_HW_BIT_RATE_MCS_5 | CONF_HW_BIT_RATE_MCS_6 | \
436 CONF_HW_BIT_RATE_MCS_7)
437
438/*
439 * Default rates for management traffic when operating in AP mode. This
440 * should be configured according to the basic rate set of the AP
441 */
442#define CONF_TX_AP_DEFAULT_MGMT_RATES (CONF_HW_BIT_RATE_1MBPS | \
443 CONF_HW_BIT_RATE_2MBPS | CONF_HW_BIT_RATE_5_5MBPS)
444
445/* default rates for working as IBSS (11b and OFDM) */
446#define CONF_TX_IBSS_DEFAULT_RATES (CONF_HW_BIT_RATE_1MBPS | \
447 CONF_HW_BIT_RATE_2MBPS | CONF_HW_BIT_RATE_5_5MBPS | \
448 CONF_HW_BIT_RATE_11MBPS | CONF_TX_OFDM_RATES);
449
450struct conf_tx_rate_class {
451
452 /*
453 * The rates enabled for this rate class.
454 *
455 * Range: CONF_HW_BIT_RATE_* bit mask
456 */
457 u32 enabled_rates;
458
459 /*
460 * The dot11 short retry limit used for TX retries.
461 *
462 * Range: u8
463 */
464 u8 short_retry_limit;
465
466 /*
467 * The dot11 long retry limit used for TX retries.
468 *
469 * Range: u8
470 */
471 u8 long_retry_limit;
472
473 /*
474 * Flags controlling the attributes of TX transmission.
475 *
476 * Range: bit 0: Truncate - when set, FW attempts to send a frame stop
477 * when the total valid per-rate attempts have
478 * been exhausted; otherwise transmissions
479 * will continue at the lowest available rate
480 * until the appropriate one of the
481 * short_retry_limit, long_retry_limit,
482 * dot11_max_transmit_msdu_life_time, or
483 * max_tx_life_time, is exhausted.
484 * 1: Preamble Override - indicates if the preamble type
485 * should be used in TX.
486 * 2: Preamble Type - the type of the preamble to be used by
487 * the policy (0 - long preamble, 1 - short preamble.
488 */
489 u8 aflags;
490};
491
492#define CONF_TX_MAX_AC_COUNT 4
493
494/* Slot number setting to start transmission at PIFS interval */
495#define CONF_TX_AIFS_PIFS 1
496/* Slot number setting to start transmission at DIFS interval normal
497 * DCF access */
498#define CONF_TX_AIFS_DIFS 2
499
500
501enum conf_tx_ac {
502 CONF_TX_AC_BE = 0, /* best effort / legacy */
503 CONF_TX_AC_BK = 1, /* background */
504 CONF_TX_AC_VI = 2, /* video */
505 CONF_TX_AC_VO = 3, /* voice */
506 CONF_TX_AC_CTS2SELF = 4, /* fictitious AC, follows AC_VO */
507 CONF_TX_AC_ANY_TID = 0x1f
508};
509
510struct conf_tx_ac_category {
511 /*
512 * The AC class identifier.
513 *
514 * Range: enum conf_tx_ac
515 */
516 u8 ac;
517
518 /*
519 * The contention window minimum size (in slots) for the access
520 * class.
521 *
522 * Range: u8
523 */
524 u8 cw_min;
525
526 /*
527 * The contention window maximum size (in slots) for the access
528 * class.
529 *
530 * Range: u8
531 */
532 u16 cw_max;
533
534 /*
535 * The AIF value (in slots) for the access class.
536 *
537 * Range: u8
538 */
539 u8 aifsn;
540
541 /*
542 * The TX Op Limit (in microseconds) for the access class.
543 *
544 * Range: u16
545 */
546 u16 tx_op_limit;
547};
548
549#define CONF_TX_MAX_TID_COUNT 8
550
551/* Allow TX BA on all TIDs but 6,7. These are currently reserved in the FW */
552#define CONF_TX_BA_ENABLED_TID_BITMAP 0x3F
553
554enum {
555 CONF_CHANNEL_TYPE_DCF = 0, /* DC/LEGACY*/
556 CONF_CHANNEL_TYPE_EDCF = 1, /* EDCA*/
557 CONF_CHANNEL_TYPE_HCCA = 2, /* HCCA*/
558};
559
560enum {
561 CONF_PS_SCHEME_LEGACY = 0,
562 CONF_PS_SCHEME_UPSD_TRIGGER = 1,
563 CONF_PS_SCHEME_LEGACY_PSPOLL = 2,
564 CONF_PS_SCHEME_SAPSD = 3,
565};
566
567enum {
568 CONF_ACK_POLICY_LEGACY = 0,
569 CONF_ACK_POLICY_NO_ACK = 1,
570 CONF_ACK_POLICY_BLOCK = 2,
571};
572
573
574struct conf_tx_tid {
575 u8 queue_id;
576 u8 channel_type;
577 u8 tsid;
578 u8 ps_scheme;
579 u8 ack_policy;
580 u32 apsd_conf[2];
581};
582
583struct conf_tx_settings {
584 /*
585 * The TX ED value for TELEC Enable/Disable.
586 *
587 * Range: 0, 1
588 */
589 u8 tx_energy_detection;
590
591 /*
592 * Configuration for rate classes for TX (currently only one
593 * rate class supported). Used in non-AP mode.
594 */
595 struct conf_tx_rate_class sta_rc_conf;
596
597 /*
598 * Configuration for access categories for TX rate control.
599 */
600 u8 ac_conf_count;
601 struct conf_tx_ac_category ac_conf[CONF_TX_MAX_AC_COUNT];
602
603 /*
604 * AP-mode - allow this number of TX retries to a station before an
605 * event is triggered from FW.
606 * In AP-mode the hlids of unreachable stations are given in the
607 * "sta_tx_retry_exceeded" member in the event mailbox.
608 */
609 u8 max_tx_retries;
610
611 /*
612 * AP-mode - after this number of seconds a connected station is
613 * considered inactive.
614 */
615 u16 ap_aging_period;
616
617 /*
618 * Configuration for TID parameters.
619 */
620 u8 tid_conf_count;
621 struct conf_tx_tid tid_conf[CONF_TX_MAX_TID_COUNT];
622
623 /*
624 * The TX fragmentation threshold.
625 *
626 * Range: u16
627 */
628 u16 frag_threshold;
629
630 /*
631 * Max time in msec the FW may delay frame TX-Complete interrupt.
632 *
633 * Range: u16
634 */
635 u16 tx_compl_timeout;
636
637 /*
638 * Completed TX packet count which requires to issue the TX-Complete
639 * interrupt.
640 *
641 * Range: u16
642 */
643 u16 tx_compl_threshold;
644
645 /*
646 * The rate used for control messages and scanning on the 2.4GHz band
647 *
648 * Range: CONF_HW_BIT_RATE_* bit mask
649 */
650 u32 basic_rate;
651
652 /*
653 * The rate used for control messages and scanning on the 5GHz band
654 *
655 * Range: CONF_HW_BIT_RATE_* bit mask
656 */
657 u32 basic_rate_5;
658
659 /*
660 * TX retry limits for templates
661 */
662 u8 tmpl_short_retry_limit;
663 u8 tmpl_long_retry_limit;
664
665 /* Time in ms for Tx watchdog timer to expire */
666 u32 tx_watchdog_timeout;
667};
668
669enum {
670 CONF_WAKE_UP_EVENT_BEACON = 0x01, /* Wake on every Beacon*/
671 CONF_WAKE_UP_EVENT_DTIM = 0x02, /* Wake on every DTIM*/
672 CONF_WAKE_UP_EVENT_N_DTIM = 0x04, /* Wake every Nth DTIM */
673 CONF_WAKE_UP_EVENT_N_BEACONS = 0x08, /* Wake every Nth beacon */
674 CONF_WAKE_UP_EVENT_BITS_MASK = 0x0F
675};
676
677#define CONF_MAX_BCN_FILT_IE_COUNT 32
678
679#define CONF_BCN_RULE_PASS_ON_CHANGE BIT(0)
680#define CONF_BCN_RULE_PASS_ON_APPEARANCE BIT(1)
681
682#define CONF_BCN_IE_OUI_LEN 3
683#define CONF_BCN_IE_VER_LEN 2
684
685struct conf_bcn_filt_rule {
686 /*
687 * IE number to which to associate a rule.
688 *
689 * Range: u8
690 */
691 u8 ie;
692
693 /*
694 * Rule to associate with the specific ie.
695 *
696 * Range: CONF_BCN_RULE_PASS_ON_*
697 */
698 u8 rule;
699
700 /*
701 * OUI for the vendor specifie IE (221)
702 */
703 u8 oui[CONF_BCN_IE_OUI_LEN];
704
705 /*
706 * Type for the vendor specifie IE (221)
707 */
708 u8 type;
709
710 /*
711 * Version for the vendor specifie IE (221)
712 */
713 u8 version[CONF_BCN_IE_VER_LEN];
714};
715
716#define CONF_MAX_RSSI_SNR_TRIGGERS 8
717
718enum {
719 CONF_TRIG_METRIC_RSSI_BEACON = 0,
720 CONF_TRIG_METRIC_RSSI_DATA,
721 CONF_TRIG_METRIC_SNR_BEACON,
722 CONF_TRIG_METRIC_SNR_DATA
723};
724
725enum {
726 CONF_TRIG_EVENT_TYPE_LEVEL = 0,
727 CONF_TRIG_EVENT_TYPE_EDGE
728};
729
730enum {
731 CONF_TRIG_EVENT_DIR_LOW = 0,
732 CONF_TRIG_EVENT_DIR_HIGH,
733 CONF_TRIG_EVENT_DIR_BIDIR
734};
735
736struct conf_sig_weights {
737
738 /*
739 * RSSI from beacons average weight.
740 *
741 * Range: u8
742 */
743 u8 rssi_bcn_avg_weight;
744
745 /*
746 * RSSI from data average weight.
747 *
748 * Range: u8
749 */
750 u8 rssi_pkt_avg_weight;
751
752 /*
753 * SNR from beacons average weight.
754 *
755 * Range: u8
756 */
757 u8 snr_bcn_avg_weight;
758
759 /*
760 * SNR from data average weight.
761 *
762 * Range: u8
763 */
764 u8 snr_pkt_avg_weight;
765};
766
767enum conf_bcn_filt_mode {
768 CONF_BCN_FILT_MODE_DISABLED = 0,
769 CONF_BCN_FILT_MODE_ENABLED = 1
770};
771
772enum conf_bet_mode {
773 CONF_BET_MODE_DISABLE = 0,
774 CONF_BET_MODE_ENABLE = 1,
775};
776
777struct conf_conn_settings {
778 /*
779 * Firmware wakeup conditions configuration. The host may set only
780 * one bit.
781 *
782 * Range: CONF_WAKE_UP_EVENT_*
783 */
784 u8 wake_up_event;
785
786 /*
787 * Listen interval for beacons or Dtims.
788 *
789 * Range: 0 for beacon and Dtim wakeup
790 * 1-10 for x Dtims
791 * 1-255 for x beacons
792 */
793 u8 listen_interval;
794
795 /*
796 * Firmware wakeup conditions during suspend
797 * Range: CONF_WAKE_UP_EVENT_*
798 */
799 u8 suspend_wake_up_event;
800
801 /*
802 * Listen interval during suspend.
803 * Currently will be in DTIMs (1-10)
804 *
805 */
806 u8 suspend_listen_interval;
807
808 /*
809 * Enable or disable the beacon filtering.
810 *
811 * Range: CONF_BCN_FILT_MODE_*
812 */
813 enum conf_bcn_filt_mode bcn_filt_mode;
814
815 /*
816 * Configure Beacon filter pass-thru rules.
817 */
818 u8 bcn_filt_ie_count;
819 struct conf_bcn_filt_rule bcn_filt_ie[CONF_MAX_BCN_FILT_IE_COUNT];
820
821 /*
822 * The number of consecutive beacons to lose, before the firmware
823 * becomes out of synch.
824 *
825 * Range: u32
826 */
827 u32 synch_fail_thold;
828
829 /*
830 * After out-of-synch, the number of TU's to wait without a further
831 * received beacon (or probe response) before issuing the BSS_EVENT_LOSE
832 * event.
833 *
834 * Range: u32
835 */
836 u32 bss_lose_timeout;
837
838 /*
839 * Beacon receive timeout.
840 *
841 * Range: u32
842 */
843 u32 beacon_rx_timeout;
844
845 /*
846 * Broadcast receive timeout.
847 *
848 * Range: u32
849 */
850 u32 broadcast_timeout;
851
852 /*
853 * Enable/disable reception of broadcast packets in power save mode
854 *
855 * Range: 1 - enable, 0 - disable
856 */
857 u8 rx_broadcast_in_ps;
858
859 /*
860 * Consecutive PS Poll failures before sending event to driver
861 *
862 * Range: u8
863 */
864 u8 ps_poll_threshold;
865
866 /*
867 * Configuration of signal average weights.
868 */
869 struct conf_sig_weights sig_weights;
870
871 /*
872 * Specifies if beacon early termination procedure is enabled or
873 * disabled.
874 *
875 * Range: CONF_BET_MODE_*
876 */
877 u8 bet_enable;
878
879 /*
880 * Specifies the maximum number of consecutive beacons that may be
881 * early terminated. After this number is reached at least one full
882 * beacon must be correctly received in FW before beacon ET
883 * resumes.
884 *
885 * Range 0 - 255
886 */
887 u8 bet_max_consecutive;
888
889 /*
890 * Specifies the maximum number of times to try PSM entry if it fails
891 * (if sending the appropriate null-func message fails.)
892 *
893 * Range 0 - 255
894 */
895 u8 psm_entry_retries;
896
897 /*
898 * Specifies the maximum number of times to try PSM exit if it fails
899 * (if sending the appropriate null-func message fails.)
900 *
901 * Range 0 - 255
902 */
903 u8 psm_exit_retries;
904
905 /*
906 * Specifies the maximum number of times to try transmit the PSM entry
907 * null-func frame for each PSM entry attempt
908 *
909 * Range 0 - 255
910 */
911 u8 psm_entry_nullfunc_retries;
912
913 /*
914 * Specifies the dynamic PS timeout in ms that will be used
915 * by the FW when in AUTO_PS mode
916 */
917 u16 dynamic_ps_timeout;
918
919 /*
920 * Specifies whether dynamic PS should be disabled and PSM forced.
921 * This is required for certain WiFi certification tests.
922 */
923 u8 forced_ps;
924
925 /*
926 *
927 * Specifies the interval of the connection keep-alive null-func
928 * frame in ms.
929 *
930 * Range: 1000 - 3600000
931 */
932 u32 keep_alive_interval;
933
934 /*
935 * Maximum listen interval supported by the driver in units of beacons.
936 *
937 * Range: u16
938 */
939 u8 max_listen_interval;
940};
941
942enum {
943 CONF_REF_CLK_19_2_E,
944 CONF_REF_CLK_26_E,
945 CONF_REF_CLK_38_4_E,
946 CONF_REF_CLK_52_E,
947 CONF_REF_CLK_38_4_M_XTAL,
948 CONF_REF_CLK_26_M_XTAL,
949};
950
951enum single_dual_band_enum {
952 CONF_SINGLE_BAND,
953 CONF_DUAL_BAND
954};
955
956#define CONF_RSSI_AND_PROCESS_COMPENSATION_SIZE 15
957#define CONF_NUMBER_OF_SUB_BANDS_5 7
958#define CONF_NUMBER_OF_RATE_GROUPS 6
959#define CONF_NUMBER_OF_CHANNELS_2_4 14
960#define CONF_NUMBER_OF_CHANNELS_5 35
961
962struct conf_itrim_settings {
963 /* enable dco itrim */
964 u8 enable;
965
966 /* moderation timeout in microsecs from the last TX */
967 u32 timeout;
968};
969
970struct conf_pm_config_settings {
971 /*
972 * Host clock settling time
973 *
974 * Range: 0 - 30000 us
975 */
976 u32 host_clk_settling_time;
977
978 /*
979 * Host fast wakeup support
980 *
981 * Range: true, false
982 */
983 bool host_fast_wakeup_support;
984};
985
986struct conf_roam_trigger_settings {
987 /*
988 * The minimum interval between two trigger events.
989 *
990 * Range: 0 - 60000 ms
991 */
992 u16 trigger_pacing;
993
994 /*
995 * The weight for rssi/beacon average calculation
996 *
997 * Range: 0 - 255
998 */
999 u8 avg_weight_rssi_beacon;
1000
1001 /*
1002 * The weight for rssi/data frame average calculation
1003 *
1004 * Range: 0 - 255
1005 */
1006 u8 avg_weight_rssi_data;
1007
1008 /*
1009 * The weight for snr/beacon average calculation
1010 *
1011 * Range: 0 - 255
1012 */
1013 u8 avg_weight_snr_beacon;
1014
1015 /*
1016 * The weight for snr/data frame average calculation
1017 *
1018 * Range: 0 - 255
1019 */
1020 u8 avg_weight_snr_data;
1021};
1022
1023struct conf_scan_settings {
1024 /*
1025 * The minimum time to wait on each channel for active scans
1026 *
1027 * Range: u32 tu/1000
1028 */
1029 u32 min_dwell_time_active;
1030
1031 /*
1032 * The maximum time to wait on each channel for active scans
1033 *
1034 * Range: u32 tu/1000
1035 */
1036 u32 max_dwell_time_active;
1037
1038 /*
1039 * The minimum time to wait on each channel for passive scans
1040 *
1041 * Range: u32 tu/1000
1042 */
1043 u32 min_dwell_time_passive;
1044
1045 /*
1046 * The maximum time to wait on each channel for passive scans
1047 *
1048 * Range: u32 tu/1000
1049 */
1050 u32 max_dwell_time_passive;
1051
1052 /*
1053 * Number of probe requests to transmit on each active scan channel
1054 *
1055 * Range: u8
1056 */
1057 u16 num_probe_reqs;
1058
1059 /*
1060 * Scan trigger (split scan) timeout. The FW will split the scan
1061 * operation into slices of the given time and allow the FW to schedule
1062 * other tasks in between.
1063 *
1064 * Range: u32 Microsecs
1065 */
1066 u32 split_scan_timeout;
1067};
1068
1069struct conf_sched_scan_settings {
1070 /*
1071 * The base time to wait on the channel for active scans (in TU/1000).
1072 * The minimum dwell time is calculated according to this:
1073 * min_dwell_time = base + num_of_probes_to_be_sent * delta_per_probe
1074 * The maximum dwell time is calculated according to this:
1075 * max_dwell_time = min_dwell_time + max_dwell_time_delta
1076 */
1077 u32 base_dwell_time;
1078
1079 /* The delta between the min dwell time and max dwell time for
1080 * active scans (in TU/1000s). The max dwell time is used by the FW once
1081 * traffic is detected on the channel.
1082 */
1083 u32 max_dwell_time_delta;
1084
1085 /* Delta added to min dwell time per each probe in 2.4 GHz (TU/1000) */
1086 u32 dwell_time_delta_per_probe;
1087
1088 /* Delta added to min dwell time per each probe in 5 GHz (TU/1000) */
1089 u32 dwell_time_delta_per_probe_5;
1090
1091 /* time to wait on the channel for passive scans (in TU/1000) */
1092 u32 dwell_time_passive;
1093
1094 /* time to wait on the channel for DFS scans (in TU/1000) */
1095 u32 dwell_time_dfs;
1096
1097 /* number of probe requests to send on each channel in active scans */
1098 u8 num_probe_reqs;
1099
1100 /* RSSI threshold to be used for filtering */
1101 s8 rssi_threshold;
1102
1103 /* SNR threshold to be used for filtering */
1104 s8 snr_threshold;
1105};
1106
1107struct conf_ht_setting {
1108 u8 rx_ba_win_size;
1109 u8 tx_ba_win_size;
1110 u16 inactivity_timeout;
1111
1112 /* bitmap of enabled TIDs for TX BA sessions */
1113 u8 tx_ba_tid_bitmap;
1114};
1115
1116struct conf_memory_settings {
1117 /* Number of stations supported in IBSS mode */
1118 u8 num_stations;
1119
1120 /* Number of ssid profiles used in IBSS mode */
1121 u8 ssid_profiles;
1122
1123 /* Number of memory buffers allocated to rx pool */
1124 u8 rx_block_num;
1125
1126 /* Minimum number of blocks allocated to tx pool */
1127 u8 tx_min_block_num;
1128
1129 /* Disable/Enable dynamic memory */
1130 u8 dynamic_memory;
1131
1132 /*
1133 * Minimum required free tx memory blocks in order to assure optimum
1134 * performance
1135 *
1136 * Range: 0-120
1137 */
1138 u8 min_req_tx_blocks;
1139
1140 /*
1141 * Minimum required free rx memory blocks in order to assure optimum
1142 * performance
1143 *
1144 * Range: 0-120
1145 */
1146 u8 min_req_rx_blocks;
1147
1148 /*
1149 * Minimum number of mem blocks (free+used) guaranteed for TX
1150 *
1151 * Range: 0-120
1152 */
1153 u8 tx_min;
1154};
1155
1156struct conf_fm_coex {
1157 u8 enable;
1158 u8 swallow_period;
1159 u8 n_divider_fref_set_1;
1160 u8 n_divider_fref_set_2;
1161 u16 m_divider_fref_set_1;
1162 u16 m_divider_fref_set_2;
1163 u32 coex_pll_stabilization_time;
1164 u16 ldo_stabilization_time;
1165 u8 fm_disturbed_band_margin;
1166 u8 swallow_clk_diff;
1167};
1168
1169struct conf_rx_streaming_settings {
1170 /*
1171 * RX Streaming duration (in msec) from last tx/rx
1172 *
1173 * Range: u32
1174 */
1175 u32 duration;
1176
1177 /*
1178 * Bitmap of tids to be polled during RX streaming.
1179 * (Note: it doesn't look like it really matters)
1180 *
1181 * Range: 0x1-0xff
1182 */
1183 u8 queues;
1184
1185 /*
1186 * RX Streaming interval.
1187 * (Note:this value is also used as the rx streaming timeout)
1188 * Range: 0 (disabled), 10 - 100
1189 */
1190 u8 interval;
1191
1192 /*
1193 * enable rx streaming also when there is no coex activity
1194 */
1195 u8 always;
1196};
1197
1198struct conf_fwlog {
1199 /* Continuous or on-demand */
1200 u8 mode;
1201
1202 /*
1203 * Number of memory blocks dedicated for the FW logger
1204 *
1205 * Range: 1-3, or 0 to disable the FW logger
1206 */
1207 u8 mem_blocks;
1208
1209 /* Minimum log level threshold */
1210 u8 severity;
1211
1212 /* Include/exclude timestamps from the log messages */
1213 u8 timestamp;
1214
1215 /* See enum wl1271_fwlogger_output */
1216 u8 output;
1217
1218 /* Regulates the frequency of log messages */
1219 u8 threshold;
1220};
1221
1222#define ACX_RATE_MGMT_NUM_OF_RATES 13
1223struct conf_rate_policy_settings {
1224 u16 rate_retry_score;
1225 u16 per_add;
1226 u16 per_th1;
1227 u16 per_th2;
1228 u16 max_per;
1229 u8 inverse_curiosity_factor;
1230 u8 tx_fail_low_th;
1231 u8 tx_fail_high_th;
1232 u8 per_alpha_shift;
1233 u8 per_add_shift;
1234 u8 per_beta1_shift;
1235 u8 per_beta2_shift;
1236 u8 rate_check_up;
1237 u8 rate_check_down;
1238 u8 rate_retry_policy[ACX_RATE_MGMT_NUM_OF_RATES];
1239};
1240
1241struct conf_hangover_settings {
1242 u32 recover_time;
1243 u8 hangover_period;
1244 u8 dynamic_mode;
1245 u8 early_termination_mode;
1246 u8 max_period;
1247 u8 min_period;
1248 u8 increase_delta;
1249 u8 decrease_delta;
1250 u8 quiet_time;
1251 u8 increase_time;
1252 u8 window_size;
1253};
1254
1255struct wlcore_conf {
1256 struct conf_sg_settings sg;
1257 struct conf_rx_settings rx;
1258 struct conf_tx_settings tx;
1259 struct conf_conn_settings conn;
1260 struct conf_itrim_settings itrim;
1261 struct conf_pm_config_settings pm_config;
1262 struct conf_roam_trigger_settings roam_trigger;
1263 struct conf_scan_settings scan;
1264 struct conf_sched_scan_settings sched_scan;
1265 struct conf_ht_setting ht;
1266 struct conf_memory_settings mem;
1267 struct conf_fm_coex fm_coex;
1268 struct conf_rx_streaming_settings rx_streaming;
1269 struct conf_fwlog fwlog;
1270 struct conf_rate_policy_settings rate;
1271 struct conf_hangover_settings hangover;
1272};
1273
1274#endif
diff --git a/drivers/net/wireless/ti/wlcore/debug.h b/drivers/net/wireless/ti/wlcore/debug.h
new file mode 100644
index 000000000000..6b800b3cbea5
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/debug.h
@@ -0,0 +1,103 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (C) 2011 Texas Instruments. All rights reserved.
5 * Copyright (C) 2008-2009 Nokia Corporation
6 *
7 * Contact: Luciano Coelho <coelho@ti.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 __DEBUG_H__
26#define __DEBUG_H__
27
28#include <linux/bitops.h>
29#include <linux/printk.h>
30
31#define DRIVER_NAME "wl12xx"
32#define DRIVER_PREFIX DRIVER_NAME ": "
33
34enum {
35 DEBUG_NONE = 0,
36 DEBUG_IRQ = BIT(0),
37 DEBUG_SPI = BIT(1),
38 DEBUG_BOOT = BIT(2),
39 DEBUG_MAILBOX = BIT(3),
40 DEBUG_TESTMODE = BIT(4),
41 DEBUG_EVENT = BIT(5),
42 DEBUG_TX = BIT(6),
43 DEBUG_RX = BIT(7),
44 DEBUG_SCAN = BIT(8),
45 DEBUG_CRYPT = BIT(9),
46 DEBUG_PSM = BIT(10),
47 DEBUG_MAC80211 = BIT(11),
48 DEBUG_CMD = BIT(12),
49 DEBUG_ACX = BIT(13),
50 DEBUG_SDIO = BIT(14),
51 DEBUG_FILTERS = BIT(15),
52 DEBUG_ADHOC = BIT(16),
53 DEBUG_AP = BIT(17),
54 DEBUG_PROBE = BIT(18),
55 DEBUG_IO = BIT(19),
56 DEBUG_MASTER = (DEBUG_ADHOC | DEBUG_AP),
57 DEBUG_ALL = ~0,
58};
59
60extern u32 wl12xx_debug_level;
61
62#define DEBUG_DUMP_LIMIT 1024
63
64#define wl1271_error(fmt, arg...) \
65 pr_err(DRIVER_PREFIX "ERROR " fmt "\n", ##arg)
66
67#define wl1271_warning(fmt, arg...) \
68 pr_warning(DRIVER_PREFIX "WARNING " fmt "\n", ##arg)
69
70#define wl1271_notice(fmt, arg...) \
71 pr_info(DRIVER_PREFIX fmt "\n", ##arg)
72
73#define wl1271_info(fmt, arg...) \
74 pr_info(DRIVER_PREFIX fmt "\n", ##arg)
75
76#define wl1271_debug(level, fmt, arg...) \
77 do { \
78 if (level & wl12xx_debug_level) \
79 pr_debug(DRIVER_PREFIX fmt "\n", ##arg); \
80 } while (0)
81
82/* TODO: use pr_debug_hex_dump when it becomes available */
83#define wl1271_dump(level, prefix, buf, len) \
84 do { \
85 if (level & wl12xx_debug_level) \
86 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
87 DUMP_PREFIX_OFFSET, 16, 1, \
88 buf, \
89 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
90 0); \
91 } while (0)
92
93#define wl1271_dump_ascii(level, prefix, buf, len) \
94 do { \
95 if (level & wl12xx_debug_level) \
96 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
97 DUMP_PREFIX_OFFSET, 16, 1, \
98 buf, \
99 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
100 true); \
101 } while (0)
102
103#endif /* __DEBUG_H__ */
diff --git a/drivers/net/wireless/ti/wlcore/debugfs.c b/drivers/net/wireless/ti/wlcore/debugfs.c
new file mode 100644
index 000000000000..0b775e35b5df
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/debugfs.c
@@ -0,0 +1,1204 @@
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 "wlcore.h"
30#include "debug.h"
31#include "acx.h"
32#include "ps.h"
33#include "io.h"
34#include "tx.h"
35
36/* ms */
37#define WL1271_DEBUGFS_STATS_LIFETIME 1000
38
39/* debugfs macros idea from mac80211 */
40#define DEBUGFS_FORMAT_BUFFER_SIZE 100
41static int wl1271_format_buffer(char __user *userbuf, size_t count,
42 loff_t *ppos, char *fmt, ...)
43{
44 va_list args;
45 char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
46 int res;
47
48 va_start(args, fmt);
49 res = vscnprintf(buf, sizeof(buf), fmt, args);
50 va_end(args);
51
52 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
53}
54
55#define DEBUGFS_READONLY_FILE(name, fmt, value...) \
56static ssize_t name## _read(struct file *file, char __user *userbuf, \
57 size_t count, loff_t *ppos) \
58{ \
59 struct wl1271 *wl = file->private_data; \
60 return wl1271_format_buffer(userbuf, count, ppos, \
61 fmt "\n", ##value); \
62} \
63 \
64static const struct file_operations name## _ops = { \
65 .read = name## _read, \
66 .open = wl1271_open_file_generic, \
67 .llseek = generic_file_llseek, \
68};
69
70#define DEBUGFS_ADD(name, parent) \
71 entry = debugfs_create_file(#name, 0400, parent, \
72 wl, &name## _ops); \
73 if (!entry || IS_ERR(entry)) \
74 goto err; \
75
76#define DEBUGFS_ADD_PREFIX(prefix, name, parent) \
77 do { \
78 entry = debugfs_create_file(#name, 0400, parent, \
79 wl, &prefix## _## name## _ops); \
80 if (!entry || IS_ERR(entry)) \
81 goto err; \
82 } while (0);
83
84#define DEBUGFS_FWSTATS_FILE(sub, name, fmt) \
85static ssize_t sub## _ ##name## _read(struct file *file, \
86 char __user *userbuf, \
87 size_t count, loff_t *ppos) \
88{ \
89 struct wl1271 *wl = file->private_data; \
90 \
91 wl1271_debugfs_update_stats(wl); \
92 \
93 return wl1271_format_buffer(userbuf, count, ppos, fmt "\n", \
94 wl->stats.fw_stats->sub.name); \
95} \
96 \
97static const struct file_operations sub## _ ##name## _ops = { \
98 .read = sub## _ ##name## _read, \
99 .open = wl1271_open_file_generic, \
100 .llseek = generic_file_llseek, \
101};
102
103#define DEBUGFS_FWSTATS_ADD(sub, name) \
104 DEBUGFS_ADD(sub## _ ##name, stats)
105
106static void wl1271_debugfs_update_stats(struct wl1271 *wl)
107{
108 int ret;
109
110 mutex_lock(&wl->mutex);
111
112 ret = wl1271_ps_elp_wakeup(wl);
113 if (ret < 0)
114 goto out;
115
116 if (wl->state == WL1271_STATE_ON && !wl->plt &&
117 time_after(jiffies, wl->stats.fw_stats_update +
118 msecs_to_jiffies(WL1271_DEBUGFS_STATS_LIFETIME))) {
119 wl1271_acx_statistics(wl, wl->stats.fw_stats);
120 wl->stats.fw_stats_update = jiffies;
121 }
122
123 wl1271_ps_elp_sleep(wl);
124
125out:
126 mutex_unlock(&wl->mutex);
127}
128
129static int wl1271_open_file_generic(struct inode *inode, struct file *file)
130{
131 file->private_data = inode->i_private;
132 return 0;
133}
134
135DEBUGFS_FWSTATS_FILE(tx, internal_desc_overflow, "%u");
136
137DEBUGFS_FWSTATS_FILE(rx, out_of_mem, "%u");
138DEBUGFS_FWSTATS_FILE(rx, hdr_overflow, "%u");
139DEBUGFS_FWSTATS_FILE(rx, hw_stuck, "%u");
140DEBUGFS_FWSTATS_FILE(rx, dropped, "%u");
141DEBUGFS_FWSTATS_FILE(rx, fcs_err, "%u");
142DEBUGFS_FWSTATS_FILE(rx, xfr_hint_trig, "%u");
143DEBUGFS_FWSTATS_FILE(rx, path_reset, "%u");
144DEBUGFS_FWSTATS_FILE(rx, reset_counter, "%u");
145
146DEBUGFS_FWSTATS_FILE(dma, rx_requested, "%u");
147DEBUGFS_FWSTATS_FILE(dma, rx_errors, "%u");
148DEBUGFS_FWSTATS_FILE(dma, tx_requested, "%u");
149DEBUGFS_FWSTATS_FILE(dma, tx_errors, "%u");
150
151DEBUGFS_FWSTATS_FILE(isr, cmd_cmplt, "%u");
152DEBUGFS_FWSTATS_FILE(isr, fiqs, "%u");
153DEBUGFS_FWSTATS_FILE(isr, rx_headers, "%u");
154DEBUGFS_FWSTATS_FILE(isr, rx_mem_overflow, "%u");
155DEBUGFS_FWSTATS_FILE(isr, rx_rdys, "%u");
156DEBUGFS_FWSTATS_FILE(isr, irqs, "%u");
157DEBUGFS_FWSTATS_FILE(isr, tx_procs, "%u");
158DEBUGFS_FWSTATS_FILE(isr, decrypt_done, "%u");
159DEBUGFS_FWSTATS_FILE(isr, dma0_done, "%u");
160DEBUGFS_FWSTATS_FILE(isr, dma1_done, "%u");
161DEBUGFS_FWSTATS_FILE(isr, tx_exch_complete, "%u");
162DEBUGFS_FWSTATS_FILE(isr, commands, "%u");
163DEBUGFS_FWSTATS_FILE(isr, rx_procs, "%u");
164DEBUGFS_FWSTATS_FILE(isr, hw_pm_mode_changes, "%u");
165DEBUGFS_FWSTATS_FILE(isr, host_acknowledges, "%u");
166DEBUGFS_FWSTATS_FILE(isr, pci_pm, "%u");
167DEBUGFS_FWSTATS_FILE(isr, wakeups, "%u");
168DEBUGFS_FWSTATS_FILE(isr, low_rssi, "%u");
169
170DEBUGFS_FWSTATS_FILE(wep, addr_key_count, "%u");
171DEBUGFS_FWSTATS_FILE(wep, default_key_count, "%u");
172/* skipping wep.reserved */
173DEBUGFS_FWSTATS_FILE(wep, key_not_found, "%u");
174DEBUGFS_FWSTATS_FILE(wep, decrypt_fail, "%u");
175DEBUGFS_FWSTATS_FILE(wep, packets, "%u");
176DEBUGFS_FWSTATS_FILE(wep, interrupt, "%u");
177
178DEBUGFS_FWSTATS_FILE(pwr, ps_enter, "%u");
179DEBUGFS_FWSTATS_FILE(pwr, elp_enter, "%u");
180DEBUGFS_FWSTATS_FILE(pwr, missing_bcns, "%u");
181DEBUGFS_FWSTATS_FILE(pwr, wake_on_host, "%u");
182DEBUGFS_FWSTATS_FILE(pwr, wake_on_timer_exp, "%u");
183DEBUGFS_FWSTATS_FILE(pwr, tx_with_ps, "%u");
184DEBUGFS_FWSTATS_FILE(pwr, tx_without_ps, "%u");
185DEBUGFS_FWSTATS_FILE(pwr, rcvd_beacons, "%u");
186DEBUGFS_FWSTATS_FILE(pwr, power_save_off, "%u");
187DEBUGFS_FWSTATS_FILE(pwr, enable_ps, "%u");
188DEBUGFS_FWSTATS_FILE(pwr, disable_ps, "%u");
189DEBUGFS_FWSTATS_FILE(pwr, fix_tsf_ps, "%u");
190/* skipping cont_miss_bcns_spread for now */
191DEBUGFS_FWSTATS_FILE(pwr, rcvd_awake_beacons, "%u");
192
193DEBUGFS_FWSTATS_FILE(mic, rx_pkts, "%u");
194DEBUGFS_FWSTATS_FILE(mic, calc_failure, "%u");
195
196DEBUGFS_FWSTATS_FILE(aes, encrypt_fail, "%u");
197DEBUGFS_FWSTATS_FILE(aes, decrypt_fail, "%u");
198DEBUGFS_FWSTATS_FILE(aes, encrypt_packets, "%u");
199DEBUGFS_FWSTATS_FILE(aes, decrypt_packets, "%u");
200DEBUGFS_FWSTATS_FILE(aes, encrypt_interrupt, "%u");
201DEBUGFS_FWSTATS_FILE(aes, decrypt_interrupt, "%u");
202
203DEBUGFS_FWSTATS_FILE(event, heart_beat, "%u");
204DEBUGFS_FWSTATS_FILE(event, calibration, "%u");
205DEBUGFS_FWSTATS_FILE(event, rx_mismatch, "%u");
206DEBUGFS_FWSTATS_FILE(event, rx_mem_empty, "%u");
207DEBUGFS_FWSTATS_FILE(event, rx_pool, "%u");
208DEBUGFS_FWSTATS_FILE(event, oom_late, "%u");
209DEBUGFS_FWSTATS_FILE(event, phy_transmit_error, "%u");
210DEBUGFS_FWSTATS_FILE(event, tx_stuck, "%u");
211
212DEBUGFS_FWSTATS_FILE(ps, pspoll_timeouts, "%u");
213DEBUGFS_FWSTATS_FILE(ps, upsd_timeouts, "%u");
214DEBUGFS_FWSTATS_FILE(ps, upsd_max_sptime, "%u");
215DEBUGFS_FWSTATS_FILE(ps, upsd_max_apturn, "%u");
216DEBUGFS_FWSTATS_FILE(ps, pspoll_max_apturn, "%u");
217DEBUGFS_FWSTATS_FILE(ps, pspoll_utilization, "%u");
218DEBUGFS_FWSTATS_FILE(ps, upsd_utilization, "%u");
219
220DEBUGFS_FWSTATS_FILE(rxpipe, rx_prep_beacon_drop, "%u");
221DEBUGFS_FWSTATS_FILE(rxpipe, descr_host_int_trig_rx_data, "%u");
222DEBUGFS_FWSTATS_FILE(rxpipe, beacon_buffer_thres_host_int_trig_rx_data, "%u");
223DEBUGFS_FWSTATS_FILE(rxpipe, missed_beacon_host_int_trig_rx_data, "%u");
224DEBUGFS_FWSTATS_FILE(rxpipe, tx_xfr_host_int_trig_rx_data, "%u");
225
226DEBUGFS_READONLY_FILE(retry_count, "%u", wl->stats.retry_count);
227DEBUGFS_READONLY_FILE(excessive_retries, "%u",
228 wl->stats.excessive_retries);
229
230static ssize_t tx_queue_len_read(struct file *file, char __user *userbuf,
231 size_t count, loff_t *ppos)
232{
233 struct wl1271 *wl = file->private_data;
234 u32 queue_len;
235 char buf[20];
236 int res;
237
238 queue_len = wl1271_tx_total_queue_count(wl);
239
240 res = scnprintf(buf, sizeof(buf), "%u\n", queue_len);
241 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
242}
243
244static const struct file_operations tx_queue_len_ops = {
245 .read = tx_queue_len_read,
246 .open = wl1271_open_file_generic,
247 .llseek = default_llseek,
248};
249
250static ssize_t gpio_power_read(struct file *file, char __user *user_buf,
251 size_t count, loff_t *ppos)
252{
253 struct wl1271 *wl = file->private_data;
254 bool state = test_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
255
256 int res;
257 char buf[10];
258
259 res = scnprintf(buf, sizeof(buf), "%d\n", state);
260
261 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
262}
263
264static ssize_t gpio_power_write(struct file *file,
265 const char __user *user_buf,
266 size_t count, loff_t *ppos)
267{
268 struct wl1271 *wl = file->private_data;
269 unsigned long value;
270 int ret;
271
272 ret = kstrtoul_from_user(user_buf, count, 10, &value);
273 if (ret < 0) {
274 wl1271_warning("illegal value in gpio_power");
275 return -EINVAL;
276 }
277
278 mutex_lock(&wl->mutex);
279
280 if (value)
281 wl1271_power_on(wl);
282 else
283 wl1271_power_off(wl);
284
285 mutex_unlock(&wl->mutex);
286 return count;
287}
288
289static const struct file_operations gpio_power_ops = {
290 .read = gpio_power_read,
291 .write = gpio_power_write,
292 .open = wl1271_open_file_generic,
293 .llseek = default_llseek,
294};
295
296static ssize_t start_recovery_write(struct file *file,
297 const char __user *user_buf,
298 size_t count, loff_t *ppos)
299{
300 struct wl1271 *wl = file->private_data;
301
302 mutex_lock(&wl->mutex);
303 wl12xx_queue_recovery_work(wl);
304 mutex_unlock(&wl->mutex);
305
306 return count;
307}
308
309static const struct file_operations start_recovery_ops = {
310 .write = start_recovery_write,
311 .open = wl1271_open_file_generic,
312 .llseek = default_llseek,
313};
314
315static ssize_t dynamic_ps_timeout_read(struct file *file, char __user *user_buf,
316 size_t count, loff_t *ppos)
317{
318 struct wl1271 *wl = file->private_data;
319
320 return wl1271_format_buffer(user_buf, count,
321 ppos, "%d\n",
322 wl->conf.conn.dynamic_ps_timeout);
323}
324
325static ssize_t dynamic_ps_timeout_write(struct file *file,
326 const char __user *user_buf,
327 size_t count, loff_t *ppos)
328{
329 struct wl1271 *wl = file->private_data;
330 struct wl12xx_vif *wlvif;
331 unsigned long value;
332 int ret;
333
334 ret = kstrtoul_from_user(user_buf, count, 10, &value);
335 if (ret < 0) {
336 wl1271_warning("illegal value in dynamic_ps");
337 return -EINVAL;
338 }
339
340 if (value < 1 || value > 65535) {
341 wl1271_warning("dyanmic_ps_timeout is not in valid range");
342 return -ERANGE;
343 }
344
345 mutex_lock(&wl->mutex);
346
347 wl->conf.conn.dynamic_ps_timeout = value;
348
349 if (wl->state == WL1271_STATE_OFF)
350 goto out;
351
352 ret = wl1271_ps_elp_wakeup(wl);
353 if (ret < 0)
354 goto out;
355
356 /* In case we're already in PSM, trigger it again to set new timeout
357 * immediately without waiting for re-association
358 */
359
360 wl12xx_for_each_wlvif_sta(wl, wlvif) {
361 if (test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags))
362 wl1271_ps_set_mode(wl, wlvif, STATION_AUTO_PS_MODE);
363 }
364
365 wl1271_ps_elp_sleep(wl);
366
367out:
368 mutex_unlock(&wl->mutex);
369 return count;
370}
371
372static const struct file_operations dynamic_ps_timeout_ops = {
373 .read = dynamic_ps_timeout_read,
374 .write = dynamic_ps_timeout_write,
375 .open = wl1271_open_file_generic,
376 .llseek = default_llseek,
377};
378
379static ssize_t forced_ps_read(struct file *file, char __user *user_buf,
380 size_t count, loff_t *ppos)
381{
382 struct wl1271 *wl = file->private_data;
383
384 return wl1271_format_buffer(user_buf, count,
385 ppos, "%d\n",
386 wl->conf.conn.forced_ps);
387}
388
389static ssize_t forced_ps_write(struct file *file,
390 const char __user *user_buf,
391 size_t count, loff_t *ppos)
392{
393 struct wl1271 *wl = file->private_data;
394 struct wl12xx_vif *wlvif;
395 unsigned long value;
396 int ret, ps_mode;
397
398 ret = kstrtoul_from_user(user_buf, count, 10, &value);
399 if (ret < 0) {
400 wl1271_warning("illegal value in forced_ps");
401 return -EINVAL;
402 }
403
404 if (value != 1 && value != 0) {
405 wl1271_warning("forced_ps should be either 0 or 1");
406 return -ERANGE;
407 }
408
409 mutex_lock(&wl->mutex);
410
411 if (wl->conf.conn.forced_ps == value)
412 goto out;
413
414 wl->conf.conn.forced_ps = value;
415
416 if (wl->state == WL1271_STATE_OFF)
417 goto out;
418
419 ret = wl1271_ps_elp_wakeup(wl);
420 if (ret < 0)
421 goto out;
422
423 /* In case we're already in PSM, trigger it again to switch mode
424 * immediately without waiting for re-association
425 */
426
427 ps_mode = value ? STATION_POWER_SAVE_MODE : STATION_AUTO_PS_MODE;
428
429 wl12xx_for_each_wlvif_sta(wl, wlvif) {
430 if (test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags))
431 wl1271_ps_set_mode(wl, wlvif, ps_mode);
432 }
433
434 wl1271_ps_elp_sleep(wl);
435
436out:
437 mutex_unlock(&wl->mutex);
438 return count;
439}
440
441static const struct file_operations forced_ps_ops = {
442 .read = forced_ps_read,
443 .write = forced_ps_write,
444 .open = wl1271_open_file_generic,
445 .llseek = default_llseek,
446};
447
448static ssize_t split_scan_timeout_read(struct file *file, char __user *user_buf,
449 size_t count, loff_t *ppos)
450{
451 struct wl1271 *wl = file->private_data;
452
453 return wl1271_format_buffer(user_buf, count,
454 ppos, "%d\n",
455 wl->conf.scan.split_scan_timeout / 1000);
456}
457
458static ssize_t split_scan_timeout_write(struct file *file,
459 const char __user *user_buf,
460 size_t count, loff_t *ppos)
461{
462 struct wl1271 *wl = file->private_data;
463 unsigned long value;
464 int ret;
465
466 ret = kstrtoul_from_user(user_buf, count, 10, &value);
467 if (ret < 0) {
468 wl1271_warning("illegal value in split_scan_timeout");
469 return -EINVAL;
470 }
471
472 if (value == 0)
473 wl1271_info("split scan will be disabled");
474
475 mutex_lock(&wl->mutex);
476
477 wl->conf.scan.split_scan_timeout = value * 1000;
478
479 mutex_unlock(&wl->mutex);
480 return count;
481}
482
483static const struct file_operations split_scan_timeout_ops = {
484 .read = split_scan_timeout_read,
485 .write = split_scan_timeout_write,
486 .open = wl1271_open_file_generic,
487 .llseek = default_llseek,
488};
489
490static ssize_t driver_state_read(struct file *file, char __user *user_buf,
491 size_t count, loff_t *ppos)
492{
493 struct wl1271 *wl = file->private_data;
494 int res = 0;
495 ssize_t ret;
496 char *buf;
497
498#define DRIVER_STATE_BUF_LEN 1024
499
500 buf = kmalloc(DRIVER_STATE_BUF_LEN, GFP_KERNEL);
501 if (!buf)
502 return -ENOMEM;
503
504 mutex_lock(&wl->mutex);
505
506#define DRIVER_STATE_PRINT(x, fmt) \
507 (res += scnprintf(buf + res, DRIVER_STATE_BUF_LEN - res,\
508 #x " = " fmt "\n", wl->x))
509
510#define DRIVER_STATE_PRINT_LONG(x) DRIVER_STATE_PRINT(x, "%ld")
511#define DRIVER_STATE_PRINT_INT(x) DRIVER_STATE_PRINT(x, "%d")
512#define DRIVER_STATE_PRINT_STR(x) DRIVER_STATE_PRINT(x, "%s")
513#define DRIVER_STATE_PRINT_LHEX(x) DRIVER_STATE_PRINT(x, "0x%lx")
514#define DRIVER_STATE_PRINT_HEX(x) DRIVER_STATE_PRINT(x, "0x%x")
515
516 DRIVER_STATE_PRINT_INT(tx_blocks_available);
517 DRIVER_STATE_PRINT_INT(tx_allocated_blocks);
518 DRIVER_STATE_PRINT_INT(tx_allocated_pkts[0]);
519 DRIVER_STATE_PRINT_INT(tx_allocated_pkts[1]);
520 DRIVER_STATE_PRINT_INT(tx_allocated_pkts[2]);
521 DRIVER_STATE_PRINT_INT(tx_allocated_pkts[3]);
522 DRIVER_STATE_PRINT_INT(tx_frames_cnt);
523 DRIVER_STATE_PRINT_LHEX(tx_frames_map[0]);
524 DRIVER_STATE_PRINT_INT(tx_queue_count[0]);
525 DRIVER_STATE_PRINT_INT(tx_queue_count[1]);
526 DRIVER_STATE_PRINT_INT(tx_queue_count[2]);
527 DRIVER_STATE_PRINT_INT(tx_queue_count[3]);
528 DRIVER_STATE_PRINT_INT(tx_packets_count);
529 DRIVER_STATE_PRINT_INT(tx_results_count);
530 DRIVER_STATE_PRINT_LHEX(flags);
531 DRIVER_STATE_PRINT_INT(tx_blocks_freed);
532 DRIVER_STATE_PRINT_INT(rx_counter);
533 DRIVER_STATE_PRINT_INT(state);
534 DRIVER_STATE_PRINT_INT(channel);
535 DRIVER_STATE_PRINT_INT(band);
536 DRIVER_STATE_PRINT_INT(power_level);
537 DRIVER_STATE_PRINT_INT(sg_enabled);
538 DRIVER_STATE_PRINT_INT(enable_11a);
539 DRIVER_STATE_PRINT_INT(noise);
540 DRIVER_STATE_PRINT_HEX(ap_fw_ps_map);
541 DRIVER_STATE_PRINT_LHEX(ap_ps_map);
542 DRIVER_STATE_PRINT_HEX(quirks);
543 DRIVER_STATE_PRINT_HEX(irq);
544 DRIVER_STATE_PRINT_HEX(ref_clock);
545 DRIVER_STATE_PRINT_HEX(tcxo_clock);
546 DRIVER_STATE_PRINT_HEX(hw_pg_ver);
547 DRIVER_STATE_PRINT_HEX(platform_quirks);
548 DRIVER_STATE_PRINT_HEX(chip.id);
549 DRIVER_STATE_PRINT_STR(chip.fw_ver_str);
550 DRIVER_STATE_PRINT_INT(sched_scanning);
551
552#undef DRIVER_STATE_PRINT_INT
553#undef DRIVER_STATE_PRINT_LONG
554#undef DRIVER_STATE_PRINT_HEX
555#undef DRIVER_STATE_PRINT_LHEX
556#undef DRIVER_STATE_PRINT_STR
557#undef DRIVER_STATE_PRINT
558#undef DRIVER_STATE_BUF_LEN
559
560 mutex_unlock(&wl->mutex);
561
562 ret = simple_read_from_buffer(user_buf, count, ppos, buf, res);
563 kfree(buf);
564 return ret;
565}
566
567static const struct file_operations driver_state_ops = {
568 .read = driver_state_read,
569 .open = wl1271_open_file_generic,
570 .llseek = default_llseek,
571};
572
573static ssize_t vifs_state_read(struct file *file, char __user *user_buf,
574 size_t count, loff_t *ppos)
575{
576 struct wl1271 *wl = file->private_data;
577 struct wl12xx_vif *wlvif;
578 int ret, res = 0;
579 const int buf_size = 4096;
580 char *buf;
581 char tmp_buf[64];
582
583 buf = kzalloc(buf_size, GFP_KERNEL);
584 if (!buf)
585 return -ENOMEM;
586
587 mutex_lock(&wl->mutex);
588
589#define VIF_STATE_PRINT(x, fmt) \
590 (res += scnprintf(buf + res, buf_size - res, \
591 #x " = " fmt "\n", wlvif->x))
592
593#define VIF_STATE_PRINT_LONG(x) VIF_STATE_PRINT(x, "%ld")
594#define VIF_STATE_PRINT_INT(x) VIF_STATE_PRINT(x, "%d")
595#define VIF_STATE_PRINT_STR(x) VIF_STATE_PRINT(x, "%s")
596#define VIF_STATE_PRINT_LHEX(x) VIF_STATE_PRINT(x, "0x%lx")
597#define VIF_STATE_PRINT_LLHEX(x) VIF_STATE_PRINT(x, "0x%llx")
598#define VIF_STATE_PRINT_HEX(x) VIF_STATE_PRINT(x, "0x%x")
599
600#define VIF_STATE_PRINT_NSTR(x, len) \
601 do { \
602 memset(tmp_buf, 0, sizeof(tmp_buf)); \
603 memcpy(tmp_buf, wlvif->x, \
604 min_t(u8, len, sizeof(tmp_buf) - 1)); \
605 res += scnprintf(buf + res, buf_size - res, \
606 #x " = %s\n", tmp_buf); \
607 } while (0)
608
609 wl12xx_for_each_wlvif(wl, wlvif) {
610 VIF_STATE_PRINT_INT(role_id);
611 VIF_STATE_PRINT_INT(bss_type);
612 VIF_STATE_PRINT_LHEX(flags);
613 VIF_STATE_PRINT_INT(p2p);
614 VIF_STATE_PRINT_INT(dev_role_id);
615 VIF_STATE_PRINT_INT(dev_hlid);
616
617 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
618 wlvif->bss_type == BSS_TYPE_IBSS) {
619 VIF_STATE_PRINT_INT(sta.hlid);
620 VIF_STATE_PRINT_INT(sta.ba_rx_bitmap);
621 VIF_STATE_PRINT_INT(sta.basic_rate_idx);
622 VIF_STATE_PRINT_INT(sta.ap_rate_idx);
623 VIF_STATE_PRINT_INT(sta.p2p_rate_idx);
624 VIF_STATE_PRINT_INT(sta.qos);
625 } else {
626 VIF_STATE_PRINT_INT(ap.global_hlid);
627 VIF_STATE_PRINT_INT(ap.bcast_hlid);
628 VIF_STATE_PRINT_LHEX(ap.sta_hlid_map[0]);
629 VIF_STATE_PRINT_INT(ap.mgmt_rate_idx);
630 VIF_STATE_PRINT_INT(ap.bcast_rate_idx);
631 VIF_STATE_PRINT_INT(ap.ucast_rate_idx[0]);
632 VIF_STATE_PRINT_INT(ap.ucast_rate_idx[1]);
633 VIF_STATE_PRINT_INT(ap.ucast_rate_idx[2]);
634 VIF_STATE_PRINT_INT(ap.ucast_rate_idx[3]);
635 }
636 VIF_STATE_PRINT_INT(last_tx_hlid);
637 VIF_STATE_PRINT_LHEX(links_map[0]);
638 VIF_STATE_PRINT_NSTR(ssid, wlvif->ssid_len);
639 VIF_STATE_PRINT_INT(band);
640 VIF_STATE_PRINT_INT(channel);
641 VIF_STATE_PRINT_HEX(bitrate_masks[0]);
642 VIF_STATE_PRINT_HEX(bitrate_masks[1]);
643 VIF_STATE_PRINT_HEX(basic_rate_set);
644 VIF_STATE_PRINT_HEX(basic_rate);
645 VIF_STATE_PRINT_HEX(rate_set);
646 VIF_STATE_PRINT_INT(beacon_int);
647 VIF_STATE_PRINT_INT(default_key);
648 VIF_STATE_PRINT_INT(aid);
649 VIF_STATE_PRINT_INT(session_counter);
650 VIF_STATE_PRINT_INT(psm_entry_retry);
651 VIF_STATE_PRINT_INT(power_level);
652 VIF_STATE_PRINT_INT(rssi_thold);
653 VIF_STATE_PRINT_INT(last_rssi_event);
654 VIF_STATE_PRINT_INT(ba_support);
655 VIF_STATE_PRINT_INT(ba_allowed);
656 VIF_STATE_PRINT_INT(is_gem);
657 VIF_STATE_PRINT_LLHEX(tx_security_seq);
658 VIF_STATE_PRINT_INT(tx_security_last_seq_lsb);
659 }
660
661#undef VIF_STATE_PRINT_INT
662#undef VIF_STATE_PRINT_LONG
663#undef VIF_STATE_PRINT_HEX
664#undef VIF_STATE_PRINT_LHEX
665#undef VIF_STATE_PRINT_LLHEX
666#undef VIF_STATE_PRINT_STR
667#undef VIF_STATE_PRINT_NSTR
668#undef VIF_STATE_PRINT
669
670 mutex_unlock(&wl->mutex);
671
672 ret = simple_read_from_buffer(user_buf, count, ppos, buf, res);
673 kfree(buf);
674 return ret;
675}
676
677static const struct file_operations vifs_state_ops = {
678 .read = vifs_state_read,
679 .open = wl1271_open_file_generic,
680 .llseek = default_llseek,
681};
682
683static ssize_t dtim_interval_read(struct file *file, char __user *user_buf,
684 size_t count, loff_t *ppos)
685{
686 struct wl1271 *wl = file->private_data;
687 u8 value;
688
689 if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_DTIM ||
690 wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_DTIM)
691 value = wl->conf.conn.listen_interval;
692 else
693 value = 0;
694
695 return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
696}
697
698static ssize_t dtim_interval_write(struct file *file,
699 const char __user *user_buf,
700 size_t count, loff_t *ppos)
701{
702 struct wl1271 *wl = file->private_data;
703 unsigned long value;
704 int ret;
705
706 ret = kstrtoul_from_user(user_buf, count, 10, &value);
707 if (ret < 0) {
708 wl1271_warning("illegal value for dtim_interval");
709 return -EINVAL;
710 }
711
712 if (value < 1 || value > 10) {
713 wl1271_warning("dtim value is not in valid range");
714 return -ERANGE;
715 }
716
717 mutex_lock(&wl->mutex);
718
719 wl->conf.conn.listen_interval = value;
720 /* for some reason there are different event types for 1 and >1 */
721 if (value == 1)
722 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_DTIM;
723 else
724 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM;
725
726 /*
727 * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
728 * take effect on the next time we enter psm.
729 */
730 mutex_unlock(&wl->mutex);
731 return count;
732}
733
734static const struct file_operations dtim_interval_ops = {
735 .read = dtim_interval_read,
736 .write = dtim_interval_write,
737 .open = wl1271_open_file_generic,
738 .llseek = default_llseek,
739};
740
741
742
743static ssize_t suspend_dtim_interval_read(struct file *file,
744 char __user *user_buf,
745 size_t count, loff_t *ppos)
746{
747 struct wl1271 *wl = file->private_data;
748 u8 value;
749
750 if (wl->conf.conn.suspend_wake_up_event == CONF_WAKE_UP_EVENT_DTIM ||
751 wl->conf.conn.suspend_wake_up_event == CONF_WAKE_UP_EVENT_N_DTIM)
752 value = wl->conf.conn.suspend_listen_interval;
753 else
754 value = 0;
755
756 return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
757}
758
759static ssize_t suspend_dtim_interval_write(struct file *file,
760 const char __user *user_buf,
761 size_t count, loff_t *ppos)
762{
763 struct wl1271 *wl = file->private_data;
764 unsigned long value;
765 int ret;
766
767 ret = kstrtoul_from_user(user_buf, count, 10, &value);
768 if (ret < 0) {
769 wl1271_warning("illegal value for suspend_dtim_interval");
770 return -EINVAL;
771 }
772
773 if (value < 1 || value > 10) {
774 wl1271_warning("suspend_dtim value is not in valid range");
775 return -ERANGE;
776 }
777
778 mutex_lock(&wl->mutex);
779
780 wl->conf.conn.suspend_listen_interval = value;
781 /* for some reason there are different event types for 1 and >1 */
782 if (value == 1)
783 wl->conf.conn.suspend_wake_up_event = CONF_WAKE_UP_EVENT_DTIM;
784 else
785 wl->conf.conn.suspend_wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM;
786
787 mutex_unlock(&wl->mutex);
788 return count;
789}
790
791
792static const struct file_operations suspend_dtim_interval_ops = {
793 .read = suspend_dtim_interval_read,
794 .write = suspend_dtim_interval_write,
795 .open = wl1271_open_file_generic,
796 .llseek = default_llseek,
797};
798
799static ssize_t beacon_interval_read(struct file *file, char __user *user_buf,
800 size_t count, loff_t *ppos)
801{
802 struct wl1271 *wl = file->private_data;
803 u8 value;
804
805 if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_BEACON ||
806 wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_BEACONS)
807 value = wl->conf.conn.listen_interval;
808 else
809 value = 0;
810
811 return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
812}
813
814static ssize_t beacon_interval_write(struct file *file,
815 const char __user *user_buf,
816 size_t count, loff_t *ppos)
817{
818 struct wl1271 *wl = file->private_data;
819 unsigned long value;
820 int ret;
821
822 ret = kstrtoul_from_user(user_buf, count, 10, &value);
823 if (ret < 0) {
824 wl1271_warning("illegal value for beacon_interval");
825 return -EINVAL;
826 }
827
828 if (value < 1 || value > 255) {
829 wl1271_warning("beacon interval value is not in valid range");
830 return -ERANGE;
831 }
832
833 mutex_lock(&wl->mutex);
834
835 wl->conf.conn.listen_interval = value;
836 /* for some reason there are different event types for 1 and >1 */
837 if (value == 1)
838 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_BEACON;
839 else
840 wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_BEACONS;
841
842 /*
843 * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
844 * take effect on the next time we enter psm.
845 */
846 mutex_unlock(&wl->mutex);
847 return count;
848}
849
850static const struct file_operations beacon_interval_ops = {
851 .read = beacon_interval_read,
852 .write = beacon_interval_write,
853 .open = wl1271_open_file_generic,
854 .llseek = default_llseek,
855};
856
857static ssize_t rx_streaming_interval_write(struct file *file,
858 const char __user *user_buf,
859 size_t count, loff_t *ppos)
860{
861 struct wl1271 *wl = file->private_data;
862 struct wl12xx_vif *wlvif;
863 unsigned long value;
864 int ret;
865
866 ret = kstrtoul_from_user(user_buf, count, 10, &value);
867 if (ret < 0) {
868 wl1271_warning("illegal value in rx_streaming_interval!");
869 return -EINVAL;
870 }
871
872 /* valid values: 0, 10-100 */
873 if (value && (value < 10 || value > 100)) {
874 wl1271_warning("value is not in range!");
875 return -ERANGE;
876 }
877
878 mutex_lock(&wl->mutex);
879
880 wl->conf.rx_streaming.interval = value;
881
882 ret = wl1271_ps_elp_wakeup(wl);
883 if (ret < 0)
884 goto out;
885
886 wl12xx_for_each_wlvif_sta(wl, wlvif) {
887 wl1271_recalc_rx_streaming(wl, wlvif);
888 }
889
890 wl1271_ps_elp_sleep(wl);
891out:
892 mutex_unlock(&wl->mutex);
893 return count;
894}
895
896static ssize_t rx_streaming_interval_read(struct file *file,
897 char __user *userbuf,
898 size_t count, loff_t *ppos)
899{
900 struct wl1271 *wl = file->private_data;
901 return wl1271_format_buffer(userbuf, count, ppos,
902 "%d\n", wl->conf.rx_streaming.interval);
903}
904
905static const struct file_operations rx_streaming_interval_ops = {
906 .read = rx_streaming_interval_read,
907 .write = rx_streaming_interval_write,
908 .open = wl1271_open_file_generic,
909 .llseek = default_llseek,
910};
911
912static ssize_t rx_streaming_always_write(struct file *file,
913 const char __user *user_buf,
914 size_t count, loff_t *ppos)
915{
916 struct wl1271 *wl = file->private_data;
917 struct wl12xx_vif *wlvif;
918 unsigned long value;
919 int ret;
920
921 ret = kstrtoul_from_user(user_buf, count, 10, &value);
922 if (ret < 0) {
923 wl1271_warning("illegal value in rx_streaming_write!");
924 return -EINVAL;
925 }
926
927 /* valid values: 0, 10-100 */
928 if (!(value == 0 || value == 1)) {
929 wl1271_warning("value is not in valid!");
930 return -EINVAL;
931 }
932
933 mutex_lock(&wl->mutex);
934
935 wl->conf.rx_streaming.always = value;
936
937 ret = wl1271_ps_elp_wakeup(wl);
938 if (ret < 0)
939 goto out;
940
941 wl12xx_for_each_wlvif_sta(wl, wlvif) {
942 wl1271_recalc_rx_streaming(wl, wlvif);
943 }
944
945 wl1271_ps_elp_sleep(wl);
946out:
947 mutex_unlock(&wl->mutex);
948 return count;
949}
950
951static ssize_t rx_streaming_always_read(struct file *file,
952 char __user *userbuf,
953 size_t count, loff_t *ppos)
954{
955 struct wl1271 *wl = file->private_data;
956 return wl1271_format_buffer(userbuf, count, ppos,
957 "%d\n", wl->conf.rx_streaming.always);
958}
959
960static const struct file_operations rx_streaming_always_ops = {
961 .read = rx_streaming_always_read,
962 .write = rx_streaming_always_write,
963 .open = wl1271_open_file_generic,
964 .llseek = default_llseek,
965};
966
967static ssize_t beacon_filtering_write(struct file *file,
968 const char __user *user_buf,
969 size_t count, loff_t *ppos)
970{
971 struct wl1271 *wl = file->private_data;
972 struct wl12xx_vif *wlvif;
973 char buf[10];
974 size_t len;
975 unsigned long value;
976 int ret;
977
978 len = min(count, sizeof(buf) - 1);
979 if (copy_from_user(buf, user_buf, len))
980 return -EFAULT;
981 buf[len] = '\0';
982
983 ret = kstrtoul(buf, 0, &value);
984 if (ret < 0) {
985 wl1271_warning("illegal value for beacon_filtering!");
986 return -EINVAL;
987 }
988
989 mutex_lock(&wl->mutex);
990
991 ret = wl1271_ps_elp_wakeup(wl);
992 if (ret < 0)
993 goto out;
994
995 wl12xx_for_each_wlvif(wl, wlvif) {
996 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, !!value);
997 }
998
999 wl1271_ps_elp_sleep(wl);
1000out:
1001 mutex_unlock(&wl->mutex);
1002 return count;
1003}
1004
1005static const struct file_operations beacon_filtering_ops = {
1006 .write = beacon_filtering_write,
1007 .open = wl1271_open_file_generic,
1008 .llseek = default_llseek,
1009};
1010
1011static int wl1271_debugfs_add_files(struct wl1271 *wl,
1012 struct dentry *rootdir)
1013{
1014 int ret = 0;
1015 struct dentry *entry, *stats, *streaming;
1016
1017 stats = debugfs_create_dir("fw-statistics", rootdir);
1018 if (!stats || IS_ERR(stats)) {
1019 entry = stats;
1020 goto err;
1021 }
1022
1023 DEBUGFS_FWSTATS_ADD(tx, internal_desc_overflow);
1024
1025 DEBUGFS_FWSTATS_ADD(rx, out_of_mem);
1026 DEBUGFS_FWSTATS_ADD(rx, hdr_overflow);
1027 DEBUGFS_FWSTATS_ADD(rx, hw_stuck);
1028 DEBUGFS_FWSTATS_ADD(rx, dropped);
1029 DEBUGFS_FWSTATS_ADD(rx, fcs_err);
1030 DEBUGFS_FWSTATS_ADD(rx, xfr_hint_trig);
1031 DEBUGFS_FWSTATS_ADD(rx, path_reset);
1032 DEBUGFS_FWSTATS_ADD(rx, reset_counter);
1033
1034 DEBUGFS_FWSTATS_ADD(dma, rx_requested);
1035 DEBUGFS_FWSTATS_ADD(dma, rx_errors);
1036 DEBUGFS_FWSTATS_ADD(dma, tx_requested);
1037 DEBUGFS_FWSTATS_ADD(dma, tx_errors);
1038
1039 DEBUGFS_FWSTATS_ADD(isr, cmd_cmplt);
1040 DEBUGFS_FWSTATS_ADD(isr, fiqs);
1041 DEBUGFS_FWSTATS_ADD(isr, rx_headers);
1042 DEBUGFS_FWSTATS_ADD(isr, rx_mem_overflow);
1043 DEBUGFS_FWSTATS_ADD(isr, rx_rdys);
1044 DEBUGFS_FWSTATS_ADD(isr, irqs);
1045 DEBUGFS_FWSTATS_ADD(isr, tx_procs);
1046 DEBUGFS_FWSTATS_ADD(isr, decrypt_done);
1047 DEBUGFS_FWSTATS_ADD(isr, dma0_done);
1048 DEBUGFS_FWSTATS_ADD(isr, dma1_done);
1049 DEBUGFS_FWSTATS_ADD(isr, tx_exch_complete);
1050 DEBUGFS_FWSTATS_ADD(isr, commands);
1051 DEBUGFS_FWSTATS_ADD(isr, rx_procs);
1052 DEBUGFS_FWSTATS_ADD(isr, hw_pm_mode_changes);
1053 DEBUGFS_FWSTATS_ADD(isr, host_acknowledges);
1054 DEBUGFS_FWSTATS_ADD(isr, pci_pm);
1055 DEBUGFS_FWSTATS_ADD(isr, wakeups);
1056 DEBUGFS_FWSTATS_ADD(isr, low_rssi);
1057
1058 DEBUGFS_FWSTATS_ADD(wep, addr_key_count);
1059 DEBUGFS_FWSTATS_ADD(wep, default_key_count);
1060 /* skipping wep.reserved */
1061 DEBUGFS_FWSTATS_ADD(wep, key_not_found);
1062 DEBUGFS_FWSTATS_ADD(wep, decrypt_fail);
1063 DEBUGFS_FWSTATS_ADD(wep, packets);
1064 DEBUGFS_FWSTATS_ADD(wep, interrupt);
1065
1066 DEBUGFS_FWSTATS_ADD(pwr, ps_enter);
1067 DEBUGFS_FWSTATS_ADD(pwr, elp_enter);
1068 DEBUGFS_FWSTATS_ADD(pwr, missing_bcns);
1069 DEBUGFS_FWSTATS_ADD(pwr, wake_on_host);
1070 DEBUGFS_FWSTATS_ADD(pwr, wake_on_timer_exp);
1071 DEBUGFS_FWSTATS_ADD(pwr, tx_with_ps);
1072 DEBUGFS_FWSTATS_ADD(pwr, tx_without_ps);
1073 DEBUGFS_FWSTATS_ADD(pwr, rcvd_beacons);
1074 DEBUGFS_FWSTATS_ADD(pwr, power_save_off);
1075 DEBUGFS_FWSTATS_ADD(pwr, enable_ps);
1076 DEBUGFS_FWSTATS_ADD(pwr, disable_ps);
1077 DEBUGFS_FWSTATS_ADD(pwr, fix_tsf_ps);
1078 /* skipping cont_miss_bcns_spread for now */
1079 DEBUGFS_FWSTATS_ADD(pwr, rcvd_awake_beacons);
1080
1081 DEBUGFS_FWSTATS_ADD(mic, rx_pkts);
1082 DEBUGFS_FWSTATS_ADD(mic, calc_failure);
1083
1084 DEBUGFS_FWSTATS_ADD(aes, encrypt_fail);
1085 DEBUGFS_FWSTATS_ADD(aes, decrypt_fail);
1086 DEBUGFS_FWSTATS_ADD(aes, encrypt_packets);
1087 DEBUGFS_FWSTATS_ADD(aes, decrypt_packets);
1088 DEBUGFS_FWSTATS_ADD(aes, encrypt_interrupt);
1089 DEBUGFS_FWSTATS_ADD(aes, decrypt_interrupt);
1090
1091 DEBUGFS_FWSTATS_ADD(event, heart_beat);
1092 DEBUGFS_FWSTATS_ADD(event, calibration);
1093 DEBUGFS_FWSTATS_ADD(event, rx_mismatch);
1094 DEBUGFS_FWSTATS_ADD(event, rx_mem_empty);
1095 DEBUGFS_FWSTATS_ADD(event, rx_pool);
1096 DEBUGFS_FWSTATS_ADD(event, oom_late);
1097 DEBUGFS_FWSTATS_ADD(event, phy_transmit_error);
1098 DEBUGFS_FWSTATS_ADD(event, tx_stuck);
1099
1100 DEBUGFS_FWSTATS_ADD(ps, pspoll_timeouts);
1101 DEBUGFS_FWSTATS_ADD(ps, upsd_timeouts);
1102 DEBUGFS_FWSTATS_ADD(ps, upsd_max_sptime);
1103 DEBUGFS_FWSTATS_ADD(ps, upsd_max_apturn);
1104 DEBUGFS_FWSTATS_ADD(ps, pspoll_max_apturn);
1105 DEBUGFS_FWSTATS_ADD(ps, pspoll_utilization);
1106 DEBUGFS_FWSTATS_ADD(ps, upsd_utilization);
1107
1108 DEBUGFS_FWSTATS_ADD(rxpipe, rx_prep_beacon_drop);
1109 DEBUGFS_FWSTATS_ADD(rxpipe, descr_host_int_trig_rx_data);
1110 DEBUGFS_FWSTATS_ADD(rxpipe, beacon_buffer_thres_host_int_trig_rx_data);
1111 DEBUGFS_FWSTATS_ADD(rxpipe, missed_beacon_host_int_trig_rx_data);
1112 DEBUGFS_FWSTATS_ADD(rxpipe, tx_xfr_host_int_trig_rx_data);
1113
1114 DEBUGFS_ADD(tx_queue_len, rootdir);
1115 DEBUGFS_ADD(retry_count, rootdir);
1116 DEBUGFS_ADD(excessive_retries, rootdir);
1117
1118 DEBUGFS_ADD(gpio_power, rootdir);
1119 DEBUGFS_ADD(start_recovery, rootdir);
1120 DEBUGFS_ADD(driver_state, rootdir);
1121 DEBUGFS_ADD(vifs_state, rootdir);
1122 DEBUGFS_ADD(dtim_interval, rootdir);
1123 DEBUGFS_ADD(suspend_dtim_interval, rootdir);
1124 DEBUGFS_ADD(beacon_interval, rootdir);
1125 DEBUGFS_ADD(beacon_filtering, rootdir);
1126 DEBUGFS_ADD(dynamic_ps_timeout, rootdir);
1127 DEBUGFS_ADD(forced_ps, rootdir);
1128 DEBUGFS_ADD(split_scan_timeout, rootdir);
1129
1130 streaming = debugfs_create_dir("rx_streaming", rootdir);
1131 if (!streaming || IS_ERR(streaming))
1132 goto err;
1133
1134 DEBUGFS_ADD_PREFIX(rx_streaming, interval, streaming);
1135 DEBUGFS_ADD_PREFIX(rx_streaming, always, streaming);
1136
1137
1138 return 0;
1139
1140err:
1141 if (IS_ERR(entry))
1142 ret = PTR_ERR(entry);
1143 else
1144 ret = -ENOMEM;
1145
1146 return ret;
1147}
1148
1149void wl1271_debugfs_reset(struct wl1271 *wl)
1150{
1151 if (!wl->stats.fw_stats)
1152 return;
1153
1154 memset(wl->stats.fw_stats, 0, sizeof(*wl->stats.fw_stats));
1155 wl->stats.retry_count = 0;
1156 wl->stats.excessive_retries = 0;
1157}
1158
1159int wl1271_debugfs_init(struct wl1271 *wl)
1160{
1161 int ret;
1162 struct dentry *rootdir;
1163
1164 rootdir = debugfs_create_dir(KBUILD_MODNAME,
1165 wl->hw->wiphy->debugfsdir);
1166
1167 if (IS_ERR(rootdir)) {
1168 ret = PTR_ERR(rootdir);
1169 goto err;
1170 }
1171
1172 wl->stats.fw_stats = kzalloc(sizeof(*wl->stats.fw_stats),
1173 GFP_KERNEL);
1174
1175 if (!wl->stats.fw_stats) {
1176 ret = -ENOMEM;
1177 goto err_fw;
1178 }
1179
1180 wl->stats.fw_stats_update = jiffies;
1181
1182 ret = wl1271_debugfs_add_files(wl, rootdir);
1183
1184 if (ret < 0)
1185 goto err_file;
1186
1187 return 0;
1188
1189err_file:
1190 kfree(wl->stats.fw_stats);
1191 wl->stats.fw_stats = NULL;
1192
1193err_fw:
1194 debugfs_remove_recursive(rootdir);
1195
1196err:
1197 return ret;
1198}
1199
1200void wl1271_debugfs_exit(struct wl1271 *wl)
1201{
1202 kfree(wl->stats.fw_stats);
1203 wl->stats.fw_stats = NULL;
1204}
diff --git a/drivers/net/wireless/ti/wlcore/debugfs.h b/drivers/net/wireless/ti/wlcore/debugfs.h
new file mode 100644
index 000000000000..a8d3aef011ff
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/debugfs.h
@@ -0,0 +1,33 @@
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#ifndef __DEBUGFS_H__
25#define __DEBUGFS_H__
26
27#include "wlcore.h"
28
29int wl1271_debugfs_init(struct wl1271 *wl);
30void wl1271_debugfs_exit(struct wl1271 *wl);
31void wl1271_debugfs_reset(struct wl1271 *wl);
32
33#endif /* WL1271_DEBUGFS_H */
diff --git a/drivers/net/wireless/ti/wlcore/event.c b/drivers/net/wireless/ti/wlcore/event.c
new file mode 100644
index 000000000000..292632ddf890
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/event.c
@@ -0,0 +1,306 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2008-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 "wlcore.h"
25#include "debug.h"
26#include "io.h"
27#include "event.h"
28#include "ps.h"
29#include "scan.h"
30#include "wl12xx_80211.h"
31
32static void wl1271_event_rssi_trigger(struct wl1271 *wl,
33 struct wl12xx_vif *wlvif,
34 struct event_mailbox *mbox)
35{
36 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
37 enum nl80211_cqm_rssi_threshold_event event;
38 s8 metric = mbox->rssi_snr_trigger_metric[0];
39
40 wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric);
41
42 if (metric <= wlvif->rssi_thold)
43 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
44 else
45 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
46
47 if (event != wlvif->last_rssi_event)
48 ieee80211_cqm_rssi_notify(vif, event, GFP_KERNEL);
49 wlvif->last_rssi_event = event;
50}
51
52static void wl1271_stop_ba_event(struct wl1271 *wl, struct wl12xx_vif *wlvif)
53{
54 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
55
56 if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
57 if (!wlvif->sta.ba_rx_bitmap)
58 return;
59 ieee80211_stop_rx_ba_session(vif, wlvif->sta.ba_rx_bitmap,
60 vif->bss_conf.bssid);
61 } else {
62 u8 hlid;
63 struct wl1271_link *lnk;
64 for_each_set_bit(hlid, wlvif->ap.sta_hlid_map,
65 WL12XX_MAX_LINKS) {
66 lnk = &wl->links[hlid];
67 if (!lnk->ba_bitmap)
68 continue;
69
70 ieee80211_stop_rx_ba_session(vif,
71 lnk->ba_bitmap,
72 lnk->addr);
73 }
74 }
75}
76
77static void wl12xx_event_soft_gemini_sense(struct wl1271 *wl,
78 u8 enable)
79{
80 struct wl12xx_vif *wlvif;
81
82 if (enable) {
83 set_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
84 } else {
85 clear_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
86 wl12xx_for_each_wlvif_sta(wl, wlvif) {
87 wl1271_recalc_rx_streaming(wl, wlvif);
88 }
89 }
90
91}
92
93static void wl1271_event_mbox_dump(struct event_mailbox *mbox)
94{
95 wl1271_debug(DEBUG_EVENT, "MBOX DUMP:");
96 wl1271_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector);
97 wl1271_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask);
98}
99
100static int wl1271_event_process(struct wl1271 *wl)
101{
102 struct event_mailbox *mbox = wl->mbox;
103 struct ieee80211_vif *vif;
104 struct wl12xx_vif *wlvif;
105 u32 vector;
106 bool beacon_loss = false;
107 bool disconnect_sta = false;
108 unsigned long sta_bitmap = 0;
109
110 wl1271_event_mbox_dump(mbox);
111
112 vector = le32_to_cpu(mbox->events_vector);
113 vector &= ~(le32_to_cpu(mbox->events_mask));
114 wl1271_debug(DEBUG_EVENT, "vector: 0x%x", vector);
115
116 if (vector & SCAN_COMPLETE_EVENT_ID) {
117 wl1271_debug(DEBUG_EVENT, "status: 0x%x",
118 mbox->scheduled_scan_status);
119
120 wl1271_scan_stm(wl, wl->scan_vif);
121 }
122
123 if (vector & PERIODIC_SCAN_REPORT_EVENT_ID) {
124 wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_REPORT_EVENT "
125 "(status 0x%0x)", mbox->scheduled_scan_status);
126
127 wl1271_scan_sched_scan_results(wl);
128 }
129
130 if (vector & PERIODIC_SCAN_COMPLETE_EVENT_ID) {
131 wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_COMPLETE_EVENT "
132 "(status 0x%0x)", mbox->scheduled_scan_status);
133 if (wl->sched_scanning) {
134 ieee80211_sched_scan_stopped(wl->hw);
135 wl->sched_scanning = false;
136 }
137 }
138
139 if (vector & SOFT_GEMINI_SENSE_EVENT_ID)
140 wl12xx_event_soft_gemini_sense(wl,
141 mbox->soft_gemini_sense_info);
142
143 /*
144 * The BSS_LOSE_EVENT_ID is only needed while psm (and hence beacon
145 * filtering) is enabled. Without PSM, the stack will receive all
146 * beacons and can detect beacon loss by itself.
147 *
148 * As there's possibility that the driver disables PSM before receiving
149 * BSS_LOSE_EVENT, beacon loss has to be reported to the stack.
150 *
151 */
152 if (vector & BSS_LOSE_EVENT_ID) {
153 /* TODO: check for multi-role */
154 wl1271_info("Beacon loss detected.");
155
156 /* indicate to the stack, that beacons have been lost */
157 beacon_loss = true;
158 }
159
160 if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) {
161 /* TODO: check actual multi-role support */
162 wl1271_debug(DEBUG_EVENT, "RSSI_SNR_TRIGGER_0_EVENT");
163 wl12xx_for_each_wlvif_sta(wl, wlvif) {
164 wl1271_event_rssi_trigger(wl, wlvif, mbox);
165 }
166 }
167
168 if (vector & BA_SESSION_RX_CONSTRAINT_EVENT_ID) {
169 u8 role_id = mbox->role_id;
170 wl1271_debug(DEBUG_EVENT, "BA_SESSION_RX_CONSTRAINT_EVENT_ID. "
171 "ba_allowed = 0x%x, role_id=%d",
172 mbox->rx_ba_allowed, role_id);
173
174 wl12xx_for_each_wlvif(wl, wlvif) {
175 if (role_id != 0xff && role_id != wlvif->role_id)
176 continue;
177
178 wlvif->ba_allowed = !!mbox->rx_ba_allowed;
179 if (!wlvif->ba_allowed)
180 wl1271_stop_ba_event(wl, wlvif);
181 }
182 }
183
184 if (vector & CHANNEL_SWITCH_COMPLETE_EVENT_ID) {
185 wl1271_debug(DEBUG_EVENT, "CHANNEL_SWITCH_COMPLETE_EVENT_ID. "
186 "status = 0x%x",
187 mbox->channel_switch_status);
188 /*
189 * That event uses for two cases:
190 * 1) channel switch complete with status=0
191 * 2) channel switch failed status=1
192 */
193
194 /* TODO: configure only the relevant vif */
195 wl12xx_for_each_wlvif_sta(wl, wlvif) {
196 bool success;
197
198 if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS,
199 &wlvif->flags))
200 continue;
201
202 success = mbox->channel_switch_status ? false : true;
203 vif = wl12xx_wlvif_to_vif(wlvif);
204
205 ieee80211_chswitch_done(vif, success);
206 }
207 }
208
209 if ((vector & DUMMY_PACKET_EVENT_ID)) {
210 wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID");
211 wl1271_tx_dummy_packet(wl);
212 }
213
214 /*
215 * "TX retries exceeded" has a different meaning according to mode.
216 * In AP mode the offending station is disconnected.
217 */
218 if (vector & MAX_TX_RETRY_EVENT_ID) {
219 wl1271_debug(DEBUG_EVENT, "MAX_TX_RETRY_EVENT_ID");
220 sta_bitmap |= le16_to_cpu(mbox->sta_tx_retry_exceeded);
221 disconnect_sta = true;
222 }
223
224 if (vector & INACTIVE_STA_EVENT_ID) {
225 wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID");
226 sta_bitmap |= le16_to_cpu(mbox->sta_aging_status);
227 disconnect_sta = true;
228 }
229
230 if (disconnect_sta) {
231 u32 num_packets = wl->conf.tx.max_tx_retries;
232 struct ieee80211_sta *sta;
233 const u8 *addr;
234 int h;
235
236 for_each_set_bit(h, &sta_bitmap, WL12XX_MAX_LINKS) {
237 bool found = false;
238 /* find the ap vif connected to this sta */
239 wl12xx_for_each_wlvif_ap(wl, wlvif) {
240 if (!test_bit(h, wlvif->ap.sta_hlid_map))
241 continue;
242 found = true;
243 break;
244 }
245 if (!found)
246 continue;
247
248 vif = wl12xx_wlvif_to_vif(wlvif);
249 addr = wl->links[h].addr;
250
251 rcu_read_lock();
252 sta = ieee80211_find_sta(vif, addr);
253 if (sta) {
254 wl1271_debug(DEBUG_EVENT, "remove sta %d", h);
255 ieee80211_report_low_ack(sta, num_packets);
256 }
257 rcu_read_unlock();
258 }
259 }
260
261 if (beacon_loss)
262 wl12xx_for_each_wlvif_sta(wl, wlvif) {
263 vif = wl12xx_wlvif_to_vif(wlvif);
264 ieee80211_connection_loss(vif);
265 }
266
267 return 0;
268}
269
270int wl1271_event_unmask(struct wl1271 *wl)
271{
272 int ret;
273
274 ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask));
275 if (ret < 0)
276 return ret;
277
278 return 0;
279}
280
281int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num)
282{
283 int ret;
284
285 wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
286
287 if (mbox_num > 1)
288 return -EINVAL;
289
290 /* first we read the mbox descriptor */
291 wl1271_read(wl, wl->mbox_ptr[mbox_num], wl->mbox,
292 sizeof(*wl->mbox), false);
293
294 /* process the descriptor */
295 ret = wl1271_event_process(wl);
296 if (ret < 0)
297 return ret;
298
299 /*
300 * TODO: we just need this because one bit is in a different
301 * place. Is there any better way?
302 */
303 wl->ops->ack_event(wl);
304
305 return 0;
306}
diff --git a/drivers/net/wireless/ti/wlcore/event.h b/drivers/net/wireless/ti/wlcore/event.h
new file mode 100644
index 000000000000..8adf18d6c58f
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/event.h
@@ -0,0 +1,140 @@
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 __EVENT_H__
26#define __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 RSSI_SNR_TRIGGER_0_EVENT_ID = BIT(0),
42 RSSI_SNR_TRIGGER_1_EVENT_ID = BIT(1),
43 RSSI_SNR_TRIGGER_2_EVENT_ID = BIT(2),
44 RSSI_SNR_TRIGGER_3_EVENT_ID = BIT(3),
45 RSSI_SNR_TRIGGER_4_EVENT_ID = BIT(4),
46 RSSI_SNR_TRIGGER_5_EVENT_ID = BIT(5),
47 RSSI_SNR_TRIGGER_6_EVENT_ID = BIT(6),
48 RSSI_SNR_TRIGGER_7_EVENT_ID = BIT(7),
49 MEASUREMENT_START_EVENT_ID = BIT(8),
50 MEASUREMENT_COMPLETE_EVENT_ID = BIT(9),
51 SCAN_COMPLETE_EVENT_ID = BIT(10),
52 WFD_DISCOVERY_COMPLETE_EVENT_ID = BIT(11),
53 AP_DISCOVERY_COMPLETE_EVENT_ID = BIT(12),
54 RESERVED1 = BIT(13),
55 PSPOLL_DELIVERY_FAILURE_EVENT_ID = BIT(14),
56 ROLE_STOP_COMPLETE_EVENT_ID = BIT(15),
57 RADAR_DETECTED_EVENT_ID = BIT(16),
58 CHANNEL_SWITCH_COMPLETE_EVENT_ID = BIT(17),
59 BSS_LOSE_EVENT_ID = BIT(18),
60 REGAINED_BSS_EVENT_ID = BIT(19),
61 MAX_TX_RETRY_EVENT_ID = BIT(20),
62 DUMMY_PACKET_EVENT_ID = BIT(21),
63 SOFT_GEMINI_SENSE_EVENT_ID = BIT(22),
64 CHANGE_AUTO_MODE_TIMEOUT_EVENT_ID = BIT(23),
65 SOFT_GEMINI_AVALANCHE_EVENT_ID = BIT(24),
66 PLT_RX_CALIBRATION_COMPLETE_EVENT_ID = BIT(25),
67 INACTIVE_STA_EVENT_ID = BIT(26),
68 PEER_REMOVE_COMPLETE_EVENT_ID = BIT(27),
69 PERIODIC_SCAN_COMPLETE_EVENT_ID = BIT(28),
70 PERIODIC_SCAN_REPORT_EVENT_ID = BIT(29),
71 BA_SESSION_RX_CONSTRAINT_EVENT_ID = BIT(30),
72 REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID = BIT(31),
73 EVENT_MBOX_ALL_EVENT_ID = 0x7fffffff,
74};
75
76enum {
77 EVENT_ENTER_POWER_SAVE_FAIL = 0,
78 EVENT_ENTER_POWER_SAVE_SUCCESS,
79};
80
81#define NUM_OF_RSSI_SNR_TRIGGERS 8
82
83struct event_mailbox {
84 __le32 events_vector;
85 __le32 events_mask;
86 __le32 reserved_1;
87 __le32 reserved_2;
88
89 u8 number_of_scan_results;
90 u8 scan_tag;
91 u8 completed_scan_status;
92 u8 reserved_3;
93
94 u8 soft_gemini_sense_info;
95 u8 soft_gemini_protective_info;
96 s8 rssi_snr_trigger_metric[NUM_OF_RSSI_SNR_TRIGGERS];
97 u8 change_auto_mode_timeout;
98 u8 scheduled_scan_status;
99 u8 reserved4;
100 /* tuned channel (roc) */
101 u8 roc_channel;
102
103 __le16 hlid_removed_bitmap;
104
105 /* bitmap of aged stations (by HLID) */
106 __le16 sta_aging_status;
107
108 /* bitmap of stations (by HLID) which exceeded max tx retries */
109 __le16 sta_tx_retry_exceeded;
110
111 /* discovery completed results */
112 u8 discovery_tag;
113 u8 number_of_preq_results;
114 u8 number_of_prsp_results;
115 u8 reserved_5;
116
117 /* rx ba constraint */
118 u8 role_id; /* 0xFF means any role. */
119 u8 rx_ba_allowed;
120 u8 reserved_6[2];
121
122 /* Channel switch results */
123
124 u8 channel_switch_role_id;
125 u8 channel_switch_status;
126 u8 reserved_7[2];
127
128 u8 ps_poll_delivery_failure_role_ids;
129 u8 stopped_role_ids;
130 u8 started_role_ids;
131
132 u8 reserved_8[9];
133} __packed;
134
135struct wl1271;
136
137int wl1271_event_unmask(struct wl1271 *wl);
138int wl1271_event_handle(struct wl1271 *wl, u8 mbox);
139
140#endif
diff --git a/drivers/net/wireless/ti/wlcore/hw_ops.h b/drivers/net/wireless/ti/wlcore/hw_ops.h
new file mode 100644
index 000000000000..9384b4d56c24
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/hw_ops.h
@@ -0,0 +1,122 @@
1/*
2 * This file is part of wlcore
3 *
4 * Copyright (C) 2011 Texas Instruments Inc.
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
22#ifndef __WLCORE_HW_OPS_H__
23#define __WLCORE_HW_OPS_H__
24
25#include "wlcore.h"
26#include "rx.h"
27
28static inline u32
29wlcore_hw_calc_tx_blocks(struct wl1271 *wl, u32 len, u32 spare_blks)
30{
31 if (!wl->ops->calc_tx_blocks)
32 BUG_ON(1);
33
34 return wl->ops->calc_tx_blocks(wl, len, spare_blks);
35}
36
37static inline void
38wlcore_hw_set_tx_desc_blocks(struct wl1271 *wl, struct wl1271_tx_hw_descr *desc,
39 u32 blks, u32 spare_blks)
40{
41 if (!wl->ops->set_tx_desc_blocks)
42 BUG_ON(1);
43
44 return wl->ops->set_tx_desc_blocks(wl, desc, blks, spare_blks);
45}
46
47static inline void
48wlcore_hw_set_tx_desc_data_len(struct wl1271 *wl,
49 struct wl1271_tx_hw_descr *desc,
50 struct sk_buff *skb)
51{
52 if (!wl->ops->set_tx_desc_data_len)
53 BUG_ON(1);
54
55 wl->ops->set_tx_desc_data_len(wl, desc, skb);
56}
57
58static inline enum wl_rx_buf_align
59wlcore_hw_get_rx_buf_align(struct wl1271 *wl, u32 rx_desc)
60{
61
62 if (!wl->ops->get_rx_buf_align)
63 BUG_ON(1);
64
65 return wl->ops->get_rx_buf_align(wl, rx_desc);
66}
67
68static inline void
69wlcore_hw_prepare_read(struct wl1271 *wl, u32 rx_desc, u32 len)
70{
71 if (wl->ops->prepare_read)
72 wl->ops->prepare_read(wl, rx_desc, len);
73}
74
75static inline u32
76wlcore_hw_get_rx_packet_len(struct wl1271 *wl, void *rx_data, u32 data_len)
77{
78 if (!wl->ops->get_rx_packet_len)
79 BUG_ON(1);
80
81 return wl->ops->get_rx_packet_len(wl, rx_data, data_len);
82}
83
84static inline void wlcore_hw_tx_delayed_compl(struct wl1271 *wl)
85{
86 if (wl->ops->tx_delayed_compl)
87 wl->ops->tx_delayed_compl(wl);
88}
89
90static inline void wlcore_hw_tx_immediate_compl(struct wl1271 *wl)
91{
92 if (wl->ops->tx_immediate_compl)
93 wl->ops->tx_immediate_compl(wl);
94}
95
96static inline int
97wlcore_hw_init_vif(struct wl1271 *wl, struct wl12xx_vif *wlvif)
98{
99 if (wl->ops->init_vif)
100 return wl->ops->init_vif(wl, wlvif);
101
102 return 0;
103}
104
105static inline u32
106wlcore_hw_sta_get_ap_rate_mask(struct wl1271 *wl, struct wl12xx_vif *wlvif)
107{
108 if (!wl->ops->sta_get_ap_rate_mask)
109 BUG_ON(1);
110
111 return wl->ops->sta_get_ap_rate_mask(wl, wlvif);
112}
113
114static inline int wlcore_identify_fw(struct wl1271 *wl)
115{
116 if (wl->ops->identify_fw)
117 return wl->ops->identify_fw(wl);
118
119 return 0;
120}
121
122#endif
diff --git a/drivers/net/wireless/ti/wlcore/ini.h b/drivers/net/wireless/ti/wlcore/ini.h
new file mode 100644
index 000000000000..4cf9ecc56212
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/ini.h
@@ -0,0 +1,220 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 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#ifndef __INI_H__
25#define __INI_H__
26
27#define GENERAL_SETTINGS_DRPW_LPD 0xc0
28#define SCRATCH_ENABLE_LPD BIT(25)
29
30#define WL1271_INI_MAX_SMART_REFLEX_PARAM 16
31
32struct wl1271_ini_general_params {
33 u8 ref_clock;
34 u8 settling_time;
35 u8 clk_valid_on_wakeup;
36 u8 dc2dc_mode;
37 u8 dual_mode_select;
38 u8 tx_bip_fem_auto_detect;
39 u8 tx_bip_fem_manufacturer;
40 u8 general_settings;
41 u8 sr_state;
42 u8 srf1[WL1271_INI_MAX_SMART_REFLEX_PARAM];
43 u8 srf2[WL1271_INI_MAX_SMART_REFLEX_PARAM];
44 u8 srf3[WL1271_INI_MAX_SMART_REFLEX_PARAM];
45} __packed;
46
47#define WL128X_INI_MAX_SETTINGS_PARAM 4
48
49struct wl128x_ini_general_params {
50 u8 ref_clock;
51 u8 settling_time;
52 u8 clk_valid_on_wakeup;
53 u8 tcxo_ref_clock;
54 u8 tcxo_settling_time;
55 u8 tcxo_valid_on_wakeup;
56 u8 tcxo_ldo_voltage;
57 u8 xtal_itrim_val;
58 u8 platform_conf;
59 u8 dual_mode_select;
60 u8 tx_bip_fem_auto_detect;
61 u8 tx_bip_fem_manufacturer;
62 u8 general_settings[WL128X_INI_MAX_SETTINGS_PARAM];
63 u8 sr_state;
64 u8 srf1[WL1271_INI_MAX_SMART_REFLEX_PARAM];
65 u8 srf2[WL1271_INI_MAX_SMART_REFLEX_PARAM];
66 u8 srf3[WL1271_INI_MAX_SMART_REFLEX_PARAM];
67} __packed;
68
69#define WL1271_INI_RSSI_PROCESS_COMPENS_SIZE 15
70
71struct wl1271_ini_band_params_2 {
72 u8 rx_trace_insertion_loss;
73 u8 tx_trace_loss;
74 u8 rx_rssi_process_compens[WL1271_INI_RSSI_PROCESS_COMPENS_SIZE];
75} __packed;
76
77#define WL1271_INI_CHANNEL_COUNT_2 14
78
79struct wl128x_ini_band_params_2 {
80 u8 rx_trace_insertion_loss;
81 u8 tx_trace_loss[WL1271_INI_CHANNEL_COUNT_2];
82 u8 rx_rssi_process_compens[WL1271_INI_RSSI_PROCESS_COMPENS_SIZE];
83} __packed;
84
85#define WL1271_INI_RATE_GROUP_COUNT 6
86
87struct wl1271_ini_fem_params_2 {
88 __le16 tx_bip_ref_pd_voltage;
89 u8 tx_bip_ref_power;
90 u8 tx_bip_ref_offset;
91 u8 tx_per_rate_pwr_limits_normal[WL1271_INI_RATE_GROUP_COUNT];
92 u8 tx_per_rate_pwr_limits_degraded[WL1271_INI_RATE_GROUP_COUNT];
93 u8 tx_per_rate_pwr_limits_extreme[WL1271_INI_RATE_GROUP_COUNT];
94 u8 tx_per_chan_pwr_limits_11b[WL1271_INI_CHANNEL_COUNT_2];
95 u8 tx_per_chan_pwr_limits_ofdm[WL1271_INI_CHANNEL_COUNT_2];
96 u8 tx_pd_vs_rate_offsets[WL1271_INI_RATE_GROUP_COUNT];
97 u8 tx_ibias[WL1271_INI_RATE_GROUP_COUNT];
98 u8 rx_fem_insertion_loss;
99 u8 degraded_low_to_normal_thr;
100 u8 normal_to_degraded_high_thr;
101} __packed;
102
103#define WL128X_INI_RATE_GROUP_COUNT 7
104/* low and high temperatures */
105#define WL128X_INI_PD_VS_TEMPERATURE_RANGES 2
106
107struct wl128x_ini_fem_params_2 {
108 __le16 tx_bip_ref_pd_voltage;
109 u8 tx_bip_ref_power;
110 u8 tx_bip_ref_offset;
111 u8 tx_per_rate_pwr_limits_normal[WL128X_INI_RATE_GROUP_COUNT];
112 u8 tx_per_rate_pwr_limits_degraded[WL128X_INI_RATE_GROUP_COUNT];
113 u8 tx_per_rate_pwr_limits_extreme[WL128X_INI_RATE_GROUP_COUNT];
114 u8 tx_per_chan_pwr_limits_11b[WL1271_INI_CHANNEL_COUNT_2];
115 u8 tx_per_chan_pwr_limits_ofdm[WL1271_INI_CHANNEL_COUNT_2];
116 u8 tx_pd_vs_rate_offsets[WL128X_INI_RATE_GROUP_COUNT];
117 u8 tx_ibias[WL128X_INI_RATE_GROUP_COUNT + 1];
118 u8 tx_pd_vs_chan_offsets[WL1271_INI_CHANNEL_COUNT_2];
119 u8 tx_pd_vs_temperature[WL128X_INI_PD_VS_TEMPERATURE_RANGES];
120 u8 rx_fem_insertion_loss;
121 u8 degraded_low_to_normal_thr;
122 u8 normal_to_degraded_high_thr;
123} __packed;
124
125#define WL1271_INI_CHANNEL_COUNT_5 35
126#define WL1271_INI_SUB_BAND_COUNT_5 7
127
128struct wl1271_ini_band_params_5 {
129 u8 rx_trace_insertion_loss[WL1271_INI_SUB_BAND_COUNT_5];
130 u8 tx_trace_loss[WL1271_INI_SUB_BAND_COUNT_5];
131 u8 rx_rssi_process_compens[WL1271_INI_RSSI_PROCESS_COMPENS_SIZE];
132} __packed;
133
134struct wl128x_ini_band_params_5 {
135 u8 rx_trace_insertion_loss[WL1271_INI_SUB_BAND_COUNT_5];
136 u8 tx_trace_loss[WL1271_INI_CHANNEL_COUNT_5];
137 u8 rx_rssi_process_compens[WL1271_INI_RSSI_PROCESS_COMPENS_SIZE];
138} __packed;
139
140struct wl1271_ini_fem_params_5 {
141 __le16 tx_bip_ref_pd_voltage[WL1271_INI_SUB_BAND_COUNT_5];
142 u8 tx_bip_ref_power[WL1271_INI_SUB_BAND_COUNT_5];
143 u8 tx_bip_ref_offset[WL1271_INI_SUB_BAND_COUNT_5];
144 u8 tx_per_rate_pwr_limits_normal[WL1271_INI_RATE_GROUP_COUNT];
145 u8 tx_per_rate_pwr_limits_degraded[WL1271_INI_RATE_GROUP_COUNT];
146 u8 tx_per_rate_pwr_limits_extreme[WL1271_INI_RATE_GROUP_COUNT];
147 u8 tx_per_chan_pwr_limits_ofdm[WL1271_INI_CHANNEL_COUNT_5];
148 u8 tx_pd_vs_rate_offsets[WL1271_INI_RATE_GROUP_COUNT];
149 u8 tx_ibias[WL1271_INI_RATE_GROUP_COUNT];
150 u8 rx_fem_insertion_loss[WL1271_INI_SUB_BAND_COUNT_5];
151 u8 degraded_low_to_normal_thr;
152 u8 normal_to_degraded_high_thr;
153} __packed;
154
155struct wl128x_ini_fem_params_5 {
156 __le16 tx_bip_ref_pd_voltage[WL1271_INI_SUB_BAND_COUNT_5];
157 u8 tx_bip_ref_power[WL1271_INI_SUB_BAND_COUNT_5];
158 u8 tx_bip_ref_offset[WL1271_INI_SUB_BAND_COUNT_5];
159 u8 tx_per_rate_pwr_limits_normal[WL128X_INI_RATE_GROUP_COUNT];
160 u8 tx_per_rate_pwr_limits_degraded[WL128X_INI_RATE_GROUP_COUNT];
161 u8 tx_per_rate_pwr_limits_extreme[WL128X_INI_RATE_GROUP_COUNT];
162 u8 tx_per_chan_pwr_limits_ofdm[WL1271_INI_CHANNEL_COUNT_5];
163 u8 tx_pd_vs_rate_offsets[WL128X_INI_RATE_GROUP_COUNT];
164 u8 tx_ibias[WL128X_INI_RATE_GROUP_COUNT];
165 u8 tx_pd_vs_chan_offsets[WL1271_INI_CHANNEL_COUNT_5];
166 u8 tx_pd_vs_temperature[WL1271_INI_SUB_BAND_COUNT_5 *
167 WL128X_INI_PD_VS_TEMPERATURE_RANGES];
168 u8 rx_fem_insertion_loss[WL1271_INI_SUB_BAND_COUNT_5];
169 u8 degraded_low_to_normal_thr;
170 u8 normal_to_degraded_high_thr;
171} __packed;
172
173/* NVS data structure */
174#define WL1271_INI_NVS_SECTION_SIZE 468
175#define WL1271_INI_FEM_MODULE_COUNT 2
176
177#define WL1271_INI_LEGACY_NVS_FILE_SIZE 800
178
179struct wl1271_nvs_file {
180 /* NVS section - must be first! */
181 u8 nvs[WL1271_INI_NVS_SECTION_SIZE];
182
183 /* INI section */
184 struct wl1271_ini_general_params general_params;
185 u8 padding1;
186 struct wl1271_ini_band_params_2 stat_radio_params_2;
187 u8 padding2;
188 struct {
189 struct wl1271_ini_fem_params_2 params;
190 u8 padding;
191 } dyn_radio_params_2[WL1271_INI_FEM_MODULE_COUNT];
192 struct wl1271_ini_band_params_5 stat_radio_params_5;
193 u8 padding3;
194 struct {
195 struct wl1271_ini_fem_params_5 params;
196 u8 padding;
197 } dyn_radio_params_5[WL1271_INI_FEM_MODULE_COUNT];
198} __packed;
199
200struct wl128x_nvs_file {
201 /* NVS section - must be first! */
202 u8 nvs[WL1271_INI_NVS_SECTION_SIZE];
203
204 /* INI section */
205 struct wl128x_ini_general_params general_params;
206 u8 fem_vendor_and_options;
207 struct wl128x_ini_band_params_2 stat_radio_params_2;
208 u8 padding2;
209 struct {
210 struct wl128x_ini_fem_params_2 params;
211 u8 padding;
212 } dyn_radio_params_2[WL1271_INI_FEM_MODULE_COUNT];
213 struct wl128x_ini_band_params_5 stat_radio_params_5;
214 u8 padding3;
215 struct {
216 struct wl128x_ini_fem_params_5 params;
217 u8 padding;
218 } dyn_radio_params_5[WL1271_INI_FEM_MODULE_COUNT];
219} __packed;
220#endif
diff --git a/drivers/net/wireless/ti/wlcore/init.c b/drivers/net/wireless/ti/wlcore/init.c
new file mode 100644
index 000000000000..9f89255eb6e6
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/init.c
@@ -0,0 +1,737 @@
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 "debug.h"
29#include "init.h"
30#include "wl12xx_80211.h"
31#include "acx.h"
32#include "cmd.h"
33#include "tx.h"
34#include "io.h"
35#include "hw_ops.h"
36
37int wl1271_init_templates_config(struct wl1271 *wl)
38{
39 int ret, i;
40 size_t max_size;
41
42 /* send empty templates for fw memory reservation */
43 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
44 CMD_TEMPL_CFG_PROBE_REQ_2_4, NULL,
45 WL1271_CMD_TEMPL_MAX_SIZE,
46 0, WL1271_RATE_AUTOMATIC);
47 if (ret < 0)
48 return ret;
49
50 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
51 CMD_TEMPL_CFG_PROBE_REQ_5,
52 NULL, WL1271_CMD_TEMPL_MAX_SIZE, 0,
53 WL1271_RATE_AUTOMATIC);
54 if (ret < 0)
55 return ret;
56
57 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
58 CMD_TEMPL_NULL_DATA, NULL,
59 sizeof(struct wl12xx_null_data_template),
60 0, WL1271_RATE_AUTOMATIC);
61 if (ret < 0)
62 return ret;
63
64 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
65 CMD_TEMPL_PS_POLL, NULL,
66 sizeof(struct wl12xx_ps_poll_template),
67 0, WL1271_RATE_AUTOMATIC);
68 if (ret < 0)
69 return ret;
70
71 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
72 CMD_TEMPL_QOS_NULL_DATA, NULL,
73 sizeof
74 (struct ieee80211_qos_hdr),
75 0, WL1271_RATE_AUTOMATIC);
76 if (ret < 0)
77 return ret;
78
79 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
80 CMD_TEMPL_PROBE_RESPONSE, NULL,
81 WL1271_CMD_TEMPL_DFLT_SIZE,
82 0, WL1271_RATE_AUTOMATIC);
83 if (ret < 0)
84 return ret;
85
86 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
87 CMD_TEMPL_BEACON, NULL,
88 WL1271_CMD_TEMPL_DFLT_SIZE,
89 0, WL1271_RATE_AUTOMATIC);
90 if (ret < 0)
91 return ret;
92
93 max_size = sizeof(struct wl12xx_arp_rsp_template) +
94 WL1271_EXTRA_SPACE_MAX;
95 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
96 CMD_TEMPL_ARP_RSP, NULL,
97 max_size,
98 0, WL1271_RATE_AUTOMATIC);
99 if (ret < 0)
100 return ret;
101
102 /*
103 * Put very large empty placeholders for all templates. These
104 * reserve memory for later.
105 */
106 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
107 CMD_TEMPL_AP_PROBE_RESPONSE, NULL,
108 WL1271_CMD_TEMPL_MAX_SIZE,
109 0, WL1271_RATE_AUTOMATIC);
110 if (ret < 0)
111 return ret;
112
113 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
114 CMD_TEMPL_AP_BEACON, NULL,
115 WL1271_CMD_TEMPL_MAX_SIZE,
116 0, WL1271_RATE_AUTOMATIC);
117 if (ret < 0)
118 return ret;
119
120 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
121 CMD_TEMPL_DEAUTH_AP, NULL,
122 sizeof
123 (struct wl12xx_disconn_template),
124 0, WL1271_RATE_AUTOMATIC);
125 if (ret < 0)
126 return ret;
127
128 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
129 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
130 CMD_TEMPL_KLV, NULL,
131 sizeof(struct ieee80211_qos_hdr),
132 i, WL1271_RATE_AUTOMATIC);
133 if (ret < 0)
134 return ret;
135 }
136
137 return 0;
138}
139
140static int wl1271_ap_init_deauth_template(struct wl1271 *wl,
141 struct wl12xx_vif *wlvif)
142{
143 struct wl12xx_disconn_template *tmpl;
144 int ret;
145 u32 rate;
146
147 tmpl = kzalloc(sizeof(*tmpl), GFP_KERNEL);
148 if (!tmpl) {
149 ret = -ENOMEM;
150 goto out;
151 }
152
153 tmpl->header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT |
154 IEEE80211_STYPE_DEAUTH);
155
156 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
157 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
158 CMD_TEMPL_DEAUTH_AP,
159 tmpl, sizeof(*tmpl), 0, rate);
160
161out:
162 kfree(tmpl);
163 return ret;
164}
165
166static int wl1271_ap_init_null_template(struct wl1271 *wl,
167 struct ieee80211_vif *vif)
168{
169 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
170 struct ieee80211_hdr_3addr *nullfunc;
171 int ret;
172 u32 rate;
173
174 nullfunc = kzalloc(sizeof(*nullfunc), GFP_KERNEL);
175 if (!nullfunc) {
176 ret = -ENOMEM;
177 goto out;
178 }
179
180 nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
181 IEEE80211_STYPE_NULLFUNC |
182 IEEE80211_FCTL_FROMDS);
183
184 /* nullfunc->addr1 is filled by FW */
185
186 memcpy(nullfunc->addr2, vif->addr, ETH_ALEN);
187 memcpy(nullfunc->addr3, vif->addr, ETH_ALEN);
188
189 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
190 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
191 CMD_TEMPL_NULL_DATA, nullfunc,
192 sizeof(*nullfunc), 0, rate);
193
194out:
195 kfree(nullfunc);
196 return ret;
197}
198
199static int wl1271_ap_init_qos_null_template(struct wl1271 *wl,
200 struct ieee80211_vif *vif)
201{
202 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
203 struct ieee80211_qos_hdr *qosnull;
204 int ret;
205 u32 rate;
206
207 qosnull = kzalloc(sizeof(*qosnull), GFP_KERNEL);
208 if (!qosnull) {
209 ret = -ENOMEM;
210 goto out;
211 }
212
213 qosnull->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
214 IEEE80211_STYPE_QOS_NULLFUNC |
215 IEEE80211_FCTL_FROMDS);
216
217 /* qosnull->addr1 is filled by FW */
218
219 memcpy(qosnull->addr2, vif->addr, ETH_ALEN);
220 memcpy(qosnull->addr3, vif->addr, ETH_ALEN);
221
222 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
223 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
224 CMD_TEMPL_QOS_NULL_DATA, qosnull,
225 sizeof(*qosnull), 0, rate);
226
227out:
228 kfree(qosnull);
229 return ret;
230}
231
232static int wl12xx_init_rx_config(struct wl1271 *wl)
233{
234 int ret;
235
236 ret = wl1271_acx_rx_msdu_life_time(wl);
237 if (ret < 0)
238 return ret;
239
240 return 0;
241}
242
243static int wl12xx_init_phy_vif_config(struct wl1271 *wl,
244 struct wl12xx_vif *wlvif)
245{
246 int ret;
247
248 ret = wl1271_acx_slot(wl, wlvif, DEFAULT_SLOT_TIME);
249 if (ret < 0)
250 return ret;
251
252 ret = wl1271_acx_service_period_timeout(wl, wlvif);
253 if (ret < 0)
254 return ret;
255
256 ret = wl1271_acx_rts_threshold(wl, wlvif, wl->hw->wiphy->rts_threshold);
257 if (ret < 0)
258 return ret;
259
260 return 0;
261}
262
263static int wl1271_init_sta_beacon_filter(struct wl1271 *wl,
264 struct wl12xx_vif *wlvif)
265{
266 int ret;
267
268 ret = wl1271_acx_beacon_filter_table(wl, wlvif);
269 if (ret < 0)
270 return ret;
271
272 /* enable beacon filtering */
273 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true);
274 if (ret < 0)
275 return ret;
276
277 return 0;
278}
279
280int wl1271_init_pta(struct wl1271 *wl)
281{
282 int ret;
283
284 ret = wl12xx_acx_sg_cfg(wl);
285 if (ret < 0)
286 return ret;
287
288 ret = wl1271_acx_sg_enable(wl, wl->sg_enabled);
289 if (ret < 0)
290 return ret;
291
292 return 0;
293}
294
295int wl1271_init_energy_detection(struct wl1271 *wl)
296{
297 int ret;
298
299 ret = wl1271_acx_cca_threshold(wl);
300 if (ret < 0)
301 return ret;
302
303 return 0;
304}
305
306static int wl1271_init_beacon_broadcast(struct wl1271 *wl,
307 struct wl12xx_vif *wlvif)
308{
309 int ret;
310
311 ret = wl1271_acx_bcn_dtim_options(wl, wlvif);
312 if (ret < 0)
313 return ret;
314
315 return 0;
316}
317
318static int wl12xx_init_fwlog(struct wl1271 *wl)
319{
320 int ret;
321
322 if (wl->quirks & WLCORE_QUIRK_FWLOG_NOT_IMPLEMENTED)
323 return 0;
324
325 ret = wl12xx_cmd_config_fwlog(wl);
326 if (ret < 0)
327 return ret;
328
329 return 0;
330}
331
332/* generic sta initialization (non vif-specific) */
333static int wl1271_sta_hw_init(struct wl1271 *wl, struct wl12xx_vif *wlvif)
334{
335 int ret;
336
337 /* PS config */
338 ret = wl12xx_acx_config_ps(wl, wlvif);
339 if (ret < 0)
340 return ret;
341
342 /* FM WLAN coexistence */
343 ret = wl1271_acx_fm_coex(wl);
344 if (ret < 0)
345 return ret;
346
347 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
348 if (ret < 0)
349 return ret;
350
351 return 0;
352}
353
354static int wl1271_sta_hw_init_post_mem(struct wl1271 *wl,
355 struct ieee80211_vif *vif)
356{
357 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
358 int ret, i;
359
360 /* disable all keep-alive templates */
361 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
362 ret = wl1271_acx_keep_alive_config(wl, wlvif, i,
363 ACX_KEEP_ALIVE_TPL_INVALID);
364 if (ret < 0)
365 return ret;
366 }
367
368 /* disable the keep-alive feature */
369 ret = wl1271_acx_keep_alive_mode(wl, wlvif, false);
370 if (ret < 0)
371 return ret;
372
373 return 0;
374}
375
376/* generic ap initialization (non vif-specific) */
377static int wl1271_ap_hw_init(struct wl1271 *wl, struct wl12xx_vif *wlvif)
378{
379 int ret;
380
381 ret = wl1271_init_ap_rates(wl, wlvif);
382 if (ret < 0)
383 return ret;
384
385 return 0;
386}
387
388int wl1271_ap_init_templates(struct wl1271 *wl, struct ieee80211_vif *vif)
389{
390 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
391 int ret;
392
393 ret = wl1271_ap_init_deauth_template(wl, wlvif);
394 if (ret < 0)
395 return ret;
396
397 ret = wl1271_ap_init_null_template(wl, vif);
398 if (ret < 0)
399 return ret;
400
401 ret = wl1271_ap_init_qos_null_template(wl, vif);
402 if (ret < 0)
403 return ret;
404
405 /*
406 * when operating as AP we want to receive external beacons for
407 * configuring ERP protection.
408 */
409 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false);
410 if (ret < 0)
411 return ret;
412
413 return 0;
414}
415
416static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl,
417 struct ieee80211_vif *vif)
418{
419 return wl1271_ap_init_templates(wl, vif);
420}
421
422int wl1271_init_ap_rates(struct wl1271 *wl, struct wl12xx_vif *wlvif)
423{
424 int i, ret;
425 struct conf_tx_rate_class rc;
426 u32 supported_rates;
427
428 wl1271_debug(DEBUG_AP, "AP basic rate set: 0x%x",
429 wlvif->basic_rate_set);
430
431 if (wlvif->basic_rate_set == 0)
432 return -EINVAL;
433
434 rc.enabled_rates = wlvif->basic_rate_set;
435 rc.long_retry_limit = 10;
436 rc.short_retry_limit = 10;
437 rc.aflags = 0;
438 ret = wl1271_acx_ap_rate_policy(wl, &rc, wlvif->ap.mgmt_rate_idx);
439 if (ret < 0)
440 return ret;
441
442 /* use the min basic rate for AP broadcast/multicast */
443 rc.enabled_rates = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
444 rc.short_retry_limit = 10;
445 rc.long_retry_limit = 10;
446 rc.aflags = 0;
447 ret = wl1271_acx_ap_rate_policy(wl, &rc, wlvif->ap.bcast_rate_idx);
448 if (ret < 0)
449 return ret;
450
451 /*
452 * If the basic rates contain OFDM rates, use OFDM only
453 * rates for unicast TX as well. Else use all supported rates.
454 */
455 if ((wlvif->basic_rate_set & CONF_TX_OFDM_RATES))
456 supported_rates = CONF_TX_OFDM_RATES;
457 else
458 supported_rates = CONF_TX_AP_ENABLED_RATES;
459
460 /* unconditionally enable HT rates */
461 supported_rates |= CONF_TX_MCS_RATES;
462
463 /* configure unicast TX rate classes */
464 for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
465 rc.enabled_rates = supported_rates;
466 rc.short_retry_limit = 10;
467 rc.long_retry_limit = 10;
468 rc.aflags = 0;
469 ret = wl1271_acx_ap_rate_policy(wl, &rc,
470 wlvif->ap.ucast_rate_idx[i]);
471 if (ret < 0)
472 return ret;
473 }
474
475 return 0;
476}
477
478static int wl1271_set_ba_policies(struct wl1271 *wl, struct wl12xx_vif *wlvif)
479{
480 /* Reset the BA RX indicators */
481 wlvif->ba_allowed = true;
482 wl->ba_rx_session_count = 0;
483
484 /* BA is supported in STA/AP modes */
485 if (wlvif->bss_type != BSS_TYPE_AP_BSS &&
486 wlvif->bss_type != BSS_TYPE_STA_BSS) {
487 wlvif->ba_support = false;
488 return 0;
489 }
490
491 wlvif->ba_support = true;
492
493 /* 802.11n initiator BA session setting */
494 return wl12xx_acx_set_ba_initiator_policy(wl, wlvif);
495}
496
497/* vif-specifc initialization */
498static int wl12xx_init_sta_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
499{
500 int ret;
501
502 ret = wl1271_acx_group_address_tbl(wl, wlvif, true, NULL, 0);
503 if (ret < 0)
504 return ret;
505
506 /* Initialize connection monitoring thresholds */
507 ret = wl1271_acx_conn_monit_params(wl, wlvif, false);
508 if (ret < 0)
509 return ret;
510
511 /* Beacon filtering */
512 ret = wl1271_init_sta_beacon_filter(wl, wlvif);
513 if (ret < 0)
514 return ret;
515
516 /* Beacons and broadcast settings */
517 ret = wl1271_init_beacon_broadcast(wl, wlvif);
518 if (ret < 0)
519 return ret;
520
521 /* Configure rssi/snr averaging weights */
522 ret = wl1271_acx_rssi_snr_avg_weights(wl, wlvif);
523 if (ret < 0)
524 return ret;
525
526 return 0;
527}
528
529/* vif-specific intialization */
530static int wl12xx_init_ap_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
531{
532 int ret;
533
534 ret = wl1271_acx_ap_max_tx_retry(wl, wlvif);
535 if (ret < 0)
536 return ret;
537
538 /* initialize Tx power */
539 ret = wl1271_acx_tx_power(wl, wlvif, wlvif->power_level);
540 if (ret < 0)
541 return ret;
542
543 return 0;
544}
545
546int wl1271_init_vif_specific(struct wl1271 *wl, struct ieee80211_vif *vif)
547{
548 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
549 struct conf_tx_ac_category *conf_ac;
550 struct conf_tx_tid *conf_tid;
551 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
552 int ret, i;
553
554 /*
555 * consider all existing roles before configuring psm.
556 * TODO: reconfigure on interface removal.
557 */
558 if (!wl->ap_count) {
559 if (is_ap) {
560 /* Configure for power always on */
561 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
562 if (ret < 0)
563 return ret;
564 } else if (!wl->sta_count) {
565 if (wl->quirks & WLCORE_QUIRK_NO_ELP) {
566 /* Configure for power always on */
567 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
568 if (ret < 0)
569 return ret;
570 } else {
571 /* Configure for ELP power saving */
572 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
573 if (ret < 0)
574 return ret;
575 }
576 }
577 }
578
579 /* Mode specific init */
580 if (is_ap) {
581 ret = wl1271_ap_hw_init(wl, wlvif);
582 if (ret < 0)
583 return ret;
584
585 ret = wl12xx_init_ap_role(wl, wlvif);
586 if (ret < 0)
587 return ret;
588 } else {
589 ret = wl1271_sta_hw_init(wl, wlvif);
590 if (ret < 0)
591 return ret;
592
593 ret = wl12xx_init_sta_role(wl, wlvif);
594 if (ret < 0)
595 return ret;
596 }
597
598 wl12xx_init_phy_vif_config(wl, wlvif);
599
600 /* Default TID/AC configuration */
601 BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
602 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
603 conf_ac = &wl->conf.tx.ac_conf[i];
604 ret = wl1271_acx_ac_cfg(wl, wlvif, conf_ac->ac,
605 conf_ac->cw_min, conf_ac->cw_max,
606 conf_ac->aifsn, conf_ac->tx_op_limit);
607 if (ret < 0)
608 return ret;
609
610 conf_tid = &wl->conf.tx.tid_conf[i];
611 ret = wl1271_acx_tid_cfg(wl, wlvif,
612 conf_tid->queue_id,
613 conf_tid->channel_type,
614 conf_tid->tsid,
615 conf_tid->ps_scheme,
616 conf_tid->ack_policy,
617 conf_tid->apsd_conf[0],
618 conf_tid->apsd_conf[1]);
619 if (ret < 0)
620 return ret;
621 }
622
623 /* Configure HW encryption */
624 ret = wl1271_acx_feature_cfg(wl, wlvif);
625 if (ret < 0)
626 return ret;
627
628 /* Mode specific init - post mem init */
629 if (is_ap)
630 ret = wl1271_ap_hw_init_post_mem(wl, vif);
631 else
632 ret = wl1271_sta_hw_init_post_mem(wl, vif);
633
634 if (ret < 0)
635 return ret;
636
637 /* Configure initiator BA sessions policies */
638 ret = wl1271_set_ba_policies(wl, wlvif);
639 if (ret < 0)
640 return ret;
641
642 ret = wlcore_hw_init_vif(wl, wlvif);
643 if (ret < 0)
644 return ret;
645
646 return 0;
647}
648
649int wl1271_hw_init(struct wl1271 *wl)
650{
651 int ret;
652
653 /* Chip-specific hw init */
654 ret = wl->ops->hw_init(wl);
655 if (ret < 0)
656 return ret;
657
658 /* Init templates */
659 ret = wl1271_init_templates_config(wl);
660 if (ret < 0)
661 return ret;
662
663 ret = wl12xx_acx_mem_cfg(wl);
664 if (ret < 0)
665 return ret;
666
667 /* Configure the FW logger */
668 ret = wl12xx_init_fwlog(wl);
669 if (ret < 0)
670 return ret;
671
672 /* Bluetooth WLAN coexistence */
673 ret = wl1271_init_pta(wl);
674 if (ret < 0)
675 return ret;
676
677 /* Default memory configuration */
678 ret = wl1271_acx_init_mem_config(wl);
679 if (ret < 0)
680 return ret;
681
682 /* RX config */
683 ret = wl12xx_init_rx_config(wl);
684 if (ret < 0)
685 goto out_free_memmap;
686
687 ret = wl1271_acx_dco_itrim_params(wl);
688 if (ret < 0)
689 goto out_free_memmap;
690
691 /* Configure TX patch complete interrupt behavior */
692 ret = wl1271_acx_tx_config_options(wl);
693 if (ret < 0)
694 goto out_free_memmap;
695
696 /* RX complete interrupt pacing */
697 ret = wl1271_acx_init_rx_interrupt(wl);
698 if (ret < 0)
699 goto out_free_memmap;
700
701 /* Energy detection */
702 ret = wl1271_init_energy_detection(wl);
703 if (ret < 0)
704 goto out_free_memmap;
705
706 /* Default fragmentation threshold */
707 ret = wl1271_acx_frag_threshold(wl, wl->hw->wiphy->frag_threshold);
708 if (ret < 0)
709 goto out_free_memmap;
710
711 /* Enable data path */
712 ret = wl1271_cmd_data_path(wl, 1);
713 if (ret < 0)
714 goto out_free_memmap;
715
716 /* configure PM */
717 ret = wl1271_acx_pm_config(wl);
718 if (ret < 0)
719 goto out_free_memmap;
720
721 ret = wl12xx_acx_set_rate_mgmt_params(wl);
722 if (ret < 0)
723 goto out_free_memmap;
724
725 /* configure hangover */
726 ret = wl12xx_acx_config_hangover(wl);
727 if (ret < 0)
728 goto out_free_memmap;
729
730 return 0;
731
732 out_free_memmap:
733 kfree(wl->target_mem_map);
734 wl->target_mem_map = NULL;
735
736 return ret;
737}
diff --git a/drivers/net/wireless/ti/wlcore/init.h b/drivers/net/wireless/ti/wlcore/init.h
new file mode 100644
index 000000000000..a45fbfddec19
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/init.h
@@ -0,0 +1,39 @@
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#ifndef __INIT_H__
25#define __INIT_H__
26
27#include "wlcore.h"
28
29int wl1271_hw_init_power_auth(struct wl1271 *wl);
30int wl1271_init_templates_config(struct wl1271 *wl);
31int wl1271_init_pta(struct wl1271 *wl);
32int wl1271_init_energy_detection(struct wl1271 *wl);
33int wl1271_chip_specific_init(struct wl1271 *wl);
34int wl1271_hw_init(struct wl1271 *wl);
35int wl1271_init_vif_specific(struct wl1271 *wl, struct ieee80211_vif *vif);
36int wl1271_init_ap_rates(struct wl1271 *wl, struct wl12xx_vif *wlvif);
37int wl1271_ap_init_templates(struct wl1271 *wl, struct ieee80211_vif *vif);
38
39#endif
diff --git a/drivers/net/wireless/ti/wlcore/io.c b/drivers/net/wireless/ti/wlcore/io.c
new file mode 100644
index 000000000000..7cd0081aede5
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/io.c
@@ -0,0 +1,173 @@
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/platform_device.h>
26#include <linux/spi/spi.h>
27#include <linux/interrupt.h>
28
29#include "wlcore.h"
30#include "debug.h"
31#include "wl12xx_80211.h"
32#include "io.h"
33#include "tx.h"
34
35bool wl1271_set_block_size(struct wl1271 *wl)
36{
37 if (wl->if_ops->set_block_size) {
38 wl->if_ops->set_block_size(wl->dev, WL12XX_BUS_BLOCK_SIZE);
39 return true;
40 }
41
42 return false;
43}
44
45void wlcore_disable_interrupts(struct wl1271 *wl)
46{
47 disable_irq(wl->irq);
48}
49EXPORT_SYMBOL_GPL(wlcore_disable_interrupts);
50
51void wlcore_enable_interrupts(struct wl1271 *wl)
52{
53 enable_irq(wl->irq);
54}
55EXPORT_SYMBOL_GPL(wlcore_enable_interrupts);
56
57int wlcore_translate_addr(struct wl1271 *wl, int addr)
58{
59 struct wlcore_partition_set *part = &wl->curr_part;
60
61 /*
62 * To translate, first check to which window of addresses the
63 * particular address belongs. Then subtract the starting address
64 * of that window from the address. Then, add offset of the
65 * translated region.
66 *
67 * The translated regions occur next to each other in physical device
68 * memory, so just add the sizes of the preceding address regions to
69 * get the offset to the new region.
70 */
71 if ((addr >= part->mem.start) &&
72 (addr < part->mem.start + part->mem.size))
73 return addr - part->mem.start;
74 else if ((addr >= part->reg.start) &&
75 (addr < part->reg.start + part->reg.size))
76 return addr - part->reg.start + part->mem.size;
77 else if ((addr >= part->mem2.start) &&
78 (addr < part->mem2.start + part->mem2.size))
79 return addr - part->mem2.start + part->mem.size +
80 part->reg.size;
81 else if ((addr >= part->mem3.start) &&
82 (addr < part->mem3.start + part->mem3.size))
83 return addr - part->mem3.start + part->mem.size +
84 part->reg.size + part->mem2.size;
85
86 WARN(1, "HW address 0x%x out of range", addr);
87 return 0;
88}
89EXPORT_SYMBOL_GPL(wlcore_translate_addr);
90
91/* Set the partitions to access the chip addresses
92 *
93 * To simplify driver code, a fixed (virtual) memory map is defined for
94 * register and memory addresses. Because in the chipset, in different stages
95 * of operation, those addresses will move around, an address translation
96 * mechanism is required.
97 *
98 * There are four partitions (three memory and one register partition),
99 * which are mapped to two different areas of the hardware memory.
100 *
101 * Virtual address
102 * space
103 *
104 * | |
105 * ...+----+--> mem.start
106 * Physical address ... | |
107 * space ... | | [PART_0]
108 * ... | |
109 * 00000000 <--+----+... ...+----+--> mem.start + mem.size
110 * | | ... | |
111 * |MEM | ... | |
112 * | | ... | |
113 * mem.size <--+----+... | | {unused area)
114 * | | ... | |
115 * |REG | ... | |
116 * mem.size | | ... | |
117 * + <--+----+... ...+----+--> reg.start
118 * reg.size | | ... | |
119 * |MEM2| ... | | [PART_1]
120 * | | ... | |
121 * ...+----+--> reg.start + reg.size
122 * | |
123 *
124 */
125void wlcore_set_partition(struct wl1271 *wl,
126 const struct wlcore_partition_set *p)
127{
128 /* copy partition info */
129 memcpy(&wl->curr_part, p, sizeof(*p));
130
131 wl1271_debug(DEBUG_IO, "mem_start %08X mem_size %08X",
132 p->mem.start, p->mem.size);
133 wl1271_debug(DEBUG_IO, "reg_start %08X reg_size %08X",
134 p->reg.start, p->reg.size);
135 wl1271_debug(DEBUG_IO, "mem2_start %08X mem2_size %08X",
136 p->mem2.start, p->mem2.size);
137 wl1271_debug(DEBUG_IO, "mem3_start %08X mem3_size %08X",
138 p->mem3.start, p->mem3.size);
139
140 wl1271_raw_write32(wl, HW_PART0_START_ADDR, p->mem.start);
141 wl1271_raw_write32(wl, HW_PART0_SIZE_ADDR, p->mem.size);
142 wl1271_raw_write32(wl, HW_PART1_START_ADDR, p->reg.start);
143 wl1271_raw_write32(wl, HW_PART1_SIZE_ADDR, p->reg.size);
144 wl1271_raw_write32(wl, HW_PART2_START_ADDR, p->mem2.start);
145 wl1271_raw_write32(wl, HW_PART2_SIZE_ADDR, p->mem2.size);
146 /*
147 * We don't need the size of the last partition, as it is
148 * automatically calculated based on the total memory size and
149 * the sizes of the previous partitions.
150 */
151 wl1271_raw_write32(wl, HW_PART3_START_ADDR, p->mem3.start);
152}
153EXPORT_SYMBOL_GPL(wlcore_set_partition);
154
155void wlcore_select_partition(struct wl1271 *wl, u8 part)
156{
157 wl1271_debug(DEBUG_IO, "setting partition %d", part);
158
159 wlcore_set_partition(wl, &wl->ptable[part]);
160}
161EXPORT_SYMBOL_GPL(wlcore_select_partition);
162
163void wl1271_io_reset(struct wl1271 *wl)
164{
165 if (wl->if_ops->reset)
166 wl->if_ops->reset(wl->dev);
167}
168
169void wl1271_io_init(struct wl1271 *wl)
170{
171 if (wl->if_ops->init)
172 wl->if_ops->init(wl->dev);
173}
diff --git a/drivers/net/wireless/ti/wlcore/io.h b/drivers/net/wireless/ti/wlcore/io.h
new file mode 100644
index 000000000000..8942954b56a0
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/io.h
@@ -0,0 +1,187 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
5 * Copyright (C) 2008-2010 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 __IO_H__
26#define __IO_H__
27
28#include <linux/irqreturn.h>
29
30#define HW_ACCESS_MEMORY_MAX_RANGE 0x1FFC0
31
32#define HW_PARTITION_REGISTERS_ADDR 0x1FFC0
33#define HW_PART0_SIZE_ADDR (HW_PARTITION_REGISTERS_ADDR)
34#define HW_PART0_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 4)
35#define HW_PART1_SIZE_ADDR (HW_PARTITION_REGISTERS_ADDR + 8)
36#define HW_PART1_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 12)
37#define HW_PART2_SIZE_ADDR (HW_PARTITION_REGISTERS_ADDR + 16)
38#define HW_PART2_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 20)
39#define HW_PART3_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 24)
40
41#define HW_ACCESS_REGISTER_SIZE 4
42
43#define HW_ACCESS_PRAM_MAX_RANGE 0x3c000
44
45struct wl1271;
46
47void wlcore_disable_interrupts(struct wl1271 *wl);
48void wlcore_enable_interrupts(struct wl1271 *wl);
49
50void wl1271_io_reset(struct wl1271 *wl);
51void wl1271_io_init(struct wl1271 *wl);
52int wlcore_translate_addr(struct wl1271 *wl, int addr);
53
54/* Raw target IO, address is not translated */
55static inline void wl1271_raw_write(struct wl1271 *wl, int addr, void *buf,
56 size_t len, bool fixed)
57{
58 wl->if_ops->write(wl->dev, addr, buf, len, fixed);
59}
60
61static inline void wl1271_raw_read(struct wl1271 *wl, int addr, void *buf,
62 size_t len, bool fixed)
63{
64 wl->if_ops->read(wl->dev, addr, buf, len, fixed);
65}
66
67static inline void wlcore_raw_read_data(struct wl1271 *wl, int reg, void *buf,
68 size_t len, bool fixed)
69{
70 wl1271_raw_read(wl, wl->rtable[reg], buf, len, fixed);
71}
72
73static inline void wlcore_raw_write_data(struct wl1271 *wl, int reg, void *buf,
74 size_t len, bool fixed)
75{
76 wl1271_raw_write(wl, wl->rtable[reg], buf, len, fixed);
77}
78
79static inline u32 wl1271_raw_read32(struct wl1271 *wl, int addr)
80{
81 wl1271_raw_read(wl, addr, &wl->buffer_32,
82 sizeof(wl->buffer_32), false);
83
84 return le32_to_cpu(wl->buffer_32);
85}
86
87static inline void wl1271_raw_write32(struct wl1271 *wl, int addr, u32 val)
88{
89 wl->buffer_32 = cpu_to_le32(val);
90 wl1271_raw_write(wl, addr, &wl->buffer_32,
91 sizeof(wl->buffer_32), false);
92}
93
94static inline void wl1271_read(struct wl1271 *wl, int addr, void *buf,
95 size_t len, bool fixed)
96{
97 int physical;
98
99 physical = wlcore_translate_addr(wl, addr);
100
101 wl1271_raw_read(wl, physical, buf, len, fixed);
102}
103
104static inline void wl1271_write(struct wl1271 *wl, int addr, void *buf,
105 size_t len, bool fixed)
106{
107 int physical;
108
109 physical = wlcore_translate_addr(wl, addr);
110
111 wl1271_raw_write(wl, physical, buf, len, fixed);
112}
113
114static inline void wlcore_write_data(struct wl1271 *wl, int reg, void *buf,
115 size_t len, bool fixed)
116{
117 wl1271_write(wl, wl->rtable[reg], buf, len, fixed);
118}
119
120static inline void wlcore_read_data(struct wl1271 *wl, int reg, void *buf,
121 size_t len, bool fixed)
122{
123 wl1271_read(wl, wl->rtable[reg], buf, len, fixed);
124}
125
126static inline void wl1271_read_hwaddr(struct wl1271 *wl, int hwaddr,
127 void *buf, size_t len, bool fixed)
128{
129 int physical;
130 int addr;
131
132 /* Addresses are stored internally as addresses to 32 bytes blocks */
133 addr = hwaddr << 5;
134
135 physical = wlcore_translate_addr(wl, addr);
136
137 wl1271_raw_read(wl, physical, buf, len, fixed);
138}
139
140static inline u32 wl1271_read32(struct wl1271 *wl, int addr)
141{
142 return wl1271_raw_read32(wl, wlcore_translate_addr(wl, addr));
143}
144
145static inline void wl1271_write32(struct wl1271 *wl, int addr, u32 val)
146{
147 wl1271_raw_write32(wl, wlcore_translate_addr(wl, addr), val);
148}
149
150static inline u32 wlcore_read_reg(struct wl1271 *wl, int reg)
151{
152 return wl1271_raw_read32(wl,
153 wlcore_translate_addr(wl, wl->rtable[reg]));
154}
155
156static inline void wlcore_write_reg(struct wl1271 *wl, int reg, u32 val)
157{
158 wl1271_raw_write32(wl, wlcore_translate_addr(wl, wl->rtable[reg]), val);
159}
160
161static inline void wl1271_power_off(struct wl1271 *wl)
162{
163 wl->if_ops->power(wl->dev, false);
164 clear_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
165}
166
167static inline int wl1271_power_on(struct wl1271 *wl)
168{
169 int ret = wl->if_ops->power(wl->dev, true);
170 if (ret == 0)
171 set_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
172
173 return ret;
174}
175
176void wlcore_set_partition(struct wl1271 *wl,
177 const struct wlcore_partition_set *p);
178
179bool wl1271_set_block_size(struct wl1271 *wl);
180
181/* Functions from wl1271_main.c */
182
183int wl1271_tx_dummy_packet(struct wl1271 *wl);
184
185void wlcore_select_partition(struct wl1271 *wl, u8 part);
186
187#endif
diff --git a/drivers/net/wireless/ti/wlcore/main.c b/drivers/net/wireless/ti/wlcore/main.c
new file mode 100644
index 000000000000..2b0f987660c6
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/main.c
@@ -0,0 +1,5093 @@
1
2/*
3 * This file is part of wl1271
4 *
5 * Copyright (C) 2008-2010 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#include <linux/module.h>
26#include <linux/firmware.h>
27#include <linux/delay.h>
28#include <linux/spi/spi.h>
29#include <linux/crc32.h>
30#include <linux/etherdevice.h>
31#include <linux/vmalloc.h>
32#include <linux/platform_device.h>
33#include <linux/slab.h>
34#include <linux/wl12xx.h>
35#include <linux/sched.h>
36#include <linux/interrupt.h>
37
38#include "wlcore.h"
39#include "debug.h"
40#include "wl12xx_80211.h"
41#include "io.h"
42#include "event.h"
43#include "tx.h"
44#include "rx.h"
45#include "ps.h"
46#include "init.h"
47#include "debugfs.h"
48#include "cmd.h"
49#include "boot.h"
50#include "testmode.h"
51#include "scan.h"
52#include "hw_ops.h"
53
54#define WL1271_BOOT_RETRIES 3
55
56#define WL1271_BOOT_RETRIES 3
57
58static char *fwlog_param;
59static bool bug_on_recovery;
60static bool no_recovery;
61
62static void __wl1271_op_remove_interface(struct wl1271 *wl,
63 struct ieee80211_vif *vif,
64 bool reset_tx_queues);
65static void wl1271_op_stop(struct ieee80211_hw *hw);
66static void wl1271_free_ap_keys(struct wl1271 *wl, struct wl12xx_vif *wlvif);
67
68static int wl12xx_set_authorized(struct wl1271 *wl,
69 struct wl12xx_vif *wlvif)
70{
71 int ret;
72
73 if (WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS))
74 return -EINVAL;
75
76 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
77 return 0;
78
79 if (test_and_set_bit(WLVIF_FLAG_STA_STATE_SENT, &wlvif->flags))
80 return 0;
81
82 ret = wl12xx_cmd_set_peer_state(wl, wlvif->sta.hlid);
83 if (ret < 0)
84 return ret;
85
86 wl12xx_croc(wl, wlvif->role_id);
87
88 wl1271_info("Association completed.");
89 return 0;
90}
91
92static int wl1271_reg_notify(struct wiphy *wiphy,
93 struct regulatory_request *request)
94{
95 struct ieee80211_supported_band *band;
96 struct ieee80211_channel *ch;
97 int i;
98
99 band = wiphy->bands[IEEE80211_BAND_5GHZ];
100 for (i = 0; i < band->n_channels; i++) {
101 ch = &band->channels[i];
102 if (ch->flags & IEEE80211_CHAN_DISABLED)
103 continue;
104
105 if (ch->flags & IEEE80211_CHAN_RADAR)
106 ch->flags |= IEEE80211_CHAN_NO_IBSS |
107 IEEE80211_CHAN_PASSIVE_SCAN;
108
109 }
110
111 return 0;
112}
113
114static int wl1271_set_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif,
115 bool enable)
116{
117 int ret = 0;
118
119 /* we should hold wl->mutex */
120 ret = wl1271_acx_ps_rx_streaming(wl, wlvif, enable);
121 if (ret < 0)
122 goto out;
123
124 if (enable)
125 set_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags);
126 else
127 clear_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags);
128out:
129 return ret;
130}
131
132/*
133 * this function is being called when the rx_streaming interval
134 * has beed changed or rx_streaming should be disabled
135 */
136int wl1271_recalc_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif)
137{
138 int ret = 0;
139 int period = wl->conf.rx_streaming.interval;
140
141 /* don't reconfigure if rx_streaming is disabled */
142 if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags))
143 goto out;
144
145 /* reconfigure/disable according to new streaming_period */
146 if (period &&
147 test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) &&
148 (wl->conf.rx_streaming.always ||
149 test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags)))
150 ret = wl1271_set_rx_streaming(wl, wlvif, true);
151 else {
152 ret = wl1271_set_rx_streaming(wl, wlvif, false);
153 /* don't cancel_work_sync since we might deadlock */
154 del_timer_sync(&wlvif->rx_streaming_timer);
155 }
156out:
157 return ret;
158}
159
160static void wl1271_rx_streaming_enable_work(struct work_struct *work)
161{
162 int ret;
163 struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif,
164 rx_streaming_enable_work);
165 struct wl1271 *wl = wlvif->wl;
166
167 mutex_lock(&wl->mutex);
168
169 if (test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags) ||
170 !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) ||
171 (!wl->conf.rx_streaming.always &&
172 !test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags)))
173 goto out;
174
175 if (!wl->conf.rx_streaming.interval)
176 goto out;
177
178 ret = wl1271_ps_elp_wakeup(wl);
179 if (ret < 0)
180 goto out;
181
182 ret = wl1271_set_rx_streaming(wl, wlvif, true);
183 if (ret < 0)
184 goto out_sleep;
185
186 /* stop it after some time of inactivity */
187 mod_timer(&wlvif->rx_streaming_timer,
188 jiffies + msecs_to_jiffies(wl->conf.rx_streaming.duration));
189
190out_sleep:
191 wl1271_ps_elp_sleep(wl);
192out:
193 mutex_unlock(&wl->mutex);
194}
195
196static void wl1271_rx_streaming_disable_work(struct work_struct *work)
197{
198 int ret;
199 struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif,
200 rx_streaming_disable_work);
201 struct wl1271 *wl = wlvif->wl;
202
203 mutex_lock(&wl->mutex);
204
205 if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags))
206 goto out;
207
208 ret = wl1271_ps_elp_wakeup(wl);
209 if (ret < 0)
210 goto out;
211
212 ret = wl1271_set_rx_streaming(wl, wlvif, false);
213 if (ret)
214 goto out_sleep;
215
216out_sleep:
217 wl1271_ps_elp_sleep(wl);
218out:
219 mutex_unlock(&wl->mutex);
220}
221
222static void wl1271_rx_streaming_timer(unsigned long data)
223{
224 struct wl12xx_vif *wlvif = (struct wl12xx_vif *)data;
225 struct wl1271 *wl = wlvif->wl;
226 ieee80211_queue_work(wl->hw, &wlvif->rx_streaming_disable_work);
227}
228
229/* wl->mutex must be taken */
230void wl12xx_rearm_tx_watchdog_locked(struct wl1271 *wl)
231{
232 /* if the watchdog is not armed, don't do anything */
233 if (wl->tx_allocated_blocks == 0)
234 return;
235
236 cancel_delayed_work(&wl->tx_watchdog_work);
237 ieee80211_queue_delayed_work(wl->hw, &wl->tx_watchdog_work,
238 msecs_to_jiffies(wl->conf.tx.tx_watchdog_timeout));
239}
240
241static void wl12xx_tx_watchdog_work(struct work_struct *work)
242{
243 struct delayed_work *dwork;
244 struct wl1271 *wl;
245
246 dwork = container_of(work, struct delayed_work, work);
247 wl = container_of(dwork, struct wl1271, tx_watchdog_work);
248
249 mutex_lock(&wl->mutex);
250
251 if (unlikely(wl->state == WL1271_STATE_OFF))
252 goto out;
253
254 /* Tx went out in the meantime - everything is ok */
255 if (unlikely(wl->tx_allocated_blocks == 0))
256 goto out;
257
258 /*
259 * if a ROC is in progress, we might not have any Tx for a long
260 * time (e.g. pending Tx on the non-ROC channels)
261 */
262 if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) < WL12XX_MAX_ROLES) {
263 wl1271_debug(DEBUG_TX, "No Tx (in FW) for %d ms due to ROC",
264 wl->conf.tx.tx_watchdog_timeout);
265 wl12xx_rearm_tx_watchdog_locked(wl);
266 goto out;
267 }
268
269 /*
270 * if a scan is in progress, we might not have any Tx for a long
271 * time
272 */
273 if (wl->scan.state != WL1271_SCAN_STATE_IDLE) {
274 wl1271_debug(DEBUG_TX, "No Tx (in FW) for %d ms due to scan",
275 wl->conf.tx.tx_watchdog_timeout);
276 wl12xx_rearm_tx_watchdog_locked(wl);
277 goto out;
278 }
279
280 /*
281 * AP might cache a frame for a long time for a sleeping station,
282 * so rearm the timer if there's an AP interface with stations. If
283 * Tx is genuinely stuck we will most hopefully discover it when all
284 * stations are removed due to inactivity.
285 */
286 if (wl->active_sta_count) {
287 wl1271_debug(DEBUG_TX, "No Tx (in FW) for %d ms. AP has "
288 " %d stations",
289 wl->conf.tx.tx_watchdog_timeout,
290 wl->active_sta_count);
291 wl12xx_rearm_tx_watchdog_locked(wl);
292 goto out;
293 }
294
295 wl1271_error("Tx stuck (in FW) for %d ms. Starting recovery",
296 wl->conf.tx.tx_watchdog_timeout);
297 wl12xx_queue_recovery_work(wl);
298
299out:
300 mutex_unlock(&wl->mutex);
301}
302
303static void wlcore_adjust_conf(struct wl1271 *wl)
304{
305 /* Adjust settings according to optional module parameters */
306 if (fwlog_param) {
307 if (!strcmp(fwlog_param, "continuous")) {
308 wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS;
309 } else if (!strcmp(fwlog_param, "ondemand")) {
310 wl->conf.fwlog.mode = WL12XX_FWLOG_ON_DEMAND;
311 } else if (!strcmp(fwlog_param, "dbgpins")) {
312 wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS;
313 wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_DBG_PINS;
314 } else if (!strcmp(fwlog_param, "disable")) {
315 wl->conf.fwlog.mem_blocks = 0;
316 wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_NONE;
317 } else {
318 wl1271_error("Unknown fwlog parameter %s", fwlog_param);
319 }
320 }
321}
322
323static int wl1271_plt_init(struct wl1271 *wl)
324{
325 int ret;
326
327 ret = wl->ops->hw_init(wl);
328 if (ret < 0)
329 return ret;
330
331 ret = wl1271_acx_init_mem_config(wl);
332 if (ret < 0)
333 return ret;
334
335 ret = wl12xx_acx_mem_cfg(wl);
336 if (ret < 0)
337 goto out_free_memmap;
338
339 /* Enable data path */
340 ret = wl1271_cmd_data_path(wl, 1);
341 if (ret < 0)
342 goto out_free_memmap;
343
344 /* Configure for CAM power saving (ie. always active) */
345 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
346 if (ret < 0)
347 goto out_free_memmap;
348
349 /* configure PM */
350 ret = wl1271_acx_pm_config(wl);
351 if (ret < 0)
352 goto out_free_memmap;
353
354 return 0;
355
356 out_free_memmap:
357 kfree(wl->target_mem_map);
358 wl->target_mem_map = NULL;
359
360 return ret;
361}
362
363static void wl12xx_irq_ps_regulate_link(struct wl1271 *wl,
364 struct wl12xx_vif *wlvif,
365 u8 hlid, u8 tx_pkts)
366{
367 bool fw_ps, single_sta;
368
369 fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
370 single_sta = (wl->active_sta_count == 1);
371
372 /*
373 * Wake up from high level PS if the STA is asleep with too little
374 * packets in FW or if the STA is awake.
375 */
376 if (!fw_ps || tx_pkts < WL1271_PS_STA_MAX_PACKETS)
377 wl12xx_ps_link_end(wl, wlvif, hlid);
378
379 /*
380 * Start high-level PS if the STA is asleep with enough blocks in FW.
381 * Make an exception if this is the only connected station. In this
382 * case FW-memory congestion is not a problem.
383 */
384 else if (!single_sta && fw_ps && tx_pkts >= WL1271_PS_STA_MAX_PACKETS)
385 wl12xx_ps_link_start(wl, wlvif, hlid, true);
386}
387
388static void wl12xx_irq_update_links_status(struct wl1271 *wl,
389 struct wl12xx_vif *wlvif,
390 struct wl_fw_status *status)
391{
392 struct wl1271_link *lnk;
393 u32 cur_fw_ps_map;
394 u8 hlid, cnt;
395
396 /* TODO: also use link_fast_bitmap here */
397
398 cur_fw_ps_map = le32_to_cpu(status->link_ps_bitmap);
399 if (wl->ap_fw_ps_map != cur_fw_ps_map) {
400 wl1271_debug(DEBUG_PSM,
401 "link ps prev 0x%x cur 0x%x changed 0x%x",
402 wl->ap_fw_ps_map, cur_fw_ps_map,
403 wl->ap_fw_ps_map ^ cur_fw_ps_map);
404
405 wl->ap_fw_ps_map = cur_fw_ps_map;
406 }
407
408 for_each_set_bit(hlid, wlvif->ap.sta_hlid_map, WL12XX_MAX_LINKS) {
409 lnk = &wl->links[hlid];
410 cnt = status->counters.tx_lnk_free_pkts[hlid] -
411 lnk->prev_freed_pkts;
412
413 lnk->prev_freed_pkts = status->counters.tx_lnk_free_pkts[hlid];
414 lnk->allocated_pkts -= cnt;
415
416 wl12xx_irq_ps_regulate_link(wl, wlvif, hlid,
417 lnk->allocated_pkts);
418 }
419}
420
421static void wl12xx_fw_status(struct wl1271 *wl,
422 struct wl_fw_status *status)
423{
424 struct wl12xx_vif *wlvif;
425 struct timespec ts;
426 u32 old_tx_blk_count = wl->tx_blocks_available;
427 int avail, freed_blocks;
428 int i;
429 size_t status_len;
430
431 status_len = sizeof(*status) + wl->fw_status_priv_len;
432
433 wlcore_raw_read_data(wl, REG_RAW_FW_STATUS_ADDR, status,
434 status_len, false);
435
436 wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, "
437 "drv_rx_counter = %d, tx_results_counter = %d)",
438 status->intr,
439 status->fw_rx_counter,
440 status->drv_rx_counter,
441 status->tx_results_counter);
442
443 for (i = 0; i < NUM_TX_QUEUES; i++) {
444 /* prevent wrap-around in freed-packets counter */
445 wl->tx_allocated_pkts[i] -=
446 (status->counters.tx_released_pkts[i] -
447 wl->tx_pkts_freed[i]) & 0xff;
448
449 wl->tx_pkts_freed[i] = status->counters.tx_released_pkts[i];
450 }
451
452 /* prevent wrap-around in total blocks counter */
453 if (likely(wl->tx_blocks_freed <=
454 le32_to_cpu(status->total_released_blks)))
455 freed_blocks = le32_to_cpu(status->total_released_blks) -
456 wl->tx_blocks_freed;
457 else
458 freed_blocks = 0x100000000LL - wl->tx_blocks_freed +
459 le32_to_cpu(status->total_released_blks);
460
461 wl->tx_blocks_freed = le32_to_cpu(status->total_released_blks);
462
463 wl->tx_allocated_blocks -= freed_blocks;
464
465 /*
466 * If the FW freed some blocks:
467 * If we still have allocated blocks - re-arm the timer, Tx is
468 * not stuck. Otherwise, cancel the timer (no Tx currently).
469 */
470 if (freed_blocks) {
471 if (wl->tx_allocated_blocks)
472 wl12xx_rearm_tx_watchdog_locked(wl);
473 else
474 cancel_delayed_work(&wl->tx_watchdog_work);
475 }
476
477 avail = le32_to_cpu(status->tx_total) - wl->tx_allocated_blocks;
478
479 /*
480 * The FW might change the total number of TX memblocks before
481 * we get a notification about blocks being released. Thus, the
482 * available blocks calculation might yield a temporary result
483 * which is lower than the actual available blocks. Keeping in
484 * mind that only blocks that were allocated can be moved from
485 * TX to RX, tx_blocks_available should never decrease here.
486 */
487 wl->tx_blocks_available = max((int)wl->tx_blocks_available,
488 avail);
489
490 /* if more blocks are available now, tx work can be scheduled */
491 if (wl->tx_blocks_available > old_tx_blk_count)
492 clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
493
494 /* for AP update num of allocated TX blocks per link and ps status */
495 wl12xx_for_each_wlvif_ap(wl, wlvif) {
496 wl12xx_irq_update_links_status(wl, wlvif, status);
497 }
498
499 /* update the host-chipset time offset */
500 getnstimeofday(&ts);
501 wl->time_offset = (timespec_to_ns(&ts) >> 10) -
502 (s64)le32_to_cpu(status->fw_localtime);
503}
504
505static void wl1271_flush_deferred_work(struct wl1271 *wl)
506{
507 struct sk_buff *skb;
508
509 /* Pass all received frames to the network stack */
510 while ((skb = skb_dequeue(&wl->deferred_rx_queue)))
511 ieee80211_rx_ni(wl->hw, skb);
512
513 /* Return sent skbs to the network stack */
514 while ((skb = skb_dequeue(&wl->deferred_tx_queue)))
515 ieee80211_tx_status_ni(wl->hw, skb);
516}
517
518static void wl1271_netstack_work(struct work_struct *work)
519{
520 struct wl1271 *wl =
521 container_of(work, struct wl1271, netstack_work);
522
523 do {
524 wl1271_flush_deferred_work(wl);
525 } while (skb_queue_len(&wl->deferred_rx_queue));
526}
527
528#define WL1271_IRQ_MAX_LOOPS 256
529
530static irqreturn_t wl1271_irq(int irq, void *cookie)
531{
532 int ret;
533 u32 intr;
534 int loopcount = WL1271_IRQ_MAX_LOOPS;
535 struct wl1271 *wl = (struct wl1271 *)cookie;
536 bool done = false;
537 unsigned int defer_count;
538 unsigned long flags;
539
540 /* TX might be handled here, avoid redundant work */
541 set_bit(WL1271_FLAG_TX_PENDING, &wl->flags);
542 cancel_work_sync(&wl->tx_work);
543
544 /*
545 * In case edge triggered interrupt must be used, we cannot iterate
546 * more than once without introducing race conditions with the hardirq.
547 */
548 if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
549 loopcount = 1;
550
551 mutex_lock(&wl->mutex);
552
553 wl1271_debug(DEBUG_IRQ, "IRQ work");
554
555 if (unlikely(wl->state == WL1271_STATE_OFF))
556 goto out;
557
558 ret = wl1271_ps_elp_wakeup(wl);
559 if (ret < 0)
560 goto out;
561
562 while (!done && loopcount--) {
563 /*
564 * In order to avoid a race with the hardirq, clear the flag
565 * before acknowledging the chip. Since the mutex is held,
566 * wl1271_ps_elp_wakeup cannot be called concurrently.
567 */
568 clear_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
569 smp_mb__after_clear_bit();
570
571 wl12xx_fw_status(wl, wl->fw_status);
572
573 wlcore_hw_tx_immediate_compl(wl);
574
575 intr = le32_to_cpu(wl->fw_status->intr);
576 intr &= WL1271_INTR_MASK;
577 if (!intr) {
578 done = true;
579 continue;
580 }
581
582 if (unlikely(intr & WL1271_ACX_INTR_WATCHDOG)) {
583 wl1271_error("watchdog interrupt received! "
584 "starting recovery.");
585 wl12xx_queue_recovery_work(wl);
586
587 /* restarting the chip. ignore any other interrupt. */
588 goto out;
589 }
590
591 if (likely(intr & WL1271_ACX_INTR_DATA)) {
592 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA");
593
594 wl12xx_rx(wl, wl->fw_status);
595
596 /* Check if any tx blocks were freed */
597 spin_lock_irqsave(&wl->wl_lock, flags);
598 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
599 wl1271_tx_total_queue_count(wl) > 0) {
600 spin_unlock_irqrestore(&wl->wl_lock, flags);
601 /*
602 * In order to avoid starvation of the TX path,
603 * call the work function directly.
604 */
605 wl1271_tx_work_locked(wl);
606 } else {
607 spin_unlock_irqrestore(&wl->wl_lock, flags);
608 }
609
610 /* check for tx results */
611 wlcore_hw_tx_delayed_compl(wl);
612
613 /* Make sure the deferred queues don't get too long */
614 defer_count = skb_queue_len(&wl->deferred_tx_queue) +
615 skb_queue_len(&wl->deferred_rx_queue);
616 if (defer_count > WL1271_DEFERRED_QUEUE_LIMIT)
617 wl1271_flush_deferred_work(wl);
618 }
619
620 if (intr & WL1271_ACX_INTR_EVENT_A) {
621 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_A");
622 wl1271_event_handle(wl, 0);
623 }
624
625 if (intr & WL1271_ACX_INTR_EVENT_B) {
626 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_B");
627 wl1271_event_handle(wl, 1);
628 }
629
630 if (intr & WL1271_ACX_INTR_INIT_COMPLETE)
631 wl1271_debug(DEBUG_IRQ,
632 "WL1271_ACX_INTR_INIT_COMPLETE");
633
634 if (intr & WL1271_ACX_INTR_HW_AVAILABLE)
635 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE");
636 }
637
638 wl1271_ps_elp_sleep(wl);
639
640out:
641 spin_lock_irqsave(&wl->wl_lock, flags);
642 /* In case TX was not handled here, queue TX work */
643 clear_bit(WL1271_FLAG_TX_PENDING, &wl->flags);
644 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
645 wl1271_tx_total_queue_count(wl) > 0)
646 ieee80211_queue_work(wl->hw, &wl->tx_work);
647 spin_unlock_irqrestore(&wl->wl_lock, flags);
648
649 mutex_unlock(&wl->mutex);
650
651 return IRQ_HANDLED;
652}
653
654struct vif_counter_data {
655 u8 counter;
656
657 struct ieee80211_vif *cur_vif;
658 bool cur_vif_running;
659};
660
661static void wl12xx_vif_count_iter(void *data, u8 *mac,
662 struct ieee80211_vif *vif)
663{
664 struct vif_counter_data *counter = data;
665
666 counter->counter++;
667 if (counter->cur_vif == vif)
668 counter->cur_vif_running = true;
669}
670
671/* caller must not hold wl->mutex, as it might deadlock */
672static void wl12xx_get_vif_count(struct ieee80211_hw *hw,
673 struct ieee80211_vif *cur_vif,
674 struct vif_counter_data *data)
675{
676 memset(data, 0, sizeof(*data));
677 data->cur_vif = cur_vif;
678
679 ieee80211_iterate_active_interfaces(hw,
680 wl12xx_vif_count_iter, data);
681}
682
683static int wl12xx_fetch_firmware(struct wl1271 *wl, bool plt)
684{
685 const struct firmware *fw;
686 const char *fw_name;
687 enum wl12xx_fw_type fw_type;
688 int ret;
689
690 if (plt) {
691 fw_type = WL12XX_FW_TYPE_PLT;
692 fw_name = wl->plt_fw_name;
693 } else {
694 /*
695 * we can't call wl12xx_get_vif_count() here because
696 * wl->mutex is taken, so use the cached last_vif_count value
697 */
698 if (wl->last_vif_count > 1) {
699 fw_type = WL12XX_FW_TYPE_MULTI;
700 fw_name = wl->mr_fw_name;
701 } else {
702 fw_type = WL12XX_FW_TYPE_NORMAL;
703 fw_name = wl->sr_fw_name;
704 }
705 }
706
707 if (wl->fw_type == fw_type)
708 return 0;
709
710 wl1271_debug(DEBUG_BOOT, "booting firmware %s", fw_name);
711
712 ret = request_firmware(&fw, fw_name, wl->dev);
713
714 if (ret < 0) {
715 wl1271_error("could not get firmware %s: %d", fw_name, ret);
716 return ret;
717 }
718
719 if (fw->size % 4) {
720 wl1271_error("firmware size is not multiple of 32 bits: %zu",
721 fw->size);
722 ret = -EILSEQ;
723 goto out;
724 }
725
726 vfree(wl->fw);
727 wl->fw_type = WL12XX_FW_TYPE_NONE;
728 wl->fw_len = fw->size;
729 wl->fw = vmalloc(wl->fw_len);
730
731 if (!wl->fw) {
732 wl1271_error("could not allocate memory for the firmware");
733 ret = -ENOMEM;
734 goto out;
735 }
736
737 memcpy(wl->fw, fw->data, wl->fw_len);
738 ret = 0;
739 wl->fw_type = fw_type;
740out:
741 release_firmware(fw);
742
743 return ret;
744}
745
746static int wl1271_fetch_nvs(struct wl1271 *wl)
747{
748 const struct firmware *fw;
749 int ret;
750
751 ret = request_firmware(&fw, WL12XX_NVS_NAME, wl->dev);
752
753 if (ret < 0) {
754 wl1271_error("could not get nvs file %s: %d", WL12XX_NVS_NAME,
755 ret);
756 return ret;
757 }
758
759 wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL);
760
761 if (!wl->nvs) {
762 wl1271_error("could not allocate memory for the nvs file");
763 ret = -ENOMEM;
764 goto out;
765 }
766
767 wl->nvs_len = fw->size;
768
769out:
770 release_firmware(fw);
771
772 return ret;
773}
774
775void wl12xx_queue_recovery_work(struct wl1271 *wl)
776{
777 if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags))
778 ieee80211_queue_work(wl->hw, &wl->recovery_work);
779}
780
781size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen)
782{
783 size_t len = 0;
784
785 /* The FW log is a length-value list, find where the log end */
786 while (len < maxlen) {
787 if (memblock[len] == 0)
788 break;
789 if (len + memblock[len] + 1 > maxlen)
790 break;
791 len += memblock[len] + 1;
792 }
793
794 /* Make sure we have enough room */
795 len = min(len, (size_t)(PAGE_SIZE - wl->fwlog_size));
796
797 /* Fill the FW log file, consumed by the sysfs fwlog entry */
798 memcpy(wl->fwlog + wl->fwlog_size, memblock, len);
799 wl->fwlog_size += len;
800
801 return len;
802}
803
804static void wl12xx_read_fwlog_panic(struct wl1271 *wl)
805{
806 u32 addr;
807 u32 first_addr;
808 u8 *block;
809
810 if ((wl->quirks & WLCORE_QUIRK_FWLOG_NOT_IMPLEMENTED) ||
811 (wl->conf.fwlog.mode != WL12XX_FWLOG_ON_DEMAND) ||
812 (wl->conf.fwlog.mem_blocks == 0))
813 return;
814
815 wl1271_info("Reading FW panic log");
816
817 block = kmalloc(WL12XX_HW_BLOCK_SIZE, GFP_KERNEL);
818 if (!block)
819 return;
820
821 /*
822 * Make sure the chip is awake and the logger isn't active.
823 * This might fail if the firmware hanged.
824 */
825 if (!wl1271_ps_elp_wakeup(wl))
826 wl12xx_cmd_stop_fwlog(wl);
827
828 /* Read the first memory block address */
829 wl12xx_fw_status(wl, wl->fw_status);
830 first_addr = le32_to_cpu(wl->fw_status->log_start_addr);
831 if (!first_addr)
832 goto out;
833
834 /* Traverse the memory blocks linked list */
835 addr = first_addr;
836 do {
837 memset(block, 0, WL12XX_HW_BLOCK_SIZE);
838 wl1271_read_hwaddr(wl, addr, block, WL12XX_HW_BLOCK_SIZE,
839 false);
840
841 /*
842 * Memory blocks are linked to one another. The first 4 bytes
843 * of each memory block hold the hardware address of the next
844 * one. The last memory block points to the first one.
845 */
846 addr = le32_to_cpup((__le32 *)block);
847 if (!wl12xx_copy_fwlog(wl, block + sizeof(addr),
848 WL12XX_HW_BLOCK_SIZE - sizeof(addr)))
849 break;
850 } while (addr && (addr != first_addr));
851
852 wake_up_interruptible(&wl->fwlog_waitq);
853
854out:
855 kfree(block);
856}
857
858static void wl1271_recovery_work(struct work_struct *work)
859{
860 struct wl1271 *wl =
861 container_of(work, struct wl1271, recovery_work);
862 struct wl12xx_vif *wlvif;
863 struct ieee80211_vif *vif;
864
865 mutex_lock(&wl->mutex);
866
867 if (wl->state != WL1271_STATE_ON || wl->plt)
868 goto out_unlock;
869
870 /* Avoid a recursive recovery */
871 set_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags);
872
873 wl12xx_read_fwlog_panic(wl);
874
875 wl1271_info("Hardware recovery in progress. FW ver: %s pc: 0x%x",
876 wl->chip.fw_ver_str,
877 wlcore_read_reg(wl, REG_PC_ON_RECOVERY));
878
879 BUG_ON(bug_on_recovery &&
880 !test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags));
881
882 if (no_recovery) {
883 wl1271_info("No recovery (chosen on module load). Fw will remain stuck.");
884 clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags);
885 goto out_unlock;
886 }
887
888 BUG_ON(bug_on_recovery);
889
890 /*
891 * Advance security sequence number to overcome potential progress
892 * in the firmware during recovery. This doens't hurt if the network is
893 * not encrypted.
894 */
895 wl12xx_for_each_wlvif(wl, wlvif) {
896 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) ||
897 test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
898 wlvif->tx_security_seq +=
899 WL1271_TX_SQN_POST_RECOVERY_PADDING;
900 }
901
902 /* Prevent spurious TX during FW restart */
903 ieee80211_stop_queues(wl->hw);
904
905 if (wl->sched_scanning) {
906 ieee80211_sched_scan_stopped(wl->hw);
907 wl->sched_scanning = false;
908 }
909
910 /* reboot the chipset */
911 while (!list_empty(&wl->wlvif_list)) {
912 wlvif = list_first_entry(&wl->wlvif_list,
913 struct wl12xx_vif, list);
914 vif = wl12xx_wlvif_to_vif(wlvif);
915 __wl1271_op_remove_interface(wl, vif, false);
916 }
917 mutex_unlock(&wl->mutex);
918 wl1271_op_stop(wl->hw);
919
920 clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags);
921
922 ieee80211_restart_hw(wl->hw);
923
924 /*
925 * Its safe to enable TX now - the queues are stopped after a request
926 * to restart the HW.
927 */
928 ieee80211_wake_queues(wl->hw);
929 return;
930out_unlock:
931 mutex_unlock(&wl->mutex);
932}
933
934static void wl1271_fw_wakeup(struct wl1271 *wl)
935{
936 wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG, ELPCTRL_WAKE_UP);
937}
938
939static int wl1271_setup(struct wl1271 *wl)
940{
941 wl->fw_status = kmalloc(sizeof(*wl->fw_status), GFP_KERNEL);
942 if (!wl->fw_status)
943 return -ENOMEM;
944
945 wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL);
946 if (!wl->tx_res_if) {
947 kfree(wl->fw_status);
948 return -ENOMEM;
949 }
950
951 return 0;
952}
953
954static int wl12xx_set_power_on(struct wl1271 *wl)
955{
956 int ret;
957
958 msleep(WL1271_PRE_POWER_ON_SLEEP);
959 ret = wl1271_power_on(wl);
960 if (ret < 0)
961 goto out;
962 msleep(WL1271_POWER_ON_SLEEP);
963 wl1271_io_reset(wl);
964 wl1271_io_init(wl);
965
966 wlcore_set_partition(wl, &wl->ptable[PART_BOOT]);
967
968 /* ELP module wake up */
969 wl1271_fw_wakeup(wl);
970
971out:
972 return ret;
973}
974
975static int wl12xx_chip_wakeup(struct wl1271 *wl, bool plt)
976{
977 int ret = 0;
978
979 ret = wl12xx_set_power_on(wl);
980 if (ret < 0)
981 goto out;
982
983 /*
984 * For wl127x based devices we could use the default block
985 * size (512 bytes), but due to a bug in the sdio driver, we
986 * need to set it explicitly after the chip is powered on. To
987 * simplify the code and since the performance impact is
988 * negligible, we use the same block size for all different
989 * chip types.
990 */
991 if (wl1271_set_block_size(wl))
992 wl->quirks |= WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN;
993
994 ret = wl->ops->identify_chip(wl);
995 if (ret < 0)
996 goto out;
997
998 /* TODO: make sure the lower driver has set things up correctly */
999
1000 ret = wl1271_setup(wl);
1001 if (ret < 0)
1002 goto out;
1003
1004 ret = wl12xx_fetch_firmware(wl, plt);
1005 if (ret < 0)
1006 goto out;
1007
1008 /* No NVS from netlink, try to get it from the filesystem */
1009 if (wl->nvs == NULL) {
1010 ret = wl1271_fetch_nvs(wl);
1011 if (ret < 0)
1012 goto out;
1013 }
1014
1015out:
1016 return ret;
1017}
1018
1019int wl1271_plt_start(struct wl1271 *wl)
1020{
1021 int retries = WL1271_BOOT_RETRIES;
1022 struct wiphy *wiphy = wl->hw->wiphy;
1023 int ret;
1024
1025 mutex_lock(&wl->mutex);
1026
1027 wl1271_notice("power up");
1028
1029 if (wl->state != WL1271_STATE_OFF) {
1030 wl1271_error("cannot go into PLT state because not "
1031 "in off state: %d", wl->state);
1032 ret = -EBUSY;
1033 goto out;
1034 }
1035
1036 while (retries) {
1037 retries--;
1038 ret = wl12xx_chip_wakeup(wl, true);
1039 if (ret < 0)
1040 goto power_off;
1041
1042 ret = wl->ops->boot(wl);
1043 if (ret < 0)
1044 goto power_off;
1045
1046 ret = wl1271_plt_init(wl);
1047 if (ret < 0)
1048 goto irq_disable;
1049
1050 wl->plt = true;
1051 wl->state = WL1271_STATE_ON;
1052 wl1271_notice("firmware booted in PLT mode (%s)",
1053 wl->chip.fw_ver_str);
1054
1055 /* update hw/fw version info in wiphy struct */
1056 wiphy->hw_version = wl->chip.id;
1057 strncpy(wiphy->fw_version, wl->chip.fw_ver_str,
1058 sizeof(wiphy->fw_version));
1059
1060 goto out;
1061
1062irq_disable:
1063 mutex_unlock(&wl->mutex);
1064 /* Unlocking the mutex in the middle of handling is
1065 inherently unsafe. In this case we deem it safe to do,
1066 because we need to let any possibly pending IRQ out of
1067 the system (and while we are WL1271_STATE_OFF the IRQ
1068 work function will not do anything.) Also, any other
1069 possible concurrent operations will fail due to the
1070 current state, hence the wl1271 struct should be safe. */
1071 wlcore_disable_interrupts(wl);
1072 wl1271_flush_deferred_work(wl);
1073 cancel_work_sync(&wl->netstack_work);
1074 mutex_lock(&wl->mutex);
1075power_off:
1076 wl1271_power_off(wl);
1077 }
1078
1079 wl1271_error("firmware boot in PLT mode failed despite %d retries",
1080 WL1271_BOOT_RETRIES);
1081out:
1082 mutex_unlock(&wl->mutex);
1083
1084 return ret;
1085}
1086
1087int wl1271_plt_stop(struct wl1271 *wl)
1088{
1089 int ret = 0;
1090
1091 wl1271_notice("power down");
1092
1093 /*
1094 * Interrupts must be disabled before setting the state to OFF.
1095 * Otherwise, the interrupt handler might be called and exit without
1096 * reading the interrupt status.
1097 */
1098 wlcore_disable_interrupts(wl);
1099 mutex_lock(&wl->mutex);
1100 if (!wl->plt) {
1101 mutex_unlock(&wl->mutex);
1102
1103 /*
1104 * This will not necessarily enable interrupts as interrupts
1105 * may have been disabled when op_stop was called. It will,
1106 * however, balance the above call to disable_interrupts().
1107 */
1108 wlcore_enable_interrupts(wl);
1109
1110 wl1271_error("cannot power down because not in PLT "
1111 "state: %d", wl->state);
1112 ret = -EBUSY;
1113 goto out;
1114 }
1115
1116 mutex_unlock(&wl->mutex);
1117
1118 wl1271_flush_deferred_work(wl);
1119 cancel_work_sync(&wl->netstack_work);
1120 cancel_work_sync(&wl->recovery_work);
1121 cancel_delayed_work_sync(&wl->elp_work);
1122 cancel_delayed_work_sync(&wl->tx_watchdog_work);
1123
1124 mutex_lock(&wl->mutex);
1125 wl1271_power_off(wl);
1126 wl->flags = 0;
1127 wl->state = WL1271_STATE_OFF;
1128 wl->plt = false;
1129 wl->rx_counter = 0;
1130 mutex_unlock(&wl->mutex);
1131
1132out:
1133 return ret;
1134}
1135
1136static void wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1137{
1138 struct wl1271 *wl = hw->priv;
1139 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1140 struct ieee80211_vif *vif = info->control.vif;
1141 struct wl12xx_vif *wlvif = NULL;
1142 unsigned long flags;
1143 int q, mapping;
1144 u8 hlid;
1145
1146 if (vif)
1147 wlvif = wl12xx_vif_to_data(vif);
1148
1149 mapping = skb_get_queue_mapping(skb);
1150 q = wl1271_tx_get_queue(mapping);
1151
1152 hlid = wl12xx_tx_get_hlid(wl, wlvif, skb);
1153
1154 spin_lock_irqsave(&wl->wl_lock, flags);
1155
1156 /* queue the packet */
1157 if (hlid == WL12XX_INVALID_LINK_ID ||
1158 (wlvif && !test_bit(hlid, wlvif->links_map))) {
1159 wl1271_debug(DEBUG_TX, "DROP skb hlid %d q %d", hlid, q);
1160 ieee80211_free_txskb(hw, skb);
1161 goto out;
1162 }
1163
1164 wl1271_debug(DEBUG_TX, "queue skb hlid %d q %d len %d",
1165 hlid, q, skb->len);
1166 skb_queue_tail(&wl->links[hlid].tx_queue[q], skb);
1167
1168 wl->tx_queue_count[q]++;
1169
1170 /*
1171 * The workqueue is slow to process the tx_queue and we need stop
1172 * the queue here, otherwise the queue will get too long.
1173 */
1174 if (wl->tx_queue_count[q] >= WL1271_TX_QUEUE_HIGH_WATERMARK) {
1175 wl1271_debug(DEBUG_TX, "op_tx: stopping queues for q %d", q);
1176 ieee80211_stop_queue(wl->hw, mapping);
1177 set_bit(q, &wl->stopped_queues_map);
1178 }
1179
1180 /*
1181 * The chip specific setup must run before the first TX packet -
1182 * before that, the tx_work will not be initialized!
1183 */
1184
1185 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
1186 !test_bit(WL1271_FLAG_TX_PENDING, &wl->flags))
1187 ieee80211_queue_work(wl->hw, &wl->tx_work);
1188
1189out:
1190 spin_unlock_irqrestore(&wl->wl_lock, flags);
1191}
1192
1193int wl1271_tx_dummy_packet(struct wl1271 *wl)
1194{
1195 unsigned long flags;
1196 int q;
1197
1198 /* no need to queue a new dummy packet if one is already pending */
1199 if (test_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags))
1200 return 0;
1201
1202 q = wl1271_tx_get_queue(skb_get_queue_mapping(wl->dummy_packet));
1203
1204 spin_lock_irqsave(&wl->wl_lock, flags);
1205 set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags);
1206 wl->tx_queue_count[q]++;
1207 spin_unlock_irqrestore(&wl->wl_lock, flags);
1208
1209 /* The FW is low on RX memory blocks, so send the dummy packet asap */
1210 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags))
1211 wl1271_tx_work_locked(wl);
1212
1213 /*
1214 * If the FW TX is busy, TX work will be scheduled by the threaded
1215 * interrupt handler function
1216 */
1217 return 0;
1218}
1219
1220/*
1221 * The size of the dummy packet should be at least 1400 bytes. However, in
1222 * order to minimize the number of bus transactions, aligning it to 512 bytes
1223 * boundaries could be beneficial, performance wise
1224 */
1225#define TOTAL_TX_DUMMY_PACKET_SIZE (ALIGN(1400, 512))
1226
1227static struct sk_buff *wl12xx_alloc_dummy_packet(struct wl1271 *wl)
1228{
1229 struct sk_buff *skb;
1230 struct ieee80211_hdr_3addr *hdr;
1231 unsigned int dummy_packet_size;
1232
1233 dummy_packet_size = TOTAL_TX_DUMMY_PACKET_SIZE -
1234 sizeof(struct wl1271_tx_hw_descr) - sizeof(*hdr);
1235
1236 skb = dev_alloc_skb(TOTAL_TX_DUMMY_PACKET_SIZE);
1237 if (!skb) {
1238 wl1271_warning("Failed to allocate a dummy packet skb");
1239 return NULL;
1240 }
1241
1242 skb_reserve(skb, sizeof(struct wl1271_tx_hw_descr));
1243
1244 hdr = (struct ieee80211_hdr_3addr *) skb_put(skb, sizeof(*hdr));
1245 memset(hdr, 0, sizeof(*hdr));
1246 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
1247 IEEE80211_STYPE_NULLFUNC |
1248 IEEE80211_FCTL_TODS);
1249
1250 memset(skb_put(skb, dummy_packet_size), 0, dummy_packet_size);
1251
1252 /* Dummy packets require the TID to be management */
1253 skb->priority = WL1271_TID_MGMT;
1254
1255 /* Initialize all fields that might be used */
1256 skb_set_queue_mapping(skb, 0);
1257 memset(IEEE80211_SKB_CB(skb), 0, sizeof(struct ieee80211_tx_info));
1258
1259 return skb;
1260}
1261
1262
1263#ifdef CONFIG_PM
1264static int wl1271_configure_suspend_sta(struct wl1271 *wl,
1265 struct wl12xx_vif *wlvif)
1266{
1267 int ret = 0;
1268
1269 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
1270 goto out;
1271
1272 ret = wl1271_ps_elp_wakeup(wl);
1273 if (ret < 0)
1274 goto out;
1275
1276 ret = wl1271_acx_wake_up_conditions(wl, wlvif,
1277 wl->conf.conn.suspend_wake_up_event,
1278 wl->conf.conn.suspend_listen_interval);
1279
1280 if (ret < 0)
1281 wl1271_error("suspend: set wake up conditions failed: %d", ret);
1282
1283 wl1271_ps_elp_sleep(wl);
1284
1285out:
1286 return ret;
1287
1288}
1289
1290static int wl1271_configure_suspend_ap(struct wl1271 *wl,
1291 struct wl12xx_vif *wlvif)
1292{
1293 int ret = 0;
1294
1295 if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
1296 goto out;
1297
1298 ret = wl1271_ps_elp_wakeup(wl);
1299 if (ret < 0)
1300 goto out;
1301
1302 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true);
1303
1304 wl1271_ps_elp_sleep(wl);
1305out:
1306 return ret;
1307
1308}
1309
1310static int wl1271_configure_suspend(struct wl1271 *wl,
1311 struct wl12xx_vif *wlvif)
1312{
1313 if (wlvif->bss_type == BSS_TYPE_STA_BSS)
1314 return wl1271_configure_suspend_sta(wl, wlvif);
1315 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
1316 return wl1271_configure_suspend_ap(wl, wlvif);
1317 return 0;
1318}
1319
1320static void wl1271_configure_resume(struct wl1271 *wl,
1321 struct wl12xx_vif *wlvif)
1322{
1323 int ret = 0;
1324 bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS;
1325 bool is_sta = wlvif->bss_type == BSS_TYPE_STA_BSS;
1326
1327 if ((!is_ap) && (!is_sta))
1328 return;
1329
1330 ret = wl1271_ps_elp_wakeup(wl);
1331 if (ret < 0)
1332 return;
1333
1334 if (is_sta) {
1335 ret = wl1271_acx_wake_up_conditions(wl, wlvif,
1336 wl->conf.conn.wake_up_event,
1337 wl->conf.conn.listen_interval);
1338
1339 if (ret < 0)
1340 wl1271_error("resume: wake up conditions failed: %d",
1341 ret);
1342
1343 } else if (is_ap) {
1344 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false);
1345 }
1346
1347 wl1271_ps_elp_sleep(wl);
1348}
1349
1350static int wl1271_op_suspend(struct ieee80211_hw *hw,
1351 struct cfg80211_wowlan *wow)
1352{
1353 struct wl1271 *wl = hw->priv;
1354 struct wl12xx_vif *wlvif;
1355 int ret;
1356
1357 wl1271_debug(DEBUG_MAC80211, "mac80211 suspend wow=%d", !!wow);
1358 WARN_ON(!wow || !wow->any);
1359
1360 wl1271_tx_flush(wl);
1361
1362 mutex_lock(&wl->mutex);
1363 wl->wow_enabled = true;
1364 wl12xx_for_each_wlvif(wl, wlvif) {
1365 ret = wl1271_configure_suspend(wl, wlvif);
1366 if (ret < 0) {
1367 wl1271_warning("couldn't prepare device to suspend");
1368 return ret;
1369 }
1370 }
1371 mutex_unlock(&wl->mutex);
1372 /* flush any remaining work */
1373 wl1271_debug(DEBUG_MAC80211, "flushing remaining works");
1374
1375 /*
1376 * disable and re-enable interrupts in order to flush
1377 * the threaded_irq
1378 */
1379 wlcore_disable_interrupts(wl);
1380
1381 /*
1382 * set suspended flag to avoid triggering a new threaded_irq
1383 * work. no need for spinlock as interrupts are disabled.
1384 */
1385 set_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
1386
1387 wlcore_enable_interrupts(wl);
1388 flush_work(&wl->tx_work);
1389 flush_delayed_work(&wl->elp_work);
1390
1391 return 0;
1392}
1393
1394static int wl1271_op_resume(struct ieee80211_hw *hw)
1395{
1396 struct wl1271 *wl = hw->priv;
1397 struct wl12xx_vif *wlvif;
1398 unsigned long flags;
1399 bool run_irq_work = false;
1400
1401 wl1271_debug(DEBUG_MAC80211, "mac80211 resume wow=%d",
1402 wl->wow_enabled);
1403 WARN_ON(!wl->wow_enabled);
1404
1405 /*
1406 * re-enable irq_work enqueuing, and call irq_work directly if
1407 * there is a pending work.
1408 */
1409 spin_lock_irqsave(&wl->wl_lock, flags);
1410 clear_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
1411 if (test_and_clear_bit(WL1271_FLAG_PENDING_WORK, &wl->flags))
1412 run_irq_work = true;
1413 spin_unlock_irqrestore(&wl->wl_lock, flags);
1414
1415 if (run_irq_work) {
1416 wl1271_debug(DEBUG_MAC80211,
1417 "run postponed irq_work directly");
1418 wl1271_irq(0, wl);
1419 wlcore_enable_interrupts(wl);
1420 }
1421
1422 mutex_lock(&wl->mutex);
1423 wl12xx_for_each_wlvif(wl, wlvif) {
1424 wl1271_configure_resume(wl, wlvif);
1425 }
1426 wl->wow_enabled = false;
1427 mutex_unlock(&wl->mutex);
1428
1429 return 0;
1430}
1431#endif
1432
1433static int wl1271_op_start(struct ieee80211_hw *hw)
1434{
1435 wl1271_debug(DEBUG_MAC80211, "mac80211 start");
1436
1437 /*
1438 * We have to delay the booting of the hardware because
1439 * we need to know the local MAC address before downloading and
1440 * initializing the firmware. The MAC address cannot be changed
1441 * after boot, and without the proper MAC address, the firmware
1442 * will not function properly.
1443 *
1444 * The MAC address is first known when the corresponding interface
1445 * is added. That is where we will initialize the hardware.
1446 */
1447
1448 return 0;
1449}
1450
1451static void wl1271_op_stop(struct ieee80211_hw *hw)
1452{
1453 struct wl1271 *wl = hw->priv;
1454 int i;
1455
1456 wl1271_debug(DEBUG_MAC80211, "mac80211 stop");
1457
1458 /*
1459 * Interrupts must be disabled before setting the state to OFF.
1460 * Otherwise, the interrupt handler might be called and exit without
1461 * reading the interrupt status.
1462 */
1463 wlcore_disable_interrupts(wl);
1464 mutex_lock(&wl->mutex);
1465 if (wl->state == WL1271_STATE_OFF) {
1466 mutex_unlock(&wl->mutex);
1467
1468 /*
1469 * This will not necessarily enable interrupts as interrupts
1470 * may have been disabled when op_stop was called. It will,
1471 * however, balance the above call to disable_interrupts().
1472 */
1473 wlcore_enable_interrupts(wl);
1474 return;
1475 }
1476
1477 /*
1478 * this must be before the cancel_work calls below, so that the work
1479 * functions don't perform further work.
1480 */
1481 wl->state = WL1271_STATE_OFF;
1482 mutex_unlock(&wl->mutex);
1483
1484 wl1271_flush_deferred_work(wl);
1485 cancel_delayed_work_sync(&wl->scan_complete_work);
1486 cancel_work_sync(&wl->netstack_work);
1487 cancel_work_sync(&wl->tx_work);
1488 cancel_delayed_work_sync(&wl->elp_work);
1489 cancel_delayed_work_sync(&wl->tx_watchdog_work);
1490
1491 /* let's notify MAC80211 about the remaining pending TX frames */
1492 wl12xx_tx_reset(wl, true);
1493 mutex_lock(&wl->mutex);
1494
1495 wl1271_power_off(wl);
1496
1497 wl->band = IEEE80211_BAND_2GHZ;
1498
1499 wl->rx_counter = 0;
1500 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
1501 wl->tx_blocks_available = 0;
1502 wl->tx_allocated_blocks = 0;
1503 wl->tx_results_count = 0;
1504 wl->tx_packets_count = 0;
1505 wl->time_offset = 0;
1506 wl->ap_fw_ps_map = 0;
1507 wl->ap_ps_map = 0;
1508 wl->sched_scanning = false;
1509 memset(wl->roles_map, 0, sizeof(wl->roles_map));
1510 memset(wl->links_map, 0, sizeof(wl->links_map));
1511 memset(wl->roc_map, 0, sizeof(wl->roc_map));
1512 wl->active_sta_count = 0;
1513
1514 /* The system link is always allocated */
1515 __set_bit(WL12XX_SYSTEM_HLID, wl->links_map);
1516
1517 /*
1518 * this is performed after the cancel_work calls and the associated
1519 * mutex_lock, so that wl1271_op_add_interface does not accidentally
1520 * get executed before all these vars have been reset.
1521 */
1522 wl->flags = 0;
1523
1524 wl->tx_blocks_freed = 0;
1525
1526 for (i = 0; i < NUM_TX_QUEUES; i++) {
1527 wl->tx_pkts_freed[i] = 0;
1528 wl->tx_allocated_pkts[i] = 0;
1529 }
1530
1531 wl1271_debugfs_reset(wl);
1532
1533 kfree(wl->fw_status);
1534 wl->fw_status = NULL;
1535 kfree(wl->tx_res_if);
1536 wl->tx_res_if = NULL;
1537 kfree(wl->target_mem_map);
1538 wl->target_mem_map = NULL;
1539
1540 mutex_unlock(&wl->mutex);
1541}
1542
1543static int wl12xx_allocate_rate_policy(struct wl1271 *wl, u8 *idx)
1544{
1545 u8 policy = find_first_zero_bit(wl->rate_policies_map,
1546 WL12XX_MAX_RATE_POLICIES);
1547 if (policy >= WL12XX_MAX_RATE_POLICIES)
1548 return -EBUSY;
1549
1550 __set_bit(policy, wl->rate_policies_map);
1551 *idx = policy;
1552 return 0;
1553}
1554
1555static void wl12xx_free_rate_policy(struct wl1271 *wl, u8 *idx)
1556{
1557 if (WARN_ON(*idx >= WL12XX_MAX_RATE_POLICIES))
1558 return;
1559
1560 __clear_bit(*idx, wl->rate_policies_map);
1561 *idx = WL12XX_MAX_RATE_POLICIES;
1562}
1563
1564static u8 wl12xx_get_role_type(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1565{
1566 switch (wlvif->bss_type) {
1567 case BSS_TYPE_AP_BSS:
1568 if (wlvif->p2p)
1569 return WL1271_ROLE_P2P_GO;
1570 else
1571 return WL1271_ROLE_AP;
1572
1573 case BSS_TYPE_STA_BSS:
1574 if (wlvif->p2p)
1575 return WL1271_ROLE_P2P_CL;
1576 else
1577 return WL1271_ROLE_STA;
1578
1579 case BSS_TYPE_IBSS:
1580 return WL1271_ROLE_IBSS;
1581
1582 default:
1583 wl1271_error("invalid bss_type: %d", wlvif->bss_type);
1584 }
1585 return WL12XX_INVALID_ROLE_TYPE;
1586}
1587
1588static int wl12xx_init_vif_data(struct wl1271 *wl, struct ieee80211_vif *vif)
1589{
1590 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
1591 int i;
1592
1593 /* clear everything but the persistent data */
1594 memset(wlvif, 0, offsetof(struct wl12xx_vif, persistent));
1595
1596 switch (ieee80211_vif_type_p2p(vif)) {
1597 case NL80211_IFTYPE_P2P_CLIENT:
1598 wlvif->p2p = 1;
1599 /* fall-through */
1600 case NL80211_IFTYPE_STATION:
1601 wlvif->bss_type = BSS_TYPE_STA_BSS;
1602 break;
1603 case NL80211_IFTYPE_ADHOC:
1604 wlvif->bss_type = BSS_TYPE_IBSS;
1605 break;
1606 case NL80211_IFTYPE_P2P_GO:
1607 wlvif->p2p = 1;
1608 /* fall-through */
1609 case NL80211_IFTYPE_AP:
1610 wlvif->bss_type = BSS_TYPE_AP_BSS;
1611 break;
1612 default:
1613 wlvif->bss_type = MAX_BSS_TYPE;
1614 return -EOPNOTSUPP;
1615 }
1616
1617 wlvif->role_id = WL12XX_INVALID_ROLE_ID;
1618 wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID;
1619 wlvif->dev_hlid = WL12XX_INVALID_LINK_ID;
1620
1621 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
1622 wlvif->bss_type == BSS_TYPE_IBSS) {
1623 /* init sta/ibss data */
1624 wlvif->sta.hlid = WL12XX_INVALID_LINK_ID;
1625 wl12xx_allocate_rate_policy(wl, &wlvif->sta.basic_rate_idx);
1626 wl12xx_allocate_rate_policy(wl, &wlvif->sta.ap_rate_idx);
1627 wl12xx_allocate_rate_policy(wl, &wlvif->sta.p2p_rate_idx);
1628 } else {
1629 /* init ap data */
1630 wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID;
1631 wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID;
1632 wl12xx_allocate_rate_policy(wl, &wlvif->ap.mgmt_rate_idx);
1633 wl12xx_allocate_rate_policy(wl, &wlvif->ap.bcast_rate_idx);
1634 for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++)
1635 wl12xx_allocate_rate_policy(wl,
1636 &wlvif->ap.ucast_rate_idx[i]);
1637 }
1638
1639 wlvif->bitrate_masks[IEEE80211_BAND_2GHZ] = wl->conf.tx.basic_rate;
1640 wlvif->bitrate_masks[IEEE80211_BAND_5GHZ] = wl->conf.tx.basic_rate_5;
1641 wlvif->basic_rate_set = CONF_TX_RATE_MASK_BASIC;
1642 wlvif->basic_rate = CONF_TX_RATE_MASK_BASIC;
1643 wlvif->rate_set = CONF_TX_RATE_MASK_BASIC;
1644 wlvif->beacon_int = WL1271_DEFAULT_BEACON_INT;
1645
1646 /*
1647 * mac80211 configures some values globally, while we treat them
1648 * per-interface. thus, on init, we have to copy them from wl
1649 */
1650 wlvif->band = wl->band;
1651 wlvif->channel = wl->channel;
1652 wlvif->power_level = wl->power_level;
1653
1654 INIT_WORK(&wlvif->rx_streaming_enable_work,
1655 wl1271_rx_streaming_enable_work);
1656 INIT_WORK(&wlvif->rx_streaming_disable_work,
1657 wl1271_rx_streaming_disable_work);
1658 INIT_LIST_HEAD(&wlvif->list);
1659
1660 setup_timer(&wlvif->rx_streaming_timer, wl1271_rx_streaming_timer,
1661 (unsigned long) wlvif);
1662 return 0;
1663}
1664
1665static bool wl12xx_init_fw(struct wl1271 *wl)
1666{
1667 int retries = WL1271_BOOT_RETRIES;
1668 bool booted = false;
1669 struct wiphy *wiphy = wl->hw->wiphy;
1670 int ret;
1671
1672 while (retries) {
1673 retries--;
1674 ret = wl12xx_chip_wakeup(wl, false);
1675 if (ret < 0)
1676 goto power_off;
1677
1678 ret = wl->ops->boot(wl);
1679 if (ret < 0)
1680 goto power_off;
1681
1682 ret = wl1271_hw_init(wl);
1683 if (ret < 0)
1684 goto irq_disable;
1685
1686 booted = true;
1687 break;
1688
1689irq_disable:
1690 mutex_unlock(&wl->mutex);
1691 /* Unlocking the mutex in the middle of handling is
1692 inherently unsafe. In this case we deem it safe to do,
1693 because we need to let any possibly pending IRQ out of
1694 the system (and while we are WL1271_STATE_OFF the IRQ
1695 work function will not do anything.) Also, any other
1696 possible concurrent operations will fail due to the
1697 current state, hence the wl1271 struct should be safe. */
1698 wlcore_disable_interrupts(wl);
1699 wl1271_flush_deferred_work(wl);
1700 cancel_work_sync(&wl->netstack_work);
1701 mutex_lock(&wl->mutex);
1702power_off:
1703 wl1271_power_off(wl);
1704 }
1705
1706 if (!booted) {
1707 wl1271_error("firmware boot failed despite %d retries",
1708 WL1271_BOOT_RETRIES);
1709 goto out;
1710 }
1711
1712 wl1271_info("firmware booted (%s)", wl->chip.fw_ver_str);
1713
1714 /* update hw/fw version info in wiphy struct */
1715 wiphy->hw_version = wl->chip.id;
1716 strncpy(wiphy->fw_version, wl->chip.fw_ver_str,
1717 sizeof(wiphy->fw_version));
1718
1719 /*
1720 * Now we know if 11a is supported (info from the NVS), so disable
1721 * 11a channels if not supported
1722 */
1723 if (!wl->enable_11a)
1724 wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels = 0;
1725
1726 wl1271_debug(DEBUG_MAC80211, "11a is %ssupported",
1727 wl->enable_11a ? "" : "not ");
1728
1729 wl->state = WL1271_STATE_ON;
1730out:
1731 return booted;
1732}
1733
1734static bool wl12xx_dev_role_started(struct wl12xx_vif *wlvif)
1735{
1736 return wlvif->dev_hlid != WL12XX_INVALID_LINK_ID;
1737}
1738
1739/*
1740 * Check whether a fw switch (i.e. moving from one loaded
1741 * fw to another) is needed. This function is also responsible
1742 * for updating wl->last_vif_count, so it must be called before
1743 * loading a non-plt fw (so the correct fw (single-role/multi-role)
1744 * will be used).
1745 */
1746static bool wl12xx_need_fw_change(struct wl1271 *wl,
1747 struct vif_counter_data vif_counter_data,
1748 bool add)
1749{
1750 enum wl12xx_fw_type current_fw = wl->fw_type;
1751 u8 vif_count = vif_counter_data.counter;
1752
1753 if (test_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags))
1754 return false;
1755
1756 /* increase the vif count if this is a new vif */
1757 if (add && !vif_counter_data.cur_vif_running)
1758 vif_count++;
1759
1760 wl->last_vif_count = vif_count;
1761
1762 /* no need for fw change if the device is OFF */
1763 if (wl->state == WL1271_STATE_OFF)
1764 return false;
1765
1766 if (vif_count > 1 && current_fw == WL12XX_FW_TYPE_NORMAL)
1767 return true;
1768 if (vif_count <= 1 && current_fw == WL12XX_FW_TYPE_MULTI)
1769 return true;
1770
1771 return false;
1772}
1773
1774/*
1775 * Enter "forced psm". Make sure the sta is in psm against the ap,
1776 * to make the fw switch a bit more disconnection-persistent.
1777 */
1778static void wl12xx_force_active_psm(struct wl1271 *wl)
1779{
1780 struct wl12xx_vif *wlvif;
1781
1782 wl12xx_for_each_wlvif_sta(wl, wlvif) {
1783 wl1271_ps_set_mode(wl, wlvif, STATION_POWER_SAVE_MODE);
1784 }
1785}
1786
1787static int wl1271_op_add_interface(struct ieee80211_hw *hw,
1788 struct ieee80211_vif *vif)
1789{
1790 struct wl1271 *wl = hw->priv;
1791 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
1792 struct vif_counter_data vif_count;
1793 int ret = 0;
1794 u8 role_type;
1795 bool booted = false;
1796
1797 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1798 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
1799
1800 wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
1801 ieee80211_vif_type_p2p(vif), vif->addr);
1802
1803 wl12xx_get_vif_count(hw, vif, &vif_count);
1804
1805 mutex_lock(&wl->mutex);
1806 ret = wl1271_ps_elp_wakeup(wl);
1807 if (ret < 0)
1808 goto out_unlock;
1809
1810 /*
1811 * in some very corner case HW recovery scenarios its possible to
1812 * get here before __wl1271_op_remove_interface is complete, so
1813 * opt out if that is the case.
1814 */
1815 if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags) ||
1816 test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) {
1817 ret = -EBUSY;
1818 goto out;
1819 }
1820
1821
1822 ret = wl12xx_init_vif_data(wl, vif);
1823 if (ret < 0)
1824 goto out;
1825
1826 wlvif->wl = wl;
1827 role_type = wl12xx_get_role_type(wl, wlvif);
1828 if (role_type == WL12XX_INVALID_ROLE_TYPE) {
1829 ret = -EINVAL;
1830 goto out;
1831 }
1832
1833 if (wl12xx_need_fw_change(wl, vif_count, true)) {
1834 wl12xx_force_active_psm(wl);
1835 set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags);
1836 mutex_unlock(&wl->mutex);
1837 wl1271_recovery_work(&wl->recovery_work);
1838 return 0;
1839 }
1840
1841 /*
1842 * TODO: after the nvs issue will be solved, move this block
1843 * to start(), and make sure here the driver is ON.
1844 */
1845 if (wl->state == WL1271_STATE_OFF) {
1846 /*
1847 * we still need this in order to configure the fw
1848 * while uploading the nvs
1849 */
1850 memcpy(wl->addresses[0].addr, vif->addr, ETH_ALEN);
1851
1852 booted = wl12xx_init_fw(wl);
1853 if (!booted) {
1854 ret = -EINVAL;
1855 goto out;
1856 }
1857 }
1858
1859 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
1860 wlvif->bss_type == BSS_TYPE_IBSS) {
1861 /*
1862 * The device role is a special role used for
1863 * rx and tx frames prior to association (as
1864 * the STA role can get packets only from
1865 * its associated bssid)
1866 */
1867 ret = wl12xx_cmd_role_enable(wl, vif->addr,
1868 WL1271_ROLE_DEVICE,
1869 &wlvif->dev_role_id);
1870 if (ret < 0)
1871 goto out;
1872 }
1873
1874 ret = wl12xx_cmd_role_enable(wl, vif->addr,
1875 role_type, &wlvif->role_id);
1876 if (ret < 0)
1877 goto out;
1878
1879 ret = wl1271_init_vif_specific(wl, vif);
1880 if (ret < 0)
1881 goto out;
1882
1883 list_add(&wlvif->list, &wl->wlvif_list);
1884 set_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags);
1885
1886 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
1887 wl->ap_count++;
1888 else
1889 wl->sta_count++;
1890out:
1891 wl1271_ps_elp_sleep(wl);
1892out_unlock:
1893 mutex_unlock(&wl->mutex);
1894
1895 return ret;
1896}
1897
1898static void __wl1271_op_remove_interface(struct wl1271 *wl,
1899 struct ieee80211_vif *vif,
1900 bool reset_tx_queues)
1901{
1902 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
1903 int i, ret;
1904
1905 wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface");
1906
1907 if (!test_and_clear_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
1908 return;
1909
1910 /* because of hardware recovery, we may get here twice */
1911 if (wl->state != WL1271_STATE_ON)
1912 return;
1913
1914 wl1271_info("down");
1915
1916 if (wl->scan.state != WL1271_SCAN_STATE_IDLE &&
1917 wl->scan_vif == vif) {
1918 /*
1919 * Rearm the tx watchdog just before idling scan. This
1920 * prevents just-finished scans from triggering the watchdog
1921 */
1922 wl12xx_rearm_tx_watchdog_locked(wl);
1923
1924 wl->scan.state = WL1271_SCAN_STATE_IDLE;
1925 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
1926 wl->scan_vif = NULL;
1927 wl->scan.req = NULL;
1928 ieee80211_scan_completed(wl->hw, true);
1929 }
1930
1931 if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) {
1932 /* disable active roles */
1933 ret = wl1271_ps_elp_wakeup(wl);
1934 if (ret < 0)
1935 goto deinit;
1936
1937 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
1938 wlvif->bss_type == BSS_TYPE_IBSS) {
1939 if (wl12xx_dev_role_started(wlvif))
1940 wl12xx_stop_dev(wl, wlvif);
1941
1942 ret = wl12xx_cmd_role_disable(wl, &wlvif->dev_role_id);
1943 if (ret < 0)
1944 goto deinit;
1945 }
1946
1947 ret = wl12xx_cmd_role_disable(wl, &wlvif->role_id);
1948 if (ret < 0)
1949 goto deinit;
1950
1951 wl1271_ps_elp_sleep(wl);
1952 }
1953deinit:
1954 /* clear all hlids (except system_hlid) */
1955 wlvif->dev_hlid = WL12XX_INVALID_LINK_ID;
1956
1957 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
1958 wlvif->bss_type == BSS_TYPE_IBSS) {
1959 wlvif->sta.hlid = WL12XX_INVALID_LINK_ID;
1960 wl12xx_free_rate_policy(wl, &wlvif->sta.basic_rate_idx);
1961 wl12xx_free_rate_policy(wl, &wlvif->sta.ap_rate_idx);
1962 wl12xx_free_rate_policy(wl, &wlvif->sta.p2p_rate_idx);
1963 } else {
1964 wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID;
1965 wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID;
1966 wl12xx_free_rate_policy(wl, &wlvif->ap.mgmt_rate_idx);
1967 wl12xx_free_rate_policy(wl, &wlvif->ap.bcast_rate_idx);
1968 for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++)
1969 wl12xx_free_rate_policy(wl,
1970 &wlvif->ap.ucast_rate_idx[i]);
1971 wl1271_free_ap_keys(wl, wlvif);
1972 }
1973
1974 dev_kfree_skb(wlvif->probereq);
1975 wlvif->probereq = NULL;
1976 wl12xx_tx_reset_wlvif(wl, wlvif);
1977 if (wl->last_wlvif == wlvif)
1978 wl->last_wlvif = NULL;
1979 list_del(&wlvif->list);
1980 memset(wlvif->ap.sta_hlid_map, 0, sizeof(wlvif->ap.sta_hlid_map));
1981 wlvif->role_id = WL12XX_INVALID_ROLE_ID;
1982 wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID;
1983
1984 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
1985 wl->ap_count--;
1986 else
1987 wl->sta_count--;
1988
1989 mutex_unlock(&wl->mutex);
1990
1991 del_timer_sync(&wlvif->rx_streaming_timer);
1992 cancel_work_sync(&wlvif->rx_streaming_enable_work);
1993 cancel_work_sync(&wlvif->rx_streaming_disable_work);
1994
1995 mutex_lock(&wl->mutex);
1996}
1997
1998static void wl1271_op_remove_interface(struct ieee80211_hw *hw,
1999 struct ieee80211_vif *vif)
2000{
2001 struct wl1271 *wl = hw->priv;
2002 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
2003 struct wl12xx_vif *iter;
2004 struct vif_counter_data vif_count;
2005 bool cancel_recovery = true;
2006
2007 wl12xx_get_vif_count(hw, vif, &vif_count);
2008 mutex_lock(&wl->mutex);
2009
2010 if (wl->state == WL1271_STATE_OFF ||
2011 !test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
2012 goto out;
2013
2014 /*
2015 * wl->vif can be null here if someone shuts down the interface
2016 * just when hardware recovery has been started.
2017 */
2018 wl12xx_for_each_wlvif(wl, iter) {
2019 if (iter != wlvif)
2020 continue;
2021
2022 __wl1271_op_remove_interface(wl, vif, true);
2023 break;
2024 }
2025 WARN_ON(iter != wlvif);
2026 if (wl12xx_need_fw_change(wl, vif_count, false)) {
2027 wl12xx_force_active_psm(wl);
2028 set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags);
2029 wl12xx_queue_recovery_work(wl);
2030 cancel_recovery = false;
2031 }
2032out:
2033 mutex_unlock(&wl->mutex);
2034 if (cancel_recovery)
2035 cancel_work_sync(&wl->recovery_work);
2036}
2037
2038static int wl12xx_op_change_interface(struct ieee80211_hw *hw,
2039 struct ieee80211_vif *vif,
2040 enum nl80211_iftype new_type, bool p2p)
2041{
2042 struct wl1271 *wl = hw->priv;
2043 int ret;
2044
2045 set_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags);
2046 wl1271_op_remove_interface(hw, vif);
2047
2048 vif->type = new_type;
2049 vif->p2p = p2p;
2050 ret = wl1271_op_add_interface(hw, vif);
2051
2052 clear_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags);
2053 return ret;
2054}
2055
2056static int wl1271_join(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2057 bool set_assoc)
2058{
2059 int ret;
2060 bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS);
2061
2062 /*
2063 * One of the side effects of the JOIN command is that is clears
2064 * WPA/WPA2 keys from the chipset. Performing a JOIN while associated
2065 * to a WPA/WPA2 access point will therefore kill the data-path.
2066 * Currently the only valid scenario for JOIN during association
2067 * is on roaming, in which case we will also be given new keys.
2068 * Keep the below message for now, unless it starts bothering
2069 * users who really like to roam a lot :)
2070 */
2071 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
2072 wl1271_info("JOIN while associated.");
2073
2074 /* clear encryption type */
2075 wlvif->encryption_type = KEY_NONE;
2076
2077 if (set_assoc)
2078 set_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags);
2079
2080 if (is_ibss)
2081 ret = wl12xx_cmd_role_start_ibss(wl, wlvif);
2082 else
2083 ret = wl12xx_cmd_role_start_sta(wl, wlvif);
2084 if (ret < 0)
2085 goto out;
2086
2087 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
2088 goto out;
2089
2090 /*
2091 * The join command disable the keep-alive mode, shut down its process,
2092 * and also clear the template config, so we need to reset it all after
2093 * the join. The acx_aid starts the keep-alive process, and the order
2094 * of the commands below is relevant.
2095 */
2096 ret = wl1271_acx_keep_alive_mode(wl, wlvif, true);
2097 if (ret < 0)
2098 goto out;
2099
2100 ret = wl1271_acx_aid(wl, wlvif, wlvif->aid);
2101 if (ret < 0)
2102 goto out;
2103
2104 ret = wl12xx_cmd_build_klv_null_data(wl, wlvif);
2105 if (ret < 0)
2106 goto out;
2107
2108 ret = wl1271_acx_keep_alive_config(wl, wlvif,
2109 CMD_TEMPL_KLV_IDX_NULL_DATA,
2110 ACX_KEEP_ALIVE_TPL_VALID);
2111 if (ret < 0)
2112 goto out;
2113
2114out:
2115 return ret;
2116}
2117
2118static int wl1271_unjoin(struct wl1271 *wl, struct wl12xx_vif *wlvif)
2119{
2120 int ret;
2121
2122 if (test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags)) {
2123 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
2124
2125 wl12xx_cmd_stop_channel_switch(wl);
2126 ieee80211_chswitch_done(vif, false);
2127 }
2128
2129 /* to stop listening to a channel, we disconnect */
2130 ret = wl12xx_cmd_role_stop_sta(wl, wlvif);
2131 if (ret < 0)
2132 goto out;
2133
2134 /* reset TX security counters on a clean disconnect */
2135 wlvif->tx_security_last_seq_lsb = 0;
2136 wlvif->tx_security_seq = 0;
2137
2138out:
2139 return ret;
2140}
2141
2142static void wl1271_set_band_rate(struct wl1271 *wl, struct wl12xx_vif *wlvif)
2143{
2144 wlvif->basic_rate_set = wlvif->bitrate_masks[wlvif->band];
2145 wlvif->rate_set = wlvif->basic_rate_set;
2146}
2147
2148static int wl1271_sta_handle_idle(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2149 bool idle)
2150{
2151 int ret;
2152 bool cur_idle = !test_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
2153
2154 if (idle == cur_idle)
2155 return 0;
2156
2157 if (idle) {
2158 /* no need to croc if we weren't busy (e.g. during boot) */
2159 if (wl12xx_dev_role_started(wlvif)) {
2160 ret = wl12xx_stop_dev(wl, wlvif);
2161 if (ret < 0)
2162 goto out;
2163 }
2164 wlvif->rate_set =
2165 wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
2166 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
2167 if (ret < 0)
2168 goto out;
2169 ret = wl1271_acx_keep_alive_config(
2170 wl, wlvif, CMD_TEMPL_KLV_IDX_NULL_DATA,
2171 ACX_KEEP_ALIVE_TPL_INVALID);
2172 if (ret < 0)
2173 goto out;
2174 clear_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
2175 } else {
2176 /* The current firmware only supports sched_scan in idle */
2177 if (wl->sched_scanning) {
2178 wl1271_scan_sched_scan_stop(wl);
2179 ieee80211_sched_scan_stopped(wl->hw);
2180 }
2181
2182 ret = wl12xx_start_dev(wl, wlvif);
2183 if (ret < 0)
2184 goto out;
2185 set_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
2186 }
2187
2188out:
2189 return ret;
2190}
2191
2192static int wl12xx_config_vif(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2193 struct ieee80211_conf *conf, u32 changed)
2194{
2195 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
2196 int channel, ret;
2197
2198 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
2199
2200 /* if the channel changes while joined, join again */
2201 if (changed & IEEE80211_CONF_CHANGE_CHANNEL &&
2202 ((wlvif->band != conf->channel->band) ||
2203 (wlvif->channel != channel))) {
2204 /* send all pending packets */
2205 wl1271_tx_work_locked(wl);
2206 wlvif->band = conf->channel->band;
2207 wlvif->channel = channel;
2208
2209 if (!is_ap) {
2210 /*
2211 * FIXME: the mac80211 should really provide a fixed
2212 * rate to use here. for now, just use the smallest
2213 * possible rate for the band as a fixed rate for
2214 * association frames and other control messages.
2215 */
2216 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
2217 wl1271_set_band_rate(wl, wlvif);
2218
2219 wlvif->basic_rate =
2220 wl1271_tx_min_rate_get(wl,
2221 wlvif->basic_rate_set);
2222 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
2223 if (ret < 0)
2224 wl1271_warning("rate policy for channel "
2225 "failed %d", ret);
2226
2227 /*
2228 * change the ROC channel. do it only if we are
2229 * not idle. otherwise, CROC will be called
2230 * anyway.
2231 */
2232 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED,
2233 &wlvif->flags) &&
2234 wl12xx_dev_role_started(wlvif) &&
2235 !(conf->flags & IEEE80211_CONF_IDLE)) {
2236 ret = wl12xx_stop_dev(wl, wlvif);
2237 if (ret < 0)
2238 return ret;
2239
2240 ret = wl12xx_start_dev(wl, wlvif);
2241 if (ret < 0)
2242 return ret;
2243 }
2244 }
2245 }
2246
2247 if ((changed & IEEE80211_CONF_CHANGE_PS) && !is_ap) {
2248
2249 if ((conf->flags & IEEE80211_CONF_PS) &&
2250 test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) &&
2251 !test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) {
2252
2253 int ps_mode;
2254 char *ps_mode_str;
2255
2256 if (wl->conf.conn.forced_ps) {
2257 ps_mode = STATION_POWER_SAVE_MODE;
2258 ps_mode_str = "forced";
2259 } else {
2260 ps_mode = STATION_AUTO_PS_MODE;
2261 ps_mode_str = "auto";
2262 }
2263
2264 wl1271_debug(DEBUG_PSM, "%s ps enabled", ps_mode_str);
2265
2266 ret = wl1271_ps_set_mode(wl, wlvif, ps_mode);
2267
2268 if (ret < 0)
2269 wl1271_warning("enter %s ps failed %d",
2270 ps_mode_str, ret);
2271
2272 } else if (!(conf->flags & IEEE80211_CONF_PS) &&
2273 test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) {
2274
2275 wl1271_debug(DEBUG_PSM, "auto ps disabled");
2276
2277 ret = wl1271_ps_set_mode(wl, wlvif,
2278 STATION_ACTIVE_MODE);
2279 if (ret < 0)
2280 wl1271_warning("exit auto ps failed %d", ret);
2281 }
2282 }
2283
2284 if (conf->power_level != wlvif->power_level) {
2285 ret = wl1271_acx_tx_power(wl, wlvif, conf->power_level);
2286 if (ret < 0)
2287 return ret;
2288
2289 wlvif->power_level = conf->power_level;
2290 }
2291
2292 return 0;
2293}
2294
2295static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
2296{
2297 struct wl1271 *wl = hw->priv;
2298 struct wl12xx_vif *wlvif;
2299 struct ieee80211_conf *conf = &hw->conf;
2300 int channel, ret = 0;
2301
2302 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
2303
2304 wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d %s"
2305 " changed 0x%x",
2306 channel,
2307 conf->flags & IEEE80211_CONF_PS ? "on" : "off",
2308 conf->power_level,
2309 conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use",
2310 changed);
2311
2312 /*
2313 * mac80211 will go to idle nearly immediately after transmitting some
2314 * frames, such as the deauth. To make sure those frames reach the air,
2315 * wait here until the TX queue is fully flushed.
2316 */
2317 if ((changed & IEEE80211_CONF_CHANGE_IDLE) &&
2318 (conf->flags & IEEE80211_CONF_IDLE))
2319 wl1271_tx_flush(wl);
2320
2321 mutex_lock(&wl->mutex);
2322
2323 /* we support configuring the channel and band even while off */
2324 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
2325 wl->band = conf->channel->band;
2326 wl->channel = channel;
2327 }
2328
2329 if (changed & IEEE80211_CONF_CHANGE_POWER)
2330 wl->power_level = conf->power_level;
2331
2332 if (unlikely(wl->state == WL1271_STATE_OFF))
2333 goto out;
2334
2335 ret = wl1271_ps_elp_wakeup(wl);
2336 if (ret < 0)
2337 goto out;
2338
2339 /* configure each interface */
2340 wl12xx_for_each_wlvif(wl, wlvif) {
2341 ret = wl12xx_config_vif(wl, wlvif, conf, changed);
2342 if (ret < 0)
2343 goto out_sleep;
2344 }
2345
2346out_sleep:
2347 wl1271_ps_elp_sleep(wl);
2348
2349out:
2350 mutex_unlock(&wl->mutex);
2351
2352 return ret;
2353}
2354
2355struct wl1271_filter_params {
2356 bool enabled;
2357 int mc_list_length;
2358 u8 mc_list[ACX_MC_ADDRESS_GROUP_MAX][ETH_ALEN];
2359};
2360
2361static u64 wl1271_op_prepare_multicast(struct ieee80211_hw *hw,
2362 struct netdev_hw_addr_list *mc_list)
2363{
2364 struct wl1271_filter_params *fp;
2365 struct netdev_hw_addr *ha;
2366 struct wl1271 *wl = hw->priv;
2367
2368 if (unlikely(wl->state == WL1271_STATE_OFF))
2369 return 0;
2370
2371 fp = kzalloc(sizeof(*fp), GFP_ATOMIC);
2372 if (!fp) {
2373 wl1271_error("Out of memory setting filters.");
2374 return 0;
2375 }
2376
2377 /* update multicast filtering parameters */
2378 fp->mc_list_length = 0;
2379 if (netdev_hw_addr_list_count(mc_list) > ACX_MC_ADDRESS_GROUP_MAX) {
2380 fp->enabled = false;
2381 } else {
2382 fp->enabled = true;
2383 netdev_hw_addr_list_for_each(ha, mc_list) {
2384 memcpy(fp->mc_list[fp->mc_list_length],
2385 ha->addr, ETH_ALEN);
2386 fp->mc_list_length++;
2387 }
2388 }
2389
2390 return (u64)(unsigned long)fp;
2391}
2392
2393#define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
2394 FIF_ALLMULTI | \
2395 FIF_FCSFAIL | \
2396 FIF_BCN_PRBRESP_PROMISC | \
2397 FIF_CONTROL | \
2398 FIF_OTHER_BSS)
2399
2400static void wl1271_op_configure_filter(struct ieee80211_hw *hw,
2401 unsigned int changed,
2402 unsigned int *total, u64 multicast)
2403{
2404 struct wl1271_filter_params *fp = (void *)(unsigned long)multicast;
2405 struct wl1271 *wl = hw->priv;
2406 struct wl12xx_vif *wlvif;
2407
2408 int ret;
2409
2410 wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter changed %x"
2411 " total %x", changed, *total);
2412
2413 mutex_lock(&wl->mutex);
2414
2415 *total &= WL1271_SUPPORTED_FILTERS;
2416 changed &= WL1271_SUPPORTED_FILTERS;
2417
2418 if (unlikely(wl->state == WL1271_STATE_OFF))
2419 goto out;
2420
2421 ret = wl1271_ps_elp_wakeup(wl);
2422 if (ret < 0)
2423 goto out;
2424
2425 wl12xx_for_each_wlvif(wl, wlvif) {
2426 if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
2427 if (*total & FIF_ALLMULTI)
2428 ret = wl1271_acx_group_address_tbl(wl, wlvif,
2429 false,
2430 NULL, 0);
2431 else if (fp)
2432 ret = wl1271_acx_group_address_tbl(wl, wlvif,
2433 fp->enabled,
2434 fp->mc_list,
2435 fp->mc_list_length);
2436 if (ret < 0)
2437 goto out_sleep;
2438 }
2439 }
2440
2441 /*
2442 * the fw doesn't provide an api to configure the filters. instead,
2443 * the filters configuration is based on the active roles / ROC
2444 * state.
2445 */
2446
2447out_sleep:
2448 wl1271_ps_elp_sleep(wl);
2449
2450out:
2451 mutex_unlock(&wl->mutex);
2452 kfree(fp);
2453}
2454
2455static int wl1271_record_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2456 u8 id, u8 key_type, u8 key_size,
2457 const u8 *key, u8 hlid, u32 tx_seq_32,
2458 u16 tx_seq_16)
2459{
2460 struct wl1271_ap_key *ap_key;
2461 int i;
2462
2463 wl1271_debug(DEBUG_CRYPT, "record ap key id %d", (int)id);
2464
2465 if (key_size > MAX_KEY_SIZE)
2466 return -EINVAL;
2467
2468 /*
2469 * Find next free entry in ap_keys. Also check we are not replacing
2470 * an existing key.
2471 */
2472 for (i = 0; i < MAX_NUM_KEYS; i++) {
2473 if (wlvif->ap.recorded_keys[i] == NULL)
2474 break;
2475
2476 if (wlvif->ap.recorded_keys[i]->id == id) {
2477 wl1271_warning("trying to record key replacement");
2478 return -EINVAL;
2479 }
2480 }
2481
2482 if (i == MAX_NUM_KEYS)
2483 return -EBUSY;
2484
2485 ap_key = kzalloc(sizeof(*ap_key), GFP_KERNEL);
2486 if (!ap_key)
2487 return -ENOMEM;
2488
2489 ap_key->id = id;
2490 ap_key->key_type = key_type;
2491 ap_key->key_size = key_size;
2492 memcpy(ap_key->key, key, key_size);
2493 ap_key->hlid = hlid;
2494 ap_key->tx_seq_32 = tx_seq_32;
2495 ap_key->tx_seq_16 = tx_seq_16;
2496
2497 wlvif->ap.recorded_keys[i] = ap_key;
2498 return 0;
2499}
2500
2501static void wl1271_free_ap_keys(struct wl1271 *wl, struct wl12xx_vif *wlvif)
2502{
2503 int i;
2504
2505 for (i = 0; i < MAX_NUM_KEYS; i++) {
2506 kfree(wlvif->ap.recorded_keys[i]);
2507 wlvif->ap.recorded_keys[i] = NULL;
2508 }
2509}
2510
2511static int wl1271_ap_init_hwenc(struct wl1271 *wl, struct wl12xx_vif *wlvif)
2512{
2513 int i, ret = 0;
2514 struct wl1271_ap_key *key;
2515 bool wep_key_added = false;
2516
2517 for (i = 0; i < MAX_NUM_KEYS; i++) {
2518 u8 hlid;
2519 if (wlvif->ap.recorded_keys[i] == NULL)
2520 break;
2521
2522 key = wlvif->ap.recorded_keys[i];
2523 hlid = key->hlid;
2524 if (hlid == WL12XX_INVALID_LINK_ID)
2525 hlid = wlvif->ap.bcast_hlid;
2526
2527 ret = wl1271_cmd_set_ap_key(wl, wlvif, KEY_ADD_OR_REPLACE,
2528 key->id, key->key_type,
2529 key->key_size, key->key,
2530 hlid, key->tx_seq_32,
2531 key->tx_seq_16);
2532 if (ret < 0)
2533 goto out;
2534
2535 if (key->key_type == KEY_WEP)
2536 wep_key_added = true;
2537 }
2538
2539 if (wep_key_added) {
2540 ret = wl12xx_cmd_set_default_wep_key(wl, wlvif->default_key,
2541 wlvif->ap.bcast_hlid);
2542 if (ret < 0)
2543 goto out;
2544 }
2545
2546out:
2547 wl1271_free_ap_keys(wl, wlvif);
2548 return ret;
2549}
2550
2551static int wl1271_set_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2552 u16 action, u8 id, u8 key_type,
2553 u8 key_size, const u8 *key, u32 tx_seq_32,
2554 u16 tx_seq_16, struct ieee80211_sta *sta)
2555{
2556 int ret;
2557 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
2558
2559 /*
2560 * A role set to GEM cipher requires different Tx settings (namely
2561 * spare blocks). Note when we are in this mode so the HW can adjust.
2562 */
2563 if (key_type == KEY_GEM) {
2564 if (action == KEY_ADD_OR_REPLACE)
2565 wlvif->is_gem = true;
2566 else if (action == KEY_REMOVE)
2567 wlvif->is_gem = false;
2568 }
2569
2570 if (is_ap) {
2571 struct wl1271_station *wl_sta;
2572 u8 hlid;
2573
2574 if (sta) {
2575 wl_sta = (struct wl1271_station *)sta->drv_priv;
2576 hlid = wl_sta->hlid;
2577 } else {
2578 hlid = wlvif->ap.bcast_hlid;
2579 }
2580
2581 if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
2582 /*
2583 * We do not support removing keys after AP shutdown.
2584 * Pretend we do to make mac80211 happy.
2585 */
2586 if (action != KEY_ADD_OR_REPLACE)
2587 return 0;
2588
2589 ret = wl1271_record_ap_key(wl, wlvif, id,
2590 key_type, key_size,
2591 key, hlid, tx_seq_32,
2592 tx_seq_16);
2593 } else {
2594 ret = wl1271_cmd_set_ap_key(wl, wlvif, action,
2595 id, key_type, key_size,
2596 key, hlid, tx_seq_32,
2597 tx_seq_16);
2598 }
2599
2600 if (ret < 0)
2601 return ret;
2602 } else {
2603 const u8 *addr;
2604 static const u8 bcast_addr[ETH_ALEN] = {
2605 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2606 };
2607
2608 addr = sta ? sta->addr : bcast_addr;
2609
2610 if (is_zero_ether_addr(addr)) {
2611 /* We dont support TX only encryption */
2612 return -EOPNOTSUPP;
2613 }
2614
2615 /* The wl1271 does not allow to remove unicast keys - they
2616 will be cleared automatically on next CMD_JOIN. Ignore the
2617 request silently, as we dont want the mac80211 to emit
2618 an error message. */
2619 if (action == KEY_REMOVE && !is_broadcast_ether_addr(addr))
2620 return 0;
2621
2622 /* don't remove key if hlid was already deleted */
2623 if (action == KEY_REMOVE &&
2624 wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)
2625 return 0;
2626
2627 ret = wl1271_cmd_set_sta_key(wl, wlvif, action,
2628 id, key_type, key_size,
2629 key, addr, tx_seq_32,
2630 tx_seq_16);
2631 if (ret < 0)
2632 return ret;
2633
2634 /* the default WEP key needs to be configured at least once */
2635 if (key_type == KEY_WEP) {
2636 ret = wl12xx_cmd_set_default_wep_key(wl,
2637 wlvif->default_key,
2638 wlvif->sta.hlid);
2639 if (ret < 0)
2640 return ret;
2641 }
2642 }
2643
2644 return 0;
2645}
2646
2647static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2648 struct ieee80211_vif *vif,
2649 struct ieee80211_sta *sta,
2650 struct ieee80211_key_conf *key_conf)
2651{
2652 struct wl1271 *wl = hw->priv;
2653 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
2654 int ret;
2655 u32 tx_seq_32 = 0;
2656 u16 tx_seq_16 = 0;
2657 u8 key_type;
2658
2659 wl1271_debug(DEBUG_MAC80211, "mac80211 set key");
2660
2661 wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x sta: %p", cmd, sta);
2662 wl1271_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
2663 key_conf->cipher, key_conf->keyidx,
2664 key_conf->keylen, key_conf->flags);
2665 wl1271_dump(DEBUG_CRYPT, "KEY: ", key_conf->key, key_conf->keylen);
2666
2667 mutex_lock(&wl->mutex);
2668
2669 if (unlikely(wl->state == WL1271_STATE_OFF)) {
2670 ret = -EAGAIN;
2671 goto out_unlock;
2672 }
2673
2674 ret = wl1271_ps_elp_wakeup(wl);
2675 if (ret < 0)
2676 goto out_unlock;
2677
2678 switch (key_conf->cipher) {
2679 case WLAN_CIPHER_SUITE_WEP40:
2680 case WLAN_CIPHER_SUITE_WEP104:
2681 key_type = KEY_WEP;
2682
2683 key_conf->hw_key_idx = key_conf->keyidx;
2684 break;
2685 case WLAN_CIPHER_SUITE_TKIP:
2686 key_type = KEY_TKIP;
2687
2688 key_conf->hw_key_idx = key_conf->keyidx;
2689 tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
2690 tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
2691 break;
2692 case WLAN_CIPHER_SUITE_CCMP:
2693 key_type = KEY_AES;
2694
2695 key_conf->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2696 tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
2697 tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
2698 break;
2699 case WL1271_CIPHER_SUITE_GEM:
2700 key_type = KEY_GEM;
2701 tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
2702 tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
2703 break;
2704 default:
2705 wl1271_error("Unknown key algo 0x%x", key_conf->cipher);
2706
2707 ret = -EOPNOTSUPP;
2708 goto out_sleep;
2709 }
2710
2711 switch (cmd) {
2712 case SET_KEY:
2713 ret = wl1271_set_key(wl, wlvif, KEY_ADD_OR_REPLACE,
2714 key_conf->keyidx, key_type,
2715 key_conf->keylen, key_conf->key,
2716 tx_seq_32, tx_seq_16, sta);
2717 if (ret < 0) {
2718 wl1271_error("Could not add or replace key");
2719 goto out_sleep;
2720 }
2721
2722 /*
2723 * reconfiguring arp response if the unicast (or common)
2724 * encryption key type was changed
2725 */
2726 if (wlvif->bss_type == BSS_TYPE_STA_BSS &&
2727 (sta || key_type == KEY_WEP) &&
2728 wlvif->encryption_type != key_type) {
2729 wlvif->encryption_type = key_type;
2730 ret = wl1271_cmd_build_arp_rsp(wl, wlvif);
2731 if (ret < 0) {
2732 wl1271_warning("build arp rsp failed: %d", ret);
2733 goto out_sleep;
2734 }
2735 }
2736 break;
2737
2738 case DISABLE_KEY:
2739 ret = wl1271_set_key(wl, wlvif, KEY_REMOVE,
2740 key_conf->keyidx, key_type,
2741 key_conf->keylen, key_conf->key,
2742 0, 0, sta);
2743 if (ret < 0) {
2744 wl1271_error("Could not remove key");
2745 goto out_sleep;
2746 }
2747 break;
2748
2749 default:
2750 wl1271_error("Unsupported key cmd 0x%x", cmd);
2751 ret = -EOPNOTSUPP;
2752 break;
2753 }
2754
2755out_sleep:
2756 wl1271_ps_elp_sleep(wl);
2757
2758out_unlock:
2759 mutex_unlock(&wl->mutex);
2760
2761 return ret;
2762}
2763
2764static int wl1271_op_hw_scan(struct ieee80211_hw *hw,
2765 struct ieee80211_vif *vif,
2766 struct cfg80211_scan_request *req)
2767{
2768 struct wl1271 *wl = hw->priv;
2769 int ret;
2770 u8 *ssid = NULL;
2771 size_t len = 0;
2772
2773 wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan");
2774
2775 if (req->n_ssids) {
2776 ssid = req->ssids[0].ssid;
2777 len = req->ssids[0].ssid_len;
2778 }
2779
2780 mutex_lock(&wl->mutex);
2781
2782 if (wl->state == WL1271_STATE_OFF) {
2783 /*
2784 * We cannot return -EBUSY here because cfg80211 will expect
2785 * a call to ieee80211_scan_completed if we do - in this case
2786 * there won't be any call.
2787 */
2788 ret = -EAGAIN;
2789 goto out;
2790 }
2791
2792 ret = wl1271_ps_elp_wakeup(wl);
2793 if (ret < 0)
2794 goto out;
2795
2796 /* fail if there is any role in ROC */
2797 if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) < WL12XX_MAX_ROLES) {
2798 /* don't allow scanning right now */
2799 ret = -EBUSY;
2800 goto out_sleep;
2801 }
2802
2803 ret = wl1271_scan(hw->priv, vif, ssid, len, req);
2804out_sleep:
2805 wl1271_ps_elp_sleep(wl);
2806out:
2807 mutex_unlock(&wl->mutex);
2808
2809 return ret;
2810}
2811
2812static void wl1271_op_cancel_hw_scan(struct ieee80211_hw *hw,
2813 struct ieee80211_vif *vif)
2814{
2815 struct wl1271 *wl = hw->priv;
2816 int ret;
2817
2818 wl1271_debug(DEBUG_MAC80211, "mac80211 cancel hw scan");
2819
2820 mutex_lock(&wl->mutex);
2821
2822 if (wl->state == WL1271_STATE_OFF)
2823 goto out;
2824
2825 if (wl->scan.state == WL1271_SCAN_STATE_IDLE)
2826 goto out;
2827
2828 ret = wl1271_ps_elp_wakeup(wl);
2829 if (ret < 0)
2830 goto out;
2831
2832 if (wl->scan.state != WL1271_SCAN_STATE_DONE) {
2833 ret = wl1271_scan_stop(wl);
2834 if (ret < 0)
2835 goto out_sleep;
2836 }
2837
2838 /*
2839 * Rearm the tx watchdog just before idling scan. This
2840 * prevents just-finished scans from triggering the watchdog
2841 */
2842 wl12xx_rearm_tx_watchdog_locked(wl);
2843
2844 wl->scan.state = WL1271_SCAN_STATE_IDLE;
2845 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
2846 wl->scan_vif = NULL;
2847 wl->scan.req = NULL;
2848 ieee80211_scan_completed(wl->hw, true);
2849
2850out_sleep:
2851 wl1271_ps_elp_sleep(wl);
2852out:
2853 mutex_unlock(&wl->mutex);
2854
2855 cancel_delayed_work_sync(&wl->scan_complete_work);
2856}
2857
2858static int wl1271_op_sched_scan_start(struct ieee80211_hw *hw,
2859 struct ieee80211_vif *vif,
2860 struct cfg80211_sched_scan_request *req,
2861 struct ieee80211_sched_scan_ies *ies)
2862{
2863 struct wl1271 *wl = hw->priv;
2864 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
2865 int ret;
2866
2867 wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_start");
2868
2869 mutex_lock(&wl->mutex);
2870
2871 if (wl->state == WL1271_STATE_OFF) {
2872 ret = -EAGAIN;
2873 goto out;
2874 }
2875
2876 ret = wl1271_ps_elp_wakeup(wl);
2877 if (ret < 0)
2878 goto out;
2879
2880 ret = wl1271_scan_sched_scan_config(wl, wlvif, req, ies);
2881 if (ret < 0)
2882 goto out_sleep;
2883
2884 ret = wl1271_scan_sched_scan_start(wl, wlvif);
2885 if (ret < 0)
2886 goto out_sleep;
2887
2888 wl->sched_scanning = true;
2889
2890out_sleep:
2891 wl1271_ps_elp_sleep(wl);
2892out:
2893 mutex_unlock(&wl->mutex);
2894 return ret;
2895}
2896
2897static void wl1271_op_sched_scan_stop(struct ieee80211_hw *hw,
2898 struct ieee80211_vif *vif)
2899{
2900 struct wl1271 *wl = hw->priv;
2901 int ret;
2902
2903 wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_stop");
2904
2905 mutex_lock(&wl->mutex);
2906
2907 if (wl->state == WL1271_STATE_OFF)
2908 goto out;
2909
2910 ret = wl1271_ps_elp_wakeup(wl);
2911 if (ret < 0)
2912 goto out;
2913
2914 wl1271_scan_sched_scan_stop(wl);
2915
2916 wl1271_ps_elp_sleep(wl);
2917out:
2918 mutex_unlock(&wl->mutex);
2919}
2920
2921static int wl1271_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
2922{
2923 struct wl1271 *wl = hw->priv;
2924 int ret = 0;
2925
2926 mutex_lock(&wl->mutex);
2927
2928 if (unlikely(wl->state == WL1271_STATE_OFF)) {
2929 ret = -EAGAIN;
2930 goto out;
2931 }
2932
2933 ret = wl1271_ps_elp_wakeup(wl);
2934 if (ret < 0)
2935 goto out;
2936
2937 ret = wl1271_acx_frag_threshold(wl, value);
2938 if (ret < 0)
2939 wl1271_warning("wl1271_op_set_frag_threshold failed: %d", ret);
2940
2941 wl1271_ps_elp_sleep(wl);
2942
2943out:
2944 mutex_unlock(&wl->mutex);
2945
2946 return ret;
2947}
2948
2949static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2950{
2951 struct wl1271 *wl = hw->priv;
2952 struct wl12xx_vif *wlvif;
2953 int ret = 0;
2954
2955 mutex_lock(&wl->mutex);
2956
2957 if (unlikely(wl->state == WL1271_STATE_OFF)) {
2958 ret = -EAGAIN;
2959 goto out;
2960 }
2961
2962 ret = wl1271_ps_elp_wakeup(wl);
2963 if (ret < 0)
2964 goto out;
2965
2966 wl12xx_for_each_wlvif(wl, wlvif) {
2967 ret = wl1271_acx_rts_threshold(wl, wlvif, value);
2968 if (ret < 0)
2969 wl1271_warning("set rts threshold failed: %d", ret);
2970 }
2971 wl1271_ps_elp_sleep(wl);
2972
2973out:
2974 mutex_unlock(&wl->mutex);
2975
2976 return ret;
2977}
2978
2979static int wl1271_ssid_set(struct ieee80211_vif *vif, struct sk_buff *skb,
2980 int offset)
2981{
2982 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
2983 u8 ssid_len;
2984 const u8 *ptr = cfg80211_find_ie(WLAN_EID_SSID, skb->data + offset,
2985 skb->len - offset);
2986
2987 if (!ptr) {
2988 wl1271_error("No SSID in IEs!");
2989 return -ENOENT;
2990 }
2991
2992 ssid_len = ptr[1];
2993 if (ssid_len > IEEE80211_MAX_SSID_LEN) {
2994 wl1271_error("SSID is too long!");
2995 return -EINVAL;
2996 }
2997
2998 wlvif->ssid_len = ssid_len;
2999 memcpy(wlvif->ssid, ptr+2, ssid_len);
3000 return 0;
3001}
3002
3003static void wl12xx_remove_ie(struct sk_buff *skb, u8 eid, int ieoffset)
3004{
3005 int len;
3006 const u8 *next, *end = skb->data + skb->len;
3007 u8 *ie = (u8 *)cfg80211_find_ie(eid, skb->data + ieoffset,
3008 skb->len - ieoffset);
3009 if (!ie)
3010 return;
3011 len = ie[1] + 2;
3012 next = ie + len;
3013 memmove(ie, next, end - next);
3014 skb_trim(skb, skb->len - len);
3015}
3016
3017static void wl12xx_remove_vendor_ie(struct sk_buff *skb,
3018 unsigned int oui, u8 oui_type,
3019 int ieoffset)
3020{
3021 int len;
3022 const u8 *next, *end = skb->data + skb->len;
3023 u8 *ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
3024 skb->data + ieoffset,
3025 skb->len - ieoffset);
3026 if (!ie)
3027 return;
3028 len = ie[1] + 2;
3029 next = ie + len;
3030 memmove(ie, next, end - next);
3031 skb_trim(skb, skb->len - len);
3032}
3033
3034static int wl1271_ap_set_probe_resp_tmpl(struct wl1271 *wl, u32 rates,
3035 struct ieee80211_vif *vif)
3036{
3037 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3038 struct sk_buff *skb;
3039 int ret;
3040
3041 skb = ieee80211_proberesp_get(wl->hw, vif);
3042 if (!skb)
3043 return -EOPNOTSUPP;
3044
3045 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
3046 CMD_TEMPL_AP_PROBE_RESPONSE,
3047 skb->data,
3048 skb->len, 0,
3049 rates);
3050
3051 dev_kfree_skb(skb);
3052 return ret;
3053}
3054
3055static int wl1271_ap_set_probe_resp_tmpl_legacy(struct wl1271 *wl,
3056 struct ieee80211_vif *vif,
3057 u8 *probe_rsp_data,
3058 size_t probe_rsp_len,
3059 u32 rates)
3060{
3061 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3062 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
3063 u8 probe_rsp_templ[WL1271_CMD_TEMPL_MAX_SIZE];
3064 int ssid_ie_offset, ie_offset, templ_len;
3065 const u8 *ptr;
3066
3067 /* no need to change probe response if the SSID is set correctly */
3068 if (wlvif->ssid_len > 0)
3069 return wl1271_cmd_template_set(wl, wlvif->role_id,
3070 CMD_TEMPL_AP_PROBE_RESPONSE,
3071 probe_rsp_data,
3072 probe_rsp_len, 0,
3073 rates);
3074
3075 if (probe_rsp_len + bss_conf->ssid_len > WL1271_CMD_TEMPL_MAX_SIZE) {
3076 wl1271_error("probe_rsp template too big");
3077 return -EINVAL;
3078 }
3079
3080 /* start searching from IE offset */
3081 ie_offset = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
3082
3083 ptr = cfg80211_find_ie(WLAN_EID_SSID, probe_rsp_data + ie_offset,
3084 probe_rsp_len - ie_offset);
3085 if (!ptr) {
3086 wl1271_error("No SSID in beacon!");
3087 return -EINVAL;
3088 }
3089
3090 ssid_ie_offset = ptr - probe_rsp_data;
3091 ptr += (ptr[1] + 2);
3092
3093 memcpy(probe_rsp_templ, probe_rsp_data, ssid_ie_offset);
3094
3095 /* insert SSID from bss_conf */
3096 probe_rsp_templ[ssid_ie_offset] = WLAN_EID_SSID;
3097 probe_rsp_templ[ssid_ie_offset + 1] = bss_conf->ssid_len;
3098 memcpy(probe_rsp_templ + ssid_ie_offset + 2,
3099 bss_conf->ssid, bss_conf->ssid_len);
3100 templ_len = ssid_ie_offset + 2 + bss_conf->ssid_len;
3101
3102 memcpy(probe_rsp_templ + ssid_ie_offset + 2 + bss_conf->ssid_len,
3103 ptr, probe_rsp_len - (ptr - probe_rsp_data));
3104 templ_len += probe_rsp_len - (ptr - probe_rsp_data);
3105
3106 return wl1271_cmd_template_set(wl, wlvif->role_id,
3107 CMD_TEMPL_AP_PROBE_RESPONSE,
3108 probe_rsp_templ,
3109 templ_len, 0,
3110 rates);
3111}
3112
3113static int wl1271_bss_erp_info_changed(struct wl1271 *wl,
3114 struct ieee80211_vif *vif,
3115 struct ieee80211_bss_conf *bss_conf,
3116 u32 changed)
3117{
3118 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3119 int ret = 0;
3120
3121 if (changed & BSS_CHANGED_ERP_SLOT) {
3122 if (bss_conf->use_short_slot)
3123 ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_SHORT);
3124 else
3125 ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_LONG);
3126 if (ret < 0) {
3127 wl1271_warning("Set slot time failed %d", ret);
3128 goto out;
3129 }
3130 }
3131
3132 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3133 if (bss_conf->use_short_preamble)
3134 wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_SHORT);
3135 else
3136 wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_LONG);
3137 }
3138
3139 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
3140 if (bss_conf->use_cts_prot)
3141 ret = wl1271_acx_cts_protect(wl, wlvif,
3142 CTSPROTECT_ENABLE);
3143 else
3144 ret = wl1271_acx_cts_protect(wl, wlvif,
3145 CTSPROTECT_DISABLE);
3146 if (ret < 0) {
3147 wl1271_warning("Set ctsprotect failed %d", ret);
3148 goto out;
3149 }
3150 }
3151
3152out:
3153 return ret;
3154}
3155
3156static int wl1271_bss_beacon_info_changed(struct wl1271 *wl,
3157 struct ieee80211_vif *vif,
3158 struct ieee80211_bss_conf *bss_conf,
3159 u32 changed)
3160{
3161 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3162 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
3163 int ret = 0;
3164
3165 if ((changed & BSS_CHANGED_BEACON_INT)) {
3166 wl1271_debug(DEBUG_MASTER, "beacon interval updated: %d",
3167 bss_conf->beacon_int);
3168
3169 wlvif->beacon_int = bss_conf->beacon_int;
3170 }
3171
3172 if ((changed & BSS_CHANGED_AP_PROBE_RESP) && is_ap) {
3173 u32 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
3174 if (!wl1271_ap_set_probe_resp_tmpl(wl, rate, vif)) {
3175 wl1271_debug(DEBUG_AP, "probe response updated");
3176 set_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags);
3177 }
3178 }
3179
3180 if ((changed & BSS_CHANGED_BEACON)) {
3181 struct ieee80211_hdr *hdr;
3182 u32 min_rate;
3183 int ieoffset = offsetof(struct ieee80211_mgmt,
3184 u.beacon.variable);
3185 struct sk_buff *beacon = ieee80211_beacon_get(wl->hw, vif);
3186 u16 tmpl_id;
3187
3188 if (!beacon) {
3189 ret = -EINVAL;
3190 goto out;
3191 }
3192
3193 wl1271_debug(DEBUG_MASTER, "beacon updated");
3194
3195 ret = wl1271_ssid_set(vif, beacon, ieoffset);
3196 if (ret < 0) {
3197 dev_kfree_skb(beacon);
3198 goto out;
3199 }
3200 min_rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
3201 tmpl_id = is_ap ? CMD_TEMPL_AP_BEACON :
3202 CMD_TEMPL_BEACON;
3203 ret = wl1271_cmd_template_set(wl, wlvif->role_id, tmpl_id,
3204 beacon->data,
3205 beacon->len, 0,
3206 min_rate);
3207 if (ret < 0) {
3208 dev_kfree_skb(beacon);
3209 goto out;
3210 }
3211
3212 /*
3213 * In case we already have a probe-resp beacon set explicitly
3214 * by usermode, don't use the beacon data.
3215 */
3216 if (test_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags))
3217 goto end_bcn;
3218
3219 /* remove TIM ie from probe response */
3220 wl12xx_remove_ie(beacon, WLAN_EID_TIM, ieoffset);
3221
3222 /*
3223 * remove p2p ie from probe response.
3224 * the fw reponds to probe requests that don't include
3225 * the p2p ie. probe requests with p2p ie will be passed,
3226 * and will be responded by the supplicant (the spec
3227 * forbids including the p2p ie when responding to probe
3228 * requests that didn't include it).
3229 */
3230 wl12xx_remove_vendor_ie(beacon, WLAN_OUI_WFA,
3231 WLAN_OUI_TYPE_WFA_P2P, ieoffset);
3232
3233 hdr = (struct ieee80211_hdr *) beacon->data;
3234 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3235 IEEE80211_STYPE_PROBE_RESP);
3236 if (is_ap)
3237 ret = wl1271_ap_set_probe_resp_tmpl_legacy(wl, vif,
3238 beacon->data,
3239 beacon->len,
3240 min_rate);
3241 else
3242 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
3243 CMD_TEMPL_PROBE_RESPONSE,
3244 beacon->data,
3245 beacon->len, 0,
3246 min_rate);
3247end_bcn:
3248 dev_kfree_skb(beacon);
3249 if (ret < 0)
3250 goto out;
3251 }
3252
3253out:
3254 if (ret != 0)
3255 wl1271_error("beacon info change failed: %d", ret);
3256 return ret;
3257}
3258
3259/* AP mode changes */
3260static void wl1271_bss_info_changed_ap(struct wl1271 *wl,
3261 struct ieee80211_vif *vif,
3262 struct ieee80211_bss_conf *bss_conf,
3263 u32 changed)
3264{
3265 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3266 int ret = 0;
3267
3268 if ((changed & BSS_CHANGED_BASIC_RATES)) {
3269 u32 rates = bss_conf->basic_rates;
3270
3271 wlvif->basic_rate_set = wl1271_tx_enabled_rates_get(wl, rates,
3272 wlvif->band);
3273 wlvif->basic_rate = wl1271_tx_min_rate_get(wl,
3274 wlvif->basic_rate_set);
3275
3276 ret = wl1271_init_ap_rates(wl, wlvif);
3277 if (ret < 0) {
3278 wl1271_error("AP rate policy change failed %d", ret);
3279 goto out;
3280 }
3281
3282 ret = wl1271_ap_init_templates(wl, vif);
3283 if (ret < 0)
3284 goto out;
3285 }
3286
3287 ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, changed);
3288 if (ret < 0)
3289 goto out;
3290
3291 if ((changed & BSS_CHANGED_BEACON_ENABLED)) {
3292 if (bss_conf->enable_beacon) {
3293 if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
3294 ret = wl12xx_cmd_role_start_ap(wl, wlvif);
3295 if (ret < 0)
3296 goto out;
3297
3298 ret = wl1271_ap_init_hwenc(wl, wlvif);
3299 if (ret < 0)
3300 goto out;
3301
3302 set_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags);
3303 wl1271_debug(DEBUG_AP, "started AP");
3304 }
3305 } else {
3306 if (test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
3307 ret = wl12xx_cmd_role_stop_ap(wl, wlvif);
3308 if (ret < 0)
3309 goto out;
3310
3311 clear_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags);
3312 clear_bit(WLVIF_FLAG_AP_PROBE_RESP_SET,
3313 &wlvif->flags);
3314 wl1271_debug(DEBUG_AP, "stopped AP");
3315 }
3316 }
3317 }
3318
3319 ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed);
3320 if (ret < 0)
3321 goto out;
3322
3323 /* Handle HT information change */
3324 if ((changed & BSS_CHANGED_HT) &&
3325 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
3326 ret = wl1271_acx_set_ht_information(wl, wlvif,
3327 bss_conf->ht_operation_mode);
3328 if (ret < 0) {
3329 wl1271_warning("Set ht information failed %d", ret);
3330 goto out;
3331 }
3332 }
3333
3334out:
3335 return;
3336}
3337
3338/* STA/IBSS mode changes */
3339static void wl1271_bss_info_changed_sta(struct wl1271 *wl,
3340 struct ieee80211_vif *vif,
3341 struct ieee80211_bss_conf *bss_conf,
3342 u32 changed)
3343{
3344 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3345 bool do_join = false, set_assoc = false;
3346 bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS);
3347 bool ibss_joined = false;
3348 u32 sta_rate_set = 0;
3349 int ret;
3350 struct ieee80211_sta *sta;
3351 bool sta_exists = false;
3352 struct ieee80211_sta_ht_cap sta_ht_cap;
3353
3354 if (is_ibss) {
3355 ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf,
3356 changed);
3357 if (ret < 0)
3358 goto out;
3359 }
3360
3361 if (changed & BSS_CHANGED_IBSS) {
3362 if (bss_conf->ibss_joined) {
3363 set_bit(WLVIF_FLAG_IBSS_JOINED, &wlvif->flags);
3364 ibss_joined = true;
3365 } else {
3366 if (test_and_clear_bit(WLVIF_FLAG_IBSS_JOINED,
3367 &wlvif->flags))
3368 wl1271_unjoin(wl, wlvif);
3369 }
3370 }
3371
3372 if ((changed & BSS_CHANGED_BEACON_INT) && ibss_joined)
3373 do_join = true;
3374
3375 /* Need to update the SSID (for filtering etc) */
3376 if ((changed & BSS_CHANGED_BEACON) && ibss_joined)
3377 do_join = true;
3378
3379 if ((changed & BSS_CHANGED_BEACON_ENABLED) && ibss_joined) {
3380 wl1271_debug(DEBUG_ADHOC, "ad-hoc beaconing: %s",
3381 bss_conf->enable_beacon ? "enabled" : "disabled");
3382
3383 do_join = true;
3384 }
3385
3386 if (changed & BSS_CHANGED_IDLE && !is_ibss) {
3387 ret = wl1271_sta_handle_idle(wl, wlvif, bss_conf->idle);
3388 if (ret < 0)
3389 wl1271_warning("idle mode change failed %d", ret);
3390 }
3391
3392 if ((changed & BSS_CHANGED_CQM)) {
3393 bool enable = false;
3394 if (bss_conf->cqm_rssi_thold)
3395 enable = true;
3396 ret = wl1271_acx_rssi_snr_trigger(wl, wlvif, enable,
3397 bss_conf->cqm_rssi_thold,
3398 bss_conf->cqm_rssi_hyst);
3399 if (ret < 0)
3400 goto out;
3401 wlvif->rssi_thold = bss_conf->cqm_rssi_thold;
3402 }
3403
3404 if (changed & BSS_CHANGED_BSSID)
3405 if (!is_zero_ether_addr(bss_conf->bssid)) {
3406 ret = wl12xx_cmd_build_null_data(wl, wlvif);
3407 if (ret < 0)
3408 goto out;
3409
3410 ret = wl1271_build_qos_null_data(wl, vif);
3411 if (ret < 0)
3412 goto out;
3413 }
3414
3415 if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_HT)) {
3416 rcu_read_lock();
3417 sta = ieee80211_find_sta(vif, bss_conf->bssid);
3418 if (!sta)
3419 goto sta_not_found;
3420
3421 /* save the supp_rates of the ap */
3422 sta_rate_set = sta->supp_rates[wl->hw->conf.channel->band];
3423 if (sta->ht_cap.ht_supported)
3424 sta_rate_set |=
3425 (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET);
3426 sta_ht_cap = sta->ht_cap;
3427 sta_exists = true;
3428
3429sta_not_found:
3430 rcu_read_unlock();
3431 }
3432
3433 if ((changed & BSS_CHANGED_ASSOC)) {
3434 if (bss_conf->assoc) {
3435 u32 rates;
3436 int ieoffset;
3437 wlvif->aid = bss_conf->aid;
3438 wlvif->beacon_int = bss_conf->beacon_int;
3439 do_join = true;
3440 set_assoc = true;
3441
3442 /*
3443 * use basic rates from AP, and determine lowest rate
3444 * to use with control frames.
3445 */
3446 rates = bss_conf->basic_rates;
3447 wlvif->basic_rate_set =
3448 wl1271_tx_enabled_rates_get(wl, rates,
3449 wlvif->band);
3450 wlvif->basic_rate =
3451 wl1271_tx_min_rate_get(wl,
3452 wlvif->basic_rate_set);
3453 if (sta_rate_set)
3454 wlvif->rate_set =
3455 wl1271_tx_enabled_rates_get(wl,
3456 sta_rate_set,
3457 wlvif->band);
3458 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
3459 if (ret < 0)
3460 goto out;
3461
3462 /*
3463 * with wl1271, we don't need to update the
3464 * beacon_int and dtim_period, because the firmware
3465 * updates it by itself when the first beacon is
3466 * received after a join.
3467 */
3468 ret = wl1271_cmd_build_ps_poll(wl, wlvif, wlvif->aid);
3469 if (ret < 0)
3470 goto out;
3471
3472 /*
3473 * Get a template for hardware connection maintenance
3474 */
3475 dev_kfree_skb(wlvif->probereq);
3476 wlvif->probereq = wl1271_cmd_build_ap_probe_req(wl,
3477 wlvif,
3478 NULL);
3479 ieoffset = offsetof(struct ieee80211_mgmt,
3480 u.probe_req.variable);
3481 wl1271_ssid_set(vif, wlvif->probereq, ieoffset);
3482
3483 /* enable the connection monitoring feature */
3484 ret = wl1271_acx_conn_monit_params(wl, wlvif, true);
3485 if (ret < 0)
3486 goto out;
3487 } else {
3488 /* use defaults when not associated */
3489 bool was_assoc =
3490 !!test_and_clear_bit(WLVIF_FLAG_STA_ASSOCIATED,
3491 &wlvif->flags);
3492 bool was_ifup =
3493 !!test_and_clear_bit(WLVIF_FLAG_STA_STATE_SENT,
3494 &wlvif->flags);
3495 wlvif->aid = 0;
3496
3497 /* free probe-request template */
3498 dev_kfree_skb(wlvif->probereq);
3499 wlvif->probereq = NULL;
3500
3501 /* revert back to minimum rates for the current band */
3502 wl1271_set_band_rate(wl, wlvif);
3503 wlvif->basic_rate =
3504 wl1271_tx_min_rate_get(wl,
3505 wlvif->basic_rate_set);
3506 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
3507 if (ret < 0)
3508 goto out;
3509
3510 /* disable connection monitor features */
3511 ret = wl1271_acx_conn_monit_params(wl, wlvif, false);
3512
3513 /* Disable the keep-alive feature */
3514 ret = wl1271_acx_keep_alive_mode(wl, wlvif, false);
3515 if (ret < 0)
3516 goto out;
3517
3518 /* restore the bssid filter and go to dummy bssid */
3519 if (was_assoc) {
3520 /*
3521 * we might have to disable roc, if there was
3522 * no IF_OPER_UP notification.
3523 */
3524 if (!was_ifup) {
3525 ret = wl12xx_croc(wl, wlvif->role_id);
3526 if (ret < 0)
3527 goto out;
3528 }
3529 /*
3530 * (we also need to disable roc in case of
3531 * roaming on the same channel. until we will
3532 * have a better flow...)
3533 */
3534 if (test_bit(wlvif->dev_role_id, wl->roc_map)) {
3535 ret = wl12xx_croc(wl,
3536 wlvif->dev_role_id);
3537 if (ret < 0)
3538 goto out;
3539 }
3540
3541 wl1271_unjoin(wl, wlvif);
3542 if (!bss_conf->idle)
3543 wl12xx_start_dev(wl, wlvif);
3544 }
3545 }
3546 }
3547
3548 if (changed & BSS_CHANGED_IBSS) {
3549 wl1271_debug(DEBUG_ADHOC, "ibss_joined: %d",
3550 bss_conf->ibss_joined);
3551
3552 if (bss_conf->ibss_joined) {
3553 u32 rates = bss_conf->basic_rates;
3554 wlvif->basic_rate_set =
3555 wl1271_tx_enabled_rates_get(wl, rates,
3556 wlvif->band);
3557 wlvif->basic_rate =
3558 wl1271_tx_min_rate_get(wl,
3559 wlvif->basic_rate_set);
3560
3561 /* by default, use 11b + OFDM rates */
3562 wlvif->rate_set = CONF_TX_IBSS_DEFAULT_RATES;
3563 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
3564 if (ret < 0)
3565 goto out;
3566 }
3567 }
3568
3569 ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed);
3570 if (ret < 0)
3571 goto out;
3572
3573 if (do_join) {
3574 ret = wl1271_join(wl, wlvif, set_assoc);
3575 if (ret < 0) {
3576 wl1271_warning("cmd join failed %d", ret);
3577 goto out;
3578 }
3579
3580 /* ROC until connected (after EAPOL exchange) */
3581 if (!is_ibss) {
3582 ret = wl12xx_roc(wl, wlvif, wlvif->role_id);
3583 if (ret < 0)
3584 goto out;
3585
3586 if (test_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags))
3587 wl12xx_set_authorized(wl, wlvif);
3588 }
3589 /*
3590 * stop device role if started (we might already be in
3591 * STA/IBSS role).
3592 */
3593 if (wl12xx_dev_role_started(wlvif)) {
3594 ret = wl12xx_stop_dev(wl, wlvif);
3595 if (ret < 0)
3596 goto out;
3597 }
3598 }
3599
3600 /* Handle new association with HT. Do this after join. */
3601 if (sta_exists) {
3602 if ((changed & BSS_CHANGED_HT) &&
3603 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
3604 ret = wl1271_acx_set_ht_capabilities(wl,
3605 &sta_ht_cap,
3606 true,
3607 wlvif->sta.hlid);
3608 if (ret < 0) {
3609 wl1271_warning("Set ht cap true failed %d",
3610 ret);
3611 goto out;
3612 }
3613 }
3614 /* handle new association without HT and disassociation */
3615 else if (changed & BSS_CHANGED_ASSOC) {
3616 ret = wl1271_acx_set_ht_capabilities(wl,
3617 &sta_ht_cap,
3618 false,
3619 wlvif->sta.hlid);
3620 if (ret < 0) {
3621 wl1271_warning("Set ht cap false failed %d",
3622 ret);
3623 goto out;
3624 }
3625 }
3626 }
3627
3628 /* Handle HT information change. Done after join. */
3629 if ((changed & BSS_CHANGED_HT) &&
3630 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
3631 ret = wl1271_acx_set_ht_information(wl, wlvif,
3632 bss_conf->ht_operation_mode);
3633 if (ret < 0) {
3634 wl1271_warning("Set ht information failed %d", ret);
3635 goto out;
3636 }
3637 }
3638
3639 /* Handle arp filtering. Done after join. */
3640 if ((changed & BSS_CHANGED_ARP_FILTER) ||
3641 (!is_ibss && (changed & BSS_CHANGED_QOS))) {
3642 __be32 addr = bss_conf->arp_addr_list[0];
3643 wlvif->sta.qos = bss_conf->qos;
3644 WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS);
3645
3646 if (bss_conf->arp_addr_cnt == 1 &&
3647 bss_conf->arp_filter_enabled) {
3648 wlvif->ip_addr = addr;
3649 /*
3650 * The template should have been configured only upon
3651 * association. however, it seems that the correct ip
3652 * isn't being set (when sending), so we have to
3653 * reconfigure the template upon every ip change.
3654 */
3655 ret = wl1271_cmd_build_arp_rsp(wl, wlvif);
3656 if (ret < 0) {
3657 wl1271_warning("build arp rsp failed: %d", ret);
3658 goto out;
3659 }
3660
3661 ret = wl1271_acx_arp_ip_filter(wl, wlvif,
3662 (ACX_ARP_FILTER_ARP_FILTERING |
3663 ACX_ARP_FILTER_AUTO_ARP),
3664 addr);
3665 } else {
3666 wlvif->ip_addr = 0;
3667 ret = wl1271_acx_arp_ip_filter(wl, wlvif, 0, addr);
3668 }
3669
3670 if (ret < 0)
3671 goto out;
3672 }
3673
3674out:
3675 return;
3676}
3677
3678static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
3679 struct ieee80211_vif *vif,
3680 struct ieee80211_bss_conf *bss_conf,
3681 u32 changed)
3682{
3683 struct wl1271 *wl = hw->priv;
3684 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3685 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
3686 int ret;
3687
3688 wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed 0x%x",
3689 (int)changed);
3690
3691 mutex_lock(&wl->mutex);
3692
3693 if (unlikely(wl->state == WL1271_STATE_OFF))
3694 goto out;
3695
3696 if (unlikely(!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)))
3697 goto out;
3698
3699 ret = wl1271_ps_elp_wakeup(wl);
3700 if (ret < 0)
3701 goto out;
3702
3703 if (is_ap)
3704 wl1271_bss_info_changed_ap(wl, vif, bss_conf, changed);
3705 else
3706 wl1271_bss_info_changed_sta(wl, vif, bss_conf, changed);
3707
3708 wl1271_ps_elp_sleep(wl);
3709
3710out:
3711 mutex_unlock(&wl->mutex);
3712}
3713
3714static int wl1271_op_conf_tx(struct ieee80211_hw *hw,
3715 struct ieee80211_vif *vif, u16 queue,
3716 const struct ieee80211_tx_queue_params *params)
3717{
3718 struct wl1271 *wl = hw->priv;
3719 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3720 u8 ps_scheme;
3721 int ret = 0;
3722
3723 mutex_lock(&wl->mutex);
3724
3725 wl1271_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue);
3726
3727 if (params->uapsd)
3728 ps_scheme = CONF_PS_SCHEME_UPSD_TRIGGER;
3729 else
3730 ps_scheme = CONF_PS_SCHEME_LEGACY;
3731
3732 if (!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
3733 goto out;
3734
3735 ret = wl1271_ps_elp_wakeup(wl);
3736 if (ret < 0)
3737 goto out;
3738
3739 /*
3740 * the txop is confed in units of 32us by the mac80211,
3741 * we need us
3742 */
3743 ret = wl1271_acx_ac_cfg(wl, wlvif, wl1271_tx_get_queue(queue),
3744 params->cw_min, params->cw_max,
3745 params->aifs, params->txop << 5);
3746 if (ret < 0)
3747 goto out_sleep;
3748
3749 ret = wl1271_acx_tid_cfg(wl, wlvif, wl1271_tx_get_queue(queue),
3750 CONF_CHANNEL_TYPE_EDCF,
3751 wl1271_tx_get_queue(queue),
3752 ps_scheme, CONF_ACK_POLICY_LEGACY,
3753 0, 0);
3754
3755out_sleep:
3756 wl1271_ps_elp_sleep(wl);
3757
3758out:
3759 mutex_unlock(&wl->mutex);
3760
3761 return ret;
3762}
3763
3764static u64 wl1271_op_get_tsf(struct ieee80211_hw *hw,
3765 struct ieee80211_vif *vif)
3766{
3767
3768 struct wl1271 *wl = hw->priv;
3769 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3770 u64 mactime = ULLONG_MAX;
3771 int ret;
3772
3773 wl1271_debug(DEBUG_MAC80211, "mac80211 get tsf");
3774
3775 mutex_lock(&wl->mutex);
3776
3777 if (unlikely(wl->state == WL1271_STATE_OFF))
3778 goto out;
3779
3780 ret = wl1271_ps_elp_wakeup(wl);
3781 if (ret < 0)
3782 goto out;
3783
3784 ret = wl12xx_acx_tsf_info(wl, wlvif, &mactime);
3785 if (ret < 0)
3786 goto out_sleep;
3787
3788out_sleep:
3789 wl1271_ps_elp_sleep(wl);
3790
3791out:
3792 mutex_unlock(&wl->mutex);
3793 return mactime;
3794}
3795
3796static int wl1271_op_get_survey(struct ieee80211_hw *hw, int idx,
3797 struct survey_info *survey)
3798{
3799 struct wl1271 *wl = hw->priv;
3800 struct ieee80211_conf *conf = &hw->conf;
3801
3802 if (idx != 0)
3803 return -ENOENT;
3804
3805 survey->channel = conf->channel;
3806 survey->filled = SURVEY_INFO_NOISE_DBM;
3807 survey->noise = wl->noise;
3808
3809 return 0;
3810}
3811
3812static int wl1271_allocate_sta(struct wl1271 *wl,
3813 struct wl12xx_vif *wlvif,
3814 struct ieee80211_sta *sta)
3815{
3816 struct wl1271_station *wl_sta;
3817 int ret;
3818
3819
3820 if (wl->active_sta_count >= AP_MAX_STATIONS) {
3821 wl1271_warning("could not allocate HLID - too much stations");
3822 return -EBUSY;
3823 }
3824
3825 wl_sta = (struct wl1271_station *)sta->drv_priv;
3826 ret = wl12xx_allocate_link(wl, wlvif, &wl_sta->hlid);
3827 if (ret < 0) {
3828 wl1271_warning("could not allocate HLID - too many links");
3829 return -EBUSY;
3830 }
3831
3832 set_bit(wl_sta->hlid, wlvif->ap.sta_hlid_map);
3833 memcpy(wl->links[wl_sta->hlid].addr, sta->addr, ETH_ALEN);
3834 wl->active_sta_count++;
3835 return 0;
3836}
3837
3838void wl1271_free_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid)
3839{
3840 if (!test_bit(hlid, wlvif->ap.sta_hlid_map))
3841 return;
3842
3843 clear_bit(hlid, wlvif->ap.sta_hlid_map);
3844 memset(wl->links[hlid].addr, 0, ETH_ALEN);
3845 wl->links[hlid].ba_bitmap = 0;
3846 __clear_bit(hlid, &wl->ap_ps_map);
3847 __clear_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
3848 wl12xx_free_link(wl, wlvif, &hlid);
3849 wl->active_sta_count--;
3850
3851 /*
3852 * rearm the tx watchdog when the last STA is freed - give the FW a
3853 * chance to return STA-buffered packets before complaining.
3854 */
3855 if (wl->active_sta_count == 0)
3856 wl12xx_rearm_tx_watchdog_locked(wl);
3857}
3858
3859static int wl12xx_sta_add(struct wl1271 *wl,
3860 struct wl12xx_vif *wlvif,
3861 struct ieee80211_sta *sta)
3862{
3863 struct wl1271_station *wl_sta;
3864 int ret = 0;
3865 u8 hlid;
3866
3867 wl1271_debug(DEBUG_MAC80211, "mac80211 add sta %d", (int)sta->aid);
3868
3869 ret = wl1271_allocate_sta(wl, wlvif, sta);
3870 if (ret < 0)
3871 return ret;
3872
3873 wl_sta = (struct wl1271_station *)sta->drv_priv;
3874 hlid = wl_sta->hlid;
3875
3876 ret = wl12xx_cmd_add_peer(wl, wlvif, sta, hlid);
3877 if (ret < 0)
3878 wl1271_free_sta(wl, wlvif, hlid);
3879
3880 return ret;
3881}
3882
3883static int wl12xx_sta_remove(struct wl1271 *wl,
3884 struct wl12xx_vif *wlvif,
3885 struct ieee80211_sta *sta)
3886{
3887 struct wl1271_station *wl_sta;
3888 int ret = 0, id;
3889
3890 wl1271_debug(DEBUG_MAC80211, "mac80211 remove sta %d", (int)sta->aid);
3891
3892 wl_sta = (struct wl1271_station *)sta->drv_priv;
3893 id = wl_sta->hlid;
3894 if (WARN_ON(!test_bit(id, wlvif->ap.sta_hlid_map)))
3895 return -EINVAL;
3896
3897 ret = wl12xx_cmd_remove_peer(wl, wl_sta->hlid);
3898 if (ret < 0)
3899 return ret;
3900
3901 wl1271_free_sta(wl, wlvif, wl_sta->hlid);
3902 return ret;
3903}
3904
3905static int wl12xx_update_sta_state(struct wl1271 *wl,
3906 struct wl12xx_vif *wlvif,
3907 struct ieee80211_sta *sta,
3908 enum ieee80211_sta_state old_state,
3909 enum ieee80211_sta_state new_state)
3910{
3911 struct wl1271_station *wl_sta;
3912 u8 hlid;
3913 bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS;
3914 bool is_sta = wlvif->bss_type == BSS_TYPE_STA_BSS;
3915 int ret;
3916
3917 wl_sta = (struct wl1271_station *)sta->drv_priv;
3918 hlid = wl_sta->hlid;
3919
3920 /* Add station (AP mode) */
3921 if (is_ap &&
3922 old_state == IEEE80211_STA_NOTEXIST &&
3923 new_state == IEEE80211_STA_NONE)
3924 return wl12xx_sta_add(wl, wlvif, sta);
3925
3926 /* Remove station (AP mode) */
3927 if (is_ap &&
3928 old_state == IEEE80211_STA_NONE &&
3929 new_state == IEEE80211_STA_NOTEXIST) {
3930 /* must not fail */
3931 wl12xx_sta_remove(wl, wlvif, sta);
3932 return 0;
3933 }
3934
3935 /* Authorize station (AP mode) */
3936 if (is_ap &&
3937 new_state == IEEE80211_STA_AUTHORIZED) {
3938 ret = wl12xx_cmd_set_peer_state(wl, hlid);
3939 if (ret < 0)
3940 return ret;
3941
3942 ret = wl1271_acx_set_ht_capabilities(wl, &sta->ht_cap, true,
3943 hlid);
3944 return ret;
3945 }
3946
3947 /* Authorize station */
3948 if (is_sta &&
3949 new_state == IEEE80211_STA_AUTHORIZED) {
3950 set_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags);
3951 return wl12xx_set_authorized(wl, wlvif);
3952 }
3953
3954 if (is_sta &&
3955 old_state == IEEE80211_STA_AUTHORIZED &&
3956 new_state == IEEE80211_STA_ASSOC) {
3957 clear_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags);
3958 return 0;
3959 }
3960
3961 return 0;
3962}
3963
3964static int wl12xx_op_sta_state(struct ieee80211_hw *hw,
3965 struct ieee80211_vif *vif,
3966 struct ieee80211_sta *sta,
3967 enum ieee80211_sta_state old_state,
3968 enum ieee80211_sta_state new_state)
3969{
3970 struct wl1271 *wl = hw->priv;
3971 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3972 int ret;
3973
3974 wl1271_debug(DEBUG_MAC80211, "mac80211 sta %d state=%d->%d",
3975 sta->aid, old_state, new_state);
3976
3977 mutex_lock(&wl->mutex);
3978
3979 if (unlikely(wl->state == WL1271_STATE_OFF)) {
3980 ret = -EBUSY;
3981 goto out;
3982 }
3983
3984 ret = wl1271_ps_elp_wakeup(wl);
3985 if (ret < 0)
3986 goto out;
3987
3988 ret = wl12xx_update_sta_state(wl, wlvif, sta, old_state, new_state);
3989
3990 wl1271_ps_elp_sleep(wl);
3991out:
3992 mutex_unlock(&wl->mutex);
3993 if (new_state < old_state)
3994 return 0;
3995 return ret;
3996}
3997
3998static int wl1271_op_ampdu_action(struct ieee80211_hw *hw,
3999 struct ieee80211_vif *vif,
4000 enum ieee80211_ampdu_mlme_action action,
4001 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4002 u8 buf_size)
4003{
4004 struct wl1271 *wl = hw->priv;
4005 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
4006 int ret;
4007 u8 hlid, *ba_bitmap;
4008
4009 wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu action %d tid %d", action,
4010 tid);
4011
4012 /* sanity check - the fields in FW are only 8bits wide */
4013 if (WARN_ON(tid > 0xFF))
4014 return -ENOTSUPP;
4015
4016 mutex_lock(&wl->mutex);
4017
4018 if (unlikely(wl->state == WL1271_STATE_OFF)) {
4019 ret = -EAGAIN;
4020 goto out;
4021 }
4022
4023 if (wlvif->bss_type == BSS_TYPE_STA_BSS) {
4024 hlid = wlvif->sta.hlid;
4025 ba_bitmap = &wlvif->sta.ba_rx_bitmap;
4026 } else if (wlvif->bss_type == BSS_TYPE_AP_BSS) {
4027 struct wl1271_station *wl_sta;
4028
4029 wl_sta = (struct wl1271_station *)sta->drv_priv;
4030 hlid = wl_sta->hlid;
4031 ba_bitmap = &wl->links[hlid].ba_bitmap;
4032 } else {
4033 ret = -EINVAL;
4034 goto out;
4035 }
4036
4037 ret = wl1271_ps_elp_wakeup(wl);
4038 if (ret < 0)
4039 goto out;
4040
4041 wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu: Rx tid %d action %d",
4042 tid, action);
4043
4044 switch (action) {
4045 case IEEE80211_AMPDU_RX_START:
4046 if (!wlvif->ba_support || !wlvif->ba_allowed) {
4047 ret = -ENOTSUPP;
4048 break;
4049 }
4050
4051 if (wl->ba_rx_session_count >= RX_BA_MAX_SESSIONS) {
4052 ret = -EBUSY;
4053 wl1271_error("exceeded max RX BA sessions");
4054 break;
4055 }
4056
4057 if (*ba_bitmap & BIT(tid)) {
4058 ret = -EINVAL;
4059 wl1271_error("cannot enable RX BA session on active "
4060 "tid: %d", tid);
4061 break;
4062 }
4063
4064 ret = wl12xx_acx_set_ba_receiver_session(wl, tid, *ssn, true,
4065 hlid);
4066 if (!ret) {
4067 *ba_bitmap |= BIT(tid);
4068 wl->ba_rx_session_count++;
4069 }
4070 break;
4071
4072 case IEEE80211_AMPDU_RX_STOP:
4073 if (!(*ba_bitmap & BIT(tid))) {
4074 ret = -EINVAL;
4075 wl1271_error("no active RX BA session on tid: %d",
4076 tid);
4077 break;
4078 }
4079
4080 ret = wl12xx_acx_set_ba_receiver_session(wl, tid, 0, false,
4081 hlid);
4082 if (!ret) {
4083 *ba_bitmap &= ~BIT(tid);
4084 wl->ba_rx_session_count--;
4085 }
4086 break;
4087
4088 /*
4089 * The BA initiator session management in FW independently.
4090 * Falling break here on purpose for all TX APDU commands.
4091 */
4092 case IEEE80211_AMPDU_TX_START:
4093 case IEEE80211_AMPDU_TX_STOP:
4094 case IEEE80211_AMPDU_TX_OPERATIONAL:
4095 ret = -EINVAL;
4096 break;
4097
4098 default:
4099 wl1271_error("Incorrect ampdu action id=%x\n", action);
4100 ret = -EINVAL;
4101 }
4102
4103 wl1271_ps_elp_sleep(wl);
4104
4105out:
4106 mutex_unlock(&wl->mutex);
4107
4108 return ret;
4109}
4110
4111static int wl12xx_set_bitrate_mask(struct ieee80211_hw *hw,
4112 struct ieee80211_vif *vif,
4113 const struct cfg80211_bitrate_mask *mask)
4114{
4115 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
4116 struct wl1271 *wl = hw->priv;
4117 int i, ret = 0;
4118
4119 wl1271_debug(DEBUG_MAC80211, "mac80211 set_bitrate_mask 0x%x 0x%x",
4120 mask->control[NL80211_BAND_2GHZ].legacy,
4121 mask->control[NL80211_BAND_5GHZ].legacy);
4122
4123 mutex_lock(&wl->mutex);
4124
4125 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
4126 wlvif->bitrate_masks[i] =
4127 wl1271_tx_enabled_rates_get(wl,
4128 mask->control[i].legacy,
4129 i);
4130
4131 if (unlikely(wl->state == WL1271_STATE_OFF))
4132 goto out;
4133
4134 if (wlvif->bss_type == BSS_TYPE_STA_BSS &&
4135 !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) {
4136
4137 ret = wl1271_ps_elp_wakeup(wl);
4138 if (ret < 0)
4139 goto out;
4140
4141 wl1271_set_band_rate(wl, wlvif);
4142 wlvif->basic_rate =
4143 wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
4144 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
4145
4146 wl1271_ps_elp_sleep(wl);
4147 }
4148out:
4149 mutex_unlock(&wl->mutex);
4150
4151 return ret;
4152}
4153
4154static void wl12xx_op_channel_switch(struct ieee80211_hw *hw,
4155 struct ieee80211_channel_switch *ch_switch)
4156{
4157 struct wl1271 *wl = hw->priv;
4158 struct wl12xx_vif *wlvif;
4159 int ret;
4160
4161 wl1271_debug(DEBUG_MAC80211, "mac80211 channel switch");
4162
4163 wl1271_tx_flush(wl);
4164
4165 mutex_lock(&wl->mutex);
4166
4167 if (unlikely(wl->state == WL1271_STATE_OFF)) {
4168 wl12xx_for_each_wlvif_sta(wl, wlvif) {
4169 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
4170 ieee80211_chswitch_done(vif, false);
4171 }
4172 goto out;
4173 }
4174
4175 ret = wl1271_ps_elp_wakeup(wl);
4176 if (ret < 0)
4177 goto out;
4178
4179 /* TODO: change mac80211 to pass vif as param */
4180 wl12xx_for_each_wlvif_sta(wl, wlvif) {
4181 ret = wl12xx_cmd_channel_switch(wl, wlvif, ch_switch);
4182
4183 if (!ret)
4184 set_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags);
4185 }
4186
4187 wl1271_ps_elp_sleep(wl);
4188
4189out:
4190 mutex_unlock(&wl->mutex);
4191}
4192
4193static bool wl1271_tx_frames_pending(struct ieee80211_hw *hw)
4194{
4195 struct wl1271 *wl = hw->priv;
4196 bool ret = false;
4197
4198 mutex_lock(&wl->mutex);
4199
4200 if (unlikely(wl->state == WL1271_STATE_OFF))
4201 goto out;
4202
4203 /* packets are considered pending if in the TX queue or the FW */
4204 ret = (wl1271_tx_total_queue_count(wl) > 0) || (wl->tx_frames_cnt > 0);
4205out:
4206 mutex_unlock(&wl->mutex);
4207
4208 return ret;
4209}
4210
4211/* can't be const, mac80211 writes to this */
4212static struct ieee80211_rate wl1271_rates[] = {
4213 { .bitrate = 10,
4214 .hw_value = CONF_HW_BIT_RATE_1MBPS,
4215 .hw_value_short = CONF_HW_BIT_RATE_1MBPS, },
4216 { .bitrate = 20,
4217 .hw_value = CONF_HW_BIT_RATE_2MBPS,
4218 .hw_value_short = CONF_HW_BIT_RATE_2MBPS,
4219 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
4220 { .bitrate = 55,
4221 .hw_value = CONF_HW_BIT_RATE_5_5MBPS,
4222 .hw_value_short = CONF_HW_BIT_RATE_5_5MBPS,
4223 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
4224 { .bitrate = 110,
4225 .hw_value = CONF_HW_BIT_RATE_11MBPS,
4226 .hw_value_short = CONF_HW_BIT_RATE_11MBPS,
4227 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
4228 { .bitrate = 60,
4229 .hw_value = CONF_HW_BIT_RATE_6MBPS,
4230 .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
4231 { .bitrate = 90,
4232 .hw_value = CONF_HW_BIT_RATE_9MBPS,
4233 .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
4234 { .bitrate = 120,
4235 .hw_value = CONF_HW_BIT_RATE_12MBPS,
4236 .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
4237 { .bitrate = 180,
4238 .hw_value = CONF_HW_BIT_RATE_18MBPS,
4239 .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
4240 { .bitrate = 240,
4241 .hw_value = CONF_HW_BIT_RATE_24MBPS,
4242 .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
4243 { .bitrate = 360,
4244 .hw_value = CONF_HW_BIT_RATE_36MBPS,
4245 .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
4246 { .bitrate = 480,
4247 .hw_value = CONF_HW_BIT_RATE_48MBPS,
4248 .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
4249 { .bitrate = 540,
4250 .hw_value = CONF_HW_BIT_RATE_54MBPS,
4251 .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
4252};
4253
4254/* can't be const, mac80211 writes to this */
4255static struct ieee80211_channel wl1271_channels[] = {
4256 { .hw_value = 1, .center_freq = 2412, .max_power = 25 },
4257 { .hw_value = 2, .center_freq = 2417, .max_power = 25 },
4258 { .hw_value = 3, .center_freq = 2422, .max_power = 25 },
4259 { .hw_value = 4, .center_freq = 2427, .max_power = 25 },
4260 { .hw_value = 5, .center_freq = 2432, .max_power = 25 },
4261 { .hw_value = 6, .center_freq = 2437, .max_power = 25 },
4262 { .hw_value = 7, .center_freq = 2442, .max_power = 25 },
4263 { .hw_value = 8, .center_freq = 2447, .max_power = 25 },
4264 { .hw_value = 9, .center_freq = 2452, .max_power = 25 },
4265 { .hw_value = 10, .center_freq = 2457, .max_power = 25 },
4266 { .hw_value = 11, .center_freq = 2462, .max_power = 25 },
4267 { .hw_value = 12, .center_freq = 2467, .max_power = 25 },
4268 { .hw_value = 13, .center_freq = 2472, .max_power = 25 },
4269 { .hw_value = 14, .center_freq = 2484, .max_power = 25 },
4270};
4271
4272/* can't be const, mac80211 writes to this */
4273static struct ieee80211_supported_band wl1271_band_2ghz = {
4274 .channels = wl1271_channels,
4275 .n_channels = ARRAY_SIZE(wl1271_channels),
4276 .bitrates = wl1271_rates,
4277 .n_bitrates = ARRAY_SIZE(wl1271_rates),
4278};
4279
4280/* 5 GHz data rates for WL1273 */
4281static struct ieee80211_rate wl1271_rates_5ghz[] = {
4282 { .bitrate = 60,
4283 .hw_value = CONF_HW_BIT_RATE_6MBPS,
4284 .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
4285 { .bitrate = 90,
4286 .hw_value = CONF_HW_BIT_RATE_9MBPS,
4287 .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
4288 { .bitrate = 120,
4289 .hw_value = CONF_HW_BIT_RATE_12MBPS,
4290 .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
4291 { .bitrate = 180,
4292 .hw_value = CONF_HW_BIT_RATE_18MBPS,
4293 .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
4294 { .bitrate = 240,
4295 .hw_value = CONF_HW_BIT_RATE_24MBPS,
4296 .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
4297 { .bitrate = 360,
4298 .hw_value = CONF_HW_BIT_RATE_36MBPS,
4299 .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
4300 { .bitrate = 480,
4301 .hw_value = CONF_HW_BIT_RATE_48MBPS,
4302 .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
4303 { .bitrate = 540,
4304 .hw_value = CONF_HW_BIT_RATE_54MBPS,
4305 .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
4306};
4307
4308/* 5 GHz band channels for WL1273 */
4309static struct ieee80211_channel wl1271_channels_5ghz[] = {
4310 { .hw_value = 7, .center_freq = 5035, .max_power = 25 },
4311 { .hw_value = 8, .center_freq = 5040, .max_power = 25 },
4312 { .hw_value = 9, .center_freq = 5045, .max_power = 25 },
4313 { .hw_value = 11, .center_freq = 5055, .max_power = 25 },
4314 { .hw_value = 12, .center_freq = 5060, .max_power = 25 },
4315 { .hw_value = 16, .center_freq = 5080, .max_power = 25 },
4316 { .hw_value = 34, .center_freq = 5170, .max_power = 25 },
4317 { .hw_value = 36, .center_freq = 5180, .max_power = 25 },
4318 { .hw_value = 38, .center_freq = 5190, .max_power = 25 },
4319 { .hw_value = 40, .center_freq = 5200, .max_power = 25 },
4320 { .hw_value = 42, .center_freq = 5210, .max_power = 25 },
4321 { .hw_value = 44, .center_freq = 5220, .max_power = 25 },
4322 { .hw_value = 46, .center_freq = 5230, .max_power = 25 },
4323 { .hw_value = 48, .center_freq = 5240, .max_power = 25 },
4324 { .hw_value = 52, .center_freq = 5260, .max_power = 25 },
4325 { .hw_value = 56, .center_freq = 5280, .max_power = 25 },
4326 { .hw_value = 60, .center_freq = 5300, .max_power = 25 },
4327 { .hw_value = 64, .center_freq = 5320, .max_power = 25 },
4328 { .hw_value = 100, .center_freq = 5500, .max_power = 25 },
4329 { .hw_value = 104, .center_freq = 5520, .max_power = 25 },
4330 { .hw_value = 108, .center_freq = 5540, .max_power = 25 },
4331 { .hw_value = 112, .center_freq = 5560, .max_power = 25 },
4332 { .hw_value = 116, .center_freq = 5580, .max_power = 25 },
4333 { .hw_value = 120, .center_freq = 5600, .max_power = 25 },
4334 { .hw_value = 124, .center_freq = 5620, .max_power = 25 },
4335 { .hw_value = 128, .center_freq = 5640, .max_power = 25 },
4336 { .hw_value = 132, .center_freq = 5660, .max_power = 25 },
4337 { .hw_value = 136, .center_freq = 5680, .max_power = 25 },
4338 { .hw_value = 140, .center_freq = 5700, .max_power = 25 },
4339 { .hw_value = 149, .center_freq = 5745, .max_power = 25 },
4340 { .hw_value = 153, .center_freq = 5765, .max_power = 25 },
4341 { .hw_value = 157, .center_freq = 5785, .max_power = 25 },
4342 { .hw_value = 161, .center_freq = 5805, .max_power = 25 },
4343 { .hw_value = 165, .center_freq = 5825, .max_power = 25 },
4344};
4345
4346static struct ieee80211_supported_band wl1271_band_5ghz = {
4347 .channels = wl1271_channels_5ghz,
4348 .n_channels = ARRAY_SIZE(wl1271_channels_5ghz),
4349 .bitrates = wl1271_rates_5ghz,
4350 .n_bitrates = ARRAY_SIZE(wl1271_rates_5ghz),
4351};
4352
4353static const struct ieee80211_ops wl1271_ops = {
4354 .start = wl1271_op_start,
4355 .stop = wl1271_op_stop,
4356 .add_interface = wl1271_op_add_interface,
4357 .remove_interface = wl1271_op_remove_interface,
4358 .change_interface = wl12xx_op_change_interface,
4359#ifdef CONFIG_PM
4360 .suspend = wl1271_op_suspend,
4361 .resume = wl1271_op_resume,
4362#endif
4363 .config = wl1271_op_config,
4364 .prepare_multicast = wl1271_op_prepare_multicast,
4365 .configure_filter = wl1271_op_configure_filter,
4366 .tx = wl1271_op_tx,
4367 .set_key = wl1271_op_set_key,
4368 .hw_scan = wl1271_op_hw_scan,
4369 .cancel_hw_scan = wl1271_op_cancel_hw_scan,
4370 .sched_scan_start = wl1271_op_sched_scan_start,
4371 .sched_scan_stop = wl1271_op_sched_scan_stop,
4372 .bss_info_changed = wl1271_op_bss_info_changed,
4373 .set_frag_threshold = wl1271_op_set_frag_threshold,
4374 .set_rts_threshold = wl1271_op_set_rts_threshold,
4375 .conf_tx = wl1271_op_conf_tx,
4376 .get_tsf = wl1271_op_get_tsf,
4377 .get_survey = wl1271_op_get_survey,
4378 .sta_state = wl12xx_op_sta_state,
4379 .ampdu_action = wl1271_op_ampdu_action,
4380 .tx_frames_pending = wl1271_tx_frames_pending,
4381 .set_bitrate_mask = wl12xx_set_bitrate_mask,
4382 .channel_switch = wl12xx_op_channel_switch,
4383 CFG80211_TESTMODE_CMD(wl1271_tm_cmd)
4384};
4385
4386
4387u8 wlcore_rate_to_idx(struct wl1271 *wl, u8 rate, enum ieee80211_band band)
4388{
4389 u8 idx;
4390
4391 BUG_ON(band >= 2);
4392
4393 if (unlikely(rate >= wl->hw_tx_rate_tbl_size)) {
4394 wl1271_error("Illegal RX rate from HW: %d", rate);
4395 return 0;
4396 }
4397
4398 idx = wl->band_rate_to_idx[band][rate];
4399 if (unlikely(idx == CONF_HW_RXTX_RATE_UNSUPPORTED)) {
4400 wl1271_error("Unsupported RX rate from HW: %d", rate);
4401 return 0;
4402 }
4403
4404 return idx;
4405}
4406
4407static ssize_t wl1271_sysfs_show_bt_coex_state(struct device *dev,
4408 struct device_attribute *attr,
4409 char *buf)
4410{
4411 struct wl1271 *wl = dev_get_drvdata(dev);
4412 ssize_t len;
4413
4414 len = PAGE_SIZE;
4415
4416 mutex_lock(&wl->mutex);
4417 len = snprintf(buf, len, "%d\n\n0 - off\n1 - on\n",
4418 wl->sg_enabled);
4419 mutex_unlock(&wl->mutex);
4420
4421 return len;
4422
4423}
4424
4425static ssize_t wl1271_sysfs_store_bt_coex_state(struct device *dev,
4426 struct device_attribute *attr,
4427 const char *buf, size_t count)
4428{
4429 struct wl1271 *wl = dev_get_drvdata(dev);
4430 unsigned long res;
4431 int ret;
4432
4433 ret = kstrtoul(buf, 10, &res);
4434 if (ret < 0) {
4435 wl1271_warning("incorrect value written to bt_coex_mode");
4436 return count;
4437 }
4438
4439 mutex_lock(&wl->mutex);
4440
4441 res = !!res;
4442
4443 if (res == wl->sg_enabled)
4444 goto out;
4445
4446 wl->sg_enabled = res;
4447
4448 if (wl->state == WL1271_STATE_OFF)
4449 goto out;
4450
4451 ret = wl1271_ps_elp_wakeup(wl);
4452 if (ret < 0)
4453 goto out;
4454
4455 wl1271_acx_sg_enable(wl, wl->sg_enabled);
4456 wl1271_ps_elp_sleep(wl);
4457
4458 out:
4459 mutex_unlock(&wl->mutex);
4460 return count;
4461}
4462
4463static DEVICE_ATTR(bt_coex_state, S_IRUGO | S_IWUSR,
4464 wl1271_sysfs_show_bt_coex_state,
4465 wl1271_sysfs_store_bt_coex_state);
4466
4467static ssize_t wl1271_sysfs_show_hw_pg_ver(struct device *dev,
4468 struct device_attribute *attr,
4469 char *buf)
4470{
4471 struct wl1271 *wl = dev_get_drvdata(dev);
4472 ssize_t len;
4473
4474 len = PAGE_SIZE;
4475
4476 mutex_lock(&wl->mutex);
4477 if (wl->hw_pg_ver >= 0)
4478 len = snprintf(buf, len, "%d\n", wl->hw_pg_ver);
4479 else
4480 len = snprintf(buf, len, "n/a\n");
4481 mutex_unlock(&wl->mutex);
4482
4483 return len;
4484}
4485
4486static DEVICE_ATTR(hw_pg_ver, S_IRUGO,
4487 wl1271_sysfs_show_hw_pg_ver, NULL);
4488
4489static ssize_t wl1271_sysfs_read_fwlog(struct file *filp, struct kobject *kobj,
4490 struct bin_attribute *bin_attr,
4491 char *buffer, loff_t pos, size_t count)
4492{
4493 struct device *dev = container_of(kobj, struct device, kobj);
4494 struct wl1271 *wl = dev_get_drvdata(dev);
4495 ssize_t len;
4496 int ret;
4497
4498 ret = mutex_lock_interruptible(&wl->mutex);
4499 if (ret < 0)
4500 return -ERESTARTSYS;
4501
4502 /* Let only one thread read the log at a time, blocking others */
4503 while (wl->fwlog_size == 0) {
4504 DEFINE_WAIT(wait);
4505
4506 prepare_to_wait_exclusive(&wl->fwlog_waitq,
4507 &wait,
4508 TASK_INTERRUPTIBLE);
4509
4510 if (wl->fwlog_size != 0) {
4511 finish_wait(&wl->fwlog_waitq, &wait);
4512 break;
4513 }
4514
4515 mutex_unlock(&wl->mutex);
4516
4517 schedule();
4518 finish_wait(&wl->fwlog_waitq, &wait);
4519
4520 if (signal_pending(current))
4521 return -ERESTARTSYS;
4522
4523 ret = mutex_lock_interruptible(&wl->mutex);
4524 if (ret < 0)
4525 return -ERESTARTSYS;
4526 }
4527
4528 /* Check if the fwlog is still valid */
4529 if (wl->fwlog_size < 0) {
4530 mutex_unlock(&wl->mutex);
4531 return 0;
4532 }
4533
4534 /* Seeking is not supported - old logs are not kept. Disregard pos. */
4535 len = min(count, (size_t)wl->fwlog_size);
4536 wl->fwlog_size -= len;
4537 memcpy(buffer, wl->fwlog, len);
4538
4539 /* Make room for new messages */
4540 memmove(wl->fwlog, wl->fwlog + len, wl->fwlog_size);
4541
4542 mutex_unlock(&wl->mutex);
4543
4544 return len;
4545}
4546
4547static struct bin_attribute fwlog_attr = {
4548 .attr = {.name = "fwlog", .mode = S_IRUSR},
4549 .read = wl1271_sysfs_read_fwlog,
4550};
4551
4552static void wl12xx_derive_mac_addresses(struct wl1271 *wl,
4553 u32 oui, u32 nic, int n)
4554{
4555 int i;
4556
4557 wl1271_debug(DEBUG_PROBE, "base address: oui %06x nic %06x, n %d",
4558 oui, nic, n);
4559
4560 if (nic + n - 1 > 0xffffff)
4561 wl1271_warning("NIC part of the MAC address wraps around!");
4562
4563 for (i = 0; i < n; i++) {
4564 wl->addresses[i].addr[0] = (u8)(oui >> 16);
4565 wl->addresses[i].addr[1] = (u8)(oui >> 8);
4566 wl->addresses[i].addr[2] = (u8) oui;
4567 wl->addresses[i].addr[3] = (u8)(nic >> 16);
4568 wl->addresses[i].addr[4] = (u8)(nic >> 8);
4569 wl->addresses[i].addr[5] = (u8) nic;
4570 nic++;
4571 }
4572
4573 wl->hw->wiphy->n_addresses = n;
4574 wl->hw->wiphy->addresses = wl->addresses;
4575}
4576
4577static int wl12xx_get_hw_info(struct wl1271 *wl)
4578{
4579 int ret;
4580
4581 ret = wl12xx_set_power_on(wl);
4582 if (ret < 0)
4583 goto out;
4584
4585 wl->chip.id = wlcore_read_reg(wl, REG_CHIP_ID_B);
4586
4587 wl->fuse_oui_addr = 0;
4588 wl->fuse_nic_addr = 0;
4589
4590 wl->hw_pg_ver = wl->ops->get_pg_ver(wl);
4591
4592 if (wl->ops->get_mac)
4593 wl->ops->get_mac(wl);
4594
4595 wl1271_power_off(wl);
4596out:
4597 return ret;
4598}
4599
4600static int wl1271_register_hw(struct wl1271 *wl)
4601{
4602 int ret;
4603 u32 oui_addr = 0, nic_addr = 0;
4604
4605 if (wl->mac80211_registered)
4606 return 0;
4607
4608 ret = wl12xx_get_hw_info(wl);
4609 if (ret < 0) {
4610 wl1271_error("couldn't get hw info");
4611 goto out;
4612 }
4613
4614 ret = wl1271_fetch_nvs(wl);
4615 if (ret == 0) {
4616 /* NOTE: The wl->nvs->nvs element must be first, in
4617 * order to simplify the casting, we assume it is at
4618 * the beginning of the wl->nvs structure.
4619 */
4620 u8 *nvs_ptr = (u8 *)wl->nvs;
4621
4622 oui_addr =
4623 (nvs_ptr[11] << 16) + (nvs_ptr[10] << 8) + nvs_ptr[6];
4624 nic_addr =
4625 (nvs_ptr[5] << 16) + (nvs_ptr[4] << 8) + nvs_ptr[3];
4626 }
4627
4628 /* if the MAC address is zeroed in the NVS derive from fuse */
4629 if (oui_addr == 0 && nic_addr == 0) {
4630 oui_addr = wl->fuse_oui_addr;
4631 /* fuse has the BD_ADDR, the WLAN addresses are the next two */
4632 nic_addr = wl->fuse_nic_addr + 1;
4633 }
4634
4635 wl12xx_derive_mac_addresses(wl, oui_addr, nic_addr, 2);
4636
4637 ret = ieee80211_register_hw(wl->hw);
4638 if (ret < 0) {
4639 wl1271_error("unable to register mac80211 hw: %d", ret);
4640 goto out;
4641 }
4642
4643 wl->mac80211_registered = true;
4644
4645 wl1271_debugfs_init(wl);
4646
4647 wl1271_notice("loaded");
4648
4649out:
4650 return ret;
4651}
4652
4653static void wl1271_unregister_hw(struct wl1271 *wl)
4654{
4655 if (wl->plt)
4656 wl1271_plt_stop(wl);
4657
4658 ieee80211_unregister_hw(wl->hw);
4659 wl->mac80211_registered = false;
4660
4661}
4662
4663static int wl1271_init_ieee80211(struct wl1271 *wl)
4664{
4665 static const u32 cipher_suites[] = {
4666 WLAN_CIPHER_SUITE_WEP40,
4667 WLAN_CIPHER_SUITE_WEP104,
4668 WLAN_CIPHER_SUITE_TKIP,
4669 WLAN_CIPHER_SUITE_CCMP,
4670 WL1271_CIPHER_SUITE_GEM,
4671 };
4672
4673 /* The tx descriptor buffer and the TKIP space. */
4674 wl->hw->extra_tx_headroom = WL1271_EXTRA_SPACE_TKIP +
4675 sizeof(struct wl1271_tx_hw_descr);
4676
4677 /* unit us */
4678 /* FIXME: find a proper value */
4679 wl->hw->channel_change_time = 10000;
4680 wl->hw->max_listen_interval = wl->conf.conn.max_listen_interval;
4681
4682 wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
4683 IEEE80211_HW_SUPPORTS_PS |
4684 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
4685 IEEE80211_HW_SUPPORTS_UAPSD |
4686 IEEE80211_HW_HAS_RATE_CONTROL |
4687 IEEE80211_HW_CONNECTION_MONITOR |
4688 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
4689 IEEE80211_HW_SPECTRUM_MGMT |
4690 IEEE80211_HW_AP_LINK_PS |
4691 IEEE80211_HW_AMPDU_AGGREGATION |
4692 IEEE80211_HW_TX_AMPDU_SETUP_IN_HW |
4693 IEEE80211_HW_SCAN_WHILE_IDLE;
4694
4695 wl->hw->wiphy->cipher_suites = cipher_suites;
4696 wl->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
4697
4698 wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
4699 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP) |
4700 BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO);
4701 wl->hw->wiphy->max_scan_ssids = 1;
4702 wl->hw->wiphy->max_sched_scan_ssids = 16;
4703 wl->hw->wiphy->max_match_sets = 16;
4704 /*
4705 * Maximum length of elements in scanning probe request templates
4706 * should be the maximum length possible for a template, without
4707 * the IEEE80211 header of the template
4708 */
4709 wl->hw->wiphy->max_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE -
4710 sizeof(struct ieee80211_header);
4711
4712 wl->hw->wiphy->max_sched_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE -
4713 sizeof(struct ieee80211_header);
4714
4715 wl->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD |
4716 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
4717
4718 /* make sure all our channels fit in the scanned_ch bitmask */
4719 BUILD_BUG_ON(ARRAY_SIZE(wl1271_channels) +
4720 ARRAY_SIZE(wl1271_channels_5ghz) >
4721 WL1271_MAX_CHANNELS);
4722 /*
4723 * We keep local copies of the band structs because we need to
4724 * modify them on a per-device basis.
4725 */
4726 memcpy(&wl->bands[IEEE80211_BAND_2GHZ], &wl1271_band_2ghz,
4727 sizeof(wl1271_band_2ghz));
4728 memcpy(&wl->bands[IEEE80211_BAND_2GHZ].ht_cap, &wl->ht_cap,
4729 sizeof(wl->ht_cap));
4730 memcpy(&wl->bands[IEEE80211_BAND_5GHZ], &wl1271_band_5ghz,
4731 sizeof(wl1271_band_5ghz));
4732 memcpy(&wl->bands[IEEE80211_BAND_5GHZ].ht_cap, &wl->ht_cap,
4733 sizeof(wl->ht_cap));
4734
4735 wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
4736 &wl->bands[IEEE80211_BAND_2GHZ];
4737 wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
4738 &wl->bands[IEEE80211_BAND_5GHZ];
4739
4740 wl->hw->queues = 4;
4741 wl->hw->max_rates = 1;
4742
4743 wl->hw->wiphy->reg_notifier = wl1271_reg_notify;
4744
4745 /* the FW answers probe-requests in AP-mode */
4746 wl->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
4747 wl->hw->wiphy->probe_resp_offload =
4748 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
4749 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
4750 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
4751
4752 SET_IEEE80211_DEV(wl->hw, wl->dev);
4753
4754 wl->hw->sta_data_size = sizeof(struct wl1271_station);
4755 wl->hw->vif_data_size = sizeof(struct wl12xx_vif);
4756
4757 wl->hw->max_rx_aggregation_subframes = wl->conf.ht.rx_ba_win_size;
4758
4759 return 0;
4760}
4761
4762#define WL1271_DEFAULT_CHANNEL 0
4763
4764struct ieee80211_hw *wlcore_alloc_hw(size_t priv_size)
4765{
4766 struct ieee80211_hw *hw;
4767 struct wl1271 *wl;
4768 int i, j, ret;
4769 unsigned int order;
4770
4771 BUILD_BUG_ON(AP_MAX_STATIONS > WL12XX_MAX_LINKS);
4772
4773 hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops);
4774 if (!hw) {
4775 wl1271_error("could not alloc ieee80211_hw");
4776 ret = -ENOMEM;
4777 goto err_hw_alloc;
4778 }
4779
4780 wl = hw->priv;
4781 memset(wl, 0, sizeof(*wl));
4782
4783 wl->priv = kzalloc(priv_size, GFP_KERNEL);
4784 if (!wl->priv) {
4785 wl1271_error("could not alloc wl priv");
4786 ret = -ENOMEM;
4787 goto err_priv_alloc;
4788 }
4789
4790 INIT_LIST_HEAD(&wl->wlvif_list);
4791
4792 wl->hw = hw;
4793
4794 for (i = 0; i < NUM_TX_QUEUES; i++)
4795 for (j = 0; j < WL12XX_MAX_LINKS; j++)
4796 skb_queue_head_init(&wl->links[j].tx_queue[i]);
4797
4798 skb_queue_head_init(&wl->deferred_rx_queue);
4799 skb_queue_head_init(&wl->deferred_tx_queue);
4800
4801 INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work);
4802 INIT_WORK(&wl->netstack_work, wl1271_netstack_work);
4803 INIT_WORK(&wl->tx_work, wl1271_tx_work);
4804 INIT_WORK(&wl->recovery_work, wl1271_recovery_work);
4805 INIT_DELAYED_WORK(&wl->scan_complete_work, wl1271_scan_complete_work);
4806 INIT_DELAYED_WORK(&wl->tx_watchdog_work, wl12xx_tx_watchdog_work);
4807
4808 wl->freezable_wq = create_freezable_workqueue("wl12xx_wq");
4809 if (!wl->freezable_wq) {
4810 ret = -ENOMEM;
4811 goto err_hw;
4812 }
4813
4814 wl->channel = WL1271_DEFAULT_CHANNEL;
4815 wl->rx_counter = 0;
4816 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
4817 wl->band = IEEE80211_BAND_2GHZ;
4818 wl->flags = 0;
4819 wl->sg_enabled = true;
4820 wl->hw_pg_ver = -1;
4821 wl->ap_ps_map = 0;
4822 wl->ap_fw_ps_map = 0;
4823 wl->quirks = 0;
4824 wl->platform_quirks = 0;
4825 wl->sched_scanning = false;
4826 wl->system_hlid = WL12XX_SYSTEM_HLID;
4827 wl->active_sta_count = 0;
4828 wl->fwlog_size = 0;
4829 init_waitqueue_head(&wl->fwlog_waitq);
4830
4831 /* The system link is always allocated */
4832 __set_bit(WL12XX_SYSTEM_HLID, wl->links_map);
4833
4834 memset(wl->tx_frames_map, 0, sizeof(wl->tx_frames_map));
4835 for (i = 0; i < wl->num_tx_desc; i++)
4836 wl->tx_frames[i] = NULL;
4837
4838 spin_lock_init(&wl->wl_lock);
4839
4840 wl->state = WL1271_STATE_OFF;
4841 wl->fw_type = WL12XX_FW_TYPE_NONE;
4842 mutex_init(&wl->mutex);
4843
4844 order = get_order(WL1271_AGGR_BUFFER_SIZE);
4845 wl->aggr_buf = (u8 *)__get_free_pages(GFP_KERNEL, order);
4846 if (!wl->aggr_buf) {
4847 ret = -ENOMEM;
4848 goto err_wq;
4849 }
4850
4851 wl->dummy_packet = wl12xx_alloc_dummy_packet(wl);
4852 if (!wl->dummy_packet) {
4853 ret = -ENOMEM;
4854 goto err_aggr;
4855 }
4856
4857 /* Allocate one page for the FW log */
4858 wl->fwlog = (u8 *)get_zeroed_page(GFP_KERNEL);
4859 if (!wl->fwlog) {
4860 ret = -ENOMEM;
4861 goto err_dummy_packet;
4862 }
4863
4864 wl->mbox = kmalloc(sizeof(*wl->mbox), GFP_DMA);
4865 if (!wl->mbox) {
4866 ret = -ENOMEM;
4867 goto err_fwlog;
4868 }
4869
4870 return hw;
4871
4872err_fwlog:
4873 free_page((unsigned long)wl->fwlog);
4874
4875err_dummy_packet:
4876 dev_kfree_skb(wl->dummy_packet);
4877
4878err_aggr:
4879 free_pages((unsigned long)wl->aggr_buf, order);
4880
4881err_wq:
4882 destroy_workqueue(wl->freezable_wq);
4883
4884err_hw:
4885 wl1271_debugfs_exit(wl);
4886 kfree(wl->priv);
4887
4888err_priv_alloc:
4889 ieee80211_free_hw(hw);
4890
4891err_hw_alloc:
4892
4893 return ERR_PTR(ret);
4894}
4895EXPORT_SYMBOL_GPL(wlcore_alloc_hw);
4896
4897int wlcore_free_hw(struct wl1271 *wl)
4898{
4899 /* Unblock any fwlog readers */
4900 mutex_lock(&wl->mutex);
4901 wl->fwlog_size = -1;
4902 wake_up_interruptible_all(&wl->fwlog_waitq);
4903 mutex_unlock(&wl->mutex);
4904
4905 device_remove_bin_file(wl->dev, &fwlog_attr);
4906
4907 device_remove_file(wl->dev, &dev_attr_hw_pg_ver);
4908
4909 device_remove_file(wl->dev, &dev_attr_bt_coex_state);
4910 free_page((unsigned long)wl->fwlog);
4911 dev_kfree_skb(wl->dummy_packet);
4912 free_pages((unsigned long)wl->aggr_buf,
4913 get_order(WL1271_AGGR_BUFFER_SIZE));
4914
4915 wl1271_debugfs_exit(wl);
4916
4917 vfree(wl->fw);
4918 wl->fw = NULL;
4919 wl->fw_type = WL12XX_FW_TYPE_NONE;
4920 kfree(wl->nvs);
4921 wl->nvs = NULL;
4922
4923 kfree(wl->fw_status);
4924 kfree(wl->tx_res_if);
4925 destroy_workqueue(wl->freezable_wq);
4926
4927 kfree(wl->priv);
4928 ieee80211_free_hw(wl->hw);
4929
4930 return 0;
4931}
4932EXPORT_SYMBOL_GPL(wlcore_free_hw);
4933
4934static irqreturn_t wl12xx_hardirq(int irq, void *cookie)
4935{
4936 struct wl1271 *wl = cookie;
4937 unsigned long flags;
4938
4939 wl1271_debug(DEBUG_IRQ, "IRQ");
4940
4941 /* complete the ELP completion */
4942 spin_lock_irqsave(&wl->wl_lock, flags);
4943 set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
4944 if (wl->elp_compl) {
4945 complete(wl->elp_compl);
4946 wl->elp_compl = NULL;
4947 }
4948
4949 if (test_bit(WL1271_FLAG_SUSPENDED, &wl->flags)) {
4950 /* don't enqueue a work right now. mark it as pending */
4951 set_bit(WL1271_FLAG_PENDING_WORK, &wl->flags);
4952 wl1271_debug(DEBUG_IRQ, "should not enqueue work");
4953 disable_irq_nosync(wl->irq);
4954 pm_wakeup_event(wl->dev, 0);
4955 spin_unlock_irqrestore(&wl->wl_lock, flags);
4956 return IRQ_HANDLED;
4957 }
4958 spin_unlock_irqrestore(&wl->wl_lock, flags);
4959
4960 return IRQ_WAKE_THREAD;
4961}
4962
4963int __devinit wlcore_probe(struct wl1271 *wl, struct platform_device *pdev)
4964{
4965 struct wl12xx_platform_data *pdata = pdev->dev.platform_data;
4966 unsigned long irqflags;
4967 int ret;
4968
4969 if (!wl->ops || !wl->ptable) {
4970 ret = -EINVAL;
4971 goto out_free_hw;
4972 }
4973
4974 BUG_ON(wl->num_tx_desc > WLCORE_MAX_TX_DESCRIPTORS);
4975
4976 /* adjust some runtime configuration parameters */
4977 wlcore_adjust_conf(wl);
4978
4979 wl->irq = platform_get_irq(pdev, 0);
4980 wl->ref_clock = pdata->board_ref_clock;
4981 wl->tcxo_clock = pdata->board_tcxo_clock;
4982 wl->platform_quirks = pdata->platform_quirks;
4983 wl->set_power = pdata->set_power;
4984 wl->dev = &pdev->dev;
4985 wl->if_ops = pdata->ops;
4986
4987 platform_set_drvdata(pdev, wl);
4988
4989 if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
4990 irqflags = IRQF_TRIGGER_RISING;
4991 else
4992 irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT;
4993
4994 ret = request_threaded_irq(wl->irq, wl12xx_hardirq, wl1271_irq,
4995 irqflags,
4996 pdev->name, wl);
4997 if (ret < 0) {
4998 wl1271_error("request_irq() failed: %d", ret);
4999 goto out_free_hw;
5000 }
5001
5002 ret = enable_irq_wake(wl->irq);
5003 if (!ret) {
5004 wl->irq_wake_enabled = true;
5005 device_init_wakeup(wl->dev, 1);
5006 if (pdata->pwr_in_suspend)
5007 wl->hw->wiphy->wowlan.flags = WIPHY_WOWLAN_ANY;
5008
5009 }
5010 disable_irq(wl->irq);
5011
5012 ret = wl1271_init_ieee80211(wl);
5013 if (ret)
5014 goto out_irq;
5015
5016 ret = wl1271_register_hw(wl);
5017 if (ret)
5018 goto out_irq;
5019
5020 /* Create sysfs file to control bt coex state */
5021 ret = device_create_file(wl->dev, &dev_attr_bt_coex_state);
5022 if (ret < 0) {
5023 wl1271_error("failed to create sysfs file bt_coex_state");
5024 goto out_irq;
5025 }
5026
5027 /* Create sysfs file to get HW PG version */
5028 ret = device_create_file(wl->dev, &dev_attr_hw_pg_ver);
5029 if (ret < 0) {
5030 wl1271_error("failed to create sysfs file hw_pg_ver");
5031 goto out_bt_coex_state;
5032 }
5033
5034 /* Create sysfs file for the FW log */
5035 ret = device_create_bin_file(wl->dev, &fwlog_attr);
5036 if (ret < 0) {
5037 wl1271_error("failed to create sysfs file fwlog");
5038 goto out_hw_pg_ver;
5039 }
5040
5041 goto out;
5042
5043out_hw_pg_ver:
5044 device_remove_file(wl->dev, &dev_attr_hw_pg_ver);
5045
5046out_bt_coex_state:
5047 device_remove_file(wl->dev, &dev_attr_bt_coex_state);
5048
5049out_irq:
5050 free_irq(wl->irq, wl);
5051
5052out_free_hw:
5053 wlcore_free_hw(wl);
5054
5055out:
5056 return ret;
5057}
5058EXPORT_SYMBOL_GPL(wlcore_probe);
5059
5060int __devexit wlcore_remove(struct platform_device *pdev)
5061{
5062 struct wl1271 *wl = platform_get_drvdata(pdev);
5063
5064 if (wl->irq_wake_enabled) {
5065 device_init_wakeup(wl->dev, 0);
5066 disable_irq_wake(wl->irq);
5067 }
5068 wl1271_unregister_hw(wl);
5069 free_irq(wl->irq, wl);
5070 wlcore_free_hw(wl);
5071
5072 return 0;
5073}
5074EXPORT_SYMBOL_GPL(wlcore_remove);
5075
5076u32 wl12xx_debug_level = DEBUG_NONE;
5077EXPORT_SYMBOL_GPL(wl12xx_debug_level);
5078module_param_named(debug_level, wl12xx_debug_level, uint, S_IRUSR | S_IWUSR);
5079MODULE_PARM_DESC(debug_level, "wl12xx debugging level");
5080
5081module_param_named(fwlog, fwlog_param, charp, 0);
5082MODULE_PARM_DESC(fwlog,
5083 "FW logger options: continuous, ondemand, dbgpins or disable");
5084
5085module_param(bug_on_recovery, bool, S_IRUSR | S_IWUSR);
5086MODULE_PARM_DESC(bug_on_recovery, "BUG() on fw recovery");
5087
5088module_param(no_recovery, bool, S_IRUSR | S_IWUSR);
5089MODULE_PARM_DESC(no_recovery, "Prevent HW recovery. FW will remain stuck.");
5090
5091MODULE_LICENSE("GPL");
5092MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
5093MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");
diff --git a/drivers/net/wireless/ti/wlcore/ps.c b/drivers/net/wireless/ti/wlcore/ps.c
new file mode 100644
index 000000000000..756eee2257b4
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/ps.c
@@ -0,0 +1,306 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2008-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 "ps.h"
25#include "io.h"
26#include "tx.h"
27#include "debug.h"
28
29#define WL1271_WAKEUP_TIMEOUT 500
30
31void wl1271_elp_work(struct work_struct *work)
32{
33 struct delayed_work *dwork;
34 struct wl1271 *wl;
35 struct wl12xx_vif *wlvif;
36
37 dwork = container_of(work, struct delayed_work, work);
38 wl = container_of(dwork, struct wl1271, elp_work);
39
40 wl1271_debug(DEBUG_PSM, "elp work");
41
42 mutex_lock(&wl->mutex);
43
44 if (unlikely(wl->state == WL1271_STATE_OFF))
45 goto out;
46
47 /* our work might have been already cancelled */
48 if (unlikely(!test_bit(WL1271_FLAG_ELP_REQUESTED, &wl->flags)))
49 goto out;
50
51 if (test_bit(WL1271_FLAG_IN_ELP, &wl->flags))
52 goto out;
53
54 wl12xx_for_each_wlvif(wl, wlvif) {
55 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
56 goto out;
57
58 if (!test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags) &&
59 test_bit(WLVIF_FLAG_IN_USE, &wlvif->flags))
60 goto out;
61 }
62
63 wl1271_debug(DEBUG_PSM, "chip to elp");
64 wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG, ELPCTRL_SLEEP);
65 set_bit(WL1271_FLAG_IN_ELP, &wl->flags);
66
67out:
68 mutex_unlock(&wl->mutex);
69}
70
71/* Routines to toggle sleep mode while in ELP */
72void wl1271_ps_elp_sleep(struct wl1271 *wl)
73{
74 struct wl12xx_vif *wlvif;
75
76 if (wl->quirks & WLCORE_QUIRK_NO_ELP)
77 return;
78
79 /* we shouldn't get consecutive sleep requests */
80 if (WARN_ON(test_and_set_bit(WL1271_FLAG_ELP_REQUESTED, &wl->flags)))
81 return;
82
83 wl12xx_for_each_wlvif(wl, wlvif) {
84 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
85 return;
86
87 if (!test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags) &&
88 test_bit(WLVIF_FLAG_IN_USE, &wlvif->flags))
89 return;
90 }
91
92 ieee80211_queue_delayed_work(wl->hw, &wl->elp_work,
93 msecs_to_jiffies(wl->conf.conn.dynamic_ps_timeout));
94}
95
96int wl1271_ps_elp_wakeup(struct wl1271 *wl)
97{
98 DECLARE_COMPLETION_ONSTACK(compl);
99 unsigned long flags;
100 int ret;
101 u32 start_time = jiffies;
102 bool pending = false;
103
104 /*
105 * we might try to wake up even if we didn't go to sleep
106 * before (e.g. on boot)
107 */
108 if (!test_and_clear_bit(WL1271_FLAG_ELP_REQUESTED, &wl->flags))
109 return 0;
110
111 /* don't cancel_sync as it might contend for a mutex and deadlock */
112 cancel_delayed_work(&wl->elp_work);
113
114 if (!test_bit(WL1271_FLAG_IN_ELP, &wl->flags))
115 return 0;
116
117 wl1271_debug(DEBUG_PSM, "waking up chip from elp");
118
119 /*
120 * The spinlock is required here to synchronize both the work and
121 * the completion variable in one entity.
122 */
123 spin_lock_irqsave(&wl->wl_lock, flags);
124 if (test_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags))
125 pending = true;
126 else
127 wl->elp_compl = &compl;
128 spin_unlock_irqrestore(&wl->wl_lock, flags);
129
130 wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG, ELPCTRL_WAKE_UP);
131
132 if (!pending) {
133 ret = wait_for_completion_timeout(
134 &compl, msecs_to_jiffies(WL1271_WAKEUP_TIMEOUT));
135 if (ret == 0) {
136 wl1271_error("ELP wakeup timeout!");
137 wl12xx_queue_recovery_work(wl);
138 ret = -ETIMEDOUT;
139 goto err;
140 } else if (ret < 0) {
141 wl1271_error("ELP wakeup completion error.");
142 goto err;
143 }
144 }
145
146 clear_bit(WL1271_FLAG_IN_ELP, &wl->flags);
147
148 wl1271_debug(DEBUG_PSM, "wakeup time: %u ms",
149 jiffies_to_msecs(jiffies - start_time));
150 goto out;
151
152err:
153 spin_lock_irqsave(&wl->wl_lock, flags);
154 wl->elp_compl = NULL;
155 spin_unlock_irqrestore(&wl->wl_lock, flags);
156 return ret;
157
158out:
159 return 0;
160}
161
162int wl1271_ps_set_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
163 enum wl1271_cmd_ps_mode mode)
164{
165 int ret;
166 u16 timeout = wl->conf.conn.dynamic_ps_timeout;
167
168 switch (mode) {
169 case STATION_AUTO_PS_MODE:
170 case STATION_POWER_SAVE_MODE:
171 wl1271_debug(DEBUG_PSM, "entering psm (mode=%d,timeout=%u)",
172 mode, timeout);
173
174 ret = wl1271_acx_wake_up_conditions(wl, wlvif,
175 wl->conf.conn.wake_up_event,
176 wl->conf.conn.listen_interval);
177 if (ret < 0) {
178 wl1271_error("couldn't set wake up conditions");
179 return ret;
180 }
181
182 ret = wl1271_cmd_ps_mode(wl, wlvif, mode, timeout);
183 if (ret < 0)
184 return ret;
185
186 set_bit(WLVIF_FLAG_IN_PS, &wlvif->flags);
187
188 /* enable beacon early termination. Not relevant for 5GHz */
189 if (wlvif->band == IEEE80211_BAND_2GHZ) {
190 ret = wl1271_acx_bet_enable(wl, wlvif, true);
191 if (ret < 0)
192 return ret;
193 }
194 break;
195 case STATION_ACTIVE_MODE:
196 wl1271_debug(DEBUG_PSM, "leaving psm");
197
198 /* disable beacon early termination */
199 if (wlvif->band == IEEE80211_BAND_2GHZ) {
200 ret = wl1271_acx_bet_enable(wl, wlvif, false);
201 if (ret < 0)
202 return ret;
203 }
204
205 ret = wl1271_cmd_ps_mode(wl, wlvif, mode, 0);
206 if (ret < 0)
207 return ret;
208
209 clear_bit(WLVIF_FLAG_IN_PS, &wlvif->flags);
210 break;
211 default:
212 wl1271_warning("trying to set ps to unsupported mode %d", mode);
213 ret = -EINVAL;
214 }
215
216 return ret;
217}
218
219static void wl1271_ps_filter_frames(struct wl1271 *wl, u8 hlid)
220{
221 int i;
222 struct sk_buff *skb;
223 struct ieee80211_tx_info *info;
224 unsigned long flags;
225 int filtered[NUM_TX_QUEUES];
226
227 /* filter all frames currently in the low level queues for this hlid */
228 for (i = 0; i < NUM_TX_QUEUES; i++) {
229 filtered[i] = 0;
230 while ((skb = skb_dequeue(&wl->links[hlid].tx_queue[i]))) {
231 filtered[i]++;
232
233 if (WARN_ON(wl12xx_is_dummy_packet(wl, skb)))
234 continue;
235
236 info = IEEE80211_SKB_CB(skb);
237 info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
238 info->status.rates[0].idx = -1;
239 ieee80211_tx_status_ni(wl->hw, skb);
240 }
241 }
242
243 spin_lock_irqsave(&wl->wl_lock, flags);
244 for (i = 0; i < NUM_TX_QUEUES; i++)
245 wl->tx_queue_count[i] -= filtered[i];
246 spin_unlock_irqrestore(&wl->wl_lock, flags);
247
248 wl1271_handle_tx_low_watermark(wl);
249}
250
251void wl12xx_ps_link_start(struct wl1271 *wl, struct wl12xx_vif *wlvif,
252 u8 hlid, bool clean_queues)
253{
254 struct ieee80211_sta *sta;
255 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
256
257 if (test_bit(hlid, &wl->ap_ps_map))
258 return;
259
260 wl1271_debug(DEBUG_PSM, "start mac80211 PSM on hlid %d pkts %d "
261 "clean_queues %d", hlid, wl->links[hlid].allocated_pkts,
262 clean_queues);
263
264 rcu_read_lock();
265 sta = ieee80211_find_sta(vif, wl->links[hlid].addr);
266 if (!sta) {
267 wl1271_error("could not find sta %pM for starting ps",
268 wl->links[hlid].addr);
269 rcu_read_unlock();
270 return;
271 }
272
273 ieee80211_sta_ps_transition_ni(sta, true);
274 rcu_read_unlock();
275
276 /* do we want to filter all frames from this link's queues? */
277 if (clean_queues)
278 wl1271_ps_filter_frames(wl, hlid);
279
280 __set_bit(hlid, &wl->ap_ps_map);
281}
282
283void wl12xx_ps_link_end(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid)
284{
285 struct ieee80211_sta *sta;
286 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
287
288 if (!test_bit(hlid, &wl->ap_ps_map))
289 return;
290
291 wl1271_debug(DEBUG_PSM, "end mac80211 PSM on hlid %d", hlid);
292
293 __clear_bit(hlid, &wl->ap_ps_map);
294
295 rcu_read_lock();
296 sta = ieee80211_find_sta(vif, wl->links[hlid].addr);
297 if (!sta) {
298 wl1271_error("could not find sta %pM for ending ps",
299 wl->links[hlid].addr);
300 goto end;
301 }
302
303 ieee80211_sta_ps_transition_ni(sta, false);
304end:
305 rcu_read_unlock();
306}
diff --git a/drivers/net/wireless/ti/wlcore/ps.h b/drivers/net/wireless/ti/wlcore/ps.h
new file mode 100644
index 000000000000..de4f9da8ed26
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/ps.h
@@ -0,0 +1,41 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2008-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#ifndef __PS_H__
25#define __PS_H__
26
27#include "wlcore.h"
28#include "acx.h"
29
30int wl1271_ps_set_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
31 enum wl1271_cmd_ps_mode mode);
32void wl1271_ps_elp_sleep(struct wl1271 *wl);
33int wl1271_ps_elp_wakeup(struct wl1271 *wl);
34void wl1271_elp_work(struct work_struct *work);
35void wl12xx_ps_link_start(struct wl1271 *wl, struct wl12xx_vif *wlvif,
36 u8 hlid, bool clean_queues);
37void wl12xx_ps_link_end(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid);
38
39#define WL1271_PS_COMPLETE_TIMEOUT 500
40
41#endif /* __WL1271_PS_H__ */
diff --git a/drivers/net/wireless/ti/wlcore/rx.c b/drivers/net/wireless/ti/wlcore/rx.c
new file mode 100644
index 000000000000..89bd9385e90b
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/rx.c
@@ -0,0 +1,280 @@
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#include <linux/sched.h>
26
27#include "wlcore.h"
28#include "debug.h"
29#include "acx.h"
30#include "rx.h"
31#include "tx.h"
32#include "io.h"
33#include "hw_ops.h"
34
35/*
36 * TODO: this is here just for now, it must be removed when the data
37 * operations are in place.
38 */
39#include "../wl12xx/reg.h"
40
41static u32 wlcore_rx_get_buf_size(struct wl1271 *wl,
42 u32 rx_pkt_desc)
43{
44 if (wl->quirks & WLCORE_QUIRK_RX_BLOCKSIZE_ALIGN)
45 return (rx_pkt_desc & ALIGNED_RX_BUF_SIZE_MASK) >>
46 ALIGNED_RX_BUF_SIZE_SHIFT;
47
48 return (rx_pkt_desc & RX_BUF_SIZE_MASK) >> RX_BUF_SIZE_SHIFT_DIV;
49}
50
51static u32 wlcore_rx_get_align_buf_size(struct wl1271 *wl, u32 pkt_len)
52{
53 if (wl->quirks & WLCORE_QUIRK_RX_BLOCKSIZE_ALIGN)
54 return ALIGN(pkt_len, WL12XX_BUS_BLOCK_SIZE);
55
56 return pkt_len;
57}
58
59static void wl1271_rx_status(struct wl1271 *wl,
60 struct wl1271_rx_descriptor *desc,
61 struct ieee80211_rx_status *status,
62 u8 beacon)
63{
64 memset(status, 0, sizeof(struct ieee80211_rx_status));
65
66 if ((desc->flags & WL1271_RX_DESC_BAND_MASK) == WL1271_RX_DESC_BAND_BG)
67 status->band = IEEE80211_BAND_2GHZ;
68 else
69 status->band = IEEE80211_BAND_5GHZ;
70
71 status->rate_idx = wlcore_rate_to_idx(wl, desc->rate, status->band);
72
73 /* 11n support */
74 if (desc->rate <= wl->hw_min_ht_rate)
75 status->flag |= RX_FLAG_HT;
76
77 status->signal = desc->rssi;
78
79 /*
80 * FIXME: In wl1251, the SNR should be divided by two. In wl1271 we
81 * need to divide by two for now, but TI has been discussing about
82 * changing it. This needs to be rechecked.
83 */
84 wl->noise = desc->rssi - (desc->snr >> 1);
85
86 status->freq = ieee80211_channel_to_frequency(desc->channel,
87 status->band);
88
89 if (desc->flags & WL1271_RX_DESC_ENCRYPT_MASK) {
90 u8 desc_err_code = desc->status & WL1271_RX_DESC_STATUS_MASK;
91
92 status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED |
93 RX_FLAG_DECRYPTED;
94
95 if (unlikely(desc_err_code == WL1271_RX_DESC_MIC_FAIL)) {
96 status->flag |= RX_FLAG_MMIC_ERROR;
97 wl1271_warning("Michael MIC error");
98 }
99 }
100}
101
102static int wl1271_rx_handle_data(struct wl1271 *wl, u8 *data, u32 length,
103 enum wl_rx_buf_align rx_align, u8 *hlid)
104{
105 struct wl1271_rx_descriptor *desc;
106 struct sk_buff *skb;
107 struct ieee80211_hdr *hdr;
108 u8 *buf;
109 u8 beacon = 0;
110 u8 is_data = 0;
111 u8 reserved = 0;
112 u16 seq_num;
113 u32 pkt_data_len;
114
115 /*
116 * In PLT mode we seem to get frames and mac80211 warns about them,
117 * workaround this by not retrieving them at all.
118 */
119 if (unlikely(wl->plt))
120 return -EINVAL;
121
122 pkt_data_len = wlcore_hw_get_rx_packet_len(wl, data, length);
123 if (!pkt_data_len) {
124 wl1271_error("Invalid packet arrived from HW. length %d",
125 length);
126 return -EINVAL;
127 }
128
129 if (rx_align == WLCORE_RX_BUF_UNALIGNED)
130 reserved = NET_IP_ALIGN;
131
132 /* the data read starts with the descriptor */
133 desc = (struct wl1271_rx_descriptor *) data;
134
135 if (desc->packet_class == WL12XX_RX_CLASS_LOGGER) {
136 size_t len = length - sizeof(*desc);
137 wl12xx_copy_fwlog(wl, data + sizeof(*desc), len);
138 wake_up_interruptible(&wl->fwlog_waitq);
139 return 0;
140 }
141
142 switch (desc->status & WL1271_RX_DESC_STATUS_MASK) {
143 /* discard corrupted packets */
144 case WL1271_RX_DESC_DRIVER_RX_Q_FAIL:
145 case WL1271_RX_DESC_DECRYPT_FAIL:
146 wl1271_warning("corrupted packet in RX with status: 0x%x",
147 desc->status & WL1271_RX_DESC_STATUS_MASK);
148 return -EINVAL;
149 case WL1271_RX_DESC_SUCCESS:
150 case WL1271_RX_DESC_MIC_FAIL:
151 break;
152 default:
153 wl1271_error("invalid RX descriptor status: 0x%x",
154 desc->status & WL1271_RX_DESC_STATUS_MASK);
155 return -EINVAL;
156 }
157
158 /* skb length not including rx descriptor */
159 skb = __dev_alloc_skb(pkt_data_len + reserved, GFP_KERNEL);
160 if (!skb) {
161 wl1271_error("Couldn't allocate RX frame");
162 return -ENOMEM;
163 }
164
165 /* reserve the unaligned payload(if any) */
166 skb_reserve(skb, reserved);
167
168 buf = skb_put(skb, pkt_data_len);
169
170 /*
171 * Copy packets from aggregation buffer to the skbs without rx
172 * descriptor and with packet payload aligned care. In case of unaligned
173 * packets copy the packets in offset of 2 bytes guarantee IP header
174 * payload aligned to 4 bytes.
175 */
176 memcpy(buf, data + sizeof(*desc), pkt_data_len);
177 if (rx_align == WLCORE_RX_BUF_PADDED)
178 skb_pull(skb, NET_IP_ALIGN);
179
180 *hlid = desc->hlid;
181
182 hdr = (struct ieee80211_hdr *)skb->data;
183 if (ieee80211_is_beacon(hdr->frame_control))
184 beacon = 1;
185 if (ieee80211_is_data_present(hdr->frame_control))
186 is_data = 1;
187
188 wl1271_rx_status(wl, desc, IEEE80211_SKB_RXCB(skb), beacon);
189
190 seq_num = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4;
191 wl1271_debug(DEBUG_RX, "rx skb 0x%p: %d B %s seq %d hlid %d", skb,
192 skb->len - desc->pad_len,
193 beacon ? "beacon" : "",
194 seq_num, *hlid);
195
196 skb_queue_tail(&wl->deferred_rx_queue, skb);
197 queue_work(wl->freezable_wq, &wl->netstack_work);
198
199 return is_data;
200}
201
202void wl12xx_rx(struct wl1271 *wl, struct wl_fw_status *status)
203{
204 unsigned long active_hlids[BITS_TO_LONGS(WL12XX_MAX_LINKS)] = {0};
205 u32 buf_size;
206 u32 fw_rx_counter = status->fw_rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
207 u32 drv_rx_counter = wl->rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
208 u32 rx_counter;
209 u32 pkt_len, align_pkt_len;
210 u32 pkt_offset, des;
211 u8 hlid;
212 enum wl_rx_buf_align rx_align;
213
214 while (drv_rx_counter != fw_rx_counter) {
215 buf_size = 0;
216 rx_counter = drv_rx_counter;
217 while (rx_counter != fw_rx_counter) {
218 des = le32_to_cpu(status->rx_pkt_descs[rx_counter]);
219 pkt_len = wlcore_rx_get_buf_size(wl, des);
220 align_pkt_len = wlcore_rx_get_align_buf_size(wl,
221 pkt_len);
222 if (buf_size + align_pkt_len > WL1271_AGGR_BUFFER_SIZE)
223 break;
224 buf_size += align_pkt_len;
225 rx_counter++;
226 rx_counter &= NUM_RX_PKT_DESC_MOD_MASK;
227 }
228
229 if (buf_size == 0) {
230 wl1271_warning("received empty data");
231 break;
232 }
233
234 /* Read all available packets at once */
235 des = le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]);
236 wlcore_hw_prepare_read(wl, des, buf_size);
237 wlcore_read_data(wl, REG_SLV_MEM_DATA, wl->aggr_buf,
238 buf_size, true);
239
240 /* Split data into separate packets */
241 pkt_offset = 0;
242 while (pkt_offset < buf_size) {
243 des = le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]);
244 pkt_len = wlcore_rx_get_buf_size(wl, des);
245 rx_align = wlcore_hw_get_rx_buf_align(wl, des);
246
247 /*
248 * the handle data call can only fail in memory-outage
249 * conditions, in that case the received frame will just
250 * be dropped.
251 */
252 if (wl1271_rx_handle_data(wl,
253 wl->aggr_buf + pkt_offset,
254 pkt_len, rx_align,
255 &hlid) == 1) {
256 if (hlid < WL12XX_MAX_LINKS)
257 __set_bit(hlid, active_hlids);
258 else
259 WARN(1,
260 "hlid exceeded WL12XX_MAX_LINKS "
261 "(%d)\n", hlid);
262 }
263
264 wl->rx_counter++;
265 drv_rx_counter++;
266 drv_rx_counter &= NUM_RX_PKT_DESC_MOD_MASK;
267 pkt_offset += wlcore_rx_get_align_buf_size(wl, pkt_len);
268 }
269 }
270
271 /*
272 * Write the driver's packet counter to the FW. This is only required
273 * for older hardware revisions
274 */
275 if (wl->quirks & WLCORE_QUIRK_END_OF_TRANSACTION)
276 wl1271_write32(wl, WL12XX_REG_RX_DRIVER_COUNTER,
277 wl->rx_counter);
278
279 wl12xx_rearm_rx_streaming(wl, active_hlids);
280}
diff --git a/drivers/net/wireless/ti/wlcore/rx.h b/drivers/net/wireless/ti/wlcore/rx.h
new file mode 100644
index 000000000000..6e129e2a8546
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/rx.h
@@ -0,0 +1,142 @@
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 __RX_H__
26#define __RX_H__
27
28#include <linux/bitops.h>
29
30#define WL1271_RX_MAX_RSSI -30
31#define WL1271_RX_MIN_RSSI -95
32
33#define SHORT_PREAMBLE_BIT BIT(0)
34#define OFDM_RATE_BIT BIT(6)
35#define PBCC_RATE_BIT BIT(7)
36
37#define PLCP_HEADER_LENGTH 8
38#define RX_DESC_PACKETID_SHIFT 11
39#define RX_MAX_PACKET_ID 3
40
41#define NUM_RX_PKT_DESC_MOD_MASK 7
42
43#define RX_DESC_VALID_FCS 0x0001
44#define RX_DESC_MATCH_RXADDR1 0x0002
45#define RX_DESC_MCAST 0x0004
46#define RX_DESC_STAINTIM 0x0008
47#define RX_DESC_VIRTUAL_BM 0x0010
48#define RX_DESC_BCAST 0x0020
49#define RX_DESC_MATCH_SSID 0x0040
50#define RX_DESC_MATCH_BSSID 0x0080
51#define RX_DESC_ENCRYPTION_MASK 0x0300
52#define RX_DESC_MEASURMENT 0x0400
53#define RX_DESC_SEQNUM_MASK 0x1800
54#define RX_DESC_MIC_FAIL 0x2000
55#define RX_DESC_DECRYPT_FAIL 0x4000
56
57/*
58 * RX Descriptor flags:
59 *
60 * Bits 0-1 - band
61 * Bit 2 - STBC
62 * Bit 3 - A-MPDU
63 * Bit 4 - HT
64 * Bits 5-7 - encryption
65 */
66#define WL1271_RX_DESC_BAND_MASK 0x03
67#define WL1271_RX_DESC_ENCRYPT_MASK 0xE0
68
69#define WL1271_RX_DESC_BAND_BG 0x00
70#define WL1271_RX_DESC_BAND_J 0x01
71#define WL1271_RX_DESC_BAND_A 0x02
72
73#define WL1271_RX_DESC_STBC BIT(2)
74#define WL1271_RX_DESC_A_MPDU BIT(3)
75#define WL1271_RX_DESC_HT BIT(4)
76
77#define WL1271_RX_DESC_ENCRYPT_WEP 0x20
78#define WL1271_RX_DESC_ENCRYPT_TKIP 0x40
79#define WL1271_RX_DESC_ENCRYPT_AES 0x60
80#define WL1271_RX_DESC_ENCRYPT_GEM 0x80
81
82/*
83 * RX Descriptor status
84 *
85 * Bits 0-2 - error code
86 * Bits 3-5 - process_id tag (AP mode FW)
87 * Bits 6-7 - reserved
88 */
89#define WL1271_RX_DESC_STATUS_MASK 0x03
90
91#define WL1271_RX_DESC_SUCCESS 0x00
92#define WL1271_RX_DESC_DECRYPT_FAIL 0x01
93#define WL1271_RX_DESC_MIC_FAIL 0x02
94#define WL1271_RX_DESC_DRIVER_RX_Q_FAIL 0x03
95
96#define RX_MEM_BLOCK_MASK 0xFF
97#define RX_BUF_SIZE_MASK 0xFFF00
98#define RX_BUF_SIZE_SHIFT_DIV 6
99#define ALIGNED_RX_BUF_SIZE_MASK 0xFFFF00
100#define ALIGNED_RX_BUF_SIZE_SHIFT 8
101
102/* If set, the start of IP payload is not 4 bytes aligned */
103#define RX_BUF_UNALIGNED_PAYLOAD BIT(20)
104
105/* Describes the alignment state of a Rx buffer */
106enum wl_rx_buf_align {
107 WLCORE_RX_BUF_ALIGNED,
108 WLCORE_RX_BUF_UNALIGNED,
109 WLCORE_RX_BUF_PADDED,
110};
111
112enum {
113 WL12XX_RX_CLASS_UNKNOWN,
114 WL12XX_RX_CLASS_MANAGEMENT,
115 WL12XX_RX_CLASS_DATA,
116 WL12XX_RX_CLASS_QOS_DATA,
117 WL12XX_RX_CLASS_BCN_PRBRSP,
118 WL12XX_RX_CLASS_EAPOL,
119 WL12XX_RX_CLASS_BA_EVENT,
120 WL12XX_RX_CLASS_AMSDU,
121 WL12XX_RX_CLASS_LOGGER,
122};
123
124struct wl1271_rx_descriptor {
125 __le16 length;
126 u8 status;
127 u8 flags;
128 u8 rate;
129 u8 channel;
130 s8 rssi;
131 u8 snr;
132 __le32 timestamp;
133 u8 packet_class;
134 u8 hlid;
135 u8 pad_len;
136 u8 reserved;
137} __packed;
138
139void wl12xx_rx(struct wl1271 *wl, struct wl_fw_status *status);
140u8 wl1271_rate_to_idx(int rate, enum ieee80211_band band);
141
142#endif
diff --git a/drivers/net/wireless/ti/wlcore/scan.c b/drivers/net/wireless/ti/wlcore/scan.c
new file mode 100644
index 000000000000..ade21a011c45
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/scan.c
@@ -0,0 +1,790 @@
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 "wlcore.h"
27#include "debug.h"
28#include "cmd.h"
29#include "scan.h"
30#include "acx.h"
31#include "ps.h"
32#include "tx.h"
33
34void wl1271_scan_complete_work(struct work_struct *work)
35{
36 struct delayed_work *dwork;
37 struct wl1271 *wl;
38 struct ieee80211_vif *vif;
39 struct wl12xx_vif *wlvif;
40 int ret;
41
42 dwork = container_of(work, struct delayed_work, work);
43 wl = container_of(dwork, struct wl1271, scan_complete_work);
44
45 wl1271_debug(DEBUG_SCAN, "Scanning complete");
46
47 mutex_lock(&wl->mutex);
48
49 if (wl->state == WL1271_STATE_OFF)
50 goto out;
51
52 if (wl->scan.state == WL1271_SCAN_STATE_IDLE)
53 goto out;
54
55 vif = wl->scan_vif;
56 wlvif = wl12xx_vif_to_data(vif);
57
58 /*
59 * Rearm the tx watchdog just before idling scan. This
60 * prevents just-finished scans from triggering the watchdog
61 */
62 wl12xx_rearm_tx_watchdog_locked(wl);
63
64 wl->scan.state = WL1271_SCAN_STATE_IDLE;
65 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
66 wl->scan.req = NULL;
67 wl->scan_vif = NULL;
68
69 ret = wl1271_ps_elp_wakeup(wl);
70 if (ret < 0)
71 goto out;
72
73 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) {
74 /* restore hardware connection monitoring template */
75 wl1271_cmd_build_ap_probe_req(wl, wlvif, wlvif->probereq);
76 }
77
78 wl1271_ps_elp_sleep(wl);
79
80 if (wl->scan.failed) {
81 wl1271_info("Scan completed due to error.");
82 wl12xx_queue_recovery_work(wl);
83 }
84
85 ieee80211_scan_completed(wl->hw, false);
86
87out:
88 mutex_unlock(&wl->mutex);
89
90}
91
92
93static int wl1271_get_scan_channels(struct wl1271 *wl,
94 struct cfg80211_scan_request *req,
95 struct basic_scan_channel_params *channels,
96 enum ieee80211_band band, bool passive)
97{
98 struct conf_scan_settings *c = &wl->conf.scan;
99 int i, j;
100 u32 flags;
101
102 for (i = 0, j = 0;
103 i < req->n_channels && j < WL1271_SCAN_MAX_CHANNELS;
104 i++) {
105 flags = req->channels[i]->flags;
106
107 if (!test_bit(i, wl->scan.scanned_ch) &&
108 !(flags & IEEE80211_CHAN_DISABLED) &&
109 (req->channels[i]->band == band) &&
110 /*
111 * In passive scans, we scan all remaining
112 * channels, even if not marked as such.
113 * In active scans, we only scan channels not
114 * marked as passive.
115 */
116 (passive || !(flags & IEEE80211_CHAN_PASSIVE_SCAN))) {
117 wl1271_debug(DEBUG_SCAN, "band %d, center_freq %d ",
118 req->channels[i]->band,
119 req->channels[i]->center_freq);
120 wl1271_debug(DEBUG_SCAN, "hw_value %d, flags %X",
121 req->channels[i]->hw_value,
122 req->channels[i]->flags);
123 wl1271_debug(DEBUG_SCAN,
124 "max_antenna_gain %d, max_power %d",
125 req->channels[i]->max_antenna_gain,
126 req->channels[i]->max_power);
127 wl1271_debug(DEBUG_SCAN, "beacon_found %d",
128 req->channels[i]->beacon_found);
129
130 if (!passive) {
131 channels[j].min_duration =
132 cpu_to_le32(c->min_dwell_time_active);
133 channels[j].max_duration =
134 cpu_to_le32(c->max_dwell_time_active);
135 } else {
136 channels[j].min_duration =
137 cpu_to_le32(c->min_dwell_time_passive);
138 channels[j].max_duration =
139 cpu_to_le32(c->max_dwell_time_passive);
140 }
141 channels[j].early_termination = 0;
142 channels[j].tx_power_att = req->channels[i]->max_power;
143 channels[j].channel = req->channels[i]->hw_value;
144
145 memset(&channels[j].bssid_lsb, 0xff, 4);
146 memset(&channels[j].bssid_msb, 0xff, 2);
147
148 /* Mark the channels we already used */
149 set_bit(i, wl->scan.scanned_ch);
150
151 j++;
152 }
153 }
154
155 return j;
156}
157
158#define WL1271_NOTHING_TO_SCAN 1
159
160static int wl1271_scan_send(struct wl1271 *wl, struct ieee80211_vif *vif,
161 enum ieee80211_band band,
162 bool passive, u32 basic_rate)
163{
164 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
165 struct wl1271_cmd_scan *cmd;
166 struct wl1271_cmd_trigger_scan_to *trigger;
167 int ret;
168 u16 scan_options = 0;
169
170 /* skip active scans if we don't have SSIDs */
171 if (!passive && wl->scan.req->n_ssids == 0)
172 return WL1271_NOTHING_TO_SCAN;
173
174 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
175 trigger = kzalloc(sizeof(*trigger), GFP_KERNEL);
176 if (!cmd || !trigger) {
177 ret = -ENOMEM;
178 goto out;
179 }
180
181 if (wl->conf.scan.split_scan_timeout)
182 scan_options |= WL1271_SCAN_OPT_SPLIT_SCAN;
183
184 if (passive)
185 scan_options |= WL1271_SCAN_OPT_PASSIVE;
186
187 if (wlvif->bss_type == BSS_TYPE_AP_BSS ||
188 test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
189 cmd->params.role_id = wlvif->role_id;
190 else
191 cmd->params.role_id = wlvif->dev_role_id;
192
193 if (WARN_ON(cmd->params.role_id == WL12XX_INVALID_ROLE_ID)) {
194 ret = -EINVAL;
195 goto out;
196 }
197
198 cmd->params.scan_options = cpu_to_le16(scan_options);
199
200 cmd->params.n_ch = wl1271_get_scan_channels(wl, wl->scan.req,
201 cmd->channels,
202 band, passive);
203 if (cmd->params.n_ch == 0) {
204 ret = WL1271_NOTHING_TO_SCAN;
205 goto out;
206 }
207
208 cmd->params.tx_rate = cpu_to_le32(basic_rate);
209 cmd->params.n_probe_reqs = wl->conf.scan.num_probe_reqs;
210 cmd->params.tid_trigger = CONF_TX_AC_ANY_TID;
211 cmd->params.scan_tag = WL1271_SCAN_DEFAULT_TAG;
212
213 if (band == IEEE80211_BAND_2GHZ)
214 cmd->params.band = WL1271_SCAN_BAND_2_4_GHZ;
215 else
216 cmd->params.band = WL1271_SCAN_BAND_5_GHZ;
217
218 if (wl->scan.ssid_len && wl->scan.ssid) {
219 cmd->params.ssid_len = wl->scan.ssid_len;
220 memcpy(cmd->params.ssid, wl->scan.ssid, wl->scan.ssid_len);
221 }
222
223 memcpy(cmd->addr, vif->addr, ETH_ALEN);
224
225 ret = wl12xx_cmd_build_probe_req(wl, wlvif,
226 cmd->params.role_id, band,
227 wl->scan.ssid, wl->scan.ssid_len,
228 wl->scan.req->ie,
229 wl->scan.req->ie_len);
230 if (ret < 0) {
231 wl1271_error("PROBE request template failed");
232 goto out;
233 }
234
235 trigger->timeout = cpu_to_le32(wl->conf.scan.split_scan_timeout);
236 ret = wl1271_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger,
237 sizeof(*trigger), 0);
238 if (ret < 0) {
239 wl1271_error("trigger scan to failed for hw scan");
240 goto out;
241 }
242
243 wl1271_dump(DEBUG_SCAN, "SCAN: ", cmd, sizeof(*cmd));
244
245 ret = wl1271_cmd_send(wl, CMD_SCAN, cmd, sizeof(*cmd), 0);
246 if (ret < 0) {
247 wl1271_error("SCAN failed");
248 goto out;
249 }
250
251out:
252 kfree(cmd);
253 kfree(trigger);
254 return ret;
255}
256
257void wl1271_scan_stm(struct wl1271 *wl, struct ieee80211_vif *vif)
258{
259 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
260 int ret = 0;
261 enum ieee80211_band band;
262 u32 rate, mask;
263
264 switch (wl->scan.state) {
265 case WL1271_SCAN_STATE_IDLE:
266 break;
267
268 case WL1271_SCAN_STATE_2GHZ_ACTIVE:
269 band = IEEE80211_BAND_2GHZ;
270 mask = wlvif->bitrate_masks[band];
271 if (wl->scan.req->no_cck) {
272 mask &= ~CONF_TX_CCK_RATES;
273 if (!mask)
274 mask = CONF_TX_RATE_MASK_BASIC_P2P;
275 }
276 rate = wl1271_tx_min_rate_get(wl, mask);
277 ret = wl1271_scan_send(wl, vif, band, false, rate);
278 if (ret == WL1271_NOTHING_TO_SCAN) {
279 wl->scan.state = WL1271_SCAN_STATE_2GHZ_PASSIVE;
280 wl1271_scan_stm(wl, vif);
281 }
282
283 break;
284
285 case WL1271_SCAN_STATE_2GHZ_PASSIVE:
286 band = IEEE80211_BAND_2GHZ;
287 mask = wlvif->bitrate_masks[band];
288 if (wl->scan.req->no_cck) {
289 mask &= ~CONF_TX_CCK_RATES;
290 if (!mask)
291 mask = CONF_TX_RATE_MASK_BASIC_P2P;
292 }
293 rate = wl1271_tx_min_rate_get(wl, mask);
294 ret = wl1271_scan_send(wl, vif, band, true, rate);
295 if (ret == WL1271_NOTHING_TO_SCAN) {
296 if (wl->enable_11a)
297 wl->scan.state = WL1271_SCAN_STATE_5GHZ_ACTIVE;
298 else
299 wl->scan.state = WL1271_SCAN_STATE_DONE;
300 wl1271_scan_stm(wl, vif);
301 }
302
303 break;
304
305 case WL1271_SCAN_STATE_5GHZ_ACTIVE:
306 band = IEEE80211_BAND_5GHZ;
307 rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[band]);
308 ret = wl1271_scan_send(wl, vif, band, false, rate);
309 if (ret == WL1271_NOTHING_TO_SCAN) {
310 wl->scan.state = WL1271_SCAN_STATE_5GHZ_PASSIVE;
311 wl1271_scan_stm(wl, vif);
312 }
313
314 break;
315
316 case WL1271_SCAN_STATE_5GHZ_PASSIVE:
317 band = IEEE80211_BAND_5GHZ;
318 rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[band]);
319 ret = wl1271_scan_send(wl, vif, band, true, rate);
320 if (ret == WL1271_NOTHING_TO_SCAN) {
321 wl->scan.state = WL1271_SCAN_STATE_DONE;
322 wl1271_scan_stm(wl, vif);
323 }
324
325 break;
326
327 case WL1271_SCAN_STATE_DONE:
328 wl->scan.failed = false;
329 cancel_delayed_work(&wl->scan_complete_work);
330 ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work,
331 msecs_to_jiffies(0));
332 break;
333
334 default:
335 wl1271_error("invalid scan state");
336 break;
337 }
338
339 if (ret < 0) {
340 cancel_delayed_work(&wl->scan_complete_work);
341 ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work,
342 msecs_to_jiffies(0));
343 }
344}
345
346int wl1271_scan(struct wl1271 *wl, struct ieee80211_vif *vif,
347 const u8 *ssid, size_t ssid_len,
348 struct cfg80211_scan_request *req)
349{
350 /*
351 * cfg80211 should guarantee that we don't get more channels
352 * than what we have registered.
353 */
354 BUG_ON(req->n_channels > WL1271_MAX_CHANNELS);
355
356 if (wl->scan.state != WL1271_SCAN_STATE_IDLE)
357 return -EBUSY;
358
359 wl->scan.state = WL1271_SCAN_STATE_2GHZ_ACTIVE;
360
361 if (ssid_len && ssid) {
362 wl->scan.ssid_len = ssid_len;
363 memcpy(wl->scan.ssid, ssid, ssid_len);
364 } else {
365 wl->scan.ssid_len = 0;
366 }
367
368 wl->scan_vif = vif;
369 wl->scan.req = req;
370 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
371
372 /* we assume failure so that timeout scenarios are handled correctly */
373 wl->scan.failed = true;
374 ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work,
375 msecs_to_jiffies(WL1271_SCAN_TIMEOUT));
376
377 wl1271_scan_stm(wl, vif);
378
379 return 0;
380}
381
382int wl1271_scan_stop(struct wl1271 *wl)
383{
384 struct wl1271_cmd_header *cmd = NULL;
385 int ret = 0;
386
387 if (WARN_ON(wl->scan.state == WL1271_SCAN_STATE_IDLE))
388 return -EINVAL;
389
390 wl1271_debug(DEBUG_CMD, "cmd scan stop");
391
392 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
393 if (!cmd) {
394 ret = -ENOMEM;
395 goto out;
396 }
397
398 ret = wl1271_cmd_send(wl, CMD_STOP_SCAN, cmd,
399 sizeof(*cmd), 0);
400 if (ret < 0) {
401 wl1271_error("cmd stop_scan failed");
402 goto out;
403 }
404out:
405 kfree(cmd);
406 return ret;
407}
408
409static int
410wl1271_scan_get_sched_scan_channels(struct wl1271 *wl,
411 struct cfg80211_sched_scan_request *req,
412 struct conn_scan_ch_params *channels,
413 u32 band, bool radar, bool passive,
414 int start, int max_channels)
415{
416 struct conf_sched_scan_settings *c = &wl->conf.sched_scan;
417 int i, j;
418 u32 flags;
419 bool force_passive = !req->n_ssids;
420 u32 min_dwell_time_active, max_dwell_time_active, delta_per_probe;
421 u32 dwell_time_passive, dwell_time_dfs;
422
423 if (band == IEEE80211_BAND_5GHZ)
424 delta_per_probe = c->dwell_time_delta_per_probe_5;
425 else
426 delta_per_probe = c->dwell_time_delta_per_probe;
427
428 min_dwell_time_active = c->base_dwell_time +
429 req->n_ssids * c->num_probe_reqs * delta_per_probe;
430
431 max_dwell_time_active = min_dwell_time_active + c->max_dwell_time_delta;
432
433 min_dwell_time_active = DIV_ROUND_UP(min_dwell_time_active, 1000);
434 max_dwell_time_active = DIV_ROUND_UP(max_dwell_time_active, 1000);
435 dwell_time_passive = DIV_ROUND_UP(c->dwell_time_passive, 1000);
436 dwell_time_dfs = DIV_ROUND_UP(c->dwell_time_dfs, 1000);
437
438 for (i = 0, j = start;
439 i < req->n_channels && j < max_channels;
440 i++) {
441 flags = req->channels[i]->flags;
442
443 if (force_passive)
444 flags |= IEEE80211_CHAN_PASSIVE_SCAN;
445
446 if ((req->channels[i]->band == band) &&
447 !(flags & IEEE80211_CHAN_DISABLED) &&
448 (!!(flags & IEEE80211_CHAN_RADAR) == radar) &&
449 /* if radar is set, we ignore the passive flag */
450 (radar ||
451 !!(flags & IEEE80211_CHAN_PASSIVE_SCAN) == passive)) {
452 wl1271_debug(DEBUG_SCAN, "band %d, center_freq %d ",
453 req->channels[i]->band,
454 req->channels[i]->center_freq);
455 wl1271_debug(DEBUG_SCAN, "hw_value %d, flags %X",
456 req->channels[i]->hw_value,
457 req->channels[i]->flags);
458 wl1271_debug(DEBUG_SCAN, "max_power %d",
459 req->channels[i]->max_power);
460 wl1271_debug(DEBUG_SCAN, "min_dwell_time %d max dwell time %d",
461 min_dwell_time_active,
462 max_dwell_time_active);
463
464 if (flags & IEEE80211_CHAN_RADAR) {
465 channels[j].flags |= SCAN_CHANNEL_FLAGS_DFS;
466
467 channels[j].passive_duration =
468 cpu_to_le16(dwell_time_dfs);
469 } else {
470 channels[j].passive_duration =
471 cpu_to_le16(dwell_time_passive);
472 }
473
474 channels[j].min_duration =
475 cpu_to_le16(min_dwell_time_active);
476 channels[j].max_duration =
477 cpu_to_le16(max_dwell_time_active);
478
479 channels[j].tx_power_att = req->channels[i]->max_power;
480 channels[j].channel = req->channels[i]->hw_value;
481
482 j++;
483 }
484 }
485
486 return j - start;
487}
488
489static bool
490wl1271_scan_sched_scan_channels(struct wl1271 *wl,
491 struct cfg80211_sched_scan_request *req,
492 struct wl1271_cmd_sched_scan_config *cfg)
493{
494 cfg->passive[0] =
495 wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_2,
496 IEEE80211_BAND_2GHZ,
497 false, true, 0,
498 MAX_CHANNELS_2GHZ);
499 cfg->active[0] =
500 wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_2,
501 IEEE80211_BAND_2GHZ,
502 false, false,
503 cfg->passive[0],
504 MAX_CHANNELS_2GHZ);
505 cfg->passive[1] =
506 wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_5,
507 IEEE80211_BAND_5GHZ,
508 false, true, 0,
509 MAX_CHANNELS_5GHZ);
510 cfg->dfs =
511 wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_5,
512 IEEE80211_BAND_5GHZ,
513 true, true,
514 cfg->passive[1],
515 MAX_CHANNELS_5GHZ);
516 cfg->active[1] =
517 wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_5,
518 IEEE80211_BAND_5GHZ,
519 false, false,
520 cfg->passive[1] + cfg->dfs,
521 MAX_CHANNELS_5GHZ);
522 /* 802.11j channels are not supported yet */
523 cfg->passive[2] = 0;
524 cfg->active[2] = 0;
525
526 wl1271_debug(DEBUG_SCAN, " 2.4GHz: active %d passive %d",
527 cfg->active[0], cfg->passive[0]);
528 wl1271_debug(DEBUG_SCAN, " 5GHz: active %d passive %d",
529 cfg->active[1], cfg->passive[1]);
530 wl1271_debug(DEBUG_SCAN, " DFS: %d", cfg->dfs);
531
532 return cfg->passive[0] || cfg->active[0] ||
533 cfg->passive[1] || cfg->active[1] || cfg->dfs ||
534 cfg->passive[2] || cfg->active[2];
535}
536
537/* Returns the scan type to be used or a negative value on error */
538static int
539wl12xx_scan_sched_scan_ssid_list(struct wl1271 *wl,
540 struct cfg80211_sched_scan_request *req)
541{
542 struct wl1271_cmd_sched_scan_ssid_list *cmd = NULL;
543 struct cfg80211_match_set *sets = req->match_sets;
544 struct cfg80211_ssid *ssids = req->ssids;
545 int ret = 0, type, i, j, n_match_ssids = 0;
546
547 wl1271_debug(DEBUG_CMD, "cmd sched scan ssid list");
548
549 /* count the match sets that contain SSIDs */
550 for (i = 0; i < req->n_match_sets; i++)
551 if (sets[i].ssid.ssid_len > 0)
552 n_match_ssids++;
553
554 /* No filter, no ssids or only bcast ssid */
555 if (!n_match_ssids &&
556 (!req->n_ssids ||
557 (req->n_ssids == 1 && req->ssids[0].ssid_len == 0))) {
558 type = SCAN_SSID_FILTER_ANY;
559 goto out;
560 }
561
562 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
563 if (!cmd) {
564 ret = -ENOMEM;
565 goto out;
566 }
567
568 if (!n_match_ssids) {
569 /* No filter, with ssids */
570 type = SCAN_SSID_FILTER_DISABLED;
571
572 for (i = 0; i < req->n_ssids; i++) {
573 cmd->ssids[cmd->n_ssids].type = (ssids[i].ssid_len) ?
574 SCAN_SSID_TYPE_HIDDEN : SCAN_SSID_TYPE_PUBLIC;
575 cmd->ssids[cmd->n_ssids].len = ssids[i].ssid_len;
576 memcpy(cmd->ssids[cmd->n_ssids].ssid, ssids[i].ssid,
577 ssids[i].ssid_len);
578 cmd->n_ssids++;
579 }
580 } else {
581 type = SCAN_SSID_FILTER_LIST;
582
583 /* Add all SSIDs from the filters */
584 for (i = 0; i < req->n_match_sets; i++) {
585 /* ignore sets without SSIDs */
586 if (!sets[i].ssid.ssid_len)
587 continue;
588
589 cmd->ssids[cmd->n_ssids].type = SCAN_SSID_TYPE_PUBLIC;
590 cmd->ssids[cmd->n_ssids].len = sets[i].ssid.ssid_len;
591 memcpy(cmd->ssids[cmd->n_ssids].ssid,
592 sets[i].ssid.ssid, sets[i].ssid.ssid_len);
593 cmd->n_ssids++;
594 }
595 if ((req->n_ssids > 1) ||
596 (req->n_ssids == 1 && req->ssids[0].ssid_len > 0)) {
597 /*
598 * Mark all the SSIDs passed in the SSID list as HIDDEN,
599 * so they're used in probe requests.
600 */
601 for (i = 0; i < req->n_ssids; i++) {
602 if (!req->ssids[i].ssid_len)
603 continue;
604
605 for (j = 0; j < cmd->n_ssids; j++)
606 if (!memcmp(req->ssids[i].ssid,
607 cmd->ssids[j].ssid,
608 req->ssids[i].ssid_len)) {
609 cmd->ssids[j].type =
610 SCAN_SSID_TYPE_HIDDEN;
611 break;
612 }
613 /* Fail if SSID isn't present in the filters */
614 if (j == cmd->n_ssids) {
615 ret = -EINVAL;
616 goto out_free;
617 }
618 }
619 }
620 }
621
622 wl1271_dump(DEBUG_SCAN, "SSID_LIST: ", cmd, sizeof(*cmd));
623
624 ret = wl1271_cmd_send(wl, CMD_CONNECTION_SCAN_SSID_CFG, cmd,
625 sizeof(*cmd), 0);
626 if (ret < 0) {
627 wl1271_error("cmd sched scan ssid list failed");
628 goto out_free;
629 }
630
631out_free:
632 kfree(cmd);
633out:
634 if (ret < 0)
635 return ret;
636 return type;
637}
638
639int wl1271_scan_sched_scan_config(struct wl1271 *wl,
640 struct wl12xx_vif *wlvif,
641 struct cfg80211_sched_scan_request *req,
642 struct ieee80211_sched_scan_ies *ies)
643{
644 struct wl1271_cmd_sched_scan_config *cfg = NULL;
645 struct conf_sched_scan_settings *c = &wl->conf.sched_scan;
646 int i, ret;
647 bool force_passive = !req->n_ssids;
648
649 wl1271_debug(DEBUG_CMD, "cmd sched_scan scan config");
650
651 cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
652 if (!cfg)
653 return -ENOMEM;
654
655 cfg->rssi_threshold = c->rssi_threshold;
656 cfg->snr_threshold = c->snr_threshold;
657 cfg->n_probe_reqs = c->num_probe_reqs;
658 /* cycles set to 0 it means infinite (until manually stopped) */
659 cfg->cycles = 0;
660 /* report APs when at least 1 is found */
661 cfg->report_after = 1;
662 /* don't stop scanning automatically when something is found */
663 cfg->terminate = 0;
664 cfg->tag = WL1271_SCAN_DEFAULT_TAG;
665 /* don't filter on BSS type */
666 cfg->bss_type = SCAN_BSS_TYPE_ANY;
667 /* currently NL80211 supports only a single interval */
668 for (i = 0; i < SCAN_MAX_CYCLE_INTERVALS; i++)
669 cfg->intervals[i] = cpu_to_le32(req->interval);
670
671 cfg->ssid_len = 0;
672 ret = wl12xx_scan_sched_scan_ssid_list(wl, req);
673 if (ret < 0)
674 goto out;
675
676 cfg->filter_type = ret;
677
678 wl1271_debug(DEBUG_SCAN, "filter_type = %d", cfg->filter_type);
679
680 if (!wl1271_scan_sched_scan_channels(wl, req, cfg)) {
681 wl1271_error("scan channel list is empty");
682 ret = -EINVAL;
683 goto out;
684 }
685
686 if (!force_passive && cfg->active[0]) {
687 u8 band = IEEE80211_BAND_2GHZ;
688 ret = wl12xx_cmd_build_probe_req(wl, wlvif,
689 wlvif->dev_role_id, band,
690 req->ssids[0].ssid,
691 req->ssids[0].ssid_len,
692 ies->ie[band],
693 ies->len[band]);
694 if (ret < 0) {
695 wl1271_error("2.4GHz PROBE request template failed");
696 goto out;
697 }
698 }
699
700 if (!force_passive && cfg->active[1]) {
701 u8 band = IEEE80211_BAND_5GHZ;
702 ret = wl12xx_cmd_build_probe_req(wl, wlvif,
703 wlvif->dev_role_id, band,
704 req->ssids[0].ssid,
705 req->ssids[0].ssid_len,
706 ies->ie[band],
707 ies->len[band]);
708 if (ret < 0) {
709 wl1271_error("5GHz PROBE request template failed");
710 goto out;
711 }
712 }
713
714 wl1271_dump(DEBUG_SCAN, "SCAN_CFG: ", cfg, sizeof(*cfg));
715
716 ret = wl1271_cmd_send(wl, CMD_CONNECTION_SCAN_CFG, cfg,
717 sizeof(*cfg), 0);
718 if (ret < 0) {
719 wl1271_error("SCAN configuration failed");
720 goto out;
721 }
722out:
723 kfree(cfg);
724 return ret;
725}
726
727int wl1271_scan_sched_scan_start(struct wl1271 *wl, struct wl12xx_vif *wlvif)
728{
729 struct wl1271_cmd_sched_scan_start *start;
730 int ret = 0;
731
732 wl1271_debug(DEBUG_CMD, "cmd periodic scan start");
733
734 if (wlvif->bss_type != BSS_TYPE_STA_BSS)
735 return -EOPNOTSUPP;
736
737 if (test_bit(WLVIF_FLAG_IN_USE, &wlvif->flags))
738 return -EBUSY;
739
740 start = kzalloc(sizeof(*start), GFP_KERNEL);
741 if (!start)
742 return -ENOMEM;
743
744 start->tag = WL1271_SCAN_DEFAULT_TAG;
745
746 ret = wl1271_cmd_send(wl, CMD_START_PERIODIC_SCAN, start,
747 sizeof(*start), 0);
748 if (ret < 0) {
749 wl1271_error("failed to send scan start command");
750 goto out_free;
751 }
752
753out_free:
754 kfree(start);
755 return ret;
756}
757
758void wl1271_scan_sched_scan_results(struct wl1271 *wl)
759{
760 wl1271_debug(DEBUG_SCAN, "got periodic scan results");
761
762 ieee80211_sched_scan_results(wl->hw);
763}
764
765void wl1271_scan_sched_scan_stop(struct wl1271 *wl)
766{
767 struct wl1271_cmd_sched_scan_stop *stop;
768 int ret = 0;
769
770 wl1271_debug(DEBUG_CMD, "cmd periodic scan stop");
771
772 /* FIXME: what to do if alloc'ing to stop fails? */
773 stop = kzalloc(sizeof(*stop), GFP_KERNEL);
774 if (!stop) {
775 wl1271_error("failed to alloc memory to send sched scan stop");
776 return;
777 }
778
779 stop->tag = WL1271_SCAN_DEFAULT_TAG;
780
781 ret = wl1271_cmd_send(wl, CMD_STOP_PERIODIC_SCAN, stop,
782 sizeof(*stop), 0);
783 if (ret < 0) {
784 wl1271_error("failed to send sched scan stop command");
785 goto out_free;
786 }
787
788out_free:
789 kfree(stop);
790}
diff --git a/drivers/net/wireless/ti/wlcore/scan.h b/drivers/net/wireless/ti/wlcore/scan.h
new file mode 100644
index 000000000000..81ee36ac2078
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/scan.h
@@ -0,0 +1,233 @@
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#ifndef __SCAN_H__
25#define __SCAN_H__
26
27#include "wlcore.h"
28
29int wl1271_scan(struct wl1271 *wl, struct ieee80211_vif *vif,
30 const u8 *ssid, size_t ssid_len,
31 struct cfg80211_scan_request *req);
32int wl1271_scan_stop(struct wl1271 *wl);
33int wl1271_scan_build_probe_req(struct wl1271 *wl,
34 const u8 *ssid, size_t ssid_len,
35 const u8 *ie, size_t ie_len, u8 band);
36void wl1271_scan_stm(struct wl1271 *wl, struct ieee80211_vif *vif);
37void wl1271_scan_complete_work(struct work_struct *work);
38int wl1271_scan_sched_scan_config(struct wl1271 *wl,
39 struct wl12xx_vif *wlvif,
40 struct cfg80211_sched_scan_request *req,
41 struct ieee80211_sched_scan_ies *ies);
42int wl1271_scan_sched_scan_start(struct wl1271 *wl, struct wl12xx_vif *wlvif);
43void wl1271_scan_sched_scan_stop(struct wl1271 *wl);
44void wl1271_scan_sched_scan_results(struct wl1271 *wl);
45
46#define WL1271_SCAN_MAX_CHANNELS 24
47#define WL1271_SCAN_DEFAULT_TAG 1
48#define WL1271_SCAN_CURRENT_TX_PWR 0
49#define WL1271_SCAN_OPT_ACTIVE 0
50#define WL1271_SCAN_OPT_PASSIVE 1
51#define WL1271_SCAN_OPT_SPLIT_SCAN 2
52#define WL1271_SCAN_OPT_PRIORITY_HIGH 4
53/* scan even if we fail to enter psm */
54#define WL1271_SCAN_OPT_FORCE 8
55#define WL1271_SCAN_BAND_2_4_GHZ 0
56#define WL1271_SCAN_BAND_5_GHZ 1
57
58#define WL1271_SCAN_TIMEOUT 30000 /* msec */
59
60enum {
61 WL1271_SCAN_STATE_IDLE,
62 WL1271_SCAN_STATE_2GHZ_ACTIVE,
63 WL1271_SCAN_STATE_2GHZ_PASSIVE,
64 WL1271_SCAN_STATE_5GHZ_ACTIVE,
65 WL1271_SCAN_STATE_5GHZ_PASSIVE,
66 WL1271_SCAN_STATE_DONE
67};
68
69struct basic_scan_params {
70 /* Scan option flags (WL1271_SCAN_OPT_*) */
71 __le16 scan_options;
72 u8 role_id;
73 /* Number of scan channels in the list (maximum 30) */
74 u8 n_ch;
75 /* This field indicates the number of probe requests to send
76 per channel for an active scan */
77 u8 n_probe_reqs;
78 u8 tid_trigger;
79 u8 ssid_len;
80 u8 use_ssid_list;
81
82 /* Rate bit field for sending the probes */
83 __le32 tx_rate;
84
85 u8 ssid[IEEE80211_MAX_SSID_LEN];
86 /* Band to scan */
87 u8 band;
88
89 u8 scan_tag;
90 u8 padding2[2];
91} __packed;
92
93struct basic_scan_channel_params {
94 /* Duration in TU to wait for frames on a channel for active scan */
95 __le32 min_duration;
96 __le32 max_duration;
97 __le32 bssid_lsb;
98 __le16 bssid_msb;
99 u8 early_termination;
100 u8 tx_power_att;
101 u8 channel;
102 /* FW internal use only! */
103 u8 dfs_candidate;
104 u8 activity_detected;
105 u8 pad;
106} __packed;
107
108struct wl1271_cmd_scan {
109 struct wl1271_cmd_header header;
110
111 struct basic_scan_params params;
112 struct basic_scan_channel_params channels[WL1271_SCAN_MAX_CHANNELS];
113
114 /* src mac address */
115 u8 addr[ETH_ALEN];
116 u8 padding[2];
117} __packed;
118
119struct wl1271_cmd_trigger_scan_to {
120 struct wl1271_cmd_header header;
121
122 __le32 timeout;
123} __packed;
124
125#define MAX_CHANNELS_2GHZ 14
126#define MAX_CHANNELS_5GHZ 23
127#define MAX_CHANNELS_4GHZ 4
128
129#define SCAN_MAX_CYCLE_INTERVALS 16
130#define SCAN_MAX_BANDS 3
131
132enum {
133 SCAN_SSID_FILTER_ANY = 0,
134 SCAN_SSID_FILTER_SPECIFIC = 1,
135 SCAN_SSID_FILTER_LIST = 2,
136 SCAN_SSID_FILTER_DISABLED = 3
137};
138
139enum {
140 SCAN_BSS_TYPE_INDEPENDENT,
141 SCAN_BSS_TYPE_INFRASTRUCTURE,
142 SCAN_BSS_TYPE_ANY,
143};
144
145#define SCAN_CHANNEL_FLAGS_DFS BIT(0)
146#define SCAN_CHANNEL_FLAGS_DFS_ENABLED BIT(1)
147
148struct conn_scan_ch_params {
149 __le16 min_duration;
150 __le16 max_duration;
151 __le16 passive_duration;
152
153 u8 channel;
154 u8 tx_power_att;
155
156 /* bit 0: DFS channel; bit 1: DFS enabled */
157 u8 flags;
158
159 u8 padding[3];
160} __packed;
161
162struct wl1271_cmd_sched_scan_config {
163 struct wl1271_cmd_header header;
164
165 __le32 intervals[SCAN_MAX_CYCLE_INTERVALS];
166
167 s8 rssi_threshold; /* for filtering (in dBm) */
168 s8 snr_threshold; /* for filtering (in dB) */
169
170 u8 cycles; /* maximum number of scan cycles */
171 u8 report_after; /* report when this number of results are received */
172 u8 terminate; /* stop scanning after reporting */
173
174 u8 tag;
175 u8 bss_type; /* for filtering */
176 u8 filter_type;
177
178 u8 ssid_len; /* For SCAN_SSID_FILTER_SPECIFIC */
179 u8 ssid[IEEE80211_MAX_SSID_LEN];
180
181 u8 n_probe_reqs; /* Number of probes requests per channel */
182
183 u8 passive[SCAN_MAX_BANDS];
184 u8 active[SCAN_MAX_BANDS];
185
186 u8 dfs;
187
188 u8 padding[3];
189
190 struct conn_scan_ch_params channels_2[MAX_CHANNELS_2GHZ];
191 struct conn_scan_ch_params channels_5[MAX_CHANNELS_5GHZ];
192 struct conn_scan_ch_params channels_4[MAX_CHANNELS_4GHZ];
193} __packed;
194
195
196#define SCHED_SCAN_MAX_SSIDS 16
197
198enum {
199 SCAN_SSID_TYPE_PUBLIC = 0,
200 SCAN_SSID_TYPE_HIDDEN = 1,
201};
202
203struct wl1271_ssid {
204 u8 type;
205 u8 len;
206 u8 ssid[IEEE80211_MAX_SSID_LEN];
207 /* u8 padding[2]; */
208} __packed;
209
210struct wl1271_cmd_sched_scan_ssid_list {
211 struct wl1271_cmd_header header;
212
213 u8 n_ssids;
214 struct wl1271_ssid ssids[SCHED_SCAN_MAX_SSIDS];
215 u8 padding[3];
216} __packed;
217
218struct wl1271_cmd_sched_scan_start {
219 struct wl1271_cmd_header header;
220
221 u8 tag;
222 u8 padding[3];
223} __packed;
224
225struct wl1271_cmd_sched_scan_stop {
226 struct wl1271_cmd_header header;
227
228 u8 tag;
229 u8 padding[3];
230} __packed;
231
232
233#endif /* __WL1271_SCAN_H__ */
diff --git a/drivers/net/wireless/ti/wlcore/sdio.c b/drivers/net/wireless/ti/wlcore/sdio.c
new file mode 100644
index 000000000000..0a72347cfc4c
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/sdio.c
@@ -0,0 +1,378 @@
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/irq.h>
25#include <linux/module.h>
26#include <linux/vmalloc.h>
27#include <linux/platform_device.h>
28#include <linux/mmc/sdio_func.h>
29#include <linux/mmc/sdio_ids.h>
30#include <linux/mmc/card.h>
31#include <linux/mmc/host.h>
32#include <linux/gpio.h>
33#include <linux/wl12xx.h>
34#include <linux/pm_runtime.h>
35
36#include "wlcore.h"
37#include "wl12xx_80211.h"
38#include "io.h"
39
40#ifndef SDIO_VENDOR_ID_TI
41#define SDIO_VENDOR_ID_TI 0x0097
42#endif
43
44#ifndef SDIO_DEVICE_ID_TI_WL1271
45#define SDIO_DEVICE_ID_TI_WL1271 0x4076
46#endif
47
48struct wl12xx_sdio_glue {
49 struct device *dev;
50 struct platform_device *core;
51};
52
53static const struct sdio_device_id wl1271_devices[] __devinitconst = {
54 { SDIO_DEVICE(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271) },
55 {}
56};
57MODULE_DEVICE_TABLE(sdio, wl1271_devices);
58
59static void wl1271_sdio_set_block_size(struct device *child,
60 unsigned int blksz)
61{
62 struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent);
63 struct sdio_func *func = dev_to_sdio_func(glue->dev);
64
65 sdio_claim_host(func);
66 sdio_set_block_size(func, blksz);
67 sdio_release_host(func);
68}
69
70static void wl12xx_sdio_raw_read(struct device *child, int addr, void *buf,
71 size_t len, bool fixed)
72{
73 int ret;
74 struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent);
75 struct sdio_func *func = dev_to_sdio_func(glue->dev);
76
77 sdio_claim_host(func);
78
79 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG)) {
80 ((u8 *)buf)[0] = sdio_f0_readb(func, addr, &ret);
81 dev_dbg(child->parent, "sdio read 52 addr 0x%x, byte 0x%02x\n",
82 addr, ((u8 *)buf)[0]);
83 } else {
84 if (fixed)
85 ret = sdio_readsb(func, buf, addr, len);
86 else
87 ret = sdio_memcpy_fromio(func, buf, addr, len);
88
89 dev_dbg(child->parent, "sdio read 53 addr 0x%x, %zu bytes\n",
90 addr, len);
91 }
92
93 sdio_release_host(func);
94
95 if (ret)
96 dev_err(child->parent, "sdio read failed (%d)\n", ret);
97}
98
99static void wl12xx_sdio_raw_write(struct device *child, int addr, void *buf,
100 size_t len, bool fixed)
101{
102 int ret;
103 struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent);
104 struct sdio_func *func = dev_to_sdio_func(glue->dev);
105
106 sdio_claim_host(func);
107
108 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG)) {
109 sdio_f0_writeb(func, ((u8 *)buf)[0], addr, &ret);
110 dev_dbg(child->parent, "sdio write 52 addr 0x%x, byte 0x%02x\n",
111 addr, ((u8 *)buf)[0]);
112 } else {
113 dev_dbg(child->parent, "sdio write 53 addr 0x%x, %zu bytes\n",
114 addr, len);
115
116 if (fixed)
117 ret = sdio_writesb(func, addr, buf, len);
118 else
119 ret = sdio_memcpy_toio(func, addr, buf, len);
120 }
121
122 sdio_release_host(func);
123
124 if (ret)
125 dev_err(child->parent, "sdio write failed (%d)\n", ret);
126}
127
128static int wl12xx_sdio_power_on(struct wl12xx_sdio_glue *glue)
129{
130 int ret;
131 struct sdio_func *func = dev_to_sdio_func(glue->dev);
132
133 /* If enabled, tell runtime PM not to power off the card */
134 if (pm_runtime_enabled(&func->dev)) {
135 ret = pm_runtime_get_sync(&func->dev);
136 if (ret < 0)
137 goto out;
138 } else {
139 /* Runtime PM is disabled: power up the card manually */
140 ret = mmc_power_restore_host(func->card->host);
141 if (ret < 0)
142 goto out;
143 }
144
145 sdio_claim_host(func);
146 sdio_enable_func(func);
147 sdio_release_host(func);
148
149out:
150 return ret;
151}
152
153static int wl12xx_sdio_power_off(struct wl12xx_sdio_glue *glue)
154{
155 int ret;
156 struct sdio_func *func = dev_to_sdio_func(glue->dev);
157
158 sdio_claim_host(func);
159 sdio_disable_func(func);
160 sdio_release_host(func);
161
162 /* Power off the card manually, even if runtime PM is enabled. */
163 ret = mmc_power_save_host(func->card->host);
164 if (ret < 0)
165 return ret;
166
167 /* If enabled, let runtime PM know the card is powered off */
168 if (pm_runtime_enabled(&func->dev))
169 ret = pm_runtime_put_sync(&func->dev);
170
171 return ret;
172}
173
174static int wl12xx_sdio_set_power(struct device *child, bool enable)
175{
176 struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent);
177
178 if (enable)
179 return wl12xx_sdio_power_on(glue);
180 else
181 return wl12xx_sdio_power_off(glue);
182}
183
184static struct wl1271_if_operations sdio_ops = {
185 .read = wl12xx_sdio_raw_read,
186 .write = wl12xx_sdio_raw_write,
187 .power = wl12xx_sdio_set_power,
188 .set_block_size = wl1271_sdio_set_block_size,
189};
190
191static int __devinit wl1271_probe(struct sdio_func *func,
192 const struct sdio_device_id *id)
193{
194 struct wl12xx_platform_data *wlan_data;
195 struct wl12xx_sdio_glue *glue;
196 struct resource res[1];
197 mmc_pm_flag_t mmcflags;
198 int ret = -ENOMEM;
199
200 /* We are only able to handle the wlan function */
201 if (func->num != 0x02)
202 return -ENODEV;
203
204 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
205 if (!glue) {
206 dev_err(&func->dev, "can't allocate glue\n");
207 goto out;
208 }
209
210 glue->dev = &func->dev;
211
212 /* Grab access to FN0 for ELP reg. */
213 func->card->quirks |= MMC_QUIRK_LENIENT_FN0;
214
215 /* Use block mode for transferring over one block size of data */
216 func->card->quirks |= MMC_QUIRK_BLKSZ_FOR_BYTE_MODE;
217
218 wlan_data = wl12xx_get_platform_data();
219 if (IS_ERR(wlan_data)) {
220 ret = PTR_ERR(wlan_data);
221 dev_err(glue->dev, "missing wlan platform data: %d\n", ret);
222 goto out_free_glue;
223 }
224
225 /* if sdio can keep power while host is suspended, enable wow */
226 mmcflags = sdio_get_host_pm_caps(func);
227 dev_dbg(glue->dev, "sdio PM caps = 0x%x\n", mmcflags);
228
229 if (mmcflags & MMC_PM_KEEP_POWER)
230 wlan_data->pwr_in_suspend = true;
231
232 wlan_data->ops = &sdio_ops;
233
234 sdio_set_drvdata(func, glue);
235
236 /* Tell PM core that we don't need the card to be powered now */
237 pm_runtime_put_noidle(&func->dev);
238
239 glue->core = platform_device_alloc("wl12xx", -1);
240 if (!glue->core) {
241 dev_err(glue->dev, "can't allocate platform_device");
242 ret = -ENOMEM;
243 goto out_free_glue;
244 }
245
246 glue->core->dev.parent = &func->dev;
247
248 memset(res, 0x00, sizeof(res));
249
250 res[0].start = wlan_data->irq;
251 res[0].flags = IORESOURCE_IRQ;
252 res[0].name = "irq";
253
254 ret = platform_device_add_resources(glue->core, res, ARRAY_SIZE(res));
255 if (ret) {
256 dev_err(glue->dev, "can't add resources\n");
257 goto out_dev_put;
258 }
259
260 ret = platform_device_add_data(glue->core, wlan_data,
261 sizeof(*wlan_data));
262 if (ret) {
263 dev_err(glue->dev, "can't add platform data\n");
264 goto out_dev_put;
265 }
266
267 ret = platform_device_add(glue->core);
268 if (ret) {
269 dev_err(glue->dev, "can't add platform device\n");
270 goto out_dev_put;
271 }
272 return 0;
273
274out_dev_put:
275 platform_device_put(glue->core);
276
277out_free_glue:
278 kfree(glue);
279
280out:
281 return ret;
282}
283
284static void __devexit wl1271_remove(struct sdio_func *func)
285{
286 struct wl12xx_sdio_glue *glue = sdio_get_drvdata(func);
287
288 /* Undo decrement done above in wl1271_probe */
289 pm_runtime_get_noresume(&func->dev);
290
291 platform_device_del(glue->core);
292 platform_device_put(glue->core);
293 kfree(glue);
294}
295
296#ifdef CONFIG_PM
297static int wl1271_suspend(struct device *dev)
298{
299 /* Tell MMC/SDIO core it's OK to power down the card
300 * (if it isn't already), but not to remove it completely */
301 struct sdio_func *func = dev_to_sdio_func(dev);
302 struct wl12xx_sdio_glue *glue = sdio_get_drvdata(func);
303 struct wl1271 *wl = platform_get_drvdata(glue->core);
304 mmc_pm_flag_t sdio_flags;
305 int ret = 0;
306
307 dev_dbg(dev, "wl1271 suspend. wow_enabled: %d\n",
308 wl->wow_enabled);
309
310 /* check whether sdio should keep power */
311 if (wl->wow_enabled) {
312 sdio_flags = sdio_get_host_pm_caps(func);
313
314 if (!(sdio_flags & MMC_PM_KEEP_POWER)) {
315 dev_err(dev, "can't keep power while host "
316 "is suspended\n");
317 ret = -EINVAL;
318 goto out;
319 }
320
321 /* keep power while host suspended */
322 ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER);
323 if (ret) {
324 dev_err(dev, "error while trying to keep power\n");
325 goto out;
326 }
327 }
328out:
329 return ret;
330}
331
332static int wl1271_resume(struct device *dev)
333{
334 dev_dbg(dev, "wl1271 resume\n");
335
336 return 0;
337}
338
339static const struct dev_pm_ops wl1271_sdio_pm_ops = {
340 .suspend = wl1271_suspend,
341 .resume = wl1271_resume,
342};
343#endif
344
345static struct sdio_driver wl1271_sdio_driver = {
346 .name = "wl1271_sdio",
347 .id_table = wl1271_devices,
348 .probe = wl1271_probe,
349 .remove = __devexit_p(wl1271_remove),
350#ifdef CONFIG_PM
351 .drv = {
352 .pm = &wl1271_sdio_pm_ops,
353 },
354#endif
355};
356
357static int __init wl1271_init(void)
358{
359 return sdio_register_driver(&wl1271_sdio_driver);
360}
361
362static void __exit wl1271_exit(void)
363{
364 sdio_unregister_driver(&wl1271_sdio_driver);
365}
366
367module_init(wl1271_init);
368module_exit(wl1271_exit);
369
370MODULE_LICENSE("GPL");
371MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
372MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");
373MODULE_FIRMWARE(WL127X_FW_NAME_SINGLE);
374MODULE_FIRMWARE(WL127X_FW_NAME_MULTI);
375MODULE_FIRMWARE(WL127X_PLT_FW_NAME);
376MODULE_FIRMWARE(WL128X_FW_NAME_SINGLE);
377MODULE_FIRMWARE(WL128X_FW_NAME_MULTI);
378MODULE_FIRMWARE(WL128X_PLT_FW_NAME);
diff --git a/drivers/net/wireless/ti/wlcore/spi.c b/drivers/net/wireless/ti/wlcore/spi.c
new file mode 100644
index 000000000000..553cd3cbb98c
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/spi.c
@@ -0,0 +1,440 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2008-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/interrupt.h>
25#include <linux/irq.h>
26#include <linux/module.h>
27#include <linux/crc7.h>
28#include <linux/spi/spi.h>
29#include <linux/wl12xx.h>
30#include <linux/platform_device.h>
31#include <linux/slab.h>
32
33#include "wlcore.h"
34#include "wl12xx_80211.h"
35#include "io.h"
36
37#define WSPI_CMD_READ 0x40000000
38#define WSPI_CMD_WRITE 0x00000000
39#define WSPI_CMD_FIXED 0x20000000
40#define WSPI_CMD_BYTE_LENGTH 0x1FFE0000
41#define WSPI_CMD_BYTE_LENGTH_OFFSET 17
42#define WSPI_CMD_BYTE_ADDR 0x0001FFFF
43
44#define WSPI_INIT_CMD_CRC_LEN 5
45
46#define WSPI_INIT_CMD_START 0x00
47#define WSPI_INIT_CMD_TX 0x40
48/* the extra bypass bit is sampled by the TNET as '1' */
49#define WSPI_INIT_CMD_BYPASS_BIT 0x80
50#define WSPI_INIT_CMD_FIXEDBUSY_LEN 0x07
51#define WSPI_INIT_CMD_EN_FIXEDBUSY 0x80
52#define WSPI_INIT_CMD_DIS_FIXEDBUSY 0x00
53#define WSPI_INIT_CMD_IOD 0x40
54#define WSPI_INIT_CMD_IP 0x20
55#define WSPI_INIT_CMD_CS 0x10
56#define WSPI_INIT_CMD_WS 0x08
57#define WSPI_INIT_CMD_WSPI 0x01
58#define WSPI_INIT_CMD_END 0x01
59
60#define WSPI_INIT_CMD_LEN 8
61
62#define HW_ACCESS_WSPI_FIXED_BUSY_LEN \
63 ((WL1271_BUSY_WORD_LEN - 4) / sizeof(u32))
64#define HW_ACCESS_WSPI_INIT_CMD_MASK 0
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
71struct wl12xx_spi_glue {
72 struct device *dev;
73 struct platform_device *core;
74};
75
76static void wl12xx_spi_reset(struct device *child)
77{
78 struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
79 u8 *cmd;
80 struct spi_transfer t;
81 struct spi_message m;
82
83 cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL);
84 if (!cmd) {
85 dev_err(child->parent,
86 "could not allocate cmd for spi reset\n");
87 return;
88 }
89
90 memset(&t, 0, sizeof(t));
91 spi_message_init(&m);
92
93 memset(cmd, 0xff, WSPI_INIT_CMD_LEN);
94
95 t.tx_buf = cmd;
96 t.len = WSPI_INIT_CMD_LEN;
97 spi_message_add_tail(&t, &m);
98
99 spi_sync(to_spi_device(glue->dev), &m);
100
101 kfree(cmd);
102}
103
104static void wl12xx_spi_init(struct device *child)
105{
106 struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
107 u8 crc[WSPI_INIT_CMD_CRC_LEN], *cmd;
108 struct spi_transfer t;
109 struct spi_message m;
110
111 cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL);
112 if (!cmd) {
113 dev_err(child->parent,
114 "could not allocate cmd for spi init\n");
115 return;
116 }
117
118 memset(crc, 0, sizeof(crc));
119 memset(&t, 0, sizeof(t));
120 spi_message_init(&m);
121
122 /*
123 * Set WSPI_INIT_COMMAND
124 * the data is being send from the MSB to LSB
125 */
126 cmd[2] = 0xff;
127 cmd[3] = 0xff;
128 cmd[1] = WSPI_INIT_CMD_START | WSPI_INIT_CMD_TX;
129 cmd[0] = 0;
130 cmd[7] = 0;
131 cmd[6] |= HW_ACCESS_WSPI_INIT_CMD_MASK << 3;
132 cmd[6] |= HW_ACCESS_WSPI_FIXED_BUSY_LEN & WSPI_INIT_CMD_FIXEDBUSY_LEN;
133
134 if (HW_ACCESS_WSPI_FIXED_BUSY_LEN == 0)
135 cmd[5] |= WSPI_INIT_CMD_DIS_FIXEDBUSY;
136 else
137 cmd[5] |= WSPI_INIT_CMD_EN_FIXEDBUSY;
138
139 cmd[5] |= WSPI_INIT_CMD_IOD | WSPI_INIT_CMD_IP | WSPI_INIT_CMD_CS
140 | WSPI_INIT_CMD_WSPI | WSPI_INIT_CMD_WS;
141
142 crc[0] = cmd[1];
143 crc[1] = cmd[0];
144 crc[2] = cmd[7];
145 crc[3] = cmd[6];
146 crc[4] = cmd[5];
147
148 cmd[4] |= crc7(0, crc, WSPI_INIT_CMD_CRC_LEN) << 1;
149 cmd[4] |= WSPI_INIT_CMD_END;
150
151 t.tx_buf = cmd;
152 t.len = WSPI_INIT_CMD_LEN;
153 spi_message_add_tail(&t, &m);
154
155 spi_sync(to_spi_device(glue->dev), &m);
156 kfree(cmd);
157}
158
159#define WL1271_BUSY_WORD_TIMEOUT 1000
160
161static int wl12xx_spi_read_busy(struct device *child)
162{
163 struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
164 struct wl1271 *wl = dev_get_drvdata(child);
165 struct spi_transfer t[1];
166 struct spi_message m;
167 u32 *busy_buf;
168 int num_busy_bytes = 0;
169
170 /*
171 * Read further busy words from SPI until a non-busy word is
172 * encountered, then read the data itself into the buffer.
173 */
174
175 num_busy_bytes = WL1271_BUSY_WORD_TIMEOUT;
176 busy_buf = wl->buffer_busyword;
177 while (num_busy_bytes) {
178 num_busy_bytes--;
179 spi_message_init(&m);
180 memset(t, 0, sizeof(t));
181 t[0].rx_buf = busy_buf;
182 t[0].len = sizeof(u32);
183 t[0].cs_change = true;
184 spi_message_add_tail(&t[0], &m);
185 spi_sync(to_spi_device(glue->dev), &m);
186
187 if (*busy_buf & 0x1)
188 return 0;
189 }
190
191 /* The SPI bus is unresponsive, the read failed. */
192 dev_err(child->parent, "SPI read busy-word timeout!\n");
193 return -ETIMEDOUT;
194}
195
196static void wl12xx_spi_raw_read(struct device *child, int addr, void *buf,
197 size_t len, bool fixed)
198{
199 struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
200 struct wl1271 *wl = dev_get_drvdata(child);
201 struct spi_transfer t[2];
202 struct spi_message m;
203 u32 *busy_buf;
204 u32 *cmd;
205 u32 chunk_len;
206
207 while (len > 0) {
208 chunk_len = min((size_t)WSPI_MAX_CHUNK_SIZE, len);
209
210 cmd = &wl->buffer_cmd;
211 busy_buf = wl->buffer_busyword;
212
213 *cmd = 0;
214 *cmd |= WSPI_CMD_READ;
215 *cmd |= (chunk_len << WSPI_CMD_BYTE_LENGTH_OFFSET) &
216 WSPI_CMD_BYTE_LENGTH;
217 *cmd |= addr & WSPI_CMD_BYTE_ADDR;
218
219 if (fixed)
220 *cmd |= WSPI_CMD_FIXED;
221
222 spi_message_init(&m);
223 memset(t, 0, sizeof(t));
224
225 t[0].tx_buf = cmd;
226 t[0].len = 4;
227 t[0].cs_change = true;
228 spi_message_add_tail(&t[0], &m);
229
230 /* Busy and non busy words read */
231 t[1].rx_buf = busy_buf;
232 t[1].len = WL1271_BUSY_WORD_LEN;
233 t[1].cs_change = true;
234 spi_message_add_tail(&t[1], &m);
235
236 spi_sync(to_spi_device(glue->dev), &m);
237
238 if (!(busy_buf[WL1271_BUSY_WORD_CNT - 1] & 0x1) &&
239 wl12xx_spi_read_busy(child)) {
240 memset(buf, 0, chunk_len);
241 return;
242 }
243
244 spi_message_init(&m);
245 memset(t, 0, sizeof(t));
246
247 t[0].rx_buf = buf;
248 t[0].len = chunk_len;
249 t[0].cs_change = true;
250 spi_message_add_tail(&t[0], &m);
251
252 spi_sync(to_spi_device(glue->dev), &m);
253
254 if (!fixed)
255 addr += chunk_len;
256 buf += chunk_len;
257 len -= chunk_len;
258 }
259}
260
261static void wl12xx_spi_raw_write(struct device *child, int addr, void *buf,
262 size_t len, bool fixed)
263{
264 struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
265 struct spi_transfer t[2 * WSPI_MAX_NUM_OF_CHUNKS];
266 struct spi_message m;
267 u32 commands[WSPI_MAX_NUM_OF_CHUNKS];
268 u32 *cmd;
269 u32 chunk_len;
270 int i;
271
272 WARN_ON(len > WL1271_AGGR_BUFFER_SIZE);
273
274 spi_message_init(&m);
275 memset(t, 0, sizeof(t));
276
277 cmd = &commands[0];
278 i = 0;
279 while (len > 0) {
280 chunk_len = min((size_t)WSPI_MAX_CHUNK_SIZE, len);
281
282 *cmd = 0;
283 *cmd |= WSPI_CMD_WRITE;
284 *cmd |= (chunk_len << WSPI_CMD_BYTE_LENGTH_OFFSET) &
285 WSPI_CMD_BYTE_LENGTH;
286 *cmd |= addr & WSPI_CMD_BYTE_ADDR;
287
288 if (fixed)
289 *cmd |= WSPI_CMD_FIXED;
290
291 t[i].tx_buf = cmd;
292 t[i].len = sizeof(*cmd);
293 spi_message_add_tail(&t[i++], &m);
294
295 t[i].tx_buf = buf;
296 t[i].len = chunk_len;
297 spi_message_add_tail(&t[i++], &m);
298
299 if (!fixed)
300 addr += chunk_len;
301 buf += chunk_len;
302 len -= chunk_len;
303 cmd++;
304 }
305
306 spi_sync(to_spi_device(glue->dev), &m);
307}
308
309static struct wl1271_if_operations spi_ops = {
310 .read = wl12xx_spi_raw_read,
311 .write = wl12xx_spi_raw_write,
312 .reset = wl12xx_spi_reset,
313 .init = wl12xx_spi_init,
314 .set_block_size = NULL,
315};
316
317static int __devinit wl1271_probe(struct spi_device *spi)
318{
319 struct wl12xx_spi_glue *glue;
320 struct wl12xx_platform_data *pdata;
321 struct resource res[1];
322 int ret = -ENOMEM;
323
324 pdata = spi->dev.platform_data;
325 if (!pdata) {
326 dev_err(&spi->dev, "no platform data\n");
327 return -ENODEV;
328 }
329
330 pdata->ops = &spi_ops;
331
332 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
333 if (!glue) {
334 dev_err(&spi->dev, "can't allocate glue\n");
335 goto out;
336 }
337
338 glue->dev = &spi->dev;
339
340 spi_set_drvdata(spi, glue);
341
342 /* This is the only SPI value that we need to set here, the rest
343 * comes from the board-peripherals file */
344 spi->bits_per_word = 32;
345
346 ret = spi_setup(spi);
347 if (ret < 0) {
348 dev_err(glue->dev, "spi_setup failed\n");
349 goto out_free_glue;
350 }
351
352 glue->core = platform_device_alloc("wl12xx", -1);
353 if (!glue->core) {
354 dev_err(glue->dev, "can't allocate platform_device\n");
355 ret = -ENOMEM;
356 goto out_free_glue;
357 }
358
359 glue->core->dev.parent = &spi->dev;
360
361 memset(res, 0x00, sizeof(res));
362
363 res[0].start = spi->irq;
364 res[0].flags = IORESOURCE_IRQ;
365 res[0].name = "irq";
366
367 ret = platform_device_add_resources(glue->core, res, ARRAY_SIZE(res));
368 if (ret) {
369 dev_err(glue->dev, "can't add resources\n");
370 goto out_dev_put;
371 }
372
373 ret = platform_device_add_data(glue->core, pdata, sizeof(*pdata));
374 if (ret) {
375 dev_err(glue->dev, "can't add platform data\n");
376 goto out_dev_put;
377 }
378
379 ret = platform_device_add(glue->core);
380 if (ret) {
381 dev_err(glue->dev, "can't register platform device\n");
382 goto out_dev_put;
383 }
384
385 return 0;
386
387out_dev_put:
388 platform_device_put(glue->core);
389
390out_free_glue:
391 kfree(glue);
392out:
393 return ret;
394}
395
396static int __devexit wl1271_remove(struct spi_device *spi)
397{
398 struct wl12xx_spi_glue *glue = spi_get_drvdata(spi);
399
400 platform_device_del(glue->core);
401 platform_device_put(glue->core);
402 kfree(glue);
403
404 return 0;
405}
406
407
408static struct spi_driver wl1271_spi_driver = {
409 .driver = {
410 .name = "wl1271_spi",
411 .owner = THIS_MODULE,
412 },
413
414 .probe = wl1271_probe,
415 .remove = __devexit_p(wl1271_remove),
416};
417
418static int __init wl1271_init(void)
419{
420 return spi_register_driver(&wl1271_spi_driver);
421}
422
423static void __exit wl1271_exit(void)
424{
425 spi_unregister_driver(&wl1271_spi_driver);
426}
427
428module_init(wl1271_init);
429module_exit(wl1271_exit);
430
431MODULE_LICENSE("GPL");
432MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
433MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");
434MODULE_FIRMWARE(WL127X_FW_NAME_SINGLE);
435MODULE_FIRMWARE(WL127X_FW_NAME_MULTI);
436MODULE_FIRMWARE(WL127X_PLT_FW_NAME);
437MODULE_FIRMWARE(WL128X_FW_NAME_SINGLE);
438MODULE_FIRMWARE(WL128X_FW_NAME_MULTI);
439MODULE_FIRMWARE(WL128X_PLT_FW_NAME);
440MODULE_ALIAS("spi:wl1271");
diff --git a/drivers/net/wireless/ti/wlcore/testmode.c b/drivers/net/wireless/ti/wlcore/testmode.c
new file mode 100644
index 000000000000..9cda706e4e3f
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/testmode.c
@@ -0,0 +1,343 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 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#include "testmode.h"
24
25#include <linux/slab.h>
26#include <net/genetlink.h>
27
28#include "wlcore.h"
29#include "debug.h"
30#include "acx.h"
31#include "ps.h"
32#include "io.h"
33
34#define WL1271_TM_MAX_DATA_LENGTH 1024
35
36enum wl1271_tm_commands {
37 WL1271_TM_CMD_UNSPEC,
38 WL1271_TM_CMD_TEST,
39 WL1271_TM_CMD_INTERROGATE,
40 WL1271_TM_CMD_CONFIGURE,
41 WL1271_TM_CMD_NVS_PUSH, /* Not in use. Keep to not break ABI */
42 WL1271_TM_CMD_SET_PLT_MODE,
43 WL1271_TM_CMD_RECOVER,
44 WL1271_TM_CMD_GET_MAC,
45
46 __WL1271_TM_CMD_AFTER_LAST
47};
48#define WL1271_TM_CMD_MAX (__WL1271_TM_CMD_AFTER_LAST - 1)
49
50enum wl1271_tm_attrs {
51 WL1271_TM_ATTR_UNSPEC,
52 WL1271_TM_ATTR_CMD_ID,
53 WL1271_TM_ATTR_ANSWER,
54 WL1271_TM_ATTR_DATA,
55 WL1271_TM_ATTR_IE_ID,
56 WL1271_TM_ATTR_PLT_MODE,
57
58 __WL1271_TM_ATTR_AFTER_LAST
59};
60#define WL1271_TM_ATTR_MAX (__WL1271_TM_ATTR_AFTER_LAST - 1)
61
62static struct nla_policy wl1271_tm_policy[WL1271_TM_ATTR_MAX + 1] = {
63 [WL1271_TM_ATTR_CMD_ID] = { .type = NLA_U32 },
64 [WL1271_TM_ATTR_ANSWER] = { .type = NLA_U8 },
65 [WL1271_TM_ATTR_DATA] = { .type = NLA_BINARY,
66 .len = WL1271_TM_MAX_DATA_LENGTH },
67 [WL1271_TM_ATTR_IE_ID] = { .type = NLA_U32 },
68 [WL1271_TM_ATTR_PLT_MODE] = { .type = NLA_U32 },
69};
70
71
72static int wl1271_tm_cmd_test(struct wl1271 *wl, struct nlattr *tb[])
73{
74 int buf_len, ret, len;
75 struct sk_buff *skb;
76 void *buf;
77 u8 answer = 0;
78
79 wl1271_debug(DEBUG_TESTMODE, "testmode cmd test");
80
81 if (!tb[WL1271_TM_ATTR_DATA])
82 return -EINVAL;
83
84 buf = nla_data(tb[WL1271_TM_ATTR_DATA]);
85 buf_len = nla_len(tb[WL1271_TM_ATTR_DATA]);
86
87 if (tb[WL1271_TM_ATTR_ANSWER])
88 answer = nla_get_u8(tb[WL1271_TM_ATTR_ANSWER]);
89
90 if (buf_len > sizeof(struct wl1271_command))
91 return -EMSGSIZE;
92
93 mutex_lock(&wl->mutex);
94
95 if (wl->state == WL1271_STATE_OFF) {
96 ret = -EINVAL;
97 goto out;
98 }
99
100 ret = wl1271_ps_elp_wakeup(wl);
101 if (ret < 0)
102 goto out;
103
104 ret = wl1271_cmd_test(wl, buf, buf_len, answer);
105 if (ret < 0) {
106 wl1271_warning("testmode cmd test failed: %d", ret);
107 goto out_sleep;
108 }
109
110 if (answer) {
111 len = nla_total_size(buf_len);
112 skb = cfg80211_testmode_alloc_reply_skb(wl->hw->wiphy, len);
113 if (!skb) {
114 ret = -ENOMEM;
115 goto out_sleep;
116 }
117
118 NLA_PUT(skb, WL1271_TM_ATTR_DATA, buf_len, buf);
119 ret = cfg80211_testmode_reply(skb);
120 if (ret < 0)
121 goto out_sleep;
122 }
123
124out_sleep:
125 wl1271_ps_elp_sleep(wl);
126out:
127 mutex_unlock(&wl->mutex);
128
129 return ret;
130
131nla_put_failure:
132 kfree_skb(skb);
133 ret = -EMSGSIZE;
134 goto out_sleep;
135}
136
137static int wl1271_tm_cmd_interrogate(struct wl1271 *wl, struct nlattr *tb[])
138{
139 int ret;
140 struct wl1271_command *cmd;
141 struct sk_buff *skb;
142 u8 ie_id;
143
144 wl1271_debug(DEBUG_TESTMODE, "testmode cmd interrogate");
145
146 if (!tb[WL1271_TM_ATTR_IE_ID])
147 return -EINVAL;
148
149 ie_id = nla_get_u8(tb[WL1271_TM_ATTR_IE_ID]);
150
151 mutex_lock(&wl->mutex);
152
153 if (wl->state == WL1271_STATE_OFF) {
154 ret = -EINVAL;
155 goto out;
156 }
157
158 ret = wl1271_ps_elp_wakeup(wl);
159 if (ret < 0)
160 goto out;
161
162 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
163 if (!cmd) {
164 ret = -ENOMEM;
165 goto out_sleep;
166 }
167
168 ret = wl1271_cmd_interrogate(wl, ie_id, cmd, sizeof(*cmd));
169 if (ret < 0) {
170 wl1271_warning("testmode cmd interrogate failed: %d", ret);
171 goto out_free;
172 }
173
174 skb = cfg80211_testmode_alloc_reply_skb(wl->hw->wiphy, sizeof(*cmd));
175 if (!skb) {
176 ret = -ENOMEM;
177 goto out_free;
178 }
179
180 NLA_PUT(skb, WL1271_TM_ATTR_DATA, sizeof(*cmd), cmd);
181 ret = cfg80211_testmode_reply(skb);
182 if (ret < 0)
183 goto out_free;
184
185out_free:
186 kfree(cmd);
187out_sleep:
188 wl1271_ps_elp_sleep(wl);
189out:
190 mutex_unlock(&wl->mutex);
191
192 return ret;
193
194nla_put_failure:
195 kfree_skb(skb);
196 ret = -EMSGSIZE;
197 goto out_free;
198}
199
200static int wl1271_tm_cmd_configure(struct wl1271 *wl, struct nlattr *tb[])
201{
202 int buf_len, ret;
203 void *buf;
204 u8 ie_id;
205
206 wl1271_debug(DEBUG_TESTMODE, "testmode cmd configure");
207
208 if (!tb[WL1271_TM_ATTR_DATA])
209 return -EINVAL;
210 if (!tb[WL1271_TM_ATTR_IE_ID])
211 return -EINVAL;
212
213 ie_id = nla_get_u8(tb[WL1271_TM_ATTR_IE_ID]);
214 buf = nla_data(tb[WL1271_TM_ATTR_DATA]);
215 buf_len = nla_len(tb[WL1271_TM_ATTR_DATA]);
216
217 if (buf_len > sizeof(struct wl1271_command))
218 return -EMSGSIZE;
219
220 mutex_lock(&wl->mutex);
221 ret = wl1271_cmd_configure(wl, ie_id, buf, buf_len);
222 mutex_unlock(&wl->mutex);
223
224 if (ret < 0) {
225 wl1271_warning("testmode cmd configure failed: %d", ret);
226 return ret;
227 }
228
229 return 0;
230}
231
232static int wl1271_tm_cmd_set_plt_mode(struct wl1271 *wl, struct nlattr *tb[])
233{
234 u32 val;
235 int ret;
236
237 wl1271_debug(DEBUG_TESTMODE, "testmode cmd set plt mode");
238
239 if (!tb[WL1271_TM_ATTR_PLT_MODE])
240 return -EINVAL;
241
242 val = nla_get_u32(tb[WL1271_TM_ATTR_PLT_MODE]);
243
244 switch (val) {
245 case 0:
246 ret = wl1271_plt_stop(wl);
247 break;
248 case 1:
249 ret = wl1271_plt_start(wl);
250 break;
251 default:
252 ret = -EINVAL;
253 break;
254 }
255
256 return ret;
257}
258
259static int wl1271_tm_cmd_recover(struct wl1271 *wl, struct nlattr *tb[])
260{
261 wl1271_debug(DEBUG_TESTMODE, "testmode cmd recover");
262
263 wl12xx_queue_recovery_work(wl);
264
265 return 0;
266}
267
268static int wl12xx_tm_cmd_get_mac(struct wl1271 *wl, struct nlattr *tb[])
269{
270 struct sk_buff *skb;
271 u8 mac_addr[ETH_ALEN];
272 int ret = 0;
273
274 mutex_lock(&wl->mutex);
275
276 if (!wl->plt) {
277 ret = -EINVAL;
278 goto out;
279 }
280
281 if (wl->fuse_oui_addr == 0 && wl->fuse_nic_addr == 0) {
282 ret = -EOPNOTSUPP;
283 goto out;
284 }
285
286 mac_addr[0] = (u8)(wl->fuse_oui_addr >> 16);
287 mac_addr[1] = (u8)(wl->fuse_oui_addr >> 8);
288 mac_addr[2] = (u8) wl->fuse_oui_addr;
289 mac_addr[3] = (u8)(wl->fuse_nic_addr >> 16);
290 mac_addr[4] = (u8)(wl->fuse_nic_addr >> 8);
291 mac_addr[5] = (u8) wl->fuse_nic_addr;
292
293 skb = cfg80211_testmode_alloc_reply_skb(wl->hw->wiphy, ETH_ALEN);
294 if (!skb) {
295 ret = -ENOMEM;
296 goto out;
297 }
298
299 NLA_PUT(skb, WL1271_TM_ATTR_DATA, ETH_ALEN, mac_addr);
300 ret = cfg80211_testmode_reply(skb);
301 if (ret < 0)
302 goto out;
303
304out:
305 mutex_unlock(&wl->mutex);
306 return ret;
307
308nla_put_failure:
309 kfree_skb(skb);
310 ret = -EMSGSIZE;
311 goto out;
312}
313
314int wl1271_tm_cmd(struct ieee80211_hw *hw, void *data, int len)
315{
316 struct wl1271 *wl = hw->priv;
317 struct nlattr *tb[WL1271_TM_ATTR_MAX + 1];
318 int err;
319
320 err = nla_parse(tb, WL1271_TM_ATTR_MAX, data, len, wl1271_tm_policy);
321 if (err)
322 return err;
323
324 if (!tb[WL1271_TM_ATTR_CMD_ID])
325 return -EINVAL;
326
327 switch (nla_get_u32(tb[WL1271_TM_ATTR_CMD_ID])) {
328 case WL1271_TM_CMD_TEST:
329 return wl1271_tm_cmd_test(wl, tb);
330 case WL1271_TM_CMD_INTERROGATE:
331 return wl1271_tm_cmd_interrogate(wl, tb);
332 case WL1271_TM_CMD_CONFIGURE:
333 return wl1271_tm_cmd_configure(wl, tb);
334 case WL1271_TM_CMD_SET_PLT_MODE:
335 return wl1271_tm_cmd_set_plt_mode(wl, tb);
336 case WL1271_TM_CMD_RECOVER:
337 return wl1271_tm_cmd_recover(wl, tb);
338 case WL1271_TM_CMD_GET_MAC:
339 return wl12xx_tm_cmd_get_mac(wl, tb);
340 default:
341 return -EOPNOTSUPP;
342 }
343}
diff --git a/drivers/net/wireless/ti/wlcore/testmode.h b/drivers/net/wireless/ti/wlcore/testmode.h
new file mode 100644
index 000000000000..8071654259ea
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/testmode.h
@@ -0,0 +1,31 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 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#ifndef __TESTMODE_H__
25#define __TESTMODE_H__
26
27#include <net/mac80211.h>
28
29int wl1271_tm_cmd(struct ieee80211_hw *hw, void *data, int len);
30
31#endif /* __WL1271_TESTMODE_H__ */
diff --git a/drivers/net/wireless/ti/wlcore/tx.c b/drivers/net/wireless/ti/wlcore/tx.c
new file mode 100644
index 000000000000..6893bc207994
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/tx.c
@@ -0,0 +1,1056 @@
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 "wlcore.h"
29#include "debug.h"
30#include "io.h"
31#include "ps.h"
32#include "tx.h"
33#include "event.h"
34#include "hw_ops.h"
35
36/*
37 * TODO: this is here just for now, it must be removed when the data
38 * operations are in place.
39 */
40#include "../wl12xx/reg.h"
41
42static int wl1271_set_default_wep_key(struct wl1271 *wl,
43 struct wl12xx_vif *wlvif, u8 id)
44{
45 int ret;
46 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
47
48 if (is_ap)
49 ret = wl12xx_cmd_set_default_wep_key(wl, id,
50 wlvif->ap.bcast_hlid);
51 else
52 ret = wl12xx_cmd_set_default_wep_key(wl, id, wlvif->sta.hlid);
53
54 if (ret < 0)
55 return ret;
56
57 wl1271_debug(DEBUG_CRYPT, "default wep key idx: %d", (int)id);
58 return 0;
59}
60
61static int wl1271_alloc_tx_id(struct wl1271 *wl, struct sk_buff *skb)
62{
63 int id;
64
65 id = find_first_zero_bit(wl->tx_frames_map, wl->num_tx_desc);
66 if (id >= wl->num_tx_desc)
67 return -EBUSY;
68
69 __set_bit(id, wl->tx_frames_map);
70 wl->tx_frames[id] = skb;
71 wl->tx_frames_cnt++;
72 return id;
73}
74
75static void wl1271_free_tx_id(struct wl1271 *wl, int id)
76{
77 if (__test_and_clear_bit(id, wl->tx_frames_map)) {
78 if (unlikely(wl->tx_frames_cnt == wl->num_tx_desc))
79 clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
80
81 wl->tx_frames[id] = NULL;
82 wl->tx_frames_cnt--;
83 }
84}
85
86static void wl1271_tx_ap_update_inconnection_sta(struct wl1271 *wl,
87 struct sk_buff *skb)
88{
89 struct ieee80211_hdr *hdr;
90
91 /*
92 * add the station to the known list before transmitting the
93 * authentication response. this way it won't get de-authed by FW
94 * when transmitting too soon.
95 */
96 hdr = (struct ieee80211_hdr *)(skb->data +
97 sizeof(struct wl1271_tx_hw_descr));
98 if (ieee80211_is_auth(hdr->frame_control))
99 wl1271_acx_set_inconnection_sta(wl, hdr->addr1);
100}
101
102static void wl1271_tx_regulate_link(struct wl1271 *wl,
103 struct wl12xx_vif *wlvif,
104 u8 hlid)
105{
106 bool fw_ps, single_sta;
107 u8 tx_pkts;
108
109 if (WARN_ON(!test_bit(hlid, wlvif->links_map)))
110 return;
111
112 fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
113 tx_pkts = wl->links[hlid].allocated_pkts;
114 single_sta = (wl->active_sta_count == 1);
115
116 /*
117 * if in FW PS and there is enough data in FW we can put the link
118 * into high-level PS and clean out its TX queues.
119 * Make an exception if this is the only connected station. In this
120 * case FW-memory congestion is not a problem.
121 */
122 if (!single_sta && fw_ps && tx_pkts >= WL1271_PS_STA_MAX_PACKETS)
123 wl12xx_ps_link_start(wl, wlvif, hlid, true);
124}
125
126bool wl12xx_is_dummy_packet(struct wl1271 *wl, struct sk_buff *skb)
127{
128 return wl->dummy_packet == skb;
129}
130
131u8 wl12xx_tx_get_hlid_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif,
132 struct sk_buff *skb)
133{
134 struct ieee80211_tx_info *control = IEEE80211_SKB_CB(skb);
135
136 if (control->control.sta) {
137 struct wl1271_station *wl_sta;
138
139 wl_sta = (struct wl1271_station *)
140 control->control.sta->drv_priv;
141 return wl_sta->hlid;
142 } else {
143 struct ieee80211_hdr *hdr;
144
145 if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
146 return wl->system_hlid;
147
148 hdr = (struct ieee80211_hdr *)skb->data;
149 if (ieee80211_is_mgmt(hdr->frame_control))
150 return wlvif->ap.global_hlid;
151 else
152 return wlvif->ap.bcast_hlid;
153 }
154}
155
156u8 wl12xx_tx_get_hlid(struct wl1271 *wl, struct wl12xx_vif *wlvif,
157 struct sk_buff *skb)
158{
159 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
160
161 if (!wlvif || wl12xx_is_dummy_packet(wl, skb))
162 return wl->system_hlid;
163
164 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
165 return wl12xx_tx_get_hlid_ap(wl, wlvif, skb);
166
167 if ((test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) ||
168 test_bit(WLVIF_FLAG_IBSS_JOINED, &wlvif->flags)) &&
169 !ieee80211_is_auth(hdr->frame_control) &&
170 !ieee80211_is_assoc_req(hdr->frame_control))
171 return wlvif->sta.hlid;
172 else
173 return wlvif->dev_hlid;
174}
175
176unsigned int wlcore_calc_packet_alignment(struct wl1271 *wl,
177 unsigned int packet_length)
178{
179 if (wl->quirks & WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN)
180 return ALIGN(packet_length, WL12XX_BUS_BLOCK_SIZE);
181 else
182 return ALIGN(packet_length, WL1271_TX_ALIGN_TO);
183}
184EXPORT_SYMBOL(wlcore_calc_packet_alignment);
185
186static int wl1271_tx_allocate(struct wl1271 *wl, struct wl12xx_vif *wlvif,
187 struct sk_buff *skb, u32 extra, u32 buf_offset,
188 u8 hlid)
189{
190 struct wl1271_tx_hw_descr *desc;
191 u32 total_len = skb->len + sizeof(struct wl1271_tx_hw_descr) + extra;
192 u32 total_blocks;
193 int id, ret = -EBUSY, ac;
194 u32 spare_blocks = wl->normal_tx_spare;
195 bool is_dummy = false;
196
197 if (buf_offset + total_len > WL1271_AGGR_BUFFER_SIZE)
198 return -EAGAIN;
199
200 /* allocate free identifier for the packet */
201 id = wl1271_alloc_tx_id(wl, skb);
202 if (id < 0)
203 return id;
204
205 if (unlikely(wl12xx_is_dummy_packet(wl, skb)))
206 is_dummy = true;
207 else if (wlvif->is_gem)
208 spare_blocks = wl->gem_tx_spare;
209
210 total_blocks = wlcore_hw_calc_tx_blocks(wl, total_len, spare_blocks);
211
212 if (total_blocks <= wl->tx_blocks_available) {
213 desc = (struct wl1271_tx_hw_descr *)skb_push(
214 skb, total_len - skb->len);
215
216 wlcore_hw_set_tx_desc_blocks(wl, desc, total_blocks,
217 spare_blocks);
218
219 desc->id = id;
220
221 wl->tx_blocks_available -= total_blocks;
222 wl->tx_allocated_blocks += total_blocks;
223
224 /* If the FW was empty before, arm the Tx watchdog */
225 if (wl->tx_allocated_blocks == total_blocks)
226 wl12xx_rearm_tx_watchdog_locked(wl);
227
228 ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
229 wl->tx_allocated_pkts[ac]++;
230
231 if (!is_dummy && wlvif &&
232 wlvif->bss_type == BSS_TYPE_AP_BSS &&
233 test_bit(hlid, wlvif->ap.sta_hlid_map))
234 wl->links[hlid].allocated_pkts++;
235
236 ret = 0;
237
238 wl1271_debug(DEBUG_TX,
239 "tx_allocate: size: %d, blocks: %d, id: %d",
240 total_len, total_blocks, id);
241 } else {
242 wl1271_free_tx_id(wl, id);
243 }
244
245 return ret;
246}
247
248static void wl1271_tx_fill_hdr(struct wl1271 *wl, struct wl12xx_vif *wlvif,
249 struct sk_buff *skb, u32 extra,
250 struct ieee80211_tx_info *control, u8 hlid)
251{
252 struct timespec ts;
253 struct wl1271_tx_hw_descr *desc;
254 int ac, rate_idx;
255 s64 hosttime;
256 u16 tx_attr = 0;
257 __le16 frame_control;
258 struct ieee80211_hdr *hdr;
259 u8 *frame_start;
260 bool is_dummy;
261
262 desc = (struct wl1271_tx_hw_descr *) skb->data;
263 frame_start = (u8 *)(desc + 1);
264 hdr = (struct ieee80211_hdr *)(frame_start + extra);
265 frame_control = hdr->frame_control;
266
267 /* relocate space for security header */
268 if (extra) {
269 int hdrlen = ieee80211_hdrlen(frame_control);
270 memmove(frame_start, hdr, hdrlen);
271 }
272
273 /* configure packet life time */
274 getnstimeofday(&ts);
275 hosttime = (timespec_to_ns(&ts) >> 10);
276 desc->start_time = cpu_to_le32(hosttime - wl->time_offset);
277
278 is_dummy = wl12xx_is_dummy_packet(wl, skb);
279 if (is_dummy || !wlvif || wlvif->bss_type != BSS_TYPE_AP_BSS)
280 desc->life_time = cpu_to_le16(TX_HW_MGMT_PKT_LIFETIME_TU);
281 else
282 desc->life_time = cpu_to_le16(TX_HW_AP_MODE_PKT_LIFETIME_TU);
283
284 /* queue */
285 ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
286 desc->tid = skb->priority;
287
288 if (is_dummy) {
289 /*
290 * FW expects the dummy packet to have an invalid session id -
291 * any session id that is different than the one set in the join
292 */
293 tx_attr = (SESSION_COUNTER_INVALID <<
294 TX_HW_ATTR_OFST_SESSION_COUNTER) &
295 TX_HW_ATTR_SESSION_COUNTER;
296
297 tx_attr |= TX_HW_ATTR_TX_DUMMY_REQ;
298 } else if (wlvif) {
299 /* configure the tx attributes */
300 tx_attr = wlvif->session_counter <<
301 TX_HW_ATTR_OFST_SESSION_COUNTER;
302 }
303
304 desc->hlid = hlid;
305 if (is_dummy || !wlvif)
306 rate_idx = 0;
307 else if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
308 /* if the packets are destined for AP (have a STA entry)
309 send them with AP rate policies, otherwise use default
310 basic rates */
311 if (control->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
312 rate_idx = wlvif->sta.p2p_rate_idx;
313 else if (control->control.sta)
314 rate_idx = wlvif->sta.ap_rate_idx;
315 else
316 rate_idx = wlvif->sta.basic_rate_idx;
317 } else {
318 if (hlid == wlvif->ap.global_hlid)
319 rate_idx = wlvif->ap.mgmt_rate_idx;
320 else if (hlid == wlvif->ap.bcast_hlid)
321 rate_idx = wlvif->ap.bcast_rate_idx;
322 else
323 rate_idx = wlvif->ap.ucast_rate_idx[ac];
324 }
325
326 tx_attr |= rate_idx << TX_HW_ATTR_OFST_RATE_POLICY;
327
328 /* for WEP shared auth - no fw encryption is needed */
329 if (ieee80211_is_auth(frame_control) &&
330 ieee80211_has_protected(frame_control))
331 tx_attr |= TX_HW_ATTR_HOST_ENCRYPT;
332
333 desc->reserved = 0;
334 desc->tx_attr = cpu_to_le16(tx_attr);
335
336 wlcore_hw_set_tx_desc_data_len(wl, desc, skb);
337}
338
339/* caller must hold wl->mutex */
340static int wl1271_prepare_tx_frame(struct wl1271 *wl, struct wl12xx_vif *wlvif,
341 struct sk_buff *skb, u32 buf_offset)
342{
343 struct ieee80211_tx_info *info;
344 u32 extra = 0;
345 int ret = 0;
346 u32 total_len;
347 u8 hlid;
348 bool is_dummy;
349
350 if (!skb)
351 return -EINVAL;
352
353 info = IEEE80211_SKB_CB(skb);
354
355 /* TODO: handle dummy packets on multi-vifs */
356 is_dummy = wl12xx_is_dummy_packet(wl, skb);
357
358 if (info->control.hw_key &&
359 info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP)
360 extra = WL1271_EXTRA_SPACE_TKIP;
361
362 if (info->control.hw_key) {
363 bool is_wep;
364 u8 idx = info->control.hw_key->hw_key_idx;
365 u32 cipher = info->control.hw_key->cipher;
366
367 is_wep = (cipher == WLAN_CIPHER_SUITE_WEP40) ||
368 (cipher == WLAN_CIPHER_SUITE_WEP104);
369
370 if (unlikely(is_wep && wlvif->default_key != idx)) {
371 ret = wl1271_set_default_wep_key(wl, wlvif, idx);
372 if (ret < 0)
373 return ret;
374 wlvif->default_key = idx;
375 }
376 }
377 hlid = wl12xx_tx_get_hlid(wl, wlvif, skb);
378 if (hlid == WL12XX_INVALID_LINK_ID) {
379 wl1271_error("invalid hlid. dropping skb 0x%p", skb);
380 return -EINVAL;
381 }
382
383 ret = wl1271_tx_allocate(wl, wlvif, skb, extra, buf_offset, hlid);
384 if (ret < 0)
385 return ret;
386
387 wl1271_tx_fill_hdr(wl, wlvif, skb, extra, info, hlid);
388
389 if (!is_dummy && wlvif && wlvif->bss_type == BSS_TYPE_AP_BSS) {
390 wl1271_tx_ap_update_inconnection_sta(wl, skb);
391 wl1271_tx_regulate_link(wl, wlvif, hlid);
392 }
393
394 /*
395 * The length of each packet is stored in terms of
396 * words. Thus, we must pad the skb data to make sure its
397 * length is aligned. The number of padding bytes is computed
398 * and set in wl1271_tx_fill_hdr.
399 * In special cases, we want to align to a specific block size
400 * (eg. for wl128x with SDIO we align to 256).
401 */
402 total_len = wlcore_calc_packet_alignment(wl, skb->len);
403
404 memcpy(wl->aggr_buf + buf_offset, skb->data, skb->len);
405 memset(wl->aggr_buf + buf_offset + skb->len, 0, total_len - skb->len);
406
407 /* Revert side effects in the dummy packet skb, so it can be reused */
408 if (is_dummy)
409 skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
410
411 return total_len;
412}
413
414u32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set,
415 enum ieee80211_band rate_band)
416{
417 struct ieee80211_supported_band *band;
418 u32 enabled_rates = 0;
419 int bit;
420
421 band = wl->hw->wiphy->bands[rate_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 /* MCS rates indication are on bits 16 - 23 */
429 rate_set >>= HW_HT_RATES_OFFSET - band->n_bitrates;
430
431 for (bit = 0; bit < 8; bit++) {
432 if (rate_set & 0x1)
433 enabled_rates |= (CONF_HW_BIT_RATE_MCS_0 << bit);
434 rate_set >>= 1;
435 }
436
437 return enabled_rates;
438}
439
440void wl1271_handle_tx_low_watermark(struct wl1271 *wl)
441{
442 unsigned long flags;
443 int i;
444
445 for (i = 0; i < NUM_TX_QUEUES; i++) {
446 if (test_bit(i, &wl->stopped_queues_map) &&
447 wl->tx_queue_count[i] <= WL1271_TX_QUEUE_LOW_WATERMARK) {
448 /* firmware buffer has space, restart queues */
449 spin_lock_irqsave(&wl->wl_lock, flags);
450 ieee80211_wake_queue(wl->hw,
451 wl1271_tx_get_mac80211_queue(i));
452 clear_bit(i, &wl->stopped_queues_map);
453 spin_unlock_irqrestore(&wl->wl_lock, flags);
454 }
455 }
456}
457
458static struct sk_buff_head *wl1271_select_queue(struct wl1271 *wl,
459 struct sk_buff_head *queues)
460{
461 int i, q = -1, ac;
462 u32 min_pkts = 0xffffffff;
463
464 /*
465 * Find a non-empty ac where:
466 * 1. There are packets to transmit
467 * 2. The FW has the least allocated blocks
468 *
469 * We prioritize the ACs according to VO>VI>BE>BK
470 */
471 for (i = 0; i < NUM_TX_QUEUES; i++) {
472 ac = wl1271_tx_get_queue(i);
473 if (!skb_queue_empty(&queues[ac]) &&
474 (wl->tx_allocated_pkts[ac] < min_pkts)) {
475 q = ac;
476 min_pkts = wl->tx_allocated_pkts[q];
477 }
478 }
479
480 if (q == -1)
481 return NULL;
482
483 return &queues[q];
484}
485
486static struct sk_buff *wl12xx_lnk_skb_dequeue(struct wl1271 *wl,
487 struct wl1271_link *lnk)
488{
489 struct sk_buff *skb;
490 unsigned long flags;
491 struct sk_buff_head *queue;
492
493 queue = wl1271_select_queue(wl, lnk->tx_queue);
494 if (!queue)
495 return NULL;
496
497 skb = skb_dequeue(queue);
498 if (skb) {
499 int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
500 spin_lock_irqsave(&wl->wl_lock, flags);
501 WARN_ON_ONCE(wl->tx_queue_count[q] <= 0);
502 wl->tx_queue_count[q]--;
503 spin_unlock_irqrestore(&wl->wl_lock, flags);
504 }
505
506 return skb;
507}
508
509static struct sk_buff *wl12xx_vif_skb_dequeue(struct wl1271 *wl,
510 struct wl12xx_vif *wlvif)
511{
512 struct sk_buff *skb = NULL;
513 int i, h, start_hlid;
514
515 /* start from the link after the last one */
516 start_hlid = (wlvif->last_tx_hlid + 1) % WL12XX_MAX_LINKS;
517
518 /* dequeue according to AC, round robin on each link */
519 for (i = 0; i < WL12XX_MAX_LINKS; i++) {
520 h = (start_hlid + i) % WL12XX_MAX_LINKS;
521
522 /* only consider connected stations */
523 if (!test_bit(h, wlvif->links_map))
524 continue;
525
526 skb = wl12xx_lnk_skb_dequeue(wl, &wl->links[h]);
527 if (!skb)
528 continue;
529
530 wlvif->last_tx_hlid = h;
531 break;
532 }
533
534 if (!skb)
535 wlvif->last_tx_hlid = 0;
536
537 return skb;
538}
539
540static struct sk_buff *wl1271_skb_dequeue(struct wl1271 *wl)
541{
542 unsigned long flags;
543 struct wl12xx_vif *wlvif = wl->last_wlvif;
544 struct sk_buff *skb = NULL;
545
546 /* continue from last wlvif (round robin) */
547 if (wlvif) {
548 wl12xx_for_each_wlvif_continue(wl, wlvif) {
549 skb = wl12xx_vif_skb_dequeue(wl, wlvif);
550 if (skb) {
551 wl->last_wlvif = wlvif;
552 break;
553 }
554 }
555 }
556
557 /* dequeue from the system HLID before the restarting wlvif list */
558 if (!skb)
559 skb = wl12xx_lnk_skb_dequeue(wl, &wl->links[wl->system_hlid]);
560
561 /* do a new pass over the wlvif list */
562 if (!skb) {
563 wl12xx_for_each_wlvif(wl, wlvif) {
564 skb = wl12xx_vif_skb_dequeue(wl, wlvif);
565 if (skb) {
566 wl->last_wlvif = wlvif;
567 break;
568 }
569
570 /*
571 * No need to continue after last_wlvif. The previous
572 * pass should have found it.
573 */
574 if (wlvif == wl->last_wlvif)
575 break;
576 }
577 }
578
579 if (!skb &&
580 test_and_clear_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags)) {
581 int q;
582
583 skb = wl->dummy_packet;
584 q = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
585 spin_lock_irqsave(&wl->wl_lock, flags);
586 WARN_ON_ONCE(wl->tx_queue_count[q] <= 0);
587 wl->tx_queue_count[q]--;
588 spin_unlock_irqrestore(&wl->wl_lock, flags);
589 }
590
591 return skb;
592}
593
594static void wl1271_skb_queue_head(struct wl1271 *wl, struct wl12xx_vif *wlvif,
595 struct sk_buff *skb)
596{
597 unsigned long flags;
598 int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
599
600 if (wl12xx_is_dummy_packet(wl, skb)) {
601 set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags);
602 } else {
603 u8 hlid = wl12xx_tx_get_hlid(wl, wlvif, skb);
604 skb_queue_head(&wl->links[hlid].tx_queue[q], skb);
605
606 /* make sure we dequeue the same packet next time */
607 wlvif->last_tx_hlid = (hlid + WL12XX_MAX_LINKS - 1) %
608 WL12XX_MAX_LINKS;
609 }
610
611 spin_lock_irqsave(&wl->wl_lock, flags);
612 wl->tx_queue_count[q]++;
613 spin_unlock_irqrestore(&wl->wl_lock, flags);
614}
615
616static bool wl1271_tx_is_data_present(struct sk_buff *skb)
617{
618 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);
619
620 return ieee80211_is_data_present(hdr->frame_control);
621}
622
623void wl12xx_rearm_rx_streaming(struct wl1271 *wl, unsigned long *active_hlids)
624{
625 struct wl12xx_vif *wlvif;
626 u32 timeout;
627 u8 hlid;
628
629 if (!wl->conf.rx_streaming.interval)
630 return;
631
632 if (!wl->conf.rx_streaming.always &&
633 !test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))
634 return;
635
636 timeout = wl->conf.rx_streaming.duration;
637 wl12xx_for_each_wlvif_sta(wl, wlvif) {
638 bool found = false;
639 for_each_set_bit(hlid, active_hlids, WL12XX_MAX_LINKS) {
640 if (test_bit(hlid, wlvif->links_map)) {
641 found = true;
642 break;
643 }
644 }
645
646 if (!found)
647 continue;
648
649 /* enable rx streaming */
650 if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags))
651 ieee80211_queue_work(wl->hw,
652 &wlvif->rx_streaming_enable_work);
653
654 mod_timer(&wlvif->rx_streaming_timer,
655 jiffies + msecs_to_jiffies(timeout));
656 }
657}
658
659void wl1271_tx_work_locked(struct wl1271 *wl)
660{
661 struct wl12xx_vif *wlvif;
662 struct sk_buff *skb;
663 struct wl1271_tx_hw_descr *desc;
664 u32 buf_offset = 0;
665 bool sent_packets = false;
666 unsigned long active_hlids[BITS_TO_LONGS(WL12XX_MAX_LINKS)] = {0};
667 int ret;
668
669 if (unlikely(wl->state == WL1271_STATE_OFF))
670 return;
671
672 while ((skb = wl1271_skb_dequeue(wl))) {
673 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
674 bool has_data = false;
675
676 wlvif = NULL;
677 if (!wl12xx_is_dummy_packet(wl, skb) && info->control.vif)
678 wlvif = wl12xx_vif_to_data(info->control.vif);
679
680 has_data = wlvif && wl1271_tx_is_data_present(skb);
681 ret = wl1271_prepare_tx_frame(wl, wlvif, skb, buf_offset);
682 if (ret == -EAGAIN) {
683 /*
684 * Aggregation buffer is full.
685 * Flush buffer and try again.
686 */
687 wl1271_skb_queue_head(wl, wlvif, skb);
688 wlcore_write_data(wl, REG_SLV_MEM_DATA, wl->aggr_buf,
689 buf_offset, true);
690 sent_packets = true;
691 buf_offset = 0;
692 continue;
693 } else if (ret == -EBUSY) {
694 /*
695 * Firmware buffer is full.
696 * Queue back last skb, and stop aggregating.
697 */
698 wl1271_skb_queue_head(wl, wlvif, skb);
699 /* No work left, avoid scheduling redundant tx work */
700 set_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
701 goto out_ack;
702 } else if (ret < 0) {
703 if (wl12xx_is_dummy_packet(wl, skb))
704 /*
705 * fw still expects dummy packet,
706 * so re-enqueue it
707 */
708 wl1271_skb_queue_head(wl, wlvif, skb);
709 else
710 ieee80211_free_txskb(wl->hw, skb);
711 goto out_ack;
712 }
713 buf_offset += ret;
714 wl->tx_packets_count++;
715 if (has_data) {
716 desc = (struct wl1271_tx_hw_descr *) skb->data;
717 __set_bit(desc->hlid, active_hlids);
718 }
719 }
720
721out_ack:
722 if (buf_offset) {
723 wlcore_write_data(wl, REG_SLV_MEM_DATA, wl->aggr_buf,
724 buf_offset, true);
725 sent_packets = true;
726 }
727 if (sent_packets) {
728 /*
729 * Interrupt the firmware with the new packets. This is only
730 * required for older hardware revisions
731 */
732 if (wl->quirks & WLCORE_QUIRK_END_OF_TRANSACTION)
733 wl1271_write32(wl, WL12XX_HOST_WR_ACCESS,
734 wl->tx_packets_count);
735
736 wl1271_handle_tx_low_watermark(wl);
737 }
738 wl12xx_rearm_rx_streaming(wl, active_hlids);
739}
740
741void wl1271_tx_work(struct work_struct *work)
742{
743 struct wl1271 *wl = container_of(work, struct wl1271, tx_work);
744 int ret;
745
746 mutex_lock(&wl->mutex);
747 ret = wl1271_ps_elp_wakeup(wl);
748 if (ret < 0)
749 goto out;
750
751 wl1271_tx_work_locked(wl);
752
753 wl1271_ps_elp_sleep(wl);
754out:
755 mutex_unlock(&wl->mutex);
756}
757
758static u8 wl1271_tx_get_rate_flags(u8 rate_class_index)
759{
760 u8 flags = 0;
761
762 /*
763 * TODO: use wl12xx constants when this code is moved to wl12xx, as
764 * only it uses Tx-completion.
765 */
766 if (rate_class_index <= 8)
767 flags |= IEEE80211_TX_RC_MCS;
768
769 /*
770 * TODO: use wl12xx constants when this code is moved to wl12xx, as
771 * only it uses Tx-completion.
772 */
773 if (rate_class_index == 0)
774 flags |= IEEE80211_TX_RC_SHORT_GI;
775
776 return flags;
777}
778
779static void wl1271_tx_complete_packet(struct wl1271 *wl,
780 struct wl1271_tx_hw_res_descr *result)
781{
782 struct ieee80211_tx_info *info;
783 struct ieee80211_vif *vif;
784 struct wl12xx_vif *wlvif;
785 struct sk_buff *skb;
786 int id = result->id;
787 int rate = -1;
788 u8 rate_flags = 0;
789 u8 retries = 0;
790
791 /* check for id legality */
792 if (unlikely(id >= wl->num_tx_desc || wl->tx_frames[id] == NULL)) {
793 wl1271_warning("TX result illegal id: %d", id);
794 return;
795 }
796
797 skb = wl->tx_frames[id];
798 info = IEEE80211_SKB_CB(skb);
799
800 if (wl12xx_is_dummy_packet(wl, skb)) {
801 wl1271_free_tx_id(wl, id);
802 return;
803 }
804
805 /* info->control is valid as long as we don't update info->status */
806 vif = info->control.vif;
807 wlvif = wl12xx_vif_to_data(vif);
808
809 /* update the TX status info */
810 if (result->status == TX_SUCCESS) {
811 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
812 info->flags |= IEEE80211_TX_STAT_ACK;
813 rate = wlcore_rate_to_idx(wl, result->rate_class_index,
814 wlvif->band);
815 rate_flags = wl1271_tx_get_rate_flags(result->rate_class_index);
816 retries = result->ack_failures;
817 } else if (result->status == TX_RETRY_EXCEEDED) {
818 wl->stats.excessive_retries++;
819 retries = result->ack_failures;
820 }
821
822 info->status.rates[0].idx = rate;
823 info->status.rates[0].count = retries;
824 info->status.rates[0].flags = rate_flags;
825 info->status.ack_signal = -1;
826
827 wl->stats.retry_count += result->ack_failures;
828
829 /*
830 * update sequence number only when relevant, i.e. only in
831 * sessions of TKIP, AES and GEM (not in open or WEP sessions)
832 */
833 if (info->control.hw_key &&
834 (info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP ||
835 info->control.hw_key->cipher == WLAN_CIPHER_SUITE_CCMP ||
836 info->control.hw_key->cipher == WL1271_CIPHER_SUITE_GEM)) {
837 u8 fw_lsb = result->tx_security_sequence_number_lsb;
838 u8 cur_lsb = wlvif->tx_security_last_seq_lsb;
839
840 /*
841 * update security sequence number, taking care of potential
842 * wrap-around
843 */
844 wlvif->tx_security_seq += (fw_lsb - cur_lsb) & 0xff;
845 wlvif->tx_security_last_seq_lsb = fw_lsb;
846 }
847
848 /* remove private header from packet */
849 skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
850
851 /* remove TKIP header space if present */
852 if (info->control.hw_key &&
853 info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) {
854 int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
855 memmove(skb->data + WL1271_EXTRA_SPACE_TKIP, skb->data,
856 hdrlen);
857 skb_pull(skb, WL1271_EXTRA_SPACE_TKIP);
858 }
859
860 wl1271_debug(DEBUG_TX, "tx status id %u skb 0x%p failures %u rate 0x%x"
861 " status 0x%x",
862 result->id, skb, result->ack_failures,
863 result->rate_class_index, result->status);
864
865 /* return the packet to the stack */
866 skb_queue_tail(&wl->deferred_tx_queue, skb);
867 queue_work(wl->freezable_wq, &wl->netstack_work);
868 wl1271_free_tx_id(wl, result->id);
869}
870
871/* Called upon reception of a TX complete interrupt */
872void wl1271_tx_complete(struct wl1271 *wl)
873{
874 struct wl1271_acx_mem_map *memmap =
875 (struct wl1271_acx_mem_map *)wl->target_mem_map;
876 u32 count, fw_counter;
877 u32 i;
878
879 /* read the tx results from the chipset */
880 wl1271_read(wl, le32_to_cpu(memmap->tx_result),
881 wl->tx_res_if, sizeof(*wl->tx_res_if), false);
882 fw_counter = le32_to_cpu(wl->tx_res_if->tx_result_fw_counter);
883
884 /* write host counter to chipset (to ack) */
885 wl1271_write32(wl, le32_to_cpu(memmap->tx_result) +
886 offsetof(struct wl1271_tx_hw_res_if,
887 tx_result_host_counter), fw_counter);
888
889 count = fw_counter - wl->tx_results_count;
890 wl1271_debug(DEBUG_TX, "tx_complete received, packets: %d", count);
891
892 /* verify that the result buffer is not getting overrun */
893 if (unlikely(count > TX_HW_RESULT_QUEUE_LEN))
894 wl1271_warning("TX result overflow from chipset: %d", count);
895
896 /* process the results */
897 for (i = 0; i < count; i++) {
898 struct wl1271_tx_hw_res_descr *result;
899 u8 offset = wl->tx_results_count & TX_HW_RESULT_QUEUE_LEN_MASK;
900
901 /* process the packet */
902 result = &(wl->tx_res_if->tx_results_queue[offset]);
903 wl1271_tx_complete_packet(wl, result);
904
905 wl->tx_results_count++;
906 }
907}
908EXPORT_SYMBOL(wl1271_tx_complete);
909
910void wl1271_tx_reset_link_queues(struct wl1271 *wl, u8 hlid)
911{
912 struct sk_buff *skb;
913 int i;
914 unsigned long flags;
915 struct ieee80211_tx_info *info;
916 int total[NUM_TX_QUEUES];
917
918 for (i = 0; i < NUM_TX_QUEUES; i++) {
919 total[i] = 0;
920 while ((skb = skb_dequeue(&wl->links[hlid].tx_queue[i]))) {
921 wl1271_debug(DEBUG_TX, "link freeing skb 0x%p", skb);
922
923 if (!wl12xx_is_dummy_packet(wl, skb)) {
924 info = IEEE80211_SKB_CB(skb);
925 info->status.rates[0].idx = -1;
926 info->status.rates[0].count = 0;
927 ieee80211_tx_status_ni(wl->hw, skb);
928 }
929
930 total[i]++;
931 }
932 }
933
934 spin_lock_irqsave(&wl->wl_lock, flags);
935 for (i = 0; i < NUM_TX_QUEUES; i++)
936 wl->tx_queue_count[i] -= total[i];
937 spin_unlock_irqrestore(&wl->wl_lock, flags);
938
939 wl1271_handle_tx_low_watermark(wl);
940}
941
942/* caller must hold wl->mutex and TX must be stopped */
943void wl12xx_tx_reset_wlvif(struct wl1271 *wl, struct wl12xx_vif *wlvif)
944{
945 int i;
946
947 /* TX failure */
948 for_each_set_bit(i, wlvif->links_map, WL12XX_MAX_LINKS) {
949 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
950 wl1271_free_sta(wl, wlvif, i);
951 else
952 wlvif->sta.ba_rx_bitmap = 0;
953
954 wl->links[i].allocated_pkts = 0;
955 wl->links[i].prev_freed_pkts = 0;
956 }
957 wlvif->last_tx_hlid = 0;
958
959}
960/* caller must hold wl->mutex and TX must be stopped */
961void wl12xx_tx_reset(struct wl1271 *wl, bool reset_tx_queues)
962{
963 int i;
964 struct sk_buff *skb;
965 struct ieee80211_tx_info *info;
966
967 /* only reset the queues if something bad happened */
968 if (WARN_ON_ONCE(wl1271_tx_total_queue_count(wl) != 0)) {
969 for (i = 0; i < WL12XX_MAX_LINKS; i++)
970 wl1271_tx_reset_link_queues(wl, i);
971
972 for (i = 0; i < NUM_TX_QUEUES; i++)
973 wl->tx_queue_count[i] = 0;
974 }
975
976 wl->stopped_queues_map = 0;
977
978 /*
979 * Make sure the driver is at a consistent state, in case this
980 * function is called from a context other than interface removal.
981 * This call will always wake the TX queues.
982 */
983 if (reset_tx_queues)
984 wl1271_handle_tx_low_watermark(wl);
985
986 for (i = 0; i < wl->num_tx_desc; i++) {
987 if (wl->tx_frames[i] == NULL)
988 continue;
989
990 skb = wl->tx_frames[i];
991 wl1271_free_tx_id(wl, i);
992 wl1271_debug(DEBUG_TX, "freeing skb 0x%p", skb);
993
994 if (!wl12xx_is_dummy_packet(wl, skb)) {
995 /*
996 * Remove private headers before passing the skb to
997 * mac80211
998 */
999 info = IEEE80211_SKB_CB(skb);
1000 skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
1001 if (info->control.hw_key &&
1002 info->control.hw_key->cipher ==
1003 WLAN_CIPHER_SUITE_TKIP) {
1004 int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1005 memmove(skb->data + WL1271_EXTRA_SPACE_TKIP,
1006 skb->data, hdrlen);
1007 skb_pull(skb, WL1271_EXTRA_SPACE_TKIP);
1008 }
1009
1010 info->status.rates[0].idx = -1;
1011 info->status.rates[0].count = 0;
1012
1013 ieee80211_tx_status_ni(wl->hw, skb);
1014 }
1015 }
1016}
1017
1018#define WL1271_TX_FLUSH_TIMEOUT 500000
1019
1020/* caller must *NOT* hold wl->mutex */
1021void wl1271_tx_flush(struct wl1271 *wl)
1022{
1023 unsigned long timeout;
1024 int i;
1025 timeout = jiffies + usecs_to_jiffies(WL1271_TX_FLUSH_TIMEOUT);
1026
1027 while (!time_after(jiffies, timeout)) {
1028 mutex_lock(&wl->mutex);
1029 wl1271_debug(DEBUG_TX, "flushing tx buffer: %d %d",
1030 wl->tx_frames_cnt,
1031 wl1271_tx_total_queue_count(wl));
1032 if ((wl->tx_frames_cnt == 0) &&
1033 (wl1271_tx_total_queue_count(wl) == 0)) {
1034 mutex_unlock(&wl->mutex);
1035 return;
1036 }
1037 mutex_unlock(&wl->mutex);
1038 msleep(1);
1039 }
1040
1041 wl1271_warning("Unable to flush all TX buffers, timed out.");
1042
1043 /* forcibly flush all Tx buffers on our queues */
1044 mutex_lock(&wl->mutex);
1045 for (i = 0; i < WL12XX_MAX_LINKS; i++)
1046 wl1271_tx_reset_link_queues(wl, i);
1047 mutex_unlock(&wl->mutex);
1048}
1049
1050u32 wl1271_tx_min_rate_get(struct wl1271 *wl, u32 rate_set)
1051{
1052 if (WARN_ON(!rate_set))
1053 return 0;
1054
1055 return BIT(__ffs(rate_set));
1056}
diff --git a/drivers/net/wireless/ti/wlcore/tx.h b/drivers/net/wireless/ti/wlcore/tx.h
new file mode 100644
index 000000000000..2fd6e5dc6f75
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/tx.h
@@ -0,0 +1,231 @@
1/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
5 * Copyright (C) 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 __TX_H__
26#define __TX_H__
27
28#define TX_HW_MGMT_PKT_LIFETIME_TU 2000
29#define TX_HW_AP_MODE_PKT_LIFETIME_TU 8000
30
31#define TX_HW_ATTR_SAVE_RETRIES BIT(0)
32#define TX_HW_ATTR_HEADER_PAD BIT(1)
33#define TX_HW_ATTR_SESSION_COUNTER (BIT(2) | BIT(3) | BIT(4))
34#define TX_HW_ATTR_RATE_POLICY (BIT(5) | BIT(6) | BIT(7) | \
35 BIT(8) | BIT(9))
36#define TX_HW_ATTR_LAST_WORD_PAD (BIT(10) | BIT(11))
37#define TX_HW_ATTR_TX_CMPLT_REQ BIT(12)
38#define TX_HW_ATTR_TX_DUMMY_REQ BIT(13)
39#define TX_HW_ATTR_HOST_ENCRYPT BIT(14)
40
41#define TX_HW_ATTR_OFST_SAVE_RETRIES 0
42#define TX_HW_ATTR_OFST_HEADER_PAD 1
43#define TX_HW_ATTR_OFST_SESSION_COUNTER 2
44#define TX_HW_ATTR_OFST_RATE_POLICY 5
45#define TX_HW_ATTR_OFST_LAST_WORD_PAD 10
46#define TX_HW_ATTR_OFST_TX_CMPLT_REQ 12
47
48#define TX_HW_RESULT_QUEUE_LEN 16
49#define TX_HW_RESULT_QUEUE_LEN_MASK 0xf
50
51#define WL1271_TX_ALIGN_TO 4
52#define WL1271_EXTRA_SPACE_TKIP 4
53#define WL1271_EXTRA_SPACE_AES 8
54#define WL1271_EXTRA_SPACE_MAX 8
55
56/* Used for management frames and dummy packets */
57#define WL1271_TID_MGMT 7
58
59struct wl127x_tx_mem {
60 /*
61 * Number of extra memory blocks to allocate for this packet
62 * in addition to the number of blocks derived from the packet
63 * length.
64 */
65 u8 extra_blocks;
66 /*
67 * Total number of memory blocks allocated by the host for
68 * this packet. Must be equal or greater than the actual
69 * blocks number allocated by HW.
70 */
71 u8 total_mem_blocks;
72} __packed;
73
74struct wl128x_tx_mem {
75 /*
76 * Total number of memory blocks allocated by the host for
77 * this packet.
78 */
79 u8 total_mem_blocks;
80 /*
81 * Number of extra bytes, at the end of the frame. the host
82 * uses this padding to complete each frame to integer number
83 * of SDIO blocks.
84 */
85 u8 extra_bytes;
86} __packed;
87
88/*
89 * On wl128x based devices, when TX packets are aggregated, each packet
90 * size must be aligned to the SDIO block size. The maximum block size
91 * is bounded by the type of the padded bytes field that is sent to the
92 * FW. Currently the type is u8, so the maximum block size is 256 bytes.
93 */
94#define WL12XX_BUS_BLOCK_SIZE min(512u, \
95 (1u << (8 * sizeof(((struct wl128x_tx_mem *) 0)->extra_bytes))))
96
97struct wl1271_tx_hw_descr {
98 /* Length of packet in words, including descriptor+header+data */
99 __le16 length;
100 union {
101 struct wl127x_tx_mem wl127x_mem;
102 struct wl128x_tx_mem wl128x_mem;
103 } __packed;
104 /* Device time (in us) when the packet arrived to the driver */
105 __le32 start_time;
106 /*
107 * Max delay in TUs until transmission. The last device time the
108 * packet can be transmitted is: start_time + (1024 * life_time)
109 */
110 __le16 life_time;
111 /* Bitwise fields - see TX_ATTR... definitions above. */
112 __le16 tx_attr;
113 /* Packet identifier used also in the Tx-Result. */
114 u8 id;
115 /* The packet TID value (as User-Priority) */
116 u8 tid;
117 /* host link ID (HLID) */
118 u8 hlid;
119 u8 reserved;
120} __packed;
121
122enum wl1271_tx_hw_res_status {
123 TX_SUCCESS = 0,
124 TX_HW_ERROR = 1,
125 TX_DISABLED = 2,
126 TX_RETRY_EXCEEDED = 3,
127 TX_TIMEOUT = 4,
128 TX_KEY_NOT_FOUND = 5,
129 TX_PEER_NOT_FOUND = 6,
130 TX_SESSION_MISMATCH = 7,
131 TX_LINK_NOT_VALID = 8,
132};
133
134struct wl1271_tx_hw_res_descr {
135 /* Packet Identifier - same value used in the Tx descriptor.*/
136 u8 id;
137 /* The status of the transmission, indicating success or one of
138 several possible reasons for failure. */
139 u8 status;
140 /* Total air access duration including all retrys and overheads.*/
141 __le16 medium_usage;
142 /* The time passed from host xfer to Tx-complete.*/
143 __le32 fw_handling_time;
144 /* Total media delay
145 (from 1st EDCA AIFS counter until TX Complete). */
146 __le32 medium_delay;
147 /* LS-byte of last TKIP seq-num (saved per AC for recovery). */
148 u8 tx_security_sequence_number_lsb;
149 /* Retry count - number of transmissions without successful ACK.*/
150 u8 ack_failures;
151 /* The rate that succeeded getting ACK
152 (Valid only if status=SUCCESS). */
153 u8 rate_class_index;
154 /* for 4-byte alignment. */
155 u8 spare;
156} __packed;
157
158struct wl1271_tx_hw_res_if {
159 __le32 tx_result_fw_counter;
160 __le32 tx_result_host_counter;
161 struct wl1271_tx_hw_res_descr tx_results_queue[TX_HW_RESULT_QUEUE_LEN];
162} __packed;
163
164static inline int wl1271_tx_get_queue(int queue)
165{
166 switch (queue) {
167 case 0:
168 return CONF_TX_AC_VO;
169 case 1:
170 return CONF_TX_AC_VI;
171 case 2:
172 return CONF_TX_AC_BE;
173 case 3:
174 return CONF_TX_AC_BK;
175 default:
176 return CONF_TX_AC_BE;
177 }
178}
179
180static inline int wl1271_tx_get_mac80211_queue(int queue)
181{
182 switch (queue) {
183 case CONF_TX_AC_VO:
184 return 0;
185 case CONF_TX_AC_VI:
186 return 1;
187 case CONF_TX_AC_BE:
188 return 2;
189 case CONF_TX_AC_BK:
190 return 3;
191 default:
192 return 2;
193 }
194}
195
196static inline int wl1271_tx_total_queue_count(struct wl1271 *wl)
197{
198 int i, count = 0;
199
200 for (i = 0; i < NUM_TX_QUEUES; i++)
201 count += wl->tx_queue_count[i];
202
203 return count;
204}
205
206void wl1271_tx_work(struct work_struct *work);
207void wl1271_tx_work_locked(struct wl1271 *wl);
208void wl1271_tx_complete(struct wl1271 *wl);
209void wl12xx_tx_reset_wlvif(struct wl1271 *wl, struct wl12xx_vif *wlvif);
210void wl12xx_tx_reset(struct wl1271 *wl, bool reset_tx_queues);
211void wl1271_tx_flush(struct wl1271 *wl);
212u8 wlcore_rate_to_idx(struct wl1271 *wl, u8 rate, enum ieee80211_band band);
213u32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set,
214 enum ieee80211_band rate_band);
215u32 wl1271_tx_min_rate_get(struct wl1271 *wl, u32 rate_set);
216u8 wl12xx_tx_get_hlid_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif,
217 struct sk_buff *skb);
218u8 wl12xx_tx_get_hlid(struct wl1271 *wl, struct wl12xx_vif *wlvif,
219 struct sk_buff *skb);
220void wl1271_tx_reset_link_queues(struct wl1271 *wl, u8 hlid);
221void wl1271_handle_tx_low_watermark(struct wl1271 *wl);
222bool wl12xx_is_dummy_packet(struct wl1271 *wl, struct sk_buff *skb);
223void wl12xx_rearm_rx_streaming(struct wl1271 *wl, unsigned long *active_hlids);
224unsigned int wlcore_calc_packet_alignment(struct wl1271 *wl,
225 unsigned int packet_length);
226
227/* from main.c */
228void wl1271_free_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid);
229void wl12xx_rearm_tx_watchdog_locked(struct wl1271 *wl);
230
231#endif
diff --git a/drivers/net/wireless/ti/wlcore/wl12xx.h b/drivers/net/wireless/ti/wlcore/wl12xx.h
new file mode 100644
index 000000000000..a9b220c43e54
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/wl12xx.h
@@ -0,0 +1,466 @@
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 WL127X_FW_NAME_MULTI "ti-connectivity/wl127x-fw-4-mr.bin"
39#define WL127X_FW_NAME_SINGLE "ti-connectivity/wl127x-fw-4-sr.bin"
40
41#define WL128X_FW_NAME_MULTI "ti-connectivity/wl128x-fw-4-mr.bin"
42#define WL128X_FW_NAME_SINGLE "ti-connectivity/wl128x-fw-4-sr.bin"
43
44#define WL127X_PLT_FW_NAME "ti-connectivity/wl127x-fw-4-plt.bin"
45#define WL128X_PLT_FW_NAME "ti-connectivity/wl128x-fw-4-plt.bin"
46
47/*
48 * wl127x and wl128x are using the same NVS file name. However, the
49 * ini parameters between them are different. The driver validates
50 * the correct NVS size in wl1271_boot_upload_nvs().
51 */
52#define WL12XX_NVS_NAME "ti-connectivity/wl1271-nvs.bin"
53
54#define WL1271_TX_SECURITY_LO16(s) ((u16)((s) & 0xffff))
55#define WL1271_TX_SECURITY_HI32(s) ((u32)(((s) >> 16) & 0xffffffff))
56#define WL1271_TX_SQN_POST_RECOVERY_PADDING 0xff
57
58#define WL1271_CIPHER_SUITE_GEM 0x00147201
59
60#define WL1271_BUSY_WORD_CNT 1
61#define WL1271_BUSY_WORD_LEN (WL1271_BUSY_WORD_CNT * sizeof(u32))
62
63#define WL1271_ELP_HW_STATE_ASLEEP 0
64#define WL1271_ELP_HW_STATE_IRQ 1
65
66#define WL1271_DEFAULT_BEACON_INT 100
67#define WL1271_DEFAULT_DTIM_PERIOD 1
68
69#define WL12XX_MAX_ROLES 4
70#define WL12XX_MAX_LINKS 12
71#define WL12XX_INVALID_ROLE_ID 0xff
72#define WL12XX_INVALID_LINK_ID 0xff
73
74#define WL12XX_MAX_RATE_POLICIES 16
75
76/* Defined by FW as 0. Will not be freed or allocated. */
77#define WL12XX_SYSTEM_HLID 0
78
79/*
80 * When in AP-mode, we allow (at least) this number of packets
81 * to be transmitted to FW for a STA in PS-mode. Only when packets are
82 * present in the FW buffers it will wake the sleeping STA. We want to put
83 * enough packets for the driver to transmit all of its buffered data before
84 * the STA goes to sleep again. But we don't want to take too much memory
85 * as it might hurt the throughput of active STAs.
86 */
87#define WL1271_PS_STA_MAX_PACKETS 2
88
89#define WL1271_AP_BSS_INDEX 0
90#define WL1271_AP_DEF_BEACON_EXP 20
91
92#define WL1271_AGGR_BUFFER_SIZE (4 * PAGE_SIZE)
93
94enum wl1271_state {
95 WL1271_STATE_OFF,
96 WL1271_STATE_ON,
97};
98
99enum wl12xx_fw_type {
100 WL12XX_FW_TYPE_NONE,
101 WL12XX_FW_TYPE_NORMAL,
102 WL12XX_FW_TYPE_MULTI,
103 WL12XX_FW_TYPE_PLT,
104};
105
106struct wl1271;
107
108enum {
109 FW_VER_CHIP,
110 FW_VER_IF_TYPE,
111 FW_VER_MAJOR,
112 FW_VER_SUBTYPE,
113 FW_VER_MINOR,
114
115 NUM_FW_VER
116};
117
118#define FW_VER_CHIP_WL127X 6
119#define FW_VER_CHIP_WL128X 7
120
121#define FW_VER_IF_TYPE_STA 1
122#define FW_VER_IF_TYPE_AP 2
123
124#define FW_VER_MINOR_1_SPARE_STA_MIN 58
125#define FW_VER_MINOR_1_SPARE_AP_MIN 47
126
127#define FW_VER_MINOR_FWLOG_STA_MIN 70
128
129struct wl1271_chip {
130 u32 id;
131 char fw_ver_str[ETHTOOL_BUSINFO_LEN];
132 unsigned int fw_ver[NUM_FW_VER];
133};
134
135struct wl1271_stats {
136 struct acx_statistics *fw_stats;
137 unsigned long fw_stats_update;
138
139 unsigned int retry_count;
140 unsigned int excessive_retries;
141};
142
143#define NUM_TX_QUEUES 4
144#define NUM_RX_PKT_DESC 8
145
146#define AP_MAX_STATIONS 8
147
148struct wl_fw_packet_counters {
149 /* Cumulative counter of released packets per AC */
150 u8 tx_released_pkts[NUM_TX_QUEUES];
151
152 /* Cumulative counter of freed packets per HLID */
153 u8 tx_lnk_free_pkts[WL12XX_MAX_LINKS];
154
155 /* Cumulative counter of released Voice memory blocks */
156 u8 tx_voice_released_blks;
157
158 u8 padding[3];
159} __packed;
160
161/* FW status registers */
162struct wl_fw_status {
163 __le32 intr;
164 u8 fw_rx_counter;
165 u8 drv_rx_counter;
166 u8 reserved;
167 u8 tx_results_counter;
168 __le32 rx_pkt_descs[NUM_RX_PKT_DESC];
169 __le32 fw_localtime;
170
171 /*
172 * A bitmap (where each bit represents a single HLID)
173 * to indicate if the station is in PS mode.
174 */
175 __le32 link_ps_bitmap;
176
177 /*
178 * A bitmap (where each bit represents a single HLID) to indicate
179 * if the station is in Fast mode
180 */
181 __le32 link_fast_bitmap;
182
183 /* Cumulative counter of total released mem blocks since FW-reset */
184 __le32 total_released_blks;
185
186 /* Size (in Memory Blocks) of TX pool */
187 __le32 tx_total;
188
189 struct wl_fw_packet_counters counters;
190
191 __le32 log_start_addr;
192
193 /* Private status to be used by the lower drivers */
194 u8 priv[0];
195} __packed;
196
197struct wl1271_rx_mem_pool_addr {
198 u32 addr;
199 u32 addr_extra;
200};
201
202#define WL1271_MAX_CHANNELS 64
203struct wl1271_scan {
204 struct cfg80211_scan_request *req;
205 unsigned long scanned_ch[BITS_TO_LONGS(WL1271_MAX_CHANNELS)];
206 bool failed;
207 u8 state;
208 u8 ssid[IEEE80211_MAX_SSID_LEN+1];
209 size_t ssid_len;
210};
211
212struct wl1271_if_operations {
213 void (*read)(struct device *child, int addr, void *buf, size_t len,
214 bool fixed);
215 void (*write)(struct device *child, int addr, void *buf, size_t len,
216 bool fixed);
217 void (*reset)(struct device *child);
218 void (*init)(struct device *child);
219 int (*power)(struct device *child, bool enable);
220 void (*set_block_size) (struct device *child, unsigned int blksz);
221};
222
223#define MAX_NUM_KEYS 14
224#define MAX_KEY_SIZE 32
225
226struct wl1271_ap_key {
227 u8 id;
228 u8 key_type;
229 u8 key_size;
230 u8 key[MAX_KEY_SIZE];
231 u8 hlid;
232 u32 tx_seq_32;
233 u16 tx_seq_16;
234};
235
236enum wl12xx_flags {
237 WL1271_FLAG_GPIO_POWER,
238 WL1271_FLAG_TX_QUEUE_STOPPED,
239 WL1271_FLAG_TX_PENDING,
240 WL1271_FLAG_IN_ELP,
241 WL1271_FLAG_ELP_REQUESTED,
242 WL1271_FLAG_IRQ_RUNNING,
243 WL1271_FLAG_FW_TX_BUSY,
244 WL1271_FLAG_DUMMY_PACKET_PENDING,
245 WL1271_FLAG_SUSPENDED,
246 WL1271_FLAG_PENDING_WORK,
247 WL1271_FLAG_SOFT_GEMINI,
248 WL1271_FLAG_RECOVERY_IN_PROGRESS,
249 WL1271_FLAG_VIF_CHANGE_IN_PROGRESS,
250 WL1271_FLAG_INTENDED_FW_RECOVERY,
251};
252
253enum wl12xx_vif_flags {
254 WLVIF_FLAG_INITIALIZED,
255 WLVIF_FLAG_STA_ASSOCIATED,
256 WLVIF_FLAG_STA_AUTHORIZED,
257 WLVIF_FLAG_IBSS_JOINED,
258 WLVIF_FLAG_AP_STARTED,
259 WLVIF_FLAG_IN_PS,
260 WLVIF_FLAG_STA_STATE_SENT,
261 WLVIF_FLAG_RX_STREAMING_STARTED,
262 WLVIF_FLAG_PSPOLL_FAILURE,
263 WLVIF_FLAG_CS_PROGRESS,
264 WLVIF_FLAG_AP_PROBE_RESP_SET,
265 WLVIF_FLAG_IN_USE,
266};
267
268struct wl1271_link {
269 /* AP-mode - TX queue per AC in link */
270 struct sk_buff_head tx_queue[NUM_TX_QUEUES];
271
272 /* accounting for allocated / freed packets in FW */
273 u8 allocated_pkts;
274 u8 prev_freed_pkts;
275
276 u8 addr[ETH_ALEN];
277
278 /* bitmap of TIDs where RX BA sessions are active for this link */
279 u8 ba_bitmap;
280};
281
282struct wl1271_station {
283 u8 hlid;
284};
285
286struct wl12xx_vif {
287 struct wl1271 *wl;
288 struct list_head list;
289 unsigned long flags;
290 u8 bss_type;
291 u8 p2p; /* we are using p2p role */
292 u8 role_id;
293
294 /* sta/ibss specific */
295 u8 dev_role_id;
296 u8 dev_hlid;
297
298 union {
299 struct {
300 u8 hlid;
301 u8 ba_rx_bitmap;
302
303 u8 basic_rate_idx;
304 u8 ap_rate_idx;
305 u8 p2p_rate_idx;
306
307 bool qos;
308 } sta;
309 struct {
310 u8 global_hlid;
311 u8 bcast_hlid;
312
313 /* HLIDs bitmap of associated stations */
314 unsigned long sta_hlid_map[BITS_TO_LONGS(
315 WL12XX_MAX_LINKS)];
316
317 /* recoreded keys - set here before AP startup */
318 struct wl1271_ap_key *recorded_keys[MAX_NUM_KEYS];
319
320 u8 mgmt_rate_idx;
321 u8 bcast_rate_idx;
322 u8 ucast_rate_idx[CONF_TX_MAX_AC_COUNT];
323 } ap;
324 };
325
326 /* the hlid of the last transmitted skb */
327 int last_tx_hlid;
328
329 unsigned long links_map[BITS_TO_LONGS(WL12XX_MAX_LINKS)];
330
331 u8 ssid[IEEE80211_MAX_SSID_LEN + 1];
332 u8 ssid_len;
333
334 /* The current band */
335 enum ieee80211_band band;
336 int channel;
337
338 u32 bitrate_masks[IEEE80211_NUM_BANDS];
339 u32 basic_rate_set;
340
341 /*
342 * currently configured rate set:
343 * bits 0-15 - 802.11abg rates
344 * bits 16-23 - 802.11n MCS index mask
345 * support only 1 stream, thus only 8 bits for the MCS rates (0-7).
346 */
347 u32 basic_rate;
348 u32 rate_set;
349
350 /* probe-req template for the current AP */
351 struct sk_buff *probereq;
352
353 /* Beaconing interval (needed for ad-hoc) */
354 u32 beacon_int;
355
356 /* Default key (for WEP) */
357 u32 default_key;
358
359 /* Our association ID */
360 u16 aid;
361
362 /* Session counter for the chipset */
363 int session_counter;
364
365 /* retry counter for PSM entries */
366 u8 psm_entry_retry;
367
368 /* in dBm */
369 int power_level;
370
371 int rssi_thold;
372 int last_rssi_event;
373
374 /* save the current encryption type for auto-arp config */
375 u8 encryption_type;
376 __be32 ip_addr;
377
378 /* RX BA constraint value */
379 bool ba_support;
380 bool ba_allowed;
381
382 /* Rx Streaming */
383 struct work_struct rx_streaming_enable_work;
384 struct work_struct rx_streaming_disable_work;
385 struct timer_list rx_streaming_timer;
386
387 /* does the current role use GEM for encryption (AP or STA) */
388 bool is_gem;
389
390 /*
391 * This struct must be last!
392 * data that has to be saved acrossed reconfigs (e.g. recovery)
393 * should be declared in this struct.
394 */
395 struct {
396 u8 persistent[0];
397 /*
398 * Security sequence number
399 * bits 0-15: lower 16 bits part of sequence number
400 * bits 16-47: higher 32 bits part of sequence number
401 * bits 48-63: not in use
402 */
403 u64 tx_security_seq;
404
405 /* 8 bits of the last sequence number in use */
406 u8 tx_security_last_seq_lsb;
407 };
408};
409
410static inline struct wl12xx_vif *wl12xx_vif_to_data(struct ieee80211_vif *vif)
411{
412 return (struct wl12xx_vif *)vif->drv_priv;
413}
414
415static inline
416struct ieee80211_vif *wl12xx_wlvif_to_vif(struct wl12xx_vif *wlvif)
417{
418 return container_of((void *)wlvif, struct ieee80211_vif, drv_priv);
419}
420
421#define wl12xx_for_each_wlvif(wl, wlvif) \
422 list_for_each_entry(wlvif, &wl->wlvif_list, list)
423
424#define wl12xx_for_each_wlvif_continue(wl, wlvif) \
425 list_for_each_entry_continue(wlvif, &wl->wlvif_list, list)
426
427#define wl12xx_for_each_wlvif_bss_type(wl, wlvif, _bss_type) \
428 wl12xx_for_each_wlvif(wl, wlvif) \
429 if (wlvif->bss_type == _bss_type)
430
431#define wl12xx_for_each_wlvif_sta(wl, wlvif) \
432 wl12xx_for_each_wlvif_bss_type(wl, wlvif, BSS_TYPE_STA_BSS)
433
434#define wl12xx_for_each_wlvif_ap(wl, wlvif) \
435 wl12xx_for_each_wlvif_bss_type(wl, wlvif, BSS_TYPE_AP_BSS)
436
437int wl1271_plt_start(struct wl1271 *wl);
438int wl1271_plt_stop(struct wl1271 *wl);
439int wl1271_recalc_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif);
440void wl12xx_queue_recovery_work(struct wl1271 *wl);
441size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen);
442
443#define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
444
445#define SESSION_COUNTER_MAX 6 /* maximum value for the session counter */
446#define SESSION_COUNTER_INVALID 7 /* used with dummy_packet */
447
448#define WL1271_DEFAULT_POWER_LEVEL 0
449
450#define WL1271_TX_QUEUE_LOW_WATERMARK 32
451#define WL1271_TX_QUEUE_HIGH_WATERMARK 256
452
453#define WL1271_DEFERRED_QUEUE_LIMIT 64
454
455/* WL1271 needs a 200ms sleep after power on, and a 20ms sleep before power
456 on in case is has been shut down shortly before */
457#define WL1271_PRE_POWER_ON_SLEEP 20 /* in milliseconds */
458#define WL1271_POWER_ON_SLEEP 200 /* in milliseconds */
459
460/* Macros to handle wl1271.sta_rate_set */
461#define HW_BG_RATES_MASK 0xffff
462#define HW_HT_RATES_OFFSET 16
463
464#define WL12XX_HW_BLOCK_SIZE 256
465
466#endif
diff --git a/drivers/net/wireless/ti/wlcore/wl12xx_80211.h b/drivers/net/wireless/ti/wlcore/wl12xx_80211.h
new file mode 100644
index 000000000000..22b0bc98d7b5
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/wl12xx_80211.h
@@ -0,0 +1,137 @@
1#ifndef __WL12XX_80211_H__
2#define __WL12XX_80211_H__
3
4#include <linux/if_ether.h> /* ETH_ALEN */
5#include <linux/if_arp.h>
6
7/* RATES */
8#define IEEE80211_CCK_RATE_1MB 0x02
9#define IEEE80211_CCK_RATE_2MB 0x04
10#define IEEE80211_CCK_RATE_5MB 0x0B
11#define IEEE80211_CCK_RATE_11MB 0x16
12#define IEEE80211_OFDM_RATE_6MB 0x0C
13#define IEEE80211_OFDM_RATE_9MB 0x12
14#define IEEE80211_OFDM_RATE_12MB 0x18
15#define IEEE80211_OFDM_RATE_18MB 0x24
16#define IEEE80211_OFDM_RATE_24MB 0x30
17#define IEEE80211_OFDM_RATE_36MB 0x48
18#define IEEE80211_OFDM_RATE_48MB 0x60
19#define IEEE80211_OFDM_RATE_54MB 0x6C
20#define IEEE80211_BASIC_RATE_MASK 0x80
21
22#define IEEE80211_CCK_RATE_1MB_MASK (1<<0)
23#define IEEE80211_CCK_RATE_2MB_MASK (1<<1)
24#define IEEE80211_CCK_RATE_5MB_MASK (1<<2)
25#define IEEE80211_CCK_RATE_11MB_MASK (1<<3)
26#define IEEE80211_OFDM_RATE_6MB_MASK (1<<4)
27#define IEEE80211_OFDM_RATE_9MB_MASK (1<<5)
28#define IEEE80211_OFDM_RATE_12MB_MASK (1<<6)
29#define IEEE80211_OFDM_RATE_18MB_MASK (1<<7)
30#define IEEE80211_OFDM_RATE_24MB_MASK (1<<8)
31#define IEEE80211_OFDM_RATE_36MB_MASK (1<<9)
32#define IEEE80211_OFDM_RATE_48MB_MASK (1<<10)
33#define IEEE80211_OFDM_RATE_54MB_MASK (1<<11)
34
35#define IEEE80211_CCK_RATES_MASK 0x0000000F
36#define IEEE80211_CCK_BASIC_RATES_MASK (IEEE80211_CCK_RATE_1MB_MASK | \
37 IEEE80211_CCK_RATE_2MB_MASK)
38#define IEEE80211_CCK_DEFAULT_RATES_MASK (IEEE80211_CCK_BASIC_RATES_MASK | \
39 IEEE80211_CCK_RATE_5MB_MASK | \
40 IEEE80211_CCK_RATE_11MB_MASK)
41
42#define IEEE80211_OFDM_RATES_MASK 0x00000FF0
43#define IEEE80211_OFDM_BASIC_RATES_MASK (IEEE80211_OFDM_RATE_6MB_MASK | \
44 IEEE80211_OFDM_RATE_12MB_MASK | \
45 IEEE80211_OFDM_RATE_24MB_MASK)
46#define IEEE80211_OFDM_DEFAULT_RATES_MASK (IEEE80211_OFDM_BASIC_RATES_MASK | \
47 IEEE80211_OFDM_RATE_9MB_MASK | \
48 IEEE80211_OFDM_RATE_18MB_MASK | \
49 IEEE80211_OFDM_RATE_36MB_MASK | \
50 IEEE80211_OFDM_RATE_48MB_MASK | \
51 IEEE80211_OFDM_RATE_54MB_MASK)
52#define IEEE80211_DEFAULT_RATES_MASK (IEEE80211_OFDM_DEFAULT_RATES_MASK | \
53 IEEE80211_CCK_DEFAULT_RATES_MASK)
54
55
56/* This really should be 8, but not for our firmware */
57#define MAX_SUPPORTED_RATES 32
58#define MAX_COUNTRY_TRIPLETS 32
59
60/* Headers */
61struct ieee80211_header {
62 __le16 frame_ctl;
63 __le16 duration_id;
64 u8 da[ETH_ALEN];
65 u8 sa[ETH_ALEN];
66 u8 bssid[ETH_ALEN];
67 __le16 seq_ctl;
68 u8 payload[0];
69} __packed;
70
71struct wl12xx_ie_header {
72 u8 id;
73 u8 len;
74} __packed;
75
76/* IEs */
77
78struct wl12xx_ie_ssid {
79 struct wl12xx_ie_header header;
80 char ssid[IEEE80211_MAX_SSID_LEN];
81} __packed;
82
83struct wl12xx_ie_rates {
84 struct wl12xx_ie_header header;
85 u8 rates[MAX_SUPPORTED_RATES];
86} __packed;
87
88struct wl12xx_ie_ds_params {
89 struct wl12xx_ie_header header;
90 u8 channel;
91} __packed;
92
93struct country_triplet {
94 u8 channel;
95 u8 num_channels;
96 u8 max_tx_power;
97} __packed;
98
99struct wl12xx_ie_country {
100 struct wl12xx_ie_header header;
101 u8 country_string[IEEE80211_COUNTRY_STRING_LEN];
102 struct country_triplet triplets[MAX_COUNTRY_TRIPLETS];
103} __packed;
104
105
106/* Templates */
107
108struct wl12xx_null_data_template {
109 struct ieee80211_header header;
110} __packed;
111
112struct wl12xx_ps_poll_template {
113 __le16 fc;
114 __le16 aid;
115 u8 bssid[ETH_ALEN];
116 u8 ta[ETH_ALEN];
117} __packed;
118
119struct wl12xx_arp_rsp_template {
120 /* not including ieee80211 header */
121
122 u8 llc_hdr[sizeof(rfc1042_header)];
123 __be16 llc_type;
124
125 struct arphdr arp_hdr;
126 u8 sender_hw[ETH_ALEN];
127 __be32 sender_ip;
128 u8 target_hw[ETH_ALEN];
129 __be32 target_ip;
130} __packed;
131
132struct wl12xx_disconn_template {
133 struct ieee80211_header header;
134 __le16 disconn_reason;
135} __packed;
136
137#endif
diff --git a/drivers/net/wireless/ti/wlcore/wl12xx_platform_data.c b/drivers/net/wireless/ti/wlcore/wl12xx_platform_data.c
new file mode 100644
index 000000000000..998e95895f9d
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/wl12xx_platform_data.c
@@ -0,0 +1,49 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (C) 2010-2011 Texas Instruments, Inc.
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
22#include <linux/module.h>
23#include <linux/err.h>
24#include <linux/wl12xx.h>
25
26static struct wl12xx_platform_data *platform_data;
27
28int __init wl12xx_set_platform_data(const struct wl12xx_platform_data *data)
29{
30 if (platform_data)
31 return -EBUSY;
32 if (!data)
33 return -EINVAL;
34
35 platform_data = kmemdup(data, sizeof(*data), GFP_KERNEL);
36 if (!platform_data)
37 return -ENOMEM;
38
39 return 0;
40}
41
42struct wl12xx_platform_data *wl12xx_get_platform_data(void)
43{
44 if (!platform_data)
45 return ERR_PTR(-ENODEV);
46
47 return platform_data;
48}
49EXPORT_SYMBOL(wl12xx_get_platform_data);
diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
new file mode 100644
index 000000000000..39f9fadfebd9
--- /dev/null
+++ b/drivers/net/wireless/ti/wlcore/wlcore.h
@@ -0,0 +1,448 @@
1/*
2 * This file is part of wlcore
3 *
4 * Copyright (C) 2011 Texas Instruments Inc.
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
22#ifndef __WLCORE_H__
23#define __WLCORE_H__
24
25#include <linux/platform_device.h>
26
27#include "wl12xx.h"
28#include "event.h"
29
30/* The maximum number of Tx descriptors in all chip families */
31#define WLCORE_MAX_TX_DESCRIPTORS 32
32
33/* forward declaration */
34struct wl1271_tx_hw_descr;
35enum wl_rx_buf_align;
36
37struct wlcore_ops {
38 int (*identify_chip)(struct wl1271 *wl);
39 int (*identify_fw)(struct wl1271 *wl);
40 int (*boot)(struct wl1271 *wl);
41 void (*trigger_cmd)(struct wl1271 *wl, int cmd_box_addr,
42 void *buf, size_t len);
43 void (*ack_event)(struct wl1271 *wl);
44 u32 (*calc_tx_blocks)(struct wl1271 *wl, u32 len, u32 spare_blks);
45 void (*set_tx_desc_blocks)(struct wl1271 *wl,
46 struct wl1271_tx_hw_descr *desc,
47 u32 blks, u32 spare_blks);
48 void (*set_tx_desc_data_len)(struct wl1271 *wl,
49 struct wl1271_tx_hw_descr *desc,
50 struct sk_buff *skb);
51 enum wl_rx_buf_align (*get_rx_buf_align)(struct wl1271 *wl,
52 u32 rx_desc);
53 void (*prepare_read)(struct wl1271 *wl, u32 rx_desc, u32 len);
54 u32 (*get_rx_packet_len)(struct wl1271 *wl, void *rx_data,
55 u32 data_len);
56 void (*tx_delayed_compl)(struct wl1271 *wl);
57 void (*tx_immediate_compl)(struct wl1271 *wl);
58 int (*hw_init)(struct wl1271 *wl);
59 int (*init_vif)(struct wl1271 *wl, struct wl12xx_vif *wlvif);
60 u32 (*sta_get_ap_rate_mask)(struct wl1271 *wl,
61 struct wl12xx_vif *wlvif);
62 s8 (*get_pg_ver)(struct wl1271 *wl);
63 void (*get_mac)(struct wl1271 *wl);
64};
65
66enum wlcore_partitions {
67 PART_DOWN,
68 PART_WORK,
69 PART_BOOT,
70 PART_DRPW,
71 PART_TOP_PRCM_ELP_SOC,
72 PART_PHY_INIT,
73
74 PART_TABLE_LEN,
75};
76
77struct wlcore_partition {
78 u32 size;
79 u32 start;
80};
81
82struct wlcore_partition_set {
83 struct wlcore_partition mem;
84 struct wlcore_partition reg;
85 struct wlcore_partition mem2;
86 struct wlcore_partition mem3;
87};
88
89enum wlcore_registers {
90 /* register addresses, used with partition translation */
91 REG_ECPU_CONTROL,
92 REG_INTERRUPT_NO_CLEAR,
93 REG_INTERRUPT_ACK,
94 REG_COMMAND_MAILBOX_PTR,
95 REG_EVENT_MAILBOX_PTR,
96 REG_INTERRUPT_TRIG,
97 REG_INTERRUPT_MASK,
98 REG_PC_ON_RECOVERY,
99 REG_CHIP_ID_B,
100 REG_CMD_MBOX_ADDRESS,
101
102 /* data access memory addresses, used with partition translation */
103 REG_SLV_MEM_DATA,
104 REG_SLV_REG_DATA,
105
106 /* raw data access memory addresses */
107 REG_RAW_FW_STATUS_ADDR,
108
109 REG_TABLE_LEN,
110};
111
112struct wl1271 {
113 struct ieee80211_hw *hw;
114 bool mac80211_registered;
115
116 struct device *dev;
117
118 void *if_priv;
119
120 struct wl1271_if_operations *if_ops;
121
122 void (*set_power)(bool enable);
123 int irq;
124 int ref_clock;
125
126 spinlock_t wl_lock;
127
128 enum wl1271_state state;
129 enum wl12xx_fw_type fw_type;
130 bool plt;
131 u8 last_vif_count;
132 struct mutex mutex;
133
134 unsigned long flags;
135
136 struct wlcore_partition_set curr_part;
137
138 struct wl1271_chip chip;
139
140 int cmd_box_addr;
141
142 u8 *fw;
143 size_t fw_len;
144 void *nvs;
145 size_t nvs_len;
146
147 s8 hw_pg_ver;
148
149 /* address read from the fuse ROM */
150 u32 fuse_oui_addr;
151 u32 fuse_nic_addr;
152
153 /* we have up to 2 MAC addresses */
154 struct mac_address addresses[2];
155 int channel;
156 u8 system_hlid;
157
158 unsigned long links_map[BITS_TO_LONGS(WL12XX_MAX_LINKS)];
159 unsigned long roles_map[BITS_TO_LONGS(WL12XX_MAX_ROLES)];
160 unsigned long roc_map[BITS_TO_LONGS(WL12XX_MAX_ROLES)];
161 unsigned long rate_policies_map[
162 BITS_TO_LONGS(WL12XX_MAX_RATE_POLICIES)];
163
164 struct list_head wlvif_list;
165
166 u8 sta_count;
167 u8 ap_count;
168
169 struct wl1271_acx_mem_map *target_mem_map;
170
171 /* Accounting for allocated / available TX blocks on HW */
172 u32 tx_blocks_freed;
173 u32 tx_blocks_available;
174 u32 tx_allocated_blocks;
175 u32 tx_results_count;
176
177 /* Accounting for allocated / available Tx packets in HW */
178 u32 tx_pkts_freed[NUM_TX_QUEUES];
179 u32 tx_allocated_pkts[NUM_TX_QUEUES];
180
181 /* Transmitted TX packets counter for chipset interface */
182 u32 tx_packets_count;
183
184 /* Time-offset between host and chipset clocks */
185 s64 time_offset;
186
187 /* Frames scheduled for transmission, not handled yet */
188 int tx_queue_count[NUM_TX_QUEUES];
189 long stopped_queues_map;
190
191 /* Frames received, not handled yet by mac80211 */
192 struct sk_buff_head deferred_rx_queue;
193
194 /* Frames sent, not returned yet to mac80211 */
195 struct sk_buff_head deferred_tx_queue;
196
197 struct work_struct tx_work;
198 struct workqueue_struct *freezable_wq;
199
200 /* Pending TX frames */
201 unsigned long tx_frames_map[BITS_TO_LONGS(WLCORE_MAX_TX_DESCRIPTORS)];
202 struct sk_buff *tx_frames[WLCORE_MAX_TX_DESCRIPTORS];
203 int tx_frames_cnt;
204
205 /* FW Rx counter */
206 u32 rx_counter;
207
208 /* Rx memory pool address */
209 struct wl1271_rx_mem_pool_addr rx_mem_pool_addr;
210
211 /* Intermediate buffer, used for packet aggregation */
212 u8 *aggr_buf;
213
214 /* Reusable dummy packet template */
215 struct sk_buff *dummy_packet;
216
217 /* Network stack work */
218 struct work_struct netstack_work;
219
220 /* FW log buffer */
221 u8 *fwlog;
222
223 /* Number of valid bytes in the FW log buffer */
224 ssize_t fwlog_size;
225
226 /* Sysfs FW log entry readers wait queue */
227 wait_queue_head_t fwlog_waitq;
228
229 /* Hardware recovery work */
230 struct work_struct recovery_work;
231
232 /* Pointer that holds DMA-friendly block for the mailbox */
233 struct event_mailbox *mbox;
234
235 /* The mbox event mask */
236 u32 event_mask;
237
238 /* Mailbox pointers */
239 u32 mbox_ptr[2];
240
241 /* Are we currently scanning */
242 struct ieee80211_vif *scan_vif;
243 struct wl1271_scan scan;
244 struct delayed_work scan_complete_work;
245
246 bool sched_scanning;
247
248 /* The current band */
249 enum ieee80211_band band;
250
251 struct completion *elp_compl;
252 struct delayed_work elp_work;
253
254 /* in dBm */
255 int power_level;
256
257 struct wl1271_stats stats;
258
259 __le32 buffer_32;
260 u32 buffer_cmd;
261 u32 buffer_busyword[WL1271_BUSY_WORD_CNT];
262
263 struct wl_fw_status *fw_status;
264 struct wl1271_tx_hw_res_if *tx_res_if;
265
266 /* Current chipset configuration */
267 struct wlcore_conf conf;
268
269 bool sg_enabled;
270
271 bool enable_11a;
272
273 /* Most recently reported noise in dBm */
274 s8 noise;
275
276 /* bands supported by this instance of wl12xx */
277 struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
278
279 int tcxo_clock;
280
281 /*
282 * wowlan trigger was configured during suspend.
283 * (currently, only "ANY" trigger is supported)
284 */
285 bool wow_enabled;
286 bool irq_wake_enabled;
287
288 /*
289 * AP-mode - links indexed by HLID. The global and broadcast links
290 * are always active.
291 */
292 struct wl1271_link links[WL12XX_MAX_LINKS];
293
294 /* AP-mode - a bitmap of links currently in PS mode according to FW */
295 u32 ap_fw_ps_map;
296
297 /* AP-mode - a bitmap of links currently in PS mode in mac80211 */
298 unsigned long ap_ps_map;
299
300 /* Quirks of specific hardware revisions */
301 unsigned int quirks;
302
303 /* Platform limitations */
304 unsigned int platform_quirks;
305
306 /* number of currently active RX BA sessions */
307 int ba_rx_session_count;
308
309 /* AP-mode - number of currently connected stations */
310 int active_sta_count;
311
312 /* last wlvif we transmitted from */
313 struct wl12xx_vif *last_wlvif;
314
315 /* work to fire when Tx is stuck */
316 struct delayed_work tx_watchdog_work;
317
318 struct wlcore_ops *ops;
319 /* pointer to the lower driver partition table */
320 const struct wlcore_partition_set *ptable;
321 /* pointer to the lower driver register table */
322 const int *rtable;
323 /* name of the firmwares to load - for PLT, single role, multi-role */
324 const char *plt_fw_name;
325 const char *sr_fw_name;
326 const char *mr_fw_name;
327
328 /* per-chip-family private structure */
329 void *priv;
330
331 /* number of TX descriptors the HW supports. */
332 u32 num_tx_desc;
333
334 /* spare Tx blocks for normal/GEM operating modes */
335 u32 normal_tx_spare;
336 u32 gem_tx_spare;
337
338 /* translate HW Tx rates to standard rate-indices */
339 const u8 **band_rate_to_idx;
340
341 /* size of table for HW rates that can be received from chip */
342 u8 hw_tx_rate_tbl_size;
343
344 /* this HW rate and below are considered HT rates for this chip */
345 u8 hw_min_ht_rate;
346
347 /* HW HT (11n) capabilities */
348 struct ieee80211_sta_ht_cap ht_cap;
349
350 /* size of the private FW status data */
351 size_t fw_status_priv_len;
352};
353
354int __devinit wlcore_probe(struct wl1271 *wl, struct platform_device *pdev);
355int __devexit wlcore_remove(struct platform_device *pdev);
356struct ieee80211_hw *wlcore_alloc_hw(size_t priv_size);
357int wlcore_free_hw(struct wl1271 *wl);
358
359/* Firmware image load chunk size */
360#define CHUNK_SIZE 16384
361
362/* Quirks */
363
364/* Each RX/TX transaction requires an end-of-transaction transfer */
365#define WLCORE_QUIRK_END_OF_TRANSACTION BIT(0)
366
367/* wl127x and SPI don't support SDIO block size alignment */
368#define WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN BIT(2)
369
370/* means aggregated Rx packets are aligned to a SDIO block */
371#define WLCORE_QUIRK_RX_BLOCKSIZE_ALIGN BIT(3)
372
373/* Older firmwares did not implement the FW logger over bus feature */
374#define WLCORE_QUIRK_FWLOG_NOT_IMPLEMENTED BIT(4)
375
376/* Older firmwares use an old NVS format */
377#define WLCORE_QUIRK_LEGACY_NVS BIT(5)
378
379/* Some firmwares may not support ELP */
380#define WLCORE_QUIRK_NO_ELP BIT(6)
381
382/* TODO: move to the lower drivers when all usages are abstracted */
383#define CHIP_ID_1271_PG10 (0x4030101)
384#define CHIP_ID_1271_PG20 (0x4030111)
385#define CHIP_ID_1283_PG10 (0x05030101)
386#define CHIP_ID_1283_PG20 (0x05030111)
387
388/* TODO: move all these common registers and values elsewhere */
389#define HW_ACCESS_ELP_CTRL_REG 0x1FFFC
390
391/* ELP register commands */
392#define ELPCTRL_WAKE_UP 0x1
393#define ELPCTRL_WAKE_UP_WLAN_READY 0x5
394#define ELPCTRL_SLEEP 0x0
395/* ELP WLAN_READY bit */
396#define ELPCTRL_WLAN_READY 0x2
397
398/*************************************************************************
399
400 Interrupt Trigger Register (Host -> WiLink)
401
402**************************************************************************/
403
404/* Hardware to Embedded CPU Interrupts - first 32-bit register set */
405
406/*
407 * The host sets this bit to inform the Wlan
408 * FW that a TX packet is in the XFER
409 * Buffer #0.
410 */
411#define INTR_TRIG_TX_PROC0 BIT(2)
412
413/*
414 * The host sets this bit to inform the FW
415 * that it read a packet from RX XFER
416 * Buffer #0.
417 */
418#define INTR_TRIG_RX_PROC0 BIT(3)
419
420#define INTR_TRIG_DEBUG_ACK BIT(4)
421
422#define INTR_TRIG_STATE_CHANGED BIT(5)
423
424/* Hardware to Embedded CPU Interrupts - second 32-bit register set */
425
426/*
427 * The host sets this bit to inform the FW
428 * that it read a packet from RX XFER
429 * Buffer #1.
430 */
431#define INTR_TRIG_RX_PROC1 BIT(17)
432
433/*
434 * The host sets this bit to inform the Wlan
435 * hardware that a TX packet is in the XFER
436 * Buffer #1.
437 */
438#define INTR_TRIG_TX_PROC1 BIT(18)
439
440#define ACX_SLV_SOFT_RESET_BIT BIT(1)
441#define SOFT_RESET_MAX_TIME 1000000
442#define SOFT_RESET_STALL_TIME 1000
443
444#define ECPU_CONTROL_HALT 0x00000101
445
446#define WELP_ARM_COMMAND_VAL 0x4
447
448#endif /* __WLCORE_H__ */