blob: 76625145e32eef4eaa22d80c8312474082ef7282 [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
Luciano Coelho0f4e3122011-10-07 11:02:42 +030028#include "debug.h"
Shahar Levi00d20102010-11-08 11:20:10 +000029#include "init.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030030#include "wl12xx_80211.h"
Shahar Levi00d20102010-11-08 11:20:10 +000031#include "acx.h"
32#include "cmd.h"
33#include "reg.h"
Arik Nemtsove0fe3712010-10-16 18:19:53 +020034#include "tx.h"
Shahar Levi48a61472011-03-06 16:32:08 +020035#include "io.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030036
Eliad Peller92c77c72011-10-05 11:55:40 +020037int wl1271_init_templates_config(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030038{
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +020039 int ret, i;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030040
41 /* send empty templates for fw memory reservation */
42 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, NULL,
Eliad Peller154037d2011-08-14 13:17:12 +030043 WL1271_CMD_TEMPL_DFLT_SIZE,
Juuso Oikarinen606c1482010-04-01 11:38:21 +030044 0, WL1271_RATE_AUTOMATIC);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030045 if (ret < 0)
46 return ret;
47
Juuso Oikarinen11eb5422010-08-24 06:28:03 +030048 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
Eliad Peller154037d2011-08-14 13:17:12 +030049 NULL, WL1271_CMD_TEMPL_DFLT_SIZE, 0,
Juuso Oikarinen11eb5422010-08-24 06:28:03 +030050 WL1271_RATE_AUTOMATIC);
51 if (ret < 0)
52 return ret;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +030053
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030054 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +020055 sizeof(struct wl12xx_null_data_template),
Juuso Oikarinen606c1482010-04-01 11:38:21 +030056 0, WL1271_RATE_AUTOMATIC);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030057 if (ret < 0)
58 return ret;
59
60 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, NULL,
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +020061 sizeof(struct wl12xx_ps_poll_template),
Juuso Oikarinen606c1482010-04-01 11:38:21 +030062 0, WL1271_RATE_AUTOMATIC);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030063 if (ret < 0)
64 return ret;
65
66 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
67 sizeof
Eliad Peller97127e62011-11-09 13:12:45 +020068 (struct ieee80211_qos_hdr),
Juuso Oikarinen606c1482010-04-01 11:38:21 +030069 0, WL1271_RATE_AUTOMATIC);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030070 if (ret < 0)
71 return ret;
72
73 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE, NULL,
Eliad Peller154037d2011-08-14 13:17:12 +030074 WL1271_CMD_TEMPL_DFLT_SIZE,
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,
Eliad Peller154037d2011-08-14 13:17:12 +030080 WL1271_CMD_TEMPL_DFLT_SIZE,
Juuso Oikarinen606c1482010-04-01 11:38:21 +030081 0, WL1271_RATE_AUTOMATIC);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030082 if (ret < 0)
83 return ret;
84
Eliad Pellerc5312772010-12-09 11:31:27 +020085 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_ARP_RSP, NULL,
86 sizeof
87 (struct wl12xx_arp_rsp_template),
88 0, WL1271_RATE_AUTOMATIC);
89 if (ret < 0)
90 return ret;
91
Eliad Peller92c77c72011-10-05 11:55:40 +020092 /*
93 * Put very large empty placeholders for all templates. These
94 * reserve memory for later.
95 */
96 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_PROBE_RESPONSE, NULL,
97 WL1271_CMD_TEMPL_MAX_SIZE,
98 0, WL1271_RATE_AUTOMATIC);
99 if (ret < 0)
100 return ret;
101
102 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_BEACON, NULL,
103 WL1271_CMD_TEMPL_MAX_SIZE,
104 0, WL1271_RATE_AUTOMATIC);
105 if (ret < 0)
106 return ret;
107
108 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP, NULL,
109 sizeof
110 (struct wl12xx_disconn_template),
111 0, WL1271_RATE_AUTOMATIC);
112 if (ret < 0)
113 return ret;
114
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200115 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
116 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV, NULL,
Eliad Peller97127e62011-11-09 13:12:45 +0200117 sizeof(struct ieee80211_qos_hdr),
118 i, WL1271_RATE_AUTOMATIC);
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200119 if (ret < 0)
120 return ret;
121 }
122
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300123 return 0;
124}
125
Eliad Peller87fbcb02011-10-05 11:55:41 +0200126static int wl1271_ap_init_deauth_template(struct wl1271 *wl,
127 struct wl12xx_vif *wlvif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200128{
129 struct wl12xx_disconn_template *tmpl;
130 int ret;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300131 u32 rate;
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200132
133 tmpl = kzalloc(sizeof(*tmpl), GFP_KERNEL);
134 if (!tmpl) {
135 ret = -ENOMEM;
136 goto out;
137 }
138
139 tmpl->header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT |
140 IEEE80211_STYPE_DEAUTH);
141
Eliad Peller87fbcb02011-10-05 11:55:41 +0200142 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200143 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300144 tmpl, sizeof(*tmpl), 0, rate);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200145
146out:
147 kfree(tmpl);
148 return ret;
149}
150
Eliad Peller784f6942011-10-05 11:55:39 +0200151static int wl1271_ap_init_null_template(struct wl1271 *wl,
152 struct ieee80211_vif *vif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200153{
Eliad Peller87fbcb02011-10-05 11:55:41 +0200154 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200155 struct ieee80211_hdr_3addr *nullfunc;
156 int ret;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300157 u32 rate;
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200158
159 nullfunc = kzalloc(sizeof(*nullfunc), GFP_KERNEL);
160 if (!nullfunc) {
161 ret = -ENOMEM;
162 goto out;
163 }
164
165 nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
166 IEEE80211_STYPE_NULLFUNC |
167 IEEE80211_FCTL_FROMDS);
168
169 /* nullfunc->addr1 is filled by FW */
170
Eliad Peller784f6942011-10-05 11:55:39 +0200171 memcpy(nullfunc->addr2, vif->addr, ETH_ALEN);
172 memcpy(nullfunc->addr3, vif->addr, ETH_ALEN);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200173
Eliad Peller87fbcb02011-10-05 11:55:41 +0200174 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200175 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, nullfunc,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300176 sizeof(*nullfunc), 0, rate);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200177
178out:
179 kfree(nullfunc);
180 return ret;
181}
182
Eliad Peller784f6942011-10-05 11:55:39 +0200183static int wl1271_ap_init_qos_null_template(struct wl1271 *wl,
184 struct ieee80211_vif *vif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200185{
Eliad Peller87fbcb02011-10-05 11:55:41 +0200186 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200187 struct ieee80211_qos_hdr *qosnull;
188 int ret;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300189 u32 rate;
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200190
191 qosnull = kzalloc(sizeof(*qosnull), GFP_KERNEL);
192 if (!qosnull) {
193 ret = -ENOMEM;
194 goto out;
195 }
196
197 qosnull->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
198 IEEE80211_STYPE_QOS_NULLFUNC |
199 IEEE80211_FCTL_FROMDS);
200
201 /* qosnull->addr1 is filled by FW */
202
Eliad Peller784f6942011-10-05 11:55:39 +0200203 memcpy(qosnull->addr2, vif->addr, ETH_ALEN);
204 memcpy(qosnull->addr3, vif->addr, ETH_ALEN);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200205
Eliad Peller87fbcb02011-10-05 11:55:41 +0200206 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200207 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, qosnull,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300208 sizeof(*qosnull), 0, rate);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200209
210out:
211 kfree(qosnull);
212 return ret;
213}
214
Eliad Peller08c1d1c2011-08-14 13:17:04 +0300215static int wl12xx_init_rx_config(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300216{
217 int ret;
218
Juuso Oikarinen8793f9b2009-10-13 12:47:40 +0300219 ret = wl1271_acx_rx_msdu_life_time(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300220 if (ret < 0)
221 return ret;
222
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300223 return 0;
224}
225
Luciano Coelho12419cc2010-02-18 13:25:44 +0200226int wl1271_init_phy_config(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300227{
228 int ret;
229
230 ret = wl1271_acx_pd_threshold(wl);
231 if (ret < 0)
232 return ret;
233
Eliad Peller92c77c72011-10-05 11:55:40 +0200234 return 0;
235}
236
Eliad Peller0603d892011-10-05 11:55:51 +0200237static int wl12xx_init_phy_vif_config(struct wl1271 *wl,
238 struct wl12xx_vif *wlvif)
Eliad Peller92c77c72011-10-05 11:55:40 +0200239{
240 int ret;
241
Eliad Peller0603d892011-10-05 11:55:51 +0200242 ret = wl1271_acx_slot(wl, wlvif, DEFAULT_SLOT_TIME);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300243 if (ret < 0)
244 return ret;
245
Eliad Peller0603d892011-10-05 11:55:51 +0200246 ret = wl1271_acx_service_period_timeout(wl, wlvif);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300247 if (ret < 0)
248 return ret;
249
Eliad Peller0603d892011-10-05 11:55:51 +0200250 ret = wl1271_acx_rts_threshold(wl, wlvif, wl->hw->wiphy->rts_threshold);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300251 if (ret < 0)
252 return ret;
253
254 return 0;
255}
256
Arik Nemtsova6935342011-10-24 17:25:20 +0200257static int wl1271_init_sta_beacon_filter(struct wl1271 *wl,
258 struct wl12xx_vif *wlvif)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300259{
260 int ret;
261
Arik Nemtsova6935342011-10-24 17:25:20 +0200262 ret = wl1271_acx_beacon_filter_table(wl, wlvif);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300263 if (ret < 0)
264 return ret;
265
Arik Nemtsova6935342011-10-24 17:25:20 +0200266 /* enable beacon filtering */
267 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300268 if (ret < 0)
269 return ret;
270
271 return 0;
272}
273
Luciano Coelho12419cc2010-02-18 13:25:44 +0200274int wl1271_init_pta(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300275{
276 int ret;
277
Eliad Peller3be41122011-08-14 13:17:19 +0300278 ret = wl12xx_acx_sg_cfg(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300279 if (ret < 0)
280 return ret;
281
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +0200282 ret = wl1271_acx_sg_enable(wl, wl->sg_enabled);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300283 if (ret < 0)
284 return ret;
285
286 return 0;
287}
288
Luciano Coelho12419cc2010-02-18 13:25:44 +0200289int wl1271_init_energy_detection(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300290{
291 int ret;
292
293 ret = wl1271_acx_cca_threshold(wl);
294 if (ret < 0)
295 return ret;
296
297 return 0;
298}
299
Eliad Peller0603d892011-10-05 11:55:51 +0200300static int wl1271_init_beacon_broadcast(struct wl1271 *wl,
301 struct wl12xx_vif *wlvif)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300302{
303 int ret;
304
Eliad Peller0603d892011-10-05 11:55:51 +0200305 ret = wl1271_acx_bcn_dtim_options(wl, wlvif);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300306 if (ret < 0)
307 return ret;
308
309 return 0;
310}
311
Ido Yariv95dac04f2011-06-06 14:57:06 +0300312static int wl12xx_init_fwlog(struct wl1271 *wl)
313{
314 int ret;
315
316 if (wl->quirks & WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED)
317 return 0;
318
319 ret = wl12xx_cmd_config_fwlog(wl);
320 if (ret < 0)
321 return ret;
322
323 return 0;
324}
325
Eliad Peller92c77c72011-10-05 11:55:40 +0200326/* generic sta initialization (non vif-specific) */
Eliad Peller30d0c8f2011-10-05 11:55:42 +0200327static int wl1271_sta_hw_init(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200328{
329 int ret;
330
Eliad Pellerc8bde242011-02-02 09:59:35 +0200331 /* PS config */
Eliad Pellerd2d66c52011-10-05 11:55:43 +0200332 ret = wl12xx_acx_config_ps(wl, wlvif);
Eliad Pellerc8bde242011-02-02 09:59:35 +0200333 if (ret < 0)
334 return ret;
335
Shahar Leviff868432011-04-11 15:41:46 +0300336 /* FM WLAN coexistence */
337 ret = wl1271_acx_fm_coex(wl);
338 if (ret < 0)
339 return ret;
340
Eliad Peller30d0c8f2011-10-05 11:55:42 +0200341 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200342 if (ret < 0)
343 return ret;
344
345 return 0;
346}
347
Eliad Peller0603d892011-10-05 11:55:51 +0200348static int wl1271_sta_hw_init_post_mem(struct wl1271 *wl,
349 struct ieee80211_vif *vif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200350{
Eliad Peller0603d892011-10-05 11:55:51 +0200351 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200352 int ret, i;
353
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200354 /* disable all keep-alive templates */
355 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
Eliad Peller0603d892011-10-05 11:55:51 +0200356 ret = wl1271_acx_keep_alive_config(wl, wlvif, i,
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200357 ACX_KEEP_ALIVE_TPL_INVALID);
358 if (ret < 0)
359 return ret;
360 }
361
362 /* disable the keep-alive feature */
Eliad Peller0603d892011-10-05 11:55:51 +0200363 ret = wl1271_acx_keep_alive_mode(wl, wlvif, false);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200364 if (ret < 0)
365 return ret;
366
367 return 0;
368}
369
Eliad Peller92c77c72011-10-05 11:55:40 +0200370/* generic ap initialization (non vif-specific) */
Eliad Peller87fbcb02011-10-05 11:55:41 +0200371static int wl1271_ap_hw_init(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200372{
Arik Nemtsov70f47422011-04-18 14:15:25 +0300373 int ret;
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200374
Eliad Peller87fbcb02011-10-05 11:55:41 +0200375 ret = wl1271_init_ap_rates(wl, wlvif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200376 if (ret < 0)
377 return ret;
378
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200379 return 0;
380}
381
Eliad Peller784f6942011-10-05 11:55:39 +0200382int wl1271_ap_init_templates(struct wl1271 *wl, struct ieee80211_vif *vif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200383{
Eliad Peller87fbcb02011-10-05 11:55:41 +0200384 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200385 int ret;
386
Eliad Peller87fbcb02011-10-05 11:55:41 +0200387 ret = wl1271_ap_init_deauth_template(wl, wlvif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200388 if (ret < 0)
389 return ret;
390
Eliad Peller784f6942011-10-05 11:55:39 +0200391 ret = wl1271_ap_init_null_template(wl, vif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200392 if (ret < 0)
393 return ret;
394
Eliad Peller784f6942011-10-05 11:55:39 +0200395 ret = wl1271_ap_init_qos_null_template(wl, vif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200396 if (ret < 0)
397 return ret;
398
Arik Nemtsov521a4a22011-04-18 14:15:22 +0300399 /*
400 * when operating as AP we want to receive external beacons for
401 * configuring ERP protection.
402 */
Eliad Peller0603d892011-10-05 11:55:51 +0200403 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false);
Arik Nemtsov521a4a22011-04-18 14:15:22 +0300404 if (ret < 0)
405 return ret;
406
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200407 return 0;
408}
409
Eliad Peller784f6942011-10-05 11:55:39 +0200410static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl,
411 struct ieee80211_vif *vif)
Arik Nemtsovc45a85b2011-04-18 14:15:26 +0300412{
Eliad Peller784f6942011-10-05 11:55:39 +0200413 return wl1271_ap_init_templates(wl, vif);
Arik Nemtsovc45a85b2011-04-18 14:15:26 +0300414}
415
Eliad Peller87fbcb02011-10-05 11:55:41 +0200416int wl1271_init_ap_rates(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Arik Nemtsov70f47422011-04-18 14:15:25 +0300417{
418 int i, ret;
419 struct conf_tx_rate_class rc;
420 u32 supported_rates;
421
Eliad Peller87fbcb02011-10-05 11:55:41 +0200422 wl1271_debug(DEBUG_AP, "AP basic rate set: 0x%x",
423 wlvif->basic_rate_set);
Arik Nemtsov70f47422011-04-18 14:15:25 +0300424
Eliad Peller87fbcb02011-10-05 11:55:41 +0200425 if (wlvif->basic_rate_set == 0)
Arik Nemtsov70f47422011-04-18 14:15:25 +0300426 return -EINVAL;
427
Eliad Peller87fbcb02011-10-05 11:55:41 +0200428 rc.enabled_rates = wlvif->basic_rate_set;
Arik Nemtsov70f47422011-04-18 14:15:25 +0300429 rc.long_retry_limit = 10;
430 rc.short_retry_limit = 10;
431 rc.aflags = 0;
Eliad Pellere5a359f2011-10-10 10:13:15 +0200432 ret = wl1271_acx_ap_rate_policy(wl, &rc, wlvif->ap.mgmt_rate_idx);
Arik Nemtsov70f47422011-04-18 14:15:25 +0300433 if (ret < 0)
434 return ret;
435
436 /* use the min basic rate for AP broadcast/multicast */
Eliad Peller87fbcb02011-10-05 11:55:41 +0200437 rc.enabled_rates = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
Arik Nemtsov70f47422011-04-18 14:15:25 +0300438 rc.short_retry_limit = 10;
439 rc.long_retry_limit = 10;
440 rc.aflags = 0;
Eliad Pellere5a359f2011-10-10 10:13:15 +0200441 ret = wl1271_acx_ap_rate_policy(wl, &rc, wlvif->ap.bcast_rate_idx);
Arik Nemtsov70f47422011-04-18 14:15:25 +0300442 if (ret < 0)
443 return ret;
444
445 /*
446 * If the basic rates contain OFDM rates, use OFDM only
447 * rates for unicast TX as well. Else use all supported rates.
448 */
Eliad Peller87fbcb02011-10-05 11:55:41 +0200449 if ((wlvif->basic_rate_set & CONF_TX_OFDM_RATES))
Arik Nemtsov70f47422011-04-18 14:15:25 +0300450 supported_rates = CONF_TX_OFDM_RATES;
451 else
452 supported_rates = CONF_TX_AP_ENABLED_RATES;
453
Arik Nemtsov1a8adb62011-08-14 13:17:29 +0300454 /* unconditionally enable HT rates */
455 supported_rates |= CONF_TX_MCS_RATES;
456
Arik Nemtsov70f47422011-04-18 14:15:25 +0300457 /* configure unicast TX rate classes */
458 for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
459 rc.enabled_rates = supported_rates;
460 rc.short_retry_limit = 10;
461 rc.long_retry_limit = 10;
462 rc.aflags = 0;
Eliad Pellere5a359f2011-10-10 10:13:15 +0200463 ret = wl1271_acx_ap_rate_policy(wl, &rc,
464 wlvif->ap.ucast_rate_idx[i]);
Arik Nemtsov70f47422011-04-18 14:15:25 +0300465 if (ret < 0)
466 return ret;
467 }
468
469 return 0;
470}
471
Eliad Peller536129c82011-10-05 11:55:45 +0200472static int wl1271_set_ba_policies(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100473{
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100474 /* Reset the BA RX indicators */
Eliad Pellerd0802ab2011-10-05 11:56:04 +0200475 wlvif->ba_allowed = true;
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300476 wl->ba_rx_session_count = 0;
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100477
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300478 /* BA is supported in STA/AP modes */
Eliad Peller536129c82011-10-05 11:55:45 +0200479 if (wlvif->bss_type != BSS_TYPE_AP_BSS &&
480 wlvif->bss_type != BSS_TYPE_STA_BSS) {
Eliad Pellerd0802ab2011-10-05 11:56:04 +0200481 wlvif->ba_support = false;
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300482 return 0;
483 }
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100484
Eliad Pellerd0802ab2011-10-05 11:56:04 +0200485 wlvif->ba_support = true;
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100486
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300487 /* 802.11n initiator BA session setting */
Eliad Peller0603d892011-10-05 11:55:51 +0200488 return wl12xx_acx_set_ba_initiator_policy(wl, wlvif);
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100489}
490
Shahar Levi48a61472011-03-06 16:32:08 +0200491int wl1271_chip_specific_init(struct wl1271 *wl)
492{
493 int ret = 0;
494
495 if (wl->chip.id == CHIP_ID_1283_PG20) {
496 u32 host_cfg_bitmap = HOST_IF_CFG_RX_FIFO_ENABLE;
497
Luciano Coelhoce39def2011-11-03 08:44:41 +0200498 if (!(wl->quirks & WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT))
Shahar Levi48a61472011-03-06 16:32:08 +0200499 /* Enable SDIO padding */
500 host_cfg_bitmap |= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK;
501
502 /* Must be before wl1271_acx_init_mem_config() */
503 ret = wl1271_acx_host_if_cfg_bitmap(wl, host_cfg_bitmap);
504 if (ret < 0)
505 goto out;
506 }
507out:
508 return ret;
509}
510
Eliad Peller92c77c72011-10-05 11:55:40 +0200511/* vif-specifc initialization */
Eliad Peller0603d892011-10-05 11:55:51 +0200512static int wl12xx_init_sta_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Eliad Peller92c77c72011-10-05 11:55:40 +0200513{
514 int ret;
Shahar Levi48a61472011-03-06 16:32:08 +0200515
Eliad Peller0603d892011-10-05 11:55:51 +0200516 ret = wl1271_acx_group_address_tbl(wl, wlvif, true, NULL, 0);
Eliad Peller92c77c72011-10-05 11:55:40 +0200517 if (ret < 0)
518 return ret;
519
520 /* Initialize connection monitoring thresholds */
Eliad Peller0603d892011-10-05 11:55:51 +0200521 ret = wl1271_acx_conn_monit_params(wl, wlvif, false);
Eliad Peller92c77c72011-10-05 11:55:40 +0200522 if (ret < 0)
523 return ret;
524
525 /* Beacon filtering */
Arik Nemtsova6935342011-10-24 17:25:20 +0200526 ret = wl1271_init_sta_beacon_filter(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200527 if (ret < 0)
528 return ret;
529
530 /* Beacons and broadcast settings */
Eliad Peller0603d892011-10-05 11:55:51 +0200531 ret = wl1271_init_beacon_broadcast(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200532 if (ret < 0)
533 return ret;
534
535 /* Configure rssi/snr averaging weights */
Eliad Peller0603d892011-10-05 11:55:51 +0200536 ret = wl1271_acx_rssi_snr_avg_weights(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200537 if (ret < 0)
538 return ret;
539
540 return 0;
541}
542
543/* vif-specific intialization */
Eliad Peller0603d892011-10-05 11:55:51 +0200544static int wl12xx_init_ap_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Eliad Peller92c77c72011-10-05 11:55:40 +0200545{
546 int ret;
547
Eliad Peller0603d892011-10-05 11:55:51 +0200548 ret = wl1271_acx_ap_max_tx_retry(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200549 if (ret < 0)
550 return ret;
551
552 /* initialize Tx power */
Eliad Peller6bd65022011-10-10 10:13:11 +0200553 ret = wl1271_acx_tx_power(wl, wlvif, wlvif->power_level);
Eliad Peller92c77c72011-10-05 11:55:40 +0200554 if (ret < 0)
555 return ret;
556
557 return 0;
558}
559
560int wl1271_init_vif_specific(struct wl1271 *wl, struct ieee80211_vif *vif)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300561{
Eliad Peller87fbcb02011-10-05 11:55:41 +0200562 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Kalle Valo243eeb52010-02-18 13:25:39 +0200563 struct conf_tx_ac_category *conf_ac;
Kalle Valof2054df2010-02-18 13:25:40 +0200564 struct conf_tx_tid *conf_tid;
Eliad Peller536129c82011-10-05 11:55:45 +0200565 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
Eliad Peller92c77c72011-10-05 11:55:40 +0200566 int ret, i;
567
Eliad Pellera4e41302011-10-11 11:49:15 +0200568 /*
569 * consider all existing roles before configuring psm.
570 * TODO: reconfigure on interface removal.
571 */
572 if (!wl->ap_count) {
573 if (is_ap) {
574 /* Configure for power always on */
575 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
576 if (ret < 0)
577 return ret;
578 } else if (!wl->sta_count) {
579 /* Configure for ELP power saving */
580 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
581 if (ret < 0)
582 return ret;
583 }
584 }
585
Eliad Peller92c77c72011-10-05 11:55:40 +0200586 /* Mode specific init */
587 if (is_ap) {
Eliad Peller87fbcb02011-10-05 11:55:41 +0200588 ret = wl1271_ap_hw_init(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200589 if (ret < 0)
590 return ret;
591
Eliad Peller0603d892011-10-05 11:55:51 +0200592 ret = wl12xx_init_ap_role(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200593 if (ret < 0)
594 return ret;
595 } else {
Eliad Peller30d0c8f2011-10-05 11:55:42 +0200596 ret = wl1271_sta_hw_init(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200597 if (ret < 0)
598 return ret;
599
Eliad Peller0603d892011-10-05 11:55:51 +0200600 ret = wl12xx_init_sta_role(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200601 if (ret < 0)
602 return ret;
603 }
604
Eliad Peller0603d892011-10-05 11:55:51 +0200605 wl12xx_init_phy_vif_config(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200606
607 /* Default TID/AC configuration */
608 BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
609 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
610 conf_ac = &wl->conf.tx.ac_conf[i];
Eliad Peller0603d892011-10-05 11:55:51 +0200611 ret = wl1271_acx_ac_cfg(wl, wlvif, conf_ac->ac,
612 conf_ac->cw_min, conf_ac->cw_max,
613 conf_ac->aifsn, conf_ac->tx_op_limit);
Eliad Peller92c77c72011-10-05 11:55:40 +0200614 if (ret < 0)
615 return ret;
616
617 conf_tid = &wl->conf.tx.tid_conf[i];
Eliad Peller0603d892011-10-05 11:55:51 +0200618 ret = wl1271_acx_tid_cfg(wl, wlvif,
Eliad Peller92c77c72011-10-05 11:55:40 +0200619 conf_tid->queue_id,
620 conf_tid->channel_type,
621 conf_tid->tsid,
622 conf_tid->ps_scheme,
623 conf_tid->ack_policy,
624 conf_tid->apsd_conf[0],
625 conf_tid->apsd_conf[1]);
626 if (ret < 0)
627 return ret;
628 }
629
630 /* Configure HW encryption */
Eliad Peller0603d892011-10-05 11:55:51 +0200631 ret = wl1271_acx_feature_cfg(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200632 if (ret < 0)
633 return ret;
634
635 /* Mode specific init - post mem init */
636 if (is_ap)
637 ret = wl1271_ap_hw_init_post_mem(wl, vif);
638 else
Eliad Peller0603d892011-10-05 11:55:51 +0200639 ret = wl1271_sta_hw_init_post_mem(wl, vif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200640
641 if (ret < 0)
642 return ret;
643
644 /* Configure initiator BA sessions policies */
Eliad Peller536129c82011-10-05 11:55:45 +0200645 ret = wl1271_set_ba_policies(wl, wlvif);
Eliad Peller92c77c72011-10-05 11:55:40 +0200646 if (ret < 0)
647 return ret;
648
649 return 0;
650}
651
652int wl1271_hw_init(struct wl1271 *wl)
653{
654 int ret;
655
Luciano Coelho2c8f82e2011-12-13 11:39:50 +0200656 if (wl->chip.id == CHIP_ID_1283_PG20) {
Shahar Levi49d750ca2011-03-06 16:32:09 +0200657 ret = wl128x_cmd_general_parms(wl);
Luciano Coelho2c8f82e2011-12-13 11:39:50 +0200658 if (ret < 0)
659 return ret;
Shahar Levi49d750ca2011-03-06 16:32:09 +0200660 ret = wl128x_cmd_radio_parms(wl);
Luciano Coelho2c8f82e2011-12-13 11:39:50 +0200661 if (ret < 0)
662 return ret;
663 } else {
664 ret = wl1271_cmd_general_parms(wl);
665 if (ret < 0)
666 return ret;
Shahar Levi49d750ca2011-03-06 16:32:09 +0200667 ret = wl1271_cmd_radio_parms(wl);
Luciano Coelho2c8f82e2011-12-13 11:39:50 +0200668 if (ret < 0)
669 return ret;
670 ret = wl1271_cmd_ext_radio_parms(wl);
671 if (ret < 0)
672 return ret;
673 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300674
Shahar Levi48a61472011-03-06 16:32:08 +0200675 /* Chip-specific init */
676 ret = wl1271_chip_specific_init(wl);
677 if (ret < 0)
678 return ret;
679
Eliad Peller92c77c72011-10-05 11:55:40 +0200680 /* Init templates */
681 ret = wl1271_init_templates_config(wl);
682 if (ret < 0)
683 return ret;
Juuso Oikarinen644a4862010-10-05 13:11:56 +0200684
Eliad Peller92c77c72011-10-05 11:55:40 +0200685 ret = wl12xx_acx_mem_cfg(wl);
686 if (ret < 0)
687 return ret;
688
689 /* Configure the FW logger */
690 ret = wl12xx_init_fwlog(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300691 if (ret < 0)
692 return ret;
693
Arik Nemtsov801f8702011-04-18 14:15:20 +0300694 /* Bluetooth WLAN coexistence */
695 ret = wl1271_init_pta(wl);
696 if (ret < 0)
697 return ret;
698
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300699 /* Default memory configuration */
700 ret = wl1271_acx_init_mem_config(wl);
701 if (ret < 0)
702 return ret;
703
704 /* RX config */
Eliad Peller08c1d1c2011-08-14 13:17:04 +0300705 ret = wl12xx_init_rx_config(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300706 if (ret < 0)
707 goto out_free_memmap;
708
709 /* PHY layer config */
710 ret = wl1271_init_phy_config(wl);
711 if (ret < 0)
712 goto out_free_memmap;
713
Luciano Coelho6e92b412009-12-11 15:40:50 +0200714 ret = wl1271_acx_dco_itrim_params(wl);
715 if (ret < 0)
716 goto out_free_memmap;
717
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300718 /* Configure TX patch complete interrupt behavior */
719 ret = wl1271_acx_tx_config_options(wl);
720 if (ret < 0)
721 goto out_free_memmap;
722
723 /* RX complete interrupt pacing */
724 ret = wl1271_acx_init_rx_interrupt(wl);
725 if (ret < 0)
726 goto out_free_memmap;
727
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300728 /* Energy detection */
729 ret = wl1271_init_energy_detection(wl);
730 if (ret < 0)
731 goto out_free_memmap;
732
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300733 /* Default fragmentation threshold */
Arik Nemtsov5f704d12011-04-18 14:15:21 +0300734 ret = wl1271_acx_frag_threshold(wl, wl->hw->wiphy->frag_threshold);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300735 if (ret < 0)
736 goto out_free_memmap;
737
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300738 /* Enable data path */
Luciano Coelho94210892009-12-11 15:40:55 +0200739 ret = wl1271_cmd_data_path(wl, 1);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300740 if (ret < 0)
741 goto out_free_memmap;
742
Juuso Oikarinen38ad2d82009-12-11 15:41:08 +0200743 /* configure PM */
744 ret = wl1271_acx_pm_config(wl);
745 if (ret < 0)
746 goto out_free_memmap;
747
Eliad Pellerfa6ad9f2011-08-14 13:17:14 +0300748 ret = wl12xx_acx_set_rate_mgmt_params(wl);
749 if (ret < 0)
750 goto out_free_memmap;
751
Eliad Peller94877752011-08-28 15:11:56 +0300752 /* configure hangover */
753 ret = wl12xx_acx_config_hangover(wl);
754 if (ret < 0)
755 goto out_free_memmap;
756
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300757 return 0;
758
759 out_free_memmap:
760 kfree(wl->target_mem_map);
Juuso Oikarinen34415232009-10-08 21:56:33 +0300761 wl->target_mem_map = NULL;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300762
763 return ret;
764}