wl1251_acx.c 17.0 KB
Newer Older
1
#include "wl1251_acx.h"
K
Kalle Valo 已提交
2 3 4 5 6

#include <linux/module.h>
#include <linux/crc7.h>
#include <linux/spi/spi.h>

K
Kalle Valo 已提交
7
#include "wl1251.h"
K
Kalle Valo 已提交
8
#include "reg.h"
9 10
#include "wl1251_spi.h"
#include "wl1251_ps.h"
K
Kalle Valo 已提交
11

12
int wl1251_acx_frame_rates(struct wl1251 *wl, u8 ctrl_rate, u8 ctrl_mod,
K
Kalle Valo 已提交
13 14
			   u8 mgt_rate, u8 mgt_mod)
{
15
	struct acx_fw_gen_frame_rates *rates;
K
Kalle Valo 已提交
16 17
	int ret;

18
	wl1251_debug(DEBUG_ACX, "acx frame rates");
K
Kalle Valo 已提交
19

20 21 22 23 24
	rates = kzalloc(sizeof(*rates), GFP_KERNEL);
	if (!rates) {
		ret = -ENOMEM;
		goto out;
	}
K
Kalle Valo 已提交
25

26 27 28 29
	rates->tx_ctrl_frame_rate = ctrl_rate;
	rates->tx_ctrl_frame_mod = ctrl_mod;
	rates->tx_mgt_frame_rate = mgt_rate;
	rates->tx_mgt_frame_mod = mgt_mod;
K
Kalle Valo 已提交
30

31
	ret = wl1251_cmd_configure(wl, ACX_FW_GEN_FRAME_RATES,
32
				   rates, sizeof(*rates));
K
Kalle Valo 已提交
33
	if (ret < 0) {
34
		wl1251_error("Failed to set FW rates and modulation");
35
		goto out;
K
Kalle Valo 已提交
36 37
	}

38 39 40
out:
	kfree(rates);
	return ret;
K
Kalle Valo 已提交
41 42 43
}


44
int wl1251_acx_station_id(struct wl1251 *wl)
K
Kalle Valo 已提交
45
{
46
	struct acx_dot11_station_id *mac;
K
Kalle Valo 已提交
47 48
	int ret, i;

49
	wl1251_debug(DEBUG_ACX, "acx dot11_station_id");
K
Kalle Valo 已提交
50

51 52 53 54 55
	mac = kzalloc(sizeof(*mac), GFP_KERNEL);
	if (!mac) {
		ret = -ENOMEM;
		goto out;
	}
K
Kalle Valo 已提交
56 57

	for (i = 0; i < ETH_ALEN; i++)
58
		mac->mac[i] = wl->mac_addr[ETH_ALEN - 1 - i];
K
Kalle Valo 已提交
59

60
	ret = wl1251_cmd_configure(wl, DOT11_STATION_ID, mac, sizeof(*mac));
K
Kalle Valo 已提交
61
	if (ret < 0)
62
		goto out;
K
Kalle Valo 已提交
63

64 65 66
out:
	kfree(mac);
	return ret;
K
Kalle Valo 已提交
67 68
}

69
int wl1251_acx_default_key(struct wl1251 *wl, u8 key_id)
K
Kalle Valo 已提交
70
{
71
	struct acx_dot11_default_key *default_key;
K
Kalle Valo 已提交
72 73
	int ret;

74
	wl1251_debug(DEBUG_ACX, "acx dot11_default_key (%d)", key_id);
K
Kalle Valo 已提交
75

76 77 78 79 80
	default_key = kzalloc(sizeof(*default_key), GFP_KERNEL);
	if (!default_key) {
		ret = -ENOMEM;
		goto out;
	}
K
Kalle Valo 已提交
81

82
	default_key->id = key_id;
K
Kalle Valo 已提交
83

84
	ret = wl1251_cmd_configure(wl, DOT11_DEFAULT_KEY,
85
				   default_key, sizeof(*default_key));
K
Kalle Valo 已提交
86
	if (ret < 0) {
87
		wl1251_error("Couldnt set default key");
88
		goto out;
K
Kalle Valo 已提交
89 90 91 92
	}

	wl->default_key = key_id;

93 94 95
out:
	kfree(default_key);
	return ret;
K
Kalle Valo 已提交
96 97
}

98
int wl1251_acx_wake_up_conditions(struct wl1251 *wl, u8 wake_up_event,
99
				  u8 listen_interval)
