blob: 880c82894f63202a0c524817e71b88351a9c5c36 [file] [log] [blame]
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001/*
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 "wl1271_acx.h"
25
26#include <linux/module.h>
27#include <linux/platform_device.h>
28#include <linux/crc7.h>
29#include <linux/spi/spi.h>
30
31#include "wl1271.h"
32#include "wl12xx_80211.h"
33#include "wl1271_reg.h"
34#include "wl1271_spi.h"
35#include "wl1271_ps.h"
36
Juuso Oikarinen51f2be22009-10-13 12:47:42 +030037int wl1271_acx_wake_up_conditions(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030038{
39 struct acx_wake_up_condition *wake_up;
40 int ret;
41
42 wl1271_debug(DEBUG_ACX, "acx wake up conditions");
43
44 wake_up = kzalloc(sizeof(*wake_up), GFP_KERNEL);
45 if (!wake_up) {
46 ret = -ENOMEM;
47 goto out;
48 }
49
Juuso Oikarinen51f2be22009-10-13 12:47:42 +030050 wake_up->wake_up_event = wl->conf.conn.wake_up_event;
51 wake_up->listen_interval = wl->conf.conn.listen_interval;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030052
53 ret = wl1271_cmd_configure(wl, ACX_WAKE_UP_CONDITIONS,
54 wake_up, sizeof(*wake_up));
55 if (ret < 0) {
56 wl1271_warning("could not set wake up conditions: %d", ret);
57 goto out;
58 }
59
60out:
61 kfree(wake_up);
62 return ret;
63}
64
65int wl1271_acx_sleep_auth(struct wl1271 *wl, u8 sleep_auth)
66{
67 struct acx_sleep_auth *auth;
68 int ret;
69
70 wl1271_debug(DEBUG_ACX, "acx sleep auth");
71
72 auth = kzalloc(sizeof(*auth), GFP_KERNEL);
73 if (!auth) {
74 ret = -ENOMEM;
75 goto out;
76 }
77
78 auth->sleep_auth = sleep_auth;
79
80 ret = wl1271_cmd_configure(wl, ACX_SLEEP_AUTH, auth, sizeof(*auth));
81 if (ret < 0)
82 return ret;
83
84out:
85 kfree(auth);
86 return ret;
87}
88
89int wl1271_acx_fw_version(struct wl1271 *wl, char *buf, size_t len)
90{
91 struct acx_revision *rev;
92 int ret;
93
94 wl1271_debug(DEBUG_ACX, "acx fw rev");
95
96 rev = kzalloc(sizeof(*rev), GFP_KERNEL);
97 if (!rev) {
98 ret = -ENOMEM;
99 goto out;
100 }
101
102 ret = wl1271_cmd_interrogate(wl, ACX_FW_REV, rev, sizeof(*rev));
103 if (ret < 0) {
104 wl1271_warning("ACX_FW_REV interrogate failed");
105 goto out;
106 }
107
108 /* be careful with the buffer sizes */
109 strncpy(buf, rev->fw_version, min(len, sizeof(rev->fw_version)));
110
111 /*
112 * if the firmware version string is exactly
113 * sizeof(rev->fw_version) long or fw_len is less than
114 * sizeof(rev->fw_version) it won't be null terminated
115 */
116 buf[min(len, sizeof(rev->fw_version)) - 1] = '\0';
117
118out:
119 kfree(rev);
120 return ret;
121}
122
123int wl1271_acx_tx_power(struct wl1271 *wl, int power)
124{
125 struct acx_current_tx_power *acx;
126 int ret;
127
128 wl1271_debug(DEBUG_ACX, "acx dot11_cur_tx_pwr");
129
130 if (power < 0 || power > 25)
131 return -EINVAL;
132
133 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
134 if (!acx) {
135 ret = -ENOMEM;
136 goto out;
137 }
138
Luciano Coelhoac784032009-10-12 15:08:44 +0300139 /*
140 * FIXME: This is a workaround needed while we don't the correct
141 * calibration, to avoid distortions
142 */
143 /* acx->current_tx_power = power * 10; */
144 acx->current_tx_power = 70;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300145
146 ret = wl1271_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx));
147 if (ret < 0) {
148 wl1271_warning("configure of tx power failed: %d", ret);
149 goto out;
150 }
151
152out:
153 kfree(acx);
154 return ret;
155}
156
157int wl1271_acx_feature_cfg(struct wl1271 *wl)
158{
159 struct acx_feature_config *feature;
160 int ret;
161
162 wl1271_debug(DEBUG_ACX, "acx feature cfg");
163
164 feature = kzalloc(sizeof(*feature), GFP_KERNEL);
165 if (!feature) {
166 ret = -ENOMEM;
167 goto out;
168 }
169
170 /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */
171 feature->data_flow_options = 0;
172 feature->options = 0;
173
174 ret = wl1271_cmd_configure(wl, ACX_FEATURE_CFG,
175 feature, sizeof(*feature));
176 if (ret < 0) {
177 wl1271_error("Couldnt set HW encryption");
178 goto out;
179 }
180
181out:
182 kfree(feature);
183 return ret;
184}
185
186int wl1271_acx_mem_map(struct wl1271 *wl, struct acx_header *mem_map,
187 size_t len)
188{
189 int ret;
190
191 wl1271_debug(DEBUG_ACX, "acx mem map");
192
193 ret = wl1271_cmd_interrogate(wl, ACX_MEM_MAP, mem_map, len);
194 if (ret < 0)
195 return ret;
196
197 return 0;
198}
199
Juuso Oikarinen8793f9b2009-10-13 12:47:40 +0300200int wl1271_acx_rx_msdu_life_time(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300201{
202 struct acx_rx_msdu_lifetime *acx;
203 int ret;
204
205 wl1271_debug(DEBUG_ACX, "acx rx msdu life time");
206
207 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
208 if (!acx) {
209 ret = -ENOMEM;
210 goto out;
211 }
212
Juuso Oikarinen8793f9b2009-10-13 12:47:40 +0300213 acx->lifetime = wl->conf.rx.rx_msdu_life_time;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300214 ret = wl1271_cmd_configure(wl, DOT11_RX_MSDU_LIFE_TIME,
215 acx, sizeof(*acx));
216 if (ret < 0) {
217 wl1271_warning("failed to set rx msdu life time: %d", ret);
218 goto out;
219 }
220
221out:
222 kfree(acx);
223 return ret;
224}
225
226int wl1271_acx_rx_config(struct wl1271 *wl, u32 config, u32 filter)
227{
228 struct acx_rx_config *rx_config;
229 int ret;
230
231 wl1271_debug(DEBUG_ACX, "acx rx config");
232
233 rx_config = kzalloc(sizeof(*rx_config), GFP_KERNEL);
234 if (!rx_config) {
235 ret = -ENOMEM;
236 goto out;
237 }
238
239 rx_config->config_options = config;
240 rx_config->filter_options = filter;
241
242 ret = wl1271_cmd_configure(wl, ACX_RX_CFG,
243 rx_config, sizeof(*rx_config));
244 if (ret < 0) {
245 wl1271_warning("failed to set rx config: %d", ret);
246 goto out;
247 }
248
249out:
250 kfree(rx_config);
251 return ret;
252}
253
254int wl1271_acx_pd_threshold(struct wl1271 *wl)
255{
256 struct acx_packet_detection *pd;
257 int ret;
258
259 wl1271_debug(DEBUG_ACX, "acx data pd threshold");
260
261 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
262 if (!pd) {
263 ret = -ENOMEM;
264 goto out;
265 }
266
Juuso Oikarinen8793f9b2009-10-13 12:47:40 +0300267 pd->threshold = wl->conf.rx.packet_detection_threshold;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300268
269 ret = wl1271_cmd_configure(wl, ACX_PD_THRESHOLD, pd, sizeof(*pd));
270 if (ret < 0) {
271 wl1271_warning("failed to set pd threshold: %d", ret);
272 goto out;
273 }
274
275out:
276 kfree(pd);
277 return 0;
278}
279
280int wl1271_acx_slot(struct wl1271 *wl, enum acx_slot_type slot_time)
281{
282 struct acx_slot *slot;
283 int ret;
284
285 wl1271_debug(DEBUG_ACX, "acx slot");
286
287 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
288 if (!slot) {
289 ret = -ENOMEM;
290 goto out;
291 }
292
293 slot->wone_index = STATION_WONE_INDEX;
294 slot->slot_time = slot_time;
295
296 ret = wl1271_cmd_configure(wl, ACX_SLOT, slot, sizeof(*slot));
297 if (ret < 0) {
298 wl1271_warning("failed to set slot time: %d", ret);
299 goto out;
300 }
301
302out:
303 kfree(slot);
304 return ret;
305}
306
Juuso Oikarinenc87dec92009-10-08 21:56:31 +0300307int wl1271_acx_group_address_tbl(struct wl1271 *wl, bool enable,
308 void *mc_list, u32 mc_list_len)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300309{
310 struct acx_dot11_grp_addr_tbl *acx;
311 int ret;
312
313 wl1271_debug(DEBUG_ACX, "acx group address tbl");
314
315 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
316 if (!acx) {
317 ret = -ENOMEM;
318 goto out;
319 }
320
321 /* MAC filtering */
Juuso Oikarinenc87dec92009-10-08 21:56:31 +0300322 acx->enabled = enable;
323 acx->num_groups = mc_list_len;
324 memcpy(acx->mac_table, mc_list, mc_list_len * ETH_ALEN);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300325
326 ret = wl1271_cmd_configure(wl, DOT11_GROUP_ADDRESS_TBL,
327 acx, sizeof(*acx));
328 if (ret < 0) {
329 wl1271_warning("failed to set group addr table: %d", ret);
330 goto out;
331 }
332
333out:
334 kfree(acx);
335 return ret;
336}
337
338int wl1271_acx_service_period_timeout(struct wl1271 *wl)
339{
340 struct acx_rx_timeout *rx_timeout;
341 int ret;
342
343 rx_timeout = kzalloc(sizeof(*rx_timeout), GFP_KERNEL);
344 if (!rx_timeout) {
345 ret = -ENOMEM;
346 goto out;
347 }
348
349 wl1271_debug(DEBUG_ACX, "acx service period timeout");
350
Juuso Oikarinen8793f9b2009-10-13 12:47:40 +0300351 rx_timeout->ps_poll_timeout = wl->conf.rx.ps_poll_timeout;
352 rx_timeout->upsd_timeout = wl->conf.rx.upsd_timeout;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300353
354 ret = wl1271_cmd_configure(wl, ACX_SERVICE_PERIOD_TIMEOUT,
355 rx_timeout, sizeof(*rx_timeout));
356 if (ret < 0) {
357 wl1271_warning("failed to set service period timeout: %d",
358 ret);
359 goto out;
360 }
361
362out:
363 kfree(rx_timeout);
364 return ret;
365}
366
367int wl1271_acx_rts_threshold(struct wl1271 *wl, u16 rts_threshold)
368{
369 struct acx_rts_threshold *rts;
370 int ret;
371
372 wl1271_debug(DEBUG_ACX, "acx rts threshold");
373
374 rts = kzalloc(sizeof(*rts), GFP_KERNEL);
375 if (!rts) {
376 ret = -ENOMEM;
377 goto out;
378 }
379
380 rts->threshold = rts_threshold;
381
382 ret = wl1271_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts));
383 if (ret < 0) {
384 wl1271_warning("failed to set rts threshold: %d", ret);
385 goto out;
386 }
387
388out:
389 kfree(rts);
390 return ret;
391}
392
Juuso Oikarinen19221672009-10-08 21:56:35 +0300393int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, bool enable_filter)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300394{
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300395 struct acx_beacon_filter_option *beacon_filter = NULL;
396 int ret = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300397
398 wl1271_debug(DEBUG_ACX, "acx beacon filter opt");
399
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300400 if (enable_filter &&
401 wl->conf.conn.bcn_filt_mode == CONF_BCN_FILT_MODE_DISABLED)
402 goto out;
403
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300404 beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL);
405 if (!beacon_filter) {
406 ret = -ENOMEM;
407 goto out;
408 }
409
Juuso Oikarinen19221672009-10-08 21:56:35 +0300410 beacon_filter->enable = enable_filter;
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300411
412 /*
413 * When set to zero, and the filter is enabled, beacons
414 * without the unicast TIM bit set are dropped.
415 */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300416 beacon_filter->max_num_beacons = 0;
417
418 ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_OPT,
419 beacon_filter, sizeof(*beacon_filter));
420 if (ret < 0) {
421 wl1271_warning("failed to set beacon filter opt: %d", ret);
422 goto out;
423 }
424
425out:
426 kfree(beacon_filter);
427 return ret;
428}
429
430int wl1271_acx_beacon_filter_table(struct wl1271 *wl)
431{
432 struct acx_beacon_filter_ie_table *ie_table;
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300433 int i, idx = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300434 int ret;
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300435 bool vendor_spec = false;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300436
437 wl1271_debug(DEBUG_ACX, "acx beacon filter table");
438
439 ie_table = kzalloc(sizeof(*ie_table), GFP_KERNEL);
440 if (!ie_table) {
441 ret = -ENOMEM;
442 goto out;
443 }
444
Juuso Oikarinen19221672009-10-08 21:56:35 +0300445 /* configure default beacon pass-through rules */
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300446 ie_table->num_ie = 0;
447 for (i = 0; i < wl->conf.conn.bcn_filt_ie_count; i++) {
448 struct conf_bcn_filt_rule *r = &(wl->conf.conn.bcn_filt_ie[i]);
449 ie_table->table[idx++] = r->ie;
450 ie_table->table[idx++] = r->rule;
451
452 if (r->ie == WLAN_EID_VENDOR_SPECIFIC) {
453 /* only one vendor specific ie allowed */
454 if (vendor_spec)
455 continue;
456
457 /* for vendor specific rules configure the
458 additional fields */
459 memcpy(&(ie_table->table[idx]), r->oui,
460 CONF_BCN_IE_OUI_LEN);
461 idx += CONF_BCN_IE_OUI_LEN;
462 ie_table->table[idx++] = r->type;
463 memcpy(&(ie_table->table[idx]), r->version,
464 CONF_BCN_IE_VER_LEN);
465 idx += CONF_BCN_IE_VER_LEN;
466 vendor_spec = true;
467 }
468
469 ie_table->num_ie++;
470 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300471
472 ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_TABLE,
473 ie_table, sizeof(*ie_table));
474 if (ret < 0) {
475 wl1271_warning("failed to set beacon filter table: %d", ret);
476 goto out;
477 }
478
479out:
480 kfree(ie_table);
481 return ret;
482}
483
Juuso Oikarinen34415232009-10-08 21:56:33 +0300484int wl1271_acx_conn_monit_params(struct wl1271 *wl)
485{
486 struct acx_conn_monit_params *acx;
487 int ret;
488
489 wl1271_debug(DEBUG_ACX, "acx connection monitor parameters");
490
491 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
492 if (!acx) {
493 ret = -ENOMEM;
494 goto out;
495 }
496
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300497 acx->synch_fail_thold = wl->conf.conn.synch_fail_thold;
498 acx->bss_lose_timeout = wl->conf.conn.bss_lose_timeout;
Juuso Oikarinen34415232009-10-08 21:56:33 +0300499
500 ret = wl1271_cmd_configure(wl, ACX_CONN_MONIT_PARAMS,
501 acx, sizeof(*acx));
502 if (ret < 0) {
503 wl1271_warning("failed to set connection monitor "
504 "parameters: %d", ret);
505 goto out;
506 }
507
508out:
509 kfree(acx);
510 return ret;
511}
512
513
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300514int wl1271_acx_sg_enable(struct wl1271 *wl)
515{
516 struct acx_bt_wlan_coex *pta;
517 int ret;
518
519 wl1271_debug(DEBUG_ACX, "acx sg enable");
520
521 pta = kzalloc(sizeof(*pta), GFP_KERNEL);
522 if (!pta) {
523 ret = -ENOMEM;
524 goto out;
525 }
526
527 pta->enable = SG_ENABLE;
528
529 ret = wl1271_cmd_configure(wl, ACX_SG_ENABLE, pta, sizeof(*pta));
530 if (ret < 0) {
531 wl1271_warning("failed to set softgemini enable: %d", ret);
532 goto out;
533 }
534
535out:
536 kfree(pta);
537 return ret;
538}
539
540int wl1271_acx_sg_cfg(struct wl1271 *wl)
541{
542 struct acx_bt_wlan_coex_param *param;
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +0300543 struct conf_sg_settings *c = &wl->conf.sg;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300544 int ret;
545
546 wl1271_debug(DEBUG_ACX, "acx sg cfg");
547
548 param = kzalloc(sizeof(*param), GFP_KERNEL);
549 if (!param) {
550 ret = -ENOMEM;
551 goto out;
552 }
553
554 /* BT-WLAN coext parameters */
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +0300555 param->per_threshold = c->per_threshold;
556 param->max_scan_compensation_time = c->max_scan_compensation_time;
557 param->nfs_sample_interval = c->nfs_sample_interval;
558 param->load_ratio = c->load_ratio;
559 param->auto_ps_mode = c->auto_ps_mode;
560 param->probe_req_compensation = c->probe_req_compensation;
561 param->scan_window_compensation = c->scan_window_compensation;
562 param->antenna_config = c->antenna_config;
563 param->beacon_miss_threshold = c->beacon_miss_threshold;
564 param->rate_adaptation_threshold = c->rate_adaptation_threshold;
565 param->rate_adaptation_snr = c->rate_adaptation_snr;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300566
567 ret = wl1271_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param));
568 if (ret < 0) {
569 wl1271_warning("failed to set sg config: %d", ret);
570 goto out;
571 }
572
573out:
574 kfree(param);
575 return ret;
576}
577
578int wl1271_acx_cca_threshold(struct wl1271 *wl)
579{
580 struct acx_energy_detection *detection;
581 int ret;
582
583 wl1271_debug(DEBUG_ACX, "acx cca threshold");
584
585 detection = kzalloc(sizeof(*detection), GFP_KERNEL);
586 if (!detection) {
587 ret = -ENOMEM;
588 goto out;
589 }
590
Juuso Oikarinen8793f9b2009-10-13 12:47:40 +0300591 detection->rx_cca_threshold = wl->conf.rx.rx_cca_threshold;
Juuso Oikarinen45b531a2009-10-13 12:47:41 +0300592 detection->tx_energy_detection = wl->conf.tx.tx_energy_detection;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300593
594 ret = wl1271_cmd_configure(wl, ACX_CCA_THRESHOLD,
595 detection, sizeof(*detection));
596 if (ret < 0) {
597 wl1271_warning("failed to set cca threshold: %d", ret);
598 return ret;
599 }
600
601out:
602 kfree(detection);
603 return ret;
604}
605
606int wl1271_acx_bcn_dtim_options(struct wl1271 *wl)
607{
608 struct acx_beacon_broadcast *bb;
609 int ret;
610
611 wl1271_debug(DEBUG_ACX, "acx bcn dtim options");
612
613 bb = kzalloc(sizeof(*bb), GFP_KERNEL);
614 if (!bb) {
615 ret = -ENOMEM;
616 goto out;
617 }
618
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300619 bb->beacon_rx_timeout = wl->conf.conn.beacon_rx_timeout;
620 bb->broadcast_timeout = wl->conf.conn.broadcast_timeout;
621 bb->rx_broadcast_in_ps = wl->conf.conn.rx_broadcast_in_ps;
622 bb->ps_poll_threshold = wl->conf.conn.ps_poll_threshold;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300623
624 ret = wl1271_cmd_configure(wl, ACX_BCN_DTIM_OPTIONS, bb, sizeof(*bb));
625 if (ret < 0) {
626 wl1271_warning("failed to set rx config: %d", ret);
627 goto out;
628 }
629
630out:
631 kfree(bb);
632 return ret;
633}
634
635int wl1271_acx_aid(struct wl1271 *wl, u16 aid)
636{
637 struct acx_aid *acx_aid;
638 int ret;
639
640 wl1271_debug(DEBUG_ACX, "acx aid");
641
642 acx_aid = kzalloc(sizeof(*acx_aid), GFP_KERNEL);
643 if (!acx_aid) {
644 ret = -ENOMEM;
645 goto out;
646 }
647
648 acx_aid->aid = aid;
649
650 ret = wl1271_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid));
651 if (ret < 0) {
652 wl1271_warning("failed to set aid: %d", ret);
653 goto out;
654 }
655
656out:
657 kfree(acx_aid);
658 return ret;
659}
660
661int wl1271_acx_event_mbox_mask(struct wl1271 *wl, u32 event_mask)
662{
663 struct acx_event_mask *mask;
664 int ret;
665
666 wl1271_debug(DEBUG_ACX, "acx event mbox mask");
667
668 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
669 if (!mask) {
670 ret = -ENOMEM;
671 goto out;
672 }
673
674 /* high event mask is unused */
675 mask->high_event_mask = 0xffffffff;
676
677 mask->event_mask = event_mask;
678
679 ret = wl1271_cmd_configure(wl, ACX_EVENT_MBOX_MASK,
680 mask, sizeof(*mask));
681 if (ret < 0) {
682 wl1271_warning("failed to set acx_event_mbox_mask: %d", ret);
683 goto out;
684 }
685
686out:
687 kfree(mask);
688 return ret;
689}
690
691int wl1271_acx_set_preamble(struct wl1271 *wl, enum acx_preamble_type preamble)
692{
693 struct acx_preamble *acx;
694 int ret;
695
696 wl1271_debug(DEBUG_ACX, "acx_set_preamble");
697
698 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
699 if (!acx) {
700 ret = -ENOMEM;
701 goto out;
702 }
703
704 acx->preamble = preamble;
705
706 ret = wl1271_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx));
707 if (ret < 0) {
708 wl1271_warning("Setting of preamble failed: %d", ret);
709 goto out;
710 }
711
712out:
713 kfree(acx);
714 return ret;
715}
716
717int wl1271_acx_cts_protect(struct wl1271 *wl,
718 enum acx_ctsprotect_type ctsprotect)
719{
720 struct acx_ctsprotect *acx;
721 int ret;
722
723 wl1271_debug(DEBUG_ACX, "acx_set_ctsprotect");
724
725 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
726 if (!acx) {
727 ret = -ENOMEM;
728 goto out;
729 }
730
731 acx->ctsprotect = ctsprotect;
732
733 ret = wl1271_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx));
734 if (ret < 0) {
735 wl1271_warning("Setting of ctsprotect failed: %d", ret);
736 goto out;
737 }
738
739out:
740 kfree(acx);
741 return ret;
742}
743
744int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats)
745{
746 int ret;
747
748 wl1271_debug(DEBUG_ACX, "acx statistics");
749
750 ret = wl1271_cmd_interrogate(wl, ACX_STATISTICS, stats,
751 sizeof(*stats));
752 if (ret < 0) {
753 wl1271_warning("acx statistics failed: %d", ret);
754 return -ENOMEM;
755 }
756
757 return 0;
758}
759
Juuso Oikarinen8a5a37a2009-10-08 21:56:24 +0300760int wl1271_acx_rate_policies(struct wl1271 *wl, u32 enabled_rates)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300761{
762 struct acx_rate_policy *acx;
Juuso Oikarinen45b531a2009-10-13 12:47:41 +0300763 struct conf_tx_rate_class *c = &wl->conf.tx.rc_conf;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300764 int ret = 0;
765
766 wl1271_debug(DEBUG_ACX, "acx rate policies");
767
768 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
769
770 if (!acx) {
771 ret = -ENOMEM;
772 goto out;
773 }
774
775 /* configure one default (one-size-fits-all) rate class */
776 acx->rate_class_cnt = 1;
Juuso Oikarinen8a5a37a2009-10-08 21:56:24 +0300777 acx->rate_class[0].enabled_rates = enabled_rates;
Juuso Oikarinen45b531a2009-10-13 12:47:41 +0300778 acx->rate_class[0].short_retry_limit = c->short_retry_limit;
779 acx->rate_class[0].long_retry_limit = c->long_retry_limit;
780 acx->rate_class[0].aflags = c->aflags;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300781
782 ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
783 if (ret < 0) {
784 wl1271_warning("Setting of rate policies failed: %d", ret);
785 goto out;
786 }
787
788out:
789 kfree(acx);
790 return ret;
791}
792
793int wl1271_acx_ac_cfg(struct wl1271 *wl)
794{
795 struct acx_ac_cfg *acx;
796 int i, ret = 0;
797
798 wl1271_debug(DEBUG_ACX, "acx access category config");
799
800 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
801
802 if (!acx) {
803 ret = -ENOMEM;
804 goto out;
805 }
806
Juuso Oikarinen45b531a2009-10-13 12:47:41 +0300807 for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
808 struct conf_tx_ac_category *c = &(wl->conf.tx.ac_conf[i]);
809 acx->ac = c->ac;
810 acx->cw_min = c->cw_min;
811 acx->cw_max = c->cw_max;
812 acx->aifsn = c->aifsn;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300813 acx->reserved = 0;
Juuso Oikarinen45b531a2009-10-13 12:47:41 +0300814 acx->tx_op_limit = c->tx_op_limit;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300815
816 ret = wl1271_cmd_configure(wl, ACX_AC_CFG, acx, sizeof(*acx));
817 if (ret < 0) {
818 wl1271_warning("Setting of access category "
819 "config: %d", ret);
820 goto out;
821 }
822 }
823
824out:
825 kfree(acx);
826 return ret;
827}
828
829int wl1271_acx_tid_cfg(struct wl1271 *wl)
830{
831 struct acx_tid_config *acx;
832 int i, ret = 0;
833
834 wl1271_debug(DEBUG_ACX, "acx tid config");
835
836 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
837
838 if (!acx) {
839 ret = -ENOMEM;
840 goto out;
841 }
842
Juuso Oikarinen45b531a2009-10-13 12:47:41 +0300843 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
844 struct conf_tx_tid *c = &(wl->conf.tx.tid_conf[i]);
845 acx->queue_id = c->queue_id;
846 acx->channel_type = c->channel_type;
847 acx->tsid = c->tsid;
848 acx->ps_scheme = c->ps_scheme;
849 acx->ack_policy = c->ack_policy;
850 acx->apsd_conf[0] = c->apsd_conf[0];
851 acx->apsd_conf[1] = c->apsd_conf[1];
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300852
853 ret = wl1271_cmd_configure(wl, ACX_TID_CFG, acx, sizeof(*acx));
854 if (ret < 0) {
855 wl1271_warning("Setting of tid config failed: %d", ret);
856 goto out;
857 }
858 }
859
860out:
861 kfree(acx);
862 return ret;
863}
864
865int wl1271_acx_frag_threshold(struct wl1271 *wl)
866{
867 struct acx_frag_threshold *acx;
868 int ret = 0;
869
870 wl1271_debug(DEBUG_ACX, "acx frag threshold");
871
872 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
873
874 if (!acx) {
875 ret = -ENOMEM;
876 goto out;
877 }
878
Juuso Oikarinen45b531a2009-10-13 12:47:41 +0300879 acx->frag_threshold = wl->conf.tx.frag_threshold;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300880 ret = wl1271_cmd_configure(wl, ACX_FRAG_CFG, acx, sizeof(*acx));
881 if (ret < 0) {
882 wl1271_warning("Setting of frag threshold failed: %d", ret);
883 goto out;
884 }
885
886out:
887 kfree(acx);
888 return ret;
889}
890
891int wl1271_acx_tx_config_options(struct wl1271 *wl)
892{
893 struct acx_tx_config_options *acx;
894 int ret = 0;
895
896 wl1271_debug(DEBUG_ACX, "acx tx config options");
897
898 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
899
900 if (!acx) {
901 ret = -ENOMEM;
902 goto out;
903 }
904
Juuso Oikarinen45b531a2009-10-13 12:47:41 +0300905 acx->tx_compl_timeout = wl->conf.tx.tx_compl_timeout;
906 acx->tx_compl_threshold = wl->conf.tx.tx_compl_threshold;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300907 ret = wl1271_cmd_configure(wl, ACX_TX_CONFIG_OPT, acx, sizeof(*acx));
908 if (ret < 0) {
909 wl1271_warning("Setting of tx options failed: %d", ret);
910 goto out;
911 }
912
913out:
914 kfree(acx);
915 return ret;
916}
917
918int wl1271_acx_mem_cfg(struct wl1271 *wl)
919{
920 struct wl1271_acx_config_memory *mem_conf;
921 int ret;
922
923 wl1271_debug(DEBUG_ACX, "wl1271 mem cfg");
924
925 mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL);
926 if (!mem_conf) {
927 ret = -ENOMEM;
928 goto out;
929 }
930
931 /* memory config */
932 mem_conf->num_stations = cpu_to_le16(DEFAULT_NUM_STATIONS);
933 mem_conf->rx_mem_block_num = ACX_RX_MEM_BLOCKS;
934 mem_conf->tx_min_mem_block_num = ACX_TX_MIN_MEM_BLOCKS;
935 mem_conf->num_ssid_profiles = ACX_NUM_SSID_PROFILES;
936 mem_conf->total_tx_descriptors = ACX_TX_DESCRIPTORS;
937
938 ret = wl1271_cmd_configure(wl, ACX_MEM_CFG, mem_conf,
939 sizeof(*mem_conf));
940 if (ret < 0) {
941 wl1271_warning("wl1271 mem config failed: %d", ret);
942 goto out;
943 }
944
945out:
946 kfree(mem_conf);
947 return ret;
948}
949
950int wl1271_acx_init_mem_config(struct wl1271 *wl)
951{
952 int ret;
953
954 ret = wl1271_acx_mem_cfg(wl);
955 if (ret < 0)
956 return ret;
957
958 wl->target_mem_map = kzalloc(sizeof(struct wl1271_acx_mem_map),
Juuso Oikarinen45b531a2009-10-13 12:47:41 +0300959 GFP_KERNEL);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300960 if (!wl->target_mem_map) {
961 wl1271_error("couldn't allocate target memory map");
962 return -ENOMEM;
963 }
964
965 /* we now ask for the firmware built memory map */
966 ret = wl1271_acx_mem_map(wl, (void *)wl->target_mem_map,
967 sizeof(struct wl1271_acx_mem_map));
968 if (ret < 0) {
969 wl1271_error("couldn't retrieve firmware memory map");
970 kfree(wl->target_mem_map);
971 wl->target_mem_map = NULL;
972 return ret;
973 }
974
975 /* initialize TX block book keeping */
976 wl->tx_blocks_available = wl->target_mem_map->num_tx_mem_blocks;
977 wl1271_debug(DEBUG_TX, "available tx blocks: %d",
978 wl->tx_blocks_available);
979
980 return 0;
981}
982
983int wl1271_acx_init_rx_interrupt(struct wl1271 *wl)
984{
985 struct wl1271_acx_rx_config_opt *rx_conf;
986 int ret;
987
988 wl1271_debug(DEBUG_ACX, "wl1271 rx interrupt config");
989
990 rx_conf = kzalloc(sizeof(*rx_conf), GFP_KERNEL);
991 if (!rx_conf) {
992 ret = -ENOMEM;
993 goto out;
994 }
995
Juuso Oikarinen8793f9b2009-10-13 12:47:40 +0300996 rx_conf->threshold = wl->conf.rx.irq_pkt_threshold;
997 rx_conf->timeout = wl->conf.rx.irq_timeout;
998 rx_conf->mblk_threshold = wl->conf.rx.irq_blk_threshold;
999 rx_conf->queue_type = wl->conf.rx.queue_type;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001000
1001 ret = wl1271_cmd_configure(wl, ACX_RX_CONFIG_OPT, rx_conf,
1002 sizeof(*rx_conf));
1003 if (ret < 0) {
1004 wl1271_warning("wl1271 rx config opt failed: %d", ret);
1005 goto out;
1006 }
1007
1008out:
1009 kfree(rx_conf);
1010 return ret;
1011}
Juuso Oikarinen3cfd6cf2009-10-12 15:08:52 +03001012
1013int wl1271_acx_smart_reflex(struct wl1271 *wl)
1014{
1015 struct acx_smart_reflex_state *sr_state = NULL;
1016 struct acx_smart_reflex_config_params *sr_param = NULL;
Juuso Oikarinen47fab7d2009-10-13 12:47:43 +03001017 int i, ret;
Juuso Oikarinen3cfd6cf2009-10-12 15:08:52 +03001018
1019 wl1271_debug(DEBUG_ACX, "acx smart reflex");
1020
1021 sr_param = kzalloc(sizeof(*sr_param), GFP_KERNEL);
1022 if (!sr_param) {
1023 ret = -ENOMEM;
1024 goto out;
1025 }
1026
Juuso Oikarinen47fab7d2009-10-13 12:47:43 +03001027 for (i = 0; i < CONF_SR_ERR_TBL_COUNT; i++) {
1028 struct conf_mart_reflex_err_table *e =
1029 &(wl->conf.init.sr_err_tbl[i]);
Juuso Oikarinen3cfd6cf2009-10-12 15:08:52 +03001030
Juuso Oikarinen47fab7d2009-10-13 12:47:43 +03001031 sr_param->error_table[i].len = e->len;
1032 sr_param->error_table[i].upper_limit = e->upper_limit;
1033 memcpy(sr_param->error_table[i].values, e->values, e->len);
1034 }
Juuso Oikarinen3cfd6cf2009-10-12 15:08:52 +03001035
1036 ret = wl1271_cmd_configure(wl, ACX_SET_SMART_REFLEX_PARAMS,
1037 sr_param, sizeof(*sr_param));
1038 if (ret < 0) {
1039 wl1271_warning("failed to set smart reflex params: %d", ret);
1040 goto out;
1041 }
1042
1043 sr_state = kzalloc(sizeof(*sr_state), GFP_KERNEL);
1044 if (!sr_state) {
1045 ret = -ENOMEM;
1046 goto out;
1047 }
1048
1049 /* enable smart reflex */
Juuso Oikarinen47fab7d2009-10-13 12:47:43 +03001050 sr_state->enable = wl->conf.init.sr_enable;
Juuso Oikarinen3cfd6cf2009-10-12 15:08:52 +03001051
1052 ret = wl1271_cmd_configure(wl, ACX_SET_SMART_REFLEX_STATE,
1053 sr_state, sizeof(*sr_state));
1054 if (ret < 0) {
1055 wl1271_warning("failed to set smart reflex params: %d", ret);
1056 goto out;
1057 }
1058
1059out:
1060 kfree(sr_state);
1061 kfree(sr_param);
1062 return ret;
1063
1064}