blob: fcf2b128f9a4e553a45849cd23145be5d457b743 [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 */
Eliad Pellercdaac622012-01-31 11:57:16 +020042 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
43 CMD_TEMPL_CFG_PROBE_REQ_2_4, NULL,
Eliad Peller154037d2011-08-14 13:17:12 +030044 WL1271_CMD_TEMPL_DFLT_SIZE,
Juuso Oikarinen606c1482010-04-01 11:38:21 +030045 0, WL1271_RATE_AUTOMATIC);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030046 if (ret < 0)
47 return ret;
48
Eliad Pellercdaac622012-01-31 11:57:16 +020049 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
50 CMD_TEMPL_CFG_PROBE_REQ_5,
Eliad Peller154037d2011-08-14 13:17:12 +030051 NULL, WL1271_CMD_TEMPL_DFLT_SIZE, 0,
Juuso Oikarinen11eb5422010-08-24 06:28:03 +030052 WL1271_RATE_AUTOMATIC);
53 if (ret < 0)
54 return ret;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +030055
Eliad Pellercdaac622012-01-31 11:57:16 +020056 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
57 CMD_TEMPL_NULL_DATA, NULL,
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +020058 sizeof(struct wl12xx_null_data_template),
Juuso Oikarinen606c1482010-04-01 11:38:21 +030059 0, WL1271_RATE_AUTOMATIC);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030060 if (ret < 0)
61 return ret;
62
Eliad Pellercdaac622012-01-31 11:57:16 +020063 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
64 CMD_TEMPL_PS_POLL, NULL,
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +020065 sizeof(struct wl12xx_ps_poll_template),
Juuso Oikarinen606c1482010-04-01 11:38:21 +030066 0, WL1271_RATE_AUTOMATIC);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030067 if (ret < 0)
68 return ret;
69
Eliad Pellercdaac622012-01-31 11:57:16 +020070 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
71 CMD_TEMPL_QOS_NULL_DATA, NULL,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030072 sizeof
Eliad Peller97127e62011-11-09 13:12:45 +020073 (struct ieee80211_qos_hdr),
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
Eliad Pellercdaac622012-01-31 11:57:16 +020078 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
79 CMD_TEMPL_PROBE_RESPONSE, 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 Pellercdaac622012-01-31 11:57:16 +020085 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
86 CMD_TEMPL_BEACON, NULL,
Eliad Peller154037d2011-08-14 13:17:12 +030087 WL1271_CMD_TEMPL_DFLT_SIZE,
Juuso Oikarinen606c1482010-04-01 11:38:21 +030088 0, WL1271_RATE_AUTOMATIC);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030089 if (ret < 0)
90 return ret;
91
Eliad Pellercdaac622012-01-31 11:57:16 +020092 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
93 CMD_TEMPL_ARP_RSP, NULL,
Eliad Pellerc5312772010-12-09 11:31:27 +020094 sizeof
95 (struct wl12xx_arp_rsp_template),
96 0, WL1271_RATE_AUTOMATIC);
97 if (ret < 0)
98 return ret;
99
Eliad Peller92c77c72011-10-05 11:55:40 +0200100 /*
101 * Put very large empty placeholders for all templates. These
102 * reserve memory for later.
103 */
Eliad Pellercdaac622012-01-31 11:57:16 +0200104 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
105 CMD_TEMPL_AP_PROBE_RESPONSE, NULL,
Eliad Peller92c77c72011-10-05 11:55:40 +0200106 WL1271_CMD_TEMPL_MAX_SIZE,
107 0, WL1271_RATE_AUTOMATIC);
108 if (ret < 0)
109 return ret;
110
Eliad Pellercdaac622012-01-31 11:57:16 +0200111 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
112 CMD_TEMPL_AP_BEACON, NULL,
Eliad Peller92c77c72011-10-05 11:55:40 +0200113 WL1271_CMD_TEMPL_MAX_SIZE,
114 0, WL1271_RATE_AUTOMATIC);
115 if (ret < 0)
116 return ret;
117
Eliad Pellercdaac622012-01-31 11:57:16 +0200118 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
119 CMD_TEMPL_DEAUTH_AP, NULL,
Eliad Peller92c77c72011-10-05 11:55:40 +0200120 sizeof
121 (struct wl12xx_disconn_template),
122 0, WL1271_RATE_AUTOMATIC);
123 if (ret < 0)
124 return ret;
125
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200126 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
Eliad Pellercdaac622012-01-31 11:57:16 +0200127 ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
128 CMD_TEMPL_KLV, NULL,
Eliad Peller97127e62011-11-09 13:12:45 +0200129 sizeof(struct ieee80211_qos_hdr),
130 i, WL1271_RATE_AUTOMATIC);
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200131 if (ret < 0)
132 return ret;
133 }
134
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300135 return 0;
136}
137
Eliad Peller87fbcb02011-10-05 11:55:41 +0200138static int wl1271_ap_init_deauth_template(struct wl1271 *wl,
139 struct wl12xx_vif *wlvif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200140{
141 struct wl12xx_disconn_template *tmpl;
142 int ret;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300143 u32 rate;
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200144
145 tmpl = kzalloc(sizeof(*tmpl), GFP_KERNEL);
146 if (!tmpl) {
147 ret = -ENOMEM;
148 goto out;
149 }
150
151 tmpl->header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT |
152 IEEE80211_STYPE_DEAUTH);
153
Eliad Peller87fbcb02011-10-05 11:55:41 +0200154 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
Eliad Pellercdaac622012-01-31 11:57:16 +0200155 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
156 CMD_TEMPL_DEAUTH_AP,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300157 tmpl, sizeof(*tmpl), 0, rate);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200158
159out:
160 kfree(tmpl);
161 return ret;
162}
163
Eliad Peller784f6942011-10-05 11:55:39 +0200164static int wl1271_ap_init_null_template(struct wl1271 *wl,
165 struct ieee80211_vif *vif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200166{
Eliad Peller87fbcb02011-10-05 11:55:41 +0200167 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200168 struct ieee80211_hdr_3addr *nullfunc;
169 int ret;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300170 u32 rate;
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200171
172 nullfunc = kzalloc(sizeof(*nullfunc), GFP_KERNEL);
173 if (!nullfunc) {
174 ret = -ENOMEM;
175 goto out;
176 }
177
178 nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
179 IEEE80211_STYPE_NULLFUNC |
180 IEEE80211_FCTL_FROMDS);
181
182 /* nullfunc->addr1 is filled by FW */
183
Eliad Peller784f6942011-10-05 11:55:39 +0200184 memcpy(nullfunc->addr2, vif->addr, ETH_ALEN);
185 memcpy(nullfunc->addr3, vif->addr, ETH_ALEN);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200186
Eliad Peller87fbcb02011-10-05 11:55:41 +0200187 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
Eliad Pellercdaac622012-01-31 11:57:16 +0200188 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
189 CMD_TEMPL_NULL_DATA, nullfunc,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300190 sizeof(*nullfunc), 0, rate);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200191
192out:
193 kfree(nullfunc);
194 return ret;
195}
196
Eliad Peller784f6942011-10-05 11:55:39 +0200197static int wl1271_ap_init_qos_null_template(struct wl1271 *wl,
198 struct ieee80211_vif *vif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200199{
Eliad Peller87fbcb02011-10-05 11:55:41 +0200200 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200201 struct ieee80211_qos_hdr *qosnull;
202 int ret;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300203 u32 rate;
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200204
205 qosnull = kzalloc(sizeof(*qosnull), GFP_KERNEL);
206 if (!qosnull) {
207 ret = -ENOMEM;
208 goto out;
209 }
210
211 qosnull->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
212 IEEE80211_STYPE_QOS_NULLFUNC |
213 IEEE80211_FCTL_FROMDS);
214
215 /* qosnull->addr1 is filled by FW */
216
Eliad Peller784f6942011-10-05 11:55:39 +0200217 memcpy(qosnull->addr2, vif->addr, ETH_ALEN);
218 memcpy(qosnull->addr3, vif->addr, ETH_ALEN);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200219
Eliad Peller87fbcb02011-10-05 11:55:41 +0200220 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
Eliad Pellercdaac622012-01-31 11:57:16 +0200221 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
222 CMD_TEMPL_QOS_NULL_DATA, qosnull,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300223 sizeof(*qosnull), 0, rate);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200224
225out:
226 kfree(qosnull);
227 return ret;
228}
229
Eliad Peller08c1d1c2011-08-14 13:17:04 +0300230static int wl12xx_init_rx_config(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300231{
232 int ret;
233
Juuso Oikarinen8793f9b2009-10-13 12:47:40 +0300234 ret = wl1271_acx_rx_msdu_life_time(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300235 if (ret < 0)
236 return ret;
237
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300238 return 0;
239}
240
Eliad Peller0603d892011-10-05 11:55:51 +0200241static int wl12xx_init_phy_vif_config(struct wl1271 *wl,
242 struct wl12xx_vif *wlvif)
Eliad Peller92c77c72011-10-05 11:55:40 +0200243{
244 int ret;
245
Eliad Peller0603d892011-10-05 11:55:51 +0200246 ret = wl1271_acx_slot(wl, wlvif, DEFAULT_SLOT_TIME);
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_service_period_timeout(wl, wlvif);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300251 if (ret < 0)
252 return ret;
253
Eliad Peller0603d892011-10-05 11:55:51 +0200254 ret = wl1271_acx_rts_threshold(wl, wlvif, wl->hw->wiphy->rts_threshold);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300255 if (ret < 0)
256 return ret;
257
258 return 0;
259}
260
Arik Nemtsova6935342011-10-24 17:25:20 +0200261static int wl1271_init_sta_beacon_filter(struct wl1271 *wl,
262 struct wl12xx_vif *wlvif)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300263{
264 int ret;
265
Arik Nemtsova6935342011-10-24 17:25:20 +0200266 ret = wl1271_acx_beacon_filter_table(wl, wlvif);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300267 if (ret < 0)
268 return ret;
269
Arik Nemtsova6935342011-10-24 17:25:20 +0200270 /* enable beacon filtering */
271 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300272 if (ret < 0)
273 return ret;
274
275 return 0;
276}
277
Luciano Coelho12419cce2010-02-18 13:25:44 +0200278int wl1271_init_pta(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300279{
280 int ret;
281
Eliad Peller3be41122011-08-14 13:17:19 +0300282 ret = wl12xx_acx_sg_cfg(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300283 if (ret < 0)
284 return ret;
285
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +0200286 ret = wl1271_acx_sg_enable(wl, wl->sg_enabled);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300287 if (ret < 0)
288 return ret;
289
290 return 0;
291}
292
Luciano Coelho12419cce2010-02-18 13:25:44 +0200293int wl1271_init_energy_detection(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300294{
295 int ret;
296
297 ret = wl1271_acx_cca_threshold(wl);
298 if (ret < 0)
299 return ret;
300
301 return 0;
302}
303
Eliad Peller0603d892011-10-05 11:55:51 +0200304static int wl1271_init_beacon_broadcast(struct wl1271 *wl,
305 struct wl12xx_vif *wlvif)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300306{
307 int ret;
308
Eliad Peller0603d892011-10-05 11:55:51 +0200309 ret = wl1271_acx_bcn_dtim_options(wl, wlvif);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300310 if (ret < 0)
311 return ret;
312
313 return 0;
314}
315
Ido Yariv95dac04f2011-06-06 14:57:06 +0300316static int wl12xx_init_fwlog(struct wl1271 *wl)
317{
318 int ret;
319
320 if (wl->quirks & WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED)
321 return 0;
322
323 ret = wl12xx_cmd_config_fwlog(wl);
324 if (ret < 0)
325 return ret;
326
327 return 0;
328}
329
Eliad Peller92c77c72011-10-05 11:55:40 +0200330/* generic sta initialization (non vif-specific) */
Eliad Peller30d0c8f2011-10-05 11:55:42 +0200331static int wl1271_sta_hw_init(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200332{
333 int ret;
334
Eliad Pellerc8bde242011-02-02 09:59:35 +0200335 /* PS config */
Eliad Pellerd2d66c52011-10-05 11:55:43 +0200336 ret = wl12xx_acx_config_ps(wl, wlvif);
Eliad Pellerc8bde242011-02-02 09:59:35 +0200337 if (ret < 0)
338 return ret;
339
Shahar Leviff868432011-04-11 15:41:46 +0300340 /* FM WLAN coexistence */
341 ret = wl1271_acx_fm_coex(wl);
342 if (ret < 0)
343 return ret;
344
Eliad Peller30d0c8f2011-10-05 11:55:42 +0200345 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200346 if (ret < 0)
347 return ret;
348
349 return 0;
350}
351
Eliad Peller0603d892011-10-05 11:55:51 +0200352static int wl1271_sta_hw_init_post_mem(struct wl1271 *wl,
353 struct ieee80211_vif *vif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200354{
Eliad Peller0603d892011-10-05 11:55:51 +0200355 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200356 int ret, i;
357
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200358 /* disable all keep-alive templates */
359 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
Eliad Peller0603d892011-10-05 11:55:51 +0200360 ret = wl1271_acx_keep_alive_config(wl, wlvif, i,
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200361 ACX_KEEP_ALIVE_TPL_INVALID);
362 if (ret < 0)
363 return ret;
364 }
365
366 /* disable the keep-alive feature */
Eliad Peller0603d892011-10-05 11:55:51 +0200367 ret = wl1271_acx_keep_alive_mode(wl, wlvif, false);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200368 if (ret < 0)
369 return ret;
370
371 return 0;
372}
373
Eliad Peller92c77c72011-10-05 11:55:40 +0200374/* generic ap initialization (non vif-specific) */
Eliad Peller87fbcb02011-10-05 11:55:41 +0200375static int wl1271_ap_hw_init(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200376{
Arik Nemtsov70f47422011-04-18 14:15:25 +0300377 int ret;
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200378
Eliad Peller87fbcb02011-10-05 11:55:41 +0200379 ret = wl1271_init_ap_rates(wl, wlvif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200380 if (ret < 0)
381 return ret;
382
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200383 return 0;
384}
385
Eliad Peller784f6942011-10-05 11:55:39 +0200386int wl1271_ap_init_templates(struct wl1271 *wl, struct ieee80211_vif *vif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200387{
Eliad Peller87fbcb02011-10-05 11:55:41 +0200388 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200389 int ret;
390
Eliad Peller87fbcb02011-10-05 11:55:41 +0200391 ret = wl1271_ap_init_deauth_template(wl, wlvif);
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_null_template(wl, vif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200396 if (ret < 0)
397 return ret;
398
Eliad Peller784f6942011-10-05 11:55:39 +0200399 ret = wl1271_ap_init_qos_null_template(wl, vif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200400 if (ret < 0)
401 return ret;
402
Arik Nemtsov521a4a22011-04-18 14:15:22 +0300403 /*
404 * when operating as AP we want to receive external beacons for
405 * configuring ERP protection.
406 */
Eliad Peller0603d892011-10-05 11:55:51 +0200407 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false);
Arik Nemtsov521a4a22011-04-18 14:15:22 +0300408 if (ret < 0)
409 return ret;
410
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200411 return 0;
412}
413
Eliad Peller784f6942011-10-05 11:55:39 +0200414static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl,
415 struct ieee80211_vif *vif)
Arik Nemtsovc45a85b2011-04-18 14:15:26 +0300416{
Eliad Peller784f6942011-10-05 11:55:39 +0200417 return wl1271_ap_init_templates(wl, vif);
Arik Nemtsovc45a85b2011-04-18 14:15:26 +0300418}
419
Eliad Peller87fbcb02011-10-05 11:55:41 +0200420int wl1271_init_ap_rates(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Arik Nemtsov70f47422011-04-18 14:15:25 +0300421{
422 int i, ret;
423 struct conf_tx_rate_class rc;
424 u32 supported_rates;
425
Eliad Peller87fbcb02011-10-05 11:55:41 +0200426 wl1271_debug(DEBUG_AP, "AP basic rate set: 0x%x",
427 wlvif->basic_rate_set);
Arik Nemtsov70f47422011-04-18 14:15:25 +0300428
Eliad Peller87fbcb02011-10-05 11:55:41 +0200429 if (wlvif->basic_rate_set == 0)
Arik Nemtsov70f47422011-04-18 14:15:25 +0300430 return -EINVAL;
431
Eliad Peller87fbcb02011-10-05 11:55:41 +0200432 rc.enabled_rates = wlvif->basic_rate_set;
Arik Nemtsov70f47422011-04-18 14:15:25 +0300433 rc.long_retry_limit = 10;
434 rc.short_retry_limit = 10;
435 rc.aflags = 0;
Eliad Pellere5a359f2011-10-10 10:13:15 +0200436 ret = wl1271_acx_ap_rate_policy(wl, &rc, wlvif->ap.mgmt_rate_idx);
Arik Nemtsov70f47422011-04-18 14:15:25 +0300437 if (ret < 0)
438 return ret;
439
440 /* use the min basic rate for AP broadcast/multicast */
Eliad Peller87fbcb02011-10-05 11:55:41 +0200441 rc.enabled_rates = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
Arik Nemtsov70f47422011-04-18 14:15:25 +0300442 rc.short_retry_limit = 10;
443 rc.long_retry_limit = 10;
444 rc.aflags = 0;
Eliad Pellere5a359f2011-10-10 10:13:15 +0200445 ret = wl1271_acx_ap_rate_policy(wl, &rc, wlvif->ap.bcast_rate_idx);
Arik Nemtsov70f47422011-04-18 14:15:25 +0300446 if (ret < 0)
447 return ret;
448
449 /*
450 * If the basic rates contain OFDM rates, use OFDM only
451 * rates for unicast TX as well. Else use all supported rates.
452 */
Eliad Peller87fbcb02011-10-05 11:55:41 +0200453 if ((wlvif->basic_rate_set & CONF_TX_OFDM_RATES))
Arik Nemtsov70f47422011-04-18 14:15:25 +0300454 supported_rates = CONF_TX_OFDM_RATES;
455 else
456 supported_rates = CONF_TX_AP_ENABLED_RATES;
457
Arik Nemtsov1a8adb62011-08-14 13:17:29 +0300458 /* unconditionally enable HT rates */
459 supported_rates |= CONF_TX_MCS_RATES;
460
Arik Nemtsov70f47422011-04-18 14:15:25 +0300461 /* configure unicast TX rate classes */
462 for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
463 rc.enabled_rates = supported_rates;
464 rc.short_retry_limit = 10;
465 rc.long_retry_limit = 10;
466 rc.aflags = 0;
Eliad Pellere5a359f2011-10-10 10:13:15 +0200467 ret = wl1271_acx_ap_rate_policy(wl, &rc,
468 wlvif->ap.ucast_rate_idx[i]);
Arik Nemtsov70f47422011-04-18 14:15:25 +0300469 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
Luciano Coelhoce39def2011-11-03 08:44:41 +0200502 if (!(wl->quirks & WL12XX_QUIRK_NO_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 */
Arik Nemtsova6935342011-10-24 17:25:20 +0200530 ret = wl1271_init_sta_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 Peller6bd65022011-10-10 10:13:11 +0200557 ret = wl1271_acx_tx_power(wl, wlvif, wlvif->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
Luciano Coelho2c8f82e2011-12-13 11:39:50 +0200660 if (wl->chip.id == CHIP_ID_1283_PG20) {
Shahar Levi49d750ca2011-03-06 16:32:09 +0200661 ret = wl128x_cmd_general_parms(wl);
Luciano Coelho2c8f82e2011-12-13 11:39:50 +0200662 if (ret < 0)
663 return ret;
Shahar Levi49d750ca2011-03-06 16:32:09 +0200664 ret = wl128x_cmd_radio_parms(wl);
Luciano Coelho2c8f82e2011-12-13 11:39:50 +0200665 if (ret < 0)
666 return ret;
667 } else {
668 ret = wl1271_cmd_general_parms(wl);
669 if (ret < 0)
670 return ret;
Shahar Levi49d750ca2011-03-06 16:32:09 +0200671 ret = wl1271_cmd_radio_parms(wl);
Luciano Coelho2c8f82e2011-12-13 11:39:50 +0200672 if (ret < 0)
673 return ret;
674 ret = wl1271_cmd_ext_radio_parms(wl);
675 if (ret < 0)
676 return ret;
677 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300678
Shahar Levi48a61472011-03-06 16:32:08 +0200679 /* Chip-specific init */
680 ret = wl1271_chip_specific_init(wl);
681 if (ret < 0)
682 return ret;
683
Eliad Peller92c77c72011-10-05 11:55:40 +0200684 /* Init templates */
685 ret = wl1271_init_templates_config(wl);
686 if (ret < 0)
687 return ret;
Juuso Oikarinen644a4862010-10-05 13:11:56 +0200688
Eliad Peller92c77c72011-10-05 11:55:40 +0200689 ret = wl12xx_acx_mem_cfg(wl);
690 if (ret < 0)
691 return ret;
692
693 /* Configure the FW logger */
694 ret = wl12xx_init_fwlog(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300695 if (ret < 0)
696 return ret;
697
Arik Nemtsov801f8702011-04-18 14:15:20 +0300698 /* Bluetooth WLAN coexistence */
699 ret = wl1271_init_pta(wl);
700 if (ret < 0)
701 return ret;
702
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300703 /* Default memory configuration */
704 ret = wl1271_acx_init_mem_config(wl);
705 if (ret < 0)
706 return ret;
707
708 /* RX config */
Eliad Peller08c1d1c2011-08-14 13:17:04 +0300709 ret = wl12xx_init_rx_config(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300710 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}