blob: 2b5fb3d2df1b077d07b6e04a2414070d48ae6948 [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
Shahar Levi00d20102010-11-08 11:20:10 +000024#include "acx.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030025
26#include <linux/module.h>
27#include <linux/platform_device.h>
28#include <linux/crc7.h>
29#include <linux/spi/spi.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090030#include <linux/slab.h>
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030031
Shahar Levi00d20102010-11-08 11:20:10 +000032#include "wl12xx.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030033#include "wl12xx_80211.h"
Shahar Levi00d20102010-11-08 11:20:10 +000034#include "reg.h"
35#include "ps.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030036
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
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030089int wl1271_acx_tx_power(struct wl1271 *wl, int power)
90{
91 struct acx_current_tx_power *acx;
92 int ret;
93
94 wl1271_debug(DEBUG_ACX, "acx dot11_cur_tx_pwr");
95
96 if (power < 0 || power > 25)
97 return -EINVAL;
98
99 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
100 if (!acx) {
101 ret = -ENOMEM;
102 goto out;
103 }
104
Juuso Oikarinen6f6b5d42010-02-22 08:38:42 +0200105 acx->current_tx_power = power * 10;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300106
107 ret = wl1271_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx));
108 if (ret < 0) {
109 wl1271_warning("configure of tx power failed: %d", ret);
110 goto out;
111 }
112
113out:
114 kfree(acx);
115 return ret;
116}
117
118int wl1271_acx_feature_cfg(struct wl1271 *wl)
119{
120 struct acx_feature_config *feature;
121 int ret;
122
123 wl1271_debug(DEBUG_ACX, "acx feature cfg");
124
125 feature = kzalloc(sizeof(*feature), GFP_KERNEL);
126 if (!feature) {
127 ret = -ENOMEM;
128 goto out;
129 }
130
131 /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */
132 feature->data_flow_options = 0;
133 feature->options = 0;
134
135 ret = wl1271_cmd_configure(wl, ACX_FEATURE_CFG,
136 feature, sizeof(*feature));
137 if (ret < 0) {
138 wl1271_error("Couldnt set HW encryption");
139 goto out;
140 }
141
142out:
143 kfree(feature);
144 return ret;
145}
146
147int wl1271_acx_mem_map(struct wl1271 *wl, struct acx_header *mem_map,
148 size_t len)
149{
150 int ret;
151
152 wl1271_debug(DEBUG_ACX, "acx mem map");
153
154 ret = wl1271_cmd_interrogate(wl, ACX_MEM_MAP, mem_map, len);
155 if (ret < 0)
156 return ret;
157
158 return 0;
159}
160
Juuso Oikarinen8793f9b2009-10-13 12:47:40 +0300161int wl1271_acx_rx_msdu_life_time(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300162{
163 struct acx_rx_msdu_lifetime *acx;
164 int ret;
165
166 wl1271_debug(DEBUG_ACX, "acx rx msdu life time");
167
168 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
169 if (!acx) {
170 ret = -ENOMEM;
171 goto out;
172 }
173
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300174 acx->lifetime = cpu_to_le32(wl->conf.rx.rx_msdu_life_time);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300175 ret = wl1271_cmd_configure(wl, DOT11_RX_MSDU_LIFE_TIME,
176 acx, sizeof(*acx));
177 if (ret < 0) {
178 wl1271_warning("failed to set rx msdu life time: %d", ret);
179 goto out;
180 }
181
182out:
183 kfree(acx);
184 return ret;
185}
186
187int wl1271_acx_rx_config(struct wl1271 *wl, u32 config, u32 filter)
188{
189 struct acx_rx_config *rx_config;
190 int ret;
191
192 wl1271_debug(DEBUG_ACX, "acx rx config");
193
194 rx_config = kzalloc(sizeof(*rx_config), GFP_KERNEL);
195 if (!rx_config) {
196 ret = -ENOMEM;
197 goto out;
198 }
199
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300200 rx_config->config_options = cpu_to_le32(config);
201 rx_config->filter_options = cpu_to_le32(filter);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300202
203 ret = wl1271_cmd_configure(wl, ACX_RX_CFG,
204 rx_config, sizeof(*rx_config));
205 if (ret < 0) {
206 wl1271_warning("failed to set rx config: %d", ret);
207 goto out;
208 }
209
210out:
211 kfree(rx_config);
212 return ret;
213}
214
215int wl1271_acx_pd_threshold(struct wl1271 *wl)
216{
217 struct acx_packet_detection *pd;
218 int ret;
219
220 wl1271_debug(DEBUG_ACX, "acx data pd threshold");
221
222 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
223 if (!pd) {
224 ret = -ENOMEM;
225 goto out;
226 }
227
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300228 pd->threshold = cpu_to_le32(wl->conf.rx.packet_detection_threshold);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300229
230 ret = wl1271_cmd_configure(wl, ACX_PD_THRESHOLD, pd, sizeof(*pd));
231 if (ret < 0) {
232 wl1271_warning("failed to set pd threshold: %d", ret);
233 goto out;
234 }
235
236out:
237 kfree(pd);
Julia Lawall36d34412010-08-16 18:27:30 +0200238 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300239}
240
241int wl1271_acx_slot(struct wl1271 *wl, enum acx_slot_type slot_time)
242{
243 struct acx_slot *slot;
244 int ret;
245
246 wl1271_debug(DEBUG_ACX, "acx slot");
247
248 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
249 if (!slot) {
250 ret = -ENOMEM;
251 goto out;
252 }
253
254 slot->wone_index = STATION_WONE_INDEX;
255 slot->slot_time = slot_time;
256
257 ret = wl1271_cmd_configure(wl, ACX_SLOT, slot, sizeof(*slot));
258 if (ret < 0) {
259 wl1271_warning("failed to set slot time: %d", ret);
260 goto out;
261 }
262
263out:
264 kfree(slot);
265 return ret;
266}
267
Juuso Oikarinenc87dec92009-10-08 21:56:31 +0300268int wl1271_acx_group_address_tbl(struct wl1271 *wl, bool enable,
269 void *mc_list, u32 mc_list_len)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300270{
271 struct acx_dot11_grp_addr_tbl *acx;
272 int ret;
273
274 wl1271_debug(DEBUG_ACX, "acx group address tbl");
275
276 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
277 if (!acx) {
278 ret = -ENOMEM;
279 goto out;
280 }
281
282 /* MAC filtering */
Juuso Oikarinenc87dec92009-10-08 21:56:31 +0300283 acx->enabled = enable;
284 acx->num_groups = mc_list_len;
285 memcpy(acx->mac_table, mc_list, mc_list_len * ETH_ALEN);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300286
287 ret = wl1271_cmd_configure(wl, DOT11_GROUP_ADDRESS_TBL,
288 acx, sizeof(*acx));
289 if (ret < 0) {
290 wl1271_warning("failed to set group addr table: %d", ret);
291 goto out;
292 }
293
294out:
295 kfree(acx);
296 return ret;
297}
298
299int wl1271_acx_service_period_timeout(struct wl1271 *wl)
300{
301 struct acx_rx_timeout *rx_timeout;
302 int ret;
303
304 rx_timeout = kzalloc(sizeof(*rx_timeout), GFP_KERNEL);
305 if (!rx_timeout) {
306 ret = -ENOMEM;
307 goto out;
308 }
309
310 wl1271_debug(DEBUG_ACX, "acx service period timeout");
311
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300312 rx_timeout->ps_poll_timeout = cpu_to_le16(wl->conf.rx.ps_poll_timeout);
313 rx_timeout->upsd_timeout = cpu_to_le16(wl->conf.rx.upsd_timeout);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300314
315 ret = wl1271_cmd_configure(wl, ACX_SERVICE_PERIOD_TIMEOUT,
316 rx_timeout, sizeof(*rx_timeout));
317 if (ret < 0) {
318 wl1271_warning("failed to set service period timeout: %d",
319 ret);
320 goto out;
321 }
322
323out:
324 kfree(rx_timeout);
325 return ret;
326}
327
328int wl1271_acx_rts_threshold(struct wl1271 *wl, u16 rts_threshold)
329{
330 struct acx_rts_threshold *rts;
331 int ret;
332
333 wl1271_debug(DEBUG_ACX, "acx rts threshold");
334
335 rts = kzalloc(sizeof(*rts), GFP_KERNEL);
336 if (!rts) {
337 ret = -ENOMEM;
338 goto out;
339 }
340
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300341 rts->threshold = cpu_to_le16(rts_threshold);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300342
343 ret = wl1271_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts));
344 if (ret < 0) {
345 wl1271_warning("failed to set rts threshold: %d", ret);
346 goto out;
347 }
348
349out:
350 kfree(rts);
351 return ret;
352}
353
Luciano Coelho6e92b412009-12-11 15:40:50 +0200354int wl1271_acx_dco_itrim_params(struct wl1271 *wl)
355{
356 struct acx_dco_itrim_params *dco;
357 struct conf_itrim_settings *c = &wl->conf.itrim;
358 int ret;
359
360 wl1271_debug(DEBUG_ACX, "acx dco itrim parameters");
361
362 dco = kzalloc(sizeof(*dco), GFP_KERNEL);
363 if (!dco) {
364 ret = -ENOMEM;
365 goto out;
366 }
367
368 dco->enable = c->enable;
369 dco->timeout = cpu_to_le32(c->timeout);
370
371 ret = wl1271_cmd_configure(wl, ACX_SET_DCO_ITRIM_PARAMS,
372 dco, sizeof(*dco));
373 if (ret < 0) {
374 wl1271_warning("failed to set dco itrim parameters: %d", ret);
375 goto out;
376 }
377
378out:
379 kfree(dco);
380 return ret;
381}
382
Juuso Oikarinen19221672009-10-08 21:56:35 +0300383int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, bool enable_filter)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300384{
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300385 struct acx_beacon_filter_option *beacon_filter = NULL;
386 int ret = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300387
388 wl1271_debug(DEBUG_ACX, "acx beacon filter opt");
389
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300390 if (enable_filter &&
391 wl->conf.conn.bcn_filt_mode == CONF_BCN_FILT_MODE_DISABLED)
392 goto out;
393
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300394 beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL);
395 if (!beacon_filter) {
396 ret = -ENOMEM;
397 goto out;
398 }
399
Juuso Oikarinen19221672009-10-08 21:56:35 +0300400 beacon_filter->enable = enable_filter;
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300401
402 /*
403 * When set to zero, and the filter is enabled, beacons
404 * without the unicast TIM bit set are dropped.
405 */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300406 beacon_filter->max_num_beacons = 0;
407
408 ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_OPT,
409 beacon_filter, sizeof(*beacon_filter));
410 if (ret < 0) {
411 wl1271_warning("failed to set beacon filter opt: %d", ret);
412 goto out;
413 }
414
415out:
416 kfree(beacon_filter);
417 return ret;
418}
419
420int wl1271_acx_beacon_filter_table(struct wl1271 *wl)
421{
422 struct acx_beacon_filter_ie_table *ie_table;
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300423 int i, idx = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300424 int ret;
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300425 bool vendor_spec = false;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300426
427 wl1271_debug(DEBUG_ACX, "acx beacon filter table");
428
429 ie_table = kzalloc(sizeof(*ie_table), GFP_KERNEL);
430 if (!ie_table) {
431 ret = -ENOMEM;
432 goto out;
433 }
434
Juuso Oikarinen19221672009-10-08 21:56:35 +0300435 /* configure default beacon pass-through rules */
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300436 ie_table->num_ie = 0;
437 for (i = 0; i < wl->conf.conn.bcn_filt_ie_count; i++) {
438 struct conf_bcn_filt_rule *r = &(wl->conf.conn.bcn_filt_ie[i]);
439 ie_table->table[idx++] = r->ie;
440 ie_table->table[idx++] = r->rule;
441
442 if (r->ie == WLAN_EID_VENDOR_SPECIFIC) {
443 /* only one vendor specific ie allowed */
444 if (vendor_spec)
445 continue;
446
447 /* for vendor specific rules configure the
448 additional fields */
449 memcpy(&(ie_table->table[idx]), r->oui,
450 CONF_BCN_IE_OUI_LEN);
451 idx += CONF_BCN_IE_OUI_LEN;
452 ie_table->table[idx++] = r->type;
453 memcpy(&(ie_table->table[idx]), r->version,
454 CONF_BCN_IE_VER_LEN);
455 idx += CONF_BCN_IE_VER_LEN;
456 vendor_spec = true;
457 }
458
459 ie_table->num_ie++;
460 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300461
462 ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_TABLE,
463 ie_table, sizeof(*ie_table));
464 if (ret < 0) {
465 wl1271_warning("failed to set beacon filter table: %d", ret);
466 goto out;
467 }
468
469out:
470 kfree(ie_table);
471 return ret;
472}
473
Juuso Oikarinen6ccbb922010-03-26 12:53:23 +0200474#define ACX_CONN_MONIT_DISABLE_VALUE 0xffffffff
475
476int wl1271_acx_conn_monit_params(struct wl1271 *wl, bool enable)
Juuso Oikarinen34415232009-10-08 21:56:33 +0300477{
478 struct acx_conn_monit_params *acx;
Juuso Oikarinen6ccbb922010-03-26 12:53:23 +0200479 u32 threshold = ACX_CONN_MONIT_DISABLE_VALUE;
480 u32 timeout = ACX_CONN_MONIT_DISABLE_VALUE;
Juuso Oikarinen34415232009-10-08 21:56:33 +0300481 int ret;
482
Juuso Oikarinen6ccbb922010-03-26 12:53:23 +0200483 wl1271_debug(DEBUG_ACX, "acx connection monitor parameters: %s",
484 enable ? "enabled" : "disabled");
Juuso Oikarinen34415232009-10-08 21:56:33 +0300485
486 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
487 if (!acx) {
488 ret = -ENOMEM;
489 goto out;
490 }
491
Juuso Oikarinen6ccbb922010-03-26 12:53:23 +0200492 if (enable) {
493 threshold = wl->conf.conn.synch_fail_thold;
494 timeout = wl->conf.conn.bss_lose_timeout;
495 }
496
497 acx->synch_fail_thold = cpu_to_le32(threshold);
498 acx->bss_lose_timeout = cpu_to_le32(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
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +0200514int wl1271_acx_sg_enable(struct wl1271 *wl, bool enable)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300515{
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
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +0200527 if (enable)
528 pta->enable = wl->conf.sg.state;
529 else
530 pta->enable = CONF_SG_DISABLE;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300531
532 ret = wl1271_cmd_configure(wl, ACX_SG_ENABLE, pta, sizeof(*pta));
533 if (ret < 0) {
534 wl1271_warning("failed to set softgemini enable: %d", ret);
535 goto out;
536 }
537
538out:
539 kfree(pta);
540 return ret;
541}
542
Arik Nemtsov801f8702011-04-18 14:15:20 +0300543int wl1271_acx_sta_sg_cfg(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300544{
Arik Nemtsov801f8702011-04-18 14:15:20 +0300545 struct acx_sta_bt_wlan_coex_param *param;
Juuso Oikarinen2b60100b2009-10-13 12:47:39 +0300546 struct conf_sg_settings *c = &wl->conf.sg;
Juuso Oikarinen1b00f542010-03-18 12:26:30 +0200547 int i, ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300548
Arik Nemtsov801f8702011-04-18 14:15:20 +0300549 wl1271_debug(DEBUG_ACX, "acx sg sta cfg");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300550
551 param = kzalloc(sizeof(*param), GFP_KERNEL);
552 if (!param) {
553 ret = -ENOMEM;
554 goto out;
555 }
556
557 /* BT-WLAN coext parameters */
Arik Nemtsov801f8702011-04-18 14:15:20 +0300558 for (i = 0; i < CONF_SG_STA_PARAMS_MAX; i++)
559 param->params[i] = cpu_to_le32(c->sta_params[i]);
560 param->param_idx = CONF_SG_PARAMS_ALL;
561
562 ret = wl1271_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param));
563 if (ret < 0) {
564 wl1271_warning("failed to set sg config: %d", ret);
565 goto out;
566 }
567
568out:
569 kfree(param);
570 return ret;
571}
572
573int wl1271_acx_ap_sg_cfg(struct wl1271 *wl)
574{
575 struct acx_ap_bt_wlan_coex_param *param;
576 struct conf_sg_settings *c = &wl->conf.sg;
577 int i, ret;
578
579 wl1271_debug(DEBUG_ACX, "acx sg ap cfg");
580
581 param = kzalloc(sizeof(*param), GFP_KERNEL);
582 if (!param) {
583 ret = -ENOMEM;
584 goto out;
585 }
586
587 /* BT-WLAN coext parameters */
588 for (i = 0; i < CONF_SG_AP_PARAMS_MAX; i++)
589 param->params[i] = cpu_to_le32(c->ap_params[i]);
Juuso Oikarinen1b00f542010-03-18 12:26:30 +0200590 param->param_idx = CONF_SG_PARAMS_ALL;
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
Arik Nemtsov79b223f2010-10-16 17:52:59 +0200784int wl1271_acx_sta_rate_policies(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300785{
Arik Nemtsov79b223f2010-10-16 17:52:59 +0200786 struct acx_sta_rate_policy *acx;
Arik Nemtsov1e05a812010-10-16 17:44:51 +0200787 struct conf_tx_rate_class *c = &wl->conf.tx.sta_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;
Juuso Oikarinenebba60c2010-04-01 11:38:20 +0300802 acx->rate_class[idx].enabled_rates = cpu_to_le32(wl->basic_rate);
Juuso Oikarinen830fb672009-12-11 15:41:06 +0200803 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
Eliad Peller72c2d9e2011-02-02 09:59:37 +0200816 wl1271_debug(DEBUG_ACX, "basic_rate: 0x%x, full_rate: 0x%x",
817 acx->rate_class[ACX_TX_BASIC_RATE].enabled_rates,
818 acx->rate_class[ACX_TX_AP_FULL_RATE].enabled_rates);
819
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300820 ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
821 if (ret < 0) {
822 wl1271_warning("Setting of rate policies failed: %d", ret);
823 goto out;
824 }
825
826out:
827 kfree(acx);
828 return ret;
829}
830
Arik Nemtsov79b223f2010-10-16 17:52:59 +0200831int wl1271_acx_ap_rate_policy(struct wl1271 *wl, struct conf_tx_rate_class *c,
832 u8 idx)
833{
834 struct acx_ap_rate_policy *acx;
835 int ret = 0;
836
837 wl1271_debug(DEBUG_ACX, "acx ap rate policy");
838
839 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
840 if (!acx) {
841 ret = -ENOMEM;
842 goto out;
843 }
844
845 acx->rate_policy.enabled_rates = cpu_to_le32(c->enabled_rates);
846 acx->rate_policy.short_retry_limit = c->short_retry_limit;
847 acx->rate_policy.long_retry_limit = c->long_retry_limit;
848 acx->rate_policy.aflags = c->aflags;
849
Eliad Peller1d4801f2011-01-16 10:07:10 +0100850 acx->rate_policy_idx = cpu_to_le32(idx);
Arik Nemtsov79b223f2010-10-16 17:52:59 +0200851
852 ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
853 if (ret < 0) {
854 wl1271_warning("Setting of ap rate policy failed: %d", ret);
855 goto out;
856 }
857
858out:
859 kfree(acx);
860 return ret;
861}
862
Kalle Valo243eeb52010-02-18 13:25:39 +0200863int wl1271_acx_ac_cfg(struct wl1271 *wl, u8 ac, u8 cw_min, u16 cw_max,
864 u8 aifsn, u16 txop)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300865{
866 struct acx_ac_cfg *acx;
Kalle Valo243eeb52010-02-18 13:25:39 +0200867 int ret = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300868
Kalle Valo243eeb52010-02-18 13:25:39 +0200869 wl1271_debug(DEBUG_ACX, "acx ac cfg %d cw_ming %d cw_max %d "
870 "aifs %d txop %d", ac, cw_min, cw_max, aifsn, txop);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300871
872 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
873
874 if (!acx) {
875 ret = -ENOMEM;
876 goto out;
877 }
878
Kalle Valo243eeb52010-02-18 13:25:39 +0200879 acx->ac = ac;
880 acx->cw_min = cw_min;
881 acx->cw_max = cpu_to_le16(cw_max);
882 acx->aifsn = aifsn;
883 acx->tx_op_limit = cpu_to_le16(txop);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300884
Kalle Valo243eeb52010-02-18 13:25:39 +0200885 ret = wl1271_cmd_configure(wl, ACX_AC_CFG, acx, sizeof(*acx));
886 if (ret < 0) {
887 wl1271_warning("acx ac cfg failed: %d", ret);
888 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300889 }
890
891out:
892 kfree(acx);
893 return ret;
894}
895
Kalle Valof2054df2010-02-18 13:25:40 +0200896int wl1271_acx_tid_cfg(struct wl1271 *wl, u8 queue_id, u8 channel_type,
897 u8 tsid, u8 ps_scheme, u8 ack_policy,
898 u32 apsd_conf0, u32 apsd_conf1)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300899{
900 struct acx_tid_config *acx;
Kalle Valof2054df2010-02-18 13:25:40 +0200901 int ret = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300902
903 wl1271_debug(DEBUG_ACX, "acx tid config");
904
905 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
906
907 if (!acx) {
908 ret = -ENOMEM;
909 goto out;
910 }
911
Kalle Valof2054df2010-02-18 13:25:40 +0200912 acx->queue_id = queue_id;
913 acx->channel_type = channel_type;
914 acx->tsid = tsid;
915 acx->ps_scheme = ps_scheme;
916 acx->ack_policy = ack_policy;
917 acx->apsd_conf[0] = cpu_to_le32(apsd_conf0);
918 acx->apsd_conf[1] = cpu_to_le32(apsd_conf1);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300919
Kalle Valof2054df2010-02-18 13:25:40 +0200920 ret = wl1271_cmd_configure(wl, ACX_TID_CFG, acx, sizeof(*acx));
921 if (ret < 0) {
922 wl1271_warning("Setting of tid config failed: %d", ret);
923 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300924 }
925
926out:
927 kfree(acx);
928 return ret;
929}
930
Arik Nemtsov68d069c2010-11-08 10:51:07 +0100931int wl1271_acx_frag_threshold(struct wl1271 *wl, u16 frag_threshold)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300932{
933 struct acx_frag_threshold *acx;
934 int ret = 0;
935
936 wl1271_debug(DEBUG_ACX, "acx frag threshold");
937
938 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
939
940 if (!acx) {
941 ret = -ENOMEM;
942 goto out;
943 }
944
Arik Nemtsov68d069c2010-11-08 10:51:07 +0100945 acx->frag_threshold = cpu_to_le16(frag_threshold);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300946 ret = wl1271_cmd_configure(wl, ACX_FRAG_CFG, acx, sizeof(*acx));
947 if (ret < 0) {
948 wl1271_warning("Setting of frag threshold failed: %d", ret);
949 goto out;
950 }
951
952out:
953 kfree(acx);
954 return ret;
955}
956
957int wl1271_acx_tx_config_options(struct wl1271 *wl)
958{
959 struct acx_tx_config_options *acx;
960 int ret = 0;
961
962 wl1271_debug(DEBUG_ACX, "acx tx config options");
963
964 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
965
966 if (!acx) {
967 ret = -ENOMEM;
968 goto out;
969 }
970
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300971 acx->tx_compl_timeout = cpu_to_le16(wl->conf.tx.tx_compl_timeout);
972 acx->tx_compl_threshold = cpu_to_le16(wl->conf.tx.tx_compl_threshold);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300973 ret = wl1271_cmd_configure(wl, ACX_TX_CONFIG_OPT, acx, sizeof(*acx));
974 if (ret < 0) {
975 wl1271_warning("Setting of tx options failed: %d", ret);
976 goto out;
977 }
978
979out:
980 kfree(acx);
981 return ret;
982}
983
Eliad Pellerc8bde242011-02-02 09:59:35 +0200984int wl1271_acx_ap_mem_cfg(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300985{
Eliad Pellerc8bde242011-02-02 09:59:35 +0200986 struct wl1271_acx_ap_config_memory *mem_conf;
Ido Yarivae825e42011-04-18 16:40:14 +0300987 struct conf_memory_settings *mem;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300988 int ret;
989
990 wl1271_debug(DEBUG_ACX, "wl1271 mem cfg");
991
992 mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL);
993 if (!mem_conf) {
994 ret = -ENOMEM;
995 goto out;
996 }
997
Ido Yarivae825e42011-04-18 16:40:14 +0300998 if (wl->chip.id == CHIP_ID_1283_PG20)
999 /*
1000 * FIXME: The 128x AP FW does not yet support dynamic memory.
1001 * Use the base memory configuration for 128x for now. This
1002 * should be fine tuned in the future.
1003 */
1004 mem = &wl->conf.mem_wl128x;
1005 else
1006 mem = &wl->conf.mem_wl127x;
1007
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001008 /* memory config */
Ido Yarivae825e42011-04-18 16:40:14 +03001009 mem_conf->num_stations = mem->num_stations;
1010 mem_conf->rx_mem_block_num = mem->rx_block_num;
1011 mem_conf->tx_min_mem_block_num = mem->tx_min_block_num;
1012 mem_conf->num_ssid_profiles = mem->ssid_profiles;
Luciano Coelhod0f63b22009-10-15 10:33:29 +03001013 mem_conf->total_tx_descriptors = cpu_to_le32(ACX_TX_DESCRIPTORS);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001014
1015 ret = wl1271_cmd_configure(wl, ACX_MEM_CFG, mem_conf,
1016 sizeof(*mem_conf));
1017 if (ret < 0) {
1018 wl1271_warning("wl1271 mem config failed: %d", ret);
1019 goto out;
1020 }
1021
1022out:
1023 kfree(mem_conf);
1024 return ret;
1025}
1026
Eliad Pellerc8bde242011-02-02 09:59:35 +02001027int wl1271_acx_sta_mem_cfg(struct wl1271 *wl)
1028{
1029 struct wl1271_acx_sta_config_memory *mem_conf;
Shahar Levi13b107d2011-03-06 16:32:12 +02001030 struct conf_memory_settings *mem;
Eliad Pellerc8bde242011-02-02 09:59:35 +02001031 int ret;
1032
1033 wl1271_debug(DEBUG_ACX, "wl1271 mem cfg");
1034
1035 mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL);
1036 if (!mem_conf) {
1037 ret = -ENOMEM;
1038 goto out;
1039 }
1040
Shahar Levi13b107d2011-03-06 16:32:12 +02001041 if (wl->chip.id == CHIP_ID_1283_PG20)
1042 mem = &wl->conf.mem_wl128x;
1043 else
1044 mem = &wl->conf.mem_wl127x;
1045
Eliad Pellerc8bde242011-02-02 09:59:35 +02001046 /* memory config */
Shahar Levi13b107d2011-03-06 16:32:12 +02001047 mem_conf->num_stations = mem->num_stations;
1048 mem_conf->rx_mem_block_num = mem->rx_block_num;
1049 mem_conf->tx_min_mem_block_num = mem->tx_min_block_num;
1050 mem_conf->num_ssid_profiles = mem->ssid_profiles;
Eliad Pellerc8bde242011-02-02 09:59:35 +02001051 mem_conf->total_tx_descriptors = cpu_to_le32(ACX_TX_DESCRIPTORS);
Shahar Levi13b107d2011-03-06 16:32:12 +02001052 mem_conf->dyn_mem_enable = mem->dynamic_memory;
1053 mem_conf->tx_free_req = mem->min_req_tx_blocks;
1054 mem_conf->rx_free_req = mem->min_req_rx_blocks;
1055 mem_conf->tx_min = mem->tx_min;
Eliad Pellerc8bde242011-02-02 09:59:35 +02001056
1057 ret = wl1271_cmd_configure(wl, ACX_MEM_CFG, mem_conf,
1058 sizeof(*mem_conf));
1059 if (ret < 0) {
1060 wl1271_warning("wl1271 mem config failed: %d", ret);
1061 goto out;
1062 }
1063
1064out:
1065 kfree(mem_conf);
1066 return ret;
1067}
1068
Shahar Levi48a61472011-03-06 16:32:08 +02001069int wl1271_acx_host_if_cfg_bitmap(struct wl1271 *wl, u32 host_cfg_bitmap)
1070{
1071 struct wl1271_acx_host_config_bitmap *bitmap_conf;
1072 int ret;
1073
1074 bitmap_conf = kzalloc(sizeof(*bitmap_conf), GFP_KERNEL);
1075 if (!bitmap_conf) {
1076 ret = -ENOMEM;
1077 goto out;
1078 }
1079
1080 bitmap_conf->host_cfg_bitmap = cpu_to_le32(host_cfg_bitmap);
1081
1082 ret = wl1271_cmd_configure(wl, ACX_HOST_IF_CFG_BITMAP,
1083 bitmap_conf, sizeof(*bitmap_conf));
1084 if (ret < 0) {
1085 wl1271_warning("wl1271 bitmap config opt failed: %d", ret);
1086 goto out;
1087 }
1088
1089out:
1090 kfree(bitmap_conf);
1091
1092 return ret;
1093}
1094
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001095int wl1271_acx_init_mem_config(struct wl1271 *wl)
1096{
1097 int ret;
1098
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001099 wl->target_mem_map = kzalloc(sizeof(struct wl1271_acx_mem_map),
Juuso Oikarinen45b531a2009-10-13 12:47:41 +03001100 GFP_KERNEL);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001101 if (!wl->target_mem_map) {
1102 wl1271_error("couldn't allocate target memory map");
1103 return -ENOMEM;
1104 }
1105
1106 /* we now ask for the firmware built memory map */
1107 ret = wl1271_acx_mem_map(wl, (void *)wl->target_mem_map,
1108 sizeof(struct wl1271_acx_mem_map));
1109 if (ret < 0) {
1110 wl1271_error("couldn't retrieve firmware memory map");
1111 kfree(wl->target_mem_map);
1112 wl->target_mem_map = NULL;
1113 return ret;
1114 }
1115
1116 /* initialize TX block book keeping */
Luciano Coelhod0f63b22009-10-15 10:33:29 +03001117 wl->tx_blocks_available =
1118 le32_to_cpu(wl->target_mem_map->num_tx_mem_blocks);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001119 wl1271_debug(DEBUG_TX, "available tx blocks: %d",
1120 wl->tx_blocks_available);
1121
1122 return 0;
1123}
1124
1125int wl1271_acx_init_rx_interrupt(struct wl1271 *wl)
1126{
1127 struct wl1271_acx_rx_config_opt *rx_conf;
1128 int ret;
1129
1130 wl1271_debug(DEBUG_ACX, "wl1271 rx interrupt config");
1131
1132 rx_conf = kzalloc(sizeof(*rx_conf), GFP_KERNEL);
1133 if (!rx_conf) {
1134 ret = -ENOMEM;
1135 goto out;
1136 }
1137
Luciano Coelhod0f63b22009-10-15 10:33:29 +03001138 rx_conf->threshold = cpu_to_le16(wl->conf.rx.irq_pkt_threshold);
1139 rx_conf->timeout = cpu_to_le16(wl->conf.rx.irq_timeout);
1140 rx_conf->mblk_threshold = cpu_to_le16(wl->conf.rx.irq_blk_threshold);
Juuso Oikarinen8793f9b2009-10-13 12:47:40 +03001141 rx_conf->queue_type = wl->conf.rx.queue_type;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001142
1143 ret = wl1271_cmd_configure(wl, ACX_RX_CONFIG_OPT, rx_conf,
1144 sizeof(*rx_conf));
1145 if (ret < 0) {
1146 wl1271_warning("wl1271 rx config opt failed: %d", ret);
1147 goto out;
1148 }
1149
1150out:
1151 kfree(rx_conf);
1152 return ret;
1153}
Juuso Oikarinen3cfd6cf2009-10-12 15:08:52 +03001154
Juuso Oikarinen11f70f92009-10-13 12:47:46 +03001155int wl1271_acx_bet_enable(struct wl1271 *wl, bool enable)
1156{
1157 struct wl1271_acx_bet_enable *acx = NULL;
1158 int ret = 0;
1159
1160 wl1271_debug(DEBUG_ACX, "acx bet enable");
1161
1162 if (enable && wl->conf.conn.bet_enable == CONF_BET_MODE_DISABLE)
1163 goto out;
1164
1165 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1166 if (!acx) {
1167 ret = -ENOMEM;
1168 goto out;
1169 }
1170
1171 acx->enable = enable ? CONF_BET_MODE_ENABLE : CONF_BET_MODE_DISABLE;
1172 acx->max_consecutive = wl->conf.conn.bet_max_consecutive;
1173
1174 ret = wl1271_cmd_configure(wl, ACX_BET_ENABLE, acx, sizeof(*acx));
1175 if (ret < 0) {
1176 wl1271_warning("acx bet enable failed: %d", ret);
1177 goto out;
1178 }
1179
1180out:
1181 kfree(acx);
1182 return ret;
1183}
Juuso Oikarinen01c09162009-10-13 12:47:55 +03001184
Eliad Pellerc5312772010-12-09 11:31:27 +02001185int wl1271_acx_arp_ip_filter(struct wl1271 *wl, u8 enable, __be32 address)
Juuso Oikarinen01c09162009-10-13 12:47:55 +03001186{
1187 struct wl1271_acx_arp_filter *acx;
1188 int ret;
1189
Juuso Oikarinenca52a5e2010-07-08 17:50:02 +03001190 wl1271_debug(DEBUG_ACX, "acx arp ip filter, enable: %d", enable);
Juuso Oikarinen01c09162009-10-13 12:47:55 +03001191
1192 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1193 if (!acx) {
1194 ret = -ENOMEM;
1195 goto out;
1196 }
1197
Juuso Oikarineneb887df2010-07-08 17:49:58 +03001198 acx->version = ACX_IPV4_VERSION;
Juuso Oikarinenca52a5e2010-07-08 17:50:02 +03001199 acx->enable = enable;
Juuso Oikarinen01c09162009-10-13 12:47:55 +03001200
Eliad Pellerc5312772010-12-09 11:31:27 +02001201 if (enable)
Juuso Oikarinenca52a5e2010-07-08 17:50:02 +03001202 memcpy(acx->address, &address, ACX_IPV4_ADDR_SIZE);
Juuso Oikarinen01c09162009-10-13 12:47:55 +03001203
1204 ret = wl1271_cmd_configure(wl, ACX_ARP_IP_FILTER,
1205 acx, sizeof(*acx));
1206 if (ret < 0) {
1207 wl1271_warning("failed to set arp ip filter: %d", ret);
1208 goto out;
1209 }
1210
1211out:
1212 kfree(acx);
1213 return ret;
1214}
Juuso Oikarinen38ad2d82009-12-11 15:41:08 +02001215
1216int wl1271_acx_pm_config(struct wl1271 *wl)
1217{
1218 struct wl1271_acx_pm_config *acx = NULL;
1219 struct conf_pm_config_settings *c = &wl->conf.pm_config;
1220 int ret = 0;
1221
1222 wl1271_debug(DEBUG_ACX, "acx pm config");
1223
1224 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1225 if (!acx) {
1226 ret = -ENOMEM;
1227 goto out;
1228 }
1229
1230 acx->host_clk_settling_time = cpu_to_le32(c->host_clk_settling_time);
1231 acx->host_fast_wakeup_support = c->host_fast_wakeup_support;
1232
1233 ret = wl1271_cmd_configure(wl, ACX_PM_CONFIG, acx, sizeof(*acx));
1234 if (ret < 0) {
1235 wl1271_warning("acx pm config failed: %d", ret);
1236 goto out;
1237 }
1238
1239out:
1240 kfree(acx);
1241 return ret;
1242}
Juuso Oikarinenc1899552010-03-26 12:53:32 +02001243
1244int wl1271_acx_keep_alive_mode(struct wl1271 *wl, bool enable)
1245{
1246 struct wl1271_acx_keep_alive_mode *acx = NULL;
1247 int ret = 0;
1248
1249 wl1271_debug(DEBUG_ACX, "acx keep alive mode: %d", enable);
1250
1251 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1252 if (!acx) {
1253 ret = -ENOMEM;
1254 goto out;
1255 }
1256
1257 acx->enabled = enable;
1258
1259 ret = wl1271_cmd_configure(wl, ACX_KEEP_ALIVE_MODE, acx, sizeof(*acx));
1260 if (ret < 0) {
1261 wl1271_warning("acx keep alive mode failed: %d", ret);
1262 goto out;
1263 }
1264
1265out:
1266 kfree(acx);
1267 return ret;
1268}
Juuso Oikarinen00236aed2010-04-09 11:07:30 +03001269
Juuso Oikarinenc1899552010-03-26 12:53:32 +02001270int wl1271_acx_keep_alive_config(struct wl1271 *wl, u8 index, u8 tpl_valid)
1271{
1272 struct wl1271_acx_keep_alive_config *acx = NULL;
1273 int ret = 0;
1274
1275 wl1271_debug(DEBUG_ACX, "acx keep alive config");
1276
1277 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1278 if (!acx) {
1279 ret = -ENOMEM;
1280 goto out;
1281 }
1282
1283 acx->period = cpu_to_le32(wl->conf.conn.keep_alive_interval);
1284 acx->index = index;
1285 acx->tpl_validation = tpl_valid;
1286 acx->trigger = ACX_KEEP_ALIVE_NO_TX;
1287
1288 ret = wl1271_cmd_configure(wl, ACX_SET_KEEP_ALIVE_CONFIG,
1289 acx, sizeof(*acx));
1290 if (ret < 0) {
1291 wl1271_warning("acx keep alive config failed: %d", ret);
1292 goto out;
1293 }
1294
1295out:
1296 kfree(acx);
1297 return ret;
1298}
Juuso Oikarinen00236aed2010-04-09 11:07:30 +03001299
1300int wl1271_acx_rssi_snr_trigger(struct wl1271 *wl, bool enable,
1301 s16 thold, u8 hyst)
1302{
1303 struct wl1271_acx_rssi_snr_trigger *acx = NULL;
1304 int ret = 0;
1305
1306 wl1271_debug(DEBUG_ACX, "acx rssi snr trigger");
1307
1308 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1309 if (!acx) {
1310 ret = -ENOMEM;
1311 goto out;
1312 }
1313
1314 wl->last_rssi_event = -1;
1315
1316 acx->pacing = cpu_to_le16(wl->conf.roam_trigger.trigger_pacing);
1317 acx->metric = WL1271_ACX_TRIG_METRIC_RSSI_BEACON;
1318 acx->type = WL1271_ACX_TRIG_TYPE_EDGE;
1319 if (enable)
1320 acx->enable = WL1271_ACX_TRIG_ENABLE;
1321 else
1322 acx->enable = WL1271_ACX_TRIG_DISABLE;
1323
1324 acx->index = WL1271_ACX_TRIG_IDX_RSSI;
1325 acx->dir = WL1271_ACX_TRIG_DIR_BIDIR;
1326 acx->threshold = cpu_to_le16(thold);
1327 acx->hysteresis = hyst;
1328
1329 ret = wl1271_cmd_configure(wl, ACX_RSSI_SNR_TRIGGER, acx, sizeof(*acx));
1330 if (ret < 0) {
1331 wl1271_warning("acx rssi snr trigger setting failed: %d", ret);
1332 goto out;
1333 }
1334
1335out:
1336 kfree(acx);
1337 return ret;
1338}
1339
1340int wl1271_acx_rssi_snr_avg_weights(struct wl1271 *wl)
1341{
1342 struct wl1271_acx_rssi_snr_avg_weights *acx = NULL;
1343 struct conf_roam_trigger_settings *c = &wl->conf.roam_trigger;
1344 int ret = 0;
1345
1346 wl1271_debug(DEBUG_ACX, "acx rssi snr avg weights");
1347
1348 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1349 if (!acx) {
1350 ret = -ENOMEM;
1351 goto out;
1352 }
1353
1354 acx->rssi_beacon = c->avg_weight_rssi_beacon;
1355 acx->rssi_data = c->avg_weight_rssi_data;
1356 acx->snr_beacon = c->avg_weight_snr_beacon;
1357 acx->snr_data = c->avg_weight_snr_data;
1358
1359 ret = wl1271_cmd_configure(wl, ACX_RSSI_SNR_WEIGHTS, acx, sizeof(*acx));
1360 if (ret < 0) {
1361 wl1271_warning("acx rssi snr trigger weights failed: %d", ret);
1362 goto out;
1363 }
1364
1365out:
1366 kfree(acx);
1367 return ret;
1368}
Juuso Oikarinenbbbb5382010-07-08 17:49:57 +03001369
Shahar Levic4db1c82010-10-13 16:09:40 +02001370int wl1271_acx_set_ht_capabilities(struct wl1271 *wl,
1371 struct ieee80211_sta_ht_cap *ht_cap,
1372 bool allow_ht_operation)
1373{
1374 struct wl1271_acx_ht_capabilities *acx;
1375 u8 mac_address[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1376 int ret = 0;
Eliad Peller6177eae2010-12-22 12:38:52 +01001377 u32 ht_capabilites = 0;
Shahar Levic4db1c82010-10-13 16:09:40 +02001378
1379 wl1271_debug(DEBUG_ACX, "acx ht capabilities setting");
1380
1381 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1382 if (!acx) {
1383 ret = -ENOMEM;
1384 goto out;
1385 }
1386
1387 /* Allow HT Operation ? */
1388 if (allow_ht_operation) {
Eliad Peller6177eae2010-12-22 12:38:52 +01001389 ht_capabilites =
Shahar Levic4db1c82010-10-13 16:09:40 +02001390 WL1271_ACX_FW_CAP_HT_OPERATION;
1391 if (ht_cap->cap & IEEE80211_HT_CAP_GRN_FLD)
Eliad Peller6177eae2010-12-22 12:38:52 +01001392 ht_capabilites |=
Shahar Levic4db1c82010-10-13 16:09:40 +02001393 WL1271_ACX_FW_CAP_GREENFIELD_FRAME_FORMAT;
1394 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
Eliad Peller6177eae2010-12-22 12:38:52 +01001395 ht_capabilites |=
Shahar Levic4db1c82010-10-13 16:09:40 +02001396 WL1271_ACX_FW_CAP_SHORT_GI_FOR_20MHZ_PACKETS;
1397 if (ht_cap->cap & IEEE80211_HT_CAP_LSIG_TXOP_PROT)
Eliad Peller6177eae2010-12-22 12:38:52 +01001398 ht_capabilites |=
Shahar Levic4db1c82010-10-13 16:09:40 +02001399 WL1271_ACX_FW_CAP_LSIG_TXOP_PROTECTION;
1400
1401 /* get data from A-MPDU parameters field */
1402 acx->ampdu_max_length = ht_cap->ampdu_factor;
1403 acx->ampdu_min_spacing = ht_cap->ampdu_density;
Shahar Levic4db1c82010-10-13 16:09:40 +02001404 }
1405
Eliad Peller6dc9fb32011-02-23 00:27:07 +02001406 memcpy(acx->mac_address, mac_address, ETH_ALEN);
Eliad Peller6177eae2010-12-22 12:38:52 +01001407 acx->ht_capabilites = cpu_to_le32(ht_capabilites);
1408
Shahar Levic4db1c82010-10-13 16:09:40 +02001409 ret = wl1271_cmd_configure(wl, ACX_PEER_HT_CAP, acx, sizeof(*acx));
1410 if (ret < 0) {
1411 wl1271_warning("acx ht capabilities setting failed: %d", ret);
1412 goto out;
1413 }
1414
1415out:
1416 kfree(acx);
1417 return ret;
1418}
1419
1420int wl1271_acx_set_ht_information(struct wl1271 *wl,
1421 u16 ht_operation_mode)
1422{
1423 struct wl1271_acx_ht_information *acx;
1424 int ret = 0;
1425
1426 wl1271_debug(DEBUG_ACX, "acx ht information setting");
1427
1428 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1429 if (!acx) {
1430 ret = -ENOMEM;
1431 goto out;
1432 }
1433
1434 acx->ht_protection =
1435 (u8)(ht_operation_mode & IEEE80211_HT_OP_MODE_PROTECTION);
1436 acx->rifs_mode = 0;
Helmut Schaa95a77612011-03-02 10:46:46 +01001437 acx->gf_protection =
1438 !!(ht_operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
Shahar Levic4db1c82010-10-13 16:09:40 +02001439 acx->ht_tx_burst_limit = 0;
1440 acx->dual_cts_protection = 0;
1441
1442 ret = wl1271_cmd_configure(wl, ACX_HT_BSS_OPERATION, acx, sizeof(*acx));
1443
1444 if (ret < 0) {
1445 wl1271_warning("acx ht information setting failed: %d", ret);
1446 goto out;
1447 }
1448
1449out:
1450 kfree(acx);
1451 return ret;
1452}
1453
Levi, Shahar4b7fac72011-01-23 07:27:22 +01001454/* Configure BA session initiator/receiver parameters setting in the FW. */
1455int wl1271_acx_set_ba_session(struct wl1271 *wl,
1456 enum ieee80211_back_parties direction,
1457 u8 tid_index, u8 policy)
1458{
1459 struct wl1271_acx_ba_session_policy *acx;
1460 int ret;
1461
1462 wl1271_debug(DEBUG_ACX, "acx ba session setting");
1463
1464 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1465 if (!acx) {
1466 ret = -ENOMEM;
1467 goto out;
1468 }
1469
1470 /* ANY role */
1471 acx->role_id = 0xff;
1472 acx->tid = tid_index;
1473 acx->enable = policy;
1474 acx->ba_direction = direction;
1475
1476 switch (direction) {
1477 case WLAN_BACK_INITIATOR:
1478 acx->win_size = wl->conf.ht.tx_ba_win_size;
1479 acx->inactivity_timeout = wl->conf.ht.inactivity_timeout;
1480 break;
1481 case WLAN_BACK_RECIPIENT:
1482 acx->win_size = RX_BA_WIN_SIZE;
1483 acx->inactivity_timeout = 0;
1484 break;
1485 default:
1486 wl1271_error("Incorrect acx command id=%x\n", direction);
1487 ret = -EINVAL;
1488 goto out;
1489 }
1490
1491 ret = wl1271_cmd_configure(wl,
1492 ACX_BA_SESSION_POLICY_CFG,
1493 acx,
1494 sizeof(*acx));
1495 if (ret < 0) {
1496 wl1271_warning("acx ba session setting failed: %d", ret);
1497 goto out;
1498 }
1499
1500out:
1501 kfree(acx);
1502 return ret;
1503}
1504
Levi, Shaharbbba3e62011-01-23 07:27:23 +01001505/* setup BA session receiver setting in the FW. */
1506int wl1271_acx_set_ba_receiver_session(struct wl1271 *wl, u8 tid_index, u16 ssn,
1507 bool enable)
1508{
1509 struct wl1271_acx_ba_receiver_setup *acx;
1510 int ret;
1511
1512 wl1271_debug(DEBUG_ACX, "acx ba receiver session setting");
1513
1514 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1515 if (!acx) {
1516 ret = -ENOMEM;
1517 goto out;
1518 }
1519
1520 /* Single link for now */
1521 acx->link_id = 1;
1522 acx->tid = tid_index;
1523 acx->enable = enable;
1524 acx->win_size = 0;
1525 acx->ssn = ssn;
1526
1527 ret = wl1271_cmd_configure(wl, ACX_BA_SESSION_RX_SETUP, acx,
1528 sizeof(*acx));
1529 if (ret < 0) {
1530 wl1271_warning("acx ba receiver session failed: %d", ret);
1531 goto out;
1532 }
1533
1534out:
1535 kfree(acx);
1536 return ret;
1537}
1538
Juuso Oikarinenbbbb5382010-07-08 17:49:57 +03001539int wl1271_acx_tsf_info(struct wl1271 *wl, u64 *mactime)
1540{
1541 struct wl1271_acx_fw_tsf_information *tsf_info;
1542 int ret;
1543
1544 tsf_info = kzalloc(sizeof(*tsf_info), GFP_KERNEL);
1545 if (!tsf_info) {
1546 ret = -ENOMEM;
1547 goto out;
1548 }
1549
1550 ret = wl1271_cmd_interrogate(wl, ACX_TSF_INFO,
1551 tsf_info, sizeof(*tsf_info));
1552 if (ret < 0) {
1553 wl1271_warning("acx tsf info interrogate failed");
1554 goto out;
1555 }
1556
1557 *mactime = le32_to_cpu(tsf_info->current_tsf_low) |
1558 ((u64) le32_to_cpu(tsf_info->current_tsf_high) << 32);
1559
1560out:
1561 kfree(tsf_info);
1562 return ret;
1563}
Arik Nemtsov79b223f2010-10-16 17:52:59 +02001564
Arik Nemtsov47684802011-04-26 23:21:51 +03001565int wl1271_acx_ap_max_tx_retry(struct wl1271 *wl)
Arik Nemtsov79b223f2010-10-16 17:52:59 +02001566{
Arik Nemtsov47684802011-04-26 23:21:51 +03001567 struct wl1271_acx_ap_max_tx_retry *acx = NULL;
Arik Nemtsov79b223f2010-10-16 17:52:59 +02001568 int ret;
1569
Arik Nemtsov47684802011-04-26 23:21:51 +03001570 wl1271_debug(DEBUG_ACX, "acx ap max tx retry");
Arik Nemtsov79b223f2010-10-16 17:52:59 +02001571
1572 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1573 if (!acx)
1574 return -ENOMEM;
1575
Arik Nemtsov47684802011-04-26 23:21:51 +03001576 acx->max_tx_retry = cpu_to_le16(wl->conf.tx.max_tx_retries);
Arik Nemtsov79b223f2010-10-16 17:52:59 +02001577
1578 ret = wl1271_cmd_configure(wl, ACX_MAX_TX_FAILURE, acx, sizeof(*acx));
1579 if (ret < 0) {
Arik Nemtsov47684802011-04-26 23:21:51 +03001580 wl1271_warning("acx ap max tx retry failed: %d", ret);
1581 goto out;
1582 }
1583
1584out:
1585 kfree(acx);
1586 return ret;
1587}
1588
1589int wl1271_acx_sta_max_tx_retry(struct wl1271 *wl)
1590{
1591 struct wl1271_acx_sta_max_tx_retry *acx = NULL;
1592 int ret;
1593
1594 wl1271_debug(DEBUG_ACX, "acx sta max tx retry");
1595
1596 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1597 if (!acx)
1598 return -ENOMEM;
1599
1600 acx->max_tx_retry = wl->conf.tx.max_tx_retries;
1601
1602 ret = wl1271_cmd_configure(wl, ACX_CONS_TX_FAILURE, acx, sizeof(*acx));
1603 if (ret < 0) {
1604 wl1271_warning("acx sta max tx retry failed: %d", ret);
Arik Nemtsov79b223f2010-10-16 17:52:59 +02001605 goto out;
1606 }
1607
1608out:
1609 kfree(acx);
1610 return ret;
1611}
Eliad Pelleree608332011-02-02 09:59:34 +02001612
1613int wl1271_acx_config_ps(struct wl1271 *wl)
1614{
1615 struct wl1271_acx_config_ps *config_ps;
1616 int ret;
1617
1618 wl1271_debug(DEBUG_ACX, "acx config ps");
1619
1620 config_ps = kzalloc(sizeof(*config_ps), GFP_KERNEL);
1621 if (!config_ps) {
1622 ret = -ENOMEM;
1623 goto out;
1624 }
1625
1626 config_ps->exit_retries = wl->conf.conn.psm_exit_retries;
1627 config_ps->enter_retries = wl->conf.conn.psm_entry_retries;
1628 config_ps->null_data_rate = cpu_to_le32(wl->basic_rate);
1629
1630 ret = wl1271_cmd_configure(wl, ACX_CONFIG_PS, config_ps,
1631 sizeof(*config_ps));
1632
1633 if (ret < 0) {
1634 wl1271_warning("acx config ps failed: %d", ret);
1635 goto out;
1636 }
1637
1638out:
1639 kfree(config_ps);
1640 return ret;
1641}
Arik Nemtsov99a27752011-02-23 00:22:25 +02001642
1643int wl1271_acx_set_inconnection_sta(struct wl1271 *wl, u8 *addr)
1644{
1645 struct wl1271_acx_inconnection_sta *acx = NULL;
1646 int ret;
1647
1648 wl1271_debug(DEBUG_ACX, "acx set inconnaction sta %pM", addr);
1649
1650 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1651 if (!acx)
1652 return -ENOMEM;
1653
1654 memcpy(acx->addr, addr, ETH_ALEN);
1655
1656 ret = wl1271_cmd_configure(wl, ACX_UPDATE_INCONNECTION_STA_LIST,
1657 acx, sizeof(*acx));
1658 if (ret < 0) {
1659 wl1271_warning("acx set inconnaction sta failed: %d", ret);
1660 goto out;
1661 }
1662
1663out:
1664 kfree(acx);
1665 return ret;
1666}
Shahar Leviff868432011-04-11 15:41:46 +03001667
1668int wl1271_acx_fm_coex(struct wl1271 *wl)
1669{
1670 struct wl1271_acx_fm_coex *acx;
1671 int ret;
1672
1673 wl1271_debug(DEBUG_ACX, "acx fm coex setting");
1674
1675 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1676 if (!acx) {
1677 ret = -ENOMEM;
1678 goto out;
1679 }
1680
1681 acx->enable = wl->conf.fm_coex.enable;
1682 acx->swallow_period = wl->conf.fm_coex.swallow_period;
1683 acx->n_divider_fref_set_1 = wl->conf.fm_coex.n_divider_fref_set_1;
1684 acx->n_divider_fref_set_2 = wl->conf.fm_coex.n_divider_fref_set_2;
1685 acx->m_divider_fref_set_1 =
1686 cpu_to_le16(wl->conf.fm_coex.m_divider_fref_set_1);
1687 acx->m_divider_fref_set_2 =
1688 cpu_to_le16(wl->conf.fm_coex.m_divider_fref_set_2);
1689 acx->coex_pll_stabilization_time =
1690 cpu_to_le32(wl->conf.fm_coex.coex_pll_stabilization_time);
1691 acx->ldo_stabilization_time =
1692 cpu_to_le16(wl->conf.fm_coex.ldo_stabilization_time);
1693 acx->fm_disturbed_band_margin =
1694 wl->conf.fm_coex.fm_disturbed_band_margin;
1695 acx->swallow_clk_diff = wl->conf.fm_coex.swallow_clk_diff;
1696
1697 ret = wl1271_cmd_configure(wl, ACX_FM_COEX_CFG, acx, sizeof(*acx));
1698 if (ret < 0) {
1699 wl1271_warning("acx fm coex setting failed: %d", ret);
1700 goto out;
1701 }
1702
1703out:
1704 kfree(acx);
1705 return ret;
1706}