Merge git://github.com/Jkirsher/net-next
[pandora-kernel.git] / drivers / net / wireless / wl12xx / 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 "acx.h"
25
26 #include <linux/module.h>
27 #include <linux/platform_device.h>
28 #include <linux/spi/spi.h>
29 #include <linux/slab.h>
30
31 #include "wl12xx.h"
32 #include "wl12xx_80211.h"
33 #include "reg.h"
34 #include "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->role_id = wl->role_id;
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_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 %d", power);
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
105         acx->role_id = wl->role_id;
106         acx->current_tx_power = power * 10;
107
108         ret = wl1271_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx));
109         if (ret < 0) {
110                 wl1271_warning("configure of tx power failed: %d", ret);
111                 goto out;
112         }
113
114 out:
115         kfree(acx);
116         return ret;
117 }
118
119 int wl1271_acx_feature_cfg(struct wl1271 *wl)
120 {
121         struct acx_feature_config *feature;
122         int ret;
123
124         wl1271_debug(DEBUG_ACX, "acx feature cfg");
125
126         feature = kzalloc(sizeof(*feature), GFP_KERNEL);
127         if (!feature) {
128                 ret = -ENOMEM;
129                 goto out;
130         }
131
132         /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */
133         feature->role_id = wl->role_id;
134         feature->data_flow_options = 0;
135         feature->options = 0;
136
137         ret = wl1271_cmd_configure(wl, ACX_FEATURE_CFG,
138                                    feature, sizeof(*feature));
139         if (ret < 0) {
140                 wl1271_error("Couldnt set HW encryption");
141                 goto out;
142         }
143
144 out:
145         kfree(feature);
146         return ret;
147 }
148
149 int wl1271_acx_mem_map(struct wl1271 *wl, struct acx_header *mem_map,
150                        size_t len)
151 {
152         int ret;
153
154         wl1271_debug(DEBUG_ACX, "acx mem map");
155
156         ret = wl1271_cmd_interrogate(wl, ACX_MEM_MAP, mem_map, len);
157         if (ret < 0)
158                 return ret;
159
160         return 0;
161 }
162
163 int wl1271_acx_rx_msdu_life_time(struct wl1271 *wl)
164 {
165         struct acx_rx_msdu_lifetime *acx;
166         int ret;
167
168         wl1271_debug(DEBUG_ACX, "acx rx msdu life time");
169
170         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
171         if (!acx) {
172                 ret = -ENOMEM;
173                 goto out;
174         }
175
176         acx->lifetime = cpu_to_le32(wl->conf.rx.rx_msdu_life_time);
177         ret = wl1271_cmd_configure(wl, DOT11_RX_MSDU_LIFE_TIME,
178                                    acx, sizeof(*acx));
179         if (ret < 0) {
180                 wl1271_warning("failed to set rx msdu life time: %d", ret);
181                 goto out;
182         }
183
184 out:
185         kfree(acx);
186         return ret;
187 }
188
189 int wl1271_acx_pd_threshold(struct wl1271 *wl)
190 {
191         struct acx_packet_detection *pd;
192         int ret;
193
194         wl1271_debug(DEBUG_ACX, "acx data pd threshold");
195
196         pd = kzalloc(sizeof(*pd), GFP_KERNEL);
197         if (!pd) {
198                 ret = -ENOMEM;
199                 goto out;
200         }
201
202         pd->threshold = cpu_to_le32(wl->conf.rx.packet_detection_threshold);
203
204         ret = wl1271_cmd_configure(wl, ACX_PD_THRESHOLD, pd, sizeof(*pd));
205         if (ret < 0) {
206                 wl1271_warning("failed to set pd threshold: %d", ret);
207                 goto out;
208         }
209
210 out:
211         kfree(pd);
212         return ret;
213 }
214
215 int wl1271_acx_slot(struct wl1271 *wl, enum acx_slot_type slot_time)
216 {
217         struct acx_slot *slot;
218         int ret;
219
220         wl1271_debug(DEBUG_ACX, "acx slot");
221
222         slot = kzalloc(sizeof(*slot), GFP_KERNEL);
223         if (!slot) {
224                 ret = -ENOMEM;
225                 goto out;
226         }
227
228         slot->role_id = wl->role_id;
229         slot->wone_index = STATION_WONE_INDEX;
230         slot->slot_time = slot_time;
231
232         ret = wl1271_cmd_configure(wl, ACX_SLOT, slot, sizeof(*slot));
233         if (ret < 0) {
234                 wl1271_warning("failed to set slot time: %d", ret);
235                 goto out;
236         }
237
238 out:
239         kfree(slot);
240         return ret;
241 }
242
243 int wl1271_acx_group_address_tbl(struct wl1271 *wl, bool enable,
244                                  void *mc_list, u32 mc_list_len)
245 {
246         struct acx_dot11_grp_addr_tbl *acx;
247         int ret;
248
249         wl1271_debug(DEBUG_ACX, "acx group address tbl");
250
251         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
252         if (!acx) {
253                 ret = -ENOMEM;
254                 goto out;
255         }
256
257         /* MAC filtering */
258         acx->role_id = wl->role_id;
259         acx->enabled = enable;
260         acx->num_groups = mc_list_len;
261         memcpy(acx->mac_table, mc_list, mc_list_len * ETH_ALEN);
262
263         ret = wl1271_cmd_configure(wl, DOT11_GROUP_ADDRESS_TBL,
264                                    acx, sizeof(*acx));
265         if (ret < 0) {
266                 wl1271_warning("failed to set group addr table: %d", ret);
267                 goto out;
268         }
269
270 out:
271         kfree(acx);
272         return ret;
273 }
274
275 int wl1271_acx_service_period_timeout(struct wl1271 *wl)
276 {
277         struct acx_rx_timeout *rx_timeout;
278         int ret;
279
280         rx_timeout = kzalloc(sizeof(*rx_timeout), GFP_KERNEL);
281         if (!rx_timeout) {
282                 ret = -ENOMEM;
283                 goto out;
284         }
285
286         wl1271_debug(DEBUG_ACX, "acx service period timeout");
287
288         rx_timeout->role_id = wl->role_id;
289         rx_timeout->ps_poll_timeout = cpu_to_le16(wl->conf.rx.ps_poll_timeout);
290         rx_timeout->upsd_timeout = cpu_to_le16(wl->conf.rx.upsd_timeout);
291
292         ret = wl1271_cmd_configure(wl, ACX_SERVICE_PERIOD_TIMEOUT,
293                                    rx_timeout, sizeof(*rx_timeout));
294         if (ret < 0) {
295                 wl1271_warning("failed to set service period timeout: %d",
296                                ret);
297                 goto out;
298         }
299
300 out:
301         kfree(rx_timeout);
302         return ret;
303 }
304
305 int wl1271_acx_rts_threshold(struct wl1271 *wl, u32 rts_threshold)
306 {
307         struct acx_rts_threshold *rts;
308         int ret;
309
310         /*
311          * If the RTS threshold is not configured or out of range, use the
312          * default value.
313          */
314         if (rts_threshold > IEEE80211_MAX_RTS_THRESHOLD)
315                 rts_threshold = wl->conf.rx.rts_threshold;
316
317         wl1271_debug(DEBUG_ACX, "acx rts threshold: %d", rts_threshold);
318
319         rts = kzalloc(sizeof(*rts), GFP_KERNEL);
320         if (!rts) {
321                 ret = -ENOMEM;
322                 goto out;
323         }
324
325         rts->role_id = wl->role_id;
326         rts->threshold = cpu_to_le16((u16)rts_threshold);
327
328         ret = wl1271_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts));
329         if (ret < 0) {
330                 wl1271_warning("failed to set rts threshold: %d", ret);
331                 goto out;
332         }
333
334 out:
335         kfree(rts);
336         return ret;
337 }
338
339 int wl1271_acx_dco_itrim_params(struct wl1271 *wl)
340 {
341         struct acx_dco_itrim_params *dco;
342         struct conf_itrim_settings *c = &wl->conf.itrim;
343         int ret;
344
345         wl1271_debug(DEBUG_ACX, "acx dco itrim parameters");
346
347         dco = kzalloc(sizeof(*dco), GFP_KERNEL);
348         if (!dco) {
349                 ret = -ENOMEM;
350                 goto out;
351         }
352
353         dco->enable = c->enable;
354         dco->timeout = cpu_to_le32(c->timeout);
355
356         ret = wl1271_cmd_configure(wl, ACX_SET_DCO_ITRIM_PARAMS,
357                                    dco, sizeof(*dco));
358         if (ret < 0) {
359                 wl1271_warning("failed to set dco itrim parameters: %d", ret);
360                 goto out;
361         }
362
363 out:
364         kfree(dco);
365         return ret;
366 }
367
368 int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, bool enable_filter)
369 {
370         struct acx_beacon_filter_option *beacon_filter = NULL;
371         int ret = 0;
372
373         wl1271_debug(DEBUG_ACX, "acx beacon filter opt");
374
375         if (enable_filter &&
376             wl->conf.conn.bcn_filt_mode == CONF_BCN_FILT_MODE_DISABLED)
377                 goto out;
378
379         beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL);
380         if (!beacon_filter) {
381                 ret = -ENOMEM;
382                 goto out;
383         }
384
385         beacon_filter->role_id = wl->role_id;
386         beacon_filter->enable = enable_filter;
387
388         /*
389          * When set to zero, and the filter is enabled, beacons
390          * without the unicast TIM bit set are dropped.
391          */
392         beacon_filter->max_num_beacons = 0;
393
394         ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_OPT,
395                                    beacon_filter, sizeof(*beacon_filter));
396         if (ret < 0) {
397                 wl1271_warning("failed to set beacon filter opt: %d", ret);
398                 goto out;
399         }
400
401 out:
402         kfree(beacon_filter);
403         return ret;
404 }
405
406 int wl1271_acx_beacon_filter_table(struct wl1271 *wl)
407 {
408         struct acx_beacon_filter_ie_table *ie_table;
409         int i, idx = 0;
410         int ret;
411         bool vendor_spec = false;
412
413         wl1271_debug(DEBUG_ACX, "acx beacon filter table");
414
415         ie_table = kzalloc(sizeof(*ie_table), GFP_KERNEL);
416         if (!ie_table) {
417                 ret = -ENOMEM;
418                 goto out;
419         }
420
421         /* configure default beacon pass-through rules */
422         ie_table->role_id = wl->role_id;
423         ie_table->num_ie = 0;
424         for (i = 0; i < wl->conf.conn.bcn_filt_ie_count; i++) {
425                 struct conf_bcn_filt_rule *r = &(wl->conf.conn.bcn_filt_ie[i]);
426                 ie_table->table[idx++] = r->ie;
427                 ie_table->table[idx++] = r->rule;
428
429                 if (r->ie == WLAN_EID_VENDOR_SPECIFIC) {
430                         /* only one vendor specific ie allowed */
431                         if (vendor_spec)
432                                 continue;
433
434                         /* for vendor specific rules configure the
435                            additional fields */
436                         memcpy(&(ie_table->table[idx]), r->oui,
437                                CONF_BCN_IE_OUI_LEN);
438                         idx += CONF_BCN_IE_OUI_LEN;
439                         ie_table->table[idx++] = r->type;
440                         memcpy(&(ie_table->table[idx]), r->version,
441                                CONF_BCN_IE_VER_LEN);
442                         idx += CONF_BCN_IE_VER_LEN;
443                         vendor_spec = true;
444                 }
445
446                 ie_table->num_ie++;
447         }
448
449         ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_TABLE,
450                                    ie_table, sizeof(*ie_table));
451         if (ret < 0) {
452                 wl1271_warning("failed to set beacon filter table: %d", ret);
453                 goto out;
454         }
455
456 out:
457         kfree(ie_table);
458         return ret;
459 }
460
461 #define ACX_CONN_MONIT_DISABLE_VALUE  0xffffffff
462
463 int wl1271_acx_conn_monit_params(struct wl1271 *wl, bool enable)
464 {
465         struct acx_conn_monit_params *acx;
466         u32 threshold = ACX_CONN_MONIT_DISABLE_VALUE;
467         u32 timeout = ACX_CONN_MONIT_DISABLE_VALUE;
468         int ret;
469
470         wl1271_debug(DEBUG_ACX, "acx connection monitor parameters: %s",
471                      enable ? "enabled" : "disabled");
472
473         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
474         if (!acx) {
475                 ret = -ENOMEM;
476                 goto out;
477         }
478
479         if (enable) {
480                 threshold = wl->conf.conn.synch_fail_thold;
481                 timeout = wl->conf.conn.bss_lose_timeout;
482         }
483
484         acx->role_id = wl->role_id;
485         acx->synch_fail_thold = cpu_to_le32(threshold);
486         acx->bss_lose_timeout = cpu_to_le32(timeout);
487
488         ret = wl1271_cmd_configure(wl, ACX_CONN_MONIT_PARAMS,
489                                    acx, sizeof(*acx));
490         if (ret < 0) {
491                 wl1271_warning("failed to set connection monitor "
492                                "parameters: %d", ret);
493                 goto out;
494         }
495
496 out:
497         kfree(acx);
498         return ret;
499 }
500
501
502 int wl1271_acx_sg_enable(struct wl1271 *wl, bool enable)
503 {
504         struct acx_bt_wlan_coex *pta;
505         int ret;
506
507         wl1271_debug(DEBUG_ACX, "acx sg enable");
508
509         pta = kzalloc(sizeof(*pta), GFP_KERNEL);
510         if (!pta) {
511                 ret = -ENOMEM;
512                 goto out;
513         }
514
515         if (enable)
516                 pta->enable = wl->conf.sg.state;
517         else
518                 pta->enable = CONF_SG_DISABLE;
519
520         ret = wl1271_cmd_configure(wl, ACX_SG_ENABLE, pta, sizeof(*pta));
521         if (ret < 0) {
522                 wl1271_warning("failed to set softgemini enable: %d", ret);
523                 goto out;
524         }
525
526 out:
527         kfree(pta);
528         return ret;
529 }
530
531 int wl12xx_acx_sg_cfg(struct wl1271 *wl)
532 {
533         struct acx_bt_wlan_coex_param *param;
534         struct conf_sg_settings *c = &wl->conf.sg;
535         int i, ret;
536
537         wl1271_debug(DEBUG_ACX, "acx sg cfg");
538
539         param = kzalloc(sizeof(*param), GFP_KERNEL);
540         if (!param) {
541                 ret = -ENOMEM;
542                 goto out;
543         }
544
545         /* BT-WLAN coext parameters */
546         for (i = 0; i < CONF_SG_PARAMS_MAX; i++)
547                 param->params[i] = cpu_to_le32(c->params[i]);
548         param->param_idx = CONF_SG_PARAMS_ALL;
549
550         ret = wl1271_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param));
551         if (ret < 0) {
552                 wl1271_warning("failed to set sg config: %d", ret);
553                 goto out;
554         }
555
556 out:
557         kfree(param);
558         return ret;
559 }
560
561 int wl1271_acx_cca_threshold(struct wl1271 *wl)
562 {
563         struct acx_energy_detection *detection;
564         int ret;
565
566         wl1271_debug(DEBUG_ACX, "acx cca threshold");
567
568         detection = kzalloc(sizeof(*detection), GFP_KERNEL);
569         if (!detection) {
570                 ret = -ENOMEM;
571                 goto out;
572         }
573
574         detection->rx_cca_threshold = cpu_to_le16(wl->conf.rx.rx_cca_threshold);
575         detection->tx_energy_detection = wl->conf.tx.tx_energy_detection;
576
577         ret = wl1271_cmd_configure(wl, ACX_CCA_THRESHOLD,
578                                    detection, sizeof(*detection));
579         if (ret < 0) {
580                 wl1271_warning("failed to set cca threshold: %d", ret);
581                 return ret;
582         }
583
584 out:
585         kfree(detection);
586         return ret;
587 }
588
589 int wl1271_acx_bcn_dtim_options(struct wl1271 *wl)
590 {
591         struct acx_beacon_broadcast *bb;
592         int ret;
593
594         wl1271_debug(DEBUG_ACX, "acx bcn dtim options");
595
596         bb = kzalloc(sizeof(*bb), GFP_KERNEL);
597         if (!bb) {
598                 ret = -ENOMEM;
599                 goto out;
600         }
601
602         bb->role_id = wl->role_id;
603         bb->beacon_rx_timeout = cpu_to_le16(wl->conf.conn.beacon_rx_timeout);
604         bb->broadcast_timeout = cpu_to_le16(wl->conf.conn.broadcast_timeout);
605         bb->rx_broadcast_in_ps = wl->conf.conn.rx_broadcast_in_ps;
606         bb->ps_poll_threshold = wl->conf.conn.ps_poll_threshold;
607
608         ret = wl1271_cmd_configure(wl, ACX_BCN_DTIM_OPTIONS, bb, sizeof(*bb));
609         if (ret < 0) {
610                 wl1271_warning("failed to set rx config: %d", ret);
611                 goto out;
612         }
613
614 out:
615         kfree(bb);
616         return ret;
617 }
618
619 int wl1271_acx_aid(struct wl1271 *wl, u16 aid)
620 {
621         struct acx_aid *acx_aid;
622         int ret;
623
624         wl1271_debug(DEBUG_ACX, "acx aid");
625
626         acx_aid = kzalloc(sizeof(*acx_aid), GFP_KERNEL);
627         if (!acx_aid) {
628                 ret = -ENOMEM;
629                 goto out;
630         }
631
632         acx_aid->role_id = wl->role_id;
633         acx_aid->aid = cpu_to_le16(aid);
634
635         ret = wl1271_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid));
636         if (ret < 0) {
637                 wl1271_warning("failed to set aid: %d", ret);
638                 goto out;
639         }
640
641 out:
642         kfree(acx_aid);
643         return ret;
644 }
645
646 int wl1271_acx_event_mbox_mask(struct wl1271 *wl, u32 event_mask)
647 {
648         struct acx_event_mask *mask;
649         int ret;
650
651         wl1271_debug(DEBUG_ACX, "acx event mbox mask");
652
653         mask = kzalloc(sizeof(*mask), GFP_KERNEL);
654         if (!mask) {
655                 ret = -ENOMEM;
656                 goto out;
657         }
658
659         /* high event mask is unused */
660         mask->high_event_mask = cpu_to_le32(0xffffffff);
661         mask->event_mask = cpu_to_le32(event_mask);
662
663         ret = wl1271_cmd_configure(wl, ACX_EVENT_MBOX_MASK,
664                                    mask, sizeof(*mask));
665         if (ret < 0) {
666                 wl1271_warning("failed to set acx_event_mbox_mask: %d", ret);
667                 goto out;
668         }
669
670 out:
671         kfree(mask);
672         return ret;
673 }
674
675 int wl1271_acx_set_preamble(struct wl1271 *wl, enum acx_preamble_type preamble)
676 {
677         struct acx_preamble *acx;
678         int ret;
679
680         wl1271_debug(DEBUG_ACX, "acx_set_preamble");
681
682         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
683         if (!acx) {
684                 ret = -ENOMEM;
685                 goto out;
686         }
687
688         acx->role_id = wl->role_id;
689         acx->preamble = preamble;
690
691         ret = wl1271_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx));
692         if (ret < 0) {
693                 wl1271_warning("Setting of preamble failed: %d", ret);
694                 goto out;
695         }
696
697 out:
698         kfree(acx);
699         return ret;
700 }
701
702 int wl1271_acx_cts_protect(struct wl1271 *wl,
703                            enum acx_ctsprotect_type ctsprotect)
704 {
705         struct acx_ctsprotect *acx;
706         int ret;
707
708         wl1271_debug(DEBUG_ACX, "acx_set_ctsprotect");
709
710         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
711         if (!acx) {
712                 ret = -ENOMEM;
713                 goto out;
714         }
715
716         acx->role_id = wl->role_id;
717         acx->ctsprotect = ctsprotect;
718
719         ret = wl1271_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx));
720         if (ret < 0) {
721                 wl1271_warning("Setting of ctsprotect failed: %d", ret);
722                 goto out;
723         }
724
725 out:
726         kfree(acx);
727         return ret;
728 }
729
730 int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats)
731 {
732         int ret;
733
734         wl1271_debug(DEBUG_ACX, "acx statistics");
735
736         ret = wl1271_cmd_interrogate(wl, ACX_STATISTICS, stats,
737                                      sizeof(*stats));
738         if (ret < 0) {
739                 wl1271_warning("acx statistics failed: %d", ret);
740                 return -ENOMEM;
741         }
742
743         return 0;
744 }
745
746 int wl1271_acx_sta_rate_policies(struct wl1271 *wl)
747 {
748         struct acx_rate_policy *acx;
749         struct conf_tx_rate_class *c = &wl->conf.tx.sta_rc_conf;
750         int ret = 0;
751
752         wl1271_debug(DEBUG_ACX, "acx rate policies");
753
754         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
755
756         if (!acx) {
757                 ret = -ENOMEM;
758                 goto out;
759         }
760
761         wl1271_debug(DEBUG_ACX, "basic_rate: 0x%x, full_rate: 0x%x",
762                 wl->basic_rate, wl->rate_set);
763
764         /* configure one basic rate class */
765         acx->rate_policy_idx = cpu_to_le32(ACX_TX_BASIC_RATE);
766         acx->rate_policy.enabled_rates = cpu_to_le32(wl->basic_rate);
767         acx->rate_policy.short_retry_limit = c->short_retry_limit;
768         acx->rate_policy.long_retry_limit = c->long_retry_limit;
769         acx->rate_policy.aflags = c->aflags;
770
771         ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
772         if (ret < 0) {
773                 wl1271_warning("Setting of rate policies failed: %d", ret);
774                 goto out;
775         }
776
777         /* configure one AP supported rate class */
778         acx->rate_policy_idx = cpu_to_le32(ACX_TX_AP_FULL_RATE);
779         acx->rate_policy.enabled_rates = cpu_to_le32(wl->rate_set);
780         acx->rate_policy.short_retry_limit = c->short_retry_limit;
781         acx->rate_policy.long_retry_limit = c->long_retry_limit;
782         acx->rate_policy.aflags = c->aflags;
783
784
785
786         ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
787         if (ret < 0) {
788                 wl1271_warning("Setting of rate policies failed: %d", ret);
789                 goto out;
790         }
791
792 out:
793         kfree(acx);
794         return ret;
795 }
796
797 int wl1271_acx_ap_rate_policy(struct wl1271 *wl, struct conf_tx_rate_class *c,
798                       u8 idx)
799 {
800         struct acx_rate_policy *acx;
801         int ret = 0;
802
803         wl1271_debug(DEBUG_ACX, "acx ap rate policy %d rates 0x%x",
804                      idx, c->enabled_rates);
805
806         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
807         if (!acx) {
808                 ret = -ENOMEM;
809                 goto out;
810         }
811
812         acx->rate_policy.enabled_rates = cpu_to_le32(c->enabled_rates);
813         acx->rate_policy.short_retry_limit = c->short_retry_limit;
814         acx->rate_policy.long_retry_limit = c->long_retry_limit;
815         acx->rate_policy.aflags = c->aflags;
816
817         acx->rate_policy_idx = cpu_to_le32(idx);
818
819         ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
820         if (ret < 0) {
821                 wl1271_warning("Setting of ap rate policy 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->role_id = wl->role_id;
847         acx->ac = ac;
848         acx->cw_min = cw_min;
849         acx->cw_max = cpu_to_le16(cw_max);
850         acx->aifsn = aifsn;
851         acx->tx_op_limit = cpu_to_le16(txop);
852
853         ret = wl1271_cmd_configure(wl, ACX_AC_CFG, acx, sizeof(*acx));
854         if (ret < 0) {
855                 wl1271_warning("acx ac cfg failed: %d", ret);
856                 goto out;
857         }
858
859 out:
860         kfree(acx);
861         return ret;
862 }
863
864 int wl1271_acx_tid_cfg(struct wl1271 *wl, u8 queue_id, u8 channel_type,
865                        u8 tsid, u8 ps_scheme, u8 ack_policy,
866                        u32 apsd_conf0, u32 apsd_conf1)
867 {
868         struct acx_tid_config *acx;
869         int ret = 0;
870
871         wl1271_debug(DEBUG_ACX, "acx tid config");
872
873         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
874
875         if (!acx) {
876                 ret = -ENOMEM;
877                 goto out;
878         }
879
880         acx->role_id = wl->role_id;
881         acx->queue_id = queue_id;
882         acx->channel_type = channel_type;
883         acx->tsid = tsid;
884         acx->ps_scheme = ps_scheme;
885         acx->ack_policy = ack_policy;
886         acx->apsd_conf[0] = cpu_to_le32(apsd_conf0);
887         acx->apsd_conf[1] = cpu_to_le32(apsd_conf1);
888
889         ret = wl1271_cmd_configure(wl, ACX_TID_CFG, acx, sizeof(*acx));
890         if (ret < 0) {
891                 wl1271_warning("Setting of tid config failed: %d", ret);
892                 goto out;
893         }
894
895 out:
896         kfree(acx);
897         return ret;
898 }
899
900 int wl1271_acx_frag_threshold(struct wl1271 *wl, u32 frag_threshold)
901 {
902         struct acx_frag_threshold *acx;
903         int ret = 0;
904
905         /*
906          * If the fragmentation is not configured or out of range, use the
907          * default value.
908          */
909         if (frag_threshold > IEEE80211_MAX_FRAG_THRESHOLD)
910                 frag_threshold = wl->conf.tx.frag_threshold;
911
912         wl1271_debug(DEBUG_ACX, "acx frag threshold: %d", frag_threshold);
913
914         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
915
916         if (!acx) {
917                 ret = -ENOMEM;
918                 goto out;
919         }
920
921         acx->frag_threshold = cpu_to_le16((u16)frag_threshold);
922         ret = wl1271_cmd_configure(wl, ACX_FRAG_CFG, acx, sizeof(*acx));
923         if (ret < 0) {
924                 wl1271_warning("Setting of frag threshold failed: %d", ret);
925                 goto out;
926         }
927
928 out:
929         kfree(acx);
930         return ret;
931 }
932
933 int wl1271_acx_tx_config_options(struct wl1271 *wl)
934 {
935         struct acx_tx_config_options *acx;
936         int ret = 0;
937
938         wl1271_debug(DEBUG_ACX, "acx tx config options");
939
940         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
941
942         if (!acx) {
943                 ret = -ENOMEM;
944                 goto out;
945         }
946
947         acx->tx_compl_timeout = cpu_to_le16(wl->conf.tx.tx_compl_timeout);
948         acx->tx_compl_threshold = cpu_to_le16(wl->conf.tx.tx_compl_threshold);
949         ret = wl1271_cmd_configure(wl, ACX_TX_CONFIG_OPT, acx, sizeof(*acx));
950         if (ret < 0) {
951                 wl1271_warning("Setting of tx options failed: %d", ret);
952                 goto out;
953         }
954
955 out:
956         kfree(acx);
957         return ret;
958 }
959
960 int wl12xx_acx_mem_cfg(struct wl1271 *wl)
961 {
962         struct wl12xx_acx_config_memory *mem_conf;
963         struct conf_memory_settings *mem;
964         int ret;
965
966         wl1271_debug(DEBUG_ACX, "wl1271 mem cfg");
967
968         mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL);
969         if (!mem_conf) {
970                 ret = -ENOMEM;
971                 goto out;
972         }
973
974         if (wl->chip.id == CHIP_ID_1283_PG20)
975                 mem = &wl->conf.mem_wl128x;
976         else
977                 mem = &wl->conf.mem_wl127x;
978
979         /* memory config */
980         mem_conf->num_stations = mem->num_stations;
981         mem_conf->rx_mem_block_num = mem->rx_block_num;
982         mem_conf->tx_min_mem_block_num = mem->tx_min_block_num;
983         mem_conf->num_ssid_profiles = mem->ssid_profiles;
984         mem_conf->total_tx_descriptors = cpu_to_le32(ACX_TX_DESCRIPTORS);
985         mem_conf->dyn_mem_enable = mem->dynamic_memory;
986         mem_conf->tx_free_req = mem->min_req_tx_blocks;
987         mem_conf->rx_free_req = mem->min_req_rx_blocks;
988         mem_conf->tx_min = mem->tx_min;
989         mem_conf->fwlog_blocks = wl->conf.fwlog.mem_blocks;
990
991         ret = wl1271_cmd_configure(wl, ACX_MEM_CFG, mem_conf,
992                                    sizeof(*mem_conf));
993         if (ret < 0) {
994                 wl1271_warning("wl1271 mem config failed: %d", ret);
995                 goto out;
996         }
997
998 out:
999         kfree(mem_conf);
1000         return ret;
1001 }
1002
1003 int wl1271_acx_host_if_cfg_bitmap(struct wl1271 *wl, u32 host_cfg_bitmap)
1004 {
1005         struct wl1271_acx_host_config_bitmap *bitmap_conf;
1006         int ret;
1007
1008         bitmap_conf = kzalloc(sizeof(*bitmap_conf), GFP_KERNEL);
1009         if (!bitmap_conf) {
1010                 ret = -ENOMEM;
1011                 goto out;
1012         }
1013
1014         bitmap_conf->host_cfg_bitmap = cpu_to_le32(host_cfg_bitmap);
1015
1016         ret = wl1271_cmd_configure(wl, ACX_HOST_IF_CFG_BITMAP,
1017                                    bitmap_conf, sizeof(*bitmap_conf));
1018         if (ret < 0) {
1019                 wl1271_warning("wl1271 bitmap config opt failed: %d", ret);
1020                 goto out;
1021         }
1022
1023 out:
1024         kfree(bitmap_conf);
1025
1026         return ret;
1027 }
1028
1029 int wl1271_acx_init_mem_config(struct wl1271 *wl)
1030 {
1031         int ret;
1032
1033         wl->target_mem_map = kzalloc(sizeof(struct wl1271_acx_mem_map),
1034                                      GFP_KERNEL);
1035         if (!wl->target_mem_map) {
1036                 wl1271_error("couldn't allocate target memory map");
1037                 return -ENOMEM;
1038         }
1039
1040         /* we now ask for the firmware built memory map */
1041         ret = wl1271_acx_mem_map(wl, (void *)wl->target_mem_map,
1042                                  sizeof(struct wl1271_acx_mem_map));
1043         if (ret < 0) {
1044                 wl1271_error("couldn't retrieve firmware memory map");
1045                 kfree(wl->target_mem_map);
1046                 wl->target_mem_map = NULL;
1047                 return ret;
1048         }
1049
1050         /* initialize TX block book keeping */
1051         wl->tx_blocks_available =
1052                 le32_to_cpu(wl->target_mem_map->num_tx_mem_blocks);
1053         wl1271_debug(DEBUG_TX, "available tx blocks: %d",
1054                      wl->tx_blocks_available);
1055
1056         return 0;
1057 }
1058
1059 int wl1271_acx_init_rx_interrupt(struct wl1271 *wl)
1060 {
1061         struct wl1271_acx_rx_config_opt *rx_conf;
1062         int ret;
1063
1064         wl1271_debug(DEBUG_ACX, "wl1271 rx interrupt config");
1065
1066         rx_conf = kzalloc(sizeof(*rx_conf), GFP_KERNEL);
1067         if (!rx_conf) {
1068                 ret = -ENOMEM;
1069                 goto out;
1070         }
1071
1072         rx_conf->threshold = cpu_to_le16(wl->conf.rx.irq_pkt_threshold);
1073         rx_conf->timeout = cpu_to_le16(wl->conf.rx.irq_timeout);
1074         rx_conf->mblk_threshold = cpu_to_le16(wl->conf.rx.irq_blk_threshold);
1075         rx_conf->queue_type = wl->conf.rx.queue_type;
1076
1077         ret = wl1271_cmd_configure(wl, ACX_RX_CONFIG_OPT, rx_conf,
1078                                    sizeof(*rx_conf));
1079         if (ret < 0) {
1080                 wl1271_warning("wl1271 rx config opt failed: %d", ret);
1081                 goto out;
1082         }
1083
1084 out:
1085         kfree(rx_conf);
1086         return ret;
1087 }
1088
1089 int wl1271_acx_bet_enable(struct wl1271 *wl, bool enable)
1090 {
1091         struct wl1271_acx_bet_enable *acx = NULL;
1092         int ret = 0;
1093
1094         wl1271_debug(DEBUG_ACX, "acx bet enable");
1095
1096         if (enable && wl->conf.conn.bet_enable == CONF_BET_MODE_DISABLE)
1097                 goto out;
1098
1099         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1100         if (!acx) {
1101                 ret = -ENOMEM;
1102                 goto out;
1103         }
1104
1105         acx->role_id = wl->role_id;
1106         acx->enable = enable ? CONF_BET_MODE_ENABLE : CONF_BET_MODE_DISABLE;
1107         acx->max_consecutive = wl->conf.conn.bet_max_consecutive;
1108
1109         ret = wl1271_cmd_configure(wl, ACX_BET_ENABLE, acx, sizeof(*acx));
1110         if (ret < 0) {
1111                 wl1271_warning("acx bet enable failed: %d", ret);
1112                 goto out;
1113         }
1114
1115 out:
1116         kfree(acx);
1117         return ret;
1118 }
1119
1120 int wl1271_acx_arp_ip_filter(struct wl1271 *wl, u8 enable, __be32 address)
1121 {
1122         struct wl1271_acx_arp_filter *acx;
1123         int ret;
1124
1125         wl1271_debug(DEBUG_ACX, "acx arp ip filter, enable: %d", enable);
1126
1127         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1128         if (!acx) {
1129                 ret = -ENOMEM;
1130                 goto out;
1131         }
1132
1133         acx->role_id = wl->role_id;
1134         acx->version = ACX_IPV4_VERSION;
1135         acx->enable = enable;
1136
1137         if (enable)
1138                 memcpy(acx->address, &address, ACX_IPV4_ADDR_SIZE);
1139
1140         ret = wl1271_cmd_configure(wl, ACX_ARP_IP_FILTER,
1141                                    acx, sizeof(*acx));
1142         if (ret < 0) {
1143                 wl1271_warning("failed to set arp ip filter: %d", ret);
1144                 goto out;
1145         }
1146
1147 out:
1148         kfree(acx);
1149         return ret;
1150 }
1151
1152 int wl1271_acx_pm_config(struct wl1271 *wl)
1153 {
1154         struct wl1271_acx_pm_config *acx = NULL;
1155         struct  conf_pm_config_settings *c = &wl->conf.pm_config;
1156         int ret = 0;
1157
1158         wl1271_debug(DEBUG_ACX, "acx pm config");
1159
1160         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1161         if (!acx) {
1162                 ret = -ENOMEM;
1163                 goto out;
1164         }
1165
1166         acx->host_clk_settling_time = cpu_to_le32(c->host_clk_settling_time);
1167         acx->host_fast_wakeup_support = c->host_fast_wakeup_support;
1168
1169         ret = wl1271_cmd_configure(wl, ACX_PM_CONFIG, acx, sizeof(*acx));
1170         if (ret < 0) {
1171                 wl1271_warning("acx pm config failed: %d", ret);
1172                 goto out;
1173         }
1174
1175 out:
1176         kfree(acx);
1177         return ret;
1178 }
1179
1180 int wl1271_acx_keep_alive_mode(struct wl1271 *wl, bool enable)
1181 {
1182         struct wl1271_acx_keep_alive_mode *acx = NULL;
1183         int ret = 0;
1184
1185         wl1271_debug(DEBUG_ACX, "acx keep alive mode: %d", enable);
1186
1187         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1188         if (!acx) {
1189                 ret = -ENOMEM;
1190                 goto out;
1191         }
1192
1193         acx->role_id = wl->role_id;
1194         acx->enabled = enable;
1195
1196         ret = wl1271_cmd_configure(wl, ACX_KEEP_ALIVE_MODE, acx, sizeof(*acx));
1197         if (ret < 0) {
1198                 wl1271_warning("acx keep alive mode failed: %d", ret);
1199                 goto out;
1200         }
1201
1202 out:
1203         kfree(acx);
1204         return ret;
1205 }
1206
1207 int wl1271_acx_keep_alive_config(struct wl1271 *wl, u8 index, u8 tpl_valid)
1208 {
1209         struct wl1271_acx_keep_alive_config *acx = NULL;
1210         int ret = 0;
1211
1212         wl1271_debug(DEBUG_ACX, "acx keep alive config");
1213
1214         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1215         if (!acx) {
1216                 ret = -ENOMEM;
1217                 goto out;
1218         }
1219
1220         acx->role_id = wl->role_id;
1221         acx->period = cpu_to_le32(wl->conf.conn.keep_alive_interval);
1222         acx->index = index;
1223         acx->tpl_validation = tpl_valid;
1224         acx->trigger = ACX_KEEP_ALIVE_NO_TX;
1225
1226         ret = wl1271_cmd_configure(wl, ACX_SET_KEEP_ALIVE_CONFIG,
1227                                    acx, sizeof(*acx));
1228         if (ret < 0) {
1229                 wl1271_warning("acx keep alive config failed: %d", ret);
1230                 goto out;
1231         }
1232
1233 out:
1234         kfree(acx);
1235         return ret;
1236 }
1237
1238 int wl1271_acx_rssi_snr_trigger(struct wl1271 *wl, bool enable,
1239                                 s16 thold, u8 hyst)
1240 {
1241         struct wl1271_acx_rssi_snr_trigger *acx = NULL;
1242         int ret = 0;
1243
1244         wl1271_debug(DEBUG_ACX, "acx rssi snr trigger");
1245
1246         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1247         if (!acx) {
1248                 ret = -ENOMEM;
1249                 goto out;
1250         }
1251
1252         wl->last_rssi_event = -1;
1253
1254         acx->role_id = wl->role_id;
1255         acx->pacing = cpu_to_le16(wl->conf.roam_trigger.trigger_pacing);
1256         acx->metric = WL1271_ACX_TRIG_METRIC_RSSI_BEACON;
1257         acx->type = WL1271_ACX_TRIG_TYPE_EDGE;
1258         if (enable)
1259                 acx->enable = WL1271_ACX_TRIG_ENABLE;
1260         else
1261                 acx->enable = WL1271_ACX_TRIG_DISABLE;
1262
1263         acx->index = WL1271_ACX_TRIG_IDX_RSSI;
1264         acx->dir = WL1271_ACX_TRIG_DIR_BIDIR;
1265         acx->threshold = cpu_to_le16(thold);
1266         acx->hysteresis = hyst;
1267
1268         ret = wl1271_cmd_configure(wl, ACX_RSSI_SNR_TRIGGER, acx, sizeof(*acx));
1269         if (ret < 0) {
1270                 wl1271_warning("acx rssi snr trigger setting failed: %d", ret);
1271                 goto out;
1272         }
1273
1274 out:
1275         kfree(acx);
1276         return ret;
1277 }
1278
1279 int wl1271_acx_rssi_snr_avg_weights(struct wl1271 *wl)
1280 {
1281         struct wl1271_acx_rssi_snr_avg_weights *acx = NULL;
1282         struct conf_roam_trigger_settings *c = &wl->conf.roam_trigger;
1283         int ret = 0;
1284
1285         wl1271_debug(DEBUG_ACX, "acx rssi snr avg weights");
1286
1287         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1288         if (!acx) {
1289                 ret = -ENOMEM;
1290                 goto out;
1291         }
1292
1293         acx->role_id = wl->role_id;
1294         acx->rssi_beacon = c->avg_weight_rssi_beacon;
1295         acx->rssi_data = c->avg_weight_rssi_data;
1296         acx->snr_beacon = c->avg_weight_snr_beacon;
1297         acx->snr_data = c->avg_weight_snr_data;
1298
1299         ret = wl1271_cmd_configure(wl, ACX_RSSI_SNR_WEIGHTS, acx, sizeof(*acx));
1300         if (ret < 0) {
1301                 wl1271_warning("acx rssi snr trigger weights failed: %d", ret);
1302                 goto out;
1303         }
1304
1305 out:
1306         kfree(acx);
1307         return ret;
1308 }
1309
1310 int wl1271_acx_set_ht_capabilities(struct wl1271 *wl,
1311                                     struct ieee80211_sta_ht_cap *ht_cap,
1312                                     bool allow_ht_operation, u8 hlid)
1313 {
1314         struct wl1271_acx_ht_capabilities *acx;
1315         int ret = 0;
1316         u32 ht_capabilites = 0;
1317
1318         wl1271_debug(DEBUG_ACX, "acx ht capabilities setting "
1319                      "sta supp: %d sta cap: %d", ht_cap->ht_supported,
1320                      ht_cap->cap);
1321
1322         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1323         if (!acx) {
1324                 ret = -ENOMEM;
1325                 goto out;
1326         }
1327
1328         if (allow_ht_operation && ht_cap->ht_supported) {
1329                 /* no need to translate capabilities - use the spec values */
1330                 ht_capabilites = ht_cap->cap;
1331
1332                 /*
1333                  * this bit is not employed by the spec but only by FW to
1334                  * indicate peer HT support
1335                  */
1336                 ht_capabilites |= WL12XX_HT_CAP_HT_OPERATION;
1337
1338                 /* get data from A-MPDU parameters field */
1339                 acx->ampdu_max_length = ht_cap->ampdu_factor;
1340                 acx->ampdu_min_spacing = ht_cap->ampdu_density;
1341         }
1342
1343         acx->hlid = hlid;
1344         acx->ht_capabilites = cpu_to_le32(ht_capabilites);
1345
1346         ret = wl1271_cmd_configure(wl, ACX_PEER_HT_CAP, acx, sizeof(*acx));
1347         if (ret < 0) {
1348                 wl1271_warning("acx ht capabilities setting failed: %d", ret);
1349                 goto out;
1350         }
1351
1352 out:
1353         kfree(acx);
1354         return ret;
1355 }
1356
1357 int wl1271_acx_set_ht_information(struct wl1271 *wl,
1358                                    u16 ht_operation_mode)
1359 {
1360         struct wl1271_acx_ht_information *acx;
1361         int ret = 0;
1362
1363         wl1271_debug(DEBUG_ACX, "acx ht information setting");
1364
1365         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1366         if (!acx) {
1367                 ret = -ENOMEM;
1368                 goto out;
1369         }
1370
1371         acx->role_id = wl->role_id;
1372         acx->ht_protection =
1373                 (u8)(ht_operation_mode & IEEE80211_HT_OP_MODE_PROTECTION);
1374         acx->rifs_mode = 0;
1375         acx->gf_protection =
1376                 !!(ht_operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
1377         acx->ht_tx_burst_limit = 0;
1378         acx->dual_cts_protection = 0;
1379
1380         ret = wl1271_cmd_configure(wl, ACX_HT_BSS_OPERATION, acx, sizeof(*acx));
1381
1382         if (ret < 0) {
1383                 wl1271_warning("acx ht information setting failed: %d", ret);
1384                 goto out;
1385         }
1386
1387 out:
1388         kfree(acx);
1389         return ret;
1390 }
1391
1392 /* Configure BA session initiator/receiver parameters setting in the FW. */
1393 int wl12xx_acx_set_ba_initiator_policy(struct wl1271 *wl)
1394 {
1395         struct wl1271_acx_ba_initiator_policy *acx;
1396         int ret;
1397
1398         wl1271_debug(DEBUG_ACX, "acx ba initiator policy");
1399
1400         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1401         if (!acx) {
1402                 ret = -ENOMEM;
1403                 goto out;
1404         }
1405
1406         /* set for the current role */
1407         acx->role_id = wl->role_id;
1408         acx->tid_bitmap = wl->conf.ht.tx_ba_tid_bitmap;
1409         acx->win_size = wl->conf.ht.tx_ba_win_size;
1410         acx->inactivity_timeout = wl->conf.ht.inactivity_timeout;
1411
1412         ret = wl1271_cmd_configure(wl,
1413                                    ACX_BA_SESSION_INIT_POLICY,
1414                                    acx,
1415                                    sizeof(*acx));
1416         if (ret < 0) {
1417                 wl1271_warning("acx ba initiator policy failed: %d", ret);
1418                 goto out;
1419         }
1420
1421 out:
1422         kfree(acx);
1423         return ret;
1424 }
1425
1426 /* setup BA session receiver setting in the FW. */
1427 int wl12xx_acx_set_ba_receiver_session(struct wl1271 *wl, u8 tid_index,
1428                                        u16 ssn, bool enable, u8 peer_hlid)
1429 {
1430         struct wl1271_acx_ba_receiver_setup *acx;
1431         int ret;
1432
1433         wl1271_debug(DEBUG_ACX, "acx ba receiver session setting");
1434
1435         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1436         if (!acx) {
1437                 ret = -ENOMEM;
1438                 goto out;
1439         }
1440
1441         acx->hlid = peer_hlid;
1442         acx->tid = tid_index;
1443         acx->enable = enable;
1444         acx->win_size = wl->conf.ht.rx_ba_win_size;
1445         acx->ssn = ssn;
1446
1447         ret = wl1271_cmd_configure(wl, ACX_BA_SESSION_RX_SETUP, acx,
1448                                    sizeof(*acx));
1449         if (ret < 0) {
1450                 wl1271_warning("acx ba receiver session failed: %d", ret);
1451                 goto out;
1452         }
1453
1454 out:
1455         kfree(acx);
1456         return ret;
1457 }
1458
1459 int wl1271_acx_tsf_info(struct wl1271 *wl, u64 *mactime)
1460 {
1461         struct wl1271_acx_fw_tsf_information *tsf_info;
1462         int ret;
1463
1464         tsf_info = kzalloc(sizeof(*tsf_info), GFP_KERNEL);
1465         if (!tsf_info) {
1466                 ret = -ENOMEM;
1467                 goto out;
1468         }
1469
1470         ret = wl1271_cmd_interrogate(wl, ACX_TSF_INFO,
1471                                      tsf_info, sizeof(*tsf_info));
1472         if (ret < 0) {
1473                 wl1271_warning("acx tsf info interrogate failed");
1474                 goto out;
1475         }
1476
1477         *mactime = le32_to_cpu(tsf_info->current_tsf_low) |
1478                 ((u64) le32_to_cpu(tsf_info->current_tsf_high) << 32);
1479
1480 out:
1481         kfree(tsf_info);
1482         return ret;
1483 }
1484
1485 int wl1271_acx_ps_rx_streaming(struct wl1271 *wl, bool enable)
1486 {
1487         struct wl1271_acx_ps_rx_streaming *rx_streaming;
1488         u32 conf_queues, enable_queues;
1489         int i, ret = 0;
1490
1491         wl1271_debug(DEBUG_ACX, "acx ps rx streaming");
1492
1493         rx_streaming = kzalloc(sizeof(*rx_streaming), GFP_KERNEL);
1494         if (!rx_streaming) {
1495                 ret = -ENOMEM;
1496                 goto out;
1497         }
1498
1499         conf_queues = wl->conf.rx_streaming.queues;
1500         if (enable)
1501                 enable_queues = conf_queues;
1502         else
1503                 enable_queues = 0;
1504
1505         for (i = 0; i < 8; i++) {
1506                 /*
1507                  * Skip non-changed queues, to avoid redundant acxs.
1508                  * this check assumes conf.rx_streaming.queues can't
1509                  * be changed while rx_streaming is enabled.
1510                  */
1511                 if (!(conf_queues & BIT(i)))
1512                         continue;
1513
1514                 rx_streaming->role_id = wl->role_id;
1515                 rx_streaming->tid = i;
1516                 rx_streaming->enable = enable_queues & BIT(i);
1517                 rx_streaming->period = wl->conf.rx_streaming.interval;
1518                 rx_streaming->timeout = wl->conf.rx_streaming.interval;
1519
1520                 ret = wl1271_cmd_configure(wl, ACX_PS_RX_STREAMING,
1521                                            rx_streaming,
1522                                            sizeof(*rx_streaming));
1523                 if (ret < 0) {
1524                         wl1271_warning("acx ps rx streaming failed: %d", ret);
1525                         goto out;
1526                 }
1527         }
1528 out:
1529         kfree(rx_streaming);
1530         return ret;
1531 }
1532
1533 int wl1271_acx_ap_max_tx_retry(struct wl1271 *wl)
1534 {
1535         struct wl1271_acx_ap_max_tx_retry *acx = NULL;
1536         int ret;
1537
1538         wl1271_debug(DEBUG_ACX, "acx ap max tx retry");
1539
1540         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1541         if (!acx)
1542                 return -ENOMEM;
1543
1544         acx->role_id = wl->role_id;
1545         acx->max_tx_retry = cpu_to_le16(wl->conf.tx.max_tx_retries);
1546
1547         ret = wl1271_cmd_configure(wl, ACX_MAX_TX_FAILURE, acx, sizeof(*acx));
1548         if (ret < 0) {
1549                 wl1271_warning("acx ap max tx retry failed: %d", ret);
1550                 goto out;
1551         }
1552
1553 out:
1554         kfree(acx);
1555         return ret;
1556 }
1557
1558 int wl1271_acx_config_ps(struct wl1271 *wl)
1559 {
1560         struct wl1271_acx_config_ps *config_ps;
1561         int ret;
1562
1563         wl1271_debug(DEBUG_ACX, "acx config ps");
1564
1565         config_ps = kzalloc(sizeof(*config_ps), GFP_KERNEL);
1566         if (!config_ps) {
1567                 ret = -ENOMEM;
1568                 goto out;
1569         }
1570
1571         config_ps->exit_retries = wl->conf.conn.psm_exit_retries;
1572         config_ps->enter_retries = wl->conf.conn.psm_entry_retries;
1573         config_ps->null_data_rate = cpu_to_le32(wl->basic_rate);
1574
1575         ret = wl1271_cmd_configure(wl, ACX_CONFIG_PS, config_ps,
1576                                    sizeof(*config_ps));
1577
1578         if (ret < 0) {
1579                 wl1271_warning("acx config ps failed: %d", ret);
1580                 goto out;
1581         }
1582
1583 out:
1584         kfree(config_ps);
1585         return ret;
1586 }
1587
1588 int wl1271_acx_set_inconnection_sta(struct wl1271 *wl, u8 *addr)
1589 {
1590         struct wl1271_acx_inconnection_sta *acx = NULL;
1591         int ret;
1592
1593         wl1271_debug(DEBUG_ACX, "acx set inconnaction sta %pM", addr);
1594
1595         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1596         if (!acx)
1597                 return -ENOMEM;
1598
1599         memcpy(acx->addr, addr, ETH_ALEN);
1600
1601         ret = wl1271_cmd_configure(wl, ACX_UPDATE_INCONNECTION_STA_LIST,
1602                                    acx, sizeof(*acx));
1603         if (ret < 0) {
1604                 wl1271_warning("acx set inconnaction sta failed: %d", ret);
1605                 goto out;
1606         }
1607
1608 out:
1609         kfree(acx);
1610         return ret;
1611 }
1612
1613 int wl1271_acx_fm_coex(struct wl1271 *wl)
1614 {
1615         struct wl1271_acx_fm_coex *acx;
1616         int ret;
1617
1618         wl1271_debug(DEBUG_ACX, "acx fm coex setting");
1619
1620         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1621         if (!acx) {
1622                 ret = -ENOMEM;
1623                 goto out;
1624         }
1625
1626         acx->enable = wl->conf.fm_coex.enable;
1627         acx->swallow_period = wl->conf.fm_coex.swallow_period;
1628         acx->n_divider_fref_set_1 = wl->conf.fm_coex.n_divider_fref_set_1;
1629         acx->n_divider_fref_set_2 = wl->conf.fm_coex.n_divider_fref_set_2;
1630         acx->m_divider_fref_set_1 =
1631                 cpu_to_le16(wl->conf.fm_coex.m_divider_fref_set_1);
1632         acx->m_divider_fref_set_2 =
1633                 cpu_to_le16(wl->conf.fm_coex.m_divider_fref_set_2);
1634         acx->coex_pll_stabilization_time =
1635                 cpu_to_le32(wl->conf.fm_coex.coex_pll_stabilization_time);
1636         acx->ldo_stabilization_time =
1637                 cpu_to_le16(wl->conf.fm_coex.ldo_stabilization_time);
1638         acx->fm_disturbed_band_margin =
1639                 wl->conf.fm_coex.fm_disturbed_band_margin;
1640         acx->swallow_clk_diff = wl->conf.fm_coex.swallow_clk_diff;
1641
1642         ret = wl1271_cmd_configure(wl, ACX_FM_COEX_CFG, acx, sizeof(*acx));
1643         if (ret < 0) {
1644                 wl1271_warning("acx fm coex setting failed: %d", ret);
1645                 goto out;
1646         }
1647
1648 out:
1649         kfree(acx);
1650         return ret;
1651 }
1652
1653 int wl12xx_acx_set_rate_mgmt_params(struct wl1271 *wl)
1654 {
1655         struct wl12xx_acx_set_rate_mgmt_params *acx = NULL;
1656         struct conf_rate_policy_settings *conf = &wl->conf.rate;
1657         int ret;
1658
1659         wl1271_debug(DEBUG_ACX, "acx set rate mgmt params");
1660
1661         acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1662         if (!acx)
1663                 return -ENOMEM;
1664
1665         acx->index = ACX_RATE_MGMT_ALL_PARAMS;
1666         acx->rate_retry_score = cpu_to_le16(conf->rate_retry_score);
1667         acx->per_add = cpu_to_le16(conf->per_add);
1668         acx->per_th1 = cpu_to_le16(conf->per_th1);
1669         acx->per_th2 = cpu_to_le16(conf->per_th2);
1670         acx->max_per = cpu_to_le16(conf->max_per);
1671         acx->inverse_curiosity_factor = conf->inverse_curiosity_factor;
1672         acx->tx_fail_low_th = conf->tx_fail_low_th;
1673         acx->tx_fail_high_th = conf->tx_fail_high_th;
1674         acx->per_alpha_shift = conf->per_alpha_shift;
1675         acx->per_add_shift = conf->per_add_shift;
1676         acx->per_beta1_shift = conf->per_beta1_shift;
1677         acx->per_beta2_shift = conf->per_beta2_shift;
1678         acx->rate_check_up = conf->rate_check_up;
1679         acx->rate_check_down = conf->rate_check_down;
1680         memcpy(acx->rate_retry_policy, conf->rate_retry_policy,
1681                sizeof(acx->rate_retry_policy));
1682
1683         ret = wl1271_cmd_configure(wl, ACX_SET_RATE_MGMT_PARAMS,
1684                                    acx, sizeof(*acx));
1685         if (ret < 0) {
1686                 wl1271_warning("acx set rate mgmt params failed: %d", ret);
1687                 goto out;
1688         }
1689
1690 out:
1691         kfree(acx);
1692         return ret;
1693 }