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