blob: 60e20876e6d86954acc646d44f304ac36cac472e [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"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030034#include "wl1271_ps.h"
35
Juuso Oikarinen51f2be22009-10-13 12:47:42 +030036int wl1271_acx_wake_up_conditions(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030037{
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
Juuso Oikarinen51f2be22009-10-13 12:47:42 +030049 wake_up->wake_up_event = wl->conf.conn.wake_up_event;
50 wake_up->listen_interval = wl->conf.conn.listen_interval;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030051
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
59out:
60 kfree(wake_up);
61 return ret;
62}
63
64int 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 if (ret < 0)
81 return ret;
82
83out:
84 kfree(auth);
85 return ret;
86}
87
88int wl1271_acx_fw_version(struct wl1271 *wl, char *buf, size_t len)
89{
90 struct acx_revision *rev;
91 int ret;
92
93 wl1271_debug(DEBUG_ACX, "acx fw rev");
94
95 rev = kzalloc(sizeof(*rev), GFP_KERNEL);
96 if (!rev) {
97 ret = -ENOMEM;
98 goto out;
99 }
100
101 ret = wl1271_cmd_interrogate(wl, ACX_FW_REV, rev, sizeof(*rev));
102 if (ret < 0) {
103 wl1271_warning("ACX_FW_REV interrogate failed");
104 goto out;
105 }
106
107 /* be careful with the buffer sizes */
108 strncpy(buf, rev->fw_version, min(len, sizeof(rev->fw_version)));
109
110 /*
111 * if the firmware version string is exactly
112 * sizeof(rev->fw_version) long or fw_len is less than
113 * sizeof(rev->fw_version) it won't be null terminated
114 */
115 buf[min(len, sizeof(rev->fw_version)) - 1] = '\0';
116
117out:
118 kfree(rev);
119 return ret;
120}
121
122int wl1271_acx_tx_power(struct wl1271 *wl, int power)
123{
124 struct acx_current_tx_power *acx;
125 int ret;
126
127 wl1271_debug(DEBUG_ACX, "acx dot11_cur_tx_pwr");
128
129 if (power < 0 || power > 25)
130 return -EINVAL;
131
132 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
133 if (!acx) {
134 ret = -ENOMEM;
135 goto out;
136 }
137
Juuso Oikarinen6f6b5d42010-02-22 08:38:42 +0200138 acx->current_tx_power = power * 10;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300139
140 ret = wl1271_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx));
141 if (ret < 0) {
142 wl1271_warning("configure of tx power failed: %d", ret);
143 goto out;
144 }
145
146out:
147 kfree(acx);
148 return ret;
149}
150
151int wl1271_acx_feature_cfg(struct wl1271 *wl)
152{
153 struct acx_feature_config *feature;
154 int ret;
155
156 wl1271_debug(DEBUG_ACX, "acx feature cfg");
157
158 feature = kzalloc(sizeof(*feature), GFP_KERNEL);
159 if (!feature) {
160 ret = -ENOMEM;
161 goto out;
162 }
163
164 /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */
165 feature->data_flow_options = 0;
166 feature->options = 0;
167
168 ret = wl1271_cmd_configure(wl, ACX_FEATURE_CFG,
169 feature, sizeof(*feature));
170 if (ret < 0) {
171 wl1271_error("Couldnt set HW encryption");
172 goto out;
173 }
174
175out:
176 kfree(feature);
177 return ret;
178}
179
180int wl1271_acx_mem_map(struct wl1271 *wl, struct acx_header *mem_map,
181 size_t len)
182{
183 int ret;
184
185 wl1271_debug(DEBUG_ACX, "acx mem map");
186
187 ret = wl1271_cmd_interrogate(wl, ACX_MEM_MAP, mem_map, len);
188 if (ret < 0)
189 return ret;
190
191 return 0;
192}
193
Juuso Oikarinen8793f9b2009-10-13 12:47:40 +0300194int wl1271_acx_rx_msdu_life_time(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300195{
196 struct acx_rx_msdu_lifetime *acx;
197 int ret;
198
199 wl1271_debug(DEBUG_ACX, "acx rx msdu life time");
200
201 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
202 if (!acx) {
203 ret = -ENOMEM;
204 goto out;
205 }
206
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300207 acx->lifetime = cpu_to_le32(wl->conf.rx.rx_msdu_life_time);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300208 ret = wl1271_cmd_configure(wl, DOT11_RX_MSDU_LIFE_TIME,
209 acx, sizeof(*acx));
210 if (ret < 0) {
211 wl1271_warning("failed to set rx msdu life time: %d", ret);
212 goto out;
213 }
214
215out:
216 kfree(acx);
217 return ret;
218}
219
220int wl1271_acx_rx_config(struct wl1271 *wl, u32 config, u32 filter)
221{
222 struct acx_rx_config *rx_config;
223 int ret;
224
225 wl1271_debug(DEBUG_ACX, "acx rx config");
226
227 rx_config = kzalloc(sizeof(*rx_config), GFP_KERNEL);
228 if (!rx_config) {
229 ret = -ENOMEM;
230 goto out;
231 }
232
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300233 rx_config->config_options = cpu_to_le32(config);
234 rx_config->filter_options = cpu_to_le32(filter);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300235
236 ret = wl1271_cmd_configure(wl, ACX_RX_CFG,
237 rx_config, sizeof(*rx_config));
238 if (ret < 0) {
239 wl1271_warning("failed to set rx config: %d", ret);
240 goto out;
241 }
242
243out:
244 kfree(rx_config);
245 return ret;
246}
247
248int wl1271_acx_pd_threshold(struct wl1271 *wl)
249{
250 struct acx_packet_detection *pd;
251 int ret;
252
253 wl1271_debug(DEBUG_ACX, "acx data pd threshold");
254
255 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
256 if (!pd) {
257 ret = -ENOMEM;
258 goto out;
259 }
260
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300261 pd->threshold = cpu_to_le32(wl->conf.rx.packet_detection_threshold);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300262
263 ret = wl1271_cmd_configure(wl, ACX_PD_THRESHOLD, pd, sizeof(*pd));
264 if (ret < 0) {
265 wl1271_warning("failed to set pd threshold: %d", ret);
266 goto out;
267 }
268
269out:
270 kfree(pd);
271 return 0;
272}
273
274int wl1271_acx_slot(struct wl1271 *wl, enum acx_slot_type slot_time)
275{
276 struct acx_slot *slot;
277 int ret;
278
279 wl1271_debug(DEBUG_ACX, "acx slot");
280
281 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
282 if (!slot) {
283 ret = -ENOMEM;
284 goto out;
285 }
286
287 slot->wone_index = STATION_WONE_INDEX;
288 slot->slot_time = slot_time;
289
290 ret = wl1271_cmd_configure(wl, ACX_SLOT, slot, sizeof(*slot));
291 if (ret < 0) {
292 wl1271_warning("failed to set slot time: %d", ret);
293 goto out;
294 }
295
296out:
297 kfree(slot);
298 return ret;
299}
300
Juuso Oikarinenc87dec92009-10-08 21:56:31 +0300301int wl1271_acx_group_address_tbl(struct wl1271 *wl, bool enable,
302 void *mc_list, u32 mc_list_len)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300303{
304 struct acx_dot11_grp_addr_tbl *acx;
305 int ret;
306
307 wl1271_debug(DEBUG_ACX, "acx group address tbl");
308
309 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
310 if (!acx) {
311 ret = -ENOMEM;
312 goto out;
313 }
314
315 /* MAC filtering */
Juuso Oikarinenc87dec92009-10-08 21:56:31 +0300316 acx->enabled = enable;
317 acx->num_groups = mc_list_len;
318 memcpy(acx->mac_table, mc_list, mc_list_len * ETH_ALEN);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300319
320 ret = wl1271_cmd_configure(wl, DOT11_GROUP_ADDRESS_TBL,
321 acx, sizeof(*acx));
322 if (ret < 0) {
323 wl1271_warning("failed to set group addr table: %d", ret);
324 goto out;
325 }
326
327out:
328 kfree(acx);
329 return ret;
330}
331
332int wl1271_acx_service_period_timeout(struct wl1271 *wl)
333{
334 struct acx_rx_timeout *rx_timeout;
335 int ret;
336
337 rx_timeout = kzalloc(sizeof(*rx_timeout), GFP_KERNEL);
338 if (!rx_timeout) {
339 ret = -ENOMEM;
340 goto out;
341 }
342
343 wl1271_debug(DEBUG_ACX, "acx service period timeout");
344
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300345 rx_timeout->ps_poll_timeout = cpu_to_le16(wl->conf.rx.ps_poll_timeout);
346 rx_timeout->upsd_timeout = cpu_to_le16(wl->conf.rx.upsd_timeout);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300347
348 ret = wl1271_cmd_configure(wl, ACX_SERVICE_PERIOD_TIMEOUT,
349 rx_timeout, sizeof(*rx_timeout));
350 if (ret < 0) {
351 wl1271_warning("failed to set service period timeout: %d",
352 ret);
353 goto out;
354 }
355
356out:
357 kfree(rx_timeout);
358 return ret;
359}
360
361int wl1271_acx_rts_threshold(struct wl1271 *wl, u16 rts_threshold)
362{
363 struct acx_rts_threshold *rts;
364 int ret;
365
366 wl1271_debug(DEBUG_ACX, "acx rts threshold");
367
368 rts = kzalloc(sizeof(*rts), GFP_KERNEL);
369 if (!rts) {
370 ret = -ENOMEM;
371 goto out;
372 }
373
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300374 rts->threshold = cpu_to_le16(rts_threshold);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300375
376 ret = wl1271_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts));
377 if (ret < 0) {
378 wl1271_warning("failed to set rts threshold: %d", ret);
379 goto out;
380 }
381
382out:
383 kfree(rts);
384 return ret;
385}
386
Luciano Coelho6e92b412009-12-11 15:40:50 +0200387int wl1271_acx_dco_itrim_params(struct wl1271 *wl)
388{
389 struct acx_dco_itrim_params *dco;
390 struct conf_itrim_settings *c = &wl->conf.itrim;
391 int ret;
392
393 wl1271_debug(DEBUG_ACX, "acx dco itrim parameters");
394
395 dco = kzalloc(sizeof(*dco), GFP_KERNEL);
396 if (!dco) {
397 ret = -ENOMEM;
398 goto out;
399 }
400
401 dco->enable = c->enable;
402 dco->timeout = cpu_to_le32(c->timeout);
403
404 ret = wl1271_cmd_configure(wl, ACX_SET_DCO_ITRIM_PARAMS,
405 dco, sizeof(*dco));
406 if (ret < 0) {
407 wl1271_warning("failed to set dco itrim parameters: %d", ret);
408 goto out;
409 }
410
411out:
412 kfree(dco);
413 return ret;
414}
415
Juuso Oikarinen19221672009-10-08 21:56:35 +0300416int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, bool enable_filter)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300417{
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300418 struct acx_beacon_filter_option *beacon_filter = NULL;
419 int ret = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300420
421 wl1271_debug(DEBUG_ACX, "acx beacon filter opt");
422
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300423 if (enable_filter &&
424 wl->conf.conn.bcn_filt_mode == CONF_BCN_FILT_MODE_DISABLED)
425 goto out;
426
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300427 beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL);
428 if (!beacon_filter) {
429 ret = -ENOMEM;
430 goto out;
431 }
432
Juuso Oikarinen19221672009-10-08 21:56:35 +0300433 beacon_filter->enable = enable_filter;
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300434
435 /*
436 * When set to zero, and the filter is enabled, beacons
437 * without the unicast TIM bit set are dropped.
438 */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300439 beacon_filter->max_num_beacons = 0;
440
441 ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_OPT,
442 beacon_filter, sizeof(*beacon_filter));
443 if (ret < 0) {
444 wl1271_warning("failed to set beacon filter opt: %d", ret);
445 goto out;
446 }
447
448out:
449 kfree(beacon_filter);
450 return ret;
451}
452
453int wl1271_acx_beacon_filter_table(struct wl1271 *wl)
454{
455 struct acx_beacon_filter_ie_table *ie_table;
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300456 int i, idx = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300457 int ret;
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300458 bool vendor_spec = false;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300459
460 wl1271_debug(DEBUG_ACX, "acx beacon filter table");
461
462 ie_table = kzalloc(sizeof(*ie_table), GFP_KERNEL);
463 if (!ie_table) {
464 ret = -ENOMEM;
465 goto out;
466 }
467
Juuso Oikarinen19221672009-10-08 21:56:35 +0300468 /* configure default beacon pass-through rules */
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300469 ie_table->num_ie = 0;
470 for (i = 0; i < wl->conf.conn.bcn_filt_ie_count; i++) {
471 struct conf_bcn_filt_rule *r = &(wl->conf.conn.bcn_filt_ie[i]);
472 ie_table->table[idx++] = r->ie;
473 ie_table->table[idx++] = r->rule;
474
475 if (r->ie == WLAN_EID_VENDOR_SPECIFIC) {
476 /* only one vendor specific ie allowed */
477 if (vendor_spec)
478 continue;
479
480 /* for vendor specific rules configure the
481 additional fields */
482 memcpy(&(ie_table->table[idx]), r->oui,
483 CONF_BCN_IE_OUI_LEN);
484 idx += CONF_BCN_IE_OUI_LEN;
485 ie_table->table[idx++] = r->type;
486 memcpy(&(ie_table->table[idx]), r->version,
487 CONF_BCN_IE_VER_LEN);
488 idx += CONF_BCN_IE_VER_LEN;
489 vendor_spec = true;
490 }
491
492 ie_table->num_ie++;
493 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300494
495 ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_TABLE,
496 ie_table, sizeof(*ie_table));
497 if (ret < 0) {
498 wl1271_warning("failed to set beacon filter table: %d", ret);
499 goto out;
500 }
501
502out:
503 kfree(ie_table);
504 return ret;
505}
506
Juuso Oikarinen34415232009-10-08 21:56:33 +0300507int wl1271_acx_conn_monit_params(struct wl1271 *wl)
508{
509 struct acx_conn_monit_params *acx;
510 int ret;
511
512 wl1271_debug(DEBUG_ACX, "acx connection monitor parameters");
513
514 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
515 if (!acx) {
516 ret = -ENOMEM;
517 goto out;
518 }
519
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300520 acx->synch_fail_thold = cpu_to_le32(wl->conf.conn.synch_fail_thold);
521 acx->bss_lose_timeout = cpu_to_le32(wl->conf.conn.bss_lose_timeout);
Juuso Oikarinen34415232009-10-08 21:56:33 +0300522
523 ret = wl1271_cmd_configure(wl, ACX_CONN_MONIT_PARAMS,
524 acx, sizeof(*acx));
525 if (ret < 0) {
526 wl1271_warning("failed to set connection monitor "
527 "parameters: %d", ret);
528 goto out;
529 }
530
531out:
532 kfree(acx);
533 return ret;
534}
535
536
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300537int wl1271_acx_sg_enable(struct wl1271 *wl)
538{
539 struct acx_bt_wlan_coex *pta;
540 int ret;
541
542 wl1271_debug(DEBUG_ACX, "acx sg enable");
543
544 pta = kzalloc(sizeof(*pta), GFP_KERNEL);
545 if (!pta) {
546 ret = -ENOMEM;
547 goto out;
548 }
549
550 pta->enable = SG_ENABLE;
551
552 ret = wl1271_cmd_configure(wl, ACX_SG_ENABLE, pta, sizeof(*pta));
553 if (ret < 0) {
554 wl1271_warning("failed to set softgemini enable: %d", ret);
555 goto out;
556 }
557
558out:
559 kfree(pta);
560 return ret;
561}
562
563int wl1271_acx_sg_cfg(struct wl1271 *wl)
564{
565 struct acx_bt_wlan_coex_param *param;
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +0300566 struct conf_sg_settings *c = &wl->conf.sg;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300567 int ret;
568
569 wl1271_debug(DEBUG_ACX, "acx sg cfg");
570
571 param = kzalloc(sizeof(*param), GFP_KERNEL);
572 if (!param) {
573 ret = -ENOMEM;
574 goto out;
575 }
576
577 /* BT-WLAN coext parameters */
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300578 param->per_threshold = cpu_to_le32(c->per_threshold);
579 param->max_scan_compensation_time =
580 cpu_to_le32(c->max_scan_compensation_time);
581 param->nfs_sample_interval = cpu_to_le16(c->nfs_sample_interval);
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +0300582 param->load_ratio = c->load_ratio;
583 param->auto_ps_mode = c->auto_ps_mode;
584 param->probe_req_compensation = c->probe_req_compensation;
585 param->scan_window_compensation = c->scan_window_compensation;
586 param->antenna_config = c->antenna_config;
587 param->beacon_miss_threshold = c->beacon_miss_threshold;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300588 param->rate_adaptation_threshold =
589 cpu_to_le32(c->rate_adaptation_threshold);
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +0300590 param->rate_adaptation_snr = c->rate_adaptation_snr;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300591
592 ret = wl1271_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param));
593 if (ret < 0) {
594 wl1271_warning("failed to set sg config: %d", ret);
595 goto out;
596 }
597
598out:
599 kfree(param);
600 return ret;
601}
602
603int wl1271_acx_cca_threshold(struct wl1271 *wl)
604{
605 struct acx_energy_detection *detection;
606 int ret;
607
608 wl1271_debug(DEBUG_ACX, "acx cca threshold");
609
610 detection = kzalloc(sizeof(*detection), GFP_KERNEL);
611 if (!detection) {
612 ret = -ENOMEM;
613 goto out;
614 }
615
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300616 detection->rx_cca_threshold = cpu_to_le16(wl->conf.rx.rx_cca_threshold);
Juuso Oikarinen45b531a2009-10-13 12:47:41 +0300617 detection->tx_energy_detection = wl->conf.tx.tx_energy_detection;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300618
619 ret = wl1271_cmd_configure(wl, ACX_CCA_THRESHOLD,
620 detection, sizeof(*detection));
621 if (ret < 0) {
622 wl1271_warning("failed to set cca threshold: %d", ret);
623 return ret;
624 }
625
626out:
627 kfree(detection);
628 return ret;
629}
630
631int wl1271_acx_bcn_dtim_options(struct wl1271 *wl)
632{
633 struct acx_beacon_broadcast *bb;
634 int ret;
635
636 wl1271_debug(DEBUG_ACX, "acx bcn dtim options");
637
638 bb = kzalloc(sizeof(*bb), GFP_KERNEL);
639 if (!bb) {
640 ret = -ENOMEM;
641 goto out;
642 }
643
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300644 bb->beacon_rx_timeout = cpu_to_le16(wl->conf.conn.beacon_rx_timeout);
645 bb->broadcast_timeout = cpu_to_le16(wl->conf.conn.broadcast_timeout);
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300646 bb->rx_broadcast_in_ps = wl->conf.conn.rx_broadcast_in_ps;
647 bb->ps_poll_threshold = wl->conf.conn.ps_poll_threshold;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300648
649 ret = wl1271_cmd_configure(wl, ACX_BCN_DTIM_OPTIONS, bb, sizeof(*bb));
650 if (ret < 0) {
651 wl1271_warning("failed to set rx config: %d", ret);
652 goto out;
653 }
654
655out:
656 kfree(bb);
657 return ret;
658}
659
660int wl1271_acx_aid(struct wl1271 *wl, u16 aid)
661{
662 struct acx_aid *acx_aid;
663 int ret;
664
665 wl1271_debug(DEBUG_ACX, "acx aid");
666
667 acx_aid = kzalloc(sizeof(*acx_aid), GFP_KERNEL);
668 if (!acx_aid) {
669 ret = -ENOMEM;
670 goto out;
671 }
672
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300673 acx_aid->aid = cpu_to_le16(aid);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300674
675 ret = wl1271_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid));
676 if (ret < 0) {
677 wl1271_warning("failed to set aid: %d", ret);
678 goto out;
679 }
680
681out:
682 kfree(acx_aid);
683 return ret;
684}
685
686int wl1271_acx_event_mbox_mask(struct wl1271 *wl, u32 event_mask)
687{
688 struct acx_event_mask *mask;
689 int ret;
690
691 wl1271_debug(DEBUG_ACX, "acx event mbox mask");
692
693 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
694 if (!mask) {
695 ret = -ENOMEM;
696 goto out;
697 }
698
699 /* high event mask is unused */
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300700 mask->high_event_mask = cpu_to_le32(0xffffffff);
701 mask->event_mask = cpu_to_le32(event_mask);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300702
703 ret = wl1271_cmd_configure(wl, ACX_EVENT_MBOX_MASK,
704 mask, sizeof(*mask));
705 if (ret < 0) {
706 wl1271_warning("failed to set acx_event_mbox_mask: %d", ret);
707 goto out;
708 }
709
710out:
711 kfree(mask);
712 return ret;
713}
714
715int wl1271_acx_set_preamble(struct wl1271 *wl, enum acx_preamble_type preamble)
716{
717 struct acx_preamble *acx;
718 int ret;
719
720 wl1271_debug(DEBUG_ACX, "acx_set_preamble");
721
722 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
723 if (!acx) {
724 ret = -ENOMEM;
725 goto out;
726 }
727
728 acx->preamble = preamble;
729
730 ret = wl1271_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx));
731 if (ret < 0) {
732 wl1271_warning("Setting of preamble failed: %d", ret);
733 goto out;
734 }
735
736out:
737 kfree(acx);
738 return ret;
739}
740
741int wl1271_acx_cts_protect(struct wl1271 *wl,
742 enum acx_ctsprotect_type ctsprotect)
743{
744 struct acx_ctsprotect *acx;
745 int ret;
746
747 wl1271_debug(DEBUG_ACX, "acx_set_ctsprotect");
748
749 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
750 if (!acx) {
751 ret = -ENOMEM;
752 goto out;
753 }
754
755 acx->ctsprotect = ctsprotect;
756
757 ret = wl1271_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx));
758 if (ret < 0) {
759 wl1271_warning("Setting of ctsprotect failed: %d", ret);
760 goto out;
761 }
762
763out:
764 kfree(acx);
765 return ret;
766}
767
768int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats)
769{
770 int ret;
771
772 wl1271_debug(DEBUG_ACX, "acx statistics");
773
774 ret = wl1271_cmd_interrogate(wl, ACX_STATISTICS, stats,
775 sizeof(*stats));
776 if (ret < 0) {
777 wl1271_warning("acx statistics failed: %d", ret);
778 return -ENOMEM;
779 }
780
781 return 0;
782}
783
Juuso Oikarinen830fb672009-12-11 15:41:06 +0200784int wl1271_acx_rate_policies(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300785{
786 struct acx_rate_policy *acx;
Juuso Oikarinen45b531a2009-10-13 12:47:41 +0300787 struct conf_tx_rate_class *c = &wl->conf.tx.rc_conf;
Juuso Oikarinen830fb672009-12-11 15:41:06 +0200788 int idx = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300789 int ret = 0;
790
791 wl1271_debug(DEBUG_ACX, "acx rate policies");
792
793 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
794
795 if (!acx) {
796 ret = -ENOMEM;
797 goto out;
798 }
799
Juuso Oikarinen830fb672009-12-11 15:41:06 +0200800 /* configure one basic rate class */
801 idx = ACX_TX_BASIC_RATE;
802 acx->rate_class[idx].enabled_rates = cpu_to_le32(wl->basic_rate_set);
803 acx->rate_class[idx].short_retry_limit = c->short_retry_limit;
804 acx->rate_class[idx].long_retry_limit = c->long_retry_limit;
805 acx->rate_class[idx].aflags = c->aflags;
806
807 /* configure one AP supported rate class */
808 idx = ACX_TX_AP_FULL_RATE;
809 acx->rate_class[idx].enabled_rates = cpu_to_le32(wl->rate_set);
810 acx->rate_class[idx].short_retry_limit = c->short_retry_limit;
811 acx->rate_class[idx].long_retry_limit = c->long_retry_limit;
812 acx->rate_class[idx].aflags = c->aflags;
813
814 acx->rate_class_cnt = cpu_to_le32(ACX_TX_RATE_POLICY_CNT);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300815
816 ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
817 if (ret < 0) {
818 wl1271_warning("Setting of rate policies failed: %d", ret);
819 goto out;
820 }
821
822out:
823 kfree(acx);
824 return ret;
825}
826
Kalle Valo243eeb52010-02-18 13:25:39 +0200827int wl1271_acx_ac_cfg(struct wl1271 *wl, u8 ac, u8 cw_min, u16 cw_max,
828 u8 aifsn, u16 txop)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300829{
830 struct acx_ac_cfg *acx;
Kalle Valo243eeb52010-02-18 13:25:39 +0200831 int ret = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300832
Kalle Valo243eeb52010-02-18 13:25:39 +0200833 wl1271_debug(DEBUG_ACX, "acx ac cfg %d cw_ming %d cw_max %d "
834 "aifs %d txop %d", ac, cw_min, cw_max, aifsn, txop);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300835
836 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
837
838 if (!acx) {
839 ret = -ENOMEM;
840 goto out;
841 }
842
Kalle Valo243eeb52010-02-18 13:25:39 +0200843 acx->ac = ac;
844 acx->cw_min = cw_min;
845 acx->cw_max = cpu_to_le16(cw_max);
846 acx->aifsn = aifsn;
847 acx->tx_op_limit = cpu_to_le16(txop);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300848
Kalle Valo243eeb52010-02-18 13:25:39 +0200849 ret = wl1271_cmd_configure(wl, ACX_AC_CFG, acx, sizeof(*acx));
850 if (ret < 0) {
851 wl1271_warning("acx ac cfg failed: %d", ret);
852 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300853 }
854
855out:
856 kfree(acx);
857 return ret;
858}
859
Kalle Valof2054df2010-02-18 13:25:40 +0200860int wl1271_acx_tid_cfg(struct wl1271 *wl, u8 queue_id, u8 channel_type,
861 u8 tsid, u8 ps_scheme, u8 ack_policy,
862 u32 apsd_conf0, u32 apsd_conf1)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300863{
864 struct acx_tid_config *acx;
Kalle Valof2054df2010-02-18 13:25:40 +0200865 int ret = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300866
867 wl1271_debug(DEBUG_ACX, "acx tid config");
868
869 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
870
871 if (!acx) {
872 ret = -ENOMEM;
873 goto out;
874 }
875
Kalle Valof2054df2010-02-18 13:25:40 +0200876 acx->queue_id = queue_id;
877 acx->channel_type = channel_type;
878 acx->tsid = tsid;
879 acx->ps_scheme = ps_scheme;
880 acx->ack_policy = ack_policy;
881 acx->apsd_conf[0] = cpu_to_le32(apsd_conf0);
882 acx->apsd_conf[1] = cpu_to_le32(apsd_conf1);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300883
Kalle Valof2054df2010-02-18 13:25:40 +0200884 ret = wl1271_cmd_configure(wl, ACX_TID_CFG, acx, sizeof(*acx));
885 if (ret < 0) {
886 wl1271_warning("Setting of tid config failed: %d", ret);
887 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300888 }
889
890out:
891 kfree(acx);
892 return ret;
893}
894
895int wl1271_acx_frag_threshold(struct wl1271 *wl)
896{
897 struct acx_frag_threshold *acx;
898 int ret = 0;
899
900 wl1271_debug(DEBUG_ACX, "acx frag threshold");
901
902 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
903
904 if (!acx) {
905 ret = -ENOMEM;
906 goto out;
907 }
908
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300909 acx->frag_threshold = cpu_to_le16(wl->conf.tx.frag_threshold);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300910 ret = wl1271_cmd_configure(wl, ACX_FRAG_CFG, acx, sizeof(*acx));
911 if (ret < 0) {
912 wl1271_warning("Setting of frag threshold failed: %d", ret);
913 goto out;
914 }
915
916out:
917 kfree(acx);
918 return ret;
919}
920
921int wl1271_acx_tx_config_options(struct wl1271 *wl)
922{
923 struct acx_tx_config_options *acx;
924 int ret = 0;
925
926 wl1271_debug(DEBUG_ACX, "acx tx config options");
927
928 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
929
930 if (!acx) {
931 ret = -ENOMEM;
932 goto out;
933 }
934
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300935 acx->tx_compl_timeout = cpu_to_le16(wl->conf.tx.tx_compl_timeout);
936 acx->tx_compl_threshold = cpu_to_le16(wl->conf.tx.tx_compl_threshold);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300937 ret = wl1271_cmd_configure(wl, ACX_TX_CONFIG_OPT, acx, sizeof(*acx));
938 if (ret < 0) {
939 wl1271_warning("Setting of tx options failed: %d", ret);
940 goto out;
941 }
942
943out:
944 kfree(acx);
945 return ret;
946}
947
948int wl1271_acx_mem_cfg(struct wl1271 *wl)
949{
950 struct wl1271_acx_config_memory *mem_conf;
951 int ret;
952
953 wl1271_debug(DEBUG_ACX, "wl1271 mem cfg");
954
955 mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL);
956 if (!mem_conf) {
957 ret = -ENOMEM;
958 goto out;
959 }
960
961 /* memory config */
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300962 mem_conf->num_stations = DEFAULT_NUM_STATIONS;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300963 mem_conf->rx_mem_block_num = ACX_RX_MEM_BLOCKS;
964 mem_conf->tx_min_mem_block_num = ACX_TX_MIN_MEM_BLOCKS;
965 mem_conf->num_ssid_profiles = ACX_NUM_SSID_PROFILES;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300966 mem_conf->total_tx_descriptors = cpu_to_le32(ACX_TX_DESCRIPTORS);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300967
968 ret = wl1271_cmd_configure(wl, ACX_MEM_CFG, mem_conf,
969 sizeof(*mem_conf));
970 if (ret < 0) {
971 wl1271_warning("wl1271 mem config failed: %d", ret);
972 goto out;
973 }
974
975out:
976 kfree(mem_conf);
977 return ret;
978}
979
980int wl1271_acx_init_mem_config(struct wl1271 *wl)
981{
982 int ret;
983
984 ret = wl1271_acx_mem_cfg(wl);
985 if (ret < 0)
986 return ret;
987
988 wl->target_mem_map = kzalloc(sizeof(struct wl1271_acx_mem_map),
Juuso Oikarinen45b531a2009-10-13 12:47:41 +0300989 GFP_KERNEL);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300990 if (!wl->target_mem_map) {
991 wl1271_error("couldn't allocate target memory map");
992 return -ENOMEM;
993 }
994
995 /* we now ask for the firmware built memory map */
996 ret = wl1271_acx_mem_map(wl, (void *)wl->target_mem_map,
997 sizeof(struct wl1271_acx_mem_map));
998 if (ret < 0) {
999 wl1271_error("couldn't retrieve firmware memory map");
1000 kfree(wl->target_mem_map);
1001 wl->target_mem_map = NULL;
1002 return ret;
1003 }
1004
1005 /* initialize TX block book keeping */
Luciano Coelhod0f63b22009-10-15 10:33:29 +03001006 wl->tx_blocks_available =
1007 le32_to_cpu(wl->target_mem_map->num_tx_mem_blocks);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001008 wl1271_debug(DEBUG_TX, "available tx blocks: %d",
1009 wl->tx_blocks_available);
1010
1011 return 0;
1012}
1013
1014int wl1271_acx_init_rx_interrupt(struct wl1271 *wl)
1015{
1016 struct wl1271_acx_rx_config_opt *rx_conf;
1017 int ret;
1018
1019 wl1271_debug(DEBUG_ACX, "wl1271 rx interrupt config");
1020
1021 rx_conf = kzalloc(sizeof(*rx_conf), GFP_KERNEL);
1022 if (!rx_conf) {
1023 ret = -ENOMEM;
1024 goto out;
1025 }
1026
Luciano Coelhod0f63b22009-10-15 10:33:29 +03001027 rx_conf->threshold = cpu_to_le16(wl->conf.rx.irq_pkt_threshold);
1028 rx_conf->timeout = cpu_to_le16(wl->conf.rx.irq_timeout);
1029 rx_conf->mblk_threshold = cpu_to_le16(wl->conf.rx.irq_blk_threshold);
Juuso Oikarinen8793f9b2009-10-13 12:47:40 +03001030 rx_conf->queue_type = wl->conf.rx.queue_type;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001031
1032 ret = wl1271_cmd_configure(wl, ACX_RX_CONFIG_OPT, rx_conf,
1033 sizeof(*rx_conf));
1034 if (ret < 0) {
1035 wl1271_warning("wl1271 rx config opt failed: %d", ret);
1036 goto out;
1037 }
1038
1039out:
1040 kfree(rx_conf);
1041 return ret;
1042}
Juuso Oikarinen3cfd6cf2009-10-12 15:08:52 +03001043
Juuso Oikarinen11f70f92009-10-13 12:47:46 +03001044int wl1271_acx_bet_enable(struct wl1271 *wl, bool enable)
1045{
1046 struct wl1271_acx_bet_enable *acx = NULL;
1047 int ret = 0;
1048
1049 wl1271_debug(DEBUG_ACX, "acx bet enable");
1050
1051 if (enable && wl->conf.conn.bet_enable == CONF_BET_MODE_DISABLE)
1052 goto out;
1053
1054 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1055 if (!acx) {
1056 ret = -ENOMEM;
1057 goto out;
1058 }
1059
1060 acx->enable = enable ? CONF_BET_MODE_ENABLE : CONF_BET_MODE_DISABLE;
1061 acx->max_consecutive = wl->conf.conn.bet_max_consecutive;
1062
1063 ret = wl1271_cmd_configure(wl, ACX_BET_ENABLE, acx, sizeof(*acx));
1064 if (ret < 0) {
1065 wl1271_warning("acx bet enable failed: %d", ret);
1066 goto out;
1067 }
1068
1069out:
1070 kfree(acx);
1071 return ret;
1072}
Juuso Oikarinen01c09162009-10-13 12:47:55 +03001073
1074int wl1271_acx_arp_ip_filter(struct wl1271 *wl, bool enable, u8 *address,
1075 u8 version)
1076{
1077 struct wl1271_acx_arp_filter *acx;
1078 int ret;
1079
1080 wl1271_debug(DEBUG_ACX, "acx arp ip filter, enable: %d", enable);
1081
1082 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1083 if (!acx) {
1084 ret = -ENOMEM;
1085 goto out;
1086 }
1087
1088 acx->version = version;
1089 acx->enable = enable;
1090
1091 if (enable == true) {
1092 if (version == ACX_IPV4_VERSION)
1093 memcpy(acx->address, address, ACX_IPV4_ADDR_SIZE);
1094 else if (version == ACX_IPV6_VERSION)
1095 memcpy(acx->address, address, sizeof(acx->address));
1096 else
1097 wl1271_error("Invalid IP version");
1098 }
1099
1100 ret = wl1271_cmd_configure(wl, ACX_ARP_IP_FILTER,
1101 acx, sizeof(*acx));
1102 if (ret < 0) {
1103 wl1271_warning("failed to set arp ip filter: %d", ret);
1104 goto out;
1105 }
1106
1107out:
1108 kfree(acx);
1109 return ret;
1110}
Juuso Oikarinen38ad2d82009-12-11 15:41:08 +02001111
1112int wl1271_acx_pm_config(struct wl1271 *wl)
1113{
1114 struct wl1271_acx_pm_config *acx = NULL;
1115 struct conf_pm_config_settings *c = &wl->conf.pm_config;
1116 int ret = 0;
1117
1118 wl1271_debug(DEBUG_ACX, "acx pm config");
1119
1120 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1121 if (!acx) {
1122 ret = -ENOMEM;
1123 goto out;
1124 }
1125
1126 acx->host_clk_settling_time = cpu_to_le32(c->host_clk_settling_time);
1127 acx->host_fast_wakeup_support = c->host_fast_wakeup_support;
1128
1129 ret = wl1271_cmd_configure(wl, ACX_PM_CONFIG, acx, sizeof(*acx));
1130 if (ret < 0) {
1131 wl1271_warning("acx pm config failed: %d", ret);
1132 goto out;
1133 }
1134
1135out:
1136 kfree(acx);
1137 return ret;
1138}