init.c 16.8 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
	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
44
				      wl->scan_templ_id_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
	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
51
				      wl->scan_templ_id_5,
52
				      NULL, WL1271_CMD_TEMPL_MAX_SIZE, 0,
53 54 55
				      WL1271_RATE_AUTOMATIC);
	if (ret < 0)
		return ret;
56

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

		ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
67 68
					      wl->sched_scan_templ_id_5,
					      NULL,
69 70 71 72 73 74
					      WL1271_CMD_TEMPL_MAX_SIZE,
					      0, WL1271_RATE_AUTOMATIC);
		if (ret < 0)
			return ret;
	}

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

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

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

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

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

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

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

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

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

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

L
Luciano Coelho 已提交
155 156 157
	return 0;
}

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

	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 已提交
174
	rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
175 176
	ret = wl1271_cmd_template_set(wl, wlvif->role_id,
				      CMD_TEMPL_DEAUTH_AP,
177
				      tmpl, sizeof(*tmpl), 0, rate);
A
Arik Nemtsov 已提交
178 179 180 181 182 183

out:
	kfree(tmpl);
	return ret;
}

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

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

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

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

out:
	kfree(nullfunc);
	return ret;
}

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

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

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

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

out:
	kfree(qosnull);
	return ret;
}

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

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

	return 0;
}

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

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

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

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

	return 0;
}

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

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

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

	return 0;
}

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

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

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

	return 0;
}

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

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

	return 0;
}

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

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

	return 0;
}

336 337 338 339
static int wl12xx_init_fwlog(struct wl1271 *wl)
{
	int ret;

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

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

	return 0;
}

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

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

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

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

	return 0;
}

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

	/* disable the keep-alive feature */
E
Eliad Peller 已提交
379
	ret = wl1271_acx_keep_alive_mode(wl, wlvif, false);
A
Arik Nemtsov 已提交
380 381 382 383 384 385
	if (ret < 0)
		return ret;

	return 0;
}

386
/* generic ap initialization (non vif-specific) */
E
Eliad Peller 已提交
387
static int wl1271_ap_hw_init(struct wl1271 *wl, struct wl12xx_vif *wlvif)
A
Arik Nemtsov 已提交
388
{
389
	int ret;
A
Arik Nemtsov 已提交
390

E
Eliad Peller 已提交
391
	ret = wl1271_init_ap_rates(wl, wlvif);
A
Arik Nemtsov 已提交
392 393 394 395 396 397
	if (ret < 0)
		return ret;

	return 0;
}

398
int wl1271_ap_init_templates(struct wl1271 *wl, struct ieee80211_vif *vif)
A
Arik Nemtsov 已提交
399
{
E
Eliad Peller 已提交
400
	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
A
Arik Nemtsov 已提交
401 402
	int ret;

E
Eliad Peller 已提交
403
	ret = wl1271_ap_init_deauth_template(wl, wlvif);
A
Arik Nemtsov 已提交
404 405 406
	if (ret < 0)
		return ret;

407
	ret = wl1271_ap_init_null_template(wl, vif);
A
Arik Nemtsov 已提交
408 409 410
	if (ret < 0)
		return ret;

411
	ret = wl1271_ap_init_qos_null_template(wl, vif);
A
Arik Nemtsov 已提交
412 413 414
	if (ret < 0)
		return ret;

415 416 417 418
	/*
	 * when operating as AP we want to receive external beacons for
	 * configuring ERP protection.
	 */
E
Eliad Peller 已提交
419
	ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false);
420 421 422
	if (ret < 0)
		return ret;

A
Arik Nemtsov 已提交
423 424 425
	return 0;
}

426 427
static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl,
				      struct ieee80211_vif *vif)
428
{
429
	return wl1271_ap_init_templates(wl, vif);
430 431
}