K
Kalle Valo 已提交
100
{
101 102
	struct acx_wake_up_condition *wake_up;
	int ret;
K
Kalle Valo 已提交
103

104
	wl1251_debug(DEBUG_ACX, "acx wake up conditions");
K
Kalle Valo 已提交
105

106 107 108 109 110
	wake_up = kzalloc(sizeof(*wake_up), GFP_KERNEL);
	if (!wake_up) {
		ret = -ENOMEM;
		goto out;
	}
K
Kalle Valo 已提交
111

112
	wake_up->wake_up_event = wake_up_event;
113
	wake_up->listen_interval = listen_interval;
K
Kalle Valo 已提交
114

115
	ret = wl1251_cmd_configure(wl, ACX_WAKE_UP_CONDITIONS,
116 117
				   wake_up, sizeof(*wake_up));
	if (ret < 0) {
118
		wl1251_warning("could not set wake up conditions: %d", ret);
119 120 121 122 123 124
		goto out;
	}

out:
	kfree(wake_up);
	return ret;
K
Kalle Valo 已提交
125 126
}

127
int wl1251_acx_sleep_auth(struct wl1251 *wl, u8 sleep_auth)
K
Kalle Valo 已提交
128
{
129
	struct acx_sleep_auth *auth;
K
Kalle Valo 已提交
130 131
	int ret;

132
	wl1251_debug(DEBUG_ACX, "acx sleep auth");
K
Kalle Valo 已提交
133

134 135 136 137 138
	auth = kzalloc(sizeof(*auth), GFP_KERNEL);
	if (!auth) {
		ret = -ENOMEM;
		goto out;
	}
K
Kalle Valo 已提交
139

140
	auth->sleep_auth = sleep_auth;
K
Kalle Valo 已提交
141

142
	ret = wl1251_cmd_configure(wl, ACX_SLEEP_AUTH, auth, sizeof(*auth));
K
Kalle Valo 已提交
143 144 145
	if (ret < 0)
		return ret;

146 147 148
out:
	kfree(auth);
	return ret;
K
Kalle Valo 已提交
149 150
}

151
int wl1251_acx_fw_version(struct wl1251 *wl, char *buf, size_t len)
K
Kalle Valo 已提交
152 153 154 155
{
	struct acx_revision *rev;
	int ret;

156
	wl1251_debug(DEBUG_ACX, "acx fw rev");
K
Kalle Valo 已提交
157

158 159 160 161 162
	rev = kzalloc(sizeof(*rev), GFP_KERNEL);
	if (!rev) {
		ret = -ENOMEM;
		goto out;
	}
K
Kalle Valo 已提交
163

164
	ret = wl1251_cmd_interrogate(wl, ACX_FW_REV, rev, sizeof(*rev));
K
Kalle Valo 已提交
165
	if (ret < 0) {
166
		wl1251_warning("ACX_FW_REV interrogate failed");
167
		goto out;
K
Kalle Valo 已提交
168 169 170 171 172 173 174 175 176 177 178 179
	}

	/* be careful with the buffer sizes */
	strncpy(buf, rev->fw_version, min(len, sizeof(rev->fw_version)));

	/*
	 * if the firmware version string is exactly
	 * sizeof(rev->fw_version) long or fw_len is less than
	 * sizeof(rev->fw_version) it won't be null terminated
	 */
	buf[min(len, sizeof(rev->fw_version)) - 1] = '\0';

180 181 182
out:
	kfree(rev);
	return ret;
K
Kalle Valo 已提交
183 184
}

185
int wl1251_acx_tx_power(struct wl1251 *wl, int power)
K
Kalle Valo 已提交
186
{
187
	struct acx_current_tx_power *acx;
K
Kalle Valo 已提交
188 189
	int ret;

190
	wl1251_debug(DEBUG_ACX, "acx dot11_cur_tx_pwr");
K
Kalle Valo 已提交
191 192 193 194

	if (power < 0 || power > 25)
		return -EINVAL;

195 196 197 198 199
	acx = kzalloc(sizeof(*acx), GFP_KERNEL);
	if (!acx) {
		ret = -ENOMEM;
		goto out;
	}
K
Kalle Valo 已提交
200

201
	acx->current_tx_power = power * 10;
K
Kalle Valo 已提交
202

203
	ret = wl1251_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx));
K
Kalle Valo 已提交
204
	if (ret < 0) {
205
		wl1251_warning("configure of tx power failed: %d", ret);
206
		goto out;
K
Kalle Valo 已提交
207 208
	}

209 210 211
out:
	kfree(acx);
	return ret;
K
Kalle Valo 已提交
212 213
}

