init.c 17.0 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

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

37
int wl1271_init_templates_config(struct wl1271 *wl)
L
Luciano Coelho 已提交
38
{
39
	int ret, i;
40
	size_t max_size;
L
Luciano Coelho 已提交
41 42

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

50 51
	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
				      CMD_TEMPL_CFG_PROBE_REQ_5,
52
				      NULL, WL1271_CMD_TEMPL_MAX_SIZE, 0,
53 54 55
				      WL1271_RATE_AUTOMATIC);
	if (ret < 0)
		return ret;
56

57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
	if (wl->quirks & WLCORE_QUIRK_DUAL_PROBE_TMPL) {
		ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
					      CMD_TEMPL_APP_PROBE_REQ_2_4, NULL,
					      WL1271_CMD_TEMPL_MAX_SIZE,
					      0, WL1271_RATE_AUTOMATIC);
		if (ret < 0)
			return ret;

		ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
					      CMD_TEMPL_APP_PROBE_REQ_5, NULL,
					      WL1271_CMD_TEMPL_MAX_SIZE,
					      0, WL1271_RATE_AUTOMATIC);
		if (ret < 0)
			return ret;
	}

73 74
	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
				      CMD_TEMPL_NULL_DATA, NULL,
75
				      sizeof(struct wl12xx_null_data_template),
76
				      0, WL1271_RATE_AUTOMATIC);
L
Luciano Coelho 已提交
77 78 79
	if (ret < 0)
		return ret;

80 81
	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
				      CMD_TEMPL_PS_POLL, NULL,
82
				      sizeof(struct wl12xx_ps_poll_template),
83
				      0, WL1271_RATE_AUTOMATIC);
L
Luciano Coelho 已提交
84 85 86
	if (ret < 0)
		return ret;

87 88
	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
				      CMD_TEMPL_QOS_NULL_DATA, NULL,
L
Luciano Coelho 已提交
89
				      sizeof
90
				      (struct ieee80211_qos_hdr),
91
				      0, WL1271_RATE_AUTOMATIC);
L
Luciano Coelho 已提交
92 93 94
	if (ret < 0)
		return ret;

95 96
	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
				      CMD_TEMPL_PROBE_RESPONSE, NULL,
97
				      WL1271_CMD_TEMPL_DFLT_SIZE,
98
				      0, WL1271_RATE_AUTOMATIC);
L
Luciano Coelho 已提交
99 100 101
	if (ret < 0)
		return ret;

102 103
	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
				      CMD_TEMPL_BEACON, NULL,
104
				      WL1271_CMD_TEMPL_DFLT_SIZE,
105
				      0, WL1271_RATE_AUTOMATIC);
L
Luciano Coelho 已提交
106 107 108
	if (ret < 0)
		return ret;

109 110
	max_size = sizeof(struct wl12xx_arp_rsp_template) +
		   WL1271_EXTRA_SPACE_MAX;
111 112
	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
				      CMD_TEMPL_ARP_RSP, NULL,
113
				      max_size,
E
Eliad Peller 已提交
114 115 116 117
				      0, WL1271_RATE_AUTOMATIC);
	if (ret < 0)
		return ret;

118 119 120 121
	/*
	 * Put very large empty placeholders for all templates. These
	 * reserve memory for later.
	 */
122 123
	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
				      CMD_TEMPL_AP_PROBE_RESPONSE, NULL,
124 125 126 127 128
				      WL1271_CMD_TEMPL_MAX_SIZE,
				      0, WL1271_RATE_AUTOMATIC);
	if (ret < 0)
		return ret;

129 130
	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
				      CMD_TEMPL_AP_BEACON, NULL,
131 132 133 134 135
				      WL1271_CMD_TEMPL_MAX_SIZE,
				      0, WL1271_RATE_AUTOMATIC);
	if (ret < 0)
		return ret;

136 137
	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
				      CMD_TEMPL_DEAUTH_AP, NULL,
138 139 140 141 142 143
				      sizeof
				      (struct wl12xx_disconn_template),
				      0, WL1271_RATE_AUTOMATIC);
	if (ret < 0)
		return ret;

144
	for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
145 146
		ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
					      CMD_TEMPL_KLV, NULL,
147 148
					      sizeof(struct ieee80211_qos_hdr),
					      i, WL1271_RATE_AUTOMATIC);
149 150 151 152
		if (ret < 0)
			return ret;
	}