E
Eliad Peller 已提交
432
int wl1271_init_ap_rates(struct wl1271 *wl, struct wl12xx_vif *wlvif)
433 434 435 436 437
{
	int i, ret;
	struct conf_tx_rate_class rc;
	u32 supported_rates;

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

E
Eliad Peller 已提交
441
	if (wlvif->basic_rate_set == 0)
442 443
		return -EINVAL;

E
Eliad Peller 已提交
444
	rc.enabled_rates = wlvif->basic_rate_set;
445 446 447
	rc.long_retry_limit = 10;
	rc.short_retry_limit = 10;
	rc.aflags = 0;
E
Eliad Peller 已提交
448
	ret = wl1271_acx_ap_rate_policy(wl, &rc, wlvif->ap.mgmt_rate_idx);
449 450 451 452
	if (ret < 0)
		return ret;

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

470 471 472
	/* unconditionally enable HT rates */
	supported_rates |= CONF_TX_MCS_RATES;

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

476 477 478 479 480 481
	/* 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 已提交
482 483
		ret = wl1271_acx_ap_rate_policy(wl, &rc,
						wlvif->ap.ucast_rate_idx[i]);
484 485 486 487 488 489 490
		if (ret < 0)
			return ret;
	}

	return 0;
}

E
Eliad Peller 已提交
491
static int wl1271_set_ba_policies(struct wl1271 *wl, struct wl12xx_vif *wlvif)
L
Levi, Shahar 已提交
492 493
{
	/* Reset the BA RX indicators */
E
Eliad Peller 已提交
494
	wlvif->ba_allowed = true;
495
	wl->ba_rx_session_count = 0;
L
Levi, Shahar 已提交
496

497
	/* BA is supported in STA/AP modes */
E
Eliad Peller 已提交
498 499
	if (wlvif->bss_type != BSS_TYPE_AP_BSS &&
	    wlvif->bss_type != BSS_TYPE_STA_BSS) {
E
Eliad Peller 已提交
500
		wlvif->ba_support = false;
501 502
		return 0;
	}
L
Levi, Shahar 已提交
503

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

506
	/* 802.11n initiator BA session setting */
E
Eliad Peller 已提交
507
	return wl12xx_acx_set_ba_initiator_policy(wl, wlvif);
L
Levi, Shahar 已提交
508 509
}

510
/* vif-specifc initialization */
E
Eliad Peller 已提交
511
static int wl12xx_init_sta_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
512 513 514
{
	int ret;

E
Eliad Peller 已提交
515
	ret = wl1271_acx_group_address_tbl(wl, wlvif, true, NULL, 0);
516 517 518 519
	if (ret < 0)
		return ret;

	/* Initialize connection monitoring thresholds */
E
Eliad Peller 已提交
520
	ret = wl1271_acx_conn_monit_params(wl, wlvif, false);
521 522 523 524
	if (ret < 0)
		return ret;

	/* Beacon filtering */
525
	ret = wl1271_init_sta_beacon_filter(wl, wlvif);
526 527 528 529
	if (ret < 0)
		return ret;

	/* Beacons and broadcast settings */
E
Eliad Peller 已提交
530
	ret = wl1271_init_beacon_broadcast(wl, wlvif);
531 532
	if (ret < 0)
		return ret;
533

534
	/* Configure rssi/snr averaging weights */
E
Eliad Peller 已提交
535
	ret = wl1271_acx_rssi_snr_avg_weights(wl, wlvif);
536 537 538 539 540 541 542
	if (ret < 0)
		return ret;

	return 0;
}

/* vif-specific intialization */
E
Eliad Peller 已提交
543
static int wl12xx_init_ap_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
544 545 546
{
	int ret;

E
Eliad Peller 已提交
547
	ret = wl1271_acx_ap_max_tx_retry(wl, wlvif);
548 549 550 551
	if (ret < 0)
		return ret;

	/* initialize Tx power */
552
	ret = wl1271_acx_tx_power(wl, wlvif, wlvif->power_level);
553 554 555 556 557 558 559
	if (ret < 0)
		return ret;

	return 0;
}

int wl1271_init_vif_specific(struct wl1271 *wl, struct ieee80211_vif *vif)
L
Luciano Coelho 已提交
560
{
E
Eliad Peller 已提交
561
	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
562
	struct conf_tx_ac_category *conf_ac;
563
	struct conf_tx_tid *conf_tid;
E
Eliad Peller 已提交
564
	bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
565 566
	int ret, i;

567 568 569 570 571 572 573 574 575 576 577 578 579 580 581
	/* 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)
582
			ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
583 584 585 586 587 588
		/* Configure for ELP power saving */
		else
			ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);

		if (ret < 0)
			return ret;
589 590
	}

