blob: 80e89e319879669113d77931aa9b12d67cc8f204 [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 Coelho12419cce2010-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
Eliad Peller0603d892011-10-05 11:55:51 +0200236static int wl12xx_init_phy_vif_config(struct wl1271 *wl,
237 struct wl12xx_vif *wlvif)
Eliad Peller92c77c72011-10-05 11:55:40 +0200238{
239 int ret;
240
Eliad Peller0603d892011-10-05 11:55:51 +0200241 ret = wl1271_acx_slot(wl, wlvif, DEFAULT_SLOT_TIME);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300242 if (ret < 0)
243 return ret;
244
Eliad Peller0603d892011-10-05 11:55:51 +0200245 ret = wl1271_acx_service_period_timeout(wl, wlvif);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300246 if (ret < 0)
247 return ret;
248
Eliad Peller0603d892011-10-05 11:55:51 +0200249 ret = wl1271_acx_rts_threshold(wl, wlvif, wl->hw->wiphy->rts_threshold);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300250 if (ret < 0)
251 return ret;
252
253 return 0;
254}
255
Eliad Peller0603d892011-10-05 11:55:51 +0200256static int wl1271_init_beacon_filter(struct wl1271 *wl,
257 struct wl12xx_vif *wlvif)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300258{
259 int ret;
260
Juuso Oikarinen19221672009-10-08 21:56:35 +0300261 /* disable beacon filtering at this stage */
Eliad Peller0603d892011-10-05 11:55:51 +0200262 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300263 if (ret < 0)
264 return ret;
265
Eliad Peller0603d892011-10-05 11:55:51 +0200266 ret = wl1271_acx_beacon_filter_table(wl, wlvif);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300267 if (ret < 0)
268 return ret;
269
270 return 0;
271}
272
Luciano Coelho12419cce2010-02-18 13:25:44 +0200273int wl1271_init_pta(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300274{
275 int ret;
276
Eliad Peller3be41122011-08-14 13:17:19 +0300277 ret = wl12xx_acx_sg_cfg(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300278 if (ret < 0)
279 return ret;
280
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +0200281 ret = wl1271_acx_sg_enable(wl, wl->sg_enabled);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300282 if (ret < 0)
283 return ret;
284
285 return 0;
286}
287
Luciano Coelho12419cce2010-02-18 13:25:44 +0200288int wl1271_init_energy_detection(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300289{
290 int ret;
291
292 ret = wl1271_acx_cca_threshold(wl);
293 if (ret < 0)
294 return ret;
295
296 return 0;
297}
298
Eliad Peller0603d892011-10-05 11:55:51 +0200299static int wl1271_init_beacon_broadcast(struct wl1271 *wl,
300 struct wl12xx_vif *wlvif)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300301{
302 int ret;
303
Eliad Peller0603d892011-10-05 11:55:51 +0200304 ret = wl1271_acx_bcn_dtim_options(wl, wlvif);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300305 if (ret < 0)
306 return ret;
307
308 return 0;
309}
310
Ido Yariv95dac04f2011-06-06 14:57:06 +0300311static int wl12xx_init_fwlog(struct wl1271 *wl)
312{
313 int ret;
314
315 if (wl->quirks & WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED)
316 return 0;
317
318 ret = wl12xx_cmd_config_fwlog(wl);
319 if (ret < 0)
320 return ret;
321
322 return 0;
323}
324
Eliad Peller92c77c72011-10-05 11:55:40 +0200325/* generic sta initialization (non vif-specific) */
Eliad Peller30d0c8f2011-10-05 11:55:42 +0200326static int wl1271_sta_hw_init(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200327{
328 int ret;
329
Shahar Levi49d750ca2011-03-06 16:32:09 +0200330 if (wl->chip.id != CHIP_ID_1283_PG20) {
331 ret = wl1271_cmd_ext_radio_parms(wl);
332 if (ret < 0)
333 return ret;
334 }
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200335
Eliad Pellerc8bde242011-02-02 09:59:35 +0200336 /* PS config */
Eliad Pellerd2d66c52011-10-05 11:55:43 +0200337 ret = wl12xx_acx_config_ps(wl, wlvif);
Eliad Pellerc8bde242011-02-02 09:59:35 +0200338 if (ret < 0)
339 return ret;
340
Shahar Leviff868432011-04-11 15:41:46 +0300341 /* FM WLAN coexistence */
342 ret = wl1271_acx_fm_coex(wl);
343 if (ret < 0)
344 return ret;
345
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200346 /* Configure for ELP power saving */
347 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
348 if (ret < 0)
349 return ret;
350
Eliad Peller30d0c8f2011-10-05 11:55:42 +0200351 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200352 if (ret < 0)
353 return ret;
354
355 return 0;
356}
357
Eliad Peller0603d892011-10-05 11:55:51 +0200358static int wl1271_sta_hw_init_post_mem(struct wl1271 *wl,
359 struct ieee80211_vif *vif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200360{
Eliad Peller0603d892011-10-05 11:55:51 +0200361 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200362 int ret, i;
363
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200364 /* disable all keep-alive templates */
365 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
Eliad Peller0603d892011-10-05 11:55:51 +0200366 ret = wl1271_acx_keep_alive_config(wl, wlvif, i,
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200367 ACX_KEEP_ALIVE_TPL_INVALID);
368 if (ret < 0)
369 return ret;
370 }
371
372 /* disable the keep-alive feature */
Eliad Peller0603d892011-10-05 11:55:51 +0200373 ret = wl1271_acx_keep_alive_mode(wl, wlvif, false);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200374 if (ret < 0)
375 return ret;
376
377 return 0;
378}
379
Eliad Peller92c77c72011-10-05 11:55:40 +0200380/* generic ap initialization (non vif-specific) */
Eliad Peller87fbcb02011-10-05 11:55:41 +0200381static int wl1271_ap_hw_init(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200382{
Arik Nemtsov70f47422011-04-18 14:15:25 +0300383 int ret;
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200384
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200385 /* Configure for power always on */
386 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
387 if (ret < 0)
388 return ret;
389
Eliad Peller87fbcb02011-10-05 11:55:41 +0200390 ret = wl1271_init_ap_rates(wl, wlvif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200391 if (ret < 0)
392 return ret;
393
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200394 return 0;
395}
396
Eliad Peller784f6942011-10-05 11:55:39 +0200397int wl1271_ap_init_templates(struct wl1271 *wl, struct ieee80211_vif *vif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200398{
Eliad Peller87fbcb02011-10-05 11:55:41 +0200399 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200400 int ret;
401
Eliad Peller87fbcb02011-10-05 11:55:41 +0200402 ret = wl1271_ap_init_deauth_template(wl, wlvif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200403 if (ret < 0)
404 return ret;
405
Eliad Peller784f6942011-10-05 11:55:39 +0200406 ret = wl1271_ap_init_null_template(wl, vif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200407 if (ret < 0)
408 return ret;
409
Eliad Peller784f6942011-10-05 11:55:39 +0200410 ret = wl1271_ap_init_qos_null_template(wl, vif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200411 if (ret < 0)
412 return ret;
413
Arik Nemtsov521a4a22011-04-18 14:15:22 +0300414 /*
415 * when operating as AP we want to receive external beacons for
416 * configuring ERP protection.
417 */
Eliad Peller0603d892011-10-05 11:55:51 +0200418 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false);
Arik Nemtsov521a4a22011-04-18 14:15:22 +0300419 if (ret < 0)
420 return ret;
421
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200422 return 0;
423}
424
Eliad Peller784f6942011-10-05 11:55:39 +0200425static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl,
426 struct ieee80211_vif *vif)
Arik Nemtsovc45a85b2011-04-18 14:15:26 +0300427{
Eliad Peller784f6942011-10-05 11:55:39 +0200428 return wl1271_ap_init_templates(wl, vif);
Arik Nemtsovc45a85b2011-04-18 14:15:26 +0300429}
430
Eliad Peller87fbcb02011-10-05 11:55:41 +0200431int wl1271_init_ap_rates(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Arik Nemtsov70f47422011-04-18 14:15:25 +0300432{
433 int i, ret;
434 struct conf_tx_rate_class rc;
435 u32 supported_rates;
436
Eliad Peller87fbcb02011-10-05 11:55:41 +0200437 wl1271_debug(DEBUG_AP, "AP basic rate set: 0x%x",
438 wlvif->basic_rate_set);
Arik Nemtsov70f47422011-04-18 14:15:25 +0300439
Eliad Peller87fbcb02011-10-05 11:55:41 +0200440 if (wlvif->basic_rate_set == 0)
Arik Nemtsov70f47422011-04-18 14:15:25 +0300441 return -EINVAL;
442
Eliad Peller87fbcb02011-10-05 11:55:41 +0200443 rc.enabled_rates = wlvif->basic_rate_set;
Arik Nemtsov70f47422011-04-18 14:15:25 +0300444 rc.long_retry_limit = 10;
445 rc.short_retry_limit = 10;
446 rc.aflags = 0;
447 ret = wl1271_acx_ap_rate_policy(wl, &rc, ACX_TX_AP_MODE_MGMT_RATE);
448 if (ret < 0)
449 return ret;
450
451 /* use the min basic rate for AP broadcast/multicast */
Eliad Peller87fbcb02011-10-05 11:55:41 +0200452 rc.enabled_rates = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
Arik Nemtsov70f47422011-04-18 14:15:25 +0300453 rc.short_retry_limit = 10;
454 rc.long_retry_limit = 10;
455 rc.aflags = 0;
456 ret = wl1271_acx_ap_rate_policy(wl, &rc, ACX_TX_AP_MODE_BCST_RATE);
457 if (ret < 0)
458 return ret;
459
460 /*
461 * If the basic rates contain OFDM rates, use OFDM only
462 * rates for unicast TX as well. Else use all supported rates.
463 */
Eliad Peller87fbcb02011-10-05 11:55:41 +0200464 if ((wlvif->basic_rate_set & CONF_TX_OFDM_RATES))
Arik Nemtsov70f47422011-04-18 14:15:25 +0300465 supported_rates = CONF_TX_OFDM_RATES;
466 else
467 supported_rates = CONF_TX_AP_ENABLED_RATES;
468
Arik Nemtsov1a8adb62011-08-14 13:17:29 +0300469 /* unconditionally enable HT rates */
470 supported_rates |= CONF_TX_MCS_RATES;
471
Arik Nemtsov70f47422011-04-18 14:15:25 +0300472 /* configure unicast TX rate classes */
473 for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
474 rc.enabled_rates = supported_rates;
475 rc.short_retry_limit = 10;
476 rc.long_retry_limit = 10;
477 rc.aflags = 0;
478 ret = wl1271_acx_ap_rate_policy(wl, &rc, i);
479 if (ret < 0)
480 return ret;
481 }
482
483 return 0;
484}
485
Eliad Peller536129c2011-10-05 11:55:45 +0200486static int wl1271_set_ba_policies(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100487{
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100488 /* Reset the BA RX indicators */
Eliad Pellerd0802ab2011-10-05 11:56:04 +0200489 wlvif->ba_allowed = true;
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300490 wl->ba_rx_session_count = 0;
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100491
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300492 /* BA is supported in STA/AP modes */
Eliad Peller536129c2011-10-05 11:55:45 +0200493 if (wlvif->bss_type != BSS_TYPE_AP_BSS &&
494 wlvif->bss_type != BSS_TYPE_STA_BSS) {
Eliad Pellerd0802ab2011-10-05 11:56:04 +0200495 wlvif->ba_support = false;
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300496 return 0;
497 }
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100498
Eliad Pellerd0802ab2011-10-05 11:56:04 +0200499 wlvif->ba_support = true;
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100500
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300501 /* 802.11n initiator BA session setting */
Eliad Peller0603d892011-10-05 11:55:51 +0200502 return wl12xx_acx_set_ba_initiator_policy(wl, wlvif);
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100503}
504
Shahar Levi48a61472011-03-06 16:32:08 +0200505int wl1271_chip_specific_init(struct wl1271 *wl)
506{
507 int ret = 0;
508
509 if (wl->chip.id == CHIP_ID_1283_PG20) {
510 u32 host_cfg_bitmap = HOST_IF_CFG_RX_FIFO_ENABLE;
511
Ido Yariv0da13da2011-03-31 10:06:58 +0200512 if (wl->quirks & WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT)
Shahar Levi48a61472011-03-06 16:32:08 +0200513 /* Enable SDIO padding */
514 host_cfg_bitmap |= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK;
515
516 /* Must be before wl1271_acx_init_mem_config() */
517 ret = wl1271_acx_host_if_cfg_bitmap(wl, host_cfg_bitmap);
518 if (ret < 0)
519 goto out;
520 }
521out:
522 return ret;
523}
524
Eliad Peller92c77c72011-10-05 11:55:40 +0200525/* vif-specifc initialization */
Eliad Peller0603d892011-10-05 11:55:51 +0200526static int wl12xx_init_sta_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Eliad Peller92c77c72011-10-05 11:55:40 +0200527{
528 int ret;
Shahar Levi48a61472011-03-06 16:32:08 +0200529
Eliad Peller0603d892011-10-05 11:55:51 +0200530 ret = wl1271_acx_group_address_tbl(wl, wlvif, true, NULL, 0);
Eliad Peller92c77c72011-10-05 11:55:40 +0200531 if (ret < 0)
532 return ret;
533
534 /* Initialize connection monitoring thresholds */
Eliad Peller0603d892011-10-05 11:55:51 +0200535 ret = wl1271_acx_conn_monit_params(wl, wlvif, false);
Eliad Peller92c77c72011-10-05 11:55:40 +0200536 if (ret < 0)
537 return ret;
538
539 /* Beacon filtering */
Eliad Peller0603d892011-10-05 11:55:51 +0200540 ret = wl1271_init_beacon_filter(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200541 if (ret < 0)
542 return ret;
543
544 /* Beacons and broadcast settings */
Eliad Peller0603d892011-10-05 11:55:51 +0200545 ret = wl1271_init_beacon_broadcast(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200546 if (ret < 0)
547 return ret;
548
549 /* Configure rssi/snr averaging weights */
Eliad Peller0603d892011-10-05 11:55:51 +0200550 ret = wl1271_acx_rssi_snr_avg_weights(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200551 if (ret < 0)
552 return ret;
553
554 return 0;
555}
556
557/* vif-specific intialization */
Eliad Peller0603d892011-10-05 11:55:51 +0200558static int wl12xx_init_ap_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Eliad Peller92c77c72011-10-05 11:55:40 +0200559{
560 int ret;
561
Eliad Peller0603d892011-10-05 11:55:51 +0200562 ret = wl1271_acx_ap_max_tx_retry(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200563 if (ret < 0)
564 return ret;
565
566 /* initialize Tx power */
Eliad Peller0603d892011-10-05 11:55:51 +0200567 ret = wl1271_acx_tx_power(wl, wlvif, wl->power_level);
Eliad Peller92c77c72011-10-05 11:55:40 +0200568 if (ret < 0)
569 return ret;
570
571 return 0;
572}
573
574int wl1271_init_vif_specific(struct wl1271 *wl, struct ieee80211_vif *vif)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300575{
Eliad Peller87fbcb02011-10-05 11:55:41 +0200576 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Kalle Valo243eeb52010-02-18 13:25:39 +0200577 struct conf_tx_ac_category *conf_ac;
Kalle Valof2054df2010-02-18 13:25:40 +0200578 struct conf_tx_tid *conf_tid;
Eliad Peller536129c2011-10-05 11:55:45 +0200579 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300580
Eliad Peller92c77c72011-10-05 11:55:40 +0200581 int ret, i;
582
583 /* Mode specific init */
584 if (is_ap) {
Eliad Peller87fbcb02011-10-05 11:55:41 +0200585 ret = wl1271_ap_hw_init(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200586 if (ret < 0)
587 return ret;
588
Eliad Peller0603d892011-10-05 11:55:51 +0200589 ret = wl12xx_init_ap_role(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200590 if (ret < 0)
591 return ret;
592 } else {
Eliad Peller30d0c8f2011-10-05 11:55:42 +0200593 ret = wl1271_sta_hw_init(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200594 if (ret < 0)
595 return ret;
596
Eliad Peller0603d892011-10-05 11:55:51 +0200597 ret = wl12xx_init_sta_role(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200598 if (ret < 0)
599 return ret;
600 }
601
Eliad Peller0603d892011-10-05 11:55:51 +0200602 wl12xx_init_phy_vif_config(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200603
604 /* Default TID/AC configuration */
605 BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
606 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
607 conf_ac = &wl->conf.tx.ac_conf[i];
Eliad Peller0603d892011-10-05 11:55:51 +0200608 ret = wl1271_acx_ac_cfg(wl, wlvif, conf_ac->ac,
609 conf_ac->cw_min, conf_ac->cw_max,
610 conf_ac->aifsn, conf_ac->tx_op_limit);
Eliad Peller92c77c72011-10-05 11:55:40 +0200611 if (ret < 0)
612 return ret;
613
614 conf_tid = &wl->conf.tx.tid_conf[i];
Eliad Peller0603d892011-10-05 11:55:51 +0200615 ret = wl1271_acx_tid_cfg(wl, wlvif,
Eliad Peller92c77c72011-10-05 11:55:40 +0200616 conf_tid->queue_id,
617 conf_tid->channel_type,
618 conf_tid->tsid,
619 conf_tid->ps_scheme,
620 conf_tid->ack_policy,
621 conf_tid->apsd_conf[0],
622 conf_tid->apsd_conf[1]);
623 if (ret < 0)
624 return ret;
625 }
626
627 /* Configure HW encryption */
Eliad Peller0603d892011-10-05 11:55:51 +0200628 ret = wl1271_acx_feature_cfg(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200629 if (ret < 0)
630 return ret;
631
632 /* Mode specific init - post mem init */
633 if (is_ap)
634 ret = wl1271_ap_hw_init_post_mem(wl, vif);
635 else
Eliad Peller0603d892011-10-05 11:55:51 +0200636 ret = wl1271_sta_hw_init_post_mem(wl, vif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200637
638 if (ret < 0)
639 return ret;
640
641 /* Configure initiator BA sessions policies */
Eliad Peller536129c2011-10-05 11:55:45 +0200642 ret = wl1271_set_ba_policies(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200643 if (ret < 0)
644 return ret;
645
646 return 0;
647}
648
649int wl1271_hw_init(struct wl1271 *wl)
650{
651 int ret;
652
Shahar Levi49d750ca2011-03-06 16:32:09 +0200653 if (wl->chip.id == CHIP_ID_1283_PG20)
654 ret = wl128x_cmd_general_parms(wl);
655 else
656 ret = wl1271_cmd_general_parms(wl);
Luciano Coelho4a904062009-11-23 23:22:18 +0200657 if (ret < 0)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300658 return ret;
659
Shahar Levi49d750ca2011-03-06 16:32:09 +0200660 if (wl->chip.id == CHIP_ID_1283_PG20)
661 ret = wl128x_cmd_radio_parms(wl);
662 else
663 ret = wl1271_cmd_radio_parms(wl);
Luciano Coelho4a904062009-11-23 23:22:18 +0200664 if (ret < 0)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300665 return ret;
666
Shahar Levi48a61472011-03-06 16:32:08 +0200667 /* Chip-specific init */
668 ret = wl1271_chip_specific_init(wl);
669 if (ret < 0)
670 return ret;
671
Eliad Peller92c77c72011-10-05 11:55:40 +0200672 /* Init templates */
673 ret = wl1271_init_templates_config(wl);
674 if (ret < 0)
675 return ret;
Juuso Oikarinen644a4862010-10-05 13:11:56 +0200676
Eliad Peller92c77c72011-10-05 11:55:40 +0200677 ret = wl12xx_acx_mem_cfg(wl);
678 if (ret < 0)
679 return ret;
680
681 /* Configure the FW logger */
682 ret = wl12xx_init_fwlog(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300683 if (ret < 0)
684 return ret;
685
Arik Nemtsov801f8702011-04-18 14:15:20 +0300686 /* Bluetooth WLAN coexistence */
687 ret = wl1271_init_pta(wl);
688 if (ret < 0)
689 return ret;
690
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300691 /* Default memory configuration */
692 ret = wl1271_acx_init_mem_config(wl);
693 if (ret < 0)
694 return ret;
695
696 /* RX config */
Eliad Peller08c1d1c2011-08-14 13:17:04 +0300697 ret = wl12xx_init_rx_config(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300698 if (ret < 0)
699 goto out_free_memmap;
700
701 /* PHY layer config */
702 ret = wl1271_init_phy_config(wl);
703 if (ret < 0)
704 goto out_free_memmap;
705
Luciano Coelho6e92b412009-12-11 15:40:50 +0200706 ret = wl1271_acx_dco_itrim_params(wl);
707 if (ret < 0)
708 goto out_free_memmap;
709
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300710 /* Configure TX patch complete interrupt behavior */
711 ret = wl1271_acx_tx_config_options(wl);
712 if (ret < 0)
713 goto out_free_memmap;
714
715 /* RX complete interrupt pacing */
716 ret = wl1271_acx_init_rx_interrupt(wl);
717 if (ret < 0)
718 goto out_free_memmap;
719
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300720 /* Energy detection */
721 ret = wl1271_init_energy_detection(wl);
722 if (ret < 0)
723 goto out_free_memmap;
724
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300725 /* Default fragmentation threshold */
Arik Nemtsov5f704d12011-04-18 14:15:21 +0300726 ret = wl1271_acx_frag_threshold(wl, wl->hw->wiphy->frag_threshold);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300727 if (ret < 0)
728 goto out_free_memmap;
729
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300730 /* Enable data path */
Luciano Coelho94210892009-12-11 15:40:55 +0200731 ret = wl1271_cmd_data_path(wl, 1);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300732 if (ret < 0)
733 goto out_free_memmap;
734
Juuso Oikarinen38ad2d82009-12-11 15:41:08 +0200735 /* configure PM */
736 ret = wl1271_acx_pm_config(wl);
737 if (ret < 0)
738 goto out_free_memmap;
739
Eliad Pellerfa6ad9f2011-08-14 13:17:14 +0300740 ret = wl12xx_acx_set_rate_mgmt_params(wl);
741 if (ret < 0)
742 goto out_free_memmap;
743
Eliad Peller94877752011-08-28 15:11:56 +0300744 /* configure hangover */
745 ret = wl12xx_acx_config_hangover(wl);
746 if (ret < 0)
747 goto out_free_memmap;
748
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300749 return 0;
750
751 out_free_memmap:
752 kfree(wl->target_mem_map);
Juuso Oikarinen34415232009-10-08 21:56:33 +0300753 wl->target_mem_map = NULL;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300754
755 return ret;
756}