wl1251: enable beacon early termination while in power-saving mode
[pandora-wifi.git] / drivers / net / wireless / wl12xx / wl1271_acx.c
1 /*
2  * This file is part of wl1271
3  *
4  * Copyright (C) 2008-2009 Nokia Corporation
5  *
6  * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * version 2 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  *
22  */
23
24 #include "wl1271_acx.h"
25
26 #include <linux/module.h>
27 #include <linux/platform_device.h>
28 #include <linux/crc7.h>
29 #include <linux/spi/spi.h>
30
31 #include "wl1271.h"
32 #include "wl12xx_80211.h"
33 #include "wl1271_reg.h"
34 #include "wl1271_spi.h"
35 #include "wl1271_ps.h"
36
37 int wl1271_acx_wake_up_conditions(struct wl1271 *wl)
38 {
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
50         wake_up->wake_up_event = wl->conf.conn.wake_up_event;
51         wake_up->listen_interval = wl->conf.conn.listen_interval;
52
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
60 out:
61         kfree(wake_up);
62         return ret;
63 }
64
65 int 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
84 out:
85         kfree(auth);
86         return ret;
87 }
88
89 int wl1271_acx_fw_version(struct wl1271 *wl, char *buf, size_t len)
90 {
91         struct acx_revision *rev;
92         int ret;
93
94         wl1271_debug(DEBUG_ACX, "acx fw rev");
95
96         rev = kzalloc(sizeof(*rev), GFP_KERNEL);
97         if (!rev) {
98                 ret = -ENOMEM;
99                 goto out;
100         }
101
102         ret = wl1271_cmd_interrogate(wl, ACX_FW_REV, rev, sizeof(*rev));
103         if (ret < 0) {
104                 wl1271_warning("ACX_FW_REV interrogate failed");
105                 goto out;
106         }
107
108         /* be careful with the buffer sizes */
109         strncpy(buf, rev->fw_version, min(len, sizeof(rev->fw_version)));
110
111         /*
112          * if the firmware version string is exactly
113          * sizeof(rev->fw_version) long or fw_len is less than
114          * sizeof(rev->fw_version) it won't be null terminated
115          */
116         buf[min(len, sizeof(rev->fw_version)) - 1] = '\0';
117
118 out:
119         kfree(rev);
120         return ret;
121 }
122
123 int wl1271_acx_tx_power(struct wl1271 *wl, int power)
124 {
125         struct acx_current_tx_power *acx;
126         int ret;
127
128         wl1271_debug(DEBUG_ACX, "acx dot11_cur_tx_pwr");
129
130         if (power < 0 || power > 25)
131                 return -EINVAL;
132
133         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
134         if (!acx) {
135                 ret = -ENOMEM;
136                 goto out;
137         }
138
139         /*
140          * FIXME: This is a workaround needed while we don't the correct
141          * calibration, to avoid distortions
142          */
143         /* acx->current_tx_power = power * 10; */
144         acx->current_tx_power = 120;
145
146         ret = wl1271_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx));
147         if (ret < 0) {
148                 wl1271_warning("configure of tx power failed: %d", ret);
149                 goto out;
150         }
151
152 out:
153         kfree(acx);
154         return ret;
155 }
156
157 int wl1271_acx_feature_cfg(struct wl1271 *wl)
158 {
159         struct acx_feature_config *feature;
160         int ret;
161
162         wl1271_debug(DEBUG_ACX, "acx feature cfg");
163
164         feature = kzalloc(sizeof(*feature), GFP_KERNEL);
165         if (!feature) {
166                 ret = -ENOMEM;
167                 goto out;
168         }
169
170         /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */
171         feature->data_flow_options = 0;
172         feature->options = 0;
173
174         ret = wl1271_cmd_configure(wl, ACX_FEATURE_CFG,
175                                    feature, sizeof(*feature));
176         if (ret < 0) {
177                 wl1271_error("Couldnt set HW encryption");
178                 goto out;
179         }
180
181 out:
182         kfree(feature);
183         return ret;
184 }
185
186 int wl1271_acx_mem_map(struct wl1271 *wl, struct acx_header *mem_map,
187                        size_t len)
188 {
189         int ret;
190
191         wl1271_debug(DEBUG_ACX, "acx mem map");
192
193         ret = wl1271_cmd_interrogate(wl, ACX_MEM_MAP, mem_map, len);
194         if (ret < 0)
195                 return ret;
196
197         return 0;
198 }
199
200 int wl1271_acx_rx_msdu_life_time(struct wl1271 *wl)
201 {
202         struct acx_rx_msdu_lifetime *acx;
203         int ret;
204
205         wl1271_debug(DEBUG_ACX, "acx rx msdu life time");
206
207         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
208         if (!acx) {
209                 ret = -ENOMEM;
210                 goto out;
211         }
212
213         acx->lifetime = cpu_to_le32(wl->conf.rx.rx_msdu_life_time);
214         ret = wl1271_cmd_configure(wl, DOT11_RX_MSDU_LIFE_TIME,
215                                    acx, sizeof(*acx));
216         if (ret < 0) {
217                 wl1271_warning("failed to set rx msdu life time: %d", ret);
218                 goto out;
219         }
220
221 out:
222         kfree(acx);
223         return ret;
224 }
225
226 int wl1271_acx_rx_config(struct wl1271 *wl, u32 config, u32 filter)
227 {
228         struct acx_rx_config *rx_config;
229         int ret;
230
231         wl1271_debug(DEBUG_ACX, "acx rx config");
232
233         rx_config = kzalloc(sizeof(*rx_config), GFP_KERNEL);
234         if (!rx_config) {
235                 ret = -ENOMEM;
236                 goto out;
237         }
238
239         rx_config->config_options = cpu_to_le32(config);
240         rx_config->filter_options = cpu_to_le32(filter);
241
242         ret = wl1271_cmd_configure(wl, ACX_RX_CFG,
243                                    rx_config, sizeof(*rx_config));
244         if (ret < 0) {
245                 wl1271_warning("failed to set rx config: %d", ret);
246                 goto out;
247         }
248
249 out:
250         kfree(rx_config);
251         return ret;
252 }
253
254 int wl1271_acx_pd_threshold(struct wl1271 *wl)
255 {
256         struct acx_packet_detection *pd;
257         int ret;
258
259         wl1271_debug(DEBUG_ACX, "acx data pd threshold");
260
261         pd = kzalloc(sizeof(*pd), GFP_KERNEL);
262         if (!pd) {
263                 ret = -ENOMEM;
264                 goto out;
265         }
266
267         pd->threshold = cpu_to_le32(wl->conf.rx.packet_detection_threshold);
268
269         ret = wl1271_cmd_configure(wl, ACX_PD_THRESHOLD, pd, sizeof(*pd));
270         if (ret < 0) {
271                 wl1271_warning("failed to set pd threshold: %d", ret);
272                 goto out;
273         }
274
275 out:
276         kfree(pd);
277         return 0;
278 }
279
280 int wl1271_acx_slot(struct wl1271 *wl, enum acx_slot_type slot_time)
281 {
282         struct acx_slot *slot;
283         int ret;
284
285         wl1271_debug(DEBUG_ACX, "acx slot");
286
287         slot = kzalloc(sizeof(*slot), GFP_KERNEL);
288         if (!slot) {
289                 ret = -ENOMEM;
290                 goto out;
291         }
292
293         slot->wone_index = STATION_WONE_INDEX;
294         slot->slot_time = slot_time;
295
296         ret = wl1271_cmd_configure(wl, ACX_SLOT, slot, sizeof(*slot));
297         if (ret < 0) {
298                 wl1271_warning("failed to set slot time: %d", ret);
299                 goto out;
300         }
301
302 out:
303         kfree(slot);
304         return ret;
305 }
306
307 int wl1271_acx_group_address_tbl(struct wl1271 *wl, bool enable,
308                                  void *mc_list, u32 mc_list_len)
309 {
310         struct acx_dot11_grp_addr_tbl *acx;
311         int ret;
312
313         wl1271_debug(DEBUG_ACX, "acx group address tbl");
314
315         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
316         if (!acx) {
317                 ret = -ENOMEM;
318                 goto out;
319         }
320
321         /* MAC filtering */
322         acx->enabled = enable;
323         acx->num_groups = mc_list_len;
324         memcpy(acx->mac_table, mc_list, mc_list_len * ETH_ALEN);
325
326         ret = wl1271_cmd_configure(wl, DOT11_GROUP_ADDRESS_TBL,
327                                    acx, sizeof(*acx));
328         if (ret < 0) {
329                 wl1271_warning("failed to set group addr table: %d", ret);
330                 goto out;
331         }
332
333 out:
334         kfree(acx);
335         return ret;
336 }
337
338 int wl1271_acx_service_period_timeout(struct wl1271 *wl)
339 {
340         struct acx_rx_timeout *rx_timeout;
341         int ret;
342
343         rx_timeout = kzalloc(sizeof(*rx_timeout), GFP_KERNEL);
344         if (!rx_timeout) {
345                 ret = -ENOMEM;
346                 goto out;
347         }
348
349         wl1271_debug(DEBUG_ACX, "acx service period timeout");
350
351         rx_timeout->ps_poll_timeout = cpu_to_le16(wl->conf.rx.ps_poll_timeout);
352         rx_timeout->upsd_timeout = cpu_to_le16(wl->conf.rx.upsd_timeout);
353
354         ret = wl1271_cmd_configure(wl, ACX_SERVICE_PERIOD_TIMEOUT,
355                                    rx_timeout, sizeof(*rx_timeout));
356         if (ret < 0) {
357                 wl1271_warning("failed to set service period timeout: %d",
358                                ret);
359                 goto out;
360         }
361
362 out:
363         kfree(rx_timeout);
364         return ret;
365 }
366
367 int wl1271_acx_rts_threshold(struct wl1271 *wl, u16 rts_threshold)
368 {
369         struct acx_rts_threshold *rts;
370         int ret;
371
372         wl1271_debug(DEBUG_ACX, "acx rts threshold");
373
374         rts = kzalloc(sizeof(*rts), GFP_KERNEL);
375         if (!rts) {
376                 ret = -ENOMEM;
377                 goto out;
378         }
379
380         rts->threshold = cpu_to_le16(rts_threshold);
381
382         ret = wl1271_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts));
383         if (ret < 0) {
384                 wl1271_warning("failed to set rts threshold: %d", ret);
385                 goto out;
386         }
387
388 out:
389         kfree(rts);
390         return ret;
391 }
392
393 int wl1271_acx_dco_itrim_params(struct wl1271 *wl)
394 {
395         struct acx_dco_itrim_params *dco;
396         struct conf_itrim_settings *c = &wl->conf.itrim;
397         int ret;
398
399         wl1271_debug(DEBUG_ACX, "acx dco itrim parameters");
400
401         dco = kzalloc(sizeof(*dco), GFP_KERNEL);
402         if (!dco) {
403                 ret = -ENOMEM;
404                 goto out;
405         }
406
407         dco->enable = c->enable;
408         dco->timeout = cpu_to_le32(c->timeout);
409
410         ret = wl1271_cmd_configure(wl, ACX_SET_DCO_ITRIM_PARAMS,
411                                    dco, sizeof(*dco));
412         if (ret < 0) {
413                 wl1271_warning("failed to set dco itrim parameters: %d", ret);
414                 goto out;
415         }
416
417 out:
418         kfree(dco);
419         return ret;
420 }
421
422 int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, bool enable_filter)
423 {
424         struct acx_beacon_filter_option *beacon_filter = NULL;
425         int ret = 0;
426
427         wl1271_debug(DEBUG_ACX, "acx beacon filter opt");
428
429         if (enable_filter &&
430             wl->conf.conn.bcn_filt_mode == CONF_BCN_FILT_MODE_DISABLED)
431                 goto out;
432
433         beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL);
434         if (!beacon_filter) {
435                 ret = -ENOMEM;
436                 goto out;
437         }
438
439         beacon_filter->enable = enable_filter;
440
441         /*
442          * When set to zero, and the filter is enabled, beacons
443          * without the unicast TIM bit set are dropped.
444          */
445         beacon_filter->max_num_beacons = 0;
446
447         ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_OPT,
448                                    beacon_filter, sizeof(*beacon_filter));
449         if (ret < 0) {
450                 wl1271_warning("failed to set beacon filter opt: %d", ret);
451                 goto out;
452         }
453
454 out:
455         kfree(beacon_filter);
456         return ret;
457 }
458
459 int wl1271_acx_beacon_filter_table(struct wl1271 *wl)
460 {
461         struct acx_beacon_filter_ie_table *ie_table;
462         int i, idx = 0;
463         int ret;
464         bool vendor_spec = false;
465
466         wl1271_debug(DEBUG_ACX, "acx beacon filter table");
467
468         ie_table = kzalloc(sizeof(*ie_table), GFP_KERNEL);
469         if (!ie_table) {
470                 ret = -ENOMEM;
471                 goto out;
472         }
473
474         /* configure default beacon pass-through rules */
475         ie_table->num_ie = 0;
476         for (i = 0; i < wl->conf.conn.bcn_filt_ie_count; i++) {
477                 struct conf_bcn_filt_rule *r = &(wl->conf.conn.bcn_filt_ie[i]);
478                 ie_table->table[idx++] = r->ie;
479                 ie_table->table[idx++] = r->rule;
480
481                 if (r->ie == WLAN_EID_VENDOR_SPECIFIC) {
482                         /* only one vendor specific ie allowed */
483                         if (vendor_spec)
484                                 continue;
485
486                         /* for vendor specific rules configure the
487                            additional fields */
488                         memcpy(&(ie_table->table[idx]), r->oui,
489                                CONF_BCN_IE_OUI_LEN);
490                         idx += CONF_BCN_IE_OUI_LEN;
491                         ie_table->table[idx++] = r->type;
492                         memcpy(&(ie_table->table[idx]), r->version,
493                                CONF_BCN_IE_VER_LEN);
494                         idx += CONF_BCN_IE_VER_LEN;
495                         vendor_spec = true;
496                 }
497
498                 ie_table->num_ie++;
499         }
500
501         ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_TABLE,
502                                    ie_table, sizeof(*ie_table));
503         if (ret < 0) {
504                 wl1271_warning("failed to set beacon filter table: %d", ret);
505                 goto out;
506         }
507
508 out:
509         kfree(ie_table);
510         return ret;
511 }
512
513 int wl1271_acx_conn_monit_params(struct wl1271 *wl)
514 {
515         struct acx_conn_monit_params *acx;
516         int ret;
517
518         wl1271_debug(DEBUG_ACX, "acx connection monitor parameters");
519
520         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
521         if (!acx) {
522                 ret = -ENOMEM;
523                 goto out;
524         }
525
526         acx->synch_fail_thold = cpu_to_le32(wl->conf.conn.synch_fail_thold);
527         acx->bss_lose_timeout = cpu_to_le32(wl->conf.conn.bss_lose_timeout);
528
529         ret = wl1271_cmd_configure(wl, ACX_CONN_MONIT_PARAMS,
530                                    acx, sizeof(*acx));
531         if (ret < 0) {
532                 wl1271_warning("failed to set connection monitor "
533                                "parameters: %d", ret);
534                 goto out;
535         }
536
537 out:
538         kfree(acx);
539         return ret;
540 }
541
542
543 int wl1271_acx_sg_enable(struct wl1271 *wl)
544 {
545         struct acx_bt_wlan_coex *pta;
546         int ret;
547
548         wl1271_debug(DEBUG_ACX, "acx sg enable");
549
550         pta = kzalloc(sizeof(*pta), GFP_KERNEL);
551         if (!pta) {
552                 ret = -ENOMEM;
553                 goto out;
554         }
555
556         pta->enable = SG_ENABLE;
557
558         ret = wl1271_cmd_configure(wl, ACX_SG_ENABLE, pta, sizeof(*pta));
559         if (ret < 0) {
560                 wl1271_warning("failed to set softgemini enable: %d", ret);
561                 goto out;
562         }
563
564 out:
565         kfree(pta);
566         return ret;
567 }
568
569 int wl1271_acx_sg_cfg(struct wl1271 *wl)
570 {
571         struct acx_bt_wlan_coex_param *param;
572         struct conf_sg_settings *c = &wl->conf.sg;
573         int ret;
574
575         wl1271_debug(DEBUG_ACX, "acx sg cfg");
576
577         param = kzalloc(sizeof(*param), GFP_KERNEL);
578         if (!param) {
579                 ret = -ENOMEM;
580                 goto out;
581         }
582
583         /* BT-WLAN coext parameters */
584         param->per_threshold = cpu_to_le32(c->per_threshold);
585         param->max_scan_compensation_time =
586                 cpu_to_le32(c->max_scan_compensation_time);
587         param->nfs_sample_interval = cpu_to_le16(c->nfs_sample_interval);
588         param->load_ratio = c->load_ratio;
589         param->auto_ps_mode = c->auto_ps_mode;
590         param->probe_req_compensation = c->probe_req_compensation;
591         param->scan_window_compensation = c->scan_window_compensation;
592         param->antenna_config = c->antenna_config;
593         param->beacon_miss_threshold = c->beacon_miss_threshold;
594         param->rate_adaptation_threshold =
595                 cpu_to_le32(c->rate_adaptation_threshold);
596         param->rate_adaptation_snr = c->rate_adaptation_snr;
597
598         ret = wl1271_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param));
599         if (ret < 0) {
600                 wl1271_warning("failed to set sg config: %d", ret);
601                 goto out;
602         }
603
604 out:
605         kfree(param);
606         return ret;
607 }
608
609 int wl1271_acx_cca_threshold(struct wl1271 *wl)
610 {
611         struct acx_energy_detection *detection;
612         int ret;
613
614         wl1271_debug(DEBUG_ACX, "acx cca threshold");
615
616         detection = kzalloc(sizeof(*detection), GFP_KERNEL);
617         if (!detection) {
618                 ret = -ENOMEM;
619                 goto out;
620         }
621
622         detection->rx_cca_threshold = cpu_to_le16(wl->conf.rx.rx_cca_threshold);
623         detection->tx_energy_detection = wl->conf.tx.tx_energy_detection;
624
625         ret = wl1271_cmd_configure(wl, ACX_CCA_THRESHOLD,
626                                    detection, sizeof(*detection));
627         if (ret < 0) {
628                 wl1271_warning("failed to set cca threshold: %d", ret);
629                 return ret;
630         }
631
632 out:
633         kfree(detection);
634         return ret;
635 }
636
637 int wl1271_acx_bcn_dtim_options(struct wl1271 *wl)
638 {
639         struct acx_beacon_broadcast *bb;
640         int ret;
641
642         wl1271_debug(DEBUG_ACX, "acx bcn dtim options");
643
644         bb = kzalloc(sizeof(*bb), GFP_KERNEL);
645         if (!bb) {
646                 ret = -ENOMEM;
647                 goto out;
648         }
649
650         bb->beacon_rx_timeout = cpu_to_le16(wl->conf.conn.beacon_rx_timeout);
651         bb->broadcast_timeout = cpu_to_le16(wl->conf.conn.broadcast_timeout);
652         bb->rx_broadcast_in_ps = wl->conf.conn.rx_broadcast_in_ps;
653         bb->ps_poll_threshold = wl->conf.conn.ps_poll_threshold;
654
655         ret = wl1271_cmd_configure(wl, ACX_BCN_DTIM_OPTIONS, bb, sizeof(*bb));
656         if (ret < 0) {
657                 wl1271_warning("failed to set rx config: %d", ret);
658                 goto out;
659         }
660
661 out:
662         kfree(bb);
663         return ret;
664 }
665
666 int wl1271_acx_aid(struct wl1271 *wl, u16 aid)
667 {
668         struct acx_aid *acx_aid;
669         int ret;
670
671         wl1271_debug(DEBUG_ACX, "acx aid");
672
673         acx_aid = kzalloc(sizeof(*acx_aid), GFP_KERNEL);
674         if (!acx_aid) {
675                 ret = -ENOMEM;
676                 goto out;
677         }
678
679         acx_aid->aid = cpu_to_le16(aid);
680
681         ret = wl1271_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid));
682         if (ret < 0) {
683                 wl1271_warning("failed to set aid: %d", ret);
684                 goto out;
685         }
686
687 out:
688         kfree(acx_aid);
689         return ret;
690 }
691
692 int wl1271_acx_event_mbox_mask(struct wl1271 *wl, u32 event_mask)
693 {
694         struct acx_event_mask *mask;
695         int ret;
696
697         wl1271_debug(DEBUG_ACX, "acx event mbox mask");
698
699         mask = kzalloc(sizeof(*mask), GFP_KERNEL);
700         if (!mask) {
701                 ret = -ENOMEM;
702                 goto out;
703         }
704
705         /* high event mask is unused */
706         mask->high_event_mask = cpu_to_le32(0xffffffff);
707         mask->event_mask = cpu_to_le32(event_mask);
708
709         ret = wl1271_cmd_configure(wl, ACX_EVENT_MBOX_MASK,
710                                    mask, sizeof(*mask));
711         if (ret < 0) {
712                 wl1271_warning("failed to set acx_event_mbox_mask: %d", ret);
713                 goto out;
714         }
715
716 out:
717         kfree(mask);
718         return ret;
719 }
720
721 int wl1271_acx_set_preamble(struct wl1271 *wl, enum acx_preamble_type preamble)
722 {
723         struct acx_preamble *acx;
724         int ret;
725
726         wl1271_debug(DEBUG_ACX, "acx_set_preamble");
727
728         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
729         if (!acx) {
730                 ret = -ENOMEM;
731                 goto out;
732         }
733
734         acx->preamble = preamble;
735
736         ret = wl1271_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx));
737         if (ret < 0) {
738                 wl1271_warning("Setting of preamble failed: %d", ret);
739                 goto out;
740         }
741
742 out:
743         kfree(acx);
744         return ret;
745 }
746
747 int wl1271_acx_cts_protect(struct wl1271 *wl,
748                            enum acx_ctsprotect_type ctsprotect)
749 {
750         struct acx_ctsprotect *acx;
751         int ret;
752
753         wl1271_debug(DEBUG_ACX, "acx_set_ctsprotect");
754
755         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
756         if (!acx) {
757                 ret = -ENOMEM;
758                 goto out;
759         }
760
761         acx->ctsprotect = ctsprotect;
762
763         ret = wl1271_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx));
764         if (ret < 0) {
765                 wl1271_warning("Setting of ctsprotect failed: %d", ret);
766                 goto out;
767         }
768
769 out:
770         kfree(acx);
771         return ret;
772 }
773
774 int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats)
775 {
776         int ret;
777
778         wl1271_debug(DEBUG_ACX, "acx statistics");
779
780         ret = wl1271_cmd_interrogate(wl, ACX_STATISTICS, stats,
781                                      sizeof(*stats));
782         if (ret < 0) {
783                 wl1271_warning("acx statistics failed: %d", ret);
784                 return -ENOMEM;
785         }
786
787         return 0;
788 }
789
790 int wl1271_acx_rate_policies(struct wl1271 *wl)
791 {
792         struct acx_rate_policy *acx;
793         struct conf_tx_rate_class *c = &wl->conf.tx.rc_conf;
794         int idx = 0;
795         int ret = 0;
796
797         wl1271_debug(DEBUG_ACX, "acx rate policies");
798
799         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
800
801         if (!acx) {
802                 ret = -ENOMEM;
803                 goto out;
804         }
805
806         /* configure one basic rate class */
807         idx = ACX_TX_BASIC_RATE;
808         acx->rate_class[idx].enabled_rates = cpu_to_le32(wl->basic_rate_set);
809         acx->rate_class[idx].short_retry_limit = c->short_retry_limit;
810         acx->rate_class[idx].long_retry_limit = c->long_retry_limit;
811         acx->rate_class[idx].aflags = c->aflags;
812
813         /* configure one AP supported rate class */
814         idx = ACX_TX_AP_FULL_RATE;
815         acx->rate_class[idx].enabled_rates = cpu_to_le32(wl->rate_set);
816         acx->rate_class[idx].short_retry_limit = c->short_retry_limit;
817         acx->rate_class[idx].long_retry_limit = c->long_retry_limit;
818         acx->rate_class[idx].aflags = c->aflags;
819
820         acx->rate_class_cnt = cpu_to_le32(ACX_TX_RATE_POLICY_CNT);
821
822         ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
823         if (ret < 0) {
824                 wl1271_warning("Setting of rate policies failed: %d", ret);
825                 goto out;
826         }
827
828 out:
829         kfree(acx);
830         return ret;
831 }
832
833 int wl1271_acx_ac_cfg(struct wl1271 *wl, u8 ac, u8 cw_min, u16 cw_max,
834                       u8 aifsn, u16 txop)
835 {
836         struct acx_ac_cfg *acx;
837         int ret = 0;
838
839         wl1271_debug(DEBUG_ACX, "acx ac cfg %d cw_ming %d cw_max %d "
840                      "aifs %d txop %d", ac, cw_min, cw_max, aifsn, txop);
841
842         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
843
844         if (!acx) {
845                 ret = -ENOMEM;
846                 goto out;
847         }
848
849         acx->ac = ac;
850         acx->cw_min = cw_min;
851         acx->cw_max = cpu_to_le16(cw_max);
852         acx->aifsn = aifsn;
853         acx->tx_op_limit = cpu_to_le16(txop);
854
855         ret = wl1271_cmd_configure(wl, ACX_AC_CFG, acx, sizeof(*acx));
856         if (ret < 0) {
857                 wl1271_warning("acx ac cfg failed: %d", ret);
858                 goto out;
859         }
860
861 out:
862         kfree(acx);
863         return ret;
864 }
865
866 int wl1271_acx_tid_cfg(struct wl1271 *wl, u8 queue_id, u8 channel_type,
867                        u8 tsid, u8 ps_scheme, u8 ack_policy,
868                        u32 apsd_conf0, u32 apsd_conf1)
869 {
870         struct acx_tid_config *acx;
871         int ret = 0;
872
873         wl1271_debug(DEBUG_ACX, "acx tid config");
874
875         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
876
877         if (!acx) {
878                 ret = -ENOMEM;
879                 goto out;
880         }
881
882         acx->queue_id = queue_id;
883         acx->channel_type = channel_type;
884         acx->tsid = tsid;
885         acx->ps_scheme = ps_scheme;
886         acx->ack_policy = ack_policy;
887         acx->apsd_conf[0] = cpu_to_le32(apsd_conf0);
888         acx->apsd_conf[1] = cpu_to_le32(apsd_conf1);
889
890         ret = wl1271_cmd_configure(wl, ACX_TID_CFG, acx, sizeof(*acx));
891         if (ret < 0) {
892                 wl1271_warning("Setting of tid config failed: %d", ret);
893                 goto out;
894         }
895
896 out:
897         kfree(acx);
898         return ret;
899 }
900
901 int wl1271_acx_frag_threshold(struct wl1271 *wl)
902 {
903         struct acx_frag_threshold *acx;
904         int ret = 0;
905
906         wl1271_debug(DEBUG_ACX, "acx frag threshold");
907
908         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
909
910         if (!acx) {
911                 ret = -ENOMEM;
912                 goto out;
913         }
914
915         acx->frag_threshold = cpu_to_le16(wl->conf.tx.frag_threshold);
916         ret = wl1271_cmd_configure(wl, ACX_FRAG_CFG, acx, sizeof(*acx));
917         if (ret < 0) {
918                 wl1271_warning("Setting of frag threshold failed: %d", ret);
919                 goto out;
920         }
921
922 out:
923         kfree(acx);
924         return ret;
925 }
926
927 int wl1271_acx_tx_config_options(struct wl1271 *wl)
928 {
929         struct acx_tx_config_options *acx;
930         int ret = 0;
931
932         wl1271_debug(DEBUG_ACX, "acx tx config options");
933
934         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
935
936         if (!acx) {
937                 ret = -ENOMEM;
938                 goto out;
939         }
940
941         acx->tx_compl_timeout = cpu_to_le16(wl->conf.tx.tx_compl_timeout);
942         acx->tx_compl_threshold = cpu_to_le16(wl->conf.tx.tx_compl_threshold);
943         ret = wl1271_cmd_configure(wl, ACX_TX_CONFIG_OPT, acx, sizeof(*acx));
944         if (ret < 0) {
945                 wl1271_warning("Setting of tx options failed: %d", ret);
946                 goto out;
947         }
948
949 out:
950         kfree(acx);
951         return ret;
952 }
953
954 int wl1271_acx_mem_cfg(struct wl1271 *wl)
955 {
956         struct wl1271_acx_config_memory *mem_conf;
957         int ret;
958
959         wl1271_debug(DEBUG_ACX, "wl1271 mem cfg");
960
961         mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL);
962         if (!mem_conf) {
963                 ret = -ENOMEM;
964                 goto out;
965         }
966
967         /* memory config */
968         mem_conf->num_stations = DEFAULT_NUM_STATIONS;
969         mem_conf->rx_mem_block_num = ACX_RX_MEM_BLOCKS;
970         mem_conf->tx_min_mem_block_num = ACX_TX_MIN_MEM_BLOCKS;
971         mem_conf->num_ssid_profiles = ACX_NUM_SSID_PROFILES;
972         mem_conf->total_tx_descriptors = cpu_to_le32(ACX_TX_DESCRIPTORS);
973
974         ret = wl1271_cmd_configure(wl, ACX_MEM_CFG, mem_conf,
975                                    sizeof(*mem_conf));
976         if (ret < 0) {
977                 wl1271_warning("wl1271 mem config failed: %d", ret);
978                 goto out;
979         }
980
981 out:
982         kfree(mem_conf);
983         return ret;
984 }
985
986 int wl1271_acx_init_mem_config(struct wl1271 *wl)
987 {
988         int ret;
989
990         ret = wl1271_acx_mem_cfg(wl);
991         if (ret < 0)
992                 return ret;
993
994         wl->target_mem_map = kzalloc(sizeof(struct wl1271_acx_mem_map),
995                                      GFP_KERNEL);
996         if (!wl->target_mem_map) {
997                 wl1271_error("couldn't allocate target memory map");
998                 return -ENOMEM;
999         }
1000
1001         /* we now ask for the firmware built memory map */
1002         ret = wl1271_acx_mem_map(wl, (void *)wl->target_mem_map,
1003                                  sizeof(struct wl1271_acx_mem_map));
1004         if (ret < 0) {
1005                 wl1271_error("couldn't retrieve firmware memory map");
1006                 kfree(wl->target_mem_map);
1007                 wl->target_mem_map = NULL;
1008                 return ret;
1009         }
1010
1011         /* initialize TX block book keeping */
1012         wl->tx_blocks_available =
1013                 le32_to_cpu(wl->target_mem_map->num_tx_mem_blocks);
1014         wl1271_debug(DEBUG_TX, "available tx blocks: %d",
1015                      wl->tx_blocks_available);
1016
1017         return 0;
1018 }
1019
1020 int wl1271_acx_init_rx_interrupt(struct wl1271 *wl)
1021 {
1022         struct wl1271_acx_rx_config_opt *rx_conf;
1023         int ret;
1024
1025         wl1271_debug(DEBUG_ACX, "wl1271 rx interrupt config");
1026
1027         rx_conf = kzalloc(sizeof(*rx_conf), GFP_KERNEL);
1028         if (!rx_conf) {
1029                 ret = -ENOMEM;
1030                 goto out;
1031         }
1032
1033         rx_conf->threshold = cpu_to_le16(wl->conf.rx.irq_pkt_threshold);
1034         rx_conf->timeout = cpu_to_le16(wl->conf.rx.irq_timeout);
1035         rx_conf->mblk_threshold = cpu_to_le16(wl->conf.rx.irq_blk_threshold);
1036         rx_conf->queue_type = wl->conf.rx.queue_type;
1037
1038         ret = wl1271_cmd_configure(wl, ACX_RX_CONFIG_OPT, rx_conf,
1039                                    sizeof(*rx_conf));
1040         if (ret < 0) {
1041                 wl1271_warning("wl1271 rx config opt failed: %d", ret);
1042                 goto out;
1043         }
1044
1045 out:
1046         kfree(rx_conf);
1047         return ret;
1048 }
1049
1050 int wl1271_acx_bet_enable(struct wl1271 *wl, bool enable)
1051 {
1052         struct wl1271_acx_bet_enable *acx = NULL;
1053         int ret = 0;
1054
1055         wl1271_debug(DEBUG_ACX, "acx bet enable");
1056
1057         if (enable && wl->conf.conn.bet_enable == CONF_BET_MODE_DISABLE)
1058                 goto out;
1059
1060         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1061         if (!acx) {
1062                 ret = -ENOMEM;
1063                 goto out;
1064         }
1065
1066         acx->enable = enable ? CONF_BET_MODE_ENABLE : CONF_BET_MODE_DISABLE;
1067         acx->max_consecutive = wl->conf.conn.bet_max_consecutive;
1068
1069         ret = wl1271_cmd_configure(wl, ACX_BET_ENABLE, acx, sizeof(*acx));
1070         if (ret < 0) {
1071                 wl1271_warning("acx bet enable failed: %d", ret);
1072                 goto out;
1073         }
1074
1075 out:
1076         kfree(acx);
1077         return ret;
1078 }
1079
1080 int wl1271_acx_arp_ip_filter(struct wl1271 *wl, bool enable, u8 *address,
1081                              u8 version)
1082 {
1083         struct wl1271_acx_arp_filter *acx;
1084         int ret;
1085
1086         wl1271_debug(DEBUG_ACX, "acx arp ip filter, enable: %d", enable);
1087
1088         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1089         if (!acx) {
1090                 ret = -ENOMEM;
1091                 goto out;
1092         }
1093
1094         acx->version = version;
1095         acx->enable = enable;
1096
1097         if (enable == true) {
1098                 if (version == ACX_IPV4_VERSION)
1099                         memcpy(acx->address, address, ACX_IPV4_ADDR_SIZE);
1100                 else if (version == ACX_IPV6_VERSION)
1101                         memcpy(acx->address, address, sizeof(acx->address));
1102                 else
1103                         wl1271_error("Invalid IP version");
1104         }
1105
1106         ret = wl1271_cmd_configure(wl, ACX_ARP_IP_FILTER,
1107                                    acx, sizeof(*acx));
1108         if (ret < 0) {
1109                 wl1271_warning("failed to set arp ip filter: %d", ret);
1110                 goto out;
1111         }
1112
1113 out:
1114         kfree(acx);
1115         return ret;
1116 }
1117
1118 int wl1271_acx_pm_config(struct wl1271 *wl)
1119 {
1120         struct wl1271_acx_pm_config *acx = NULL;
1121         struct  conf_pm_config_settings *c = &wl->conf.pm_config;
1122         int ret = 0;
1123
1124         wl1271_debug(DEBUG_ACX, "acx pm config");
1125
1126         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1127         if (!acx) {
1128                 ret = -ENOMEM;
1129                 goto out;
1130         }
1131
1132         acx->host_clk_settling_time = cpu_to_le32(c->host_clk_settling_time);
1133         acx->host_fast_wakeup_support = c->host_fast_wakeup_support;
1134
1135         ret = wl1271_cmd_configure(wl, ACX_PM_CONFIG, acx, sizeof(*acx));
1136         if (ret < 0) {
1137                 wl1271_warning("acx pm config failed: %d", ret);
1138                 goto out;
1139         }
1140
1141 out:
1142         kfree(acx);
1143         return ret;
1144 }