]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/net/wireless/wl12xx/init.c
wl12xx: mcp2.5 - add config_ps acx
[mirror_ubuntu-zesty-kernel.git] / drivers / net / wireless / wl12xx / init.c
CommitLineData
f5fc0f86
LC
1/*
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>
5a0e3ad6 26#include <linux/slab.h>
f5fc0f86 27
00d20100 28#include "init.h"
f5fc0f86 29#include "wl12xx_80211.h"
00d20100
SL
30#include "acx.h"
31#include "cmd.h"
32#include "reg.h"
e0fe371b 33#include "tx.h"
f5fc0f86 34
e0fe371b 35int wl1271_sta_init_templates_config(struct wl1271 *wl)
f5fc0f86 36{
bfb24c9e 37 int ret, i;
f5fc0f86
LC
38
39 /* send empty templates for fw memory reservation */
40 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, NULL,
ea559b46 41 WL1271_CMD_TEMPL_MAX_SIZE,
606c1487 42 0, WL1271_RATE_AUTOMATIC);
f5fc0f86
LC
43 if (ret < 0)
44 return ret;
45
11eb5429 46 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
ea559b46 47 NULL, WL1271_CMD_TEMPL_MAX_SIZE, 0,
11eb5429
JO
48 WL1271_RATE_AUTOMATIC);
49 if (ret < 0)
50 return ret;
abb0b3bf 51
f5fc0f86 52 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
bfb24c9e 53 sizeof(struct wl12xx_null_data_template),
606c1487 54 0, WL1271_RATE_AUTOMATIC);
f5fc0f86
LC
55 if (ret < 0)
56 return ret;
57
58 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, NULL,
bfb24c9e 59 sizeof(struct wl12xx_ps_poll_template),
606c1487 60 0, WL1271_RATE_AUTOMATIC);
f5fc0f86
LC
61 if (ret < 0)
62 return ret;
63
64 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
65 sizeof
bfb24c9e 66 (struct wl12xx_qos_null_data_template),
606c1487 67 0, WL1271_RATE_AUTOMATIC);
f5fc0f86
LC
68 if (ret < 0)
69 return ret;
70
71 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE, NULL,
72 sizeof
bfb24c9e 73 (struct wl12xx_probe_resp_template),
606c1487 74 0, WL1271_RATE_AUTOMATIC);
f5fc0f86
LC
75 if (ret < 0)
76 return ret;
77
78 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON, NULL,
79 sizeof
bfb24c9e 80 (struct wl12xx_beacon_template),
606c1487 81 0, WL1271_RATE_AUTOMATIC);
f5fc0f86
LC
82 if (ret < 0)
83 return ret;
84
c5312772
EP
85 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
bfb24c9e
JO
92 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
93 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV, NULL,
606c1487
JO
94 WL1271_CMD_TEMPL_MAX_SIZE, i,
95 WL1271_RATE_AUTOMATIC);
bfb24c9e
JO
96 if (ret < 0)
97 return ret;
98 }
99
f5fc0f86
LC
100 return 0;
101}
102
e0fe371b
AN
103static int wl1271_ap_init_deauth_template(struct wl1271 *wl)
104{
105 struct wl12xx_disconn_template *tmpl;
106 int ret;
107
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
117 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP,
118 tmpl, sizeof(*tmpl), 0,
119 wl1271_tx_min_rate_get(wl));
120
121out:
122 kfree(tmpl);
123 return ret;
124}
125
126static int wl1271_ap_init_null_template(struct wl1271 *wl)
127{
128 struct ieee80211_hdr_3addr *nullfunc;
129 int ret;
130
131 nullfunc = kzalloc(sizeof(*nullfunc), GFP_KERNEL);
132 if (!nullfunc) {
133 ret = -ENOMEM;
134 goto out;
135 }
136
137 nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
138 IEEE80211_STYPE_NULLFUNC |
139 IEEE80211_FCTL_FROMDS);
140
141 /* nullfunc->addr1 is filled by FW */
142
143 memcpy(nullfunc->addr2, wl->mac_addr, ETH_ALEN);
144 memcpy(nullfunc->addr3, wl->mac_addr, ETH_ALEN);
145
146 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, nullfunc,
147 sizeof(*nullfunc), 0,
148 wl1271_tx_min_rate_get(wl));
149
150out:
151 kfree(nullfunc);
152 return ret;
153}
154
155static int wl1271_ap_init_qos_null_template(struct wl1271 *wl)
156{
157 struct ieee80211_qos_hdr *qosnull;
158 int ret;
159
160 qosnull = kzalloc(sizeof(*qosnull), GFP_KERNEL);
161 if (!qosnull) {
162 ret = -ENOMEM;
163 goto out;
164 }
165
166 qosnull->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
167 IEEE80211_STYPE_QOS_NULLFUNC |
168 IEEE80211_FCTL_FROMDS);
169
170 /* qosnull->addr1 is filled by FW */
171
172 memcpy(qosnull->addr2, wl->mac_addr, ETH_ALEN);
173 memcpy(qosnull->addr3, wl->mac_addr, ETH_ALEN);
174
175 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, qosnull,
176 sizeof(*qosnull), 0,
177 wl1271_tx_min_rate_get(wl));
178
179out:
180 kfree(qosnull);
181 return ret;
182}
183
184static int wl1271_ap_init_templates_config(struct wl1271 *wl)
185{
186 int ret;
187
188 /*
189 * Put very large empty placeholders for all templates. These
190 * reserve memory for later.
191 */
192 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_PROBE_RESPONSE, NULL,
193 sizeof
194 (struct wl12xx_probe_resp_template),
195 0, WL1271_RATE_AUTOMATIC);
196 if (ret < 0)
197 return ret;
198
199 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_BEACON, NULL,
200 sizeof
201 (struct wl12xx_beacon_template),
202 0, WL1271_RATE_AUTOMATIC);
203 if (ret < 0)
204 return ret;
205
206 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP, NULL,
207 sizeof
208 (struct wl12xx_disconn_template),
209 0, WL1271_RATE_AUTOMATIC);
210 if (ret < 0)
211 return ret;
212
213 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
214 sizeof(struct wl12xx_null_data_template),
215 0, WL1271_RATE_AUTOMATIC);
216 if (ret < 0)
217 return ret;
218
219 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
220 sizeof
221 (struct wl12xx_qos_null_data_template),
222 0, WL1271_RATE_AUTOMATIC);
223 if (ret < 0)
224 return ret;
225
226 return 0;
227}
228
f5fc0f86
LC
229static int wl1271_init_rx_config(struct wl1271 *wl, u32 config, u32 filter)
230{
231 int ret;
232
8793f9bb 233 ret = wl1271_acx_rx_msdu_life_time(wl);
f5fc0f86
LC
234 if (ret < 0)
235 return ret;
236
237 ret = wl1271_acx_rx_config(wl, config, filter);
238 if (ret < 0)
239 return ret;
240
241 return 0;
242}
243
12419cce 244int wl1271_init_phy_config(struct wl1271 *wl)
f5fc0f86
LC
245{
246 int ret;
247
248 ret = wl1271_acx_pd_threshold(wl);
249 if (ret < 0)
250 return ret;
251
252 ret = wl1271_acx_slot(wl, DEFAULT_SLOT_TIME);
253 if (ret < 0)
254 return ret;
255
f5fc0f86
LC
256 ret = wl1271_acx_service_period_timeout(wl);
257 if (ret < 0)
258 return ret;
259
8793f9bb 260 ret = wl1271_acx_rts_threshold(wl, wl->conf.rx.rts_threshold);
f5fc0f86
LC
261 if (ret < 0)
262 return ret;
263
264 return 0;
265}
266
267static int wl1271_init_beacon_filter(struct wl1271 *wl)
268{
269 int ret;
270
1922167b
JO
271 /* disable beacon filtering at this stage */
272 ret = wl1271_acx_beacon_filter_opt(wl, false);
f5fc0f86
LC
273 if (ret < 0)
274 return ret;
275
276 ret = wl1271_acx_beacon_filter_table(wl);
277 if (ret < 0)
278 return ret;
279
280 return 0;
281}
282
12419cce 283int wl1271_init_pta(struct wl1271 *wl)
f5fc0f86
LC
284{
285 int ret;
286
1b00f546 287 ret = wl1271_acx_sg_cfg(wl);
f5fc0f86
LC
288 if (ret < 0)
289 return ret;
290
7fc3a864 291 ret = wl1271_acx_sg_enable(wl, wl->sg_enabled);
f5fc0f86
LC
292 if (ret < 0)
293 return ret;
294
295 return 0;
296}
297
12419cce 298int wl1271_init_energy_detection(struct wl1271 *wl)
f5fc0f86
LC
299{
300 int ret;
301
302 ret = wl1271_acx_cca_threshold(wl);
303 if (ret < 0)
304 return ret;
305
306 return 0;
307}
308
309static int wl1271_init_beacon_broadcast(struct wl1271 *wl)
310{
311 int ret;
312
313 ret = wl1271_acx_bcn_dtim_options(wl);
314 if (ret < 0)
315 return ret;
316
317 return 0;
318}
319
e0fe371b
AN
320static int wl1271_sta_hw_init(struct wl1271 *wl)
321{
322 int ret;
323
324 ret = wl1271_cmd_ext_radio_parms(wl);
325 if (ret < 0)
326 return ret;
327
328 ret = wl1271_sta_init_templates_config(wl);
329 if (ret < 0)
330 return ret;
331
332 ret = wl1271_acx_group_address_tbl(wl, true, NULL, 0);
333 if (ret < 0)
334 return ret;
335
336 /* Initialize connection monitoring thresholds */
337 ret = wl1271_acx_conn_monit_params(wl, false);
338 if (ret < 0)
339 return ret;
340
341 /* Beacon filtering */
342 ret = wl1271_init_beacon_filter(wl);
343 if (ret < 0)
344 return ret;
345
346 /* Bluetooth WLAN coexistence */
347 ret = wl1271_init_pta(wl);
348 if (ret < 0)
349 return ret;
350
351 /* Beacons and broadcast settings */
352 ret = wl1271_init_beacon_broadcast(wl);
353 if (ret < 0)
354 return ret;
355
356 /* Configure for ELP power saving */
357 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
358 if (ret < 0)
359 return ret;
360
361 /* Configure rssi/snr averaging weights */
362 ret = wl1271_acx_rssi_snr_avg_weights(wl);
363 if (ret < 0)
364 return ret;
365
366 ret = wl1271_acx_sta_rate_policies(wl);
367 if (ret < 0)
368 return ret;
369
370 return 0;
371}
372
373static int wl1271_sta_hw_init_post_mem(struct wl1271 *wl)
374{
375 int ret, i;
376
377 ret = wl1271_cmd_set_sta_default_wep_key(wl, wl->default_key);
378 if (ret < 0) {
379 wl1271_warning("couldn't set default key");
380 return ret;
381 }
382
383 /* disable all keep-alive templates */
384 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
385 ret = wl1271_acx_keep_alive_config(wl, i,
386 ACX_KEEP_ALIVE_TPL_INVALID);
387 if (ret < 0)
388 return ret;
389 }
390
391 /* disable the keep-alive feature */
392 ret = wl1271_acx_keep_alive_mode(wl, false);
393 if (ret < 0)
394 return ret;
395
396 return 0;
397}
398
399static int wl1271_ap_hw_init(struct wl1271 *wl)
400{
401 int ret, i;
402
403 ret = wl1271_ap_init_templates_config(wl);
404 if (ret < 0)
405 return ret;
406
407 /* Configure for power always on */
408 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
409 if (ret < 0)
410 return ret;
411
412 /* Configure initial TX rate classes */
413 for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
414 ret = wl1271_acx_ap_rate_policy(wl,
415 &wl->conf.tx.ap_rc_conf[i], i);
416 if (ret < 0)
417 return ret;
418 }
419
420 ret = wl1271_acx_ap_rate_policy(wl,
421 &wl->conf.tx.ap_mgmt_conf,
422 ACX_TX_AP_MODE_MGMT_RATE);
423 if (ret < 0)
424 return ret;
425
426 ret = wl1271_acx_ap_rate_policy(wl,
427 &wl->conf.tx.ap_bcst_conf,
428 ACX_TX_AP_MODE_BCST_RATE);
429 if (ret < 0)
430 return ret;
431
432 ret = wl1271_acx_max_tx_retry(wl);
433 if (ret < 0)
434 return ret;
435
436 return 0;
437}
438
439static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl)
440{
441 int ret;
442
443 ret = wl1271_ap_init_deauth_template(wl);
444 if (ret < 0)
445 return ret;
446
447 ret = wl1271_ap_init_null_template(wl);
448 if (ret < 0)
449 return ret;
450
451 ret = wl1271_ap_init_qos_null_template(wl);
452 if (ret < 0)
453 return ret;
454
455 return 0;
456}
457
4b7fac77
LS
458static void wl1271_check_ba_support(struct wl1271 *wl)
459{
460 /* validate FW cose ver x.x.x.50-60.x */
461 if ((wl->chip.fw_ver[3] >= WL12XX_BA_SUPPORT_FW_COST_VER2_START) &&
462 (wl->chip.fw_ver[3] < WL12XX_BA_SUPPORT_FW_COST_VER2_END)) {
463 wl->ba_support = true;
464 return;
465 }
466
467 wl->ba_support = false;
468}
469
470static int wl1271_set_ba_policies(struct wl1271 *wl)
471{
472 u8 tid_index;
473 u8 ret = 0;
474
475 /* Reset the BA RX indicators */
4b7fac77
LS
476 wl->ba_rx_bitmap = 0;
477
478 /* validate that FW support BA */
479 wl1271_check_ba_support(wl);
480
481 if (wl->ba_support)
482 /* 802.11n initiator BA session setting */
483 for (tid_index = 0; tid_index < CONF_TX_MAX_TID_COUNT;
484 ++tid_index) {
485 ret = wl1271_acx_set_ba_session(wl, WLAN_BACK_INITIATOR,
486 tid_index, true);
487 if (ret < 0)
488 break;
489 }
490
491 return ret;
492}
493
f5fc0f86
LC
494int wl1271_hw_init(struct wl1271 *wl)
495{
243eeb51 496 struct conf_tx_ac_category *conf_ac;
f2054df5 497 struct conf_tx_tid *conf_tid;
243eeb51 498 int ret, i;
e0fe371b 499 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
f5fc0f86 500
98b5dd5d 501 ret = wl1271_cmd_general_parms(wl);
4a90406b 502 if (ret < 0)
f5fc0f86
LC
503 return ret;
504
98b5dd5d 505 ret = wl1271_cmd_radio_parms(wl);
4a90406b 506 if (ret < 0)
f5fc0f86
LC
507 return ret;
508
e0fe371b
AN
509 /* Mode specific init */
510 if (is_ap)
511 ret = wl1271_ap_hw_init(wl);
512 else
513 ret = wl1271_sta_hw_init(wl);
644a4860 514
f5fc0f86
LC
515 if (ret < 0)
516 return ret;
517
518 /* Default memory configuration */
519 ret = wl1271_acx_init_mem_config(wl);
520 if (ret < 0)
521 return ret;
522
523 /* RX config */
524 ret = wl1271_init_rx_config(wl,
eb5b28d0
JO
525 RX_CFG_PROMISCUOUS | RX_CFG_TSF,
526 RX_FILTER_OPTION_DEF);
f5fc0f86
LC
527 /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
528 RX_FILTER_OPTION_FILTER_ALL); */
529 if (ret < 0)
530 goto out_free_memmap;
531
532 /* PHY layer config */
533 ret = wl1271_init_phy_config(wl);
534 if (ret < 0)
535 goto out_free_memmap;
536
6e92b416
LC
537 ret = wl1271_acx_dco_itrim_params(wl);
538 if (ret < 0)
539 goto out_free_memmap;
540
f5fc0f86
LC
541 /* Configure TX patch complete interrupt behavior */
542 ret = wl1271_acx_tx_config_options(wl);
543 if (ret < 0)
544 goto out_free_memmap;
545
546 /* RX complete interrupt pacing */
547 ret = wl1271_acx_init_rx_interrupt(wl);
548 if (ret < 0)
549 goto out_free_memmap;
550
f5fc0f86
LC
551 /* Energy detection */
552 ret = wl1271_init_energy_detection(wl);
553 if (ret < 0)
554 goto out_free_memmap;
555
f5fc0f86 556 /* Default fragmentation threshold */
68d069c4 557 ret = wl1271_acx_frag_threshold(wl, wl->conf.tx.frag_threshold);
f5fc0f86
LC
558 if (ret < 0)
559 goto out_free_memmap;
560
9987a9da
JO
561 /* Default TID/AC configuration */
562 BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
f2054df5 563 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
9987a9da
JO
564 conf_ac = &wl->conf.tx.ac_conf[i];
565 ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
566 conf_ac->cw_max, conf_ac->aifsn,
567 conf_ac->tx_op_limit);
568 if (ret < 0)
569 goto out_free_memmap;
570
f2054df5
KV
571 conf_tid = &wl->conf.tx.tid_conf[i];
572 ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id,
573 conf_tid->channel_type,
574 conf_tid->tsid,
575 conf_tid->ps_scheme,
576 conf_tid->ack_policy,
577 conf_tid->apsd_conf[0],
578 conf_tid->apsd_conf[1]);
579 if (ret < 0)
580 goto out_free_memmap;
581 }
f5fc0f86 582
f5fc0f86 583 /* Enable data path */
94210897 584 ret = wl1271_cmd_data_path(wl, 1);
f5fc0f86
LC
585 if (ret < 0)
586 goto out_free_memmap;
587
f5fc0f86 588 /* Configure HW encryption */
e0fe371b 589 ret = wl1271_acx_feature_cfg(wl);
f5fc0f86
LC
590 if (ret < 0)
591 goto out_free_memmap;
592
38ad2d87
JO
593 /* configure PM */
594 ret = wl1271_acx_pm_config(wl);
595 if (ret < 0)
596 goto out_free_memmap;
597
e0fe371b
AN
598 /* Mode specific init - post mem init */
599 if (is_ap)
600 ret = wl1271_ap_hw_init_post_mem(wl);
601 else
602 ret = wl1271_sta_hw_init_post_mem(wl);
c1899554 603
00236aed
JO
604 if (ret < 0)
605 goto out_free_memmap;
606
4b7fac77
LS
607 /* Configure initiator BA sessions policies */
608 ret = wl1271_set_ba_policies(wl);
609 if (ret < 0)
610 goto out_free_memmap;
611
f5fc0f86
LC
612 return 0;
613
614 out_free_memmap:
615 kfree(wl->target_mem_map);
34415236 616 wl->target_mem_map = NULL;
f5fc0f86
LC
617
618 return ret;
619}