init.c 15.4 KB
Newer Older
L
Luciano Coelho 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 * This file is part of wl1271
 *
 * Copyright (C) 2009 Nokia Corporation
 *
 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

#include <linux/kernel.h>
#include <linux/module.h>
26
#include <linux/slab.h>
L
Luciano Coelho 已提交
27

S
Shahar Levi 已提交
28
#include "init.h"
L
Luciano Coelho 已提交
29
#include "wl12xx_80211.h"
S
Shahar Levi 已提交
30 31 32
#include "acx.h"
#include "cmd.h"
#include "reg.h"
A
Arik Nemtsov 已提交
33
#include "tx.h"
34
#include "io.h"
L
Luciano Coelho 已提交
35

A
Arik Nemtsov 已提交
36
int wl1271_sta_init_templates_config(struct wl1271 *wl)
L
Luciano Coelho 已提交
37
{
38
	int ret, i;
L
Luciano Coelho 已提交
39 40 41

	/* send empty templates for fw memory reservation */
	ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, NULL,
42
				      WL1271_CMD_TEMPL_DFLT_SIZE,
43
				      0, WL1271_RATE_AUTOMATIC);
L
Luciano Coelho 已提交
44 45 46
	if (ret < 0)
		return ret;

47
	ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
48
				      NULL, WL1271_CMD_TEMPL_DFLT_SIZE, 0,
49 50 51
				      WL1271_RATE_AUTOMATIC);
	if (ret < 0)
		return ret;
52

L
Luciano Coelho 已提交
53
	ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
54
				      sizeof(struct wl12xx_null_data_template),
55
				      0, WL1271_RATE_AUTOMATIC);
L
Luciano Coelho 已提交
56 57 58 59
	if (ret < 0)
		return ret;

	ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, NULL,
60
				      sizeof(struct wl12xx_ps_poll_template),
61
				      0, WL1271_RATE_AUTOMATIC);
L
Luciano Coelho 已提交
62 63 64 65 66
	if (ret < 0)
		return ret;

	ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
				      sizeof
67
				      (struct wl12xx_qos_null_data_template),
68
				      0, WL1271_RATE_AUTOMATIC);
L
Luciano Coelho 已提交
69 70 71 72
	if (ret < 0)
		return ret;

	ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE, NULL,
73
				      WL1271_CMD_TEMPL_DFLT_SIZE,
74
				      0, WL1271_RATE_AUTOMATIC);
L
Luciano Coelho 已提交
75 76 77 78
	if (ret < 0)
		return ret;

	ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON, NULL,
79
				      WL1271_CMD_TEMPL_DFLT_SIZE,
80
				      0, WL1271_RATE_AUTOMATIC);
L
Luciano Coelho 已提交
81 82 83
	if (ret < 0)
		return ret;

E
Eliad Peller 已提交
84 85 86 87 88 89 90
	ret = wl1271_cmd_template_set(wl, CMD_TEMPL_ARP_RSP, NULL,
				      sizeof
				      (struct wl12xx_arp_rsp_template),
				      0, WL1271_RATE_AUTOMATIC);
	if (ret < 0)
		return ret;

91 92
	for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
		ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV, NULL,
93
					      WL1271_CMD_TEMPL_DFLT_SIZE, i,
94
					      WL1271_RATE_AUTOMATIC);
95 96 97 98
		if (ret < 0)
			return ret;
	}

L
Luciano Coelho 已提交
99 100 101
	return 0;
}

A
Arik Nemtsov 已提交
102 103 104 105
static int wl1271_ap_init_deauth_template(struct wl1271 *wl)
{
	struct wl12xx_disconn_template *tmpl;
	int ret;
106
	u32 rate;
A
Arik Nemtsov 已提交
107 108 109 110 111 112 113 114 115 116

	tmpl = kzalloc(sizeof(*tmpl), GFP_KERNEL);
	if (!tmpl) {
		ret = -ENOMEM;
		goto out;
	}

	tmpl->header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT |
					     IEEE80211_STYPE_DEAUTH);

117
	rate = wl1271_tx_min_rate_get(wl, wl->basic_rate_set);
A
Arik Nemtsov 已提交
118
	ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP,
119
				      tmpl, sizeof(*tmpl), 0, rate);
