blob: 4af7e2fb52fd5d406ae7c689e26431899f0e10dd [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
Eliad Peller30d0c8f2011-10-05 11:55:42 +0200346 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200347 if (ret < 0)
348 return ret;
349
350 return 0;
351}
352
Eliad Peller0603d892011-10-05 11:55:51 +0200353static int wl1271_sta_hw_init_post_mem(struct wl1271 *wl,
354 struct ieee80211_vif *vif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200355{
Eliad Peller0603d892011-10-05 11:55:51 +0200356 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200357 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++) {
Eliad Peller0603d892011-10-05 11:55:51 +0200361 ret = wl1271_acx_keep_alive_config(wl, wlvif, i,
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200362 ACX_KEEP_ALIVE_TPL_INVALID);
363 if (ret < 0)
364 return ret;
365 }
366
367 /* disable the keep-alive feature */
Eliad Peller0603d892011-10-05 11:55:51 +0200368 ret = wl1271_acx_keep_alive_mode(wl, wlvif, false);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200369 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
Eliad Peller87fbcb02011-10-05 11:55:41 +0200380 ret = wl1271_init_ap_rates(wl, wlvif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200381 if (ret < 0)
382 return ret;
383
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200384 return 0;
385}
386
Eliad Peller784f6942011-10-05 11:55:39 +0200387int wl1271_ap_init_templates(struct wl1271 *wl, struct ieee80211_vif *vif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200388{
Eliad Peller87fbcb02011-10-05 11:55:41 +0200389 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200390 int ret;
391
Eliad Peller87fbcb02011-10-05 11:55:41 +0200392 ret = wl1271_ap_init_deauth_template(wl, wlvif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200393 if (ret < 0)
394 return ret;
395
Eliad Peller784f6942011-10-05 11:55:39 +0200396 ret = wl1271_ap_init_null_template(wl, vif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200397 if (ret < 0)
398 return ret;
399
Eliad Peller784f6942011-10-05 11:55:39 +0200400 ret = wl1271_ap_init_qos_null_template(wl, vif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200401 if (ret < 0)
402 return ret;
403
Arik Nemtsov521a4a22011-04-18 14:15:22 +0300404 /*
405 * when operating as AP we want to receive external beacons for
406 * configuring ERP protection.
407 */
Eliad Peller0603d892011-10-05 11:55:51 +0200408 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false);
Arik Nemtsov521a4a22011-04-18 14:15:22 +0300409 if (ret < 0)
410 return ret;
411
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200412 return 0;
413}
414
Eliad Peller784f6942011-10-05 11:55:39 +0200415static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl,
416 struct ieee80211_vif *vif)
Arik Nemtsovc45a85b2011-04-18 14:15:26 +0300417{
Eliad Peller784f6942011-10-05 11:55:39 +0200418 return wl1271_ap_init_templates(wl, vif);
Arik Nemtsovc45a85b2011-04-18 14:15:26 +0300419}
420
Eliad Peller87fbcb02011-10-05 11:55:41 +0200421int wl1271_init_ap_rates(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Arik Nemtsov70f47422011-04-18 14:15:25 +0300422{
423 int i, ret;
424 struct conf_tx_rate_class rc;
425 u32 supported_rates;
426
Eliad Peller87fbcb02011-10-05 11:55:41 +0200427 wl1271_debug(DEBUG_AP, "AP basic rate set: 0x%x",
428 wlvif->basic_rate_set);
Arik Nemtsov70f47422011-04-18 14:15:25 +0300429
Eliad Peller87fbcb02011-10-05 11:55:41 +0200430 if (wlvif->basic_rate_set == 0)
Arik Nemtsov70f47422011-04-18 14:15:25 +0300431 return -EINVAL;
432
Eliad Peller87fbcb02011-10-05 11:55:41 +0200433 rc.enabled_rates = wlvif->basic_rate_set;
Arik Nemtsov70f47422011-04-18 14:15:25 +0300434 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 Peller87fbcb02011-10-05 11:55:41 +0200442 rc.enabled_rates = wl1271_tx_min_rate_get(wl, wlvif->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 */
Eliad Peller87fbcb02011-10-05 11:55:41 +0200454 if ((wlvif->basic_rate_set & CONF_TX_OFDM_RATES))
Arik Nemtsov70f47422011-04-18 14:15:25 +0300455 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
Eliad Peller536129c2011-10-05 11:55:45 +0200476static int wl1271_set_ba_policies(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100477{
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100478 /* Reset the BA RX indicators */
Eliad Pellerd0802ab2011-10-05 11:56:04 +0200479 wlvif->ba_allowed = true;
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300480 wl->ba_rx_session_count = 0;
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100481
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300482 /* BA is supported in STA/AP modes */
Eliad Peller536129c2011-10-05 11:55:45 +0200483 if (wlvif->bss_type != BSS_TYPE_AP_BSS &&
484 wlvif->bss_type != BSS_TYPE_STA_BSS) {
Eliad Pellerd0802ab2011-10-05 11:56:04 +0200485 wlvif->ba_support = false;
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300486 return 0;
487 }
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100488
Eliad Pellerd0802ab2011-10-05 11:56:04 +0200489 wlvif->ba_support = true;
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100490
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300491 /* 802.11n initiator BA session setting */
Eliad Peller0603d892011-10-05 11:55:51 +0200492 return wl12xx_acx_set_ba_initiator_policy(wl, wlvif);
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100493}
494
Shahar Levi48a61472011-03-06 16:32:08 +0200495int wl1271_chip_specific_init(struct wl1271 *wl)
496{
497 int ret = 0;
498
499 if (wl->chip.id == CHIP_ID_1283_PG20) {
500 u32 host_cfg_bitmap = HOST_IF_CFG_RX_FIFO_ENABLE;
501
Ido Yariv0da13da2011-03-31 10:06:58 +0200502 if (wl->quirks & WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT)
Shahar Levi48a61472011-03-06 16:32:08 +0200503 /* Enable SDIO padding */
504 host_cfg_bitmap |= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK;
505
506 /* Must be before wl1271_acx_init_mem_config() */
507 ret = wl1271_acx_host_if_cfg_bitmap(wl, host_cfg_bitmap);
508 if (ret < 0)
509 goto out;
510 }
511out:
512 return ret;
513}
514
Eliad Peller92c77c72011-10-05 11:55:40 +0200515/* vif-specifc initialization */
Eliad Peller0603d892011-10-05 11:55:51 +0200516static int wl12xx_init_sta_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Eliad Peller92c77c72011-10-05 11:55:40 +0200517{
518 int ret;
Shahar Levi48a61472011-03-06 16:32:08 +0200519
Eliad Peller0603d892011-10-05 11:55:51 +0200520 ret = wl1271_acx_group_address_tbl(wl, wlvif, true, NULL, 0);
Eliad Peller92c77c72011-10-05 11:55:40 +0200521 if (ret < 0)
522 return ret;
523
524 /* Initialize connection monitoring thresholds */
Eliad Peller0603d892011-10-05 11:55:51 +0200525 ret = wl1271_acx_conn_monit_params(wl, wlvif, false);
Eliad Peller92c77c72011-10-05 11:55:40 +0200526 if (ret < 0)
527 return ret;
528
529 /* Beacon filtering */
Eliad Peller0603d892011-10-05 11:55:51 +0200530 ret = wl1271_init_beacon_filter(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200531 if (ret < 0)
532 return ret;
533
534 /* Beacons and broadcast settings */
Eliad Peller0603d892011-10-05 11:55:51 +0200535 ret = wl1271_init_beacon_broadcast(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200536 if (ret < 0)
537 return ret;
538
539 /* Configure rssi/snr averaging weights */
Eliad Peller0603d892011-10-05 11:55:51 +0200540 ret = wl1271_acx_rssi_snr_avg_weights(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200541 if (ret < 0)
542 return ret;
543
544 return 0;
545}
546
547/* vif-specific intialization */
Eliad Peller0603d892011-10-05 11:55:51 +0200548static int wl12xx_init_ap_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Eliad Peller92c77c72011-10-05 11:55:40 +0200549{
550 int ret;
551
Eliad Peller0603d892011-10-05 11:55:51 +0200552 ret = wl1271_acx_ap_max_tx_retry(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200553 if (ret < 0)
554 return ret;
555
556 /* initialize Tx power */
Eliad Peller0603d892011-10-05 11:55:51 +0200557 ret = wl1271_acx_tx_power(wl, wlvif, wl->power_level);
Eliad Peller92c77c72011-10-05 11:55:40 +0200558 if (ret < 0)
559 return ret;
560
561 return 0;
562}
563
564int wl1271_init_vif_specific(struct wl1271 *wl, struct ieee80211_vif *vif)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300565{
Eliad Peller87fbcb02011-10-05 11:55:41 +0200566 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
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;
Eliad Peller536129c2011-10-05 11:55:45 +0200569 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
Eliad Peller92c77c72011-10-05 11:55:40 +0200570 int ret, i;
571
Eliad Pellera4e41302011-10-11 11:49:15 +0200572 /*
573 * consider all existing roles before configuring psm.
574 * TODO: reconfigure on interface removal.
575 */
576 if (!wl->ap_count) {
577 if (is_ap) {
578 /* Configure for power always on */
579 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
580 if (ret < 0)
581 return ret;
582 } else if (!wl->sta_count) {
583 /* Configure for ELP power saving */
584 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
585 if (ret < 0)
586 return ret;
587 }
588 }
589
Eliad Peller92c77c72011-10-05 11:55:40 +0200590 /* Mode specific init */
591 if (is_ap) {
Eliad Peller87fbcb02011-10-05 11:55:41 +0200592 ret = wl1271_ap_hw_init(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200593 if (ret < 0)
594 return ret;
595
Eliad Peller0603d892011-10-05 11:55:51 +0200596 ret = wl12xx_init_ap_role(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200597 if (ret < 0)
598 return ret;
599 } else {
Eliad Peller30d0c8f2011-10-05 11:55:42 +0200600 ret = wl1271_sta_hw_init(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200601 if (ret < 0)
602 return ret;
603
Eliad Peller0603d892011-10-05 11:55:51 +0200604 ret = wl12xx_init_sta_role(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200605 if (ret < 0)
606 return ret;
607 }
608
Eliad Peller0603d892011-10-05 11:55:51 +0200609 wl12xx_init_phy_vif_config(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200610
611 /* Default TID/AC configuration */
612 BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
613 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
614 conf_ac = &wl->conf.tx.ac_conf[i];
Eliad Peller0603d892011-10-05 11:55:51 +0200615 ret = wl1271_acx_ac_cfg(wl, wlvif, conf_ac->ac,
616 conf_ac->cw_min, conf_ac->cw_max,
617 conf_ac->aifsn, conf_ac->tx_op_limit);
Eliad Peller92c77c72011-10-05 11:55:40 +0200618 if (ret < 0)
619 return ret;
620
621 conf_tid = &wl->conf.tx.tid_conf[i];
Eliad Peller0603d892011-10-05 11:55:51 +0200622 ret = wl1271_acx_tid_cfg(wl, wlvif,
Eliad Peller92c77c72011-10-05 11:55:40 +0200623 conf_tid->queue_id,
624 conf_tid->channel_type,
625 conf_tid->tsid,
626 conf_tid->ps_scheme,
627 conf_tid->ack_policy,
628 conf_tid->apsd_conf[0],
629 conf_tid->apsd_conf[1]);
630 if (ret < 0)
631 return ret;
632 }
633
634 /* Configure HW encryption */
Eliad Peller0603d892011-10-05 11:55:51 +0200635 ret = wl1271_acx_feature_cfg(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200636 if (ret < 0)
637 return ret;
638
639 /* Mode specific init - post mem init */
640 if (is_ap)
641 ret = wl1271_ap_hw_init_post_mem(wl, vif);
642 else
Eliad Peller0603d892011-10-05 11:55:51 +0200643 ret = wl1271_sta_hw_init_post_mem(wl, vif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200644
645 if (ret < 0)
646 return ret;
647
648 /* Configure initiator BA sessions policies */
Eliad Peller536129c2011-10-05 11:55:45 +0200649 ret = wl1271_set_ba_policies(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200650 if (ret < 0)
651 return ret;
652
653 return 0;
654}
655
656int wl1271_hw_init(struct wl1271 *wl)
657{
658 int ret;
659
Shahar Levi49d750ca2011-03-06 16:32:09 +0200660 if (wl->chip.id == CHIP_ID_1283_PG20)
661 ret = wl128x_cmd_general_parms(wl);
662 else
663 ret = wl1271_cmd_general_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 Levi49d750ca2011-03-06 16:32:09 +0200667 if (wl->chip.id == CHIP_ID_1283_PG20)
668 ret = wl128x_cmd_radio_parms(wl);
669 else
670 ret = wl1271_cmd_radio_parms(wl);
Luciano Coelho4a904062009-11-23 23:22:18 +0200671 if (ret < 0)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300672 return ret;
673
Shahar Levi48a61472011-03-06 16:32:08 +0200674 /* Chip-specific init */
675 ret = wl1271_chip_specific_init(wl);
676 if (ret < 0)
677 return ret;
678
Eliad Peller92c77c72011-10-05 11:55:40 +0200679 /* Init templates */
680 ret = wl1271_init_templates_config(wl);
681 if (ret < 0)
682 return ret;
Juuso Oikarinen644a4862010-10-05 13:11:56 +0200683
Eliad Peller92c77c72011-10-05 11:55:40 +0200684 ret = wl12xx_acx_mem_cfg(wl);
685 if (ret < 0)
686 return ret;
687
688 /* Configure the FW logger */
689 ret = wl12xx_init_fwlog(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300690 if (ret < 0)
691 return ret;
692
Arik Nemtsov801f8702011-04-18 14:15:20 +0300693 /* Bluetooth WLAN coexistence */
694 ret = wl1271_init_pta(wl);
695 if (ret < 0)
696 return ret;
697
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300698 /* Default memory configuration */
699 ret = wl1271_acx_init_mem_config(wl);
700 if (ret < 0)
701 return ret;
702
703 /* RX config */
Eliad Peller08c1d1c2011-08-14 13:17:04 +0300704 ret = wl12xx_init_rx_config(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300705 if (ret < 0)
706 goto out_free_memmap;
707
708 /* PHY layer config */
709 ret = wl1271_init_phy_config(wl);
710 if (ret < 0)
711 goto out_free_memmap;
712
Luciano Coelho6e92b412009-12-11 15:40:50 +0200713 ret = wl1271_acx_dco_itrim_params(wl);
714 if (ret < 0)
715 goto out_free_memmap;
716
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300717 /* Configure TX patch complete interrupt behavior */
718 ret = wl1271_acx_tx_config_options(wl);
719 if (ret < 0)
720 goto out_free_memmap;
721
722 /* RX complete interrupt pacing */
723 ret = wl1271_acx_init_rx_interrupt(wl);
724 if (ret < 0)
725 goto out_free_memmap;
726
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300727 /* Energy detection */
728 ret = wl1271_init_energy_detection(wl);
729 if (ret < 0)
730 goto out_free_memmap;
731
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300732 /* Default fragmentation threshold */
Arik Nemtsov5f704d12011-04-18 14:15:21 +0300733 ret = wl1271_acx_frag_threshold(wl, wl->hw->wiphy->frag_threshold);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300734 if (ret < 0)
735 goto out_free_memmap;
736
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300737 /* Enable data path */
Luciano Coelho94210892009-12-11 15:40:55 +0200738 ret = wl1271_cmd_data_path(wl, 1);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300739 if (ret < 0)
740 goto out_free_memmap;
741
Juuso Oikarinen38ad2d82009-12-11 15:41:08 +0200742 /* configure PM */
743 ret = wl1271_acx_pm_config(wl);
744 if (ret < 0)
745 goto out_free_memmap;
746
Eliad Pellerfa6ad9f2011-08-14 13:17:14 +0300747 ret = wl12xx_acx_set_rate_mgmt_params(wl);
748 if (ret < 0)
749 goto out_free_memmap;
750
Eliad Peller94877752011-08-28 15:11:56 +0300751 /* configure hangover */
752 ret = wl12xx_acx_config_hangover(wl);
753 if (ret < 0)
754 goto out_free_memmap;
755
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300756 return 0;
757
758 out_free_memmap:
759 kfree(wl->target_mem_map);
Juuso Oikarinen34415232009-10-08 21:56:33 +0300760 wl->target_mem_map = NULL;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300761
762 return ret;
763}