214
int wl1251_acx_feature_cfg(struct wl1251 *wl)
K
Kalle Valo 已提交
215
{
216
	struct acx_feature_config *feature;
K
Kalle Valo 已提交
217 218
	int ret;

219
	wl1251_debug(DEBUG_ACX, "acx feature cfg");
K
Kalle Valo 已提交
220

221 222 223 224 225
	feature = kzalloc(sizeof(*feature), GFP_KERNEL);
	if (!feature) {
		ret = -ENOMEM;
		goto out;
	}
K
Kalle Valo 已提交
226 227

	/* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */
228 229
	feature->data_flow_options = 0;
	feature->options = 0;
K
Kalle Valo 已提交
230

231
	ret = wl1251_cmd_configure(wl, ACX_FEATURE_CFG,
232 233
				   feature, sizeof(*feature));
	if (ret < 0) {
234
		wl1251_error("Couldnt set HW encryption");
235 236
		goto out;
	}
K
Kalle Valo 已提交
237

238 239
out:
	kfree(feature);
K
Kalle Valo 已提交
240 241 242
	return ret;
}

243
int wl1251_acx_mem_map(struct wl1251 *wl, struct acx_header *mem_map,
244
		       size_t len)
K
Kalle Valo 已提交
245 246 247
{
	int ret;

248
	wl1251_debug(DEBUG_ACX, "acx mem map");
K
Kalle Valo 已提交
249

250
	ret = wl1251_cmd_interrogate(wl, ACX_MEM_MAP, mem_map, len);
K
Kalle Valo 已提交
251 252 253 254 255 256
	if (ret < 0)
		return ret;

	return 0;
}

257
int wl1251_acx_data_path_params(struct wl1251 *wl,
258
				struct acx_data_path_params_resp *resp)
K
Kalle Valo 已提交
259
{
260
	struct acx_data_path_params *params;
K
Kalle Valo 已提交
261 262
	int ret;

263
	wl1251_debug(DEBUG_ACX, "acx data path params");
K
Kalle Valo 已提交
264

265 266 267 268 269
	params = kzalloc(sizeof(*params), GFP_KERNEL);
	if (!params) {
		ret = -ENOMEM;
		goto out;
	}
K
Kalle Valo 已提交
270

271 272
	params->rx_packet_ring_chunk_size = DP_RX_PACKET_RING_CHUNK_SIZE;
	params->tx_packet_ring_chunk_size = DP_TX_PACKET_RING_CHUNK_SIZE;
K
Kalle Valo 已提交
273

274 275
	params->rx_packet_ring_chunk_num = DP_RX_PACKET_RING_CHUNK_NUM;
	params->tx_packet_ring_chunk_num = DP_TX_PACKET_RING_CHUNK_NUM;
K
Kalle Valo 已提交
276

277
	params->tx_complete_threshold = 1;
K
Kalle Valo 已提交
278

279
	params->tx_complete_ring_depth = FW_TX_CMPLT_BLOCK_SIZE;
K
Kalle Valo 已提交
280

281
	params->tx_complete_timeout = DP_TX_COMPLETE_TIME_OUT;
K
Kalle Valo 已提交
282

283
	ret = wl1251_cmd_configure(wl, ACX_DATA_PATH_PARAMS,
284
				   params, sizeof(*params));
K
Kalle Valo 已提交
285
	if (ret < 0)
286
		goto out;
K
Kalle Valo 已提交
287

288
	/* FIXME: shouldn't this be ACX_DATA_PATH_RESP_PARAMS? */
289
	ret = wl1251_cmd_interrogate(wl, ACX_DATA_PATH_PARAMS,
290
				     resp, sizeof(*resp));
K
Kalle Valo 已提交
291 292

	if (ret < 0) {
293
		wl1251_warning("failed to read data path parameters: %d", ret);
294 295
		goto out;
	} else if (resp->header.cmd.status != CMD_STATUS_SUCCESS) {
296
		wl1251_warning("data path parameter acx status failed");
297 298
		ret = -EIO;
		goto out;
K
Kalle Valo 已提交
299 300
	}

301 302 303
out:
	kfree(params);
	return ret;
K
Kalle Valo 已提交
304 305
}

306
int wl1251_acx_rx_msdu_life_time(struct wl1251 *wl, u32 life_time)
K
Kalle Valo 已提交
307
{
308
	struct acx_rx_msdu_lifetime *acx;
K
Kalle Valo 已提交
309 310
	int ret;

311
	wl1251_debug(DEBUG_ACX, "acx rx msdu life time");
K
Kalle Valo 已提交
312

313 314 315 316 317
	acx = kzalloc(sizeof(*acx), GFP_KERNEL);
	if (!acx) {
		ret = -ENOMEM;
		goto out;
	}
K
Kalle Valo 已提交
318

319
	acx->lifetime = life_time;
320
	ret = wl1251_cmd_configure(wl, DOT11_RX_MSDU_LIFE_TIME,
321
				   acx, sizeof(*acx));
K
Kalle Valo 已提交
322
	if (ret < 0) {
323
		wl1251_warning("failed to set rx msdu life time: %d", ret);
324
		goto out;
K
Kalle Valo 已提交
325 326
	}

327 328 329
out:
	kfree(acx);
	return ret;
K
Kalle Valo 已提交
330 331
}

