blob: 145601dddab0eb6b53fdf8edfa54dd00cdabedf3 [file] [log] [blame]
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001/*
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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030027
Shahar Levi00d20102010-11-08 11:20:10 +000028#include "init.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030029#include "wl12xx_80211.h"
Shahar Levi00d20102010-11-08 11:20:10 +000030#include "acx.h"
31#include "cmd.h"
32#include "reg.h"
Arik Nemtsove0fe3712010-10-16 18:19:53 +020033#include "tx.h"
Shahar Levi48a61472011-03-06 16:32:08 +020034#include "io.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030035
Eliad Peller92c77c72011-10-05 11:55:40 +020036int wl1271_init_templates_config(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030037{
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +020038 int ret, i;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030039
40 /* send empty templates for fw memory reservation */
41 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, NULL,
Eliad Peller154037d2011-08-14 13:17:12 +030042 WL1271_CMD_TEMPL_DFLT_SIZE,
Juuso Oikarinen606c1482010-04-01 11:38:21 +030043 0, WL1271_RATE_AUTOMATIC);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030044 if (ret < 0)
45 return ret;
46
Juuso Oikarinen11eb5422010-08-24 06:28:03 +030047 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
Eliad Peller154037d2011-08-14 13:17:12 +030048 NULL, WL1271_CMD_TEMPL_DFLT_SIZE, 0,
Juuso Oikarinen11eb5422010-08-24 06:28:03 +030049 WL1271_RATE_AUTOMATIC);
50 if (ret < 0)
51 return ret;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +030052
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030053 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +020054 sizeof(struct wl12xx_null_data_template),
Juuso Oikarinen606c1482010-04-01 11:38:21 +030055 0, WL1271_RATE_AUTOMATIC);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030056 if (ret < 0)
57 return ret;
58
59 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, NULL,
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +020060 sizeof(struct wl12xx_ps_poll_template),
Juuso Oikarinen606c1482010-04-01 11:38:21 +030061 0, WL1271_RATE_AUTOMATIC);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030062 if (ret < 0)
63 return ret;
64
65 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
66 sizeof
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +020067 (struct wl12xx_qos_null_data_template),
Juuso Oikarinen606c1482010-04-01 11:38:21 +030068 0, WL1271_RATE_AUTOMATIC);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030069 if (ret < 0)
70 return ret;
71
72 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE, NULL,
Eliad Peller154037d2011-08-14 13:17:12 +030073 WL1271_CMD_TEMPL_DFLT_SIZE,
Juuso Oikarinen606c1482010-04-01 11:38:21 +030074 0, WL1271_RATE_AUTOMATIC);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030075 if (ret < 0)
76 return ret;
77
78 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON, NULL,
Eliad Peller154037d2011-08-14 13:17:12 +030079 WL1271_CMD_TEMPL_DFLT_SIZE,
Juuso Oikarinen606c1482010-04-01 11:38:21 +030080 0, WL1271_RATE_AUTOMATIC);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030081 if (ret < 0)
82 return ret;
83
Eliad Pellerc5312772010-12-09 11:31:27 +020084 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_ARP_RSP, NULL,
85 sizeof
86 (struct wl12xx_arp_rsp_template),
87 0, WL1271_RATE_AUTOMATIC);
88 if (ret < 0)
89 return ret;
90
Eliad Peller92c77c72011-10-05 11:55:40 +020091 /*
92 * Put very large empty placeholders for all templates. These
93 * reserve memory for later.
94 */
95 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_PROBE_RESPONSE, NULL,
96 WL1271_CMD_TEMPL_MAX_SIZE,
97 0, WL1271_RATE_AUTOMATIC);
98 if (ret < 0)
99 return ret;
100
101 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_BEACON, NULL,
102 WL1271_CMD_TEMPL_MAX_SIZE,
103 0, WL1271_RATE_AUTOMATIC);
104 if (ret < 0)
105 return ret;
106
107 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP, NULL,
108 sizeof
109 (struct wl12xx_disconn_template),
110 0, WL1271_RATE_AUTOMATIC);
111 if (ret < 0)
112 return ret;
113
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200114 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
115 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV, NULL,
Eliad Peller154037d2011-08-14 13:17:12 +0300116 WL1271_CMD_TEMPL_DFLT_SIZE, i,
Juuso Oikarinen606c1482010-04-01 11:38:21 +0300117 WL1271_RATE_AUTOMATIC);
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200118 if (ret < 0)
119 return ret;
120 }
121
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300122 return 0;
123}
124
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200125static int wl1271_ap_init_deauth_template(struct wl1271 *wl)
126{
127 struct wl12xx_disconn_template *tmpl;
128 int ret;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300129 u32 rate;
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200130
131 tmpl = kzalloc(sizeof(*tmpl), GFP_KERNEL);
132 if (!tmpl) {
133 ret = -ENOMEM;
134 goto out;
135 }
136
137 tmpl->header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT |
138 IEEE80211_STYPE_DEAUTH);
139
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300140 rate = wl1271_tx_min_rate_get(wl, wl->basic_rate_set);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200141 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300142 tmpl, sizeof(*tmpl), 0, rate);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200143
144out:
145 kfree(tmpl);
146 return ret;
147}
148
Eliad Peller784f6942011-10-05 11:55:39 +0200149static int wl1271_ap_init_null_template(struct wl1271 *wl,
150 struct ieee80211_vif *vif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200151{
152 struct ieee80211_hdr_3addr *nullfunc;
153 int ret;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300154 u32 rate;
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200155
156 nullfunc = kzalloc(sizeof(*nullfunc), GFP_KERNEL);
157 if (!nullfunc) {
158 ret = -ENOMEM;
159 goto out;
160 }
161
162 nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
163 IEEE80211_STYPE_NULLFUNC |
164 IEEE80211_FCTL_FROMDS);
165
166 /* nullfunc->addr1 is filled by FW */
167
Eliad Peller784f6942011-10-05 11:55:39 +0200168 memcpy(nullfunc->addr2, vif->addr, ETH_ALEN);
169 memcpy(nullfunc->addr3, vif->addr, ETH_ALEN);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200170
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300171 rate = wl1271_tx_min_rate_get(wl, wl->basic_rate_set);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200172 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, nullfunc,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300173 sizeof(*nullfunc), 0, rate);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200174
175out:
176 kfree(nullfunc);
177 return ret;
178}
179
Eliad Peller784f6942011-10-05 11:55:39 +0200180static int wl1271_ap_init_qos_null_template(struct wl1271 *wl,
181 struct ieee80211_vif *vif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200182{
183 struct ieee80211_qos_hdr *qosnull;
184 int ret;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300185 u32 rate;
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200186
187 qosnull = kzalloc(sizeof(*qosnull), GFP_KERNEL);
188 if (!qosnull) {
189 ret = -ENOMEM;
190 goto out;
191 }
192
193 qosnull->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
194 IEEE80211_STYPE_QOS_NULLFUNC |
195 IEEE80211_FCTL_FROMDS);
196
197 /* qosnull->addr1 is filled by FW */
198
Eliad Peller784f6942011-10-05 11:55:39 +0200199 memcpy(qosnull->addr2, vif->addr, ETH_ALEN);
200 memcpy(qosnull->addr3, vif->addr, ETH_ALEN);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200201
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300202 rate = wl1271_tx_min_rate_get(wl, wl->basic_rate_set);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200203 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, qosnull,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300204 sizeof(*qosnull), 0, rate);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200205
206out:
207 kfree(qosnull);
208 return ret;
209}
210
Eliad Peller08c1d1c2011-08-14 13:17:04 +0300211static int wl12xx_init_rx_config(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300212{
213 int ret;
214
Juuso Oikarinen8793f9b2009-10-13 12:47:40 +0300215 ret = wl1271_acx_rx_msdu_life_time(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300216 if (ret < 0)
217 return ret;
218
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300219 return 0;
220}
221
Luciano Coelho12419cc2010-02-18 13:25:44 +0200222int wl1271_init_phy_config(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300223{
224 int ret;
225
226 ret = wl1271_acx_pd_threshold(wl);
227 if (ret < 0)
228 return ret;
229
Eliad Peller92c77c72011-10-05 11:55:40 +0200230 return 0;
231}
232
233static int wl12xx_init_phy_vif_config(struct wl1271 *wl)
234{
235 int ret;
236
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300237 ret = wl1271_acx_slot(wl, DEFAULT_SLOT_TIME);
238 if (ret < 0)
239 return ret;
240
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300241 ret = wl1271_acx_service_period_timeout(wl);
242 if (ret < 0)
243 return ret;
244
Arik Nemtsov5f704d12011-04-18 14:15:21 +0300245 ret = wl1271_acx_rts_threshold(wl, wl->hw->wiphy->rts_threshold);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300246 if (ret < 0)
247 return ret;
248
249 return 0;
250}
251
252static int wl1271_init_beacon_filter(struct wl1271 *wl)
253{
254 int ret;
255
Juuso Oikarinen19221672009-10-08 21:56:35 +0300256 /* disable beacon filtering at this stage */
257 ret = wl1271_acx_beacon_filter_opt(wl, false);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300258 if (ret < 0)
259 return ret;
260
261 ret = wl1271_acx_beacon_filter_table(wl);
262 if (ret < 0)
263 return ret;
264
265 return 0;
266}
267
Luciano Coelho12419cc2010-02-18 13:25:44 +0200268int wl1271_init_pta(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300269{
270 int ret;
271
Eliad Peller3be41122011-08-14 13:17:19 +0300272 ret = wl12xx_acx_sg_cfg(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300273 if (ret < 0)
274 return ret;
275
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +0200276 ret = wl1271_acx_sg_enable(wl, wl->sg_enabled);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300277 if (ret < 0)
278 return ret;
279
280 return 0;
281}
282
Luciano Coelho12419cc2010-02-18 13:25:44 +0200283int wl1271_init_energy_detection(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300284{
285 int ret;
286
287 ret = wl1271_acx_cca_threshold(wl);
288 if (ret < 0)
289 return ret;
290
291 return 0;
292}
293
294static int wl1271_init_beacon_broadcast(struct wl1271 *wl)
295{
296 int ret;
297
298 ret = wl1271_acx_bcn_dtim_options(wl);
299 if (ret < 0)
300 return ret;
301
302 return 0;
303}
304
Ido Yariv95dac04f2011-06-06 14:57:06 +0300305static int wl12xx_init_fwlog(struct wl1271 *wl)
306{
307 int ret;
308
309 if (wl->quirks & WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED)
310 return 0;
311
312 ret = wl12xx_cmd_config_fwlog(wl);
313 if (ret < 0)
314 return ret;
315
316 return 0;
317}
318
Eliad Peller92c77c72011-10-05 11:55:40 +0200319/* generic sta initialization (non vif-specific) */
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200320static int wl1271_sta_hw_init(struct wl1271 *wl)
321{
322 int ret;
323
Shahar Levi49d750ca2011-03-06 16:32:09 +0200324 if (wl->chip.id != CHIP_ID_1283_PG20) {
325 ret = wl1271_cmd_ext_radio_parms(wl);
326 if (ret < 0)
327 return ret;
328 }
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200329
Eliad Pellerc8bde242011-02-02 09:59:35 +0200330 /* PS config */
331 ret = wl1271_acx_config_ps(wl);
332 if (ret < 0)
333 return ret;
334
Shahar Leviff868432011-04-11 15:41:46 +0300335 /* FM WLAN coexistence */
336 ret = wl1271_acx_fm_coex(wl);
337 if (ret < 0)
338 return ret;
339
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200340 /* Configure for ELP power saving */
341 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
342 if (ret < 0)
343 return ret;
344
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200345 ret = wl1271_acx_sta_rate_policies(wl);
346 if (ret < 0)
347 return ret;
348
349 return 0;
350}
351
352static int wl1271_sta_hw_init_post_mem(struct wl1271 *wl)
353{
354 int ret, i;
355
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200356 /* disable all keep-alive templates */
357 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
358 ret = wl1271_acx_keep_alive_config(wl, i,
359 ACX_KEEP_ALIVE_TPL_INVALID);
360 if (ret < 0)
361 return ret;
362 }
363
364 /* disable the keep-alive feature */
365 ret = wl1271_acx_keep_alive_mode(wl, false);
366 if (ret < 0)
367 return ret;
368
369 return 0;
370}
371
Eliad Peller92c77c72011-10-05 11:55:40 +0200372/* generic ap initialization (non vif-specific) */
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200373static int wl1271_ap_hw_init(struct wl1271 *wl)
374{
Arik Nemtsov70f47422011-04-18 14:15:25 +0300375 int ret;
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200376
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200377 /* Configure for power always on */
378 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
379 if (ret < 0)
380 return ret;
381
Arik Nemtsov70f47422011-04-18 14:15:25 +0300382 ret = wl1271_init_ap_rates(wl);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200383 if (ret < 0)
384 return ret;
385
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200386 return 0;
387}
388
Eliad Peller784f6942011-10-05 11:55:39 +0200389int wl1271_ap_init_templates(struct wl1271 *wl, struct ieee80211_vif *vif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200390{
391 int ret;
392
393 ret = wl1271_ap_init_deauth_template(wl);
394 if (ret < 0)
395 return ret;
396
Eliad Peller784f6942011-10-05 11:55:39 +0200397 ret = wl1271_ap_init_null_template(wl, vif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200398 if (ret < 0)
399 return ret;
400
Eliad Peller784f6942011-10-05 11:55:39 +0200401 ret = wl1271_ap_init_qos_null_template(wl, vif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200402 if (ret < 0)
403 return ret;
404
Arik Nemtsov521a4a22011-04-18 14:15:22 +0300405 /*
406 * when operating as AP we want to receive external beacons for
407 * configuring ERP protection.
408 */
Eliad Pellerf42bd2c2011-08-14 13:17:13 +0300409 ret = wl1271_acx_beacon_filter_opt(wl, false);
Arik Nemtsov521a4a22011-04-18 14:15:22 +0300410 if (ret < 0)
411 return ret;
412
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200413 return 0;
414}
415
Eliad Peller784f6942011-10-05 11:55:39 +0200416static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl,
417 struct ieee80211_vif *vif)
Arik Nemtsovc45a85b2011-04-18 14:15:26 +0300418{
Eliad Peller784f6942011-10-05 11:55:39 +0200419 return wl1271_ap_init_templates(wl, vif);
Arik Nemtsovc45a85b2011-04-18 14:15:26 +0300420}
421
Arik Nemtsov70f47422011-04-18 14:15:25 +0300422int wl1271_init_ap_rates(struct wl1271 *wl)
423{
424 int i, ret;
425 struct conf_tx_rate_class rc;
426 u32 supported_rates;
427
428 wl1271_debug(DEBUG_AP, "AP basic rate set: 0x%x", wl->basic_rate_set);
429
430 if (wl->basic_rate_set == 0)
431 return -EINVAL;
432
433 rc.enabled_rates = wl->basic_rate_set;
434 rc.long_retry_limit = 10;
435 rc.short_retry_limit = 10;
436 rc.aflags = 0;
437 ret = wl1271_acx_ap_rate_policy(wl, &rc, ACX_TX_AP_MODE_MGMT_RATE);
438 if (ret < 0)
439 return ret;
440
441 /* use the min basic rate for AP broadcast/multicast */
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300442 rc.enabled_rates = wl1271_tx_min_rate_get(wl, wl->basic_rate_set);
Arik Nemtsov70f47422011-04-18 14:15:25 +0300443 rc.short_retry_limit = 10;
444 rc.long_retry_limit = 10;
445 rc.aflags = 0;
446 ret = wl1271_acx_ap_rate_policy(wl, &rc, ACX_TX_AP_MODE_BCST_RATE);
447 if (ret < 0)
448 return ret;
449
450 /*
451 * If the basic rates contain OFDM rates, use OFDM only
452 * rates for unicast TX as well. Else use all supported rates.
453 */
454 if ((wl->basic_rate_set & CONF_TX_OFDM_RATES))
455 supported_rates = CONF_TX_OFDM_RATES;
456 else
457 supported_rates = CONF_TX_AP_ENABLED_RATES;
458
Arik Nemtsov1a8adb62011-08-14 13:17:29 +0300459 /* unconditionally enable HT rates */
460 supported_rates |= CONF_TX_MCS_RATES;
461
Arik Nemtsov70f47422011-04-18 14:15:25 +0300462 /* configure unicast TX rate classes */
463 for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
464 rc.enabled_rates = supported_rates;
465 rc.short_retry_limit = 10;
466 rc.long_retry_limit = 10;
467 rc.aflags = 0;
468 ret = wl1271_acx_ap_rate_policy(wl, &rc, i);
469 if (ret < 0)
470 return ret;
471 }
472
473 return 0;
474}
475
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100476static int wl1271_set_ba_policies(struct wl1271 *wl)
477{
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100478 /* Reset the BA RX indicators */
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100479 wl->ba_rx_bitmap = 0;
Shahar Levi70559a02011-05-22 16:10:22 +0300480 wl->ba_allowed = true;
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300481 wl->ba_rx_session_count = 0;
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100482
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300483 /* BA is supported in STA/AP modes */
484 if (wl->bss_type != BSS_TYPE_AP_BSS &&
485 wl->bss_type != BSS_TYPE_STA_BSS) {
486 wl->ba_support = false;
487 return 0;
488 }
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100489
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300490 wl->ba_support = true;
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100491
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300492 /* 802.11n initiator BA session setting */
493 return wl12xx_acx_set_ba_initiator_policy(wl);
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100494}
495
Shahar Levi48a61472011-03-06 16:32:08 +0200496int wl1271_chip_specific_init(struct wl1271 *wl)
497{
498 int ret = 0;
499
500 if (wl->chip.id == CHIP_ID_1283_PG20) {
501 u32 host_cfg_bitmap = HOST_IF_CFG_RX_FIFO_ENABLE;
502
Ido Yariv0da13da2011-03-31 10:06:58 +0200503 if (wl->quirks & WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT)
Shahar Levi48a61472011-03-06 16:32:08 +0200504 /* Enable SDIO padding */
505 host_cfg_bitmap |= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK;
506
507 /* Must be before wl1271_acx_init_mem_config() */
508 ret = wl1271_acx_host_if_cfg_bitmap(wl, host_cfg_bitmap);
509 if (ret < 0)
510 goto out;
511 }
512out:
513 return ret;
514}
515
Eliad Peller92c77c72011-10-05 11:55:40 +0200516/* vif-specifc initialization */
517static int wl12xx_init_sta_role(struct wl1271 *wl, struct ieee80211_vif *vif)
518{
519 int ret;
Shahar Levi48a61472011-03-06 16:32:08 +0200520
Eliad Peller92c77c72011-10-05 11:55:40 +0200521 ret = wl1271_acx_group_address_tbl(wl, true, NULL, 0);
522 if (ret < 0)
523 return ret;
524
525 /* Initialize connection monitoring thresholds */
526 ret = wl1271_acx_conn_monit_params(wl, false);
527 if (ret < 0)
528 return ret;
529
530 /* Beacon filtering */
531 ret = wl1271_init_beacon_filter(wl);
532 if (ret < 0)
533 return ret;
534
535 /* Beacons and broadcast settings */
536 ret = wl1271_init_beacon_broadcast(wl);
537 if (ret < 0)
538 return ret;
539
540 /* Configure rssi/snr averaging weights */
541 ret = wl1271_acx_rssi_snr_avg_weights(wl);
542 if (ret < 0)
543 return ret;
544
545 return 0;
546}
547
548/* vif-specific intialization */
549static int wl12xx_init_ap_role(struct wl1271 *wl, struct ieee80211_vif *vif)
550{
551 int ret;
552
553 ret = wl1271_acx_ap_max_tx_retry(wl);
554 if (ret < 0)
555 return ret;
556
557 /* initialize Tx power */
558 ret = wl1271_acx_tx_power(wl, wl->power_level);
559 if (ret < 0)
560 return ret;
561
562 return 0;
563}
564
565int wl1271_init_vif_specific(struct wl1271 *wl, struct ieee80211_vif *vif)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300566{
Kalle Valo243eeb52010-02-18 13:25:39 +0200567 struct conf_tx_ac_category *conf_ac;
Kalle Valof2054df2010-02-18 13:25:40 +0200568 struct conf_tx_tid *conf_tid;
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200569 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300570
Eliad Peller92c77c72011-10-05 11:55:40 +0200571 int ret, i;
572
573 /* Mode specific init */
574 if (is_ap) {
575 ret = wl1271_ap_hw_init(wl);
576 if (ret < 0)
577 return ret;
578
579 ret = wl12xx_init_ap_role(wl, vif);
580 if (ret < 0)
581 return ret;
582 } else {
583 ret = wl1271_sta_hw_init(wl);
584 if (ret < 0)
585 return ret;
586
587 ret = wl12xx_init_sta_role(wl, vif);
588 if (ret < 0)
589 return ret;
590 }
591
592 wl12xx_init_phy_vif_config(wl);
593
594 /* Default TID/AC configuration */
595 BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
596 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
597 conf_ac = &wl->conf.tx.ac_conf[i];
598 ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
599 conf_ac->cw_max, conf_ac->aifsn,
600 conf_ac->tx_op_limit);
601 if (ret < 0)
602 return ret;
603
604 conf_tid = &wl->conf.tx.tid_conf[i];
605 ret = wl1271_acx_tid_cfg(wl,
606 conf_tid->queue_id,
607 conf_tid->channel_type,
608 conf_tid->tsid,
609 conf_tid->ps_scheme,
610 conf_tid->ack_policy,
611 conf_tid->apsd_conf[0],
612 conf_tid->apsd_conf[1]);
613 if (ret < 0)
614 return ret;
615 }
616
617 /* Configure HW encryption */
618 ret = wl1271_acx_feature_cfg(wl);
619 if (ret < 0)
620 return ret;
621
622 /* Mode specific init - post mem init */
623 if (is_ap)
624 ret = wl1271_ap_hw_init_post_mem(wl, vif);
625 else
626 ret = wl1271_sta_hw_init_post_mem(wl);
627
628 if (ret < 0)
629 return ret;
630
631 /* Configure initiator BA sessions policies */
632 ret = wl1271_set_ba_policies(wl);
633 if (ret < 0)
634 return ret;
635
636 return 0;
637}
638
639int wl1271_hw_init(struct wl1271 *wl)
640{
641 int ret;
642
Shahar Levi49d750ca2011-03-06 16:32:09 +0200643 if (wl->chip.id == CHIP_ID_1283_PG20)
644 ret = wl128x_cmd_general_parms(wl);
645 else
646 ret = wl1271_cmd_general_parms(wl);
Luciano Coelho4a904062009-11-23 23:22:18 +0200647 if (ret < 0)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300648 return ret;
649
Shahar Levi49d750ca2011-03-06 16:32:09 +0200650 if (wl->chip.id == CHIP_ID_1283_PG20)
651 ret = wl128x_cmd_radio_parms(wl);
652 else
653 ret = wl1271_cmd_radio_parms(wl);
Luciano Coelho4a904062009-11-23 23:22:18 +0200654 if (ret < 0)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300655 return ret;
656
Shahar Levi48a61472011-03-06 16:32:08 +0200657 /* Chip-specific init */
658 ret = wl1271_chip_specific_init(wl);
659 if (ret < 0)
660 return ret;
661
Eliad Peller92c77c72011-10-05 11:55:40 +0200662 /* Init templates */
663 ret = wl1271_init_templates_config(wl);
664 if (ret < 0)
665 return ret;
Juuso Oikarinen644a4862010-10-05 13:11:56 +0200666
Eliad Peller92c77c72011-10-05 11:55:40 +0200667 ret = wl12xx_acx_mem_cfg(wl);
668 if (ret < 0)
669 return ret;
670
671 /* Configure the FW logger */
672 ret = wl12xx_init_fwlog(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300673 if (ret < 0)
674 return ret;
675
Arik Nemtsov801f8702011-04-18 14:15:20 +0300676 /* Bluetooth WLAN coexistence */
677 ret = wl1271_init_pta(wl);
678 if (ret < 0)
679 return ret;
680
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300681 /* Default memory configuration */
682 ret = wl1271_acx_init_mem_config(wl);
683 if (ret < 0)
684 return ret;
685
686 /* RX config */
Eliad Peller08c1d1c2011-08-14 13:17:04 +0300687 ret = wl12xx_init_rx_config(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300688 if (ret < 0)
689 goto out_free_memmap;
690
691 /* PHY layer config */
692 ret = wl1271_init_phy_config(wl);
693 if (ret < 0)
694 goto out_free_memmap;
695
Luciano Coelho6e92b412009-12-11 15:40:50 +0200696 ret = wl1271_acx_dco_itrim_params(wl);
697 if (ret < 0)
698 goto out_free_memmap;
699
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300700 /* Configure TX patch complete interrupt behavior */
701 ret = wl1271_acx_tx_config_options(wl);
702 if (ret < 0)
703 goto out_free_memmap;
704
705 /* RX complete interrupt pacing */
706 ret = wl1271_acx_init_rx_interrupt(wl);
707 if (ret < 0)
708 goto out_free_memmap;
709
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300710 /* Energy detection */
711 ret = wl1271_init_energy_detection(wl);
712 if (ret < 0)
713 goto out_free_memmap;
714
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300715 /* Default fragmentation threshold */
Arik Nemtsov5f704d12011-04-18 14:15:21 +0300716 ret = wl1271_acx_frag_threshold(wl, wl->hw->wiphy->frag_threshold);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300717 if (ret < 0)
718 goto out_free_memmap;
719
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300720 /* Enable data path */
Luciano Coelho94210892009-12-11 15:40:55 +0200721 ret = wl1271_cmd_data_path(wl, 1);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300722 if (ret < 0)
723 goto out_free_memmap;
724
Juuso Oikarinen38ad2d82009-12-11 15:41:08 +0200725 /* configure PM */
726 ret = wl1271_acx_pm_config(wl);
727 if (ret < 0)
728 goto out_free_memmap;
729
Eliad Pellerfa6ad9f2011-08-14 13:17:14 +0300730 ret = wl12xx_acx_set_rate_mgmt_params(wl);
731 if (ret < 0)
732 goto out_free_memmap;
733
Eliad Peller94877752011-08-28 15:11:56 +0300734 /* configure hangover */
735 ret = wl12xx_acx_config_hangover(wl);
736 if (ret < 0)
737 goto out_free_memmap;
738
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300739 return 0;
740
741 out_free_memmap:
742 kfree(wl->target_mem_map);
Juuso Oikarinen34415232009-10-08 21:56:33 +0300743 wl->target_mem_map = NULL;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300744
745 return ret;
746}