A
Arik Nemtsov 已提交
120 121 122 123 124 125

out:
	kfree(tmpl);
	return ret;
}

126 127
static int wl1271_ap_init_null_template(struct wl1271 *wl,
					struct ieee80211_vif *vif)
A
Arik Nemtsov 已提交
128 129 130
{
	struct ieee80211_hdr_3addr *nullfunc;
	int ret;
131
	u32 rate;
A
Arik Nemtsov 已提交
132 133 134 135 136 137 138 139 140 141 142 143 144

	nullfunc = kzalloc(sizeof(*nullfunc), GFP_KERNEL);
	if (!nullfunc) {
		ret = -ENOMEM;
		goto out;
	}

	nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
					      IEEE80211_STYPE_NULLFUNC |
					      IEEE80211_FCTL_FROMDS);

	/* nullfunc->addr1 is filled by FW */

145 146
	memcpy(nullfunc->addr2, vif->addr, ETH_ALEN);
	memcpy(nullfunc->addr3, vif->addr, ETH_ALEN);
A
Arik Nemtsov 已提交
147

148
	rate = wl1271_tx_min_rate_get(wl, wl->basic_rate_set);
A
Arik Nemtsov 已提交
149
	ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, nullfunc,
150
				      sizeof(*nullfunc), 0, rate);
A
Arik Nemtsov 已提交
151 152 153 154 155 156

out:
	kfree(nullfunc);
	return ret;
}

157 158
static int wl1271_ap_init_qos_null_template(struct wl1271 *wl,
					    struct ieee80211_vif *vif)
A
Arik Nemtsov 已提交
159 160 161
{
	struct ieee80211_qos_hdr *qosnull;
	int ret;
162
	u32 rate;
A
Arik Nemtsov 已提交
163 164 165 166 167 168 169 170 171 172 173 174 175

	qosnull = kzalloc(sizeof(*qosnull), GFP_KERNEL);
	if (!qosnull) {
		ret = -ENOMEM;
		goto out;
	}

	qosnull->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
					     IEEE80211_STYPE_QOS_NULLFUNC |
					     IEEE80211_FCTL_FROMDS);

	/* qosnull->addr1 is filled by FW */

176 177
	memcpy(qosnull->addr2, vif->addr, ETH_ALEN);
	memcpy(qosnull->addr3, vif->addr, ETH_ALEN);
A
Arik Nemtsov 已提交
178

179
	rate = wl1271_tx_min_rate_get(wl, wl->basic_rate_set);
A
Arik Nemtsov 已提交
180
	ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, qosnull,
181
				      sizeof(*qosnull), 0, rate);
A
Arik Nemtsov 已提交
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196

out:
	kfree(qosnull);
	return ret;
}

static int wl1271_ap_init_templates_config(struct wl1271 *wl)
{
	int ret;

	/*
	 * Put very large empty placeholders for all templates. These
	 * reserve memory for later.
	 */
	ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_PROBE_RESPONSE, NULL,
197
				      WL1271_CMD_TEMPL_MAX_SIZE,
A
Arik Nemtsov 已提交
198 199 200 201 202
				      0, WL1271_RATE_AUTOMATIC);
	if (ret < 0)
		return ret;

	ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_BEACON, NULL,
203
				      WL1271_CMD_TEMPL_MAX_SIZE,
A
Arik Nemtsov 已提交
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
				      0, WL1271_RATE_AUTOMATIC);
	if (ret < 0)
		return ret;

	ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP, NULL,
				      sizeof
				      (struct wl12xx_disconn_template),
				      0, WL1271_RATE_AUTOMATIC);
	if (ret < 0)
		return ret;

	ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
				      sizeof(struct wl12xx_null_data_template),
				      0, WL1271_RATE_AUTOMATIC);
	if (ret < 0)
		return ret;

	ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
				      sizeof
				      (struct wl12xx_qos_null_data_template),
				      0, WL1271_RATE_AUTOMATIC);
	if (ret < 0)
		return ret;

	return 0;
}

E
Eliad Peller 已提交
231
static int wl12xx_init_rx_config(struct wl1271 *wl)
L
Luciano Coelho 已提交
232 233 234
{
	int ret;

235
	ret = wl1271_acx_rx_msdu_life_time(wl);
L
Luciano Coelho 已提交
236 237 238 239 240 241
	if (ret < 0)
		return ret;

	return 0;
}