332
int wl1251_acx_rx_config(struct wl1251 *wl, u32 config, u32 filter)
K
Kalle Valo 已提交
333
{
334
	struct acx_rx_config *rx_config;
K
Kalle Valo 已提交
335 336
	int ret;

337
	wl1251_debug(DEBUG_ACX, "acx rx config");
K
Kalle Valo 已提交
338

339 340 341 342 343 344 345 346
	rx_config = kzalloc(sizeof(*rx_config), GFP_KERNEL);
	if (!rx_config) {
		ret = -ENOMEM;
		goto out;
	}

	rx_config->config_options = config;
	rx_config->filter_options = filter;
K
Kalle Valo 已提交
347

348
	ret = wl1251_cmd_configure(wl, ACX_RX_CFG,
349
				   rx_config, sizeof(*rx_config));
K
Kalle Valo 已提交
350
	if (ret < 0) {
351
		wl1251_warning("failed to set rx config: %d", ret);
352
		goto out;
K
Kalle Valo 已提交
353 354
	}

355 356 357
out:
	kfree(rx_config);
	return ret;
K
Kalle Valo 已提交
358 359
}

360
int wl1251_acx_pd_threshold(struct wl1251 *wl)
K
Kalle Valo 已提交
361
{
362
	struct acx_packet_detection *pd;
K
Kalle Valo 已提交
363 364
	int ret;

365
	wl1251_debug(DEBUG_ACX, "acx data pd threshold");
K
Kalle Valo 已提交
366

367 368 369 370 371 372
	pd = kzalloc(sizeof(*pd), GFP_KERNEL);
	if (!pd) {
		ret = -ENOMEM;
		goto out;
	}

K
Kalle Valo 已提交
373 374
	/* FIXME: threshold value not set */

375
	ret = wl1251_cmd_configure(wl, ACX_PD_THRESHOLD, pd, sizeof(*pd));
K
Kalle Valo 已提交
376
	if (ret < 0) {
377
		wl1251_warning("failed to set pd threshold: %d", ret);
378
		goto out;
K
Kalle Valo 已提交
379 380
	}

381 382
out:
	kfree(pd);
K
Kalle Valo 已提交
383 384 385
	return 0;
}

386
int wl1251_acx_slot(struct wl1251 *wl, enum acx_slot_type slot_time)
K
Kalle Valo 已提交
387
{
388
	struct acx_slot *slot;
K
Kalle Valo 已提交
389 390
	int ret;

391
	wl1251_debug(DEBUG_ACX, "acx slot");
K
Kalle Valo 已提交
392

393 394 395 396 397
	slot = kzalloc(sizeof(*slot), GFP_KERNEL);
	if (!slot) {
		ret = -ENOMEM;
		goto out;
	}
K
Kalle Valo 已提交
398

399 400
	slot->wone_index = STATION_WONE_INDEX;
	slot->slot_time = slot_time;
K
Kalle Valo 已提交
401

402
	ret = wl1251_cmd_configure(wl, ACX_SLOT, slot, sizeof(*slot));
K
Kalle Valo 已提交
403
	if (ret < 0) {
404
		wl1251_warning("failed to set slot time: %d", ret);
405
		goto out;
K
Kalle Valo 已提交
406 407
	}

408 409 410
out:
	kfree(slot);
	return ret;
K
Kalle Valo 已提交
411 412
}

413
int wl1251_acx_group_address_tbl(struct wl1251 *wl)
K
Kalle Valo 已提交
414
{
415
	struct acx_dot11_grp_addr_tbl *acx;
K
Kalle Valo 已提交
416 417
	int ret;

418
	wl1251_debug(DEBUG_ACX, "acx group address tbl");
K
Kalle Valo 已提交
419

420 421 422 423 424
	acx = kzalloc(sizeof(*acx), GFP_KERNEL);
	if (!acx) {
		ret = -ENOMEM;
		goto out;
	}
K
Kalle Valo 已提交
425

426 427 428 429
	/* MAC filtering */
	acx->enabled = 0;
	acx->num_groups = 0;
	memset(acx->mac_table, 0, ADDRESS_GROUP_MAX_LEN);
K
Kalle Valo 已提交
430

431
	ret = wl1251_cmd_configure(wl, DOT11_GROUP_ADDRESS_TBL,
432
				   acx, sizeof(*acx));
K
Kalle Valo 已提交
433
	if (ret < 0) {
434
		wl1251_warning("failed to set group addr table: %d", ret);
435
		goto out;
K
Kalle Valo 已提交
436 437
	}

438 439 440
out:
	kfree(acx);
	return ret;
K
Kalle Valo 已提交
441 442
}

