wl1271: Enable smart reflex
[linux-2.6/btrfs-unstable.git] / drivers / net / wireless / wl12xx / wl1271_acx.c
blob6c29890022186708a46fcaba5ffbcc0e5c1ba33f
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 "wl1271_acx.h"
26 #include <linux/module.h>
27 #include <linux/platform_device.h>
28 #include <linux/crc7.h>
29 #include <linux/spi/spi.h>
31 #include "wl1271.h"
32 #include "wl12xx_80211.h"
33 #include "wl1271_reg.h"
34 #include "wl1271_spi.h"
35 #include "wl1271_ps.h"
37 int wl1271_acx_wake_up_conditions(struct wl1271 *wl, u8 wake_up_event,
38 u8 listen_interval)
40 struct acx_wake_up_condition *wake_up;
41 int ret;
43 wl1271_debug(DEBUG_ACX, "acx wake up conditions");
45 wake_up = kzalloc(sizeof(*wake_up), GFP_KERNEL);
46 if (!wake_up) {
47 ret = -ENOMEM;
48 goto out;
51 wake_up->wake_up_event = wake_up_event;
52 wake_up->listen_interval = listen_interval;
54 ret = wl1271_cmd_configure(wl, ACX_WAKE_UP_CONDITIONS,
55 wake_up, sizeof(*wake_up));
56 if (ret < 0) {
57 wl1271_warning("could not set wake up conditions: %d", ret);
58 goto out;
61 out:
62 kfree(wake_up);
63 return ret;
66 int wl1271_acx_sleep_auth(struct wl1271 *wl, u8 sleep_auth)
68 struct acx_sleep_auth *auth;
69 int ret;
71 wl1271_debug(DEBUG_ACX, "acx sleep auth");
73 auth = kzalloc(sizeof(*auth), GFP_KERNEL);
74 if (!auth) {
75 ret = -ENOMEM;
76 goto out;
79 auth->sleep_auth = sleep_auth;
81 ret = wl1271_cmd_configure(wl, ACX_SLEEP_AUTH, auth, sizeof(*auth));
82 if (ret < 0)
83 return ret;
85 out:
86 kfree(auth);
87 return ret;
90 int wl1271_acx_fw_version(struct wl1271 *wl, char *buf, size_t len)
92 struct acx_revision *rev;
93 int ret;
95 wl1271_debug(DEBUG_ACX, "acx fw rev");
97 rev = kzalloc(sizeof(*rev), GFP_KERNEL);
98 if (!rev) {
99 ret = -ENOMEM;
100 goto out;
103 ret = wl1271_cmd_interrogate(wl, ACX_FW_REV, rev, sizeof(*rev));
104 if (ret < 0) {
105 wl1271_warning("ACX_FW_REV interrogate failed");
106 goto out;
109 /* be careful with the buffer sizes */
110 strncpy(buf, rev->fw_version, min(len, sizeof(rev->fw_version)));
113 * if the firmware version string is exactly
114 * sizeof(rev->fw_version) long or fw_len is less than
115 * sizeof(rev->fw_version) it won't be null terminated
117 buf[min(len, sizeof(rev->fw_version)) - 1] = '\0';
119 out:
120 kfree(rev);
121 return ret;
124 int wl1271_acx_tx_power(struct wl1271 *wl, int power)
126 struct acx_current_tx_power *acx;
127 int ret;
129 wl1271_debug(DEBUG_ACX, "acx dot11_cur_tx_pwr");
131 if (power < 0 || power > 25)
132 return -EINVAL;
134 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
135 if (!acx) {
136 ret = -ENOMEM;
137 goto out;
141 * FIXME: This is a workaround needed while we don't the correct
142 * calibration, to avoid distortions
144 /* acx->current_tx_power = power * 10; */
145 acx->current_tx_power = 70;
147 ret = wl1271_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx));
148 if (ret < 0) {
149 wl1271_warning("configure of tx power failed: %d", ret);
150 goto out;
153 out:
154 kfree(acx);
155 return ret;
158 int wl1271_acx_feature_cfg(struct wl1271 *wl)
160 struct acx_feature_config *feature;
161 int ret;
163 wl1271_debug(DEBUG_ACX, "acx feature cfg");
165 feature = kzalloc(sizeof(*feature), GFP_KERNEL);
166 if (!feature) {
167 ret = -ENOMEM;
168 goto out;
171 /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */
172 feature->data_flow_options = 0;
173 feature->options = 0;
175 ret = wl1271_cmd_configure(wl, ACX_FEATURE_CFG,
176 feature, sizeof(*feature));
177 if (ret < 0) {
178 wl1271_error("Couldnt set HW encryption");
179 goto out;
182 out:
183 kfree(feature);
184 return ret;
187 int wl1271_acx_mem_map(struct wl1271 *wl, struct acx_header *mem_map,
188 size_t len)
190 int ret;
192 wl1271_debug(DEBUG_ACX, "acx mem map");
194 ret = wl1271_cmd_interrogate(wl, ACX_MEM_MAP, mem_map, len);
195 if (ret < 0)
196 return ret;
198 return 0;
201 int wl1271_acx_rx_msdu_life_time(struct wl1271 *wl, u32 life_time)
203 struct acx_rx_msdu_lifetime *acx;
204 int ret;
206 wl1271_debug(DEBUG_ACX, "acx rx msdu life time");
208 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
209 if (!acx) {
210 ret = -ENOMEM;
211 goto out;
214 acx->lifetime = life_time;
215 ret = wl1271_cmd_configure(wl, DOT11_RX_MSDU_LIFE_TIME,
216 acx, sizeof(*acx));
217 if (ret < 0) {
218 wl1271_warning("failed to set rx msdu life time: %d", ret);
219 goto out;
222 out:
223 kfree(acx);
224 return ret;
227 int wl1271_acx_rx_config(struct wl1271 *wl, u32 config, u32 filter)
229 struct acx_rx_config *rx_config;
230 int ret;
232 wl1271_debug(DEBUG_ACX, "acx rx config");
234 rx_config = kzalloc(sizeof(*rx_config), GFP_KERNEL);
235 if (!rx_config) {
236 ret = -ENOMEM;
237 goto out;
240 rx_config->config_options = config;
241 rx_config->filter_options = filter;
243 ret = wl1271_cmd_configure(wl, ACX_RX_CFG,
244 rx_config, sizeof(*rx_config));
245 if (ret < 0) {
246 wl1271_warning("failed to set rx config: %d", ret);
247 goto out;
250 out:
251 kfree(rx_config);
252 return ret;
255 int wl1271_acx_pd_threshold(struct wl1271 *wl)
257 struct acx_packet_detection *pd;
258 int ret;
260 wl1271_debug(DEBUG_ACX, "acx data pd threshold");
262 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
263 if (!pd) {
264 ret = -ENOMEM;
265 goto out;
268 /* FIXME: threshold value not set */
270 ret = wl1271_cmd_configure(wl, ACX_PD_THRESHOLD, pd, sizeof(*pd));
271 if (ret < 0) {
272 wl1271_warning("failed to set pd threshold: %d", ret);
273 goto out;
276 out:
277 kfree(pd);
278 return 0;
281 int wl1271_acx_slot(struct wl1271 *wl, enum acx_slot_type slot_time)
283 struct acx_slot *slot;
284 int ret;
286 wl1271_debug(DEBUG_ACX, "acx slot");
288 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
289 if (!slot) {
290 ret = -ENOMEM;
291 goto out;
294 slot->wone_index = STATION_WONE_INDEX;
295 slot->slot_time = slot_time;
297 ret = wl1271_cmd_configure(wl, ACX_SLOT, slot, sizeof(*slot));
298 if (ret < 0) {
299 wl1271_warning("failed to set slot time: %d", ret);
300 goto out;
303 out:
304 kfree(slot);
305 return ret;
308 int wl1271_acx_group_address_tbl(struct wl1271 *wl, bool enable,
309 void *mc_list, u32 mc_list_len)
311 struct acx_dot11_grp_addr_tbl *acx;
312 int ret;
314 wl1271_debug(DEBUG_ACX, "acx group address tbl");
316 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
317 if (!acx) {
318 ret = -ENOMEM;
319 goto out;
322 /* MAC filtering */
323 acx->enabled = enable;
324 acx->num_groups = mc_list_len;
325 memcpy(acx->mac_table, mc_list, mc_list_len * ETH_ALEN);
327 ret = wl1271_cmd_configure(wl, DOT11_GROUP_ADDRESS_TBL,
328 acx, sizeof(*acx));
329 if (ret < 0) {
330 wl1271_warning("failed to set group addr table: %d", ret);
331 goto out;
334 out:
335 kfree(acx);
336 return ret;
339 int wl1271_acx_service_period_timeout(struct wl1271 *wl)
341 struct acx_rx_timeout *rx_timeout;
342 int ret;
344 rx_timeout = kzalloc(sizeof(*rx_timeout), GFP_KERNEL);
345 if (!rx_timeout) {
346 ret = -ENOMEM;
347 goto out;
350 wl1271_debug(DEBUG_ACX, "acx service period timeout");
352 rx_timeout->ps_poll_timeout = RX_TIMEOUT_PS_POLL_DEF;
353 rx_timeout->upsd_timeout = RX_TIMEOUT_UPSD_DEF;
355 ret = wl1271_cmd_configure(wl, ACX_SERVICE_PERIOD_TIMEOUT,
356 rx_timeout, sizeof(*rx_timeout));
357 if (ret < 0) {
358 wl1271_warning("failed to set service period timeout: %d",
359 ret);
360 goto out;
363 out:
364 kfree(rx_timeout);
365 return ret;
368 int wl1271_acx_rts_threshold(struct wl1271 *wl, u16 rts_threshold)
370 struct acx_rts_threshold *rts;
371 int ret;
373 wl1271_debug(DEBUG_ACX, "acx rts threshold");
375 rts = kzalloc(sizeof(*rts), GFP_KERNEL);
376 if (!rts) {
377 ret = -ENOMEM;
378 goto out;
381 rts->threshold = rts_threshold;
383 ret = wl1271_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts));
384 if (ret < 0) {
385 wl1271_warning("failed to set rts threshold: %d", ret);
386 goto out;
389 out:
390 kfree(rts);
391 return ret;
394 int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, bool enable_filter)
396 struct acx_beacon_filter_option *beacon_filter;
397 int ret;
399 wl1271_debug(DEBUG_ACX, "acx beacon filter opt");
401 beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL);
402 if (!beacon_filter) {
403 ret = -ENOMEM;
404 goto out;
407 beacon_filter->enable = enable_filter;
408 beacon_filter->max_num_beacons = 0;
410 ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_OPT,
411 beacon_filter, sizeof(*beacon_filter));
412 if (ret < 0) {
413 wl1271_warning("failed to set beacon filter opt: %d", ret);
414 goto out;
417 out:
418 kfree(beacon_filter);
419 return ret;
422 int wl1271_acx_beacon_filter_table(struct wl1271 *wl)
424 struct acx_beacon_filter_ie_table *ie_table;
425 int idx = 0;
426 int ret;
428 wl1271_debug(DEBUG_ACX, "acx beacon filter table");
430 ie_table = kzalloc(sizeof(*ie_table), GFP_KERNEL);
431 if (!ie_table) {
432 ret = -ENOMEM;
433 goto out;
436 /* configure default beacon pass-through rules */
437 ie_table->num_ie = 1;
438 ie_table->table[idx++] = BEACON_FILTER_IE_ID_CHANNEL_SWITCH_ANN;
439 ie_table->table[idx++] = BEACON_RULE_PASS_ON_APPEARANCE;
441 ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_TABLE,
442 ie_table, sizeof(*ie_table));
443 if (ret < 0) {
444 wl1271_warning("failed to set beacon filter table: %d", ret);
445 goto out;
448 out:
449 kfree(ie_table);
450 return ret;
453 int wl1271_acx_conn_monit_params(struct wl1271 *wl)
455 struct acx_conn_monit_params *acx;
456 int ret;
458 wl1271_debug(DEBUG_ACX, "acx connection monitor parameters");
460 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
461 if (!acx) {
462 ret = -ENOMEM;
463 goto out;
466 acx->synch_fail_thold = SYNCH_FAIL_DEFAULT_THRESHOLD;
467 acx->bss_lose_timeout = NO_BEACON_DEFAULT_TIMEOUT;
469 ret = wl1271_cmd_configure(wl, ACX_CONN_MONIT_PARAMS,
470 acx, sizeof(*acx));
471 if (ret < 0) {
472 wl1271_warning("failed to set connection monitor "
473 "parameters: %d", ret);
474 goto out;
477 out:
478 kfree(acx);
479 return ret;
483 int wl1271_acx_sg_enable(struct wl1271 *wl)
485 struct acx_bt_wlan_coex *pta;
486 int ret;
488 wl1271_debug(DEBUG_ACX, "acx sg enable");
490 pta = kzalloc(sizeof(*pta), GFP_KERNEL);
491 if (!pta) {
492 ret = -ENOMEM;
493 goto out;
496 pta->enable = SG_ENABLE;
498 ret = wl1271_cmd_configure(wl, ACX_SG_ENABLE, pta, sizeof(*pta));
499 if (ret < 0) {
500 wl1271_warning("failed to set softgemini enable: %d", ret);
501 goto out;
504 out:
505 kfree(pta);
506 return ret;
509 int wl1271_acx_sg_cfg(struct wl1271 *wl)
511 struct acx_bt_wlan_coex_param *param;
512 int ret;
514 wl1271_debug(DEBUG_ACX, "acx sg cfg");
516 param = kzalloc(sizeof(*param), GFP_KERNEL);
517 if (!param) {
518 ret = -ENOMEM;
519 goto out;
522 /* BT-WLAN coext parameters */
523 param->min_rate = RATE_INDEX_24MBPS;
524 param->bt_hp_max_time = PTA_BT_HP_MAXTIME_DEF;
525 param->wlan_hp_max_time = PTA_WLAN_HP_MAX_TIME_DEF;
526 param->sense_disable_timer = PTA_SENSE_DISABLE_TIMER_DEF;
527 param->rx_time_bt_hp = PTA_PROTECTIVE_RX_TIME_DEF;
528 param->tx_time_bt_hp = PTA_PROTECTIVE_TX_TIME_DEF;
529 param->rx_time_bt_hp_fast = PTA_PROTECTIVE_RX_TIME_FAST_DEF;
530 param->tx_time_bt_hp_fast = PTA_PROTECTIVE_TX_TIME_FAST_DEF;
531 param->wlan_cycle_fast = PTA_CYCLE_TIME_FAST_DEF;
532 param->bt_anti_starvation_period = PTA_ANTI_STARVE_PERIOD_DEF;
533 param->next_bt_lp_packet = PTA_TIMEOUT_NEXT_BT_LP_PACKET_DEF;
534 param->wake_up_beacon = PTA_TIME_BEFORE_BEACON_DEF;
535 param->hp_dm_max_guard_time = PTA_HPDM_MAX_TIME_DEF;
536 param->next_wlan_packet = PTA_TIME_OUT_NEXT_WLAN_DEF;
537 param->antenna_type = PTA_ANTENNA_TYPE_DEF;
538 param->signal_type = PTA_SIGNALING_TYPE_DEF;
539 param->afh_leverage_on = PTA_AFH_LEVERAGE_ON_DEF;
540 param->quiet_cycle_num = PTA_NUMBER_QUIET_CYCLE_DEF;
541 param->max_cts = PTA_MAX_NUM_CTS_DEF;
542 param->wlan_packets_num = PTA_NUMBER_OF_WLAN_PACKETS_DEF;
543 param->bt_packets_num = PTA_NUMBER_OF_BT_PACKETS_DEF;
544 param->missed_rx_avalanche = PTA_RX_FOR_AVALANCHE_DEF;
545 param->wlan_elp_hp = PTA_ELP_HP_DEF;
546 param->bt_anti_starvation_cycles = PTA_ANTI_STARVE_NUM_CYCLE_DEF;
547 param->ack_mode_dual_ant = PTA_ACK_MODE_DEF;
548 param->pa_sd_enable = PTA_ALLOW_PA_SD_DEF;
549 param->pta_auto_mode_enable = PTA_AUTO_MODE_NO_CTS_DEF;
550 param->bt_hp_respected_num = PTA_BT_HP_RESPECTED_DEF;
552 ret = wl1271_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param));
553 if (ret < 0) {
554 wl1271_warning("failed to set sg config: %d", ret);
555 goto out;
558 out:
559 kfree(param);
560 return ret;
563 int wl1271_acx_cca_threshold(struct wl1271 *wl)
565 struct acx_energy_detection *detection;
566 int ret;
568 wl1271_debug(DEBUG_ACX, "acx cca threshold");
570 detection = kzalloc(sizeof(*detection), GFP_KERNEL);
571 if (!detection) {
572 ret = -ENOMEM;
573 goto out;
576 detection->rx_cca_threshold = CCA_THRSH_DISABLE_ENERGY_D;
577 detection->tx_energy_detection = 0;
579 ret = wl1271_cmd_configure(wl, ACX_CCA_THRESHOLD,
580 detection, sizeof(*detection));
581 if (ret < 0) {
582 wl1271_warning("failed to set cca threshold: %d", ret);
583 return ret;
586 out:
587 kfree(detection);
588 return ret;
591 int wl1271_acx_bcn_dtim_options(struct wl1271 *wl)
593 struct acx_beacon_broadcast *bb;
594 int ret;
596 wl1271_debug(DEBUG_ACX, "acx bcn dtim options");
598 bb = kzalloc(sizeof(*bb), GFP_KERNEL);
599 if (!bb) {
600 ret = -ENOMEM;
601 goto out;
604 bb->beacon_rx_timeout = BCN_RX_TIMEOUT_DEF_VALUE;
605 bb->broadcast_timeout = BROADCAST_RX_TIMEOUT_DEF_VALUE;
606 bb->rx_broadcast_in_ps = RX_BROADCAST_IN_PS_DEF_VALUE;
607 bb->ps_poll_threshold = CONSECUTIVE_PS_POLL_FAILURE_DEF;
609 ret = wl1271_cmd_configure(wl, ACX_BCN_DTIM_OPTIONS, bb, sizeof(*bb));
610 if (ret < 0) {
611 wl1271_warning("failed to set rx config: %d", ret);
612 goto out;
615 out:
616 kfree(bb);
617 return ret;
620 int wl1271_acx_aid(struct wl1271 *wl, u16 aid)
622 struct acx_aid *acx_aid;
623 int ret;
625 wl1271_debug(DEBUG_ACX, "acx aid");
627 acx_aid = kzalloc(sizeof(*acx_aid), GFP_KERNEL);
628 if (!acx_aid) {
629 ret = -ENOMEM;
630 goto out;
633 acx_aid->aid = aid;
635 ret = wl1271_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid));
636 if (ret < 0) {
637 wl1271_warning("failed to set aid: %d", ret);
638 goto out;
641 out:
642 kfree(acx_aid);
643 return ret;
646 int wl1271_acx_event_mbox_mask(struct wl1271 *wl, u32 event_mask)
648 struct acx_event_mask *mask;
649 int ret;
651 wl1271_debug(DEBUG_ACX, "acx event mbox mask");
653 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
654 if (!mask) {
655 ret = -ENOMEM;
656 goto out;
659 /* high event mask is unused */
660 mask->high_event_mask = 0xffffffff;
662 mask->event_mask = event_mask;
664 ret = wl1271_cmd_configure(wl, ACX_EVENT_MBOX_MASK,
665 mask, sizeof(*mask));
666 if (ret < 0) {
667 wl1271_warning("failed to set acx_event_mbox_mask: %d", ret);
668 goto out;
671 out:
672 kfree(mask);
673 return ret;
676 int wl1271_acx_set_preamble(struct wl1271 *wl, enum acx_preamble_type preamble)
678 struct acx_preamble *acx;
679 int ret;
681 wl1271_debug(DEBUG_ACX, "acx_set_preamble");
683 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
684 if (!acx) {
685 ret = -ENOMEM;
686 goto out;
689 acx->preamble = preamble;
691 ret = wl1271_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx));
692 if (ret < 0) {
693 wl1271_warning("Setting of preamble failed: %d", ret);
694 goto out;
697 out:
698 kfree(acx);
699 return ret;
702 int wl1271_acx_cts_protect(struct wl1271 *wl,
703 enum acx_ctsprotect_type ctsprotect)
705 struct acx_ctsprotect *acx;
706 int ret;
708 wl1271_debug(DEBUG_ACX, "acx_set_ctsprotect");
710 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
711 if (!acx) {
712 ret = -ENOMEM;
713 goto out;
716 acx->ctsprotect = ctsprotect;
718 ret = wl1271_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx));
719 if (ret < 0) {
720 wl1271_warning("Setting of ctsprotect failed: %d", ret);
721 goto out;
724 out:
725 kfree(acx);
726 return ret;
729 int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats)
731 int ret;
733 wl1271_debug(DEBUG_ACX, "acx statistics");
735 ret = wl1271_cmd_interrogate(wl, ACX_STATISTICS, stats,
736 sizeof(*stats));
737 if (ret < 0) {
738 wl1271_warning("acx statistics failed: %d", ret);
739 return -ENOMEM;
742 return 0;
745 int wl1271_acx_rate_policies(struct wl1271 *wl, u32 enabled_rates)
747 struct acx_rate_policy *acx;
748 int ret = 0;
750 wl1271_debug(DEBUG_ACX, "acx rate policies");
752 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
754 if (!acx) {
755 ret = -ENOMEM;
756 goto out;
759 /* configure one default (one-size-fits-all) rate class */
760 acx->rate_class_cnt = 1;
761 acx->rate_class[0].enabled_rates = enabled_rates;
762 acx->rate_class[0].short_retry_limit = ACX_RATE_RETRY_LIMIT;
763 acx->rate_class[0].long_retry_limit = ACX_RATE_RETRY_LIMIT;
764 acx->rate_class[0].aflags = 0;
766 ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
767 if (ret < 0) {
768 wl1271_warning("Setting of rate policies failed: %d", ret);
769 goto out;
772 out:
773 kfree(acx);
774 return ret;
777 int wl1271_acx_ac_cfg(struct wl1271 *wl)
779 struct acx_ac_cfg *acx;
780 int i, ret = 0;
782 wl1271_debug(DEBUG_ACX, "acx access category config");
784 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
786 if (!acx) {
787 ret = -ENOMEM;
788 goto out;
792 * FIXME: Configure each AC with appropriate values (most suitable
793 * values will probably be different for each AC.
795 for (i = 0; i < WL1271_ACX_AC_COUNT; i++) {
796 acx->ac = i;
799 * FIXME: The following default values originate from
800 * the TI reference driver. What do they mean?
802 acx->cw_min = 15;
803 acx->cw_max = 63;
804 acx->aifsn = 3;
805 acx->reserved = 0;
806 acx->tx_op_limit = 0;
808 ret = wl1271_cmd_configure(wl, ACX_AC_CFG, acx, sizeof(*acx));
809 if (ret < 0) {
810 wl1271_warning("Setting of access category "
811 "config: %d", ret);
812 goto out;
816 out:
817 kfree(acx);
818 return ret;
821 int wl1271_acx_tid_cfg(struct wl1271 *wl)
823 struct acx_tid_config *acx;
824 int i, ret = 0;
826 wl1271_debug(DEBUG_ACX, "acx tid config");
828 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
830 if (!acx) {
831 ret = -ENOMEM;
832 goto out;
835 /* FIXME: configure each TID with a different AC reference */
836 for (i = 0; i < WL1271_ACX_TID_COUNT; i++) {
837 acx->queue_id = i;
838 acx->tsid = WL1271_ACX_AC_BE;
839 acx->ps_scheme = WL1271_ACX_PS_SCHEME_LEGACY;
840 acx->ack_policy = WL1271_ACX_ACK_POLICY_LEGACY;
842 ret = wl1271_cmd_configure(wl, ACX_TID_CFG, acx, sizeof(*acx));
843 if (ret < 0) {
844 wl1271_warning("Setting of tid config failed: %d", ret);
845 goto out;
849 out:
850 kfree(acx);
851 return ret;
854 int wl1271_acx_frag_threshold(struct wl1271 *wl)
856 struct acx_frag_threshold *acx;
857 int ret = 0;
859 wl1271_debug(DEBUG_ACX, "acx frag threshold");
861 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
863 if (!acx) {
864 ret = -ENOMEM;
865 goto out;
868 acx->frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
869 ret = wl1271_cmd_configure(wl, ACX_FRAG_CFG, acx, sizeof(*acx));
870 if (ret < 0) {
871 wl1271_warning("Setting of frag threshold failed: %d", ret);
872 goto out;
875 out:
876 kfree(acx);
877 return ret;
880 int wl1271_acx_tx_config_options(struct wl1271 *wl)
882 struct acx_tx_config_options *acx;
883 int ret = 0;
885 wl1271_debug(DEBUG_ACX, "acx tx config options");
887 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
889 if (!acx) {
890 ret = -ENOMEM;
891 goto out;
894 acx->tx_compl_timeout = WL1271_ACX_TX_COMPL_TIMEOUT;
895 acx->tx_compl_threshold = WL1271_ACX_TX_COMPL_THRESHOLD;
896 ret = wl1271_cmd_configure(wl, ACX_TX_CONFIG_OPT, acx, sizeof(*acx));
897 if (ret < 0) {
898 wl1271_warning("Setting of tx options failed: %d", ret);
899 goto out;
902 out:
903 kfree(acx);
904 return ret;
907 int wl1271_acx_mem_cfg(struct wl1271 *wl)
909 struct wl1271_acx_config_memory *mem_conf;
910 int ret;
912 wl1271_debug(DEBUG_ACX, "wl1271 mem cfg");
914 mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL);
915 if (!mem_conf) {
916 ret = -ENOMEM;
917 goto out;
920 /* memory config */
921 mem_conf->num_stations = cpu_to_le16(DEFAULT_NUM_STATIONS);
922 mem_conf->rx_mem_block_num = ACX_RX_MEM_BLOCKS;
923 mem_conf->tx_min_mem_block_num = ACX_TX_MIN_MEM_BLOCKS;
924 mem_conf->num_ssid_profiles = ACX_NUM_SSID_PROFILES;
925 mem_conf->total_tx_descriptors = ACX_TX_DESCRIPTORS;
927 ret = wl1271_cmd_configure(wl, ACX_MEM_CFG, mem_conf,
928 sizeof(*mem_conf));
929 if (ret < 0) {
930 wl1271_warning("wl1271 mem config failed: %d", ret);
931 goto out;
934 out:
935 kfree(mem_conf);
936 return ret;
939 int wl1271_acx_init_mem_config(struct wl1271 *wl)
941 int ret;
943 ret = wl1271_acx_mem_cfg(wl);
944 if (ret < 0)
945 return ret;
947 wl->target_mem_map = kzalloc(sizeof(struct wl1271_acx_mem_map),
948 GFP_KERNEL);
949 if (!wl->target_mem_map) {
950 wl1271_error("couldn't allocate target memory map");
951 return -ENOMEM;
954 /* we now ask for the firmware built memory map */
955 ret = wl1271_acx_mem_map(wl, (void *)wl->target_mem_map,
956 sizeof(struct wl1271_acx_mem_map));
957 if (ret < 0) {
958 wl1271_error("couldn't retrieve firmware memory map");
959 kfree(wl->target_mem_map);
960 wl->target_mem_map = NULL;
961 return ret;
964 /* initialize TX block book keeping */
965 wl->tx_blocks_available = wl->target_mem_map->num_tx_mem_blocks;
966 wl1271_debug(DEBUG_TX, "available tx blocks: %d",
967 wl->tx_blocks_available);
969 return 0;
972 int wl1271_acx_init_rx_interrupt(struct wl1271 *wl)
974 struct wl1271_acx_rx_config_opt *rx_conf;
975 int ret;
977 wl1271_debug(DEBUG_ACX, "wl1271 rx interrupt config");
979 rx_conf = kzalloc(sizeof(*rx_conf), GFP_KERNEL);
980 if (!rx_conf) {
981 ret = -ENOMEM;
982 goto out;
985 rx_conf->threshold = WL1271_RX_INTR_THRESHOLD_DEF;
986 rx_conf->timeout = WL1271_RX_INTR_TIMEOUT_DEF;
987 rx_conf->mblk_threshold = USHORT_MAX; /* Disabled */
988 rx_conf->queue_type = RX_QUEUE_TYPE_RX_LOW_PRIORITY;
990 ret = wl1271_cmd_configure(wl, ACX_RX_CONFIG_OPT, rx_conf,
991 sizeof(*rx_conf));
992 if (ret < 0) {
993 wl1271_warning("wl1271 rx config opt failed: %d", ret);
994 goto out;
997 out:
998 kfree(rx_conf);
999 return ret;
1002 int wl1271_acx_smart_reflex(struct wl1271 *wl)
1004 struct acx_smart_reflex_state *sr_state = NULL;
1005 struct acx_smart_reflex_config_params *sr_param = NULL;
1006 int ret;
1008 wl1271_debug(DEBUG_ACX, "acx smart reflex");
1010 sr_param = kzalloc(sizeof(*sr_param), GFP_KERNEL);
1011 if (!sr_param) {
1012 ret = -ENOMEM;
1013 goto out;
1016 /* set cryptic smart reflex parameters - source TI reference code */
1017 sr_param->error_table[0].len = 0x07;
1018 sr_param->error_table[0].upper_limit = 0x03;
1019 sr_param->error_table[0].values[0] = 0x18;
1020 sr_param->error_table[0].values[1] = 0x10;
1021 sr_param->error_table[0].values[2] = 0x05;
1022 sr_param->error_table[0].values[3] = 0xfb;
1023 sr_param->error_table[0].values[4] = 0xf0;
1024 sr_param->error_table[0].values[5] = 0xe8;
1026 sr_param->error_table[1].len = 0x07;
1027 sr_param->error_table[1].upper_limit = 0x03;
1028 sr_param->error_table[1].values[0] = 0x18;
1029 sr_param->error_table[1].values[1] = 0x10;
1030 sr_param->error_table[1].values[2] = 0x05;
1031 sr_param->error_table[1].values[3] = 0xf6;
1032 sr_param->error_table[1].values[4] = 0xf0;
1033 sr_param->error_table[1].values[5] = 0xe8;
1035 sr_param->error_table[2].len = 0x07;
1036 sr_param->error_table[2].upper_limit = 0x03;
1037 sr_param->error_table[2].values[0] = 0x18;
1038 sr_param->error_table[2].values[1] = 0x10;
1039 sr_param->error_table[2].values[2] = 0x05;
1040 sr_param->error_table[2].values[3] = 0xfb;
1041 sr_param->error_table[2].values[4] = 0xf0;
1042 sr_param->error_table[2].values[5] = 0xe8;
1044 ret = wl1271_cmd_configure(wl, ACX_SET_SMART_REFLEX_PARAMS,
1045 sr_param, sizeof(*sr_param));
1046 if (ret < 0) {
1047 wl1271_warning("failed to set smart reflex params: %d", ret);
1048 goto out;
1051 sr_state = kzalloc(sizeof(*sr_state), GFP_KERNEL);
1052 if (!sr_state) {
1053 ret = -ENOMEM;
1054 goto out;
1057 /* enable smart reflex */
1058 sr_state->enable = 1;
1060 ret = wl1271_cmd_configure(wl, ACX_SET_SMART_REFLEX_STATE,
1061 sr_state, sizeof(*sr_state));
1062 if (ret < 0) {
1063 wl1271_warning("failed to set smart reflex params: %d", ret);
1064 goto out;
1067 out:
1068 kfree(sr_state);
1069 kfree(sr_param);
1070 return ret;