242
int wl1271_init_phy_config(struct wl1271 *wl)
L
Luciano Coelho 已提交
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
{
	int ret;

	ret = wl1271_acx_pd_threshold(wl);
	if (ret < 0)
		return ret;

	ret = wl1271_acx_slot(wl, DEFAULT_SLOT_TIME);
	if (ret < 0)
		return ret;

	ret = wl1271_acx_service_period_timeout(wl);
	if (ret < 0)
		return ret;

258
	ret = wl1271_acx_rts_threshold(wl, wl->hw->wiphy->rts_threshold);
L
Luciano Coelho 已提交
259 260 261 262 263 264 265 266 267 268
	if (ret < 0)
		return ret;

	return 0;
}

static int wl1271_init_beacon_filter(struct wl1271 *wl)
{
	int ret;

269 270
	/* disable beacon filtering at this stage */
	ret = wl1271_acx_beacon_filter_opt(wl, false);
L
Luciano Coelho 已提交
271 272 273 274 275 276 277 278 279 280
	if (ret < 0)
		return ret;

	ret = wl1271_acx_beacon_filter_table(wl);
	if (ret < 0)
		return ret;

	return 0;
}

281
int wl1271_init_pta(struct wl1271 *wl)
L
Luciano Coelho 已提交
282 283 284
{
	int ret;

285
	ret = wl12xx_acx_sg_cfg(wl);
L
Luciano Coelho 已提交
286 287 288
	if (ret < 0)
		return ret;

289
	ret = wl1271_acx_sg_enable(wl, wl->sg_enabled);
L
Luciano Coelho 已提交
290 291 292 293 294 295
	if (ret < 0)
		return ret;

	return 0;
}

296
int wl1271_init_energy_detection(struct wl1271 *wl)
L
Luciano Coelho 已提交
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
{
	int ret;

	ret = wl1271_acx_cca_threshold(wl);
	if (ret < 0)
		return ret;

	return 0;
}

static int wl1271_init_beacon_broadcast(struct wl1271 *wl)
{
	int ret;

	ret = wl1271_acx_bcn_dtim_options(wl);
	if (ret < 0)
		return ret;

	return 0;
}

318 319 320 321 322 323 324 325 326 327 328 329 330 331
static int wl12xx_init_fwlog(struct wl1271 *wl)
{
	int ret;

	if (wl->quirks & WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED)
		return 0;

	ret = wl12xx_cmd_config_fwlog(wl);
	if (ret < 0)
		return ret;

	return 0;
}

A
Arik Nemtsov 已提交
332 333 334 335
static int wl1271_sta_hw_init(struct wl1271 *wl)
{
	int ret;

336 337 338 339 340
	if (wl->chip.id != CHIP_ID_1283_PG20) {
		ret = wl1271_cmd_ext_radio_parms(wl);
		if (ret < 0)
			return ret;
	}
A
Arik Nemtsov 已提交
341

342 343 344 345 346
	/* PS config */
	ret = wl1271_acx_config_ps(wl);
	if (ret < 0)
		return ret;

A
Arik Nemtsov 已提交
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
	ret = wl1271_sta_init_templates_config(wl);
	if (ret < 0)
		return ret;

	ret = wl1271_acx_group_address_tbl(wl, true, NULL, 0);
	if (ret < 0)
		return ret;

	/* Initialize connection monitoring thresholds */
	ret = wl1271_acx_conn_monit_params(wl, false);
	if (ret < 0)
		return ret;

	/* Beacon filtering */
	ret = wl1271_init_beacon_filter(wl);
	if (ret < 0)
		return ret;

S
Shahar Levi 已提交
365 366 367 368 369
	/* FM WLAN coexistence */
	ret = wl1271_acx_fm_coex(wl);
	if (ret < 0)
		return ret;

A
Arik Nemtsov 已提交
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
	/* Beacons and broadcast settings */
	ret = wl1271_init_beacon_broadcast(wl);
	if (ret < 0)
		return ret;

	/* Configure for ELP power saving */
	ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
	if (ret < 0)
		return ret;

	/* Configure rssi/snr averaging weights */
	ret = wl1271_acx_rssi_snr_avg_weights(wl);
	if (ret < 0)
		return ret;

	ret = wl1271_acx_sta_rate_policies(wl);
	if (ret < 0)
		return ret;

E
Eliad Peller 已提交
389
	ret = wl12xx_acx_mem_cfg(wl);
390 391 392
	if (ret < 0)
		return ret;

393 394 395 396 397
	/* Configure the FW logger */
	ret = wl12xx_init_fwlog(wl);
	if (ret < 0)
		return ret;

A
Arik Nemtsov 已提交
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
	return 0;
}

