diff options
author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-22 10:38:37 -0500 |
---|---|---|
committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-22 10:38:37 -0500 |
commit | fcc9d2e5a6c89d22b8b773a64fb4ad21ac318446 (patch) | |
tree | a57612d1888735a2ec7972891b68c1ac5ec8faea /drivers/net/wireless/wl12xx | |
parent | 8dea78da5cee153b8af9c07a2745f6c55057fe12 (diff) |
Diffstat (limited to 'drivers/net/wireless/wl12xx')
36 files changed, 20890 insertions, 0 deletions
diff --git a/drivers/net/wireless/wl12xx/Kconfig b/drivers/net/wireless/wl12xx/Kconfig new file mode 100644 index 00000000000..07bcb1548d8 --- /dev/null +++ b/drivers/net/wireless/wl12xx/Kconfig | |||
@@ -0,0 +1,68 @@ | |||
1 | menuconfig WL12XX_MENU | ||
2 | tristate "TI wl12xx driver support" | ||
3 | depends on MAC80211 && EXPERIMENTAL | ||
4 | ---help--- | ||
5 | This will enable TI wl12xx driver support for the following chips: | ||
6 | wl1271, wl1273, wl1281 and wl1283. | ||
7 | The drivers make use of the mac80211 stack. | ||
8 | |||
9 | config WL12XX | ||
10 | tristate "TI wl12xx support" | ||
11 | depends on WL12XX_MENU && GENERIC_HARDIRQS | ||
12 | depends on INET | ||
13 | select FW_LOADER | ||
14 | ---help--- | ||
15 | This module adds support for wireless adapters based on TI wl1271 and | ||
16 | TI wl1273 chipsets. This module does *not* include support for wl1251. | ||
17 | For wl1251 support, use the separate homonymous driver instead. | ||
18 | |||
19 | If you choose to build a module, it will be called wl12xx. Say N if | ||
20 | unsure. | ||
21 | |||
22 | config WL12XX_HT | ||
23 | bool "TI wl12xx 802.11 HT support (EXPERIMENTAL)" | ||
24 | depends on WL12XX && EXPERIMENTAL | ||
25 | default n | ||
26 | ---help--- | ||
27 | This will enable 802.11 HT support in the wl12xx module. | ||
28 | |||
29 | That configuration is temporary due to the code incomplete and | ||
30 | still in testing process. | ||
31 | |||
32 | config WL12XX_SPI | ||
33 | tristate "TI wl12xx SPI support" | ||
34 | depends on WL12XX && SPI_MASTER | ||
35 | select CRC7 | ||
36 | ---help--- | ||
37 | This module adds support for the SPI interface of adapters using | ||
38 | TI wl12xx chipsets. Select this if your platform is using | ||
39 | the SPI bus. | ||
40 | |||
41 | If you choose to build a module, it'll be called wl12xx_spi. | ||
42 | Say N if unsure. | ||
43 | |||
44 | config WL12XX_SDIO | ||
45 | tristate "TI wl12xx SDIO support" | ||
46 | depends on WL12XX && MMC | ||
47 | ---help--- | ||
48 | This module adds support for the SDIO interface of adapters using | ||
49 | TI wl12xx chipsets. Select this if your platform is using | ||
50 | the SDIO bus. | ||
51 | |||
52 | If you choose to build a module, it'll be called wl12xx_sdio. | ||
53 | Say N if unsure. | ||
54 | |||
55 | config WL12XX_SDIO_TEST | ||
56 | tristate "TI wl12xx SDIO testing support" | ||
57 | depends on WL12XX && MMC && WL12XX_SDIO | ||
58 | default n | ||
59 | ---help--- | ||
60 | This module adds support for the SDIO bus testing with the | ||
61 | TI wl12xx chipsets. You probably don't want this unless you are | ||
62 | testing a new hardware platform. Select this if you want to test the | ||
63 | SDIO bus which is connected to the wl12xx chip. | ||
64 | |||
65 | config WL12XX_PLATFORM_DATA | ||
66 | bool | ||
67 | depends on WL12XX_SDIO != n || WL1251_SDIO != n | ||
68 | default y | ||
diff --git a/drivers/net/wireless/wl12xx/Makefile b/drivers/net/wireless/wl12xx/Makefile new file mode 100644 index 00000000000..521c0414e52 --- /dev/null +++ b/drivers/net/wireless/wl12xx/Makefile | |||
@@ -0,0 +1,16 @@ | |||
1 | wl12xx-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 | |||
4 | wl12xx_spi-objs = spi.o | ||
5 | wl12xx_sdio-objs = sdio.o | ||
6 | wl12xx_sdio_test-objs = sdio_test.o | ||
7 | |||
8 | wl12xx-$(CONFIG_NL80211_TESTMODE) += testmode.o | ||
9 | obj-$(CONFIG_WL12XX) += wl12xx.o | ||
10 | obj-$(CONFIG_WL12XX_SPI) += wl12xx_spi.o | ||
11 | obj-$(CONFIG_WL12XX_SDIO) += wl12xx_sdio.o | ||
12 | |||
13 | obj-$(CONFIG_WL12XX_SDIO_TEST) += wl12xx_sdio_test.o | ||
14 | |||
15 | # small builtin driver bit | ||
16 | obj-$(CONFIG_WL12XX_PLATFORM_DATA) += wl12xx_platform_data.o | ||
diff --git a/drivers/net/wireless/wl12xx/acx.c b/drivers/net/wireless/wl12xx/acx.c new file mode 100644 index 00000000000..34f6ab53e51 --- /dev/null +++ b/drivers/net/wireless/wl12xx/acx.c | |||
@@ -0,0 +1,1765 @@ | |||
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 "wl12xx.h" | ||
32 | #include "wl12xx_80211.h" | ||
33 | #include "reg.h" | ||
34 | #include "ps.h" | ||
35 | |||
36 | int wl1271_acx_wake_up_conditions(struct wl1271 *wl) | ||
37 | { | ||
38 | struct acx_wake_up_condition *wake_up; | ||
39 | int ret; | ||
40 | |||
41 | wl1271_debug(DEBUG_ACX, "acx wake up conditions"); | ||
42 | |||
43 | wake_up = kzalloc(sizeof(*wake_up), GFP_KERNEL); | ||
44 | if (!wake_up) { | ||
45 | ret = -ENOMEM; | ||
46 | goto out; | ||
47 | } | ||
48 | |||
49 | wake_up->wake_up_event = wl->conf.conn.wake_up_event; | ||
50 | wake_up->listen_interval = wl->conf.conn.listen_interval; | ||
51 | |||
52 | ret = wl1271_cmd_configure(wl, ACX_WAKE_UP_CONDITIONS, | ||
53 | wake_up, sizeof(*wake_up)); | ||
54 | if (ret < 0) { | ||
55 | wl1271_warning("could not set wake up conditions: %d", ret); | ||
56 | goto out; | ||
57 | } | ||
58 | |||
59 | out: | ||
60 | kfree(wake_up); | ||
61 | return ret; | ||
62 | } | ||
63 | |||
64 | int wl1271_acx_sleep_auth(struct wl1271 *wl, u8 sleep_auth) | ||
65 | { | ||
66 | struct acx_sleep_auth *auth; | ||
67 | int ret; | ||
68 | |||
69 | wl1271_debug(DEBUG_ACX, "acx sleep auth"); | ||
70 | |||
71 | auth = kzalloc(sizeof(*auth), GFP_KERNEL); | ||
72 | if (!auth) { | ||
73 | ret = -ENOMEM; | ||
74 | goto out; | ||
75 | } | ||
76 | |||
77 | auth->sleep_auth = sleep_auth; | ||
78 | |||
79 | ret = wl1271_cmd_configure(wl, ACX_SLEEP_AUTH, auth, sizeof(*auth)); | ||
80 | |||
81 | out: | ||
82 | kfree(auth); | ||
83 | return ret; | ||
84 | } | ||
85 | |||
86 | int wl1271_acx_tx_power(struct wl1271 *wl, int power) | ||
87 | { | ||
88 | struct acx_current_tx_power *acx; | ||
89 | int ret; | ||
90 | |||
91 | wl1271_debug(DEBUG_ACX, "acx dot11_cur_tx_pwr %d", power); | ||
92 | |||
93 | if (power < 0 || power > 25) | ||
94 | return -EINVAL; | ||
95 | |||
96 | acx = kzalloc(sizeof(*acx), GFP_KERNEL); | ||
97 | if (!acx) { | ||
98 | ret = -ENOMEM; | ||
99 | goto out; | ||
100 | } | ||
101 | |||
102 | acx->current_tx_power = power * 10; | ||
103 | |||
104 | ret = wl1271_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx)); | ||
105 | if (ret < 0) { | ||
106 | wl1271_warning("configure of tx power failed: %d", ret); | ||
107 | goto out; | ||
108 | } | ||
109 | |||
110 | out: | ||
111 | kfree(acx); | ||
112 | return ret; | ||
113 | } | ||
114 | |||
115 | int wl1271_acx_feature_cfg(struct wl1271 *wl) | ||
116 | { | ||
117 | struct acx_feature_config *feature; | ||
118 | int ret; | ||
119 | |||
120 | wl1271_debug(DEBUG_ACX, "acx feature cfg"); | ||
121 | |||
122 | feature = kzalloc(sizeof(*feature), GFP_KERNEL); | ||
123 | if (!feature) { | ||
124 | ret = -ENOMEM; | ||
125 | goto out; | ||
126 | } | ||
127 | |||
128 | /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */ | ||
129 | feature->data_flow_options = 0; | ||
130 | feature->options = 0; | ||
131 | |||
132 | ret = wl1271_cmd_configure(wl, ACX_FEATURE_CFG, | ||
133 | feature, sizeof(*feature)); | ||
134 | if (ret < 0) { | ||
135 | wl1271_error("Couldnt set HW encryption"); | ||
136 | goto out; | ||
137 | } | ||
138 | |||
139 | out: | ||
140 | kfree(feature); | ||
141 | return ret; | ||
142 | } | ||
143 | |||
144 | int wl1271_acx_mem_map(struct wl1271 *wl, struct acx_header *mem_map, | ||
145 | size_t len) | ||
146 | { | ||
147 | int ret; | ||
148 | |||
149 | wl1271_debug(DEBUG_ACX, "acx mem map"); | ||
150 | |||
151 | ret = wl1271_cmd_interrogate(wl, ACX_MEM_MAP, mem_map, len); | ||
152 | if (ret < 0) | ||
153 | return ret; | ||
154 | |||
155 | return 0; | ||
156 | } | ||
157 | |||
158 | int wl1271_acx_rx_msdu_life_time(struct wl1271 *wl) | ||
159 | { | ||
160 | struct acx_rx_msdu_lifetime *acx; | ||
161 | int ret; | ||
162 | |||
163 | wl1271_debug(DEBUG_ACX, "acx rx msdu life time"); | ||
164 | |||
165 | acx = kzalloc(sizeof(*acx), GFP_KERNEL); | ||
166 | if (!acx) { | ||
167 | ret = -ENOMEM; | ||
168 | goto out; | ||
169 | } | ||
170 | |||
171 | acx->lifetime = cpu_to_le32(wl->conf.rx.rx_msdu_life_time); | ||
172 | ret = wl1271_cmd_configure(wl, DOT11_RX_MSDU_LIFE_TIME, | ||
173 | acx, sizeof(*acx)); | ||
174 | if (ret < 0) { | ||
175 | wl1271_warning("failed to set rx msdu life time: %d", ret); | ||
176 | goto out; | ||
177 | } | ||
178 | |||
179 | out: | ||
180 | kfree(acx); | ||
181 | return ret; | ||
182 | } | ||
183 | |||
184 | int wl1271_acx_rx_config(struct wl1271 *wl, u32 config, u32 filter) | ||
185 | { | ||
186 | struct acx_rx_config *rx_config; | ||
187 | int ret; | ||
188 | |||
189 | wl1271_debug(DEBUG_ACX, "acx rx config"); | ||
190 | |||
191 | rx_config = kzalloc(sizeof(*rx_config), GFP_KERNEL); | ||
192 | if (!rx_config) { | ||
193 | ret = -ENOMEM; | ||
194 | goto out; | ||
195 | } | ||
196 | |||
197 | rx_config->config_options = cpu_to_le32(config); | ||
198 | rx_config->filter_options = cpu_to_le32(filter); | ||
199 | |||
200 | ret = wl1271_cmd_configure(wl, ACX_RX_CFG, | ||
201 | rx_config, sizeof(*rx_config)); | ||
202 | if (ret < 0) { | ||
203 | wl1271_warning("failed to set rx config: %d", ret); | ||
204 | goto out; | ||
205 | } | ||
206 | |||
207 | out: | ||
208 | kfree(rx_config); | ||
209 | return ret; | ||
210 | } | ||
211 | |||
212 | int wl1271_acx_pd_threshold(struct wl1271 *wl) | ||
213 | { | ||
214 | struct acx_packet_detection *pd; | ||
215 | int ret; | ||
216 | |||
217 | wl1271_debug(DEBUG_ACX, "acx data pd threshold"); | ||
218 | |||
219 | pd = kzalloc(sizeof(*pd), GFP_KERNEL); | ||
220 | if (!pd) { | ||
221 | ret = -ENOMEM; | ||
222 | goto out; | ||
223 | } | ||
224 | |||
225 | pd->threshold = cpu_to_le32(wl->conf.rx.packet_detection_threshold); | ||
226 | |||
227 | ret = wl1271_cmd_configure(wl, ACX_PD_THRESHOLD, pd, sizeof(*pd)); | ||
228 | if (ret < 0) { | ||
229 | wl1271_warning("failed to set pd threshold: %d", ret); | ||
230 | goto out; | ||
231 | } | ||
232 | |||
233 | out: | ||
234 | kfree(pd); | ||
235 | return ret; | ||
236 | } | ||
237 | |||
238 | int wl1271_acx_slot(struct wl1271 *wl, enum acx_slot_type slot_time) | ||
239 | { | ||
240 | struct acx_slot *slot; | ||
241 | int ret; | ||
242 | |||
243 | wl1271_debug(DEBUG_ACX, "acx slot"); | ||
244 | |||
245 | slot = kzalloc(sizeof(*slot), GFP_KERNEL); | ||
246 | if (!slot) { | ||
247 | ret = -ENOMEM; | ||
248 | goto out; | ||
249 | } | ||
250 | |||
251 | slot->wone_index = STATION_WONE_INDEX; | ||
252 | slot->slot_time = slot_time; | ||
253 | |||
254 | ret = wl1271_cmd_configure(wl, ACX_SLOT, slot, sizeof(*slot)); | ||
255 | if (ret < 0) { | ||
256 | wl1271_warning("failed to set slot time: %d", ret); | ||
257 | goto out; | ||
258 | } | ||
259 | |||
260 | out: | ||
261 | kfree(slot); | ||
262 | return ret; | ||
263 | } | ||
264 | |||
265 | int wl1271_acx_group_address_tbl(struct wl1271 *wl, bool enable, | ||
266 | void *mc_list, u32 mc_list_len) | ||
267 | { | ||
268 | struct acx_dot11_grp_addr_tbl *acx; | ||
269 | int ret; | ||
270 | |||
271 | wl1271_debug(DEBUG_ACX, "acx group address tbl"); | ||
272 | |||
273 | acx = kzalloc(sizeof(*acx), GFP_KERNEL); | ||
274 | if (!acx) { | ||
275 | ret = -ENOMEM; | ||
276 | goto out; | ||
277 | } | ||
278 | |||
279 | /* MAC filtering */ | ||
280 | acx->enabled = enable; | ||
281 | acx->num_groups = mc_list_len; | ||
282 | memcpy(acx->mac_table, mc_list, mc_list_len * ETH_ALEN); | ||
283 | |||
284 | ret = wl1271_cmd_configure(wl, DOT11_GROUP_ADDRESS_TBL, | ||
285 | acx, sizeof(*acx)); | ||
286 | if (ret < 0) { | ||
287 | wl1271_warning("failed to set group addr table: %d", ret); | ||
288 | goto out; | ||
289 | } | ||
290 | |||
291 | out: | ||
292 | kfree(acx); | ||
293 | return ret; | ||
294 | } | ||
295 | |||
296 | int wl1271_acx_service_period_timeout(struct wl1271 *wl) | ||
297 | { | ||
298 | struct acx_rx_timeout *rx_timeout; | ||
299 | int ret; | ||
300 | |||
301 | rx_timeout = kzalloc(sizeof(*rx_timeout), GFP_KERNEL); | ||
302 | if (!rx_timeout) { | ||
303 | ret = -ENOMEM; | ||
304 | goto out; | ||
305 | } | ||
306 | |||
307 | wl1271_debug(DEBUG_ACX, "acx service period timeout"); | ||
308 | |||
309 | rx_timeout->ps_poll_timeout = cpu_to_le16(wl->conf.rx.ps_poll_timeout); | ||
310 | rx_timeout->upsd_timeout = cpu_to_le16(wl->conf.rx.upsd_timeout); | ||
311 | |||
312 | ret = wl1271_cmd_configure(wl, ACX_SERVICE_PERIOD_TIMEOUT, | ||
313 | rx_timeout, sizeof(*rx_timeout)); | ||
314 | if (ret < 0) { | ||
315 | wl1271_warning("failed to set service period timeout: %d", | ||
316 | ret); | ||
317 | goto out; | ||
318 | } | ||
319 | |||
320 | out: | ||
321 | kfree(rx_timeout); | ||
322 | return ret; | ||
323 | } | ||
324 | |||
325 | int wl1271_acx_rts_threshold(struct wl1271 *wl, u32 rts_threshold) | ||
326 | { | ||
327 | struct acx_rts_threshold *rts; | ||
328 | int ret; | ||
329 | |||
330 | /* | ||
331 | * If the RTS threshold is not configured or out of range, use the | ||
332 | * default value. | ||
333 | */ | ||
334 | if (rts_threshold > IEEE80211_MAX_RTS_THRESHOLD) | ||
335 | rts_threshold = wl->conf.rx.rts_threshold; | ||
336 | |||
337 | wl1271_debug(DEBUG_ACX, "acx rts threshold: %d", rts_threshold); | ||
338 | |||
339 | rts = kzalloc(sizeof(*rts), GFP_KERNEL); | ||
340 | if (!rts) { | ||
341 | ret = -ENOMEM; | ||
342 | goto out; | ||
343 | } | ||
344 | |||
345 | rts->threshold = cpu_to_le16((u16)rts_threshold); | ||
346 | |||
347 | ret = wl1271_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts)); | ||
348 | if (ret < 0) { | ||
349 | wl1271_warning("failed to set rts threshold: %d", ret); | ||
350 | goto out; | ||
351 | } | ||
352 | |||
353 | out: | ||
354 | kfree(rts); | ||
355 | return ret; | ||
356 | } | ||
357 | |||
358 | int wl1271_acx_dco_itrim_params(struct wl1271 *wl) | ||
359 | { | ||
360 | struct acx_dco_itrim_params *dco; | ||
361 | struct conf_itrim_settings *c = &wl->conf.itrim; | ||
362 | int ret; | ||
363 | |||
364 | wl1271_debug(DEBUG_ACX, "acx dco itrim parameters"); | ||
365 | |||
366 | dco = kzalloc(sizeof(*dco), GFP_KERNEL); | ||
367 | if (!dco) { | ||
368 | ret = -ENOMEM; | ||
369 | goto out; | ||
370 | } | ||
371 | |||
372 | dco->enable = c->enable; | ||
373 | dco->timeout = cpu_to_le32(c->timeout); | ||
374 | |||
375 | ret = wl1271_cmd_configure(wl, ACX_SET_DCO_ITRIM_PARAMS, | ||
376 | dco, sizeof(*dco)); | ||
377 | if (ret < 0) { | ||
378 | wl1271_warning("failed to set dco itrim parameters: %d", ret); | ||
379 | goto out; | ||
380 | } | ||
381 | |||
382 | out: | ||
383 | kfree(dco); | ||
384 | return ret; | ||
385 | } | ||
386 | |||
387 | int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, bool enable_filter) | ||
388 | { | ||
389 | struct acx_beacon_filter_option *beacon_filter = NULL; | ||
390 | int ret = 0; | ||
391 | |||
392 | wl1271_debug(DEBUG_ACX, "acx beacon filter opt"); | ||
393 | |||
394 | if (enable_filter && | ||
395 | wl->conf.conn.bcn_filt_mode == CONF_BCN_FILT_MODE_DISABLED) | ||
396 | goto out; | ||
397 | |||
398 | beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL); | ||
399 | if (!beacon_filter) { | ||
400 | ret = -ENOMEM; | ||
401 | goto out; | ||
402 | } | ||
403 | |||
404 | beacon_filter->enable = enable_filter; | ||
405 | |||
406 | /* | ||
407 | * When set to zero, and the filter is enabled, beacons | ||
408 | * without the unicast TIM bit set are dropped. | ||
409 | */ | ||
410 | beacon_filter->max_num_beacons = 0; | ||
411 | |||
412 | ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_OPT, | ||
413 | beacon_filter, sizeof(*beacon_filter)); | ||
414 | if (ret < 0) { | ||
415 | wl1271_warning("failed to set beacon filter opt: %d", ret); | ||
416 | goto out; | ||
417 | } | ||
418 | |||
419 | out: | ||
420 | kfree(beacon_filter); | ||
421 | return ret; | ||
422 | } | ||
423 | |||
424 | int wl1271_acx_beacon_filter_table(struct wl1271 *wl) | ||
425 | { | ||
426 | struct acx_beacon_filter_ie_table *ie_table; | ||
427 | int i, idx = 0; | ||
428 | int ret; | ||
429 | bool vendor_spec = false; | ||
430 | |||
431 | wl1271_debug(DEBUG_ACX, "acx beacon filter table"); | ||
432 | |||
433 | ie_table = kzalloc(sizeof(*ie_table), GFP_KERNEL); | ||
434 | if (!ie_table) { | ||
435 | ret = -ENOMEM; | ||
436 | goto out; | ||
437 | } | ||
438 | |||
439 | /* configure default beacon pass-through rules */ | ||
440 | ie_table->num_ie = 0; | ||
441 | for (i = 0; i < wl->conf.conn.bcn_filt_ie_count; i++) { | ||
442 | struct conf_bcn_filt_rule *r = &(wl->conf.conn.bcn_filt_ie[i]); | ||
443 | ie_table->table[idx++] = r->ie; | ||
444 | ie_table->table[idx++] = r->rule; | ||
445 | |||
446 | if (r->ie == WLAN_EID_VENDOR_SPECIFIC) { | ||
447 | /* only one vendor specific ie allowed */ | ||
448 | if (vendor_spec) | ||
449 | continue; | ||
450 | |||
451 | /* for vendor specific rules configure the | ||
452 | additional fields */ | ||
453 | memcpy(&(ie_table->table[idx]), r->oui, | ||
454 | CONF_BCN_IE_OUI_LEN); | ||
455 | idx += CONF_BCN_IE_OUI_LEN; | ||
456 | ie_table->table[idx++] = r->type; | ||
457 | memcpy(&(ie_table->table[idx]), r->version, | ||
458 | CONF_BCN_IE_VER_LEN); | ||
459 | idx += CONF_BCN_IE_VER_LEN; | ||
460 | vendor_spec = true; | ||
461 | } | ||
462 | |||
463 | ie_table->num_ie++; | ||
464 | } | ||
465 | |||
466 | ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_TABLE, | ||
467 | ie_table, sizeof(*ie_table)); | ||
468 | if (ret < 0) { | ||
469 | wl1271_warning("failed to set beacon filter table: %d", ret); | ||
470 | goto out; | ||
471 | } | ||
472 | |||
473 | out: | ||
474 | kfree(ie_table); | ||
475 | return ret; | ||
476 | } | ||
477 | |||
478 | #define ACX_CONN_MONIT_DISABLE_VALUE 0xffffffff | ||
479 | |||
480 | int wl1271_acx_conn_monit_params(struct wl1271 *wl, bool enable) | ||
481 | { | ||
482 | struct acx_conn_monit_params *acx; | ||
483 | u32 threshold = ACX_CONN_MONIT_DISABLE_VALUE; | ||
484 | u32 timeout = ACX_CONN_MONIT_DISABLE_VALUE; | ||
485 | int ret; | ||
486 | |||
487 | wl1271_debug(DEBUG_ACX, "acx connection monitor parameters: %s", | ||
488 | enable ? "enabled" : "disabled"); | ||
489 | |||
490 | acx = kzalloc(sizeof(*acx), GFP_KERNEL); | ||
491 | if (!acx) { | ||
492 | ret = -ENOMEM; | ||
493 | goto out; | ||
494 | } | ||
495 | |||
496 | if (enable) { | ||
497 | threshold = wl->conf.conn.synch_fail_thold; | ||
498 | timeout = wl->conf.conn.bss_lose_timeout; | ||
499 | } | ||
500 | |||
501 | acx->synch_fail_thold = cpu_to_le32(threshold); | ||
502 | acx->bss_lose_timeout = cpu_to_le32(timeout); | ||
503 | |||
504 | ret = wl1271_cmd_configure(wl, ACX_CONN_MONIT_PARAMS, | ||
505 | acx, sizeof(*acx)); | ||
506 | if (ret < 0) { | ||
507 | wl1271_warning("failed to set connection monitor " | ||
508 | "parameters: %d", ret); | ||
509 | goto out; | ||
510 | } | ||
511 | |||
512 | out: | ||
513 | kfree(acx); | ||
514 | return ret; | ||
515 | } | ||
516 | |||
517 | |||
518 | int wl1271_acx_sg_enable(struct wl1271 *wl, bool enable) | ||
519 | { | ||
520 | struct acx_bt_wlan_coex *pta; | ||
521 | int ret; | ||
522 | |||
523 | wl1271_debug(DEBUG_ACX, "acx sg enable"); | ||
524 | |||
525 | pta = kzalloc(sizeof(*pta), GFP_KERNEL); | ||
526 | if (!pta) { | ||
527 | ret = -ENOMEM; | ||
528 | goto out; | ||
529 | } | ||
530 | |||
531 | if (enable) | ||
532 | pta->enable = wl->conf.sg.state; | ||
533 | else | ||
534 | pta->enable = CONF_SG_DISABLE; | ||
535 | |||
536 | ret = wl1271_cmd_configure(wl, ACX_SG_ENABLE, pta, sizeof(*pta)); | ||
537 | if (ret < 0) { | ||
538 | wl1271_warning("failed to set softgemini enable: %d", ret); | ||
539 | goto out; | ||
540 | } | ||
541 | |||
542 | out: | ||
543 | kfree(pta); | ||
544 | return ret; | ||
545 | } | ||
546 | |||
547 | int wl1271_acx_sta_sg_cfg(struct wl1271 *wl) | ||
548 | { | ||
549 | struct acx_sta_bt_wlan_coex_param *param; | ||
550 | struct conf_sg_settings *c = &wl->conf.sg; | ||
551 | int i, ret; | ||
552 | |||
553 | wl1271_debug(DEBUG_ACX, "acx sg sta cfg"); | ||
554 | |||
555 | param = kzalloc(sizeof(*param), GFP_KERNEL); | ||
556 | if (!param) { | ||
557 | ret = -ENOMEM; | ||
558 | goto out; | ||
559 | } | ||
560 | |||
561 | /* BT-WLAN coext parameters */ | ||
562 | for (i = 0; i < CONF_SG_STA_PARAMS_MAX; i++) | ||
563 | param->params[i] = cpu_to_le32(c->sta_params[i]); | ||
564 | param->param_idx = CONF_SG_PARAMS_ALL; | ||
565 | |||
566 | ret = wl1271_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param)); | ||
567 | if (ret < 0) { | ||
568 | wl1271_warning("failed to set sg config: %d", ret); | ||
569 | goto out; | ||
570 | } | ||
571 | |||
572 | out: | ||
573 | kfree(param); | ||
574 | return ret; | ||
575 | } | ||
576 | |||
577 | int wl1271_acx_ap_sg_cfg(struct wl1271 *wl) | ||
578 | { | ||
579 | struct acx_ap_bt_wlan_coex_param *param; | ||
580 | struct conf_sg_settings *c = &wl->conf.sg; | ||
581 | int i, ret; | ||
582 | |||
583 | wl1271_debug(DEBUG_ACX, "acx sg ap cfg"); | ||
584 | |||
585 | param = kzalloc(sizeof(*param), GFP_KERNEL); | ||
586 | if (!param) { | ||
587 | ret = -ENOMEM; | ||
588 | goto out; | ||
589 | } | ||
590 | |||
591 | /* BT-WLAN coext parameters */ | ||
592 | for (i = 0; i < CONF_SG_AP_PARAMS_MAX; i++) | ||
593 | param->params[i] = cpu_to_le32(c->ap_params[i]); | ||
594 | param->param_idx = CONF_SG_PARAMS_ALL; | ||
595 | |||
596 | ret = wl1271_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param)); | ||
597 | if (ret < 0) { | ||
598 | wl1271_warning("failed to set sg config: %d", ret); | ||
599 | goto out; | ||
600 | } | ||
601 | |||
602 | out: | ||
603 | kfree(param); | ||
604 | return ret; | ||
605 | } | ||
606 | |||
607 | int wl1271_acx_cca_threshold(struct wl1271 *wl) | ||
608 | { | ||
609 | struct acx_energy_detection *detection; | ||
610 | int ret; | ||
611 | |||
612 | wl1271_debug(DEBUG_ACX, "acx cca threshold"); | ||
613 | |||
614 | detection = kzalloc(sizeof(*detection), GFP_KERNEL); | ||
615 | if (!detection) { | ||
616 | ret = -ENOMEM; | ||
617 | goto out; | ||
618 | } | ||
619 | |||
620 | detection->rx_cca_threshold = cpu_to_le16(wl->conf.rx.rx_cca_threshold); | ||
621 | detection->tx_energy_detection = wl->conf.tx.tx_energy_detection; | ||
622 | |||
623 | ret = wl1271_cmd_configure(wl, ACX_CCA_THRESHOLD, | ||
624 | detection, sizeof(*detection)); | ||
625 | if (ret < 0) | ||
626 | wl1271_warning("failed to set cca threshold: %d", ret); | ||
627 | |||
628 | out: | ||
629 | kfree(detection); | ||
630 | return ret; | ||
631 | } | ||
632 | |||
633 | int wl1271_acx_bcn_dtim_options(struct wl1271 *wl) | ||
634 | { | ||
635 | struct acx_beacon_broadcast *bb; | ||
636 | int ret; | ||
637 | |||
638 | wl1271_debug(DEBUG_ACX, "acx bcn dtim options"); | ||
639 | |||
640 | bb = kzalloc(sizeof(*bb), GFP_KERNEL); | ||
641 | if (!bb) { | ||
642 | ret = -ENOMEM; | ||
643 | goto out; | ||
644 | } | ||
645 | |||
646 | bb->beacon_rx_timeout = cpu_to_le16(wl->conf.conn.beacon_rx_timeout); | ||
647 | bb->broadcast_timeout = cpu_to_le16(wl->conf.conn.broadcast_timeout); | ||
648 | bb->rx_broadcast_in_ps = wl->conf.conn.rx_broadcast_in_ps; | ||
649 | bb->ps_poll_threshold = wl->conf.conn.ps_poll_threshold; | ||
650 | |||
651 | ret = wl1271_cmd_configure(wl, ACX_BCN_DTIM_OPTIONS, bb, sizeof(*bb)); | ||
652 | if (ret < 0) { | ||
653 | wl1271_warning("failed to set rx config: %d", ret); | ||
654 | goto out; | ||
655 | } | ||
656 | |||
657 | out: | ||
658 | kfree(bb); | ||
659 | return ret; | ||
660 | } | ||
661 | |||
662 | int wl1271_acx_aid(struct wl1271 *wl, u16 aid) | ||
663 | { | ||
664 | struct acx_aid *acx_aid; | ||
665 | int ret; | ||
666 | |||
667 | wl1271_debug(DEBUG_ACX, "acx aid"); | ||
668 | |||
669 | acx_aid = kzalloc(sizeof(*acx_aid), GFP_KERNEL); | ||
670 | if (!acx_aid) { | ||
671 | ret = -ENOMEM; | ||
672 | goto out; | ||
673 | } | ||
674 | |||
675 | acx_aid->aid = cpu_to_le16(aid); | ||
676 | |||
677 | ret = wl1271_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid)); | ||
678 | if (ret < 0) { | ||
679 | wl1271_warning("failed to set aid: %d", ret); | ||
680 | goto out; | ||
681 | } | ||
682 | |||
683 | out: | ||
684 | kfree(acx_aid); | ||
685 | return ret; | ||
686 | } | ||
687 | |||
688 | int wl1271_acx_event_mbox_mask(struct wl1271 *wl, u32 event_mask) | ||
689 | { | ||
690 | struct acx_event_mask *mask; | ||
691 | int ret; | ||
692 | |||
693 | wl1271_debug(DEBUG_ACX, "acx event mbox mask"); | ||
694 | |||
695 | mask = kzalloc(sizeof(*mask), GFP_KERNEL); | ||
696 | if (!mask) { | ||
697 | ret = -ENOMEM; | ||
698 | goto out; | ||
699 | } | ||
700 | |||
701 | /* high event mask is unused */ | ||
702 | mask->high_event_mask = cpu_to_le32(0xffffffff); | ||
703 | mask->event_mask = cpu_to_le32(event_mask); | ||
704 | |||
705 | ret = wl1271_cmd_configure(wl, ACX_EVENT_MBOX_MASK, | ||
706 | mask, sizeof(*mask)); | ||
707 | if (ret < 0) { | ||
708 | wl1271_warning("failed to set acx_event_mbox_mask: %d", ret); | ||
709 | goto out; | ||
710 | } | ||
711 | |||
712 | out: | ||
713 | kfree(mask); | ||
714 | return ret; | ||
715 | } | ||
716 | |||
717 | int wl1271_acx_set_preamble(struct wl1271 *wl, enum acx_preamble_type preamble) | ||
718 | { | ||
719 | struct acx_preamble *acx; | ||
720 | int ret; | ||
721 | |||
722 | wl1271_debug(DEBUG_ACX, "acx_set_preamble"); | ||
723 | |||
724 | acx = kzalloc(sizeof(*acx), GFP_KERNEL); | ||
725 | if (!acx) { | ||
726 | ret = -ENOMEM; | ||
727 | goto out; | ||
728 | } | ||
729 | |||
730 | acx->preamble = preamble; | ||
731 | |||
732 | ret = wl1271_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx)); | ||
733 | if (ret < 0) { | ||
734 | wl1271_warning("Setting of preamble failed: %d", ret); | ||
735 | goto out; | ||
736 | } | ||
737 | |||
738 | out: | ||
739 | kfree(acx); | ||
740 | return ret; | ||
741 | } | ||
742 | |||
743 | int wl1271_acx_cts_protect(struct wl1271 *wl, | ||
744 | enum acx_ctsprotect_type ctsprotect) | ||
745 | { | ||
746 | struct acx_ctsprotect *acx; | ||
747 | int ret; | ||
748 | |||
749 | wl1271_debug(DEBUG_ACX, "acx_set_ctsprotect"); | ||
750 | |||
751 | acx = kzalloc(sizeof(*acx), GFP_KERNEL); | ||
752 | if (!acx) { | ||
753 | ret = -ENOMEM; | ||
754 | goto out; | ||
755 | } | ||
756 | |||
757 | acx->ctsprotect = ctsprotect; | ||
758 | |||
759 | ret = wl1271_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx)); | ||
760 | if (ret < 0) { | ||
761 | wl1271_warning("Setting of ctsprotect failed: %d", ret); | ||
762 | goto out; | ||
763 | } | ||
764 | |||
765 | out: | ||
766 | kfree(acx); | ||
767 | return ret; | ||
768 | } | ||
769 | |||
770 | int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats) | ||
771 | { | ||
772 | int ret; | ||
773 | |||
774 | wl1271_debug(DEBUG_ACX, "acx statistics"); | ||
775 | |||
776 | ret = wl1271_cmd_interrogate(wl, ACX_STATISTICS, stats, | ||
777 | sizeof(*stats)); | ||
778 | if (ret < 0) { | ||
779 | wl1271_warning("acx statistics failed: %d", ret); | ||
780 | return -ENOMEM; | ||
781 | } | ||
782 | |||
783 | return 0; | ||
784 | } | ||
785 | |||
786 | int wl1271_acx_sta_rate_policies(struct wl1271 *wl) | ||
787 | { | ||
788 | struct acx_sta_rate_policy *acx; | ||
789 | struct conf_tx_rate_class *c = &wl->conf.tx.sta_rc_conf; | ||
790 | int idx = 0; | ||
791 | int ret = 0; | ||
792 | |||
793 | wl1271_debug(DEBUG_ACX, "acx rate policies"); | ||
794 | |||
795 | acx = kzalloc(sizeof(*acx), GFP_KERNEL); | ||
796 | |||
797 | if (!acx) { | ||
798 | ret = -ENOMEM; | ||
799 | goto out; | ||
800 | } | ||
801 | |||
802 | /* configure one basic rate class */ | ||
803 | idx = ACX_TX_BASIC_RATE; | ||
804 | acx->rate_class[idx].enabled_rates = cpu_to_le32(wl->basic_rate); | ||
805 | acx->rate_class[idx].short_retry_limit = c->short_retry_limit; | ||
806 | acx->rate_class[idx].long_retry_limit = c->long_retry_limit; | ||
807 | acx->rate_class[idx].aflags = c->aflags; | ||
808 | |||
809 | /* configure one AP supported rate class */ | ||
810 | idx = ACX_TX_AP_FULL_RATE; | ||
811 | acx->rate_class[idx].enabled_rates = cpu_to_le32(wl->rate_set); | ||
812 | acx->rate_class[idx].short_retry_limit = c->short_retry_limit; | ||
813 | acx->rate_class[idx].long_retry_limit = c->long_retry_limit; | ||
814 | acx->rate_class[idx].aflags = c->aflags; | ||
815 | |||
816 | acx->rate_class_cnt = cpu_to_le32(ACX_TX_RATE_POLICY_CNT); | ||
817 | |||
818 | wl1271_debug(DEBUG_ACX, "basic_rate: 0x%x, full_rate: 0x%x", | ||
819 | acx->rate_class[ACX_TX_BASIC_RATE].enabled_rates, | ||
820 | acx->rate_class[ACX_TX_AP_FULL_RATE].enabled_rates); | ||
821 | |||
822 | ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx)); | ||
823 | if (ret < 0) { | ||
824 | wl1271_warning("Setting of rate policies failed: %d", ret); | ||
825 | goto out; | ||
826 | } | ||
827 | |||
828 | out: | ||
829 | kfree(acx); | ||
830 | return ret; | ||
831 | } | ||
832 | |||
833 | int wl1271_acx_ap_rate_policy(struct wl1271 *wl, struct conf_tx_rate_class *c, | ||
834 | u8 idx) | ||
835 | { | ||
836 | struct acx_ap_rate_policy *acx; | ||
837 | int ret = 0; | ||
838 | |||
839 | wl1271_debug(DEBUG_ACX, "acx ap rate policy %d rates 0x%x", | ||
840 | idx, c->enabled_rates); | ||
841 | |||
842 | acx = kzalloc(sizeof(*acx), GFP_KERNEL); | ||
843 | if (!acx) { | ||
844 | ret = -ENOMEM; | ||
845 | goto out; | ||
846 | } | ||
847 | |||
848 | acx->rate_policy.enabled_rates = cpu_to_le32(c->enabled_rates); | ||
849 | acx->rate_policy.short_retry_limit = c->short_retry_limit; | ||
850 | acx->rate_policy.long_retry_limit = c->long_retry_limit; | ||
851 | acx->rate_policy.aflags = c->aflags; | ||
852 | |||
853 | acx->rate_policy_idx = cpu_to_le32(idx); | ||
854 | |||
855 | ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx)); | ||
856 | if (ret < 0) { | ||
857 | wl1271_warning("Setting of ap rate policy failed: %d", ret); | ||
858 | goto out; | ||
859 | } | ||
860 | |||
861 | out: | ||
862 | kfree(acx); | ||
863 | return ret; | ||
864 | } | ||
865 | |||
866 | int wl1271_acx_ac_cfg(struct wl1271 *wl, u8 ac, u8 cw_min, u16 cw_max, | ||
867 | u8 aifsn, u16 txop) | ||
868 | { | ||
869 | struct acx_ac_cfg *acx; | ||
870 | int ret = 0; | ||
871 | |||
872 | wl1271_debug(DEBUG_ACX, "acx ac cfg %d cw_ming %d cw_max %d " | ||
873 | "aifs %d txop %d", ac, cw_min, cw_max, aifsn, txop); | ||
874 | |||
875 | acx = kzalloc(sizeof(*acx), GFP_KERNEL); | ||
876 | |||
877 | if (!acx) { | ||
878 | ret = -ENOMEM; | ||
879 | goto out; | ||
880 | } | ||
881 | |||
882 | acx->ac = ac; | ||
883 | acx->cw_min = cw_min; | ||
884 | acx->cw_max = cpu_to_le16(cw_max); | ||
885 | acx->aifsn = aifsn; | ||
886 | acx->tx_op_limit = cpu_to_le16(txop); | ||
887 | |||
888 | ret = wl1271_cmd_configure(wl, ACX_AC_CFG, acx, sizeof(*acx)); | ||
889 | if (ret < 0) { | ||
890 | wl1271_warning("acx ac cfg failed: %d", ret); | ||
891 | goto out; | ||
892 | } | ||
893 | |||
894 | out: | ||
895 | kfree(acx); | ||
896 | return ret; | ||
897 | } | ||
898 | |||
899 | int wl1271_acx_tid_cfg(struct wl1271 *wl, u8 queue_id, u8 channel_type, | ||
900 | u8 tsid, u8 ps_scheme, u8 ack_policy, | ||
901 | u32 apsd_conf0, u32 apsd_conf1) | ||
902 | { | ||
903 | struct acx_tid_config *acx; | ||
904 | int ret = 0; | ||
905 | |||
906 | wl1271_debug(DEBUG_ACX, "acx tid config"); | ||
907 | |||
908 | acx = kzalloc(sizeof(*acx), GFP_KERNEL); | ||
909 | |||
910 | if (!acx) { | ||
911 | ret = -ENOMEM; | ||
912 | goto out; | ||
913 | } | ||
914 | |||
915 | acx->queue_id = queue_id; | ||
916 | acx->channel_type = channel_type; | ||
917 | acx->tsid = tsid; | ||
918 | acx->ps_scheme = ps_scheme; | ||
919 | acx->ack_policy = ack_policy; | ||
920 | acx->apsd_conf[0] = cpu_to_le32(apsd_conf0); | ||
921 | acx->apsd_conf[1] = cpu_to_le32(apsd_conf1); | ||
922 | |||
923 | ret = wl1271_cmd_configure(wl, ACX_TID_CFG, acx, sizeof(*acx)); | ||
924 | if (ret < 0) { | ||
925 | wl1271_warning("Setting of tid config failed: %d", ret); | ||
926 | goto out; | ||
927 | } | ||
928 | |||
929 | out: | ||
930 | kfree(acx); | ||
931 | return ret; | ||
932 | } | ||
933 | |||
934 | int wl1271_acx_frag_threshold(struct wl1271 *wl, u32 frag_threshold) | ||
935 | { | ||
936 | struct acx_frag_threshold *acx; | ||
937 | int ret = 0; | ||
938 | |||
939 | /* | ||
940 | * If the fragmentation is not configured or out of range, use the | ||
941 | * default value. | ||
942 | */ | ||
943 | if (frag_threshold > IEEE80211_MAX_FRAG_THRESHOLD) | ||
944 | frag_threshold = wl->conf.tx.frag_threshold; | ||
945 | |||
946 | wl1271_debug(DEBUG_ACX, "acx frag threshold: %d", frag_threshold); | ||
947 | |||
948 | acx = kzalloc(sizeof(*acx), GFP_KERNEL); | ||
949 | |||
950 | if (!acx) { | ||
951 | ret = -ENOMEM; | ||
952 | goto out; | ||
953 | } | ||
954 | |||
955 | acx->frag_threshold = cpu_to_le16((u16)frag_threshold); | ||
956 | ret = wl1271_cmd_configure(wl, ACX_FRAG_CFG, acx, sizeof(*acx)); | ||
957 | if (ret < 0) { | ||
958 | wl1271_warning("Setting of frag threshold failed: %d", ret); | ||
959 | goto out; | ||
960 | } | ||
961 | |||
962 | out: | ||
963 | kfree(acx); | ||
964 | return ret; | ||
965 | } | ||
966 | |||
967 | int wl1271_acx_tx_config_options(struct wl1271 *wl) | ||
968 | { | ||
969 | struct acx_tx_config_options *acx; | ||
970 | int ret = 0; | ||
971 | |||
972 | wl1271_debug(DEBUG_ACX, "acx tx config options"); | ||
973 | |||
974 | acx = kzalloc(sizeof(*acx), GFP_KERNEL); | ||
975 | |||
976 | if (!acx) { | ||
977 | ret = -ENOMEM; | ||
978 | goto out; | ||
979 | } | ||
980 | |||
981 | acx->tx_compl_timeout = cpu_to_le16(wl->conf.tx.tx_compl_timeout); | ||
982 | acx->tx_compl_threshold = cpu_to_le16(wl->conf.tx.tx_compl_threshold); | ||
983 | ret = wl1271_cmd_configure(wl, ACX_TX_CONFIG_OPT, acx, sizeof(*acx)); | ||
984 | if (ret < 0) { | ||
985 | wl1271_warning("Setting of tx options failed: %d", ret); | ||
986 | goto out; | ||
987 | } | ||
988 | |||
989 | out: | ||
990 | kfree(acx); | ||
991 | return ret; | ||
992 | } | ||
993 | |||
994 | int wl1271_acx_ap_mem_cfg(struct wl1271 *wl) | ||
995 | { | ||
996 | struct wl1271_acx_ap_config_memory *mem_conf; | ||
997 | struct conf_memory_settings *mem; | ||
998 | int ret; | ||
999 | |||
1000 | wl1271_debug(DEBUG_ACX, "wl1271 mem cfg"); | ||
1001 | |||
1002 | mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL); | ||
1003 | if (!mem_conf) { | ||
1004 | ret = -ENOMEM; | ||
1005 | goto out; | ||
1006 | } | ||
1007 | |||
1008 | if (wl->chip.id == CHIP_ID_1283_PG20) | ||
1009 | /* | ||
1010 | * FIXME: The 128x AP FW does not yet support dynamic memory. | ||
1011 | * Use the base memory configuration for 128x for now. This | ||
1012 | * should be fine tuned in the future. | ||
1013 | */ | ||
1014 | mem = &wl->conf.mem_wl128x; | ||
1015 | else | ||
1016 | mem = &wl->conf.mem_wl127x; | ||
1017 | |||
1018 | /* memory config */ | ||
1019 | mem_conf->num_stations = mem->num_stations; | ||
1020 | mem_conf->rx_mem_block_num = mem->rx_block_num; | ||
1021 | mem_conf->tx_min_mem_block_num = mem->tx_min_block_num; | ||
1022 | mem_conf->num_ssid_profiles = mem->ssid_profiles; | ||
1023 | mem_conf->total_tx_descriptors = cpu_to_le32(ACX_TX_DESCRIPTORS); | ||
1024 | |||
1025 | ret = wl1271_cmd_configure(wl, ACX_MEM_CFG, mem_conf, | ||
1026 | sizeof(*mem_conf)); | ||
1027 | if (ret < 0) { | ||
1028 | wl1271_warning("wl1271 mem config failed: %d", ret); | ||
1029 | goto out; | ||
1030 | } | ||
1031 | |||
1032 | out: | ||
1033 | kfree(mem_conf); | ||
1034 | return ret; | ||
1035 | } | ||
1036 | |||
1037 | int wl1271_acx_sta_mem_cfg(struct wl1271 *wl) | ||
1038 | { | ||
1039 | struct wl1271_acx_sta_config_memory *mem_conf; | ||
1040 | struct conf_memory_settings *mem; | ||
1041 | int ret; | ||
1042 | |||
1043 | wl1271_debug(DEBUG_ACX, "wl1271 mem cfg"); | ||
1044 | |||
1045 | mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL); | ||
1046 | if (!mem_conf) { | ||
1047 | ret = -ENOMEM; | ||
1048 | goto out; | ||
1049 | } | ||
1050 | |||
1051 | if (wl->chip.id == CHIP_ID_1283_PG20) | ||
1052 | mem = &wl->conf.mem_wl128x; | ||
1053 | else | ||
1054 | mem = &wl->conf.mem_wl127x; | ||
1055 | |||
1056 | /* memory config */ | ||
1057 | mem_conf->num_stations = mem->num_stations; | ||
1058 | mem_conf->rx_mem_block_num = mem->rx_block_num; | ||
1059 | mem_conf->tx_min_mem_block_num = mem->tx_min_block_num; | ||
1060 | mem_conf->num_ssid_profiles = mem->ssid_profiles; | ||
1061 | mem_conf->total_tx_descriptors = cpu_to_le32(ACX_TX_DESCRIPTORS); | ||
1062 | mem_conf->dyn_mem_enable = mem->dynamic_memory; | ||
1063 | mem_conf->tx_free_req = mem->min_req_tx_blocks; | ||
1064 | mem_conf->rx_free_req = mem->min_req_rx_blocks; | ||
1065 | mem_conf->tx_min = mem->tx_min; | ||
1066 | mem_conf->fwlog_blocks = wl->conf.fwlog.mem_blocks; | ||
1067 | |||
1068 | ret = wl1271_cmd_configure(wl, ACX_MEM_CFG, mem_conf, | ||
1069 | sizeof(*mem_conf)); | ||
1070 | if (ret < 0) { | ||
1071 | wl1271_warning("wl1271 mem config failed: %d", ret); | ||
1072 | goto out; | ||
1073 | } | ||
1074 | |||
1075 | out: | ||
1076 | kfree(mem_conf); | ||
1077 | return ret; | ||
1078 | } | ||
1079 | |||
1080 | int wl1271_acx_host_if_cfg_bitmap(struct wl1271 *wl, u32 host_cfg_bitmap) | ||
1081 | { | ||
1082 | struct wl1271_acx_host_config_bitmap *bitmap_conf; | ||
1083 | int ret; | ||
1084 | |||
1085 | bitmap_conf = kzalloc(sizeof(*bitmap_conf), GFP_KERNEL); | ||
1086 | if (!bitmap_conf) { | ||
1087 | ret = -ENOMEM; | ||
1088 | goto out; | ||
1089 | } | ||
1090 | |||
1091 | bitmap_conf->host_cfg_bitmap = cpu_to_le32(host_cfg_bitmap); | ||
1092 | |||
1093 | ret = wl1271_cmd_configure(wl, ACX_HOST_IF_CFG_BITMAP, | ||
1094 | bitmap_conf, sizeof(*bitmap_conf)); | ||
1095 | if (ret < 0) { | ||
1096 | wl1271_warning("wl1271 bitmap config opt failed: %d", ret); | ||
1097 | goto out; | ||
1098 | } | ||
1099 | |||
1100 | out: | ||
1101 | kfree(bitmap_conf); | ||
1102 | |||
1103 | return ret; | ||
1104 | } | ||
1105 | |||
1106 | int wl1271_acx_init_mem_config(struct wl1271 *wl) | ||
1107 | { | ||
1108 | int ret; | ||
1109 | |||
1110 | wl->target_mem_map = kzalloc(sizeof(struct wl1271_acx_mem_map), | ||
1111 | GFP_KERNEL); | ||
1112 | if (!wl->target_mem_map) { | ||
1113 | wl1271_error("couldn't allocate target memory map"); | ||
1114 | return -ENOMEM; | ||
1115 | } | ||
1116 | |||
1117 | /* we now ask for the firmware built memory map */ | ||
1118 | ret = wl1271_acx_mem_map(wl, (void *)wl->target_mem_map, | ||
1119 | sizeof(struct wl1271_acx_mem_map)); | ||
1120 | if (ret < 0) { | ||
1121 | wl1271_error("couldn't retrieve firmware memory map"); | ||
1122 | kfree(wl->target_mem_map); | ||
1123 | wl->target_mem_map = NULL; | ||
1124 | return ret; | ||
1125 | } | ||
1126 | |||
1127 | /* initialize TX block book keeping */ | ||
1128 | wl->tx_blocks_available = | ||
1129 | le32_to_cpu(wl->target_mem_map->num_tx_mem_blocks); | ||
1130 | wl1271_debug(DEBUG_TX, "available tx blocks: %d", | ||
1131 | wl->tx_blocks_available); | ||
1132 | |||
1133 | return 0; | ||
1134 | } | ||
1135 | |||
1136 | int wl1271_acx_init_rx_interrupt(struct wl1271 *wl) | ||
1137 | { | ||
1138 | struct wl1271_acx_rx_config_opt *rx_conf; | ||
1139 | int ret; | ||
1140 | |||
1141 | wl1271_debug(DEBUG_ACX, "wl1271 rx interrupt config"); | ||
1142 | |||
1143 | rx_conf = kzalloc(sizeof(*rx_conf), GFP_KERNEL); | ||
1144 | if (!rx_conf) { | ||
1145 | ret = -ENOMEM; | ||
1146 | goto out; | ||
1147 | } | ||
1148 | |||
1149 | rx_conf->threshold = cpu_to_le16(wl->conf.rx.irq_pkt_threshold); | ||
1150 | rx_conf->timeout = cpu_to_le16(wl->conf.rx.irq_timeout); | ||
1151 | rx_conf->mblk_threshold = cpu_to_le16(wl->conf.rx.irq_blk_threshold); | ||
1152 | rx_conf->queue_type = wl->conf.rx.queue_type; | ||
1153 | |||
1154 | ret = wl1271_cmd_configure(wl, ACX_RX_CONFIG_OPT, rx_conf, | ||
1155 | sizeof(*rx_conf)); | ||
1156 | if (ret < 0) { | ||
1157 | wl1271_warning("wl1271 rx config opt failed: %d", ret); | ||
1158 | goto out; | ||
1159 | } | ||
1160 | |||
1161 | out: | ||
1162 | kfree(rx_conf); | ||
1163 | return ret; | ||
1164 | } | ||
1165 | |||
1166 | int wl1271_acx_bet_enable(struct wl1271 *wl, bool enable) | ||
1167 | { | ||
1168 | struct wl1271_acx_bet_enable *acx = NULL; | ||
1169 | int ret = 0; | ||
1170 | |||
1171 | wl1271_debug(DEBUG_ACX, "acx bet enable"); | ||
1172 | |||
1173 | if (enable && wl->conf.conn.bet_enable == CONF_BET_MODE_DISABLE) | ||
1174 | goto out; | ||
1175 | |||
1176 | acx = kzalloc(sizeof(*acx), GFP_KERNEL); | ||
1177 | if (!acx) { | ||
1178 | ret = -ENOMEM; | ||
1179 | goto out; | ||
1180 | } | ||
1181 | |||
1182 | acx->enable = enable ? CONF_BET_MODE_ENABLE : CONF_BET_MODE_DISABLE; | ||
1183 | acx->max_consecutive = wl->conf.conn.bet_max_consecutive; | ||
1184 | |||
1185 | ret = wl1271_cmd_configure(wl, ACX_BET_ENABLE, acx, sizeof(*acx)); | ||
1186 | if (ret < 0) { | ||
1187 | wl1271_warning("acx bet enable failed: %d", ret); | ||
1188 | goto out; | ||
1189 | } | ||
1190 | |||
1191 | out: | ||
1192 | kfree(acx); | ||
1193 | return ret; | ||
1194 | } | ||
1195 | |||
1196 | int wl1271_acx_arp_ip_filter(struct wl1271 *wl, u8 enable, __be32 address) | ||
1197 | { | ||
1198 | struct wl1271_acx_arp_filter *acx; | ||
1199 | int ret; | ||
1200 | |||
1201 | wl1271_debug(DEBUG_ACX, "acx arp ip filter, enable: %d", enable); | ||
1202 | |||
1203 | acx = kzalloc(sizeof(*acx), GFP_KERNEL); | ||
1204 | if (!acx) { | ||
1205 | ret = -ENOMEM; | ||
1206 | goto out; | ||
1207 | } | ||
1208 | |||
1209 | acx->version = ACX_IPV4_VERSION; | ||
1210 | acx->enable = enable; | ||
1211 | |||
1212 | if (enable) | ||
1213 | memcpy(acx->address, &address, ACX_IPV4_ADDR_SIZE); | ||
1214 | |||
1215 | ret = wl1271_cmd_configure(wl, ACX_ARP_IP_FILTER, | ||
1216 | acx, sizeof(*acx)); | ||
1217 | if (ret < 0) { | ||
1218 | wl1271_warning("failed to set arp ip filter: %d", ret); | ||
1219 | goto out; | ||
1220 | } | ||
1221 | |||
1222 | out: | ||
1223 | kfree(acx); | ||
1224 | return ret; | ||
1225 | } | ||
1226 | |||
1227 | int wl1271_acx_pm_config(struct wl1271 *wl) | ||
1228 | { | ||
1229 | struct wl1271_acx_pm_config *acx = NULL; | ||
1230 | struct conf_pm_config_settings *c = &wl->conf.pm_config; | ||
1231 | int ret = 0; | ||
1232 | |||
1233 | wl1271_debug(DEBUG_ACX, "acx pm config"); | ||
1234 | |||
1235 | acx = kzalloc(sizeof(*acx), GFP_KERNEL); | ||
1236 | if (!acx) { | ||
1237 | ret = -ENOMEM; | ||
1238 | goto out; | ||
1239 | } | ||
1240 | |||
1241 | acx->host_clk_settling_time = cpu_to_le32(c->host_clk_settling_time); | ||
1242 | acx->host_fast_wakeup_support = c->host_fast_wakeup_support; | ||
1243 | |||
1244 | ret = wl1271_cmd_configure(wl, ACX_PM_CONFIG, acx, sizeof(*acx)); | ||
1245 | if (ret < 0) { | ||
1246 | wl1271_warning("acx pm config failed: %d", ret); | ||
1247 | goto out; | ||
1248 | } | ||
1249 | |||
1250 | out: | ||
1251 | kfree(acx); | ||
1252 | return ret; | ||
1253 | } | ||
1254 | |||
1255 | int wl1271_acx_keep_alive_mode(struct wl1271 *wl, bool enable) | ||
1256 | { | ||
1257 | struct wl1271_acx_keep_alive_mode *acx = NULL; | ||
1258 | int ret = 0; | ||
1259 | |||
1260 | wl1271_debug(DEBUG_ACX, "acx keep alive mode: %d", enable); | ||
1261 | |||
1262 | acx = kzalloc(sizeof(*acx), GFP_KERNEL); | ||
1263 | if (!acx) { | ||
1264 | ret = -ENOMEM; | ||
1265 | goto out; | ||
1266 | } | ||
1267 | |||
1268 | acx->enabled = enable; | ||
1269 | |||
1270 | ret = wl1271_cmd_configure(wl, ACX_KEEP_ALIVE_MODE, acx, sizeof(*acx)); | ||
1271 | if (ret < 0) { | ||
1272 | wl1271_warning("acx keep alive mode failed: %d", ret); | ||
1273 | goto out; | ||
1274 | } | ||
1275 | |||
1276 | out: | ||
1277 | kfree(acx); | ||
1278 | return ret; | ||
1279 | } | ||
1280 | |||
1281 | int wl1271_acx_keep_alive_config(struct wl1271 *wl, u8 index, u8 tpl_valid) | ||
1282 | { | ||
1283 | struct wl1271_acx_keep_alive_config *acx = NULL; | ||
1284 | int ret = 0; | ||
1285 | |||
1286 | wl1271_debug(DEBUG_ACX, "acx keep alive config"); | ||
1287 | |||
1288 | acx = kzalloc(sizeof(*acx), GFP_KERNEL); | ||
1289 | if (!acx) { | ||
1290 | ret = -ENOMEM; | ||
1291 | goto out; | ||
1292 | } | ||
1293 | |||
1294 | acx->period = cpu_to_le32(wl->conf.conn.keep_alive_interval); | ||
1295 | acx->index = index; | ||
1296 | acx->tpl_validation = tpl_valid; | ||
1297 | acx->trigger = ACX_KEEP_ALIVE_NO_TX; | ||
1298 | |||
1299 | ret = wl1271_cmd_configure(wl, ACX_SET_KEEP_ALIVE_CONFIG, | ||
1300 | acx, sizeof(*acx)); | ||
1301 | if (ret < 0) { | ||
1302 | wl1271_warning("acx keep alive config failed: %d", ret); | ||
1303 | goto out; | ||
1304 | } | ||
1305 | |||
1306 | out: | ||
1307 | kfree(acx); | ||
1308 | return ret; | ||
1309 | } | ||
1310 | |||
1311 | int wl1271_acx_rssi_snr_trigger(struct wl1271 *wl, bool enable, | ||
1312 | s16 thold, u8 hyst) | ||
1313 | { | ||
1314 | struct wl1271_acx_rssi_snr_trigger *acx = NULL; | ||
1315 | int ret = 0; | ||
1316 | |||
1317 | wl1271_debug(DEBUG_ACX, "acx rssi snr trigger"); | ||
1318 | |||
1319 | acx = kzalloc(sizeof(*acx), GFP_KERNEL); | ||
1320 | if (!acx) { | ||
1321 | ret = -ENOMEM; | ||
1322 | goto out; | ||
1323 | } | ||
1324 | |||
1325 | wl->last_rssi_event = -1; | ||
1326 | |||
1327 | acx->pacing = cpu_to_le16(wl->conf.roam_trigger.trigger_pacing); | ||
1328 | acx->metric = WL1271_ACX_TRIG_METRIC_RSSI_BEACON; | ||
1329 | acx->type = WL1271_ACX_TRIG_TYPE_EDGE; | ||
1330 | if (enable) | ||
1331 | acx->enable = WL1271_ACX_TRIG_ENABLE; | ||
1332 | else | ||
1333 | acx->enable = WL1271_ACX_TRIG_DISABLE; | ||
1334 | |||
1335 | acx->index = WL1271_ACX_TRIG_IDX_RSSI; | ||
1336 | acx->dir = WL1271_ACX_TRIG_DIR_BIDIR; | ||
1337 | acx->threshold = cpu_to_le16(thold); | ||
1338 | acx->hysteresis = hyst; | ||
1339 | |||
1340 | ret = wl1271_cmd_configure(wl, ACX_RSSI_SNR_TRIGGER, acx, sizeof(*acx)); | ||
1341 | if (ret < 0) { | ||
1342 | wl1271_warning("acx rssi snr trigger setting failed: %d", ret); | ||
1343 | goto out; | ||
1344 | } | ||
1345 | |||
1346 | out: | ||
1347 | kfree(acx); | ||
1348 | return ret; | ||
1349 | } | ||
1350 | |||
1351 | int wl1271_acx_rssi_snr_avg_weights(struct wl1271 *wl) | ||
1352 | { | ||
1353 | struct wl1271_acx_rssi_snr_avg_weights *acx = NULL; | ||
1354 | struct conf_roam_trigger_settings *c = &wl->conf.roam_trigger; | ||
1355 | int ret = 0; | ||
1356 | |||
1357 | wl1271_debug(DEBUG_ACX, "acx rssi snr avg weights"); | ||
1358 | |||
1359 | acx = kzalloc(sizeof(*acx), GFP_KERNEL); | ||
1360 | if (!acx) { | ||
1361 | ret = -ENOMEM; | ||
1362 | goto out; | ||
1363 | } | ||
1364 | |||
1365 | acx->rssi_beacon = c->avg_weight_rssi_beacon; | ||
1366 | acx->rssi_data = c->avg_weight_rssi_data; | ||
1367 | acx->snr_beacon = c->avg_weight_snr_beacon; | ||
1368 | acx->snr_data = c->avg_weight_snr_data; | ||
1369 | |||
1370 | ret = wl1271_cmd_configure(wl, ACX_RSSI_SNR_WEIGHTS, acx, sizeof(*acx)); | ||
1371 | if (ret < 0) { | ||
1372 | wl1271_warning("acx rssi snr trigger weights failed: %d", ret); | ||
1373 | goto out; | ||
1374 | } | ||
1375 | |||
1376 | out: | ||
1377 | kfree(acx); | ||
1378 | return ret; | ||
1379 | } | ||
1380 | |||
1381 | int wl1271_acx_set_ht_capabilities(struct wl1271 *wl, | ||
1382 | struct ieee80211_sta_ht_cap *ht_cap, | ||
1383 | bool allow_ht_operation) | ||
1384 | { | ||
1385 | struct wl1271_acx_ht_capabilities *acx; | ||
1386 | u8 mac_address[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; | ||
1387 | int ret = 0; | ||
1388 | u32 ht_capabilites = 0; | ||
1389 | |||
1390 | wl1271_debug(DEBUG_ACX, "acx ht capabilities setting"); | ||
1391 | |||
1392 | acx = kzalloc(sizeof(*acx), GFP_KERNEL); | ||
1393 | if (!acx) { | ||
1394 | ret = -ENOMEM; | ||
1395 | goto out; | ||
1396 | } | ||
1397 | |||
1398 | /* Allow HT Operation ? */ | ||
1399 | if (allow_ht_operation) { | ||
1400 | ht_capabilites = | ||
1401 | WL1271_ACX_FW_CAP_HT_OPERATION; | ||
1402 | if (ht_cap->cap & IEEE80211_HT_CAP_GRN_FLD) | ||
1403 | ht_capabilites |= | ||
1404 | WL1271_ACX_FW_CAP_GREENFIELD_FRAME_FORMAT; | ||
1405 | if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20) | ||
1406 | ht_capabilites |= | ||
1407 | WL1271_ACX_FW_CAP_SHORT_GI_FOR_20MHZ_PACKETS; | ||
1408 | if (ht_cap->cap & IEEE80211_HT_CAP_LSIG_TXOP_PROT) | ||
1409 | ht_capabilites |= | ||
1410 | WL1271_ACX_FW_CAP_LSIG_TXOP_PROTECTION; | ||
1411 | |||
1412 | /* get data from A-MPDU parameters field */ | ||
1413 | acx->ampdu_max_length = ht_cap->ampdu_factor; | ||
1414 | acx->ampdu_min_spacing = ht_cap->ampdu_density; | ||
1415 | } | ||
1416 | |||
1417 | memcpy(acx->mac_address, mac_address, ETH_ALEN); | ||
1418 | acx->ht_capabilites = cpu_to_le32(ht_capabilites); | ||
1419 | |||
1420 | ret = wl1271_cmd_configure(wl, ACX_PEER_HT_CAP, acx, sizeof(*acx)); | ||
1421 | if (ret < 0) { | ||
1422 | wl1271_warning("acx ht capabilities setting failed: %d", ret); | ||
1423 | goto out; | ||
1424 | } | ||
1425 | |||
1426 | out: | ||
1427 | kfree(acx); | ||
1428 | return ret; | ||
1429 | } | ||
1430 | |||
1431 | int wl1271_acx_set_ht_information(struct wl1271 *wl, | ||
1432 | u16 ht_operation_mode) | ||
1433 | { | ||
1434 | struct wl1271_acx_ht_information *acx; | ||
1435 | int ret = 0; | ||
1436 | |||
1437 | wl1271_debug(DEBUG_ACX, "acx ht information setting"); | ||
1438 | |||
1439 | acx = kzalloc(sizeof(*acx), GFP_KERNEL); | ||
1440 | if (!acx) { | ||
1441 | ret = -ENOMEM; | ||
1442 | goto out; | ||
1443 | } | ||
1444 | |||
1445 | acx->ht_protection = | ||
1446 | (u8)(ht_operation_mode & IEEE80211_HT_OP_MODE_PROTECTION); | ||
1447 | acx->rifs_mode = 0; | ||
1448 | acx->gf_protection = | ||
1449 | !!(ht_operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT); | ||
1450 | acx->ht_tx_burst_limit = 0; | ||
1451 | acx->dual_cts_protection = 0; | ||
1452 | |||
1453 | ret = wl1271_cmd_configure(wl, ACX_HT_BSS_OPERATION, acx, sizeof(*acx)); | ||
1454 | |||
1455 | if (ret < 0) { | ||
1456 | wl1271_warning("acx ht information setting failed: %d", ret); | ||
1457 | goto out; | ||
1458 | } | ||
1459 | |||
1460 | out: | ||
1461 | kfree(acx); | ||
1462 | return ret; | ||
1463 | } | ||
1464 | |||
1465 | /* Configure BA session initiator/receiver parameters setting in the FW. */ | ||
1466 | int wl1271_acx_set_ba_session(struct wl1271 *wl, | ||
1467 | enum ieee80211_back_parties direction, | ||
1468 | u8 tid_index, u8 policy) | ||
1469 | { | ||
1470 | struct wl1271_acx_ba_session_policy *acx; | ||
1471 | int ret; | ||
1472 | |||
1473 | wl1271_debug(DEBUG_ACX, "acx ba session setting"); | ||
1474 | |||
1475 | acx = kzalloc(sizeof(*acx), GFP_KERNEL); | ||
1476 | if (!acx) { | ||
1477 | ret = -ENOMEM; | ||
1478 | goto out; | ||
1479 | } | ||
1480 | |||
1481 | /* ANY role */ | ||
1482 | acx->role_id = 0xff; | ||
1483 | acx->tid = tid_index; | ||
1484 | acx->enable = policy; | ||
1485 | acx->ba_direction = direction; | ||
1486 | |||
1487 | switch (direction) { | ||
1488 | case WLAN_BACK_INITIATOR: | ||
1489 | acx->win_size = wl->conf.ht.tx_ba_win_size; | ||
1490 | acx->inactivity_timeout = wl->conf.ht.inactivity_timeout; | ||
1491 | break; | ||
1492 | case WLAN_BACK_RECIPIENT: | ||
1493 | acx->win_size = RX_BA_WIN_SIZE; | ||
1494 | acx->inactivity_timeout = 0; | ||
1495 | break; | ||
1496 | default: | ||
1497 | wl1271_error("Incorrect acx command id=%x\n", direction); | ||
1498 | ret = -EINVAL; | ||
1499 | goto out; | ||
1500 | } | ||
1501 | |||
1502 | ret = wl1271_cmd_configure(wl, | ||
1503 | ACX_BA_SESSION_POLICY_CFG, | ||
1504 | acx, | ||
1505 | sizeof(*acx)); | ||
1506 | if (ret < 0) { | ||
1507 | wl1271_warning("acx ba session setting failed: %d", ret); | ||
1508 | goto out; | ||
1509 | } | ||
1510 | |||
1511 | out: | ||
1512 | kfree(acx); | ||
1513 | return ret; | ||
1514 | } | ||
1515 | |||
1516 | /* setup BA session receiver setting in the FW. */ | ||
1517 | int wl1271_acx_set_ba_receiver_session(struct wl1271 *wl, u8 tid_index, u16 ssn, | ||
1518 | bool enable) | ||
1519 | { | ||
1520 | struct wl1271_acx_ba_receiver_setup *acx; | ||
1521 | int ret; | ||
1522 | |||
1523 | wl1271_debug(DEBUG_ACX, "acx ba receiver session setting"); | ||
1524 | |||
1525 | acx = kzalloc(sizeof(*acx), GFP_KERNEL); | ||
1526 | if (!acx) { | ||
1527 | ret = -ENOMEM; | ||
1528 | goto out; | ||
1529 | } | ||
1530 | |||
1531 | /* Single link for now */ | ||
1532 | acx->link_id = 1; | ||
1533 | acx->tid = tid_index; | ||
1534 | acx->enable = enable; | ||
1535 | acx->win_size = 0; | ||
1536 | acx->ssn = ssn; | ||
1537 | |||
1538 | ret = wl1271_cmd_configure(wl, ACX_BA_SESSION_RX_SETUP, acx, | ||
1539 | sizeof(*acx)); | ||
1540 | if (ret < 0) { | ||
1541 | wl1271_warning("acx ba receiver session failed: %d", ret); | ||
1542 | goto out; | ||
1543 | } | ||
1544 | |||
1545 | out: | ||
1546 | kfree(acx); | ||
1547 | return ret; | ||
1548 | } | ||
1549 | |||
1550 | int wl1271_acx_tsf_info(struct wl1271 *wl, u64 *mactime) | ||
1551 | { | ||
1552 | struct wl1271_acx_fw_tsf_information *tsf_info; | ||
1553 | int ret; | ||
1554 | |||
1555 | tsf_info = kzalloc(sizeof(*tsf_info), GFP_KERNEL); | ||
1556 | if (!tsf_info) { | ||
1557 | ret = -ENOMEM; | ||
1558 | goto out; | ||
1559 | } | ||
1560 | |||
1561 | ret = wl1271_cmd_interrogate(wl, ACX_TSF_INFO, | ||
1562 | tsf_info, sizeof(*tsf_info)); | ||
1563 | if (ret < 0) { | ||
1564 | wl1271_warning("acx tsf info interrogate failed"); | ||
1565 | goto out; | ||
1566 | } | ||
1567 | |||
1568 | *mactime = le32_to_cpu(tsf_info->current_tsf_low) | | ||
1569 | ((u64) le32_to_cpu(tsf_info->current_tsf_high) << 32); | ||
1570 | |||
1571 | out: | ||
1572 | kfree(tsf_info); | ||
1573 | return ret; | ||
1574 | } | ||
1575 | |||
1576 | int wl1271_acx_ps_rx_streaming(struct wl1271 *wl, bool enable) | ||
1577 | { | ||
1578 | struct wl1271_acx_ps_rx_streaming *rx_streaming; | ||
1579 | u32 conf_queues, enable_queues; | ||
1580 | int i, ret = 0; | ||
1581 | |||
1582 | wl1271_debug(DEBUG_ACX, "acx ps rx streaming"); | ||
1583 | |||
1584 | rx_streaming = kzalloc(sizeof(*rx_streaming), GFP_KERNEL); | ||
1585 | if (!rx_streaming) { | ||
1586 | ret = -ENOMEM; | ||
1587 | goto out; | ||
1588 | } | ||
1589 | |||
1590 | conf_queues = wl->conf.rx_streaming.queues; | ||
1591 | if (enable) | ||
1592 | enable_queues = conf_queues; | ||
1593 | else | ||
1594 | enable_queues = 0; | ||
1595 | |||
1596 | for (i = 0; i < 8; i++) { | ||
1597 | /* | ||
1598 | * Skip non-changed queues, to avoid redundant acxs. | ||
1599 | * this check assumes conf.rx_streaming.queues can't | ||
1600 | * be changed while rx_streaming is enabled. | ||
1601 | */ | ||
1602 | if (!(conf_queues & BIT(i))) | ||
1603 | continue; | ||
1604 | |||
1605 | rx_streaming->tid = i; | ||
1606 | rx_streaming->enable = enable_queues & BIT(i); | ||
1607 | rx_streaming->period = wl->conf.rx_streaming.interval; | ||
1608 | rx_streaming->timeout = wl->conf.rx_streaming.interval; | ||
1609 | |||
1610 | ret = wl1271_cmd_configure(wl, ACX_PS_RX_STREAMING, | ||
1611 | rx_streaming, | ||
1612 | sizeof(*rx_streaming)); | ||
1613 | if (ret < 0) { | ||
1614 | wl1271_warning("acx ps rx streaming failed: %d", ret); | ||
1615 | goto out; | ||
1616 | } | ||
1617 | } | ||
1618 | out: | ||
1619 | kfree(rx_streaming); | ||
1620 | return ret; | ||
1621 | } | ||
1622 | |||
1623 | int wl1271_acx_ap_max_tx_retry(struct wl1271 *wl) | ||
1624 | { | ||
1625 | struct wl1271_acx_ap_max_tx_retry *acx = NULL; | ||
1626 | int ret; | ||
1627 | |||
1628 | wl1271_debug(DEBUG_ACX, "acx ap max tx retry"); | ||
1629 | |||
1630 | acx = kzalloc(sizeof(*acx), GFP_KERNEL); | ||
1631 | if (!acx) | ||
1632 | return -ENOMEM; | ||
1633 | |||
1634 | acx->max_tx_retry = cpu_to_le16(wl->conf.tx.max_tx_retries); | ||
1635 | |||
1636 | ret = wl1271_cmd_configure(wl, ACX_MAX_TX_FAILURE, acx, sizeof(*acx)); | ||
1637 | if (ret < 0) { | ||
1638 | wl1271_warning("acx ap max tx retry failed: %d", ret); | ||
1639 | goto out; | ||
1640 | } | ||
1641 | |||
1642 | out: | ||
1643 | kfree(acx); | ||
1644 | return ret; | ||
1645 | } | ||
1646 | |||
1647 | int wl1271_acx_config_ps(struct wl1271 *wl) | ||
1648 | { | ||
1649 | struct wl1271_acx_config_ps *config_ps; | ||
1650 | int ret; | ||
1651 | |||
1652 | wl1271_debug(DEBUG_ACX, "acx config ps"); | ||
1653 | |||
1654 | config_ps = kzalloc(sizeof(*config_ps), GFP_KERNEL); | ||
1655 | if (!config_ps) { | ||
1656 | ret = -ENOMEM; | ||
1657 | goto out; | ||
1658 | } | ||
1659 | |||
1660 | config_ps->exit_retries = wl->conf.conn.psm_exit_retries; | ||
1661 | config_ps->enter_retries = wl->conf.conn.psm_entry_retries; | ||
1662 | config_ps->null_data_rate = cpu_to_le32(wl->basic_rate); | ||
1663 | |||
1664 | ret = wl1271_cmd_configure(wl, ACX_CONFIG_PS, config_ps, | ||
1665 | sizeof(*config_ps)); | ||
1666 | |||
1667 | if (ret < 0) { | ||
1668 | wl1271_warning("acx config ps failed: %d", ret); | ||
1669 | goto out; | ||
1670 | } | ||
1671 | |||
1672 | out: | ||
1673 | kfree(config_ps); | ||
1674 | return ret; | ||
1675 | } | ||
1676 | |||
1677 | int wl1271_acx_set_inconnection_sta(struct wl1271 *wl, u8 *addr) | ||
1678 | { | ||
1679 | struct wl1271_acx_inconnection_sta *acx = NULL; | ||
1680 | int ret; | ||
1681 | |||
1682 | wl1271_debug(DEBUG_ACX, "acx set inconnaction sta %pM", addr); | ||
1683 | |||
1684 | acx = kzalloc(sizeof(*acx), GFP_KERNEL); | ||
1685 | if (!acx) | ||
1686 | return -ENOMEM; | ||
1687 | |||
1688 | memcpy(acx->addr, addr, ETH_ALEN); | ||
1689 | |||
1690 | ret = wl1271_cmd_configure(wl, ACX_UPDATE_INCONNECTION_STA_LIST, | ||
1691 | acx, sizeof(*acx)); | ||
1692 | if (ret < 0) { | ||
1693 | wl1271_warning("acx set inconnaction sta failed: %d", ret); | ||
1694 | goto out; | ||
1695 | } | ||
1696 | |||
1697 | out: | ||
1698 | kfree(acx); | ||
1699 | return ret; | ||
1700 | } | ||
1701 | |||
1702 | int wl1271_acx_set_ap_beacon_filter(struct wl1271 *wl, bool enable) | ||
1703 | { | ||
1704 | struct acx_ap_beacon_filter *acx = NULL; | ||
1705 | int ret; | ||
1706 | |||
1707 | wl1271_debug(DEBUG_ACX, "acx set ap beacon filter: %d", enable); | ||
1708 | |||
1709 | acx = kzalloc(sizeof(*acx), GFP_KERNEL); | ||
1710 | if (!acx) | ||
1711 | return -ENOMEM; | ||
1712 | |||
1713 | acx->enable = enable ? 1 : 0; | ||
1714 | |||
1715 | ret = wl1271_cmd_configure(wl, ACX_AP_BEACON_FILTER_OPT, | ||
1716 | acx, sizeof(*acx)); | ||
1717 | if (ret < 0) { | ||
1718 | wl1271_warning("acx set ap beacon filter failed: %d", ret); | ||
1719 | goto out; | ||
1720 | } | ||
1721 | |||
1722 | out: | ||
1723 | kfree(acx); | ||
1724 | return ret; | ||
1725 | } | ||
1726 | |||
1727 | int wl1271_acx_fm_coex(struct wl1271 *wl) | ||
1728 | { | ||
1729 | struct wl1271_acx_fm_coex *acx; | ||
1730 | int ret; | ||
1731 | |||
1732 | wl1271_debug(DEBUG_ACX, "acx fm coex setting"); | ||
1733 | |||
1734 | acx = kzalloc(sizeof(*acx), GFP_KERNEL); | ||
1735 | if (!acx) { | ||
1736 | ret = -ENOMEM; | ||
1737 | goto out; | ||
1738 | } | ||
1739 | |||
1740 | acx->enable = wl->conf.fm_coex.enable; | ||
1741 | acx->swallow_period = wl->conf.fm_coex.swallow_period; | ||
1742 | acx->n_divider_fref_set_1 = wl->conf.fm_coex.n_divider_fref_set_1; | ||
1743 | acx->n_divider_fref_set_2 = wl->conf.fm_coex.n_divider_fref_set_2; | ||
1744 | acx->m_divider_fref_set_1 = | ||
1745 | cpu_to_le16(wl->conf.fm_coex.m_divider_fref_set_1); | ||
1746 | acx->m_divider_fref_set_2 = | ||
1747 | cpu_to_le16(wl->conf.fm_coex.m_divider_fref_set_2); | ||
1748 | acx->coex_pll_stabilization_time = | ||
1749 | cpu_to_le32(wl->conf.fm_coex.coex_pll_stabilization_time); | ||
1750 | acx->ldo_stabilization_time = | ||
1751 | cpu_to_le16(wl->conf.fm_coex.ldo_stabilization_time); | ||
1752 | acx->fm_disturbed_band_margin = | ||
1753 | wl->conf.fm_coex.fm_disturbed_band_margin; | ||
1754 | acx->swallow_clk_diff = wl->conf.fm_coex.swallow_clk_diff; | ||
1755 | |||
1756 | ret = wl1271_cmd_configure(wl, ACX_FM_COEX_CFG, acx, sizeof(*acx)); | ||
1757 | if (ret < 0) { | ||
1758 | wl1271_warning("acx fm coex setting failed: %d", ret); | ||
1759 | goto out; | ||
1760 | } | ||
1761 | |||
1762 | out: | ||
1763 | kfree(acx); | ||
1764 | return ret; | ||
1765 | } | ||
diff --git a/drivers/net/wireless/wl12xx/acx.h b/drivers/net/wireless/wl12xx/acx.h new file mode 100644 index 00000000000..d2eb86eccc0 --- /dev/null +++ b/drivers/net/wireless/wl12xx/acx.h | |||
@@ -0,0 +1,1409 @@ | |||
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 "wl12xx.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 */ | ||
71 | struct 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 | |||
81 | struct 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 | |||
104 | enum wl1271_psm_mode { | ||
105 | /* Active mode */ | ||
106 | WL1271_PSM_CAM = 0, | ||
107 | |||
108 | /* Power save mode */ | ||
109 | WL1271_PSM_PS = 1, | ||
110 | |||
111 | /* Extreme low power */ | ||
112 | WL1271_PSM_ELP = 2, | ||
113 | }; | ||
114 | |||
115 | struct acx_sleep_auth { | ||
116 | struct acx_header header; | ||
117 | |||
118 | /* The sleep level authorization of the device. */ | ||
119 | /* 0 - Always active*/ | ||
120 | /* 1 - Power down mode: light / fast sleep*/ | ||
121 | /* 2 - ELP mode: Deep / Max sleep*/ | ||
122 | u8 sleep_auth; | ||
123 | u8 padding[3]; | ||
124 | } __packed; | ||
125 | |||
126 | enum { | ||
127 | HOSTIF_PCI_MASTER_HOST_INDIRECT, | ||
128 | HOSTIF_PCI_MASTER_HOST_DIRECT, | ||
129 | HOSTIF_SLAVE, | ||
130 | HOSTIF_PKT_RING, | ||
131 | HOSTIF_DONTCARE = 0xFF | ||
132 | }; | ||
133 | |||
134 | #define DEFAULT_UCAST_PRIORITY 0 | ||
135 | #define DEFAULT_RX_Q_PRIORITY 0 | ||
136 | #define DEFAULT_RXQ_PRIORITY 0 /* low 0 .. 15 high */ | ||
137 | #define DEFAULT_RXQ_TYPE 0x07 /* All frames, Data/Ctrl/Mgmt */ | ||
138 | #define TRACE_BUFFER_MAX_SIZE 256 | ||
139 | |||
140 | #define DP_RX_PACKET_RING_CHUNK_SIZE 1600 | ||
141 | #define DP_TX_PACKET_RING_CHUNK_SIZE 1600 | ||
142 | #define DP_RX_PACKET_RING_CHUNK_NUM 2 | ||
143 | #define DP_TX_PACKET_RING_CHUNK_NUM 2 | ||
144 | #define DP_TX_COMPLETE_TIME_OUT 20 | ||
145 | |||
146 | #define TX_MSDU_LIFETIME_MIN 0 | ||
147 | #define TX_MSDU_LIFETIME_MAX 3000 | ||
148 | #define TX_MSDU_LIFETIME_DEF 512 | ||
149 | #define RX_MSDU_LIFETIME_MIN 0 | ||
150 | #define RX_MSDU_LIFETIME_MAX 0xFFFFFFFF | ||
151 | #define RX_MSDU_LIFETIME_DEF 512000 | ||
152 | |||
153 | struct acx_rx_msdu_lifetime { | ||
154 | struct acx_header header; | ||
155 | |||
156 | /* | ||
157 | * The maximum amount of time, in TU, before the | ||
158 | * firmware discards the MSDU. | ||
159 | */ | ||
160 | __le32 lifetime; | ||
161 | } __packed; | ||
162 | |||
163 | /* | ||
164 | * RX Config Options Table | ||
165 | * Bit Definition | ||
166 | * === ========== | ||
167 | * 31:14 Reserved | ||
168 | * 13 Copy RX Status - when set, write three receive status words | ||
169 | * to top of rx'd MPDUs. | ||
170 | * When cleared, do not write three status words (added rev 1.5) | ||
171 | * 12 Reserved | ||
172 | * 11 RX Complete upon FCS error - when set, give rx complete | ||
173 | * interrupt for FCS errors, after the rx filtering, e.g. unicast | ||
174 | * frames not to us with FCS error will not generate an interrupt. | ||
175 | * 10 SSID Filter Enable - When set, the WiLink discards all beacon, | ||
176 | * probe request, and probe response frames with an SSID that does | ||
177 | * not match the SSID specified by the host in the START/JOIN | ||
178 | * command. | ||
179 | * When clear, the WiLink receives frames with any SSID. | ||
180 | * 9 Broadcast Filter Enable - When set, the WiLink discards all | ||
181 | * broadcast frames. When clear, the WiLink receives all received | ||
182 | * broadcast frames. | ||
183 | * 8:6 Reserved | ||
184 | * 5 BSSID Filter Enable - When set, the WiLink discards any frames | ||
185 | * with a BSSID that does not match the BSSID specified by the | ||
186 | * host. | ||
187 | * When clear, the WiLink receives frames from any BSSID. | ||
188 | * 4 MAC Addr Filter - When set, the WiLink discards any frames | ||
189 | * with a destination address that does not match the MAC address | ||
190 | * of the adaptor. | ||
191 | * When clear, the WiLink receives frames destined to any MAC | ||
192 | * address. | ||
193 | * 3 Promiscuous - When set, the WiLink receives all valid frames | ||
194 | * (i.e., all frames that pass the FCS check). | ||
195 | * When clear, only frames that pass the other filters specified | ||
196 | * are received. | ||
197 | * 2 FCS - When set, the WiLink includes the FCS with the received | ||
198 | * frame. | ||
199 | * When cleared, the FCS is discarded. | ||
200 | * 1 PLCP header - When set, write all data from baseband to frame | ||
201 | * buffer including PHY header. | ||
202 | * 0 Reserved - Always equal to 0. | ||
203 | * | ||
204 | * RX Filter Options Table | ||
205 | * Bit Definition | ||
206 | * === ========== | ||
207 | * 31:12 Reserved - Always equal to 0. | ||
208 | * 11 Association - When set, the WiLink receives all association | ||
209 | * related frames (association request/response, reassocation | ||
210 | * request/response, and disassociation). When clear, these frames | ||
211 | * are discarded. | ||
212 | * 10 Auth/De auth - When set, the WiLink receives all authentication | ||
213 | * and de-authentication frames. When clear, these frames are | ||
214 | * discarded. | ||
215 | * 9 Beacon - When set, the WiLink receives all beacon frames. | ||
216 | * When clear, these frames are discarded. | ||
217 | * 8 Contention Free - When set, the WiLink receives all contention | ||
218 | * free frames. | ||
219 | * When clear, these frames are discarded. | ||
220 | * 7 Control - When set, the WiLink receives all control frames. | ||
221 | * When clear, these frames are discarded. | ||
222 | * 6 Data - When set, the WiLink receives all data frames. | ||
223 | * When clear, these frames are discarded. | ||
224 | * 5 FCS Error - When set, the WiLink receives frames that have FCS | ||
225 | * errors. | ||
226 | * When clear, these frames are discarded. | ||
227 | * 4 Management - When set, the WiLink receives all management | ||
228 | * frames. | ||
229 | * When clear, these frames are discarded. | ||
230 | * 3 Probe Request - When set, the WiLink receives all probe request | ||
231 | * frames. | ||
232 | * When clear, these frames are discarded. | ||
233 | * 2 Probe Response - When set, the WiLink receives all probe | ||
234 | * response frames. | ||
235 | * When clear, these frames are discarded. | ||
236 | * 1 RTS/CTS/ACK - When set, the WiLink receives all RTS, CTS and ACK | ||
237 | * frames. | ||
238 | * When clear, these frames are discarded. | ||
239 | * 0 Rsvd Type/Sub Type - When set, the WiLink receives all frames | ||
240 | * that have reserved frame types and sub types as defined by the | ||
241 | * 802.11 specification. | ||
242 | * When clear, these frames are discarded. | ||
243 | */ | ||
244 | struct acx_rx_config { | ||
245 | struct acx_header header; | ||
246 | |||
247 | __le32 config_options; | ||
248 | __le32 filter_options; | ||
249 | } __packed; | ||
250 | |||
251 | struct acx_packet_detection { | ||
252 | struct acx_header header; | ||
253 | |||
254 | __le32 threshold; | ||
255 | } __packed; | ||
256 | |||
257 | |||
258 | enum acx_slot_type { | ||
259 | SLOT_TIME_LONG = 0, | ||
260 | SLOT_TIME_SHORT = 1, | ||
261 | DEFAULT_SLOT_TIME = SLOT_TIME_SHORT, | ||
262 | MAX_SLOT_TIMES = 0xFF | ||
263 | }; | ||
264 | |||
265 | #define STATION_WONE_INDEX 0 | ||
266 | |||
267 | struct acx_slot { | ||
268 | struct acx_header header; | ||
269 | |||
270 | u8 wone_index; /* Reserved */ | ||
271 | u8 slot_time; | ||
272 | u8 reserved[6]; | ||
273 | } __packed; | ||
274 | |||
275 | |||
276 | #define ACX_MC_ADDRESS_GROUP_MAX (8) | ||
277 | #define ADDRESS_GROUP_MAX_LEN (ETH_ALEN * ACX_MC_ADDRESS_GROUP_MAX) | ||
278 | |||
279 | struct acx_dot11_grp_addr_tbl { | ||
280 | struct acx_header header; | ||
281 | |||
282 | u8 enabled; | ||
283 | u8 num_groups; | ||
284 | u8 pad[2]; | ||
285 | u8 mac_table[ADDRESS_GROUP_MAX_LEN]; | ||
286 | } __packed; | ||
287 | |||
288 | struct acx_rx_timeout { | ||
289 | struct acx_header header; | ||
290 | |||
291 | __le16 ps_poll_timeout; | ||
292 | __le16 upsd_timeout; | ||
293 | } __packed; | ||
294 | |||
295 | struct acx_rts_threshold { | ||
296 | struct acx_header header; | ||
297 | |||
298 | __le16 threshold; | ||
299 | u8 pad[2]; | ||
300 | } __packed; | ||
301 | |||
302 | struct acx_beacon_filter_option { | ||
303 | struct acx_header header; | ||
304 | |||
305 | u8 enable; | ||
306 | /* | ||
307 | * The number of beacons without the unicast TIM | ||
308 | * bit set that the firmware buffers before | ||
309 | * signaling the host about ready frames. | ||
310 | * When set to 0 and the filter is enabled, beacons | ||
311 | * without the unicast TIM bit set are dropped. | ||
312 | */ | ||
313 | u8 max_num_beacons; | ||
314 | u8 pad[2]; | ||
315 | } __packed; | ||
316 | |||
317 | /* | ||
318 | * ACXBeaconFilterEntry (not 221) | ||
319 | * Byte Offset Size (Bytes) Definition | ||
320 | * =========== ============ ========== | ||
321 | * 0 1 IE identifier | ||
322 | * 1 1 Treatment bit mask | ||
323 | * | ||
324 | * ACXBeaconFilterEntry (221) | ||
325 | * Byte Offset Size (Bytes) Definition | ||
326 | * =========== ============ ========== | ||
327 | * 0 1 IE identifier | ||
328 | * 1 1 Treatment bit mask | ||
329 | * 2 3 OUI | ||
330 | * 5 1 Type | ||
331 | * 6 2 Version | ||
332 | * | ||
333 | * | ||
334 | * Treatment bit mask - The information element handling: | ||
335 | * bit 0 - The information element is compared and transferred | ||
336 | * in case of change. | ||
337 | * bit 1 - The information element is transferred to the host | ||
338 | * with each appearance or disappearance. | ||
339 | * Note that both bits can be set at the same time. | ||
340 | */ | ||
341 | #define BEACON_FILTER_TABLE_MAX_IE_NUM (32) | ||
342 | #define BEACON_FILTER_TABLE_MAX_VENDOR_SPECIFIC_IE_NUM (6) | ||
343 | #define BEACON_FILTER_TABLE_IE_ENTRY_SIZE (2) | ||
344 | #define BEACON_FILTER_TABLE_EXTRA_VENDOR_SPECIFIC_IE_SIZE (6) | ||
345 | #define BEACON_FILTER_TABLE_MAX_SIZE ((BEACON_FILTER_TABLE_MAX_IE_NUM * \ | ||
346 | BEACON_FILTER_TABLE_IE_ENTRY_SIZE) + \ | ||
347 | (BEACON_FILTER_TABLE_MAX_VENDOR_SPECIFIC_IE_NUM * \ | ||
348 | BEACON_FILTER_TABLE_EXTRA_VENDOR_SPECIFIC_IE_SIZE)) | ||
349 | |||
350 | struct acx_beacon_filter_ie_table { | ||
351 | struct acx_header header; | ||
352 | |||
353 | u8 num_ie; | ||
354 | u8 pad[3]; | ||
355 | u8 table[BEACON_FILTER_TABLE_MAX_SIZE]; | ||
356 | } __packed; | ||
357 | |||
358 | struct acx_conn_monit_params { | ||
359 | struct acx_header header; | ||
360 | |||
361 | __le32 synch_fail_thold; /* number of beacons missed */ | ||
362 | __le32 bss_lose_timeout; /* number of TU's from synch fail */ | ||
363 | } __packed; | ||
364 | |||
365 | struct acx_bt_wlan_coex { | ||
366 | struct acx_header header; | ||
367 | |||
368 | u8 enable; | ||
369 | u8 pad[3]; | ||
370 | } __packed; | ||
371 | |||
372 | struct acx_sta_bt_wlan_coex_param { | ||
373 | struct acx_header header; | ||
374 | |||
375 | __le32 params[CONF_SG_STA_PARAMS_MAX]; | ||
376 | u8 param_idx; | ||
377 | u8 padding[3]; | ||
378 | } __packed; | ||
379 | |||
380 | struct acx_ap_bt_wlan_coex_param { | ||
381 | struct acx_header header; | ||
382 | |||
383 | __le32 params[CONF_SG_AP_PARAMS_MAX]; | ||
384 | u8 param_idx; | ||
385 | u8 padding[3]; | ||
386 | } __packed; | ||
387 | |||
388 | |||
389 | struct acx_dco_itrim_params { | ||
390 | struct acx_header header; | ||
391 | |||
392 | u8 enable; | ||
393 | u8 padding[3]; | ||
394 | __le32 timeout; | ||
395 | } __packed; | ||
396 | |||
397 | struct acx_energy_detection { | ||
398 | struct acx_header header; | ||
399 | |||
400 | /* The RX Clear Channel Assessment threshold in the PHY */ | ||
401 | __le16 rx_cca_threshold; | ||
402 | u8 tx_energy_detection; | ||
403 | u8 pad; | ||
404 | } __packed; | ||
405 | |||
406 | struct acx_beacon_broadcast { | ||
407 | struct acx_header header; | ||
408 | |||
409 | __le16 beacon_rx_timeout; | ||
410 | __le16 broadcast_timeout; | ||
411 | |||
412 | /* Enables receiving of broadcast packets in PS mode */ | ||
413 | u8 rx_broadcast_in_ps; | ||
414 | |||
415 | /* Consecutive PS Poll failures before updating the host */ | ||
416 | u8 ps_poll_threshold; | ||
417 | u8 pad[2]; | ||
418 | } __packed; | ||
419 | |||
420 | struct acx_event_mask { | ||
421 | struct acx_header header; | ||
422 | |||
423 | __le32 event_mask; | ||
424 | __le32 high_event_mask; /* Unused */ | ||
425 | } __packed; | ||
426 | |||
427 | #define CFG_RX_FCS BIT(2) | ||
428 | #define CFG_RX_ALL_GOOD BIT(3) | ||
429 | #define CFG_UNI_FILTER_EN BIT(4) | ||
430 | #define CFG_BSSID_FILTER_EN BIT(5) | ||
431 | #define CFG_MC_FILTER_EN BIT(6) | ||
432 | #define CFG_MC_ADDR0_EN BIT(7) | ||
433 | #define CFG_MC_ADDR1_EN BIT(8) | ||
434 | #define CFG_BC_REJECT_EN BIT(9) | ||
435 | #define CFG_SSID_FILTER_EN BIT(10) | ||
436 | #define CFG_RX_INT_FCS_ERROR BIT(11) | ||
437 | #define CFG_RX_INT_ENCRYPTED BIT(12) | ||
438 | #define CFG_RX_WR_RX_STATUS BIT(13) | ||
439 | #define CFG_RX_FILTER_NULTI BIT(14) | ||
440 | #define CFG_RX_RESERVE BIT(15) | ||
441 | #define CFG_RX_TIMESTAMP_TSF BIT(16) | ||
442 | |||
443 | #define CFG_RX_RSV_EN BIT(0) | ||
444 | #define CFG_RX_RCTS_ACK BIT(1) | ||
445 | #define CFG_RX_PRSP_EN BIT(2) | ||
446 | #define CFG_RX_PREQ_EN BIT(3) | ||
447 | #define CFG_RX_MGMT_EN BIT(4) | ||
448 | #define CFG_RX_FCS_ERROR BIT(5) | ||
449 | #define CFG_RX_DATA_EN BIT(6) | ||
450 | #define CFG_RX_CTL_EN BIT(7) | ||
451 | #define CFG_RX_CF_EN BIT(8) | ||
452 | #define CFG_RX_BCN_EN BIT(9) | ||
453 | #define CFG_RX_AUTH_EN BIT(10) | ||
454 | #define CFG_RX_ASSOC_EN BIT(11) | ||
455 | |||
456 | #define SCAN_PASSIVE BIT(0) | ||
457 | #define SCAN_5GHZ_BAND BIT(1) | ||
458 | #define SCAN_TRIGGERED BIT(2) | ||
459 | #define SCAN_PRIORITY_HIGH BIT(3) | ||
460 | |||
461 | /* When set, disable HW encryption */ | ||
462 | #define DF_ENCRYPTION_DISABLE 0x01 | ||
463 | #define DF_SNIFF_MODE_ENABLE 0x80 | ||
464 | |||
465 | struct acx_feature_config { | ||
466 | struct acx_header header; | ||
467 | |||
468 | __le32 options; | ||
469 | __le32 data_flow_options; | ||
470 | } __packed; | ||
471 | |||
472 | struct acx_current_tx_power { | ||
473 | struct acx_header header; | ||
474 | |||
475 | u8 current_tx_power; | ||
476 | u8 padding[3]; | ||
477 | } __packed; | ||
478 | |||
479 | struct acx_wake_up_condition { | ||
480 | struct acx_header header; | ||
481 | |||
482 | u8 wake_up_event; /* Only one bit can be set */ | ||
483 | u8 listen_interval; | ||
484 | u8 pad[2]; | ||
485 | } __packed; | ||
486 | |||
487 | struct acx_aid { | ||
488 | struct acx_header header; | ||
489 | |||
490 | /* | ||
491 | * To be set when associated with an AP. | ||
492 | */ | ||
493 | __le16 aid; | ||
494 | u8 pad[2]; | ||
495 | } __packed; | ||
496 | |||
497 | enum acx_preamble_type { | ||
498 | ACX_PREAMBLE_LONG = 0, | ||
499 | ACX_PREAMBLE_SHORT = 1 | ||
500 | }; | ||
501 | |||
502 | struct acx_preamble { | ||
503 | struct acx_header header; | ||
504 | |||
505 | /* | ||
506 | * When set, the WiLink transmits the frames with a short preamble and | ||
507 | * when cleared, the WiLink transmits the frames with a long preamble. | ||
508 | */ | ||
509 | u8 preamble; | ||
510 | u8 padding[3]; | ||
511 | } __packed; | ||
512 | |||
513 | enum acx_ctsprotect_type { | ||
514 | CTSPROTECT_DISABLE = 0, | ||
515 | CTSPROTECT_ENABLE = 1 | ||
516 | }; | ||
517 | |||
518 | struct acx_ctsprotect { | ||
519 | struct acx_header header; | ||
520 | u8 ctsprotect; | ||
521 | u8 padding[3]; | ||
522 | } __packed; | ||
523 | |||
524 | struct acx_tx_statistics { | ||
525 | __le32 internal_desc_overflow; | ||
526 | } __packed; | ||
527 | |||
528 | struct acx_rx_statistics { | ||
529 | __le32 out_of_mem; | ||
530 | __le32 hdr_overflow; | ||
531 | __le32 hw_stuck; | ||
532 | __le32 dropped; | ||
533 | __le32 fcs_err; | ||
534 | __le32 xfr_hint_trig; | ||
535 | __le32 path_reset; | ||
536 | __le32 reset_counter; | ||
537 | } __packed; | ||
538 | |||
539 | struct acx_dma_statistics { | ||
540 | __le32 rx_requested; | ||
541 | __le32 rx_errors; | ||
542 | __le32 tx_requested; | ||
543 | __le32 tx_errors; | ||
544 | } __packed; | ||
545 | |||
546 | struct acx_isr_statistics { | ||
547 | /* host command complete */ | ||
548 | __le32 cmd_cmplt; | ||
549 | |||
550 | /* fiqisr() */ | ||
551 | __le32 fiqs; | ||
552 | |||
553 | /* (INT_STS_ND & INT_TRIG_RX_HEADER) */ | ||
554 | __le32 rx_headers; | ||
555 | |||
556 | /* (INT_STS_ND & INT_TRIG_RX_CMPLT) */ | ||
557 | __le32 rx_completes; | ||
558 | |||
559 | /* (INT_STS_ND & INT_TRIG_NO_RX_BUF) */ | ||
560 | __le32 rx_mem_overflow; | ||
561 | |||
562 | /* (INT_STS_ND & INT_TRIG_S_RX_RDY) */ | ||
563 | __le32 rx_rdys; | ||
564 | |||
565 | /* irqisr() */ | ||
566 | __le32 irqs; | ||
567 | |||
568 | /* (INT_STS_ND & INT_TRIG_TX_PROC) */ | ||
569 | __le32 tx_procs; | ||
570 | |||
571 | /* (INT_STS_ND & INT_TRIG_DECRYPT_DONE) */ | ||
572 | __le32 decrypt_done; | ||
573 | |||
574 | /* (INT_STS_ND & INT_TRIG_DMA0) */ | ||
575 | __le32 dma0_done; | ||
576 | |||
577 | /* (INT_STS_ND & INT_TRIG_DMA1) */ | ||
578 | __le32 dma1_done; | ||
579 | |||
580 | /* (INT_STS_ND & INT_TRIG_TX_EXC_CMPLT) */ | ||
581 | __le32 tx_exch_complete; | ||
582 | |||
583 | /* (INT_STS_ND & INT_TRIG_COMMAND) */ | ||
584 | __le32 commands; | ||
585 | |||
586 | /* (INT_STS_ND & INT_TRIG_RX_PROC) */ | ||
587 | __le32 rx_procs; | ||
588 | |||
589 | /* (INT_STS_ND & INT_TRIG_PM_802) */ | ||
590 | __le32 hw_pm_mode_changes; | ||
591 | |||
592 | /* (INT_STS_ND & INT_TRIG_ACKNOWLEDGE) */ | ||
593 | __le32 host_acknowledges; | ||
594 | |||
595 | /* (INT_STS_ND & INT_TRIG_PM_PCI) */ | ||
596 | __le32 pci_pm; | ||
597 | |||
598 | /* (INT_STS_ND & INT_TRIG_ACM_WAKEUP) */ | ||
599 | __le32 wakeups; | ||
600 | |||
601 | /* (INT_STS_ND & INT_TRIG_LOW_RSSI) */ | ||
602 | __le32 low_rssi; | ||
603 | } __packed; | ||
604 | |||
605 | struct acx_wep_statistics { | ||
606 | /* WEP address keys configured */ | ||
607 | __le32 addr_key_count; | ||
608 | |||
609 | /* default keys configured */ | ||
610 | __le32 default_key_count; | ||
611 | |||
612 | __le32 reserved; | ||
613 | |||
614 | /* number of times that WEP key not found on lookup */ | ||
615 | __le32 key_not_found; | ||
616 | |||
617 | /* number of times that WEP key decryption failed */ | ||
618 | __le32 decrypt_fail; | ||
619 | |||
620 | /* WEP packets decrypted */ | ||
621 | __le32 packets; | ||
622 | |||
623 | /* WEP decrypt interrupts */ | ||
624 | __le32 interrupt; | ||
625 | } __packed; | ||
626 | |||
627 | #define ACX_MISSED_BEACONS_SPREAD 10 | ||
628 | |||
629 | struct acx_pwr_statistics { | ||
630 | /* the amount of enters into power save mode (both PD & ELP) */ | ||
631 | __le32 ps_enter; | ||
632 | |||
633 | /* the amount of enters into ELP mode */ | ||
634 | __le32 elp_enter; | ||
635 | |||
636 | /* the amount of missing beacon interrupts to the host */ | ||
637 | __le32 missing_bcns; | ||
638 | |||
639 | /* the amount of wake on host-access times */ | ||
640 | __le32 wake_on_host; | ||
641 | |||
642 | /* the amount of wake on timer-expire */ | ||
643 | __le32 wake_on_timer_exp; | ||
644 | |||
645 | /* the number of packets that were transmitted with PS bit set */ | ||
646 | __le32 tx_with_ps; | ||
647 | |||
648 | /* the number of packets that were transmitted with PS bit clear */ | ||
649 | __le32 tx_without_ps; | ||
650 | |||
651 | /* the number of received beacons */ | ||
652 | __le32 rcvd_beacons; | ||
653 | |||
654 | /* the number of entering into PowerOn (power save off) */ | ||
655 | __le32 power_save_off; | ||
656 | |||
657 | /* the number of entries into power save mode */ | ||
658 | __le16 enable_ps; | ||
659 | |||
660 | /* | ||
661 | * the number of exits from power save, not including failed PS | ||
662 | * transitions | ||
663 | */ | ||
664 | __le16 disable_ps; | ||
665 | |||
666 | /* | ||
667 | * the number of times the TSF counter was adjusted because | ||
668 | * of drift | ||
669 | */ | ||
670 | __le32 fix_tsf_ps; | ||
671 | |||
672 | /* Gives statistics about the spread continuous missed beacons. | ||
673 | * The 16 LSB are dedicated for the PS mode. | ||
674 | * The 16 MSB are dedicated for the PS mode. | ||
675 | * cont_miss_bcns_spread[0] - single missed beacon. | ||
676 | * cont_miss_bcns_spread[1] - two continuous missed beacons. | ||
677 | * cont_miss_bcns_spread[2] - three continuous missed beacons. | ||
678 | * ... | ||
679 | * cont_miss_bcns_spread[9] - ten and more continuous missed beacons. | ||
680 | */ | ||
681 | __le32 cont_miss_bcns_spread[ACX_MISSED_BEACONS_SPREAD]; | ||
682 | |||
683 | /* the number of beacons in awake mode */ | ||
684 | __le32 rcvd_awake_beacons; | ||
685 | } __packed; | ||
686 | |||
687 | struct acx_mic_statistics { | ||
688 | __le32 rx_pkts; | ||
689 | __le32 calc_failure; | ||
690 | } __packed; | ||
691 | |||
692 | struct acx_aes_statistics { | ||
693 | __le32 encrypt_fail; | ||
694 | __le32 decrypt_fail; | ||
695 | __le32 encrypt_packets; | ||
696 | __le32 decrypt_packets; | ||
697 | __le32 encrypt_interrupt; | ||
698 | __le32 decrypt_interrupt; | ||
699 | } __packed; | ||
700 | |||
701 | struct acx_event_statistics { | ||
702 | __le32 heart_beat; | ||
703 | __le32 calibration; | ||
704 | __le32 rx_mismatch; | ||
705 | __le32 rx_mem_empty; | ||
706 | __le32 rx_pool; | ||
707 | __le32 oom_late; | ||
708 | __le32 phy_transmit_error; | ||
709 | __le32 tx_stuck; | ||
710 | } __packed; | ||
711 | |||
712 | struct acx_ps_statistics { | ||
713 | __le32 pspoll_timeouts; | ||
714 | __le32 upsd_timeouts; | ||
715 | __le32 upsd_max_sptime; | ||
716 | __le32 upsd_max_apturn; | ||
717 | __le32 pspoll_max_apturn; | ||
718 | __le32 pspoll_utilization; | ||
719 | __le32 upsd_utilization; | ||
720 | } __packed; | ||
721 | |||
722 | struct acx_rxpipe_statistics { | ||
723 | __le32 rx_prep_beacon_drop; | ||
724 | __le32 descr_host_int_trig_rx_data; | ||
725 | __le32 beacon_buffer_thres_host_int_trig_rx_data; | ||
726 | __le32 missed_beacon_host_int_trig_rx_data; | ||
727 | __le32 tx_xfr_host_int_trig_rx_data; | ||
728 | } __packed; | ||
729 | |||
730 | struct acx_statistics { | ||
731 | struct acx_header header; | ||
732 | |||
733 | struct acx_tx_statistics tx; | ||
734 | struct acx_rx_statistics rx; | ||
735 | struct acx_dma_statistics dma; | ||
736 | struct acx_isr_statistics isr; | ||
737 | struct acx_wep_statistics wep; | ||
738 | struct acx_pwr_statistics pwr; | ||
739 | struct acx_aes_statistics aes; | ||
740 | struct acx_mic_statistics mic; | ||
741 | struct acx_event_statistics event; | ||
742 | struct acx_ps_statistics ps; | ||
743 | struct acx_rxpipe_statistics rxpipe; | ||
744 | } __packed; | ||
745 | |||
746 | struct acx_rate_class { | ||
747 | __le32 enabled_rates; | ||
748 | u8 short_retry_limit; | ||
749 | u8 long_retry_limit; | ||
750 | u8 aflags; | ||
751 | u8 reserved; | ||
752 | }; | ||
753 | |||
754 | #define ACX_TX_BASIC_RATE 0 | ||
755 | #define ACX_TX_AP_FULL_RATE 1 | ||
756 | #define ACX_TX_RATE_POLICY_CNT 2 | ||
757 | struct acx_sta_rate_policy { | ||
758 | struct acx_header header; | ||
759 | |||
760 | __le32 rate_class_cnt; | ||
761 | struct acx_rate_class rate_class[CONF_TX_MAX_RATE_CLASSES]; | ||
762 | } __packed; | ||
763 | |||
764 | |||
765 | #define ACX_TX_AP_MODE_MGMT_RATE 4 | ||
766 | #define ACX_TX_AP_MODE_BCST_RATE 5 | ||
767 | struct acx_ap_rate_policy { | ||
768 | struct acx_header header; | ||
769 | |||
770 | __le32 rate_policy_idx; | ||
771 | struct acx_rate_class rate_policy; | ||
772 | } __packed; | ||
773 | |||
774 | struct acx_ac_cfg { | ||
775 | struct acx_header header; | ||
776 | u8 ac; | ||
777 | u8 cw_min; | ||
778 | __le16 cw_max; | ||
779 | u8 aifsn; | ||
780 | u8 reserved; | ||
781 | __le16 tx_op_limit; | ||
782 | } __packed; | ||
783 | |||
784 | struct acx_tid_config { | ||
785 | struct acx_header header; | ||
786 | u8 queue_id; | ||
787 | u8 channel_type; | ||
788 | u8 tsid; | ||
789 | u8 ps_scheme; | ||
790 | u8 ack_policy; | ||
791 | u8 padding[3]; | ||
792 | __le32 apsd_conf[2]; | ||
793 | } __packed; | ||
794 | |||
795 | struct acx_frag_threshold { | ||
796 | struct acx_header header; | ||
797 | __le16 frag_threshold; | ||
798 | u8 padding[2]; | ||
799 | } __packed; | ||
800 | |||
801 | struct acx_tx_config_options { | ||
802 | struct acx_header header; | ||
803 | __le16 tx_compl_timeout; /* msec */ | ||
804 | __le16 tx_compl_threshold; /* number of packets */ | ||
805 | } __packed; | ||
806 | |||
807 | #define ACX_TX_DESCRIPTORS 32 | ||
808 | |||
809 | struct wl1271_acx_ap_config_memory { | ||
810 | struct acx_header header; | ||
811 | |||
812 | u8 rx_mem_block_num; | ||
813 | u8 tx_min_mem_block_num; | ||
814 | u8 num_stations; | ||
815 | u8 num_ssid_profiles; | ||
816 | __le32 total_tx_descriptors; | ||
817 | } __packed; | ||
818 | |||
819 | struct wl1271_acx_sta_config_memory { | ||
820 | struct acx_header header; | ||
821 | |||
822 | u8 rx_mem_block_num; | ||
823 | u8 tx_min_mem_block_num; | ||
824 | u8 num_stations; | ||
825 | u8 num_ssid_profiles; | ||
826 | __le32 total_tx_descriptors; | ||
827 | u8 dyn_mem_enable; | ||
828 | u8 tx_free_req; | ||
829 | u8 rx_free_req; | ||
830 | u8 tx_min; | ||
831 | u8 fwlog_blocks; | ||
832 | u8 padding[3]; | ||
833 | } __packed; | ||
834 | |||
835 | struct wl1271_acx_mem_map { | ||
836 | struct acx_header header; | ||
837 | |||
838 | __le32 code_start; | ||
839 | __le32 code_end; | ||
840 | |||
841 | __le32 wep_defkey_start; | ||
842 | __le32 wep_defkey_end; | ||
843 | |||
844 | __le32 sta_table_start; | ||
845 | __le32 sta_table_end; | ||
846 | |||
847 | __le32 packet_template_start; | ||
848 | __le32 packet_template_end; | ||
849 | |||
850 | /* Address of the TX result interface (control block) */ | ||
851 | __le32 tx_result; | ||
852 | __le32 tx_result_queue_start; | ||
853 | |||
854 | __le32 queue_memory_start; | ||
855 | __le32 queue_memory_end; | ||
856 | |||
857 | __le32 packet_memory_pool_start; | ||
858 | __le32 packet_memory_pool_end; | ||
859 | |||
860 | __le32 debug_buffer1_start; | ||
861 | __le32 debug_buffer1_end; | ||
862 | |||
863 | __le32 debug_buffer2_start; | ||
864 | __le32 debug_buffer2_end; | ||
865 | |||
866 | /* Number of blocks FW allocated for TX packets */ | ||
867 | __le32 num_tx_mem_blocks; | ||
868 | |||
869 | /* Number of blocks FW allocated for RX packets */ | ||
870 | __le32 num_rx_mem_blocks; | ||
871 | |||
872 | /* the following 4 fields are valid in SLAVE mode only */ | ||
873 | u8 *tx_cbuf; | ||
874 | u8 *rx_cbuf; | ||
875 | __le32 rx_ctrl; | ||
876 | __le32 tx_ctrl; | ||
877 | } __packed; | ||
878 | |||
879 | struct wl1271_acx_rx_config_opt { | ||
880 | struct acx_header header; | ||
881 | |||
882 | __le16 mblk_threshold; | ||
883 | __le16 threshold; | ||
884 | __le16 timeout; | ||
885 | u8 queue_type; | ||
886 | u8 reserved; | ||
887 | } __packed; | ||
888 | |||
889 | |||
890 | struct wl1271_acx_bet_enable { | ||
891 | struct acx_header header; | ||
892 | |||
893 | u8 enable; | ||
894 | u8 max_consecutive; | ||
895 | u8 padding[2]; | ||
896 | } __packed; | ||
897 | |||
898 | #define ACX_IPV4_VERSION 4 | ||
899 | #define ACX_IPV6_VERSION 6 | ||
900 | #define ACX_IPV4_ADDR_SIZE 4 | ||
901 | |||
902 | /* bitmap of enabled arp_filter features */ | ||
903 | #define ACX_ARP_FILTER_ARP_FILTERING BIT(0) | ||
904 | #define ACX_ARP_FILTER_AUTO_ARP BIT(1) | ||
905 | |||
906 | struct wl1271_acx_arp_filter { | ||
907 | struct acx_header header; | ||
908 | u8 version; /* ACX_IPV4_VERSION, ACX_IPV6_VERSION */ | ||
909 | u8 enable; /* bitmap of enabled ARP filtering features */ | ||
910 | u8 padding[2]; | ||
911 | u8 address[16]; /* The configured device IP address - all ARP | ||
912 | requests directed to this IP address will pass | ||
913 | through. For IPv4, the first four bytes are | ||
914 | used. */ | ||
915 | } __packed; | ||
916 | |||
917 | struct wl1271_acx_pm_config { | ||
918 | struct acx_header header; | ||
919 | |||
920 | __le32 host_clk_settling_time; | ||
921 | u8 host_fast_wakeup_support; | ||
922 | u8 padding[3]; | ||
923 | } __packed; | ||
924 | |||
925 | struct wl1271_acx_keep_alive_mode { | ||
926 | struct acx_header header; | ||
927 | |||
928 | u8 enabled; | ||
929 | u8 padding[3]; | ||
930 | } __packed; | ||
931 | |||
932 | enum { | ||
933 | ACX_KEEP_ALIVE_NO_TX = 0, | ||
934 | ACX_KEEP_ALIVE_PERIOD_ONLY | ||
935 | }; | ||
936 | |||
937 | enum { | ||
938 | ACX_KEEP_ALIVE_TPL_INVALID = 0, | ||
939 | ACX_KEEP_ALIVE_TPL_VALID | ||
940 | }; | ||
941 | |||
942 | struct wl1271_acx_keep_alive_config { | ||
943 | struct acx_header header; | ||
944 | |||
945 | __le32 period; | ||
946 | u8 index; | ||
947 | u8 tpl_validation; | ||
948 | u8 trigger; | ||
949 | u8 padding; | ||
950 | } __packed; | ||
951 | |||
952 | #define HOST_IF_CFG_RX_FIFO_ENABLE BIT(0) | ||
953 | #define HOST_IF_CFG_TX_EXTRA_BLKS_SWAP BIT(1) | ||
954 | #define HOST_IF_CFG_TX_PAD_TO_SDIO_BLK BIT(3) | ||
955 | |||
956 | struct wl1271_acx_host_config_bitmap { | ||
957 | struct acx_header header; | ||
958 | |||
959 | __le32 host_cfg_bitmap; | ||
960 | } __packed; | ||
961 | |||
962 | enum { | ||
963 | WL1271_ACX_TRIG_TYPE_LEVEL = 0, | ||
964 | WL1271_ACX_TRIG_TYPE_EDGE, | ||
965 | }; | ||
966 | |||
967 | enum { | ||
968 | WL1271_ACX_TRIG_DIR_LOW = 0, | ||
969 | WL1271_ACX_TRIG_DIR_HIGH, | ||
970 | WL1271_ACX_TRIG_DIR_BIDIR, | ||
971 | }; | ||
972 | |||
973 | enum { | ||
974 | WL1271_ACX_TRIG_ENABLE = 1, | ||
975 | WL1271_ACX_TRIG_DISABLE, | ||
976 | }; | ||
977 | |||
978 | enum { | ||
979 | WL1271_ACX_TRIG_METRIC_RSSI_BEACON = 0, | ||
980 | WL1271_ACX_TRIG_METRIC_RSSI_DATA, | ||
981 | WL1271_ACX_TRIG_METRIC_SNR_BEACON, | ||
982 | WL1271_ACX_TRIG_METRIC_SNR_DATA, | ||
983 | }; | ||
984 | |||
985 | enum { | ||
986 | WL1271_ACX_TRIG_IDX_RSSI = 0, | ||
987 | WL1271_ACX_TRIG_COUNT = 8, | ||
988 | }; | ||
989 | |||
990 | struct wl1271_acx_rssi_snr_trigger { | ||
991 | struct acx_header header; | ||
992 | |||
993 | __le16 threshold; | ||
994 | __le16 pacing; /* 0 - 60000 ms */ | ||
995 | u8 metric; | ||
996 | u8 type; | ||
997 | u8 dir; | ||
998 | u8 hysteresis; | ||
999 | u8 index; | ||
1000 | u8 enable; | ||
1001 | u8 padding[2]; | ||
1002 | }; | ||
1003 | |||
1004 | struct wl1271_acx_rssi_snr_avg_weights { | ||
1005 | struct acx_header header; | ||
1006 | |||
1007 | u8 rssi_beacon; | ||
1008 | u8 rssi_data; | ||
1009 | u8 snr_beacon; | ||
1010 | u8 snr_data; | ||
1011 | }; | ||
1012 | |||
1013 | /* | ||
1014 | * ACX_PEER_HT_CAP | ||
1015 | * Configure HT capabilities - declare the capabilities of the peer | ||
1016 | * we are connected to. | ||
1017 | */ | ||
1018 | struct wl1271_acx_ht_capabilities { | ||
1019 | struct acx_header header; | ||
1020 | |||
1021 | /* | ||
1022 | * bit 0 - Allow HT Operation | ||
1023 | * bit 1 - Allow Greenfield format in TX | ||
1024 | * bit 2 - Allow Short GI in TX | ||
1025 | * bit 3 - Allow L-SIG TXOP Protection in TX | ||
1026 | * bit 4 - Allow HT Control fields in TX. | ||
1027 | * Note, driver will still leave space for HT control in packets | ||
1028 | * regardless of the value of this field. FW will be responsible | ||
1029 | * to drop the HT field from any frame when this Bit set to 0. | ||
1030 | * bit 5 - Allow RD initiation in TXOP. FW is allowed to initate RD. | ||
1031 | * Exact policy setting for this feature is TBD. | ||
1032 | * Note, this bit can only be set to 1 if bit 3 is set to 1. | ||
1033 | */ | ||
1034 | __le32 ht_capabilites; | ||
1035 | |||
1036 | /* | ||
1037 | * Indicates to which peer these capabilities apply. | ||
1038 | * For infrastructure use ff:ff:ff:ff:ff:ff that indicates relevance | ||
1039 | * for all peers. | ||
1040 | * Only valid for IBSS/DLS operation. | ||
1041 | */ | ||
1042 | u8 mac_address[ETH_ALEN]; | ||
1043 | |||
1044 | /* | ||
1045 | * This the maximum A-MPDU length supported by the AP. The FW may not | ||
1046 | * exceed this length when sending A-MPDUs | ||
1047 | */ | ||
1048 | u8 ampdu_max_length; | ||
1049 | |||
1050 | /* This is the minimal spacing required when sending A-MPDUs to the AP*/ | ||
1051 | u8 ampdu_min_spacing; | ||
1052 | } __packed; | ||
1053 | |||
1054 | /* HT Capabilites Fw Bit Mask Mapping */ | ||
1055 | #define WL1271_ACX_FW_CAP_HT_OPERATION BIT(0) | ||
1056 | #define WL1271_ACX_FW_CAP_GREENFIELD_FRAME_FORMAT BIT(1) | ||
1057 | #define WL1271_ACX_FW_CAP_SHORT_GI_FOR_20MHZ_PACKETS BIT(2) | ||
1058 | #define WL1271_ACX_FW_CAP_LSIG_TXOP_PROTECTION BIT(3) | ||
1059 | #define WL1271_ACX_FW_CAP_HT_CONTROL_FIELDS BIT(4) | ||
1060 | #define WL1271_ACX_FW_CAP_RD_INITIATION BIT(5) | ||
1061 | |||
1062 | |||
1063 | /* | ||
1064 | * ACX_HT_BSS_OPERATION | ||
1065 | * Configure HT capabilities - AP rules for behavior in the BSS. | ||
1066 | */ | ||
1067 | struct wl1271_acx_ht_information { | ||
1068 | struct acx_header header; | ||
1069 | |||
1070 | /* Values: 0 - RIFS not allowed, 1 - RIFS allowed */ | ||
1071 | u8 rifs_mode; | ||
1072 | |||
1073 | /* Values: 0 - 3 like in spec */ | ||
1074 | u8 ht_protection; | ||
1075 | |||
1076 | /* Values: 0 - GF protection not required, 1 - GF protection required */ | ||
1077 | u8 gf_protection; | ||
1078 | |||
1079 | /*Values: 0 - TX Burst limit not required, 1 - TX Burst Limit required*/ | ||
1080 | u8 ht_tx_burst_limit; | ||
1081 | |||
1082 | /* | ||
1083 | * Values: 0 - Dual CTS protection not required, | ||
1084 | * 1 - Dual CTS Protection required | ||
1085 | * Note: When this value is set to 1 FW will protect all TXOP with RTS | ||
1086 | * frame and will not use CTS-to-self regardless of the value of the | ||
1087 | * ACX_CTS_PROTECTION information element | ||
1088 | */ | ||
1089 | u8 dual_cts_protection; | ||
1090 | |||
1091 | u8 padding[3]; | ||
1092 | } __packed; | ||
1093 | |||
1094 | #define RX_BA_WIN_SIZE 8 | ||
1095 | |||
1096 | struct wl1271_acx_ba_session_policy { | ||
1097 | struct acx_header header; | ||
1098 | /* | ||
1099 | * Specifies role Id, Range 0-7, 0xFF means ANY role. | ||
1100 | * Future use. For now this field is irrelevant | ||
1101 | */ | ||
1102 | u8 role_id; | ||
1103 | /* | ||
1104 | * Specifies Link Id, Range 0-31, 0xFF means ANY Link Id. | ||
1105 | * Not applicable if Role Id is set to ANY. | ||
1106 | */ | ||
1107 | u8 link_id; | ||
1108 | |||
1109 | u8 tid; | ||
1110 | |||
1111 | u8 enable; | ||
1112 | |||
1113 | /* Windows size in number of packets */ | ||
1114 | u16 win_size; | ||
1115 | |||
1116 | /* | ||
1117 | * As initiator inactivity timeout in time units(TU) of 1024us. | ||
1118 | * As receiver reserved | ||
1119 | */ | ||
1120 | u16 inactivity_timeout; | ||
1121 | |||
1122 | /* Initiator = 1/Receiver = 0 */ | ||
1123 | u8 ba_direction; | ||
1124 | |||
1125 | u8 padding[3]; | ||
1126 | } __packed; | ||
1127 | |||
1128 | struct wl1271_acx_ba_receiver_setup { | ||
1129 | struct acx_header header; | ||
1130 | |||
1131 | /* Specifies Link Id, Range 0-31, 0xFF means ANY Link Id */ | ||
1132 | u8 link_id; | ||
1133 | |||
1134 | u8 tid; | ||
1135 | |||
1136 | u8 enable; | ||
1137 | |||
1138 | u8 padding[1]; | ||
1139 | |||
1140 | /* Windows size in number of packets */ | ||
1141 | u16 win_size; | ||
1142 | |||
1143 | /* BA session starting sequence number. RANGE 0-FFF */ | ||
1144 | u16 ssn; | ||
1145 | } __packed; | ||
1146 | |||
1147 | struct wl1271_acx_fw_tsf_information { | ||
1148 | struct acx_header header; | ||
1149 | |||
1150 | __le32 current_tsf_high; | ||
1151 | __le32 current_tsf_low; | ||
1152 | __le32 last_bttt_high; | ||
1153 | __le32 last_tbtt_low; | ||
1154 | u8 last_dtim_count; | ||
1155 | u8 padding[3]; | ||
1156 | } __packed; | ||
1157 | |||
1158 | struct wl1271_acx_ps_rx_streaming { | ||
1159 | struct acx_header header; | ||
1160 | |||
1161 | u8 tid; | ||
1162 | u8 enable; | ||
1163 | |||
1164 | /* interval between triggers (10-100 msec) */ | ||
1165 | u8 period; | ||
1166 | |||
1167 | /* timeout before first trigger (0-200 msec) */ | ||
1168 | u8 timeout; | ||
1169 | } __packed; | ||
1170 | |||
1171 | struct wl1271_acx_ap_max_tx_retry { | ||
1172 | struct acx_header header; | ||
1173 | |||
1174 | /* | ||
1175 | * the number of frames transmission failures before | ||
1176 | * issuing the aging event. | ||
1177 | */ | ||
1178 | __le16 max_tx_retry; | ||
1179 | u8 padding_1[2]; | ||
1180 | } __packed; | ||
1181 | |||
1182 | struct wl1271_acx_config_ps { | ||
1183 | struct acx_header header; | ||
1184 | |||
1185 | u8 exit_retries; | ||
1186 | u8 enter_retries; | ||
1187 | u8 padding[2]; | ||
1188 | __le32 null_data_rate; | ||
1189 | } __packed; | ||
1190 | |||
1191 | struct wl1271_acx_inconnection_sta { | ||
1192 | struct acx_header header; | ||
1193 | |||
1194 | u8 addr[ETH_ALEN]; | ||
1195 | u8 padding1[2]; | ||
1196 | } __packed; | ||
1197 | |||
1198 | struct acx_ap_beacon_filter { | ||
1199 | struct acx_header header; | ||
1200 | |||
1201 | u8 enable; | ||
1202 | u8 pad[3]; | ||
1203 | } __packed; | ||
1204 | |||
1205 | /* | ||
1206 | * ACX_FM_COEX_CFG | ||
1207 | * set the FM co-existence parameters. | ||
1208 | */ | ||
1209 | struct wl1271_acx_fm_coex { | ||
1210 | struct acx_header header; | ||
1211 | /* enable(1) / disable(0) the FM Coex feature */ | ||
1212 | u8 enable; | ||
1213 | /* | ||
1214 | * Swallow period used in COEX PLL swallowing mechanism. | ||
1215 | * 0xFF = use FW default | ||
1216 | */ | ||
1217 | u8 swallow_period; | ||
1218 | /* | ||
1219 | * The N divider used in COEX PLL swallowing mechanism for Fref of | ||
1220 | * 38.4/19.2 Mhz. 0xFF = use FW default | ||
1221 | */ | ||
1222 | u8 n_divider_fref_set_1; | ||
1223 | /* | ||
1224 | * The N divider used in COEX PLL swallowing mechanism for Fref of | ||
1225 | * 26/52 Mhz. 0xFF = use FW default | ||
1226 | */ | ||
1227 | u8 n_divider_fref_set_2; | ||
1228 | /* | ||
1229 | * The M divider used in COEX PLL swallowing mechanism for Fref of | ||
1230 | * 38.4/19.2 Mhz. 0xFFFF = use FW default | ||
1231 | */ | ||
1232 | __le16 m_divider_fref_set_1; | ||
1233 | /* | ||
1234 | * The M divider used in COEX PLL swallowing mechanism for Fref of | ||
1235 | * 26/52 Mhz. 0xFFFF = use FW default | ||
1236 | */ | ||
1237 | __le16 m_divider_fref_set_2; | ||
1238 | /* | ||
1239 | * The time duration in uSec required for COEX PLL to stabilize. | ||
1240 | * 0xFFFFFFFF = use FW default | ||
1241 | */ | ||
1242 | __le32 coex_pll_stabilization_time; | ||
1243 | /* | ||
1244 | * The time duration in uSec required for LDO to stabilize. | ||
1245 | * 0xFFFFFFFF = use FW default | ||
1246 | */ | ||
1247 | __le16 ldo_stabilization_time; | ||
1248 | /* | ||
1249 | * The disturbed frequency band margin around the disturbed frequency | ||
1250 | * center (single sided). | ||
1251 | * For example, if 2 is configured, the following channels will be | ||
1252 | * considered disturbed channel: | ||
1253 | * 80 +- 0.1 MHz, 91 +- 0.1 MHz, 98 +- 0.1 MHz, 102 +- 0.1 MH | ||
1254 | * 0xFF = use FW default | ||
1255 | */ | ||
1256 | u8 fm_disturbed_band_margin; | ||
1257 | /* | ||
1258 | * The swallow clock difference of the swallowing mechanism. | ||
1259 | * 0xFF = use FW default | ||
1260 | */ | ||
1261 | u8 swallow_clk_diff; | ||
1262 | } __packed; | ||
1263 | |||
1264 | enum { | ||
1265 | ACX_WAKE_UP_CONDITIONS = 0x0002, | ||
1266 | ACX_MEM_CFG = 0x0003, | ||
1267 | ACX_SLOT = 0x0004, | ||
1268 | ACX_AC_CFG = 0x0007, | ||
1269 | ACX_MEM_MAP = 0x0008, | ||
1270 | ACX_AID = 0x000A, | ||
1271 | /* ACX_FW_REV is missing in the ref driver, but seems to work */ | ||
1272 | ACX_FW_REV = 0x000D, | ||
1273 | ACX_MEDIUM_USAGE = 0x000F, | ||
1274 | ACX_RX_CFG = 0x0010, | ||
1275 | ACX_TX_QUEUE_CFG = 0x0011, /* FIXME: only used by wl1251 */ | ||
1276 | ACX_STATISTICS = 0x0013, /* Debug API */ | ||
1277 | ACX_PWR_CONSUMPTION_STATISTICS = 0x0014, | ||
1278 | ACX_FEATURE_CFG = 0x0015, | ||
1279 | ACX_TID_CFG = 0x001A, | ||
1280 | ACX_PS_RX_STREAMING = 0x001B, | ||
1281 | ACX_BEACON_FILTER_OPT = 0x001F, | ||
1282 | ACX_AP_BEACON_FILTER_OPT = 0x0020, | ||
1283 | ACX_NOISE_HIST = 0x0021, | ||
1284 | ACX_HDK_VERSION = 0x0022, /* ??? */ | ||
1285 | ACX_PD_THRESHOLD = 0x0023, | ||
1286 | ACX_TX_CONFIG_OPT = 0x0024, | ||
1287 | ACX_CCA_THRESHOLD = 0x0025, | ||
1288 | ACX_EVENT_MBOX_MASK = 0x0026, | ||
1289 | ACX_CONN_MONIT_PARAMS = 0x002D, | ||
1290 | ACX_CONS_TX_FAILURE = 0x002F, | ||
1291 | ACX_BCN_DTIM_OPTIONS = 0x0031, | ||
1292 | ACX_SG_ENABLE = 0x0032, | ||
1293 | ACX_SG_CFG = 0x0033, | ||
1294 | ACX_FM_COEX_CFG = 0x0034, | ||
1295 | ACX_BEACON_FILTER_TABLE = 0x0038, | ||
1296 | ACX_ARP_IP_FILTER = 0x0039, | ||
1297 | ACX_ROAMING_STATISTICS_TBL = 0x003B, | ||
1298 | ACX_RATE_POLICY = 0x003D, | ||
1299 | ACX_CTS_PROTECTION = 0x003E, | ||
1300 | ACX_SLEEP_AUTH = 0x003F, | ||
1301 | ACX_PREAMBLE_TYPE = 0x0040, | ||
1302 | ACX_ERROR_CNT = 0x0041, | ||
1303 | ACX_IBSS_FILTER = 0x0044, | ||
1304 | ACX_SERVICE_PERIOD_TIMEOUT = 0x0045, | ||
1305 | ACX_TSF_INFO = 0x0046, | ||
1306 | ACX_CONFIG_PS_WMM = 0x0049, | ||
1307 | ACX_ENABLE_RX_DATA_FILTER = 0x004A, | ||
1308 | ACX_SET_RX_DATA_FILTER = 0x004B, | ||
1309 | ACX_GET_DATA_FILTER_STATISTICS = 0x004C, | ||
1310 | ACX_RX_CONFIG_OPT = 0x004E, | ||
1311 | ACX_FRAG_CFG = 0x004F, | ||
1312 | ACX_BET_ENABLE = 0x0050, | ||
1313 | ACX_RSSI_SNR_TRIGGER = 0x0051, | ||
1314 | ACX_RSSI_SNR_WEIGHTS = 0x0052, | ||
1315 | ACX_KEEP_ALIVE_MODE = 0x0053, | ||
1316 | ACX_SET_KEEP_ALIVE_CONFIG = 0x0054, | ||
1317 | ACX_BA_SESSION_POLICY_CFG = 0x0055, | ||
1318 | ACX_BA_SESSION_RX_SETUP = 0x0056, | ||
1319 | ACX_PEER_HT_CAP = 0x0057, | ||
1320 | ACX_HT_BSS_OPERATION = 0x0058, | ||
1321 | ACX_COEX_ACTIVITY = 0x0059, | ||
1322 | ACX_SET_DCO_ITRIM_PARAMS = 0x0061, | ||
1323 | ACX_GEN_FW_CMD = 0x0070, | ||
1324 | ACX_HOST_IF_CFG_BITMAP = 0x0071, | ||
1325 | ACX_MAX_TX_FAILURE = 0x0072, | ||
1326 | ACX_UPDATE_INCONNECTION_STA_LIST = 0x0073, | ||
1327 | DOT11_RX_MSDU_LIFE_TIME = 0x1004, | ||
1328 | DOT11_CUR_TX_PWR = 0x100D, | ||
1329 | DOT11_RX_DOT11_MODE = 0x1012, | ||
1330 | DOT11_RTS_THRESHOLD = 0x1013, | ||
1331 | DOT11_GROUP_ADDRESS_TBL = 0x1014, | ||
1332 | ACX_PM_CONFIG = 0x1016, | ||
1333 | ACX_CONFIG_PS = 0x1017, | ||
1334 | ACX_CONFIG_HANGOVER = 0x1018, | ||
1335 | }; | ||
1336 | |||
1337 | |||
1338 | int wl1271_acx_wake_up_conditions(struct wl1271 *wl); | ||
1339 | int wl1271_acx_sleep_auth(struct wl1271 *wl, u8 sleep_auth); | ||
1340 | int wl1271_acx_tx_power(struct wl1271 *wl, int power); | ||
1341 | int wl1271_acx_feature_cfg(struct wl1271 *wl); | ||
1342 | int wl1271_acx_mem_map(struct wl1271 *wl, | ||
1343 | struct acx_header *mem_map, size_t len); | ||
1344 | int wl1271_acx_rx_msdu_life_time(struct wl1271 *wl); | ||
1345 | int wl1271_acx_rx_config(struct wl1271 *wl, u32 config, u32 filter); | ||
1346 | int wl1271_acx_pd_threshold(struct wl1271 *wl); | ||
1347 | int wl1271_acx_slot(struct wl1271 *wl, enum acx_slot_type slot_time); | ||
1348 | int wl1271_acx_group_address_tbl(struct wl1271 *wl, bool enable, | ||
1349 | void *mc_list, u32 mc_list_len); | ||
1350 | int wl1271_acx_service_period_timeout(struct wl1271 *wl); | ||
1351 | int wl1271_acx_rts_threshold(struct wl1271 *wl, u32 rts_threshold); | ||
1352 | int wl1271_acx_dco_itrim_params(struct wl1271 *wl); | ||
1353 | int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, bool enable_filter); | ||
1354 | int wl1271_acx_beacon_filter_table(struct wl1271 *wl); | ||
1355 | int wl1271_acx_conn_monit_params(struct wl1271 *wl, bool enable); | ||
1356 | int wl1271_acx_sg_enable(struct wl1271 *wl, bool enable); | ||
1357 | int wl1271_acx_sta_sg_cfg(struct wl1271 *wl); | ||
1358 | int wl1271_acx_ap_sg_cfg(struct wl1271 *wl); | ||
1359 | int wl1271_acx_cca_threshold(struct wl1271 *wl); | ||
1360 | int wl1271_acx_bcn_dtim_options(struct wl1271 *wl); | ||
1361 | int wl1271_acx_aid(struct wl1271 *wl, u16 aid); | ||
1362 | int wl1271_acx_event_mbox_mask(struct wl1271 *wl, u32 event_mask); | ||
1363 | int wl1271_acx_set_preamble(struct wl1271 *wl, enum acx_preamble_type preamble); | ||
1364 | int wl1271_acx_cts_protect(struct wl1271 *wl, | ||
1365 | enum acx_ctsprotect_type ctsprotect); | ||
1366 | int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats); | ||
1367 | int wl1271_acx_sta_rate_policies(struct wl1271 *wl); | ||
1368 | int wl1271_acx_ap_rate_policy(struct wl1271 *wl, struct conf_tx_rate_class *c, | ||
1369 | u8 idx); | ||
1370 | int wl1271_acx_ac_cfg(struct wl1271 *wl, u8 ac, u8 cw_min, u16 cw_max, | ||
1371 | u8 aifsn, u16 txop); | ||
1372 | int wl1271_acx_tid_cfg(struct wl1271 *wl, u8 queue_id, u8 channel_type, | ||
1373 | u8 tsid, u8 ps_scheme, u8 ack_policy, | ||
1374 | u32 apsd_conf0, u32 apsd_conf1); | ||
1375 | int wl1271_acx_frag_threshold(struct wl1271 *wl, u32 frag_threshold); | ||
1376 | int wl1271_acx_tx_config_options(struct wl1271 *wl); | ||
1377 | int wl1271_acx_ap_mem_cfg(struct wl1271 *wl); | ||
1378 | int wl1271_acx_sta_mem_cfg(struct wl1271 *wl); | ||
1379 | int wl1271_acx_init_mem_config(struct wl1271 *wl); | ||
1380 | int wl1271_acx_host_if_cfg_bitmap(struct wl1271 *wl, u32 host_cfg_bitmap); | ||
1381 | int wl1271_acx_init_rx_interrupt(struct wl1271 *wl); | ||
1382 | int wl1271_acx_smart_reflex(struct wl1271 *wl); | ||
1383 | int wl1271_acx_bet_enable(struct wl1271 *wl, bool enable); | ||
1384 | int wl1271_acx_arp_ip_filter(struct wl1271 *wl, u8 enable, __be32 address); | ||
1385 | int wl1271_acx_pm_config(struct wl1271 *wl); | ||
1386 | int wl1271_acx_keep_alive_mode(struct wl1271 *wl, bool enable); | ||
1387 | int wl1271_acx_keep_alive_config(struct wl1271 *wl, u8 index, u8 tpl_valid); | ||
1388 | int wl1271_acx_rssi_snr_trigger(struct wl1271 *wl, bool enable, | ||
1389 | s16 thold, u8 hyst); | ||
1390 | int wl1271_acx_rssi_snr_avg_weights(struct wl1271 *wl); | ||
1391 | int wl1271_acx_set_ht_capabilities(struct wl1271 *wl, | ||
1392 | struct ieee80211_sta_ht_cap *ht_cap, | ||
1393 | bool allow_ht_operation); | ||
1394 | int wl1271_acx_set_ht_information(struct wl1271 *wl, | ||
1395 | u16 ht_operation_mode); | ||
1396 | int wl1271_acx_set_ba_session(struct wl1271 *wl, | ||
1397 | enum ieee80211_back_parties direction, | ||
1398 | u8 tid_index, u8 policy); | ||
1399 | int wl1271_acx_set_ba_receiver_session(struct wl1271 *wl, u8 tid_index, u16 ssn, | ||
1400 | bool enable); | ||
1401 | int wl1271_acx_tsf_info(struct wl1271 *wl, u64 *mactime); | ||
1402 | int wl1271_acx_ps_rx_streaming(struct wl1271 *wl, bool enable); | ||
1403 | int wl1271_acx_ap_max_tx_retry(struct wl1271 *wl); | ||
1404 | int wl1271_acx_config_ps(struct wl1271 *wl); | ||
1405 | int wl1271_acx_set_inconnection_sta(struct wl1271 *wl, u8 *addr); | ||
1406 | int wl1271_acx_set_ap_beacon_filter(struct wl1271 *wl, bool enable); | ||
1407 | int wl1271_acx_fm_coex(struct wl1271 *wl); | ||
1408 | |||
1409 | #endif /* __WL1271_ACX_H__ */ | ||
diff --git a/drivers/net/wireless/wl12xx/boot.c b/drivers/net/wireless/wl12xx/boot.c new file mode 100644 index 00000000000..454e913bec6 --- /dev/null +++ b/drivers/net/wireless/wl12xx/boot.c | |||
@@ -0,0 +1,876 @@ | |||
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 | |||
27 | #include "acx.h" | ||
28 | #include "reg.h" | ||
29 | #include "boot.h" | ||
30 | #include "io.h" | ||
31 | #include "event.h" | ||
32 | #include "rx.h" | ||
33 | |||
34 | static struct wl1271_partition_set part_table[PART_TABLE_LEN] = { | ||
35 | [PART_DOWN] = { | ||
36 | .mem = { | ||
37 | .start = 0x00000000, | ||
38 | .size = 0x000177c0 | ||
39 | }, | ||
40 | .reg = { | ||
41 | .start = REGISTERS_BASE, | ||
42 | .size = 0x00008800 | ||
43 | }, | ||
44 | .mem2 = { | ||
45 | .start = 0x00000000, | ||
46 | .size = 0x00000000 | ||
47 | }, | ||
48 | .mem3 = { | ||
49 | .start = 0x00000000, | ||
50 | .size = 0x00000000 | ||
51 | }, | ||
52 | }, | ||
53 | |||
54 | [PART_WORK] = { | ||
55 | .mem = { | ||
56 | .start = 0x00040000, | ||
57 | .size = 0x00014fc0 | ||
58 | }, | ||
59 | .reg = { | ||
60 | .start = REGISTERS_BASE, | ||
61 | .size = 0x0000a000 | ||
62 | }, | ||
63 | .mem2 = { | ||
64 | .start = 0x003004f8, | ||
65 | .size = 0x00000004 | ||
66 | }, | ||
67 | .mem3 = { | ||
68 | .start = 0x00040404, | ||
69 | .size = 0x00000000 | ||
70 | }, | ||
71 | }, | ||
72 | |||
73 | [PART_DRPW] = { | ||
74 | .mem = { | ||
75 | .start = 0x00040000, | ||
76 | .size = 0x00014fc0 | ||
77 | }, | ||
78 | .reg = { | ||
79 | .start = DRPW_BASE, | ||
80 | .size = 0x00006000 | ||
81 | }, | ||
82 | .mem2 = { | ||
83 | .start = 0x00000000, | ||
84 | .size = 0x00000000 | ||
85 | }, | ||
86 | .mem3 = { | ||
87 | .start = 0x00000000, | ||
88 | .size = 0x00000000 | ||
89 | } | ||
90 | } | ||
91 | }; | ||
92 | |||
93 | static void wl1271_boot_set_ecpu_ctrl(struct wl1271 *wl, u32 flag) | ||
94 | { | ||
95 | u32 cpu_ctrl; | ||
96 | |||
97 | /* 10.5.0 run the firmware (I) */ | ||
98 | cpu_ctrl = wl1271_read32(wl, ACX_REG_ECPU_CONTROL); | ||
99 | |||
100 | /* 10.5.1 run the firmware (II) */ | ||
101 | cpu_ctrl |= flag; | ||
102 | wl1271_write32(wl, ACX_REG_ECPU_CONTROL, cpu_ctrl); | ||
103 | } | ||
104 | |||
105 | static unsigned int wl12xx_get_fw_ver_quirks(struct wl1271 *wl) | ||
106 | { | ||
107 | unsigned int quirks = 0; | ||
108 | unsigned int *fw_ver = wl->chip.fw_ver; | ||
109 | |||
110 | /* Only for wl127x */ | ||
111 | if ((fw_ver[FW_VER_CHIP] == FW_VER_CHIP_WL127X) && | ||
112 | /* Check STA version */ | ||
113 | (((fw_ver[FW_VER_IF_TYPE] == FW_VER_IF_TYPE_STA) && | ||
114 | (fw_ver[FW_VER_MINOR] < FW_VER_MINOR_1_SPARE_STA_MIN)) || | ||
115 | /* Check AP version */ | ||
116 | ((fw_ver[FW_VER_IF_TYPE] == FW_VER_IF_TYPE_AP) && | ||
117 | (fw_ver[FW_VER_MINOR] < FW_VER_MINOR_1_SPARE_AP_MIN)))) | ||
118 | quirks |= WL12XX_QUIRK_USE_2_SPARE_BLOCKS; | ||
119 | |||
120 | /* Only new station firmwares support routing fw logs to the host */ | ||
121 | if ((fw_ver[FW_VER_IF_TYPE] == FW_VER_IF_TYPE_STA) && | ||
122 | (fw_ver[FW_VER_MINOR] < FW_VER_MINOR_FWLOG_STA_MIN)) | ||
123 | quirks |= WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED; | ||
124 | |||
125 | /* This feature is not yet supported for AP mode */ | ||
126 | if (fw_ver[FW_VER_IF_TYPE] == FW_VER_IF_TYPE_AP) | ||
127 | quirks |= WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED; | ||
128 | |||
129 | return quirks; | ||
130 | } | ||
131 | |||
132 | static void wl1271_parse_fw_ver(struct wl1271 *wl) | ||
133 | { | ||
134 | int ret; | ||
135 | |||
136 | ret = sscanf(wl->chip.fw_ver_str + 4, "%u.%u.%u.%u.%u", | ||
137 | &wl->chip.fw_ver[0], &wl->chip.fw_ver[1], | ||
138 | &wl->chip.fw_ver[2], &wl->chip.fw_ver[3], | ||
139 | &wl->chip.fw_ver[4]); | ||
140 | |||
141 | if (ret != 5) { | ||
142 | wl1271_warning("fw version incorrect value"); | ||
143 | memset(wl->chip.fw_ver, 0, sizeof(wl->chip.fw_ver)); | ||
144 | return; | ||
145 | } | ||
146 | |||
147 | /* Check if any quirks are needed with older fw versions */ | ||
148 | wl->quirks |= wl12xx_get_fw_ver_quirks(wl); | ||
149 | } | ||
150 | |||
151 | static void wl1271_boot_fw_version(struct wl1271 *wl) | ||
152 | { | ||
153 | struct wl1271_static_data static_data; | ||
154 | |||
155 | wl1271_read(wl, wl->cmd_box_addr, &static_data, sizeof(static_data), | ||
156 | false); | ||
157 | |||
158 | strncpy(wl->chip.fw_ver_str, static_data.fw_version, | ||
159 | sizeof(wl->chip.fw_ver_str)); | ||
160 | |||
161 | /* make sure the string is NULL-terminated */ | ||
162 | wl->chip.fw_ver_str[sizeof(wl->chip.fw_ver_str) - 1] = '\0'; | ||
163 | |||
164 | wl1271_parse_fw_ver(wl); | ||
165 | } | ||
166 | |||
167 | static int wl1271_boot_upload_firmware_chunk(struct wl1271 *wl, void *buf, | ||
168 | size_t fw_data_len, u32 dest) | ||
169 | { | ||
170 | struct wl1271_partition_set partition; | ||
171 | int addr, chunk_num, partition_limit; | ||
172 | u8 *p, *chunk; | ||
173 | |||
174 | /* whal_FwCtrl_LoadFwImageSm() */ | ||
175 | |||
176 | wl1271_debug(DEBUG_BOOT, "starting firmware upload"); | ||
177 | |||
178 | wl1271_debug(DEBUG_BOOT, "fw_data_len %zd chunk_size %d", | ||
179 | fw_data_len, CHUNK_SIZE); | ||
180 | |||
181 | if ((fw_data_len % 4) != 0) { | ||
182 | wl1271_error("firmware length not multiple of four"); | ||
183 | return -EIO; | ||
184 | } | ||
185 | |||
186 | chunk = kmalloc(CHUNK_SIZE, GFP_KERNEL); | ||
187 | if (!chunk) { | ||
188 | wl1271_error("allocation for firmware upload chunk failed"); | ||
189 | return -ENOMEM; | ||
190 | } | ||
191 | |||
192 | memcpy(&partition, &part_table[PART_DOWN], sizeof(partition)); | ||
193 | partition.mem.start = dest; | ||
194 | wl1271_set_partition(wl, &partition); | ||
195 | |||
196 | /* 10.1 set partition limit and chunk num */ | ||
197 | chunk_num = 0; | ||
198 | partition_limit = part_table[PART_DOWN].mem.size; | ||
199 | |||
200 | while (chunk_num < fw_data_len / CHUNK_SIZE) { | ||
201 | /* 10.2 update partition, if needed */ | ||
202 | addr = dest + (chunk_num + 2) * CHUNK_SIZE; | ||
203 | if (addr > partition_limit) { | ||
204 | addr = dest + chunk_num * CHUNK_SIZE; | ||
205 | partition_limit = chunk_num * CHUNK_SIZE + | ||
206 | part_table[PART_DOWN].mem.size; | ||
207 | partition.mem.start = addr; | ||
208 | wl1271_set_partition(wl, &partition); | ||
209 | } | ||
210 | |||
211 | /* 10.3 upload the chunk */ | ||
212 | addr = dest + chunk_num * CHUNK_SIZE; | ||
213 | p = buf + chunk_num * CHUNK_SIZE; | ||
214 | memcpy(chunk, p, CHUNK_SIZE); | ||
215 | wl1271_debug(DEBUG_BOOT, "uploading fw chunk 0x%p to 0x%x", | ||
216 | p, addr); | ||
217 | wl1271_write(wl, addr, chunk, CHUNK_SIZE, false); | ||
218 | |||
219 | chunk_num++; | ||
220 | } | ||
221 | |||
222 | /* 10.4 upload the last chunk */ | ||
223 | addr = dest + chunk_num * CHUNK_SIZE; | ||
224 | p = buf + chunk_num * CHUNK_SIZE; | ||
225 | memcpy(chunk, p, fw_data_len % CHUNK_SIZE); | ||
226 | wl1271_debug(DEBUG_BOOT, "uploading fw last chunk (%zd B) 0x%p to 0x%x", | ||
227 | fw_data_len % CHUNK_SIZE, p, addr); | ||
228 | wl1271_write(wl, addr, chunk, fw_data_len % CHUNK_SIZE, false); | ||
229 | |||
230 | kfree(chunk); | ||
231 | return 0; | ||
232 | } | ||
233 | |||
234 | static int wl1271_boot_upload_firmware(struct wl1271 *wl) | ||
235 | { | ||
236 | u32 chunks, addr, len; | ||
237 | int ret = 0; | ||
238 | u8 *fw; | ||
239 | |||
240 | fw = wl->fw; | ||
241 | chunks = be32_to_cpup((__be32 *) fw); | ||
242 | fw += sizeof(u32); | ||
243 | |||
244 | wl1271_debug(DEBUG_BOOT, "firmware chunks to be uploaded: %u", chunks); | ||
245 | |||
246 | while (chunks--) { | ||
247 | addr = be32_to_cpup((__be32 *) fw); | ||
248 | fw += sizeof(u32); | ||
249 | len = be32_to_cpup((__be32 *) fw); | ||
250 | fw += sizeof(u32); | ||
251 | |||
252 | if (len > 300000) { | ||
253 | wl1271_info("firmware chunk too long: %u", len); | ||
254 | return -EINVAL; | ||
255 | } | ||
256 | wl1271_debug(DEBUG_BOOT, "chunk %d addr 0x%x len %u", | ||
257 | chunks, addr, len); | ||
258 | ret = wl1271_boot_upload_firmware_chunk(wl, fw, len, addr); | ||
259 | if (ret != 0) | ||
260 | break; | ||
261 | fw += len; | ||
262 | } | ||
263 | |||
264 | return ret; | ||
265 | } | ||
266 | |||
267 | static int wl1271_boot_upload_nvs(struct wl1271 *wl) | ||
268 | { | ||
269 | size_t nvs_len, burst_len; | ||
270 | int i; | ||
271 | u32 dest_addr, val; | ||
272 | u8 *nvs_ptr, *nvs_aligned; | ||
273 | |||
274 | if (wl->nvs == NULL) | ||
275 | return -ENODEV; | ||
276 | |||
277 | if (wl->chip.id == CHIP_ID_1283_PG20) { | ||
278 | struct wl128x_nvs_file *nvs = (struct wl128x_nvs_file *)wl->nvs; | ||
279 | |||
280 | if (wl->nvs_len == sizeof(struct wl128x_nvs_file)) { | ||
281 | if (nvs->general_params.dual_mode_select) | ||
282 | wl->enable_11a = true; | ||
283 | } else { | ||
284 | wl1271_error("nvs size is not as expected: %zu != %zu", | ||
285 | wl->nvs_len, | ||
286 | sizeof(struct wl128x_nvs_file)); | ||
287 | kfree(wl->nvs); | ||
288 | wl->nvs = NULL; | ||
289 | wl->nvs_len = 0; | ||
290 | return -EILSEQ; | ||
291 | } | ||
292 | |||
293 | /* only the first part of the NVS needs to be uploaded */ | ||
294 | nvs_len = sizeof(nvs->nvs); | ||
295 | nvs_ptr = (u8 *)nvs->nvs; | ||
296 | |||
297 | } else { | ||
298 | struct wl1271_nvs_file *nvs = | ||
299 | (struct wl1271_nvs_file *)wl->nvs; | ||
300 | /* | ||
301 | * FIXME: the LEGACY NVS image support (NVS's missing the 5GHz | ||
302 | * band configurations) can be removed when those NVS files stop | ||
303 | * floating around. | ||
304 | */ | ||
305 | if (wl->nvs_len == sizeof(struct wl1271_nvs_file) || | ||
306 | wl->nvs_len == WL1271_INI_LEGACY_NVS_FILE_SIZE) { | ||
307 | /* for now 11a is unsupported in AP mode */ | ||
308 | if (wl->bss_type != BSS_TYPE_AP_BSS && | ||
309 | nvs->general_params.dual_mode_select) | ||
310 | wl->enable_11a = true; | ||
311 | } | ||
312 | |||
313 | if (wl->nvs_len != sizeof(struct wl1271_nvs_file) && | ||
314 | (wl->nvs_len != WL1271_INI_LEGACY_NVS_FILE_SIZE || | ||
315 | wl->enable_11a)) { | ||
316 | wl1271_error("nvs size is not as expected: %zu != %zu", | ||
317 | wl->nvs_len, sizeof(struct wl1271_nvs_file)); | ||
318 | kfree(wl->nvs); | ||
319 | wl->nvs = NULL; | ||
320 | wl->nvs_len = 0; | ||
321 | return -EILSEQ; | ||
322 | } | ||
323 | |||
324 | /* only the first part of the NVS needs to be uploaded */ | ||
325 | nvs_len = sizeof(nvs->nvs); | ||
326 | nvs_ptr = (u8 *) nvs->nvs; | ||
327 | } | ||
328 | |||
329 | /* update current MAC address to NVS */ | ||
330 | nvs_ptr[11] = wl->mac_addr[0]; | ||
331 | nvs_ptr[10] = wl->mac_addr[1]; | ||
332 | nvs_ptr[6] = wl->mac_addr[2]; | ||
333 | nvs_ptr[5] = wl->mac_addr[3]; | ||
334 | nvs_ptr[4] = wl->mac_addr[4]; | ||
335 | nvs_ptr[3] = wl->mac_addr[5]; | ||
336 | |||
337 | /* | ||
338 | * Layout before the actual NVS tables: | ||
339 | * 1 byte : burst length. | ||
340 | * 2 bytes: destination address. | ||
341 | * n bytes: data to burst copy. | ||
342 | * | ||
343 | * This is ended by a 0 length, then the NVS tables. | ||
344 | */ | ||
345 | |||
346 | /* FIXME: Do we need to check here whether the LSB is 1? */ | ||
347 | while (nvs_ptr[0]) { | ||
348 | burst_len = nvs_ptr[0]; | ||
349 | dest_addr = (nvs_ptr[1] & 0xfe) | ((u32)(nvs_ptr[2] << 8)); | ||
350 | |||
351 | /* | ||
352 | * Due to our new wl1271_translate_reg_addr function, | ||
353 | * we need to add the REGISTER_BASE to the destination | ||
354 | */ | ||
355 | dest_addr += REGISTERS_BASE; | ||
356 | |||
357 | /* We move our pointer to the data */ | ||
358 | nvs_ptr += 3; | ||
359 | |||
360 | for (i = 0; i < burst_len; i++) { | ||
361 | if (nvs_ptr + 3 >= (u8 *) wl->nvs + nvs_len) | ||
362 | goto out_badnvs; | ||
363 | |||
364 | val = (nvs_ptr[0] | (nvs_ptr[1] << 8) | ||
365 | | (nvs_ptr[2] << 16) | (nvs_ptr[3] << 24)); | ||
366 | |||
367 | wl1271_debug(DEBUG_BOOT, | ||
368 | "nvs burst write 0x%x: 0x%x", | ||
369 | dest_addr, val); | ||
370 | wl1271_write32(wl, dest_addr, val); | ||
371 | |||
372 | nvs_ptr += 4; | ||
373 | dest_addr += 4; | ||
374 | } | ||
375 | |||
376 | if (nvs_ptr >= (u8 *) wl->nvs + nvs_len) | ||
377 | goto out_badnvs; | ||
378 | } | ||
379 | |||
380 | /* | ||
381 | * We've reached the first zero length, the first NVS table | ||
382 | * is located at an aligned offset which is at least 7 bytes further. | ||
383 | * NOTE: The wl->nvs->nvs element must be first, in order to | ||
384 | * simplify the casting, we assume it is at the beginning of | ||
385 | * the wl->nvs structure. | ||
386 | */ | ||
387 | nvs_ptr = (u8 *)wl->nvs + | ||
388 | ALIGN(nvs_ptr - (u8 *)wl->nvs + 7, 4); | ||
389 | |||
390 | if (nvs_ptr >= (u8 *) wl->nvs + nvs_len) | ||
391 | goto out_badnvs; | ||
392 | |||
393 | nvs_len -= nvs_ptr - (u8 *)wl->nvs; | ||
394 | |||
395 | /* Now we must set the partition correctly */ | ||
396 | wl1271_set_partition(wl, &part_table[PART_WORK]); | ||
397 | |||
398 | /* Copy the NVS tables to a new block to ensure alignment */ | ||
399 | nvs_aligned = kmemdup(nvs_ptr, nvs_len, GFP_KERNEL); | ||
400 | if (!nvs_aligned) | ||
401 | return -ENOMEM; | ||
402 | |||
403 | /* And finally we upload the NVS tables */ | ||
404 | wl1271_write(wl, CMD_MBOX_ADDRESS, nvs_aligned, nvs_len, false); | ||
405 | |||
406 | kfree(nvs_aligned); | ||
407 | return 0; | ||
408 | |||
409 | out_badnvs: | ||
410 | wl1271_error("nvs data is malformed"); | ||
411 | return -EILSEQ; | ||
412 | } | ||
413 | |||
414 | static void wl1271_boot_enable_interrupts(struct wl1271 *wl) | ||
415 | { | ||
416 | wl1271_enable_interrupts(wl); | ||
417 | wl1271_write32(wl, ACX_REG_INTERRUPT_MASK, | ||
418 | WL1271_ACX_INTR_ALL & ~(WL1271_INTR_MASK)); | ||
419 | wl1271_write32(wl, HI_CFG, HI_CFG_DEF_VAL); | ||
420 | } | ||
421 | |||
422 | static int wl1271_boot_soft_reset(struct wl1271 *wl) | ||
423 | { | ||
424 | unsigned long timeout; | ||
425 | u32 boot_data; | ||
426 | |||
427 | /* perform soft reset */ | ||
428 | wl1271_write32(wl, ACX_REG_SLV_SOFT_RESET, ACX_SLV_SOFT_RESET_BIT); | ||
429 | |||
430 | /* SOFT_RESET is self clearing */ | ||
431 | timeout = jiffies + usecs_to_jiffies(SOFT_RESET_MAX_TIME); | ||
432 | while (1) { | ||
433 | boot_data = wl1271_read32(wl, ACX_REG_SLV_SOFT_RESET); | ||
434 | wl1271_debug(DEBUG_BOOT, "soft reset bootdata 0x%x", boot_data); | ||
435 | if ((boot_data & ACX_SLV_SOFT_RESET_BIT) == 0) | ||
436 | break; | ||
437 | |||
438 | if (time_after(jiffies, timeout)) { | ||
439 | /* 1.2 check pWhalBus->uSelfClearTime if the | ||
440 | * timeout was reached */ | ||
441 | wl1271_error("soft reset timeout"); | ||
442 | return -1; | ||
443 | } | ||
444 | |||
445 | udelay(SOFT_RESET_STALL_TIME); | ||
446 | } | ||
447 | |||
448 | /* disable Rx/Tx */ | ||
449 | wl1271_write32(wl, ENABLE, 0x0); | ||
450 | |||
451 | /* disable auto calibration on start*/ | ||
452 | wl1271_write32(wl, SPARE_A2, 0xffff); | ||
453 | |||
454 | return 0; | ||
455 | } | ||
456 | |||
457 | static int wl1271_boot_run_firmware(struct wl1271 *wl) | ||
458 | { | ||
459 | int loop, ret; | ||
460 | u32 chip_id, intr; | ||
461 | |||
462 | wl1271_boot_set_ecpu_ctrl(wl, ECPU_CONTROL_HALT); | ||
463 | |||
464 | chip_id = wl1271_read32(wl, CHIP_ID_B); | ||
465 | |||
466 | wl1271_debug(DEBUG_BOOT, "chip id after firmware boot: 0x%x", chip_id); | ||
467 | |||
468 | if (chip_id != wl->chip.id) { | ||
469 | wl1271_error("chip id doesn't match after firmware boot"); | ||
470 | return -EIO; | ||
471 | } | ||
472 | |||
473 | /* wait for init to complete */ | ||
474 | loop = 0; | ||
475 | while (loop++ < INIT_LOOP) { | ||
476 | udelay(INIT_LOOP_DELAY); | ||
477 | intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR); | ||
478 | |||
479 | if (intr == 0xffffffff) { | ||
480 | wl1271_error("error reading hardware complete " | ||
481 | "init indication"); | ||
482 | return -EIO; | ||
483 | } | ||
484 | /* check that ACX_INTR_INIT_COMPLETE is enabled */ | ||
485 | else if (intr & WL1271_ACX_INTR_INIT_COMPLETE) { | ||
486 | wl1271_write32(wl, ACX_REG_INTERRUPT_ACK, | ||
487 | WL1271_ACX_INTR_INIT_COMPLETE); | ||
488 | break; | ||
489 | } | ||
490 | } | ||
491 | |||
492 | if (loop > INIT_LOOP) { | ||
493 | wl1271_error("timeout waiting for the hardware to " | ||
494 | "complete initialization"); | ||
495 | return -EIO; | ||
496 | } | ||
497 | |||
498 | /* get hardware config command mail box */ | ||
499 | wl->cmd_box_addr = wl1271_read32(wl, REG_COMMAND_MAILBOX_PTR); | ||
500 | |||
501 | /* get hardware config event mail box */ | ||
502 | wl->event_box_addr = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR); | ||
503 | |||
504 | /* set the working partition to its "running" mode offset */ | ||
505 | wl1271_set_partition(wl, &part_table[PART_WORK]); | ||
506 | |||
507 | wl1271_debug(DEBUG_MAILBOX, "cmd_box_addr 0x%x event_box_addr 0x%x", | ||
508 | wl->cmd_box_addr, wl->event_box_addr); | ||
509 | |||
510 | wl1271_boot_fw_version(wl); | ||
511 | |||
512 | /* | ||
513 | * in case of full asynchronous mode the firmware event must be | ||
514 | * ready to receive event from the command mailbox | ||
515 | */ | ||
516 | |||
517 | /* unmask required mbox events */ | ||
518 | wl->event_mask = BSS_LOSE_EVENT_ID | | ||
519 | SCAN_COMPLETE_EVENT_ID | | ||
520 | PS_REPORT_EVENT_ID | | ||
521 | JOIN_EVENT_COMPLETE_ID | | ||
522 | DISCONNECT_EVENT_COMPLETE_ID | | ||
523 | RSSI_SNR_TRIGGER_0_EVENT_ID | | ||
524 | PSPOLL_DELIVERY_FAILURE_EVENT_ID | | ||
525 | SOFT_GEMINI_SENSE_EVENT_ID | | ||
526 | PERIODIC_SCAN_REPORT_EVENT_ID | | ||
527 | PERIODIC_SCAN_COMPLETE_EVENT_ID; | ||
528 | |||
529 | if (wl->bss_type == BSS_TYPE_AP_BSS) | ||
530 | wl->event_mask |= STA_REMOVE_COMPLETE_EVENT_ID | | ||
531 | INACTIVE_STA_EVENT_ID | | ||
532 | MAX_TX_RETRY_EVENT_ID; | ||
533 | else | ||
534 | wl->event_mask |= DUMMY_PACKET_EVENT_ID | | ||
535 | BA_SESSION_RX_CONSTRAINT_EVENT_ID; | ||
536 | |||
537 | ret = wl1271_event_unmask(wl); | ||
538 | if (ret < 0) { | ||
539 | wl1271_error("EVENT mask setting failed"); | ||
540 | return ret; | ||
541 | } | ||
542 | |||
543 | wl1271_event_mbox_config(wl); | ||
544 | |||
545 | /* firmware startup completed */ | ||
546 | return 0; | ||
547 | } | ||
548 | |||
549 | static int wl1271_boot_write_irq_polarity(struct wl1271 *wl) | ||
550 | { | ||
551 | u32 polarity; | ||
552 | |||
553 | polarity = wl1271_top_reg_read(wl, OCP_REG_POLARITY); | ||
554 | |||
555 | /* We use HIGH polarity, so unset the LOW bit */ | ||
556 | polarity &= ~POLARITY_LOW; | ||
557 | wl1271_top_reg_write(wl, OCP_REG_POLARITY, polarity); | ||
558 | |||
559 | return 0; | ||
560 | } | ||
561 | |||
562 | static void wl1271_boot_hw_version(struct wl1271 *wl) | ||
563 | { | ||
564 | u32 fuse; | ||
565 | |||
566 | fuse = wl1271_top_reg_read(wl, REG_FUSE_DATA_2_1); | ||
567 | fuse = (fuse & PG_VER_MASK) >> PG_VER_OFFSET; | ||
568 | |||
569 | wl->hw_pg_ver = (s8)fuse; | ||
570 | |||
571 | if (((wl->hw_pg_ver & PG_MAJOR_VER_MASK) >> PG_MAJOR_VER_OFFSET) < 3) | ||
572 | wl->quirks |= WL12XX_QUIRK_END_OF_TRANSACTION; | ||
573 | } | ||
574 | |||
575 | static int wl128x_switch_tcxo_to_fref(struct wl1271 *wl) | ||
576 | { | ||
577 | u16 spare_reg; | ||
578 | |||
579 | /* Mask bits [2] & [8:4] in the sys_clk_cfg register */ | ||
580 | spare_reg = wl1271_top_reg_read(wl, WL_SPARE_REG); | ||
581 | if (spare_reg == 0xFFFF) | ||
582 | return -EFAULT; | ||
583 | spare_reg |= (BIT(3) | BIT(5) | BIT(6)); | ||
584 | wl1271_top_reg_write(wl, WL_SPARE_REG, spare_reg); | ||
585 | |||
586 | /* Enable FREF_CLK_REQ & mux MCS and coex PLLs to FREF */ | ||
587 | wl1271_top_reg_write(wl, SYS_CLK_CFG_REG, | ||
588 | WL_CLK_REQ_TYPE_PG2 | MCS_PLL_CLK_SEL_FREF); | ||
589 | |||
590 | /* Delay execution for 15msec, to let the HW settle */ | ||
591 | mdelay(15); | ||
592 | |||
593 | return 0; | ||
594 | } | ||
595 | |||
596 | static bool wl128x_is_tcxo_valid(struct wl1271 *wl) | ||
597 | { | ||
598 | u16 tcxo_detection; | ||
599 | |||
600 | tcxo_detection = wl1271_top_reg_read(wl, TCXO_CLK_DETECT_REG); | ||
601 | if (tcxo_detection & TCXO_DET_FAILED) | ||
602 | return false; | ||
603 | |||
604 | return true; | ||
605 | } | ||
606 | |||
607 | static bool wl128x_is_fref_valid(struct wl1271 *wl) | ||
608 | { | ||
609 | u16 fref_detection; | ||
610 | |||
611 | fref_detection = wl1271_top_reg_read(wl, FREF_CLK_DETECT_REG); | ||
612 | if (fref_detection & FREF_CLK_DETECT_FAIL) | ||
613 | return false; | ||
614 | |||
615 | return true; | ||
616 | } | ||
617 | |||
618 | static int wl128x_manually_configure_mcs_pll(struct wl1271 *wl) | ||
619 | { | ||
620 | wl1271_top_reg_write(wl, MCS_PLL_M_REG, MCS_PLL_M_REG_VAL); | ||
621 | wl1271_top_reg_write(wl, MCS_PLL_N_REG, MCS_PLL_N_REG_VAL); | ||
622 | wl1271_top_reg_write(wl, MCS_PLL_CONFIG_REG, MCS_PLL_CONFIG_REG_VAL); | ||
623 | |||
624 | return 0; | ||
625 | } | ||
626 | |||
627 | static int wl128x_configure_mcs_pll(struct wl1271 *wl, int clk) | ||
628 | { | ||
629 | u16 spare_reg; | ||
630 | u16 pll_config; | ||
631 | u8 input_freq; | ||
632 | |||
633 | /* Mask bits [3:1] in the sys_clk_cfg register */ | ||
634 | spare_reg = wl1271_top_reg_read(wl, WL_SPARE_REG); | ||
635 | if (spare_reg == 0xFFFF) | ||
636 | return -EFAULT; | ||
637 | spare_reg |= BIT(2); | ||
638 | wl1271_top_reg_write(wl, WL_SPARE_REG, spare_reg); | ||
639 | |||
640 | /* Handle special cases of the TCXO clock */ | ||
641 | if (wl->tcxo_clock == WL12XX_TCXOCLOCK_16_8 || | ||
642 | wl->tcxo_clock == WL12XX_TCXOCLOCK_33_6) | ||
643 | return wl128x_manually_configure_mcs_pll(wl); | ||
644 | |||
645 | /* Set the input frequency according to the selected clock source */ | ||
646 | input_freq = (clk & 1) + 1; | ||
647 | |||
648 | pll_config = wl1271_top_reg_read(wl, MCS_PLL_CONFIG_REG); | ||
649 | if (pll_config == 0xFFFF) | ||
650 | return -EFAULT; | ||
651 | pll_config |= (input_freq << MCS_SEL_IN_FREQ_SHIFT); | ||
652 | pll_config |= MCS_PLL_ENABLE_HP; | ||
653 | wl1271_top_reg_write(wl, MCS_PLL_CONFIG_REG, pll_config); | ||
654 | |||
655 | return 0; | ||
656 | } | ||
657 | |||
658 | /* | ||
659 | * WL128x has two clocks input - TCXO and FREF. | ||
660 | * TCXO is the main clock of the device, while FREF is used to sync | ||
661 | * between the GPS and the cellular modem. | ||
662 | * In cases where TCXO is 32.736MHz or 16.368MHz, the FREF will be used | ||
663 | * as the WLAN/BT main clock. | ||
664 | */ | ||
665 | static int wl128x_boot_clk(struct wl1271 *wl, int *selected_clock) | ||
666 | { | ||
667 | u16 sys_clk_cfg; | ||
668 | |||
669 | /* For XTAL-only modes, FREF will be used after switching from TCXO */ | ||
670 | if (wl->ref_clock == WL12XX_REFCLOCK_26_XTAL || | ||
671 | wl->ref_clock == WL12XX_REFCLOCK_38_XTAL) { | ||
672 | if (!wl128x_switch_tcxo_to_fref(wl)) | ||
673 | return -EINVAL; | ||
674 | goto fref_clk; | ||
675 | } | ||
676 | |||
677 | /* Query the HW, to determine which clock source we should use */ | ||
678 | sys_clk_cfg = wl1271_top_reg_read(wl, SYS_CLK_CFG_REG); | ||
679 | if (sys_clk_cfg == 0xFFFF) | ||
680 | return -EINVAL; | ||
681 | if (sys_clk_cfg & PRCM_CM_EN_MUX_WLAN_FREF) | ||
682 | goto fref_clk; | ||
683 | |||
684 | /* If TCXO is either 32.736MHz or 16.368MHz, switch to FREF */ | ||
685 | if (wl->tcxo_clock == WL12XX_TCXOCLOCK_16_368 || | ||
686 | wl->tcxo_clock == WL12XX_TCXOCLOCK_32_736) { | ||
687 | if (!wl128x_switch_tcxo_to_fref(wl)) | ||
688 | return -EINVAL; | ||
689 | goto fref_clk; | ||
690 | } | ||
691 | |||
692 | /* TCXO clock is selected */ | ||
693 | if (!wl128x_is_tcxo_valid(wl)) | ||
694 | return -EINVAL; | ||
695 | *selected_clock = wl->tcxo_clock; | ||
696 | goto config_mcs_pll; | ||
697 | |||
698 | fref_clk: | ||
699 | /* FREF clock is selected */ | ||
700 | if (!wl128x_is_fref_valid(wl)) | ||
701 | return -EINVAL; | ||
702 | *selected_clock = wl->ref_clock; | ||
703 | |||
704 | config_mcs_pll: | ||
705 | return wl128x_configure_mcs_pll(wl, *selected_clock); | ||
706 | } | ||
707 | |||
708 | static int wl127x_boot_clk(struct wl1271 *wl) | ||
709 | { | ||
710 | u32 pause; | ||
711 | u32 clk; | ||
712 | |||
713 | wl1271_boot_hw_version(wl); | ||
714 | |||
715 | if (wl->ref_clock == CONF_REF_CLK_19_2_E || | ||
716 | wl->ref_clock == CONF_REF_CLK_38_4_E || | ||
717 | wl->ref_clock == CONF_REF_CLK_38_4_M_XTAL) | ||
718 | /* ref clk: 19.2/38.4/38.4-XTAL */ | ||
719 | clk = 0x3; | ||
720 | else if (wl->ref_clock == CONF_REF_CLK_26_E || | ||
721 | wl->ref_clock == CONF_REF_CLK_52_E) | ||
722 | /* ref clk: 26/52 */ | ||
723 | clk = 0x5; | ||
724 | else | ||
725 | return -EINVAL; | ||
726 | |||
727 | if (wl->ref_clock != CONF_REF_CLK_19_2_E) { | ||
728 | u16 val; | ||
729 | /* Set clock type (open drain) */ | ||
730 | val = wl1271_top_reg_read(wl, OCP_REG_CLK_TYPE); | ||
731 | val &= FREF_CLK_TYPE_BITS; | ||
732 | wl1271_top_reg_write(wl, OCP_REG_CLK_TYPE, val); | ||
733 | |||
734 | /* Set clock pull mode (no pull) */ | ||
735 | val = wl1271_top_reg_read(wl, OCP_REG_CLK_PULL); | ||
736 | val |= NO_PULL; | ||
737 | wl1271_top_reg_write(wl, OCP_REG_CLK_PULL, val); | ||
738 | } else { | ||
739 | u16 val; | ||
740 | /* Set clock polarity */ | ||
741 | val = wl1271_top_reg_read(wl, OCP_REG_CLK_POLARITY); | ||
742 | val &= FREF_CLK_POLARITY_BITS; | ||
743 | val |= CLK_REQ_OUTN_SEL; | ||
744 | wl1271_top_reg_write(wl, OCP_REG_CLK_POLARITY, val); | ||
745 | } | ||
746 | |||
747 | wl1271_write32(wl, PLL_PARAMETERS, clk); | ||
748 | |||
749 | pause = wl1271_read32(wl, PLL_PARAMETERS); | ||
750 | |||
751 | wl1271_debug(DEBUG_BOOT, "pause1 0x%x", pause); | ||
752 | |||
753 | pause &= ~(WU_COUNTER_PAUSE_VAL); | ||
754 | pause |= WU_COUNTER_PAUSE_VAL; | ||
755 | wl1271_write32(wl, WU_COUNTER_PAUSE, pause); | ||
756 | |||
757 | return 0; | ||
758 | } | ||
759 | |||
760 | /* uploads NVS and firmware */ | ||
761 | int wl1271_load_firmware(struct wl1271 *wl) | ||
762 | { | ||
763 | int ret = 0; | ||
764 | u32 tmp, clk; | ||
765 | int selected_clock = -1; | ||
766 | |||
767 | if (wl->chip.id == CHIP_ID_1283_PG20) { | ||
768 | ret = wl128x_boot_clk(wl, &selected_clock); | ||
769 | if (ret < 0) | ||
770 | goto out; | ||
771 | } else { | ||
772 | ret = wl127x_boot_clk(wl); | ||
773 | if (ret < 0) | ||
774 | goto out; | ||
775 | } | ||
776 | |||
777 | /* Continue the ELP wake up sequence */ | ||
778 | wl1271_write32(wl, WELP_ARM_COMMAND, WELP_ARM_COMMAND_VAL); | ||
779 | udelay(500); | ||
780 | |||
781 | wl1271_set_partition(wl, &part_table[PART_DRPW]); | ||
782 | |||
783 | /* Read-modify-write DRPW_SCRATCH_START register (see next state) | ||
784 | to be used by DRPw FW. The RTRIM value will be added by the FW | ||
785 | before taking DRPw out of reset */ | ||
786 | |||
787 | wl1271_debug(DEBUG_BOOT, "DRPW_SCRATCH_START %08x", DRPW_SCRATCH_START); | ||
788 | clk = wl1271_read32(wl, DRPW_SCRATCH_START); | ||
789 | |||
790 | wl1271_debug(DEBUG_BOOT, "clk2 0x%x", clk); | ||
791 | |||
792 | if (wl->chip.id == CHIP_ID_1283_PG20) { | ||
793 | clk |= ((selected_clock & 0x3) << 1) << 4; | ||
794 | } else { | ||
795 | clk |= (wl->ref_clock << 1) << 4; | ||
796 | } | ||
797 | |||
798 | if (wl->quirks & WL12XX_QUIRK_LPD_MODE) | ||
799 | clk |= SCRATCH_ENABLE_LPD; | ||
800 | |||
801 | wl1271_write32(wl, DRPW_SCRATCH_START, clk); | ||
802 | |||
803 | wl1271_set_partition(wl, &part_table[PART_WORK]); | ||
804 | |||
805 | /* Disable interrupts */ | ||
806 | wl1271_write32(wl, ACX_REG_INTERRUPT_MASK, WL1271_ACX_INTR_ALL); | ||
807 | |||
808 | ret = wl1271_boot_soft_reset(wl); | ||
809 | if (ret < 0) | ||
810 | goto out; | ||
811 | |||
812 | /* 2. start processing NVS file */ | ||
813 | ret = wl1271_boot_upload_nvs(wl); | ||
814 | if (ret < 0) | ||
815 | goto out; | ||
816 | |||
817 | /* write firmware's last address (ie. it's length) to | ||
818 | * ACX_EEPROMLESS_IND_REG */ | ||
819 | wl1271_debug(DEBUG_BOOT, "ACX_EEPROMLESS_IND_REG"); | ||
820 | |||
821 | wl1271_write32(wl, ACX_EEPROMLESS_IND_REG, ACX_EEPROMLESS_IND_REG); | ||
822 | |||
823 | tmp = wl1271_read32(wl, CHIP_ID_B); | ||
824 | |||
825 | wl1271_debug(DEBUG_BOOT, "chip id 0x%x", tmp); | ||
826 | |||
827 | /* 6. read the EEPROM parameters */ | ||
828 | tmp = wl1271_read32(wl, SCR_PAD2); | ||
829 | |||
830 | /* WL1271: The reference driver skips steps 7 to 10 (jumps directly | ||
831 | * to upload_fw) */ | ||
832 | |||
833 | if (wl->chip.id == CHIP_ID_1283_PG20) | ||
834 | wl1271_top_reg_write(wl, SDIO_IO_DS, wl->conf.hci_io_ds); | ||
835 | |||
836 | ret = wl1271_boot_upload_firmware(wl); | ||
837 | if (ret < 0) | ||
838 | goto out; | ||
839 | |||
840 | out: | ||
841 | return ret; | ||
842 | } | ||
843 | EXPORT_SYMBOL_GPL(wl1271_load_firmware); | ||
844 | |||
845 | int wl1271_boot(struct wl1271 *wl) | ||
846 | { | ||
847 | int ret; | ||
848 | |||
849 | /* upload NVS and firmware */ | ||
850 | ret = wl1271_load_firmware(wl); | ||
851 | if (ret) | ||
852 | return ret; | ||
853 | |||
854 | /* 10.5 start firmware */ | ||
855 | ret = wl1271_boot_run_firmware(wl); | ||
856 | if (ret < 0) | ||
857 | goto out; | ||
858 | |||
859 | ret = wl1271_boot_write_irq_polarity(wl); | ||
860 | if (ret < 0) | ||
861 | goto out; | ||
862 | |||
863 | wl1271_write32(wl, ACX_REG_INTERRUPT_MASK, | ||
864 | WL1271_ACX_ALL_EVENTS_VECTOR); | ||
865 | |||
866 | /* Enable firmware interrupts now */ | ||
867 | wl1271_boot_enable_interrupts(wl); | ||
868 | |||
869 | /* set the wl1271 default filters */ | ||
870 | wl1271_set_default_filters(wl); | ||
871 | |||
872 | wl1271_event_mbox_config(wl); | ||
873 | |||
874 | out: | ||
875 | return ret; | ||
876 | } | ||
diff --git a/drivers/net/wireless/wl12xx/boot.h b/drivers/net/wireless/wl12xx/boot.h new file mode 100644 index 00000000000..e8f8255bbab --- /dev/null +++ b/drivers/net/wireless/wl12xx/boot.h | |||
@@ -0,0 +1,129 @@ | |||
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 "wl12xx.h" | ||
28 | |||
29 | int wl1271_boot(struct wl1271 *wl); | ||
30 | int wl1271_load_firmware(struct wl1271 *wl); | ||
31 | |||
32 | #define WL1271_NO_SUBBANDS 8 | ||
33 | #define WL1271_NO_POWER_LEVELS 4 | ||
34 | #define WL1271_FW_VERSION_MAX_LEN 20 | ||
35 | |||
36 | struct wl1271_static_data { | ||
37 | u8 mac_address[ETH_ALEN]; | ||
38 | u8 padding[2]; | ||
39 | u8 fw_version[WL1271_FW_VERSION_MAX_LEN]; | ||
40 | u32 hw_version; | ||
41 | u8 tx_power_table[WL1271_NO_SUBBANDS][WL1271_NO_POWER_LEVELS]; | ||
42 | }; | ||
43 | |||
44 | /* number of times we try to read the INIT interrupt */ | ||
45 | #define INIT_LOOP 20000 | ||
46 | |||
47 | /* delay between retries */ | ||
48 | #define INIT_LOOP_DELAY 50 | ||
49 | |||
50 | #define WU_COUNTER_PAUSE_VAL 0x3FF | ||
51 | #define WELP_ARM_COMMAND_VAL 0x4 | ||
52 | |||
53 | #define OCP_REG_POLARITY 0x0064 | ||
54 | #define OCP_REG_CLK_TYPE 0x0448 | ||
55 | #define OCP_REG_CLK_POLARITY 0x0cb2 | ||
56 | #define OCP_REG_CLK_PULL 0x0cb4 | ||
57 | |||
58 | #define REG_FUSE_DATA_2_1 0x050a | ||
59 | #define PG_VER_MASK 0x3c | ||
60 | #define PG_VER_OFFSET 2 | ||
61 | |||
62 | #define PG_MAJOR_VER_MASK 0x3 | ||
63 | #define PG_MAJOR_VER_OFFSET 0x0 | ||
64 | #define PG_MINOR_VER_MASK 0xc | ||
65 | #define PG_MINOR_VER_OFFSET 0x2 | ||
66 | |||
67 | #define CMD_MBOX_ADDRESS 0x407B4 | ||
68 | |||
69 | #define POLARITY_LOW BIT(1) | ||
70 | #define NO_PULL (BIT(14) | BIT(15)) | ||
71 | |||
72 | #define FREF_CLK_TYPE_BITS 0xfffffe7f | ||
73 | #define CLK_REQ_PRCM 0x100 | ||
74 | #define FREF_CLK_POLARITY_BITS 0xfffff8ff | ||
75 | #define CLK_REQ_OUTN_SEL 0x700 | ||
76 | |||
77 | /* PLL configuration algorithm for wl128x */ | ||
78 | #define SYS_CLK_CFG_REG 0x2200 | ||
79 | /* Bit[0] - 0-TCXO, 1-FREF */ | ||
80 | #define MCS_PLL_CLK_SEL_FREF BIT(0) | ||
81 | /* Bit[3:2] - 01-TCXO, 10-FREF */ | ||
82 | #define WL_CLK_REQ_TYPE_FREF BIT(3) | ||
83 | #define WL_CLK_REQ_TYPE_PG2 (BIT(3) | BIT(2)) | ||
84 | /* Bit[4] - 0-TCXO, 1-FREF */ | ||
85 | #define PRCM_CM_EN_MUX_WLAN_FREF BIT(4) | ||
86 | |||
87 | #define TCXO_ILOAD_INT_REG 0x2264 | ||
88 | #define TCXO_CLK_DETECT_REG 0x2266 | ||
89 | |||
90 | #define TCXO_DET_FAILED BIT(4) | ||
91 | |||
92 | #define FREF_ILOAD_INT_REG 0x2084 | ||
93 | #define FREF_CLK_DETECT_REG 0x2086 | ||
94 | #define FREF_CLK_DETECT_FAIL BIT(4) | ||
95 | |||
96 | /* Use this reg for masking during driver access */ | ||
97 | #define WL_SPARE_REG 0x2320 | ||
98 | #define WL_SPARE_VAL BIT(2) | ||
99 | /* Bit[6:5:3] - mask wl write SYS_CLK_CFG[8:5:2:4] */ | ||
100 | #define WL_SPARE_MASK_8526 (BIT(6) | BIT(5) | BIT(3)) | ||
101 | |||
102 | #define PLL_LOCK_COUNTERS_REG 0xD8C | ||
103 | #define PLL_LOCK_COUNTERS_COEX 0x0F | ||
104 | #define PLL_LOCK_COUNTERS_MCS 0xF0 | ||
105 | #define MCS_PLL_OVERRIDE_REG 0xD90 | ||
106 | #define MCS_PLL_CONFIG_REG 0xD92 | ||
107 | #define MCS_SEL_IN_FREQ_MASK 0x0070 | ||
108 | #define MCS_SEL_IN_FREQ_SHIFT 4 | ||
109 | #define MCS_PLL_CONFIG_REG_VAL 0x73 | ||
110 | #define MCS_PLL_ENABLE_HP (BIT(0) | BIT(1)) | ||
111 | |||
112 | #define MCS_PLL_M_REG 0xD94 | ||
113 | #define MCS_PLL_N_REG 0xD96 | ||
114 | #define MCS_PLL_M_REG_VAL 0xC8 | ||
115 | #define MCS_PLL_N_REG_VAL 0x07 | ||
116 | |||
117 | #define SDIO_IO_DS 0xd14 | ||
118 | |||
119 | /* SDIO/wSPI DS configuration values */ | ||
120 | enum { | ||
121 | HCI_IO_DS_8MA = 0, | ||
122 | HCI_IO_DS_4MA = 1, /* default */ | ||
123 | HCI_IO_DS_6MA = 2, | ||
124 | HCI_IO_DS_2MA = 3, | ||
125 | }; | ||
126 | |||
127 | /* end PLL configuration algorithm for wl128x */ | ||
128 | |||
129 | #endif | ||
diff --git a/drivers/net/wireless/wl12xx/cmd.c b/drivers/net/wireless/wl12xx/cmd.c new file mode 100644 index 00000000000..2144f60b4e6 --- /dev/null +++ b/drivers/net/wireless/wl12xx/cmd.c | |||
@@ -0,0 +1,1331 @@ | |||
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 "wl12xx.h" | ||
32 | #include "reg.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 | */ | ||
50 | int 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 | wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD); | ||
70 | |||
71 | timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT); | ||
72 | |||
73 | intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR); | ||
74 | while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) { | ||
75 | if (time_after(jiffies, timeout)) { | ||
76 | wl1271_error("command complete timeout"); | ||
77 | ret = -ETIMEDOUT; | ||
78 | goto fail; | ||
79 | } | ||
80 | |||
81 | poll_count++; | ||
82 | if (poll_count < WL1271_CMD_FAST_POLL_COUNT) | ||
83 | udelay(10); | ||
84 | else | ||
85 | msleep(1); | ||
86 | |||
87 | intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR); | ||
88 | } | ||
89 | |||
90 | /* read back the status code of the command */ | ||
91 | if (res_len == 0) | ||
92 | res_len = sizeof(struct wl1271_cmd_header); | ||
93 | wl1271_read(wl, wl->cmd_box_addr, cmd, res_len, false); | ||
94 | |||
95 | status = le16_to_cpu(cmd->status); | ||
96 | if (status != CMD_STATUS_SUCCESS) { | ||
97 | wl1271_error("command execute failure %d", status); | ||
98 | ret = -EIO; | ||
99 | goto fail; | ||
100 | } | ||
101 | |||
102 | wl1271_write32(wl, ACX_REG_INTERRUPT_ACK, | ||
103 | WL1271_ACX_INTR_CMD_COMPLETE); | ||
104 | return 0; | ||
105 | |||
106 | fail: | ||
107 | WARN_ON(1); | ||
108 | wl12xx_queue_recovery_work(wl); | ||
109 | return ret; | ||
110 | } | ||
111 | |||
112 | int wl1271_cmd_general_parms(struct wl1271 *wl) | ||
113 | { | ||
114 | struct wl1271_general_parms_cmd *gen_parms; | ||
115 | struct wl1271_ini_general_params *gp = | ||
116 | &((struct wl1271_nvs_file *)wl->nvs)->general_params; | ||
117 | bool answer = false; | ||
118 | int ret; | ||
119 | |||
120 | if (!wl->nvs) | ||
121 | return -ENODEV; | ||
122 | |||
123 | if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) { | ||
124 | wl1271_warning("FEM index from INI out of bounds"); | ||
125 | return -EINVAL; | ||
126 | } | ||
127 | |||
128 | gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL); | ||
129 | if (!gen_parms) | ||
130 | return -ENOMEM; | ||
131 | |||
132 | gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM; | ||
133 | |||
134 | memcpy(&gen_parms->general_params, gp, sizeof(*gp)); | ||
135 | |||
136 | if (gp->tx_bip_fem_auto_detect) | ||
137 | answer = true; | ||
138 | |||
139 | /* Override the REF CLK from the NVS with the one from platform data */ | ||
140 | gen_parms->general_params.ref_clock = wl->ref_clock; | ||
141 | |||
142 | /* LPD mode enable (bits 6-7) in WL1271 AP mode only */ | ||
143 | if (wl->quirks & WL12XX_QUIRK_LPD_MODE) | ||
144 | gen_parms->general_params.general_settings |= | ||
145 | GENERAL_SETTINGS_DRPW_LPD; | ||
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 | |||
165 | out: | ||
166 | kfree(gen_parms); | ||
167 | return ret; | ||
168 | } | ||
169 | |||
170 | int wl128x_cmd_general_parms(struct wl1271 *wl) | ||
171 | { | ||
172 | struct wl128x_general_parms_cmd *gen_parms; | ||
173 | struct wl128x_ini_general_params *gp = | ||
174 | &((struct wl128x_nvs_file *)wl->nvs)->general_params; | ||
175 | bool answer = false; | ||
176 | int ret; | ||
177 | |||
178 | if (!wl->nvs) | ||
179 | return -ENODEV; | ||
180 | |||
181 | if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) { | ||
182 | wl1271_warning("FEM index from ini out of bounds"); | ||
183 | return -EINVAL; | ||
184 | } | ||
185 | |||
186 | gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL); | ||
187 | if (!gen_parms) | ||
188 | return -ENOMEM; | ||
189 | |||
190 | gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM; | ||
191 | |||
192 | memcpy(&gen_parms->general_params, gp, sizeof(*gp)); | ||
193 | |||
194 | if (gp->tx_bip_fem_auto_detect) | ||
195 | answer = true; | ||
196 | |||
197 | /* Replace REF and TCXO CLKs with the ones from platform data */ | ||
198 | gen_parms->general_params.ref_clock = wl->ref_clock; | ||
199 | gen_parms->general_params.tcxo_ref_clock = wl->tcxo_clock; | ||
200 | |||
201 | ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer); | ||
202 | if (ret < 0) { | ||
203 | wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed"); | ||
204 | goto out; | ||
205 | } | ||
206 | |||
207 | gp->tx_bip_fem_manufacturer = | ||
208 | gen_parms->general_params.tx_bip_fem_manufacturer; | ||
209 | |||
210 | if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) { | ||
211 | wl1271_warning("FEM index from FW out of bounds"); | ||
212 | ret = -EINVAL; | ||
213 | goto out; | ||
214 | } | ||
215 | |||
216 | wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n", | ||
217 | answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer); | ||
218 | |||
219 | out: | ||
220 | kfree(gen_parms); | ||
221 | return ret; | ||
222 | } | ||
223 | |||
224 | int wl1271_cmd_radio_parms(struct wl1271 *wl) | ||
225 | { | ||
226 | struct wl1271_nvs_file *nvs = (struct wl1271_nvs_file *)wl->nvs; | ||
227 | struct wl1271_radio_parms_cmd *radio_parms; | ||
228 | struct wl1271_ini_general_params *gp = &nvs->general_params; | ||
229 | int ret; | ||
230 | |||
231 | if (!wl->nvs) | ||
232 | return -ENODEV; | ||
233 | |||
234 | radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL); | ||
235 | if (!radio_parms) | ||
236 | return -ENOMEM; | ||
237 | |||
238 | radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM; | ||
239 | |||
240 | /* 2.4GHz parameters */ | ||
241 | memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2, | ||
242 | sizeof(struct wl1271_ini_band_params_2)); | ||
243 | memcpy(&radio_parms->dyn_params_2, | ||
244 | &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params, | ||
245 | sizeof(struct wl1271_ini_fem_params_2)); | ||
246 | |||
247 | /* 5GHz parameters */ | ||
248 | memcpy(&radio_parms->static_params_5, | ||
249 | &nvs->stat_radio_params_5, | ||
250 | sizeof(struct wl1271_ini_band_params_5)); | ||
251 | memcpy(&radio_parms->dyn_params_5, | ||
252 | &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params, | ||
253 | sizeof(struct wl1271_ini_fem_params_5)); | ||
254 | |||
255 | wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ", | ||
256 | radio_parms, sizeof(*radio_parms)); | ||
257 | |||
258 | ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0); | ||
259 | if (ret < 0) | ||
260 | wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed"); | ||
261 | |||
262 | kfree(radio_parms); | ||
263 | return ret; | ||
264 | } | ||
265 | |||
266 | int wl128x_cmd_radio_parms(struct wl1271 *wl) | ||
267 | { | ||
268 | struct wl128x_nvs_file *nvs = (struct wl128x_nvs_file *)wl->nvs; | ||
269 | struct wl128x_radio_parms_cmd *radio_parms; | ||
270 | struct wl128x_ini_general_params *gp = &nvs->general_params; | ||
271 | int ret; | ||
272 | |||
273 | if (!wl->nvs) | ||
274 | return -ENODEV; | ||
275 | |||
276 | radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL); | ||
277 | if (!radio_parms) | ||
278 | return -ENOMEM; | ||
279 | |||
280 | radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM; | ||
281 | |||
282 | /* 2.4GHz parameters */ | ||
283 | memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2, | ||
284 | sizeof(struct wl128x_ini_band_params_2)); | ||
285 | memcpy(&radio_parms->dyn_params_2, | ||
286 | &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params, | ||
287 | sizeof(struct wl128x_ini_fem_params_2)); | ||
288 | |||
289 | /* 5GHz parameters */ | ||
290 | memcpy(&radio_parms->static_params_5, | ||
291 | &nvs->stat_radio_params_5, | ||
292 | sizeof(struct wl128x_ini_band_params_5)); | ||
293 | memcpy(&radio_parms->dyn_params_5, | ||
294 | &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params, | ||
295 | sizeof(struct wl128x_ini_fem_params_5)); | ||
296 | |||
297 | radio_parms->fem_vendor_and_options = nvs->fem_vendor_and_options; | ||
298 | |||
299 | wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ", | ||
300 | radio_parms, sizeof(*radio_parms)); | ||
301 | |||
302 | ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0); | ||
303 | if (ret < 0) | ||
304 | wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed"); | ||
305 | |||
306 | kfree(radio_parms); | ||
307 | return ret; | ||
308 | } | ||
309 | |||
310 | int wl1271_cmd_ext_radio_parms(struct wl1271 *wl) | ||
311 | { | ||
312 | struct wl1271_ext_radio_parms_cmd *ext_radio_parms; | ||
313 | struct conf_rf_settings *rf = &wl->conf.rf; | ||
314 | int ret; | ||
315 | |||
316 | if (!wl->nvs) | ||
317 | return -ENODEV; | ||
318 | |||
319 | ext_radio_parms = kzalloc(sizeof(*ext_radio_parms), GFP_KERNEL); | ||
320 | if (!ext_radio_parms) | ||
321 | return -ENOMEM; | ||
322 | |||
323 | ext_radio_parms->test.id = TEST_CMD_INI_FILE_RF_EXTENDED_PARAM; | ||
324 | |||
325 | memcpy(ext_radio_parms->tx_per_channel_power_compensation_2, | ||
326 | rf->tx_per_channel_power_compensation_2, | ||
327 | CONF_TX_PWR_COMPENSATION_LEN_2); | ||
328 | memcpy(ext_radio_parms->tx_per_channel_power_compensation_5, | ||
329 | rf->tx_per_channel_power_compensation_5, | ||
330 | CONF_TX_PWR_COMPENSATION_LEN_5); | ||
331 | |||
332 | wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_EXT_RADIO_PARAM: ", | ||
333 | ext_radio_parms, sizeof(*ext_radio_parms)); | ||
334 | |||
335 | ret = wl1271_cmd_test(wl, ext_radio_parms, sizeof(*ext_radio_parms), 0); | ||
336 | if (ret < 0) | ||
337 | wl1271_warning("TEST_CMD_INI_FILE_RF_EXTENDED_PARAM failed"); | ||
338 | |||
339 | kfree(ext_radio_parms); | ||
340 | return ret; | ||
341 | } | ||
342 | |||
343 | /* | ||
344 | * Poll the mailbox event field until any of the bits in the mask is set or a | ||
345 | * timeout occurs (WL1271_EVENT_TIMEOUT in msecs) | ||
346 | */ | ||
347 | static int wl1271_cmd_wait_for_event_or_timeout(struct wl1271 *wl, u32 mask) | ||
348 | { | ||
349 | u32 events_vector, event; | ||
350 | unsigned long timeout; | ||
351 | |||
352 | timeout = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT); | ||
353 | |||
354 | do { | ||
355 | if (time_after(jiffies, timeout)) { | ||
356 | wl1271_debug(DEBUG_CMD, "timeout waiting for event %d", | ||
357 | (int)mask); | ||
358 | return -ETIMEDOUT; | ||
359 | } | ||
360 | |||
361 | msleep(1); | ||
362 | |||
363 | /* read from both event fields */ | ||
364 | wl1271_read(wl, wl->mbox_ptr[0], &events_vector, | ||
365 | sizeof(events_vector), false); | ||
366 | event = events_vector & mask; | ||
367 | wl1271_read(wl, wl->mbox_ptr[1], &events_vector, | ||
368 | sizeof(events_vector), false); | ||
369 | event |= events_vector & mask; | ||
370 | } while (!event); | ||
371 | |||
372 | return 0; | ||
373 | } | ||
374 | |||
375 | static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask) | ||
376 | { | ||
377 | int ret; | ||
378 | |||
379 | ret = wl1271_cmd_wait_for_event_or_timeout(wl, mask); | ||
380 | if (ret != 0) { | ||
381 | wl12xx_queue_recovery_work(wl); | ||
382 | return ret; | ||
383 | } | ||
384 | |||
385 | return 0; | ||
386 | } | ||
387 | |||
388 | int wl1271_cmd_join(struct wl1271 *wl, u8 bss_type) | ||
389 | { | ||
390 | struct wl1271_cmd_join *join; | ||
391 | int ret, i; | ||
392 | u8 *bssid; | ||
393 | |||
394 | join = kzalloc(sizeof(*join), GFP_KERNEL); | ||
395 | if (!join) { | ||
396 | ret = -ENOMEM; | ||
397 | goto out; | ||
398 | } | ||
399 | |||
400 | wl1271_debug(DEBUG_CMD, "cmd join"); | ||
401 | |||
402 | /* Reverse order BSSID */ | ||
403 | bssid = (u8 *) &join->bssid_lsb; | ||
404 | for (i = 0; i < ETH_ALEN; i++) | ||
405 | bssid[i] = wl->bssid[ETH_ALEN - i - 1]; | ||
406 | |||
407 | join->rx_config_options = cpu_to_le32(wl->rx_config); | ||
408 | join->rx_filter_options = cpu_to_le32(wl->rx_filter); | ||
409 | join->bss_type = bss_type; | ||
410 | join->basic_rate_set = cpu_to_le32(wl->basic_rate_set); | ||
411 | join->supported_rate_set = cpu_to_le32(wl->rate_set); | ||
412 | |||
413 | if (wl->band == IEEE80211_BAND_5GHZ) | ||
414 | join->bss_type |= WL1271_JOIN_CMD_BSS_TYPE_5GHZ; | ||
415 | |||
416 | join->beacon_interval = cpu_to_le16(wl->beacon_int); | ||
417 | join->dtim_interval = WL1271_DEFAULT_DTIM_PERIOD; | ||
418 | |||
419 | join->channel = wl->channel; | ||
420 | join->ssid_len = wl->ssid_len; | ||
421 | memcpy(join->ssid, wl->ssid, wl->ssid_len); | ||
422 | |||
423 | join->ctrl |= wl->session_counter << WL1271_JOIN_CMD_TX_SESSION_OFFSET; | ||
424 | |||
425 | wl1271_debug(DEBUG_CMD, "cmd join: basic_rate_set=0x%x, rate_set=0x%x", | ||
426 | join->basic_rate_set, join->supported_rate_set); | ||
427 | |||
428 | ret = wl1271_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join), 0); | ||
429 | if (ret < 0) { | ||
430 | wl1271_error("failed to initiate cmd join"); | ||
431 | goto out_free; | ||
432 | } | ||
433 | |||
434 | ret = wl1271_cmd_wait_for_event(wl, JOIN_EVENT_COMPLETE_ID); | ||
435 | if (ret < 0) | ||
436 | wl1271_error("cmd join event completion error"); | ||
437 | |||
438 | out_free: | ||
439 | kfree(join); | ||
440 | |||
441 | out: | ||
442 | return ret; | ||
443 | } | ||
444 | |||
445 | /** | ||
446 | * send test command to firmware | ||
447 | * | ||
448 | * @wl: wl struct | ||
449 | * @buf: buffer containing the command, with all headers, must work with dma | ||
450 | * @len: length of the buffer | ||
451 | * @answer: is answer needed | ||
452 | */ | ||
453 | int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer) | ||
454 | { | ||
455 | int ret; | ||
456 | size_t res_len = 0; | ||
457 | |||
458 | wl1271_debug(DEBUG_CMD, "cmd test"); | ||
459 | |||
460 | if (answer) | ||
461 | res_len = buf_len; | ||
462 | |||
463 | ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len); | ||
464 | |||
465 | if (ret < 0) { | ||
466 | wl1271_warning("TEST command failed"); | ||
467 | return ret; | ||
468 | } | ||
469 | |||
470 | return ret; | ||
471 | } | ||
472 | |||
473 | /** | ||
474 | * read acx from firmware | ||
475 | * | ||
476 | * @wl: wl struct | ||
477 | * @id: acx id | ||
478 | * @buf: buffer for the response, including all headers, must work with dma | ||
479 | * @len: length of buf | ||
480 | */ | ||
481 | int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len) | ||
482 | { | ||
483 | struct acx_header *acx = buf; | ||
484 | int ret; | ||
485 | |||
486 | wl1271_debug(DEBUG_CMD, "cmd interrogate"); | ||
487 | |||
488 | acx->id = cpu_to_le16(id); | ||
489 | |||
490 | /* payload length, does not include any headers */ | ||
491 | acx->len = cpu_to_le16(len - sizeof(*acx)); | ||
492 | |||
493 | ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len); | ||
494 | if (ret < 0) | ||
495 | wl1271_error("INTERROGATE command failed"); | ||
496 | |||
497 | return ret; | ||
498 | } | ||
499 | |||
500 | /** | ||
501 | * write acx value to firmware | ||
502 | * | ||
503 | * @wl: wl struct | ||
504 | * @id: acx id | ||
505 | * @buf: buffer containing acx, including all headers, must work with dma | ||
506 | * @len: length of buf | ||
507 | */ | ||
508 | int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len) | ||
509 | { | ||
510 | struct acx_header *acx = buf; | ||
511 | int ret; | ||
512 | |||
513 | wl1271_debug(DEBUG_CMD, "cmd configure"); | ||
514 | |||
515 | acx->id = cpu_to_le16(id); | ||
516 | |||
517 | /* payload length, does not include any headers */ | ||
518 | acx->len = cpu_to_le16(len - sizeof(*acx)); | ||
519 | |||
520 | ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0); | ||
521 | if (ret < 0) { | ||
522 | wl1271_warning("CONFIGURE command NOK"); | ||
523 | return ret; | ||
524 | } | ||
525 | |||
526 | return 0; | ||
527 | } | ||
528 | |||
529 | int wl1271_cmd_data_path(struct wl1271 *wl, bool enable) | ||
530 | { | ||
531 | struct cmd_enabledisable_path *cmd; | ||
532 | int ret; | ||
533 | u16 cmd_rx, cmd_tx; | ||
534 | |||
535 | wl1271_debug(DEBUG_CMD, "cmd data path"); | ||
536 | |||
537 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | ||
538 | if (!cmd) { | ||
539 | ret = -ENOMEM; | ||
540 | goto out; | ||
541 | } | ||
542 | |||
543 | /* the channel here is only used for calibration, so hardcoded to 1 */ | ||
544 | cmd->channel = 1; | ||
545 | |||
546 | if (enable) { | ||
547 | cmd_rx = CMD_ENABLE_RX; | ||
548 | cmd_tx = CMD_ENABLE_TX; | ||
549 | } else { | ||
550 | cmd_rx = CMD_DISABLE_RX; | ||
551 | cmd_tx = CMD_DISABLE_TX; | ||
552 | } | ||
553 | |||
554 | ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0); | ||
555 | if (ret < 0) { | ||
556 | wl1271_error("rx %s cmd for channel %d failed", | ||
557 | enable ? "start" : "stop", cmd->channel); | ||
558 | goto out; | ||
559 | } | ||
560 | |||
561 | wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d", | ||
562 | enable ? "start" : "stop", cmd->channel); | ||
563 | |||
564 | ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0); | ||
565 | if (ret < 0) { | ||
566 | wl1271_error("tx %s cmd for channel %d failed", | ||
567 | enable ? "start" : "stop", cmd->channel); | ||
568 | goto out; | ||
569 | } | ||
570 | |||
571 | wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d", | ||
572 | enable ? "start" : "stop", cmd->channel); | ||
573 | |||
574 | out: | ||
575 | kfree(cmd); | ||
576 | return ret; | ||
577 | } | ||
578 | |||
579 | int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode) | ||
580 | { | ||
581 | struct wl1271_cmd_ps_params *ps_params = NULL; | ||
582 | int ret = 0; | ||
583 | |||
584 | wl1271_debug(DEBUG_CMD, "cmd set ps mode"); | ||
585 | |||
586 | ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL); | ||
587 | if (!ps_params) { | ||
588 | ret = -ENOMEM; | ||
589 | goto out; | ||
590 | } | ||
591 | |||
592 | ps_params->ps_mode = ps_mode; | ||
593 | |||
594 | ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params, | ||
595 | sizeof(*ps_params), 0); | ||
596 | if (ret < 0) { | ||
597 | wl1271_error("cmd set_ps_mode failed"); | ||
598 | goto out; | ||
599 | } | ||
600 | |||
601 | out: | ||
602 | kfree(ps_params); | ||
603 | return ret; | ||
604 | } | ||
605 | |||
606 | int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id, | ||
607 | void *buf, size_t buf_len, int index, u32 rates) | ||
608 | { | ||
609 | struct wl1271_cmd_template_set *cmd; | ||
610 | int ret = 0; | ||
611 | |||
612 | wl1271_debug(DEBUG_CMD, "cmd template_set %d", template_id); | ||
613 | |||
614 | WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE); | ||
615 | buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE); | ||
616 | |||
617 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | ||
618 | if (!cmd) { | ||
619 | ret = -ENOMEM; | ||
620 | goto out; | ||
621 | } | ||
622 | |||
623 | cmd->len = cpu_to_le16(buf_len); | ||
624 | cmd->template_type = template_id; | ||
625 | cmd->enabled_rates = cpu_to_le32(rates); | ||
626 | cmd->short_retry_limit = wl->conf.tx.tmpl_short_retry_limit; | ||
627 | cmd->long_retry_limit = wl->conf.tx.tmpl_long_retry_limit; | ||
628 | cmd->index = index; | ||
629 | |||
630 | if (buf) | ||
631 | memcpy(cmd->template_data, buf, buf_len); | ||
632 | |||
633 | ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0); | ||
634 | if (ret < 0) { | ||
635 | wl1271_warning("cmd set_template failed: %d", ret); | ||
636 | goto out_free; | ||
637 | } | ||
638 | |||
639 | out_free: | ||
640 | kfree(cmd); | ||
641 | |||
642 | out: | ||
643 | return ret; | ||
644 | } | ||
645 | |||
646 | int wl1271_cmd_build_null_data(struct wl1271 *wl) | ||
647 | { | ||
648 | struct sk_buff *skb = NULL; | ||
649 | int size; | ||
650 | void *ptr; | ||
651 | int ret = -ENOMEM; | ||
652 | |||
653 | |||
654 | if (wl->bss_type == BSS_TYPE_IBSS) { | ||
655 | size = sizeof(struct wl12xx_null_data_template); | ||
656 | ptr = NULL; | ||
657 | } else { | ||
658 | skb = ieee80211_nullfunc_get(wl->hw, wl->vif); | ||
659 | if (!skb) | ||
660 | goto out; | ||
661 | size = skb->len; | ||
662 | ptr = skb->data; | ||
663 | } | ||
664 | |||
665 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, ptr, size, 0, | ||
666 | wl->basic_rate); | ||
667 | |||
668 | out: | ||
669 | dev_kfree_skb(skb); | ||
670 | if (ret) | ||
671 | wl1271_warning("cmd buld null data failed %d", ret); | ||
672 | |||
673 | return ret; | ||
674 | |||
675 | } | ||
676 | |||
677 | int wl1271_cmd_build_klv_null_data(struct wl1271 *wl) | ||
678 | { | ||
679 | struct sk_buff *skb = NULL; | ||
680 | int ret = -ENOMEM; | ||
681 | |||
682 | skb = ieee80211_nullfunc_get(wl->hw, wl->vif); | ||
683 | if (!skb) | ||
684 | goto out; | ||
685 | |||
686 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV, | ||
687 | skb->data, skb->len, | ||
688 | CMD_TEMPL_KLV_IDX_NULL_DATA, | ||
689 | wl->basic_rate); | ||
690 | |||
691 | out: | ||
692 | dev_kfree_skb(skb); | ||
693 | if (ret) | ||
694 | wl1271_warning("cmd build klv null data failed %d", ret); | ||
695 | |||
696 | return ret; | ||
697 | |||
698 | } | ||
699 | |||
700 | int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid) | ||
701 | { | ||
702 | struct sk_buff *skb; | ||
703 | int ret = 0; | ||
704 | |||
705 | skb = ieee80211_pspoll_get(wl->hw, wl->vif); | ||
706 | if (!skb) | ||
707 | goto out; | ||
708 | |||
709 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, skb->data, | ||
710 | skb->len, 0, wl->basic_rate_set); | ||
711 | |||
712 | out: | ||
713 | dev_kfree_skb(skb); | ||
714 | return ret; | ||
715 | } | ||
716 | |||
717 | int wl1271_cmd_build_probe_req(struct wl1271 *wl, | ||
718 | const u8 *ssid, size_t ssid_len, | ||
719 | const u8 *ie, size_t ie_len, u8 band) | ||
720 | { | ||
721 | struct sk_buff *skb; | ||
722 | int ret; | ||
723 | |||
724 | skb = ieee80211_probereq_get(wl->hw, wl->vif, ssid, ssid_len, | ||
725 | ie, ie_len); | ||
726 | if (!skb) { | ||
727 | ret = -ENOMEM; | ||
728 | goto out; | ||
729 | } | ||
730 | |||
731 | wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len); | ||
732 | |||
733 | if (band == IEEE80211_BAND_2GHZ) | ||
734 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, | ||
735 | skb->data, skb->len, 0, | ||
736 | wl->conf.tx.basic_rate); | ||
737 | else | ||
738 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5, | ||
739 | skb->data, skb->len, 0, | ||
740 | wl->conf.tx.basic_rate_5); | ||
741 | |||
742 | out: | ||
743 | dev_kfree_skb(skb); | ||
744 | return ret; | ||
745 | } | ||
746 | |||
747 | struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl, | ||
748 | struct sk_buff *skb) | ||
749 | { | ||
750 | int ret; | ||
751 | |||
752 | if (!skb) | ||
753 | skb = ieee80211_ap_probereq_get(wl->hw, wl->vif); | ||
754 | if (!skb) | ||
755 | goto out; | ||
756 | |||
757 | wl1271_dump(DEBUG_SCAN, "AP PROBE REQ: ", skb->data, skb->len); | ||
758 | |||
759 | if (wl->band == IEEE80211_BAND_2GHZ) | ||
760 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, | ||
761 | skb->data, skb->len, 0, | ||
762 | wl->conf.tx.basic_rate); | ||
763 | else | ||
764 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5, | ||
765 | skb->data, skb->len, 0, | ||
766 | wl->conf.tx.basic_rate_5); | ||
767 | |||
768 | if (ret < 0) | ||
769 | wl1271_error("Unable to set ap probe request template."); | ||
770 | |||
771 | out: | ||
772 | return skb; | ||
773 | } | ||
774 | |||
775 | int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, __be32 ip_addr) | ||
776 | { | ||
777 | int ret; | ||
778 | struct wl12xx_arp_rsp_template tmpl; | ||
779 | struct ieee80211_hdr_3addr *hdr; | ||
780 | struct arphdr *arp_hdr; | ||
781 | |||
782 | memset(&tmpl, 0, sizeof(tmpl)); | ||
783 | |||
784 | /* mac80211 header */ | ||
785 | hdr = &tmpl.hdr; | ||
786 | hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | | ||
787 | IEEE80211_STYPE_DATA | | ||
788 | IEEE80211_FCTL_TODS); | ||
789 | memcpy(hdr->addr1, wl->vif->bss_conf.bssid, ETH_ALEN); | ||
790 | memcpy(hdr->addr2, wl->vif->addr, ETH_ALEN); | ||
791 | memset(hdr->addr3, 0xff, ETH_ALEN); | ||
792 | |||
793 | /* llc layer */ | ||
794 | memcpy(tmpl.llc_hdr, rfc1042_header, sizeof(rfc1042_header)); | ||
795 | tmpl.llc_type = cpu_to_be16(ETH_P_ARP); | ||
796 | |||
797 | /* arp header */ | ||
798 | arp_hdr = &tmpl.arp_hdr; | ||
799 | arp_hdr->ar_hrd = cpu_to_be16(ARPHRD_ETHER); | ||
800 | arp_hdr->ar_pro = cpu_to_be16(ETH_P_IP); | ||
801 | arp_hdr->ar_hln = ETH_ALEN; | ||
802 | arp_hdr->ar_pln = 4; | ||
803 | arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY); | ||
804 | |||
805 | /* arp payload */ | ||
806 | memcpy(tmpl.sender_hw, wl->vif->addr, ETH_ALEN); | ||
807 | tmpl.sender_ip = ip_addr; | ||
808 | |||
809 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_ARP_RSP, | ||
810 | &tmpl, sizeof(tmpl), 0, | ||
811 | wl->basic_rate); | ||
812 | |||
813 | return ret; | ||
814 | } | ||
815 | |||
816 | int wl1271_build_qos_null_data(struct wl1271 *wl) | ||
817 | { | ||
818 | struct ieee80211_qos_hdr template; | ||
819 | |||
820 | memset(&template, 0, sizeof(template)); | ||
821 | |||
822 | memcpy(template.addr1, wl->bssid, ETH_ALEN); | ||
823 | memcpy(template.addr2, wl->mac_addr, ETH_ALEN); | ||
824 | memcpy(template.addr3, wl->bssid, ETH_ALEN); | ||
825 | |||
826 | template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | | ||
827 | IEEE80211_STYPE_QOS_NULLFUNC | | ||
828 | IEEE80211_FCTL_TODS); | ||
829 | |||
830 | /* FIXME: not sure what priority to use here */ | ||
831 | template.qos_ctrl = cpu_to_le16(0); | ||
832 | |||
833 | return wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, &template, | ||
834 | sizeof(template), 0, | ||
835 | wl->basic_rate); | ||
836 | } | ||
837 | |||
838 | int wl1271_cmd_set_sta_default_wep_key(struct wl1271 *wl, u8 id) | ||
839 | { | ||
840 | struct wl1271_cmd_set_sta_keys *cmd; | ||
841 | int ret = 0; | ||
842 | |||
843 | wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id); | ||
844 | |||
845 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | ||
846 | if (!cmd) { | ||
847 | ret = -ENOMEM; | ||
848 | goto out; | ||
849 | } | ||
850 | |||
851 | cmd->id = id; | ||
852 | cmd->key_action = cpu_to_le16(KEY_SET_ID); | ||
853 | cmd->key_type = KEY_WEP; | ||
854 | |||
855 | ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0); | ||
856 | if (ret < 0) { | ||
857 | wl1271_warning("cmd set_default_wep_key failed: %d", ret); | ||
858 | goto out; | ||
859 | } | ||
860 | |||
861 | out: | ||
862 | kfree(cmd); | ||
863 | |||
864 | return ret; | ||
865 | } | ||
866 | |||
867 | int wl1271_cmd_set_ap_default_wep_key(struct wl1271 *wl, u8 id) | ||
868 | { | ||
869 | struct wl1271_cmd_set_ap_keys *cmd; | ||
870 | int ret = 0; | ||
871 | |||
872 | wl1271_debug(DEBUG_CMD, "cmd set_ap_default_wep_key %d", id); | ||
873 | |||
874 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | ||
875 | if (!cmd) { | ||
876 | ret = -ENOMEM; | ||
877 | goto out; | ||
878 | } | ||
879 | |||
880 | cmd->hlid = WL1271_AP_BROADCAST_HLID; | ||
881 | cmd->key_id = id; | ||
882 | cmd->lid_key_type = WEP_DEFAULT_LID_TYPE; | ||
883 | cmd->key_action = cpu_to_le16(KEY_SET_ID); | ||
884 | cmd->key_type = KEY_WEP; | ||
885 | |||
886 | ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0); | ||
887 | if (ret < 0) { | ||
888 | wl1271_warning("cmd set_ap_default_wep_key failed: %d", ret); | ||
889 | goto out; | ||
890 | } | ||
891 | |||
892 | out: | ||
893 | kfree(cmd); | ||
894 | |||
895 | return ret; | ||
896 | } | ||
897 | |||
898 | int wl1271_cmd_set_sta_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type, | ||
899 | u8 key_size, const u8 *key, const u8 *addr, | ||
900 | u32 tx_seq_32, u16 tx_seq_16) | ||
901 | { | ||
902 | struct wl1271_cmd_set_sta_keys *cmd; | ||
903 | int ret = 0; | ||
904 | |||
905 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | ||
906 | if (!cmd) { | ||
907 | ret = -ENOMEM; | ||
908 | goto out; | ||
909 | } | ||
910 | |||
911 | if (key_type != KEY_WEP) | ||
912 | memcpy(cmd->addr, addr, ETH_ALEN); | ||
913 | |||
914 | cmd->key_action = cpu_to_le16(action); | ||
915 | cmd->key_size = key_size; | ||
916 | cmd->key_type = key_type; | ||
917 | |||
918 | cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16); | ||
919 | cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32); | ||
920 | |||
921 | /* we have only one SSID profile */ | ||
922 | cmd->ssid_profile = 0; | ||
923 | |||
924 | cmd->id = id; | ||
925 | |||
926 | if (key_type == KEY_TKIP) { | ||
927 | /* | ||
928 | * We get the key in the following form: | ||
929 | * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes) | ||
930 | * but the target is expecting: | ||
931 | * TKIP - RX MIC - TX MIC | ||
932 | */ | ||
933 | memcpy(cmd->key, key, 16); | ||
934 | memcpy(cmd->key + 16, key + 24, 8); | ||
935 | memcpy(cmd->key + 24, key + 16, 8); | ||
936 | |||
937 | } else { | ||
938 | memcpy(cmd->key, key, key_size); | ||
939 | } | ||
940 | |||
941 | wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd)); | ||
942 | |||
943 | ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0); | ||
944 | if (ret < 0) { | ||
945 | wl1271_warning("could not set keys"); | ||
946 | goto out; | ||
947 | } | ||
948 | |||
949 | out: | ||
950 | kfree(cmd); | ||
951 | |||
952 | return ret; | ||
953 | } | ||
954 | |||
955 | int wl1271_cmd_set_ap_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type, | ||
956 | u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32, | ||
957 | u16 tx_seq_16) | ||
958 | { | ||
959 | struct wl1271_cmd_set_ap_keys *cmd; | ||
960 | int ret = 0; | ||
961 | u8 lid_type; | ||
962 | |||
963 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | ||
964 | if (!cmd) | ||
965 | return -ENOMEM; | ||
966 | |||
967 | if (hlid == WL1271_AP_BROADCAST_HLID) { | ||
968 | if (key_type == KEY_WEP) | ||
969 | lid_type = WEP_DEFAULT_LID_TYPE; | ||
970 | else | ||
971 | lid_type = BROADCAST_LID_TYPE; | ||
972 | } else { | ||
973 | lid_type = UNICAST_LID_TYPE; | ||
974 | } | ||
975 | |||
976 | wl1271_debug(DEBUG_CRYPT, "ap key action: %d id: %d lid: %d type: %d" | ||
977 | " hlid: %d", (int)action, (int)id, (int)lid_type, | ||
978 | (int)key_type, (int)hlid); | ||
979 | |||
980 | cmd->lid_key_type = lid_type; | ||
981 | cmd->hlid = hlid; | ||
982 | cmd->key_action = cpu_to_le16(action); | ||
983 | cmd->key_size = key_size; | ||
984 | cmd->key_type = key_type; | ||
985 | cmd->key_id = id; | ||
986 | cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16); | ||
987 | cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32); | ||
988 | |||
989 | if (key_type == KEY_TKIP) { | ||
990 | /* | ||
991 | * We get the key in the following form: | ||
992 | * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes) | ||
993 | * but the target is expecting: | ||
994 | * TKIP - RX MIC - TX MIC | ||
995 | */ | ||
996 | memcpy(cmd->key, key, 16); | ||
997 | memcpy(cmd->key + 16, key + 24, 8); | ||
998 | memcpy(cmd->key + 24, key + 16, 8); | ||
999 | } else { | ||
1000 | memcpy(cmd->key, key, key_size); | ||
1001 | } | ||
1002 | |||
1003 | wl1271_dump(DEBUG_CRYPT, "TARGET AP KEY: ", cmd, sizeof(*cmd)); | ||
1004 | |||
1005 | ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0); | ||
1006 | if (ret < 0) { | ||
1007 | wl1271_warning("could not set ap keys"); | ||
1008 | goto out; | ||
1009 | } | ||
1010 | |||
1011 | out: | ||
1012 | kfree(cmd); | ||
1013 | return ret; | ||
1014 | } | ||
1015 | |||
1016 | int wl1271_cmd_disconnect(struct wl1271 *wl) | ||
1017 | { | ||
1018 | struct wl1271_cmd_disconnect *cmd; | ||
1019 | int ret = 0; | ||
1020 | |||
1021 | wl1271_debug(DEBUG_CMD, "cmd disconnect"); | ||
1022 | |||
1023 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | ||
1024 | if (!cmd) { | ||
1025 | ret = -ENOMEM; | ||
1026 | goto out; | ||
1027 | } | ||
1028 | |||
1029 | cmd->rx_config_options = cpu_to_le32(wl->rx_config); | ||
1030 | cmd->rx_filter_options = cpu_to_le32(wl->rx_filter); | ||
1031 | /* disconnect reason is not used in immediate disconnections */ | ||
1032 | cmd->type = DISCONNECT_IMMEDIATE; | ||
1033 | |||
1034 | ret = wl1271_cmd_send(wl, CMD_DISCONNECT, cmd, sizeof(*cmd), 0); | ||
1035 | if (ret < 0) { | ||
1036 | wl1271_error("failed to send disconnect command"); | ||
1037 | goto out_free; | ||
1038 | } | ||
1039 | |||
1040 | ret = wl1271_cmd_wait_for_event(wl, DISCONNECT_EVENT_COMPLETE_ID); | ||
1041 | if (ret < 0) | ||
1042 | wl1271_error("cmd disconnect event completion error"); | ||
1043 | |||
1044 | out_free: | ||
1045 | kfree(cmd); | ||
1046 | |||
1047 | out: | ||
1048 | return ret; | ||
1049 | } | ||
1050 | |||
1051 | int wl1271_cmd_set_sta_state(struct wl1271 *wl) | ||
1052 | { | ||
1053 | struct wl1271_cmd_set_sta_state *cmd; | ||
1054 | int ret = 0; | ||
1055 | |||
1056 | wl1271_debug(DEBUG_CMD, "cmd set sta state"); | ||
1057 | |||
1058 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | ||
1059 | if (!cmd) { | ||
1060 | ret = -ENOMEM; | ||
1061 | goto out; | ||
1062 | } | ||
1063 | |||
1064 | cmd->state = WL1271_CMD_STA_STATE_CONNECTED; | ||
1065 | |||
1066 | ret = wl1271_cmd_send(wl, CMD_SET_STA_STATE, cmd, sizeof(*cmd), 0); | ||
1067 | if (ret < 0) { | ||
1068 | wl1271_error("failed to send set STA state command"); | ||
1069 | goto out_free; | ||
1070 | } | ||
1071 | |||
1072 | out_free: | ||
1073 | kfree(cmd); | ||
1074 | |||
1075 | out: | ||
1076 | return ret; | ||
1077 | } | ||
1078 | |||
1079 | int wl1271_cmd_start_bss(struct wl1271 *wl) | ||
1080 | { | ||
1081 | struct wl1271_cmd_bss_start *cmd; | ||
1082 | struct ieee80211_bss_conf *bss_conf = &wl->vif->bss_conf; | ||
1083 | int ret; | ||
1084 | |||
1085 | wl1271_debug(DEBUG_CMD, "cmd start bss"); | ||
1086 | |||
1087 | /* | ||
1088 | * FIXME: We currently do not support hidden SSID. The real SSID | ||
1089 | * should be fetched from mac80211 first. | ||
1090 | */ | ||
1091 | if (wl->ssid_len == 0) { | ||
1092 | wl1271_warning("Hidden SSID currently not supported for AP"); | ||
1093 | ret = -EINVAL; | ||
1094 | goto out; | ||
1095 | } | ||
1096 | |||
1097 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | ||
1098 | if (!cmd) { | ||
1099 | ret = -ENOMEM; | ||
1100 | goto out; | ||
1101 | } | ||
1102 | |||
1103 | memcpy(cmd->bssid, bss_conf->bssid, ETH_ALEN); | ||
1104 | |||
1105 | cmd->aging_period = cpu_to_le16(wl->conf.tx.ap_aging_period); | ||
1106 | cmd->bss_index = WL1271_AP_BSS_INDEX; | ||
1107 | cmd->global_hlid = WL1271_AP_GLOBAL_HLID; | ||
1108 | cmd->broadcast_hlid = WL1271_AP_BROADCAST_HLID; | ||
1109 | cmd->basic_rate_set = cpu_to_le32(wl->basic_rate_set); | ||
1110 | cmd->beacon_interval = cpu_to_le16(wl->beacon_int); | ||
1111 | cmd->dtim_interval = bss_conf->dtim_period; | ||
1112 | cmd->beacon_expiry = WL1271_AP_DEF_BEACON_EXP; | ||
1113 | cmd->channel = wl->channel; | ||
1114 | cmd->ssid_len = wl->ssid_len; | ||
1115 | cmd->ssid_type = SSID_TYPE_PUBLIC; | ||
1116 | memcpy(cmd->ssid, wl->ssid, wl->ssid_len); | ||
1117 | |||
1118 | switch (wl->band) { | ||
1119 | case IEEE80211_BAND_2GHZ: | ||
1120 | cmd->band = RADIO_BAND_2_4GHZ; | ||
1121 | break; | ||
1122 | case IEEE80211_BAND_5GHZ: | ||
1123 | cmd->band = RADIO_BAND_5GHZ; | ||
1124 | break; | ||
1125 | default: | ||
1126 | wl1271_warning("bss start - unknown band: %d", (int)wl->band); | ||
1127 | cmd->band = RADIO_BAND_2_4GHZ; | ||
1128 | break; | ||
1129 | } | ||
1130 | |||
1131 | ret = wl1271_cmd_send(wl, CMD_BSS_START, cmd, sizeof(*cmd), 0); | ||
1132 | if (ret < 0) { | ||
1133 | wl1271_error("failed to initiate cmd start bss"); | ||
1134 | goto out_free; | ||
1135 | } | ||
1136 | |||
1137 | out_free: | ||
1138 | kfree(cmd); | ||
1139 | |||
1140 | out: | ||
1141 | return ret; | ||
1142 | } | ||
1143 | |||
1144 | int wl1271_cmd_stop_bss(struct wl1271 *wl) | ||
1145 | { | ||
1146 | struct wl1271_cmd_bss_start *cmd; | ||
1147 | int ret; | ||
1148 | |||
1149 | wl1271_debug(DEBUG_CMD, "cmd stop bss"); | ||
1150 | |||
1151 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | ||
1152 | if (!cmd) { | ||
1153 | ret = -ENOMEM; | ||
1154 | goto out; | ||
1155 | } | ||
1156 | |||
1157 | cmd->bss_index = WL1271_AP_BSS_INDEX; | ||
1158 | |||
1159 | ret = wl1271_cmd_send(wl, CMD_BSS_STOP, cmd, sizeof(*cmd), 0); | ||
1160 | if (ret < 0) { | ||
1161 | wl1271_error("failed to initiate cmd stop bss"); | ||
1162 | goto out_free; | ||
1163 | } | ||
1164 | |||
1165 | out_free: | ||
1166 | kfree(cmd); | ||
1167 | |||
1168 | out: | ||
1169 | return ret; | ||
1170 | } | ||
1171 | |||
1172 | int wl1271_cmd_add_sta(struct wl1271 *wl, struct ieee80211_sta *sta, u8 hlid) | ||
1173 | { | ||
1174 | struct wl1271_cmd_add_sta *cmd; | ||
1175 | int ret; | ||
1176 | |||
1177 | wl1271_debug(DEBUG_CMD, "cmd add sta %d", (int)hlid); | ||
1178 | |||
1179 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | ||
1180 | if (!cmd) { | ||
1181 | ret = -ENOMEM; | ||
1182 | goto out; | ||
1183 | } | ||
1184 | |||
1185 | /* currently we don't support UAPSD */ | ||
1186 | cmd->sp_len = 0; | ||
1187 | |||
1188 | memcpy(cmd->addr, sta->addr, ETH_ALEN); | ||
1189 | cmd->bss_index = WL1271_AP_BSS_INDEX; | ||
1190 | cmd->aid = sta->aid; | ||
1191 | cmd->hlid = hlid; | ||
1192 | cmd->wmm = sta->wme ? 1 : 0; | ||
1193 | |||
1194 | cmd->supported_rates = cpu_to_le32(wl1271_tx_enabled_rates_get(wl, | ||
1195 | sta->supp_rates[wl->band])); | ||
1196 | |||
1197 | wl1271_debug(DEBUG_CMD, "new sta rates: 0x%x", cmd->supported_rates); | ||
1198 | |||
1199 | ret = wl1271_cmd_send(wl, CMD_ADD_STA, cmd, sizeof(*cmd), 0); | ||
1200 | if (ret < 0) { | ||
1201 | wl1271_error("failed to initiate cmd add sta"); | ||
1202 | goto out_free; | ||
1203 | } | ||
1204 | |||
1205 | out_free: | ||
1206 | kfree(cmd); | ||
1207 | |||
1208 | out: | ||
1209 | return ret; | ||
1210 | } | ||
1211 | |||
1212 | int wl1271_cmd_remove_sta(struct wl1271 *wl, u8 hlid) | ||
1213 | { | ||
1214 | struct wl1271_cmd_remove_sta *cmd; | ||
1215 | int ret; | ||
1216 | |||
1217 | wl1271_debug(DEBUG_CMD, "cmd remove sta %d", (int)hlid); | ||
1218 | |||
1219 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | ||
1220 | if (!cmd) { | ||
1221 | ret = -ENOMEM; | ||
1222 | goto out; | ||
1223 | } | ||
1224 | |||
1225 | cmd->hlid = hlid; | ||
1226 | /* We never send a deauth, mac80211 is in charge of this */ | ||
1227 | cmd->reason_opcode = 0; | ||
1228 | cmd->send_deauth_flag = 0; | ||
1229 | |||
1230 | ret = wl1271_cmd_send(wl, CMD_REMOVE_STA, cmd, sizeof(*cmd), 0); | ||
1231 | if (ret < 0) { | ||
1232 | wl1271_error("failed to initiate cmd remove sta"); | ||
1233 | goto out_free; | ||
1234 | } | ||
1235 | |||
1236 | /* | ||
1237 | * We are ok with a timeout here. The event is sometimes not sent | ||
1238 | * due to a firmware bug. | ||
1239 | */ | ||
1240 | wl1271_cmd_wait_for_event_or_timeout(wl, STA_REMOVE_COMPLETE_EVENT_ID); | ||
1241 | |||
1242 | out_free: | ||
1243 | kfree(cmd); | ||
1244 | |||
1245 | out: | ||
1246 | return ret; | ||
1247 | } | ||
1248 | |||
1249 | int wl12xx_cmd_config_fwlog(struct wl1271 *wl) | ||
1250 | { | ||
1251 | struct wl12xx_cmd_config_fwlog *cmd; | ||
1252 | int ret = 0; | ||
1253 | |||
1254 | wl1271_debug(DEBUG_CMD, "cmd config firmware logger"); | ||
1255 | |||
1256 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | ||
1257 | if (!cmd) { | ||
1258 | ret = -ENOMEM; | ||
1259 | goto out; | ||
1260 | } | ||
1261 | |||
1262 | cmd->logger_mode = wl->conf.fwlog.mode; | ||
1263 | cmd->log_severity = wl->conf.fwlog.severity; | ||
1264 | cmd->timestamp = wl->conf.fwlog.timestamp; | ||
1265 | cmd->output = wl->conf.fwlog.output; | ||
1266 | cmd->threshold = wl->conf.fwlog.threshold; | ||
1267 | |||
1268 | ret = wl1271_cmd_send(wl, CMD_CONFIG_FWLOGGER, cmd, sizeof(*cmd), 0); | ||
1269 | if (ret < 0) { | ||
1270 | wl1271_error("failed to send config firmware logger command"); | ||
1271 | goto out_free; | ||
1272 | } | ||
1273 | |||
1274 | out_free: | ||
1275 | kfree(cmd); | ||
1276 | |||
1277 | out: | ||
1278 | return ret; | ||
1279 | } | ||
1280 | |||
1281 | int wl12xx_cmd_start_fwlog(struct wl1271 *wl) | ||
1282 | { | ||
1283 | struct wl12xx_cmd_start_fwlog *cmd; | ||
1284 | int ret = 0; | ||
1285 | |||
1286 | wl1271_debug(DEBUG_CMD, "cmd start firmware logger"); | ||
1287 | |||
1288 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | ||
1289 | if (!cmd) { | ||
1290 | ret = -ENOMEM; | ||
1291 | goto out; | ||
1292 | } | ||
1293 | |||
1294 | ret = wl1271_cmd_send(wl, CMD_START_FWLOGGER, cmd, sizeof(*cmd), 0); | ||
1295 | if (ret < 0) { | ||
1296 | wl1271_error("failed to send start firmware logger command"); | ||
1297 | goto out_free; | ||
1298 | } | ||
1299 | |||
1300 | out_free: | ||
1301 | kfree(cmd); | ||
1302 | |||
1303 | out: | ||
1304 | return ret; | ||
1305 | } | ||
1306 | |||
1307 | int wl12xx_cmd_stop_fwlog(struct wl1271 *wl) | ||
1308 | { | ||
1309 | struct wl12xx_cmd_stop_fwlog *cmd; | ||
1310 | int ret = 0; | ||
1311 | |||
1312 | wl1271_debug(DEBUG_CMD, "cmd stop firmware logger"); | ||
1313 | |||
1314 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | ||
1315 | if (!cmd) { | ||
1316 | ret = -ENOMEM; | ||
1317 | goto out; | ||
1318 | } | ||
1319 | |||
1320 | ret = wl1271_cmd_send(wl, CMD_STOP_FWLOGGER, cmd, sizeof(*cmd), 0); | ||
1321 | if (ret < 0) { | ||
1322 | wl1271_error("failed to send stop firmware logger command"); | ||
1323 | goto out_free; | ||
1324 | } | ||
1325 | |||
1326 | out_free: | ||
1327 | kfree(cmd); | ||
1328 | |||
1329 | out: | ||
1330 | return ret; | ||
1331 | } | ||
diff --git a/drivers/net/wireless/wl12xx/cmd.h b/drivers/net/wireless/wl12xx/cmd.h new file mode 100644 index 00000000000..1f7037292c1 --- /dev/null +++ b/drivers/net/wireless/wl12xx/cmd.h | |||
@@ -0,0 +1,640 @@ | |||
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 "wl12xx.h" | ||
29 | |||
30 | struct acx_header; | ||
31 | |||
32 | int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len, | ||
33 | size_t res_len); | ||
34 | int wl1271_cmd_general_parms(struct wl1271 *wl); | ||
35 | int wl128x_cmd_general_parms(struct wl1271 *wl); | ||
36 | int wl1271_cmd_radio_parms(struct wl1271 *wl); | ||
37 | int wl128x_cmd_radio_parms(struct wl1271 *wl); | ||
38 | int wl1271_cmd_ext_radio_parms(struct wl1271 *wl); | ||
39 | int wl1271_cmd_join(struct wl1271 *wl, u8 bss_type); | ||
40 | int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer); | ||
41 | int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len); | ||
42 | int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len); | ||
43 | int wl1271_cmd_data_path(struct wl1271 *wl, bool enable); | ||
44 | int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode); | ||
45 | int wl1271_cmd_read_memory(struct wl1271 *wl, u32 addr, void *answer, | ||
46 | size_t len); | ||
47 | int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id, | ||
48 | void *buf, size_t buf_len, int index, u32 rates); | ||
49 | int wl1271_cmd_build_null_data(struct wl1271 *wl); | ||
50 | int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid); | ||
51 | int wl1271_cmd_build_probe_req(struct wl1271 *wl, | ||
52 | const u8 *ssid, size_t ssid_len, | ||
53 | const u8 *ie, size_t ie_len, u8 band); | ||
54 | struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl, | ||
55 | struct sk_buff *skb); | ||
56 | int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, __be32 ip_addr); | ||
57 | int wl1271_build_qos_null_data(struct wl1271 *wl); | ||
58 | int wl1271_cmd_build_klv_null_data(struct wl1271 *wl); | ||
59 | int wl1271_cmd_set_sta_default_wep_key(struct wl1271 *wl, u8 id); | ||
60 | int wl1271_cmd_set_ap_default_wep_key(struct wl1271 *wl, u8 id); | ||
61 | int wl1271_cmd_set_sta_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type, | ||
62 | u8 key_size, const u8 *key, const u8 *addr, | ||
63 | u32 tx_seq_32, u16 tx_seq_16); | ||
64 | int wl1271_cmd_set_ap_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type, | ||
65 | u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32, | ||
66 | u16 tx_seq_16); | ||
67 | int wl1271_cmd_disconnect(struct wl1271 *wl); | ||
68 | int wl1271_cmd_set_sta_state(struct wl1271 *wl); | ||
69 | int wl1271_cmd_start_bss(struct wl1271 *wl); | ||
70 | int wl1271_cmd_stop_bss(struct wl1271 *wl); | ||
71 | int wl1271_cmd_add_sta(struct wl1271 *wl, struct ieee80211_sta *sta, u8 hlid); | ||
72 | int wl1271_cmd_remove_sta(struct wl1271 *wl, u8 hlid); | ||
73 | int wl12xx_cmd_config_fwlog(struct wl1271 *wl); | ||
74 | int wl12xx_cmd_start_fwlog(struct wl1271 *wl); | ||
75 | int wl12xx_cmd_stop_fwlog(struct wl1271 *wl); | ||
76 | |||
77 | enum wl1271_commands { | ||
78 | CMD_INTERROGATE = 1, /*use this to read information elements*/ | ||
79 | CMD_CONFIGURE = 2, /*use this to write information elements*/ | ||
80 | CMD_ENABLE_RX = 3, | ||
81 | CMD_ENABLE_TX = 4, | ||
82 | CMD_DISABLE_RX = 5, | ||
83 | CMD_DISABLE_TX = 6, | ||
84 | CMD_SCAN = 8, | ||
85 | CMD_STOP_SCAN = 9, | ||
86 | CMD_START_JOIN = 11, | ||
87 | CMD_SET_KEYS = 12, | ||
88 | CMD_READ_MEMORY = 13, | ||
89 | CMD_WRITE_MEMORY = 14, | ||
90 | CMD_SET_TEMPLATE = 19, | ||
91 | CMD_TEST = 23, | ||
92 | CMD_NOISE_HIST = 28, | ||
93 | CMD_LNA_CONTROL = 32, | ||
94 | CMD_SET_BCN_MODE = 33, | ||
95 | CMD_MEASUREMENT = 34, | ||
96 | CMD_STOP_MEASUREMENT = 35, | ||
97 | CMD_DISCONNECT = 36, | ||
98 | CMD_SET_PS_MODE = 37, | ||
99 | CMD_CHANNEL_SWITCH = 38, | ||
100 | CMD_STOP_CHANNEL_SWICTH = 39, | ||
101 | CMD_AP_DISCOVERY = 40, | ||
102 | CMD_STOP_AP_DISCOVERY = 41, | ||
103 | CMD_SPS_SCAN = 42, | ||
104 | CMD_STOP_SPS_SCAN = 43, | ||
105 | CMD_HEALTH_CHECK = 45, | ||
106 | CMD_DEBUG = 46, | ||
107 | CMD_TRIGGER_SCAN_TO = 47, | ||
108 | CMD_CONNECTION_SCAN_CFG = 48, | ||
109 | CMD_CONNECTION_SCAN_SSID_CFG = 49, | ||
110 | CMD_START_PERIODIC_SCAN = 50, | ||
111 | CMD_STOP_PERIODIC_SCAN = 51, | ||
112 | CMD_SET_STA_STATE = 52, | ||
113 | CMD_CONFIG_FWLOGGER = 53, | ||
114 | CMD_START_FWLOGGER = 54, | ||
115 | CMD_STOP_FWLOGGER = 55, | ||
116 | |||
117 | /* AP mode commands */ | ||
118 | CMD_BSS_START = 60, | ||
119 | CMD_BSS_STOP = 61, | ||
120 | CMD_ADD_STA = 62, | ||
121 | CMD_REMOVE_STA = 63, | ||
122 | |||
123 | NUM_COMMANDS, | ||
124 | MAX_COMMAND_ID = 0xFFFF, | ||
125 | }; | ||
126 | |||
127 | #define MAX_CMD_PARAMS 572 | ||
128 | |||
129 | enum { | ||
130 | CMD_TEMPL_KLV_IDX_NULL_DATA = 0, | ||
131 | CMD_TEMPL_KLV_IDX_MAX = 4 | ||
132 | }; | ||
133 | |||
134 | enum cmd_templ { | ||
135 | CMD_TEMPL_NULL_DATA = 0, | ||
136 | CMD_TEMPL_BEACON, | ||
137 | CMD_TEMPL_CFG_PROBE_REQ_2_4, | ||
138 | CMD_TEMPL_CFG_PROBE_REQ_5, | ||
139 | CMD_TEMPL_PROBE_RESPONSE, | ||
140 | CMD_TEMPL_QOS_NULL_DATA, | ||
141 | CMD_TEMPL_PS_POLL, | ||
142 | CMD_TEMPL_KLV, | ||
143 | CMD_TEMPL_DISCONNECT, | ||
144 | CMD_TEMPL_PROBE_REQ_2_4, /* for firmware internal use only */ | ||
145 | CMD_TEMPL_PROBE_REQ_5, /* for firmware internal use only */ | ||
146 | CMD_TEMPL_BAR, /* for firmware internal use only */ | ||
147 | CMD_TEMPL_CTS, /* | ||
148 | * For CTS-to-self (FastCTS) mechanism | ||
149 | * for BT/WLAN coexistence (SoftGemini). */ | ||
150 | CMD_TEMPL_ARP_RSP, | ||
151 | CMD_TEMPL_LINK_MEASUREMENT_REPORT, | ||
152 | |||
153 | /* AP-mode specific */ | ||
154 | CMD_TEMPL_AP_BEACON = 13, | ||
155 | CMD_TEMPL_AP_PROBE_RESPONSE, | ||
156 | CMD_TEMPL_AP_ARP_RSP, | ||
157 | CMD_TEMPL_DEAUTH_AP, | ||
158 | |||
159 | CMD_TEMPL_MAX = 0xff | ||
160 | }; | ||
161 | |||
162 | /* unit ms */ | ||
163 | #define WL1271_COMMAND_TIMEOUT 2000 | ||
164 | #define WL1271_CMD_TEMPL_MAX_SIZE 252 | ||
165 | #define WL1271_EVENT_TIMEOUT 750 | ||
166 | |||
167 | struct wl1271_cmd_header { | ||
168 | __le16 id; | ||
169 | __le16 status; | ||
170 | /* payload */ | ||
171 | u8 data[0]; | ||
172 | } __packed; | ||
173 | |||
174 | #define WL1271_CMD_MAX_PARAMS 572 | ||
175 | |||
176 | struct wl1271_command { | ||
177 | struct wl1271_cmd_header header; | ||
178 | u8 parameters[WL1271_CMD_MAX_PARAMS]; | ||
179 | } __packed; | ||
180 | |||
181 | enum { | ||
182 | CMD_MAILBOX_IDLE = 0, | ||
183 | CMD_STATUS_SUCCESS = 1, | ||
184 | CMD_STATUS_UNKNOWN_CMD = 2, | ||
185 | CMD_STATUS_UNKNOWN_IE = 3, | ||
186 | CMD_STATUS_REJECT_MEAS_SG_ACTIVE = 11, | ||
187 | CMD_STATUS_RX_BUSY = 13, | ||
188 | CMD_STATUS_INVALID_PARAM = 14, | ||
189 | CMD_STATUS_TEMPLATE_TOO_LARGE = 15, | ||
190 | CMD_STATUS_OUT_OF_MEMORY = 16, | ||
191 | CMD_STATUS_STA_TABLE_FULL = 17, | ||
192 | CMD_STATUS_RADIO_ERROR = 18, | ||
193 | CMD_STATUS_WRONG_NESTING = 19, | ||
194 | CMD_STATUS_TIMEOUT = 21, /* Driver internal use.*/ | ||
195 | CMD_STATUS_FW_RESET = 22, /* Driver internal use.*/ | ||
196 | MAX_COMMAND_STATUS = 0xff | ||
197 | }; | ||
198 | |||
199 | #define CMDMBOX_HEADER_LEN 4 | ||
200 | #define CMDMBOX_INFO_ELEM_HEADER_LEN 4 | ||
201 | |||
202 | enum { | ||
203 | BSS_TYPE_IBSS = 0, | ||
204 | BSS_TYPE_STA_BSS = 2, | ||
205 | BSS_TYPE_AP_BSS = 3, | ||
206 | MAX_BSS_TYPE = 0xFF | ||
207 | }; | ||
208 | |||
209 | #define WL1271_JOIN_CMD_CTRL_TX_FLUSH 0x80 /* Firmware flushes all Tx */ | ||
210 | #define WL1271_JOIN_CMD_TX_SESSION_OFFSET 1 | ||
211 | #define WL1271_JOIN_CMD_BSS_TYPE_5GHZ 0x10 | ||
212 | |||
213 | struct wl1271_cmd_join { | ||
214 | struct wl1271_cmd_header header; | ||
215 | |||
216 | __le32 bssid_lsb; | ||
217 | __le16 bssid_msb; | ||
218 | __le16 beacon_interval; /* in TBTTs */ | ||
219 | __le32 rx_config_options; | ||
220 | __le32 rx_filter_options; | ||
221 | |||
222 | /* | ||
223 | * The target uses this field to determine the rate at | ||
224 | * which to transmit control frame responses (such as | ||
225 | * ACK or CTS frames). | ||
226 | */ | ||
227 | __le32 basic_rate_set; | ||
228 | __le32 supported_rate_set; | ||
229 | u8 dtim_interval; | ||
230 | /* | ||
231 | * bits 0-2: This bitwise field specifies the type | ||
232 | * of BSS to start or join (BSS_TYPE_*). | ||
233 | * bit 4: Band - The radio band in which to join | ||
234 | * or start. | ||
235 | * 0 - 2.4GHz band | ||
236 | * 1 - 5GHz band | ||
237 | * bits 3, 5-7: Reserved | ||
238 | */ | ||
239 | u8 bss_type; | ||
240 | u8 channel; | ||
241 | u8 ssid_len; | ||
242 | u8 ssid[IW_ESSID_MAX_SIZE]; | ||
243 | u8 ctrl; /* JOIN_CMD_CTRL_* */ | ||
244 | u8 reserved[3]; | ||
245 | } __packed; | ||
246 | |||
247 | struct cmd_enabledisable_path { | ||
248 | struct wl1271_cmd_header header; | ||
249 | |||
250 | u8 channel; | ||
251 | u8 padding[3]; | ||
252 | } __packed; | ||
253 | |||
254 | #define WL1271_RATE_AUTOMATIC 0 | ||
255 | |||
256 | struct wl1271_cmd_template_set { | ||
257 | struct wl1271_cmd_header header; | ||
258 | |||
259 | __le16 len; | ||
260 | u8 template_type; | ||
261 | u8 index; /* relevant only for KLV_TEMPLATE type */ | ||
262 | __le32 enabled_rates; | ||
263 | u8 short_retry_limit; | ||
264 | u8 long_retry_limit; | ||
265 | u8 aflags; | ||
266 | u8 reserved; | ||
267 | u8 template_data[WL1271_CMD_TEMPL_MAX_SIZE]; | ||
268 | } __packed; | ||
269 | |||
270 | #define TIM_ELE_ID 5 | ||
271 | #define PARTIAL_VBM_MAX 251 | ||
272 | |||
273 | struct wl1271_tim { | ||
274 | u8 identity; | ||
275 | u8 length; | ||
276 | u8 dtim_count; | ||
277 | u8 dtim_period; | ||
278 | u8 bitmap_ctrl; | ||
279 | u8 pvb_field[PARTIAL_VBM_MAX]; /* Partial Virtual Bitmap */ | ||
280 | } __packed; | ||
281 | |||
282 | enum wl1271_cmd_ps_mode { | ||
283 | STATION_ACTIVE_MODE, | ||
284 | STATION_POWER_SAVE_MODE | ||
285 | }; | ||
286 | |||
287 | struct wl1271_cmd_ps_params { | ||
288 | struct wl1271_cmd_header header; | ||
289 | |||
290 | u8 ps_mode; /* STATION_* */ | ||
291 | u8 padding[3]; | ||
292 | } __packed; | ||
293 | |||
294 | /* HW encryption keys */ | ||
295 | #define NUM_ACCESS_CATEGORIES_COPY 4 | ||
296 | |||
297 | enum wl1271_cmd_key_action { | ||
298 | KEY_ADD_OR_REPLACE = 1, | ||
299 | KEY_REMOVE = 2, | ||
300 | KEY_SET_ID = 3, | ||
301 | MAX_KEY_ACTION = 0xffff, | ||
302 | }; | ||
303 | |||
304 | enum wl1271_cmd_key_type { | ||
305 | KEY_NONE = 0, | ||
306 | KEY_WEP = 1, | ||
307 | KEY_TKIP = 2, | ||
308 | KEY_AES = 3, | ||
309 | KEY_GEM = 4, | ||
310 | }; | ||
311 | |||
312 | /* FIXME: Add description for key-types */ | ||
313 | |||
314 | struct wl1271_cmd_set_sta_keys { | ||
315 | struct wl1271_cmd_header header; | ||
316 | |||
317 | /* Ignored for default WEP key */ | ||
318 | u8 addr[ETH_ALEN]; | ||
319 | |||
320 | /* key_action_e */ | ||
321 | __le16 key_action; | ||
322 | |||
323 | __le16 reserved_1; | ||
324 | |||
325 | /* key size in bytes */ | ||
326 | u8 key_size; | ||
327 | |||
328 | /* key_type_e */ | ||
329 | u8 key_type; | ||
330 | u8 ssid_profile; | ||
331 | |||
332 | /* | ||
333 | * TKIP, AES: frame's key id field. | ||
334 | * For WEP default key: key id; | ||
335 | */ | ||
336 | u8 id; | ||
337 | u8 reserved_2[6]; | ||
338 | u8 key[MAX_KEY_SIZE]; | ||
339 | __le16 ac_seq_num16[NUM_ACCESS_CATEGORIES_COPY]; | ||
340 | __le32 ac_seq_num32[NUM_ACCESS_CATEGORIES_COPY]; | ||
341 | } __packed; | ||
342 | |||
343 | enum wl1271_cmd_lid_key_type { | ||
344 | UNICAST_LID_TYPE = 0, | ||
345 | BROADCAST_LID_TYPE = 1, | ||
346 | WEP_DEFAULT_LID_TYPE = 2 | ||
347 | }; | ||
348 | |||
349 | struct wl1271_cmd_set_ap_keys { | ||
350 | struct wl1271_cmd_header header; | ||
351 | |||
352 | /* | ||
353 | * Indicates whether the HLID is a unicast key set | ||
354 | * or broadcast key set. A special value 0xFF is | ||
355 | * used to indicate that the HLID is on WEP-default | ||
356 | * (multi-hlids). of type wl1271_cmd_lid_key_type. | ||
357 | */ | ||
358 | u8 hlid; | ||
359 | |||
360 | /* | ||
361 | * In WEP-default network (hlid == 0xFF) used to | ||
362 | * indicate which network STA/IBSS/AP role should be | ||
363 | * changed | ||
364 | */ | ||
365 | u8 lid_key_type; | ||
366 | |||
367 | /* | ||
368 | * Key ID - For TKIP and AES key types, this field | ||
369 | * indicates the value that should be inserted into | ||
370 | * the KeyID field of frames transmitted using this | ||
371 | * key entry. For broadcast keys the index use as a | ||
372 | * marker for TX/RX key. | ||
373 | * For WEP default network (HLID=0xFF), this field | ||
374 | * indicates the ID of the key to add or remove. | ||
375 | */ | ||
376 | u8 key_id; | ||
377 | u8 reserved_1; | ||
378 | |||
379 | /* key_action_e */ | ||
380 | __le16 key_action; | ||
381 | |||
382 | /* key size in bytes */ | ||
383 | u8 key_size; | ||
384 | |||
385 | /* key_type_e */ | ||
386 | u8 key_type; | ||
387 | |||
388 | /* This field holds the security key data to add to the STA table */ | ||
389 | u8 key[MAX_KEY_SIZE]; | ||
390 | __le16 ac_seq_num16[NUM_ACCESS_CATEGORIES_COPY]; | ||
391 | __le32 ac_seq_num32[NUM_ACCESS_CATEGORIES_COPY]; | ||
392 | } __packed; | ||
393 | |||
394 | struct wl1271_cmd_test_header { | ||
395 | u8 id; | ||
396 | u8 padding[3]; | ||
397 | } __packed; | ||
398 | |||
399 | enum wl1271_channel_tune_bands { | ||
400 | WL1271_CHANNEL_TUNE_BAND_2_4, | ||
401 | WL1271_CHANNEL_TUNE_BAND_5, | ||
402 | WL1271_CHANNEL_TUNE_BAND_4_9 | ||
403 | }; | ||
404 | |||
405 | #define WL1271_PD_REFERENCE_POINT_BAND_B_G 0 | ||
406 | |||
407 | #define TEST_CMD_INI_FILE_RADIO_PARAM 0x19 | ||
408 | #define TEST_CMD_INI_FILE_GENERAL_PARAM 0x1E | ||
409 | #define TEST_CMD_INI_FILE_RF_EXTENDED_PARAM 0x26 | ||
410 | |||
411 | struct wl1271_general_parms_cmd { | ||
412 | struct wl1271_cmd_header header; | ||
413 | |||
414 | struct wl1271_cmd_test_header test; | ||
415 | |||
416 | struct wl1271_ini_general_params general_params; | ||
417 | |||
418 | u8 sr_debug_table[WL1271_INI_MAX_SMART_REFLEX_PARAM]; | ||
419 | u8 sr_sen_n_p; | ||
420 | u8 sr_sen_n_p_gain; | ||
421 | u8 sr_sen_nrn; | ||
422 | u8 sr_sen_prn; | ||
423 | u8 padding[3]; | ||
424 | } __packed; | ||
425 | |||
426 | struct wl128x_general_parms_cmd { | ||
427 | struct wl1271_cmd_header header; | ||
428 | |||
429 | struct wl1271_cmd_test_header test; | ||
430 | |||
431 | struct wl128x_ini_general_params general_params; | ||
432 | |||
433 | u8 sr_debug_table[WL1271_INI_MAX_SMART_REFLEX_PARAM]; | ||
434 | u8 sr_sen_n_p; | ||
435 | u8 sr_sen_n_p_gain; | ||
436 | u8 sr_sen_nrn; | ||
437 | u8 sr_sen_prn; | ||
438 | u8 padding[3]; | ||
439 | } __packed; | ||
440 | |||
441 | struct wl1271_radio_parms_cmd { | ||
442 | struct wl1271_cmd_header header; | ||
443 | |||
444 | struct wl1271_cmd_test_header test; | ||
445 | |||
446 | /* Static radio parameters */ | ||
447 | struct wl1271_ini_band_params_2 static_params_2; | ||
448 | struct wl1271_ini_band_params_5 static_params_5; | ||
449 | |||
450 | /* Dynamic radio parameters */ | ||
451 | struct wl1271_ini_fem_params_2 dyn_params_2; | ||
452 | u8 padding2; | ||
453 | struct wl1271_ini_fem_params_5 dyn_params_5; | ||
454 | u8 padding3[2]; | ||
455 | } __packed; | ||
456 | |||
457 | struct wl128x_radio_parms_cmd { | ||
458 | struct wl1271_cmd_header header; | ||
459 | |||
460 | struct wl1271_cmd_test_header test; | ||
461 | |||
462 | /* Static radio parameters */ | ||
463 | struct wl128x_ini_band_params_2 static_params_2; | ||
464 | struct wl128x_ini_band_params_5 static_params_5; | ||
465 | |||
466 | u8 fem_vendor_and_options; | ||
467 | |||
468 | /* Dynamic radio parameters */ | ||
469 | struct wl128x_ini_fem_params_2 dyn_params_2; | ||
470 | u8 padding2; | ||
471 | struct wl128x_ini_fem_params_5 dyn_params_5; | ||
472 | } __packed; | ||
473 | |||
474 | struct wl1271_ext_radio_parms_cmd { | ||
475 | struct wl1271_cmd_header header; | ||
476 | |||
477 | struct wl1271_cmd_test_header test; | ||
478 | |||
479 | u8 tx_per_channel_power_compensation_2[CONF_TX_PWR_COMPENSATION_LEN_2]; | ||
480 | u8 tx_per_channel_power_compensation_5[CONF_TX_PWR_COMPENSATION_LEN_5]; | ||
481 | u8 padding[3]; | ||
482 | } __packed; | ||
483 | |||
484 | /* | ||
485 | * There are three types of disconnections: | ||
486 | * | ||
487 | * DISCONNECT_IMMEDIATE: the fw doesn't send any frames | ||
488 | * DISCONNECT_DEAUTH: the fw generates a DEAUTH request with the reason | ||
489 | * we have passed | ||
490 | * DISCONNECT_DISASSOC: the fw generates a DESASSOC request with the reason | ||
491 | * we have passed | ||
492 | */ | ||
493 | enum wl1271_disconnect_type { | ||
494 | DISCONNECT_IMMEDIATE, | ||
495 | DISCONNECT_DEAUTH, | ||
496 | DISCONNECT_DISASSOC | ||
497 | }; | ||
498 | |||
499 | struct wl1271_cmd_disconnect { | ||
500 | struct wl1271_cmd_header header; | ||
501 | |||
502 | __le32 rx_config_options; | ||
503 | __le32 rx_filter_options; | ||
504 | |||
505 | __le16 reason; | ||
506 | u8 type; | ||
507 | |||
508 | u8 padding; | ||
509 | } __packed; | ||
510 | |||
511 | #define WL1271_CMD_STA_STATE_CONNECTED 1 | ||
512 | |||
513 | struct wl1271_cmd_set_sta_state { | ||
514 | struct wl1271_cmd_header header; | ||
515 | |||
516 | u8 state; | ||
517 | u8 padding[3]; | ||
518 | } __packed; | ||
519 | |||
520 | enum wl1271_ssid_type { | ||
521 | SSID_TYPE_PUBLIC = 0, | ||
522 | SSID_TYPE_HIDDEN = 1 | ||
523 | }; | ||
524 | |||
525 | struct wl1271_cmd_bss_start { | ||
526 | struct wl1271_cmd_header header; | ||
527 | |||
528 | /* wl1271_ssid_type */ | ||
529 | u8 ssid_type; | ||
530 | u8 ssid_len; | ||
531 | u8 ssid[IW_ESSID_MAX_SIZE]; | ||
532 | u8 padding_1[2]; | ||
533 | |||
534 | /* Basic rate set */ | ||
535 | __le32 basic_rate_set; | ||
536 | /* Aging period in seconds*/ | ||
537 | __le16 aging_period; | ||
538 | |||
539 | /* | ||
540 | * This field specifies the time between target beacon | ||
541 | * transmission times (TBTTs), in time units (TUs). | ||
542 | * Valid values are 1 to 1024. | ||
543 | */ | ||
544 | __le16 beacon_interval; | ||
545 | u8 bssid[ETH_ALEN]; | ||
546 | u8 bss_index; | ||
547 | /* Radio band */ | ||
548 | u8 band; | ||
549 | u8 channel; | ||
550 | /* The host link id for the AP's global queue */ | ||
551 | u8 global_hlid; | ||
552 | /* The host link id for the AP's broadcast queue */ | ||
553 | u8 broadcast_hlid; | ||
554 | /* DTIM count */ | ||
555 | u8 dtim_interval; | ||
556 | /* Beacon expiry time in ms */ | ||
557 | u8 beacon_expiry; | ||
558 | u8 padding_2[3]; | ||
559 | } __packed; | ||
560 | |||
561 | struct wl1271_cmd_add_sta { | ||
562 | struct wl1271_cmd_header header; | ||
563 | |||
564 | u8 addr[ETH_ALEN]; | ||
565 | u8 hlid; | ||
566 | u8 aid; | ||
567 | u8 psd_type[NUM_ACCESS_CATEGORIES_COPY]; | ||
568 | __le32 supported_rates; | ||
569 | u8 bss_index; | ||
570 | u8 sp_len; | ||
571 | u8 wmm; | ||
572 | u8 padding1; | ||
573 | } __packed; | ||
574 | |||
575 | struct wl1271_cmd_remove_sta { | ||
576 | struct wl1271_cmd_header header; | ||
577 | |||
578 | u8 hlid; | ||
579 | u8 reason_opcode; | ||
580 | u8 send_deauth_flag; | ||
581 | u8 padding1; | ||
582 | } __packed; | ||
583 | |||
584 | /* | ||
585 | * Continuous mode - packets are transferred to the host periodically | ||
586 | * via the data path. | ||
587 | * On demand - Log messages are stored in a cyclic buffer in the | ||
588 | * firmware, and only transferred to the host when explicitly requested | ||
589 | */ | ||
590 | enum wl12xx_fwlogger_log_mode { | ||
591 | WL12XX_FWLOG_CONTINUOUS, | ||
592 | WL12XX_FWLOG_ON_DEMAND | ||
593 | }; | ||
594 | |||
595 | /* Include/exclude timestamps from the log messages */ | ||
596 | enum wl12xx_fwlogger_timestamp { | ||
597 | WL12XX_FWLOG_TIMESTAMP_DISABLED, | ||
598 | WL12XX_FWLOG_TIMESTAMP_ENABLED | ||
599 | }; | ||
600 | |||
601 | /* | ||
602 | * Logs can be routed to the debug pinouts (where available), to the host bus | ||
603 | * (SDIO/SPI), or dropped | ||
604 | */ | ||
605 | enum wl12xx_fwlogger_output { | ||
606 | WL12XX_FWLOG_OUTPUT_NONE, | ||
607 | WL12XX_FWLOG_OUTPUT_DBG_PINS, | ||
608 | WL12XX_FWLOG_OUTPUT_HOST, | ||
609 | }; | ||
610 | |||
611 | struct wl12xx_cmd_config_fwlog { | ||
612 | struct wl1271_cmd_header header; | ||
613 | |||
614 | /* See enum wl12xx_fwlogger_log_mode */ | ||
615 | u8 logger_mode; | ||
616 | |||
617 | /* Minimum log level threshold */ | ||
618 | u8 log_severity; | ||
619 | |||
620 | /* Include/exclude timestamps from the log messages */ | ||
621 | u8 timestamp; | ||
622 | |||
623 | /* See enum wl1271_fwlogger_output */ | ||
624 | u8 output; | ||
625 | |||
626 | /* Regulates the frequency of log messages */ | ||
627 | u8 threshold; | ||
628 | |||
629 | u8 padding[3]; | ||
630 | } __packed; | ||
631 | |||
632 | struct wl12xx_cmd_start_fwlog { | ||
633 | struct wl1271_cmd_header header; | ||
634 | } __packed; | ||
635 | |||
636 | struct wl12xx_cmd_stop_fwlog { | ||
637 | struct wl1271_cmd_header header; | ||
638 | } __packed; | ||
639 | |||
640 | #endif /* __WL1271_CMD_H__ */ | ||
diff --git a/drivers/net/wireless/wl12xx/conf.h b/drivers/net/wireless/wl12xx/conf.h new file mode 100644 index 00000000000..6080e01d92c --- /dev/null +++ b/drivers/net/wireless/wl12xx/conf.h | |||
@@ -0,0 +1,1332 @@ | |||
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 | |||
27 | enum { | ||
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 | |||
51 | enum { | ||
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 | enum { | ||
69 | CONF_HW_RXTX_RATE_MCS7 = 0, | ||
70 | CONF_HW_RXTX_RATE_MCS6, | ||
71 | CONF_HW_RXTX_RATE_MCS5, | ||
72 | CONF_HW_RXTX_RATE_MCS4, | ||
73 | CONF_HW_RXTX_RATE_MCS3, | ||
74 | CONF_HW_RXTX_RATE_MCS2, | ||
75 | CONF_HW_RXTX_RATE_MCS1, | ||
76 | CONF_HW_RXTX_RATE_MCS0, | ||
77 | CONF_HW_RXTX_RATE_54, | ||
78 | CONF_HW_RXTX_RATE_48, | ||
79 | CONF_HW_RXTX_RATE_36, | ||
80 | CONF_HW_RXTX_RATE_24, | ||
81 | CONF_HW_RXTX_RATE_22, | ||
82 | CONF_HW_RXTX_RATE_18, | ||
83 | CONF_HW_RXTX_RATE_12, | ||
84 | CONF_HW_RXTX_RATE_11, | ||
85 | CONF_HW_RXTX_RATE_9, | ||
86 | CONF_HW_RXTX_RATE_6, | ||
87 | CONF_HW_RXTX_RATE_5_5, | ||
88 | CONF_HW_RXTX_RATE_2, | ||
89 | CONF_HW_RXTX_RATE_1, | ||
90 | CONF_HW_RXTX_RATE_MAX, | ||
91 | CONF_HW_RXTX_RATE_UNSUPPORTED = 0xff | ||
92 | }; | ||
93 | |||
94 | enum { | ||
95 | CONF_SG_DISABLE = 0, | ||
96 | CONF_SG_PROTECTIVE, | ||
97 | CONF_SG_OPPORTUNISTIC | ||
98 | }; | ||
99 | |||
100 | enum { | ||
101 | /* | ||
102 | * PER threshold in PPM of the BT voice | ||
103 | * | ||
104 | * Range: 0 - 10000000 | ||
105 | */ | ||
106 | CONF_SG_BT_PER_THRESHOLD = 0, | ||
107 | |||
108 | /* | ||
109 | * Number of consequent RX_ACTIVE activities to override BT voice | ||
110 | * frames to ensure WLAN connection | ||
111 | * | ||
112 | * Range: 0 - 100 | ||
113 | */ | ||
114 | CONF_SG_HV3_MAX_OVERRIDE, | ||
115 | |||
116 | /* | ||
117 | * Defines the PER threshold of the BT voice | ||
118 | * | ||
119 | * Range: 0 - 65000 | ||
120 | */ | ||
121 | CONF_SG_BT_NFS_SAMPLE_INTERVAL, | ||
122 | |||
123 | /* | ||
124 | * Defines the load ratio of BT | ||
125 | * | ||
126 | * Range: 0 - 100 (%) | ||
127 | */ | ||
128 | CONF_SG_BT_LOAD_RATIO, | ||
129 | |||
130 | /* | ||
131 | * Defines whether the SG will force WLAN host to enter/exit PSM | ||
132 | * | ||
133 | * Range: 1 - SG can force, 0 - host handles PSM | ||
134 | */ | ||
135 | CONF_SG_AUTO_PS_MODE, | ||
136 | |||
137 | /* | ||
138 | * Compensation percentage of probe requests when scan initiated | ||
139 | * during BT voice/ACL link. | ||
140 | * | ||
141 | * Range: 0 - 255 (%) | ||
142 | */ | ||
143 | CONF_SG_AUTO_SCAN_PROBE_REQ, | ||
144 | |||
145 | /* | ||
146 | * Compensation percentage of probe requests when active scan initiated | ||
147 | * during BT voice | ||
148 | * | ||
149 | * Range: 0 - 255 (%) | ||
150 | */ | ||
151 | CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_HV3, | ||
152 | |||
153 | /* | ||
154 | * Defines antenna configuration (single/dual antenna) | ||
155 | * | ||
156 | * Range: 0 - single antenna, 1 - dual antenna | ||
157 | */ | ||
158 | CONF_SG_ANTENNA_CONFIGURATION, | ||
159 | |||
160 | /* | ||
161 | * The threshold (percent) of max consequtive beacon misses before | ||
162 | * increasing priority of beacon reception. | ||
163 | * | ||
164 | * Range: 0 - 100 (%) | ||
165 | */ | ||
166 | CONF_SG_BEACON_MISS_PERCENT, | ||
167 | |||
168 | /* | ||
169 | * The rate threshold below which receiving a data frame from the AP | ||
170 | * will increase the priority of the data frame above BT traffic. | ||
171 | * | ||
172 | * Range: 0,2, 5(=5.5), 6, 9, 11, 12, 18, 24, 36, 48, 54 | ||
173 | */ | ||
174 | CONF_SG_RATE_ADAPT_THRESH, | ||
175 | |||
176 | /* | ||
177 | * Not used currently. | ||
178 | * | ||
179 | * Range: 0 | ||
180 | */ | ||
181 | CONF_SG_RATE_ADAPT_SNR, | ||
182 | |||
183 | /* | ||
184 | * Configure the min and max time BT gains the antenna | ||
185 | * in WLAN PSM / BT master basic rate | ||
186 | * | ||
187 | * Range: 0 - 255 (ms) | ||
188 | */ | ||
189 | CONF_SG_WLAN_PS_BT_ACL_MASTER_MIN_BR, | ||
190 | CONF_SG_WLAN_PS_BT_ACL_MASTER_MAX_BR, | ||
191 | |||
192 | /* | ||
193 | * The time after it expires no new WLAN trigger frame is trasmitted | ||
194 | * in WLAN PSM / BT master basic rate | ||
195 | * | ||
196 | * Range: 0 - 255 (ms) | ||
197 | */ | ||
198 | CONF_SG_WLAN_PS_MAX_BT_ACL_MASTER_BR, | ||
199 | |||
200 | /* | ||
201 | * Configure the min and max time BT gains the antenna | ||
202 | * in WLAN PSM / BT slave basic rate | ||
203 | * | ||
204 | * Range: 0 - 255 (ms) | ||
205 | */ | ||
206 | CONF_SG_WLAN_PS_BT_ACL_SLAVE_MIN_BR, | ||
207 | CONF_SG_WLAN_PS_BT_ACL_SLAVE_MAX_BR, | ||
208 | |||
209 | /* | ||
210 | * The time after it expires no new WLAN trigger frame is trasmitted | ||
211 | * in WLAN PSM / BT slave basic rate | ||
212 | * | ||
213 | * Range: 0 - 255 (ms) | ||
214 | */ | ||
215 | CONF_SG_WLAN_PS_MAX_BT_ACL_SLAVE_BR, | ||
216 | |||
217 | /* | ||
218 | * Configure the min and max time BT gains the antenna | ||
219 | * in WLAN PSM / BT master EDR | ||
220 | * | ||
221 | * Range: 0 - 255 (ms) | ||
222 | */ | ||
223 | CONF_SG_WLAN_PS_BT_ACL_MASTER_MIN_EDR, | ||
224 | CONF_SG_WLAN_PS_BT_ACL_MASTER_MAX_EDR, | ||
225 | |||
226 | /* | ||
227 | * The time after it expires no new WLAN trigger frame is trasmitted | ||
228 | * in WLAN PSM / BT master EDR | ||
229 | * | ||
230 | * Range: 0 - 255 (ms) | ||
231 | */ | ||
232 | CONF_SG_WLAN_PS_MAX_BT_ACL_MASTER_EDR, | ||
233 | |||
234 | /* | ||
235 | * Configure the min and max time BT gains the antenna | ||
236 | * in WLAN PSM / BT slave EDR | ||
237 | * | ||
238 | * Range: 0 - 255 (ms) | ||
239 | */ | ||
240 | CONF_SG_WLAN_PS_BT_ACL_SLAVE_MIN_EDR, | ||
241 | CONF_SG_WLAN_PS_BT_ACL_SLAVE_MAX_EDR, | ||
242 | |||
243 | /* | ||
244 | * The time after it expires no new WLAN trigger frame is trasmitted | ||
245 | * in WLAN PSM / BT slave EDR | ||
246 | * | ||
247 | * Range: 0 - 255 (ms) | ||
248 | */ | ||
249 | CONF_SG_WLAN_PS_MAX_BT_ACL_SLAVE_EDR, | ||
250 | |||
251 | /* | ||
252 | * RX guard time before the beginning of a new BT voice frame during | ||
253 | * which no new WLAN trigger frame is transmitted. | ||
254 | * | ||
255 | * Range: 0 - 100000 (us) | ||
256 | */ | ||
257 | CONF_SG_RXT, | ||
258 | |||
259 | /* | ||
260 | * TX guard time before the beginning of a new BT voice frame during | ||
261 | * which no new WLAN frame is transmitted. | ||
262 | * | ||
263 | * Range: 0 - 100000 (us) | ||
264 | */ | ||
265 | |||
266 | CONF_SG_TXT, | ||
267 | |||
268 | /* | ||
269 | * Enable adaptive RXT/TXT algorithm. If disabled, the host values | ||
270 | * will be utilized. | ||
271 | * | ||
272 | * Range: 0 - disable, 1 - enable | ||
273 | */ | ||
274 | CONF_SG_ADAPTIVE_RXT_TXT, | ||
275 | |||
276 | /* | ||
277 | * The used WLAN legacy service period during active BT ACL link | ||
278 | * | ||
279 | * Range: 0 - 255 (ms) | ||
280 | */ | ||
281 | CONF_SG_PS_POLL_TIMEOUT, | ||
282 | |||
283 | /* | ||
284 | * The used WLAN UPSD service period during active BT ACL link | ||
285 | * | ||
286 | * Range: 0 - 255 (ms) | ||
287 | */ | ||
288 | CONF_SG_UPSD_TIMEOUT, | ||
289 | |||
290 | /* | ||
291 | * Configure the min and max time BT gains the antenna | ||
292 | * in WLAN Active / BT master EDR | ||
293 | * | ||
294 | * Range: 0 - 255 (ms) | ||
295 | */ | ||
296 | CONF_SG_WLAN_ACTIVE_BT_ACL_MASTER_MIN_EDR, | ||
297 | CONF_SG_WLAN_ACTIVE_BT_ACL_MASTER_MAX_EDR, | ||
298 | |||
299 | /* | ||
300 | * The maximum time WLAN can gain the antenna for | ||
301 | * in WLAN Active / BT master EDR | ||
302 | * | ||
303 | * Range: 0 - 255 (ms) | ||
304 | */ | ||
305 | CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_MASTER_EDR, | ||
306 | |||
307 | /* | ||
308 | * Configure the min and max time BT gains the antenna | ||
309 | * in WLAN Active / BT slave EDR | ||
310 | * | ||
311 | * Range: 0 - 255 (ms) | ||
312 | */ | ||
313 | CONF_SG_WLAN_ACTIVE_BT_ACL_SLAVE_MIN_EDR, | ||
314 | CONF_SG_WLAN_ACTIVE_BT_ACL_SLAVE_MAX_EDR, | ||
315 | |||
316 | /* | ||
317 | * The maximum time WLAN can gain the antenna for | ||
318 | * in WLAN Active / BT slave EDR | ||
319 | * | ||
320 | * Range: 0 - 255 (ms) | ||
321 | */ | ||
322 | CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_SLAVE_EDR, | ||
323 | |||
324 | /* | ||
325 | * Configure the min and max time BT gains the antenna | ||
326 | * in WLAN Active / BT basic rate | ||
327 | * | ||
328 | * Range: 0 - 255 (ms) | ||
329 | */ | ||
330 | CONF_SG_WLAN_ACTIVE_BT_ACL_MIN_BR, | ||
331 | CONF_SG_WLAN_ACTIVE_BT_ACL_MAX_BR, | ||
332 | |||
333 | /* | ||
334 | * The maximum time WLAN can gain the antenna for | ||
335 | * in WLAN Active / BT basic rate | ||
336 | * | ||
337 | * Range: 0 - 255 (ms) | ||
338 | */ | ||
339 | CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_BR, | ||
340 | |||
341 | /* | ||
342 | * Compensation percentage of WLAN passive scan window if initiated | ||
343 | * during BT voice | ||
344 | * | ||
345 | * Range: 0 - 1000 (%) | ||
346 | */ | ||
347 | CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_HV3, | ||
348 | |||
349 | /* | ||
350 | * Compensation percentage of WLAN passive scan window if initiated | ||
351 | * during BT A2DP | ||
352 | * | ||
353 | * Range: 0 - 1000 (%) | ||
354 | */ | ||
355 | CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP, | ||
356 | |||
357 | /* | ||
358 | * Fixed time ensured for BT traffic to gain the antenna during WLAN | ||
359 | * passive scan. | ||
360 | * | ||
361 | * Range: 0 - 1000 ms | ||
362 | */ | ||
363 | CONF_SG_PASSIVE_SCAN_A2DP_BT_TIME, | ||
364 | |||
365 | /* | ||
366 | * Fixed time ensured for WLAN traffic to gain the antenna during WLAN | ||
367 | * passive scan. | ||
368 | * | ||
369 | * Range: 0 - 1000 ms | ||
370 | */ | ||
371 | CONF_SG_PASSIVE_SCAN_A2DP_WLAN_TIME, | ||
372 | |||
373 | /* | ||
374 | * Number of consequent BT voice frames not interrupted by WLAN | ||
375 | * | ||
376 | * Range: 0 - 100 | ||
377 | */ | ||
378 | CONF_SG_HV3_MAX_SERVED, | ||
379 | |||
380 | /* | ||
381 | * Protection time of the DHCP procedure. | ||
382 | * | ||
383 | * Range: 0 - 100000 (ms) | ||
384 | */ | ||
385 | CONF_SG_DHCP_TIME, | ||
386 | |||
387 | /* | ||
388 | * Compensation percentage of WLAN active scan window if initiated | ||
389 | * during BT A2DP | ||
390 | * | ||
391 | * Range: 0 - 1000 (%) | ||
392 | */ | ||
393 | CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_A2DP, | ||
394 | CONF_SG_TEMP_PARAM_1, | ||
395 | CONF_SG_TEMP_PARAM_2, | ||
396 | CONF_SG_TEMP_PARAM_3, | ||
397 | CONF_SG_TEMP_PARAM_4, | ||
398 | CONF_SG_TEMP_PARAM_5, | ||
399 | |||
400 | /* | ||
401 | * AP beacon miss | ||
402 | * | ||
403 | * Range: 0 - 255 | ||
404 | */ | ||
405 | CONF_SG_AP_BEACON_MISS_TX, | ||
406 | |||
407 | /* | ||
408 | * AP RX window length | ||
409 | * | ||
410 | * Range: 0 - 50 | ||
411 | */ | ||
412 | CONF_SG_RX_WINDOW_LENGTH, | ||
413 | |||
414 | /* | ||
415 | * AP connection protection time | ||
416 | * | ||
417 | * Range: 0 - 5000 | ||
418 | */ | ||
419 | CONF_SG_AP_CONNECTION_PROTECTION_TIME, | ||
420 | |||
421 | CONF_SG_TEMP_PARAM_6, | ||
422 | CONF_SG_TEMP_PARAM_7, | ||
423 | CONF_SG_TEMP_PARAM_8, | ||
424 | CONF_SG_TEMP_PARAM_9, | ||
425 | CONF_SG_TEMP_PARAM_10, | ||
426 | |||
427 | CONF_SG_STA_PARAMS_MAX = CONF_SG_TEMP_PARAM_5 + 1, | ||
428 | CONF_SG_AP_PARAMS_MAX = CONF_SG_TEMP_PARAM_10 + 1, | ||
429 | |||
430 | CONF_SG_PARAMS_ALL = 0xff | ||
431 | }; | ||
432 | |||
433 | struct conf_sg_settings { | ||
434 | u32 sta_params[CONF_SG_STA_PARAMS_MAX]; | ||
435 | u32 ap_params[CONF_SG_AP_PARAMS_MAX]; | ||
436 | u8 state; | ||
437 | }; | ||
438 | |||
439 | enum conf_rx_queue_type { | ||
440 | CONF_RX_QUEUE_TYPE_LOW_PRIORITY, /* All except the high priority */ | ||
441 | CONF_RX_QUEUE_TYPE_HIGH_PRIORITY, /* Management and voice packets */ | ||
442 | }; | ||
443 | |||
444 | struct conf_rx_settings { | ||
445 | /* | ||
446 | * The maximum amount of time, in TU, before the | ||
447 | * firmware discards the MSDU. | ||
448 | * | ||
449 | * Range: 0 - 0xFFFFFFFF | ||
450 | */ | ||
451 | u32 rx_msdu_life_time; | ||
452 | |||
453 | /* | ||
454 | * Packet detection threshold in the PHY. | ||
455 | * | ||
456 | * FIXME: details unknown. | ||
457 | */ | ||
458 | u32 packet_detection_threshold; | ||
459 | |||
460 | /* | ||
461 | * The longest time the STA will wait to receive traffic from the AP | ||
462 | * after a PS-poll has been transmitted. | ||
463 | * | ||
464 | * Range: 0 - 200000 | ||
465 | */ | ||
466 | u16 ps_poll_timeout; | ||
467 | /* | ||
468 | * The longest time the STA will wait to receive traffic from the AP | ||
469 | * after a frame has been sent from an UPSD enabled queue. | ||
470 | * | ||
471 | * Range: 0 - 200000 | ||
472 | */ | ||
473 | u16 upsd_timeout; | ||
474 | |||
475 | /* | ||
476 | * The number of octets in an MPDU, below which an RTS/CTS | ||
477 | * handshake is not performed. | ||
478 | * | ||
479 | * Range: 0 - 4096 | ||
480 | */ | ||
481 | u16 rts_threshold; | ||
482 | |||
483 | /* | ||
484 | * The RX Clear Channel Assessment threshold in the PHY | ||
485 | * (the energy threshold). | ||
486 | * | ||
487 | * Range: ENABLE_ENERGY_D == 0x140A | ||
488 | * DISABLE_ENERGY_D == 0xFFEF | ||
489 | */ | ||
490 | u16 rx_cca_threshold; | ||
491 | |||
492 | /* | ||
493 | * Occupied Rx mem-blocks number which requires interrupting the host | ||
494 | * (0 = no buffering, 0xffff = disabled). | ||
495 | * | ||
496 | * Range: u16 | ||
497 | */ | ||
498 | u16 irq_blk_threshold; | ||
499 | |||
500 | /* | ||
501 | * Rx packets number which requires interrupting the host | ||
502 | * (0 = no buffering). | ||
503 | * | ||
504 | * Range: u16 | ||
505 | */ | ||
506 | u16 irq_pkt_threshold; | ||
507 | |||
508 | /* | ||
509 | * Max time in msec the FW may delay RX-Complete interrupt. | ||
510 | * | ||
511 | * Range: 1 - 100 | ||
512 | */ | ||
513 | u16 irq_timeout; | ||
514 | |||
515 | /* | ||
516 | * The RX queue type. | ||
517 | * | ||
518 | * Range: RX_QUEUE_TYPE_RX_LOW_PRIORITY, RX_QUEUE_TYPE_RX_HIGH_PRIORITY, | ||
519 | */ | ||
520 | u8 queue_type; | ||
521 | }; | ||
522 | |||
523 | #define CONF_TX_MAX_RATE_CLASSES 8 | ||
524 | |||
525 | #define CONF_TX_RATE_MASK_UNSPECIFIED 0 | ||
526 | #define CONF_TX_RATE_MASK_BASIC (CONF_HW_BIT_RATE_1MBPS | \ | ||
527 | CONF_HW_BIT_RATE_2MBPS) | ||
528 | #define CONF_TX_RATE_RETRY_LIMIT 10 | ||
529 | |||
530 | /* | ||
531 | * Rates supported for data packets when operating as AP. Note the absence | ||
532 | * of the 22Mbps rate. There is a FW limitation on 12 rates so we must drop | ||
533 | * one. The rate dropped is not mandatory under any operating mode. | ||
534 | */ | ||
535 | #define CONF_TX_AP_ENABLED_RATES (CONF_HW_BIT_RATE_1MBPS | \ | ||
536 | CONF_HW_BIT_RATE_2MBPS | CONF_HW_BIT_RATE_5_5MBPS | \ | ||
537 | CONF_HW_BIT_RATE_6MBPS | CONF_HW_BIT_RATE_9MBPS | \ | ||
538 | CONF_HW_BIT_RATE_11MBPS | CONF_HW_BIT_RATE_12MBPS | \ | ||
539 | CONF_HW_BIT_RATE_18MBPS | CONF_HW_BIT_RATE_24MBPS | \ | ||
540 | CONF_HW_BIT_RATE_36MBPS | CONF_HW_BIT_RATE_48MBPS | \ | ||
541 | CONF_HW_BIT_RATE_54MBPS) | ||
542 | |||
543 | #define CONF_TX_OFDM_RATES (CONF_HW_BIT_RATE_6MBPS | \ | ||
544 | CONF_HW_BIT_RATE_12MBPS | CONF_HW_BIT_RATE_24MBPS | \ | ||
545 | CONF_HW_BIT_RATE_36MBPS | CONF_HW_BIT_RATE_48MBPS | \ | ||
546 | CONF_HW_BIT_RATE_54MBPS) | ||
547 | |||
548 | |||
549 | /* | ||
550 | * Default rates for management traffic when operating in AP mode. This | ||
551 | * should be configured according to the basic rate set of the AP | ||
552 | */ | ||
553 | #define CONF_TX_AP_DEFAULT_MGMT_RATES (CONF_HW_BIT_RATE_1MBPS | \ | ||
554 | CONF_HW_BIT_RATE_2MBPS | CONF_HW_BIT_RATE_5_5MBPS) | ||
555 | |||
556 | /* | ||
557 | * Default rates for working as IBSS. use 11b rates | ||
558 | */ | ||
559 | #define CONF_TX_IBSS_DEFAULT_RATES (CONF_HW_BIT_RATE_1MBPS | \ | ||
560 | CONF_HW_BIT_RATE_2MBPS | CONF_HW_BIT_RATE_5_5MBPS | \ | ||
561 | CONF_HW_BIT_RATE_11MBPS); | ||
562 | |||
563 | struct conf_tx_rate_class { | ||
564 | |||
565 | /* | ||
566 | * The rates enabled for this rate class. | ||
567 | * | ||
568 | * Range: CONF_HW_BIT_RATE_* bit mask | ||
569 | */ | ||
570 | u32 enabled_rates; | ||
571 | |||
572 | /* | ||
573 | * The dot11 short retry limit used for TX retries. | ||
574 | * | ||
575 | * Range: u8 | ||
576 | */ | ||
577 | u8 short_retry_limit; | ||
578 | |||
579 | /* | ||
580 | * The dot11 long retry limit used for TX retries. | ||
581 | * | ||
582 | * Range: u8 | ||
583 | */ | ||
584 | u8 long_retry_limit; | ||
585 | |||
586 | /* | ||
587 | * Flags controlling the attributes of TX transmission. | ||
588 | * | ||
589 | * Range: bit 0: Truncate - when set, FW attempts to send a frame stop | ||
590 | * when the total valid per-rate attempts have | ||
591 | * been exhausted; otherwise transmissions | ||
592 | * will continue at the lowest available rate | ||
593 | * until the appropriate one of the | ||
594 | * short_retry_limit, long_retry_limit, | ||
595 | * dot11_max_transmit_msdu_life_time, or | ||
596 | * max_tx_life_time, is exhausted. | ||
597 | * 1: Preamble Override - indicates if the preamble type | ||
598 | * should be used in TX. | ||
599 | * 2: Preamble Type - the type of the preamble to be used by | ||
600 | * the policy (0 - long preamble, 1 - short preamble. | ||
601 | */ | ||
602 | u8 aflags; | ||
603 | }; | ||
604 | |||
605 | #define CONF_TX_MAX_AC_COUNT 4 | ||
606 | |||
607 | /* Slot number setting to start transmission at PIFS interval */ | ||
608 | #define CONF_TX_AIFS_PIFS 1 | ||
609 | /* Slot number setting to start transmission at DIFS interval normal | ||
610 | * DCF access */ | ||
611 | #define CONF_TX_AIFS_DIFS 2 | ||
612 | |||
613 | |||
614 | enum conf_tx_ac { | ||
615 | CONF_TX_AC_BE = 0, /* best effort / legacy */ | ||
616 | CONF_TX_AC_BK = 1, /* background */ | ||
617 | CONF_TX_AC_VI = 2, /* video */ | ||
618 | CONF_TX_AC_VO = 3, /* voice */ | ||
619 | CONF_TX_AC_CTS2SELF = 4, /* fictitious AC, follows AC_VO */ | ||
620 | CONF_TX_AC_ANY_TID = 0x1f | ||
621 | }; | ||
622 | |||
623 | struct conf_tx_ac_category { | ||
624 | /* | ||
625 | * The AC class identifier. | ||
626 | * | ||
627 | * Range: enum conf_tx_ac | ||
628 | */ | ||
629 | u8 ac; | ||
630 | |||
631 | /* | ||
632 | * The contention window minimum size (in slots) for the access | ||
633 | * class. | ||
634 | * | ||
635 | * Range: u8 | ||
636 | */ | ||
637 | u8 cw_min; | ||
638 | |||
639 | /* | ||
640 | * The contention window maximum size (in slots) for the access | ||
641 | * class. | ||
642 | * | ||
643 | * Range: u8 | ||
644 | */ | ||
645 | u16 cw_max; | ||
646 | |||
647 | /* | ||
648 | * The AIF value (in slots) for the access class. | ||
649 | * | ||
650 | * Range: u8 | ||
651 | */ | ||
652 | u8 aifsn; | ||
653 | |||
654 | /* | ||
655 | * The TX Op Limit (in microseconds) for the access class. | ||
656 | * | ||
657 | * Range: u16 | ||
658 | */ | ||
659 | u16 tx_op_limit; | ||
660 | }; | ||
661 | |||
662 | #define CONF_TX_MAX_TID_COUNT 8 | ||
663 | |||
664 | enum { | ||
665 | CONF_CHANNEL_TYPE_DCF = 0, /* DC/LEGACY*/ | ||
666 | CONF_CHANNEL_TYPE_EDCF = 1, /* EDCA*/ | ||
667 | CONF_CHANNEL_TYPE_HCCA = 2, /* HCCA*/ | ||
668 | }; | ||
669 | |||
670 | enum { | ||
671 | CONF_PS_SCHEME_LEGACY = 0, | ||
672 | CONF_PS_SCHEME_UPSD_TRIGGER = 1, | ||
673 | CONF_PS_SCHEME_LEGACY_PSPOLL = 2, | ||
674 | CONF_PS_SCHEME_SAPSD = 3, | ||
675 | }; | ||
676 | |||
677 | enum { | ||
678 | CONF_ACK_POLICY_LEGACY = 0, | ||
679 | CONF_ACK_POLICY_NO_ACK = 1, | ||
680 | CONF_ACK_POLICY_BLOCK = 2, | ||
681 | }; | ||
682 | |||
683 | |||
684 | struct conf_tx_tid { | ||
685 | u8 queue_id; | ||
686 | u8 channel_type; | ||
687 | u8 tsid; | ||
688 | u8 ps_scheme; | ||
689 | u8 ack_policy; | ||
690 | u32 apsd_conf[2]; | ||
691 | }; | ||
692 | |||
693 | struct conf_tx_settings { | ||
694 | /* | ||
695 | * The TX ED value for TELEC Enable/Disable. | ||
696 | * | ||
697 | * Range: 0, 1 | ||
698 | */ | ||
699 | u8 tx_energy_detection; | ||
700 | |||
701 | /* | ||
702 | * Configuration for rate classes for TX (currently only one | ||
703 | * rate class supported). Used in non-AP mode. | ||
704 | */ | ||
705 | struct conf_tx_rate_class sta_rc_conf; | ||
706 | |||
707 | /* | ||
708 | * Configuration for access categories for TX rate control. | ||
709 | */ | ||
710 | u8 ac_conf_count; | ||
711 | struct conf_tx_ac_category ac_conf[CONF_TX_MAX_AC_COUNT]; | ||
712 | |||
713 | /* | ||
714 | * AP-mode - allow this number of TX retries to a station before an | ||
715 | * event is triggered from FW. | ||
716 | * In AP-mode the hlids of unreachable stations are given in the | ||
717 | * "sta_tx_retry_exceeded" member in the event mailbox. | ||
718 | */ | ||
719 | u8 max_tx_retries; | ||
720 | |||
721 | /* | ||
722 | * AP-mode - after this number of seconds a connected station is | ||
723 | * considered inactive. | ||
724 | */ | ||
725 | u16 ap_aging_period; | ||
726 | |||
727 | /* | ||
728 | * Configuration for TID parameters. | ||
729 | */ | ||
730 | u8 tid_conf_count; | ||
731 | struct conf_tx_tid tid_conf[CONF_TX_MAX_TID_COUNT]; | ||
732 | |||
733 | /* | ||
734 | * The TX fragmentation threshold. | ||
735 | * | ||
736 | * Range: u16 | ||
737 | */ | ||
738 | u16 frag_threshold; | ||
739 | |||
740 | /* | ||
741 | * Max time in msec the FW may delay frame TX-Complete interrupt. | ||
742 | * | ||
743 | * Range: u16 | ||
744 | */ | ||
745 | u16 tx_compl_timeout; | ||
746 | |||
747 | /* | ||
748 | * Completed TX packet count which requires to issue the TX-Complete | ||
749 | * interrupt. | ||
750 | * | ||
751 | * Range: u16 | ||
752 | */ | ||
753 | u16 tx_compl_threshold; | ||
754 | |||
755 | /* | ||
756 | * The rate used for control messages and scanning on the 2.4GHz band | ||
757 | * | ||
758 | * Range: CONF_HW_BIT_RATE_* bit mask | ||
759 | */ | ||
760 | u32 basic_rate; | ||
761 | |||
762 | /* | ||
763 | * The rate used for control messages and scanning on the 5GHz band | ||
764 | * | ||
765 | * Range: CONF_HW_BIT_RATE_* bit mask | ||
766 | */ | ||
767 | u32 basic_rate_5; | ||
768 | |||
769 | /* | ||
770 | * TX retry limits for templates | ||
771 | */ | ||
772 | u8 tmpl_short_retry_limit; | ||
773 | u8 tmpl_long_retry_limit; | ||
774 | }; | ||
775 | |||
776 | enum { | ||
777 | CONF_WAKE_UP_EVENT_BEACON = 0x01, /* Wake on every Beacon*/ | ||
778 | CONF_WAKE_UP_EVENT_DTIM = 0x02, /* Wake on every DTIM*/ | ||
779 | CONF_WAKE_UP_EVENT_N_DTIM = 0x04, /* Wake every Nth DTIM */ | ||
780 | CONF_WAKE_UP_EVENT_N_BEACONS = 0x08, /* Wake every Nth beacon */ | ||
781 | CONF_WAKE_UP_EVENT_BITS_MASK = 0x0F | ||
782 | }; | ||
783 | |||
784 | #define CONF_MAX_BCN_FILT_IE_COUNT 32 | ||
785 | |||
786 | #define CONF_BCN_RULE_PASS_ON_CHANGE BIT(0) | ||
787 | #define CONF_BCN_RULE_PASS_ON_APPEARANCE BIT(1) | ||
788 | |||
789 | #define CONF_BCN_IE_OUI_LEN 3 | ||
790 | #define CONF_BCN_IE_VER_LEN 2 | ||
791 | |||
792 | struct conf_bcn_filt_rule { | ||
793 | /* | ||
794 | * IE number to which to associate a rule. | ||
795 | * | ||
796 | * Range: u8 | ||
797 | */ | ||
798 | u8 ie; | ||
799 | |||
800 | /* | ||
801 | * Rule to associate with the specific ie. | ||
802 | * | ||
803 | * Range: CONF_BCN_RULE_PASS_ON_* | ||
804 | */ | ||
805 | u8 rule; | ||
806 | |||
807 | /* | ||
808 | * OUI for the vendor specifie IE (221) | ||
809 | */ | ||
810 | u8 oui[CONF_BCN_IE_OUI_LEN]; | ||
811 | |||
812 | /* | ||
813 | * Type for the vendor specifie IE (221) | ||
814 | */ | ||
815 | u8 type; | ||
816 | |||
817 | /* | ||
818 | * Version for the vendor specifie IE (221) | ||
819 | */ | ||
820 | u8 version[CONF_BCN_IE_VER_LEN]; | ||
821 | }; | ||
822 | |||
823 | #define CONF_MAX_RSSI_SNR_TRIGGERS 8 | ||
824 | |||
825 | enum { | ||
826 | CONF_TRIG_METRIC_RSSI_BEACON = 0, | ||
827 | CONF_TRIG_METRIC_RSSI_DATA, | ||
828 | CONF_TRIG_METRIC_SNR_BEACON, | ||
829 | CONF_TRIG_METRIC_SNR_DATA | ||
830 | }; | ||
831 | |||
832 | enum { | ||
833 | CONF_TRIG_EVENT_TYPE_LEVEL = 0, | ||
834 | CONF_TRIG_EVENT_TYPE_EDGE | ||
835 | }; | ||
836 | |||
837 | enum { | ||
838 | CONF_TRIG_EVENT_DIR_LOW = 0, | ||
839 | CONF_TRIG_EVENT_DIR_HIGH, | ||
840 | CONF_TRIG_EVENT_DIR_BIDIR | ||
841 | }; | ||
842 | |||
843 | struct conf_sig_weights { | ||
844 | |||
845 | /* | ||
846 | * RSSI from beacons average weight. | ||
847 | * | ||
848 | * Range: u8 | ||
849 | */ | ||
850 | u8 rssi_bcn_avg_weight; | ||
851 | |||
852 | /* | ||
853 | * RSSI from data average weight. | ||
854 | * | ||
855 | * Range: u8 | ||
856 | */ | ||
857 | u8 rssi_pkt_avg_weight; | ||
858 | |||
859 | /* | ||
860 | * SNR from beacons average weight. | ||
861 | * | ||
862 | * Range: u8 | ||
863 | */ | ||
864 | u8 snr_bcn_avg_weight; | ||
865 | |||
866 | /* | ||
867 | * SNR from data average weight. | ||
868 | * | ||
869 | * Range: u8 | ||
870 | */ | ||
871 | u8 snr_pkt_avg_weight; | ||
872 | }; | ||
873 | |||
874 | enum conf_bcn_filt_mode { | ||
875 | CONF_BCN_FILT_MODE_DISABLED = 0, | ||
876 | CONF_BCN_FILT_MODE_ENABLED = 1 | ||
877 | }; | ||
878 | |||
879 | enum conf_bet_mode { | ||
880 | CONF_BET_MODE_DISABLE = 0, | ||
881 | CONF_BET_MODE_ENABLE = 1, | ||
882 | }; | ||
883 | |||
884 | struct conf_conn_settings { | ||
885 | /* | ||
886 | * Firmware wakeup conditions configuration. The host may set only | ||
887 | * one bit. | ||
888 | * | ||
889 | * Range: CONF_WAKE_UP_EVENT_* | ||
890 | */ | ||
891 | u8 wake_up_event; | ||
892 | |||
893 | /* | ||
894 | * Listen interval for beacons or Dtims. | ||
895 | * | ||
896 | * Range: 0 for beacon and Dtim wakeup | ||
897 | * 1-10 for x Dtims | ||
898 | * 1-255 for x beacons | ||
899 | */ | ||
900 | u8 listen_interval; | ||
901 | |||
902 | /* | ||
903 | * Enable or disable the beacon filtering. | ||
904 | * | ||
905 | * Range: CONF_BCN_FILT_MODE_* | ||
906 | */ | ||
907 | enum conf_bcn_filt_mode bcn_filt_mode; | ||
908 | |||
909 | /* | ||
910 | * Configure Beacon filter pass-thru rules. | ||
911 | */ | ||
912 | u8 bcn_filt_ie_count; | ||
913 | struct conf_bcn_filt_rule bcn_filt_ie[CONF_MAX_BCN_FILT_IE_COUNT]; | ||
914 | |||
915 | /* | ||
916 | * The number of consequtive beacons to lose, before the firmware | ||
917 | * becomes out of synch. | ||
918 | * | ||
919 | * Range: u32 | ||
920 | */ | ||
921 | u32 synch_fail_thold; | ||
922 | |||
923 | /* | ||
924 | * After out-of-synch, the number of TU's to wait without a further | ||
925 | * received beacon (or probe response) before issuing the BSS_EVENT_LOSE | ||
926 | * event. | ||
927 | * | ||
928 | * Range: u32 | ||
929 | */ | ||
930 | u32 bss_lose_timeout; | ||
931 | |||
932 | /* | ||
933 | * Beacon receive timeout. | ||
934 | * | ||
935 | * Range: u32 | ||
936 | */ | ||
937 | u32 beacon_rx_timeout; | ||
938 | |||
939 | /* | ||
940 | * Broadcast receive timeout. | ||
941 | * | ||
942 | * Range: u32 | ||
943 | */ | ||
944 | u32 broadcast_timeout; | ||
945 | |||
946 | /* | ||
947 | * Enable/disable reception of broadcast packets in power save mode | ||
948 | * | ||
949 | * Range: 1 - enable, 0 - disable | ||
950 | */ | ||
951 | u8 rx_broadcast_in_ps; | ||
952 | |||
953 | /* | ||
954 | * Consequtive PS Poll failures before sending event to driver | ||
955 | * | ||
956 | * Range: u8 | ||
957 | */ | ||
958 | u8 ps_poll_threshold; | ||
959 | |||
960 | /* | ||
961 | * PS Poll failure recovery ACTIVE period length | ||
962 | * | ||
963 | * Range: u32 (ms) | ||
964 | */ | ||
965 | u32 ps_poll_recovery_period; | ||
966 | |||
967 | /* | ||
968 | * Configuration of signal average weights. | ||
969 | */ | ||
970 | struct conf_sig_weights sig_weights; | ||
971 | |||
972 | /* | ||
973 | * Specifies if beacon early termination procedure is enabled or | ||
974 | * disabled. | ||
975 | * | ||
976 | * Range: CONF_BET_MODE_* | ||
977 | */ | ||
978 | u8 bet_enable; | ||
979 | |||
980 | /* | ||
981 | * Specifies the maximum number of consecutive beacons that may be | ||
982 | * early terminated. After this number is reached at least one full | ||
983 | * beacon must be correctly received in FW before beacon ET | ||
984 | * resumes. | ||
985 | * | ||
986 | * Range 0 - 255 | ||
987 | */ | ||
988 | u8 bet_max_consecutive; | ||
989 | |||
990 | /* | ||
991 | * Specifies the maximum number of times to try PSM entry if it fails | ||
992 | * (if sending the appropriate null-func message fails.) | ||
993 | * | ||
994 | * Range 0 - 255 | ||
995 | */ | ||
996 | u8 psm_entry_retries; | ||
997 | |||
998 | /* | ||
999 | * Specifies the maximum number of times to try PSM exit if it fails | ||
1000 | * (if sending the appropriate null-func message fails.) | ||
1001 | * | ||
1002 | * Range 0 - 255 | ||
1003 | */ | ||
1004 | u8 psm_exit_retries; | ||
1005 | |||
1006 | /* | ||
1007 | * Specifies the maximum number of times to try transmit the PSM entry | ||
1008 | * null-func frame for each PSM entry attempt | ||
1009 | * | ||
1010 | * Range 0 - 255 | ||
1011 | */ | ||
1012 | u8 psm_entry_nullfunc_retries; | ||
1013 | |||
1014 | /* | ||
1015 | * Specifies the time to linger in active mode after successfully | ||
1016 | * transmitting the PSM entry null-func frame. | ||
1017 | * | ||
1018 | * Range 0 - 255 TU's | ||
1019 | */ | ||
1020 | u8 psm_entry_hangover_period; | ||
1021 | |||
1022 | /* | ||
1023 | * | ||
1024 | * Specifies the interval of the connection keep-alive null-func | ||
1025 | * frame in ms. | ||
1026 | * | ||
1027 | * Range: 1000 - 3600000 | ||
1028 | */ | ||
1029 | u32 keep_alive_interval; | ||
1030 | |||
1031 | /* | ||
1032 | * Maximum listen interval supported by the driver in units of beacons. | ||
1033 | * | ||
1034 | * Range: u16 | ||
1035 | */ | ||
1036 | u8 max_listen_interval; | ||
1037 | }; | ||
1038 | |||
1039 | enum { | ||
1040 | CONF_REF_CLK_19_2_E, | ||
1041 | CONF_REF_CLK_26_E, | ||
1042 | CONF_REF_CLK_38_4_E, | ||
1043 | CONF_REF_CLK_52_E, | ||
1044 | CONF_REF_CLK_38_4_M_XTAL, | ||
1045 | CONF_REF_CLK_26_M_XTAL, | ||
1046 | }; | ||
1047 | |||
1048 | enum single_dual_band_enum { | ||
1049 | CONF_SINGLE_BAND, | ||
1050 | CONF_DUAL_BAND | ||
1051 | }; | ||
1052 | |||
1053 | #define CONF_RSSI_AND_PROCESS_COMPENSATION_SIZE 15 | ||
1054 | #define CONF_NUMBER_OF_SUB_BANDS_5 7 | ||
1055 | #define CONF_NUMBER_OF_RATE_GROUPS 6 | ||
1056 | #define CONF_NUMBER_OF_CHANNELS_2_4 14 | ||
1057 | #define CONF_NUMBER_OF_CHANNELS_5 35 | ||
1058 | |||
1059 | struct conf_itrim_settings { | ||
1060 | /* enable dco itrim */ | ||
1061 | u8 enable; | ||
1062 | |||
1063 | /* moderation timeout in microsecs from the last TX */ | ||
1064 | u32 timeout; | ||
1065 | }; | ||
1066 | |||
1067 | struct conf_pm_config_settings { | ||
1068 | /* | ||
1069 | * Host clock settling time | ||
1070 | * | ||
1071 | * Range: 0 - 30000 us | ||
1072 | */ | ||
1073 | u32 host_clk_settling_time; | ||
1074 | |||
1075 | /* | ||
1076 | * Host fast wakeup support | ||
1077 | * | ||
1078 | * Range: true, false | ||
1079 | */ | ||
1080 | bool host_fast_wakeup_support; | ||
1081 | }; | ||
1082 | |||
1083 | struct conf_roam_trigger_settings { | ||
1084 | /* | ||
1085 | * The minimum interval between two trigger events. | ||
1086 | * | ||
1087 | * Range: 0 - 60000 ms | ||
1088 | */ | ||
1089 | u16 trigger_pacing; | ||
1090 | |||
1091 | /* | ||
1092 | * The weight for rssi/beacon average calculation | ||
1093 | * | ||
1094 | * Range: 0 - 255 | ||
1095 | */ | ||
1096 | u8 avg_weight_rssi_beacon; | ||
1097 | |||
1098 | /* | ||
1099 | * The weight for rssi/data frame average calculation | ||
1100 | * | ||
1101 | * Range: 0 - 255 | ||
1102 | */ | ||
1103 | u8 avg_weight_rssi_data; | ||
1104 | |||
1105 | /* | ||
1106 | * The weight for snr/beacon average calculation | ||
1107 | * | ||
1108 | * Range: 0 - 255 | ||
1109 | */ | ||
1110 | u8 avg_weight_snr_beacon; | ||
1111 | |||
1112 | /* | ||
1113 | * The weight for snr/data frame average calculation | ||
1114 | * | ||
1115 | * Range: 0 - 255 | ||
1116 | */ | ||
1117 | u8 avg_weight_snr_data; | ||
1118 | }; | ||
1119 | |||
1120 | struct conf_scan_settings { | ||
1121 | /* | ||
1122 | * The minimum time to wait on each channel for active scans | ||
1123 | * | ||
1124 | * Range: u32 tu/1000 | ||
1125 | */ | ||
1126 | u32 min_dwell_time_active; | ||
1127 | |||
1128 | /* | ||
1129 | * The maximum time to wait on each channel for active scans | ||
1130 | * | ||
1131 | * Range: u32 tu/1000 | ||
1132 | */ | ||
1133 | u32 max_dwell_time_active; | ||
1134 | |||
1135 | /* | ||
1136 | * The minimum time to wait on each channel for passive scans | ||
1137 | * | ||
1138 | * Range: u32 tu/1000 | ||
1139 | */ | ||
1140 | u32 min_dwell_time_passive; | ||
1141 | |||
1142 | /* | ||
1143 | * The maximum time to wait on each channel for passive scans | ||
1144 | * | ||
1145 | * Range: u32 tu/1000 | ||
1146 | */ | ||
1147 | u32 max_dwell_time_passive; | ||
1148 | |||
1149 | /* | ||
1150 | * Number of probe requests to transmit on each active scan channel | ||
1151 | * | ||
1152 | * Range: u8 | ||
1153 | */ | ||
1154 | u16 num_probe_reqs; | ||
1155 | |||
1156 | }; | ||
1157 | |||
1158 | struct conf_sched_scan_settings { | ||
1159 | /* minimum time to wait on the channel for active scans (in TUs) */ | ||
1160 | u16 min_dwell_time_active; | ||
1161 | |||
1162 | /* maximum time to wait on the channel for active scans (in TUs) */ | ||
1163 | u16 max_dwell_time_active; | ||
1164 | |||
1165 | /* time to wait on the channel for passive scans (in TUs) */ | ||
1166 | u32 dwell_time_passive; | ||
1167 | |||
1168 | /* time to wait on the channel for DFS scans (in TUs) */ | ||
1169 | u32 dwell_time_dfs; | ||
1170 | |||
1171 | /* number of probe requests to send on each channel in active scans */ | ||
1172 | u8 num_probe_reqs; | ||
1173 | |||
1174 | /* RSSI threshold to be used for filtering */ | ||
1175 | s8 rssi_threshold; | ||
1176 | |||
1177 | /* SNR threshold to be used for filtering */ | ||
1178 | s8 snr_threshold; | ||
1179 | }; | ||
1180 | |||
1181 | /* these are number of channels on the band divided by two, rounded up */ | ||
1182 | #define CONF_TX_PWR_COMPENSATION_LEN_2 7 | ||
1183 | #define CONF_TX_PWR_COMPENSATION_LEN_5 18 | ||
1184 | |||
1185 | struct conf_rf_settings { | ||
1186 | /* | ||
1187 | * Per channel power compensation for 2.4GHz | ||
1188 | * | ||
1189 | * Range: s8 | ||
1190 | */ | ||
1191 | u8 tx_per_channel_power_compensation_2[CONF_TX_PWR_COMPENSATION_LEN_2]; | ||
1192 | |||
1193 | /* | ||
1194 | * Per channel power compensation for 5GHz | ||
1195 | * | ||
1196 | * Range: s8 | ||
1197 | */ | ||
1198 | u8 tx_per_channel_power_compensation_5[CONF_TX_PWR_COMPENSATION_LEN_5]; | ||
1199 | }; | ||
1200 | |||
1201 | struct conf_ht_setting { | ||
1202 | u16 tx_ba_win_size; | ||
1203 | u16 inactivity_timeout; | ||
1204 | }; | ||
1205 | |||
1206 | struct conf_memory_settings { | ||
1207 | /* Number of stations supported in IBSS mode */ | ||
1208 | u8 num_stations; | ||
1209 | |||
1210 | /* Number of ssid profiles used in IBSS mode */ | ||
1211 | u8 ssid_profiles; | ||
1212 | |||
1213 | /* Number of memory buffers allocated to rx pool */ | ||
1214 | u8 rx_block_num; | ||
1215 | |||
1216 | /* Minimum number of blocks allocated to tx pool */ | ||
1217 | u8 tx_min_block_num; | ||
1218 | |||
1219 | /* Disable/Enable dynamic memory */ | ||
1220 | u8 dynamic_memory; | ||
1221 | |||
1222 | /* | ||
1223 | * Minimum required free tx memory blocks in order to assure optimum | ||
1224 | * performance | ||
1225 | * | ||
1226 | * Range: 0-120 | ||
1227 | */ | ||
1228 | u8 min_req_tx_blocks; | ||
1229 | |||
1230 | /* | ||
1231 | * Minimum required free rx memory blocks in order to assure optimum | ||
1232 | * performance | ||
1233 | * | ||
1234 | * Range: 0-120 | ||
1235 | */ | ||
1236 | u8 min_req_rx_blocks; | ||
1237 | |||
1238 | /* | ||
1239 | * Minimum number of mem blocks (free+used) guaranteed for TX | ||
1240 | * | ||
1241 | * Range: 0-120 | ||
1242 | */ | ||
1243 | u8 tx_min; | ||
1244 | }; | ||
1245 | |||
1246 | struct conf_fm_coex { | ||
1247 | u8 enable; | ||
1248 | u8 swallow_period; | ||
1249 | u8 n_divider_fref_set_1; | ||
1250 | u8 n_divider_fref_set_2; | ||
1251 | u16 m_divider_fref_set_1; | ||
1252 | u16 m_divider_fref_set_2; | ||
1253 | u32 coex_pll_stabilization_time; | ||
1254 | u16 ldo_stabilization_time; | ||
1255 | u8 fm_disturbed_band_margin; | ||
1256 | u8 swallow_clk_diff; | ||
1257 | }; | ||
1258 | |||
1259 | struct conf_rx_streaming_settings { | ||
1260 | /* | ||
1261 | * RX Streaming duration (in msec) from last tx/rx | ||
1262 | * | ||
1263 | * Range: u32 | ||
1264 | */ | ||
1265 | u32 duration; | ||
1266 | |||
1267 | /* | ||
1268 | * Bitmap of tids to be polled during RX streaming. | ||
1269 | * (Note: it doesn't look like it really matters) | ||
1270 | * | ||
1271 | * Range: 0x1-0xff | ||
1272 | */ | ||
1273 | u8 queues; | ||
1274 | |||
1275 | /* | ||
1276 | * RX Streaming interval. | ||
1277 | * (Note:this value is also used as the rx streaming timeout) | ||
1278 | * Range: 0 (disabled), 10 - 100 | ||
1279 | */ | ||
1280 | u8 interval; | ||
1281 | |||
1282 | /* | ||
1283 | * enable rx streaming also when there is no coex activity | ||
1284 | */ | ||
1285 | u8 always; | ||
1286 | }; | ||
1287 | |||
1288 | struct conf_fwlog { | ||
1289 | /* Continuous or on-demand */ | ||
1290 | u8 mode; | ||
1291 | |||
1292 | /* | ||
1293 | * Number of memory blocks dedicated for the FW logger | ||
1294 | * | ||
1295 | * Range: 1-3, or 0 to disable the FW logger | ||
1296 | */ | ||
1297 | u8 mem_blocks; | ||
1298 | |||
1299 | /* Minimum log level threshold */ | ||
1300 | u8 severity; | ||
1301 | |||
1302 | /* Include/exclude timestamps from the log messages */ | ||
1303 | u8 timestamp; | ||
1304 | |||
1305 | /* See enum wl1271_fwlogger_output */ | ||
1306 | u8 output; | ||
1307 | |||
1308 | /* Regulates the frequency of log messages */ | ||
1309 | u8 threshold; | ||
1310 | }; | ||
1311 | |||
1312 | struct conf_drv_settings { | ||
1313 | struct conf_sg_settings sg; | ||
1314 | struct conf_rx_settings rx; | ||
1315 | struct conf_tx_settings tx; | ||
1316 | struct conf_conn_settings conn; | ||
1317 | struct conf_itrim_settings itrim; | ||
1318 | struct conf_pm_config_settings pm_config; | ||
1319 | struct conf_roam_trigger_settings roam_trigger; | ||
1320 | struct conf_scan_settings scan; | ||
1321 | struct conf_sched_scan_settings sched_scan; | ||
1322 | struct conf_rf_settings rf; | ||
1323 | struct conf_ht_setting ht; | ||
1324 | struct conf_memory_settings mem_wl127x; | ||
1325 | struct conf_memory_settings mem_wl128x; | ||
1326 | struct conf_fm_coex fm_coex; | ||
1327 | struct conf_rx_streaming_settings rx_streaming; | ||
1328 | struct conf_fwlog fwlog; | ||
1329 | u8 hci_io_ds; | ||
1330 | }; | ||
1331 | |||
1332 | #endif | ||
diff --git a/drivers/net/wireless/wl12xx/debugfs.c b/drivers/net/wireless/wl12xx/debugfs.c new file mode 100644 index 00000000000..37934b5601c --- /dev/null +++ b/drivers/net/wireless/wl12xx/debugfs.c | |||
@@ -0,0 +1,850 @@ | |||
1 | /* | ||
2 | * This file is part of wl1271 | ||
3 | * | ||
4 | * Copyright (C) 2009 Nokia Corporation | ||
5 | * | ||
6 | * Contact: Luciano Coelho <luciano.coelho@nokia.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU General Public License | ||
10 | * version 2 as published by the Free Software Foundation. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, but | ||
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
20 | * 02110-1301 USA | ||
21 | * | ||
22 | */ | ||
23 | |||
24 | #include "debugfs.h" | ||
25 | |||
26 | #include <linux/skbuff.h> | ||
27 | #include <linux/slab.h> | ||
28 | |||
29 | #include "wl12xx.h" | ||
30 | #include "acx.h" | ||
31 | #include "ps.h" | ||
32 | #include "io.h" | ||
33 | #include "tx.h" | ||
34 | |||
35 | /* ms */ | ||
36 | #define WL1271_DEBUGFS_STATS_LIFETIME 1000 | ||
37 | |||
38 | /* debugfs macros idea from mac80211 */ | ||
39 | #define DEBUGFS_FORMAT_BUFFER_SIZE 100 | ||
40 | static int wl1271_format_buffer(char __user *userbuf, size_t count, | ||
41 | loff_t *ppos, char *fmt, ...) | ||
42 | { | ||
43 | va_list args; | ||
44 | char buf[DEBUGFS_FORMAT_BUFFER_SIZE]; | ||
45 | int res; | ||
46 | |||
47 | va_start(args, fmt); | ||
48 | res = vscnprintf(buf, sizeof(buf), fmt, args); | ||
49 | va_end(args); | ||
50 | |||
51 | return simple_read_from_buffer(userbuf, count, ppos, buf, res); | ||
52 | } | ||
53 | |||
54 | #define DEBUGFS_READONLY_FILE(name, fmt, value...) \ | ||
55 | static ssize_t name## _read(struct file *file, char __user *userbuf, \ | ||
56 | size_t count, loff_t *ppos) \ | ||
57 | { \ | ||
58 | struct wl1271 *wl = file->private_data; \ | ||
59 | return wl1271_format_buffer(userbuf, count, ppos, \ | ||
60 | fmt "\n", ##value); \ | ||
61 | } \ | ||
62 | \ | ||
63 | static const struct file_operations name## _ops = { \ | ||
64 | .read = name## _read, \ | ||
65 | .open = wl1271_open_file_generic, \ | ||
66 | .llseek = generic_file_llseek, \ | ||
67 | }; | ||
68 | |||
69 | #define DEBUGFS_ADD(name, parent) \ | ||
70 | entry = debugfs_create_file(#name, 0400, parent, \ | ||
71 | wl, &name## _ops); \ | ||
72 | if (!entry || IS_ERR(entry)) \ | ||
73 | goto err; \ | ||
74 | |||
75 | #define DEBUGFS_ADD_PREFIX(prefix, name, parent) \ | ||
76 | do { \ | ||
77 | entry = debugfs_create_file(#name, 0400, parent, \ | ||
78 | wl, &prefix## _## name## _ops); \ | ||
79 | if (!entry || IS_ERR(entry)) \ | ||
80 | goto err; \ | ||
81 | } while (0); | ||
82 | |||
83 | #define DEBUGFS_FWSTATS_FILE(sub, name, fmt) \ | ||
84 | static ssize_t sub## _ ##name## _read(struct file *file, \ | ||
85 | char __user *userbuf, \ | ||
86 | size_t count, loff_t *ppos) \ | ||
87 | { \ | ||
88 | struct wl1271 *wl = file->private_data; \ | ||
89 | \ | ||
90 | wl1271_debugfs_update_stats(wl); \ | ||
91 | \ | ||
92 | return wl1271_format_buffer(userbuf, count, ppos, fmt "\n", \ | ||
93 | wl->stats.fw_stats->sub.name); \ | ||
94 | } \ | ||
95 | \ | ||
96 | static const struct file_operations sub## _ ##name## _ops = { \ | ||
97 | .read = sub## _ ##name## _read, \ | ||
98 | .open = wl1271_open_file_generic, \ | ||
99 | .llseek = generic_file_llseek, \ | ||
100 | }; | ||
101 | |||
102 | #define DEBUGFS_FWSTATS_ADD(sub, name) \ | ||
103 | DEBUGFS_ADD(sub## _ ##name, stats) | ||
104 | |||
105 | static void wl1271_debugfs_update_stats(struct wl1271 *wl) | ||
106 | { | ||
107 | int ret; | ||
108 | |||
109 | mutex_lock(&wl->mutex); | ||
110 | |||
111 | ret = wl1271_ps_elp_wakeup(wl); | ||
112 | if (ret < 0) | ||
113 | goto out; | ||
114 | |||
115 | if (wl->state == WL1271_STATE_ON && | ||
116 | time_after(jiffies, wl->stats.fw_stats_update + | ||
117 | msecs_to_jiffies(WL1271_DEBUGFS_STATS_LIFETIME))) { | ||
118 | wl1271_acx_statistics(wl, wl->stats.fw_stats); | ||
119 | wl->stats.fw_stats_update = jiffies; | ||
120 | } | ||
121 | |||
122 | wl1271_ps_elp_sleep(wl); | ||
123 | |||
124 | out: | ||
125 | mutex_unlock(&wl->mutex); | ||
126 | } | ||
127 | |||
128 | static int wl1271_open_file_generic(struct inode *inode, struct file *file) | ||
129 | { | ||
130 | file->private_data = inode->i_private; | ||
131 | return 0; | ||
132 | } | ||
133 | |||
134 | DEBUGFS_FWSTATS_FILE(tx, internal_desc_overflow, "%u"); | ||
135 | |||
136 | DEBUGFS_FWSTATS_FILE(rx, out_of_mem, "%u"); | ||
137 | DEBUGFS_FWSTATS_FILE(rx, hdr_overflow, "%u"); | ||
138 | DEBUGFS_FWSTATS_FILE(rx, hw_stuck, "%u"); | ||
139 | DEBUGFS_FWSTATS_FILE(rx, dropped, "%u"); | ||
140 | DEBUGFS_FWSTATS_FILE(rx, fcs_err, "%u"); | ||
141 | DEBUGFS_FWSTATS_FILE(rx, xfr_hint_trig, "%u"); | ||
142 | DEBUGFS_FWSTATS_FILE(rx, path_reset, "%u"); | ||
143 | DEBUGFS_FWSTATS_FILE(rx, reset_counter, "%u"); | ||
144 | |||
145 | DEBUGFS_FWSTATS_FILE(dma, rx_requested, "%u"); | ||
146 | DEBUGFS_FWSTATS_FILE(dma, rx_errors, "%u"); | ||
147 | DEBUGFS_FWSTATS_FILE(dma, tx_requested, "%u"); | ||
148 | DEBUGFS_FWSTATS_FILE(dma, tx_errors, "%u"); | ||
149 | |||
150 | DEBUGFS_FWSTATS_FILE(isr, cmd_cmplt, "%u"); | ||
151 | DEBUGFS_FWSTATS_FILE(isr, fiqs, "%u"); | ||
152 | DEBUGFS_FWSTATS_FILE(isr, rx_headers, "%u"); | ||
153 | DEBUGFS_FWSTATS_FILE(isr, rx_mem_overflow, "%u"); | ||
154 | DEBUGFS_FWSTATS_FILE(isr, rx_rdys, "%u"); | ||
155 | DEBUGFS_FWSTATS_FILE(isr, irqs, "%u"); | ||
156 | DEBUGFS_FWSTATS_FILE(isr, tx_procs, "%u"); | ||
157 | DEBUGFS_FWSTATS_FILE(isr, decrypt_done, "%u"); | ||
158 | DEBUGFS_FWSTATS_FILE(isr, dma0_done, "%u"); | ||
159 | DEBUGFS_FWSTATS_FILE(isr, dma1_done, "%u"); | ||
160 | DEBUGFS_FWSTATS_FILE(isr, tx_exch_complete, "%u"); | ||
161 | DEBUGFS_FWSTATS_FILE(isr, commands, "%u"); | ||
162 | DEBUGFS_FWSTATS_FILE(isr, rx_procs, "%u"); | ||
163 | DEBUGFS_FWSTATS_FILE(isr, hw_pm_mode_changes, "%u"); | ||
164 | DEBUGFS_FWSTATS_FILE(isr, host_acknowledges, "%u"); | ||
165 | DEBUGFS_FWSTATS_FILE(isr, pci_pm, "%u"); | ||
166 | DEBUGFS_FWSTATS_FILE(isr, wakeups, "%u"); | ||
167 | DEBUGFS_FWSTATS_FILE(isr, low_rssi, "%u"); | ||
168 | |||
169 | DEBUGFS_FWSTATS_FILE(wep, addr_key_count, "%u"); | ||
170 | DEBUGFS_FWSTATS_FILE(wep, default_key_count, "%u"); | ||
171 | /* skipping wep.reserved */ | ||
172 | DEBUGFS_FWSTATS_FILE(wep, key_not_found, "%u"); | ||
173 | DEBUGFS_FWSTATS_FILE(wep, decrypt_fail, "%u"); | ||
174 | DEBUGFS_FWSTATS_FILE(wep, packets, "%u"); | ||
175 | DEBUGFS_FWSTATS_FILE(wep, interrupt, "%u"); | ||
176 | |||
177 | DEBUGFS_FWSTATS_FILE(pwr, ps_enter, "%u"); | ||
178 | DEBUGFS_FWSTATS_FILE(pwr, elp_enter, "%u"); | ||
179 | DEBUGFS_FWSTATS_FILE(pwr, missing_bcns, "%u"); | ||
180 | DEBUGFS_FWSTATS_FILE(pwr, wake_on_host, "%u"); | ||
181 | DEBUGFS_FWSTATS_FILE(pwr, wake_on_timer_exp, "%u"); | ||
182 | DEBUGFS_FWSTATS_FILE(pwr, tx_with_ps, "%u"); | ||
183 | DEBUGFS_FWSTATS_FILE(pwr, tx_without_ps, "%u"); | ||
184 | DEBUGFS_FWSTATS_FILE(pwr, rcvd_beacons, "%u"); | ||
185 | DEBUGFS_FWSTATS_FILE(pwr, power_save_off, "%u"); | ||
186 | DEBUGFS_FWSTATS_FILE(pwr, enable_ps, "%u"); | ||
187 | DEBUGFS_FWSTATS_FILE(pwr, disable_ps, "%u"); | ||
188 | DEBUGFS_FWSTATS_FILE(pwr, fix_tsf_ps, "%u"); | ||
189 | /* skipping cont_miss_bcns_spread for now */ | ||
190 | DEBUGFS_FWSTATS_FILE(pwr, rcvd_awake_beacons, "%u"); | ||
191 | |||
192 | DEBUGFS_FWSTATS_FILE(mic, rx_pkts, "%u"); | ||
193 | DEBUGFS_FWSTATS_FILE(mic, calc_failure, "%u"); | ||
194 | |||
195 | DEBUGFS_FWSTATS_FILE(aes, encrypt_fail, "%u"); | ||
196 | DEBUGFS_FWSTATS_FILE(aes, decrypt_fail, "%u"); | ||
197 | DEBUGFS_FWSTATS_FILE(aes, encrypt_packets, "%u"); | ||
198 | DEBUGFS_FWSTATS_FILE(aes, decrypt_packets, "%u"); | ||
199 | DEBUGFS_FWSTATS_FILE(aes, encrypt_interrupt, "%u"); | ||
200 | DEBUGFS_FWSTATS_FILE(aes, decrypt_interrupt, "%u"); | ||
201 | |||
202 | DEBUGFS_FWSTATS_FILE(event, heart_beat, "%u"); | ||
203 | DEBUGFS_FWSTATS_FILE(event, calibration, "%u"); | ||
204 | DEBUGFS_FWSTATS_FILE(event, rx_mismatch, "%u"); | ||
205 | DEBUGFS_FWSTATS_FILE(event, rx_mem_empty, "%u"); | ||
206 | DEBUGFS_FWSTATS_FILE(event, rx_pool, "%u"); | ||
207 | DEBUGFS_FWSTATS_FILE(event, oom_late, "%u"); | ||
208 | DEBUGFS_FWSTATS_FILE(event, phy_transmit_error, "%u"); | ||
209 | DEBUGFS_FWSTATS_FILE(event, tx_stuck, "%u"); | ||
210 | |||
211 | DEBUGFS_FWSTATS_FILE(ps, pspoll_timeouts, "%u"); | ||
212 | DEBUGFS_FWSTATS_FILE(ps, upsd_timeouts, "%u"); | ||
213 | DEBUGFS_FWSTATS_FILE(ps, upsd_max_sptime, "%u"); | ||
214 | DEBUGFS_FWSTATS_FILE(ps, upsd_max_apturn, "%u"); | ||
215 | DEBUGFS_FWSTATS_FILE(ps, pspoll_max_apturn, "%u"); | ||
216 | DEBUGFS_FWSTATS_FILE(ps, pspoll_utilization, "%u"); | ||
217 | DEBUGFS_FWSTATS_FILE(ps, upsd_utilization, "%u"); | ||
218 | |||
219 | DEBUGFS_FWSTATS_FILE(rxpipe, rx_prep_beacon_drop, "%u"); | ||
220 | DEBUGFS_FWSTATS_FILE(rxpipe, descr_host_int_trig_rx_data, "%u"); | ||
221 | DEBUGFS_FWSTATS_FILE(rxpipe, beacon_buffer_thres_host_int_trig_rx_data, "%u"); | ||
222 | DEBUGFS_FWSTATS_FILE(rxpipe, missed_beacon_host_int_trig_rx_data, "%u"); | ||
223 | DEBUGFS_FWSTATS_FILE(rxpipe, tx_xfr_host_int_trig_rx_data, "%u"); | ||
224 | |||
225 | DEBUGFS_READONLY_FILE(retry_count, "%u", wl->stats.retry_count); | ||
226 | DEBUGFS_READONLY_FILE(excessive_retries, "%u", | ||
227 | wl->stats.excessive_retries); | ||
228 | |||
229 | static ssize_t tx_queue_len_read(struct file *file, char __user *userbuf, | ||
230 | size_t count, loff_t *ppos) | ||
231 | { | ||
232 | struct wl1271 *wl = file->private_data; | ||
233 | u32 queue_len; | ||
234 | char buf[20]; | ||
235 | int res; | ||
236 | |||
237 | queue_len = wl1271_tx_total_queue_count(wl); | ||
238 | |||
239 | res = scnprintf(buf, sizeof(buf), "%u\n", queue_len); | ||
240 | return simple_read_from_buffer(userbuf, count, ppos, buf, res); | ||
241 | } | ||
242 | |||
243 | static const struct file_operations tx_queue_len_ops = { | ||
244 | .read = tx_queue_len_read, | ||
245 | .open = wl1271_open_file_generic, | ||
246 | .llseek = default_llseek, | ||
247 | }; | ||
248 | |||
249 | static ssize_t gpio_power_read(struct file *file, char __user *user_buf, | ||
250 | size_t count, loff_t *ppos) | ||
251 | { | ||
252 | struct wl1271 *wl = file->private_data; | ||
253 | bool state = test_bit(WL1271_FLAG_GPIO_POWER, &wl->flags); | ||
254 | |||
255 | int res; | ||
256 | char buf[10]; | ||
257 | |||
258 | res = scnprintf(buf, sizeof(buf), "%d\n", state); | ||
259 | |||
260 | return simple_read_from_buffer(user_buf, count, ppos, buf, res); | ||
261 | } | ||
262 | |||
263 | static ssize_t gpio_power_write(struct file *file, | ||
264 | const char __user *user_buf, | ||
265 | size_t count, loff_t *ppos) | ||
266 | { | ||
267 | struct wl1271 *wl = file->private_data; | ||
268 | char buf[10]; | ||
269 | size_t len; | ||
270 | unsigned long value; | ||
271 | int ret; | ||
272 | |||
273 | len = min(count, sizeof(buf) - 1); | ||
274 | if (copy_from_user(buf, user_buf, len)) { | ||
275 | return -EFAULT; | ||
276 | } | ||
277 | buf[len] = '\0'; | ||
278 | |||
279 | ret = kstrtoul(buf, 0, &value); | ||
280 | if (ret < 0) { | ||
281 | wl1271_warning("illegal value in gpio_power"); | ||
282 | return -EINVAL; | ||
283 | } | ||
284 | |||
285 | mutex_lock(&wl->mutex); | ||
286 | |||
287 | if (value) | ||
288 | wl1271_power_on(wl); | ||
289 | else | ||
290 | wl1271_power_off(wl); | ||
291 | |||
292 | mutex_unlock(&wl->mutex); | ||
293 | return count; | ||
294 | } | ||
295 | |||
296 | static const struct file_operations gpio_power_ops = { | ||
297 | .read = gpio_power_read, | ||
298 | .write = gpio_power_write, | ||
299 | .open = wl1271_open_file_generic, | ||
300 | .llseek = default_llseek, | ||
301 | }; | ||
302 | |||
303 | static ssize_t start_recovery_write(struct file *file, | ||
304 | const char __user *user_buf, | ||
305 | size_t count, loff_t *ppos) | ||
306 | { | ||
307 | struct wl1271 *wl = file->private_data; | ||
308 | |||
309 | mutex_lock(&wl->mutex); | ||
310 | wl12xx_queue_recovery_work(wl); | ||
311 | mutex_unlock(&wl->mutex); | ||
312 | |||
313 | return count; | ||
314 | } | ||
315 | |||
316 | static const struct file_operations start_recovery_ops = { | ||
317 | .write = start_recovery_write, | ||
318 | .open = wl1271_open_file_generic, | ||
319 | .llseek = default_llseek, | ||
320 | }; | ||
321 | |||
322 | static ssize_t driver_state_read(struct file *file, char __user *user_buf, | ||
323 | size_t count, loff_t *ppos) | ||
324 | { | ||
325 | struct wl1271 *wl = file->private_data; | ||
326 | int res = 0; | ||
327 | char buf[1024]; | ||
328 | |||
329 | mutex_lock(&wl->mutex); | ||
330 | |||
331 | #define DRIVER_STATE_PRINT(x, fmt) \ | ||
332 | (res += scnprintf(buf + res, sizeof(buf) - res,\ | ||
333 | #x " = " fmt "\n", wl->x)) | ||
334 | |||
335 | #define DRIVER_STATE_PRINT_LONG(x) DRIVER_STATE_PRINT(x, "%ld") | ||
336 | #define DRIVER_STATE_PRINT_INT(x) DRIVER_STATE_PRINT(x, "%d") | ||
337 | #define DRIVER_STATE_PRINT_STR(x) DRIVER_STATE_PRINT(x, "%s") | ||
338 | #define DRIVER_STATE_PRINT_LHEX(x) DRIVER_STATE_PRINT(x, "0x%lx") | ||
339 | #define DRIVER_STATE_PRINT_HEX(x) DRIVER_STATE_PRINT(x, "0x%x") | ||
340 | |||
341 | DRIVER_STATE_PRINT_INT(tx_blocks_available); | ||
342 | DRIVER_STATE_PRINT_INT(tx_allocated_blocks[0]); | ||
343 | DRIVER_STATE_PRINT_INT(tx_allocated_blocks[1]); | ||
344 | DRIVER_STATE_PRINT_INT(tx_allocated_blocks[2]); | ||
345 | DRIVER_STATE_PRINT_INT(tx_allocated_blocks[3]); | ||
346 | DRIVER_STATE_PRINT_INT(tx_frames_cnt); | ||
347 | DRIVER_STATE_PRINT_LHEX(tx_frames_map[0]); | ||
348 | DRIVER_STATE_PRINT_INT(tx_queue_count[0]); | ||
349 | DRIVER_STATE_PRINT_INT(tx_queue_count[1]); | ||
350 | DRIVER_STATE_PRINT_INT(tx_queue_count[2]); | ||
351 | DRIVER_STATE_PRINT_INT(tx_queue_count[3]); | ||
352 | DRIVER_STATE_PRINT_INT(tx_packets_count); | ||
353 | DRIVER_STATE_PRINT_INT(tx_results_count); | ||
354 | DRIVER_STATE_PRINT_LHEX(flags); | ||
355 | DRIVER_STATE_PRINT_INT(tx_blocks_freed[0]); | ||
356 | DRIVER_STATE_PRINT_INT(tx_blocks_freed[1]); | ||
357 | DRIVER_STATE_PRINT_INT(tx_blocks_freed[2]); | ||
358 | DRIVER_STATE_PRINT_INT(tx_blocks_freed[3]); | ||
359 | DRIVER_STATE_PRINT_INT(tx_security_last_seq_lsb); | ||
360 | DRIVER_STATE_PRINT_INT(rx_counter); | ||
361 | DRIVER_STATE_PRINT_INT(session_counter); | ||
362 | DRIVER_STATE_PRINT_INT(state); | ||
363 | DRIVER_STATE_PRINT_INT(bss_type); | ||
364 | DRIVER_STATE_PRINT_INT(channel); | ||
365 | DRIVER_STATE_PRINT_HEX(rate_set); | ||
366 | DRIVER_STATE_PRINT_HEX(basic_rate_set); | ||
367 | DRIVER_STATE_PRINT_HEX(basic_rate); | ||
368 | DRIVER_STATE_PRINT_INT(band); | ||
369 | DRIVER_STATE_PRINT_INT(beacon_int); | ||
370 | DRIVER_STATE_PRINT_INT(psm_entry_retry); | ||
371 | DRIVER_STATE_PRINT_INT(ps_poll_failures); | ||
372 | DRIVER_STATE_PRINT_HEX(filters); | ||
373 | DRIVER_STATE_PRINT_HEX(rx_config); | ||
374 | DRIVER_STATE_PRINT_HEX(rx_filter); | ||
375 | DRIVER_STATE_PRINT_INT(power_level); | ||
376 | DRIVER_STATE_PRINT_INT(rssi_thold); | ||
377 | DRIVER_STATE_PRINT_INT(last_rssi_event); | ||
378 | DRIVER_STATE_PRINT_INT(sg_enabled); | ||
379 | DRIVER_STATE_PRINT_INT(enable_11a); | ||
380 | DRIVER_STATE_PRINT_INT(noise); | ||
381 | DRIVER_STATE_PRINT_LHEX(ap_hlid_map[0]); | ||
382 | DRIVER_STATE_PRINT_INT(last_tx_hlid); | ||
383 | DRIVER_STATE_PRINT_INT(ba_support); | ||
384 | DRIVER_STATE_PRINT_HEX(ba_rx_bitmap); | ||
385 | DRIVER_STATE_PRINT_HEX(ap_fw_ps_map); | ||
386 | DRIVER_STATE_PRINT_LHEX(ap_ps_map); | ||
387 | DRIVER_STATE_PRINT_HEX(quirks); | ||
388 | DRIVER_STATE_PRINT_HEX(irq); | ||
389 | DRIVER_STATE_PRINT_HEX(ref_clock); | ||
390 | DRIVER_STATE_PRINT_HEX(tcxo_clock); | ||
391 | DRIVER_STATE_PRINT_HEX(hw_pg_ver); | ||
392 | DRIVER_STATE_PRINT_HEX(platform_quirks); | ||
393 | DRIVER_STATE_PRINT_HEX(chip.id); | ||
394 | DRIVER_STATE_PRINT_STR(chip.fw_ver_str); | ||
395 | DRIVER_STATE_PRINT_INT(sched_scanning); | ||
396 | |||
397 | #undef DRIVER_STATE_PRINT_INT | ||
398 | #undef DRIVER_STATE_PRINT_LONG | ||
399 | #undef DRIVER_STATE_PRINT_HEX | ||
400 | #undef DRIVER_STATE_PRINT_LHEX | ||
401 | #undef DRIVER_STATE_PRINT_STR | ||
402 | #undef DRIVER_STATE_PRINT | ||
403 | |||
404 | mutex_unlock(&wl->mutex); | ||
405 | |||
406 | return simple_read_from_buffer(user_buf, count, ppos, buf, res); | ||
407 | } | ||
408 | |||
409 | static const struct file_operations driver_state_ops = { | ||
410 | .read = driver_state_read, | ||
411 | .open = wl1271_open_file_generic, | ||
412 | .llseek = default_llseek, | ||
413 | }; | ||
414 | |||
415 | static ssize_t dtim_interval_read(struct file *file, char __user *user_buf, | ||
416 | size_t count, loff_t *ppos) | ||
417 | { | ||
418 | struct wl1271 *wl = file->private_data; | ||
419 | u8 value; | ||
420 | |||
421 | if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_DTIM || | ||
422 | wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_DTIM) | ||
423 | value = wl->conf.conn.listen_interval; | ||
424 | else | ||
425 | value = 0; | ||
426 | |||
427 | return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value); | ||
428 | } | ||
429 | |||
430 | static ssize_t dtim_interval_write(struct file *file, | ||
431 | const char __user *user_buf, | ||
432 | size_t count, loff_t *ppos) | ||
433 | { | ||
434 | struct wl1271 *wl = file->private_data; | ||
435 | char buf[10]; | ||
436 | size_t len; | ||
437 | unsigned long value; | ||
438 | int ret; | ||
439 | |||
440 | len = min(count, sizeof(buf) - 1); | ||
441 | if (copy_from_user(buf, user_buf, len)) | ||
442 | return -EFAULT; | ||
443 | buf[len] = '\0'; | ||
444 | |||
445 | ret = kstrtoul(buf, 0, &value); | ||
446 | if (ret < 0) { | ||
447 | wl1271_warning("illegal value for dtim_interval"); | ||
448 | return -EINVAL; | ||
449 | } | ||
450 | |||
451 | if (value < 1 || value > 10) { | ||
452 | wl1271_warning("dtim value is not in valid range"); | ||
453 | return -ERANGE; | ||
454 | } | ||
455 | |||
456 | mutex_lock(&wl->mutex); | ||
457 | |||
458 | wl->conf.conn.listen_interval = value; | ||
459 | /* for some reason there are different event types for 1 and >1 */ | ||
460 | if (value == 1) | ||
461 | wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_DTIM; | ||
462 | else | ||
463 | wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM; | ||
464 | |||
465 | /* | ||
466 | * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only | ||
467 | * take effect on the next time we enter psm. | ||
468 | */ | ||
469 | mutex_unlock(&wl->mutex); | ||
470 | return count; | ||
471 | } | ||
472 | |||
473 | static const struct file_operations dtim_interval_ops = { | ||
474 | .read = dtim_interval_read, | ||
475 | .write = dtim_interval_write, | ||
476 | .open = wl1271_open_file_generic, | ||
477 | .llseek = default_llseek, | ||
478 | }; | ||
479 | |||
480 | static ssize_t beacon_interval_read(struct file *file, char __user *user_buf, | ||
481 | size_t count, loff_t *ppos) | ||
482 | { | ||
483 | struct wl1271 *wl = file->private_data; | ||
484 | u8 value; | ||
485 | |||
486 | if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_BEACON || | ||
487 | wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_BEACONS) | ||
488 | value = wl->conf.conn.listen_interval; | ||
489 | else | ||
490 | value = 0; | ||
491 | |||
492 | return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value); | ||
493 | } | ||
494 | |||
495 | static ssize_t beacon_interval_write(struct file *file, | ||
496 | const char __user *user_buf, | ||
497 | size_t count, loff_t *ppos) | ||
498 | { | ||
499 | struct wl1271 *wl = file->private_data; | ||
500 | char buf[10]; | ||
501 | size_t len; | ||
502 | unsigned long value; | ||
503 | int ret; | ||
504 | |||
505 | len = min(count, sizeof(buf) - 1); | ||
506 | if (copy_from_user(buf, user_buf, len)) | ||
507 | return -EFAULT; | ||
508 | buf[len] = '\0'; | ||
509 | |||
510 | ret = kstrtoul(buf, 0, &value); | ||
511 | if (ret < 0) { | ||
512 | wl1271_warning("illegal value for beacon_interval"); | ||
513 | return -EINVAL; | ||
514 | } | ||
515 | |||
516 | if (value < 1 || value > 255) { | ||
517 | wl1271_warning("beacon interval value is not in valid range"); | ||
518 | return -ERANGE; | ||
519 | } | ||
520 | |||
521 | mutex_lock(&wl->mutex); | ||
522 | |||
523 | wl->conf.conn.listen_interval = value; | ||
524 | /* for some reason there are different event types for 1 and >1 */ | ||
525 | if (value == 1) | ||
526 | wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_BEACON; | ||
527 | else | ||
528 | wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_BEACONS; | ||
529 | |||
530 | /* | ||
531 | * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only | ||
532 | * take effect on the next time we enter psm. | ||
533 | */ | ||
534 | mutex_unlock(&wl->mutex); | ||
535 | return count; | ||
536 | } | ||
537 | |||
538 | static const struct file_operations beacon_interval_ops = { | ||
539 | .read = beacon_interval_read, | ||
540 | .write = beacon_interval_write, | ||
541 | .open = wl1271_open_file_generic, | ||
542 | .llseek = default_llseek, | ||
543 | }; | ||
544 | |||
545 | static ssize_t rx_streaming_interval_write(struct file *file, | ||
546 | const char __user *user_buf, | ||
547 | size_t count, loff_t *ppos) | ||
548 | { | ||
549 | struct wl1271 *wl = file->private_data; | ||
550 | char buf[10]; | ||
551 | size_t len; | ||
552 | unsigned long value; | ||
553 | int ret; | ||
554 | |||
555 | len = min(count, sizeof(buf) - 1); | ||
556 | if (copy_from_user(buf, user_buf, len)) | ||
557 | return -EFAULT; | ||
558 | buf[len] = '\0'; | ||
559 | |||
560 | ret = kstrtoul(buf, 0, &value); | ||
561 | if (ret < 0) { | ||
562 | wl1271_warning("illegal value in rx_streaming_interval!"); | ||
563 | return -EINVAL; | ||
564 | } | ||
565 | |||
566 | /* valid values: 0, 10-100 */ | ||
567 | if (value && (value < 10 || value > 100)) { | ||
568 | wl1271_warning("value is not in range!"); | ||
569 | return -ERANGE; | ||
570 | } | ||
571 | |||
572 | mutex_lock(&wl->mutex); | ||
573 | |||
574 | wl->conf.rx_streaming.interval = value; | ||
575 | |||
576 | ret = wl1271_ps_elp_wakeup(wl); | ||
577 | if (ret < 0) | ||
578 | goto out; | ||
579 | |||
580 | wl1271_recalc_rx_streaming(wl); | ||
581 | |||
582 | wl1271_ps_elp_sleep(wl); | ||
583 | out: | ||
584 | mutex_unlock(&wl->mutex); | ||
585 | return count; | ||
586 | } | ||
587 | |||
588 | static ssize_t rx_streaming_interval_read(struct file *file, | ||
589 | char __user *userbuf, | ||
590 | size_t count, loff_t *ppos) | ||
591 | { | ||
592 | struct wl1271 *wl = file->private_data; | ||
593 | return wl1271_format_buffer(userbuf, count, ppos, | ||
594 | "%d\n", wl->conf.rx_streaming.interval); | ||
595 | } | ||
596 | |||
597 | static const struct file_operations rx_streaming_interval_ops = { | ||
598 | .read = rx_streaming_interval_read, | ||
599 | .write = rx_streaming_interval_write, | ||
600 | .open = wl1271_open_file_generic, | ||
601 | .llseek = default_llseek, | ||
602 | }; | ||
603 | |||
604 | static ssize_t rx_streaming_always_write(struct file *file, | ||
605 | const char __user *user_buf, | ||
606 | size_t count, loff_t *ppos) | ||
607 | { | ||
608 | struct wl1271 *wl = file->private_data; | ||
609 | char buf[10]; | ||
610 | size_t len; | ||
611 | unsigned long value; | ||
612 | int ret; | ||
613 | |||
614 | len = min(count, sizeof(buf) - 1); | ||
615 | if (copy_from_user(buf, user_buf, len)) | ||
616 | return -EFAULT; | ||
617 | buf[len] = '\0'; | ||
618 | |||
619 | ret = kstrtoul(buf, 0, &value); | ||
620 | if (ret < 0) { | ||
621 | wl1271_warning("illegal value in rx_streaming_write!"); | ||
622 | return -EINVAL; | ||
623 | } | ||
624 | |||
625 | /* valid values: 0, 10-100 */ | ||
626 | if (!(value == 0 || value == 1)) { | ||
627 | wl1271_warning("value is not in valid!"); | ||
628 | return -EINVAL; | ||
629 | } | ||
630 | |||
631 | mutex_lock(&wl->mutex); | ||
632 | |||
633 | wl->conf.rx_streaming.always = value; | ||
634 | |||
635 | ret = wl1271_ps_elp_wakeup(wl); | ||
636 | if (ret < 0) | ||
637 | goto out; | ||
638 | |||
639 | wl1271_recalc_rx_streaming(wl); | ||
640 | |||
641 | wl1271_ps_elp_sleep(wl); | ||
642 | out: | ||
643 | mutex_unlock(&wl->mutex); | ||
644 | return count; | ||
645 | } | ||
646 | |||
647 | static ssize_t rx_streaming_always_read(struct file *file, | ||
648 | char __user *userbuf, | ||
649 | size_t count, loff_t *ppos) | ||
650 | { | ||
651 | struct wl1271 *wl = file->private_data; | ||
652 | return wl1271_format_buffer(userbuf, count, ppos, | ||
653 | "%d\n", wl->conf.rx_streaming.always); | ||
654 | } | ||
655 | |||
656 | static const struct file_operations rx_streaming_always_ops = { | ||
657 | .read = rx_streaming_always_read, | ||
658 | .write = rx_streaming_always_write, | ||
659 | .open = wl1271_open_file_generic, | ||
660 | .llseek = default_llseek, | ||
661 | }; | ||
662 | |||
663 | static int wl1271_debugfs_add_files(struct wl1271 *wl, | ||
664 | struct dentry *rootdir) | ||
665 | { | ||
666 | int ret = 0; | ||
667 | struct dentry *entry, *stats, *streaming; | ||
668 | |||
669 | stats = debugfs_create_dir("fw-statistics", rootdir); | ||
670 | if (!stats || IS_ERR(stats)) { | ||
671 | entry = stats; | ||
672 | goto err; | ||
673 | } | ||
674 | |||
675 | DEBUGFS_FWSTATS_ADD(tx, internal_desc_overflow); | ||
676 | |||
677 | DEBUGFS_FWSTATS_ADD(rx, out_of_mem); | ||
678 | DEBUGFS_FWSTATS_ADD(rx, hdr_overflow); | ||
679 | DEBUGFS_FWSTATS_ADD(rx, hw_stuck); | ||
680 | DEBUGFS_FWSTATS_ADD(rx, dropped); | ||
681 | DEBUGFS_FWSTATS_ADD(rx, fcs_err); | ||
682 | DEBUGFS_FWSTATS_ADD(rx, xfr_hint_trig); | ||
683 | DEBUGFS_FWSTATS_ADD(rx, path_reset); | ||
684 | DEBUGFS_FWSTATS_ADD(rx, reset_counter); | ||
685 | |||
686 | DEBUGFS_FWSTATS_ADD(dma, rx_requested); | ||
687 | DEBUGFS_FWSTATS_ADD(dma, rx_errors); | ||
688 | DEBUGFS_FWSTATS_ADD(dma, tx_requested); | ||
689 | DEBUGFS_FWSTATS_ADD(dma, tx_errors); | ||
690 | |||
691 | DEBUGFS_FWSTATS_ADD(isr, cmd_cmplt); | ||
692 | DEBUGFS_FWSTATS_ADD(isr, fiqs); | ||
693 | DEBUGFS_FWSTATS_ADD(isr, rx_headers); | ||
694 | DEBUGFS_FWSTATS_ADD(isr, rx_mem_overflow); | ||
695 | DEBUGFS_FWSTATS_ADD(isr, rx_rdys); | ||
696 | DEBUGFS_FWSTATS_ADD(isr, irqs); | ||
697 | DEBUGFS_FWSTATS_ADD(isr, tx_procs); | ||
698 | DEBUGFS_FWSTATS_ADD(isr, decrypt_done); | ||
699 | DEBUGFS_FWSTATS_ADD(isr, dma0_done); | ||
700 | DEBUGFS_FWSTATS_ADD(isr, dma1_done); | ||
701 | DEBUGFS_FWSTATS_ADD(isr, tx_exch_complete); | ||
702 | DEBUGFS_FWSTATS_ADD(isr, commands); | ||
703 | DEBUGFS_FWSTATS_ADD(isr, rx_procs); | ||
704 | DEBUGFS_FWSTATS_ADD(isr, hw_pm_mode_changes); | ||
705 | DEBUGFS_FWSTATS_ADD(isr, host_acknowledges); | ||
706 | DEBUGFS_FWSTATS_ADD(isr, pci_pm); | ||
707 | DEBUGFS_FWSTATS_ADD(isr, wakeups); | ||
708 | DEBUGFS_FWSTATS_ADD(isr, low_rssi); | ||
709 | |||
710 | DEBUGFS_FWSTATS_ADD(wep, addr_key_count); | ||
711 | DEBUGFS_FWSTATS_ADD(wep, default_key_count); | ||
712 | /* skipping wep.reserved */ | ||
713 | DEBUGFS_FWSTATS_ADD(wep, key_not_found); | ||
714 | DEBUGFS_FWSTATS_ADD(wep, decrypt_fail); | ||
715 | DEBUGFS_FWSTATS_ADD(wep, packets); | ||
716 | DEBUGFS_FWSTATS_ADD(wep, interrupt); | ||
717 | |||
718 | DEBUGFS_FWSTATS_ADD(pwr, ps_enter); | ||
719 | DEBUGFS_FWSTATS_ADD(pwr, elp_enter); | ||
720 | DEBUGFS_FWSTATS_ADD(pwr, missing_bcns); | ||
721 | DEBUGFS_FWSTATS_ADD(pwr, wake_on_host); | ||
722 | DEBUGFS_FWSTATS_ADD(pwr, wake_on_timer_exp); | ||
723 | DEBUGFS_FWSTATS_ADD(pwr, tx_with_ps); | ||
724 | DEBUGFS_FWSTATS_ADD(pwr, tx_without_ps); | ||
725 | DEBUGFS_FWSTATS_ADD(pwr, rcvd_beacons); | ||
726 | DEBUGFS_FWSTATS_ADD(pwr, power_save_off); | ||
727 | DEBUGFS_FWSTATS_ADD(pwr, enable_ps); | ||
728 | DEBUGFS_FWSTATS_ADD(pwr, disable_ps); | ||
729 | DEBUGFS_FWSTATS_ADD(pwr, fix_tsf_ps); | ||
730 | /* skipping cont_miss_bcns_spread for now */ | ||
731 | DEBUGFS_FWSTATS_ADD(pwr, rcvd_awake_beacons); | ||
732 | |||
733 | DEBUGFS_FWSTATS_ADD(mic, rx_pkts); | ||
734 | DEBUGFS_FWSTATS_ADD(mic, calc_failure); | ||
735 | |||
736 | DEBUGFS_FWSTATS_ADD(aes, encrypt_fail); | ||
737 | DEBUGFS_FWSTATS_ADD(aes, decrypt_fail); | ||
738 | DEBUGFS_FWSTATS_ADD(aes, encrypt_packets); | ||
739 | DEBUGFS_FWSTATS_ADD(aes, decrypt_packets); | ||
740 | DEBUGFS_FWSTATS_ADD(aes, encrypt_interrupt); | ||
741 | DEBUGFS_FWSTATS_ADD(aes, decrypt_interrupt); | ||
742 | |||
743 | DEBUGFS_FWSTATS_ADD(event, heart_beat); | ||
744 | DEBUGFS_FWSTATS_ADD(event, calibration); | ||
745 | DEBUGFS_FWSTATS_ADD(event, rx_mismatch); | ||
746 | DEBUGFS_FWSTATS_ADD(event, rx_mem_empty); | ||
747 | DEBUGFS_FWSTATS_ADD(event, rx_pool); | ||
748 | DEBUGFS_FWSTATS_ADD(event, oom_late); | ||
749 | DEBUGFS_FWSTATS_ADD(event, phy_transmit_error); | ||
750 | DEBUGFS_FWSTATS_ADD(event, tx_stuck); | ||
751 | |||
752 | DEBUGFS_FWSTATS_ADD(ps, pspoll_timeouts); | ||
753 | DEBUGFS_FWSTATS_ADD(ps, upsd_timeouts); | ||
754 | DEBUGFS_FWSTATS_ADD(ps, upsd_max_sptime); | ||
755 | DEBUGFS_FWSTATS_ADD(ps, upsd_max_apturn); | ||
756 | DEBUGFS_FWSTATS_ADD(ps, pspoll_max_apturn); | ||
757 | DEBUGFS_FWSTATS_ADD(ps, pspoll_utilization); | ||
758 | DEBUGFS_FWSTATS_ADD(ps, upsd_utilization); | ||
759 | |||
760 | DEBUGFS_FWSTATS_ADD(rxpipe, rx_prep_beacon_drop); | ||
761 | DEBUGFS_FWSTATS_ADD(rxpipe, descr_host_int_trig_rx_data); | ||
762 | DEBUGFS_FWSTATS_ADD(rxpipe, beacon_buffer_thres_host_int_trig_rx_data); | ||
763 | DEBUGFS_FWSTATS_ADD(rxpipe, missed_beacon_host_int_trig_rx_data); | ||
764 | DEBUGFS_FWSTATS_ADD(rxpipe, tx_xfr_host_int_trig_rx_data); | ||
765 | |||
766 | DEBUGFS_ADD(tx_queue_len, rootdir); | ||
767 | DEBUGFS_ADD(retry_count, rootdir); | ||
768 | DEBUGFS_ADD(excessive_retries, rootdir); | ||
769 | |||
770 | DEBUGFS_ADD(gpio_power, rootdir); | ||
771 | DEBUGFS_ADD(start_recovery, rootdir); | ||
772 | DEBUGFS_ADD(driver_state, rootdir); | ||
773 | DEBUGFS_ADD(dtim_interval, rootdir); | ||
774 | DEBUGFS_ADD(beacon_interval, rootdir); | ||
775 | |||
776 | streaming = debugfs_create_dir("rx_streaming", rootdir); | ||
777 | if (!streaming || IS_ERR(streaming)) | ||
778 | goto err; | ||
779 | |||
780 | DEBUGFS_ADD_PREFIX(rx_streaming, interval, streaming); | ||
781 | DEBUGFS_ADD_PREFIX(rx_streaming, always, streaming); | ||
782 | |||
783 | |||
784 | return 0; | ||
785 | |||
786 | err: | ||
787 | if (IS_ERR(entry)) | ||
788 | ret = PTR_ERR(entry); | ||
789 | else | ||
790 | ret = -ENOMEM; | ||
791 | |||
792 | return ret; | ||
793 | } | ||
794 | |||
795 | void wl1271_debugfs_reset(struct wl1271 *wl) | ||
796 | { | ||
797 | if (!wl->stats.fw_stats) | ||
798 | return; | ||
799 | |||
800 | memset(wl->stats.fw_stats, 0, sizeof(*wl->stats.fw_stats)); | ||
801 | wl->stats.retry_count = 0; | ||
802 | wl->stats.excessive_retries = 0; | ||
803 | } | ||
804 | |||
805 | int wl1271_debugfs_init(struct wl1271 *wl) | ||
806 | { | ||
807 | int ret; | ||
808 | struct dentry *rootdir; | ||
809 | |||
810 | rootdir = debugfs_create_dir(KBUILD_MODNAME, | ||
811 | wl->hw->wiphy->debugfsdir); | ||
812 | |||
813 | if (IS_ERR(rootdir)) { | ||
814 | ret = PTR_ERR(rootdir); | ||
815 | goto err; | ||
816 | } | ||
817 | |||
818 | wl->stats.fw_stats = kzalloc(sizeof(*wl->stats.fw_stats), | ||
819 | GFP_KERNEL); | ||
820 | |||
821 | if (!wl->stats.fw_stats) { | ||
822 | ret = -ENOMEM; | ||
823 | goto err_fw; | ||
824 | } | ||
825 | |||
826 | wl->stats.fw_stats_update = jiffies; | ||
827 | |||
828 | ret = wl1271_debugfs_add_files(wl, rootdir); | ||
829 | |||
830 | if (ret < 0) | ||
831 | goto err_file; | ||
832 | |||
833 | return 0; | ||
834 | |||
835 | err_file: | ||
836 | kfree(wl->stats.fw_stats); | ||
837 | wl->stats.fw_stats = NULL; | ||
838 | |||
839 | err_fw: | ||
840 | debugfs_remove_recursive(rootdir); | ||
841 | |||
842 | err: | ||
843 | return ret; | ||
844 | } | ||
845 | |||
846 | void wl1271_debugfs_exit(struct wl1271 *wl) | ||
847 | { | ||
848 | kfree(wl->stats.fw_stats); | ||
849 | wl->stats.fw_stats = NULL; | ||
850 | } | ||
diff --git a/drivers/net/wireless/wl12xx/debugfs.h b/drivers/net/wireless/wl12xx/debugfs.h new file mode 100644 index 00000000000..254c5b292cf --- /dev/null +++ b/drivers/net/wireless/wl12xx/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 "wl12xx.h" | ||
28 | |||
29 | int wl1271_debugfs_init(struct wl1271 *wl); | ||
30 | void wl1271_debugfs_exit(struct wl1271 *wl); | ||
31 | void wl1271_debugfs_reset(struct wl1271 *wl); | ||
32 | |||
33 | #endif /* WL1271_DEBUGFS_H */ | ||
diff --git a/drivers/net/wireless/wl12xx/event.c b/drivers/net/wireless/wl12xx/event.c new file mode 100644 index 00000000000..304aaa2ee01 --- /dev/null +++ b/drivers/net/wireless/wl12xx/event.c | |||
@@ -0,0 +1,389 @@ | |||
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 "wl12xx.h" | ||
25 | #include "reg.h" | ||
26 | #include "io.h" | ||
27 | #include "event.h" | ||
28 | #include "ps.h" | ||
29 | #include "scan.h" | ||
30 | #include "wl12xx_80211.h" | ||
31 | |||
32 | void wl1271_pspoll_work(struct work_struct *work) | ||
33 | { | ||
34 | struct delayed_work *dwork; | ||
35 | struct wl1271 *wl; | ||
36 | int ret; | ||
37 | |||
38 | dwork = container_of(work, struct delayed_work, work); | ||
39 | wl = container_of(dwork, struct wl1271, pspoll_work); | ||
40 | |||
41 | wl1271_debug(DEBUG_EVENT, "pspoll work"); | ||
42 | |||
43 | mutex_lock(&wl->mutex); | ||
44 | |||
45 | if (unlikely(wl->state == WL1271_STATE_OFF)) | ||
46 | goto out; | ||
47 | |||
48 | if (!test_and_clear_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags)) | ||
49 | goto out; | ||
50 | |||
51 | if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) | ||
52 | goto out; | ||
53 | |||
54 | /* | ||
55 | * if we end up here, then we were in powersave when the pspoll | ||
56 | * delivery failure occurred, and no-one changed state since, so | ||
57 | * we should go back to powersave. | ||
58 | */ | ||
59 | ret = wl1271_ps_elp_wakeup(wl); | ||
60 | if (ret < 0) | ||
61 | goto out; | ||
62 | |||
63 | wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE, wl->basic_rate, true); | ||
64 | |||
65 | wl1271_ps_elp_sleep(wl); | ||
66 | out: | ||
67 | mutex_unlock(&wl->mutex); | ||
68 | }; | ||
69 | |||
70 | static void wl1271_event_pspoll_delivery_fail(struct wl1271 *wl) | ||
71 | { | ||
72 | int delay = wl->conf.conn.ps_poll_recovery_period; | ||
73 | int ret; | ||
74 | |||
75 | wl->ps_poll_failures++; | ||
76 | if (wl->ps_poll_failures == 1) | ||
77 | wl1271_info("AP with dysfunctional ps-poll, " | ||
78 | "trying to work around it."); | ||
79 | |||
80 | /* force active mode receive data from the AP */ | ||
81 | if (test_bit(WL1271_FLAG_PSM, &wl->flags)) { | ||
82 | ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE, | ||
83 | wl->basic_rate, true); | ||
84 | if (ret < 0) | ||
85 | return; | ||
86 | set_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags); | ||
87 | ieee80211_queue_delayed_work(wl->hw, &wl->pspoll_work, | ||
88 | msecs_to_jiffies(delay)); | ||
89 | } | ||
90 | |||
91 | /* | ||
92 | * If already in active mode, lets we should be getting data from | ||
93 | * the AP right away. If we enter PSM too fast after this, and data | ||
94 | * remains on the AP, we will get another event like this, and we'll | ||
95 | * go into active once more. | ||
96 | */ | ||
97 | } | ||
98 | |||
99 | static int wl1271_event_ps_report(struct wl1271 *wl, | ||
100 | struct event_mailbox *mbox, | ||
101 | bool *beacon_loss) | ||
102 | { | ||
103 | int ret = 0; | ||
104 | u32 total_retries = wl->conf.conn.psm_entry_retries; | ||
105 | |||
106 | wl1271_debug(DEBUG_EVENT, "ps_status: 0x%x", mbox->ps_status); | ||
107 | |||
108 | switch (mbox->ps_status) { | ||
109 | case EVENT_ENTER_POWER_SAVE_FAIL: | ||
110 | wl1271_debug(DEBUG_PSM, "PSM entry failed"); | ||
111 | |||
112 | if (!test_bit(WL1271_FLAG_PSM, &wl->flags)) { | ||
113 | /* remain in active mode */ | ||
114 | wl->psm_entry_retry = 0; | ||
115 | break; | ||
116 | } | ||
117 | |||
118 | if (wl->psm_entry_retry < total_retries) { | ||
119 | wl->psm_entry_retry++; | ||
120 | ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE, | ||
121 | wl->basic_rate, true); | ||
122 | } else { | ||
123 | wl1271_info("No ack to nullfunc from AP."); | ||
124 | wl->psm_entry_retry = 0; | ||
125 | *beacon_loss = true; | ||
126 | } | ||
127 | break; | ||
128 | case EVENT_ENTER_POWER_SAVE_SUCCESS: | ||
129 | wl->psm_entry_retry = 0; | ||
130 | |||
131 | /* enable beacon filtering */ | ||
132 | ret = wl1271_acx_beacon_filter_opt(wl, true); | ||
133 | if (ret < 0) | ||
134 | break; | ||
135 | |||
136 | /* | ||
137 | * BET has only a minor effect in 5GHz and masks | ||
138 | * channel switch IEs, so we only enable BET on 2.4GHz | ||
139 | */ | ||
140 | if (wl->band == IEEE80211_BAND_2GHZ) | ||
141 | /* enable beacon early termination */ | ||
142 | ret = wl1271_acx_bet_enable(wl, true); | ||
143 | |||
144 | if (wl->ps_compl) { | ||
145 | complete(wl->ps_compl); | ||
146 | wl->ps_compl = NULL; | ||
147 | } | ||
148 | break; | ||
149 | default: | ||
150 | break; | ||
151 | } | ||
152 | |||
153 | return ret; | ||
154 | } | ||
155 | |||
156 | static void wl1271_event_rssi_trigger(struct wl1271 *wl, | ||
157 | struct event_mailbox *mbox) | ||
158 | { | ||
159 | enum nl80211_cqm_rssi_threshold_event event; | ||
160 | s8 metric = mbox->rssi_snr_trigger_metric[0]; | ||
161 | |||
162 | wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric); | ||
163 | |||
164 | if (metric <= wl->rssi_thold) | ||
165 | event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW; | ||
166 | else | ||
167 | event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH; | ||
168 | |||
169 | if (event != wl->last_rssi_event) | ||
170 | ieee80211_cqm_rssi_notify(wl->vif, event, GFP_KERNEL); | ||
171 | wl->last_rssi_event = event; | ||
172 | } | ||
173 | |||
174 | static void wl1271_stop_ba_event(struct wl1271 *wl, u8 ba_allowed) | ||
175 | { | ||
176 | /* Convert the value to bool */ | ||
177 | wl->ba_allowed = !!ba_allowed; | ||
178 | |||
179 | /* | ||
180 | * Return in case: | ||
181 | * there are not BA open or the event indication is to allowed BA | ||
182 | */ | ||
183 | if ((!wl->ba_rx_bitmap) || (wl->ba_allowed)) | ||
184 | return; | ||
185 | |||
186 | ieee80211_stop_rx_ba_session(wl->vif, wl->ba_rx_bitmap, wl->bssid); | ||
187 | } | ||
188 | |||
189 | static void wl12xx_event_soft_gemini_sense(struct wl1271 *wl, | ||
190 | u8 enable) | ||
191 | { | ||
192 | if (enable) { | ||
193 | /* disable dynamic PS when requested by the firmware */ | ||
194 | ieee80211_disable_dyn_ps(wl->vif); | ||
195 | set_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags); | ||
196 | } else { | ||
197 | ieee80211_enable_dyn_ps(wl->vif); | ||
198 | clear_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags); | ||
199 | wl1271_recalc_rx_streaming(wl); | ||
200 | } | ||
201 | |||
202 | } | ||
203 | |||
204 | static void wl1271_event_mbox_dump(struct event_mailbox *mbox) | ||
205 | { | ||
206 | wl1271_debug(DEBUG_EVENT, "MBOX DUMP:"); | ||
207 | wl1271_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector); | ||
208 | wl1271_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask); | ||
209 | } | ||
210 | |||
211 | static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox) | ||
212 | { | ||
213 | int ret; | ||
214 | u32 vector; | ||
215 | bool beacon_loss = false; | ||
216 | bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS); | ||
217 | bool disconnect_sta = false; | ||
218 | unsigned long sta_bitmap = 0; | ||
219 | |||
220 | wl1271_event_mbox_dump(mbox); | ||
221 | |||
222 | vector = le32_to_cpu(mbox->events_vector); | ||
223 | vector &= ~(le32_to_cpu(mbox->events_mask)); | ||
224 | wl1271_debug(DEBUG_EVENT, "vector: 0x%x", vector); | ||
225 | |||
226 | if (vector & SCAN_COMPLETE_EVENT_ID) { | ||
227 | wl1271_debug(DEBUG_EVENT, "status: 0x%x", | ||
228 | mbox->scheduled_scan_status); | ||
229 | |||
230 | wl1271_scan_stm(wl); | ||
231 | } | ||
232 | |||
233 | if (vector & PERIODIC_SCAN_REPORT_EVENT_ID) { | ||
234 | wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_REPORT_EVENT " | ||
235 | "(status 0x%0x)", mbox->scheduled_scan_status); | ||
236 | |||
237 | wl1271_scan_sched_scan_results(wl); | ||
238 | } | ||
239 | |||
240 | if (vector & PERIODIC_SCAN_COMPLETE_EVENT_ID) { | ||
241 | wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_COMPLETE_EVENT " | ||
242 | "(status 0x%0x)", mbox->scheduled_scan_status); | ||
243 | if (wl->sched_scanning) { | ||
244 | wl1271_scan_sched_scan_stop(wl); | ||
245 | ieee80211_sched_scan_stopped(wl->hw); | ||
246 | } | ||
247 | } | ||
248 | |||
249 | if (vector & SOFT_GEMINI_SENSE_EVENT_ID && | ||
250 | wl->bss_type == BSS_TYPE_STA_BSS) | ||
251 | wl12xx_event_soft_gemini_sense(wl, | ||
252 | mbox->soft_gemini_sense_info); | ||
253 | |||
254 | /* | ||
255 | * The BSS_LOSE_EVENT_ID is only needed while psm (and hence beacon | ||
256 | * filtering) is enabled. Without PSM, the stack will receive all | ||
257 | * beacons and can detect beacon loss by itself. | ||
258 | * | ||
259 | * As there's possibility that the driver disables PSM before receiving | ||
260 | * BSS_LOSE_EVENT, beacon loss has to be reported to the stack. | ||
261 | * | ||
262 | */ | ||
263 | if ((vector & BSS_LOSE_EVENT_ID) && !is_ap) { | ||
264 | wl1271_info("Beacon loss detected."); | ||
265 | |||
266 | /* indicate to the stack, that beacons have been lost */ | ||
267 | beacon_loss = true; | ||
268 | } | ||
269 | |||
270 | if ((vector & PS_REPORT_EVENT_ID) && !is_ap) { | ||
271 | wl1271_debug(DEBUG_EVENT, "PS_REPORT_EVENT"); | ||
272 | ret = wl1271_event_ps_report(wl, mbox, &beacon_loss); | ||
273 | if (ret < 0) | ||
274 | return ret; | ||
275 | } | ||
276 | |||
277 | if ((vector & PSPOLL_DELIVERY_FAILURE_EVENT_ID) && !is_ap) | ||
278 | wl1271_event_pspoll_delivery_fail(wl); | ||
279 | |||
280 | if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) { | ||
281 | wl1271_debug(DEBUG_EVENT, "RSSI_SNR_TRIGGER_0_EVENT"); | ||
282 | if (wl->vif) | ||
283 | wl1271_event_rssi_trigger(wl, mbox); | ||
284 | } | ||
285 | |||
286 | if ((vector & BA_SESSION_RX_CONSTRAINT_EVENT_ID) && !is_ap) { | ||
287 | wl1271_debug(DEBUG_EVENT, "BA_SESSION_RX_CONSTRAINT_EVENT_ID. " | ||
288 | "ba_allowed = 0x%x", mbox->ba_allowed); | ||
289 | |||
290 | if (wl->vif) | ||
291 | wl1271_stop_ba_event(wl, mbox->ba_allowed); | ||
292 | } | ||
293 | |||
294 | if ((vector & DUMMY_PACKET_EVENT_ID) && !is_ap) { | ||
295 | wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID"); | ||
296 | if (wl->vif) | ||
297 | wl1271_tx_dummy_packet(wl); | ||
298 | } | ||
299 | |||
300 | /* | ||
301 | * "TX retries exceeded" has a different meaning according to mode. | ||
302 | * In AP mode the offending station is disconnected. | ||
303 | */ | ||
304 | if ((vector & MAX_TX_RETRY_EVENT_ID) && is_ap) { | ||
305 | wl1271_debug(DEBUG_EVENT, "MAX_TX_RETRY_EVENT_ID"); | ||
306 | sta_bitmap |= le16_to_cpu(mbox->sta_tx_retry_exceeded); | ||
307 | disconnect_sta = true; | ||
308 | } | ||
309 | |||
310 | if ((vector & INACTIVE_STA_EVENT_ID) && is_ap) { | ||
311 | wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID"); | ||
312 | sta_bitmap |= le16_to_cpu(mbox->sta_aging_status); | ||
313 | disconnect_sta = true; | ||
314 | } | ||
315 | |||
316 | if (is_ap && disconnect_sta) { | ||
317 | u32 num_packets = wl->conf.tx.max_tx_retries; | ||
318 | struct ieee80211_sta *sta; | ||
319 | const u8 *addr; | ||
320 | int h; | ||
321 | |||
322 | for (h = find_first_bit(&sta_bitmap, AP_MAX_LINKS); | ||
323 | h < AP_MAX_LINKS; | ||
324 | h = find_next_bit(&sta_bitmap, AP_MAX_LINKS, h+1)) { | ||
325 | if (!wl1271_is_active_sta(wl, h)) | ||
326 | continue; | ||
327 | |||
328 | addr = wl->links[h].addr; | ||
329 | |||
330 | rcu_read_lock(); | ||
331 | sta = ieee80211_find_sta(wl->vif, addr); | ||
332 | if (sta) { | ||
333 | wl1271_debug(DEBUG_EVENT, "remove sta %d", h); | ||
334 | ieee80211_report_low_ack(sta, num_packets); | ||
335 | } | ||
336 | rcu_read_unlock(); | ||
337 | } | ||
338 | } | ||
339 | |||
340 | if (wl->vif && beacon_loss) | ||
341 | ieee80211_connection_loss(wl->vif); | ||
342 | |||
343 | return 0; | ||
344 | } | ||
345 | |||
346 | int wl1271_event_unmask(struct wl1271 *wl) | ||
347 | { | ||
348 | int ret; | ||
349 | |||
350 | ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask)); | ||
351 | if (ret < 0) | ||
352 | return ret; | ||
353 | |||
354 | return 0; | ||
355 | } | ||
356 | |||
357 | void wl1271_event_mbox_config(struct wl1271 *wl) | ||
358 | { | ||
359 | wl->mbox_ptr[0] = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR); | ||
360 | wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox); | ||
361 | |||
362 | wl1271_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x", | ||
363 | wl->mbox_ptr[0], wl->mbox_ptr[1]); | ||
364 | } | ||
365 | |||
366 | int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num) | ||
367 | { | ||
368 | struct event_mailbox mbox; | ||
369 | int ret; | ||
370 | |||
371 | wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num); | ||
372 | |||
373 | if (mbox_num > 1) | ||
374 | return -EINVAL; | ||
375 | |||
376 | /* first we read the mbox descriptor */ | ||
377 | wl1271_read(wl, wl->mbox_ptr[mbox_num], &mbox, | ||
378 | sizeof(struct event_mailbox), false); | ||
379 | |||
380 | /* process the descriptor */ | ||
381 | ret = wl1271_event_process(wl, &mbox); | ||
382 | if (ret < 0) | ||
383 | return ret; | ||
384 | |||
385 | /* then we let the firmware know it can go on...*/ | ||
386 | wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK); | ||
387 | |||
388 | return 0; | ||
389 | } | ||
diff --git a/drivers/net/wireless/wl12xx/event.h b/drivers/net/wireless/wl12xx/event.h new file mode 100644 index 00000000000..e524ad6fe4e --- /dev/null +++ b/drivers/net/wireless/wl12xx/event.h | |||
@@ -0,0 +1,156 @@ | |||
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 | |||
40 | enum { | ||
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 | SCHEDULED_SCAN_COMPLETE_EVENT_ID = BIT(11), | ||
53 | AP_DISCOVERY_COMPLETE_EVENT_ID = BIT(12), | ||
54 | PS_REPORT_EVENT_ID = BIT(13), | ||
55 | PSPOLL_DELIVERY_FAILURE_EVENT_ID = BIT(14), | ||
56 | DISCONNECT_EVENT_COMPLETE_ID = BIT(15), | ||
57 | JOIN_EVENT_COMPLETE_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 | /* STA: dummy paket for dynamic mem blocks */ | ||
63 | DUMMY_PACKET_EVENT_ID = BIT(21), | ||
64 | /* AP: STA remove complete */ | ||
65 | STA_REMOVE_COMPLETE_EVENT_ID = BIT(21), | ||
66 | SOFT_GEMINI_SENSE_EVENT_ID = BIT(22), | ||
67 | /* STA: SG prediction */ | ||
68 | SOFT_GEMINI_PREDICTION_EVENT_ID = BIT(23), | ||
69 | /* AP: Inactive STA */ | ||
70 | INACTIVE_STA_EVENT_ID = BIT(23), | ||
71 | SOFT_GEMINI_AVALANCHE_EVENT_ID = BIT(24), | ||
72 | PLT_RX_CALIBRATION_COMPLETE_EVENT_ID = BIT(25), | ||
73 | DBG_EVENT_ID = BIT(26), | ||
74 | HEALTH_CHECK_REPLY_EVENT_ID = BIT(27), | ||
75 | PERIODIC_SCAN_COMPLETE_EVENT_ID = BIT(28), | ||
76 | PERIODIC_SCAN_REPORT_EVENT_ID = BIT(29), | ||
77 | BA_SESSION_RX_CONSTRAINT_EVENT_ID = BIT(30), | ||
78 | EVENT_MBOX_ALL_EVENT_ID = 0x7fffffff, | ||
79 | }; | ||
80 | |||
81 | enum { | ||
82 | EVENT_ENTER_POWER_SAVE_FAIL = 0, | ||
83 | EVENT_ENTER_POWER_SAVE_SUCCESS, | ||
84 | }; | ||
85 | |||
86 | struct event_debug_report { | ||
87 | u8 debug_event_id; | ||
88 | u8 num_params; | ||
89 | __le16 pad; | ||
90 | __le32 report_1; | ||
91 | __le32 report_2; | ||
92 | __le32 report_3; | ||
93 | } __packed; | ||
94 | |||
95 | #define NUM_OF_RSSI_SNR_TRIGGERS 8 | ||
96 | |||
97 | struct event_mailbox { | ||
98 | __le32 events_vector; | ||
99 | __le32 events_mask; | ||
100 | __le32 reserved_1; | ||
101 | __le32 reserved_2; | ||
102 | |||
103 | u8 dbg_event_id; | ||
104 | u8 num_relevant_params; | ||
105 | __le16 reserved_3; | ||
106 | __le32 event_report_p1; | ||
107 | __le32 event_report_p2; | ||
108 | __le32 event_report_p3; | ||
109 | |||
110 | u8 number_of_scan_results; | ||
111 | u8 scan_tag; | ||
112 | u8 reserved_4[2]; | ||
113 | __le32 compl_scheduled_scan_status; | ||
114 | |||
115 | __le16 scheduled_scan_attended_channels; | ||
116 | u8 soft_gemini_sense_info; | ||
117 | u8 soft_gemini_protective_info; | ||
118 | s8 rssi_snr_trigger_metric[NUM_OF_RSSI_SNR_TRIGGERS]; | ||
119 | u8 channel_switch_status; | ||
120 | u8 scheduled_scan_status; | ||
121 | u8 ps_status; | ||
122 | |||
123 | /* AP FW only */ | ||
124 | u8 hlid_removed; | ||
125 | |||
126 | /* a bitmap of hlids for stations that have been inactive too long */ | ||
127 | __le16 sta_aging_status; | ||
128 | |||
129 | /* a bitmap of hlids for stations which didn't respond to TX */ | ||
130 | __le16 sta_tx_retry_exceeded; | ||
131 | |||
132 | /* | ||
133 | * Bitmap, Each bit set represents the Role ID for which this constraint | ||
134 | * is set. Range: 0 - FF, FF means ANY role | ||
135 | */ | ||
136 | u8 ba_role_id; | ||
137 | /* | ||
138 | * Bitmap, Each bit set represents the Link ID for which this constraint | ||
139 | * is set. Not applicable if ba_role_id is set to ANY role (FF). | ||
140 | * Range: 0 - FFFF, FFFF means ANY link in that role | ||
141 | */ | ||
142 | u8 ba_link_id; | ||
143 | u8 ba_allowed; | ||
144 | |||
145 | u8 reserved_5[21]; | ||
146 | } __packed; | ||
147 | |||
148 | int wl1271_event_unmask(struct wl1271 *wl); | ||
149 | void wl1271_event_mbox_config(struct wl1271 *wl); | ||
150 | int wl1271_event_handle(struct wl1271 *wl, u8 mbox); | ||
151 | void wl1271_pspoll_work(struct work_struct *work); | ||
152 | |||
153 | /* Functions from main.c */ | ||
154 | bool wl1271_is_active_sta(struct wl1271 *wl, u8 hlid); | ||
155 | |||
156 | #endif | ||
diff --git a/drivers/net/wireless/wl12xx/ini.h b/drivers/net/wireless/wl12xx/ini.h new file mode 100644 index 00000000000..4cf9ecc5621 --- /dev/null +++ b/drivers/net/wireless/wl12xx/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 | |||
32 | struct 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 | |||
49 | struct 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 | |||
71 | struct 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 | |||
79 | struct 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 | |||
87 | struct 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 | |||
107 | struct 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 | |||
128 | struct 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 | |||
134 | struct 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 | |||
140 | struct 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 | |||
155 | struct 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 | |||
179 | struct 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 | |||
200 | struct 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/wl12xx/init.c b/drivers/net/wireless/wl12xx/init.c new file mode 100644 index 00000000000..c3e9a2e4410 --- /dev/null +++ b/drivers/net/wireless/wl12xx/init.c | |||
@@ -0,0 +1,748 @@ | |||
1 | /* | ||
2 | * This file is part of wl1271 | ||
3 | * | ||
4 | * Copyright (C) 2009 Nokia Corporation | ||
5 | * | ||
6 | * Contact: Luciano Coelho <luciano.coelho@nokia.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU General Public License | ||
10 | * version 2 as published by the Free Software Foundation. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, but | ||
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
20 | * 02110-1301 USA | ||
21 | * | ||
22 | */ | ||
23 | |||
24 | #include <linux/kernel.h> | ||
25 | #include <linux/module.h> | ||
26 | #include <linux/slab.h> | ||
27 | |||
28 | #include "init.h" | ||
29 | #include "wl12xx_80211.h" | ||
30 | #include "acx.h" | ||
31 | #include "cmd.h" | ||
32 | #include "reg.h" | ||
33 | #include "tx.h" | ||
34 | #include "io.h" | ||
35 | |||
36 | int wl1271_sta_init_templates_config(struct wl1271 *wl) | ||
37 | { | ||
38 | int ret, i; | ||
39 | |||
40 | /* send empty templates for fw memory reservation */ | ||
41 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, NULL, | ||
42 | WL1271_CMD_TEMPL_MAX_SIZE, | ||
43 | 0, WL1271_RATE_AUTOMATIC); | ||
44 | if (ret < 0) | ||
45 | return ret; | ||
46 | |||
47 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5, | ||
48 | NULL, WL1271_CMD_TEMPL_MAX_SIZE, 0, | ||
49 | WL1271_RATE_AUTOMATIC); | ||
50 | if (ret < 0) | ||
51 | return ret; | ||
52 | |||
53 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL, | ||
54 | sizeof(struct wl12xx_null_data_template), | ||
55 | 0, WL1271_RATE_AUTOMATIC); | ||
56 | if (ret < 0) | ||
57 | return ret; | ||
58 | |||
59 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, NULL, | ||
60 | sizeof(struct wl12xx_ps_poll_template), | ||
61 | 0, WL1271_RATE_AUTOMATIC); | ||
62 | if (ret < 0) | ||
63 | return ret; | ||
64 | |||
65 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL, | ||
66 | sizeof | ||
67 | (struct wl12xx_qos_null_data_template), | ||
68 | 0, WL1271_RATE_AUTOMATIC); | ||
69 | if (ret < 0) | ||
70 | return ret; | ||
71 | |||
72 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE, NULL, | ||
73 | sizeof | ||
74 | (struct wl12xx_probe_resp_template), | ||
75 | 0, WL1271_RATE_AUTOMATIC); | ||
76 | if (ret < 0) | ||
77 | return ret; | ||
78 | |||
79 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON, NULL, | ||
80 | sizeof | ||
81 | (struct wl12xx_beacon_template), | ||
82 | 0, WL1271_RATE_AUTOMATIC); | ||
83 | if (ret < 0) | ||
84 | return ret; | ||
85 | |||
86 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_ARP_RSP, NULL, | ||
87 | sizeof | ||
88 | (struct wl12xx_arp_rsp_template), | ||
89 | 0, WL1271_RATE_AUTOMATIC); | ||
90 | if (ret < 0) | ||
91 | return ret; | ||
92 | |||
93 | for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) { | ||
94 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV, NULL, | ||
95 | WL1271_CMD_TEMPL_MAX_SIZE, i, | ||
96 | WL1271_RATE_AUTOMATIC); | ||
97 | if (ret < 0) | ||
98 | return ret; | ||
99 | } | ||
100 | |||
101 | return 0; | ||
102 | } | ||
103 | |||
104 | static int wl1271_ap_init_deauth_template(struct wl1271 *wl) | ||
105 | { | ||
106 | struct wl12xx_disconn_template *tmpl; | ||
107 | int ret; | ||
108 | |||
109 | tmpl = kzalloc(sizeof(*tmpl), GFP_KERNEL); | ||
110 | if (!tmpl) { | ||
111 | ret = -ENOMEM; | ||
112 | goto out; | ||
113 | } | ||
114 | |||
115 | tmpl->header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT | | ||
116 | IEEE80211_STYPE_DEAUTH); | ||
117 | |||
118 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP, | ||
119 | tmpl, sizeof(*tmpl), 0, | ||
120 | wl1271_tx_min_rate_get(wl)); | ||
121 | |||
122 | out: | ||
123 | kfree(tmpl); | ||
124 | return ret; | ||
125 | } | ||
126 | |||
127 | static int wl1271_ap_init_null_template(struct wl1271 *wl) | ||
128 | { | ||
129 | struct ieee80211_hdr_3addr *nullfunc; | ||
130 | int ret; | ||
131 | |||
132 | nullfunc = kzalloc(sizeof(*nullfunc), GFP_KERNEL); | ||
133 | if (!nullfunc) { | ||
134 | ret = -ENOMEM; | ||
135 | goto out; | ||
136 | } | ||
137 | |||
138 | nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | | ||
139 | IEEE80211_STYPE_NULLFUNC | | ||
140 | IEEE80211_FCTL_FROMDS); | ||
141 | |||
142 | /* nullfunc->addr1 is filled by FW */ | ||
143 | |||
144 | memcpy(nullfunc->addr2, wl->mac_addr, ETH_ALEN); | ||
145 | memcpy(nullfunc->addr3, wl->mac_addr, ETH_ALEN); | ||
146 | |||
147 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, nullfunc, | ||
148 | sizeof(*nullfunc), 0, | ||
149 | wl1271_tx_min_rate_get(wl)); | ||
150 | |||
151 | out: | ||
152 | kfree(nullfunc); | ||
153 | return ret; | ||
154 | } | ||
155 | |||
156 | static int wl1271_ap_init_qos_null_template(struct wl1271 *wl) | ||
157 | { | ||
158 | struct ieee80211_qos_hdr *qosnull; | ||
159 | int ret; | ||
160 | |||
161 | qosnull = kzalloc(sizeof(*qosnull), GFP_KERNEL); | ||
162 | if (!qosnull) { | ||
163 | ret = -ENOMEM; | ||
164 | goto out; | ||
165 | } | ||
166 | |||
167 | qosnull->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | | ||
168 | IEEE80211_STYPE_QOS_NULLFUNC | | ||
169 | IEEE80211_FCTL_FROMDS); | ||
170 | |||
171 | /* qosnull->addr1 is filled by FW */ | ||
172 | |||
173 | memcpy(qosnull->addr2, wl->mac_addr, ETH_ALEN); | ||
174 | memcpy(qosnull->addr3, wl->mac_addr, ETH_ALEN); | ||
175 | |||
176 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, qosnull, | ||
177 | sizeof(*qosnull), 0, | ||
178 | wl1271_tx_min_rate_get(wl)); | ||
179 | |||
180 | out: | ||
181 | kfree(qosnull); | ||
182 | return ret; | ||
183 | } | ||
184 | |||
185 | static int wl1271_ap_init_templates_config(struct wl1271 *wl) | ||
186 | { | ||
187 | int ret; | ||
188 | |||
189 | /* | ||
190 | * Put very large empty placeholders for all templates. These | ||
191 | * reserve memory for later. | ||
192 | */ | ||
193 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_PROBE_RESPONSE, NULL, | ||
194 | sizeof | ||
195 | (struct wl12xx_probe_resp_template), | ||
196 | 0, WL1271_RATE_AUTOMATIC); | ||
197 | if (ret < 0) | ||
198 | return ret; | ||
199 | |||
200 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_BEACON, NULL, | ||
201 | sizeof | ||
202 | (struct wl12xx_beacon_template), | ||
203 | 0, WL1271_RATE_AUTOMATIC); | ||
204 | if (ret < 0) | ||
205 | return ret; | ||
206 | |||
207 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP, NULL, | ||
208 | sizeof | ||
209 | (struct wl12xx_disconn_template), | ||
210 | 0, WL1271_RATE_AUTOMATIC); | ||
211 | if (ret < 0) | ||
212 | return ret; | ||
213 | |||
214 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL, | ||
215 | sizeof(struct wl12xx_null_data_template), | ||
216 | 0, WL1271_RATE_AUTOMATIC); | ||
217 | if (ret < 0) | ||
218 | return ret; | ||
219 | |||
220 | ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL, | ||
221 | sizeof | ||
222 | (struct wl12xx_qos_null_data_template), | ||
223 | 0, WL1271_RATE_AUTOMATIC); | ||
224 | if (ret < 0) | ||
225 | return ret; | ||
226 | |||
227 | return 0; | ||
228 | } | ||
229 | |||
230 | static int wl1271_init_rx_config(struct wl1271 *wl, u32 config, u32 filter) | ||
231 | { | ||
232 | int ret; | ||
233 | |||
234 | ret = wl1271_acx_rx_msdu_life_time(wl); | ||
235 | if (ret < 0) | ||
236 | return ret; | ||
237 | |||
238 | ret = wl1271_acx_rx_config(wl, config, filter); | ||
239 | if (ret < 0) | ||
240 | return ret; | ||
241 | |||
242 | return 0; | ||
243 | } | ||
244 | |||
245 | int wl1271_init_phy_config(struct wl1271 *wl) | ||
246 | { | ||
247 | int ret; | ||
248 | |||
249 | ret = wl1271_acx_pd_threshold(wl); | ||
250 | if (ret < 0) | ||
251 | return ret; | ||
252 | |||
253 | ret = wl1271_acx_slot(wl, DEFAULT_SLOT_TIME); | ||
254 | if (ret < 0) | ||
255 | return ret; | ||
256 | |||
257 | ret = wl1271_acx_service_period_timeout(wl); | ||
258 | if (ret < 0) | ||
259 | return ret; | ||
260 | |||
261 | ret = wl1271_acx_rts_threshold(wl, wl->hw->wiphy->rts_threshold); | ||
262 | if (ret < 0) | ||
263 | return ret; | ||
264 | |||
265 | return 0; | ||
266 | } | ||
267 | |||
268 | static int wl1271_init_beacon_filter(struct wl1271 *wl) | ||
269 | { | ||
270 | int ret; | ||
271 | |||
272 | /* disable beacon filtering at this stage */ | ||
273 | ret = wl1271_acx_beacon_filter_opt(wl, false); | ||
274 | if (ret < 0) | ||
275 | return ret; | ||
276 | |||
277 | ret = wl1271_acx_beacon_filter_table(wl); | ||
278 | if (ret < 0) | ||
279 | return ret; | ||
280 | |||
281 | return 0; | ||
282 | } | ||
283 | |||
284 | int wl1271_init_pta(struct wl1271 *wl) | ||
285 | { | ||
286 | int ret; | ||
287 | |||
288 | if (wl->bss_type == BSS_TYPE_AP_BSS) | ||
289 | ret = wl1271_acx_ap_sg_cfg(wl); | ||
290 | else | ||
291 | ret = wl1271_acx_sta_sg_cfg(wl); | ||
292 | if (ret < 0) | ||
293 | return ret; | ||
294 | |||
295 | ret = wl1271_acx_sg_enable(wl, wl->sg_enabled); | ||
296 | if (ret < 0) | ||
297 | return ret; | ||
298 | |||
299 | return 0; | ||
300 | } | ||
301 | |||
302 | int wl1271_init_energy_detection(struct wl1271 *wl) | ||
303 | { | ||
304 | int ret; | ||
305 | |||
306 | ret = wl1271_acx_cca_threshold(wl); | ||
307 | if (ret < 0) | ||
308 | return ret; | ||
309 | |||
310 | return 0; | ||
311 | } | ||
312 | |||
313 | static int wl1271_init_beacon_broadcast(struct wl1271 *wl) | ||
314 | { | ||
315 | int ret; | ||
316 | |||
317 | ret = wl1271_acx_bcn_dtim_options(wl); | ||
318 | if (ret < 0) | ||
319 | return ret; | ||
320 | |||
321 | return 0; | ||
322 | } | ||
323 | |||
324 | static int wl12xx_init_fwlog(struct wl1271 *wl) | ||
325 | { | ||
326 | int ret; | ||
327 | |||
328 | if (wl->quirks & WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED) | ||
329 | return 0; | ||
330 | |||
331 | ret = wl12xx_cmd_config_fwlog(wl); | ||
332 | if (ret < 0) | ||
333 | return ret; | ||
334 | |||
335 | return 0; | ||
336 | } | ||
337 | |||
338 | static int wl1271_sta_hw_init(struct wl1271 *wl) | ||
339 | { | ||
340 | int ret; | ||
341 | |||
342 | if (wl->chip.id != CHIP_ID_1283_PG20) { | ||
343 | ret = wl1271_cmd_ext_radio_parms(wl); | ||
344 | if (ret < 0) | ||
345 | return ret; | ||
346 | } | ||
347 | |||
348 | /* PS config */ | ||
349 | ret = wl1271_acx_config_ps(wl); | ||
350 | if (ret < 0) | ||
351 | return ret; | ||
352 | |||
353 | ret = wl1271_sta_init_templates_config(wl); | ||
354 | if (ret < 0) | ||
355 | return ret; | ||
356 | |||
357 | ret = wl1271_acx_group_address_tbl(wl, true, NULL, 0); | ||
358 | if (ret < 0) | ||
359 | return ret; | ||
360 | |||
361 | /* Initialize connection monitoring thresholds */ | ||
362 | ret = wl1271_acx_conn_monit_params(wl, false); | ||
363 | if (ret < 0) | ||
364 | return ret; | ||
365 | |||
366 | /* Beacon filtering */ | ||
367 | ret = wl1271_init_beacon_filter(wl); | ||
368 | if (ret < 0) | ||
369 | return ret; | ||
370 | |||
371 | /* FM WLAN coexistence */ | ||
372 | ret = wl1271_acx_fm_coex(wl); | ||
373 | if (ret < 0) | ||
374 | return ret; | ||
375 | |||
376 | /* Beacons and broadcast settings */ | ||
377 | ret = wl1271_init_beacon_broadcast(wl); | ||
378 | if (ret < 0) | ||
379 | return ret; | ||
380 | |||
381 | /* Configure for ELP power saving */ | ||
382 | ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP); | ||
383 | if (ret < 0) | ||
384 | return ret; | ||
385 | |||
386 | /* Configure rssi/snr averaging weights */ | ||
387 | ret = wl1271_acx_rssi_snr_avg_weights(wl); | ||
388 | if (ret < 0) | ||
389 | return ret; | ||
390 | |||
391 | ret = wl1271_acx_sta_rate_policies(wl); | ||
392 | if (ret < 0) | ||
393 | return ret; | ||
394 | |||
395 | ret = wl1271_acx_sta_mem_cfg(wl); | ||
396 | if (ret < 0) | ||
397 | return ret; | ||
398 | |||
399 | /* Configure the FW logger */ | ||
400 | ret = wl12xx_init_fwlog(wl); | ||
401 | if (ret < 0) | ||
402 | return ret; | ||
403 | |||
404 | return 0; | ||
405 | } | ||
406 | |||
407 | static int wl1271_sta_hw_init_post_mem(struct wl1271 *wl) | ||
408 | { | ||
409 | int ret, i; | ||
410 | |||
411 | ret = wl1271_cmd_set_sta_default_wep_key(wl, wl->default_key); | ||
412 | if (ret < 0) { | ||
413 | wl1271_warning("couldn't set default key"); | ||
414 | return ret; | ||
415 | } | ||
416 | |||
417 | /* disable all keep-alive templates */ | ||
418 | for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) { | ||
419 | ret = wl1271_acx_keep_alive_config(wl, i, | ||
420 | ACX_KEEP_ALIVE_TPL_INVALID); | ||
421 | if (ret < 0) | ||
422 | return ret; | ||
423 | } | ||
424 | |||
425 | /* disable the keep-alive feature */ | ||
426 | ret = wl1271_acx_keep_alive_mode(wl, false); | ||
427 | if (ret < 0) | ||
428 | return ret; | ||
429 | |||
430 | return 0; | ||
431 | } | ||
432 | |||
433 | static int wl1271_ap_hw_init(struct wl1271 *wl) | ||
434 | { | ||
435 | int ret; | ||
436 | |||
437 | ret = wl1271_ap_init_templates_config(wl); | ||
438 | if (ret < 0) | ||
439 | return ret; | ||
440 | |||
441 | /* Configure for power always on */ | ||
442 | ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM); | ||
443 | if (ret < 0) | ||
444 | return ret; | ||
445 | |||
446 | ret = wl1271_init_ap_rates(wl); | ||
447 | if (ret < 0) | ||
448 | return ret; | ||
449 | |||
450 | ret = wl1271_acx_ap_max_tx_retry(wl); | ||
451 | if (ret < 0) | ||
452 | return ret; | ||
453 | |||
454 | ret = wl1271_acx_ap_mem_cfg(wl); | ||
455 | if (ret < 0) | ||
456 | return ret; | ||
457 | |||
458 | /* initialize Tx power */ | ||
459 | ret = wl1271_acx_tx_power(wl, wl->power_level); | ||
460 | if (ret < 0) | ||
461 | return ret; | ||
462 | |||
463 | return 0; | ||
464 | } | ||
465 | |||
466 | int wl1271_ap_init_templates(struct wl1271 *wl) | ||
467 | { | ||
468 | int ret; | ||
469 | |||
470 | ret = wl1271_ap_init_deauth_template(wl); | ||
471 | if (ret < 0) | ||
472 | return ret; | ||
473 | |||
474 | ret = wl1271_ap_init_null_template(wl); | ||
475 | if (ret < 0) | ||
476 | return ret; | ||
477 | |||
478 | ret = wl1271_ap_init_qos_null_template(wl); | ||
479 | if (ret < 0) | ||
480 | return ret; | ||
481 | |||
482 | /* | ||
483 | * when operating as AP we want to receive external beacons for | ||
484 | * configuring ERP protection. | ||
485 | */ | ||
486 | ret = wl1271_acx_set_ap_beacon_filter(wl, false); | ||
487 | if (ret < 0) | ||
488 | return ret; | ||
489 | |||
490 | return 0; | ||
491 | } | ||
492 | |||
493 | static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl) | ||
494 | { | ||
495 | return wl1271_ap_init_templates(wl); | ||
496 | } | ||
497 | |||
498 | int wl1271_init_ap_rates(struct wl1271 *wl) | ||
499 | { | ||
500 | int i, ret; | ||
501 | struct conf_tx_rate_class rc; | ||
502 | u32 supported_rates; | ||
503 | |||
504 | wl1271_debug(DEBUG_AP, "AP basic rate set: 0x%x", wl->basic_rate_set); | ||
505 | |||
506 | if (wl->basic_rate_set == 0) | ||
507 | return -EINVAL; | ||
508 | |||
509 | rc.enabled_rates = wl->basic_rate_set; | ||
510 | rc.long_retry_limit = 10; | ||
511 | rc.short_retry_limit = 10; | ||
512 | rc.aflags = 0; | ||
513 | ret = wl1271_acx_ap_rate_policy(wl, &rc, ACX_TX_AP_MODE_MGMT_RATE); | ||
514 | if (ret < 0) | ||
515 | return ret; | ||
516 | |||
517 | /* use the min basic rate for AP broadcast/multicast */ | ||
518 | rc.enabled_rates = wl1271_tx_min_rate_get(wl); | ||
519 | rc.short_retry_limit = 10; | ||
520 | rc.long_retry_limit = 10; | ||
521 | rc.aflags = 0; | ||
522 | ret = wl1271_acx_ap_rate_policy(wl, &rc, ACX_TX_AP_MODE_BCST_RATE); | ||
523 | if (ret < 0) | ||
524 | return ret; | ||
525 | |||
526 | /* | ||
527 | * If the basic rates contain OFDM rates, use OFDM only | ||
528 | * rates for unicast TX as well. Else use all supported rates. | ||
529 | */ | ||
530 | if ((wl->basic_rate_set & CONF_TX_OFDM_RATES)) | ||
531 | supported_rates = CONF_TX_OFDM_RATES; | ||
532 | else | ||
533 | supported_rates = CONF_TX_AP_ENABLED_RATES; | ||
534 | |||
535 | /* configure unicast TX rate classes */ | ||
536 | for (i = 0; i < wl->conf.tx.ac_conf_count; i++) { | ||
537 | rc.enabled_rates = supported_rates; | ||
538 | rc.short_retry_limit = 10; | ||
539 | rc.long_retry_limit = 10; | ||
540 | rc.aflags = 0; | ||
541 | ret = wl1271_acx_ap_rate_policy(wl, &rc, i); | ||
542 | if (ret < 0) | ||
543 | return ret; | ||
544 | } | ||
545 | |||
546 | return 0; | ||
547 | } | ||
548 | |||
549 | static void wl1271_check_ba_support(struct wl1271 *wl) | ||
550 | { | ||
551 | /* validate FW cose ver x.x.x.50-60.x */ | ||
552 | if ((wl->chip.fw_ver[3] >= WL12XX_BA_SUPPORT_FW_COST_VER2_START) && | ||
553 | (wl->chip.fw_ver[3] < WL12XX_BA_SUPPORT_FW_COST_VER2_END)) { | ||
554 | wl->ba_support = true; | ||
555 | return; | ||
556 | } | ||
557 | |||
558 | wl->ba_support = false; | ||
559 | } | ||
560 | |||
561 | static int wl1271_set_ba_policies(struct wl1271 *wl) | ||
562 | { | ||
563 | u8 tid_index; | ||
564 | int ret = 0; | ||
565 | |||
566 | /* Reset the BA RX indicators */ | ||
567 | wl->ba_rx_bitmap = 0; | ||
568 | wl->ba_allowed = true; | ||
569 | |||
570 | /* validate that FW support BA */ | ||
571 | wl1271_check_ba_support(wl); | ||
572 | |||
573 | if (wl->ba_support) | ||
574 | /* 802.11n initiator BA session setting */ | ||
575 | for (tid_index = 0; tid_index < CONF_TX_MAX_TID_COUNT; | ||
576 | ++tid_index) { | ||
577 | ret = wl1271_acx_set_ba_session(wl, WLAN_BACK_INITIATOR, | ||
578 | tid_index, true); | ||
579 | if (ret < 0) | ||
580 | break; | ||
581 | } | ||
582 | |||
583 | return ret; | ||
584 | } | ||
585 | |||
586 | int wl1271_chip_specific_init(struct wl1271 *wl) | ||
587 | { | ||
588 | int ret = 0; | ||
589 | |||
590 | if (wl->chip.id == CHIP_ID_1283_PG20) { | ||
591 | u32 host_cfg_bitmap = HOST_IF_CFG_RX_FIFO_ENABLE; | ||
592 | |||
593 | if (wl->quirks & WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT) | ||
594 | /* Enable SDIO padding */ | ||
595 | host_cfg_bitmap |= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK; | ||
596 | |||
597 | /* Must be before wl1271_acx_init_mem_config() */ | ||
598 | ret = wl1271_acx_host_if_cfg_bitmap(wl, host_cfg_bitmap); | ||
599 | if (ret < 0) | ||
600 | goto out; | ||
601 | } | ||
602 | out: | ||
603 | return ret; | ||
604 | } | ||
605 | |||
606 | |||
607 | int wl1271_hw_init(struct wl1271 *wl) | ||
608 | { | ||
609 | struct conf_tx_ac_category *conf_ac; | ||
610 | struct conf_tx_tid *conf_tid; | ||
611 | int ret, i; | ||
612 | bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS); | ||
613 | |||
614 | if (wl->chip.id == CHIP_ID_1283_PG20) | ||
615 | ret = wl128x_cmd_general_parms(wl); | ||
616 | else | ||
617 | ret = wl1271_cmd_general_parms(wl); | ||
618 | if (ret < 0) | ||
619 | return ret; | ||
620 | |||
621 | if (wl->chip.id == CHIP_ID_1283_PG20) | ||
622 | ret = wl128x_cmd_radio_parms(wl); | ||
623 | else | ||
624 | ret = wl1271_cmd_radio_parms(wl); | ||
625 | if (ret < 0) | ||
626 | return ret; | ||
627 | |||
628 | /* Chip-specific init */ | ||
629 | ret = wl1271_chip_specific_init(wl); | ||
630 | if (ret < 0) | ||
631 | return ret; | ||
632 | |||
633 | /* Mode specific init */ | ||
634 | if (is_ap) | ||
635 | ret = wl1271_ap_hw_init(wl); | ||
636 | else | ||
637 | ret = wl1271_sta_hw_init(wl); | ||
638 | |||
639 | if (ret < 0) | ||
640 | return ret; | ||
641 | |||
642 | /* Bluetooth WLAN coexistence */ | ||
643 | ret = wl1271_init_pta(wl); | ||
644 | if (ret < 0) | ||
645 | return ret; | ||
646 | |||
647 | /* Default memory configuration */ | ||
648 | ret = wl1271_acx_init_mem_config(wl); | ||
649 | if (ret < 0) | ||
650 | return ret; | ||
651 | |||
652 | /* RX config */ | ||
653 | ret = wl1271_init_rx_config(wl, | ||
654 | RX_CFG_PROMISCUOUS | RX_CFG_TSF, | ||
655 | RX_FILTER_OPTION_DEF); | ||
656 | /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS, | ||
657 | RX_FILTER_OPTION_FILTER_ALL); */ | ||
658 | if (ret < 0) | ||
659 | goto out_free_memmap; | ||
660 | |||
661 | /* PHY layer config */ | ||
662 | ret = wl1271_init_phy_config(wl); | ||
663 | if (ret < 0) | ||
664 | goto out_free_memmap; | ||
665 | |||
666 | ret = wl1271_acx_dco_itrim_params(wl); | ||
667 | if (ret < 0) | ||
668 | goto out_free_memmap; | ||
669 | |||
670 | /* Configure TX patch complete interrupt behavior */ | ||
671 | ret = wl1271_acx_tx_config_options(wl); | ||
672 | if (ret < 0) | ||
673 | goto out_free_memmap; | ||
674 | |||
675 | /* RX complete interrupt pacing */ | ||
676 | ret = wl1271_acx_init_rx_interrupt(wl); | ||
677 | if (ret < 0) | ||
678 | goto out_free_memmap; | ||
679 | |||
680 | /* Energy detection */ | ||
681 | ret = wl1271_init_energy_detection(wl); | ||
682 | if (ret < 0) | ||
683 | goto out_free_memmap; | ||
684 | |||
685 | /* Default fragmentation threshold */ | ||
686 | ret = wl1271_acx_frag_threshold(wl, wl->hw->wiphy->frag_threshold); | ||
687 | if (ret < 0) | ||
688 | goto out_free_memmap; | ||
689 | |||
690 | /* Default TID/AC configuration */ | ||
691 | BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count); | ||
692 | for (i = 0; i < wl->conf.tx.tid_conf_count; i++) { | ||
693 | conf_ac = &wl->conf.tx.ac_conf[i]; | ||
694 | ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min, | ||
695 | conf_ac->cw_max, conf_ac->aifsn, | ||
696 | conf_ac->tx_op_limit); | ||
697 | if (ret < 0) | ||
698 | goto out_free_memmap; | ||
699 | |||
700 | conf_tid = &wl->conf.tx.tid_conf[i]; | ||
701 | ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id, | ||
702 | conf_tid->channel_type, | ||
703 | conf_tid->tsid, | ||
704 | conf_tid->ps_scheme, | ||
705 | conf_tid->ack_policy, | ||
706 | conf_tid->apsd_conf[0], | ||
707 | conf_tid->apsd_conf[1]); | ||
708 | if (ret < 0) | ||
709 | goto out_free_memmap; | ||
710 | } | ||
711 | |||
712 | /* Enable data path */ | ||
713 | ret = wl1271_cmd_data_path(wl, 1); | ||
714 | if (ret < 0) | ||
715 | goto out_free_memmap; | ||
716 | |||
717 | /* Configure HW encryption */ | ||
718 | ret = wl1271_acx_feature_cfg(wl); | ||
719 | if (ret < 0) | ||
720 | goto out_free_memmap; | ||
721 | |||
722 | /* configure PM */ | ||
723 | ret = wl1271_acx_pm_config(wl); | ||
724 | if (ret < 0) | ||
725 | goto out_free_memmap; | ||
726 | |||
727 | /* Mode specific init - post mem init */ | ||
728 | if (is_ap) | ||
729 | ret = wl1271_ap_hw_init_post_mem(wl); | ||
730 | else | ||
731 | ret = wl1271_sta_hw_init_post_mem(wl); | ||
732 | |||
733 | if (ret < 0) | ||
734 | goto out_free_memmap; | ||
735 | |||
736 | /* Configure initiator BA sessions policies */ | ||
737 | ret = wl1271_set_ba_policies(wl); | ||
738 | if (ret < 0) | ||
739 | goto out_free_memmap; | ||
740 | |||
741 | return 0; | ||
742 | |||
743 | out_free_memmap: | ||
744 | kfree(wl->target_mem_map); | ||
745 | wl->target_mem_map = NULL; | ||
746 | |||
747 | return ret; | ||
748 | } | ||
diff --git a/drivers/net/wireless/wl12xx/init.h b/drivers/net/wireless/wl12xx/init.h new file mode 100644 index 00000000000..3a3c230fd29 --- /dev/null +++ b/drivers/net/wireless/wl12xx/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 "wl12xx.h" | ||
28 | |||
29 | int wl1271_hw_init_power_auth(struct wl1271 *wl); | ||
30 | int wl1271_sta_init_templates_config(struct wl1271 *wl); | ||
31 | int wl1271_init_phy_config(struct wl1271 *wl); | ||
32 | int wl1271_init_pta(struct wl1271 *wl); | ||
33 | int wl1271_init_energy_detection(struct wl1271 *wl); | ||
34 | int wl1271_chip_specific_init(struct wl1271 *wl); | ||
35 | int wl1271_hw_init(struct wl1271 *wl); | ||
36 | int wl1271_init_ap_rates(struct wl1271 *wl); | ||
37 | int wl1271_ap_init_templates(struct wl1271 *wl); | ||
38 | |||
39 | #endif | ||
diff --git a/drivers/net/wireless/wl12xx/io.c b/drivers/net/wireless/wl12xx/io.c new file mode 100644 index 00000000000..c2da66f4504 --- /dev/null +++ b/drivers/net/wireless/wl12xx/io.c | |||
@@ -0,0 +1,183 @@ | |||
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 | |||
28 | #include "wl12xx.h" | ||
29 | #include "wl12xx_80211.h" | ||
30 | #include "io.h" | ||
31 | #include "tx.h" | ||
32 | |||
33 | #define OCP_CMD_LOOP 32 | ||
34 | |||
35 | #define OCP_CMD_WRITE 0x1 | ||
36 | #define OCP_CMD_READ 0x2 | ||
37 | |||
38 | #define OCP_READY_MASK BIT(18) | ||
39 | #define OCP_STATUS_MASK (BIT(16) | BIT(17)) | ||
40 | |||
41 | #define OCP_STATUS_NO_RESP 0x00000 | ||
42 | #define OCP_STATUS_OK 0x10000 | ||
43 | #define OCP_STATUS_REQ_FAILED 0x20000 | ||
44 | #define OCP_STATUS_RESP_ERROR 0x30000 | ||
45 | |||
46 | bool wl1271_set_block_size(struct wl1271 *wl) | ||
47 | { | ||
48 | if (wl->if_ops->set_block_size) { | ||
49 | wl->if_ops->set_block_size(wl, WL12XX_BUS_BLOCK_SIZE); | ||
50 | return true; | ||
51 | } | ||
52 | |||
53 | return false; | ||
54 | } | ||
55 | |||
56 | void wl1271_disable_interrupts(struct wl1271 *wl) | ||
57 | { | ||
58 | wl->if_ops->disable_irq(wl); | ||
59 | } | ||
60 | |||
61 | void wl1271_enable_interrupts(struct wl1271 *wl) | ||
62 | { | ||
63 | wl->if_ops->enable_irq(wl); | ||
64 | } | ||
65 | |||
66 | /* Set the SPI partitions to access the chip addresses | ||
67 | * | ||
68 | * To simplify driver code, a fixed (virtual) memory map is defined for | ||
69 | * register and memory addresses. Because in the chipset, in different stages | ||
70 | * of operation, those addresses will move around, an address translation | ||
71 | * mechanism is required. | ||
72 | * | ||
73 | * There are four partitions (three memory and one register partition), | ||
74 | * which are mapped to two different areas of the hardware memory. | ||
75 | * | ||
76 | * Virtual address | ||
77 | * space | ||
78 | * | ||
79 | * | | | ||
80 | * ...+----+--> mem.start | ||
81 | * Physical address ... | | | ||
82 | * space ... | | [PART_0] | ||
83 | * ... | | | ||
84 | * 00000000 <--+----+... ...+----+--> mem.start + mem.size | ||
85 | * | | ... | | | ||
86 | * |MEM | ... | | | ||
87 | * | | ... | | | ||
88 | * mem.size <--+----+... | | {unused area) | ||
89 | * | | ... | | | ||
90 | * |REG | ... | | | ||
91 | * mem.size | | ... | | | ||
92 | * + <--+----+... ...+----+--> reg.start | ||
93 | * reg.size | | ... | | | ||
94 | * |MEM2| ... | | [PART_1] | ||
95 | * | | ... | | | ||
96 | * ...+----+--> reg.start + reg.size | ||
97 | * | | | ||
98 | * | ||
99 | */ | ||
100 | int wl1271_set_partition(struct wl1271 *wl, | ||
101 | struct wl1271_partition_set *p) | ||
102 | { | ||
103 | /* copy partition info */ | ||
104 | memcpy(&wl->part, p, sizeof(*p)); | ||
105 | |||
106 | wl1271_debug(DEBUG_SPI, "mem_start %08X mem_size %08X", | ||
107 | p->mem.start, p->mem.size); | ||
108 | wl1271_debug(DEBUG_SPI, "reg_start %08X reg_size %08X", | ||
109 | p->reg.start, p->reg.size); | ||
110 | wl1271_debug(DEBUG_SPI, "mem2_start %08X mem2_size %08X", | ||
111 | p->mem2.start, p->mem2.size); | ||
112 | wl1271_debug(DEBUG_SPI, "mem3_start %08X mem3_size %08X", | ||
113 | p->mem3.start, p->mem3.size); | ||
114 | |||
115 | /* write partition info to the chipset */ | ||
116 | wl1271_raw_write32(wl, HW_PART0_START_ADDR, p->mem.start); | ||
117 | wl1271_raw_write32(wl, HW_PART0_SIZE_ADDR, p->mem.size); | ||
118 | wl1271_raw_write32(wl, HW_PART1_START_ADDR, p->reg.start); | ||
119 | wl1271_raw_write32(wl, HW_PART1_SIZE_ADDR, p->reg.size); | ||
120 | wl1271_raw_write32(wl, HW_PART2_START_ADDR, p->mem2.start); | ||
121 | wl1271_raw_write32(wl, HW_PART2_SIZE_ADDR, p->mem2.size); | ||
122 | wl1271_raw_write32(wl, HW_PART3_START_ADDR, p->mem3.start); | ||
123 | |||
124 | return 0; | ||
125 | } | ||
126 | EXPORT_SYMBOL_GPL(wl1271_set_partition); | ||
127 | |||
128 | void wl1271_io_reset(struct wl1271 *wl) | ||
129 | { | ||
130 | if (wl->if_ops->reset) | ||
131 | wl->if_ops->reset(wl); | ||
132 | } | ||
133 | |||
134 | void wl1271_io_init(struct wl1271 *wl) | ||
135 | { | ||
136 | if (wl->if_ops->init) | ||
137 | wl->if_ops->init(wl); | ||
138 | } | ||
139 | |||
140 | void wl1271_top_reg_write(struct wl1271 *wl, int addr, u16 val) | ||
141 | { | ||
142 | /* write address >> 1 + 0x30000 to OCP_POR_CTR */ | ||
143 | addr = (addr >> 1) + 0x30000; | ||
144 | wl1271_write32(wl, OCP_POR_CTR, addr); | ||
145 | |||
146 | /* write value to OCP_POR_WDATA */ | ||
147 | wl1271_write32(wl, OCP_DATA_WRITE, val); | ||
148 | |||
149 | /* write 1 to OCP_CMD */ | ||
150 | wl1271_write32(wl, OCP_CMD, OCP_CMD_WRITE); | ||
151 | } | ||
152 | |||
153 | u16 wl1271_top_reg_read(struct wl1271 *wl, int addr) | ||
154 | { | ||
155 | u32 val; | ||
156 | int timeout = OCP_CMD_LOOP; | ||
157 | |||
158 | /* write address >> 1 + 0x30000 to OCP_POR_CTR */ | ||
159 | addr = (addr >> 1) + 0x30000; | ||
160 | wl1271_write32(wl, OCP_POR_CTR, addr); | ||
161 | |||
162 | /* write 2 to OCP_CMD */ | ||
163 | wl1271_write32(wl, OCP_CMD, OCP_CMD_READ); | ||
164 | |||
165 | /* poll for data ready */ | ||
166 | do { | ||
167 | val = wl1271_read32(wl, OCP_DATA_READ); | ||
168 | } while (!(val & OCP_READY_MASK) && --timeout); | ||
169 | |||
170 | if (!timeout) { | ||
171 | wl1271_warning("Top register access timed out."); | ||
172 | return 0xffff; | ||
173 | } | ||
174 | |||
175 | /* check data status and return if OK */ | ||
176 | if ((val & OCP_STATUS_MASK) == OCP_STATUS_OK) | ||
177 | return val & 0xffff; | ||
178 | else { | ||
179 | wl1271_warning("Top register access returned error."); | ||
180 | return 0xffff; | ||
181 | } | ||
182 | } | ||
183 | |||
diff --git a/drivers/net/wireless/wl12xx/io.h b/drivers/net/wireless/wl12xx/io.h new file mode 100644 index 00000000000..a2fe4f506ad --- /dev/null +++ b/drivers/net/wireless/wl12xx/io.h | |||
@@ -0,0 +1,191 @@ | |||
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 | #include "reg.h" | ||
30 | |||
31 | #define HW_ACCESS_MEMORY_MAX_RANGE 0x1FFC0 | ||
32 | |||
33 | #define HW_PARTITION_REGISTERS_ADDR 0x1FFC0 | ||
34 | #define HW_PART0_SIZE_ADDR (HW_PARTITION_REGISTERS_ADDR) | ||
35 | #define HW_PART0_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 4) | ||
36 | #define HW_PART1_SIZE_ADDR (HW_PARTITION_REGISTERS_ADDR + 8) | ||
37 | #define HW_PART1_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 12) | ||
38 | #define HW_PART2_SIZE_ADDR (HW_PARTITION_REGISTERS_ADDR + 16) | ||
39 | #define HW_PART2_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 20) | ||
40 | #define HW_PART3_START_ADDR (HW_PARTITION_REGISTERS_ADDR + 24) | ||
41 | |||
42 | #define HW_ACCESS_REGISTER_SIZE 4 | ||
43 | |||
44 | #define HW_ACCESS_PRAM_MAX_RANGE 0x3c000 | ||
45 | |||
46 | struct wl1271; | ||
47 | |||
48 | void wl1271_disable_interrupts(struct wl1271 *wl); | ||
49 | void wl1271_enable_interrupts(struct wl1271 *wl); | ||
50 | |||
51 | void wl1271_io_reset(struct wl1271 *wl); | ||
52 | void wl1271_io_init(struct wl1271 *wl); | ||
53 | |||
54 | static inline struct device *wl1271_wl_to_dev(struct wl1271 *wl) | ||
55 | { | ||
56 | return wl->if_ops->dev(wl); | ||
57 | } | ||
58 | |||
59 | |||
60 | /* Raw target IO, address is not translated */ | ||
61 | static inline void wl1271_raw_write(struct wl1271 *wl, int addr, void *buf, | ||
62 | size_t len, bool fixed) | ||
63 | { | ||
64 | wl->if_ops->write(wl, addr, buf, len, fixed); | ||
65 | } | ||
66 | |||
67 | static inline void wl1271_raw_read(struct wl1271 *wl, int addr, void *buf, | ||
68 | size_t len, bool fixed) | ||
69 | { | ||
70 | wl->if_ops->read(wl, addr, buf, len, fixed); | ||
71 | } | ||
72 | |||
73 | static inline u32 wl1271_raw_read32(struct wl1271 *wl, int addr) | ||
74 | { | ||
75 | wl1271_raw_read(wl, addr, &wl->buffer_32, | ||
76 | sizeof(wl->buffer_32), false); | ||
77 | |||
78 | return le32_to_cpu(wl->buffer_32); | ||
79 | } | ||
80 | |||
81 | static inline void wl1271_raw_write32(struct wl1271 *wl, int addr, u32 val) | ||
82 | { | ||
83 | wl->buffer_32 = cpu_to_le32(val); | ||
84 | wl1271_raw_write(wl, addr, &wl->buffer_32, | ||
85 | sizeof(wl->buffer_32), false); | ||
86 | } | ||
87 | |||
88 | /* Translated target IO */ | ||
89 | static inline int wl1271_translate_addr(struct wl1271 *wl, int addr) | ||
90 | { | ||
91 | /* | ||
92 | * To translate, first check to which window of addresses the | ||
93 | * particular address belongs. Then subtract the starting address | ||
94 | * of that window from the address. Then, add offset of the | ||
95 | * translated region. | ||
96 | * | ||
97 | * The translated regions occur next to each other in physical device | ||
98 | * memory, so just add the sizes of the preceding address regions to | ||
99 | * get the offset to the new region. | ||
100 | * | ||
101 | * Currently, only the two first regions are addressed, and the | ||
102 | * assumption is that all addresses will fall into either of those | ||
103 | * two. | ||
104 | */ | ||
105 | if ((addr >= wl->part.reg.start) && | ||
106 | (addr < wl->part.reg.start + wl->part.reg.size)) | ||
107 | return addr - wl->part.reg.start + wl->part.mem.size; | ||
108 | else | ||
109 | return addr - wl->part.mem.start; | ||
110 | } | ||
111 | |||
112 | static inline void wl1271_read(struct wl1271 *wl, int addr, void *buf, | ||
113 | size_t len, bool fixed) | ||
114 | { | ||
115 | int physical; | ||
116 | |||
117 | physical = wl1271_translate_addr(wl, addr); | ||
118 | |||
119 | wl1271_raw_read(wl, physical, buf, len, fixed); | ||
120 | } | ||
121 | |||
122 | static inline void wl1271_write(struct wl1271 *wl, int addr, void *buf, | ||
123 | size_t len, bool fixed) | ||
124 | { | ||
125 | int physical; | ||
126 | |||
127 | physical = wl1271_translate_addr(wl, addr); | ||
128 | |||
129 | wl1271_raw_write(wl, physical, buf, len, fixed); | ||
130 | } | ||
131 | |||
132 | static inline void wl1271_read_hwaddr(struct wl1271 *wl, int hwaddr, | ||
133 | void *buf, size_t len, bool fixed) | ||
134 | { | ||
135 | int physical; | ||
136 | int addr; | ||
137 | |||
138 | /* Addresses are stored internally as addresses to 32 bytes blocks */ | ||
139 | addr = hwaddr << 5; | ||
140 | |||
141 | physical = wl1271_translate_addr(wl, addr); | ||
142 | |||
143 | wl1271_raw_read(wl, physical, buf, len, fixed); | ||
144 | } | ||
145 | |||
146 | static inline u32 wl1271_read32(struct wl1271 *wl, int addr) | ||
147 | { | ||
148 | return wl1271_raw_read32(wl, wl1271_translate_addr(wl, addr)); | ||
149 | } | ||
150 | |||
151 | static inline void wl1271_write32(struct wl1271 *wl, int addr, u32 val) | ||
152 | { | ||
153 | wl1271_raw_write32(wl, wl1271_translate_addr(wl, addr), val); | ||
154 | } | ||
155 | |||
156 | static inline void wl1271_power_off(struct wl1271 *wl) | ||
157 | { | ||
158 | wl->if_ops->power(wl, false); | ||
159 | clear_bit(WL1271_FLAG_GPIO_POWER, &wl->flags); | ||
160 | } | ||
161 | |||
162 | static inline int wl1271_power_on(struct wl1271 *wl) | ||
163 | { | ||
164 | int ret = wl->if_ops->power(wl, true); | ||
165 | if (ret == 0) | ||
166 | set_bit(WL1271_FLAG_GPIO_POWER, &wl->flags); | ||
167 | |||
168 | return ret; | ||
169 | } | ||
170 | |||
171 | |||
172 | /* Top Register IO */ | ||
173 | void wl1271_top_reg_write(struct wl1271 *wl, int addr, u16 val); | ||
174 | u16 wl1271_top_reg_read(struct wl1271 *wl, int addr); | ||
175 | |||
176 | int wl1271_set_partition(struct wl1271 *wl, | ||
177 | struct wl1271_partition_set *p); | ||
178 | |||
179 | /* Functions from wl1271_main.c */ | ||
180 | |||
181 | int wl1271_register_hw(struct wl1271 *wl); | ||
182 | void wl1271_unregister_hw(struct wl1271 *wl); | ||
183 | int wl1271_init_ieee80211(struct wl1271 *wl); | ||
184 | struct ieee80211_hw *wl1271_alloc_hw(void); | ||
185 | int wl1271_free_hw(struct wl1271 *wl); | ||
186 | irqreturn_t wl1271_irq(int irq, void *data); | ||
187 | bool wl1271_set_block_size(struct wl1271 *wl); | ||
188 | int wl1271_tx_dummy_packet(struct wl1271 *wl); | ||
189 | void wl1271_configure_filters(struct wl1271 *wl, unsigned int filters); | ||
190 | |||
191 | #endif | ||
diff --git a/drivers/net/wireless/wl12xx/main.c b/drivers/net/wireless/wl12xx/main.c new file mode 100644 index 00000000000..b70ae40ad66 --- /dev/null +++ b/drivers/net/wireless/wl12xx/main.c | |||
@@ -0,0 +1,4561 @@ | |||
1 | /* | ||
2 | * This file is part of wl1271 | ||
3 | * | ||
4 | * Copyright (C) 2008-2010 Nokia Corporation | ||
5 | * | ||
6 | * Contact: Luciano Coelho <luciano.coelho@nokia.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU General Public License | ||
10 | * version 2 as published by the Free Software Foundation. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, but | ||
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
20 | * 02110-1301 USA | ||
21 | * | ||
22 | */ | ||
23 | |||
24 | #include <linux/module.h> | ||
25 | #include <linux/firmware.h> | ||
26 | #include <linux/delay.h> | ||
27 | #include <linux/spi/spi.h> | ||
28 | #include <linux/crc32.h> | ||
29 | #include <linux/etherdevice.h> | ||
30 | #include <linux/vmalloc.h> | ||
31 | #include <linux/platform_device.h> | ||
32 | #include <linux/slab.h> | ||
33 | #include <linux/wl12xx.h> | ||
34 | #include <linux/sched.h> | ||
35 | |||
36 | #include "wl12xx.h" | ||
37 | #include "wl12xx_80211.h" | ||
38 | #include "reg.h" | ||
39 | #include "io.h" | ||
40 | #include "event.h" | ||
41 | #include "tx.h" | ||
42 | #include "rx.h" | ||
43 | #include "ps.h" | ||
44 | #include "init.h" | ||
45 | #include "debugfs.h" | ||
46 | #include "cmd.h" | ||
47 | #include "boot.h" | ||
48 | #include "testmode.h" | ||
49 | #include "scan.h" | ||
50 | |||
51 | #define WL1271_BOOT_RETRIES 3 | ||
52 | |||
53 | static struct conf_drv_settings default_conf = { | ||
54 | .sg = { | ||
55 | .sta_params = { | ||
56 | [CONF_SG_BT_PER_THRESHOLD] = 7500, | ||
57 | [CONF_SG_HV3_MAX_OVERRIDE] = 0, | ||
58 | [CONF_SG_BT_NFS_SAMPLE_INTERVAL] = 400, | ||
59 | [CONF_SG_BT_LOAD_RATIO] = 200, | ||
60 | [CONF_SG_AUTO_PS_MODE] = 1, | ||
61 | [CONF_SG_AUTO_SCAN_PROBE_REQ] = 170, | ||
62 | [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_HV3] = 50, | ||
63 | [CONF_SG_ANTENNA_CONFIGURATION] = 0, | ||
64 | [CONF_SG_BEACON_MISS_PERCENT] = 60, | ||
65 | [CONF_SG_RATE_ADAPT_THRESH] = 12, | ||
66 | [CONF_SG_RATE_ADAPT_SNR] = 0, | ||
67 | [CONF_SG_WLAN_PS_BT_ACL_MASTER_MIN_BR] = 10, | ||
68 | [CONF_SG_WLAN_PS_BT_ACL_MASTER_MAX_BR] = 30, | ||
69 | [CONF_SG_WLAN_PS_MAX_BT_ACL_MASTER_BR] = 8, | ||
70 | [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MIN_BR] = 20, | ||
71 | [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MAX_BR] = 50, | ||
72 | /* Note: with UPSD, this should be 4 */ | ||
73 | [CONF_SG_WLAN_PS_MAX_BT_ACL_SLAVE_BR] = 8, | ||
74 | [CONF_SG_WLAN_PS_BT_ACL_MASTER_MIN_EDR] = 7, | ||
75 | [CONF_SG_WLAN_PS_BT_ACL_MASTER_MAX_EDR] = 25, | ||
76 | [CONF_SG_WLAN_PS_MAX_BT_ACL_MASTER_EDR] = 20, | ||
77 | /* Note: with UPDS, this should be 15 */ | ||
78 | [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MIN_EDR] = 8, | ||
79 | /* Note: with UPDS, this should be 50 */ | ||
80 | [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MAX_EDR] = 40, | ||
81 | /* Note: with UPDS, this should be 10 */ | ||
82 | [CONF_SG_WLAN_PS_MAX_BT_ACL_SLAVE_EDR] = 20, | ||
83 | [CONF_SG_RXT] = 1200, | ||
84 | [CONF_SG_TXT] = 1000, | ||
85 | [CONF_SG_ADAPTIVE_RXT_TXT] = 1, | ||
86 | [CONF_SG_PS_POLL_TIMEOUT] = 10, | ||
87 | [CONF_SG_UPSD_TIMEOUT] = 10, | ||
88 | [CONF_SG_WLAN_ACTIVE_BT_ACL_MASTER_MIN_EDR] = 7, | ||
89 | [CONF_SG_WLAN_ACTIVE_BT_ACL_MASTER_MAX_EDR] = 15, | ||
90 | [CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_MASTER_EDR] = 15, | ||
91 | [CONF_SG_WLAN_ACTIVE_BT_ACL_SLAVE_MIN_EDR] = 8, | ||
92 | [CONF_SG_WLAN_ACTIVE_BT_ACL_SLAVE_MAX_EDR] = 20, | ||
93 | [CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_SLAVE_EDR] = 15, | ||
94 | [CONF_SG_WLAN_ACTIVE_BT_ACL_MIN_BR] = 20, | ||
95 | [CONF_SG_WLAN_ACTIVE_BT_ACL_MAX_BR] = 50, | ||
96 | [CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_BR] = 10, | ||
97 | [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_HV3] = 200, | ||
98 | [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP] = 800, | ||
99 | [CONF_SG_PASSIVE_SCAN_A2DP_BT_TIME] = 75, | ||
100 | [CONF_SG_PASSIVE_SCAN_A2DP_WLAN_TIME] = 15, | ||
101 | [CONF_SG_HV3_MAX_SERVED] = 6, | ||
102 | [CONF_SG_DHCP_TIME] = 5000, | ||
103 | [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_A2DP] = 100, | ||
104 | }, | ||
105 | .ap_params = { | ||
106 | [CONF_SG_BT_PER_THRESHOLD] = 7500, | ||
107 | [CONF_SG_HV3_MAX_OVERRIDE] = 0, | ||
108 | [CONF_SG_BT_NFS_SAMPLE_INTERVAL] = 400, | ||
109 | [CONF_SG_BT_LOAD_RATIO] = 50, | ||
110 | [CONF_SG_AUTO_PS_MODE] = 1, | ||
111 | [CONF_SG_AUTO_SCAN_PROBE_REQ] = 170, | ||
112 | [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_HV3] = 50, | ||
113 | [CONF_SG_ANTENNA_CONFIGURATION] = 0, | ||
114 | [CONF_SG_BEACON_MISS_PERCENT] = 60, | ||
115 | [CONF_SG_RATE_ADAPT_THRESH] = 64, | ||
116 | [CONF_SG_RATE_ADAPT_SNR] = 1, | ||
117 | [CONF_SG_WLAN_PS_BT_ACL_MASTER_MIN_BR] = 10, | ||
118 | [CONF_SG_WLAN_PS_BT_ACL_MASTER_MAX_BR] = 25, | ||
119 | [CONF_SG_WLAN_PS_MAX_BT_ACL_MASTER_BR] = 25, | ||
120 | [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MIN_BR] = 20, | ||
121 | [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MAX_BR] = 25, | ||
122 | [CONF_SG_WLAN_PS_MAX_BT_ACL_SLAVE_BR] = 25, | ||
123 | [CONF_SG_WLAN_PS_BT_ACL_MASTER_MIN_EDR] = 7, | ||
124 | [CONF_SG_WLAN_PS_BT_ACL_MASTER_MAX_EDR] = 25, | ||
125 | [CONF_SG_WLAN_PS_MAX_BT_ACL_MASTER_EDR] = 25, | ||
126 | [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MIN_EDR] = 8, | ||
127 | [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MAX_EDR] = 25, | ||
128 | [CONF_SG_WLAN_PS_MAX_BT_ACL_SLAVE_EDR] = 25, | ||
129 | [CONF_SG_RXT] = 1200, | ||
130 | [CONF_SG_TXT] = 1000, | ||
131 | [CONF_SG_ADAPTIVE_RXT_TXT] = 1, | ||
132 | [CONF_SG_PS_POLL_TIMEOUT] = 10, | ||
133 | [CONF_SG_UPSD_TIMEOUT] = 10, | ||
134 | [CONF_SG_WLAN_ACTIVE_BT_ACL_MASTER_MIN_EDR] = 7, | ||
135 | [CONF_SG_WLAN_ACTIVE_BT_ACL_MASTER_MAX_EDR] = 15, | ||
136 | [CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_MASTER_EDR] = 15, | ||
137 | [CONF_SG_WLAN_ACTIVE_BT_ACL_SLAVE_MIN_EDR] = 8, | ||
138 | [CONF_SG_WLAN_ACTIVE_BT_ACL_SLAVE_MAX_EDR] = 20, | ||
139 | [CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_SLAVE_EDR] = 15, | ||
140 | [CONF_SG_WLAN_ACTIVE_BT_ACL_MIN_BR] = 20, | ||
141 | [CONF_SG_WLAN_ACTIVE_BT_ACL_MAX_BR] = 50, | ||
142 | [CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_BR] = 10, | ||
143 | [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_HV3] = 200, | ||
144 | [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP] = 800, | ||
145 | [CONF_SG_PASSIVE_SCAN_A2DP_BT_TIME] = 75, | ||
146 | [CONF_SG_PASSIVE_SCAN_A2DP_WLAN_TIME] = 15, | ||
147 | [CONF_SG_HV3_MAX_SERVED] = 6, | ||
148 | [CONF_SG_DHCP_TIME] = 5000, | ||
149 | [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_A2DP] = 100, | ||
150 | [CONF_SG_TEMP_PARAM_1] = 0, | ||
151 | [CONF_SG_TEMP_PARAM_2] = 0, | ||
152 | [CONF_SG_TEMP_PARAM_3] = 0, | ||
153 | [CONF_SG_TEMP_PARAM_4] = 0, | ||
154 | [CONF_SG_TEMP_PARAM_5] = 0, | ||
155 | [CONF_SG_AP_BEACON_MISS_TX] = 3, | ||
156 | [CONF_SG_RX_WINDOW_LENGTH] = 6, | ||
157 | [CONF_SG_AP_CONNECTION_PROTECTION_TIME] = 50, | ||
158 | [CONF_SG_TEMP_PARAM_6] = 1, | ||
159 | }, | ||
160 | .state = CONF_SG_PROTECTIVE, | ||
161 | }, | ||
162 | .rx = { | ||
163 | .rx_msdu_life_time = 512000, | ||
164 | .packet_detection_threshold = 0, | ||
165 | .ps_poll_timeout = 15, | ||
166 | .upsd_timeout = 15, | ||
167 | .rts_threshold = IEEE80211_MAX_RTS_THRESHOLD, | ||
168 | .rx_cca_threshold = 0, | ||
169 | .irq_blk_threshold = 0xFFFF, | ||
170 | .irq_pkt_threshold = 0, | ||
171 | .irq_timeout = 600, | ||
172 | .queue_type = CONF_RX_QUEUE_TYPE_LOW_PRIORITY, | ||
173 | }, | ||
174 | .tx = { | ||
175 | .tx_energy_detection = 0, | ||
176 | .sta_rc_conf = { | ||
177 | .enabled_rates = 0, | ||
178 | .short_retry_limit = 10, | ||
179 | .long_retry_limit = 10, | ||
180 | .aflags = 0, | ||
181 | }, | ||
182 | .ac_conf_count = 4, | ||
183 | .ac_conf = { | ||
184 | [CONF_TX_AC_BE] = { | ||
185 | .ac = CONF_TX_AC_BE, | ||
186 | .cw_min = 15, | ||
187 | .cw_max = 63, | ||
188 | .aifsn = 3, | ||
189 | .tx_op_limit = 0, | ||
190 | }, | ||
191 | [CONF_TX_AC_BK] = { | ||
192 | .ac = CONF_TX_AC_BK, | ||
193 | .cw_min = 15, | ||
194 | .cw_max = 63, | ||
195 | .aifsn = 7, | ||
196 | .tx_op_limit = 0, | ||
197 | }, | ||
198 | [CONF_TX_AC_VI] = { | ||
199 | .ac = CONF_TX_AC_VI, | ||
200 | .cw_min = 15, | ||
201 | .cw_max = 63, | ||
202 | .aifsn = CONF_TX_AIFS_PIFS, | ||
203 | .tx_op_limit = 3008, | ||
204 | }, | ||
205 | [CONF_TX_AC_VO] = { | ||
206 | .ac = CONF_TX_AC_VO, | ||
207 | .cw_min = 15, | ||
208 | .cw_max = 63, | ||
209 | .aifsn = CONF_TX_AIFS_PIFS, | ||
210 | .tx_op_limit = 1504, | ||
211 | }, | ||
212 | }, | ||
213 | .max_tx_retries = 100, | ||
214 | .ap_aging_period = 300, | ||
215 | .tid_conf_count = 4, | ||
216 | .tid_conf = { | ||
217 | [CONF_TX_AC_BE] = { | ||
218 | .queue_id = CONF_TX_AC_BE, | ||
219 | .channel_type = CONF_CHANNEL_TYPE_EDCF, | ||
220 | .tsid = CONF_TX_AC_BE, | ||
221 | .ps_scheme = CONF_PS_SCHEME_LEGACY, | ||
222 | .ack_policy = CONF_ACK_POLICY_LEGACY, | ||
223 | .apsd_conf = {0, 0}, | ||
224 | }, | ||
225 | [CONF_TX_AC_BK] = { | ||
226 | .queue_id = CONF_TX_AC_BK, | ||
227 | .channel_type = CONF_CHANNEL_TYPE_EDCF, | ||
228 | .tsid = CONF_TX_AC_BK, | ||
229 | .ps_scheme = CONF_PS_SCHEME_LEGACY, | ||
230 | .ack_policy = CONF_ACK_POLICY_LEGACY, | ||
231 | .apsd_conf = {0, 0}, | ||
232 | }, | ||
233 | [CONF_TX_AC_VI] = { | ||
234 | .queue_id = CONF_TX_AC_VI, | ||
235 | .channel_type = CONF_CHANNEL_TYPE_EDCF, | ||
236 | .tsid = CONF_TX_AC_VI, | ||
237 | .ps_scheme = CONF_PS_SCHEME_LEGACY, | ||
238 | .ack_policy = CONF_ACK_POLICY_LEGACY, | ||
239 | .apsd_conf = {0, 0}, | ||
240 | }, | ||
241 | [CONF_TX_AC_VO] = { | ||
242 | .queue_id = CONF_TX_AC_VO, | ||
243 | .channel_type = CONF_CHANNEL_TYPE_EDCF, | ||
244 | .tsid = CONF_TX_AC_VO, | ||
245 | .ps_scheme = CONF_PS_SCHEME_LEGACY, | ||
246 | .ack_policy = CONF_ACK_POLICY_LEGACY, | ||
247 | .apsd_conf = {0, 0}, | ||
248 | }, | ||
249 | }, | ||
250 | .frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD, | ||
251 | .tx_compl_timeout = 700, | ||
252 | .tx_compl_threshold = 4, | ||
253 | .basic_rate = CONF_HW_BIT_RATE_1MBPS, | ||
254 | .basic_rate_5 = CONF_HW_BIT_RATE_6MBPS, | ||
255 | .tmpl_short_retry_limit = 10, | ||
256 | .tmpl_long_retry_limit = 10, | ||
257 | }, | ||
258 | .conn = { | ||
259 | .wake_up_event = CONF_WAKE_UP_EVENT_DTIM, | ||
260 | .listen_interval = 1, | ||
261 | .bcn_filt_mode = CONF_BCN_FILT_MODE_ENABLED, | ||
262 | .bcn_filt_ie_count = 2, | ||
263 | .bcn_filt_ie = { | ||
264 | [0] = { | ||
265 | .ie = WLAN_EID_CHANNEL_SWITCH, | ||
266 | .rule = CONF_BCN_RULE_PASS_ON_APPEARANCE, | ||
267 | }, | ||
268 | [1] = { | ||
269 | .ie = WLAN_EID_HT_INFORMATION, | ||
270 | .rule = CONF_BCN_RULE_PASS_ON_CHANGE, | ||
271 | }, | ||
272 | }, | ||
273 | .synch_fail_thold = 10, | ||
274 | .bss_lose_timeout = 100, | ||
275 | .beacon_rx_timeout = 10000, | ||
276 | .broadcast_timeout = 20000, | ||
277 | .rx_broadcast_in_ps = 1, | ||
278 | .ps_poll_threshold = 10, | ||
279 | .ps_poll_recovery_period = 700, | ||
280 | .bet_enable = CONF_BET_MODE_ENABLE, | ||
281 | .bet_max_consecutive = 50, | ||
282 | .psm_entry_retries = 5, | ||
283 | .psm_exit_retries = 16, | ||
284 | .psm_entry_nullfunc_retries = 3, | ||
285 | .psm_entry_hangover_period = 1, | ||
286 | .keep_alive_interval = 55000, | ||
287 | .max_listen_interval = 20, | ||
288 | }, | ||
289 | .itrim = { | ||
290 | .enable = false, | ||
291 | .timeout = 50000, | ||
292 | }, | ||
293 | .pm_config = { | ||
294 | .host_clk_settling_time = 5000, | ||
295 | .host_fast_wakeup_support = false | ||
296 | }, | ||
297 | .roam_trigger = { | ||
298 | .trigger_pacing = 1, | ||
299 | .avg_weight_rssi_beacon = 20, | ||
300 | .avg_weight_rssi_data = 10, | ||
301 | .avg_weight_snr_beacon = 20, | ||
302 | .avg_weight_snr_data = 10, | ||
303 | }, | ||
304 | .scan = { | ||
305 | .min_dwell_time_active = 7500, | ||
306 | .max_dwell_time_active = 30000, | ||
307 | .min_dwell_time_passive = 100000, | ||
308 | .max_dwell_time_passive = 100000, | ||
309 | .num_probe_reqs = 2, | ||
310 | }, | ||
311 | .sched_scan = { | ||
312 | /* sched_scan requires dwell times in TU instead of TU/1000 */ | ||
313 | .min_dwell_time_active = 8, | ||
314 | .max_dwell_time_active = 30, | ||
315 | .dwell_time_passive = 100, | ||
316 | .dwell_time_dfs = 150, | ||
317 | .num_probe_reqs = 2, | ||
318 | .rssi_threshold = -90, | ||
319 | .snr_threshold = 0, | ||
320 | }, | ||
321 | .rf = { | ||
322 | .tx_per_channel_power_compensation_2 = { | ||
323 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
324 | }, | ||
325 | .tx_per_channel_power_compensation_5 = { | ||
326 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
327 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
328 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
329 | }, | ||
330 | }, | ||
331 | .ht = { | ||
332 | .tx_ba_win_size = 64, | ||
333 | .inactivity_timeout = 10000, | ||
334 | }, | ||
335 | .mem_wl127x = { | ||
336 | .num_stations = 1, | ||
337 | .ssid_profiles = 1, | ||
338 | .rx_block_num = 70, | ||
339 | .tx_min_block_num = 40, | ||
340 | .dynamic_memory = 1, | ||
341 | .min_req_tx_blocks = 100, | ||
342 | .min_req_rx_blocks = 22, | ||
343 | .tx_min = 27, | ||
344 | }, | ||
345 | .mem_wl128x = { | ||
346 | .num_stations = 1, | ||
347 | .ssid_profiles = 1, | ||
348 | .rx_block_num = 40, | ||
349 | .tx_min_block_num = 40, | ||
350 | .dynamic_memory = 1, | ||
351 | .min_req_tx_blocks = 45, | ||
352 | .min_req_rx_blocks = 22, | ||
353 | .tx_min = 27, | ||
354 | }, | ||
355 | .fm_coex = { | ||
356 | .enable = true, | ||
357 | .swallow_period = 5, | ||
358 | .n_divider_fref_set_1 = 0xff, /* default */ | ||
359 | .n_divider_fref_set_2 = 12, | ||
360 | .m_divider_fref_set_1 = 148, | ||
361 | .m_divider_fref_set_2 = 0xffff, /* default */ | ||
362 | .coex_pll_stabilization_time = 0xffffffff, /* default */ | ||
363 | .ldo_stabilization_time = 0xffff, /* default */ | ||
364 | .fm_disturbed_band_margin = 0xff, /* default */ | ||
365 | .swallow_clk_diff = 0xff, /* default */ | ||
366 | }, | ||
367 | .rx_streaming = { | ||
368 | .duration = 150, | ||
369 | .queues = 0x1, | ||
370 | .interval = 20, | ||
371 | .always = 0, | ||
372 | }, | ||
373 | .fwlog = { | ||
374 | .mode = WL12XX_FWLOG_ON_DEMAND, | ||
375 | .mem_blocks = 2, | ||
376 | .severity = 0, | ||
377 | .timestamp = WL12XX_FWLOG_TIMESTAMP_DISABLED, | ||
378 | .output = WL12XX_FWLOG_OUTPUT_HOST, | ||
379 | .threshold = 0, | ||
380 | }, | ||
381 | .hci_io_ds = HCI_IO_DS_6MA, | ||
382 | }; | ||
383 | |||
384 | static char *fwlog_param; | ||
385 | |||
386 | static void __wl1271_op_remove_interface(struct wl1271 *wl, | ||
387 | bool reset_tx_queues); | ||
388 | static void wl1271_free_ap_keys(struct wl1271 *wl); | ||
389 | |||
390 | |||
391 | static void wl1271_device_release(struct device *dev) | ||
392 | { | ||
393 | |||
394 | } | ||
395 | |||
396 | static struct platform_device wl1271_device = { | ||
397 | .name = "wl1271", | ||
398 | .id = -1, | ||
399 | |||
400 | /* device model insists to have a release function */ | ||
401 | .dev = { | ||
402 | .release = wl1271_device_release, | ||
403 | }, | ||
404 | }; | ||
405 | |||
406 | static DEFINE_MUTEX(wl_list_mutex); | ||
407 | static LIST_HEAD(wl_list); | ||
408 | |||
409 | static int wl1271_check_operstate(struct wl1271 *wl, unsigned char operstate) | ||
410 | { | ||
411 | int ret; | ||
412 | if (operstate != IF_OPER_UP) | ||
413 | return 0; | ||
414 | |||
415 | if (test_and_set_bit(WL1271_FLAG_STA_STATE_SENT, &wl->flags)) | ||
416 | return 0; | ||
417 | |||
418 | ret = wl1271_cmd_set_sta_state(wl); | ||
419 | if (ret < 0) | ||
420 | return ret; | ||
421 | |||
422 | wl1271_info("Association completed."); | ||
423 | return 0; | ||
424 | } | ||
425 | static int wl1271_dev_notify(struct notifier_block *me, unsigned long what, | ||
426 | void *arg) | ||
427 | { | ||
428 | struct net_device *dev = arg; | ||
429 | struct wireless_dev *wdev; | ||
430 | struct wiphy *wiphy; | ||
431 | struct ieee80211_hw *hw; | ||
432 | struct wl1271 *wl; | ||
433 | struct wl1271 *wl_temp; | ||
434 | int ret = 0; | ||
435 | |||
436 | /* Check that this notification is for us. */ | ||
437 | if (what != NETDEV_CHANGE) | ||
438 | return NOTIFY_DONE; | ||
439 | |||
440 | wdev = dev->ieee80211_ptr; | ||
441 | if (wdev == NULL) | ||
442 | return NOTIFY_DONE; | ||
443 | |||
444 | wiphy = wdev->wiphy; | ||
445 | if (wiphy == NULL) | ||
446 | return NOTIFY_DONE; | ||
447 | |||
448 | hw = wiphy_priv(wiphy); | ||
449 | if (hw == NULL) | ||
450 | return NOTIFY_DONE; | ||
451 | |||
452 | wl_temp = hw->priv; | ||
453 | mutex_lock(&wl_list_mutex); | ||
454 | list_for_each_entry(wl, &wl_list, list) { | ||
455 | if (wl == wl_temp) | ||
456 | break; | ||
457 | } | ||
458 | mutex_unlock(&wl_list_mutex); | ||
459 | if (wl != wl_temp) | ||
460 | return NOTIFY_DONE; | ||
461 | |||
462 | mutex_lock(&wl->mutex); | ||
463 | |||
464 | if (wl->state == WL1271_STATE_OFF) | ||
465 | goto out; | ||
466 | |||
467 | if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) | ||
468 | goto out; | ||
469 | |||
470 | ret = wl1271_ps_elp_wakeup(wl); | ||
471 | if (ret < 0) | ||
472 | goto out; | ||
473 | |||
474 | wl1271_check_operstate(wl, dev->operstate); | ||
475 | |||
476 | wl1271_ps_elp_sleep(wl); | ||
477 | |||
478 | out: | ||
479 | mutex_unlock(&wl->mutex); | ||
480 | |||
481 | return NOTIFY_OK; | ||
482 | } | ||
483 | |||
484 | static int wl1271_reg_notify(struct wiphy *wiphy, | ||
485 | struct regulatory_request *request) | ||
486 | { | ||
487 | struct ieee80211_supported_band *band; | ||
488 | struct ieee80211_channel *ch; | ||
489 | int i; | ||
490 | |||
491 | band = wiphy->bands[IEEE80211_BAND_5GHZ]; | ||
492 | for (i = 0; i < band->n_channels; i++) { | ||
493 | ch = &band->channels[i]; | ||
494 | if (ch->flags & IEEE80211_CHAN_DISABLED) | ||
495 | continue; | ||
496 | |||
497 | if (ch->flags & IEEE80211_CHAN_RADAR) | ||
498 | ch->flags |= IEEE80211_CHAN_NO_IBSS | | ||
499 | IEEE80211_CHAN_PASSIVE_SCAN; | ||
500 | |||
501 | } | ||
502 | |||
503 | return 0; | ||
504 | } | ||
505 | |||
506 | static int wl1271_set_rx_streaming(struct wl1271 *wl, bool enable) | ||
507 | { | ||
508 | int ret = 0; | ||
509 | |||
510 | /* we should hold wl->mutex */ | ||
511 | ret = wl1271_acx_ps_rx_streaming(wl, enable); | ||
512 | if (ret < 0) | ||
513 | goto out; | ||
514 | |||
515 | if (enable) | ||
516 | set_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags); | ||
517 | else | ||
518 | clear_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags); | ||
519 | out: | ||
520 | return ret; | ||
521 | } | ||
522 | |||
523 | /* | ||
524 | * this function is being called when the rx_streaming interval | ||
525 | * has beed changed or rx_streaming should be disabled | ||
526 | */ | ||
527 | int wl1271_recalc_rx_streaming(struct wl1271 *wl) | ||
528 | { | ||
529 | int ret = 0; | ||
530 | int period = wl->conf.rx_streaming.interval; | ||
531 | |||
532 | /* don't reconfigure if rx_streaming is disabled */ | ||
533 | if (!test_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags)) | ||
534 | goto out; | ||
535 | |||
536 | /* reconfigure/disable according to new streaming_period */ | ||
537 | if (period && | ||
538 | test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags) && | ||
539 | (wl->conf.rx_streaming.always || | ||
540 | test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))) | ||
541 | ret = wl1271_set_rx_streaming(wl, true); | ||
542 | else { | ||
543 | ret = wl1271_set_rx_streaming(wl, false); | ||
544 | /* don't cancel_work_sync since we might deadlock */ | ||
545 | del_timer_sync(&wl->rx_streaming_timer); | ||
546 | } | ||
547 | out: | ||
548 | return ret; | ||
549 | } | ||
550 | |||
551 | static void wl1271_rx_streaming_enable_work(struct work_struct *work) | ||
552 | { | ||
553 | int ret; | ||
554 | struct wl1271 *wl = | ||
555 | container_of(work, struct wl1271, rx_streaming_enable_work); | ||
556 | |||
557 | mutex_lock(&wl->mutex); | ||
558 | |||
559 | if (test_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags) || | ||
560 | !test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags) || | ||
561 | (!wl->conf.rx_streaming.always && | ||
562 | !test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))) | ||
563 | goto out; | ||
564 | |||
565 | if (!wl->conf.rx_streaming.interval) | ||
566 | goto out; | ||
567 | |||
568 | ret = wl1271_ps_elp_wakeup(wl); | ||
569 | if (ret < 0) | ||
570 | goto out; | ||
571 | |||
572 | ret = wl1271_set_rx_streaming(wl, true); | ||
573 | if (ret < 0) | ||
574 | goto out_sleep; | ||
575 | |||
576 | /* stop it after some time of inactivity */ | ||
577 | mod_timer(&wl->rx_streaming_timer, | ||
578 | jiffies + msecs_to_jiffies(wl->conf.rx_streaming.duration)); | ||
579 | |||
580 | out_sleep: | ||
581 | wl1271_ps_elp_sleep(wl); | ||
582 | out: | ||
583 | mutex_unlock(&wl->mutex); | ||
584 | } | ||
585 | |||
586 | static void wl1271_rx_streaming_disable_work(struct work_struct *work) | ||
587 | { | ||
588 | int ret; | ||
589 | struct wl1271 *wl = | ||
590 | container_of(work, struct wl1271, rx_streaming_disable_work); | ||
591 | |||
592 | mutex_lock(&wl->mutex); | ||
593 | |||
594 | if (!test_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags)) | ||
595 | goto out; | ||
596 | |||
597 | ret = wl1271_ps_elp_wakeup(wl); | ||
598 | if (ret < 0) | ||
599 | goto out; | ||
600 | |||
601 | ret = wl1271_set_rx_streaming(wl, false); | ||
602 | if (ret) | ||
603 | goto out_sleep; | ||
604 | |||
605 | out_sleep: | ||
606 | wl1271_ps_elp_sleep(wl); | ||
607 | out: | ||
608 | mutex_unlock(&wl->mutex); | ||
609 | } | ||
610 | |||
611 | static void wl1271_rx_streaming_timer(unsigned long data) | ||
612 | { | ||
613 | struct wl1271 *wl = (struct wl1271 *)data; | ||
614 | ieee80211_queue_work(wl->hw, &wl->rx_streaming_disable_work); | ||
615 | } | ||
616 | |||
617 | static void wl1271_conf_init(struct wl1271 *wl) | ||
618 | { | ||
619 | |||
620 | /* | ||
621 | * This function applies the default configuration to the driver. This | ||
622 | * function is invoked upon driver load (spi probe.) | ||
623 | * | ||
624 | * The configuration is stored in a run-time structure in order to | ||
625 | * facilitate for run-time adjustment of any of the parameters. Making | ||
626 | * changes to the configuration structure will apply the new values on | ||
627 | * the next interface up (wl1271_op_start.) | ||
628 | */ | ||
629 | |||
630 | /* apply driver default configuration */ | ||
631 | memcpy(&wl->conf, &default_conf, sizeof(default_conf)); | ||
632 | |||
633 | /* Adjust settings according to optional module parameters */ | ||
634 | if (fwlog_param) { | ||
635 | if (!strcmp(fwlog_param, "continuous")) { | ||
636 | wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS; | ||
637 | } else if (!strcmp(fwlog_param, "ondemand")) { | ||
638 | wl->conf.fwlog.mode = WL12XX_FWLOG_ON_DEMAND; | ||
639 | } else if (!strcmp(fwlog_param, "dbgpins")) { | ||
640 | wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS; | ||
641 | wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_DBG_PINS; | ||
642 | } else if (!strcmp(fwlog_param, "disable")) { | ||
643 | wl->conf.fwlog.mem_blocks = 0; | ||
644 | wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_NONE; | ||
645 | } else { | ||
646 | wl1271_error("Unknown fwlog parameter %s", fwlog_param); | ||
647 | } | ||
648 | } | ||
649 | } | ||
650 | |||
651 | static int wl1271_plt_init(struct wl1271 *wl) | ||
652 | { | ||
653 | struct conf_tx_ac_category *conf_ac; | ||
654 | struct conf_tx_tid *conf_tid; | ||
655 | int ret, i; | ||
656 | |||
657 | if (wl->chip.id == CHIP_ID_1283_PG20) | ||
658 | ret = wl128x_cmd_general_parms(wl); | ||
659 | else | ||
660 | ret = wl1271_cmd_general_parms(wl); | ||
661 | if (ret < 0) | ||
662 | return ret; | ||
663 | |||
664 | if (wl->chip.id == CHIP_ID_1283_PG20) | ||
665 | ret = wl128x_cmd_radio_parms(wl); | ||
666 | else | ||
667 | ret = wl1271_cmd_radio_parms(wl); | ||
668 | if (ret < 0) | ||
669 | return ret; | ||
670 | |||
671 | if (wl->chip.id != CHIP_ID_1283_PG20) { | ||
672 | ret = wl1271_cmd_ext_radio_parms(wl); | ||
673 | if (ret < 0) | ||
674 | return ret; | ||
675 | } | ||
676 | if (ret < 0) | ||
677 | return ret; | ||
678 | |||
679 | /* Chip-specific initializations */ | ||
680 | ret = wl1271_chip_specific_init(wl); | ||
681 | if (ret < 0) | ||
682 | return ret; | ||
683 | |||
684 | ret = wl1271_sta_init_templates_config(wl); | ||
685 | if (ret < 0) | ||
686 | return ret; | ||
687 | |||
688 | ret = wl1271_acx_init_mem_config(wl); | ||
689 | if (ret < 0) | ||
690 | return ret; | ||
691 | |||
692 | /* PHY layer config */ | ||
693 | ret = wl1271_init_phy_config(wl); | ||
694 | if (ret < 0) | ||
695 | goto out_free_memmap; | ||
696 | |||
697 | ret = wl1271_acx_dco_itrim_params(wl); | ||
698 | if (ret < 0) | ||
699 | goto out_free_memmap; | ||
700 | |||
701 | /* Initialize connection monitoring thresholds */ | ||
702 | ret = wl1271_acx_conn_monit_params(wl, false); | ||
703 | if (ret < 0) | ||
704 | goto out_free_memmap; | ||
705 | |||
706 | /* Bluetooth WLAN coexistence */ | ||
707 | ret = wl1271_init_pta(wl); | ||
708 | if (ret < 0) | ||
709 | goto out_free_memmap; | ||
710 | |||
711 | /* FM WLAN coexistence */ | ||
712 | ret = wl1271_acx_fm_coex(wl); | ||
713 | if (ret < 0) | ||
714 | goto out_free_memmap; | ||
715 | |||
716 | /* Energy detection */ | ||
717 | ret = wl1271_init_energy_detection(wl); | ||
718 | if (ret < 0) | ||
719 | goto out_free_memmap; | ||
720 | |||
721 | ret = wl1271_acx_sta_mem_cfg(wl); | ||
722 | if (ret < 0) | ||
723 | goto out_free_memmap; | ||
724 | |||
725 | /* Default fragmentation threshold */ | ||
726 | ret = wl1271_acx_frag_threshold(wl, wl->conf.tx.frag_threshold); | ||
727 | if (ret < 0) | ||
728 | goto out_free_memmap; | ||
729 | |||
730 | /* Default TID/AC configuration */ | ||
731 | BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count); | ||
732 | for (i = 0; i < wl->conf.tx.tid_conf_count; i++) { | ||
733 | conf_ac = &wl->conf.tx.ac_conf[i]; | ||
734 | ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min, | ||
735 | conf_ac->cw_max, conf_ac->aifsn, | ||
736 | conf_ac->tx_op_limit); | ||
737 | if (ret < 0) | ||
738 | goto out_free_memmap; | ||
739 | |||
740 | conf_tid = &wl->conf.tx.tid_conf[i]; | ||
741 | ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id, | ||
742 | conf_tid->channel_type, | ||
743 | conf_tid->tsid, | ||
744 | conf_tid->ps_scheme, | ||
745 | conf_tid->ack_policy, | ||
746 | conf_tid->apsd_conf[0], | ||
747 | conf_tid->apsd_conf[1]); | ||
748 | if (ret < 0) | ||
749 | goto out_free_memmap; | ||
750 | } | ||
751 | |||
752 | /* Enable data path */ | ||
753 | ret = wl1271_cmd_data_path(wl, 1); | ||
754 | if (ret < 0) | ||
755 | goto out_free_memmap; | ||
756 | |||
757 | /* Configure for CAM power saving (ie. always active) */ | ||
758 | ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM); | ||
759 | if (ret < 0) | ||
760 | goto out_free_memmap; | ||
761 | |||
762 | /* configure PM */ | ||
763 | ret = wl1271_acx_pm_config(wl); | ||
764 | if (ret < 0) | ||
765 | goto out_free_memmap; | ||
766 | |||
767 | return 0; | ||
768 | |||
769 | out_free_memmap: | ||
770 | kfree(wl->target_mem_map); | ||
771 | wl->target_mem_map = NULL; | ||
772 | |||
773 | return ret; | ||
774 | } | ||
775 | |||
776 | static void wl1271_irq_ps_regulate_link(struct wl1271 *wl, u8 hlid, u8 tx_blks) | ||
777 | { | ||
778 | bool fw_ps; | ||
779 | |||
780 | /* only regulate station links */ | ||
781 | if (hlid < WL1271_AP_STA_HLID_START) | ||
782 | return; | ||
783 | |||
784 | fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map); | ||
785 | |||
786 | /* | ||
787 | * Wake up from high level PS if the STA is asleep with too little | ||
788 | * blocks in FW or if the STA is awake. | ||
789 | */ | ||
790 | if (!fw_ps || tx_blks < WL1271_PS_STA_MAX_BLOCKS) | ||
791 | wl1271_ps_link_end(wl, hlid); | ||
792 | |||
793 | /* Start high-level PS if the STA is asleep with enough blocks in FW */ | ||
794 | else if (fw_ps && tx_blks >= WL1271_PS_STA_MAX_BLOCKS) | ||
795 | wl1271_ps_link_start(wl, hlid, true); | ||
796 | } | ||
797 | |||
798 | static void wl1271_irq_update_links_status(struct wl1271 *wl, | ||
799 | struct wl1271_fw_ap_status *status) | ||
800 | { | ||
801 | u32 cur_fw_ps_map; | ||
802 | u8 hlid; | ||
803 | |||
804 | cur_fw_ps_map = le32_to_cpu(status->link_ps_bitmap); | ||
805 | if (wl->ap_fw_ps_map != cur_fw_ps_map) { | ||
806 | wl1271_debug(DEBUG_PSM, | ||
807 | "link ps prev 0x%x cur 0x%x changed 0x%x", | ||
808 | wl->ap_fw_ps_map, cur_fw_ps_map, | ||
809 | wl->ap_fw_ps_map ^ cur_fw_ps_map); | ||
810 | |||
811 | wl->ap_fw_ps_map = cur_fw_ps_map; | ||
812 | } | ||
813 | |||
814 | for (hlid = WL1271_AP_STA_HLID_START; hlid < AP_MAX_LINKS; hlid++) { | ||
815 | u8 cnt = status->tx_lnk_free_blks[hlid] - | ||
816 | wl->links[hlid].prev_freed_blks; | ||
817 | |||
818 | wl->links[hlid].prev_freed_blks = | ||
819 | status->tx_lnk_free_blks[hlid]; | ||
820 | wl->links[hlid].allocated_blks -= cnt; | ||
821 | |||
822 | wl1271_irq_ps_regulate_link(wl, hlid, | ||
823 | wl->links[hlid].allocated_blks); | ||
824 | } | ||
825 | } | ||
826 | |||
827 | static u32 wl1271_tx_allocated_blocks(struct wl1271 *wl) | ||
828 | { | ||
829 | int i; | ||
830 | u32 total_alloc_blocks = 0; | ||
831 | |||
832 | for (i = 0; i < NUM_TX_QUEUES; i++) | ||
833 | total_alloc_blocks += wl->tx_allocated_blocks[i]; | ||
834 | |||
835 | return total_alloc_blocks; | ||
836 | } | ||
837 | |||
838 | static void wl1271_fw_status(struct wl1271 *wl, | ||
839 | struct wl1271_fw_full_status *full_status) | ||
840 | { | ||
841 | struct wl1271_fw_common_status *status = &full_status->common; | ||
842 | struct timespec ts; | ||
843 | u32 old_tx_blk_count = wl->tx_blocks_available; | ||
844 | u32 freed_blocks = 0, ac_freed_blocks; | ||
845 | int i; | ||
846 | |||
847 | if (wl->bss_type == BSS_TYPE_AP_BSS) { | ||
848 | wl1271_raw_read(wl, FW_STATUS_ADDR, status, | ||
849 | sizeof(struct wl1271_fw_ap_status), false); | ||
850 | } else { | ||
851 | wl1271_raw_read(wl, FW_STATUS_ADDR, status, | ||
852 | sizeof(struct wl1271_fw_sta_status), false); | ||
853 | } | ||
854 | |||
855 | wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, " | ||
856 | "drv_rx_counter = %d, tx_results_counter = %d)", | ||
857 | status->intr, | ||
858 | status->fw_rx_counter, | ||
859 | status->drv_rx_counter, | ||
860 | status->tx_results_counter); | ||
861 | |||
862 | /* update number of available TX blocks */ | ||
863 | for (i = 0; i < NUM_TX_QUEUES; i++) { | ||
864 | ac_freed_blocks = le32_to_cpu(status->tx_released_blks[i]) - | ||
865 | wl->tx_blocks_freed[i]; | ||
866 | freed_blocks += ac_freed_blocks; | ||
867 | |||
868 | wl->tx_allocated_blocks[i] -= ac_freed_blocks; | ||
869 | |||
870 | wl->tx_blocks_freed[i] = | ||
871 | le32_to_cpu(status->tx_released_blks[i]); | ||
872 | } | ||
873 | |||
874 | if (wl->bss_type == BSS_TYPE_AP_BSS) { | ||
875 | /* Update num of allocated TX blocks per link and ps status */ | ||
876 | wl1271_irq_update_links_status(wl, &full_status->ap); | ||
877 | wl->tx_blocks_available += freed_blocks; | ||
878 | } else { | ||
879 | int avail = full_status->sta.tx_total - | ||
880 | wl1271_tx_allocated_blocks(wl); | ||
881 | |||
882 | /* | ||
883 | * The FW might change the total number of TX memblocks before | ||
884 | * we get a notification about blocks being released. Thus, the | ||
885 | * available blocks calculation might yield a temporary result | ||
886 | * which is lower than the actual available blocks. Keeping in | ||
887 | * mind that only blocks that were allocated can be moved from | ||
888 | * TX to RX, tx_blocks_available should never decrease here. | ||
889 | */ | ||
890 | wl->tx_blocks_available = max((int)wl->tx_blocks_available, | ||
891 | avail); | ||
892 | } | ||
893 | |||
894 | /* if more blocks are available now, tx work can be scheduled */ | ||
895 | if (wl->tx_blocks_available > old_tx_blk_count) | ||
896 | clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags); | ||
897 | |||
898 | /* update the host-chipset time offset */ | ||
899 | getnstimeofday(&ts); | ||
900 | wl->time_offset = (timespec_to_ns(&ts) >> 10) - | ||
901 | (s64)le32_to_cpu(status->fw_localtime); | ||
902 | } | ||
903 | |||
904 | static void wl1271_flush_deferred_work(struct wl1271 *wl) | ||
905 | { | ||
906 | struct sk_buff *skb; | ||
907 | |||
908 | /* Pass all received frames to the network stack */ | ||
909 | while ((skb = skb_dequeue(&wl->deferred_rx_queue))) | ||
910 | ieee80211_rx_ni(wl->hw, skb); | ||
911 | |||
912 | /* Return sent skbs to the network stack */ | ||
913 | while ((skb = skb_dequeue(&wl->deferred_tx_queue))) | ||
914 | ieee80211_tx_status_ni(wl->hw, skb); | ||
915 | } | ||
916 | |||
917 | static void wl1271_netstack_work(struct work_struct *work) | ||
918 | { | ||
919 | struct wl1271 *wl = | ||
920 | container_of(work, struct wl1271, netstack_work); | ||
921 | |||
922 | do { | ||
923 | wl1271_flush_deferred_work(wl); | ||
924 | } while (skb_queue_len(&wl->deferred_rx_queue)); | ||
925 | } | ||
926 | |||
927 | #define WL1271_IRQ_MAX_LOOPS 256 | ||
928 | |||
929 | irqreturn_t wl1271_irq(int irq, void *cookie) | ||
930 | { | ||
931 | int ret; | ||
932 | u32 intr; | ||
933 | int loopcount = WL1271_IRQ_MAX_LOOPS; | ||
934 | struct wl1271 *wl = (struct wl1271 *)cookie; | ||
935 | bool done = false; | ||
936 | unsigned int defer_count; | ||
937 | unsigned long flags; | ||
938 | |||
939 | /* TX might be handled here, avoid redundant work */ | ||
940 | set_bit(WL1271_FLAG_TX_PENDING, &wl->flags); | ||
941 | cancel_work_sync(&wl->tx_work); | ||
942 | |||
943 | /* | ||
944 | * In case edge triggered interrupt must be used, we cannot iterate | ||
945 | * more than once without introducing race conditions with the hardirq. | ||
946 | */ | ||
947 | if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ) | ||
948 | loopcount = 1; | ||
949 | |||
950 | mutex_lock(&wl->mutex); | ||
951 | |||
952 | wl1271_debug(DEBUG_IRQ, "IRQ work"); | ||
953 | |||
954 | if (unlikely(wl->state == WL1271_STATE_OFF)) | ||
955 | goto out; | ||
956 | |||
957 | ret = wl1271_ps_elp_wakeup(wl); | ||
958 | if (ret < 0) | ||
959 | goto out; | ||
960 | |||
961 | while (!done && loopcount--) { | ||
962 | /* | ||
963 | * In order to avoid a race with the hardirq, clear the flag | ||
964 | * before acknowledging the chip. Since the mutex is held, | ||
965 | * wl1271_ps_elp_wakeup cannot be called concurrently. | ||
966 | */ | ||
967 | clear_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags); | ||
968 | smp_mb__after_clear_bit(); | ||
969 | |||
970 | wl1271_fw_status(wl, wl->fw_status); | ||
971 | intr = le32_to_cpu(wl->fw_status->common.intr); | ||
972 | intr &= WL1271_INTR_MASK; | ||
973 | if (!intr) { | ||
974 | done = true; | ||
975 | continue; | ||
976 | } | ||
977 | |||
978 | if (unlikely(intr & WL1271_ACX_INTR_WATCHDOG)) { | ||
979 | wl1271_error("watchdog interrupt received! " | ||
980 | "starting recovery."); | ||
981 | wl12xx_queue_recovery_work(wl); | ||
982 | |||
983 | /* restarting the chip. ignore any other interrupt. */ | ||
984 | goto out; | ||
985 | } | ||
986 | |||
987 | if (likely(intr & WL1271_ACX_INTR_DATA)) { | ||
988 | wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA"); | ||
989 | |||
990 | wl1271_rx(wl, &wl->fw_status->common); | ||
991 | |||
992 | /* Check if any tx blocks were freed */ | ||
993 | spin_lock_irqsave(&wl->wl_lock, flags); | ||
994 | if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) && | ||
995 | wl1271_tx_total_queue_count(wl) > 0) { | ||
996 | spin_unlock_irqrestore(&wl->wl_lock, flags); | ||
997 | /* | ||
998 | * In order to avoid starvation of the TX path, | ||
999 | * call the work function directly. | ||
1000 | */ | ||
1001 | wl1271_tx_work_locked(wl); | ||
1002 | } else { | ||
1003 | spin_unlock_irqrestore(&wl->wl_lock, flags); | ||
1004 | } | ||
1005 | |||
1006 | /* check for tx results */ | ||
1007 | if (wl->fw_status->common.tx_results_counter != | ||
1008 | (wl->tx_results_count & 0xff)) | ||
1009 | wl1271_tx_complete(wl); | ||
1010 | |||
1011 | /* Make sure the deferred queues don't get too long */ | ||
1012 | defer_count = skb_queue_len(&wl->deferred_tx_queue) + | ||
1013 | skb_queue_len(&wl->deferred_rx_queue); | ||
1014 | if (defer_count > WL1271_DEFERRED_QUEUE_LIMIT) | ||
1015 | wl1271_flush_deferred_work(wl); | ||
1016 | } | ||
1017 | |||
1018 | if (intr & WL1271_ACX_INTR_EVENT_A) { | ||
1019 | wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_A"); | ||
1020 | wl1271_event_handle(wl, 0); | ||
1021 | } | ||
1022 | |||
1023 | if (intr & WL1271_ACX_INTR_EVENT_B) { | ||
1024 | wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_B"); | ||
1025 | wl1271_event_handle(wl, 1); | ||
1026 | } | ||
1027 | |||
1028 | if (intr & WL1271_ACX_INTR_INIT_COMPLETE) | ||
1029 | wl1271_debug(DEBUG_IRQ, | ||
1030 | "WL1271_ACX_INTR_INIT_COMPLETE"); | ||
1031 | |||
1032 | if (intr & WL1271_ACX_INTR_HW_AVAILABLE) | ||
1033 | wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE"); | ||
1034 | } | ||
1035 | |||
1036 | wl1271_ps_elp_sleep(wl); | ||
1037 | |||
1038 | out: | ||
1039 | spin_lock_irqsave(&wl->wl_lock, flags); | ||
1040 | /* In case TX was not handled here, queue TX work */ | ||
1041 | clear_bit(WL1271_FLAG_TX_PENDING, &wl->flags); | ||
1042 | if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) && | ||
1043 | wl1271_tx_total_queue_count(wl) > 0) | ||
1044 | ieee80211_queue_work(wl->hw, &wl->tx_work); | ||
1045 | spin_unlock_irqrestore(&wl->wl_lock, flags); | ||
1046 | |||
1047 | mutex_unlock(&wl->mutex); | ||
1048 | |||
1049 | return IRQ_HANDLED; | ||
1050 | } | ||
1051 | EXPORT_SYMBOL_GPL(wl1271_irq); | ||
1052 | |||
1053 | static int wl1271_fetch_firmware(struct wl1271 *wl) | ||
1054 | { | ||
1055 | const struct firmware *fw; | ||
1056 | const char *fw_name; | ||
1057 | int ret; | ||
1058 | |||
1059 | switch (wl->bss_type) { | ||
1060 | case BSS_TYPE_AP_BSS: | ||
1061 | if (wl->chip.id == CHIP_ID_1283_PG20) | ||
1062 | fw_name = WL128X_AP_FW_NAME; | ||
1063 | else | ||
1064 | fw_name = WL127X_AP_FW_NAME; | ||
1065 | break; | ||
1066 | case BSS_TYPE_IBSS: | ||
1067 | case BSS_TYPE_STA_BSS: | ||
1068 | if (wl->chip.id == CHIP_ID_1283_PG20) | ||
1069 | fw_name = WL128X_FW_NAME; | ||
1070 | else | ||
1071 | fw_name = WL1271_FW_NAME; | ||
1072 | break; | ||
1073 | default: | ||
1074 | wl1271_error("no compatible firmware for bss_type %d", | ||
1075 | wl->bss_type); | ||
1076 | return -EINVAL; | ||
1077 | } | ||
1078 | |||
1079 | wl1271_debug(DEBUG_BOOT, "booting firmware %s", fw_name); | ||
1080 | |||
1081 | ret = request_firmware(&fw, fw_name, wl1271_wl_to_dev(wl)); | ||
1082 | |||
1083 | if (ret < 0) { | ||
1084 | wl1271_error("could not get firmware: %d", ret); | ||
1085 | return ret; | ||
1086 | } | ||
1087 | |||
1088 | if (fw->size % 4) { | ||
1089 | wl1271_error("firmware size is not multiple of 32 bits: %zu", | ||
1090 | fw->size); | ||
1091 | ret = -EILSEQ; | ||
1092 | goto out; | ||
1093 | } | ||
1094 | |||
1095 | vfree(wl->fw); | ||
1096 | wl->fw_len = fw->size; | ||
1097 | wl->fw = vmalloc(wl->fw_len); | ||
1098 | |||
1099 | if (!wl->fw) { | ||
1100 | wl1271_error("could not allocate memory for the firmware"); | ||
1101 | ret = -ENOMEM; | ||
1102 | goto out; | ||
1103 | } | ||
1104 | |||
1105 | memcpy(wl->fw, fw->data, wl->fw_len); | ||
1106 | wl->fw_bss_type = wl->bss_type; | ||
1107 | ret = 0; | ||
1108 | |||
1109 | out: | ||
1110 | release_firmware(fw); | ||
1111 | |||
1112 | return ret; | ||
1113 | } | ||
1114 | |||
1115 | static int wl1271_fetch_nvs(struct wl1271 *wl) | ||
1116 | { | ||
1117 | const struct firmware *fw; | ||
1118 | int ret; | ||
1119 | |||
1120 | ret = request_firmware(&fw, WL12XX_NVS_NAME, wl1271_wl_to_dev(wl)); | ||
1121 | |||
1122 | if (ret < 0) { | ||
1123 | wl1271_error("could not get nvs file: %d", ret); | ||
1124 | return ret; | ||
1125 | } | ||
1126 | |||
1127 | wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL); | ||
1128 | |||
1129 | if (!wl->nvs) { | ||
1130 | wl1271_error("could not allocate memory for the nvs file"); | ||
1131 | ret = -ENOMEM; | ||
1132 | goto out; | ||
1133 | } | ||
1134 | |||
1135 | wl->nvs_len = fw->size; | ||
1136 | |||
1137 | out: | ||
1138 | release_firmware(fw); | ||
1139 | |||
1140 | return ret; | ||
1141 | } | ||
1142 | |||
1143 | void wl12xx_queue_recovery_work(struct wl1271 *wl) | ||
1144 | { | ||
1145 | if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) | ||
1146 | ieee80211_queue_work(wl->hw, &wl->recovery_work); | ||
1147 | } | ||
1148 | |||
1149 | size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen) | ||
1150 | { | ||
1151 | size_t len = 0; | ||
1152 | |||
1153 | /* The FW log is a length-value list, find where the log end */ | ||
1154 | while (len < maxlen) { | ||
1155 | if (memblock[len] == 0) | ||
1156 | break; | ||
1157 | if (len + memblock[len] + 1 > maxlen) | ||
1158 | break; | ||
1159 | len += memblock[len] + 1; | ||
1160 | } | ||
1161 | |||
1162 | /* Make sure we have enough room */ | ||
1163 | len = min(len, (size_t)(PAGE_SIZE - wl->fwlog_size)); | ||
1164 | |||
1165 | /* Fill the FW log file, consumed by the sysfs fwlog entry */ | ||
1166 | memcpy(wl->fwlog + wl->fwlog_size, memblock, len); | ||
1167 | wl->fwlog_size += len; | ||
1168 | |||
1169 | return len; | ||
1170 | } | ||
1171 | |||
1172 | static void wl12xx_read_fwlog_panic(struct wl1271 *wl) | ||
1173 | { | ||
1174 | u32 addr; | ||
1175 | u32 first_addr; | ||
1176 | u8 *block; | ||
1177 | |||
1178 | if ((wl->quirks & WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED) || | ||
1179 | (wl->conf.fwlog.mode != WL12XX_FWLOG_ON_DEMAND) || | ||
1180 | (wl->conf.fwlog.mem_blocks == 0)) | ||
1181 | return; | ||
1182 | |||
1183 | wl1271_info("Reading FW panic log"); | ||
1184 | |||
1185 | block = kmalloc(WL12XX_HW_BLOCK_SIZE, GFP_KERNEL); | ||
1186 | if (!block) | ||
1187 | return; | ||
1188 | |||
1189 | /* | ||
1190 | * Make sure the chip is awake and the logger isn't active. | ||
1191 | * This might fail if the firmware hanged. | ||
1192 | */ | ||
1193 | if (!wl1271_ps_elp_wakeup(wl)) | ||
1194 | wl12xx_cmd_stop_fwlog(wl); | ||
1195 | |||
1196 | /* Read the first memory block address */ | ||
1197 | wl1271_fw_status(wl, wl->fw_status); | ||
1198 | first_addr = __le32_to_cpu(wl->fw_status->sta.log_start_addr); | ||
1199 | if (!first_addr) | ||
1200 | goto out; | ||
1201 | |||
1202 | /* Traverse the memory blocks linked list */ | ||
1203 | addr = first_addr; | ||
1204 | do { | ||
1205 | memset(block, 0, WL12XX_HW_BLOCK_SIZE); | ||
1206 | wl1271_read_hwaddr(wl, addr, block, WL12XX_HW_BLOCK_SIZE, | ||
1207 | false); | ||
1208 | |||
1209 | /* | ||
1210 | * Memory blocks are linked to one another. The first 4 bytes | ||
1211 | * of each memory block hold the hardware address of the next | ||
1212 | * one. The last memory block points to the first one. | ||
1213 | */ | ||
1214 | addr = __le32_to_cpup((__le32 *)block); | ||
1215 | if (!wl12xx_copy_fwlog(wl, block + sizeof(addr), | ||
1216 | WL12XX_HW_BLOCK_SIZE - sizeof(addr))) | ||
1217 | break; | ||
1218 | } while (addr && (addr != first_addr)); | ||
1219 | |||
1220 | wake_up_interruptible(&wl->fwlog_waitq); | ||
1221 | |||
1222 | out: | ||
1223 | kfree(block); | ||
1224 | } | ||
1225 | |||
1226 | static void wl1271_recovery_work(struct work_struct *work) | ||
1227 | { | ||
1228 | struct wl1271 *wl = | ||
1229 | container_of(work, struct wl1271, recovery_work); | ||
1230 | |||
1231 | mutex_lock(&wl->mutex); | ||
1232 | |||
1233 | if (wl->state != WL1271_STATE_ON) | ||
1234 | goto out; | ||
1235 | |||
1236 | /* Avoid a recursive recovery */ | ||
1237 | set_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags); | ||
1238 | |||
1239 | wl12xx_read_fwlog_panic(wl); | ||
1240 | |||
1241 | wl1271_info("Hardware recovery in progress. FW ver: %s pc: 0x%x", | ||
1242 | wl->chip.fw_ver_str, wl1271_read32(wl, SCR_PAD4)); | ||
1243 | |||
1244 | /* | ||
1245 | * Advance security sequence number to overcome potential progress | ||
1246 | * in the firmware during recovery. This doens't hurt if the network is | ||
1247 | * not encrypted. | ||
1248 | */ | ||
1249 | if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags) || | ||
1250 | test_bit(WL1271_FLAG_AP_STARTED, &wl->flags)) | ||
1251 | wl->tx_security_seq += WL1271_TX_SQN_POST_RECOVERY_PADDING; | ||
1252 | |||
1253 | if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) | ||
1254 | ieee80211_connection_loss(wl->vif); | ||
1255 | |||
1256 | /* Prevent spurious TX during FW restart */ | ||
1257 | ieee80211_stop_queues(wl->hw); | ||
1258 | |||
1259 | if (wl->sched_scanning) { | ||
1260 | ieee80211_sched_scan_stopped(wl->hw); | ||
1261 | wl->sched_scanning = false; | ||
1262 | } | ||
1263 | |||
1264 | /* reboot the chipset */ | ||
1265 | __wl1271_op_remove_interface(wl, false); | ||
1266 | |||
1267 | clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags); | ||
1268 | |||
1269 | ieee80211_restart_hw(wl->hw); | ||
1270 | |||
1271 | /* | ||
1272 | * Its safe to enable TX now - the queues are stopped after a request | ||
1273 | * to restart the HW. | ||
1274 | */ | ||
1275 | ieee80211_wake_queues(wl->hw); | ||
1276 | |||
1277 | out: | ||
1278 | mutex_unlock(&wl->mutex); | ||
1279 | } | ||
1280 | |||
1281 | static void wl1271_fw_wakeup(struct wl1271 *wl) | ||
1282 | { | ||
1283 | u32 elp_reg; | ||
1284 | |||
1285 | elp_reg = ELPCTRL_WAKE_UP; | ||
1286 | wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg); | ||
1287 | } | ||
1288 | |||
1289 | static int wl1271_setup(struct wl1271 *wl) | ||
1290 | { | ||
1291 | wl->fw_status = kmalloc(sizeof(*wl->fw_status), GFP_KERNEL); | ||
1292 | if (!wl->fw_status) | ||
1293 | return -ENOMEM; | ||
1294 | |||
1295 | wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL); | ||
1296 | if (!wl->tx_res_if) { | ||
1297 | kfree(wl->fw_status); | ||
1298 | return -ENOMEM; | ||
1299 | } | ||
1300 | |||
1301 | return 0; | ||
1302 | } | ||
1303 | |||
1304 | static int wl1271_chip_wakeup(struct wl1271 *wl) | ||
1305 | { | ||
1306 | struct wl1271_partition_set partition; | ||
1307 | int ret = 0; | ||
1308 | |||
1309 | msleep(WL1271_PRE_POWER_ON_SLEEP); | ||
1310 | ret = wl1271_power_on(wl); | ||
1311 | if (ret < 0) | ||
1312 | goto out; | ||
1313 | msleep(WL1271_POWER_ON_SLEEP); | ||
1314 | wl1271_io_reset(wl); | ||
1315 | wl1271_io_init(wl); | ||
1316 | |||
1317 | /* We don't need a real memory partition here, because we only want | ||
1318 | * to use the registers at this point. */ | ||
1319 | memset(&partition, 0, sizeof(partition)); | ||
1320 | partition.reg.start = REGISTERS_BASE; | ||
1321 | partition.reg.size = REGISTERS_DOWN_SIZE; | ||
1322 | wl1271_set_partition(wl, &partition); | ||
1323 | |||
1324 | /* ELP module wake up */ | ||
1325 | wl1271_fw_wakeup(wl); | ||
1326 | |||
1327 | /* whal_FwCtrl_BootSm() */ | ||
1328 | |||
1329 | /* 0. read chip id from CHIP_ID */ | ||
1330 | wl->chip.id = wl1271_read32(wl, CHIP_ID_B); | ||
1331 | |||
1332 | /* 1. check if chip id is valid */ | ||
1333 | |||
1334 | switch (wl->chip.id) { | ||
1335 | case CHIP_ID_1271_PG10: | ||
1336 | wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete", | ||
1337 | wl->chip.id); | ||
1338 | |||
1339 | ret = wl1271_setup(wl); | ||
1340 | if (ret < 0) | ||
1341 | goto out; | ||
1342 | break; | ||
1343 | case CHIP_ID_1271_PG20: | ||
1344 | wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)", | ||
1345 | wl->chip.id); | ||
1346 | |||
1347 | /* | ||
1348 | * 'end-of-transaction flag' and 'LPD mode flag' | ||
1349 | * should be set in wl127x AP mode only | ||
1350 | */ | ||
1351 | if (wl->bss_type == BSS_TYPE_AP_BSS) | ||
1352 | wl->quirks |= (WL12XX_QUIRK_END_OF_TRANSACTION | | ||
1353 | WL12XX_QUIRK_LPD_MODE); | ||
1354 | |||
1355 | ret = wl1271_setup(wl); | ||
1356 | if (ret < 0) | ||
1357 | goto out; | ||
1358 | break; | ||
1359 | case CHIP_ID_1283_PG20: | ||
1360 | wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1283 PG20)", | ||
1361 | wl->chip.id); | ||
1362 | |||
1363 | ret = wl1271_setup(wl); | ||
1364 | if (ret < 0) | ||
1365 | goto out; | ||
1366 | |||
1367 | if (wl1271_set_block_size(wl)) | ||
1368 | wl->quirks |= WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT; | ||
1369 | break; | ||
1370 | case CHIP_ID_1283_PG10: | ||
1371 | default: | ||
1372 | wl1271_warning("unsupported chip id: 0x%x", wl->chip.id); | ||
1373 | ret = -ENODEV; | ||
1374 | goto out; | ||
1375 | } | ||
1376 | |||
1377 | /* Make sure the firmware type matches the BSS type */ | ||
1378 | if (wl->fw == NULL || wl->fw_bss_type != wl->bss_type) { | ||
1379 | ret = wl1271_fetch_firmware(wl); | ||
1380 | if (ret < 0) | ||
1381 | goto out; | ||
1382 | } | ||
1383 | |||
1384 | /* No NVS from netlink, try to get it from the filesystem */ | ||
1385 | if (wl->nvs == NULL) { | ||
1386 | ret = wl1271_fetch_nvs(wl); | ||
1387 | if (ret < 0) | ||
1388 | goto out; | ||
1389 | } | ||
1390 | |||
1391 | out: | ||
1392 | return ret; | ||
1393 | } | ||
1394 | |||
1395 | int wl1271_plt_start(struct wl1271 *wl) | ||
1396 | { | ||
1397 | int retries = WL1271_BOOT_RETRIES; | ||
1398 | int ret; | ||
1399 | |||
1400 | mutex_lock(&wl->mutex); | ||
1401 | |||
1402 | wl1271_notice("power up"); | ||
1403 | |||
1404 | if (wl->state != WL1271_STATE_OFF) { | ||
1405 | wl1271_error("cannot go into PLT state because not " | ||
1406 | "in off state: %d", wl->state); | ||
1407 | ret = -EBUSY; | ||
1408 | goto out; | ||
1409 | } | ||
1410 | |||
1411 | wl->bss_type = BSS_TYPE_STA_BSS; | ||
1412 | |||
1413 | while (retries) { | ||
1414 | retries--; | ||
1415 | ret = wl1271_chip_wakeup(wl); | ||
1416 | if (ret < 0) | ||
1417 | goto power_off; | ||
1418 | |||
1419 | ret = wl1271_boot(wl); | ||
1420 | if (ret < 0) | ||
1421 | goto power_off; | ||
1422 | |||
1423 | ret = wl1271_plt_init(wl); | ||
1424 | if (ret < 0) | ||
1425 | goto irq_disable; | ||
1426 | |||
1427 | wl->state = WL1271_STATE_PLT; | ||
1428 | wl1271_notice("firmware booted in PLT mode (%s)", | ||
1429 | wl->chip.fw_ver_str); | ||
1430 | |||
1431 | goto out; | ||
1432 | |||
1433 | irq_disable: | ||
1434 | mutex_unlock(&wl->mutex); | ||
1435 | /* Unlocking the mutex in the middle of handling is | ||
1436 | inherently unsafe. In this case we deem it safe to do, | ||
1437 | because we need to let any possibly pending IRQ out of | ||
1438 | the system (and while we are WL1271_STATE_OFF the IRQ | ||
1439 | work function will not do anything.) Also, any other | ||
1440 | possible concurrent operations will fail due to the | ||
1441 | current state, hence the wl1271 struct should be safe. */ | ||
1442 | wl1271_disable_interrupts(wl); | ||
1443 | wl1271_flush_deferred_work(wl); | ||
1444 | cancel_work_sync(&wl->netstack_work); | ||
1445 | mutex_lock(&wl->mutex); | ||
1446 | power_off: | ||
1447 | wl1271_power_off(wl); | ||
1448 | } | ||
1449 | |||
1450 | wl1271_error("firmware boot in PLT mode failed despite %d retries", | ||
1451 | WL1271_BOOT_RETRIES); | ||
1452 | out: | ||
1453 | mutex_unlock(&wl->mutex); | ||
1454 | |||
1455 | return ret; | ||
1456 | } | ||
1457 | |||
1458 | static int __wl1271_plt_stop(struct wl1271 *wl) | ||
1459 | { | ||
1460 | int ret = 0; | ||
1461 | |||
1462 | wl1271_notice("power down"); | ||
1463 | |||
1464 | if (wl->state != WL1271_STATE_PLT) { | ||
1465 | wl1271_error("cannot power down because not in PLT " | ||
1466 | "state: %d", wl->state); | ||
1467 | ret = -EBUSY; | ||
1468 | goto out; | ||
1469 | } | ||
1470 | |||
1471 | wl1271_power_off(wl); | ||
1472 | |||
1473 | wl->state = WL1271_STATE_OFF; | ||
1474 | wl->rx_counter = 0; | ||
1475 | |||
1476 | mutex_unlock(&wl->mutex); | ||
1477 | wl1271_disable_interrupts(wl); | ||
1478 | wl1271_flush_deferred_work(wl); | ||
1479 | cancel_work_sync(&wl->netstack_work); | ||
1480 | cancel_work_sync(&wl->recovery_work); | ||
1481 | mutex_lock(&wl->mutex); | ||
1482 | out: | ||
1483 | return ret; | ||
1484 | } | ||
1485 | |||
1486 | int wl1271_plt_stop(struct wl1271 *wl) | ||
1487 | { | ||
1488 | int ret; | ||
1489 | |||
1490 | mutex_lock(&wl->mutex); | ||
1491 | ret = __wl1271_plt_stop(wl); | ||
1492 | mutex_unlock(&wl->mutex); | ||
1493 | return ret; | ||
1494 | } | ||
1495 | |||
1496 | static void wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb) | ||
1497 | { | ||
1498 | struct wl1271 *wl = hw->priv; | ||
1499 | unsigned long flags; | ||
1500 | int q, mapping; | ||
1501 | u8 hlid = 0; | ||
1502 | |||
1503 | mapping = skb_get_queue_mapping(skb); | ||
1504 | q = wl1271_tx_get_queue(mapping); | ||
1505 | |||
1506 | if (wl->bss_type == BSS_TYPE_AP_BSS) | ||
1507 | hlid = wl1271_tx_get_hlid(skb); | ||
1508 | |||
1509 | spin_lock_irqsave(&wl->wl_lock, flags); | ||
1510 | |||
1511 | wl->tx_queue_count[q]++; | ||
1512 | |||
1513 | /* | ||
1514 | * The workqueue is slow to process the tx_queue and we need stop | ||
1515 | * the queue here, otherwise the queue will get too long. | ||
1516 | */ | ||
1517 | if (wl->tx_queue_count[q] >= WL1271_TX_QUEUE_HIGH_WATERMARK) { | ||
1518 | wl1271_debug(DEBUG_TX, "op_tx: stopping queues for q %d", q); | ||
1519 | ieee80211_stop_queue(wl->hw, mapping); | ||
1520 | set_bit(q, &wl->stopped_queues_map); | ||
1521 | } | ||
1522 | |||
1523 | /* queue the packet */ | ||
1524 | if (wl->bss_type == BSS_TYPE_AP_BSS) { | ||
1525 | wl1271_debug(DEBUG_TX, "queue skb hlid %d q %d", hlid, q); | ||
1526 | skb_queue_tail(&wl->links[hlid].tx_queue[q], skb); | ||
1527 | } else { | ||
1528 | skb_queue_tail(&wl->tx_queue[q], skb); | ||
1529 | } | ||
1530 | |||
1531 | /* | ||
1532 | * The chip specific setup must run before the first TX packet - | ||
1533 | * before that, the tx_work will not be initialized! | ||
1534 | */ | ||
1535 | |||
1536 | if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) && | ||
1537 | !test_bit(WL1271_FLAG_TX_PENDING, &wl->flags)) | ||
1538 | ieee80211_queue_work(wl->hw, &wl->tx_work); | ||
1539 | |||
1540 | spin_unlock_irqrestore(&wl->wl_lock, flags); | ||
1541 | } | ||
1542 | |||
1543 | int wl1271_tx_dummy_packet(struct wl1271 *wl) | ||
1544 | { | ||
1545 | unsigned long flags; | ||
1546 | int q = wl1271_tx_get_queue(skb_get_queue_mapping(wl->dummy_packet)); | ||
1547 | |||
1548 | spin_lock_irqsave(&wl->wl_lock, flags); | ||
1549 | set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags); | ||
1550 | wl->tx_queue_count[q]++; | ||
1551 | spin_unlock_irqrestore(&wl->wl_lock, flags); | ||
1552 | |||
1553 | /* The FW is low on RX memory blocks, so send the dummy packet asap */ | ||
1554 | if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags)) | ||
1555 | wl1271_tx_work_locked(wl); | ||
1556 | |||
1557 | /* | ||
1558 | * If the FW TX is busy, TX work will be scheduled by the threaded | ||
1559 | * interrupt handler function | ||
1560 | */ | ||
1561 | return 0; | ||
1562 | } | ||
1563 | |||
1564 | /* | ||
1565 | * The size of the dummy packet should be at least 1400 bytes. However, in | ||
1566 | * order to minimize the number of bus transactions, aligning it to 512 bytes | ||
1567 | * boundaries could be beneficial, performance wise | ||
1568 | */ | ||
1569 | #define TOTAL_TX_DUMMY_PACKET_SIZE (ALIGN(1400, 512)) | ||
1570 | |||
1571 | static struct sk_buff *wl12xx_alloc_dummy_packet(struct wl1271 *wl) | ||
1572 | { | ||
1573 | struct sk_buff *skb; | ||
1574 | struct ieee80211_hdr_3addr *hdr; | ||
1575 | unsigned int dummy_packet_size; | ||
1576 | |||
1577 | dummy_packet_size = TOTAL_TX_DUMMY_PACKET_SIZE - | ||
1578 | sizeof(struct wl1271_tx_hw_descr) - sizeof(*hdr); | ||
1579 | |||
1580 | skb = dev_alloc_skb(TOTAL_TX_DUMMY_PACKET_SIZE); | ||
1581 | if (!skb) { | ||
1582 | wl1271_warning("Failed to allocate a dummy packet skb"); | ||
1583 | return NULL; | ||
1584 | } | ||
1585 | |||
1586 | skb_reserve(skb, sizeof(struct wl1271_tx_hw_descr)); | ||
1587 | |||
1588 | hdr = (struct ieee80211_hdr_3addr *) skb_put(skb, sizeof(*hdr)); | ||
1589 | memset(hdr, 0, sizeof(*hdr)); | ||
1590 | hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | | ||
1591 | IEEE80211_STYPE_NULLFUNC | | ||
1592 | IEEE80211_FCTL_TODS); | ||
1593 | |||
1594 | memset(skb_put(skb, dummy_packet_size), 0, dummy_packet_size); | ||
1595 | |||
1596 | /* Dummy packets require the TID to be management */ | ||
1597 | skb->priority = WL1271_TID_MGMT; | ||
1598 | |||
1599 | /* Initialize all fields that might be used */ | ||
1600 | skb_set_queue_mapping(skb, 0); | ||
1601 | memset(IEEE80211_SKB_CB(skb), 0, sizeof(struct ieee80211_tx_info)); | ||
1602 | |||
1603 | return skb; | ||
1604 | } | ||
1605 | |||
1606 | |||
1607 | static struct notifier_block wl1271_dev_notifier = { | ||
1608 | .notifier_call = wl1271_dev_notify, | ||
1609 | }; | ||
1610 | |||
1611 | #ifdef CONFIG_PM | ||
1612 | static int wl1271_configure_suspend_sta(struct wl1271 *wl) | ||
1613 | { | ||
1614 | int ret = 0; | ||
1615 | |||
1616 | mutex_lock(&wl->mutex); | ||
1617 | |||
1618 | if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) | ||
1619 | goto out_unlock; | ||
1620 | |||
1621 | ret = wl1271_ps_elp_wakeup(wl); | ||
1622 | if (ret < 0) | ||
1623 | goto out_unlock; | ||
1624 | |||
1625 | /* enter psm if needed*/ | ||
1626 | if (!test_bit(WL1271_FLAG_PSM, &wl->flags)) { | ||
1627 | DECLARE_COMPLETION_ONSTACK(compl); | ||
1628 | |||
1629 | wl->ps_compl = &compl; | ||
1630 | ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE, | ||
1631 | wl->basic_rate, true); | ||
1632 | if (ret < 0) | ||
1633 | goto out_sleep; | ||
1634 | |||
1635 | /* we must unlock here so we will be able to get events */ | ||
1636 | wl1271_ps_elp_sleep(wl); | ||
1637 | mutex_unlock(&wl->mutex); | ||
1638 | |||
1639 | ret = wait_for_completion_timeout( | ||
1640 | &compl, msecs_to_jiffies(WL1271_PS_COMPLETE_TIMEOUT)); | ||
1641 | if (ret <= 0) { | ||
1642 | wl1271_warning("couldn't enter ps mode!"); | ||
1643 | ret = -EBUSY; | ||
1644 | goto out; | ||
1645 | } | ||
1646 | |||
1647 | /* take mutex again, and wakeup */ | ||
1648 | mutex_lock(&wl->mutex); | ||
1649 | |||
1650 | ret = wl1271_ps_elp_wakeup(wl); | ||
1651 | if (ret < 0) | ||
1652 | goto out_unlock; | ||
1653 | } | ||
1654 | out_sleep: | ||
1655 | wl1271_ps_elp_sleep(wl); | ||
1656 | out_unlock: | ||
1657 | mutex_unlock(&wl->mutex); | ||
1658 | out: | ||
1659 | return ret; | ||
1660 | |||
1661 | } | ||
1662 | |||
1663 | static int wl1271_configure_suspend_ap(struct wl1271 *wl) | ||
1664 | { | ||
1665 | int ret = 0; | ||
1666 | |||
1667 | mutex_lock(&wl->mutex); | ||
1668 | |||
1669 | if (!test_bit(WL1271_FLAG_AP_STARTED, &wl->flags)) | ||
1670 | goto out_unlock; | ||
1671 | |||
1672 | ret = wl1271_ps_elp_wakeup(wl); | ||
1673 | if (ret < 0) | ||
1674 | goto out_unlock; | ||
1675 | |||
1676 | ret = wl1271_acx_set_ap_beacon_filter(wl, true); | ||
1677 | |||
1678 | wl1271_ps_elp_sleep(wl); | ||
1679 | out_unlock: | ||
1680 | mutex_unlock(&wl->mutex); | ||
1681 | return ret; | ||
1682 | |||
1683 | } | ||
1684 | |||
1685 | static int wl1271_configure_suspend(struct wl1271 *wl) | ||
1686 | { | ||
1687 | if (wl->bss_type == BSS_TYPE_STA_BSS) | ||
1688 | return wl1271_configure_suspend_sta(wl); | ||
1689 | if (wl->bss_type == BSS_TYPE_AP_BSS) | ||
1690 | return wl1271_configure_suspend_ap(wl); | ||
1691 | return 0; | ||
1692 | } | ||
1693 | |||
1694 | static void wl1271_configure_resume(struct wl1271 *wl) | ||
1695 | { | ||
1696 | int ret; | ||
1697 | bool is_sta = wl->bss_type == BSS_TYPE_STA_BSS; | ||
1698 | bool is_ap = wl->bss_type == BSS_TYPE_AP_BSS; | ||
1699 | |||
1700 | if (!is_sta && !is_ap) | ||
1701 | return; | ||
1702 | |||
1703 | mutex_lock(&wl->mutex); | ||
1704 | ret = wl1271_ps_elp_wakeup(wl); | ||
1705 | if (ret < 0) | ||
1706 | goto out; | ||
1707 | |||
1708 | if (is_sta) { | ||
1709 | /* exit psm if it wasn't configured */ | ||
1710 | if (!test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags)) | ||
1711 | wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE, | ||
1712 | wl->basic_rate, true); | ||
1713 | } else if (is_ap) { | ||
1714 | wl1271_acx_set_ap_beacon_filter(wl, false); | ||
1715 | } | ||
1716 | |||
1717 | wl1271_ps_elp_sleep(wl); | ||
1718 | out: | ||
1719 | mutex_unlock(&wl->mutex); | ||
1720 | } | ||
1721 | |||
1722 | static int wl1271_op_suspend(struct ieee80211_hw *hw, | ||
1723 | struct cfg80211_wowlan *wow) | ||
1724 | { | ||
1725 | struct wl1271 *wl = hw->priv; | ||
1726 | int ret; | ||
1727 | |||
1728 | wl1271_debug(DEBUG_MAC80211, "mac80211 suspend wow=%d", !!wow); | ||
1729 | WARN_ON(!wow || !wow->any); | ||
1730 | |||
1731 | wl->wow_enabled = true; | ||
1732 | ret = wl1271_configure_suspend(wl); | ||
1733 | if (ret < 0) { | ||
1734 | wl1271_warning("couldn't prepare device to suspend"); | ||
1735 | return ret; | ||
1736 | } | ||
1737 | /* flush any remaining work */ | ||
1738 | wl1271_debug(DEBUG_MAC80211, "flushing remaining works"); | ||
1739 | |||
1740 | /* | ||
1741 | * disable and re-enable interrupts in order to flush | ||
1742 | * the threaded_irq | ||
1743 | */ | ||
1744 | wl1271_disable_interrupts(wl); | ||
1745 | |||
1746 | /* | ||
1747 | * set suspended flag to avoid triggering a new threaded_irq | ||
1748 | * work. no need for spinlock as interrupts are disabled. | ||
1749 | */ | ||
1750 | set_bit(WL1271_FLAG_SUSPENDED, &wl->flags); | ||
1751 | |||
1752 | wl1271_enable_interrupts(wl); | ||
1753 | flush_work(&wl->tx_work); | ||
1754 | flush_delayed_work(&wl->pspoll_work); | ||
1755 | flush_delayed_work(&wl->elp_work); | ||
1756 | |||
1757 | return 0; | ||
1758 | } | ||
1759 | |||
1760 | static int wl1271_op_resume(struct ieee80211_hw *hw) | ||
1761 | { | ||
1762 | struct wl1271 *wl = hw->priv; | ||
1763 | unsigned long flags; | ||
1764 | bool run_irq_work = false; | ||
1765 | |||
1766 | wl1271_debug(DEBUG_MAC80211, "mac80211 resume wow=%d", | ||
1767 | wl->wow_enabled); | ||
1768 | WARN_ON(!wl->wow_enabled); | ||
1769 | |||
1770 | /* | ||
1771 | * re-enable irq_work enqueuing, and call irq_work directly if | ||
1772 | * there is a pending work. | ||
1773 | */ | ||
1774 | spin_lock_irqsave(&wl->wl_lock, flags); | ||
1775 | clear_bit(WL1271_FLAG_SUSPENDED, &wl->flags); | ||
1776 | if (test_and_clear_bit(WL1271_FLAG_PENDING_WORK, &wl->flags)) | ||
1777 | run_irq_work = true; | ||
1778 | spin_unlock_irqrestore(&wl->wl_lock, flags); | ||
1779 | |||
1780 | if (run_irq_work) { | ||
1781 | wl1271_debug(DEBUG_MAC80211, | ||
1782 | "run postponed irq_work directly"); | ||
1783 | wl1271_irq(0, wl); | ||
1784 | wl1271_enable_interrupts(wl); | ||
1785 | } | ||
1786 | wl1271_configure_resume(wl); | ||
1787 | wl->wow_enabled = false; | ||
1788 | |||
1789 | return 0; | ||
1790 | } | ||
1791 | #endif | ||
1792 | |||
1793 | static int wl1271_op_start(struct ieee80211_hw *hw) | ||
1794 | { | ||
1795 | wl1271_debug(DEBUG_MAC80211, "mac80211 start"); | ||
1796 | |||
1797 | /* | ||
1798 | * We have to delay the booting of the hardware because | ||
1799 | * we need to know the local MAC address before downloading and | ||
1800 | * initializing the firmware. The MAC address cannot be changed | ||
1801 | * after boot, and without the proper MAC address, the firmware | ||
1802 | * will not function properly. | ||
1803 | * | ||
1804 | * The MAC address is first known when the corresponding interface | ||
1805 | * is added. That is where we will initialize the hardware. | ||
1806 | * | ||
1807 | * In addition, we currently have different firmwares for AP and managed | ||
1808 | * operation. We will know which to boot according to interface type. | ||
1809 | */ | ||
1810 | |||
1811 | return 0; | ||
1812 | } | ||
1813 | |||
1814 | static void wl1271_op_stop(struct ieee80211_hw *hw) | ||
1815 | { | ||
1816 | wl1271_debug(DEBUG_MAC80211, "mac80211 stop"); | ||
1817 | } | ||
1818 | |||
1819 | static int wl1271_op_add_interface(struct ieee80211_hw *hw, | ||
1820 | struct ieee80211_vif *vif) | ||
1821 | { | ||
1822 | struct wl1271 *wl = hw->priv; | ||
1823 | struct wiphy *wiphy = hw->wiphy; | ||
1824 | int retries = WL1271_BOOT_RETRIES; | ||
1825 | int ret = 0; | ||
1826 | bool booted = false; | ||
1827 | |||
1828 | wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM", | ||
1829 | vif->type, vif->addr); | ||
1830 | |||
1831 | mutex_lock(&wl->mutex); | ||
1832 | if (wl->vif) { | ||
1833 | wl1271_debug(DEBUG_MAC80211, | ||
1834 | "multiple vifs are not supported yet"); | ||
1835 | ret = -EBUSY; | ||
1836 | goto out; | ||
1837 | } | ||
1838 | |||
1839 | /* | ||
1840 | * in some very corner case HW recovery scenarios its possible to | ||
1841 | * get here before __wl1271_op_remove_interface is complete, so | ||
1842 | * opt out if that is the case. | ||
1843 | */ | ||
1844 | if (test_bit(WL1271_FLAG_IF_INITIALIZED, &wl->flags)) { | ||
1845 | ret = -EBUSY; | ||
1846 | goto out; | ||
1847 | } | ||
1848 | |||
1849 | switch (vif->type) { | ||
1850 | case NL80211_IFTYPE_STATION: | ||
1851 | wl->bss_type = BSS_TYPE_STA_BSS; | ||
1852 | wl->set_bss_type = BSS_TYPE_STA_BSS; | ||
1853 | break; | ||
1854 | case NL80211_IFTYPE_ADHOC: | ||
1855 | wl->bss_type = BSS_TYPE_IBSS; | ||
1856 | wl->set_bss_type = BSS_TYPE_STA_BSS; | ||
1857 | break; | ||
1858 | case NL80211_IFTYPE_AP: | ||
1859 | wl->bss_type = BSS_TYPE_AP_BSS; | ||
1860 | break; | ||
1861 | default: | ||
1862 | ret = -EOPNOTSUPP; | ||
1863 | goto out; | ||
1864 | } | ||
1865 | |||
1866 | memcpy(wl->mac_addr, vif->addr, ETH_ALEN); | ||
1867 | |||
1868 | if (wl->state != WL1271_STATE_OFF) { | ||
1869 | wl1271_error("cannot start because not in off state: %d", | ||
1870 | wl->state); | ||
1871 | ret = -EBUSY; | ||
1872 | goto out; | ||
1873 | } | ||
1874 | |||
1875 | while (retries) { | ||
1876 | retries--; | ||
1877 | ret = wl1271_chip_wakeup(wl); | ||
1878 | if (ret < 0) | ||
1879 | goto power_off; | ||
1880 | |||
1881 | ret = wl1271_boot(wl); | ||
1882 | if (ret < 0) | ||
1883 | goto power_off; | ||
1884 | |||
1885 | ret = wl1271_hw_init(wl); | ||
1886 | if (ret < 0) | ||
1887 | goto irq_disable; | ||
1888 | |||
1889 | booted = true; | ||
1890 | break; | ||
1891 | |||
1892 | irq_disable: | ||
1893 | mutex_unlock(&wl->mutex); | ||
1894 | /* Unlocking the mutex in the middle of handling is | ||
1895 | inherently unsafe. In this case we deem it safe to do, | ||
1896 | because we need to let any possibly pending IRQ out of | ||
1897 | the system (and while we are WL1271_STATE_OFF the IRQ | ||
1898 | work function will not do anything.) Also, any other | ||
1899 | possible concurrent operations will fail due to the | ||
1900 | current state, hence the wl1271 struct should be safe. */ | ||
1901 | wl1271_disable_interrupts(wl); | ||
1902 | wl1271_flush_deferred_work(wl); | ||
1903 | cancel_work_sync(&wl->netstack_work); | ||
1904 | mutex_lock(&wl->mutex); | ||
1905 | power_off: | ||
1906 | wl1271_power_off(wl); | ||
1907 | } | ||
1908 | |||
1909 | if (!booted) { | ||
1910 | wl1271_error("firmware boot failed despite %d retries", | ||
1911 | WL1271_BOOT_RETRIES); | ||
1912 | goto out; | ||
1913 | } | ||
1914 | |||
1915 | wl->vif = vif; | ||
1916 | wl->state = WL1271_STATE_ON; | ||
1917 | set_bit(WL1271_FLAG_IF_INITIALIZED, &wl->flags); | ||
1918 | wl1271_info("firmware booted (%s)", wl->chip.fw_ver_str); | ||
1919 | |||
1920 | /* update hw/fw version info in wiphy struct */ | ||
1921 | wiphy->hw_version = wl->chip.id; | ||
1922 | strncpy(wiphy->fw_version, wl->chip.fw_ver_str, | ||
1923 | sizeof(wiphy->fw_version)); | ||
1924 | |||
1925 | /* | ||
1926 | * Now we know if 11a is supported (info from the NVS), so disable | ||
1927 | * 11a channels if not supported | ||
1928 | */ | ||
1929 | if (!wl->enable_11a) | ||
1930 | wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels = 0; | ||
1931 | |||
1932 | wl1271_debug(DEBUG_MAC80211, "11a is %ssupported", | ||
1933 | wl->enable_11a ? "" : "not "); | ||
1934 | |||
1935 | out: | ||
1936 | mutex_unlock(&wl->mutex); | ||
1937 | |||
1938 | mutex_lock(&wl_list_mutex); | ||
1939 | if (!ret) | ||
1940 | list_add(&wl->list, &wl_list); | ||
1941 | mutex_unlock(&wl_list_mutex); | ||
1942 | |||
1943 | return ret; | ||
1944 | } | ||
1945 | |||
1946 | static void __wl1271_op_remove_interface(struct wl1271 *wl, | ||
1947 | bool reset_tx_queues) | ||
1948 | { | ||
1949 | int i; | ||
1950 | |||
1951 | wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface"); | ||
1952 | |||
1953 | /* because of hardware recovery, we may get here twice */ | ||
1954 | if (wl->state != WL1271_STATE_ON) | ||
1955 | return; | ||
1956 | |||
1957 | wl1271_info("down"); | ||
1958 | |||
1959 | mutex_lock(&wl_list_mutex); | ||
1960 | list_del(&wl->list); | ||
1961 | mutex_unlock(&wl_list_mutex); | ||
1962 | |||
1963 | /* enable dyn ps just in case (if left on due to fw crash etc) */ | ||
1964 | if (wl->bss_type == BSS_TYPE_STA_BSS) | ||
1965 | ieee80211_enable_dyn_ps(wl->vif); | ||
1966 | |||
1967 | if (wl->scan.state != WL1271_SCAN_STATE_IDLE) { | ||
1968 | wl->scan.state = WL1271_SCAN_STATE_IDLE; | ||
1969 | memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch)); | ||
1970 | wl->scan.req = NULL; | ||
1971 | ieee80211_scan_completed(wl->hw, true); | ||
1972 | } | ||
1973 | |||
1974 | /* | ||
1975 | * this must be before the cancel_work calls below, so that the work | ||
1976 | * functions don't perform further work. | ||
1977 | */ | ||
1978 | wl->state = WL1271_STATE_OFF; | ||
1979 | |||
1980 | mutex_unlock(&wl->mutex); | ||
1981 | |||
1982 | wl1271_disable_interrupts(wl); | ||
1983 | wl1271_flush_deferred_work(wl); | ||
1984 | cancel_delayed_work_sync(&wl->scan_complete_work); | ||
1985 | cancel_work_sync(&wl->netstack_work); | ||
1986 | cancel_work_sync(&wl->tx_work); | ||
1987 | del_timer_sync(&wl->rx_streaming_timer); | ||
1988 | cancel_work_sync(&wl->rx_streaming_enable_work); | ||
1989 | cancel_work_sync(&wl->rx_streaming_disable_work); | ||
1990 | cancel_delayed_work_sync(&wl->pspoll_work); | ||
1991 | cancel_delayed_work_sync(&wl->elp_work); | ||
1992 | |||
1993 | mutex_lock(&wl->mutex); | ||
1994 | |||
1995 | /* let's notify MAC80211 about the remaining pending TX frames */ | ||
1996 | wl1271_tx_reset(wl, reset_tx_queues); | ||
1997 | wl1271_power_off(wl); | ||
1998 | |||
1999 | memset(wl->bssid, 0, ETH_ALEN); | ||
2000 | memset(wl->ssid, 0, IW_ESSID_MAX_SIZE + 1); | ||
2001 | wl->ssid_len = 0; | ||
2002 | wl->bss_type = MAX_BSS_TYPE; | ||
2003 | wl->set_bss_type = MAX_BSS_TYPE; | ||
2004 | wl->band = IEEE80211_BAND_2GHZ; | ||
2005 | |||
2006 | wl->rx_counter = 0; | ||
2007 | wl->psm_entry_retry = 0; | ||
2008 | wl->power_level = WL1271_DEFAULT_POWER_LEVEL; | ||
2009 | wl->tx_blocks_available = 0; | ||
2010 | wl->tx_results_count = 0; | ||
2011 | wl->tx_packets_count = 0; | ||
2012 | wl->time_offset = 0; | ||
2013 | wl->session_counter = 0; | ||
2014 | wl->rate_set = CONF_TX_RATE_MASK_BASIC; | ||
2015 | wl->vif = NULL; | ||
2016 | wl->filters = 0; | ||
2017 | wl1271_free_ap_keys(wl); | ||
2018 | memset(wl->ap_hlid_map, 0, sizeof(wl->ap_hlid_map)); | ||
2019 | wl->ap_fw_ps_map = 0; | ||
2020 | wl->ap_ps_map = 0; | ||
2021 | wl->sched_scanning = false; | ||
2022 | |||
2023 | /* | ||
2024 | * this is performed after the cancel_work calls and the associated | ||
2025 | * mutex_lock, so that wl1271_op_add_interface does not accidentally | ||
2026 | * get executed before all these vars have been reset. | ||
2027 | */ | ||
2028 | wl->flags = 0; | ||
2029 | |||
2030 | for (i = 0; i < NUM_TX_QUEUES; i++) { | ||
2031 | wl->tx_blocks_freed[i] = 0; | ||
2032 | wl->tx_allocated_blocks[i] = 0; | ||
2033 | } | ||
2034 | |||
2035 | wl1271_debugfs_reset(wl); | ||
2036 | |||
2037 | kfree(wl->fw_status); | ||
2038 | wl->fw_status = NULL; | ||
2039 | kfree(wl->tx_res_if); | ||
2040 | wl->tx_res_if = NULL; | ||
2041 | kfree(wl->target_mem_map); | ||
2042 | wl->target_mem_map = NULL; | ||
2043 | } | ||
2044 | |||
2045 | static void wl1271_op_remove_interface(struct ieee80211_hw *hw, | ||
2046 | struct ieee80211_vif *vif) | ||
2047 | { | ||
2048 | struct wl1271 *wl = hw->priv; | ||
2049 | |||
2050 | mutex_lock(&wl->mutex); | ||
2051 | /* | ||
2052 | * wl->vif can be null here if someone shuts down the interface | ||
2053 | * just when hardware recovery has been started. | ||
2054 | */ | ||
2055 | if (wl->vif) { | ||
2056 | WARN_ON(wl->vif != vif); | ||
2057 | __wl1271_op_remove_interface(wl, true); | ||
2058 | } | ||
2059 | |||
2060 | mutex_unlock(&wl->mutex); | ||
2061 | cancel_work_sync(&wl->recovery_work); | ||
2062 | } | ||
2063 | |||
2064 | void wl1271_configure_filters(struct wl1271 *wl, unsigned int filters) | ||
2065 | { | ||
2066 | wl1271_set_default_filters(wl); | ||
2067 | |||
2068 | /* combine requested filters with current filter config */ | ||
2069 | filters = wl->filters | filters; | ||
2070 | |||
2071 | wl1271_debug(DEBUG_FILTERS, "RX filters set: "); | ||
2072 | |||
2073 | if (filters & FIF_PROMISC_IN_BSS) { | ||
2074 | wl1271_debug(DEBUG_FILTERS, " - FIF_PROMISC_IN_BSS"); | ||
2075 | wl->rx_config &= ~CFG_UNI_FILTER_EN; | ||
2076 | wl->rx_config |= CFG_BSSID_FILTER_EN; | ||
2077 | } | ||
2078 | if (filters & FIF_BCN_PRBRESP_PROMISC) { | ||
2079 | wl1271_debug(DEBUG_FILTERS, " - FIF_BCN_PRBRESP_PROMISC"); | ||
2080 | wl->rx_config &= ~CFG_BSSID_FILTER_EN; | ||
2081 | wl->rx_config &= ~CFG_SSID_FILTER_EN; | ||
2082 | } | ||
2083 | if (filters & FIF_OTHER_BSS) { | ||
2084 | wl1271_debug(DEBUG_FILTERS, " - FIF_OTHER_BSS"); | ||
2085 | wl->rx_config &= ~CFG_BSSID_FILTER_EN; | ||
2086 | } | ||
2087 | if (filters & FIF_CONTROL) { | ||
2088 | wl1271_debug(DEBUG_FILTERS, " - FIF_CONTROL"); | ||
2089 | wl->rx_filter |= CFG_RX_CTL_EN; | ||
2090 | } | ||
2091 | if (filters & FIF_FCSFAIL) { | ||
2092 | wl1271_debug(DEBUG_FILTERS, " - FIF_FCSFAIL"); | ||
2093 | wl->rx_filter |= CFG_RX_FCS_ERROR; | ||
2094 | } | ||
2095 | } | ||
2096 | |||
2097 | static int wl1271_dummy_join(struct wl1271 *wl) | ||
2098 | { | ||
2099 | int ret = 0; | ||
2100 | /* we need to use a dummy BSSID for now */ | ||
2101 | static const u8 dummy_bssid[ETH_ALEN] = { 0x0b, 0xad, 0xde, | ||
2102 | 0xad, 0xbe, 0xef }; | ||
2103 | |||
2104 | memcpy(wl->bssid, dummy_bssid, ETH_ALEN); | ||
2105 | |||
2106 | /* pass through frames from all BSS */ | ||
2107 | wl1271_configure_filters(wl, FIF_OTHER_BSS); | ||
2108 | |||
2109 | ret = wl1271_cmd_join(wl, wl->set_bss_type); | ||
2110 | if (ret < 0) | ||
2111 | goto out; | ||
2112 | |||
2113 | set_bit(WL1271_FLAG_JOINED, &wl->flags); | ||
2114 | |||
2115 | out: | ||
2116 | return ret; | ||
2117 | } | ||
2118 | |||
2119 | static int wl1271_join(struct wl1271 *wl, bool set_assoc) | ||
2120 | { | ||
2121 | int ret; | ||
2122 | |||
2123 | /* | ||
2124 | * One of the side effects of the JOIN command is that is clears | ||
2125 | * WPA/WPA2 keys from the chipset. Performing a JOIN while associated | ||
2126 | * to a WPA/WPA2 access point will therefore kill the data-path. | ||
2127 | * Currently the only valid scenario for JOIN during association | ||
2128 | * is on roaming, in which case we will also be given new keys. | ||
2129 | * Keep the below message for now, unless it starts bothering | ||
2130 | * users who really like to roam a lot :) | ||
2131 | */ | ||
2132 | if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) | ||
2133 | wl1271_info("JOIN while associated."); | ||
2134 | |||
2135 | if (set_assoc) | ||
2136 | set_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags); | ||
2137 | |||
2138 | ret = wl1271_cmd_join(wl, wl->set_bss_type); | ||
2139 | if (ret < 0) | ||
2140 | goto out; | ||
2141 | |||
2142 | set_bit(WL1271_FLAG_JOINED, &wl->flags); | ||
2143 | |||
2144 | if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) | ||
2145 | goto out; | ||
2146 | |||
2147 | /* | ||
2148 | * The join command disable the keep-alive mode, shut down its process, | ||
2149 | * and also clear the template config, so we need to reset it all after | ||
2150 | * the join. The acx_aid starts the keep-alive process, and the order | ||
2151 | * of the commands below is relevant. | ||
2152 | */ | ||
2153 | ret = wl1271_acx_keep_alive_mode(wl, true); | ||
2154 | if (ret < 0) | ||
2155 | goto out; | ||
2156 | |||
2157 | ret = wl1271_acx_aid(wl, wl->aid); | ||
2158 | if (ret < 0) | ||
2159 | goto out; | ||
2160 | |||
2161 | ret = wl1271_cmd_build_klv_null_data(wl); | ||
2162 | if (ret < 0) | ||
2163 | goto out; | ||
2164 | |||
2165 | ret = wl1271_acx_keep_alive_config(wl, CMD_TEMPL_KLV_IDX_NULL_DATA, | ||
2166 | ACX_KEEP_ALIVE_TPL_VALID); | ||
2167 | if (ret < 0) | ||
2168 | goto out; | ||
2169 | |||
2170 | out: | ||
2171 | return ret; | ||
2172 | } | ||
2173 | |||
2174 | static int wl1271_unjoin(struct wl1271 *wl) | ||
2175 | { | ||
2176 | int ret; | ||
2177 | |||
2178 | /* to stop listening to a channel, we disconnect */ | ||
2179 | ret = wl1271_cmd_disconnect(wl); | ||
2180 | if (ret < 0) | ||
2181 | goto out; | ||
2182 | |||
2183 | clear_bit(WL1271_FLAG_JOINED, &wl->flags); | ||
2184 | memset(wl->bssid, 0, ETH_ALEN); | ||
2185 | |||
2186 | /* reset TX security counters on a clean disconnect */ | ||
2187 | wl->tx_security_last_seq_lsb = 0; | ||
2188 | wl->tx_security_seq = 0; | ||
2189 | |||
2190 | /* stop filtering packets based on bssid */ | ||
2191 | wl1271_configure_filters(wl, FIF_OTHER_BSS); | ||
2192 | |||
2193 | out: | ||
2194 | return ret; | ||
2195 | } | ||
2196 | |||
2197 | static void wl1271_set_band_rate(struct wl1271 *wl) | ||
2198 | { | ||
2199 | if (wl->band == IEEE80211_BAND_2GHZ) | ||
2200 | wl->basic_rate_set = wl->conf.tx.basic_rate; | ||
2201 | else | ||
2202 | wl->basic_rate_set = wl->conf.tx.basic_rate_5; | ||
2203 | } | ||
2204 | |||
2205 | static int wl1271_sta_handle_idle(struct wl1271 *wl, bool idle) | ||
2206 | { | ||
2207 | int ret; | ||
2208 | |||
2209 | if (idle) { | ||
2210 | if (test_bit(WL1271_FLAG_JOINED, &wl->flags)) { | ||
2211 | ret = wl1271_unjoin(wl); | ||
2212 | if (ret < 0) | ||
2213 | goto out; | ||
2214 | } | ||
2215 | wl->rate_set = wl1271_tx_min_rate_get(wl); | ||
2216 | ret = wl1271_acx_sta_rate_policies(wl); | ||
2217 | if (ret < 0) | ||
2218 | goto out; | ||
2219 | ret = wl1271_acx_keep_alive_config( | ||
2220 | wl, CMD_TEMPL_KLV_IDX_NULL_DATA, | ||
2221 | ACX_KEEP_ALIVE_TPL_INVALID); | ||
2222 | if (ret < 0) | ||
2223 | goto out; | ||
2224 | set_bit(WL1271_FLAG_IDLE, &wl->flags); | ||
2225 | } else { | ||
2226 | /* increment the session counter */ | ||
2227 | wl->session_counter++; | ||
2228 | if (wl->session_counter >= SESSION_COUNTER_MAX) | ||
2229 | wl->session_counter = 0; | ||
2230 | |||
2231 | /* The current firmware only supports sched_scan in idle */ | ||
2232 | if (wl->sched_scanning) { | ||
2233 | wl1271_scan_sched_scan_stop(wl); | ||
2234 | ieee80211_sched_scan_stopped(wl->hw); | ||
2235 | } | ||
2236 | |||
2237 | ret = wl1271_dummy_join(wl); | ||
2238 | if (ret < 0) | ||
2239 | goto out; | ||
2240 | clear_bit(WL1271_FLAG_IDLE, &wl->flags); | ||
2241 | } | ||
2242 | |||
2243 | out: | ||
2244 | return ret; | ||
2245 | } | ||
2246 | |||
2247 | static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed) | ||
2248 | { | ||
2249 | struct wl1271 *wl = hw->priv; | ||
2250 | struct ieee80211_conf *conf = &hw->conf; | ||
2251 | int channel, ret = 0; | ||
2252 | bool is_ap; | ||
2253 | |||
2254 | channel = ieee80211_frequency_to_channel(conf->channel->center_freq); | ||
2255 | |||
2256 | wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d %s" | ||
2257 | " changed 0x%x", | ||
2258 | channel, | ||
2259 | conf->flags & IEEE80211_CONF_PS ? "on" : "off", | ||
2260 | conf->power_level, | ||
2261 | conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use", | ||
2262 | changed); | ||
2263 | |||
2264 | /* | ||
2265 | * mac80211 will go to idle nearly immediately after transmitting some | ||
2266 | * frames, such as the deauth. To make sure those frames reach the air, | ||
2267 | * wait here until the TX queue is fully flushed. | ||
2268 | */ | ||
2269 | if ((changed & IEEE80211_CONF_CHANGE_IDLE) && | ||
2270 | (conf->flags & IEEE80211_CONF_IDLE)) | ||
2271 | wl1271_tx_flush(wl); | ||
2272 | |||
2273 | mutex_lock(&wl->mutex); | ||
2274 | |||
2275 | if (unlikely(wl->state == WL1271_STATE_OFF)) { | ||
2276 | /* we support configuring the channel and band while off */ | ||
2277 | if ((changed & IEEE80211_CONF_CHANGE_CHANNEL)) { | ||
2278 | wl->band = conf->channel->band; | ||
2279 | wl->channel = channel; | ||
2280 | } | ||
2281 | |||
2282 | if ((changed & IEEE80211_CONF_CHANGE_POWER)) | ||
2283 | wl->power_level = conf->power_level; | ||
2284 | |||
2285 | goto out; | ||
2286 | } | ||
2287 | |||
2288 | is_ap = (wl->bss_type == BSS_TYPE_AP_BSS); | ||
2289 | |||
2290 | ret = wl1271_ps_elp_wakeup(wl); | ||
2291 | if (ret < 0) | ||
2292 | goto out; | ||
2293 | |||
2294 | /* if the channel changes while joined, join again */ | ||
2295 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL && | ||
2296 | ((wl->band != conf->channel->band) || | ||
2297 | (wl->channel != channel))) { | ||
2298 | wl->band = conf->channel->band; | ||
2299 | wl->channel = channel; | ||
2300 | |||
2301 | if (!is_ap) { | ||
2302 | /* | ||
2303 | * FIXME: the mac80211 should really provide a fixed | ||
2304 | * rate to use here. for now, just use the smallest | ||
2305 | * possible rate for the band as a fixed rate for | ||
2306 | * association frames and other control messages. | ||
2307 | */ | ||
2308 | if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) | ||
2309 | wl1271_set_band_rate(wl); | ||
2310 | |||
2311 | wl->basic_rate = wl1271_tx_min_rate_get(wl); | ||
2312 | ret = wl1271_acx_sta_rate_policies(wl); | ||
2313 | if (ret < 0) | ||
2314 | wl1271_warning("rate policy for channel " | ||
2315 | "failed %d", ret); | ||
2316 | |||
2317 | if (test_bit(WL1271_FLAG_JOINED, &wl->flags)) { | ||
2318 | ret = wl1271_join(wl, false); | ||
2319 | if (ret < 0) | ||
2320 | wl1271_warning("cmd join on channel " | ||
2321 | "failed %d", ret); | ||
2322 | } | ||
2323 | } | ||
2324 | } | ||
2325 | |||
2326 | if (changed & IEEE80211_CONF_CHANGE_IDLE && !is_ap) { | ||
2327 | ret = wl1271_sta_handle_idle(wl, | ||
2328 | conf->flags & IEEE80211_CONF_IDLE); | ||
2329 | if (ret < 0) | ||
2330 | wl1271_warning("idle mode change failed %d", ret); | ||
2331 | } | ||
2332 | |||
2333 | /* | ||
2334 | * if mac80211 changes the PSM mode, make sure the mode is not | ||
2335 | * incorrectly changed after the pspoll failure active window. | ||
2336 | */ | ||
2337 | if (changed & IEEE80211_CONF_CHANGE_PS) | ||
2338 | clear_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags); | ||
2339 | |||
2340 | if (conf->flags & IEEE80211_CONF_PS && | ||
2341 | !test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags)) { | ||
2342 | set_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags); | ||
2343 | |||
2344 | /* | ||
2345 | * We enter PSM only if we're already associated. | ||
2346 | * If we're not, we'll enter it when joining an SSID, | ||
2347 | * through the bss_info_changed() hook. | ||
2348 | */ | ||
2349 | if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) { | ||
2350 | wl1271_debug(DEBUG_PSM, "psm enabled"); | ||
2351 | ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE, | ||
2352 | wl->basic_rate, true); | ||
2353 | } | ||
2354 | } else if (!(conf->flags & IEEE80211_CONF_PS) && | ||
2355 | test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags)) { | ||
2356 | wl1271_debug(DEBUG_PSM, "psm disabled"); | ||
2357 | |||
2358 | clear_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags); | ||
2359 | |||
2360 | if (test_bit(WL1271_FLAG_PSM, &wl->flags)) | ||
2361 | ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE, | ||
2362 | wl->basic_rate, true); | ||
2363 | } | ||
2364 | |||
2365 | if (conf->power_level != wl->power_level) { | ||
2366 | ret = wl1271_acx_tx_power(wl, conf->power_level); | ||
2367 | if (ret < 0) | ||
2368 | goto out_sleep; | ||
2369 | |||
2370 | wl->power_level = conf->power_level; | ||
2371 | } | ||
2372 | |||
2373 | out_sleep: | ||
2374 | wl1271_ps_elp_sleep(wl); | ||
2375 | |||
2376 | out: | ||
2377 | mutex_unlock(&wl->mutex); | ||
2378 | |||
2379 | return ret; | ||
2380 | } | ||
2381 | |||
2382 | struct wl1271_filter_params { | ||
2383 | bool enabled; | ||
2384 | int mc_list_length; | ||
2385 | u8 mc_list[ACX_MC_ADDRESS_GROUP_MAX][ETH_ALEN]; | ||
2386 | }; | ||
2387 | |||
2388 | static u64 wl1271_op_prepare_multicast(struct ieee80211_hw *hw, | ||
2389 | struct netdev_hw_addr_list *mc_list) | ||
2390 | { | ||
2391 | struct wl1271_filter_params *fp; | ||
2392 | struct netdev_hw_addr *ha; | ||
2393 | struct wl1271 *wl = hw->priv; | ||
2394 | |||
2395 | if (unlikely(wl->state == WL1271_STATE_OFF)) | ||
2396 | return 0; | ||
2397 | |||
2398 | fp = kzalloc(sizeof(*fp), GFP_ATOMIC); | ||
2399 | if (!fp) { | ||
2400 | wl1271_error("Out of memory setting filters."); | ||
2401 | return 0; | ||
2402 | } | ||
2403 | |||
2404 | /* update multicast filtering parameters */ | ||
2405 | fp->mc_list_length = 0; | ||
2406 | if (netdev_hw_addr_list_count(mc_list) > ACX_MC_ADDRESS_GROUP_MAX) { | ||
2407 | fp->enabled = false; | ||
2408 | } else { | ||
2409 | fp->enabled = true; | ||
2410 | netdev_hw_addr_list_for_each(ha, mc_list) { | ||
2411 | memcpy(fp->mc_list[fp->mc_list_length], | ||
2412 | ha->addr, ETH_ALEN); | ||
2413 | fp->mc_list_length++; | ||
2414 | } | ||
2415 | } | ||
2416 | |||
2417 | return (u64)(unsigned long)fp; | ||
2418 | } | ||
2419 | |||
2420 | #define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \ | ||
2421 | FIF_ALLMULTI | \ | ||
2422 | FIF_FCSFAIL | \ | ||
2423 | FIF_BCN_PRBRESP_PROMISC | \ | ||
2424 | FIF_CONTROL | \ | ||
2425 | FIF_OTHER_BSS) | ||
2426 | |||
2427 | static void wl1271_op_configure_filter(struct ieee80211_hw *hw, | ||
2428 | unsigned int changed, | ||
2429 | unsigned int *total, u64 multicast) | ||
2430 | { | ||
2431 | struct wl1271_filter_params *fp = (void *)(unsigned long)multicast; | ||
2432 | struct wl1271 *wl = hw->priv; | ||
2433 | int ret; | ||
2434 | |||
2435 | wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter changed %x" | ||
2436 | " total %x", changed, *total); | ||
2437 | |||
2438 | mutex_lock(&wl->mutex); | ||
2439 | |||
2440 | *total &= WL1271_SUPPORTED_FILTERS; | ||
2441 | changed &= WL1271_SUPPORTED_FILTERS; | ||
2442 | |||
2443 | if (unlikely(wl->state == WL1271_STATE_OFF)) | ||
2444 | goto out; | ||
2445 | |||
2446 | ret = wl1271_ps_elp_wakeup(wl); | ||
2447 | if (ret < 0) | ||
2448 | goto out; | ||
2449 | |||
2450 | if (wl->bss_type != BSS_TYPE_AP_BSS) { | ||
2451 | if (*total & FIF_ALLMULTI) | ||
2452 | ret = wl1271_acx_group_address_tbl(wl, false, NULL, 0); | ||
2453 | else if (fp) | ||
2454 | ret = wl1271_acx_group_address_tbl(wl, fp->enabled, | ||
2455 | fp->mc_list, | ||
2456 | fp->mc_list_length); | ||
2457 | if (ret < 0) | ||
2458 | goto out_sleep; | ||
2459 | } | ||
2460 | |||
2461 | /* determine, whether supported filter values have changed */ | ||
2462 | if (changed == 0) | ||
2463 | goto out_sleep; | ||
2464 | |||
2465 | /* configure filters */ | ||
2466 | wl->filters = *total; | ||
2467 | wl1271_configure_filters(wl, 0); | ||
2468 | |||
2469 | /* apply configured filters */ | ||
2470 | ret = wl1271_acx_rx_config(wl, wl->rx_config, wl->rx_filter); | ||
2471 | if (ret < 0) | ||
2472 | goto out_sleep; | ||
2473 | |||
2474 | out_sleep: | ||
2475 | wl1271_ps_elp_sleep(wl); | ||
2476 | |||
2477 | out: | ||
2478 | mutex_unlock(&wl->mutex); | ||
2479 | kfree(fp); | ||
2480 | } | ||
2481 | |||
2482 | static int wl1271_record_ap_key(struct wl1271 *wl, u8 id, u8 key_type, | ||
2483 | u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32, | ||
2484 | u16 tx_seq_16) | ||
2485 | { | ||
2486 | struct wl1271_ap_key *ap_key; | ||
2487 | int i; | ||
2488 | |||
2489 | wl1271_debug(DEBUG_CRYPT, "record ap key id %d", (int)id); | ||
2490 | |||
2491 | if (key_size > MAX_KEY_SIZE) | ||
2492 | return -EINVAL; | ||
2493 | |||
2494 | /* | ||
2495 | * Find next free entry in ap_keys. Also check we are not replacing | ||
2496 | * an existing key. | ||
2497 | */ | ||
2498 | for (i = 0; i < MAX_NUM_KEYS; i++) { | ||
2499 | if (wl->recorded_ap_keys[i] == NULL) | ||
2500 | break; | ||
2501 | |||
2502 | if (wl->recorded_ap_keys[i]->id == id) { | ||
2503 | wl1271_warning("trying to record key replacement"); | ||
2504 | return -EINVAL; | ||
2505 | } | ||
2506 | } | ||
2507 | |||
2508 | if (i == MAX_NUM_KEYS) | ||
2509 | return -EBUSY; | ||
2510 | |||
2511 | ap_key = kzalloc(sizeof(*ap_key), GFP_KERNEL); | ||
2512 | if (!ap_key) | ||
2513 | return -ENOMEM; | ||
2514 | |||
2515 | ap_key->id = id; | ||
2516 | ap_key->key_type = key_type; | ||
2517 | ap_key->key_size = key_size; | ||
2518 | memcpy(ap_key->key, key, key_size); | ||
2519 | ap_key->hlid = hlid; | ||
2520 | ap_key->tx_seq_32 = tx_seq_32; | ||
2521 | ap_key->tx_seq_16 = tx_seq_16; | ||
2522 | |||
2523 | wl->recorded_ap_keys[i] = ap_key; | ||
2524 | return 0; | ||
2525 | } | ||
2526 | |||
2527 | static void wl1271_free_ap_keys(struct wl1271 *wl) | ||
2528 | { | ||
2529 | int i; | ||
2530 | |||
2531 | for (i = 0; i < MAX_NUM_KEYS; i++) { | ||
2532 | kfree(wl->recorded_ap_keys[i]); | ||
2533 | wl->recorded_ap_keys[i] = NULL; | ||
2534 | } | ||
2535 | } | ||
2536 | |||
2537 | static int wl1271_ap_init_hwenc(struct wl1271 *wl) | ||
2538 | { | ||
2539 | int i, ret = 0; | ||
2540 | struct wl1271_ap_key *key; | ||
2541 | bool wep_key_added = false; | ||
2542 | |||
2543 | for (i = 0; i < MAX_NUM_KEYS; i++) { | ||
2544 | if (wl->recorded_ap_keys[i] == NULL) | ||
2545 | break; | ||
2546 | |||
2547 | key = wl->recorded_ap_keys[i]; | ||
2548 | ret = wl1271_cmd_set_ap_key(wl, KEY_ADD_OR_REPLACE, | ||
2549 | key->id, key->key_type, | ||
2550 | key->key_size, key->key, | ||
2551 | key->hlid, key->tx_seq_32, | ||
2552 | key->tx_seq_16); | ||
2553 | if (ret < 0) | ||
2554 | goto out; | ||
2555 | |||
2556 | if (key->key_type == KEY_WEP) | ||
2557 | wep_key_added = true; | ||
2558 | } | ||
2559 | |||
2560 | if (wep_key_added) { | ||
2561 | ret = wl1271_cmd_set_ap_default_wep_key(wl, wl->default_key); | ||
2562 | if (ret < 0) | ||
2563 | goto out; | ||
2564 | } | ||
2565 | |||
2566 | out: | ||
2567 | wl1271_free_ap_keys(wl); | ||
2568 | return ret; | ||
2569 | } | ||
2570 | |||
2571 | static int wl1271_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type, | ||
2572 | u8 key_size, const u8 *key, u32 tx_seq_32, | ||
2573 | u16 tx_seq_16, struct ieee80211_sta *sta) | ||
2574 | { | ||
2575 | int ret; | ||
2576 | bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS); | ||
2577 | |||
2578 | if (is_ap) { | ||
2579 | struct wl1271_station *wl_sta; | ||
2580 | u8 hlid; | ||
2581 | |||
2582 | if (sta) { | ||
2583 | wl_sta = (struct wl1271_station *)sta->drv_priv; | ||
2584 | hlid = wl_sta->hlid; | ||
2585 | } else { | ||
2586 | hlid = WL1271_AP_BROADCAST_HLID; | ||
2587 | } | ||
2588 | |||
2589 | if (!test_bit(WL1271_FLAG_AP_STARTED, &wl->flags)) { | ||
2590 | /* | ||
2591 | * We do not support removing keys after AP shutdown. | ||
2592 | * Pretend we do to make mac80211 happy. | ||
2593 | */ | ||
2594 | if (action != KEY_ADD_OR_REPLACE) | ||
2595 | return 0; | ||
2596 | |||
2597 | ret = wl1271_record_ap_key(wl, id, | ||
2598 | key_type, key_size, | ||
2599 | key, hlid, tx_seq_32, | ||
2600 | tx_seq_16); | ||
2601 | } else { | ||
2602 | ret = wl1271_cmd_set_ap_key(wl, action, | ||
2603 | id, key_type, key_size, | ||
2604 | key, hlid, tx_seq_32, | ||
2605 | tx_seq_16); | ||
2606 | } | ||
2607 | |||
2608 | if (ret < 0) | ||
2609 | return ret; | ||
2610 | } else { | ||
2611 | const u8 *addr; | ||
2612 | static const u8 bcast_addr[ETH_ALEN] = { | ||
2613 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff | ||
2614 | }; | ||
2615 | |||
2616 | addr = sta ? sta->addr : bcast_addr; | ||
2617 | |||
2618 | if (is_zero_ether_addr(addr)) { | ||
2619 | /* We dont support TX only encryption */ | ||
2620 | return -EOPNOTSUPP; | ||
2621 | } | ||
2622 | |||
2623 | /* The wl1271 does not allow to remove unicast keys - they | ||
2624 | will be cleared automatically on next CMD_JOIN. Ignore the | ||
2625 | request silently, as we dont want the mac80211 to emit | ||
2626 | an error message. */ | ||
2627 | if (action == KEY_REMOVE && !is_broadcast_ether_addr(addr)) | ||
2628 | return 0; | ||
2629 | |||
2630 | ret = wl1271_cmd_set_sta_key(wl, action, | ||
2631 | id, key_type, key_size, | ||
2632 | key, addr, tx_seq_32, | ||
2633 | tx_seq_16); | ||
2634 | if (ret < 0) | ||
2635 | return ret; | ||
2636 | |||
2637 | /* the default WEP key needs to be configured at least once */ | ||
2638 | if (key_type == KEY_WEP) { | ||
2639 | ret = wl1271_cmd_set_sta_default_wep_key(wl, | ||
2640 | wl->default_key); | ||
2641 | if (ret < 0) | ||
2642 | return ret; | ||
2643 | } | ||
2644 | } | ||
2645 | |||
2646 | return 0; | ||
2647 | } | ||
2648 | |||
2649 | static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, | ||
2650 | struct ieee80211_vif *vif, | ||
2651 | struct ieee80211_sta *sta, | ||
2652 | struct ieee80211_key_conf *key_conf) | ||
2653 | { | ||
2654 | struct wl1271 *wl = hw->priv; | ||
2655 | int ret; | ||
2656 | u32 tx_seq_32 = 0; | ||
2657 | u16 tx_seq_16 = 0; | ||
2658 | u8 key_type; | ||
2659 | |||
2660 | wl1271_debug(DEBUG_MAC80211, "mac80211 set key"); | ||
2661 | |||
2662 | wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x sta: %p", cmd, sta); | ||
2663 | wl1271_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x", | ||
2664 | key_conf->cipher, key_conf->keyidx, | ||
2665 | key_conf->keylen, key_conf->flags); | ||
2666 | wl1271_dump(DEBUG_CRYPT, "KEY: ", key_conf->key, key_conf->keylen); | ||
2667 | |||
2668 | mutex_lock(&wl->mutex); | ||
2669 | |||
2670 | if (unlikely(wl->state == WL1271_STATE_OFF)) { | ||
2671 | ret = -EAGAIN; | ||
2672 | goto out_unlock; | ||
2673 | } | ||
2674 | |||
2675 | ret = wl1271_ps_elp_wakeup(wl); | ||
2676 | if (ret < 0) | ||
2677 | goto out_unlock; | ||
2678 | |||
2679 | switch (key_conf->cipher) { | ||
2680 | case WLAN_CIPHER_SUITE_WEP40: | ||
2681 | case WLAN_CIPHER_SUITE_WEP104: | ||
2682 | key_type = KEY_WEP; | ||
2683 | |||
2684 | key_conf->hw_key_idx = key_conf->keyidx; | ||
2685 | break; | ||
2686 | case WLAN_CIPHER_SUITE_TKIP: | ||
2687 | key_type = KEY_TKIP; | ||
2688 | |||
2689 | key_conf->hw_key_idx = key_conf->keyidx; | ||
2690 | tx_seq_32 = WL1271_TX_SECURITY_HI32(wl->tx_security_seq); | ||
2691 | tx_seq_16 = WL1271_TX_SECURITY_LO16(wl->tx_security_seq); | ||
2692 | break; | ||
2693 | case WLAN_CIPHER_SUITE_CCMP: | ||
2694 | key_type = KEY_AES; | ||
2695 | |||
2696 | key_conf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; | ||
2697 | tx_seq_32 = WL1271_TX_SECURITY_HI32(wl->tx_security_seq); | ||
2698 | tx_seq_16 = WL1271_TX_SECURITY_LO16(wl->tx_security_seq); | ||
2699 | break; | ||
2700 | case WL1271_CIPHER_SUITE_GEM: | ||
2701 | key_type = KEY_GEM; | ||
2702 | tx_seq_32 = WL1271_TX_SECURITY_HI32(wl->tx_security_seq); | ||
2703 | tx_seq_16 = WL1271_TX_SECURITY_LO16(wl->tx_security_seq); | ||
2704 | break; | ||
2705 | default: | ||
2706 | wl1271_error("Unknown key algo 0x%x", key_conf->cipher); | ||
2707 | |||
2708 | ret = -EOPNOTSUPP; | ||
2709 | goto out_sleep; | ||
2710 | } | ||
2711 | |||
2712 | switch (cmd) { | ||
2713 | case SET_KEY: | ||
2714 | ret = wl1271_set_key(wl, KEY_ADD_OR_REPLACE, | ||
2715 | key_conf->keyidx, key_type, | ||
2716 | key_conf->keylen, key_conf->key, | ||
2717 | tx_seq_32, tx_seq_16, sta); | ||
2718 | if (ret < 0) { | ||
2719 | wl1271_error("Could not add or replace key"); | ||
2720 | goto out_sleep; | ||
2721 | } | ||
2722 | break; | ||
2723 | |||
2724 | case DISABLE_KEY: | ||
2725 | ret = wl1271_set_key(wl, KEY_REMOVE, | ||
2726 | key_conf->keyidx, key_type, | ||
2727 | key_conf->keylen, key_conf->key, | ||
2728 | 0, 0, sta); | ||
2729 | if (ret < 0) { | ||
2730 | wl1271_error("Could not remove key"); | ||
2731 | goto out_sleep; | ||
2732 | } | ||
2733 | break; | ||
2734 | |||
2735 | default: | ||
2736 | wl1271_error("Unsupported key cmd 0x%x", cmd); | ||
2737 | ret = -EOPNOTSUPP; | ||
2738 | break; | ||
2739 | } | ||
2740 | |||
2741 | out_sleep: | ||
2742 | wl1271_ps_elp_sleep(wl); | ||
2743 | |||
2744 | out_unlock: | ||
2745 | mutex_unlock(&wl->mutex); | ||
2746 | |||
2747 | return ret; | ||
2748 | } | ||
2749 | |||
2750 | static int wl1271_op_hw_scan(struct ieee80211_hw *hw, | ||
2751 | struct ieee80211_vif *vif, | ||
2752 | struct cfg80211_scan_request *req) | ||
2753 | { | ||
2754 | struct wl1271 *wl = hw->priv; | ||
2755 | int ret; | ||
2756 | u8 *ssid = NULL; | ||
2757 | size_t len = 0; | ||
2758 | |||
2759 | wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan"); | ||
2760 | |||
2761 | if (req->n_ssids) { | ||
2762 | ssid = req->ssids[0].ssid; | ||
2763 | len = req->ssids[0].ssid_len; | ||
2764 | } | ||
2765 | |||
2766 | mutex_lock(&wl->mutex); | ||
2767 | |||
2768 | if (wl->state == WL1271_STATE_OFF) { | ||
2769 | /* | ||
2770 | * We cannot return -EBUSY here because cfg80211 will expect | ||
2771 | * a call to ieee80211_scan_completed if we do - in this case | ||
2772 | * there won't be any call. | ||
2773 | */ | ||
2774 | ret = -EAGAIN; | ||
2775 | goto out; | ||
2776 | } | ||
2777 | |||
2778 | ret = wl1271_ps_elp_wakeup(wl); | ||
2779 | if (ret < 0) | ||
2780 | goto out; | ||
2781 | |||
2782 | ret = wl1271_scan(hw->priv, ssid, len, req); | ||
2783 | |||
2784 | wl1271_ps_elp_sleep(wl); | ||
2785 | |||
2786 | out: | ||
2787 | mutex_unlock(&wl->mutex); | ||
2788 | |||
2789 | return ret; | ||
2790 | } | ||
2791 | |||
2792 | static void wl1271_op_cancel_hw_scan(struct ieee80211_hw *hw, | ||
2793 | struct ieee80211_vif *vif) | ||
2794 | { | ||
2795 | struct wl1271 *wl = hw->priv; | ||
2796 | int ret; | ||
2797 | |||
2798 | wl1271_debug(DEBUG_MAC80211, "mac80211 cancel hw scan"); | ||
2799 | |||
2800 | mutex_lock(&wl->mutex); | ||
2801 | |||
2802 | if (wl->state == WL1271_STATE_OFF) | ||
2803 | goto out; | ||
2804 | |||
2805 | if (wl->scan.state == WL1271_SCAN_STATE_IDLE) | ||
2806 | goto out; | ||
2807 | |||
2808 | ret = wl1271_ps_elp_wakeup(wl); | ||
2809 | if (ret < 0) | ||
2810 | goto out; | ||
2811 | |||
2812 | if (wl->scan.state != WL1271_SCAN_STATE_DONE) { | ||
2813 | ret = wl1271_scan_stop(wl); | ||
2814 | if (ret < 0) | ||
2815 | goto out_sleep; | ||
2816 | } | ||
2817 | wl->scan.state = WL1271_SCAN_STATE_IDLE; | ||
2818 | memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch)); | ||
2819 | wl->scan.req = NULL; | ||
2820 | ieee80211_scan_completed(wl->hw, true); | ||
2821 | |||
2822 | out_sleep: | ||
2823 | wl1271_ps_elp_sleep(wl); | ||
2824 | out: | ||
2825 | mutex_unlock(&wl->mutex); | ||
2826 | |||
2827 | cancel_delayed_work_sync(&wl->scan_complete_work); | ||
2828 | } | ||
2829 | |||
2830 | static int wl1271_op_sched_scan_start(struct ieee80211_hw *hw, | ||
2831 | struct ieee80211_vif *vif, | ||
2832 | struct cfg80211_sched_scan_request *req, | ||
2833 | struct ieee80211_sched_scan_ies *ies) | ||
2834 | { | ||
2835 | struct wl1271 *wl = hw->priv; | ||
2836 | int ret; | ||
2837 | |||
2838 | wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_start"); | ||
2839 | |||
2840 | mutex_lock(&wl->mutex); | ||
2841 | |||
2842 | ret = wl1271_ps_elp_wakeup(wl); | ||
2843 | if (ret < 0) | ||
2844 | goto out; | ||
2845 | |||
2846 | ret = wl1271_scan_sched_scan_config(wl, req, ies); | ||
2847 | if (ret < 0) | ||
2848 | goto out_sleep; | ||
2849 | |||
2850 | ret = wl1271_scan_sched_scan_start(wl); | ||
2851 | if (ret < 0) | ||
2852 | goto out_sleep; | ||
2853 | |||
2854 | wl->sched_scanning = true; | ||
2855 | |||
2856 | out_sleep: | ||
2857 | wl1271_ps_elp_sleep(wl); | ||
2858 | out: | ||
2859 | mutex_unlock(&wl->mutex); | ||
2860 | return ret; | ||
2861 | } | ||
2862 | |||
2863 | static void wl1271_op_sched_scan_stop(struct ieee80211_hw *hw, | ||
2864 | struct ieee80211_vif *vif) | ||
2865 | { | ||
2866 | struct wl1271 *wl = hw->priv; | ||
2867 | int ret; | ||
2868 | |||
2869 | wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_stop"); | ||
2870 | |||
2871 | mutex_lock(&wl->mutex); | ||
2872 | |||
2873 | ret = wl1271_ps_elp_wakeup(wl); | ||
2874 | if (ret < 0) | ||
2875 | goto out; | ||
2876 | |||
2877 | wl1271_scan_sched_scan_stop(wl); | ||
2878 | |||
2879 | wl1271_ps_elp_sleep(wl); | ||
2880 | out: | ||
2881 | mutex_unlock(&wl->mutex); | ||
2882 | } | ||
2883 | |||
2884 | static int wl1271_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value) | ||
2885 | { | ||
2886 | struct wl1271 *wl = hw->priv; | ||
2887 | int ret = 0; | ||
2888 | |||
2889 | mutex_lock(&wl->mutex); | ||
2890 | |||
2891 | if (unlikely(wl->state == WL1271_STATE_OFF)) { | ||
2892 | ret = -EAGAIN; | ||
2893 | goto out; | ||
2894 | } | ||
2895 | |||
2896 | ret = wl1271_ps_elp_wakeup(wl); | ||
2897 | if (ret < 0) | ||
2898 | goto out; | ||
2899 | |||
2900 | ret = wl1271_acx_frag_threshold(wl, value); | ||
2901 | if (ret < 0) | ||
2902 | wl1271_warning("wl1271_op_set_frag_threshold failed: %d", ret); | ||
2903 | |||
2904 | wl1271_ps_elp_sleep(wl); | ||
2905 | |||
2906 | out: | ||
2907 | mutex_unlock(&wl->mutex); | ||
2908 | |||
2909 | return ret; | ||
2910 | } | ||
2911 | |||
2912 | static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value) | ||
2913 | { | ||
2914 | struct wl1271 *wl = hw->priv; | ||
2915 | int ret = 0; | ||
2916 | |||
2917 | mutex_lock(&wl->mutex); | ||
2918 | |||
2919 | if (unlikely(wl->state == WL1271_STATE_OFF)) { | ||
2920 | ret = -EAGAIN; | ||
2921 | goto out; | ||
2922 | } | ||
2923 | |||
2924 | ret = wl1271_ps_elp_wakeup(wl); | ||
2925 | if (ret < 0) | ||
2926 | goto out; | ||
2927 | |||
2928 | ret = wl1271_acx_rts_threshold(wl, value); | ||
2929 | if (ret < 0) | ||
2930 | wl1271_warning("wl1271_op_set_rts_threshold failed: %d", ret); | ||
2931 | |||
2932 | wl1271_ps_elp_sleep(wl); | ||
2933 | |||
2934 | out: | ||
2935 | mutex_unlock(&wl->mutex); | ||
2936 | |||
2937 | return ret; | ||
2938 | } | ||
2939 | |||
2940 | static int wl1271_ssid_set(struct wl1271 *wl, struct sk_buff *skb, | ||
2941 | int offset) | ||
2942 | { | ||
2943 | u8 ssid_len; | ||
2944 | const u8 *ptr = cfg80211_find_ie(WLAN_EID_SSID, skb->data + offset, | ||
2945 | skb->len - offset); | ||
2946 | |||
2947 | if (!ptr) { | ||
2948 | wl1271_error("No SSID in IEs!"); | ||
2949 | return -ENOENT; | ||
2950 | } | ||
2951 | |||
2952 | ssid_len = ptr[1]; | ||
2953 | if (ssid_len > IEEE80211_MAX_SSID_LEN) { | ||
2954 | wl1271_error("SSID is too long!"); | ||
2955 | return -EINVAL; | ||
2956 | } | ||
2957 | |||
2958 | wl->ssid_len = ssid_len; | ||
2959 | memcpy(wl->ssid, ptr+2, ssid_len); | ||
2960 | return 0; | ||
2961 | } | ||
2962 | |||
2963 | static int wl1271_bss_erp_info_changed(struct wl1271 *wl, | ||
2964 | struct ieee80211_bss_conf *bss_conf, | ||
2965 | u32 changed) | ||
2966 | { | ||
2967 | int ret = 0; | ||
2968 | |||
2969 | if (changed & BSS_CHANGED_ERP_SLOT) { | ||
2970 | if (bss_conf->use_short_slot) | ||
2971 | ret = wl1271_acx_slot(wl, SLOT_TIME_SHORT); | ||
2972 | else | ||
2973 | ret = wl1271_acx_slot(wl, SLOT_TIME_LONG); | ||
2974 | if (ret < 0) { | ||
2975 | wl1271_warning("Set slot time failed %d", ret); | ||
2976 | goto out; | ||
2977 | } | ||
2978 | } | ||
2979 | |||
2980 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { | ||
2981 | if (bss_conf->use_short_preamble) | ||
2982 | wl1271_acx_set_preamble(wl, ACX_PREAMBLE_SHORT); | ||
2983 | else | ||
2984 | wl1271_acx_set_preamble(wl, ACX_PREAMBLE_LONG); | ||
2985 | } | ||
2986 | |||
2987 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { | ||
2988 | if (bss_conf->use_cts_prot) | ||
2989 | ret = wl1271_acx_cts_protect(wl, CTSPROTECT_ENABLE); | ||
2990 | else | ||
2991 | ret = wl1271_acx_cts_protect(wl, CTSPROTECT_DISABLE); | ||
2992 | if (ret < 0) { | ||
2993 | wl1271_warning("Set ctsprotect failed %d", ret); | ||
2994 | goto out; | ||
2995 | } | ||
2996 | } | ||
2997 | |||
2998 | out: | ||
2999 | return ret; | ||
3000 | } | ||
3001 | |||
3002 | static int wl1271_bss_beacon_info_changed(struct wl1271 *wl, | ||
3003 | struct ieee80211_vif *vif, | ||
3004 | struct ieee80211_bss_conf *bss_conf, | ||
3005 | u32 changed) | ||
3006 | { | ||
3007 | bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS); | ||
3008 | int ret = 0; | ||
3009 | |||
3010 | if ((changed & BSS_CHANGED_BEACON_INT)) { | ||
3011 | wl1271_debug(DEBUG_MASTER, "beacon interval updated: %d", | ||
3012 | bss_conf->beacon_int); | ||
3013 | |||
3014 | wl->beacon_int = bss_conf->beacon_int; | ||
3015 | } | ||
3016 | |||
3017 | if ((changed & BSS_CHANGED_BEACON)) { | ||
3018 | struct ieee80211_hdr *hdr; | ||
3019 | int ieoffset = offsetof(struct ieee80211_mgmt, | ||
3020 | u.beacon.variable); | ||
3021 | struct sk_buff *beacon = ieee80211_beacon_get(wl->hw, vif); | ||
3022 | u16 tmpl_id; | ||
3023 | |||
3024 | if (!beacon) | ||
3025 | goto out; | ||
3026 | |||
3027 | wl1271_debug(DEBUG_MASTER, "beacon updated"); | ||
3028 | |||
3029 | ret = wl1271_ssid_set(wl, beacon, ieoffset); | ||
3030 | if (ret < 0) { | ||
3031 | dev_kfree_skb(beacon); | ||
3032 | goto out; | ||
3033 | } | ||
3034 | tmpl_id = is_ap ? CMD_TEMPL_AP_BEACON : | ||
3035 | CMD_TEMPL_BEACON; | ||
3036 | ret = wl1271_cmd_template_set(wl, tmpl_id, | ||
3037 | beacon->data, | ||
3038 | beacon->len, 0, | ||
3039 | wl1271_tx_min_rate_get(wl)); | ||
3040 | if (ret < 0) { | ||
3041 | dev_kfree_skb(beacon); | ||
3042 | goto out; | ||
3043 | } | ||
3044 | |||
3045 | hdr = (struct ieee80211_hdr *) beacon->data; | ||
3046 | hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | | ||
3047 | IEEE80211_STYPE_PROBE_RESP); | ||
3048 | |||
3049 | tmpl_id = is_ap ? CMD_TEMPL_AP_PROBE_RESPONSE : | ||
3050 | CMD_TEMPL_PROBE_RESPONSE; | ||
3051 | ret = wl1271_cmd_template_set(wl, | ||
3052 | tmpl_id, | ||
3053 | beacon->data, | ||
3054 | beacon->len, 0, | ||
3055 | wl1271_tx_min_rate_get(wl)); | ||
3056 | dev_kfree_skb(beacon); | ||
3057 | if (ret < 0) | ||
3058 | goto out; | ||
3059 | } | ||
3060 | |||
3061 | out: | ||
3062 | return ret; | ||
3063 | } | ||
3064 | |||
3065 | /* AP mode changes */ | ||
3066 | static void wl1271_bss_info_changed_ap(struct wl1271 *wl, | ||
3067 | struct ieee80211_vif *vif, | ||
3068 | struct ieee80211_bss_conf *bss_conf, | ||
3069 | u32 changed) | ||
3070 | { | ||
3071 | int ret = 0; | ||
3072 | |||
3073 | if ((changed & BSS_CHANGED_BASIC_RATES)) { | ||
3074 | u32 rates = bss_conf->basic_rates; | ||
3075 | |||
3076 | wl->basic_rate_set = wl1271_tx_enabled_rates_get(wl, rates); | ||
3077 | wl->basic_rate = wl1271_tx_min_rate_get(wl); | ||
3078 | |||
3079 | ret = wl1271_init_ap_rates(wl); | ||
3080 | if (ret < 0) { | ||
3081 | wl1271_error("AP rate policy change failed %d", ret); | ||
3082 | goto out; | ||
3083 | } | ||
3084 | |||
3085 | ret = wl1271_ap_init_templates(wl); | ||
3086 | if (ret < 0) | ||
3087 | goto out; | ||
3088 | } | ||
3089 | |||
3090 | ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, changed); | ||
3091 | if (ret < 0) | ||
3092 | goto out; | ||
3093 | |||
3094 | if ((changed & BSS_CHANGED_BEACON_ENABLED)) { | ||
3095 | if (bss_conf->enable_beacon) { | ||
3096 | if (!test_bit(WL1271_FLAG_AP_STARTED, &wl->flags)) { | ||
3097 | ret = wl1271_cmd_start_bss(wl); | ||
3098 | if (ret < 0) | ||
3099 | goto out; | ||
3100 | |||
3101 | set_bit(WL1271_FLAG_AP_STARTED, &wl->flags); | ||
3102 | wl1271_debug(DEBUG_AP, "started AP"); | ||
3103 | |||
3104 | ret = wl1271_ap_init_hwenc(wl); | ||
3105 | if (ret < 0) | ||
3106 | goto out; | ||
3107 | } | ||
3108 | } else { | ||
3109 | if (test_bit(WL1271_FLAG_AP_STARTED, &wl->flags)) { | ||
3110 | ret = wl1271_cmd_stop_bss(wl); | ||
3111 | if (ret < 0) | ||
3112 | goto out; | ||
3113 | |||
3114 | clear_bit(WL1271_FLAG_AP_STARTED, &wl->flags); | ||
3115 | wl1271_debug(DEBUG_AP, "stopped AP"); | ||
3116 | } | ||
3117 | } | ||
3118 | } | ||
3119 | |||
3120 | ret = wl1271_bss_erp_info_changed(wl, bss_conf, changed); | ||
3121 | if (ret < 0) | ||
3122 | goto out; | ||
3123 | out: | ||
3124 | return; | ||
3125 | } | ||
3126 | |||
3127 | /* STA/IBSS mode changes */ | ||
3128 | static void wl1271_bss_info_changed_sta(struct wl1271 *wl, | ||
3129 | struct ieee80211_vif *vif, | ||
3130 | struct ieee80211_bss_conf *bss_conf, | ||
3131 | u32 changed) | ||
3132 | { | ||
3133 | bool do_join = false, set_assoc = false; | ||
3134 | bool is_ibss = (wl->bss_type == BSS_TYPE_IBSS); | ||
3135 | u32 sta_rate_set = 0; | ||
3136 | int ret; | ||
3137 | struct ieee80211_sta *sta; | ||
3138 | bool sta_exists = false; | ||
3139 | struct ieee80211_sta_ht_cap sta_ht_cap; | ||
3140 | |||
3141 | if (is_ibss) { | ||
3142 | ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, | ||
3143 | changed); | ||
3144 | if (ret < 0) | ||
3145 | goto out; | ||
3146 | } | ||
3147 | |||
3148 | if ((changed & BSS_CHANGED_BEACON_INT) && is_ibss) | ||
3149 | do_join = true; | ||
3150 | |||
3151 | /* Need to update the SSID (for filtering etc) */ | ||
3152 | if ((changed & BSS_CHANGED_BEACON) && is_ibss) | ||
3153 | do_join = true; | ||
3154 | |||
3155 | if ((changed & BSS_CHANGED_BEACON_ENABLED) && is_ibss) { | ||
3156 | wl1271_debug(DEBUG_ADHOC, "ad-hoc beaconing: %s", | ||
3157 | bss_conf->enable_beacon ? "enabled" : "disabled"); | ||
3158 | |||
3159 | if (bss_conf->enable_beacon) | ||
3160 | wl->set_bss_type = BSS_TYPE_IBSS; | ||
3161 | else | ||
3162 | wl->set_bss_type = BSS_TYPE_STA_BSS; | ||
3163 | do_join = true; | ||
3164 | } | ||
3165 | |||
3166 | if ((changed & BSS_CHANGED_CQM)) { | ||
3167 | bool enable = false; | ||
3168 | if (bss_conf->cqm_rssi_thold) | ||
3169 | enable = true; | ||
3170 | ret = wl1271_acx_rssi_snr_trigger(wl, enable, | ||
3171 | bss_conf->cqm_rssi_thold, | ||
3172 | bss_conf->cqm_rssi_hyst); | ||
3173 | if (ret < 0) | ||
3174 | goto out; | ||
3175 | wl->rssi_thold = bss_conf->cqm_rssi_thold; | ||
3176 | } | ||
3177 | |||
3178 | if ((changed & BSS_CHANGED_BSSID) && | ||
3179 | /* | ||
3180 | * Now we know the correct bssid, so we send a new join command | ||
3181 | * and enable the BSSID filter | ||
3182 | */ | ||
3183 | memcmp(wl->bssid, bss_conf->bssid, ETH_ALEN)) { | ||
3184 | memcpy(wl->bssid, bss_conf->bssid, ETH_ALEN); | ||
3185 | |||
3186 | if (!is_zero_ether_addr(wl->bssid)) { | ||
3187 | ret = wl1271_cmd_build_null_data(wl); | ||
3188 | if (ret < 0) | ||
3189 | goto out; | ||
3190 | |||
3191 | ret = wl1271_build_qos_null_data(wl); | ||
3192 | if (ret < 0) | ||
3193 | goto out; | ||
3194 | |||
3195 | /* filter out all packets not from this BSSID */ | ||
3196 | wl1271_configure_filters(wl, 0); | ||
3197 | |||
3198 | /* Need to update the BSSID (for filtering etc) */ | ||
3199 | do_join = true; | ||
3200 | } | ||
3201 | } | ||
3202 | |||
3203 | rcu_read_lock(); | ||
3204 | sta = ieee80211_find_sta(vif, bss_conf->bssid); | ||
3205 | if (sta) { | ||
3206 | /* save the supp_rates of the ap */ | ||
3207 | sta_rate_set = sta->supp_rates[wl->hw->conf.channel->band]; | ||
3208 | if (sta->ht_cap.ht_supported) | ||
3209 | sta_rate_set |= | ||
3210 | (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET); | ||
3211 | sta_ht_cap = sta->ht_cap; | ||
3212 | sta_exists = true; | ||
3213 | } | ||
3214 | rcu_read_unlock(); | ||
3215 | |||
3216 | if (sta_exists) { | ||
3217 | /* handle new association with HT and HT information change */ | ||
3218 | if ((changed & BSS_CHANGED_HT) && | ||
3219 | (bss_conf->channel_type != NL80211_CHAN_NO_HT)) { | ||
3220 | ret = wl1271_acx_set_ht_capabilities(wl, &sta_ht_cap, | ||
3221 | true); | ||
3222 | if (ret < 0) { | ||
3223 | wl1271_warning("Set ht cap true failed %d", | ||
3224 | ret); | ||
3225 | goto out; | ||
3226 | } | ||
3227 | ret = wl1271_acx_set_ht_information(wl, | ||
3228 | bss_conf->ht_operation_mode); | ||
3229 | if (ret < 0) { | ||
3230 | wl1271_warning("Set ht information failed %d", | ||
3231 | ret); | ||
3232 | goto out; | ||
3233 | } | ||
3234 | } | ||
3235 | /* handle new association without HT and disassociation */ | ||
3236 | else if (changed & BSS_CHANGED_ASSOC) { | ||
3237 | ret = wl1271_acx_set_ht_capabilities(wl, &sta_ht_cap, | ||
3238 | false); | ||
3239 | if (ret < 0) { | ||
3240 | wl1271_warning("Set ht cap false failed %d", | ||
3241 | ret); | ||
3242 | goto out; | ||
3243 | } | ||
3244 | } | ||
3245 | } | ||
3246 | |||
3247 | if ((changed & BSS_CHANGED_ASSOC)) { | ||
3248 | if (bss_conf->assoc) { | ||
3249 | u32 rates; | ||
3250 | int ieoffset; | ||
3251 | wl->aid = bss_conf->aid; | ||
3252 | set_assoc = true; | ||
3253 | |||
3254 | wl->ps_poll_failures = 0; | ||
3255 | |||
3256 | /* | ||
3257 | * use basic rates from AP, and determine lowest rate | ||
3258 | * to use with control frames. | ||
3259 | */ | ||
3260 | rates = bss_conf->basic_rates; | ||
3261 | wl->basic_rate_set = wl1271_tx_enabled_rates_get(wl, | ||
3262 | rates); | ||
3263 | wl->basic_rate = wl1271_tx_min_rate_get(wl); | ||
3264 | if (sta_rate_set) | ||
3265 | wl->rate_set = wl1271_tx_enabled_rates_get(wl, | ||
3266 | sta_rate_set); | ||
3267 | ret = wl1271_acx_sta_rate_policies(wl); | ||
3268 | if (ret < 0) | ||
3269 | goto out; | ||
3270 | |||
3271 | /* | ||
3272 | * with wl1271, we don't need to update the | ||
3273 | * beacon_int and dtim_period, because the firmware | ||
3274 | * updates it by itself when the first beacon is | ||
3275 | * received after a join. | ||
3276 | */ | ||
3277 | ret = wl1271_cmd_build_ps_poll(wl, wl->aid); | ||
3278 | if (ret < 0) | ||
3279 | goto out; | ||
3280 | |||
3281 | /* | ||
3282 | * Get a template for hardware connection maintenance | ||
3283 | */ | ||
3284 | dev_kfree_skb(wl->probereq); | ||
3285 | wl->probereq = wl1271_cmd_build_ap_probe_req(wl, NULL); | ||
3286 | ieoffset = offsetof(struct ieee80211_mgmt, | ||
3287 | u.probe_req.variable); | ||
3288 | wl1271_ssid_set(wl, wl->probereq, ieoffset); | ||
3289 | |||
3290 | /* enable the connection monitoring feature */ | ||
3291 | ret = wl1271_acx_conn_monit_params(wl, true); | ||
3292 | if (ret < 0) | ||
3293 | goto out; | ||
3294 | |||
3295 | /* If we want to go in PSM but we're not there yet */ | ||
3296 | if (test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags) && | ||
3297 | !test_bit(WL1271_FLAG_PSM, &wl->flags)) { | ||
3298 | enum wl1271_cmd_ps_mode mode; | ||
3299 | |||
3300 | mode = STATION_POWER_SAVE_MODE; | ||
3301 | ret = wl1271_ps_set_mode(wl, mode, | ||
3302 | wl->basic_rate, | ||
3303 | true); | ||
3304 | if (ret < 0) | ||
3305 | goto out; | ||
3306 | } | ||
3307 | } else { | ||
3308 | /* use defaults when not associated */ | ||
3309 | bool was_assoc = | ||
3310 | !!test_and_clear_bit(WL1271_FLAG_STA_ASSOCIATED, | ||
3311 | &wl->flags); | ||
3312 | clear_bit(WL1271_FLAG_STA_STATE_SENT, &wl->flags); | ||
3313 | wl->aid = 0; | ||
3314 | |||
3315 | /* free probe-request template */ | ||
3316 | dev_kfree_skb(wl->probereq); | ||
3317 | wl->probereq = NULL; | ||
3318 | |||
3319 | /* re-enable dynamic ps - just in case */ | ||
3320 | ieee80211_enable_dyn_ps(wl->vif); | ||
3321 | |||
3322 | /* revert back to minimum rates for the current band */ | ||
3323 | wl1271_set_band_rate(wl); | ||
3324 | wl->basic_rate = wl1271_tx_min_rate_get(wl); | ||
3325 | ret = wl1271_acx_sta_rate_policies(wl); | ||
3326 | if (ret < 0) | ||
3327 | goto out; | ||
3328 | |||
3329 | /* disable connection monitor features */ | ||
3330 | ret = wl1271_acx_conn_monit_params(wl, false); | ||
3331 | |||
3332 | /* Disable the keep-alive feature */ | ||
3333 | ret = wl1271_acx_keep_alive_mode(wl, false); | ||
3334 | if (ret < 0) | ||
3335 | goto out; | ||
3336 | |||
3337 | /* restore the bssid filter and go to dummy bssid */ | ||
3338 | if (was_assoc) { | ||
3339 | wl1271_unjoin(wl); | ||
3340 | wl1271_dummy_join(wl); | ||
3341 | } | ||
3342 | } | ||
3343 | } | ||
3344 | |||
3345 | if (changed & BSS_CHANGED_IBSS) { | ||
3346 | wl1271_debug(DEBUG_ADHOC, "ibss_joined: %d", | ||
3347 | bss_conf->ibss_joined); | ||
3348 | |||
3349 | if (bss_conf->ibss_joined) { | ||
3350 | u32 rates = bss_conf->basic_rates; | ||
3351 | wl->basic_rate_set = wl1271_tx_enabled_rates_get(wl, | ||
3352 | rates); | ||
3353 | wl->basic_rate = wl1271_tx_min_rate_get(wl); | ||
3354 | |||
3355 | /* by default, use 11b rates */ | ||
3356 | wl->rate_set = CONF_TX_IBSS_DEFAULT_RATES; | ||
3357 | ret = wl1271_acx_sta_rate_policies(wl); | ||
3358 | if (ret < 0) | ||
3359 | goto out; | ||
3360 | } | ||
3361 | } | ||
3362 | |||
3363 | ret = wl1271_bss_erp_info_changed(wl, bss_conf, changed); | ||
3364 | if (ret < 0) | ||
3365 | goto out; | ||
3366 | |||
3367 | if (changed & BSS_CHANGED_ARP_FILTER) { | ||
3368 | __be32 addr = bss_conf->arp_addr_list[0]; | ||
3369 | WARN_ON(wl->bss_type != BSS_TYPE_STA_BSS); | ||
3370 | |||
3371 | if (bss_conf->arp_addr_cnt == 1 && | ||
3372 | bss_conf->arp_filter_enabled) { | ||
3373 | /* | ||
3374 | * The template should have been configured only upon | ||
3375 | * association. however, it seems that the correct ip | ||
3376 | * isn't being set (when sending), so we have to | ||
3377 | * reconfigure the template upon every ip change. | ||
3378 | */ | ||
3379 | ret = wl1271_cmd_build_arp_rsp(wl, addr); | ||
3380 | if (ret < 0) { | ||
3381 | wl1271_warning("build arp rsp failed: %d", ret); | ||
3382 | goto out; | ||
3383 | } | ||
3384 | |||
3385 | ret = wl1271_acx_arp_ip_filter(wl, | ||
3386 | ACX_ARP_FILTER_ARP_FILTERING, | ||
3387 | addr); | ||
3388 | } else | ||
3389 | ret = wl1271_acx_arp_ip_filter(wl, 0, addr); | ||
3390 | |||
3391 | if (ret < 0) | ||
3392 | goto out; | ||
3393 | } | ||
3394 | |||
3395 | if (do_join) { | ||
3396 | ret = wl1271_join(wl, set_assoc); | ||
3397 | if (ret < 0) { | ||
3398 | wl1271_warning("cmd join failed %d", ret); | ||
3399 | goto out; | ||
3400 | } | ||
3401 | wl1271_check_operstate(wl, ieee80211_get_operstate(vif)); | ||
3402 | } | ||
3403 | |||
3404 | out: | ||
3405 | return; | ||
3406 | } | ||
3407 | |||
3408 | static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw, | ||
3409 | struct ieee80211_vif *vif, | ||
3410 | struct ieee80211_bss_conf *bss_conf, | ||
3411 | u32 changed) | ||
3412 | { | ||
3413 | struct wl1271 *wl = hw->priv; | ||
3414 | bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS); | ||
3415 | int ret; | ||
3416 | |||
3417 | wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed 0x%x", | ||
3418 | (int)changed); | ||
3419 | |||
3420 | mutex_lock(&wl->mutex); | ||
3421 | |||
3422 | if (unlikely(wl->state == WL1271_STATE_OFF)) | ||
3423 | goto out; | ||
3424 | |||
3425 | ret = wl1271_ps_elp_wakeup(wl); | ||
3426 | if (ret < 0) | ||
3427 | goto out; | ||
3428 | |||
3429 | if (is_ap) | ||
3430 | wl1271_bss_info_changed_ap(wl, vif, bss_conf, changed); | ||
3431 | else | ||
3432 | wl1271_bss_info_changed_sta(wl, vif, bss_conf, changed); | ||
3433 | |||
3434 | wl1271_ps_elp_sleep(wl); | ||
3435 | |||
3436 | out: | ||
3437 | mutex_unlock(&wl->mutex); | ||
3438 | } | ||
3439 | |||
3440 | static int wl1271_op_conf_tx(struct ieee80211_hw *hw, u16 queue, | ||
3441 | const struct ieee80211_tx_queue_params *params) | ||
3442 | { | ||
3443 | struct wl1271 *wl = hw->priv; | ||
3444 | u8 ps_scheme; | ||
3445 | int ret = 0; | ||
3446 | |||
3447 | mutex_lock(&wl->mutex); | ||
3448 | |||
3449 | wl1271_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue); | ||
3450 | |||
3451 | if (params->uapsd) | ||
3452 | ps_scheme = CONF_PS_SCHEME_UPSD_TRIGGER; | ||
3453 | else | ||
3454 | ps_scheme = CONF_PS_SCHEME_LEGACY; | ||
3455 | |||
3456 | if (wl->state == WL1271_STATE_OFF) { | ||
3457 | /* | ||
3458 | * If the state is off, the parameters will be recorded and | ||
3459 | * configured on init. This happens in AP-mode. | ||
3460 | */ | ||
3461 | struct conf_tx_ac_category *conf_ac = | ||
3462 | &wl->conf.tx.ac_conf[wl1271_tx_get_queue(queue)]; | ||
3463 | struct conf_tx_tid *conf_tid = | ||
3464 | &wl->conf.tx.tid_conf[wl1271_tx_get_queue(queue)]; | ||
3465 | |||
3466 | conf_ac->ac = wl1271_tx_get_queue(queue); | ||
3467 | conf_ac->cw_min = (u8)params->cw_min; | ||
3468 | conf_ac->cw_max = params->cw_max; | ||
3469 | conf_ac->aifsn = params->aifs; | ||
3470 | conf_ac->tx_op_limit = params->txop << 5; | ||
3471 | |||
3472 | conf_tid->queue_id = wl1271_tx_get_queue(queue); | ||
3473 | conf_tid->channel_type = CONF_CHANNEL_TYPE_EDCF; | ||
3474 | conf_tid->tsid = wl1271_tx_get_queue(queue); | ||
3475 | conf_tid->ps_scheme = ps_scheme; | ||
3476 | conf_tid->ack_policy = CONF_ACK_POLICY_LEGACY; | ||
3477 | conf_tid->apsd_conf[0] = 0; | ||
3478 | conf_tid->apsd_conf[1] = 0; | ||
3479 | goto out; | ||
3480 | } | ||
3481 | |||
3482 | ret = wl1271_ps_elp_wakeup(wl); | ||
3483 | if (ret < 0) | ||
3484 | goto out; | ||
3485 | |||
3486 | /* | ||
3487 | * the txop is confed in units of 32us by the mac80211, | ||
3488 | * we need us | ||
3489 | */ | ||
3490 | ret = wl1271_acx_ac_cfg(wl, wl1271_tx_get_queue(queue), | ||
3491 | params->cw_min, params->cw_max, | ||
3492 | params->aifs, params->txop << 5); | ||
3493 | if (ret < 0) | ||
3494 | goto out_sleep; | ||
3495 | |||
3496 | ret = wl1271_acx_tid_cfg(wl, wl1271_tx_get_queue(queue), | ||
3497 | CONF_CHANNEL_TYPE_EDCF, | ||
3498 | wl1271_tx_get_queue(queue), | ||
3499 | ps_scheme, CONF_ACK_POLICY_LEGACY, | ||
3500 | 0, 0); | ||
3501 | |||
3502 | out_sleep: | ||
3503 | wl1271_ps_elp_sleep(wl); | ||
3504 | |||
3505 | out: | ||
3506 | mutex_unlock(&wl->mutex); | ||
3507 | |||
3508 | return ret; | ||
3509 | } | ||
3510 | |||
3511 | static u64 wl1271_op_get_tsf(struct ieee80211_hw *hw) | ||
3512 | { | ||
3513 | |||
3514 | struct wl1271 *wl = hw->priv; | ||
3515 | u64 mactime = ULLONG_MAX; | ||
3516 | int ret; | ||
3517 | |||
3518 | wl1271_debug(DEBUG_MAC80211, "mac80211 get tsf"); | ||
3519 | |||
3520 | mutex_lock(&wl->mutex); | ||
3521 | |||
3522 | if (unlikely(wl->state == WL1271_STATE_OFF)) | ||
3523 | goto out; | ||
3524 | |||
3525 | ret = wl1271_ps_elp_wakeup(wl); | ||
3526 | if (ret < 0) | ||
3527 | goto out; | ||
3528 | |||
3529 | ret = wl1271_acx_tsf_info(wl, &mactime); | ||
3530 | if (ret < 0) | ||
3531 | goto out_sleep; | ||
3532 | |||
3533 | out_sleep: | ||
3534 | wl1271_ps_elp_sleep(wl); | ||
3535 | |||
3536 | out: | ||
3537 | mutex_unlock(&wl->mutex); | ||
3538 | return mactime; | ||
3539 | } | ||
3540 | |||
3541 | static int wl1271_op_get_survey(struct ieee80211_hw *hw, int idx, | ||
3542 | struct survey_info *survey) | ||
3543 | { | ||
3544 | struct wl1271 *wl = hw->priv; | ||
3545 | struct ieee80211_conf *conf = &hw->conf; | ||
3546 | |||
3547 | if (idx != 0) | ||
3548 | return -ENOENT; | ||
3549 | |||
3550 | survey->channel = conf->channel; | ||
3551 | survey->filled = SURVEY_INFO_NOISE_DBM; | ||
3552 | survey->noise = wl->noise; | ||
3553 | |||
3554 | return 0; | ||
3555 | } | ||
3556 | |||
3557 | static int wl1271_allocate_sta(struct wl1271 *wl, | ||
3558 | struct ieee80211_sta *sta, | ||
3559 | u8 *hlid) | ||
3560 | { | ||
3561 | struct wl1271_station *wl_sta; | ||
3562 | int id; | ||
3563 | |||
3564 | id = find_first_zero_bit(wl->ap_hlid_map, AP_MAX_STATIONS); | ||
3565 | if (id >= AP_MAX_STATIONS) { | ||
3566 | wl1271_warning("could not allocate HLID - too much stations"); | ||
3567 | return -EBUSY; | ||
3568 | } | ||
3569 | |||
3570 | wl_sta = (struct wl1271_station *)sta->drv_priv; | ||
3571 | __set_bit(id, wl->ap_hlid_map); | ||
3572 | wl_sta->hlid = WL1271_AP_STA_HLID_START + id; | ||
3573 | *hlid = wl_sta->hlid; | ||
3574 | memcpy(wl->links[wl_sta->hlid].addr, sta->addr, ETH_ALEN); | ||
3575 | return 0; | ||
3576 | } | ||
3577 | |||
3578 | static void wl1271_free_sta(struct wl1271 *wl, u8 hlid) | ||
3579 | { | ||
3580 | int id = hlid - WL1271_AP_STA_HLID_START; | ||
3581 | |||
3582 | if (WARN_ON(!test_bit(id, wl->ap_hlid_map))) | ||
3583 | return; | ||
3584 | |||
3585 | __clear_bit(id, wl->ap_hlid_map); | ||
3586 | memset(wl->links[hlid].addr, 0, ETH_ALEN); | ||
3587 | wl1271_tx_reset_link_queues(wl, hlid); | ||
3588 | __clear_bit(hlid, &wl->ap_ps_map); | ||
3589 | __clear_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map); | ||
3590 | } | ||
3591 | |||
3592 | bool wl1271_is_active_sta(struct wl1271 *wl, u8 hlid) | ||
3593 | { | ||
3594 | int id = hlid - WL1271_AP_STA_HLID_START; | ||
3595 | return test_bit(id, wl->ap_hlid_map); | ||
3596 | } | ||
3597 | |||
3598 | static int wl1271_op_sta_add(struct ieee80211_hw *hw, | ||
3599 | struct ieee80211_vif *vif, | ||
3600 | struct ieee80211_sta *sta) | ||
3601 | { | ||
3602 | struct wl1271 *wl = hw->priv; | ||
3603 | int ret = 0; | ||
3604 | u8 hlid; | ||
3605 | |||
3606 | mutex_lock(&wl->mutex); | ||
3607 | |||
3608 | if (unlikely(wl->state == WL1271_STATE_OFF)) | ||
3609 | goto out; | ||
3610 | |||
3611 | if (wl->bss_type != BSS_TYPE_AP_BSS) | ||
3612 | goto out; | ||
3613 | |||
3614 | wl1271_debug(DEBUG_MAC80211, "mac80211 add sta %d", (int)sta->aid); | ||
3615 | |||
3616 | ret = wl1271_allocate_sta(wl, sta, &hlid); | ||
3617 | if (ret < 0) | ||
3618 | goto out; | ||
3619 | |||
3620 | ret = wl1271_ps_elp_wakeup(wl); | ||
3621 | if (ret < 0) | ||
3622 | goto out_free_sta; | ||
3623 | |||
3624 | ret = wl1271_cmd_add_sta(wl, sta, hlid); | ||
3625 | if (ret < 0) | ||
3626 | goto out_sleep; | ||
3627 | |||
3628 | out_sleep: | ||
3629 | wl1271_ps_elp_sleep(wl); | ||
3630 | |||
3631 | out_free_sta: | ||
3632 | if (ret < 0) | ||
3633 | wl1271_free_sta(wl, hlid); | ||
3634 | |||
3635 | out: | ||
3636 | mutex_unlock(&wl->mutex); | ||
3637 | return ret; | ||
3638 | } | ||
3639 | |||
3640 | static int wl1271_op_sta_remove(struct ieee80211_hw *hw, | ||
3641 | struct ieee80211_vif *vif, | ||
3642 | struct ieee80211_sta *sta) | ||
3643 | { | ||
3644 | struct wl1271 *wl = hw->priv; | ||
3645 | struct wl1271_station *wl_sta; | ||
3646 | int ret = 0, id; | ||
3647 | |||
3648 | mutex_lock(&wl->mutex); | ||
3649 | |||
3650 | if (unlikely(wl->state == WL1271_STATE_OFF)) | ||
3651 | goto out; | ||
3652 | |||
3653 | if (wl->bss_type != BSS_TYPE_AP_BSS) | ||
3654 | goto out; | ||
3655 | |||
3656 | wl1271_debug(DEBUG_MAC80211, "mac80211 remove sta %d", (int)sta->aid); | ||
3657 | |||
3658 | wl_sta = (struct wl1271_station *)sta->drv_priv; | ||
3659 | id = wl_sta->hlid - WL1271_AP_STA_HLID_START; | ||
3660 | if (WARN_ON(!test_bit(id, wl->ap_hlid_map))) | ||
3661 | goto out; | ||
3662 | |||
3663 | ret = wl1271_ps_elp_wakeup(wl); | ||
3664 | if (ret < 0) | ||
3665 | goto out; | ||
3666 | |||
3667 | ret = wl1271_cmd_remove_sta(wl, wl_sta->hlid); | ||
3668 | if (ret < 0) | ||
3669 | goto out_sleep; | ||
3670 | |||
3671 | wl1271_free_sta(wl, wl_sta->hlid); | ||
3672 | |||
3673 | out_sleep: | ||
3674 | wl1271_ps_elp_sleep(wl); | ||
3675 | |||
3676 | out: | ||
3677 | mutex_unlock(&wl->mutex); | ||
3678 | return ret; | ||
3679 | } | ||
3680 | |||
3681 | static int wl1271_op_ampdu_action(struct ieee80211_hw *hw, | ||
3682 | struct ieee80211_vif *vif, | ||
3683 | enum ieee80211_ampdu_mlme_action action, | ||
3684 | struct ieee80211_sta *sta, u16 tid, u16 *ssn, | ||
3685 | u8 buf_size) | ||
3686 | { | ||
3687 | struct wl1271 *wl = hw->priv; | ||
3688 | int ret; | ||
3689 | |||
3690 | mutex_lock(&wl->mutex); | ||
3691 | |||
3692 | if (unlikely(wl->state == WL1271_STATE_OFF)) { | ||
3693 | ret = -EAGAIN; | ||
3694 | goto out; | ||
3695 | } | ||
3696 | |||
3697 | ret = wl1271_ps_elp_wakeup(wl); | ||
3698 | if (ret < 0) | ||
3699 | goto out; | ||
3700 | |||
3701 | wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu: Rx tid %d action %d", | ||
3702 | tid, action); | ||
3703 | |||
3704 | switch (action) { | ||
3705 | case IEEE80211_AMPDU_RX_START: | ||
3706 | if ((wl->ba_support) && (wl->ba_allowed)) { | ||
3707 | ret = wl1271_acx_set_ba_receiver_session(wl, tid, *ssn, | ||
3708 | true); | ||
3709 | if (!ret) | ||
3710 | wl->ba_rx_bitmap |= BIT(tid); | ||
3711 | } else { | ||
3712 | ret = -ENOTSUPP; | ||
3713 | } | ||
3714 | break; | ||
3715 | |||
3716 | case IEEE80211_AMPDU_RX_STOP: | ||
3717 | ret = wl1271_acx_set_ba_receiver_session(wl, tid, 0, false); | ||
3718 | if (!ret) | ||
3719 | wl->ba_rx_bitmap &= ~BIT(tid); | ||
3720 | break; | ||
3721 | |||
3722 | /* | ||
3723 | * The BA initiator session management in FW independently. | ||
3724 | * Falling break here on purpose for all TX APDU commands. | ||
3725 | */ | ||
3726 | case IEEE80211_AMPDU_TX_START: | ||
3727 | case IEEE80211_AMPDU_TX_STOP: | ||
3728 | case IEEE80211_AMPDU_TX_OPERATIONAL: | ||
3729 | ret = -EINVAL; | ||
3730 | break; | ||
3731 | |||
3732 | default: | ||
3733 | wl1271_error("Incorrect ampdu action id=%x\n", action); | ||
3734 | ret = -EINVAL; | ||
3735 | } | ||
3736 | |||
3737 | wl1271_ps_elp_sleep(wl); | ||
3738 | |||
3739 | out: | ||
3740 | mutex_unlock(&wl->mutex); | ||
3741 | |||
3742 | return ret; | ||
3743 | } | ||
3744 | |||
3745 | static bool wl1271_tx_frames_pending(struct ieee80211_hw *hw) | ||
3746 | { | ||
3747 | struct wl1271 *wl = hw->priv; | ||
3748 | bool ret = false; | ||
3749 | |||
3750 | mutex_lock(&wl->mutex); | ||
3751 | |||
3752 | if (unlikely(wl->state == WL1271_STATE_OFF)) | ||
3753 | goto out; | ||
3754 | |||
3755 | /* packets are considered pending if in the TX queue or the FW */ | ||
3756 | ret = (wl1271_tx_total_queue_count(wl) > 0) || (wl->tx_frames_cnt > 0); | ||
3757 | |||
3758 | /* the above is appropriate for STA mode for PS purposes */ | ||
3759 | WARN_ON(wl->bss_type != BSS_TYPE_STA_BSS); | ||
3760 | |||
3761 | out: | ||
3762 | mutex_unlock(&wl->mutex); | ||
3763 | |||
3764 | return ret; | ||
3765 | } | ||
3766 | |||
3767 | /* can't be const, mac80211 writes to this */ | ||
3768 | static struct ieee80211_rate wl1271_rates[] = { | ||
3769 | { .bitrate = 10, | ||
3770 | .hw_value = CONF_HW_BIT_RATE_1MBPS, | ||
3771 | .hw_value_short = CONF_HW_BIT_RATE_1MBPS, }, | ||
3772 | { .bitrate = 20, | ||
3773 | .hw_value = CONF_HW_BIT_RATE_2MBPS, | ||
3774 | .hw_value_short = CONF_HW_BIT_RATE_2MBPS, | ||
3775 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | ||
3776 | { .bitrate = 55, | ||
3777 | .hw_value = CONF_HW_BIT_RATE_5_5MBPS, | ||
3778 | .hw_value_short = CONF_HW_BIT_RATE_5_5MBPS, | ||
3779 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | ||
3780 | { .bitrate = 110, | ||
3781 | .hw_value = CONF_HW_BIT_RATE_11MBPS, | ||
3782 | .hw_value_short = CONF_HW_BIT_RATE_11MBPS, | ||
3783 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | ||
3784 | { .bitrate = 60, | ||
3785 | .hw_value = CONF_HW_BIT_RATE_6MBPS, | ||
3786 | .hw_value_short = CONF_HW_BIT_RATE_6MBPS, }, | ||
3787 | { .bitrate = 90, | ||
3788 | .hw_value = CONF_HW_BIT_RATE_9MBPS, | ||
3789 | .hw_value_short = CONF_HW_BIT_RATE_9MBPS, }, | ||
3790 | { .bitrate = 120, | ||
3791 | .hw_value = CONF_HW_BIT_RATE_12MBPS, | ||
3792 | .hw_value_short = CONF_HW_BIT_RATE_12MBPS, }, | ||
3793 | { .bitrate = 180, | ||
3794 | .hw_value = CONF_HW_BIT_RATE_18MBPS, | ||
3795 | .hw_value_short = CONF_HW_BIT_RATE_18MBPS, }, | ||
3796 | { .bitrate = 240, | ||
3797 | .hw_value = CONF_HW_BIT_RATE_24MBPS, | ||
3798 | .hw_value_short = CONF_HW_BIT_RATE_24MBPS, }, | ||
3799 | { .bitrate = 360, | ||
3800 | .hw_value = CONF_HW_BIT_RATE_36MBPS, | ||
3801 | .hw_value_short = CONF_HW_BIT_RATE_36MBPS, }, | ||
3802 | { .bitrate = 480, | ||
3803 | .hw_value = CONF_HW_BIT_RATE_48MBPS, | ||
3804 | .hw_value_short = CONF_HW_BIT_RATE_48MBPS, }, | ||
3805 | { .bitrate = 540, | ||
3806 | .hw_value = CONF_HW_BIT_RATE_54MBPS, | ||
3807 | .hw_value_short = CONF_HW_BIT_RATE_54MBPS, }, | ||
3808 | }; | ||
3809 | |||
3810 | /* can't be const, mac80211 writes to this */ | ||
3811 | static struct ieee80211_channel wl1271_channels[] = { | ||
3812 | { .hw_value = 1, .center_freq = 2412, .max_power = 25 }, | ||
3813 | { .hw_value = 2, .center_freq = 2417, .max_power = 25 }, | ||
3814 | { .hw_value = 3, .center_freq = 2422, .max_power = 25 }, | ||
3815 | { .hw_value = 4, .center_freq = 2427, .max_power = 25 }, | ||
3816 | { .hw_value = 5, .center_freq = 2432, .max_power = 25 }, | ||
3817 | { .hw_value = 6, .center_freq = 2437, .max_power = 25 }, | ||
3818 | { .hw_value = 7, .center_freq = 2442, .max_power = 25 }, | ||
3819 | { .hw_value = 8, .center_freq = 2447, .max_power = 25 }, | ||
3820 | { .hw_value = 9, .center_freq = 2452, .max_power = 25 }, | ||
3821 | { .hw_value = 10, .center_freq = 2457, .max_power = 25 }, | ||
3822 | { .hw_value = 11, .center_freq = 2462, .max_power = 25 }, | ||
3823 | { .hw_value = 12, .center_freq = 2467, .max_power = 25 }, | ||
3824 | { .hw_value = 13, .center_freq = 2472, .max_power = 25 }, | ||
3825 | { .hw_value = 14, .center_freq = 2484, .max_power = 25 }, | ||
3826 | }; | ||
3827 | |||
3828 | /* mapping to indexes for wl1271_rates */ | ||
3829 | static const u8 wl1271_rate_to_idx_2ghz[] = { | ||
3830 | /* MCS rates are used only with 11n */ | ||
3831 | 7, /* CONF_HW_RXTX_RATE_MCS7 */ | ||
3832 | 6, /* CONF_HW_RXTX_RATE_MCS6 */ | ||
3833 | 5, /* CONF_HW_RXTX_RATE_MCS5 */ | ||
3834 | 4, /* CONF_HW_RXTX_RATE_MCS4 */ | ||
3835 | 3, /* CONF_HW_RXTX_RATE_MCS3 */ | ||
3836 | 2, /* CONF_HW_RXTX_RATE_MCS2 */ | ||
3837 | 1, /* CONF_HW_RXTX_RATE_MCS1 */ | ||
3838 | 0, /* CONF_HW_RXTX_RATE_MCS0 */ | ||
3839 | |||
3840 | 11, /* CONF_HW_RXTX_RATE_54 */ | ||
3841 | 10, /* CONF_HW_RXTX_RATE_48 */ | ||
3842 | 9, /* CONF_HW_RXTX_RATE_36 */ | ||
3843 | 8, /* CONF_HW_RXTX_RATE_24 */ | ||
3844 | |||
3845 | /* TI-specific rate */ | ||
3846 | CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_22 */ | ||
3847 | |||
3848 | 7, /* CONF_HW_RXTX_RATE_18 */ | ||
3849 | 6, /* CONF_HW_RXTX_RATE_12 */ | ||
3850 | 3, /* CONF_HW_RXTX_RATE_11 */ | ||
3851 | 5, /* CONF_HW_RXTX_RATE_9 */ | ||
3852 | 4, /* CONF_HW_RXTX_RATE_6 */ | ||
3853 | 2, /* CONF_HW_RXTX_RATE_5_5 */ | ||
3854 | 1, /* CONF_HW_RXTX_RATE_2 */ | ||
3855 | 0 /* CONF_HW_RXTX_RATE_1 */ | ||
3856 | }; | ||
3857 | |||
3858 | /* 11n STA capabilities */ | ||
3859 | #define HW_RX_HIGHEST_RATE 72 | ||
3860 | |||
3861 | #ifdef CONFIG_WL12XX_HT | ||
3862 | #define WL12XX_HT_CAP { \ | ||
3863 | .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 | \ | ||
3864 | (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT), \ | ||
3865 | .ht_supported = true, \ | ||
3866 | .ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K, \ | ||
3867 | .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, \ | ||
3868 | .mcs = { \ | ||
3869 | .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, \ | ||
3870 | .rx_highest = cpu_to_le16(HW_RX_HIGHEST_RATE), \ | ||
3871 | .tx_params = IEEE80211_HT_MCS_TX_DEFINED, \ | ||
3872 | }, \ | ||
3873 | } | ||
3874 | #else | ||
3875 | #define WL12XX_HT_CAP { \ | ||
3876 | .ht_supported = false, \ | ||
3877 | } | ||
3878 | #endif | ||
3879 | |||
3880 | /* can't be const, mac80211 writes to this */ | ||
3881 | static struct ieee80211_supported_band wl1271_band_2ghz = { | ||
3882 | .channels = wl1271_channels, | ||
3883 | .n_channels = ARRAY_SIZE(wl1271_channels), | ||
3884 | .bitrates = wl1271_rates, | ||
3885 | .n_bitrates = ARRAY_SIZE(wl1271_rates), | ||
3886 | .ht_cap = WL12XX_HT_CAP, | ||
3887 | }; | ||
3888 | |||
3889 | /* 5 GHz data rates for WL1273 */ | ||
3890 | static struct ieee80211_rate wl1271_rates_5ghz[] = { | ||
3891 | { .bitrate = 60, | ||
3892 | .hw_value = CONF_HW_BIT_RATE_6MBPS, | ||
3893 | .hw_value_short = CONF_HW_BIT_RATE_6MBPS, }, | ||
3894 | { .bitrate = 90, | ||
3895 | .hw_value = CONF_HW_BIT_RATE_9MBPS, | ||
3896 | .hw_value_short = CONF_HW_BIT_RATE_9MBPS, }, | ||
3897 | { .bitrate = 120, | ||
3898 | .hw_value = CONF_HW_BIT_RATE_12MBPS, | ||
3899 | .hw_value_short = CONF_HW_BIT_RATE_12MBPS, }, | ||
3900 | { .bitrate = 180, | ||
3901 | .hw_value = CONF_HW_BIT_RATE_18MBPS, | ||
3902 | .hw_value_short = CONF_HW_BIT_RATE_18MBPS, }, | ||
3903 | { .bitrate = 240, | ||
3904 | .hw_value = CONF_HW_BIT_RATE_24MBPS, | ||
3905 | .hw_value_short = CONF_HW_BIT_RATE_24MBPS, }, | ||
3906 | { .bitrate = 360, | ||
3907 | .hw_value = CONF_HW_BIT_RATE_36MBPS, | ||
3908 | .hw_value_short = CONF_HW_BIT_RATE_36MBPS, }, | ||
3909 | { .bitrate = 480, | ||
3910 | .hw_value = CONF_HW_BIT_RATE_48MBPS, | ||
3911 | .hw_value_short = CONF_HW_BIT_RATE_48MBPS, }, | ||
3912 | { .bitrate = 540, | ||
3913 | .hw_value = CONF_HW_BIT_RATE_54MBPS, | ||
3914 | .hw_value_short = CONF_HW_BIT_RATE_54MBPS, }, | ||
3915 | }; | ||
3916 | |||
3917 | /* 5 GHz band channels for WL1273 */ | ||
3918 | static struct ieee80211_channel wl1271_channels_5ghz[] = { | ||
3919 | { .hw_value = 7, .center_freq = 5035, .max_power = 25 }, | ||
3920 | { .hw_value = 8, .center_freq = 5040, .max_power = 25 }, | ||
3921 | { .hw_value = 9, .center_freq = 5045, .max_power = 25 }, | ||
3922 | { .hw_value = 11, .center_freq = 5055, .max_power = 25 }, | ||
3923 | { .hw_value = 12, .center_freq = 5060, .max_power = 25 }, | ||
3924 | { .hw_value = 16, .center_freq = 5080, .max_power = 25 }, | ||
3925 | { .hw_value = 34, .center_freq = 5170, .max_power = 25 }, | ||
3926 | { .hw_value = 36, .center_freq = 5180, .max_power = 25 }, | ||
3927 | { .hw_value = 38, .center_freq = 5190, .max_power = 25 }, | ||
3928 | { .hw_value = 40, .center_freq = 5200, .max_power = 25 }, | ||
3929 | { .hw_value = 42, .center_freq = 5210, .max_power = 25 }, | ||
3930 | { .hw_value = 44, .center_freq = 5220, .max_power = 25 }, | ||
3931 | { .hw_value = 46, .center_freq = 5230, .max_power = 25 }, | ||
3932 | { .hw_value = 48, .center_freq = 5240, .max_power = 25 }, | ||
3933 | { .hw_value = 52, .center_freq = 5260, .max_power = 25 }, | ||
3934 | { .hw_value = 56, .center_freq = 5280, .max_power = 25 }, | ||
3935 | { .hw_value = 60, .center_freq = 5300, .max_power = 25 }, | ||
3936 | { .hw_value = 64, .center_freq = 5320, .max_power = 25 }, | ||
3937 | { .hw_value = 100, .center_freq = 5500, .max_power = 25 }, | ||
3938 | { .hw_value = 104, .center_freq = 5520, .max_power = 25 }, | ||
3939 | { .hw_value = 108, .center_freq = 5540, .max_power = 25 }, | ||
3940 | { .hw_value = 112, .center_freq = 5560, .max_power = 25 }, | ||
3941 | { .hw_value = 116, .center_freq = 5580, .max_power = 25 }, | ||
3942 | { .hw_value = 120, .center_freq = 5600, .max_power = 25 }, | ||
3943 | { .hw_value = 124, .center_freq = 5620, .max_power = 25 }, | ||
3944 | { .hw_value = 128, .center_freq = 5640, .max_power = 25 }, | ||
3945 | { .hw_value = 132, .center_freq = 5660, .max_power = 25 }, | ||
3946 | { .hw_value = 136, .center_freq = 5680, .max_power = 25 }, | ||
3947 | { .hw_value = 140, .center_freq = 5700, .max_power = 25 }, | ||
3948 | { .hw_value = 149, .center_freq = 5745, .max_power = 25 }, | ||
3949 | { .hw_value = 153, .center_freq = 5765, .max_power = 25 }, | ||
3950 | { .hw_value = 157, .center_freq = 5785, .max_power = 25 }, | ||
3951 | { .hw_value = 161, .center_freq = 5805, .max_power = 25 }, | ||
3952 | { .hw_value = 165, .center_freq = 5825, .max_power = 25 }, | ||
3953 | }; | ||
3954 | |||
3955 | /* mapping to indexes for wl1271_rates_5ghz */ | ||
3956 | static const u8 wl1271_rate_to_idx_5ghz[] = { | ||
3957 | /* MCS rates are used only with 11n */ | ||
3958 | 7, /* CONF_HW_RXTX_RATE_MCS7 */ | ||
3959 | 6, /* CONF_HW_RXTX_RATE_MCS6 */ | ||
3960 | 5, /* CONF_HW_RXTX_RATE_MCS5 */ | ||
3961 | 4, /* CONF_HW_RXTX_RATE_MCS4 */ | ||
3962 | 3, /* CONF_HW_RXTX_RATE_MCS3 */ | ||
3963 | 2, /* CONF_HW_RXTX_RATE_MCS2 */ | ||
3964 | 1, /* CONF_HW_RXTX_RATE_MCS1 */ | ||
3965 | 0, /* CONF_HW_RXTX_RATE_MCS0 */ | ||
3966 | |||
3967 | 7, /* CONF_HW_RXTX_RATE_54 */ | ||
3968 | 6, /* CONF_HW_RXTX_RATE_48 */ | ||
3969 | 5, /* CONF_HW_RXTX_RATE_36 */ | ||
3970 | 4, /* CONF_HW_RXTX_RATE_24 */ | ||
3971 | |||
3972 | /* TI-specific rate */ | ||
3973 | CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_22 */ | ||
3974 | |||
3975 | 3, /* CONF_HW_RXTX_RATE_18 */ | ||
3976 | 2, /* CONF_HW_RXTX_RATE_12 */ | ||
3977 | CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_11 */ | ||
3978 | 1, /* CONF_HW_RXTX_RATE_9 */ | ||
3979 | 0, /* CONF_HW_RXTX_RATE_6 */ | ||
3980 | CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_5_5 */ | ||
3981 | CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_2 */ | ||
3982 | CONF_HW_RXTX_RATE_UNSUPPORTED /* CONF_HW_RXTX_RATE_1 */ | ||
3983 | }; | ||
3984 | |||
3985 | static struct ieee80211_supported_band wl1271_band_5ghz = { | ||
3986 | .channels = wl1271_channels_5ghz, | ||
3987 | .n_channels = ARRAY_SIZE(wl1271_channels_5ghz), | ||
3988 | .bitrates = wl1271_rates_5ghz, | ||
3989 | .n_bitrates = ARRAY_SIZE(wl1271_rates_5ghz), | ||
3990 | .ht_cap = WL12XX_HT_CAP, | ||
3991 | }; | ||
3992 | |||
3993 | static const u8 *wl1271_band_rate_to_idx[] = { | ||
3994 | [IEEE80211_BAND_2GHZ] = wl1271_rate_to_idx_2ghz, | ||
3995 | [IEEE80211_BAND_5GHZ] = wl1271_rate_to_idx_5ghz | ||
3996 | }; | ||
3997 | |||
3998 | static const struct ieee80211_ops wl1271_ops = { | ||
3999 | .start = wl1271_op_start, | ||
4000 | .stop = wl1271_op_stop, | ||
4001 | .add_interface = wl1271_op_add_interface, | ||
4002 | .remove_interface = wl1271_op_remove_interface, | ||
4003 | #ifdef CONFIG_PM | ||
4004 | .suspend = wl1271_op_suspend, | ||
4005 | .resume = wl1271_op_resume, | ||
4006 | #endif | ||
4007 | .config = wl1271_op_config, | ||
4008 | .prepare_multicast = wl1271_op_prepare_multicast, | ||
4009 | .configure_filter = wl1271_op_configure_filter, | ||
4010 | .tx = wl1271_op_tx, | ||
4011 | .set_key = wl1271_op_set_key, | ||
4012 | .hw_scan = wl1271_op_hw_scan, | ||
4013 | .cancel_hw_scan = wl1271_op_cancel_hw_scan, | ||
4014 | .sched_scan_start = wl1271_op_sched_scan_start, | ||
4015 | .sched_scan_stop = wl1271_op_sched_scan_stop, | ||
4016 | .bss_info_changed = wl1271_op_bss_info_changed, | ||
4017 | .set_frag_threshold = wl1271_op_set_frag_threshold, | ||
4018 | .set_rts_threshold = wl1271_op_set_rts_threshold, | ||
4019 | .conf_tx = wl1271_op_conf_tx, | ||
4020 | .get_tsf = wl1271_op_get_tsf, | ||
4021 | .get_survey = wl1271_op_get_survey, | ||
4022 | .sta_add = wl1271_op_sta_add, | ||
4023 | .sta_remove = wl1271_op_sta_remove, | ||
4024 | .ampdu_action = wl1271_op_ampdu_action, | ||
4025 | .tx_frames_pending = wl1271_tx_frames_pending, | ||
4026 | CFG80211_TESTMODE_CMD(wl1271_tm_cmd) | ||
4027 | }; | ||
4028 | |||
4029 | |||
4030 | u8 wl1271_rate_to_idx(int rate, enum ieee80211_band band) | ||
4031 | { | ||
4032 | u8 idx; | ||
4033 | |||
4034 | BUG_ON(band >= sizeof(wl1271_band_rate_to_idx)/sizeof(u8 *)); | ||
4035 | |||
4036 | if (unlikely(rate >= CONF_HW_RXTX_RATE_MAX)) { | ||
4037 | wl1271_error("Illegal RX rate from HW: %d", rate); | ||
4038 | return 0; | ||
4039 | } | ||
4040 | |||
4041 | idx = wl1271_band_rate_to_idx[band][rate]; | ||
4042 | if (unlikely(idx == CONF_HW_RXTX_RATE_UNSUPPORTED)) { | ||
4043 | wl1271_error("Unsupported RX rate from HW: %d", rate); | ||
4044 | return 0; | ||
4045 | } | ||
4046 | |||
4047 | return idx; | ||
4048 | } | ||
4049 | |||
4050 | static ssize_t wl1271_sysfs_show_bt_coex_state(struct device *dev, | ||
4051 | struct device_attribute *attr, | ||
4052 | char *buf) | ||
4053 | { | ||
4054 | struct wl1271 *wl = dev_get_drvdata(dev); | ||
4055 | ssize_t len; | ||
4056 | |||
4057 | len = PAGE_SIZE; | ||
4058 | |||
4059 | mutex_lock(&wl->mutex); | ||
4060 | len = snprintf(buf, len, "%d\n\n0 - off\n1 - on\n", | ||
4061 | wl->sg_enabled); | ||
4062 | mutex_unlock(&wl->mutex); | ||
4063 | |||
4064 | return len; | ||
4065 | |||
4066 | } | ||
4067 | |||
4068 | static ssize_t wl1271_sysfs_store_bt_coex_state(struct device *dev, | ||
4069 | struct device_attribute *attr, | ||
4070 | const char *buf, size_t count) | ||
4071 | { | ||
4072 | struct wl1271 *wl = dev_get_drvdata(dev); | ||
4073 | unsigned long res; | ||
4074 | int ret; | ||
4075 | |||
4076 | ret = kstrtoul(buf, 10, &res); | ||
4077 | if (ret < 0) { | ||
4078 | wl1271_warning("incorrect value written to bt_coex_mode"); | ||
4079 | return count; | ||
4080 | } | ||
4081 | |||
4082 | mutex_lock(&wl->mutex); | ||
4083 | |||
4084 | res = !!res; | ||
4085 | |||
4086 | if (res == wl->sg_enabled) | ||
4087 | goto out; | ||
4088 | |||
4089 | wl->sg_enabled = res; | ||
4090 | |||
4091 | if (wl->state == WL1271_STATE_OFF) | ||
4092 | goto out; | ||
4093 | |||
4094 | ret = wl1271_ps_elp_wakeup(wl); | ||
4095 | if (ret < 0) | ||
4096 | goto out; | ||
4097 | |||
4098 | wl1271_acx_sg_enable(wl, wl->sg_enabled); | ||
4099 | wl1271_ps_elp_sleep(wl); | ||
4100 | |||
4101 | out: | ||
4102 | mutex_unlock(&wl->mutex); | ||
4103 | return count; | ||
4104 | } | ||
4105 | |||
4106 | static DEVICE_ATTR(bt_coex_state, S_IRUGO | S_IWUSR, | ||
4107 | wl1271_sysfs_show_bt_coex_state, | ||
4108 | wl1271_sysfs_store_bt_coex_state); | ||
4109 | |||
4110 | static ssize_t wl1271_sysfs_show_hw_pg_ver(struct device *dev, | ||
4111 | struct device_attribute *attr, | ||
4112 | char *buf) | ||
4113 | { | ||
4114 | struct wl1271 *wl = dev_get_drvdata(dev); | ||
4115 | ssize_t len; | ||
4116 | |||
4117 | len = PAGE_SIZE; | ||
4118 | |||
4119 | mutex_lock(&wl->mutex); | ||
4120 | if (wl->hw_pg_ver >= 0) | ||
4121 | len = snprintf(buf, len, "%d\n", wl->hw_pg_ver); | ||
4122 | else | ||
4123 | len = snprintf(buf, len, "n/a\n"); | ||
4124 | mutex_unlock(&wl->mutex); | ||
4125 | |||
4126 | return len; | ||
4127 | } | ||
4128 | |||
4129 | static DEVICE_ATTR(hw_pg_ver, S_IRUGO | S_IWUSR, | ||
4130 | wl1271_sysfs_show_hw_pg_ver, NULL); | ||
4131 | |||
4132 | static ssize_t wl1271_sysfs_read_fwlog(struct file *filp, struct kobject *kobj, | ||
4133 | struct bin_attribute *bin_attr, | ||
4134 | char *buffer, loff_t pos, size_t count) | ||
4135 | { | ||
4136 | struct device *dev = container_of(kobj, struct device, kobj); | ||
4137 | struct wl1271 *wl = dev_get_drvdata(dev); | ||
4138 | ssize_t len; | ||
4139 | int ret; | ||
4140 | |||
4141 | ret = mutex_lock_interruptible(&wl->mutex); | ||
4142 | if (ret < 0) | ||
4143 | return -ERESTARTSYS; | ||
4144 | |||
4145 | /* Let only one thread read the log at a time, blocking others */ | ||
4146 | while (wl->fwlog_size == 0) { | ||
4147 | DEFINE_WAIT(wait); | ||
4148 | |||
4149 | prepare_to_wait_exclusive(&wl->fwlog_waitq, | ||
4150 | &wait, | ||
4151 | TASK_INTERRUPTIBLE); | ||
4152 | |||
4153 | if (wl->fwlog_size != 0) { | ||
4154 | finish_wait(&wl->fwlog_waitq, &wait); | ||
4155 | break; | ||
4156 | } | ||
4157 | |||
4158 | mutex_unlock(&wl->mutex); | ||
4159 | |||
4160 | schedule(); | ||
4161 | finish_wait(&wl->fwlog_waitq, &wait); | ||
4162 | |||
4163 | if (signal_pending(current)) | ||
4164 | return -ERESTARTSYS; | ||
4165 | |||
4166 | ret = mutex_lock_interruptible(&wl->mutex); | ||
4167 | if (ret < 0) | ||
4168 | return -ERESTARTSYS; | ||
4169 | } | ||
4170 | |||
4171 | /* Check if the fwlog is still valid */ | ||
4172 | if (wl->fwlog_size < 0) { | ||
4173 | mutex_unlock(&wl->mutex); | ||
4174 | return 0; | ||
4175 | } | ||
4176 | |||
4177 | /* Seeking is not supported - old logs are not kept. Disregard pos. */ | ||
4178 | len = min(count, (size_t)wl->fwlog_size); | ||
4179 | wl->fwlog_size -= len; | ||
4180 | memcpy(buffer, wl->fwlog, len); | ||
4181 | |||
4182 | /* Make room for new messages */ | ||
4183 | memmove(wl->fwlog, wl->fwlog + len, wl->fwlog_size); | ||
4184 | |||
4185 | mutex_unlock(&wl->mutex); | ||
4186 | |||
4187 | return len; | ||
4188 | } | ||
4189 | |||
4190 | static struct bin_attribute fwlog_attr = { | ||
4191 | .attr = {.name = "fwlog", .mode = S_IRUSR}, | ||
4192 | .read = wl1271_sysfs_read_fwlog, | ||
4193 | }; | ||
4194 | |||
4195 | int wl1271_register_hw(struct wl1271 *wl) | ||
4196 | { | ||
4197 | int ret; | ||
4198 | |||
4199 | if (wl->mac80211_registered) | ||
4200 | return 0; | ||
4201 | |||
4202 | ret = wl1271_fetch_nvs(wl); | ||
4203 | if (ret == 0) { | ||
4204 | /* NOTE: The wl->nvs->nvs element must be first, in | ||
4205 | * order to simplify the casting, we assume it is at | ||
4206 | * the beginning of the wl->nvs structure. | ||
4207 | */ | ||
4208 | u8 *nvs_ptr = (u8 *)wl->nvs; | ||
4209 | |||
4210 | wl->mac_addr[0] = nvs_ptr[11]; | ||
4211 | wl->mac_addr[1] = nvs_ptr[10]; | ||
4212 | wl->mac_addr[2] = nvs_ptr[6]; | ||
4213 | wl->mac_addr[3] = nvs_ptr[5]; | ||
4214 | wl->mac_addr[4] = nvs_ptr[4]; | ||
4215 | wl->mac_addr[5] = nvs_ptr[3]; | ||
4216 | } | ||
4217 | |||
4218 | SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr); | ||
4219 | |||
4220 | ret = ieee80211_register_hw(wl->hw); | ||
4221 | if (ret < 0) { | ||
4222 | wl1271_error("unable to register mac80211 hw: %d", ret); | ||
4223 | return ret; | ||
4224 | } | ||
4225 | |||
4226 | wl->mac80211_registered = true; | ||
4227 | |||
4228 | wl1271_debugfs_init(wl); | ||
4229 | |||
4230 | register_netdevice_notifier(&wl1271_dev_notifier); | ||
4231 | |||
4232 | wl1271_notice("loaded"); | ||
4233 | |||
4234 | return 0; | ||
4235 | } | ||
4236 | EXPORT_SYMBOL_GPL(wl1271_register_hw); | ||
4237 | |||
4238 | void wl1271_unregister_hw(struct wl1271 *wl) | ||
4239 | { | ||
4240 | if (wl->state == WL1271_STATE_PLT) | ||
4241 | __wl1271_plt_stop(wl); | ||
4242 | |||
4243 | unregister_netdevice_notifier(&wl1271_dev_notifier); | ||
4244 | ieee80211_unregister_hw(wl->hw); | ||
4245 | wl->mac80211_registered = false; | ||
4246 | |||
4247 | } | ||
4248 | EXPORT_SYMBOL_GPL(wl1271_unregister_hw); | ||
4249 | |||
4250 | int wl1271_init_ieee80211(struct wl1271 *wl) | ||
4251 | { | ||
4252 | static const u32 cipher_suites[] = { | ||
4253 | WLAN_CIPHER_SUITE_WEP40, | ||
4254 | WLAN_CIPHER_SUITE_WEP104, | ||
4255 | WLAN_CIPHER_SUITE_TKIP, | ||
4256 | WLAN_CIPHER_SUITE_CCMP, | ||
4257 | WL1271_CIPHER_SUITE_GEM, | ||
4258 | }; | ||
4259 | |||
4260 | /* The tx descriptor buffer and the TKIP space. */ | ||
4261 | wl->hw->extra_tx_headroom = WL1271_TKIP_IV_SPACE + | ||
4262 | sizeof(struct wl1271_tx_hw_descr); | ||
4263 | |||
4264 | /* unit us */ | ||
4265 | /* FIXME: find a proper value */ | ||
4266 | wl->hw->channel_change_time = 10000; | ||
4267 | wl->hw->max_listen_interval = wl->conf.conn.max_listen_interval; | ||
4268 | |||
4269 | wl->hw->flags = IEEE80211_HW_SIGNAL_DBM | | ||
4270 | IEEE80211_HW_BEACON_FILTER | | ||
4271 | IEEE80211_HW_SUPPORTS_PS | | ||
4272 | IEEE80211_HW_SUPPORTS_UAPSD | | ||
4273 | IEEE80211_HW_HAS_RATE_CONTROL | | ||
4274 | IEEE80211_HW_CONNECTION_MONITOR | | ||
4275 | IEEE80211_HW_SUPPORTS_CQM_RSSI | | ||
4276 | IEEE80211_HW_REPORTS_TX_ACK_STATUS | | ||
4277 | IEEE80211_HW_SPECTRUM_MGMT | | ||
4278 | IEEE80211_HW_AP_LINK_PS; | ||
4279 | |||
4280 | wl->hw->wiphy->cipher_suites = cipher_suites; | ||
4281 | wl->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites); | ||
4282 | |||
4283 | wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | | ||
4284 | BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP); | ||
4285 | wl->hw->wiphy->max_scan_ssids = 1; | ||
4286 | wl->hw->wiphy->max_sched_scan_ssids = 1; | ||
4287 | /* | ||
4288 | * Maximum length of elements in scanning probe request templates | ||
4289 | * should be the maximum length possible for a template, without | ||
4290 | * the IEEE80211 header of the template | ||
4291 | */ | ||
4292 | wl->hw->wiphy->max_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE - | ||
4293 | sizeof(struct ieee80211_header); | ||
4294 | |||
4295 | /* make sure all our channels fit in the scanned_ch bitmask */ | ||
4296 | BUILD_BUG_ON(ARRAY_SIZE(wl1271_channels) + | ||
4297 | ARRAY_SIZE(wl1271_channels_5ghz) > | ||
4298 | WL1271_MAX_CHANNELS); | ||
4299 | /* | ||
4300 | * We keep local copies of the band structs because we need to | ||
4301 | * modify them on a per-device basis. | ||
4302 | */ | ||
4303 | memcpy(&wl->bands[IEEE80211_BAND_2GHZ], &wl1271_band_2ghz, | ||
4304 | sizeof(wl1271_band_2ghz)); | ||
4305 | memcpy(&wl->bands[IEEE80211_BAND_5GHZ], &wl1271_band_5ghz, | ||
4306 | sizeof(wl1271_band_5ghz)); | ||
4307 | |||
4308 | wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = | ||
4309 | &wl->bands[IEEE80211_BAND_2GHZ]; | ||
4310 | wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = | ||
4311 | &wl->bands[IEEE80211_BAND_5GHZ]; | ||
4312 | |||
4313 | wl->hw->queues = 4; | ||
4314 | wl->hw->max_rates = 1; | ||
4315 | |||
4316 | wl->hw->wiphy->reg_notifier = wl1271_reg_notify; | ||
4317 | |||
4318 | SET_IEEE80211_DEV(wl->hw, wl1271_wl_to_dev(wl)); | ||
4319 | |||
4320 | wl->hw->sta_data_size = sizeof(struct wl1271_station); | ||
4321 | |||
4322 | wl->hw->max_rx_aggregation_subframes = 8; | ||
4323 | |||
4324 | return 0; | ||
4325 | } | ||
4326 | EXPORT_SYMBOL_GPL(wl1271_init_ieee80211); | ||
4327 | |||
4328 | #define WL1271_DEFAULT_CHANNEL 0 | ||
4329 | |||
4330 | struct ieee80211_hw *wl1271_alloc_hw(void) | ||
4331 | { | ||
4332 | struct ieee80211_hw *hw; | ||
4333 | struct platform_device *plat_dev = NULL; | ||
4334 | struct wl1271 *wl; | ||
4335 | int i, j, ret; | ||
4336 | unsigned int order; | ||
4337 | |||
4338 | hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops); | ||
4339 | if (!hw) { | ||
4340 | wl1271_error("could not alloc ieee80211_hw"); | ||
4341 | ret = -ENOMEM; | ||
4342 | goto err_hw_alloc; | ||
4343 | } | ||
4344 | |||
4345 | plat_dev = kmemdup(&wl1271_device, sizeof(wl1271_device), GFP_KERNEL); | ||
4346 | if (!plat_dev) { | ||
4347 | wl1271_error("could not allocate platform_device"); | ||
4348 | ret = -ENOMEM; | ||
4349 | goto err_plat_alloc; | ||
4350 | } | ||
4351 | |||
4352 | wl = hw->priv; | ||
4353 | memset(wl, 0, sizeof(*wl)); | ||
4354 | |||
4355 | INIT_LIST_HEAD(&wl->list); | ||
4356 | |||
4357 | wl->hw = hw; | ||
4358 | wl->plat_dev = plat_dev; | ||
4359 | |||
4360 | for (i = 0; i < NUM_TX_QUEUES; i++) | ||
4361 | skb_queue_head_init(&wl->tx_queue[i]); | ||
4362 | |||
4363 | for (i = 0; i < NUM_TX_QUEUES; i++) | ||
4364 | for (j = 0; j < AP_MAX_LINKS; j++) | ||
4365 | skb_queue_head_init(&wl->links[j].tx_queue[i]); | ||
4366 | |||
4367 | skb_queue_head_init(&wl->deferred_rx_queue); | ||
4368 | skb_queue_head_init(&wl->deferred_tx_queue); | ||
4369 | |||
4370 | INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work); | ||
4371 | INIT_DELAYED_WORK(&wl->pspoll_work, wl1271_pspoll_work); | ||
4372 | INIT_WORK(&wl->netstack_work, wl1271_netstack_work); | ||
4373 | INIT_WORK(&wl->tx_work, wl1271_tx_work); | ||
4374 | INIT_WORK(&wl->recovery_work, wl1271_recovery_work); | ||
4375 | INIT_DELAYED_WORK(&wl->scan_complete_work, wl1271_scan_complete_work); | ||
4376 | INIT_WORK(&wl->rx_streaming_enable_work, | ||
4377 | wl1271_rx_streaming_enable_work); | ||
4378 | INIT_WORK(&wl->rx_streaming_disable_work, | ||
4379 | wl1271_rx_streaming_disable_work); | ||
4380 | |||
4381 | wl->freezable_wq = create_freezable_workqueue("wl12xx_wq"); | ||
4382 | if (!wl->freezable_wq) { | ||
4383 | ret = -ENOMEM; | ||
4384 | goto err_hw; | ||
4385 | } | ||
4386 | |||
4387 | wl->channel = WL1271_DEFAULT_CHANNEL; | ||
4388 | wl->beacon_int = WL1271_DEFAULT_BEACON_INT; | ||
4389 | wl->default_key = 0; | ||
4390 | wl->rx_counter = 0; | ||
4391 | wl->rx_config = WL1271_DEFAULT_STA_RX_CONFIG; | ||
4392 | wl->rx_filter = WL1271_DEFAULT_STA_RX_FILTER; | ||
4393 | wl->psm_entry_retry = 0; | ||
4394 | wl->power_level = WL1271_DEFAULT_POWER_LEVEL; | ||
4395 | wl->basic_rate_set = CONF_TX_RATE_MASK_BASIC; | ||
4396 | wl->basic_rate = CONF_TX_RATE_MASK_BASIC; | ||
4397 | wl->rate_set = CONF_TX_RATE_MASK_BASIC; | ||
4398 | wl->band = IEEE80211_BAND_2GHZ; | ||
4399 | wl->vif = NULL; | ||
4400 | wl->flags = 0; | ||
4401 | wl->sg_enabled = true; | ||
4402 | wl->hw_pg_ver = -1; | ||
4403 | wl->bss_type = MAX_BSS_TYPE; | ||
4404 | wl->set_bss_type = MAX_BSS_TYPE; | ||
4405 | wl->fw_bss_type = MAX_BSS_TYPE; | ||
4406 | wl->last_tx_hlid = 0; | ||
4407 | wl->ap_ps_map = 0; | ||
4408 | wl->ap_fw_ps_map = 0; | ||
4409 | wl->quirks = 0; | ||
4410 | wl->platform_quirks = 0; | ||
4411 | wl->sched_scanning = false; | ||
4412 | wl->tx_security_seq = 0; | ||
4413 | wl->tx_security_last_seq_lsb = 0; | ||
4414 | |||
4415 | setup_timer(&wl->rx_streaming_timer, wl1271_rx_streaming_timer, | ||
4416 | (unsigned long) wl); | ||
4417 | wl->fwlog_size = 0; | ||
4418 | init_waitqueue_head(&wl->fwlog_waitq); | ||
4419 | |||
4420 | memset(wl->tx_frames_map, 0, sizeof(wl->tx_frames_map)); | ||
4421 | for (i = 0; i < ACX_TX_DESCRIPTORS; i++) | ||
4422 | wl->tx_frames[i] = NULL; | ||
4423 | |||
4424 | spin_lock_init(&wl->wl_lock); | ||
4425 | |||
4426 | wl->state = WL1271_STATE_OFF; | ||
4427 | mutex_init(&wl->mutex); | ||
4428 | |||
4429 | /* Apply default driver configuration. */ | ||
4430 | wl1271_conf_init(wl); | ||
4431 | |||
4432 | order = get_order(WL1271_AGGR_BUFFER_SIZE); | ||
4433 | wl->aggr_buf = (u8 *)__get_free_pages(GFP_KERNEL, order); | ||
4434 | if (!wl->aggr_buf) { | ||
4435 | ret = -ENOMEM; | ||
4436 | goto err_wq; | ||
4437 | } | ||
4438 | |||
4439 | wl->dummy_packet = wl12xx_alloc_dummy_packet(wl); | ||
4440 | if (!wl->dummy_packet) { | ||
4441 | ret = -ENOMEM; | ||
4442 | goto err_aggr; | ||
4443 | } | ||
4444 | |||
4445 | /* Allocate one page for the FW log */ | ||
4446 | wl->fwlog = (u8 *)get_zeroed_page(GFP_KERNEL); | ||
4447 | if (!wl->fwlog) { | ||
4448 | ret = -ENOMEM; | ||
4449 | goto err_dummy_packet; | ||
4450 | } | ||
4451 | |||
4452 | /* Register platform device */ | ||
4453 | ret = platform_device_register(wl->plat_dev); | ||
4454 | if (ret) { | ||
4455 | wl1271_error("couldn't register platform device"); | ||
4456 | goto err_fwlog; | ||
4457 | } | ||
4458 | dev_set_drvdata(&wl->plat_dev->dev, wl); | ||
4459 | |||
4460 | /* Create sysfs file to control bt coex state */ | ||
4461 | ret = device_create_file(&wl->plat_dev->dev, &dev_attr_bt_coex_state); | ||
4462 | if (ret < 0) { | ||
4463 | wl1271_error("failed to create sysfs file bt_coex_state"); | ||
4464 | goto err_platform; | ||
4465 | } | ||
4466 | |||
4467 | /* Create sysfs file to get HW PG version */ | ||
4468 | ret = device_create_file(&wl->plat_dev->dev, &dev_attr_hw_pg_ver); | ||
4469 | if (ret < 0) { | ||
4470 | wl1271_error("failed to create sysfs file hw_pg_ver"); | ||
4471 | goto err_bt_coex_state; | ||
4472 | } | ||
4473 | |||
4474 | /* Create sysfs file for the FW log */ | ||
4475 | ret = device_create_bin_file(&wl->plat_dev->dev, &fwlog_attr); | ||
4476 | if (ret < 0) { | ||
4477 | wl1271_error("failed to create sysfs file fwlog"); | ||
4478 | goto err_hw_pg_ver; | ||
4479 | } | ||
4480 | |||
4481 | return hw; | ||
4482 | |||
4483 | err_hw_pg_ver: | ||
4484 | device_remove_file(&wl->plat_dev->dev, &dev_attr_hw_pg_ver); | ||
4485 | |||
4486 | err_bt_coex_state: | ||
4487 | device_remove_file(&wl->plat_dev->dev, &dev_attr_bt_coex_state); | ||
4488 | |||
4489 | err_platform: | ||
4490 | platform_device_unregister(wl->plat_dev); | ||
4491 | |||
4492 | err_fwlog: | ||
4493 | free_page((unsigned long)wl->fwlog); | ||
4494 | |||
4495 | err_dummy_packet: | ||
4496 | dev_kfree_skb(wl->dummy_packet); | ||
4497 | |||
4498 | err_aggr: | ||
4499 | free_pages((unsigned long)wl->aggr_buf, order); | ||
4500 | |||
4501 | err_wq: | ||
4502 | destroy_workqueue(wl->freezable_wq); | ||
4503 | |||
4504 | err_hw: | ||
4505 | wl1271_debugfs_exit(wl); | ||
4506 | kfree(plat_dev); | ||
4507 | |||
4508 | err_plat_alloc: | ||
4509 | ieee80211_free_hw(hw); | ||
4510 | |||
4511 | err_hw_alloc: | ||
4512 | |||
4513 | return ERR_PTR(ret); | ||
4514 | } | ||
4515 | EXPORT_SYMBOL_GPL(wl1271_alloc_hw); | ||
4516 | |||
4517 | int wl1271_free_hw(struct wl1271 *wl) | ||
4518 | { | ||
4519 | /* Unblock any fwlog readers */ | ||
4520 | mutex_lock(&wl->mutex); | ||
4521 | wl->fwlog_size = -1; | ||
4522 | wake_up_interruptible_all(&wl->fwlog_waitq); | ||
4523 | mutex_unlock(&wl->mutex); | ||
4524 | |||
4525 | device_remove_bin_file(&wl->plat_dev->dev, &fwlog_attr); | ||
4526 | platform_device_unregister(wl->plat_dev); | ||
4527 | free_page((unsigned long)wl->fwlog); | ||
4528 | dev_kfree_skb(wl->dummy_packet); | ||
4529 | free_pages((unsigned long)wl->aggr_buf, | ||
4530 | get_order(WL1271_AGGR_BUFFER_SIZE)); | ||
4531 | kfree(wl->plat_dev); | ||
4532 | |||
4533 | wl1271_debugfs_exit(wl); | ||
4534 | |||
4535 | vfree(wl->fw); | ||
4536 | wl->fw = NULL; | ||
4537 | kfree(wl->nvs); | ||
4538 | wl->nvs = NULL; | ||
4539 | |||
4540 | kfree(wl->fw_status); | ||
4541 | kfree(wl->tx_res_if); | ||
4542 | destroy_workqueue(wl->freezable_wq); | ||
4543 | |||
4544 | ieee80211_free_hw(wl->hw); | ||
4545 | |||
4546 | return 0; | ||
4547 | } | ||
4548 | EXPORT_SYMBOL_GPL(wl1271_free_hw); | ||
4549 | |||
4550 | u32 wl12xx_debug_level = DEBUG_NONE; | ||
4551 | EXPORT_SYMBOL_GPL(wl12xx_debug_level); | ||
4552 | module_param_named(debug_level, wl12xx_debug_level, uint, S_IRUSR | S_IWUSR); | ||
4553 | MODULE_PARM_DESC(debug_level, "wl12xx debugging level"); | ||
4554 | |||
4555 | module_param_named(fwlog, fwlog_param, charp, 0); | ||
4556 | MODULE_PARM_DESC(keymap, | ||
4557 | "FW logger options: continuous, ondemand, dbgpins or disable"); | ||
4558 | |||
4559 | MODULE_LICENSE("GPL"); | ||
4560 | MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>"); | ||
4561 | MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>"); | ||
diff --git a/drivers/net/wireless/wl12xx/ps.c b/drivers/net/wireless/wl12xx/ps.c new file mode 100644 index 00000000000..3548377ab9c --- /dev/null +++ b/drivers/net/wireless/wl12xx/ps.c | |||
@@ -0,0 +1,274 @@ | |||
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 "reg.h" | ||
25 | #include "ps.h" | ||
26 | #include "io.h" | ||
27 | #include "tx.h" | ||
28 | |||
29 | #define WL1271_WAKEUP_TIMEOUT 500 | ||
30 | |||
31 | void wl1271_elp_work(struct work_struct *work) | ||
32 | { | ||
33 | struct delayed_work *dwork; | ||
34 | struct wl1271 *wl; | ||
35 | |||
36 | dwork = container_of(work, struct delayed_work, work); | ||
37 | wl = container_of(dwork, struct wl1271, elp_work); | ||
38 | |||
39 | wl1271_debug(DEBUG_PSM, "elp work"); | ||
40 | |||
41 | mutex_lock(&wl->mutex); | ||
42 | |||
43 | if (unlikely(wl->state == WL1271_STATE_OFF)) | ||
44 | goto out; | ||
45 | |||
46 | /* our work might have been already cancelled */ | ||
47 | if (unlikely(!test_bit(WL1271_FLAG_ELP_REQUESTED, &wl->flags))) | ||
48 | goto out; | ||
49 | |||
50 | if (test_bit(WL1271_FLAG_IN_ELP, &wl->flags) || | ||
51 | (!test_bit(WL1271_FLAG_PSM, &wl->flags) && | ||
52 | !test_bit(WL1271_FLAG_IDLE, &wl->flags))) | ||
53 | goto out; | ||
54 | |||
55 | wl1271_debug(DEBUG_PSM, "chip to elp"); | ||
56 | wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP); | ||
57 | set_bit(WL1271_FLAG_IN_ELP, &wl->flags); | ||
58 | |||
59 | out: | ||
60 | mutex_unlock(&wl->mutex); | ||
61 | } | ||
62 | |||
63 | #define ELP_ENTRY_DELAY 5 | ||
64 | |||
65 | /* Routines to toggle sleep mode while in ELP */ | ||
66 | void wl1271_ps_elp_sleep(struct wl1271 *wl) | ||
67 | { | ||
68 | /* we shouldn't get consecutive sleep requests */ | ||
69 | if (WARN_ON(test_and_set_bit(WL1271_FLAG_ELP_REQUESTED, &wl->flags))) | ||
70 | return; | ||
71 | |||
72 | if (!test_bit(WL1271_FLAG_PSM, &wl->flags) && | ||
73 | !test_bit(WL1271_FLAG_IDLE, &wl->flags)) | ||
74 | return; | ||
75 | |||
76 | ieee80211_queue_delayed_work(wl->hw, &wl->elp_work, | ||
77 | msecs_to_jiffies(ELP_ENTRY_DELAY)); | ||
78 | } | ||
79 | |||
80 | int wl1271_ps_elp_wakeup(struct wl1271 *wl) | ||
81 | { | ||
82 | DECLARE_COMPLETION_ONSTACK(compl); | ||
83 | unsigned long flags; | ||
84 | int ret; | ||
85 | u32 start_time = jiffies; | ||
86 | bool pending = false; | ||
87 | |||
88 | /* | ||
89 | * we might try to wake up even if we didn't go to sleep | ||
90 | * before (e.g. on boot) | ||
91 | */ | ||
92 | if (!test_and_clear_bit(WL1271_FLAG_ELP_REQUESTED, &wl->flags)) | ||
93 | return 0; | ||
94 | |||
95 | /* don't cancel_sync as it might contend for a mutex and deadlock */ | ||
96 | cancel_delayed_work(&wl->elp_work); | ||
97 | |||
98 | if (!test_bit(WL1271_FLAG_IN_ELP, &wl->flags)) | ||
99 | return 0; | ||
100 | |||
101 | wl1271_debug(DEBUG_PSM, "waking up chip from elp"); | ||
102 | |||
103 | /* | ||
104 | * The spinlock is required here to synchronize both the work and | ||
105 | * the completion variable in one entity. | ||
106 | */ | ||
107 | spin_lock_irqsave(&wl->wl_lock, flags); | ||
108 | if (test_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags)) | ||
109 | pending = true; | ||
110 | else | ||
111 | wl->elp_compl = &compl; | ||
112 | spin_unlock_irqrestore(&wl->wl_lock, flags); | ||
113 | |||
114 | wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_WAKE_UP); | ||
115 | |||
116 | if (!pending) { | ||
117 | ret = wait_for_completion_timeout( | ||
118 | &compl, msecs_to_jiffies(WL1271_WAKEUP_TIMEOUT)); | ||
119 | if (ret == 0) { | ||
120 | wl1271_error("ELP wakeup timeout!"); | ||
121 | wl12xx_queue_recovery_work(wl); | ||
122 | ret = -ETIMEDOUT; | ||
123 | goto err; | ||
124 | } else if (ret < 0) { | ||
125 | wl1271_error("ELP wakeup completion error."); | ||
126 | goto err; | ||
127 | } | ||
128 | } | ||
129 | |||
130 | clear_bit(WL1271_FLAG_IN_ELP, &wl->flags); | ||
131 | |||
132 | wl1271_debug(DEBUG_PSM, "wakeup time: %u ms", | ||
133 | jiffies_to_msecs(jiffies - start_time)); | ||
134 | goto out; | ||
135 | |||
136 | err: | ||
137 | spin_lock_irqsave(&wl->wl_lock, flags); | ||
138 | wl->elp_compl = NULL; | ||
139 | spin_unlock_irqrestore(&wl->wl_lock, flags); | ||
140 | return ret; | ||
141 | |||
142 | out: | ||
143 | return 0; | ||
144 | } | ||
145 | |||
146 | int wl1271_ps_set_mode(struct wl1271 *wl, enum wl1271_cmd_ps_mode mode, | ||
147 | u32 rates, bool send) | ||
148 | { | ||
149 | int ret; | ||
150 | |||
151 | switch (mode) { | ||
152 | case STATION_POWER_SAVE_MODE: | ||
153 | wl1271_debug(DEBUG_PSM, "entering psm"); | ||
154 | |||
155 | ret = wl1271_acx_wake_up_conditions(wl); | ||
156 | if (ret < 0) { | ||
157 | wl1271_error("couldn't set wake up conditions"); | ||
158 | return ret; | ||
159 | } | ||
160 | |||
161 | ret = wl1271_cmd_ps_mode(wl, STATION_POWER_SAVE_MODE); | ||
162 | if (ret < 0) | ||
163 | return ret; | ||
164 | |||
165 | set_bit(WL1271_FLAG_PSM, &wl->flags); | ||
166 | break; | ||
167 | case STATION_ACTIVE_MODE: | ||
168 | default: | ||
169 | wl1271_debug(DEBUG_PSM, "leaving psm"); | ||
170 | |||
171 | /* disable beacon early termination */ | ||
172 | if (wl->band == IEEE80211_BAND_2GHZ) { | ||
173 | ret = wl1271_acx_bet_enable(wl, false); | ||
174 | if (ret < 0) | ||
175 | return ret; | ||
176 | } | ||
177 | |||
178 | /* disable beacon filtering */ | ||
179 | ret = wl1271_acx_beacon_filter_opt(wl, false); | ||
180 | if (ret < 0) | ||
181 | return ret; | ||
182 | |||
183 | ret = wl1271_cmd_ps_mode(wl, STATION_ACTIVE_MODE); | ||
184 | if (ret < 0) | ||
185 | return ret; | ||
186 | |||
187 | clear_bit(WL1271_FLAG_PSM, &wl->flags); | ||
188 | break; | ||
189 | } | ||
190 | |||
191 | return ret; | ||
192 | } | ||
193 | |||
194 | static void wl1271_ps_filter_frames(struct wl1271 *wl, u8 hlid) | ||
195 | { | ||
196 | int i; | ||
197 | struct sk_buff *skb; | ||
198 | struct ieee80211_tx_info *info; | ||
199 | unsigned long flags; | ||
200 | int filtered[NUM_TX_QUEUES]; | ||
201 | |||
202 | /* filter all frames currently the low level queus for this hlid */ | ||
203 | for (i = 0; i < NUM_TX_QUEUES; i++) { | ||
204 | filtered[i] = 0; | ||
205 | while ((skb = skb_dequeue(&wl->links[hlid].tx_queue[i]))) { | ||
206 | info = IEEE80211_SKB_CB(skb); | ||
207 | info->flags |= IEEE80211_TX_STAT_TX_FILTERED; | ||
208 | info->status.rates[0].idx = -1; | ||
209 | ieee80211_tx_status_ni(wl->hw, skb); | ||
210 | filtered[i]++; | ||
211 | } | ||
212 | } | ||
213 | |||
214 | spin_lock_irqsave(&wl->wl_lock, flags); | ||
215 | for (i = 0; i < NUM_TX_QUEUES; i++) | ||
216 | wl->tx_queue_count[i] -= filtered[i]; | ||
217 | spin_unlock_irqrestore(&wl->wl_lock, flags); | ||
218 | |||
219 | wl1271_handle_tx_low_watermark(wl); | ||
220 | } | ||
221 | |||
222 | void wl1271_ps_link_start(struct wl1271 *wl, u8 hlid, bool clean_queues) | ||
223 | { | ||
224 | struct ieee80211_sta *sta; | ||
225 | |||
226 | if (test_bit(hlid, &wl->ap_ps_map)) | ||
227 | return; | ||
228 | |||
229 | wl1271_debug(DEBUG_PSM, "start mac80211 PSM on hlid %d blks %d " | ||
230 | "clean_queues %d", hlid, wl->links[hlid].allocated_blks, | ||
231 | clean_queues); | ||
232 | |||
233 | rcu_read_lock(); | ||
234 | sta = ieee80211_find_sta(wl->vif, wl->links[hlid].addr); | ||
235 | if (!sta) { | ||
236 | wl1271_error("could not find sta %pM for starting ps", | ||
237 | wl->links[hlid].addr); | ||
238 | rcu_read_unlock(); | ||
239 | return; | ||
240 | } | ||
241 | |||
242 | ieee80211_sta_ps_transition_ni(sta, true); | ||
243 | rcu_read_unlock(); | ||
244 | |||
245 | /* do we want to filter all frames from this link's queues? */ | ||
246 | if (clean_queues) | ||
247 | wl1271_ps_filter_frames(wl, hlid); | ||
248 | |||
249 | __set_bit(hlid, &wl->ap_ps_map); | ||
250 | } | ||
251 | |||
252 | void wl1271_ps_link_end(struct wl1271 *wl, u8 hlid) | ||
253 | { | ||
254 | struct ieee80211_sta *sta; | ||
255 | |||
256 | if (!test_bit(hlid, &wl->ap_ps_map)) | ||
257 | return; | ||
258 | |||
259 | wl1271_debug(DEBUG_PSM, "end mac80211 PSM on hlid %d", hlid); | ||
260 | |||
261 | __clear_bit(hlid, &wl->ap_ps_map); | ||
262 | |||
263 | rcu_read_lock(); | ||
264 | sta = ieee80211_find_sta(wl->vif, wl->links[hlid].addr); | ||
265 | if (!sta) { | ||
266 | wl1271_error("could not find sta %pM for ending ps", | ||
267 | wl->links[hlid].addr); | ||
268 | goto end; | ||
269 | } | ||
270 | |||
271 | ieee80211_sta_ps_transition_ni(sta, false); | ||
272 | end: | ||
273 | rcu_read_unlock(); | ||
274 | } | ||
diff --git a/drivers/net/wireless/wl12xx/ps.h b/drivers/net/wireless/wl12xx/ps.h new file mode 100644 index 00000000000..25eb9bc9b62 --- /dev/null +++ b/drivers/net/wireless/wl12xx/ps.h | |||
@@ -0,0 +1,40 @@ | |||
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 "wl12xx.h" | ||
28 | #include "acx.h" | ||
29 | |||
30 | int wl1271_ps_set_mode(struct wl1271 *wl, enum wl1271_cmd_ps_mode mode, | ||
31 | u32 rates, bool send); | ||
32 | void wl1271_ps_elp_sleep(struct wl1271 *wl); | ||
33 | int wl1271_ps_elp_wakeup(struct wl1271 *wl); | ||
34 | void wl1271_elp_work(struct work_struct *work); | ||
35 | void wl1271_ps_link_start(struct wl1271 *wl, u8 hlid, bool clean_queues); | ||
36 | void wl1271_ps_link_end(struct wl1271 *wl, u8 hlid); | ||
37 | |||
38 | #define WL1271_PS_COMPLETE_TIMEOUT 500 | ||
39 | |||
40 | #endif /* __WL1271_PS_H__ */ | ||
diff --git a/drivers/net/wireless/wl12xx/reg.h b/drivers/net/wireless/wl12xx/reg.h new file mode 100644 index 00000000000..440a4ee9cb4 --- /dev/null +++ b/drivers/net/wireless/wl12xx/reg.h | |||
@@ -0,0 +1,603 @@ | |||
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 HW_ACCESS_ELP_CTRL_REG_ADDR 0x1FFFC | ||
37 | #define FW_STATUS_ADDR (0x14FC0 + 0xA000) | ||
38 | |||
39 | /* ELP register commands */ | ||
40 | #define ELPCTRL_WAKE_UP 0x1 | ||
41 | #define ELPCTRL_WAKE_UP_WLAN_READY 0x5 | ||
42 | #define ELPCTRL_SLEEP 0x0 | ||
43 | /* ELP WLAN_READY bit */ | ||
44 | #define ELPCTRL_WLAN_READY 0x2 | ||
45 | |||
46 | /*=============================================== | ||
47 | Host Software Reset - 32bit RW | ||
48 | ------------------------------------------ | ||
49 | [31:1] Reserved | ||
50 | 0 SOFT_RESET Soft Reset - When this bit is set, | ||
51 | it holds the Wlan hardware in a soft reset state. | ||
52 | This reset disables all MAC and baseband processor | ||
53 | clocks except the CardBus/PCI interface clock. | ||
54 | It also initializes all MAC state machines except | ||
55 | the host interface. It does not reload the | ||
56 | contents of the EEPROM. When this bit is cleared | ||
57 | (not self-clearing), the Wlan hardware | ||
58 | exits the software reset state. | ||
59 | ===============================================*/ | ||
60 | #define ACX_REG_SLV_SOFT_RESET (REGISTERS_BASE + 0x0000) | ||
61 | |||
62 | #define WL1271_SLV_REG_DATA (REGISTERS_BASE + 0x0008) | ||
63 | #define WL1271_SLV_REG_ADATA (REGISTERS_BASE + 0x000c) | ||
64 | #define WL1271_SLV_MEM_DATA (REGISTERS_BASE + 0x0018) | ||
65 | |||
66 | #define ACX_REG_INTERRUPT_TRIG (REGISTERS_BASE + 0x0474) | ||
67 | #define ACX_REG_INTERRUPT_TRIG_H (REGISTERS_BASE + 0x0478) | ||
68 | |||
69 | /*============================================= | ||
70 | Host Interrupt Mask Register - 32bit (RW) | ||
71 | ------------------------------------------ | ||
72 | Setting a bit in this register masks the | ||
73 | corresponding interrupt to the host. | ||
74 | 0 - RX0 - Rx first dubble buffer Data Interrupt | ||
75 | 1 - TXD - Tx Data Interrupt | ||
76 | 2 - TXXFR - Tx Transfer Interrupt | ||
77 | 3 - RX1 - Rx second dubble buffer Data Interrupt | ||
78 | 4 - RXXFR - Rx Transfer Interrupt | ||
79 | 5 - EVENT_A - Event Mailbox interrupt | ||
80 | 6 - EVENT_B - Event Mailbox interrupt | ||
81 | 7 - WNONHST - Wake On Host Interrupt | ||
82 | 8 - TRACE_A - Debug Trace interrupt | ||
83 | 9 - TRACE_B - Debug Trace interrupt | ||
84 | 10 - CDCMP - Command Complete Interrupt | ||
85 | 11 - | ||
86 | 12 - | ||
87 | 13 - | ||
88 | 14 - ICOMP - Initialization Complete Interrupt | ||
89 | 16 - SG SE - Soft Gemini - Sense enable interrupt | ||
90 | 17 - SG SD - Soft Gemini - Sense disable interrupt | ||
91 | 18 - - | ||
92 | 19 - - | ||
93 | 20 - - | ||
94 | 21- - | ||
95 | Default: 0x0001 | ||
96 | *==============================================*/ | ||
97 | #define ACX_REG_INTERRUPT_MASK (REGISTERS_BASE + 0x04DC) | ||
98 | |||
99 | /*============================================= | ||
100 | Host Interrupt Mask Set 16bit, (Write only) | ||
101 | ------------------------------------------ | ||
102 | Setting a bit in this register sets | ||
103 | the corresponding bin in ACX_HINT_MASK register | ||
104 | without effecting the mask | ||
105 | state of other bits (0 = no effect). | ||
106 | ==============================================*/ | ||
107 | #define ACX_REG_HINT_MASK_SET (REGISTERS_BASE + 0x04E0) | ||
108 | |||
109 | /*============================================= | ||
110 | Host Interrupt Mask Clear 16bit,(Write only) | ||
111 | ------------------------------------------ | ||
112 | Setting a bit in this register clears | ||
113 | the corresponding bin in ACX_HINT_MASK register | ||
114 | without effecting the mask | ||
115 | state of other bits (0 = no effect). | ||
116 | =============================================*/ | ||
117 | #define ACX_REG_HINT_MASK_CLR (REGISTERS_BASE + 0x04E4) | ||
118 | |||
119 | /*============================================= | ||
120 | Host Interrupt Status Nondestructive Read | ||
121 | 16bit,(Read only) | ||
122 | ------------------------------------------ | ||
123 | The host can read this register to determine | ||
124 | which interrupts are active. | ||
125 | Reading this register doesn't | ||
126 | effect its content. | ||
127 | =============================================*/ | ||
128 | #define ACX_REG_INTERRUPT_NO_CLEAR (REGISTERS_BASE + 0x04E8) | ||
129 | |||
130 | /*============================================= | ||
131 | Host Interrupt Status Clear on Read Register | ||
132 | 16bit,(Read only) | ||
133 | ------------------------------------------ | ||
134 | The host can read this register to determine | ||
135 | which interrupts are active. | ||
136 | Reading this register clears it, | ||
137 | thus making all interrupts inactive. | ||
138 | ==============================================*/ | ||
139 | #define ACX_REG_INTERRUPT_CLEAR (REGISTERS_BASE + 0x04F8) | ||
140 | |||
141 | /*============================================= | ||
142 | Host Interrupt Acknowledge Register | ||
143 | 16bit,(Write only) | ||
144 | ------------------------------------------ | ||
145 | The host can set individual bits in this | ||
146 | register to clear (acknowledge) the corresp. | ||
147 | interrupt status bits in the HINT_STS_CLR and | ||
148 | HINT_STS_ND registers, thus making the | ||
149 | assotiated interrupt inactive. (0-no effect) | ||
150 | ==============================================*/ | ||
151 | #define ACX_REG_INTERRUPT_ACK (REGISTERS_BASE + 0x04F0) | ||
152 | |||
153 | #define RX_DRIVER_COUNTER_ADDRESS (REGISTERS_BASE + 0x0538) | ||
154 | |||
155 | /* Device Configuration registers*/ | ||
156 | #define SOR_CFG (REGISTERS_BASE + 0x0800) | ||
157 | |||
158 | /* Embedded ARM CPU Control */ | ||
159 | |||
160 | /*=============================================== | ||
161 | Halt eCPU - 32bit RW | ||
162 | ------------------------------------------ | ||
163 | 0 HALT_ECPU Halt Embedded CPU - This bit is the | ||
164 | compliment of bit 1 (MDATA2) in the SOR_CFG register. | ||
165 | During a hardware reset, this bit holds | ||
166 | the inverse of MDATA2. | ||
167 | When downloading firmware from the host, | ||
168 | set this bit (pull down MDATA2). | ||
169 | The host clears this bit after downloading the firmware into | ||
170 | zero-wait-state SSRAM. | ||
171 | When loading firmware from Flash, clear this bit (pull up MDATA2) | ||
172 | so that the eCPU can run the bootloader code in Flash | ||
173 | HALT_ECPU eCPU State | ||
174 | -------------------- | ||
175 | 1 halt eCPU | ||
176 | 0 enable eCPU | ||
177 | ===============================================*/ | ||
178 | #define ACX_REG_ECPU_CONTROL (REGISTERS_BASE + 0x0804) | ||
179 | |||
180 | #define HI_CFG (REGISTERS_BASE + 0x0808) | ||
181 | |||
182 | /*=============================================== | ||
183 | EEPROM Burst Read Start - 32bit RW | ||
184 | ------------------------------------------ | ||
185 | [31:1] Reserved | ||
186 | 0 ACX_EE_START - EEPROM Burst Read Start 0 | ||
187 | Setting this bit starts a burst read from | ||
188 | the external EEPROM. | ||
189 | If this bit is set (after reset) before an EEPROM read/write, | ||
190 | the burst read starts at EEPROM address 0. | ||
191 | Otherwise, it starts at the address | ||
192 | following the address of the previous access. | ||
193 | TheWlan hardware hardware clears this bit automatically. | ||
194 | |||
195 | Default: 0x00000000 | ||
196 | *================================================*/ | ||
197 | #define ACX_REG_EE_START (REGISTERS_BASE + 0x080C) | ||
198 | |||
199 | #define OCP_POR_CTR (REGISTERS_BASE + 0x09B4) | ||
200 | #define OCP_DATA_WRITE (REGISTERS_BASE + 0x09B8) | ||
201 | #define OCP_DATA_READ (REGISTERS_BASE + 0x09BC) | ||
202 | #define OCP_CMD (REGISTERS_BASE + 0x09C0) | ||
203 | |||
204 | #define WL1271_HOST_WR_ACCESS (REGISTERS_BASE + 0x09F8) | ||
205 | |||
206 | #define CHIP_ID_B (REGISTERS_BASE + 0x5674) | ||
207 | |||
208 | #define CHIP_ID_1271_PG10 (0x4030101) | ||
209 | #define CHIP_ID_1271_PG20 (0x4030111) | ||
210 | #define CHIP_ID_1283_PG10 (0x05030101) | ||
211 | #define CHIP_ID_1283_PG20 (0x05030111) | ||
212 | |||
213 | #define ENABLE (REGISTERS_BASE + 0x5450) | ||
214 | |||
215 | /* Power Management registers */ | ||
216 | #define ELP_CFG_MODE (REGISTERS_BASE + 0x5804) | ||
217 | #define ELP_CMD (REGISTERS_BASE + 0x5808) | ||
218 | #define PLL_CAL_TIME (REGISTERS_BASE + 0x5810) | ||
219 | #define CLK_REQ_TIME (REGISTERS_BASE + 0x5814) | ||
220 | #define CLK_BUF_TIME (REGISTERS_BASE + 0x5818) | ||
221 | |||
222 | #define CFG_PLL_SYNC_CNT (REGISTERS_BASE + 0x5820) | ||
223 | |||
224 | /* Scratch Pad registers*/ | ||
225 | #define SCR_PAD0 (REGISTERS_BASE + 0x5608) | ||
226 | #define SCR_PAD1 (REGISTERS_BASE + 0x560C) | ||
227 | #define SCR_PAD2 (REGISTERS_BASE + 0x5610) | ||
228 | #define SCR_PAD3 (REGISTERS_BASE + 0x5614) | ||
229 | #define SCR_PAD4 (REGISTERS_BASE + 0x5618) | ||
230 | #define SCR_PAD4_SET (REGISTERS_BASE + 0x561C) | ||
231 | #define SCR_PAD4_CLR (REGISTERS_BASE + 0x5620) | ||
232 | #define SCR_PAD5 (REGISTERS_BASE + 0x5624) | ||
233 | #define SCR_PAD5_SET (REGISTERS_BASE + 0x5628) | ||
234 | #define SCR_PAD5_CLR (REGISTERS_BASE + 0x562C) | ||
235 | #define SCR_PAD6 (REGISTERS_BASE + 0x5630) | ||
236 | #define SCR_PAD7 (REGISTERS_BASE + 0x5634) | ||
237 | #define SCR_PAD8 (REGISTERS_BASE + 0x5638) | ||
238 | #define SCR_PAD9 (REGISTERS_BASE + 0x563C) | ||
239 | |||
240 | /* Spare registers*/ | ||
241 | #define SPARE_A1 (REGISTERS_BASE + 0x0994) | ||
242 | #define SPARE_A2 (REGISTERS_BASE + 0x0998) | ||
243 | #define SPARE_A3 (REGISTERS_BASE + 0x099C) | ||
244 | #define SPARE_A4 (REGISTERS_BASE + 0x09A0) | ||
245 | #define SPARE_A5 (REGISTERS_BASE + 0x09A4) | ||
246 | #define SPARE_A6 (REGISTERS_BASE + 0x09A8) | ||
247 | #define SPARE_A7 (REGISTERS_BASE + 0x09AC) | ||
248 | #define SPARE_A8 (REGISTERS_BASE + 0x09B0) | ||
249 | #define SPARE_B1 (REGISTERS_BASE + 0x5420) | ||
250 | #define SPARE_B2 (REGISTERS_BASE + 0x5424) | ||
251 | #define SPARE_B3 (REGISTERS_BASE + 0x5428) | ||
252 | #define SPARE_B4 (REGISTERS_BASE + 0x542C) | ||
253 | #define SPARE_B5 (REGISTERS_BASE + 0x5430) | ||
254 | #define SPARE_B6 (REGISTERS_BASE + 0x5434) | ||
255 | #define SPARE_B7 (REGISTERS_BASE + 0x5438) | ||
256 | #define SPARE_B8 (REGISTERS_BASE + 0x543C) | ||
257 | |||
258 | #define PLL_PARAMETERS (REGISTERS_BASE + 0x6040) | ||
259 | #define WU_COUNTER_PAUSE (REGISTERS_BASE + 0x6008) | ||
260 | #define WELP_ARM_COMMAND (REGISTERS_BASE + 0x6100) | ||
261 | #define DRPW_SCRATCH_START (DRPW_BASE + 0x002C) | ||
262 | |||
263 | |||
264 | #define ACX_SLV_SOFT_RESET_BIT BIT(1) | ||
265 | #define ACX_REG_EEPROM_START_BIT BIT(1) | ||
266 | |||
267 | /* Command/Information Mailbox Pointers */ | ||
268 | |||
269 | /*=============================================== | ||
270 | Command Mailbox Pointer - 32bit RW | ||
271 | ------------------------------------------ | ||
272 | This register holds the start address of | ||
273 | the command mailbox located in the Wlan hardware memory. | ||
274 | The host must read this pointer after a reset to | ||
275 | find the location of the command mailbox. | ||
276 | The Wlan hardware initializes the command mailbox | ||
277 | pointer with the default address of the command mailbox. | ||
278 | The command mailbox pointer is not valid until after | ||
279 | the host receives the Init Complete interrupt from | ||
280 | the Wlan hardware. | ||
281 | ===============================================*/ | ||
282 | #define REG_COMMAND_MAILBOX_PTR (SCR_PAD0) | ||
283 | |||
284 | /*=============================================== | ||
285 | Information Mailbox Pointer - 32bit RW | ||
286 | ------------------------------------------ | ||
287 | This register holds the start address of | ||
288 | the information mailbox located in the Wlan hardware memory. | ||
289 | The host must read this pointer after a reset to find | ||
290 | the location of the information mailbox. | ||
291 | The Wlan hardware initializes the information mailbox pointer | ||
292 | with the default address of the information mailbox. | ||
293 | The information mailbox pointer is not valid | ||
294 | until after the host receives the Init Complete interrupt from | ||
295 | the Wlan hardware. | ||
296 | ===============================================*/ | ||
297 | #define REG_EVENT_MAILBOX_PTR (SCR_PAD1) | ||
298 | |||
299 | |||
300 | /* Misc */ | ||
301 | |||
302 | #define REG_ENABLE_TX_RX (ENABLE) | ||
303 | /* | ||
304 | * Rx configuration (filter) information element | ||
305 | * --------------------------------------------- | ||
306 | */ | ||
307 | #define REG_RX_CONFIG (RX_CFG) | ||
308 | #define REG_RX_FILTER (RX_FILTER_CFG) | ||
309 | |||
310 | |||
311 | #define RX_CFG_ENABLE_PHY_HEADER_PLCP 0x0002 | ||
312 | |||
313 | /* promiscuous - receives all valid frames */ | ||
314 | #define RX_CFG_PROMISCUOUS 0x0008 | ||
315 | |||
316 | /* receives frames from any BSSID */ | ||
317 | #define RX_CFG_BSSID 0x0020 | ||
318 | |||
319 | /* receives frames destined to any MAC address */ | ||
320 | #define RX_CFG_MAC 0x0010 | ||
321 | |||
322 | #define RX_CFG_ENABLE_ONLY_MY_DEST_MAC 0x0010 | ||
323 | #define RX_CFG_ENABLE_ANY_DEST_MAC 0x0000 | ||
324 | #define RX_CFG_ENABLE_ONLY_MY_BSSID 0x0020 | ||
325 | #define RX_CFG_ENABLE_ANY_BSSID 0x0000 | ||
326 | |||
327 | /* discards all broadcast frames */ | ||
328 | #define RX_CFG_DISABLE_BCAST 0x0200 | ||
329 | |||
330 | #define RX_CFG_ENABLE_ONLY_MY_SSID 0x0400 | ||
331 | #define RX_CFG_ENABLE_RX_CMPLT_FCS_ERROR 0x0800 | ||
332 | #define RX_CFG_COPY_RX_STATUS 0x2000 | ||
333 | #define RX_CFG_TSF 0x10000 | ||
334 | |||
335 | #define RX_CONFIG_OPTION_ANY_DST_MY_BSS (RX_CFG_ENABLE_ANY_DEST_MAC | \ | ||
336 | RX_CFG_ENABLE_ONLY_MY_BSSID) | ||
337 | |||
338 | #define RX_CONFIG_OPTION_MY_DST_ANY_BSS (RX_CFG_ENABLE_ONLY_MY_DEST_MAC\ | ||
339 | | RX_CFG_ENABLE_ANY_BSSID) | ||
340 | |||
341 | #define RX_CONFIG_OPTION_ANY_DST_ANY_BSS (RX_CFG_ENABLE_ANY_DEST_MAC | \ | ||
342 | RX_CFG_ENABLE_ANY_BSSID) | ||
343 | |||
344 | #define RX_CONFIG_OPTION_MY_DST_MY_BSS (RX_CFG_ENABLE_ONLY_MY_DEST_MAC\ | ||
345 | | RX_CFG_ENABLE_ONLY_MY_BSSID) | ||
346 | |||
347 | #define RX_CONFIG_OPTION_FOR_SCAN (RX_CFG_ENABLE_PHY_HEADER_PLCP \ | ||
348 | | RX_CFG_ENABLE_RX_CMPLT_FCS_ERROR \ | ||
349 | | RX_CFG_COPY_RX_STATUS | RX_CFG_TSF) | ||
350 | |||
351 | #define RX_CONFIG_OPTION_FOR_MEASUREMENT (RX_CFG_ENABLE_ANY_DEST_MAC) | ||
352 | |||
353 | #define RX_CONFIG_OPTION_FOR_JOIN (RX_CFG_ENABLE_ONLY_MY_BSSID | \ | ||
354 | RX_CFG_ENABLE_ONLY_MY_DEST_MAC) | ||
355 | |||
356 | #define RX_CONFIG_OPTION_FOR_IBSS_JOIN (RX_CFG_ENABLE_ONLY_MY_SSID | \ | ||
357 | RX_CFG_ENABLE_ONLY_MY_DEST_MAC) | ||
358 | |||
359 | #define RX_FILTER_OPTION_DEF (CFG_RX_MGMT_EN | CFG_RX_DATA_EN\ | ||
360 | | CFG_RX_CTL_EN | CFG_RX_BCN_EN\ | ||
361 | | CFG_RX_AUTH_EN | CFG_RX_ASSOC_EN) | ||
362 | |||
363 | #define RX_FILTER_OPTION_FILTER_ALL 0 | ||
364 | |||
365 | #define RX_FILTER_OPTION_DEF_PRSP_BCN (CFG_RX_PRSP_EN | CFG_RX_MGMT_EN\ | ||
366 | | CFG_RX_RCTS_ACK | CFG_RX_BCN_EN) | ||
367 | |||
368 | #define RX_FILTER_OPTION_JOIN (CFG_RX_MGMT_EN | CFG_RX_DATA_EN\ | ||
369 | | CFG_RX_BCN_EN | CFG_RX_AUTH_EN\ | ||
370 | | CFG_RX_ASSOC_EN | CFG_RX_RCTS_ACK\ | ||
371 | | CFG_RX_PRSP_EN) | ||
372 | |||
373 | |||
374 | /*=============================================== | ||
375 | EEPROM Read/Write Request 32bit RW | ||
376 | ------------------------------------------ | ||
377 | 1 EE_READ - EEPROM Read Request 1 - Setting this bit | ||
378 | loads a single byte of data into the EE_DATA | ||
379 | register from the EEPROM location specified in | ||
380 | the EE_ADDR register. | ||
381 | The Wlan hardware hardware clears this bit automatically. | ||
382 | EE_DATA is valid when this bit is cleared. | ||
383 | |||
384 | 0 EE_WRITE - EEPROM Write Request - Setting this bit | ||
385 | writes a single byte of data from the EE_DATA register into the | ||
386 | EEPROM location specified in the EE_ADDR register. | ||
387 | The Wlan hardware hardware clears this bit automatically. | ||
388 | *===============================================*/ | ||
389 | #define ACX_EE_CTL_REG EE_CTL | ||
390 | #define EE_WRITE 0x00000001ul | ||
391 | #define EE_READ 0x00000002ul | ||
392 | |||
393 | /*=============================================== | ||
394 | EEPROM Address - 32bit RW | ||
395 | ------------------------------------------ | ||
396 | This register specifies the address | ||
397 | within the EEPROM from/to which to read/write data. | ||
398 | ===============================================*/ | ||
399 | #define ACX_EE_ADDR_REG EE_ADDR | ||
400 | |||
401 | /*=============================================== | ||
402 | EEPROM Data - 32bit RW | ||
403 | ------------------------------------------ | ||
404 | This register either holds the read 8 bits of | ||
405 | data from the EEPROM or the write data | ||
406 | to be written to the EEPROM. | ||
407 | ===============================================*/ | ||
408 | #define ACX_EE_DATA_REG EE_DATA | ||
409 | |||
410 | /*=============================================== | ||
411 | EEPROM Base Address - 32bit RW | ||
412 | ------------------------------------------ | ||
413 | This register holds the upper nine bits | ||
414 | [23:15] of the 24-bit Wlan hardware memory | ||
415 | address for burst reads from EEPROM accesses. | ||
416 | The EEPROM provides the lower 15 bits of this address. | ||
417 | The MSB of the address from the EEPROM is ignored. | ||
418 | ===============================================*/ | ||
419 | #define ACX_EE_CFG EE_CFG | ||
420 | |||
421 | /*=============================================== | ||
422 | GPIO Output Values -32bit, RW | ||
423 | ------------------------------------------ | ||
424 | [31:16] Reserved | ||
425 | [15: 0] Specify the output values (at the output driver inputs) for | ||
426 | GPIO[15:0], respectively. | ||
427 | ===============================================*/ | ||
428 | #define ACX_GPIO_OUT_REG GPIO_OUT | ||
429 | #define ACX_MAX_GPIO_LINES 15 | ||
430 | |||
431 | /*=============================================== | ||
432 | Contention window -32bit, RW | ||
433 | ------------------------------------------ | ||
434 | [31:26] Reserved | ||
435 | [25:16] Max (0x3ff) | ||
436 | [15:07] Reserved | ||
437 | [06:00] Current contention window value - default is 0x1F | ||
438 | ===============================================*/ | ||
439 | #define ACX_CONT_WIND_CFG_REG CONT_WIND_CFG | ||
440 | #define ACX_CONT_WIND_MIN_MASK 0x0000007f | ||
441 | #define ACX_CONT_WIND_MAX 0x03ff0000 | ||
442 | |||
443 | /*=============================================== | ||
444 | HI_CFG Interface Configuration Register Values | ||
445 | ------------------------------------------ | ||
446 | ===============================================*/ | ||
447 | #define HI_CFG_UART_ENABLE 0x00000004 | ||
448 | #define HI_CFG_RST232_ENABLE 0x00000008 | ||
449 | #define HI_CFG_CLOCK_REQ_SELECT 0x00000010 | ||
450 | #define HI_CFG_HOST_INT_ENABLE 0x00000020 | ||
451 | #define HI_CFG_VLYNQ_OUTPUT_ENABLE 0x00000040 | ||
452 | #define HI_CFG_HOST_INT_ACTIVE_LOW 0x00000080 | ||
453 | #define HI_CFG_UART_TX_OUT_GPIO_15 0x00000100 | ||
454 | #define HI_CFG_UART_TX_OUT_GPIO_14 0x00000200 | ||
455 | #define HI_CFG_UART_TX_OUT_GPIO_7 0x00000400 | ||
456 | |||
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 | |||
463 | #define REF_FREQ_19_2 0 | ||
464 | #define REF_FREQ_26_0 1 | ||
465 | #define REF_FREQ_38_4 2 | ||
466 | #define REF_FREQ_40_0 3 | ||
467 | #define REF_FREQ_33_6 4 | ||
468 | #define REF_FREQ_NUM 5 | ||
469 | |||
470 | #define LUT_PARAM_INTEGER_DIVIDER 0 | ||
471 | #define LUT_PARAM_FRACTIONAL_DIVIDER 1 | ||
472 | #define LUT_PARAM_ATTN_BB 2 | ||
473 | #define LUT_PARAM_ALPHA_BB 3 | ||
474 | #define LUT_PARAM_STOP_TIME_BB 4 | ||
475 | #define LUT_PARAM_BB_PLL_LOOP_FILTER 5 | ||
476 | #define LUT_PARAM_NUM 6 | ||
477 | |||
478 | #define ACX_EEPROMLESS_IND_REG (SCR_PAD4) | ||
479 | #define USE_EEPROM 0 | ||
480 | #define SOFT_RESET_MAX_TIME 1000000 | ||
481 | #define SOFT_RESET_STALL_TIME 1000 | ||
482 | #define NVS_DATA_BUNDARY_ALIGNMENT 4 | ||
483 | |||
484 | |||
485 | /* Firmware image load chunk size */ | ||
486 | #define CHUNK_SIZE 512 | ||
487 | |||
488 | /* Firmware image header size */ | ||
489 | #define FW_HDR_SIZE 8 | ||
490 | |||
491 | #define ECPU_CONTROL_HALT 0x00000101 | ||
492 | |||
493 | |||
494 | /****************************************************************************** | ||
495 | |||
496 | CHANNELS, BAND & REG DOMAINS definitions | ||
497 | |||
498 | ******************************************************************************/ | ||
499 | |||
500 | |||
501 | enum { | ||
502 | RADIO_BAND_2_4GHZ = 0, /* 2.4 Ghz band */ | ||
503 | RADIO_BAND_5GHZ = 1, /* 5 Ghz band */ | ||
504 | RADIO_BAND_JAPAN_4_9_GHZ = 2, | ||
505 | DEFAULT_BAND = RADIO_BAND_2_4GHZ, | ||
506 | INVALID_BAND = 0xFE, | ||
507 | MAX_RADIO_BANDS = 0xFF | ||
508 | }; | ||
509 | |||
510 | #define SHORT_PREAMBLE_BIT BIT(0) /* CCK or Barker depending on the rate */ | ||
511 | #define OFDM_RATE_BIT BIT(6) | ||
512 | #define PBCC_RATE_BIT BIT(7) | ||
513 | |||
514 | enum { | ||
515 | CCK_LONG = 0, | ||
516 | CCK_SHORT = SHORT_PREAMBLE_BIT, | ||
517 | PBCC_LONG = PBCC_RATE_BIT, | ||
518 | PBCC_SHORT = PBCC_RATE_BIT | SHORT_PREAMBLE_BIT, | ||
519 | OFDM = OFDM_RATE_BIT | ||
520 | }; | ||
521 | |||
522 | /****************************************************************************** | ||
523 | |||
524 | Transmit-Descriptor RATE-SET field definitions... | ||
525 | |||
526 | Define a new "Rate-Set" for TX path that incorporates the | ||
527 | Rate & Modulation info into a single 16-bit field. | ||
528 | |||
529 | TxdRateSet_t: | ||
530 | b15 - Indicates Preamble type (1=SHORT, 0=LONG). | ||
531 | Notes: | ||
532 | Must be LONG (0) for 1Mbps rate. | ||
533 | Does not apply (set to 0) for RevG-OFDM rates. | ||
534 | b14 - Indicates PBCC encoding (1=PBCC, 0=not). | ||
535 | Notes: | ||
536 | Does not apply (set to 0) for rates 1 and 2 Mbps. | ||
537 | Does not apply (set to 0) for RevG-OFDM rates. | ||
538 | b13 - Unused (set to 0). | ||
539 | b12-b0 - Supported Rate indicator bits as defined below. | ||
540 | |||
541 | ******************************************************************************/ | ||
542 | |||
543 | |||
544 | /************************************************************************* | ||
545 | |||
546 | Interrupt Trigger Register (Host -> WiLink) | ||
547 | |||
548 | **************************************************************************/ | ||
549 | |||
550 | /* Hardware to Embedded CPU Interrupts - first 32-bit register set */ | ||
551 | |||
552 | /* | ||
553 | * Host Command Interrupt. Setting this bit masks | ||
554 | * the interrupt that the host issues to inform | ||
555 | * the FW that it has sent a command | ||
556 | * to the Wlan hardware Command Mailbox. | ||
557 | */ | ||
558 | #define INTR_TRIG_CMD BIT(0) | ||
559 | |||
560 | /* | ||
561 | * Host Event Acknowlegde Interrupt. The host | ||
562 | * sets this bit to acknowledge that it received | ||
563 | * the unsolicited information from the event | ||
564 | * mailbox. | ||
565 | */ | ||
566 | #define INTR_TRIG_EVENT_ACK BIT(1) | ||
567 | |||
568 | /* | ||
569 | * The host sets this bit to inform the Wlan | ||
570 | * FW that a TX packet is in the XFER | ||
571 | * Buffer #0. | ||
572 | */ | ||
573 | #define INTR_TRIG_TX_PROC0 BIT(2) | ||
574 | |||
575 | /* | ||
576 | * The host sets this bit to inform the FW | ||
577 | * that it read a packet from RX XFER | ||
578 | * Buffer #0. | ||
579 | */ | ||
580 | #define INTR_TRIG_RX_PROC0 BIT(3) | ||
581 | |||
582 | #define INTR_TRIG_DEBUG_ACK BIT(4) | ||
583 | |||
584 | #define INTR_TRIG_STATE_CHANGED BIT(5) | ||
585 | |||
586 | |||
587 | /* Hardware to Embedded CPU Interrupts - second 32-bit register set */ | ||
588 | |||
589 | /* | ||
590 | * The host sets this bit to inform the FW | ||
591 | * that it read a packet from RX XFER | ||
592 | * Buffer #1. | ||
593 | */ | ||
594 | #define INTR_TRIG_RX_PROC1 BIT(17) | ||
595 | |||
596 | /* | ||
597 | * The host sets this bit to inform the Wlan | ||
598 | * hardware that a TX packet is in the XFER | ||
599 | * Buffer #1. | ||
600 | */ | ||
601 | #define INTR_TRIG_TX_PROC1 BIT(18) | ||
602 | |||
603 | #endif | ||
diff --git a/drivers/net/wireless/wl12xx/rx.c b/drivers/net/wireless/wl12xx/rx.c new file mode 100644 index 00000000000..0450fb49dbb --- /dev/null +++ b/drivers/net/wireless/wl12xx/rx.c | |||
@@ -0,0 +1,273 @@ | |||
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 "wl12xx.h" | ||
28 | #include "acx.h" | ||
29 | #include "reg.h" | ||
30 | #include "rx.h" | ||
31 | #include "io.h" | ||
32 | |||
33 | static u8 wl1271_rx_get_mem_block(struct wl1271_fw_common_status *status, | ||
34 | u32 drv_rx_counter) | ||
35 | { | ||
36 | return le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]) & | ||
37 | RX_MEM_BLOCK_MASK; | ||
38 | } | ||
39 | |||
40 | static u32 wl1271_rx_get_buf_size(struct wl1271_fw_common_status *status, | ||
41 | u32 drv_rx_counter) | ||
42 | { | ||
43 | return (le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]) & | ||
44 | RX_BUF_SIZE_MASK) >> RX_BUF_SIZE_SHIFT_DIV; | ||
45 | } | ||
46 | |||
47 | static void wl1271_rx_status(struct wl1271 *wl, | ||
48 | struct wl1271_rx_descriptor *desc, | ||
49 | struct ieee80211_rx_status *status, | ||
50 | u8 beacon) | ||
51 | { | ||
52 | memset(status, 0, sizeof(struct ieee80211_rx_status)); | ||
53 | |||
54 | if ((desc->flags & WL1271_RX_DESC_BAND_MASK) == WL1271_RX_DESC_BAND_BG) | ||
55 | status->band = IEEE80211_BAND_2GHZ; | ||
56 | else | ||
57 | status->band = IEEE80211_BAND_5GHZ; | ||
58 | |||
59 | status->rate_idx = wl1271_rate_to_idx(desc->rate, status->band); | ||
60 | |||
61 | #ifdef CONFIG_WL12XX_HT | ||
62 | /* 11n support */ | ||
63 | if (desc->rate <= CONF_HW_RXTX_RATE_MCS0) | ||
64 | status->flag |= RX_FLAG_HT; | ||
65 | #endif | ||
66 | |||
67 | status->signal = desc->rssi; | ||
68 | |||
69 | /* | ||
70 | * FIXME: In wl1251, the SNR should be divided by two. In wl1271 we | ||
71 | * need to divide by two for now, but TI has been discussing about | ||
72 | * changing it. This needs to be rechecked. | ||
73 | */ | ||
74 | wl->noise = desc->rssi - (desc->snr >> 1); | ||
75 | |||
76 | status->freq = ieee80211_channel_to_frequency(desc->channel, | ||
77 | status->band); | ||
78 | |||
79 | if (desc->flags & WL1271_RX_DESC_ENCRYPT_MASK) { | ||
80 | u8 desc_err_code = desc->status & WL1271_RX_DESC_STATUS_MASK; | ||
81 | |||
82 | status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED | | ||
83 | RX_FLAG_DECRYPTED; | ||
84 | |||
85 | if (unlikely(desc_err_code == WL1271_RX_DESC_MIC_FAIL)) { | ||
86 | status->flag |= RX_FLAG_MMIC_ERROR; | ||
87 | wl1271_warning("Michael MIC error"); | ||
88 | } | ||
89 | } | ||
90 | } | ||
91 | |||
92 | static int wl1271_rx_handle_data(struct wl1271 *wl, u8 *data, u32 length) | ||
93 | { | ||
94 | struct wl1271_rx_descriptor *desc; | ||
95 | struct sk_buff *skb; | ||
96 | struct ieee80211_hdr *hdr; | ||
97 | u8 *buf; | ||
98 | u8 beacon = 0; | ||
99 | u8 is_data = 0; | ||
100 | |||
101 | /* | ||
102 | * In PLT mode we seem to get frames and mac80211 warns about them, | ||
103 | * workaround this by not retrieving them at all. | ||
104 | */ | ||
105 | if (unlikely(wl->state == WL1271_STATE_PLT)) | ||
106 | return -EINVAL; | ||
107 | |||
108 | /* the data read starts with the descriptor */ | ||
109 | desc = (struct wl1271_rx_descriptor *) data; | ||
110 | |||
111 | if (desc->packet_class == WL12XX_RX_CLASS_LOGGER) { | ||
112 | size_t len = length - sizeof(*desc); | ||
113 | wl12xx_copy_fwlog(wl, data + sizeof(*desc), len); | ||
114 | wake_up_interruptible(&wl->fwlog_waitq); | ||
115 | return 0; | ||
116 | } | ||
117 | |||
118 | switch (desc->status & WL1271_RX_DESC_STATUS_MASK) { | ||
119 | /* discard corrupted packets */ | ||
120 | case WL1271_RX_DESC_DRIVER_RX_Q_FAIL: | ||
121 | case WL1271_RX_DESC_DECRYPT_FAIL: | ||
122 | wl1271_warning("corrupted packet in RX with status: 0x%x", | ||
123 | desc->status & WL1271_RX_DESC_STATUS_MASK); | ||
124 | return -EINVAL; | ||
125 | case WL1271_RX_DESC_SUCCESS: | ||
126 | case WL1271_RX_DESC_MIC_FAIL: | ||
127 | break; | ||
128 | default: | ||
129 | wl1271_error("invalid RX descriptor status: 0x%x", | ||
130 | desc->status & WL1271_RX_DESC_STATUS_MASK); | ||
131 | return -EINVAL; | ||
132 | } | ||
133 | |||
134 | skb = __dev_alloc_skb(length, GFP_KERNEL); | ||
135 | if (!skb) { | ||
136 | wl1271_error("Couldn't allocate RX frame"); | ||
137 | return -ENOMEM; | ||
138 | } | ||
139 | |||
140 | buf = skb_put(skb, length); | ||
141 | memcpy(buf, data, length); | ||
142 | |||
143 | /* now we pull the descriptor out of the buffer */ | ||
144 | skb_pull(skb, sizeof(*desc)); | ||
145 | |||
146 | hdr = (struct ieee80211_hdr *)skb->data; | ||
147 | if (ieee80211_is_beacon(hdr->frame_control)) | ||
148 | beacon = 1; | ||
149 | if (ieee80211_is_data_present(hdr->frame_control)) | ||
150 | is_data = 1; | ||
151 | |||
152 | wl1271_rx_status(wl, desc, IEEE80211_SKB_RXCB(skb), beacon); | ||
153 | |||
154 | wl1271_debug(DEBUG_RX, "rx skb 0x%p: %d B %s", skb, | ||
155 | skb->len - desc->pad_len, | ||
156 | beacon ? "beacon" : ""); | ||
157 | |||
158 | skb_trim(skb, skb->len - desc->pad_len); | ||
159 | |||
160 | skb_queue_tail(&wl->deferred_rx_queue, skb); | ||
161 | queue_work(wl->freezable_wq, &wl->netstack_work); | ||
162 | |||
163 | return is_data; | ||
164 | } | ||
165 | |||
166 | void wl1271_rx(struct wl1271 *wl, struct wl1271_fw_common_status *status) | ||
167 | { | ||
168 | struct wl1271_acx_mem_map *wl_mem_map = wl->target_mem_map; | ||
169 | u32 buf_size; | ||
170 | u32 fw_rx_counter = status->fw_rx_counter & NUM_RX_PKT_DESC_MOD_MASK; | ||
171 | u32 drv_rx_counter = wl->rx_counter & NUM_RX_PKT_DESC_MOD_MASK; | ||
172 | u32 rx_counter; | ||
173 | u32 mem_block; | ||
174 | u32 pkt_length; | ||
175 | u32 pkt_offset; | ||
176 | bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS); | ||
177 | bool had_data = false; | ||
178 | |||
179 | while (drv_rx_counter != fw_rx_counter) { | ||
180 | buf_size = 0; | ||
181 | rx_counter = drv_rx_counter; | ||
182 | while (rx_counter != fw_rx_counter) { | ||
183 | pkt_length = wl1271_rx_get_buf_size(status, rx_counter); | ||
184 | if (buf_size + pkt_length > WL1271_AGGR_BUFFER_SIZE) | ||
185 | break; | ||
186 | buf_size += pkt_length; | ||
187 | rx_counter++; | ||
188 | rx_counter &= NUM_RX_PKT_DESC_MOD_MASK; | ||
189 | } | ||
190 | |||
191 | if (buf_size == 0) { | ||
192 | wl1271_warning("received empty data"); | ||
193 | break; | ||
194 | } | ||
195 | |||
196 | if (wl->chip.id != CHIP_ID_1283_PG20) { | ||
197 | /* | ||
198 | * Choose the block we want to read | ||
199 | * For aggregated packets, only the first memory block | ||
200 | * should be retrieved. The FW takes care of the rest. | ||
201 | */ | ||
202 | mem_block = wl1271_rx_get_mem_block(status, | ||
203 | drv_rx_counter); | ||
204 | |||
205 | wl->rx_mem_pool_addr.addr = (mem_block << 8) + | ||
206 | le32_to_cpu(wl_mem_map->packet_memory_pool_start); | ||
207 | |||
208 | wl->rx_mem_pool_addr.addr_extra = | ||
209 | wl->rx_mem_pool_addr.addr + 4; | ||
210 | |||
211 | wl1271_write(wl, WL1271_SLV_REG_DATA, | ||
212 | &wl->rx_mem_pool_addr, | ||
213 | sizeof(wl->rx_mem_pool_addr), false); | ||
214 | } | ||
215 | |||
216 | /* Read all available packets at once */ | ||
217 | wl1271_read(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf, | ||
218 | buf_size, true); | ||
219 | |||
220 | /* Split data into separate packets */ | ||
221 | pkt_offset = 0; | ||
222 | while (pkt_offset < buf_size) { | ||
223 | pkt_length = wl1271_rx_get_buf_size(status, | ||
224 | drv_rx_counter); | ||
225 | /* | ||
226 | * the handle data call can only fail in memory-outage | ||
227 | * conditions, in that case the received frame will just | ||
228 | * be dropped. | ||
229 | */ | ||
230 | if (wl1271_rx_handle_data(wl, | ||
231 | wl->aggr_buf + pkt_offset, | ||
232 | pkt_length) == 1) | ||
233 | had_data = true; | ||
234 | |||
235 | wl->rx_counter++; | ||
236 | drv_rx_counter++; | ||
237 | drv_rx_counter &= NUM_RX_PKT_DESC_MOD_MASK; | ||
238 | pkt_offset += pkt_length; | ||
239 | } | ||
240 | } | ||
241 | |||
242 | /* | ||
243 | * Write the driver's packet counter to the FW. This is only required | ||
244 | * for older hardware revisions | ||
245 | */ | ||
246 | if (wl->quirks & WL12XX_QUIRK_END_OF_TRANSACTION) | ||
247 | wl1271_write32(wl, RX_DRIVER_COUNTER_ADDRESS, wl->rx_counter); | ||
248 | |||
249 | if (!is_ap && wl->conf.rx_streaming.interval && had_data && | ||
250 | (wl->conf.rx_streaming.always || | ||
251 | test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))) { | ||
252 | u32 timeout = wl->conf.rx_streaming.duration; | ||
253 | |||
254 | /* restart rx streaming */ | ||
255 | if (!test_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags)) | ||
256 | ieee80211_queue_work(wl->hw, | ||
257 | &wl->rx_streaming_enable_work); | ||
258 | |||
259 | mod_timer(&wl->rx_streaming_timer, | ||
260 | jiffies + msecs_to_jiffies(timeout)); | ||
261 | } | ||
262 | } | ||
263 | |||
264 | void wl1271_set_default_filters(struct wl1271 *wl) | ||
265 | { | ||
266 | if (wl->bss_type == BSS_TYPE_AP_BSS) { | ||
267 | wl->rx_config = WL1271_DEFAULT_AP_RX_CONFIG; | ||
268 | wl->rx_filter = WL1271_DEFAULT_AP_RX_FILTER; | ||
269 | } else { | ||
270 | wl->rx_config = WL1271_DEFAULT_STA_RX_CONFIG; | ||
271 | wl->rx_filter = WL1271_DEFAULT_STA_RX_FILTER; | ||
272 | } | ||
273 | } | ||
diff --git a/drivers/net/wireless/wl12xx/rx.h b/drivers/net/wireless/wl12xx/rx.h new file mode 100644 index 00000000000..c88e3fa1d60 --- /dev/null +++ b/drivers/net/wireless/wl12xx/rx.h | |||
@@ -0,0 +1,134 @@ | |||
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 0x07 | ||
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 | |||
100 | enum { | ||
101 | WL12XX_RX_CLASS_UNKNOWN, | ||
102 | WL12XX_RX_CLASS_MANAGEMENT, | ||
103 | WL12XX_RX_CLASS_DATA, | ||
104 | WL12XX_RX_CLASS_QOS_DATA, | ||
105 | WL12XX_RX_CLASS_BCN_PRBRSP, | ||
106 | WL12XX_RX_CLASS_EAPOL, | ||
107 | WL12XX_RX_CLASS_BA_EVENT, | ||
108 | WL12XX_RX_CLASS_AMSDU, | ||
109 | WL12XX_RX_CLASS_LOGGER, | ||
110 | }; | ||
111 | |||
112 | struct wl1271_rx_descriptor { | ||
113 | __le16 length; | ||
114 | u8 status; | ||
115 | u8 flags; | ||
116 | u8 rate; | ||
117 | u8 channel; | ||
118 | s8 rssi; | ||
119 | u8 snr; | ||
120 | __le32 timestamp; | ||
121 | u8 packet_class; | ||
122 | union { | ||
123 | u8 process_id; /* STA FW */ | ||
124 | u8 hlid; /* AP FW */ | ||
125 | } __packed; | ||
126 | u8 pad_len; | ||
127 | u8 reserved; | ||
128 | } __packed; | ||
129 | |||
130 | void wl1271_rx(struct wl1271 *wl, struct wl1271_fw_common_status *status); | ||
131 | u8 wl1271_rate_to_idx(int rate, enum ieee80211_band band); | ||
132 | void wl1271_set_default_filters(struct wl1271 *wl); | ||
133 | |||
134 | #endif | ||
diff --git a/drivers/net/wireless/wl12xx/scan.c b/drivers/net/wireless/wl12xx/scan.c new file mode 100644 index 00000000000..afb7356bd48 --- /dev/null +++ b/drivers/net/wireless/wl12xx/scan.c | |||
@@ -0,0 +1,613 @@ | |||
1 | /* | ||
2 | * This file is part of wl1271 | ||
3 | * | ||
4 | * Copyright (C) 2009-2010 Nokia Corporation | ||
5 | * | ||
6 | * Contact: Luciano Coelho <luciano.coelho@nokia.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU General Public License | ||
10 | * version 2 as published by the Free Software Foundation. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, but | ||
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
20 | * 02110-1301 USA | ||
21 | * | ||
22 | */ | ||
23 | |||
24 | #include <linux/ieee80211.h> | ||
25 | |||
26 | #include "wl12xx.h" | ||
27 | #include "cmd.h" | ||
28 | #include "scan.h" | ||
29 | #include "acx.h" | ||
30 | #include "ps.h" | ||
31 | |||
32 | void wl1271_scan_complete_work(struct work_struct *work) | ||
33 | { | ||
34 | struct delayed_work *dwork; | ||
35 | struct wl1271 *wl; | ||
36 | |||
37 | dwork = container_of(work, struct delayed_work, work); | ||
38 | wl = container_of(dwork, struct wl1271, scan_complete_work); | ||
39 | |||
40 | wl1271_debug(DEBUG_SCAN, "Scanning complete"); | ||
41 | |||
42 | mutex_lock(&wl->mutex); | ||
43 | |||
44 | if (wl->state == WL1271_STATE_OFF) | ||
45 | goto out; | ||
46 | |||
47 | if (wl->scan.state == WL1271_SCAN_STATE_IDLE) | ||
48 | goto out; | ||
49 | |||
50 | wl->scan.state = WL1271_SCAN_STATE_IDLE; | ||
51 | memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch)); | ||
52 | wl->scan.req = NULL; | ||
53 | ieee80211_scan_completed(wl->hw, false); | ||
54 | |||
55 | /* restore hardware connection monitoring template */ | ||
56 | if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) { | ||
57 | if (wl1271_ps_elp_wakeup(wl) == 0) { | ||
58 | wl1271_cmd_build_ap_probe_req(wl, wl->probereq); | ||
59 | wl1271_ps_elp_sleep(wl); | ||
60 | } | ||
61 | } | ||
62 | |||
63 | if (wl->scan.failed) { | ||
64 | wl1271_info("Scan completed due to error."); | ||
65 | wl12xx_queue_recovery_work(wl); | ||
66 | } | ||
67 | |||
68 | out: | ||
69 | mutex_unlock(&wl->mutex); | ||
70 | |||
71 | } | ||
72 | |||
73 | |||
74 | static int wl1271_get_scan_channels(struct wl1271 *wl, | ||
75 | struct cfg80211_scan_request *req, | ||
76 | struct basic_scan_channel_params *channels, | ||
77 | enum ieee80211_band band, bool passive) | ||
78 | { | ||
79 | struct conf_scan_settings *c = &wl->conf.scan; | ||
80 | int i, j; | ||
81 | u32 flags; | ||
82 | |||
83 | for (i = 0, j = 0; | ||
84 | i < req->n_channels && j < WL1271_SCAN_MAX_CHANNELS; | ||
85 | i++) { | ||
86 | flags = req->channels[i]->flags; | ||
87 | |||
88 | if (!test_bit(i, wl->scan.scanned_ch) && | ||
89 | !(flags & IEEE80211_CHAN_DISABLED) && | ||
90 | (req->channels[i]->band == band) && | ||
91 | /* | ||
92 | * In passive scans, we scan all remaining | ||
93 | * channels, even if not marked as such. | ||
94 | * In active scans, we only scan channels not | ||
95 | * marked as passive. | ||
96 | */ | ||
97 | (passive || !(flags & IEEE80211_CHAN_PASSIVE_SCAN))) { | ||
98 | wl1271_debug(DEBUG_SCAN, "band %d, center_freq %d ", | ||
99 | req->channels[i]->band, | ||
100 | req->channels[i]->center_freq); | ||
101 | wl1271_debug(DEBUG_SCAN, "hw_value %d, flags %X", | ||
102 | req->channels[i]->hw_value, | ||
103 | req->channels[i]->flags); | ||
104 | wl1271_debug(DEBUG_SCAN, | ||
105 | "max_antenna_gain %d, max_power %d", | ||
106 | req->channels[i]->max_antenna_gain, | ||
107 | req->channels[i]->max_power); | ||
108 | wl1271_debug(DEBUG_SCAN, "beacon_found %d", | ||
109 | req->channels[i]->beacon_found); | ||
110 | |||
111 | if (!passive) { | ||
112 | channels[j].min_duration = | ||
113 | cpu_to_le32(c->min_dwell_time_active); | ||
114 | channels[j].max_duration = | ||
115 | cpu_to_le32(c->max_dwell_time_active); | ||
116 | } else { | ||
117 | channels[j].min_duration = | ||
118 | cpu_to_le32(c->min_dwell_time_passive); | ||
119 | channels[j].max_duration = | ||
120 | cpu_to_le32(c->max_dwell_time_passive); | ||
121 | } | ||
122 | channels[j].early_termination = 0; | ||
123 | channels[j].tx_power_att = req->channels[i]->max_power; | ||
124 | channels[j].channel = req->channels[i]->hw_value; | ||
125 | |||
126 | memset(&channels[j].bssid_lsb, 0xff, 4); | ||
127 | memset(&channels[j].bssid_msb, 0xff, 2); | ||
128 | |||
129 | /* Mark the channels we already used */ | ||
130 | set_bit(i, wl->scan.scanned_ch); | ||
131 | |||
132 | j++; | ||
133 | } | ||
134 | } | ||
135 | |||
136 | return j; | ||
137 | } | ||
138 | |||
139 | #define WL1271_NOTHING_TO_SCAN 1 | ||
140 | |||
141 | static int wl1271_scan_send(struct wl1271 *wl, enum ieee80211_band band, | ||
142 | bool passive, u32 basic_rate) | ||
143 | { | ||
144 | struct wl1271_cmd_scan *cmd; | ||
145 | struct wl1271_cmd_trigger_scan_to *trigger; | ||
146 | int ret; | ||
147 | u16 scan_options = 0; | ||
148 | |||
149 | /* skip active scans if we don't have SSIDs */ | ||
150 | if (!passive && wl->scan.req->n_ssids == 0) | ||
151 | return WL1271_NOTHING_TO_SCAN; | ||
152 | |||
153 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | ||
154 | trigger = kzalloc(sizeof(*trigger), GFP_KERNEL); | ||
155 | if (!cmd || !trigger) { | ||
156 | ret = -ENOMEM; | ||
157 | goto out; | ||
158 | } | ||
159 | |||
160 | /* We always use high priority scans */ | ||
161 | scan_options = WL1271_SCAN_OPT_PRIORITY_HIGH; | ||
162 | |||
163 | if (passive) | ||
164 | scan_options |= WL1271_SCAN_OPT_PASSIVE; | ||
165 | |||
166 | cmd->params.scan_options = cpu_to_le16(scan_options); | ||
167 | |||
168 | cmd->params.n_ch = wl1271_get_scan_channels(wl, wl->scan.req, | ||
169 | cmd->channels, | ||
170 | band, passive); | ||
171 | if (cmd->params.n_ch == 0) { | ||
172 | ret = WL1271_NOTHING_TO_SCAN; | ||
173 | goto out; | ||
174 | } | ||
175 | |||
176 | cmd->params.tx_rate = cpu_to_le32(basic_rate); | ||
177 | cmd->params.rx_config_options = cpu_to_le32(CFG_RX_ALL_GOOD); | ||
178 | cmd->params.rx_filter_options = | ||
179 | cpu_to_le32(CFG_RX_PRSP_EN | CFG_RX_MGMT_EN | CFG_RX_BCN_EN); | ||
180 | |||
181 | cmd->params.n_probe_reqs = wl->conf.scan.num_probe_reqs; | ||
182 | cmd->params.tx_rate = cpu_to_le32(basic_rate); | ||
183 | cmd->params.tid_trigger = 0; | ||
184 | cmd->params.scan_tag = WL1271_SCAN_DEFAULT_TAG; | ||
185 | |||
186 | if (band == IEEE80211_BAND_2GHZ) | ||
187 | cmd->params.band = WL1271_SCAN_BAND_2_4_GHZ; | ||
188 | else | ||
189 | cmd->params.band = WL1271_SCAN_BAND_5_GHZ; | ||
190 | |||
191 | if (wl->scan.ssid_len && wl->scan.ssid) { | ||
192 | cmd->params.ssid_len = wl->scan.ssid_len; | ||
193 | memcpy(cmd->params.ssid, wl->scan.ssid, wl->scan.ssid_len); | ||
194 | } | ||
195 | |||
196 | ret = wl1271_cmd_build_probe_req(wl, wl->scan.ssid, wl->scan.ssid_len, | ||
197 | wl->scan.req->ie, wl->scan.req->ie_len, | ||
198 | band); | ||
199 | if (ret < 0) { | ||
200 | wl1271_error("PROBE request template failed"); | ||
201 | goto out; | ||
202 | } | ||
203 | |||
204 | /* disable the timeout */ | ||
205 | trigger->timeout = 0; | ||
206 | ret = wl1271_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger, | ||
207 | sizeof(*trigger), 0); | ||
208 | if (ret < 0) { | ||
209 | wl1271_error("trigger scan to failed for hw scan"); | ||
210 | goto out; | ||
211 | } | ||
212 | |||
213 | wl1271_dump(DEBUG_SCAN, "SCAN: ", cmd, sizeof(*cmd)); | ||
214 | |||
215 | ret = wl1271_cmd_send(wl, CMD_SCAN, cmd, sizeof(*cmd), 0); | ||
216 | if (ret < 0) { | ||
217 | wl1271_error("SCAN failed"); | ||
218 | goto out; | ||
219 | } | ||
220 | |||
221 | out: | ||
222 | kfree(cmd); | ||
223 | kfree(trigger); | ||
224 | return ret; | ||
225 | } | ||
226 | |||
227 | void wl1271_scan_stm(struct wl1271 *wl) | ||
228 | { | ||
229 | int ret = 0; | ||
230 | |||
231 | switch (wl->scan.state) { | ||
232 | case WL1271_SCAN_STATE_IDLE: | ||
233 | break; | ||
234 | |||
235 | case WL1271_SCAN_STATE_2GHZ_ACTIVE: | ||
236 | ret = wl1271_scan_send(wl, IEEE80211_BAND_2GHZ, false, | ||
237 | wl->conf.tx.basic_rate); | ||
238 | if (ret == WL1271_NOTHING_TO_SCAN) { | ||
239 | wl->scan.state = WL1271_SCAN_STATE_2GHZ_PASSIVE; | ||
240 | wl1271_scan_stm(wl); | ||
241 | } | ||
242 | |||
243 | break; | ||
244 | |||
245 | case WL1271_SCAN_STATE_2GHZ_PASSIVE: | ||
246 | ret = wl1271_scan_send(wl, IEEE80211_BAND_2GHZ, true, | ||
247 | wl->conf.tx.basic_rate); | ||
248 | if (ret == WL1271_NOTHING_TO_SCAN) { | ||
249 | if (wl->enable_11a) | ||
250 | wl->scan.state = WL1271_SCAN_STATE_5GHZ_ACTIVE; | ||
251 | else | ||
252 | wl->scan.state = WL1271_SCAN_STATE_DONE; | ||
253 | wl1271_scan_stm(wl); | ||
254 | } | ||
255 | |||
256 | break; | ||
257 | |||
258 | case WL1271_SCAN_STATE_5GHZ_ACTIVE: | ||
259 | ret = wl1271_scan_send(wl, IEEE80211_BAND_5GHZ, false, | ||
260 | wl->conf.tx.basic_rate_5); | ||
261 | if (ret == WL1271_NOTHING_TO_SCAN) { | ||
262 | wl->scan.state = WL1271_SCAN_STATE_5GHZ_PASSIVE; | ||
263 | wl1271_scan_stm(wl); | ||
264 | } | ||
265 | |||
266 | break; | ||
267 | |||
268 | case WL1271_SCAN_STATE_5GHZ_PASSIVE: | ||
269 | ret = wl1271_scan_send(wl, IEEE80211_BAND_5GHZ, true, | ||
270 | wl->conf.tx.basic_rate_5); | ||
271 | if (ret == WL1271_NOTHING_TO_SCAN) { | ||
272 | wl->scan.state = WL1271_SCAN_STATE_DONE; | ||
273 | wl1271_scan_stm(wl); | ||
274 | } | ||
275 | |||
276 | break; | ||
277 | |||
278 | case WL1271_SCAN_STATE_DONE: | ||
279 | wl->scan.failed = false; | ||
280 | cancel_delayed_work(&wl->scan_complete_work); | ||
281 | ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work, | ||
282 | msecs_to_jiffies(0)); | ||
283 | break; | ||
284 | |||
285 | default: | ||
286 | wl1271_error("invalid scan state"); | ||
287 | break; | ||
288 | } | ||
289 | |||
290 | if (ret < 0) { | ||
291 | cancel_delayed_work(&wl->scan_complete_work); | ||
292 | ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work, | ||
293 | msecs_to_jiffies(0)); | ||
294 | } | ||
295 | } | ||
296 | |||
297 | int wl1271_scan(struct wl1271 *wl, const u8 *ssid, size_t ssid_len, | ||
298 | struct cfg80211_scan_request *req) | ||
299 | { | ||
300 | /* | ||
301 | * cfg80211 should guarantee that we don't get more channels | ||
302 | * than what we have registered. | ||
303 | */ | ||
304 | BUG_ON(req->n_channels > WL1271_MAX_CHANNELS); | ||
305 | |||
306 | if (wl->scan.state != WL1271_SCAN_STATE_IDLE) | ||
307 | return -EBUSY; | ||
308 | |||
309 | wl->scan.state = WL1271_SCAN_STATE_2GHZ_ACTIVE; | ||
310 | |||
311 | if (ssid_len && ssid) { | ||
312 | wl->scan.ssid_len = ssid_len; | ||
313 | memcpy(wl->scan.ssid, ssid, ssid_len); | ||
314 | } else { | ||
315 | wl->scan.ssid_len = 0; | ||
316 | } | ||
317 | |||
318 | wl->scan.req = req; | ||
319 | memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch)); | ||
320 | |||
321 | /* we assume failure so that timeout scenarios are handled correctly */ | ||
322 | wl->scan.failed = true; | ||
323 | ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work, | ||
324 | msecs_to_jiffies(WL1271_SCAN_TIMEOUT)); | ||
325 | |||
326 | wl1271_scan_stm(wl); | ||
327 | |||
328 | return 0; | ||
329 | } | ||
330 | |||
331 | int wl1271_scan_stop(struct wl1271 *wl) | ||
332 | { | ||
333 | struct wl1271_cmd_header *cmd = NULL; | ||
334 | int ret = 0; | ||
335 | |||
336 | if (WARN_ON(wl->scan.state == WL1271_SCAN_STATE_IDLE)) | ||
337 | return -EINVAL; | ||
338 | |||
339 | wl1271_debug(DEBUG_CMD, "cmd scan stop"); | ||
340 | |||
341 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | ||
342 | if (!cmd) { | ||
343 | ret = -ENOMEM; | ||
344 | goto out; | ||
345 | } | ||
346 | |||
347 | ret = wl1271_cmd_send(wl, CMD_STOP_SCAN, cmd, | ||
348 | sizeof(*cmd), 0); | ||
349 | if (ret < 0) { | ||
350 | wl1271_error("cmd stop_scan failed"); | ||
351 | goto out; | ||
352 | } | ||
353 | out: | ||
354 | kfree(cmd); | ||
355 | return ret; | ||
356 | } | ||
357 | |||
358 | static int | ||
359 | wl1271_scan_get_sched_scan_channels(struct wl1271 *wl, | ||
360 | struct cfg80211_sched_scan_request *req, | ||
361 | struct conn_scan_ch_params *channels, | ||
362 | u32 band, bool radar, bool passive, | ||
363 | int start, int max_channels) | ||
364 | { | ||
365 | struct conf_sched_scan_settings *c = &wl->conf.sched_scan; | ||
366 | int i, j; | ||
367 | u32 flags; | ||
368 | bool force_passive = !req->n_ssids; | ||
369 | |||
370 | for (i = 0, j = start; | ||
371 | i < req->n_channels && j < max_channels; | ||
372 | i++) { | ||
373 | flags = req->channels[i]->flags; | ||
374 | |||
375 | if (force_passive) | ||
376 | flags |= IEEE80211_CHAN_PASSIVE_SCAN; | ||
377 | |||
378 | if ((req->channels[i]->band == band) && | ||
379 | !(flags & IEEE80211_CHAN_DISABLED) && | ||
380 | (!!(flags & IEEE80211_CHAN_RADAR) == radar) && | ||
381 | /* if radar is set, we ignore the passive flag */ | ||
382 | (radar || | ||
383 | !!(flags & IEEE80211_CHAN_PASSIVE_SCAN) == passive)) { | ||
384 | wl1271_debug(DEBUG_SCAN, "band %d, center_freq %d ", | ||
385 | req->channels[i]->band, | ||
386 | req->channels[i]->center_freq); | ||
387 | wl1271_debug(DEBUG_SCAN, "hw_value %d, flags %X", | ||
388 | req->channels[i]->hw_value, | ||
389 | req->channels[i]->flags); | ||
390 | wl1271_debug(DEBUG_SCAN, "max_power %d", | ||
391 | req->channels[i]->max_power); | ||
392 | |||
393 | if (flags & IEEE80211_CHAN_RADAR) { | ||
394 | channels[j].flags |= SCAN_CHANNEL_FLAGS_DFS; | ||
395 | channels[j].passive_duration = | ||
396 | cpu_to_le16(c->dwell_time_dfs); | ||
397 | } | ||
398 | else if (flags & IEEE80211_CHAN_PASSIVE_SCAN) { | ||
399 | channels[j].passive_duration = | ||
400 | cpu_to_le16(c->dwell_time_passive); | ||
401 | } else { | ||
402 | channels[j].min_duration = | ||
403 | cpu_to_le16(c->min_dwell_time_active); | ||
404 | channels[j].max_duration = | ||
405 | cpu_to_le16(c->max_dwell_time_active); | ||
406 | } | ||
407 | channels[j].tx_power_att = req->channels[i]->max_power; | ||
408 | channels[j].channel = req->channels[i]->hw_value; | ||
409 | |||
410 | j++; | ||
411 | } | ||
412 | } | ||
413 | |||
414 | return j - start; | ||
415 | } | ||
416 | |||
417 | static bool | ||
418 | wl1271_scan_sched_scan_channels(struct wl1271 *wl, | ||
419 | struct cfg80211_sched_scan_request *req, | ||
420 | struct wl1271_cmd_sched_scan_config *cfg) | ||
421 | { | ||
422 | cfg->passive[0] = | ||
423 | wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_2, | ||
424 | IEEE80211_BAND_2GHZ, | ||
425 | false, true, 0, | ||
426 | MAX_CHANNELS_2GHZ); | ||
427 | cfg->active[0] = | ||
428 | wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_2, | ||
429 | IEEE80211_BAND_2GHZ, | ||
430 | false, false, | ||
431 | cfg->passive[0], | ||
432 | MAX_CHANNELS_2GHZ); | ||
433 | cfg->passive[1] = | ||
434 | wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_5, | ||
435 | IEEE80211_BAND_5GHZ, | ||
436 | false, true, 0, | ||
437 | MAX_CHANNELS_5GHZ); | ||
438 | cfg->dfs = | ||
439 | wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_5, | ||
440 | IEEE80211_BAND_5GHZ, | ||
441 | true, true, | ||
442 | cfg->passive[1], | ||
443 | MAX_CHANNELS_5GHZ); | ||
444 | cfg->active[1] = | ||
445 | wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_5, | ||
446 | IEEE80211_BAND_5GHZ, | ||
447 | false, false, | ||
448 | cfg->passive[1] + cfg->dfs, | ||
449 | MAX_CHANNELS_5GHZ); | ||
450 | /* 802.11j channels are not supported yet */ | ||
451 | cfg->passive[2] = 0; | ||
452 | cfg->active[2] = 0; | ||
453 | |||
454 | wl1271_debug(DEBUG_SCAN, " 2.4GHz: active %d passive %d", | ||
455 | cfg->active[0], cfg->passive[0]); | ||
456 | wl1271_debug(DEBUG_SCAN, " 5GHz: active %d passive %d", | ||
457 | cfg->active[1], cfg->passive[1]); | ||
458 | wl1271_debug(DEBUG_SCAN, " DFS: %d", cfg->dfs); | ||
459 | |||
460 | return cfg->passive[0] || cfg->active[0] || | ||
461 | cfg->passive[1] || cfg->active[1] || cfg->dfs || | ||
462 | cfg->passive[2] || cfg->active[2]; | ||
463 | } | ||
464 | |||
465 | int wl1271_scan_sched_scan_config(struct wl1271 *wl, | ||
466 | struct cfg80211_sched_scan_request *req, | ||
467 | struct ieee80211_sched_scan_ies *ies) | ||
468 | { | ||
469 | struct wl1271_cmd_sched_scan_config *cfg = NULL; | ||
470 | struct conf_sched_scan_settings *c = &wl->conf.sched_scan; | ||
471 | int i, ret; | ||
472 | bool force_passive = !req->n_ssids; | ||
473 | |||
474 | wl1271_debug(DEBUG_CMD, "cmd sched_scan scan config"); | ||
475 | |||
476 | cfg = kzalloc(sizeof(*cfg), GFP_KERNEL); | ||
477 | if (!cfg) | ||
478 | return -ENOMEM; | ||
479 | |||
480 | cfg->rssi_threshold = c->rssi_threshold; | ||
481 | cfg->snr_threshold = c->snr_threshold; | ||
482 | cfg->n_probe_reqs = c->num_probe_reqs; | ||
483 | /* cycles set to 0 it means infinite (until manually stopped) */ | ||
484 | cfg->cycles = 0; | ||
485 | /* report APs when at least 1 is found */ | ||
486 | cfg->report_after = 1; | ||
487 | /* don't stop scanning automatically when something is found */ | ||
488 | cfg->terminate = 0; | ||
489 | cfg->tag = WL1271_SCAN_DEFAULT_TAG; | ||
490 | /* don't filter on BSS type */ | ||
491 | cfg->bss_type = SCAN_BSS_TYPE_ANY; | ||
492 | /* currently NL80211 supports only a single interval */ | ||
493 | for (i = 0; i < SCAN_MAX_CYCLE_INTERVALS; i++) | ||
494 | cfg->intervals[i] = cpu_to_le32(req->interval); | ||
495 | |||
496 | if (!force_passive && req->ssids[0].ssid_len && req->ssids[0].ssid) { | ||
497 | cfg->filter_type = SCAN_SSID_FILTER_SPECIFIC; | ||
498 | cfg->ssid_len = req->ssids[0].ssid_len; | ||
499 | memcpy(cfg->ssid, req->ssids[0].ssid, | ||
500 | req->ssids[0].ssid_len); | ||
501 | } else { | ||
502 | cfg->filter_type = SCAN_SSID_FILTER_ANY; | ||
503 | cfg->ssid_len = 0; | ||
504 | } | ||
505 | |||
506 | if (!wl1271_scan_sched_scan_channels(wl, req, cfg)) { | ||
507 | wl1271_error("scan channel list is empty"); | ||
508 | ret = -EINVAL; | ||
509 | goto out; | ||
510 | } | ||
511 | |||
512 | if (!force_passive && cfg->active[0]) { | ||
513 | ret = wl1271_cmd_build_probe_req(wl, req->ssids[0].ssid, | ||
514 | req->ssids[0].ssid_len, | ||
515 | ies->ie[IEEE80211_BAND_2GHZ], | ||
516 | ies->len[IEEE80211_BAND_2GHZ], | ||
517 | IEEE80211_BAND_2GHZ); | ||
518 | if (ret < 0) { | ||
519 | wl1271_error("2.4GHz PROBE request template failed"); | ||
520 | goto out; | ||
521 | } | ||
522 | } | ||
523 | |||
524 | if (!force_passive && cfg->active[1]) { | ||
525 | ret = wl1271_cmd_build_probe_req(wl, req->ssids[0].ssid, | ||
526 | req->ssids[0].ssid_len, | ||
527 | ies->ie[IEEE80211_BAND_5GHZ], | ||
528 | ies->len[IEEE80211_BAND_5GHZ], | ||
529 | IEEE80211_BAND_5GHZ); | ||
530 | if (ret < 0) { | ||
531 | wl1271_error("5GHz PROBE request template failed"); | ||
532 | goto out; | ||
533 | } | ||
534 | } | ||
535 | |||
536 | wl1271_dump(DEBUG_SCAN, "SCAN_CFG: ", cfg, sizeof(*cfg)); | ||
537 | |||
538 | ret = wl1271_cmd_send(wl, CMD_CONNECTION_SCAN_CFG, cfg, | ||
539 | sizeof(*cfg), 0); | ||
540 | if (ret < 0) { | ||
541 | wl1271_error("SCAN configuration failed"); | ||
542 | goto out; | ||
543 | } | ||
544 | out: | ||
545 | kfree(cfg); | ||
546 | return ret; | ||
547 | } | ||
548 | |||
549 | int wl1271_scan_sched_scan_start(struct wl1271 *wl) | ||
550 | { | ||
551 | struct wl1271_cmd_sched_scan_start *start; | ||
552 | int ret = 0; | ||
553 | |||
554 | wl1271_debug(DEBUG_CMD, "cmd periodic scan start"); | ||
555 | |||
556 | if (wl->bss_type != BSS_TYPE_STA_BSS) | ||
557 | return -EOPNOTSUPP; | ||
558 | |||
559 | if (!test_bit(WL1271_FLAG_IDLE, &wl->flags)) | ||
560 | return -EBUSY; | ||
561 | |||
562 | start = kzalloc(sizeof(*start), GFP_KERNEL); | ||
563 | if (!start) | ||
564 | return -ENOMEM; | ||
565 | |||
566 | start->tag = WL1271_SCAN_DEFAULT_TAG; | ||
567 | |||
568 | ret = wl1271_cmd_send(wl, CMD_START_PERIODIC_SCAN, start, | ||
569 | sizeof(*start), 0); | ||
570 | if (ret < 0) { | ||
571 | wl1271_error("failed to send scan start command"); | ||
572 | goto out_free; | ||
573 | } | ||
574 | |||
575 | out_free: | ||
576 | kfree(start); | ||
577 | return ret; | ||
578 | } | ||
579 | |||
580 | void wl1271_scan_sched_scan_results(struct wl1271 *wl) | ||
581 | { | ||
582 | wl1271_debug(DEBUG_SCAN, "got periodic scan results"); | ||
583 | |||
584 | ieee80211_sched_scan_results(wl->hw); | ||
585 | } | ||
586 | |||
587 | void wl1271_scan_sched_scan_stop(struct wl1271 *wl) | ||
588 | { | ||
589 | struct wl1271_cmd_sched_scan_stop *stop; | ||
590 | int ret = 0; | ||
591 | |||
592 | wl1271_debug(DEBUG_CMD, "cmd periodic scan stop"); | ||
593 | |||
594 | /* FIXME: what to do if alloc'ing to stop fails? */ | ||
595 | stop = kzalloc(sizeof(*stop), GFP_KERNEL); | ||
596 | if (!stop) { | ||
597 | wl1271_error("failed to alloc memory to send sched scan stop"); | ||
598 | return; | ||
599 | } | ||
600 | |||
601 | stop->tag = WL1271_SCAN_DEFAULT_TAG; | ||
602 | |||
603 | ret = wl1271_cmd_send(wl, CMD_STOP_PERIODIC_SCAN, stop, | ||
604 | sizeof(*stop), 0); | ||
605 | if (ret < 0) { | ||
606 | wl1271_error("failed to send sched scan stop command"); | ||
607 | goto out_free; | ||
608 | } | ||
609 | wl->sched_scanning = false; | ||
610 | |||
611 | out_free: | ||
612 | kfree(stop); | ||
613 | } | ||
diff --git a/drivers/net/wireless/wl12xx/scan.h b/drivers/net/wireless/wl12xx/scan.h new file mode 100644 index 00000000000..d882e4da71b --- /dev/null +++ b/drivers/net/wireless/wl12xx/scan.h | |||
@@ -0,0 +1,224 @@ | |||
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 "wl12xx.h" | ||
28 | |||
29 | int wl1271_scan(struct wl1271 *wl, const u8 *ssid, size_t ssid_len, | ||
30 | struct cfg80211_scan_request *req); | ||
31 | int wl1271_scan_stop(struct wl1271 *wl); | ||
32 | int wl1271_scan_build_probe_req(struct wl1271 *wl, | ||
33 | const u8 *ssid, size_t ssid_len, | ||
34 | const u8 *ie, size_t ie_len, u8 band); | ||
35 | void wl1271_scan_stm(struct wl1271 *wl); | ||
36 | void wl1271_scan_complete_work(struct work_struct *work); | ||
37 | int wl1271_scan_sched_scan_config(struct wl1271 *wl, | ||
38 | struct cfg80211_sched_scan_request *req, | ||
39 | struct ieee80211_sched_scan_ies *ies); | ||
40 | int wl1271_scan_sched_scan_start(struct wl1271 *wl); | ||
41 | void wl1271_scan_sched_scan_stop(struct wl1271 *wl); | ||
42 | void wl1271_scan_sched_scan_results(struct wl1271 *wl); | ||
43 | |||
44 | #define WL1271_SCAN_MAX_CHANNELS 24 | ||
45 | #define WL1271_SCAN_DEFAULT_TAG 1 | ||
46 | #define WL1271_SCAN_CURRENT_TX_PWR 0 | ||
47 | #define WL1271_SCAN_OPT_ACTIVE 0 | ||
48 | #define WL1271_SCAN_OPT_PASSIVE 1 | ||
49 | #define WL1271_SCAN_OPT_PRIORITY_HIGH 4 | ||
50 | #define WL1271_SCAN_BAND_2_4_GHZ 0 | ||
51 | #define WL1271_SCAN_BAND_5_GHZ 1 | ||
52 | |||
53 | #define WL1271_SCAN_TIMEOUT 10000 /* msec */ | ||
54 | |||
55 | enum { | ||
56 | WL1271_SCAN_STATE_IDLE, | ||
57 | WL1271_SCAN_STATE_2GHZ_ACTIVE, | ||
58 | WL1271_SCAN_STATE_2GHZ_PASSIVE, | ||
59 | WL1271_SCAN_STATE_5GHZ_ACTIVE, | ||
60 | WL1271_SCAN_STATE_5GHZ_PASSIVE, | ||
61 | WL1271_SCAN_STATE_DONE | ||
62 | }; | ||
63 | |||
64 | struct basic_scan_params { | ||
65 | __le32 rx_config_options; | ||
66 | __le32 rx_filter_options; | ||
67 | /* Scan option flags (WL1271_SCAN_OPT_*) */ | ||
68 | __le16 scan_options; | ||
69 | /* Number of scan channels in the list (maximum 30) */ | ||
70 | u8 n_ch; | ||
71 | /* This field indicates the number of probe requests to send | ||
72 | per channel for an active scan */ | ||
73 | u8 n_probe_reqs; | ||
74 | /* Rate bit field for sending the probes */ | ||
75 | __le32 tx_rate; | ||
76 | u8 tid_trigger; | ||
77 | u8 ssid_len; | ||
78 | /* in order to align */ | ||
79 | u8 padding1[2]; | ||
80 | u8 ssid[IW_ESSID_MAX_SIZE]; | ||
81 | /* Band to scan */ | ||
82 | u8 band; | ||
83 | u8 use_ssid_list; | ||
84 | u8 scan_tag; | ||
85 | u8 padding2; | ||
86 | } __packed; | ||
87 | |||
88 | struct basic_scan_channel_params { | ||
89 | /* Duration in TU to wait for frames on a channel for active scan */ | ||
90 | __le32 min_duration; | ||
91 | __le32 max_duration; | ||
92 | __le32 bssid_lsb; | ||
93 | __le16 bssid_msb; | ||
94 | u8 early_termination; | ||
95 | u8 tx_power_att; | ||
96 | u8 channel; | ||
97 | /* FW internal use only! */ | ||
98 | u8 dfs_candidate; | ||
99 | u8 activity_detected; | ||
100 | u8 pad; | ||
101 | } __packed; | ||
102 | |||
103 | struct wl1271_cmd_scan { | ||
104 | struct wl1271_cmd_header header; | ||
105 | |||
106 | struct basic_scan_params params; | ||
107 | struct basic_scan_channel_params channels[WL1271_SCAN_MAX_CHANNELS]; | ||
108 | } __packed; | ||
109 | |||
110 | struct wl1271_cmd_trigger_scan_to { | ||
111 | struct wl1271_cmd_header header; | ||
112 | |||
113 | __le32 timeout; | ||
114 | } __packed; | ||
115 | |||
116 | #define MAX_CHANNELS_2GHZ 14 | ||
117 | #define MAX_CHANNELS_5GHZ 23 | ||
118 | #define MAX_CHANNELS_4GHZ 4 | ||
119 | |||
120 | #define SCAN_MAX_CYCLE_INTERVALS 16 | ||
121 | #define SCAN_MAX_BANDS 3 | ||
122 | |||
123 | enum { | ||
124 | SCAN_SSID_FILTER_ANY = 0, | ||
125 | SCAN_SSID_FILTER_SPECIFIC = 1, | ||
126 | SCAN_SSID_FILTER_LIST = 2, | ||
127 | SCAN_SSID_FILTER_DISABLED = 3 | ||
128 | }; | ||
129 | |||
130 | enum { | ||
131 | SCAN_BSS_TYPE_INDEPENDENT, | ||
132 | SCAN_BSS_TYPE_INFRASTRUCTURE, | ||
133 | SCAN_BSS_TYPE_ANY, | ||
134 | }; | ||
135 | |||
136 | #define SCAN_CHANNEL_FLAGS_DFS BIT(0) | ||
137 | #define SCAN_CHANNEL_FLAGS_DFS_ENABLED BIT(1) | ||
138 | |||
139 | struct conn_scan_ch_params { | ||
140 | __le16 min_duration; | ||
141 | __le16 max_duration; | ||
142 | __le16 passive_duration; | ||
143 | |||
144 | u8 channel; | ||
145 | u8 tx_power_att; | ||
146 | |||
147 | /* bit 0: DFS channel; bit 1: DFS enabled */ | ||
148 | u8 flags; | ||
149 | |||
150 | u8 padding[3]; | ||
151 | } __packed; | ||
152 | |||
153 | struct wl1271_cmd_sched_scan_config { | ||
154 | struct wl1271_cmd_header header; | ||
155 | |||
156 | __le32 intervals[SCAN_MAX_CYCLE_INTERVALS]; | ||
157 | |||
158 | s8 rssi_threshold; /* for filtering (in dBm) */ | ||
159 | s8 snr_threshold; /* for filtering (in dB) */ | ||
160 | |||
161 | u8 cycles; /* maximum number of scan cycles */ | ||
162 | u8 report_after; /* report when this number of results are received */ | ||
163 | u8 terminate; /* stop scanning after reporting */ | ||
164 | |||
165 | u8 tag; | ||
166 | u8 bss_type; /* for filtering */ | ||
167 | u8 filter_type; | ||
168 | |||
169 | u8 ssid_len; /* For SCAN_SSID_FILTER_SPECIFIC */ | ||
170 | u8 ssid[IW_ESSID_MAX_SIZE]; | ||
171 | |||
172 | u8 n_probe_reqs; /* Number of probes requests per channel */ | ||
173 | |||
174 | u8 passive[SCAN_MAX_BANDS]; | ||
175 | u8 active[SCAN_MAX_BANDS]; | ||
176 | |||
177 | u8 dfs; | ||
178 | |||
179 | u8 padding[3]; | ||
180 | |||
181 | struct conn_scan_ch_params channels_2[MAX_CHANNELS_2GHZ]; | ||
182 | struct conn_scan_ch_params channels_5[MAX_CHANNELS_5GHZ]; | ||
183 | struct conn_scan_ch_params channels_4[MAX_CHANNELS_4GHZ]; | ||
184 | } __packed; | ||
185 | |||
186 | |||
187 | #define SCHED_SCAN_MAX_SSIDS 8 | ||
188 | |||
189 | enum { | ||
190 | SCAN_SSID_TYPE_PUBLIC = 0, | ||
191 | SCAN_SSID_TYPE_HIDDEN = 1, | ||
192 | }; | ||
193 | |||
194 | struct wl1271_ssid { | ||
195 | u8 type; | ||
196 | u8 len; | ||
197 | u8 ssid[IW_ESSID_MAX_SIZE]; | ||
198 | /* u8 padding[2]; */ | ||
199 | } __packed; | ||
200 | |||
201 | struct wl1271_cmd_sched_scan_ssid_list { | ||
202 | struct wl1271_cmd_header header; | ||
203 | |||
204 | u8 n_ssids; | ||
205 | struct wl1271_ssid ssids[SCHED_SCAN_MAX_SSIDS]; | ||
206 | u8 padding[3]; | ||
207 | } __packed; | ||
208 | |||
209 | struct wl1271_cmd_sched_scan_start { | ||
210 | struct wl1271_cmd_header header; | ||
211 | |||
212 | u8 tag; | ||
213 | u8 padding[3]; | ||
214 | } __packed; | ||
215 | |||
216 | struct wl1271_cmd_sched_scan_stop { | ||
217 | struct wl1271_cmd_header header; | ||
218 | |||
219 | u8 tag; | ||
220 | u8 padding[3]; | ||
221 | } __packed; | ||
222 | |||
223 | |||
224 | #endif /* __WL1271_SCAN_H__ */ | ||
diff --git a/drivers/net/wireless/wl12xx/sdio.c b/drivers/net/wireless/wl12xx/sdio.c new file mode 100644 index 00000000000..fb1fd5af75e --- /dev/null +++ b/drivers/net/wireless/wl12xx/sdio.c | |||
@@ -0,0 +1,418 @@ | |||
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/mmc/sdio_func.h> | ||
28 | #include <linux/mmc/sdio_ids.h> | ||
29 | #include <linux/mmc/card.h> | ||
30 | #include <linux/mmc/host.h> | ||
31 | #include <linux/gpio.h> | ||
32 | #include <linux/wl12xx.h> | ||
33 | #include <linux/pm_runtime.h> | ||
34 | |||
35 | #include "wl12xx.h" | ||
36 | #include "wl12xx_80211.h" | ||
37 | #include "io.h" | ||
38 | |||
39 | #ifndef SDIO_VENDOR_ID_TI | ||
40 | #define SDIO_VENDOR_ID_TI 0x0097 | ||
41 | #endif | ||
42 | |||
43 | #ifndef SDIO_DEVICE_ID_TI_WL1271 | ||
44 | #define SDIO_DEVICE_ID_TI_WL1271 0x4076 | ||
45 | #endif | ||
46 | |||
47 | static const struct sdio_device_id wl1271_devices[] __devinitconst = { | ||
48 | { SDIO_DEVICE(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271) }, | ||
49 | {} | ||
50 | }; | ||
51 | MODULE_DEVICE_TABLE(sdio, wl1271_devices); | ||
52 | |||
53 | static void wl1271_sdio_set_block_size(struct wl1271 *wl, unsigned int blksz) | ||
54 | { | ||
55 | sdio_claim_host(wl->if_priv); | ||
56 | sdio_set_block_size(wl->if_priv, blksz); | ||
57 | sdio_release_host(wl->if_priv); | ||
58 | } | ||
59 | |||
60 | static inline struct sdio_func *wl_to_func(struct wl1271 *wl) | ||
61 | { | ||
62 | return wl->if_priv; | ||
63 | } | ||
64 | |||
65 | static struct device *wl1271_sdio_wl_to_dev(struct wl1271 *wl) | ||
66 | { | ||
67 | return &(wl_to_func(wl)->dev); | ||
68 | } | ||
69 | |||
70 | static irqreturn_t wl1271_hardirq(int irq, void *cookie) | ||
71 | { | ||
72 | struct wl1271 *wl = cookie; | ||
73 | unsigned long flags; | ||
74 | |||
75 | wl1271_debug(DEBUG_IRQ, "IRQ"); | ||
76 | |||
77 | /* complete the ELP completion */ | ||
78 | spin_lock_irqsave(&wl->wl_lock, flags); | ||
79 | set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags); | ||
80 | if (wl->elp_compl) { | ||
81 | complete(wl->elp_compl); | ||
82 | wl->elp_compl = NULL; | ||
83 | } | ||
84 | |||
85 | if (test_bit(WL1271_FLAG_SUSPENDED, &wl->flags)) { | ||
86 | /* don't enqueue a work right now. mark it as pending */ | ||
87 | set_bit(WL1271_FLAG_PENDING_WORK, &wl->flags); | ||
88 | wl1271_debug(DEBUG_IRQ, "should not enqueue work"); | ||
89 | disable_irq_nosync(wl->irq); | ||
90 | pm_wakeup_event(wl1271_sdio_wl_to_dev(wl), 0); | ||
91 | spin_unlock_irqrestore(&wl->wl_lock, flags); | ||
92 | return IRQ_HANDLED; | ||
93 | } | ||
94 | spin_unlock_irqrestore(&wl->wl_lock, flags); | ||
95 | |||
96 | return IRQ_WAKE_THREAD; | ||
97 | } | ||
98 | |||
99 | static void wl1271_sdio_disable_interrupts(struct wl1271 *wl) | ||
100 | { | ||
101 | disable_irq(wl->irq); | ||
102 | } | ||
103 | |||
104 | static void wl1271_sdio_enable_interrupts(struct wl1271 *wl) | ||
105 | { | ||
106 | enable_irq(wl->irq); | ||
107 | } | ||
108 | |||
109 | static void wl1271_sdio_raw_read(struct wl1271 *wl, int addr, void *buf, | ||
110 | size_t len, bool fixed) | ||
111 | { | ||
112 | int ret; | ||
113 | struct sdio_func *func = wl_to_func(wl); | ||
114 | |||
115 | if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) { | ||
116 | ((u8 *)buf)[0] = sdio_f0_readb(func, addr, &ret); | ||
117 | wl1271_debug(DEBUG_SDIO, "sdio read 52 addr 0x%x, byte 0x%02x", | ||
118 | addr, ((u8 *)buf)[0]); | ||
119 | } else { | ||
120 | if (fixed) | ||
121 | ret = sdio_readsb(func, buf, addr, len); | ||
122 | else | ||
123 | ret = sdio_memcpy_fromio(func, buf, addr, len); | ||
124 | |||
125 | wl1271_debug(DEBUG_SDIO, "sdio read 53 addr 0x%x, %zu bytes", | ||
126 | addr, len); | ||
127 | wl1271_dump_ascii(DEBUG_SDIO, "data: ", buf, len); | ||
128 | } | ||
129 | |||
130 | if (ret) | ||
131 | wl1271_error("sdio read failed (%d)", ret); | ||
132 | } | ||
133 | |||
134 | static void wl1271_sdio_raw_write(struct wl1271 *wl, int addr, void *buf, | ||
135 | size_t len, bool fixed) | ||
136 | { | ||
137 | int ret; | ||
138 | struct sdio_func *func = wl_to_func(wl); | ||
139 | |||
140 | if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) { | ||
141 | sdio_f0_writeb(func, ((u8 *)buf)[0], addr, &ret); | ||
142 | wl1271_debug(DEBUG_SDIO, "sdio write 52 addr 0x%x, byte 0x%02x", | ||
143 | addr, ((u8 *)buf)[0]); | ||
144 | } else { | ||
145 | wl1271_debug(DEBUG_SDIO, "sdio write 53 addr 0x%x, %zu bytes", | ||
146 | addr, len); | ||
147 | wl1271_dump_ascii(DEBUG_SDIO, "data: ", buf, len); | ||
148 | |||
149 | if (fixed) | ||
150 | ret = sdio_writesb(func, addr, buf, len); | ||
151 | else | ||
152 | ret = sdio_memcpy_toio(func, addr, buf, len); | ||
153 | } | ||
154 | |||
155 | if (ret) | ||
156 | wl1271_error("sdio write failed (%d)", ret); | ||
157 | } | ||
158 | |||
159 | static int wl1271_sdio_power_on(struct wl1271 *wl) | ||
160 | { | ||
161 | struct sdio_func *func = wl_to_func(wl); | ||
162 | int ret; | ||
163 | |||
164 | /* If enabled, tell runtime PM not to power off the card */ | ||
165 | if (pm_runtime_enabled(&func->dev)) { | ||
166 | ret = pm_runtime_get_sync(&func->dev); | ||
167 | if (ret < 0) | ||
168 | goto out; | ||
169 | } else { | ||
170 | /* Runtime PM is disabled: power up the card manually */ | ||
171 | ret = mmc_power_restore_host(func->card->host); | ||
172 | if (ret < 0) | ||
173 | goto out; | ||
174 | } | ||
175 | |||
176 | sdio_claim_host(func); | ||
177 | sdio_enable_func(func); | ||
178 | |||
179 | out: | ||
180 | return ret; | ||
181 | } | ||
182 | |||
183 | static int wl1271_sdio_power_off(struct wl1271 *wl) | ||
184 | { | ||
185 | struct sdio_func *func = wl_to_func(wl); | ||
186 | int ret; | ||
187 | |||
188 | sdio_disable_func(func); | ||
189 | sdio_release_host(func); | ||
190 | |||
191 | /* Power off the card manually, even if runtime PM is enabled. */ | ||
192 | ret = mmc_power_save_host(func->card->host); | ||
193 | if (ret < 0) | ||
194 | return ret; | ||
195 | |||
196 | /* If enabled, let runtime PM know the card is powered off */ | ||
197 | if (pm_runtime_enabled(&func->dev)) | ||
198 | ret = pm_runtime_put_sync(&func->dev); | ||
199 | |||
200 | return ret; | ||
201 | } | ||
202 | |||
203 | static int wl1271_sdio_set_power(struct wl1271 *wl, bool enable) | ||
204 | { | ||
205 | if (enable) | ||
206 | return wl1271_sdio_power_on(wl); | ||
207 | else | ||
208 | return wl1271_sdio_power_off(wl); | ||
209 | } | ||
210 | |||
211 | static struct wl1271_if_operations sdio_ops = { | ||
212 | .read = wl1271_sdio_raw_read, | ||
213 | .write = wl1271_sdio_raw_write, | ||
214 | .power = wl1271_sdio_set_power, | ||
215 | .dev = wl1271_sdio_wl_to_dev, | ||
216 | .enable_irq = wl1271_sdio_enable_interrupts, | ||
217 | .disable_irq = wl1271_sdio_disable_interrupts, | ||
218 | .set_block_size = wl1271_sdio_set_block_size, | ||
219 | }; | ||
220 | |||
221 | static int __devinit wl1271_probe(struct sdio_func *func, | ||
222 | const struct sdio_device_id *id) | ||
223 | { | ||
224 | struct ieee80211_hw *hw; | ||
225 | const struct wl12xx_platform_data *wlan_data; | ||
226 | struct wl1271 *wl; | ||
227 | unsigned long irqflags; | ||
228 | mmc_pm_flag_t mmcflags; | ||
229 | int ret; | ||
230 | |||
231 | /* We are only able to handle the wlan function */ | ||
232 | if (func->num != 0x02) | ||
233 | return -ENODEV; | ||
234 | |||
235 | hw = wl1271_alloc_hw(); | ||
236 | if (IS_ERR(hw)) | ||
237 | return PTR_ERR(hw); | ||
238 | |||
239 | wl = hw->priv; | ||
240 | |||
241 | wl->if_priv = func; | ||
242 | wl->if_ops = &sdio_ops; | ||
243 | |||
244 | /* Grab access to FN0 for ELP reg. */ | ||
245 | func->card->quirks |= MMC_QUIRK_LENIENT_FN0; | ||
246 | |||
247 | /* Use block mode for transferring over one block size of data */ | ||
248 | func->card->quirks |= MMC_QUIRK_BLKSZ_FOR_BYTE_MODE; | ||
249 | |||
250 | wlan_data = wl12xx_get_platform_data(); | ||
251 | if (IS_ERR(wlan_data)) { | ||
252 | ret = PTR_ERR(wlan_data); | ||
253 | wl1271_error("missing wlan platform data: %d", ret); | ||
254 | goto out_free; | ||
255 | } | ||
256 | |||
257 | wl->irq = wlan_data->irq; | ||
258 | wl->ref_clock = wlan_data->board_ref_clock; | ||
259 | wl->tcxo_clock = wlan_data->board_tcxo_clock; | ||
260 | wl->platform_quirks = wlan_data->platform_quirks; | ||
261 | |||
262 | if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ) | ||
263 | irqflags = IRQF_TRIGGER_RISING; | ||
264 | else | ||
265 | irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT; | ||
266 | |||
267 | ret = request_threaded_irq(wl->irq, wl1271_hardirq, wl1271_irq, | ||
268 | irqflags, | ||
269 | DRIVER_NAME, wl); | ||
270 | if (ret < 0) { | ||
271 | wl1271_error("request_irq() failed: %d", ret); | ||
272 | goto out_free; | ||
273 | } | ||
274 | |||
275 | ret = enable_irq_wake(wl->irq); | ||
276 | if (!ret) { | ||
277 | wl->irq_wake_enabled = true; | ||
278 | device_init_wakeup(wl1271_sdio_wl_to_dev(wl), 1); | ||
279 | |||
280 | /* if sdio can keep power while host is suspended, enable wow */ | ||
281 | mmcflags = sdio_get_host_pm_caps(func); | ||
282 | wl1271_debug(DEBUG_SDIO, "sdio PM caps = 0x%x", mmcflags); | ||
283 | |||
284 | if (mmcflags & MMC_PM_KEEP_POWER) | ||
285 | hw->wiphy->wowlan.flags = WIPHY_WOWLAN_ANY; | ||
286 | } | ||
287 | disable_irq(wl->irq); | ||
288 | |||
289 | ret = wl1271_init_ieee80211(wl); | ||
290 | if (ret) | ||
291 | goto out_irq; | ||
292 | |||
293 | ret = wl1271_register_hw(wl); | ||
294 | if (ret) | ||
295 | goto out_irq; | ||
296 | |||
297 | sdio_set_drvdata(func, wl); | ||
298 | |||
299 | /* Tell PM core that we don't need the card to be powered now */ | ||
300 | pm_runtime_put_noidle(&func->dev); | ||
301 | |||
302 | return 0; | ||
303 | |||
304 | out_irq: | ||
305 | free_irq(wl->irq, wl); | ||
306 | |||
307 | out_free: | ||
308 | wl1271_free_hw(wl); | ||
309 | |||
310 | return ret; | ||
311 | } | ||
312 | |||
313 | static void __devexit wl1271_remove(struct sdio_func *func) | ||
314 | { | ||
315 | struct wl1271 *wl = sdio_get_drvdata(func); | ||
316 | |||
317 | /* Undo decrement done above in wl1271_probe */ | ||
318 | pm_runtime_get_noresume(&func->dev); | ||
319 | |||
320 | wl1271_unregister_hw(wl); | ||
321 | if (wl->irq_wake_enabled) { | ||
322 | device_init_wakeup(wl1271_sdio_wl_to_dev(wl), 0); | ||
323 | disable_irq_wake(wl->irq); | ||
324 | } | ||
325 | free_irq(wl->irq, wl); | ||
326 | wl1271_free_hw(wl); | ||
327 | } | ||
328 | |||
329 | #ifdef CONFIG_PM | ||
330 | static int wl1271_suspend(struct device *dev) | ||
331 | { | ||
332 | /* Tell MMC/SDIO core it's OK to power down the card | ||
333 | * (if it isn't already), but not to remove it completely */ | ||
334 | struct sdio_func *func = dev_to_sdio_func(dev); | ||
335 | struct wl1271 *wl = sdio_get_drvdata(func); | ||
336 | mmc_pm_flag_t sdio_flags; | ||
337 | int ret = 0; | ||
338 | |||
339 | wl1271_debug(DEBUG_MAC80211, "wl1271 suspend. wow_enabled: %d", | ||
340 | wl->wow_enabled); | ||
341 | |||
342 | /* check whether sdio should keep power */ | ||
343 | if (wl->wow_enabled) { | ||
344 | sdio_flags = sdio_get_host_pm_caps(func); | ||
345 | |||
346 | if (!(sdio_flags & MMC_PM_KEEP_POWER)) { | ||
347 | wl1271_error("can't keep power while host " | ||
348 | "is suspended"); | ||
349 | ret = -EINVAL; | ||
350 | goto out; | ||
351 | } | ||
352 | |||
353 | /* keep power while host suspended */ | ||
354 | ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER); | ||
355 | if (ret) { | ||
356 | wl1271_error("error while trying to keep power"); | ||
357 | goto out; | ||
358 | } | ||
359 | |||
360 | /* release host */ | ||
361 | sdio_release_host(func); | ||
362 | } | ||
363 | out: | ||
364 | return ret; | ||
365 | } | ||
366 | |||
367 | static int wl1271_resume(struct device *dev) | ||
368 | { | ||
369 | struct sdio_func *func = dev_to_sdio_func(dev); | ||
370 | struct wl1271 *wl = sdio_get_drvdata(func); | ||
371 | |||
372 | wl1271_debug(DEBUG_MAC80211, "wl1271 resume"); | ||
373 | if (wl->wow_enabled) { | ||
374 | /* claim back host */ | ||
375 | sdio_claim_host(func); | ||
376 | } | ||
377 | |||
378 | return 0; | ||
379 | } | ||
380 | |||
381 | static const struct dev_pm_ops wl1271_sdio_pm_ops = { | ||
382 | .suspend = wl1271_suspend, | ||
383 | .resume = wl1271_resume, | ||
384 | }; | ||
385 | #endif | ||
386 | |||
387 | static struct sdio_driver wl1271_sdio_driver = { | ||
388 | .name = "wl1271_sdio", | ||
389 | .id_table = wl1271_devices, | ||
390 | .probe = wl1271_probe, | ||
391 | .remove = __devexit_p(wl1271_remove), | ||
392 | #ifdef CONFIG_PM | ||
393 | .drv = { | ||
394 | .pm = &wl1271_sdio_pm_ops, | ||
395 | }, | ||
396 | #endif | ||
397 | }; | ||
398 | |||
399 | static int __init wl1271_init(void) | ||
400 | { | ||
401 | return sdio_register_driver(&wl1271_sdio_driver); | ||
402 | } | ||
403 | |||
404 | static void __exit wl1271_exit(void) | ||
405 | { | ||
406 | sdio_unregister_driver(&wl1271_sdio_driver); | ||
407 | } | ||
408 | |||
409 | module_init(wl1271_init); | ||
410 | module_exit(wl1271_exit); | ||
411 | |||
412 | MODULE_LICENSE("GPL"); | ||
413 | MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>"); | ||
414 | MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>"); | ||
415 | MODULE_FIRMWARE(WL1271_FW_NAME); | ||
416 | MODULE_FIRMWARE(WL128X_FW_NAME); | ||
417 | MODULE_FIRMWARE(WL127X_AP_FW_NAME); | ||
418 | MODULE_FIRMWARE(WL128X_AP_FW_NAME); | ||
diff --git a/drivers/net/wireless/wl12xx/sdio_test.c b/drivers/net/wireless/wl12xx/sdio_test.c new file mode 100644 index 00000000000..f2891539287 --- /dev/null +++ b/drivers/net/wireless/wl12xx/sdio_test.c | |||
@@ -0,0 +1,534 @@ | |||
1 | /* | ||
2 | * SDIO testing driver for wl12xx | ||
3 | * | ||
4 | * Copyright (C) 2010 Nokia Corporation | ||
5 | * | ||
6 | * Contact: Roger Quadros <roger.quadros@nokia.com> | ||
7 | * | ||
8 | * wl12xx read/write routines taken from the main module | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or | ||
11 | * modify it under the terms of the GNU General Public License | ||
12 | * version 2 as published by the Free Software Foundation. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, but | ||
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | * General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
22 | * 02110-1301 USA | ||
23 | * | ||
24 | */ | ||
25 | |||
26 | #include <linux/irq.h> | ||
27 | #include <linux/module.h> | ||
28 | #include <linux/crc7.h> | ||
29 | #include <linux/vmalloc.h> | ||
30 | #include <linux/mmc/sdio_func.h> | ||
31 | #include <linux/mmc/sdio_ids.h> | ||
32 | #include <linux/mmc/card.h> | ||
33 | #include <linux/gpio.h> | ||
34 | #include <linux/wl12xx.h> | ||
35 | #include <linux/kthread.h> | ||
36 | #include <linux/firmware.h> | ||
37 | #include <linux/pm_runtime.h> | ||
38 | |||
39 | #include "wl12xx.h" | ||
40 | #include "io.h" | ||
41 | #include "boot.h" | ||
42 | |||
43 | #ifndef SDIO_VENDOR_ID_TI | ||
44 | #define SDIO_VENDOR_ID_TI 0x0097 | ||
45 | #endif | ||
46 | |||
47 | #ifndef SDIO_DEVICE_ID_TI_WL1271 | ||
48 | #define SDIO_DEVICE_ID_TI_WL1271 0x4076 | ||
49 | #endif | ||
50 | |||
51 | static bool rx, tx; | ||
52 | |||
53 | module_param(rx, bool, S_IRUGO | S_IWUSR); | ||
54 | MODULE_PARM_DESC(rx, "Perform rx test. Default (0). " | ||
55 | "This test continuously reads data from the SDIO device.\n"); | ||
56 | |||
57 | module_param(tx, bool, S_IRUGO | S_IWUSR); | ||
58 | MODULE_PARM_DESC(tx, "Perform tx test. Default (0). " | ||
59 | "This test continuously writes data to the SDIO device.\n"); | ||
60 | |||
61 | struct wl1271_test { | ||
62 | struct wl1271 wl; | ||
63 | struct task_struct *test_task; | ||
64 | }; | ||
65 | |||
66 | static const struct sdio_device_id wl1271_devices[] = { | ||
67 | { SDIO_DEVICE(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271) }, | ||
68 | {} | ||
69 | }; | ||
70 | |||
71 | static inline struct sdio_func *wl_to_func(struct wl1271 *wl) | ||
72 | { | ||
73 | return wl->if_priv; | ||
74 | } | ||
75 | |||
76 | static struct device *wl1271_sdio_wl_to_dev(struct wl1271 *wl) | ||
77 | { | ||
78 | return &(wl_to_func(wl)->dev); | ||
79 | } | ||
80 | |||
81 | static void wl1271_sdio_raw_read(struct wl1271 *wl, int addr, void *buf, | ||
82 | size_t len, bool fixed) | ||
83 | { | ||
84 | int ret = 0; | ||
85 | struct sdio_func *func = wl_to_func(wl); | ||
86 | |||
87 | if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) { | ||
88 | ((u8 *)buf)[0] = sdio_f0_readb(func, addr, &ret); | ||
89 | wl1271_debug(DEBUG_SDIO, "sdio read 52 addr 0x%x, byte 0x%02x", | ||
90 | addr, ((u8 *)buf)[0]); | ||
91 | } else { | ||
92 | if (fixed) | ||
93 | ret = sdio_readsb(func, buf, addr, len); | ||
94 | else | ||
95 | ret = sdio_memcpy_fromio(func, buf, addr, len); | ||
96 | |||
97 | wl1271_debug(DEBUG_SDIO, "sdio read 53 addr 0x%x, %zu bytes", | ||
98 | addr, len); | ||
99 | wl1271_dump_ascii(DEBUG_SDIO, "data: ", buf, len); | ||
100 | } | ||
101 | |||
102 | if (ret) | ||
103 | wl1271_error("sdio read failed (%d)", ret); | ||
104 | } | ||
105 | |||
106 | static void wl1271_sdio_raw_write(struct wl1271 *wl, int addr, void *buf, | ||
107 | size_t len, bool fixed) | ||
108 | { | ||
109 | int ret = 0; | ||
110 | struct sdio_func *func = wl_to_func(wl); | ||
111 | |||
112 | if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) { | ||
113 | sdio_f0_writeb(func, ((u8 *)buf)[0], addr, &ret); | ||
114 | wl1271_debug(DEBUG_SDIO, "sdio write 52 addr 0x%x, byte 0x%02x", | ||
115 | addr, ((u8 *)buf)[0]); | ||
116 | } else { | ||
117 | wl1271_debug(DEBUG_SDIO, "sdio write 53 addr 0x%x, %zu bytes", | ||
118 | addr, len); | ||
119 | wl1271_dump_ascii(DEBUG_SDIO, "data: ", buf, len); | ||
120 | |||
121 | if (fixed) | ||
122 | ret = sdio_writesb(func, addr, buf, len); | ||
123 | else | ||
124 | ret = sdio_memcpy_toio(func, addr, buf, len); | ||
125 | } | ||
126 | if (ret) | ||
127 | wl1271_error("sdio write failed (%d)", ret); | ||
128 | |||
129 | } | ||
130 | |||
131 | static int wl1271_sdio_set_power(struct wl1271 *wl, bool enable) | ||
132 | { | ||
133 | struct sdio_func *func = wl_to_func(wl); | ||
134 | int ret; | ||
135 | |||
136 | /* Let the SDIO stack handle wlan_enable control, so we | ||
137 | * keep host claimed while wlan is in use to keep wl1271 | ||
138 | * alive. | ||
139 | */ | ||
140 | if (enable) { | ||
141 | /* Power up the card */ | ||
142 | ret = pm_runtime_get_sync(&func->dev); | ||
143 | if (ret < 0) | ||
144 | goto out; | ||
145 | sdio_claim_host(func); | ||
146 | sdio_enable_func(func); | ||
147 | sdio_release_host(func); | ||
148 | } else { | ||
149 | sdio_claim_host(func); | ||
150 | sdio_disable_func(func); | ||
151 | sdio_release_host(func); | ||
152 | |||
153 | /* Power down the card */ | ||
154 | ret = pm_runtime_put_sync(&func->dev); | ||
155 | } | ||
156 | |||
157 | out: | ||
158 | return ret; | ||
159 | } | ||
160 | |||
161 | static void wl1271_sdio_disable_interrupts(struct wl1271 *wl) | ||
162 | { | ||
163 | } | ||
164 | |||
165 | static void wl1271_sdio_enable_interrupts(struct wl1271 *wl) | ||
166 | { | ||
167 | } | ||
168 | |||
169 | |||
170 | static struct wl1271_if_operations sdio_ops = { | ||
171 | .read = wl1271_sdio_raw_read, | ||
172 | .write = wl1271_sdio_raw_write, | ||
173 | .power = wl1271_sdio_set_power, | ||
174 | .dev = wl1271_sdio_wl_to_dev, | ||
175 | .enable_irq = wl1271_sdio_enable_interrupts, | ||
176 | .disable_irq = wl1271_sdio_disable_interrupts, | ||
177 | }; | ||
178 | |||
179 | static void wl1271_fw_wakeup(struct wl1271 *wl) | ||
180 | { | ||
181 | u32 elp_reg; | ||
182 | |||
183 | elp_reg = ELPCTRL_WAKE_UP; | ||
184 | wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg); | ||
185 | } | ||
186 | |||
187 | static int wl1271_fetch_firmware(struct wl1271 *wl) | ||
188 | { | ||
189 | const struct firmware *fw; | ||
190 | int ret; | ||
191 | |||
192 | if (wl->chip.id == CHIP_ID_1283_PG20) | ||
193 | ret = request_firmware(&fw, WL128X_FW_NAME, | ||
194 | wl1271_wl_to_dev(wl)); | ||
195 | else | ||
196 | ret = request_firmware(&fw, WL1271_FW_NAME, | ||
197 | wl1271_wl_to_dev(wl)); | ||
198 | |||
199 | if (ret < 0) { | ||
200 | wl1271_error("could not get firmware: %d", ret); | ||
201 | return ret; | ||
202 | } | ||
203 | |||
204 | if (fw->size % 4) { | ||
205 | wl1271_error("firmware size is not multiple of 32 bits: %zu", | ||
206 | fw->size); | ||
207 | ret = -EILSEQ; | ||
208 | goto out; | ||
209 | } | ||
210 | |||
211 | wl->fw_len = fw->size; | ||
212 | wl->fw = vmalloc(wl->fw_len); | ||
213 | |||
214 | if (!wl->fw) { | ||
215 | wl1271_error("could not allocate memory for the firmware"); | ||
216 | ret = -ENOMEM; | ||
217 | goto out; | ||
218 | } | ||
219 | |||
220 | memcpy(wl->fw, fw->data, wl->fw_len); | ||
221 | |||
222 | ret = 0; | ||
223 | |||
224 | out: | ||
225 | release_firmware(fw); | ||
226 | |||
227 | return ret; | ||
228 | } | ||
229 | |||
230 | static int wl1271_fetch_nvs(struct wl1271 *wl) | ||
231 | { | ||
232 | const struct firmware *fw; | ||
233 | int ret; | ||
234 | |||
235 | ret = request_firmware(&fw, WL12XX_NVS_NAME, wl1271_wl_to_dev(wl)); | ||
236 | |||
237 | if (ret < 0) { | ||
238 | wl1271_error("could not get nvs file: %d", ret); | ||
239 | return ret; | ||
240 | } | ||
241 | |||
242 | wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL); | ||
243 | |||
244 | if (!wl->nvs) { | ||
245 | wl1271_error("could not allocate memory for the nvs file"); | ||
246 | ret = -ENOMEM; | ||
247 | goto out; | ||
248 | } | ||
249 | |||
250 | wl->nvs_len = fw->size; | ||
251 | |||
252 | out: | ||
253 | release_firmware(fw); | ||
254 | |||
255 | return ret; | ||
256 | } | ||
257 | |||
258 | static int wl1271_chip_wakeup(struct wl1271 *wl) | ||
259 | { | ||
260 | struct wl1271_partition_set partition; | ||
261 | int ret; | ||
262 | |||
263 | msleep(WL1271_PRE_POWER_ON_SLEEP); | ||
264 | ret = wl1271_power_on(wl); | ||
265 | if (ret) | ||
266 | return ret; | ||
267 | |||
268 | msleep(WL1271_POWER_ON_SLEEP); | ||
269 | |||
270 | /* We don't need a real memory partition here, because we only want | ||
271 | * to use the registers at this point. */ | ||
272 | memset(&partition, 0, sizeof(partition)); | ||
273 | partition.reg.start = REGISTERS_BASE; | ||
274 | partition.reg.size = REGISTERS_DOWN_SIZE; | ||
275 | wl1271_set_partition(wl, &partition); | ||
276 | |||
277 | /* ELP module wake up */ | ||
278 | wl1271_fw_wakeup(wl); | ||
279 | |||
280 | /* whal_FwCtrl_BootSm() */ | ||
281 | |||
282 | /* 0. read chip id from CHIP_ID */ | ||
283 | wl->chip.id = wl1271_read32(wl, CHIP_ID_B); | ||
284 | |||
285 | /* 1. check if chip id is valid */ | ||
286 | |||
287 | switch (wl->chip.id) { | ||
288 | case CHIP_ID_1271_PG10: | ||
289 | wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete", | ||
290 | wl->chip.id); | ||
291 | break; | ||
292 | case CHIP_ID_1271_PG20: | ||
293 | wl1271_notice("chip id 0x%x (1271 PG20)", | ||
294 | wl->chip.id); | ||
295 | break; | ||
296 | case CHIP_ID_1283_PG20: | ||
297 | wl1271_notice("chip id 0x%x (1283 PG20)", | ||
298 | wl->chip.id); | ||
299 | break; | ||
300 | case CHIP_ID_1283_PG10: | ||
301 | default: | ||
302 | wl1271_warning("unsupported chip id: 0x%x", wl->chip.id); | ||
303 | return -ENODEV; | ||
304 | } | ||
305 | |||
306 | return ret; | ||
307 | } | ||
308 | |||
309 | static struct wl1271_partition_set part_down = { | ||
310 | .mem = { | ||
311 | .start = 0x00000000, | ||
312 | .size = 0x000177c0 | ||
313 | }, | ||
314 | .reg = { | ||
315 | .start = REGISTERS_BASE, | ||
316 | .size = 0x00008800 | ||
317 | }, | ||
318 | .mem2 = { | ||
319 | .start = 0x00000000, | ||
320 | .size = 0x00000000 | ||
321 | }, | ||
322 | .mem3 = { | ||
323 | .start = 0x00000000, | ||
324 | .size = 0x00000000 | ||
325 | }, | ||
326 | }; | ||
327 | |||
328 | static int tester(void *data) | ||
329 | { | ||
330 | struct wl1271 *wl = data; | ||
331 | struct sdio_func *func = wl_to_func(wl); | ||
332 | struct device *pdev = &func->dev; | ||
333 | int ret = 0; | ||
334 | bool rx_started = 0; | ||
335 | bool tx_started = 0; | ||
336 | uint8_t *tx_buf, *rx_buf; | ||
337 | int test_size = PAGE_SIZE; | ||
338 | u32 addr = 0; | ||
339 | struct wl1271_partition_set partition; | ||
340 | |||
341 | /* We assume chip is powered up and firmware fetched */ | ||
342 | |||
343 | memcpy(&partition, &part_down, sizeof(partition)); | ||
344 | partition.mem.start = addr; | ||
345 | wl1271_set_partition(wl, &partition); | ||
346 | |||
347 | tx_buf = kmalloc(test_size, GFP_KERNEL); | ||
348 | rx_buf = kmalloc(test_size, GFP_KERNEL); | ||
349 | if (!tx_buf || !rx_buf) { | ||
350 | dev_err(pdev, | ||
351 | "Could not allocate memory. Test will not run.\n"); | ||
352 | ret = -ENOMEM; | ||
353 | goto free; | ||
354 | } | ||
355 | |||
356 | memset(tx_buf, 0x5a, test_size); | ||
357 | |||
358 | /* write something in data area so we can read it back */ | ||
359 | wl1271_write(wl, addr, tx_buf, test_size, false); | ||
360 | |||
361 | while (!kthread_should_stop()) { | ||
362 | if (rx && !rx_started) { | ||
363 | dev_info(pdev, "starting rx test\n"); | ||
364 | rx_started = 1; | ||
365 | } else if (!rx && rx_started) { | ||
366 | dev_info(pdev, "stopping rx test\n"); | ||
367 | rx_started = 0; | ||
368 | } | ||
369 | |||
370 | if (tx && !tx_started) { | ||
371 | dev_info(pdev, "starting tx test\n"); | ||
372 | tx_started = 1; | ||
373 | } else if (!tx && tx_started) { | ||
374 | dev_info(pdev, "stopping tx test\n"); | ||
375 | tx_started = 0; | ||
376 | } | ||
377 | |||
378 | if (rx_started) | ||
379 | wl1271_read(wl, addr, rx_buf, test_size, false); | ||
380 | |||
381 | if (tx_started) | ||
382 | wl1271_write(wl, addr, tx_buf, test_size, false); | ||
383 | |||
384 | if (!rx_started && !tx_started) | ||
385 | msleep(100); | ||
386 | } | ||
387 | |||
388 | free: | ||
389 | kfree(tx_buf); | ||
390 | kfree(rx_buf); | ||
391 | return ret; | ||
392 | } | ||
393 | |||
394 | static int __devinit wl1271_probe(struct sdio_func *func, | ||
395 | const struct sdio_device_id *id) | ||
396 | { | ||
397 | const struct wl12xx_platform_data *wlan_data; | ||
398 | struct wl1271 *wl; | ||
399 | struct wl1271_test *wl_test; | ||
400 | int ret = 0; | ||
401 | |||
402 | /* wl1271 has 2 sdio functions we handle just the wlan part */ | ||
403 | if (func->num != 0x02) | ||
404 | return -ENODEV; | ||
405 | |||
406 | wl_test = kzalloc(sizeof(struct wl1271_test), GFP_KERNEL); | ||
407 | if (!wl_test) { | ||
408 | dev_err(&func->dev, "Could not allocate memory\n"); | ||
409 | return -ENOMEM; | ||
410 | } | ||
411 | |||
412 | wl = &wl_test->wl; | ||
413 | |||
414 | wl->if_priv = func; | ||
415 | wl->if_ops = &sdio_ops; | ||
416 | |||
417 | /* Grab access to FN0 for ELP reg. */ | ||
418 | func->card->quirks |= MMC_QUIRK_LENIENT_FN0; | ||
419 | |||
420 | /* Use block mode for transferring over one block size of data */ | ||
421 | func->card->quirks |= MMC_QUIRK_BLKSZ_FOR_BYTE_MODE; | ||
422 | |||
423 | wlan_data = wl12xx_get_platform_data(); | ||
424 | if (IS_ERR(wlan_data)) { | ||
425 | ret = PTR_ERR(wlan_data); | ||
426 | dev_err(&func->dev, "missing wlan platform data: %d\n", ret); | ||
427 | goto out_free; | ||
428 | } | ||
429 | |||
430 | wl->irq = wlan_data->irq; | ||
431 | wl->ref_clock = wlan_data->board_ref_clock; | ||
432 | wl->tcxo_clock = wlan_data->board_tcxo_clock; | ||
433 | |||
434 | sdio_set_drvdata(func, wl_test); | ||
435 | |||
436 | |||
437 | /* power up the device */ | ||
438 | ret = wl1271_chip_wakeup(wl); | ||
439 | if (ret) { | ||
440 | dev_err(&func->dev, "could not wake up chip\n"); | ||
441 | goto out_free; | ||
442 | } | ||
443 | |||
444 | if (wl->fw == NULL) { | ||
445 | ret = wl1271_fetch_firmware(wl); | ||
446 | if (ret < 0) { | ||
447 | dev_err(&func->dev, "firmware fetch error\n"); | ||
448 | goto out_off; | ||
449 | } | ||
450 | } | ||
451 | |||
452 | /* fetch NVS */ | ||
453 | if (wl->nvs == NULL) { | ||
454 | ret = wl1271_fetch_nvs(wl); | ||
455 | if (ret < 0) { | ||
456 | dev_err(&func->dev, "NVS fetch error\n"); | ||
457 | goto out_off; | ||
458 | } | ||
459 | } | ||
460 | |||
461 | ret = wl1271_load_firmware(wl); | ||
462 | if (ret < 0) { | ||
463 | dev_err(&func->dev, "firmware load error: %d\n", ret); | ||
464 | goto out_free; | ||
465 | } | ||
466 | |||
467 | dev_info(&func->dev, "initialized\n"); | ||
468 | |||
469 | /* I/O testing will be done in the tester thread */ | ||
470 | |||
471 | wl_test->test_task = kthread_run(tester, wl, "sdio_tester"); | ||
472 | if (IS_ERR(wl_test->test_task)) { | ||
473 | dev_err(&func->dev, "unable to create kernel thread\n"); | ||
474 | ret = PTR_ERR(wl_test->test_task); | ||
475 | goto out_free; | ||
476 | } | ||
477 | |||
478 | return 0; | ||
479 | |||
480 | out_off: | ||
481 | /* power off the chip */ | ||
482 | wl1271_power_off(wl); | ||
483 | |||
484 | out_free: | ||
485 | kfree(wl_test); | ||
486 | return ret; | ||
487 | } | ||
488 | |||
489 | static void __devexit wl1271_remove(struct sdio_func *func) | ||
490 | { | ||
491 | struct wl1271_test *wl_test = sdio_get_drvdata(func); | ||
492 | |||
493 | /* stop the I/O test thread */ | ||
494 | kthread_stop(wl_test->test_task); | ||
495 | |||
496 | /* power off the chip */ | ||
497 | wl1271_power_off(&wl_test->wl); | ||
498 | |||
499 | vfree(wl_test->wl.fw); | ||
500 | wl_test->wl.fw = NULL; | ||
501 | kfree(wl_test->wl.nvs); | ||
502 | wl_test->wl.nvs = NULL; | ||
503 | |||
504 | kfree(wl_test); | ||
505 | } | ||
506 | |||
507 | static struct sdio_driver wl1271_sdio_driver = { | ||
508 | .name = "wl12xx_sdio_test", | ||
509 | .id_table = wl1271_devices, | ||
510 | .probe = wl1271_probe, | ||
511 | .remove = __devexit_p(wl1271_remove), | ||
512 | }; | ||
513 | |||
514 | static int __init wl1271_init(void) | ||
515 | { | ||
516 | int ret; | ||
517 | |||
518 | ret = sdio_register_driver(&wl1271_sdio_driver); | ||
519 | if (ret < 0) | ||
520 | pr_err("failed to register sdio driver: %d\n", ret); | ||
521 | |||
522 | return ret; | ||
523 | } | ||
524 | module_init(wl1271_init); | ||
525 | |||
526 | static void __exit wl1271_exit(void) | ||
527 | { | ||
528 | sdio_unregister_driver(&wl1271_sdio_driver); | ||
529 | } | ||
530 | module_exit(wl1271_exit); | ||
531 | |||
532 | MODULE_LICENSE("GPL"); | ||
533 | MODULE_AUTHOR("Roger Quadros <roger.quadros@nokia.com>"); | ||
534 | |||
diff --git a/drivers/net/wireless/wl12xx/spi.c b/drivers/net/wireless/wl12xx/spi.c new file mode 100644 index 00000000000..e0b3736d7e1 --- /dev/null +++ b/drivers/net/wireless/wl12xx/spi.c | |||
@@ -0,0 +1,493 @@ | |||
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/slab.h> | ||
31 | |||
32 | #include "wl12xx.h" | ||
33 | #include "wl12xx_80211.h" | ||
34 | #include "io.h" | ||
35 | |||
36 | #include "reg.h" | ||
37 | |||
38 | #define WSPI_CMD_READ 0x40000000 | ||
39 | #define WSPI_CMD_WRITE 0x00000000 | ||
40 | #define WSPI_CMD_FIXED 0x20000000 | ||
41 | #define WSPI_CMD_BYTE_LENGTH 0x1FFE0000 | ||
42 | #define WSPI_CMD_BYTE_LENGTH_OFFSET 17 | ||
43 | #define WSPI_CMD_BYTE_ADDR 0x0001FFFF | ||
44 | |||
45 | #define WSPI_INIT_CMD_CRC_LEN 5 | ||
46 | |||
47 | #define WSPI_INIT_CMD_START 0x00 | ||
48 | #define WSPI_INIT_CMD_TX 0x40 | ||
49 | /* the extra bypass bit is sampled by the TNET as '1' */ | ||
50 | #define WSPI_INIT_CMD_BYPASS_BIT 0x80 | ||
51 | #define WSPI_INIT_CMD_FIXEDBUSY_LEN 0x07 | ||
52 | #define WSPI_INIT_CMD_EN_FIXEDBUSY 0x80 | ||
53 | #define WSPI_INIT_CMD_DIS_FIXEDBUSY 0x00 | ||
54 | #define WSPI_INIT_CMD_IOD 0x40 | ||
55 | #define WSPI_INIT_CMD_IP 0x20 | ||
56 | #define WSPI_INIT_CMD_CS 0x10 | ||
57 | #define WSPI_INIT_CMD_WS 0x08 | ||
58 | #define WSPI_INIT_CMD_WSPI 0x01 | ||
59 | #define WSPI_INIT_CMD_END 0x01 | ||
60 | |||
61 | #define WSPI_INIT_CMD_LEN 8 | ||
62 | |||
63 | #define HW_ACCESS_WSPI_FIXED_BUSY_LEN \ | ||
64 | ((WL1271_BUSY_WORD_LEN - 4) / sizeof(u32)) | ||
65 | #define HW_ACCESS_WSPI_INIT_CMD_MASK 0 | ||
66 | |||
67 | /* HW limitation: maximum possible chunk size is 4095 bytes */ | ||
68 | #define WSPI_MAX_CHUNK_SIZE 4092 | ||
69 | |||
70 | #define WSPI_MAX_NUM_OF_CHUNKS (WL1271_AGGR_BUFFER_SIZE / WSPI_MAX_CHUNK_SIZE) | ||
71 | |||
72 | static inline struct spi_device *wl_to_spi(struct wl1271 *wl) | ||
73 | { | ||
74 | return wl->if_priv; | ||
75 | } | ||
76 | |||
77 | static struct device *wl1271_spi_wl_to_dev(struct wl1271 *wl) | ||
78 | { | ||
79 | return &(wl_to_spi(wl)->dev); | ||
80 | } | ||
81 | |||
82 | static void wl1271_spi_disable_interrupts(struct wl1271 *wl) | ||
83 | { | ||
84 | disable_irq(wl->irq); | ||
85 | } | ||
86 | |||
87 | static void wl1271_spi_enable_interrupts(struct wl1271 *wl) | ||
88 | { | ||
89 | enable_irq(wl->irq); | ||
90 | } | ||
91 | |||
92 | static void wl1271_spi_reset(struct wl1271 *wl) | ||
93 | { | ||
94 | u8 *cmd; | ||
95 | struct spi_transfer t; | ||
96 | struct spi_message m; | ||
97 | |||
98 | cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL); | ||
99 | if (!cmd) { | ||
100 | wl1271_error("could not allocate cmd for spi reset"); | ||
101 | return; | ||
102 | } | ||
103 | |||
104 | memset(&t, 0, sizeof(t)); | ||
105 | spi_message_init(&m); | ||
106 | |||
107 | memset(cmd, 0xff, WSPI_INIT_CMD_LEN); | ||
108 | |||
109 | t.tx_buf = cmd; | ||
110 | t.len = WSPI_INIT_CMD_LEN; | ||
111 | spi_message_add_tail(&t, &m); | ||
112 | |||
113 | spi_sync(wl_to_spi(wl), &m); | ||
114 | |||
115 | wl1271_dump(DEBUG_SPI, "spi reset -> ", cmd, WSPI_INIT_CMD_LEN); | ||
116 | kfree(cmd); | ||
117 | } | ||
118 | |||
119 | static void wl1271_spi_init(struct wl1271 *wl) | ||
120 | { | ||
121 | u8 crc[WSPI_INIT_CMD_CRC_LEN], *cmd; | ||
122 | struct spi_transfer t; | ||
123 | struct spi_message m; | ||
124 | |||
125 | cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL); | ||
126 | if (!cmd) { | ||
127 | wl1271_error("could not allocate cmd for spi init"); | ||
128 | return; | ||
129 | } | ||
130 | |||
131 | memset(crc, 0, sizeof(crc)); | ||
132 | memset(&t, 0, sizeof(t)); | ||
133 | spi_message_init(&m); | ||
134 | |||
135 | /* | ||
136 | * Set WSPI_INIT_COMMAND | ||
137 | * the data is being send from the MSB to LSB | ||
138 | */ | ||
139 | cmd[2] = 0xff; | ||
140 | cmd[3] = 0xff; | ||
141 | cmd[1] = WSPI_INIT_CMD_START | WSPI_INIT_CMD_TX; | ||
142 | cmd[0] = 0; | ||
143 | cmd[7] = 0; | ||
144 | cmd[6] |= HW_ACCESS_WSPI_INIT_CMD_MASK << 3; | ||
145 | cmd[6] |= HW_ACCESS_WSPI_FIXED_BUSY_LEN & WSPI_INIT_CMD_FIXEDBUSY_LEN; | ||
146 | |||
147 | if (HW_ACCESS_WSPI_FIXED_BUSY_LEN == 0) | ||
148 | cmd[5] |= WSPI_INIT_CMD_DIS_FIXEDBUSY; | ||
149 | else | ||
150 | cmd[5] |= WSPI_INIT_CMD_EN_FIXEDBUSY; | ||
151 | |||
152 | cmd[5] |= WSPI_INIT_CMD_IOD | WSPI_INIT_CMD_IP | WSPI_INIT_CMD_CS | ||
153 | | WSPI_INIT_CMD_WSPI | WSPI_INIT_CMD_WS; | ||
154 | |||
155 | crc[0] = cmd[1]; | ||
156 | crc[1] = cmd[0]; | ||
157 | crc[2] = cmd[7]; | ||
158 | crc[3] = cmd[6]; | ||
159 | crc[4] = cmd[5]; | ||
160 | |||
161 | cmd[4] |= crc7(0, crc, WSPI_INIT_CMD_CRC_LEN) << 1; | ||
162 | cmd[4] |= WSPI_INIT_CMD_END; | ||
163 | |||
164 | t.tx_buf = cmd; | ||
165 | t.len = WSPI_INIT_CMD_LEN; | ||
166 | spi_message_add_tail(&t, &m); | ||
167 | |||
168 | spi_sync(wl_to_spi(wl), &m); | ||
169 | wl1271_dump(DEBUG_SPI, "spi init -> ", cmd, WSPI_INIT_CMD_LEN); | ||
170 | kfree(cmd); | ||
171 | } | ||
172 | |||
173 | #define WL1271_BUSY_WORD_TIMEOUT 1000 | ||
174 | |||
175 | static int wl1271_spi_read_busy(struct wl1271 *wl) | ||
176 | { | ||
177 | struct spi_transfer t[1]; | ||
178 | struct spi_message m; | ||
179 | u32 *busy_buf; | ||
180 | int num_busy_bytes = 0; | ||
181 | |||
182 | /* | ||
183 | * Read further busy words from SPI until a non-busy word is | ||
184 | * encountered, then read the data itself into the buffer. | ||
185 | */ | ||
186 | |||
187 | num_busy_bytes = WL1271_BUSY_WORD_TIMEOUT; | ||
188 | busy_buf = wl->buffer_busyword; | ||
189 | while (num_busy_bytes) { | ||
190 | num_busy_bytes--; | ||
191 | spi_message_init(&m); | ||
192 | memset(t, 0, sizeof(t)); | ||
193 | t[0].rx_buf = busy_buf; | ||
194 | t[0].len = sizeof(u32); | ||
195 | t[0].cs_change = true; | ||
196 | spi_message_add_tail(&t[0], &m); | ||
197 | spi_sync(wl_to_spi(wl), &m); | ||
198 | |||
199 | if (*busy_buf & 0x1) | ||
200 | return 0; | ||
201 | } | ||
202 | |||
203 | /* The SPI bus is unresponsive, the read failed. */ | ||
204 | wl1271_error("SPI read busy-word timeout!\n"); | ||
205 | return -ETIMEDOUT; | ||
206 | } | ||
207 | |||
208 | static void wl1271_spi_raw_read(struct wl1271 *wl, int addr, void *buf, | ||
209 | size_t len, bool fixed) | ||
210 | { | ||
211 | struct spi_transfer t[2]; | ||
212 | struct spi_message m; | ||
213 | u32 *busy_buf; | ||
214 | u32 *cmd; | ||
215 | u32 chunk_len; | ||
216 | |||
217 | while (len > 0) { | ||
218 | chunk_len = min((size_t)WSPI_MAX_CHUNK_SIZE, len); | ||
219 | |||
220 | cmd = &wl->buffer_cmd; | ||
221 | busy_buf = wl->buffer_busyword; | ||
222 | |||
223 | *cmd = 0; | ||
224 | *cmd |= WSPI_CMD_READ; | ||
225 | *cmd |= (chunk_len << WSPI_CMD_BYTE_LENGTH_OFFSET) & | ||
226 | WSPI_CMD_BYTE_LENGTH; | ||
227 | *cmd |= addr & WSPI_CMD_BYTE_ADDR; | ||
228 | |||
229 | if (fixed) | ||
230 | *cmd |= WSPI_CMD_FIXED; | ||
231 | |||
232 | spi_message_init(&m); | ||
233 | memset(t, 0, sizeof(t)); | ||
234 | |||
235 | t[0].tx_buf = cmd; | ||
236 | t[0].len = 4; | ||
237 | t[0].cs_change = true; | ||
238 | spi_message_add_tail(&t[0], &m); | ||
239 | |||
240 | /* Busy and non busy words read */ | ||
241 | t[1].rx_buf = busy_buf; | ||
242 | t[1].len = WL1271_BUSY_WORD_LEN; | ||
243 | t[1].cs_change = true; | ||
244 | spi_message_add_tail(&t[1], &m); | ||
245 | |||
246 | spi_sync(wl_to_spi(wl), &m); | ||
247 | |||
248 | if (!(busy_buf[WL1271_BUSY_WORD_CNT - 1] & 0x1) && | ||
249 | wl1271_spi_read_busy(wl)) { | ||
250 | memset(buf, 0, chunk_len); | ||
251 | return; | ||
252 | } | ||
253 | |||
254 | spi_message_init(&m); | ||
255 | memset(t, 0, sizeof(t)); | ||
256 | |||
257 | t[0].rx_buf = buf; | ||
258 | t[0].len = chunk_len; | ||
259 | t[0].cs_change = true; | ||
260 | spi_message_add_tail(&t[0], &m); | ||
261 | |||
262 | spi_sync(wl_to_spi(wl), &m); | ||
263 | |||
264 | wl1271_dump(DEBUG_SPI, "spi_read cmd -> ", cmd, sizeof(*cmd)); | ||
265 | wl1271_dump(DEBUG_SPI, "spi_read buf <- ", buf, chunk_len); | ||
266 | |||
267 | if (!fixed) | ||
268 | addr += chunk_len; | ||
269 | buf += chunk_len; | ||
270 | len -= chunk_len; | ||
271 | } | ||
272 | } | ||
273 | |||
274 | static void wl1271_spi_raw_write(struct wl1271 *wl, int addr, void *buf, | ||
275 | size_t len, bool fixed) | ||
276 | { | ||
277 | struct spi_transfer t[2 * WSPI_MAX_NUM_OF_CHUNKS]; | ||
278 | struct spi_message m; | ||
279 | u32 commands[WSPI_MAX_NUM_OF_CHUNKS]; | ||
280 | u32 *cmd; | ||
281 | u32 chunk_len; | ||
282 | int i; | ||
283 | |||
284 | WARN_ON(len > WL1271_AGGR_BUFFER_SIZE); | ||
285 | |||
286 | spi_message_init(&m); | ||
287 | memset(t, 0, sizeof(t)); | ||
288 | |||
289 | cmd = &commands[0]; | ||
290 | i = 0; | ||
291 | while (len > 0) { | ||
292 | chunk_len = min((size_t)WSPI_MAX_CHUNK_SIZE, len); | ||
293 | |||
294 | *cmd = 0; | ||
295 | *cmd |= WSPI_CMD_WRITE; | ||
296 | *cmd |= (chunk_len << WSPI_CMD_BYTE_LENGTH_OFFSET) & | ||
297 | WSPI_CMD_BYTE_LENGTH; | ||
298 | *cmd |= addr & WSPI_CMD_BYTE_ADDR; | ||
299 | |||
300 | if (fixed) | ||
301 | *cmd |= WSPI_CMD_FIXED; | ||
302 | |||
303 | t[i].tx_buf = cmd; | ||
304 | t[i].len = sizeof(*cmd); | ||
305 | spi_message_add_tail(&t[i++], &m); | ||
306 | |||
307 | t[i].tx_buf = buf; | ||
308 | t[i].len = chunk_len; | ||
309 | spi_message_add_tail(&t[i++], &m); | ||
310 | |||
311 | wl1271_dump(DEBUG_SPI, "spi_write cmd -> ", cmd, sizeof(*cmd)); | ||
312 | wl1271_dump(DEBUG_SPI, "spi_write buf -> ", buf, chunk_len); | ||
313 | |||
314 | if (!fixed) | ||
315 | addr += chunk_len; | ||
316 | buf += chunk_len; | ||
317 | len -= chunk_len; | ||
318 | cmd++; | ||
319 | } | ||
320 | |||
321 | spi_sync(wl_to_spi(wl), &m); | ||
322 | } | ||
323 | |||
324 | static irqreturn_t wl1271_hardirq(int irq, void *cookie) | ||
325 | { | ||
326 | struct wl1271 *wl = cookie; | ||
327 | unsigned long flags; | ||
328 | |||
329 | wl1271_debug(DEBUG_IRQ, "IRQ"); | ||
330 | |||
331 | /* complete the ELP completion */ | ||
332 | spin_lock_irqsave(&wl->wl_lock, flags); | ||
333 | set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags); | ||
334 | if (wl->elp_compl) { | ||
335 | complete(wl->elp_compl); | ||
336 | wl->elp_compl = NULL; | ||
337 | } | ||
338 | spin_unlock_irqrestore(&wl->wl_lock, flags); | ||
339 | |||
340 | return IRQ_WAKE_THREAD; | ||
341 | } | ||
342 | |||
343 | static int wl1271_spi_set_power(struct wl1271 *wl, bool enable) | ||
344 | { | ||
345 | if (wl->set_power) | ||
346 | wl->set_power(enable); | ||
347 | |||
348 | return 0; | ||
349 | } | ||
350 | |||
351 | static struct wl1271_if_operations spi_ops = { | ||
352 | .read = wl1271_spi_raw_read, | ||
353 | .write = wl1271_spi_raw_write, | ||
354 | .reset = wl1271_spi_reset, | ||
355 | .init = wl1271_spi_init, | ||
356 | .power = wl1271_spi_set_power, | ||
357 | .dev = wl1271_spi_wl_to_dev, | ||
358 | .enable_irq = wl1271_spi_enable_interrupts, | ||
359 | .disable_irq = wl1271_spi_disable_interrupts, | ||
360 | .set_block_size = NULL, | ||
361 | }; | ||
362 | |||
363 | static int __devinit wl1271_probe(struct spi_device *spi) | ||
364 | { | ||
365 | struct wl12xx_platform_data *pdata; | ||
366 | struct ieee80211_hw *hw; | ||
367 | struct wl1271 *wl; | ||
368 | unsigned long irqflags; | ||
369 | int ret; | ||
370 | |||
371 | pdata = spi->dev.platform_data; | ||
372 | if (!pdata) { | ||
373 | wl1271_error("no platform data"); | ||
374 | return -ENODEV; | ||
375 | } | ||
376 | |||
377 | hw = wl1271_alloc_hw(); | ||
378 | if (IS_ERR(hw)) | ||
379 | return PTR_ERR(hw); | ||
380 | |||
381 | wl = hw->priv; | ||
382 | |||
383 | dev_set_drvdata(&spi->dev, wl); | ||
384 | wl->if_priv = spi; | ||
385 | |||
386 | wl->if_ops = &spi_ops; | ||
387 | |||
388 | /* This is the only SPI value that we need to set here, the rest | ||
389 | * comes from the board-peripherals file */ | ||
390 | spi->bits_per_word = 32; | ||
391 | |||
392 | ret = spi_setup(spi); | ||
393 | if (ret < 0) { | ||
394 | wl1271_error("spi_setup failed"); | ||
395 | goto out_free; | ||
396 | } | ||
397 | |||
398 | wl->set_power = pdata->set_power; | ||
399 | if (!wl->set_power) { | ||
400 | wl1271_error("set power function missing in platform data"); | ||
401 | ret = -ENODEV; | ||
402 | goto out_free; | ||
403 | } | ||
404 | |||
405 | wl->ref_clock = pdata->board_ref_clock; | ||
406 | wl->tcxo_clock = pdata->board_tcxo_clock; | ||
407 | wl->platform_quirks = pdata->platform_quirks; | ||
408 | |||
409 | if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ) | ||
410 | irqflags = IRQF_TRIGGER_RISING; | ||
411 | else | ||
412 | irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT; | ||
413 | |||
414 | wl->irq = spi->irq; | ||
415 | if (wl->irq < 0) { | ||
416 | wl1271_error("irq missing in platform data"); | ||
417 | ret = -ENODEV; | ||
418 | goto out_free; | ||
419 | } | ||
420 | |||
421 | ret = request_threaded_irq(wl->irq, wl1271_hardirq, wl1271_irq, | ||
422 | irqflags, | ||
423 | DRIVER_NAME, wl); | ||
424 | if (ret < 0) { | ||
425 | wl1271_error("request_irq() failed: %d", ret); | ||
426 | goto out_free; | ||
427 | } | ||
428 | |||
429 | disable_irq(wl->irq); | ||
430 | |||
431 | ret = wl1271_init_ieee80211(wl); | ||
432 | if (ret) | ||
433 | goto out_irq; | ||
434 | |||
435 | ret = wl1271_register_hw(wl); | ||
436 | if (ret) | ||
437 | goto out_irq; | ||
438 | |||
439 | return 0; | ||
440 | |||
441 | out_irq: | ||
442 | free_irq(wl->irq, wl); | ||
443 | |||
444 | out_free: | ||
445 | wl1271_free_hw(wl); | ||
446 | |||
447 | return ret; | ||
448 | } | ||
449 | |||
450 | static int __devexit wl1271_remove(struct spi_device *spi) | ||
451 | { | ||
452 | struct wl1271 *wl = dev_get_drvdata(&spi->dev); | ||
453 | |||
454 | wl1271_unregister_hw(wl); | ||
455 | free_irq(wl->irq, wl); | ||
456 | wl1271_free_hw(wl); | ||
457 | |||
458 | return 0; | ||
459 | } | ||
460 | |||
461 | |||
462 | static struct spi_driver wl1271_spi_driver = { | ||
463 | .driver = { | ||
464 | .name = "wl1271_spi", | ||
465 | .bus = &spi_bus_type, | ||
466 | .owner = THIS_MODULE, | ||
467 | }, | ||
468 | |||
469 | .probe = wl1271_probe, | ||
470 | .remove = __devexit_p(wl1271_remove), | ||
471 | }; | ||
472 | |||
473 | static int __init wl1271_init(void) | ||
474 | { | ||
475 | return spi_register_driver(&wl1271_spi_driver); | ||
476 | } | ||
477 | |||
478 | static void __exit wl1271_exit(void) | ||
479 | { | ||
480 | spi_unregister_driver(&wl1271_spi_driver); | ||
481 | } | ||
482 | |||
483 | module_init(wl1271_init); | ||
484 | module_exit(wl1271_exit); | ||
485 | |||
486 | MODULE_LICENSE("GPL"); | ||
487 | MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>"); | ||
488 | MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>"); | ||
489 | MODULE_FIRMWARE(WL1271_FW_NAME); | ||
490 | MODULE_FIRMWARE(WL128X_FW_NAME); | ||
491 | MODULE_FIRMWARE(WL127X_AP_FW_NAME); | ||
492 | MODULE_FIRMWARE(WL128X_AP_FW_NAME); | ||
493 | MODULE_ALIAS("spi:wl1271"); | ||
diff --git a/drivers/net/wireless/wl12xx/testmode.c b/drivers/net/wireless/wl12xx/testmode.c new file mode 100644 index 00000000000..abfb120df11 --- /dev/null +++ b/drivers/net/wireless/wl12xx/testmode.c | |||
@@ -0,0 +1,256 @@ | |||
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 "wl12xx.h" | ||
29 | #include "acx.h" | ||
30 | #include "reg.h" | ||
31 | |||
32 | #define WL1271_TM_MAX_DATA_LENGTH 1024 | ||
33 | |||
34 | enum wl1271_tm_commands { | ||
35 | WL1271_TM_CMD_UNSPEC, | ||
36 | WL1271_TM_CMD_TEST, | ||
37 | WL1271_TM_CMD_INTERROGATE, | ||
38 | WL1271_TM_CMD_CONFIGURE, | ||
39 | WL1271_TM_CMD_NVS_PUSH, /* Not in use. Keep to not break ABI */ | ||
40 | WL1271_TM_CMD_SET_PLT_MODE, | ||
41 | WL1271_TM_CMD_RECOVER, | ||
42 | |||
43 | __WL1271_TM_CMD_AFTER_LAST | ||
44 | }; | ||
45 | #define WL1271_TM_CMD_MAX (__WL1271_TM_CMD_AFTER_LAST - 1) | ||
46 | |||
47 | enum wl1271_tm_attrs { | ||
48 | WL1271_TM_ATTR_UNSPEC, | ||
49 | WL1271_TM_ATTR_CMD_ID, | ||
50 | WL1271_TM_ATTR_ANSWER, | ||
51 | WL1271_TM_ATTR_DATA, | ||
52 | WL1271_TM_ATTR_IE_ID, | ||
53 | WL1271_TM_ATTR_PLT_MODE, | ||
54 | |||
55 | __WL1271_TM_ATTR_AFTER_LAST | ||
56 | }; | ||
57 | #define WL1271_TM_ATTR_MAX (__WL1271_TM_ATTR_AFTER_LAST - 1) | ||
58 | |||
59 | static struct nla_policy wl1271_tm_policy[WL1271_TM_ATTR_MAX + 1] = { | ||
60 | [WL1271_TM_ATTR_CMD_ID] = { .type = NLA_U32 }, | ||
61 | [WL1271_TM_ATTR_ANSWER] = { .type = NLA_U8 }, | ||
62 | [WL1271_TM_ATTR_DATA] = { .type = NLA_BINARY, | ||
63 | .len = WL1271_TM_MAX_DATA_LENGTH }, | ||
64 | [WL1271_TM_ATTR_IE_ID] = { .type = NLA_U32 }, | ||
65 | [WL1271_TM_ATTR_PLT_MODE] = { .type = NLA_U32 }, | ||
66 | }; | ||
67 | |||
68 | |||
69 | static int wl1271_tm_cmd_test(struct wl1271 *wl, struct nlattr *tb[]) | ||
70 | { | ||
71 | int buf_len, ret, len; | ||
72 | struct sk_buff *skb; | ||
73 | void *buf; | ||
74 | u8 answer = 0; | ||
75 | |||
76 | wl1271_debug(DEBUG_TESTMODE, "testmode cmd test"); | ||
77 | |||
78 | if (!tb[WL1271_TM_ATTR_DATA]) | ||
79 | return -EINVAL; | ||
80 | |||
81 | buf = nla_data(tb[WL1271_TM_ATTR_DATA]); | ||
82 | buf_len = nla_len(tb[WL1271_TM_ATTR_DATA]); | ||
83 | |||
84 | if (tb[WL1271_TM_ATTR_ANSWER]) | ||
85 | answer = nla_get_u8(tb[WL1271_TM_ATTR_ANSWER]); | ||
86 | |||
87 | if (buf_len > sizeof(struct wl1271_command)) | ||
88 | return -EMSGSIZE; | ||
89 | |||
90 | mutex_lock(&wl->mutex); | ||
91 | ret = wl1271_cmd_test(wl, buf, buf_len, answer); | ||
92 | mutex_unlock(&wl->mutex); | ||
93 | |||
94 | if (ret < 0) { | ||
95 | wl1271_warning("testmode cmd test failed: %d", ret); | ||
96 | return ret; | ||
97 | } | ||
98 | |||
99 | if (answer) { | ||
100 | len = nla_total_size(buf_len); | ||
101 | skb = cfg80211_testmode_alloc_reply_skb(wl->hw->wiphy, len); | ||
102 | if (!skb) | ||
103 | return -ENOMEM; | ||
104 | |||
105 | NLA_PUT(skb, WL1271_TM_ATTR_DATA, buf_len, buf); | ||
106 | ret = cfg80211_testmode_reply(skb); | ||
107 | if (ret < 0) | ||
108 | return ret; | ||
109 | } | ||
110 | |||
111 | return 0; | ||
112 | |||
113 | nla_put_failure: | ||
114 | kfree_skb(skb); | ||
115 | return -EMSGSIZE; | ||
116 | } | ||
117 | |||
118 | static int wl1271_tm_cmd_interrogate(struct wl1271 *wl, struct nlattr *tb[]) | ||
119 | { | ||
120 | int ret; | ||
121 | struct wl1271_command *cmd; | ||
122 | struct sk_buff *skb; | ||
123 | u8 ie_id; | ||
124 | |||
125 | wl1271_debug(DEBUG_TESTMODE, "testmode cmd interrogate"); | ||
126 | |||
127 | if (!tb[WL1271_TM_ATTR_IE_ID]) | ||
128 | return -EINVAL; | ||
129 | |||
130 | ie_id = nla_get_u8(tb[WL1271_TM_ATTR_IE_ID]); | ||
131 | |||
132 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | ||
133 | if (!cmd) | ||
134 | return -ENOMEM; | ||
135 | |||
136 | mutex_lock(&wl->mutex); | ||
137 | ret = wl1271_cmd_interrogate(wl, ie_id, cmd, sizeof(*cmd)); | ||
138 | mutex_unlock(&wl->mutex); | ||
139 | |||
140 | if (ret < 0) { | ||
141 | wl1271_warning("testmode cmd interrogate failed: %d", ret); | ||
142 | kfree(cmd); | ||
143 | return ret; | ||
144 | } | ||
145 | |||
146 | skb = cfg80211_testmode_alloc_reply_skb(wl->hw->wiphy, sizeof(*cmd)); | ||
147 | if (!skb) { | ||
148 | kfree(cmd); | ||
149 | return -ENOMEM; | ||
150 | } | ||
151 | |||
152 | NLA_PUT(skb, WL1271_TM_ATTR_DATA, sizeof(*cmd), cmd); | ||
153 | |||
154 | return 0; | ||
155 | |||
156 | nla_put_failure: | ||
157 | kfree_skb(skb); | ||
158 | return -EMSGSIZE; | ||
159 | } | ||
160 | |||
161 | static int wl1271_tm_cmd_configure(struct wl1271 *wl, struct nlattr *tb[]) | ||
162 | { | ||
163 | int buf_len, ret; | ||
164 | void *buf; | ||
165 | u8 ie_id; | ||
166 | |||
167 | wl1271_debug(DEBUG_TESTMODE, "testmode cmd configure"); | ||
168 | |||
169 | if (!tb[WL1271_TM_ATTR_DATA]) | ||
170 | return -EINVAL; | ||
171 | if (!tb[WL1271_TM_ATTR_IE_ID]) | ||
172 | return -EINVAL; | ||
173 | |||
174 | ie_id = nla_get_u8(tb[WL1271_TM_ATTR_IE_ID]); | ||
175 | buf = nla_data(tb[WL1271_TM_ATTR_DATA]); | ||
176 | buf_len = nla_len(tb[WL1271_TM_ATTR_DATA]); | ||
177 | |||
178 | if (buf_len > sizeof(struct wl1271_command)) | ||
179 | return -EMSGSIZE; | ||
180 | |||
181 | mutex_lock(&wl->mutex); | ||
182 | ret = wl1271_cmd_configure(wl, ie_id, buf, buf_len); | ||
183 | mutex_unlock(&wl->mutex); | ||
184 | |||
185 | if (ret < 0) { | ||
186 | wl1271_warning("testmode cmd configure failed: %d", ret); | ||
187 | return ret; | ||
188 | } | ||
189 | |||
190 | return 0; | ||
191 | } | ||
192 | |||
193 | static int wl1271_tm_cmd_set_plt_mode(struct wl1271 *wl, struct nlattr *tb[]) | ||
194 | { | ||
195 | u32 val; | ||
196 | int ret; | ||
197 | |||
198 | wl1271_debug(DEBUG_TESTMODE, "testmode cmd set plt mode"); | ||
199 | |||
200 | if (!tb[WL1271_TM_ATTR_PLT_MODE]) | ||
201 | return -EINVAL; | ||
202 | |||
203 | val = nla_get_u32(tb[WL1271_TM_ATTR_PLT_MODE]); | ||
204 | |||
205 | switch (val) { | ||
206 | case 0: | ||
207 | ret = wl1271_plt_stop(wl); | ||
208 | break; | ||
209 | case 1: | ||
210 | ret = wl1271_plt_start(wl); | ||
211 | break; | ||
212 | default: | ||
213 | ret = -EINVAL; | ||
214 | break; | ||
215 | } | ||
216 | |||
217 | return ret; | ||
218 | } | ||
219 | |||
220 | static int wl1271_tm_cmd_recover(struct wl1271 *wl, struct nlattr *tb[]) | ||
221 | { | ||
222 | wl1271_debug(DEBUG_TESTMODE, "testmode cmd recover"); | ||
223 | |||
224 | wl12xx_queue_recovery_work(wl); | ||
225 | |||
226 | return 0; | ||
227 | } | ||
228 | |||
229 | int wl1271_tm_cmd(struct ieee80211_hw *hw, void *data, int len) | ||
230 | { | ||
231 | struct wl1271 *wl = hw->priv; | ||
232 | struct nlattr *tb[WL1271_TM_ATTR_MAX + 1]; | ||
233 | int err; | ||
234 | |||
235 | err = nla_parse(tb, WL1271_TM_ATTR_MAX, data, len, wl1271_tm_policy); | ||
236 | if (err) | ||
237 | return err; | ||
238 | |||
239 | if (!tb[WL1271_TM_ATTR_CMD_ID]) | ||
240 | return -EINVAL; | ||
241 | |||
242 | switch (nla_get_u32(tb[WL1271_TM_ATTR_CMD_ID])) { | ||
243 | case WL1271_TM_CMD_TEST: | ||
244 | return wl1271_tm_cmd_test(wl, tb); | ||
245 | case WL1271_TM_CMD_INTERROGATE: | ||
246 | return wl1271_tm_cmd_interrogate(wl, tb); | ||
247 | case WL1271_TM_CMD_CONFIGURE: | ||
248 | return wl1271_tm_cmd_configure(wl, tb); | ||
249 | case WL1271_TM_CMD_SET_PLT_MODE: | ||
250 | return wl1271_tm_cmd_set_plt_mode(wl, tb); | ||
251 | case WL1271_TM_CMD_RECOVER: | ||
252 | return wl1271_tm_cmd_recover(wl, tb); | ||
253 | default: | ||
254 | return -EOPNOTSUPP; | ||
255 | } | ||
256 | } | ||
diff --git a/drivers/net/wireless/wl12xx/testmode.h b/drivers/net/wireless/wl12xx/testmode.h new file mode 100644 index 00000000000..8071654259e --- /dev/null +++ b/drivers/net/wireless/wl12xx/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 | |||
29 | int wl1271_tm_cmd(struct ieee80211_hw *hw, void *data, int len); | ||
30 | |||
31 | #endif /* __WL1271_TESTMODE_H__ */ | ||
diff --git a/drivers/net/wireless/wl12xx/tx.c b/drivers/net/wireless/wl12xx/tx.c new file mode 100644 index 00000000000..48fde96ce0d --- /dev/null +++ b/drivers/net/wireless/wl12xx/tx.c | |||
@@ -0,0 +1,961 @@ | |||
1 | /* | ||
2 | * This file is part of wl1271 | ||
3 | * | ||
4 | * Copyright (C) 2009 Nokia Corporation | ||
5 | * | ||
6 | * Contact: Luciano Coelho <luciano.coelho@nokia.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU General Public License | ||
10 | * version 2 as published by the Free Software Foundation. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, but | ||
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
20 | * 02110-1301 USA | ||
21 | * | ||
22 | */ | ||
23 | |||
24 | #include <linux/kernel.h> | ||
25 | #include <linux/module.h> | ||
26 | #include <linux/etherdevice.h> | ||
27 | |||
28 | #include "wl12xx.h" | ||
29 | #include "io.h" | ||
30 | #include "reg.h" | ||
31 | #include "ps.h" | ||
32 | #include "tx.h" | ||
33 | |||
34 | static int wl1271_set_default_wep_key(struct wl1271 *wl, u8 id) | ||
35 | { | ||
36 | int ret; | ||
37 | bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS); | ||
38 | |||
39 | if (is_ap) | ||
40 | ret = wl1271_cmd_set_ap_default_wep_key(wl, id); | ||
41 | else | ||
42 | ret = wl1271_cmd_set_sta_default_wep_key(wl, id); | ||
43 | |||
44 | if (ret < 0) | ||
45 | return ret; | ||
46 | |||
47 | wl1271_debug(DEBUG_CRYPT, "default wep key idx: %d", (int)id); | ||
48 | return 0; | ||
49 | } | ||
50 | |||
51 | static int wl1271_alloc_tx_id(struct wl1271 *wl, struct sk_buff *skb) | ||
52 | { | ||
53 | int id; | ||
54 | |||
55 | id = find_first_zero_bit(wl->tx_frames_map, ACX_TX_DESCRIPTORS); | ||
56 | if (id >= ACX_TX_DESCRIPTORS) | ||
57 | return -EBUSY; | ||
58 | |||
59 | __set_bit(id, wl->tx_frames_map); | ||
60 | wl->tx_frames[id] = skb; | ||
61 | wl->tx_frames_cnt++; | ||
62 | return id; | ||
63 | } | ||
64 | |||
65 | static void wl1271_free_tx_id(struct wl1271 *wl, int id) | ||
66 | { | ||
67 | if (__test_and_clear_bit(id, wl->tx_frames_map)) { | ||
68 | if (unlikely(wl->tx_frames_cnt == ACX_TX_DESCRIPTORS)) | ||
69 | clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags); | ||
70 | |||
71 | wl->tx_frames[id] = NULL; | ||
72 | wl->tx_frames_cnt--; | ||
73 | } | ||
74 | } | ||
75 | |||
76 | static int wl1271_tx_update_filters(struct wl1271 *wl, | ||
77 | struct sk_buff *skb) | ||
78 | { | ||
79 | struct ieee80211_hdr *hdr; | ||
80 | |||
81 | hdr = (struct ieee80211_hdr *)(skb->data + | ||
82 | sizeof(struct wl1271_tx_hw_descr)); | ||
83 | |||
84 | /* | ||
85 | * stop bssid-based filtering before transmitting authentication | ||
86 | * requests. this way the hw will never drop authentication | ||
87 | * responses coming from BSSIDs it isn't familiar with (e.g. on | ||
88 | * roaming) | ||
89 | */ | ||
90 | if (!ieee80211_is_auth(hdr->frame_control)) | ||
91 | return 0; | ||
92 | |||
93 | wl1271_configure_filters(wl, FIF_OTHER_BSS); | ||
94 | |||
95 | return wl1271_acx_rx_config(wl, wl->rx_config, wl->rx_filter); | ||
96 | } | ||
97 | |||
98 | static void wl1271_tx_ap_update_inconnection_sta(struct wl1271 *wl, | ||
99 | struct sk_buff *skb) | ||
100 | { | ||
101 | struct ieee80211_hdr *hdr; | ||
102 | |||
103 | /* | ||
104 | * add the station to the known list before transmitting the | ||
105 | * authentication response. this way it won't get de-authed by FW | ||
106 | * when transmitting too soon. | ||
107 | */ | ||
108 | hdr = (struct ieee80211_hdr *)(skb->data + | ||
109 | sizeof(struct wl1271_tx_hw_descr)); | ||
110 | if (ieee80211_is_auth(hdr->frame_control)) | ||
111 | wl1271_acx_set_inconnection_sta(wl, hdr->addr1); | ||
112 | } | ||
113 | |||
114 | static void wl1271_tx_regulate_link(struct wl1271 *wl, u8 hlid) | ||
115 | { | ||
116 | bool fw_ps; | ||
117 | u8 tx_blks; | ||
118 | |||
119 | /* only regulate station links */ | ||
120 | if (hlid < WL1271_AP_STA_HLID_START) | ||
121 | return; | ||
122 | |||
123 | fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map); | ||
124 | tx_blks = wl->links[hlid].allocated_blks; | ||
125 | |||
126 | /* | ||
127 | * if in FW PS and there is enough data in FW we can put the link | ||
128 | * into high-level PS and clean out its TX queues. | ||
129 | */ | ||
130 | if (fw_ps && tx_blks >= WL1271_PS_STA_MAX_BLOCKS) | ||
131 | wl1271_ps_link_start(wl, hlid, true); | ||
132 | } | ||
133 | |||
134 | u8 wl1271_tx_get_hlid(struct sk_buff *skb) | ||
135 | { | ||
136 | struct ieee80211_tx_info *control = IEEE80211_SKB_CB(skb); | ||
137 | |||
138 | if (control->control.sta) { | ||
139 | struct wl1271_station *wl_sta; | ||
140 | |||
141 | wl_sta = (struct wl1271_station *) | ||
142 | control->control.sta->drv_priv; | ||
143 | return wl_sta->hlid; | ||
144 | } else { | ||
145 | struct ieee80211_hdr *hdr; | ||
146 | |||
147 | hdr = (struct ieee80211_hdr *)skb->data; | ||
148 | if (ieee80211_is_mgmt(hdr->frame_control)) | ||
149 | return WL1271_AP_GLOBAL_HLID; | ||
150 | else | ||
151 | return WL1271_AP_BROADCAST_HLID; | ||
152 | } | ||
153 | } | ||
154 | |||
155 | static unsigned int wl12xx_calc_packet_alignment(struct wl1271 *wl, | ||
156 | unsigned int packet_length) | ||
157 | { | ||
158 | if (wl->quirks & WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT) | ||
159 | return ALIGN(packet_length, WL12XX_BUS_BLOCK_SIZE); | ||
160 | else | ||
161 | return ALIGN(packet_length, WL1271_TX_ALIGN_TO); | ||
162 | } | ||
163 | |||
164 | static int wl1271_tx_allocate(struct wl1271 *wl, struct sk_buff *skb, u32 extra, | ||
165 | u32 buf_offset, u8 hlid) | ||
166 | { | ||
167 | struct wl1271_tx_hw_descr *desc; | ||
168 | u32 total_len = skb->len + sizeof(struct wl1271_tx_hw_descr) + extra; | ||
169 | u32 len; | ||
170 | u32 total_blocks; | ||
171 | int id, ret = -EBUSY, ac; | ||
172 | u32 spare_blocks; | ||
173 | |||
174 | if (unlikely(wl->quirks & WL12XX_QUIRK_USE_2_SPARE_BLOCKS)) | ||
175 | spare_blocks = 2; | ||
176 | else | ||
177 | spare_blocks = 1; | ||
178 | |||
179 | if (buf_offset + total_len > WL1271_AGGR_BUFFER_SIZE) | ||
180 | return -EAGAIN; | ||
181 | |||
182 | /* allocate free identifier for the packet */ | ||
183 | id = wl1271_alloc_tx_id(wl, skb); | ||
184 | if (id < 0) | ||
185 | return id; | ||
186 | |||
187 | /* approximate the number of blocks required for this packet | ||
188 | in the firmware */ | ||
189 | len = wl12xx_calc_packet_alignment(wl, total_len); | ||
190 | |||
191 | total_blocks = (len + TX_HW_BLOCK_SIZE - 1) / TX_HW_BLOCK_SIZE + | ||
192 | spare_blocks; | ||
193 | |||
194 | if (total_blocks <= wl->tx_blocks_available) { | ||
195 | desc = (struct wl1271_tx_hw_descr *)skb_push( | ||
196 | skb, total_len - skb->len); | ||
197 | |||
198 | /* HW descriptor fields change between wl127x and wl128x */ | ||
199 | if (wl->chip.id == CHIP_ID_1283_PG20) { | ||
200 | desc->wl128x_mem.total_mem_blocks = total_blocks; | ||
201 | } else { | ||
202 | desc->wl127x_mem.extra_blocks = spare_blocks; | ||
203 | desc->wl127x_mem.total_mem_blocks = total_blocks; | ||
204 | } | ||
205 | |||
206 | desc->id = id; | ||
207 | |||
208 | wl->tx_blocks_available -= total_blocks; | ||
209 | |||
210 | ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); | ||
211 | wl->tx_allocated_blocks[ac] += total_blocks; | ||
212 | |||
213 | if (wl->bss_type == BSS_TYPE_AP_BSS) | ||
214 | wl->links[hlid].allocated_blks += total_blocks; | ||
215 | |||
216 | ret = 0; | ||
217 | |||
218 | wl1271_debug(DEBUG_TX, | ||
219 | "tx_allocate: size: %d, blocks: %d, id: %d", | ||
220 | total_len, total_blocks, id); | ||
221 | } else { | ||
222 | wl1271_free_tx_id(wl, id); | ||
223 | } | ||
224 | |||
225 | return ret; | ||
226 | } | ||
227 | |||
228 | static bool wl12xx_is_dummy_packet(struct wl1271 *wl, struct sk_buff *skb) | ||
229 | { | ||
230 | return wl->dummy_packet == skb; | ||
231 | } | ||
232 | |||
233 | static void wl1271_tx_fill_hdr(struct wl1271 *wl, struct sk_buff *skb, | ||
234 | u32 extra, struct ieee80211_tx_info *control, | ||
235 | u8 hlid) | ||
236 | { | ||
237 | struct timespec ts; | ||
238 | struct wl1271_tx_hw_descr *desc; | ||
239 | int aligned_len, ac, rate_idx; | ||
240 | s64 hosttime; | ||
241 | u16 tx_attr; | ||
242 | |||
243 | desc = (struct wl1271_tx_hw_descr *) skb->data; | ||
244 | |||
245 | /* relocate space for security header */ | ||
246 | if (extra) { | ||
247 | void *framestart = skb->data + sizeof(*desc); | ||
248 | u16 fc = *(u16 *)(framestart + extra); | ||
249 | int hdrlen = ieee80211_hdrlen(cpu_to_le16(fc)); | ||
250 | memmove(framestart, framestart + extra, hdrlen); | ||
251 | } | ||
252 | |||
253 | /* configure packet life time */ | ||
254 | getnstimeofday(&ts); | ||
255 | hosttime = (timespec_to_ns(&ts) >> 10); | ||
256 | desc->start_time = cpu_to_le32(hosttime - wl->time_offset); | ||
257 | |||
258 | if (wl->bss_type != BSS_TYPE_AP_BSS) | ||
259 | desc->life_time = cpu_to_le16(TX_HW_MGMT_PKT_LIFETIME_TU); | ||
260 | else | ||
261 | desc->life_time = cpu_to_le16(TX_HW_AP_MODE_PKT_LIFETIME_TU); | ||
262 | |||
263 | /* queue */ | ||
264 | ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); | ||
265 | desc->tid = skb->priority; | ||
266 | |||
267 | if (wl12xx_is_dummy_packet(wl, skb)) { | ||
268 | /* | ||
269 | * FW expects the dummy packet to have an invalid session id - | ||
270 | * any session id that is different than the one set in the join | ||
271 | */ | ||
272 | tx_attr = ((~wl->session_counter) << | ||
273 | TX_HW_ATTR_OFST_SESSION_COUNTER) & | ||
274 | TX_HW_ATTR_SESSION_COUNTER; | ||
275 | |||
276 | tx_attr |= TX_HW_ATTR_TX_DUMMY_REQ; | ||
277 | } else { | ||
278 | /* configure the tx attributes */ | ||
279 | tx_attr = | ||
280 | wl->session_counter << TX_HW_ATTR_OFST_SESSION_COUNTER; | ||
281 | } | ||
282 | |||
283 | if (wl->bss_type != BSS_TYPE_AP_BSS) { | ||
284 | desc->aid = hlid; | ||
285 | |||
286 | /* if the packets are destined for AP (have a STA entry) | ||
287 | send them with AP rate policies, otherwise use default | ||
288 | basic rates */ | ||
289 | if (control->control.sta) | ||
290 | rate_idx = ACX_TX_AP_FULL_RATE; | ||
291 | else | ||
292 | rate_idx = ACX_TX_BASIC_RATE; | ||
293 | } else { | ||
294 | desc->hlid = hlid; | ||
295 | switch (hlid) { | ||
296 | case WL1271_AP_GLOBAL_HLID: | ||
297 | rate_idx = ACX_TX_AP_MODE_MGMT_RATE; | ||
298 | break; | ||
299 | case WL1271_AP_BROADCAST_HLID: | ||
300 | rate_idx = ACX_TX_AP_MODE_BCST_RATE; | ||
301 | break; | ||
302 | default: | ||
303 | rate_idx = ac; | ||
304 | break; | ||
305 | } | ||
306 | } | ||
307 | |||
308 | tx_attr |= rate_idx << TX_HW_ATTR_OFST_RATE_POLICY; | ||
309 | desc->reserved = 0; | ||
310 | |||
311 | aligned_len = wl12xx_calc_packet_alignment(wl, skb->len); | ||
312 | |||
313 | if (wl->chip.id == CHIP_ID_1283_PG20) { | ||
314 | desc->wl128x_mem.extra_bytes = aligned_len - skb->len; | ||
315 | desc->length = cpu_to_le16(aligned_len >> 2); | ||
316 | |||
317 | wl1271_debug(DEBUG_TX, "tx_fill_hdr: hlid: %d " | ||
318 | "tx_attr: 0x%x len: %d life: %d mem: %d", | ||
319 | desc->hlid, tx_attr, | ||
320 | le16_to_cpu(desc->length), | ||
321 | le16_to_cpu(desc->life_time), | ||
322 | desc->wl128x_mem.total_mem_blocks); | ||
323 | } else { | ||
324 | int pad; | ||
325 | |||
326 | /* Store the aligned length in terms of words */ | ||
327 | desc->length = cpu_to_le16(aligned_len >> 2); | ||
328 | |||
329 | /* calculate number of padding bytes */ | ||
330 | pad = aligned_len - skb->len; | ||
331 | tx_attr |= pad << TX_HW_ATTR_OFST_LAST_WORD_PAD; | ||
332 | |||
333 | wl1271_debug(DEBUG_TX, "tx_fill_hdr: pad: %d hlid: %d " | ||
334 | "tx_attr: 0x%x len: %d life: %d mem: %d", pad, | ||
335 | desc->hlid, tx_attr, | ||
336 | le16_to_cpu(desc->length), | ||
337 | le16_to_cpu(desc->life_time), | ||
338 | desc->wl127x_mem.total_mem_blocks); | ||
339 | } | ||
340 | |||
341 | desc->tx_attr = cpu_to_le16(tx_attr); | ||
342 | } | ||
343 | |||
344 | /* caller must hold wl->mutex */ | ||
345 | static int wl1271_prepare_tx_frame(struct wl1271 *wl, struct sk_buff *skb, | ||
346 | u32 buf_offset) | ||
347 | { | ||
348 | struct ieee80211_tx_info *info; | ||
349 | u32 extra = 0; | ||
350 | int ret = 0; | ||
351 | u32 total_len; | ||
352 | u8 hlid; | ||
353 | |||
354 | if (!skb) | ||
355 | return -EINVAL; | ||
356 | |||
357 | info = IEEE80211_SKB_CB(skb); | ||
358 | |||
359 | if (info->control.hw_key && | ||
360 | info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) | ||
361 | extra = WL1271_TKIP_IV_SPACE; | ||
362 | |||
363 | if (info->control.hw_key) { | ||
364 | bool is_wep; | ||
365 | u8 idx = info->control.hw_key->hw_key_idx; | ||
366 | u32 cipher = info->control.hw_key->cipher; | ||
367 | |||
368 | is_wep = (cipher == WLAN_CIPHER_SUITE_WEP40) || | ||
369 | (cipher == WLAN_CIPHER_SUITE_WEP104); | ||
370 | |||
371 | if (unlikely(is_wep && wl->default_key != idx)) { | ||
372 | ret = wl1271_set_default_wep_key(wl, idx); | ||
373 | if (ret < 0) | ||
374 | return ret; | ||
375 | wl->default_key = idx; | ||
376 | } | ||
377 | } | ||
378 | |||
379 | if (wl->bss_type == BSS_TYPE_AP_BSS) | ||
380 | hlid = wl1271_tx_get_hlid(skb); | ||
381 | else | ||
382 | hlid = TX_HW_DEFAULT_AID; | ||
383 | |||
384 | ret = wl1271_tx_allocate(wl, skb, extra, buf_offset, hlid); | ||
385 | if (ret < 0) | ||
386 | return ret; | ||
387 | |||
388 | wl1271_tx_fill_hdr(wl, skb, extra, info, hlid); | ||
389 | |||
390 | if (wl->bss_type == BSS_TYPE_AP_BSS) { | ||
391 | wl1271_tx_ap_update_inconnection_sta(wl, skb); | ||
392 | wl1271_tx_regulate_link(wl, hlid); | ||
393 | } else { | ||
394 | wl1271_tx_update_filters(wl, skb); | ||
395 | } | ||
396 | |||
397 | /* | ||
398 | * The length of each packet is stored in terms of | ||
399 | * words. Thus, we must pad the skb data to make sure its | ||
400 | * length is aligned. The number of padding bytes is computed | ||
401 | * and set in wl1271_tx_fill_hdr. | ||
402 | * In special cases, we want to align to a specific block size | ||
403 | * (eg. for wl128x with SDIO we align to 256). | ||
404 | */ | ||
405 | total_len = wl12xx_calc_packet_alignment(wl, skb->len); | ||
406 | |||
407 | memcpy(wl->aggr_buf + buf_offset, skb->data, skb->len); | ||
408 | memset(wl->aggr_buf + buf_offset + skb->len, 0, total_len - skb->len); | ||
409 | |||
410 | /* Revert side effects in the dummy packet skb, so it can be reused */ | ||
411 | if (wl12xx_is_dummy_packet(wl, skb)) | ||
412 | skb_pull(skb, sizeof(struct wl1271_tx_hw_descr)); | ||
413 | |||
414 | return total_len; | ||
415 | } | ||
416 | |||
417 | u32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set) | ||
418 | { | ||
419 | struct ieee80211_supported_band *band; | ||
420 | u32 enabled_rates = 0; | ||
421 | int bit; | ||
422 | |||
423 | band = wl->hw->wiphy->bands[wl->band]; | ||
424 | for (bit = 0; bit < band->n_bitrates; bit++) { | ||
425 | if (rate_set & 0x1) | ||
426 | enabled_rates |= band->bitrates[bit].hw_value; | ||
427 | rate_set >>= 1; | ||
428 | } | ||
429 | |||
430 | #ifdef CONFIG_WL12XX_HT | ||
431 | /* MCS rates indication are on bits 16 - 23 */ | ||
432 | rate_set >>= HW_HT_RATES_OFFSET - band->n_bitrates; | ||
433 | |||
434 | for (bit = 0; bit < 8; bit++) { | ||
435 | if (rate_set & 0x1) | ||
436 | enabled_rates |= (CONF_HW_BIT_RATE_MCS_0 << bit); | ||
437 | rate_set >>= 1; | ||
438 | } | ||
439 | #endif | ||
440 | |||
441 | return enabled_rates; | ||
442 | } | ||
443 | |||
444 | void wl1271_handle_tx_low_watermark(struct wl1271 *wl) | ||
445 | { | ||
446 | unsigned long flags; | ||
447 | int i; | ||
448 | |||
449 | for (i = 0; i < NUM_TX_QUEUES; i++) { | ||
450 | if (test_bit(i, &wl->stopped_queues_map) && | ||
451 | wl->tx_queue_count[i] <= WL1271_TX_QUEUE_LOW_WATERMARK) { | ||
452 | /* firmware buffer has space, restart queues */ | ||
453 | spin_lock_irqsave(&wl->wl_lock, flags); | ||
454 | ieee80211_wake_queue(wl->hw, | ||
455 | wl1271_tx_get_mac80211_queue(i)); | ||
456 | clear_bit(i, &wl->stopped_queues_map); | ||
457 | spin_unlock_irqrestore(&wl->wl_lock, flags); | ||
458 | } | ||
459 | } | ||
460 | } | ||
461 | |||
462 | static struct sk_buff_head *wl1271_select_queue(struct wl1271 *wl, | ||
463 | struct sk_buff_head *queues) | ||
464 | { | ||
465 | int i, q = -1; | ||
466 | u32 min_blks = 0xffffffff; | ||
467 | |||
468 | /* | ||
469 | * Find a non-empty ac where: | ||
470 | * 1. There are packets to transmit | ||
471 | * 2. The FW has the least allocated blocks | ||
472 | */ | ||
473 | for (i = 0; i < NUM_TX_QUEUES; i++) | ||
474 | if (!skb_queue_empty(&queues[i]) && | ||
475 | (wl->tx_allocated_blocks[i] < min_blks)) { | ||
476 | q = i; | ||
477 | min_blks = wl->tx_allocated_blocks[q]; | ||
478 | } | ||
479 | |||
480 | if (q == -1) | ||
481 | return NULL; | ||
482 | |||
483 | return &queues[q]; | ||
484 | } | ||
485 | |||
486 | static struct sk_buff *wl1271_sta_skb_dequeue(struct wl1271 *wl) | ||
487 | { | ||
488 | struct sk_buff *skb = NULL; | ||
489 | unsigned long flags; | ||
490 | struct sk_buff_head *queue; | ||
491 | |||
492 | queue = wl1271_select_queue(wl, wl->tx_queue); | ||
493 | if (!queue) | ||
494 | goto out; | ||
495 | |||
496 | skb = skb_dequeue(queue); | ||
497 | |||
498 | out: | ||
499 | if (skb) { | ||
500 | int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); | ||
501 | spin_lock_irqsave(&wl->wl_lock, flags); | ||
502 | wl->tx_queue_count[q]--; | ||
503 | spin_unlock_irqrestore(&wl->wl_lock, flags); | ||
504 | } | ||
505 | |||
506 | return skb; | ||
507 | } | ||
508 | |||
509 | static struct sk_buff *wl1271_ap_skb_dequeue(struct wl1271 *wl) | ||
510 | { | ||
511 | struct sk_buff *skb = NULL; | ||
512 | unsigned long flags; | ||
513 | int i, h, start_hlid; | ||
514 | struct sk_buff_head *queue; | ||
515 | |||
516 | /* start from the link after the last one */ | ||
517 | start_hlid = (wl->last_tx_hlid + 1) % AP_MAX_LINKS; | ||
518 | |||
519 | /* dequeue according to AC, round robin on each link */ | ||
520 | for (i = 0; i < AP_MAX_LINKS; i++) { | ||
521 | h = (start_hlid + i) % AP_MAX_LINKS; | ||
522 | |||
523 | /* only consider connected stations */ | ||
524 | if (h >= WL1271_AP_STA_HLID_START && | ||
525 | !test_bit(h - WL1271_AP_STA_HLID_START, wl->ap_hlid_map)) | ||
526 | continue; | ||
527 | |||
528 | queue = wl1271_select_queue(wl, wl->links[h].tx_queue); | ||
529 | if (!queue) | ||
530 | continue; | ||
531 | |||
532 | skb = skb_dequeue(queue); | ||
533 | if (skb) | ||
534 | break; | ||
535 | } | ||
536 | |||
537 | if (skb) { | ||
538 | int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); | ||
539 | wl->last_tx_hlid = h; | ||
540 | spin_lock_irqsave(&wl->wl_lock, flags); | ||
541 | wl->tx_queue_count[q]--; | ||
542 | spin_unlock_irqrestore(&wl->wl_lock, flags); | ||
543 | } else { | ||
544 | wl->last_tx_hlid = 0; | ||
545 | } | ||
546 | |||
547 | return skb; | ||
548 | } | ||
549 | |||
550 | static struct sk_buff *wl1271_skb_dequeue(struct wl1271 *wl) | ||
551 | { | ||
552 | unsigned long flags; | ||
553 | struct sk_buff *skb = NULL; | ||
554 | |||
555 | if (wl->bss_type == BSS_TYPE_AP_BSS) | ||
556 | skb = wl1271_ap_skb_dequeue(wl); | ||
557 | else | ||
558 | skb = wl1271_sta_skb_dequeue(wl); | ||
559 | |||
560 | if (!skb && | ||
561 | test_and_clear_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags)) { | ||
562 | int q; | ||
563 | |||
564 | skb = wl->dummy_packet; | ||
565 | q = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); | ||
566 | spin_lock_irqsave(&wl->wl_lock, flags); | ||
567 | wl->tx_queue_count[q]--; | ||
568 | spin_unlock_irqrestore(&wl->wl_lock, flags); | ||
569 | } | ||
570 | |||
571 | return skb; | ||
572 | } | ||
573 | |||
574 | static void wl1271_skb_queue_head(struct wl1271 *wl, struct sk_buff *skb) | ||
575 | { | ||
576 | unsigned long flags; | ||
577 | int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); | ||
578 | |||
579 | if (wl12xx_is_dummy_packet(wl, skb)) { | ||
580 | set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags); | ||
581 | } else if (wl->bss_type == BSS_TYPE_AP_BSS) { | ||
582 | u8 hlid = wl1271_tx_get_hlid(skb); | ||
583 | skb_queue_head(&wl->links[hlid].tx_queue[q], skb); | ||
584 | |||
585 | /* make sure we dequeue the same packet next time */ | ||
586 | wl->last_tx_hlid = (hlid + AP_MAX_LINKS - 1) % AP_MAX_LINKS; | ||
587 | } else { | ||
588 | skb_queue_head(&wl->tx_queue[q], skb); | ||
589 | } | ||
590 | |||
591 | spin_lock_irqsave(&wl->wl_lock, flags); | ||
592 | wl->tx_queue_count[q]++; | ||
593 | spin_unlock_irqrestore(&wl->wl_lock, flags); | ||
594 | } | ||
595 | |||
596 | static bool wl1271_tx_is_data_present(struct sk_buff *skb) | ||
597 | { | ||
598 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data); | ||
599 | |||
600 | return ieee80211_is_data_present(hdr->frame_control); | ||
601 | } | ||
602 | |||
603 | void wl1271_tx_work_locked(struct wl1271 *wl) | ||
604 | { | ||
605 | struct sk_buff *skb; | ||
606 | u32 buf_offset = 0; | ||
607 | bool sent_packets = false; | ||
608 | bool had_data = false; | ||
609 | bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS); | ||
610 | int ret; | ||
611 | |||
612 | if (unlikely(wl->state == WL1271_STATE_OFF)) | ||
613 | return; | ||
614 | |||
615 | while ((skb = wl1271_skb_dequeue(wl))) { | ||
616 | if (wl1271_tx_is_data_present(skb)) | ||
617 | had_data = true; | ||
618 | |||
619 | ret = wl1271_prepare_tx_frame(wl, skb, buf_offset); | ||
620 | if (ret == -EAGAIN) { | ||
621 | /* | ||
622 | * Aggregation buffer is full. | ||
623 | * Flush buffer and try again. | ||
624 | */ | ||
625 | wl1271_skb_queue_head(wl, skb); | ||
626 | wl1271_write(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf, | ||
627 | buf_offset, true); | ||
628 | sent_packets = true; | ||
629 | buf_offset = 0; | ||
630 | continue; | ||
631 | } else if (ret == -EBUSY) { | ||
632 | /* | ||
633 | * Firmware buffer is full. | ||
634 | * Queue back last skb, and stop aggregating. | ||
635 | */ | ||
636 | wl1271_skb_queue_head(wl, skb); | ||
637 | /* No work left, avoid scheduling redundant tx work */ | ||
638 | set_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags); | ||
639 | goto out_ack; | ||
640 | } else if (ret < 0) { | ||
641 | dev_kfree_skb(skb); | ||
642 | goto out_ack; | ||
643 | } | ||
644 | buf_offset += ret; | ||
645 | wl->tx_packets_count++; | ||
646 | } | ||
647 | |||
648 | out_ack: | ||
649 | if (buf_offset) { | ||
650 | wl1271_write(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf, | ||
651 | buf_offset, true); | ||
652 | sent_packets = true; | ||
653 | } | ||
654 | if (sent_packets) { | ||
655 | /* | ||
656 | * Interrupt the firmware with the new packets. This is only | ||
657 | * required for older hardware revisions | ||
658 | */ | ||
659 | if (wl->quirks & WL12XX_QUIRK_END_OF_TRANSACTION) | ||
660 | wl1271_write32(wl, WL1271_HOST_WR_ACCESS, | ||
661 | wl->tx_packets_count); | ||
662 | |||
663 | wl1271_handle_tx_low_watermark(wl); | ||
664 | } | ||
665 | if (!is_ap && wl->conf.rx_streaming.interval && had_data && | ||
666 | (wl->conf.rx_streaming.always || | ||
667 | test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))) { | ||
668 | u32 timeout = wl->conf.rx_streaming.duration; | ||
669 | |||
670 | /* enable rx streaming */ | ||
671 | if (!test_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags)) | ||
672 | ieee80211_queue_work(wl->hw, | ||
673 | &wl->rx_streaming_enable_work); | ||
674 | |||
675 | mod_timer(&wl->rx_streaming_timer, | ||
676 | jiffies + msecs_to_jiffies(timeout)); | ||
677 | } | ||
678 | } | ||
679 | |||
680 | void wl1271_tx_work(struct work_struct *work) | ||
681 | { | ||
682 | struct wl1271 *wl = container_of(work, struct wl1271, tx_work); | ||
683 | int ret; | ||
684 | |||
685 | mutex_lock(&wl->mutex); | ||
686 | ret = wl1271_ps_elp_wakeup(wl); | ||
687 | if (ret < 0) | ||
688 | goto out; | ||
689 | |||
690 | wl1271_tx_work_locked(wl); | ||
691 | |||
692 | wl1271_ps_elp_sleep(wl); | ||
693 | out: | ||
694 | mutex_unlock(&wl->mutex); | ||
695 | } | ||
696 | |||
697 | static void wl1271_tx_complete_packet(struct wl1271 *wl, | ||
698 | struct wl1271_tx_hw_res_descr *result) | ||
699 | { | ||
700 | struct ieee80211_tx_info *info; | ||
701 | struct sk_buff *skb; | ||
702 | int id = result->id; | ||
703 | int rate = -1; | ||
704 | u8 retries = 0; | ||
705 | |||
706 | /* check for id legality */ | ||
707 | if (unlikely(id >= ACX_TX_DESCRIPTORS || wl->tx_frames[id] == NULL)) { | ||
708 | wl1271_warning("TX result illegal id: %d", id); | ||
709 | return; | ||
710 | } | ||
711 | |||
712 | skb = wl->tx_frames[id]; | ||
713 | info = IEEE80211_SKB_CB(skb); | ||
714 | |||
715 | if (wl12xx_is_dummy_packet(wl, skb)) { | ||
716 | wl1271_free_tx_id(wl, id); | ||
717 | return; | ||
718 | } | ||
719 | |||
720 | /* update the TX status info */ | ||
721 | if (result->status == TX_SUCCESS) { | ||
722 | if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) | ||
723 | info->flags |= IEEE80211_TX_STAT_ACK; | ||
724 | rate = wl1271_rate_to_idx(result->rate_class_index, wl->band); | ||
725 | retries = result->ack_failures; | ||
726 | } else if (result->status == TX_RETRY_EXCEEDED) { | ||
727 | wl->stats.excessive_retries++; | ||
728 | retries = result->ack_failures; | ||
729 | } | ||
730 | |||
731 | info->status.rates[0].idx = rate; | ||
732 | info->status.rates[0].count = retries; | ||
733 | info->status.rates[0].flags = 0; | ||
734 | info->status.ack_signal = -1; | ||
735 | |||
736 | wl->stats.retry_count += result->ack_failures; | ||
737 | |||
738 | /* | ||
739 | * update sequence number only when relevant, i.e. only in | ||
740 | * sessions of TKIP, AES and GEM (not in open or WEP sessions) | ||
741 | */ | ||
742 | if (info->control.hw_key && | ||
743 | (info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP || | ||
744 | info->control.hw_key->cipher == WLAN_CIPHER_SUITE_CCMP || | ||
745 | info->control.hw_key->cipher == WL1271_CIPHER_SUITE_GEM)) { | ||
746 | u8 fw_lsb = result->tx_security_sequence_number_lsb; | ||
747 | u8 cur_lsb = wl->tx_security_last_seq_lsb; | ||
748 | |||
749 | /* | ||
750 | * update security sequence number, taking care of potential | ||
751 | * wrap-around | ||
752 | */ | ||
753 | wl->tx_security_seq += (fw_lsb - cur_lsb + 256) % 256; | ||
754 | wl->tx_security_last_seq_lsb = fw_lsb; | ||
755 | } | ||
756 | |||
757 | /* remove private header from packet */ | ||
758 | skb_pull(skb, sizeof(struct wl1271_tx_hw_descr)); | ||
759 | |||
760 | /* remove TKIP header space if present */ | ||
761 | if (info->control.hw_key && | ||
762 | info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) { | ||
763 | int hdrlen = ieee80211_get_hdrlen_from_skb(skb); | ||
764 | memmove(skb->data + WL1271_TKIP_IV_SPACE, skb->data, hdrlen); | ||
765 | skb_pull(skb, WL1271_TKIP_IV_SPACE); | ||
766 | } | ||
767 | |||
768 | wl1271_debug(DEBUG_TX, "tx status id %u skb 0x%p failures %u rate 0x%x" | ||
769 | " status 0x%x", | ||
770 | result->id, skb, result->ack_failures, | ||
771 | result->rate_class_index, result->status); | ||
772 | |||
773 | /* return the packet to the stack */ | ||
774 | skb_queue_tail(&wl->deferred_tx_queue, skb); | ||
775 | queue_work(wl->freezable_wq, &wl->netstack_work); | ||
776 | wl1271_free_tx_id(wl, result->id); | ||
777 | } | ||
778 | |||
779 | /* Called upon reception of a TX complete interrupt */ | ||
780 | void wl1271_tx_complete(struct wl1271 *wl) | ||
781 | { | ||
782 | struct wl1271_acx_mem_map *memmap = | ||
783 | (struct wl1271_acx_mem_map *)wl->target_mem_map; | ||
784 | u32 count, fw_counter; | ||
785 | u32 i; | ||
786 | |||
787 | /* read the tx results from the chipset */ | ||
788 | wl1271_read(wl, le32_to_cpu(memmap->tx_result), | ||
789 | wl->tx_res_if, sizeof(*wl->tx_res_if), false); | ||
790 | fw_counter = le32_to_cpu(wl->tx_res_if->tx_result_fw_counter); | ||
791 | |||
792 | /* write host counter to chipset (to ack) */ | ||
793 | wl1271_write32(wl, le32_to_cpu(memmap->tx_result) + | ||
794 | offsetof(struct wl1271_tx_hw_res_if, | ||
795 | tx_result_host_counter), fw_counter); | ||
796 | |||
797 | count = fw_counter - wl->tx_results_count; | ||
798 | wl1271_debug(DEBUG_TX, "tx_complete received, packets: %d", count); | ||
799 | |||
800 | /* verify that the result buffer is not getting overrun */ | ||
801 | if (unlikely(count > TX_HW_RESULT_QUEUE_LEN)) | ||
802 | wl1271_warning("TX result overflow from chipset: %d", count); | ||
803 | |||
804 | /* process the results */ | ||
805 | for (i = 0; i < count; i++) { | ||
806 | struct wl1271_tx_hw_res_descr *result; | ||
807 | u8 offset = wl->tx_results_count & TX_HW_RESULT_QUEUE_LEN_MASK; | ||
808 | |||
809 | /* process the packet */ | ||
810 | result = &(wl->tx_res_if->tx_results_queue[offset]); | ||
811 | wl1271_tx_complete_packet(wl, result); | ||
812 | |||
813 | wl->tx_results_count++; | ||
814 | } | ||
815 | } | ||
816 | |||
817 | void wl1271_tx_reset_link_queues(struct wl1271 *wl, u8 hlid) | ||
818 | { | ||
819 | struct sk_buff *skb; | ||
820 | int i; | ||
821 | unsigned long flags; | ||
822 | struct ieee80211_tx_info *info; | ||
823 | int total[NUM_TX_QUEUES]; | ||
824 | |||
825 | for (i = 0; i < NUM_TX_QUEUES; i++) { | ||
826 | total[i] = 0; | ||
827 | while ((skb = skb_dequeue(&wl->links[hlid].tx_queue[i]))) { | ||
828 | wl1271_debug(DEBUG_TX, "link freeing skb 0x%p", skb); | ||
829 | info = IEEE80211_SKB_CB(skb); | ||
830 | info->status.rates[0].idx = -1; | ||
831 | info->status.rates[0].count = 0; | ||
832 | ieee80211_tx_status_ni(wl->hw, skb); | ||
833 | total[i]++; | ||
834 | } | ||
835 | } | ||
836 | |||
837 | spin_lock_irqsave(&wl->wl_lock, flags); | ||
838 | for (i = 0; i < NUM_TX_QUEUES; i++) | ||
839 | wl->tx_queue_count[i] -= total[i]; | ||
840 | spin_unlock_irqrestore(&wl->wl_lock, flags); | ||
841 | |||
842 | wl1271_handle_tx_low_watermark(wl); | ||
843 | } | ||
844 | |||
845 | /* caller must hold wl->mutex and TX must be stopped */ | ||
846 | void wl1271_tx_reset(struct wl1271 *wl, bool reset_tx_queues) | ||
847 | { | ||
848 | int i; | ||
849 | struct sk_buff *skb; | ||
850 | struct ieee80211_tx_info *info; | ||
851 | |||
852 | /* TX failure */ | ||
853 | if (wl->bss_type == BSS_TYPE_AP_BSS) { | ||
854 | for (i = 0; i < AP_MAX_LINKS; i++) { | ||
855 | wl1271_tx_reset_link_queues(wl, i); | ||
856 | wl->links[i].allocated_blks = 0; | ||
857 | wl->links[i].prev_freed_blks = 0; | ||
858 | } | ||
859 | |||
860 | wl->last_tx_hlid = 0; | ||
861 | } else { | ||
862 | for (i = 0; i < NUM_TX_QUEUES; i++) { | ||
863 | while ((skb = skb_dequeue(&wl->tx_queue[i]))) { | ||
864 | wl1271_debug(DEBUG_TX, "freeing skb 0x%p", | ||
865 | skb); | ||
866 | |||
867 | if (!wl12xx_is_dummy_packet(wl, skb)) { | ||
868 | info = IEEE80211_SKB_CB(skb); | ||
869 | info->status.rates[0].idx = -1; | ||
870 | info->status.rates[0].count = 0; | ||
871 | ieee80211_tx_status_ni(wl->hw, skb); | ||
872 | } | ||
873 | } | ||
874 | wl->tx_queue_count[i] = 0; | ||
875 | } | ||
876 | } | ||
877 | |||
878 | wl->stopped_queues_map = 0; | ||
879 | |||
880 | /* | ||
881 | * Make sure the driver is at a consistent state, in case this | ||
882 | * function is called from a context other than interface removal. | ||
883 | * This call will always wake the TX queues. | ||
884 | */ | ||
885 | if (reset_tx_queues) | ||
886 | wl1271_handle_tx_low_watermark(wl); | ||
887 | |||
888 | for (i = 0; i < ACX_TX_DESCRIPTORS; i++) { | ||
889 | if (wl->tx_frames[i] == NULL) | ||
890 | continue; | ||
891 | |||
892 | skb = wl->tx_frames[i]; | ||
893 | wl1271_free_tx_id(wl, i); | ||
894 | wl1271_debug(DEBUG_TX, "freeing skb 0x%p", skb); | ||
895 | |||
896 | if (!wl12xx_is_dummy_packet(wl, skb)) { | ||
897 | /* | ||
898 | * Remove private headers before passing the skb to | ||
899 | * mac80211 | ||
900 | */ | ||
901 | info = IEEE80211_SKB_CB(skb); | ||
902 | skb_pull(skb, sizeof(struct wl1271_tx_hw_descr)); | ||
903 | if (info->control.hw_key && | ||
904 | info->control.hw_key->cipher == | ||
905 | WLAN_CIPHER_SUITE_TKIP) { | ||
906 | int hdrlen = ieee80211_get_hdrlen_from_skb(skb); | ||
907 | memmove(skb->data + WL1271_TKIP_IV_SPACE, | ||
908 | skb->data, hdrlen); | ||
909 | skb_pull(skb, WL1271_TKIP_IV_SPACE); | ||
910 | } | ||
911 | |||
912 | info->status.rates[0].idx = -1; | ||
913 | info->status.rates[0].count = 0; | ||
914 | |||
915 | ieee80211_tx_status_ni(wl->hw, skb); | ||
916 | } | ||
917 | } | ||
918 | } | ||
919 | |||
920 | #define WL1271_TX_FLUSH_TIMEOUT 500000 | ||
921 | |||
922 | /* caller must *NOT* hold wl->mutex */ | ||
923 | void wl1271_tx_flush(struct wl1271 *wl) | ||
924 | { | ||
925 | unsigned long timeout; | ||
926 | timeout = jiffies + usecs_to_jiffies(WL1271_TX_FLUSH_TIMEOUT); | ||
927 | |||
928 | while (!time_after(jiffies, timeout)) { | ||
929 | mutex_lock(&wl->mutex); | ||
930 | wl1271_debug(DEBUG_TX, "flushing tx buffer: %d %d", | ||
931 | wl->tx_frames_cnt, | ||
932 | wl1271_tx_total_queue_count(wl)); | ||
933 | if ((wl->tx_frames_cnt == 0) && | ||
934 | (wl1271_tx_total_queue_count(wl) == 0)) { | ||
935 | mutex_unlock(&wl->mutex); | ||
936 | return; | ||
937 | } | ||
938 | mutex_unlock(&wl->mutex); | ||
939 | msleep(1); | ||
940 | } | ||
941 | |||
942 | wl1271_warning("Unable to flush all TX buffers, timed out."); | ||
943 | } | ||
944 | |||
945 | u32 wl1271_tx_min_rate_get(struct wl1271 *wl) | ||
946 | { | ||
947 | int i; | ||
948 | u32 rate = 0; | ||
949 | |||
950 | if (!wl->basic_rate_set) { | ||
951 | WARN_ON(1); | ||
952 | wl->basic_rate_set = wl->conf.tx.basic_rate; | ||
953 | } | ||
954 | |||
955 | for (i = 0; !rate; i++) { | ||
956 | if ((wl->basic_rate_set >> i) & 0x1) | ||
957 | rate = 1 << i; | ||
958 | } | ||
959 | |||
960 | return rate; | ||
961 | } | ||
diff --git a/drivers/net/wireless/wl12xx/tx.h b/drivers/net/wireless/wl12xx/tx.h new file mode 100644 index 00000000000..5d719b5a3d1 --- /dev/null +++ b/drivers/net/wireless/wl12xx/tx.h | |||
@@ -0,0 +1,223 @@ | |||
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_BLOCK_SIZE 252 | ||
29 | |||
30 | #define TX_HW_MGMT_PKT_LIFETIME_TU 2000 | ||
31 | #define TX_HW_AP_MODE_PKT_LIFETIME_TU 8000 | ||
32 | /* The chipset reference driver states, that the "aid" value 1 | ||
33 | * is for infra-BSS, but is still always used */ | ||
34 | #define TX_HW_DEFAULT_AID 1 | ||
35 | |||
36 | #define TX_HW_ATTR_SAVE_RETRIES BIT(0) | ||
37 | #define TX_HW_ATTR_HEADER_PAD BIT(1) | ||
38 | #define TX_HW_ATTR_SESSION_COUNTER (BIT(2) | BIT(3) | BIT(4)) | ||
39 | #define TX_HW_ATTR_RATE_POLICY (BIT(5) | BIT(6) | BIT(7) | \ | ||
40 | BIT(8) | BIT(9)) | ||
41 | #define TX_HW_ATTR_LAST_WORD_PAD (BIT(10) | BIT(11)) | ||
42 | #define TX_HW_ATTR_TX_CMPLT_REQ BIT(12) | ||
43 | #define TX_HW_ATTR_TX_DUMMY_REQ BIT(13) | ||
44 | |||
45 | #define TX_HW_ATTR_OFST_SAVE_RETRIES 0 | ||
46 | #define TX_HW_ATTR_OFST_HEADER_PAD 1 | ||
47 | #define TX_HW_ATTR_OFST_SESSION_COUNTER 2 | ||
48 | #define TX_HW_ATTR_OFST_RATE_POLICY 5 | ||
49 | #define TX_HW_ATTR_OFST_LAST_WORD_PAD 10 | ||
50 | #define TX_HW_ATTR_OFST_TX_CMPLT_REQ 12 | ||
51 | |||
52 | #define TX_HW_RESULT_QUEUE_LEN 16 | ||
53 | #define TX_HW_RESULT_QUEUE_LEN_MASK 0xf | ||
54 | |||
55 | #define WL1271_TX_ALIGN_TO 4 | ||
56 | #define WL1271_TKIP_IV_SPACE 4 | ||
57 | |||
58 | /* Used for management frames and dummy packets */ | ||
59 | #define WL1271_TID_MGMT 7 | ||
60 | |||
61 | struct wl127x_tx_mem { | ||
62 | /* | ||
63 | * Number of extra memory blocks to allocate for this packet | ||
64 | * in addition to the number of blocks derived from the packet | ||
65 | * length. | ||
66 | */ | ||
67 | u8 extra_blocks; | ||
68 | /* | ||
69 | * Total number of memory blocks allocated by the host for | ||
70 | * this packet. Must be equal or greater than the actual | ||
71 | * blocks number allocated by HW. | ||
72 | */ | ||
73 | u8 total_mem_blocks; | ||
74 | } __packed; | ||
75 | |||
76 | struct wl128x_tx_mem { | ||
77 | /* | ||
78 | * Total number of memory blocks allocated by the host for | ||
79 | * this packet. | ||
80 | */ | ||
81 | u8 total_mem_blocks; | ||
82 | /* | ||
83 | * Number of extra bytes, at the end of the frame. the host | ||
84 | * uses this padding to complete each frame to integer number | ||
85 | * of SDIO blocks. | ||
86 | */ | ||
87 | u8 extra_bytes; | ||
88 | } __packed; | ||
89 | |||
90 | /* | ||
91 | * On wl128x based devices, when TX packets are aggregated, each packet | ||
92 | * size must be aligned to the SDIO block size. The maximum block size | ||
93 | * is bounded by the type of the padded bytes field that is sent to the | ||
94 | * FW. Currently the type is u8, so the maximum block size is 256 bytes. | ||
95 | */ | ||
96 | #define WL12XX_BUS_BLOCK_SIZE min(512u, \ | ||
97 | (1u << (8 * sizeof(((struct wl128x_tx_mem *) 0)->extra_bytes)))) | ||
98 | |||
99 | struct wl1271_tx_hw_descr { | ||
100 | /* Length of packet in words, including descriptor+header+data */ | ||
101 | __le16 length; | ||
102 | union { | ||
103 | struct wl127x_tx_mem wl127x_mem; | ||
104 | struct wl128x_tx_mem wl128x_mem; | ||
105 | } __packed; | ||
106 | /* Device time (in us) when the packet arrived to the driver */ | ||
107 | __le32 start_time; | ||
108 | /* | ||
109 | * Max delay in TUs until transmission. The last device time the | ||
110 | * packet can be transmitted is: start_time + (1024 * life_time) | ||
111 | */ | ||
112 | __le16 life_time; | ||
113 | /* Bitwise fields - see TX_ATTR... definitions above. */ | ||
114 | __le16 tx_attr; | ||
115 | /* Packet identifier used also in the Tx-Result. */ | ||
116 | u8 id; | ||
117 | /* The packet TID value (as User-Priority) */ | ||
118 | u8 tid; | ||
119 | union { | ||
120 | /* STA - Identifier of the remote STA in IBSS, 1 in infra-BSS */ | ||
121 | u8 aid; | ||
122 | /* AP - host link ID (HLID) */ | ||
123 | u8 hlid; | ||
124 | } __packed; | ||
125 | u8 reserved; | ||
126 | } __packed; | ||
127 | |||
128 | enum wl1271_tx_hw_res_status { | ||
129 | TX_SUCCESS = 0, | ||
130 | TX_HW_ERROR = 1, | ||
131 | TX_DISABLED = 2, | ||
132 | TX_RETRY_EXCEEDED = 3, | ||
133 | TX_TIMEOUT = 4, | ||
134 | TX_KEY_NOT_FOUND = 5, | ||
135 | TX_PEER_NOT_FOUND = 6, | ||
136 | TX_SESSION_MISMATCH = 7 | ||
137 | }; | ||
138 | |||
139 | struct wl1271_tx_hw_res_descr { | ||
140 | /* Packet Identifier - same value used in the Tx descriptor.*/ | ||
141 | u8 id; | ||
142 | /* The status of the transmission, indicating success or one of | ||
143 | several possible reasons for failure. */ | ||
144 | u8 status; | ||
145 | /* Total air access duration including all retrys and overheads.*/ | ||
146 | __le16 medium_usage; | ||
147 | /* The time passed from host xfer to Tx-complete.*/ | ||
148 | __le32 fw_handling_time; | ||
149 | /* Total media delay | ||
150 | (from 1st EDCA AIFS counter until TX Complete). */ | ||
151 | __le32 medium_delay; | ||
152 | /* LS-byte of last TKIP seq-num (saved per AC for recovery). */ | ||
153 | u8 tx_security_sequence_number_lsb; | ||
154 | /* Retry count - number of transmissions without successful ACK.*/ | ||
155 | u8 ack_failures; | ||
156 | /* The rate that succeeded getting ACK | ||
157 | (Valid only if status=SUCCESS). */ | ||
158 | u8 rate_class_index; | ||
159 | /* for 4-byte alignment. */ | ||
160 | u8 spare; | ||
161 | } __packed; | ||
162 | |||
163 | struct wl1271_tx_hw_res_if { | ||
164 | __le32 tx_result_fw_counter; | ||
165 | __le32 tx_result_host_counter; | ||
166 | struct wl1271_tx_hw_res_descr tx_results_queue[TX_HW_RESULT_QUEUE_LEN]; | ||
167 | } __packed; | ||
168 | |||
169 | static inline int wl1271_tx_get_queue(int queue) | ||
170 | { | ||
171 | switch (queue) { | ||
172 | case 0: | ||
173 | return CONF_TX_AC_VO; | ||
174 | case 1: | ||
175 | return CONF_TX_AC_VI; | ||
176 | case 2: | ||
177 | return CONF_TX_AC_BE; | ||
178 | case 3: | ||
179 | return CONF_TX_AC_BK; | ||
180 | default: | ||
181 | return CONF_TX_AC_BE; | ||
182 | } | ||
183 | } | ||
184 | |||
185 | static inline int wl1271_tx_get_mac80211_queue(int queue) | ||
186 | { | ||
187 | switch (queue) { | ||
188 | case CONF_TX_AC_VO: | ||
189 | return 0; | ||
190 | case CONF_TX_AC_VI: | ||
191 | return 1; | ||
192 | case CONF_TX_AC_BE: | ||
193 | return 2; | ||
194 | case CONF_TX_AC_BK: | ||
195 | return 3; | ||
196 | default: | ||
197 | return 2; | ||
198 | } | ||
199 | } | ||
200 | |||
201 | static inline int wl1271_tx_total_queue_count(struct wl1271 *wl) | ||
202 | { | ||
203 | int i, count = 0; | ||
204 | |||
205 | for (i = 0; i < NUM_TX_QUEUES; i++) | ||
206 | count += wl->tx_queue_count[i]; | ||
207 | |||
208 | return count; | ||
209 | } | ||
210 | |||
211 | void wl1271_tx_work(struct work_struct *work); | ||
212 | void wl1271_tx_work_locked(struct wl1271 *wl); | ||
213 | void wl1271_tx_complete(struct wl1271 *wl); | ||
214 | void wl1271_tx_reset(struct wl1271 *wl, bool reset_tx_queues); | ||
215 | void wl1271_tx_flush(struct wl1271 *wl); | ||
216 | u8 wl1271_rate_to_idx(int rate, enum ieee80211_band band); | ||
217 | u32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set); | ||
218 | u32 wl1271_tx_min_rate_get(struct wl1271 *wl); | ||
219 | u8 wl1271_tx_get_hlid(struct sk_buff *skb); | ||
220 | void wl1271_tx_reset_link_queues(struct wl1271 *wl, u8 hlid); | ||
221 | void wl1271_handle_tx_low_watermark(struct wl1271 *wl); | ||
222 | |||
223 | #endif | ||
diff --git a/drivers/net/wireless/wl12xx/wl12xx.h b/drivers/net/wireless/wl12xx/wl12xx.h new file mode 100644 index 00000000000..1a8751eb814 --- /dev/null +++ b/drivers/net/wireless/wl12xx/wl12xx.h | |||
@@ -0,0 +1,682 @@ | |||
1 | /* | ||
2 | * This file is part of wl1271 | ||
3 | * | ||
4 | * Copyright (C) 1998-2009 Texas Instruments. All rights reserved. | ||
5 | * Copyright (C) 2008-2009 Nokia Corporation | ||
6 | * | ||
7 | * Contact: Luciano Coelho <luciano.coelho@nokia.com> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or | ||
10 | * modify it under the terms of the GNU General Public License | ||
11 | * version 2 as published by the Free Software Foundation. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, but | ||
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
21 | * 02110-1301 USA | ||
22 | * | ||
23 | */ | ||
24 | |||
25 | #ifndef __WL12XX_H__ | ||
26 | #define __WL12XX_H__ | ||
27 | |||
28 | #include <linux/mutex.h> | ||
29 | #include <linux/completion.h> | ||
30 | #include <linux/spinlock.h> | ||
31 | #include <linux/list.h> | ||
32 | #include <linux/bitops.h> | ||
33 | #include <net/mac80211.h> | ||
34 | |||
35 | #include "conf.h" | ||
36 | #include "ini.h" | ||
37 | |||
38 | #define DRIVER_NAME "wl1271" | ||
39 | #define DRIVER_PREFIX DRIVER_NAME ": " | ||
40 | |||
41 | /* | ||
42 | * FW versions support BA 11n | ||
43 | * versions marks x.x.x.50-60.x | ||
44 | */ | ||
45 | #define WL12XX_BA_SUPPORT_FW_COST_VER2_START 50 | ||
46 | #define WL12XX_BA_SUPPORT_FW_COST_VER2_END 60 | ||
47 | |||
48 | enum { | ||
49 | DEBUG_NONE = 0, | ||
50 | DEBUG_IRQ = BIT(0), | ||
51 | DEBUG_SPI = BIT(1), | ||
52 | DEBUG_BOOT = BIT(2), | ||
53 | DEBUG_MAILBOX = BIT(3), | ||
54 | DEBUG_TESTMODE = BIT(4), | ||
55 | DEBUG_EVENT = BIT(5), | ||
56 | DEBUG_TX = BIT(6), | ||
57 | DEBUG_RX = BIT(7), | ||
58 | DEBUG_SCAN = BIT(8), | ||
59 | DEBUG_CRYPT = BIT(9), | ||
60 | DEBUG_PSM = BIT(10), | ||
61 | DEBUG_MAC80211 = BIT(11), | ||
62 | DEBUG_CMD = BIT(12), | ||
63 | DEBUG_ACX = BIT(13), | ||
64 | DEBUG_SDIO = BIT(14), | ||
65 | DEBUG_FILTERS = BIT(15), | ||
66 | DEBUG_ADHOC = BIT(16), | ||
67 | DEBUG_AP = BIT(17), | ||
68 | DEBUG_MASTER = (DEBUG_ADHOC | DEBUG_AP), | ||
69 | DEBUG_ALL = ~0, | ||
70 | }; | ||
71 | |||
72 | extern u32 wl12xx_debug_level; | ||
73 | |||
74 | #define DEBUG_DUMP_LIMIT 1024 | ||
75 | |||
76 | #define wl1271_error(fmt, arg...) \ | ||
77 | pr_err(DRIVER_PREFIX "ERROR " fmt "\n", ##arg) | ||
78 | |||
79 | #define wl1271_warning(fmt, arg...) \ | ||
80 | pr_warning(DRIVER_PREFIX "WARNING " fmt "\n", ##arg) | ||
81 | |||
82 | #define wl1271_notice(fmt, arg...) \ | ||
83 | pr_info(DRIVER_PREFIX fmt "\n", ##arg) | ||
84 | |||
85 | #define wl1271_info(fmt, arg...) \ | ||
86 | pr_info(DRIVER_PREFIX fmt "\n", ##arg) | ||
87 | |||
88 | #define wl1271_debug(level, fmt, arg...) \ | ||
89 | do { \ | ||
90 | if (level & wl12xx_debug_level) \ | ||
91 | pr_debug(DRIVER_PREFIX fmt "\n", ##arg); \ | ||
92 | } while (0) | ||
93 | |||
94 | /* TODO: use pr_debug_hex_dump when it will be available */ | ||
95 | #define wl1271_dump(level, prefix, buf, len) \ | ||
96 | do { \ | ||
97 | if (level & wl12xx_debug_level) \ | ||
98 | print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \ | ||
99 | DUMP_PREFIX_OFFSET, 16, 1, \ | ||
100 | buf, \ | ||
101 | min_t(size_t, len, DEBUG_DUMP_LIMIT), \ | ||
102 | 0); \ | ||
103 | } while (0) | ||
104 | |||
105 | #define wl1271_dump_ascii(level, prefix, buf, len) \ | ||
106 | do { \ | ||
107 | if (level & wl12xx_debug_level) \ | ||
108 | print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \ | ||
109 | DUMP_PREFIX_OFFSET, 16, 1, \ | ||
110 | buf, \ | ||
111 | min_t(size_t, len, DEBUG_DUMP_LIMIT), \ | ||
112 | true); \ | ||
113 | } while (0) | ||
114 | |||
115 | #define WL1271_DEFAULT_STA_RX_CONFIG (CFG_UNI_FILTER_EN | \ | ||
116 | CFG_BSSID_FILTER_EN | \ | ||
117 | CFG_MC_FILTER_EN) | ||
118 | |||
119 | #define WL1271_DEFAULT_STA_RX_FILTER (CFG_RX_RCTS_ACK | CFG_RX_PRSP_EN | \ | ||
120 | CFG_RX_MGMT_EN | CFG_RX_DATA_EN | \ | ||
121 | CFG_RX_CTL_EN | CFG_RX_BCN_EN | \ | ||
122 | CFG_RX_AUTH_EN | CFG_RX_ASSOC_EN) | ||
123 | |||
124 | #define WL1271_DEFAULT_AP_RX_CONFIG 0 | ||
125 | |||
126 | #define WL1271_DEFAULT_AP_RX_FILTER (CFG_RX_RCTS_ACK | CFG_RX_PREQ_EN | \ | ||
127 | CFG_RX_MGMT_EN | CFG_RX_DATA_EN | \ | ||
128 | CFG_RX_CTL_EN | CFG_RX_AUTH_EN | \ | ||
129 | CFG_RX_ASSOC_EN) | ||
130 | |||
131 | |||
132 | |||
133 | #define WL1271_FW_NAME "ti-connectivity/wl1271-fw-2.bin" | ||
134 | #define WL128X_FW_NAME "ti-connectivity/wl128x-fw.bin" | ||
135 | #define WL127X_AP_FW_NAME "ti-connectivity/wl1271-fw-ap.bin" | ||
136 | #define WL128X_AP_FW_NAME "ti-connectivity/wl128x-fw-ap.bin" | ||
137 | |||
138 | /* | ||
139 | * wl127x and wl128x are using the same NVS file name. However, the | ||
140 | * ini parameters between them are different. The driver validates | ||
141 | * the correct NVS size in wl1271_boot_upload_nvs(). | ||
142 | */ | ||
143 | #define WL12XX_NVS_NAME "ti-connectivity/wl1271-nvs.bin" | ||
144 | |||
145 | #define WL1271_TX_SECURITY_LO16(s) ((u16)((s) & 0xffff)) | ||
146 | #define WL1271_TX_SECURITY_HI32(s) ((u32)(((s) >> 16) & 0xffffffff)) | ||
147 | #define WL1271_TX_SQN_POST_RECOVERY_PADDING 0xff | ||
148 | |||
149 | #define WL1271_CIPHER_SUITE_GEM 0x00147201 | ||
150 | |||
151 | #define WL1271_BUSY_WORD_CNT 1 | ||
152 | #define WL1271_BUSY_WORD_LEN (WL1271_BUSY_WORD_CNT * sizeof(u32)) | ||
153 | |||
154 | #define WL1271_ELP_HW_STATE_ASLEEP 0 | ||
155 | #define WL1271_ELP_HW_STATE_IRQ 1 | ||
156 | |||
157 | #define WL1271_DEFAULT_BEACON_INT 100 | ||
158 | #define WL1271_DEFAULT_DTIM_PERIOD 1 | ||
159 | |||
160 | #define WL1271_AP_GLOBAL_HLID 0 | ||
161 | #define WL1271_AP_BROADCAST_HLID 1 | ||
162 | #define WL1271_AP_STA_HLID_START 2 | ||
163 | |||
164 | /* | ||
165 | * When in AP-mode, we allow (at least) this number of mem-blocks | ||
166 | * to be transmitted to FW for a STA in PS-mode. Only when packets are | ||
167 | * present in the FW buffers it will wake the sleeping STA. We want to put | ||
168 | * enough packets for the driver to transmit all of its buffered data before | ||
169 | * the STA goes to sleep again. But we don't want to take too much mem-blocks | ||
170 | * as it might hurt the throughput of active STAs. | ||
171 | * The number of blocks (18) is enough for 2 large packets. | ||
172 | */ | ||
173 | #define WL1271_PS_STA_MAX_BLOCKS (2 * 9) | ||
174 | |||
175 | #define WL1271_AP_BSS_INDEX 0 | ||
176 | #define WL1271_AP_DEF_BEACON_EXP 20 | ||
177 | |||
178 | #define ACX_TX_DESCRIPTORS 32 | ||
179 | |||
180 | #define WL1271_AGGR_BUFFER_SIZE (4 * PAGE_SIZE) | ||
181 | |||
182 | enum wl1271_state { | ||
183 | WL1271_STATE_OFF, | ||
184 | WL1271_STATE_ON, | ||
185 | WL1271_STATE_PLT, | ||
186 | }; | ||
187 | |||
188 | enum wl1271_partition_type { | ||
189 | PART_DOWN, | ||
190 | PART_WORK, | ||
191 | PART_DRPW, | ||
192 | |||
193 | PART_TABLE_LEN | ||
194 | }; | ||
195 | |||
196 | struct wl1271_partition { | ||
197 | u32 size; | ||
198 | u32 start; | ||
199 | }; | ||
200 | |||
201 | struct wl1271_partition_set { | ||
202 | struct wl1271_partition mem; | ||
203 | struct wl1271_partition reg; | ||
204 | struct wl1271_partition mem2; | ||
205 | struct wl1271_partition mem3; | ||
206 | }; | ||
207 | |||
208 | struct wl1271; | ||
209 | |||
210 | enum { | ||
211 | FW_VER_CHIP, | ||
212 | FW_VER_IF_TYPE, | ||
213 | FW_VER_MAJOR, | ||
214 | FW_VER_SUBTYPE, | ||
215 | FW_VER_MINOR, | ||
216 | |||
217 | NUM_FW_VER | ||
218 | }; | ||
219 | |||
220 | #define FW_VER_CHIP_WL127X 6 | ||
221 | #define FW_VER_CHIP_WL128X 7 | ||
222 | |||
223 | #define FW_VER_IF_TYPE_STA 1 | ||
224 | #define FW_VER_IF_TYPE_AP 2 | ||
225 | |||
226 | #define FW_VER_MINOR_1_SPARE_STA_MIN 58 | ||
227 | #define FW_VER_MINOR_1_SPARE_AP_MIN 47 | ||
228 | |||
229 | #define FW_VER_MINOR_FWLOG_STA_MIN 70 | ||
230 | |||
231 | struct wl1271_chip { | ||
232 | u32 id; | ||
233 | char fw_ver_str[ETHTOOL_BUSINFO_LEN]; | ||
234 | unsigned int fw_ver[NUM_FW_VER]; | ||
235 | }; | ||
236 | |||
237 | struct wl1271_stats { | ||
238 | struct acx_statistics *fw_stats; | ||
239 | unsigned long fw_stats_update; | ||
240 | |||
241 | unsigned int retry_count; | ||
242 | unsigned int excessive_retries; | ||
243 | }; | ||
244 | |||
245 | #define NUM_TX_QUEUES 4 | ||
246 | #define NUM_RX_PKT_DESC 8 | ||
247 | |||
248 | #define AP_MAX_STATIONS 5 | ||
249 | |||
250 | /* Broadcast and Global links + links to stations */ | ||
251 | #define AP_MAX_LINKS (AP_MAX_STATIONS + 2) | ||
252 | |||
253 | /* FW status registers common for AP/STA */ | ||
254 | struct wl1271_fw_common_status { | ||
255 | __le32 intr; | ||
256 | u8 fw_rx_counter; | ||
257 | u8 drv_rx_counter; | ||
258 | u8 reserved; | ||
259 | u8 tx_results_counter; | ||
260 | __le32 rx_pkt_descs[NUM_RX_PKT_DESC]; | ||
261 | __le32 tx_released_blks[NUM_TX_QUEUES]; | ||
262 | __le32 fw_localtime; | ||
263 | } __packed; | ||
264 | |||
265 | /* FW status registers for AP */ | ||
266 | struct wl1271_fw_ap_status { | ||
267 | struct wl1271_fw_common_status common; | ||
268 | |||
269 | /* Next fields valid only in AP FW */ | ||
270 | |||
271 | /* | ||
272 | * A bitmap (where each bit represents a single HLID) | ||
273 | * to indicate if the station is in PS mode. | ||
274 | */ | ||
275 | __le32 link_ps_bitmap; | ||
276 | |||
277 | /* Number of freed MBs per HLID */ | ||
278 | u8 tx_lnk_free_blks[AP_MAX_LINKS]; | ||
279 | u8 padding_1[1]; | ||
280 | } __packed; | ||
281 | |||
282 | /* FW status registers for STA */ | ||
283 | struct wl1271_fw_sta_status { | ||
284 | struct wl1271_fw_common_status common; | ||
285 | |||
286 | u8 tx_total; | ||
287 | u8 reserved1; | ||
288 | __le16 reserved2; | ||
289 | __le32 log_start_addr; | ||
290 | } __packed; | ||
291 | |||
292 | struct wl1271_fw_full_status { | ||
293 | union { | ||
294 | struct wl1271_fw_common_status common; | ||
295 | struct wl1271_fw_sta_status sta; | ||
296 | struct wl1271_fw_ap_status ap; | ||
297 | }; | ||
298 | } __packed; | ||
299 | |||
300 | |||
301 | struct wl1271_rx_mem_pool_addr { | ||
302 | u32 addr; | ||
303 | u32 addr_extra; | ||
304 | }; | ||
305 | |||
306 | #define WL1271_MAX_CHANNELS 64 | ||
307 | struct wl1271_scan { | ||
308 | struct cfg80211_scan_request *req; | ||
309 | unsigned long scanned_ch[BITS_TO_LONGS(WL1271_MAX_CHANNELS)]; | ||
310 | bool failed; | ||
311 | u8 state; | ||
312 | u8 ssid[IW_ESSID_MAX_SIZE+1]; | ||
313 | size_t ssid_len; | ||
314 | }; | ||
315 | |||
316 | struct wl1271_if_operations { | ||
317 | void (*read)(struct wl1271 *wl, int addr, void *buf, size_t len, | ||
318 | bool fixed); | ||
319 | void (*write)(struct wl1271 *wl, int addr, void *buf, size_t len, | ||
320 | bool fixed); | ||
321 | void (*reset)(struct wl1271 *wl); | ||
322 | void (*init)(struct wl1271 *wl); | ||
323 | int (*power)(struct wl1271 *wl, bool enable); | ||
324 | struct device* (*dev)(struct wl1271 *wl); | ||
325 | void (*enable_irq)(struct wl1271 *wl); | ||
326 | void (*disable_irq)(struct wl1271 *wl); | ||
327 | void (*set_block_size) (struct wl1271 *wl, unsigned int blksz); | ||
328 | }; | ||
329 | |||
330 | #define MAX_NUM_KEYS 14 | ||
331 | #define MAX_KEY_SIZE 32 | ||
332 | |||
333 | struct wl1271_ap_key { | ||
334 | u8 id; | ||
335 | u8 key_type; | ||
336 | u8 key_size; | ||
337 | u8 key[MAX_KEY_SIZE]; | ||
338 | u8 hlid; | ||
339 | u32 tx_seq_32; | ||
340 | u16 tx_seq_16; | ||
341 | }; | ||
342 | |||
343 | enum wl12xx_flags { | ||
344 | WL1271_FLAG_STA_ASSOCIATED, | ||
345 | WL1271_FLAG_JOINED, | ||
346 | WL1271_FLAG_GPIO_POWER, | ||
347 | WL1271_FLAG_TX_QUEUE_STOPPED, | ||
348 | WL1271_FLAG_TX_PENDING, | ||
349 | WL1271_FLAG_IN_ELP, | ||
350 | WL1271_FLAG_ELP_REQUESTED, | ||
351 | WL1271_FLAG_PSM, | ||
352 | WL1271_FLAG_PSM_REQUESTED, | ||
353 | WL1271_FLAG_IRQ_RUNNING, | ||
354 | WL1271_FLAG_IDLE, | ||
355 | WL1271_FLAG_PSPOLL_FAILURE, | ||
356 | WL1271_FLAG_STA_STATE_SENT, | ||
357 | WL1271_FLAG_FW_TX_BUSY, | ||
358 | WL1271_FLAG_AP_STARTED, | ||
359 | WL1271_FLAG_IF_INITIALIZED, | ||
360 | WL1271_FLAG_DUMMY_PACKET_PENDING, | ||
361 | WL1271_FLAG_SUSPENDED, | ||
362 | WL1271_FLAG_PENDING_WORK, | ||
363 | WL1271_FLAG_SOFT_GEMINI, | ||
364 | WL1271_FLAG_RX_STREAMING_STARTED, | ||
365 | WL1271_FLAG_RECOVERY_IN_PROGRESS, | ||
366 | }; | ||
367 | |||
368 | struct wl1271_link { | ||
369 | /* AP-mode - TX queue per AC in link */ | ||
370 | struct sk_buff_head tx_queue[NUM_TX_QUEUES]; | ||
371 | |||
372 | /* accounting for allocated / available TX blocks in FW */ | ||
373 | u8 allocated_blks; | ||
374 | u8 prev_freed_blks; | ||
375 | |||
376 | u8 addr[ETH_ALEN]; | ||
377 | }; | ||
378 | |||
379 | struct wl1271 { | ||
380 | struct platform_device *plat_dev; | ||
381 | struct ieee80211_hw *hw; | ||
382 | bool mac80211_registered; | ||
383 | |||
384 | void *if_priv; | ||
385 | |||
386 | struct wl1271_if_operations *if_ops; | ||
387 | |||
388 | void (*set_power)(bool enable); | ||
389 | int irq; | ||
390 | int ref_clock; | ||
391 | |||
392 | spinlock_t wl_lock; | ||
393 | |||
394 | enum wl1271_state state; | ||
395 | struct mutex mutex; | ||
396 | |||
397 | unsigned long flags; | ||
398 | |||
399 | struct wl1271_partition_set part; | ||
400 | |||
401 | struct wl1271_chip chip; | ||
402 | |||
403 | int cmd_box_addr; | ||
404 | int event_box_addr; | ||
405 | |||
406 | u8 *fw; | ||
407 | size_t fw_len; | ||
408 | u8 fw_bss_type; | ||
409 | void *nvs; | ||
410 | size_t nvs_len; | ||
411 | |||
412 | s8 hw_pg_ver; | ||
413 | |||
414 | u8 bssid[ETH_ALEN]; | ||
415 | u8 mac_addr[ETH_ALEN]; | ||
416 | u8 bss_type; | ||
417 | u8 set_bss_type; | ||
418 | u8 ssid[IW_ESSID_MAX_SIZE + 1]; | ||
419 | u8 ssid_len; | ||
420 | int channel; | ||
421 | |||
422 | struct wl1271_acx_mem_map *target_mem_map; | ||
423 | |||
424 | /* Accounting for allocated / available TX blocks on HW */ | ||
425 | u32 tx_blocks_freed[NUM_TX_QUEUES]; | ||
426 | u32 tx_blocks_available; | ||
427 | u32 tx_allocated_blocks[NUM_TX_QUEUES]; | ||
428 | u32 tx_results_count; | ||
429 | |||
430 | /* Transmitted TX packets counter for chipset interface */ | ||
431 | u32 tx_packets_count; | ||
432 | |||
433 | /* Time-offset between host and chipset clocks */ | ||
434 | s64 time_offset; | ||
435 | |||
436 | /* Session counter for the chipset */ | ||
437 | int session_counter; | ||
438 | |||
439 | /* Frames scheduled for transmission, not handled yet */ | ||
440 | struct sk_buff_head tx_queue[NUM_TX_QUEUES]; | ||
441 | int tx_queue_count[NUM_TX_QUEUES]; | ||
442 | long stopped_queues_map; | ||
443 | |||
444 | /* Frames received, not handled yet by mac80211 */ | ||
445 | struct sk_buff_head deferred_rx_queue; | ||
446 | |||
447 | /* Frames sent, not returned yet to mac80211 */ | ||
448 | struct sk_buff_head deferred_tx_queue; | ||
449 | |||
450 | struct work_struct tx_work; | ||
451 | struct workqueue_struct *freezable_wq; | ||
452 | |||
453 | /* Pending TX frames */ | ||
454 | unsigned long tx_frames_map[BITS_TO_LONGS(ACX_TX_DESCRIPTORS)]; | ||
455 | struct sk_buff *tx_frames[ACX_TX_DESCRIPTORS]; | ||
456 | int tx_frames_cnt; | ||
457 | |||
458 | /* | ||
459 | * Security sequence number | ||
460 | * bits 0-15: lower 16 bits part of sequence number | ||
461 | * bits 16-47: higher 32 bits part of sequence number | ||
462 | * bits 48-63: not in use | ||
463 | */ | ||
464 | u64 tx_security_seq; | ||
465 | |||
466 | /* 8 bits of the last sequence number in use */ | ||
467 | u8 tx_security_last_seq_lsb; | ||
468 | |||
469 | /* FW Rx counter */ | ||
470 | u32 rx_counter; | ||
471 | |||
472 | /* Rx memory pool address */ | ||
473 | struct wl1271_rx_mem_pool_addr rx_mem_pool_addr; | ||
474 | |||
475 | /* Intermediate buffer, used for packet aggregation */ | ||
476 | u8 *aggr_buf; | ||
477 | |||
478 | /* Reusable dummy packet template */ | ||
479 | struct sk_buff *dummy_packet; | ||
480 | |||
481 | /* Network stack work */ | ||
482 | struct work_struct netstack_work; | ||
483 | |||
484 | /* FW log buffer */ | ||
485 | u8 *fwlog; | ||
486 | |||
487 | /* Number of valid bytes in the FW log buffer */ | ||
488 | ssize_t fwlog_size; | ||
489 | |||
490 | /* Sysfs FW log entry readers wait queue */ | ||
491 | wait_queue_head_t fwlog_waitq; | ||
492 | |||
493 | /* Hardware recovery work */ | ||
494 | struct work_struct recovery_work; | ||
495 | |||
496 | /* The mbox event mask */ | ||
497 | u32 event_mask; | ||
498 | |||
499 | /* Mailbox pointers */ | ||
500 | u32 mbox_ptr[2]; | ||
501 | |||
502 | /* Are we currently scanning */ | ||
503 | struct wl1271_scan scan; | ||
504 | struct delayed_work scan_complete_work; | ||
505 | |||
506 | bool sched_scanning; | ||
507 | |||
508 | /* probe-req template for the current AP */ | ||
509 | struct sk_buff *probereq; | ||
510 | |||
511 | /* Our association ID */ | ||
512 | u16 aid; | ||
513 | |||
514 | /* | ||
515 | * currently configured rate set: | ||
516 | * bits 0-15 - 802.11abg rates | ||
517 | * bits 16-23 - 802.11n MCS index mask | ||
518 | * support only 1 stream, thus only 8 bits for the MCS rates (0-7). | ||
519 | */ | ||
520 | u32 basic_rate_set; | ||
521 | u32 basic_rate; | ||
522 | u32 rate_set; | ||
523 | |||
524 | /* The current band */ | ||
525 | enum ieee80211_band band; | ||
526 | |||
527 | /* Beaconing interval (needed for ad-hoc) */ | ||
528 | u32 beacon_int; | ||
529 | |||
530 | /* Default key (for WEP) */ | ||
531 | u32 default_key; | ||
532 | |||
533 | /* Rx Streaming */ | ||
534 | struct work_struct rx_streaming_enable_work; | ||
535 | struct work_struct rx_streaming_disable_work; | ||
536 | struct timer_list rx_streaming_timer; | ||
537 | |||
538 | unsigned int filters; | ||
539 | unsigned int rx_config; | ||
540 | unsigned int rx_filter; | ||
541 | |||
542 | struct completion *elp_compl; | ||
543 | struct completion *ps_compl; | ||
544 | struct delayed_work elp_work; | ||
545 | struct delayed_work pspoll_work; | ||
546 | |||
547 | /* counter for ps-poll delivery failures */ | ||
548 | int ps_poll_failures; | ||
549 | |||
550 | /* retry counter for PSM entries */ | ||
551 | u8 psm_entry_retry; | ||
552 | |||
553 | /* in dBm */ | ||
554 | int power_level; | ||
555 | |||
556 | int rssi_thold; | ||
557 | int last_rssi_event; | ||
558 | |||
559 | struct wl1271_stats stats; | ||
560 | |||
561 | __le32 buffer_32; | ||
562 | u32 buffer_cmd; | ||
563 | u32 buffer_busyword[WL1271_BUSY_WORD_CNT]; | ||
564 | |||
565 | struct wl1271_fw_full_status *fw_status; | ||
566 | struct wl1271_tx_hw_res_if *tx_res_if; | ||
567 | |||
568 | struct ieee80211_vif *vif; | ||
569 | |||
570 | /* Current chipset configuration */ | ||
571 | struct conf_drv_settings conf; | ||
572 | |||
573 | bool sg_enabled; | ||
574 | |||
575 | bool enable_11a; | ||
576 | |||
577 | struct list_head list; | ||
578 | |||
579 | /* Most recently reported noise in dBm */ | ||
580 | s8 noise; | ||
581 | |||
582 | /* map for HLIDs of associated stations - when operating in AP mode */ | ||
583 | unsigned long ap_hlid_map[BITS_TO_LONGS(AP_MAX_STATIONS)]; | ||
584 | |||
585 | /* recoreded keys for AP-mode - set here before AP startup */ | ||
586 | struct wl1271_ap_key *recorded_ap_keys[MAX_NUM_KEYS]; | ||
587 | |||
588 | /* bands supported by this instance of wl12xx */ | ||
589 | struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS]; | ||
590 | |||
591 | /* RX BA constraint value */ | ||
592 | bool ba_support; | ||
593 | u8 ba_rx_bitmap; | ||
594 | bool ba_allowed; | ||
595 | |||
596 | int tcxo_clock; | ||
597 | |||
598 | /* | ||
599 | * wowlan trigger was configured during suspend. | ||
600 | * (currently, only "ANY" trigger is supported) | ||
601 | */ | ||
602 | bool wow_enabled; | ||
603 | bool irq_wake_enabled; | ||
604 | |||
605 | /* | ||
606 | * AP-mode - links indexed by HLID. The global and broadcast links | ||
607 | * are always active. | ||
608 | */ | ||
609 | struct wl1271_link links[AP_MAX_LINKS]; | ||
610 | |||
611 | /* the hlid of the link where the last transmitted skb came from */ | ||
612 | int last_tx_hlid; | ||
613 | |||
614 | /* AP-mode - a bitmap of links currently in PS mode according to FW */ | ||
615 | u32 ap_fw_ps_map; | ||
616 | |||
617 | /* AP-mode - a bitmap of links currently in PS mode in mac80211 */ | ||
618 | unsigned long ap_ps_map; | ||
619 | |||
620 | /* Quirks of specific hardware revisions */ | ||
621 | unsigned int quirks; | ||
622 | |||
623 | /* Platform limitations */ | ||
624 | unsigned int platform_quirks; | ||
625 | }; | ||
626 | |||
627 | struct wl1271_station { | ||
628 | u8 hlid; | ||
629 | }; | ||
630 | |||
631 | int wl1271_plt_start(struct wl1271 *wl); | ||
632 | int wl1271_plt_stop(struct wl1271 *wl); | ||
633 | int wl1271_recalc_rx_streaming(struct wl1271 *wl); | ||
634 | void wl12xx_queue_recovery_work(struct wl1271 *wl); | ||
635 | size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen); | ||
636 | |||
637 | #define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */ | ||
638 | |||
639 | #define SESSION_COUNTER_MAX 7 /* maximum value for the session counter */ | ||
640 | |||
641 | #define WL1271_DEFAULT_POWER_LEVEL 0 | ||
642 | |||
643 | #define WL1271_TX_QUEUE_LOW_WATERMARK 32 | ||
644 | #define WL1271_TX_QUEUE_HIGH_WATERMARK 256 | ||
645 | |||
646 | #define WL1271_DEFERRED_QUEUE_LIMIT 64 | ||
647 | |||
648 | /* WL1271 needs a 200ms sleep after power on, and a 20ms sleep before power | ||
649 | on in case is has been shut down shortly before */ | ||
650 | #define WL1271_PRE_POWER_ON_SLEEP 20 /* in milliseconds */ | ||
651 | #define WL1271_POWER_ON_SLEEP 200 /* in milliseconds */ | ||
652 | |||
653 | /* Macros to handle wl1271.sta_rate_set */ | ||
654 | #define HW_BG_RATES_MASK 0xffff | ||
655 | #define HW_HT_RATES_OFFSET 16 | ||
656 | |||
657 | /* Quirks */ | ||
658 | |||
659 | /* Each RX/TX transaction requires an end-of-transaction transfer */ | ||
660 | #define WL12XX_QUIRK_END_OF_TRANSACTION BIT(0) | ||
661 | |||
662 | /* | ||
663 | * Older firmwares use 2 spare TX blocks | ||
664 | * (for STA < 6.1.3.50.58 or for AP < 6.2.0.0.47) | ||
665 | */ | ||
666 | #define WL12XX_QUIRK_USE_2_SPARE_BLOCKS BIT(1) | ||
667 | |||
668 | /* WL128X requires aggregated packets to be aligned to the SDIO block size */ | ||
669 | #define WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT BIT(2) | ||
670 | |||
671 | /* | ||
672 | * WL127X AP mode requires Low Power DRPw (LPD) enable to reduce power | ||
673 | * consumption | ||
674 | */ | ||
675 | #define WL12XX_QUIRK_LPD_MODE BIT(3) | ||
676 | |||
677 | /* Older firmwares did not implement the FW logger over bus feature */ | ||
678 | #define WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED BIT(4) | ||
679 | |||
680 | #define WL12XX_HW_BLOCK_SIZE 256 | ||
681 | |||
682 | #endif | ||
diff --git a/drivers/net/wireless/wl12xx/wl12xx_80211.h b/drivers/net/wireless/wl12xx/wl12xx_80211.h new file mode 100644 index 00000000000..18fe542360f --- /dev/null +++ b/drivers/net/wireless/wl12xx/wl12xx_80211.h | |||
@@ -0,0 +1,167 @@ | |||
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 */ | ||
61 | struct 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 | |||
71 | struct wl12xx_ie_header { | ||
72 | u8 id; | ||
73 | u8 len; | ||
74 | } __packed; | ||
75 | |||
76 | /* IEs */ | ||
77 | |||
78 | struct wl12xx_ie_ssid { | ||
79 | struct wl12xx_ie_header header; | ||
80 | char ssid[IW_ESSID_MAX_SIZE]; | ||
81 | } __packed; | ||
82 | |||
83 | struct wl12xx_ie_rates { | ||
84 | struct wl12xx_ie_header header; | ||
85 | u8 rates[MAX_SUPPORTED_RATES]; | ||
86 | } __packed; | ||
87 | |||
88 | struct wl12xx_ie_ds_params { | ||
89 | struct wl12xx_ie_header header; | ||
90 | u8 channel; | ||
91 | } __packed; | ||
92 | |||
93 | struct country_triplet { | ||
94 | u8 channel; | ||
95 | u8 num_channels; | ||
96 | u8 max_tx_power; | ||
97 | } __packed; | ||
98 | |||
99 | struct 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 | |||
108 | struct wl12xx_beacon_template { | ||
109 | struct ieee80211_header header; | ||
110 | __le32 time_stamp[2]; | ||
111 | __le16 beacon_interval; | ||
112 | __le16 capability; | ||
113 | struct wl12xx_ie_ssid ssid; | ||
114 | struct wl12xx_ie_rates rates; | ||
115 | struct wl12xx_ie_rates ext_rates; | ||
116 | struct wl12xx_ie_ds_params ds_params; | ||
117 | struct wl12xx_ie_country country; | ||
118 | } __packed; | ||
119 | |||
120 | struct wl12xx_null_data_template { | ||
121 | struct ieee80211_header header; | ||
122 | } __packed; | ||
123 | |||
124 | struct wl12xx_ps_poll_template { | ||
125 | __le16 fc; | ||
126 | __le16 aid; | ||
127 | u8 bssid[ETH_ALEN]; | ||
128 | u8 ta[ETH_ALEN]; | ||
129 | } __packed; | ||
130 | |||
131 | struct wl12xx_qos_null_data_template { | ||
132 | struct ieee80211_header header; | ||
133 | __le16 qos_ctl; | ||
134 | } __packed; | ||
135 | |||
136 | struct wl12xx_arp_rsp_template { | ||
137 | struct ieee80211_hdr_3addr hdr; | ||
138 | |||
139 | u8 llc_hdr[sizeof(rfc1042_header)]; | ||
140 | __be16 llc_type; | ||
141 | |||
142 | struct arphdr arp_hdr; | ||
143 | u8 sender_hw[ETH_ALEN]; | ||
144 | __be32 sender_ip; | ||
145 | u8 target_hw[ETH_ALEN]; | ||
146 | __be32 target_ip; | ||
147 | } __packed; | ||
148 | |||
149 | |||
150 | struct wl12xx_probe_resp_template { | ||
151 | struct ieee80211_header header; | ||
152 | __le32 time_stamp[2]; | ||
153 | __le16 beacon_interval; | ||
154 | __le16 capability; | ||
155 | struct wl12xx_ie_ssid ssid; | ||
156 | struct wl12xx_ie_rates rates; | ||
157 | struct wl12xx_ie_rates ext_rates; | ||
158 | struct wl12xx_ie_ds_params ds_params; | ||
159 | struct wl12xx_ie_country country; | ||
160 | } __packed; | ||
161 | |||
162 | struct wl12xx_disconn_template { | ||
163 | struct ieee80211_header header; | ||
164 | __le16 disconn_reason; | ||
165 | } __packed; | ||
166 | |||
167 | #endif | ||
diff --git a/drivers/net/wireless/wl12xx/wl12xx_platform_data.c b/drivers/net/wireless/wl12xx/wl12xx_platform_data.c new file mode 100644 index 00000000000..973b11060a8 --- /dev/null +++ b/drivers/net/wireless/wl12xx/wl12xx_platform_data.c | |||
@@ -0,0 +1,28 @@ | |||
1 | #include <linux/module.h> | ||
2 | #include <linux/err.h> | ||
3 | #include <linux/wl12xx.h> | ||
4 | |||
5 | static const struct wl12xx_platform_data *platform_data; | ||
6 | |||
7 | int __init wl12xx_set_platform_data(const struct wl12xx_platform_data *data) | ||
8 | { | ||
9 | if (platform_data) | ||
10 | return -EBUSY; | ||
11 | if (!data) | ||
12 | return -EINVAL; | ||
13 | |||
14 | platform_data = kmemdup(data, sizeof(*data), GFP_KERNEL); | ||
15 | if (!platform_data) | ||
16 | return -ENOMEM; | ||
17 | |||
18 | return 0; | ||
19 | } | ||
20 | |||
21 | const struct wl12xx_platform_data *wl12xx_get_platform_data(void) | ||
22 | { | ||
23 | if (!platform_data) | ||
24 | return ERR_PTR(-ENODEV); | ||
25 | |||
26 | return platform_data; | ||
27 | } | ||
28 | EXPORT_SYMBOL(wl12xx_get_platform_data); | ||