L
Luciano Coelho 已提交
153 154 155
	return 0;
}

E
Eliad Peller 已提交
156 157
static int wl1271_ap_init_deauth_template(struct wl1271 *wl,
					  struct wl12xx_vif *wlvif)
A
Arik Nemtsov 已提交
158 159 160
{
	struct wl12xx_disconn_template *tmpl;
	int ret;
161
	u32 rate;
A
Arik Nemtsov 已提交
162 163 164 165 166 167 168 169 170 171

	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);

E
Eliad Peller 已提交
172
	rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
173 174
	ret = wl1271_cmd_template_set(wl, wlvif->role_id,
				      CMD_TEMPL_DEAUTH_AP,
175
				      tmpl, sizeof(*tmpl), 0, rate);
A
Arik Nemtsov 已提交
176 177 178 179 180 181

out:
	kfree(tmpl);
	return ret;
}

182 183
static int wl1271_ap_init_null_template(struct wl1271 *wl,
					struct ieee80211_vif *vif)
A
Arik Nemtsov 已提交
184
{
E
Eliad Peller 已提交
185
	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
A
Arik Nemtsov 已提交
186 187
	struct ieee80211_hdr_3addr *nullfunc;
	int ret;
188
	u32 rate;
A
Arik Nemtsov 已提交
189 190 191 192 193 194 195 196 197 198 199 200 201

	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 */

202 203
	memcpy(nullfunc->addr2, vif->addr, ETH_ALEN);
	memcpy(nullfunc->addr3, vif->addr, ETH_ALEN);
A
Arik Nemtsov 已提交
204

E
Eliad Peller 已提交
205
	rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
206 207
	ret = wl1271_cmd_template_set(wl, wlvif->role_id,
				      CMD_TEMPL_NULL_DATA, nullfunc,
208
				      sizeof(*nullfunc), 0, rate);
A
Arik Nemtsov 已提交
209 210 211 212 213 214

out:
	kfree(nullfunc);
	return ret;
}

215 216
static int wl1271_ap_init_qos_null_template(struct wl1271 *wl,
					    struct ieee80211_vif *vif)
A
Arik Nemtsov 已提交
217
{
E
Eliad Peller 已提交
218
	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
A
Arik Nemtsov 已提交
219 220
	struct ieee80211_qos_hdr *qosnull;
	int ret;
221
	u32 rate;
A
Arik Nemtsov 已提交
222 223 224 225 226 227 228 229 230 231 232 233 234

	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 */

235 236
	memcpy(qosnull->addr2, vif->addr, ETH_ALEN);
	memcpy(qosnull->addr3, vif->addr, ETH_ALEN);
A
Arik Nemtsov 已提交
237

E
Eliad Peller 已提交
238
	rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
239 240
	ret = wl1271_cmd_template_set(wl, wlvif->role_id,
				      CMD_TEMPL_QOS_NULL_DATA, qosnull,
241
				      sizeof(*qosnull), 0, rate);
A
Arik Nemtsov 已提交
242 243 244 245 246 247

out:
	kfree(qosnull);
	return ret;
}

248
static int wl12xx_init_rx_config(struct wl1271 *wl)
A
Arik Nemtsov 已提交
249 250 251
{
	int ret;

252
	ret = wl1271_acx_rx_msdu_life_time(wl);
A
Arik Nemtsov 已提交
253 254 255 256 257 258
	if (ret < 0)
		return ret;

	return 0;
}

E
Eliad Peller 已提交
259 260
static int wl12xx_init_phy_vif_config(struct wl1271 *wl,
					    struct wl12xx_vif *wlvif)
L
Luciano Coelho 已提交
261 262 263
{
	int ret;

E
Eliad Peller 已提交
264
	ret = wl1271_acx_slot(wl, wlvif, DEFAULT_SLOT_TIME);
L
Luciano Coelho 已提交
265 266 267
	if (ret < 0)
		return ret;

E
Eliad Peller 已提交
268
	ret = wl1271_acx_service_period_timeout(wl, wlvif);
L
Luciano Coelho 已提交
269 270 271
	if (ret < 0)
		return ret;

E
Eliad Peller 已提交
272
	ret = wl1271_acx_rts_threshold(wl, wlvif, wl->hw->wiphy->rts_threshold);
L
Luciano Coelho 已提交
273 274 275 276 277 278
	if (ret < 0)
		return ret;

	return 0;
}