static int wl1271_sta_hw_init_post_mem(struct wl1271 *wl)
{
	int ret, i;

	/* disable all keep-alive templates */
	for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
		ret = wl1271_acx_keep_alive_config(wl, i,
						   ACX_KEEP_ALIVE_TPL_INVALID);
		if (ret < 0)
			return ret;
	}

	/* disable the keep-alive feature */
	ret = wl1271_acx_keep_alive_mode(wl, false);
	if (ret < 0)
		return ret;

	return 0;
}

static int wl1271_ap_hw_init(struct wl1271 *wl)
{
423
	int ret;
A
Arik Nemtsov 已提交
424 425 426 427 428 429 430 431 432 433

	ret = wl1271_ap_init_templates_config(wl);
	if (ret < 0)
		return ret;

	/* Configure for power always on */
	ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
	if (ret < 0)
		return ret;

434
	ret = wl1271_init_ap_rates(wl);
A
Arik Nemtsov 已提交
435 436 437
	if (ret < 0)
		return ret;

438
	ret = wl1271_acx_ap_max_tx_retry(wl);
A
Arik Nemtsov 已提交
439 440 441
	if (ret < 0)
		return ret;

E
Eliad Peller 已提交
442
	ret = wl12xx_acx_mem_cfg(wl);
443 444 445
	if (ret < 0)
		return ret;

446 447 448 449 450
	/* initialize Tx power */
	ret = wl1271_acx_tx_power(wl, wl->power_level);
	if (ret < 0)
		return ret;

A
Arik Nemtsov 已提交
451 452 453
	return 0;
}

454
int wl1271_ap_init_templates(struct wl1271 *wl, struct ieee80211_vif *vif)
A
Arik Nemtsov 已提交
455 456 457 458 459 460 461
{
	int ret;

	ret = wl1271_ap_init_deauth_template(wl);
	if (ret < 0)
		return ret;

462
	ret = wl1271_ap_init_null_template(wl, vif);
A
Arik Nemtsov 已提交
463 464 465
	if (ret < 0)
		return ret;

466
	ret = wl1271_ap_init_qos_null_template(wl, vif);
A
Arik Nemtsov 已提交
467 468 469
	if (ret < 0)
		return ret;

470 471 472 473
	/*
	 * when operating as AP we want to receive external beacons for
	 * configuring ERP protection.
	 */
474
	ret = wl1271_acx_beacon_filter_opt(wl, false);
475 476 477
	if (ret < 0)
		return ret;

A
Arik Nemtsov 已提交
478 479 480
	return 0;
}

481 482
static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl,
				      struct ieee80211_vif *vif)
483
{
484
	return wl1271_ap_init_templates(wl, vif);
485 486
}