443
int wl1251_acx_service_period_timeout(struct wl1251 *wl)
K
Kalle Valo 已提交
444
{
445
	struct acx_rx_timeout *rx_timeout;
K
Kalle Valo 已提交
446 447
	int ret;

448 449 450 451 452
	rx_timeout = kzalloc(sizeof(*rx_timeout), GFP_KERNEL);
	if (!rx_timeout) {
		ret = -ENOMEM;
		goto out;
	}
K
Kalle Valo 已提交
453

454
	wl1251_debug(DEBUG_ACX, "acx service period timeout");
K
Kalle Valo 已提交
455

456 457
	rx_timeout->ps_poll_timeout = RX_TIMEOUT_PS_POLL_DEF;
	rx_timeout->upsd_timeout = RX_TIMEOUT_UPSD_DEF;
K
Kalle Valo 已提交
458

459
	ret = wl1251_cmd_configure(wl, ACX_SERVICE_PERIOD_TIMEOUT,
460
				   rx_timeout, sizeof(*rx_timeout));
K
Kalle Valo 已提交
461
	if (ret < 0) {
462
		wl1251_warning("failed to set service period timeout: %d",
K
Kalle Valo 已提交
463
			       ret);
464
		goto out;
K
Kalle Valo 已提交
465 466
	}

467 468 469
out:
	kfree(rx_timeout);
	return ret;
K
Kalle Valo 已提交
470 471
}

472
int wl1251_acx_rts_threshold(struct wl1251 *wl, u16 rts_threshold)
K
Kalle Valo 已提交
473
{
474
	struct acx_rts_threshold *rts;
K
Kalle Valo 已提交
475 476
	int ret;

477
	wl1251_debug(DEBUG_ACX, "acx rts threshold");
K
Kalle Valo 已提交
478

479 480 481 482 483
	rts = kzalloc(sizeof(*rts), GFP_KERNEL);
	if (!rts) {
		ret = -ENOMEM;
		goto out;
	}
K
Kalle Valo 已提交
484

485
	rts->threshold = rts_threshold;
K
Kalle Valo 已提交
486

487
	ret = wl1251_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts));
K
Kalle Valo 已提交
488
	if (ret < 0) {
489
		wl1251_warning("failed to set rts threshold: %d", ret);
490
		goto out;
K
Kalle Valo 已提交
491 492
	}

493 494 495
out:
	kfree(rts);
	return ret;
K
Kalle Valo 已提交
496 497
}

498
int wl1251_acx_beacon_filter_opt(struct wl1251 *wl)
K
Kalle Valo 已提交
499
{
500
	struct acx_beacon_filter_option *beacon_filter;
K
Kalle Valo 已提交
501 502
	int ret;

503
	wl1251_debug(DEBUG_ACX, "acx beacon filter opt");
K
Kalle Valo 已提交
504

505 506 507 508 509
	beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL);
	if (!beacon_filter) {
		ret = -ENOMEM;
		goto out;
	}
K
Kalle Valo 已提交
510

511 512
	beacon_filter->enable = 0;
	beacon_filter->max_num_beacons = 0;
K
Kalle Valo 已提交
513

514
	ret = wl1251_cmd_configure(wl, ACX_BEACON_FILTER_OPT,
515
				   beacon_filter, sizeof(*beacon_filter));
K
Kalle Valo 已提交
516
	if (ret < 0) {
517
		wl1251_warning("failed to set beacon filter opt: %d", ret);
518
		goto out;
K
Kalle Valo 已提交
519 520
	}

521 522 523
out:
	kfree(beacon_filter);
	return ret;
K
Kalle Valo 已提交
524 525
}

526
int wl1251_acx_beacon_filter_table(struct wl1251 *wl)
K
Kalle Valo 已提交
527
{
528
	struct acx_beacon_filter_ie_table *ie_table;
K
Kalle Valo 已提交
529 530
	int ret;

531
	wl1251_debug(DEBUG_ACX, "acx beacon filter table");
K
Kalle Valo 已提交
532

533 534 535 536 537
	ie_table = kzalloc(sizeof(*ie_table), GFP_KERNEL);
	if (!ie_table) {
		ret = -ENOMEM;
		goto out;
	}
K
Kalle Valo 已提交
538

539 540
	ie_table->num_ie = 0;
	memset(ie_table->table, 0, BEACON_FILTER_TABLE_MAX_SIZE);
K
Kalle Valo 已提交
541

542
	ret = wl1251_cmd_configure(wl, ACX_BEACON_FILTER_TABLE,
543
				   ie_table, sizeof(*ie_table));
K
Kalle Valo 已提交
544
	if (ret < 0) {
545
		wl1251_warning("failed to set beacon filter table: %d", ret);
546
		goto out;
K
Kalle Valo 已提交
547 548
	}

549 550 551
out:
	kfree(ie_table);
	return ret;
K
Kalle Valo 已提交
552 553
}

