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