Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / drivers / net / wireless / ti / wlcore / acx.c
blob3ca9167d6146af610c445f358bf45b2bebd52c03
1 /*
2 * This file is part of wl1271
4 * Copyright (C) 2008-2009 Nokia Corporation
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
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.
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.
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
24 #include "acx.h"
26 #include <linux/module.h>
27 #include <linux/platform_device.h>
28 #include <linux/spi/spi.h>
29 #include <linux/slab.h>
31 #include "wlcore.h"
32 #include "debug.h"
33 #include "wl12xx_80211.h"
34 #include "ps.h"
35 #include "hw_ops.h"
37 int wl1271_acx_wake_up_conditions(struct wl1271 *wl, struct wl12xx_vif *wlvif,
38 u8 wake_up_event, u8 listen_interval)
40 struct acx_wake_up_condition *wake_up;
41 int ret;
43 wl1271_debug(DEBUG_ACX, "acx wake up conditions (wake_up_event %d listen_interval %d)",
44 wake_up_event, listen_interval);
46 wake_up = kzalloc(sizeof(*wake_up), GFP_KERNEL);
47 if (!wake_up) {
48 ret = -ENOMEM;
49 goto out;
52 wake_up->role_id = wlvif->role_id;
53 wake_up->wake_up_event = wake_up_event;
54 wake_up->listen_interval = listen_interval;
56 ret = wl1271_cmd_configure(wl, ACX_WAKE_UP_CONDITIONS,
57 wake_up, sizeof(*wake_up));
58 if (ret < 0) {
59 wl1271_warning("could not set wake up conditions: %d", ret);
60 goto out;
63 out:
64 kfree(wake_up);
65 return ret;
68 int wl1271_acx_sleep_auth(struct wl1271 *wl, u8 sleep_auth)
70 struct acx_sleep_auth *auth;
71 int ret;
73 wl1271_debug(DEBUG_ACX, "acx sleep auth %d", sleep_auth);
75 auth = kzalloc(sizeof(*auth), GFP_KERNEL);
76 if (!auth) {
77 ret = -ENOMEM;
78 goto out;
81 auth->sleep_auth = sleep_auth;
83 ret = wl1271_cmd_configure(wl, ACX_SLEEP_AUTH, auth, sizeof(*auth));
84 if (ret < 0) {
85 wl1271_error("could not configure sleep_auth to %d: %d",
86 sleep_auth, ret);
87 goto out;
90 wl->sleep_auth = sleep_auth;
91 out:
92 kfree(auth);
93 return ret;
95 EXPORT_SYMBOL_GPL(wl1271_acx_sleep_auth);
97 int wl1271_acx_tx_power(struct wl1271 *wl, struct wl12xx_vif *wlvif,
98 int power)
100 struct acx_current_tx_power *acx;
101 int ret;
103 wl1271_debug(DEBUG_ACX, "acx dot11_cur_tx_pwr %d", power);
105 if (power < 0 || power > 25)
106 return -EINVAL;
108 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
109 if (!acx) {
110 ret = -ENOMEM;
111 goto out;
114 acx->role_id = wlvif->role_id;
115 acx->current_tx_power = power * 10;
117 ret = wl1271_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx));
118 if (ret < 0) {
119 wl1271_warning("configure of tx power failed: %d", ret);
120 goto out;
123 out:
124 kfree(acx);
125 return ret;
128 int wl1271_acx_feature_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif)
130 struct acx_feature_config *feature;
131 int ret;
133 wl1271_debug(DEBUG_ACX, "acx feature cfg");
135 feature = kzalloc(sizeof(*feature), GFP_KERNEL);
136 if (!feature) {
137 ret = -ENOMEM;
138 goto out;
141 /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */
142 feature->role_id = wlvif->role_id;
143 feature->data_flow_options = 0;
144 feature->options = 0;
146 ret = wl1271_cmd_configure(wl, ACX_FEATURE_CFG,
147 feature, sizeof(*feature));
148 if (ret < 0) {
149 wl1271_error("Couldn't set HW encryption");
150 goto out;
153 out:
154 kfree(feature);
155 return ret;
158 int wl1271_acx_mem_map(struct wl1271 *wl, struct acx_header *mem_map,
159 size_t len)
161 int ret;
163 wl1271_debug(DEBUG_ACX, "acx mem map");
165 ret = wl1271_cmd_interrogate(wl, ACX_MEM_MAP, mem_map,
166 sizeof(struct acx_header), len);
167 if (ret < 0)
168 return ret;
170 return 0;
173 int wl1271_acx_rx_msdu_life_time(struct wl1271 *wl)
175 struct acx_rx_msdu_lifetime *acx;
176 int ret;
178 wl1271_debug(DEBUG_ACX, "acx rx msdu life time");
180 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
181 if (!acx) {
182 ret = -ENOMEM;
183 goto out;
186 acx->lifetime = cpu_to_le32(wl->conf.rx.rx_msdu_life_time);
187 ret = wl1271_cmd_configure(wl, DOT11_RX_MSDU_LIFE_TIME,
188 acx, sizeof(*acx));
189 if (ret < 0) {
190 wl1271_warning("failed to set rx msdu life time: %d", ret);
191 goto out;
194 out:
195 kfree(acx);
196 return ret;
199 int wl1271_acx_slot(struct wl1271 *wl, struct wl12xx_vif *wlvif,
200 enum acx_slot_type slot_time)
202 struct acx_slot *slot;
203 int ret;
205 wl1271_debug(DEBUG_ACX, "acx slot");
207 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
208 if (!slot) {
209 ret = -ENOMEM;
210 goto out;
213 slot->role_id = wlvif->role_id;
214 slot->wone_index = STATION_WONE_INDEX;
215 slot->slot_time = slot_time;
217 ret = wl1271_cmd_configure(wl, ACX_SLOT, slot, sizeof(*slot));
218 if (ret < 0) {
219 wl1271_warning("failed to set slot time: %d", ret);
220 goto out;
223 out:
224 kfree(slot);
225 return ret;
228 int wl1271_acx_group_address_tbl(struct wl1271 *wl, struct wl12xx_vif *wlvif,
229 bool enable, void *mc_list, u32 mc_list_len)
231 struct acx_dot11_grp_addr_tbl *acx;
232 int ret;
234 wl1271_debug(DEBUG_ACX, "acx group address tbl");
236 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
237 if (!acx) {
238 ret = -ENOMEM;
239 goto out;
242 /* MAC filtering */
243 acx->role_id = wlvif->role_id;
244 acx->enabled = enable;
245 acx->num_groups = mc_list_len;
246 memcpy(acx->mac_table, mc_list, mc_list_len * ETH_ALEN);
248 ret = wl1271_cmd_configure(wl, DOT11_GROUP_ADDRESS_TBL,
249 acx, sizeof(*acx));
250 if (ret < 0) {
251 wl1271_warning("failed to set group addr table: %d", ret);
252 goto out;
255 out:
256 kfree(acx);
257 return ret;
260 int wl1271_acx_service_period_timeout(struct wl1271 *wl,
261 struct wl12xx_vif *wlvif)
263 struct acx_rx_timeout *rx_timeout;
264 int ret;
266 rx_timeout = kzalloc(sizeof(*rx_timeout), GFP_KERNEL);
267 if (!rx_timeout) {
268 ret = -ENOMEM;
269 goto out;
272 wl1271_debug(DEBUG_ACX, "acx service period timeout");
274 rx_timeout->role_id = wlvif->role_id;
275 rx_timeout->ps_poll_timeout = cpu_to_le16(wl->conf.rx.ps_poll_timeout);
276 rx_timeout->upsd_timeout = cpu_to_le16(wl->conf.rx.upsd_timeout);
278 ret = wl1271_cmd_configure(wl, ACX_SERVICE_PERIOD_TIMEOUT,
279 rx_timeout, sizeof(*rx_timeout));
280 if (ret < 0) {
281 wl1271_warning("failed to set service period timeout: %d",
282 ret);
283 goto out;
286 out:
287 kfree(rx_timeout);
288 return ret;
291 int wl1271_acx_rts_threshold(struct wl1271 *wl, struct wl12xx_vif *wlvif,
292 u32 rts_threshold)
294 struct acx_rts_threshold *rts;
295 int ret;
298 * If the RTS threshold is not configured or out of range, use the
299 * default value.
301 if (rts_threshold > IEEE80211_MAX_RTS_THRESHOLD)
302 rts_threshold = wl->conf.rx.rts_threshold;
304 wl1271_debug(DEBUG_ACX, "acx rts threshold: %d", rts_threshold);
306 rts = kzalloc(sizeof(*rts), GFP_KERNEL);
307 if (!rts) {
308 ret = -ENOMEM;
309 goto out;
312 rts->role_id = wlvif->role_id;
313 rts->threshold = cpu_to_le16((u16)rts_threshold);
315 ret = wl1271_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts));
316 if (ret < 0) {
317 wl1271_warning("failed to set rts threshold: %d", ret);
318 goto out;
321 out:
322 kfree(rts);
323 return ret;
326 int wl1271_acx_dco_itrim_params(struct wl1271 *wl)
328 struct acx_dco_itrim_params *dco;
329 struct conf_itrim_settings *c = &wl->conf.itrim;
330 int ret;
332 wl1271_debug(DEBUG_ACX, "acx dco itrim parameters");
334 dco = kzalloc(sizeof(*dco), GFP_KERNEL);
335 if (!dco) {
336 ret = -ENOMEM;
337 goto out;
340 dco->enable = c->enable;
341 dco->timeout = cpu_to_le32(c->timeout);
343 ret = wl1271_cmd_configure(wl, ACX_SET_DCO_ITRIM_PARAMS,
344 dco, sizeof(*dco));
345 if (ret < 0) {
346 wl1271_warning("failed to set dco itrim parameters: %d", ret);
347 goto out;
350 out:
351 kfree(dco);
352 return ret;
355 int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, struct wl12xx_vif *wlvif,
356 bool enable_filter)
358 struct acx_beacon_filter_option *beacon_filter = NULL;
359 int ret = 0;
361 wl1271_debug(DEBUG_ACX, "acx beacon filter opt enable=%d",
362 enable_filter);
364 if (enable_filter &&
365 wl->conf.conn.bcn_filt_mode == CONF_BCN_FILT_MODE_DISABLED)
366 goto out;
368 beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL);
369 if (!beacon_filter) {
370 ret = -ENOMEM;
371 goto out;
374 beacon_filter->role_id = wlvif->role_id;
375 beacon_filter->enable = enable_filter;
378 * When set to zero, and the filter is enabled, beacons
379 * without the unicast TIM bit set are dropped.
381 beacon_filter->max_num_beacons = 0;
383 ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_OPT,
384 beacon_filter, sizeof(*beacon_filter));
385 if (ret < 0) {
386 wl1271_warning("failed to set beacon filter opt: %d", ret);
387 goto out;
390 out:
391 kfree(beacon_filter);
392 return ret;
395 int wl1271_acx_beacon_filter_table(struct wl1271 *wl,
396 struct wl12xx_vif *wlvif)
398 struct acx_beacon_filter_ie_table *ie_table;
399 int i, idx = 0;
400 int ret;
401 bool vendor_spec = false;
403 wl1271_debug(DEBUG_ACX, "acx beacon filter table");
405 ie_table = kzalloc(sizeof(*ie_table), GFP_KERNEL);
406 if (!ie_table) {
407 ret = -ENOMEM;
408 goto out;
411 /* configure default beacon pass-through rules */
412 ie_table->role_id = wlvif->role_id;
413 ie_table->num_ie = 0;
414 for (i = 0; i < wl->conf.conn.bcn_filt_ie_count; i++) {
415 struct conf_bcn_filt_rule *r = &(wl->conf.conn.bcn_filt_ie[i]);
416 ie_table->table[idx++] = r->ie;
417 ie_table->table[idx++] = r->rule;
419 if (r->ie == WLAN_EID_VENDOR_SPECIFIC) {
420 /* only one vendor specific ie allowed */
421 if (vendor_spec)
422 continue;
424 /* for vendor specific rules configure the
425 additional fields */
426 memcpy(&(ie_table->table[idx]), r->oui,
427 CONF_BCN_IE_OUI_LEN);
428 idx += CONF_BCN_IE_OUI_LEN;
429 ie_table->table[idx++] = r->type;
430 memcpy(&(ie_table->table[idx]), r->version,
431 CONF_BCN_IE_VER_LEN);
432 idx += CONF_BCN_IE_VER_LEN;
433 vendor_spec = true;
436 ie_table->num_ie++;
439 ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_TABLE,
440 ie_table, sizeof(*ie_table));
441 if (ret < 0) {
442 wl1271_warning("failed to set beacon filter table: %d", ret);
443 goto out;
446 out:
447 kfree(ie_table);
448 return ret;
451 #define ACX_CONN_MONIT_DISABLE_VALUE 0xffffffff
453 int wl1271_acx_conn_monit_params(struct wl1271 *wl, struct wl12xx_vif *wlvif,
454 bool enable)
456 struct acx_conn_monit_params *acx;
457 u32 threshold = ACX_CONN_MONIT_DISABLE_VALUE;
458 u32 timeout = ACX_CONN_MONIT_DISABLE_VALUE;
459 int ret;
461 wl1271_debug(DEBUG_ACX, "acx connection monitor parameters: %s",
462 enable ? "enabled" : "disabled");
464 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
465 if (!acx) {
466 ret = -ENOMEM;
467 goto out;
470 if (enable) {
471 threshold = wl->conf.conn.synch_fail_thold;
472 timeout = wl->conf.conn.bss_lose_timeout;
475 acx->role_id = wlvif->role_id;
476 acx->synch_fail_thold = cpu_to_le32(threshold);
477 acx->bss_lose_timeout = cpu_to_le32(timeout);
479 ret = wl1271_cmd_configure(wl, ACX_CONN_MONIT_PARAMS,
480 acx, sizeof(*acx));
481 if (ret < 0) {
482 wl1271_warning("failed to set connection monitor "
483 "parameters: %d", ret);
484 goto out;
487 out:
488 kfree(acx);
489 return ret;
493 int wl1271_acx_sg_enable(struct wl1271 *wl, bool enable)
495 struct acx_bt_wlan_coex *pta;
496 int ret;
498 wl1271_debug(DEBUG_ACX, "acx sg enable");
500 pta = kzalloc(sizeof(*pta), GFP_KERNEL);
501 if (!pta) {
502 ret = -ENOMEM;
503 goto out;
506 if (enable)
507 pta->enable = wl->conf.sg.state;
508 else
509 pta->enable = CONF_SG_DISABLE;
511 ret = wl1271_cmd_configure(wl, ACX_SG_ENABLE, pta, sizeof(*pta));
512 if (ret < 0) {
513 wl1271_warning("failed to set softgemini enable: %d", ret);
514 goto out;
517 out:
518 kfree(pta);
519 return ret;
522 int wl12xx_acx_sg_cfg(struct wl1271 *wl)
524 struct acx_bt_wlan_coex_param *param;
525 struct conf_sg_settings *c = &wl->conf.sg;
526 int i, ret;
528 wl1271_debug(DEBUG_ACX, "acx sg cfg");
530 param = kzalloc(sizeof(*param), GFP_KERNEL);
531 if (!param) {
532 ret = -ENOMEM;
533 goto out;
536 /* BT-WLAN coext parameters */
537 for (i = 0; i < WLCORE_CONF_SG_PARAMS_MAX; i++)
538 param->params[i] = cpu_to_le32(c->params[i]);
539 param->param_idx = WLCORE_CONF_SG_PARAMS_ALL;
541 ret = wl1271_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param));
542 if (ret < 0) {
543 wl1271_warning("failed to set sg config: %d", ret);
544 goto out;
547 out:
548 kfree(param);
549 return ret;
552 int wl1271_acx_cca_threshold(struct wl1271 *wl)
554 struct acx_energy_detection *detection;
555 int ret;
557 wl1271_debug(DEBUG_ACX, "acx cca threshold");
559 detection = kzalloc(sizeof(*detection), GFP_KERNEL);
560 if (!detection) {
561 ret = -ENOMEM;
562 goto out;
565 detection->rx_cca_threshold = cpu_to_le16(wl->conf.rx.rx_cca_threshold);
566 detection->tx_energy_detection = wl->conf.tx.tx_energy_detection;
568 ret = wl1271_cmd_configure(wl, ACX_CCA_THRESHOLD,
569 detection, sizeof(*detection));
570 if (ret < 0)
571 wl1271_warning("failed to set cca threshold: %d", ret);
573 out:
574 kfree(detection);
575 return ret;
578 int wl1271_acx_bcn_dtim_options(struct wl1271 *wl, struct wl12xx_vif *wlvif)
580 struct acx_beacon_broadcast *bb;
581 int ret;
583 wl1271_debug(DEBUG_ACX, "acx bcn dtim options");
585 bb = kzalloc(sizeof(*bb), GFP_KERNEL);
586 if (!bb) {
587 ret = -ENOMEM;
588 goto out;
591 bb->role_id = wlvif->role_id;
592 bb->beacon_rx_timeout = cpu_to_le16(wl->conf.conn.beacon_rx_timeout);
593 bb->broadcast_timeout = cpu_to_le16(wl->conf.conn.broadcast_timeout);
594 bb->rx_broadcast_in_ps = wl->conf.conn.rx_broadcast_in_ps;
595 bb->ps_poll_threshold = wl->conf.conn.ps_poll_threshold;
597 ret = wl1271_cmd_configure(wl, ACX_BCN_DTIM_OPTIONS, bb, sizeof(*bb));
598 if (ret < 0) {
599 wl1271_warning("failed to set rx config: %d", ret);
600 goto out;
603 out:
604 kfree(bb);
605 return ret;
608 int wl1271_acx_aid(struct wl1271 *wl, struct wl12xx_vif *wlvif, u16 aid)
610 struct acx_aid *acx_aid;
611 int ret;
613 wl1271_debug(DEBUG_ACX, "acx aid");
615 acx_aid = kzalloc(sizeof(*acx_aid), GFP_KERNEL);
616 if (!acx_aid) {
617 ret = -ENOMEM;
618 goto out;
621 acx_aid->role_id = wlvif->role_id;
622 acx_aid->aid = cpu_to_le16(aid);
624 ret = wl1271_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid));
625 if (ret < 0) {
626 wl1271_warning("failed to set aid: %d", ret);
627 goto out;
630 out:
631 kfree(acx_aid);
632 return ret;
635 int wl1271_acx_event_mbox_mask(struct wl1271 *wl, u32 event_mask)
637 struct acx_event_mask *mask;
638 int ret;
640 wl1271_debug(DEBUG_ACX, "acx event mbox mask");
642 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
643 if (!mask) {
644 ret = -ENOMEM;
645 goto out;
648 /* high event mask is unused */
649 mask->high_event_mask = cpu_to_le32(0xffffffff);
650 mask->event_mask = cpu_to_le32(event_mask);
652 ret = wl1271_cmd_configure(wl, ACX_EVENT_MBOX_MASK,
653 mask, sizeof(*mask));
654 if (ret < 0) {
655 wl1271_warning("failed to set acx_event_mbox_mask: %d", ret);
656 goto out;
659 out:
660 kfree(mask);
661 return ret;
664 int wl1271_acx_set_preamble(struct wl1271 *wl, struct wl12xx_vif *wlvif,
665 enum acx_preamble_type preamble)
667 struct acx_preamble *acx;
668 int ret;
670 wl1271_debug(DEBUG_ACX, "acx_set_preamble");
672 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
673 if (!acx) {
674 ret = -ENOMEM;
675 goto out;
678 acx->role_id = wlvif->role_id;
679 acx->preamble = preamble;
681 ret = wl1271_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx));
682 if (ret < 0) {
683 wl1271_warning("Setting of preamble failed: %d", ret);
684 goto out;
687 out:
688 kfree(acx);
689 return ret;
692 int wl1271_acx_cts_protect(struct wl1271 *wl, struct wl12xx_vif *wlvif,
693 enum acx_ctsprotect_type ctsprotect)
695 struct acx_ctsprotect *acx;
696 int ret;
698 wl1271_debug(DEBUG_ACX, "acx_set_ctsprotect");
700 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
701 if (!acx) {
702 ret = -ENOMEM;
703 goto out;
706 acx->role_id = wlvif->role_id;
707 acx->ctsprotect = ctsprotect;
709 ret = wl1271_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx));
710 if (ret < 0) {
711 wl1271_warning("Setting of ctsprotect failed: %d", ret);
712 goto out;
715 out:
716 kfree(acx);
717 return ret;
720 int wl1271_acx_statistics(struct wl1271 *wl, void *stats)
722 int ret;
724 wl1271_debug(DEBUG_ACX, "acx statistics");
726 ret = wl1271_cmd_interrogate(wl, ACX_STATISTICS, stats,
727 sizeof(struct acx_header),
728 wl->stats.fw_stats_len);
729 if (ret < 0) {
730 wl1271_warning("acx statistics failed: %d", ret);
731 return -ENOMEM;
734 return 0;
737 int wl1271_acx_sta_rate_policies(struct wl1271 *wl, struct wl12xx_vif *wlvif)
739 struct acx_rate_policy *acx;
740 struct conf_tx_rate_class *c = &wl->conf.tx.sta_rc_conf;
741 int ret = 0;
743 wl1271_debug(DEBUG_ACX, "acx rate policies");
745 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
747 if (!acx) {
748 ret = -ENOMEM;
749 goto out;
752 wl1271_debug(DEBUG_ACX, "basic_rate: 0x%x, full_rate: 0x%x",
753 wlvif->basic_rate, wlvif->rate_set);
755 /* configure one basic rate class */
756 acx->rate_policy_idx = cpu_to_le32(wlvif->sta.basic_rate_idx);
757 acx->rate_policy.enabled_rates = cpu_to_le32(wlvif->basic_rate);
758 acx->rate_policy.short_retry_limit = c->short_retry_limit;
759 acx->rate_policy.long_retry_limit = c->long_retry_limit;
760 acx->rate_policy.aflags = c->aflags;
762 ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
763 if (ret < 0) {
764 wl1271_warning("Setting of rate policies failed: %d", ret);
765 goto out;
768 /* configure one AP supported rate class */
769 acx->rate_policy_idx = cpu_to_le32(wlvif->sta.ap_rate_idx);
771 /* the AP policy is HW specific */
772 acx->rate_policy.enabled_rates =
773 cpu_to_le32(wlcore_hw_sta_get_ap_rate_mask(wl, wlvif));
774 acx->rate_policy.short_retry_limit = c->short_retry_limit;
775 acx->rate_policy.long_retry_limit = c->long_retry_limit;
776 acx->rate_policy.aflags = c->aflags;
778 ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
779 if (ret < 0) {
780 wl1271_warning("Setting of rate policies failed: %d", ret);
781 goto out;
785 * configure one rate class for basic p2p operations.
786 * (p2p packets should always go out with OFDM rates, even
787 * if we are currently connected to 11b AP)
789 acx->rate_policy_idx = cpu_to_le32(wlvif->sta.p2p_rate_idx);
790 acx->rate_policy.enabled_rates =
791 cpu_to_le32(CONF_TX_RATE_MASK_BASIC_P2P);
792 acx->rate_policy.short_retry_limit = c->short_retry_limit;
793 acx->rate_policy.long_retry_limit = c->long_retry_limit;
794 acx->rate_policy.aflags = c->aflags;
796 ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
797 if (ret < 0) {
798 wl1271_warning("Setting of rate policies failed: %d", ret);
799 goto out;
802 out:
803 kfree(acx);
804 return ret;
807 int wl1271_acx_ap_rate_policy(struct wl1271 *wl, struct conf_tx_rate_class *c,
808 u8 idx)
810 struct acx_rate_policy *acx;
811 int ret = 0;
813 wl1271_debug(DEBUG_ACX, "acx ap rate policy %d rates 0x%x",
814 idx, c->enabled_rates);
816 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
817 if (!acx) {
818 ret = -ENOMEM;
819 goto out;
822 acx->rate_policy.enabled_rates = cpu_to_le32(c->enabled_rates);
823 acx->rate_policy.short_retry_limit = c->short_retry_limit;
824 acx->rate_policy.long_retry_limit = c->long_retry_limit;
825 acx->rate_policy.aflags = c->aflags;
827 acx->rate_policy_idx = cpu_to_le32(idx);
829 ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
830 if (ret < 0) {
831 wl1271_warning("Setting of ap rate policy failed: %d", ret);
832 goto out;
835 out:
836 kfree(acx);
837 return ret;
840 int wl1271_acx_ac_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif,
841 u8 ac, u8 cw_min, u16 cw_max, u8 aifsn, u16 txop)
843 struct acx_ac_cfg *acx;
844 int ret = 0;
846 wl1271_debug(DEBUG_ACX, "acx ac cfg %d cw_ming %d cw_max %d "
847 "aifs %d txop %d", ac, cw_min, cw_max, aifsn, txop);
849 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
851 if (!acx) {
852 ret = -ENOMEM;
853 goto out;
856 acx->role_id = wlvif->role_id;
857 acx->ac = ac;
858 acx->cw_min = cw_min;
859 acx->cw_max = cpu_to_le16(cw_max);
860 acx->aifsn = aifsn;
861 acx->tx_op_limit = cpu_to_le16(txop);
863 ret = wl1271_cmd_configure(wl, ACX_AC_CFG, acx, sizeof(*acx));
864 if (ret < 0) {
865 wl1271_warning("acx ac cfg failed: %d", ret);
866 goto out;
869 out:
870 kfree(acx);
871 return ret;
874 int wl1271_acx_tid_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif,
875 u8 queue_id, u8 channel_type,
876 u8 tsid, u8 ps_scheme, u8 ack_policy,
877 u32 apsd_conf0, u32 apsd_conf1)
879 struct acx_tid_config *acx;
880 int ret = 0;
882 wl1271_debug(DEBUG_ACX, "acx tid config");
884 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
886 if (!acx) {
887 ret = -ENOMEM;
888 goto out;
891 acx->role_id = wlvif->role_id;
892 acx->queue_id = queue_id;
893 acx->channel_type = channel_type;
894 acx->tsid = tsid;
895 acx->ps_scheme = ps_scheme;
896 acx->ack_policy = ack_policy;
897 acx->apsd_conf[0] = cpu_to_le32(apsd_conf0);
898 acx->apsd_conf[1] = cpu_to_le32(apsd_conf1);
900 ret = wl1271_cmd_configure(wl, ACX_TID_CFG, acx, sizeof(*acx));
901 if (ret < 0) {
902 wl1271_warning("Setting of tid config failed: %d", ret);
903 goto out;
906 out:
907 kfree(acx);
908 return ret;
911 int wl1271_acx_frag_threshold(struct wl1271 *wl, u32 frag_threshold)
913 struct acx_frag_threshold *acx;
914 int ret = 0;
917 * If the fragmentation is not configured or out of range, use the
918 * default value.
920 if (frag_threshold > IEEE80211_MAX_FRAG_THRESHOLD)
921 frag_threshold = wl->conf.tx.frag_threshold;
923 wl1271_debug(DEBUG_ACX, "acx frag threshold: %d", frag_threshold);
925 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
927 if (!acx) {
928 ret = -ENOMEM;
929 goto out;
932 acx->frag_threshold = cpu_to_le16((u16)frag_threshold);
933 ret = wl1271_cmd_configure(wl, ACX_FRAG_CFG, acx, sizeof(*acx));
934 if (ret < 0) {
935 wl1271_warning("Setting of frag threshold failed: %d", ret);
936 goto out;
939 out:
940 kfree(acx);
941 return ret;
944 int wl1271_acx_tx_config_options(struct wl1271 *wl)
946 struct acx_tx_config_options *acx;
947 int ret = 0;
949 wl1271_debug(DEBUG_ACX, "acx tx config options");
951 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
953 if (!acx) {
954 ret = -ENOMEM;
955 goto out;
958 acx->tx_compl_timeout = cpu_to_le16(wl->conf.tx.tx_compl_timeout);
959 acx->tx_compl_threshold = cpu_to_le16(wl->conf.tx.tx_compl_threshold);
960 ret = wl1271_cmd_configure(wl, ACX_TX_CONFIG_OPT, acx, sizeof(*acx));
961 if (ret < 0) {
962 wl1271_warning("Setting of tx options failed: %d", ret);
963 goto out;
966 out:
967 kfree(acx);
968 return ret;
971 int wl12xx_acx_mem_cfg(struct wl1271 *wl)
973 struct wl12xx_acx_config_memory *mem_conf;
974 struct conf_memory_settings *mem;
975 int ret;
977 wl1271_debug(DEBUG_ACX, "wl1271 mem cfg");
979 mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL);
980 if (!mem_conf) {
981 ret = -ENOMEM;
982 goto out;
985 mem = &wl->conf.mem;
987 /* memory config */
988 mem_conf->num_stations = mem->num_stations;
989 mem_conf->rx_mem_block_num = mem->rx_block_num;
990 mem_conf->tx_min_mem_block_num = mem->tx_min_block_num;
991 mem_conf->num_ssid_profiles = mem->ssid_profiles;
992 mem_conf->total_tx_descriptors = cpu_to_le32(wl->num_tx_desc);
993 mem_conf->dyn_mem_enable = mem->dynamic_memory;
994 mem_conf->tx_free_req = mem->min_req_tx_blocks;
995 mem_conf->rx_free_req = mem->min_req_rx_blocks;
996 mem_conf->tx_min = mem->tx_min;
997 mem_conf->fwlog_blocks = wl->conf.fwlog.mem_blocks;
999 ret = wl1271_cmd_configure(wl, ACX_MEM_CFG, mem_conf,
1000 sizeof(*mem_conf));
1001 if (ret < 0) {
1002 wl1271_warning("wl1271 mem config failed: %d", ret);
1003 goto out;
1006 out:
1007 kfree(mem_conf);
1008 return ret;
1010 EXPORT_SYMBOL_GPL(wl12xx_acx_mem_cfg);
1012 int wl1271_acx_init_mem_config(struct wl1271 *wl)
1014 int ret;
1016 wl->target_mem_map = kzalloc(sizeof(struct wl1271_acx_mem_map),
1017 GFP_KERNEL);
1018 if (!wl->target_mem_map) {
1019 wl1271_error("couldn't allocate target memory map");
1020 return -ENOMEM;
1023 /* we now ask for the firmware built memory map */
1024 ret = wl1271_acx_mem_map(wl, (void *)wl->target_mem_map,
1025 sizeof(struct wl1271_acx_mem_map));
1026 if (ret < 0) {
1027 wl1271_error("couldn't retrieve firmware memory map");
1028 kfree(wl->target_mem_map);
1029 wl->target_mem_map = NULL;
1030 return ret;
1033 /* initialize TX block book keeping */
1034 wl->tx_blocks_available =
1035 le32_to_cpu(wl->target_mem_map->num_tx_mem_blocks);
1036 wl1271_debug(DEBUG_TX, "available tx blocks: %d",
1037 wl->tx_blocks_available);
1039 return 0;
1041 EXPORT_SYMBOL_GPL(wl1271_acx_init_mem_config);
1043 int wl1271_acx_init_rx_interrupt(struct wl1271 *wl)
1045 struct wl1271_acx_rx_config_opt *rx_conf;
1046 int ret;
1048 wl1271_debug(DEBUG_ACX, "wl1271 rx interrupt config");
1050 rx_conf = kzalloc(sizeof(*rx_conf), GFP_KERNEL);
1051 if (!rx_conf) {
1052 ret = -ENOMEM;
1053 goto out;
1056 rx_conf->threshold = cpu_to_le16(wl->conf.rx.irq_pkt_threshold);
1057 rx_conf->timeout = cpu_to_le16(wl->conf.rx.irq_timeout);
1058 rx_conf->mblk_threshold = cpu_to_le16(wl->conf.rx.irq_blk_threshold);
1059 rx_conf->queue_type = wl->conf.rx.queue_type;
1061 ret = wl1271_cmd_configure(wl, ACX_RX_CONFIG_OPT, rx_conf,
1062 sizeof(*rx_conf));
1063 if (ret < 0) {
1064 wl1271_warning("wl1271 rx config opt failed: %d", ret);
1065 goto out;
1068 out:
1069 kfree(rx_conf);
1070 return ret;
1073 int wl1271_acx_bet_enable(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1074 bool enable)
1076 struct wl1271_acx_bet_enable *acx = NULL;
1077 int ret = 0;
1079 wl1271_debug(DEBUG_ACX, "acx bet enable");
1081 if (enable && wl->conf.conn.bet_enable == CONF_BET_MODE_DISABLE)
1082 goto out;
1084 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1085 if (!acx) {
1086 ret = -ENOMEM;
1087 goto out;
1090 acx->role_id = wlvif->role_id;
1091 acx->enable = enable ? CONF_BET_MODE_ENABLE : CONF_BET_MODE_DISABLE;
1092 acx->max_consecutive = wl->conf.conn.bet_max_consecutive;
1094 ret = wl1271_cmd_configure(wl, ACX_BET_ENABLE, acx, sizeof(*acx));
1095 if (ret < 0) {
1096 wl1271_warning("acx bet enable failed: %d", ret);
1097 goto out;
1100 out:
1101 kfree(acx);
1102 return ret;
1105 int wl1271_acx_arp_ip_filter(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1106 u8 enable, __be32 address)
1108 struct wl1271_acx_arp_filter *acx;
1109 int ret;
1111 wl1271_debug(DEBUG_ACX, "acx arp ip filter, enable: %d", enable);
1113 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1114 if (!acx) {
1115 ret = -ENOMEM;
1116 goto out;
1119 acx->role_id = wlvif->role_id;
1120 acx->version = ACX_IPV4_VERSION;
1121 acx->enable = enable;
1123 if (enable)
1124 memcpy(acx->address, &address, ACX_IPV4_ADDR_SIZE);
1126 ret = wl1271_cmd_configure(wl, ACX_ARP_IP_FILTER,
1127 acx, sizeof(*acx));
1128 if (ret < 0) {
1129 wl1271_warning("failed to set arp ip filter: %d", ret);
1130 goto out;
1133 out:
1134 kfree(acx);
1135 return ret;
1138 int wl1271_acx_pm_config(struct wl1271 *wl)
1140 struct wl1271_acx_pm_config *acx = NULL;
1141 struct conf_pm_config_settings *c = &wl->conf.pm_config;
1142 int ret = 0;
1144 wl1271_debug(DEBUG_ACX, "acx pm config");
1146 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1147 if (!acx) {
1148 ret = -ENOMEM;
1149 goto out;
1152 acx->host_clk_settling_time = cpu_to_le32(c->host_clk_settling_time);
1153 acx->host_fast_wakeup_support = c->host_fast_wakeup_support;
1155 ret = wl1271_cmd_configure(wl, ACX_PM_CONFIG, acx, sizeof(*acx));
1156 if (ret < 0) {
1157 wl1271_warning("acx pm config failed: %d", ret);
1158 goto out;
1161 out:
1162 kfree(acx);
1163 return ret;
1165 EXPORT_SYMBOL_GPL(wl1271_acx_pm_config);
1167 int wl1271_acx_keep_alive_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1168 bool enable)
1170 struct wl1271_acx_keep_alive_mode *acx = NULL;
1171 int ret = 0;
1173 wl1271_debug(DEBUG_ACX, "acx keep alive mode: %d", enable);
1175 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1176 if (!acx) {
1177 ret = -ENOMEM;
1178 goto out;
1181 acx->role_id = wlvif->role_id;
1182 acx->enabled = enable;
1184 ret = wl1271_cmd_configure(wl, ACX_KEEP_ALIVE_MODE, acx, sizeof(*acx));
1185 if (ret < 0) {
1186 wl1271_warning("acx keep alive mode failed: %d", ret);
1187 goto out;
1190 out:
1191 kfree(acx);
1192 return ret;
1195 int wl1271_acx_keep_alive_config(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1196 u8 index, u8 tpl_valid)
1198 struct wl1271_acx_keep_alive_config *acx = NULL;
1199 int ret = 0;
1201 wl1271_debug(DEBUG_ACX, "acx keep alive config");
1203 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1204 if (!acx) {
1205 ret = -ENOMEM;
1206 goto out;
1209 acx->role_id = wlvif->role_id;
1210 acx->period = cpu_to_le32(wl->conf.conn.keep_alive_interval);
1211 acx->index = index;
1212 acx->tpl_validation = tpl_valid;
1213 acx->trigger = ACX_KEEP_ALIVE_NO_TX;
1215 ret = wl1271_cmd_configure(wl, ACX_SET_KEEP_ALIVE_CONFIG,
1216 acx, sizeof(*acx));
1217 if (ret < 0) {
1218 wl1271_warning("acx keep alive config failed: %d", ret);
1219 goto out;
1222 out:
1223 kfree(acx);
1224 return ret;
1227 int wl1271_acx_rssi_snr_trigger(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1228 bool enable, s16 thold, u8 hyst)
1230 struct wl1271_acx_rssi_snr_trigger *acx = NULL;
1231 int ret = 0;
1233 wl1271_debug(DEBUG_ACX, "acx rssi snr trigger");
1235 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1236 if (!acx) {
1237 ret = -ENOMEM;
1238 goto out;
1241 wlvif->last_rssi_event = -1;
1243 acx->role_id = wlvif->role_id;
1244 acx->pacing = cpu_to_le16(wl->conf.roam_trigger.trigger_pacing);
1245 acx->metric = WL1271_ACX_TRIG_METRIC_RSSI_BEACON;
1246 acx->type = WL1271_ACX_TRIG_TYPE_EDGE;
1247 if (enable)
1248 acx->enable = WL1271_ACX_TRIG_ENABLE;
1249 else
1250 acx->enable = WL1271_ACX_TRIG_DISABLE;
1252 acx->index = WL1271_ACX_TRIG_IDX_RSSI;
1253 acx->dir = WL1271_ACX_TRIG_DIR_BIDIR;
1254 acx->threshold = cpu_to_le16(thold);
1255 acx->hysteresis = hyst;
1257 ret = wl1271_cmd_configure(wl, ACX_RSSI_SNR_TRIGGER, acx, sizeof(*acx));
1258 if (ret < 0) {
1259 wl1271_warning("acx rssi snr trigger setting failed: %d", ret);
1260 goto out;
1263 out:
1264 kfree(acx);
1265 return ret;
1268 int wl1271_acx_rssi_snr_avg_weights(struct wl1271 *wl,
1269 struct wl12xx_vif *wlvif)
1271 struct wl1271_acx_rssi_snr_avg_weights *acx = NULL;
1272 struct conf_roam_trigger_settings *c = &wl->conf.roam_trigger;
1273 int ret = 0;
1275 wl1271_debug(DEBUG_ACX, "acx rssi snr avg weights");
1277 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1278 if (!acx) {
1279 ret = -ENOMEM;
1280 goto out;
1283 acx->role_id = wlvif->role_id;
1284 acx->rssi_beacon = c->avg_weight_rssi_beacon;
1285 acx->rssi_data = c->avg_weight_rssi_data;
1286 acx->snr_beacon = c->avg_weight_snr_beacon;
1287 acx->snr_data = c->avg_weight_snr_data;
1289 ret = wl1271_cmd_configure(wl, ACX_RSSI_SNR_WEIGHTS, acx, sizeof(*acx));
1290 if (ret < 0) {
1291 wl1271_warning("acx rssi snr trigger weights failed: %d", ret);
1292 goto out;
1295 out:
1296 kfree(acx);
1297 return ret;
1300 int wl1271_acx_set_ht_capabilities(struct wl1271 *wl,
1301 struct ieee80211_sta_ht_cap *ht_cap,
1302 bool allow_ht_operation, u8 hlid)
1304 struct wl1271_acx_ht_capabilities *acx;
1305 int ret = 0;
1306 u32 ht_capabilites = 0;
1308 wl1271_debug(DEBUG_ACX, "acx ht capabilities setting "
1309 "sta supp: %d sta cap: %d", ht_cap->ht_supported,
1310 ht_cap->cap);
1312 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1313 if (!acx) {
1314 ret = -ENOMEM;
1315 goto out;
1318 if (allow_ht_operation && ht_cap->ht_supported) {
1319 /* no need to translate capabilities - use the spec values */
1320 ht_capabilites = ht_cap->cap;
1323 * this bit is not employed by the spec but only by FW to
1324 * indicate peer HT support
1326 ht_capabilites |= WL12XX_HT_CAP_HT_OPERATION;
1328 /* get data from A-MPDU parameters field */
1329 acx->ampdu_max_length = ht_cap->ampdu_factor;
1330 acx->ampdu_min_spacing = ht_cap->ampdu_density;
1333 acx->hlid = hlid;
1334 acx->ht_capabilites = cpu_to_le32(ht_capabilites);
1336 ret = wl1271_cmd_configure(wl, ACX_PEER_HT_CAP, acx, sizeof(*acx));
1337 if (ret < 0) {
1338 wl1271_warning("acx ht capabilities setting failed: %d", ret);
1339 goto out;
1342 out:
1343 kfree(acx);
1344 return ret;
1346 EXPORT_SYMBOL_GPL(wl1271_acx_set_ht_capabilities);
1349 int wl1271_acx_set_ht_information(struct wl1271 *wl,
1350 struct wl12xx_vif *wlvif,
1351 u16 ht_operation_mode)
1353 struct wl1271_acx_ht_information *acx;
1354 int ret = 0;
1356 wl1271_debug(DEBUG_ACX, "acx ht information setting");
1358 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1359 if (!acx) {
1360 ret = -ENOMEM;
1361 goto out;
1364 acx->role_id = wlvif->role_id;
1365 acx->ht_protection =
1366 (u8)(ht_operation_mode & IEEE80211_HT_OP_MODE_PROTECTION);
1367 acx->rifs_mode = 0;
1368 acx->gf_protection =
1369 !!(ht_operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
1370 acx->ht_tx_burst_limit = 0;
1371 acx->dual_cts_protection = 0;
1373 ret = wl1271_cmd_configure(wl, ACX_HT_BSS_OPERATION, acx, sizeof(*acx));
1375 if (ret < 0) {
1376 wl1271_warning("acx ht information setting failed: %d", ret);
1377 goto out;
1380 out:
1381 kfree(acx);
1382 return ret;
1385 /* Configure BA session initiator/receiver parameters setting in the FW. */
1386 int wl12xx_acx_set_ba_initiator_policy(struct wl1271 *wl,
1387 struct wl12xx_vif *wlvif)
1389 struct wl1271_acx_ba_initiator_policy *acx;
1390 int ret;
1392 wl1271_debug(DEBUG_ACX, "acx ba initiator policy");
1394 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1395 if (!acx) {
1396 ret = -ENOMEM;
1397 goto out;
1400 /* set for the current role */
1401 acx->role_id = wlvif->role_id;
1402 acx->tid_bitmap = wl->conf.ht.tx_ba_tid_bitmap;
1403 acx->win_size = wl->conf.ht.tx_ba_win_size;
1404 acx->inactivity_timeout = wl->conf.ht.inactivity_timeout;
1406 ret = wl1271_cmd_configure(wl,
1407 ACX_BA_SESSION_INIT_POLICY,
1408 acx,
1409 sizeof(*acx));
1410 if (ret < 0) {
1411 wl1271_warning("acx ba initiator policy failed: %d", ret);
1412 goto out;
1415 out:
1416 kfree(acx);
1417 return ret;
1420 /* setup BA session receiver setting in the FW. */
1421 int wl12xx_acx_set_ba_receiver_session(struct wl1271 *wl, u8 tid_index,
1422 u16 ssn, bool enable, u8 peer_hlid,
1423 u8 win_size)
1425 struct wl1271_acx_ba_receiver_setup *acx;
1426 int ret;
1428 wl1271_debug(DEBUG_ACX, "acx ba receiver session setting");
1430 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1431 if (!acx) {
1432 ret = -ENOMEM;
1433 goto out;
1436 acx->hlid = peer_hlid;
1437 acx->tid = tid_index;
1438 acx->enable = enable;
1439 acx->win_size = win_size;
1440 acx->ssn = ssn;
1442 ret = wlcore_cmd_configure_failsafe(wl, ACX_BA_SESSION_RX_SETUP, acx,
1443 sizeof(*acx),
1444 BIT(CMD_STATUS_NO_RX_BA_SESSION));
1445 if (ret < 0) {
1446 wl1271_warning("acx ba receiver session failed: %d", ret);
1447 goto out;
1450 /* sometimes we can't start the session */
1451 if (ret == CMD_STATUS_NO_RX_BA_SESSION) {
1452 wl1271_warning("no fw rx ba on tid %d", tid_index);
1453 ret = -EBUSY;
1454 goto out;
1457 ret = 0;
1458 out:
1459 kfree(acx);
1460 return ret;
1463 int wl12xx_acx_tsf_info(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1464 u64 *mactime)
1466 struct wl12xx_acx_fw_tsf_information *tsf_info;
1467 int ret;
1469 tsf_info = kzalloc(sizeof(*tsf_info), GFP_KERNEL);
1470 if (!tsf_info) {
1471 ret = -ENOMEM;
1472 goto out;
1475 tsf_info->role_id = wlvif->role_id;
1477 ret = wl1271_cmd_interrogate(wl, ACX_TSF_INFO, tsf_info,
1478 sizeof(struct acx_header), sizeof(*tsf_info));
1479 if (ret < 0) {
1480 wl1271_warning("acx tsf info interrogate failed");
1481 goto out;
1484 *mactime = le32_to_cpu(tsf_info->current_tsf_low) |
1485 ((u64) le32_to_cpu(tsf_info->current_tsf_high) << 32);
1487 out:
1488 kfree(tsf_info);
1489 return ret;
1492 int wl1271_acx_ps_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1493 bool enable)
1495 struct wl1271_acx_ps_rx_streaming *rx_streaming;
1496 u32 conf_queues, enable_queues;
1497 int i, ret = 0;
1499 wl1271_debug(DEBUG_ACX, "acx ps rx streaming");
1501 rx_streaming = kzalloc(sizeof(*rx_streaming), GFP_KERNEL);
1502 if (!rx_streaming) {
1503 ret = -ENOMEM;
1504 goto out;
1507 conf_queues = wl->conf.rx_streaming.queues;
1508 if (enable)
1509 enable_queues = conf_queues;
1510 else
1511 enable_queues = 0;
1513 for (i = 0; i < 8; i++) {
1515 * Skip non-changed queues, to avoid redundant acxs.
1516 * this check assumes conf.rx_streaming.queues can't
1517 * be changed while rx_streaming is enabled.
1519 if (!(conf_queues & BIT(i)))
1520 continue;
1522 rx_streaming->role_id = wlvif->role_id;
1523 rx_streaming->tid = i;
1524 rx_streaming->enable = enable_queues & BIT(i);
1525 rx_streaming->period = wl->conf.rx_streaming.interval;
1526 rx_streaming->timeout = wl->conf.rx_streaming.interval;
1528 ret = wl1271_cmd_configure(wl, ACX_PS_RX_STREAMING,
1529 rx_streaming,
1530 sizeof(*rx_streaming));
1531 if (ret < 0) {
1532 wl1271_warning("acx ps rx streaming failed: %d", ret);
1533 goto out;
1536 out:
1537 kfree(rx_streaming);
1538 return ret;
1541 int wl1271_acx_ap_max_tx_retry(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1543 struct wl1271_acx_ap_max_tx_retry *acx = NULL;
1544 int ret;
1546 wl1271_debug(DEBUG_ACX, "acx ap max tx retry");
1548 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1549 if (!acx)
1550 return -ENOMEM;
1552 acx->role_id = wlvif->role_id;
1553 acx->max_tx_retry = cpu_to_le16(wl->conf.tx.max_tx_retries);
1555 ret = wl1271_cmd_configure(wl, ACX_MAX_TX_FAILURE, acx, sizeof(*acx));
1556 if (ret < 0) {
1557 wl1271_warning("acx ap max tx retry failed: %d", ret);
1558 goto out;
1561 out:
1562 kfree(acx);
1563 return ret;
1566 int wl12xx_acx_config_ps(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1568 struct wl1271_acx_config_ps *config_ps;
1569 int ret;
1571 wl1271_debug(DEBUG_ACX, "acx config ps");
1573 config_ps = kzalloc(sizeof(*config_ps), GFP_KERNEL);
1574 if (!config_ps) {
1575 ret = -ENOMEM;
1576 goto out;
1579 config_ps->exit_retries = wl->conf.conn.psm_exit_retries;
1580 config_ps->enter_retries = wl->conf.conn.psm_entry_retries;
1581 config_ps->null_data_rate = cpu_to_le32(wlvif->basic_rate);
1583 ret = wl1271_cmd_configure(wl, ACX_CONFIG_PS, config_ps,
1584 sizeof(*config_ps));
1586 if (ret < 0) {
1587 wl1271_warning("acx config ps failed: %d", ret);
1588 goto out;
1591 out:
1592 kfree(config_ps);
1593 return ret;
1596 int wl1271_acx_set_inconnection_sta(struct wl1271 *wl,
1597 struct wl12xx_vif *wlvif, u8 *addr)
1599 struct wl1271_acx_inconnection_sta *acx = NULL;
1600 int ret;
1602 wl1271_debug(DEBUG_ACX, "acx set inconnaction sta %pM", addr);
1604 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1605 if (!acx)
1606 return -ENOMEM;
1608 memcpy(acx->addr, addr, ETH_ALEN);
1609 acx->role_id = wlvif->role_id;
1611 ret = wl1271_cmd_configure(wl, ACX_UPDATE_INCONNECTION_STA_LIST,
1612 acx, sizeof(*acx));
1613 if (ret < 0) {
1614 wl1271_warning("acx set inconnaction sta failed: %d", ret);
1615 goto out;
1618 out:
1619 kfree(acx);
1620 return ret;
1623 int wl1271_acx_fm_coex(struct wl1271 *wl)
1625 struct wl1271_acx_fm_coex *acx;
1626 int ret;
1628 wl1271_debug(DEBUG_ACX, "acx fm coex setting");
1630 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1631 if (!acx) {
1632 ret = -ENOMEM;
1633 goto out;
1636 acx->enable = wl->conf.fm_coex.enable;
1637 acx->swallow_period = wl->conf.fm_coex.swallow_period;
1638 acx->n_divider_fref_set_1 = wl->conf.fm_coex.n_divider_fref_set_1;
1639 acx->n_divider_fref_set_2 = wl->conf.fm_coex.n_divider_fref_set_2;
1640 acx->m_divider_fref_set_1 =
1641 cpu_to_le16(wl->conf.fm_coex.m_divider_fref_set_1);
1642 acx->m_divider_fref_set_2 =
1643 cpu_to_le16(wl->conf.fm_coex.m_divider_fref_set_2);
1644 acx->coex_pll_stabilization_time =
1645 cpu_to_le32(wl->conf.fm_coex.coex_pll_stabilization_time);
1646 acx->ldo_stabilization_time =
1647 cpu_to_le16(wl->conf.fm_coex.ldo_stabilization_time);
1648 acx->fm_disturbed_band_margin =
1649 wl->conf.fm_coex.fm_disturbed_band_margin;
1650 acx->swallow_clk_diff = wl->conf.fm_coex.swallow_clk_diff;
1652 ret = wl1271_cmd_configure(wl, ACX_FM_COEX_CFG, acx, sizeof(*acx));
1653 if (ret < 0) {
1654 wl1271_warning("acx fm coex setting failed: %d", ret);
1655 goto out;
1658 out:
1659 kfree(acx);
1660 return ret;
1663 int wl12xx_acx_set_rate_mgmt_params(struct wl1271 *wl)
1665 struct wl12xx_acx_set_rate_mgmt_params *acx = NULL;
1666 struct conf_rate_policy_settings *conf = &wl->conf.rate;
1667 int ret;
1669 wl1271_debug(DEBUG_ACX, "acx set rate mgmt params");
1671 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1672 if (!acx)
1673 return -ENOMEM;
1675 acx->index = ACX_RATE_MGMT_ALL_PARAMS;
1676 acx->rate_retry_score = cpu_to_le16(conf->rate_retry_score);
1677 acx->per_add = cpu_to_le16(conf->per_add);
1678 acx->per_th1 = cpu_to_le16(conf->per_th1);
1679 acx->per_th2 = cpu_to_le16(conf->per_th2);
1680 acx->max_per = cpu_to_le16(conf->max_per);
1681 acx->inverse_curiosity_factor = conf->inverse_curiosity_factor;
1682 acx->tx_fail_low_th = conf->tx_fail_low_th;
1683 acx->tx_fail_high_th = conf->tx_fail_high_th;
1684 acx->per_alpha_shift = conf->per_alpha_shift;
1685 acx->per_add_shift = conf->per_add_shift;
1686 acx->per_beta1_shift = conf->per_beta1_shift;
1687 acx->per_beta2_shift = conf->per_beta2_shift;
1688 acx->rate_check_up = conf->rate_check_up;
1689 acx->rate_check_down = conf->rate_check_down;
1690 memcpy(acx->rate_retry_policy, conf->rate_retry_policy,
1691 sizeof(acx->rate_retry_policy));
1693 ret = wl1271_cmd_configure(wl, ACX_SET_RATE_MGMT_PARAMS,
1694 acx, sizeof(*acx));
1695 if (ret < 0) {
1696 wl1271_warning("acx set rate mgmt params failed: %d", ret);
1697 goto out;
1700 out:
1701 kfree(acx);
1702 return ret;
1705 int wl12xx_acx_config_hangover(struct wl1271 *wl)
1707 struct wl12xx_acx_config_hangover *acx;
1708 struct conf_hangover_settings *conf = &wl->conf.hangover;
1709 int ret;
1711 wl1271_debug(DEBUG_ACX, "acx config hangover");
1713 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1714 if (!acx) {
1715 ret = -ENOMEM;
1716 goto out;
1719 acx->recover_time = cpu_to_le32(conf->recover_time);
1720 acx->hangover_period = conf->hangover_period;
1721 acx->dynamic_mode = conf->dynamic_mode;
1722 acx->early_termination_mode = conf->early_termination_mode;
1723 acx->max_period = conf->max_period;
1724 acx->min_period = conf->min_period;
1725 acx->increase_delta = conf->increase_delta;
1726 acx->decrease_delta = conf->decrease_delta;
1727 acx->quiet_time = conf->quiet_time;
1728 acx->increase_time = conf->increase_time;
1729 acx->window_size = conf->window_size;
1731 ret = wl1271_cmd_configure(wl, ACX_CONFIG_HANGOVER, acx,
1732 sizeof(*acx));
1734 if (ret < 0) {
1735 wl1271_warning("acx config hangover failed: %d", ret);
1736 goto out;
1739 out:
1740 kfree(acx);
1741 return ret;
1745 int wlcore_acx_average_rssi(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1746 s8 *avg_rssi)
1748 struct acx_roaming_stats *acx;
1749 int ret = 0;
1751 wl1271_debug(DEBUG_ACX, "acx roaming statistics");
1753 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1754 if (!acx) {
1755 ret = -ENOMEM;
1756 goto out;
1759 acx->role_id = wlvif->role_id;
1760 ret = wl1271_cmd_interrogate(wl, ACX_ROAMING_STATISTICS_TBL,
1761 acx, sizeof(*acx), sizeof(*acx));
1762 if (ret < 0) {
1763 wl1271_warning("acx roaming statistics failed: %d", ret);
1764 ret = -ENOMEM;
1765 goto out;
1768 *avg_rssi = acx->rssi_beacon;
1769 out:
1770 kfree(acx);
1771 return ret;
1774 #ifdef CONFIG_PM
1775 /* Set the global behaviour of RX filters - On/Off + default action */
1776 int wl1271_acx_default_rx_filter_enable(struct wl1271 *wl, bool enable,
1777 enum rx_filter_action action)
1779 struct acx_default_rx_filter *acx;
1780 int ret;
1782 wl1271_debug(DEBUG_ACX, "acx default rx filter en: %d act: %d",
1783 enable, action);
1785 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1786 if (!acx)
1787 return -ENOMEM;
1789 acx->enable = enable;
1790 acx->default_action = action;
1792 ret = wl1271_cmd_configure(wl, ACX_ENABLE_RX_DATA_FILTER, acx,
1793 sizeof(*acx));
1794 if (ret < 0) {
1795 wl1271_warning("acx default rx filter enable failed: %d", ret);
1796 goto out;
1799 out:
1800 kfree(acx);
1801 return ret;
1804 /* Configure or disable a specific RX filter pattern */
1805 int wl1271_acx_set_rx_filter(struct wl1271 *wl, u8 index, bool enable,
1806 struct wl12xx_rx_filter *filter)
1808 struct acx_rx_filter_cfg *acx;
1809 int fields_size = 0;
1810 int acx_size;
1811 int ret;
1813 WARN_ON(enable && !filter);
1814 WARN_ON(index >= WL1271_MAX_RX_FILTERS);
1816 wl1271_debug(DEBUG_ACX,
1817 "acx set rx filter idx: %d enable: %d filter: %p",
1818 index, enable, filter);
1820 if (enable) {
1821 fields_size = wl1271_rx_filter_get_fields_size(filter);
1823 wl1271_debug(DEBUG_ACX, "act: %d num_fields: %d field_size: %d",
1824 filter->action, filter->num_fields, fields_size);
1827 acx_size = ALIGN(sizeof(*acx) + fields_size, 4);
1828 acx = kzalloc(acx_size, GFP_KERNEL);
1830 if (!acx)
1831 return -ENOMEM;
1833 acx->enable = enable;
1834 acx->index = index;
1836 if (enable) {
1837 acx->num_fields = filter->num_fields;
1838 acx->action = filter->action;
1839 wl1271_rx_filter_flatten_fields(filter, acx->fields);
1842 wl1271_dump(DEBUG_ACX, "RX_FILTER: ", acx, acx_size);
1844 ret = wl1271_cmd_configure(wl, ACX_SET_RX_DATA_FILTER, acx, acx_size);
1845 if (ret < 0) {
1846 wl1271_warning("setting rx filter failed: %d", ret);
1847 goto out;
1850 out:
1851 kfree(acx);
1852 return ret;
1854 #endif /* CONFIG_PM */