blob: c00bdf8a3584707ecac0517538172bf98b1faae7 [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
Eliad Peller87fbcb02011-10-05 11:55:41 +0200125static int wl1271_ap_init_deauth_template(struct wl1271 *wl,
126 struct wl12xx_vif *wlvif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200127{
128 struct wl12xx_disconn_template *tmpl;
129 int ret;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300130 u32 rate;
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200131
132 tmpl = kzalloc(sizeof(*tmpl), GFP_KERNEL);
133 if (!tmpl) {
134 ret = -ENOMEM;
135 goto out;
136 }
137
138 tmpl->header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT |
139 IEEE80211_STYPE_DEAUTH);
140
Eliad Peller87fbcb02011-10-05 11:55:41 +0200141 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200142 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300143 tmpl, sizeof(*tmpl), 0, rate);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200144
145out:
146 kfree(tmpl);
147 return ret;
148}
149
Eliad Peller784f6942011-10-05 11:55:39 +0200150static int wl1271_ap_init_null_template(struct wl1271 *wl,
151 struct ieee80211_vif *vif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200152{
Eliad Peller87fbcb02011-10-05 11:55:41 +0200153 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200154 struct ieee80211_hdr_3addr *nullfunc;
155 int ret;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300156 u32 rate;
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200157
158 nullfunc = kzalloc(sizeof(*nullfunc), GFP_KERNEL);
159 if (!nullfunc) {
160 ret = -ENOMEM;
161 goto out;
162 }
163
164 nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
165 IEEE80211_STYPE_NULLFUNC |
166 IEEE80211_FCTL_FROMDS);
167
168 /* nullfunc->addr1 is filled by FW */
169
Eliad Peller784f6942011-10-05 11:55:39 +0200170 memcpy(nullfunc->addr2, vif->addr, ETH_ALEN);
171 memcpy(nullfunc->addr3, vif->addr, ETH_ALEN);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200172
Eliad Peller87fbcb02011-10-05 11:55:41 +0200173 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200174 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, nullfunc,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300175 sizeof(*nullfunc), 0, rate);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200176
177out:
178 kfree(nullfunc);
179 return ret;
180}
181
Eliad Peller784f6942011-10-05 11:55:39 +0200182static int wl1271_ap_init_qos_null_template(struct wl1271 *wl,
183 struct ieee80211_vif *vif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200184{
Eliad Peller87fbcb02011-10-05 11:55:41 +0200185 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200186 struct ieee80211_qos_hdr *qosnull;
187 int ret;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300188 u32 rate;
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200189
190 qosnull = kzalloc(sizeof(*qosnull), GFP_KERNEL);
191 if (!qosnull) {
192 ret = -ENOMEM;
193 goto out;
194 }
195
196 qosnull->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
197 IEEE80211_STYPE_QOS_NULLFUNC |
198 IEEE80211_FCTL_FROMDS);
199
200 /* qosnull->addr1 is filled by FW */
201
Eliad Peller784f6942011-10-05 11:55:39 +0200202 memcpy(qosnull->addr2, vif->addr, ETH_ALEN);
203 memcpy(qosnull->addr3, vif->addr, ETH_ALEN);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200204
Eliad Peller87fbcb02011-10-05 11:55:41 +0200205 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200206 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, qosnull,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300207 sizeof(*qosnull), 0, rate);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200208
209out:
210 kfree(qosnull);
211 return ret;
212}
213
Eliad Peller08c1d1c2011-08-14 13:17:04 +0300214static int wl12xx_init_rx_config(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300215{
216 int ret;
217
Juuso Oikarinen8793f9b2009-10-13 12:47:40 +0300218 ret = wl1271_acx_rx_msdu_life_time(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300219 if (ret < 0)
220 return ret;
221
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300222 return 0;
223}
224
Luciano Coelho12419cc2010-02-18 13:25:44 +0200225int wl1271_init_phy_config(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300226{
227 int ret;
228
229 ret = wl1271_acx_pd_threshold(wl);
230 if (ret < 0)
231 return ret;
232
Eliad Peller92c77c72011-10-05 11:55:40 +0200233 return 0;
234}
235
236static int wl12xx_init_phy_vif_config(struct wl1271 *wl)
237{
238 int ret;
239
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300240 ret = wl1271_acx_slot(wl, DEFAULT_SLOT_TIME);
241 if (ret < 0)
242 return ret;
243
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300244 ret = wl1271_acx_service_period_timeout(wl);
245 if (ret < 0)
246 return ret;
247
Arik Nemtsov5f704d12011-04-18 14:15:21 +0300248 ret = wl1271_acx_rts_threshold(wl, wl->hw->wiphy->rts_threshold);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300249 if (ret < 0)
250 return ret;
251
252 return 0;
253}
254
255static int wl1271_init_beacon_filter(struct wl1271 *wl)
256{
257 int ret;
258
Juuso Oikarinen19221672009-10-08 21:56:35 +0300259 /* disable beacon filtering at this stage */
260 ret = wl1271_acx_beacon_filter_opt(wl, false);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300261 if (ret < 0)
262 return ret;
263
264 ret = wl1271_acx_beacon_filter_table(wl);
265 if (ret < 0)
266 return ret;
267
268 return 0;
269}
270
Luciano Coelho12419cc2010-02-18 13:25:44 +0200271int wl1271_init_pta(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300272{
273 int ret;
274
Eliad Peller3be41122011-08-14 13:17:19 +0300275 ret = wl12xx_acx_sg_cfg(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300276 if (ret < 0)
277 return ret;
278
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +0200279 ret = wl1271_acx_sg_enable(wl, wl->sg_enabled);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300280 if (ret < 0)
281 return ret;
282
283 return 0;
284}
285
Luciano Coelho12419cc2010-02-18 13:25:44 +0200286int wl1271_init_energy_detection(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300287{
288 int ret;
289
290 ret = wl1271_acx_cca_threshold(wl);
291 if (ret < 0)
292 return ret;
293
294 return 0;
295}
296
297static int wl1271_init_beacon_broadcast(struct wl1271 *wl)
298{
299 int ret;
300
301 ret = wl1271_acx_bcn_dtim_options(wl);
302 if (ret < 0)
303 return ret;
304
305 return 0;
306}
307
Ido Yariv95dac04f2011-06-06 14:57:06 +0300308static int wl12xx_init_fwlog(struct wl1271 *wl)
309{
310 int ret;
311
312 if (wl->quirks & WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED)
313 return 0;
314
315 ret = wl12xx_cmd_config_fwlog(wl);
316 if (ret < 0)
317 return ret;
318
319 return 0;
320}
321
Eliad Peller92c77c72011-10-05 11:55:40 +0200322/* generic sta initialization (non vif-specific) */
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200323static int wl1271_sta_hw_init(struct wl1271 *wl)
324{
325 int ret;
326
Shahar Levi49d750ca2011-03-06 16:32:09 +0200327 if (wl->chip.id != CHIP_ID_1283_PG20) {
328 ret = wl1271_cmd_ext_radio_parms(wl);
329 if (ret < 0)
330 return ret;
331 }
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200332
Eliad Pellerc8bde242011-02-02 09:59:35 +0200333 /* PS config */
334 ret = wl1271_acx_config_ps(wl);
335 if (ret < 0)
336 return ret;
337
Shahar Leviff868432011-04-11 15:41:46 +0300338 /* FM WLAN coexistence */
339 ret = wl1271_acx_fm_coex(wl);
340 if (ret < 0)
341 return ret;
342
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200343 /* Configure for ELP power saving */
344 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
345 if (ret < 0)
346 return ret;
347
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200348 ret = wl1271_acx_sta_rate_policies(wl);
349 if (ret < 0)
350 return ret;
351
352 return 0;
353}
354
355static int wl1271_sta_hw_init_post_mem(struct wl1271 *wl)
356{
357 int ret, i;
358
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200359 /* disable all keep-alive templates */
360 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
361 ret = wl1271_acx_keep_alive_config(wl, i,
362 ACX_KEEP_ALIVE_TPL_INVALID);
363 if (ret < 0)
364 return ret;
365 }
366
367 /* disable the keep-alive feature */
368 ret = wl1271_acx_keep_alive_mode(wl, false);
369 if (ret < 0)
370 return ret;
371
372 return 0;
373}
374
Eliad Peller92c77c72011-10-05 11:55:40 +0200375/* generic ap initialization (non vif-specific) */
Eliad Peller87fbcb02011-10-05 11:55:41 +0200376static int wl1271_ap_hw_init(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200377{
Arik Nemtsov70f47422011-04-18 14:15:25 +0300378 int ret;
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200379
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200380 /* Configure for power always on */
381 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
382 if (ret < 0)
383 return ret;
384
Eliad Peller87fbcb02011-10-05 11:55:41 +0200385 ret = wl1271_init_ap_rates(wl, wlvif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200386 if (ret < 0)
387 return ret;
388
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200389 return 0;
390}
391
Eliad Peller784f6942011-10-05 11:55:39 +0200392int wl1271_ap_init_templates(struct wl1271 *wl, struct ieee80211_vif *vif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200393{
Eliad Peller87fbcb02011-10-05 11:55:41 +0200394 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200395 int ret;
396
Eliad Peller87fbcb02011-10-05 11:55:41 +0200397 ret = wl1271_ap_init_deauth_template(wl, wlvif);
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_null_template(wl, vif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200402 if (ret < 0)
403 return ret;
404
Eliad Peller784f6942011-10-05 11:55:39 +0200405 ret = wl1271_ap_init_qos_null_template(wl, vif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200406 if (ret < 0)
407 return ret;
408
Arik Nemtsov521a4a22011-04-18 14:15:22 +0300409 /*
410 * when operating as AP we want to receive external beacons for
411 * configuring ERP protection.
412 */
Eliad Pellerf42bd2c2011-08-14 13:17:13 +0300413 ret = wl1271_acx_beacon_filter_opt(wl, false);
Arik Nemtsov521a4a22011-04-18 14:15:22 +0300414 if (ret < 0)
415 return ret;
416
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200417 return 0;
418}
419
Eliad Peller784f6942011-10-05 11:55:39 +0200420static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl,
421 struct ieee80211_vif *vif)
Arik Nemtsovc45a85b2011-04-18 14:15:26 +0300422{
Eliad Peller784f6942011-10-05 11:55:39 +0200423 return wl1271_ap_init_templates(wl, vif);
Arik Nemtsovc45a85b2011-04-18 14:15:26 +0300424}
425
Eliad Peller87fbcb02011-10-05 11:55:41 +0200426int wl1271_init_ap_rates(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Arik Nemtsov70f47422011-04-18 14:15:25 +0300427{
428 int i, ret;
429 struct conf_tx_rate_class rc;
430 u32 supported_rates;
431
Eliad Peller87fbcb02011-10-05 11:55:41 +0200432 wl1271_debug(DEBUG_AP, "AP basic rate set: 0x%x",
433 wlvif->basic_rate_set);
Arik Nemtsov70f47422011-04-18 14:15:25 +0300434
Eliad Peller87fbcb02011-10-05 11:55:41 +0200435 if (wlvif->basic_rate_set == 0)
Arik Nemtsov70f47422011-04-18 14:15:25 +0300436 return -EINVAL;
437
Eliad Peller87fbcb02011-10-05 11:55:41 +0200438 rc.enabled_rates = wlvif->basic_rate_set;
Arik Nemtsov70f47422011-04-18 14:15:25 +0300439 rc.long_retry_limit = 10;
440 rc.short_retry_limit = 10;
441 rc.aflags = 0;
442 ret = wl1271_acx_ap_rate_policy(wl, &rc, ACX_TX_AP_MODE_MGMT_RATE);
443 if (ret < 0)
444 return ret;
445
446 /* use the min basic rate for AP broadcast/multicast */
Eliad Peller87fbcb02011-10-05 11:55:41 +0200447 rc.enabled_rates = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
Arik Nemtsov70f47422011-04-18 14:15:25 +0300448 rc.short_retry_limit = 10;
449 rc.long_retry_limit = 10;
450 rc.aflags = 0;
451 ret = wl1271_acx_ap_rate_policy(wl, &rc, ACX_TX_AP_MODE_BCST_RATE);
452 if (ret < 0)
453 return ret;
454
455 /*
456 * If the basic rates contain OFDM rates, use OFDM only
457 * rates for unicast TX as well. Else use all supported rates.
458 */
Eliad Peller87fbcb02011-10-05 11:55:41 +0200459 if ((wlvif->basic_rate_set & CONF_TX_OFDM_RATES))
Arik Nemtsov70f47422011-04-18 14:15:25 +0300460 supported_rates = CONF_TX_OFDM_RATES;
461 else
462 supported_rates = CONF_TX_AP_ENABLED_RATES;
463
Arik Nemtsov1a8adb62011-08-14 13:17:29 +0300464 /* unconditionally enable HT rates */
465 supported_rates |= CONF_TX_MCS_RATES;
466
Arik Nemtsov70f47422011-04-18 14:15:25 +0300467 /* configure unicast TX rate classes */
468 for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
469 rc.enabled_rates = supported_rates;
470 rc.short_retry_limit = 10;
471 rc.long_retry_limit = 10;
472 rc.aflags = 0;
473 ret = wl1271_acx_ap_rate_policy(wl, &rc, i);
474 if (ret < 0)
475 return ret;
476 }
477
478 return 0;
479}
480
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100481static int wl1271_set_ba_policies(struct wl1271 *wl)
482{
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100483 /* Reset the BA RX indicators */
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100484 wl->ba_rx_bitmap = 0;
Shahar Levi70559a02011-05-22 16:10:22 +0300485 wl->ba_allowed = true;
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300486 wl->ba_rx_session_count = 0;
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100487
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300488 /* BA is supported in STA/AP modes */
489 if (wl->bss_type != BSS_TYPE_AP_BSS &&
490 wl->bss_type != BSS_TYPE_STA_BSS) {
491 wl->ba_support = false;
492 return 0;
493 }
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100494
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300495 wl->ba_support = true;
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100496
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300497 /* 802.11n initiator BA session setting */
498 return wl12xx_acx_set_ba_initiator_policy(wl);
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100499}
500
Shahar Levi48a61472011-03-06 16:32:08 +0200501int wl1271_chip_specific_init(struct wl1271 *wl)
502{
503 int ret = 0;
504
505 if (wl->chip.id == CHIP_ID_1283_PG20) {
506 u32 host_cfg_bitmap = HOST_IF_CFG_RX_FIFO_ENABLE;
507
Ido Yariv0da13da2011-03-31 10:06:58 +0200508 if (wl->quirks & WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT)
Shahar Levi48a61472011-03-06 16:32:08 +0200509 /* Enable SDIO padding */
510 host_cfg_bitmap |= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK;
511
512 /* Must be before wl1271_acx_init_mem_config() */
513 ret = wl1271_acx_host_if_cfg_bitmap(wl, host_cfg_bitmap);
514 if (ret < 0)
515 goto out;
516 }
517out:
518 return ret;
519}
520
Eliad Peller92c77c72011-10-05 11:55:40 +0200521/* vif-specifc initialization */
522static int wl12xx_init_sta_role(struct wl1271 *wl, struct ieee80211_vif *vif)
523{
524 int ret;
Shahar Levi48a61472011-03-06 16:32:08 +0200525
Eliad Peller92c77c72011-10-05 11:55:40 +0200526 ret = wl1271_acx_group_address_tbl(wl, true, NULL, 0);
527 if (ret < 0)
528 return ret;
529
530 /* Initialize connection monitoring thresholds */
531 ret = wl1271_acx_conn_monit_params(wl, false);
532 if (ret < 0)
533 return ret;
534
535 /* Beacon filtering */
536 ret = wl1271_init_beacon_filter(wl);
537 if (ret < 0)
538 return ret;
539
540 /* Beacons and broadcast settings */
541 ret = wl1271_init_beacon_broadcast(wl);
542 if (ret < 0)
543 return ret;
544
545 /* Configure rssi/snr averaging weights */
546 ret = wl1271_acx_rssi_snr_avg_weights(wl);
547 if (ret < 0)
548 return ret;
549
550 return 0;
551}
552
553/* vif-specific intialization */
554static int wl12xx_init_ap_role(struct wl1271 *wl, struct ieee80211_vif *vif)
555{
556 int ret;
557
558 ret = wl1271_acx_ap_max_tx_retry(wl);
559 if (ret < 0)
560 return ret;
561
562 /* initialize Tx power */
563 ret = wl1271_acx_tx_power(wl, wl->power_level);
564 if (ret < 0)
565 return ret;
566
567 return 0;
568}
569
570int wl1271_init_vif_specific(struct wl1271 *wl, struct ieee80211_vif *vif)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300571{
Eliad Peller87fbcb02011-10-05 11:55:41 +0200572 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Kalle Valo243eeb52010-02-18 13:25:39 +0200573 struct conf_tx_ac_category *conf_ac;
Kalle Valof2054df2010-02-18 13:25:40 +0200574 struct conf_tx_tid *conf_tid;
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200575 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300576
Eliad Peller92c77c72011-10-05 11:55:40 +0200577 int ret, i;
578
579 /* Mode specific init */
580 if (is_ap) {
Eliad Peller87fbcb02011-10-05 11:55:41 +0200581 ret = wl1271_ap_hw_init(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200582 if (ret < 0)
583 return ret;
584
585 ret = wl12xx_init_ap_role(wl, vif);
586 if (ret < 0)
587 return ret;
588 } else {
589 ret = wl1271_sta_hw_init(wl);
590 if (ret < 0)
591 return ret;
592
593 ret = wl12xx_init_sta_role(wl, vif);
594 if (ret < 0)
595 return ret;
596 }
597
598 wl12xx_init_phy_vif_config(wl);
599
600 /* Default TID/AC configuration */
601 BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
602 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
603 conf_ac = &wl->conf.tx.ac_conf[i];
604 ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
605 conf_ac->cw_max, conf_ac->aifsn,
606 conf_ac->tx_op_limit);
607 if (ret < 0)
608 return ret;
609
610 conf_tid = &wl->conf.tx.tid_conf[i];
611 ret = wl1271_acx_tid_cfg(wl,
612 conf_tid->queue_id,
613 conf_tid->channel_type,
614 conf_tid->tsid,
615 conf_tid->ps_scheme,
616 conf_tid->ack_policy,
617 conf_tid->apsd_conf[0],
618 conf_tid->apsd_conf[1]);
619 if (ret < 0)
620 return ret;
621 }
622
623 /* Configure HW encryption */
624 ret = wl1271_acx_feature_cfg(wl);
625 if (ret < 0)
626 return ret;
627
628 /* Mode specific init - post mem init */
629 if (is_ap)
630 ret = wl1271_ap_hw_init_post_mem(wl, vif);
631 else
632 ret = wl1271_sta_hw_init_post_mem(wl);
633
634 if (ret < 0)
635 return ret;
636
637 /* Configure initiator BA sessions policies */
638 ret = wl1271_set_ba_policies(wl);
639 if (ret < 0)
640 return ret;
641
642 return 0;
643}
644
645int wl1271_hw_init(struct wl1271 *wl)
646{
647 int ret;
648
Shahar Levi49d750ca2011-03-06 16:32:09 +0200649 if (wl->chip.id == CHIP_ID_1283_PG20)
650 ret = wl128x_cmd_general_parms(wl);
651 else
652 ret = wl1271_cmd_general_parms(wl);
Luciano Coelho4a904062009-11-23 23:22:18 +0200653 if (ret < 0)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300654 return ret;
655
Shahar Levi49d750ca2011-03-06 16:32:09 +0200656 if (wl->chip.id == CHIP_ID_1283_PG20)
657 ret = wl128x_cmd_radio_parms(wl);
658 else
659 ret = wl1271_cmd_radio_parms(wl);
Luciano Coelho4a904062009-11-23 23:22:18 +0200660 if (ret < 0)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300661 return ret;
662
Shahar Levi48a61472011-03-06 16:32:08 +0200663 /* Chip-specific init */
664 ret = wl1271_chip_specific_init(wl);
665 if (ret < 0)
666 return ret;
667
Eliad Peller92c77c72011-10-05 11:55:40 +0200668 /* Init templates */
669 ret = wl1271_init_templates_config(wl);
670 if (ret < 0)
671 return ret;
Juuso Oikarinen644a4862010-10-05 13:11:56 +0200672
Eliad Peller92c77c72011-10-05 11:55:40 +0200673 ret = wl12xx_acx_mem_cfg(wl);
674 if (ret < 0)
675 return ret;
676
677 /* Configure the FW logger */
678 ret = wl12xx_init_fwlog(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300679 if (ret < 0)
680 return ret;
681
Arik Nemtsov801f8702011-04-18 14:15:20 +0300682 /* Bluetooth WLAN coexistence */
683 ret = wl1271_init_pta(wl);
684 if (ret < 0)
685 return ret;
686
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300687 /* Default memory configuration */
688 ret = wl1271_acx_init_mem_config(wl);
689 if (ret < 0)
690 return ret;
691
692 /* RX config */
Eliad Peller08c1d1c2011-08-14 13:17:04 +0300693 ret = wl12xx_init_rx_config(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300694 if (ret < 0)
695 goto out_free_memmap;
696
697 /* PHY layer config */
698 ret = wl1271_init_phy_config(wl);
699 if (ret < 0)
700 goto out_free_memmap;
701
Luciano Coelho6e92b412009-12-11 15:40:50 +0200702 ret = wl1271_acx_dco_itrim_params(wl);
703 if (ret < 0)
704 goto out_free_memmap;
705
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300706 /* Configure TX patch complete interrupt behavior */
707 ret = wl1271_acx_tx_config_options(wl);
708 if (ret < 0)
709 goto out_free_memmap;
710
711 /* RX complete interrupt pacing */
712 ret = wl1271_acx_init_rx_interrupt(wl);
713 if (ret < 0)
714 goto out_free_memmap;
715
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300716 /* Energy detection */
717 ret = wl1271_init_energy_detection(wl);
718 if (ret < 0)
719 goto out_free_memmap;
720
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300721 /* Default fragmentation threshold */
Arik Nemtsov5f704d12011-04-18 14:15:21 +0300722 ret = wl1271_acx_frag_threshold(wl, wl->hw->wiphy->frag_threshold);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300723 if (ret < 0)
724 goto out_free_memmap;
725
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300726 /* Enable data path */
Luciano Coelho94210892009-12-11 15:40:55 +0200727 ret = wl1271_cmd_data_path(wl, 1);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300728 if (ret < 0)
729 goto out_free_memmap;
730
Juuso Oikarinen38ad2d82009-12-11 15:41:08 +0200731 /* configure PM */
732 ret = wl1271_acx_pm_config(wl);
733 if (ret < 0)
734 goto out_free_memmap;
735
Eliad Pellerfa6ad9f2011-08-14 13:17:14 +0300736 ret = wl12xx_acx_set_rate_mgmt_params(wl);
737 if (ret < 0)
738 goto out_free_memmap;
739
Eliad Peller94877752011-08-28 15:11:56 +0300740 /* configure hangover */
741 ret = wl12xx_acx_config_hangover(wl);
742 if (ret < 0)
743 goto out_free_memmap;
744
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300745 return 0;
746
747 out_free_memmap:
748 kfree(wl->target_mem_map);
Juuso Oikarinen34415232009-10-08 21:56:33 +0300749 wl->target_mem_map = NULL;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300750
751 return ret;
752}