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