554
int wl1251_acx_sg_enable(struct wl1251 *wl)
K
Kalle Valo 已提交
555
{
556
	struct acx_bt_wlan_coex *pta;
K
Kalle Valo 已提交
557 558
	int ret;

559
	wl1251_debug(DEBUG_ACX, "acx sg enable");
K
Kalle Valo 已提交
560

561 562 563 564 565
	pta = kzalloc(sizeof(*pta), GFP_KERNEL);
	if (!pta) {
		ret = -ENOMEM;
		goto out;
	}
K
Kalle Valo 已提交
566

567
	pta->enable = SG_ENABLE;
K
Kalle Valo 已提交
568

569
	ret = wl1251_cmd_configure(wl, ACX_SG_ENABLE, pta, sizeof(*pta));
K
Kalle Valo 已提交
570
	if (ret < 0) {
571
		wl1251_warning("failed to set softgemini enable: %d", ret);
572
		goto out;
K
Kalle Valo 已提交
573 574
	}

575 576 577
out:
	kfree(pta);
	return ret;
K
Kalle Valo 已提交
578 579
}

580
int wl1251_acx_sg_cfg(struct wl1251 *wl)
K
Kalle Valo 已提交
581
{
582
	struct acx_bt_wlan_coex_param *param;
K
Kalle Valo 已提交
583 584
	int ret;

585
	wl1251_debug(DEBUG_ACX, "acx sg cfg");
K
Kalle Valo 已提交
586

587 588 589 590 591 592
	param = kzalloc(sizeof(*param), GFP_KERNEL);
	if (!param) {
		ret = -ENOMEM;
		goto out;
	}

K
Kalle Valo 已提交
593
	/* BT-WLAN coext parameters */
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622
	param->min_rate = RATE_INDEX_24MBPS;
	param->bt_hp_max_time = PTA_BT_HP_MAXTIME_DEF;
	param->wlan_hp_max_time = PTA_WLAN_HP_MAX_TIME_DEF;
	param->sense_disable_timer = PTA_SENSE_DISABLE_TIMER_DEF;
	param->rx_time_bt_hp = PTA_PROTECTIVE_RX_TIME_DEF;
	param->tx_time_bt_hp = PTA_PROTECTIVE_TX_TIME_DEF;
	param->rx_time_bt_hp_fast = PTA_PROTECTIVE_RX_TIME_FAST_DEF;
	param->tx_time_bt_hp_fast = PTA_PROTECTIVE_TX_TIME_FAST_DEF;
	param->wlan_cycle_fast = PTA_CYCLE_TIME_FAST_DEF;
	param->bt_anti_starvation_period = PTA_ANTI_STARVE_PERIOD_DEF;
	param->next_bt_lp_packet = PTA_TIMEOUT_NEXT_BT_LP_PACKET_DEF;
	param->wake_up_beacon = PTA_TIME_BEFORE_BEACON_DEF;
	param->hp_dm_max_guard_time = PTA_HPDM_MAX_TIME_DEF;
	param->next_wlan_packet = PTA_TIME_OUT_NEXT_WLAN_DEF;
	param->antenna_type = PTA_ANTENNA_TYPE_DEF;
	param->signal_type = PTA_SIGNALING_TYPE_DEF;
	param->afh_leverage_on = PTA_AFH_LEVERAGE_ON_DEF;
	param->quiet_cycle_num = PTA_NUMBER_QUIET_CYCLE_DEF;
	param->max_cts = PTA_MAX_NUM_CTS_DEF;
	param->wlan_packets_num = PTA_NUMBER_OF_WLAN_PACKETS_DEF;
	param->bt_packets_num = PTA_NUMBER_OF_BT_PACKETS_DEF;
	param->missed_rx_avalanche = PTA_RX_FOR_AVALANCHE_DEF;
	param->wlan_elp_hp = PTA_ELP_HP_DEF;
	param->bt_anti_starvation_cycles = PTA_ANTI_STARVE_NUM_CYCLE_DEF;
	param->ack_mode_dual_ant = PTA_ACK_MODE_DEF;
	param->pa_sd_enable = PTA_ALLOW_PA_SD_DEF;
	param->pta_auto_mode_enable = PTA_AUTO_MODE_NO_CTS_DEF;
	param->bt_hp_respected_num = PTA_BT_HP_RESPECTED_DEF;

623
	ret = wl1251_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param));
