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