wl1271: fix a bunch of sparse warnings
[pandora-kernel.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_ps.h"
35
36 int wl1271_acx_wake_up_conditions(struct wl1271 *wl)
37 {
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
49         wake_up->wake_up_event = wl->conf.conn.wake_up_event;
50         wake_up->listen_interval = wl->conf.conn.listen_interval;
51
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
59 out:
60         kfree(wake_up);
61         return ret;
62 }
63
64 int 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
83 out:
84         kfree(auth);
85         return ret;
86 }
87
88 int 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
117 out:
118         kfree(rev);
119         return ret;
120 }
121
122 int 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
138         acx->current_tx_power = power * 10;
139
140         ret = wl1271_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx));
141         if (ret < 0) {
142                 wl1271_warning("configure of tx power failed: %d", ret);
143                 goto out;
144         }
145
146 out:
147         kfree(acx);
148         return ret;
149 }
150
151 int wl1271_acx_feature_cfg(struct wl1271 *wl)
152 {
153         struct acx_feature_config *feature;
154         int ret;
155
156         wl1271_debug(DEBUG_ACX, "acx feature cfg");
157
158         feature = kzalloc(sizeof(*feature), GFP_KERNEL);
159         if (!feature) {
160                 ret = -ENOMEM;
161                 goto out;
162         }
163
164         /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */
165         feature->data_flow_options = 0;
166         feature->options = 0;
167
168         ret = wl1271_cmd_configure(wl, ACX_FEATURE_CFG,
169                                    feature, sizeof(*feature));
170         if (ret < 0) {
171                 wl1271_error("Couldnt set HW encryption");
172                 goto out;
173         }
174
175 out:
176         kfree(feature);
177         return ret;
178 }
179
180 int wl1271_acx_mem_map(struct wl1271 *wl, struct acx_header *mem_map,
181                        size_t len)
182 {
183         int ret;
184
185         wl1271_debug(DEBUG_ACX, "acx mem map");
186
187         ret = wl1271_cmd_interrogate(wl, ACX_MEM_MAP, mem_map, len);
188         if (ret < 0)
189                 return ret;
190
191         return 0;
192 }
193
194 int wl1271_acx_rx_msdu_life_time(struct wl1271 *wl)
195 {
196         struct acx_rx_msdu_lifetime *acx;
197         int ret;
198
199         wl1271_debug(DEBUG_ACX, "acx rx msdu life time");
200
201         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
202         if (!acx) {
203                 ret = -ENOMEM;
204                 goto out;
205         }
206
207         acx->lifetime = cpu_to_le32(wl->conf.rx.rx_msdu_life_time);
208         ret = wl1271_cmd_configure(wl, DOT11_RX_MSDU_LIFE_TIME,
209                                    acx, sizeof(*acx));
210         if (ret < 0) {
211                 wl1271_warning("failed to set rx msdu life time: %d", ret);
212                 goto out;
213         }
214
215 out:
216         kfree(acx);
217         return ret;
218 }
219
220 int wl1271_acx_rx_config(struct wl1271 *wl, u32 config, u32 filter)
221 {
222         struct acx_rx_config *rx_config;
223         int ret;
224
225         wl1271_debug(DEBUG_ACX, "acx rx config");
226
227         rx_config = kzalloc(sizeof(*rx_config), GFP_KERNEL);
228         if (!rx_config) {
229                 ret = -ENOMEM;
230                 goto out;
231         }
232
233         rx_config->config_options = cpu_to_le32(config);
234         rx_config->filter_options = cpu_to_le32(filter);
235
236         ret = wl1271_cmd_configure(wl, ACX_RX_CFG,
237                                    rx_config, sizeof(*rx_config));
238         if (ret < 0) {
239                 wl1271_warning("failed to set rx config: %d", ret);
240                 goto out;
241         }
242
243 out:
244         kfree(rx_config);
245         return ret;
246 }
247
248 int wl1271_acx_pd_threshold(struct wl1271 *wl)
249 {
250         struct acx_packet_detection *pd;
251         int ret;
252
253         wl1271_debug(DEBUG_ACX, "acx data pd threshold");
254
255         pd = kzalloc(sizeof(*pd), GFP_KERNEL);
256         if (!pd) {
257                 ret = -ENOMEM;
258                 goto out;
259         }
260
261         pd->threshold = cpu_to_le32(wl->conf.rx.packet_detection_threshold);
262
263         ret = wl1271_cmd_configure(wl, ACX_PD_THRESHOLD, pd, sizeof(*pd));
264         if (ret < 0) {
265                 wl1271_warning("failed to set pd threshold: %d", ret);
266                 goto out;
267         }
268
269 out:
270         kfree(pd);
271         return 0;
272 }
273
274 int wl1271_acx_slot(struct wl1271 *wl, enum acx_slot_type slot_time)
275 {
276         struct acx_slot *slot;
277         int ret;
278
279         wl1271_debug(DEBUG_ACX, "acx slot");
280
281         slot = kzalloc(sizeof(*slot), GFP_KERNEL);
282         if (!slot) {
283                 ret = -ENOMEM;
284                 goto out;
285         }
286
287         slot->wone_index = STATION_WONE_INDEX;
288         slot->slot_time = slot_time;
289
290         ret = wl1271_cmd_configure(wl, ACX_SLOT, slot, sizeof(*slot));
291         if (ret < 0) {
292                 wl1271_warning("failed to set slot time: %d", ret);
293                 goto out;
294         }
295
296 out:
297         kfree(slot);
298         return ret;
299 }
300
301 int wl1271_acx_group_address_tbl(struct wl1271 *wl, bool enable,
302                                  void *mc_list, u32 mc_list_len)
303 {
304         struct acx_dot11_grp_addr_tbl *acx;
305         int ret;
306
307         wl1271_debug(DEBUG_ACX, "acx group address tbl");
308
309         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
310         if (!acx) {
311                 ret = -ENOMEM;
312                 goto out;
313         }
314
315         /* MAC filtering */
316         acx->enabled = enable;
317         acx->num_groups = mc_list_len;
318         memcpy(acx->mac_table, mc_list, mc_list_len * ETH_ALEN);
319
320         ret = wl1271_cmd_configure(wl, DOT11_GROUP_ADDRESS_TBL,
321                                    acx, sizeof(*acx));
322         if (ret < 0) {
323                 wl1271_warning("failed to set group addr table: %d", ret);
324                 goto out;
325         }
326
327 out:
328         kfree(acx);
329         return ret;
330 }
331
332 int wl1271_acx_service_period_timeout(struct wl1271 *wl)
333 {
334         struct acx_rx_timeout *rx_timeout;
335         int ret;
336
337         rx_timeout = kzalloc(sizeof(*rx_timeout), GFP_KERNEL);
338         if (!rx_timeout) {
339                 ret = -ENOMEM;
340                 goto out;
341         }
342
343         wl1271_debug(DEBUG_ACX, "acx service period timeout");
344
345         rx_timeout->ps_poll_timeout = cpu_to_le16(wl->conf.rx.ps_poll_timeout);
346         rx_timeout->upsd_timeout = cpu_to_le16(wl->conf.rx.upsd_timeout);
347
348         ret = wl1271_cmd_configure(wl, ACX_SERVICE_PERIOD_TIMEOUT,
349                                    rx_timeout, sizeof(*rx_timeout));
350         if (ret < 0) {
351                 wl1271_warning("failed to set service period timeout: %d",
352                                ret);
353                 goto out;
354         }
355
356 out:
357         kfree(rx_timeout);
358         return ret;
359 }
360
361 int wl1271_acx_rts_threshold(struct wl1271 *wl, u16 rts_threshold)
362 {
363         struct acx_rts_threshold *rts;
364         int ret;
365
366         wl1271_debug(DEBUG_ACX, "acx rts threshold");
367
368         rts = kzalloc(sizeof(*rts), GFP_KERNEL);
369         if (!rts) {
370                 ret = -ENOMEM;
371                 goto out;
372         }
373
374         rts->threshold = cpu_to_le16(rts_threshold);
375
376         ret = wl1271_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts));
377         if (ret < 0) {
378                 wl1271_warning("failed to set rts threshold: %d", ret);
379                 goto out;
380         }
381
382 out:
383         kfree(rts);
384         return ret;
385 }
386
387 int wl1271_acx_dco_itrim_params(struct wl1271 *wl)
388 {
389         struct acx_dco_itrim_params *dco;
390         struct conf_itrim_settings *c = &wl->conf.itrim;
391         int ret;
392
393         wl1271_debug(DEBUG_ACX, "acx dco itrim parameters");
394
395         dco = kzalloc(sizeof(*dco), GFP_KERNEL);
396         if (!dco) {
397                 ret = -ENOMEM;
398                 goto out;
399         }
400
401         dco->enable = c->enable;
402         dco->timeout = cpu_to_le32(c->timeout);
403
404         ret = wl1271_cmd_configure(wl, ACX_SET_DCO_ITRIM_PARAMS,
405                                    dco, sizeof(*dco));
406         if (ret < 0) {
407                 wl1271_warning("failed to set dco itrim parameters: %d", ret);
408                 goto out;
409         }
410
411 out:
412         kfree(dco);
413         return ret;
414 }
415
416 int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, bool enable_filter)
417 {
418         struct acx_beacon_filter_option *beacon_filter = NULL;
419         int ret = 0;
420
421         wl1271_debug(DEBUG_ACX, "acx beacon filter opt");
422
423         if (enable_filter &&
424             wl->conf.conn.bcn_filt_mode == CONF_BCN_FILT_MODE_DISABLED)
425                 goto out;
426
427         beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL);
428         if (!beacon_filter) {
429                 ret = -ENOMEM;
430                 goto out;
431         }
432
433         beacon_filter->enable = enable_filter;
434
435         /*
436          * When set to zero, and the filter is enabled, beacons
437          * without the unicast TIM bit set are dropped.
438          */
439         beacon_filter->max_num_beacons = 0;
440
441         ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_OPT,
442                                    beacon_filter, sizeof(*beacon_filter));
443         if (ret < 0) {
444                 wl1271_warning("failed to set beacon filter opt: %d", ret);
445                 goto out;
446         }
447
448 out:
449         kfree(beacon_filter);
450         return ret;
451 }
452
453 int wl1271_acx_beacon_filter_table(struct wl1271 *wl)
454 {
455         struct acx_beacon_filter_ie_table *ie_table;
456         int i, idx = 0;
457         int ret;
458         bool vendor_spec = false;
459
460         wl1271_debug(DEBUG_ACX, "acx beacon filter table");
461
462         ie_table = kzalloc(sizeof(*ie_table), GFP_KERNEL);
463         if (!ie_table) {
464                 ret = -ENOMEM;
465                 goto out;
466         }
467
468         /* configure default beacon pass-through rules */
469         ie_table->num_ie = 0;
470         for (i = 0; i < wl->conf.conn.bcn_filt_ie_count; i++) {
471                 struct conf_bcn_filt_rule *r = &(wl->conf.conn.bcn_filt_ie[i]);
472                 ie_table->table[idx++] = r->ie;
473                 ie_table->table[idx++] = r->rule;
474
475                 if (r->ie == WLAN_EID_VENDOR_SPECIFIC) {
476                         /* only one vendor specific ie allowed */
477                         if (vendor_spec)
478                                 continue;
479
480                         /* for vendor specific rules configure the
481                            additional fields */
482                         memcpy(&(ie_table->table[idx]), r->oui,
483                                CONF_BCN_IE_OUI_LEN);
484                         idx += CONF_BCN_IE_OUI_LEN;
485                         ie_table->table[idx++] = r->type;
486                         memcpy(&(ie_table->table[idx]), r->version,
487                                CONF_BCN_IE_VER_LEN);
488                         idx += CONF_BCN_IE_VER_LEN;
489                         vendor_spec = true;
490                 }
491
492                 ie_table->num_ie++;
493         }
494
495         ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_TABLE,
496                                    ie_table, sizeof(*ie_table));
497         if (ret < 0) {
498                 wl1271_warning("failed to set beacon filter table: %d", ret);
499                 goto out;
500         }
501
502 out:
503         kfree(ie_table);
504         return ret;
505 }
506
507 #define ACX_CONN_MONIT_DISABLE_VALUE  0xffffffff
508
509 int wl1271_acx_conn_monit_params(struct wl1271 *wl, bool enable)
510 {
511         struct acx_conn_monit_params *acx;
512         u32 threshold = ACX_CONN_MONIT_DISABLE_VALUE;
513         u32 timeout = ACX_CONN_MONIT_DISABLE_VALUE;
514         int ret;
515
516         wl1271_debug(DEBUG_ACX, "acx connection monitor parameters: %s",
517                      enable ? "enabled" : "disabled");
518
519         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
520         if (!acx) {
521                 ret = -ENOMEM;
522                 goto out;
523         }
524
525         if (enable) {
526                 threshold = wl->conf.conn.synch_fail_thold;
527                 timeout = wl->conf.conn.bss_lose_timeout;
528         }
529
530         acx->synch_fail_thold = cpu_to_le32(threshold);
531         acx->bss_lose_timeout = cpu_to_le32(timeout);
532
533         ret = wl1271_cmd_configure(wl, ACX_CONN_MONIT_PARAMS,
534                                    acx, sizeof(*acx));
535         if (ret < 0) {
536                 wl1271_warning("failed to set connection monitor "
537                                "parameters: %d", ret);
538                 goto out;
539         }
540
541 out:
542         kfree(acx);
543         return ret;
544 }
545
546
547 int wl1271_acx_sg_enable(struct wl1271 *wl, bool enable)
548 {
549         struct acx_bt_wlan_coex *pta;
550         int ret;
551
552         wl1271_debug(DEBUG_ACX, "acx sg enable");
553
554         pta = kzalloc(sizeof(*pta), GFP_KERNEL);
555         if (!pta) {
556                 ret = -ENOMEM;
557                 goto out;
558         }
559
560         if (enable)
561                 pta->enable = wl->conf.sg.state;
562         else
563                 pta->enable = CONF_SG_DISABLE;
564
565         ret = wl1271_cmd_configure(wl, ACX_SG_ENABLE, pta, sizeof(*pta));
566         if (ret < 0) {
567                 wl1271_warning("failed to set softgemini enable: %d", ret);
568                 goto out;
569         }
570
571 out:
572         kfree(pta);
573         return ret;
574 }
575
576 int wl1271_acx_sg_cfg(struct wl1271 *wl)
577 {
578         struct acx_bt_wlan_coex_param *param;
579         struct conf_sg_settings *c = &wl->conf.sg;
580         int i, ret;
581
582         wl1271_debug(DEBUG_ACX, "acx sg cfg");
583
584         param = kzalloc(sizeof(*param), GFP_KERNEL);
585         if (!param) {
586                 ret = -ENOMEM;
587                 goto out;
588         }
589
590         /* BT-WLAN coext parameters */
591         for (i = 0; i < CONF_SG_PARAMS_MAX; i++)
592                 param->params[i] = cpu_to_le32(c->params[i]);
593         param->param_idx = CONF_SG_PARAMS_ALL;
594
595         ret = wl1271_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param));
596         if (ret < 0) {
597                 wl1271_warning("failed to set sg config: %d", ret);
598                 goto out;
599         }
600
601 out:
602         kfree(param);
603         return ret;
604 }
605
606 int wl1271_acx_cca_threshold(struct wl1271 *wl)
607 {
608         struct acx_energy_detection *detection;
609         int ret;
610
611         wl1271_debug(DEBUG_ACX, "acx cca threshold");
612
613         detection = kzalloc(sizeof(*detection), GFP_KERNEL);
614         if (!detection) {
615                 ret = -ENOMEM;
616                 goto out;
617         }
618
619         detection->rx_cca_threshold = cpu_to_le16(wl->conf.rx.rx_cca_threshold);
620         detection->tx_energy_detection = wl->conf.tx.tx_energy_detection;
621
622         ret = wl1271_cmd_configure(wl, ACX_CCA_THRESHOLD,
623                                    detection, sizeof(*detection));
624         if (ret < 0) {
625                 wl1271_warning("failed to set cca threshold: %d", ret);
626                 return ret;
627         }
628
629 out:
630         kfree(detection);
631         return ret;
632 }
633
634 int wl1271_acx_bcn_dtim_options(struct wl1271 *wl)
635 {
636         struct acx_beacon_broadcast *bb;
637         int ret;
638
639         wl1271_debug(DEBUG_ACX, "acx bcn dtim options");
640
641         bb = kzalloc(sizeof(*bb), GFP_KERNEL);
642         if (!bb) {
643                 ret = -ENOMEM;
644                 goto out;
645         }
646
647         bb->beacon_rx_timeout = cpu_to_le16(wl->conf.conn.beacon_rx_timeout);
648         bb->broadcast_timeout = cpu_to_le16(wl->conf.conn.broadcast_timeout);
649         bb->rx_broadcast_in_ps = wl->conf.conn.rx_broadcast_in_ps;
650         bb->ps_poll_threshold = wl->conf.conn.ps_poll_threshold;
651
652         ret = wl1271_cmd_configure(wl, ACX_BCN_DTIM_OPTIONS, bb, sizeof(*bb));
653         if (ret < 0) {
654                 wl1271_warning("failed to set rx config: %d", ret);
655                 goto out;
656         }
657
658 out:
659         kfree(bb);
660         return ret;
661 }
662
663 int wl1271_acx_aid(struct wl1271 *wl, u16 aid)
664 {
665         struct acx_aid *acx_aid;
666         int ret;
667
668         wl1271_debug(DEBUG_ACX, "acx aid");
669
670         acx_aid = kzalloc(sizeof(*acx_aid), GFP_KERNEL);
671         if (!acx_aid) {
672                 ret = -ENOMEM;
673                 goto out;
674         }
675
676         acx_aid->aid = cpu_to_le16(aid);
677
678         ret = wl1271_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid));
679         if (ret < 0) {
680                 wl1271_warning("failed to set aid: %d", ret);
681                 goto out;
682         }
683
684 out:
685         kfree(acx_aid);
686         return ret;
687 }
688
689 int wl1271_acx_event_mbox_mask(struct wl1271 *wl, u32 event_mask)
690 {
691         struct acx_event_mask *mask;
692         int ret;
693
694         wl1271_debug(DEBUG_ACX, "acx event mbox mask");
695
696         mask = kzalloc(sizeof(*mask), GFP_KERNEL);
697         if (!mask) {
698                 ret = -ENOMEM;
699                 goto out;
700         }
701
702         /* high event mask is unused */
703         mask->high_event_mask = cpu_to_le32(0xffffffff);
704         mask->event_mask = cpu_to_le32(event_mask);
705
706         ret = wl1271_cmd_configure(wl, ACX_EVENT_MBOX_MASK,
707                                    mask, sizeof(*mask));
708         if (ret < 0) {
709                 wl1271_warning("failed to set acx_event_mbox_mask: %d", ret);
710                 goto out;
711         }
712
713 out:
714         kfree(mask);
715         return ret;
716 }
717
718 int wl1271_acx_set_preamble(struct wl1271 *wl, enum acx_preamble_type preamble)
719 {
720         struct acx_preamble *acx;
721         int ret;
722
723         wl1271_debug(DEBUG_ACX, "acx_set_preamble");
724
725         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
726         if (!acx) {
727                 ret = -ENOMEM;
728                 goto out;
729         }
730
731         acx->preamble = preamble;
732
733         ret = wl1271_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx));
734         if (ret < 0) {
735                 wl1271_warning("Setting of preamble failed: %d", ret);
736                 goto out;
737         }
738
739 out:
740         kfree(acx);
741         return ret;
742 }
743
744 int wl1271_acx_cts_protect(struct wl1271 *wl,
745                            enum acx_ctsprotect_type ctsprotect)
746 {
747         struct acx_ctsprotect *acx;
748         int ret;
749
750         wl1271_debug(DEBUG_ACX, "acx_set_ctsprotect");
751
752         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
753         if (!acx) {
754                 ret = -ENOMEM;
755                 goto out;
756         }
757
758         acx->ctsprotect = ctsprotect;
759
760         ret = wl1271_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx));
761         if (ret < 0) {
762                 wl1271_warning("Setting of ctsprotect failed: %d", ret);
763                 goto out;
764         }
765
766 out:
767         kfree(acx);
768         return ret;
769 }
770
771 int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats)
772 {
773         int ret;
774
775         wl1271_debug(DEBUG_ACX, "acx statistics");
776
777         ret = wl1271_cmd_interrogate(wl, ACX_STATISTICS, stats,
778                                      sizeof(*stats));
779         if (ret < 0) {
780                 wl1271_warning("acx statistics failed: %d", ret);
781                 return -ENOMEM;
782         }
783
784         return 0;
785 }
786
787 int wl1271_acx_rate_policies(struct wl1271 *wl)
788 {
789         struct acx_rate_policy *acx;
790         struct conf_tx_rate_class *c = &wl->conf.tx.rc_conf;
791         int idx = 0;
792         int ret = 0;
793
794         wl1271_debug(DEBUG_ACX, "acx rate policies");
795
796         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
797
798         if (!acx) {
799                 ret = -ENOMEM;
800                 goto out;
801         }
802
803         /* configure one basic rate class */
804         idx = ACX_TX_BASIC_RATE;
805         acx->rate_class[idx].enabled_rates = cpu_to_le32(wl->basic_rate);
806         acx->rate_class[idx].short_retry_limit = c->short_retry_limit;
807         acx->rate_class[idx].long_retry_limit = c->long_retry_limit;
808         acx->rate_class[idx].aflags = c->aflags;
809
810         /* configure one AP supported rate class */
811         idx = ACX_TX_AP_FULL_RATE;
812         acx->rate_class[idx].enabled_rates = cpu_to_le32(wl->rate_set);
813         acx->rate_class[idx].short_retry_limit = c->short_retry_limit;
814         acx->rate_class[idx].long_retry_limit = c->long_retry_limit;
815         acx->rate_class[idx].aflags = c->aflags;
816
817         acx->rate_class_cnt = cpu_to_le32(ACX_TX_RATE_POLICY_CNT);
818
819         ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
820         if (ret < 0) {
821                 wl1271_warning("Setting of rate policies failed: %d", ret);
822                 goto out;
823         }
824
825 out:
826         kfree(acx);
827         return ret;
828 }
829
830 int wl1271_acx_ac_cfg(struct wl1271 *wl, u8 ac, u8 cw_min, u16 cw_max,
831                       u8 aifsn, u16 txop)
832 {
833         struct acx_ac_cfg *acx;
834         int ret = 0;
835
836         wl1271_debug(DEBUG_ACX, "acx ac cfg %d cw_ming %d cw_max %d "
837                      "aifs %d txop %d", ac, cw_min, cw_max, aifsn, txop);
838
839         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
840
841         if (!acx) {
842                 ret = -ENOMEM;
843                 goto out;
844         }
845
846         acx->ac = ac;
847         acx->cw_min = cw_min;
848         acx->cw_max = cpu_to_le16(cw_max);
849         acx->aifsn = aifsn;
850         acx->tx_op_limit = cpu_to_le16(txop);
851
852         ret = wl1271_cmd_configure(wl, ACX_AC_CFG, acx, sizeof(*acx));
853         if (ret < 0) {
854                 wl1271_warning("acx ac cfg failed: %d", ret);
855                 goto out;
856         }
857
858 out:
859         kfree(acx);
860         return ret;
861 }
862
863 int wl1271_acx_tid_cfg(struct wl1271 *wl, u8 queue_id, u8 channel_type,
864                        u8 tsid, u8 ps_scheme, u8 ack_policy,
865                        u32 apsd_conf0, u32 apsd_conf1)
866 {
867         struct acx_tid_config *acx;
868         int ret = 0;
869
870         wl1271_debug(DEBUG_ACX, "acx tid config");
871
872         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
873
874         if (!acx) {
875                 ret = -ENOMEM;
876                 goto out;
877         }
878
879         acx->queue_id = queue_id;
880         acx->channel_type = channel_type;
881         acx->tsid = tsid;
882         acx->ps_scheme = ps_scheme;
883         acx->ack_policy = ack_policy;
884         acx->apsd_conf[0] = cpu_to_le32(apsd_conf0);
885         acx->apsd_conf[1] = cpu_to_le32(apsd_conf1);
886
887         ret = wl1271_cmd_configure(wl, ACX_TID_CFG, acx, sizeof(*acx));
888         if (ret < 0) {
889                 wl1271_warning("Setting of tid config failed: %d", ret);
890                 goto out;
891         }
892
893 out:
894         kfree(acx);
895         return ret;
896 }
897
898 int wl1271_acx_frag_threshold(struct wl1271 *wl)
899 {
900         struct acx_frag_threshold *acx;
901         int ret = 0;
902
903         wl1271_debug(DEBUG_ACX, "acx frag threshold");
904
905         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
906
907         if (!acx) {
908                 ret = -ENOMEM;
909                 goto out;
910         }
911
912         acx->frag_threshold = cpu_to_le16(wl->conf.tx.frag_threshold);
913         ret = wl1271_cmd_configure(wl, ACX_FRAG_CFG, acx, sizeof(*acx));
914         if (ret < 0) {
915                 wl1271_warning("Setting of frag threshold failed: %d", ret);
916                 goto out;
917         }
918
919 out:
920         kfree(acx);
921         return ret;
922 }
923
924 int wl1271_acx_tx_config_options(struct wl1271 *wl)
925 {
926         struct acx_tx_config_options *acx;
927         int ret = 0;
928
929         wl1271_debug(DEBUG_ACX, "acx tx config options");
930
931         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
932
933         if (!acx) {
934                 ret = -ENOMEM;
935                 goto out;
936         }
937
938         acx->tx_compl_timeout = cpu_to_le16(wl->conf.tx.tx_compl_timeout);
939         acx->tx_compl_threshold = cpu_to_le16(wl->conf.tx.tx_compl_threshold);
940         ret = wl1271_cmd_configure(wl, ACX_TX_CONFIG_OPT, acx, sizeof(*acx));
941         if (ret < 0) {
942                 wl1271_warning("Setting of tx options failed: %d", ret);
943                 goto out;
944         }
945
946 out:
947         kfree(acx);
948         return ret;
949 }
950
951 int wl1271_acx_mem_cfg(struct wl1271 *wl)
952 {
953         struct wl1271_acx_config_memory *mem_conf;
954         int ret;
955
956         wl1271_debug(DEBUG_ACX, "wl1271 mem cfg");
957
958         mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL);
959         if (!mem_conf) {
960                 ret = -ENOMEM;
961                 goto out;
962         }
963
964         /* memory config */
965         mem_conf->num_stations = DEFAULT_NUM_STATIONS;
966         mem_conf->rx_mem_block_num = ACX_RX_MEM_BLOCKS;
967         mem_conf->tx_min_mem_block_num = ACX_TX_MIN_MEM_BLOCKS;
968         mem_conf->num_ssid_profiles = ACX_NUM_SSID_PROFILES;
969         mem_conf->total_tx_descriptors = cpu_to_le32(ACX_TX_DESCRIPTORS);
970
971         ret = wl1271_cmd_configure(wl, ACX_MEM_CFG, mem_conf,
972                                    sizeof(*mem_conf));
973         if (ret < 0) {
974                 wl1271_warning("wl1271 mem config failed: %d", ret);
975                 goto out;
976         }
977
978 out:
979         kfree(mem_conf);
980         return ret;
981 }
982
983 int wl1271_acx_init_mem_config(struct wl1271 *wl)
984 {
985         int ret;
986
987         ret = wl1271_acx_mem_cfg(wl);
988         if (ret < 0)
989                 return ret;
990
991         wl->target_mem_map = kzalloc(sizeof(struct wl1271_acx_mem_map),
992                                      GFP_KERNEL);
993         if (!wl->target_mem_map) {
994                 wl1271_error("couldn't allocate target memory map");
995                 return -ENOMEM;
996         }
997
998         /* we now ask for the firmware built memory map */
999         ret = wl1271_acx_mem_map(wl, (void *)wl->target_mem_map,
1000                                  sizeof(struct wl1271_acx_mem_map));
1001         if (ret < 0) {
1002                 wl1271_error("couldn't retrieve firmware memory map");
1003                 kfree(wl->target_mem_map);
1004                 wl->target_mem_map = NULL;
1005                 return ret;
1006         }
1007
1008         /* initialize TX block book keeping */
1009         wl->tx_blocks_available =
1010                 le32_to_cpu(wl->target_mem_map->num_tx_mem_blocks);
1011         wl1271_debug(DEBUG_TX, "available tx blocks: %d",
1012                      wl->tx_blocks_available);
1013
1014         return 0;
1015 }
1016
1017 int wl1271_acx_init_rx_interrupt(struct wl1271 *wl)
1018 {
1019         struct wl1271_acx_rx_config_opt *rx_conf;
1020         int ret;
1021
1022         wl1271_debug(DEBUG_ACX, "wl1271 rx interrupt config");
1023
1024         rx_conf = kzalloc(sizeof(*rx_conf), GFP_KERNEL);
1025         if (!rx_conf) {
1026                 ret = -ENOMEM;
1027                 goto out;
1028         }
1029
1030         rx_conf->threshold = cpu_to_le16(wl->conf.rx.irq_pkt_threshold);
1031         rx_conf->timeout = cpu_to_le16(wl->conf.rx.irq_timeout);
1032         rx_conf->mblk_threshold = cpu_to_le16(wl->conf.rx.irq_blk_threshold);
1033         rx_conf->queue_type = wl->conf.rx.queue_type;
1034
1035         ret = wl1271_cmd_configure(wl, ACX_RX_CONFIG_OPT, rx_conf,
1036                                    sizeof(*rx_conf));
1037         if (ret < 0) {
1038                 wl1271_warning("wl1271 rx config opt failed: %d", ret);
1039                 goto out;
1040         }
1041
1042 out:
1043         kfree(rx_conf);
1044         return ret;
1045 }
1046
1047 int wl1271_acx_bet_enable(struct wl1271 *wl, bool enable)
1048 {
1049         struct wl1271_acx_bet_enable *acx = NULL;
1050         int ret = 0;
1051
1052         wl1271_debug(DEBUG_ACX, "acx bet enable");
1053
1054         if (enable && wl->conf.conn.bet_enable == CONF_BET_MODE_DISABLE)
1055                 goto out;
1056
1057         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1058         if (!acx) {
1059                 ret = -ENOMEM;
1060                 goto out;
1061         }
1062
1063         acx->enable = enable ? CONF_BET_MODE_ENABLE : CONF_BET_MODE_DISABLE;
1064         acx->max_consecutive = wl->conf.conn.bet_max_consecutive;
1065
1066         ret = wl1271_cmd_configure(wl, ACX_BET_ENABLE, acx, sizeof(*acx));
1067         if (ret < 0) {
1068                 wl1271_warning("acx bet enable failed: %d", ret);
1069                 goto out;
1070         }
1071
1072 out:
1073         kfree(acx);
1074         return ret;
1075 }
1076
1077 int wl1271_acx_arp_ip_filter(struct wl1271 *wl, bool enable, u8 *address,
1078                              u8 version)
1079 {
1080         struct wl1271_acx_arp_filter *acx;
1081         int ret;
1082
1083         wl1271_debug(DEBUG_ACX, "acx arp ip filter, enable: %d", enable);
1084
1085         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1086         if (!acx) {
1087                 ret = -ENOMEM;
1088                 goto out;
1089         }
1090
1091         acx->version = version;
1092         acx->enable = enable;
1093
1094         if (enable == true) {
1095                 if (version == ACX_IPV4_VERSION)
1096                         memcpy(acx->address, address, ACX_IPV4_ADDR_SIZE);
1097                 else if (version == ACX_IPV6_VERSION)
1098                         memcpy(acx->address, address, sizeof(acx->address));
1099                 else
1100                         wl1271_error("Invalid IP version");
1101         }
1102
1103         ret = wl1271_cmd_configure(wl, ACX_ARP_IP_FILTER,
1104                                    acx, sizeof(*acx));
1105         if (ret < 0) {
1106                 wl1271_warning("failed to set arp ip filter: %d", ret);
1107                 goto out;
1108         }
1109
1110 out:
1111         kfree(acx);
1112         return ret;
1113 }
1114
1115 int wl1271_acx_pm_config(struct wl1271 *wl)
1116 {
1117         struct wl1271_acx_pm_config *acx = NULL;
1118         struct  conf_pm_config_settings *c = &wl->conf.pm_config;
1119         int ret = 0;
1120
1121         wl1271_debug(DEBUG_ACX, "acx pm config");
1122
1123         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1124         if (!acx) {
1125                 ret = -ENOMEM;
1126                 goto out;
1127         }
1128
1129         acx->host_clk_settling_time = cpu_to_le32(c->host_clk_settling_time);
1130         acx->host_fast_wakeup_support = c->host_fast_wakeup_support;
1131
1132         ret = wl1271_cmd_configure(wl, ACX_PM_CONFIG, acx, sizeof(*acx));
1133         if (ret < 0) {
1134                 wl1271_warning("acx pm config failed: %d", ret);
1135                 goto out;
1136         }
1137
1138 out:
1139         kfree(acx);
1140         return ret;
1141 }
1142
1143 int wl1271_acx_keep_alive_mode(struct wl1271 *wl, bool enable)
1144 {
1145         struct wl1271_acx_keep_alive_mode *acx = NULL;
1146         int ret = 0;
1147
1148         wl1271_debug(DEBUG_ACX, "acx keep alive mode: %d", enable);
1149
1150         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1151         if (!acx) {
1152                 ret = -ENOMEM;
1153                 goto out;
1154         }
1155
1156         acx->enabled = enable;
1157
1158         ret = wl1271_cmd_configure(wl, ACX_KEEP_ALIVE_MODE, acx, sizeof(*acx));
1159         if (ret < 0) {
1160                 wl1271_warning("acx keep alive mode failed: %d", ret);
1161                 goto out;
1162         }
1163
1164 out:
1165         kfree(acx);
1166         return ret;
1167 }
1168
1169 int wl1271_acx_keep_alive_config(struct wl1271 *wl, u8 index, u8 tpl_valid)
1170 {
1171         struct wl1271_acx_keep_alive_config *acx = NULL;
1172         int ret = 0;
1173
1174         wl1271_debug(DEBUG_ACX, "acx keep alive config");
1175
1176         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1177         if (!acx) {
1178                 ret = -ENOMEM;
1179                 goto out;
1180         }
1181
1182         acx->period = cpu_to_le32(wl->conf.conn.keep_alive_interval);
1183         acx->index = index;
1184         acx->tpl_validation = tpl_valid;
1185         acx->trigger = ACX_KEEP_ALIVE_NO_TX;
1186
1187         ret = wl1271_cmd_configure(wl, ACX_SET_KEEP_ALIVE_CONFIG,
1188                                    acx, sizeof(*acx));
1189         if (ret < 0) {
1190                 wl1271_warning("acx keep alive config failed: %d", ret);
1191                 goto out;
1192         }
1193
1194 out:
1195         kfree(acx);
1196         return ret;
1197 }
1198
1199 int wl1271_acx_rssi_snr_trigger(struct wl1271 *wl, bool enable,
1200                                 s16 thold, u8 hyst)
1201 {
1202         struct wl1271_acx_rssi_snr_trigger *acx = NULL;
1203         int ret = 0;
1204
1205         wl1271_debug(DEBUG_ACX, "acx rssi snr trigger");
1206
1207         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1208         if (!acx) {
1209                 ret = -ENOMEM;
1210                 goto out;
1211         }
1212
1213         wl->last_rssi_event = -1;
1214
1215         acx->pacing = cpu_to_le16(wl->conf.roam_trigger.trigger_pacing);
1216         acx->metric = WL1271_ACX_TRIG_METRIC_RSSI_BEACON;
1217         acx->type = WL1271_ACX_TRIG_TYPE_EDGE;
1218         if (enable)
1219                 acx->enable = WL1271_ACX_TRIG_ENABLE;
1220         else
1221                 acx->enable = WL1271_ACX_TRIG_DISABLE;
1222
1223         acx->index = WL1271_ACX_TRIG_IDX_RSSI;
1224         acx->dir = WL1271_ACX_TRIG_DIR_BIDIR;
1225         acx->threshold = cpu_to_le16(thold);
1226         acx->hysteresis = hyst;
1227
1228         ret = wl1271_cmd_configure(wl, ACX_RSSI_SNR_TRIGGER, acx, sizeof(*acx));
1229         if (ret < 0) {
1230                 wl1271_warning("acx rssi snr trigger setting failed: %d", ret);
1231                 goto out;
1232         }
1233
1234 out:
1235         kfree(acx);
1236         return ret;
1237 }
1238
1239 int wl1271_acx_rssi_snr_avg_weights(struct wl1271 *wl)
1240 {
1241         struct wl1271_acx_rssi_snr_avg_weights *acx = NULL;
1242         struct conf_roam_trigger_settings *c = &wl->conf.roam_trigger;
1243         int ret = 0;
1244
1245         wl1271_debug(DEBUG_ACX, "acx rssi snr avg weights");
1246
1247         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1248         if (!acx) {
1249                 ret = -ENOMEM;
1250                 goto out;
1251         }
1252
1253         acx->rssi_beacon = c->avg_weight_rssi_beacon;
1254         acx->rssi_data = c->avg_weight_rssi_data;
1255         acx->snr_beacon = c->avg_weight_snr_beacon;
1256         acx->snr_data = c->avg_weight_snr_data;
1257
1258         ret = wl1271_cmd_configure(wl, ACX_RSSI_SNR_WEIGHTS, acx, sizeof(*acx));
1259         if (ret < 0) {
1260                 wl1271_warning("acx rssi snr trigger weights failed: %d", ret);
1261                 goto out;
1262         }
1263
1264 out:
1265         kfree(acx);
1266         return ret;
1267 }