K
Kalle Valo 已提交
624
	if (ret < 0) {
625
		wl1251_warning("failed to set sg config: %d", ret);
626
		goto out;
K
Kalle Valo 已提交
627 628
	}

629 630 631
out:
	kfree(param);
	return ret;
K
Kalle Valo 已提交
632 633
}

634
int wl1251_acx_cca_threshold(struct wl1251 *wl)
K
Kalle Valo 已提交
635
{
636
	struct acx_energy_detection *detection;
K
Kalle Valo 已提交
637 638
	int ret;

639
	wl1251_debug(DEBUG_ACX, "acx cca threshold");
K
Kalle Valo 已提交
640

641 642 643 644 645
	detection = kzalloc(sizeof(*detection), GFP_KERNEL);
	if (!detection) {
		ret = -ENOMEM;
		goto out;
	}
K
Kalle Valo 已提交
646

647 648
	detection->rx_cca_threshold = CCA_THRSH_DISABLE_ENERGY_D;
	detection->tx_energy_detection = 0;
K
Kalle Valo 已提交
649

650
	ret = wl1251_cmd_configure(wl, ACX_CCA_THRESHOLD,
651
				   detection, sizeof(*detection));
K
Kalle Valo 已提交
652
	if (ret < 0) {
653
		wl1251_warning("failed to set cca threshold: %d", ret);
K
Kalle Valo 已提交
654 655 656
		return ret;
	}

657 658 659
out:
	kfree(detection);
	return ret;
K
Kalle Valo 已提交
660 661
}

662
int wl1251_acx_bcn_dtim_options(struct wl1251 *wl)
K
Kalle Valo 已提交
663
{
664
	struct acx_beacon_broadcast *bb;
K
Kalle Valo 已提交
665 666
	int ret;

667
	wl1251_debug(DEBUG_ACX, "acx bcn dtim options");
K
Kalle Valo 已提交
668

669 670 671 672 673
	bb = kzalloc(sizeof(*bb), GFP_KERNEL);
	if (!bb) {
		ret = -ENOMEM;
		goto out;
	}
K
Kalle Valo 已提交
674

675 676 677 678
	bb->beacon_rx_timeout = BCN_RX_TIMEOUT_DEF_VALUE;
	bb->broadcast_timeout = BROADCAST_RX_TIMEOUT_DEF_VALUE;
	bb->rx_broadcast_in_ps = RX_BROADCAST_IN_PS_DEF_VALUE;
	bb->ps_poll_threshold = CONSECUTIVE_PS_POLL_FAILURE_DEF;
K
Kalle Valo 已提交
679

680
	ret = wl1251_cmd_configure(wl, ACX_BCN_DTIM_OPTIONS, bb, sizeof(*bb));
K
Kalle Valo 已提交
681
	if (ret < 0) {
682
		wl1251_warning("failed to set rx config: %d", ret);
683
		goto out;
K
Kalle Valo 已提交
684 685
	}

686 687 688
out:
	kfree(bb);
	return ret;
K
Kalle Valo 已提交
689 690
}

691
int wl1251_acx_aid(struct wl1251 *wl, u16 aid)
K
Kalle Valo 已提交
692
{
693
	struct acx_aid *acx_aid;
K
Kalle Valo 已提交
694 695
	int ret;

696
	wl1251_debug(DEBUG_ACX, "acx aid");
K
Kalle Valo 已提交
697

698 699 700 701 702
	acx_aid = kzalloc(sizeof(*acx_aid), GFP_KERNEL);
	if (!acx_aid) {
		ret = -ENOMEM;
		goto out;
	}
K
Kalle Valo 已提交
703

704
	acx_aid->aid = aid;
K
Kalle Valo 已提交
705

706
	ret = wl1251_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid));
K
Kalle Valo 已提交
707
	if (ret < 0) {
708
		wl1251_warning("failed to set aid: %d", ret);
709
		goto out;
K
Kalle Valo 已提交
710 711
	}

712 713 714
out:
	kfree(acx_aid);
	return ret;
K
Kalle Valo 已提交
715 716
}

