blob: b1242a6de27b1f9f16acaecada09918dec808c5f [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
Arik Nemtsove0fe3712010-10-16 18:19:53 +020036int wl1271_sta_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,
Guy Eilamea559b42010-12-09 16:54:59 +020042 WL1271_CMD_TEMPL_MAX_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,
Guy Eilamea559b42010-12-09 16:54:59 +020048 NULL, WL1271_CMD_TEMPL_MAX_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,
73 sizeof
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +020074 (struct wl12xx_probe_resp_template),
Juuso Oikarinen606c1482010-04-01 11:38:21 +030075 0, WL1271_RATE_AUTOMATIC);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030076 if (ret < 0)
77 return ret;
78
79 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON, NULL,
80 sizeof
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +020081 (struct wl12xx_beacon_template),
Juuso Oikarinen606c1482010-04-01 11:38:21 +030082 0, WL1271_RATE_AUTOMATIC);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030083 if (ret < 0)
84 return ret;
85
Eliad Pellerc5312772010-12-09 11:31:27 +020086 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_ARP_RSP, NULL,
87 sizeof
88 (struct wl12xx_arp_rsp_template),
89 0, WL1271_RATE_AUTOMATIC);
90 if (ret < 0)
91 return ret;
92
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +020093 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
94 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV, NULL,
Juuso Oikarinen606c1482010-04-01 11:38:21 +030095 WL1271_CMD_TEMPL_MAX_SIZE, i,
96 WL1271_RATE_AUTOMATIC);
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +020097 if (ret < 0)
98 return ret;
99 }
100
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300101 return 0;
102}
103
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200104static int wl1271_ap_init_deauth_template(struct wl1271 *wl)
105{
106 struct wl12xx_disconn_template *tmpl;
107 int ret;
108
109 tmpl = kzalloc(sizeof(*tmpl), GFP_KERNEL);
110 if (!tmpl) {
111 ret = -ENOMEM;
112 goto out;
113 }
114
115 tmpl->header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT |
116 IEEE80211_STYPE_DEAUTH);
117
118 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP,
119 tmpl, sizeof(*tmpl), 0,
120 wl1271_tx_min_rate_get(wl));
121
122out:
123 kfree(tmpl);
124 return ret;
125}
126
127static int wl1271_ap_init_null_template(struct wl1271 *wl)
128{
129 struct ieee80211_hdr_3addr *nullfunc;
130 int ret;
131
132 nullfunc = kzalloc(sizeof(*nullfunc), GFP_KERNEL);
133 if (!nullfunc) {
134 ret = -ENOMEM;
135 goto out;
136 }
137
138 nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
139 IEEE80211_STYPE_NULLFUNC |
140 IEEE80211_FCTL_FROMDS);
141
142 /* nullfunc->addr1 is filled by FW */
143
144 memcpy(nullfunc->addr2, wl->mac_addr, ETH_ALEN);
145 memcpy(nullfunc->addr3, wl->mac_addr, ETH_ALEN);
146
147 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, nullfunc,
148 sizeof(*nullfunc), 0,
149 wl1271_tx_min_rate_get(wl));
150
151out:
152 kfree(nullfunc);
153 return ret;
154}
155
156static int wl1271_ap_init_qos_null_template(struct wl1271 *wl)
157{
158 struct ieee80211_qos_hdr *qosnull;
159 int ret;
160
161 qosnull = kzalloc(sizeof(*qosnull), GFP_KERNEL);
162 if (!qosnull) {
163 ret = -ENOMEM;
164 goto out;
165 }
166
167 qosnull->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
168 IEEE80211_STYPE_QOS_NULLFUNC |
169 IEEE80211_FCTL_FROMDS);
170
171 /* qosnull->addr1 is filled by FW */
172
173 memcpy(qosnull->addr2, wl->mac_addr, ETH_ALEN);
174 memcpy(qosnull->addr3, wl->mac_addr, ETH_ALEN);
175
176 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, qosnull,
177 sizeof(*qosnull), 0,
178 wl1271_tx_min_rate_get(wl));
179
180out:
181 kfree(qosnull);
182 return ret;
183}
184
185static int wl1271_ap_init_templates_config(struct wl1271 *wl)
186{
187 int ret;
188
189 /*
190 * Put very large empty placeholders for all templates. These
191 * reserve memory for later.
192 */
193 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_PROBE_RESPONSE, NULL,
194 sizeof
195 (struct wl12xx_probe_resp_template),
196 0, WL1271_RATE_AUTOMATIC);
197 if (ret < 0)
198 return ret;
199
200 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_BEACON, NULL,
201 sizeof
202 (struct wl12xx_beacon_template),
203 0, WL1271_RATE_AUTOMATIC);
204 if (ret < 0)
205 return ret;
206
207 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP, NULL,
208 sizeof
209 (struct wl12xx_disconn_template),
210 0, WL1271_RATE_AUTOMATIC);
211 if (ret < 0)
212 return ret;
213
214 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
215 sizeof(struct wl12xx_null_data_template),
216 0, WL1271_RATE_AUTOMATIC);
217 if (ret < 0)
218 return ret;
219
220 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
221 sizeof
222 (struct wl12xx_qos_null_data_template),
223 0, WL1271_RATE_AUTOMATIC);
224 if (ret < 0)
225 return ret;
226
227 return 0;
228}
229
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300230static int wl1271_init_rx_config(struct wl1271 *wl, u32 config, u32 filter)
231{
232 int ret;
233
Juuso Oikarinen8793f9b2009-10-13 12:47:40 +0300234 ret = wl1271_acx_rx_msdu_life_time(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300235 if (ret < 0)
236 return ret;
237
238 ret = wl1271_acx_rx_config(wl, config, filter);
239 if (ret < 0)
240 return ret;
241
242 return 0;
243}
244
Luciano Coelho12419cc2010-02-18 13:25:44 +0200245int wl1271_init_phy_config(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300246{
247 int ret;
248
249 ret = wl1271_acx_pd_threshold(wl);
250 if (ret < 0)
251 return ret;
252
253 ret = wl1271_acx_slot(wl, DEFAULT_SLOT_TIME);
254 if (ret < 0)
255 return ret;
256
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300257 ret = wl1271_acx_service_period_timeout(wl);
258 if (ret < 0)
259 return ret;
260
Arik Nemtsov5f704d12011-04-18 14:15:21 +0300261 ret = wl1271_acx_rts_threshold(wl, wl->hw->wiphy->rts_threshold);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300262 if (ret < 0)
263 return ret;
264
265 return 0;
266}
267
268static int wl1271_init_beacon_filter(struct wl1271 *wl)
269{
270 int ret;
271
Juuso Oikarinen19221672009-10-08 21:56:35 +0300272 /* disable beacon filtering at this stage */
273 ret = wl1271_acx_beacon_filter_opt(wl, false);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300274 if (ret < 0)
275 return ret;
276
277 ret = wl1271_acx_beacon_filter_table(wl);
278 if (ret < 0)
279 return ret;
280
281 return 0;
282}
283
Luciano Coelho12419cc2010-02-18 13:25:44 +0200284int wl1271_init_pta(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300285{
286 int ret;
287
Arik Nemtsov801f8702011-04-18 14:15:20 +0300288 if (wl->bss_type == BSS_TYPE_AP_BSS)
289 ret = wl1271_acx_ap_sg_cfg(wl);
290 else
291 ret = wl1271_acx_sta_sg_cfg(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300292 if (ret < 0)
293 return ret;
294
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +0200295 ret = wl1271_acx_sg_enable(wl, wl->sg_enabled);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300296 if (ret < 0)
297 return ret;
298
299 return 0;
300}
301
Luciano Coelho12419cc2010-02-18 13:25:44 +0200302int wl1271_init_energy_detection(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300303{
304 int ret;
305
306 ret = wl1271_acx_cca_threshold(wl);
307 if (ret < 0)
308 return ret;
309
310 return 0;
311}
312
313static int wl1271_init_beacon_broadcast(struct wl1271 *wl)
314{
315 int ret;
316
317 ret = wl1271_acx_bcn_dtim_options(wl);
318 if (ret < 0)
319 return ret;
320
321 return 0;
322}
323
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200324static int wl1271_sta_hw_init(struct wl1271 *wl)
325{
326 int ret;
327
Shahar Levi49d750ca2011-03-06 16:32:09 +0200328 if (wl->chip.id != CHIP_ID_1283_PG20) {
329 ret = wl1271_cmd_ext_radio_parms(wl);
330 if (ret < 0)
331 return ret;
332 }
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200333
Eliad Pellerc8bde242011-02-02 09:59:35 +0200334 /* PS config */
335 ret = wl1271_acx_config_ps(wl);
336 if (ret < 0)
337 return ret;
338
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200339 ret = wl1271_sta_init_templates_config(wl);
340 if (ret < 0)
341 return ret;
342
343 ret = wl1271_acx_group_address_tbl(wl, true, NULL, 0);
344 if (ret < 0)
345 return ret;
346
347 /* Initialize connection monitoring thresholds */
348 ret = wl1271_acx_conn_monit_params(wl, false);
349 if (ret < 0)
350 return ret;
351
352 /* Beacon filtering */
353 ret = wl1271_init_beacon_filter(wl);
354 if (ret < 0)
355 return ret;
356
Shahar Leviff868432011-04-11 15:41:46 +0300357 /* FM WLAN coexistence */
358 ret = wl1271_acx_fm_coex(wl);
359 if (ret < 0)
360 return ret;
361
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200362 /* Beacons and broadcast settings */
363 ret = wl1271_init_beacon_broadcast(wl);
364 if (ret < 0)
365 return ret;
366
367 /* Configure for ELP power saving */
368 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
369 if (ret < 0)
370 return ret;
371
372 /* Configure rssi/snr averaging weights */
373 ret = wl1271_acx_rssi_snr_avg_weights(wl);
374 if (ret < 0)
375 return ret;
376
377 ret = wl1271_acx_sta_rate_policies(wl);
378 if (ret < 0)
379 return ret;
380
Arik Nemtsov47684802011-04-26 23:21:51 +0300381 ret = wl1271_acx_sta_max_tx_retry(wl);
382 if (ret < 0)
383 return ret;
384
Eliad Pellerc8bde242011-02-02 09:59:35 +0200385 ret = wl1271_acx_sta_mem_cfg(wl);
386 if (ret < 0)
387 return ret;
388
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200389 return 0;
390}
391
392static int wl1271_sta_hw_init_post_mem(struct wl1271 *wl)
393{
394 int ret, i;
395
396 ret = wl1271_cmd_set_sta_default_wep_key(wl, wl->default_key);
397 if (ret < 0) {
398 wl1271_warning("couldn't set default key");
399 return ret;
400 }
401
402 /* disable all keep-alive templates */
403 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
404 ret = wl1271_acx_keep_alive_config(wl, i,
405 ACX_KEEP_ALIVE_TPL_INVALID);
406 if (ret < 0)
407 return ret;
408 }
409
410 /* disable the keep-alive feature */
411 ret = wl1271_acx_keep_alive_mode(wl, false);
412 if (ret < 0)
413 return ret;
414
415 return 0;
416}
417
418static int wl1271_ap_hw_init(struct wl1271 *wl)
419{
Arik Nemtsov70f47422011-04-18 14:15:25 +0300420 int ret;
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200421
422 ret = wl1271_ap_init_templates_config(wl);
423 if (ret < 0)
424 return ret;
425
426 /* Configure for power always on */
427 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
428 if (ret < 0)
429 return ret;
430
Arik Nemtsov70f47422011-04-18 14:15:25 +0300431 ret = wl1271_init_ap_rates(wl);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200432 if (ret < 0)
433 return ret;
434
Arik Nemtsov47684802011-04-26 23:21:51 +0300435 ret = wl1271_acx_ap_max_tx_retry(wl);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200436 if (ret < 0)
437 return ret;
438
Eliad Pellerc8bde242011-02-02 09:59:35 +0200439 ret = wl1271_acx_ap_mem_cfg(wl);
440 if (ret < 0)
441 return ret;
442
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200443 return 0;
444}
445
Arik Nemtsovc45a85b2011-04-18 14:15:26 +0300446int wl1271_ap_init_templates(struct wl1271 *wl)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200447{
448 int ret;
449
450 ret = wl1271_ap_init_deauth_template(wl);
451 if (ret < 0)
452 return ret;
453
454 ret = wl1271_ap_init_null_template(wl);
455 if (ret < 0)
456 return ret;
457
458 ret = wl1271_ap_init_qos_null_template(wl);
459 if (ret < 0)
460 return ret;
461
Arik Nemtsov521a4a22011-04-18 14:15:22 +0300462 /*
463 * when operating as AP we want to receive external beacons for
464 * configuring ERP protection.
465 */
466 ret = wl1271_acx_set_ap_beacon_filter(wl, false);
467 if (ret < 0)
468 return ret;
469
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200470 return 0;
471}
472
Arik Nemtsovc45a85b2011-04-18 14:15:26 +0300473static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl)
474{
475 return wl1271_ap_init_templates(wl);
476}
477
Arik Nemtsov70f47422011-04-18 14:15:25 +0300478int wl1271_init_ap_rates(struct wl1271 *wl)
479{
480 int i, ret;
481 struct conf_tx_rate_class rc;
482 u32 supported_rates;
483
484 wl1271_debug(DEBUG_AP, "AP basic rate set: 0x%x", wl->basic_rate_set);
485
486 if (wl->basic_rate_set == 0)
487 return -EINVAL;
488
489 rc.enabled_rates = wl->basic_rate_set;
490 rc.long_retry_limit = 10;
491 rc.short_retry_limit = 10;
492 rc.aflags = 0;
493 ret = wl1271_acx_ap_rate_policy(wl, &rc, ACX_TX_AP_MODE_MGMT_RATE);
494 if (ret < 0)
495 return ret;
496
497 /* use the min basic rate for AP broadcast/multicast */
498 rc.enabled_rates = wl1271_tx_min_rate_get(wl);
499 rc.short_retry_limit = 10;
500 rc.long_retry_limit = 10;
501 rc.aflags = 0;
502 ret = wl1271_acx_ap_rate_policy(wl, &rc, ACX_TX_AP_MODE_BCST_RATE);
503 if (ret < 0)
504 return ret;
505
506 /*
507 * If the basic rates contain OFDM rates, use OFDM only
508 * rates for unicast TX as well. Else use all supported rates.
509 */
510 if ((wl->basic_rate_set & CONF_TX_OFDM_RATES))
511 supported_rates = CONF_TX_OFDM_RATES;
512 else
513 supported_rates = CONF_TX_AP_ENABLED_RATES;
514
515 /* configure unicast TX rate classes */
516 for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
517 rc.enabled_rates = supported_rates;
518 rc.short_retry_limit = 10;
519 rc.long_retry_limit = 10;
520 rc.aflags = 0;
521 ret = wl1271_acx_ap_rate_policy(wl, &rc, i);
522 if (ret < 0)
523 return ret;
524 }
525
526 return 0;
527}
528
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100529static void wl1271_check_ba_support(struct wl1271 *wl)
530{
531 /* validate FW cose ver x.x.x.50-60.x */
532 if ((wl->chip.fw_ver[3] >= WL12XX_BA_SUPPORT_FW_COST_VER2_START) &&
533 (wl->chip.fw_ver[3] < WL12XX_BA_SUPPORT_FW_COST_VER2_END)) {
534 wl->ba_support = true;
535 return;
536 }
537
538 wl->ba_support = false;
539}
540
541static int wl1271_set_ba_policies(struct wl1271 *wl)
542{
543 u8 tid_index;
Dan Carpenter03c5a9c2011-02-07 19:47:42 +0300544 int ret = 0;
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100545
546 /* Reset the BA RX indicators */
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100547 wl->ba_rx_bitmap = 0;
548
549 /* validate that FW support BA */
550 wl1271_check_ba_support(wl);
551
552 if (wl->ba_support)
553 /* 802.11n initiator BA session setting */
554 for (tid_index = 0; tid_index < CONF_TX_MAX_TID_COUNT;
555 ++tid_index) {
556 ret = wl1271_acx_set_ba_session(wl, WLAN_BACK_INITIATOR,
557 tid_index, true);
558 if (ret < 0)
559 break;
560 }
561
562 return ret;
563}
564
Shahar Levi48a61472011-03-06 16:32:08 +0200565int wl1271_chip_specific_init(struct wl1271 *wl)
566{
567 int ret = 0;
568
569 if (wl->chip.id == CHIP_ID_1283_PG20) {
570 u32 host_cfg_bitmap = HOST_IF_CFG_RX_FIFO_ENABLE;
571
Ido Yariv0da13da2011-03-31 10:06:58 +0200572 if (wl->quirks & WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT)
Shahar Levi48a61472011-03-06 16:32:08 +0200573 /* Enable SDIO padding */
574 host_cfg_bitmap |= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK;
575
576 /* Must be before wl1271_acx_init_mem_config() */
577 ret = wl1271_acx_host_if_cfg_bitmap(wl, host_cfg_bitmap);
578 if (ret < 0)
579 goto out;
580 }
581out:
582 return ret;
583}
584
585
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300586int wl1271_hw_init(struct wl1271 *wl)
587{
Kalle Valo243eeb52010-02-18 13:25:39 +0200588 struct conf_tx_ac_category *conf_ac;
Kalle Valof2054df2010-02-18 13:25:40 +0200589 struct conf_tx_tid *conf_tid;
Kalle Valo243eeb52010-02-18 13:25:39 +0200590 int ret, i;
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200591 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300592
Shahar Levi49d750ca2011-03-06 16:32:09 +0200593 if (wl->chip.id == CHIP_ID_1283_PG20)
594 ret = wl128x_cmd_general_parms(wl);
595 else
596 ret = wl1271_cmd_general_parms(wl);
Luciano Coelho4a904062009-11-23 23:22:18 +0200597 if (ret < 0)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300598 return ret;
599
Shahar Levi49d750ca2011-03-06 16:32:09 +0200600 if (wl->chip.id == CHIP_ID_1283_PG20)
601 ret = wl128x_cmd_radio_parms(wl);
602 else
603 ret = wl1271_cmd_radio_parms(wl);
Luciano Coelho4a904062009-11-23 23:22:18 +0200604 if (ret < 0)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300605 return ret;
606
Shahar Levi48a61472011-03-06 16:32:08 +0200607 /* Chip-specific init */
608 ret = wl1271_chip_specific_init(wl);
609 if (ret < 0)
610 return ret;
611
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200612 /* Mode specific init */
613 if (is_ap)
614 ret = wl1271_ap_hw_init(wl);
615 else
616 ret = wl1271_sta_hw_init(wl);
Juuso Oikarinen644a4862010-10-05 13:11:56 +0200617
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300618 if (ret < 0)
619 return ret;
620
Arik Nemtsov801f8702011-04-18 14:15:20 +0300621 /* Bluetooth WLAN coexistence */
622 ret = wl1271_init_pta(wl);
623 if (ret < 0)
624 return ret;
625
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300626 /* Default memory configuration */
627 ret = wl1271_acx_init_mem_config(wl);
628 if (ret < 0)
629 return ret;
630
631 /* RX config */
632 ret = wl1271_init_rx_config(wl,
Juuso Oikarineneb5b28d2009-10-13 12:47:45 +0300633 RX_CFG_PROMISCUOUS | RX_CFG_TSF,
634 RX_FILTER_OPTION_DEF);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300635 /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
636 RX_FILTER_OPTION_FILTER_ALL); */
637 if (ret < 0)
638 goto out_free_memmap;
639
640 /* PHY layer config */
641 ret = wl1271_init_phy_config(wl);
642 if (ret < 0)
643 goto out_free_memmap;
644
Luciano Coelho6e92b412009-12-11 15:40:50 +0200645 ret = wl1271_acx_dco_itrim_params(wl);
646 if (ret < 0)
647 goto out_free_memmap;
648
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300649 /* Configure TX patch complete interrupt behavior */
650 ret = wl1271_acx_tx_config_options(wl);
651 if (ret < 0)
652 goto out_free_memmap;
653
654 /* RX complete interrupt pacing */
655 ret = wl1271_acx_init_rx_interrupt(wl);
656 if (ret < 0)
657 goto out_free_memmap;
658
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300659 /* Energy detection */
660 ret = wl1271_init_energy_detection(wl);
661 if (ret < 0)
662 goto out_free_memmap;
663
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300664 /* Default fragmentation threshold */
Arik Nemtsov5f704d12011-04-18 14:15:21 +0300665 ret = wl1271_acx_frag_threshold(wl, wl->hw->wiphy->frag_threshold);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300666 if (ret < 0)
667 goto out_free_memmap;
668
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200669 /* Default TID/AC configuration */
670 BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
Kalle Valof2054df2010-02-18 13:25:40 +0200671 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200672 conf_ac = &wl->conf.tx.ac_conf[i];
673 ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
674 conf_ac->cw_max, conf_ac->aifsn,
675 conf_ac->tx_op_limit);
676 if (ret < 0)
677 goto out_free_memmap;
678
Kalle Valof2054df2010-02-18 13:25:40 +0200679 conf_tid = &wl->conf.tx.tid_conf[i];
680 ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id,
681 conf_tid->channel_type,
682 conf_tid->tsid,
683 conf_tid->ps_scheme,
684 conf_tid->ack_policy,
685 conf_tid->apsd_conf[0],
686 conf_tid->apsd_conf[1]);
687 if (ret < 0)
688 goto out_free_memmap;
689 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300690
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300691 /* Enable data path */
Luciano Coelho94210892009-12-11 15:40:55 +0200692 ret = wl1271_cmd_data_path(wl, 1);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300693 if (ret < 0)
694 goto out_free_memmap;
695
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300696 /* Configure HW encryption */
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200697 ret = wl1271_acx_feature_cfg(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300698 if (ret < 0)
699 goto out_free_memmap;
700
Juuso Oikarinen38ad2d82009-12-11 15:41:08 +0200701 /* configure PM */
702 ret = wl1271_acx_pm_config(wl);
703 if (ret < 0)
704 goto out_free_memmap;
705
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200706 /* Mode specific init - post mem init */
707 if (is_ap)
708 ret = wl1271_ap_hw_init_post_mem(wl);
709 else
710 ret = wl1271_sta_hw_init_post_mem(wl);
Juuso Oikarinenc1899552010-03-26 12:53:32 +0200711
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300712 if (ret < 0)
713 goto out_free_memmap;
714
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100715 /* Configure initiator BA sessions policies */
716 ret = wl1271_set_ba_policies(wl);
717 if (ret < 0)
718 goto out_free_memmap;
719
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300720 return 0;
721
722 out_free_memmap:
723 kfree(wl->target_mem_map);
Juuso Oikarinen34415232009-10-08 21:56:33 +0300724 wl->target_mem_map = NULL;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300725
726 return ret;
727}