xref: /openbmc/linux/drivers/net/wireless/ti/wl1251/acx.c (revision 4d09b537)
190921014SLuciano Coelho #include "acx.h"
290921014SLuciano Coelho 
390921014SLuciano Coelho #include <linux/module.h>
490921014SLuciano Coelho #include <linux/slab.h>
590921014SLuciano Coelho #include <linux/crc7.h>
690921014SLuciano Coelho 
790921014SLuciano Coelho #include "wl1251.h"
890921014SLuciano Coelho #include "reg.h"
990921014SLuciano Coelho #include "cmd.h"
1090921014SLuciano Coelho #include "ps.h"
1190921014SLuciano Coelho 
1290921014SLuciano Coelho int wl1251_acx_frame_rates(struct wl1251 *wl, u8 ctrl_rate, u8 ctrl_mod,
1390921014SLuciano Coelho 			   u8 mgt_rate, u8 mgt_mod)
1490921014SLuciano Coelho {
1590921014SLuciano Coelho 	struct acx_fw_gen_frame_rates *rates;
1690921014SLuciano Coelho 	int ret;
1790921014SLuciano Coelho 
1890921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx frame rates");
1990921014SLuciano Coelho 
2090921014SLuciano Coelho 	rates = kzalloc(sizeof(*rates), GFP_KERNEL);
2160ce473eSJing Wang 	if (!rates)
2260ce473eSJing Wang 		return -ENOMEM;
2390921014SLuciano Coelho 
2490921014SLuciano Coelho 	rates->tx_ctrl_frame_rate = ctrl_rate;
2590921014SLuciano Coelho 	rates->tx_ctrl_frame_mod = ctrl_mod;
2690921014SLuciano Coelho 	rates->tx_mgt_frame_rate = mgt_rate;
2790921014SLuciano Coelho 	rates->tx_mgt_frame_mod = mgt_mod;
2890921014SLuciano Coelho 
2990921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, ACX_FW_GEN_FRAME_RATES,
3090921014SLuciano Coelho 				   rates, sizeof(*rates));
3190921014SLuciano Coelho 	if (ret < 0) {
3290921014SLuciano Coelho 		wl1251_error("Failed to set FW rates and modulation");
3390921014SLuciano Coelho 		goto out;
3490921014SLuciano Coelho 	}
3590921014SLuciano Coelho 
3690921014SLuciano Coelho out:
3790921014SLuciano Coelho 	kfree(rates);
3890921014SLuciano Coelho 	return ret;
3990921014SLuciano Coelho }
4090921014SLuciano Coelho 
4190921014SLuciano Coelho 
4290921014SLuciano Coelho int wl1251_acx_station_id(struct wl1251 *wl)
4390921014SLuciano Coelho {
4490921014SLuciano Coelho 	struct acx_dot11_station_id *mac;
4590921014SLuciano Coelho 	int ret, i;
4690921014SLuciano Coelho 
4790921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx dot11_station_id");
4890921014SLuciano Coelho 
4990921014SLuciano Coelho 	mac = kzalloc(sizeof(*mac), GFP_KERNEL);
5060ce473eSJing Wang 	if (!mac)
5160ce473eSJing Wang 		return -ENOMEM;
5290921014SLuciano Coelho 
5390921014SLuciano Coelho 	for (i = 0; i < ETH_ALEN; i++)
5490921014SLuciano Coelho 		mac->mac[i] = wl->mac_addr[ETH_ALEN - 1 - i];
5590921014SLuciano Coelho 
5690921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, DOT11_STATION_ID, mac, sizeof(*mac));
5790921014SLuciano Coelho 	if (ret < 0)
5890921014SLuciano Coelho 		goto out;
5990921014SLuciano Coelho 
6090921014SLuciano Coelho out:
6190921014SLuciano Coelho 	kfree(mac);
6290921014SLuciano Coelho 	return ret;
6390921014SLuciano Coelho }
6490921014SLuciano Coelho 
6590921014SLuciano Coelho int wl1251_acx_default_key(struct wl1251 *wl, u8 key_id)
6690921014SLuciano Coelho {
6790921014SLuciano Coelho 	struct acx_dot11_default_key *default_key;
6890921014SLuciano Coelho 	int ret;
6990921014SLuciano Coelho 
7090921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx dot11_default_key (%d)", key_id);
7190921014SLuciano Coelho 
7290921014SLuciano Coelho 	default_key = kzalloc(sizeof(*default_key), GFP_KERNEL);
7360ce473eSJing Wang 	if (!default_key)
7460ce473eSJing Wang 		return -ENOMEM;
7590921014SLuciano Coelho 
7690921014SLuciano Coelho 	default_key->id = key_id;
7790921014SLuciano Coelho 
7890921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, DOT11_DEFAULT_KEY,
7990921014SLuciano Coelho 				   default_key, sizeof(*default_key));
8090921014SLuciano Coelho 	if (ret < 0) {
8190921014SLuciano Coelho 		wl1251_error("Couldn't set default key");
8290921014SLuciano Coelho 		goto out;
8390921014SLuciano Coelho 	}
8490921014SLuciano Coelho 
8590921014SLuciano Coelho 	wl->default_key = key_id;
8690921014SLuciano Coelho 
8790921014SLuciano Coelho out:
8890921014SLuciano Coelho 	kfree(default_key);
8990921014SLuciano Coelho 	return ret;
9090921014SLuciano Coelho }
9190921014SLuciano Coelho 
9290921014SLuciano Coelho int wl1251_acx_wake_up_conditions(struct wl1251 *wl, u8 wake_up_event,
9390921014SLuciano Coelho 				  u8 listen_interval)
9490921014SLuciano Coelho {
9590921014SLuciano Coelho 	struct acx_wake_up_condition *wake_up;
9690921014SLuciano Coelho 	int ret;
9790921014SLuciano Coelho 
9890921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx wake up conditions");
9990921014SLuciano Coelho 
10090921014SLuciano Coelho 	wake_up = kzalloc(sizeof(*wake_up), GFP_KERNEL);
10160ce473eSJing Wang 	if (!wake_up)
10260ce473eSJing Wang 		return -ENOMEM;
10390921014SLuciano Coelho 
10490921014SLuciano Coelho 	wake_up->wake_up_event = wake_up_event;
10590921014SLuciano Coelho 	wake_up->listen_interval = listen_interval;
10690921014SLuciano Coelho 
10790921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, ACX_WAKE_UP_CONDITIONS,
10890921014SLuciano Coelho 				   wake_up, sizeof(*wake_up));
10990921014SLuciano Coelho 	if (ret < 0) {
11090921014SLuciano Coelho 		wl1251_warning("could not set wake up conditions: %d", ret);
11190921014SLuciano Coelho 		goto out;
11290921014SLuciano Coelho 	}
11390921014SLuciano Coelho 
11490921014SLuciano Coelho out:
11590921014SLuciano Coelho 	kfree(wake_up);
11690921014SLuciano Coelho 	return ret;
11790921014SLuciano Coelho }
11890921014SLuciano Coelho 
11990921014SLuciano Coelho int wl1251_acx_sleep_auth(struct wl1251 *wl, u8 sleep_auth)
12090921014SLuciano Coelho {
12190921014SLuciano Coelho 	struct acx_sleep_auth *auth;
12290921014SLuciano Coelho 	int ret;
12390921014SLuciano Coelho 
12490921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx sleep auth");
12590921014SLuciano Coelho 
12690921014SLuciano Coelho 	auth = kzalloc(sizeof(*auth), GFP_KERNEL);
12760ce473eSJing Wang 	if (!auth)
12860ce473eSJing Wang 		return -ENOMEM;
12990921014SLuciano Coelho 
13090921014SLuciano Coelho 	auth->sleep_auth = sleep_auth;
13190921014SLuciano Coelho 
13290921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, ACX_SLEEP_AUTH, auth, sizeof(*auth));
13390921014SLuciano Coelho 
13490921014SLuciano Coelho 	kfree(auth);
13590921014SLuciano Coelho 	return ret;
13690921014SLuciano Coelho }
13790921014SLuciano Coelho 
13890921014SLuciano Coelho int wl1251_acx_fw_version(struct wl1251 *wl, char *buf, size_t len)
13990921014SLuciano Coelho {
14090921014SLuciano Coelho 	struct acx_revision *rev;
14190921014SLuciano Coelho 	int ret;
14290921014SLuciano Coelho 
14390921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx fw rev");
14490921014SLuciano Coelho 
14590921014SLuciano Coelho 	rev = kzalloc(sizeof(*rev), GFP_KERNEL);
14660ce473eSJing Wang 	if (!rev)
14760ce473eSJing Wang 		return -ENOMEM;
14890921014SLuciano Coelho 
14990921014SLuciano Coelho 	ret = wl1251_cmd_interrogate(wl, ACX_FW_REV, rev, sizeof(*rev));
15090921014SLuciano Coelho 	if (ret < 0) {
15190921014SLuciano Coelho 		wl1251_warning("ACX_FW_REV interrogate failed");
15290921014SLuciano Coelho 		goto out;
15390921014SLuciano Coelho 	}
15490921014SLuciano Coelho 
15590921014SLuciano Coelho 	/* be careful with the buffer sizes */
15690921014SLuciano Coelho 	strncpy(buf, rev->fw_version, min(len, sizeof(rev->fw_version)));
15790921014SLuciano Coelho 
15890921014SLuciano Coelho 	/*
15990921014SLuciano Coelho 	 * if the firmware version string is exactly
16090921014SLuciano Coelho 	 * sizeof(rev->fw_version) long or fw_len is less than
16190921014SLuciano Coelho 	 * sizeof(rev->fw_version) it won't be null terminated
16290921014SLuciano Coelho 	 */
16390921014SLuciano Coelho 	buf[min(len, sizeof(rev->fw_version)) - 1] = '\0';
16490921014SLuciano Coelho 
16590921014SLuciano Coelho out:
16690921014SLuciano Coelho 	kfree(rev);
16790921014SLuciano Coelho 	return ret;
16890921014SLuciano Coelho }
16990921014SLuciano Coelho 
17090921014SLuciano Coelho int wl1251_acx_tx_power(struct wl1251 *wl, int power)
17190921014SLuciano Coelho {
17290921014SLuciano Coelho 	struct acx_current_tx_power *acx;
17390921014SLuciano Coelho 	int ret;
17490921014SLuciano Coelho 
17590921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx dot11_cur_tx_pwr");
17690921014SLuciano Coelho 
17790921014SLuciano Coelho 	if (power < 0 || power > 25)
17890921014SLuciano Coelho 		return -EINVAL;
17990921014SLuciano Coelho 
18090921014SLuciano Coelho 	acx = kzalloc(sizeof(*acx), GFP_KERNEL);
18160ce473eSJing Wang 	if (!acx)
18260ce473eSJing Wang 		return -ENOMEM;
18390921014SLuciano Coelho 
18490921014SLuciano Coelho 	acx->current_tx_power = power * 10;
18590921014SLuciano Coelho 
18690921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx));
18790921014SLuciano Coelho 	if (ret < 0) {
18890921014SLuciano Coelho 		wl1251_warning("configure of tx power failed: %d", ret);
18990921014SLuciano Coelho 		goto out;
19090921014SLuciano Coelho 	}
19190921014SLuciano Coelho 
19290921014SLuciano Coelho out:
19390921014SLuciano Coelho 	kfree(acx);
19490921014SLuciano Coelho 	return ret;
19590921014SLuciano Coelho }
19690921014SLuciano Coelho 
1974d09b537SDavid Gnedt int wl1251_acx_feature_cfg(struct wl1251 *wl, u32 data_flow_options)
19890921014SLuciano Coelho {
19990921014SLuciano Coelho 	struct acx_feature_config *feature;
20090921014SLuciano Coelho 	int ret;
20190921014SLuciano Coelho 
20290921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx feature cfg");
20390921014SLuciano Coelho 
20490921014SLuciano Coelho 	feature = kzalloc(sizeof(*feature), GFP_KERNEL);
20560ce473eSJing Wang 	if (!feature)
20660ce473eSJing Wang 		return -ENOMEM;
20790921014SLuciano Coelho 
2084d09b537SDavid Gnedt 	/* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE can be set */
2094d09b537SDavid Gnedt 	feature->data_flow_options = data_flow_options;
21090921014SLuciano Coelho 	feature->options = 0;
21190921014SLuciano Coelho 
21290921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, ACX_FEATURE_CFG,
21390921014SLuciano Coelho 				   feature, sizeof(*feature));
21490921014SLuciano Coelho 	if (ret < 0) {
21590921014SLuciano Coelho 		wl1251_error("Couldn't set HW encryption");
21690921014SLuciano Coelho 		goto out;
21790921014SLuciano Coelho 	}
21890921014SLuciano Coelho 
21990921014SLuciano Coelho out:
22090921014SLuciano Coelho 	kfree(feature);
22190921014SLuciano Coelho 	return ret;
22290921014SLuciano Coelho }
22390921014SLuciano Coelho 
22490921014SLuciano Coelho int wl1251_acx_mem_map(struct wl1251 *wl, struct acx_header *mem_map,
22590921014SLuciano Coelho 		       size_t len)
22690921014SLuciano Coelho {
22790921014SLuciano Coelho 	int ret;
22890921014SLuciano Coelho 
22990921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx mem map");
23090921014SLuciano Coelho 
23190921014SLuciano Coelho 	ret = wl1251_cmd_interrogate(wl, ACX_MEM_MAP, mem_map, len);
23290921014SLuciano Coelho 	if (ret < 0)
23390921014SLuciano Coelho 		return ret;
23490921014SLuciano Coelho 
23590921014SLuciano Coelho 	return 0;
23690921014SLuciano Coelho }
23790921014SLuciano Coelho 
23890921014SLuciano Coelho int wl1251_acx_data_path_params(struct wl1251 *wl,
23990921014SLuciano Coelho 				struct acx_data_path_params_resp *resp)
24090921014SLuciano Coelho {
24190921014SLuciano Coelho 	struct acx_data_path_params *params;
24290921014SLuciano Coelho 	int ret;
24390921014SLuciano Coelho 
24490921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx data path params");
24590921014SLuciano Coelho 
24690921014SLuciano Coelho 	params = kzalloc(sizeof(*params), GFP_KERNEL);
24760ce473eSJing Wang 	if (!params)
24860ce473eSJing Wang 		return -ENOMEM;
24990921014SLuciano Coelho 
25090921014SLuciano Coelho 	params->rx_packet_ring_chunk_size = DP_RX_PACKET_RING_CHUNK_SIZE;
25190921014SLuciano Coelho 	params->tx_packet_ring_chunk_size = DP_TX_PACKET_RING_CHUNK_SIZE;
25290921014SLuciano Coelho 
25390921014SLuciano Coelho 	params->rx_packet_ring_chunk_num = DP_RX_PACKET_RING_CHUNK_NUM;
25490921014SLuciano Coelho 	params->tx_packet_ring_chunk_num = DP_TX_PACKET_RING_CHUNK_NUM;
25590921014SLuciano Coelho 
25690921014SLuciano Coelho 	params->tx_complete_threshold = 1;
25790921014SLuciano Coelho 
25890921014SLuciano Coelho 	params->tx_complete_ring_depth = FW_TX_CMPLT_BLOCK_SIZE;
25990921014SLuciano Coelho 
26090921014SLuciano Coelho 	params->tx_complete_timeout = DP_TX_COMPLETE_TIME_OUT;
26190921014SLuciano Coelho 
26290921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, ACX_DATA_PATH_PARAMS,
26390921014SLuciano Coelho 				   params, sizeof(*params));
26490921014SLuciano Coelho 	if (ret < 0)
26590921014SLuciano Coelho 		goto out;
26690921014SLuciano Coelho 
26790921014SLuciano Coelho 	/* FIXME: shouldn't this be ACX_DATA_PATH_RESP_PARAMS? */
26890921014SLuciano Coelho 	ret = wl1251_cmd_interrogate(wl, ACX_DATA_PATH_PARAMS,
26990921014SLuciano Coelho 				     resp, sizeof(*resp));
27090921014SLuciano Coelho 
27190921014SLuciano Coelho 	if (ret < 0) {
27290921014SLuciano Coelho 		wl1251_warning("failed to read data path parameters: %d", ret);
27390921014SLuciano Coelho 		goto out;
27490921014SLuciano Coelho 	} else if (resp->header.cmd.status != CMD_STATUS_SUCCESS) {
27590921014SLuciano Coelho 		wl1251_warning("data path parameter acx status failed");
27690921014SLuciano Coelho 		ret = -EIO;
27790921014SLuciano Coelho 		goto out;
27890921014SLuciano Coelho 	}
27990921014SLuciano Coelho 
28090921014SLuciano Coelho out:
28190921014SLuciano Coelho 	kfree(params);
28290921014SLuciano Coelho 	return ret;
28390921014SLuciano Coelho }
28490921014SLuciano Coelho 
28590921014SLuciano Coelho int wl1251_acx_rx_msdu_life_time(struct wl1251 *wl, u32 life_time)
28690921014SLuciano Coelho {
28790921014SLuciano Coelho 	struct acx_rx_msdu_lifetime *acx;
28890921014SLuciano Coelho 	int ret;
28990921014SLuciano Coelho 
29090921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx rx msdu life time");
29190921014SLuciano Coelho 
29290921014SLuciano Coelho 	acx = kzalloc(sizeof(*acx), GFP_KERNEL);
29360ce473eSJing Wang 	if (!acx)
29460ce473eSJing Wang 		return -ENOMEM;
29590921014SLuciano Coelho 
29690921014SLuciano Coelho 	acx->lifetime = life_time;
29790921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, DOT11_RX_MSDU_LIFE_TIME,
29890921014SLuciano Coelho 				   acx, sizeof(*acx));
29990921014SLuciano Coelho 	if (ret < 0) {
30090921014SLuciano Coelho 		wl1251_warning("failed to set rx msdu life time: %d", ret);
30190921014SLuciano Coelho 		goto out;
30290921014SLuciano Coelho 	}
30390921014SLuciano Coelho 
30490921014SLuciano Coelho out:
30590921014SLuciano Coelho 	kfree(acx);
30690921014SLuciano Coelho 	return ret;
30790921014SLuciano Coelho }
30890921014SLuciano Coelho 
30990921014SLuciano Coelho int wl1251_acx_rx_config(struct wl1251 *wl, u32 config, u32 filter)
31090921014SLuciano Coelho {
31190921014SLuciano Coelho 	struct acx_rx_config *rx_config;
31290921014SLuciano Coelho 	int ret;
31390921014SLuciano Coelho 
31490921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx rx config");
31590921014SLuciano Coelho 
31690921014SLuciano Coelho 	rx_config = kzalloc(sizeof(*rx_config), GFP_KERNEL);
31760ce473eSJing Wang 	if (!rx_config)
31860ce473eSJing Wang 		return -ENOMEM;
31990921014SLuciano Coelho 
32090921014SLuciano Coelho 	rx_config->config_options = config;
32190921014SLuciano Coelho 	rx_config->filter_options = filter;
32290921014SLuciano Coelho 
32390921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, ACX_RX_CFG,
32490921014SLuciano Coelho 				   rx_config, sizeof(*rx_config));
32590921014SLuciano Coelho 	if (ret < 0) {
32690921014SLuciano Coelho 		wl1251_warning("failed to set rx config: %d", ret);
32790921014SLuciano Coelho 		goto out;
32890921014SLuciano Coelho 	}
32990921014SLuciano Coelho 
33090921014SLuciano Coelho out:
33190921014SLuciano Coelho 	kfree(rx_config);
33290921014SLuciano Coelho 	return ret;
33390921014SLuciano Coelho }
33490921014SLuciano Coelho 
33590921014SLuciano Coelho int wl1251_acx_pd_threshold(struct wl1251 *wl)
33690921014SLuciano Coelho {
33790921014SLuciano Coelho 	struct acx_packet_detection *pd;
33890921014SLuciano Coelho 	int ret;
33990921014SLuciano Coelho 
34090921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx data pd threshold");
34190921014SLuciano Coelho 
34290921014SLuciano Coelho 	pd = kzalloc(sizeof(*pd), GFP_KERNEL);
34360ce473eSJing Wang 	if (!pd)
34460ce473eSJing Wang 		return -ENOMEM;
34590921014SLuciano Coelho 
34690921014SLuciano Coelho 	/* FIXME: threshold value not set */
34790921014SLuciano Coelho 
34890921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, ACX_PD_THRESHOLD, pd, sizeof(*pd));
34990921014SLuciano Coelho 	if (ret < 0) {
35090921014SLuciano Coelho 		wl1251_warning("failed to set pd threshold: %d", ret);
35190921014SLuciano Coelho 		goto out;
35290921014SLuciano Coelho 	}
35390921014SLuciano Coelho 
35490921014SLuciano Coelho out:
35590921014SLuciano Coelho 	kfree(pd);
35690921014SLuciano Coelho 	return ret;
35790921014SLuciano Coelho }
35890921014SLuciano Coelho 
35990921014SLuciano Coelho int wl1251_acx_slot(struct wl1251 *wl, enum acx_slot_type slot_time)
36090921014SLuciano Coelho {
36190921014SLuciano Coelho 	struct acx_slot *slot;
36290921014SLuciano Coelho 	int ret;
36390921014SLuciano Coelho 
36490921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx slot");
36590921014SLuciano Coelho 
36690921014SLuciano Coelho 	slot = kzalloc(sizeof(*slot), GFP_KERNEL);
36760ce473eSJing Wang 	if (!slot)
36860ce473eSJing Wang 		return -ENOMEM;
36990921014SLuciano Coelho 
37090921014SLuciano Coelho 	slot->wone_index = STATION_WONE_INDEX;
37190921014SLuciano Coelho 	slot->slot_time = slot_time;
37290921014SLuciano Coelho 
37390921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, ACX_SLOT, slot, sizeof(*slot));
37490921014SLuciano Coelho 	if (ret < 0) {
37590921014SLuciano Coelho 		wl1251_warning("failed to set slot time: %d", ret);
37690921014SLuciano Coelho 		goto out;
37790921014SLuciano Coelho 	}
37890921014SLuciano Coelho 
37990921014SLuciano Coelho out:
38090921014SLuciano Coelho 	kfree(slot);
38190921014SLuciano Coelho 	return ret;
38290921014SLuciano Coelho }
38390921014SLuciano Coelho 
38490921014SLuciano Coelho int wl1251_acx_group_address_tbl(struct wl1251 *wl)
38590921014SLuciano Coelho {
38690921014SLuciano Coelho 	struct acx_dot11_grp_addr_tbl *acx;
38790921014SLuciano Coelho 	int ret;
38890921014SLuciano Coelho 
38990921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx group address tbl");
39090921014SLuciano Coelho 
39190921014SLuciano Coelho 	acx = kzalloc(sizeof(*acx), GFP_KERNEL);
39260ce473eSJing Wang 	if (!acx)
39360ce473eSJing Wang 		return -ENOMEM;
39490921014SLuciano Coelho 
39590921014SLuciano Coelho 	/* MAC filtering */
39690921014SLuciano Coelho 	acx->enabled = 0;
39790921014SLuciano Coelho 	acx->num_groups = 0;
39890921014SLuciano Coelho 	memset(acx->mac_table, 0, ADDRESS_GROUP_MAX_LEN);
39990921014SLuciano Coelho 
40090921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, DOT11_GROUP_ADDRESS_TBL,
40190921014SLuciano Coelho 				   acx, sizeof(*acx));
40290921014SLuciano Coelho 	if (ret < 0) {
40390921014SLuciano Coelho 		wl1251_warning("failed to set group addr table: %d", ret);
40490921014SLuciano Coelho 		goto out;
40590921014SLuciano Coelho 	}
40690921014SLuciano Coelho 
40790921014SLuciano Coelho out:
40890921014SLuciano Coelho 	kfree(acx);
40990921014SLuciano Coelho 	return ret;
41090921014SLuciano Coelho }
41190921014SLuciano Coelho 
41290921014SLuciano Coelho int wl1251_acx_service_period_timeout(struct wl1251 *wl)
41390921014SLuciano Coelho {
41490921014SLuciano Coelho 	struct acx_rx_timeout *rx_timeout;
41590921014SLuciano Coelho 	int ret;
41690921014SLuciano Coelho 
41790921014SLuciano Coelho 	rx_timeout = kzalloc(sizeof(*rx_timeout), GFP_KERNEL);
41860ce473eSJing Wang 	if (!rx_timeout)
41960ce473eSJing Wang 		return -ENOMEM;
42090921014SLuciano Coelho 
42190921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx service period timeout");
42290921014SLuciano Coelho 
42390921014SLuciano Coelho 	rx_timeout->ps_poll_timeout = RX_TIMEOUT_PS_POLL_DEF;
42490921014SLuciano Coelho 	rx_timeout->upsd_timeout = RX_TIMEOUT_UPSD_DEF;
42590921014SLuciano Coelho 
42690921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, ACX_SERVICE_PERIOD_TIMEOUT,
42790921014SLuciano Coelho 				   rx_timeout, sizeof(*rx_timeout));
42890921014SLuciano Coelho 	if (ret < 0) {
42990921014SLuciano Coelho 		wl1251_warning("failed to set service period timeout: %d",
43090921014SLuciano Coelho 			       ret);
43190921014SLuciano Coelho 		goto out;
43290921014SLuciano Coelho 	}
43390921014SLuciano Coelho 
43490921014SLuciano Coelho out:
43590921014SLuciano Coelho 	kfree(rx_timeout);
43690921014SLuciano Coelho 	return ret;
43790921014SLuciano Coelho }
43890921014SLuciano Coelho 
43990921014SLuciano Coelho int wl1251_acx_rts_threshold(struct wl1251 *wl, u16 rts_threshold)
44090921014SLuciano Coelho {
44190921014SLuciano Coelho 	struct acx_rts_threshold *rts;
44290921014SLuciano Coelho 	int ret;
44390921014SLuciano Coelho 
44490921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx rts threshold");
44590921014SLuciano Coelho 
44690921014SLuciano Coelho 	rts = kzalloc(sizeof(*rts), GFP_KERNEL);
44760ce473eSJing Wang 	if (!rts)
44860ce473eSJing Wang 		return -ENOMEM;
44990921014SLuciano Coelho 
45090921014SLuciano Coelho 	rts->threshold = rts_threshold;
45190921014SLuciano Coelho 
45290921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts));
45390921014SLuciano Coelho 	if (ret < 0) {
45490921014SLuciano Coelho 		wl1251_warning("failed to set rts threshold: %d", ret);
45590921014SLuciano Coelho 		goto out;
45690921014SLuciano Coelho 	}
45790921014SLuciano Coelho 
45890921014SLuciano Coelho out:
45990921014SLuciano Coelho 	kfree(rts);
46090921014SLuciano Coelho 	return ret;
46190921014SLuciano Coelho }
46290921014SLuciano Coelho 
46390921014SLuciano Coelho int wl1251_acx_beacon_filter_opt(struct wl1251 *wl, bool enable_filter)
46490921014SLuciano Coelho {
46590921014SLuciano Coelho 	struct acx_beacon_filter_option *beacon_filter;
46690921014SLuciano Coelho 	int ret;
46790921014SLuciano Coelho 
46890921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx beacon filter opt");
46990921014SLuciano Coelho 
47090921014SLuciano Coelho 	beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL);
47160ce473eSJing Wang 	if (!beacon_filter)
47260ce473eSJing Wang 		return -ENOMEM;
47390921014SLuciano Coelho 
47490921014SLuciano Coelho 	beacon_filter->enable = enable_filter;
47590921014SLuciano Coelho 	beacon_filter->max_num_beacons = 0;
47690921014SLuciano Coelho 
47790921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, ACX_BEACON_FILTER_OPT,
47890921014SLuciano Coelho 				   beacon_filter, sizeof(*beacon_filter));
47990921014SLuciano Coelho 	if (ret < 0) {
48090921014SLuciano Coelho 		wl1251_warning("failed to set beacon filter opt: %d", ret);
48190921014SLuciano Coelho 		goto out;
48290921014SLuciano Coelho 	}
48390921014SLuciano Coelho 
48490921014SLuciano Coelho out:
48590921014SLuciano Coelho 	kfree(beacon_filter);
48690921014SLuciano Coelho 	return ret;
48790921014SLuciano Coelho }
48890921014SLuciano Coelho 
48990921014SLuciano Coelho int wl1251_acx_beacon_filter_table(struct wl1251 *wl)
49090921014SLuciano Coelho {
49190921014SLuciano Coelho 	struct acx_beacon_filter_ie_table *ie_table;
49290921014SLuciano Coelho 	int idx = 0;
49390921014SLuciano Coelho 	int ret;
49490921014SLuciano Coelho 
49590921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx beacon filter table");
49690921014SLuciano Coelho 
49790921014SLuciano Coelho 	ie_table = kzalloc(sizeof(*ie_table), GFP_KERNEL);
49860ce473eSJing Wang 	if (!ie_table)
49960ce473eSJing Wang 		return -ENOMEM;
50090921014SLuciano Coelho 
50190921014SLuciano Coelho 	/* configure default beacon pass-through rules */
50290921014SLuciano Coelho 	ie_table->num_ie = 1;
50390921014SLuciano Coelho 	ie_table->table[idx++] = BEACON_FILTER_IE_ID_CHANNEL_SWITCH_ANN;
50490921014SLuciano Coelho 	ie_table->table[idx++] = BEACON_RULE_PASS_ON_APPEARANCE;
50590921014SLuciano Coelho 
50690921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, ACX_BEACON_FILTER_TABLE,
50790921014SLuciano Coelho 				   ie_table, sizeof(*ie_table));
50890921014SLuciano Coelho 	if (ret < 0) {
50990921014SLuciano Coelho 		wl1251_warning("failed to set beacon filter table: %d", ret);
51090921014SLuciano Coelho 		goto out;
51190921014SLuciano Coelho 	}
51290921014SLuciano Coelho 
51390921014SLuciano Coelho out:
51490921014SLuciano Coelho 	kfree(ie_table);
51590921014SLuciano Coelho 	return ret;
51690921014SLuciano Coelho }
51790921014SLuciano Coelho 
51890921014SLuciano Coelho int wl1251_acx_conn_monit_params(struct wl1251 *wl)
51990921014SLuciano Coelho {
52090921014SLuciano Coelho 	struct acx_conn_monit_params *acx;
52190921014SLuciano Coelho 	int ret;
52290921014SLuciano Coelho 
52390921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx connection monitor parameters");
52490921014SLuciano Coelho 
52590921014SLuciano Coelho 	acx = kzalloc(sizeof(*acx), GFP_KERNEL);
52660ce473eSJing Wang 	if (!acx)
52760ce473eSJing Wang 		return -ENOMEM;
52890921014SLuciano Coelho 
52990921014SLuciano Coelho 	acx->synch_fail_thold = SYNCH_FAIL_DEFAULT_THRESHOLD;
53090921014SLuciano Coelho 	acx->bss_lose_timeout = NO_BEACON_DEFAULT_TIMEOUT;
53190921014SLuciano Coelho 
53290921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, ACX_CONN_MONIT_PARAMS,
53390921014SLuciano Coelho 				   acx, sizeof(*acx));
53490921014SLuciano Coelho 	if (ret < 0) {
53590921014SLuciano Coelho 		wl1251_warning("failed to set connection monitor "
53690921014SLuciano Coelho 			       "parameters: %d", ret);
53790921014SLuciano Coelho 		goto out;
53890921014SLuciano Coelho 	}
53990921014SLuciano Coelho 
54090921014SLuciano Coelho out:
54190921014SLuciano Coelho 	kfree(acx);
54290921014SLuciano Coelho 	return ret;
54390921014SLuciano Coelho }
54490921014SLuciano Coelho 
54590921014SLuciano Coelho int wl1251_acx_sg_enable(struct wl1251 *wl)
54690921014SLuciano Coelho {
54790921014SLuciano Coelho 	struct acx_bt_wlan_coex *pta;
54890921014SLuciano Coelho 	int ret;
54990921014SLuciano Coelho 
55090921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx sg enable");
55190921014SLuciano Coelho 
55290921014SLuciano Coelho 	pta = kzalloc(sizeof(*pta), GFP_KERNEL);
55360ce473eSJing Wang 	if (!pta)
55460ce473eSJing Wang 		return -ENOMEM;
55590921014SLuciano Coelho 
55690921014SLuciano Coelho 	pta->enable = SG_ENABLE;
55790921014SLuciano Coelho 
55890921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, ACX_SG_ENABLE, pta, sizeof(*pta));
55990921014SLuciano Coelho 	if (ret < 0) {
56090921014SLuciano Coelho 		wl1251_warning("failed to set softgemini enable: %d", ret);
56190921014SLuciano Coelho 		goto out;
56290921014SLuciano Coelho 	}
56390921014SLuciano Coelho 
56490921014SLuciano Coelho out:
56590921014SLuciano Coelho 	kfree(pta);
56690921014SLuciano Coelho 	return ret;
56790921014SLuciano Coelho }
56890921014SLuciano Coelho 
56990921014SLuciano Coelho int wl1251_acx_sg_cfg(struct wl1251 *wl)
57090921014SLuciano Coelho {
57190921014SLuciano Coelho 	struct acx_bt_wlan_coex_param *param;
57290921014SLuciano Coelho 	int ret;
57390921014SLuciano Coelho 
57490921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx sg cfg");
57590921014SLuciano Coelho 
57690921014SLuciano Coelho 	param = kzalloc(sizeof(*param), GFP_KERNEL);
57760ce473eSJing Wang 	if (!param)
57860ce473eSJing Wang 		return -ENOMEM;
57990921014SLuciano Coelho 
58090921014SLuciano Coelho 	/* BT-WLAN coext parameters */
58190921014SLuciano Coelho 	param->min_rate = RATE_INDEX_24MBPS;
58290921014SLuciano Coelho 	param->bt_hp_max_time = PTA_BT_HP_MAXTIME_DEF;
58390921014SLuciano Coelho 	param->wlan_hp_max_time = PTA_WLAN_HP_MAX_TIME_DEF;
58490921014SLuciano Coelho 	param->sense_disable_timer = PTA_SENSE_DISABLE_TIMER_DEF;
58590921014SLuciano Coelho 	param->rx_time_bt_hp = PTA_PROTECTIVE_RX_TIME_DEF;
58690921014SLuciano Coelho 	param->tx_time_bt_hp = PTA_PROTECTIVE_TX_TIME_DEF;
58790921014SLuciano Coelho 	param->rx_time_bt_hp_fast = PTA_PROTECTIVE_RX_TIME_FAST_DEF;
58890921014SLuciano Coelho 	param->tx_time_bt_hp_fast = PTA_PROTECTIVE_TX_TIME_FAST_DEF;
58990921014SLuciano Coelho 	param->wlan_cycle_fast = PTA_CYCLE_TIME_FAST_DEF;
59090921014SLuciano Coelho 	param->bt_anti_starvation_period = PTA_ANTI_STARVE_PERIOD_DEF;
59190921014SLuciano Coelho 	param->next_bt_lp_packet = PTA_TIMEOUT_NEXT_BT_LP_PACKET_DEF;
59290921014SLuciano Coelho 	param->wake_up_beacon = PTA_TIME_BEFORE_BEACON_DEF;
59390921014SLuciano Coelho 	param->hp_dm_max_guard_time = PTA_HPDM_MAX_TIME_DEF;
59490921014SLuciano Coelho 	param->next_wlan_packet = PTA_TIME_OUT_NEXT_WLAN_DEF;
59590921014SLuciano Coelho 	param->antenna_type = PTA_ANTENNA_TYPE_DEF;
59690921014SLuciano Coelho 	param->signal_type = PTA_SIGNALING_TYPE_DEF;
59790921014SLuciano Coelho 	param->afh_leverage_on = PTA_AFH_LEVERAGE_ON_DEF;
59890921014SLuciano Coelho 	param->quiet_cycle_num = PTA_NUMBER_QUIET_CYCLE_DEF;
59990921014SLuciano Coelho 	param->max_cts = PTA_MAX_NUM_CTS_DEF;
60090921014SLuciano Coelho 	param->wlan_packets_num = PTA_NUMBER_OF_WLAN_PACKETS_DEF;
60190921014SLuciano Coelho 	param->bt_packets_num = PTA_NUMBER_OF_BT_PACKETS_DEF;
60290921014SLuciano Coelho 	param->missed_rx_avalanche = PTA_RX_FOR_AVALANCHE_DEF;
60390921014SLuciano Coelho 	param->wlan_elp_hp = PTA_ELP_HP_DEF;
60490921014SLuciano Coelho 	param->bt_anti_starvation_cycles = PTA_ANTI_STARVE_NUM_CYCLE_DEF;
60590921014SLuciano Coelho 	param->ack_mode_dual_ant = PTA_ACK_MODE_DEF;
60690921014SLuciano Coelho 	param->pa_sd_enable = PTA_ALLOW_PA_SD_DEF;
60790921014SLuciano Coelho 	param->pta_auto_mode_enable = PTA_AUTO_MODE_NO_CTS_DEF;
60890921014SLuciano Coelho 	param->bt_hp_respected_num = PTA_BT_HP_RESPECTED_DEF;
60990921014SLuciano Coelho 
61090921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param));
61190921014SLuciano Coelho 	if (ret < 0) {
61290921014SLuciano Coelho 		wl1251_warning("failed to set sg config: %d", ret);
61390921014SLuciano Coelho 		goto out;
61490921014SLuciano Coelho 	}
61590921014SLuciano Coelho 
61690921014SLuciano Coelho out:
61790921014SLuciano Coelho 	kfree(param);
61890921014SLuciano Coelho 	return ret;
61990921014SLuciano Coelho }
62090921014SLuciano Coelho 
62190921014SLuciano Coelho int wl1251_acx_cca_threshold(struct wl1251 *wl)
62290921014SLuciano Coelho {
62390921014SLuciano Coelho 	struct acx_energy_detection *detection;
62490921014SLuciano Coelho 	int ret;
62590921014SLuciano Coelho 
62690921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx cca threshold");
62790921014SLuciano Coelho 
62890921014SLuciano Coelho 	detection = kzalloc(sizeof(*detection), GFP_KERNEL);
62960ce473eSJing Wang 	if (!detection)
63060ce473eSJing Wang 		return -ENOMEM;
63190921014SLuciano Coelho 
63290921014SLuciano Coelho 	detection->rx_cca_threshold = CCA_THRSH_DISABLE_ENERGY_D;
63390921014SLuciano Coelho 	detection->tx_energy_detection = 0;
63490921014SLuciano Coelho 
63590921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, ACX_CCA_THRESHOLD,
63690921014SLuciano Coelho 				   detection, sizeof(*detection));
63790921014SLuciano Coelho 	if (ret < 0)
63890921014SLuciano Coelho 		wl1251_warning("failed to set cca threshold: %d", ret);
63990921014SLuciano Coelho 
64090921014SLuciano Coelho 	kfree(detection);
64190921014SLuciano Coelho 	return ret;
64290921014SLuciano Coelho }
64390921014SLuciano Coelho 
64490921014SLuciano Coelho int wl1251_acx_bcn_dtim_options(struct wl1251 *wl)
64590921014SLuciano Coelho {
64690921014SLuciano Coelho 	struct acx_beacon_broadcast *bb;
64790921014SLuciano Coelho 	int ret;
64890921014SLuciano Coelho 
64990921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx bcn dtim options");
65090921014SLuciano Coelho 
65190921014SLuciano Coelho 	bb = kzalloc(sizeof(*bb), GFP_KERNEL);
65260ce473eSJing Wang 	if (!bb)
65360ce473eSJing Wang 		return -ENOMEM;
65490921014SLuciano Coelho 
65590921014SLuciano Coelho 	bb->beacon_rx_timeout = BCN_RX_TIMEOUT_DEF_VALUE;
65690921014SLuciano Coelho 	bb->broadcast_timeout = BROADCAST_RX_TIMEOUT_DEF_VALUE;
65790921014SLuciano Coelho 	bb->rx_broadcast_in_ps = RX_BROADCAST_IN_PS_DEF_VALUE;
65890921014SLuciano Coelho 	bb->ps_poll_threshold = CONSECUTIVE_PS_POLL_FAILURE_DEF;
65990921014SLuciano Coelho 
66090921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, ACX_BCN_DTIM_OPTIONS, bb, sizeof(*bb));
66190921014SLuciano Coelho 	if (ret < 0) {
66290921014SLuciano Coelho 		wl1251_warning("failed to set rx config: %d", ret);
66390921014SLuciano Coelho 		goto out;
66490921014SLuciano Coelho 	}
66590921014SLuciano Coelho 
66690921014SLuciano Coelho out:
66790921014SLuciano Coelho 	kfree(bb);
66890921014SLuciano Coelho 	return ret;
66990921014SLuciano Coelho }
67090921014SLuciano Coelho 
67190921014SLuciano Coelho int wl1251_acx_aid(struct wl1251 *wl, u16 aid)
67290921014SLuciano Coelho {
67390921014SLuciano Coelho 	struct acx_aid *acx_aid;
67490921014SLuciano Coelho 	int ret;
67590921014SLuciano Coelho 
67690921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx aid");
67790921014SLuciano Coelho 
67890921014SLuciano Coelho 	acx_aid = kzalloc(sizeof(*acx_aid), GFP_KERNEL);
67960ce473eSJing Wang 	if (!acx_aid)
68060ce473eSJing Wang 		return -ENOMEM;
68190921014SLuciano Coelho 
68290921014SLuciano Coelho 	acx_aid->aid = aid;
68390921014SLuciano Coelho 
68490921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid));
68590921014SLuciano Coelho 	if (ret < 0) {
68690921014SLuciano Coelho 		wl1251_warning("failed to set aid: %d", ret);
68790921014SLuciano Coelho 		goto out;
68890921014SLuciano Coelho 	}
68990921014SLuciano Coelho 
69090921014SLuciano Coelho out:
69190921014SLuciano Coelho 	kfree(acx_aid);
69290921014SLuciano Coelho 	return ret;
69390921014SLuciano Coelho }
69490921014SLuciano Coelho 
69590921014SLuciano Coelho int wl1251_acx_event_mbox_mask(struct wl1251 *wl, u32 event_mask)
69690921014SLuciano Coelho {
69790921014SLuciano Coelho 	struct acx_event_mask *mask;
69890921014SLuciano Coelho 	int ret;
69990921014SLuciano Coelho 
70090921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx event mbox mask");
70190921014SLuciano Coelho 
70290921014SLuciano Coelho 	mask = kzalloc(sizeof(*mask), GFP_KERNEL);
70360ce473eSJing Wang 	if (!mask)
70460ce473eSJing Wang 		return -ENOMEM;
70590921014SLuciano Coelho 
70690921014SLuciano Coelho 	/* high event mask is unused */
70790921014SLuciano Coelho 	mask->high_event_mask = 0xffffffff;
70890921014SLuciano Coelho 
70990921014SLuciano Coelho 	mask->event_mask = event_mask;
71090921014SLuciano Coelho 
71190921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, ACX_EVENT_MBOX_MASK,
71290921014SLuciano Coelho 				   mask, sizeof(*mask));
71390921014SLuciano Coelho 	if (ret < 0) {
71490921014SLuciano Coelho 		wl1251_warning("failed to set acx_event_mbox_mask: %d", ret);
71590921014SLuciano Coelho 		goto out;
71690921014SLuciano Coelho 	}
71790921014SLuciano Coelho 
71890921014SLuciano Coelho out:
71990921014SLuciano Coelho 	kfree(mask);
72090921014SLuciano Coelho 	return ret;
72190921014SLuciano Coelho }
72290921014SLuciano Coelho 
72390921014SLuciano Coelho int wl1251_acx_low_rssi(struct wl1251 *wl, s8 threshold, u8 weight,
72490921014SLuciano Coelho 			u8 depth, enum wl1251_acx_low_rssi_type type)
72590921014SLuciano Coelho {
72690921014SLuciano Coelho 	struct acx_low_rssi *rssi;
72790921014SLuciano Coelho 	int ret;
72890921014SLuciano Coelho 
72990921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx low rssi");
73090921014SLuciano Coelho 
73190921014SLuciano Coelho 	rssi = kzalloc(sizeof(*rssi), GFP_KERNEL);
73290921014SLuciano Coelho 	if (!rssi)
73390921014SLuciano Coelho 		return -ENOMEM;
73490921014SLuciano Coelho 
73590921014SLuciano Coelho 	rssi->threshold = threshold;
73690921014SLuciano Coelho 	rssi->weight = weight;
73790921014SLuciano Coelho 	rssi->depth = depth;
73890921014SLuciano Coelho 	rssi->type = type;
73990921014SLuciano Coelho 
74090921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, ACX_LOW_RSSI, rssi, sizeof(*rssi));
74190921014SLuciano Coelho 	if (ret < 0)
74290921014SLuciano Coelho 		wl1251_warning("failed to set low rssi threshold: %d", ret);
74390921014SLuciano Coelho 
74490921014SLuciano Coelho 	kfree(rssi);
74590921014SLuciano Coelho 	return ret;
74690921014SLuciano Coelho }
74790921014SLuciano Coelho 
74890921014SLuciano Coelho int wl1251_acx_set_preamble(struct wl1251 *wl, enum acx_preamble_type preamble)
74990921014SLuciano Coelho {
75090921014SLuciano Coelho 	struct acx_preamble *acx;
75190921014SLuciano Coelho 	int ret;
75290921014SLuciano Coelho 
75390921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx_set_preamble");
75490921014SLuciano Coelho 
75590921014SLuciano Coelho 	acx = kzalloc(sizeof(*acx), GFP_KERNEL);
75660ce473eSJing Wang 	if (!acx)
75760ce473eSJing Wang 		return -ENOMEM;
75890921014SLuciano Coelho 
75990921014SLuciano Coelho 	acx->preamble = preamble;
76090921014SLuciano Coelho 
76190921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx));
76290921014SLuciano Coelho 	if (ret < 0) {
76390921014SLuciano Coelho 		wl1251_warning("Setting of preamble failed: %d", ret);
76490921014SLuciano Coelho 		goto out;
76590921014SLuciano Coelho 	}
76690921014SLuciano Coelho 
76790921014SLuciano Coelho out:
76890921014SLuciano Coelho 	kfree(acx);
76990921014SLuciano Coelho 	return ret;
77090921014SLuciano Coelho }
77190921014SLuciano Coelho 
77290921014SLuciano Coelho int wl1251_acx_cts_protect(struct wl1251 *wl,
77390921014SLuciano Coelho 			   enum acx_ctsprotect_type ctsprotect)
77490921014SLuciano Coelho {
77590921014SLuciano Coelho 	struct acx_ctsprotect *acx;
77690921014SLuciano Coelho 	int ret;
77790921014SLuciano Coelho 
77890921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx_set_ctsprotect");
77990921014SLuciano Coelho 
78090921014SLuciano Coelho 	acx = kzalloc(sizeof(*acx), GFP_KERNEL);
78160ce473eSJing Wang 	if (!acx)
78260ce473eSJing Wang 		return -ENOMEM;
78390921014SLuciano Coelho 
78490921014SLuciano Coelho 	acx->ctsprotect = ctsprotect;
78590921014SLuciano Coelho 
78690921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx));
78790921014SLuciano Coelho 	if (ret < 0) {
78890921014SLuciano Coelho 		wl1251_warning("Setting of ctsprotect failed: %d", ret);
78990921014SLuciano Coelho 		goto out;
79090921014SLuciano Coelho 	}
79190921014SLuciano Coelho 
79290921014SLuciano Coelho out:
79390921014SLuciano Coelho 	kfree(acx);
79490921014SLuciano Coelho 	return ret;
79590921014SLuciano Coelho }
79690921014SLuciano Coelho 
79790921014SLuciano Coelho int wl1251_acx_tsf_info(struct wl1251 *wl, u64 *mactime)
79890921014SLuciano Coelho {
79990921014SLuciano Coelho 	struct acx_tsf_info *tsf_info;
80090921014SLuciano Coelho 	int ret;
80190921014SLuciano Coelho 
80290921014SLuciano Coelho 	tsf_info = kzalloc(sizeof(*tsf_info), GFP_KERNEL);
80360ce473eSJing Wang 	if (!tsf_info)
80460ce473eSJing Wang 		return -ENOMEM;
80590921014SLuciano Coelho 
80690921014SLuciano Coelho 	ret = wl1251_cmd_interrogate(wl, ACX_TSF_INFO,
80790921014SLuciano Coelho 				     tsf_info, sizeof(*tsf_info));
80890921014SLuciano Coelho 	if (ret < 0) {
80990921014SLuciano Coelho 		wl1251_warning("ACX_FW_REV interrogate failed");
81090921014SLuciano Coelho 		goto out;
81190921014SLuciano Coelho 	}
81290921014SLuciano Coelho 
81390921014SLuciano Coelho 	*mactime = tsf_info->current_tsf_lsb |
814cae6247dSGrazvydas Ignotas 		((u64)tsf_info->current_tsf_msb << 32);
81590921014SLuciano Coelho 
81690921014SLuciano Coelho out:
81790921014SLuciano Coelho 	kfree(tsf_info);
81890921014SLuciano Coelho 	return ret;
81990921014SLuciano Coelho }
82090921014SLuciano Coelho 
82190921014SLuciano Coelho int wl1251_acx_statistics(struct wl1251 *wl, struct acx_statistics *stats)
82290921014SLuciano Coelho {
82390921014SLuciano Coelho 	int ret;
82490921014SLuciano Coelho 
82590921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx statistics");
82690921014SLuciano Coelho 
82790921014SLuciano Coelho 	ret = wl1251_cmd_interrogate(wl, ACX_STATISTICS, stats,
82890921014SLuciano Coelho 				     sizeof(*stats));
82990921014SLuciano Coelho 	if (ret < 0) {
83090921014SLuciano Coelho 		wl1251_warning("acx statistics failed: %d", ret);
83190921014SLuciano Coelho 		return -ENOMEM;
83290921014SLuciano Coelho 	}
83390921014SLuciano Coelho 
83490921014SLuciano Coelho 	return 0;
83590921014SLuciano Coelho }
83690921014SLuciano Coelho 
83790921014SLuciano Coelho int wl1251_acx_rate_policies(struct wl1251 *wl)
83890921014SLuciano Coelho {
83990921014SLuciano Coelho 	struct acx_rate_policy *acx;
84090921014SLuciano Coelho 	int ret = 0;
84190921014SLuciano Coelho 
84290921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx rate policies");
84390921014SLuciano Coelho 
84490921014SLuciano Coelho 	acx = kzalloc(sizeof(*acx), GFP_KERNEL);
84560ce473eSJing Wang 	if (!acx)
84660ce473eSJing Wang 		return -ENOMEM;
84790921014SLuciano Coelho 
84890921014SLuciano Coelho 	/* configure one default (one-size-fits-all) rate class */
84990921014SLuciano Coelho 	acx->rate_class_cnt = 1;
85090921014SLuciano Coelho 	acx->rate_class[0].enabled_rates = ACX_RATE_MASK_UNSPECIFIED;
85190921014SLuciano Coelho 	acx->rate_class[0].short_retry_limit = ACX_RATE_RETRY_LIMIT;
85290921014SLuciano Coelho 	acx->rate_class[0].long_retry_limit = ACX_RATE_RETRY_LIMIT;
85390921014SLuciano Coelho 	acx->rate_class[0].aflags = 0;
85490921014SLuciano Coelho 
85590921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
85690921014SLuciano Coelho 	if (ret < 0) {
85790921014SLuciano Coelho 		wl1251_warning("Setting of rate policies failed: %d", ret);
85890921014SLuciano Coelho 		goto out;
85990921014SLuciano Coelho 	}
86090921014SLuciano Coelho 
86190921014SLuciano Coelho out:
86290921014SLuciano Coelho 	kfree(acx);
86390921014SLuciano Coelho 	return ret;
86490921014SLuciano Coelho }
86590921014SLuciano Coelho 
86690921014SLuciano Coelho int wl1251_acx_mem_cfg(struct wl1251 *wl)
86790921014SLuciano Coelho {
86890921014SLuciano Coelho 	struct wl1251_acx_config_memory *mem_conf;
86990921014SLuciano Coelho 	int ret, i;
87090921014SLuciano Coelho 
87190921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx mem cfg");
87290921014SLuciano Coelho 
87390921014SLuciano Coelho 	mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL);
87460ce473eSJing Wang 	if (!mem_conf)
87560ce473eSJing Wang 		return -ENOMEM;
87690921014SLuciano Coelho 
87790921014SLuciano Coelho 	/* memory config */
87890921014SLuciano Coelho 	mem_conf->mem_config.num_stations = cpu_to_le16(DEFAULT_NUM_STATIONS);
87990921014SLuciano Coelho 	mem_conf->mem_config.rx_mem_block_num = 35;
88090921014SLuciano Coelho 	mem_conf->mem_config.tx_min_mem_block_num = 64;
88190921014SLuciano Coelho 	mem_conf->mem_config.num_tx_queues = MAX_TX_QUEUES;
88290921014SLuciano Coelho 	mem_conf->mem_config.host_if_options = HOSTIF_PKT_RING;
88390921014SLuciano Coelho 	mem_conf->mem_config.num_ssid_profiles = 1;
88490921014SLuciano Coelho 	mem_conf->mem_config.debug_buffer_size =
88590921014SLuciano Coelho 		cpu_to_le16(TRACE_BUFFER_MAX_SIZE);
88690921014SLuciano Coelho 
88790921014SLuciano Coelho 	/* RX queue config */
88890921014SLuciano Coelho 	mem_conf->rx_queue_config.dma_address = 0;
88990921014SLuciano Coelho 	mem_conf->rx_queue_config.num_descs = ACX_RX_DESC_DEF;
89090921014SLuciano Coelho 	mem_conf->rx_queue_config.priority = DEFAULT_RXQ_PRIORITY;
89190921014SLuciano Coelho 	mem_conf->rx_queue_config.type = DEFAULT_RXQ_TYPE;
89290921014SLuciano Coelho 
89390921014SLuciano Coelho 	/* TX queue config */
89490921014SLuciano Coelho 	for (i = 0; i < MAX_TX_QUEUES; i++) {
89590921014SLuciano Coelho 		mem_conf->tx_queue_config[i].num_descs = ACX_TX_DESC_DEF;
89690921014SLuciano Coelho 		mem_conf->tx_queue_config[i].attributes = i;
89790921014SLuciano Coelho 	}
89890921014SLuciano Coelho 
89990921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, ACX_MEM_CFG, mem_conf,
90090921014SLuciano Coelho 				   sizeof(*mem_conf));
90190921014SLuciano Coelho 	if (ret < 0) {
90290921014SLuciano Coelho 		wl1251_warning("wl1251 mem config failed: %d", ret);
90390921014SLuciano Coelho 		goto out;
90490921014SLuciano Coelho 	}
90590921014SLuciano Coelho 
90690921014SLuciano Coelho out:
90790921014SLuciano Coelho 	kfree(mem_conf);
90890921014SLuciano Coelho 	return ret;
90990921014SLuciano Coelho }
91090921014SLuciano Coelho 
91190921014SLuciano Coelho int wl1251_acx_wr_tbtt_and_dtim(struct wl1251 *wl, u16 tbtt, u8 dtim)
91290921014SLuciano Coelho {
91390921014SLuciano Coelho 	struct wl1251_acx_wr_tbtt_and_dtim *acx;
91490921014SLuciano Coelho 	int ret;
91590921014SLuciano Coelho 
91690921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx tbtt and dtim");
91790921014SLuciano Coelho 
91890921014SLuciano Coelho 	acx = kzalloc(sizeof(*acx), GFP_KERNEL);
91960ce473eSJing Wang 	if (!acx)
92060ce473eSJing Wang 		return -ENOMEM;
92190921014SLuciano Coelho 
92290921014SLuciano Coelho 	acx->tbtt = tbtt;
92390921014SLuciano Coelho 	acx->dtim = dtim;
92490921014SLuciano Coelho 
92590921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, ACX_WR_TBTT_AND_DTIM,
92690921014SLuciano Coelho 				   acx, sizeof(*acx));
92790921014SLuciano Coelho 	if (ret < 0) {
92890921014SLuciano Coelho 		wl1251_warning("failed to set tbtt and dtim: %d", ret);
92990921014SLuciano Coelho 		goto out;
93090921014SLuciano Coelho 	}
93190921014SLuciano Coelho 
93290921014SLuciano Coelho out:
93390921014SLuciano Coelho 	kfree(acx);
93490921014SLuciano Coelho 	return ret;
93590921014SLuciano Coelho }
93690921014SLuciano Coelho 
93790921014SLuciano Coelho int wl1251_acx_bet_enable(struct wl1251 *wl, enum wl1251_acx_bet_mode mode,
93890921014SLuciano Coelho 			  u8 max_consecutive)
93990921014SLuciano Coelho {
94090921014SLuciano Coelho 	struct wl1251_acx_bet_enable *acx;
94190921014SLuciano Coelho 	int ret;
94290921014SLuciano Coelho 
94390921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx bet enable");
94490921014SLuciano Coelho 
94590921014SLuciano Coelho 	acx = kzalloc(sizeof(*acx), GFP_KERNEL);
94660ce473eSJing Wang 	if (!acx)
94760ce473eSJing Wang 		return -ENOMEM;
94890921014SLuciano Coelho 
94990921014SLuciano Coelho 	acx->enable = mode;
95090921014SLuciano Coelho 	acx->max_consecutive = max_consecutive;
95190921014SLuciano Coelho 
95290921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, ACX_BET_ENABLE, acx, sizeof(*acx));
95390921014SLuciano Coelho 	if (ret < 0) {
95490921014SLuciano Coelho 		wl1251_warning("wl1251 acx bet enable failed: %d", ret);
95590921014SLuciano Coelho 		goto out;
95690921014SLuciano Coelho 	}
95790921014SLuciano Coelho 
95890921014SLuciano Coelho out:
95990921014SLuciano Coelho 	kfree(acx);
96090921014SLuciano Coelho 	return ret;
96190921014SLuciano Coelho }
96290921014SLuciano Coelho 
963204cc5c4SDavid Gnedt int wl1251_acx_arp_ip_filter(struct wl1251 *wl, bool enable, __be32 address)
964204cc5c4SDavid Gnedt {
965204cc5c4SDavid Gnedt 	struct wl1251_acx_arp_filter *acx;
966204cc5c4SDavid Gnedt 	int ret;
967204cc5c4SDavid Gnedt 
968204cc5c4SDavid Gnedt 	wl1251_debug(DEBUG_ACX, "acx arp ip filter, enable: %d", enable);
969204cc5c4SDavid Gnedt 
970204cc5c4SDavid Gnedt 	acx = kzalloc(sizeof(*acx), GFP_KERNEL);
971204cc5c4SDavid Gnedt 	if (!acx)
972204cc5c4SDavid Gnedt 		return -ENOMEM;
973204cc5c4SDavid Gnedt 
974204cc5c4SDavid Gnedt 	acx->version = ACX_IPV4_VERSION;
975204cc5c4SDavid Gnedt 	acx->enable = enable;
976204cc5c4SDavid Gnedt 
977204cc5c4SDavid Gnedt 	if (enable)
978204cc5c4SDavid Gnedt 		memcpy(acx->address, &address, ACX_IPV4_ADDR_SIZE);
979204cc5c4SDavid Gnedt 
980204cc5c4SDavid Gnedt 	ret = wl1251_cmd_configure(wl, ACX_ARP_IP_FILTER,
981204cc5c4SDavid Gnedt 				   acx, sizeof(*acx));
982204cc5c4SDavid Gnedt 	if (ret < 0)
983204cc5c4SDavid Gnedt 		wl1251_warning("failed to set arp ip filter: %d", ret);
984204cc5c4SDavid Gnedt 
985204cc5c4SDavid Gnedt 	kfree(acx);
986204cc5c4SDavid Gnedt 	return ret;
987204cc5c4SDavid Gnedt }
988204cc5c4SDavid Gnedt 
98990921014SLuciano Coelho int wl1251_acx_ac_cfg(struct wl1251 *wl, u8 ac, u8 cw_min, u16 cw_max,
99090921014SLuciano Coelho 		      u8 aifs, u16 txop)
99190921014SLuciano Coelho {
99290921014SLuciano Coelho 	struct wl1251_acx_ac_cfg *acx;
99390921014SLuciano Coelho 	int ret = 0;
99490921014SLuciano Coelho 
99590921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx ac cfg %d cw_ming %d cw_max %d "
99690921014SLuciano Coelho 		     "aifs %d txop %d", ac, cw_min, cw_max, aifs, txop);
99790921014SLuciano Coelho 
99890921014SLuciano Coelho 	acx = kzalloc(sizeof(*acx), GFP_KERNEL);
99960ce473eSJing Wang 	if (!acx)
100060ce473eSJing Wang 		return -ENOMEM;
100190921014SLuciano Coelho 
100290921014SLuciano Coelho 	acx->ac = ac;
100390921014SLuciano Coelho 	acx->cw_min = cw_min;
100490921014SLuciano Coelho 	acx->cw_max = cw_max;
100590921014SLuciano Coelho 	acx->aifsn = aifs;
100690921014SLuciano Coelho 	acx->txop_limit = txop;
100790921014SLuciano Coelho 
100890921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, ACX_AC_CFG, acx, sizeof(*acx));
100990921014SLuciano Coelho 	if (ret < 0) {
101090921014SLuciano Coelho 		wl1251_warning("acx ac cfg failed: %d", ret);
101190921014SLuciano Coelho 		goto out;
101290921014SLuciano Coelho 	}
101390921014SLuciano Coelho 
101490921014SLuciano Coelho out:
101590921014SLuciano Coelho 	kfree(acx);
101690921014SLuciano Coelho 	return ret;
101790921014SLuciano Coelho }
101890921014SLuciano Coelho 
101990921014SLuciano Coelho int wl1251_acx_tid_cfg(struct wl1251 *wl, u8 queue,
102090921014SLuciano Coelho 		       enum wl1251_acx_channel_type type,
102190921014SLuciano Coelho 		       u8 tsid, enum wl1251_acx_ps_scheme ps_scheme,
102290921014SLuciano Coelho 		       enum wl1251_acx_ack_policy ack_policy)
102390921014SLuciano Coelho {
102490921014SLuciano Coelho 	struct wl1251_acx_tid_cfg *acx;
102590921014SLuciano Coelho 	int ret = 0;
102690921014SLuciano Coelho 
102790921014SLuciano Coelho 	wl1251_debug(DEBUG_ACX, "acx tid cfg %d type %d tsid %d "
102890921014SLuciano Coelho 		     "ps_scheme %d ack_policy %d", queue, type, tsid,
102990921014SLuciano Coelho 		     ps_scheme, ack_policy);
103090921014SLuciano Coelho 
103190921014SLuciano Coelho 	acx = kzalloc(sizeof(*acx), GFP_KERNEL);
103260ce473eSJing Wang 	if (!acx)
103360ce473eSJing Wang 		return -ENOMEM;
103490921014SLuciano Coelho 
103590921014SLuciano Coelho 	acx->queue = queue;
103690921014SLuciano Coelho 	acx->type = type;
103790921014SLuciano Coelho 	acx->tsid = tsid;
103890921014SLuciano Coelho 	acx->ps_scheme = ps_scheme;
103990921014SLuciano Coelho 	acx->ack_policy = ack_policy;
104090921014SLuciano Coelho 
104190921014SLuciano Coelho 	ret = wl1251_cmd_configure(wl, ACX_TID_CFG, acx, sizeof(*acx));
104290921014SLuciano Coelho 	if (ret < 0) {
104390921014SLuciano Coelho 		wl1251_warning("acx tid cfg failed: %d", ret);
104490921014SLuciano Coelho 		goto out;
104590921014SLuciano Coelho 	}
104690921014SLuciano Coelho 
104790921014SLuciano Coelho out:
104890921014SLuciano Coelho 	kfree(acx);
104990921014SLuciano Coelho 	return ret;
105090921014SLuciano Coelho }
1051