279 280
static int wl1271_init_sta_beacon_filter(struct wl1271 *wl,
					 struct wl12xx_vif *wlvif)
L
Luciano Coelho 已提交
281 282 283
{
	int ret;

284
	ret = wl1271_acx_beacon_filter_table(wl, wlvif);
L
Luciano Coelho 已提交
285 286 287
	if (ret < 0)
		return ret;

288 289
	/* enable beacon filtering */
	ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true);
L
Luciano Coelho 已提交
290 291 292 293 294 295
	if (ret < 0)
		return ret;

	return 0;
}

296
int wl1271_init_pta(struct wl1271 *wl)
L
Luciano Coelho 已提交
297 298 299
{
	int ret;

300
	ret = wl12xx_acx_sg_cfg(wl);
L
Luciano Coelho 已提交
301 302 303
	if (ret < 0)
		return ret;

304
	ret = wl1271_acx_sg_enable(wl, wl->sg_enabled);
L
Luciano Coelho 已提交
305 306 307 308 309 310
	if (ret < 0)
		return ret;

	return 0;
}

311
int wl1271_init_energy_detection(struct wl1271 *wl)
L
Luciano Coelho 已提交
312 313 314 315 316 317 318 319 320 321
{
	int ret;

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

	return 0;
}

E
Eliad Peller 已提交
322 323
static int wl1271_init_beacon_broadcast(struct wl1271 *wl,
					struct wl12xx_vif *wlvif)
L
Luciano Coelho 已提交
324 325 326
{
	int ret;

E
Eliad Peller 已提交
327
	ret = wl1271_acx_bcn_dtim_options(wl, wlvif);
L
Luciano Coelho 已提交
328 329 330 331 332 333
	if (ret < 0)
		return ret;

	return 0;
}

334 335 336 337
static int wl12xx_init_fwlog(struct wl1271 *wl)
{
	int ret;

338
	if (wl->quirks & WLCORE_QUIRK_FWLOG_NOT_IMPLEMENTED)
339 340 341 342 343 344 345 346 347
		return 0;

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

	return 0;
}

348
/* generic sta initialization (non vif-specific) */
E
Eliad Peller 已提交
349
static int wl1271_sta_hw_init(struct wl1271 *wl, struct wl12xx_vif *wlvif)
A
Arik Nemtsov 已提交
350 351 352
{
	int ret;

353
	/* PS config */
E
Eliad Peller 已提交
354
	ret = wl12xx_acx_config_ps(wl, wlvif);
355 356 357
	if (ret < 0)
		return ret;

S
Shahar Levi 已提交
358 359 360 361 362
	/* FM WLAN coexistence */
	ret = wl1271_acx_fm_coex(wl);
	if (ret < 0)
		return ret;

E
Eliad Peller 已提交
363
	ret = wl1271_acx_sta_rate_policies(wl, wlvif);
A
Arik Nemtsov 已提交
364 365 366 367 368 369
	if (ret < 0)
		return ret;

	return 0;
}

E
Eliad Peller 已提交
370 371
static int wl1271_sta_hw_init_post_mem(struct wl1271 *wl,
				       struct ieee80211_vif *vif)
A
Arik Nemtsov 已提交
372
{
E
Eliad Peller 已提交
373
	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
A
Arik Nemtsov 已提交
374 375 376 377
	int ret, i;

	/* disable all keep-alive templates */
	for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
E
Eliad Peller 已提交
378
		ret = wl1271_acx_keep_alive_config(wl, wlvif, i,
A
Arik Nemtsov 已提交
379 380 381 382 383 384
						   ACX_KEEP_ALIVE_TPL_INVALID);
		if (ret < 0)
			return ret;
	}

	/* disable the keep-alive feature */
E
Eliad Peller 已提交
385
	ret = wl1271_acx_keep_alive_mode(wl, wlvif, false);
A
Arik Nemtsov 已提交
386 387 388 389 390 391
	if (ret < 0)
		return ret;

	return 0;
}

392
/* generic ap initialization (non vif-specific) */
E
Eliad Peller 已提交
393
static int wl1271_ap_hw_init(struct wl1271 *wl, struct wl12xx_vif *wlvif)
A
Arik Nemtsov 已提交
394
{
395
	int ret;
A
Arik Nemtsov 已提交
396

E
Eliad Peller 已提交
397
	ret = wl1271_init_ap_rates(wl, wlvif);
A
Arik Nemtsov 已提交
398 399 400 401 402 403
	if (ret < 0)
		return ret;

	return 0;
}

