blob: 4692a91ca737c7b54c354935266b8b69c34f8ba2 [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
Arik Nemtsove0fe3712010-10-16 18:19:53 +020036int wl1271_sta_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
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +020091 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
92 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV, NULL,
Eliad Peller154037d2011-08-14 13:17:12 +030093 WL1271_CMD_TEMPL_DFLT_SIZE, i,
Juuso Oikarinen606c1482010-04-01 11:38:21 +030094 WL1271_RATE_AUTOMATIC);
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +020095 if (ret < 0)
96 return ret;
97 }
98
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030099 return 0;
100}
101
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200102static int wl1271_ap_init_deauth_template(struct wl1271 *wl)
103{
104 struct wl12xx_disconn_template *tmpl;
105 int ret;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300106 u32 rate;
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200107
108 tmpl = kzalloc(sizeof(*tmpl), GFP_KERNEL);
109 if (!tmpl) {
110 ret = -ENOMEM;
111 goto out;
112 }
113
114 tmpl->header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT |
115 IEEE80211_STYPE_DEAUTH);
116
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300117 rate = wl1271_tx_min_rate_get(wl, wl->basic_rate_set);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200118 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300119 tmpl, sizeof(*tmpl), 0, rate);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200120
121out:
122 kfree(tmpl);
123 return ret;
124}
125
Eliad Peller784f6942011-10-05 11:55:39 +0200126static int wl1271_ap_init_null_template(struct wl1271 *wl,
127 struct ieee80211_vif *vif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200128{
129 struct ieee80211_hdr_3addr *nullfunc;
130 int ret;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300131 u32 rate;
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200132
133 nullfunc = kzalloc(sizeof(*nullfunc), GFP_KERNEL);
134 if (!nullfunc) {
135 ret = -ENOMEM;
136 goto out;
137 }
138
139 nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
140 IEEE80211_STYPE_NULLFUNC |
141 IEEE80211_FCTL_FROMDS);
142
143 /* nullfunc->addr1 is filled by FW */
144
Eliad Peller784f6942011-10-05 11:55:39 +0200145 memcpy(nullfunc->addr2, vif->addr, ETH_ALEN);
146 memcpy(nullfunc->addr3, vif->addr, ETH_ALEN);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200147
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300148 rate = wl1271_tx_min_rate_get(wl, wl->basic_rate_set);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200149 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, nullfunc,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300150 sizeof(*nullfunc), 0, rate);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200151
152out:
153 kfree(nullfunc);
154 return ret;
155}
156
Eliad Peller784f6942011-10-05 11:55:39 +0200157static int wl1271_ap_init_qos_null_template(struct wl1271 *wl,
158 struct ieee80211_vif *vif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200159{
160 struct ieee80211_qos_hdr *qosnull;
161 int ret;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300162 u32 rate;
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200163
164 qosnull = kzalloc(sizeof(*qosnull), GFP_KERNEL);
165 if (!qosnull) {
166 ret = -ENOMEM;
167 goto out;
168 }
169
170 qosnull->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
171 IEEE80211_STYPE_QOS_NULLFUNC |
172 IEEE80211_FCTL_FROMDS);
173
174 /* qosnull->addr1 is filled by FW */
175
Eliad Peller784f6942011-10-05 11:55:39 +0200176 memcpy(qosnull->addr2, vif->addr, ETH_ALEN);
177 memcpy(qosnull->addr3, vif->addr, ETH_ALEN);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200178
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300179 rate = wl1271_tx_min_rate_get(wl, wl->basic_rate_set);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200180 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, qosnull,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300181 sizeof(*qosnull), 0, rate);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200182
183out:
184 kfree(qosnull);
185 return ret;
186}
187
188static int wl1271_ap_init_templates_config(struct wl1271 *wl)
189{
190 int ret;
191
192 /*
193 * Put very large empty placeholders for all templates. These
194 * reserve memory for later.
195 */
196 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_PROBE_RESPONSE, NULL,
Eliad Peller154037d2011-08-14 13:17:12 +0300197 WL1271_CMD_TEMPL_MAX_SIZE,
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200198 0, WL1271_RATE_AUTOMATIC);
199 if (ret < 0)
200 return ret;
201
202 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_BEACON, NULL,
Eliad Peller154037d2011-08-14 13:17:12 +0300203 WL1271_CMD_TEMPL_MAX_SIZE,
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200204 0, WL1271_RATE_AUTOMATIC);
205 if (ret < 0)
206 return ret;
207
208 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP, NULL,
209 sizeof
210 (struct wl12xx_disconn_template),
211 0, WL1271_RATE_AUTOMATIC);
212 if (ret < 0)
213 return ret;
214
215 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
216 sizeof(struct wl12xx_null_data_template),
217 0, WL1271_RATE_AUTOMATIC);
218 if (ret < 0)
219 return ret;
220
221 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
222 sizeof
223 (struct wl12xx_qos_null_data_template),
224 0, WL1271_RATE_AUTOMATIC);
225 if (ret < 0)
226 return ret;
227
228 return 0;
229}
230
Eliad Peller08c1d1c2011-08-14 13:17:04 +0300231static int wl12xx_init_rx_config(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300232{
233 int ret;
234
Juuso Oikarinen8793f9b2009-10-13 12:47:40 +0300235 ret = wl1271_acx_rx_msdu_life_time(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300236 if (ret < 0)
237 return ret;
238
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300239 return 0;
240}
241
Luciano Coelho12419cce2010-02-18 13:25:44 +0200242int wl1271_init_phy_config(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300243{
244 int ret;
245
246 ret = wl1271_acx_pd_threshold(wl);
247 if (ret < 0)
248 return ret;
249
250 ret = wl1271_acx_slot(wl, DEFAULT_SLOT_TIME);
251 if (ret < 0)
252 return ret;
253
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300254 ret = wl1271_acx_service_period_timeout(wl);
255 if (ret < 0)
256 return ret;
257
Arik Nemtsov5f704d12011-04-18 14:15:21 +0300258 ret = wl1271_acx_rts_threshold(wl, wl->hw->wiphy->rts_threshold);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300259 if (ret < 0)
260 return ret;
261
262 return 0;
263}
264
265static int wl1271_init_beacon_filter(struct wl1271 *wl)
266{
267 int ret;
268
Juuso Oikarinen19221672009-10-08 21:56:35 +0300269 /* disable beacon filtering at this stage */
270 ret = wl1271_acx_beacon_filter_opt(wl, false);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300271 if (ret < 0)
272 return ret;
273
274 ret = wl1271_acx_beacon_filter_table(wl);
275 if (ret < 0)
276 return ret;
277
278 return 0;
279}
280
Luciano Coelho12419cce2010-02-18 13:25:44 +0200281int wl1271_init_pta(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300282{
283 int ret;
284
Eliad Peller3be41122011-08-14 13:17:19 +0300285 ret = wl12xx_acx_sg_cfg(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300286 if (ret < 0)
287 return ret;
288
Juuso Oikarinen7fc3a862010-03-18 12:26:32 +0200289 ret = wl1271_acx_sg_enable(wl, wl->sg_enabled);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300290 if (ret < 0)
291 return ret;
292
293 return 0;
294}
295
Luciano Coelho12419cce2010-02-18 13:25:44 +0200296int wl1271_init_energy_detection(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300297{
298 int ret;
299
300 ret = wl1271_acx_cca_threshold(wl);
301 if (ret < 0)
302 return ret;
303
304 return 0;
305}
306
307static int wl1271_init_beacon_broadcast(struct wl1271 *wl)
308{
309 int ret;
310
311 ret = wl1271_acx_bcn_dtim_options(wl);
312 if (ret < 0)
313 return ret;
314
315 return 0;
316}
317
Ido Yariv95dac04f2011-06-06 14:57:06 +0300318static int wl12xx_init_fwlog(struct wl1271 *wl)
319{
320 int ret;
321
322 if (wl->quirks & WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED)
323 return 0;
324
325 ret = wl12xx_cmd_config_fwlog(wl);
326 if (ret < 0)
327 return ret;
328
329 return 0;
330}
331
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200332static int wl1271_sta_hw_init(struct wl1271 *wl)
333{
334 int ret;
335
Shahar Levi49d750ca2011-03-06 16:32:09 +0200336 if (wl->chip.id != CHIP_ID_1283_PG20) {
337 ret = wl1271_cmd_ext_radio_parms(wl);
338 if (ret < 0)
339 return ret;
340 }
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200341
Eliad Pellerc8bde242011-02-02 09:59:35 +0200342 /* PS config */
343 ret = wl1271_acx_config_ps(wl);
344 if (ret < 0)
345 return ret;
346
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200347 ret = wl1271_sta_init_templates_config(wl);
348 if (ret < 0)
349 return ret;
350
351 ret = wl1271_acx_group_address_tbl(wl, true, NULL, 0);
352 if (ret < 0)
353 return ret;
354
355 /* Initialize connection monitoring thresholds */
356 ret = wl1271_acx_conn_monit_params(wl, false);
357 if (ret < 0)
358 return ret;
359
360 /* Beacon filtering */
361 ret = wl1271_init_beacon_filter(wl);
362 if (ret < 0)
363 return ret;
364
Shahar Leviff868432011-04-11 15:41:46 +0300365 /* FM WLAN coexistence */
366 ret = wl1271_acx_fm_coex(wl);
367 if (ret < 0)
368 return ret;
369
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200370 /* Beacons and broadcast settings */
371 ret = wl1271_init_beacon_broadcast(wl);
372 if (ret < 0)
373 return ret;
374
375 /* Configure for ELP power saving */
376 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
377 if (ret < 0)
378 return ret;
379
380 /* Configure rssi/snr averaging weights */
381 ret = wl1271_acx_rssi_snr_avg_weights(wl);
382 if (ret < 0)
383 return ret;
384
385 ret = wl1271_acx_sta_rate_policies(wl);
386 if (ret < 0)
387 return ret;
388
Eliad Peller7f0979882011-08-14 13:17:06 +0300389 ret = wl12xx_acx_mem_cfg(wl);
Eliad Pellerc8bde242011-02-02 09:59:35 +0200390 if (ret < 0)
391 return ret;
392
Ido Yariv95dac04f2011-06-06 14:57:06 +0300393 /* Configure the FW logger */
394 ret = wl12xx_init_fwlog(wl);
395 if (ret < 0)
396 return ret;
397
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200398 return 0;
399}
400
401static int wl1271_sta_hw_init_post_mem(struct wl1271 *wl)
402{
403 int ret, i;
404
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200405 /* disable all keep-alive templates */
406 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
407 ret = wl1271_acx_keep_alive_config(wl, i,
408 ACX_KEEP_ALIVE_TPL_INVALID);
409 if (ret < 0)
410 return ret;
411 }
412
413 /* disable the keep-alive feature */
414 ret = wl1271_acx_keep_alive_mode(wl, false);
415 if (ret < 0)
416 return ret;
417
418 return 0;
419}
420
421static int wl1271_ap_hw_init(struct wl1271 *wl)
422{
Arik Nemtsov70f47422011-04-18 14:15:25 +0300423 int ret;
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200424
425 ret = wl1271_ap_init_templates_config(wl);
426 if (ret < 0)
427 return ret;
428
429 /* Configure for power always on */
430 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
431 if (ret < 0)
432 return ret;
433
Arik Nemtsov70f47422011-04-18 14:15:25 +0300434 ret = wl1271_init_ap_rates(wl);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200435 if (ret < 0)
436 return ret;
437
Arik Nemtsov3618f302011-06-26 10:36:03 +0300438 ret = wl1271_acx_ap_max_tx_retry(wl);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200439 if (ret < 0)
440 return ret;
441
Eliad Peller7f0979882011-08-14 13:17:06 +0300442 ret = wl12xx_acx_mem_cfg(wl);
Eliad Pellerc8bde242011-02-02 09:59:35 +0200443 if (ret < 0)
444 return ret;
445
Arik Nemtsov097f8822011-06-27 22:06:34 +0300446 /* initialize Tx power */
447 ret = wl1271_acx_tx_power(wl, wl->power_level);
448 if (ret < 0)
449 return ret;
450
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200451 return 0;
452}
453
Eliad Peller784f6942011-10-05 11:55:39 +0200454int wl1271_ap_init_templates(struct wl1271 *wl, struct ieee80211_vif *vif)
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200455{
456 int ret;
457
458 ret = wl1271_ap_init_deauth_template(wl);
459 if (ret < 0)
460 return ret;
461
Eliad Peller784f6942011-10-05 11:55:39 +0200462 ret = wl1271_ap_init_null_template(wl, vif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200463 if (ret < 0)
464 return ret;
465
Eliad Peller784f6942011-10-05 11:55:39 +0200466 ret = wl1271_ap_init_qos_null_template(wl, vif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200467 if (ret < 0)
468 return ret;
469
Arik Nemtsov521a4a22011-04-18 14:15:22 +0300470 /*
471 * when operating as AP we want to receive external beacons for
472 * configuring ERP protection.
473 */
Eliad Pellerf42bd2c2011-08-14 13:17:13 +0300474 ret = wl1271_acx_beacon_filter_opt(wl, false);
Arik Nemtsov521a4a22011-04-18 14:15:22 +0300475 if (ret < 0)
476 return ret;
477
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200478 return 0;
479}
480
Eliad Peller784f6942011-10-05 11:55:39 +0200481static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl,
482 struct ieee80211_vif *vif)
Arik Nemtsovc45a85b2011-04-18 14:15:26 +0300483{
Eliad Peller784f6942011-10-05 11:55:39 +0200484 return wl1271_ap_init_templates(wl, vif);
Arik Nemtsovc45a85b2011-04-18 14:15:26 +0300485}
486
Arik Nemtsov70f47422011-04-18 14:15:25 +0300487int wl1271_init_ap_rates(struct wl1271 *wl)
488{
489 int i, ret;
490 struct conf_tx_rate_class rc;
491 u32 supported_rates;
492
493 wl1271_debug(DEBUG_AP, "AP basic rate set: 0x%x", wl->basic_rate_set);
494
495 if (wl->basic_rate_set == 0)
496 return -EINVAL;
497
498 rc.enabled_rates = wl->basic_rate_set;
499 rc.long_retry_limit = 10;
500 rc.short_retry_limit = 10;
501 rc.aflags = 0;
502 ret = wl1271_acx_ap_rate_policy(wl, &rc, ACX_TX_AP_MODE_MGMT_RATE);
503 if (ret < 0)
504 return ret;
505
506 /* use the min basic rate for AP broadcast/multicast */
Eliad Pelleraf7fbb22011-09-19 13:51:42 +0300507 rc.enabled_rates = wl1271_tx_min_rate_get(wl, wl->basic_rate_set);
Arik Nemtsov70f47422011-04-18 14:15:25 +0300508 rc.short_retry_limit = 10;
509 rc.long_retry_limit = 10;
510 rc.aflags = 0;
511 ret = wl1271_acx_ap_rate_policy(wl, &rc, ACX_TX_AP_MODE_BCST_RATE);
512 if (ret < 0)
513 return ret;
514
515 /*
516 * If the basic rates contain OFDM rates, use OFDM only
517 * rates for unicast TX as well. Else use all supported rates.
518 */
519 if ((wl->basic_rate_set & CONF_TX_OFDM_RATES))
520 supported_rates = CONF_TX_OFDM_RATES;
521 else
522 supported_rates = CONF_TX_AP_ENABLED_RATES;
523
Arik Nemtsov1a8adb62011-08-14 13:17:29 +0300524 /* unconditionally enable HT rates */
525 supported_rates |= CONF_TX_MCS_RATES;
526
Arik Nemtsov70f47422011-04-18 14:15:25 +0300527 /* configure unicast TX rate classes */
528 for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
529 rc.enabled_rates = supported_rates;
530 rc.short_retry_limit = 10;
531 rc.long_retry_limit = 10;
532 rc.aflags = 0;
533 ret = wl1271_acx_ap_rate_policy(wl, &rc, i);
534 if (ret < 0)
535 return ret;
536 }
537
538 return 0;
539}
540
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100541static int wl1271_set_ba_policies(struct wl1271 *wl)
542{
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100543 /* Reset the BA RX indicators */
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100544 wl->ba_rx_bitmap = 0;
Shahar Levi70559a02011-05-22 16:10:22 +0300545 wl->ba_allowed = true;
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300546 wl->ba_rx_session_count = 0;
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100547
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300548 /* BA is supported in STA/AP modes */
549 if (wl->bss_type != BSS_TYPE_AP_BSS &&
550 wl->bss_type != BSS_TYPE_STA_BSS) {
551 wl->ba_support = false;
552 return 0;
553 }
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100554
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300555 wl->ba_support = true;
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100556
Arik Nemtsov0f9c8252011-08-17 10:45:49 +0300557 /* 802.11n initiator BA session setting */
558 return wl12xx_acx_set_ba_initiator_policy(wl);
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100559}
560
Shahar Levi48a61472011-03-06 16:32:08 +0200561int wl1271_chip_specific_init(struct wl1271 *wl)
562{
563 int ret = 0;
564
565 if (wl->chip.id == CHIP_ID_1283_PG20) {
566 u32 host_cfg_bitmap = HOST_IF_CFG_RX_FIFO_ENABLE;
567
Ido Yariv0da13da2011-03-31 10:06:58 +0200568 if (wl->quirks & WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT)
Shahar Levi48a61472011-03-06 16:32:08 +0200569 /* Enable SDIO padding */
570 host_cfg_bitmap |= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK;
571
572 /* Must be before wl1271_acx_init_mem_config() */
573 ret = wl1271_acx_host_if_cfg_bitmap(wl, host_cfg_bitmap);
574 if (ret < 0)
575 goto out;
576 }
577out:
578 return ret;
579}
580
581
Eliad Peller784f6942011-10-05 11:55:39 +0200582int wl1271_hw_init(struct wl1271 *wl, struct ieee80211_vif *vif)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300583{
Kalle Valo243eeb52010-02-18 13:25:39 +0200584 struct conf_tx_ac_category *conf_ac;
Kalle Valof2054df2010-02-18 13:25:40 +0200585 struct conf_tx_tid *conf_tid;
Kalle Valo243eeb52010-02-18 13:25:39 +0200586 int ret, i;
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200587 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300588
Shahar Levi49d750ca2011-03-06 16:32:09 +0200589 if (wl->chip.id == CHIP_ID_1283_PG20)
590 ret = wl128x_cmd_general_parms(wl);
591 else
592 ret = wl1271_cmd_general_parms(wl);
Luciano Coelho4a904062009-11-23 23:22:18 +0200593 if (ret < 0)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300594 return ret;
595
Shahar Levi49d750ca2011-03-06 16:32:09 +0200596 if (wl->chip.id == CHIP_ID_1283_PG20)
597 ret = wl128x_cmd_radio_parms(wl);
598 else
599 ret = wl1271_cmd_radio_parms(wl);
Luciano Coelho4a904062009-11-23 23:22:18 +0200600 if (ret < 0)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300601 return ret;
602
Shahar Levi48a61472011-03-06 16:32:08 +0200603 /* Chip-specific init */
604 ret = wl1271_chip_specific_init(wl);
605 if (ret < 0)
606 return ret;
607
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200608 /* Mode specific init */
609 if (is_ap)
610 ret = wl1271_ap_hw_init(wl);
611 else
612 ret = wl1271_sta_hw_init(wl);
Juuso Oikarinen644a4862010-10-05 13:11:56 +0200613
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300614 if (ret < 0)
615 return ret;
616
Arik Nemtsov801f8702011-04-18 14:15:20 +0300617 /* Bluetooth WLAN coexistence */
618 ret = wl1271_init_pta(wl);
619 if (ret < 0)
620 return ret;
621
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300622 /* Default memory configuration */
623 ret = wl1271_acx_init_mem_config(wl);
624 if (ret < 0)
625 return ret;
626
627 /* RX config */
Eliad Peller08c1d1c2011-08-14 13:17:04 +0300628 ret = wl12xx_init_rx_config(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300629 if (ret < 0)
630 goto out_free_memmap;
631
632 /* PHY layer config */
633 ret = wl1271_init_phy_config(wl);
634 if (ret < 0)
635 goto out_free_memmap;
636
Luciano Coelho6e92b412009-12-11 15:40:50 +0200637 ret = wl1271_acx_dco_itrim_params(wl);
638 if (ret < 0)
639 goto out_free_memmap;
640
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300641 /* Configure TX patch complete interrupt behavior */
642 ret = wl1271_acx_tx_config_options(wl);
643 if (ret < 0)
644 goto out_free_memmap;
645
646 /* RX complete interrupt pacing */
647 ret = wl1271_acx_init_rx_interrupt(wl);
648 if (ret < 0)
649 goto out_free_memmap;
650
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300651 /* Energy detection */
652 ret = wl1271_init_energy_detection(wl);
653 if (ret < 0)
654 goto out_free_memmap;
655
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300656 /* Default fragmentation threshold */
Arik Nemtsov5f704d12011-04-18 14:15:21 +0300657 ret = wl1271_acx_frag_threshold(wl, wl->hw->wiphy->frag_threshold);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300658 if (ret < 0)
659 goto out_free_memmap;
660
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200661 /* Default TID/AC configuration */
662 BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
Kalle Valof2054df2010-02-18 13:25:40 +0200663 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
Juuso Oikarinen9987a9d2010-09-01 11:31:12 +0200664 conf_ac = &wl->conf.tx.ac_conf[i];
665 ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
666 conf_ac->cw_max, conf_ac->aifsn,
667 conf_ac->tx_op_limit);
668 if (ret < 0)
669 goto out_free_memmap;
670
Kalle Valof2054df2010-02-18 13:25:40 +0200671 conf_tid = &wl->conf.tx.tid_conf[i];
672 ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id,
673 conf_tid->channel_type,
674 conf_tid->tsid,
675 conf_tid->ps_scheme,
676 conf_tid->ack_policy,
677 conf_tid->apsd_conf[0],
678 conf_tid->apsd_conf[1]);
679 if (ret < 0)
680 goto out_free_memmap;
681 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300682
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300683 /* Enable data path */
Luciano Coelho94210892009-12-11 15:40:55 +0200684 ret = wl1271_cmd_data_path(wl, 1);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300685 if (ret < 0)
686 goto out_free_memmap;
687
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300688 /* Configure HW encryption */
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200689 ret = wl1271_acx_feature_cfg(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300690 if (ret < 0)
691 goto out_free_memmap;
692
Juuso Oikarinen38ad2d82009-12-11 15:41:08 +0200693 /* configure PM */
694 ret = wl1271_acx_pm_config(wl);
695 if (ret < 0)
696 goto out_free_memmap;
697
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200698 /* Mode specific init - post mem init */
699 if (is_ap)
Eliad Peller784f6942011-10-05 11:55:39 +0200700 ret = wl1271_ap_hw_init_post_mem(wl, vif);
Arik Nemtsove0fe3712010-10-16 18:19:53 +0200701 else
702 ret = wl1271_sta_hw_init_post_mem(wl);
Juuso Oikarinenc1899552010-03-26 12:53:32 +0200703
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300704 if (ret < 0)
705 goto out_free_memmap;
706
Eliad Pellerfa6ad9f2011-08-14 13:17:14 +0300707 ret = wl12xx_acx_set_rate_mgmt_params(wl);
708 if (ret < 0)
709 goto out_free_memmap;
710
Levi, Shahar4b7fac72011-01-23 07:27:22 +0100711 /* Configure initiator BA sessions policies */
712 ret = wl1271_set_ba_policies(wl);
713 if (ret < 0)
714 goto out_free_memmap;
715
Eliad Peller94877752011-08-28 15:11:56 +0300716 /* configure hangover */
717 ret = wl12xx_acx_config_hangover(wl);
718 if (ret < 0)
719 goto out_free_memmap;
720
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300721 return 0;
722
723 out_free_memmap:
724 kfree(wl->target_mem_map);
Juuso Oikarinen34415232009-10-08 21:56:33 +0300725 wl->target_mem_map = NULL;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300726
727 return ret;
728}