487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506
int wl1271_init_ap_rates(struct wl1271 *wl)
{
	int i, ret;
	struct conf_tx_rate_class rc;
	u32 supported_rates;

	wl1271_debug(DEBUG_AP, "AP basic rate set: 0x%x", wl->basic_rate_set);

	if (wl->basic_rate_set == 0)
		return -EINVAL;

	rc.enabled_rates = wl->basic_rate_set;
	rc.long_retry_limit = 10;
	rc.short_retry_limit = 10;
	rc.aflags = 0;
	ret = wl1271_acx_ap_rate_policy(wl, &rc, ACX_TX_AP_MODE_MGMT_RATE);
	if (ret < 0)
		return ret;

	/* use the min basic rate for AP broadcast/multicast */
507
	rc.enabled_rates = wl1271_tx_min_rate_get(wl, wl->basic_rate_set);
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523
	rc.short_retry_limit = 10;
	rc.long_retry_limit = 10;
	rc.aflags = 0;
	ret = wl1271_acx_ap_rate_policy(wl, &rc, ACX_TX_AP_MODE_BCST_RATE);
	if (ret < 0)
		return ret;

	/*
	 * If the basic rates contain OFDM rates, use OFDM only
	 * rates for unicast TX as well. Else use all supported rates.
	 */
	if ((wl->basic_rate_set & CONF_TX_OFDM_RATES))
		supported_rates = CONF_TX_OFDM_RATES;
	else
		supported_rates = CONF_TX_AP_ENABLED_RATES;

524 525 526
	/* unconditionally enable HT rates */
	supported_rates |= CONF_TX_MCS_RATES;

527 528 529 530 531 532 533 534 535 536 537 538 539 540
	/* configure unicast TX rate classes */
	for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
		rc.enabled_rates = supported_rates;
		rc.short_retry_limit = 10;
		rc.long_retry_limit = 10;
		rc.aflags = 0;
		ret = wl1271_acx_ap_rate_policy(wl, &rc, i);
		if (ret < 0)
			return ret;
	}

	return 0;
}

L
Levi, Shahar 已提交
541 542 543 544
static int wl1271_set_ba_policies(struct wl1271 *wl)
{
	/* Reset the BA RX indicators */
	wl->ba_rx_bitmap = 0;
545
	wl->ba_allowed = true;
546
	wl->ba_rx_session_count = 0;
L
Levi, Shahar 已提交
547

548 549 550 551 552 553
	/* BA is supported in STA/AP modes */
	if (wl->bss_type != BSS_TYPE_AP_BSS &&
	    wl->bss_type != BSS_TYPE_STA_BSS) {
		wl->ba_support = false;
		return 0;
	}
L
Levi, Shahar 已提交
554

555
	wl->ba_support = true;
L
Levi, Shahar 已提交
556

557 558
	/* 802.11n initiator BA session setting */
	return wl12xx_acx_set_ba_initiator_policy(wl);
L
Levi, Shahar 已提交
559 560
}

561 562 563 564 565 566 567
int wl1271_chip_specific_init(struct wl1271 *wl)
{
	int ret = 0;

	if (wl->chip.id == CHIP_ID_1283_PG20) {
		u32 host_cfg_bitmap = HOST_IF_CFG_RX_FIFO_ENABLE;

568
		if (wl->quirks & WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT)
569 570 571 572 573 574 575 576 577 578 579 580 581
			/* Enable SDIO padding */
			host_cfg_bitmap |= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK;

		/* Must be before wl1271_acx_init_mem_config() */
		ret = wl1271_acx_host_if_cfg_bitmap(wl, host_cfg_bitmap);
		if (ret < 0)
			goto out;
	}
out:
	return ret;
}