717
int wl1251_acx_event_mbox_mask(struct wl1251 *wl, u32 event_mask)
K
Kalle Valo 已提交
718
{
719
	struct acx_event_mask *mask;
K
Kalle Valo 已提交
720 721
	int ret;

722
	wl1251_debug(DEBUG_ACX, "acx event mbox mask");
K
Kalle Valo 已提交
723

724 725 726 727 728
	mask = kzalloc(sizeof(*mask), GFP_KERNEL);
	if (!mask) {
		ret = -ENOMEM;
		goto out;
	}
K
Kalle Valo 已提交
729 730

	/* high event mask is unused */
731
	mask->high_event_mask = 0xffffffff;
K
Kalle Valo 已提交
732

733
	mask->event_mask = event_mask;
K
Kalle Valo 已提交
734

735
	ret = wl1251_cmd_configure(wl, ACX_EVENT_MBOX_MASK,
736
				   mask, sizeof(*mask));
K
Kalle Valo 已提交
737
	if (ret < 0) {
738
		wl1251_warning("failed to set acx_event_mbox_mask: %d", ret);
739
		goto out;
K
Kalle Valo 已提交
740 741
	}

742 743 744
out:
	kfree(mask);
	return ret;
K
Kalle Valo 已提交
745 746
}

747
int wl1251_acx_set_preamble(struct wl1251 *wl, enum acx_preamble_type preamble)
K
Kalle Valo 已提交
748
{
749
	struct acx_preamble *acx;
K
Kalle Valo 已提交
750 751
	int ret;

752
	wl1251_debug(DEBUG_ACX, "acx_set_preamble");
K
Kalle Valo 已提交
753

754 755 756 757 758
	acx = kzalloc(sizeof(*acx), GFP_KERNEL);
	if (!acx) {
		ret = -ENOMEM;
		goto out;
	}
K
Kalle Valo 已提交
759

760 761
	acx->preamble = preamble;

762
	ret = wl1251_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx));
K
Kalle Valo 已提交
763
	if (ret < 0) {
764
		wl1251_warning("Setting of preamble failed: %d", ret);
765
		goto out;
K
Kalle Valo 已提交
766
	}
767 768 769 770

out:
	kfree(acx);
	return ret;
K
Kalle Valo 已提交
771 772
}

773
int wl1251_acx_cts_protect(struct wl1251 *wl,
K
Kalle Valo 已提交
774 775
			   enum acx_ctsprotect_type ctsprotect)
{
776
	struct acx_ctsprotect *acx;
K
Kalle Valo 已提交
777 778
	int ret;

779
	wl1251_debug(DEBUG_ACX, "acx_set_ctsprotect");
K
Kalle Valo 已提交
780

781 782 783 784 785 786 787
	acx = kzalloc(sizeof(*acx), GFP_KERNEL);
	if (!acx) {
		ret = -ENOMEM;
		goto out;
	}

	acx->ctsprotect = ctsprotect;
K
Kalle Valo 已提交
788

789
	ret = wl1251_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx));
K
Kalle Valo 已提交
790
	if (ret < 0) {
791
		wl1251_warning("Setting of ctsprotect failed: %d", ret);
792
		goto out;
K
Kalle Valo 已提交
793
	}
794 795 796 797

out:
	kfree(acx);
	return ret;
K
Kalle Valo 已提交
798 799
}

800
int wl1251_acx_tsf_info(struct wl1251 *wl, u64 *mactime)
K
Kalle Valo 已提交
801
{
802
	struct acx_tsf_info *tsf_info;
K
Kalle Valo 已提交
803 804
	int ret;

805 806
	tsf_info = kzalloc(sizeof(*tsf_info), GFP_KERNEL);
	if (!tsf_info) {
K
Kalle Valo 已提交
807 808 809 810
		ret = -ENOMEM;
		goto out;
	}

811
	ret = wl1251_cmd_interrogate(wl, ACX_TSF_INFO,
812
				     tsf_info, sizeof(*tsf_info));
K
Kalle Valo 已提交
813
	if (ret < 0) {
814
		wl1251_warning("ACX_FW_REV interrogate failed");
K
Kalle Valo 已提交
815 816 817
		goto out;
	}

818 819
	*mactime = tsf_info->current_tsf_lsb |
		(tsf_info->current_tsf_msb << 31);
K
Kalle Valo 已提交
820 821

out:
822
	kfree(tsf_info);
K
Kalle Valo 已提交
823 824
	return ret;
}
825

826
int wl1251_acx_statistics(struct wl1251 *wl, struct acx_statistics *stats)
827 828 829
{
	int ret;

830
	wl1251_debug(DEBUG_ACX, "acx statistics");
831

832
	ret = wl1251_cmd_interrogate(wl, ACX_STATISTICS, stats,
833 834
				     sizeof(*stats));
	if (ret < 0) {
835
		wl1251_warning("acx statistics failed: %d", ret);
836 837 838 839 840
		return -ENOMEM;
	}

	return 0;
}