blob: f41f886741f1f988b8f68ab36b049b9ee7d1e5a8 [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
Luciano Coelhoac784032009-10-12 15:08:44 +0300138 /*
139 * FIXME: This is a workaround needed while we don't the correct
140 * calibration, to avoid distortions
141 */
142 /* acx->current_tx_power = power * 10; */
Juuso Oikarinen605351e2009-11-02 20:22:09 +0200143 acx->current_tx_power = 120;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300144
145 ret = wl1271_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx));
146 if (ret < 0) {
147 wl1271_warning("configure of tx power failed: %d", ret);
148 goto out;
149 }
150
151out:
152 kfree(acx);
153 return ret;
154}
155
156int wl1271_acx_feature_cfg(struct wl1271 *wl)
157{
158 struct acx_feature_config *feature;
159 int ret;
160
161 wl1271_debug(DEBUG_ACX, "acx feature cfg");
162
163 feature = kzalloc(sizeof(*feature), GFP_KERNEL);
164 if (!feature) {
165 ret = -ENOMEM;
166 goto out;
167 }
168
169 /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */
170 feature->data_flow_options = 0;
171 feature->options = 0;
172
173 ret = wl1271_cmd_configure(wl, ACX_FEATURE_CFG,
174 feature, sizeof(*feature));
175 if (ret < 0) {
176 wl1271_error("Couldnt set HW encryption");
177 goto out;
178 }
179
180out:
181 kfree(feature);
182 return ret;
183}
184
185int wl1271_acx_mem_map(struct wl1271 *wl, struct acx_header *mem_map,
186 size_t len)
187{
188 int ret;
189
190 wl1271_debug(DEBUG_ACX, "acx mem map");
191
192 ret = wl1271_cmd_interrogate(wl, ACX_MEM_MAP, mem_map, len);
193 if (ret < 0)
194 return ret;
195
196 return 0;
197}
198
Juuso Oikarinen8793f9b2009-10-13 12:47:40 +0300199int wl1271_acx_rx_msdu_life_time(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300200{
201 struct acx_rx_msdu_lifetime *acx;
202 int ret;
203
204 wl1271_debug(DEBUG_ACX, "acx rx msdu life time");
205
206 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
207 if (!acx) {
208 ret = -ENOMEM;
209 goto out;
210 }
211
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300212 acx->lifetime = cpu_to_le32(wl->conf.rx.rx_msdu_life_time);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300213 ret = wl1271_cmd_configure(wl, DOT11_RX_MSDU_LIFE_TIME,
214 acx, sizeof(*acx));
215 if (ret < 0) {
216 wl1271_warning("failed to set rx msdu life time: %d", ret);
217 goto out;
218 }
219
220out:
221 kfree(acx);
222 return ret;
223}
224
225int wl1271_acx_rx_config(struct wl1271 *wl, u32 config, u32 filter)
226{
227 struct acx_rx_config *rx_config;
228 int ret;
229
230 wl1271_debug(DEBUG_ACX, "acx rx config");
231
232 rx_config = kzalloc(sizeof(*rx_config), GFP_KERNEL);
233 if (!rx_config) {
234 ret = -ENOMEM;
235 goto out;
236 }
237
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300238 rx_config->config_options = cpu_to_le32(config);
239 rx_config->filter_options = cpu_to_le32(filter);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300240
241 ret = wl1271_cmd_configure(wl, ACX_RX_CFG,
242 rx_config, sizeof(*rx_config));
243 if (ret < 0) {
244 wl1271_warning("failed to set rx config: %d", ret);
245 goto out;
246 }
247
248out:
249 kfree(rx_config);
250 return ret;
251}
252
253int wl1271_acx_pd_threshold(struct wl1271 *wl)
254{
255 struct acx_packet_detection *pd;
256 int ret;
257
258 wl1271_debug(DEBUG_ACX, "acx data pd threshold");
259
260 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
261 if (!pd) {
262 ret = -ENOMEM;
263 goto out;
264 }
265
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300266 pd->threshold = cpu_to_le32(wl->conf.rx.packet_detection_threshold);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300267
268 ret = wl1271_cmd_configure(wl, ACX_PD_THRESHOLD, pd, sizeof(*pd));
269 if (ret < 0) {
270 wl1271_warning("failed to set pd threshold: %d", ret);
271 goto out;
272 }
273
274out:
275 kfree(pd);
276 return 0;
277}
278
279int wl1271_acx_slot(struct wl1271 *wl, enum acx_slot_type slot_time)
280{
281 struct acx_slot *slot;
282 int ret;
283
284 wl1271_debug(DEBUG_ACX, "acx slot");
285
286 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
287 if (!slot) {
288 ret = -ENOMEM;
289 goto out;
290 }
291
292 slot->wone_index = STATION_WONE_INDEX;
293 slot->slot_time = slot_time;
294
295 ret = wl1271_cmd_configure(wl, ACX_SLOT, slot, sizeof(*slot));
296 if (ret < 0) {
297 wl1271_warning("failed to set slot time: %d", ret);
298 goto out;
299 }
300
301out:
302 kfree(slot);
303 return ret;
304}
305
Juuso Oikarinenc87dec92009-10-08 21:56:31 +0300306int wl1271_acx_group_address_tbl(struct wl1271 *wl, bool enable,
307 void *mc_list, u32 mc_list_len)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300308{
309 struct acx_dot11_grp_addr_tbl *acx;
310 int ret;
311
312 wl1271_debug(DEBUG_ACX, "acx group address tbl");
313
314 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
315 if (!acx) {
316 ret = -ENOMEM;
317 goto out;
318 }
319
320 /* MAC filtering */
Juuso Oikarinenc87dec92009-10-08 21:56:31 +0300321 acx->enabled = enable;
322 acx->num_groups = mc_list_len;
323 memcpy(acx->mac_table, mc_list, mc_list_len * ETH_ALEN);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300324
325 ret = wl1271_cmd_configure(wl, DOT11_GROUP_ADDRESS_TBL,
326 acx, sizeof(*acx));
327 if (ret < 0) {
328 wl1271_warning("failed to set group addr table: %d", ret);
329 goto out;
330 }
331
332out:
333 kfree(acx);
334 return ret;
335}
336
337int wl1271_acx_service_period_timeout(struct wl1271 *wl)
338{
339 struct acx_rx_timeout *rx_timeout;
340 int ret;
341
342 rx_timeout = kzalloc(sizeof(*rx_timeout), GFP_KERNEL);
343 if (!rx_timeout) {
344 ret = -ENOMEM;
345 goto out;
346 }
347
348 wl1271_debug(DEBUG_ACX, "acx service period timeout");
349
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300350 rx_timeout->ps_poll_timeout = cpu_to_le16(wl->conf.rx.ps_poll_timeout);
351 rx_timeout->upsd_timeout = cpu_to_le16(wl->conf.rx.upsd_timeout);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300352
353 ret = wl1271_cmd_configure(wl, ACX_SERVICE_PERIOD_TIMEOUT,
354 rx_timeout, sizeof(*rx_timeout));
355 if (ret < 0) {
356 wl1271_warning("failed to set service period timeout: %d",
357 ret);
358 goto out;
359 }
360
361out:
362 kfree(rx_timeout);
363 return ret;
364}
365
366int wl1271_acx_rts_threshold(struct wl1271 *wl, u16 rts_threshold)
367{
368 struct acx_rts_threshold *rts;
369 int ret;
370
371 wl1271_debug(DEBUG_ACX, "acx rts threshold");
372
373 rts = kzalloc(sizeof(*rts), GFP_KERNEL);
374 if (!rts) {
375 ret = -ENOMEM;
376 goto out;
377 }
378
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300379 rts->threshold = cpu_to_le16(rts_threshold);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300380
381 ret = wl1271_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts));
382 if (ret < 0) {
383 wl1271_warning("failed to set rts threshold: %d", ret);
384 goto out;
385 }
386
387out:
388 kfree(rts);
389 return ret;
390}
391
Luciano Coelho6e92b412009-12-11 15:40:50 +0200392int wl1271_acx_dco_itrim_params(struct wl1271 *wl)
393{
394 struct acx_dco_itrim_params *dco;
395 struct conf_itrim_settings *c = &wl->conf.itrim;
396 int ret;
397
398 wl1271_debug(DEBUG_ACX, "acx dco itrim parameters");
399
400 dco = kzalloc(sizeof(*dco), GFP_KERNEL);
401 if (!dco) {
402 ret = -ENOMEM;
403 goto out;
404 }
405
406 dco->enable = c->enable;
407 dco->timeout = cpu_to_le32(c->timeout);
408
409 ret = wl1271_cmd_configure(wl, ACX_SET_DCO_ITRIM_PARAMS,
410 dco, sizeof(*dco));
411 if (ret < 0) {
412 wl1271_warning("failed to set dco itrim parameters: %d", ret);
413 goto out;
414 }
415
416out:
417 kfree(dco);
418 return ret;
419}
420
Juuso Oikarinen19221672009-10-08 21:56:35 +0300421int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, bool enable_filter)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300422{
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300423 struct acx_beacon_filter_option *beacon_filter = NULL;
424 int ret = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300425
426 wl1271_debug(DEBUG_ACX, "acx beacon filter opt");
427
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300428 if (enable_filter &&
429 wl->conf.conn.bcn_filt_mode == CONF_BCN_FILT_MODE_DISABLED)
430 goto out;
431
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300432 beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL);
433 if (!beacon_filter) {
434 ret = -ENOMEM;
435 goto out;
436 }
437
Juuso Oikarinen19221672009-10-08 21:56:35 +0300438 beacon_filter->enable = enable_filter;
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300439
440 /*
441 * When set to zero, and the filter is enabled, beacons
442 * without the unicast TIM bit set are dropped.
443 */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300444 beacon_filter->max_num_beacons = 0;
445
446 ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_OPT,
447 beacon_filter, sizeof(*beacon_filter));
448 if (ret < 0) {
449 wl1271_warning("failed to set beacon filter opt: %d", ret);
450 goto out;
451 }
452
453out:
454 kfree(beacon_filter);
455 return ret;
456}
457
458int wl1271_acx_beacon_filter_table(struct wl1271 *wl)
459{
460 struct acx_beacon_filter_ie_table *ie_table;
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300461 int i, idx = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300462 int ret;
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300463 bool vendor_spec = false;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300464
465 wl1271_debug(DEBUG_ACX, "acx beacon filter table");
466
467 ie_table = kzalloc(sizeof(*ie_table), GFP_KERNEL);
468 if (!ie_table) {
469 ret = -ENOMEM;
470 goto out;
471 }
472
Juuso Oikarinen19221672009-10-08 21:56:35 +0300473 /* configure default beacon pass-through rules */
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300474 ie_table->num_ie = 0;
475 for (i = 0; i < wl->conf.conn.bcn_filt_ie_count; i++) {
476 struct conf_bcn_filt_rule *r = &(wl->conf.conn.bcn_filt_ie[i]);
477 ie_table->table[idx++] = r->ie;
478 ie_table->table[idx++] = r->rule;
479
480 if (r->ie == WLAN_EID_VENDOR_SPECIFIC) {
481 /* only one vendor specific ie allowed */
482 if (vendor_spec)
483 continue;
484
485 /* for vendor specific rules configure the
486 additional fields */
487 memcpy(&(ie_table->table[idx]), r->oui,
488 CONF_BCN_IE_OUI_LEN);
489 idx += CONF_BCN_IE_OUI_LEN;
490 ie_table->table[idx++] = r->type;
491 memcpy(&(ie_table->table[idx]), r->version,
492 CONF_BCN_IE_VER_LEN);
493 idx += CONF_BCN_IE_VER_LEN;
494 vendor_spec = true;
495 }
496
497 ie_table->num_ie++;
498 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300499
500 ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_TABLE,
501 ie_table, sizeof(*ie_table));
502 if (ret < 0) {
503 wl1271_warning("failed to set beacon filter table: %d", ret);
504 goto out;
505 }
506
507out:
508 kfree(ie_table);
509 return ret;
510}
511
Juuso Oikarinen34415232009-10-08 21:56:33 +0300512int wl1271_acx_conn_monit_params(struct wl1271 *wl)
513{
514 struct acx_conn_monit_params *acx;
515 int ret;
516
517 wl1271_debug(DEBUG_ACX, "acx connection monitor parameters");
518
519 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
520 if (!acx) {
521 ret = -ENOMEM;
522 goto out;
523 }
524
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300525 acx->synch_fail_thold = cpu_to_le32(wl->conf.conn.synch_fail_thold);
526 acx->bss_lose_timeout = cpu_to_le32(wl->conf.conn.bss_lose_timeout);
Juuso Oikarinen34415232009-10-08 21:56:33 +0300527
528 ret = wl1271_cmd_configure(wl, ACX_CONN_MONIT_PARAMS,
529 acx, sizeof(*acx));
530 if (ret < 0) {
531 wl1271_warning("failed to set connection monitor "
532 "parameters: %d", ret);
533 goto out;
534 }
535
536out:
537 kfree(acx);
538 return ret;
539}
540
541
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300542int wl1271_acx_sg_enable(struct wl1271 *wl)
543{
544 struct acx_bt_wlan_coex *pta;
545 int ret;
546
547 wl1271_debug(DEBUG_ACX, "acx sg enable");
548
549 pta = kzalloc(sizeof(*pta), GFP_KERNEL);
550 if (!pta) {
551 ret = -ENOMEM;
552 goto out;
553 }
554
555 pta->enable = SG_ENABLE;
556
557 ret = wl1271_cmd_configure(wl, ACX_SG_ENABLE, pta, sizeof(*pta));
558 if (ret < 0) {
559 wl1271_warning("failed to set softgemini enable: %d", ret);
560 goto out;
561 }
562
563out:
564 kfree(pta);
565 return ret;
566}
567
568int wl1271_acx_sg_cfg(struct wl1271 *wl)
569{
570 struct acx_bt_wlan_coex_param *param;
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +0300571 struct conf_sg_settings *c = &wl->conf.sg;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300572 int ret;
573
574 wl1271_debug(DEBUG_ACX, "acx sg cfg");
575
576 param = kzalloc(sizeof(*param), GFP_KERNEL);
577 if (!param) {
578 ret = -ENOMEM;
579 goto out;
580 }
581
582 /* BT-WLAN coext parameters */
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300583 param->per_threshold = cpu_to_le32(c->per_threshold);
584 param->max_scan_compensation_time =
585 cpu_to_le32(c->max_scan_compensation_time);
586 param->nfs_sample_interval = cpu_to_le16(c->nfs_sample_interval);
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +0300587 param->load_ratio = c->load_ratio;
588 param->auto_ps_mode = c->auto_ps_mode;
589 param->probe_req_compensation = c->probe_req_compensation;
590 param->scan_window_compensation = c->scan_window_compensation;
591 param->antenna_config = c->antenna_config;
592 param->beacon_miss_threshold = c->beacon_miss_threshold;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300593 param->rate_adaptation_threshold =
594 cpu_to_le32(c->rate_adaptation_threshold);
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +0300595 param->rate_adaptation_snr = c->rate_adaptation_snr;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300596
597 ret = wl1271_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param));
598 if (ret < 0) {
599 wl1271_warning("failed to set sg config: %d", ret);
600 goto out;
601 }
602
603out:
604 kfree(param);
605 return ret;
606}
607
608int wl1271_acx_cca_threshold(struct wl1271 *wl)
609{
610 struct acx_energy_detection *detection;
611 int ret;
612
613 wl1271_debug(DEBUG_ACX, "acx cca threshold");
614
615 detection = kzalloc(sizeof(*detection), GFP_KERNEL);
616 if (!detection) {
617 ret = -ENOMEM;
618 goto out;
619 }
620
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300621 detection->rx_cca_threshold = cpu_to_le16(wl->conf.rx.rx_cca_threshold);
Juuso Oikarinen45b531a2009-10-13 12:47:41 +0300622 detection->tx_energy_detection = wl->conf.tx.tx_energy_detection;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300623
624 ret = wl1271_cmd_configure(wl, ACX_CCA_THRESHOLD,
625 detection, sizeof(*detection));
626 if (ret < 0) {
627 wl1271_warning("failed to set cca threshold: %d", ret);
628 return ret;
629 }
630
631out:
632 kfree(detection);
633 return ret;
634}
635
636int wl1271_acx_bcn_dtim_options(struct wl1271 *wl)
637{
638 struct acx_beacon_broadcast *bb;
639 int ret;
640
641 wl1271_debug(DEBUG_ACX, "acx bcn dtim options");
642
643 bb = kzalloc(sizeof(*bb), GFP_KERNEL);
644 if (!bb) {
645 ret = -ENOMEM;
646 goto out;
647 }
648
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300649 bb->beacon_rx_timeout = cpu_to_le16(wl->conf.conn.beacon_rx_timeout);
650 bb->broadcast_timeout = cpu_to_le16(wl->conf.conn.broadcast_timeout);
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300651 bb->rx_broadcast_in_ps = wl->conf.conn.rx_broadcast_in_ps;
652 bb->ps_poll_threshold = wl->conf.conn.ps_poll_threshold;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300653
654 ret = wl1271_cmd_configure(wl, ACX_BCN_DTIM_OPTIONS, bb, sizeof(*bb));
655 if (ret < 0) {
656 wl1271_warning("failed to set rx config: %d", ret);
657 goto out;
658 }
659
660out:
661 kfree(bb);
662 return ret;
663}
664
665int wl1271_acx_aid(struct wl1271 *wl, u16 aid)
666{
667 struct acx_aid *acx_aid;
668 int ret;
669
670 wl1271_debug(DEBUG_ACX, "acx aid");
671
672 acx_aid = kzalloc(sizeof(*acx_aid), GFP_KERNEL);
673 if (!acx_aid) {
674 ret = -ENOMEM;
675 goto out;
676 }
677
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300678 acx_aid->aid = cpu_to_le16(aid);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300679
680 ret = wl1271_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid));
681 if (ret < 0) {
682 wl1271_warning("failed to set aid: %d", ret);
683 goto out;
684 }
685
686out:
687 kfree(acx_aid);
688 return ret;
689}
690
691int wl1271_acx_event_mbox_mask(struct wl1271 *wl, u32 event_mask)
692{
693 struct acx_event_mask *mask;
694 int ret;
695
696 wl1271_debug(DEBUG_ACX, "acx event mbox mask");
697
698 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
699 if (!mask) {
700 ret = -ENOMEM;
701 goto out;
702 }
703
704 /* high event mask is unused */
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300705 mask->high_event_mask = cpu_to_le32(0xffffffff);
706 mask->event_mask = cpu_to_le32(event_mask);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300707
708 ret = wl1271_cmd_configure(wl, ACX_EVENT_MBOX_MASK,
709 mask, sizeof(*mask));
710 if (ret < 0) {
711 wl1271_warning("failed to set acx_event_mbox_mask: %d", ret);
712 goto out;
713 }
714
715out:
716 kfree(mask);
717 return ret;
718}
719
720int wl1271_acx_set_preamble(struct wl1271 *wl, enum acx_preamble_type preamble)
721{
722 struct acx_preamble *acx;
723 int ret;
724
725 wl1271_debug(DEBUG_ACX, "acx_set_preamble");
726
727 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
728 if (!acx) {
729 ret = -ENOMEM;
730 goto out;
731 }
732
733 acx->preamble = preamble;
734
735 ret = wl1271_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx));
736 if (ret < 0) {
737 wl1271_warning("Setting of preamble failed: %d", ret);
738 goto out;
739 }
740
741out:
742 kfree(acx);
743 return ret;
744}
745
746int wl1271_acx_cts_protect(struct wl1271 *wl,
747 enum acx_ctsprotect_type ctsprotect)
748{
749 struct acx_ctsprotect *acx;
750 int ret;
751
752 wl1271_debug(DEBUG_ACX, "acx_set_ctsprotect");
753
754 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
755 if (!acx) {
756 ret = -ENOMEM;
757 goto out;
758 }
759
760 acx->ctsprotect = ctsprotect;
761
762 ret = wl1271_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx));
763 if (ret < 0) {
764 wl1271_warning("Setting of ctsprotect failed: %d", ret);
765 goto out;
766 }
767
768out:
769 kfree(acx);
770 return ret;
771}
772
773int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats)
774{
775 int ret;
776
777 wl1271_debug(DEBUG_ACX, "acx statistics");
778
779 ret = wl1271_cmd_interrogate(wl, ACX_STATISTICS, stats,
780 sizeof(*stats));
781 if (ret < 0) {
782 wl1271_warning("acx statistics failed: %d", ret);
783 return -ENOMEM;
784 }
785
786 return 0;
787}
788
Juuso Oikarinen830fb672009-12-11 15:41:06 +0200789int wl1271_acx_rate_policies(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300790{
791 struct acx_rate_policy *acx;
Juuso Oikarinen45b531a2009-10-13 12:47:41 +0300792 struct conf_tx_rate_class *c = &wl->conf.tx.rc_conf;
Juuso Oikarinen830fb672009-12-11 15:41:06 +0200793 int idx = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300794 int ret = 0;
795
796 wl1271_debug(DEBUG_ACX, "acx rate policies");
797
798 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
799
800 if (!acx) {
801 ret = -ENOMEM;
802 goto out;
803 }
804
Juuso Oikarinen830fb672009-12-11 15:41:06 +0200805 /* configure one basic rate class */
806 idx = ACX_TX_BASIC_RATE;
807 acx->rate_class[idx].enabled_rates = cpu_to_le32(wl->basic_rate_set);
808 acx->rate_class[idx].short_retry_limit = c->short_retry_limit;
809 acx->rate_class[idx].long_retry_limit = c->long_retry_limit;
810 acx->rate_class[idx].aflags = c->aflags;
811
812 /* configure one AP supported rate class */
813 idx = ACX_TX_AP_FULL_RATE;
814 acx->rate_class[idx].enabled_rates = cpu_to_le32(wl->rate_set);
815 acx->rate_class[idx].short_retry_limit = c->short_retry_limit;
816 acx->rate_class[idx].long_retry_limit = c->long_retry_limit;
817 acx->rate_class[idx].aflags = c->aflags;
818
819 acx->rate_class_cnt = cpu_to_le32(ACX_TX_RATE_POLICY_CNT);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300820
821 ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
822 if (ret < 0) {
823 wl1271_warning("Setting of rate policies failed: %d", ret);
824 goto out;
825 }
826
827out:
828 kfree(acx);
829 return ret;
830}
831
Kalle Valo243eeb52010-02-18 13:25:39 +0200832int wl1271_acx_ac_cfg(struct wl1271 *wl, u8 ac, u8 cw_min, u16 cw_max,
833 u8 aifsn, u16 txop)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300834{
835 struct acx_ac_cfg *acx;
Kalle Valo243eeb52010-02-18 13:25:39 +0200836 int ret = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300837
Kalle Valo243eeb52010-02-18 13:25:39 +0200838 wl1271_debug(DEBUG_ACX, "acx ac cfg %d cw_ming %d cw_max %d "
839 "aifs %d txop %d", ac, cw_min, cw_max, aifsn, txop);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300840
841 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
842
843 if (!acx) {
844 ret = -ENOMEM;
845 goto out;
846 }
847
Kalle Valo243eeb52010-02-18 13:25:39 +0200848 acx->ac = ac;
849 acx->cw_min = cw_min;
850 acx->cw_max = cpu_to_le16(cw_max);
851 acx->aifsn = aifsn;
852 acx->tx_op_limit = cpu_to_le16(txop);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300853
Kalle Valo243eeb52010-02-18 13:25:39 +0200854 ret = wl1271_cmd_configure(wl, ACX_AC_CFG, acx, sizeof(*acx));
855 if (ret < 0) {
856 wl1271_warning("acx ac cfg failed: %d", ret);
857 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300858 }
859
860out:
861 kfree(acx);
862 return ret;
863}
864
Kalle Valof2054df2010-02-18 13:25:40 +0200865int wl1271_acx_tid_cfg(struct wl1271 *wl, u8 queue_id, u8 channel_type,
866 u8 tsid, u8 ps_scheme, u8 ack_policy,
867 u32 apsd_conf0, u32 apsd_conf1)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300868{
869 struct acx_tid_config *acx;
Kalle Valof2054df2010-02-18 13:25:40 +0200870 int ret = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300871
872 wl1271_debug(DEBUG_ACX, "acx tid config");
873
874 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
875
876 if (!acx) {
877 ret = -ENOMEM;
878 goto out;
879 }
880
Kalle Valof2054df2010-02-18 13:25:40 +0200881 acx->queue_id = queue_id;
882 acx->channel_type = channel_type;
883 acx->tsid = tsid;
884 acx->ps_scheme = ps_scheme;
885 acx->ack_policy = ack_policy;
886 acx->apsd_conf[0] = cpu_to_le32(apsd_conf0);
887 acx->apsd_conf[1] = cpu_to_le32(apsd_conf1);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300888
Kalle Valof2054df2010-02-18 13:25:40 +0200889 ret = wl1271_cmd_configure(wl, ACX_TID_CFG, acx, sizeof(*acx));
890 if (ret < 0) {
891 wl1271_warning("Setting of tid config failed: %d", ret);
892 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300893 }
894
895out:
896 kfree(acx);
897 return ret;
898}
899
900int wl1271_acx_frag_threshold(struct wl1271 *wl)
901{
902 struct acx_frag_threshold *acx;
903 int ret = 0;
904
905 wl1271_debug(DEBUG_ACX, "acx frag threshold");
906
907 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
908
909 if (!acx) {
910 ret = -ENOMEM;
911 goto out;
912 }
913
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300914 acx->frag_threshold = cpu_to_le16(wl->conf.tx.frag_threshold);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300915 ret = wl1271_cmd_configure(wl, ACX_FRAG_CFG, acx, sizeof(*acx));
916 if (ret < 0) {
917 wl1271_warning("Setting of frag threshold failed: %d", ret);
918 goto out;
919 }
920
921out:
922 kfree(acx);
923 return ret;
924}
925
926int wl1271_acx_tx_config_options(struct wl1271 *wl)
927{
928 struct acx_tx_config_options *acx;
929 int ret = 0;
930
931 wl1271_debug(DEBUG_ACX, "acx tx config options");
932
933 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
934
935 if (!acx) {
936 ret = -ENOMEM;
937 goto out;
938 }
939
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300940 acx->tx_compl_timeout = cpu_to_le16(wl->conf.tx.tx_compl_timeout);
941 acx->tx_compl_threshold = cpu_to_le16(wl->conf.tx.tx_compl_threshold);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300942 ret = wl1271_cmd_configure(wl, ACX_TX_CONFIG_OPT, acx, sizeof(*acx));
943 if (ret < 0) {
944 wl1271_warning("Setting of tx options failed: %d", ret);
945 goto out;
946 }
947
948out:
949 kfree(acx);
950 return ret;
951}
952
953int wl1271_acx_mem_cfg(struct wl1271 *wl)
954{
955 struct wl1271_acx_config_memory *mem_conf;
956 int ret;
957
958 wl1271_debug(DEBUG_ACX, "wl1271 mem cfg");
959
960 mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL);
961 if (!mem_conf) {
962 ret = -ENOMEM;
963 goto out;
964 }
965
966 /* memory config */
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300967 mem_conf->num_stations = DEFAULT_NUM_STATIONS;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300968 mem_conf->rx_mem_block_num = ACX_RX_MEM_BLOCKS;
969 mem_conf->tx_min_mem_block_num = ACX_TX_MIN_MEM_BLOCKS;
970 mem_conf->num_ssid_profiles = ACX_NUM_SSID_PROFILES;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300971 mem_conf->total_tx_descriptors = cpu_to_le32(ACX_TX_DESCRIPTORS);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300972
973 ret = wl1271_cmd_configure(wl, ACX_MEM_CFG, mem_conf,
974 sizeof(*mem_conf));
975 if (ret < 0) {
976 wl1271_warning("wl1271 mem config failed: %d", ret);
977 goto out;
978 }
979
980out:
981 kfree(mem_conf);
982 return ret;
983}
984
985int wl1271_acx_init_mem_config(struct wl1271 *wl)
986{
987 int ret;
988
989 ret = wl1271_acx_mem_cfg(wl);
990 if (ret < 0)
991 return ret;
992
993 wl->target_mem_map = kzalloc(sizeof(struct wl1271_acx_mem_map),
Juuso Oikarinen45b531a2009-10-13 12:47:41 +0300994 GFP_KERNEL);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300995 if (!wl->target_mem_map) {
996 wl1271_error("couldn't allocate target memory map");
997 return -ENOMEM;
998 }
999
1000 /* we now ask for the firmware built memory map */
1001 ret = wl1271_acx_mem_map(wl, (void *)wl->target_mem_map,
1002 sizeof(struct wl1271_acx_mem_map));
1003 if (ret < 0) {
1004 wl1271_error("couldn't retrieve firmware memory map");
1005 kfree(wl->target_mem_map);
1006 wl->target_mem_map = NULL;
1007 return ret;
1008 }
1009
1010 /* initialize TX block book keeping */
Luciano Coelhod0f63b22009-10-15 10:33:29 +03001011 wl->tx_blocks_available =
1012 le32_to_cpu(wl->target_mem_map->num_tx_mem_blocks);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001013 wl1271_debug(DEBUG_TX, "available tx blocks: %d",
1014 wl->tx_blocks_available);
1015
1016 return 0;
1017}
1018
1019int wl1271_acx_init_rx_interrupt(struct wl1271 *wl)
1020{
1021 struct wl1271_acx_rx_config_opt *rx_conf;
1022 int ret;
1023
1024 wl1271_debug(DEBUG_ACX, "wl1271 rx interrupt config");
1025
1026 rx_conf = kzalloc(sizeof(*rx_conf), GFP_KERNEL);
1027 if (!rx_conf) {
1028 ret = -ENOMEM;
1029 goto out;
1030 }
1031
Luciano Coelhod0f63b22009-10-15 10:33:29 +03001032 rx_conf->threshold = cpu_to_le16(wl->conf.rx.irq_pkt_threshold);
1033 rx_conf->timeout = cpu_to_le16(wl->conf.rx.irq_timeout);
1034 rx_conf->mblk_threshold = cpu_to_le16(wl->conf.rx.irq_blk_threshold);
Juuso Oikarinen8793f9b2009-10-13 12:47:40 +03001035 rx_conf->queue_type = wl->conf.rx.queue_type;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001036
1037 ret = wl1271_cmd_configure(wl, ACX_RX_CONFIG_OPT, rx_conf,
1038 sizeof(*rx_conf));
1039 if (ret < 0) {
1040 wl1271_warning("wl1271 rx config opt failed: %d", ret);
1041 goto out;
1042 }
1043
1044out:
1045 kfree(rx_conf);
1046 return ret;
1047}
Juuso Oikarinen3cfd6cf2009-10-12 15:08:52 +03001048
Juuso Oikarinen11f70f92009-10-13 12:47:46 +03001049int wl1271_acx_bet_enable(struct wl1271 *wl, bool enable)
1050{
1051 struct wl1271_acx_bet_enable *acx = NULL;
1052 int ret = 0;
1053
1054 wl1271_debug(DEBUG_ACX, "acx bet enable");
1055
1056 if (enable && wl->conf.conn.bet_enable == CONF_BET_MODE_DISABLE)
1057 goto out;
1058
1059 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1060 if (!acx) {
1061 ret = -ENOMEM;
1062 goto out;
1063 }
1064
1065 acx->enable = enable ? CONF_BET_MODE_ENABLE : CONF_BET_MODE_DISABLE;
1066 acx->max_consecutive = wl->conf.conn.bet_max_consecutive;
1067
1068 ret = wl1271_cmd_configure(wl, ACX_BET_ENABLE, acx, sizeof(*acx));
1069 if (ret < 0) {
1070 wl1271_warning("acx bet enable failed: %d", ret);
1071 goto out;
1072 }
1073
1074out:
1075 kfree(acx);
1076 return ret;
1077}
Juuso Oikarinen01c09162009-10-13 12:47:55 +03001078
1079int wl1271_acx_arp_ip_filter(struct wl1271 *wl, bool enable, u8 *address,
1080 u8 version)
1081{
1082 struct wl1271_acx_arp_filter *acx;
1083 int ret;
1084
1085 wl1271_debug(DEBUG_ACX, "acx arp ip filter, enable: %d", enable);
1086
1087 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1088 if (!acx) {
1089 ret = -ENOMEM;
1090 goto out;
1091 }
1092
1093 acx->version = version;
1094 acx->enable = enable;
1095
1096 if (enable == true) {
1097 if (version == ACX_IPV4_VERSION)
1098 memcpy(acx->address, address, ACX_IPV4_ADDR_SIZE);
1099 else if (version == ACX_IPV6_VERSION)
1100 memcpy(acx->address, address, sizeof(acx->address));
1101 else
1102 wl1271_error("Invalid IP version");
1103 }
1104
1105 ret = wl1271_cmd_configure(wl, ACX_ARP_IP_FILTER,
1106 acx, sizeof(*acx));
1107 if (ret < 0) {
1108 wl1271_warning("failed to set arp ip filter: %d", ret);
1109 goto out;
1110 }
1111
1112out:
1113 kfree(acx);
1114 return ret;
1115}
Juuso Oikarinen38ad2d82009-12-11 15:41:08 +02001116
1117int wl1271_acx_pm_config(struct wl1271 *wl)
1118{
1119 struct wl1271_acx_pm_config *acx = NULL;
1120 struct conf_pm_config_settings *c = &wl->conf.pm_config;
1121 int ret = 0;
1122
1123 wl1271_debug(DEBUG_ACX, "acx pm config");
1124
1125 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1126 if (!acx) {
1127 ret = -ENOMEM;
1128 goto out;
1129 }
1130
1131 acx->host_clk_settling_time = cpu_to_le32(c->host_clk_settling_time);
1132 acx->host_fast_wakeup_support = c->host_fast_wakeup_support;
1133
1134 ret = wl1271_cmd_configure(wl, ACX_PM_CONFIG, acx, sizeof(*acx));
1135 if (ret < 0) {
1136 wl1271_warning("acx pm config failed: %d", ret);
1137 goto out;
1138 }
1139
1140out:
1141 kfree(acx);
1142 return ret;
1143}