wl1271: fix endianess issues
[deliverable/linux.git] / drivers / net / wireless / wl12xx / wl1271_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 "wl1271_acx.h"
25
26 #include <linux/module.h>
27 #include <linux/platform_device.h>
28 #include <linux/crc7.h>
29 #include <linux/spi/spi.h>
30
31 #include "wl1271.h"
32 #include "wl12xx_80211.h"
33 #include "wl1271_reg.h"
34 #include "wl1271_spi.h"
35 #include "wl1271_ps.h"
36
37 int wl1271_acx_wake_up_conditions(struct wl1271 *wl)
38 {
39 struct acx_wake_up_condition *wake_up;
40 int ret;
41
42 wl1271_debug(DEBUG_ACX, "acx wake up conditions");
43
44 wake_up = kzalloc(sizeof(*wake_up), GFP_KERNEL);
45 if (!wake_up) {
46 ret = -ENOMEM;
47 goto out;
48 }
49
50 wake_up->wake_up_event = wl->conf.conn.wake_up_event;
51 wake_up->listen_interval = wl->conf.conn.listen_interval;
52
53 ret = wl1271_cmd_configure(wl, ACX_WAKE_UP_CONDITIONS,
54 wake_up, sizeof(*wake_up));
55 if (ret < 0) {
56 wl1271_warning("could not set wake up conditions: %d", ret);
57 goto out;
58 }
59
60 out:
61 kfree(wake_up);
62 return ret;
63 }
64
65 int wl1271_acx_sleep_auth(struct wl1271 *wl, u8 sleep_auth)
66 {
67 struct acx_sleep_auth *auth;
68 int ret;
69
70 wl1271_debug(DEBUG_ACX, "acx sleep auth");
71
72 auth = kzalloc(sizeof(*auth), GFP_KERNEL);
73 if (!auth) {
74 ret = -ENOMEM;
75 goto out;
76 }
77
78 auth->sleep_auth = sleep_auth;
79
80 ret = wl1271_cmd_configure(wl, ACX_SLEEP_AUTH, auth, sizeof(*auth));
81 if (ret < 0)
82 return ret;
83
84 out:
85 kfree(auth);
86 return ret;
87 }
88
89 int wl1271_acx_fw_version(struct wl1271 *wl, char *buf, size_t len)
90 {
91 struct acx_revision *rev;
92 int ret;
93
94 wl1271_debug(DEBUG_ACX, "acx fw rev");
95
96 rev = kzalloc(sizeof(*rev), GFP_KERNEL);
97 if (!rev) {
98 ret = -ENOMEM;
99 goto out;
100 }
101
102 ret = wl1271_cmd_interrogate(wl, ACX_FW_REV, rev, sizeof(*rev));
103 if (ret < 0) {
104 wl1271_warning("ACX_FW_REV interrogate failed");
105 goto out;
106 }
107
108 /* be careful with the buffer sizes */
109 strncpy(buf, rev->fw_version, min(len, sizeof(rev->fw_version)));
110
111 /*
112 * if the firmware version string is exactly
113 * sizeof(rev->fw_version) long or fw_len is less than
114 * sizeof(rev->fw_version) it won't be null terminated
115 */
116 buf[min(len, sizeof(rev->fw_version)) - 1] = '\0';
117
118 out:
119 kfree(rev);
120 return ret;
121 }
122
123 int wl1271_acx_tx_power(struct wl1271 *wl, int power)
124 {
125 struct acx_current_tx_power *acx;
126 int ret;
127
128 wl1271_debug(DEBUG_ACX, "acx dot11_cur_tx_pwr");
129
130 if (power < 0 || power > 25)
131 return -EINVAL;
132
133 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
134 if (!acx) {
135 ret = -ENOMEM;
136 goto out;
137 }
138
139 /*
140 * FIXME: This is a workaround needed while we don't the correct
141 * calibration, to avoid distortions
142 */
143 /* acx->current_tx_power = power * 10; */
144 acx->current_tx_power = 70;
145
146 ret = wl1271_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx));
147 if (ret < 0) {
148 wl1271_warning("configure of tx power failed: %d", ret);
149 goto out;
150 }
151
152 out:
153 kfree(acx);
154 return ret;
155 }
156
157 int wl1271_acx_feature_cfg(struct wl1271 *wl)
158 {
159 struct acx_feature_config *feature;
160 int ret;
161
162 wl1271_debug(DEBUG_ACX, "acx feature cfg");
163
164 feature = kzalloc(sizeof(*feature), GFP_KERNEL);
165 if (!feature) {
166 ret = -ENOMEM;
167 goto out;
168 }
169
170 /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */
171 feature->data_flow_options = 0;
172 feature->options = 0;
173
174 ret = wl1271_cmd_configure(wl, ACX_FEATURE_CFG,
175 feature, sizeof(*feature));
176 if (ret < 0) {
177 wl1271_error("Couldnt set HW encryption");
178 goto out;
179 }
180
181 out:
182 kfree(feature);
183 return ret;
184 }
185
186 int wl1271_acx_mem_map(struct wl1271 *wl, struct acx_header *mem_map,
187 size_t len)
188 {
189 int ret;
190
191 wl1271_debug(DEBUG_ACX, "acx mem map");
192
193 ret = wl1271_cmd_interrogate(wl, ACX_MEM_MAP, mem_map, len);
194 if (ret < 0)
195 return ret;
196
197 return 0;
198 }
199
200 int wl1271_acx_rx_msdu_life_time(struct wl1271 *wl)
201 {
202 struct acx_rx_msdu_lifetime *acx;
203 int ret;
204
205 wl1271_debug(DEBUG_ACX, "acx rx msdu life time");
206
207 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
208 if (!acx) {
209 ret = -ENOMEM;
210 goto out;
211 }
212
213 acx->lifetime = cpu_to_le32(wl->conf.rx.rx_msdu_life_time);
214 ret = wl1271_cmd_configure(wl, DOT11_RX_MSDU_LIFE_TIME,
215 acx, sizeof(*acx));
216 if (ret < 0) {
217 wl1271_warning("failed to set rx msdu life time: %d", ret);
218 goto out;
219 }
220
221 out:
222 kfree(acx);
223 return ret;
224 }
225
226 int wl1271_acx_rx_config(struct wl1271 *wl, u32 config, u32 filter)
227 {
228 struct acx_rx_config *rx_config;
229 int ret;
230
231 wl1271_debug(DEBUG_ACX, "acx rx config");
232
233 rx_config = kzalloc(sizeof(*rx_config), GFP_KERNEL);
234 if (!rx_config) {
235 ret = -ENOMEM;
236 goto out;
237 }
238
239 rx_config->config_options = cpu_to_le32(config);
240 rx_config->filter_options = cpu_to_le32(filter);
241
242 ret = wl1271_cmd_configure(wl, ACX_RX_CFG,
243 rx_config, sizeof(*rx_config));
244 if (ret < 0) {
245 wl1271_warning("failed to set rx config: %d", ret);
246 goto out;
247 }
248
249 out:
250 kfree(rx_config);
251 return ret;
252 }
253
254 int wl1271_acx_pd_threshold(struct wl1271 *wl)
255 {
256 struct acx_packet_detection *pd;
257 int ret;
258
259 wl1271_debug(DEBUG_ACX, "acx data pd threshold");
260
261 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
262 if (!pd) {
263 ret = -ENOMEM;
264 goto out;
265 }
266
267 pd->threshold = cpu_to_le32(wl->conf.rx.packet_detection_threshold);
268
269 ret = wl1271_cmd_configure(wl, ACX_PD_THRESHOLD, pd, sizeof(*pd));
270 if (ret < 0) {
271 wl1271_warning("failed to set pd threshold: %d", ret);
272 goto out;
273 }
274
275 out:
276 kfree(pd);
277 return 0;
278 }
279
280 int wl1271_acx_slot(struct wl1271 *wl, enum acx_slot_type slot_time)
281 {
282 struct acx_slot *slot;
283 int ret;
284
285 wl1271_debug(DEBUG_ACX, "acx slot");
286
287 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
288 if (!slot) {
289 ret = -ENOMEM;
290 goto out;
291 }
292
293 slot->wone_index = STATION_WONE_INDEX;
294 slot->slot_time = slot_time;
295
296 ret = wl1271_cmd_configure(wl, ACX_SLOT, slot, sizeof(*slot));
297 if (ret < 0) {
298 wl1271_warning("failed to set slot time: %d", ret);
299 goto out;
300 }
301
302 out:
303 kfree(slot);
304 return ret;
305 }
306
307 int wl1271_acx_group_address_tbl(struct wl1271 *wl, bool enable,
308 void *mc_list, u32 mc_list_len)
309 {
310 struct acx_dot11_grp_addr_tbl *acx;
311 int ret;
312
313 wl1271_debug(DEBUG_ACX, "acx group address tbl");
314
315 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
316 if (!acx) {
317 ret = -ENOMEM;
318 goto out;
319 }
320
321 /* MAC filtering */
322 acx->enabled = enable;
323 acx->num_groups = mc_list_len;
324 memcpy(acx->mac_table, mc_list, mc_list_len * ETH_ALEN);
325
326 ret = wl1271_cmd_configure(wl, DOT11_GROUP_ADDRESS_TBL,
327 acx, sizeof(*acx));
328 if (ret < 0) {
329 wl1271_warning("failed to set group addr table: %d", ret);
330 goto out;
331 }
332
333 out:
334 kfree(acx);
335 return ret;
336 }
337
338 int wl1271_acx_service_period_timeout(struct wl1271 *wl)
339 {
340 struct acx_rx_timeout *rx_timeout;
341 int ret;
342
343 rx_timeout = kzalloc(sizeof(*rx_timeout), GFP_KERNEL);
344 if (!rx_timeout) {
345 ret = -ENOMEM;
346 goto out;
347 }
348
349 wl1271_debug(DEBUG_ACX, "acx service period timeout");
350
351 rx_timeout->ps_poll_timeout = cpu_to_le16(wl->conf.rx.ps_poll_timeout);
352 rx_timeout->upsd_timeout = cpu_to_le16(wl->conf.rx.upsd_timeout);
353
354 ret = wl1271_cmd_configure(wl, ACX_SERVICE_PERIOD_TIMEOUT,
355 rx_timeout, sizeof(*rx_timeout));
356 if (ret < 0) {
357 wl1271_warning("failed to set service period timeout: %d",
358 ret);
359 goto out;
360 }
361
362 out:
363 kfree(rx_timeout);
364 return ret;
365 }
366
367 int wl1271_acx_rts_threshold(struct wl1271 *wl, u16 rts_threshold)
368 {
369 struct acx_rts_threshold *rts;
370 int ret;
371
372 wl1271_debug(DEBUG_ACX, "acx rts threshold");
373
374 rts = kzalloc(sizeof(*rts), GFP_KERNEL);
375 if (!rts) {
376 ret = -ENOMEM;
377 goto out;
378 }
379
380 rts->threshold = cpu_to_le16(rts_threshold);
381
382 ret = wl1271_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts));
383 if (ret < 0) {
384 wl1271_warning("failed to set rts threshold: %d", ret);
385 goto out;
386 }
387
388 out:
389 kfree(rts);
390 return ret;
391 }
392
393 int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, bool enable_filter)
394 {
395 struct acx_beacon_filter_option *beacon_filter = NULL;
396 int ret = 0;
397
398 wl1271_debug(DEBUG_ACX, "acx beacon filter opt");
399
400 if (enable_filter &&
401 wl->conf.conn.bcn_filt_mode == CONF_BCN_FILT_MODE_DISABLED)
402 goto out;
403
404 beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL);
405 if (!beacon_filter) {
406 ret = -ENOMEM;
407 goto out;
408 }
409
410 beacon_filter->enable = enable_filter;
411
412 /*
413 * When set to zero, and the filter is enabled, beacons
414 * without the unicast TIM bit set are dropped.
415 */
416 beacon_filter->max_num_beacons = 0;
417
418 ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_OPT,
419 beacon_filter, sizeof(*beacon_filter));
420 if (ret < 0) {
421 wl1271_warning("failed to set beacon filter opt: %d", ret);
422 goto out;
423 }
424
425 out:
426 kfree(beacon_filter);
427 return ret;
428 }
429
430 int wl1271_acx_beacon_filter_table(struct wl1271 *wl)
431 {
432 struct acx_beacon_filter_ie_table *ie_table;
433 int i, idx = 0;
434 int ret;
435 bool vendor_spec = false;
436
437 wl1271_debug(DEBUG_ACX, "acx beacon filter table");
438
439 ie_table = kzalloc(sizeof(*ie_table), GFP_KERNEL);
440 if (!ie_table) {
441 ret = -ENOMEM;
442 goto out;
443 }
444
445 /* configure default beacon pass-through rules */
446 ie_table->num_ie = 0;
447 for (i = 0; i < wl->conf.conn.bcn_filt_ie_count; i++) {
448 struct conf_bcn_filt_rule *r = &(wl->conf.conn.bcn_filt_ie[i]);
449 ie_table->table[idx++] = r->ie;
450 ie_table->table[idx++] = r->rule;
451
452 if (r->ie == WLAN_EID_VENDOR_SPECIFIC) {
453 /* only one vendor specific ie allowed */
454 if (vendor_spec)
455 continue;
456
457 /* for vendor specific rules configure the
458 additional fields */
459 memcpy(&(ie_table->table[idx]), r->oui,
460 CONF_BCN_IE_OUI_LEN);
461 idx += CONF_BCN_IE_OUI_LEN;
462 ie_table->table[idx++] = r->type;
463 memcpy(&(ie_table->table[idx]), r->version,
464 CONF_BCN_IE_VER_LEN);
465 idx += CONF_BCN_IE_VER_LEN;
466 vendor_spec = true;
467 }
468
469 ie_table->num_ie++;
470 }
471
472 ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_TABLE,
473 ie_table, sizeof(*ie_table));
474 if (ret < 0) {
475 wl1271_warning("failed to set beacon filter table: %d", ret);
476 goto out;
477 }
478
479 out:
480 kfree(ie_table);
481 return ret;
482 }
483
484 int wl1271_acx_conn_monit_params(struct wl1271 *wl)
485 {
486 struct acx_conn_monit_params *acx;
487 int ret;
488
489 wl1271_debug(DEBUG_ACX, "acx connection monitor parameters");
490
491 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
492 if (!acx) {
493 ret = -ENOMEM;
494 goto out;
495 }
496
497 acx->synch_fail_thold = cpu_to_le32(wl->conf.conn.synch_fail_thold);
498 acx->bss_lose_timeout = cpu_to_le32(wl->conf.conn.bss_lose_timeout);
499
500 ret = wl1271_cmd_configure(wl, ACX_CONN_MONIT_PARAMS,
501 acx, sizeof(*acx));
502 if (ret < 0) {
503 wl1271_warning("failed to set connection monitor "
504 "parameters: %d", ret);
505 goto out;
506 }
507
508 out:
509 kfree(acx);
510 return ret;
511 }
512
513
514 int wl1271_acx_sg_enable(struct wl1271 *wl)
515 {
516 struct acx_bt_wlan_coex *pta;
517 int ret;
518
519 wl1271_debug(DEBUG_ACX, "acx sg enable");
520
521 pta = kzalloc(sizeof(*pta), GFP_KERNEL);
522 if (!pta) {
523 ret = -ENOMEM;
524 goto out;
525 }
526
527 pta->enable = SG_ENABLE;
528
529 ret = wl1271_cmd_configure(wl, ACX_SG_ENABLE, pta, sizeof(*pta));
530 if (ret < 0) {
531 wl1271_warning("failed to set softgemini enable: %d", ret);
532 goto out;
533 }
534
535 out:
536 kfree(pta);
537 return ret;
538 }
539
540 int wl1271_acx_sg_cfg(struct wl1271 *wl)
541 {
542 struct acx_bt_wlan_coex_param *param;
543 struct conf_sg_settings *c = &wl->conf.sg;
544 int ret;
545
546 wl1271_debug(DEBUG_ACX, "acx sg cfg");
547
548 param = kzalloc(sizeof(*param), GFP_KERNEL);
549 if (!param) {
550 ret = -ENOMEM;
551 goto out;
552 }
553
554 /* BT-WLAN coext parameters */
555 param->per_threshold = cpu_to_le32(c->per_threshold);
556 param->max_scan_compensation_time =
557 cpu_to_le32(c->max_scan_compensation_time);
558 param->nfs_sample_interval = cpu_to_le16(c->nfs_sample_interval);
559 param->load_ratio = c->load_ratio;
560 param->auto_ps_mode = c->auto_ps_mode;
561 param->probe_req_compensation = c->probe_req_compensation;
562 param->scan_window_compensation = c->scan_window_compensation;
563 param->antenna_config = c->antenna_config;
564 param->beacon_miss_threshold = c->beacon_miss_threshold;
565 param->rate_adaptation_threshold =
566 cpu_to_le32(c->rate_adaptation_threshold);
567 param->rate_adaptation_snr = c->rate_adaptation_snr;
568
569 ret = wl1271_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param));
570 if (ret < 0) {
571 wl1271_warning("failed to set sg config: %d", ret);
572 goto out;
573 }
574
575 out:
576 kfree(param);
577 return ret;
578 }
579
580 int wl1271_acx_cca_threshold(struct wl1271 *wl)
581 {
582 struct acx_energy_detection *detection;
583 int ret;
584
585 wl1271_debug(DEBUG_ACX, "acx cca threshold");
586
587 detection = kzalloc(sizeof(*detection), GFP_KERNEL);
588 if (!detection) {
589 ret = -ENOMEM;
590 goto out;
591 }
592
593 detection->rx_cca_threshold = cpu_to_le16(wl->conf.rx.rx_cca_threshold);
594 detection->tx_energy_detection = wl->conf.tx.tx_energy_detection;
595
596 ret = wl1271_cmd_configure(wl, ACX_CCA_THRESHOLD,
597 detection, sizeof(*detection));
598 if (ret < 0) {
599 wl1271_warning("failed to set cca threshold: %d", ret);
600 return ret;
601 }
602
603 out:
604 kfree(detection);
605 return ret;
606 }
607
608 int wl1271_acx_bcn_dtim_options(struct wl1271 *wl)
609 {
610 struct acx_beacon_broadcast *bb;
611 int ret;
612
613 wl1271_debug(DEBUG_ACX, "acx bcn dtim options");
614
615 bb = kzalloc(sizeof(*bb), GFP_KERNEL);
616 if (!bb) {
617 ret = -ENOMEM;
618 goto out;
619 }
620
621 bb->beacon_rx_timeout = cpu_to_le16(wl->conf.conn.beacon_rx_timeout);
622 bb->broadcast_timeout = cpu_to_le16(wl->conf.conn.broadcast_timeout);
623 bb->rx_broadcast_in_ps = wl->conf.conn.rx_broadcast_in_ps;
624 bb->ps_poll_threshold = wl->conf.conn.ps_poll_threshold;
625
626 ret = wl1271_cmd_configure(wl, ACX_BCN_DTIM_OPTIONS, bb, sizeof(*bb));
627 if (ret < 0) {
628 wl1271_warning("failed to set rx config: %d", ret);
629 goto out;
630 }
631
632 out:
633 kfree(bb);
634 return ret;
635 }
636
637 int wl1271_acx_aid(struct wl1271 *wl, u16 aid)
638 {
639 struct acx_aid *acx_aid;
640 int ret;
641
642 wl1271_debug(DEBUG_ACX, "acx aid");
643
644 acx_aid = kzalloc(sizeof(*acx_aid), GFP_KERNEL);
645 if (!acx_aid) {
646 ret = -ENOMEM;
647 goto out;
648 }
649
650 acx_aid->aid = cpu_to_le16(aid);
651
652 ret = wl1271_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid));
653 if (ret < 0) {
654 wl1271_warning("failed to set aid: %d", ret);
655 goto out;
656 }
657
658 out:
659 kfree(acx_aid);
660 return ret;
661 }
662
663 int wl1271_acx_event_mbox_mask(struct wl1271 *wl, u32 event_mask)
664 {
665 struct acx_event_mask *mask;
666 int ret;
667
668 wl1271_debug(DEBUG_ACX, "acx event mbox mask");
669
670 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
671 if (!mask) {
672 ret = -ENOMEM;
673 goto out;
674 }
675
676 /* high event mask is unused */
677 mask->high_event_mask = cpu_to_le32(0xffffffff);
678 mask->event_mask = cpu_to_le32(event_mask);
679
680 ret = wl1271_cmd_configure(wl, ACX_EVENT_MBOX_MASK,
681 mask, sizeof(*mask));
682 if (ret < 0) {
683 wl1271_warning("failed to set acx_event_mbox_mask: %d", ret);
684 goto out;
685 }
686
687 out:
688 kfree(mask);
689 return ret;
690 }
691
692 int wl1271_acx_set_preamble(struct wl1271 *wl, enum acx_preamble_type preamble)
693 {
694 struct acx_preamble *acx;
695 int ret;
696
697 wl1271_debug(DEBUG_ACX, "acx_set_preamble");
698
699 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
700 if (!acx) {
701 ret = -ENOMEM;
702 goto out;
703 }
704
705 acx->preamble = preamble;
706
707 ret = wl1271_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx));
708 if (ret < 0) {
709 wl1271_warning("Setting of preamble failed: %d", ret);
710 goto out;
711 }
712
713 out:
714 kfree(acx);
715 return ret;
716 }
717
718 int wl1271_acx_cts_protect(struct wl1271 *wl,
719 enum acx_ctsprotect_type ctsprotect)
720 {
721 struct acx_ctsprotect *acx;
722 int ret;
723
724 wl1271_debug(DEBUG_ACX, "acx_set_ctsprotect");
725
726 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
727 if (!acx) {
728 ret = -ENOMEM;
729 goto out;
730 }
731
732 acx->ctsprotect = ctsprotect;
733
734 ret = wl1271_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx));
735 if (ret < 0) {
736 wl1271_warning("Setting of ctsprotect failed: %d", ret);
737 goto out;
738 }
739
740 out:
741 kfree(acx);
742 return ret;
743 }
744
745 int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats)
746 {
747 int ret;
748
749 wl1271_debug(DEBUG_ACX, "acx statistics");
750
751 ret = wl1271_cmd_interrogate(wl, ACX_STATISTICS, stats,
752 sizeof(*stats));
753 if (ret < 0) {
754 wl1271_warning("acx statistics failed: %d", ret);
755 return -ENOMEM;
756 }
757
758 return 0;
759 }
760
761 int wl1271_acx_rate_policies(struct wl1271 *wl, u32 enabled_rates)
762 {
763 struct acx_rate_policy *acx;
764 struct conf_tx_rate_class *c = &wl->conf.tx.rc_conf;
765 int ret = 0;
766
767 wl1271_debug(DEBUG_ACX, "acx rate policies");
768
769 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
770
771 if (!acx) {
772 ret = -ENOMEM;
773 goto out;
774 }
775
776 /* configure one default (one-size-fits-all) rate class */
777 acx->rate_class_cnt = cpu_to_le32(1);
778 acx->rate_class[0].enabled_rates = cpu_to_le32(enabled_rates);
779 acx->rate_class[0].short_retry_limit = c->short_retry_limit;
780 acx->rate_class[0].long_retry_limit = c->long_retry_limit;
781 acx->rate_class[0].aflags = c->aflags;
782
783 ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
784 if (ret < 0) {
785 wl1271_warning("Setting of rate policies failed: %d", ret);
786 goto out;
787 }
788
789 out:
790 kfree(acx);
791 return ret;
792 }
793
794 int wl1271_acx_ac_cfg(struct wl1271 *wl)
795 {
796 struct acx_ac_cfg *acx;
797 int i, ret = 0;
798
799 wl1271_debug(DEBUG_ACX, "acx access category config");
800
801 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
802
803 if (!acx) {
804 ret = -ENOMEM;
805 goto out;
806 }
807
808 for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
809 struct conf_tx_ac_category *c = &(wl->conf.tx.ac_conf[i]);
810 acx->ac = c->ac;
811 acx->cw_min = c->cw_min;
812 acx->cw_max = cpu_to_le16(c->cw_max);
813 acx->aifsn = c->aifsn;
814 acx->reserved = 0;
815 acx->tx_op_limit = cpu_to_le16(c->tx_op_limit);
816
817 ret = wl1271_cmd_configure(wl, ACX_AC_CFG, acx, sizeof(*acx));
818 if (ret < 0) {
819 wl1271_warning("Setting of access category "
820 "config: %d", ret);
821 goto out;
822 }
823 }
824
825 out:
826 kfree(acx);
827 return ret;
828 }
829
830 int wl1271_acx_tid_cfg(struct wl1271 *wl)
831 {
832 struct acx_tid_config *acx;
833 int i, ret = 0;
834
835 wl1271_debug(DEBUG_ACX, "acx tid config");
836
837 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
838
839 if (!acx) {
840 ret = -ENOMEM;
841 goto out;
842 }
843
844 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
845 struct conf_tx_tid *c = &(wl->conf.tx.tid_conf[i]);
846 acx->queue_id = c->queue_id;
847 acx->channel_type = c->channel_type;
848 acx->tsid = c->tsid;
849 acx->ps_scheme = c->ps_scheme;
850 acx->ack_policy = c->ack_policy;
851 acx->apsd_conf[0] = cpu_to_le32(c->apsd_conf[0]);
852 acx->apsd_conf[1] = cpu_to_le32(c->apsd_conf[1]);
853
854 ret = wl1271_cmd_configure(wl, ACX_TID_CFG, acx, sizeof(*acx));
855 if (ret < 0) {
856 wl1271_warning("Setting of tid config failed: %d", ret);
857 goto out;
858 }
859 }
860
861 out:
862 kfree(acx);
863 return ret;
864 }
865
866 int wl1271_acx_frag_threshold(struct wl1271 *wl)
867 {
868 struct acx_frag_threshold *acx;
869 int ret = 0;
870
871 wl1271_debug(DEBUG_ACX, "acx frag threshold");
872
873 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
874
875 if (!acx) {
876 ret = -ENOMEM;
877 goto out;
878 }
879
880 acx->frag_threshold = cpu_to_le16(wl->conf.tx.frag_threshold);
881 ret = wl1271_cmd_configure(wl, ACX_FRAG_CFG, acx, sizeof(*acx));
882 if (ret < 0) {
883 wl1271_warning("Setting of frag threshold failed: %d", ret);
884 goto out;
885 }
886
887 out:
888 kfree(acx);
889 return ret;
890 }
891
892 int wl1271_acx_tx_config_options(struct wl1271 *wl)
893 {
894 struct acx_tx_config_options *acx;
895 int ret = 0;
896
897 wl1271_debug(DEBUG_ACX, "acx tx config options");
898
899 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
900
901 if (!acx) {
902 ret = -ENOMEM;
903 goto out;
904 }
905
906 acx->tx_compl_timeout = cpu_to_le16(wl->conf.tx.tx_compl_timeout);
907 acx->tx_compl_threshold = cpu_to_le16(wl->conf.tx.tx_compl_threshold);
908 ret = wl1271_cmd_configure(wl, ACX_TX_CONFIG_OPT, acx, sizeof(*acx));
909 if (ret < 0) {
910 wl1271_warning("Setting of tx options failed: %d", ret);
911 goto out;
912 }
913
914 out:
915 kfree(acx);
916 return ret;
917 }
918
919 int wl1271_acx_mem_cfg(struct wl1271 *wl)
920 {
921 struct wl1271_acx_config_memory *mem_conf;
922 int ret;
923
924 wl1271_debug(DEBUG_ACX, "wl1271 mem cfg");
925
926 mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL);
927 if (!mem_conf) {
928 ret = -ENOMEM;
929 goto out;
930 }
931
932 /* memory config */
933 mem_conf->num_stations = DEFAULT_NUM_STATIONS;
934 mem_conf->rx_mem_block_num = ACX_RX_MEM_BLOCKS;
935 mem_conf->tx_min_mem_block_num = ACX_TX_MIN_MEM_BLOCKS;
936 mem_conf->num_ssid_profiles = ACX_NUM_SSID_PROFILES;
937 mem_conf->total_tx_descriptors = cpu_to_le32(ACX_TX_DESCRIPTORS);
938
939 ret = wl1271_cmd_configure(wl, ACX_MEM_CFG, mem_conf,
940 sizeof(*mem_conf));
941 if (ret < 0) {
942 wl1271_warning("wl1271 mem config failed: %d", ret);
943 goto out;
944 }
945
946 out:
947 kfree(mem_conf);
948 return ret;
949 }
950
951 int wl1271_acx_init_mem_config(struct wl1271 *wl)
952 {
953 int ret;
954
955 ret = wl1271_acx_mem_cfg(wl);
956 if (ret < 0)
957 return ret;
958
959 wl->target_mem_map = kzalloc(sizeof(struct wl1271_acx_mem_map),
960 GFP_KERNEL);
961 if (!wl->target_mem_map) {
962 wl1271_error("couldn't allocate target memory map");
963 return -ENOMEM;
964 }
965
966 /* we now ask for the firmware built memory map */
967 ret = wl1271_acx_mem_map(wl, (void *)wl->target_mem_map,
968 sizeof(struct wl1271_acx_mem_map));
969 if (ret < 0) {
970 wl1271_error("couldn't retrieve firmware memory map");
971 kfree(wl->target_mem_map);
972 wl->target_mem_map = NULL;
973 return ret;
974 }
975
976 /* initialize TX block book keeping */
977 wl->tx_blocks_available =
978 le32_to_cpu(wl->target_mem_map->num_tx_mem_blocks);
979 wl1271_debug(DEBUG_TX, "available tx blocks: %d",
980 wl->tx_blocks_available);
981
982 return 0;
983 }
984
985 int wl1271_acx_init_rx_interrupt(struct wl1271 *wl)
986 {
987 struct wl1271_acx_rx_config_opt *rx_conf;
988 int ret;
989
990 wl1271_debug(DEBUG_ACX, "wl1271 rx interrupt config");
991
992 rx_conf = kzalloc(sizeof(*rx_conf), GFP_KERNEL);
993 if (!rx_conf) {
994 ret = -ENOMEM;
995 goto out;
996 }
997
998 rx_conf->threshold = cpu_to_le16(wl->conf.rx.irq_pkt_threshold);
999 rx_conf->timeout = cpu_to_le16(wl->conf.rx.irq_timeout);
1000 rx_conf->mblk_threshold = cpu_to_le16(wl->conf.rx.irq_blk_threshold);
1001 rx_conf->queue_type = wl->conf.rx.queue_type;
1002
1003 ret = wl1271_cmd_configure(wl, ACX_RX_CONFIG_OPT, rx_conf,
1004 sizeof(*rx_conf));
1005 if (ret < 0) {
1006 wl1271_warning("wl1271 rx config opt failed: %d", ret);
1007 goto out;
1008 }
1009
1010 out:
1011 kfree(rx_conf);
1012 return ret;
1013 }
1014
1015 int wl1271_acx_smart_reflex(struct wl1271 *wl)
1016 {
1017 struct acx_smart_reflex_state *sr_state = NULL;
1018 struct acx_smart_reflex_config_params *sr_param = NULL;
1019 int i, ret;
1020
1021 wl1271_debug(DEBUG_ACX, "acx smart reflex");
1022
1023 sr_param = kzalloc(sizeof(*sr_param), GFP_KERNEL);
1024 if (!sr_param) {
1025 ret = -ENOMEM;
1026 goto out;
1027 }
1028
1029 for (i = 0; i < CONF_SR_ERR_TBL_COUNT; i++) {
1030 struct conf_mart_reflex_err_table *e =
1031 &(wl->conf.init.sr_err_tbl[i]);
1032
1033 sr_param->error_table[i].len = e->len;
1034 sr_param->error_table[i].upper_limit = e->upper_limit;
1035 memcpy(sr_param->error_table[i].values, e->values, e->len);
1036 }
1037
1038 ret = wl1271_cmd_configure(wl, ACX_SET_SMART_REFLEX_PARAMS,
1039 sr_param, sizeof(*sr_param));
1040 if (ret < 0) {
1041 wl1271_warning("failed to set smart reflex params: %d", ret);
1042 goto out;
1043 }
1044
1045 sr_state = kzalloc(sizeof(*sr_state), GFP_KERNEL);
1046 if (!sr_state) {
1047 ret = -ENOMEM;
1048 goto out;
1049 }
1050
1051 /* enable smart reflex */
1052 sr_state->enable = wl->conf.init.sr_enable;
1053
1054 ret = wl1271_cmd_configure(wl, ACX_SET_SMART_REFLEX_STATE,
1055 sr_state, sizeof(*sr_state));
1056 if (ret < 0) {
1057 wl1271_warning("failed to set smart reflex params: %d", ret);
1058 goto out;
1059 }
1060
1061 out:
1062 kfree(sr_state);
1063 kfree(sr_param);
1064 return ret;
1065
1066 }
1067
1068 int wl1271_acx_bet_enable(struct wl1271 *wl, bool enable)
1069 {
1070 struct wl1271_acx_bet_enable *acx = NULL;
1071 int ret = 0;
1072
1073 wl1271_debug(DEBUG_ACX, "acx bet enable");
1074
1075 if (enable && wl->conf.conn.bet_enable == CONF_BET_MODE_DISABLE)
1076 goto out;
1077
1078 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1079 if (!acx) {
1080 ret = -ENOMEM;
1081 goto out;
1082 }
1083
1084 acx->enable = enable ? CONF_BET_MODE_ENABLE : CONF_BET_MODE_DISABLE;
1085 acx->max_consecutive = wl->conf.conn.bet_max_consecutive;
1086
1087 ret = wl1271_cmd_configure(wl, ACX_BET_ENABLE, acx, sizeof(*acx));
1088 if (ret < 0) {
1089 wl1271_warning("acx bet enable failed: %d", ret);
1090 goto out;
1091 }
1092
1093 out:
1094 kfree(acx);
1095 return ret;
1096 }
1097
1098 int wl1271_acx_arp_ip_filter(struct wl1271 *wl, bool enable, u8 *address,
1099 u8 version)
1100 {
1101 struct wl1271_acx_arp_filter *acx;
1102 int ret;
1103
1104 wl1271_debug(DEBUG_ACX, "acx arp ip filter, enable: %d", enable);
1105
1106 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
1107 if (!acx) {
1108 ret = -ENOMEM;
1109 goto out;
1110 }
1111
1112 acx->version = version;
1113 acx->enable = enable;
1114
1115 if (enable == true) {
1116 if (version == ACX_IPV4_VERSION)
1117 memcpy(acx->address, address, ACX_IPV4_ADDR_SIZE);
1118 else if (version == ACX_IPV6_VERSION)
1119 memcpy(acx->address, address, sizeof(acx->address));
1120 else
1121 wl1271_error("Invalid IP version");
1122 }
1123
1124 ret = wl1271_cmd_configure(wl, ACX_ARP_IP_FILTER,
1125 acx, sizeof(*acx));
1126 if (ret < 0) {
1127 wl1271_warning("failed to set arp ip filter: %d", ret);
1128 goto out;
1129 }
1130
1131 out:
1132 kfree(acx);
1133 return ret;
1134 }
This page took 0.094271 seconds and 5 git commands to generate.