582
int wl1271_hw_init(struct wl1271 *wl, struct ieee80211_vif *vif)
L
Luciano Coelho 已提交
583
{
584
	struct conf_tx_ac_category *conf_ac;
585
	struct conf_tx_tid *conf_tid;
586
	int ret, i;
A
Arik Nemtsov 已提交
587
	bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
L
Luciano Coelho 已提交
588

589 590 591 592
	if (wl->chip.id == CHIP_ID_1283_PG20)
		ret = wl128x_cmd_general_parms(wl);
	else
		ret = wl1271_cmd_general_parms(wl);
593
	if (ret < 0)
L
Luciano Coelho 已提交
594 595
		return ret;

596 597 598 599
	if (wl->chip.id == CHIP_ID_1283_PG20)
		ret = wl128x_cmd_radio_parms(wl);
	else
		ret = wl1271_cmd_radio_parms(wl);
600
	if (ret < 0)
L
Luciano Coelho 已提交
601 602
		return ret;

603 604 605 606 607
	/* Chip-specific init */
	ret = wl1271_chip_specific_init(wl);
	if (ret < 0)
		return ret;

A
Arik Nemtsov 已提交
608 609 610 611 612
	/* Mode specific init */
	if (is_ap)
		ret = wl1271_ap_hw_init(wl);
	else
		ret = wl1271_sta_hw_init(wl);
613

L
Luciano Coelho 已提交
614 615 616
	if (ret < 0)
		return ret;

A
Arik Nemtsov 已提交
617 618 619 620 621
	/* Bluetooth WLAN coexistence */
	ret = wl1271_init_pta(wl);
	if (ret < 0)
		return ret;

L
Luciano Coelho 已提交
622 623 624 625 626 627
	/* Default memory configuration */
	ret = wl1271_acx_init_mem_config(wl);
	if (ret < 0)
		return ret;

	/* RX config */
E
Eliad Peller 已提交
628
	ret = wl12xx_init_rx_config(wl);
L
Luciano Coelho 已提交
629 630 631 632 633 634 635 636
	if (ret < 0)
		goto out_free_memmap;

	/* PHY layer config */
	ret = wl1271_init_phy_config(wl);
	if (ret < 0)
		goto out_free_memmap;

637 638 639 640
	ret = wl1271_acx_dco_itrim_params(wl);
	if (ret < 0)
		goto out_free_memmap;

L
Luciano Coelho 已提交
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656
	/* Configure TX patch complete interrupt behavior */
	ret = wl1271_acx_tx_config_options(wl);
	if (ret < 0)
		goto out_free_memmap;

	/* RX complete interrupt pacing */
	ret = wl1271_acx_init_rx_interrupt(wl);
	if (ret < 0)
		goto out_free_memmap;

	/* Energy detection */
	ret = wl1271_init_energy_detection(wl);
	if (ret < 0)
		goto out_free_memmap;

	/* Default fragmentation threshold */
657
	ret = wl1271_acx_frag_threshold(wl, wl->hw->wiphy->frag_threshold);
L
Luciano Coelho 已提交
658 659 660
	if (ret < 0)
		goto out_free_memmap;

661 662
	/* Default TID/AC configuration */
	BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
663
	for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
664 665 666 667 668 669 670
		conf_ac = &wl->conf.tx.ac_conf[i];
		ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
					conf_ac->cw_max, conf_ac->aifsn,
					conf_ac->tx_op_limit);
		if (ret < 0)
			goto out_free_memmap;

671 672 673 674 675 676 677 678 679 680 681
		conf_tid = &wl->conf.tx.tid_conf[i];
		ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id,
					 conf_tid->channel_type,
					 conf_tid->tsid,
					 conf_tid->ps_scheme,
					 conf_tid->ack_policy,
					 conf_tid->apsd_conf[0],
					 conf_tid->apsd_conf[1]);
		if (ret < 0)
			goto out_free_memmap;
	}
L
Luciano Coelho 已提交
682 683

	/* Enable data path */
684
	ret = wl1271_cmd_data_path(wl, 1);
L
Luciano Coelho 已提交
685 686 687 688
	if (ret < 0)
		goto out_free_memmap;

	/* Configure HW encryption */
A
Arik Nemtsov 已提交
689
	ret = wl1271_acx_feature_cfg(wl);
L
Luciano Coelho 已提交
690 691 692
	if (ret < 0)
		goto out_free_memmap;

693 694 695 696 697
	/* configure PM */
	ret = wl1271_acx_pm_config(wl);
	if (ret < 0)
		goto out_free_memmap;

A
Arik Nemtsov 已提交
698 699
	/* Mode specific init - post mem init */
	if (is_ap)
700
		ret = wl1271_ap_hw_init_post_mem(wl, vif);
A
Arik Nemtsov 已提交
701 702
	else
		ret = wl1271_sta_hw_init_post_mem(wl);
703

704 705 706
	if (ret < 0)
		goto out_free_memmap;

707 708 709 710
	ret = wl12xx_acx_set_rate_mgmt_params(wl);
	if (ret < 0)
		goto out_free_memmap;

L
Levi, Shahar 已提交
711 712 713 714 715
	/* Configure initiator BA sessions policies */
	ret = wl1271_set_ba_policies(wl);
	if (ret < 0)
		goto out_free_memmap;

716 717 718 719 720
	/* configure hangover */
	ret = wl12xx_acx_config_hangover(wl);
	if (ret < 0)
		goto out_free_memmap;

L
Luciano Coelho 已提交
721 722 723 724
	return 0;

 out_free_memmap:
	kfree(wl->target_mem_map);
725
	wl->target_mem_map = NULL;
L
Luciano Coelho 已提交
726 727 728

	return ret;
}