404
int wl1271_ap_init_templates(struct wl1271 *wl, struct ieee80211_vif *vif)
A
Arik Nemtsov 已提交
405
{
E
Eliad Peller 已提交
406
	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
A
Arik Nemtsov 已提交
407 408
	int ret;

E
Eliad Peller 已提交
409
	ret = wl1271_ap_init_deauth_template(wl, wlvif);
A
Arik Nemtsov 已提交
410 411 412
	if (ret < 0)
		return ret;

413
	ret = wl1271_ap_init_null_template(wl, vif);
A
Arik Nemtsov 已提交
414 415 416
	if (ret < 0)
		return ret;

417
	ret = wl1271_ap_init_qos_null_template(wl, vif);
A
Arik Nemtsov 已提交
418 419 420
	if (ret < 0)
		return ret;

421 422 423 424
	/*
	 * when operating as AP we want to receive external beacons for
	 * configuring ERP protection.
	 */
E
Eliad Peller 已提交
425
	ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false);
426 427 428
	if (ret < 0)
		return ret;

A
Arik Nemtsov 已提交
429 430 431
	return 0;
}

432 433
static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl,
				      struct ieee80211_vif *vif)
434
{
435
	return wl1271_ap_init_templates(wl, vif);
436 437
}

E
Eliad Peller 已提交
438
int wl1271_init_ap_rates(struct wl1271 *wl, struct wl12xx_vif *wlvif)
439 440 441 442 443
{
	int i, ret;
	struct conf_tx_rate_class rc;
	u32 supported_rates;

E
Eliad Peller 已提交
444 445
	wl1271_debug(DEBUG_AP, "AP basic rate set: 0x%x",
		     wlvif->basic_rate_set);
446

E
Eliad Peller 已提交
447
	if (wlvif->basic_rate_set == 0)
448 449
		return -EINVAL;

E
Eliad Peller 已提交
450
	rc.enabled_rates = wlvif->basic_rate_set;
451 452 453
	rc.long_retry_limit = 10;
	rc.short_retry_limit = 10;
	rc.aflags = 0;
E
Eliad Peller 已提交
454
	ret = wl1271_acx_ap_rate_policy(wl, &rc, wlvif->ap.mgmt_rate_idx);
455 456 457 458
	if (ret < 0)
		return ret;

	/* use the min basic rate for AP broadcast/multicast */
E
Eliad Peller 已提交
459
	rc.enabled_rates = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
460 461 462
	rc.short_retry_limit = 10;
	rc.long_retry_limit = 10;
	rc.aflags = 0;
E
Eliad Peller 已提交
463
	ret = wl1271_acx_ap_rate_policy(wl, &rc, wlvif->ap.bcast_rate_idx);
464 465 466 467 468 469 470
	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.
	 */
E
Eliad Peller 已提交
471
	if ((wlvif->basic_rate_set & CONF_TX_OFDM_RATES))
472 473 474 475
		supported_rates = CONF_TX_OFDM_RATES;
	else
		supported_rates = CONF_TX_AP_ENABLED_RATES;

476 477 478
	/* unconditionally enable HT rates */
	supported_rates |= CONF_TX_MCS_RATES;

479 480 481
	/* get extra MIMO or wide-chan rates where the HW supports it */
	supported_rates |= wlcore_hw_ap_get_mimo_wide_rate_mask(wl, wlvif);

482 483 484 485 486 487
	/* 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;
E
Eliad Peller 已提交
488 489
		ret = wl1271_acx_ap_rate_policy(wl, &rc,
						wlvif->ap.ucast_rate_idx[i]);
490 491 492 493 494 495 496
		if (ret < 0)
			return ret;
	}

	return 0;
}

E
Eliad Peller 已提交
497
static int wl1271_set_ba_policies(struct wl1271 *wl, struct wl12xx_vif *wlvif)
L
Levi, Shahar 已提交
498 499
{
	/* Reset the BA RX indicators */
E
Eliad Peller 已提交
500
	wlvif->ba_allowed = true;
501
	wl->ba_rx_session_count = 0;
L
Levi, Shahar 已提交
502

503
	/* BA is supported in STA/AP modes */
E
Eliad Peller 已提交
504 505
	if (wlvif->bss_type != BSS_TYPE_AP_BSS &&
	    wlvif->bss_type != BSS_TYPE_STA_BSS) {
E
Eliad Peller 已提交
506
		wlvif->ba_support = false;
507 508
		return 0;
	}
L
Levi, Shahar 已提交
509

E
Eliad Peller 已提交
510
	wlvif->ba_support = true;
L
Levi, Shahar 已提交
511

512
	/* 802.11n initiator BA session setting */
E
Eliad Peller 已提交
513
	return wl12xx_acx_set_ba_initiator_policy(wl, wlvif);
L
Levi, Shahar 已提交
514 515
}

