xref: /openbmc/linux/drivers/net/wireless/ti/wlcore/init.c (revision 3df74f46)
1 /*
2  * This file is part of wl1271
3  *
4  * Copyright (C) 2009 Nokia Corporation
5  *
6  * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * version 2 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  *
22  */
23 
24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/slab.h>
27 
28 #include "debug.h"
29 #include "init.h"
30 #include "wl12xx_80211.h"
31 #include "acx.h"
32 #include "cmd.h"
33 #include "tx.h"
34 #include "io.h"
35 #include "hw_ops.h"
36 
37 int wl1271_init_templates_config(struct wl1271 *wl)
38 {
39 	int ret, i;
40 	size_t max_size;
41 
42 	/* send empty templates for fw memory reservation */
43 	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
44 				      CMD_TEMPL_CFG_PROBE_REQ_2_4, NULL,
45 				      WL1271_CMD_TEMPL_MAX_SIZE,
46 				      0, WL1271_RATE_AUTOMATIC);
47 	if (ret < 0)
48 		return ret;
49 
50 	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
51 				      CMD_TEMPL_CFG_PROBE_REQ_5,
52 				      NULL, WL1271_CMD_TEMPL_MAX_SIZE, 0,
53 				      WL1271_RATE_AUTOMATIC);
54 	if (ret < 0)
55 		return ret;
56 
57 	if (wl->quirks & WLCORE_QUIRK_DUAL_PROBE_TMPL) {
58 		ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
59 					      CMD_TEMPL_APP_PROBE_REQ_2_4, NULL,
60 					      WL1271_CMD_TEMPL_MAX_SIZE,
61 					      0, WL1271_RATE_AUTOMATIC);
62 		if (ret < 0)
63 			return ret;
64 
65 		ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
66 					      CMD_TEMPL_APP_PROBE_REQ_5, NULL,
67 					      WL1271_CMD_TEMPL_MAX_SIZE,
68 					      0, WL1271_RATE_AUTOMATIC);
69 		if (ret < 0)
70 			return ret;
71 	}
72 
73 	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
74 				      CMD_TEMPL_NULL_DATA, NULL,
75 				      sizeof(struct wl12xx_null_data_template),
76 				      0, WL1271_RATE_AUTOMATIC);
77 	if (ret < 0)
78 		return ret;
79 
80 	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
81 				      CMD_TEMPL_PS_POLL, NULL,
82 				      sizeof(struct wl12xx_ps_poll_template),
83 				      0, WL1271_RATE_AUTOMATIC);
84 	if (ret < 0)
85 		return ret;
86 
87 	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
88 				      CMD_TEMPL_QOS_NULL_DATA, NULL,
89 				      sizeof
90 				      (struct ieee80211_qos_hdr),
91 				      0, WL1271_RATE_AUTOMATIC);
92 	if (ret < 0)
93 		return ret;
94 
95 	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
96 				      CMD_TEMPL_PROBE_RESPONSE, NULL,
97 				      WL1271_CMD_TEMPL_DFLT_SIZE,
98 				      0, WL1271_RATE_AUTOMATIC);
99 	if (ret < 0)
100 		return ret;
101 
102 	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
103 				      CMD_TEMPL_BEACON, NULL,
104 				      WL1271_CMD_TEMPL_DFLT_SIZE,
105 				      0, WL1271_RATE_AUTOMATIC);
106 	if (ret < 0)
107 		return ret;
108 
109 	max_size = sizeof(struct wl12xx_arp_rsp_template) +
110 		   WL1271_EXTRA_SPACE_MAX;
111 	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
112 				      CMD_TEMPL_ARP_RSP, NULL,
113 				      max_size,
114 				      0, WL1271_RATE_AUTOMATIC);
115 	if (ret < 0)
116 		return ret;
117 
118 	/*
119 	 * Put very large empty placeholders for all templates. These
120 	 * reserve memory for later.
121 	 */
122 	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
123 				      CMD_TEMPL_AP_PROBE_RESPONSE, NULL,
124 				      WL1271_CMD_TEMPL_MAX_SIZE,
125 				      0, WL1271_RATE_AUTOMATIC);
126 	if (ret < 0)
127 		return ret;
128 
129 	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
130 				      CMD_TEMPL_AP_BEACON, NULL,
131 				      WL1271_CMD_TEMPL_MAX_SIZE,
132 				      0, WL1271_RATE_AUTOMATIC);
133 	if (ret < 0)
134 		return ret;
135 
136 	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
137 				      CMD_TEMPL_DEAUTH_AP, NULL,
138 				      sizeof
139 				      (struct wl12xx_disconn_template),
140 				      0, WL1271_RATE_AUTOMATIC);
141 	if (ret < 0)
142 		return ret;
143 
144 	for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
145 		ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
146 					      CMD_TEMPL_KLV, NULL,
147 					      sizeof(struct ieee80211_qos_hdr),
148 					      i, WL1271_RATE_AUTOMATIC);
149 		if (ret < 0)
150 			return ret;
151 	}
152 
153 	return 0;
154 }
155 
156 static int wl1271_ap_init_deauth_template(struct wl1271 *wl,
157 					  struct wl12xx_vif *wlvif)
158 {
159 	struct wl12xx_disconn_template *tmpl;
160 	int ret;
161 	u32 rate;
162 
163 	tmpl = kzalloc(sizeof(*tmpl), GFP_KERNEL);
164 	if (!tmpl) {
165 		ret = -ENOMEM;
166 		goto out;
167 	}
168 
169 	tmpl->header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT |
170 					     IEEE80211_STYPE_DEAUTH);
171 
172 	rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
173 	ret = wl1271_cmd_template_set(wl, wlvif->role_id,
174 				      CMD_TEMPL_DEAUTH_AP,
175 				      tmpl, sizeof(*tmpl), 0, rate);
176 
177 out:
178 	kfree(tmpl);
179 	return ret;
180 }
181 
182 static int wl1271_ap_init_null_template(struct wl1271 *wl,
183 					struct ieee80211_vif *vif)
184 {
185 	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
186 	struct ieee80211_hdr_3addr *nullfunc;
187 	int ret;
188 	u32 rate;
189 
190 	nullfunc = kzalloc(sizeof(*nullfunc), GFP_KERNEL);
191 	if (!nullfunc) {
192 		ret = -ENOMEM;
193 		goto out;
194 	}
195 
196 	nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
197 					      IEEE80211_STYPE_NULLFUNC |
198 					      IEEE80211_FCTL_FROMDS);
199 
200 	/* nullfunc->addr1 is filled by FW */
201 
202 	memcpy(nullfunc->addr2, vif->addr, ETH_ALEN);
203 	memcpy(nullfunc->addr3, vif->addr, ETH_ALEN);
204 
205 	rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
206 	ret = wl1271_cmd_template_set(wl, wlvif->role_id,
207 				      CMD_TEMPL_NULL_DATA, nullfunc,
208 				      sizeof(*nullfunc), 0, rate);
209 
210 out:
211 	kfree(nullfunc);
212 	return ret;
213 }
214 
215 static int wl1271_ap_init_qos_null_template(struct wl1271 *wl,
216 					    struct ieee80211_vif *vif)
217 {
218 	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
219 	struct ieee80211_qos_hdr *qosnull;
220 	int ret;
221 	u32 rate;
222 
223 	qosnull = kzalloc(sizeof(*qosnull), GFP_KERNEL);
224 	if (!qosnull) {
225 		ret = -ENOMEM;
226 		goto out;
227 	}
228 
229 	qosnull->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
230 					     IEEE80211_STYPE_QOS_NULLFUNC |
231 					     IEEE80211_FCTL_FROMDS);
232 
233 	/* qosnull->addr1 is filled by FW */
234 
235 	memcpy(qosnull->addr2, vif->addr, ETH_ALEN);
236 	memcpy(qosnull->addr3, vif->addr, ETH_ALEN);
237 
238 	rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
239 	ret = wl1271_cmd_template_set(wl, wlvif->role_id,
240 				      CMD_TEMPL_QOS_NULL_DATA, qosnull,
241 				      sizeof(*qosnull), 0, rate);
242 
243 out:
244 	kfree(qosnull);
245 	return ret;
246 }
247 
248 static int wl12xx_init_rx_config(struct wl1271 *wl)
249 {
250 	int ret;
251 
252 	ret = wl1271_acx_rx_msdu_life_time(wl);
253 	if (ret < 0)
254 		return ret;
255 
256 	return 0;
257 }
258 
259 static int wl12xx_init_phy_vif_config(struct wl1271 *wl,
260 					    struct wl12xx_vif *wlvif)
261 {
262 	int ret;
263 
264 	ret = wl1271_acx_slot(wl, wlvif, DEFAULT_SLOT_TIME);
265 	if (ret < 0)
266 		return ret;
267 
268 	ret = wl1271_acx_service_period_timeout(wl, wlvif);
269 	if (ret < 0)
270 		return ret;
271 
272 	ret = wl1271_acx_rts_threshold(wl, wlvif, wl->hw->wiphy->rts_threshold);
273 	if (ret < 0)
274 		return ret;
275 
276 	return 0;
277 }
278 
279 static int wl1271_init_sta_beacon_filter(struct wl1271 *wl,
280 					 struct wl12xx_vif *wlvif)
281 {
282 	int ret;
283 
284 	ret = wl1271_acx_beacon_filter_table(wl, wlvif);
285 	if (ret < 0)
286 		return ret;
287 
288 	/* enable beacon filtering */
289 	ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true);
290 	if (ret < 0)
291 		return ret;
292 
293 	return 0;
294 }
295 
296 int wl1271_init_pta(struct wl1271 *wl)
297 {
298 	int ret;
299 
300 	ret = wl12xx_acx_sg_cfg(wl);
301 	if (ret < 0)
302 		return ret;
303 
304 	ret = wl1271_acx_sg_enable(wl, wl->sg_enabled);
305 	if (ret < 0)
306 		return ret;
307 
308 	return 0;
309 }
310 
311 int wl1271_init_energy_detection(struct wl1271 *wl)
312 {
313 	int ret;
314 
315 	ret = wl1271_acx_cca_threshold(wl);
316 	if (ret < 0)
317 		return ret;
318 
319 	return 0;
320 }
321 
322 static int wl1271_init_beacon_broadcast(struct wl1271 *wl,
323 					struct wl12xx_vif *wlvif)
324 {
325 	int ret;
326 
327 	ret = wl1271_acx_bcn_dtim_options(wl, wlvif);
328 	if (ret < 0)
329 		return ret;
330 
331 	return 0;
332 }
333 
334 static int wl12xx_init_fwlog(struct wl1271 *wl)
335 {
336 	int ret;
337 
338 	if (wl->quirks & WLCORE_QUIRK_FWLOG_NOT_IMPLEMENTED)
339 		return 0;
340 
341 	ret = wl12xx_cmd_config_fwlog(wl);
342 	if (ret < 0)
343 		return ret;
344 
345 	return 0;
346 }
347 
348 /* generic sta initialization (non vif-specific) */
349 static int wl1271_sta_hw_init(struct wl1271 *wl, struct wl12xx_vif *wlvif)
350 {
351 	int ret;
352 
353 	/* PS config */
354 	ret = wl12xx_acx_config_ps(wl, wlvif);
355 	if (ret < 0)
356 		return ret;
357 
358 	/* FM WLAN coexistence */
359 	ret = wl1271_acx_fm_coex(wl);
360 	if (ret < 0)
361 		return ret;
362 
363 	ret = wl1271_acx_sta_rate_policies(wl, wlvif);
364 	if (ret < 0)
365 		return ret;
366 
367 	return 0;
368 }
369 
370 static int wl1271_sta_hw_init_post_mem(struct wl1271 *wl,
371 				       struct ieee80211_vif *vif)
372 {
373 	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
374 	int ret, i;
375 
376 	/* disable all keep-alive templates */
377 	for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
378 		ret = wl1271_acx_keep_alive_config(wl, wlvif, i,
379 						   ACX_KEEP_ALIVE_TPL_INVALID);
380 		if (ret < 0)
381 			return ret;
382 	}
383 
384 	/* disable the keep-alive feature */
385 	ret = wl1271_acx_keep_alive_mode(wl, wlvif, false);
386 	if (ret < 0)
387 		return ret;
388 
389 	return 0;
390 }
391 
392 /* generic ap initialization (non vif-specific) */
393 static int wl1271_ap_hw_init(struct wl1271 *wl, struct wl12xx_vif *wlvif)
394 {
395 	int ret;
396 
397 	ret = wl1271_init_ap_rates(wl, wlvif);
398 	if (ret < 0)
399 		return ret;
400 
401 	return 0;
402 }
403 
404 int wl1271_ap_init_templates(struct wl1271 *wl, struct ieee80211_vif *vif)
405 {
406 	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
407 	int ret;
408 
409 	ret = wl1271_ap_init_deauth_template(wl, wlvif);
410 	if (ret < 0)
411 		return ret;
412 
413 	ret = wl1271_ap_init_null_template(wl, vif);
414 	if (ret < 0)
415 		return ret;
416 
417 	ret = wl1271_ap_init_qos_null_template(wl, vif);
418 	if (ret < 0)
419 		return ret;
420 
421 	/*
422 	 * when operating as AP we want to receive external beacons for
423 	 * configuring ERP protection.
424 	 */
425 	ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false);
426 	if (ret < 0)
427 		return ret;
428 
429 	return 0;
430 }
431 
432 static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl,
433 				      struct ieee80211_vif *vif)
434 {
435 	return wl1271_ap_init_templates(wl, vif);
436 }
437 
438 int wl1271_init_ap_rates(struct wl1271 *wl, struct wl12xx_vif *wlvif)
439 {
440 	int i, ret;
441 	struct conf_tx_rate_class rc;
442 	u32 supported_rates;
443 
444 	wl1271_debug(DEBUG_AP, "AP basic rate set: 0x%x",
445 		     wlvif->basic_rate_set);
446 
447 	if (wlvif->basic_rate_set == 0)
448 		return -EINVAL;
449 
450 	rc.enabled_rates = wlvif->basic_rate_set;
451 	rc.long_retry_limit = 10;
452 	rc.short_retry_limit = 10;
453 	rc.aflags = 0;
454 	ret = wl1271_acx_ap_rate_policy(wl, &rc, wlvif->ap.mgmt_rate_idx);
455 	if (ret < 0)
456 		return ret;
457 
458 	/* use the min basic rate for AP broadcast/multicast */
459 	rc.enabled_rates = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
460 	rc.short_retry_limit = 10;
461 	rc.long_retry_limit = 10;
462 	rc.aflags = 0;
463 	ret = wl1271_acx_ap_rate_policy(wl, &rc, wlvif->ap.bcast_rate_idx);
464 	if (ret < 0)
465 		return ret;
466 
467 	/*
468 	 * If the basic rates contain OFDM rates, use OFDM only
469 	 * rates for unicast TX as well. Else use all supported rates.
470 	 */
471 	if ((wlvif->basic_rate_set & CONF_TX_OFDM_RATES))
472 		supported_rates = CONF_TX_OFDM_RATES;
473 	else
474 		supported_rates = CONF_TX_AP_ENABLED_RATES;
475 
476 	/* unconditionally enable HT rates */
477 	supported_rates |= CONF_TX_MCS_RATES;
478 
479 	/* get extra MIMO or wide-chan rates where the HW supports it */
480 	supported_rates |= wlcore_hw_ap_get_mimo_wide_rate_mask(wl, wlvif);
481 
482 	/* configure unicast TX rate classes */
483 	for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
484 		rc.enabled_rates = supported_rates;
485 		rc.short_retry_limit = 10;
486 		rc.long_retry_limit = 10;
487 		rc.aflags = 0;
488 		ret = wl1271_acx_ap_rate_policy(wl, &rc,
489 						wlvif->ap.ucast_rate_idx[i]);
490 		if (ret < 0)
491 			return ret;
492 	}
493 
494 	return 0;
495 }
496 
497 static int wl1271_set_ba_policies(struct wl1271 *wl, struct wl12xx_vif *wlvif)
498 {
499 	/* Reset the BA RX indicators */
500 	wlvif->ba_allowed = true;
501 	wl->ba_rx_session_count = 0;
502 
503 	/* BA is supported in STA/AP modes */
504 	if (wlvif->bss_type != BSS_TYPE_AP_BSS &&
505 	    wlvif->bss_type != BSS_TYPE_STA_BSS) {
506 		wlvif->ba_support = false;
507 		return 0;
508 	}
509 
510 	wlvif->ba_support = true;
511 
512 	/* 802.11n initiator BA session setting */
513 	return wl12xx_acx_set_ba_initiator_policy(wl, wlvif);
514 }
515 
516 /* vif-specifc initialization */
517 static int wl12xx_init_sta_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
518 {
519 	int ret;
520 
521 	ret = wl1271_acx_group_address_tbl(wl, wlvif, true, NULL, 0);
522 	if (ret < 0)
523 		return ret;
524 
525 	/* Initialize connection monitoring thresholds */
526 	ret = wl1271_acx_conn_monit_params(wl, wlvif, false);
527 	if (ret < 0)
528 		return ret;
529 
530 	/* Beacon filtering */
531 	ret = wl1271_init_sta_beacon_filter(wl, wlvif);
532 	if (ret < 0)
533 		return ret;
534 
535 	/* Beacons and broadcast settings */
536 	ret = wl1271_init_beacon_broadcast(wl, wlvif);
537 	if (ret < 0)
538 		return ret;
539 
540 	/* Configure rssi/snr averaging weights */
541 	ret = wl1271_acx_rssi_snr_avg_weights(wl, wlvif);
542 	if (ret < 0)
543 		return ret;
544 
545 	return 0;
546 }
547 
548 /* vif-specific intialization */
549 static int wl12xx_init_ap_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
550 {
551 	int ret;
552 
553 	ret = wl1271_acx_ap_max_tx_retry(wl, wlvif);
554 	if (ret < 0)
555 		return ret;
556 
557 	/* initialize Tx power */
558 	ret = wl1271_acx_tx_power(wl, wlvif, wlvif->power_level);
559 	if (ret < 0)
560 		return ret;
561 
562 	return 0;
563 }
564 
565 int wl1271_init_vif_specific(struct wl1271 *wl, struct ieee80211_vif *vif)
566 {
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;
570 	bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
571 	int ret, i;
572 
573 	/* consider all existing roles before configuring psm. */
574 
575 	if (wl->ap_count == 0 && is_ap) { /* first AP */
576 		/* Configure for power always on */
577 		ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
578 		if (ret < 0)
579 			return ret;
580 	/* first STA, no APs */
581 	} else if (wl->sta_count == 0 && wl->ap_count == 0 && !is_ap) {
582 		u8 sta_auth = wl->conf.conn.sta_sleep_auth;
583 		/* Configure for power according to debugfs */
584 		if (sta_auth != WL1271_PSM_ILLEGAL)
585 			ret = wl1271_acx_sleep_auth(wl, sta_auth);
586 		/* Configure for power always on */
587 		else if (wl->quirks & WLCORE_QUIRK_NO_ELP)
588 			ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
589 		/* Configure for ELP power saving */
590 		else
591 			ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
592 
593 		if (ret < 0)
594 			return ret;
595 	}
596 
597 	/* Mode specific init */
598 	if (is_ap) {
599 		ret = wl1271_ap_hw_init(wl, wlvif);
600 		if (ret < 0)
601 			return ret;
602 
603 		ret = wl12xx_init_ap_role(wl, wlvif);
604 		if (ret < 0)
605 			return ret;
606 	} else {
607 		ret = wl1271_sta_hw_init(wl, wlvif);
608 		if (ret < 0)
609 			return ret;
610 
611 		ret = wl12xx_init_sta_role(wl, wlvif);
612 		if (ret < 0)
613 			return ret;
614 	}
615 
616 	wl12xx_init_phy_vif_config(wl, wlvif);
617 
618 	/* Default TID/AC configuration */
619 	BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
620 	for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
621 		conf_ac = &wl->conf.tx.ac_conf[i];
622 		ret = wl1271_acx_ac_cfg(wl, wlvif, conf_ac->ac,
623 					conf_ac->cw_min, conf_ac->cw_max,
624 					conf_ac->aifsn, conf_ac->tx_op_limit);
625 		if (ret < 0)
626 			return ret;
627 
628 		conf_tid = &wl->conf.tx.tid_conf[i];
629 		ret = wl1271_acx_tid_cfg(wl, wlvif,
630 					 conf_tid->queue_id,
631 					 conf_tid->channel_type,
632 					 conf_tid->tsid,
633 					 conf_tid->ps_scheme,
634 					 conf_tid->ack_policy,
635 					 conf_tid->apsd_conf[0],
636 					 conf_tid->apsd_conf[1]);
637 		if (ret < 0)
638 			return ret;
639 	}
640 
641 	/* Configure HW encryption */
642 	ret = wl1271_acx_feature_cfg(wl, wlvif);
643 	if (ret < 0)
644 		return ret;
645 
646 	/* Mode specific init - post mem init */
647 	if (is_ap)
648 		ret = wl1271_ap_hw_init_post_mem(wl, vif);
649 	else
650 		ret = wl1271_sta_hw_init_post_mem(wl, vif);
651 
652 	if (ret < 0)
653 		return ret;
654 
655 	/* Configure initiator BA sessions policies */
656 	ret = wl1271_set_ba_policies(wl, wlvif);
657 	if (ret < 0)
658 		return ret;
659 
660 	ret = wlcore_hw_init_vif(wl, wlvif);
661 	if (ret < 0)
662 		return ret;
663 
664 	return 0;
665 }
666 
667 int wl1271_hw_init(struct wl1271 *wl)
668 {
669 	int ret;
670 
671 	/* Chip-specific hw init */
672 	ret = wl->ops->hw_init(wl);
673 	if (ret < 0)
674 		return ret;
675 
676 	/* Init templates */
677 	ret = wl1271_init_templates_config(wl);
678 	if (ret < 0)
679 		return ret;
680 
681 	ret = wl12xx_acx_mem_cfg(wl);
682 	if (ret < 0)
683 		return ret;
684 
685 	/* Configure the FW logger */
686 	ret = wl12xx_init_fwlog(wl);
687 	if (ret < 0)
688 		return ret;
689 
690 	/* Bluetooth WLAN coexistence */
691 	ret = wl1271_init_pta(wl);
692 	if (ret < 0)
693 		return ret;
694 
695 	/* Default memory configuration */
696 	ret = wl1271_acx_init_mem_config(wl);
697 	if (ret < 0)
698 		return ret;
699 
700 	/* RX config */
701 	ret = wl12xx_init_rx_config(wl);
702 	if (ret < 0)
703 		goto out_free_memmap;
704 
705 	ret = wl1271_acx_dco_itrim_params(wl);
706 	if (ret < 0)
707 		goto out_free_memmap;
708 
709 	/* Configure TX patch complete interrupt behavior */
710 	ret = wl1271_acx_tx_config_options(wl);
711 	if (ret < 0)
712 		goto out_free_memmap;
713 
714 	/* RX complete interrupt pacing */
715 	ret = wl1271_acx_init_rx_interrupt(wl);
716 	if (ret < 0)
717 		goto out_free_memmap;
718 
719 	/* Energy detection */
720 	ret = wl1271_init_energy_detection(wl);
721 	if (ret < 0)
722 		goto out_free_memmap;
723 
724 	/* Default fragmentation threshold */
725 	ret = wl1271_acx_frag_threshold(wl, wl->hw->wiphy->frag_threshold);
726 	if (ret < 0)
727 		goto out_free_memmap;
728 
729 	/* Enable data path */
730 	ret = wl1271_cmd_data_path(wl, 1);
731 	if (ret < 0)
732 		goto out_free_memmap;
733 
734 	/* configure PM */
735 	ret = wl1271_acx_pm_config(wl);
736 	if (ret < 0)
737 		goto out_free_memmap;
738 
739 	ret = wl12xx_acx_set_rate_mgmt_params(wl);
740 	if (ret < 0)
741 		goto out_free_memmap;
742 
743 	/* configure hangover */
744 	ret = wl12xx_acx_config_hangover(wl);
745 	if (ret < 0)
746 		goto out_free_memmap;
747 
748 	return 0;
749 
750  out_free_memmap:
751 	kfree(wl->target_mem_map);
752 	wl->target_mem_map = NULL;
753 
754 	return ret;
755 }
756