591 592
	/* Mode specific init */
	if (is_ap) {
E
Eliad Peller 已提交
593
		ret = wl1271_ap_hw_init(wl, wlvif);
594 595 596
		if (ret < 0)
			return ret;

E
Eliad Peller 已提交
597
		ret = wl12xx_init_ap_role(wl, wlvif);
598 599 600
		if (ret < 0)
			return ret;
	} else {
E
Eliad Peller 已提交
601
		ret = wl1271_sta_hw_init(wl, wlvif);
602 603 604
		if (ret < 0)
			return ret;

E
Eliad Peller 已提交
605
		ret = wl12xx_init_sta_role(wl, wlvif);
606 607 608 609
		if (ret < 0)
			return ret;
	}

E
Eliad Peller 已提交
610
	wl12xx_init_phy_vif_config(wl, wlvif);
611 612 613 614 615

	/* 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 已提交
616 617 618
		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);
619 620 621 622
		if (ret < 0)
			return ret;

		conf_tid = &wl->conf.tx.tid_conf[i];
E
Eliad Peller 已提交
623
		ret = wl1271_acx_tid_cfg(wl, wlvif,
624 625 626 627 628 629 630 631 632 633 634 635
					 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 已提交
636
	ret = wl1271_acx_feature_cfg(wl, wlvif);
637 638 639 640 641 642 643
	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 已提交
644
		ret = wl1271_sta_hw_init_post_mem(wl, vif);
645 646 647 648 649

	if (ret < 0)
		return ret;

	/* Configure initiator BA sessions policies */
E
Eliad Peller 已提交
650
	ret = wl1271_set_ba_policies(wl, wlvif);
651 652 653
	if (ret < 0)
		return ret;

654 655 656 657
	ret = wlcore_hw_init_vif(wl, wlvif);
	if (ret < 0)
		return ret;

658 659 660 661 662 663 664
	return 0;
}

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

665 666
	/* Chip-specific hw init */
	ret = wl->ops->hw_init(wl);
667 668 669
	if (ret < 0)
		return ret;

670 671 672 673
	/* Init templates */
	ret = wl1271_init_templates_config(wl);
	if (ret < 0)
		return ret;
674

675 676 677 678 679 680
	ret = wl12xx_acx_mem_cfg(wl);
	if (ret < 0)
		return ret;

	/* Configure the FW logger */
	ret = wl12xx_init_fwlog(wl);
L
Luciano Coelho 已提交
681 682 683
	if (ret < 0)
		return ret;

A
Arik Nemtsov 已提交
684 685 686 687 688
	/* Bluetooth WLAN coexistence */
	ret = wl1271_init_pta(wl);
	if (ret < 0)
		return ret;

L
Luciano Coelho 已提交
689 690 691 692 693 694
	/* Default memory configuration */
	ret = wl1271_acx_init_mem_config(wl);
	if (ret < 0)
		return ret;

	/* RX config */
E
Eliad Peller 已提交
695
	ret = wl12xx_init_rx_config(wl);
L
Luciano Coelho 已提交
696 697 698
	if (ret < 0)
		goto out_free_memmap;

699 700 701 702
	ret = wl1271_acx_dco_itrim_params(wl);
	if (ret < 0)
		goto out_free_memmap;

L
Luciano Coelho 已提交
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718
	/* 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 */
719
	ret = wl1271_acx_frag_threshold(wl, wl->hw->wiphy->frag_threshold);
L
Luciano Coelho 已提交
720 721 722 723
	if (ret < 0)
		goto out_free_memmap;

	/* Enable data path */
724
	ret = wl1271_cmd_data_path(wl, 1);
L
Luciano Coelho 已提交
725 726 727
	if (ret < 0)
		goto out_free_memmap;

728 729 730 731 732
	/* configure PM */
	ret = wl1271_acx_pm_config(wl);
	if (ret < 0)
		goto out_free_memmap;

733 734 735 736
	ret = wl12xx_acx_set_rate_mgmt_params(wl);
	if (ret < 0)
		goto out_free_memmap;

737 738 739 740 741
	/* configure hangover */
	ret = wl12xx_acx_config_hangover(wl);
	if (ret < 0)
		goto out_free_memmap;

L
Luciano Coelho 已提交
742 743 744 745
	return 0;

 out_free_memmap:
	kfree(wl->target_mem_map);
746
	wl->target_mem_map = NULL;
L
Luciano Coelho 已提交
747 748 749

	return ret;
}