1f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho/*
2f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * This file is part of wl1271
3f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho *
4f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * Copyright (C) 2009 Nokia Corporation
5f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho *
6f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho *
8f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * This program is free software; you can redistribute it and/or
9f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * modify it under the terms of the GNU General Public License
10f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * version 2 as published by the Free Software Foundation.
11f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho *
12f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * This program is distributed in the hope that it will be useful, but
13f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * WITHOUT ANY WARRANTY; without even the implied warranty of
14f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * General Public License for more details.
16f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho *
17f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * You should have received a copy of the GNU General Public License
18f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * along with this program; if not, write to the Free Software
19f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho * 02110-1301 USA
21f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho *
22f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho */
23f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
24f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho#include <linux/kernel.h>
25f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho#include <linux/module.h>
265a0e3ad6af8660be21ca98a971cd00f331318c05Tejun Heo#include <linux/slab.h>
27f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
280f4e31222a2c0b93f25a87effd2033cb78c7a79cLuciano Coelho#include "debug.h"
2900d201001bd4e8a46e3d03c970abcb72256c368bShahar Levi#include "init.h"
30f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho#include "wl12xx_80211.h"
3100d201001bd4e8a46e3d03c970abcb72256c368bShahar Levi#include "acx.h"
3200d201001bd4e8a46e3d03c970abcb72256c368bShahar Levi#include "cmd.h"
33e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov#include "tx.h"
3448a61477bdc04896bd96d259388a0c42a7019943Shahar Levi#include "io.h"
358a9affc08d676a9fe627361ab6767cdec0740af3Arik Nemtsov#include "hw_ops.h"
36f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
3792c77c734f958474ac73af670834bc32cb833e54Eliad Pellerint wl1271_init_templates_config(struct wl1271 *wl)
38f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho{
39bfb24c9e16921f0e57fcec5180ffa20929832545Juuso Oikarinen	int ret, i;
405ec8a448e0e978103bc5ca7136084b5e2b36989eEliad Peller	size_t max_size;
41f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
42f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	/* send empty templates for fw memory reservation */
43cdaac6281170ee2934ad443cb60fbdd6cf318b64Eliad Peller	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
4478e28062fea51c62280cd17fe6143ed583f83ba0Eliad Peller				      wl->scan_templ_id_2_4, NULL,
45c08e371a683021cfb99632db799bea9b69d176e5Ido Reis				      WL1271_CMD_TEMPL_MAX_SIZE,
46606c1487ac894798121bc2c64d27c1953c5a6210Juuso Oikarinen				      0, WL1271_RATE_AUTOMATIC);
47f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	if (ret < 0)
48f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho		return ret;
49f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
50cdaac6281170ee2934ad443cb60fbdd6cf318b64Eliad Peller	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
5178e28062fea51c62280cd17fe6143ed583f83ba0Eliad Peller				      wl->scan_templ_id_5,
52c08e371a683021cfb99632db799bea9b69d176e5Ido Reis				      NULL, WL1271_CMD_TEMPL_MAX_SIZE, 0,
5311eb54298fa7197cb4187f8a3474ead0709f76ffJuuso Oikarinen				      WL1271_RATE_AUTOMATIC);
5411eb54298fa7197cb4187f8a3474ead0709f76ffJuuso Oikarinen	if (ret < 0)
5511eb54298fa7197cb4187f8a3474ead0709f76ffJuuso Oikarinen		return ret;
56abb0b3bfb2d2411034b721df21c31964265b851eTeemu Paasikivi
573df74f46d88e39a032eb2cc3f2a571b66082acbaYoni Divinsky	if (wl->quirks & WLCORE_QUIRK_DUAL_PROBE_TMPL) {
583df74f46d88e39a032eb2cc3f2a571b66082acbaYoni Divinsky		ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
5978e28062fea51c62280cd17fe6143ed583f83ba0Eliad Peller					      wl->sched_scan_templ_id_2_4,
6078e28062fea51c62280cd17fe6143ed583f83ba0Eliad Peller					      NULL,
613df74f46d88e39a032eb2cc3f2a571b66082acbaYoni Divinsky					      WL1271_CMD_TEMPL_MAX_SIZE,
623df74f46d88e39a032eb2cc3f2a571b66082acbaYoni Divinsky					      0, WL1271_RATE_AUTOMATIC);
633df74f46d88e39a032eb2cc3f2a571b66082acbaYoni Divinsky		if (ret < 0)
643df74f46d88e39a032eb2cc3f2a571b66082acbaYoni Divinsky			return ret;
653df74f46d88e39a032eb2cc3f2a571b66082acbaYoni Divinsky
663df74f46d88e39a032eb2cc3f2a571b66082acbaYoni Divinsky		ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
6778e28062fea51c62280cd17fe6143ed583f83ba0Eliad Peller					      wl->sched_scan_templ_id_5,
6878e28062fea51c62280cd17fe6143ed583f83ba0Eliad Peller					      NULL,
693df74f46d88e39a032eb2cc3f2a571b66082acbaYoni Divinsky					      WL1271_CMD_TEMPL_MAX_SIZE,
703df74f46d88e39a032eb2cc3f2a571b66082acbaYoni Divinsky					      0, WL1271_RATE_AUTOMATIC);
713df74f46d88e39a032eb2cc3f2a571b66082acbaYoni Divinsky		if (ret < 0)
723df74f46d88e39a032eb2cc3f2a571b66082acbaYoni Divinsky			return ret;
733df74f46d88e39a032eb2cc3f2a571b66082acbaYoni Divinsky	}
743df74f46d88e39a032eb2cc3f2a571b66082acbaYoni Divinsky
75cdaac6281170ee2934ad443cb60fbdd6cf318b64Eliad Peller	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
76cdaac6281170ee2934ad443cb60fbdd6cf318b64Eliad Peller				      CMD_TEMPL_NULL_DATA, NULL,
77bfb24c9e16921f0e57fcec5180ffa20929832545Juuso Oikarinen				      sizeof(struct wl12xx_null_data_template),
78606c1487ac894798121bc2c64d27c1953c5a6210Juuso Oikarinen				      0, WL1271_RATE_AUTOMATIC);
79f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	if (ret < 0)
80f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho		return ret;
81f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
82cdaac6281170ee2934ad443cb60fbdd6cf318b64Eliad Peller	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
83cdaac6281170ee2934ad443cb60fbdd6cf318b64Eliad Peller				      CMD_TEMPL_PS_POLL, NULL,
84bfb24c9e16921f0e57fcec5180ffa20929832545Juuso Oikarinen				      sizeof(struct wl12xx_ps_poll_template),
85606c1487ac894798121bc2c64d27c1953c5a6210Juuso Oikarinen				      0, WL1271_RATE_AUTOMATIC);
86f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	if (ret < 0)
87f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho		return ret;
88f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
89cdaac6281170ee2934ad443cb60fbdd6cf318b64Eliad Peller	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
90cdaac6281170ee2934ad443cb60fbdd6cf318b64Eliad Peller				      CMD_TEMPL_QOS_NULL_DATA, NULL,
91f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho				      sizeof
9297127e67218e5970a5a7df0513ded730b19a67e9Eliad Peller				      (struct ieee80211_qos_hdr),
93606c1487ac894798121bc2c64d27c1953c5a6210Juuso Oikarinen				      0, WL1271_RATE_AUTOMATIC);
94f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	if (ret < 0)
95f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho		return ret;
96f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
97cdaac6281170ee2934ad443cb60fbdd6cf318b64Eliad Peller	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
98cdaac6281170ee2934ad443cb60fbdd6cf318b64Eliad Peller				      CMD_TEMPL_PROBE_RESPONSE, NULL,
99154037d1681caaff7d33521b84017ee58b396438Eliad Peller				      WL1271_CMD_TEMPL_DFLT_SIZE,
100606c1487ac894798121bc2c64d27c1953c5a6210Juuso Oikarinen				      0, WL1271_RATE_AUTOMATIC);
101f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	if (ret < 0)
102f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho		return ret;
103f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
104cdaac6281170ee2934ad443cb60fbdd6cf318b64Eliad Peller	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
105cdaac6281170ee2934ad443cb60fbdd6cf318b64Eliad Peller				      CMD_TEMPL_BEACON, NULL,
106154037d1681caaff7d33521b84017ee58b396438Eliad Peller				      WL1271_CMD_TEMPL_DFLT_SIZE,
107606c1487ac894798121bc2c64d27c1953c5a6210Juuso Oikarinen				      0, WL1271_RATE_AUTOMATIC);
108f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	if (ret < 0)
109f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho		return ret;
110f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
1115ec8a448e0e978103bc5ca7136084b5e2b36989eEliad Peller	max_size = sizeof(struct wl12xx_arp_rsp_template) +
1125ec8a448e0e978103bc5ca7136084b5e2b36989eEliad Peller		   WL1271_EXTRA_SPACE_MAX;
113cdaac6281170ee2934ad443cb60fbdd6cf318b64Eliad Peller	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
114cdaac6281170ee2934ad443cb60fbdd6cf318b64Eliad Peller				      CMD_TEMPL_ARP_RSP, NULL,
1155ec8a448e0e978103bc5ca7136084b5e2b36989eEliad Peller				      max_size,
116c5312772156bb5f9b2e95e4c91526d578426a069Eliad Peller				      0, WL1271_RATE_AUTOMATIC);
117c5312772156bb5f9b2e95e4c91526d578426a069Eliad Peller	if (ret < 0)
118c5312772156bb5f9b2e95e4c91526d578426a069Eliad Peller		return ret;
119c5312772156bb5f9b2e95e4c91526d578426a069Eliad Peller
12092c77c734f958474ac73af670834bc32cb833e54Eliad Peller	/*
12192c77c734f958474ac73af670834bc32cb833e54Eliad Peller	 * Put very large empty placeholders for all templates. These
12292c77c734f958474ac73af670834bc32cb833e54Eliad Peller	 * reserve memory for later.
12392c77c734f958474ac73af670834bc32cb833e54Eliad Peller	 */
124cdaac6281170ee2934ad443cb60fbdd6cf318b64Eliad Peller	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
125cdaac6281170ee2934ad443cb60fbdd6cf318b64Eliad Peller				      CMD_TEMPL_AP_PROBE_RESPONSE, NULL,
12692c77c734f958474ac73af670834bc32cb833e54Eliad Peller				      WL1271_CMD_TEMPL_MAX_SIZE,
12792c77c734f958474ac73af670834bc32cb833e54Eliad Peller				      0, WL1271_RATE_AUTOMATIC);
12892c77c734f958474ac73af670834bc32cb833e54Eliad Peller	if (ret < 0)
12992c77c734f958474ac73af670834bc32cb833e54Eliad Peller		return ret;
13092c77c734f958474ac73af670834bc32cb833e54Eliad Peller
131cdaac6281170ee2934ad443cb60fbdd6cf318b64Eliad Peller	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
132cdaac6281170ee2934ad443cb60fbdd6cf318b64Eliad Peller				      CMD_TEMPL_AP_BEACON, NULL,
13392c77c734f958474ac73af670834bc32cb833e54Eliad Peller				      WL1271_CMD_TEMPL_MAX_SIZE,
13492c77c734f958474ac73af670834bc32cb833e54Eliad Peller				      0, WL1271_RATE_AUTOMATIC);
13592c77c734f958474ac73af670834bc32cb833e54Eliad Peller	if (ret < 0)
13692c77c734f958474ac73af670834bc32cb833e54Eliad Peller		return ret;
13792c77c734f958474ac73af670834bc32cb833e54Eliad Peller
138cdaac6281170ee2934ad443cb60fbdd6cf318b64Eliad Peller	ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
139cdaac6281170ee2934ad443cb60fbdd6cf318b64Eliad Peller				      CMD_TEMPL_DEAUTH_AP, NULL,
14092c77c734f958474ac73af670834bc32cb833e54Eliad Peller				      sizeof
14192c77c734f958474ac73af670834bc32cb833e54Eliad Peller				      (struct wl12xx_disconn_template),
14292c77c734f958474ac73af670834bc32cb833e54Eliad Peller				      0, WL1271_RATE_AUTOMATIC);
14392c77c734f958474ac73af670834bc32cb833e54Eliad Peller	if (ret < 0)
14492c77c734f958474ac73af670834bc32cb833e54Eliad Peller		return ret;
14592c77c734f958474ac73af670834bc32cb833e54Eliad Peller
146001e39a8effd5a9774153ca6ca67849a93b95852Eliad Peller	for (i = 0; i < WLCORE_MAX_KLV_TEMPLATES; i++) {
147cdaac6281170ee2934ad443cb60fbdd6cf318b64Eliad Peller		ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
148cdaac6281170ee2934ad443cb60fbdd6cf318b64Eliad Peller					      CMD_TEMPL_KLV, NULL,
14997127e67218e5970a5a7df0513ded730b19a67e9Eliad Peller					      sizeof(struct ieee80211_qos_hdr),
15097127e67218e5970a5a7df0513ded730b19a67e9Eliad Peller					      i, WL1271_RATE_AUTOMATIC);
151bfb24c9e16921f0e57fcec5180ffa20929832545Juuso Oikarinen		if (ret < 0)
152bfb24c9e16921f0e57fcec5180ffa20929832545Juuso Oikarinen			return ret;
153bfb24c9e16921f0e57fcec5180ffa20929832545Juuso Oikarinen	}
154bfb24c9e16921f0e57fcec5180ffa20929832545Juuso Oikarinen
155f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	return 0;
156f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho}
157f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
15887fbcb0f8c5c8fd57a4e3e7e638977c04ce1e0caEliad Pellerstatic int wl1271_ap_init_deauth_template(struct wl1271 *wl,
15987fbcb0f8c5c8fd57a4e3e7e638977c04ce1e0caEliad Peller					  struct wl12xx_vif *wlvif)
160e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov{
161e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	struct wl12xx_disconn_template *tmpl;
162e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	int ret;
163af7fbb28efff0c0d8fc0852ad6622e5437a7611eEliad Peller	u32 rate;
164e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
165e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	tmpl = kzalloc(sizeof(*tmpl), GFP_KERNEL);
166e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	if (!tmpl) {
167e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov		ret = -ENOMEM;
168e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov		goto out;
169e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	}
170e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
171e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	tmpl->header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT |
172e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov					     IEEE80211_STYPE_DEAUTH);
173e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
17487fbcb0f8c5c8fd57a4e3e7e638977c04ce1e0caEliad Peller	rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
175cdaac6281170ee2934ad443cb60fbdd6cf318b64Eliad Peller	ret = wl1271_cmd_template_set(wl, wlvif->role_id,
176cdaac6281170ee2934ad443cb60fbdd6cf318b64Eliad Peller				      CMD_TEMPL_DEAUTH_AP,
177af7fbb28efff0c0d8fc0852ad6622e5437a7611eEliad Peller				      tmpl, sizeof(*tmpl), 0, rate);
178e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
179e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsovout:
180e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	kfree(tmpl);
181e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	return ret;
182e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov}
183e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
184784f694d0f3ca927361aa0c26de1aa340eb5b275Eliad Pellerstatic int wl1271_ap_init_null_template(struct wl1271 *wl,
185784f694d0f3ca927361aa0c26de1aa340eb5b275Eliad Peller					struct ieee80211_vif *vif)
186e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov{
18787fbcb0f8c5c8fd57a4e3e7e638977c04ce1e0caEliad Peller	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
188e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	struct ieee80211_hdr_3addr *nullfunc;
189e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	int ret;
190af7fbb28efff0c0d8fc0852ad6622e5437a7611eEliad Peller	u32 rate;
191e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
192e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	nullfunc = kzalloc(sizeof(*nullfunc), GFP_KERNEL);
193e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	if (!nullfunc) {
194e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov		ret = -ENOMEM;
195e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov		goto out;
196e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	}
197e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
198e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
199e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov					      IEEE80211_STYPE_NULLFUNC |
200e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov					      IEEE80211_FCTL_FROMDS);
201e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
202e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	/* nullfunc->addr1 is filled by FW */
203e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
204784f694d0f3ca927361aa0c26de1aa340eb5b275Eliad Peller	memcpy(nullfunc->addr2, vif->addr, ETH_ALEN);
205784f694d0f3ca927361aa0c26de1aa340eb5b275Eliad Peller	memcpy(nullfunc->addr3, vif->addr, ETH_ALEN);
206e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
20787fbcb0f8c5c8fd57a4e3e7e638977c04ce1e0caEliad Peller	rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
208cdaac6281170ee2934ad443cb60fbdd6cf318b64Eliad Peller	ret = wl1271_cmd_template_set(wl, wlvif->role_id,
209cdaac6281170ee2934ad443cb60fbdd6cf318b64Eliad Peller				      CMD_TEMPL_NULL_DATA, nullfunc,
210af7fbb28efff0c0d8fc0852ad6622e5437a7611eEliad Peller				      sizeof(*nullfunc), 0, rate);
211e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
212e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsovout:
213e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	kfree(nullfunc);
214e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	return ret;
215e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov}
216e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
217784f694d0f3ca927361aa0c26de1aa340eb5b275Eliad Pellerstatic int wl1271_ap_init_qos_null_template(struct wl1271 *wl,
218784f694d0f3ca927361aa0c26de1aa340eb5b275Eliad Peller					    struct ieee80211_vif *vif)
219e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov{
22087fbcb0f8c5c8fd57a4e3e7e638977c04ce1e0caEliad Peller	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
221e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	struct ieee80211_qos_hdr *qosnull;
222e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	int ret;
223af7fbb28efff0c0d8fc0852ad6622e5437a7611eEliad Peller	u32 rate;
224e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
225e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	qosnull = kzalloc(sizeof(*qosnull), GFP_KERNEL);
226e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	if (!qosnull) {
227e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov		ret = -ENOMEM;
228e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov		goto out;
229e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	}
230e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
231e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	qosnull->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
232e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov					     IEEE80211_STYPE_QOS_NULLFUNC |
233e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov					     IEEE80211_FCTL_FROMDS);
234e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
235e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	/* qosnull->addr1 is filled by FW */
236e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
237784f694d0f3ca927361aa0c26de1aa340eb5b275Eliad Peller	memcpy(qosnull->addr2, vif->addr, ETH_ALEN);
238784f694d0f3ca927361aa0c26de1aa340eb5b275Eliad Peller	memcpy(qosnull->addr3, vif->addr, ETH_ALEN);
239e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
24087fbcb0f8c5c8fd57a4e3e7e638977c04ce1e0caEliad Peller	rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
241cdaac6281170ee2934ad443cb60fbdd6cf318b64Eliad Peller	ret = wl1271_cmd_template_set(wl, wlvif->role_id,
242cdaac6281170ee2934ad443cb60fbdd6cf318b64Eliad Peller				      CMD_TEMPL_QOS_NULL_DATA, qosnull,
243af7fbb28efff0c0d8fc0852ad6622e5437a7611eEliad Peller				      sizeof(*qosnull), 0, rate);
244e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
245e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsovout:
246e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	kfree(qosnull);
247e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	return ret;
248e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov}
249e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
25092c77c734f958474ac73af670834bc32cb833e54Eliad Pellerstatic int wl12xx_init_rx_config(struct wl1271 *wl)
251e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov{
252e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	int ret;
253e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
25492c77c734f958474ac73af670834bc32cb833e54Eliad Peller	ret = wl1271_acx_rx_msdu_life_time(wl);
255e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	if (ret < 0)
256e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov		return ret;
257e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
258e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	return 0;
259e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov}
260e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
2610603d891c5b5153f667a79357d4652824c22b54eEliad Pellerstatic int wl12xx_init_phy_vif_config(struct wl1271 *wl,
2620603d891c5b5153f667a79357d4652824c22b54eEliad Peller					    struct wl12xx_vif *wlvif)
263f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho{
264f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	int ret;
265f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
2660603d891c5b5153f667a79357d4652824c22b54eEliad Peller	ret = wl1271_acx_slot(wl, wlvif, DEFAULT_SLOT_TIME);
267f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	if (ret < 0)
268f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho		return ret;
269f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
2700603d891c5b5153f667a79357d4652824c22b54eEliad Peller	ret = wl1271_acx_service_period_timeout(wl, wlvif);
271f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	if (ret < 0)
272f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho		return ret;
273f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
2740603d891c5b5153f667a79357d4652824c22b54eEliad Peller	ret = wl1271_acx_rts_threshold(wl, wlvif, wl->hw->wiphy->rts_threshold);
275f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	if (ret < 0)
276f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho		return ret;
277f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
278f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	return 0;
279f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho}
280f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
281a693534b1a46ee934606cec52b12baeaebba0342Arik Nemtsovstatic int wl1271_init_sta_beacon_filter(struct wl1271 *wl,
282a693534b1a46ee934606cec52b12baeaebba0342Arik Nemtsov					 struct wl12xx_vif *wlvif)
283f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho{
284f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	int ret;
285f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
286a693534b1a46ee934606cec52b12baeaebba0342Arik Nemtsov	ret = wl1271_acx_beacon_filter_table(wl, wlvif);
287f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	if (ret < 0)
288f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho		return ret;
289f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
290d881fa2c5032918e2b03ce6e12a5886f08acb459Eliad Peller	/* disable beacon filtering until we get the first beacon */
291d881fa2c5032918e2b03ce6e12a5886f08acb459Eliad Peller	ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false);
292f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	if (ret < 0)
293f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho		return ret;
294f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
295f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	return 0;
296f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho}
297f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
29812419cce88fa591a846a542d35cff43b69d9e271Luciano Coelhoint wl1271_init_pta(struct wl1271 *wl)
299f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho{
300f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	int ret;
301f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
3023be4112cb2c53fcda85fb408aea9a6f94075683bEliad Peller	ret = wl12xx_acx_sg_cfg(wl);
303f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	if (ret < 0)
304f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho		return ret;
305f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
3067fc3a8647d2eaa8bc2f7ac7e9baff55199da7be6Juuso Oikarinen	ret = wl1271_acx_sg_enable(wl, wl->sg_enabled);
307f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	if (ret < 0)
308f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho		return ret;
309f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
310f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	return 0;
311f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho}
312f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
31312419cce88fa591a846a542d35cff43b69d9e271Luciano Coelhoint wl1271_init_energy_detection(struct wl1271 *wl)
314f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho{
315f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	int ret;
316f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
317f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	ret = wl1271_acx_cca_threshold(wl);
318f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	if (ret < 0)
319f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho		return ret;
320f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
321f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	return 0;
322f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho}
323f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
3240603d891c5b5153f667a79357d4652824c22b54eEliad Pellerstatic int wl1271_init_beacon_broadcast(struct wl1271 *wl,
3250603d891c5b5153f667a79357d4652824c22b54eEliad Peller					struct wl12xx_vif *wlvif)
326f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho{
327f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	int ret;
328f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
3290603d891c5b5153f667a79357d4652824c22b54eEliad Peller	ret = wl1271_acx_bcn_dtim_options(wl, wlvif);
330f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	if (ret < 0)
331f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho		return ret;
332f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
333f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	return 0;
334f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho}
335f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
33695dac04f881322b510c45e5ae83f0dbee4f823a2Ido Yarivstatic int wl12xx_init_fwlog(struct wl1271 *wl)
33795dac04f881322b510c45e5ae83f0dbee4f823a2Ido Yariv{
33895dac04f881322b510c45e5ae83f0dbee4f823a2Ido Yariv	int ret;
33995dac04f881322b510c45e5ae83f0dbee4f823a2Ido Yariv
3406f7dd16cb125468a5393861c22fbecfb52dd9653Luciano Coelho	if (wl->quirks & WLCORE_QUIRK_FWLOG_NOT_IMPLEMENTED)
34195dac04f881322b510c45e5ae83f0dbee4f823a2Ido Yariv		return 0;
34295dac04f881322b510c45e5ae83f0dbee4f823a2Ido Yariv
34395dac04f881322b510c45e5ae83f0dbee4f823a2Ido Yariv	ret = wl12xx_cmd_config_fwlog(wl);
34495dac04f881322b510c45e5ae83f0dbee4f823a2Ido Yariv	if (ret < 0)
34595dac04f881322b510c45e5ae83f0dbee4f823a2Ido Yariv		return ret;
34695dac04f881322b510c45e5ae83f0dbee4f823a2Ido Yariv
34795dac04f881322b510c45e5ae83f0dbee4f823a2Ido Yariv	return 0;
34895dac04f881322b510c45e5ae83f0dbee4f823a2Ido Yariv}
34995dac04f881322b510c45e5ae83f0dbee4f823a2Ido Yariv
35092c77c734f958474ac73af670834bc32cb833e54Eliad Peller/* generic sta initialization (non vif-specific) */
35130d0c8fd5b87d1c5486705d6420545a21533e115Eliad Pellerstatic int wl1271_sta_hw_init(struct wl1271 *wl, struct wl12xx_vif *wlvif)
352e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov{
353e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	int ret;
354e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
355c8bde243421d759844264cf11e4248e7862c2722Eliad Peller	/* PS config */
356d2d66c56cf6c8727662aa321991f791604c22094Eliad Peller	ret = wl12xx_acx_config_ps(wl, wlvif);
357c8bde243421d759844264cf11e4248e7862c2722Eliad Peller	if (ret < 0)
358c8bde243421d759844264cf11e4248e7862c2722Eliad Peller		return ret;
359c8bde243421d759844264cf11e4248e7862c2722Eliad Peller
360ff86843dfbb368766d0aecd0147821d9a2b60edbShahar Levi	/* FM WLAN coexistence */
361ff86843dfbb368766d0aecd0147821d9a2b60edbShahar Levi	ret = wl1271_acx_fm_coex(wl);
362ff86843dfbb368766d0aecd0147821d9a2b60edbShahar Levi	if (ret < 0)
363ff86843dfbb368766d0aecd0147821d9a2b60edbShahar Levi		return ret;
364ff86843dfbb368766d0aecd0147821d9a2b60edbShahar Levi
36530d0c8fd5b87d1c5486705d6420545a21533e115Eliad Peller	ret = wl1271_acx_sta_rate_policies(wl, wlvif);
366e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	if (ret < 0)
367e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov		return ret;
368e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
369e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	return 0;
370e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov}
371e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
3720603d891c5b5153f667a79357d4652824c22b54eEliad Pellerstatic int wl1271_sta_hw_init_post_mem(struct wl1271 *wl,
3730603d891c5b5153f667a79357d4652824c22b54eEliad Peller				       struct ieee80211_vif *vif)
374e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov{
3750603d891c5b5153f667a79357d4652824c22b54eEliad Peller	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
376001e39a8effd5a9774153ca6ca67849a93b95852Eliad Peller	int ret;
377e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
378e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	/* disable the keep-alive feature */
3790603d891c5b5153f667a79357d4652824c22b54eEliad Peller	ret = wl1271_acx_keep_alive_mode(wl, wlvif, false);
380e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	if (ret < 0)
381e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov		return ret;
382e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
383e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	return 0;
384e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov}
385e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
38692c77c734f958474ac73af670834bc32cb833e54Eliad Peller/* generic ap initialization (non vif-specific) */
38787fbcb0f8c5c8fd57a4e3e7e638977c04ce1e0caEliad Pellerstatic int wl1271_ap_hw_init(struct wl1271 *wl, struct wl12xx_vif *wlvif)
388e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov{
38970f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov	int ret;
390e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
39187fbcb0f8c5c8fd57a4e3e7e638977c04ce1e0caEliad Peller	ret = wl1271_init_ap_rates(wl, wlvif);
392e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	if (ret < 0)
393e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov		return ret;
394e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
395e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	return 0;
396e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov}
397e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
398784f694d0f3ca927361aa0c26de1aa340eb5b275Eliad Pellerint wl1271_ap_init_templates(struct wl1271 *wl, struct ieee80211_vif *vif)
399e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov{
40087fbcb0f8c5c8fd57a4e3e7e638977c04ce1e0caEliad Peller	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
401e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	int ret;
402e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
40387fbcb0f8c5c8fd57a4e3e7e638977c04ce1e0caEliad Peller	ret = wl1271_ap_init_deauth_template(wl, wlvif);
404e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	if (ret < 0)
405e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov		return ret;
406e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
407784f694d0f3ca927361aa0c26de1aa340eb5b275Eliad Peller	ret = wl1271_ap_init_null_template(wl, vif);
408e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	if (ret < 0)
409e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov		return ret;
410e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
411784f694d0f3ca927361aa0c26de1aa340eb5b275Eliad Peller	ret = wl1271_ap_init_qos_null_template(wl, vif);
412e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	if (ret < 0)
413e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov		return ret;
414e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
415521a4a23261354885c01bf75b42150629004ed83Arik Nemtsov	/*
416521a4a23261354885c01bf75b42150629004ed83Arik Nemtsov	 * when operating as AP we want to receive external beacons for
417521a4a23261354885c01bf75b42150629004ed83Arik Nemtsov	 * configuring ERP protection.
418521a4a23261354885c01bf75b42150629004ed83Arik Nemtsov	 */
4190603d891c5b5153f667a79357d4652824c22b54eEliad Peller	ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false);
420521a4a23261354885c01bf75b42150629004ed83Arik Nemtsov	if (ret < 0)
421521a4a23261354885c01bf75b42150629004ed83Arik Nemtsov		return ret;
422521a4a23261354885c01bf75b42150629004ed83Arik Nemtsov
423e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov	return 0;
424e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov}
425e0fe371b74326a85029fe8720506e021fe73905aArik Nemtsov
426784f694d0f3ca927361aa0c26de1aa340eb5b275Eliad Pellerstatic int wl1271_ap_hw_init_post_mem(struct wl1271 *wl,
427784f694d0f3ca927361aa0c26de1aa340eb5b275Eliad Peller				      struct ieee80211_vif *vif)
428c45a85b5a3c0ca841a7ffc700bdece8ee01486beArik Nemtsov{
429784f694d0f3ca927361aa0c26de1aa340eb5b275Eliad Peller	return wl1271_ap_init_templates(wl, vif);
430c45a85b5a3c0ca841a7ffc700bdece8ee01486beArik Nemtsov}
431c45a85b5a3c0ca841a7ffc700bdece8ee01486beArik Nemtsov
43287fbcb0f8c5c8fd57a4e3e7e638977c04ce1e0caEliad Pellerint wl1271_init_ap_rates(struct wl1271 *wl, struct wl12xx_vif *wlvif)
43370f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov{
43470f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov	int i, ret;
43570f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov	struct conf_tx_rate_class rc;
43670f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov	u32 supported_rates;
43770f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov
43887fbcb0f8c5c8fd57a4e3e7e638977c04ce1e0caEliad Peller	wl1271_debug(DEBUG_AP, "AP basic rate set: 0x%x",
43987fbcb0f8c5c8fd57a4e3e7e638977c04ce1e0caEliad Peller		     wlvif->basic_rate_set);
44070f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov
44187fbcb0f8c5c8fd57a4e3e7e638977c04ce1e0caEliad Peller	if (wlvif->basic_rate_set == 0)
44270f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov		return -EINVAL;
44370f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov
44487fbcb0f8c5c8fd57a4e3e7e638977c04ce1e0caEliad Peller	rc.enabled_rates = wlvif->basic_rate_set;
44570f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov	rc.long_retry_limit = 10;
44670f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov	rc.short_retry_limit = 10;
44770f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov	rc.aflags = 0;
448e5a359f873f50cc123d5ca97637caa30fa095bb9Eliad Peller	ret = wl1271_acx_ap_rate_policy(wl, &rc, wlvif->ap.mgmt_rate_idx);
44970f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov	if (ret < 0)
45070f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov		return ret;
45170f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov
45270f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov	/* use the min basic rate for AP broadcast/multicast */
45387fbcb0f8c5c8fd57a4e3e7e638977c04ce1e0caEliad Peller	rc.enabled_rates = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
45470f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov	rc.short_retry_limit = 10;
45570f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov	rc.long_retry_limit = 10;
45670f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov	rc.aflags = 0;
457e5a359f873f50cc123d5ca97637caa30fa095bb9Eliad Peller	ret = wl1271_acx_ap_rate_policy(wl, &rc, wlvif->ap.bcast_rate_idx);
45870f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov	if (ret < 0)
45970f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov		return ret;
46070f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov
46170f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov	/*
46270f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov	 * If the basic rates contain OFDM rates, use OFDM only
46370f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov	 * rates for unicast TX as well. Else use all supported rates.
46470f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov	 */
465bc566f9203c2813a2e083677eb99c62b1cb14d03Arik Nemtsov	if (wl->ofdm_only_ap && (wlvif->basic_rate_set & CONF_TX_OFDM_RATES))
46670f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov		supported_rates = CONF_TX_OFDM_RATES;
46770f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov	else
46842ec1f82a862b38eb84bc3bbd7fb97b1aa48f18cEliad Peller		supported_rates = CONF_TX_ENABLED_RATES;
46970f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov
4701a8adb67f9c37cad9539dd9dcb289ce1411680fcArik Nemtsov	/* unconditionally enable HT rates */
4711a8adb67f9c37cad9539dd9dcb289ce1411680fcArik Nemtsov	supported_rates |= CONF_TX_MCS_RATES;
4721a8adb67f9c37cad9539dd9dcb289ce1411680fcArik Nemtsov
473ebc7e57ddd01ffa4c996dde7095746259693755dArik Nemtsov	/* get extra MIMO or wide-chan rates where the HW supports it */
474ebc7e57ddd01ffa4c996dde7095746259693755dArik Nemtsov	supported_rates |= wlcore_hw_ap_get_mimo_wide_rate_mask(wl, wlvif);
475ebc7e57ddd01ffa4c996dde7095746259693755dArik Nemtsov
47670f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov	/* configure unicast TX rate classes */
47770f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov	for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
47870f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov		rc.enabled_rates = supported_rates;
47970f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov		rc.short_retry_limit = 10;
48070f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov		rc.long_retry_limit = 10;
48170f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov		rc.aflags = 0;
482e5a359f873f50cc123d5ca97637caa30fa095bb9Eliad Peller		ret = wl1271_acx_ap_rate_policy(wl, &rc,
483e5a359f873f50cc123d5ca97637caa30fa095bb9Eliad Peller						wlvif->ap.ucast_rate_idx[i]);
48470f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov		if (ret < 0)
48570f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov			return ret;
48670f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov	}
48770f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov
48870f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov	return 0;
48970f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov}
49070f474241b3d5fb633635a2ce39ea9da4afeea6cArik Nemtsov
491536129c8ad35de87ff2f864f205a54ac32bfebccEliad Pellerstatic int wl1271_set_ba_policies(struct wl1271 *wl, struct wl12xx_vif *wlvif)
4924b7fac77b4c1badac84df3dcbdf07199d94cb1c3Levi, Shahar{
4934b7fac77b4c1badac84df3dcbdf07199d94cb1c3Levi, Shahar	/* Reset the BA RX indicators */
494d0802abdf9c60b1dadb097e806022f3449b0cc6bEliad Peller	wlvif->ba_allowed = true;
4950f9c8250e10a16f48f82ffda3a5a7cb9e7b4a9eeArik Nemtsov	wl->ba_rx_session_count = 0;
4964b7fac77b4c1badac84df3dcbdf07199d94cb1c3Levi, Shahar
4970f9c8250e10a16f48f82ffda3a5a7cb9e7b4a9eeArik Nemtsov	/* BA is supported in STA/AP modes */
498536129c8ad35de87ff2f864f205a54ac32bfebccEliad Peller	if (wlvif->bss_type != BSS_TYPE_AP_BSS &&
499536129c8ad35de87ff2f864f205a54ac32bfebccEliad Peller	    wlvif->bss_type != BSS_TYPE_STA_BSS) {
500d0802abdf9c60b1dadb097e806022f3449b0cc6bEliad Peller		wlvif->ba_support = false;
5010f9c8250e10a16f48f82ffda3a5a7cb9e7b4a9eeArik Nemtsov		return 0;
5020f9c8250e10a16f48f82ffda3a5a7cb9e7b4a9eeArik Nemtsov	}
5034b7fac77b4c1badac84df3dcbdf07199d94cb1c3Levi, Shahar
504d0802abdf9c60b1dadb097e806022f3449b0cc6bEliad Peller	wlvif->ba_support = true;
5054b7fac77b4c1badac84df3dcbdf07199d94cb1c3Levi, Shahar
5060f9c8250e10a16f48f82ffda3a5a7cb9e7b4a9eeArik Nemtsov	/* 802.11n initiator BA session setting */
5070603d891c5b5153f667a79357d4652824c22b54eEliad Peller	return wl12xx_acx_set_ba_initiator_policy(wl, wlvif);
5084b7fac77b4c1badac84df3dcbdf07199d94cb1c3Levi, Shahar}
5094b7fac77b4c1badac84df3dcbdf07199d94cb1c3Levi, Shahar
51092c77c734f958474ac73af670834bc32cb833e54Eliad Peller/* vif-specifc initialization */
5110603d891c5b5153f667a79357d4652824c22b54eEliad Pellerstatic int wl12xx_init_sta_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
51292c77c734f958474ac73af670834bc32cb833e54Eliad Peller{
51392c77c734f958474ac73af670834bc32cb833e54Eliad Peller	int ret;
51492c77c734f958474ac73af670834bc32cb833e54Eliad Peller
5150603d891c5b5153f667a79357d4652824c22b54eEliad Peller	ret = wl1271_acx_group_address_tbl(wl, wlvif, true, NULL, 0);
51692c77c734f958474ac73af670834bc32cb833e54Eliad Peller	if (ret < 0)
51792c77c734f958474ac73af670834bc32cb833e54Eliad Peller		return ret;
51892c77c734f958474ac73af670834bc32cb833e54Eliad Peller
51992c77c734f958474ac73af670834bc32cb833e54Eliad Peller	/* Initialize connection monitoring thresholds */
5200603d891c5b5153f667a79357d4652824c22b54eEliad Peller	ret = wl1271_acx_conn_monit_params(wl, wlvif, false);
52192c77c734f958474ac73af670834bc32cb833e54Eliad Peller	if (ret < 0)
52292c77c734f958474ac73af670834bc32cb833e54Eliad Peller		return ret;
52392c77c734f958474ac73af670834bc32cb833e54Eliad Peller
52492c77c734f958474ac73af670834bc32cb833e54Eliad Peller	/* Beacon filtering */
525a693534b1a46ee934606cec52b12baeaebba0342Arik Nemtsov	ret = wl1271_init_sta_beacon_filter(wl, wlvif);
52692c77c734f958474ac73af670834bc32cb833e54Eliad Peller	if (ret < 0)
52792c77c734f958474ac73af670834bc32cb833e54Eliad Peller		return ret;
52892c77c734f958474ac73af670834bc32cb833e54Eliad Peller
52992c77c734f958474ac73af670834bc32cb833e54Eliad Peller	/* Beacons and broadcast settings */
5300603d891c5b5153f667a79357d4652824c22b54eEliad Peller	ret = wl1271_init_beacon_broadcast(wl, wlvif);
53192c77c734f958474ac73af670834bc32cb833e54Eliad Peller	if (ret < 0)
53292c77c734f958474ac73af670834bc32cb833e54Eliad Peller		return ret;
53348a61477bdc04896bd96d259388a0c42a7019943Shahar Levi
53492c77c734f958474ac73af670834bc32cb833e54Eliad Peller	/* Configure rssi/snr averaging weights */
5350603d891c5b5153f667a79357d4652824c22b54eEliad Peller	ret = wl1271_acx_rssi_snr_avg_weights(wl, wlvif);
53692c77c734f958474ac73af670834bc32cb833e54Eliad Peller	if (ret < 0)
53792c77c734f958474ac73af670834bc32cb833e54Eliad Peller		return ret;
53892c77c734f958474ac73af670834bc32cb833e54Eliad Peller
53992c77c734f958474ac73af670834bc32cb833e54Eliad Peller	return 0;
54092c77c734f958474ac73af670834bc32cb833e54Eliad Peller}
54192c77c734f958474ac73af670834bc32cb833e54Eliad Peller
54292c77c734f958474ac73af670834bc32cb833e54Eliad Peller/* vif-specific intialization */
5430603d891c5b5153f667a79357d4652824c22b54eEliad Pellerstatic int wl12xx_init_ap_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
54492c77c734f958474ac73af670834bc32cb833e54Eliad Peller{
54592c77c734f958474ac73af670834bc32cb833e54Eliad Peller	int ret;
54692c77c734f958474ac73af670834bc32cb833e54Eliad Peller
5470603d891c5b5153f667a79357d4652824c22b54eEliad Peller	ret = wl1271_acx_ap_max_tx_retry(wl, wlvif);
54892c77c734f958474ac73af670834bc32cb833e54Eliad Peller	if (ret < 0)
54992c77c734f958474ac73af670834bc32cb833e54Eliad Peller		return ret;
55092c77c734f958474ac73af670834bc32cb833e54Eliad Peller
55192c77c734f958474ac73af670834bc32cb833e54Eliad Peller	/* initialize Tx power */
5526bd650299046f00df6d7374c7f61c5afe6df6696Eliad Peller	ret = wl1271_acx_tx_power(wl, wlvif, wlvif->power_level);
55392c77c734f958474ac73af670834bc32cb833e54Eliad Peller	if (ret < 0)
55492c77c734f958474ac73af670834bc32cb833e54Eliad Peller		return ret;
55592c77c734f958474ac73af670834bc32cb833e54Eliad Peller
55692c77c734f958474ac73af670834bc32cb833e54Eliad Peller	return 0;
55792c77c734f958474ac73af670834bc32cb833e54Eliad Peller}
55892c77c734f958474ac73af670834bc32cb833e54Eliad Peller
55992c77c734f958474ac73af670834bc32cb833e54Eliad Pellerint wl1271_init_vif_specific(struct wl1271 *wl, struct ieee80211_vif *vif)
560f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho{
56187fbcb0f8c5c8fd57a4e3e7e638977c04ce1e0caEliad Peller	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
562243eeb51eaa0a33caeff3e2275b2460eea5579ecKalle Valo	struct conf_tx_ac_category *conf_ac;
563f2054df5170734eacd1db82138c70746ec8387deKalle Valo	struct conf_tx_tid *conf_tid;
564536129c8ad35de87ff2f864f205a54ac32bfebccEliad Peller	bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
56592c77c734f958474ac73af670834bc32cb833e54Eliad Peller	int ret, i;
56692c77c734f958474ac73af670834bc32cb833e54Eliad Peller
5672f18cf7c3b99779465def78318b4243d1f66cce8Arik Nemtsov	/* consider all existing roles before configuring psm. */
5682f18cf7c3b99779465def78318b4243d1f66cce8Arik Nemtsov
5692f18cf7c3b99779465def78318b4243d1f66cce8Arik Nemtsov	if (wl->ap_count == 0 && is_ap) { /* first AP */
5702f18cf7c3b99779465def78318b4243d1f66cce8Arik Nemtsov		/* Configure for power always on */
5712f18cf7c3b99779465def78318b4243d1f66cce8Arik Nemtsov		ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
5722f18cf7c3b99779465def78318b4243d1f66cce8Arik Nemtsov		if (ret < 0)
5732f18cf7c3b99779465def78318b4243d1f66cce8Arik Nemtsov			return ret;
57471e996bef90b23919f627a38367b9e8b44b77d37Eliad Peller
57571e996bef90b23919f627a38367b9e8b44b77d37Eliad Peller		/* unmask ap events */
57671e996bef90b23919f627a38367b9e8b44b77d37Eliad Peller		wl->event_mask |= wl->ap_event_mask;
57771e996bef90b23919f627a38367b9e8b44b77d37Eliad Peller		ret = wl1271_event_unmask(wl);
57871e996bef90b23919f627a38367b9e8b44b77d37Eliad Peller		if (ret < 0)
57971e996bef90b23919f627a38367b9e8b44b77d37Eliad Peller			return ret;
5802f18cf7c3b99779465def78318b4243d1f66cce8Arik Nemtsov	/* first STA, no APs */
5812f18cf7c3b99779465def78318b4243d1f66cce8Arik Nemtsov	} else if (wl->sta_count == 0 && wl->ap_count == 0 && !is_ap) {
5822f18cf7c3b99779465def78318b4243d1f66cce8Arik Nemtsov		u8 sta_auth = wl->conf.conn.sta_sleep_auth;
5832f18cf7c3b99779465def78318b4243d1f66cce8Arik Nemtsov		/* Configure for power according to debugfs */
5842f18cf7c3b99779465def78318b4243d1f66cce8Arik Nemtsov		if (sta_auth != WL1271_PSM_ILLEGAL)
5852f18cf7c3b99779465def78318b4243d1f66cce8Arik Nemtsov			ret = wl1271_acx_sleep_auth(wl, sta_auth);
5862f18cf7c3b99779465def78318b4243d1f66cce8Arik Nemtsov		/* Configure for ELP power saving */
5872f18cf7c3b99779465def78318b4243d1f66cce8Arik Nemtsov		else
5882f18cf7c3b99779465def78318b4243d1f66cce8Arik Nemtsov			ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
5892f18cf7c3b99779465def78318b4243d1f66cce8Arik Nemtsov
5902f18cf7c3b99779465def78318b4243d1f66cce8Arik Nemtsov		if (ret < 0)
5912f18cf7c3b99779465def78318b4243d1f66cce8Arik Nemtsov			return ret;
592a4e4130dcea01f3e0dfcbfeaf0d815b971e6e515Eliad Peller	}
593a4e4130dcea01f3e0dfcbfeaf0d815b971e6e515Eliad Peller
59492c77c734f958474ac73af670834bc32cb833e54Eliad Peller	/* Mode specific init */
59592c77c734f958474ac73af670834bc32cb833e54Eliad Peller	if (is_ap) {
59687fbcb0f8c5c8fd57a4e3e7e638977c04ce1e0caEliad Peller		ret = wl1271_ap_hw_init(wl, wlvif);
59792c77c734f958474ac73af670834bc32cb833e54Eliad Peller		if (ret < 0)
59892c77c734f958474ac73af670834bc32cb833e54Eliad Peller			return ret;
59992c77c734f958474ac73af670834bc32cb833e54Eliad Peller
6000603d891c5b5153f667a79357d4652824c22b54eEliad Peller		ret = wl12xx_init_ap_role(wl, wlvif);
60192c77c734f958474ac73af670834bc32cb833e54Eliad Peller		if (ret < 0)
60292c77c734f958474ac73af670834bc32cb833e54Eliad Peller			return ret;
60392c77c734f958474ac73af670834bc32cb833e54Eliad Peller	} else {
60430d0c8fd5b87d1c5486705d6420545a21533e115Eliad Peller		ret = wl1271_sta_hw_init(wl, wlvif);
60592c77c734f958474ac73af670834bc32cb833e54Eliad Peller		if (ret < 0)
60692c77c734f958474ac73af670834bc32cb833e54Eliad Peller			return ret;
60792c77c734f958474ac73af670834bc32cb833e54Eliad Peller
6080603d891c5b5153f667a79357d4652824c22b54eEliad Peller		ret = wl12xx_init_sta_role(wl, wlvif);
60992c77c734f958474ac73af670834bc32cb833e54Eliad Peller		if (ret < 0)
61092c77c734f958474ac73af670834bc32cb833e54Eliad Peller			return ret;
61192c77c734f958474ac73af670834bc32cb833e54Eliad Peller	}
61292c77c734f958474ac73af670834bc32cb833e54Eliad Peller
6130603d891c5b5153f667a79357d4652824c22b54eEliad Peller	wl12xx_init_phy_vif_config(wl, wlvif);
61492c77c734f958474ac73af670834bc32cb833e54Eliad Peller
61592c77c734f958474ac73af670834bc32cb833e54Eliad Peller	/* Default TID/AC configuration */
61692c77c734f958474ac73af670834bc32cb833e54Eliad Peller	BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
61792c77c734f958474ac73af670834bc32cb833e54Eliad Peller	for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
61892c77c734f958474ac73af670834bc32cb833e54Eliad Peller		conf_ac = &wl->conf.tx.ac_conf[i];
6190603d891c5b5153f667a79357d4652824c22b54eEliad Peller		ret = wl1271_acx_ac_cfg(wl, wlvif, conf_ac->ac,
6200603d891c5b5153f667a79357d4652824c22b54eEliad Peller					conf_ac->cw_min, conf_ac->cw_max,
6210603d891c5b5153f667a79357d4652824c22b54eEliad Peller					conf_ac->aifsn, conf_ac->tx_op_limit);
62292c77c734f958474ac73af670834bc32cb833e54Eliad Peller		if (ret < 0)
62392c77c734f958474ac73af670834bc32cb833e54Eliad Peller			return ret;
62492c77c734f958474ac73af670834bc32cb833e54Eliad Peller
62592c77c734f958474ac73af670834bc32cb833e54Eliad Peller		conf_tid = &wl->conf.tx.tid_conf[i];
6260603d891c5b5153f667a79357d4652824c22b54eEliad Peller		ret = wl1271_acx_tid_cfg(wl, wlvif,
62792c77c734f958474ac73af670834bc32cb833e54Eliad Peller					 conf_tid->queue_id,
62892c77c734f958474ac73af670834bc32cb833e54Eliad Peller					 conf_tid->channel_type,
62992c77c734f958474ac73af670834bc32cb833e54Eliad Peller					 conf_tid->tsid,
63092c77c734f958474ac73af670834bc32cb833e54Eliad Peller					 conf_tid->ps_scheme,
63192c77c734f958474ac73af670834bc32cb833e54Eliad Peller					 conf_tid->ack_policy,
63292c77c734f958474ac73af670834bc32cb833e54Eliad Peller					 conf_tid->apsd_conf[0],
63392c77c734f958474ac73af670834bc32cb833e54Eliad Peller					 conf_tid->apsd_conf[1]);
63492c77c734f958474ac73af670834bc32cb833e54Eliad Peller		if (ret < 0)
63592c77c734f958474ac73af670834bc32cb833e54Eliad Peller			return ret;
63692c77c734f958474ac73af670834bc32cb833e54Eliad Peller	}
63792c77c734f958474ac73af670834bc32cb833e54Eliad Peller
63892c77c734f958474ac73af670834bc32cb833e54Eliad Peller	/* Configure HW encryption */
6390603d891c5b5153f667a79357d4652824c22b54eEliad Peller	ret = wl1271_acx_feature_cfg(wl, wlvif);
64092c77c734f958474ac73af670834bc32cb833e54Eliad Peller	if (ret < 0)
64192c77c734f958474ac73af670834bc32cb833e54Eliad Peller		return ret;
64292c77c734f958474ac73af670834bc32cb833e54Eliad Peller
64392c77c734f958474ac73af670834bc32cb833e54Eliad Peller	/* Mode specific init - post mem init */
64492c77c734f958474ac73af670834bc32cb833e54Eliad Peller	if (is_ap)
64592c77c734f958474ac73af670834bc32cb833e54Eliad Peller		ret = wl1271_ap_hw_init_post_mem(wl, vif);
64692c77c734f958474ac73af670834bc32cb833e54Eliad Peller	else
6470603d891c5b5153f667a79357d4652824c22b54eEliad Peller		ret = wl1271_sta_hw_init_post_mem(wl, vif);
64892c77c734f958474ac73af670834bc32cb833e54Eliad Peller
64992c77c734f958474ac73af670834bc32cb833e54Eliad Peller	if (ret < 0)
65092c77c734f958474ac73af670834bc32cb833e54Eliad Peller		return ret;
65192c77c734f958474ac73af670834bc32cb833e54Eliad Peller
65292c77c734f958474ac73af670834bc32cb833e54Eliad Peller	/* Configure initiator BA sessions policies */
653536129c8ad35de87ff2f864f205a54ac32bfebccEliad Peller	ret = wl1271_set_ba_policies(wl, wlvif);
65492c77c734f958474ac73af670834bc32cb833e54Eliad Peller	if (ret < 0)
65592c77c734f958474ac73af670834bc32cb833e54Eliad Peller		return ret;
65692c77c734f958474ac73af670834bc32cb833e54Eliad Peller
6578a9affc08d676a9fe627361ab6767cdec0740af3Arik Nemtsov	ret = wlcore_hw_init_vif(wl, wlvif);
6588a9affc08d676a9fe627361ab6767cdec0740af3Arik Nemtsov	if (ret < 0)
6598a9affc08d676a9fe627361ab6767cdec0740af3Arik Nemtsov		return ret;
6608a9affc08d676a9fe627361ab6767cdec0740af3Arik Nemtsov
66192c77c734f958474ac73af670834bc32cb833e54Eliad Peller	return 0;
66292c77c734f958474ac73af670834bc32cb833e54Eliad Peller}
66392c77c734f958474ac73af670834bc32cb833e54Eliad Peller
66492c77c734f958474ac73af670834bc32cb833e54Eliad Pellerint wl1271_hw_init(struct wl1271 *wl)
66592c77c734f958474ac73af670834bc32cb833e54Eliad Peller{
66692c77c734f958474ac73af670834bc32cb833e54Eliad Peller	int ret;
66792c77c734f958474ac73af670834bc32cb833e54Eliad Peller
6689d68d1eea7fb4d05b5bd037da6a66329d640b2f1Luciano Coelho	/* Chip-specific hw init */
6699d68d1eea7fb4d05b5bd037da6a66329d640b2f1Luciano Coelho	ret = wl->ops->hw_init(wl);
67048a61477bdc04896bd96d259388a0c42a7019943Shahar Levi	if (ret < 0)
67148a61477bdc04896bd96d259388a0c42a7019943Shahar Levi		return ret;
67248a61477bdc04896bd96d259388a0c42a7019943Shahar Levi
67392c77c734f958474ac73af670834bc32cb833e54Eliad Peller	/* Init templates */
67492c77c734f958474ac73af670834bc32cb833e54Eliad Peller	ret = wl1271_init_templates_config(wl);
67592c77c734f958474ac73af670834bc32cb833e54Eliad Peller	if (ret < 0)
67692c77c734f958474ac73af670834bc32cb833e54Eliad Peller		return ret;
677644a48607cd40954b6fb095b39a3ccaa0204191eJuuso Oikarinen
67892c77c734f958474ac73af670834bc32cb833e54Eliad Peller	ret = wl12xx_acx_mem_cfg(wl);
67992c77c734f958474ac73af670834bc32cb833e54Eliad Peller	if (ret < 0)
68092c77c734f958474ac73af670834bc32cb833e54Eliad Peller		return ret;
68192c77c734f958474ac73af670834bc32cb833e54Eliad Peller
68292c77c734f958474ac73af670834bc32cb833e54Eliad Peller	/* Configure the FW logger */
68392c77c734f958474ac73af670834bc32cb833e54Eliad Peller	ret = wl12xx_init_fwlog(wl);
684f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	if (ret < 0)
685f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho		return ret;
686f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
6876b70e7eb70cd6c5ad445ec02f74b84131a4c721aVictor Goldenshtein	ret = wlcore_cmd_regdomain_config_locked(wl);
6886b70e7eb70cd6c5ad445ec02f74b84131a4c721aVictor Goldenshtein	if (ret < 0)
6896b70e7eb70cd6c5ad445ec02f74b84131a4c721aVictor Goldenshtein		return ret;
6906b70e7eb70cd6c5ad445ec02f74b84131a4c721aVictor Goldenshtein
691801f870bc0524bad7ebef9cea52d20e4d4992e4aArik Nemtsov	/* Bluetooth WLAN coexistence */
692801f870bc0524bad7ebef9cea52d20e4d4992e4aArik Nemtsov	ret = wl1271_init_pta(wl);
693801f870bc0524bad7ebef9cea52d20e4d4992e4aArik Nemtsov	if (ret < 0)
694801f870bc0524bad7ebef9cea52d20e4d4992e4aArik Nemtsov		return ret;
695801f870bc0524bad7ebef9cea52d20e4d4992e4aArik Nemtsov
696f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	/* Default memory configuration */
697f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	ret = wl1271_acx_init_mem_config(wl);
698f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	if (ret < 0)
699f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho		return ret;
700f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
701f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	/* RX config */
70208c1d1c7042330e2280a7718be4ad88c2e8f8268Eliad Peller	ret = wl12xx_init_rx_config(wl);
703f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	if (ret < 0)
704f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho		goto out_free_memmap;
705f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
7066e92b416b0aa6a59629cc32ee2b27129d73b98b8Luciano Coelho	ret = wl1271_acx_dco_itrim_params(wl);
7076e92b416b0aa6a59629cc32ee2b27129d73b98b8Luciano Coelho	if (ret < 0)
7086e92b416b0aa6a59629cc32ee2b27129d73b98b8Luciano Coelho		goto out_free_memmap;
7096e92b416b0aa6a59629cc32ee2b27129d73b98b8Luciano Coelho
710f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	/* Configure TX patch complete interrupt behavior */
711f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	ret = wl1271_acx_tx_config_options(wl);
712f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	if (ret < 0)
713f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho		goto out_free_memmap;
714f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
715f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	/* RX complete interrupt pacing */
716f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	ret = wl1271_acx_init_rx_interrupt(wl);
717f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	if (ret < 0)
718f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho		goto out_free_memmap;
719f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
720f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	/* Energy detection */
721f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	ret = wl1271_init_energy_detection(wl);
722f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	if (ret < 0)
723f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho		goto out_free_memmap;
724f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
725f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	/* Default fragmentation threshold */
7265f704d180e448d05859e1cb6572822ba27dbcdc7Arik Nemtsov	ret = wl1271_acx_frag_threshold(wl, wl->hw->wiphy->frag_threshold);
727f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	if (ret < 0)
728f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho		goto out_free_memmap;
729f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
730f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	/* Enable data path */
73194210897e2b7df8446fdecd360342149e5b4a400Luciano Coelho	ret = wl1271_cmd_data_path(wl, 1);
732f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	if (ret < 0)
733f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho		goto out_free_memmap;
734f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
73538ad2d87d42ba847c100ef132e8e363513982c8bJuuso Oikarinen	/* configure PM */
73638ad2d87d42ba847c100ef132e8e363513982c8bJuuso Oikarinen	ret = wl1271_acx_pm_config(wl);
73738ad2d87d42ba847c100ef132e8e363513982c8bJuuso Oikarinen	if (ret < 0)
73838ad2d87d42ba847c100ef132e8e363513982c8bJuuso Oikarinen		goto out_free_memmap;
73938ad2d87d42ba847c100ef132e8e363513982c8bJuuso Oikarinen
740fa6ad9f0f34b0754ce7551866b33587f077a2a51Eliad Peller	ret = wl12xx_acx_set_rate_mgmt_params(wl);
741fa6ad9f0f34b0754ce7551866b33587f077a2a51Eliad Peller	if (ret < 0)
742fa6ad9f0f34b0754ce7551866b33587f077a2a51Eliad Peller		goto out_free_memmap;
743fa6ad9f0f34b0754ce7551866b33587f077a2a51Eliad Peller
7449487775c5b785d7c1e8182825c9ff9cf5e88149eEliad Peller	/* configure hangover */
7459487775c5b785d7c1e8182825c9ff9cf5e88149eEliad Peller	ret = wl12xx_acx_config_hangover(wl);
7469487775c5b785d7c1e8182825c9ff9cf5e88149eEliad Peller	if (ret < 0)
7479487775c5b785d7c1e8182825c9ff9cf5e88149eEliad Peller		goto out_free_memmap;
7489487775c5b785d7c1e8182825c9ff9cf5e88149eEliad Peller
749f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	return 0;
750f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
751f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho out_free_memmap:
752f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	kfree(wl->target_mem_map);
753344152361e6d14ade61d7f43678db7418cb445dbJuuso Oikarinen	wl->target_mem_map = NULL;
754f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho
755f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho	return ret;
756f5fc0f86b02afef1119b523623b4cde41475bc8cLuciano Coelho}
757