516
/* vif-specifc initialization */
E
Eliad Peller 已提交
517
static int wl12xx_init_sta_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
518 519 520
{
	int ret;

E
Eliad Peller 已提交
521
	ret = wl1271_acx_group_address_tbl(wl, wlvif, true, NULL, 0);
522 523 524 525
	if (ret < 0)
		return ret;

	/* Initialize connection monitoring thresholds */
E
Eliad Peller 已提交
526
	ret = wl1271_acx_conn_monit_params(wl, wlvif, false);
527 528 529 530
	if (ret < 0)
		return ret;

	/* Beacon filtering */
531
	ret = wl1271_init_sta_beacon_filter(wl, wlvif);
532 533 534 535
	if (ret < 0)
		return ret;

	/* Beacons and broadcast settings */
E
Eliad Peller 已提交
536
	ret = wl1271_init_beacon_broadcast(wl, wlvif);
537 538
	if (ret < 0)
		return ret;
539

540
	/* Configure rssi/snr averaging weights */
E
Eliad Peller 已提交
541
	ret = wl1271_acx_rssi_snr_avg_weights(wl, wlvif);
542 543 544 545 546 547 548
	if (ret < 0)
		return ret;

	return 0;
}

/* vif-specific intialization */
E
Eliad Peller 已提交
549
static int wl12xx_init_ap_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
550 551 552
{
	int ret;

E
Eliad Peller 已提交
553
	ret = wl1271_acx_ap_max_tx_retry(wl, wlvif);
554 555 556 557
	if (ret < 0)
		return ret;

	/* initialize Tx power */
558
	ret = wl1271_acx_tx_power(wl, wlvif, wlvif->power_level);
559 560 561 562 563 564 565
	if (ret < 0)
		return ret;

	return 0;
}

int wl1271_init_vif_specific(struct wl1271 *wl, struct ieee80211_vif *vif)
L
Luciano Coelho 已提交
566
{
E
Eliad Peller 已提交
567
	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
568
	struct conf_tx_ac_category *conf_ac;
569
	struct conf_tx_tid *conf_tid;
E
Eliad Peller 已提交
570
	bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
571 572
	int ret, i;

573 574 575 576 577 578 579 580 581 582 583 584 585 586 587
	/* consider all existing roles before configuring psm. */

	if (wl->ap_count == 0 && is_ap) { /* first AP */
		/* Configure for power always on */
		ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
		if (ret < 0)
			return ret;
	/* first STA, no APs */
	} else if (wl->sta_count == 0 && wl->ap_count == 0 && !is_ap) {
		u8 sta_auth = wl->conf.conn.sta_sleep_auth;
		/* Configure for power according to debugfs */
		if (sta_auth != WL1271_PSM_ILLEGAL)
			ret = wl1271_acx_sleep_auth(wl, sta_auth);
		/* Configure for power always on */
		else if (wl->quirks & WLCORE_QUIRK_NO_ELP)
588
			ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
589 590 591 592 593 594
		/* Configure for ELP power saving */
		else
			ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);

		if (ret < 0)
			return ret;
595 596
	}

597 598
	/* Mode specific init */
	if (is_ap) {
E
Eliad Peller 已提交
599
		ret = wl1271_ap_hw_init(wl, wlvif);
600 601 602
		if (ret < 0)
			return ret;

E
Eliad Peller 已提交
603
		ret = wl12xx_init_ap_role(wl, wlvif);
604 605 606
		if (ret < 0)
			return ret;
	} else {
E
Eliad Peller 已提交
607
		ret = wl1271_sta_hw_init(wl, wlvif);
608 609 610
		if (ret < 0)
			return ret;

E
Eliad Peller 已提交
611
		ret = wl12xx_init_sta_role(wl, wlvif);
612 613 614 615
		if (ret < 0)
			return ret;
	}

E
Eliad Peller 已提交
616
	wl12xx_init_phy_vif_config(wl, wlvif);
617 618 619 620 621

	/* Default TID/AC configuration */
	BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
	for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
		conf_ac = &wl->conf.tx.ac_conf[i];
E
Eliad Peller 已提交
622 623 624
		ret = wl1271_acx_ac_cfg(wl, wlvif, conf_ac->ac,
					conf_ac->cw_min, conf_ac->cw_max,
					conf_ac->aifsn, conf_ac->tx_op_limit);
625 626 627 628
		if (ret < 0)
			return ret;

		conf_tid = &wl->conf.tx.tid_conf[i];
E
Eliad Peller 已提交
629
		ret = wl1271_acx_tid_cfg(wl, wlvif,
630 631 632 633 634 635 636 637 638 639 640 641
					 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)
			return ret;
	}

	/* Configure HW encryption */
E
Eliad Peller 已提交
642
	ret = wl1271_acx_feature_cfg(wl, wlvif);
643 644 645 646 647 648 649
	if (ret < 0)
		return ret;

	/* Mode specific init - post mem init */
	if (is_ap)
		ret = wl1271_ap_hw_init_post_mem(wl, vif);
	else
E
Eliad Peller 已提交
650
		ret = wl1271_sta_hw_init_post_mem(wl, vif);
651 652 653 654 655

	if (ret < 0)
		return ret;

	/* Configure initiator BA sessions policies */
E
Eliad Peller 已提交
656
	ret = wl1271_set_ba_policies(wl, wlvif);
657 658 659
	if (ret < 0)
		return ret;

660 661 662 663
	ret = wlcore_hw_init_vif(wl, wlvif);
	if (ret < 0)
		return ret;

664 665 666 667 668 669 670
	return 0;
}

int wl1271_hw_init(struct wl1271 *wl)
{
	int ret;

671 672
	/* Chip-specific hw init */
	ret = wl->ops->hw_init(wl);
673 674 675
	if (ret < 0)
		return ret;

676 677 678 679
	/* Init templates */
	ret = wl1271_init_templates_config(wl);
	if (ret < 0)
		return ret;
680

681 682 683 684 685 686
	ret = wl12xx_acx_mem_cfg(wl);
	if (ret < 0)
		return ret;

	/* Configure the FW logger */
	ret = wl12xx_init_fwlog(wl);
L
Luciano Coelho 已提交
687 688 689
	if (ret < 0)
		return ret;

A
Arik Nemtsov 已提交
690 691 692 693 694
	/* Bluetooth WLAN coexistence */
	ret = wl1271_init_pta(wl);
	if (ret < 0)
		return ret;

L
Luciano Coelho 已提交
695 696 697 698 699 700
	/* Default memory configuration */
	ret = wl1271_acx_init_mem_config(wl);
	if (ret < 0)
		return ret;

	/* RX config */
E
Eliad Peller 已提交
701
	ret = wl12xx_init_rx_config(wl);
L
Luciano Coelho 已提交
702 703 704
	if (ret < 0)
		goto out_free_memmap;

705 706 707 708
	ret = wl1271_acx_dco_itrim_params(wl);
	if (ret < 0)
		goto out_free_memmap;

L
Luciano Coelho 已提交
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724
	/* 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 */
725
	ret = wl1271_acx_frag_threshold(wl, wl->hw->wiphy->frag_threshold);
L
Luciano Coelho 已提交
726 727 728 729
	if (ret < 0)
		goto out_free_memmap;

	/* Enable data path */
730
	ret = wl1271_cmd_data_path(wl, 1);
L
Luciano Coelho 已提交
731 732 733
	if (ret < 0)
		goto out_free_memmap;

734 735 736 737 738
	/* configure PM */
	ret = wl1271_acx_pm_config(wl);
	if (ret < 0)
		goto out_free_memmap;

739 740 741 742
	ret = wl12xx_acx_set_rate_mgmt_params(wl);
	if (ret < 0)
		goto out_free_memmap;

743 744 745 746 747
	/* configure hangover */
	ret = wl12xx_acx_config_hangover(wl);
	if (ret < 0)
		goto out_free_memmap;

L
Luciano Coelho 已提交
748 749 750 751
	return 0;

 out_free_memmap:
	kfree(wl->target_mem_map);
752
	wl->target_mem_map = NULL;
L
Luciano Coelho 已提交
753 754 755

	return ret;
}